00001 // $Id: infobar.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 // The code to position and display the infobar. 00100 00101 00102 #include "camtypes.h" 00103 #include "mainfrm.h" 00104 //#include "tim.h" 00105 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00106 //#include "ensure.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00107 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00108 //#include "document.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00109 //#include "barsdlgs.h" 00110 #include "bubbleid.h" 00111 00112 #include <afxpriv.h> 00113 00114 #include "infobar.h" 00115 00116 DECLARE_SOURCE("$Revision: 1282 $"); 00117 00118 CC_IMPLEMENT_DYNCREATE(InfoBarOp, DialogOp) 00119 00120 const CDlgMode InfoBarOp::Mode = MODELESS; // Mode of the dialog 00121 00122 BOOL InfoBarOp::Visible = TRUE; 00123 00124 UINT32 InfoBarOp::IDD = _R(IDD_INFOBAR); 00125 00126 InfoBarOp::InfoBarOp(CDlgResID SubDialogID) : 00127 DialogOp(InfoBarOp::IDD, InfoBarOp::Mode, SubDialogID) 00128 { 00129 00130 // Not dragging the info bar intially 00131 DraggingBar = FALSE; 00132 } 00133 00134 00135 MsgResult InfoBarOp::Message( Msg* Message) 00136 { 00137 /* 00138 if (Document::GetCurrent() == NULL) 00139 // No document - can't do anything 00140 return; 00141 00142 // Process static Infobar control messages 00143 if ((Gadget == _R(IDC_INVOKE_LYR_DLG)) && (DlgMsg == DIM_LFT_BN_CLICKED)) 00144 { 00145 // Obtain a pointer to the op descriptor for the Layer dialog operation 00146 OpDescriptor* OpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(LayerDlg)); 00147 // Invoke the operation. 00148 OpDesc->Invoke(); 00149 } 00150 00151 // Process active layer selection 00152 if ((Gadget == _R(IDC_LAYER_COMBO)) && (DlgMsg == DIM_SELECTION_CHANGED)) 00153 { 00154 // Obtain the index of the selected item 00155 WORD Index; 00156 GetValueIndex(_R(IDC_LAYER_COMBO), &Index); 00157 ChangeActiveLayer(Index); 00158 } 00159 00160 if (Gadget >= _R(ID_FIRST_TOOL_CTRL)) 00161 { 00162 // Gadgets with IDs of 1000 or greater belong to the tool, not the Info bar, so 00163 // pass the message on to the tool. 00164 Tool *pTool = Tool::GetCurrent(); 00165 ENSURE(pTool != NULL, "InfoBarOp::HandleMessage - no Tool is selected!"); 00166 if (pTool != NULL) 00167 pTool->HandleInfoBarMessage(DlgMsg, Gadget); 00168 } 00169 else 00170 { 00171 #if 0 00172 // Handle the dragging of the info bar 00173 switch (DlgMsg) 00174 { 00175 case DIM_RGT_BN_DOWN: 00176 case DIM_LFT_BN_DOWN: 00177 GetCursorPos(&DragPos); 00178 SetCapture(WindowID); 00179 DraggingBar = TRUE; 00180 break; 00181 00182 case DIM_MOUSE_DRAG: 00183 if (!DraggingBar) 00184 { 00185 GetCursorPos(&DragPos); 00186 SetCapture(WindowID); 00187 DraggingBar = TRUE; 00188 return; 00189 } 00190 00191 POINT CurrPoint; 00192 GetCursorPos(&CurrPoint); 00193 ScrollWindow(WindowID, CurrPoint.x - DragPos.x, 0, NULL, NULL); 00194 DragPos = CurrPoint; 00195 break; 00196 00197 case DIM_RGT_BN_UP: 00198 case DIM_LFT_BN_UP: 00199 ReleaseCapture(); 00200 DraggingBar = FALSE; 00201 break; 00202 } 00203 #endif 00204 } 00205 */ 00206 return OK; 00207 } 00208 00209 // ----------------------------------------------------------------------------------------- 00210 00211 OpState InfoBarOp::GetState(String_256*, OpDescriptor*) 00212 { 00213 OpState OpSt; 00214 return(OpSt); 00215 } 00216 00217 // ----------------------------------------------------------------------------------------- 00218 00219 BOOL InfoBarOp::Init() 00220 { 00221 // Create the OpDescriptor for this operation class. 00222 if (!(RegisterOpDescriptor( 00223 0, 00224 _R(IDT_VIEWINFOBAR), 00225 CC_RUNTIME_CLASS(InfoBarOp), 00226 OPTOKEN_INFOBAR, 00227 InfoBarOp::GetState, 00228 0, /* help ID */ 00229 _R(IDBBL_INFOBAROP), 00230 0 /* bitmap ID */))) 00231 { 00232 return FALSE; 00233 } 00234 // Declare info bar preference. 00235 return Camelot.DeclareSection("Windows", 5) && 00236 Camelot.DeclarePref("Windows", "InfoBarIsVisible", &Visible); 00237 } 00238 00239 // ----------------------------------------------------------------------------------------- 00240 00241 BOOL InfoBarOp::Create() 00242 { 00243 return DialogOp::Create(); 00244 } 00245 00246 // ----------------------------------------------------------------------------------------- 00247 00248 void InfoBarOp::Do(OpDescriptor*) 00249 { 00250 // Just to make sure info bar is not opened until it is positioned correctly (by 00251 // InfoBarOp::OnSizeParent()). 00252 Close(); 00253 } 00254 00255 /******************************************************************************************** 00256 00257 > void InfoBarOp::OnSizeParent(WPARAM, LPARAM lParam) 00258 00259 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00260 Created: 9/11/93 00261 Inputs: WPARAM - ignored. 00262 lParam - the special MFC structure that is sent when a parent tells its 00263 child windows to resize themselves. 00264 Outputs: lParam - the structure is updated to reflect how much client area was 00265 taken by the Info Bar. 00266 Purpose: Resize the info bar when the parent window moves/resizes, or when one of 00267 the children becomes visible/invisible. 00268 00269 The WM_SIZEPARENT message is sent, which is a special AFX message (from the 00270 WM_USER address space I think). The child windows then adjust the structure 00271 passed to them to steal part of the workspace for themselves, and whatever is 00272 left over is used for the client area. 00273 00274 This is all undocumented and was deduced by looking at the MFC files 00275 WINCORE.CPP, WINFRM.CPP, BARCORE.CPP, and BARDLG.CPP. 00276 00277 ********************************************************************************************/ 00278 00279 void InfoBarOp::OnSizeParent(WPARAM, LPARAM lParam) 00280 { 00281 AFX_SIZEPARENTPARAMS FAR* lpLayout = (AFX_SIZEPARENTPARAMS FAR*)lParam; 00282 00283 if (Visible) 00284 { 00285 // Make the window zero size to avoid redraws 00286 //MoveWindow(WindowID, 0, 0, 0, 0, FALSE); 00287 00288 // Info Bar is visible - reposition it wrt parent window. 00289 CRect rect; 00290 rect.CopyRect(&lpLayout->rect); 00291 00292 CSize sizeAvail = rect.Size(); // maximum size available 00293 CSize size; // maximum requested size 00294 size.cx = min(32767, sizeAvail.cx); 00295 size.cy = min(28, sizeAvail.cy); 00296 00297 00298 // top align (stretch width) 00299 size.cx = sizeAvail.cx; 00300 lpLayout->rect.top += size.cy; 00301 00302 rect.right = rect.left + size.cx; 00303 rect.bottom = rect.top + size.cy; 00304 00305 #if _MFC_VER < 0x300 00306 _AfxRepositionWindow(lpLayout, WindowID, &rect); 00307 00308 // If the window hasn't actually been opened yet, then open it. 00309 // This deferral is necessary otherwise the window is opened before being 00310 // correctly positioned, and a portion of the document view is invalidated 00311 // and redrawn, which we definitely don't want. 00312 #if 1 00313 if (!IsWindowVisible(WindowID)) 00314 { 00315 lpLayout->hDWP = 00316 ::DeferWindowPos(lpLayout->hDWP, WindowID, NULL, 0, 0, 0, 0, 00317 SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE| 00318 SWP_SHOWWINDOW); 00319 } 00320 #endif 00321 #else 00322 lpLayout->hDWP = ::DeferWindowPos(lpLayout->hDWP, WindowID, NULL, 00323 rect.left, rect.top, 00324 rect.right - rect.left, rect.bottom - rect.top, 00325 SWP_NOACTIVATE|SWP_NOZORDER|SWP_SHOWWINDOW); 00326 #endif 00327 } 00328 } 00329 00330 00331 /******************************************************************************************** 00332 00333 > void InfoBarOp::Toggle() 00334 00335 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00336 Created: 9/11/93 00337 Purpose: Toggle the Info Bar on or off (i.e. make it invisible or visible). 00338 00339 ********************************************************************************************/ 00340 00341 void InfoBarOp::Toggle() 00342 { 00343 // Work out whether to open or close the info bar, and do so. 00344 // (Also update preference variable) 00345 if (IsOpen()) 00346 { 00347 Close(); 00348 Visible = FALSE; 00349 } 00350 else 00351 { 00352 Open(); 00353 Visible = TRUE; 00354 } 00355 00356 // Find the main frame, and force the child windows to be repositioned/redrawn. 00357 CMainFrame *pFrame = (CMainFrame *) AfxGetApp()->m_pMainWnd; 00358 pFrame->RecalcLayout(); 00359 } 00360 00361 /******************************************************************************************** 00362 00363 > void InfoBarOp::NewCurrentSpread() 00364 00365 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00366 Created: 10/1/94 00367 Inputs: - 00368 Outputs: - 00369 Returns: - 00370 Purpose: This function gets called by the LayerManager when the Current Spread is 00371 changing. 00372 Errors: - 00373 SeeAlso: - 00374 00375 ********************************************************************************************/ 00376 00377 void InfoBarOp::NewCurrentSpread() 00378 { 00379 ENSURE(FALSE,"This function should not be called"); 00380 /* 00381 GadgetRedraw(_R(IDC_LAYER_COMBO),FALSE); // Turn off drawing until we have finished making changes 00382 // to the gadget. 00383 // Delete any existing list items 00384 INT32 Count; 00385 GetValueCount(_R(IDC_LAYER_COMBO),&Count); 00386 while (Count != 0) 00387 { 00388 DeleteValue(_R(IDC_LAYER_COMBO), FALSE, Count-1); 00389 Count--; 00390 } 00391 00392 WORD SelItemIndex = 0; // The list index of the selected item (i.e. the active layer) 00393 WORD i = 0; 00394 00395 BOOL FoundActiveLayer = FALSE; 00396 00397 // Traverse the Layer Manager's LyrDetList and add all layer identifiers to the list gadget 00398 List* LyrList = &((Document::GetCurrent()->GetLayerMgr()).LyrDetList); 00399 ListItem* CurLayerDet = LyrList->GetHead(); 00400 ENSURE(CurLayerDet != NULL, "The LyrDetList is empty"); 00401 while (CurLayerDet != NULL) 00402 { 00403 // Is the current layer the active layer ? 00404 if ( ((LyrDetails*)CurLayerDet)->Status.Flags.Active ) 00405 { 00406 // Ensure that there is only one active layer 00407 ENSURE (!FoundActiveLayer, "More than one active layer found"); 00408 FoundActiveLayer = TRUE; 00409 SelItemIndex = i; 00410 } 00411 // Add string to end of list box 00412 SetStringGadgetValue(_R(IDC_LAYER_COMBO),&(((LyrDetails*)CurLayerDet)->Status.StringLayerID)); 00413 00414 CurLayerDet = LyrList->GetNext(CurLayerDet); 00415 i++; 00416 } 00417 00418 ENSURE(FoundActiveLayer,"No active layer was found"); 00419 00420 GadgetRedraw(_R(IDC_LAYER_COMBO),TRUE); // Turn drawing back on 00421 00422 SetSelectedValueIndex(_R(IDC_LAYER_COMBO), SelItemIndex); // Select the active layer 00423 */ 00424 } 00425 00426 /******************************************************************************************** 00427 00428 > void InfoBarOp::DisableLayerList() 00429 00430 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00431 Created: 17/1/94 00432 Inputs: - 00433 Outputs: - 00434 Returns: - 00435 Purpose: Disables the layer control 00436 Errors: - 00437 SeeAlso: - 00438 00439 ********************************************************************************************/ 00440 00441 void InfoBarOp::DisableLayerControl() 00442 { 00443 EnableGadget(_R(IDC_LAYER_COMBO), FALSE ); 00444 EnableGadget(_R(IDC_INVOKE_LYR_DLG), FALSE); 00445 } 00446 00447 /******************************************************************************************** 00448 00449 > void InfoBarOp::EnableLayerControl() 00450 00451 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00452 Created: 17/1/94 00453 Inputs: - 00454 Outputs: - 00455 Returns: - 00456 Purpose: Enables the layer control 00457 Errors: - 00458 SeeAlso: - 00459 00460 ********************************************************************************************/ 00461 00462 void InfoBarOp::EnableLayerControl() 00463 { 00464 EnableGadget(_R(IDC_LAYER_COMBO), TRUE ); 00465 EnableGadget(_R(IDC_INVOKE_LYR_DLG), TRUE ); 00466 } 00467 00468 /******************************************************************************************** 00469 00470 > void InfoBarOp::ChangeActiveLayer(WORD NewLayerIndex) 00471 00472 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00473 Created: 11/1/94 00474 Inputs: NewLayerIndex: z-order Index of the new active layer. 00475 Outputs: - 00476 Returns: - 00477 Purpose: Changes the active layer 00478 Errors: - 00479 SeeAlso: - 00480 00481 ********************************************************************************************/ 00482 00483 void InfoBarOp::ChangeActiveLayer(WORD NewLayerIndex) 00484 { 00485 ENSURE(FALSE,"This function should not be called"); 00486 /* 00487 INT32 CurrentIndex = 0; 00488 // Traverse the Layer Manager's LyrDetList 00489 List* LyrList = &((Document::GetCurrent()->GetLayerMgr()).LyrDetList); 00490 ListItem* CurLayerDet = LyrList->GetHead(); 00491 ENSURE(CurLayerDet != NULL, "The LyrDetList is empty"); 00492 while (CurLayerDet != NULL) 00493 { 00494 if (CurrentIndex == NewLayerIndex) 00495 { 00496 // We have found the layer to make active 00497 ((LyrDetails*)CurLayerDet)->Status.Flags.Active = TRUE; 00498 } 00499 else if ( ((LyrDetails*)CurLayerDet)->Status.Flags.Active ) 00500 { 00501 // We have found the old active layer 00502 ((LyrDetails*)CurLayerDet)->Status.Flags.Active = FALSE; 00503 } 00504 CurLayerDet = LyrList->GetNext(CurLayerDet); // Get next layer detail record 00505 CurrentIndex ++; 00506 } 00507 00508 // Commit the changes 00509 (Document::GetCurrent()->GetLayerMgr()).CommitLayerChanges(); 00510 */ 00511 } 00512 00513 00514 CC_IMPLEMENT_DYNCREATE(InfoBarViewOp, Operation) 00515 00516 /******************************************************************************************** 00517 00518 > BOOL InfoBarViewOp::Init() 00519 00520 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00521 Created: 15/10/93 00522 Returns: TRUE if worked, FALSE if failed (out of memory) 00523 Purpose: Declares op descriptor for toggling info bar.. 00524 Errors: Returns FALSE on failure. 00525 Scope: Static 00526 00527 ********************************************************************************************/ 00528 00529 BOOL InfoBarViewOp::Init() 00530 { 00531 return (RegisterOpDescriptor( 00532 0, 00533 _R(IDT_VIEWINFOBAR), 00534 CC_RUNTIME_CLASS(InfoBarViewOp), 00535 OPTOKEN_VIEWINFOBAR, 00536 GetState, 00537 0, /* help ID */ 00538 _R(IDBBL_VIEWINFOBAROP), 00539 0 /* bitmap ID */)); 00540 } 00541 00542 /******************************************************************************************** 00543 00544 > void InfoBarViewOp::Do(OpDescriptor*) 00545 00546 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00547 Created: 15/10/93 00548 Purpose: Toggles the info bar. 00549 00550 ********************************************************************************************/ 00551 00552 void InfoBarViewOp::Do(OpDescriptor*) 00553 { 00554 // Tell the main window to toggle the info bar. 00555 CMainFrame::pInfoBar->Toggle(); 00556 00557 // This operation is now finished 00558 End(); 00559 } 00560 00561 /******************************************************************************************** 00562 00563 > InfoBarViewOp::InfoBarViewOp() 00564 00565 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00566 Created: 15/10/93 00567 Purpose: Constructor for InfoBarViewOp operation. It is not undoable. 00568 00569 ********************************************************************************************/ 00570 00571 InfoBarViewOp::InfoBarViewOp() 00572 { 00573 } 00574 00575 00576 00577 /******************************************************************************************** 00578 00579 > OpState InfoBarViewOp::GetState(String_256*, OpDescriptor*) 00580 00581 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00582 Created: 15/10/93 00583 Purpose: This item is always available, so long as a document is visible. 00584 It is ticked if the info bar is visible. 00585 00586 ********************************************************************************************/ 00587 00588 OpState InfoBarViewOp::GetState(String_256*, OpDescriptor*) 00589 { 00590 // Tick the item if the info bar is visible 00591 OpState OpSt(CMainFrame::pInfoBar->IsOpen()); 00592 00593 return OpSt; 00594 } 00595