-
-;;; Handle box
-
-;; (defun create-handle-box-toolbar ()
-;; (let ((toolbar (toolbar-new :horizontal :both)))
-;; (toolbar-append-item
-;; toolbar "Horizontal" (pixmap-new "clg:examples;test.xpm")
-;; :tooltip-text "Horizontal toolbar layout"
-;; :callback #'(lambda () (setf (toolbar-orientation toolbar) :horizontal)))
-
-;; (toolbar-append-item
-;; toolbar "Vertical" (pixmap-new "clg:examples;test.xpm")
-;; :tooltip-text "Vertical toolbar layout"
-;; :callback #'(lambda () (setf (toolbar-orientation toolbar) :vertical)))
-
-;; (toolbar-append-space toolbar)
-
-;; (toolbar-append-item
-;; toolbar "Icons" (pixmap-new "clg:examples;test.xpm")
-;; :tooltip-text "Only show toolbar icons"
-;; :callback #'(lambda () (setf (toolbar-style toolbar) :icons)))
-
-;; (toolbar-append-item
-;; toolbar "Text" (pixmap-new "clg:examples;test.xpm")
-;; :tooltip-text "Only show toolbar text"
-;; :callback #'(lambda () (setf (toolbar-style toolbar) :text)))
-
-;; (toolbar-append-item
-;; toolbar "Both" (pixmap-new "clg:examples;test.xpm")
-;; :tooltip-text "Show toolbar icons and text"
-;; :callback #'(lambda () (setf (toolbar-style toolbar) :both)))
-
-;; (toolbar-append-space toolbar)
-
-;; (toolbar-append-item
-;; toolbar "Small" (pixmap-new "clg:examples;test.xpm")
-;; :tooltip-text "Use small spaces"
-;; :callback #'(lambda () (setf (toolbar-space-size toolbar) 5)))
-
-;; (toolbar-append-item
-;; toolbar "Big" (pixmap-new "clg:examples;test.xpm")
-;; :tooltip-text "Use big spaces"
-;; :callback #'(lambda () (setf (toolbar-space-size toolbar) 10)))
-
-;; (toolbar-append-space toolbar)
-
-;; (toolbar-append-item
-;; toolbar "Enable" (pixmap-new "clg:examples;test.xpm")
-;; :tooltip-text "Enable tooltips"
-;; :callback #'(lambda () (toolbar-enable-tooltips toolbar)))
-
-;; (toolbar-append-item
-;; toolbar "Disable" (pixmap-new "clg:examples;test.xpm")
-;; :tooltip-text "Disable tooltips"
-;; :callback #'(lambda () (toolbar-disable-tooltips toolbar)))
-
-;; (toolbar-append-space toolbar)
-
-;; (toolbar-append-item
-;; toolbar "Borders" (pixmap-new "clg:examples;test.xpm")
-;; :tooltip-text "Show borders"
-;; :callback #'(lambda () (setf (toolbar-relief toolbar) :normal)))
-
-;; (toolbar-append-item
-;; toolbar "Borderless" (pixmap-new "clg:examples;test.xpm")
-;; :tooltip-text "Hide borders"
-;; :callback #'(lambda () (setf (toolbar-relief toolbar) :none)))
-
-;; toolbar))
-
-
-;; (defun handle-box-child-signal (handle-box child action)
-;; (format t "~S: child ~S ~A~%" handle-box child action))
-
-
-;; (define-test-window create-handle-box "Handle Box Test"
-;; (setf (window-allow-grow-p window) t)
-;; (setf (window-allow-shrink-p window) t)
-;; (setf (window-auto-shrink-p window) nil)
-;; (setf (container-border-width window) 20)
-;; (let ((v-box (v-box-new nil 0)))
-;; (container-add window v-box)
-
-;; (container-add v-box (create-label "Above"))
-;; (container-add v-box (hseparator-new))
-
-;; (let ((hbox (hbox-new nil 10)))
-;; (container-add v-box hbox)
+;; Font selection dialog
+
+(define-toplevel create-font-selection (window "Font Button" :resizable nil)
+ (make-instance 'h-box
+ :parent window :spacing 8 :border-width 8
+ :child (make-instance 'label :label "Pick a font")
+ :child (make-instance 'font-button
+ :use-font t :title "Font Selection Dialog")))
+
+
+;;; Icon View
+
+#+(or cmu sbcl)
+(defun get-directory-listing (directory)
+ (let ((dir #+cmu(unix:open-dir directory)
+ #+sbcl(sb-posix:opendir directory)))
+ (unwind-protect
+ (loop
+ as filename = #+cmu(unix:read-dir dir)
+ #+sbcl(let ((dirent (sb-posix:readdir dir)))
+ (unless (sb-grovel::foreign-nullp dirent)
+ (sb-posix:dirent-name dirent)))
+ while filename
+ collect (let* ((pathname (format nil "~A~A" directory filename))
+ (directory-p
+ #+cmu(eq (unix:unix-file-kind pathname) :directory)
+ #+sbcl(sb-posix:s-isdir (sb-posix:stat-mode (sb-posix:stat pathname)))))
+ (list filename directory-p)))
+ #+cmu(unix:close-dir dir)
+ #+sbcl(sb-posix:closedir dir))))
+
+#+clisp
+(defun get-directory-listing (directory)
+ (nconc
+ (mapcar #'(lambda (entry)
+ (let ((pathname (namestring (first entry))))
+ (list (subseq pathname (1+ (position #\/ pathname :from-end t))) nil)))
+ (directory (format nil "~A*" directory) :full t))
+ (mapcar #'(lambda (entry)
+ (let ((pathname (namestring entry)))
+ (list (subseq pathname (1+ (position #\/ pathname :from-end t :end (1- (length pathname)))) (1- (length pathname))) nil)))
+
+ (directory (format nil "~A*/" directory)))))
+
+
+#?(pkg-config:pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0" :error nil)
+(let ((file-pixbuf nil)
+ (folder-pixbuf nil))
+ (defun load-pixbufs ()
+ (unless file-pixbuf
+ (handler-case
+ (setf
+ file-pixbuf (gdk:pixbuf-load #p"/usr/share/icons/gnome/48x48/filesystems/gnome-fs-regular.png")
+ folder-pixbuf (gdk:pixbuf-load #p"/usr/share/icons/gnome/48x48/filesystems/gnome-fs-directory.png"))
+ (glib:glib-error (condition)
+ (make-instance 'message-dialog
+ :message-type :error :visible t
+ :text "<b>Failed to load an image</b>"
+ :secondary-text (glib:gerror-message condition)
+ :signal (list :close #'widget-destroy :object t))
+ (return-from load-pixbufs nil))))
+ t)
+
+ (defun fill-store (store directory)
+ (list-store-clear store)
+ (loop
+ for (filename directory-p) in (get-directory-listing directory)
+ unless (or (string= filename ".") (string= filename ".."))
+ do (list-store-insert store 0
+ (vector
+ filename
+ (if directory-p folder-pixbuf file-pixbuf)
+ directory-p))))
+
+ (defun sort-func (store a b)
+ (let ((a-dir-p (tree-model-value store a 'directory-p))
+ (b-dir-p (tree-model-value store b 'directory-p))
+ (a-name (tree-model-value store a 'filename))
+ (b-name (tree-model-value store b 'filename)))
+ (cond
+ ((and a-dir-p (not b-dir-p)) :before)
+ ((and (not a-dir-p) b-dir-p) :after)
+ ((string< a-name b-name) :before)
+ ((string> a-name b-name) :after)
+ (t :equal))))
+
+
+ (defun parent-dir (dir)
+ (let ((end (1+ (position #\/ dir :from-end t :end (1- (length dir))))))
+ (subseq dir 0 end)))
+
+ (define-toplevel create-icon-view (window "Icon View demo"
+ :default-width 650
+ :default-height 400)
+ (if (not (load-pixbufs))
+ (widget-destroy window)
+ (let* ((directory "/")
+ (store (make-instance 'list-store
+ :column-types '(string gdk:pixbuf boolean)
+ :column-names '(filename pixbuf directory-p)))
+ (icon-view (make-instance 'icon-view
+ :model store :selection-mode :multiple
+ :text-column 'filename
+ :pixbuf-column 'pixbuf))
+ (up (make-instance 'tool-button
+ :stock "gtk-go-up" :is-important t :sensitive nil))
+ (home (make-instance 'tool-button
+ :stock "gtk-home" :is-important t)))
+ (tree-sortable-set-sort-func store :default #'sort-func)
+ (tree-sortable-set-sort-column store :default :ascending)
+ (fill-store store directory)
+
+ (signal-connect icon-view 'item-activated
+ #'(lambda (path)
+ (when (tree-model-value store path 'directory-p)
+ (setq directory
+ (concatenate 'string directory (tree-model-value store path 'filename) "/"))
+ (fill-store store directory)
+ (setf (widget-sensitive-p up) t))))
+
+ (signal-connect up 'clicked
+ #'(lambda ()
+ (unless (string= directory "/")
+ (setq directory (parent-dir directory))
+ (fill-store store directory)
+ (setf
+ (widget-sensitive-p home)
+ (not (string= directory (namestring (truename #p"clg:")))))
+ (setf (widget-sensitive-p up) (not (string= directory "/"))))))
+
+ (signal-connect home 'clicked
+ #'(lambda ()
+ (setq directory (namestring (truename #p"clg:")))
+ (fill-store store directory)
+ (setf (widget-sensitive-p up) t)
+ (setf (widget-sensitive-p home) nil)))