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.15 2005/01/06 21:59:51 espen Exp $
21 ;;; Some of the code in this file are really outdatet, but it is
22 ;;; still the most complete example of how to use the library
28 (defmacro define-toplevel (name (window title &rest initargs) &body body)
32 (setq ,window (apply #'make-instance 'window :title ,title ',initargs))
33 (signal-connect ,window 'destroy #'(lambda () (setq ,window nil)))
36 (if (not (widget-visible-p ,window))
37 (widget-show-all ,window)
38 (widget-hide ,window)))))
41 (defmacro define-dialog (name (dialog title &optional (class 'dialog)
47 (setq ,dialog (apply #'make-instance ,class :title ,title ',initargs))
48 (signal-connect ,dialog 'destroy #'(lambda () (setq ,dialog nil)))
51 (if (not (widget-visible-p ,dialog))
53 (widget-hide ,dialog)))))
56 (defmacro define-simple-dialog (name (dialog title &rest initargs) &body body)
57 `(define-dialog ,name (,dialog ,title 'dialog ,@initargs)
59 (dialog-add-button ,dialog "gtk-close" #'widget-destroy :object t)))
63 ;;; Pixmaps used in some of the tests
105 (defvar book-closed-xpm
130 (defvar mini-page-xpm
153 (defvar book-open-xpm
180 (defun create-bbox-in-frame (class frame-label spacing width height layout)
181 (declare (ignore width height))
182 (make-instance 'frame
184 :child (make-instance class
185 :border-width 5 :layout-style layout :spacing spacing
186 :child (make-instance 'button :stock "gtk-ok")
187 :child (make-instance 'button :stock "gtk-cancel")
188 :child (make-instance 'button :stock "gtk-help"))))
190 (define-toplevel create-button-box (window "Button Boxes")
191 (make-instance 'v-box
192 :parent window :border-width 10 :spacing 10 :show-all t
193 :child (make-instance 'frame
194 :label "Horizontal Button Boxes"
195 :child (make-instance 'v-box
196 :border-width 10 :spacing 10
199 (apply #'create-bbox-in-frame
201 '(("Spread" 40 85 20 :spread)
202 ("Edge" 40 85 20 :edge)
203 ("Start" 40 85 20 :start)
204 ("End" 40 85 20 :end)))))
205 :child (make-instance 'frame
206 :label "Vertical Button Boxes"
207 :child (make-instance 'h-box
208 :border-width 10 :spacing 10
211 (apply #'create-bbox-in-frame
213 '(("Spread" 30 85 20 :spread)
214 ("Edge" 30 85 20 :edge)
215 ("Start" 30 85 20 :start)
216 ("End" 30 85 20 :end)))))))
221 (define-simple-dialog create-buttons (dialog "Buttons")
222 (let ((table (make-instance 'table
223 :n-rows 3 :n-columns 3 :homogeneous nil
224 :row-spacing 5 :column-spacing 5 :border-width 10
228 collect (make-instance 'button
229 :label (format nil "button~D" (1+ n))))))
233 (let ((button (nth (+ (* 3 row) column) buttons))
234 (button+1 (nth (mod (+ (* 3 row) column 1) 9) buttons)))
235 (signal-connect button 'clicked
237 (if (widget-visible-p button+1)
238 (widget-hide button+1)
239 (widget-show button+1))))
240 (table-attach table button column (1+ column) row (1+ row)
241 :options '(:expand :fill)))))
242 (widget-show-all table)))
247 (define-simple-dialog create-calendar (dialog "Calendar")
248 (make-instance 'v-box
249 :parent dialog :border-width 10 :show-all t
250 :child (make-instance 'calendar)))
255 (define-simple-dialog create-check-buttons (dialog "Check Buttons")
256 (make-instance 'v-box
257 :border-width 10 :spacing 10 :parent dialog :show-all t
260 collect (make-instance 'check-button
261 :label (format nil "Button~D" n)))))
267 (define-dialog create-color-selection (dialog "Color selection dialog"
268 'color-selection-dialog
269 :allow-grow nil :allow-shrink nil)
270 (with-slots (action-area colorsel) dialog
271 ;; This seg faults for some unknown reason
272 ;; (let ((button (make-instance 'check-button :label "Show Palette")))
273 ;; (dialog-add-action-widget dialog button
276 ;; (color-selection-has-palette-p colorsel)
277 ;; (toggle-button-active-p button)))))
279 (container-add action-area
280 (create-check-button "Show Opacity"
282 (setf (color-selection-has-opacity-control-p colorsel) state))))
284 (container-add action-area
285 (create-check-button "Show Palette"
287 (setf (color-selection-has-palette-p colorsel) state))))
289 (signal-connect dialog :ok
291 (let ((color (color-selection-current-color colorsel)))
292 (format t "Selected color: ~A~%" color)
293 (setf (color-selection-current-color colorsel) color)
294 (widget-hide dialog))))
296 (signal-connect dialog :cancel #'widget-destroy :object t)))
301 (defun clamp (n min-val max-val)
302 (declare (number n min-val max-val))
303 (max (min n max-val) min-val))
305 (defun set-cursor (spinner drawing-area label)
308 (logand (clamp (spin-button-value-as-int spinner) 0 152) #xFE)
310 (setf (label-label label) (string-downcase cursor))
311 (setf (widget-cursor drawing-area) cursor)))
313 (defun cursor-expose (drawing-area event)
314 (declare (ignore event))
315 (multiple-value-bind (width height)
316 (widget-get-size-allocation drawing-area)
317 (let* ((window (widget-window drawing-area))
318 (style (widget-style drawing-area))
319 (white-gc (style-white-gc style))
320 (gray-gc (style-bg-gc style :normal))
321 (black-gc (style-black-gc style)))
322 (gdk:draw-rectangle window white-gc t 0 0 width (floor height 2))
323 (gdk:draw-rectangle window black-gc t 0 (floor height 2) width
325 (gdk:draw-rectangle window gray-gc t (floor width 3)
326 (floor height 3) (floor width 3)
330 (define-simple-dialog create-cursors (dialog "Cursors")
331 (let ((spinner (make-instance 'spin-button
332 :adjustment (adjustment-new
334 (1- (enum-int :last-cursor 'gdk:cursor-type))
336 (drawing-area (make-instance 'drawing-area
337 :width-request 80 :height-request 80
338 :events '(:exposure-mask :button-press-mask)))
339 (label (make-instance 'label :label "XXX")))
341 (signal-connect drawing-area 'expose-event #'cursor-expose :object t)
343 (signal-connect drawing-area 'button-press-event
345 (case (gdk:event-button event)
346 (1 (spin-button-spin spinner :step-forward 0.0))
347 (3 (spin-button-spin spinner :step-backward 0.0)))
350 (signal-connect drawing-area 'scroll-event
352 (case (gdk:event-direction event)
353 (:up (spin-button-spin spinner :step-forward 0.0))
354 (:down (spin-button-spin spinner :step-backward 0.0)))
357 (signal-connect spinner 'changed
359 (set-cursor spinner drawing-area label)))
361 (make-instance 'v-box
362 :parent dialog :border-width 10 :spacing 5 :show-all t
364 (make-instance 'h-box
367 (make-instance 'label :label "Cursor Value : ")
371 :child (make-instance 'frame
372 ; :shadow-type :etched-in
373 :label "Cursor Area" :label-xalign 0.5 :border-width 10
375 :child (list label :expand nil))
377 (widget-realize drawing-area)
378 (set-cursor spinner drawing-area label)))
384 (defun create-dialog ()
386 (setq dialog (make-instance 'dialog
387 :title "Dialog" :default-width 200
389 :button (list "gtk-ok" #'widget-destroy :object t)
390 :signal (list 'destroy
392 (setq dialog nil)))))
394 (let ((label (make-instance 'label
395 :label "Dialog Test" :xpad 10 :ypad 10 :visible t
397 (signal-connect dialog "Toggle"
399 (if (widget-visible-p label)
401 (widget-show label))))))
403 (if (widget-visible-p dialog)
405 (widget-show dialog))))
410 (define-simple-dialog create-entry (dialog "Entry")
411 (let ((main (make-instance 'v-box
412 :border-width 10 :spacing 10 :parent dialog)))
414 (let ((entry (make-instance 'entry :text "hello world" :parent main)))
415 (editable-select-region entry 0 5) ; this has no effect when
417 ;; (editable-insert-text entry "great " 6)
418 ;; (editable-delete-text entry 6 12)
420 (let ((combo (make-instance 'combo-box-entry
425 "item3 item3 item3 item3"
426 "item4 item4 item4 item4 item4"
427 "item5 item5 item5 item5 item5 item5"
428 "item6 item6 item6 item6 item6"
429 "item7 item7 item7 item7"
432 (with-slots (child) combo
433 (setf (editable-text child) "hello world")
434 (editable-select-region child 0)))
436 (flet ((create-check-button (label slot)
437 (make-instance 'check-button
438 :label label :active t :parent main
439 :signal (list 'toggled
441 (setf (slot-value entry slot)
442 (toggle-button-active-p button)))
445 (create-check-button "Editable" 'editable)
446 (create-check-button "Visible" 'visibility)
447 (create-check-button "Sensitive" 'sensitive)))
448 (widget-show-all main)))
453 (define-simple-dialog create-expander (dialog "Expander" :resizable nil)
454 (make-instance 'v-box
455 :parent dialog :spacing 5 :border-width 5 :show-all t
456 :child (create-label "Expander demo. Click on the triangle for details.")
457 :child (make-instance 'expander
459 :child (create-label "Details can be shown or hidden."))))
462 ;; File chooser dialog
464 (define-dialog create-file-chooser (dialog "File Chooser" 'file-chooser-dialog)
465 (dialog-add-button dialog "gtk-cancel" #'widget-destroy :object t)
466 (dialog-add-button dialog "gtk-ok"
468 (if (slot-boundp dialog 'filename)
469 (format t "Selected file: ~A~%" (file-chooser-filename dialog))
470 (write-line "No files selected"))
471 (widget-destroy dialog))))
477 ;; (defun create-handle-box-toolbar ()
478 ;; (let ((toolbar (toolbar-new :horizontal :both)))
479 ;; (toolbar-append-item
480 ;; toolbar "Horizontal" (pixmap-new "clg:examples;test.xpm")
481 ;; :tooltip-text "Horizontal toolbar layout"
482 ;; :callback #'(lambda () (setf (toolbar-orientation toolbar) :horizontal)))
484 ;; (toolbar-append-item
485 ;; toolbar "Vertical" (pixmap-new "clg:examples;test.xpm")
486 ;; :tooltip-text "Vertical toolbar layout"
487 ;; :callback #'(lambda () (setf (toolbar-orientation toolbar) :vertical)))
489 ;; (toolbar-append-space toolbar)
491 ;; (toolbar-append-item
492 ;; toolbar "Icons" (pixmap-new "clg:examples;test.xpm")
493 ;; :tooltip-text "Only show toolbar icons"
494 ;; :callback #'(lambda () (setf (toolbar-style toolbar) :icons)))
496 ;; (toolbar-append-item
497 ;; toolbar "Text" (pixmap-new "clg:examples;test.xpm")
498 ;; :tooltip-text "Only show toolbar text"
499 ;; :callback #'(lambda () (setf (toolbar-style toolbar) :text)))
501 ;; (toolbar-append-item
502 ;; toolbar "Both" (pixmap-new "clg:examples;test.xpm")
503 ;; :tooltip-text "Show toolbar icons and text"
504 ;; :callback #'(lambda () (setf (toolbar-style toolbar) :both)))
506 ;; (toolbar-append-space toolbar)
508 ;; (toolbar-append-item
509 ;; toolbar "Small" (pixmap-new "clg:examples;test.xpm")
510 ;; :tooltip-text "Use small spaces"
511 ;; :callback #'(lambda () (setf (toolbar-space-size toolbar) 5)))
513 ;; (toolbar-append-item
514 ;; toolbar "Big" (pixmap-new "clg:examples;test.xpm")
515 ;; :tooltip-text "Use big spaces"
516 ;; :callback #'(lambda () (setf (toolbar-space-size toolbar) 10)))
518 ;; (toolbar-append-space toolbar)
520 ;; (toolbar-append-item
521 ;; toolbar "Enable" (pixmap-new "clg:examples;test.xpm")
522 ;; :tooltip-text "Enable tooltips"
523 ;; :callback #'(lambda () (toolbar-enable-tooltips toolbar)))
525 ;; (toolbar-append-item
526 ;; toolbar "Disable" (pixmap-new "clg:examples;test.xpm")
527 ;; :tooltip-text "Disable tooltips"
528 ;; :callback #'(lambda () (toolbar-disable-tooltips toolbar)))
530 ;; (toolbar-append-space toolbar)
532 ;; (toolbar-append-item
533 ;; toolbar "Borders" (pixmap-new "clg:examples;test.xpm")
534 ;; :tooltip-text "Show borders"
535 ;; :callback #'(lambda () (setf (toolbar-relief toolbar) :normal)))
537 ;; (toolbar-append-item
538 ;; toolbar "Borderless" (pixmap-new "clg:examples;test.xpm")
539 ;; :tooltip-text "Hide borders"
540 ;; :callback #'(lambda () (setf (toolbar-relief toolbar) :none)))
545 ;; (defun handle-box-child-signal (handle-box child action)
546 ;; (format t "~S: child ~S ~A~%" handle-box child action))
549 ;; (define-test-window create-handle-box "Handle Box Test"
550 ;; (setf (window-allow-grow-p window) t)
551 ;; (setf (window-allow-shrink-p window) t)
552 ;; (setf (window-auto-shrink-p window) nil)
553 ;; (setf (container-border-width window) 20)
554 ;; (let ((v-box (v-box-new nil 0)))
555 ;; (container-add window v-box)
557 ;; (container-add v-box (create-label "Above"))
558 ;; (container-add v-box (hseparator-new))
560 ;; (let ((hbox (hbox-new nil 10)))
561 ;; (container-add v-box hbox)
563 ;; (let ((handle-box (handle-box-new)))
564 ;; (box-pack-start hbox handle-box nil nil 0)
566 ;; handle-box 'child-attached
568 ;; (handle-box-child-signal handle-box child "attached")))
570 ;; handle-box 'child-detached
572 ;; (handle-box-child-signal handle-box child "detached")))
573 ;; (container-add handle-box (create-handle-box-toolbar)))
575 ;; (let ((handle-box (handle-box-new)))
576 ;; (box-pack-start hbox handle-box nil nil 0)
578 ;; handle-box 'child-attached
580 ;; (handle-box-child-signal handle-box child "attached")))
582 ;; handle-box 'child-detached
584 ;; (handle-box-child-signal handle-box child "detached")))
586 ;; (let ((handle-box2 (handle-box-new)))
587 ;; (container-add handle-box handle-box2)
589 ;; handle-box2 'child-attached
591 ;; (handle-box-child-signal handle-box child "attached")))
593 ;; handle-box2 'child-detached
595 ;; (handle-box-child-signal handle-box child "detached")))
596 ;; (container-add handle-box2 (create-label "Foo!")))))
598 ;; (container-add v-box (hseparator-new))
599 ;; (container-add v-box (create-label "Below"))))
603 (define-toplevel create-image (window "Image")
604 (make-instance 'image :file #p"clg:examples;gtk.png" :parent window))
609 (define-toplevel create-labels (window "Labels" :border-width 5 :resizable nil)
610 (flet ((create-label-in-frame (frame-label label-text &rest args)
612 (make-instance 'frame
614 :child (apply #'make-instance 'label :label label-text :xpad 5 :ypad 5 args))
615 :fill nil :expand nil)))
616 (make-instance 'h-box
617 :spacing 5 :parent window
618 :child-args '(:fill nil :expand nil)
619 :child (make-instance 'v-box
621 :child (create-label-in-frame "Normal Label" "This is a Normal label")
622 :child (create-label-in-frame "Multi-line Label"
623 "This is a Multi-line label.
626 :child (create-label-in-frame "Left Justified Label"
627 "This is a Left-Justified
631 :child (create-label-in-frame "Right Justified Label"
632 "This is a Right-Justified
636 :child (make-instance 'v-box
638 :child (create-label-in-frame "Line wrapped label"
639 "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.
640 It supports multiple paragraphs correctly, and correctly adds many extra spaces. "
643 :child (create-label-in-frame "Filled, wrapped label"
644 "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.
645 This is a new paragraph.
646 This is another newer, longer, better paragraph. It is coming to an end, unfortunately."
647 :justify :fill :wrap t)
649 :child (create-label-in-frame "Underlined label"
650 "This label is underlined!
651 This one is underlined (こんにちは) in quite a funky fashion"
653 :pattern "_________________________ _ _________ _ _____ _ __ __ ___ ____ _____")))))
658 (defun layout-expose (layout event)
659 (when (eq (gdk:event-window event) (layout-bin-window layout))
660 (with-slots (gdk:x gdk:y gdk:width gdk:height) event
661 (let ((imin (truncate gdk:x 10))
662 (imax (truncate (+ gdk:x gdk:width 9) 10))
663 (jmin (truncate gdk:y 10))
664 (jmax (truncate (+ gdk:y gdk:height 9) 10)))
666 (let ((window (layout-bin-window layout))
667 (gc (style-black-gc (widget-style layout))))
669 for i from imin below imax
671 for j from jmin below jmax
672 unless (zerop (mod (+ i j) 2))
673 do (gdk:draw-rectangle
674 window gc t (* 10 i) (* 10 j)
675 (1+ (mod i 10)) (1+ (mod j 10)))))))))
678 (define-toplevel create-layout (window "Layout" :default-width 200
680 (let ((layout (make-instance 'layout
681 :parent (make-instance 'scrolled-window :parent window)
682 :width 1600 :height 128000 :events '(:exposure-mask)
683 :signal (list 'expose-event #'layout-expose :object t)
686 (with-slots (hadjustment vadjustment) layout
688 (adjustment-step-increment hadjustment) 10.0
689 (adjustment-step-increment vadjustment) 10.0))
693 (let ((text (format nil "Button ~D, ~D" i j)))
694 (make-instance (if (not (zerop (mod (+ i j) 2)))
697 :label text :parent (list layout :x (* j 100) :y (* i 100))))))
700 for i from 16 below 1280
701 do (let ((text (format nil "Button ~D, ~D" i 0)))
702 (make-instance (if (not (zerop (mod i 2)))
705 :label text :parent (list layout :x 0 :y (* i 100)))))))
711 (define-simple-dialog create-list (dialog "List" :default-height 400)
712 (let* ((store (make-instance 'list-store
713 :column-types '(string int boolean)
714 :column-names '(:foo :bar :baz)
715 :initial-content '(#("First" 12321 nil)
716 (:foo "Yeah" :baz t))))
717 (tree (make-instance 'tree-view :model store)))
720 with iter = (make-instance 'tree-iter)
722 do (list-store-append store (vector "Test" i (zerop (mod i 3))) iter))
724 (let ((column (make-instance 'tree-view-column :title "Column 1"))
725 (cell (make-instance 'cell-renderer-text)))
726 (cell-layout-pack column cell :expand t)
727 (cell-layout-add-attribute column cell 'text (column-index store :foo))
728 (tree-view-append-column tree column))
730 (let ((column (make-instance 'tree-view-column :title "Column 2"))
731 (cell (make-instance 'cell-renderer-text :background "orange")))
732 (cell-layout-pack column cell :expand t)
733 (cell-layout-add-attribute column cell 'text (column-index store :bar))
734 (tree-view-append-column tree column))
736 (let ((column (make-instance 'tree-view-column :title "Column 3"))
737 (cell (make-instance 'cell-renderer-text)))
738 (cell-layout-pack column cell :expand t)
739 (cell-layout-add-attribute column cell 'text (column-index store :baz))
740 (tree-view-append-column tree column))
742 (make-instance 'v-box
743 :parent dialog :border-width 10 :spacing 10 :show-all t
745 (make-instance 'h-box
747 :child (make-instance 'button
748 :label "Remove Selection"
749 :signal (list 'clicked
754 (make-instance 'tree-row-reference :model store :path path))
755 (tree-selection-get-selected-rows
756 (tree-view-selection tree)))))
758 #'(lambda (reference)
759 (list-store-remove store reference))
763 (make-instance 'h-box
765 :child (make-instance 'check-button
766 :label "Show Headers" :active t
767 :signal (list 'toggled
770 (tree-view-headers-visible-p tree)
771 (toggle-button-active-p button)))
773 :child (make-instance 'check-button
774 :label "Reorderable" :active nil
775 :signal (list 'toggled
778 (tree-view-reorderable-p tree)
779 (toggle-button-active-p button)))
782 (make-instance 'h-box
783 :child (make-instance 'label :label "Selection Mode: ")
784 :child (make-instance 'combo-box
785 :content '("Single" "Browse" "Multiple")
787 :signal (list 'changed
788 #'(lambda (combo-box)
791 (tree-view-selection tree))
793 #(:single :browse :multiple)
794 (combo-box-active combo-box))))
798 :child (make-instance 'scrolled-window
799 :child tree :hscrollbar-policy :automatic))))
804 (defun create-menu (depth tearoff)
805 (unless (zerop depth)
806 (let ((menu (make-instance 'menu)))
808 (let ((menu-item (make-instance 'tearoff-menu-item)))
809 (menu-shell-append menu menu-item)))
813 (make-instance 'radio-menu-item
814 :label (format nil "item ~2D - ~D" depth (1+ i)))))
816 (radio-menu-item-add-to-group menu-item group)
817 (setq group menu-item))
818 (unless (zerop (mod depth 2))
819 (setf (check-menu-item-active-p menu-item) t))
820 (menu-shell-append menu menu-item)
822 (setf (widget-sensitive-p menu-item) nil))
823 (let ((submenu (create-menu (1- depth) t)))
825 (setf (menu-item-submenu menu-item) submenu))))))
829 (define-simple-dialog create-menus (dialog "Menus" :default-width 200)
830 (let* ((main (make-instance 'v-box :parent dialog))
831 ; (accel-group (make-instance 'accel-group))
832 (menubar (make-instance 'menu-bar :parent (list main :expand nil))))
833 ; (accel-group-attach accel-group window)
835 (let ((menu-item (make-instance 'menu-item
836 :label (format nil "test~%line2"))))
837 (setf (menu-item-submenu menu-item) (create-menu 2 t))
838 (menu-shell-append menubar menu-item))
840 (let ((menu-item (make-instance 'menu-item :label "foo")))
841 (setf (menu-item-submenu menu-item) (create-menu 3 t))
842 (menu-shell-append menubar menu-item))
844 (let ((menu-item (make-instance 'menu-item :label "bar")))
845 (setf (menu-item-submenu menu-item) (create-menu 4 t))
846 (setf (menu-item-right-justified-p menu-item) t)
847 (menu-shell-append menubar menu-item))
849 (make-instance 'v-box
850 :spacing 10 :border-width 10 :parent main
851 :child (make-instance 'combo-box
855 collect (format nil "Item ~D" i))))
857 (widget-show-all main)))
862 (defun create-notebook-page (notebook page-num book-closed)
863 (let* ((title (format nil "Page ~D" page-num))
864 (page (make-instance 'frame :label title :border-width 10))
865 (v-box (make-instance 'v-box
866 :homogeneous t :border-width 10 :parent page)))
868 (make-instance 'h-box
869 :parent (list v-box :fill nil :padding 5) :homogeneous t
870 :child-args '(:padding 5)
871 :child (make-instance 'check-button
872 :label "Fill Tab" :active t
873 :signal (list 'toggled
876 (notebook-child-tab-fill-p page)
877 (toggle-button-active-p button)))
879 :child (make-instance 'check-button
881 :signal (list 'toggled
884 (notebook-child-tab-expand-p page)
885 (toggle-button-active-p button)))
887 :child (make-instance 'check-button
889 :signal (list 'toggled
892 (notebook-child-tab-pack page)
893 (if (toggle-button-active-p button)
897 :child (make-instance 'button
899 :signal (list 'clicked #'(lambda () (widget-hide page)))))
901 (let ((label-box (make-instance 'h-box
903 :child-args '(:expand nil)
904 :child (make-instance 'image :pixbuf book-closed)
905 :child (make-instance 'label :label title)))
906 (menu-box (make-instance 'h-box
908 :child-args '(:expand nil)
909 :child (make-instance 'image :pixbuf book-closed)
910 :child (make-instance 'label :label title))))
912 (widget-show-all page)
913 (notebook-append notebook page label-box menu-box))))
916 (define-simple-dialog create-notebook (dialog "Notebook")
917 (let ((main (make-instance 'v-box :parent dialog)))
918 (let ((book-open (gdk:pixbuf-new-from-xpm-data book-open-xpm))
919 (book-closed (gdk:pixbuf-new-from-xpm-data book-closed-xpm))
920 (notebook (make-instance 'notebook
921 :border-width 10 :tab-pos :top :parent main)))
922 (flet ((set-image (page func pixbuf)
925 (first (container-children (funcall func notebook page))))
927 (signal-connect notebook 'switch-page
928 #'(lambda (pointer page)
929 (declare (ignore pointer))
930 (unless (eq page (notebook-current-page-num notebook))
931 (set-image page #'notebook-menu-label book-open)
932 (set-image page #'notebook-tab-label book-open)
933 (let ((curpage (notebook-current-page notebook)))
935 (set-image curpage #'notebook-menu-label book-closed)
936 (set-image curpage #'notebook-tab-label book-closed)))))))
937 (loop for i from 1 to 5 do (create-notebook-page notebook i book-closed))
939 (make-instance 'h-separator :parent (list main :expand nil :padding 10))
941 (make-instance 'h-box
942 :spacing 5 :border-width 10
943 :parent (list main :expand nil)
944 :child-args '(:fill nil)
945 :child (make-instance 'check-button
947 :signal (list 'clicked
949 (if (toggle-button-active-p button)
950 (notebook-popup-enable notebook)
951 (notebook-popup-disable notebook)))
953 :child (make-instance 'check-button
954 :label "Homogeneous tabs"
955 :signal (list 'clicked
958 (notebook-homogeneous-p notebook)
959 (toggle-button-active-p button)))
962 (make-instance 'h-box
963 :spacing 5 :border-width 10
964 :parent (list main :expand nil)
965 :child-args '(:expand nil)
966 :child (make-instance 'label :label "Notebook Style: ")
967 :child (let ((scrollable-p nil))
968 (make-instance 'combo-box
969 :content '("Standard" "No tabs" "Scrollable") :active 0
970 :signal (list 'changed
971 #'(lambda (combo-box)
972 (case (combo-box-active combo-box)
974 (setf (notebook-show-tabs-p notebook) t)
976 (setq scrollable-p nil)
977 (setf (notebook-scrollable-p notebook) nil)
979 do (notebook-remove-page notebook 5))))
981 (setf (notebook-show-tabs-p notebook) nil)
983 (setq scrollable-p nil)
984 (setf (notebook-scrollable-p notebook) nil)
986 do (notebook-remove-page notebook 5))))
989 (setq scrollable-p t)
990 (setf (notebook-show-tabs-p notebook) t)
991 (setf (notebook-scrollable-p notebook) t)
992 (loop for i from 6 to 15
993 do (create-notebook-page notebook i book-closed))))))
995 :child (make-instance 'button
996 :label "Show all Pages"
997 :signal (list 'clicked
999 (map-container nil #'widget-show notebook)))))
1001 (make-instance 'h-box
1002 :spacing 5 :border-width 10
1003 :parent (list main :expand nil)
1004 :child (make-instance 'button
1006 :signal (list 'clicked #'notebook-prev-page :object notebook))
1007 :child (make-instance 'button
1009 :signal (list 'clicked #'notebook-next-page :object notebook))
1010 :child (make-instance 'button
1012 :signal (let ((tab-pos 0))
1015 (setq tab-pos (mod (1+ tab-pos) 4))
1017 (notebook-tab-pos notebook)
1018 (svref #(:top :right :bottom :left) tab-pos))))))))
1019 (widget-show-all main)))
1024 (defun toggle-resize (child)
1025 (setf (paned-child-resize-p child) (not (paned-child-resize-p child))))
1027 (defun toggle-shrink (child)
1028 (setf (paned-child-shrink-p child) (not (paned-child-shrink-p child))))
1030 (defun create-pane-options (paned frame-label label1 label2)
1031 (let* ((table (make-instance 'table :n-rows 3 :n-columns 2 :homogeneous t)))
1032 (table-attach table (create-label label1) 0 1 0 1 :options '(:expand :fill))
1033 (let ((check-button (make-instance 'check-button :label "Resize")))
1034 (table-attach table check-button 0 1 1 2 :options '(:expand :fill))
1035 (signal-connect check-button 'toggled
1036 #'toggle-resize :object (paned-child1 paned)))
1037 (let ((check-button (make-instance 'check-button :label "Shrink" :active t)))
1038 (table-attach table check-button 0 1 2 3 :options '(:expand :fill))
1039 (signal-connect check-button 'toggled
1040 #'toggle-shrink :object (paned-child1 paned)))
1042 (table-attach table (create-label label2) 1 2 0 1 :options '(:expand :fill))
1043 (let ((check-button (make-instance 'check-button :label "Resize" :active t)))
1044 (table-attach table check-button 1 2 1 2 :options '(:expand :fill))
1045 (signal-connect check-button 'toggled
1046 #'toggle-resize :object (paned-child2 paned)))
1047 (let ((check-button (make-instance 'check-button :label "Shrink" :active t)))
1048 (table-attach table check-button 1 2 2 3 :options '(:expand :fill))
1049 (signal-connect check-button 'toggled
1050 #'toggle-shrink :object (paned-child2 paned)))
1051 (make-instance 'frame :label frame-label :border-width 4 :child table)))
1053 (define-toplevel create-panes (window "Panes")
1054 (let* ((hpaned (make-instance 'h-paned
1055 :child1 (make-instance 'frame
1056 :width-request 60 :height-request 60
1058 :child (make-instance 'button :label "Hi there"))
1059 :child2 (make-instance 'frame
1060 :width-request 80 :height-request 60
1062 (vpaned (make-instance 'v-paned
1065 :child2 (make-instance 'frame
1066 :width-request 80 :height-request 60
1067 :shadow-type :in))))
1069 (make-instance 'v-box
1071 :child-args '(:expand nil)
1072 :child (list vpaned :expand t)
1073 :child (create-pane-options hpaned "Horizontal" "Left" "Right")
1074 :child (create-pane-options vpaned "Vertical" "Top" "Bottom"))))
1079 (define-simple-dialog create-progress-bar (dialog "Progress Bar")
1080 (let* ((progress (make-instance 'progress-bar :pulse-step 0.05))
1081 (activity-mode-button (make-instance 'check-button
1082 :label "Activity mode"))
1083 (timer (timeout-add 100
1085 (if (toggle-button-active-p activity-mode-button)
1086 (progress-bar-pulse progress)
1087 (let ((fract (+ (progress-bar-fraction progress) 0.01)))
1089 (progress-bar-fraction progress)
1095 (make-instance 'v-box
1096 :parent dialog :border-width 10 :spacing 10 :show-all t
1098 :child activity-mode-button)
1100 (signal-connect dialog 'destroy
1101 #'(lambda () (when timer (timeout-remove timer))))))
1106 (define-simple-dialog create-radio-buttons (dialog "Radio buttons")
1107 (make-instance 'v-box
1108 :parent dialog :border-width 10 :spacing 10 :show-all t
1109 :children (make-radio-group 'radio-button
1110 '((:label "button1") (:label "button2") (:label "button3"))
1116 (define-simple-dialog create-range-controls (dialog "Range controls")
1117 (let ((adjustment (adjustment-new 0.0 0.0 101.0 0.1 1.0 1.0)))
1118 (make-instance 'v-box
1119 :parent dialog :border-width 10 :spacing 10 :show-all t
1120 :child (make-instance 'h-scale
1121 :width-request 150 :adjustment adjustment :inverted t
1122 :update-policy :delayed :digits 1 :draw-value t)
1123 :child (make-instance 'h-scrollbar
1124 :adjustment adjustment :update-policy :continuous))))
1129 (define-simple-dialog create-reparent (dialog "Reparent")
1130 (let ((main (make-instance 'h-box
1131 :homogeneous t :spacing 10 :border-width 10 :parent dialog))
1132 (label (make-instance 'label :label "Hello World")))
1134 (flet ((create-frame (title)
1135 (let* ((frame (make-instance 'frame :label title :parent main))
1136 (box (make-instance 'v-box
1137 :spacing 5 :border-width 5 :parent frame))
1138 (button (make-instance 'button
1139 :label "switch" :parent (list box :expand nil))))
1140 (signal-connect button 'clicked
1142 (widget-reparent label box)))
1145 (box-pack-start (create-frame "Frame 1") label nil t 0)
1146 (create-frame "Frame 2"))
1147 (widget-show-all main)))
1152 (define-toplevel create-rulers (window "Rulers"
1153 :default-width 300 :default-height 300
1154 ;; :events '(:pointer-motion-mask
1155 ;; :pointer-motion-hint-mask)
1158 (widget-events window)
1159 '(:pointer-motion-mask :pointer-motion-hint-mask))
1161 (let ((table (make-instance 'table :n-rows 2 :n-columns 2 :parent window))
1162 (h-ruler (make-instance 'h-ruler
1163 :metric :centimeters :lower 100.0d0 :upper 0.0d0
1164 :position 0.0d0 :max-size 20.0d0))
1165 (v-ruler (make-instance 'v-ruler
1166 :lower 5.0d0 :upper 15.0d0
1167 :position 0.0d0 :max-size 20.0d0)))
1168 (signal-connect window 'motion-notify-event
1170 (widget-event h-ruler event)
1171 (widget-event v-ruler event)))
1172 (table-attach table h-ruler 1 2 0 1 :options :fill :x-options :expand)
1173 (table-attach table v-ruler 0 1 1 2 :options :fill :y-options :expand)))
1178 (define-simple-dialog create-scrolled-windows (dialog "Scrolled windows"
1180 :default-height 300)
1181 (let* ((scrolled-window
1182 (make-instance 'scrolled-window
1183 :parent dialog :border-width 10
1184 :vscrollbar-policy :automatic
1185 :hscrollbar-policy :automatic))
1187 (make-instance 'table
1188 :n-rows 20 :n-columns 20 :row-spacing 10 :column-spacing 10
1189 :focus-vadjustment (scrolled-window-vadjustment scrolled-window)
1190 :focus-hadjustment (scrolled-window-hadjustment scrolled-window))))
1192 (scrolled-window-add-with-viewport scrolled-window table)
1196 (make-instance 'toggle-button
1197 :label (format nil "button (~D,~D)~%" i j))))
1198 (table-attach table button i (1+ i) j (1+ j)))))
1199 (widget-show-all scrolled-window)))
1204 (define-simple-dialog create-size-group (dialog "Size Group" :resizable nil)
1205 (let ((size-group (make-instance 'size-group)))
1206 (flet ((create-frame (label rows)
1207 (let ((table (make-instance 'table
1208 :n-rows (length rows) :n-columns 2 :homogeneous nil
1209 :row-spacing 5 :column-spacing 10 :border-width 5)))
1213 do (table-attach table
1214 (create-label (first row) :xalign 0 :yalign 1)
1215 0 1 i (1+ i) :x-options '(:expand :fill))
1216 (let ((combo (make-instance 'combo-box
1217 :content (rest row) :active 0)))
1218 (size-group-add-widget size-group combo)
1219 (table-attach table combo 1 2 i (1+ i))))
1220 (make-instance 'frame :label label :child table))))
1222 (make-instance 'v-box
1223 :parent dialog :border-width 5 :spacing 5 :show-all t
1224 :child (create-frame "Color Options"
1225 '(("Foreground" "Red" "Green" "Blue")
1226 ("Background" "Red" "Green" "Blue")))
1227 :child (create-frame "Line Options"
1228 '(("Dashing" "Solid" "Dashed" "Dotted")
1229 ("Line ends" "Square" "Round" "Arrow")))
1230 :child (create-check-button "Enable grouping"
1233 (size-group-mode size-group)
1234 (if active :horizontal :none)))
1240 ;; (defun shape-create-icon (xpm-file x y px py type root-window destroy)
1242 ;; (make-instance 'window
1243 ;; :type type :x x :y y
1244 ;; :events '(:button-motion :pointer-motion-hint :button-press)))
1246 ;; (make-instance 'fixed
1247 ;; :parent window :width 100 :height 100)))
1249 ;; (widget-realize window)
1250 ;; (multiple-value-bind (source mask) nil ;(gdk:pixmap-create xpm-file)
1251 ;; (let ((pixmap (pixmap-new source mask))
1254 ;; (declare (fixnum x-offset y-offset))
1255 ;; (fixed-put fixed pixmap px py)
1256 ;; (widget-shape-combine-mask window mask px py)
1258 ;; (signal-connect window 'button-press-event
1259 ;; #'(lambda (event)
1260 ;; (when (typep event 'gdk:button-press-event)
1261 ;; (setq x-offset (truncate (gdk:event-x event)))
1262 ;; (setq y-offset (truncate (gdk:event-y event)))
1263 ;; (grab-add window)
1264 ;; (gdk:pointer-grab
1265 ;; (widget-window window) t
1266 ;; '(:button-release :button-motion :pointer-motion-hint)
1270 ;; (signal-connect window 'button-release-event
1271 ;; #'(lambda (event)
1272 ;; (declare (ignore event))
1273 ;; (grab-remove window)
1274 ;; (gdk:pointer-ungrab 0)
1277 ;; (signal-connect window 'motion-notify-event
1278 ;; #'(lambda (event)
1279 ;; (declare (ignore event))
1280 ;; (multiple-value-bind (win xp yp mask)
1281 ;; (gdk:window-get-pointer root-window)
1282 ;; (declare (ignore mask win) (fixnum xp yp))
1283 ;; (widget-set-uposition
1284 ;; window :x (- xp x-offset) :y (- yp y-offset)))
1286 ;; (signal-connect window 'destroy destroy)))
1288 ;; (widget-show-all window)
1292 ;; (let ((modeller nil)
1295 ;; (defun create-shapes ()
1296 ;; (let ((root-window (gdk:get-root-window)))
1297 ;; (if (not modeller)
1300 ;; (shape-create-icon
1301 ;; "clg:examples;Modeller.xpm" 440 140 0 0 :popup root-window
1302 ;; #'(lambda () (widget-destroyed modeller))))
1303 ;; (widget-destroy modeller))
1308 ;; (shape-create-icon
1309 ;; "clg:examples;FilesQueue.xpm" 580 170 0 0 :popup root-window
1310 ;; #'(lambda () (widget-destroyed sheets))))
1311 ;; (widget-destroy sheets))
1316 ;; (shape-create-icon
1317 ;; "clg:examples;3DRings.xpm" 460 270 25 25 :toplevel root-window
1318 ;; #'(lambda () (widget-destroyed rings))))
1319 ;; (widget-destroy rings)))))
1325 (define-simple-dialog create-spins (dialog "Spin buttons" :has-separator nil)
1326 (let ((main (make-instance 'v-box
1327 :spacing 5 :border-width 10 :parent dialog)))
1329 (flet ((create-date-spinner (label adjustment shadow-type)
1330 (declare (ignore shadow-type))
1331 (make-instance 'v-box
1332 :child-args '(:expand nil)
1333 :child (make-instance 'label
1334 :label label :xalign 0.0 :yalign 0.5)
1335 :child (make-instance 'spin-button
1336 :adjustment adjustment :wrap t))))
1337 (make-instance 'frame
1338 :label "Not accelerated" :parent main
1339 :child (make-instance 'h-box
1341 :child-args '(:padding 5)
1342 :child (create-date-spinner "Day : "
1343 (adjustment-new 1.0 1.0 31.0 1.0 5.0 0.0) :out)
1344 :child (create-date-spinner "Month : "
1345 (adjustment-new 1.0 1.0 12.0 1.0 5.0 0.0) :etched-in)
1346 :child (create-date-spinner "Year : "
1347 (adjustment-new 1998.0 0.0 2100.0 1.0 100.0 0.0) :in))))
1349 (let ((spinner1 (make-instance 'spin-button
1350 :adjustment (adjustment-new 0.0 -10000.0 10000.0 0.5 100.0 0.0)
1351 :climb-rate 1.0 :digits 2 :wrap t :width-request 100))
1352 (spinner2 (make-instance 'spin-button
1353 :adjustment (adjustment-new 2.0 1.0 5.0 1.0 1.0 0.0)
1354 :climb-rate 1.0 :wrap t))
1355 (value-label (make-instance 'label :label "0")))
1356 (signal-connect (spin-button-adjustment spinner2) 'value-changed
1359 (spin-button-digits spinner1)
1360 (floor (spin-button-value spinner2)))))
1362 (make-instance 'frame
1363 :label "Accelerated" :parent main
1364 :child (make-instance 'v-box
1367 (make-instance 'h-box
1368 :child-args '(:padding 5)
1369 :child (make-instance 'v-box
1370 :child (make-instance 'label
1372 :xalign 0.0 :yalign 0.5)
1374 :child (make-instance 'v-box
1375 :child (make-instance 'label
1377 :xalign 0.0 :yalign 0.5)
1379 :expand nil :padding 5)
1380 :child (make-instance 'check-button
1381 :label "Snap to 0.5-ticks" :active t
1382 :signal (list 'clicked
1385 (spin-button-snap-to-ticks-p spinner1)
1386 (toggle-button-active-p button)))
1388 :child (make-instance 'check-button
1389 :label "Numeric only input mode" :active t
1390 :signal (list 'clicked
1393 (spin-button-numeric-p spinner1)
1394 (toggle-button-active-p button)))
1398 (make-instance 'h-box
1399 :child-args '(:padding 5)
1400 :child (make-instance 'button
1401 :label "Value as Int"
1402 :signal (list 'clicked
1405 (label-label value-label)
1407 (spin-button-value-as-int
1409 :child (make-instance 'button
1410 :label "Value as Float"
1411 :signal (list 'clicked
1414 (label-label value-label)
1416 (format nil "~~,~DF"
1417 (spin-button-digits spinner1))
1418 (spin-button-value spinner1)))))))
1419 :padding 5 :expand nil))))
1420 (widget-show-all main)))
1425 (define-toplevel create-statusbar (window "Statusbar")
1426 (let ((statusbar (make-instance 'statusbar :has-resize-grip t))
1427 (close-button (create-button '("close" :can-default t)
1428 #'widget-destroy :object window))
1431 (signal-connect statusbar 'text-popped
1432 #'(lambda (context-id text)
1433 (declare (ignore context-id))
1434 (format nil "Popped: ~A~%" text)))
1436 (make-instance 'v-box
1438 :child (make-instance 'v-box
1439 :border-width 10 :spacing 10
1440 :child (create-button "push something"
1442 (statusbar-push statusbar 1
1443 (format nil "something ~D" (incf counter)))))
1444 :child (create-button "pop"
1446 (statusbar-pop statusbar 1)))
1447 :child (create-button "steal #4"
1449 (statusbar-remove statusbar 1 4)))
1450 :child (create-button "dump stack")
1451 :child (create-button "test contexts"))
1452 :child (list (make-instance 'h-separator) :expand nil)
1454 (make-instance 'v-box :border-width 10 :child close-button)
1456 :child (list statusbar :expand nil))
1458 (widget-grab-focus close-button)))
1463 (define-simple-dialog create-idle-test (dialog "Idle Test")
1464 (let ((label (make-instance 'label
1465 :label "count: 0" :xpad 10 :ypad 10))
1468 (signal-connect dialog 'destroy
1469 #'(lambda () (when idle (idle-remove idle))))
1471 (make-instance 'v-box
1472 :parent dialog :border-width 10 :spacing 10 :show-all t
1474 :child (make-instance 'frame
1475 :label "Label Container" :border-width 5
1476 :child(make-instance 'v-box
1477 :children (make-radio-group 'radio-button
1478 '((:label "Resize-Parent" :value :parent :active t)
1479 (:label "Resize-Queue" :value :queue)
1480 (:label "Resize-Immediate" :value :immediate))
1483 (container-resize-mode (dialog-action-area dialog)) mode))))))
1485 (dialog-add-button dialog "Start"
1492 (setf (label-label label) (format nil "count: ~D" count))
1495 (dialog-add-button dialog "Stop"
1499 (setq idle nil))))))
1505 (define-simple-dialog create-timeout-test (dialog "Timeout Test")
1506 (let ((label (make-instance 'label
1507 :label "count: 0" :xpad 10 :ypad 10 :parent dialog :visible t))
1510 (signal-connect dialog 'destroy
1511 #'(lambda () (when timer (timeout-remove timer))))
1513 (dialog-add-button dialog "Start"
1520 (setf (label-label label) (format nil "count: ~D" count))
1523 (dialog-add-button dialog "Stop"
1526 (timeout-remove timer)
1527 (setq timer nil))))))
1532 (define-simple-dialog create-text (dialog "Text" :default-width 400
1533 :default-height 400)
1534 (let* ((text-view (make-instance 'text-view
1535 :border-width 10 :visible t :wrap-mode :word))
1536 (buffer (text-view-buffer text-view))
1539 (text-buffer-create-tag buffer "Bold" :weight :bold)
1540 (text-buffer-create-tag buffer "Italic" :style :italic)
1541 (text-buffer-create-tag buffer "Underline" :underline :single)
1543 (flet ((create-toggle-callback (tag-name)
1544 (let ((tag (text-tag-table-lookup
1545 (text-buffer-tag-table buffer) tag-name)))
1547 (unless (eq (and (find tag active-tags) t) active)
1550 (push tag active-tags)
1551 (setq active-tags (delete tag active-tags)))
1552 (multiple-value-bind (start end)
1553 (text-buffer-get-selection-bounds buffer)
1555 (text-buffer-apply-tag buffer tag start end)
1556 (text-buffer-remove-tag buffer tag start end))))))))
1559 (make-instance 'action-group
1560 :action (create-toggle-action
1561 "Bold" "gtk-bold" "Bold" "<control>B" "Bold" nil
1562 (create-toggle-callback "Bold"))
1563 :action (create-toggle-action
1564 "Italic" "gtk-italic" "Italic" "<control>I" "Italic" nil
1565 (create-toggle-callback "Italic"))
1566 :action (create-toggle-action
1567 "Underline" "gtk-underline" "Underline" "<control>U" "Underline" nil
1568 (create-toggle-callback "Underline"))))
1569 (ui (make-instance 'ui-manager)))
1571 (ui-manager-insert-action-group ui actions)
1572 (ui-manager-add-ui ui
1573 '((:toolbar "ToolBar"
1575 (:toolitem "Italic")
1576 (:toolitem "Underline"))))
1578 ;; Callback to activate/deactivate toolbar buttons when cursor
1580 (signal-connect buffer 'mark-set
1581 #'(lambda (location mark)
1582 (declare (ignore mark))
1583 (text-tag-table-foreach (text-buffer-tag-table buffer)
1588 (text-iter-has-tag-p location tag)
1589 (not (text-iter-begins-tag-p location tag)))
1590 (text-iter-ends-tag-p location tag))))
1591 (unless (eq active (and (find tag active-tags) t))
1593 (push tag active-tags)
1594 (setq active-tags (delete tag active-tags)))
1596 (toggle-action-active-p
1597 (action-group-get-action actions (text-tag-name tag)))
1600 ;; Callback to apply active tags when a character is inserted
1601 (signal-connect buffer 'insert-text
1602 #'(lambda (iter &rest args)
1603 (declare (ignore args))
1604 (let ((before (text-buffer-get-iter-at-offset buffer
1605 (1- (text-iter-offset iter)))))
1607 for tag in active-tags
1608 do (text-buffer-apply-tag buffer tag before iter))))
1611 (container-add dialog (ui-manager-get-widget ui "/ToolBar") :expand nil)
1612 (container-add dialog text-view)))))
1617 (define-simple-dialog create-toggle-buttons (dialog "Toggle Button")
1618 (make-instance 'v-box
1619 :border-width 10 :spacing 10 :parent dialog :show-all t
1622 collect (make-instance 'toggle-button
1623 :label (format nil "Button~D" (1+ n))))))
1629 (define-toplevel create-toolbar (window "Toolbar test" :resizable nil)
1630 (make-instance 'toolbar
1631 :show-tooltips t :show-arrow nil :parent window
1633 ;; Insert a stock item
1634 :child (make-instance 'tool-button
1636 :tip-text "Destroy toolbar"
1637 :tip-private "Toolbar/Quit"
1638 :signal (list 'clicked #'(lambda () (widget-destroy window))))
1640 :child (make-instance 'separator-tool-item)
1642 :child (make-instance 'tool-button
1643 :label "Horizontal" :stock "gtk-go-forward"
1644 :tip-text "Horizontal toolbar layout"
1645 :tip-private "Toolbar/Horizontal"
1646 :signal (list 'clicked
1648 (setf (toolbar-orientation toolbar) :horizontal))
1651 :child (make-instance 'tool-button
1652 :label "Vertical" :stock "gtk-go-down"
1653 :tip-text "Vertical toolbar layout"
1654 :tip-private "Toolbar/Vertical"
1655 :signal (list 'clicked
1657 (setf (toolbar-orientation toolbar) :vertical))
1660 :child (make-instance 'separator-tool-item)
1662 :children (make-radio-group 'radio-tool-button
1663 '((:label "Icons" :stock "gtk-justify-left"
1664 :tip-text "Only show toolbar icons"
1665 :tip-private "Toolbar/IconsOnly"
1667 (:label "Both" :stock "gtk-justify-center"
1668 :tip-text "Show toolbar icons and text"
1669 :tip-private "Toolbar/Both"
1670 :value :both :active t)
1671 (:label "Text" :stock "gtk-justify-right"
1672 :tip-text "Show toolbar text"
1673 :tip-private "Toolbar/TextOnly"
1676 #'(lambda (toolbar style)
1677 (setf (toolbar-style toolbar) style))
1680 :child (make-instance 'separator-tool-item)
1682 :child (make-instance 'tool-item
1683 :child (make-instance 'entry)
1684 :tip-text "This is an unusable GtkEntry"
1685 :tip-private "Hey don't click me!")
1687 :child (make-instance 'separator-tool-item)
1689 :child (make-instance 'tool-button
1690 :label "Enable" :stock "gtk-add"
1691 :tip-text "Enable tooltips"
1692 :tip-private "Toolbar/EnableTooltips"
1693 :signal (list 'clicked
1695 (setf (toolbar-show-tooltips-p toolbar) t))
1698 :child (make-instance 'tool-button
1699 :label "Disable" :stock "gtk-remove"
1700 :tip-text "Disable tooltips"
1701 :tip-private "Toolbar/DisableTooltips"
1702 :signal (list 'clicked
1704 (setf (toolbar-show-tooltips-p toolbar) nil))
1707 ;; :child (make-instance 'separator-tool-item)
1709 ;; :child (make-instance 'tool-button
1710 ;; :label "GTK" :icon #p"clg:examples;gtk.png"
1711 ;; :tip-text "GTK+ Logo"
1712 ;; :tip-private "Toolbar/GTK+")
1719 (define-simple-dialog create-tooltips (dialog "Tooltips" :default-width 200)
1720 (let ((tooltips (make-instance 'tooltips)))
1721 (flet ((create-button (label tip-text tip-private)
1722 (let ((button (make-instance 'toggle-button :label label)))
1723 (tooltips-set-tip tooltips button tip-text tip-private)
1725 (make-instance 'v-box
1726 :parent dialog :border-width 10 :spacing 10 :show-all t
1727 :child (create-button "button1" "This is button 1" "ContextHelp/button/1")
1728 :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")))))
1733 (defvar *ui-description*
1734 '((:menubar "MenuBar"
1739 (:menuitem "SaveAs")
1742 (:menu "PreferencesMenu"
1748 (:menuitem "Square")
1749 (:menuitem "Rectangle")
1753 (:menuitem "About")))
1758 (:toolitem "Logo"))))
1760 (define-toplevel create-ui-manager (window "UI Manager")
1762 (make-instance 'action-group
1764 :action (create-action "FileMenu" nil "_File")
1765 :action (create-action "PreferencesMenu" nil "_Preferences")
1766 :action (create-action "ColorMenu" nil "_Color")
1767 :action (create-action "ShapeMenu" nil "_Shape")
1768 :action (create-action "HelpMenu" nil "_Help")
1769 :action (create-action "New" "gtk-new" "_New" "<control>N" "Create a new file")
1770 :action (create-action "Open" "gtk-open" "_Open" "<control>O" "Open a file" #'create-file-chooser)
1771 :action (create-action "Save" "gtk-save" "_Save" "<control>S" "Save current file")
1772 :action (create-action "SaveAs" "gtk-save" "Save _As..." "" "Save to a file")
1773 :action (create-action "Quit" "gtk-quit" "_Quit" "<control>Q" "Quit" (list #'widget-destroy :object window))
1774 :action (create-action "About" nil "_About" "<control>A" "About")
1775 :action (create-action "Logo" "demo-gtk-logo" "" nil "GTK+")
1776 :action (create-toggle-action "Bold" "gtk-bold" "_Bold" "<control>B" "Bold" t)
1777 :actions (create-radio-actions
1778 '(("Red" nil "_Red" "<control>R" "Blood")
1779 ("Green" nil "_Green" "<control>G" "Grass")
1780 ("Blue" nil "_Blue" "<control>B" "Sky"))
1782 :actions (create-radio-actions
1783 '(("Square" nil "_Square" "<control>S" "Square")
1784 ("Rectangle" nil "_Rectangle" "<control>R" "Rectangle")
1785 ("Oval" nil "_Oval" "<control>O" "Egg")))))
1786 (ui (make-instance 'ui-manager)))
1788 (ui-manager-insert-action-group ui actions)
1789 (ui-manager-add-ui ui *ui-description*)
1791 (window-add-accel-group window (ui-manager-accel-group ui))
1793 (make-instance 'v-box
1794 :parent window :show-all t
1796 (ui-manager-get-widget ui "/MenuBar")
1797 :expand nil :fill nil)
1799 (ui-manager-get-widget ui "/ToolBar")
1800 :expand nil :fill nil)
1801 :child (make-instance 'label
1802 :label "Type <alt> to start"
1803 :xalign 0.5 :yalign 0.5
1804 :width-request 200 :height-request 200))))
1810 (defun create-main-window ()
1811 ;; (rc-parse "clg:examples;testgtkrc2")
1812 ;; (rc-parse "clg:examples;testgtkrc")
1814 (let* ((button-specs
1815 '(("button box" create-button-box)
1816 ("buttons" create-buttons)
1817 ("calendar" create-calendar)
1818 ("check buttons" create-check-buttons)
1819 ("color selection" create-color-selection)
1820 ("cursors" create-cursors)
1821 ("dialog" create-dialog)
1823 ("entry" create-entry)
1824 ;; ("event watcher")
1825 ("enxpander" create-expander)
1826 ("file chooser" create-file-chooser)
1827 ;; ("font selection")
1828 ;; ("handle box" create-handle-box)
1829 ("image" create-image)
1830 ("labels" create-labels)
1831 ("layout" create-layout)
1832 ("list" create-list)
1833 ("menus" create-menus)
1835 ("notebook" create-notebook)
1836 ("panes" create-panes)
1837 ("progress bar" create-progress-bar)
1838 ("radio buttons" create-radio-buttons)
1839 ("range controls" create-range-controls)
1841 ("reparent" create-reparent)
1842 ("rulers" create-rulers)
1843 ;; ("saved position")
1844 ("scrolled windows" create-scrolled-windows)
1845 ("size group" create-size-group)
1846 ;; ("shapes" create-shapes)
1847 ("spinbutton" create-spins)
1848 ("statusbar" create-statusbar)
1849 ("test idle" create-idle-test)
1850 ;; ("test mainloop")
1851 ;; ("test scrolling")
1852 ;; ("test selection")
1853 ("test timeout" create-timeout-test)
1854 ("text" create-text)
1855 ("toggle buttons" create-toggle-buttons)
1856 ("toolbar" create-toolbar)
1857 ("tooltips" create-tooltips)
1858 ;; ("tree" #|create-tree|#)
1859 ("UI manager" create-ui-manager)
1861 (main-window (make-instance 'window
1862 :title "testgtk.lisp" :name "main_window"
1863 :default-width 200 :default-height 400
1864 :allow-grow t :allow-shrink nil))
1865 (scrolled-window (make-instance 'scrolled-window
1866 :hscrollbar-policy :automatic
1867 :vscrollbar-policy :automatic
1869 (close-button (make-instance 'button
1870 :label "close" :can-default t
1871 :signal (list 'clicked #'widget-destroy
1872 :object main-window))))
1874 (let ((icon (gdk:pixbuf-load #p"clg:examples;gtk.png")))
1876 (window-icon main-window)
1877 (gdk:pixbuf-add-alpha icon t 254 254 252)))
1880 (make-instance 'v-box
1882 :child-args '(:expand nil)
1883 :child (list (make-instance 'label :label (gtk-version)) :fill nil)
1884 :child (list (make-instance 'label :label "clg CVS version") :fill nil)
1885 :child (list scrolled-window :expand t)
1886 :child (make-instance 'h-separator)
1887 :child (make-instance 'v-box
1888 :homogeneous nil :spacing 10 :border-width 10
1889 :child close-button))
1892 (make-instance 'v-box
1893 :focus-vadjustment (scrolled-window-vadjustment scrolled-window)
1894 :children (mapcar #'(lambda (spec)
1895 (apply #'create-button spec))
1897 (scrolled-window-add-with-viewport scrolled-window content-box))
1899 (widget-grab-focus close-button)
1900 (widget-show-all main-window)
1904 (create-main-window)