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