enlightenment/src/menu.h

145 lines
4.0 KiB
C
Raw Normal View History

#ifndef E_MENU_H
#define E_MENU_H
#include "e.h"
Alright, I spent some time now reading e17's code. Here's what I've changed, this is big, so read this carefully :) * I've added debugging macros for messages and function call tracing. Usage: D("Creating item %i %i %i\n", x, y, z); Define DEBUG to use the D macro. D_ENTER; D_RETURN; D_RETURN_(x); These are for call tracing. Use D_RETURN_(x) when returning something from a function. Define DEBUG_NEST to use this. * added iconbar header file to Makefile.am * added proper new()/cleanup() calls for E_Delayed_Action; * I've completely rewritten the object and observer handling. Bye bye macros, this was nasty. It'll be hard enough to avoid leaks with usecounting in C. We now basically have the same system as gtk. There's a clear separation of observer and object code now. An E_Object by itself has nothing to do with observing or being observed, therefore, there are now E_Observers and E_Observees that are derived from E_Object. IMPORTANT: The cleanup system now reflects the reference count system, therefore, all ..._free() calls are now static, because the destructor should never be called explicitly, but implicitly through e_object_unref(). The object handling now is as follows: - The cleanup functions clean up everything that is contained in a struct, but NOT the struct itself. Instead of the final free() call, they call the destructor of the base class. The calls will walk up the hierarchy and clean up what's contained in every struct, and the final e_object_cleanup() will free the structure itself. E_Delayed_Action is a good example. - The only calls that influence the reference count are e_object_ref() and e_object_unref(). If you need to do things before an object gets destroyed, you can query the use count using e_object_get_usecount() and check if it's equal to 1. So this: OBJ_UNREF(b); OBJ_IF_FREE(b) { ecore_window_reparent(e->win, 0, 0, 0); e_icccm_release(e->win); OBJ_FREE(b); } now is this: if (e_object_get_usecount(E_OBJECT(b)) == 1) { ecore_window_reparent(e->win, 0, 0, 0); e_icccm_release(e->win); } e_object_unref(E_OBJECT(b)); object.h and observer.h are completely commented, it shouldn't be too hard to understand. This'll need to be documented in the manual anyway. * E_Objects are now used in lots of places where void* were used as pointers to objects before, especially in the actions code. This is obviously better, as it will generate compiler warnings when people want to pass things to functions that expect E_Objects. This could probably be more restrictive. * Added typedefs for the function prototypes in E_Action_Impl. Those fat signatures were just painful to read in the function declarations/implementations. * I've also tried to give parameters more useful names. Calling an object "o" is a lot of fun when you want to grep for it. * Included is also Graham's latest menu.c patch. Sorry for the delay, Graham. * I've added checks to the menu code that make sure that menus don't pop up when they're empty (which resulted in a little useless rectangle). I guess that's it for now. Sorry if I broke anything, but this was necessary imho. SVN revision: 5605
2001-11-02 09:07:52 -08:00
#include "object.h"
typedef struct _E_Menu E_Menu;
typedef struct _E_Menu_Item E_Menu_Item;
struct _E_Menu
{
Alright, I spent some time now reading e17's code. Here's what I've changed, this is big, so read this carefully :) * I've added debugging macros for messages and function call tracing. Usage: D("Creating item %i %i %i\n", x, y, z); Define DEBUG to use the D macro. D_ENTER; D_RETURN; D_RETURN_(x); These are for call tracing. Use D_RETURN_(x) when returning something from a function. Define DEBUG_NEST to use this. * added iconbar header file to Makefile.am * added proper new()/cleanup() calls for E_Delayed_Action; * I've completely rewritten the object and observer handling. Bye bye macros, this was nasty. It'll be hard enough to avoid leaks with usecounting in C. We now basically have the same system as gtk. There's a clear separation of observer and object code now. An E_Object by itself has nothing to do with observing or being observed, therefore, there are now E_Observers and E_Observees that are derived from E_Object. IMPORTANT: The cleanup system now reflects the reference count system, therefore, all ..._free() calls are now static, because the destructor should never be called explicitly, but implicitly through e_object_unref(). The object handling now is as follows: - The cleanup functions clean up everything that is contained in a struct, but NOT the struct itself. Instead of the final free() call, they call the destructor of the base class. The calls will walk up the hierarchy and clean up what's contained in every struct, and the final e_object_cleanup() will free the structure itself. E_Delayed_Action is a good example. - The only calls that influence the reference count are e_object_ref() and e_object_unref(). If you need to do things before an object gets destroyed, you can query the use count using e_object_get_usecount() and check if it's equal to 1. So this: OBJ_UNREF(b); OBJ_IF_FREE(b) { ecore_window_reparent(e->win, 0, 0, 0); e_icccm_release(e->win); OBJ_FREE(b); } now is this: if (e_object_get_usecount(E_OBJECT(b)) == 1) { ecore_window_reparent(e->win, 0, 0, 0); e_icccm_release(e->win); } e_object_unref(E_OBJECT(b)); object.h and observer.h are completely commented, it shouldn't be too hard to understand. This'll need to be documented in the manual anyway. * E_Objects are now used in lots of places where void* were used as pointers to objects before, especially in the actions code. This is obviously better, as it will generate compiler warnings when people want to pass things to functions that expect E_Objects. This could probably be more restrictive. * Added typedefs for the function prototypes in E_Action_Impl. Those fat signatures were just painful to read in the function declarations/implementations. * I've also tried to give parameters more useful names. Calling an object "o" is a lot of fun when you want to grep for it. * Included is also Graham's latest menu.c patch. Sorry for the delay, Graham. * I've added checks to the menu code that make sure that menus don't pop up when they're empty (which resulted in a little useless rectangle). I guess that's it for now. Sorry if I broke anything, but this was necessary imho. SVN revision: 5605
2001-11-02 09:07:52 -08:00
E_Object o;
struct {
int x, y, w, h;
int visible;
} current, previous;
struct {
int l, r, t, b;
} border, sel_border;
struct {
Window main, evas;
} win;
Evas evas;
Ebits_Object bg;
Evas_List entries;
char *bg_file;
int first_expose;
int recalc_entries;
int redo_sel;
int changed;
int delete_me;
struct {
int state, icon, text;
} size;
struct {
int icon, state;
} pad;
E_Menu_Item *selected;
Time time;
void (*func_hide) (E_Menu *m, void *data);
void *func_hide_data;
};
struct _E_Menu_Item
{
int x, y;
struct {
struct {
int w, h;
} min;
int w, h;
} size;
Ebits_Object bg;
char *bg_file;
int selected;
Evas_Object obj_entry;
char *str;
Evas_Object obj_text;
char *icon;
Evas_Object obj_icon;
int scale_icon;
Ebits_Object state;
char *state_file;
Ebits_Object sep;
char *sep_file;
int separator;
int radio_group;
int radio;
int check;
int on;
E_Menu *menu;
E_Menu *submenu;
void (*func_select) (E_Menu *m, E_Menu_Item *mi, void *data);
void *func_select_data;
};
/**
* e_menu_init - Menu event handling initalization.
*
* This function hooks in the necessary event handlers for
* menu handling.
*/
void e_menu_init(void );
void e_menu_callback_item(E_Menu *m, E_Menu_Item *mi);
void e_menu_item_set_callback(E_Menu_Item *mi, void (*func) (E_Menu *m, E_Menu_Item *mi, void *data), void *data);
void e_menu_hide_callback(E_Menu *m, void (*func) (E_Menu *m, void *data), void *data);
void e_menu_hide_submenus(E_Menu *menus_after);
void e_menu_select(int dx, int dy);
void e_menu_event_win_show(void );
void e_menu_event_win_hide(void );
void e_menu_set_background(E_Menu *m);
void e_menu_set_sel(E_Menu *m, E_Menu_Item *mi);
void e_menu_set_sep(E_Menu *m, E_Menu_Item *mi);
void e_menu_set_state(E_Menu *m, E_Menu_Item *mi);
E_Menu *e_menu_new(void );
void e_menu_hide(E_Menu *m);
void e_menu_show(E_Menu *m);
void e_menu_move_to(E_Menu *m, int x, int y);
void e_menu_show_at_mouse(E_Menu *m, int x, int y, Time t);
void e_menu_add_item(E_Menu *m, E_Menu_Item *mi);
void e_menu_del_item(E_Menu *m, E_Menu_Item *mi);
void e_menu_item_update(E_Menu *m, E_Menu_Item *mi);
void e_menu_item_unrealize(E_Menu *m, E_Menu_Item *mi);
void e_menu_item_realize(E_Menu *m, E_Menu_Item *mi);
E_Menu_Item *e_menu_item_new(char *str);
void e_menu_obscure_outside_screen(E_Menu *m);
void e_menu_scroll_all_by(int dx, int dy);
void e_menu_update_visibility(E_Menu *m);
void e_menu_update_base(E_Menu *m);
void e_menu_update_finish(E_Menu *m);
void e_menu_update_shows(E_Menu *m);
void e_menu_update_hides(E_Menu *m);
void e_menu_update(E_Menu *m);
void e_menu_item_set_icon(E_Menu_Item *mi, char *icon);
void e_menu_item_set_text(E_Menu_Item *mi, char *text);
void e_menu_item_set_separator(E_Menu_Item *mi, int sep);
void e_menu_item_set_radio(E_Menu_Item *mi, int radio);
void e_menu_item_set_check(E_Menu_Item *mi, int check);
void e_menu_item_set_state(E_Menu_Item *mi, int state);
void e_menu_item_set_submenu(E_Menu_Item *mi, E_Menu *submenu);
void e_menu_item_set_scale_icon(E_Menu_Item *mi, int scale);
void e_menu_set_padding_icon(E_Menu *m, int pad);
void e_menu_set_padding_state(E_Menu *m, int pad);
#endif