|
GnuCash 2.4.99
|
00001 /********************************************************************\ 00002 * gnc-component-manager.h - GUI component manager interface * 00003 * Copyright (C) 2000 Dave Peticolas <dave@krondo.com> * 00004 * * 00005 * This program is free software; you can redistribute it and/or * 00006 * modify it under the terms of the GNU General Public License as * 00007 * published by the Free Software Foundation; either version 2 of * 00008 * the License, or (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License* 00016 * along with this program; if not, write to the Free Software * 00017 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 00018 \********************************************************************/ 00019 00020 #ifndef GNC_COMPONENT_MANAGER_H 00021 #define GNC_COMPONENT_MANAGER_H 00022 00023 #include <glib.h> 00024 00025 #include "GNCId.h" 00026 #include "qof.h" 00027 00028 00029 #define NO_COMPONENT (-1) 00030 00031 typedef struct 00032 { 00033 QofEventId event_mask; 00034 } EventInfo; 00035 00036 00037 /* GNCComponentRefreshHandler 00038 * Handler invoked to inform the component that a refresh 00039 * may be needed. 00040 * 00041 * changes: if NULL, the component should perform a refresh. 00042 * 00043 * if non-NULL, changes is a GncGUID hash that maps 00044 * GUIDs to EventInfo structs describing which 00045 * events have been received. Entities not in 00046 * the hash have not generated any events. 00047 * Entities which have been destroyed will be in 00048 * the hash, but may not exist anymore. 00049 * 00050 * Note since refreshes may not occur with every change, 00051 * an entity may have all three change values. 00052 * 00053 * The component should use 'changes' to determine whether 00054 * or not a refresh is needed. The hash table must not be 00055 * changed. 00056 * 00057 * Notes on refreshing: when the handler is invoked any engine 00058 * entities used by the component may have 00059 * already been deleted. 'Refreshing' the 00060 * component may require closing the component. 00061 * 00062 * Notes on dealing with destroyed entities: As stated above, entities 00063 * in the changes GHashTable may no longer exist. So how can you 00064 * determine if this has happened? Well, it's a good idea to check 00065 * for the QOF_EVENT_DESTROY bit in the EventInfo structure. Of 00066 * course, that means you need the hash key (GncGUID) for the destroyed 00067 * entity. How are you going to get the GncGUID from the entity if the 00068 * entity has already been destroyed? You're not. So, you have to 00069 * save a COPY of the key (GncGUID) away beforehand. 00070 * 00071 * user_data: user_data supplied when component was registered. 00072 */ 00073 typedef void (*GNCComponentRefreshHandler) (GHashTable *changes, 00074 gpointer user_data); 00075 00076 /* GNCComponentCloseHandler 00077 * Handler invoked to close the component. 00078 * 00079 * user_data: user_data supplied when component was registered. 00080 * 00081 * Notes on closing: components are not automatically unregistered 00082 * when the close handler is invoked. Components 00083 * may not ignore the handler. 00084 */ 00085 typedef void (*GNCComponentCloseHandler) (gpointer user_data); 00086 00087 00088 /* GNCComponentFindHandler 00089 * Handler invoked when searching for a component. 00090 * 00091 * find_data: find_data supplied when search was started. 00092 * user_data: user_data supplied when component was registered. 00093 * 00094 * Return: TRUE if the component matches the search criteria. 00095 */ 00096 typedef gboolean (*GNCComponentFindHandler) (gpointer find_data, 00097 gpointer user_data); 00098 00099 /* GNCComponentHandler 00100 * Generic handler used in iterating over components. 00101 * 00102 * component_class: class of component 00103 * component_id: id of component 00104 * iter_data: user_data supplied by caller 00105 * 00106 * Return: TRUE if the callback did something 00107 */ 00108 typedef gboolean (*GNCComponentHandler) (const char *class, 00109 gint component_id, 00110 gpointer user_data, 00111 gpointer iter_data); 00112 00113 /* gnc_component_manager_init 00114 * Initialize the component manager. 00115 */ 00116 void gnc_component_manager_init (void); 00117 00118 /* gnc_component_manager_shutdown 00119 * Shutdown the component manager. 00120 */ 00121 void gnc_component_manager_shutdown (void); 00122 00123 /* gnc_register_gui_component 00124 * Register a GUI component with the manager. 00125 * 00126 * component_class: a string defining a class of components 00127 * certain component functions can be performed 00128 * on all components in a class. For that reason, 00129 * components in the same class should all use 00130 * the same type for user_data. 00131 * 00132 * refresh_cb: refresh handler, may be NULL 00133 * close_cb: close handler, may be NULL 00134 * user_data: user_data argument for handlers 00135 * 00136 * 00137 * Notes: After a refresh handler is registered, the 00138 * component must use the API calls below to 00139 * inform the component manager which engine 00140 * entities are being 'watched', i.e., which 00141 * engine entities may cause the component 00142 * to need refreshing. 00143 * 00144 * When a component is first registered, it 00145 * is not watching anything, and thus will 00146 * not receive refresh events. 00147 * 00148 * Return: id of component, or NO_COMPONENT, if error 00149 */ 00150 gint gnc_register_gui_component (const char *component_class, 00151 GNCComponentRefreshHandler refresh_handler, 00152 GNCComponentCloseHandler close_handler, 00153 gpointer user_data); 00154 00155 /* gnc_gui_component_set_session 00156 * Set the associated session of this component 00157 * 00158 * component_id: id of component which is watching the entity 00159 * session: the session this component is associated with 00160 */ 00161 void gnc_gui_component_set_session (gint component_id, gpointer session); 00162 00163 /* gnc_gui_component_watch_entity 00164 * Add an entity to the list of those being watched by the component. 00165 * Only entities with refresh handlers should add watches. 00166 * 00167 * component_id: id of component which is watching the entity 00168 * entity: id of entity to watch 00169 * event_mask: mask which determines which kinds of events are watched 00170 * setting the mask to 0 turns off watching for the entity. 00171 */ 00172 void gnc_gui_component_watch_entity (gint component_id, 00173 const GncGUID *entity, 00174 QofEventId event_mask); 00175 00176 /* gnc_gui_component_watch_entity_type 00177 * Watch all entities of a particular type. 00178 * 00179 * component_id: id of component which is watching the entity type 00180 * entity_type: type of entity to watch, either GNC_ID_TRANS or 00181 * GNC_ID_ACCOUNT 00182 * event_mask: mask which determines which kinds of events are watched 00183 * setting the mask to 0 turns off watching for the entity type 00184 */ 00185 void gnc_gui_component_watch_entity_type (gint component_id, 00186 QofIdTypeConst entity_type, 00187 QofEventId event_mask); 00188 00189 /* gnc_gui_get_entity_events 00190 * Return the event info of the events which have been generated by 00191 * the given entity. 00192 * 00193 * changes: a hash of changes as in the refresh handler 00194 * entity: the GncGUID of the entity to get the event mask for 00195 * 00196 * Returns: the event info of the entity, or NULL 00197 * if it is not found. 00198 */ 00199 const EventInfo * gnc_gui_get_entity_events (GHashTable *changes, 00200 const GncGUID *entity); 00201 00202 /* gnc_gui_component_clear_watches 00203 * Clear all watches for the component. 00204 * 00205 * component_id: id of component to clear watches for. 00206 */ 00207 void gnc_gui_component_clear_watches (gint component_id); 00208 00209 /* gnc_unregister_gui_component 00210 * Unregister a gui component from the manager. 00211 * 00212 * component_id: id of component to unregister 00213 */ 00214 void gnc_unregister_gui_component (gint component_id); 00215 00216 /* gnc_unregister_gui_component_by_data 00217 * Unregister a gui component using the user_data pointer. 00218 * 00219 * component_class: class component is in 00220 * user_data: user_data pointer of component to unregister 00221 * all components with that user_data in the 00222 * class are unregistered. 00223 */ 00224 void gnc_unregister_gui_component_by_data (const char *component_class, 00225 gpointer user_data); 00226 00227 /* gnc_suspend_gui_refresh 00228 * Suspend refresh handlers by the component manager. 00229 * This routine may be called multiple times. Each call 00230 * increases the suspend counter (starts at zero). 00231 */ 00232 void gnc_suspend_gui_refresh (void); 00233 00234 /* gnc_resume_gui_refresh 00235 * Resume refresh handlers by the component manager. 00236 * Each call reduces the suspend counter by one. When 00237 * the counter reaches zero, all changes which have 00238 * occured since the last refresh are collected and 00239 * passed to the components in refresh handlers. 00240 */ 00241 void gnc_resume_gui_refresh (void); 00242 00243 /* gnc_gui_refresh_all 00244 * Force all components to refresh. 00245 * 00246 * This routine may only be invoked when the suspend counter 00247 * is zero. It should never be mixed with the suspend/resume 00248 * refresh routines. 00249 */ 00250 void gnc_gui_refresh_all (void); 00251 00252 /* gnc_gui_refresh_suspended 00253 * Return TRUE if gui refreshes are suspended. 00254 */ 00255 gboolean gnc_gui_refresh_suspended (void); 00256 00257 /* gnc_close_gui_component 00258 * Invoke the close handler for the indicated component. 00259 * 00260 * component_id: id of component to close 00261 */ 00262 void gnc_close_gui_component (gint component_id); 00263 00264 /* gnc_close_gui_component_by_data 00265 * Invoke the close handler for components in the given 00266 * class with the given user_data. 00267 * 00268 * component_class: class to close components in 00269 * user_data: user_data of component to close 00270 * all components with that user_data 00271 * are closed. 00272 */ 00273 void gnc_close_gui_component_by_data (const char *component_class, 00274 gpointer user_data); 00275 00276 /* gnc_close_gui_component_by_session 00277 * Invoke the close handler for components with the given session 00278 * 00279 * session: session to close 00280 * all components with that session 00281 * are closed. 00282 */ 00283 void gnc_close_gui_component_by_session (gpointer session); 00284 00285 /* gnc_find_gui_components 00286 * Search for components in the specified class. 00287 * 00288 * component_class: the class to search for components in 00289 * must be non-NULL 00290 * find_cb: the handler used to search for the component 00291 * if NULL, all components in class are returned 00292 * find_data: find_data passed to find_cb 00293 * 00294 * Returns: GList of user_data of found components, or NULL if none found 00295 * The list should be freed with g_list_free(). 00296 * 00297 * Notes on finding: components should not be registered or unregistered 00298 * by the find callback. 00299 */ 00300 GList * gnc_find_gui_components (const char *component_class, 00301 GNCComponentFindHandler find_handler, 00302 gpointer find_data); 00303 00304 /* gnc_find_first_gui_component 00305 * Search for the first matching component in the specified class. 00306 * 00307 * component_class: the class to search for components in 00308 * must be non-NULL 00309 * find_cb: the handler used to search for the component 00310 * must be non-null 00311 * find_data: find_data passed to find_cb 00312 * 00313 * Returns: user_data of first found component, or NULL if none found 00314 * 00315 * Notes on finding: components should not be registered or unregistered 00316 * by the find callback. 00317 */ 00318 gpointer gnc_find_first_gui_component (const char *component_class, 00319 GNCComponentFindHandler find_handler, 00320 gpointer find_data); 00321 00322 /* gnc_forall_gui_components 00323 * Invoke 'handler' for components in the database. 00324 * 00325 * component_class: class to iterate over, if NULL then 00326 * all classes are iterated over 00327 * handler: handler to invoke 00328 * iter_data: data passed to handler 00329 * 00330 * Notes on forall: components may be unregistered by the handler, 00331 * but no components should be registered. 00332 */ 00333 gint gnc_forall_gui_components (const char *component_class, 00334 GNCComponentHandler handler, 00335 gpointer iter_data); 00336 00337 #endif
1.7.4