1 ;; Common Lisp bindings for GTK+ v2.0
2 ;; Copyright (C) 1999-2005 Espen S. Johnsen <espen@users.sf.net>
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.
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.
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
18 ;; $Id: testgtk.lisp,v 1.21 2005-02-27 13:28:19 espen Exp $
24 (defmacro define-toplevel (name (window title &rest initargs) &body body)
28 (setq ,window (make-instance 'window :title ,title ,@initargs :show-children t))
29 (signal-connect ,window 'destroy #'(lambda () (setq ,window nil)))
32 (if (not (widget-visible-p ,window))
34 (widget-hide ,window)))))
37 (defmacro define-dialog (name (dialog title &optional (class 'dialog)
43 (setq ,dialog (make-instance ,class :title ,title ,@initargs :show-children t))
44 (signal-connect ,dialog 'destroy #'(lambda () (setq ,dialog nil)))
47 (if (not (widget-visible-p ,dialog))
49 (widget-hide ,dialog)))))
52 (defmacro define-simple-dialog (name (dialog title &rest initargs) &body body)
53 `(define-dialog ,name (,dialog ,title 'dialog ,@initargs)
55 (dialog-add-button ,dialog "gtk-close" #'widget-destroy :object t)))
59 ;;; Pixmaps used in some of the tests
101 (defvar book-closed-xpm
126 (defvar mini-page-xpm
149 (defvar book-open-xpm
176 (defun create-bbox-in-frame (class frame-label spacing width height layout)
177 (declare (ignore width height))
178 (make-instance 'frame
180 :child (make-instance class
181 :border-width 5 :layout-style layout :spacing spacing
182 :child (make-instance 'button :stock "gtk-ok")
183 :child (make-instance 'button :stock "gtk-cancel")
184 :child (make-instance 'button :stock "gtk-help"))))
186 (define-toplevel create-button-box (window "Button Boxes")
187 (make-instance 'v-box
188 :parent window :border-width 10 :spacing 10
189 :child (make-instance 'frame
190 :label "Horizontal Button Boxes"
191 :child (make-instance 'v-box
192 :border-width 10 :spacing 10
195 (apply #'create-bbox-in-frame
197 '(("Spread" 40 85 20 :spread)
198 ("Edge" 40 85 20 :edge)
199 ("Start" 40 85 20 :start)
200 ("End" 40 85 20 :end)))))
201 :child (make-instance 'frame
202 :label "Vertical Button Boxes"
203 :child (make-instance 'h-box
204 :border-width 10 :spacing 10
207 (apply #'create-bbox-in-frame
209 '(("Spread" 30 85 20 :spread)
210 ("Edge" 30 85 20 :edge)
211 ("Start" 30 85 20 :start)
212 ("End" 30 85 20 :end)))))))
217 (define-simple-dialog create-buttons (dialog "Buttons")
218 (let ((table (make-instance 'table
219 :n-rows 3 :n-columns 3 :homogeneous nil
220 :row-spacing 5 :column-spacing 5 :border-width 10
224 collect (make-instance 'button
225 :label (format nil "button~D" (1+ n))))))
229 (let ((button (nth (+ (* 3 row) column) buttons))
230 (button+1 (nth (mod (+ (* 3 row) column 1) 9) buttons)))
231 (signal-connect button 'clicked
233 (if (widget-visible-p button+1)
234 (widget-hide button+1)
235 (widget-show button+1))))
236 (table-attach table button column (1+ column) row (1+ row)
237 :options '(:expand :fill)))))))
242 (define-simple-dialog create-calendar (dialog "Calendar")
243 (make-instance 'v-box
244 :parent dialog :border-width 10
245 :child (make-instance 'calendar)))
250 (define-simple-dialog create-check-buttons (dialog "Check Buttons")
251 (make-instance 'v-box
252 :border-width 10 :spacing 10 :parent dialog
255 collect (make-instance 'check-button
256 :label (format nil "Button~D" n)))))
262 (define-dialog create-color-selection (dialog "Color selection dialog"
263 'color-selection-dialog
264 :allow-grow nil :allow-shrink nil
266 (with-slots (colorsel) dialog
267 (let ((button (make-instance 'check-button :label "Show Opacity")))
268 (dialog-add-action-widget dialog button
271 (color-selection-has-opacity-control-p colorsel)
272 (toggle-button-active-p button)))))
274 (let ((button (make-instance 'check-button :label "Show Palette")))
275 (dialog-add-action-widget dialog button
278 (color-selection-has-palette-p colorsel)
279 (toggle-button-active-p button)))))
281 (signal-connect dialog :ok
283 (let ((color (color-selection-current-color colorsel)))
284 (format t "Selected color: ~A~%" color)
285 (setf (color-selection-current-color colorsel) color)
286 (widget-hide dialog))))
288 (signal-connect dialog :cancel #'widget-destroy :object t)))
293 (defun clamp (n min-val max-val)
294 (declare (number n min-val max-val))
295 (max (min n max-val) min-val))
297 (defun set-cursor (spinner drawing-area label)
300 (logand (clamp (spin-button-value-as-int spinner) 0 152) #xFE)
302 (setf (label-label label) (string-downcase cursor))
303 (setf (widget-cursor drawing-area) cursor)))
305 (defun cursor-expose (drawing-area event)
306 (declare (ignore event))
307 (multiple-value-bind (width height)
308 (widget-get-size-allocation drawing-area)
309 (let* ((window (widget-window drawing-area))
310 (style (widget-style drawing-area))
311 (white-gc (style-white-gc style))
312 (gray-gc (style-bg-gc style :normal))
313 (black-gc (style-black-gc style)))
314 (gdk:draw-rectangle window white-gc t 0 0 width (floor height 2))
315 (gdk:draw-rectangle window black-gc t 0 (floor height 2) width
317 (gdk:draw-rectangle window gray-gc t (floor width 3)
318 (floor height 3) (floor width 3)
322 (define-simple-dialog create-cursors (dialog "Cursors")
323 (let ((spinner (make-instance 'spin-button
324 :adjustment (adjustment-new
326 (1- (enum-int :last-cursor 'gdk:cursor-type))
328 (drawing-area (make-instance 'drawing-area
329 :width-request 80 :height-request 80
330 :events '(:exposure :button-press)))
331 (label (make-instance 'label :label "XXX")))
333 (signal-connect drawing-area 'expose-event #'cursor-expose :object t)
335 (signal-connect drawing-area 'button-press-event
337 (case (gdk:event-button event)
338 (1 (spin-button-spin spinner :step-forward))
339 (3 (spin-button-spin spinner :step-backward)))
342 (signal-connect drawing-area 'scroll-event
344 (case (gdk:event-direction event)
345 (:up (spin-button-spin spinner :step-forward))
346 (:down (spin-button-spin spinner :step-backward)))
349 (signal-connect spinner 'changed
351 (set-cursor spinner drawing-area label)))
353 (make-instance 'v-box
354 :parent dialog :border-width 10 :spacing 5
356 (make-instance 'h-box
359 (make-instance 'label :label "Cursor Value : ")
363 :child (make-instance 'frame
364 :label "Cursor Area" :label-xalign 0.5 :border-width 10
366 :child (list label :expand nil))
368 (widget-realize drawing-area)
369 (set-cursor spinner drawing-area label)))
375 (defun create-dialog ()
377 (setq dialog (make-instance 'dialog
378 :title "Dialog" :default-width 200
380 :button (list "gtk-ok" #'widget-destroy :object t)
381 :signal (list 'destroy
383 (setq dialog nil)))))
385 (let ((label (make-instance 'label
386 :label "Dialog Test" :xpad 10 :ypad 10 :visible t
388 (signal-connect dialog "Toggle"
390 (if (widget-visible-p label)
392 (widget-show label))))))
394 (if (widget-visible-p dialog)
396 (widget-show dialog))))
401 (define-simple-dialog create-entry (dialog "Entry")
402 (let ((main (make-instance 'v-box
403 :border-width 10 :spacing 10 :parent dialog)))
405 (let ((entry (make-instance 'entry :text "hello world" :parent main)))
406 (editable-select-region entry 0 5) ; this has no effect when
408 ;; (editable-insert-text entry "great " 6)
409 ;; (editable-delete-text entry 6 12)
411 (let ((combo (make-instance 'combo-box-entry
416 "item3 item3 item3 item3"
417 "item4 item4 item4 item4 item4"
418 "item5 item5 item5 item5 item5 item5"
419 "item6 item6 item6 item6 item6"
420 "item7 item7 item7 item7"
423 (with-slots (child) combo
424 (setf (editable-text child) "hello world")
425 (editable-select-region child 0)))
427 (flet ((create-check-button (label slot)
428 (make-instance 'check-button
429 :label label :active t :parent main
430 :signal (list 'toggled
432 (setf (slot-value entry slot)
433 (toggle-button-active-p button)))
436 (create-check-button "Editable" 'editable)
437 (create-check-button "Visible" 'visibility)
438 (create-check-button "Sensitive" 'sensitive)))))
443 (define-simple-dialog create-expander (dialog "Expander" :resizable nil)
444 (make-instance 'v-box
445 :parent dialog :spacing 5 :border-width 5
446 :child (create-label "Expander demo. Click on the triangle for details.")
447 :child (make-instance 'expander
449 :child (create-label "Details can be shown or hidden."))))
452 ;; File chooser dialog
454 (define-dialog create-file-chooser (dialog "File Chooser" 'file-chooser-dialog)
455 (dialog-add-button dialog "gtk-cancel" #'widget-destroy :object t)
456 (dialog-add-button dialog "gtk-ok"
458 (if (slot-boundp dialog 'filename)
459 (format t "Selected file: ~A~%" (file-chooser-filename dialog))
460 (write-line "No files selected"))
461 (widget-destroy dialog))))
464 ;; Font selection dialog
466 (define-toplevel create-font-selection (window "Font Button" :resizable nil)
467 (make-instance 'h-box
468 :parent window :spacing 8 :border-width 8
469 :child (make-instance 'label :label "Pick a font")
470 :child (make-instance 'font-button
471 :use-font t :title "Font Selection Dialog")))
476 (define-toplevel create-handle-box (window "Handle Box Test" :border-width 20)
477 (make-instance 'v-box
479 :child (create-label "Above")
480 :child (make-instance 'h-separator)
481 :child (make-instance 'h-box
484 (make-instance 'handle-box
485 :child (create-toolbar window)
486 :signal (list 'child-attached
488 (format t "~A attached~%" child)))
489 :signal (list 'child-detached
491 (format t "~A detached~%" child))))
492 :expand nil :fill :nil))
493 :child (make-instance 'h-separator)
494 :child (create-label "Below")))
498 (define-toplevel create-image (window "Image")
499 (make-instance 'image :file #p"clg:examples;gtk.png" :parent window))
504 (define-toplevel create-labels (window "Labels" :border-width 5 :resizable nil)
505 (flet ((create-label-in-frame (frame-label label-text &rest args)
507 (make-instance 'frame
509 :child (apply #'make-instance 'label :label label-text :xpad 5 :ypad 5 args))
510 :fill nil :expand nil)))
511 (make-instance 'h-box
512 :spacing 5 :parent window
513 :child-args '(:fill nil :expand nil)
514 :child (make-instance 'v-box
516 :child (create-label-in-frame "Normal Label" "This is a Normal label")
517 :child (create-label-in-frame "Multi-line Label"
518 "This is a Multi-line label.
521 :child (create-label-in-frame "Left Justified Label"
522 "This is a Left-Justified
526 :child (create-label-in-frame "Right Justified Label"
527 "This is a Right-Justified
531 :child (make-instance 'v-box
533 :child (create-label-in-frame "Line wrapped label"
534 "This is an example of a line-wrapped label. It should not be taking up the entire width allocated to it, but automatically wraps the words to fit. The time has come, for all good men, to come to the aid of their party. The sixth sheik's six sheep's sick.
535 It supports multiple paragraphs correctly, and correctly adds many extra spaces. "
538 :child (create-label-in-frame "Filled, wrapped label"
539 "This is an example of a line-wrapped, filled label. It should be taking up the entire width allocated to it. Here is a seneance to prove my point. Here is another sentence. Here comes the sun, do de do de do.
540 This is a new paragraph.
541 This is another newer, longer, better paragraph. It is coming to an end, unfortunately."
542 :justify :fill :wrap t)
544 :child (create-label-in-frame "Underlined label"
545 "This label is underlined!
546 This one is underlined (こんにちは) in quite a funky fashion"
548 :pattern "_________________________ _ _________ _ _____ _ __ __ ___ ____ _____")))))
553 (defun layout-expose (layout event)
554 (when (eq (gdk:event-window event) (layout-bin-window layout))
555 (with-slots (gdk:x gdk:y gdk:width gdk:height) event
556 (let ((imin (truncate gdk:x 10))
557 (imax (truncate (+ gdk:x gdk:width 9) 10))
558 (jmin (truncate gdk:y 10))
559 (jmax (truncate (+ gdk:y gdk:height 9) 10)))
561 (let ((window (layout-bin-window layout))
562 (gc (style-black-gc (widget-style layout))))
564 for i from imin below imax
566 for j from jmin below jmax
567 unless (zerop (mod (+ i j) 2))
568 do (gdk:draw-rectangle
569 window gc t (* 10 i) (* 10 j)
570 (1+ (mod i 10)) (1+ (mod j 10)))))))))
573 (define-toplevel create-layout (window "Layout" :default-width 200
575 (let ((layout (make-instance 'layout
576 :parent (make-instance 'scrolled-window :parent window)
577 :width 1600 :height 128000 :events '(:exposure)
578 :signal (list 'expose-event #'layout-expose :object t))))
580 (with-slots (hadjustment vadjustment) layout
582 (adjustment-step-increment hadjustment) 10.0
583 (adjustment-step-increment vadjustment) 10.0))
587 (let ((text (format nil "Button ~D, ~D" i j)))
589 (make-instance (if (not (zerop (mod (+ i j) 2)))
592 :label text :visible t)
593 (* j 100) (* i 100)))))
596 for i from 16 below 1280
597 do (let ((text (format nil "Button ~D, ~D" i 0)))
599 (make-instance (if (not (zerop (mod i 2)))
602 :label text :visible t)
609 (define-simple-dialog create-list (dialog "List" :default-height 400)
610 (let* ((store (make-instance 'list-store
611 :column-types '(string int boolean)
612 :column-names '(:foo :bar :baz)
613 :initial-content '(#("First" 12321 nil)
614 (:foo "Yeah" :baz t))))
615 (tree (make-instance 'tree-view :model store)))
618 with iter = (make-instance 'tree-iter)
620 do (list-store-append store (vector "Test" i (zerop (mod i 3))) iter))
622 (let ((column (make-instance 'tree-view-column :title "Column 1"))
623 (cell (make-instance 'cell-renderer-text)))
624 (cell-layout-pack column cell :expand t)
625 (cell-layout-add-attribute column cell 'text (column-index store :foo))
626 (tree-view-append-column tree column))
628 (let ((column (make-instance 'tree-view-column :title "Column 2"))
629 (cell (make-instance 'cell-renderer-text :background "orange")))
630 (cell-layout-pack column cell :expand t)
631 (cell-layout-add-attribute column cell 'text (column-index store :bar))
632 (tree-view-append-column tree column))
634 (let ((column (make-instance 'tree-view-column :title "Column 3"))
635 (cell (make-instance 'cell-renderer-text)))
636 (cell-layout-pack column cell :expand t)
637 (cell-layout-add-attribute column cell 'text (column-index store :baz))
638 (tree-view-append-column tree column))
640 (make-instance 'v-box
641 :parent dialog :border-width 10 :spacing 10
643 (make-instance 'h-box
645 :child (make-instance 'button
646 :label "Remove Selection"
647 :signal (list 'clicked
652 (make-instance 'tree-row-reference :model store :path path))
653 (tree-selection-get-selected-rows
654 (tree-view-selection tree)))))
656 #'(lambda (reference)
657 (list-store-remove store reference))
661 (make-instance 'h-box
663 :child (make-instance 'check-button
664 :label "Show Headers" :active t
665 :signal (list 'toggled
668 (tree-view-headers-visible-p tree)
669 (toggle-button-active-p button)))
671 :child (make-instance 'check-button
672 :label "Reorderable" :active nil
673 :signal (list 'toggled
676 (tree-view-reorderable-p tree)
677 (toggle-button-active-p button)))
680 (make-instance 'h-box
681 :child (make-instance 'label :label "Selection Mode: ")
682 :child (make-instance 'combo-box
683 :content '("Single" "Browse" "Multiple")
685 :signal (list 'changed
686 #'(lambda (combo-box)
689 (tree-view-selection tree))
691 #(:single :browse :multiple)
692 (combo-box-active combo-box))))
696 :child (make-instance 'scrolled-window
697 :child tree :hscrollbar-policy :automatic))))
702 (defun create-menu (depth tearoff)
703 (unless (zerop depth)
704 (let ((menu (make-instance 'menu)))
706 (let ((menu-item (make-instance 'tearoff-menu-item)))
707 (menu-shell-append menu menu-item)))
711 (make-instance 'radio-menu-item
712 :label (format nil "item ~2D - ~D" depth (1+ i)))))
714 (add-to-radio-group menu-item group)
715 (setq group menu-item))
716 (unless (zerop (mod depth 2))
717 (setf (check-menu-item-active-p menu-item) t))
718 (menu-shell-append menu menu-item)
720 (setf (widget-sensitive-p menu-item) nil))
721 (let ((submenu (create-menu (1- depth) t)))
723 (setf (menu-item-submenu menu-item) submenu))))))
727 (define-simple-dialog create-menus (dialog "Menus" :default-width 200)
728 (let* ((main (make-instance 'v-box :parent dialog))
729 ; (accel-group (make-instance 'accel-group))
730 (menubar (make-instance 'menu-bar :parent (list main :expand nil))))
731 ; (window-add-accel-group dialog accel-group)
733 (let ((menu-item (make-instance 'menu-item
734 :label (format nil "test~%line2"))))
735 (setf (menu-item-submenu menu-item) (create-menu 2 t))
736 (menu-shell-append menubar menu-item))
738 (let ((menu-item (make-instance 'menu-item :label "foo")))
739 (setf (menu-item-submenu menu-item) (create-menu 3 t))
740 (menu-shell-append menubar menu-item))
742 (let ((menu-item (make-instance 'menu-item :label "bar")))
743 (setf (menu-item-submenu menu-item) (create-menu 4 t))
744 (setf (menu-item-right-justified-p menu-item) t)
745 (menu-shell-append menubar menu-item))
747 (make-instance 'v-box
748 :spacing 10 :border-width 10 :parent main
749 :child (make-instance 'combo-box
753 collect (format nil "Item ~D" i))))
755 (widget-show-all main)))
760 (defun create-notebook-page (notebook page-num book-closed)
761 (let* ((title (format nil "Page ~D" page-num))
762 (page (make-instance 'frame :label title :border-width 10))
763 (v-box (make-instance 'v-box
764 :homogeneous t :border-width 10 :parent page)))
766 (make-instance 'h-box
767 :parent (list v-box :fill nil :padding 5) :homogeneous t
768 :child-args '(:padding 5)
769 :child (make-instance 'check-button
770 :label "Fill Tab" :active t
771 :signal (list 'toggled
774 (notebook-child-tab-fill-p page)
775 (toggle-button-active-p button)))
777 :child (make-instance 'check-button
779 :signal (list 'toggled
782 (notebook-child-tab-expand-p page)
783 (toggle-button-active-p button)))
785 :child (make-instance 'check-button
787 :signal (list 'toggled
790 (notebook-child-tab-pack page)
791 (if (toggle-button-active-p button)
795 :child (make-instance 'button
797 :signal (list 'clicked #'(lambda () (widget-hide page)))))
799 (let ((label-box (make-instance 'h-box
801 :child-args '(:expand nil)
802 :child (make-instance 'image :pixbuf book-closed)
803 :child (make-instance 'label :label title)))
804 (menu-box (make-instance 'h-box
806 :child-args '(:expand nil)
807 :child (make-instance 'image :pixbuf book-closed)
808 :child (make-instance 'label :label title))))
810 (widget-show-all page)
811 (notebook-append notebook page label-box menu-box))))
814 (define-simple-dialog create-notebook (dialog "Notebook")
815 (let ((main (make-instance 'v-box :parent dialog)))
816 (let ((book-open (gdk:pixbuf-new-from-xpm-data book-open-xpm))
817 (book-closed (gdk:pixbuf-new-from-xpm-data book-closed-xpm))
818 (notebook (make-instance 'notebook
819 :border-width 10 :tab-pos :top :parent main)))
820 (flet ((set-image (page func pixbuf)
823 (first (container-children (funcall func notebook page))))
825 (signal-connect notebook 'switch-page
826 #'(lambda (pointer page)
827 (declare (ignore pointer))
828 (set-image page #'notebook-menu-label book-open)
829 (set-image page #'notebook-tab-label book-open)
830 (when (slot-boundp notebook 'current-page)
831 (let ((curpage (notebook-current-page notebook)))
832 (set-image curpage #'notebook-menu-label book-closed)
833 (set-image curpage #'notebook-tab-label book-closed))))))
834 (loop for i from 1 to 5 do (create-notebook-page notebook i book-closed))
836 (make-instance 'h-separator :parent (list main :expand nil :padding 10))
838 (make-instance 'h-box
839 :spacing 5 :border-width 10
840 :parent (list main :expand nil)
841 :child-args '(:fill nil)
842 :child (make-instance 'check-button
844 :signal (list 'clicked
846 (if (toggle-button-active-p button)
847 (notebook-popup-enable notebook)
848 (notebook-popup-disable notebook)))
850 :child (make-instance 'check-button
851 :label "Homogeneous tabs"
852 :signal (list 'clicked
855 (notebook-homogeneous-p notebook)
856 (toggle-button-active-p button)))
859 (make-instance 'h-box
860 :spacing 5 :border-width 10
861 :parent (list main :expand nil)
862 :child-args '(:expand nil)
863 :child (make-instance 'label :label "Notebook Style: ")
864 :child (let ((scrollable-p nil))
865 (make-instance 'combo-box
866 :content '("Standard" "No tabs" "Scrollable") :active 0
867 :signal (list 'changed
868 #'(lambda (combo-box)
869 (case (combo-box-active combo-box)
871 (setf (notebook-show-tabs-p notebook) t)
873 (setq scrollable-p nil)
874 (setf (notebook-scrollable-p notebook) nil)
876 do (notebook-remove-page notebook 5))))
878 (setf (notebook-show-tabs-p notebook) nil)
880 (setq scrollable-p nil)
881 (setf (notebook-scrollable-p notebook) nil)
883 do (notebook-remove-page notebook 5))))
886 (setq scrollable-p t)
887 (setf (notebook-show-tabs-p notebook) t)
888 (setf (notebook-scrollable-p notebook) t)
889 (loop for i from 6 to 15
890 do (create-notebook-page notebook i book-closed))))))
892 :child (make-instance 'button
893 :label "Show all Pages"
894 :signal (list 'clicked
896 (map-container nil #'widget-show notebook)))))
898 (make-instance 'h-box
899 :spacing 5 :border-width 10
900 :parent (list main :expand nil)
901 :child (make-instance 'button
903 :signal (list 'clicked #'notebook-prev-page :object notebook))
904 :child (make-instance 'button
906 :signal (list 'clicked #'notebook-next-page :object notebook))
907 :child (make-instance 'button
909 :signal (let ((tab-pos 0))
912 (setq tab-pos (mod (1+ tab-pos) 4))
914 (notebook-tab-pos notebook)
915 (svref #(:top :right :bottom :left) tab-pos))))))))
916 (widget-show-all main)))
921 (defun toggle-resize (child)
922 (setf (paned-child-resize-p child) (not (paned-child-resize-p child))))
924 (defun toggle-shrink (child)
925 (setf (paned-child-shrink-p child) (not (paned-child-shrink-p child))))
927 (defun create-pane-options (paned frame-label label1 label2)
928 (let* ((table (make-instance 'table :n-rows 3 :n-columns 2 :homogeneous t)))
929 (table-attach table (create-label label1) 0 1 0 1 :options '(:expand :fill))
930 (let ((check-button (make-instance 'check-button :label "Resize")))
931 (table-attach table check-button 0 1 1 2 :options '(:expand :fill))
932 (signal-connect check-button 'toggled
933 #'toggle-resize :object (paned-child1 paned)))
934 (let ((check-button (make-instance 'check-button :label "Shrink" :active t)))
935 (table-attach table check-button 0 1 2 3 :options '(:expand :fill))
936 (signal-connect check-button 'toggled
937 #'toggle-shrink :object (paned-child1 paned)))
939 (table-attach table (create-label label2) 1 2 0 1 :options '(:expand :fill))
940 (let ((check-button (make-instance 'check-button :label "Resize" :active t)))
941 (table-attach table check-button 1 2 1 2 :options '(:expand :fill))
942 (signal-connect check-button 'toggled
943 #'toggle-resize :object (paned-child2 paned)))
944 (let ((check-button (make-instance 'check-button :label "Shrink" :active t)))
945 (table-attach table check-button 1 2 2 3 :options '(:expand :fill))
946 (signal-connect check-button 'toggled
947 #'toggle-shrink :object (paned-child2 paned)))
948 (make-instance 'frame :label frame-label :border-width 4 :child table)))
950 (define-toplevel create-panes (window "Panes")
951 (let* ((hpaned (make-instance 'h-paned
952 :child1 (make-instance 'frame
953 :width-request 60 :height-request 60
955 :child (make-instance 'button :label "Hi there"))
956 :child2 (make-instance 'frame
957 :width-request 80 :height-request 60
959 (vpaned (make-instance 'v-paned
962 :child2 (make-instance 'frame
963 :width-request 80 :height-request 60
966 (make-instance 'v-box
968 :child-args '(:expand nil)
969 :child (list vpaned :expand t)
970 :child (create-pane-options hpaned "Horizontal" "Left" "Right")
971 :child (create-pane-options vpaned "Vertical" "Top" "Bottom"))))
976 (define-simple-dialog create-progress-bar (dialog "Progress Bar")
977 (let* ((progress (make-instance 'progress-bar :pulse-step 0.05))
978 (activity-mode-button (make-instance 'check-button
979 :label "Activity mode"))
980 (timer (timeout-add 100
982 (if (toggle-button-active-p activity-mode-button)
983 (progress-bar-pulse progress)
984 (let ((fract (+ (progress-bar-fraction progress) 0.01)))
986 (progress-bar-fraction progress)
992 (make-instance 'v-box
993 :parent dialog :border-width 10 :spacing 10
995 :child activity-mode-button)
997 (signal-connect dialog 'destroy
998 #'(lambda () (when timer (timeout-remove timer))))))
1003 (define-simple-dialog create-radio-buttons (dialog "Radio buttons")
1004 (make-instance 'v-box
1005 :parent dialog :border-width 10 :spacing 10
1006 :children (make-radio-group 'radio-button
1007 '((:label "button1") (:label "button2") (:label "button3"))
1013 (define-simple-dialog create-range-controls (dialog "Range controls")
1014 (let ((adjustment (adjustment-new 0.0 0.0 101.0 0.1 1.0 1.0)))
1015 (make-instance 'v-box
1016 :parent dialog :border-width 10 :spacing 10
1017 :child (make-instance 'h-scale
1018 :width-request 150 :adjustment adjustment :inverted t
1019 :update-policy :delayed :digits 1 :draw-value t)
1020 :child (make-instance 'h-scrollbar
1021 :adjustment adjustment :update-policy :continuous))))
1026 (define-simple-dialog create-reparent (dialog "Reparent")
1027 (let ((main (make-instance 'h-box
1028 :homogeneous t :spacing 10 :border-width 10 :parent dialog))
1029 (label (make-instance 'label :label "Hello World")))
1031 (flet ((create-frame (title)
1032 (let* ((frame (make-instance 'frame :label title :parent main))
1033 (box (make-instance 'v-box
1034 :spacing 5 :border-width 5 :parent frame))
1035 (button (make-instance 'button
1036 :label "switch" :parent (list box :expand nil))))
1037 (signal-connect button 'clicked
1039 (widget-reparent label box)))
1042 (box-pack-start (create-frame "Frame 1") label nil t 0)
1043 (create-frame "Frame 2"))
1044 (widget-show-all main)))
1049 (define-toplevel create-rulers (window "Rulers"
1050 :default-width 300 :default-height 300
1051 :events '(:pointer-motion :pointer-motion-hint))
1052 (let ((table (make-instance 'table :n-rows 2 :n-columns 2 :parent window))
1053 (h-ruler (make-instance 'h-ruler
1054 :metric :centimeters :lower 100.0d0 :upper 0.0d0
1055 :position 0.0d0 :max-size 20.0d0))
1056 (v-ruler (make-instance 'v-ruler
1057 :lower 5.0d0 :upper 15.0d0
1058 :position 0.0d0 :max-size 20.0d0)))
1059 (signal-connect window 'motion-notify-event
1061 (widget-event h-ruler event)
1062 (widget-event v-ruler event)))
1063 (table-attach table h-ruler 1 2 0 1 :options :fill :x-options :expand)
1064 (table-attach table v-ruler 0 1 1 2 :options :fill :y-options :expand)))
1069 (define-simple-dialog create-scrolled-windows (dialog "Scrolled windows"
1071 :default-height 300)
1072 (let* ((scrolled-window
1073 (make-instance 'scrolled-window
1074 :parent dialog :border-width 10
1075 :vscrollbar-policy :automatic
1076 :hscrollbar-policy :automatic))
1078 (make-instance 'table
1079 :n-rows 20 :n-columns 20 :row-spacing 10 :column-spacing 10
1080 :focus-vadjustment (scrolled-window-vadjustment scrolled-window)
1081 :focus-hadjustment (scrolled-window-hadjustment scrolled-window))))
1083 (scrolled-window-add-with-viewport scrolled-window table)
1087 (make-instance 'toggle-button
1088 :label (format nil "button (~D,~D)~%" i j))))
1089 (table-attach table button i (1+ i) j (1+ j)))))
1090 (widget-show-all scrolled-window)))
1095 (define-simple-dialog create-size-group (dialog "Size Group" :resizable nil)
1096 (let ((size-group (make-instance 'size-group)))
1097 (flet ((create-frame (label rows)
1098 (let ((table (make-instance 'table
1099 :n-rows (length rows) :n-columns 2 :homogeneous nil
1100 :row-spacing 5 :column-spacing 10 :border-width 5)))
1104 do (table-attach table
1105 (create-label (first row) :xalign 0 :yalign 1)
1106 0 1 i (1+ i) :x-options '(:expand :fill))
1107 (let ((combo (make-instance 'combo-box
1108 :content (rest row) :active 0)))
1109 (size-group-add-widget size-group combo)
1110 (table-attach table combo 1 2 i (1+ i))))
1111 (make-instance 'frame :label label :child table))))
1113 (make-instance 'v-box
1114 :parent dialog :border-width 5 :spacing 5
1115 :child (create-frame "Color Options"
1116 '(("Foreground" "Red" "Green" "Blue")
1117 ("Background" "Red" "Green" "Blue")))
1118 :child (create-frame "Line Options"
1119 '(("Dashing" "Solid" "Dashed" "Dotted")
1120 ("Line ends" "Square" "Round" "Arrow")))
1121 :child (create-check-button "Enable grouping"
1124 (size-group-mode size-group)
1125 (if active :horizontal :none)))
1131 (defun create-shape-icon (xpm-file x y px py type root-window destroy)
1133 (make-instance 'window
1134 :type type :default-width 100 :default-height 100
1135 :events '(:button-motion :pointer-motion-hint :button-press)
1136 :signal (list 'destroy destroy))))
1138 (widget-realize window)
1139 (multiple-value-bind (source mask) (gdk:pixmap-create xpm-file)
1140 (let ((fixed (make-instance 'fixed :parent window)))
1141 (fixed-put fixed (create-image-widget source mask) px py))
1142 (widget-shape-combine-mask window mask px py))
1146 (declare (fixnum x-offset y-offset))
1147 (signal-connect window 'button-press-event
1149 (when (typep event 'gdk:button-press-event)
1150 (setq x-offset (truncate (gdk:event-x event)))
1151 (setq y-offset (truncate (gdk:event-y event)))
1153 (gdk:pointer-grab (widget-window window)
1154 :events '(:button-release :button-motion :pointer-motion-hint)
1155 :owner-events t :time event))))
1157 (signal-connect window 'button-release-event
1159 (grab-remove window)
1160 (gdk:pointer-ungrab event)))
1162 (signal-connect window 'motion-notify-event
1164 (declare (ignore event))
1165 (multiple-value-bind (win xp yp mask)
1166 (gdk:window-get-pointer root-window)
1167 (declare (ignore mask win) (fixnum xp yp))
1168 (window-move window (- xp x-offset) (- yp y-offset))))))
1170 (window-move window x y)
1171 (widget-show-all window)
1175 (let ((modeller nil)
1178 (defun create-shapes ()
1179 (let ((root-window (gdk:get-root-window)))
1184 "clg:examples;Modeller.xpm" 440 140 0 0 :popup root-window
1185 #'(lambda () (setq modeller nil))))
1186 (widget-destroy modeller))
1192 "clg:examples;FilesQueue.xpm" 580 170 0 0 :popup root-window
1193 #'(lambda () (setq sheets nil))))
1194 (widget-destroy sheets))
1200 "clg:examples;3DRings.xpm" 460 270 25 25 :toplevel root-window
1201 #'(lambda () (setq rings nil))))
1202 (widget-destroy rings)))))
1208 (define-simple-dialog create-spins (dialog "Spin buttons" :has-separator nil)
1209 (let ((main (make-instance 'v-box
1210 :spacing 5 :border-width 10 :parent dialog)))
1212 (flet ((create-date-spinner (label adjustment shadow-type)
1213 (declare (ignore shadow-type))
1214 (make-instance 'v-box
1215 :child-args '(:expand nil)
1216 :child (make-instance 'label
1217 :label label :xalign 0.0 :yalign 0.5)
1218 :child (make-instance 'spin-button
1219 :adjustment adjustment :wrap t))))
1220 (make-instance 'frame
1221 :label "Not accelerated" :parent main
1222 :child (make-instance 'h-box
1224 :child-args '(:padding 5)
1225 :child (create-date-spinner "Day : "
1226 (adjustment-new 1.0 1.0 31.0 1.0 5.0 0.0) :out)
1227 :child (create-date-spinner "Month : "
1228 (adjustment-new 1.0 1.0 12.0 1.0 5.0 0.0) :etched-in)
1229 :child (create-date-spinner "Year : "
1230 (adjustment-new 1998.0 0.0 2100.0 1.0 100.0 0.0) :in))))
1232 (let ((spinner1 (make-instance 'spin-button
1233 :adjustment (adjustment-new 0.0 -10000.0 10000.0 0.5 100.0 0.0)
1234 :climb-rate 1.0 :digits 2 :wrap t :width-request 100))
1235 (spinner2 (make-instance 'spin-button
1236 :adjustment (adjustment-new 2.0 1.0 5.0 1.0 1.0 0.0)
1237 :climb-rate 1.0 :wrap t))
1238 (value-label (make-instance 'label :label "0")))
1239 (signal-connect (spin-button-adjustment spinner2) 'value-changed
1242 (spin-button-digits spinner1)
1243 (floor (spin-button-value spinner2)))))
1245 (make-instance 'frame
1246 :label "Accelerated" :parent main
1247 :child (make-instance 'v-box
1250 (make-instance 'h-box
1251 :child-args '(:padding 5)
1252 :child (make-instance 'v-box
1253 :child (make-instance 'label
1255 :xalign 0.0 :yalign 0.5)
1257 :child (make-instance 'v-box
1258 :child (make-instance 'label
1260 :xalign 0.0 :yalign 0.5)
1262 :expand nil :padding 5)
1263 :child (make-instance 'check-button
1264 :label "Snap to 0.5-ticks" :active t
1265 :signal (list 'clicked
1268 (spin-button-snap-to-ticks-p spinner1)
1269 (toggle-button-active-p button)))
1271 :child (make-instance 'check-button
1272 :label "Numeric only input mode" :active t
1273 :signal (list 'clicked
1276 (spin-button-numeric-p spinner1)
1277 (toggle-button-active-p button)))
1281 (make-instance 'h-box
1282 :child-args '(:padding 5)
1283 :child (make-instance 'button
1284 :label "Value as Int"
1285 :signal (list 'clicked
1288 (label-label value-label)
1290 (spin-button-value-as-int
1292 :child (make-instance 'button
1293 :label "Value as Float"
1294 :signal (list 'clicked
1297 (label-label value-label)
1299 (format nil "~~,~DF"
1300 (spin-button-digits spinner1))
1301 (spin-button-value spinner1)))))))
1302 :padding 5 :expand nil))))
1303 (widget-show-all main)))
1308 (define-toplevel create-statusbar (window "Statusbar")
1309 (let ((statusbar (make-instance 'statusbar :has-resize-grip t))
1310 (close-button (create-button '("close" :can-default t)
1311 #'widget-destroy :object window))
1314 (signal-connect statusbar 'text-popped
1315 #'(lambda (context-id text)
1316 (declare (ignore context-id))
1317 (format nil "Popped: ~A~%" text)))
1319 (make-instance 'v-box
1321 :child (make-instance 'v-box
1322 :border-width 10 :spacing 10
1323 :child (create-button "push something"
1325 (statusbar-push statusbar 1
1326 (format nil "something ~D" (incf counter)))))
1327 :child (create-button "pop"
1329 (statusbar-pop statusbar 1)))
1330 :child (create-button "steal #4"
1332 (statusbar-remove statusbar 1 4)))
1333 :child (create-button "dump stack")
1334 :child (create-button "test contexts"))
1335 :child (list (make-instance 'h-separator) :expand nil)
1337 (make-instance 'v-box :border-width 10 :child close-button)
1339 :child (list statusbar :expand nil))
1341 (widget-grab-focus close-button)))
1346 (define-simple-dialog create-idle-test (dialog "Idle Test")
1347 (let ((label (make-instance 'label
1348 :label "count: 0" :xpad 10 :ypad 10))
1351 (signal-connect dialog 'destroy
1352 #'(lambda () (when idle (idle-remove idle))))
1354 (make-instance 'v-box
1355 :parent dialog :border-width 10 :spacing 10
1357 :child (make-instance 'frame
1358 :label "Label Container" :border-width 5
1359 :child(make-instance 'v-box
1360 :children (make-radio-group 'radio-button
1361 '((:label "Resize-Parent" :value :parent :active t)
1362 (:label "Resize-Queue" :value :queue)
1363 (:label "Resize-Immediate" :value :immediate))
1366 (container-resize-mode (dialog-action-area dialog)) mode))))))
1368 (dialog-add-button dialog "Start"
1375 (setf (label-label label) (format nil "count: ~D" count))
1378 (dialog-add-button dialog "Stop"
1382 (setq idle nil))))))
1388 (define-simple-dialog create-timeout-test (dialog "Timeout Test")
1389 (let ((label (make-instance 'label
1390 :label "count: 0" :xpad 10 :ypad 10 :parent dialog :visible t))
1393 (signal-connect dialog 'destroy
1394 #'(lambda () (when timer (timeout-remove timer))))
1396 (dialog-add-button dialog "Start"
1403 (setf (label-label label) (format nil "count: ~D" count))
1406 (dialog-add-button dialog "Stop"
1409 (timeout-remove timer)
1410 (setq timer nil))))))
1415 (define-simple-dialog create-text (dialog "Text" :default-width 400
1416 :default-height 400)
1417 (let* ((text-view (make-instance 'text-view
1418 :border-width 10 :visible t :wrap-mode :word))
1419 (buffer (text-view-buffer text-view))
1422 (text-buffer-create-tag buffer "Bold" :weight :bold)
1423 (text-buffer-create-tag buffer "Italic" :style :italic)
1424 (text-buffer-create-tag buffer "Underline" :underline :single)
1426 (flet ((create-toggle-callback (tag-name)
1427 (let ((tag (text-tag-table-lookup
1428 (text-buffer-tag-table buffer) tag-name)))
1430 (unless (eq (and (find tag active-tags) t) active)
1433 (push tag active-tags)
1434 (setq active-tags (delete tag active-tags)))
1435 (multiple-value-bind (non-zero-p start end)
1436 (text-buffer-get-selection-bounds buffer)
1437 (declare (ignore non-zero-p))
1439 (text-buffer-apply-tag buffer tag start end)
1440 (text-buffer-remove-tag buffer tag start end))))))))
1443 (make-instance 'action-group
1444 :action (create-toggle-action
1445 "Bold" "gtk-bold" "Bold" "<control>B" "Bold" nil
1446 (create-toggle-callback "Bold"))
1447 :action (create-toggle-action
1448 "Italic" "gtk-italic" "Italic" "<control>I" "Italic" nil
1449 (create-toggle-callback "Italic"))
1450 :action (create-toggle-action
1451 "Underline" "gtk-underline" "Underline" "<control>U" "Underline" nil
1452 (create-toggle-callback "Underline"))))
1453 (ui (make-instance 'ui-manager)))
1455 (ui-manager-insert-action-group ui actions)
1456 (ui-manager-add-ui ui
1457 '((:toolbar "ToolBar"
1459 (:toolitem "Italic")
1460 (:toolitem "Underline"))))
1462 ;; Callback to activate/deactivate toolbar buttons when cursor
1464 (signal-connect buffer 'mark-set
1465 #'(lambda (location mark)
1466 (declare (ignore mark))
1467 (text-tag-table-foreach (text-buffer-tag-table buffer)
1472 (text-iter-has-tag-p location tag)
1473 (not (text-iter-begins-tag-p location tag)))
1474 (text-iter-ends-tag-p location tag))))
1475 (unless (eq active (and (find tag active-tags) t))
1477 (push tag active-tags)
1478 (setq active-tags (delete tag active-tags)))
1480 (toggle-action-active-p
1481 (action-group-get-action actions (text-tag-name tag)))
1484 ;; Callback to apply active tags when a character is inserted
1485 (signal-connect buffer 'insert-text
1486 #'(lambda (iter &rest args)
1487 (declare (ignore args))
1488 (let ((before (text-buffer-get-iter-at-offset buffer
1489 (1- (text-iter-offset iter)))))
1491 for tag in active-tags
1492 do (text-buffer-apply-tag buffer tag before iter))))
1495 (container-add dialog (ui-manager-get-widget ui "/ToolBar") :expand nil)
1496 (container-add dialog text-view)))))
1501 (define-simple-dialog create-toggle-buttons (dialog "Toggle Button")
1502 (make-instance 'v-box
1503 :border-width 10 :spacing 10 :parent dialog
1506 collect (make-instance 'toggle-button
1507 :label (format nil "Button~D" (1+ n))))))
1513 (defun create-toolbar (window)
1514 (make-instance 'toolbar
1515 :show-tooltips t :show-arrow nil
1517 ;; Insert a stock item
1518 :child (make-instance 'tool-button
1520 :tip-text "Destroy toolbar"
1521 :tip-private "Toolbar/Quit"
1522 :signal (list 'clicked #'(lambda () (widget-destroy window))))
1524 :child (make-instance 'separator-tool-item)
1526 :child (make-instance 'tool-button
1527 :label "Horizontal" :stock "gtk-go-forward"
1528 :tip-text "Horizontal toolbar layout"
1529 :tip-private "Toolbar/Horizontal"
1530 :signal (list 'clicked
1532 (setf (toolbar-orientation toolbar) :horizontal))
1535 :child (make-instance 'tool-button
1536 :label "Vertical" :stock "gtk-go-down"
1537 :tip-text "Vertical toolbar layout"
1538 :tip-private "Toolbar/Vertical"
1539 :signal (list 'clicked
1541 (setf (toolbar-orientation toolbar) :vertical))
1544 :child (make-instance 'separator-tool-item)
1546 :children (make-radio-group 'radio-tool-button
1547 '((:label "Icons" :stock "gtk-justify-left"
1548 :tip-text "Only show toolbar icons"
1549 :tip-private "Toolbar/IconsOnly"
1551 (:label "Both" :stock "gtk-justify-center"
1552 :tip-text "Show toolbar icons and text"
1553 :tip-private "Toolbar/Both"
1554 :value :both :active t)
1555 (:label "Text" :stock "gtk-justify-right"
1556 :tip-text "Show toolbar text"
1557 :tip-private "Toolbar/TextOnly"
1560 #'(lambda (toolbar style)
1561 (setf (toolbar-style toolbar) style))
1564 :child (make-instance 'separator-tool-item)
1566 :child (make-instance 'tool-item
1567 :child (make-instance 'entry)
1568 :tip-text "This is an unusable GtkEntry"
1569 :tip-private "Hey don't click me!")
1571 :child (make-instance 'separator-tool-item)
1573 :child (make-instance 'tool-button
1574 :label "Enable" :stock "gtk-add"
1575 :tip-text "Enable tooltips"
1576 :tip-private "Toolbar/EnableTooltips"
1577 :signal (list 'clicked
1579 (setf (toolbar-show-tooltips-p toolbar) t))
1582 :child (make-instance 'tool-button
1583 :label "Disable" :stock "gtk-remove"
1584 :tip-text "Disable tooltips"
1585 :tip-private "Toolbar/DisableTooltips"
1586 :signal (list 'clicked
1588 (setf (toolbar-show-tooltips-p toolbar) nil))
1591 ;; :child (make-instance 'separator-tool-item)
1593 ;; :child (make-instance 'tool-button
1594 ;; :label "GTK" :icon #p"clg:examples;gtk.png"
1595 ;; :tip-text "GTK+ Logo"
1596 ;; :tip-private "Toolbar/GTK+")
1599 (define-toplevel create-toolbar-window (window "Toolbar test" :resizable nil)
1600 (container-add window (create-toolbar window)))
1606 (define-simple-dialog create-tooltips (dialog "Tooltips" :default-width 200)
1607 (let ((tooltips (make-instance 'tooltips)))
1608 (flet ((create-button (label tip-text tip-private)
1609 (let ((button (make-instance 'toggle-button :label label)))
1610 (tooltips-set-tip tooltips button tip-text tip-private)
1612 (make-instance 'v-box
1613 :parent dialog :border-width 10 :spacing 10
1614 :child (create-button "button1" "This is button 1" "ContextHelp/button/1")
1615 :child (create-button "button2" "This is button 2. This is also has a really long tooltip which probably won't fit on a single line and will therefore need to be wrapped. Hopefully the wrapping will work correctly." "ContextHelp/button/2")))))
1620 (defvar *ui-description*
1621 '((:menubar "MenuBar"
1626 (:menuitem "SaveAs")
1629 (:menu "PreferencesMenu"
1635 (:menuitem "Square")
1636 (:menuitem "Rectangle")
1640 (:menuitem "About")))
1645 (:toolitem "Logo"))))
1647 (define-toplevel create-ui-manager (window "UI Manager")
1649 (make-instance 'action-group
1651 :action (create-action "FileMenu" nil "_File")
1652 :action (create-action "PreferencesMenu" nil "_Preferences")
1653 :action (create-action "ColorMenu" nil "_Color")
1654 :action (create-action "ShapeMenu" nil "_Shape")
1655 :action (create-action "HelpMenu" nil "_Help")
1656 :action (create-action "New" "gtk-new" "_New" "<control>N" "Create a new file")
1657 :action (create-action "Open" "gtk-open" "_Open" "<control>O" "Open a file" #'create-file-chooser)
1658 :action (create-action "Save" "gtk-save" "_Save" "<control>S" "Save current file")
1659 :action (create-action "SaveAs" "gtk-save" "Save _As..." "" "Save to a file")
1660 :action (create-action "Quit" "gtk-quit" "_Quit" "<control>Q" "Quit" (list #'widget-destroy :object window))
1661 :action (create-action "About" nil "_About" "<control>A" "About")
1662 :action (create-action "Logo" "demo-gtk-logo" "" nil "GTK+")
1663 :action (create-toggle-action "Bold" "gtk-bold" "_Bold" "<control>B" "Bold" t)
1664 :actions (create-radio-actions
1665 '(("Red" nil "_Red" "<control>R" "Blood")
1666 ("Green" nil "_Green" "<control>G" "Grass")
1667 ("Blue" nil "_Blue" "<control>B" "Sky"))
1669 :actions (create-radio-actions
1670 '(("Square" nil "_Square" "<control>S" "Square")
1671 ("Rectangle" nil "_Rectangle" "<control>R" "Rectangle")
1672 ("Oval" nil "_Oval" "<control>O" "Egg")))))
1673 (ui (make-instance 'ui-manager)))
1675 (ui-manager-insert-action-group ui actions)
1676 (ui-manager-add-ui ui *ui-description*)
1678 (window-add-accel-group window (ui-manager-accel-group ui))
1680 (make-instance 'v-box
1683 (ui-manager-get-widget ui "/MenuBar")
1684 :expand nil :fill nil)
1686 (ui-manager-get-widget ui "/ToolBar")
1687 :expand nil :fill nil)
1688 :child (make-instance 'label
1689 :label "Type <alt> to start"
1690 :xalign 0.5 :yalign 0.5
1691 :width-request 200 :height-request 200))))
1697 (defun create-main-window ()
1698 ;; (rc-parse "clg:examples;testgtkrc2")
1699 ;; (rc-parse "clg:examples;testgtkrc")
1701 (let* ((button-specs
1702 '(("button box" create-button-box)
1703 ("buttons" create-buttons)
1704 ("calendar" create-calendar)
1705 ("check buttons" create-check-buttons)
1706 ("color selection" create-color-selection)
1707 ("cursors" create-cursors)
1708 ("dialog" create-dialog)
1710 ("entry" create-entry)
1711 ;; ("event watcher")
1712 ("enxpander" create-expander)
1713 ("file chooser" create-file-chooser)
1714 ("font selection" create-font-selection)
1715 ("handle box" create-handle-box)
1716 ("image" create-image)
1717 ("labels" create-labels)
1718 ("layout" create-layout)
1719 ("list" create-list)
1720 ("menus" create-menus)
1722 ("notebook" create-notebook)
1723 ("panes" create-panes)
1724 ("progress bar" create-progress-bar)
1725 ("radio buttons" create-radio-buttons)
1726 ("range controls" create-range-controls)
1728 ("reparent" create-reparent)
1729 ("rulers" create-rulers)
1730 ;; ("saved position")
1731 ("scrolled windows" create-scrolled-windows)
1732 ("size group" create-size-group)
1733 ("shapes" create-shapes)
1734 ("spinbutton" create-spins)
1735 ("statusbar" create-statusbar)
1736 ("test idle" create-idle-test)
1737 ;; ("test mainloop")
1738 ;; ("test scrolling")
1739 ;; ("test selection")
1740 ("test timeout" create-timeout-test)
1741 ("text" create-text)
1742 ("toggle buttons" create-toggle-buttons)
1743 ("toolbar" create-toolbar-window)
1744 ("tooltips" create-tooltips)
1745 ;; ("tree" #|create-tree|#)
1746 ("UI manager" create-ui-manager)
1748 (main-window (make-instance 'window
1749 :title "testgtk.lisp" :name "main_window"
1750 :default-width 200 :default-height 400
1751 :allow-grow t :allow-shrink nil))
1752 (scrolled-window (make-instance 'scrolled-window
1753 :hscrollbar-policy :automatic
1754 :vscrollbar-policy :automatic
1756 (close-button (make-instance 'button
1757 :label "close" :can-default t
1758 :signal (list 'clicked #'widget-destroy
1759 :object main-window))))
1761 (let ((icon (gdk:pixbuf-load #p"clg:examples;gtk.png")))
1763 (window-icon main-window)
1764 (gdk:pixbuf-add-alpha icon t 254 254 252)))
1767 (make-instance 'v-box
1769 :child-args '(:expand nil)
1770 :child (list (make-instance 'label :label (gtk-version)) :fill nil)
1771 :child (list (make-instance 'label :label "clg CVS version") :fill nil)
1772 :child (list scrolled-window :expand t)
1773 :child (make-instance 'h-separator)
1774 :child (make-instance 'v-box
1775 :homogeneous nil :spacing 10 :border-width 10
1776 :child close-button))
1779 (make-instance 'v-box
1780 :focus-vadjustment (scrolled-window-vadjustment scrolled-window)
1781 :children (mapcar #'(lambda (spec)
1782 (apply #'create-button spec))
1784 (scrolled-window-add-with-viewport scrolled-window content-box))
1786 (widget-grab-focus close-button)
1787 (widget-show-all main-window)
1791 (create-main-window)