(require 'std-ffi)
(require 'foreign-stdlib)
(require 'foreign-sugar)
(require 'foreign-ctools)
(require 'foreign-cenums)
(require 'srfi-0)
(require 'glib) ;; convenience; who's going to use gtk without glib?
(require 'gdk)

(let ((os (assq 'os-name (system-features))))
  (cond 
   ((equal? os '(os-name . "Linux"))
    (foreign-file "/usr/lib/libgtk-x11-2.0.so.0"))    
   ((equal? os '(os-name . "SunOS"))
    (foreign-file "/usr/lib/libgtk-x11-2.0.so"))
   ((equal? os '(os-name . "MacOS X"))
    (foreign-file "/sw/lib/libgtk-x11-2.0.dylib")
    ;(foreign-file "~/Library/Gtk+-Cocoa.framework/Gtk+-Cocoa")
    )
   (else
    (error "Add case in gtk.sch for os: " os))))

;;; XXX perhaps we need a bit of type abstraction for callbacks
;;; like these, where we could abstract over what type should be
;;; ascribed to the callback argument.
;;;
;;; (But that's an absurd amount of machinery to add when one can
;;; easily get around the problem by passing closures as the callback,
;;; as would have been appropriate in the first place)

(define gtktextiter*-rt (ffi-install-void*-subtype 'gtktextiter*))
(establish-void*-subhierarchy! '(gtkclipboard*))
(establish-void*-subhierarchy! '(gtktextchildanchor*))
(establish-void*-subhierarchy! '(gtkwindowgroup*))
(establish-void*-subhierarchy! '(gtkiconset*))

(establish-void*-subhierarchy!
 '(gobject* (gtkobject* 
             (gtkwidget* (gtkentry*)
                         (gtkinvisible*)
                         (gtkcontainer*
                          (gtkbin* (gtkalignment*)
                                   (gtkwindow* (gtkdialog* (gtkaboutdialog*)
                                                           (gtkmessagedialog*)
                                                           (gtkfileselection*)))
                                   (gtkbutton* (gtktogglebutton*
                                                (gtkcheckbutton*
                                                 (gtkradiobutton*)))
                                               (gtkoptionmenu*))
                                   (gtkcombobox*)
                                   (gtktoolitem* (gtktoolbutton*))
                                   (gtkframe*)
                                   (gtkitem* (gtkmenuitem*
                                              (gtkcheckmenuitem*
                                               (gtkradiomenuitem*))
                                              (gtkimagemenuitem*)
                                              (gtkseparatormenuitem*)
                                              (gtktearoffmenuitem*))))
                          (gtkbox* (gtkvbox*)
                                   (gtkhbox*
                                    (gtkstatusbar*)
                                    (gtkcombo*)))
                          (gtktable*)
                          (gtktoolbar*)
                          (gtkmenushell* (gtkmenubar*)
                                         (gtkmenu*))
                          (gtktextview*)) ;; end gtkcontainer*
                         (gtkmisc* (gtklabel* (gtkaccellabel*))
                                   (gtkarrow*)
                                   (gtkimage*)
                                   (gtkpixmap*))
                         (gtkrange* (gtkscale*)
                                    (gtkscrollbar*))
                         (gtkprogress* (gtkprogressbar*))
;; Deprecated in gtk2
;                         (gtktext*)
                         )
             (gtktooltips*)
             (gtkadjustment*))
            (gtkaccelgroup*)
            (gtktextbuffer*)
            (gtktextmark*)
            (gtktexttagtable*)
            (gtktexttag*)
            (gtkentrycompletion*)
            ))

(define gtk-init 
  (let ()
    (define-foreign (gtk-init void* void*) void)
    (lambda arg-strings
      (let ((string-vec (list->vector (cons "larceny" arg-strings))))
        (call-with-char** string-vec
                          (lambda (argv)
                            (call-with-boxed 
                             argv 
                             (lambda (&argv)
                               (call-with-boxed (vector-length string-vec)
                                                (lambda (&argc)
                                                  (gtk-init &argc &argv)))))))))))


(define-syntax invoke-form/target-dep-paths
  (syntax-rules ()
    ((_ FORM . ARGS)
     (cond-expand
      (macosx 
       (FORM
        ("/sw/include/gtk-2.0"
         "/sw/include/glib-2.0"
         "/sw/lib/glib-2.0/include"
         "/sw/lib/gtk-2.0/include"
         "/sw/include/pango-1.0"
         "/sw/include/atk-1.0"
         "/sw/include/gtk-2.0")
        . ARGS))
      (unix
       (FORM
        ("/usr/include/glib-2.0"
         "/usr/lib/glib-2.0/include"
         "/usr/lib/gtk-2.0/include"
         "/usr/include/pango-1.0"
         "/usr/include/cairo"
         "/usr/include/atk-1.0"
         "/usr/include/gtk-2.0")
        . ARGS))
      (else
       (error 'define-cfields-offsets ": no support for your target..."))))))

(define-syntax invoke-form/expand-paths
  (syntax-rules ()
    ((_ (PATHS ...) macro-cmd . ARGS)
     (macro-cmd (path PATHS) ... . ARGS))))

(define-syntax define-cfields-offsets/target-dep-paths
  (syntax-rules ()
    ((_ (HEADERS ...) FORMS ...)
     (invoke-form/target-dep-paths 
      invoke-form/expand-paths
      define-c-info
      (include<> HEADERS) ... FORMS ...))))

(define-syntax define-gtk-enum
  (syntax-rules ()
    ((_ enum-type (decls ...) (scm-name c-name) ...)
     (invoke-form/target-dep-paths
      define-gtk-enum/swap-in-paths 
      enum-type (decls ...)
      (scm-name c-name) ...))))

(define-syntax define-gtk-enum-set
  (syntax-rules ()
    ((_ enum-type (decls ...) (scm-name c-name) ...)
     (invoke-form/target-dep-paths
      define-gtk-enum-set/swap-in-paths 
      enum-type (decls ...)
      (scm-name c-name) ...))))

(define-syntax define-gtk-enum/swap-in-paths
  (syntax-rules ()
    ((_ (PATHS ...) enum-type (decls ...) . ARGS)
     (define-c-enum enum-type ((path PATHS) ... decls ...) . ARGS))))

(define-syntax define-gtk-enum-set/swap-in-paths
  (syntax-rules ()
    ((_ (PATHS ...) enum-type (decls ...) . ARGS)
     (define-c-enum-set enum-type ((path PATHS) ... decls ...) . ARGS))))

(define-gtk-enum gtkanchortype ((include<> "gtk/gtkenums.h"))
  (center "GTK_ANCHOR_CENTER")
  (north "GTK_ANCHOR_NORTH")
  (north-west "GTK_ANCHOR_NORTH_WEST")
  (north-east "GTK_ANCHOR_NORTH_EAST")
  (south "GTK_ANCHOR_SOUTH")
  (south-west "GTK_ANCHOR_SOUTH_WEST")
  (south-east "GTK_ANCHOR_SOUTH_EAST")
  (west "GTK_ANCHOR_WEST")
  (east "GTK_ANCHOR_EAST")
  (n "GTK_ANCHOR_N")
  (nw "GTK_ANCHOR_NW")
  (ne "GTK_ANCHOR_NE")
  (s "GTK_ANCHOR_S")
  (sw "GTK_ANCHOR_SW")
  (se "GTK_ANCHOR_SE")
  (w "GTK_ANCHOR_W")
  (e "GTK_ANCHOR_E"))

(define-gtk-enum gtkarrowtype ((include<> "gtk/gtkenums.h"))
  (up    "GTK_ARROW_UP")
  (down  "GTK_ARROW_DOWN")
  (left  "GTK_ARROW_LEFT")
  (right "GTK_ARROW_RIGHT"))

(define-gtk-enum-set gtkattachoptions ((include<> "gtk/gtkenums.h"))
  (expand "GTK_EXPAND")
  (shrink "GTK_SHRINK")
  (fill "GTK_FILL"))

(define-gtk-enum gtkbuttonboxstyle ((include<> "gtk/gtkenums.h"))
  (default-style "GTK_BUTTONBOX_DEFAULT_STYLE")
  (spread "GTK_BUTTONBOX_SPREAD")
  (edge "GTK_BUTTONBOX_EDGE")
  (start "GTK_BUTTONBOX_START")
  (end "GTK_BUTTONBOX_END"))

(define-gtk-enum gtkcurvetype ((include<> "gtk/gtkenums.h"))
  (linear "GTK_CURVE_TYPE_LINEAR")
  (spline "GTK_CURVE_TYPE_SPLINE")
  (free   "GTK_CURVE_TYPE_FREE"))

(define-gtk-enum gtkdeletetype ((include<> "gtk/gtkenums.h"))
  (chars             "GTK_DELETE_CHARS")
  (word-ends         "GTK_DELETE_WORD_ENDS")
  (words             "GTK_DELETE_WORDS")
  (display-lines     "GTK_DELETE_DISPLAY_LINES")
  (display-line-ends "GTK_DELETE_DISPLAY_LINE_ENDS")
  (paragraph-ends    "GTK_DELETE_PARAGRAPH_ENDS")
  (paragraphs        "GTK_DELETE_PARAGRAPHS")
  (whitespace        "GTK_DELETE_WHITESPACE"))

(define-gtk-enum gtkdirectiontype ((include<> "gtk/gtkenums.h"))
  (forward  "GTK_DIR_TAB_FORWARD")
  (backward "GTK_DIR_TAB_BACKWARD")
  (up       "GTK_DIR_UP")
  (down     "GTK_DIR_DOWN")
  (left     "GTK_DIR_LEFT")
  (right    "GTK_DIR_RIGHT"))

(define-gtk-enum gtkexpanderstyle ((include<> "gtk/gtkenums.h"))
  (collapsed      "GTK_EXPANDER_COLLAPSED")
  (semi-collapsed "GTK_EXPANDER_SEMI_COLLAPSED")
  (semi-expanded  "GTK_EXPANDER_SEMI_EXPANDED")
  (expanded       "GTK_EXPANDER_EXPANDED"))

(define-gtk-enum gtkiconsize ((include<> "gtk/gtkenums.h"))
  (invalid       "GTK_ICON_SIZE_INVALID")
  (menu          "GTK_ICON_SIZE_MENU")
  (small-toolbar "GTK_ICON_SIZE_SMALL_TOOLBAR")
  (large-toolbar "GTK_ICON_SIZE_LARGE_TOOLBAR")
  (button        "GTK_ICON_SIZE_BUTTON")
  (dnd           "GTK_ICON_SIZE_DND")
  (dialog        "GTK_ICON_SIZE_DIALOG"))

(define-gtk-enum gtktextdirection ((include<> "gtk/gtkenums.h"))
  (none "GTK_TEXT_DIR_NONE")
  (ltr  "GTK_TEXT_DIR_LTR")
  (rtl  "GTK_TEXT_DIR_RTL"))

(define-gtk-enum gtkjustification ((include<> "gtk/gtkenums.h"))
  (left "GTK_JUSTIFY_LEFT")
  (right "GTK_JUSTIFY_RIGHT")
  (center "GTK_JUSTIFY_CENTER")
  (fill "GTK_JUSTIFY_FILL"))

(define-gtk-enum gtkmenudirectiontype ((include<> "gtk/gtkenums.h"))
  (parent "GTK_MENU_DIR_PARENT")
  (child "GTK_MENU_DIR_CHILD")
  (next "GTK_MENU_DIR_NEXT")
  (prev "GTK_MENU_DIR_PREV"))

(define-gtk-enum gtkmetrictype ((include<> "gtk/gtkenums.h"))
  (pixels "GTK_PIXELS")
  (inches "GTK_INCHES")
  (centimeters "GTK_CENTIMETERS"))

(define-gtk-enum gtkmovementstep ((include<> "gtk/gtkenums.h"))
  (logical-positions  "GTK_MOVEMENT_LOGICAL_POSITIONS")
  (visual-positions   "GTK_MOVEMENT_VISUAL_POSITIONS")
  (words              "GTK_MOVEMENT_WORDS")
  (display-lines      "GTK_MOVEMENT_DISPLAY_LINES")
  (display-lines-ends "GTK_MOVEMENT_DISPLAY_LINE_ENDS")
  (paragraphs         "GTK_MOVEMENT_PARAGRAPHS")
  (paragraphs-ends    "GTK_MOVEMENT_PARAGRAPH_ENDS")
  (pages              "GTK_MOVEMENT_PAGES")
  (buffer-ends        "GTK_MOVEMENT_BUFFER_ENDS")
  (horizontal-pages   "GTK_MOVEMENT_HORIZONTAL_PAGES"))

(define-gtk-enum gtkscrollstep ((include<> "gtk/gtkenums.h"))
  (steps "GTK_SCROLL_STEPS")
  (pages "GTK_SCROLL_PAGES")
  (ends  "GTK_SCROLL_ENDS")
  (horizontal-steps "GTK_SCROLL_HORIZONTAL_STEPS")
  (horizontal-pages "GTK_SCROLL_HORIZONTAL_PAGES")
  (horizontal-ends  "GTK_SCROLL_HORIZONTAL_ENDS"))

(define-gtk-enum gtkorientation  ((include<> "gtk/gtkenums.h"))
  (horizontal "GTK_ORIENTATION_HORIZONTAL")
  (vertical "GTK_ORIENTATION_VERTICAL"))

(define-gtk-enum gtkcornertype ((include<> "gtk/gtkenums.h"))
  (top-left     "GTK_CORNER_TOP_LEFT")
  (bottom-left  "GTK_CORNER_BOTTOM_LEFT")
  (top-right    "GTK_CORNER_TOP_RIGHT")
  (bottom-right "GTK_CORNER_BOTTOM_RIGHT"))

(define-gtk-enum gtkpacktype ((include<> "gtk/gtkenums.h"))
  (start "GTK_PACK_START")
  (end   "GTK_PACK_END"))

(define-gtk-enum gtkpathprioritytype ((include<> "gtk/gtkenums.h"))
  (lowest      "GTK_PATH_PRIO_LOWEST")
  (gtk         "GTK_PATH_PRIO_GTK")
  (application "GTK_PATH_PRIO_APPLICATION")
  (theme       "GTK_PATH_PRIO_THEME")
  (rc          "GTK_PATH_PRIO_RC")
  (highest     "GTK_PATH_PRIO_HIGHEST"))

(define-gtk-enum gtkpathtype ((include<> "gtk/gtkenums.h"))
  (widget "GTK_PATH_WIDGET")
  (widget-class "GTK_PATH_WIDGET_CLASS")
  (path-class "GTK_PATH_CLASS"))

(define-gtk-enum gtkpolicytype ((include<> "gtk/gtkenums.h"))
  (always "GTK_POLICY_ALWAYS")
  (automatic "GTK_POLICY_AUTOMATIC")
  (never "GTK_POLICY_NEVER"))

(define-gtk-enum gtkpositiontype ((include<> "gtk/gtkenums.h"))
  (left   "GTK_POS_LEFT")
  (right  "GTK_POS_RIGHT")
  (top    "GTK_POS_TOP")
  (bottom "GTK_POS_BOTTOM"))

(define-gtk-enum gtkpreviewtype ((include<> "gtk/gtkenums.h"))
  (color     "GTK_PREVIEW_COLOR")
  (grayscale "GTK_PREVIEW_GRAYSCALE"))

(define-gtk-enum gtkreliefstyle ((include<> "gtk/gtkenums.h"))
  (normal "GTK_RELIEF_NORMAL")
  (half   "GTK_RELIEF_HALF")
  (none   "GTK_RELIEF_NONE"))

(define-gtk-enum gtkresizemode ((include<> "gtk/gtkenums.h"))
  (parent    "GTK_RESIZE_PARENT")
  (queue     "GTK_RESIZE_QUEUE")
  (immediate "GTK_RESIZE_IMMEDIATE"))

(define-gtk-enum gtkscrolltype ((include<> "gtk/gtkenums.h"))
  (none          "GTK_SCROLL_NONE")
  (jump          "GTK_SCROLL_JUMP")
  (step-backward "GTK_SCROLL_STEP_BACKWARD")
  (step-forward  "GTK_SCROLL_STEP_FORWARD")
  (page-backward "GTK_SCROLL_PAGE_BACKWARD")
  (page-forward  "GTK_SCROLL_PAGE_FORWARD")
  (step-up       "GTK_SCROLL_STEP_UP")
  (step-down     "GTK_SCROLL_STEP_DOWN")
  (page-up       "GTK_SCROLL_PAGE_UP")
  (page-down     "GTK_SCROLL_PAGE_DOWN")
  (step-left     "GTK_SCROLL_STEP_LEFT")
  (step-right    "GTK_SCROLL_STEP_RIGHT")
  (page-left     "GTK_SCROLL_PAGE_LEFT")
  (page-right    "GTK_SCROLL_PAGE_RIGHT")
  (start         "GTK_SCROLL_START")
  (end           "GTK_SCROLL_END"))

(define-gtk-enum gtkselectionmode ((include<> "gtk/gtkenums.h"))
  (none   "GTK_SELECTION_NONE")
  (single "GTK_SELECTION_SINGLE")
  (browse "GTK_SELECTION_BROWSE")
  (multiple "GTK_SELECTION_MULTIPLE"))

(define-gtk-enum gtkshadowtype ((include<> "gtk/gtkenums.h"))
  (none   "GTK_SHADOW_NONE")
  (in     "GTK_SHADOW_IN")
  (out    "GTK_SHADOW_OUT")
  (etched-in "GTK_SHADOW_ETCHED_IN")
  (etched-out "GTK_SHADOW_ETCHED_OUT"))

(define-gtk-enum gtkstatetype ((include<> "gtk/gtkenums.h"))
  (normal   "GTK_STATE_NORMAL")
  (active   "GTK_STATE_ACTIVE")
  (prelight "GTK_STATE_PRELIGHT")
  (selected "GTK_STATE_SELECTED")
  (insensitive "GTK_STATE_INSENSITIVE"))

(define-gtk-enum gtktoolbarstyle ((include<> "gtk/gtkenums.h"))
  (icons  "GTK_TOOLBAR_ICONS")
  (text   "GTK_TOOLBAR_TEXT")
  (both   "GTK_TOOLBAR_BOTH")
  (both-horiz "GTK_TOOLBAR_BOTH_HORIZ"))

(define-gtk-enum gtkupdatetype ((include<> "gtk/gtkenums.h"))
  (continuous    "GTK_UPDATE_CONTINUOUS")
  (discontinuous "GTK_UPDATE_DISCONTINUOUS")
  (delayed       "GTK_UPDATE_DELAYED"))

(define-gtk-enum gtkvisibility ((include<> "gtk/gtkenums.h"))
  (none    "GTK_VISIBILITY_NONE")
  (partial "GTK_VISIBILITY_PARTIAL")
  (full    "GTK_VISIBILITY_FULL"))

(define-gtk-enum gtkwindowposition ((include<> "gtk/gtkenums.h"))
  (none             "GTK_WIN_POS_NONE")
  (center           "GTK_WIN_POS_CENTER")
  (mouse            "GTK_WIN_POS_MOUSE")
  (center-always    "GTK_WIN_POS_CENTER_ALWAYS")
  (center-on-parent "GTK_WIN_POS_CENTER_ON_PARENT"))

(define-gtk-enum gtkwindowtype ((include<> "gtk/gtkenums.h"))
  (toplevel "GTK_WINDOW_TOPLEVEL")
  (popup    "GTK_WINDOW_POPUP"))

(define-gtk-enum gtkwrapmode ((include<> "gtk/gtkenums.h"))
  (none      "GTK_WRAP_NONE")
  (char      "GTK_WRAP_CHAR")
  (word      "GTK_WRAP_WORD")
  (word-char "GTK_WRAP_WORD_CHAR"))

(define-gtk-enum gtksorttype ((include<> "gtk/gtkenums.h"))
  (ascending  "GTK_SORT_ASCENDING")
  (descending "GTK_SORT_DESCENDING"))

(define-gtk-enum gtkimpreeditstyle ((include<> "gtk/gtkenums.h"))
  (nothing  "GTK_IM_PREEDIT_NOTHING")
  (callback "GTK_IM_PREEDIT_CALLBACK")
  (none     "GTK_IM_PREEDIT_NONE"))
 
(define-gtk-enum gtkimstatusstyle ((include<> "gtk/gtkenums.h"))
  (nothing  "GTK_IM_STATUS_NOTHING")
  (callback "GTK_IM_STATUS_CALLBACK")
  (none     "GTK_IM_STATUS_NONE"))

(define-gtk-enum-set gtkdialogflags ((include<> "gtk/gtkdialog.h")) 
  (modal               "GTK_DIALOG_MODAL")
  (destroy-with-parent "GTK_DIALOG_DESTROY_WITH_PARENT")
  (no-separator        "GTK_DIALOG_NO_SEPARATOR"))

(define-gtk-enum gtkresponsetype ((include<> "gtk/gtkdialog.h")) 
  (none   "GTK_RESPONSE_NONE")
  (reject "GTK_RESPONSE_REJECT")
  (accept "GTK_RESPONSE_ACCEPT")
  (ok     "GTK_RESPONSE_OK")
  (cancel "GTK_RESPONSE_CANCEL")
  (close  "GTK_RESPONSE_CLOSE")
  (yes    "GTK_RESPONSE_YES")
  (no     "GTK_RESPONSE_NO")
  (apply  "GTK_RESPONSE_APPLY")
  (help   "GTK_RESPONSE_HELP"))

(define-gtk-enum gtkmessagetype ((include<> "gtk/gtkmessagedialog.h"))
  (info     "GTK_MESSAGE_INFO")
  (warning  "GTK_MESSAGE_WARNING")
  (question "GTK_MESSAGE_QUESTION")
  (error    "GTK_MESSAGE_ERROR"))

(define-gtk-enum gtkbuttonstype ((include<> "gtk/gtkmessagedialog.h"))
  (none      "GTK_BUTTONS_NONE")
  (ok        "GTK_BUTTONS_OK")
  (close     "GTK_BUTTONS_CLOSE")
  (cancel    "GTK_BUTTONS_CANCEL")
  (yes/no    "GTK_BUTTONS_YES_NO")
  (ok/cancel "GTK_BUTTONS_OK_CANCEL"))

(define-gtk-enum-set gdkwindowhints ((include<> "gdk/gdkwindow.h"))
  (pos "GDK_HINT_POS")
  (min-size "GDK_HINT_MIN_SIZE")
  (max-size "GDK_HINT_MAX_SIZE")
  (base-size "GDK_HINT_BASE_SIZE")
  (aspect "GDK_HINT_ASPECT")
  (resize-increment "GDK_HINT_RESIZE_INC")
  (window-gravity "GDK_HINT_WIN_GRAVITY")
  (user-pos "GDK_HINT_USER_POS")
  (user-size "GDK_HINT_USER_SIZE"))

(define-gtk-enum gdkgravity ((include<> "gdk/gdkwindow.h"))
  (north-west "GDK_GRAVITY_NORTH_WEST")
  (north      "GDK_GRAVITY_NORTH")
  (north-east "GDK_GRAVITY_NORTH_EAST")
  (west       "GDK_GRAVITY_WEST")
  (center     "GDK_GRAVITY_CENTER")
  (east       "GDK_GRAVITY_EAST")
  (south-west "GDK_GRAVITY_SOUTH_WEST")
  (south      "GDK_GRAVITY_SOUTH")
  (south-east "GDK_GRAVITY_SOUTH_EAST")
  (static     "GDK_GRAVITY_STATIC"))

(define-gtk-enum-set gdkmodifiertype ((include "gdk/gdktypes.h"))
  (shift    "GDK_SHIFT_MASK")
  (lock     "GDK_LOCK_MASK")
  (control  "GDK_CONTROL_MASK")
  (mod1     "GDK_MOD1_MASK")
  (mod2     "GDK_MOD2_MASK")
  (mod3     "GDK_MOD3_MASK")
  (mod4     "GDK_MOD4_MASK")
  (mod5     "GDK_MOD5_MASK")
  (button1  "GDK_BUTTON1_MASK")
  (button2  "GDK_BUTTON2_MASK")
  (button3  "GDK_BUTTON3_MASK")
  (button4  "GDK_BUTTON4_MASK")
  (button5  "GDK_BUTTON5_MASK")
  (release  "GDK_RELEASE_MASK")
  (modifier "GDK_MODIFIER_MASK"))

(define-gtk-enum gdkwindowedge ((include<> "gdk/gdkwindow.h"))
  (north-west "GDK_WINDOW_EDGE_NORTH_WEST")
  (north      "GDK_WINDOW_EDGE_NORTH")
  (north-east "GDK_WINDOW_EDGE_NORTH_EAST")
  (west       "GDK_WINDOW_EDGE_WEST")
  (east       "GDK_WINDOW_EDGE_EAST")
  (south-west "GDK_WINDOW_EDGE_SOUTH_WEST")
  (south      "GDK_WINDOW_EDGE_SOUTH")
  (south-east "GDK_WINDOW_EDGE_SOUTH_EAST"))

(define-gtk-enum gdkwindowtypehint ((include<> "gdk/gdkwindow.h"))
  (normal       "GDK_WINDOW_TYPE_HINT_NORMAL")
  (dialog       "GDK_WINDOW_TYPE_HINT_DIALOG")
  (menu         "GDK_WINDOW_TYPE_HINT_MENU")
  (toolbar      "GDK_WINDOW_TYPE_HINT_TOOLBAR")
  (splashscreen "GDK_WINDOW_TYPE_HINT_SPLASHSCREEN")
  (utility      "GDK_WINDOW_TYPE_HINT_UTILITY")
  (dock         "GDK_WINDOW_TYPE_HINT_DOCK")
  (desktop      "GDK_WINDOW_TYPE_HINT_DESKTOP"))

(define-gtk-enum gtkprogressbarstyle ((include<> "gtk/gtkprogressbar.h"))
  (continuous   "GTK_PROGRESS_CONTINUOUS")
  (discrete     "GTK_PROGRESS_DISCRETE"))

(define-gtk-enum gtkprogressbarorientation ((include<> "gtk/gtkprogressbar.h"))
  (left-to-right "GTK_PROGRESS_LEFT_TO_RIGHT")
  (right-to-left "GTK_PROGRESS_RIGHT_TO_LEFT")
  (bottom-to-top "GTK_PROGRESS_BOTTOM_TO_TOP")
  (top-to-bottom "GTK_PROGRESS_TOP_TO_BOTTOM"))

(define-gtk-enum-set gtkaccelgroup ((include<> "gtk/gtkaccelgroup.h"))
  (visible "GTK_ACCEL_VISIBLE")
  (locked "GTK_ACCEL_LOCKED")
  (mask "GTK_ACCEL_MASK"))

(define-gtk-enum-set gtkwidgetflags ((include<> "gtk/gtkwidget.h"))
  (toplevel "GTK_TOPLEVEL")
  (no-window "GTK_NO_WINDOW")
  (realized "GTK_REALIZED")
  (mapped "GTK_MAPPED")
  (visible "GTK_VISIBLE")
  (sensitive "GTK_SENSITIVE")
  (parent-sensitive "GTK_PARENT_SENSITIVE")
  (can-focus "GTK_CAN_FOCUS")
  (has-focus "GTK_HAS_FOCUS")
  (can-default "GTK_CAN_DEFAULT")
  (has-default "GTK_HAS_DEFAULT")
  (has-grab "GTK_HAS_GRAB")
  (rc-style "GTK_RC_STYLE")
  (composite-child "GTK_COMPOSITE_CHILD")
  (no-reparent "GTK_NO_REPARENT")
  (app-paintable "GTK_APP_PAINTABLE")
  (receives-default "GTK_RECEIVES_DEFAULT")
  (double-buffered "GTK_DOUBLE_BUFFERED")
  (no-show-all "GTK_NO_SHOW_ALL"))

(define-gtk-enum gtkwidgethelptype ((include<> "gtk/gtkwidget.h"))
  (tooltip "GTK_WIDGET_HELP_TOOLTIP")
  (whats-this "GTK_WIDGET_HELP_WHATS_THIS"))

(define-gtk-enum gtktextwindowtype ((include<> "gtk/gtktextview.h"))
  (private "GTK_TEXT_WINDOW_PRIVATE")
  (widget "GTK_TEXT_WINDOW_WIDGET")
  (text "GTK_TEXT_WINDOW_TEXT")
  (left "GTK_TEXT_WINDOW_LEFT")
  (right "GTK_TEXT_WINDOW_RIGHT")
  (top "GTK_TEXT_WINDOW_TOP")
  (bottom "GTK_TEXT_WINDOW_BOTTOM"))

(define-gtk-enum gtkimagetype ((include<> "gtk/gtkimage.h"))
  (empty "GTK_IMAGE_EMPTY")
  (pixmap "GTK_IMAGE_PIXMAP")
  (image  "GTK_IMAGE_IMAGE")
  (pixbuf "GTK_IMAGE_PIXBUF")
  (stock  "GTK_IMAGE_STOCK")
  (icon-set "GTK_IMAGE_ICON_SET")
  (animation "GTK_IMAGE_ANIMATION")
  (icon-name "GTK_IMAGE_ICON_NAME"))

(define-foreign (gtk-widget-show gtkwidget*) void)
(define-foreign (gtk-widget-show-now gtkwidget*) void)
(define-foreign (gtk-widget-hide gtkwidget*) void)
(define-foreign (gtk-widget-show-all gtkwidget*) void)
(define-foreign (gtk-widget-hide-all gtkwidget*) void)
(define-foreign (gtk-widget-map gtkwidget*) void)
(define-foreign (gtk-widget-unmap gtkwidget*) void)
(define-foreign (gtk-widget-realize gtkwidget*) void)
(define-foreign (gtk-widget-unrealize gtkwidget*) void)
(define-foreign (gtk-widget-add-accelerator gtkwidget* string gtkaccelgroup* 
                                            char
                                            gdkmodifiertype 
                                            gtkaccelgroup)
  void)
(define-foreign (gtk-widget-get-parent gtkwidget*) gtkwidget*)
(define-foreign (gtk-widget-set-parent gtkwidget* gtkwidget*) void)
(define-foreign (gtk-widget-get-parent-window gtkwidget*) gdkwindow*)
(define-foreign (gtk-widget-set-parent-window gtkwidget* gdkwindow*) void)
(define-foreign (gtk-widget-grab-default gtkwidget*) void)
(define-foreign (gtk-widget-grab-focus gtkwidget*) void)
(define-foreign (gtk-grab-add gtkwidget*) void)
(define-foreign (gtk-grab-get-current) gtkwidget*)
(define-foreign (gtk-grab-remove gtkwidget*) void)
(define (gtk-widget-set-flags widget flags)
  (void*-word-set! widget gtkobject-flags-offset 
                   (fxlogior 
                    (void*-word-ref widget gtkobject-flags-offset)
                    ((enum->marshall-out gtkwidgetflags)
                     flags))))

(define-foreign (gtk-main) void)
(define-foreign (gtk-main-level) uint)
(define-foreign (gtk-main-quit) void)
(define-foreign (gtk-main-iteration) bool)
(define-foreign (gtk-main-iteration-do bool) bool)
(define-foreign (gtk-timeout-add uint (-> (void*) bool) (maybe void*)) uint)
(define-foreign (gtk-timeout-remove uint) void)
(define-foreign (gtk-events-pending) bool)
(define-foreign (gtk-exit int) void)


(define-foreign (gtk-container-set-border-width! gtkcontainer* int) void)
(define-foreign (gtk-container-add gtkcontainer* gtkwidget*) void)

(define-foreign (gtk-hbox-new bool int) gtkhbox*)
(define-foreign (gtk-vbox-new bool int) gtkvbox*)
(define-foreign (gtk-hseparator-new) gtkwidget*)
(define-foreign (gtk-box-pack-start gtkbox* gtkwidget* bool bool int) void)
(define-foreign (gtk-box-pack-end   gtkbox* gtkwidget* bool bool int) void)
(define-foreign (gtk-misc-set-alignment gtkmisc* float float) void)
(define-foreign (gtk-misc-set-padding gtkmisc* int int) void)
(define-foreign (gtk-widget-set-size-request gtkwidget* int int) void)
(define-foreign (gtk-table-new int int bool) gtkwidget*)
(define-foreign (gtk-table-attach-defaults gtktable* gtkwidget* int int int int)
  void)
(define-foreign (gtk-table-set-row-spacing gtktable* uint uint) void)

(define-foreign (gtk-adjustment-new double double double double double double) gtkobject*)
(define-foreign (gtk-vscale-new gtkadjustment*) gtkwidget*)
(define-foreign (gtk-hscale-new gtkadjustment*) gtkwidget*)
(define-foreign (gtk-hscrollbar-new gtkadjustment*) gtkwidget*)
(define-foreign (gtk-vscrollbar-new gtkadjustment*) gtkwidget*)
(define-foreign (gtk-range-set-update-policy gtkrange* gtkupdatetype) void)
(define-foreign (gtk-scale-set-digits gtkscale* int) void)
(define-foreign (gtk-scale-set-value-pos gtkscale* gtkpositiontype) void)
(define-foreign (gtk-scale-set-draw-value gtkscale* bool) void)
(define-foreign (gtk-menu-item-new-with-label string) gtkmenuitem*)
(define-foreign (gtk-menu-item-new) gtkmenuitem*)
(define-foreign (gtk-menu-new) gtkmenu*)
(define-foreign (gtk-option-menu-new) gtkoptionmenu*)
(define-foreign (gtk-menu-shell-append gtkmenushell* gtkwidget*) void)
(define-foreign (gtk-option-menu-set-menu gtkoptionmenu* gtkwidget*) void)
(define-foreign (gtk-frame-new string) gtkframe*)
(define-foreign (gtk-frame-set-shadow-type gtkframe* gtkshadowtype) void)
(define-foreign (gtk-frame-get-shadow-type gtkframe*) gtkshadowtype)
(define-foreign (gtk-frame-set-label-align gtkframe* float float) void)
;; XXX need boxed floats to do get-frame-get-label-align...
(define-foreign (gtk-label-new string) gtkwidget*)
(define-foreign (gtk-label-set-text gtklabel* string) void)
(define-foreign (gtk-label-set-markup gtklabel* string) void)
(define-foreign (gtk-label-set-markup-with-mnemonic gtklabel* string) void)
(define-foreign (gtk-label-set-pattern gtklabel* string) void)
(define-foreign (gtk-label-set-justify gtklabel* gtkjustification) void)
(define-foreign (gtk-label-set-width-chars gtklabel* int) void)
(define-foreign (gtk-label-set-max-width-chars gtklabel* int) void)
(define-foreign (gtk-label-get gtklabel* (ret string)) void)
(define-foreign (gtk-label-parse-uline gtklabel* string) int)
(define-foreign (gtk-label-set-line-wrap gtklabel* bool) void)
(define-foreign (gtk-label-get-layout-offsets gtklabel* (ret int) (ret int)) void)
(define-foreign (gtk-label-get-mnemonic-keyval gtklabel*) uint)
(define-foreign (gtk-label-get-selectable gtklabel*) bool)
(define-foreign (gtk-label-get-text gtklabel*) string)
(define-foreign (gtk-label-new-with-mnemonic string) gtklabel*)
(define-foreign (gtk-label-select-region gtklabel* int int) void)
(define-foreign (gtk-label-set-mnemonic-widget gtklabel* gtkwidget*) void)
(define-foreign (gtk-label-set-selectable gtklabel* bool) void)
(define-foreign (gtk-label-set-text-with-mnemonic gtklabel* string) void)
(define-foreign (gtk-label-get-justify gtklabel*) gtkjustification)
(define-foreign (gtk-label-get-width-chars gtklabel*) int)
(define-foreign (gtk-label-get-max-width-chars gtklabel*) int)
(define-foreign (gtk-label-get-label gtklabel*) string)
(define-foreign (gtk-label-get-line-wrap gtklabel*) bool)
(define-foreign (gtk-label-get-mnemonic-widget gtklabel*) gtkwidget*)
(define-foreign (gtk-label-get-selection-bounds gtklabel* (ret int) (ret int)) bool)
(define-foreign (gtk-label-get-use-markup gtklabel*) bool)
(define-foreign (gtk-label-get-use-underline gtklabel*) bool)
(define-foreign (gtk-label-get-single-line-mode gtklabel*) bool)
(define-foreign (gtk-label-get-angle gtklabel*) double)
(define-foreign (gtk-label-set-label gtklabel* string) void)
(define-foreign (gtk-label-set-use-markup gtklabel* bool) void)
(define-foreign (gtk-label-set-use-underline gtklabel* bool) void)
(define-foreign (gtk-label-set-single-line-mode gtklabel* bool) void)
(define-foreign (gtk-label-set-angle gtklabel* double) void)

(define-foreign (gtk-widget-show-all gtkwidget*) void)
(define-foreign (gtk-arrow-new gtkarrowtype gtkshadowtype) gtkarrow*)
(define-foreign (gtk-alignment-new float float float float) gtkalignment*)
(define-foreign (gtk-table-attach gtktable* gtkwidget* 
                                  uint uint uint uint 
                                  gtkattachoptions gtkattachoptions
                                  uint uint) 
  void)
(define-foreign (gtk-widget-destroy gtkwidget*) void)
(define-foreign (gtk-progress-bar-new) gtkprogressbar*)
(define-foreign (gtk-progress-bar-pulse gtkprogressbar*) void)
(define-foreign (gtk-progress-bar-set-text gtkprogressbar* string) void)
(define-foreign (gtk-progress-bar-set-fraction gtkprogressbar* double) void)
(define-foreign (gtk-progress-bar-set-pulse-step gtkprogressbar* double) void)
(define-foreign (gtk-progress-bar-set-orientation gtkprogressbar* gtkprogressbarorientation) void)
(define-foreign (gtk-progress-bar-get-text gtkprogressbar*) string)
(define-foreign (gtk-progress-bar-get-fraction gtkprogressbar*) double)
(define-foreign (gtk-progress-bar-get-pulse-step gtkprogressbar*) double)
(define-foreign (gtk-progress-bar-get-orientation gtkprogressbar*) gtkprogressbarorientation)
(define-foreign (gtk-progress-bar-new-with-adjustment gtkadjustment*) gtkprogressbar*)
(define-foreign (gtk-progress-bar-set-bar-style gtkprogressbar* gtkprogressbarstyle) void)
(define-foreign (gtk-progress-bar-set-discrete-blocks gtkprogressbar* uint) void)
(define-foreign (gtk-progress-bar-set-activity-step gtkprogressbar* uint) void)
(define-foreign (gtk-progress-bar-set-activity-blocks gtkprogressbar* uint) void)
(define-foreign (gtk-progress-bar-update gtkprogressbar* double) void)

(define-foreign (gtk-statusbar-new) gtkstatusbar*)
(define-foreign (gtk-statusbar-get-context-id gtkstatusbar* string) uint)
(define-foreign (gtk-statusbar-push gtkstatusbar* uint string) uint)
(define-foreign (gtk-statusbar-pop gtkstatusbar* uint) void)
(define-foreign (gtk-statusbar-remove gtkstatusbar* uint uint) void)
(define-foreign (gtk-statusbar-set-has-resize-grip gtkstatusbar* bool) void)
(define-foreign (gtk-statusbar-get-has-resize-grip gtkstatusbar*) bool)

(define-foreign (gtk-button-new) gtkbutton*)
(define-foreign (gtk-button-new-with-label string) gtkbutton*)
(define-foreign (gtk-button-new-with-mnemonic string) gtkbutton*)
(define-foreign (gtk-button-new-from-stock string) gtkbutton*)
(define-foreign (gtk-button-pressed gtkbutton*) void)
(define-foreign (gtk-button-released gtkbutton*) void)
(define-foreign (gtk-button-clicked gtkbutton*) void)
(define-foreign (gtk-button-enter gtkbutton*) void)
(define-foreign (gtk-button-leave gtkbutton*) void)
(define-foreign (gtk-button-set-relief gtkbutton* gtkreliefstyle) void)
(define-foreign (gtk-button-get-relief gtkbutton*) gtkreliefstyle)
(define-foreign (gtk-button-get-label gtkbutton*) string)
(define-foreign (gtk-button-set-label gtkbutton* string) void)
(define-foreign (gtk-button-get-use-stock gtkbutton*) bool)
(define-foreign (gtk-button-set-use-stock gtkbutton* bool) void)
(define-foreign (gtk-button-get-use-underline gtkbutton*) bool)
(define-foreign (gtk-button-set-use-underline gtkbutton* bool) void)
(define-foreign (gtk-button-set-focus-on-click gtkbutton* bool) void)
(define-foreign (gtk-button-get-focus-on-click gtkbutton*) bool)
(define-foreign (gtk-button-set-alignment gtkbutton* float float) void)
;XXX (define-foreign (gtk-button-get-alignment gtkbutton* (ret float) (ret float)) void)

(define-foreign (gtk-check-button-new) gtkcheckbutton*)
(define-foreign (gtk-check-button-new-with-label string) gtkcheckbutton*)
(define-foreign (gtk-check-button-new-with-mnemonic string) gtkcheckbutton*)

;(define-foreign (gtk-radio-button-new gslist*) gtkradiobutton*)
(define-foreign (gtk-radio-button-new-from-widget gtkradiobutton*) 
  gtkradiobutton*)
(define-foreign (gtk-radio-button-new-with-label (maybe void*) string) 
  gtkradiobutton*)
(define-foreign (gtk-radio-button-new-with-label-from-widget 
                 gtkradiobutton* string) gtkradiobutton*)
;(define-foreign (gtk-radio-button-new-with-mnemonic gslist* string) gtkradiobutton*)
(define-foreign (gtk-radio-button-new-with-mnemonic-from-widget 
                 gtkradiobutton* string) gtkradiobutton*)
;(define-foreign (gtk-radio-button-set-group gtkradiobutton* gslist*) void)
;(define-foreign (gtk-radio-button-get-group gtkradiobutton*) gslist*)

(define-foreign (gtk-toggle-button-new) gtktogglebutton*)
(define-foreign (gtk-toggle-button-new-with-label string) gtktogglebutton*)
(define-foreign (gtk-toggle-button-new-with-mnemonic string) gtktogglebutton*)
(define-foreign (gtk-toggle-button-set-mode gtktogglebutton* bool) void)
(define-foreign (gtk-toggle-button-get-mode gtktogglebutton*) bool)
(define-foreign (gtk-toggle-button-toggled gtktogglebutton*) void)
(define-foreign (gtk-toggle-button-get-active gtktogglebutton*) bool)
(define-foreign (gtk-toggle-button-set-active gtktogglebutton* bool) void)
(define-foreign (gtk-toggle-button-set-inconsistent gtktogglebutton* bool) void)
(define-foreign (gtk-toggle-button-get-inconsistent gtktogglebutton*) bool)

(define-foreign (gtk-entry-new) gtkentry*)
(define-foreign (gtk-entry-new-with-max-length int) gtkentry*)
(define-foreign (gtk-entry-set-text gtkentry* string) void)
(define-foreign (gtk-entry-append-text gtkentry* string) void)
(define-foreign (gtk-entry-prepend-text gtkentry* string) void)
(define-foreign (gtk-entry-set-position gtkentry* int) void)
(define-foreign (gtk-entry-get-text gtkentry*) string)
(define-foreign (gtk-entry-select-region gtkentry* int int) void)
(define-foreign (gtk-entry-set-visibility gtkentry* bool) void)
(define-foreign (gtk-entry-set-invisible-char gtkentry* uint) void)
(define-foreign (gtk-entry-set-editable gtkentry* bool) void)
(define-foreign (gtk-entry-set-max-length gtkentry* int) void)
(define-foreign (gtk-entry-get-activates-default gtkentry*) bool)
(define-foreign (gtk-entry-get-has-frame gtkentry*) bool)
(define-foreign (gtk-entry-get-width-chars gtkentry*) int)
(define-foreign (gtk-entry-set-activates-default gtkentry* bool) void)
(define-foreign (gtk-entry-set-has-frame gtkentry* bool) void)
(define-foreign (gtk-entry-set-width-chars gtkentry* int) void)
(define-foreign (gtk-entry-get-invisible-char gtkentry*) uint)
(define-foreign (gtk-entry-set-alignment gtkentry* float) void)
(define-foreign (gtk-entry-get-alignment gtkentry*) float)
;(define-foreign (gtk-entry-get-layout gtkentry*) pangolayout*)
(define-foreign (gtk-entry-get-layout-offsets gtkentry* (ret int) (ret int)) void)
(define-foreign (gtk-entry-layout-index-to-text-index gtkentry* int) int)
(define-foreign (gtk-entry-text-index-to-layout-index gtkentry* int) int)
(define-foreign (gtk-entry-get-max-length gtkentry*) int)
(define-foreign (gtk-entry-get-visibility gtkentry*) bool)
(define-foreign (gtk-entry-set-completion gtkentry* gtkentrycompletion*) void)
(define-foreign (gtk-entry-get-completion gtkentry*) gtkentrycompletion*)

(define-foreign (gtk-container-set-border-width gtkcontainer* uint) void)
(define-foreign (gtk-container-get-border-width gtkcontainer*) uint)


(define-foreign (gtk-tooltips-new) gtktooltips*)
(define-foreign (gtk-tooltips-set-tip gtktooltips* gtkwidget* string (maybe string)) void)

(define-foreign (gtk-menu-bar-new) gtkmenubar*)

(define-foreign (gtk-accel-group-new) gtkaccelgroup*)
;; (define-foreign (gtk-accel-group-attach void* void*) void) ;; XXX

(define-foreign (gtk-menu-item-set-submenu gtkmenuitem* gtkwidget*) void)
(define-foreign (gtk-menu-item-get-submenu gtkmenuitem*) gtkwidget*)

(define-foreign (gtk-check-menu-item-new) gtkcheckmenuitem*)
(define-foreign (gtk-check-menu-item-new-with-label string) gtkcheckmenuitem*)
(define-foreign (gtk-check-menu-item-new-with-mnemonic string) gtkcheckmenuitem*)
(define-foreign (gtk-check-menu-item-set-active gtkcheckmenuitem* bool) void)
(define-foreign (gtk-check-menu-item-get-active gtkcheckmenuitem*) bool)
(define-foreign (gtk-check-menu-item-toggled gtkcheckmenuitem*) void)
(define-foreign (gtk-check-menu-item-set-inconsistent gtkcheckmenuitem* bool) void)
(define-foreign (gtk-check-menu-item-get-inconsistent gtkcheckmenuitem*) bool)

(define-foreign (gtk-radio-menu-item-new (maybe void*)) gtkradiomenuitem*)
(define-foreign (gtk-radio-menu-item-new-with-label (maybe void*) string) gtkradiomenuitem*)
(define-foreign (gtk-radio-menu-item-new-with-mnemonic (maybe void*) string) gtkradiomenuitem*)
(define-foreign (gtk-radio-menu-item-get-group gtkradiomenuitem*) void*)
(define-foreign (gtk-radio-menu-item-set-group gtkradiomenuitem* (maybe void*)) void)

(define-foreign (gtk-toolbar-get-type) uint)
(define-foreign (gtk-toolbar-new) gtktoolbar*)
(define-foreign (gtk-toolbar-get-orientation gtktoolbar*) gtkorientation)
(define-foreign (gtk-toolbar-set-orientation gtktoolbar* gtkorientation) void)
(define-foreign (gtk-toolbar-get-tooltips gtktoolbar*) bool)
(define-foreign (gtk-toolbar-set-tooltips gtktoolbar* bool) void)
(define-foreign (gtk-toolbar-get-style gtktoolbar*) gtktoolbarstyle)
(define-foreign (gtk-toolbar-set-style gtktoolbar* gtktoolbarstyle) void)
'(define-foreign (gtk-toolbar-append-item 
                 gtktoolbar* string string string gtkwidget* 
                 (-> (gtkwidget* void*) void) (maybe void*))
  void)
(define-foreign (gtk-toolbar-append-space gtktoolbar*) void)
(define-foreign (gtk-toolbar-append-widget gtktoolbar* gtkwidget* string string) void)
(define-foreign (gtk-toolbar-prepend-widget gtktoolbar* gtkwidget* string string) void)
(define-foreign (gtk-toolbar-insert-widget gtktoolbar* gtkwidget* string string int) void)
'(define-foreign (gtk-toolbar-append-element 
                 gtktoolbar* uint (maybe gtkwidget*) 
                 (maybe string) string (maybe string) 
                 gtkwidget* (-> (gtkwidget* void*) void) (maybe void*)) 
  gtkwidget*)
'(define-foreign (gtk-toolbar-prepend-element 
                 gtktoolbar* uint (maybe gtkwidget*) 
                 (maybe string) string (maybe string) 
                 gtkwidget* (-> (gtkwidget* void*) void) (maybe void*)) 
  void*)
'(define-foreign (gtk-toolbar-prepend-element 
                 gtktoolbar* uint (maybe gtkwidget*)
                 (maybe string) string (maybe string) 
                 gtkwidget* (-> (gtkwidget* void*) void) (maybe void*) int) 
  gtkwidget*)

(define-foreign (gtk-pixmap-new gdkpixmap* (maybe gdkbitmap*)) gtkpixmap*)

(define-foreign (gtk-combo-new) gtkcombo*)
(define-foreign (gtk-combo-set-value-in-list gtkcombo* bool bool) void)
(define-foreign (gtk-combo-set-use-arrows gtkcombo* bool) void)
(define-foreign (gtk-combo-set-use-arrows-always gtkcombo* bool) void)
(define-foreign (gtk-combo-set-case-sensitive gtkcombo* bool) void)
(define-foreign (gtk-combo-set-item-string gtkcombo* gtkitem* string) void)
(define-foreign (gtk-combo-set-popdown-strings gtkcombo* glist*) void)
(define-foreign (gtk-combo-disable-activate gtkcombo*) void)

;; Deprecated in gtk2
;(define-foreign (gtk-text-new (maybe gtkadjustment*) (maybe gtkadjustment*)) gtktext*)
;(define-foreign (gtk-text-set-editable  gtktext* bool) void)
;(define-foreign (gtk-text-set-word-wrap gtktext* bool) void)
;(define-foreign (gtk-text-set-line-wrap gtktext* bool) void)
;(define-foreign (gtk-text-set-adjustments gtktext* gtkadjustment* gtkadjustment*) void)
;(define-foreign (gtk-text-set-point gtktext* uint) void)
;(define-foreign (gtk-text-get-point gtktext*) uint)
;(define-foreign (gtk-text-get-length gtktext*) uint)
;(define-foreign (gtk-text-freeze gtktext*) void)
;(define-foreign (gtk-text-thaw gtktext*) void)
;(define-foreign (gtk-text-insert gtktext* gdkfont* gdkcolor* gdkcolor* string int) void)
;(define-foreign (gtk-text-backward-delete gtktext* uint) bool)
;(define-foreign (gtk-text-forward-delete gtktext* uint) bool)

(define-foreign (gtk-text-view-new) gtktextview*)
(define-foreign (gtk-text-view-new-with-buffer gtktextbuffer*) gtktextview*)
(define-foreign (gtk-text-view-set-buffer gtktextview* gtktextbuffer*) void)
(define-foreign (gtk-text-view-get-buffer gtktextview*) gtktextbuffer*)
(define-foreign (gtk-text-view-scroll-to-mark gtktextview* 
                                              gtktextmark*
                                              double bool double double) void)
(define-foreign (gtk-text-view-scroll-to-iter gtktextview* gtktextiter* 
                                              double bool double double) void)
(define-foreign (gtk-text-view-scroll-mark-onscreen gtktextview* gtktextmark*) void)
(define-foreign (gtk-text-view-place-cursor-onscreen gtktextview*) bool)
(define-foreign (gtk-text-view-get-visible-rect gtktextview* gdkrectangle*) void)
(define-foreign (gtk-text-view-get-iter-location gtktextview* 
                                                 gtktextiter* gdkrectangle*) void)
(define-foreign (gtk-text-view-get-line-at-y gtktextview* 
                                             gtktextiter* int int*) void)
(define-foreign (gtk-text-view-get-line-yrange gtktextview* 
                                               gtktextiter* int* int*) void)
(define-foreign (gtk-text-view-get-iter-at-location gtktextview* 
                                                    gtktextiter* int int) void)
(define-foreign (gtk-text-view-get-iter-at-position gtktextview* 
                                                    gtktextiter* int* int int) void)
(define-foreign (gtk-text-view-buffer-to-window-coords gtktextview*
                                                       uint int int int* int*) void)
(define-foreign (gtk-text-view-window-to-buffer-coords gtktextview*
                                                       uint int int int* int*) void)
(define-foreign (gtk-text-view-get-window gtktextview* gtktextwindowtype) gdkwindow*)
(define-foreign (gtk-text-view-get-window-type gtktextview* gdkwindow*) gtktextwindowtype)
(define-foreign (gtk-text-view-set-border-window-size gtktextview* gtktextwindowtype int) void)
(define-foreign (gtk-text-view-get-border-window-size gtktextview* gtktextwindowtype) int)
(define-foreign (gtk-text-view-forward-display-line gtktextview* gtktextiter*) bool)
(define-foreign (gtk-text-view-backward-display-line gtktextview* gtktextiter*) bool)
(define-foreign (gtk-text-view-forward-display-line-end gtktextview* gtktextiter*) bool)
(define-foreign (gtk-text-view-backward-display-line-start gtktextview* gtktextiter*) bool)
(define-foreign (gtk-text-view-starts-display-line gtktextview* gtktextiter*) bool)
(define-foreign (gtk-text-view-move-visually gtktextview* gtktextiter* int) bool)
(define-foreign (gtk-text-view-add-child-at-anchor gtktextview* 
                                                   gtkwidget* gtktextchildanchor*) void)
(define-foreign (gtk-text-child-anchor-new) gtktextchildanchor*)
(define-foreign (gtk-text-child-anchor-get-widgets gtktextchildanchor*) glist*)
(define-foreign (gtk-text-child-anchor-get-deleted gtktextchildanchor*) glist*)
(define-foreign (gtk-text-view-add-child-in-window
                 gtktextview* gtkwidget* gtktextwindowtype int int) void)
(define-foreign (gtk-text-view-move-child gtktextview* gtkwidget* int int) void)
(define-foreign (gtk-text-view-set-wrap-mode gtktextview* gtkwrapmode) void)
(define-foreign (gtk-text-view-get-wrap-mode gtktextview*) gtkwrapmode)
(define-foreign (gtk-text-view-set-editable gtktextview* bool) void)
(define-foreign (gtk-text-view-get-editable gtktextview*) bool)
(define-foreign (gtk-text-view-set-cursor-visible gtktextview* bool) void)
(define-foreign (gtk-text-view-get-cursor-visible gtktextview*) bool)
(define-foreign (gtk-text-view-set-overwrite gtktextview* bool) void)
(define-foreign (gtk-text-view-get-overwrite gtktextview*) bool)
(define-foreign (gtk-text-view-set-pixels-above-lines gtktextview* int) void)
(define-foreign (gtk-text-view-get-pixels-above-lines gtktextview*) int)
(define-foreign (gtk-text-view-set-pixels-below-lines gtktextview* int) void)
(define-foreign (gtk-text-view-get-pixels-below-lines gtktextview*) int)
(define-foreign (gtk-text-view-set-pixels-inside-wrap gtktextview* int) void)
(define-foreign (gtk-text-view-get-pixels-inside-wrap gtktextview*) int)

(define-foreign (gtk-text-buffer-new (maybe gtktexttagtable*)) gtktextbuffer*)
(define-foreign (gtk-text-buffer-get-line-count gtktextbuffer*) int)
(define-foreign (gtk-text-buffer-get-char-count gtktextbuffer*) int)
(define-foreign (gtk-text-buffer-get-tag-table gtktextbuffer*) gtktexttagtable*)
(define-foreign (gtk-text-buffer-set-text gtktextbuffer* string int) void)
(define-foreign (gtk-text-buffer-insert gtktextbuffer* gtktextiter* string int) void)
(define-foreign (gtk-text-buffer-insert-at-cursor gtktextbuffer* string int) void)
(define-foreign (gtk-text-buffer-insert-interactive gtktextbuffer* gtktextiter* string int bool) bool)
(define-foreign (gtk-text-buffer-insert-interactive-at-cursor gtktextbuffer* string int bool) bool)
(define-foreign (gtk-text-buffer-insert-range gtktextbuffer* gtktextiter* gtktextiter* gtktextiter*) void)
(define-foreign (gtk-text-buffer-insert-range-interactive gtktextbuffer* gtktextiter* gtktextiter* gtktextiter* bool) bool)
;; can't handle varargs with define-foreign
;(define-foreign (gtk-text-buffer-insert-with-tags gtktextbuffer* gtktextiter* string int gtktexttag* ...) void)
;(define-foreign (gtk-text-buffer-insert-with-tags-by-name gtktextbuffer* gtktextiter* string int string ...) void)
(define-foreign (gtk-text-buffer-delete gtktextbuffer* gtktextiter* gtktextiter*) void)
(define-foreign (gtk-text-buffer-delete-interactive gtktextbuffer* gtktextiter* gtktextiter* bool) bool)
(define-foreign (gtk-text-buffer-backspace gtktextbuffer* gtktextiter* bool bool) bool)
(define-foreign (gtk-text-buffer-get-text gtktextbuffer* gtktextiter* gtktextiter* bool) string)
(define-foreign (gtk-text-buffer-get-slice gtktextbuffer* gtktextiter* gtktextiter* bool) string)
(define-foreign (gtk-text-buffer-insert-pixbuf gtktextbuffer* gtktextiter* gdkpixbuf*) void)
(define-foreign (gtk-text-buffer-insert-child-anchor gtktextbuffer* gtktextiter* gtktextchildanchor*) void)
(define-foreign (gtk-text-buffer-create-child-anchor gtktextbuffer* gtktextiter*) gtktextchildanchor*)
(define-foreign (gtk-text-buffer-create-mark gtktextbuffer* (maybe string) gtktextiter* bool) gtktextmark*)
(define-foreign (gtk-text-buffer-move-mark gtktextbuffer* gtktextmark* gtktextiter*) void)
(define-foreign (gtk-text-buffer-delete-mark gtktextbuffer* gtktextmark*) void)
(define-foreign (gtk-text-buffer-get-mark gtktextbuffer* string) (maybe gtktextmark*))
(define-foreign (gtk-text-buffer-move-mark-by-name gtktextbuffer* string gtktextiter*) void)
(define-foreign (gtk-text-buffer-delete-mark-by-name gtktextbuffer* string) void)
(define-foreign (gtk-text-buffer-get-insert gtktextbuffer*) gtktextmark*)
(define-foreign (gtk-text-buffer-get-selection-bound gtktextbuffer*) gtktextmark*)
(define-foreign (gtk-text-buffer-place-cursor gtktextbuffer* gtktextiter*) void)
(define-foreign (gtk-text-buffer-select-range gtktextbuffer* gtktextiter* gtktextiter*) void)
(define-foreign (gtk-text-buffer-apply-tag gtktextbuffer* gtktexttag* gtktextiter* gtktextiter*) void)
(define-foreign (gtk-text-buffer-remove-tag gtktextbuffer* gtktexttag* gtktextiter* gtktextiter*) void)
(define-foreign (gtk-text-buffer-apply-tag-by-name gtktextbuffer* string gtktextiter* gtktextiter*) void)
(define-foreign (gtk-text-buffer-remove-tag-by-name gtktextbuffer* string gtktextiter* gtktextiter*) void)
(define-foreign (gtk-text-buffer-remove-all-tags gtktextbuffer* gtktextiter* gtktextiter*) void)
;; Again, var args are not yet supported in define-foreign.
;; (But then again, why not support them?)
;(define-foreign (gtk-text-buffer-create-tag gtktextbuffer* string string ...) gtktexttag*)
(define-foreign (gtk-text-buffer-get-iter-at-line-offset gtktextbuffer* gtktextiter* int int) void)
(define-foreign (gtk-text-buffer-get-iter-at-line-index gtktextbuffer* gtktextiter* int int) void)
(define-foreign (gtk-text-buffer-get-iter-at-offset gtktextbuffer* gtktextiter* int) void)
(define-foreign (gtk-text-buffer-get-iter-at-line gtktextbuffer* gtktextiter* int) void)
(define-foreign (gtk-text-buffer-get-start-iter gtktextbuffer* gtktextiter*) void)
(define-foreign (gtk-text-buffer-get-end-iter gtktextbuffer* gtktextiter*) void)
(define-foreign (gtk-text-buffer-get-bounds gtktextbuffer* gtktextiter* gtktextiter*) void)
(define-foreign (gtk-text-buffer-get-iter-at-mark gtktextbuffer* gtktextiter* gtktextmark*) void)
(define-foreign (gtk-text-buffer-get-iter-at-child-anchor gtktextbuffer* gtktextiter* gtktextchildanchor*) void)
(define-foreign (gtk-text-buffer-get-modified gtktextbuffer*) bool)
(define-foreign (gtk-text-buffer-set-modified gtktextbuffer* bool) void)
(define-foreign (gtk-text-buffer-add-selection-clipboard gtktextbuffer* gtkclipboard*) void)
(define-foreign (gtk-text-buffer-remove-selection-clipboard gtktextbuffer* gtkclipboard*) void)
(define-foreign (gtk-text-buffer-cut-clipboard gtktextbuffer* gtkclipboard* bool) void)
(define-foreign (gtk-text-buffer-copy-clipboard gtktextbuffer* gtkclipboard*) void)
(define-foreign (gtk-text-buffer-paste-clipboard gtktextbuffer* gtkclipboard* (maybe gtktextiter*) bool) void)
(define-foreign (gtk-text-buffer-get-selection-bounds gtktextbuffer* gtktextiter* gtktextiter*) bool)
(define-foreign (gtk-text-buffer-delete-selection gtktextbuffer* bool bool) bool)
(define-foreign (gtk-text-buffer-begin-user-action gtktextbuffer*) void)
(define-foreign (gtk-text-buffer-end-user-action gtktextbuffer*) void)

(define-foreign (gtk-text-iter-get-buffer gtktextiter*) gtktextbuffer*)
(define-foreign (gtk-text-iter-copy gtktextiter*) gtktextiter*)
(define-foreign (gtk-text-iter-free gtktextiter*) void)
(define-foreign (gtk-text-iter-get-offset gtktextiter*) int)
(define-foreign (gtk-text-iter-get-line gtktextiter*) int)
(define-foreign (gtk-text-iter-get-line-offset gtktextiter*) int)
(define-foreign (gtk-text-iter-get-line-index gtktextiter*) int)
(define-foreign (gtk-text-iter-get-visible-line-offset gtktextiter*) int)
(define-foreign (gtk-text-iter-get-visible-line-index gtktextiter*) int)
(define-foreign (gtk-text-iter-get-char gtktextiter*) uint) ;; gunichar is guint32...
(define-foreign (gtk-text-iter-get-slice gtktextiter* gtktextiter*) string)
(define-foreign (gtk-text-iter-get-text   gtktextiter* gtktextiter*) string)
(define-foreign (gtk-text-iter-get-visible-slice gtktextiter* gtktextiter*) string)
(define-foreign (gtk-text-iter-get-visible-text  gtktextiter* gtktextiter*) string)
(define-foreign (gtk-text-iter-get-child-anchor gtktextiter*) gtktextchildanchor*)
(define-foreign (gtk-text-iter-get-toggled-tags gtktextiter* bool) gslist*)
(define-foreign (gtk-text-iter-begins-tag gtktextiter* gtktexttag*) bool)
(define-foreign (gtk-text-iter-ends-tag gtktextiter* gtktexttag*) bool)
(define-foreign (gtk-text-iter-toggles-tag gtktextiter* gtktexttag*) bool)
(define-foreign (gtk-text-iter-has-tag gtktextiter* gtktexttag*) bool)
(define-foreign (gtk-text-iter-get-tags gtktextiter*) gslist*)
(define-foreign (gtk-text-iter-editable gtktextiter* bool) bool)
(define-foreign (gtk-text-iter-can-insert gtktextiter* bool) bool)
(define-foreign (gtk-text-iter-starts-word gtktextiter*) bool)
(define-foreign (gtk-text-iter-ends-word gtktextiter*) bool)
(define-foreign (gtk-text-iter-inside-word gtktextiter*) bool)
(define-foreign (gtk-text-iter-starts-sentence gtktextiter*) bool)
(define-foreign (gtk-text-iter-ends-sentence gtktextiter*) bool)
(define-foreign (gtk-text-iter-inside-sentence gtktextiter*) bool)
(define-foreign (gtk-text-iter-starts-line gtktextiter*) bool)
(define-foreign (gtk-text-iter-ends-line gtktextiter*) bool)
(define-foreign (gtk-text-iter-is-cursor-position gtktextiter*) bool)
(define-foreign (gtk-text-iter-get-chars-in-line gtktextiter*) int)
(define-foreign (gtk-text-iter-get-bytes-in-line gtktextiter*) int)
;(define-foreign (gtk-text-iter-get-attributes gtktextiter* gtktextattributes*) bool)
;(define-foreign (gtk-text-iter-get-language gtktextiter*) pangolanguage*)
(define-foreign (gtk-text-iter-is-end gtktextiter*) bool)
(define-foreign (gtk-text-iter-is-start gtktextiter*) bool)

(define-foreign (gtk-text-iter-forward-char gtktextiter*) bool)
(define-foreign (gtk-text-iter-backward-char gtktextiter*) bool)
(define-foreign (gtk-text-iter-forward-chars gtktextiter* int) bool)
(define-foreign (gtk-text-iter-backward-chars gtktextiter* int) bool)
(define-foreign (gtk-text-iter-forward-line gtktextiter*) bool)
(define-foreign (gtk-text-iter-backward-line gtktextiter*) bool)
(define-foreign (gtk-text-iter-forward-lines gtktextiter* int) bool)
(define-foreign (gtk-text-iter-backward-lines gtktextiter* int) bool)
(define-foreign (gtk-text-iter-forward-word-end gtktextiter*) bool)
(define-foreign (gtk-text-iter-backward-word-start gtktextiter*) bool)
(define-foreign (gtk-text-iter-forward-word-ends gtktextiter* int) bool)
(define-foreign (gtk-text-iter-backward-word-starts gtktextiter* int) bool)
(define-foreign (gtk-text-iter-forward-visible-word-end gtktextiter*) bool)
(define-foreign (gtk-text-iter-backward-visible-word-start gtktextiter*) bool)
(define-foreign (gtk-text-iter-forward-visible-word-ends gtktextiter* int) bool)
(define-foreign (gtk-text-iter-backward-visible-word-starts gtktextiter* int) bool)
(define-foreign (gtk-text-iter-forward-cursor-position gtktextiter*) bool)
(define-foreign (gtk-text-iter-backward-cursor-position gtktextiter*) bool)
(define-foreign (gtk-text-iter-forward-cursor-positions gtktextiter* int) bool)
(define-foreign (gtk-text-iter-backward-cursor-positions gtktextiter* int) bool)
(define-foreign (gtk-text-iter-forward-visible-cursor-position gtktextiter*) bool)
(define-foreign (gtk-text-iter-backward-visible-cursor-position gtktextiter*) bool)
(define-foreign (gtk-text-iter-forward-visible-cursor-positions gtktextiter* int) bool)
(define-foreign (gtk-text-iter-backward-visible-cursor-positions gtktextiter* int) bool)

(define-foreign (gtk-text-iter-set-offset gtktextiter* int) void)
(define-foreign (gtk-text-iter-set-line gtktextiter* int) void)
(define-foreign (gtk-text-iter-set-line-offset gtktextiter* int) void)
(define-foreign (gtk-text-iter-set-line-index gtktextiter* int) void)
(define-foreign (gtk-text-iter-forward-to-end gtktextiter*) void)
(define-foreign (gtk-text-iter-forward-to-line-end gtktextiter*) void)
(define-foreign (gtk-text-iter-set-visible-line-offset gtktextiter* int) void)
(define-foreign (gtk-text-iter-set-visible-line-index gtktextiter* int) void)

(define-foreign (gtk-text-iter-forward-to-tag-toggle gtktextiter* gtktexttag*) bool)
(define-foreign (gtk-text-iter-backward-to-tag-toggle gtktextiter* gtktexttag*) bool)
(define-foreign (gtk-text-iter-forward-find-char gtktextiter* (-> (uint void*) bool) void* gtktextiter*) bool)
(define-foreign (gtk-text-iter-backward-find-char gtktextiter* (-> (uint void*) bool) void* gtktextiter*) bool)
;; FSK is too lazy to add the gtktextsearchflags enum
;(define-foreign (gtk-text-iter-forward-search gtktextiter* string gtktextsearchflags gtktextiter* gtktextiter* gtktextiter*) bool)
;(define-foreign (gtk-text-iter-backward-search gtktextiter* string gtktextsearchflags gtktextiter* gtktextiter* gtktextiter*) bool)
(define-foreign (gtk-text-iter-equal gtktextiter* gtktextiter*) bool)
(define-foreign (gtk-text-iter-compare gtktextiter* gtktextiter*) bool)
(define-foreign (gtk-text-iter-in-range gtktextiter* gtktextiter* gtktextiter*) bool)
(define-foreign (gtk-text-iter-order gtktextiter* gtktextiter*) void)

(define-foreign (gtk-clipboard-get gdkatom*) gtkclipboard*)
; FSK is too lazy to add gdkdisplay* now
;(define-foreign (gtk-clipboard-get-for-display gdkdisplay* gdkatom*) gtkclipboard*)
;(define-foreign (gtk-clipboard-get-display gtkclipboard*) gdkdisplay*)
(define-foreign (gtk-clipboard-set-text gtkclipboard* string int) void)
(define-foreign (gtk-clipboard-set-image gtkclipboard* gdkpixbuf*) void)

(define-foreign (gtk-dialog-new) gtkdialog*)
(define-foreign (gtk-dialog-run gtkdialog*) int)
(define-foreign (gtk-dialog-response gtkdialog* int) void)
(define-foreign (gtk-dialog-add-button gtkdialog* string int) gtkwidget*)
(define-foreign (gtk-dialog-add-action-widget gtkdialog* gtkwidget* int) void)
(define-foreign (gtk-dialog-get-has-separator gtkdialog*) bool)
(define-foreign (gtk-dialog-set-default-response gtkdialog* int) void)
(define-foreign (gtk-dialog-set-has-separator gtkdialog* bool) void)
(define-foreign (gtk-dialog-set-response-sensitive gtkdialog* int bool) void)
(define-foreign (gtk-alternative-dialog-button-order gdkscreen*) bool)
(define-foreign (gtk-dialog-set-alternative-button-order-from-array 
                 gtkdialog* int int*) void)

(define-foreign (gtk-invisible-new) gtkinvisible*)
(define-foreign (gtk-invisible-new-for-screen gdkscreen*) gtkinvisible*)
(define-foreign (gtk-invisible-set-screen gtkinvisible* gdkscreen*) void)
(define-foreign (gtk-invisible-get-screen gtkinvisible*) gdkscreen*)

;(define-foreign (gtk-message-dialog-new gtkwindow* uint 

(define-foreign (gtk-message-dialog-new gtkwindow* gtkdialogflags 
                                        gtkmessagetype gtkbuttonstype string) 
  gtkmessagedialog*)
(define-foreign (gtk-message-dialog-new-with-markup gtkwindow* gtkdialogflags
                                                    gtkmessagetype gtkbuttonstype
                                                    string)
  gtkmessagedialog*)
(define-foreign (gtk-message-dialog-set-markup gtkmessagedialog* string) void)
(define-foreign (gtk-message-dialog-format-secondary-text gtkmessagedialog* string) 
  void)
(define-foreign (gtk-message-dialog-format-secondary-markup gtkmessagedialog* string)
  void)

(define-foreign (gtk-window-new gtkwindowtype) gtkwindow*)
(define-foreign (gtk-window-set-title gtkwindow* string) void)
(define-foreign (gtk-window-set-wmclass gtkwindow* string string) void)
(define-foreign (gtk-window-set-policy gtkwindow* int int int) void)
(define-foreign (gtk-window-set-resizable gtkwindow* bool) void)
(define-foreign (gtk-window-get-resizable gtkwindow*) bool)
(define-foreign (gtk-window-add-accel-group gtkwindow* gtkaccelgroup*) void)
(define-foreign (gtk-window-remove-accel-group gtkwindow* gtkaccelgroup*) void)
(define-foreign (gtk-window-activate-focus gtkwindow*) bool)
(define-foreign (gtk-window-activate-default gtkwindow*) bool)
(define-foreign (gtk-window-set-modal gtkwindow* bool) void)
(define-foreign (gtk-window-set-default-size gtkwindow* int int) void)
(define-foreign (gtk-window-set-geometry-hints gtkwindow* gtkwidget* gdkgeometry* gdkwindowhints) void)
(define-foreign (gtk-window-set-gravity gtkwindow* gdkgravity) void)
(define-foreign (gtk-window-get-gravity gtkwindow*) gdkgravity)
(define-foreign (gtk-window-set-position gtkwindow* gtkwindowposition) void)
(define-foreign (gtk-window-set-transient-for gtkwindow* gtkwindow*) void)
(define-foreign (gtk-window-set-destroy-with-parent gtkwindow* bool) void)
(define-foreign (gtk-window-set-screen gtkwindow* gdkscreen*) void)
(define-foreign (gtk-window-get-screen gtkwindow*) gdkscreen*)
(define-foreign (gtk-window-is-active gtkwindow*) bool)
(define-foreign (gtk-window-has-toplevel-focus gtkwindow*) bool)
; gtk-window-list-toplevels
(define-foreign (gtk-window-add-mnemonic gtkwindow* uint gtkwidget*) void)
(define-foreign (gtk-window-remove-mnemonic gtkwindow* uint gtkwidget*) void)
(define-foreign (gtk-window-mnemonic-activate gtkwidget* uint gdkmodifiertype) bool)
(define-foreign (gtk-window-activate-key gtkwidget* gdkeventkey*) bool)
(define-foreign (gtk-window-propagate-key-event gtkwidget* gdkeventkey*) bool)
(define-foreign (gtk-window-get-focus gtkwindow*) gtkwidget*)
(define-foreign (gtk-window-set-focus gtkwindow* gtkwidget*) void)
(define-foreign (gtk-window-set-default gtkwindow* gtkwidget*) void)
(define-foreign (gtk-window-present gtkwindow*) void)
(define-foreign (gtk-window-iconify gtkwindow*) void)
(define-foreign (gtk-window-deiconify gtkwindow*) void)
(define-foreign (gtk-window-stick gtkwindow*) void)
(define-foreign (gtk-window-unstick gtkwindow*) void)
(define-foreign (gtk-window-maximize gtkwindow*) void)
(define-foreign (gtk-window-unmaximize gtkwindow*) void)
(define-foreign (gtk-window-fullscreen gtkwindow*) void)
(define-foreign (gtk-window-unfullscreen gtkwindow*) void)

(define-foreign (gtk-window-set-keep-above gtkwindow* bool) void)
(define-foreign (gtk-window-set-keep-below gtkwindow* bool) void)
(define-foreign (gtk-window-begin-resize-drag gtkwindow* gdkwindowedge int int int uint) void)
(define-foreign (gtk-window-begin-move-drag gtkwindow* int int int uint) void)
(define-foreign (gtk-window-set-decorated gtkwindow* bool) void)
(define-foreign (gtk-window-set-frame-dimensions gtkwindow* int int int int) void)
(define-foreign (gtk-window-set-has-frame gtkwindow* bool) void)
(define-foreign (gtk-window-set-mnemonic-modifier gtkwindow* gdkmodifiertype) void)
(define-foreign (gtk-window-set-role gtkwindow* string) void)
(define-foreign (gtk-window-set-type-hint gtkwindow* gdkwindowtypehint) void)
(define-foreign (gtk-window-set-skip-taskbar-hint gtkwindow* bool) void)
(define-foreign (gtk-window-set-skip-pager-hint gtkwindow* bool) void)
(define-foreign (gtk-window-set-accept-focus gtkwindow* bool) void)
(define-foreign (gtk-window-set-focus-on-map gtkwindow* bool) void)
(define-foreign (gtk-window-get-decorated gtkwindow*) bool)
;(define-foreign (gtk-window-get-default-icon-list) glist*)
(define-foreign (gtk-window-get-default-size gtkwindow* (ret int) (ret int)) void)
(define-foreign (gtk-window-get-destroy-with-parent gtkwindow*) bool)
(define-foreign (gtk-window-get-frame-dimensions 
                 gtkwindow* (ret int) (ret int) (ret int) (ret int))  void)
(define-foreign (gtk-window-get-has-frame gtkwindow*) bool)
(define-foreign (gtk-window-get-icon gtkwindow*) gdkpixbuf*)
;(define-foreign (gtk-window-get-icon-list gtkwindow*) gslist*)
(define-foreign (gtk-window-get-icon-name gtkwindow*) string)
(define-foreign (gtk-window-get-mnemonic-modifier gtkwindow*) gdkmodifiertype)
(define-foreign (gtk-window-get-modal gtkwindow*) bool)
(define-foreign (gtk-window-get-position gtkwindow* (ret int) (ret int)) void)
(define-foreign (gtk-window-get-role gtkwindow*) string)
(define-foreign (gtk-window-get-size gtkwindow* (ret int) (ret int)) void)
(define-foreign (gtk-window-get-title gtkwindow*) string)
(define-foreign (gtk-window-get-transient-for gtkwindow*) gtkwindow*)
(define-foreign (gtk-window-get-type-hint gtkwindow*) gdkwindowtypehint)
(define-foreign (gtk-window-get-skip-taskbar-hint gtkwindow*) bool)
(define-foreign (gtk-window-get-skip-pager-hint gtkwindow*) bool)
(define-foreign (gtk-window-get-accept-focus gtkwindow*) bool)
(define-foreign (gtk-window-get-focus-on-map gtkwindow*) bool)
(define-foreign (gtk-window-move gtkwindow* int int) void)
(define-foreign (gtk-window-parse-geometry gtkwindow* string) bool)
(define-foreign (gtk-window-reshow-with-initial-size gtkwindow*) void)
(define-foreign (gtk-window-resize gtkwindow* int int) void)
;(define-foreign (gtk-window-set-default-icon-list glist*) void)
(define-foreign (gtk-window-set-default-icon gdkpixbuf*) void)
;(define-foreign (gtk-window-set-default-icon-from-file string gerror**) bool)
(define-foreign (gtk-window-set-default-icon-name string) void)
(define-foreign (gtk-window-set-icon gtkwindow* gdkpixbuf*) void)
;(define-foreign (gtk-window-set-icon-list gtkwindow* glist*) void)
;(define-foreign (gtk-window-set-icon-from-file gtkwindow* string gerror**) bool)
(define-foreign (gtk-window-set-icon-name gtkwindow* string) void)
(define-foreign (gtk-window-set-auto-startup-notification bool) void)
(define-foreign (gtk-decorated-window-init gtkwindow*) void)
(define-foreign (gtk-decorated-window-calculate-frame-size gtkwindow*) void)
(define-foreign (gtk-decorated-window-set-title gtkwindow* string) void)
(define-foreign (gtk-decorated-window-move-resize-window gtkwindow* int int int int) void)

(define-foreign (gtk-window-group-new) gtkwindowgroup*)
(define-foreign (gtk-window-group-add-window gtkwindowgroup* gtkwindow*) void)
(define-foreign (gtk-window-group-remove-window gtkwindowgroup* gtkwindow*) void)

(define-foreign (gtk-about-dialog-new) gtkaboutdialog*)
(define-foreign (gtk-about-dialog-get-name gtkaboutdialog*) string)
(define-foreign (gtk-about-dialog-set-name gtkaboutdialog* string) void)
(define-foreign (gtk-about-dialog-get-version gtkaboutdialog*) string)
(define-foreign (gtk-about-dialog-set-version gtkaboutdialog* string) void)
(define-foreign (gtk-about-dialog-get-copyright gtkaboutdialog*) string)
(define-foreign (gtk-about-dialog-set-copyright gtkaboutdialog* string) void)
(define-foreign (gtk-about-dialog-get-comments gtkaboutdialog*) string)
(define-foreign (gtk-about-dialog-set-comments gtkaboutdialog* string) void)
(define-foreign (gtk-about-dialog-get-license gtkaboutdialog*) string)
(define-foreign (gtk-about-dialog-set-license gtkaboutdialog* string) void)
(define-foreign (gtk-about-dialog-get-website gtkaboutdialog*) string)
(define-foreign (gtk-about-dialog-set-website gtkaboutdialog* string) void)
(define-foreign (gtk-about-dialog-get-website-label gtkaboutdialog*) string)
(define-foreign (gtk-about-dialog-set-website-label gtkaboutdialog* string) void)
;(define-foreign (gtk-about-dialog-get-authors gtkaboutdialog*) stringarray)
;(define-foreign (gtk-about-dialog-set-authors gtkaboutdialog* stringarray) void)
;(define-foreign (gtk-about-dialog-get-artists gtkaboutdialog*) stringarray)
;(define-foreign (gtk-about-dialog-set-artists gtkaboutdialog* stringarray) void)
;(define-foreign (gtk-about-dialog-get-documenters gtkaboutdialog*) stringarray)
;(define-foreign (gtk-about-dialog-set-documenters gtkaboutdialog* stringarray) void)
(define-foreign (gtk-about-dialog-get-logo gtkaboutdialog*) gdkpixbuf*)
(define-foreign (gtk-about-dialog-set-logo gtkaboutdialog* gdkpixbuf*) void)
(define-foreign (gtk-about-dialog-get-logo-icon-name gtkaboutdialog*) string)
(define-foreign (gtk-about-dialog-set-logo-icon-name gtkaboutdialog* string) void)
;; gtk-about-dialog-set-email-hook gtk-about-dialog-set-url-hook 
(define-foreign (gtk-show-about-dialog gtkaboutdialog* string) void)

(define-foreign (gtk-accel-label-new string) gtkaccellabel*)
;(define-foreign (gtk-accel-label-set-accel-closure gtkaccellabel* gclosure*) void)
(define-foreign (gtk-accel-label-get-accel-widget gtkaccellabel*) gtkwidget*)
(define-foreign (gtk-accel-label-set-accel-widget gtkaccellabel* gtkwidget*) void)
(define-foreign (gtk-accel-label-get-accel-width gtkaccellabel*) uint)
(define-foreign (gtk-accel-label-refetch gtkaccellabel*) bool)

(define-foreign (gtk-image-get-icon-set gtkimage* (ret gtkiconset*) (ret gtkiconsize)) void)
(define-foreign (gtk-image-get-image gtkimage* (ret gdkimage*) (ret gdkbitmap*)) void)
(define-foreign (gtk-image-get-pixbuf gtkimage*) gdkpixbuf*)
(define-foreign (gtk-image-get-pixmap gtkimage* (ret gdkpixmap*) (ret gdkbitmap*)) void)
(define-foreign (gtk-image-get-stock gtkimage* (ret string) (ret gtkiconsize)) void)
;(define-foreign (gtk-image-get-animation gtkimage*) gtkpixbufanimation*)
(define-foreign (gtk-image-get-icon-name gtkimage* (ret string) (ret gtkiconsize)) void)
(define-foreign (gtk-image-get-storage-type gtkimage*) gtkimagetype)
(define-foreign (gtk-image-new-from-file string) gtkwidget*)
(define-foreign (gtk-image-new-from-icon-set gtkiconset* gtkiconsize) gtkimage*)
(define-foreign (gtk-image-new-from-image gdkimage* gdkbitmap*) gtkimage*)
(define-foreign (gtk-image-new-from-pixbuf gdkpixbuf*) gtkimage*)
(define-foreign (gtk-image-new-from-pixmap gdkpixmap* gdkbitmap*) gtkimage*)
(define-foreign (gtk-image-new-from-stock string gtkiconsize) gtkimage*)
;(define-foreign (gtk-image-new-from-animation gtkpixbufanimation*) gtkimage*)
(define-foreign (gtk-image-new-from-icon-name string gtkiconsize) gtkimage*)
(define-foreign (gtk-image-set-from-file gtkimage* string) void)
(define-foreign (gtk-image-set-from-icon-set gtkimage* gtkiconset* gtkiconsize) void)
(define-foreign (gtk-image-set-from-image gtkimage* gdkimage* gdkbitmap*) void)
(define-foreign (gtk-image-set-from-pixbuf gtkimage* gdkpixbuf*) gtkimage*)
(define-foreign (gtk-image-set-from-pixmap gtkimage* gdkpixmap* gdkbitmap*) gtkimage*)
(define-foreign (gtk-image-set-from-stock gtkimage* string gtkiconsize) gtkimage*)
;(define-foreign (gtk-image-set-from-animation gtkimage* gtkpixbufanimation*) gtkimage*)
(define-foreign (gtk-image-set-from-icon-name gtkimage* string gtkiconsize) void)
(define-foreign (gtk-image-new) gtkimage*)
(define-foreign (gtk-image-set) gtkimage* gtkimage* gdkbitmap*)
(define-foreign (gtk-image-get gtkimage* (ret gdkimage*) (ret gdkbitmap*)) void)
(define-foreign (gtk-image-set-pixel-size gtkimage* int) void)
(define-foreign (gtk-image-get-pixel-size gtkimage*) int)

(define-cfields-offsets/target-dep-paths ("gtk/gtk.h") 
  (fields "GtkObject" (gtkobject-flags-offset "flags"))
  (fields "GtkDialog" 
          (gtkdialog-vbox-offset "vbox")
          (gtkdialog-action-area-offset "action_area"))
  (fields "GtkFileSelection" 
          (gtkfilesel-dir-list-offset "dir_list")
          (gtkfilesel-file-list-offset "file_list")
          (gtkfilesel-selection-entry-offset "selection_entry")
          (gtkfilesel-selection-text-offset "selection_text")
          (gtkfilesel-main-vbox-offset "main_vbox")
          (gtkfilesel-ok-button-offset "ok_button")
          (gtkfilesel-cancel-button-offset "cancel_button")
          (gtkfilesel-help-button-offset "help_button")
          (gtkfilesel-history-pulldown-offset "history_pulldown")
          (gtkfilesel-history-menu-offset "history_menu")
          (gtkfilesel-history-list-offset "history_list"))
;; Deprecated in gtk2
;  (fields "GtkText" 
;          (gtktext-text-area-offset "text_area")
;          (gtktext-hadj-offset      "hadj")
;          (gtktext-vadj-offset      "vadj"))
  (fields "GtkTextView"
          (layout-offset "layout")
          (buffer-offset "buffer")
          (text-window-offset "text_window")
          (left-window-offset "left_window")
          (right-window-offset "right_window")
          (top-window-offset "top_window")
          (bottom-window-offset "bottom_window")
          (hadjustment-offset "hadjustment")
          (vadjustment-offset "vadjustment")
          )
  (sizeof sizeof-gtktextiter "GtkTextIter")
  )

(define malloc-gtk-text-iter
  (let ((malloc (stdlib/malloc gtktextiter*-rt)) ; potential space leak!
        (size sizeof-gtktextiter))
    (lambda ()
      (malloc size))))

(define (gtk-text-view-hadjustment text-view)
  (void*-void*-ref text-view hadjustment-offset))
(define (gtk-text-view-vadjustment text-view)
  (void*-void*-ref text-view vadjustment-offset))

(define (gtk-dialog-vbox dialog)
  (void*-void*-ref dialog gtkdialog-vbox-offset))
(define (gtk-dialog-action-area dialog)
  (void*-void*-ref dialog gtkdialog-action-area-offset))

(define-foreign (gtk-file-selection-new string) gtkfileselection*)
(define-foreign (gtk-file-selection-set-filename gtkfileselection* string) void)
(define-foreign (gtk-file-selection-get-filename gtkfileselection*) string)
(define-foreign (gtk-file-selection-complete gtkfileselection* string) void)
(define-foreign (gtk-file-selection-show-fileop-buttons gtkfileselection*) void)
(define-foreign (gtk-file-selection-hide-fileop-buttons gtkfileselection*) void)
;; XXX add support for gtk_file_selection_get_selections
(define-foreign (gtk-file-selection-set-select-multiple gtkfileselection* bool) void)
(define-foreign (gtk-file-selection-get-select-multiple gtkfileselection*) bool)

(define (gtk-file-selection-ok-button filesel)
  (void*-void*-ref filesel gtkfilesel-ok-button-offset))
(define (gtk-file-selection-cancel-button filesel)
  (void*-void*-ref filesel gtkfilesel-cancel-button-offset))

;; BELOW ARE DEPRECATED ACCORDING TO GTK+ HEADER FILES...
(define GTK-TOOLBAR-CHILD-SPACE 0)
(define GTK-TOOLBAR-CHILD-BUTTON 1)
(define GTK-TOOLBAR-CHILD-TOGGLEBUTTON 2)
(define GTK-TOOLBAR-CHILD-RADIOBUTTON 3)
(define GTK-TOOLBAR-CHILD-WIDGET 4)
