chiark / gitweb /
Added some Gtk+ 2.10 stuff
[clg] / gdk / gdk.lisp
CommitLineData
55212af1 1;; Common Lisp bindings for GTK+ v2.x
1b7d3a82 2;; Copyright 2000-2006 Espen S. Johnsen <espen@users.sf.net>
0d07716f 3;;
55212af1 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:
0d07716f 11;;
55212af1 12;; The above copyright notice and this permission notice shall be
13;; included in all copies or substantial portions of the Software.
0d07716f 14;;
55212af1 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
e0c6be61 23;; $Id: gdk.lisp,v 1.32 2006/08/14 14:03:32 espen Exp $
0d07716f 24
25
26(in-package "GDK")
27
e295d6df 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))
0d07716f 34
0d07716f 35
e295d6df 36
a05a0e59 37;;; Display
e295d6df 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
a05a0e59 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
e295d6df 89(defbinding (display-connection-number "clg_gdk_connection_number")
90 (&optional (display (display-get-default))) int
91 (display display))
92
93
a05a0e59 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
09bf47c6 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
a05a0e59 222
e295d6df 223;;; Events
0d07716f 224
5515cd18 225(defbinding (events-pending-p "gdk_events_pending") () boolean)
0d07716f 226
5515cd18 227(defbinding event-get () event)
0d07716f 228
5515cd18 229(defbinding event-peek () event)
0d07716f 230
5515cd18 231(defbinding event-get-graphics-expose () event
0d07716f 232 (window window))
233
5515cd18 234(defbinding event-put () event
0d07716f 235 (event event))
236
5515cd18 237;(defbinding event-handler-set () ...)
0d07716f 238
5515cd18 239(defbinding set-show-events () nil
0d07716f 240 (show-events boolean))
241
5515cd18 242(defbinding get-show-events () boolean)
0d07716f 243
0d07716f 244
a05a0e59 245;;; Miscellaneous functions
0d07716f 246
a05a0e59 247(defbinding screen-width () int)
248(defbinding screen-height () int)
0d07716f 249
a05a0e59 250(defbinding screen-width-mm () int)
251(defbinding screen-height-mm () int)
0d07716f 252
a05a0e59 253(defbinding pointer-grab
254 (window &key owner-events events confine-to cursor time) grab-status
0d07716f 255 (window window)
256 (owner-events boolean)
a05a0e59 257 (events event-mask)
0d07716f 258 (confine-to (or null window))
259 (cursor (or null cursor))
4a098e36 260 ((or time 0) (unsigned 32)))
0d07716f 261
a05a0e59 262(defbinding (pointer-ungrab "gdk_display_pointer_ungrab")
4a098e36 263 (&optional time (display (display-get-default))) nil
a05a0e59 264 (display display)
4a098e36 265 ((or time 0) (unsigned 32)))
0d07716f 266
a05a0e59 267(defbinding (pointer-is-grabbed-p "gdk_display_pointer_is_grabbed")
1b7d3a82 268 (&optional (display (display-get-default))) boolean
269 (display display))
a05a0e59 270
271(defbinding keyboard-grab (window &key owner-events time) grab-status
0d07716f 272 (window window)
273 (owner-events boolean)
4a098e36 274 ((or time 0) (unsigned 32)))
0d07716f 275
a05a0e59 276(defbinding (keyboard-ungrab "gdk_display_keyboard_ungrab")
4a098e36 277 (&optional time (display (display-get-default))) nil
a05a0e59 278 (display display)
4a098e36 279 ((or time 0) (unsigned 32)))
0d07716f 280
0d07716f 281
0d07716f 282
596c3078 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
0d07716f 290
291
292;;; Visuals
293
5515cd18 294(defbinding visual-get-best-depth () int)
0d07716f 295
5515cd18 296(defbinding visual-get-best-type () visual-type)
0d07716f 297
5515cd18 298(defbinding visual-get-system () visual)
0d07716f 299
300
5515cd18 301(defbinding (%visual-get-best-with-nothing "gdk_visual_get_best") () visual)
0d07716f 302
5515cd18 303(defbinding %visual-get-best-with-depth () visual
0d07716f 304 (depth int))
305
5515cd18 306(defbinding %visual-get-best-with-type () visual
0d07716f 307 (type visual-type))
308
5515cd18 309(defbinding %visual-get-best-with-both () visual
0d07716f 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
5515cd18 320;(defbinding query-depths ..)
0d07716f 321
5515cd18 322;(defbinding query-visual-types ..)
0d07716f 323
5515cd18 324(defbinding list-visuals () (glist visual))
0d07716f 325
326
327;;; Windows
328
5515cd18 329(defbinding window-destroy () nil
0d07716f 330 (window window))
331
64780167 332(defbinding window-at-pointer () window
333 (x int :out)
334 (y int :out))
0d07716f 335
5515cd18 336(defbinding window-show () nil
0d07716f 337 (window window))
338
64780167 339(defbinding window-show-unraised () nil
340 (window window))
341
5515cd18 342(defbinding window-hide () nil
0d07716f 343 (window window))
344
64780167 345(defbinding window-is-visible-p () boolean
346 (window window))
347
348(defbinding window-is-viewable-p () boolean
349 (window window))
350
5515cd18 351(defbinding window-withdraw () nil
0d07716f 352 (window window))
353
64780167 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
5515cd18 386(defbinding window-move () nil
0d07716f 387 (window window)
388 (x int)
389 (y int))
390
5515cd18 391(defbinding window-resize () nil
0d07716f 392 (window window)
393 (width int)
394 (height int))
395
5515cd18 396(defbinding window-move-resize () nil
0d07716f 397 (window window)
398 (x int)
399 (y int)
400 (width int)
401 (height int))
402
64780167 403(defbinding window-scroll () nil
404 (window window)
405 (dx int)
406 (dy int))
407
5515cd18 408(defbinding window-reparent () nil
0d07716f 409 (window window)
410 (new-parent window)
411 (x int)
412 (y int))
413
5515cd18 414(defbinding window-clear () nil
0d07716f 415 (window window))
416
64780167 417(defbinding %window-clear-area () nil
0d07716f 418 (window window)
419 (x int) (y int) (width int) (height int))
420
64780167 421(defbinding %window-clear-area-e () nil
0d07716f 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
64780167 427 (%window-clear-area-e window x y width height)
428 (%window-clear-area window x y width height)))
0d07716f 429
5515cd18 430(defbinding window-raise () nil
0d07716f 431 (window window))
432
5515cd18 433(defbinding window-lower () nil
0d07716f 434 (window window))
435
64780167 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
09bf47c6 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))
64780167 467
09bf47c6 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
64780167 507(defbinding window-set-user-data () nil
508 (window window)
509 (user-data pointer))
0d07716f 510
5515cd18 511(defbinding window-set-override-redirect () nil
0d07716f 512 (window window)
09bf47c6 513 (override-redirect-p boolean))
0d07716f 514
09bf47c6 515(defbinding window-set-accept-focus () nil
516 (window window)
517 (accept-focus-p boolean))
0d07716f 518
09bf47c6 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
5515cd18 525; (defbinding window-remove-filter () nil
0d07716f 526
09bf47c6 527;; New code should use window-shape-combine
5515cd18 528(defbinding window-shape-combine-mask () nil
0d07716f 529 (window window)
530 (shape-mask bitmap)
531 (offset-x int)
532 (offset-y int))
533
09bf47c6 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
5515cd18 546(defbinding window-set-child-shapes () nil
0d07716f 547 (window window))
548
5515cd18 549(defbinding window-merge-child-shapes () nil
0d07716f 550 (window window))
551
09bf47c6 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)))
0d07716f 577
5515cd18 578(defbinding window-set-static-gravities () boolean
0d07716f 579 (window window)
09bf47c6 580 (use-static-p boolean))
581
582(defbinding window-set-title () nil
583 (window window)
584 (title string))
0d07716f 585
09bf47c6 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))
0d07716f 594
5515cd18 595(defbinding window-set-cursor () nil
0d07716f 596 (window window)
64780167 597 (cursor (or null cursor)))
0d07716f 598
09bf47c6 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
e0c6be61 609(defbinding window-set-icon-list () nil
09bf47c6 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
5515cd18 645(defbinding window-get-pointer () window
0d07716f 646 (window window)
647 (x int :out)
648 (y int :out)
649 (mask modifier-type :out))
650
09bf47c6 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
64780167 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
402183fc 682(defbinding %get-default-root-window () window)
0d07716f 683
67824820 684(defun get-root-window (&optional display)
402183fc 685 (if display
686 (error "Not implemented")
687 (%get-default-root-window)))
0d07716f 688
689
64780167 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
0d07716f 705;;
706
5515cd18 707(defbinding rgb-init () nil)
0d07716f 708
709
710
711
712;;; Cursor
713
6091b3e8 714(defmethod allocate-foreign ((cursor cursor) &key source mask fg bg
adc20f66 715 (x 0) (y 0) (display (display-get-default)))
6091b3e8 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
48acc6ae 727 (apply #'make-instance 'cursor :source cursor args)))
64780167 728
729(defbinding %cursor-new-for-display () pointer
730 (display display)
0d07716f 731 (cursor-type cursor-type))
732
64780167 733(defbinding %cursor-new-from-pixmap () pointer
0d07716f 734 (source pixmap)
735 (mask bitmap)
736 (foreground color)
737 (background color)
738 (x int) (y int))
739
64780167 740(defbinding %cursor-new-from-pixbuf () pointer
741 (display display)
742 (pixbuf pixbuf)
743 (x int) (y int))
744
5515cd18 745(defbinding %cursor-ref () pointer
6baf860c 746 (location pointer))
0d07716f 747
5515cd18 748(defbinding %cursor-unref () nil
6baf860c 749 (location pointer))
750
0d07716f 751
0d07716f 752;;; Pixmaps
402183fc 753
dc96fcd4 754(defbinding %pixmap-new () pointer
755 (window (or null window))
0d07716f 756 (width int)
757 (height int)
dc96fcd4 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
5515cd18 767(defbinding %pixmap-colormap-create-from-xpm () pixmap
0d07716f 768 (window (or null window))
769 (colormap (or null colormap))
770 (mask bitmap :out)
771 (color (or null color))
1b7d3a82 772 (filename pathname))
0d07716f 773
5515cd18 774(defbinding %pixmap-colormap-create-from-xpm-d () pixmap
0d07716f 775 (window (or null window))
776 (colormap (or null colormap))
777 (mask bitmap :out)
778 (color (or null color))
b53669e6 779 (data (vector string)))
0d07716f 780
dc96fcd4 781;; Deprecated, use pixbufs instead
5a66b42b 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)
b53669e6 788 (etypecase source
5a66b42b 789 ((or string pathname)
1b7d3a82 790 (%pixmap-colormap-create-from-xpm window colormap color source))
b53669e6 791 ((vector string)
792 (%pixmap-colormap-create-from-xpm-d window colormap color source)))
5a66b42b 793 (values pixmap mask))))
402183fc 794
0d07716f 795
0d07716f 796;;; Color
797
dc96fcd4 798(defbinding colormap-get-system () colormap)
799
2e10ba8b 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
1b7d3a82 808 (with-memory (location #.(foreign-size (find-class 'color)))
2e10ba8b 809 (%color-copy location)))
810
0d07716f 811(defun %scale-value (value)
812 (etypecase value
813 (integer value)
814 (float (truncate (* value 65535)))))
815
1b7d3a82 816(defmethod initialize-instance ((color color) &key (red 0.0) (green 0.0) (blue 0.0))
0d07716f 817 (call-next-method)
818 (with-slots ((%red red) (%green green) (%blue blue)) color
819 (setf
216bc8c3 820 %red (%scale-value red)
821 %green (%scale-value green)
822 %blue (%scale-value blue))))
0d07716f 823
f3f8586a 824(defbinding %color-parse () boolean
2e10ba8b 825 (spec string)
1b7d3a82 826 (color color :in/return))
2e10ba8b 827
f3f8586a 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
0d07716f 834(defun ensure-color (color)
835 (etypecase color
836 (null nil)
837 (color color)
f3f8586a 838 (string (color-parse color))
216bc8c3 839 (vector
2e10ba8b 840 (make-instance 'color
f3f8586a 841 :red (svref color 0) :green (svref color 1) :blue (svref color 2)))))
842
0d07716f 843
844
dc96fcd4 845;;; Drawable -- all the draw- functions are deprecated and will be
1b7d3a82 846;;; removed, use cairo for drawing instead.
64780167 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
64780167 878(defbinding draw-line () nil
879 (drawable drawable) (gc gc)
880 (x1 int) (y1 int)
881 (x2 int) (y2 int))
882
64780167 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
5515cd18 894(defbinding draw-rectangle () nil
64780167 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
64780167 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))
0d07716f 955
956
957;;; Key values
958
5515cd18 959(defbinding keyval-name () string
0d07716f 960 (keyval unsigned-int))
961
56b0eab3 962(defbinding %keyval-from-name () unsigned-int
0d07716f 963 (name string))
964
56b0eab3 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
5515cd18 971(defbinding keyval-to-upper () unsigned-int
0d07716f 972 (keyval unsigned-int))
973
596c3078 974(defbinding keyval-to-lower () unsigned-int
0d07716f 975 (keyval unsigned-int))
976
5515cd18 977(defbinding (keyval-is-upper-p "gdk_keyval_is_upper") () boolean
0d07716f 978 (keyval unsigned-int))
979
5515cd18 980(defbinding (keyval-is-lower-p "gdk_keyval_is_lower") () boolean
0d07716f 981 (keyval unsigned-int))
982
78dc8487 983;;; Cairo interaction
984
1b7d3a82 985#?(pkg-exists-p "gtk+-2.0" :atleast-version "2.8.0")
78dc8487 986(progn
987 (defbinding cairo-create () cairo:context
988 (drawable drawable))
989
10ec8e36 990 (defmacro with-cairo-context ((cr drawable) &body body)
991 `(let ((,cr (cairo-create ,drawable)))
992 (unwind-protect
993 (progn ,@body)
1b7d3a82 994 (invalidate-instance ,cr t))))
10ec8e36 995
78dc8487 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)
00a8d921 1014
1015
1b7d3a82 1016
00a8d921 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
1b7d3a82 1050 ,@body
00a8d921 1051 (threads-leave t)))))