1 // GTK_APP.H : a GTK2 application class. 2 3 // Copyright (C) 2003 Tommi Hassinen. 4 5 // This package is free software; you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation; either version 2 of the License, or 8 // (at your option) any later version. 9 10 // This package is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 15 // You should have received a copy of the GNU General Public License 16 // along with this package; if not, write to the Free Software 17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 19 /*################################################################################################*/ 20 21 #ifndef GTK_APP_H 22 #define GTK_APP_H 23 24 #include "ghemicalconfig2.h" 25 26 struct pv_views_objs_record; 27 struct pv_chains_record; 28 struct pv_atoms_record; 29 struct pv_bonds_record; 30 31 #include <glib.h> 32 #include <unistd.h> 33 34 #include "custom_app.h" 35 #include "gtk_project.h" 36 37 // uncomment this if you wish to have the traditional short toolbar labels. 38 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 39 #define USE_SHORT_TOOLBAR_LABELS 40 41 /*################################################################################################*/ 42 43 struct pv_viewsobjs_record 44 { 45 custom_camera * owner; ///< this is non-NULL for child items. 46 47 ogl_dummy_object * refV1; ///< for camera/light-type objects. 48 base_wcl * refV2; ///< for view/client-type objects. 49 50 ogl_smart_object * refO; ///< for object-type objects. 51 52 GtkTreeIter iter; 53 }; 54 55 struct pv_chains_record 56 { 57 i32s c_r_ind; 58 GtkTreeIter iter; 59 }; 60 61 struct pv_atoms_record 62 { 63 atom * ref; 64 GtkTreeIter iter; 65 }; 66 67 struct pv_bonds_record 68 { 69 bond * ref; 70 GtkTreeIter iter; 71 }; 72 73 class gtk_app : 74 public custom_app 75 { 76 protected: 77 78 static GtkActionEntry entries1[]; 79 static GtkToggleActionEntry entries2[]; 80 static const char * ui_description; 81 82 static GtkUIManager * ui_manager; 83 84 static GtkWidget * main_window; 85 static GtkWidget * main_vbox; 86 87 static GtkWidget * main_menubar; 88 static GtkWidget * main_toolbar; 89 90 static GtkWidget * mtb_mtool_draw; 91 static GtkWidget * mtb_mtool_erase; 92 static GtkWidget * mtb_mtool_select; 93 static GtkWidget * mtb_mtool_zoom; 94 static GtkWidget * mtb_mtool_clipping; 95 static GtkWidget * mtb_mtool_translate_xy; 96 static GtkWidget * mtb_mtool_translate_z; 97 static GtkWidget * mtb_mtool_orbit_xy; 98 static GtkWidget * mtb_mtool_orbit_z; 99 static GtkWidget * mtb_mtool_rotate_xy; 100 static GtkWidget * mtb_mtool_rotate_z; 101 static GtkWidget * mtb_mtool_measure; 102 103 // here is the former gtk_project stuff... 104 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 105 106 static GtkWidget * paned_widget; 107 108 static GtkWidget * notebook_widget; 109 110 static GtkTextBuffer * txt_buffer; 111 static GtkTextMark * end_mark; 112 113 static GtkWidget * scroll_widget; 114 static GtkWidget * txt_widget; 115 116 // here is the former gtk_project_view stuff... 117 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 118 119 static GtkActionEntry pv_viewsobjs_entries[]; 120 static const char * pv_viewsobjs_ui_description; 121 122 static GtkActionEntry pv_chains_entries[]; 123 static const char * pv_chains_ui_description; 124 125 static GtkActionEntry pv_atoms_entries[]; 126 static const char * pv_atoms_ui_description; 127 128 static GtkActionEntry pv_bonds_entries[]; 129 static const char * pv_bonds_ui_description; 130 131 static GtkWidget * pv_view_widget; 132 static GtkWidget * pv_label_widget; 133 134 list<pv_viewsobjs_record *> pv_viewsobjs_data; 135 GtkTreeStore * pv_viewsobjs_store; 136 GtkWidget * pv_viewsobjs_widget; 137 GtkWidget * pv_viewsobjs_label; 138 GtkWidget * pv_viewsobjs_menu; 139 GtkWidget * pv_viewsobjs_sw; 140 141 list<pv_chains_record *> pv_chains_data; 142 GtkTreeStore * pv_chains_store; 143 GtkWidget * pv_chains_widget; 144 GtkWidget * pv_chains_label; 145 GtkWidget * pv_chains_menu; 146 GtkWidget * pv_chains_sw; 147 148 list<pv_atoms_record *> pv_atoms_data; 149 GtkListStore * pv_atoms_store; 150 GtkWidget * pv_atoms_widget; 151 GtkWidget * pv_atoms_label; 152 GtkWidget * pv_atoms_menu; 153 GtkWidget * pv_atoms_sw; 154 155 list<pv_bonds_record *> pv_bonds_data; 156 GtkListStore * pv_bonds_store; 157 GtkWidget * pv_bonds_widget; 158 GtkWidget * pv_bonds_label; 159 GtkWidget * pv_bonds_menu; 160 GtkWidget * pv_bonds_sw; 161 162 // friends... 163 // ^^^^^^^^^^ 164 friend class gtk_file_open_dialog; 165 166 private: 167 168 // the constructor is private so that only a single instance 169 // of the class can be created (by calling GetGtkApp()). 170 171 gtk_app(void); 172 173 public: 174 175 ~gtk_app(void); 176 177 static gtk_app * GetAppX(void); 178 static gtk_project * GetPrjX(void); 179 180 void AttachDetachView(base_wcl *); 181 void SetTransientForMainWnd(GtkWindow *); 182 183 void AddTabToNB(GtkWidget *, GtkWidget *); 184 void RemoveTabFromNB(GtkWidget *); 185 186 void SetTabTitleNB(GtkWidget *, GtkWidget *); 187 188 protected: 189 190 void InitPV(void); 191 192 void SetNewProject(void); // virtual 193 194 static gboolean DeleteEventHandler(GtkWidget *, GdkEvent *, gpointer); 195 static void DestroyHandler(GtkWidget *, gpointer); 196 197 public: 198 199 static void sMessage(const char *); 200 static void sWarningMessage(const char *); 201 static void sErrorMessage(const char *); 202 203 static bool sQuestion(const char *); 204 static void sPrintToLog(const char *); 205 206 void Message(const char *); // virtual 207 void WarningMessage(const char *); // virtual 208 void ErrorMessage(const char *); // virtual 209 210 bool Question(const char *); // virtual 211 void PrintToLog(const char *); // virtual 212 GetUIManager(void)213 static GtkUIManager * GetUIManager(void) { return ui_manager; } GetMainWindow(void)214 static GtkWidget * GetMainWindow(void) { return main_window; } 215 216 void UpdateAllWindowTitles(void); // virtual 217 218 void CameraAdded(custom_camera *); // virtual 219 void CameraRemoved(custom_camera *); // virtual 220 221 void LightAdded(ogl_light *); // virtual 222 void LightRemoved(ogl_light *); // virtual 223 224 void GraphicsClientAdded(oglview_wcl *); // virtual 225 void GraphicsClientRemoved(oglview_wcl *); // virtual 226 227 void PlottingClientAdded(base_wcl *); // virtual 228 void PlottingClientRemoved(base_wcl *); // virtual 229 230 void ObjectAdded(ogl_smart_object *); // virtual 231 void ObjectRemoved(ogl_smart_object *); // virtual 232 233 static gint ViewsObjsPopupHandler(GtkWidget *, GdkEvent *); 234 static void viewsobjs_SetCurrent(GtkWidget *, gpointer); 235 static void viewsobjs_Delete(GtkWidget *, gpointer); 236 237 void BuildChainsView(void); // virtual 238 void ClearChainsView(void); // virtual 239 static gint ChainsPopupHandler(GtkWidget *, GdkEvent *); 240 static void chains_UpdateView(GtkWidget *, gpointer); 241 static void chains_SelectItem(GtkWidget *, gpointer); 242 243 void AtomAdded(atom *); // virtual 244 void AtomUpdateItem(atom *); // virtual 245 void AtomRemoved(atom *); // virtual 246 static gint AtomsPopupHandler(GtkWidget *, GdkEvent *); 247 static void atoms_SelectAtom(GtkWidget *, gpointer); 248 static gint atoms_ToggleLocked(GtkWidget *, gchar *, gpointer *); 249 250 void BondAdded(bond *); // virtual 251 void BondUpdateItem(bond *); // virtual 252 void BondRemoved(bond *); // virtual 253 static gint BondsPopupHandler(GtkWidget *, GdkEvent *); 254 static void bonds_SelectBond(GtkWidget *, gpointer); 255 256 // the toolbar-button callbacks start here ; the toolbar-button callbacks start here 257 // the toolbar-button callbacks start here ; the toolbar-button callbacks start here 258 // the toolbar-button callbacks start here ; the toolbar-button callbacks start here 259 260 static void HandleToggleButtons(custom_app::mtool); 261 static void maintb_tool_Draw(gpointer, guint, GtkWidget *); 262 static void maintb_tool_Erase(gpointer, guint, GtkWidget *); 263 static void maintb_tool_Select(gpointer, guint, GtkWidget *); 264 static void maintb_tool_Zoom(gpointer, guint, GtkWidget *); 265 static void maintb_tool_Clipping(gpointer, guint, GtkWidget *); 266 static void maintb_tool_TranslateXY(gpointer, guint, GtkWidget *); 267 static void maintb_tool_TranslateZ(gpointer, guint, GtkWidget *); 268 static void maintb_tool_OrbitXY(gpointer, guint, GtkWidget *); 269 static void maintb_tool_OrbitZ(gpointer, guint, GtkWidget *); 270 static void maintb_tool_RotateXY(gpointer, guint, GtkWidget *); 271 static void maintb_tool_RotateZ(gpointer, guint, GtkWidget *); 272 static void maintb_tool_Measure(gpointer, guint, GtkWidget *); 273 274 static void maintb_dial_Element(gpointer, guint, GtkWidget *); 275 static void maintb_dial_BondType(gpointer, guint, GtkWidget *); 276 static void maintb_dial_Setup(gpointer, guint, GtkWidget *); 277 278 // the main-menu callbacks start here ; the main-menu callbacks start here 279 // the main-menu callbacks start here ; the main-menu callbacks start here 280 // the main-menu callbacks start here ; the main-menu callbacks start here 281 282 static void mainmenu_FileNew(gpointer, guint, GtkWidget *); 283 static void mainmenu_FileOpen(gpointer, guint, GtkWidget *); 284 static void mainmenu_FileSaveAs(gpointer, guint, GtkWidget *); 285 static void mainmenu_FileClose(gpointer, guint, GtkWidget *); 286 287 static void mainmenu_HelpHelp(gpointer, guint, GtkWidget *); 288 static void mainmenu_HelpAbout(gpointer, guint, GtkWidget *); 289 }; 290 291 /*################################################################################################*/ 292 293 #endif // GTK_APP_H 294 295 // eof 296