Added pseudo type COPY-OF
[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.18 2004-11-19 13:09:00 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 &key button)
325 (declare (ignore button))
326 (call-next-method)
327 (dolist (button-definition (get-all initargs :button))
328 (apply #'dialog-add-button dialog (mklist button-definition))))
329
330
331 (defvar %*response-id-key* (gensym))
332
333 (defun %dialog-find-response-id-num (dialog id &optional create-p error-p)
334 (or
335 (cadr (assoc id (rest (type-expand-1 'response-type))))
336 (let ((response-ids (object-data dialog %*response-id-key*)))
337 (cond
338 ((and response-ids (position id response-ids :test #'equal)))
339 (create-p
340 (cond
341 (response-ids
342 (vector-push-extend id response-ids)
343 (1- (length response-ids)))
344 (t
345 (setf
346 (object-data dialog %*response-id-key*)
347 (make-array 1 :adjustable t :fill-pointer t :initial-element id))
348 0)))
349 (error-p
350 (error "Invalid response: ~A" id))))))
351
352 (defun %dialog-find-response-id (dialog response-id-num)
353 (if (< response-id-num 0)
354 (car
355 (rassoc
356 (list response-id-num)
357 (rest (type-expand-1 'response-type)) :test #'equal))
358 (aref (object-data dialog %*response-id-key*) response-id-num )))
359
360
361 (defmethod signal-connect ((dialog dialog) signal function &key object after)
362 (let ((response-id-num (%dialog-find-response-id-num dialog signal)))
363 (cond
364 (response-id-num
365 (call-next-method
366 dialog 'response
367 #'(lambda (dialog id)
368 (when (= id response-id-num)
369 (cond
370 ((eq object t) (funcall function dialog))
371 (object (funcall function object))
372 (t (funcall function)))))
373 :object t :after after))
374 ((call-next-method)))))
375
376
377 (defbinding dialog-run () nil
378 (dialog dialog))
379
380 (defbinding dialog-response (dialog response-id) nil
381 (dialog dialog)
382 ((%dialog-find-response-id-num dialog response-id nil t) int))
383
384
385 (defbinding %dialog-add-button () button
386 (dialog dialog)
387 (text string)
388 (response-id-num int))
389
390 (defun dialog-add-button (dialog label &optional (response label)
391 &key default object after)
392 "Adds a button to the dialog. If no response is given, then label
393 will be used."
394 (let* ((id (if (functionp response)
395 label
396 response))
397 (id-num (%dialog-find-response-id-num dialog id t))
398 (button (%dialog-add-button dialog label id-num)))
399 (when (functionp response)
400 (signal-connect dialog id response :object object :after after))
401 (when default
402 (%dialog-set-default-response dialog id-num))
403 button))
404
405
406 (defbinding %dialog-add-action-widget () button
407 (dialog dialog)
408 (action-widget widget)
409 (response-id-num int))
410
411 (defun dialog-add-action-widget (dialog widget &optional (response widget)
412 &key default object after)
413 (let* ((id (if (functionp response)
414 widget
415 response))
416 (id-num (%dialog-find-response-id-num dialog id t)))
417 (%dialog-add-action-widget dialog widget id-num)
418 (when (functionp response)
419 (signal-connect dialog id response :object object :after after))
420 (when default
421 (%dialog-set-default-response dialog id-num))
422 widget))
423
424
425 (defbinding %dialog-set-default-response () nil
426 (dialog dialog)
427 (response-id-num int))
428
429 (defun dialog-set-default-response (dialog response-id)
430 (%dialog-set-default-response
431 dialog (%dialog-find-response-id-num dialog response-id nil t)))
432
433 (defbinding dialog-set-response-sensitive (dialog response-id sensitive) nil
434 (dialog dialog)
435 ((%dialog-find-response-id-num dialog response-id nil t) int)
436 (sensitive boolean))
437
438
439 ;; Addition dialog functions
440
441 (defmethod container-add ((dialog dialog) (child widget) &rest args)
442 (apply #'container-add (dialog-vbox dialog) child args))
443
444 (defmethod container-remove ((dialog dialog) (child widget))
445 (container-remove (dialog-vbox dialog) child))
446
447 (defmethod container-children ((dialog dialog))
448 (container-children (dialog-vbox dialog)))
449
450 (defmethod (setf container-children) (children (dialog dialog))
451 (setf (container-children (dialog-vbox dialog)) children))
452
453
454
455 ;;; Drawing area -- no functions
456
457
458 ;;; Entry
459
460 (defbinding entry-get-layout () (copy-of pango:layout)
461 (entry entry))
462
463 (defbinding entry-get-layout-offsets () nil
464 (entry entry)
465 (x int :out)
466 (y int :out))
467
468
469 ;;; Image
470
471 (defbinding image-set-from-file () nil
472 (image image)
473 (filename pathname))
474
475 (defbinding image-set-from-pixmap () nil
476 (image image)
477 (pixmap gdk:pixmap)
478 (mask gdk:bitmap))
479
480 (defbinding image-set-from-stock () nil
481 (image image)
482 (stock-id string)
483 (icon-size icon-size))
484
485 (defun image-set-from-pixmap-data (image pixmap-data)
486 (multiple-value-bind (pixmap mask) (gdk:pixmap-create pixmap-data)
487 (image-set-from-pixmap image pixmap mask)))
488
489 (defun image-set-from-source (image source)
490 (etypecase source
491 (pathname (image-set-from-file image source))
492 (string (if (stock-lookup source)
493 (setf (image-stock image) source)
494 (image-set-from-file image source)))
495 (vector (image-set-from-pixmap-data image source))))
496
497
498 (defmethod shared-initialize ((image image) names &rest initargs
499 &key file pixmap source)
500 (prog1
501 (if (vectorp pixmap)
502 (progn
503 (remf initargs :pixmap)
504 (apply #'call-next-method image names initargs))
505 (call-next-method))
506 (cond
507 (file (image-set-from-file image file))
508 ((vectorp pixmap) (image-set-from-pixmap-data image pixmap))
509 (source (image-set-from-source image source)))))
510
511
512 ;;; Label
513
514 (defbinding label-get-layout-offsets () nil
515 (label label)
516 (x int :out)
517 (y int :out))
518
519 (defbinding label-select-region () nil
520 (label label)
521 (start int)
522 (end int))
523
524 (defbinding label-get-text () string
525 (label label))
526
527 (defbinding label-get-layout () (copy-of pango:layout)
528 (label label))
529
530 (defbinding label-get-selection-bounds () boolean
531 (label label)
532 (start int :out)
533 (end int :out))
534
535
536
537 ;;; Radio button
538
539 (defbinding %radio-button-get-group () pointer
540 (radio-button radio-button))
541
542 (defbinding %radio-button-set-group () nil
543 (radio-button radio-button)
544 (group pointer))
545
546 (defun radio-button-add-to-group (button1 button2)
547 "Add BUTTON1 to the group which BUTTON2 belongs to."
548 (%radio-button-set-group button1 (%radio-button-get-group button2)))
549
550
551 (defmethod initialize-instance ((button radio-button)
552 &rest initargs &key group-with)
553 (declare (ignore initargs))
554 (call-next-method)
555 (when group-with
556 (radio-button-add-to-group button group-with)))
557
558
559 ;;; Item
560
561 (defbinding item-select () nil
562 (item item))
563
564 (defbinding item-deselect () nil
565 (item item))
566
567 (defbinding item-toggle () nil
568 (item item))
569
570
571
572 ;;; Menu item
573
574 (defun (setf menu-item-label) (label menu-item)
575 (make-instance 'accel-label
576 :label label :xalign 0.0 :yalign 0.5 :accel-widget menu-item
577 :visible t :parent menu-item)
578 label)
579
580 (defun menu-item-label (menu-item)
581 (with-slots (child) menu-item
582 (when (typep child 'label)
583 (label-label child))))
584
585 (defbinding %menu-item-set-submenu () nil
586 (menu-item menu-item)
587 (submenu menu))
588
589 (defbinding %menu-item-remove-submenu () nil
590 (menu-item menu-item))
591
592 (defun (setf menu-item-submenu) (submenu menu-item)
593 (if (not submenu)
594 (%menu-item-remove-submenu menu-item)
595 (%menu-item-set-submenu menu-item submenu))
596 submenu)
597
598 (defbinding menu-item-set-accel-path () nil
599 (menu-item menu-item)
600 (accel-path string))
601
602 (defbinding menu-item-select () nil
603 (menu-item menu-item))
604
605 (defbinding menu-item-deselect () nil
606 (menu-item menu-item))
607
608 (defbinding menu-item-activate () nil
609 (menu-item menu-item))
610
611 (defbinding menu-item-toggle-size-request () nil
612 (menu-item menu-item)
613 (requisition int :out))
614
615 (defbinding menu-item-toggle-size-allocate () nil
616 (menu-item menu-item)
617 (allocation int))
618
619
620
621 ;;; Radio menu item
622
623 (defbinding %radio-menu-item-get-group () pointer
624 (radio-menu-item radio-menu-item))
625
626 (defbinding %radio-menu-item-set-group () nil
627 (radio-menu-item radio-menu-item)
628 (group pointer))
629
630 (defun radio-menu-item-add-to-group (item1 item2)
631 "Add ITEM1 to the group which ITEM2 belongs to."
632 (%radio-menu-item-set-group item1 (%radio-menu-item-get-group item2)))
633
634 (defmethod initialize-instance ((item radio-menu-item)
635 &rest initargs &key group-with)
636 (declare (ignore initargs))
637 (prog1
638 (call-next-method)
639 (when group-with
640 (radio-menu-item-add-to-group item group-with))))
641
642
643
644 ;;; Toggle button
645
646 (defbinding toggle-button-toggled () nil
647 (toggle-button toggle-button))
648
649
650
651 ;;; Window
652
653 (defbinding window-set-wmclass () nil
654 (window window)
655 (wmclass-name string)
656 (wmclass-class string))
657
658 (defbinding window-add-accel-group () nil
659 (window window)
660 (accel-group accel-group))
661
662 (defbinding window-remove-accel-group () nil
663 (window window)
664 (accel-group accel-group))
665
666 (defbinding window-activate-focus () int
667 (window window))
668
669 (defbinding window-activate-default () int
670 (window window))
671
672 (defbinding window-set-default-size (window width height) int
673 (window window)
674 ((or width -1) int)
675 ((or height -1) int))
676
677 ;(defbinding window-set-geometry-hints)
678
679 (defbinding window-list-toplevels () (glist window))
680
681 (defbinding window-add-mnemonic (window key target) nil
682 (window window)
683 ((gdk:keyval-from-name key) unsigned-int)
684 (target widget))
685
686 (defbinding window-remove-mnemonic (window key target) nil
687 (window window)
688 ((gdk:keyval-from-name key) unsigned-int)
689 (target widget))
690
691 (defbinding window-mnemonic-activate (window key modifier) nil
692 (window window)
693 ((gdk:keyval-from-name key) unsigned-int)
694 (modifier gdk:modifier-type))
695
696 (defbinding window-present () nil
697 (window window))
698
699 (defbinding window-iconify () nil
700 (window window))
701
702 (defbinding window-deiconify () nil
703 (window window))
704
705 (defbinding window-stick () nil
706 (window window))
707
708 (defbinding window-unstick () nil
709 (window window))
710
711 (defbinding window-maximize () nil
712 (window window))
713
714 (defbinding window-unmaximize () nil
715 (window window))
716
717 (defbinding window-begin-resize-drag () nil
718 (window window)
719 (edge gdk:window-edge)
720 (button int)
721 (root-x int) (root-y int)
722 (timestamp unsigned-int))
723
724 (defbinding window-begin-move-drag () nil
725 (window window)
726 (edge gdk:window-edge)
727 (button int)
728 (root-x int) (root-y int)
729 (timestamp unsigned-int))
730
731 (defbinding window-set-frame-dimensions () nil
732 (window window)
733 (left int) (top int) (rigth int) (bottom int))
734
735 (defbinding (window-default-icons "gtk_window_get_default_icon_list")
736 () (glist gdk:pixbuf))
737
738 (defbinding %window-get-default-size () nil
739 (window window)
740 (width int :out)
741 (height int :out))
742
743 (defun window-get-default-size (window)
744 (multiple-value-bind (width height) (%window-get-default-size window)
745 (values (unless (= width -1) width) (unless (= height -1) height))))
746
747 (defbinding window-get-frame-dimensions () nil
748 (window window)
749 (left int :out) (top int :out) (rigth int :out) (bottom int :out))
750
751 (defbinding %window-get-icon-list () (glist gdk:pixbuf)
752 (window window))
753
754 (defmethod window-icon ((window window))
755 (let ((icon-list (%window-get-icon-list window)))
756 (if (endp (rest icon-list))
757 (first icon-list)
758 icon-list)))
759
760 (defbinding window-get-position () nil
761 (window window)
762 (root-x int :out)
763 (root-y int :out))
764
765 (defbinding window-get-size () nil
766 (window window)
767 (width int :out)
768 (height int :out))
769
770 (defbinding window-move () nil
771 (window window)
772 (x int)
773 (y int))
774
775 (defbinding window-parse-geometry () boolean
776 (window window)
777 (geometry string))
778
779 (defbinding window-reshow-with-initial-size () nil
780 (window window))
781
782 (defbinding window-resize () nil
783 (window window)
784 (width int)
785 (heigth int))
786
787 (defbinding %window-set-icon-list () nil
788 (window window)
789 (icon-list (glist gdk:pixbuf)))
790
791 (defmethod (setf window-icon) (icon (window window))
792 (%window-set-icon-list window (mklist icon)))
793
794
795
796
797 ;;; File chooser
798
799
800
801
802 ;;; Scrolled window
803
804 (defun (setf scrolled-window-scrollbar-policy) (policy window)
805 (setf (scrolled-window-hscrollbar-policy window) policy)
806 (setf (scrolled-window-vscrollbar-policy window) policy))
807
808 (defbinding scrolled-window-add-with-viewport () nil
809 (scrolled-window scrolled-window)
810 (child widget))
811
812
813
814
815
816
817
818 ;;; Statusbar
819
820 (defbinding (statusbar-context-id "gtk_statusbar_get_context_id")
821 () unsigned-int
822 (statusbar statusbar)
823 (context-description string))
824
825 (defbinding statusbar-push () unsigned-int
826 (statusbar statusbar)
827 (context-id unsigned-int)
828 (text string))
829
830 (defbinding statusbar-pop () nil
831 (statusbar statusbar)
832 (context-id unsigned-int))
833
834 (defbinding statusbar-remove () nil
835 (statusbar statusbar)
836 (context-id unsigned-int)
837 (message-id unsigned-int))
838
839
840
841 ;;; Fixed
842
843 (defbinding fixed-put () nil
844 (fixed fixed)
845 (widget widget)
846 (x int) (y int))
847
848 (defbinding fixed-move () nil
849 (fixed fixed)
850 (widget widget)
851 (x int) (y int))
852
853
854
855 ;;; Notebook
856
857 (defun %notebook-position (notebook page)
858 (etypecase page
859 (int page)
860 (keyword (case page
861 (:first 0)
862 (:last -1)
863 (t (error "Invalid position keyword: ~A" page))))
864 (widget (notebook-page-num notebook page t))))
865
866 (defun %notebook-child (notebook position)
867 (typecase position
868 (widget position)
869 (t (notebook-nth-page-child notebook position))))
870
871
872 (defbinding (notebook-insert "gtk_notebook_insert_page_menu")
873 (notebook position child tab-label &optional menu-label) nil
874 (notebook notebook)
875 (child widget)
876 ((if (stringp tab-label)
877 (make-instance 'label :label tab-label)
878 tab-label) widget)
879 ((if (stringp menu-label)
880 (make-instance 'label :label menu-label)
881 menu-label) (or null widget))
882 ((%notebook-position notebook position) int))
883
884 (defun notebook-append (notebook child tab-label &optional menu-label)
885 (notebook-insert notebook :last child tab-label menu-label))
886
887 (defun notebook-prepend (notebook child tab-label &optional menu-label)
888 (notebook-insert notebook :first child tab-label menu-label))
889
890 (defbinding notebook-remove-page (notebook page) nil
891 (notebook notebook)
892 ((%notebook-position notebook page) int))
893
894 (defbinding %notebook-page-num () int
895 (notebook notebook)
896 (child widget))
897
898 (defun notebook-page-num (notebook child &optional error-p)
899 (let ((page-num (%notebook-page-num notebook child)))
900 (if (= page-num -1)
901 (when error-p
902 (error "~A is not a child of ~A" child notebook))
903 page-num)))
904
905 (defbinding notebook-next-page () nil
906 (notebook notebook))
907
908 (defbinding notebook-prev-page () nil
909 (notebook notebook))
910
911 (defbinding notebook-reorder-child (notebook child position) nil
912 (notebook notebook)
913 (child widget)
914 ((%notebook-position notebook position) int))
915
916 (defbinding notebook-popup-enable () nil
917 (notebook notebook))
918
919 (defbinding notebook-popup-disable () nil
920 (notebook notebook))
921
922 (defbinding (notebook-nth-page-child "gtk_notebook_get_nth_page")
923 (notebook page) widget
924 (notebook notebook)
925 ((case page
926 (:first 0)
927 (:last -1)
928 (t page)) int))
929
930
931 (defbinding %notebook-get-current-page () int
932 (notebook notebook))
933
934 (defun notebook-current-page-num (notebook)
935 (let ((num (%notebook-get-current-page notebook)))
936 (when (>= num 0)
937 num)))
938
939 (defun notebook-current-page (notebook)
940 (let ((page-num (notebook-current-page-num notebook)))
941 (when page-num
942 (notebook-nth-page-child notebook page-num))))
943
944 (defbinding %notebook-set-current-page () nil
945 (notebook notebook)
946 (page-num int))
947
948 (defun (setf notebook-current-page) (page notebook)
949 (%notebook-set-current-page notebook (%notebook-position notebook page))
950 page)
951
952
953 (defbinding (notebook-tab-label "gtk_notebook_get_tab_label")
954 (notebook page) widget
955 (notebook notebook)
956 ((%notebook-child notebook page) widget))
957
958 (defbinding (notebook-tab-label-text "gtk_notebook_get_tab_label_text")
959 (notebook page) (copy-of string)
960 (notebook notebook)
961 ((%notebook-child notebook page) widget))
962
963 (defbinding %notebook-set-tab-label () nil
964 (notebook notebook)
965 (page widget)
966 (tab-label widget))
967
968 (defun (setf notebook-tab-label) (tab-label notebook page)
969 (let ((widget (if (stringp tab-label)
970 (make-instance 'label :label tab-label)
971 tab-label)))
972 (%notebook-set-tab-label notebook (%notebook-child notebook page) widget)
973 widget))
974
975
976 (defbinding (notebook-menu-label "gtk_notebook_get_menu_label")
977 (notebook page) widget
978 (notebook notebook)
979 ((%notebook-child notebook page) widget))
980
981 (defbinding (notebook-menu-label-text "gtk_notebook_get_menu_label_text")
982 (notebook page) (copy-of string)
983 (notebook notebook)
984 ((%notebook-child notebook page) widget))
985
986 (defbinding %notebook-set-menu-label () nil
987 (notebook notebook)
988 (page widget)
989 (menu-label widget))
990
991 (defun (setf notebook-menu-label) (menu-label notebook page)
992 (let ((widget (if (stringp menu-label)
993 (make-instance 'label :label menu-label)
994 menu-label)))
995 (%notebook-set-menu-label notebook (%notebook-child notebook page) widget)
996 widget))
997
998
999 (defbinding notebook-query-tab-label-packing (notebook page) nil
1000 (notebook notebook)
1001 ((%notebook-child notebook page) widget)
1002 (expand boolean :out)
1003 (fill boolean :out)
1004 (pack-type pack-type :out))
1005
1006 (defbinding notebook-set-tab-label-packing
1007 (notebook page expand fill pack-type) nil
1008 (notebook notebook)
1009 ((%notebook-child notebook page) widget)
1010 (expand boolean)
1011 (fill boolean)
1012 (pack-type pack-type))
1013
1014
1015
1016 ;;; Paned
1017
1018 (defbinding paned-pack1 () nil
1019 (paned paned)
1020 (child widget)
1021 (resize boolean)
1022 (shrink boolean))
1023
1024 (defbinding paned-pack2 () nil
1025 (paned paned)
1026 (child widget)
1027 (resize boolean)
1028 (shrink boolean))
1029
1030 (defun (setf paned-child1) (child paned)
1031 (paned-pack1 paned child nil t)
1032 child)
1033
1034 (defun (setf paned-child2) (child paned)
1035 (paned-pack2 paned child t t)
1036 child)
1037
1038 ;; Defined in gtkglue.c
1039 (defbinding paned-child1 () widget
1040 (paned paned)
1041 (resize boolean :out)
1042 (shrink boolean :out))
1043
1044 ;; Defined in gtkglue.c
1045 (defbinding paned-child2 () widget
1046 (paned paned)
1047 (resize boolean :out)
1048 (shrink boolean :out))
1049
1050
1051
1052 ;;; Layout
1053
1054 (defbinding layout-put () nil
1055 (layout layout)
1056 (widget widget)
1057 (x int)
1058 (y int))
1059
1060 (defbinding layout-move () nil
1061 (layout layout)
1062 (widget widget)
1063 (x int)
1064 (y int))
1065
1066
1067
1068 ;;; Menu shell
1069
1070 (defbinding menu-shell-insert (menu-shell menu-item position) nil
1071 (menu-shell menu-shell)
1072 (menu-item menu-item)
1073 ((case position
1074 (:first 0)
1075 (:last -1)
1076 (t position)) int))
1077
1078 (defun menu-shell-append (menu-shell menu-item)
1079 (menu-shell-insert menu-shell menu-item :last))
1080
1081 (defun menu-shell-prepend (menu-shell menu-item)
1082 (menu-shell-insert menu-shell menu-item :fisrt))
1083
1084 (defbinding menu-shell-deactivate () nil
1085 (menu-shell menu-shell))
1086
1087 (defbinding menu-shell-select-item () nil
1088 (menu-shell menu-shell)
1089 (menu-item menu-item))
1090
1091 (defbinding menu-shell-deselect () nil
1092 (menu-shell menu-shell))
1093
1094 (defbinding menu-shell-activate-item () nil
1095 (menu-shell menu-shell)
1096 (menu-item menu-item)
1097 (fore-deactivate boolean))
1098
1099
1100
1101 ;;; Menu
1102
1103 (defun %menu-position (menu child)
1104 (etypecase child
1105 (int child)
1106 (keyword (case child
1107 (:first 0)
1108 (:last -1)
1109 (t (error "Invalid position keyword: ~A" child))))
1110 (widget (menu-child-position menu child))))
1111
1112
1113 (defbinding menu-reorder-child (menu menu-item position) nil
1114 (menu menu)
1115 (menu-item menu-item)
1116 ((%menu-position menu position) int))
1117
1118 (def-callback-marshal %menu-popup-callback (nil (x int) (y int) (push-in boolean)))
1119
1120 (defbinding %menu-popup () nil
1121 (menu menu)
1122 (parent-menu-shell (or null menu-shell))
1123 (parent-menu-item (or null menu-item))
1124 (callback-func (or null pointer))
1125 (callback-id unsigned-int)
1126 (button unsigned-int)
1127 (activate-time (unsigned 32)))
1128
1129 (defun menu-popup (menu button activate-time &key callback parent-menu-shell
1130 parent-menu-item)
1131 (if callback
1132 (with-callback-function (id callback)
1133 (%menu-popup
1134 menu parent-menu-shell parent-menu-item
1135 (callback %menu-popup-callback) id button activate-time))
1136 (%menu-popup
1137 menu parent-menu-shell parent-menu-item nil 0 button activate-time)))
1138
1139 (defbinding menu-set-accel-path () nil
1140 (menu menu)
1141 (accel-path string))
1142
1143 (defbinding menu-reposition () nil
1144 (menu menu))
1145
1146 (defbinding menu-popdown () nil
1147 (menu menu))
1148
1149 (defun menu-child-position (menu child)
1150 (position child (container-children menu)))
1151
1152 (defun menu-active-num (menu)
1153 (menu-child-position menu (menu-active menu)))
1154
1155 (defbinding %menu-set-active () nil
1156 (menu menu)
1157 (index unsigned-int))
1158
1159 (defun (setf menu-active) (menu child)
1160 (%menu-set-active menu (%menu-position menu child))
1161 child)
1162
1163
1164
1165 ;;; Table
1166
1167 (defbinding table-resize () nil
1168 (table table)
1169 (rows unsigned-int)
1170 (columns unsigned-int))
1171
1172 (defbinding table-attach (table child left right top bottom
1173 &key (x-options '(:expand :fill))
1174 (y-options '(:expand :fill))
1175 (x-padding 0) (y-padding 0)) nil
1176 (table table)
1177 (child widget)
1178 (left unsigned-int)
1179 (right unsigned-int)
1180 (top unsigned-int)
1181 (bottom unsigned-int)
1182 (x-options attach-options)
1183 (y-options attach-options)
1184 (x-padding unsigned-int)
1185 (y-padding unsigned-int))
1186
1187
1188 (defbinding %table-set-row-spacing () nil
1189 (table table)
1190 (row unsigned-int)
1191 (spacing unsigned-int))
1192
1193 (defbinding %table-set-row-spacings () nil
1194 (table table)
1195 (spacing unsigned-int))
1196
1197 (defun (setf table-row-spacing) (spacing table &optional row)
1198 (if row
1199 (%table-set-row-spacing table row spacing)
1200 (%table-set-row-spacings table spacing))
1201 spacing)
1202
1203 (defbinding %table-get-row-spacing () unsigned-int
1204 (table table)
1205 (row unsigned-int))
1206
1207 (defbinding %table-get-default-row-spacing () unsigned-int
1208 (table table))
1209
1210 (defun table-row-spacing (table &optional row)
1211 (if row
1212 (%table-get-row-spacing table row)
1213 (%table-get-default-row-spacing table)))
1214
1215
1216 (defbinding %table-set-col-spacing () nil
1217 (table table)
1218 (col unsigned-int)
1219 (spacing unsigned-int))
1220
1221 (defbinding %table-set-col-spacings () nil
1222 (table table)
1223 (spacing unsigned-int))
1224
1225 (defun (setf table-col-spacing) (spacing table &optional col)
1226 (if col
1227 (%table-set-col-spacing table col spacing)
1228 (%table-set-col-spacings table spacing))
1229 spacing)
1230
1231 (defbinding %table-get-col-spacing () unsigned-int
1232 (table table)
1233 (col unsigned-int))
1234
1235 (defbinding %table-get-default-col-spacing () unsigned-int
1236 (table table))
1237
1238 (defun table-col-spacing (table &optional col)
1239 (if col
1240 (%table-get-col-spacing table col)
1241 (%table-get-default-col-spacing table)))
1242
1243
1244
1245 ;;; Toolbar
1246
1247 (defbinding %toolbar-insert-element () widget
1248 (toolbar toolbar)
1249 (type toolbar-child-type)
1250 (widget (or null widget))
1251 (text string)
1252 (tooltip-text string)
1253 (tooltip-private-text string)
1254 (icon (or null widget))
1255 (nil null)
1256 (nil null)
1257 (position int))
1258
1259 (defbinding %toolbar-insert-stock () widget
1260 (toolbar toolbar)
1261 (stock-id string)
1262 (tooltip-text string)
1263 (tooltip-private-text string)
1264 (nil null)
1265 (nil null)
1266 (position int))
1267
1268 (defun toolbar-insert (toolbar position element
1269 &key tooltip-text tooltip-private-text
1270 type icon group callback object)
1271 (let* ((numpos (case position
1272 (:first -1)
1273 (:last 0)
1274 (t position)))
1275 (widget
1276 (cond
1277 ((or
1278 (eq type :space)
1279 (and (not type) (eq element :space)))
1280 (%toolbar-insert-element
1281 toolbar :space nil nil
1282 tooltip-text tooltip-private-text nil numpos))
1283 ((or
1284 (eq type :widget)
1285 (and (not type) (typep element 'widget)))
1286 (%toolbar-insert-element
1287 toolbar :widget element nil
1288 tooltip-text tooltip-private-text nil numpos))
1289 ((or
1290 (eq type :stock)
1291 (and
1292 (not type)
1293 (typep element 'string)
1294 (stock-lookup element)))
1295 (%toolbar-insert-stock
1296 toolbar element tooltip-text tooltip-private-text numpos))
1297 ((typep element 'string)
1298 (%toolbar-insert-element
1299 toolbar (or type :button) (when (eq type :radio-button) group)
1300 element tooltip-text tooltip-private-text
1301 (etypecase icon
1302 (null nil)
1303 (widget icon)
1304 ((or pathname string vector)
1305 (make-instance 'image
1306 :source icon ; :icon-size (toolbar-icon-size toolbar)
1307 )))
1308 numpos))
1309 ((error "Invalid element type: ~A" element)))))
1310 (when callback
1311 (signal-connect widget 'clicked callback :object object))
1312 widget))
1313
1314 (defun toolbar-append (toolbar element &key tooltip-text tooltip-private-text
1315 type icon group callback object)
1316 (toolbar-insert
1317 toolbar :first element :type type :icon icon :group group
1318 :tooltip-text tooltip-text :tooltip-private-text tooltip-private-text
1319 :callback callback :object object))
1320
1321 (defun toolbar-prepend (toolbar element &key tooltip-text tooltip-private-text
1322 type icon group callback object)
1323 (toolbar-insert
1324 toolbar :last element :type type :icon icon :group group
1325 :tooltip-text tooltip-text :tooltip-private-text tooltip-private-text
1326 :callback callback :object object))
1327
1328
1329 (defun toolbar-insert-space (toolbar position)
1330 (toolbar-insert toolbar position :space))
1331
1332 (defun toolbar-append-space (toolbar)
1333 (toolbar-append toolbar :space))
1334
1335 (defun toolbar-prepend-space (toolbar)
1336 (toolbar-prepend toolbar :space))
1337
1338
1339 (defun toolbar-enable-tooltips (toolbar)
1340 (setf (toolbar-tooltips-p toolbar) t))
1341
1342 (defun toolbar-disable-tooltips (toolbar)
1343 (setf (toolbar-tooltips-p toolbar) nil))
1344
1345
1346 (defbinding toolbar-remove-space () nil
1347 (toolbar toolbar)
1348 (position int))
1349
1350 (defbinding toolbar-unset-icon-size () nil
1351 (toolbar toolbar))
1352
1353 (defbinding toolbar-unset-style () nil
1354 (toolbar toolbar))
1355
1356
1357 ;;; Editable
1358
1359 (defbinding editable-select-region (editable &optional (start 0) end) nil
1360 (editable editable)
1361 (start int)
1362 ((or end -1) int))
1363
1364 (defbinding editable-get-selection-bounds (editable) nil
1365 (editable editable)
1366 (start int :out)
1367 (end int :out))
1368
1369 (defbinding editable-insert-text
1370 (editable text &optional (position 0)) nil
1371 (editable editable)
1372 (text string)
1373 ((length text) int)
1374 ((or position -1) int :in-out))
1375
1376 (defun editable-append-text (editable text)
1377 (editable-insert-text editable text nil))
1378
1379 (defun editable-prepend-text (editable text)
1380 (editable-insert-text editable text 0))
1381
1382 (defbinding editable-delete-text (editable &optional (start 0) end) nil
1383 (editable editable)
1384 (start int)
1385 ((or end -1) int))
1386
1387 (defbinding (editable-text "gtk_editable_get_chars")
1388 (editable &optional (start 0) end) string
1389 (editable editable)
1390 (start int)
1391 ((or end -1) int))
1392
1393 (defun (setf editable-text) (text editable)
1394 (if text
1395 (editable-delete-text
1396 editable
1397 (editable-insert-text editable text))
1398 (editable-delete-text editable))
1399 text)
1400
1401 (defbinding editable-cut-clipboard () nil
1402 (editable editable))
1403
1404 (defbinding editable-copy-clipboard () nil
1405 (editable editable))
1406
1407 (defbinding editable-paste-clipboard () nil
1408 (editable editable))
1409
1410 (defbinding editable-delete-selection () nil
1411 (editable editable))
1412
1413
1414
1415 ;;; Spin button
1416
1417 (defun spin-button-value-as-int (spin-button)
1418 (round (spin-button-value spin-button)))
1419
1420 (defbinding spin-button-spin () nil
1421 (spin-button spin-button)
1422 (direction spin-type)
1423 (increment single-float))
1424
1425 (defbinding spin-button-update () nil
1426 (spin-button spin-button))
1427
1428
1429
1430 ; ;;; Ruler
1431
1432 (defbinding ruler-set-range () nil
1433 (ruler ruler)
1434 (lower single-float)
1435 (upper single-float)
1436 (position single-float)
1437 (max-size single-float))
1438
1439 (defbinding ruler-draw-ticks () nil
1440 (ruler ruler))
1441
1442 (defbinding ruler-draw-pos () nil
1443 (ruler ruler))
1444
1445
1446
1447 ;;; Range
1448
1449 (defun range-lower (range)
1450 (adjustment-lower (range-adjustment range)))
1451
1452 (defun range-upper (range)
1453 (adjustment-upper (range-adjustment range)))
1454
1455 (defun (setf range-lower) (value range)
1456 (setf (adjustment-lower (range-adjustment range)) value))
1457
1458 (defun (setf range-upper) (value range)
1459 (setf (adjustment-upper (range-adjustment range)) value))
1460
1461 (defun range-page-increment (range)
1462 (adjustment-page-increment (range-adjustment range)))
1463
1464 (defun range-step-increment (range)
1465 (adjustment-step-increment (range-adjustment range)))
1466
1467 (defun (setf range-page-increment) (value range)
1468 (setf (adjustment-page-increment (range-adjustment range)) value))
1469
1470 (defun (setf range-step-increment) (value range)
1471 (setf (adjustment-step-increment (range-adjustment range)) value))
1472
1473 (defbinding range-set-range () nil
1474 (range range)
1475 (lower double-float)
1476 (upper double-float))
1477
1478 (defbinding range-set-increments () nil
1479 (range range)
1480 (step double-float)
1481 (page double-float))
1482
1483
1484 ;;; Scale
1485
1486 ; (defbinding scale-draw-value () nil
1487 ; (scale scale))
1488
1489
1490
1491 ;;; Progress bar
1492
1493 (defbinding progress-bar-pulse () nil
1494 (progress-bar progress-bar))
1495
1496
1497
1498 ;;; Stock items
1499
1500 (defbinding stock-lookup () boolean
1501 (stock-id string)
1502 ((make-instance 'stock-item) stock-item :return))
1503
1504
1505
1506
1507 ;;; Tooltips
1508
1509 (defbinding tooltips-enable () nil
1510 (tooltips tooltips))
1511
1512 (defbinding tooltips-disable () nil
1513 (tooltips tooltips))
1514
1515 (defun (setf tooltips-enabled-p) (enable tooltips)
1516 (if enable
1517 (tooltips-enable tooltips)
1518 (tooltips-disable tooltips)))
1519
1520 (defbinding tooltips-set-tip () nil
1521 (tooltips tooltips)
1522 (widget widget)
1523 (tip-text string)
1524 (tip-private string))
1525
1526 (defbinding tooltips-force-window () nil
1527 (tooltips tooltips))
1528
1529
1530
1531 ;;; Rc
1532
1533 (defbinding rc-add-default-file (filename) nil
1534 ((namestring (truename filename)) string))
1535
1536 (defbinding rc-parse (filename) nil
1537 ((namestring (truename filename)) string))
1538
1539 (defbinding rc-parse-string () nil
1540 (rc-string string))
1541
1542 (defbinding rc-reparse-all () nil)
1543
1544 (defbinding rc-get-style () style
1545 (widget widget))
1546
1547
1548
1549 ;;; Accelerator Groups
1550 #|
1551 (defbinding accel-group-get-default () accel-group)
1552
1553 (deftype-method alien-ref accel-group (type-spec)
1554 (declare (ignore type-spec))
1555 '%accel-group-ref)
1556
1557 (deftype-method alien-unref accel-group (type-spec)
1558 (declare (ignore type-spec))
1559 '%accel-group-unref)
1560
1561 (defbinding %accel-group-ref () accel-group
1562 (accel-group (or accel-group pointer)))
1563
1564 (defbinding %accel-group-unref () nil
1565 (accel-group (or accel-group pointer)))
1566
1567 (defbinding accel-group-activate (accel-group key modifiers) boolean
1568 (accel-group accel-group)
1569 ((gdk:keyval-from-name key) unsigned-int)
1570 (modifiers gdk:modifier-type))
1571
1572 (defbinding accel-groups-activate (object key modifiers) boolean
1573 (object object)
1574 ((gdk:keyval-from-name key) unsigned-int)
1575 (modifiers gdk:modifier-type))
1576
1577 (defbinding accel-group-attach () nil
1578 (accel-group accel-group)
1579 (object object))
1580
1581 (defbinding accel-group-detach () nil
1582 (accel-group accel-group)
1583 (object object))
1584
1585 (defbinding accel-group-lock () nil
1586 (accel-group accel-group))
1587
1588 (defbinding accel-group-unlock () nil
1589 (accel-group accel-group))
1590
1591
1592 ;;; Accelerator Groups Entries
1593
1594 (defbinding accel-group-get-entry (accel-group key modifiers) accel-entry
1595 (accel-group accel-group)
1596 ((gdk:keyval-from-name key) unsigned-int)
1597 (modifiers gdk:modifier-type))
1598
1599 (defbinding accel-group-lock-entry (accel-group key modifiers) nil
1600 (accel-group accel-group)
1601 ((gdk:keyval-from-name key) unsigned-int)
1602 (modifiers gdk:modifier-type))
1603
1604 (defbinding accel-group-unlock-entry (accel-group key modifiers) nil
1605 (accel-group accel-group)
1606 ((gdk:keyval-from-name key) unsigned-int)
1607 (modifiers gdk:modifier-type))
1608
1609 (defbinding accel-group-add
1610 (accel-group key modifiers flags object signal) nil
1611 (accel-group accel-group)
1612 ((gdk:keyval-from-name key) unsigned-int)
1613 (modifiers gdk:modifier-type)
1614 (flags accel-flags)
1615 (object object)
1616 ((name-to-string signal) string))
1617
1618 (defbinding accel-group-add (accel-group key modifiers object) nil
1619 (accel-group accel-group)
1620 ((gdk:keyval-from-name key) unsigned-int)
1621 (modifiers gdk:modifier-type)
1622 (object object))
1623
1624
1625 ;;; Accelerator Signals
1626
1627 (defbinding accel-group-handle-add
1628 (object signal-id accel-group key modifiers flags) nil
1629 (object object)
1630 (signal-id unsigned-int)
1631 (accel-group accel-group)
1632 ((gdk:keyval-from-name key) unsigned-int)
1633 (modifiers gdk:modifier-type)
1634 (flags accel-flags))
1635
1636 (defbinding accel-group-handle-remove
1637 (object accel-group key modifiers) nil
1638 (object object)
1639 (accel-group accel-group)
1640 ((gdk:keyval-from-name key) unsigned-int)
1641 (modifiers gdk:modifier-type))
1642 |#