chiark / gitweb /
Added some Gtk+ 2.10 stuff
[clg] / gdk / gdk.lisp
... / ...
CommitLineData
1;; Common Lisp bindings for GTK+ v2.x
2;; Copyright 2000-2006 Espen S. Johnsen <espen@users.sf.net>
3;;
4;; Permission is hereby granted, free of charge, to any person obtaining
5;; a copy of this software and associated documentation files (the
6;; "Software"), to deal in the Software without restriction, including
7;; without limitation the rights to use, copy, modify, merge, publish,
8;; distribute, sublicense, and/or sell copies of the Software, and to
9;; permit persons to whom the Software is furnished to do so, subject to
10;; the following conditions:
11;;
12;; The above copyright notice and this permission notice shall be
13;; included in all copies or substantial portions of the Software.
14;;
15;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18;; IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19;; CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23;; $Id: gdk.lisp,v 1.32 2006-08-14 14:03:32 espen Exp $
24
25
26(in-package "GDK")
27
28;;; Initialization
29
30(defbinding (gdk-init "gdk_parse_args") () nil
31 "Initializes the library without opening the display."
32 (nil null)
33 (nil null))
34
35
36
37;;; Display
38
39(defbinding %display-open () display
40 (display-name (or null string)))
41
42(defun display-open (&optional display-name)
43 (let ((display (%display-open display-name)))
44 (unless (display-get-default)
45 (display-set-default display))
46 display))
47
48(defbinding %display-get-n-screens () int
49 (display display))
50
51(defbinding %display-get-screen () screen
52 (display display)
53 (screen-num int))
54
55(defun display-screens (&optional (display (display-get-default)))
56 (loop
57 for i from 0 below (%display-get-n-screens display)
58 collect (%display-get-screen display i)))
59
60(defbinding display-get-default-screen
61 (&optional (display (display-get-default))) screen
62 (display display))
63
64(defbinding display-beep (&optional (display (display-get-default))) nil
65 (display display))
66
67(defbinding display-sync (&optional (display (display-get-default))) nil
68 (display display))
69
70(defbinding display-flush (&optional (display (display-get-default))) nil
71 (display display))
72
73(defbinding display-close (&optional (display (display-get-default))) nil
74 (display display))
75
76(defbinding display-get-event
77 (&optional (display (display-get-default))) event
78 (display display))
79
80(defbinding display-peek-event
81 (&optional (display (display-get-default))) event
82 (display display))
83
84(defbinding display-put-event
85 (event &optional (display (display-get-default))) event
86 (display display)
87 (event event))
88
89(defbinding (display-connection-number "clg_gdk_connection_number")
90 (&optional (display (display-get-default))) int
91 (display display))
92
93
94
95;;; Display manager
96
97(defbinding display-get-default () display)
98
99(defbinding (display-manager "gdk_display_manager_get") () display-manager)
100
101(defbinding (display-set-default "gdk_display_manager_set_default_display")
102 (display) nil
103 ((display-manager) display-manager)
104 (display display))
105
106
107;;; Primitive graphics structures (points, rectangles and regions)
108
109(defbinding %rectangle-intersect () boolean
110 (src1 rectangle)
111 (src2 rectangle)
112 (dest rectangle))
113
114(defun rectangle-intersect (src1 src2 &optional (dest (make-instance 'rectangle)))
115 "Calculates the intersection of two rectangles. It is allowed for DEST to be the same as either SRC1 or SRC2. DEST is returned if the to rectangles intersect, otherwise NIL"
116 (when (%rectangle-intersect src1 src2 dest)
117 dest))
118
119(defbinding rectangle-union (src1 src2 &optional (dest (make-instance 'rectangle))) nil
120 "Calculates the union of two rectangles. The union of rectangles SRC1 and SRC2 is the smallest rectangle which includes both SRC1 and SRC2 within it. It is allowed for DEST to be the same as either SRC1 or SRC2."
121 (src1 rectangle)
122 (src2 rectangle)
123 (dest rectangle :in/return))
124
125(defun ensure-rectangle (rectangle)
126 (etypecase rectangle
127 (rectangle rectangle)
128 (vector (make-instance 'rectangle
129 :x (aref rectangle 0) :y (aref rectangle 1)
130 :width (aref rectangle 2) :height (aref rectangle 3)))))
131
132
133(defbinding %region-new () pointer)
134
135(defbinding %region-polygon () pointer
136 (points (vector (inlined point)))
137 (n-points int)
138 (fill-rule fill-rule))
139
140(defbinding %region-rectangle () pointer
141 (rectangle rectangle))
142
143(defbinding %region-copy () pointer
144 (location pointer))
145
146(defbinding %region-destroy () nil
147 (location pointer))
148
149(defmethod allocate-foreign ((region region) &key rectangle polygon fill-rule)
150 (declare (ignore initargs))
151 (cond
152 ((and rectangle polygon)
153 (error "Only one of the keyword arguments :RECTANGLE and :POLYGON can be specified"))
154 (rectangle (%region-rectangle (ensure-rectangle rectangle)))
155 (polygon (%region-polygon polygon (length polygon) fill-rule))
156 ((%region-new))))
157
158(defun ensure-region (region)
159 (etypecase region
160 (region region)
161 ((or rectangle vector)
162 (make-instance 'region :rectangle (ensure-rectangle region)))))
163
164(defbinding region-get-clipbox (region &optional (rectangle (make-instance 'rectangle))) nil
165 (region region)
166 (rectangle rectangle :in/return))
167
168(defbinding %region-get-rectangles () nil
169 (region region)
170 (rectangles pointer :out)
171 (n-rectangles int :out))
172
173(defun region-get-rectangles (region)
174 "Obtains the area covered by the region as a list of rectangles."
175 (multiple-value-bind (location length) (%region-get-rectangles region)
176 (prog1
177 (map-c-vector 'list #'identity location 'point length :get)
178 (deallocate-memory location))))
179
180(defbinding region-empty-p () boolean
181 (region region))
182
183(defbinding region-equal-p () boolean
184 (region1 region)
185 (region2 region))
186
187(defbinding region-point-in-p () boolean
188 (region region)
189 (x int)
190 (y int))
191
192(defbinding region-rect-in (region rectangle) overlap-type
193 (region region)
194 ((ensure-rectangle rectangle) rectangle))
195
196(defbinding region-offset () nil
197 (region region)
198 (dx int)
199 (dy int))
200
201(defbinding region-shrink () nil
202 (region region)
203 (dx int)
204 (dy int))
205
206(defbinding region-intersect (source1 source2) nil
207 (source1 region)
208 ((ensure-region source2) region))
209
210(defbinding region-union (source1 source2) nil
211 (source1 region)
212 ((ensure-region source2) region))
213
214(defbinding region-subtract (source1 source2) nil
215 (source1 region)
216 ((ensure-region source2) region))
217
218(defbinding region-xor (source1 source2) nil
219 (source1 region)
220 ((ensure-region source2) region))
221
222
223;;; Events
224
225(defbinding (events-pending-p "gdk_events_pending") () boolean)
226
227(defbinding event-get () event)
228
229(defbinding event-peek () event)
230
231(defbinding event-get-graphics-expose () event
232 (window window))
233
234(defbinding event-put () event
235 (event event))
236
237;(defbinding event-handler-set () ...)
238
239(defbinding set-show-events () nil
240 (show-events boolean))
241
242(defbinding get-show-events () boolean)
243
244
245;;; Miscellaneous functions
246
247(defbinding screen-width () int)
248(defbinding screen-height () int)
249
250(defbinding screen-width-mm () int)
251(defbinding screen-height-mm () int)
252
253(defbinding pointer-grab
254 (window &key owner-events events confine-to cursor time) grab-status
255 (window window)
256 (owner-events boolean)
257 (events event-mask)
258 (confine-to (or null window))
259 (cursor (or null cursor))
260 ((or time 0) (unsigned 32)))
261
262(defbinding (pointer-ungrab "gdk_display_pointer_ungrab")
263 (&optional time (display (display-get-default))) nil
264 (display display)
265 ((or time 0) (unsigned 32)))
266
267(defbinding (pointer-is-grabbed-p "gdk_display_pointer_is_grabbed")
268 (&optional (display (display-get-default))) boolean
269 (display display))
270
271(defbinding keyboard-grab (window &key owner-events time) grab-status
272 (window window)
273 (owner-events boolean)
274 ((or time 0) (unsigned 32)))
275
276(defbinding (keyboard-ungrab "gdk_display_keyboard_ungrab")
277 (&optional time (display (display-get-default))) nil
278 (display display)
279 ((or time 0) (unsigned 32)))
280
281
282
283(defbinding atom-intern (atom-name &optional only-if-exists) atom
284 ((string atom-name) string)
285 (only-if-exists boolean))
286
287(defbinding atom-name () string
288 (atom atom))
289
290
291
292;;; Visuals
293
294(defbinding visual-get-best-depth () int)
295
296(defbinding visual-get-best-type () visual-type)
297
298(defbinding visual-get-system () visual)
299
300
301(defbinding (%visual-get-best-with-nothing "gdk_visual_get_best") () visual)
302
303(defbinding %visual-get-best-with-depth () visual
304 (depth int))
305
306(defbinding %visual-get-best-with-type () visual
307 (type visual-type))
308
309(defbinding %visual-get-best-with-both () visual
310 (depth int)
311 (type visual-type))
312
313(defun visual-get-best (&key depth type)
314 (cond
315 ((and depth type) (%visual-get-best-with-both depth type))
316 (depth (%visual-get-best-with-depth depth))
317 (type (%visual-get-best-with-type type))
318 (t (%visual-get-best-with-nothing))))
319
320;(defbinding query-depths ..)
321
322;(defbinding query-visual-types ..)
323
324(defbinding list-visuals () (glist visual))
325
326
327;;; Windows
328
329(defbinding window-destroy () nil
330 (window window))
331
332(defbinding window-at-pointer () window
333 (x int :out)
334 (y int :out))
335
336(defbinding window-show () nil
337 (window window))
338
339(defbinding window-show-unraised () nil
340 (window window))
341
342(defbinding window-hide () nil
343 (window window))
344
345(defbinding window-is-visible-p () boolean
346 (window window))
347
348(defbinding window-is-viewable-p () boolean
349 (window window))
350
351(defbinding window-withdraw () nil
352 (window window))
353
354(defbinding window-iconify () nil
355 (window window))
356
357(defbinding window-deiconify () nil
358 (window window))
359
360(defbinding window-stick () nil
361 (window window))
362
363(defbinding window-unstick () nil
364 (window window))
365
366(defbinding window-maximize () nil
367 (window window))
368
369(defbinding window-unmaximize () nil
370 (window window))
371
372(defbinding window-fullscreen () nil
373 (window window))
374
375(defbinding window-unfullscreen () nil
376 (window window))
377
378(defbinding window-set-keep-above () nil
379 (window window)
380 (setting boolean))
381
382(defbinding window-set-keep-below () nil
383 (window window)
384 (setting boolean))
385
386(defbinding window-move () nil
387 (window window)
388 (x int)
389 (y int))
390
391(defbinding window-resize () nil
392 (window window)
393 (width int)
394 (height int))
395
396(defbinding window-move-resize () nil
397 (window window)
398 (x int)
399 (y int)
400 (width int)
401 (height int))
402
403(defbinding window-scroll () nil
404 (window window)
405 (dx int)
406 (dy int))
407
408(defbinding window-reparent () nil
409 (window window)
410 (new-parent window)
411 (x int)
412 (y int))
413
414(defbinding window-clear () nil
415 (window window))
416
417(defbinding %window-clear-area () nil
418 (window window)
419 (x int) (y int) (width int) (height int))
420
421(defbinding %window-clear-area-e () nil
422 (window window)
423 (x int) (y int) (width int) (height int))
424
425(defun window-clear-area (window x y width height &optional expose)
426 (if expose
427 (%window-clear-area-e window x y width height)
428 (%window-clear-area window x y width height)))
429
430(defbinding window-raise () nil
431 (window window))
432
433(defbinding window-lower () nil
434 (window window))
435
436(defbinding window-focus () nil
437 (window window)
438 (timestamp unsigned-int))
439
440(defbinding window-register-dnd () nil
441 (window window))
442
443(defbinding window-begin-resize-drag () nil
444 (window window)
445 (edge window-edge)
446 (button int)
447 (root-x int)
448 (root-y int)
449 (timestamp unsigned-int))
450
451(defbinding window-begin-move-drag () nil
452 (window window)
453 (button int)
454 (root-x int)
455 (root-y int)
456 (timestamp unsigned-int))
457
458;; Probably not needed
459;; (defbinding window-constrain-size () nil ..
460
461(defbinding window-begin-paint-region (window region) nil
462 (window window)
463 ((ensure-region region) region))
464
465(defbinding window-end-paint () nil
466 (window window))
467
468(defmacro with-window-paint ((window region) &body body)
469 `(progn
470 (window-begin-paint-region ,window ,region)
471 (unwind-protect
472 (progn ,@body)
473 (window-end-paint ,window))))
474
475;; TODO: create wrapper function and use gdk_window_invalidate_maybe_recurse
476;; if last arg is a function
477(defbinding window-invalidate-region (window region invalidate-children-p) nil
478 (window window)
479 ((ensure-region region) region)
480 (invalidate-children-p boolean))
481
482(defbinding window-get-update-area () region
483 (window window))
484
485(defbinding window-freeze-updates () nil
486 (window window))
487
488(defbinding window-thaw-updates () nil
489 (window window))
490
491(defbinding window-process-all-updates () nil)
492
493(defbinding window-process-updates () nil
494 (window window)
495 (update-children-p boolean))
496
497(defbinding window-set-debug-updates () nil
498 (enable-p boolean))
499
500(defbinding window-enable-synchronized-configure () nil
501 (window window))
502
503(defbinding window-configure-finished () nil
504 (window window))
505
506;; Deprecated, use gobject user data mechanism
507(defbinding window-set-user-data () nil
508 (window window)
509 (user-data pointer))
510
511(defbinding window-set-override-redirect () nil
512 (window window)
513 (override-redirect-p boolean))
514
515(defbinding window-set-accept-focus () nil
516 (window window)
517 (accept-focus-p boolean))
518
519(defbinding window-set-focus-on-map () nil
520 (window window)
521 (focus-on-map-p boolean))
522
523;; Added if needed
524; (defbinding window-add-filter () nil
525; (defbinding window-remove-filter () nil
526
527;; New code should use window-shape-combine
528(defbinding window-shape-combine-mask () nil
529 (window window)
530 (shape-mask bitmap)
531 (offset-x int)
532 (offset-y int))
533
534(defbinding %window-shape-combine-region () nil
535 (window window)
536 (region (or null region))
537 (offset-x int)
538 (offset-y int))
539
540(defun window-shape-combine (window shape offset-x offset-y)
541 (etypecase shape
542 (nil (%window-shape-combine-region window nil 0 0)
543 (region (%window-shape-combine-region window shape offset-x offset-y))
544 (bitmask (window-shape-combine-mask window shape offset-x offset-y)))))
545
546(defbinding window-set-child-shapes () nil
547 (window window))
548
549(defbinding window-merge-child-shapes () nil
550 (window window))
551
552#?(pkg-exists-p "gtk+-2.0" :atleast-version "2.10.0")
553(progn
554 (defbinding %window-input-shape-combine-mask () nil
555 (window window)
556 (shape-mask bitmap)
557 (x int)
558 (y int))
559
560 (defbinding %window-input-shape-combine-region () nil
561 (window window)
562 (region (or null region))
563 (x int)
564 (y int))
565
566 (defun window-input-shape-combine (window shape x y)
567 (etypecase shape
568 (nil (%window-input-shape-combine-region window nil 0 0)
569 (region (%window-input-shape-combine-region window shape x y))
570 (bitmask (%window-input-shape-combine-mask window shape x y)))))
571
572 (defbinding window-set-child-input-shapes () nil
573 (window window))
574
575 (defbinding window-merge-child-input-shapes () nil
576 (window window)))
577
578(defbinding window-set-static-gravities () boolean
579 (window window)
580 (use-static-p boolean))
581
582(defbinding window-set-title () nil
583 (window window)
584 (title string))
585
586(defbinding window-set-background () nil
587 (window window)
588 (color color))
589
590(defbinding window-set-back-pixmap (window pixmap &optional parent-relative-p) nil
591 (window window)
592 (pixmap (or null pixmap))
593 (parent-relative-p boolean))
594
595(defbinding window-set-cursor () nil
596 (window window)
597 (cursor (or null cursor)))
598
599(defbinding window-get-geometry () nil
600 (window window)
601 (x int :out)
602 (y int :out)
603 (width int :out)
604 (height int :out)
605 (depth int :out))
606
607;(defbinding window-set-geometry-hints () nil
608
609(defbinding window-set-icon-list () nil
610 (window window)
611 (icons (glist pixbufs)))
612
613(defbinding window-set-skip-taskbar-hint () nil
614 (window window)
615 (skip-taskbar-p boolean))
616
617(defbinding window-set-skip-pager-hint () nil
618 (window window)
619 (skip-pager-p boolean))
620
621#?(pkg-exists-p "gtk+-2.0" :atleast-version "2.8.0")
622(defbinding window-set-urgency-hint () nil
623 (window window)
624 (urgent-p boolean))
625
626(defbinding window-get-position () nil
627 (window window)
628 (x int :out)
629 (y int :out))
630
631(defbinding window-get-root-origin () nil
632 (window window)
633 (x int :out)
634 (y int :out))
635
636(defbinding window-get-frame-extents (window &optional (extents (make-instance 'rect))) nil
637 (window window)
638 (extents rectangle :in/return))
639
640(defbinding window-get-origin () nil ; this may not work as
641 (window window) ; an int is actually returned
642 (x int :out)
643 (y int :out))
644
645(defbinding window-get-pointer () window
646 (window window)
647 (x int :out)
648 (y int :out)
649 (mask modifier-type :out))
650
651;(defbinding window-set-icon () nil
652
653(defbinding window-set-icon-name () nil
654 (window window)
655 (icon-name string))
656
657(defbinding window-set-transient-for () nil
658 (window window)
659 (parent window))
660
661(defbinding window-set-role () nil
662 (window window)
663 (role string))
664
665(defbinding %window-get-decorations () boolean
666 (window window)
667 (decorations wm-decoration :out))
668
669(defun %window-decorations-getter (window)
670 (nth-value 1 (%window-get-decorations window)))
671
672(defun %window-decorations-boundp (window)
673 (%window-get-decorations window))
674
675(defbinding %window-get-toplevels () (glist window))
676
677(defun window-get-toplevels (&optional screen)
678 (if screen
679 (error "Not implemented")
680 (%window-get-toplevels)))
681
682(defbinding %get-default-root-window () window)
683
684(defun get-root-window (&optional display)
685 (if display
686 (error "Not implemented")
687 (%get-default-root-window)))
688
689
690
691;;; Drag and Drop
692
693;; Destination side
694
695(defbinding drag-status () nil
696 (context drag-context)
697 (action drag-action)
698 (time (unsigned 32)))
699
700
701
702
703
704
705;;
706
707(defbinding rgb-init () nil)
708
709
710
711
712;;; Cursor
713
714(defmethod allocate-foreign ((cursor cursor) &key source mask fg bg
715 (x 0) (y 0) (display (display-get-default)))
716 (etypecase source
717 (keyword (%cursor-new-for-display display source))
718 (pixbuf (%cursor-new-from-pixbuf display source x y))
719 (pixmap (%cursor-new-from-pixmap source mask
720 (or fg (ensure-color #(0.0 0.0 0.0)))
721 (or bg (ensure-color #(1.0 1.0 1.0))) x y))
722 (pathname (%cursor-new-from-pixbuf display (pixbuf-load source) x y))))
723
724(defun ensure-cursor (cursor &rest args)
725 (if (typep cursor 'cursor)
726 cursor
727 (apply #'make-instance 'cursor :source cursor args)))
728
729(defbinding %cursor-new-for-display () pointer
730 (display display)
731 (cursor-type cursor-type))
732
733(defbinding %cursor-new-from-pixmap () pointer
734 (source pixmap)
735 (mask bitmap)
736 (foreground color)
737 (background color)
738 (x int) (y int))
739
740(defbinding %cursor-new-from-pixbuf () pointer
741 (display display)
742 (pixbuf pixbuf)
743 (x int) (y int))
744
745(defbinding %cursor-ref () pointer
746 (location pointer))
747
748(defbinding %cursor-unref () nil
749 (location pointer))
750
751
752;;; Pixmaps
753
754(defbinding %pixmap-new () pointer
755 (window (or null window))
756 (width int)
757 (height int)
758 (depth int))
759
760(defmethod allocate-foreign ((pximap pixmap) &key width height depth window)
761 (%pixmap-new window width height depth))
762
763(defun pixmap-new (width height depth &key window)
764 (warn "PIXMAP-NEW is deprecated, use (make-instance 'pixmap ...) instead")
765 (make-instance 'pixmap :width width :height height :depth depth :window window))
766
767(defbinding %pixmap-colormap-create-from-xpm () pixmap
768 (window (or null window))
769 (colormap (or null colormap))
770 (mask bitmap :out)
771 (color (or null color))
772 (filename pathname))
773
774(defbinding %pixmap-colormap-create-from-xpm-d () pixmap
775 (window (or null window))
776 (colormap (or null colormap))
777 (mask bitmap :out)
778 (color (or null color))
779 (data (vector string)))
780
781;; Deprecated, use pixbufs instead
782(defun pixmap-create (source &key color window colormap)
783 (let ((window
784 (if (not (or window colormap))
785 (get-root-window)
786 window)))
787 (multiple-value-bind (pixmap mask)
788 (etypecase source
789 ((or string pathname)
790 (%pixmap-colormap-create-from-xpm window colormap color source))
791 ((vector string)
792 (%pixmap-colormap-create-from-xpm-d window colormap color source)))
793 (values pixmap mask))))
794
795
796;;; Color
797
798(defbinding colormap-get-system () colormap)
799
800(defbinding %color-copy () pointer
801 (location pointer))
802
803(defmethod allocate-foreign ((color color) &rest initargs)
804 (declare (ignore color initargs))
805 ;; Color structs are allocated as memory chunks by gdk, and since
806 ;; there is no gdk_color_new we have to use this hack to get a new
807 ;; color chunk
808 (with-memory (location #.(foreign-size (find-class 'color)))
809 (%color-copy location)))
810
811(defun %scale-value (value)
812 (etypecase value
813 (integer value)
814 (float (truncate (* value 65535)))))
815
816(defmethod initialize-instance ((color color) &key (red 0.0) (green 0.0) (blue 0.0))
817 (call-next-method)
818 (with-slots ((%red red) (%green green) (%blue blue)) color
819 (setf
820 %red (%scale-value red)
821 %green (%scale-value green)
822 %blue (%scale-value blue))))
823
824(defbinding %color-parse () boolean
825 (spec string)
826 (color color :in/return))
827
828(defun color-parse (spec &optional (color (make-instance 'color)))
829 (multiple-value-bind (succeeded-p color) (%color-parse spec color)
830 (if succeeded-p
831 color
832 (error "Parsing color specification ~S failed." spec))))
833
834(defun ensure-color (color)
835 (etypecase color
836 (null nil)
837 (color color)
838 (string (color-parse color))
839 (vector
840 (make-instance 'color
841 :red (svref color 0) :green (svref color 1) :blue (svref color 2)))))
842
843
844
845;;; Drawable -- all the draw- functions are deprecated and will be
846;;; removed, use cairo for drawing instead.
847
848(defbinding drawable-get-size () nil
849 (drawable drawable)
850 (width int :out)
851 (height int :out))
852
853(defbinding (drawable-width "gdk_drawable_get_size") () nil
854 (drawable drawable)
855 (width int :out)
856 (nil null))
857
858(defbinding (drawable-height "gdk_drawable_get_size") () nil
859 (drawable drawable)
860 (nil null)
861 (height int :out))
862
863;; (defbinding drawable-get-clip-region () region
864;; (drawable drawable))
865
866;; (defbinding drawable-get-visible-region () region
867;; (drawable drawable))
868
869(defbinding draw-point () nil
870 (drawable drawable) (gc gc)
871 (x int) (y int))
872
873(defbinding %draw-points () nil
874 (drawable drawable) (gc gc)
875 (points pointer)
876 (n-points int))
877
878(defbinding draw-line () nil
879 (drawable drawable) (gc gc)
880 (x1 int) (y1 int)
881 (x2 int) (y2 int))
882
883(defbinding draw-pixbuf
884 (drawable gc pixbuf src-x src-y dest-x dest-y &optional
885 width height (dither :none) (x-dither 0) (y-dither 0)) nil
886 (drawable drawable) (gc (or null gc))
887 (pixbuf pixbuf)
888 (src-x int) (src-y int)
889 (dest-x int) (dest-y int)
890 ((or width -1) int) ((or height -1) int)
891 (dither rgb-dither)
892 (x-dither int) (y-dither int))
893
894(defbinding draw-rectangle () nil
895 (drawable drawable) (gc gc)
896 (filled boolean)
897 (x int) (y int)
898 (width int) (height int))
899
900(defbinding draw-arc () nil
901 (drawable drawable) (gc gc)
902 (filled boolean)
903 (x int) (y int)
904 (width int) (height int)
905 (angle1 int) (angle2 int))
906
907(defbinding %draw-layout () nil
908 (drawable drawable) (gc gc)
909 (font pango:font)
910 (x int) (y int)
911 (layout pango:layout))
912
913(defbinding %draw-layout-with-colors () nil
914 (drawable drawable) (gc gc)
915 (font pango:font)
916 (x int) (y int)
917 (layout pango:layout)
918 (foreground (or null color))
919 (background (or null color)))
920
921(defun draw-layout (drawable gc font x y layout &optional foreground background)
922 (if (or foreground background)
923 (%draw-layout-with-colors drawable gc font x y layout foreground background)
924 (%draw-layout drawable gc font x y layout)))
925
926(defbinding draw-drawable
927 (drawable gc src src-x src-y dest-x dest-y &optional width height) nil
928 (drawable drawable) (gc gc)
929 (src drawable)
930 (src-x int) (src-y int)
931 (dest-x int) (dest-y int)
932 ((or width -1) int) ((or height -1) int))
933
934(defbinding draw-image
935 (drawable gc image src-x src-y dest-x dest-y &optional width height) nil
936 (drawable drawable) (gc gc)
937 (image image)
938 (src-x int) (src-y int)
939 (dest-x int) (dest-y int)
940 ((or width -1) int) ((or height -1) int))
941
942(defbinding drawable-get-image () image
943 (drawable drawable)
944 (x int) (y int)
945 (width int) (height int))
946
947(defbinding drawable-copy-to-image
948 (drawable src-x src-y width height &optional image dest-x dest-y) image
949 (drawable drawable)
950 (image (or null image))
951 (src-x int) (src-y int)
952 ((if image dest-x 0) int)
953 ((if image dest-y 0) int)
954 (width int) (height int))
955
956
957;;; Key values
958
959(defbinding keyval-name () string
960 (keyval unsigned-int))
961
962(defbinding %keyval-from-name () unsigned-int
963 (name string))
964
965(defun keyval-from-name (name)
966 "Returns the keysym value for the given key name or NIL if it is not a valid name."
967 (let ((keyval (%keyval-from-name name)))
968 (unless (zerop keyval)
969 keyval)))
970
971(defbinding keyval-to-upper () unsigned-int
972 (keyval unsigned-int))
973
974(defbinding keyval-to-lower () unsigned-int
975 (keyval unsigned-int))
976
977(defbinding (keyval-is-upper-p "gdk_keyval_is_upper") () boolean
978 (keyval unsigned-int))
979
980(defbinding (keyval-is-lower-p "gdk_keyval_is_lower") () boolean
981 (keyval unsigned-int))
982
983;;; Cairo interaction
984
985#?(pkg-exists-p "gtk+-2.0" :atleast-version "2.8.0")
986(progn
987 (defbinding cairo-create () cairo:context
988 (drawable drawable))
989
990 (defmacro with-cairo-context ((cr drawable) &body body)
991 `(let ((,cr (cairo-create ,drawable)))
992 (unwind-protect
993 (progn ,@body)
994 (invalidate-instance ,cr t))))
995
996 (defbinding cairo-set-source-color () nil
997 (cr cairo:context)
998 (color color))
999
1000 (defbinding cairo-set-source-pixbuf () nil
1001 (cr cairo:context)
1002 (pixbuf pixbuf)
1003 (x double-float)
1004 (y double-float))
1005
1006 (defbinding cairo-rectangle () nil
1007 (cr cairo:context)
1008 (rectangle rectangle))
1009
1010;; (defbinding cairo-region () nil
1011;; (cr cairo:context)
1012;; (region region))
1013)
1014
1015
1016
1017;;; Multi-threading support
1018
1019#+sbcl
1020(progn
1021 (defvar *global-lock* (sb-thread:make-mutex :name "global GDK lock"))
1022 (let ((recursive-level 0))
1023 (defun threads-enter ()
1024 (if (eq (sb-thread:mutex-value *global-lock*) sb-thread:*current-thread*)
1025 (incf recursive-level)
1026 (sb-thread:get-mutex *global-lock*)))
1027
1028 (defun threads-leave (&optional flush-p)
1029 (cond
1030 ((zerop recursive-level)
1031 (when flush-p
1032 (display-flush))
1033 (sb-thread:release-mutex *global-lock*))
1034 (t (decf recursive-level)))))
1035
1036 (define-callback %enter-fn nil ()
1037 (threads-enter))
1038
1039 (define-callback %leave-fn nil ()
1040 (threads-leave))
1041
1042 (defbinding threads-set-lock-functions (&optional) nil
1043 (%enter-fn callback)
1044 (%leave-fn callback))
1045
1046 (defmacro with-global-lock (&body body)
1047 `(progn
1048 (threads-enter)
1049 (unwind-protect
1050 ,@body
1051 (threads-leave t)))))