chiark / gitweb /
Added bindings to GtkAssistant
[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.77 2007-07-05 11:34:27 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     (let ((main-running (sb-thread:make-waitqueue)))
191       (gdk:with-global-lock
192        (setf *main-thread*
193         (sb-thread:make-thread 
194          #'(lambda () 
195              (gdk:threads-init)  
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        swank::*slime-repl-eval-hooks*))))
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-groups)
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-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   (if (< id 0)
810       (int-to-response-type id)
811     (aref (user-data dialog 'responses) id)))
812
813
814 (defmethod compute-signal-id ((dialog dialog) signal)
815   (if (dialog-response-id dialog signal)
816       (ensure-signal-id 'response dialog)
817     (call-next-method)))
818
819 (defmethod compute-signal-function ((dialog dialog) signal function object args)
820   (declare (ignore function object args))
821   (let ((callback (call-next-method))
822         (id (dialog-response-id dialog signal)))
823     (if id
824         #'(lambda (dialog response)
825             (when (= response id)
826               (funcall callback dialog)))
827       callback)))
828
829 (defbinding dialog-run () nil
830   (dialog dialog))
831
832 (defbinding dialog-response (dialog response) nil
833   (dialog dialog)
834   ((dialog-response-id dialog response nil t) int))
835
836
837 (defbinding %dialog-add-button () button
838   (dialog dialog)
839   (text string)
840   (response-id int))
841
842 (defun dialog-add-button (dialog label &optional (response label)
843                           &key default object after)
844   "Adds a button to the dialog."
845   (let* ((signal (if (functionp response)
846                      label
847                    response))
848          (id (dialog-response-id dialog signal t))
849          (button (%dialog-add-button dialog label id)))
850     (when (functionp response)
851        (signal-connect dialog signal response :object object :after after))
852     (when default
853       (%dialog-set-default-response dialog id))
854     button))
855
856
857 (defbinding %dialog-add-action-widget () nil
858   (dialog dialog)
859   (action-widget widget)
860   (response-id int))
861
862 (defun dialog-add-action-widget (dialog widget &optional (response widget)
863                                  &key default object after)
864   (let* ((signal (if (functionp response)
865                      widget
866                    response))
867          (id (dialog-response-id dialog signal t)))
868     (unless (widget-hidden-p widget)
869       (widget-show widget))
870     (%dialog-add-action-widget dialog widget id)
871     (when (functionp response)
872        (signal-connect dialog signal response :object object :after after))
873     (when default
874       (%dialog-set-default-response dialog id))
875     widget))
876
877
878 (defbinding %dialog-set-default-response () nil
879   (dialog dialog)
880   (response-id int))
881
882 (defun dialog-set-default-response (dialog response)
883   (%dialog-set-default-response
884    dialog (dialog-response-id dialog response nil t)))
885
886 (defbinding dialog-set-response-sensitive (dialog response sensitive) nil
887   (dialog dialog)
888   ((dialog-response-id dialog response nil t) int)
889   (sensitive boolean))
890
891 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
892 (defbinding alternative-dialog-button-order-p (&optional screen) boolean
893   (screen (or null gdk:screen)))
894
895 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
896 (defbinding (dialog-set-alternative-button-order 
897              "gtk_dialog_set_alternative_button_order_from_array")
898     (dialog new-order) nil
899   (dialog dialog)
900   ((length new-order) int)
901   ((map 'vector #'(lambda (response)
902                     (dialog-response-id dialog response nil t))
903         new-order) (vector int)))
904
905
906 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.8.0")
907 (progn
908   (defbinding %dialog-get-response-for-widget () int
909     (dialog dialog)
910     (widget widget))
911
912   (defun dialog-get-response-for-widget (dialog widget)
913     (dialog-find-response dialog (dialog-get-response-for-widget dialog widget))))
914
915
916 (defmethod container-add ((dialog dialog) (child widget) &rest args)
917   (apply #'container-add (dialog-vbox dialog) child args))
918
919
920 (defmethod container-remove ((dialog dialog) (child widget))
921   (container-remove (dialog-vbox dialog) child))
922
923 (defmethod container-children ((dialog dialog))
924   (container-children (dialog-vbox dialog)))
925
926 (defmethod (setf container-children) (children (dialog dialog))
927   (setf (container-children (dialog-vbox dialog)) children))
928
929
930 ;;; Drawing Area
931
932 (defun drawing-area-scroll (drawing-area dx dy)
933   (gdk:window-scroll (widget-window drawing-area) dx dy))
934
935
936 ;;; Entry
937
938 (defbinding entry-get-layout-offsets () nil
939   (entry entry)
940   (x int :out)
941   (y int :out))
942
943 (defbinding entry-layout-index-to-text-index () int
944   (entry entry)
945   (layout-index int))
946
947 (defbinding entry-text-index-to-layout-index () int
948   (entry entry)
949   (text-index int))
950
951
952 ;;; Entry Completion
953
954 (define-callback-marshal %entry-completion-match-callback boolean 
955   (entry-completion string tree-iter))
956
957 (defbinding entry-completion-set-match-func (completion function) nil
958   (completion entry-completion)
959   (%entry-completion-match-callback callback)
960   ((register-callback-function function) unsigned-int)
961   (user-data-destroy-callback callback))
962
963 (defbinding entry-completion-complete () nil
964   (completion entry-completion))
965
966 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
967 (defbinding entry-completion-insert-prefix () nil
968   (completion entry-completion))
969
970 (defbinding entry-completion-insert-action-text () nil
971   (completion entry-completion)
972   (index int)
973   (text string))
974
975 (defbinding entry-completion-insert-action-markup () nil
976   (completion entry-completion)
977   (index int)
978   (markup string))
979
980 (defbinding entry-completion-delete-action () nil
981   (completion entry-completion)
982   (index int))
983
984
985 ;;; File Chooser
986
987 (defmethod initialize-instance ((file-chooser file-chooser) &rest initargs 
988                                 &key filter filters shortcut-folder 
989                                 shortcut-folders shortcut-folder-uti
990                                 shortcut-folder-uris)
991   (declare (ignore filter filters shortcut-folder shortcut-folders 
992                    shortcut-folder-uti shortcut-folder-uris))
993   (prog1
994       (call-next-method)
995     (initial-add file-chooser #'file-chooser-add-filter
996      initargs :filer :filters)
997     (initial-add file-chooser #'file-chooser-add-shortcut-folder
998      initargs :shortcut-folder :shortcut-folders)
999     (initial-add file-chooser #'file-chooser-add-shortcut-folder-uri
1000      initargs :shortcut-folder-uri :shortcut-folders-uris)))
1001
1002
1003 (defbinding file-chooser-select-filename () boolean
1004   (file-chooser file-chooser)
1005   (filename string))
1006
1007 (defbinding file-chooser-unselect-filename () nil
1008   (file-chooser file-chooser)
1009   (filename string))
1010
1011 (defbinding file-chooser-select-all () boolean
1012   (file-chooser file-chooser))
1013
1014 (defbinding file-chooser-unselect-all () boolean
1015   (file-chooser file-chooser))
1016   
1017 (defbinding file-chooser-get-filenames () (gslist string)
1018   (file-chooser file-chooser))
1019
1020 (defbinding file-chooser-select-uri () boolean
1021   (file-chooser file-chooser)
1022   (uri string))
1023
1024 (defbinding file-chooser-unselect-uri () nil
1025   (file-chooser file-chooser)
1026   (uri string))
1027
1028 (defbinding file-chooser-get-uris () (gslist string)
1029   (file-chooser file-chooser))
1030
1031 (defbinding file-chooser-add-filter () nil
1032   (file-chooser file-chooser)
1033   (filter file-filter))
1034
1035 (defbinding file-chooser-remove-filter () nil
1036   (file-chooser file-chooser)
1037   (filter file-filter))
1038
1039 (defbinding file-chooser-list-filters () (gslist file-filter)
1040   (file-chooser file-chooser))
1041
1042 (defbinding file-chooser-add-shortcut-folder () boolean
1043   (file-chooser file-chooser)
1044   (folder string)
1045   (nil null))
1046
1047 (defbinding file-chooser-remove-shortcut-folder () nil
1048   (file-chooser file-chooser)
1049   (folder string)
1050   (nil null))
1051
1052 (defbinding file-chooser-list-shortcut-folders () (gslist string)
1053   (file-chooser file-chooser))
1054
1055 (defbinding file-chooser-add-shortcut-folder-uri () boolean
1056   (file-chooser file-chooser)
1057   (uri string)
1058   (nil null))
1059
1060 (defbinding file-chooser-remove-shortcut-folder-uri () nil
1061   (file-chooser file-chooser)
1062   (uri string)
1063   (nil null))
1064
1065 (defbinding file-chooser-list-shortcut-folder-uris () (gslist string)
1066   (file-chooser file-chooser))
1067
1068
1069 ;;; File Filter
1070
1071 (defmethod initialize-instance ((file-filter file-filter) &rest initargs 
1072                                 &key mime-type mime-types pattern patterns
1073                                 pixbuf-formats)
1074   (declare (ignore mime-type mime-types pattern patterns))
1075   (prog1
1076       (call-next-method)
1077     (when pixbuf-formats
1078       #?-(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
1079       (warn "Initarg :PIXBUF-FORMATS not supportet in this version of Gtk")
1080       #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
1081       (file-filter-add-pixbuf-formats file-filter))
1082     (initial-add file-filter #'file-filter-add-mime-type
1083      initargs :mime-type :mime-types)
1084     (initial-add file-filter #'file-filter-add-pattern
1085      initargs :pattern :patterns)))
1086
1087
1088 (defbinding file-filter-add-mime-type () nil
1089   (filter file-filter)
1090   (mime-type string))
1091
1092 (defbinding file-filter-add-pattern () nil
1093   (filter file-filter)
1094   (pattern string))
1095
1096 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
1097 (defbinding file-filter-add-pixbuf-formats () nil
1098   (filter file-filter))
1099
1100 (define-callback-marshal %file-filter-callback boolean (file-filter-info))
1101
1102 (defbinding file-filter-add-custom (filter needed function) nil
1103   (filter file-filter)
1104   (needed file-filter-flags)
1105   (%file-filter-callback callback)
1106   ((register-callback-function function) unsigned-int)
1107   (user-data-destroy-callback callback))
1108
1109 (defbinding file-filter-get-needed () file-filter-flags
1110   (filter file-filter))
1111
1112 (defbinding file-filter-filter () boolean
1113   (filter file-filter)
1114   (filter-info file-filter-info))
1115
1116
1117
1118 ;;; Image
1119
1120 (defbinding image-set-from-file () nil
1121   (image image)
1122   (filename pathname))
1123
1124 (defmethod (setf image-pixmap) ((data vector) (image image))
1125   (multiple-value-bind (pixmap mask) (gdk:pixmap-create data)
1126     (setf (image-pixmap image) pixmap)
1127     (setf (image-mask image) mask)))
1128
1129 (defmethod initialize-instance ((image image) &rest initargs &key pixmap file)
1130   (cond
1131    ((typep pixmap 'vector)
1132     (multiple-value-bind (pixmap mask) (gdk:pixmap-create pixmap)
1133       (apply #'call-next-method image :pixmap pixmap :mask mask initargs)))
1134    (file
1135     (prog1
1136         (call-next-method)
1137       (image-set-from-file image file)))
1138    ((call-next-method))))
1139
1140 (defun create-image-widget (source &optional mask)
1141   (etypecase source
1142     (gdk:pixbuf (make-instance 'image :pixbuf source))
1143     (string (make-instance 'image :stock source))
1144     (pathname (make-instance 'image :file source))
1145     ((or list vector) (make-instance 'image :pixmap source))
1146     (gdk:pixmap (make-instance 'image :pixmap source :mask mask))))
1147
1148 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.8.0")
1149 (defbinding image-clear () nil
1150   (image image))
1151
1152
1153
1154 ;;; Image menu item
1155
1156 (defmethod initialize-instance ((item image-menu-item) &rest initargs &key image)
1157   (if (and image (not (typep image 'widget)))
1158       (apply #'call-next-method item :image (create-image-widget image) initargs) 
1159     (call-next-method)))
1160
1161
1162 (defmethod (setf image-menu-item-image) ((widget widget) (item image-menu-item))
1163   (setf (slot-value item 'image) widget))
1164
1165 (defmethod (setf image-menu-item-image) (image (item image-menu-item))
1166   (setf (image-menu-item-image item) (create-image-widget image)))
1167
1168
1169 ;;; Label
1170
1171 (defmethod shared-initialize ((label label) names &key pattern)
1172   (declare (ignore names))
1173   (call-next-method)
1174   (when pattern
1175     (setf (label-pattern label) pattern)))
1176
1177 (defbinding label-get-layout-offsets () nil
1178   (label label)
1179   (x int :out)
1180   (y int :out))
1181
1182 (defbinding label-select-region () nil
1183   (label label)
1184   (start int)
1185   (end int))
1186
1187 (defbinding label-get-selection-bounds () boolean
1188   (label label)
1189   (start int :out)
1190   (end int :out))
1191
1192
1193
1194 ;;; Radio button
1195
1196 (defbinding %radio-button-get-group () pointer
1197   (radio-button radio-button))
1198
1199 (defbinding %radio-button-set-group () nil
1200   (radio-button radio-button)
1201   (group pointer))
1202
1203 (defmethod add-to-radio-group ((button1 radio-button) (button2 radio-button))
1204   "Add BUTTON1 to the group which BUTTON2 belongs to."
1205   (%radio-button-set-group button1 (%radio-button-get-group button2)))
1206
1207 (defun %add-activate-callback (widget signal function object after)
1208   (if object
1209       (signal-connect widget signal
1210        #'(lambda (object)
1211            (when (slot-value widget 'active)
1212              (funcall function object (slot-value widget 'value))))
1213        :object object :after after)
1214     (signal-connect widget signal 
1215      #'(lambda ()
1216          (when (slot-value widget 'active)
1217            (funcall function (slot-value widget 'value))))
1218      :after after)))
1219
1220 (defmethod activate-radio-widget ((button radio-button))
1221   (signal-emit button 'clicked))
1222
1223 (defgeneric add-activate-callback (action function &key object after))
1224
1225 (defmethod add-activate-callback ((button radio-button) function &key object after)
1226   (%add-activate-callback button 'clicked function object after))
1227
1228 (defmethod initialize-instance ((button radio-button) &key group)
1229   (prog1
1230       (call-next-method)
1231     (when group
1232       (add-to-radio-group button group))))
1233
1234
1235 ;;; Item
1236
1237 (defbinding item-select () nil
1238   (item item))
1239
1240 (defbinding item-deselect () nil
1241   (item item))
1242
1243 (defbinding item-toggle () nil
1244   (item item))
1245
1246
1247
1248 ;;; Menu item
1249
1250 (defmethod initialize-instance ((item menu-item) &key label)
1251   (prog1
1252       (call-next-method)
1253     (when label
1254       (setf (menu-item-label item) label))))
1255
1256
1257 (defun (setf menu-item-label) (label menu-item)
1258   (make-instance 'accel-label
1259    :label label :xalign 0.0 :yalign 0.5 :accel-widget menu-item
1260    :use-underline (menu-item-use-underline-p menu-item)
1261    :visible t  :parent menu-item)
1262   label)
1263
1264 (defun menu-item-label (menu-item)
1265   (when (and (slot-boundp menu-item 'child) 
1266              (typep (bin-child menu-item) 'label))
1267     (label-label (bin-child menu-item))))
1268
1269 (defbinding menu-item-remove-submenu () nil
1270   (menu-item menu-item))
1271
1272 (defbinding menu-item-set-accel-path () nil
1273   (menu-item menu-item)
1274   (accel-path string))
1275
1276 (defbinding menu-item-select () nil
1277   (menu-item menu-item))
1278
1279 (defbinding menu-item-deselect () nil
1280   (menu-item menu-item))
1281
1282 (defbinding menu-item-activate () nil
1283   (menu-item menu-item))
1284
1285 (defbinding menu-item-toggle-size-request () nil
1286   (menu-item menu-item)
1287   (requisition int :out))
1288
1289 (defbinding menu-item-toggle-size-allocate () nil
1290   (menu-item menu-item)
1291   (allocation int))
1292
1293
1294 ;;; Menu tool button
1295
1296 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
1297 (defbinding menu-tool-button-set-arrow-tooltip () nil
1298   (menu-tool-button menu-tool-button)
1299   (tooltips tooltips)
1300   (tip-text string)
1301   (tip-private string))
1302
1303
1304 ;;; Message dialog
1305
1306 (defmethod allocate-foreign ((dialog message-dialog) &key (message-type :info)
1307                              (buttons :close) flags transient-parent)
1308   (%message-dialog-new transient-parent flags message-type buttons))
1309
1310
1311 (defmethod shared-initialize ((dialog message-dialog) names &key text 
1312                               #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
1313                               secondary-text)
1314   (declare (ignore names))
1315   (when text
1316     (message-dialog-set-markup dialog text))
1317   #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
1318   (when secondary-text
1319     (message-dialog-format-secondary-markup dialog secondary-text))
1320   (call-next-method))
1321
1322
1323 (defbinding %message-dialog-new () pointer
1324   (parent (or null window))
1325   (flags dialog-flags)
1326   (type message-type)
1327   (buttons buttons-type)
1328   (nil null))
1329
1330 (defbinding message-dialog-set-markup () nil
1331   (message-dialog message-dialog)
1332   (markup string))
1333
1334 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
1335 (defbinding message-dialog-format-secondary-text () nil
1336   (message-dialog message-dialog)
1337   (text string))
1338
1339 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
1340 (defbinding message-dialog-format-secondary-markup () nil
1341   (message-dialog message-dialog)
1342   (markup string))
1343
1344
1345
1346 ;;; Radio menu item
1347
1348 (defbinding %radio-menu-item-get-group () pointer
1349   (radio-menu-item radio-menu-item))
1350
1351 (defbinding %radio-menu-item-set-group () nil
1352   (radio-menu-item radio-menu-item)
1353   (group pointer))
1354
1355 (defmethod activate-radio-widget ((item radio-menu-item))
1356   (menu-item-activate item))
1357
1358 (defmethod add-to-radio-group ((item1 radio-menu-item) (item2 radio-menu-item))
1359   "Add ITEM1 to the group which ITEM2 belongs to."
1360   (%radio-menu-item-set-group item1 (%radio-menu-item-get-group item2)))
1361
1362 (defmethod add-activate-callback ((item radio-menu-item) function &key object after)
1363   (%add-activate-callback item 'activate function object after))
1364
1365 (defmethod initialize-instance ((item radio-menu-item) &key group)
1366   (prog1
1367       (call-next-method)
1368     (when group
1369       (add-to-radio-group item group))))
1370
1371   
1372
1373 ;;; Radio tool button
1374
1375 (defbinding %radio-tool-button-get-group () pointer
1376   (radio-tool-button radio-tool-button))
1377
1378 (defbinding %radio-tool-button-set-group () nil
1379   (radio-tool-button radio-tool-button)
1380   (group pointer))
1381
1382 (defmethod activate-radio-widget ((button radio-tool-button))
1383   (signal-emit button 'clicked))
1384
1385 (defmethod add-to-radio-group ((button1 radio-tool-button) (button2 radio-tool-button))
1386   "Add BUTTON1 to the group which BUTTON2 belongs to."
1387   (%radio-tool-button-set-group button1 (%radio-tool-button-get-group button2)))
1388 (defmethod add-activate-callback ((button radio-tool-button) function &key object after)
1389   (%add-activate-callback button 'clicked function object after))
1390
1391 (defmethod initialize-instance ((button radio-tool-button) &key group)
1392   (prog1
1393       (call-next-method)
1394     (when group
1395       (add-to-radio-group button group))))
1396
1397
1398
1399 ;;; Toggle button
1400
1401 (defbinding toggle-button-toggled () nil
1402   (toggle-button toggle-button))
1403
1404
1405 ;;; Window
1406
1407 (defmethod initialize-instance ((window window) &rest initargs 
1408                                 &key display accel-group accel-groups)
1409   (declare (ignore accel-group accel-groups))
1410   (prog1
1411       (if display
1412           (apply #'call-next-method
1413            window :screen (gdk:display-get-default-screen (gdk:ensure-display display)) initargs)
1414         (call-next-method))
1415     (initial-add window #'window-add-accel-group 
1416      initargs :accel-group :accel-groups)))
1417
1418 #-debug-ref-counting
1419 (defmethod print-object ((window window) stream)
1420   (if (and 
1421        (proxy-valid-p window) 
1422        (slot-boundp window 'title) 
1423        (not (zerop (length (window-title window)))))
1424       (print-unreadable-object (window stream :type t :identity nil)
1425         (format stream "~S at 0x~X" 
1426          (window-title window) (pointer-address (foreign-location window))))
1427     (call-next-method)))
1428
1429 (defbinding window-set-wmclass () nil
1430   (window window)
1431   (wmclass-name string)
1432   (wmclass-class string))
1433
1434 (defbinding window-add-accel-group () nil
1435   (window window)
1436   (accel-group accel-group))
1437
1438 (defbinding window-remove-accel-group () nil
1439   (window window)
1440   (accel-group accel-group))
1441
1442 (defbinding window-activate-focus () int
1443   (window window))
1444
1445 (defbinding window-activate-default () int
1446   (window window))
1447
1448 (defbinding window-set-default-size (window width height) int
1449   (window window)
1450   ((or width -1) int)
1451   ((or height -1) int))
1452
1453 (defbinding %window-set-geometry-hints () nil
1454   (window window)
1455   (widget (or widget null))
1456   (geometry gdk:geometry)
1457   (geometry-mask gdk:window-hints))
1458
1459 (defun window-set-geometry-hints (window &key widget min-width min-height
1460                                   max-width max-height base-width base-height
1461                                   width-inc height-inc gravity
1462                                   aspect (min-aspect aspect) (max-aspect aspect))
1463   (let ((geometry (make-instance 'gdk:geometry 
1464                    :min-width (or min-width -1)
1465                    :min-height (or min-height -1)
1466                    :max-width (or max-width -1)
1467                    :max-height (or max-height -1)
1468                    :base-width (or base-width 0)
1469                    :base-height (or base-height 0)
1470                    :width-inc (or width-inc 0)
1471                    :height-inc (or height-inc 0)
1472                    :min-aspect (or min-aspect 0)
1473                    :max-aspect (or max-aspect 0)))
1474         (mask ()))
1475     (when (or min-width min-height)
1476       (push :min-size mask))
1477     (when (or max-width max-height)
1478       (push :max-size mask))
1479     (when (or base-width base-height)
1480       (push :base-size mask))
1481     (when (or width-inc height-inc)
1482       (push :resize-inc mask))
1483     (when (or min-aspect max-aspect)
1484       (push :aspect mask))
1485     (when gravity
1486       (push :win-gravity mask)
1487       (setf (gdk:geometry-gravity geometry) gravity))
1488     (%window-set-geometry-hints window widget geometry mask)))
1489
1490 (defbinding window-list-toplevels () (glist (copy-of window))
1491   "Returns a list of all existing toplevel windows.")
1492
1493 (defbinding window-add-mnemonic (window key target) nil
1494   (window window)
1495   ((gdk:keyval-from-name key) unsigned-int)
1496   (target widget))
1497
1498 (defbinding window-remove-mnemonic (window key target) nil
1499   (window window)
1500   ((gdk:keyval-from-name key) unsigned-int)
1501   (target widget))
1502
1503 (defbinding window-mnemonic-activate (window key modifier) nil
1504   (window window)
1505   ((gdk:keyval-from-name key) unsigned-int)
1506   (modifier gdk:modifier-type))
1507
1508 (defbinding window-activate-key () boolean
1509   (window window)
1510   (event gdk:key-event))
1511
1512 (defbinding window-propagate-key-event () boolean
1513   (window window)
1514   (event gdk:key-event))
1515
1516 #?-(pkg-exists-p "gtk+-2.0" :atleast-version "2.8.0")
1517 (defbinding window-present () nil
1518   (window window))
1519
1520 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.8.0")
1521 (progn
1522   (defbinding %window-present () nil
1523     (window window))
1524
1525   (defbinding %window-present-with-time () nil
1526     (window window)
1527     (timespamp unsigned-int))
1528
1529   (defun window-present (window &optional timestamp)
1530     (if timestamp
1531         (%window-present-with-time window timestamp)
1532       (%window-present window))))
1533
1534 (defbinding window-iconify () nil
1535   (window window))
1536
1537 (defbinding window-deiconify () nil
1538   (window window))
1539
1540 (defbinding window-stick () nil
1541   (window window))
1542
1543 (defbinding window-unstick () nil
1544   (window window))
1545
1546 (defbinding window-maximize () nil
1547   (window window))
1548
1549 (defbinding window-unmaximize () nil
1550   (window window))
1551
1552 (defbinding window-fullscreen () nil
1553   (window window))
1554
1555 (defbinding window-unfullscreen () nil
1556   (window window))
1557
1558 (defbinding window-set-keep-above () nil
1559   (window window)
1560   (setting boolean))
1561
1562 (defbinding window-set-keep-below () nil
1563   (window window)
1564   (setting boolean))
1565
1566 (defbinding window-begin-resize-drag () nil
1567   (window window)
1568   (edge gdk:window-edge)
1569   (button int)
1570   (root-x int) (root-y int)
1571   (timestamp unsigned-int))
1572
1573 (defbinding window-begin-move-drag () nil
1574   (window window)
1575   (edge gdk:window-edge)
1576   (button int)
1577   (root-x int) (root-y int)
1578   (timestamp unsigned-int))
1579
1580 (defbinding window-set-frame-dimensions () nil
1581   (window window)
1582   (left int) (top int) (rigth int) (bottom int))
1583
1584 (defbinding %window-get-default-size () nil
1585   (window window)
1586   (width int :out)
1587   (height int :out))
1588
1589 (defun window-get-default-size (window)
1590   (multiple-value-bind (width height) (%window-get-default-size window)
1591     (values (unless (= width -1) width) (unless (= height -1) height))))
1592
1593 (defbinding window-get-frame-dimensions () nil
1594   (window window)
1595   (left int :out) (top int :out) (rigth int :out) (bottom int :out))
1596
1597 (defbinding %window-get-icon-list () (glist (copy-of gdk:pixbuf))
1598   (window window))
1599
1600 (defbinding window-get-position () nil
1601   (window window)
1602   (root-x int :out)
1603   (root-y int :out))
1604
1605 (defbinding window-get-size () nil
1606   (window window)
1607   (width int :out)
1608   (height int :out))
1609
1610 (defbinding window-move () nil
1611   (window window)
1612   (x int)
1613   (y int))
1614
1615 (defbinding window-parse-geometry () boolean
1616   (window window)
1617   (geometry string))
1618
1619 (defbinding window-reshow-with-initial-size () nil
1620   (window window))
1621
1622 (defbinding window-resize () nil
1623   (window window)
1624   (width int)
1625   (heigth int))
1626
1627 (defbinding (window-default-icon-list "gtk_window_get_default_icon_list")
1628     () (glist gdk:pixbuf))
1629
1630 (defun window-default-icon ()
1631   (first (window-default-icon-list)))
1632
1633 (defbinding %window-set-default-icon-list () nil
1634   (icons (glist gdk:pixbuf)))
1635
1636 (defun (setf window-default-icon-list) (icons)
1637   (%window-set-default-icon-list icons)
1638   icons)
1639
1640 (defbinding %window-set-default-icon () nil
1641   (icons (glist gdk:pixbuf)))
1642
1643 (defgeneric (setf window-default-icon) (icon))
1644
1645 (defmethod (setf window-default-icon) ((icon gdk:pixbuf))
1646   (%window-set-default-icon icon)
1647   icon)
1648
1649 (defgeneric (setf window-group) (group window))
1650
1651 (defmethod (setf window-group) ((group window-group) (window window))
1652   (window-group-add-window group window)
1653   group)
1654
1655 (defbinding %window-set-default-icon-from-file () boolean
1656   (filename pathname)
1657   (nil null))
1658
1659 (defmethod (setf window-default-icon) ((icon-file pathname))
1660   (%window-set-default-icon-from-file icon-file)
1661   icon-file)
1662
1663 (defbinding %window-set-icon-from-file () boolean
1664   (window window)
1665   (filename pathname)
1666   (nil null))
1667
1668 (defmethod (setf window-icon) ((icon-file pathname) (window window))
1669   (%window-set-icon-from-file window icon-file)
1670   icon-file)
1671
1672 (defbinding window-set-auto-startup-notification () nil
1673   (setting boolean))
1674
1675 (defbinding decorated-window-init () nil
1676   (window window))
1677
1678 (defbinding decorated-window-calculate-frame-size () nil
1679   (window window))
1680
1681 (defbinding decorated-window-set-title () nil
1682   (window window)
1683   (title string))
1684
1685 (defbinding decorated-window-move-resize-window () nil
1686   (window window)
1687   (x int)
1688   (y int)
1689   (width int)
1690   (heigth int))
1691
1692
1693 ;;; Window group
1694
1695 (defmethod initialize-instance ((window-group window-group) &rest initargs 
1696                                 &key window windows)
1697   (declare (ignore window windows))
1698   (prog1
1699       (call-next-method)
1700     (initial-add window-group #'window-group-add-window 
1701      initargs :window :windows)))
1702
1703
1704 (defbinding window-group-add-window () nil
1705   (window-group window-group)
1706   (window window))
1707
1708 (defbinding window-group-remove-window () nil
1709   (window-group window-group)
1710   (window window))
1711
1712
1713 ;;; Scrolled window
1714
1715 (defun (setf scrolled-window-scrollbar-policy) (policy window)
1716   (setf (scrolled-window-hscrollbar-policy window) policy)
1717   (setf (scrolled-window-vscrollbar-policy window) policy))
1718
1719 (defbinding scrolled-window-add-with-viewport () nil
1720    (scrolled-window scrolled-window)
1721    (child widget))
1722
1723 (defmethod shared-initialize ((window scrolled-window) names &key policy)
1724   (declare (ignore names))
1725   (when policy 
1726     (setf (slot-value window 'hscrollbar-policy) policy)
1727     (setf (slot-value window 'vscrollbar-policy) policy))
1728   (call-next-method))
1729
1730
1731 ;;; Statusbar
1732
1733 (defbinding statusbar-get-context-id () unsigned-int
1734   (statusbar statusbar)
1735   (context-description string))
1736
1737 (defbinding statusbar-push () unsigned-int
1738   (statusbar statusbar)
1739   (context-id unsigned-int)  
1740   (text string))
1741
1742 (defbinding statusbar-pop () nil
1743   (statusbar statusbar)
1744   (context-id unsigned-int))
1745
1746 (defbinding statusbar-remove () nil
1747   (statusbar statusbar)
1748   (context-id unsigned-int)
1749   (message-id unsigned-int))
1750
1751
1752
1753 ;;; Fixed
1754
1755 (defbinding fixed-put () nil
1756   (fixed fixed)
1757   (widget widget)
1758   (x int) (y int))
1759
1760 (defbinding fixed-move () nil
1761   (fixed fixed)
1762   (widget widget)
1763   (x int) (y int))
1764
1765
1766
1767 ;;; Notebook
1768
1769 (defun %ensure-notebook-position (notebook page)
1770   (etypecase page
1771     (position page)
1772     (widget (notebook-page-num notebook page t))))
1773
1774 (defun %ensure-notebook-child (notebook position)
1775   (typecase position
1776      (widget position)
1777      (t (notebook-get-nth-page notebook position))))
1778
1779 (defbinding (notebook-insert "gtk_notebook_insert_page_menu")
1780     (notebook position child &optional tab-label menu-label) nil
1781   (notebook notebook)
1782   (child widget)
1783   ((if (stringp tab-label)
1784        (make-instance 'label :label tab-label)
1785      tab-label) (or null widget))
1786   ((if (stringp menu-label)
1787        (make-instance 'label :label menu-label)
1788      menu-label) (or null widget))
1789   ((%ensure-notebook-position notebook position) position))
1790
1791 (defun notebook-append (notebook child &optional tab-label menu-label)
1792   (notebook-insert notebook :last child tab-label menu-label))
1793
1794 (defun notebook-prepend (notebook child &optional tab-label menu-label)
1795   (notebook-insert notebook :first child tab-label menu-label))
1796   
1797 (defbinding notebook-remove-page (notebook page) nil
1798   (notebook notebook)
1799   ((%ensure-notebook-position notebook page) position))
1800
1801 (defbinding %notebook-page-num () int
1802   (notebook notebook)
1803   (child widget))
1804
1805 (defun notebook-page-num (notebook child &optional error-p)
1806   (let ((page-num (%notebook-page-num notebook child)))
1807     (if (= page-num -1)
1808         (when error-p
1809           (error "~A is not a page in ~A" child notebook))
1810       page-num)))
1811
1812 (defbinding notebook-next-page () nil
1813   (notebook notebook))
1814
1815 (defbinding notebook-prev-page () nil
1816   (notebook notebook))
1817
1818 (defbinding notebook-reorder-child (notebook child position) nil
1819   (notebook notebook)
1820   (child widget)
1821   ((%ensure-notebook-position notebook position) int))
1822
1823 (defbinding notebook-popup-enable () nil
1824   (notebook notebook))
1825
1826 (defbinding notebook-popup-disable () nil
1827   (notebook notebook))
1828
1829 (defbinding notebook-get-nth-page () widget
1830   (notebook notebook)
1831   (page position))
1832
1833 (defun %notebook-current-page (notebook)
1834   (when (slot-boundp notebook 'current-page-num)
1835     (notebook-get-nth-page notebook (notebook-current-page-num notebook))))
1836
1837 (defun (setf notebook-current-page) (page notebook)
1838   (setf (notebook-current-page-num notebook) (notebook-page-num notebook page)))
1839
1840 (defbinding (notebook-tab-label "gtk_notebook_get_tab_label")
1841     (notebook page) widget
1842   (notebook notebook)
1843   ((%ensure-notebook-child notebook page) widget))
1844
1845 (defbinding (notebook-tab-label-text "gtk_notebook_get_tab_label_text")
1846     (notebook page) (copy-of string)
1847   (notebook notebook)
1848   ((%ensure-notebook-child notebook page) widget))
1849
1850 (defbinding %notebook-set-tab-label () nil
1851   (notebook notebook)
1852   (page widget)
1853   (tab-label widget))
1854
1855 (defun (setf notebook-tab-label) (tab-label notebook page)
1856   (let ((widget (if (stringp tab-label)
1857                     (make-instance 'label :label tab-label)
1858                   tab-label)))
1859     (%notebook-set-tab-label notebook (%ensure-notebook-child notebook page) widget)
1860     widget))
1861
1862
1863 (defbinding (notebook-menu-label "gtk_notebook_get_menu_label")
1864     (notebook page) widget
1865   (notebook notebook)
1866   ((%ensure-notebook-child notebook page) widget))
1867
1868 (defbinding (notebook-menu-label-text "gtk_notebook_get_menu_label_text")
1869     (notebook page) (copy-of string)
1870   (notebook notebook)
1871   ((%ensure-notebook-child notebook page) widget))
1872
1873 (defbinding %notebook-set-menu-label () nil
1874   (notebook notebook)
1875   (page widget)
1876   (menu-label widget))
1877
1878 (defun (setf notebook-menu-label) (menu-label notebook page)
1879   (let ((widget (if (stringp menu-label)
1880                     (make-instance 'label :label menu-label)
1881                   menu-label)))
1882     (%notebook-set-menu-label notebook (%ensure-notebook-child notebook page) widget)
1883     widget))
1884
1885
1886 (defbinding notebook-query-tab-label-packing (notebook page) nil
1887   (notebook notebook)
1888   ((%ensure-notebook-child notebook page) widget)
1889   (expand boolean :out)
1890   (fill boolean :out)
1891   (pack-type pack-type :out))
1892
1893 (defbinding notebook-set-tab-label-packing
1894     (notebook page expand fill pack-type) nil
1895   (notebook notebook)
1896   ((%ensure-notebook-child notebook page) widget)
1897   (expand boolean)
1898   (fill boolean)
1899   (pack-type pack-type))
1900
1901
1902
1903 ;;; Paned
1904
1905 (defbinding paned-pack1 () nil
1906   (paned paned)
1907   (child widget)
1908   (resize boolean)
1909   (shrink boolean))
1910
1911 (defbinding paned-pack2 () nil
1912   (paned paned)
1913   (child widget)
1914   (resize boolean)
1915   (shrink boolean))
1916
1917
1918 ;;; Layout
1919
1920 (defbinding layout-put () nil
1921   (layout layout)
1922   (child widget)
1923   (x int)
1924   (y int))
1925
1926 (defbinding layout-move () nil
1927   (layout layout)
1928   (child widget)
1929   (x int)
1930   (y int))
1931
1932 (defbinding layout-set-size () nil
1933   (layout layout)
1934   (width unsigned-int)
1935   (height unsigned-int))
1936
1937 (defbinding layout-get-size () nil
1938   (layout layout)
1939   (width unsigned-int :out)
1940   (height unsigned-int :out))
1941
1942
1943 ;;; Menu shell
1944
1945 (defbinding menu-shell-insert (menu-shell menu-item position) nil
1946   (menu-shell menu-shell)
1947   (menu-item menu-item)
1948   ((case position
1949      (:first 0)
1950      (:last -1)
1951      (t position)) int))
1952
1953 (defun menu-shell-append (menu-shell menu-item)
1954   (menu-shell-insert menu-shell menu-item :last))
1955
1956 (defun menu-shell-prepend (menu-shell menu-item)
1957   (menu-shell-insert menu-shell menu-item :fisrt))
1958
1959 (defbinding menu-shell-deactivate () nil
1960   (menu-shell menu-shell))
1961
1962 (defbinding menu-shell-select-item () nil
1963   (menu-shell menu-shell)
1964   (menu-item menu-item))
1965
1966 (defbinding menu-shell-select-first () nil
1967   (menu-shell menu-shell)
1968   (search-sensitive boolean))
1969
1970 (defbinding menu-shell-deselect () nil
1971   (menu-shell menu-shell))
1972
1973 (defbinding menu-shell-activate-item () nil
1974   (menu-shell menu-shell)
1975   (menu-item menu-item)
1976   (fore-deactivate boolean))
1977
1978 (defbinding menu-shell-cancel () nil
1979   (menu-shell menu-shell))
1980
1981
1982 ;;; Menu
1983
1984 (defun %menu-position (menu child)
1985   (etypecase child
1986     (int child)
1987     (keyword (case child
1988                (:first 0)
1989                (:last -1)
1990                (t (error "Invalid position keyword: ~A" child))))
1991     (widget (menu-child-position menu child))))
1992
1993
1994 (defbinding menu-reorder-child (menu menu-item position) nil
1995   (menu menu)
1996   (menu-item menu-item)
1997   ((%menu-position menu position) int))
1998
1999 (defbinding menu-attach () nil
2000   (menu menu)
2001   (menu-item menu-item)
2002   (left-attach unsigned-int)
2003   (right-attach unsigned-int)
2004   (top-attach unsigned-int)
2005   (bottom-attach unsigned-int))
2006
2007 (define-callback-marshal %menu-position-callback nil 
2008   (menu (x int) (y int) (push-in boolean)))
2009
2010 (defbinding %menu-popup () nil
2011   (menu menu)
2012   (parent-menu-shell (or null menu-shell))
2013   (parent-menu-item (or null menu-item))
2014   (callback (or null callback))
2015   (callback-id unsigned-int)
2016   (button unsigned-int)
2017   (activate-time (unsigned 32)))
2018
2019 (defun menu-popup (menu button activate-time &key callback parent-menu-shell
2020                    parent-menu-item)
2021   (if callback
2022       (with-callback-function (id callback)
2023         (%menu-popup 
2024          menu parent-menu-shell parent-menu-item 
2025          %menu-position-callback id button activate-time))
2026     (%menu-popup
2027      menu parent-menu-shell parent-menu-item nil 0 button activate-time)))
2028  
2029 (defbinding menu-set-accel-path () nil
2030   (menu menu)
2031   (accel-path string))
2032
2033 (defbinding menu-reposition () nil
2034   (menu menu))
2035
2036 (defbinding menu-popdown () nil
2037   (menu menu))
2038
2039 (defun menu-child-position (menu child)
2040   (position child (container-children menu)))
2041
2042 (defun menu-active-num (menu)
2043   (menu-child-position menu (menu-active menu)))
2044
2045 (defbinding %menu-set-active () nil
2046   (menu menu)
2047   (index unsigned-int))
2048
2049 (defun (setf menu-active) (menu child)
2050   (%menu-set-active menu (%menu-position menu child))
2051   child)
2052   
2053 (define-callback %menu-detach-callback nil ((widget widget) (menu menu))
2054   (funcall (user-data menu 'detach-func) widget menu))
2055
2056 (defbinding %menu-attach-to-widget (menu widget) nil
2057   (menu menu)
2058   (widget widget)
2059   (%menu-detach-callback callback))
2060
2061 (defun menu-attach-to-widget (menu widget function)
2062   (setf (user-data menu 'detach-func) function)
2063   (%menu-attach-to-widget menu widget))
2064
2065 (defbinding menu-detach () nil
2066   (menu menu))
2067
2068 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
2069 (defbinding menu-get-for-attach-widget () (copy-of (glist widget))
2070   (widget widget))
2071
2072 (defbinding menu-set-monitor () nil
2073   (menu menu)
2074   (monitor-num int))
2075
2076
2077 ;;; Table
2078
2079 (defbinding table-resize () nil
2080   (table table)
2081   (rows unsigned-int)
2082   (columns unsigned-int))
2083
2084 (defbinding table-attach (table child left right top bottom
2085                           &key options x-options y-options
2086                           (x-padding 0) (y-padding 0)) nil
2087   (table table)
2088   (child widget)
2089   (left unsigned-int)
2090   (right unsigned-int)
2091   (top unsigned-int)
2092   (bottom unsigned-int)
2093   ((append (mklist options) (mklist x-options)) attach-options)
2094   ((append (mklist options) (mklist y-options)) attach-options)
2095   (x-padding unsigned-int)
2096   (y-padding unsigned-int))
2097
2098
2099 (defbinding %table-set-row-spacing () nil
2100   (table table)
2101   (row unsigned-int)
2102   (spacing unsigned-int))
2103
2104 (defbinding %table-set-row-spacings () nil
2105   (table table)
2106   (spacing unsigned-int))
2107
2108 (defun (setf table-row-spacing) (spacing table &optional row)
2109   (if row
2110       (%table-set-row-spacing table row spacing)
2111     (%table-set-row-spacings table spacing))
2112   spacing)
2113
2114 (defbinding %table-get-row-spacing () unsigned-int
2115   (table table)
2116   (row unsigned-int))
2117
2118 (defbinding %table-get-default-row-spacing () unsigned-int
2119   (table table))
2120
2121 (defun table-row-spacing (table &optional row)
2122   (if row
2123       (%table-get-row-spacing table row)
2124     (%table-get-default-row-spacing table)))
2125
2126
2127 (defbinding %table-set-col-spacing () nil
2128   (table table)
2129   (col unsigned-int)
2130   (spacing unsigned-int))
2131
2132 (defbinding %table-set-col-spacings () nil
2133   (table table)
2134   (spacing unsigned-int))
2135
2136 (defun (setf table-column-spacing) (spacing table &optional column)
2137   (if column
2138       (%table-set-col-spacing table column spacing)
2139     (%table-set-col-spacings table spacing))
2140   spacing)
2141
2142 (defun (setf table-col-spacing) (spacing table &optional col)
2143   (warn "TABLE-COL-SPACING is deprecatet, use TABLE-COLUMN-SPACING instead")
2144   (setf (table-column-spacing table col) spacing))
2145
2146 (defbinding %table-get-col-spacing () unsigned-int
2147   (table table)
2148   (col unsigned-int))
2149
2150 (defbinding %table-get-default-col-spacing () unsigned-int
2151   (table table))
2152
2153 (defun table-column-spacing (table &optional column)
2154   (if column
2155       (%table-get-col-spacing table column)
2156     (%table-get-default-col-spacing table)))
2157   
2158 (defun table-col-spacing (table &optional col)
2159   (warn "TABLE-COL-SPACING is deprecatet, use TABLE-COLUMN-SPACING instead")
2160   (table-column-spacing table col))
2161
2162
2163
2164 ;;; Toolbar
2165
2166 (defmethod initialize-instance ((toolbar toolbar) &rest initargs &key tooltips)
2167   (if (eq tooltips t)
2168       (apply #'call-next-method toolbar
2169        :tooltips (make-instance 'tooltips) initargs)
2170     (call-next-method)))
2171
2172 (defbinding %toolbar-insert () nil
2173   (toolbar toolbar)
2174   (tool-item tool-item)
2175   (position position))
2176
2177 (defun toolbar-insert (toolbar tool-item &optional (position :end))
2178   (%toolbar-insert toolbar tool-item position)
2179   (%tool-item-update-tooltips tool-item))
2180
2181 (defbinding toolbar-get-item-index () int
2182   (toolbar toolbar)
2183   (item tool-item))
2184
2185 (defbinding toolbar-get-nth-item () tool-item
2186   (toolbar toolbar)
2187   (n int))
2188
2189 (defbinding toolbar-get-drop-index () int
2190   (toolbar toolbar)
2191   (x int) (y int))
2192
2193 (defbinding toolbar-set-drop-highlight-item () nil
2194   (toolbar toolbar)
2195   (tool-item tool-item)
2196   (index int))
2197
2198
2199 ;;; Tool button
2200
2201 (defmethod initialize-instance ((button tool-button) &rest initargs &key icon)
2202   (if (and icon (not (typep icon 'widget)))
2203       (apply #'call-next-method button :icon (create-image-widget icon) initargs)
2204     (call-next-method)))
2205
2206
2207 ;;; Tool item
2208
2209 (defbinding tool-item-set-tooltip () nil
2210   (tool-item tool-item)
2211   (tooltips tooltips)
2212   (tip-text string)
2213   (tip-private string))
2214
2215
2216 (defun %tool-item-update-tooltips (tool-item)
2217   (when (and 
2218          (slot-boundp tool-item 'parent)
2219          (or 
2220           (user-data-p tool-item 'tip-text)
2221           (user-data-p tool-item 'tip-private)))
2222     (tool-item-set-tooltip
2223      tool-item (toolbar-tooltips (widget-parent tool-item))
2224      (or (user-data tool-item 'tip-text) "")
2225      (or (user-data tool-item 'tip-private) ""))))
2226
2227 (defmethod (setf tool-item-tip-text) ((tip-text string) (tool-item tool-item))
2228   (setf (user-data tool-item 'tip-text) tip-text)
2229   (%tool-item-update-tooltips tool-item)
2230   tip-text)
2231
2232 (defmethod (setf tool-item-tip-private) ((tip-private string) (tool-item tool-item))
2233   (setf (user-data tool-item 'tip-private) tip-private)
2234   (%tool-item-update-tooltips tool-item)
2235   tip-private)
2236
2237 (defmethod container-add ((toolbar toolbar) (tool-item tool-item) &rest args)
2238   (declare (ignore args))
2239   (prog1
2240       (call-next-method)
2241     (%tool-item-update-tooltips tool-item)))
2242
2243
2244 (defbinding tool-item-retrieve-proxy-menu-item () widget
2245   (tool-item tool-item))
2246
2247 (defbinding (tool-item-proxy-menu-item 
2248              "gtk_tool_item_get_proxy_menu_item") () menu-item
2249   (tool-item tool-item)
2250   (menu-item-id string))
2251
2252 (defbinding %tool-item-set-proxy-menu-item () nil
2253   (tool-item tool-item)
2254   (menu-item-id string)
2255   (menu-item menu-item))
2256
2257 (defun (setf tool-item-proxy-menu-item) (menu-item menu-item-id tool-item)
2258   (%tool-item-set-proxy-menu-item menu-item-id tool-item menu-item)
2259    menu-item)
2260
2261 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
2262 (defbinding tool-item-rebuild-menu () nil
2263   (tool-item tool-item))
2264
2265
2266 ;;; Editable
2267
2268 (defbinding editable-select-region (editable &optional (start 0) end) nil
2269   (editable editable)
2270   (start int)
2271   ((or end -1) int))
2272
2273 (defbinding editable-get-selection-bounds (editable) nil
2274   (editable editable)
2275   (start int :out)
2276   (end int :out))
2277
2278 (defbinding editable-insert-text (editable text &optional (position 0)) nil
2279   (editable editable)
2280   (text string)
2281   ((length text) int)
2282   (position position :in/out))
2283
2284 (defun editable-append-text (editable text)
2285   (editable-insert-text editable text nil))
2286
2287 (defun editable-prepend-text (editable text)
2288   (editable-insert-text editable text 0))
2289
2290 (defbinding editable-delete-text (editable &optional (start 0) end) nil
2291   (editable editable)
2292   (start int)
2293   ((or end -1) int))
2294
2295 (defbinding (editable-text "gtk_editable_get_chars")
2296     (editable &optional (start 0) end) string
2297   (editable editable)
2298   (start int)
2299   ((or end -1) int))
2300
2301 (defun (setf editable-text) (text editable)
2302   (if text
2303       (editable-delete-text
2304        editable
2305        (editable-insert-text editable text))
2306     (editable-delete-text editable))
2307   text)
2308
2309 (defbinding editable-cut-clipboard () nil
2310   (editable editable))
2311
2312 (defbinding editable-copy-clipboard () nil
2313   (editable editable))
2314
2315 (defbinding editable-paste-clipboard () nil
2316   (editable editable))
2317
2318 (defbinding editable-delete-selection () nil
2319   (editable editable))
2320
2321
2322
2323 ;;; Spin button
2324
2325 (defbinding spin-button-configure () nil
2326   (spin-button spin-button)
2327   (adjustment adjustment)
2328   (climb-rate double-float)
2329   (digits unsigned-int))
2330
2331 (defbinding spin-button-set-range () nil
2332   (spin-button spin-button)
2333   (min double-float)
2334   (max double-float))
2335
2336 (defbinding spin-button-get-range () nil
2337   (spin-button spin-button)
2338   (min double-float :out)
2339   (max double-float :out))
2340
2341 (defun spin-button-value-as-int (spin-button)
2342   (round (spin-button-value spin-button)))
2343
2344 (defbinding %spin-button-spin () nil
2345   (spin-button spin-button)
2346   (direction spin-type)
2347   (increment double-float))
2348
2349 (defun spin-button-spin (spin-button value)
2350   (etypecase value
2351     (real (%spin-button-spin spin-button :spin-user-defined value))
2352     (spin-type (%spin-button-spin spin-button value 0))))
2353
2354
2355 (defbinding spin-button-update () nil
2356   (spin-button spin-button))
2357
2358
2359
2360 ; ;;; Ruler
2361
2362 (defbinding ruler-set-range () nil
2363   (ruler ruler)
2364   (lower single-float)
2365   (upper single-float)
2366   (position single-float)
2367   (max-size single-float))
2368
2369 (defbinding ruler-get-range () nil
2370   (ruler ruler)
2371   (lower single-float :out)
2372   (upper single-float :out)
2373   (position single-float :out)
2374   (max-size single-float :out))
2375
2376
2377
2378 ;;; Range
2379
2380 (defun range-lower (range)
2381   (adjustment-lower (range-adjustment range)))
2382
2383 (defun range-upper (range)
2384   (adjustment-upper (range-adjustment range)))
2385
2386 (defun (setf range-lower) (value range)
2387   (setf (adjustment-lower (range-adjustment range)) value))
2388
2389 (defun (setf range-upper) (value range)
2390   (setf (adjustment-upper (range-adjustment range)) value))
2391
2392 (defun range-page-increment (range)
2393   (adjustment-page-increment (range-adjustment range)))
2394
2395 (defun range-step-increment (range)
2396   (adjustment-step-increment (range-adjustment range)))
2397
2398 (defun (setf range-page-increment) (value range)
2399   (setf (adjustment-page-increment (range-adjustment range)) value))
2400
2401 (defun (setf range-step-increment) (value range)
2402   (setf (adjustment-step-increment (range-adjustment range)) value))
2403
2404 (defbinding range-set-range () nil
2405   (range range)
2406   (lower double-float)
2407   (upper double-float))
2408
2409 (defbinding range-set-increments () nil
2410   (range range)
2411   (step double-float)
2412   (page double-float))
2413
2414
2415 ;;; Scale
2416
2417 (defbinding scale-get-layout-offsets () nil
2418   (scale scale)
2419   (x int :out)
2420   (y int :out))
2421
2422
2423 ;;; Progress bar
2424
2425 (defbinding progress-bar-pulse () nil
2426   (progress-bar progress-bar))
2427
2428
2429 ;;; Size group
2430
2431 (defmethod initialize-instance ((size-group size-group) &rest initargs 
2432                                 &key widget widgets)
2433   (declare (ignore widget widgets))
2434   (prog1
2435       (call-next-method)
2436     (initial-add size-group #'size-group-add-widget 
2437      initargs :widget :widgets)))
2438
2439
2440 (defbinding size-group-add-widget () nil
2441   (size-group size-group)
2442   (widget widget))
2443
2444 (defbinding size-group-remove-widget () nil
2445   (size-group size-group)
2446   (widget widget))
2447
2448
2449 ;;; Stock items
2450
2451 (defbinding %stock-item-copy () pointer
2452   (location pointer))
2453
2454 (defbinding %stock-item-free () nil
2455   (location pointer))
2456
2457 (defbinding stock-add (stock-item) nil
2458   (stock-item stock-item)
2459   (1 unsigned-int))
2460
2461 (defbinding stock-list-ids () (gslist string))
2462
2463 (defbinding %stock-lookup () boolean
2464   (stock-id string)
2465   (location pointer))
2466
2467 (defun stock-lookup (stock-id)
2468   (with-memory (stock-item (foreign-size (find-class 'stock-item)))
2469     (when (%stock-lookup stock-id stock-item)
2470       (ensure-proxy-instance 'stock-item (%stock-item-copy stock-item)))))
2471
2472 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.8.0")
2473 (progn
2474   (define-callback-marshal %stock-translate-callback string ((path string)))
2475
2476   (defbinding (stock-set-translate-function "gtk_stock_set_translate_func") 
2477       (domain function) nil
2478     (domain string)
2479     (%stock-translate-callback callback)
2480     ((register-callback-function function) unsigned-int)
2481     (user-data-destroy-callback callback)))
2482
2483   
2484
2485 ;;; Tooltips
2486
2487 (defbinding tooltips-enable () nil
2488   (tooltips tooltips))
2489
2490 (defbinding tooltips-disable () nil
2491   (tooltips tooltips))
2492
2493 (defun (setf tooltips-enabled-p) (enable tooltips)
2494   (if enable
2495       (tooltips-enable tooltips)
2496     (tooltips-disable tooltips)))
2497
2498 (defbinding tooltips-set-tip () nil
2499   (tooltips tooltips)
2500   (widget widget)
2501   (tip-text string)
2502   (tip-private string))
2503
2504 (defbinding tooltips-data-get () tooltips-data
2505   (widget widget))
2506
2507 (defbinding tooltips-force-window () nil
2508   (tooltips tooltips))
2509
2510 (defbinding tooltips-get-info-from-tip-window () boolean
2511   (tip-window window)
2512   (tooltips tooltips :out)
2513   (current-widget widget :out))
2514
2515
2516 ;;; Resource Files
2517
2518 (defbinding rc-get-style () style
2519   (widget widget))
2520
2521 (defbinding rc-get-style-by-paths (&key path class-path class) style
2522   (path (or null string))
2523   (class-path (or null string))
2524   (class gtype))
2525
2526 (defbinding rc-parse () nil
2527   (filename pathname))
2528
2529 (defbinding rc-parse-string () nil
2530   (rc-string string))
2531
2532 (defbinding %rc-reparse-all () boolean)
2533
2534 (defbinding %rc-reparse-all-for-settings () boolean
2535   (settings settings)
2536   (force-load-p boolean))
2537
2538 (defun rc-reparse-all (&optional setting force-load-p)
2539   (if setting
2540       (%rc-reparse-all-for-settings setting force-load-p)
2541     (%rc-reparse-all)))
2542
2543 (defbinding rc-reset-styles () nil
2544   (settings settings))
2545
2546 (defbinding rc-add-default-file () nil
2547   (filename pathname))
2548
2549 (defbinding rc-get-default-files ()
2550     (copy-of (null-terminated-vector (copy-of string))))
2551
2552 (defbinding rc-get-module-dir () string)
2553
2554 (defbinding rc-get-im-module-path () string)
2555
2556 (defbinding rc-get-im-module-file () string)
2557
2558 (defbinding rc-get-theme-dir () string)
2559
2560
2561 ;;; Settings
2562
2563 (defbinding (settings-get "gtk_settings_get_for_screen")
2564     (&optional (screen (gdk:display-get-default-screen))) settings
2565   (screen gdk:screen))
2566
2567
2568 ;;; Plug and Socket
2569
2570 (defbinding socket-add-id () nil
2571   (socket socket)
2572   (id gdk:native-window))
2573
2574 (defbinding %plug-new () pointer
2575   (id gdk:native-window))
2576
2577 (defmethod allocate-foreign ((plug plug) &key id)
2578   (%plug-new (or id 0)))
2579
2580
2581 ;;;; New stuff in Gtk+ 2.10
2582
2583 ;;; Link button
2584
2585 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.10.0")
2586 (progn
2587   (define-callback-marshal %link-button-uri-callback nil (link-button (link string)))
2588
2589   (defbinding link-button-set-uri-hook (function) pointer
2590     (%link-button-uri-callback callback)
2591     ((register-callback-function function) unsigned-int)
2592     (user-data-destroy-callback callback)))