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