2 (:use :cl :gtk :gdk :gobject)
13 #:test-treeview-list))
15 (in-package :gtk-demo)
18 (let ((window (make-instance 'gtk-window :type :toplevel :app-paintable t))
20 (g-signal-connect window "destroy" (lambda (widget)
23 (g-signal-connect window "motion-notify-event" (lambda (widget event)
25 (setf x (event-motion-x event)
26 y (event-motion-y event))
27 (gtk-widget-queue-draw window)))
28 (g-signal-connect window "expose-event"
29 (lambda (widget event)
30 (declare (ignore event))
33 (using* ((gdk-window (widget-window window))
34 (gc (gdk-gc-new gdk-window))
35 (layout (gtk-widget-create-pango-layout window (format nil "X: ~F~%Y: ~F" x y))))
36 (gdk-draw-layout gdk-window gc 0 0 layout)
37 (gdk-gc-set-rgb-fg-color gc (make-color :red 65535 :green 0 :blue 0))
38 (multiple-value-bind (x y) (drawable-get-size gdk-window)
39 (gdk-draw-line gdk-window gc 0 0 x y)))))
40 (g-signal-connect window "configure-event"
41 (lambda (widget event)
42 (declare (ignore event))
44 (gtk-widget-queue-draw window)))
45 (gtk-widget-show-all window)
46 (push :pointer-motion-mask (gdk-window-events (widget-window window)))
51 (using* ((window (make-instance 'gtk-window :type :toplevel :title "Testing entry" :border-width 10))
52 (box (make-instance 'v-box))
53 (entry (make-instance 'entry))
54 (button (make-instance 'button :label "OK"))
55 (text-buffer (make-instance 'text-buffer))
56 (text-view (make-instance 'text-view :buffer text-buffer))
57 (button-select (make-instance 'button :label "Select"))
58 (button-insert (make-instance 'button :label "Insert")))
59 (box-pack-start box (make-instance 'label :label "Enter <b>anything</b> you wish:" :use-markup t) :expand nil)
60 (box-pack-start box entry :expand nil)
61 (box-pack-start box button :expand nil)
62 (box-pack-start box button-select :expand nil)
63 (box-pack-start box button-insert :expand nil)
64 (using* ((w (make-instance 'scrolled-window)))
65 (box-pack-start box w)
66 (container-add w text-view))
67 (container-add window box)
68 (g-signal-connect window "destroy" (lambda (widget) (release widget) (gtk-main-quit)))
69 (g-signal-connect window "delete-event" (lambda (widget event)
70 (declare (ignore event))
72 (using (dlg (make-instance 'message-dialog :text "Are you sure?" :buttons :yes-no))
73 (let ((response (dialog-run dlg)))
75 (not (eq :yes response))))))
76 (g-signal-connect button "clicked" (lambda (button) (release button)
77 (setf (text-buffer-text text-buffer)
78 (format nil "~A~%~A" (text-buffer-text text-buffer) (entry-text entry))
79 (entry-text entry) "")))
80 (g-signal-connect button-select "clicked" (lambda (button) (release button)
81 (editable-select-region entry 5 10)))
82 (g-signal-connect button-insert "clicked" (lambda (button) (release button)
83 (editable-insert-text entry "hello" 2)))
84 (gtk-widget-show-all window)
87 (defun table-packing ()
88 (using* ((window (make-instance 'gtk-window :type :toplevel :title "Table packing" :border-width 20))
89 (table (make-instance 'table :n-rows 2 :n-columns 2 :homogeneous t))
90 (button-1 (make-instance 'button :label "Button 1"))
91 (button-2 (make-instance 'button :label "Button 2"))
92 (button-q (make-instance 'button :label "Quit")))
93 (container-add window table)
94 (table-attach table button-1 0 1 0 1)
95 (table-attach table button-2 1 2 0 1)
96 (table-attach table button-q 0 2 1 2)
97 (g-signal-connect window "destroy" (lambda (w) (release w) (gtk-main-quit)))
98 (g-signal-connect button-q "clicked" (lambda (b) (release b) (object-destroy window)))
99 (gtk-widget-show-all window)
102 (defun test-pixbuf ()
103 (using* ((window (make-instance 'gtk-window :title "Test pixbuf" :request-width 600 :request-height 240))
104 (vbox (make-instance 'v-box))
105 (eventbox (make-instance 'event-box))
106 (vbox-1 (make-instance 'v-box)))
107 (container-add window vbox)
108 (box-pack-start vbox (make-instance 'label :text "Placing bg image" :font "Times New Roman Italic 10" :color "#00f" :request-height 40))
109 (g-signal-connect window "destroy" (lambda (w) (release w) (gtk-main-quit)))
110 (box-pack-start vbox eventbox)
111 (container-add eventbox vbox-1)
112 (box-pack-start vbox-1 (make-instance 'label :text "This is the eventbox"))
113 (box-pack-start vbox-1 (make-instance 'label :text "The green ball is the bg"))
114 (gtk-widget-show-all window)
118 (using*((window (make-instance 'gtk-window :title "Test images"))
119 (image (make-instance 'image :icon-name "applications-development" :icon-size 6)))
120 (container-add window image)
121 (g-signal-connect window "destroy" (lambda (w) (release w) (gtk-main-quit)))
122 (gtk-widget-show-all window)
125 (defun test-progress-bar ()
126 (using* ((window (make-instance 'gtk-window :title "Test progress bar"))
127 (v-box (make-instance 'v-box))
128 (p-bar (make-instance 'progress-bar :test "A process"))
129 (button-pulse (make-instance 'button :label "Pulse"))
130 (button-set (make-instance 'button :label "Set"))
131 (entry (make-instance 'entry)))
132 (g-signal-connect window "destroy" (lambda (w) (release w) (gtk-main-quit)))
133 (container-add window v-box)
134 (box-pack-start v-box p-bar)
135 (box-pack-start v-box button-pulse)
136 (box-pack-start v-box button-set)
137 (box-pack-start v-box entry)
138 (g-signal-connect button-pulse "clicked" (lambda (w) (release w) (progress-bar-pulse p-bar)))
139 (g-signal-connect button-set "clicked" (lambda (w) (release w)
140 (setf (progress-bar-fraction p-bar)
141 (coerce (read-from-string (entry-text entry)) 'real))))
142 (gtk-widget-show-all window)
145 (defun test-status-bar ()
146 (using* ((window (make-instance 'gtk-window :title "Text status bar"))
147 (v-box (make-instance 'v-box))
148 (h-box (make-instance 'h-box))
149 (label (make-instance 'label :label "Test of status bar" :xalign 0.5 :yalign 0.5))
150 (status-bar (make-instance 'statusbar :has-resize-grip t))
151 (button-push (make-instance 'button :label "Push"))
152 (button-pop (make-instance 'button :label "Pop"))
153 (entry (make-instance 'entry))
154 (icon (make-instance 'status-icon :icon-name "applications-development")))
155 (set-status-icon-tooltip icon "An icon from lisp program")
156 (g-signal-connect window "destroy" (lambda (w) (release w)
157 #+ (or) (setf (status-icon-visible icon) nil)
159 (g-signal-connect button-push "clicked" (lambda (b) (release b) (status-bar-push status-bar "lisp-prog" (entry-text entry))))
160 (g-signal-connect button-pop "clicked" (lambda (b) (release b) (status-bar-pop status-bar "lisp-prog")))
161 (g-signal-connect icon "activate" (lambda (i) (release i)
162 (using (message-dialog (make-instance 'message-dialog :buttons :ok :text "You clicked on icon!"))
163 (dialog-run message-dialog)
164 (object-destroy message-dialog))))
165 (container-add window v-box)
166 (box-pack-start v-box h-box :expand nil)
167 (box-pack-start h-box entry)
168 (box-pack-start h-box button-push :expand nil)
169 (box-pack-start h-box button-pop :expand nil)
170 (box-pack-start v-box label)
171 (box-pack-start v-box status-bar :expand nil)
172 (gtk-widget-show-all window)
173 (setf (status-icon-screen icon) (gtk-window-screen window))
176 (defun test-scale-button ()
177 (using* ((window (make-instance 'gtk-window :type :toplevel :title "Testing scale button"))
178 (button (make-instance 'scale-button :icons (list "media-seek-backward" "media-seek-forward" "media-playback-stop" "media-playback-start") :adjustment (make-instance 'adjustment :lower -40 :upper 50 :value 20))))
179 (g-signal-connect window "destroy" (lambda (w) (release w) (gtk-main-quit)))
180 (container-add window button)
181 (gtk-widget-show-all window)
184 (defun test-text-view ()
185 (using* ((window (make-instance 'gtk-window :type :toplevel :title "Testing text view" :width-request 400 :height-request 300))
186 (button (make-instance 'button :label "Do"))
187 (bold-btn (make-instance 'button :label "Bold"))
188 (buffer (make-instance 'text-buffer :text "Some text buffer with some text inside"))
189 (v (make-instance 'text-view :buffer buffer :wrap-mode :word))
190 (box (make-instance 'v-box))
191 (scrolled (make-instance 'scrolled-window :hscrollbar-policy :automatic :vscrollbar-policy :automatic)))
192 (g-signal-connect window "destroy" (lambda (w) (release w) (gtk-main-quit)))
193 (g-signal-connect button "clicked" (lambda (b)
195 (using* ((i1 (make-instance 'text-iter))
196 (i2 (make-instance 'text-iter)))
197 (multiple-value-bind (i1 i2) (text-buffer-get-selection-bounds buffer)
199 (using* ((i1 i1) (i2 i2)
200 (dialog (make-instance 'message-dialog :buttons :ok)))
201 (setf (message-dialog-text dialog) (format nil "selection: from (~A,~A) to (~A,~A)"
202 (text-iter-line i1) (text-iter-line-offset i1)
203 (text-iter-line i2) (text-iter-line-offset i2)))
205 (object-destroy dialog)))))))
206 (g-signal-connect bold-btn "clicked" (Lambda (b)
208 (multiple-value-bind (start end) (text-buffer-get-selection-bounds buffer)
209 (when (and start end)
210 (using* ((start start) (end end) (tag (text-tag-table-lookup (text-buffer-tag-table buffer) "bold")))
211 (if (text-iter-has-tag start tag)
212 (text-buffer-remove-tag buffer tag start end)
213 (text-buffer-apply-tag buffer tag start end)))))))
214 (let ((tag (make-instance 'text-tag :name "bold" :weight 700)))
215 (text-tag-table-add (text-buffer-tag-table buffer) tag)
216 (g-signal-connect tag "event"
217 (lambda (tag object event iter)
218 (declare (ignore tag object iter))
219 (when (eq (event-type event) :button-release)
220 (using (dlg (make-instance 'message-dialog :text "You clicked on bold text." :buttons :ok))
222 (object-destroy dlg))))))
223 (container-add window box)
224 (container-add scrolled v)
225 (box-pack-start box button :expand nil)
226 (box-pack-start box bold-btn :expand nil)
227 (box-pack-start box scrolled)
228 (gtk-widget-show-all window)
231 (defun demo-code-editor ()
232 (using* ((window (make-instance 'gtk-window :type :toplevel :title "Code editor" :width-request 400 :height-request 400 :window-position :center))
233 (scrolled (make-instance 'scrolled-window :hscrollbar-policy :automatic :vscrollbar-policy :automatic))
234 (buffer (make-instance 'text-buffer))
235 (view (make-instance 'text-view :buffer buffer)))
236 (g-signal-connect window "destroy" (lambda (w) (release w) (gtk-main-quit)))
237 (container-add window scrolled)
238 (container-add scrolled view)
239 (gtk-widget-show-all window)
240 (g-signal-connect buffer "insert-text" (lambda (buffer location text len)
241 (using* ((buffer buffer) (location location))
242 (format t "~A~%" (list buffer location text len)))))
245 (defstruct tvi title value)
247 (defun test-treeview-list ()
248 (let* ((window (make-instance 'gtk-window :type :toplevel :title "Treeview (list)"))
249 (model (make-instance 'array-list-store))
250 (scroll (make-instance 'scrolled-window :hscrollbar-policy :automatic :vscrollbar-policy :automatic))
251 (tv (make-instance 'tree-view :headers-visible t :width-request 100 :height-request 400 :rules-hint t))
252 (h-box (make-instance 'h-box))
253 (v-box (make-instance 'v-box))
254 (title-entry (make-instance 'entry))
255 (value-entry (make-instance 'entry))
256 (button (make-instance 'button :label "Add")))
257 (store-add-column model "gchararray" #'tvi-title)
258 (store-add-column model "gint" #'tvi-value)
259 (store-add-item model (make-tvi :title "Monday" :value 1))
260 (store-add-item model (make-tvi :title "Tuesday" :value 2))
261 (store-add-item model (make-tvi :title "Wednesday" :value 3))
262 (store-add-item model (make-tvi :title "Thursday" :value 4))
263 (store-add-item model (make-tvi :title "Friday" :value 5))
264 (store-add-item model (make-tvi :title "Saturday" :value 6))
265 (store-add-item model (make-tvi :title "Sunday" :value 7))
266 (setf (tree-view-model tv) model (tree-view-tooltip-column tv) 0)
267 (gobject:g-signal-connect window "destroy" (lambda (w) (gobject:release w) (gtk-main-quit)))
268 (gobject:g-signal-connect button "clicked" (lambda (b) (gobject:release b)
269 (store-add-item model (make-tvi :title (entry-text title-entry)
270 :value (or (parse-integer (entry-text value-entry)
273 (g-signal-connect tv "row-activated" (lambda (tv path column)
274 (release* tv path column)
275 (format t "You clicked on row ~A~%" (tree-path-indices path))))
276 (container-add window v-box)
277 (box-pack-start v-box h-box :expand nil)
278 (box-pack-start h-box title-entry :expand nil)
279 (box-pack-start h-box value-entry :expand nil)
280 (box-pack-start h-box button :expand nil)
281 (box-pack-start v-box scroll)
282 (container-add scroll tv)
283 (let ((column (make-instance 'tree-view-column :title "Title" :sort-column-id 0))
284 (renderer (make-instance 'cell-renderer-text :text "A text")))
285 (tree-view-column-pack-start column renderer)
286 (tree-view-column-add-attribute column renderer "text" 0)
287 (tree-view-append-column tv column)
288 (print (tree-view-column-tree-view column))
289 (print (tree-view-column-cell-renderers column)))
290 (let ((column (make-instance 'tree-view-column :title "Value"))
291 (renderer (make-instance 'cell-renderer-text :text "A text")))
292 (tree-view-column-pack-start column renderer)
293 (tree-view-column-add-attribute column renderer "text" 1)
294 (tree-view-append-column tv column)
295 (print (tree-view-column-tree-view column))
296 (print (tree-view-column-cell-renderers column)))
297 (gtk-widget-show-all window)