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