Debian Codegraph @

src/af/xap/xp/xap_App.h

raw
1 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
2
3 /* AbiSource Application Framework
4 * Copyright (C) 1998,1999 AbiSource, Inc.
5 * Copyright (C) 2004 Hubert Figuiere
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301 USA.
21 */
22
23
24 #ifndef XAP_APP_H
25 #define XAP_APP_H
26
27 /* pre-emptive dismissal; ut_types.h is needed by just about everything,
28 * so even if it's commented out in-file that's still a lot of work for
29 * the preprocessor to do...
30 */
31 #ifndef UT_TYPES_H
32 #include "ut_types.h"
33 #endif
34 #include "ut_vector.h"
35 #include "ut_Language.h"
36 #include "ut_string_class.h"
37 #include "xap_AppImpl.h"
38 #include "xav_Listener.h"
39 #include <map>
40 #include <string>
41 #include <list>
42
43 #define NUM_MODELESSID 39
44
45 class XAP_DialogFactory;
46 class XAP_Dialog_Modeless;
47 class XAP_Toolbar_ControlFactory;
48 class XAP_Frame;
49 class EV_EditMethodContainer;
50 class EV_EditBindingMap;
51 class EV_EditEventMapper;
52 class EV_Menu_ActionSet;
53 class EV_Toolbar_ActionSet;
54 class XAP_BindingSet;
55 class XAP_Prefs;
56 class XAP_StringSet;
57 class XAP_Dictionary;
58 class PD_DocumentRange;
59 class AV_View;
60 class AD_Document;
61 class XAP_EncodingManager;
62 class UT_String;
63 class XAP_Menu_Factory;
64 class XAP_Toolbar_Factory;
65 class UT_UUIDGenerator;
66 class GR_GraphicsFactory;
67 class GR_Graphics;
68 class GR_AllocInfo;
69 class XAP_InputModes;
70 class AV_Listener;
71 class GR_EmbedManager;
72 class XAP_Module;
73 class UT_ScriptLibrary;
74
75
76 #define XAP_SD_FILENAME_LENGTH 256
77 #define XAP_SD_MAX_FILES 5
78
79 /*!
80 Date for storing state
81 Please note that this struction must not contain any pointers; the hildon state saving
82 mechanism simply memcopies its contents.
83 */
84 struct ABI_EXPORT XAP_StateData
85 {
86 XAP_StateData();
87 UT_uint32 iFileCount;
88 char filenames[XAP_SD_MAX_FILES][XAP_SD_FILENAME_LENGTH];
89 UT_uint32 iDocPos[XAP_SD_MAX_FILES];
90 UT_sint32 iXScroll[XAP_SD_MAX_FILES];
91 UT_sint32 iYScroll[XAP_SD_MAX_FILES];
92 };
93
94 /*****************************************************************
95 ******************************************************************
96 ** This file defines the base class for the cross-platform
97 ** application. This is used to hold all of the application-specific
98 ** data. Only one of these is created by the application.
99 ******************************************************************
100 *****************************************************************/
101
102 class ABI_EXPORT XAP_App
103 {
104 public: /* TODO these should be protected */
105 static const char* s_szBuild_ID;
106 static const char* s_szBuild_Version;
107 static const char* s_szBuild_Options;
108 static const char* s_szBuild_Target;
109 static const char* s_szBuild_CompileTime;
110 static const char* s_szBuild_CompileDate;
111 static const char* s_szAbiSuite_Home;
112
113 public:
114 static const char* getBuildId ();
115 static const char* getBuildVersion ();
116 static const char* getBuildOptions ();
117 static const char* getBuildTarget ();
118 static const char* getBuildCompileTime ();
119 static const char* getBuildCompileDate ();
120 static const char* getAbiSuiteHome ();
121
122 public:
123 XAP_App(const char * szAppName);
124 virtual ~XAP_App();
125
126 XAP_AppImpl* getImpl()
127 { return m_pImpl; }
128
129 virtual const char * getDefaultEncoding () const = 0 ;
130
131 virtual bool initialize(const char * szKeyBindingsKey, const char * szKeyBindingsDefaultValue);
132 virtual bool rememberFrame(XAP_Frame* pFrame, XAP_Frame* pCloneOf = 0);
133 virtual bool forgetFrame(XAP_Frame * pFrame);
134 virtual bool forgetClones(XAP_Frame * pFrame);
135 virtual bool getClones(UT_GenericVector<XAP_Frame*> *pvClonesCopy, XAP_Frame * pFrame);
136 virtual XAP_Frame * newFrame() = 0;
137 virtual void reallyExit() = 0;
138
139 bool updateClones(XAP_Frame * pFrame);
140
141 virtual void notifyFrameCountChange (); // default is empty method
142 UT_sint32 getFrameCount() const;
143 XAP_Frame * getFrame(UT_sint32 ndx) const;
144 UT_sint32 findFrame(XAP_Frame * pFrame) const;
145 UT_sint32 findFrame(const char * szFilename) const;
146
147 void enumerateFrames(UT_Vector & v) const;
148 std::list< AD_Document* > getDocuments( const AD_Document * pExclude = 0 ) const;
149 void enumerateDocuments(UT_Vector & v, const AD_Document * pExclude) const;
150 const char * getApplicationTitleForTitleBar() const;
151 const char * getApplicationName() const;
152
153 virtual void rebuildMenus(void);
154
155 EV_EditMethodContainer * getEditMethodContainer() const;
156 EV_EditBindingMap * getBindingMap(const char * szName);
157 XAP_BindingSet * getBindingSet(void)
158 { return m_pBindingSet;} /* the set of binding maps */
159 const EV_Menu_ActionSet * getMenuActionSet() const;
160 const EV_Toolbar_ActionSet * getToolbarActionSet() const;
161 const XAP_EncodingManager * getEncodingManager() const;
162 EV_Menu_ActionSet * getMenuActionSet();
163 EV_Toolbar_ActionSet * getToolbarActionSet();
164
165 // only used in ispell builds because aspell doesn't suck...
166 bool addWordToDict(const UT_UCSChar * pWord, UT_uint32 len);
167 bool isWordInDict(const UT_UCSChar * pWord, UT_uint32 len) const;
168 void suggestWord(UT_GenericVector<UT_UCSChar*> * pVecSuggestions, const UT_UCSChar * pWord, UT_uint32 lenWord);
169 XAP_Prefs * getPrefs() const;
170 bool getPrefsValue(const gchar * szKey, const gchar ** pszValue) const;
171 bool getPrefsValue(const UT_String &stKey, UT_String &stValue) const;
172 bool getPrefsValueBool(const gchar * szKey, bool * pbValue) const;
173
174 static XAP_App * getApp();
175
176 virtual XAP_DialogFactory * getDialogFactory() = 0;
177 virtual XAP_Toolbar_ControlFactory * getControlFactory() = 0;
178
179 virtual const XAP_StringSet * getStringSet() const = 0;
180 virtual void migrate(const char *oldName, const char *newName, const char *path) const;
181 virtual const char * getUserPrivateDirectory() = 0;
182 virtual const char * getAbiSuiteLibDir() const;
183 virtual const char * getAbiSuiteAppDir() const = 0;
184 virtual bool findAbiSuiteLibFile(std::string & path, const char * filename, const char * subdir = 0);
185 virtual bool findAbiSuiteAppFile(std::string & path, const char * filename, const char * subdir = 0); // doesn't check user-dir
186 virtual void copyToClipboard(PD_DocumentRange * pDocRange, bool bUseClipboard = true) = 0;
187 virtual void pasteFromClipboard(PD_DocumentRange * pDocRange, bool bUseClipboard, bool bHonorFormatting = true) = 0;
188 virtual bool canPasteFromClipboard() = 0;
189 virtual void cacheCurrentSelection(AV_View *) = 0;
190 virtual void addClipboardFmt (const char * /*szFormat*/) {}
191 virtual void deleteClipboardFmt (const char * /*szFormat*/) {}
192 void rememberFocussedFrame(void * pJustFocussedFrame);
193 XAP_Frame * getLastFocussedFrame() const;
194 XAP_Frame * findValidFrame() const;
195 bool safeCompare(XAP_Frame * lff, XAP_Frame * f);
196 UT_sint32 safefindFrame(XAP_Frame * f) const;
197 void clearLastFocussedFrame();
198 void clearIdTable();
199 bool setDebugBool(void) { m_bDebugBool = true; return m_bDebugBool; }
200 bool clearDebugBool(void) { m_bDebugBool = false; return m_bDebugBool; }
201 bool isDebug(void) { return m_bDebugBool; }
202 void rememberModelessId(UT_sint32 id, XAP_Dialog_Modeless * pDialog);
203 void forgetModelessId(UT_sint32 id);
204 bool isModelessRunning(UT_sint32 id);
205 XAP_Dialog_Modeless * getModelessDialog(UT_sint32 id);
206 void closeModelessDlgs();
207 void notifyModelessDlgsOfActiveFrame(XAP_Frame *p_Frame);
208 void notifyModelessDlgsCloseFrame(XAP_Frame *p_Frame);
209
210 virtual void setViewSelection(AV_View * /*pView*/) {}; //subclasses override
211 virtual AV_View * getViewSelection() { return static_cast<AV_View *>(NULL);} ; // subclasses override
212
213 virtual bool setGeometry(UT_sint32 x, UT_sint32 y,
214 UT_uint32 width, UT_uint32 height, UT_uint32 flags = 0);
215 virtual bool getGeometry(UT_sint32 *x, UT_sint32 *y,
216 UT_uint32 *width, UT_uint32 *height, UT_uint32 *flags = 0);
217 virtual void parseAndSetGeometry(const char *string);
218 virtual UT_sint32 makeDirectory(const char * szPath, const UT_sint32 mode ) const = 0;
219 XAP_Menu_Factory * getMenuFactory(void) const { return m_pMenuFactory; }
220 XAP_Toolbar_Factory * getToolbarFactory(void) const { return m_pToolbarFactory; }
221
222 typedef enum {BIDI_SUPPORT_NONE, BIDI_SUPPORT_GUI, BIDI_SUPPORT_FULL} BidiSupportType;
223
224 virtual BidiSupportType theOSHasBidiSupport() const {return BIDI_SUPPORT_NONE;}
225 void setEnableSmoothScrolling(bool b);
226 bool isSmoothScrollingEnabled(void) { return m_bEnableSmoothScrolling; }
227
228 void setBonoboRunning(void) { m_bBonoboRunning = true; }
229 bool isBonoboRunning(void) const { return m_bBonoboRunning; }
230 virtual void getDefaultGeometry(UT_uint32& /*width*/,
231 UT_uint32& /*height*/,
232 UT_uint32& /*flags*/) {}
233
234 const UT_LangRecord * getKbdLanguage() const { return m_pKbdLang; }
235 void setKbdLanguage(const char * pszLang);
236
237 UT_UUIDGenerator * getUUIDGenerator() const { return m_pUUIDGenerator; }
238 std::string createUUIDString() const;
239
240 bool openURL(const char * url) { return m_pImpl->openURL(url); }
241 bool openHelpURL(const char * url) { return m_pImpl->openHelpURL(url); }
242 UT_String localizeHelpUrl(const char * pathBeforeLang,
243 const char * pathAfterLang, const char * remoteURLbase)
244 { return m_pImpl->localizeHelpUrl(pathBeforeLang, pathAfterLang, remoteURLbase); }
245
246 GR_GraphicsFactory * getGraphicsFactory() const { return m_pGraphicsFactory; }
247 void setDefaultGraphicsId(UT_uint32 i);
248 /* primary graphics allocator */
249 GR_Graphics * newGraphics(GR_AllocInfo &ai) const;
250 /* secondary graphics allocator; use only in special cases */
251 GR_Graphics * newGraphics(UT_uint32 iClassId, GR_AllocInfo &ai) const;
252 virtual GR_Graphics * newDefaultScreenGraphics() const = 0;
253
254 virtual UT_sint32 setInputMode(const char * szName, bool bForce=false);
255 const char * getInputMode() const;
256 EV_EditEventMapper * getEditEventMapper() const;
257 bool addListener(AV_Listener * pListener, AV_ListenerId * pListenerId);
258 bool removeListener(AV_ListenerId listenerId);
259 virtual bool notifyListeners(AV_View * pView, const AV_ChangeMask hint,void * pPrivateData = NULL);
260
261 bool registerEmbeddable(GR_EmbedManager * pEmbed, const char *uid = NULL);
262 bool unRegisterEmbeddable(const char *uid);
263 GR_EmbedManager * getEmbeddableManager(GR_Graphics * pG, const char * szObjectType);
264 XAP_Module * getPlugin(const char * szPluginName);
265
266 static const char* findNearestFont(const char* pszFontFamily,
267 const char* pszFontStyle,
268 const char* pszFontVariant,
269 const char* pszFontWeight,
270 const char* pszFontStretch,
271 const char* pszFontSize,
272 const char* pszLang);
273
274 bool saveState(bool bQuit);
275 bool retrieveState();
276 virtual void clearStateInfo(){};
277
278 bool getDisableDoubleBuffering() const;
279 void setDisableDoubleBuffering( bool v );
280 bool getNoGUI() const;
281 void setNoGUI( bool v );
282
283 protected:
284 void _setAbiSuiteLibDir(const char * sz);
285 virtual const char * _getKbdLanguage() {return NULL;}
286 void _setUUIDGenerator(UT_UUIDGenerator * pG) { m_pUUIDGenerator = pG; }
287
288 virtual bool _saveState(XAP_StateData & sd);
289 virtual bool _retrieveState(XAP_StateData & sd);
290
291 const char * m_szAppName;
292 const char * m_szAbiSuiteLibDir;
293
294 EV_EditMethodContainer * m_pEMC; /* the set of all possible EditMethods in the app */
295 XAP_BindingSet * m_pBindingSet; /* the set of binding maps */
296 EV_Menu_ActionSet * m_pMenuActionSet; /* the set of all possible menu actions in the app */
297 EV_Toolbar_ActionSet * m_pToolbarActionSet;
298 XAP_Dictionary * m_pDict;
299 XAP_Prefs * m_prefs; /* populated in AP_<platform>App::initialize() */
300
301 UT_GenericVector<XAP_Frame*> m_vecFrames;
302 typedef std::map<std::string, UT_GenericVector<XAP_Frame*>*> CloneMap;
303 CloneMap m_hashClones;
304 XAP_Frame * m_lastFocussedFrame;
305 XAP_Menu_Factory * m_pMenuFactory;
306 XAP_Toolbar_Factory * m_pToolbarFactory;
307
308 struct modeless_pair
309 {
310 UT_sint32 id;
311 XAP_Dialog_Modeless * pDialog;
312 } m_IdTable[NUM_MODELESSID+1];
313
314 static XAP_App * m_pApp;
315 bool m_bAllowCustomizing;
316 bool m_bAreCustomized;
317 bool m_bDebugBool;
318 bool m_bBonoboRunning;
319 bool m_bEnableSmoothScrolling;
320 bool m_bDisableDoubleBuffering;
321 bool m_bNoGUI;
322 private:
323 const UT_LangRecord * m_pKbdLang;
324 UT_UUIDGenerator * m_pUUIDGenerator;
325
326 GR_GraphicsFactory * m_pGraphicsFactory;
327 UT_uint32 m_iDefaultGraphicsId;
328
329 XAP_InputModes * m_pInputModes;
330 std::map<std::string, GR_EmbedManager *> m_mapEmbedManagers;
331 XAP_App(const XAP_App&); // should not even be called. Just to avoid a warning.
332 void operator=(const XAP_App&);
333 #ifdef DEBUG
334 void _fundamentalAsserts() const;
335 #endif
336 XAP_AppImpl* m_pImpl;
337 UT_GenericVector<AV_Listener *> m_vecPluginListeners;
338 UT_ScriptLibrary * m_pScriptLibrary;
339 };
340
341 #endif /* XAP_APP_H */