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