gntwidget.h

Go to the documentation of this file.
00001 
00005 /*
00006  * GNT - The GLib Ncurses Toolkit
00007  *
00008  * GNT is the legal property of its developers, whose names are too numerous
00009  * to list here.  Please refer to the COPYRIGHT file distributed with this
00010  * source distribution.
00011  *
00012  * This library is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License as published by
00014  * the Free Software Foundation; either version 2 of the License, or
00015  * (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License
00023  * along with this program; if not, write to the Free Software
00024  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
00025  */
00026 
00027 #ifndef GNT_WIDGET_H
00028 #define GNT_WIDGET_H
00029 
00030 #include <stdio.h>
00031 #include <glib.h>
00032 #include <ncurses.h>
00033 
00034 #include "gntbindable.h"
00035 
00036 #define GNT_TYPE_WIDGET             (gnt_widget_get_gtype())
00037 #define GNT_WIDGET(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_WIDGET, GntWidget))
00038 #define GNT_WIDGET_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_WIDGET, GntWidgetClass))
00039 #define GNT_IS_WIDGET(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_WIDGET))
00040 #define GNT_IS_WIDGET_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_WIDGET))
00041 #define GNT_WIDGET_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_WIDGET, GntWidgetClass))
00042 
00043 #define GNT_WIDGET_FLAGS(obj)               (GNT_WIDGET(obj)->priv.flags)
00044 #define GNT_WIDGET_SET_FLAGS(obj, flags)        (GNT_WIDGET_FLAGS(obj) |= flags)
00045 #define GNT_WIDGET_UNSET_FLAGS(obj, flags)  (GNT_WIDGET_FLAGS(obj) &= ~(flags))
00046 #define GNT_WIDGET_IS_FLAG_SET(obj, flags)  (GNT_WIDGET_FLAGS(obj) & (flags))
00047 
00048 typedef struct _GntWidget           GntWidget;
00049 typedef struct _GntWidgetPriv       GntWidgetPriv;
00050 typedef struct _GntWidgetClass      GntWidgetClass;
00051 
00052 typedef enum _GntWidgetFlags
00053 {
00054     GNT_WIDGET_DESTROYING     = 1 << 0,
00055     GNT_WIDGET_CAN_TAKE_FOCUS = 1 << 1,
00056     GNT_WIDGET_MAPPED         = 1 << 2,
00057     /* XXX: Need to set the following two as properties, and setup a callback whenever these
00058      * get chnaged. */
00059     GNT_WIDGET_NO_BORDER      = 1 << 3,
00060     GNT_WIDGET_NO_SHADOW      = 1 << 4,
00061     GNT_WIDGET_HAS_FOCUS      = 1 << 5,
00062     GNT_WIDGET_DRAWING        = 1 << 6,
00063     GNT_WIDGET_URGENT         = 1 << 7,
00064     GNT_WIDGET_GROW_X         = 1 << 8,
00065     GNT_WIDGET_GROW_Y         = 1 << 9,
00066     GNT_WIDGET_INVISIBLE      = 1 << 10,
00067     GNT_WIDGET_TRANSIENT      = 1 << 11,
00068     GNT_WIDGET_DISABLE_ACTIONS = 1 << 12,
00069 } GntWidgetFlags;
00070 
00071 /* XXX: This will probably move elsewhere */
00072 typedef enum _GntMouseEvent
00073 {
00074     GNT_LEFT_MOUSE_DOWN = 1,
00075     GNT_RIGHT_MOUSE_DOWN,
00076     GNT_MIDDLE_MOUSE_DOWN,
00077     GNT_MOUSE_UP,
00078     GNT_MOUSE_SCROLL_UP,
00079     GNT_MOUSE_SCROLL_DOWN
00080 } GntMouseEvent;
00081 
00082 /* XXX: I'll have to ask grim what he's using this for in guifications. */
00083 typedef enum _GntParamFlags
00084 {
00085     GNT_PARAM_SERIALIZABLE  = 1 << G_PARAM_USER_SHIFT
00086 } GntParamFlags;
00087 
00088 struct _GntWidgetPriv
00089 {
00090     int x, y;
00091     int width, height;
00092     GntWidgetFlags flags;
00093     char *name;
00094 
00095     int minw, minh;    /* Minimum size for the widget */
00096 };
00097 
00098 struct _GntWidget
00099 {
00100     GntBindable inherit;
00101 
00102     GntWidget *parent;
00103 
00104     GntWidgetPriv priv;
00105     WINDOW *window;
00106 
00107     void (*gnt_reserved1)(void);
00108     void (*gnt_reserved2)(void);
00109     void (*gnt_reserved3)(void);
00110     void (*gnt_reserved4)(void);
00111 };
00112 
00113 struct _GntWidgetClass
00114 {
00115     GntBindableClass parent;
00116 
00117     void (*map)(GntWidget *obj);
00118     void (*show)(GntWidget *obj);       /* This will call draw() and take focus (if it can take focus) */
00119     void (*destroy)(GntWidget *obj);
00120     void (*draw)(GntWidget *obj);       /* This will draw the widget */
00121     void (*hide)(GntWidget *obj);
00122     void (*expose)(GntWidget *widget, int x, int y, int width, int height);
00123     void (*gained_focus)(GntWidget *widget);
00124     void (*lost_focus)(GntWidget *widget);
00125 
00126     void (*size_request)(GntWidget *widget);
00127     gboolean (*confirm_size)(GntWidget *widget, int x, int y);
00128     void (*size_changed)(GntWidget *widget, int w, int h);
00129     void (*set_position)(GntWidget *widget, int x, int y);
00130     gboolean (*key_pressed)(GntWidget *widget, const char *key);
00131     void (*activate)(GntWidget *widget);
00132     gboolean (*clicked)(GntWidget *widget, GntMouseEvent event, int x, int y);
00133 
00134     void (*gnt_reserved1)(void);
00135     void (*gnt_reserved2)(void);
00136     void (*gnt_reserved3)(void);
00137     void (*gnt_reserved4)(void);
00138 };
00139 
00140 G_BEGIN_DECLS
00141 
00145 GType gnt_widget_get_gtype(void);
00146 
00151 void gnt_widget_destroy(GntWidget *widget);
00152 
00159 void gnt_widget_show(GntWidget *widget);
00160 
00165 void gnt_widget_draw(GntWidget *widget);
00166 
00171 void gnt_widget_expose(GntWidget *widget, int x, int y, int width, int height);
00172 
00177 void gnt_widget_hide(GntWidget *widget);
00178 
00186 void gnt_widget_get_position(GntWidget *widget, int *x, int *y);
00187 
00194 void gnt_widget_set_position(GntWidget *widget, int x, int y);
00195 
00200 void gnt_widget_size_request(GntWidget *widget);
00201 
00208 void gnt_widget_get_size(GntWidget *widget, int *width, int *height);
00209 
00219 gboolean gnt_widget_set_size(GntWidget *widget, int width, int height);
00220 
00230 gboolean gnt_widget_confirm_size(GntWidget *widget, int width, int height);
00231 
00240 gboolean gnt_widget_key_pressed(GntWidget *widget, const char *keys);
00241 
00252 gboolean gnt_widget_clicked(GntWidget *widget, GntMouseEvent event, int x, int y);
00253 
00262 gboolean gnt_widget_set_focus(GntWidget *widget, gboolean set);
00263 
00268 void gnt_widget_activate(GntWidget *widget);
00269 
00275 void gnt_widget_set_name(GntWidget *widget, const char *name);
00276 
00282 const char *gnt_widget_get_name(GntWidget *widget);
00283 
00288 void gnt_widget_queue_update(GntWidget *widget);
00289 
00296 void gnt_widget_set_take_focus(GntWidget *widget, gboolean set);
00297 
00304 void gnt_widget_set_visible(GntWidget *widget, gboolean set);
00305 
00314 gboolean gnt_widget_has_shadow(GntWidget *widget);
00315 
00316 G_END_DECLS
00317 
00318 #endif /* GNT_WIDGET_H */