Adding bindings to entry completion
[clg] / gtk / gtk.lisp
1 ;; Common Lisp bindings for GTK+ v2.0
2 ;; Copyright (C) 1999-2001 Espen S. Johnsen <esj@stud.cs.uit.no>
3 ;;
4 ;; This library is free software; you can redistribute it and/or
5 ;; modify it under the terms of the GNU Lesser General Public
6 ;; License as published by the Free Software Foundation; either
7 ;; version 2 of the License, or (at your option) any later version.
8 ;;
9 ;; This library is distributed in the hope that it will be useful,
10 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ;; Lesser General Public License for more details.
13 ;;
14 ;; You should have received a copy of the GNU Lesser General Public
15 ;; License along with this library; if not, write to the Free Software
16 ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18 ;; $Id: gtk.lisp,v 1.24 2004-12-20 22:43:26 espen Exp $
19
20
21 (in-package "GTK")
22
23 ;;; Gtk version
24
25 (defbinding check-version () (copy-of string)
26 (required-major unsigned-int)
27 (required-minor unsigned-int)
28 (required-micro unsigned-int))
29
30 (defbinding query-version () nil
31 (major unsigned-int :out)
32 (minor unsigned-int :out)
33 (micro unsigned-int :out))
34
35 (defun gtk-version ()
36 (multiple-value-bind (major minor micro)
37 (query-version)
38 (if (zerop micro)
39 (format nil "Gtk+ v~A.~A" major minor)
40 (format nil "Gtk+ v~A.~A.~A" major minor micro))))
41
42 (defbinding get-default-language () (copy-of pango:language))
43
44
45 ;;;; Initalization
46
47 (defbinding (gtk-init "gtk_parse_args") () nil
48 "Initializes the library without opening the display."
49 (nil null)
50 (nil null))
51
52 (defun clg-init (&optional display)
53 "Initializes the system and starts the event handling"
54 (unless (gdk:display-get-default)
55 (gdk:gdk-init)
56 (gtk-init)
57 (prog1
58 (gdk:display-open display)
59 (system:add-fd-handler
60 (gdk:display-connection-number) :input #'main-iterate-all)
61 (setq lisp::*periodic-polling-function* #'main-iterate-all)
62 (setq lisp::*max-event-to-sec* 0)
63 (setq lisp::*max-event-to-usec* 1000))))
64
65
66 ;;; Acccel group
67
68
69
70 ;;; Acccel label
71
72 (defbinding accel-label-refetch () boolean
73 (accel-label accel-label))
74
75
76 ;;; Adjustment
77
78 (defmethod shared-initialize ((adjustment adjustment) names &key value)
79 (prog1
80 (call-next-method)
81 ;; we need to make sure that the value is set last, otherwise it
82 ;; may be outside current limits
83 (when value
84 (setf (slot-value adjustment 'value) value))))
85
86
87 (defbinding adjustment-changed () nil
88 (adjustment adjustment))
89
90 (defbinding adjustment-value-changed () nil
91 (adjustment adjustment))
92
93 (defbinding adjustment-clamp-page () nil
94 (adjustment adjustment)
95 (lower single-float)
96 (upper single-float))
97
98
99 ;;; Arrow -- no functions
100
101
102
103 ;;; Aspect frame
104
105
106 ;;; Bin
107
108 (defun (setf bin-child) (child bin)
109 (when-bind (current-child (bin-child bin))
110 (container-remove bin current-child))
111 (container-add bin child)
112 child)
113
114
115 ;;; Binding
116
117
118
119 ;;; Box
120
121 (defbinding box-pack-start () nil
122 (box box)
123 (child widget)
124 (expand boolean)
125 (fill boolean)
126 (padding unsigned-int))
127
128 (defbinding box-pack-end () nil
129 (box box)
130 (child widget)
131 (expand boolean)
132 (fill boolean)
133 (padding unsigned-int))
134
135 (defun box-pack (box child &key end expand fill (padding 0))
136 (if end
137 (box-pack-end box child expand fill padding)
138 (box-pack-start box child expand fill padding)))
139
140 (defbinding box-reorder-child () nil
141 (box box)
142 (child widget)
143 (position int))
144
145 (defbinding box-query-child-packing () nil
146 (box box)
147 (child widget)
148 (expand boolean :out)
149 (fill boolean :out)
150 (padding unsigned-int :out)
151 (pack-type pack-type :out))
152
153 (defbinding box-set-child-packing () nil
154 (box box)
155 (child widget)
156 (expand boolean)
157 (fill boolean)
158 (padding unsigned-int)
159 (pack-type pack-type))
160
161
162
163 ;;; Button
164
165 (defbinding button-pressed () nil
166 (button button))
167
168 (defbinding button-released () nil
169 (button button))
170
171 (defbinding button-clicked () nil
172 (button button))
173
174 (defbinding button-enter () nil
175 (button button))
176
177 (defbinding button-leave () nil
178 (button button))
179
180
181
182 ;;; Calendar
183
184 (defbinding calendar-select-month () int
185 (calendar calendar)
186 (month unsigned-int)
187 (year unsigned-int))
188
189 (defbinding calendar-select-day () nil
190 (calendar calendar)
191 (day unsigned-int))
192
193 (defbinding calendar-mark-day () int
194 (calendar calendar)
195 (day unsigned-int))
196
197 (defbinding calendar-unmark-day () int
198 (calendar calendar)
199 (day unsigned-int))
200
201 (defbinding calendar-clear-marks () nil
202 (calendar calendar))
203
204 (defbinding calendar-display-options () nil
205 (calendar calendar)
206 (options calendar-display-options))
207
208 (defbinding (calendar-date "gtk_calendar_get_date") () nil
209 (calendar calendar)
210 (year unsigned-int :out)
211 (month unsigned-int :out)
212 (day unsigned-int :out))
213
214 (defbinding calendar-freeze () nil
215 (calendar calendar))
216
217 (defbinding calendar-thaw () nil
218 (calendar calendar))
219
220
221
222 ;;; Cell editable
223
224
225
226 ;;; Cell renderer
227
228
229
230 ;;; Cell renderer pixbuf -- no functions
231
232
233
234 ;;; Cell renderer text
235
236
237
238 ;;; Cell renderer toggle -- no functions
239
240
241
242 ;;; Check button -- no functions
243
244
245
246 ;;; Check menu item
247
248 (defbinding check-menu-item-toggled () nil
249 (check-menu-item check-menu-item))
250
251
252
253 ;;; Clipboard
254
255
256 ;;; Color selection
257
258 (defbinding (color-selection-is-adjusting-p
259 "gtk_color_selection_is_adjusting") () boolean
260 (colorsel color-selection))
261
262
263
264 ;;; Color selection dialog -- no functions
265
266
267
268 ;;;; Combo Box
269
270 (defmethod shared-initialize ((combo-box combo-box) names &key model content)
271 (unless model
272 (setf
273 (combo-box-model combo-box)
274 (make-instance 'list-store :column-types '(string)))
275 (unless (typep combo-box 'combo-box-entry)
276 (let ((cell (make-instance 'cell-renderer-text)))
277 (cell-layout-pack combo-box cell :expand t)
278 (cell-layout-add-attribute combo-box cell :text 0)))
279 (when content
280 (map 'nil #'(lambda (text)
281 (combo-box-append-text combo-box text))
282 content)))
283 (call-next-method))
284
285 ;; (defmethod shared-initialize :after ((combo-box combo-box) names &key active)
286 ;; (when active
287 ;; (signal-emit combo-box 'changed)))
288
289 (defbinding combo-box-append-text () nil
290 (combo-box combo-box)
291 (text string))
292
293 (defbinding combo-box-insert-text () nil
294 (combo-box combo-box)
295 (position int)
296 (text string))
297
298 (defbinding combo-box-prepend-text () nil
299 (combo-box combo-box)
300 (text string))
301
302 #+gtk2.6
303 (defbinding combo-box-get-active-text () string
304 (combo-box combo-box))
305
306 (defbinding combo-box-popup () nil
307 (combo-box combo-box))
308
309 (defbinding combo-box-popdown () nil
310 (combo-box combo-box))
311
312
313
314 ;;;; Combo Box Entry
315
316 (defmethod shared-initialize ((combo-box-entry combo-box-entry) names &key model)
317 (call-next-method)
318 (unless model
319 (setf (combo-box-entry-text-column combo-box-entry) 0)))
320
321
322 ;;;; Dialog
323
324 (defmethod shared-initialize ((dialog dialog) names &rest initargs
325 &key button buttons)
326 (declare (ignore button buttons))
327 (prog1
328 (call-next-method)
329 (initial-apply-add dialog #'dialog-add-button initargs :button :buttons)))
330
331
332 (defvar %*response-id-key* (gensym))
333
334 (defun %dialog-find-response-id-num (dialog id &optional create-p error-p)
335 (or
336 (cadr (assoc id (rest (type-expand-1 'response-type))))
337 (let ((response-ids (object-data dialog %*response-id-key*)))
338 (cond
339 ((and response-ids (position id response-ids :test #'equal)))
340 (create-p
341 (cond
342 (response-ids
343 (vector-push-extend id response-ids)
344 (1- (length response-ids)))
345 (t
346 (setf
347 (object-data dialog %*response-id-key*)
348 (make-array 1 :adjustable t :fill-pointer t :initial-element id))
349 0)))
350 (error-p
351 (error "Invalid response: ~A" id))))))
352
353 (defun %dialog-find-response-id (dialog response-id-num)
354 (if (< response-id-num 0)
355 (car
356 (rassoc
357 (list response-id-num)
358 (rest (type-expand-1 'response-type)) :test #'equal))
359 (aref (object-data dialog %*response-id-key*) response-id-num )))
360
361
362 (defmethod signal-connect ((dialog dialog) signal function &key object after)
363 (let ((response-id-num (%dialog-find-response-id-num dialog signal)))
364 (cond
365 (response-id-num
366 (call-next-method
367 dialog 'response
368 #'(lambda (dialog id)
369 (when (= id response-id-num)
370 (cond
371 ((eq object t) (funcall function dialog))
372 (object (funcall function object))
373 (t (funcall function)))))
374 :object t :after after))
375 ((call-next-method)))))
376
377
378 (defbinding dialog-run () nil
379 (dialog dialog))
380
381 (defbinding dialog-response (dialog response-id) nil
382 (dialog dialog)
383 ((%dialog-find-response-id-num dialog response-id nil t) int))
384
385
386 (defbinding %dialog-add-button () button
387 (dialog dialog)
388 (text string)
389 (response-id-num int))
390
391 (defun dialog-add-button (dialog label &optional (response label)
392 &key default object after)
393 "Adds a button to the dialog. If no response is given, then label
394 will be used."
395 (let* ((id (if (functionp response)
396 label
397 response))
398 (id-num (%dialog-find-response-id-num dialog id t))
399 (button (%dialog-add-button dialog label id-num)))
400 (when (functionp response)
401 (signal-connect dialog id response :object object :after after))
402 (when default
403 (%dialog-set-default-response dialog id-num))
404 button))
405
406
407 (defbinding %dialog-add-action-widget () button
408 (dialog dialog)
409 (action-widget widget)
410 (response-id-num int))
411
412 (defun dialog-add-action-widget (dialog widget &optional (response widget)
413 &key default object after)
414 (let* ((id (if (functionp response)
415 widget
416 response))
417 (id-num (%dialog-find-response-id-num dialog id t)))
418 (%dialog-add-action-widget dialog widget id-num)
419 (when (functionp response)
420 (signal-connect dialog id response :object object :after after))
421 (when default
422 (%dialog-set-default-response dialog id-num))
423 widget))
424
425
426 (defbinding %dialog-set-default-response () nil
427 (dialog dialog)
428 (response-id-num int))
429
430 (defun dialog-set-default-response (dialog response-id)
431 (%dialog-set-default-response
432 dialog (%dialog-find-response-id-num dialog response-id nil t)))
433
434 (defbinding dialog-set-response-sensitive (dialog response-id sensitive) nil
435 (dialog dialog)
436 ((%dialog-find-response-id-num dialog response-id nil t) int)
437 (sensitive boolean))
438
439
440 ;; Addition dialog functions
441
442 (defmethod container-add ((dialog dialog) (child widget) &rest args)
443 (apply #'container-add (dialog-vbox dialog) child args))
444
445 (defmethod container-remove ((dialog dialog) (child widget))
446 (container-remove (dialog-vbox dialog) child))
447
448 (defmethod container-children ((dialog dialog))
449 (container-children (dialog-vbox dialog)))
450
451 (defmethod (setf container-children) (children (dialog dialog))
452 (setf (container-children (dialog-vbox dialog)) children))
453
454
455
456 ;;; Drawing area
457
458 (defbinding drawing-area-get-size () nil
459 (drawing-area drawing-area)
460 (width int :out)
461 (height int :out))
462
463
464 ;;; Entry
465
466 (defbinding entry-get-layout () pango:layout
467 (entry entry))
468
469 (defbinding entry-get-layout-offsets () nil
470 (entry entry)
471 (x int :out)
472 (y int :out))
473
474
475 ;;; Entry Completion
476
477 (def-callback-marshal %entry-completion-match-func
478 (boolean entry-completion string (copy-of tree-iter)))
479
480 (defbinding entry-completion-set-match-func (completion function) nil
481 (completion entry-completion)
482 ((callback %entry-completion-match-func) pointer)
483 ((register-callback-function function) unsigned-int)
484 ((callback %destroy-user-data) pointer))
485
486 (defbinding entry-completion-complete () nil
487 (completion entry-completion))
488
489 #+gtk2.6
490 (defbinding entry-completion-insert-prefix () nil
491 (completion entry-completion))
492
493 (defbinding entry-completion-insert-action-text () nil
494 (completion entry-completion)
495 (index int)
496 (text string))
497
498 (defbinding entry-completion-insert-action-markup () nil
499 (completion entry-completion)
500 (index int)
501 (markup string))
502
503 (defbinding entry-completion-delete-action () nil
504 (completion entry-completion)
505 (index int))
506
507
508 ;;; Image
509
510 (defbinding image-set-from-file () nil
511 (image image)
512 (filename pathname))
513
514 (defbinding image-set-from-pixmap () nil
515 (image image)
516 (pixmap gdk:pixmap)
517 (mask gdk:bitmap))
518
519 (defbinding image-set-from-stock () nil
520 (image image)
521 (stock-id string)
522 (icon-size icon-size))
523
524 (defun image-set-from-pixmap-data (image pixmap-data)
525 (multiple-value-bind (pixmap mask) (gdk:pixmap-create pixmap-data)
526 (image-set-from-pixmap image pixmap mask)))
527
528 (defun image-set-from-source (image source)
529 (etypecase source
530 (pathname (image-set-from-file image source))
531 (string (if (stock-lookup source)
532 (setf (image-stock image) source)
533 (image-set-from-file image source)))
534 (vector (image-set-from-pixmap-data image source))))
535
536
537 (defmethod shared-initialize ((image image) names &rest initargs
538 &key file pixmap source)
539 (prog1
540 (if (vectorp pixmap)
541 (progn
542 (remf initargs :pixmap)
543 (apply #'call-next-method image names initargs))
544 (call-next-method))
545 (cond
546 (file (image-set-from-file image file))
547 ((vectorp pixmap) (image-set-from-pixmap-data image pixmap))
548 (source (image-set-from-source image source)))))
549
550
551 ;;; Label
552
553 (defbinding label-get-layout-offsets () nil
554 (label label)
555 (x int :out)
556 (y int :out))
557
558 (defbinding label-select-region () nil
559 (label label)
560 (start int)
561 (end int))
562
563 (defbinding label-get-text () string
564 (label label))
565
566 (defbinding label-get-layout () pango:layout
567 (label label))
568
569 (defbinding label-get-selection-bounds () boolean
570 (label label)
571 (start int :out)
572 (end int :out))
573
574
575
576 ;;; Radio button
577
578 (defbinding %radio-button-get-group () pointer
579 (radio-button radio-button))
580
581 (defbinding %radio-button-set-group () nil
582 (radio-button radio-button)
583 (group pointer))
584
585 (defun radio-button-add-to-group (button1 button2)
586 "Add BUTTON1 to the group which BUTTON2 belongs to."
587 (%radio-button-set-group button1 (%radio-button-get-group button2)))
588
589
590 (defmethod initialize-instance ((button radio-button)
591 &rest initargs &key group-with)
592 (declare (ignore initargs))
593 (call-next-method)
594 (when group-with
595 (radio-button-add-to-group button group-with)))
596
597
598 ;;; Item
599
600 (defbinding item-select () nil
601 (item item))
602
603 (defbinding item-deselect () nil
604 (item item))
605
606 (defbinding item-toggle () nil
607 (item item))
608
609
610
611 ;;; Menu item
612
613 (defun (setf menu-item-label) (label menu-item)
614 (make-instance 'accel-label
615 :label label :xalign 0.0 :yalign 0.5 :accel-widget menu-item
616 :visible t :parent menu-item)
617 label)
618
619 (defun menu-item-label (menu-item)
620 (with-slots (child) menu-item
621 (when (typep child 'label)
622 (label-label child))))
623
624 (defbinding %menu-item-set-submenu () nil
625 (menu-item menu-item)
626 (submenu menu))
627
628 (defbinding %menu-item-remove-submenu () nil
629 (menu-item menu-item))
630
631 (defun (setf menu-item-submenu) (submenu menu-item)
632 (if (not submenu)
633 (%menu-item-remove-submenu menu-item)
634 (%menu-item-set-submenu menu-item submenu))
635 submenu)
636
637 (defbinding menu-item-set-accel-path () nil
638 (menu-item menu-item)
639 (accel-path string))
640
641 (defbinding menu-item-select () nil
642 (menu-item menu-item))
643
644 (defbinding menu-item-deselect () nil
645 (menu-item menu-item))
646
647 (defbinding menu-item-activate () nil
648 (menu-item menu-item))
649
650 (defbinding menu-item-toggle-size-request () nil
651 (menu-item menu-item)
652 (requisition int :out))
653
654 (defbinding menu-item-toggle-size-allocate () nil
655 (menu-item menu-item)
656 (allocation int))
657
658
659
660 ;;; Radio menu item
661
662 (defbinding %radio-menu-item-get-group () pointer
663 (radio-menu-item radio-menu-item))
664
665 (defbinding %radio-menu-item-set-group () nil
666 (radio-menu-item radio-menu-item)
667 (group pointer))
668
669 (defun radio-menu-item-add-to-group (item1 item2)
670 "Add ITEM1 to the group which ITEM2 belongs to."
671 (%radio-menu-item-set-group item1 (%radio-menu-item-get-group item2)))
672
673 (defmethod initialize-instance ((item radio-menu-item)
674 &rest initargs &key group-with)
675 (declare (ignore initargs))
676 (prog1
677 (call-next-method)
678 (when group-with
679 (radio-menu-item-add-to-group item group-with))))
680
681
682
683 ;;; Toggle button
684
685 (defbinding toggle-button-toggled () nil
686 (toggle-button toggle-button))
687
688
689
690 ;;; Window
691
692 (defmethod initialize-instance ((window window) &rest initargs
693 &key accel-group accel-groups)
694 (declare (ignore accel-group accel-groups))
695 (prog1
696 (call-next-method)
697 (initial-add window #'window-add-accel-group
698 initargs :accel-group :accel-groups)))
699
700
701 (defbinding window-set-wmclass () nil
702 (window window)
703 (wmclass-name string)
704 (wmclass-class string))
705
706 (defbinding window-add-accel-group () nil
707 (window window)
708 (accel-group accel-group))
709
710 (defbinding window-remove-accel-group () nil
711 (window window)
712 (accel-group accel-group))
713
714 (defbinding window-activate-focus () int
715 (window window))
716
717 (defbinding window-activate-default () int
718 (window window))
719
720 (defbinding window-set-default-size (window width height) int
721 (window window)
722 ((or width -1) int)
723 ((or height -1) int))
724
725 ;(defbinding window-set-geometry-hints)
726
727 (defbinding window-list-toplevels () (glist (copy-of window))
728 "Returns a list of all existing toplevel windows.")
729
730 (defbinding window-add-mnemonic (window key target) nil
731 (window window)
732 ((gdk:keyval-from-name key) unsigned-int)
733 (target widget))
734
735 (defbinding window-remove-mnemonic (window key target) nil
736 (window window)
737 ((gdk:keyval-from-name key) unsigned-int)
738 (target widget))
739
740 (defbinding window-mnemonic-activate (window key modifier) nil
741 (window window)
742 ((gdk:keyval-from-name key) unsigned-int)
743 (modifier gdk:modifier-type))
744
745 (defbinding window-present () nil
746 (window window))
747
748 (defbinding window-iconify () nil
749 (window window))
750
751 (defbinding window-deiconify () nil
752 (window window))
753
754 (defbinding window-stick () nil
755 (window window))
756
757 (defbinding window-unstick () nil
758 (window window))
759
760 (defbinding window-maximize () nil
761 (window window))
762
763 (defbinding window-unmaximize () nil
764 (window window))
765
766 (defbinding window-begin-resize-drag () nil
767 (window window)
768 (edge gdk:window-edge)
769 (button int)
770 (root-x int) (root-y int)
771 (timestamp unsigned-int))
772
773 (defbinding window-begin-move-drag () nil
774 (window window)
775 (edge gdk:window-edge)
776 (button int)
777 (root-x int) (root-y int)
778 (timestamp unsigned-int))
779
780 (defbinding window-set-frame-dimensions () nil
781 (window window)
782 (left int) (top int) (rigth int) (bottom int))
783
784 (defbinding (window-default-icons "gtk_window_get_default_icon_list")
785 () (glist gdk:pixbuf))
786
787 (defbinding %window-get-default-size () nil
788 (window window)
789 (width int :out)
790 (height int :out))
791
792 (defun window-get-default-size (window)
793 (multiple-value-bind (width height) (%window-get-default-size window)
794 (values (unless (= width -1) width) (unless (= height -1) height))))
795
796 (defbinding window-get-frame-dimensions () nil
797 (window window)
798 (left int :out) (top int :out) (rigth int :out) (bottom int :out))
799
800 (defbinding %window-get-icon-list () (glist gdk:pixbuf)
801 (window window))
802
803 (defmethod window-icon ((window window))
804 (let ((icon-list (%window-get-icon-list window)))
805 (if (endp (rest icon-list))
806 (first icon-list)
807 icon-list)))
808
809 (defbinding window-get-position () nil
810 (window window)
811 (root-x int :out)
812 (root-y int :out))
813
814 (defbinding window-get-size () nil
815 (window window)
816 (width int :out)
817 (height int :out))
818
819 (defbinding window-move () nil
820 (window window)
821 (x int)
822 (y int))
823
824 (defbinding window-parse-geometry () boolean
825 (window window)
826 (geometry string))
827
828 (defbinding window-reshow-with-initial-size () nil
829 (window window))
830
831 (defbinding window-resize () nil
832 (window window)
833 (width int)
834 (heigth int))
835
836 (defbinding %window-set-icon-list () nil
837 (window window)
838 (icon-list (glist gdk:pixbuf)))
839
840 (defmethod (setf window-icon) (icon (window window))
841 (%window-set-icon-list window (mklist icon)))
842
843
844
845
846 ;;; File chooser
847
848
849
850
851 ;;; Scrolled window
852
853 (defun (setf scrolled-window-scrollbar-policy) (policy window)
854 (setf (scrolled-window-hscrollbar-policy window) policy)
855 (setf (scrolled-window-vscrollbar-policy window) policy))
856
857 (defbinding scrolled-window-add-with-viewport () nil
858 (scrolled-window scrolled-window)
859 (child widget))
860
861
862
863
864
865
866
867 ;;; Statusbar
868
869 (defbinding (statusbar-context-id "gtk_statusbar_get_context_id")
870 () unsigned-int
871 (statusbar statusbar)
872 (context-description string))
873
874 (defbinding statusbar-push () unsigned-int
875 (statusbar statusbar)
876 (context-id unsigned-int)
877 (text string))
878
879 (defbinding statusbar-pop () nil
880 (statusbar statusbar)
881 (context-id unsigned-int))
882
883 (defbinding statusbar-remove () nil
884 (statusbar statusbar)
885 (context-id unsigned-int)
886 (message-id unsigned-int))
887
888
889
890 ;;; Fixed
891
892 (defbinding fixed-put () nil
893 (fixed fixed)
894 (widget widget)
895 (x int) (y int))
896
897 (defbinding fixed-move () nil
898 (fixed fixed)
899 (widget widget)
900 (x int) (y int))
901
902
903
904 ;;; Notebook
905
906 (defun %notebook-position (notebook page)
907 (etypecase page
908 (int page)
909 (keyword (case page
910 (:first 0)
911 (:last -1)
912 (t (error "Invalid position keyword: ~A" page))))
913 (widget (notebook-page-num notebook page t))))
914
915 (defun %notebook-child (notebook position)
916 (typecase position
917 (widget position)
918 (t (notebook-nth-page-child notebook position))))
919
920
921 (defbinding (notebook-insert "gtk_notebook_insert_page_menu")
922 (notebook position child tab-label &optional menu-label) nil
923 (notebook notebook)
924 (child widget)
925 ((if (stringp tab-label)
926 (make-instance 'label :label tab-label)
927 tab-label) widget)
928 ((if (stringp menu-label)
929 (make-instance 'label :label menu-label)
930 menu-label) (or null widget))
931 ((%notebook-position notebook position) int))
932
933 (defun notebook-append (notebook child tab-label &optional menu-label)
934 (notebook-insert notebook :last child tab-label menu-label))
935
936 (defun notebook-prepend (notebook child tab-label &optional menu-label)
937 (notebook-insert notebook :first child tab-label menu-label))
938
939 (defbinding notebook-remove-page (notebook page) nil
940 (notebook notebook)
941 ((%notebook-position notebook page) int))
942
943 (defbinding %notebook-page-num () int
944 (notebook notebook)
945 (child widget))
946
947 (defun notebook-page-num (notebook child &optional error-p)
948 (let ((page-num (%notebook-page-num notebook child)))
949 (if (= page-num -1)
950 (when error-p
951 (error "~A is not a child of ~A" child notebook))
952 page-num)))
953
954 (defbinding notebook-next-page () nil
955 (notebook notebook))
956
957 (defbinding notebook-prev-page () nil
958 (notebook notebook))
959
960 (defbinding notebook-reorder-child (notebook child position) nil
961 (notebook notebook)
962 (child widget)
963 ((%notebook-position notebook position) int))
964
965 (defbinding notebook-popup-enable () nil
966 (notebook notebook))
967
968 (defbinding notebook-popup-disable () nil
969 (notebook notebook))
970
971 (defbinding (notebook-nth-page-child "gtk_notebook_get_nth_page")
972 (notebook page) widget
973 (notebook notebook)
974 ((case page
975 (:first 0)
976 (:last -1)
977 (t page)) int))
978
979
980 (defbinding %notebook-get-current-page () int
981 (notebook notebook))
982
983 (defun notebook-current-page-num (notebook)
984 (let ((num (%notebook-get-current-page notebook)))
985 (when (>= num 0)
986 num)))
987
988 (defun notebook-current-page (notebook)
989 (let ((page-num (notebook-current-page-num notebook)))
990 (when page-num
991 (notebook-nth-page-child notebook page-num))))
992
993 (defbinding %notebook-set-current-page () nil
994 (notebook notebook)
995 (page-num int))
996
997 (defun (setf notebook-current-page) (page notebook)
998 (%notebook-set-current-page notebook (%notebook-position notebook page))
999 page)
1000
1001
1002 (defbinding (notebook-tab-label "gtk_notebook_get_tab_label")
1003 (notebook page) widget
1004 (notebook notebook)
1005 ((%notebook-child notebook page) widget))
1006
1007 (defbinding (notebook-tab-label-text "gtk_notebook_get_tab_label_text")
1008 (notebook page) (copy-of string)
1009 (notebook notebook)
1010 ((%notebook-child notebook page) widget))
1011
1012 (defbinding %notebook-set-tab-label () nil
1013 (notebook notebook)
1014 (page widget)
1015 (tab-label widget))
1016
1017 (defun (setf notebook-tab-label) (tab-label notebook page)
1018 (let ((widget (if (stringp tab-label)
1019 (make-instance 'label :label tab-label)
1020 tab-label)))
1021 (%notebook-set-tab-label notebook (%notebook-child notebook page) widget)
1022 widget))
1023
1024
1025 (defbinding (notebook-menu-label "gtk_notebook_get_menu_label")
1026 (notebook page) widget
1027 (notebook notebook)
1028 ((%notebook-child notebook page) widget))
1029
1030 (defbinding (notebook-menu-label-text "gtk_notebook_get_menu_label_text")
1031 (notebook page) (copy-of string)
1032 (notebook notebook)
1033 ((%notebook-child notebook page) widget))
1034
1035 (defbinding %notebook-set-menu-label () nil
1036 (notebook notebook)
1037 (page widget)
1038 (menu-label widget))
1039
1040 (defun (setf notebook-menu-label) (menu-label notebook page)
1041 (let ((widget (if (stringp menu-label)
1042 (make-instance 'label :label menu-label)
1043 menu-label)))
1044 (%notebook-set-menu-label notebook (%notebook-child notebook page) widget)
1045 widget))
1046
1047
1048 (defbinding notebook-query-tab-label-packing (notebook page) nil
1049 (notebook notebook)
1050 ((%notebook-child notebook page) widget)
1051 (expand boolean :out)
1052 (fill boolean :out)
1053 (pack-type pack-type :out))
1054
1055 (defbinding notebook-set-tab-label-packing
1056 (notebook page expand fill pack-type) nil
1057 (notebook notebook)
1058 ((%notebook-child notebook page) widget)
1059 (expand boolean)
1060 (fill boolean)
1061 (pack-type pack-type))
1062
1063
1064
1065 ;;; Paned
1066
1067 (defbinding paned-pack1 () nil
1068 (paned paned)
1069 (child widget)
1070 (resize boolean)
1071 (shrink boolean))
1072
1073 (defbinding paned-pack2 () nil
1074 (paned paned)
1075 (child widget)
1076 (resize boolean)
1077 (shrink boolean))
1078
1079
1080 ;;; Layout
1081
1082 (defbinding layout-put () nil
1083 (layout layout)
1084 (widget widget)
1085 (x int)
1086 (y int))
1087
1088 (defbinding layout-move () nil
1089 (layout layout)
1090 (widget widget)
1091 (x int)
1092 (y int))
1093
1094
1095
1096 ;;; Menu shell
1097
1098 (defbinding menu-shell-insert (menu-shell menu-item position) nil
1099 (menu-shell menu-shell)
1100 (menu-item menu-item)
1101 ((case position
1102 (:first 0)
1103 (:last -1)
1104 (t position)) int))
1105
1106 (defun menu-shell-append (menu-shell menu-item)
1107 (menu-shell-insert menu-shell menu-item :last))
1108
1109 (defun menu-shell-prepend (menu-shell menu-item)
1110 (menu-shell-insert menu-shell menu-item :fisrt))
1111
1112 (defbinding menu-shell-deactivate () nil
1113 (menu-shell menu-shell))
1114
1115 (defbinding menu-shell-select-item () nil
1116 (menu-shell menu-shell)
1117 (menu-item menu-item))
1118
1119 (defbinding menu-shell-deselect () nil
1120 (menu-shell menu-shell))
1121
1122 (defbinding menu-shell-activate-item () nil
1123 (menu-shell menu-shell)
1124 (menu-item menu-item)
1125 (fore-deactivate boolean))
1126
1127
1128
1129 ;;; Menu
1130
1131 (defun %menu-position (menu child)
1132 (etypecase child
1133 (int child)
1134 (keyword (case child
1135 (:first 0)
1136 (:last -1)
1137 (t (error "Invalid position keyword: ~A" child))))
1138 (widget (menu-child-position menu child))))
1139
1140
1141 (defbinding menu-reorder-child (menu menu-item position) nil
1142 (menu menu)
1143 (menu-item menu-item)
1144 ((%menu-position menu position) int))
1145
1146 (def-callback-marshal %menu-popup-callback (nil (x int) (y int) (push-in boolean)))
1147
1148 (defbinding %menu-popup () nil
1149 (menu menu)
1150 (parent-menu-shell (or null menu-shell))
1151 (parent-menu-item (or null menu-item))
1152 (callback-func (or null pointer))
1153 (callback-id unsigned-int)
1154 (button unsigned-int)
1155 (activate-time (unsigned 32)))
1156
1157 (defun menu-popup (menu button activate-time &key callback parent-menu-shell
1158 parent-menu-item)
1159 (if callback
1160 (with-callback-function (id callback)
1161 (%menu-popup
1162 menu parent-menu-shell parent-menu-item
1163 (callback %menu-popup-callback) id button activate-time))
1164 (%menu-popup
1165 menu parent-menu-shell parent-menu-item nil 0 button activate-time)))
1166
1167 (defbinding menu-set-accel-path () nil
1168 (menu menu)
1169 (accel-path string))
1170
1171 (defbinding menu-reposition () nil
1172 (menu menu))
1173
1174 (defbinding menu-popdown () nil
1175 (menu menu))
1176
1177 (defun menu-child-position (menu child)
1178 (position child (container-children menu)))
1179
1180 (defun menu-active-num (menu)
1181 (menu-child-position menu (menu-active menu)))
1182
1183 (defbinding %menu-set-active () nil
1184 (menu menu)
1185 (index unsigned-int))
1186
1187 (defun (setf menu-active) (menu child)
1188 (%menu-set-active menu (%menu-position menu child))
1189 child)
1190
1191
1192
1193 ;;; Table
1194
1195 (defbinding table-resize () nil
1196 (table table)
1197 (rows unsigned-int)
1198 (columns unsigned-int))
1199
1200 (defbinding table-attach (table child left right top bottom
1201 &key options x-options y-options
1202 (x-padding 0) (y-padding 0)) nil
1203 (table table)
1204 (child widget)
1205 (left unsigned-int)
1206 (right unsigned-int)
1207 (top unsigned-int)
1208 (bottom unsigned-int)
1209 ((append (mklist options) (mklist x-options)) attach-options)
1210 ((append (mklist options) (mklist y-options)) attach-options)
1211 (x-padding unsigned-int)
1212 (y-padding unsigned-int))
1213
1214
1215 (defbinding %table-set-row-spacing () nil
1216 (table table)
1217 (row unsigned-int)
1218 (spacing unsigned-int))
1219
1220 (defbinding %table-set-row-spacings () nil
1221 (table table)
1222 (spacing unsigned-int))
1223
1224 (defun (setf table-row-spacing) (spacing table &optional row)
1225 (if row
1226 (%table-set-row-spacing table row spacing)
1227 (%table-set-row-spacings table spacing))
1228 spacing)
1229
1230 (defbinding %table-get-row-spacing () unsigned-int
1231 (table table)
1232 (row unsigned-int))
1233
1234 (defbinding %table-get-default-row-spacing () unsigned-int
1235 (table table))
1236
1237 (defun table-row-spacing (table &optional row)
1238 (if row
1239 (%table-get-row-spacing table row)
1240 (%table-get-default-row-spacing table)))
1241
1242
1243 (defbinding %table-set-col-spacing () nil
1244 (table table)
1245 (col unsigned-int)
1246 (spacing unsigned-int))
1247
1248 (defbinding %table-set-col-spacings () nil
1249 (table table)
1250 (spacing unsigned-int))
1251
1252 (defun (setf table-col-spacing) (spacing table &optional col)
1253 (if col
1254 (%table-set-col-spacing table col spacing)
1255 (%table-set-col-spacings table spacing))
1256 spacing)
1257
1258 (defbinding %table-get-col-spacing () unsigned-int
1259 (table table)
1260 (col unsigned-int))
1261
1262 (defbinding %table-get-default-col-spacing () unsigned-int
1263 (table table))
1264
1265 (defun table-col-spacing (table &optional col)
1266 (if col
1267 (%table-get-col-spacing table col)
1268 (%table-get-default-col-spacing table)))
1269
1270
1271
1272 ;;; Toolbar
1273
1274 (defbinding %toolbar-insert-element () widget
1275 (toolbar toolbar)
1276 (type toolbar-child-type)
1277 (widget (or null widget))
1278 (text string)
1279 (tooltip-text string)
1280 (tooltip-private-text string)
1281 (icon (or null widget))
1282 (nil null)
1283 (nil null)
1284 (position int))
1285
1286 (defbinding %toolbar-insert-stock () widget
1287 (toolbar toolbar)
1288 (stock-id string)
1289 (tooltip-text string)
1290 (tooltip-private-text string)
1291 (nil null)
1292 (nil null)
1293 (position int))
1294
1295 (defun toolbar-insert (toolbar position element
1296 &key tooltip-text tooltip-private-text
1297 type icon group callback object)
1298 (let* ((numpos (case position
1299 (:first -1)
1300 (:last 0)
1301 (t position)))
1302 (widget
1303 (cond
1304 ((or
1305 (eq type :space)
1306 (and (not type) (eq element :space)))
1307 (%toolbar-insert-element
1308 toolbar :space nil nil
1309 tooltip-text tooltip-private-text nil numpos))
1310 ((or
1311 (eq type :widget)
1312 (and (not type) (typep element 'widget)))
1313 (%toolbar-insert-element
1314 toolbar :widget element nil
1315 tooltip-text tooltip-private-text nil numpos))
1316 ((or
1317 (eq type :stock)
1318 (and
1319 (not type)
1320 (typep element 'string)
1321 (stock-lookup element)))
1322 (%toolbar-insert-stock
1323 toolbar element tooltip-text tooltip-private-text numpos))
1324 ((typep element 'string)
1325 (%toolbar-insert-element
1326 toolbar (or type :button) (when (eq type :radio-button) group)
1327 element tooltip-text tooltip-private-text
1328 (etypecase icon
1329 (null nil)
1330 (widget icon)
1331 ((or pathname string vector)
1332 (make-instance 'image
1333 :source icon ; :icon-size (toolbar-icon-size toolbar)
1334 )))
1335 numpos))
1336 ((error "Invalid element type: ~A" element)))))
1337 (when callback
1338 (signal-connect widget 'clicked callback :object object))
1339 widget))
1340
1341 (defun toolbar-append (toolbar element &key tooltip-text tooltip-private-text
1342 type icon group callback object)
1343 (toolbar-insert
1344 toolbar :first element :type type :icon icon :group group
1345 :tooltip-text tooltip-text :tooltip-private-text tooltip-private-text
1346 :callback callback :object object))
1347
1348 (defun toolbar-prepend (toolbar element &key tooltip-text tooltip-private-text
1349 type icon group callback object)
1350 (toolbar-insert
1351 toolbar :last element :type type :icon icon :group group
1352 :tooltip-text tooltip-text :tooltip-private-text tooltip-private-text
1353 :callback callback :object object))
1354
1355
1356 (defun toolbar-insert-space (toolbar position)
1357 (toolbar-insert toolbar position :space))
1358
1359 (defun toolbar-append-space (toolbar)
1360 (toolbar-append toolbar :space))
1361
1362 (defun toolbar-prepend-space (toolbar)
1363 (toolbar-prepend toolbar :space))
1364
1365
1366 (defun toolbar-enable-tooltips (toolbar)
1367 (setf (toolbar-tooltips-p toolbar) t))
1368
1369 (defun toolbar-disable-tooltips (toolbar)
1370 (setf (toolbar-tooltips-p toolbar) nil))
1371
1372
1373 (defbinding toolbar-remove-space () nil
1374 (toolbar toolbar)
1375 (position int))
1376
1377 (defbinding toolbar-unset-icon-size () nil
1378 (toolbar toolbar))
1379
1380 (defbinding toolbar-unset-style () nil
1381 (toolbar toolbar))
1382
1383
1384 ;;; Editable
1385
1386 (defbinding editable-select-region (editable &optional (start 0) end) nil
1387 (editable editable)
1388 (start int)
1389 ((or end -1) int))
1390
1391 (defbinding editable-get-selection-bounds (editable) nil
1392 (editable editable)
1393 (start int :out)
1394 (end int :out))
1395
1396 (defbinding editable-insert-text
1397 (editable text &optional (position 0)) nil
1398 (editable editable)
1399 (text string)
1400 ((length text) int)
1401 ((or position -1) int :in-out))
1402
1403 (defun editable-append-text (editable text)
1404 (editable-insert-text editable text nil))
1405
1406 (defun editable-prepend-text (editable text)
1407 (editable-insert-text editable text 0))
1408
1409 (defbinding editable-delete-text (editable &optional (start 0) end) nil
1410 (editable editable)
1411 (start int)
1412 ((or end -1) int))
1413
1414 (defbinding (editable-text "gtk_editable_get_chars")
1415 (editable &optional (start 0) end) string
1416 (editable editable)
1417 (start int)
1418 ((or end -1) int))
1419
1420 (defun (setf editable-text) (text editable)
1421 (if text
1422 (editable-delete-text
1423 editable
1424 (editable-insert-text editable text))
1425 (editable-delete-text editable))
1426 text)
1427
1428 (defbinding editable-cut-clipboard () nil
1429 (editable editable))
1430
1431 (defbinding editable-copy-clipboard () nil
1432 (editable editable))
1433
1434 (defbinding editable-paste-clipboard () nil
1435 (editable editable))
1436
1437 (defbinding editable-delete-selection () nil
1438 (editable editable))
1439
1440
1441
1442 ;;; Spin button
1443
1444 (defun spin-button-value-as-int (spin-button)
1445 (round (spin-button-value spin-button)))
1446
1447 (defbinding spin-button-spin () nil
1448 (spin-button spin-button)
1449 (direction spin-type)
1450 (increment single-float))
1451
1452 (defbinding spin-button-update () nil
1453 (spin-button spin-button))
1454
1455
1456
1457 ; ;;; Ruler
1458
1459 (defbinding ruler-set-range () nil
1460 (ruler ruler)
1461 (lower single-float)
1462 (upper single-float)
1463 (position single-float)
1464 (max-size single-float))
1465
1466 (defbinding ruler-draw-ticks () nil
1467 (ruler ruler))
1468
1469 (defbinding ruler-draw-pos () nil
1470 (ruler ruler))
1471
1472
1473
1474 ;;; Range
1475
1476 (defun range-lower (range)
1477 (adjustment-lower (range-adjustment range)))
1478
1479 (defun range-upper (range)
1480 (adjustment-upper (range-adjustment range)))
1481
1482 (defun (setf range-lower) (value range)
1483 (setf (adjustment-lower (range-adjustment range)) value))
1484
1485 (defun (setf range-upper) (value range)
1486 (setf (adjustment-upper (range-adjustment range)) value))
1487
1488 (defun range-page-increment (range)
1489 (adjustment-page-increment (range-adjustment range)))
1490
1491 (defun range-step-increment (range)
1492 (adjustment-step-increment (range-adjustment range)))
1493
1494 (defun (setf range-page-increment) (value range)
1495 (setf (adjustment-page-increment (range-adjustment range)) value))
1496
1497 (defun (setf range-step-increment) (value range)
1498 (setf (adjustment-step-increment (range-adjustment range)) value))
1499
1500 (defbinding range-set-range () nil
1501 (range range)
1502 (lower double-float)
1503 (upper double-float))
1504
1505 (defbinding range-set-increments () nil
1506 (range range)
1507 (step double-float)
1508 (page double-float))
1509
1510
1511 ;;; Scale
1512
1513 ; (defbinding scale-draw-value () nil
1514 ; (scale scale))
1515
1516
1517
1518 ;;; Progress bar
1519
1520 (defbinding progress-bar-pulse () nil
1521 (progress-bar progress-bar))
1522
1523
1524 ;;; Size group
1525
1526 (defmethod initialize-instance ((size-group size-group) &rest initargs
1527 &key widget widgets)
1528 (declare (ignore widget widgets))
1529 (prog1
1530 (call-next-method)
1531 (initial-add size-group #'size-group-add-widget
1532 initargs :widget :widgets)))
1533
1534
1535 (defbinding size-group-add-widget () nil
1536 (size-group size-group)
1537 (widget widget))
1538
1539 (defbinding size-group-remove-widget () nil
1540 (size-group size-group)
1541 (widget widget))
1542
1543
1544 ;;; Stock items
1545
1546 (defbinding %stock-item-copy () pointer
1547 (location pointer))
1548
1549 (defbinding %stock-item-free () nil
1550 (location pointer))
1551
1552 (defmethod reference-foreign ((class (eql (find-class 'stock-item))) location)
1553 (%stock-item-copy location))
1554
1555 (defmethod unreference-foreign ((class (eql (find-class 'stock-item))) location)
1556 (%stock-item-free location))
1557
1558 (defbinding stock-add (stock-item) nil
1559 (stock-item stock-item)
1560 (1 unsigned-int))
1561
1562 (defbinding stock-list-ids () (gslist string))
1563
1564 (defbinding %stock-lookup () boolean
1565 (stock-id string)
1566 (location pointer))
1567
1568 (defun stock-lookup (stock-id)
1569 (let ((location
1570 (allocate-memory (proxy-instance-size (find-class 'stock-item)))))
1571 (unwind-protect
1572 (when (%stock-lookup stock-id location)
1573 (ensure-proxy-instance 'stock-item (%stock-item-copy location)))
1574 (deallocate-memory location))))
1575
1576
1577 ;;; Tooltips
1578
1579 (defbinding tooltips-enable () nil
1580 (tooltips tooltips))
1581
1582 (defbinding tooltips-disable () nil
1583 (tooltips tooltips))
1584
1585 (defun (setf tooltips-enabled-p) (enable tooltips)
1586 (if enable
1587 (tooltips-enable tooltips)
1588 (tooltips-disable tooltips)))
1589
1590 (defbinding tooltips-set-tip () nil
1591 (tooltips tooltips)
1592 (widget widget)
1593 (tip-text string)
1594 (tip-private string))
1595
1596 (defbinding tooltips-force-window () nil
1597 (tooltips tooltips))
1598
1599
1600
1601 ;;; Rc
1602
1603 (defbinding rc-add-default-file (filename) nil
1604 ((namestring (truename filename)) string))
1605
1606 (defbinding rc-parse (filename) nil
1607 ((namestring (truename filename)) string))
1608
1609 (defbinding rc-parse-string () nil
1610 (rc-string string))
1611
1612 (defbinding rc-reparse-all () nil)
1613
1614 (defbinding rc-get-style () style
1615 (widget widget))
1616
1617
1618
1619 ;;; Accelerator Groups
1620 #|
1621 (defbinding accel-group-activate (accel-group key modifiers) boolean
1622 (accel-group accel-group)
1623 ((gdk:keyval-from-name key) unsigned-int)
1624 (modifiers gdk:modifier-type))
1625
1626 (defbinding accel-groups-activate (object key modifiers) boolean
1627 (object object)
1628 ((gdk:keyval-from-name key) unsigned-int)
1629 (modifiers gdk:modifier-type))
1630
1631 (defbinding accel-group-attach () nil
1632 (accel-group accel-group)
1633 (object object))
1634
1635 (defbinding accel-group-detach () nil
1636 (accel-group accel-group)
1637 (object object))
1638
1639 (defbinding accel-group-lock () nil
1640 (accel-group accel-group))
1641
1642 (defbinding accel-group-unlock () nil
1643 (accel-group accel-group))
1644
1645
1646 ;;; Accelerator Groups Entries
1647
1648 (defbinding accel-group-get-entry (accel-group key modifiers) accel-entry
1649 (accel-group accel-group)
1650 ((gdk:keyval-from-name key) unsigned-int)
1651 (modifiers gdk:modifier-type))
1652
1653 (defbinding accel-group-lock-entry (accel-group key modifiers) nil
1654 (accel-group accel-group)
1655 ((gdk:keyval-from-name key) unsigned-int)
1656 (modifiers gdk:modifier-type))
1657
1658 (defbinding accel-group-unlock-entry (accel-group key modifiers) nil
1659 (accel-group accel-group)
1660 ((gdk:keyval-from-name key) unsigned-int)
1661 (modifiers gdk:modifier-type))
1662
1663 (defbinding accel-group-add
1664 (accel-group key modifiers flags object signal) nil
1665 (accel-group accel-group)
1666 ((gdk:keyval-from-name key) unsigned-int)
1667 (modifiers gdk:modifier-type)
1668 (flags accel-flags)
1669 (object object)
1670 ((name-to-string signal) string))
1671
1672 (defbinding accel-group-add (accel-group key modifiers object) nil
1673 (accel-group accel-group)
1674 ((gdk:keyval-from-name key) unsigned-int)
1675 (modifiers gdk:modifier-type)
1676 (object object))
1677
1678
1679 ;;; Accelerator Signals
1680
1681 (defbinding accel-group-handle-add
1682 (object signal-id accel-group key modifiers flags) nil
1683 (object object)
1684 (signal-id unsigned-int)
1685 (accel-group accel-group)
1686 ((gdk:keyval-from-name key) unsigned-int)
1687 (modifiers gdk:modifier-type)
1688 (flags accel-flags))
1689
1690 (defbinding accel-group-handle-remove
1691 (object accel-group key modifiers) nil
1692 (object object)
1693 (accel-group accel-group)
1694 ((gdk:keyval-from-name key) unsigned-int)
1695 (modifiers gdk:modifier-type))
1696 |#