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.22 2005/02/27 14:24:49 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 (file-chooser-add-filter dialog
456 (make-instance 'file-filter :name "All files" :pattern "*"))
457 (file-chooser-add-filter dialog
458 (make-instance 'file-filter :name "Common Lisp source code"
459 :patterns '("*.lisp" "*.lsp")))
461 (dialog-add-button dialog "gtk-cancel" #'widget-destroy :object t)
462 (dialog-add-button dialog "gtk-ok"
464 (if (slot-boundp dialog 'filename)
465 (format t "Selected file: ~A~%" (file-chooser-filename dialog))
466 (write-line "No files selected"))
467 (widget-destroy dialog))))
470 ;; Font selection dialog
472 (define-toplevel create-font-selection (window "Font Button" :resizable nil)
473 (make-instance 'h-box
474 :parent window :spacing 8 :border-width 8
475 :child (make-instance 'label :label "Pick a font")
476 :child (make-instance 'font-button
477 :use-font t :title "Font Selection Dialog")))
482 (define-toplevel create-handle-box (window "Handle Box Test" :border-width 20)
483 (make-instance 'v-box
485 :child (create-label "Above")
486 :child (make-instance 'h-separator)
487 :child (make-instance 'h-box
490 (make-instance 'handle-box
491 :child (create-toolbar window)
492 :signal (list 'child-attached
494 (format t "~A attached~%" child)))
495 :signal (list 'child-detached
497 (format t "~A detached~%" child))))
498 :expand nil :fill :nil))
499 :child (make-instance 'h-separator)
500 :child (create-label "Below")))
504 (define-toplevel create-image (window "Image")
505 (make-instance 'image :file #p"clg:examples;gtk.png" :parent window))
510 (define-toplevel create-labels (window "Labels" :border-width 5 :resizable nil)
511 (flet ((create-label-in-frame (frame-label label-text &rest args)
513 (make-instance 'frame
515 :child (apply #'make-instance 'label :label label-text :xpad 5 :ypad 5 args))
516 :fill nil :expand nil)))
517 (make-instance 'h-box
518 :spacing 5 :parent window
519 :child-args '(:fill nil :expand nil)
520 :child (make-instance 'v-box
522 :child (create-label-in-frame "Normal Label" "This is a Normal label")
523 :child (create-label-in-frame "Multi-line Label"
524 "This is a Multi-line label.
527 :child (create-label-in-frame "Left Justified Label"
528 "This is a Left-Justified
532 :child (create-label-in-frame "Right Justified Label"
533 "This is a Right-Justified
537 :child (make-instance 'v-box
539 :child (create-label-in-frame "Line wrapped label"
540 "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.
541 It supports multiple paragraphs correctly, and correctly adds many extra spaces. "
544 :child (create-label-in-frame "Filled, wrapped label"
545 "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.
546 This is a new paragraph.
547 This is another newer, longer, better paragraph. It is coming to an end, unfortunately."
548 :justify :fill :wrap t)
550 :child (create-label-in-frame "Underlined label"
551 "This label is underlined!
552 This one is underlined (こんにちは) in quite a funky fashion"
554 :pattern "_________________________ _ _________ _ _____ _ __ __ ___ ____ _____")))))
559 (defun layout-expose (layout event)
560 (when (eq (gdk:event-window event) (layout-bin-window layout))
561 (with-slots (gdk:x gdk:y gdk:width gdk:height) event
562 (let ((imin (truncate gdk:x 10))
563 (imax (truncate (+ gdk:x gdk:width 9) 10))
564 (jmin (truncate gdk:y 10))
565 (jmax (truncate (+ gdk:y gdk:height 9) 10)))
567 (let ((window (layout-bin-window layout))
568 (gc (style-black-gc (widget-style layout))))
570 for i from imin below imax
572 for j from jmin below jmax
573 unless (zerop (mod (+ i j) 2))
574 do (gdk:draw-rectangle
575 window gc t (* 10 i) (* 10 j)
576 (1+ (mod i 10)) (1+ (mod j 10)))))))))
579 (define-toplevel create-layout (window "Layout" :default-width 200
581 (let ((layout (make-instance 'layout
582 :parent (make-instance 'scrolled-window :parent window)
583 :width 1600 :height 128000 :events '(:exposure)
584 :signal (list 'expose-event #'layout-expose :object t))))
586 (with-slots (hadjustment vadjustment) layout
588 (adjustment-step-increment hadjustment) 10.0
589 (adjustment-step-increment vadjustment) 10.0))
593 (let ((text (format nil "Button ~D, ~D" i j)))
595 (make-instance (if (not (zerop (mod (+ i j) 2)))
598 :label text :visible t)
599 (* j 100) (* i 100)))))
602 for i from 16 below 1280
603 do (let ((text (format nil "Button ~D, ~D" i 0)))
605 (make-instance (if (not (zerop (mod i 2)))
608 :label text :visible t)
615 (define-simple-dialog create-list (dialog "List" :default-height 400)
616 (let* ((store (make-instance 'list-store
617 :column-types '(string int boolean)
618 :column-names '(:foo :bar :baz)
619 :initial-content '(#("First" 12321 nil)
620 (:foo "Yeah" :baz t))))
621 (tree (make-instance 'tree-view :model store)))
624 with iter = (make-instance 'tree-iter)
626 do (list-store-append store (vector "Test" i (zerop (mod i 3))) iter))
628 (let ((column (make-instance 'tree-view-column :title "Column 1"))
629 (cell (make-instance 'cell-renderer-text)))
630 (cell-layout-pack column cell :expand t)
631 (cell-layout-add-attribute column cell 'text (column-index store :foo))
632 (tree-view-append-column tree column))
634 (let ((column (make-instance 'tree-view-column :title "Column 2"))
635 (cell (make-instance 'cell-renderer-text :background "orange")))
636 (cell-layout-pack column cell :expand t)
637 (cell-layout-add-attribute column cell 'text (column-index store :bar))
638 (tree-view-append-column tree column))
640 (let ((column (make-instance 'tree-view-column :title "Column 3"))
641 (cell (make-instance 'cell-renderer-text)))
642 (cell-layout-pack column cell :expand t)
643 (cell-layout-add-attribute column cell 'text (column-index store :baz))
644 (tree-view-append-column tree column))
646 (make-instance 'v-box
647 :parent dialog :border-width 10 :spacing 10
649 (make-instance 'h-box
651 :child (make-instance 'button
652 :label "Remove Selection"
653 :signal (list 'clicked
658 (make-instance 'tree-row-reference :model store :path path))
659 (tree-selection-get-selected-rows
660 (tree-view-selection tree)))))
662 #'(lambda (reference)
663 (list-store-remove store reference))
667 (make-instance 'h-box
669 :child (make-instance 'check-button
670 :label "Show Headers" :active t
671 :signal (list 'toggled
674 (tree-view-headers-visible-p tree)
675 (toggle-button-active-p button)))
677 :child (make-instance 'check-button
678 :label "Reorderable" :active nil
679 :signal (list 'toggled
682 (tree-view-reorderable-p tree)
683 (toggle-button-active-p button)))
686 (make-instance 'h-box
687 :child (make-instance 'label :label "Selection Mode: ")
688 :child (make-instance 'combo-box
689 :content '("Single" "Browse" "Multiple")
691 :signal (list 'changed
692 #'(lambda (combo-box)
695 (tree-view-selection tree))
697 #(:single :browse :multiple)
698 (combo-box-active combo-box))))
702 :child (make-instance 'scrolled-window
703 :child tree :hscrollbar-policy :automatic))))
708 (defun create-menu (depth tearoff)
709 (unless (zerop depth)
710 (let ((menu (make-instance 'menu)))
712 (let ((menu-item (make-instance 'tearoff-menu-item)))
713 (menu-shell-append menu menu-item)))
717 (make-instance 'radio-menu-item
718 :label (format nil "item ~2D - ~D" depth (1+ i)))))
720 (add-to-radio-group menu-item group)
721 (setq group menu-item))
722 (unless (zerop (mod depth 2))
723 (setf (check-menu-item-active-p menu-item) t))
724 (menu-shell-append menu menu-item)
726 (setf (widget-sensitive-p menu-item) nil))
727 (let ((submenu (create-menu (1- depth) t)))
729 (setf (menu-item-submenu menu-item) submenu))))))
733 (define-simple-dialog create-menus (dialog "Menus" :default-width 200)
734 (let* ((main (make-instance 'v-box :parent dialog))
735 ; (accel-group (make-instance 'accel-group))
736 (menubar (make-instance 'menu-bar :parent (list main :expand nil))))
737 ; (window-add-accel-group dialog accel-group)
739 (let ((menu-item (make-instance 'menu-item
740 :label (format nil "test~%line2"))))
741 (setf (menu-item-submenu menu-item) (create-menu 2 t))
742 (menu-shell-append menubar menu-item))
744 (let ((menu-item (make-instance 'menu-item :label "foo")))
745 (setf (menu-item-submenu menu-item) (create-menu 3 t))
746 (menu-shell-append menubar menu-item))
748 (let ((menu-item (make-instance 'menu-item :label "bar")))
749 (setf (menu-item-submenu menu-item) (create-menu 4 t))
750 (setf (menu-item-right-justified-p menu-item) t)
751 (menu-shell-append menubar menu-item))
753 (make-instance 'v-box
754 :spacing 10 :border-width 10 :parent main
755 :child (make-instance 'combo-box
759 collect (format nil "Item ~D" i))))
761 (widget-show-all main)))
766 (defun create-notebook-page (notebook page-num book-closed)
767 (let* ((title (format nil "Page ~D" page-num))
768 (page (make-instance 'frame :label title :border-width 10))
769 (v-box (make-instance 'v-box
770 :homogeneous t :border-width 10 :parent page)))
772 (make-instance 'h-box
773 :parent (list v-box :fill nil :padding 5) :homogeneous t
774 :child-args '(:padding 5)
775 :child (make-instance 'check-button
776 :label "Fill Tab" :active t
777 :signal (list 'toggled
780 (notebook-child-tab-fill-p page)
781 (toggle-button-active-p button)))
783 :child (make-instance 'check-button
785 :signal (list 'toggled
788 (notebook-child-tab-expand-p page)
789 (toggle-button-active-p button)))
791 :child (make-instance 'check-button
793 :signal (list 'toggled
796 (notebook-child-tab-pack page)
797 (if (toggle-button-active-p button)
801 :child (make-instance 'button
803 :signal (list 'clicked #'(lambda () (widget-hide page)))))
805 (let ((label-box (make-instance 'h-box
807 :child-args '(:expand nil)
808 :child (make-instance 'image :pixbuf book-closed)
809 :child (make-instance 'label :label title)))
810 (menu-box (make-instance 'h-box
812 :child-args '(:expand nil)
813 :child (make-instance 'image :pixbuf book-closed)
814 :child (make-instance 'label :label title))))
816 (widget-show-all page)
817 (notebook-append notebook page label-box menu-box))))
820 (define-simple-dialog create-notebook (dialog "Notebook")
821 (let ((main (make-instance 'v-box :parent dialog)))
822 (let ((book-open (gdk:pixbuf-new-from-xpm-data book-open-xpm))
823 (book-closed (gdk:pixbuf-new-from-xpm-data book-closed-xpm))
824 (notebook (make-instance 'notebook
825 :border-width 10 :tab-pos :top :parent main)))
826 (flet ((set-image (page func pixbuf)
829 (first (container-children (funcall func notebook page))))
831 (signal-connect notebook 'switch-page
832 #'(lambda (pointer page)
833 (declare (ignore pointer))
834 (set-image page #'notebook-menu-label book-open)
835 (set-image page #'notebook-tab-label book-open)
836 (when (slot-boundp notebook 'current-page)
837 (let ((curpage (notebook-current-page notebook)))
838 (set-image curpage #'notebook-menu-label book-closed)
839 (set-image curpage #'notebook-tab-label book-closed))))))
840 (loop for i from 1 to 5 do (create-notebook-page notebook i book-closed))
842 (make-instance 'h-separator :parent (list main :expand nil :padding 10))
844 (make-instance 'h-box
845 :spacing 5 :border-width 10
846 :parent (list main :expand nil)
847 :child-args '(:fill nil)
848 :child (make-instance 'check-button
850 :signal (list 'clicked
852 (if (toggle-button-active-p button)
853 (notebook-popup-enable notebook)
854 (notebook-popup-disable notebook)))
856 :child (make-instance 'check-button
857 :label "Homogeneous tabs"
858 :signal (list 'clicked
861 (notebook-homogeneous-p notebook)
862 (toggle-button-active-p button)))
865 (make-instance 'h-box
866 :spacing 5 :border-width 10
867 :parent (list main :expand nil)
868 :child-args '(:expand nil)
869 :child (make-instance 'label :label "Notebook Style: ")
870 :child (let ((scrollable-p nil))
871 (make-instance 'combo-box
872 :content '("Standard" "No tabs" "Scrollable") :active 0
873 :signal (list 'changed
874 #'(lambda (combo-box)
875 (case (combo-box-active combo-box)
877 (setf (notebook-show-tabs-p notebook) t)
879 (setq scrollable-p nil)
880 (setf (notebook-scrollable-p notebook) nil)
882 do (notebook-remove-page notebook 5))))
884 (setf (notebook-show-tabs-p notebook) nil)
886 (setq scrollable-p nil)
887 (setf (notebook-scrollable-p notebook) nil)
889 do (notebook-remove-page notebook 5))))
892 (setq scrollable-p t)
893 (setf (notebook-show-tabs-p notebook) t)
894 (setf (notebook-scrollable-p notebook) t)
895 (loop for i from 6 to 15
896 do (create-notebook-page notebook i book-closed))))))
898 :child (make-instance 'button
899 :label "Show all Pages"
900 :signal (list 'clicked
902 (map-container nil #'widget-show notebook)))))
904 (make-instance 'h-box
905 :spacing 5 :border-width 10
906 :parent (list main :expand nil)
907 :child (make-instance 'button
909 :signal (list 'clicked #'notebook-prev-page :object notebook))
910 :child (make-instance 'button
912 :signal (list 'clicked #'notebook-next-page :object notebook))
913 :child (make-instance 'button
915 :signal (let ((tab-pos 0))
918 (setq tab-pos (mod (1+ tab-pos) 4))
920 (notebook-tab-pos notebook)
921 (svref #(:top :right :bottom :left) tab-pos))))))))
922 (widget-show-all main)))
927 (defun toggle-resize (child)
928 (setf (paned-child-resize-p child) (not (paned-child-resize-p child))))
930 (defun toggle-shrink (child)
931 (setf (paned-child-shrink-p child) (not (paned-child-shrink-p child))))
933 (defun create-pane-options (paned frame-label label1 label2)
934 (let* ((table (make-instance 'table :n-rows 3 :n-columns 2 :homogeneous t)))
935 (table-attach table (create-label label1) 0 1 0 1 :options '(:expand :fill))
936 (let ((check-button (make-instance 'check-button :label "Resize")))
937 (table-attach table check-button 0 1 1 2 :options '(:expand :fill))
938 (signal-connect check-button 'toggled
939 #'toggle-resize :object (paned-child1 paned)))
940 (let ((check-button (make-instance 'check-button :label "Shrink" :active t)))
941 (table-attach table check-button 0 1 2 3 :options '(:expand :fill))
942 (signal-connect check-button 'toggled
943 #'toggle-shrink :object (paned-child1 paned)))
945 (table-attach table (create-label label2) 1 2 0 1 :options '(:expand :fill))
946 (let ((check-button (make-instance 'check-button :label "Resize" :active t)))
947 (table-attach table check-button 1 2 1 2 :options '(:expand :fill))
948 (signal-connect check-button 'toggled
949 #'toggle-resize :object (paned-child2 paned)))
950 (let ((check-button (make-instance 'check-button :label "Shrink" :active t)))
951 (table-attach table check-button 1 2 2 3 :options '(:expand :fill))
952 (signal-connect check-button 'toggled
953 #'toggle-shrink :object (paned-child2 paned)))
954 (make-instance 'frame :label frame-label :border-width 4 :child table)))
956 (define-toplevel create-panes (window "Panes")
957 (let* ((hpaned (make-instance 'h-paned
958 :child1 (make-instance 'frame
959 :width-request 60 :height-request 60
961 :child (make-instance 'button :label "Hi there"))
962 :child2 (make-instance 'frame
963 :width-request 80 :height-request 60
965 (vpaned (make-instance 'v-paned
968 :child2 (make-instance 'frame
969 :width-request 80 :height-request 60
972 (make-instance 'v-box
974 :child-args '(:expand nil)
975 :child (list vpaned :expand t)
976 :child (create-pane-options hpaned "Horizontal" "Left" "Right")
977 :child (create-pane-options vpaned "Vertical" "Top" "Bottom"))))
982 (define-simple-dialog create-progress-bar (dialog "Progress Bar")
983 (let* ((progress (make-instance 'progress-bar :pulse-step 0.05))
984 (activity-mode-button (make-instance 'check-button
985 :label "Activity mode"))
986 (timer (timeout-add 100
988 (if (toggle-button-active-p activity-mode-button)
989 (progress-bar-pulse progress)
990 (let ((fract (+ (progress-bar-fraction progress) 0.01)))
992 (progress-bar-fraction progress)
998 (make-instance 'v-box
999 :parent dialog :border-width 10 :spacing 10
1001 :child activity-mode-button)
1003 (signal-connect dialog 'destroy
1004 #'(lambda () (when timer (timeout-remove timer))))))
1009 (define-simple-dialog create-radio-buttons (dialog "Radio buttons")
1010 (make-instance 'v-box
1011 :parent dialog :border-width 10 :spacing 10
1012 :children (make-radio-group 'radio-button
1013 '((:label "button1") (:label "button2") (:label "button3"))
1019 (define-simple-dialog create-range-controls (dialog "Range controls")
1020 (let ((adjustment (adjustment-new 0.0 0.0 101.0 0.1 1.0 1.0)))
1021 (make-instance 'v-box
1022 :parent dialog :border-width 10 :spacing 10
1023 :child (make-instance 'h-scale
1024 :width-request 150 :adjustment adjustment :inverted t
1025 :update-policy :delayed :digits 1 :draw-value t)
1026 :child (make-instance 'h-scrollbar
1027 :adjustment adjustment :update-policy :continuous))))
1032 (define-simple-dialog create-reparent (dialog "Reparent")
1033 (let ((main (make-instance 'h-box
1034 :homogeneous t :spacing 10 :border-width 10 :parent dialog))
1035 (label (make-instance 'label :label "Hello World")))
1037 (flet ((create-frame (title)
1038 (let* ((frame (make-instance 'frame :label title :parent main))
1039 (box (make-instance 'v-box
1040 :spacing 5 :border-width 5 :parent frame))
1041 (button (make-instance 'button
1042 :label "switch" :parent (list box :expand nil))))
1043 (signal-connect button 'clicked
1045 (widget-reparent label box)))
1048 (box-pack-start (create-frame "Frame 1") label nil t 0)
1049 (create-frame "Frame 2"))
1050 (widget-show-all main)))
1055 (define-toplevel create-rulers (window "Rulers"
1056 :default-width 300 :default-height 300
1057 :events '(:pointer-motion :pointer-motion-hint))
1058 (let ((table (make-instance 'table :n-rows 2 :n-columns 2 :parent window))
1059 (h-ruler (make-instance 'h-ruler
1060 :metric :centimeters :lower 100.0d0 :upper 0.0d0
1061 :position 0.0d0 :max-size 20.0d0))
1062 (v-ruler (make-instance 'v-ruler
1063 :lower 5.0d0 :upper 15.0d0
1064 :position 0.0d0 :max-size 20.0d0)))
1065 (signal-connect window 'motion-notify-event
1067 (widget-event h-ruler event)
1068 (widget-event v-ruler event)))
1069 (table-attach table h-ruler 1 2 0 1 :options :fill :x-options :expand)
1070 (table-attach table v-ruler 0 1 1 2 :options :fill :y-options :expand)))
1075 (define-simple-dialog create-scrolled-windows (dialog "Scrolled windows"
1077 :default-height 300)
1078 (let* ((scrolled-window
1079 (make-instance 'scrolled-window
1080 :parent dialog :border-width 10
1081 :vscrollbar-policy :automatic
1082 :hscrollbar-policy :automatic))
1084 (make-instance 'table
1085 :n-rows 20 :n-columns 20 :row-spacing 10 :column-spacing 10
1086 :focus-vadjustment (scrolled-window-vadjustment scrolled-window)
1087 :focus-hadjustment (scrolled-window-hadjustment scrolled-window))))
1089 (scrolled-window-add-with-viewport scrolled-window table)
1093 (make-instance 'toggle-button
1094 :label (format nil "button (~D,~D)~%" i j))))
1095 (table-attach table button i (1+ i) j (1+ j)))))
1096 (widget-show-all scrolled-window)))
1101 (define-simple-dialog create-size-group (dialog "Size Group" :resizable nil)
1102 (let ((size-group (make-instance 'size-group)))
1103 (flet ((create-frame (label rows)
1104 (let ((table (make-instance 'table
1105 :n-rows (length rows) :n-columns 2 :homogeneous nil
1106 :row-spacing 5 :column-spacing 10 :border-width 5)))
1110 do (table-attach table
1111 (create-label (first row) :xalign 0 :yalign 1)
1112 0 1 i (1+ i) :x-options '(:expand :fill))
1113 (let ((combo (make-instance 'combo-box
1114 :content (rest row) :active 0)))
1115 (size-group-add-widget size-group combo)
1116 (table-attach table combo 1 2 i (1+ i))))
1117 (make-instance 'frame :label label :child table))))
1119 (make-instance 'v-box
1120 :parent dialog :border-width 5 :spacing 5
1121 :child (create-frame "Color Options"
1122 '(("Foreground" "Red" "Green" "Blue")
1123 ("Background" "Red" "Green" "Blue")))
1124 :child (create-frame "Line Options"
1125 '(("Dashing" "Solid" "Dashed" "Dotted")
1126 ("Line ends" "Square" "Round" "Arrow")))
1127 :child (create-check-button "Enable grouping"
1130 (size-group-mode size-group)
1131 (if active :horizontal :none)))
1137 (defun create-shape-icon (xpm-file x y px py type root-window destroy)
1139 (make-instance 'window
1140 :type type :default-width 100 :default-height 100
1141 :events '(:button-motion :pointer-motion-hint :button-press)
1142 :signal (list 'destroy destroy))))
1144 (widget-realize window)
1145 (multiple-value-bind (source mask) (gdk:pixmap-create xpm-file)
1146 (let ((fixed (make-instance 'fixed :parent window)))
1147 (fixed-put fixed (create-image-widget source mask) px py))
1148 (widget-shape-combine-mask window mask px py))
1152 (declare (fixnum x-offset y-offset))
1153 (signal-connect window 'button-press-event
1155 (when (typep event 'gdk:button-press-event)
1156 (setq x-offset (truncate (gdk:event-x event)))
1157 (setq y-offset (truncate (gdk:event-y event)))
1159 (gdk:pointer-grab (widget-window window)
1160 :events '(:button-release :button-motion :pointer-motion-hint)
1161 :owner-events t :time event))))
1163 (signal-connect window 'button-release-event
1165 (grab-remove window)
1166 (gdk:pointer-ungrab event)))
1168 (signal-connect window 'motion-notify-event
1170 (declare (ignore event))
1171 (multiple-value-bind (win xp yp mask)
1172 (gdk:window-get-pointer root-window)
1173 (declare (ignore mask win) (fixnum xp yp))
1174 (window-move window (- xp x-offset) (- yp y-offset))))))
1176 (window-move window x y)
1177 (widget-show-all window)
1181 (let ((modeller nil)
1184 (defun create-shapes ()
1185 (let ((root-window (gdk:get-root-window)))
1190 "clg:examples;Modeller.xpm" 440 140 0 0 :popup root-window
1191 #'(lambda () (setq modeller nil))))
1192 (widget-destroy modeller))
1198 "clg:examples;FilesQueue.xpm" 580 170 0 0 :popup root-window
1199 #'(lambda () (setq sheets nil))))
1200 (widget-destroy sheets))
1206 "clg:examples;3DRings.xpm" 460 270 25 25 :toplevel root-window
1207 #'(lambda () (setq rings nil))))
1208 (widget-destroy rings)))))
1214 (define-simple-dialog create-spins (dialog "Spin buttons" :has-separator nil)
1215 (let ((main (make-instance 'v-box
1216 :spacing 5 :border-width 10 :parent dialog)))
1218 (flet ((create-date-spinner (label adjustment shadow-type)
1219 (declare (ignore shadow-type))
1220 (make-instance 'v-box
1221 :child-args '(:expand nil)
1222 :child (make-instance 'label
1223 :label label :xalign 0.0 :yalign 0.5)
1224 :child (make-instance 'spin-button
1225 :adjustment adjustment :wrap t))))
1226 (make-instance 'frame
1227 :label "Not accelerated" :parent main
1228 :child (make-instance 'h-box
1230 :child-args '(:padding 5)
1231 :child (create-date-spinner "Day : "
1232 (adjustment-new 1.0 1.0 31.0 1.0 5.0 0.0) :out)
1233 :child (create-date-spinner "Month : "
1234 (adjustment-new 1.0 1.0 12.0 1.0 5.0 0.0) :etched-in)
1235 :child (create-date-spinner "Year : "
1236 (adjustment-new 1998.0 0.0 2100.0 1.0 100.0 0.0) :in))))
1238 (let ((spinner1 (make-instance 'spin-button
1239 :adjustment (adjustment-new 0.0 -10000.0 10000.0 0.5 100.0 0.0)
1240 :climb-rate 1.0 :digits 2 :wrap t :width-request 100))
1241 (spinner2 (make-instance 'spin-button
1242 :adjustment (adjustment-new 2.0 1.0 5.0 1.0 1.0 0.0)
1243 :climb-rate 1.0 :wrap t))
1244 (value-label (make-instance 'label :label "0")))
1245 (signal-connect (spin-button-adjustment spinner2) 'value-changed
1248 (spin-button-digits spinner1)
1249 (floor (spin-button-value spinner2)))))
1251 (make-instance 'frame
1252 :label "Accelerated" :parent main
1253 :child (make-instance 'v-box
1256 (make-instance 'h-box
1257 :child-args '(:padding 5)
1258 :child (make-instance 'v-box
1259 :child (make-instance 'label
1261 :xalign 0.0 :yalign 0.5)
1263 :child (make-instance 'v-box
1264 :child (make-instance 'label
1266 :xalign 0.0 :yalign 0.5)
1268 :expand nil :padding 5)
1269 :child (make-instance 'check-button
1270 :label "Snap to 0.5-ticks" :active t
1271 :signal (list 'clicked
1274 (spin-button-snap-to-ticks-p spinner1)
1275 (toggle-button-active-p button)))
1277 :child (make-instance 'check-button
1278 :label "Numeric only input mode" :active t
1279 :signal (list 'clicked
1282 (spin-button-numeric-p spinner1)
1283 (toggle-button-active-p button)))
1287 (make-instance 'h-box
1288 :child-args '(:padding 5)
1289 :child (make-instance 'button
1290 :label "Value as Int"
1291 :signal (list 'clicked
1294 (label-label value-label)
1296 (spin-button-value-as-int
1298 :child (make-instance 'button
1299 :label "Value as Float"
1300 :signal (list 'clicked
1303 (label-label value-label)
1305 (format nil "~~,~DF"
1306 (spin-button-digits spinner1))
1307 (spin-button-value spinner1)))))))
1308 :padding 5 :expand nil))))
1309 (widget-show-all main)))
1314 (define-toplevel create-statusbar (window "Statusbar")
1315 (let ((statusbar (make-instance 'statusbar :has-resize-grip t))
1316 (close-button (create-button '("close" :can-default t)
1317 #'widget-destroy :object window))
1320 (signal-connect statusbar 'text-popped
1321 #'(lambda (context-id text)
1322 (declare (ignore context-id))
1323 (format nil "Popped: ~A~%" text)))
1325 (make-instance 'v-box
1327 :child (make-instance 'v-box
1328 :border-width 10 :spacing 10
1329 :child (create-button "push something"
1331 (statusbar-push statusbar 1
1332 (format nil "something ~D" (incf counter)))))
1333 :child (create-button "pop"
1335 (statusbar-pop statusbar 1)))
1336 :child (create-button "steal #4"
1338 (statusbar-remove statusbar 1 4)))
1339 :child (create-button "dump stack")
1340 :child (create-button "test contexts"))
1341 :child (list (make-instance 'h-separator) :expand nil)
1343 (make-instance 'v-box :border-width 10 :child close-button)
1345 :child (list statusbar :expand nil))
1347 (widget-grab-focus close-button)))
1352 (define-simple-dialog create-idle-test (dialog "Idle Test")
1353 (let ((label (make-instance 'label
1354 :label "count: 0" :xpad 10 :ypad 10))
1357 (signal-connect dialog 'destroy
1358 #'(lambda () (when idle (idle-remove idle))))
1360 (make-instance 'v-box
1361 :parent dialog :border-width 10 :spacing 10
1363 :child (make-instance 'frame
1364 :label "Label Container" :border-width 5
1365 :child(make-instance 'v-box
1366 :children (make-radio-group 'radio-button
1367 '((:label "Resize-Parent" :value :parent :active t)
1368 (:label "Resize-Queue" :value :queue)
1369 (:label "Resize-Immediate" :value :immediate))
1372 (container-resize-mode (dialog-action-area dialog)) mode))))))
1374 (dialog-add-button dialog "Start"
1381 (setf (label-label label) (format nil "count: ~D" count))
1384 (dialog-add-button dialog "Stop"
1388 (setq idle nil))))))
1394 (define-simple-dialog create-timeout-test (dialog "Timeout Test")
1395 (let ((label (make-instance 'label
1396 :label "count: 0" :xpad 10 :ypad 10 :parent dialog :visible t))
1399 (signal-connect dialog 'destroy
1400 #'(lambda () (when timer (timeout-remove timer))))
1402 (dialog-add-button dialog "Start"
1409 (setf (label-label label) (format nil "count: ~D" count))
1412 (dialog-add-button dialog "Stop"
1415 (timeout-remove timer)
1416 (setq timer nil))))))
1421 (define-simple-dialog create-text (dialog "Text" :default-width 400
1422 :default-height 400)
1423 (let* ((text-view (make-instance 'text-view
1424 :border-width 10 :visible t :wrap-mode :word))
1425 (buffer (text-view-buffer text-view))
1428 (text-buffer-create-tag buffer "Bold" :weight :bold)
1429 (text-buffer-create-tag buffer "Italic" :style :italic)
1430 (text-buffer-create-tag buffer "Underline" :underline :single)
1432 (flet ((create-toggle-callback (tag-name)
1433 (let ((tag (text-tag-table-lookup
1434 (text-buffer-tag-table buffer) tag-name)))
1436 (unless (eq (and (find tag active-tags) t) active)
1439 (push tag active-tags)
1440 (setq active-tags (delete tag active-tags)))
1441 (multiple-value-bind (non-zero-p start end)
1442 (text-buffer-get-selection-bounds buffer)
1443 (declare (ignore non-zero-p))
1445 (text-buffer-apply-tag buffer tag start end)
1446 (text-buffer-remove-tag buffer tag start end))))))))
1449 (make-instance 'action-group
1450 :action (create-toggle-action
1451 "Bold" "gtk-bold" "Bold" "<control>B" "Bold" nil
1452 (create-toggle-callback "Bold"))
1453 :action (create-toggle-action
1454 "Italic" "gtk-italic" "Italic" "<control>I" "Italic" nil
1455 (create-toggle-callback "Italic"))
1456 :action (create-toggle-action
1457 "Underline" "gtk-underline" "Underline" "<control>U" "Underline" nil
1458 (create-toggle-callback "Underline"))))
1459 (ui (make-instance 'ui-manager)))
1461 (ui-manager-insert-action-group ui actions)
1462 (ui-manager-add-ui ui
1463 '((:toolbar "ToolBar"
1465 (:toolitem "Italic")
1466 (:toolitem "Underline"))))
1468 ;; Callback to activate/deactivate toolbar buttons when cursor
1470 (signal-connect buffer 'mark-set
1471 #'(lambda (location mark)
1472 (declare (ignore mark))
1473 (text-tag-table-foreach (text-buffer-tag-table buffer)
1478 (text-iter-has-tag-p location tag)
1479 (not (text-iter-begins-tag-p location tag)))
1480 (text-iter-ends-tag-p location tag))))
1481 (unless (eq active (and (find tag active-tags) t))
1483 (push tag active-tags)
1484 (setq active-tags (delete tag active-tags)))
1486 (toggle-action-active-p
1487 (action-group-get-action actions (text-tag-name tag)))
1490 ;; Callback to apply active tags when a character is inserted
1491 (signal-connect buffer 'insert-text
1492 #'(lambda (iter &rest args)
1493 (declare (ignore args))
1494 (let ((before (text-buffer-get-iter-at-offset buffer
1495 (1- (text-iter-offset iter)))))
1497 for tag in active-tags
1498 do (text-buffer-apply-tag buffer tag before iter))))
1501 (container-add dialog (ui-manager-get-widget ui "/ToolBar") :expand nil)
1502 (container-add dialog text-view)))))
1507 (define-simple-dialog create-toggle-buttons (dialog "Toggle Button")
1508 (make-instance 'v-box
1509 :border-width 10 :spacing 10 :parent dialog
1512 collect (make-instance 'toggle-button
1513 :label (format nil "Button~D" (1+ n))))))
1519 (defun create-toolbar (window)
1520 (make-instance 'toolbar
1521 :show-tooltips t :show-arrow nil
1523 ;; Insert a stock item
1524 :child (make-instance 'tool-button
1526 :tip-text "Destroy toolbar"
1527 :tip-private "Toolbar/Quit"
1528 :signal (list 'clicked #'(lambda () (widget-destroy window))))
1530 :child (make-instance 'separator-tool-item)
1532 :child (make-instance 'tool-button
1533 :label "Horizontal" :stock "gtk-go-forward"
1534 :tip-text "Horizontal toolbar layout"
1535 :tip-private "Toolbar/Horizontal"
1536 :signal (list 'clicked
1538 (setf (toolbar-orientation toolbar) :horizontal))
1541 :child (make-instance 'tool-button
1542 :label "Vertical" :stock "gtk-go-down"
1543 :tip-text "Vertical toolbar layout"
1544 :tip-private "Toolbar/Vertical"
1545 :signal (list 'clicked
1547 (setf (toolbar-orientation toolbar) :vertical))
1550 :child (make-instance 'separator-tool-item)
1552 :children (make-radio-group 'radio-tool-button
1553 '((:label "Icons" :stock "gtk-justify-left"
1554 :tip-text "Only show toolbar icons"
1555 :tip-private "Toolbar/IconsOnly"
1557 (:label "Both" :stock "gtk-justify-center"
1558 :tip-text "Show toolbar icons and text"
1559 :tip-private "Toolbar/Both"
1560 :value :both :active t)
1561 (:label "Text" :stock "gtk-justify-right"
1562 :tip-text "Show toolbar text"
1563 :tip-private "Toolbar/TextOnly"
1566 #'(lambda (toolbar style)
1567 (setf (toolbar-style toolbar) style))
1570 :child (make-instance 'separator-tool-item)
1572 :child (make-instance 'tool-item
1573 :child (make-instance 'entry)
1574 :tip-text "This is an unusable GtkEntry"
1575 :tip-private "Hey don't click me!")
1577 :child (make-instance 'separator-tool-item)
1579 :child (make-instance 'tool-button
1580 :label "Enable" :stock "gtk-add"
1581 :tip-text "Enable tooltips"
1582 :tip-private "Toolbar/EnableTooltips"
1583 :signal (list 'clicked
1585 (setf (toolbar-show-tooltips-p toolbar) t))
1588 :child (make-instance 'tool-button
1589 :label "Disable" :stock "gtk-remove"
1590 :tip-text "Disable tooltips"
1591 :tip-private "Toolbar/DisableTooltips"
1592 :signal (list 'clicked
1594 (setf (toolbar-show-tooltips-p toolbar) nil))
1597 ;; :child (make-instance 'separator-tool-item)
1599 ;; :child (make-instance 'tool-button
1600 ;; :label "GTK" :icon #p"clg:examples;gtk.png"
1601 ;; :tip-text "GTK+ Logo"
1602 ;; :tip-private "Toolbar/GTK+")
1605 (define-toplevel create-toolbar-window (window "Toolbar test" :resizable nil)
1606 (container-add window (create-toolbar window)))
1612 (define-simple-dialog create-tooltips (dialog "Tooltips" :default-width 200)
1613 (let ((tooltips (make-instance 'tooltips)))
1614 (flet ((create-button (label tip-text tip-private)
1615 (let ((button (make-instance 'toggle-button :label label)))
1616 (tooltips-set-tip tooltips button tip-text tip-private)
1618 (make-instance 'v-box
1619 :parent dialog :border-width 10 :spacing 10
1620 :child (create-button "button1" "This is button 1" "ContextHelp/button/1")
1621 :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")))))
1626 (defvar *ui-description*
1627 '((:menubar "MenuBar"
1632 (:menuitem "SaveAs")
1635 (:menu "PreferencesMenu"
1641 (:menuitem "Square")
1642 (:menuitem "Rectangle")
1646 (:menuitem "About")))
1651 (:toolitem "Logo"))))
1653 (define-toplevel create-ui-manager (window "UI Manager")
1655 (make-instance 'action-group
1657 :action (create-action "FileMenu" nil "_File")
1658 :action (create-action "PreferencesMenu" nil "_Preferences")
1659 :action (create-action "ColorMenu" nil "_Color")
1660 :action (create-action "ShapeMenu" nil "_Shape")
1661 :action (create-action "HelpMenu" nil "_Help")
1662 :action (create-action "New" "gtk-new" "_New" "<control>N" "Create a new file")
1663 :action (create-action "Open" "gtk-open" "_Open" "<control>O" "Open a file" #'create-file-chooser)
1664 :action (create-action "Save" "gtk-save" "_Save" "<control>S" "Save current file")
1665 :action (create-action "SaveAs" "gtk-save" "Save _As..." "" "Save to a file")
1666 :action (create-action "Quit" "gtk-quit" "_Quit" "<control>Q" "Quit" (list #'widget-destroy :object window))
1667 :action (create-action "About" nil "_About" "<control>A" "About")
1668 :action (create-action "Logo" "demo-gtk-logo" "" nil "GTK+")
1669 :action (create-toggle-action "Bold" "gtk-bold" "_Bold" "<control>B" "Bold" t)
1670 :actions (create-radio-actions
1671 '(("Red" nil "_Red" "<control>R" "Blood")
1672 ("Green" nil "_Green" "<control>G" "Grass")
1673 ("Blue" nil "_Blue" "<control>B" "Sky"))
1675 :actions (create-radio-actions
1676 '(("Square" nil "_Square" "<control>S" "Square")
1677 ("Rectangle" nil "_Rectangle" "<control>R" "Rectangle")
1678 ("Oval" nil "_Oval" "<control>O" "Egg")))))
1679 (ui (make-instance 'ui-manager)))
1681 (ui-manager-insert-action-group ui actions)
1682 (ui-manager-add-ui ui *ui-description*)
1684 (window-add-accel-group window (ui-manager-accel-group ui))
1686 (make-instance 'v-box
1689 (ui-manager-get-widget ui "/MenuBar")
1690 :expand nil :fill nil)
1692 (ui-manager-get-widget ui "/ToolBar")
1693 :expand nil :fill nil)
1694 :child (make-instance 'label
1695 :label "Type <alt> to start"
1696 :xalign 0.5 :yalign 0.5
1697 :width-request 200 :height-request 200))))
1703 (defun create-main-window ()
1704 ;; (rc-parse "clg:examples;testgtkrc2")
1705 ;; (rc-parse "clg:examples;testgtkrc")
1707 (let* ((button-specs
1708 '(("button box" create-button-box)
1709 ("buttons" create-buttons)
1710 ("calendar" create-calendar)
1711 ("check buttons" create-check-buttons)
1712 ("color selection" create-color-selection)
1713 ("cursors" create-cursors)
1714 ("dialog" create-dialog)
1716 ("entry" create-entry)
1717 ;; ("event watcher")
1718 ("enxpander" create-expander)
1719 ("file chooser" create-file-chooser)
1720 ("font selection" create-font-selection)
1721 ("handle box" create-handle-box)
1722 ("image" create-image)
1723 ("labels" create-labels)
1724 ("layout" create-layout)
1725 ("list" create-list)
1726 ("menus" create-menus)
1728 ("notebook" create-notebook)
1729 ("panes" create-panes)
1730 ("progress bar" create-progress-bar)
1731 ("radio buttons" create-radio-buttons)
1732 ("range controls" create-range-controls)
1734 ("reparent" create-reparent)
1735 ("rulers" create-rulers)
1736 ;; ("saved position")
1737 ("scrolled windows" create-scrolled-windows)
1738 ("size group" create-size-group)
1739 ("shapes" create-shapes)
1740 ("spinbutton" create-spins)
1741 ("statusbar" create-statusbar)
1742 ("test idle" create-idle-test)
1743 ;; ("test mainloop")
1744 ;; ("test scrolling")
1745 ;; ("test selection")
1746 ("test timeout" create-timeout-test)
1747 ("text" create-text)
1748 ("toggle buttons" create-toggle-buttons)
1749 ("toolbar" create-toolbar-window)
1750 ("tooltips" create-tooltips)
1751 ;; ("tree" #|create-tree|#)
1752 ("UI manager" create-ui-manager)
1754 (main-window (make-instance 'window
1755 :title "testgtk.lisp" :name "main_window"
1756 :default-width 200 :default-height 400
1757 :allow-grow t :allow-shrink nil))
1758 (scrolled-window (make-instance 'scrolled-window
1759 :hscrollbar-policy :automatic
1760 :vscrollbar-policy :automatic
1762 (close-button (make-instance 'button
1763 :label "close" :can-default t
1764 :signal (list 'clicked #'widget-destroy
1765 :object main-window))))
1767 (let ((icon (gdk:pixbuf-load #p"clg:examples;gtk.png")))
1769 (window-icon main-window)
1770 (gdk:pixbuf-add-alpha icon t 254 254 252)))
1773 (make-instance 'v-box
1775 :child-args '(:expand nil)
1776 :child (list (make-instance 'label :label (gtk-version)) :fill nil)
1777 :child (list (make-instance 'label :label "clg CVS version") :fill nil)
1778 :child (list scrolled-window :expand t)
1779 :child (make-instance 'h-separator)
1780 :child (make-instance 'v-box
1781 :homogeneous nil :spacing 10 :border-width 10
1782 :child close-button))
1785 (make-instance 'v-box
1786 :focus-vadjustment (scrolled-window-vadjustment scrolled-window)
1787 :children (mapcar #'(lambda (spec)
1788 (apply #'create-button spec))
1790 (scrolled-window-add-with-viewport scrolled-window content-box))
1792 (widget-grab-focus close-button)
1793 (widget-show-all main-window)
1797 (create-main-window)