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