| 1 |
/* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */ |
| 2 |
/* AbiSource Application Framework |
| 3 |
* Copyright (C) 1998, 1999 AbiSource, Inc. |
| 4 |
* Copyright (C) 2004 Hubert Figuiere |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU General Public License |
| 8 |
* as published by the Free Software Foundation; either version 2 |
| 9 |
* of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 19 |
* 02110-1301 USA. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include <stdio.h> |
| 23 |
#include <stdlib.h> |
| 24 |
#include <signal.h> |
| 25 |
#include <string.h> |
| 26 |
#include <time.h> |
| 27 |
#include <memory> |
| 28 |
|
| 29 |
#include <glib.h> |
| 30 |
#include <gsf/gsf-utils.h> |
| 31 |
|
| 32 |
#include "ut_types.h" |
| 33 |
#include "ut_assert.h" |
| 34 |
#include "ut_path.h" |
| 35 |
#include "ut_string.h" |
| 36 |
#include "ut_debugmsg.h" |
| 37 |
#include "ut_Language.h" |
| 38 |
#include "ut_uuid.h" |
| 39 |
#include "ev_EditMethod.h" |
| 40 |
#include "ev_Menu_Actions.h" |
| 41 |
#include "ev_Toolbar_Actions.h" |
| 42 |
#include "xap_App.h" |
| 43 |
#include "xap_AppImpl.h" |
| 44 |
#include "xap_InputModes.h" |
| 45 |
#include "gr_Image.h" |
| 46 |
#include "xap_Frame.h" |
| 47 |
#include "xap_EditMethods.h" |
| 48 |
#include "xap_ModuleManager.h" |
| 49 |
#include "xap_Module.h" |
| 50 |
|
| 51 |
#include "xap_Menu_ActionSet.h" |
| 52 |
#include "xap_Toolbar_ActionSet.h" |
| 53 |
#include "xap_LoadBindings.h" |
| 54 |
#include "xap_Dictionary.h" |
| 55 |
#include "xap_Prefs.h" |
| 56 |
#include "xap_EncodingManager.h" |
| 57 |
#include "xap_Menu_Layouts.h" |
| 58 |
#include "xap_Toolbar_Layouts.h" |
| 59 |
#include "xav_View.h" |
| 60 |
#include "xad_Document.h" |
| 61 |
#include "ut_rand.h" |
| 62 |
#include "gr_CharWidthsCache.h" |
| 63 |
#include "xav_Listener.h" |
| 64 |
#include "gr_EmbedManager.h" |
| 65 |
#include "ut_Script.h" |
| 66 |
|
| 67 |
|
| 68 |
/*****************************************************************/ |
| 69 |
|
| 70 |
XAP_StateData::XAP_StateData() |
| 71 |
: iFileCount(0) |
| 72 |
{ |
| 73 |
memset(&filenames, 0, sizeof(filenames)); |
| 74 |
memset(&iDocPos, 0, sizeof(iDocPos)); |
| 75 |
memset(&iXScroll, 0, sizeof(iXScroll)); |
| 76 |
memset(&iYScroll, 0, sizeof(iYScroll)); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
XAP_App * XAP_App::m_pApp = NULL; |
| 81 |
|
| 82 |
XAP_App * XAP_App::getApp() {return m_pApp;} |
| 83 |
|
| 84 |
XAP_App::XAP_App(const char * szAppName) |
| 85 |
: m_szAppName(szAppName), |
| 86 |
m_szAbiSuiteLibDir(NULL), |
| 87 |
m_pEMC(NULL), |
| 88 |
m_pBindingSet(NULL), |
| 89 |
m_pMenuActionSet(NULL), |
| 90 |
m_pToolbarActionSet(NULL), |
| 91 |
m_pDict(NULL), |
| 92 |
m_prefs(NULL), |
| 93 |
m_lastFocussedFrame(NULL), |
| 94 |
m_pMenuFactory(NULL), |
| 95 |
m_pToolbarFactory(NULL), |
| 96 |
m_bAllowCustomizing(true), |
| 97 |
m_bAreCustomized(true), |
| 98 |
m_bDebugBool(false), |
| 99 |
m_bBonoboRunning(false), |
| 100 |
m_bEnableSmoothScrolling(true), |
| 101 |
m_bDisableDoubleBuffering(false), |
| 102 |
m_bNoGUI(false), |
| 103 |
m_pKbdLang(NULL), // must not be deleted by destructor !!! |
| 104 |
m_pUUIDGenerator(NULL), |
| 105 |
m_pGraphicsFactory(NULL), |
| 106 |
m_iDefaultGraphicsId(0), |
| 107 |
m_pInputModes(NULL), |
| 108 |
m_pImpl(NULL), |
| 109 |
m_pScriptLibrary(NULL) |
| 110 |
{ |
| 111 |
#ifdef DEBUG |
| 112 |
_fundamentalAsserts(); // see the comments in the function itself |
| 113 |
UT_DEBUGMSG(("ZZZZZZZZZZZZZZZZZZZZZZZaaaaaaaaaaaaaaAbiSuite Home |%s|\n",XAP_App::s_szAbiSuite_Home )); |
| 114 |
|
| 115 |
#endif |
| 116 |
|
| 117 |
m_pGraphicsFactory = new GR_GraphicsFactory; |
| 118 |
UT_ASSERT( m_pGraphicsFactory ); |
| 119 |
|
| 120 |
m_pImpl = XAP_AppImpl::static_constructor(); |
| 121 |
|
| 122 |
UT_ASSERT(szAppName && *szAppName); |
| 123 |
m_pApp = this; |
| 124 |
|
| 125 |
// TODO don't build GUI when only doing commandline |
| 126 |
// file conversion |
| 127 |
UT_DEBUGMSG(("SEVIOR: Building menus and toolbars \n")); |
| 128 |
m_pMenuFactory = new XAP_Menu_Factory(this); |
| 129 |
m_pToolbarFactory = new XAP_Toolbar_Factory(this); |
| 130 |
clearIdTable(); |
| 131 |
m_vecPluginListeners.clear(); // Just to be safe |
| 132 |
} |
| 133 |
|
| 134 |
XAP_App::~XAP_App() |
| 135 |
{ |
| 136 |
// HACK: for now, this works from XAP code |
| 137 |
// TODO: where should this really go? |
| 138 |
if (m_pDict) |
| 139 |
m_pDict->save(); |
| 140 |
|
| 141 |
// run thru and destroy all frames on our window list. |
| 142 |
UT_VECTOR_PURGEALL(XAP_Frame *, m_vecFrames); |
| 143 |
// when can have NULL pointers.... |
| 144 |
|
| 145 |
FREEP(m_szAbiSuiteLibDir); |
| 146 |
DELETEP(m_pEMC); |
| 147 |
DELETEP(m_pBindingSet); |
| 148 |
DELETEP(m_pMenuActionSet); |
| 149 |
DELETEP(m_pToolbarActionSet); |
| 150 |
DELETEP(m_pDict); |
| 151 |
DELETEP(m_prefs); |
| 152 |
DELETEP(m_pMenuFactory); |
| 153 |
DELETEP(m_pToolbarFactory); |
| 154 |
|
| 155 |
// Delete the instance of the Encoding Manager. |
| 156 |
XAP_EncodingManager::get_instance()->Delete_instance(); |
| 157 |
|
| 158 |
GR_CharWidthsCache::destroyCharWidthsCache(); |
| 159 |
|
| 160 |
DELETEP(m_pUUIDGenerator); |
| 161 |
DELETEP(m_pGraphicsFactory); |
| 162 |
DELETEP(m_pInputModes); |
| 163 |
DELETEP(m_pImpl); |
| 164 |
DELETEP(m_pScriptLibrary); |
| 165 |
|
| 166 |
/* reset the static pointer, since it is no longer valid */ |
| 167 |
m_pApp = NULL; |
| 168 |
} |
| 169 |
|
| 170 |
const char* XAP_App::getBuildId () |
| 171 |
{ |
| 172 |
return s_szBuild_ID; |
| 173 |
} |
| 174 |
|
| 175 |
const char* XAP_App::getBuildVersion () |
| 176 |
{ |
| 177 |
return s_szBuild_Version; |
| 178 |
} |
| 179 |
|
| 180 |
const char* XAP_App::getBuildOptions () |
| 181 |
{ |
| 182 |
return s_szBuild_Options; |
| 183 |
} |
| 184 |
|
| 185 |
const char* XAP_App::getBuildTarget () |
| 186 |
{ |
| 187 |
return s_szBuild_Target; |
| 188 |
} |
| 189 |
|
| 190 |
const char* XAP_App::getBuildCompileTime () |
| 191 |
{ |
| 192 |
return s_szBuild_CompileTime; |
| 193 |
} |
| 194 |
|
| 195 |
const char* XAP_App::getBuildCompileDate () |
| 196 |
{ |
| 197 |
return s_szBuild_CompileDate; |
| 198 |
} |
| 199 |
|
| 200 |
const char* XAP_App::getAbiSuiteHome () |
| 201 |
{ |
| 202 |
return s_szAbiSuite_Home; |
| 203 |
} |
| 204 |
|
| 205 |
/*! this function is silly */ |
| 206 |
const XAP_EncodingManager* XAP_App::getEncodingManager() const |
| 207 |
{ |
| 208 |
return XAP_EncodingManager::get_instance(); |
| 209 |
} |
| 210 |
|
| 211 |
EV_Menu_ActionSet *XAP_App::getMenuActionSet() |
| 212 |
{ |
| 213 |
return m_pMenuActionSet; |
| 214 |
} |
| 215 |
|
| 216 |
EV_Toolbar_ActionSet *XAP_App::getToolbarActionSet() |
| 217 |
{ |
| 218 |
return m_pToolbarActionSet; |
| 219 |
} |
| 220 |
|
| 221 |
/*! |
| 222 |
* Returns a pointer to the requested plugin if it is loaded. |
| 223 |
* Return NULL otherwise. |
| 224 |
*/ |
| 225 |
XAP_Module * XAP_App::getPlugin(const char * szPluginName) |
| 226 |
{ |
| 227 |
XAP_Module * pModule = NULL; |
| 228 |
const UT_GenericVector<XAP_Module*> * pVec = XAP_ModuleManager::instance().enumModules (); |
| 229 |
bool bFound = false; |
| 230 |
for (UT_sint32 i = 0; (i < pVec->size()) && !bFound; i++) |
| 231 |
{ |
| 232 |
pModule = pVec->getNthItem (i); |
| 233 |
const char * szName = pModule->getModuleInfo()->name; |
| 234 |
if(g_ascii_strcasecmp(szName,szPluginName) == 0) |
| 235 |
{ |
| 236 |
bFound = true; |
| 237 |
} |
| 238 |
} |
| 239 |
if(!bFound) |
| 240 |
{ |
| 241 |
return NULL; |
| 242 |
} |
| 243 |
return pModule; |
| 244 |
} |
| 245 |
|
| 246 |
/*! |
| 247 |
* Register an embeddable plugin with XAP_App |
| 248 |
*/ |
| 249 |
bool XAP_App::registerEmbeddable(GR_EmbedManager * pEmbed, const char *uid) |
| 250 |
{ |
| 251 |
UT_return_val_if_fail( pEmbed, false ); |
| 252 |
|
| 253 |
if (uid == NULL) |
| 254 |
uid = pEmbed->getObjectType(); |
| 255 |
if (uid && *uid && m_mapEmbedManagers.find(uid) == m_mapEmbedManagers.end()) |
| 256 |
{ |
| 257 |
m_mapEmbedManagers[uid] = pEmbed; |
| 258 |
return true; |
| 259 |
} |
| 260 |
return false; |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
/*! |
| 265 |
* UnRegister an embeddable plugin with XAP_App. The plugin itself is |
| 266 |
* responsible for actually deleting the object. |
| 267 |
*/ |
| 268 |
bool XAP_App::unRegisterEmbeddable(const char *uid) |
| 269 |
{ |
| 270 |
if (uid == NULL || *uid == 0) |
| 271 |
return false; |
| 272 |
std::map<std::string, GR_EmbedManager *>::iterator i = m_mapEmbedManagers.find(uid); |
| 273 |
if(i != m_mapEmbedManagers.end()) |
| 274 |
{ |
| 275 |
m_mapEmbedManagers.erase(i); |
| 276 |
return true; |
| 277 |
} |
| 278 |
return false; |
| 279 |
} |
| 280 |
|
| 281 |
/*! |
| 282 |
* Return a copy of the requested embedable plugin or a default manager. |
| 283 |
* The calling routine must delete this. |
| 284 |
*/ |
| 285 |
GR_EmbedManager * XAP_App:: getEmbeddableManager(GR_Graphics * pG, const char * szObjectType) |
| 286 |
{ |
| 287 |
GR_EmbedManager * pCur = NULL; |
| 288 |
if (szObjectType && szObjectType != 0) |
| 289 |
pCur = m_mapEmbedManagers[szObjectType]; |
| 290 |
if(pCur != NULL) |
| 291 |
{ |
| 292 |
UT_DEBUGMSG(("Found a plugin of type %s \n",pCur->getObjectType())); |
| 293 |
return pCur->create(pG); |
| 294 |
} |
| 295 |
return new GR_EmbedManager(pG); |
| 296 |
} |
| 297 |
|
| 298 |
bool XAP_App::initialize(const char * szKeyBindingsKey, const char * szKeyBindingsDefaultValue) |
| 299 |
{ |
| 300 |
gsf_init(); |
| 301 |
|
| 302 |
// create application-wide resources that |
| 303 |
// are shared by everything. |
| 304 |
|
| 305 |
// init keyboard language (cannot be in the constructor as it |
| 306 |
// requires the platform code already initialised |
| 307 |
setKbdLanguage(_getKbdLanguage()); |
| 308 |
|
| 309 |
// HACK: for now, this works from XAP code |
| 310 |
// TODO: where should this really go? |
| 311 |
char * szPathname = g_build_filename(getUserPrivateDirectory(), "custom.dic", NULL); |
| 312 |
UT_ASSERT(szPathname); |
| 313 |
m_pDict = new XAP_Dictionary(szPathname); |
| 314 |
FREEP(szPathname); |
| 315 |
UT_return_val_if_fail(m_pDict,false); |
| 316 |
m_pDict->load(); |
| 317 |
clearIdTable(); |
| 318 |
// |
| 319 |
// Set Smooth Scrolling |
| 320 |
// |
| 321 |
bool bEnableSmooth = true; |
| 322 |
getPrefsValueBool(XAP_PREF_KEY_EnableSmoothScrolling, &bEnableSmooth); |
| 323 |
if(bEnableSmooth) |
| 324 |
setEnableSmoothScrolling(true); |
| 325 |
else |
| 326 |
setEnableSmoothScrolling(false); |
| 327 |
|
| 328 |
// |
| 329 |
// Need to initialize the random number generator. |
| 330 |
// |
| 331 |
UT_uint32 t = static_cast<UT_uint32>(time(NULL)); |
| 332 |
UT_srandom(t); |
| 333 |
|
| 334 |
// Input mode initilization, taken out of the XAP_Frame |
| 335 |
const char * szBindings = NULL; |
| 336 |
EV_EditBindingMap * pBindingMap = NULL; |
| 337 |
|
| 338 |
if ((getPrefsValue(szKeyBindingsKey, |
| 339 |
static_cast<const gchar**>(&szBindings))) && |
| 340 |
(szBindings) && (*szBindings)) |
| 341 |
pBindingMap = m_pApp->getBindingMap(szBindings); |
| 342 |
if (!pBindingMap) |
| 343 |
pBindingMap = m_pApp->getBindingMap(szKeyBindingsDefaultValue); |
| 344 |
UT_ASSERT(pBindingMap); |
| 345 |
|
| 346 |
if (!m_pInputModes) |
| 347 |
{ |
| 348 |
m_pInputModes = new XAP_InputModes(); |
| 349 |
UT_ASSERT(m_pInputModes); |
| 350 |
} |
| 351 |
bool bResult; |
| 352 |
bResult = m_pInputModes->createInputMode(szBindings,pBindingMap); |
| 353 |
UT_ASSERT(bResult); |
| 354 |
bResult = m_pInputModes->setCurrentMap(szBindings); |
| 355 |
UT_ASSERT(bResult); |
| 356 |
UT_UNUSED(bResult); // TODO deal with the error |
| 357 |
|
| 358 |
// check if the prefs are set to use specific graphics class |
| 359 |
const char * pszGraphics = NULL; |
| 360 |
if(getPrefsValue(XAP_PREF_KEY_DefaultGraphics, &pszGraphics)) |
| 361 |
{ |
| 362 |
UT_uint32 iID = 0; |
| 363 |
|
| 364 |
// please leave this in hex format (the constants are defined in gr_Graphics.h as hex) |
| 365 |
sscanf(pszGraphics,"%x", &iID); |
| 366 |
if(iID != 0) |
| 367 |
{ |
| 368 |
UT_DEBUGMSG(("Graphics %d requested as default\n", iID)); |
| 369 |
|
| 370 |
// first of all, check that it is registered |
| 371 |
GR_GraphicsFactory * pGF = getGraphicsFactory(); |
| 372 |
UT_return_val_if_fail(pGF,false); |
| 373 |
|
| 374 |
if(pGF->isRegistered(iID)) |
| 375 |
{ |
| 376 |
pGF->registerAsDefault(iID, true); |
| 377 |
pGF->registerAsDefault(iID, false); |
| 378 |
} |
| 379 |
else |
| 380 |
{ |
| 381 |
UT_DEBUGMSG(("Graphics not loaded\n")); |
| 382 |
} |
| 383 |
} |
| 384 |
} |
| 385 |
m_pScriptLibrary = new UT_ScriptLibrary(); |
| 386 |
return true; |
| 387 |
} |
| 388 |
|
| 389 |
/*! |
| 390 |
* Plugins can register themselves here if they want to receive |
| 391 |
* notifications of document changes. |
| 392 |
*/ |
| 393 |
bool XAP_App::addListener(AV_Listener * pListener, |
| 394 |
AV_ListenerId * pListenerId) |
| 395 |
{ |
| 396 |
UT_sint32 kLimit = m_vecPluginListeners.getItemCount(); |
| 397 |
UT_sint32 k; |
| 398 |
|
| 399 |
// see if we can recycle a cell in the vector. |
| 400 |
UT_DEBUGMSG(("Asked to register pListener %p \n",pListener)); |
| 401 |
|
| 402 |
for (k=0; k<kLimit; k++) |
| 403 |
if (m_vecPluginListeners.getNthItem(k) == 0) |
| 404 |
{ |
| 405 |
static_cast<void>(m_vecPluginListeners.setNthItem(k,pListener,NULL)); |
| 406 |
goto ClaimThisK; |
| 407 |
} |
| 408 |
|
| 409 |
// otherwise, extend the vector for it. |
| 410 |
|
| 411 |
if (m_vecPluginListeners.addItem(pListener,&k) != 0) |
| 412 |
{ |
| 413 |
UT_DEBUGMSG(("Failed! id %d \n",k)); |
| 414 |
return false; // could not add item to vector |
| 415 |
} |
| 416 |
|
| 417 |
ClaimThisK: |
| 418 |
|
| 419 |
// give our vector index back to the caller as a "Listener Id". |
| 420 |
|
| 421 |
*pListenerId = k; |
| 422 |
return true; |
| 423 |
} |
| 424 |
|
| 425 |
|
| 426 |
/*! |
| 427 |
* Plugins must remove themselves if they've registered. |
| 428 |
*/ |
| 429 |
bool XAP_App::removeListener(AV_ListenerId listenerId) |
| 430 |
{ |
| 431 |
if (listenerId == (AV_ListenerId) -1) |
| 432 |
return false; |
| 433 |
|
| 434 |
if (m_vecPluginListeners.getNthItem(listenerId)) { |
| 435 |
m_vecPluginListeners.deleteNthItem(listenerId); |
| 436 |
return true; |
| 437 |
} |
| 438 |
return false; |
| 439 |
} |
| 440 |
|
| 441 |
/*! |
| 442 |
* Send notifications to all the registered plugins |
| 443 |
*/ |
| 444 |
bool XAP_App::notifyListeners(AV_View * pView, const AV_ChangeMask hint, void * pPrivateData) |
| 445 |
{ |
| 446 |
/* |
| 447 |
App-specific logic calls this virtual method when relevant portions of |
| 448 |
the view state *may* have changed. (That's why it's called a hint.) |
| 449 |
|
| 450 |
This base class implementation doesn't do any filtering of those |
| 451 |
hints, it just broadcasts those hints to all listeners. |
| 452 |
|
| 453 |
Subclasses are encouraged to improve the quality of those hints by |
| 454 |
filtering out mask bits which haven't *actually* changed since the |
| 455 |
last notification. To do so, they would |
| 456 |
|
| 457 |
- copy the hint (it's passed as a const), |
| 458 |
- clear any irrelevant bits, and |
| 459 |
- call this implementation on the way out |
| 460 |
|
| 461 |
Good hinting logic is app-specific, and non-trivial to tune, but it's |
| 462 |
worth doing, because it helps minimizes flicker for things like |
| 463 |
toolbar button state. |
| 464 |
*/ |
| 465 |
|
| 466 |
// make sure there's something left |
| 467 |
|
| 468 |
if (hint == AV_CHG_NONE) |
| 469 |
{ |
| 470 |
return false; |
| 471 |
} |
| 472 |
|
| 473 |
// notify listeners of a change. |
| 474 |
|
| 475 |
AV_ListenerId lid; |
| 476 |
AV_ListenerId lidCount = m_vecPluginListeners.getItemCount(); |
| 477 |
|
| 478 |
// for each listener in our vector, we send a notification. |
| 479 |
// we step over null listners (for listeners which have been |
| 480 |
// removed (views that went away)). |
| 481 |
|
| 482 |
for (lid=0; lid<lidCount; lid++) |
| 483 |
{ |
| 484 |
AV_Listener * pListener = static_cast<AV_Listener *>(m_vecPluginListeners.getNthItem(lid)); |
| 485 |
if(pListener->getType()!= AV_LISTENER_PLUGIN_EXTRA ) |
| 486 |
{ |
| 487 |
pListener->notify(pView,hint); |
| 488 |
} |
| 489 |
else |
| 490 |
{ |
| 491 |
AV_ListenerExtra * pExtra = static_cast<AV_ListenerExtra *>(pListener); |
| 492 |
pExtra->notify(pView,hint,pPrivateData); |
| 493 |
} |
| 494 |
} |
| 495 |
|
| 496 |
return true; |
| 497 |
} |
| 498 |
|
| 499 |
|
| 500 |
void XAP_App::setEnableSmoothScrolling(bool b) |
| 501 |
{ |
| 502 |
m_bEnableSmoothScrolling = b; |
| 503 |
} |
| 504 |
|
| 505 |
const char * XAP_App::getApplicationTitleForTitleBar() const |
| 506 |
{ |
| 507 |
static char _title[512]; |
| 508 |
|
| 509 |
// return a string that the platform-specific code |
| 510 |
// can copy to the title bar of a window. |
| 511 |
|
| 512 |
//sprintf(_title, "%s (www.abisource.com)", m_szAppName); |
| 513 |
sprintf(_title, "%s", m_szAppName); |
| 514 |
|
| 515 |
return _title; |
| 516 |
} |
| 517 |
|
| 518 |
const char * XAP_App::getApplicationName() const |
| 519 |
{ |
| 520 |
// return a string that the platform-specific code |
| 521 |
// can use as a class name for various window-manager-like |
| 522 |
// operations. |
| 523 |
return m_szAppName; |
| 524 |
} |
| 525 |
|
| 526 |
void XAP_App::rebuildMenus(void) |
| 527 |
{ |
| 528 |
UT_uint32 frameCount = getFrameCount(); |
| 529 |
|
| 530 |
for (UT_uint32 i = 0; i < frameCount; i++) |
| 531 |
if (XAP_Frame * pFrame = getFrame(i)) |
| 532 |
{ |
| 533 |
pFrame->rebuildMenus(); |
| 534 |
} |
| 535 |
} |
| 536 |
|
| 537 |
EV_EditMethodContainer * XAP_App::getEditMethodContainer() const |
| 538 |
{ |
| 539 |
return m_pEMC; |
| 540 |
} |
| 541 |
|
| 542 |
EV_EditBindingMap * XAP_App::getBindingMap(const char * szName) |
| 543 |
{ |
| 544 |
UT_return_val_if_fail(m_pBindingSet,NULL); |
| 545 |
return m_pBindingSet->getMap(szName); |
| 546 |
} |
| 547 |
|
| 548 |
const EV_Menu_ActionSet * XAP_App::getMenuActionSet() const |
| 549 |
{ |
| 550 |
return m_pMenuActionSet; |
| 551 |
} |
| 552 |
|
| 553 |
const EV_Toolbar_ActionSet * XAP_App::getToolbarActionSet() const |
| 554 |
{ |
| 555 |
return m_pToolbarActionSet; |
| 556 |
} |
| 557 |
|
| 558 |
bool XAP_App::rememberFrame(XAP_Frame * pFrame, XAP_Frame * pCloneOf) |
| 559 |
{ |
| 560 |
UT_ASSERT(pFrame); |
| 561 |
|
| 562 |
// add this frame to our window list |
| 563 |
m_vecFrames.addItem(pFrame); |
| 564 |
|
| 565 |
if(! m_lastFocussedFrame) |
| 566 |
rememberFocussedFrame(pFrame); |
| 567 |
|
| 568 |
// TODO: error-check the following for mem failures |
| 569 |
if (pCloneOf) |
| 570 |
{ |
| 571 |
// locate vector of this frame's clones |
| 572 |
CloneMap::const_iterator iter = m_hashClones.find(pCloneOf->getViewKey()); |
| 573 |
|
| 574 |
UT_GenericVector<XAP_Frame*> * pvClones = NULL; |
| 575 |
|
| 576 |
if (iter != m_hashClones.end()) |
| 577 |
{ |
| 578 |
UT_GenericVector<XAP_Frame*> * pEntry = iter->second; |
| 579 |
|
| 580 |
// hash table entry already exists |
| 581 |
pvClones = pEntry; |
| 582 |
|
| 583 |
if (!pvClones) |
| 584 |
{ |
| 585 |
// nothing there, so create a new one |
| 586 |
pvClones = new UT_GenericVector<XAP_Frame*>(); |
| 587 |
UT_return_val_if_fail(pvClones,false); |
| 588 |
|
| 589 |
pvClones->addItem(pCloneOf); |
| 590 |
|
| 591 |
// reuse this slot |
| 592 |
m_hashClones[pCloneOf->getViewKey()] = pvClones; |
| 593 |
} |
| 594 |
} |
| 595 |
else |
| 596 |
{ |
| 597 |
// create a new one |
| 598 |
pvClones = new UT_GenericVector<XAP_Frame*>(); |
| 599 |
UT_return_val_if_fail(pvClones,false); |
| 600 |
|
| 601 |
pvClones->addItem(pCloneOf); |
| 602 |
|
| 603 |
// add it to the hash table |
| 604 |
m_hashClones.insert(std::make_pair(pCloneOf->getViewKey(), pvClones)); |
| 605 |
} |
| 606 |
|
| 607 |
pvClones->addItem(pFrame); |
| 608 |
|
| 609 |
// notify all clones of their new view numbers |
| 610 |
for (UT_sint32 j=0; j<pvClones->getItemCount(); j++) |
| 611 |
{ |
| 612 |
XAP_Frame * f = pvClones->getNthItem(j); |
| 613 |
UT_continue_if_fail(f); |
| 614 |
|
| 615 |
f->setViewNumber(j+1); |
| 616 |
|
| 617 |
if (f != pFrame) |
| 618 |
f->updateTitle(); |
| 619 |
} |
| 620 |
} |
| 621 |
|
| 622 |
// TODO do something here... |
| 623 |
notifyFrameCountChange(); |
| 624 |
return true; |
| 625 |
} |
| 626 |
|
| 627 |
bool XAP_App::forgetFrame(XAP_Frame * pFrame) |
| 628 |
{ |
| 629 |
UT_return_val_if_fail(pFrame,false); |
| 630 |
|
| 631 |
// If this frame is the currently focussed frame write in NULL |
| 632 |
// until another frame appears |
| 633 |
|
| 634 |
if(pFrame == m_lastFocussedFrame ) |
| 635 |
{ |
| 636 |
m_lastFocussedFrame = static_cast<XAP_Frame *>(NULL); |
| 637 |
} |
| 638 |
|
| 639 |
if (pFrame->getViewNumber() > 0) |
| 640 |
{ |
| 641 |
// locate vector of this frame's clones |
| 642 |
CloneMap::const_iterator iter = m_hashClones.find(pFrame->getViewKey()); |
| 643 |
UT_ASSERT(iter != m_hashClones.end()); |
| 644 |
|
| 645 |
if (iter != m_hashClones.end()) |
| 646 |
{ |
| 647 |
UT_GenericVector<XAP_Frame*> * pvClones = iter->second; |
| 648 |
UT_return_val_if_fail(pvClones,false); |
| 649 |
|
| 650 |
// remove this frame from the vector |
| 651 |
UT_sint32 i = pvClones->findItem(pFrame); |
| 652 |
UT_ASSERT(i >= 0); |
| 653 |
|
| 654 |
if (i >= 0) |
| 655 |
{ |
| 656 |
pvClones->deleteNthItem(i); |
| 657 |
} |
| 658 |
|
| 659 |
// see how many clones are left |
| 660 |
UT_uint32 count = pvClones->getItemCount(); |
| 661 |
UT_ASSERT(count > 0); |
| 662 |
XAP_Frame * f = NULL; |
| 663 |
|
| 664 |
if (count == 1) |
| 665 |
{ |
| 666 |
// remaining clone is now a singleton |
| 667 |
f = pvClones->getNthItem(count-1); |
| 668 |
UT_return_val_if_fail(f,false); |
| 669 |
|
| 670 |
f->setViewNumber(0); |
| 671 |
f->updateTitle(); |
| 672 |
|
| 673 |
// remove this entry from hashtable |
| 674 |
m_hashClones.erase(f->getViewKey()); |
| 675 |
delete pvClones; |
| 676 |
} |
| 677 |
else |
| 678 |
{ |
| 679 |
// notify remaining clones of their new view numbers |
| 680 |
for (UT_uint32 j=0; j<count; j++) |
| 681 |
{ |
| 682 |
f = static_cast<XAP_Frame *>(pvClones->getNthItem(j)); |
| 683 |
UT_continue_if_fail(f); |
| 684 |
|
| 685 |
f->setViewNumber(j+1); |
| 686 |
f->updateTitle(); |
| 687 |
} |
| 688 |
} |
| 689 |
} |
| 690 |
} |
| 691 |
|
| 692 |
// remove this frame from our window list |
| 693 |
UT_sint32 ndx = m_vecFrames.findItem(pFrame); |
| 694 |
UT_ASSERT_HARMLESS(ndx >= 0); |
| 695 |
|
| 696 |
if (ndx >= 0) |
| 697 |
{ |
| 698 |
m_vecFrames.deleteNthItem(ndx); |
| 699 |
notifyFrameCountChange(); |
| 700 |
} |
| 701 |
|
| 702 |
notifyModelessDlgsCloseFrame(pFrame); |
| 703 |
|
| 704 |
// TODO do something here... |
| 705 |
|
| 706 |
return true; |
| 707 |
} |
| 708 |
|
| 709 |
bool XAP_App::forgetClones(XAP_Frame * pFrame) |
| 710 |
{ |
| 711 |
UT_return_val_if_fail(pFrame,false); |
| 712 |
|
| 713 |
if (pFrame->getViewNumber() == 0) |
| 714 |
{ |
| 715 |
return forgetFrame(pFrame); |
| 716 |
} |
| 717 |
|
| 718 |
UT_GenericVector<XAP_Frame*> vClones; |
| 719 |
getClones(&vClones, pFrame); |
| 720 |
|
| 721 |
for (UT_sint32 i = 0; i < vClones.getItemCount(); i++) |
| 722 |
{ |
| 723 |
XAP_Frame * f = static_cast<XAP_Frame *>(vClones.getNthItem(i)); |
| 724 |
forgetFrame(f); |
| 725 |
} |
| 726 |
|
| 727 |
return true; |
| 728 |
} |
| 729 |
|
| 730 |
bool XAP_App::getClones(UT_GenericVector<XAP_Frame*> *pvClonesCopy, XAP_Frame * pFrame) |
| 731 |
{ |
| 732 |
UT_ASSERT(pvClonesCopy); |
| 733 |
UT_return_val_if_fail(pFrame,false); |
| 734 |
UT_ASSERT(pFrame->getViewNumber() > 0); |
| 735 |
|
| 736 |
// locate vector of this frame's clones |
| 737 |
CloneMap::const_iterator iter = m_hashClones.find(pFrame->getViewKey()); |
| 738 |
UT_GenericVector<XAP_Frame*> * pvClones = NULL; |
| 739 |
if (iter != m_hashClones.end()) { |
| 740 |
pvClones = iter->second; |
| 741 |
} |
| 742 |
UT_ASSERT(pvClones); |
| 743 |
|
| 744 |
return pvClonesCopy->copy(pvClones); |
| 745 |
} |
| 746 |
|
| 747 |
bool XAP_App::updateClones(XAP_Frame * pFrame) |
| 748 |
{ |
| 749 |
UT_return_val_if_fail(pFrame,false); |
| 750 |
UT_ASSERT(pFrame->getViewNumber() > 0); |
| 751 |
|
| 752 |
// locate vector of this frame's clones |
| 753 |
CloneMap::const_iterator iter = m_hashClones.find(pFrame->getViewKey()); |
| 754 |
UT_ASSERT(iter != m_hashClones.end()); |
| 755 |
|
| 756 |
if (iter != m_hashClones.end()) |
| 757 |
{ |
| 758 |
UT_GenericVector<XAP_Frame*>* pvClones = iter->second; |
| 759 |
UT_return_val_if_fail(pvClones,false); |
| 760 |
|
| 761 |
UT_uint32 count = pvClones->getItemCount(); |
| 762 |
UT_ASSERT(count > 0); |
| 763 |
XAP_Frame * f = NULL; |
| 764 |
|
| 765 |
for (UT_uint32 j=0; j<count; j++) |
| 766 |
{ |
| 767 |
f = pvClones->getNthItem(j); |
| 768 |
UT_continue_if_fail(f); |
| 769 |
|
| 770 |
f->updateTitle(); |
| 771 |
} |
| 772 |
} |
| 773 |
|
| 774 |
return true; |
| 775 |
} |
| 776 |
|
| 777 |
void XAP_App::notifyFrameCountChange() // default is empty method |
| 778 |
{ |
| 779 |
UT_DEBUGMSG(("XAP_App::notifyFrameCountChange(): count=%lu\n", static_cast<unsigned long>(getFrameCount()))); |
| 780 |
} |
| 781 |
|
| 782 |
UT_sint32 XAP_App::getFrameCount() const |
| 783 |
{ |
| 784 |
return m_vecFrames.getItemCount(); |
| 785 |
} |
| 786 |
|
| 787 |
XAP_Frame * XAP_App::getFrame(UT_sint32 ndx) const |
| 788 |
{ |
| 789 |
XAP_Frame * pFrame = NULL; |
| 790 |
|
| 791 |
if (ndx < m_vecFrames.getItemCount()) |
| 792 |
{ |
| 793 |
pFrame = m_vecFrames.getNthItem(ndx); |
| 794 |
UT_ASSERT(pFrame); |
| 795 |
} |
| 796 |
return pFrame; |
| 797 |
} |
| 798 |
|
| 799 |
UT_sint32 XAP_App::findFrame(XAP_Frame * pFrame) const |
| 800 |
{ |
| 801 |
return m_vecFrames.findItem(pFrame); |
| 802 |
} |
| 803 |
|
| 804 |
UT_sint32 XAP_App::findFrame(const char * szFilename) const |
| 805 |
{ |
| 806 |
if (!szFilename || !*szFilename) |
| 807 |
return -1; |
| 808 |
|
| 809 |
for (UT_sint32 i=0; i<getFrameCount(); i++) |
| 810 |
{ |
| 811 |
XAP_Frame * f = getFrame(i); |
| 812 |
UT_continue_if_fail(f); |
| 813 |
const char * s = f->getFilename(); |
| 814 |
|
| 815 |
if (s && *s && (0 == g_ascii_strcasecmp(szFilename, s))) |
| 816 |
{ |
| 817 |
return i; |
| 818 |
} |
| 819 |
} |
| 820 |
|
| 821 |
return -1; |
| 822 |
} |
| 823 |
|
| 824 |
void XAP_App::_setAbiSuiteLibDir(const char * sz) |
| 825 |
{ |
| 826 |
FREEP(m_szAbiSuiteLibDir); |
| 827 |
m_szAbiSuiteLibDir = g_strdup(sz); |
| 828 |
} |
| 829 |
|
| 830 |
// This should be removed at some time. |
| 831 |
void XAP_App::migrate (const char *oldName, const char *newName, const char *path) const |
| 832 |
{ |
| 833 |
UT_UNUSED(oldName); |
| 834 |
UT_UNUSED(newName); |
| 835 |
UT_UNUSED(path); |
| 836 |
} |
| 837 |
|
| 838 |
const char * XAP_App::getAbiSuiteLibDir() const |
| 839 |
{ |
| 840 |
return m_szAbiSuiteLibDir; |
| 841 |
} |
| 842 |
|
| 843 |
bool XAP_App::findAbiSuiteLibFile(std::string & path, const char * filename, const char * subdir) |
| 844 |
{ |
| 845 |
if (!filename) |
| 846 |
{ |
| 847 |
return false; |
| 848 |
} |
| 849 |
|
| 850 |
bool bFound = false; |
| 851 |
|
| 852 |
const char * dir[2] = { |
| 853 |
getUserPrivateDirectory(), |
| 854 |
getAbiSuiteLibDir() |
| 855 |
}; |
| 856 |
for (int i=0; !bFound && i<2; i++) |
| 857 |
{ |
| 858 |
path = dir[i]; |
| 859 |
if (subdir) |
| 860 |
{ |
| 861 |
path += G_DIR_SEPARATOR; |
| 862 |
path += subdir; |
| 863 |
} |
| 864 |
path += G_DIR_SEPARATOR; |
| 865 |
path += filename; |
| 866 |
bFound = UT_isRegularFile (path.c_str ()); |
| 867 |
} |
| 868 |
return bFound; |
| 869 |
} |
| 870 |
|
| 871 |
bool XAP_App::findAbiSuiteAppFile(std::string & path, const char * filename, const char * subdir) |
| 872 |
{ |
| 873 |
if (!filename) |
| 874 |
{ |
| 875 |
return false; |
| 876 |
} |
| 877 |
|
| 878 |
bool bFound = false; |
| 879 |
|
| 880 |
const char * dir = getAbiSuiteAppDir(); |
| 881 |
if (dir) |
| 882 |
{ |
| 883 |
path = dir; |
| 884 |
if (subdir) |
| 885 |
{ |
| 886 |
path += G_DIR_SEPARATOR; |
| 887 |
path += subdir; |
| 888 |
} |
| 889 |
path += G_DIR_SEPARATOR; |
| 890 |
path += filename; |
| 891 |
bFound = UT_isRegularFile (path.c_str ()); |
| 892 |
} |
| 893 |
return bFound; |
| 894 |
} |
| 895 |
|
| 896 |
bool XAP_App::addWordToDict(const UT_UCSChar * pWord, UT_uint32 len) |
| 897 |
{ |
| 898 |
if (!m_pDict) |
| 899 |
return false; |
| 900 |
|
| 901 |
return m_pDict->addWord(pWord, len); |
| 902 |
} |
| 903 |
|
| 904 |
bool XAP_App::isWordInDict(const UT_UCSChar * pWord, UT_uint32 len) const |
| 905 |
{ |
| 906 |
if (!m_pDict) |
| 907 |
return false; |
| 908 |
|
| 909 |
return m_pDict->isWord(pWord, len); |
| 910 |
} |
| 911 |
|
| 912 |
/*! |
| 913 |
* Look up the custom dictionary for suggested words |
| 914 |
*/ |
| 915 |
void XAP_App::suggestWord(UT_GenericVector<UT_UCSChar*> * pVecSuggestions, const UT_UCSChar * pWord, UT_uint32 lenWord) |
| 916 |
{ |
| 917 |
if(m_pDict) |
| 918 |
{ |
| 919 |
m_pDict->suggestWord(pVecSuggestions, pWord, lenWord); |
| 920 |
} |
| 921 |
} |
| 922 |
|
| 923 |
XAP_Prefs * XAP_App::getPrefs() const |
| 924 |
{ |
| 925 |
return m_prefs; |
| 926 |
} |
| 927 |
|
| 928 |
bool XAP_App::getPrefsValue(const gchar * szKey, const gchar ** pszValue) const |
| 929 |
{ |
| 930 |
if (!m_prefs) |
| 931 |
return false; |
| 932 |
|
| 933 |
return m_prefs->getPrefsValue(szKey,pszValue); |
| 934 |
} |
| 935 |
|
| 936 |
bool XAP_App::getPrefsValue(const UT_String &stKey, UT_String &stValue) const |
| 937 |
{ |
| 938 |
if (!m_prefs) |
| 939 |
return false; |
| 940 |
|
| 941 |
return m_prefs->getPrefsValue(stKey, stValue); |
| 942 |
} |
| 943 |
|
| 944 |
bool XAP_App::getPrefsValueBool(const gchar * szKey, bool * pbValue) const |
| 945 |
{ |
| 946 |
if (!m_prefs) |
| 947 |
return false; |
| 948 |
|
| 949 |
return m_prefs->getPrefsValueBool(szKey,pbValue); |
| 950 |
} |
| 951 |
|
| 952 |
void XAP_App::rememberFocussedFrame( void * pJustFocussedFrame) |
| 953 |
{ |
| 954 |
m_lastFocussedFrame = static_cast<XAP_Frame *>(pJustFocussedFrame); |
| 955 |
|
| 956 |
UT_sint32 i = safefindFrame( m_lastFocussedFrame); |
| 957 |
if(i < 0 ) |
| 958 |
{ |
| 959 |
m_lastFocussedFrame = static_cast<XAP_Frame *>(NULL); |
| 960 |
} |
| 961 |
notifyModelessDlgsOfActiveFrame(m_lastFocussedFrame); |
| 962 |
} |
| 963 |
|
| 964 |
UT_sint32 XAP_App::safefindFrame( XAP_Frame * f) const |
| 965 |
{ |
| 966 |
size_t ff = reinterpret_cast<size_t>(f); |
| 967 |
UT_sint32 num_frames = m_vecFrames.getItemCount(); |
| 968 |
UT_sint32 i; |
| 969 |
for( i = 0; i< num_frames; i++) |
| 970 |
{ |
| 971 |
size_t lf = reinterpret_cast<size_t>( m_vecFrames.getNthItem(i)); |
| 972 |
if( lf == ff) break; |
| 973 |
} |
| 974 |
if( i == num_frames ) i = -1; |
| 975 |
return i; |
| 976 |
} |
| 977 |
|
| 978 |
void XAP_App::clearLastFocussedFrame() |
| 979 |
{ |
| 980 |
m_lastFocussedFrame = static_cast<XAP_Frame *>(NULL); |
| 981 |
} |
| 982 |
|
| 983 |
XAP_Frame* XAP_App::getLastFocussedFrame() const |
| 984 |
{ |
| 985 |
if(m_lastFocussedFrame == static_cast<XAP_Frame *>(NULL)) |
| 986 |
return static_cast<XAP_Frame *>(NULL); |
| 987 |
UT_sint32 i = safefindFrame(m_lastFocussedFrame); |
| 988 |
if( i>= 0) |
| 989 |
return m_lastFocussedFrame; |
| 990 |
return static_cast<XAP_Frame *>(NULL); |
| 991 |
} |
| 992 |
|
| 993 |
XAP_Frame * XAP_App::findValidFrame() const |
| 994 |
{ |
| 995 |
XAP_Frame * validFrame = getFrame(0); |
| 996 |
return validFrame; |
| 997 |
} |
| 998 |
|
| 999 |
void XAP_App::clearIdTable() |
| 1000 |
{ |
| 1001 |
for(UT_sint32 i =0; i <= NUM_MODELESSID; i++) |
| 1002 |
{ |
| 1003 |
m_IdTable[i].id = -1; |
| 1004 |
m_IdTable[i].pDialog = static_cast<XAP_Dialog_Modeless *>(NULL); |
| 1005 |
} |
| 1006 |
} |
| 1007 |
|
| 1008 |
void XAP_App::rememberModelessId(UT_sint32 id, XAP_Dialog_Modeless * pDialog) |
| 1009 |
{ |
| 1010 |
// find a free slot in the m_IdTable |
| 1011 |
|
| 1012 |
UT_sint32 i; |
| 1013 |
for(i=0; (i<= NUM_MODELESSID) && (m_IdTable[i].id != -1); i++) { |
| 1014 |
|
| 1015 |
} |
| 1016 |
UT_ASSERT( i <= NUM_MODELESSID ); |
| 1017 |
// This assert cause a warning because array subscript is out of bounds. |
| 1018 |
// UT_ASSERT( m_IdTable[i].id == -1 ); |
| 1019 |
UT_ASSERT( pDialog); |
| 1020 |
m_IdTable[i].id = id; |
| 1021 |
m_IdTable[i].pDialog = pDialog; |
| 1022 |
} |
| 1023 |
|
| 1024 |
void XAP_App::forgetModelessId( UT_sint32 id ) |
| 1025 |
{ |
| 1026 |
// remove the id, pDialog pair from the m_IdTable |
| 1027 |
|
| 1028 |
UT_sint32 i; |
| 1029 |
for(i=0; i <= NUM_MODELESSID && m_IdTable[i].id != id; i++) { |
| 1030 |
|
| 1031 |
} |
| 1032 |
if(i > NUM_MODELESSID) |
| 1033 |
{ |
| 1034 |
// |
| 1035 |
// forgotten already |
| 1036 |
// |
| 1037 |
return; |
| 1038 |
} |
| 1039 |
m_IdTable[i].id = -1; |
| 1040 |
m_IdTable[i].pDialog = static_cast<XAP_Dialog_Modeless *>(NULL); |
| 1041 |
} |
| 1042 |
|
| 1043 |
bool XAP_App::isModelessRunning(UT_sint32 id) |
| 1044 |
{ |
| 1045 |
// returns true if the modeless dialog given by id is running |
| 1046 |
|
| 1047 |
UT_sint32 i; |
| 1048 |
for(i=0; i <= NUM_MODELESSID && m_IdTable[i].id != id; i++) { |
| 1049 |
|
| 1050 |
} |
| 1051 |
if( i> NUM_MODELESSID) |
| 1052 |
{ |
| 1053 |
return false; |
| 1054 |
} |
| 1055 |
UT_ASSERT( m_IdTable[i].id == id ); |
| 1056 |
return true; |
| 1057 |
} |
| 1058 |
|
| 1059 |
XAP_Dialog_Modeless * XAP_App::getModelessDialog( UT_sint32 i) |
| 1060 |
{ |
| 1061 |
// Retrieve pDialog from the table based on its location in the table |
| 1062 |
return m_IdTable[i].pDialog; |
| 1063 |
} |
| 1064 |
|
| 1065 |
void XAP_App::closeModelessDlgs() |
| 1066 |
{ |
| 1067 |
// Delete all the open modeless dialogs |
| 1068 |
|
| 1069 |
for(UT_sint32 i=0; i <= NUM_MODELESSID; i++) |
| 1070 |
{ |
| 1071 |
if(m_IdTable[i].id >= 0) |
| 1072 |
{ |
| 1073 |
if(getModelessDialog(i) != static_cast<XAP_Dialog_Modeless *>(NULL)) |
| 1074 |
{ |
| 1075 |
getModelessDialog(i)->destroy(); |
| 1076 |
} |
| 1077 |
m_IdTable[i].id = -1; |
| 1078 |
m_IdTable[i].pDialog = NULL; |
| 1079 |
} |
| 1080 |
} |
| 1081 |
} |
| 1082 |
|
| 1083 |
|
| 1084 |
void XAP_App::notifyModelessDlgsOfActiveFrame(XAP_Frame *p_Frame) |
| 1085 |
{ |
| 1086 |
for(UT_sint32 i=0; i <= NUM_MODELESSID; i++) |
| 1087 |
{ |
| 1088 |
if(getModelessDialog(i) != static_cast<XAP_Dialog_Modeless *>(NULL)) |
| 1089 |
{ |
| 1090 |
getModelessDialog(i)->setActiveFrame(p_Frame); |
| 1091 |
} |
| 1092 |
} |
| 1093 |
} |
| 1094 |
|
| 1095 |
void XAP_App::notifyModelessDlgsCloseFrame(XAP_Frame *p_Frame) |
| 1096 |
{ |
| 1097 |
for(UT_sint32 i=0; i <= NUM_MODELESSID; i++) |
| 1098 |
{ |
| 1099 |
if(getModelessDialog(i) != static_cast<XAP_Dialog_Modeless *>(NULL)) |
| 1100 |
{ |
| 1101 |
getModelessDialog(i)->notifyCloseFrame(p_Frame); |
| 1102 |
} |
| 1103 |
} |
| 1104 |
} |
| 1105 |
|
| 1106 |
/* Window Geometry Preferences */ |
| 1107 |
bool XAP_App::setGeometry(UT_sint32 x, UT_sint32 y, UT_uint32 width, UT_uint32 height , UT_uint32 flags) |
| 1108 |
{ |
| 1109 |
XAP_Prefs *prefs = getPrefs(); |
| 1110 |
return prefs->setGeometry(x, y, width, height, flags); |
| 1111 |
} |
| 1112 |
|
| 1113 |
bool XAP_App::getGeometry(UT_sint32 *x, UT_sint32 *y, UT_uint32 *width, UT_uint32 *height, UT_uint32 *flags) |
| 1114 |
{ |
| 1115 |
XAP_Prefs *prefs = getPrefs(); |
| 1116 |
return prefs->getGeometry(x, y, width, height, flags); |
| 1117 |
} |
| 1118 |
|
| 1119 |
void XAP_App::parseAndSetGeometry(const char *string) |
| 1120 |
{ |
| 1121 |
UT_uint32 nw, nh, nflags; |
| 1122 |
UT_sint32 nx, ny; |
| 1123 |
char *next; |
| 1124 |
|
| 1125 |
nw = nh = nflags = 0; |
| 1126 |
nx = ny = 0; |
| 1127 |
|
| 1128 |
next = const_cast<char *>(string); |
| 1129 |
if (*next != '+' && *next != '-') |
| 1130 |
{ |
| 1131 |
nw = strtoul(next, &next, 10); |
| 1132 |
if(*next == 'x' || *next == 'X') |
| 1133 |
{ |
| 1134 |
next++; |
| 1135 |
nh = strtoul(next, &next, 10); |
| 1136 |
nflags |= PREF_FLAG_GEOMETRY_SIZE; |
| 1137 |
} |
| 1138 |
} |
| 1139 |
if (*next == '+' || *next == '-') |
| 1140 |
{ |
| 1141 |
nx = strtoul(next, &next, 10); |
| 1142 |
if(*next == '+' || *next == '-') |
| 1143 |
{ |
| 1144 |
ny = strtoul(next, &next, 10); |
| 1145 |
nflags |= PREF_FLAG_GEOMETRY_POS; |
| 1146 |
} |
| 1147 |
} |
| 1148 |
|
| 1149 |
//Don't update the geometry from the file |
| 1150 |
if(nflags) |
| 1151 |
{ |
| 1152 |
nflags |= PREF_FLAG_GEOMETRY_NOUPDATE; |
| 1153 |
setGeometry(nx, ny, nw, nh, nflags); |
| 1154 |
} |
| 1155 |
} |
| 1156 |
|
| 1157 |
/*! |
| 1158 |
translate given language tag into static UT_LangRecord stored in |
| 1159 |
UT_Language class and set m_pKbdLang to it; do addtional |
| 1160 |
processing to ensure the change propagates into the status bar |
| 1161 |
*/ |
| 1162 |
void XAP_App::setKbdLanguage(const char * pszLang) |
| 1163 |
{ |
| 1164 |
if(!pszLang) |
| 1165 |
{ |
| 1166 |
m_pKbdLang = NULL; |
| 1167 |
} |
| 1168 |
else |
| 1169 |
{ |
| 1170 |
UT_Language Lang; |
| 1171 |
m_pKbdLang = Lang.getLangRecordFromCode(pszLang); |
| 1172 |
|
| 1173 |
// ensure that the change is shown in our status bar |
| 1174 |
bool bChangeLang = false; |
| 1175 |
getPrefsValueBool(XAP_PREF_KEY_ChangeLanguageWithKeyboard, &bChangeLang); |
| 1176 |
|
| 1177 |
if(bChangeLang && m_pKbdLang) |
| 1178 |
{ |
| 1179 |
UT_return_if_fail(m_pKbdLang->m_szLangCode); |
| 1180 |
|
| 1181 |
// invoke appropriate formatting method if it exists |
| 1182 |
const EV_EditMethodContainer * pEMC = getEditMethodContainer(); |
| 1183 |
|
| 1184 |
if(pEMC) |
| 1185 |
{ |
| 1186 |
EV_EditMethod * pEM = pEMC->findEditMethodByName("language"); |
| 1187 |
|
| 1188 |
if (pEM) |
| 1189 |
{ |
| 1190 |
XAP_Frame * pFrame = getLastFocussedFrame(); |
| 1191 |
|
| 1192 |
if(pFrame) |
| 1193 |
{ |
| 1194 |
AV_View * pView = pFrame->getCurrentView(); |
| 1195 |
|
| 1196 |
if(pView) |
| 1197 |
{ |
| 1198 |
EV_EditMethodCallData CallData(m_pKbdLang->m_szLangCode, |
| 1199 |
strlen(m_pKbdLang->m_szLangCode)); |
| 1200 |
|
| 1201 |
pEM->Fn(pView,&CallData); |
| 1202 |
} |
| 1203 |
} |
| 1204 |
} |
| 1205 |
} |
| 1206 |
} |
| 1207 |
} |
| 1208 |
} |
| 1209 |
|
| 1210 |
void XAP_App::enumerateFrames(UT_Vector & v) const |
| 1211 |
{ |
| 1212 |
for(UT_sint32 i = 0; i < getFrameCount(); ++i) |
| 1213 |
{ |
| 1214 |
XAP_Frame * pF = getFrame(i); |
| 1215 |
if(pF) |
| 1216 |
{ |
| 1217 |
if (v.findItem((void*)pF) < 0) |
| 1218 |
{ |
| 1219 |
v.addItem((void*)pF); |
| 1220 |
} |
| 1221 |
} |
| 1222 |
} |
| 1223 |
} |
| 1224 |
|
| 1225 |
std::list< AD_Document* > |
| 1226 |
XAP_App::getDocuments( const AD_Document * pExclude ) const |
| 1227 |
{ |
| 1228 |
UT_Vector t; |
| 1229 |
enumerateDocuments( t, pExclude ); |
| 1230 |
std::list< AD_Document* > ret; |
| 1231 |
for( int i=0; i < t.size(); ++i ) |
| 1232 |
ret.push_back( (AD_Document*)t[i] ); |
| 1233 |
return ret; |
| 1234 |
} |
| 1235 |
|
| 1236 |
|
| 1237 |
/*! |
| 1238 |
Enumerates currently open document associated with the |
| 1239 |
application, excluding document pointed to by pExclude |
| 1240 |
|
| 1241 |
\param v: UT_Vector into which to store the document pointers |
| 1242 |
|
| 1243 |
\para pExclude: pointer to a document to exclude from enumeration, |
| 1244 |
can be NULL (e.g., if this function is called from |
| 1245 |
inside a document, it might be desirable to |
| 1246 |
exclude that document) |
| 1247 |
*/ |
| 1248 |
void XAP_App::enumerateDocuments(UT_Vector & v, const AD_Document * pExclude) const |
| 1249 |
{ |
| 1250 |
UT_sint32 iIndx; |
| 1251 |
|
| 1252 |
for(UT_sint32 i = 0; i < getFrameCount(); ++i) |
| 1253 |
{ |
| 1254 |
XAP_Frame * pF = getFrame(i); |
| 1255 |
|
| 1256 |
if(pF) |
| 1257 |
{ |
| 1258 |
AD_Document * pD = pF->getCurrentDoc(); |
| 1259 |
|
| 1260 |
if(pD && pD != pExclude) |
| 1261 |
{ |
| 1262 |
iIndx = v.findItem((void*)pD); |
| 1263 |
|
| 1264 |
if(iIndx < 0) |
| 1265 |
{ |
| 1266 |
v.addItem((void*)pD); |
| 1267 |
} |
| 1268 |
} |
| 1269 |
} |
| 1270 |
} |
| 1271 |
} |
| 1272 |
|
| 1273 |
EV_EditEventMapper * XAP_App::getEditEventMapper(void) const |
| 1274 |
{ |
| 1275 |
UT_return_val_if_fail(m_pInputModes,NULL); |
| 1276 |
return m_pInputModes->getCurrentMap(); |
| 1277 |
} |
| 1278 |
|
| 1279 |
UT_sint32 XAP_App::setInputMode(const char * szName, bool bForce) |
| 1280 |
{ |
| 1281 |
UT_sint32 i; |
| 1282 |
|
| 1283 |
UT_DEBUGMSG(("XAP_App::setInputMode: %s %d\n", szName, bForce)); |
| 1284 |
|
| 1285 |
UT_return_val_if_fail(m_pInputModes,-1); |
| 1286 |
const char * szCurrentName = m_pInputModes->getCurrentMapName(); |
| 1287 |
if (!bForce && (g_ascii_strcasecmp(szName,szCurrentName) == 0)) |
| 1288 |
return 0; // already set, no change required |
| 1289 |
|
| 1290 |
EV_EditEventMapper * p = m_pInputModes->getMapByName(szName); |
| 1291 |
if (!p) |
| 1292 |
{ |
| 1293 |
// map not previously loaded -- we need to install it first |
| 1294 |
|
| 1295 |
EV_EditBindingMap * pBindingMap = m_pApp->getBindingMap(szName); |
| 1296 |
UT_return_val_if_fail(pBindingMap,-1); |
| 1297 |
bool bResult; |
| 1298 |
bResult = m_pInputModes->createInputMode(szName,pBindingMap); |
| 1299 |
UT_return_val_if_fail(bResult,-1); |
| 1300 |
} |
| 1301 |
|
| 1302 |
// note: derrived classes will need to update keyboard |
| 1303 |
// note: and mouse after we return. |
| 1304 |
|
| 1305 |
UT_DEBUGMSG(("Setting InputMode to [%s] for the current window.\n",szName)); |
| 1306 |
|
| 1307 |
bool bStatus = m_pInputModes->setCurrentMap(szName); |
| 1308 |
|
| 1309 |
// notify all the frames about the INPUTMODE change |
| 1310 |
for (i = 0; i < getFrameCount(); i++) { |
| 1311 |
getFrame(i)->getCurrentView()->notifyListeners(AV_CHG_INPUTMODE); |
| 1312 |
} |
| 1313 |
|
| 1314 |
// rebuild menu's |
| 1315 |
UT_DEBUGMSG(("XAP_App::setInputMode:: rebuilding menu's!")); |
| 1316 |
rebuildMenus(); |
| 1317 |
|
| 1318 |
return (bStatus); |
| 1319 |
} |
| 1320 |
|
| 1321 |
const char * XAP_App::getInputMode(void) const |
| 1322 |
{ |
| 1323 |
return m_pInputModes->getCurrentMapName(); |
| 1324 |
} |
| 1325 |
|
| 1326 |
/*! |
| 1327 |
This is the primary function for allocating graphics classes. It |
| 1328 |
determines if screen or priter graphics is required and then |
| 1329 |
allocates appropriate graphics respecting current setting. |
| 1330 |
*/ |
| 1331 |
GR_Graphics * XAP_App::newGraphics(GR_AllocInfo ¶m) const |
| 1332 |
{ |
| 1333 |
UT_return_val_if_fail(m_pGraphicsFactory, NULL); |
| 1334 |
|
| 1335 |
if(param.isPrinterGraphics()) |
| 1336 |
{ |
| 1337 |
return m_pGraphicsFactory->newGraphics(GRID_DEFAULT_PRINT, param); |
| 1338 |
} |
| 1339 |
else |
| 1340 |
{ |
| 1341 |
return m_pGraphicsFactory->newGraphics(GRID_DEFAULT, param); |
| 1342 |
} |
| 1343 |
} |
| 1344 |
|
| 1345 |
/*! |
| 1346 |
Use only if you require specific graphics, otherwise use newGraphics(GR_AllocInfo*) |
| 1347 |
*/ |
| 1348 |
GR_Graphics * XAP_App::newGraphics(UT_uint32 iClassId, GR_AllocInfo ¶m) const |
| 1349 |
{ |
| 1350 |
UT_return_val_if_fail(m_pGraphicsFactory, NULL); |
| 1351 |
|
| 1352 |
return m_pGraphicsFactory->newGraphics(iClassId, param); |
| 1353 |
} |
| 1354 |
|
| 1355 |
void XAP_App::setDefaultGraphicsId(UT_uint32 i) |
| 1356 |
{ |
| 1357 |
if(i == GRID_UNKNOWN) |
| 1358 |
return; |
| 1359 |
|
| 1360 |
m_iDefaultGraphicsId = i; |
| 1361 |
|
| 1362 |
if(i < GRID_LAST_BUILT_IN && i > GRID_LAST_DEFAULT) |
| 1363 |
{ |
| 1364 |
// change the preference settings |
| 1365 |
UT_return_if_fail(m_prefs) |
| 1366 |
|
| 1367 |
XAP_PrefsScheme *pPrefsScheme = m_prefs->getCurrentScheme(); |
| 1368 |
UT_return_if_fail(pPrefsScheme); |
| 1369 |
|
| 1370 |
UT_String s; |
| 1371 |
UT_String_sprintf(s, "%d", i); |
| 1372 |
|
| 1373 |
pPrefsScheme->setValue(XAP_PREF_KEY_DefaultGraphics, s.c_str()); |
| 1374 |
} |
| 1375 |
} |
| 1376 |
|
| 1377 |
/*! |
| 1378 |
Find the nearest matching font based on the provided parameters |
| 1379 |
|
| 1380 |
TODO: we should use a more sophisticated description of fonts to allow for |
| 1381 |
better matching |
| 1382 |
*/ |
| 1383 |
const char* XAP_App::findNearestFont(const char* pszFontFamily, |
| 1384 |
const char* pszFontStyle, |
| 1385 |
const char* pszFontVariant, |
| 1386 |
const char* pszFontWeight, |
| 1387 |
const char* pszFontStretch, |
| 1388 |
const char* pszFontSize, |
| 1389 |
const char* pszLang) |
| 1390 |
{ |
| 1391 |
return GR_Graphics::findNearestFont(pszFontFamily, pszFontStyle, |
| 1392 |
pszFontVariant, pszFontWeight, |
| 1393 |
pszFontStretch, pszFontSize, |
| 1394 |
pszLang); |
| 1395 |
} |
| 1396 |
|
| 1397 |
/*! |
| 1398 |
Puts together the data necessary for state saving, carrying out any auxiliary actions |
| 1399 |
required (such as dealing with dirty documents). |
| 1400 |
|
| 1401 |
The actual mechanism through which the state data is stored is implemented in _saveState(). |
| 1402 |
*/ |
| 1403 |
|
| 1404 |
#define HIBERNATED_EXT ".HIBERNATED.abw" |
| 1405 |
bool XAP_App::saveState(bool bQuit) |
| 1406 |
{ |
| 1407 |
// gather the state data for platform code to deal with |
| 1408 |
XAP_StateData sd; |
| 1409 |
|
| 1410 |
bool bRet = true; |
| 1411 |
|
| 1412 |
// We will store data for up to XAP_SD_MAX_FILES, making sure we save it for the last |
| 1413 |
// focussed frame in the first slot |
| 1414 |
|
| 1415 |
XAP_Frame * pLastFrame = getLastFocussedFrame(); |
| 1416 |
|
| 1417 |
UT_sint32 i; |
| 1418 |
UT_sint32 j; |
| 1419 |
|
| 1420 |
for(i = 0, j = 0; i < m_vecFrames.getItemCount(); ++i, ++j) |
| 1421 |
{ |
| 1422 |
XAP_Frame * pFrame = NULL; |
| 1423 |
|
| 1424 |
if(i == 0) |
| 1425 |
pFrame = pLastFrame; |
| 1426 |
else |
| 1427 |
pFrame = m_vecFrames[i]; |
| 1428 |
|
| 1429 |
if(pLastFrame == pFrame && j != 0) |
| 1430 |
{ |
| 1431 |
// we have done this frame, but need to do the one at pos 0 in its place |
| 1432 |
pFrame = m_vecFrames[0]; |
| 1433 |
} |
| 1434 |
|
| 1435 |
|
| 1436 |
if(!pFrame) |
| 1437 |
{ |
| 1438 |
--j; |
| 1439 |
continue; |
| 1440 |
} |
| 1441 |
|
| 1442 |
AD_Document * pDoc = pFrame->getCurrentDoc(); |
| 1443 |
|
| 1444 |
if(!pDoc) |
| 1445 |
{ |
| 1446 |
--j; |
| 1447 |
continue; |
| 1448 |
} |
| 1449 |
|
| 1450 |
UT_Error e = UT_OK; |
| 1451 |
|
| 1452 |
if(pDoc->isDirty()) |
| 1453 |
{ |
| 1454 |
// need to decide what to do about dirty documents; perhaps we should keep a |
| 1455 |
// copy of the unsaved state under a different name? |
| 1456 |
// for now just save (otherwise the user will loose the changes when app |
| 1457 |
// hibernates) |
| 1458 |
e = pDoc->save(); |
| 1459 |
if(e == UT_SAVE_NAMEERROR) |
| 1460 |
{ |
| 1461 |
// this is an Untitled document |
| 1462 |
UT_UTF8String s = pFrame->getNonDecoratedTitle(); |
| 1463 |
s += HIBERNATED_EXT; |
| 1464 |
e = pDoc->saveAs(s.utf8_str(), 0); |
| 1465 |
} |
| 1466 |
|
| 1467 |
bRet &= (UT_OK == e); |
| 1468 |
} |
| 1469 |
|
| 1470 |
if(j >= XAP_SD_MAX_FILES || e != UT_OK) |
| 1471 |
{ |
| 1472 |
// no storage space left -- nothing more we can do with this document, so move |
| 1473 |
// to the next one (do not break, we need to deal with anything that is not |
| 1474 |
// saved) |
| 1475 |
|
| 1476 |
--j; // we want to preserve the j value |
| 1477 |
continue; |
| 1478 |
} |
| 1479 |
|
| 1480 |
|
| 1481 |
const char * file = pDoc->getFilename(); |
| 1482 |
if(file && strlen(file) < XAP_SD_FILENAME_LENGTH) |
| 1483 |
{ |
| 1484 |
strncpy(sd.filenames[j], file, XAP_SD_FILENAME_LENGTH); |
| 1485 |
|
| 1486 |
AV_View * pView = pFrame->getCurrentView(); |
| 1487 |
if(pView) |
| 1488 |
{ |
| 1489 |
sd.iDocPos[j] = pView->getPoint(); |
| 1490 |
sd.iXScroll[j] = pView->getXScrollOffset(); |
| 1491 |
sd.iYScroll[j] = pView->getYScrollOffset(); |
| 1492 |
} |
| 1493 |
} |
| 1494 |
else |
| 1495 |
{ |
| 1496 |
--j; |
| 1497 |
continue; |
| 1498 |
} |
| 1499 |
} |
| 1500 |
|
| 1501 |
sd.iFileCount = j; |
| 1502 |
|
| 1503 |
if(!_saveState(sd)) |
| 1504 |
return false; |
| 1505 |
|
| 1506 |
if(bQuit) |
| 1507 |
{ |
| 1508 |
// we have dealt with unsaved docs above, so just clean up any modeless dlgs and quit |
| 1509 |
closeModelessDlgs(); |
| 1510 |
reallyExit(); |
| 1511 |
} |
| 1512 |
|
| 1513 |
return bRet; |
| 1514 |
} |
| 1515 |
|
| 1516 |
/*! |
| 1517 |
Implements the actual mechanism for storing of status data; derrived classes can |
| 1518 |
override to provide methods suitable to their platform. |
| 1519 |
|
| 1520 |
For now, this method does nothing; it could save state data in the profile if we |
| 1521 |
wanted to. (For a working implementation see xap_UnixHildonApp.cpp) |
| 1522 |
|
| 1523 |
returns true on success |
| 1524 |
*/ |
| 1525 |
bool XAP_App::_saveState(XAP_StateData & ) |
| 1526 |
{ |
| 1527 |
return false; |
| 1528 |
} |
| 1529 |
|
| 1530 |
/*! |
| 1531 |
Does the work necessary to restore the application to a previously saved state. The |
| 1532 |
actual mechanism through which the stored state data is retrieved is implemented in |
| 1533 |
_retrieveState(). |
| 1534 |
*/ |
| 1535 |
|
| 1536 |
|
| 1537 |
bool XAP_App::retrieveState() |
| 1538 |
{ |
| 1539 |
XAP_StateData sd; |
| 1540 |
|
| 1541 |
bool bRet = true; |
| 1542 |
|
| 1543 |
if(!_retrieveState(sd)) |
| 1544 |
return false; |
| 1545 |
|
| 1546 |
UT_return_val_if_fail(sd.iFileCount <= XAP_SD_MAX_FILES, false); |
| 1547 |
|
| 1548 |
// now do our thing with it: |
| 1549 |
// * open the files stored in the data |
| 1550 |
// * move carets and scrollbars to the saved positions |
| 1551 |
// * make the first saved frame to be the current frame |
| 1552 |
|
| 1553 |
// we should only be restoring state with no docs already |
| 1554 |
// opened |
| 1555 |
UT_return_val_if_fail(m_vecFrames.getItemCount() <= 1, false); |
| 1556 |
XAP_Frame * pFrame = NULL; |
| 1557 |
|
| 1558 |
if(m_vecFrames.getItemCount()) |
| 1559 |
pFrame = m_vecFrames.getNthItem(0); |
| 1560 |
|
| 1561 |
// if there is a frame, it should be one with unmodified untitled document |
| 1562 |
UT_return_val_if_fail( !pFrame || (!pFrame->getFilename() && !pFrame->isDirty()), false ); |
| 1563 |
|
| 1564 |
UT_Error errorCode = UT_IE_IMPORTERROR; |
| 1565 |
|
| 1566 |
for(UT_uint32 i = 0; i < sd.iFileCount; ++i) |
| 1567 |
{ |
| 1568 |
if(!pFrame) |
| 1569 |
pFrame = newFrame(); |
| 1570 |
|
| 1571 |
if (!pFrame) |
| 1572 |
return false; |
| 1573 |
|
| 1574 |
// Open a complete but blank frame, then load the document into it |
| 1575 |
errorCode = pFrame->loadDocument((const char *)NULL, 0 /*IEFT_Unknown*/); |
| 1576 |
|
| 1577 |
bRet &= (errorCode == UT_OK); |
| 1578 |
|
| 1579 |
if (errorCode == UT_OK) |
| 1580 |
pFrame->show(); |
| 1581 |
else |
| 1582 |
continue; |
| 1583 |
|
| 1584 |
errorCode = pFrame->loadDocument(sd.filenames[i], 0 /*IEFT_Unknown*/); |
| 1585 |
|
| 1586 |
bRet &= (errorCode == UT_OK); |
| 1587 |
|
| 1588 |
if (errorCode != UT_OK) |
| 1589 |
continue; |
| 1590 |
|
| 1591 |
pFrame->show(); |
| 1592 |
|
| 1593 |
AV_View* pView = pFrame->getCurrentView(); |
| 1594 |
if(!pView) |
| 1595 |
{ |
| 1596 |
UT_ASSERT_HARMLESS( UT_SHOULD_NOT_HAPPEN ); |
| 1597 |
bRet = false; |
| 1598 |
continue; |
| 1599 |
} |
| 1600 |
|
| 1601 |
pView->setPoint(sd.iDocPos[i]); |
| 1602 |
pView->setXScrollOffset(sd.iXScroll[i]); |
| 1603 |
pView->setYScrollOffset(sd.iYScroll[i]); |
| 1604 |
|
| 1605 |
// now we check if this doc was autosaved Untitled* doc at hibernation |
| 1606 |
char * p = strstr(sd.filenames[i], HIBERNATED_EXT); |
| 1607 |
if(p) |
| 1608 |
{ |
| 1609 |
// remove extension |
| 1610 |
p = 0; |
| 1611 |
AD_Document * pDoc = pFrame->getCurrentDoc(); |
| 1612 |
|
| 1613 |
if(pDoc) |
| 1614 |
{ |
| 1615 |
pDoc->clearFilename(); |
| 1616 |
pDoc->forceDirty(); |
| 1617 |
pFrame->updateTitle(); |
| 1618 |
} |
| 1619 |
} |
| 1620 |
|
| 1621 |
|
| 1622 |
// frame used -- next doc needs a new one |
| 1623 |
pFrame = NULL; |
| 1624 |
} |
| 1625 |
|
| 1626 |
// set focus to the first frame |
| 1627 |
pFrame = m_vecFrames.getNthItem(0); |
| 1628 |
UT_return_val_if_fail( pFrame, false ); |
| 1629 |
|
| 1630 |
AV_View* pView = pFrame->getCurrentView(); |
| 1631 |
UT_return_val_if_fail( pView, false ); |
| 1632 |
|
| 1633 |
pView->focusChange(AV_FOCUS_HERE); |
| 1634 |
|
| 1635 |
return bRet; |
| 1636 |
} |
| 1637 |
|
| 1638 |
/*! |
| 1639 |
Implements the actual mechanism for retrieving of status data; derrived classes can |
| 1640 |
override to provide methods suitable to their platform. |
| 1641 |
|
| 1642 |
For now, this method does nothing; it could read state data in the profile if we |
| 1643 |
wanted to. (For a working implementation see xap_UnixHildonApp.cpp) |
| 1644 |
|
| 1645 |
returns true on success |
| 1646 |
*/ |
| 1647 |
bool XAP_App::_retrieveState(XAP_StateData & ) |
| 1648 |
{ |
| 1649 |
return false; |
| 1650 |
} |
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
#ifdef DEBUG |
| 1655 |
/*! |
| 1656 |
This function contains some of the most fundamental assumptions |
| 1657 |
about the compiler without which the code will not work; this is |
| 1658 |
for the benefit of future ports, etc. |
| 1659 |
Tomas, May 15, 2003 |
| 1660 |
|
| 1661 |
If you get assert in this function, then you have a real problem |
| 1662 |
-- the code will not work without substantial adjustments. |
| 1663 |
*/ |
| 1664 |
void XAP_App::_fundamentalAsserts() const |
| 1665 |
{ |
| 1666 |
// our UT_Vector class is frequently used to store integers |
| 1667 |
// directly inside of a void * |
| 1668 |
UT_ASSERT(sizeof(void*) >= sizeof(UT_uint32)); |
| 1669 |
|
| 1670 |
// we frequently assume that gchar * is only one byte in size |
| 1671 |
UT_ASSERT(sizeof(gchar) == sizeof(char)); |
| 1672 |
} |
| 1673 |
#endif |
| 1674 |
|
| 1675 |
bool |
| 1676 |
XAP_App::getDisableDoubleBuffering() const |
| 1677 |
{ |
| 1678 |
return m_bDisableDoubleBuffering; |
| 1679 |
} |
| 1680 |
|
| 1681 |
void |
| 1682 |
XAP_App::setDisableDoubleBuffering( bool v ) |
| 1683 |
{ |
| 1684 |
m_bDisableDoubleBuffering = v; |
| 1685 |
} |
| 1686 |
|
| 1687 |
bool |
| 1688 |
XAP_App::getNoGUI() const |
| 1689 |
{ |
| 1690 |
return m_bNoGUI; |
| 1691 |
} |
| 1692 |
|
| 1693 |
void |
| 1694 |
XAP_App::setNoGUI( bool v ) |
| 1695 |
{ |
| 1696 |
setDisableDoubleBuffering(true); |
| 1697 |
m_bNoGUI = v; |
| 1698 |
} |
| 1699 |
|
| 1700 |
std::string |
| 1701 |
XAP_App::createUUIDString() const |
| 1702 |
{ |
| 1703 |
std::auto_ptr<UT_UUID> uuido(getUUIDGenerator()->createUUID()); |
| 1704 |
std::string ret; |
| 1705 |
uuido->toString(ret); |
| 1706 |
return ret; |
| 1707 |
} |
| 1708 |
|