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