Bug fix for COLOR-SELECTION
[clg] / gtk / gtk.lisp
1 ;; Common Lisp bindings for GTK+ v2.x
2 ;; Copyright 1999-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: gtk.lisp,v 1.88 2008-01-10 22:11:15 espen Exp $
24
25
26 (in-package "GTK")
27
28 ;;; Gtk version
29
30 (defbinding check-version () (copy-of string)
31 (required-major unsigned-int)
32 (required-minor unsigned-int)
33 (required-micro unsigned-int))
34
35 (defbinding query-version () nil
36 (major unsigned-int :out)
37 (minor unsigned-int :out)
38 (micro unsigned-int :out))
39
40 (defun gtk-version ()
41 (multiple-value-bind (major minor micro)
42 (query-version)
43 (if (zerop micro)
44 (format nil "Gtk+ v~A.~A" major minor)
45 (format nil "Gtk+ v~A.~A.~A" major minor micro))))
46
47 (defun clg-version ()
48 "clg 0.93")
49
50
51 ;;;; Initalization and display handling
52
53 (defparameter *event-poll-interval* 10000) ; in microseconds
54
55
56 (defbinding (gtk-init "gtk_parse_args") () boolean
57 "Initializes the library without opening the display."
58 (nil null)
59 (nil null))
60
61 (defun clg-init (&optional display multi-threading-p)
62 "Initializes the system and starts event handling."
63 (unless (gdk:display-get-default)
64 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.8.0")
65 (progn
66 #+sbcl(sb-int:set-floating-point-modes :traps nil)
67 #+cmu(ext:set-floating-point-modes :traps nil))
68
69 (gdk:gdk-init)
70 (unless (gtk-init)
71 (error "Initialization of GTK+ failed."))
72
73 (if (not multi-threading-p)
74 (%init-async-event-handling display)
75 #+sb-thread(%init-multi-threaded-event-handling display)
76 #-sb-thread(error "Multi threading not supported on this platform")))
77 (gdk:ensure-display display t))
78
79 (defun clg-init-with-threading (&optional display)
80 (clg-init display t))
81
82
83 #?(sbcl>= 1 0 6)
84 ;; A very minimal implementation of CLISP's socket-status
85 (defun socket-status (socket seconds microseconds)
86 (sb-alien:with-alien ((read-fds (sb-alien:struct sb-unix:fd-set)))
87 (let ((fd (sb-sys:fd-stream-fd (car socket))))
88 (sb-unix:fd-zero read-fds)
89 (sb-unix:fd-set fd read-fds)
90
91 (let ((num-fds-changed
92 (sb-unix:unix-fast-select
93 (1+ fd) (sb-alien:addr read-fds) nil nil
94 seconds microseconds)))
95 (unless (or (not num-fds-changed) (zerop num-fds-changed))
96 (if (peek-char nil (car socket) nil)
97 :input
98 :eof))))))
99
100 (defun %init-async-event-handling (display)
101 (let ((style #?(or (featurep :cmu) (sbcl< 1 0 6)) :fd-handler
102 #?-(or (featurep :cmu) (sbcl< 1 0 6)) nil))
103 (when (and
104 (find-package "SWANK")
105 (not (eq (symbol-value (find-symbol "*COMMUNICATION-STYLE*" "SWANK")) style)))
106 (error "When running clg in Slime, the communication style ~S must be used in combination with asynchronous event handling on this platform. See the README file and <http://common-lisp.net/project/slime/doc/html/slime_45.html> for more information." style)))
107
108 #?(or (featurep :cmu) (sbcl< 1 0 6))
109 (progn
110 (signal-connect (gdk:display-manager) 'display-opened
111 #'(lambda (display)
112 (let ((fd (gdk:display-connection-number display)))
113 (unless (< fd 0)
114 (let ((handler (add-fd-handler
115 (gdk:display-connection-number display)
116 :input #'main-iterate-all)))
117 (signal-connect display 'closed
118 #'(lambda (is-error-p)
119 (declare (ignore is-error-p))
120 (remove-fd-handler handler))))))))
121 (setq *periodic-polling-function* #'main-iterate-all)
122 (setq *max-event-to-sec* 0)
123 (setq *max-event-to-usec* *event-poll-interval*))
124
125 #+(and clisp readline)
126 ;; Readline will call the event hook at most ten times per second
127 (setf readline:event-hook #'main-iterate-all)
128
129 #?-(or (featurep :cmu) (sbcl< 1 0 6))
130 ;; When running in Slime we need to hook into the Swank server
131 ;; to handle events asynchronously.
132 (if (find-package "SWANK")
133 (let ((read-from-emacs (symbol-function (find-symbol "READ-FROM-EMACS" "SWANK")))
134 (stream (funcall (find-symbol "CONNECTION.SOCKET-IO" "SWANK") (symbol-value (find-symbol "*EMACS-CONNECTION*" "SWANK")))))
135 (setf (symbol-function (find-symbol "READ-FROM-EMACS" "SWANK"))
136 #'(lambda ()
137 (loop
138 (case (socket-status (cons stream :input) 0 *event-poll-interval*)
139 ((:input :eof) (return (funcall read-from-emacs)))
140 (otherwise (main-iterate-all)))))))
141 #-(and clisp readline)
142 (warn "Asynchronous event handling not supported on this platform. An explicit main loop has to be started."))
143
144 (gdk:display-open display))
145
146 #+sb-thread
147 (progn
148 (defvar *main-thread* nil)
149
150 ;; Hopefully, when threading support is added to the Win32 port of
151 ;; SBCL in the future, this will work just out of the box.
152 #+win32
153 (let ((done (sb-thread:make-waitqueue))
154 (functions ())
155 (results ()))
156
157 ;; In Win32 all GDK calls have to be made from the main loop
158 ;; thread, so we add a timeout function which will poll for code and
159 ;; execute it.
160
161 (defun funcall-in-main (function)
162 (if (or
163 (not *main-thread*)
164 (eq sb-thread:*current-thread* *main-thread*))
165 (funcall function)
166 (gdk:with-global-lock
167 (push function functions)
168 (sb-thread:condition-wait done gdk:*global-lock*)
169 (pop results))))
170
171 ;; Will lock REPL on error, need to be fixed!
172 (defun %funcall-in-main-poll ()
173 (when functions
174 (loop
175 for n from 0
176 while functions
177 do (push (funcall (pop functions)) results)
178 finally (sb-thread:condition-notify done n)))
179 t))
180
181 (defmacro within-main-loop (&body body)
182 #-win32 `(gdk:with-global-lock ,@body)
183 #+win32 `(funcall-in-main #'(lambda () ,@body)))
184
185 (defun %init-multi-threaded-event-handling (display)
186 (when (and
187 (find-package "SWANK")
188 (not (eq (symbol-value (find-symbol "*COMMUNICATION-STYLE*" "SWANK")) :spawn)))
189 (error "When running clg in Slime, the communication style :spawn must be used in combination with multi threaded event handling. See the README file and <http://common-lisp.net/project/slime/doc/html/slime_45.html> for more information."))
190 (gdk:threads-init)
191 (let ((main-running (sb-thread:make-waitqueue)))
192 (gdk:with-global-lock
193 (setf *main-thread*
194 (sb-thread:make-thread
195 #'(lambda ()
196 (gdk:with-global-lock
197 (gdk:display-open display)
198 #+win32(gdk:timeout-add-with-lock (/ *event-poll-interval* 1000)
199 #'%funcall-in-main-poll)
200 (sb-thread:condition-notify main-running)
201 (main)))
202 :name "gtk event loop"))
203 (sb-thread:condition-wait main-running gdk:*global-lock*)))
204
205 ;; We need to hook into the Swank server to protect calls to GDK properly.
206 ;; This will *only* protect code entered directly in the REPL.
207 (when (find-package "SWANK")
208 (let ((repl-eval-hook (find-symbol "*SLIME-REPL-EVAL-HOOKS*" "SWANK")))
209 (if repl-eval-hook
210 (push #'(lambda (form)
211 (within-main-loop (eval form)))
212 (symbol-value (find-symbol "*SLIME-REPL-EVAL-HOOKS*" "SWANK")))
213 (warn "Your version of Slime does not have *SLIME-REPL-EVAL-HOOKS* so all calls to Gtk+ functions have to be explicit protected by wrapping them in a WITHIN-MAIN-LOOP form"))))))
214
215 #-sb-thread
216 (defmacro within-main-loop (&body body)
217 `(progn ,@body))
218
219
220
221 ;;; Generic functions
222
223 (defgeneric add-to-radio-group (item1 item2))
224 (defgeneric activate-radio-widget (item))
225 (defgeneric (setf tool-item-tip-text) (tip-text tool-item))
226 (defgeneric (setf tool-item-tip-private) (tip-private tool-item))
227
228
229
230 ;;; Misc
231
232 (defbinding grab-add () nil
233 (widget widget))
234
235 (defbinding grab-get-current () widget)
236
237 (defbinding grab-remove () nil
238 (widget widget))
239
240 (defbinding get-default-language () (copy-of pango:language))
241
242
243 ;;; About dialog
244
245 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
246 (progn
247 (define-callback-marshal %about-dialog-activate-link-callback nil
248 (about-dialog (link string)))
249
250 (defbinding about-dialog-set-email-hook (function) nil
251 (%about-dialog-activate-link-callback callback)
252 ((register-callback-function function) unsigned-int)
253 (user-data-destroy-callback callback))
254
255 (defbinding about-dialog-set-url-hook (function) nil
256 (%about-dialog-activate-link-callback callback)
257 ((register-callback-function function) unsigned-int)
258 (user-data-destroy-callback callback)))
259
260
261 ;;; Acccel group
262
263 (defbinding %accel-group-connect () nil
264 (accel-group accel-group)
265 (key unsigned-int)
266 (modifiers gdk:modifier-type)
267 (flags accel-flags)
268 (gclosure gclosure))
269
270 (defun accel-group-connect (group accelerator function &optional flags)
271 (multiple-value-bind (key modifiers) (parse-accelerator accelerator)
272 (let ((gclosure (make-callback-closure function)))
273 (%accel-group-connect group key modifiers flags gclosure)
274 gclosure)))
275
276 (defbinding accel-group-connect-by-path (group path function) nil
277 (group accel-group)
278 (path string)
279 ((make-callback-closure function) gclosure :in/return))
280
281 (defbinding %accel-group-disconnect (group gclosure) boolean
282 (group accel-group)
283 (gclosure gclosure))
284
285 (defbinding %accel-group-disconnect-key () boolean
286 (group accel-group)
287 (key unsigned-int)
288 (modifiers gdk:modifier-type))
289
290 (defun accel-group-disconnect (group accelerator)
291 (etypecase accelerator
292 (gclosure (%accel-group-disconnect group accelerator))
293 (string
294 (multiple-value-bind (key modifiers) (parse-accelerator accelerator)
295 (%accel-group-disconnect-key group key modifiers)))))
296
297 (defbinding %accel-group-query () (copy-of (vector (inlined accel-group-entry) n))
298 (accel-group accel-group)
299 (key unsigned-int)
300 (modifiers gdk:modifier-type)
301 (n int :out))
302
303 (defun accel-group-query (accel-group accelerator)
304 (multiple-value-bind (key modifiers) (parse-accelerator accelerator)
305 (%accel-group-query accel-group key modifiers)))
306
307 (defbinding %accel-group-activate () boolean
308 (accel-group accel-group)
309 (acceleratable gobject)
310 (key unsigned-int)
311 (modifiers gdk:modifier-type))
312
313 (defun accel-group-activate (accel-group acceleratable accelerator)
314 (multiple-value-bind (key modifiers) (parse-accelerator accelerator)
315 (%accel-group-activate accel-group acceleratable key modifiers)))
316
317 (defbinding accel-group-lock () nil
318 (accel-group accel-group))
319
320 (defbinding accel-group-unlock () nil
321 (accel-group accel-group))
322
323 (defbinding accel-group-from-accel-closure () accel-group
324 (closure gclosure))
325
326 (defbinding %accel-groups-activate () boolean
327 (object gobject)
328 (key unsigned-int)
329 (modifiers gdk:modifier-type))
330
331 (defun accel-groups-activate (object accelerator)
332 (multiple-value-bind (key modifiers) (parse-accelerator accelerator)
333 (%accel-groups-activate object key modifiers)))
334
335 (defbinding accel-groups-from-object () (gslist accel-group)
336 (object gobject))
337
338 (defbinding accelerator-valid-p (key &optional modifiers) boolean
339 (key unsigned-int)
340 (modifiers gdk:modifier-type))
341
342 (defbinding %accelerator-parse () nil
343 (accelerator string)
344 (key unsigned-int :out)
345 (modifiers gdk:modifier-type :out))
346
347 (defgeneric parse-accelerator (accelerator))
348
349 (defmethod parse-accelerator ((accelerator string))
350 (multiple-value-bind (key modifiers) (%accelerator-parse accelerator)
351 (if (zerop key)
352 (error "Invalid accelerator: ~A" accelerator)
353 (values key modifiers))))
354
355 (defmethod parse-accelerator ((accelerator cons))
356 (destructuring-bind (key modifiers) accelerator
357 (values
358 (etypecase key
359 (integer key)
360 (string
361 (or
362 (gdk:keyval-from-name key)
363 (error "Invalid key name: ~A" key)))
364 (character (parse-accelerator key)))
365 modifiers)))
366
367 (defmethod parse-accelerator ((key integer))
368 key)
369
370 (defmethod parse-accelerator ((key character))
371 (or
372 (gdk:keyval-from-name (string key))
373 (error "Invalid key name: ~A" key)))
374
375
376 (defbinding accelerator-name () string
377 (key unsigned-int)
378 (modifiers gdk:modifier-type))
379
380 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
381 (defbinding accelerator-get-label () string
382 (key unsigned-int)
383 (modifiers gdk:modifier-type))
384
385 (defbinding %accelerator-set-default-mod-mask () nil
386 (default-modifiers gdk:modifier-type))
387
388 (defun (setf accelerator-default-modifier-mask) (default-modifiers)
389 (%accelerator-set-default-mod-mask default-modifiers))
390
391 (defbinding (accelerator-default-modifier-mask "gtk_accelerator_get_default_mod_mask") () gdk:modifier-type)
392
393
394 ;;; Acccel label
395
396 (defbinding accel-label-get-accel-width () unsigned-int
397 (accel-label accel-label))
398
399 (defbinding accel-label-refetch () boolean
400 (accel-label accel-label))
401
402
403
404 ;;; Accel map
405
406 (defbinding %accel-map-add-entry () nil
407 (path string)
408 (key unsigned-int)
409 (modifiers gdk:modifier-type))
410
411 (defun accel-map-add-entry (path accelerator)
412 (multiple-value-bind (key modifiers) (parse-accelerator accelerator)
413 (%accel-map-add-entry path key modifiers)))
414
415 (defbinding %accel-map-lookup-entry () boolean
416 (path string)
417 ((make-instance 'accel-key) accel-key :in/return))
418
419 (defun accel-map-lookup-entry (path)
420 (multiple-value-bind (found-p accel-key) (%accel-map-lookup-entry path)
421 (when found-p
422 (values
423 (slot-value accel-key 'key)
424 (slot-value accel-key 'modifiers)
425 (slot-value accel-key 'flags)))))
426
427 (defbinding %accel-map-change-entry () boolean
428 (path string)
429 (key unsigned-int)
430 (modifiers gdk:modifier-type)
431 (replace boolean))
432
433 (defun accel-map-change-entry (path accelerator &optional replace)
434 (multiple-value-bind (key modifiers) (parse-accelerator accelerator)
435 (%accel-map-change-entry path key modifiers replace)))
436
437 (defbinding accel-map-load () nil
438 (filename pathname))
439
440 (defbinding accel-map-save () nil
441 (filename pathname))
442
443 (define-callback-marshal %accel-map-foreach-callback nil
444 ((accel-path string) (key unsigned-int)
445 (modifiers gdk:modifier-type) (changed boolean)) :callback-id :first)
446
447 (defbinding %accel-map-foreach (callback-id) nil
448 (callback-id unsigned-int)
449 (%accel-map-foreach-callback callback))
450
451 (defbinding %accel-map-foreach-unfiltered (callback-id) nil
452 (callback-id unsigned-int)
453 (%accel-map-foreach-callback callback))
454
455 (defun accel-map-foreach (function &optional (filter-p t))
456 (with-callback-function (id function)
457 (if filter-p
458 (%accel-map-foreach id)
459 (%accel-map-foreach-unfiltered id))))
460
461 (defbinding accel-map-add-filter () nil
462 (filter string))
463
464 (defbinding accel-map-get () accel-map)
465
466 (defbinding accel-map-lock-path () nil
467 (path string))
468
469 (defbinding accel-map-unlock-path () nil
470 (path string))
471
472
473
474 ;;; Accessibility
475
476 (defbinding accessible-connect-widget-destroyed () nil
477 (accessible accessible))
478
479
480 ;;; Adjustment
481
482 (defmethod initialize-instance ((adjustment adjustment) &key value)
483 (prog1
484 (call-next-method)
485 ;; we need to make sure that the value is set last, otherwise it
486 ;; may be outside current limits and ignored
487 (when value
488 (setf (slot-value adjustment 'value) value))))
489
490
491 (defbinding adjustment-changed () nil
492 (adjustment adjustment))
493
494 (defbinding adjustment-value-changed () nil
495 (adjustment adjustment))
496
497 (defbinding adjustment-clamp-page () nil
498 (adjustment adjustment)
499 (lower single-float)
500 (upper single-float))
501
502
503 ;;; Alignment
504
505 (defbinding alignment-set () nil
506 (alognment alignment)
507 (x-align single-float)
508 (y-align single-float)
509 (x-scale single-float)
510 (y-scale single-float))
511
512 (defbinding alignment-get-padding () nil
513 (alognment alignment)
514 (top unsigned-int :out)
515 (bottom unsigned-int :out)
516 (left unsigned-int :out)
517 (right unsigned-int :out))
518
519 (defbinding alignment-set-padding () nil
520 (alognment alignment)
521 (top unsigned-int)
522 (bottom unsigned-int)
523 (left unsigned-int)
524 (right unsigned-int))
525
526
527 ;;; Assistant
528
529 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.10.0")
530 (progn
531 (defbinding assistant-get-nth-page () widget
532 (assistant assistant)
533 (page-num int))
534
535 (defbinding %assistant-insert-page () int
536 (assistant assistant)
537 (page widget)
538 (pos int))
539
540 (defun assistant-insert-page (assistant page position &rest child-args)
541 (let ((pos (case position
542 (:first 0)
543 (:last -1)
544 (t position))))
545 (prog1
546 (%assistant-insert-page assistant page pos)
547 (init-child-slots assistant page child-args))))
548
549 (defun assistant-append-page (assistant page &rest child-args)
550 (apply #'assistant-insert-page assistant page :last child-args))
551
552 (defun assistant-prepend-page (assistant page &rest child-args)
553 (apply #'assistant-insert-page assistant page :first child-args))
554
555 (define-callback-marshal %assistant-page-func-callback int
556 ((current-page int)))
557
558 (defbinding assistant-set-forward-page-func (assistant function) nil
559 (assistant assistant)
560 (%assistant-page-func-callback callback)
561 ((register-callback-function function) pointer-data)
562 (user-data-destroy-callback callback))
563
564 (defbinding assistant-add-action-widget () nil
565 (assistant assistant)
566 (child widget))
567
568 (defbinding assistant-remove-action-widget () nil
569 (assistant assistant)
570 (child widget))
571
572 (defbinding assistant-update-buttons-state () nil
573 (assistant assistant)))
574
575
576
577 ;;; Aspect frame
578
579
580 ;;; Bin
581
582 (defun (setf bin-child) (child bin)
583 (when-bind (current-child (bin-child bin))
584 (container-remove bin current-child))
585 (container-add bin child)
586 child)
587
588 (defmethod compute-signal-function ((bin bin) signal function object args)
589 (declare (ignore signal))
590 (if (eq object :child)
591 #'(lambda (&rest emission-args)
592 (apply function (bin-child bin) (nconc (rest emission-args) args)))
593 (call-next-method)))
594
595
596 ;;; Box
597
598 (defbinding box-pack-start () nil
599 (box box)
600 (child widget)
601 (expand boolean)
602 (fill boolean)
603 (padding unsigned-int))
604
605 (defbinding box-pack-end () nil
606 (box box)
607 (child widget)
608 (expand boolean)
609 (fill boolean)
610 (padding unsigned-int))
611
612 (defun box-pack (box child &key end (expand t) (fill t) (padding 0))
613 (if end
614 (box-pack-end box child expand fill padding)
615 (box-pack-start box child expand fill padding)))
616
617 (defbinding box-reorder-child () nil
618 (box box)
619 (child widget)
620 (position int))
621
622 (defbinding box-query-child-packing () nil
623 (box box)
624 (child widget)
625 (expand boolean :out)
626 (fill boolean :out)
627 (padding unsigned-int :out)
628 (pack-type pack-type :out))
629
630 (defbinding box-set-child-packing () nil
631 (box box)
632 (child widget)
633 (expand boolean)
634 (fill boolean)
635 (padding unsigned-int)
636 (pack-type pack-type))
637
638
639
640 ;;; Button
641
642 (defmethod initialize-instance ((button button) &rest initargs &key stock)
643 (if stock
644 (apply #'call-next-method button
645 :label stock :use-stock t :use-underline t initargs)
646 (call-next-method)))
647
648
649 (defbinding button-pressed () nil
650 (button button))
651
652 (defbinding button-released () nil
653 (button button))
654
655 (defbinding button-clicked () nil
656 (button button))
657
658 (defbinding button-enter () nil
659 (button button))
660
661 (defbinding button-leave () nil
662 (button button))
663
664
665
666 ;;; Calendar
667
668 (defbinding calendar-select-month () int
669 (calendar calendar)
670 (month unsigned-int)
671 (year unsigned-int))
672
673 (defbinding calendar-select-day () nil
674 (calendar calendar)
675 (day unsigned-int))
676
677 (defbinding calendar-mark-day () int
678 (calendar calendar)
679 (day unsigned-int))
680
681 (defbinding calendar-unmark-day () int
682 (calendar calendar)
683 (day unsigned-int))
684
685 (defbinding calendar-clear-marks () nil
686 (calendar calendar))
687
688 (defbinding calendar-get-date () nil
689 (calendar calendar)
690 (year unsigned-int :out)
691 (month unsigned-int :out)
692 (day unsigned-int :out))
693
694 (defbinding calendar-freeze () nil
695 (calendar calendar))
696
697 (defbinding calendar-thaw () nil
698 (calendar calendar))
699
700
701 ;;; Check menu item
702
703 (defbinding check-menu-item-toggled () nil
704 (check-menu-item check-menu-item))
705
706
707 ;;; Color selection
708
709 (defbinding color-selection-is-adjusting-p () boolean
710 (colorsel color-selection))
711
712 (defbinding (color-selection-previous-color
713 "gtk_color_selection_get_previous_color") () nil
714 (colorsel color-selection)
715 ((make-instance 'gdk:color) gdk:color :in/return))
716
717
718 ;;; Color selection dialog -- no functions
719
720
721
722 ;;;; Combo Box
723
724 (defmethod initialize-instance ((combo-box combo-box) &rest initargs
725 &key model content active)
726 (remf initargs :active)
727 (if model
728 (apply #'call-next-method combo-box initargs)
729 (progn
730 (apply #'call-next-method combo-box
731 :model (make-instance 'list-store :column-types '(string))
732 initargs)
733 (unless (typep combo-box 'combo-box-entry)
734 (let ((cell (make-instance 'cell-renderer-text)))
735 (cell-layout-pack combo-box cell :expand t)
736 (cell-layout-add-attribute combo-box cell :text 0)))))
737 (when content
738 (mapc #'(lambda (text)
739 (combo-box-append-text combo-box text))
740 content))
741 (when active
742 (setf (combo-box-active combo-box) active)))
743
744
745 ;; (defmethod shared-initialize :after ((combo-box combo-box) names &key active)
746 ;; (when active
747 ;; (signal-emit combo-box 'changed)))
748
749 (defbinding combo-box-append-text () nil
750 (combo-box combo-box)
751 (text string))
752
753 (defbinding combo-box-insert-text () nil
754 (combo-box combo-box)
755 (position int)
756 (text string))
757
758 (defbinding combo-box-prepend-text () nil
759 (combo-box combo-box)
760 (text string))
761
762 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
763 (defbinding combo-box-get-active-text () string
764 (combo-box combo-box))
765
766 (defbinding combo-box-popup () nil
767 (combo-box combo-box))
768
769 (defbinding combo-box-popdown () nil
770 (combo-box combo-box))
771
772
773
774 ;;;; Combo Box Entry
775
776 (defmethod initialize-instance ((combo-box-entry combo-box-entry) &key model)
777 (call-next-method)
778 (unless model
779 (setf (combo-box-entry-text-column combo-box-entry) 0)))
780
781
782 ;;;; Dialog
783
784 (defmethod shared-initialize ((dialog dialog) names &rest initargs
785 &key button buttons)
786 (declare (ignore names button buttons))
787 (prog1
788 (call-next-method)
789 (initial-apply-add dialog #'dialog-add-button initargs :button :buttons)))
790
791
792 (defun dialog-response-id (dialog response &optional create-p error-p)
793 "Returns a numeric response id"
794 (if (typep response 'response-type)
795 (response-type-to-int response)
796 (let ((responses (user-data dialog 'responses)))
797 (cond
798 ((and responses (position response responses :test #'equal)))
799 (create-p
800 (cond
801 (responses
802 (vector-push-extend response responses)
803 (1- (length responses)))
804 (t
805 (setf
806 (user-data dialog 'responses)
807 (make-array 1 :adjustable t :fill-pointer t
808 :initial-element response))
809 0)))
810 (error-p
811 (error "Invalid response: ~A" response))))))
812
813 (defun dialog-find-response (dialog id)
814 "Finds a symbolic response given a numeric id"
815 (cond
816 ((not (numberp id)) id)
817 ((< id 0) (int-to-response-type id))
818 ((aref (user-data dialog 'responses) id))))
819
820
821 (defmethod compute-signal-id ((dialog dialog) signal)
822 (if (dialog-response-id dialog signal)
823 (ensure-signal-id 'response dialog)
824 (call-next-method)))
825
826 (defmethod compute-signal-function ((dialog dialog) signal function object args)
827 (declare (ignore function object args))
828 (let ((callback (call-next-method))
829 (id (dialog-response-id dialog signal)))
830 (cond
831 (id
832 #'(lambda (dialog response)
833 (when (= response id)
834 (funcall callback dialog))))
835 ((string-equal signal "response")
836 #'(lambda (dialog response)
837 (funcall callback dialog (dialog-find-response dialog response))))
838 (callback))))
839
840 (defbinding dialog-run () nil
841 (dialog dialog))
842
843 (defbinding dialog-response (dialog response) nil
844 (dialog dialog)
845 ((dialog-response-id dialog response nil t) int))
846
847
848 (defbinding %dialog-add-button () button
849 (dialog dialog)
850 (text string)
851 (response-id int))
852
853 (defun dialog-add-button (dialog label &optional (response label)
854 &key default object after)
855 "Adds a button to the dialog."
856 (let* ((signal (if (functionp response)
857 label
858 response))
859 (id (dialog-response-id dialog signal t))
860 (button (%dialog-add-button dialog label id)))
861 (when (functionp response)
862 (signal-connect dialog signal response :object object :after after))
863 (when default
864 (%dialog-set-default-response dialog id))
865 button))
866
867
868 (defbinding %dialog-add-action-widget () nil
869 (dialog dialog)
870 (action-widget widget)
871 (response-id int))
872
873 (defun dialog-add-action-widget (dialog widget &optional (response widget)
874 &key default object after)
875 (let* ((signal (if (functionp response)
876 widget
877 response))
878 (id (dialog-response-id dialog signal t)))
879 (unless (widget-hidden-p widget)
880 (widget-show widget))
881 (%dialog-add-action-widget dialog widget id)
882 (when (functionp response)
883 (signal-connect dialog signal response :object object :after after))
884 (when default
885 (setf (widget-can-default-p widget) t)
886 (%dialog-set-default-response dialog id))
887 widget))
888
889
890 (defbinding %dialog-set-default-response () nil
891 (dialog dialog)
892 (response-id int))
893
894 (defun dialog-set-default-response (dialog response)
895 (%dialog-set-default-response
896 dialog (dialog-response-id dialog response nil t)))
897
898 (defbinding dialog-set-response-sensitive (dialog response sensitive) nil
899 (dialog dialog)
900 ((dialog-response-id dialog response nil t) int)
901 (sensitive boolean))
902
903 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
904 (defbinding alternative-dialog-button-order-p (&optional screen) boolean
905 (screen (or null gdk:screen)))
906
907 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
908 (defbinding (dialog-set-alternative-button-order
909 "gtk_dialog_set_alternative_button_order_from_array")
910 (dialog new-order) nil
911 (dialog dialog)
912 ((length new-order) int)
913 ((map 'vector #'(lambda (response)
914 (dialog-response-id dialog response nil t))
915 new-order) (vector int)))
916
917
918 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.8.0")
919 (progn
920 (defbinding %dialog-get-response-for-widget () int
921 (dialog dialog)
922 (widget widget))
923
924 (defun dialog-get-response-for-widget (dialog widget)
925 (dialog-find-response dialog (dialog-get-response-for-widget dialog widget))))
926
927
928 (defmethod container-add ((dialog dialog) (child widget) &rest args)
929 (apply #'container-add (dialog-vbox dialog) child args))
930
931
932 (defmethod container-remove ((dialog dialog) (child widget))
933 (container-remove (dialog-vbox dialog) child))
934
935 (defmethod container-children ((dialog dialog))
936 (container-children (dialog-vbox dialog)))
937
938 (defmethod (setf container-children) (children (dialog dialog))
939 (setf (container-children (dialog-vbox dialog)) children))
940
941
942 ;;; Drawing Area
943
944 (defun drawing-area-scroll (drawing-area dx dy)
945 (gdk:window-scroll (widget-window drawing-area) dx dy))
946
947
948 ;;; Entry
949
950 (defbinding entry-get-layout-offsets () nil
951 (entry entry)
952 (x int :out)
953 (y int :out))
954
955 (defbinding entry-layout-index-to-text-index () int
956 (entry entry)
957 (layout-index int))
958
959 (defbinding entry-text-index-to-layout-index () int
960 (entry entry)
961 (text-index int))
962
963
964 ;;; Entry Completion
965
966 (define-callback-marshal %entry-completion-match-callback boolean
967 (entry-completion string tree-iter))
968
969 (defbinding entry-completion-set-match-func (completion function) nil
970 (completion entry-completion)
971 (%entry-completion-match-callback callback)
972 ((register-callback-function function) unsigned-int)
973 (user-data-destroy-callback callback))
974
975 (defbinding entry-completion-complete () nil
976 (completion entry-completion))
977
978 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.12.0")
979 (defbinding entry-completion-get-completion-prefix () string
980 (completion entry-completion))
981
982 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
983 (defbinding entry-completion-insert-prefix () nil
984 (completion entry-completion))
985
986 (defbinding entry-completion-insert-action-text () nil
987 (completion entry-completion)
988 (index int)
989 (text string))
990
991 (defbinding entry-completion-insert-action-markup () nil
992 (completion entry-completion)
993 (index int)
994 (markup string))
995
996 (defbinding entry-completion-delete-action () nil
997 (completion entry-completion)
998 (index int))
999
1000
1001 ;;; File Chooser
1002
1003 (defmethod initialize-instance ((file-chooser file-chooser) &rest initargs
1004 &key filter filters shortcut-folder
1005 shortcut-folders shortcut-folder-uti
1006 shortcut-folder-uris)
1007 (declare (ignore filter filters shortcut-folder shortcut-folders
1008 shortcut-folder-uti shortcut-folder-uris))
1009 (prog1
1010 (call-next-method)
1011 (initial-add file-chooser #'file-chooser-add-filter
1012 initargs :filer :filters)
1013 (initial-add file-chooser #'file-chooser-add-shortcut-folder
1014 initargs :shortcut-folder :shortcut-folders)
1015 (initial-add file-chooser #'file-chooser-add-shortcut-folder-uri
1016 initargs :shortcut-folder-uri :shortcut-folders-uris)))
1017
1018
1019 (defbinding file-chooser-select-filename () boolean
1020 (file-chooser file-chooser)
1021 (filename string))
1022
1023 (defbinding file-chooser-unselect-filename () nil
1024 (file-chooser file-chooser)
1025 (filename string))
1026
1027 (defbinding file-chooser-select-all () boolean
1028 (file-chooser file-chooser))
1029
1030 (defbinding file-chooser-unselect-all () boolean
1031 (file-chooser file-chooser))
1032
1033 (defbinding file-chooser-get-filenames () (gslist string)
1034 (file-chooser file-chooser))
1035
1036 (defbinding file-chooser-select-uri () boolean
1037 (file-chooser file-chooser)
1038 (uri string))
1039
1040 (defbinding file-chooser-unselect-uri () nil
1041 (file-chooser file-chooser)
1042 (uri string))
1043
1044 (defbinding file-chooser-get-uris () (gslist string)
1045 (file-chooser file-chooser))
1046
1047 (defbinding file-chooser-add-filter () nil
1048 (file-chooser file-chooser)
1049 (filter file-filter))
1050
1051 (defbinding file-chooser-remove-filter () nil
1052 (file-chooser file-chooser)
1053 (filter file-filter))
1054
1055 (defbinding file-chooser-list-filters () (gslist file-filter)
1056 (file-chooser file-chooser))
1057
1058 (defbinding file-chooser-add-shortcut-folder () boolean
1059 (file-chooser file-chooser)
1060 (folder string)
1061 (nil null))
1062
1063 (defbinding file-chooser-remove-shortcut-folder () nil
1064 (file-chooser file-chooser)
1065 (folder string)
1066 (nil null))
1067
1068 (defbinding file-chooser-list-shortcut-folders () (gslist string)
1069 (file-chooser file-chooser))
1070
1071 (defbinding file-chooser-add-shortcut-folder-uri () boolean
1072 (file-chooser file-chooser)
1073 (uri string)
1074 (nil null))
1075
1076 (defbinding file-chooser-remove-shortcut-folder-uri () nil
1077 (file-chooser file-chooser)
1078 (uri string)
1079 (nil null))
1080
1081 (defbinding file-chooser-list-shortcut-folder-uris () (gslist string)
1082 (file-chooser file-chooser))
1083
1084
1085 ;;; File Filter
1086
1087 (defmethod initialize-instance ((file-filter file-filter) &rest initargs
1088 &key mime-type mime-types pattern patterns
1089 pixbuf-formats)
1090 (declare (ignore mime-type mime-types pattern patterns))
1091 (prog1
1092 (call-next-method)
1093 (when pixbuf-formats
1094 #?-(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
1095 (warn "Initarg :PIXBUF-FORMATS not supportet in this version of Gtk")
1096 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
1097 (file-filter-add-pixbuf-formats file-filter))
1098 (initial-add file-filter #'file-filter-add-mime-type
1099 initargs :mime-type :mime-types)
1100 (initial-add file-filter #'file-filter-add-pattern
1101 initargs :pattern :patterns)))
1102
1103
1104 (defbinding file-filter-add-mime-type () nil
1105 (filter file-filter)
1106 (mime-type string))
1107
1108 (defbinding file-filter-add-pattern () nil
1109 (filter file-filter)
1110 (pattern string))
1111
1112 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
1113 (defbinding file-filter-add-pixbuf-formats () nil
1114 (filter file-filter))
1115
1116 (define-callback-marshal %file-filter-callback boolean (file-filter-info))
1117
1118 (defbinding file-filter-add-custom (filter needed function) nil
1119 (filter file-filter)
1120 (needed file-filter-flags)
1121 (%file-filter-callback callback)
1122 ((register-callback-function function) unsigned-int)
1123 (user-data-destroy-callback callback))
1124
1125 (defbinding file-filter-get-needed () file-filter-flags
1126 (filter file-filter))
1127
1128 (defbinding file-filter-filter () boolean
1129 (filter file-filter)
1130 (filter-info file-filter-info))
1131
1132
1133
1134 ;;; Image
1135
1136 (defbinding image-set-from-file () nil
1137 (image image)
1138 (filename pathname))
1139
1140 (defmethod (setf image-pixmap) ((data vector) (image image))
1141 (multiple-value-bind (pixmap mask) (gdk:pixmap-create data)
1142 (setf (image-pixmap image) pixmap)
1143 (setf (image-mask image) mask)))
1144
1145 (defmethod initialize-instance ((image image) &rest initargs &key pixmap file)
1146 (cond
1147 ((typep pixmap 'vector)
1148 (multiple-value-bind (pixmap mask) (gdk:pixmap-create pixmap)
1149 (apply #'call-next-method image :pixmap pixmap :mask mask initargs)))
1150 (file
1151 (prog1
1152 (call-next-method)
1153 (image-set-from-file image file)))
1154 ((call-next-method))))
1155
1156 (defun create-image-widget (source &optional mask)
1157 (etypecase source
1158 (gdk:pixbuf (make-instance 'image :pixbuf source))
1159 (string (make-instance 'image :stock source))
1160 (pathname (make-instance 'image :file source))
1161 ((or list vector) (make-instance 'image :pixmap source))
1162 (gdk:pixmap (make-instance 'image :pixmap source :mask mask))))
1163
1164 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.8.0")
1165 (defbinding image-clear () nil
1166 (image image))
1167
1168
1169
1170 ;;; Image menu item
1171
1172 (defmethod initialize-instance ((item image-menu-item) &rest initargs &key image)
1173 (if (and image (not (typep image 'widget)))
1174 (apply #'call-next-method item :image (create-image-widget image) initargs)
1175 (call-next-method)))
1176
1177
1178 (defmethod (setf image-menu-item-image) ((widget widget) (item image-menu-item))
1179 (setf (slot-value item 'image) widget))
1180
1181 (defmethod (setf image-menu-item-image) (image (item image-menu-item))
1182 (setf (image-menu-item-image item) (create-image-widget image)))
1183
1184
1185 ;;; Label
1186
1187 (defmethod shared-initialize ((label label) names &key pattern)
1188 (declare (ignore names))
1189 (call-next-method)
1190 (when pattern
1191 (setf (label-pattern label) pattern)))
1192
1193 (defbinding label-get-layout-offsets () nil
1194 (label label)
1195 (x int :out)
1196 (y int :out))
1197
1198 (defbinding label-select-region () nil
1199 (label label)
1200 (start int)
1201 (end int))
1202
1203 (defbinding label-get-selection-bounds () boolean
1204 (label label)
1205 (start int :out)
1206 (end int :out))
1207
1208
1209
1210 ;;; Radio button
1211
1212 (defbinding %radio-button-get-group () pointer
1213 (radio-button radio-button))
1214
1215 (defbinding %radio-button-set-group () nil
1216 (radio-button radio-button)
1217 (group pointer))
1218
1219 (defmethod add-to-radio-group ((button1 radio-button) (button2 radio-button))
1220 "Add BUTTON1 to the group which BUTTON2 belongs to."
1221 (%radio-button-set-group button1 (%radio-button-get-group button2)))
1222
1223 (defun %add-activate-callback (widget signal function object after)
1224 (if object
1225 (signal-connect widget signal
1226 #'(lambda (object)
1227 (when (slot-value widget 'active)
1228 (funcall function object (slot-value widget 'value))))
1229 :object object :after after)
1230 (signal-connect widget signal
1231 #'(lambda ()
1232 (when (slot-value widget 'active)
1233 (funcall function (slot-value widget 'value))))
1234 :after after)))
1235
1236 (defmethod activate-radio-widget ((button radio-button))
1237 (signal-emit button 'clicked))
1238
1239 (defgeneric add-activate-callback (action function &key object after))
1240
1241 (defmethod add-activate-callback ((button radio-button) function &key object after)
1242 (%add-activate-callback button 'clicked function object after))
1243
1244 (defmethod initialize-instance ((button radio-button) &key group)
1245 (prog1
1246 (call-next-method)
1247 (when group
1248 (add-to-radio-group button group))))
1249
1250
1251 ;;; Item
1252
1253 (defbinding item-select () nil
1254 (item item))
1255
1256 (defbinding item-deselect () nil
1257 (item item))
1258
1259 (defbinding item-toggle () nil
1260 (item item))
1261
1262
1263
1264 ;;; Menu item
1265
1266 (defmethod initialize-instance ((item menu-item) &key label)
1267 (prog1
1268 (call-next-method)
1269 (when label
1270 (setf (menu-item-label item) label))))
1271
1272
1273 (defun (setf menu-item-label) (label menu-item)
1274 (make-instance 'accel-label
1275 :label label :xalign 0.0 :yalign 0.5 :accel-widget menu-item
1276 :use-underline (menu-item-use-underline-p menu-item)
1277 :visible t :parent menu-item)
1278 label)
1279
1280 (defun menu-item-label (menu-item)
1281 (when (and (slot-boundp menu-item 'child)
1282 (typep (bin-child menu-item) 'label))
1283 (label-label (bin-child menu-item))))
1284
1285 (defbinding menu-item-remove-submenu () nil
1286 (menu-item menu-item))
1287
1288 (defbinding menu-item-set-accel-path () nil
1289 (menu-item menu-item)
1290 (accel-path string))
1291
1292 (defbinding menu-item-select () nil
1293 (menu-item menu-item))
1294
1295 (defbinding menu-item-deselect () nil
1296 (menu-item menu-item))
1297
1298 (defbinding menu-item-activate () nil
1299 (menu-item menu-item))
1300
1301 (defbinding menu-item-toggle-size-request () nil
1302 (menu-item menu-item)
1303 (requisition int :out))
1304
1305 (defbinding menu-item-toggle-size-allocate () nil
1306 (menu-item menu-item)
1307 (allocation int))
1308
1309
1310 ;;; Menu tool button
1311
1312 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
1313 (defbinding menu-tool-button-set-arrow-tooltip () nil
1314 (menu-tool-button menu-tool-button)
1315 (tooltips tooltips)
1316 (tip-text string)
1317 (tip-private string))
1318
1319
1320 ;;; Message dialog
1321
1322 (defmethod allocate-foreign ((dialog message-dialog) &key (message-type :info)
1323 button buttons flags transient-parent)
1324 (let ((stock-buttons
1325 (cond
1326 ((and (not buttons) (not button))
1327 (case message-type
1328 (:question :yes-no)
1329 (t :ok)))
1330 ((listp buttons) :none)
1331 (t buttons))))
1332 (%message-dialog-new transient-parent flags message-type stock-buttons)))
1333
1334
1335 (defmethod shared-initialize ((dialog message-dialog) names &rest initargs
1336 &key message-type buttons button text
1337 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
1338 secondary-text)
1339 (declare (ignore names))
1340 (when text
1341 (message-dialog-set-markup dialog text))
1342 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
1343 (when secondary-text
1344 (message-dialog-format-secondary-markup dialog secondary-text))
1345 (when (and (not buttons) (not button))
1346 (loop
1347 for (key value) on initargs by #'cddr
1348 when (and (eq key :signal) (eq (first value) :close))
1349 do (warn "Default button configuration changed from ~A to ~A" :close
1350 (if (eq message-type :question) :yes-no :ok))
1351 (loop-finish)))
1352 (if (typep buttons 'buttons-type)
1353 (apply #'call-next-method dialog names (plist-remove :buttons initargs))
1354 (call-next-method)))
1355
1356
1357 (defbinding %message-dialog-new () pointer
1358 (parent (or null window))
1359 (flags dialog-flags)
1360 (type message-type)
1361 (buttons buttons-type)
1362 (nil null))
1363
1364 (defbinding message-dialog-set-markup () nil
1365 (message-dialog message-dialog)
1366 (markup string))
1367
1368 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
1369 (defbinding message-dialog-format-secondary-text () nil
1370 (message-dialog message-dialog)
1371 (text string))
1372
1373 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
1374 (defbinding message-dialog-format-secondary-markup () nil
1375 (message-dialog message-dialog)
1376 (markup string))
1377
1378
1379
1380 ;;; Radio menu item
1381
1382 (defbinding %radio-menu-item-get-group () pointer
1383 (radio-menu-item radio-menu-item))
1384
1385 (defbinding %radio-menu-item-set-group () nil
1386 (radio-menu-item radio-menu-item)
1387 (group pointer))
1388
1389 (defmethod activate-radio-widget ((item radio-menu-item))
1390 (menu-item-activate item))
1391
1392 (defmethod add-to-radio-group ((item1 radio-menu-item) (item2 radio-menu-item))
1393 "Add ITEM1 to the group which ITEM2 belongs to."
1394 (%radio-menu-item-set-group item1 (%radio-menu-item-get-group item2)))
1395
1396 (defmethod add-activate-callback ((item radio-menu-item) function &key object after)
1397 (%add-activate-callback item 'activate function object after))
1398
1399 (defmethod initialize-instance ((item radio-menu-item) &key group)
1400 (prog1
1401 (call-next-method)
1402 (when group
1403 (add-to-radio-group item group))))
1404
1405
1406
1407 ;;; Radio tool button
1408
1409 (defbinding %radio-tool-button-get-group () pointer
1410 (radio-tool-button radio-tool-button))
1411
1412 (defbinding %radio-tool-button-set-group () nil
1413 (radio-tool-button radio-tool-button)
1414 (group pointer))
1415
1416 (defmethod activate-radio-widget ((button radio-tool-button))
1417 (signal-emit button 'clicked))
1418
1419 (defmethod add-to-radio-group ((button1 radio-tool-button) (button2 radio-tool-button))
1420 "Add BUTTON1 to the group which BUTTON2 belongs to."
1421 (%radio-tool-button-set-group button1 (%radio-tool-button-get-group button2)))
1422 (defmethod add-activate-callback ((button radio-tool-button) function &key object after)
1423 (%add-activate-callback button 'clicked function object after))
1424
1425 (defmethod initialize-instance ((button radio-tool-button) &key group)
1426 (prog1
1427 (call-next-method)
1428 (when group
1429 (add-to-radio-group button group))))
1430
1431
1432
1433 ;;; Toggle button
1434
1435 (defbinding toggle-button-toggled () nil
1436 (toggle-button toggle-button))
1437
1438
1439 ;;; Window
1440
1441 (defmethod initialize-instance ((window window) &rest initargs
1442 &key display accel-group accel-groups)
1443 (declare (ignore accel-group accel-groups))
1444 (prog1
1445 (if display
1446 (apply #'call-next-method
1447 window :screen (gdk:display-get-default-screen (gdk:ensure-display display)) initargs)
1448 (call-next-method))
1449 (initial-add window #'window-add-accel-group
1450 initargs :accel-group :accel-groups)))
1451
1452 #-debug-ref-counting
1453 (defmethod print-object ((window window) stream)
1454 (if (and
1455 (proxy-valid-p window)
1456 (slot-boundp window 'title)
1457 (not (zerop (length (window-title window)))))
1458 (print-unreadable-object (window stream :type t :identity nil)
1459 (format stream "~S at 0x~X"
1460 (window-title window) (pointer-address (foreign-location window))))
1461 (call-next-method)))
1462
1463 (defbinding window-set-wmclass () nil
1464 (window window)
1465 (wmclass-name string)
1466 (wmclass-class string))
1467
1468 (defbinding window-add-accel-group () nil
1469 (window window)
1470 (accel-group accel-group))
1471
1472 (defbinding window-remove-accel-group () nil
1473 (window window)
1474 (accel-group accel-group))
1475
1476 (defbinding window-activate-focus () int
1477 (window window))
1478
1479 (defbinding window-activate-default () int
1480 (window window))
1481
1482 (defbinding window-set-default-size (window width height) int
1483 (window window)
1484 ((or width -1) int)
1485 ((or height -1) int))
1486
1487 (defbinding %window-set-geometry-hints () nil
1488 (window window)
1489 (widget (or widget null))
1490 (geometry gdk:geometry)
1491 (geometry-mask gdk:window-hints))
1492
1493 (defun window-set-geometry-hints (window &key widget min-width min-height
1494 max-width max-height base-width base-height
1495 width-inc height-inc gravity
1496 aspect (min-aspect aspect) (max-aspect aspect))
1497 (let ((geometry (make-instance 'gdk:geometry
1498 :min-width (or min-width -1)
1499 :min-height (or min-height -1)
1500 :max-width (or max-width -1)
1501 :max-height (or max-height -1)
1502 :base-width (or base-width 0)
1503 :base-height (or base-height 0)
1504 :width-inc (or width-inc 0)
1505 :height-inc (or height-inc 0)
1506 :min-aspect (or min-aspect 0)
1507 :max-aspect (or max-aspect 0)))
1508 (mask ()))
1509 (when (or min-width min-height)
1510 (push :min-size mask))
1511 (when (or max-width max-height)
1512 (push :max-size mask))
1513 (when (or base-width base-height)
1514 (push :base-size mask))
1515 (when (or width-inc height-inc)
1516 (push :resize-inc mask))
1517 (when (or min-aspect max-aspect)
1518 (push :aspect mask))
1519 (when gravity
1520 (push :win-gravity mask)
1521 (setf (gdk:geometry-gravity geometry) gravity))
1522 (%window-set-geometry-hints window widget geometry mask)))
1523
1524 (defbinding window-list-toplevels () (glist (copy-of window))
1525 "Returns a list of all existing toplevel windows.")
1526
1527 (defbinding window-add-mnemonic (window key target) nil
1528 (window window)
1529 ((gdk:keyval-from-name key) unsigned-int)
1530 (target widget))
1531
1532 (defbinding window-remove-mnemonic (window key target) nil
1533 (window window)
1534 ((gdk:keyval-from-name key) unsigned-int)
1535 (target widget))
1536
1537 (defbinding window-mnemonic-activate (window key modifier) nil
1538 (window window)
1539 ((gdk:keyval-from-name key) unsigned-int)
1540 (modifier gdk:modifier-type))
1541
1542 (defbinding window-activate-key () boolean
1543 (window window)
1544 (event gdk:key-event))
1545
1546 (defbinding window-propagate-key-event () boolean
1547 (window window)
1548 (event gdk:key-event))
1549
1550 #?-(pkg-exists-p "gtk+-2.0" :atleast-version "2.8.0")
1551 (defbinding window-present () nil
1552 (window window))
1553
1554 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.8.0")
1555 (progn
1556 (defbinding %window-present () nil
1557 (window window))
1558
1559 (defbinding %window-present-with-time () nil
1560 (window window)
1561 (timespamp unsigned-int))
1562
1563 (defun window-present (window &optional timestamp)
1564 (if timestamp
1565 (%window-present-with-time window timestamp)
1566 (%window-present window))))
1567
1568 (defbinding window-iconify () nil
1569 (window window))
1570
1571 (defbinding window-deiconify () nil
1572 (window window))
1573
1574 (defbinding window-stick () nil
1575 (window window))
1576
1577 (defbinding window-unstick () nil
1578 (window window))
1579
1580 (defbinding window-maximize () nil
1581 (window window))
1582
1583 (defbinding window-unmaximize () nil
1584 (window window))
1585
1586 (defbinding window-fullscreen () nil
1587 (window window))
1588
1589 (defbinding window-unfullscreen () nil
1590 (window window))
1591
1592 (defbinding window-set-keep-above () nil
1593 (window window)
1594 (setting boolean))
1595
1596 (defbinding window-set-keep-below () nil
1597 (window window)
1598 (setting boolean))
1599
1600 (defbinding window-begin-resize-drag () nil
1601 (window window)
1602 (edge gdk:window-edge)
1603 (button int)
1604 (root-x int) (root-y int)
1605 (timestamp unsigned-int))
1606
1607 (defbinding window-begin-move-drag () nil
1608 (window window)
1609 (edge gdk:window-edge)
1610 (button int)
1611 (root-x int) (root-y int)
1612 (timestamp unsigned-int))
1613
1614 (defbinding window-set-frame-dimensions () nil
1615 (window window)
1616 (left int) (top int) (rigth int) (bottom int))
1617
1618 (defbinding %window-get-default-size () nil
1619 (window window)
1620 (width int :out)
1621 (height int :out))
1622
1623 (defun window-get-default-size (window)
1624 (multiple-value-bind (width height) (%window-get-default-size window)
1625 (values (unless (= width -1) width) (unless (= height -1) height))))
1626
1627 (defbinding window-get-frame-dimensions () nil
1628 (window window)
1629 (left int :out) (top int :out) (rigth int :out) (bottom int :out))
1630
1631 (defbinding %window-get-icon-list () (glist (copy-of gdk:pixbuf))
1632 (window window))
1633
1634 (defbinding window-get-position () nil
1635 (window window)
1636 (root-x int :out)
1637 (root-y int :out))
1638
1639 (defbinding window-get-size () nil
1640 (window window)
1641 (width int :out)
1642 (height int :out))
1643
1644 (defbinding window-move () nil
1645 (window window)
1646 (x int)
1647 (y int))
1648
1649 (defbinding window-parse-geometry () boolean
1650 (window window)
1651 (geometry string))
1652
1653 (defbinding window-reshow-with-initial-size () nil
1654 (window window))
1655
1656 (defbinding window-resize () nil
1657 (window window)
1658 (width int)
1659 (heigth int))
1660
1661 (defbinding (window-default-icon-list "gtk_window_get_default_icon_list")
1662 () (glist gdk:pixbuf))
1663
1664 (defun window-default-icon ()
1665 (first (window-default-icon-list)))
1666
1667 (defbinding %window-set-default-icon-list () nil
1668 (icons (glist gdk:pixbuf)))
1669
1670 (defun (setf window-default-icon-list) (icons)
1671 (%window-set-default-icon-list icons)
1672 icons)
1673
1674 (defbinding %window-set-default-icon () nil
1675 (icons (glist gdk:pixbuf)))
1676
1677 (defgeneric (setf window-default-icon) (icon))
1678
1679 (defmethod (setf window-default-icon) ((icon gdk:pixbuf))
1680 (%window-set-default-icon icon)
1681 icon)
1682
1683 (defgeneric (setf window-group) (group window))
1684
1685 (defmethod (setf window-group) ((group window-group) (window window))
1686 (window-group-add-window group window)
1687 group)
1688
1689 (defbinding %window-set-default-icon-from-file () boolean
1690 (filename pathname)
1691 (nil null))
1692
1693 (defmethod (setf window-default-icon) ((icon-file pathname))
1694 (%window-set-default-icon-from-file icon-file)
1695 icon-file)
1696
1697 (defbinding %window-set-icon-from-file () boolean
1698 (window window)
1699 (filename pathname)
1700 (nil null))
1701
1702 (defmethod (setf window-icon) ((icon-file pathname) (window window))
1703 (%window-set-icon-from-file window icon-file)
1704 icon-file)
1705
1706 (defbinding window-set-auto-startup-notification () nil
1707 (setting boolean))
1708
1709 (defbinding decorated-window-init () nil
1710 (window window))
1711
1712 (defbinding decorated-window-calculate-frame-size () nil
1713 (window window))
1714
1715 (defbinding decorated-window-set-title () nil
1716 (window window)
1717 (title string))
1718
1719 (defbinding decorated-window-move-resize-window () nil
1720 (window window)
1721 (x int)
1722 (y int)
1723 (width int)
1724 (heigth int))
1725
1726
1727 ;;; Window group
1728
1729 (defmethod initialize-instance ((window-group window-group) &rest initargs
1730 &key window windows)
1731 (declare (ignore window windows))
1732 (prog1
1733 (call-next-method)
1734 (initial-add window-group #'window-group-add-window
1735 initargs :window :windows)))
1736
1737
1738 (defbinding window-group-add-window () nil
1739 (window-group window-group)
1740 (window window))
1741
1742 (defbinding window-group-remove-window () nil
1743 (window-group window-group)
1744 (window window))
1745
1746
1747 ;;; Scrolled window
1748
1749 (defun (setf scrolled-window-scrollbar-policy) (policy window)
1750 (setf (scrolled-window-hscrollbar-policy window) policy)
1751 (setf (scrolled-window-vscrollbar-policy window) policy))
1752
1753 (defbinding scrolled-window-add-with-viewport () nil
1754 (scrolled-window scrolled-window)
1755 (child widget))
1756
1757 (defmethod shared-initialize ((window scrolled-window) names &key policy)
1758 (declare (ignore names))
1759 (when policy
1760 (setf (slot-value window 'hscrollbar-policy) policy)
1761 (setf (slot-value window 'vscrollbar-policy) policy))
1762 (call-next-method))
1763
1764
1765 ;;; Statusbar
1766
1767 (defbinding statusbar-get-context-id () unsigned-int
1768 (statusbar statusbar)
1769 (context-description string))
1770
1771 (defbinding statusbar-push () unsigned-int
1772 (statusbar statusbar)
1773 (context-id unsigned-int)
1774 (text string))
1775
1776 (defbinding statusbar-pop () nil
1777 (statusbar statusbar)
1778 (context-id unsigned-int))
1779
1780 (defbinding statusbar-remove () nil
1781 (statusbar statusbar)
1782 (context-id unsigned-int)
1783 (message-id unsigned-int))
1784
1785
1786
1787 ;;; Fixed
1788
1789 (defbinding fixed-put () nil
1790 (fixed fixed)
1791 (widget widget)
1792 (x int) (y int))
1793
1794 (defbinding fixed-move () nil
1795 (fixed fixed)
1796 (widget widget)
1797 (x int) (y int))
1798
1799
1800
1801 ;;; Notebook
1802
1803 (defun %ensure-notebook-position (notebook page)
1804 (etypecase page
1805 (position page)
1806 (widget (notebook-page-num notebook page t))))
1807
1808 (defun %ensure-notebook-child (notebook position)
1809 (typecase position
1810 (widget position)
1811 (t (notebook-get-nth-page notebook position))))
1812
1813 (defbinding (notebook-insert "gtk_notebook_insert_page_menu")
1814 (notebook position child &optional tab-label menu-label) nil
1815 (notebook notebook)
1816 (child widget)
1817 ((if (stringp tab-label)
1818 (make-instance 'label :label tab-label)
1819 tab-label) (or null widget))
1820 ((if (stringp menu-label)
1821 (make-instance 'label :label menu-label)
1822 menu-label) (or null widget))
1823 ((%ensure-notebook-position notebook position) position))
1824
1825 (defun notebook-append (notebook child &optional tab-label menu-label)
1826 (notebook-insert notebook :last child tab-label menu-label))
1827
1828 (defun notebook-prepend (notebook child &optional tab-label menu-label)
1829 (notebook-insert notebook :first child tab-label menu-label))
1830
1831 (defbinding notebook-remove-page (notebook page) nil
1832 (notebook notebook)
1833 ((%ensure-notebook-position notebook page) position))
1834
1835 (defbinding %notebook-page-num () int
1836 (notebook notebook)
1837 (child widget))
1838
1839 (defun notebook-page-num (notebook child &optional error-p)
1840 (let ((page-num (%notebook-page-num notebook child)))
1841 (if (= page-num -1)
1842 (when error-p
1843 (error "~A is not a page in ~A" child notebook))
1844 page-num)))
1845
1846 (defbinding notebook-next-page () nil
1847 (notebook notebook))
1848
1849 (defbinding notebook-prev-page () nil
1850 (notebook notebook))
1851
1852 (defbinding notebook-reorder-child (notebook child position) nil
1853 (notebook notebook)
1854 (child widget)
1855 ((%ensure-notebook-position notebook position) int))
1856
1857 (defbinding notebook-popup-enable () nil
1858 (notebook notebook))
1859
1860 (defbinding notebook-popup-disable () nil
1861 (notebook notebook))
1862
1863 (defbinding notebook-get-nth-page () widget
1864 (notebook notebook)
1865 (page position))
1866
1867 (defun %notebook-current-page (notebook)
1868 (when (slot-boundp notebook 'current-page-num)
1869 (notebook-get-nth-page notebook (notebook-current-page-num notebook))))
1870
1871 (defun (setf notebook-current-page) (page notebook)
1872 (setf (notebook-current-page-num notebook) (notebook-page-num notebook page)))
1873
1874 (defbinding (notebook-tab-label "gtk_notebook_get_tab_label")
1875 (notebook page) widget
1876 (notebook notebook)
1877 ((%ensure-notebook-child notebook page) widget))
1878
1879 (defbinding (notebook-tab-label-text "gtk_notebook_get_tab_label_text")
1880 (notebook page) (copy-of string)
1881 (notebook notebook)
1882 ((%ensure-notebook-child notebook page) widget))
1883
1884 (defbinding %notebook-set-tab-label () nil
1885 (notebook notebook)
1886 (page widget)
1887 (tab-label widget))
1888
1889 (defun (setf notebook-tab-label) (tab-label notebook page)
1890 (let ((widget (if (stringp tab-label)
1891 (make-instance 'label :label tab-label)
1892 tab-label)))
1893 (%notebook-set-tab-label notebook (%ensure-notebook-child notebook page) widget)
1894 widget))
1895
1896
1897 (defbinding (notebook-menu-label "gtk_notebook_get_menu_label")
1898 (notebook page) widget
1899 (notebook notebook)
1900 ((%ensure-notebook-child notebook page) widget))
1901
1902 (defbinding (notebook-menu-label-text "gtk_notebook_get_menu_label_text")
1903 (notebook page) (copy-of string)
1904 (notebook notebook)
1905 ((%ensure-notebook-child notebook page) widget))
1906
1907 (defbinding %notebook-set-menu-label () nil
1908 (notebook notebook)
1909 (page widget)
1910 (menu-label widget))
1911
1912 (defun (setf notebook-menu-label) (menu-label notebook page)
1913 (let ((widget (if (stringp menu-label)
1914 (make-instance 'label :label menu-label)
1915 menu-label)))
1916 (%notebook-set-menu-label notebook (%ensure-notebook-child notebook page) widget)
1917 widget))
1918
1919
1920 (defbinding notebook-query-tab-label-packing (notebook page) nil
1921 (notebook notebook)
1922 ((%ensure-notebook-child notebook page) widget)
1923 (expand boolean :out)
1924 (fill boolean :out)
1925 (pack-type pack-type :out))
1926
1927 (defbinding notebook-set-tab-label-packing
1928 (notebook page expand fill pack-type) nil
1929 (notebook notebook)
1930 ((%ensure-notebook-child notebook page) widget)
1931 (expand boolean)
1932 (fill boolean)
1933 (pack-type pack-type))
1934
1935
1936
1937 ;;; Paned
1938
1939 (defbinding paned-pack1 () nil
1940 (paned paned)
1941 (child widget)
1942 (resize boolean)
1943 (shrink boolean))
1944
1945 (defbinding paned-pack2 () nil
1946 (paned paned)
1947 (child widget)
1948 (resize boolean)
1949 (shrink boolean))
1950
1951
1952 ;;; Layout
1953
1954 (defbinding layout-put () nil
1955 (layout layout)
1956 (child widget)
1957 (x int)
1958 (y int))
1959
1960 (defbinding layout-move () nil
1961 (layout layout)
1962 (child widget)
1963 (x int)
1964 (y int))
1965
1966 (defbinding layout-set-size () nil
1967 (layout layout)
1968 (width unsigned-int)
1969 (height unsigned-int))
1970
1971 (defbinding layout-get-size () nil
1972 (layout layout)
1973 (width unsigned-int :out)
1974 (height unsigned-int :out))
1975
1976
1977 ;;; Menu shell
1978
1979 (defbinding menu-shell-insert (menu-shell menu-item position) nil
1980 (menu-shell menu-shell)
1981 (menu-item menu-item)
1982 ((case position
1983 (:first 0)
1984 (:last -1)
1985 (t position)) int))
1986
1987 (defun menu-shell-append (menu-shell menu-item)
1988 (menu-shell-insert menu-shell menu-item :last))
1989
1990 (defun menu-shell-prepend (menu-shell menu-item)
1991 (menu-shell-insert menu-shell menu-item :fisrt))
1992
1993 (defbinding menu-shell-deactivate () nil
1994 (menu-shell menu-shell))
1995
1996 (defbinding menu-shell-select-item () nil
1997 (menu-shell menu-shell)
1998 (menu-item menu-item))
1999
2000 (defbinding menu-shell-select-first () nil
2001 (menu-shell menu-shell)
2002 (search-sensitive boolean))
2003
2004 (defbinding menu-shell-deselect () nil
2005 (menu-shell menu-shell))
2006
2007 (defbinding menu-shell-activate-item () nil
2008 (menu-shell menu-shell)
2009 (menu-item menu-item)
2010 (fore-deactivate boolean))
2011
2012 (defbinding menu-shell-cancel () nil
2013 (menu-shell menu-shell))
2014
2015
2016 ;;; Menu
2017
2018 (defun %menu-position (menu child)
2019 (etypecase child
2020 (int child)
2021 (keyword (case child
2022 (:first 0)
2023 (:last -1)
2024 (t (error "Invalid position keyword: ~A" child))))
2025 (widget (menu-child-position menu child))))
2026
2027
2028 (defbinding menu-reorder-child (menu menu-item position) nil
2029 (menu menu)
2030 (menu-item menu-item)
2031 ((%menu-position menu position) int))
2032
2033 (defbinding menu-attach () nil
2034 (menu menu)
2035 (menu-item menu-item)
2036 (left-attach unsigned-int)
2037 (right-attach unsigned-int)
2038 (top-attach unsigned-int)
2039 (bottom-attach unsigned-int))
2040
2041 (define-callback-marshal %menu-position-callback nil
2042 (menu (x int) (y int) (push-in boolean)))
2043
2044 (defbinding %menu-popup () nil
2045 (menu menu)
2046 (parent-menu-shell (or null menu-shell))
2047 (parent-menu-item (or null menu-item))
2048 (callback (or null callback))
2049 (callback-id unsigned-int)
2050 (button unsigned-int)
2051 (activate-time (unsigned 32)))
2052
2053 (defun menu-popup (menu button activate-time &key callback parent-menu-shell
2054 parent-menu-item)
2055 (if callback
2056 (with-callback-function (id callback)
2057 (%menu-popup
2058 menu parent-menu-shell parent-menu-item
2059 %menu-position-callback id button activate-time))
2060 (%menu-popup
2061 menu parent-menu-shell parent-menu-item nil 0 button activate-time)))
2062
2063 (defbinding menu-set-accel-path () nil
2064 (menu menu)
2065 (accel-path string))
2066
2067 (defbinding menu-reposition () nil
2068 (menu menu))
2069
2070 (defbinding menu-popdown () nil
2071 (menu menu))
2072
2073 (defun menu-child-position (menu child)
2074 (position child (container-children menu)))
2075
2076 (defun menu-active-num (menu)
2077 (menu-child-position menu (menu-active menu)))
2078
2079 (defbinding %menu-set-active () nil
2080 (menu menu)
2081 (index unsigned-int))
2082
2083 (defun (setf menu-active) (menu child)
2084 (%menu-set-active menu (%menu-position menu child))
2085 child)
2086
2087 (define-callback %menu-detach-callback nil ((widget widget) (menu menu))
2088 (funcall (user-data menu 'detach-func) widget menu))
2089
2090 (defbinding %menu-attach-to-widget (menu widget) nil
2091 (menu menu)
2092 (widget widget)
2093 (%menu-detach-callback callback))
2094
2095 (defun menu-attach-to-widget (menu widget function)
2096 (setf (user-data menu 'detach-func) function)
2097 (%menu-attach-to-widget menu widget))
2098
2099 (defbinding menu-detach () nil
2100 (menu menu))
2101
2102 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
2103 (defbinding menu-get-for-attach-widget () (copy-of (glist widget))
2104 (widget widget))
2105
2106 (defbinding menu-set-monitor () nil
2107 (menu menu)
2108 (monitor-num int))
2109
2110
2111 ;;; Table
2112
2113 (defbinding table-resize () nil
2114 (table table)
2115 (rows unsigned-int)
2116 (columns unsigned-int))
2117
2118 (defbinding table-attach (table child left right top bottom
2119 &key options x-options y-options
2120 (x-padding 0) (y-padding 0)) nil
2121 (table table)
2122 (child widget)
2123 (left unsigned-int)
2124 (right unsigned-int)
2125 (top unsigned-int)
2126 (bottom unsigned-int)
2127 ((append (mklist options) (mklist x-options)) attach-options)
2128 ((append (mklist options) (mklist y-options)) attach-options)
2129 (x-padding unsigned-int)
2130 (y-padding unsigned-int))
2131
2132
2133 (defbinding %table-set-row-spacing () nil
2134 (table table)
2135 (row unsigned-int)
2136 (spacing unsigned-int))
2137
2138 (defbinding %table-set-row-spacings () nil
2139 (table table)
2140 (spacing unsigned-int))
2141
2142 (defun (setf table-row-spacing) (spacing table &optional row)
2143 (if row
2144 (%table-set-row-spacing table row spacing)
2145 (%table-set-row-spacings table spacing))
2146 spacing)
2147
2148 (defbinding %table-get-row-spacing () unsigned-int
2149 (table table)
2150 (row unsigned-int))
2151
2152 (defbinding %table-get-default-row-spacing () unsigned-int
2153 (table table))
2154
2155 (defun table-row-spacing (table &optional row)
2156 (if row
2157 (%table-get-row-spacing table row)
2158 (%table-get-default-row-spacing table)))
2159
2160
2161 (defbinding %table-set-col-spacing () nil
2162 (table table)
2163 (col unsigned-int)
2164 (spacing unsigned-int))
2165
2166 (defbinding %table-set-col-spacings () nil
2167 (table table)
2168 (spacing unsigned-int))
2169
2170 (defun (setf table-column-spacing) (spacing table &optional column)
2171 (if column
2172 (%table-set-col-spacing table column spacing)
2173 (%table-set-col-spacings table spacing))
2174 spacing)
2175
2176 (defun (setf table-col-spacing) (spacing table &optional col)
2177 (warn "TABLE-COL-SPACING is deprecatet, use TABLE-COLUMN-SPACING instead")
2178 (setf (table-column-spacing table col) spacing))
2179
2180 (defbinding %table-get-col-spacing () unsigned-int
2181 (table table)
2182 (col unsigned-int))
2183
2184 (defbinding %table-get-default-col-spacing () unsigned-int
2185 (table table))
2186
2187 (defun table-column-spacing (table &optional column)
2188 (if column
2189 (%table-get-col-spacing table column)
2190 (%table-get-default-col-spacing table)))
2191
2192 (defun table-col-spacing (table &optional col)
2193 (warn "TABLE-COL-SPACING is deprecatet, use TABLE-COLUMN-SPACING instead")
2194 (table-column-spacing table col))
2195
2196
2197
2198 ;;; Toolbar
2199
2200 (defmethod initialize-instance ((toolbar toolbar) &rest initargs &key tooltips)
2201 (if (eq tooltips t)
2202 (apply #'call-next-method toolbar
2203 :tooltips (make-instance 'tooltips) initargs)
2204 (call-next-method)))
2205
2206 (defbinding %toolbar-insert () nil
2207 (toolbar toolbar)
2208 (tool-item tool-item)
2209 (position position))
2210
2211 (defun toolbar-insert (toolbar tool-item &optional (position :end))
2212 (%toolbar-insert toolbar tool-item position)
2213 (%tool-item-update-tooltips tool-item))
2214
2215 (defbinding toolbar-get-item-index () int
2216 (toolbar toolbar)
2217 (item tool-item))
2218
2219 (defbinding toolbar-get-nth-item () tool-item
2220 (toolbar toolbar)
2221 (n int))
2222
2223 (defbinding toolbar-get-drop-index () int
2224 (toolbar toolbar)
2225 (x int) (y int))
2226
2227 (defbinding toolbar-set-drop-highlight-item () nil
2228 (toolbar toolbar)
2229 (tool-item tool-item)
2230 (index int))
2231
2232
2233 ;;; Tool button
2234
2235 (defmethod initialize-instance ((button tool-button) &rest initargs &key icon)
2236 (if (and icon (not (typep icon 'widget)))
2237 (apply #'call-next-method button :icon (create-image-widget icon) initargs)
2238 (call-next-method)))
2239
2240
2241 ;;; Tool item
2242
2243 (defbinding tool-item-set-tooltip () nil
2244 (tool-item tool-item)
2245 (tooltips tooltips)
2246 (tip-text string)
2247 (tip-private string))
2248
2249
2250 (defun %tool-item-update-tooltips (tool-item)
2251 (when (and
2252 (slot-boundp tool-item 'parent)
2253 (or
2254 (user-data-p tool-item 'tip-text)
2255 (user-data-p tool-item 'tip-private)))
2256 (tool-item-set-tooltip
2257 tool-item (toolbar-tooltips (widget-parent tool-item))
2258 (or (user-data tool-item 'tip-text) "")
2259 (or (user-data tool-item 'tip-private) ""))))
2260
2261 (defmethod (setf tool-item-tip-text) ((tip-text string) (tool-item tool-item))
2262 (setf (user-data tool-item 'tip-text) tip-text)
2263 (%tool-item-update-tooltips tool-item)
2264 tip-text)
2265
2266 (defmethod (setf tool-item-tip-private) ((tip-private string) (tool-item tool-item))
2267 (setf (user-data tool-item 'tip-private) tip-private)
2268 (%tool-item-update-tooltips tool-item)
2269 tip-private)
2270
2271 (defmethod container-add ((toolbar toolbar) (tool-item tool-item) &rest args)
2272 (declare (ignore args))
2273 (prog1
2274 (call-next-method)
2275 (%tool-item-update-tooltips tool-item)))
2276
2277
2278 (defbinding tool-item-retrieve-proxy-menu-item () widget
2279 (tool-item tool-item))
2280
2281 (defbinding (tool-item-proxy-menu-item
2282 "gtk_tool_item_get_proxy_menu_item") () menu-item
2283 (tool-item tool-item)
2284 (menu-item-id string))
2285
2286 (defbinding %tool-item-set-proxy-menu-item () nil
2287 (tool-item tool-item)
2288 (menu-item-id string)
2289 (menu-item menu-item))
2290
2291 (defun (setf tool-item-proxy-menu-item) (menu-item menu-item-id tool-item)
2292 (%tool-item-set-proxy-menu-item menu-item-id tool-item menu-item)
2293 menu-item)
2294
2295 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
2296 (defbinding tool-item-rebuild-menu () nil
2297 (tool-item tool-item))
2298
2299
2300 ;;; Editable
2301
2302 (defbinding editable-select-region (editable &optional (start 0) end) nil
2303 (editable editable)
2304 (start int)
2305 ((or end -1) int))
2306
2307 (defbinding editable-get-selection-bounds (editable) nil
2308 (editable editable)
2309 (start int :out)
2310 (end int :out))
2311
2312 (defbinding editable-insert-text (editable text &optional (position 0)) nil
2313 (editable editable)
2314 (text string)
2315 ((length text) int)
2316 (position position :in/out))
2317
2318 (defun editable-append-text (editable text)
2319 (editable-insert-text editable text nil))
2320
2321 (defun editable-prepend-text (editable text)
2322 (editable-insert-text editable text 0))
2323
2324 (defbinding editable-delete-text (editable &optional (start 0) end) nil
2325 (editable editable)
2326 (start int)
2327 ((or end -1) int))
2328
2329 (defbinding (editable-text "gtk_editable_get_chars")
2330 (editable &optional (start 0) end) string
2331 (editable editable)
2332 (start int)
2333 ((or end -1) int))
2334
2335 (defun (setf editable-text) (text editable)
2336 (if text
2337 (editable-delete-text
2338 editable
2339 (editable-insert-text editable text))
2340 (editable-delete-text editable))
2341 text)
2342
2343 (defbinding editable-cut-clipboard () nil
2344 (editable editable))
2345
2346 (defbinding editable-copy-clipboard () nil
2347 (editable editable))
2348
2349 (defbinding editable-paste-clipboard () nil
2350 (editable editable))
2351
2352 (defbinding editable-delete-selection () nil
2353 (editable editable))
2354
2355
2356
2357 ;;; Spin button
2358
2359 (defbinding spin-button-configure () nil
2360 (spin-button spin-button)
2361 (adjustment adjustment)
2362 (climb-rate double-float)
2363 (digits unsigned-int))
2364
2365 (defbinding spin-button-set-range () nil
2366 (spin-button spin-button)
2367 (min double-float)
2368 (max double-float))
2369
2370 (defbinding spin-button-get-range () nil
2371 (spin-button spin-button)
2372 (min double-float :out)
2373 (max double-float :out))
2374
2375 (defun spin-button-value-as-int (spin-button)
2376 (round (spin-button-value spin-button)))
2377
2378 (defbinding %spin-button-spin () nil
2379 (spin-button spin-button)
2380 (direction spin-type)
2381 (increment double-float))
2382
2383 (defun spin-button-spin (spin-button value)
2384 (etypecase value
2385 (real (%spin-button-spin spin-button :spin-user-defined value))
2386 (spin-type (%spin-button-spin spin-button value 0))))
2387
2388
2389 (defbinding spin-button-update () nil
2390 (spin-button spin-button))
2391
2392
2393
2394 ; ;;; Ruler
2395
2396 (defbinding ruler-set-range () nil
2397 (ruler ruler)
2398 (lower single-float)
2399 (upper single-float)
2400 (position single-float)
2401 (max-size single-float))
2402
2403 (defbinding ruler-get-range () nil
2404 (ruler ruler)
2405 (lower single-float :out)
2406 (upper single-float :out)
2407 (position single-float :out)
2408 (max-size single-float :out))
2409
2410
2411
2412 ;;; Range
2413
2414 (defun range-lower (range)
2415 (adjustment-lower (range-adjustment range)))
2416
2417 (defun range-upper (range)
2418 (adjustment-upper (range-adjustment range)))
2419
2420 (defun (setf range-lower) (value range)
2421 (setf (adjustment-lower (range-adjustment range)) value))
2422
2423 (defun (setf range-upper) (value range)
2424 (setf (adjustment-upper (range-adjustment range)) value))
2425
2426 (defun range-page-increment (range)
2427 (adjustment-page-increment (range-adjustment range)))
2428
2429 (defun range-step-increment (range)
2430 (adjustment-step-increment (range-adjustment range)))
2431
2432 (defun (setf range-page-increment) (value range)
2433 (setf (adjustment-page-increment (range-adjustment range)) value))
2434
2435 (defun (setf range-step-increment) (value range)
2436 (setf (adjustment-step-increment (range-adjustment range)) value))
2437
2438 (defbinding range-set-range () nil
2439 (range range)
2440 (lower double-float)
2441 (upper double-float))
2442
2443 (defbinding range-set-increments () nil
2444 (range range)
2445 (step double-float)
2446 (page double-float))
2447
2448
2449 ;;; Scale
2450
2451 (defbinding scale-get-layout-offsets () nil
2452 (scale scale)
2453 (x int :out)
2454 (y int :out))
2455
2456
2457 ;;; Progress bar
2458
2459 (defbinding progress-bar-pulse () nil
2460 (progress-bar progress-bar))
2461
2462
2463 ;;; Size group
2464
2465 (defmethod initialize-instance ((size-group size-group) &rest initargs
2466 &key widget widgets)
2467 (declare (ignore widget widgets))
2468 (prog1
2469 (call-next-method)
2470 (initial-add size-group #'size-group-add-widget
2471 initargs :widget :widgets)))
2472
2473
2474 (defbinding size-group-add-widget () nil
2475 (size-group size-group)
2476 (widget widget))
2477
2478 (defbinding size-group-remove-widget () nil
2479 (size-group size-group)
2480 (widget widget))
2481
2482
2483 ;;; Stock items
2484
2485 (defbinding %stock-item-copy () pointer
2486 (location pointer))
2487
2488 (defbinding %stock-item-free () nil
2489 (location pointer))
2490
2491 (defbinding stock-add (stock-item) nil
2492 (stock-item stock-item)
2493 (1 unsigned-int))
2494
2495 (defbinding stock-list-ids () (gslist string))
2496
2497 (defbinding %stock-lookup () boolean
2498 (stock-id string)
2499 (location pointer))
2500
2501 (defun stock-lookup (stock-id)
2502 (with-memory (stock-item (foreign-size (find-class 'stock-item)))
2503 (when (%stock-lookup stock-id stock-item)
2504 (ensure-proxy-instance 'stock-item (%stock-item-copy stock-item)))))
2505
2506 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.8.0")
2507 (progn
2508 (define-callback-marshal %stock-translate-callback string ((path string)))
2509
2510 (defbinding (stock-set-translate-function "gtk_stock_set_translate_func")
2511 (domain function) nil
2512 (domain string)
2513 (%stock-translate-callback callback)
2514 ((register-callback-function function) unsigned-int)
2515 (user-data-destroy-callback callback)))
2516
2517
2518 ;;; Tooltip
2519
2520 ;; #?-(pkg-exists-p "gtk+-2.0" :atleast-version "2.12.0")
2521 ;; (progn
2522 ;; (defbinding %tooltip-set-markup () nil
2523 ;; tooltip
2524 ;; (markup string))
2525
2526 ;; (defbinding %tooltip-set-text () nil
2527 ;; tooltip
2528 ;; (text string))
2529
2530 ;; (defbinding %tooltip-set-icon () nil
2531 ;; tooltip
2532 ;; (icon gdk:pixbuf))
2533
2534 ;; (defbinding %tooltip-set-from-stock-icon () nil
2535 ;; tooltip
2536 ;; (stock-id string)
2537 ;; icon-size)
2538
2539 ;; (defbinding %tooltip-set-custom () nil
2540 ;; tooltip
2541 ;; widget)
2542
2543 ;; (defun tooltip-set (tooltip value &key (markup t) (icon-size :button))
2544 ;; (etypecase value
2545 ;; (string (if markup
2546 ;; (tooltip-set-markup tooltip value)
2547 ;; (tooltip-set-text tooltip value)))
2548 ;; (pixbuf (tooltip-set-icon tooltip value))
2549 ;; (keyword (tooltip-set-icon-from-stock tooltip value icon-size))
2550
2551
2552
2553 ;;; Tooltips
2554
2555 ;; GtkTooltips has been deprecated in favor of the new tooltip API
2556 ;; introduced in in GTK+ 2.12
2557
2558 (defbinding tooltips-enable () nil
2559 (tooltips tooltips))
2560
2561 (defbinding tooltips-disable () nil
2562 (tooltips tooltips))
2563
2564 (defun (setf tooltips-enabled-p) (enable tooltips)
2565 (if enable
2566 (tooltips-enable tooltips)
2567 (tooltips-disable tooltips)))
2568
2569 (defbinding tooltips-set-tip () nil
2570 (tooltips tooltips)
2571 (widget widget)
2572 (tip-text string)
2573 (tip-private string))
2574
2575 (defbinding tooltips-data-get () tooltips-data
2576 (widget widget))
2577
2578 (defbinding tooltips-force-window () nil
2579 (tooltips tooltips))
2580
2581 (defbinding tooltips-get-info-from-tip-window () boolean
2582 (tip-window window)
2583 (tooltips tooltips :out)
2584 (current-widget widget :out))
2585
2586
2587 ;;; Resource Files
2588
2589 (defbinding rc-get-style () style
2590 (widget widget))
2591
2592 (defbinding rc-get-style-by-paths (&key path class-path class) style
2593 (path (or null string))
2594 (class-path (or null string))
2595 (class gtype))
2596
2597 (defbinding rc-parse () nil
2598 (filename pathname))
2599
2600 (defbinding rc-parse-string () nil
2601 (rc-string string))
2602
2603 (defbinding %rc-reparse-all () boolean)
2604
2605 (defbinding %rc-reparse-all-for-settings () boolean
2606 (settings settings)
2607 (force-load-p boolean))
2608
2609 (defun rc-reparse-all (&optional setting force-load-p)
2610 (if setting
2611 (%rc-reparse-all-for-settings setting force-load-p)
2612 (%rc-reparse-all)))
2613
2614 (defbinding rc-reset-styles () nil
2615 (settings settings))
2616
2617 (defbinding rc-add-default-file () nil
2618 (filename pathname))
2619
2620 (defbinding rc-get-default-files ()
2621 (copy-of (null-terminated-vector (copy-of string))))
2622
2623 (defbinding rc-get-module-dir () string)
2624
2625 (defbinding rc-get-im-module-path () string)
2626
2627 (defbinding rc-get-im-module-file () string)
2628
2629 (defbinding rc-get-theme-dir () string)
2630
2631
2632 ;;; Settings
2633
2634 (defbinding (settings-get "gtk_settings_get_for_screen")
2635 (&optional (screen (gdk:display-get-default-screen))) settings
2636 (screen gdk:screen))
2637
2638
2639 ;;; Plug and Socket
2640
2641 (defbinding socket-add-id () nil
2642 (socket socket)
2643 (id gdk:native-window))
2644
2645 (defbinding %plug-new () pointer
2646 (id gdk:native-window))
2647
2648 (defmethod allocate-foreign ((plug plug) &key id)
2649 (%plug-new (or id 0)))
2650
2651
2652 ;;; Link button
2653
2654 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.10.0")
2655 (progn
2656 (define-callback-marshal %link-button-uri-callback nil (link-button (link string)))
2657
2658 (defbinding link-button-set-uri-hook (function) pointer
2659 (%link-button-uri-callback callback)
2660 ((register-callback-function function) unsigned-int)
2661 (user-data-destroy-callback callback)))
2662
2663
2664 ;;; Builder
2665
2666 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.12.0")
2667 (progn
2668 (defmethod initialize-instance ((builder builder) &key interface
2669 (connect-signals t) (package *package*))
2670 (call-next-method)
2671 (etypecase interface
2672 (null)
2673 (string (builder-add-from-string builder interface))
2674 (pathname (builder-add-from-file builder interface)))
2675 (when connect-signals
2676 (builder-connect-signals builder package)))
2677
2678
2679 (defbinding builder-add-from-file () boolean
2680 builder
2681 pathname
2682 (nil gerror-signal :out))
2683
2684 (defbinding builder-add-from-string () boolean
2685 builder
2686 (buffer string)
2687 (-1 int) ; TODO: add gsize type
2688 (nil gerror-signal :out))
2689
2690 (defbinding builder-get-object () gobject
2691 builder
2692 (name string))
2693
2694 (defbinding builder-get-objects () (gslist gobject)
2695 builder)
2696
2697 (defun intern-with-package-prefix (name default-package)
2698 (let ((pos (position #\: name)))
2699 (if pos
2700 (intern
2701 (string-upcase (subseq name (1+ pos)))
2702 (string-upcase (subseq name 0 pos)))
2703 (intern (string-upcase name) default-package))))
2704
2705 (define-callback %builder-connect-function nil
2706 (builder (object gobject) (signal-name string) (handler-name string)
2707 (connect-object gobject) connect-flags (package user-data-id))
2708 (format t "Connect signal ~A for ~A to ~A in default package ~A with flags ~A~%" signal-name object handler-name (find-user-data package) connect-flags)
2709 (signal-connect
2710 object signal-name
2711 (intern-with-package-prefix handler-name (find-user-data package))
2712 :object (or connect-object object) :after (find :after connect-flags)))
2713
2714 (defbinding %builder-connect-signals-full (builder package) nil
2715 builder
2716 (%builder-connect-function callback)
2717 (package user-data-id))
2718
2719 (defun builder-connect-signals (builder &optional (package *package*))
2720 (with-user-data (id package)
2721 (%builder-connect-signals-full builder id))))
2722