widget.h

00001 /***************************************************************************
00002     begin                : Mon Sep 20 2004
00003     copyright            : (C) 2004 - 2006 by Alper Akcan
00004     email                : distchx@yahoo.com
00005  ***************************************************************************/
00006 
00007 /***************************************************************************
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU Lesser General Public License as        *
00011  *   published by the Free Software Foundation; either version 2.1 of the  *
00012  *   License, or (at your option) any later version.                       *
00013  *                                                                         *
00014  ***************************************************************************/
00015 
00016 #ifndef W_WIDGET_H_
00017 #define W_WIDGET_H_
00018 
00019 /* reduce memory usage, this is a bit hacky
00020  * some speed consumptions ;|
00021  * 
00022  * levels;
00023  *      0: no memory optimizations, memory hungary but faster
00024  *      1: disables image caching, reduces memory usage, especially
00025  *         for the applications that have several images
00026  *      2: will free hided object's and its childs' buffers (vbuf and matrix)
00027  *         slowers show() hide() processes, but cute.
00028  *      3: much more memory optimization, too slower, draws everthing on the fly.
00029  */
00030 #define WIDGET_OPTIMIZE_MEMORY 2
00031 
00032 typedef struct w_object_s w_object_t;
00033 typedef struct w_button_s w_button_t;
00034 typedef struct w_checkbox_s w_checkbox_t;
00035 typedef struct w_editbox_s w_editbox_t;
00036 typedef struct w_frame_image_s w_frame_image_t;
00037 typedef struct w_frame_s w_frame_t;
00038 typedef struct w_progressbar_s w_progressbar_t;
00039 typedef struct w_scrollbufferbar_s w_scrollbufferbar_t;
00040 typedef struct w_scrollbuffer_s w_scrollbuffer_t;
00041 typedef struct w_textbox_s w_textbox_t;
00042 typedef struct w_window_s w_window_t;
00043 
00044 typedef struct w_effect_s w_effect_t;
00045 typedef struct w_signal_s w_signal_t;
00046 
00047 /* signal.c */
00048 struct w_signal_s {
00049         w_object_t *from;
00050         w_object_t *to;
00051         void (*func) (w_signal_t *);
00052         void *arg;
00053 };
00054 
00055 void w_signal_send (w_object_t *from, w_object_t *to, void (*func) (w_signal_t *), void *arg);
00056 void w_signal_delete (w_object_t *object);
00057 
00058 /* effect .c */
00059 typedef enum {
00060         EFFECT_NONE    = 0x0,
00061         EFFECT_FADEIN  = 0x1,
00062         EFFECT_FADEOUT = 0x2,
00063         EFFECT_POPIN   = 0x4,
00064         EFFECT_POPOUT  = 0x8,
00065         EFFECT_SHOW    = (EFFECT_FADEIN | EFFECT_POPIN),
00066         EFFECT_HIDE    = (EFFECT_FADEOUT | EFFECT_POPOUT)
00067 } EFFECT;
00068 
00069 struct w_effect_s {
00070         EFFECT effect;
00071         int level;
00072         int interval;
00073         s_timer_t *timer;
00074 };
00075 
00076 int w_effect_stop (w_object_t *object);
00077 int w_effect_start (w_object_t *object);
00078 void w_effect_timer_cb (s_window_t *window, s_timer_t *timer);
00079 int w_effect_apply (s_surface_t *surface, s_rect_t *rect, w_object_t *effect, w_object_t *object);
00080 
00081 /* object.c */
00082 
00097 
00100 typedef enum {
00102         OBJECT_OBJECT           = 0x0,
00104         OBJECT_FRAME            = 0x1,
00106         OBJECT_BUTTON           = 0x2,
00108         OBJECT_TEXTBOX          = 0x3,
00110         OBJECT_EDITBOX          = 0x4,
00112         OBJECT_PROGRESSBAR      = 0x5,
00114         OBJECT_CHECKBOX         = 0x6,
00116         OBJECT_SCROLLBUFFER     = 0x7,
00118         OBJECT_SCROLLBUFFERBAR  = 0x8,
00120         OBJECT_WINDOW           = 0x9,
00122         OBJECT_OBJECTS          = 0xa
00123 } OBJECT;
00124 
00127 struct w_object_s {
00129         OBJECT type;
00131         s_list_t *childs;
00133         s_list_t *shown;
00135         s_surface_t *surface;
00137         w_object_t *parent;
00139         s_rect_t *content;
00141         int showed;
00143         int focused;
00145         w_effect_t *effect;
00147         void (*geometry) (w_object_t *object);
00149         void (*draw) (w_object_t *object);
00151         void (*event) (w_object_t *object, s_event_t *event);
00153         void (*destroy) (w_object_t *object);
00155         w_window_t *window;
00157         void *data[OBJECT_OBJECTS];
00159         void *priv;
00160 };
00161 
00164 void w_object_hide_ (w_object_t *object);
00165 void w_object_show_ (w_object_t *object);
00166 int w_object_update_to_surface (w_object_t *object, s_surface_t *surface, s_rect_t *coor, w_object_t *effect, int do_effect);
00167 int w_object_update (w_object_t *object, s_rect_t *coor);
00168 int w_object_draw (w_object_t *object);
00169 int w_object_refresh (w_object_t *object);
00170 int w_object_set_content (w_object_t *object, int x, int y, int w, int h);
00171 int w_object_move_correct (w_object_t *object);
00172 int w_object_move_silent (w_object_t *object, int x, int y, int w, int h);
00173 int w_object_move (w_object_t *object, int x, int y, int w, int h);
00174 int w_object_hide (w_object_t *object);
00175 int w_object_show (w_object_t *object);
00176 int w_object_childatposition (w_object_t *object, int x, int y, w_object_t **child);
00177 int w_object_atposition (w_object_t *root, int x, int y, w_object_t **object);
00178 void w_object_signal (w_object_t *from, w_object_t *to, void (*func) (w_signal_t *), void *arg);
00179 int w_object_level_get_ (w_object_t *parent, w_object_t **object, int *level);
00180 int w_object_level_get (w_object_t *parent, w_object_t **object, int level);
00181 int w_object_level_count_ (w_object_t *parent, int *level);
00182 int w_object_level_count (w_object_t *parent, int *level);
00183 int w_object_level_find_ (w_object_t *parent, w_object_t *object, int *level);
00184 int w_object_level_find (w_object_t *parent, w_object_t *object, int *level);
00185 int w_object_isshownchild (w_object_t *parent, w_object_t *child);
00186 int w_object_ischild (w_object_t *parent, w_object_t *child);
00187 int w_object_init (w_window_t *window, w_object_t **object, void (*draw) (w_object_t *), w_object_t *parent);
00188 void w_object_uninit (w_object_t *object);
00189 
00190 /* frame.c */
00191 typedef enum {
00192         FRAME_NOFRAME           = 0x00,
00193         FRAME_BOX               = 0x01,
00194         FRAME_PANEL             = 0x02,
00195         FRAME_WINPANEL          = 0x03,
00196         FRAME_HLINE             = 0x04,
00197         FRAME_VLINE             = 0x05,
00198         FRAME_STYLEDPANEL       = 0x06,
00199         FRAME_POPUPPANEL        = 0x07,
00200         FRAME_MENUBARPANEL      = 0x08,
00201         FRAME_TOOLBARPANEL      = 0x09,
00202         FRAME_LINEEDITPANEL     = 0x0a,
00203         FRAME_TABWIDGETPANEL    = 0x0b,
00204         FRAME_GROUPBOXPANEL     = 0x0c,
00205         FRAME_EMPTY             = 0x0d,
00206         FRAME_MSHAPE            = 0x0f
00207 } FRAME_SHAPE;
00208 
00209 typedef enum {
00210         FRAME_PLAIN             = 0x010,
00211         FRAME_RAISED            = 0x020,
00212         FRAME_SUNKEN            = 0x040,
00213         FRAME_FOCUSED           = 0x100,
00214         FRAME_MSHADOW           = 0x0f0
00215 } FRAME_SHADOW;
00216 
00217 typedef enum {
00218         FRAME_IMAGE_SOLID       = 0x0,
00219         FRAME_IMAGE_VERTICAL    = 0x1,
00220         FRAME_IMAGE_HORIZONTAL  = 0x2,
00221 } FRAME_IMAGE_ROTATION;
00222 
00223 struct w_frame_image_s {
00224         unsigned int style;
00225         unsigned int rotation;
00226         s_list_t *images;
00227         s_list_t *names;
00228 };
00229 
00230 struct w_frame_s {
00231         w_object_t *object;
00232         unsigned int style;
00233         unsigned int linewidth;
00234         unsigned int midlinewidth;
00235         s_list_t *images;
00236 };
00237 
00238 int w_frame_set_style (w_object_t *object, FRAME_SHAPE shape, FRAME_SHADOW shadow);
00239 int w_frame_image_init (w_frame_image_t **fimg);
00240 int w_frame_image_uninit (w_frame_image_t *fimg);
00241 int w_frame_set_image (w_object_t *object, unsigned int style, unsigned int rotation, unsigned int nimgs, char **imgs);
00242 void w_frame_draw_image (w_object_t *object, w_frame_image_t *fimg);
00243 void w_frame_draw (w_object_t *object);
00244 void w_frame_geometry (w_object_t *object);
00245 int w_frame_init (w_window_t *window, w_frame_t **frame, unsigned int style, w_object_t *parent);
00246 void w_frame_uninit (w_object_t *object);
00247 
00248 /* button.c */
00249 struct w_button_s {
00250         w_object_t *object;
00251         w_frame_t *frame;
00252         s_handler_t *handler_m;
00253         s_handler_t *handler_k;
00254         void (*pressed) (w_object_t *, int);
00255         void (*released) (w_object_t *, int);
00256         void (*clicked) (w_object_t *, int, int);
00257         int state;
00258 };
00259 
00260 int w_button_set_pressed (w_object_t *object, void (*pressed) (w_object_t *, int));
00261 int w_button_set_released (w_object_t *object, void (*released) (w_object_t *, int));
00262 int w_button_set_clicked (w_object_t *object, void (*clicked) (w_object_t *, int, int));
00263 int w_button_set_image (w_object_t *object, unsigned int style, unsigned int rotation, unsigned int nimgs, char **imgs);
00264 int w_button_set_style (w_object_t *object, FRAME_SHAPE shape, FRAME_SHADOW shadow);
00265 void w_button_event (w_object_t *object, s_event_t *event);
00266 void w_button_draw (w_object_t *object);
00267 void w_button_geometry (w_object_t *object);
00268 void w_button_cb_o (s_window_t *window, s_event_t *event, s_handler_t *handler);
00269 void w_button_cb_p (s_window_t *window, s_event_t *event, s_handler_t *handler);
00270 void w_button_cb_c (s_window_t *window, s_event_t *event, s_handler_t *handler);
00271 void w_button_cb_r (s_window_t *window, s_event_t *event, s_handler_t *handler);
00272 void w_button_cb_hr (s_window_t *window, s_event_t *event, s_handler_t *handler);
00273 void w_button_cb_rh (s_window_t *window, s_event_t *event, s_handler_t *handler);
00274 void w_button_cb_ho (s_window_t *window, s_event_t *event, s_handler_t *handler);
00275 void w_button_cb_oh (s_window_t *window, s_event_t *event, s_handler_t *handler);
00276 void w_button_cb_hoh (s_window_t *window, s_event_t *event, s_handler_t *handler);
00277 int w_button_init (w_window_t *window, w_button_t **button, w_object_t *parent);
00278 void w_button_uninit (w_object_t *object);
00279 
00280 /* textbox.c */
00281 typedef enum {
00282         TEXTBOX_WRAP    = 0x1,
00283         TEXTBOX_VCENTER = 0x2,
00284         TEXTBOX_HCENTER = 0x4
00285 } TEXTBOX_PROPERTIES;
00286 
00287 struct w_textbox_s {
00288         w_object_t *object;
00289         w_frame_t *frame;
00290         s_list_t *lines;
00291         char *str;
00292         char *font;
00293         unsigned int size;
00294         unsigned int rgb;
00295         TEXTBOX_PROPERTIES properties;
00296         int height;
00297         int yoffset;
00298 };
00299 
00300 void w_textbox_slide (w_object_t *object, int vertical, int horizontal, int *ytotal, int *yoffset);
00301 int w_textbox_set_properties (w_object_t *object, TEXTBOX_PROPERTIES properties);
00302 int w_textbox_set_image (w_object_t *object, unsigned int style, unsigned int rotation, unsigned int nimgs, char **imgs);
00303 int w_textbox_set_style (w_object_t *object, FRAME_SHAPE shape, FRAME_SHADOW shadow);
00304 void w_textbox_draw (w_object_t *object);
00305 int w_textbox_set_rgb (w_object_t *object, int r, int g, int b);
00306 int w_textbox_set_size (w_object_t *object, int size);
00307 int w_textbox_set_str (w_object_t *object, char *str);
00308 void w_textbox_geometry (w_object_t *object);
00309 int w_textbox_init (w_window_t *window, w_textbox_t **textbox, w_object_t *parent);
00310 void w_textbox_uninit (w_object_t *object);
00311 void w_textbox_loadimages(w_object_t *object,char *file_left,char *file_middle,char *file_right);
00312 
00313 /* editbox.c */
00314 struct w_editbox_s {
00315         w_object_t *object;
00316         w_textbox_t *textbox;
00317         s_handler_t *handler_mouse;
00318         s_handler_t *handler_keybd;
00319 };
00320 
00321 int w_editbox_set_str (w_object_t *object, char *str);
00322 int w_editbox_set_style (w_object_t *object, FRAME_SHAPE shape, FRAME_SHADOW shadow);
00323 int w_editbox_set_image (w_object_t *object, unsigned int style, unsigned int rotation, unsigned int nimgs, char **imgs);
00324 int w_editbox_set_size (w_object_t *object, int size);
00325 int w_editbox_set_rgb (w_object_t *object, int r, int g, int b);
00326 int w_editbox_set_properties (w_object_t *object, TEXTBOX_PROPERTIES properties);
00327 void w_editbox_draw (w_object_t *object);
00328 void w_editbox_geometry (w_object_t *object);
00329 int w_editbox_init (w_window_t *window, w_editbox_t **editbox, w_object_t *parent);
00330 void w_editbox_uninit (w_object_t *object);
00331 
00332 /* checkbox.c */
00333 struct w_checkbox_s {
00334         w_object_t *object;
00335         w_button_t *button;
00336         w_frame_t *box;
00337         w_textbox_t *text;
00338         void (*changed) (w_object_t *, int);
00339         int state;
00340 };
00341 
00342 int w_checkbox_set_str (w_object_t *object, char *str);
00343 int w_checkbox_set_changed (w_object_t *object, void (*changed) (w_object_t *, int));
00344 int w_checkbox_set_style (w_object_t *object, FRAME_SHAPE shape, FRAME_SHADOW shadow);
00345 int w_checkbox_set_image (w_object_t *object, unsigned int style, unsigned int rotation, unsigned int nimgs, char **imgs);
00346 int w_checkbox_set_boxstyle (w_object_t *object, FRAME_SHAPE shape, FRAME_SHADOW shadow);
00347 int w_checkbox_set_boximage (w_object_t *object, unsigned int style, unsigned int rotation, unsigned int nimgs, char **imgs);
00348 int w_checkbox_set_rgb (w_object_t *object, int r, int g, int b);
00349 int w_checkbox_set_size (w_object_t *object, int size);
00350 int w_checkbox_set_properties (w_object_t *object, TEXTBOX_PROPERTIES properties);
00351 void w_checkbox_geometry (w_object_t *object);
00352 void w_checkbox_draw (w_object_t *object);
00353 void w_checkbox_state (w_object_t *object, int state);
00354 void w_checkbox_released (w_object_t *object, int btn);
00355 void w_checkbox_uninit (w_object_t *object);
00356 int w_checkbox_init (w_window_t *window, w_checkbox_t **checkbox, w_object_t *parent);
00357 
00358 /* progressbar.c */
00359 struct w_progressbar_s {
00360         w_object_t *object;
00361         w_frame_t *frame;
00362         w_frame_t *box;
00363         w_textbox_t *text;
00364         unsigned int level;
00365         void (*changed) (w_object_t *, int);
00366 };
00367 
00368 int w_progressbar_set_changed (w_object_t *object, void (*changed) (w_object_t *, int));
00369 int w_progressbar_set_style (w_object_t *object, FRAME_SHAPE shape, FRAME_SHADOW shadow);
00370 int w_progressbar_set_image (w_object_t *object, unsigned int style, unsigned int rotation, unsigned int nimgs, char **imgs);
00371 int w_progressbar_set_boxstyle (w_object_t *object, FRAME_SHAPE shape, FRAME_SHADOW shadow);
00372 int w_progressbar_set_boximage (w_object_t *object, unsigned int style, unsigned int rotation, unsigned int nimgs, char **imgs);
00373 void w_progressbar_level (w_object_t *object, unsigned int level);
00374 void w_progressbar_geometry (w_object_t *object);
00375 int w_progressbar_init (w_window_t *window, w_progressbar_t **progressbar, w_object_t *parent);
00376 void w_progressbar_uninit (w_object_t *object);
00377 
00378 /* scrollbar.c */
00379 struct w_scrollbufferbar_s {
00380         w_object_t *object;
00381         w_frame_t *frame;
00382         w_button_t *add;
00383         w_button_t *sub;
00384         w_frame_t *box;
00385 };
00386 
00387 struct w_scrollbuffer_s {
00388         w_object_t *object;
00389         w_frame_t *frame;
00390         w_scrollbufferbar_t *vertical;
00391         w_object_t *child;
00392         void (*slide) (w_object_t *, int, int, int *, int *);
00393 };
00394 
00395 void w_scrollbuffer_set_slide (w_object_t *object, void (*slide) (w_object_t *, int, int, int *, int *));
00396 void w_scrollbufferbar_add_pressed (w_object_t *object, int button);
00397 void w_scrollbufferbar_sub_pressed (w_object_t *object, int button);
00398 void w_scrollbufferbar_geometry (w_object_t *object);
00399 void w_scrollbufferbar_uninit (w_object_t *object);
00400 int w_scrollbufferbar_init (w_window_t *window, w_scrollbufferbar_t **scrollbufferbar, w_object_t *parent);
00401 int w_scrollbuffer_set_boxstyle (w_object_t *object, FRAME_SHAPE shape, FRAME_SHADOW shadow);
00402 int w_scrollbuffer_set_boximage (w_object_t *object, unsigned int style, unsigned int rotation, unsigned int nimgs, char **imgs);
00403 int w_scrollbuffer_set_addstyle (w_object_t *object, FRAME_SHAPE shape, FRAME_SHADOW shadow);
00404 int w_scrollbuffer_set_addimage (w_object_t *object, unsigned int style, unsigned int rotation, unsigned int nimgs, char **imgs);
00405 int w_scrollbuffer_set_substyle (w_object_t *object, FRAME_SHAPE shape, FRAME_SHADOW shadow);
00406 int w_scrollbuffer_set_subimage (w_object_t *object, unsigned int style, unsigned int rotation, unsigned int nimgs, char **imgs);
00407 void w_scrollbuffer_slide (w_object_t *object, int vertical, int horizontal);
00408 void w_scrollbuffer_set_child (w_object_t *object, w_object_t *child);
00409 void w_scrollbuffer_geometry (w_object_t *object);
00410 void w_scrollbuffer_uninit (w_object_t *object);
00411 int w_scrollbuffer_init (w_window_t *window, w_scrollbuffer_t **scrollbuffer, w_object_t *parent);
00412 
00413 /* window.c */
00414 struct w_window_s {
00415         s_window_t *window;
00416         w_object_t *object;
00417         w_object_t *focus;
00418         s_list_t *images;
00419         s_list_t *fonts;
00420 };
00421 
00422 void w_window_focus_change_notify (s_window_t *window, w_object_t *focus);
00423 void w_window_change_keybd_focus (s_window_t *window, int type);
00424 void w_window_atevent (s_window_t *window, s_event_t *event);
00425 int w_window_init (w_window_t **window, S_WINDOW type, w_window_t *parent);
00426 int w_window_set_coor (w_window_t *window, int x, int y, int w, int h);
00427 s_image_t * w_window_image_get (w_window_t *window, char *image);
00428 int w_window_image_add (w_window_t *window, char *image);
00429 s_font_t * w_window_font_get (w_window_t *window, char *font);
00430 int w_window_font_add (w_window_t *window, char *font);
00431 int w_window_uninit (w_window_t *window);
00432 
00433 #endif /* W_WIDGET_H_ */

Generated on Wed Dec 27 17:53:06 2006 for xynth-0.8.40 by  doxygen 1.4.7