1 // -*- C++ -*- 2 3 /* 4 * Gnome Chemistry Utils 5 * gcugtk/application.h 6 * 7 * Copyright (C) 2005-2012 Jean Bréfort <jean.brefort@normalesup.org> 8 * 9 * This program is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU General Public License as 11 * published by the Free Software Foundation; either version 3 of the 12 * License, or (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 22 * USA 23 */ 24 25 #ifndef GCU_GTK_APPLICATION_H 26 #define GCU_GTK_APPLICATION_H 27 28 #include <gcu/application.h> 29 30 namespace gcu { 31 class Object; 32 } 33 34 /*!\file*/ 35 /*!\namespace gcugtk 36 \brief The Gtk using base classes. 37 38 The namespace used for C++ base classes usin Gtk+. This namespace implements 39 various virtual classes defined in namespace gcu. 40 */ 41 namespace gcugtk { 42 43 class Object; 44 class CmdContextGtk; 45 46 /*!\struct Database gcugtk/application.h 47 A simple struture storing a database name and the URI used to access it. 48 */ 49 typedef struct { 50 /*! 51 The database name as it will appear in the user interface 52 */ 53 std::string name; 54 /*! 55 The URI of the database. %I will be replaced by the molecule InChI, 56 %K by the InChiKey and %S by the SMILES of the target molecule. 57 */ 58 std::string uri; 59 } Database; 60 61 /*! 62 Window states 63 */ 64 typedef enum { 65 /*! 66 Normal window. 67 */ 68 NormalWindowState, 69 /*! 70 Maximized window. 71 */ 72 MaximizedWindowState, 73 /*! 74 Minimized window. 75 */ 76 MinimizedWindowState, 77 /*! 78 Full screen window. 79 */ 80 FullScreenWindowState 81 } WindowState; 82 83 /*!\class Application gcugtk/application.h 84 This class is a base class for applications. It provides some basic services. 85 */ 86 class Application: public gcu::Application 87 { 88 friend class ApplicationPrivate; 89 public: 90 /*! 91 @param name the name of the application. 92 @param datadir where data for the application are stored. 93 @param help_name the name to use for the help file (with .xml extension). 94 If NULL, the name parameter is used. 95 @param icon_name the name to use for the default icon of all windows. If NULL, 96 the help_name or name parameters will be used. 97 @param cc the associated CmdContextGtk. 98 99 The datadir variable is used to build the full path to the help file: 100 "file://"+datadir+"/gnome/help/"+name+"/"+LANG+"/"+name".xml". 101 */ 102 Application (std::string name, std::string datadir = DATADIR, char const *help_name = NULL, char const *icon_name = NULL, CmdContextGtk *cc = NULL); 103 /*! 104 The destructor. 105 */ 106 virtual ~Application (); 107 108 /*! 109 @return the default WindowState for the application. New window should use this setting. 110 */ GetDefaultWindowState()111 static WindowState GetDefaultWindowState () {return DefaultWindowState;} 112 113 /*! 114 @return a GtkWidget for managing pixmap resolution when saving as image. This widget is 115 intended to be added to a GtkFileChooserDialog. 116 */ 117 GtkWidget *GetImageResolutionWidget (); 118 119 /*! 120 @return a GtkWidget for managing pixmap width and height when saving as image. This 121 widget is intended to be added to a GtkFileChooserDialog. 122 */ 123 GtkWidget *GetImageSizeWidget (); 124 125 /*! 126 @param clipboard a GtkClipboard 127 @param selection_data the current GtkSelectionData 128 129 The virtual member called by OnReceiveTargets(). The defaullt implementation 130 does nothing. This method should be overriden for derived classes supporting 131 clipboard operations. 132 */ ReceiveTargets(G_GNUC_UNUSED GtkClipboard * clipboard,G_GNUC_UNUSED GtkSelectionData * selection_data)133 virtual void ReceiveTargets (G_GNUC_UNUSED GtkClipboard *clipboard, G_GNUC_UNUSED GtkSelectionData *selection_data) {;} 134 135 /*! 136 @param clipboard a GtkClipboard 137 @param selection_data the current GtkSelectionData 138 @param App the Application target 139 140 Static callback to pass as third argument to gtk_clipboard_request_contents(). 141 \a App must be used as fourth argument (user_data). 142 */ OnReceiveTargets(GtkClipboard * clipboard,GtkSelectionData * selection_data,Application * App)143 static void OnReceiveTargets (GtkClipboard *clipboard, GtkSelectionData *selection_data, Application *App) 144 { 145 App->ReceiveTargets (clipboard, selection_data); 146 } 147 148 /*! 149 @param screen the screen wher the uri should be displayed. 150 @param uri the uri to display. 151 152 Displays uri in the default web browser if any. 153 */ 154 void ShowURI (GdkScreen *screen, std::string& uri); 155 156 /*! 157 @param screen the screen where the uri should be displayed. 158 @param uri the uri to the package bugs database. Default value is PACKAGE_BUGREPORT. 159 160 Opens the bugs web page in the default browser if any. 161 */ 162 void OnBug (GdkScreen *screen, char const *uri = PACKAGE_BUGREPORT) 163 {std::string s (uri); ShowURI (screen, s);} 164 165 /*! 166 @param screen the screen where the uri should be displayed. 167 @param uri the uri to the main web page of the program. Default value is 168 "http://gchemutils.nongnu.org/". 169 */ 170 void OnWeb (GdkScreen *screen, char const *uri = "http://gchemutils.nongnu.org/") 171 {std::string s (uri); ShowURI (screen, s);} 172 173 /*! 174 @param screen the screen where the uri should be displayed. 175 @param MailAddress the mail adress to which a message will be sent. Defaults to the 176 Gnome Chemistry Utils main list. 177 178 Creates a new empty message using the default mail if any. 179 */ 180 void OnMail (GdkScreen *screen, char const *MailAddress = "mailto:gchemutils-main@nongnu.org"); 181 182 /*! 183 @param screen the screen where the IRC window should be displayed. 184 Attempts to open the \#gchemutils channel at irc.gimp.net. 185 */ 186 void OnLiveAssistance (GdkScreen *screen); 187 188 /*! 189 @return a dummy Application instance which might be used when there is no other 190 Application available. 191 */ 192 static Application *GetDefaultApplication (); 193 194 protected: 195 196 /*! 197 This method is called by the framework when all the documents have been removed from 198 the set of opened documents. The default behavior is to call gtk_main_quit and exit 199 the program. Derived class might overide this method to change this. 200 */ NoMoreDocsEvent()201 virtual void NoMoreDocsEvent () {gtk_main_quit ();} 202 203 /*! 204 Creates a default GtkCmdContext instance for the application. 205 */ 206 void CreateDefaultCmdContext (); 207 208 /*! 209 @return true if the main loop is running. 210 */ LoopRunning()211 bool LoopRunning () {return (gtk_main_level ());} 212 213 private: 214 static WindowState DefaultWindowState; 215 216 /*!\fn GetRecentManager() 217 @return the GtkRecentFileManager attached to the application. 218 */ 219 GCU_RO_PROP (GtkRecentManager*, RecentManager) 220 }; 221 222 } // namespace gcugtk 223 224 #endif // GCU_GTK_APPLICATION_H 225