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