Add GtkEntryCompletion documentation
[cl-gtk2.git] / gtk / gtk.widget.lisp
bloba70ec15e704c0547a18577a82b28ad962ea07961
1 (in-package :gtk)
3 ; TODO: GtkWidget
5 (defun widget-flags (widget)
6 (convert-from-foreign (gtk-object-flags-as-integer widget) 'widget-flags))
8 (defun (setf widget-flags) (new-value widget)
9 (setf (gtk-object-flags-as-integer widget)
10 (convert-to-foreign new-value 'widget-flags))
11 new-value)
13 (export 'widget-flags)
15 (defcstruct %gtk-requisition
16 (:width :int)
17 (:height :int))
19 (defcstruct %gtk-allocation
20 (:x :int)
21 (:y :int)
22 (:width :int)
23 (:height :int))
25 (defcstruct %gtk-widget
26 (:object %gtk-object)
27 (:private-flags :uint16)
28 (:state state-type)
29 (:saved-state state-type)
30 (:name (:pointer :char))
31 (:style :pointer)
32 (:requisition %gtk-requisition)
33 (:allocation %gtk-allocation)
34 (:window :pointer)
35 (:parent :pointer))
37 (defun widget-state (widget)
38 (foreign-slot-value (pointer widget) '%gtk-widget :state))
40 (export 'widget-state)
41 (defun widget-saved-state (widget)
42 (foreign-slot-value (pointer widget) '%gtk-widget :saved-state))
44 (export 'widget-saved-state)
46 (defmacro widget-p-fn (type)
47 (let ((name (intern (format nil "WIDGET-~A-P" (symbol-name type)) (find-package :gtk))))
48 `(progn (defun ,name (widget)
49 (member ,type (widget-flags widget)))
50 (export ',name))))
52 (widget-p-fn :toplevel)
53 (widget-p-fn :no-window)
54 (widget-p-fn :realized)
55 (widget-p-fn :mapped)
56 (widget-p-fn :visible)
57 (widget-p-fn :sensitive)
58 (widget-p-fn :parent-sensitive)
59 (widget-p-fn :can-focus)
60 (widget-p-fn :has-focus)
61 (widget-p-fn :can-default)
62 (widget-p-fn :has-default)
63 (widget-p-fn :has-grab)
64 (widget-p-fn :rc-style)
65 (widget-p-fn :composite-child)
66 (widget-p-fn :no-reparent)
67 (widget-p-fn :app-paintable)
68 (widget-p-fn :receives-default)
69 (widget-p-fn :double-buffered)
70 (widget-p-fn :no-show-all)
72 (defcfun (widget-unparent "gtk_widget_unparent") :void
73 (widget g-object))
75 (export 'widget-unparent)
77 (defcfun gtk-widget-show :void
78 (widget g-object))
80 (defcfun gtk-widget-show-all :void
81 (widget g-object))
83 (defun widget-show (widget &key (all t))
84 (if all
85 (gtk-widget-show-all widget)
86 (gtk-widget-show widget)))
88 (export 'widget-show)
90 (defcfun (widget-show-now "gtk_widget_show_now") :void
91 (widget g-object))
93 (export 'widget-show-now)
95 (defcfun gtk-widget-hide :void
96 (widget g-object))
98 (defcfun gtk-widget-hide-all :void
99 (widget g-object))
101 (defun widget-hide (widget &key (all t))
102 (if all
103 (gtk-widget-hide-all widget)
104 (gtk-widget-hide widget)))
106 (defcfun (widget-map "gtk_widget_map") :void
107 (widget g-object))
109 (export 'widget-map)
111 (defcfun (widget-unmap "gtk_widget_unmap") :void
112 (widget g-object))
114 (export 'widget-unmap)
116 (defcfun (widget-realize "gtk_widget_realize") :void
117 (width g-object))
119 (export 'widget-realize)
121 (defcfun (widget-unrealize "gtk_widget_unrealize") :void
122 (width g-object))
124 (export 'widget-unrealize)
126 (defcfun (widget-queue-draw "gtk_widget_queue_draw") :void
127 (widget (g-object widget)))
129 (export 'widget-queue-draw)
131 (defcfun (widget-queue-resize "gtk_widget_queue_resize") :void
132 (widget (g-object widget)))
134 (export 'widget-queue-resize)
136 (defcfun (widget-queue-resize-no-redraw "gtk_widget_queue_resize_no_redraw") :void
137 (widget (g-object widget)))
139 (export 'widget-queue-resize-no-redraw)
141 ; TODO: gtk_widget_get_child_requisition
143 ; TODO: gtk_widget_size_allocate
145 (defcfun (widget-add-accelerator "gtk_widget_add_accelerator") :void
146 (widget g-object)
147 (accel-signal :string)
148 (accel-group g-object)
149 (accel-key :uint)
150 (accel-mods modifier-type)
151 (accel-flags accel-flags))
153 (export 'widget-add-accelerator)
155 (defcfun (widget-remove-accelerator "gtk_widget_remove_accelerator") :void
156 (widget g-object)
157 (accel-group g-object)
158 (accel-key :uint)
159 (accel-mods modifier-type))
161 (export 'widget-remove-accelerator)
163 (defcfun (widget-set-accel-path "gtk_widget_set_accel_path") :void
164 (widget g-object)
165 (accel-path :string)
166 (accel-group g-object))
168 (export 'widget-set-accel-path)
170 ; TODO: gtk_widget_list_accel_closures
172 (defcfun gtk-widget-can-activate-accel :boolean
173 (widget g-object)
174 (signal-id :uint))
176 (defun widget-can-activate-accel (widget signal)
177 (when (stringp signal) (setf signal (g-signal-lookup signal (g-type-from-object widget))))
178 (gtk-widget-can-activate-accel widget signal))
180 (export 'widget-can-activate-accel)
182 ; TODO: gtk_widget_event
184 (defcfun (widget-activate "gtk_widget_activate") :boolean
185 (widget g-object))
187 (export 'widget-activate)
189 (defcfun (widget-reparent "gtk_widget_reparent") :void
190 (widget g-object)
191 (new-parent g-object))
193 (export 'widget-reparent)
195 (defcfun gtk-widget-intersect :boolean
196 (widget g-object)
197 (area (g-boxed-foreign rectangle))
198 (intersection (g-boxed-foreign rectangle :in-out)))
200 (defun widget-intersect (widget rectangle)
201 (let ((result (make-rectangle :x 0 :y 0 :width 0 :height 0)))
202 (when (gtk-widget-intersect widget rectangle result)
203 result)))
205 (export 'widget-intersect)
207 (defcfun (widget-focus-p "gtk_widget_is_focus") :boolean
208 (widget g-object))
210 (export 'widget-focus-p)
212 (defcfun (widget-grab-focus "gtk_widget_grab_focus") :void
213 (widget g-object))
215 (export 'widget-grab-focus)
217 (defcfun (widget-grab-default "gtk_widget_grab_default") :void
218 (widget g-object))
220 (export 'widget-grab-default)
222 ; TODO: gtk_widget_set_state
224 ; TODO: gtk_widget_set_parent_window
226 ; TODO: gtk_widget_get_parent_window
228 ; TODO: gtk_widget_set_extension_events
230 ; TODO: gtk_widget_get_extension_events
233 ; fix ownership issues:
234 ; TODO: gtk_widget_get_toplevel
236 ; TODO: gtk_widget_get_ancestor
238 ; TODO: gtk_widget_get_colormap
240 ; TODO: gtk_widget_get_visual
242 (defcfun gtk-widget-get-pointer :void
243 (widget g-object)
244 (x (:pointer :int))
245 (y (:pointer :int)))
247 (defun widget-pointer (widget)
248 (with-foreign-objects ((x :int) (y :int))
249 (gtk-widget-get-pointer widget x y)
250 (values (mem-ref x :int) (mem-ref y :int))))
252 (export 'widget-pointer)
254 (defcfun (widget-contained-p "gtk_widget_is_ancestor") :boolean
255 (widget g-object)
256 (container g-object))
258 (export 'widget-contained-p)
260 (defcfun gtk-widget-translate-coordinates :boolean
261 (src-widget g-object)
262 (dst-widget g-object)
263 (src-x :int)
264 (src-y :int)
265 (dst-x (:pointer :int))
266 (dst-y (:pointer :int)))
268 (defun widget-translate-coordinates (src-widget dst-widget src-x src-y)
269 (with-foreign-objects ((dst-x :int) (dst-y :int))
270 (gtk-widget-translate-coordinates src-widget dst-widget src-x src-y dst-x dst-y)
271 (values (mem-ref dst-x :int)
272 (mem-ref dst-y :int))))
274 (export 'widget-translate-coordinates)
276 (defcfun (widget-ensure-style "gtk_widget_ensure_style") :void
277 (widget g-object))
279 (export 'widget-ensure-style)
281 (defcfun (widget-reset-rc-styles "gtk_widget_reset_rc_styles") :void
282 (widget g-object))
284 (export 'widget-reset-rc-styles)
286 ; TODO: gtk_widget_push_colormap
288 ; TODO: gtk_widget_pop_colormap
290 ; TODO: gtk_widget_set_default_colormap
292 ; TODO: gtk_widget_get_default_colormap
294 ; TODO: gtk_widget_get_default_style (ownership)
296 ; TODO: gtk_widget_get_default_visual
298 (defcfun (widget-default-direction "gtk_widget_get_default_direction") text-direction)
300 (defcfun gtk-widget-set-default-direction :void
301 (direction text-direction))
303 (defun (setf widget-default-direction) (new-value)
304 (gtk-widget-set-default-direction new-value))
306 (export 'widget-default-direction)
308 ; TODO: gtk_widget_shape_combine_mask
310 ; TODO: gtk_widget_input_shape_combine_mask
312 (defcfun gtk-widget-path :void
313 (widget g-object)
314 (path-length (:pointer :uint))
315 (path (:pointer (:pointer :char)))
316 (path-reversed (:pointer (:pointer :char))))
318 (defcfun gtk-widget-class-path :void
319 (widget g-object)
320 (path-length (:pointer :uint))
321 (path (:pointer (:pointer :char)))
322 (path-reversed (:pointer (:pointer :char))))
324 (defun widget-path (widget &key (path-type :name))
325 (assert (typep path-type '(member :name :class)))
326 (with-foreign-object (path :pointer)
327 (ecase path-type
328 (:name (gtk-widget-path widget (null-pointer) path (null-pointer)))
329 (:class (gtk-widget-class-path widget (null-pointer) path (null-pointer))))
330 (mem-ref path '(g-string :free-from-foreign t))))
332 (export 'widget-path)
334 ; TODO: gtk_widget_modify_style
336 ; TODO: gtk_widget_get_modifier_style
338 ; TODO: gtk_widget_modify_fg
340 ; TODO: gtk_widget_modify_bg
342 ; TODO: gtk_widget_modify_text
344 ; TODO: gtk_widget_modify_base
346 ; TODO: gtk_widget_modify_font
348 ; TODO: gtk_widget_modify_cursor
350 (defcfun (widget-create-pango-context "gtk_widget_create_pango_context") g-object
351 (widget g-object))
353 (export 'widget-create-pango-context)
355 (defcfun (widget-get-pango-context "gtk_widget_get_pango_context") g-object
356 (widget g-object))
358 (export 'widget-get-pango-context)
360 (defcfun (widget-create-pango-layout "gtk_widget_create_pango_layout") (g-object gdk::pango-layout :already-referenced)
361 (widget (g-object widget))
362 (text :string))
364 (export 'widget-create-pango-layout)
366 (defcfun (widget-render-icon "gtk_widget_render_icon") g-object
367 (widget g-object)
368 (stock-id :string)
369 (size icon-size)
370 (detail :string))
372 (export 'widget-render-icon)
374 (defcfun (widget-push-composite-child "gtk_widget_push_composite_child") :void
375 (widget g-object))
377 (export 'widget-push-composite-child)
379 (defcfun (widget-pop-composite-child "gtk_widget_pop_composite_child") :void
380 (widget g-object))
382 (export 'widget-pop-composite-child)
384 (defcfun (widget-queue-draw-area "gtk_widget_queue_draw_area") :void
385 (widget g-object)
386 (x :int)
387 (y :int)
388 (width :int)
389 (height :int))
391 (export 'widget-queue-draw-area)
393 (defcfun (widget-reset-shapes "gtk_widget_reset_shapes") :void
394 (widget g-object))
396 (export 'widget-reset-shapes)
398 (defcfun (widget-set-scroll-adjustments "gtk_widget_set_scroll_adjustments") :boolean
399 (widget g-object)
400 (hadjustment g-object)
401 (vadjustment g-object))
403 (export 'widget-set-scroll-adjustments)
405 ; TODO: gtk_widget_class_install_style_property
407 ; TOOD: gtk_widget_class_install_style_property_parser
409 ; TODO: gtk_widget_class_list_style_properties
411 ; TODO: gtk_widget_region_intersect
413 ; TODO: gtk_widget_send_expose
415 (defcfun gtk-widget-style-get-property :void
416 (widget g-object)
417 (property-name :string)
418 (value (:pointer g-value)))
420 (defcfun gtk-widget-class-find-style-property (:pointer g-param-spec)
421 (class :pointer)
422 (property-name :string))
424 (defcfun gtk-widget-class-list-style-properties (:pointer (:pointer g-param-spec))
425 (class :pointer)
426 (n-properties (:pointer :int)))
428 (defun widget-class-get-style-properties (type)
429 (setf type (ensure-g-type type))
430 (let ((class (g-type-class-ref type)))
431 (unwind-protect
432 (with-foreign-object (np :int)
433 (let ((specs (gtk-widget-class-list-style-properties class np)))
434 (unwind-protect
435 (loop
436 repeat (mem-ref np :int)
437 for i from 0
438 for spec = (mem-aref specs :pointer i)
439 collect (parse-g-param-spec spec))
440 (g-free specs))))
441 (g-type-class-unref class))))
443 (export 'widget-class-get-style-properties)
445 (defun widget-child-property-type (widget property-name)
446 (let* ((type (g-type-from-object widget))
447 (class (g-type-class-ref type)))
448 (unwind-protect
449 (let ((g-param-spec (gtk-widget-class-find-style-property class property-name)))
450 (when (null-pointer-p g-param-spec) (error "Widget ~A has no style-property named '~A'" widget property-name))
451 (foreign-slot-value g-param-spec 'gobject:g-param-spec :value-type))
452 (g-type-class-unref class))))
454 (defun widget-child-property-value (widget property-name &optional property-type)
455 (unless property-type (setf property-type (widget-child-property-type widget property-name)))
456 (setf property-type (ensure-g-type property-type))
457 (with-foreign-object (gvalue 'g-value)
458 (g-value-zero gvalue)
459 (g-value-init gvalue property-type)
460 (prog1 (gtk-widget-style-get-property widget property-name gvalue)
461 (g-value-unset gvalue))))
463 (export 'widget-child-property-value)
465 (defcfun (widget-child-focus "gtk_widget_child_focus") :boolean
466 (widget g-object)
467 (direction direction-type))
469 (export 'widget-child-focus)
471 (defcfun (widget-freeze-child-notify "gtk_widget_freeze_child_notify") :void
472 (widget g-object))
474 (export 'widget-freeze-child-notify)
476 (defcfun (widget-settings "gtk_widget_get_settings") g-object
477 (widget g-object))
479 (export 'widget-settings)
481 ; TODO: gtk_widget_get_clipboard
483 (defcfun (widget-display "gtk_widget_get_display") g-object
484 (widget g-object))
486 (export 'widget-display)
488 (defcfun (widget-root-window "gtk_widget_get_root_window") g-object
489 (widget g-object))
491 (export 'widget-root-window)
493 (defcfun (widget-screen "gtk_widget_get_screen") g-object
494 (widget g-object))
496 (export 'widget-screen)
498 (defcfun (widget-has-screen "gtk_widget_has_screen") :boolean
499 (widget g-object))
501 (export 'widget-has-screen)
503 ; TODO: gtk_widget_set_child_visible
505 (defcfun (widget-thaw-child-notify "gtk_widget_thaw_child_notify") :void
506 (widget g-object))
508 (export 'widget-thaw-child-notify)
510 ; TODO: gtk_widget_list_mnemonic_labels
512 (defcfun (widget-add-mnemonic-label "gtk_widget_add_mnemonic_label") :void
513 (widget g-object)
514 (label g-object))
516 (export 'widget-add-mnemonic-label)
518 (defcfun (widget-remove-mnemonic-label "gtk_widget_remove_mnemonic_label") :void
519 (widget g-object)
520 (label g-object))
522 (export 'widget-remove-mnemonic-label)
524 (defcfun (widget-action "gtk_widget_get_action") g-object
525 (widget g-object))
527 (export 'widget-action)
529 (defcfun (widget-composited-p "gtk_widget_is_composited") :boolean
530 (widget g-object))
532 (export 'widget-composited-p)
534 (defcfun (widget-error-bell "gtk_widget_error_bell") :void
535 (widget g-object))
537 (export 'widget-error-bell)
539 (defcfun (widget-trigger-tooltip-query "gtk_tooltip_trigger_tooltip_query") :void
540 (widget g-object))
542 (export 'widget-trigger-tooltip-query)
544 (defcfun gtk-widget-get-snapshot g-object
545 (widget g-object)
546 (clip-rectangle (g-boxed-foreign rectangle)))
548 (defun widget-snapshot (widget &optional clip-rectangle)
549 (gtk-widget-get-snapshot widget clip-rectangle))
551 (export 'widget-snapshot)