applet-widget.h 6.5 KB
Newer Older
1 2 3 4 5 6
#ifndef __APPLET_WIDGET_H__
#define __APPLET_WIDGET_H__

#include <gtk/gtk.h>
#include <gnome.h>

7 8
#define HAVE_SAVE_SESSION_SIGNAL 1

9 10 11 12
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

13 14 15 16 17 18 19 20 21
#ifndef PANEL_H
/*from panel.h*/
typedef enum {
	ORIENT_UP,
	ORIENT_DOWN,
	ORIENT_LEFT,
	ORIENT_RIGHT
} PanelOrientType;
#endif
22

23 24 25 26 27 28 29 30 31
#ifndef __PANEL_WIDGET_H__
/*from panel-widget.h*/
typedef enum {
	PANEL_BACK_NONE,
	PANEL_BACK_COLOR,
	PANEL_BACK_PIXMAP
} PanelBackType;
#endif

32 33 34 35 36 37 38
#define APPLET_WIDGET(obj)          GTK_CHECK_CAST (obj, applet_widget_get_type (), AppletWidget)
#define APPLET_WIDGET_CLASS(klass)  GTK_CHECK_CLASS_CAST (klass, applet_widget_get_type (), AppletWidgetClass)
#define IS_APPLET_WIDGET(obj)       GTK_CHECK_TYPE (obj, applet_widget_get_type ())

typedef struct _AppletWidget		AppletWidget;
typedef struct _AppletWidgetClass	AppletWidgetClass;

39
typedef void (*AppletCallbackFunc)(AppletWidget *applet, gpointer data);
George Lebl's avatar
George Lebl committed
40
typedef void (*AppletStartNewFunc)(const char *param, gpointer data);
41

42 43 44 45
struct _AppletWidget
{
	GtkPlug			window;

George Lebl's avatar
George Lebl committed
46
	int			applet_id;
47

48
	/* use these as prefixes when loading saving data */
49 50 51 52 53
	char			*cfgpath; /*source compatibility SHOULD BE REMOVED
					    when session_save signal is removed*/
	char			*globcfgpath; /*a file which applets can use for
						global settings*/
	char			*privcfgpath; /*applets own cfg path*/
54 55 56 57 58 59
};

struct _AppletWidgetClass
{
	GtkPlugClass parent_class;

60 61 62 63
	/* when the orientation of the parent panel changes, you should 
	   connect this signal before doing applet_widget_add so that
	   you get an initial change_orient signal during the add, so
	   that you can update your orientation properly */
64 65
	void (* change_orient) (AppletWidget *applet,
				PanelOrientType orient);
66 67 68 69
	/* the panel background changes, the pixmap handeling is likely
	   to change */
	void (* back_change) (AppletWidget *applet,
			      PanelBackType type,
George Lebl's avatar
George Lebl committed
70
			      char *pixmap,
71 72 73 74 75
			      GdkColor *color);
	/*will send the current state of the tooltips, if they are enabled
	  or disabled, you should only need this if you are doing something
	  weird*/
	void (* tooltip_state) (AppletWidget *applet,
George Lebl's avatar
George Lebl committed
76
				int enabled);
77 78 79
	/*when the panel wants to save a session it will call this signal 
	  if you trap it make sure you do gnome_config_sync() and
	  gnome_config_drop_all() after your done otherwise the changes
George Lebl's avatar
George Lebl committed
80 81
	  might not be written to file, also make sure you return
	  FALSE from this signal or your position wil not get saved!*/
82 83 84 85 86 87
	int (* save_session) (AppletWidget *applet,
			      char *cfgpath,
			      char *globcfgpath);

	/*old version of the signal ... about to be phased out,
	  DO NOT USE THIS SIGNAL IN NEW APPLETS*/
George Lebl's avatar
George Lebl committed
88
	int (* session_save) (AppletWidget *applet,
89 90
			      char *cfgpath,
			      char *globcfgpath);
91 92 93
};

guint		applet_widget_get_type		(void);
94 95 96

/*start one but add a parameter that the panel should use next time
  to start us*/
George Lebl's avatar
George Lebl committed
97
GtkWidget*	applet_widget_new_with_param	(const char *param);
98 99 100


/*start a normal applet*/
101 102
#define applet_widget_new()	\
	applet_widget_new_with_param("")
103 104

/*set tooltip over the applet, NULL to remove a tooltip*/
105
void		applet_widget_set_tooltip	(AppletWidget *applet,
George Lebl's avatar
George Lebl committed
106
						 char *text);
107

108 109 110
/*set tooltip on a specific widget inside the applet*/
void		applet_widget_set_widget_tooltip(AppletWidget *applet,
						 GtkWidget *widget,
George Lebl's avatar
George Lebl committed
111
						 char *text);
112

113 114 115 116
/* add a widget to the plug and register the applet, this has to
   be done after all the children had been added so that the applet-lib
   can bind the events over them so that peoplce can move them with
   the second button, get the menu, etc ...*/
117 118 119
void		applet_widget_add		(AppletWidget *applet,
						 GtkWidget *widget);

120 121 122
/* remove the plug from the panel, this will destroy the applet */
void		applet_widget_remove_from_panel (AppletWidget *applet);

123 124 125 126 127 128 129
/* The callback functions control the applet's right click menu, the name
   is just a string, which has to be unique and which controls the nesting,
   for example a name of "foo/bar" will add an item to the submenu
   identified by "/foo" (which you should have created before with
   register_callback_dir, use this for properies callback, help, about,
   etc... etc...
*/
Jiri (George) Lebl's avatar
Jiri (George) Lebl committed
130
/*add a callback onto the applet's right click menu*/
131
void		applet_widget_register_callback	(AppletWidget *applet,
George Lebl's avatar
George Lebl committed
132 133
						 char *name,
						 char *menutext,
134 135
						 AppletCallbackFunc func,
						 gpointer data);
136
void		applet_widget_register_stock_callback	(AppletWidget *applet,
George Lebl's avatar
George Lebl committed
137 138 139
							 char *name,
							 char *stock_type,
							 char *menutext,
140 141
							 AppletCallbackFunc func,
							 gpointer data);
Jiri (George) Lebl's avatar
Jiri (George) Lebl committed
142 143
/*remove a menuitem*/
void		applet_widget_unregister_callback (AppletWidget *applet,
George Lebl's avatar
George Lebl committed
144
						   char *name);
Jiri (George) Lebl's avatar
Jiri (George) Lebl committed
145 146
/*add a submenu*/
void		applet_widget_register_callback_dir (AppletWidget *applet,
George Lebl's avatar
George Lebl committed
147 148
						     char *name,
						     char *menutext);
149
void		applet_widget_register_stock_callback_dir (AppletWidget *applet,
George Lebl's avatar
George Lebl committed
150 151 152
							   char *name,
							   char *stock_type,
							   char *menutext);
Jiri (George) Lebl's avatar
Jiri (George) Lebl committed
153 154
/*remove a submenu*/
void		applet_widget_unregister_callback_dir (AppletWidget *applet,
George Lebl's avatar
George Lebl committed
155
						       char *name);
Jiri (George) Lebl's avatar
Jiri (George) Lebl committed
156

157 158

/* get the applet widget with the id of applet_id */
George Lebl's avatar
George Lebl committed
159
AppletWidget*	applet_widget_get_by_id		(int applet_id);
160

161
/*get thenumber of applets*/
George Lebl's avatar
George Lebl committed
162
int		applet_widget_get_applet_count	(void);
163

164 165 166 167
/*tell the panel to save the session here (just saves no shutdown),
  this should be done when you change some of your config and want
  the panel to save it's config, you should NOT call this in the
  session_save handler as it will result in a locked panel*/
168
void		applet_widget_sync_config	(void);
169

170
/* Get the oprientation the applet should use */
171 172
PanelOrientType	applet_widget_get_panel_orient	(AppletWidget *applet);

173

174 175 176 177 178 179 180 181 182
/*use this instead of gnome init, if you want multi applet, you also
  have to specify a "start new applet" function which will launch a new
  applet*/
error_t		applet_widget_init		(char *app_id,
						 struct argp *app_parser,
						 int argc,
						 char **argv,
						 unsigned int flags,
						 int *arg_index,
George Lebl's avatar
George Lebl committed
183 184 185
						 char *argv0,
						 int last_die,
						 int multi_applet,
186 187 188 189 190 191 192 193 194 195
						 AppletStartNewFunc new_func,
						 gpointer new_func_data);

/*defaults init for use with "normal" non-multi applets*/
#define \
applet_widget_init_defaults(app_id,app_parser,argc,argv,flags,arg_index,argv0) \
applet_widget_init(app_id,app_parser,argc,argv,flags,arg_index, \
		   argv0,TRUE,FALSE,NULL,NULL)


196
/* use this as gtk_main in applets */
197 198
void		applet_widget_gtk_main		(void);

199
/* convenience function for multi applets */
George Lebl's avatar
George Lebl committed
200
char *		make_param_string		(int argc, char *argv[]);
201

202 203 204 205 206 207
#ifdef __cplusplus
}
#endif /* __cplusplus */


#endif /* __APPLET_WIDGET_H__ */