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