00001 // $Id: ralphdoc.cpp 1282 2006-06-09 09:46:49Z alex $ 00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE 00003 ================================XARAHEADERSTART=========================== 00004 00005 Xara LX, a vector drawing and manipulation program. 00006 Copyright (C) 1993-2006 Xara Group Ltd. 00007 Copyright on certain contributions may be held in joint with their 00008 respective authors. See AUTHORS file for details. 00009 00010 LICENSE TO USE AND MODIFY SOFTWARE 00011 ---------------------------------- 00012 00013 This file is part of Xara LX. 00014 00015 Xara LX is free software; you can redistribute it and/or modify it 00016 under the terms of the GNU General Public License version 2 as published 00017 by the Free Software Foundation. 00018 00019 Xara LX and its component source files are distributed in the hope 00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the 00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00022 See the GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License along 00025 with Xara LX (see the file GPL in the root directory of the 00026 distribution); if not, write to the Free Software Foundation, Inc., 51 00027 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00028 00029 00030 ADDITIONAL RIGHTS 00031 ----------------- 00032 00033 Conditional upon your continuing compliance with the GNU General Public 00034 License described above, Xara Group Ltd grants to you certain additional 00035 rights. 00036 00037 The additional rights are to use, modify, and distribute the software 00038 together with the wxWidgets library, the wxXtra library, and the "CDraw" 00039 library and any other such library that any version of Xara LX relased 00040 by Xara Group Ltd requires in order to compile and execute, including 00041 the static linking of that library to XaraLX. In the case of the 00042 "CDraw" library, you may satisfy obligation under the GNU General Public 00043 License to provide source code by providing a binary copy of the library 00044 concerned and a copy of the license accompanying it. 00045 00046 Nothing in this section restricts any of the rights you have under 00047 the GNU General Public License. 00048 00049 00050 SCOPE OF LICENSE 00051 ---------------- 00052 00053 This license applies to this program (XaraLX) and its constituent source 00054 files only, and does not necessarily apply to other Xara products which may 00055 in part share the same code base, and are subject to their own licensing 00056 terms. 00057 00058 This license does not apply to files in the wxXtra directory, which 00059 are built into a separate library, and are subject to the wxWindows 00060 license contained within that directory in the file "WXXTRA-LICENSE". 00061 00062 This license does not apply to the binary libraries (if any) within 00063 the "libs" directory, which are subject to a separate license contained 00064 within that directory in the file "LIBS-LICENSE". 00065 00066 00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS 00068 ---------------------------------------------- 00069 00070 Subject to the terms of the GNU Public License (see above), you are 00071 free to do whatever you like with your modifications. However, you may 00072 (at your option) wish contribute them to Xara's source tree. You can 00073 find details of how to do this at: 00074 http://www.xaraxtreme.org/developers/ 00075 00076 Prior to contributing your modifications, you will need to complete our 00077 contributor agreement. This can be found at: 00078 http://www.xaraxtreme.org/developers/contribute/ 00079 00080 Please note that Xara will not accept modifications which modify any of 00081 the text between the start and end of this header (marked 00082 XARAHEADERSTART and XARAHEADEREND). 00083 00084 00085 MARKS 00086 ----- 00087 00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara 00089 designs are registered or unregistered trademarks, design-marks, and/or 00090 service marks of Xara Group Ltd. All rights in these marks are reserved. 00091 00092 00093 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK. 00094 http://www.xara.com/ 00095 00096 =================================XARAHEADEREND============================ 00097 */ 00098 00099 // implementation file for the Camelots COM RalphDoc 00100 00101 /* 00102 */ 00103 #include "camtypes.h" 00104 #include "cversion.h" 00105 00106 #ifdef RALPH 00107 00108 #include "ralphdoc.h" 00109 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00110 //#include "document.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00111 #include "ralphvw.h" 00112 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00113 #include "toollist.h" 00114 00115 #include "nativeop.h" 00116 #include "zoomops.h" 00117 #include "grndrgn.h" 00118 //#include "mario.h" 00119 #include "product.h" 00120 //#include "ccfile.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00121 //#include "filters.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00122 //#include "spread.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00123 #include "grnddib.h" 00124 #include "grndbmp.h" 00125 #include "ralphprn.h" 00126 //#include "ccfile.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00127 #include <iostream.h> 00128 //#include "filters.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00129 #include "progress.h" 00130 #include "camelot.h" 00131 #include "ralphcri.h" 00132 00133 00134 //#include "hotlink.h" //For the default status bar string 00135 00136 DECLARE_SOURCE( "$Revision: 1282 $" ); 00137 00138 00139 IMPLEMENT_DYNCREATE( RalphDocument, CCmdTarget ) 00140 00141 CC_IMPLEMENT_DYNCREATE( LoadContext, CCObject) 00142 00143 00144 DWORD LoadTimerStart =0; 00145 00146 #define new DEBUG_NEW 00147 00148 //-------------------------------------------------------------------------------------- 00149 // Statics 00150 00151 // Flag for forcing a palette or not. The quick viewer should set this 00152 // to TRUE so it can force its own palette in the foreground. The plugins 00153 // should set it to FALSE, since they're dependant on their host... 00154 BOOL RalphDocument::ForegroundPalette = FALSE; 00155 00156 // the window to attach the rendering timer to 00157 CWnd * RalphDocument::pTimerWnd = NULL; 00158 00159 CString CurrentStatusText=""; 00160 void* RalphDocument::RestoreStackLimit = NULL; 00161 00162 Document* RalphDocument::sm_pImportingDoc = NULL; 00163 DWORD RalphDocument::sm_ImportThreadID = 0; 00164 BOOL RalphDocument::InsideRenderLoop = FALSE; 00165 // Indicates if we are inside the render loop 00166 BOOL RalphDocument::RenderTimerOn = FALSE; 00167 // Flag which indicates if the render timer is on/off 00168 // create this event with manual reset unsignalled 00169 HANDLE RalphDocument::g_hAbortDownLoadEvent = CreateEvent(NULL,TRUE,FALSE,NULL); 00170 // create this event with auto reset signalled 00171 HANDLE RalphDocument::g_hSafeToEnterLoad = CreateEvent(NULL,FALSE,TRUE,NULL); 00172 // an array of events for multiple waits 00173 HANDLE RalphDocument::WakeEvents[2]={RalphDocument::g_hAbortDownLoadEvent,RalphDocument::g_hSafeToEnterLoad}; 00174 INT32 RalphDocument::RalphDocCnt = 0; 00175 00176 00177 // Ralph's critical section stuff 00178 CRITICAL_SECTION RalphCriticalSection::sm_Section; 00179 BOOL RalphCriticalSection::sm_bInit = FALSE; 00180 00181 /******************************************************************************************** 00182 00183 > LoadContext::LoadContext() 00184 00185 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 00186 Created: 20/4/96 00187 Purpose: Constructor for the LoadContext class 00188 00189 ********************************************************************************************/ 00190 00191 LoadContext::LoadContext() 00192 { 00193 // Create the data available event 00194 hDataAvailableEvent = CreateEvent(NULL,FALSE,FALSE,NULL); 00195 00196 // a flag to avoid deadlock in the "network down" case 00197 AsynchDownLoadComplete = FALSE; 00198 00199 // the total of bytes in the file that have not been read 00200 BytesAvailable = 0; 00201 00202 // the total bytes in the file 00203 TotalBytes = 0; 00204 00205 } 00206 00207 /******************************************************************************************** 00208 00209 > LoadContext::~LoadContext() 00210 00211 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 00212 Created: 20/4/96 00213 Purpose: Destructor for the LoadContext class 00214 00215 ********************************************************************************************/ 00216 00217 00218 LoadContext::~LoadContext() 00219 { 00220 // clean up the event 00221 if ( hDataAvailableEvent) 00222 { 00223 CloseHandle(hDataAvailableEvent ); 00224 hDataAvailableEvent== NULL; 00225 } 00226 } 00227 00228 00229 /******************************************************************************************** 00230 > void CALLBACK EXPORT TimerProca(HWND, UINT32, UINT32 id, DWORD systime) 00231 00232 Author: Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com> 00233 Created: 14/7/93 00234 Inputs: From Windows 00235 Outputs: - 00236 Returns: - 00237 Purpose: Timer procedure to handle timer events sent to MainFrm window. 00238 Asks Camelot to do background rendering. If there were no spare timers on 00239 startup, then the CCamApp::OnIdle function is used instead, which doesn't 00240 work when menus are down or dialogs are up, but is better than nothing. 00241 Errors: - 00242 SeeAlso: CCamApp::OnIdle;BackgroundRender 00243 ********************************************************************************************/ 00244 00245 void CALLBACK EXPORT TimerProcA(HWND, UINT32, UINT32 id, DWORD) 00246 { 00247 RalphDocument::InsideRenderLoop = TRUE; 00248 if (id == CAM_TIMER_ID) 00249 { 00250 //TRACEUSER( "Simon", _T("D1 In TimerProcA\n")); 00251 if (!(RalphDocument::sm_ImportThreadID)) 00252 { 00253 Camelot.ServiceRendering(); 00254 } 00255 else 00256 { 00257 static INT32 Count=ASYNC_RENDER_RATE; 00258 if (!Count) 00259 { 00260 Camelot.ServiceRendering(); // Do stuff 00261 Count = ASYNC_RENDER_RATE; 00262 } 00263 Count--; 00264 00265 // We are asynchronously loading so go slow 00266 } 00267 } 00268 RalphDocument::InsideRenderLoop = FALSE; 00269 } 00270 00271 00272 /******************************************************************************************** 00273 00274 > LoadThreadProc(LPVOID pParam) 00275 00276 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 00277 Created: 20/4/96 00278 Inputs: pParam - a pointer to the ralph document we are about to load into 00279 Outputs: - 00280 Returns: - 00281 Purpose: the asynchronous download thread proc ! 00282 Returns: 0 for success... 00283 00284 ********************************************************************************************/ 00285 00286 00287 UINT32 LoadThreadProc(LPVOID pParam) 00288 { 00289 RalphDocument * pThisDoc = (RalphDocument*)pParam; 00290 00291 if( pThisDoc == NULL || !pThisDoc->IsKindOf(RUNTIME_CLASS(RalphDocument))) 00292 { 00293 if(pThisDoc) 00294 pThisDoc->pLoadThread=NULL; 00295 return TRUE; //FALSE; // illegal parameter 00296 } 00297 00298 00299 00300 // TRACEUSER( "Chris", _T("***** Thread %x Waiting \n"), ::GetCurrentThreadId()); 00301 00302 //-------------------- ENTER CRITICAL SECTION -------------------- 00303 // we have a problem here, some of the filters (esp the older ones) are liberaly 00304 // strewn with statics - about the only thing we can do at the moment is ensure 00305 // that only one thread is let in at a time 00306 // ** note ** that it is safe to let all blocked thread through in the abort case as 00307 // they simple bypass the load and clean up 00308 00309 // wait for a "safe to enter" or an "abort" event 00310 DWORD we = WaitForMultipleObjects(2,RalphDocument::WakeEvents,FALSE,INFINITE); 00311 00312 00313 GDrawContext* GD = NULL; 00314 00315 TRY 00316 { 00317 // which event let us through ? 00318 if(we == WAIT_OBJECT_0) 00319 { 00320 // we are aborting so don't bother with the load 00321 // just skip past and clean up 00322 // TRACEUSER( "Chris", _T("***** Enter load from an ABORT EVENT\n")); 00323 pThisDoc->IsImportOK = FALSE; 00324 } 00325 else 00326 { 00327 // these globals will be used in set current etc.. if called from this thread 00328 RalphDocument::sm_pImportingDoc = pThisDoc->GetRalphDocument(); 00329 RalphDocument::sm_ImportThreadID = ::GetCurrentThreadId(); 00330 00331 Document * pDocument = pThisDoc->GetRalphDocument(); 00332 00333 // Tell the Doc we are not importing the file 00334 pDocument->SetIsImporting(FALSE); 00335 00336 // create a new g_draw context to avoid stack problems 00337 GD = new GDrawAsm(::GetCurrentThreadId()); 00338 00339 // Do the load. 00340 pThisDoc->IsImportOK = InvokeNativeFileOp(OPTOKEN_NATIVELOAD, pThisDoc->TempReadAsynchFile, FILTERID_GENERIC); 00341 // TRACEUSER( "Chris", _T("***** Load op Exit - %s\n",pThisDoc->IsImportOK ? "OK!!":"FAILED!!")); 00342 } 00343 00344 // tidy up - delete temp files etc 00345 //pThisDoc->CleanUpAfterAsynchDownLoad (pThisDoc->IsImportOK); 00346 SendMessage(pThisDoc->GetRalphView()->GetSafeHwnd(), WM_DOWNLOADCOMPLETE,pThisDoc->IsImportOK ,0); 00347 if(we != WAIT_OBJECT_0) 00348 { 00349 RalphDocument::sm_pImportingDoc = NULL; 00350 RalphDocument::sm_ImportThreadID = 0; 00351 } 00352 } 00353 00354 CATCH( CFileException, e) 00355 { 00356 TRACEUSER( "Gerry", _T("Yikes CFileException in Load thread\n")); 00357 } 00358 END_CATCH 00359 00360 // delete the g_draw context 00361 if (GD != NULL) 00362 { 00363 delete GD; 00364 GD = NULL; 00365 } 00366 00367 //TRACEUSER( "Chris", _T("**** Thread %x leaving Load thread proc\n"), ::GetCurrentThreadId()); 00368 00369 //-------------------- LEAVE CRITICAL SECTION -------------------- 00370 // set the SafeToEnterLoad event to allow the next thread in 00371 TRACEUSER( "Simon", _T("D1 Leaving LoadThreadProc\n")); 00372 SetEvent(RalphDocument::g_hSafeToEnterLoad); 00373 00374 pThisDoc->pLoadThread = NULL; 00375 return 0; // for success 00376 } 00377 00378 /******************************************************************************************** 00379 00380 > static void RalphDocument::OnRalphAboutToDie() 00381 00382 00383 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 00384 Created: 20/4/96 00385 Purpose: clean up static events etc.. 00386 00387 ********************************************************************************************/ 00388 00389 00390 void RalphDocument::OnRalphAboutToDie() 00391 { 00392 00393 // close the static events used for thread synchronisation 00394 if (g_hSafeToEnterLoad) 00395 { 00396 CloseHandle(g_hSafeToEnterLoad ); 00397 g_hSafeToEnterLoad== NULL; 00398 } 00399 00400 if (g_hAbortDownLoadEvent) 00401 { 00402 CloseHandle(g_hAbortDownLoadEvent ); 00403 g_hAbortDownLoadEvent== NULL; 00404 } 00405 00406 } 00407 00408 /******************************************************************************************** 00409 00410 > BOOL RalphDocument::StartLoadThread() 00411 00412 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 00413 Created: 20/4/96 00414 Purpose: start the asynchronous download 00415 00416 ********************************************************************************************/ 00417 00418 BOOL RalphDocument::StartLoadThread() 00419 { 00420 00421 TRACEUSER( "Chris", _T("Start the load thread\n")); 00422 00423 LoadTimerStart = GetTickCount(); 00424 00425 if(pDocument==NULL) 00426 return FALSE; 00427 if(pRalphView==NULL) 00428 return FALSE; 00429 00430 // belt & braces job, this - make sure we clear the abort condition 00431 Progress::ClearRalphAbortJob(); 00432 00433 // and make sure the abort event is unsignalled 00434 ResetEvent(g_hAbortDownLoadEvent); 00435 00436 //********************** Create the temp file ********************** 00437 00438 BOOL ok = TRUE; 00439 00440 // get a temp file name 00441 char PathBuffer [_MAX_PATH]; // Tmp directory 00442 char FileBuffer [_MAX_PATH]; 00443 00444 // Get the path to the temp directory 00445 ok =GetTempPath(sizeof(PathBuffer), PathBuffer); 00446 00447 // Get a unique filename (full path) 00448 static UINT32 Unique = 0; 00449 if (ok) ok = GetTempFileName(PathBuffer, TEMP_FILE_PREFIX, ++Unique, FileBuffer); 00450 if(!ok) 00451 return FALSE; 00452 00453 PathString = FileBuffer; 00454 00455 // string to hold the filename 00456 CString URLString ; 00457 CString ExtString; 00458 // the full URL 00459 URLString = GetDocumentURL(); 00460 00461 // find the last '.' in the string 00462 INT32 iPointerToExtension = URLString.ReverseFind('.'); 00463 00464 // extract the filename 00465 if (iPointerToExtension!=-1) 00466 { 00467 // chars required = total length - index of last '.' 00468 INT32 nCharsToExtract = URLString.GetLength()-iPointerToExtension; 00469 ExtString=URLString.Right(nCharsToExtract); 00470 00471 // find the last '.' in the string 00472 INT32 iPointerToPathExt = PathString.ReverseFind('.'); 00473 CString LeftString; 00474 if(iPointerToPathExt!=-1) 00475 { 00476 LeftString = PathString.Left(iPointerToPathExt); 00477 LeftString +=ExtString; 00478 } 00479 PathString = LeftString; 00480 } 00481 00482 // create the write file 00483 TempWriteAsynchFile = new CCAsynchDiskFile(); 00484 00485 00486 if(! TempWriteAsynchFile) 00487 return FALSE; 00488 00489 // attach a down load context to allow thread synchronisation 00490 TempWriteAsynchFile->SetDownloadContext(&TheLoadContext); 00491 00492 // open the asynch file for the download 00493 if(! TempWriteAsynchFile->open(PathName((LPCSTR)PathString), ios::out| ios::binary )) 00494 return FALSE; 00495 00496 // create the read file 00497 TempReadAsynchFile = new CCAsynchDiskFile(PathName((LPCSTR)PathString), 00498 ios::in| ios::binary ); 00499 00500 TempReadAsynchFile->SetDownloadContext(&TheLoadContext); 00501 00502 if(! TempReadAsynchFile) 00503 return FALSE; 00504 00505 00506 // Actually do an Import of The Camelot Native EPS format 00507 IsImportOK = TRUE; 00508 00509 // will test whether a load error occured 00510 LoadErrorHasOccured = FALSE; 00511 00512 // Scary multi-threading starts here 00513 00514 //******************** start the load thread ********************** 00515 00516 pLoadThread = AfxBeginThread(LoadThreadProc,this,THREAD_PRIORITY_NORMAL); 00517 00518 return TRUE; 00519 } 00520 00521 /******************************************************************************************** 00522 00523 > STDMETHODIMP RalphDocument::OnDataAvailable (unsigned char* pReadBuffer,DWORD BytesRead) 00524 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 00525 Created: 13/06/96 00526 Inputs: pReadBuffer - char buffer containing new data 00527 BytesRead - size of buffer 00528 Outputs: - 00529 Returns: - 00530 Purpose: write the data to the asynch download file 00531 this is thread safe at the streambuf level 00532 ********************************************************************************************/ 00533 00534 00535 BOOL RalphDocument::OnDataAvailable (unsigned char* pReadBuffer,DWORD BytesRead) 00536 { 00537 if(!IsImportOK) 00538 return TRUE; 00539 00540 // TRACEUSER( "Chris", _T("---- >> %d Bytes now\n"),BytesRead); 00541 // well !!! this shouldn't happen 00542 if(pLoadThread==NULL) 00543 return TRUE; 00544 // check we've got some data 00545 if(pReadBuffer==NULL||BytesRead==0) 00546 return TRUE; 00547 00548 ASSERT(TempWriteAsynchFile); 00549 00550 // write it to the file 00551 if(TempWriteAsynchFile) 00552 { 00553 TempWriteAsynchFile->write(pReadBuffer,BytesRead); 00554 } 00555 return TRUE; 00556 } 00557 00558 /******************************************************************************************** 00559 00560 > BOOL RalphDocument::CleanUpAfterAsynchDownLoad (BOOL LoadOK) 00561 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 00562 Created: 13/06/96 00563 Input: LoadOK - load success state 00564 Purpose: set up doc states etc. 00565 this function is called by the ralphview on receipt of a WM_DOWNLOADCOMPLETE 00566 message - this is posted by the load thread before it exits - the idea is to 00567 keep access to ralph windows within the same thread. 00568 ********************************************************************************************/ 00569 00570 BOOL RalphDocument::CleanUpAfterAsynchDownLoad (BOOL LoadOK) 00571 { 00572 00573 if(pDocument==NULL) 00574 return FALSE; 00575 if(pRalphView==NULL) 00576 return FALSE; 00577 00578 00579 00580 TRACEUSER( "Gerry", _T("Clean up load %s\n",LoadOK?"OK":"Failed")); 00581 00582 // close the file and delete the file object 00583 if(TempWriteAsynchFile) 00584 { 00585 TempWriteAsynchFile->close(); 00586 delete TempWriteAsynchFile; 00587 TempWriteAsynchFile = NULL; 00588 } 00589 00590 if(TempReadAsynchFile) 00591 { 00592 00593 TempReadAsynchFile->close(); 00594 delete TempReadAsynchFile; 00595 TempReadAsynchFile = NULL; 00596 00597 // actually delete the file fromn the disk 00598 BOOL DeletedOk = DeleteFile((LPCSTR)PathString); 00599 00600 ENSURE(DeletedOk,"Couldn't delete temp asynch download file"); 00601 } 00602 00603 if(LoadOK) 00604 { 00605 // Set the flag back to its default value 00606 if (pDocument!=NULL) 00607 pDocument->SetIsImporting(TRUE); 00608 00609 // pDocument->SetCurrent(); 00610 if(!pRalphView->IsSafeToDraw()) 00611 { 00612 pRalphView->SetSafeToDraw(TRUE); 00613 // Setup the initial view mode 00614 SelectViewMode(Viewmode); 00615 } 00616 00617 // Ok All nodes in the document should be safe now, turn off the SafeRender system 00618 pDocument->GetSafeRenderPointer().SetPointerInValid(); 00619 00620 } 00621 else 00622 { 00623 // force a redraw so we can display an error 00624 pRalphView->Invalidate(); 00625 } 00626 00627 // Kill the previous zoom by setting an invalid index 00628 DocView* pDocView = NULL; 00629 pDocView = pRalphView->GetDocViewPtr(); 00630 00631 if(pDocView) 00632 pDocView->SetPrevZoomIndex(cUninitZoomIndex); 00633 00634 /* char buf[64]; 00635 sprintf(buf,"Load took.. %f secs",((double)(GetTickCount()-LoadTimerStart)) /1000); 00636 MessageBox(NULL,buf,"Timer",MB_OK); 00637 */ 00638 00639 // Ok All nodes in the document should be safe now, turn off the SafeRender system 00640 00641 00642 //Beep(2000,15); 00643 00644 return TRUE; 00645 } 00646 00647 00648 00649 /******************************************************************************************** 00650 00651 > BOOL RalphDocument::EndAsynchDownLoad(HRESULT Status) 00652 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 00653 Created: 20/4/96 00654 Input: Status - HRESULT indicating success or abort 00655 Purpose: end the asynchronous download 00656 00657 ********************************************************************************************/ 00658 00659 BOOL RalphDocument::EndAsynchDownLoad(HRESULT Status) 00660 { 00661 00662 if(!IsImportOK) 00663 return TRUE; 00664 00665 TRACEUSER( "Chris", _T("End Download status %d\n"),Status); 00666 00667 if(pDocument==NULL) 00668 return FALSE; 00669 if(pRalphView==NULL) 00670 return FALSE; 00671 if(pLoadThread==NULL) 00672 return FALSE; 00673 00674 TRACEUSER( "Chris", _T("***** End download thread %x\n"),pLoadThread->m_nThreadID); 00675 00676 00677 // Flag the file in the queue that its stream is ended 00678 if(TempWriteAsynchFile ) 00679 TempWriteAsynchFile->DownloadHasEnded(Status); 00680 00681 // AfxDebugBreak(); 00682 00683 00684 // something has gone horribly wrong or the user has aborted 00685 if(Status != 0) 00686 { 00687 TRACEUSER( "Chris", _T("***** Abort the load now !!!\n")); 00688 00689 // this event will wake 00690 // a} any thread waiting for data 00691 // b} open the floodgates in LoadThreadProc 00692 SetEvent(g_hAbortDownLoadEvent); 00693 00694 // fake an escape condition in the progress system - 00695 // this should abort the load nicely 00696 Progress::RalphAbortJob(); 00697 00698 // wait for the load thread to exit before we return 00699 // the first attempt to block this thread using WaitForSingleObject() 00700 // failed as the load thread requires communication with this thread 00701 // using windows messages... this is bad 'cause WaitForSingleObject 00702 // blocks our message loop - deadlock. 00703 00704 //********************** the message loop ************************** 00705 // this message loop is based on the one in CWinThread::Run() 00706 // but I have removed the idle stuff -we don't need any UI updates 00707 // etc.. so I reckon the simpler the better 00708 00709 // for tracking the idle time state 00710 MSG m_msgCur; 00711 // acquire and dispatch messages until a WM_QUIT message is received. 00712 BOOL bDoingBackgroundProcessing =TRUE; 00713 00714 while (bDoingBackgroundProcessing && pLoadThread) 00715 { 00716 // phase2: pump messages while available 00717 do 00718 { 00719 // pump message, but break on WM_QUIT 00720 if (!AfxGetApp()->PumpMessage()) 00721 bDoingBackgroundProcessing = FALSE; 00722 } while (::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE) && pLoadThread); 00723 } 00724 00725 TRACEUSER( "Gerry", _T("thread's dead\n")); 00726 00727 // make sure we clear the abort condition 00728 Progress::ClearRalphAbortJob(); 00729 00730 return FALSE; 00731 } 00732 00733 00734 00735 TRACEUSER( "Chris", _T("Normal end download \n")); 00736 00737 return TRUE; 00738 } 00739 00740 00741 00742 00743 00744 00745 /******************************************************************************************** 00746 00747 > RalphDocument::RalphDocument(HWND ParentWnd) 00748 00749 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 00750 Created: 20/4/96 00751 Purpose: Constructor for the ralphdoc class 00752 00753 ********************************************************************************************/ 00754 00755 RalphDocument::RalphDocument() 00756 { 00757 pDocument = NULL; 00758 pRalphView = NULL; 00759 00760 // default view mode 00761 Viewmode = DOCUMENT_VIEW; 00762 Dither = ORDERED_DITHER; 00763 Toolmode = ZOOM_TOOL; 00764 Quality = ANTI_ALIASED; 00765 DocumentViewInit = FALSE; 00766 InsideRalphMethod = FALSE; 00767 pIErrorCallback = NULL; 00768 pIEventCallback = NULL; 00769 TempWriteAsynchFile = NULL; 00770 TempReadAsynchFile = NULL; 00771 pLoadThread = NULL; 00772 IsImportOK = TRUE; 00773 LoadErrorHasOccured = FALSE; 00774 CurrentStatusText = ""; 00775 00776 00777 if(RalphDocCnt==0) 00778 { 00779 //::SetTimer(RalphDocument::pTimerWnd->GetSafeHwnd(),CAM_TIMER_ID, CAM_TIMER_FREQUENCY,TimerProcA); 00780 SetRenderTimer(TRUE); 00781 } 00782 RalphDocCnt++; 00783 00784 AfxOleLockApp(); 00785 } 00786 00787 /******************************************************************************************** 00788 00789 > RalphDocument::~RalphDocument() 00790 00791 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 00792 Created: 20/4/96 00793 Purpose: Destructor for the ralphdoc class 00794 00795 ********************************************************************************************/ 00796 00797 RalphDocument::~RalphDocument() 00798 { 00799 // AfxDebugBreak(); 00800 00801 TRACEUSER( "Chris", _T("***** Ralph is dead %x loadthread %x\n"), ::GetCurrentThreadId(),sm_ImportThreadID); 00802 00803 Progress::ClearRalphAbortJob(); 00804 Error::ClearError(); 00805 00806 if(pDocument != NULL) 00807 pDocument->SetCurrent(); 00808 00809 // Nuke the view associated with this document 00810 if(pRalphView != NULL) 00811 { 00812 pRalphView->DestroyWindow(); 00813 delete pRalphView; 00814 pRalphView = NULL; 00815 } 00816 00817 // Nuke the document associated with this document 00818 if(pDocument != NULL) 00819 { 00820 delete pDocument; 00821 pDocument = NULL; 00822 } 00823 00824 if(pIErrorCallback) 00825 { 00826 //pIErrorCallback->Release(); 00827 pIErrorCallback = NULL; 00828 } 00829 00830 if (pIEventCallback) 00831 { 00832 pIEventCallback = NULL; 00833 } 00834 00835 RalphDocCnt--; 00836 if (!RalphDocCnt) 00837 { 00838 SetRenderTimer(FALSE); // Stop the render timer 00839 } 00840 00841 AfxOleUnlockApp(); 00842 } 00843 00844 00845 // Vape the ralphdoc 00846 void RalphDocument::OnFinalRelease() 00847 { 00848 TRACEUSER( "Richard", _T("void RalphDocument::OnFinalRelease()\n")); 00849 delete this; 00850 } 00851 00852 /******************************************************************************************** 00853 00854 > BOOL RalphDocument::SelectDitherType(DitherType Dither) 00855 00856 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 00857 Created: 20/4/96 00858 Input Dither - Ordered / Diffused 00859 Purpose: Set the Dither type and force a redraw 00860 00861 ********************************************************************************************/ 00862 00863 BOOL RalphDocument::SelectDitherType(DitherType Dither) 00864 { 00865 if(!pRalphView) 00866 return FALSE; 00867 00868 // translate to GRender Dither values 00869 switch(Dither) 00870 { 00871 case ORDERED_DITHER: 00872 if(RalphDocument::ForegroundPalette) 00873 GRenderRegion::SetViewDither(2); // Enhanced greyscale dithering 00874 else 00875 GRenderRegion::SetViewDither(1); // Normal netscapey palette thing 00876 break; 00877 case ERROR_DIFFUSE_DITHER: 00878 GRenderRegion::SetViewDither(3); 00879 break; 00880 case NO_DITHER: 00881 GRenderRegion::SetViewDither(4); 00882 break; 00883 } 00884 00885 // and force a redraw of the view 00886 DocView* pDocView = NULL; 00887 pDocView = pRalphView->GetDocViewPtr(); 00888 00889 if(pDocView==NULL) 00890 return FALSE; 00891 00892 pDocView->ForceRedraw(); 00893 return TRUE; 00894 } 00895 00896 /******************************************************************************************** 00897 00898 > BOOL RalphDocument::SelectTool(ToolMode toolmode) 00899 00900 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 00901 Created: 20/4/96 00902 Input Toolmode - enum defining the tool to switch to 00903 Purpose: Switch into the given tool 00904 00905 ********************************************************************************************/ 00906 00907 BOOL RalphDocument::SelectTool(ToolMode toolmode) 00908 { 00909 00910 UINT32 ToolId =0; 00911 // translate to camelot tool id's 00912 switch(toolmode) 00913 { 00914 case PUSH_TOOL: 00915 ToolId = TOOLID_PUSH; 00916 break; 00917 case ZOOM_TOOL : 00918 ToolId = TOOLID_ZOOM; 00919 break; 00920 00921 // unknown or NO_TOOL 00922 case NO_TOOL: 00923 default: 00924 ToolId=0; 00925 00926 } 00927 00928 if (Tool::GetCurrentID() == ToolId) 00929 return TRUE; // Already the selected tool 00930 00931 // go into neutral 00932 if(ToolId == 0) 00933 { 00934 Tool::SetNoCurrent(); 00935 } 00936 // set the tool current 00937 else 00938 { 00939 ToolListItem * pItem = NULL; 00940 pItem = Tool::Find(ToolId); 00941 if(pItem == NULL) 00942 return FALSE; 00943 00944 pItem->pTool->SetCurrent(); 00945 } 00946 00947 00948 return TRUE; 00949 } 00950 00951 /******************************************************************************************** 00952 00953 > BOOL RalphDocument::SelectViewQuality(INT32 ViewQuality) 00954 00955 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 00956 Created: 20/4/96 00957 Input ViewQuality value for new view quality 00958 Purpose: Change the render quality for this document 00959 00960 ********************************************************************************************/ 00961 00962 BOOL RalphDocument::SelectViewQuality(INT32 ViewQuality) 00963 { 00964 if(pRalphView==NULL) 00965 return FALSE; 00966 return pRalphView->SetViewQuality(ViewQuality); 00967 } 00968 00969 00970 /******************************************************************************************** 00971 00972 > BOOL RalphDocument::SelectPaletteMode(BOOL Foreground) 00973 00974 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00975 Created: 1/8/96 00976 Purpose: Change the palette realising mode 00977 00978 ********************************************************************************************/ 00979 00980 BOOL RalphDocument::SelectPaletteMode(BOOL Foreground) 00981 { 00982 RalphDocument::ForegroundPalette = Foreground; 00983 00984 /* if(pRalphView==NULL) 00985 // Redraw ? 00986 */ 00987 return TRUE; 00988 } 00989 00990 /******************************************************************************************** 00991 00992 > BOOL RalphDocument::RestoreZoomAndScroll) 00993 00994 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 00995 Created: 20/4/96 00996 Purpose: Restore the zoom and scroll offsets 00997 ********************************************************************************************/ 00998 00999 BOOL RalphDocument::RestoreZoomAndScroll() 01000 { 01001 DocView* pDocView = NULL; 01002 01003 if(pRalphView==NULL) 01004 return FALSE; 01005 01006 pDocView = pRalphView->GetDocViewPtr(); 01007 01008 if(pDocView==NULL) 01009 return FALSE; 01010 01011 // Restore the saved scale factor and scroll offsets. 01012 pDocView->SetViewScale(LastViewScale); 01013 01014 pDocView->SetScrollOffsets(LastScrollOffset, FALSE); 01015 01016 pDocView->SetZoomTableIndex(LastZoomIndex); 01017 01018 pDocView->ForceRedraw(TRUE); 01019 01020 01021 return TRUE; 01022 } 01023 01024 /******************************************************************************************** 01025 01026 > BOOL RalphDocument::SaveZoomAndScroll) 01027 01028 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 01029 Created: 20/4/96 01030 Purpose: Save the zoom and scroll offsets so that we can restore them after 01031 view mode changes 01032 ********************************************************************************************/ 01033 01034 BOOL RalphDocument::SaveZoomAndScroll() 01035 { 01036 DocView* pDocView = NULL; 01037 01038 if(pRalphView ==NULL) 01039 return FALSE; 01040 01041 pDocView = pRalphView->GetDocViewPtr(); 01042 01043 if(pDocView==NULL) 01044 return FALSE; 01045 01046 // Record the current scale and scroll offset. 01047 LastZoomIndex = pDocView->GetZoomTableIndex(); 01048 LastViewScale = pDocView->GetViewScale(); 01049 LastScrollOffset = pDocView->GetScrollOffsets(); 01050 return TRUE; 01051 } 01052 01053 /******************************************************************************************** 01054 01055 > BOOL RalphDocument::ZoomToFullScale() 01056 01057 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 01058 Created: 20/4/96 01059 Purpose: Set up initial Scale and scroll offsets for document view 01060 01061 ********************************************************************************************/ 01062 01063 BOOL RalphDocument::ZoomToFullScale() 01064 { 01065 if(pRalphView==NULL) 01066 return FALSE; 01067 01068 if(pDocument==NULL) 01069 return FALSE; 01070 01071 // This has been removed by Gerry (again 9/9/96) 01072 // It actually causes an unecessary redraw so don't do it 01073 // pRalphView->LockWindowUpdate(); 01074 01075 DocView* pDocView = NULL; 01076 pDocView = pRalphView->GetDocViewPtr(); 01077 01078 if(pDocView) 01079 { 01080 // make sure we save the last zoom 01081 OpZoomPrevZoomDescriptor::SaveZoom(pDocView); 01082 01083 // 100 % 01084 pDocView->SetViewScale(FIXED16(1.0)); 01085 // force OnNewView by setting 0 scroll offsets 01086 pDocView->SetScrollOffsets(WorkCoord(0,0), FALSE); 01087 // position the window in the correct place 01088 pDocView->OnNewView(); 01089 01090 pDocView->ForceRedraw(TRUE); 01091 } 01092 01093 // all done... let the redraw begin. 01094 // pRalphView->UnlockWindowUpdate(); 01095 01096 return TRUE; 01097 } 01098 01099 01100 /******************************************************************************************** 01101 01102 > BOOL RalphDocument::SetDocumentViewMode() 01103 01104 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 01105 Created: 20/4/96 01106 Purpose:1 Set up initial Scale and scroll offsets for document view 01107 01108 ********************************************************************************************/ 01109 01110 BOOL RalphDocument::SetDocumentViewMode() 01111 { 01112 01113 if(pRalphView==NULL) 01114 return FALSE; 01115 01116 if(pDocument==NULL) 01117 return FALSE; 01118 01119 // if we are going into Document view for the first time we 01120 // initialise the view at 100% with the page corner at top left of view 01121 if(!DocumentViewInit) 01122 { 01123 01124 DocView* pDocView = NULL; 01125 pDocView = pRalphView->GetDocViewPtr(); 01126 01127 if(pDocView) 01128 { 01129 OpZoomDescriptor::FakeInvoke(OPTOKEN_ZOOMSPREAD); 01130 01131 } 01132 DocumentViewInit = TRUE; 01133 // save the zoom factor and scroll offset 01134 01135 return SaveZoomAndScroll(); 01136 01137 } 01138 else 01139 { 01140 // restore last zoom factor and scroll offsets 01141 return RestoreZoomAndScroll(); 01142 } 01143 return TRUE; 01144 } 01145 01146 /******************************************************************************************** 01147 > BOOL RalphDocument::SelectViewMode(ViewMode Vmode) 01148 01149 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 01150 Created: 20/4/96 01151 Purpose: Change the view mode for this document 01152 01153 ********************************************************************************************/ 01154 01155 BOOL RalphDocument::SelectViewMode(ViewMode Vmode) 01156 { 01157 01158 if(pRalphView==NULL) 01159 return FALSE; 01160 01161 if(pDocument==NULL) 01162 return FALSE; 01163 01164 01165 // set the doc view state 01166 Viewmode = Vmode; 01167 01168 // let the kernel know 01169 pDocument->SetRalphViewMode(Viewmode); 01170 01171 switch (Vmode) 01172 { 01173 case DOCUMENT_VIEW: 01174 pRalphView->ShowScrollers(TRUE); 01175 SetDocumentViewMode(); 01176 break; 01177 case PAGE_VIEW: 01178 pRalphView->ShowScrollers(FALSE); 01179 // save the zoom factor and scroll offset 01180 SaveZoomAndScroll(); 01181 break; 01182 case DRAWING_VIEW: 01183 pRalphView->ShowScrollers(FALSE); 01184 // zoom to drawing 01185 OpZoomDescriptor::FakeInvoke(OPTOKEN_ZOOMDRAWING); 01186 break; 01187 } 01188 01189 01190 DocView * pDocView = NULL; 01191 01192 // get a pointer to the kernel docview 01193 pDocView = pRalphView->GetDocViewPtr(); 01194 01195 if(pDocView == NULL) 01196 return FALSE; 01197 01198 // Kill the previous zoom by setting an invalid index 01199 pDocView->SetPrevZoomIndex(cUninitZoomIndex); 01200 01201 return TRUE; 01202 } 01203 01204 /******************************************************************************************** 01205 01206 > void RalphDocument::SetSelected() 01207 01208 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> & Simon 01209 Created: 08/08/96 01210 Purpose: Make this RalphDocument selected. All Tool operations will act on this document. 01211 ********************************************************************************************/ 01212 01213 void RalphDocument::SetSelected() 01214 { 01215 // Make this the selected view 01216 DocView* pDocVw = pRalphView->GetDocViewPtr(); 01217 ASSERT(pDocVw); 01218 if (pDocVw) 01219 { 01220 if (DocView::GetSelected() != pDocVw) 01221 { 01222 Document::SetSelectedViewAndSpread(pDocVw->GetDoc(), 01223 pDocVw, 01224 NULL); 01225 } 01226 } 01227 SelectTool(Toolmode); 01228 } 01229 01230 /******************************************************************************************** 01231 01232 > BOOL RalphDocument::PassErrorToHarness(HRESULT ErrCode) 01233 01234 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 01235 Created: 13/06/96 01236 Purpose: Pass any error codes back to the harness (Netscape Pluggin etc..) 01237 so that they can inform the user 01238 ********************************************************************************************/ 01239 01240 BOOL RalphDocument::PassErrorToHarness(HRESULT ErrCode) 01241 { 01242 // we won't report the error during the load 01243 // we'll simply flag it and report it after 01244 if(pLoadThread) 01245 { 01246 LoadErrorHasOccured = TRUE; 01247 } 01248 else 01249 { 01250 01251 if(!pIErrorCallback) 01252 return FALSE; 01253 else 01254 pIErrorCallback->InformError(ErrCode); 01255 } 01256 return TRUE; 01257 } 01258 01259 /******************************************************************************************** 01260 01261 > BOOL RalphDocument::PrintRalphView(HDC hDC, DWORD X, DWORD Y, DWORD Width, DWORD Height, DWORD DPI) 01262 01263 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> (in a rumbling state) 01264 Created: 23/08/96 01265 Inputs: hDC - Handle of device context to which we want to print (metafile dc, etc) 01266 X, Y, Width, Height - DC co-ords within which we should render 01267 DPI - DPI of bitmap to construct for the DC 01268 Returns: TRUE if no serious problems... In fact, TRUE all the time... 01269 Purpose: Print the current view (in its current state) to the given DC. 01270 At the moment we only support bitmap printing via GRenderRalphPrint. 01271 ********************************************************************************************/ 01272 01273 BOOL RalphDocument::PrintRalphView(HDC hDC, DWORD X, DWORD Y, DWORD Width, DWORD Height, DWORD DPI) 01274 { 01275 // Create a grenderregion, attach it to the given dc and render the view into it 01276 if(pDocument != NULL && pRalphView != NULL) 01277 { 01278 Spread *pSpread = pDocument->FindFirstSpread(); 01279 DocView* pDocVw = pRalphView->GetDocViewPtr(); 01280 01281 // Force fore-ground redraw mode 01282 BOOL OldBackgroundRedrawState = pDocVw->GetForeBackMode(); 01283 pDocVw->SetForeBackMode(FALSE); 01284 01285 // Get the view's clip rect in Spread Coords 01286 DocRect ClipRect = pDocVw->GetDocViewRect(pSpread); 01287 pSpread->DocCoordToSpreadCoord(&ClipRect); 01288 01289 // Get the current view's rendering matrix and view scale 01290 Matrix ConvMatrix = pDocVw->ConstructRenderingMatrix(pSpread); 01291 FIXED16 ViewScale = pDocVw->GetViewScale(); 01292 01293 // Construct a Ralph Print render region which is basically a maligned GRenderPrint (GRenderDIB) 01294 GRenderRalphPrint *pPrintRR = new GRenderRalphPrint(ClipRect, ConvMatrix, ViewScale, 32, (double)DPI); 01295 01296 if(pPrintRR != NULL) 01297 { 01298 CDC *pDC = CDC::FromHandle(hDC); 01299 pPrintRR->SetDCRect(X, Y, X+Width, Y+Height); 01300 01301 // Attach our DC to the view and render region... 01302 if(pDC != NULL && pPrintRR->AttachDevice(pDocVw, pDC, pSpread)) 01303 { 01304 // Render the current view to the constructed render region... 01305 pDocVw->ContinueRenderView(pPrintRR, pSpread); 01306 } 01307 } 01308 01309 // Restore fore-ground redraw mode 01310 pDocVw->SetForeBackMode(OldBackgroundRedrawState); 01311 } 01312 01313 return TRUE; 01314 } 01315 01316 01317 /******************************************************************************************** 01318 01319 > BOOL RalphDocument::WebAddressSelected(LPCWSTR WebAddress) 01320 01321 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 01322 Created: 20/08/96 01323 Purpose: Call this function to inform an interested harness that a Web address has 01324 been selected. 01325 ********************************************************************************************/ 01326 01327 void RalphDocument::WebAddressSelected(String_256* InAddress) 01328 { 01329 CString WebAddress=*InAddress; 01330 01331 // If the interface is registered then inform the harness of the event 01332 if(pIEventCallback) 01333 pIEventCallback->WebAddressSelected(WebAddress); 01334 } 01335 01336 /******************************************************************************************** 01337 01338 > void RalphDocument::SetStatusBar(String_256* pNewText) 01339 01340 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 01341 Created: 6/9/96 01342 Purpose: Sets the status bar of the browser to the new text 01343 See Also: DocView::OnMouseMove; DocView::OnMouseMoveWithNoTool 01344 ********************************************************************************************/ 01345 01346 void RalphDocument::SetStatusBar(String_256* pNewText) 01347 { 01348 CString TextToPass=*pNewText; 01349 01350 //Only change the status bar text if the new text is different 01351 //from the old text. 01352 // If the interface is registered then inform the harness of the event 01353 if(pIEventCallback) 01354 pIEventCallback->SetStatusBar(TextToPass); 01355 01356 CurrentStatusText=TextToPass; 01357 01358 } 01359 01360 /******************************************************************************************** 01361 01362 > void RalphDocument::SetStatusBar(CString NewText) 01363 01364 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 01365 Created: 6/9/96 01366 Purpose: Sets the status bar of the browser to the new text 01367 ********************************************************************************************/ 01368 01369 void RalphDocument::SetStatusBar(CString NewText) 01370 { 01371 //Only change the status bar text if the new text is different 01372 //from the old text. 01373 if(NewText!=CurrentStatusText) 01374 { 01375 // If the interface is registered then inform the harness of the event 01376 if(pIEventCallback) 01377 pIEventCallback->SetStatusBar(NewText); 01378 01379 CurrentStatusText=NewText; 01380 } 01381 } 01382 01383 /******************************************************************************************** 01384 01385 > void RalphDocument::SetStatusBar() 01386 01387 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 01388 Created: 6/9/96 01389 Purpose: Sets the status bar of the browser to a default 01390 message. 01391 ********************************************************************************************/ 01392 01393 void RalphDocument::SetStatusBar() 01394 { 01395 String_256 DefaultText(_R(IDS_DEFAULTBROWSERSTATUSSTR)); 01396 01397 CString TextToPass(DefaultText); 01398 01399 //Only change the status bar text if the new text is different 01400 //from the old text. 01401 // if(TextToPass!=CurrentStatusText) 01402 // { 01403 // If the interface is registered then inform the harness of the event 01404 if(pIEventCallback) 01405 { 01406 pIEventCallback->SetStatusBar(TextToPass); 01407 CurrentStatusText=TextToPass; 01408 } 01409 // else 01410 // { 01411 // CurrentStatusText=""; 01412 // } 01413 01414 // } 01415 } 01416 01417 /******************************************************************************************** 01418 01419 > String_256 RalphDocument::GetDocumentURL() 01420 01421 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 01422 Created: 6/9/96 01423 Returns: DocumentURL 01424 Purpose: Gets the URL of this Ralph document. 01425 ********************************************************************************************/ 01426 01427 String_256 RalphDocument::GetDocumentURL() 01428 { 01429 String_256 ReturnText(DocumentURL); 01430 01431 return ReturnText; 01432 } 01433 01434 /******************************************************************************************** 01435 01436 > String_256 RalphDocument::GetDocumentURL() 01437 01438 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 01439 Created: 6/9/96 01440 Returns: The base URL of this Ralph document 01441 Purpose: Gets the base URL of this Ralph document. The base URL is the path... 01442 that is, the entire string used to access file minus the filename on the end. 01443 01444 Ideally this function would return the value of the HTML variable "Base" for 01445 Camelot documents embedded within HTML. But it doesn't. 01446 ********************************************************************************************/ 01447 01448 String_256 RalphDocument::GetBaseURL() 01449 { 01450 /* CString ParseString; 01451 01452 //To get the base URL, we're going to parse the document's URL. 01453 //First we need to get the characters we're going to search for 01454 //from the document's resources. 01455 01456 // CString sPathSeparator; 01457 //tring sColon; 01458 //CString sParaSeparator; 01459 //CString sFragment; 01460 //CString sQuery; 01461 01462 String_256 s256PathSeperator(_R(IDS_URL_PATH_SEPARATOR)); 01463 CString sPathSeparator(s256PathSeperator); 01464 01465 String_256 s256ParaSeparator(_R(IDS_URL_PARAMETER_SEPARATOR)); 01466 CString sParaSeparator(s256ParaSeparator); 01467 01468 //sPathSeparator.LoadString(_R(IDS_URL_PATH_SEPARATOR)); 01469 //sColon.LoadString(_R(IDS_URL_COLON)); 01470 //sParaSeparator.LoadString(_R(IDS_URL_PARAMETER_SEPARATOR)); 01471 //sFragment.LoadString(_R(IDS_URL_FRAGMENT)); 01472 //sQuery.LoadString(_R(IDS_URL_QUERY)); 01473 01474 char cPathSeparator=sPathSeparator[0]; 01475 char cParaSeparator=sParaSeparator[0]; 01476 01477 //Now we can do some parsing with those characters 01478 //The parsing rules are usually unpleasant, and are contained in 01479 //http://ds.internic.net/rfc/rfc1808.txt. But in our case it's easy. 01480 01481 //The form of a URL should always be: 01482 // <scheme>://<net_loc>/<path>;<params>?<query>#<fragment> 01483 01484 //And we only want: 01485 // <scheme>://<net_loc>/<path> 01486 01487 01488 01489 //So find the first semicolon in the string 01490 01491 ParseString=DocumentURL; 01492 01493 INT32 iEndPointer=ParseString.Find(cParaSeparator); 01494 01495 //If we found a semicolon, take everything from that semicolon onwards 01496 //out of the string 01497 if (iEndPointer!=-1) 01498 { 01499 ParseString=ParseString.Left(iEndPointer); 01500 } 01501 01502 //Now find the last / in the string 01503 01504 iEndPointer=ParseString.ReverseFind(cPathSeparator); 01505 01506 //Did we find a / ? 01507 if (iEndPointer) 01508 { 01509 //Yes. So the string to return is everything up to that slash. 01510 ParseString=ParseString.Left(iEndPointer+1); 01511 } 01512 else 01513 { 01514 //No. So there isn't a base URL. Return a blank string. 01515 ParseString.Empty(); 01516 } 01517 01518 //And create a string to return 01519 //String_256 ReturnString(ParseString);*/ 01520 01521 return DocumentURL; 01522 } 01523 01524 /******************************************************************************************** 01525 01526 > void RalphDocument::SetRenderTimer(BOOL State) 01527 01528 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 01529 Created: 03/10/96 01530 Inputs: State: When TRUE the render timer is started. When FALSE the render timer 01531 is stopped. 01532 Purpose: Starts/Stops the render timer. 01533 ********************************************************************************************/ 01534 01535 void RalphDocument::SetRenderTimer(BOOL StartTimer) 01536 { 01537 BOOL ok = TRUE; 01538 01539 if (RenderTimerOn == StartTimer) 01540 { 01541 ASSERT(FALSE); 01542 return; 01543 } 01544 if (StartTimer) 01545 { 01546 // If we don't have a timer window then we must remember to create it 01547 if(pTimerWnd==NULL) 01548 { 01549 pTimerWnd= new CWnd(); 01550 BOOL WindowCreated =FALSE; 01551 01552 if(pTimerWnd) 01553 { 01554 WindowCreated = pTimerWnd->CreateEx(0,AfxRegisterWndClass( 01555 0, 01556 0, 01557 0, 01558 0), 01559 01560 NULL, NULL, 01561 0,0,8,8, 01562 NULL, 01563 NULL); 01564 01565 //pTimerWnd->SetTimer(CAM_TIMER_ID, CAM_TIMER_FREQUENCY,TimerProcA); 01566 01567 } 01568 ENSURE(WindowCreated,"Failed to create the timer window"); 01569 // Now start the heart 01570 } 01571 ok = ::SetTimer(RalphDocument::pTimerWnd->GetSafeHwnd(),CAM_TIMER_ID, CAM_TIMER_FREQUENCY,TimerProcA); 01572 ASSERT(ok); 01573 } 01574 else 01575 { 01576 ok = ::KillTimer(RalphDocument::pTimerWnd->GetSafeHwnd(),CAM_TIMER_ID); 01577 #ifdef _DEBUG 01578 ASSERT(ok); 01579 #endif 01580 if (pTimerWnd) 01581 { 01582 pTimerWnd->DestroyWindow(); 01583 delete pTimerWnd; 01584 pTimerWnd = NULL; 01585 } 01586 } 01587 RenderTimerOn = StartTimer; 01588 } 01589 01590 //******************************************************************************************* 01591 // ** PLEASE READ ** 01592 // Ralph Document Interface notes 01593 // All interface methods MUST start with 01594 // METHOD_PROLOGUE(containing class, interface class) this macro creates pThis 01595 // START_RALPH_METHOD() - sets a flag used by the error reportiong system 01596 // These methods should NEVER return normally !! they MUST use 01597 // RALPH_RETURN() 01598 // as this clears the flag set in the START_RALPH_METHOD 01599 // NB this does not apply to the standard AddRef, Release and QueryInterface methods 01600 // TO test for any errors that may have occured -during an Op for instance use 01601 // GET_RALPH_ERROR() 01602 // This tests whether a serious ERROR1 has occured and if so clears the InMethod flag 01603 // and returns the error (mapped to an HRESULT in Error::GetRalphError() 01604 //******************************************************************************************* 01605 01606 01607 // RalphDoc's Interface Map 01608 BEGIN_INTERFACE_MAP(RalphDocument, CCmdTarget) 01609 INTERFACE_PART(RalphDocument, IID_ICreation, Creation) 01610 INTERFACE_PART(RalphDocument, IID_ICommandControl,CommandControl) 01611 INTERFACE_PART(RalphDocument, IID_IViewControl,ViewControl) 01612 INTERFACE_PART(RalphDocument, IID_IInitRalph,InitRalph) 01613 INTERFACE_PART(RalphDocument, IID_IAsynchDownLoad,AsynchDownLoad) 01614 END_INTERFACE_MAP() 01615 01616 // We must call this. See Help for IMPLEMENT_OLECREATE 01617 // This is RalphDoc's CLASS_ID 01618 // 27682680-d299-11cf-ab39-0020af71e433 01619 IMPLEMENT_OLECREATE(RalphDocument, "RalphDocument", 01620 0x27682680, 0xd299, 0x11cf, 0xab, 0x39, 0x0, 0x20, 0xaf, 0x71, 0xe4, 0x33); 01621 01622 01623 /******************************************************************************************** 01624 01625 > STDMETHODIMP_ BOOL RalphDocument::XCreation::GetVerNum(TCHAR* pVerNum) 01626 01627 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 01628 Created: 20/4/96 01629 Purpose: Creates a View for the RalphDocument. 01630 01631 ********************************************************************************************/ 01632 STDMETHODIMP RalphDocument::XCreation::GetVerNum(TCHAR * pVerNum) 01633 01634 { 01635 METHOD_PROLOGUE(RalphDocument, Creation) 01636 START_RALPH_METHOD() 01637 // ouch.. 01638 if(pVerNum == NULL) 01639 RALPH_RETURN(E_FAIL); 01640 // get the ver num and date 01641 TCHAR VerText[] = TEXT(PRODUCT_VERSION_NO " " __DATE__ ); 01642 // the build number 01643 TCHAR Temp[32]; 01644 camSprintf(Temp,_T(" (%d)"), CAMELOT_VERSION_MINOR); 01645 // add them 01646 CString FullText(VerText); 01647 FullText +=Temp; 01648 // and return 01649 ::camStrcpy(pVerNum,FullText); 01650 // fine.. 01651 RALPH_RETURN (S_OK); 01652 01653 } 01654 01655 /******************************************************************************************** 01656 01657 > STDMETHODIMP_ BOOL RalphDocument::XCreation::CreateViewWindow(HWND ParentWnd 01658 ViewMode Vmode, 01659 BOOL ShowScrollers, 01660 BOOL ShowWindow, 01661 BOOL HasBorder, 01662 HWND * ViewWindow) 01663 01664 01665 01666 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 01667 Created: 20/4/96 01668 Purpose: Creates a View for the RalphDocument. 01669 Errors: S_OK - success 01670 RALPH_E_OUTOFMEMORY - 01671 RALPH_E_BAD_FILE - load failed 01672 RALPH_E_LOADFAILED - load failed 01673 RALPH_E_UNEXPECTED - catch all error 01674 01675 ********************************************************************************************/ 01676 STDMETHODIMP RalphDocument::XCreation::CreateViewWindow(HWND ParentWnd, 01677 ViewMode Vmode, 01678 BOOL ShowScrollers, 01679 BOOL ShowWindow, 01680 BOOL HasBorder, 01681 HWND * ViewWindow) 01682 01683 { 01684 METHOD_PROLOGUE(RalphDocument, Creation) 01685 START_RALPH_METHOD() 01686 01687 Progress::ClearRalphAbortJob(); 01688 Error::ClearError(); 01689 01690 Progress::ClearRalphAbortJob(); 01691 Error::ClearError(); 01692 01693 01694 BOOL ok =TRUE; 01695 01696 if(ParentWnd==0) 01697 RALPH_RETURN (RALPH_E_UNEXPECTED); 01698 01699 // set this for LoadDocument 01700 pThis->Viewmode =Vmode; 01701 01702 // create a document and initialise 01703 pThis->pDocument = new Document(NULL); 01704 01705 01706 if(pThis->pDocument==NULL) 01707 RALPH_RETURN (RALPH_E_OUTOFMEMORY); 01708 01709 // set a horrible BOOL so that we know were a RALPH Doc 01710 pThis->pDocument->SetRalphDoc(TRUE); 01711 pThis->pDocument->ConnectRalphDocument(pThis); 01712 01713 // Try to initialise the kernel Document 01714 if (!pThis->pDocument->Init(NULL)) 01715 { 01716 // Didn't work - delete the Document object and throw an exception 01717 delete pThis->pDocument; 01718 RALPH_RETURN (RALPH_E_OUTOFMEMORY); 01719 } 01720 01721 // create a test window 01722 pThis->pRalphView = new RalphView(pThis); 01723 if(pThis->pRalphView==NULL) 01724 RALPH_RETURN (RALPH_E_OUTOFMEMORY); 01725 01726 // attach it to our kernel doc thingy 01727 ok = pThis->pRalphView->AttachKernelDoc(pThis->pDocument); 01728 if(!ok) 01729 RALPH_RETURN (RALPH_E_UNEXPECTED); 01730 01731 // create the window 01732 ok = pThis->pRalphView->Create(ParentWnd,HasBorder ? WS_BORDER : 0); 01733 01734 TRACEUSER( "Chris", _T("Create Window %s\n",ok ? "OK!!":"FAILED!!")); 01735 01736 GET_RALPH_ERROR(); 01737 01738 if(!ok) 01739 RALPH_RETURN (RALPH_E_UNEXPECTED); 01740 01741 // should we show the window now ? 01742 if(ShowWindow); 01743 pThis->pRalphView->ShowWindow(SW_SHOW); 01744 01745 // scrollers ? 01746 pThis->pRalphView->ShowScrollers(ShowScrollers); 01747 01748 pThis->hParentWnd = ParentWnd; 01749 // out put the Hwnd so that harness can do some stuff ( resize us etc..) 01750 *ViewWindow = pThis->pRalphView->GetSafeHwnd(); 01751 01752 // create a timer to enable background rendering 01753 // if(SetTimer(pThis->pRalphView->m_hWnd,CAM_TIMER_ID, CAM_TIMER_FREQUENCY,TimerProcA)==0) 01754 // RALPH_RETURN (RALPH_E_UNEXPECTED); 01755 01756 // Setup the initial view mode 01757 //pThis->SelectViewMode(Vmode); 01758 pThis->Viewmode = Vmode; 01759 01760 pThis->pDocument->SetRalphViewMode(Vmode); 01761 01762 RALPH_RETURN (S_OK); 01763 } 01764 01765 01766 /******************************************************************************************** 01767 01768 > STDMETHODIMP_ (BOOL) RalphDocument::XCreation::LoadDocument(TCHAR * pFileToLoad) 01769 01770 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 01771 Created: 20/4/96 01772 Purpose: Clean up the document and do a native load 01773 01774 ********************************************************************************************/ 01775 01776 STDMETHODIMP RalphDocument::XCreation::LoadDocument(TCHAR * pFileToLoad) 01777 { 01778 METHOD_PROLOGUE(RalphDocument, Creation) 01779 01780 if(pFileToLoad || pThis->pDocument || pThis->pRalphView) 01781 { 01782 // Little bit of niceness to handle async and sync loads at the same time... 01783 DWORD we = 0; 01784 MSG m_msgCur; 01785 do 01786 { 01787 // pump message, but break on WM_QUIT 01788 while(::GetCurrentThreadId() && ::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE)) 01789 { 01790 AfxGetApp()->PumpMessage(); 01791 } 01792 01793 // wait for a "safe to enter" or an "abort" event 01794 we = WaitForMultipleObjects(2,RalphDocument::WakeEvents,FALSE,1); 01795 01796 // Bad in render xar file and drop a cmx file situations... 01797 /*if(we == WAIT_OBJECT_0) 01798 { 01799 RALPH_RETURN (E_FAIL); 01800 }*/ 01801 } while(we == WAIT_TIMEOUT); 01802 } 01803 01804 START_RALPH_METHOD() 01805 01806 if(pFileToLoad==NULL) 01807 RALPH_RETURN (E_FAIL); 01808 if(pThis->pDocument==NULL) 01809 RALPH_RETURN (E_FAIL); 01810 if(pThis->pRalphView==NULL) 01811 RALPH_RETURN (E_FAIL); 01812 01813 // it would be nice to reinit the document here !! 01814 //pDocument->SetCurrent(); 01815 //pDocument->ReInit(); 01816 01817 //AfxDebugBreak(); 01818 01819 pThis->pDocument->SetCurrent(); 01820 01821 // make it the selected view 01822 Document::SetSelectedViewAndSpread(pThis->pDocument, pThis->pRalphView->GetDocViewPtr(), NULL); 01823 01824 // TESTING 01825 pThis->pRalphView->ShowWindow(SW_SHOW); 01826 01827 // Make sure these point to this doc and this view. 01828 if (pThis->pDocument->GetFirstDocView() != NULL) 01829 pThis->pDocument->GetFirstDocView()->SetCurrent(); 01830 01831 // Tell the Doc we are not importing the file 01832 pThis->pDocument->SetIsImporting(FALSE); 01833 01834 // do a busy cursor 01835 HCURSOR hWaitCurs = LoadCursor(NULL,_R(IDC_WAIT)); 01836 HCURSOR hOldCurs = SetCursor(hWaitCurs); 01837 01838 //BOOL IsImportOK = TRUE; 01839 01840 // Do the load. 01841 // CCDiskFile file(PathName(pFileToLoad), ios::in | ios::binary); 01842 CCDiskFile file(1024, FALSE, TRUE); 01843 01844 TRY 01845 { 01846 // Open the xxx.pfm file 01847 pThis->IsImportOK = file.open(PathName(pFileToLoad), ios::in | ios::nocreate | ios::binary); 01848 } 01849 CATCH(CFileException, e) 01850 { 01851 Error::ClearError(); 01852 pThis->IsImportOK = FALSE; 01853 } 01854 END_CATCH 01855 01856 if(pThis->IsImportOK) 01857 { 01858 // ERROR3_PF(("RalphDoc::LoadDocument suceeded with '%s' to load", pFileToLoad)); 01859 pThis->IsImportOK = InvokeNativeFileOp(OPTOKEN_NATIVELOAD, &file, FILTERID_GENERIC); 01860 } 01861 01862 if(pThis->pRalphView) 01863 pThis->pRalphView->SetSafeToDraw(pThis->IsImportOK); 01864 01865 // set the cursor back 01866 SetCursor(hOldCurs); 01867 01868 // Set the flag back to its default value 01869 if (pThis->pDocument!=NULL) 01870 pThis->pDocument->SetIsImporting(TRUE); 01871 01872 // See if the Import worked OK 01873 if (!pThis->IsImportOK) 01874 { 01875 TRACE( _T("SetEventA %d\n"), ::GetCurrentThreadId()); 01876 if(pThis->pRalphView) 01877 pThis->pRalphView->Invalidate(); 01878 SetEvent(RalphDocument::g_hSafeToEnterLoad); 01879 RALPH_RETURN (E_FAIL); 01880 } 01881 01882 // TESTING 01883 //pThis->pRalphView->ShowWindow(SW_SHOW); 01884 01885 // Document::SetSelectedViewAndSpread(pThis->pDocument, NULL, NULL); 01886 01887 pThis->pDocument->SetCurrent(); 01888 Document::SetSelectedViewAndSpread(pThis->pDocument, pThis->pRalphView->GetDocViewPtr(), NULL); 01889 01890 // Setup the initial view mode 01891 if(pThis->Viewmode!=DEFER_SETTINGVIEW) 01892 pThis->SelectViewMode(pThis->Viewmode); 01893 01894 // Were ready to render 01895 pThis->pDocument->GetSafeRenderPointer().SetPointerInValid(); 01896 01897 TRACE( _T("SetEventB %d\n"), ::GetCurrentThreadId()); 01898 SetEvent(RalphDocument::g_hSafeToEnterLoad); 01899 01900 GET_RALPH_ERROR(); 01901 RALPH_RETURN (S_OK); 01902 } 01903 01904 01905 01906 01907 /******************************************************************************************** 01908 01909 > STDMETHODIMP_ (BOOL) RalphDocument::XCreation::RenderToDC(HDC TheDC, DWORD X, 01910 DWORD Y, DWORD Width, DWORD Height, DWORD DPI) 01911 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 01912 Created: 20/8/96 01913 Purpose: Render the current document to the given HDC 01914 01915 ********************************************************************************************/ 01916 STDMETHODIMP RalphDocument::XCreation::RenderToDC(HDC hDC, DWORD X, DWORD Y, 01917 DWORD Width, DWORD Height, DWORD DPI) 01918 { 01919 METHOD_PROLOGUE(RalphDocument, Creation) 01920 START_RALPH_METHOD() 01921 01922 pThis->PrintRalphView(hDC, X, Y, Width, Height, DPI); 01923 01924 GET_RALPH_ERROR(); 01925 RALPH_RETURN (S_OK); 01926 } 01927 01928 01929 /******************************************************************************************** 01930 01931 > STDMETHODIMP_ BOOL RalphDocument::XCreation::AddRef() 01932 01933 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 01934 Created: 13/06/96 01935 Purpose: IRalphDocument's AddRef implementation 01936 ********************************************************************************************/ 01937 01938 01939 STDMETHODIMP_(UINT32) RalphDocument::XCreation::AddRef() 01940 { 01941 METHOD_PROLOGUE(RalphDocument, Creation) 01942 01943 return pThis->ExternalAddRef(); 01944 } 01945 01946 /******************************************************************************************** 01947 01948 > STDMETHODIMP_ BOOL RalphDocument::XCreation::Release() 01949 01950 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 01951 Created: 13/06/96 01952 Purpose: IRalphDocument's Release implementation 01953 ********************************************************************************************/ 01954 01955 01956 STDMETHODIMP_(UINT32) RalphDocument::XCreation::Release() 01957 { 01958 METHOD_PROLOGUE(RalphDocument, Creation) 01959 01960 return pThis->ExternalRelease(); 01961 } 01962 01963 /******************************************************************************************** 01964 01965 > STDMETHODIMP_ BOOL RalphDocument::XCreation::QueryInterface() 01966 01967 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 01968 Created: 13/06/96 01969 Purpose: IRalphDocument's QueryInterface implementation 01970 ********************************************************************************************/ 01971 01972 STDMETHODIMP RalphDocument::XCreation::QueryInterface( 01973 REFIID iid, LPVOID* ppvObj) 01974 { 01975 METHOD_PROLOGUE(RalphDocument, Creation) 01976 01977 return pThis->ExternalQueryInterface(&iid, ppvObj); 01978 } 01979 01980 01981 //******************************************************************************************* 01982 // ******************* Command Control ****************************************************** 01983 //******************************************************************************************* 01984 01985 /******************************************************************************************** 01986 01987 > STDMETHODIMP_ BOOL RalphDocument::XCommandControl::SetToolMode 01988 ( ToolMode toolmode) 01989 01990 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 01991 Created: 30/06/96 01992 Purpose: ICommandControl SetToolmode implementation 01993 ********************************************************************************************/ 01994 01995 STDMETHODIMP RalphDocument::XCommandControl::SetToolMode( 01996 ToolMode toolmode) 01997 { 01998 METHOD_PROLOGUE(RalphDocument, CommandControl) 01999 START_RALPH_METHOD() 02000 02001 pThis->Toolmode = toolmode; 02002 02003 if(pThis->SelectTool(toolmode)==FALSE) 02004 RALPH_RETURN (E_FAIL); 02005 02006 GET_RALPH_ERROR(); 02007 02008 RALPH_RETURN (S_OK); 02009 02010 } 02011 02012 02013 /******************************************************************************************** 02014 02015 > STDMETHODIMP_ BOOL RalphDocument::XCommandControl::PreviousZoom() 02016 02017 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02018 Created: 30/06/96 02019 Purpose: ICommandControl PreviousZoom implementation - just call the op 02020 ********************************************************************************************/ 02021 02022 STDMETHODIMP RalphDocument::XCommandControl::PreviousZoom() 02023 { 02024 METHOD_PROLOGUE(RalphDocument, CommandControl) 02025 START_RALPH_METHOD() 02026 02027 OpZoomDescriptor::FakeInvoke(OPTOKEN_ZOOMPREV); 02028 02029 GET_RALPH_ERROR(); 02030 02031 RALPH_RETURN (S_OK); 02032 } 02033 02034 /******************************************************************************************** 02035 02036 > STDMETHODIMP_ BOOL RalphDocument::XCommandControl::ZoomToDrawing() 02037 02038 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02039 Created: 30/06/96 02040 Purpose: ICommandControl ZommToDrawing implementation - just call the op 02041 ********************************************************************************************/ 02042 02043 STDMETHODIMP RalphDocument::XCommandControl::ZoomToDrawing() 02044 { 02045 METHOD_PROLOGUE(RalphDocument, CommandControl) 02046 START_RALPH_METHOD() 02047 02048 // To enable ZoomToFit during async downloading we will 02049 // zoom to the stored viewport rectangle 02050 // if the standard ZOOMDRAWING is used we zoom to a random rectangle 02051 // according to the state of the tree 02052 DocRect* ViewportRect = pThis->GetViewportRect() ; 02053 RalphView * pRalphView = pThis->GetRalphView(); 02054 if(!ViewportRect->IsEmpty() && pRalphView) 02055 { 02056 SendMessage(pRalphView->GetSafeHwnd(),WM_ZOOMTORECT,NULL,(INT32)(ViewportRect)); 02057 } 02058 else 02059 { 02060 OpZoomDescriptor::FakeInvoke(OPTOKEN_ZOOMDRAWING); 02061 } 02062 02063 GET_RALPH_ERROR(); 02064 02065 RALPH_RETURN (S_OK); 02066 } 02067 02068 /******************************************************************************************** 02069 02070 > STDMETHODIMP_ BOOL RalphDocument::XCommandControl::ZoomToFullScale() 02071 02072 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02073 Created: 30/06/96 02074 Purpose: ICommandControl ZoomToFullScale implementation 02075 ********************************************************************************************/ 02076 02077 STDMETHODIMP RalphDocument::XCommandControl::ZoomToFullScale() 02078 { 02079 METHOD_PROLOGUE(RalphDocument, CommandControl) 02080 START_RALPH_METHOD() 02081 02082 // this will set the scale to 100% and reset the origin 02083 pThis->ZoomToFullScale(); 02084 GET_RALPH_ERROR(); 02085 02086 RALPH_RETURN (S_OK); 02087 } 02088 02089 02090 /******************************************************************************************** 02091 02092 > STDMETHODIMP_ BOOL RalphDocument::XCommandControl::SetQuality(QualityLevel Quality) 02093 02094 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02095 Created: 30/06/96 02096 Purpose: ICommandControl SetQualityLevel implementation - set the render quality for 02097 this document 02098 ********************************************************************************************/ 02099 02100 STDMETHODIMP RalphDocument::XCommandControl::SetQuality(QualityLevel Quality) 02101 { 02102 METHOD_PROLOGUE(RalphDocument, CommandControl) 02103 START_RALPH_METHOD() 02104 02105 pThis->Quality = Quality; 02106 02107 INT32 ViewQuality = QUALITY_LEVEL_ANTI; 02108 02109 // translate our QualityLevel enum into a value that Camelot understands 02110 switch(Quality) 02111 { 02112 case ANTI_ALIASED: 02113 ViewQuality = QUALITY_LEVEL_ANTI; 02114 break; 02115 case NORMAL: 02116 ViewQuality = QUALITY_LEVEL_NORMAL; 02117 break; 02118 case SIMPLE: 02119 ViewQuality = QUALITY_LEVEL_SIMPLE; 02120 break; 02121 case OUTLINE: 02122 ViewQuality = QUALITY_LEVEL_OUTLINE; 02123 } 02124 02125 02126 02127 02128 // Set the render quality on this doc 02129 if(pThis->SelectViewQuality(ViewQuality)==FALSE) 02130 RALPH_RETURN(E_FAIL); 02131 02132 GET_RALPH_ERROR(); 02133 RALPH_RETURN(S_OK); 02134 02135 } 02136 02137 /******************************************************************************************** 02138 02139 > STDMETHODIMP_ BOOL RalphDocument::XCommandControl::SetQuality(QualityLevel Quality) 02140 02141 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02142 Created: 30/06/96 02143 Purpose: ICommandControl SetQualityLevel implementation - set the render quality for 02144 this document 02145 ********************************************************************************************/ 02146 02147 STDMETHODIMP RalphDocument::XCommandControl::SetURL(CString InURL) 02148 { 02149 METHOD_PROLOGUE(RalphDocument, CommandControl) 02150 START_RALPH_METHOD() 02151 02152 pThis->DocumentURL = InURL; 02153 02154 // pThis->Quality = Quality; 02155 02156 // if(pThis->SelectViewQuality(ViewQuality)==FALSE) 02157 // RALPH_RETURN(E_FAIL); 02158 02159 // GET_RALPH_ERROR(); 02160 RALPH_RETURN(S_OK); 02161 02162 } 02163 02164 /******************************************************************************************** 02165 02166 > STDMETHODIMP_ BOOL RalphDocument::XCommandControl::SetDitherType(DitherType ) 02167 02168 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02169 Created: 30/06/96 02170 Purpose: ICommandControl SetDitherType implementation 02171 ********************************************************************************************/ 02172 02173 STDMETHODIMP RalphDocument::XCommandControl::SetDitherType(DitherType Dither) 02174 { 02175 02176 METHOD_PROLOGUE(RalphDocument, CommandControl) 02177 START_RALPH_METHOD() ; 02178 02179 if(pThis->SelectDitherType( Dither )==FALSE) 02180 RALPH_RETURN(E_FAIL); 02181 02182 GET_RALPH_ERROR(); 02183 02184 RALPH_RETURN(S_OK); 02185 } 02186 02187 02188 /******************************************************************************************** 02189 02190 > STDMETHODIMP_ BOOL RalphDocument::XCommandControl::SetPaletteMode(BOOL Foreground) 02191 02192 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 02193 Created: 1/8/96 02194 Purpose: ICommandControl SetPaletteMode implementation 02195 (Plugins rely on their hosts to setup fabby palettes, so should use 02196 background palettes. Quickviewers should do their own palettes, so 02197 should call this with Foreground = TRUE) 02198 ********************************************************************************************/ 02199 02200 STDMETHODIMP RalphDocument::XCommandControl::SetPaletteMode(BOOL Foreground) 02201 { 02202 METHOD_PROLOGUE(RalphDocument, CommandControl) 02203 START_RALPH_METHOD() ; 02204 02205 pThis->SelectPaletteMode(Foreground); 02206 02207 GET_RALPH_ERROR(); 02208 02209 RALPH_RETURN(S_OK); 02210 } 02211 02212 02213 /******************************************************************************************** 02214 02215 > STDMETHODIMP_ BOOL RalphDocument::XCommandControl::AddRef() 02216 02217 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02218 Created: 13/06/96 02219 Purpose: ICommandControl's AddRef implementation 02220 ********************************************************************************************/ 02221 02222 02223 STDMETHODIMP_(UINT32) RalphDocument::XCommandControl::AddRef() 02224 { 02225 METHOD_PROLOGUE(RalphDocument, CommandControl) 02226 02227 return pThis->ExternalAddRef(); 02228 } 02229 02230 /******************************************************************************************** 02231 02232 > STDMETHODIMP_ BOOL RalphDocument::XCommandControl::Release() 02233 02234 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02235 Created: 13/06/96 02236 Purpose: ICommandControl's Release implementation 02237 ********************************************************************************************/ 02238 02239 02240 STDMETHODIMP_(UINT32) RalphDocument::XCommandControl::Release() 02241 { 02242 METHOD_PROLOGUE(RalphDocument, CommandControl) 02243 return pThis->ExternalRelease(); 02244 } 02245 02246 /******************************************************************************************** 02247 02248 > STDMETHODIMP_ BOOL RalphDocument::XCommandControl::QueryInterface() 02249 02250 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02251 Created: 13/06/96 02252 Purpose: ICommandControl's QueryInterface implementation 02253 ********************************************************************************************/ 02254 02255 STDMETHODIMP RalphDocument::XCommandControl::QueryInterface( 02256 REFIID iid, LPVOID* ppvObj) 02257 { 02258 METHOD_PROLOGUE(RalphDocument, CommandControl) 02259 return pThis->ExternalQueryInterface(&iid, ppvObj); 02260 } 02261 02262 02263 /******************************************************************************************** 02264 02265 > STDMETHODIMP RalphDocument::XCommandControl::HasPreviousZoom() 02266 02267 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02268 Created: 13/06/96 02269 Purpose: ICommandControl's HasPreviousZoom implementation 02270 ********************************************************************************************/ 02271 STDMETHODIMP RalphDocument::XCommandControl::HasPreviousZoom() 02272 { 02273 METHOD_PROLOGUE(RalphDocument, CommandControl) 02274 START_RALPH_METHOD() 02275 HRESULT hr =S_FALSE; 02276 DocView * pDocView = pThis->pRalphView->GetDocViewPtr(); 02277 02278 if(pDocView==NULL) 02279 RALPH_RETURN(E_FAIL); 02280 02281 if((pDocView != NULL && pDocView->GetPrevZoomIndex() != cUninitZoomIndex)==FALSE) 02282 hr=S_OK; 02283 02284 RALPH_RETURN(hr); 02285 02286 } 02287 02288 //******************************************************************************************* 02289 // ******************* View Control ********************************************************* 02290 //******************************************************************************************* 02291 02292 /******************************************************************************************** 02293 02294 > STDMETHODIMP_ BOOL RalphDocument::XViewControl::AddRef() 02295 02296 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02297 Created: 13/06/96 02298 Purpose: IViewControl's AddRef implementation 02299 ********************************************************************************************/ 02300 02301 02302 STDMETHODIMP_(UINT32) RalphDocument::XViewControl::AddRef() 02303 { 02304 METHOD_PROLOGUE(RalphDocument, ViewControl) 02305 02306 return pThis->ExternalAddRef(); 02307 } 02308 02309 /******************************************************************************************** 02310 02311 > STDMETHODIMP_ BOOL RalphDocument::XViewControl::Release() 02312 02313 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02314 Created: 13/06/96 02315 Purpose: IViewControl's Release implementation 02316 ********************************************************************************************/ 02317 02318 02319 STDMETHODIMP_(UINT32) RalphDocument::XViewControl::Release() 02320 { 02321 METHOD_PROLOGUE(RalphDocument, ViewControl) 02322 return pThis->ExternalRelease(); 02323 } 02324 02325 /******************************************************************************************** 02326 02327 > STDMETHODIMP_ BOOL RalphDocument::XViewControl::QueryInterface() 02328 02329 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02330 Created: 13/06/96 02331 Purpose: IViewControl's QueryInterface implementation 02332 ********************************************************************************************/ 02333 02334 STDMETHODIMP RalphDocument::XViewControl::QueryInterface( 02335 REFIID iid, LPVOID* ppvObj) 02336 { 02337 METHOD_PROLOGUE(RalphDocument, ViewControl) 02338 return pThis->ExternalQueryInterface(&iid, ppvObj); 02339 } 02340 02341 /******************************************************************************************** 02342 02343 > STDMETHODIMP RalphDocument::XViewControl::ShowScrollers(BOOL state) 02344 02345 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02346 Created: 30/06/96 02347 Purpose: IViewControl ShowScrollers implementation - just show/hide the scrollers 02348 ********************************************************************************************/ 02349 02350 STDMETHODIMP RalphDocument::XViewControl::ShowScrollers(BOOL state) 02351 { 02352 METHOD_PROLOGUE(RalphDocument, ViewControl) 02353 START_RALPH_METHOD(); 02354 02355 if( pThis->pRalphView == NULL) 02356 RALPH_RETURN(E_FAIL); 02357 02358 pThis->pRalphView->ShowScrollers(state); 02359 02360 GET_RALPH_ERROR(); 02361 RALPH_RETURN(S_OK); 02362 } 02363 02364 /******************************************************************************************** 02365 02366 > STDMETHODIMP RalphDocument::XViewControl::SetViewMode(ViewMode Viewmode) 02367 02368 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02369 Created: 30/06/96 02370 Purpose: IViewControl SetViewMode - PAGE_VIEW,DOCUMENT_VIEW or DRAWING_VIEW 02371 ********************************************************************************************/ 02372 02373 STDMETHODIMP RalphDocument::XViewControl::SetViewMode(ViewMode Viewmode) 02374 { 02375 METHOD_PROLOGUE(RalphDocument, ViewControl) 02376 START_RALPH_METHOD() 02377 02378 if(pThis->SelectViewMode(Viewmode)==FALSE) 02379 RALPH_RETURN(E_FAIL); 02380 02381 RALPH_RETURN(S_OK); 02382 02383 } 02384 02385 02386 //******************************************************************************************* 02387 // ******************* InitRalph ***************************************************** 02388 //******************************************************************************************* 02389 02390 /******************************************************************************************** 02391 02392 > STDMETHODIMP RalphDocument::XInitRalphk::AddRef() 02393 02394 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02395 Created: 13/06/96 02396 Purpose: IInitRalph's AddRef implementation 02397 ********************************************************************************************/ 02398 02399 02400 STDMETHODIMP_(UINT32) RalphDocument::XInitRalph::AddRef() 02401 { 02402 METHOD_PROLOGUE(RalphDocument,InitRalph) 02403 02404 return pThis->ExternalAddRef(); 02405 } 02406 02407 /******************************************************************************************** 02408 02409 > STDMETHODIMP RalphDocument::XInitRalph::Release() 02410 02411 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02412 Created: 13/06/96 02413 Purpose: IInitRalph's Release implementation 02414 ********************************************************************************************/ 02415 02416 02417 STDMETHODIMP_(UINT32) RalphDocument::XInitRalph::Release() 02418 { 02419 METHOD_PROLOGUE(RalphDocument, InitRalph) 02420 return pThis->ExternalRelease(); 02421 } 02422 02423 /******************************************************************************************** 02424 02425 > STDMETHODIMP RalphDocument::XInitRalph::QueryInterface() 02426 02427 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02428 Created: 13/06/96 02429 Purpose: IInitRalph's QueryInterface implementation 02430 ********************************************************************************************/ 02431 02432 STDMETHODIMP RalphDocument::XInitRalph::QueryInterface( 02433 REFIID iid, LPVOID* ppvObj) 02434 { 02435 METHOD_PROLOGUE(RalphDocument, InitRalph) 02436 return pThis->ExternalQueryInterface(&iid, ppvObj); 02437 } 02438 02439 /******************************************************************************************** 02440 02441 > STDMETHODIMP RalphDocument::XInitRalph::SetErrorCallback 02442 ( IErrorCallback* pCallbackInterface) 02443 02444 02445 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02446 Created: 13/06/96 02447 Purpose: IInitRalph SetErroCallback implementation 02448 ********************************************************************************************/ 02449 02450 STDMETHODIMP RalphDocument::XInitRalph::SetErrorCallback( 02451 IErrorCallback* pCallbackInterface) 02452 { 02453 METHOD_PROLOGUE(RalphDocument, InitRalph) 02454 START_RALPH_METHOD() 02455 02456 pThis->pIErrorCallback = pCallbackInterface; 02457 // pThis->pIErrorCallback->AddRef(); 02458 02459 RALPH_RETURN(S_OK); 02460 } 02461 02462 02463 02464 //******************************************************************************************* 02465 // ******************* AsynchDownLoad ***************************************************** 02466 //******************************************************************************************* 02467 02468 /******************************************************************************************** 02469 02470 > STDMETHODIMP RalphDocument::XAsynchDownLoad::AddRef() 02471 02472 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02473 Created: 13/06/96 02474 Purpose: IInitRalph's AddRef implementation 02475 ********************************************************************************************/ 02476 02477 02478 STDMETHODIMP_(UINT32) RalphDocument::XAsynchDownLoad::AddRef() 02479 { 02480 METHOD_PROLOGUE(RalphDocument,AsynchDownLoad) 02481 02482 return pThis->ExternalAddRef(); 02483 } 02484 02485 /******************************************************************************************** 02486 02487 > STDMETHODIMP RalphDocument::XAsynchDownLoad::Release() 02488 02489 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02490 Created: 13/06/96 02491 Purpose: IInitRalph's Release implementation 02492 ********************************************************************************************/ 02493 02494 02495 STDMETHODIMP_(UINT32) RalphDocument::XAsynchDownLoad::Release() 02496 { 02497 METHOD_PROLOGUE(RalphDocument, AsynchDownLoad) 02498 return pThis->ExternalRelease(); 02499 } 02500 02501 /******************************************************************************************** 02502 02503 > STDMETHODIMP RalphDocument::XAsynchDownLoad::QueryInterface() 02504 02505 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02506 Created: 13/06/96 02507 Purpose: IInitRalph's QueryInterface implementation 02508 ********************************************************************************************/ 02509 02510 STDMETHODIMP RalphDocument::XAsynchDownLoad::QueryInterface( 02511 REFIID iid, LPVOID* ppvObj) 02512 { 02513 METHOD_PROLOGUE(RalphDocument, AsynchDownLoad) 02514 return pThis->ExternalQueryInterface(&iid, ppvObj); 02515 } 02516 02517 /* 02518 STDMETHOD(StartAsynchDownLoad) (); 02519 STDMETHOD(OnDataAvailable) (CString &Buffer); 02520 STDMETHOD(EndAsynchDownLoad) (HRESULT Status); 02521 */ 02522 /******************************************************************************************** 02523 02524 > STDMETHODIMP RalphDocument::XAsynchDownLoad::StartAsynchDownLoad() 02525 02526 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02527 Created: 13/06/96 02528 Purpose: Create the file for the download and start the thread 02529 ********************************************************************************************/ 02530 02531 STDMETHODIMP RalphDocument::XAsynchDownLoad::StartAsynchDownLoad() 02532 { 02533 METHOD_PROLOGUE(RalphDocument, AsynchDownLoad) 02534 START_RALPH_METHOD() 02535 02536 02537 if(!pThis->StartLoadThread()) 02538 RALPH_RETURN(RALPH_E_LOADFAILED); 02539 02540 RALPH_RETURN(S_OK); 02541 } 02542 02543 /******************************************************************************************** 02544 02545 > STDMETHODIMP RalphDocument::XAsynchDownLoad::OnDataAvailable) (CString &Buffer) 02546 02547 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02548 Created: 13/06/96 02549 Purpose: write the data to the asynch down load file 02550 ********************************************************************************************/ 02551 02552 STDMETHODIMP RalphDocument::XAsynchDownLoad::OnDataAvailable (unsigned char* pReadBuffer,DWORD BytesRead) 02553 { 02554 METHOD_PROLOGUE(RalphDocument, AsynchDownLoad) 02555 START_RALPH_METHOD() 02556 02557 pThis->OnDataAvailable(pReadBuffer,BytesRead); 02558 02559 RALPH_RETURN(S_OK); 02560 } 02561 02562 /******************************************************************************************** 02563 02564 > STDMETHODIMP RalphDocument::XAsynchDownLoad::EndAsynchDownLoad(HRESULT Status) 02565 02566 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 02567 Created: 13/06/96 02568 Purpose: End the download according to the status 02569 ********************************************************************************************/ 02570 02571 STDMETHODIMP RalphDocument::XAsynchDownLoad::EndAsynchDownLoad(HRESULT Status) 02572 { 02573 METHOD_PROLOGUE(RalphDocument, AsynchDownLoad) 02574 START_RALPH_METHOD() 02575 02576 if(!pThis->EndAsynchDownLoad(Status)) 02577 RALPH_RETURN(RALPH_E_LOADFAILED); 02578 02579 RALPH_RETURN(S_OK); 02580 } 02581 02582 02583 /******************************************************************************************** 02584 02585 > STDMETHODIMP RalphDocument::XInitRalph::SetEventCallback 02586 ( IEventCallback* pCallbackInterface) 02587 02588 02589 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 02590 Created: 20/08/96 02591 Inputs: pCallbackInterface: A pointer to an event callback interface 02592 Returns: S_OK ( for now) 02593 Purpose: Called to register a Harness interface to receive event notifications. 02594 ********************************************************************************************/ 02595 02596 STDMETHODIMP RalphDocument::XInitRalph::SetEventCallback( 02597 IEventCallback* pCallbackInterface) 02598 { 02599 METHOD_PROLOGUE(RalphDocument, InitRalph) 02600 START_RALPH_METHOD() 02601 pThis->pIEventCallback = pCallbackInterface; 02602 RALPH_RETURN(S_OK); 02603 } 02604 02605 02606 #endif