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.24 2005-03-06 17:12:22 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" :resizable nil)
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 (multiple-value-bind (sec min hour date month year day daylight-p zone)
1228 (declare (ignore sec min hour day daylight-p zone))
1229 (make-instance 'frame
1230 :label "Not accelerated" :parent main
1231 :child (make-instance 'h-box
1233 :child-args '(:padding 5)
1234 :child (create-date-spinner "Day : "
1235 (adjustment-new date 1 31 1 5 0) :out)
1236 :child (create-date-spinner "Month : "
1237 (adjustment-new month 1 12 1 5 0) :etched-in)
1238 :child (create-date-spinner "Year : "
1239 (adjustment-new year 0 2100 1 100 0) :in)))))
1241 (let ((spinner1 (make-instance 'spin-button
1242 :adjustment (adjustment-new 0.0 -10000.0 10000.0 0.5 100.0 0.0)
1243 :climb-rate 1.0 :digits 2 :wrap t :width-request 100))
1244 (spinner2 (make-instance 'spin-button
1245 :adjustment (adjustment-new 2.0 1.0 5.0 1.0 1.0 0.0)
1246 :climb-rate 1.0 :wrap t))
1247 (value-label (make-instance 'label :label "0")))
1248 (signal-connect (spin-button-adjustment spinner2) 'value-changed
1251 (spin-button-digits spinner1)
1252 (floor (spin-button-value spinner2)))))
1254 (make-instance 'frame
1255 :label "Accelerated" :parent main
1256 :child (make-instance 'v-box
1259 (make-instance 'h-box
1260 :child-args '(:padding 5)
1261 :child (make-instance 'v-box
1262 :child (make-instance 'label
1264 :xalign 0.0 :yalign 0.5)
1266 :child (make-instance 'v-box
1267 :child (make-instance 'label
1269 :xalign 0.0 :yalign 0.5)
1271 :expand nil :padding 5)
1272 :child (make-instance 'check-button
1273 :label "Snap to 0.5-ticks" :active t
1274 :signal (list 'clicked
1277 (spin-button-snap-to-ticks-p spinner1)
1278 (toggle-button-active-p button)))
1280 :child (make-instance 'check-button
1281 :label "Numeric only input mode" :active t
1282 :signal (list 'clicked
1285 (spin-button-numeric-p spinner1)
1286 (toggle-button-active-p button)))
1290 (make-instance 'h-box
1291 :child-args '(:padding 5)
1292 :child (make-instance 'button
1293 :label "Value as Int"
1294 :signal (list 'clicked
1297 (label-label value-label)
1299 (spin-button-value-as-int
1301 :child (make-instance 'button
1302 :label "Value as Float"
1303 :signal (list 'clicked
1306 (label-label value-label)
1308 (format nil "~~,~DF"
1309 (spin-button-digits spinner1))
1310 (spin-button-value spinner1)))))))
1311 :padding 5 :expand nil))))
1312 (widget-show-all main)))
1317 (define-toplevel create-statusbar (window "Statusbar")
1318 (let ((statusbar (make-instance 'statusbar :has-resize-grip t))
1319 (close-button (create-button '("close" :can-default t)
1320 #'widget-destroy :object window))
1323 (signal-connect statusbar 'text-popped
1324 #'(lambda (context-id text)
1325 (declare (ignore context-id))
1326 (format nil "Popped: ~A~%" text)))
1328 (make-instance 'v-box
1330 :child (make-instance 'v-box
1331 :border-width 10 :spacing 10
1332 :child (create-button "push something"
1334 (statusbar-push statusbar 1
1335 (format nil "something ~D" (incf counter)))))
1336 :child (create-button "pop"
1338 (statusbar-pop statusbar 1)))
1339 :child (create-button "steal #4"
1341 (statusbar-remove statusbar 1 4)))
1342 :child (create-button "dump stack")
1343 :child (create-button "test contexts"))
1344 :child (list (make-instance 'h-separator) :expand nil)
1346 (make-instance 'v-box :border-width 10 :child close-button)
1348 :child (list statusbar :expand nil))
1350 (widget-grab-focus close-button)))
1355 (define-simple-dialog create-idle-test (dialog "Idle Test")
1356 (let ((label (make-instance 'label
1357 :label "count: 0" :xpad 10 :ypad 10))
1360 (signal-connect dialog 'destroy
1361 #'(lambda () (when idle (idle-remove idle))))
1363 (make-instance 'v-box
1364 :parent dialog :border-width 10 :spacing 10
1366 :child (make-instance 'frame
1367 :label "Label Container" :border-width 5
1368 :child(make-instance 'v-box
1369 :children (make-radio-group 'radio-button
1370 '((:label "Resize-Parent" :value :parent :active t)
1371 (:label "Resize-Queue" :value :queue)
1372 (:label "Resize-Immediate" :value :immediate))
1375 (container-resize-mode (dialog-action-area dialog)) mode))))))
1377 (dialog-add-button dialog "Start"
1384 (setf (label-label label) (format nil "count: ~D" count))
1387 (dialog-add-button dialog "Stop"
1391 (setq idle nil))))))
1397 (define-simple-dialog create-timeout-test (dialog "Timeout Test")
1398 (let ((label (make-instance 'label
1399 :label "count: 0" :xpad 10 :ypad 10 :parent dialog :visible t))
1402 (signal-connect dialog 'destroy
1403 #'(lambda () (when timer (timeout-remove timer))))
1405 (dialog-add-button dialog "Start"
1412 (setf (label-label label) (format nil "count: ~D" count))
1415 (dialog-add-button dialog "Stop"
1418 (timeout-remove timer)
1419 (setq timer nil))))))
1424 (define-simple-dialog create-text (dialog "Text" :default-width 400
1425 :default-height 400)
1426 (let* ((text-view (make-instance 'text-view
1427 :border-width 10 :visible t :wrap-mode :word))
1428 (buffer (text-view-buffer text-view))
1431 (text-buffer-create-tag buffer "Bold" :weight :bold)
1432 (text-buffer-create-tag buffer "Italic" :style :italic)
1433 (text-buffer-create-tag buffer "Underline" :underline :single)
1435 (flet ((create-toggle-callback (tag-name)
1436 (let ((tag (text-tag-table-lookup
1437 (text-buffer-tag-table buffer) tag-name)))
1439 (unless (eq (and (find tag active-tags) t) active)
1442 (push tag active-tags)
1443 (setq active-tags (delete tag active-tags)))
1444 (multiple-value-bind (non-zero-p start end)
1445 (text-buffer-get-selection-bounds buffer)
1446 (declare (ignore non-zero-p))
1448 (text-buffer-apply-tag buffer tag start end)
1449 (text-buffer-remove-tag buffer tag start end))))))))
1452 (make-instance 'action-group
1453 :action (create-toggle-action
1454 "Bold" "gtk-bold" "Bold" "<control>B" "Bold" nil
1455 (create-toggle-callback "Bold"))
1456 :action (create-toggle-action
1457 "Italic" "gtk-italic" "Italic" "<control>I" "Italic" nil
1458 (create-toggle-callback "Italic"))
1459 :action (create-toggle-action
1460 "Underline" "gtk-underline" "Underline" "<control>U" "Underline" nil
1461 (create-toggle-callback "Underline"))))
1462 (ui (make-instance 'ui-manager)))
1464 (ui-manager-insert-action-group ui actions)
1465 (ui-manager-add-ui ui
1466 '((:toolbar "ToolBar"
1468 (:toolitem "Italic")
1469 (:toolitem "Underline"))))
1471 ;; Callback to activate/deactivate toolbar buttons when cursor
1473 (signal-connect buffer 'mark-set
1474 #'(lambda (location mark)
1475 (declare (ignore mark))
1476 (text-tag-table-foreach (text-buffer-tag-table buffer)
1481 (text-iter-has-tag-p location tag)
1482 (not (text-iter-begins-tag-p location tag)))
1483 (text-iter-ends-tag-p location tag))))
1484 (unless (eq active (and (find tag active-tags) t))
1486 (push tag active-tags)
1487 (setq active-tags (delete tag active-tags)))
1489 (toggle-action-active-p
1490 (action-group-get-action actions (text-tag-name tag)))
1493 ;; Callback to apply active tags when a character is inserted
1494 (signal-connect buffer 'insert-text
1495 #'(lambda (iter &rest args)
1496 (declare (ignore args))
1497 (let ((before (text-buffer-get-iter-at-offset buffer
1498 (1- (text-iter-offset iter)))))
1500 for tag in active-tags
1501 do (text-buffer-apply-tag buffer tag before iter))))
1504 (container-add dialog (ui-manager-get-widget ui "/ToolBar") :expand nil)
1505 (container-add dialog text-view)))))
1510 (define-simple-dialog create-toggle-buttons (dialog "Toggle Button")
1511 (make-instance 'v-box
1512 :border-width 10 :spacing 10 :parent dialog
1515 collect (make-instance 'toggle-button
1516 :label (format nil "Button~D" (1+ n))))))
1522 (defun create-toolbar (window)
1523 (make-instance 'toolbar
1524 :show-tooltips t :show-arrow nil
1526 ;; Insert a stock item
1527 :child (make-instance 'tool-button
1529 :tip-text "Destroy toolbar"
1530 :tip-private "Toolbar/Quit"
1531 :signal (list 'clicked #'(lambda () (widget-destroy window))))
1533 :child (make-instance 'separator-tool-item)
1535 :child (make-instance 'tool-button
1536 :label "Horizontal" :stock "gtk-go-forward"
1537 :tip-text "Horizontal toolbar layout"
1538 :tip-private "Toolbar/Horizontal"
1539 :signal (list 'clicked
1541 (setf (toolbar-orientation toolbar) :horizontal))
1544 :child (make-instance 'tool-button
1545 :label "Vertical" :stock "gtk-go-down"
1546 :tip-text "Vertical toolbar layout"
1547 :tip-private "Toolbar/Vertical"
1548 :signal (list 'clicked
1550 (setf (toolbar-orientation toolbar) :vertical))
1553 :child (make-instance 'separator-tool-item)
1555 :children (make-radio-group 'radio-tool-button
1556 '((:label "Icons" :stock "gtk-justify-left"
1557 :tip-text "Only show toolbar icons"
1558 :tip-private "Toolbar/IconsOnly"
1560 (:label "Both" :stock "gtk-justify-center"
1561 :tip-text "Show toolbar icons and text"
1562 :tip-private "Toolbar/Both"
1563 :value :both :active t)
1564 (:label "Text" :stock "gtk-justify-right"
1565 :tip-text "Show toolbar text"
1566 :tip-private "Toolbar/TextOnly"
1569 #'(lambda (toolbar style)
1570 (setf (toolbar-style toolbar) style))
1573 :child (make-instance 'separator-tool-item)
1575 :child (make-instance 'tool-item
1576 :child (make-instance 'entry)
1577 :tip-text "This is an unusable GtkEntry"
1578 :tip-private "Hey don't click me!")
1580 :child (make-instance 'separator-tool-item)
1582 :child (make-instance 'tool-button
1583 :label "Enable" :stock "gtk-add"
1584 :tip-text "Enable tooltips"
1585 :tip-private "Toolbar/EnableTooltips"
1586 :signal (list 'clicked
1588 (setf (toolbar-show-tooltips-p toolbar) t))
1591 :child (make-instance 'tool-button
1592 :label "Disable" :stock "gtk-remove"
1593 :tip-text "Disable tooltips"
1594 :tip-private "Toolbar/DisableTooltips"
1595 :signal (list 'clicked
1597 (setf (toolbar-show-tooltips-p toolbar) nil))
1600 ;; :child (make-instance 'separator-tool-item)
1602 ;; :child (make-instance 'tool-button
1603 ;; :label "GTK" :icon #p"clg:examples;gtk.png"
1604 ;; :tip-text "GTK+ Logo"
1605 ;; :tip-private "Toolbar/GTK+")
1608 (define-toplevel create-toolbar-window (window "Toolbar test" :resizable nil)
1609 (container-add window (create-toolbar window)))
1615 (define-simple-dialog create-tooltips (dialog "Tooltips" :default-width 200)
1616 (let ((tooltips (make-instance 'tooltips)))
1617 (flet ((create-button (label tip-text tip-private)
1618 (let ((button (make-instance 'toggle-button :label label)))
1619 (tooltips-set-tip tooltips button tip-text tip-private)
1621 (make-instance 'v-box
1622 :parent dialog :border-width 10 :spacing 10
1623 :child (create-button "button1" "This is button 1" "ContextHelp/button/1")
1624 :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")))))
1629 (defvar *ui-description*
1630 '((:menubar "MenuBar"
1635 (:menuitem "SaveAs")
1638 (:menu "PreferencesMenu"
1644 (:menuitem "Square")
1645 (:menuitem "Rectangle")
1649 (:menuitem "About")))
1654 (:toolitem "Logo"))))
1656 (define-toplevel create-ui-manager (window "UI Manager")
1658 (make-instance 'action-group
1660 :action (create-action "FileMenu" nil "_File")
1661 :action (create-action "PreferencesMenu" nil "_Preferences")
1662 :action (create-action "ColorMenu" nil "_Color")
1663 :action (create-action "ShapeMenu" nil "_Shape")
1664 :action (create-action "HelpMenu" nil "_Help")
1665 :action (create-action "New" "gtk-new" "_New" "<control>N" "Create a new file")
1666 :action (create-action "Open" "gtk-open" "_Open" "<control>O" "Open a file" #'create-file-chooser)
1667 :action (create-action "Save" "gtk-save" "_Save" "<control>S" "Save current file")
1668 :action (create-action "SaveAs" "gtk-save" "Save _As..." "" "Save to a file")
1669 :action (create-action "Quit" "gtk-quit" "_Quit" "<control>Q" "Quit" (list #'widget-destroy :object window))
1670 :action (create-action "About" nil "_About" "<control>A" "About")
1671 :action (create-action "Logo" "demo-gtk-logo" "" nil "GTK+")
1672 :action (create-toggle-action "Bold" "gtk-bold" "_Bold" "<control>B" "Bold" t)
1673 :actions (create-radio-actions
1674 '(("Red" nil "_Red" "<control>R" "Blood")
1675 ("Green" nil "_Green" "<control>G" "Grass")
1676 ("Blue" nil "_Blue" "<control>B" "Sky"))
1678 :actions (create-radio-actions
1679 '(("Square" nil "_Square" "<control>S" "Square")
1680 ("Rectangle" nil "_Rectangle" "<control>R" "Rectangle")
1681 ("Oval" nil "_Oval" "<control>O" "Egg")))))
1682 (ui (make-instance 'ui-manager)))
1684 (ui-manager-insert-action-group ui actions)
1685 (ui-manager-add-ui ui *ui-description*)
1687 (window-add-accel-group window (ui-manager-accel-group ui))
1689 (make-instance 'v-box
1692 (ui-manager-get-widget ui "/MenuBar")
1693 :expand nil :fill nil)
1695 (ui-manager-get-widget ui "/ToolBar")
1696 :expand nil :fill nil)
1697 :child (make-instance 'label
1698 :label "Type <alt> to start"
1699 :xalign 0.5 :yalign 0.5
1700 :width-request 200 :height-request 200))))
1706 (defun create-main-window ()
1707 ;; (rc-parse "clg:examples;testgtkrc2")
1708 ;; (rc-parse "clg:examples;testgtkrc")
1710 (let* ((button-specs
1711 '(("button box" create-button-box)
1712 ("buttons" create-buttons)
1713 ("calendar" create-calendar)
1714 ("check buttons" create-check-buttons)
1715 ("color selection" create-color-selection)
1716 ("cursors" create-cursors)
1717 ("dialog" create-dialog)
1719 ("entry" create-entry)
1720 ;; ("event watcher")
1721 ("enxpander" create-expander)
1722 ("file chooser" create-file-chooser)
1723 ("font selection" create-font-selection)
1724 ("handle box" create-handle-box)
1725 ("image" create-image)
1726 ("labels" create-labels)
1727 ("layout" create-layout)
1728 ("list" create-list)
1729 ("menus" create-menus)
1731 ("notebook" create-notebook)
1732 ("panes" create-panes)
1733 ("progress bar" create-progress-bar)
1734 ("radio buttons" create-radio-buttons)
1735 ("range controls" create-range-controls)
1737 ("reparent" create-reparent)
1738 ("rulers" create-rulers)
1739 ;; ("saved position")
1740 ("scrolled windows" create-scrolled-windows)
1741 ("size group" create-size-group)
1742 ("shapes" create-shapes)
1743 ("spinbutton" create-spins)
1744 ("statusbar" create-statusbar)
1745 ("test idle" create-idle-test)
1746 ;; ("test mainloop")
1747 ;; ("test scrolling")
1748 ;; ("test selection")
1749 ("test timeout" create-timeout-test)
1750 ("text" create-text)
1751 ("toggle buttons" create-toggle-buttons)
1752 ("toolbar" create-toolbar-window)
1753 ("tooltips" create-tooltips)
1754 ;; ("tree" #|create-tree|#)
1755 ("UI manager" create-ui-manager)
1757 (main-window (make-instance 'window
1758 :title "testgtk.lisp" :name "main_window"
1759 :default-width 200 :default-height 400
1760 :allow-grow t :allow-shrink nil))
1761 (scrolled-window (make-instance 'scrolled-window
1762 :hscrollbar-policy :automatic
1763 :vscrollbar-policy :automatic
1765 (close-button (make-instance 'button
1766 :label "close" :can-default t
1767 :signal (list 'clicked #'widget-destroy
1768 :object main-window))))
1770 (let ((icon (gdk:pixbuf-load #p"clg:examples;gtk.png")))
1772 (window-icon main-window)
1773 (gdk:pixbuf-add-alpha icon t 254 254 252)))
1776 (make-instance 'v-box
1778 :child-args '(:expand nil)
1779 :child (list (make-instance 'label :label (gtk-version)) :fill nil)
1780 :child (list (make-instance 'label :label "clg CVS version") :fill nil)
1781 :child (list (make-instance 'label
1782 :label #-cmu(format nil "~A (~A)"
1783 (lisp-implementation-type)
1784 (lisp-implementation-version))
1785 ;; The version string in CMUCL is far too long
1786 #+cmu(lisp-implementation-type))
1788 :child (list scrolled-window :expand t)
1789 :child (make-instance 'h-separator)
1790 :child (make-instance 'v-box
1791 :homogeneous nil :spacing 10 :border-width 10
1792 :child close-button))
1795 (make-instance 'v-box
1796 :focus-vadjustment (scrolled-window-vadjustment scrolled-window)
1797 :children (mapcar #'(lambda (spec)
1798 (apply #'create-button spec))
1800 (scrolled-window-add-with-viewport scrolled-window content-box))
1802 (widget-grab-focus close-button)
1803 (widget-show-all main-window)
1807 (create-main-window)