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