appstate.h File Reference

(r1785/r751)

Go to the source code of this file.

Functions

BOOL InitAppState ()
 Initialises the app-state system, reading prefs.
BOOL SaveAppWindowState (BOOL fAutoRestart)
 Saves the document/view window state into the registry/custom .INI file.
BOOL LoadAppWindowState (wxWindow *pSplashBox)

Variables

BOOL fRestoreWorkspaceOnStartup


Function Documentation

BOOL InitAppState  ) 
 

Initialises the app-state system, reading prefs.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/10/95
Returns:
TRUE if successfully initialises the app-state system.
See also:
LoadAppWindowState

Definition at line 786 of file appstate.cpp.

00787 {
00788     // First, declare this pref.
00789     ERROR2IF(!GetApplication()->DeclareSection(TEXT("Workspace"), 5) ||
00790              !GetApplication()->DeclarePref(TEXT("Workspace"), TEXT("RestoreOnStartup"),
00791                                             &fRestoreWorkspaceOnStartup, FALSE, TRUE),
00792              FALSE,
00793              _R(IDE_BAD_INI_FILE));
00794 
00795 //  TRACEUSER( "JustinF", _T("%s restore workspace on startup\n"),
00796 //            (LPCTSTR) ((fRestoreWorkspaceOnStartup) ? TEXT("Will") : TEXT("Won't")));
00797 
00798     // Success!
00799     return TRUE;
00800 }

BOOL LoadAppWindowState wxWindow *  pSplashBox  ) 
 

BOOL SaveAppWindowState BOOL  fAutoRestart  ) 
 

Saves the document/view window state into the registry/custom .INI file.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/9/95 Inputss: fAutoRestart if TRUE then the registry is set to automatically restart Camelot the next time the user logs on
Returns:
TRUE if successful.
See also:
LoadAppWindowState
CCamApp::InitInstance does this for now! Next, get and save the position of the main window. WINDOWPLACEMENT wp; wp.length = sizeof(wp); if (!GetMainFrame()->GetWindowPlacement(&wp)) { ERROR3("Can't get main frame window placement info"); return FALSE; }

Save the icon, normal, and maximised positions. SetRegValue(hDocKey, TEXT("FrameLoX"), REG_DWORD, &wp.rcNormalPosition.left, sizeof(DWORD)); SetRegValue(hDocKey, TEXT("FrameLoY"), REG_DWORD, &wp.rcNormalPosition.top, sizeof(DWORD)); SetRegValue(hDocKey, TEXT("FrameHiX"), REG_DWORD, &wp.rcNormalPosition.right, sizeof(DWORD)); SetRegValue(hDocKey, TEXT("FrameHiY"), REG_DWORD, &wp.rcNormalPosition.bottom, sizeof(DWORD)); SetRegValue(hDocKey, TEXT("MaxiX"), REG_DWORD, &wp.ptMaxPosition.x, sizeof(DWORD)); SetRegValue(hDocKey, TEXT("MaxiY"), REG_DWORD, &wp.ptMaxPosition.y, sizeof(DWORD)); SetRegValue(hDocKey, TEXT("IconX"), REG_DWORD, &wp.ptMinPosition.x, sizeof(DWORD)); SetRegValue(hDocKey, TEXT("IconY"), REG_DWORD, &wp.ptMinPosition.y, sizeof(DWORD));

Save the window's state. SetRegValue(hDocKey, TEXT(""), REG_DWORD, &wp.showCmd, sizeof(DWORD));

Definition at line 312 of file appstate.cpp.

00313 {
00314     // Don't do this under Win32s.
00315     if (IsWin32s() && !IsWin32c()) return FALSE;
00316 
00317     // Don't allow a call twice (now we have two document templates, each will try to call
00318     // this, so ignore second calls).
00319     static BOOL fHasBeenCalled = FALSE;
00320     if (fHasBeenCalled) return TRUE;
00321     fHasBeenCalled = TRUE;
00322 
00323     // If there's a status line then set it.
00324     CMainFrame* pMainWnd = GetMainFrame();
00325     if (pMainWnd != NULL)
00326     {
00327         pMainWnd->UpdateStatusBarText(&String_256(_R(IDS_SAVING_WORKSPACE_MSG)), FALSE);
00328     }
00329 
00330     // First open/create a new sub-key under the app-state key for holding window positions.
00331     HKEY hMDIKey = CreateRegKey(hAppStateRegKey, TEXT("Workspace\\MDI"));
00332     if (hMDIKey == NULL)
00333     {
00334         ERROR3("Can't get an MDI key in SaveAppWindowState");
00335         return FALSE;
00336     }
00337     
00338     // Get the 'selected' document, if any.
00339     Document* pKernelDoc = Document::GetSelected();
00340     if (pKernelDoc == NULL)
00341     {
00342         // There's no docs open to bother with.
00343         TRACEUSER( "JustinF", _T("No docs open so nothing to do in SaveAppWindowState\n"));
00344 
00345         // Write how many docs and views there are.
00346         DWORD n = 0;
00347         SetRegValue(hMDIKey, TEXT("OpenDocCount"), REG_DWORD, &n, sizeof(DWORD));
00348         SetRegValue(hMDIKey, TEXT("TotalViewCount"), REG_DWORD, &n, sizeof(DWORD));
00349         CloseRegKey(hMDIKey);
00350         return TRUE;
00351     }
00352     
00353     // This counts the total number of open docs & views.
00354     DWORD nDocs = 0;
00355     INT32 nTotalViewCount = 0;
00356 
00357     // Loop over each document template.
00358     POSITION posTmp = AfxGetApp()->GetFirstDocTemplatePosition();
00359     while (posTmp)
00360     {
00361         // Get the next doc template.
00362         CDocTemplate* pTemplate = AfxGetApp()->GetNextDocTemplate(posTmp);
00363 
00364         // Iterate through all the open documents, counting them.
00365         POSITION posDoc = pTemplate->GetFirstDocPosition();
00366         while (posDoc)
00367         {
00368             // Get this document, skipping any that aren't acting as a server (or hidden).
00369             CCamDoc* pDoc = (CCamDoc*) pTemplate->GetNextDoc(posDoc);
00370         #if (_OLE_VER >= 0x200)
00371             if (pDoc->IsEmbedded() || pDoc->GetKernelDoc()->IsAHiddenDoc()) continue;
00372         #endif
00373 
00374             // Create a new subkey for this doc.
00375             TCHAR szDocID[32];
00376             ::wsprintf(szDocID, TEXT("Doc %lu"), ++nDocs);
00377             HKEY hDocKey = CreateRegKey(hMDIKey, szDocID);
00378             if (hDocKey == NULL)
00379             {
00380                 ERROR3("Can't get a doc sub-key in SaveAppWindowState");
00381                 CloseRegKey(hMDIKey);
00382                 return FALSE;
00383             }
00384             
00385             // Iterate through each view on the doc, saving it's state, and counting them.
00386             DWORD nViews = 0;
00387             POSITION posView = pDoc->GetFirstViewPosition();
00388             while (posView)
00389             {
00390                 // Get this view.
00391                 ScreenCamView* pView = (ScreenCamView*) pDoc->GetNextView(posView);
00392 
00393                 // Create a new subkey for this view.
00394                 TCHAR szViewID[32];
00395                 ::wsprintf(szViewID, TEXT("View %lu"), ++nViews);
00396                 HKEY hViewKey = CreateRegKey(hDocKey, szViewID);
00397                 if (hViewKey == NULL)
00398                 {
00399                     ERROR3("Can't get a view sub-key in SaveAppWindowState");
00400                     CloseRegKey(hDocKey);
00401                     CloseRegKey(hMDIKey);
00402                     return FALSE;
00403                 }
00404 
00405                 // Write the view's state into the key.
00406                 MakeKeyFromView(hViewKey, pView);
00407                 CloseRegKey(hViewKey);
00408 
00409                 // COunt this view.
00410                 nTotalViewCount++;
00411             }
00412 
00413             // Save the state of the doc in the subkey.
00414             CString strDocPath = pDoc->GetPathName();
00415             if (strDocPath.IsEmpty())
00416             {
00417                 // Aha!  There is no path name, which means that either (i) the doc is untitled
00418                 // or (ii) the doc is based on a non-native import, eg. a JPEG, or (iii) the doc is
00419                 // as unsaved copy.  See if it has an 'original' path-name saved by the importer, if
00420                 // so then save that out.  Otherwise save out a null string, signifying an untitled doc.
00421                 strDocPath = pDoc->GetOriginalPath();
00422                 if (strDocPath.IsEmpty()) strDocPath = TEXT("");        // untitled
00423             }
00424             
00425         //      TRACEUSER( "JustinF", _T("SaveAppWindowState: path to doc is %s\n"), (LPCTSTR) strDocPath);
00426             SetRegValue(hDocKey, TEXT("FilePath"), REG_SZ,
00427                         (LPCTSTR) strDocPath, strDocPath.GetLength() + 1);
00428             SetRegValue(hDocKey, TEXT("AttachedViewCount"), REG_DWORD, &nViews, sizeof(DWORD));
00429             CloseRegKey(hDocKey);
00430         }
00431     }
00432 
00433     // Write how many docs and views there are.
00434     SetRegValue(hMDIKey, TEXT("OpenDocCount"), REG_DWORD, &nDocs, sizeof(DWORD));
00435     SetRegValue(hMDIKey, TEXT("TotalViewCount"), REG_DWORD, &nTotalViewCount, sizeof(DWORD));
00436     
00437     CloseRegKey(hMDIKey);
00438 
00439 
00440 /*************************************************** CCamApp::InitInstance does this for now!
00441     // Next, get and save the position of the main window.
00442     WINDOWPLACEMENT wp;
00443     wp.length = sizeof(wp);
00444     if (!GetMainFrame()->GetWindowPlacement(&wp))
00445     {
00446         ERROR3("Can't get main frame window placement info");
00447         return FALSE;
00448     }
00449 
00450     // Save the icon, normal, and maximised positions.
00451     SetRegValue(hDocKey, TEXT("FrameLoX"), REG_DWORD, &wp.rcNormalPosition.left,   sizeof(DWORD));
00452     SetRegValue(hDocKey, TEXT("FrameLoY"), REG_DWORD, &wp.rcNormalPosition.top,    sizeof(DWORD));
00453     SetRegValue(hDocKey, TEXT("FrameHiX"), REG_DWORD, &wp.rcNormalPosition.right,  sizeof(DWORD));
00454     SetRegValue(hDocKey, TEXT("FrameHiY"), REG_DWORD, &wp.rcNormalPosition.bottom, sizeof(DWORD));
00455     SetRegValue(hDocKey, TEXT("MaxiX"),    REG_DWORD, &wp.ptMaxPosition.x,         sizeof(DWORD));
00456     SetRegValue(hDocKey, TEXT("MaxiY"),    REG_DWORD, &wp.ptMaxPosition.y,         sizeof(DWORD));
00457     SetRegValue(hDocKey, TEXT("IconX"),    REG_DWORD, &wp.ptMinPosition.x,         sizeof(DWORD));
00458     SetRegValue(hDocKey, TEXT("IconY"),    REG_DWORD, &wp.ptMinPosition.y,         sizeof(DWORD));
00459 
00460     // Save the window's state.
00461     SetRegValue(hDocKey, TEXT(""), REG_DWORD, &wp.showCmd, sizeof(DWORD));
00462 */
00463 
00464     // Finally, if we are supposed to restart automatically . . .
00465     if (fAutoRestart)
00466     {
00467         // . . . we write a command-line to run under a special key.
00468         HKEY hRunOnceKey = CreateRegKey(HKEY_CURRENT_USER,
00469                                 TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce"));
00470         if (hRunOnceKey == NULL)
00471         {
00472             ERROR3("Can't get a RunOnce key in SaveAppWindowState");
00473             return FALSE;
00474         }
00475 
00476         // Windows will run this command-line on startup.
00477         TCHAR szAutoCmd[_MAX_PATH * 2];
00478         ::wsprintf(szAutoCmd, TEXT("%s /Restore"), (LPCTSTR) szCamelotExePath);
00479         SetRegValue(hRunOnceKey, szCamelotAppRegistryID, REG_SZ,
00480                     szAutoCmd, ::camStrlen(szAutoCmd));
00481         CloseRegKey(hRunOnceKey);
00482 
00483         // If there's a status line then set it.
00484         TRACEUSER( "JustinF", _T("\nSee you later . . .\n\n"));
00485         StatusLine::SetPrefix(String_256(_R(IDS_SEE_YOU_LATER_MSG)));
00486     }
00487     
00488     // Success!
00489     return TRUE;
00490 }


Variable Documentation

BOOL fRestoreWorkspaceOnStartup
 

Definition at line 129 of file appstate.cpp.


Generated on Sat Nov 10 03:49:03 2007 for Camelot by  doxygen 1.4.4