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