00001 // $Id: ccolbar.cpp 1528 2006-07-25 13:43:14Z gerry $ 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 // CColBar.cpp - implementation of the CColourBar class 00099 00100 /* 00101 */ 00102 00103 00104 /* IMPORTANT NOTE! 00105 * =============== 00106 * 00107 * When working on the Colour Bar, it is VITAL that you remember that it 00108 * differs from much of Camelot in that it works exclusively on the 00109 * SelectedDocument (rather than CurrentDocument). 00110 * Thus, you need to be careful to ensure that Current == Selected if you 00111 * add any subroutine calls, or else you may shaft everything. 00112 */ 00113 00114 00115 00116 #include "camtypes.h" 00117 00118 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00119 //#include "attrmgr.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00120 #include "camelot.h" 00121 #include "ccolbar.h" 00122 #include "colcontx.h" 00123 #include "coldlog.h" 00124 #include "colmsg.h" 00125 #include "colormgr.h" 00126 #include "colourix.h" 00127 #include "colpick.h" 00128 #include "comattrmsg.h" 00129 //#include "cursor.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00130 //#include "ctrlhelp.h" 00131 #include "devcolor.h" 00132 //#include "doccolor.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00133 //#include "document.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00134 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00135 #include "dragmgr.h" 00136 //#include "galres.h" // For drag cursors 00137 //#include "ink.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00138 //#include "jason.h" 00139 #include "keypress.h" 00140 #include "lineattr.h" 00141 #include "linwthop.h" 00142 #include "camframe.h" 00143 #include "opgrad.h" 00144 #include "palman.h" 00145 //#include "range.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00146 //#include "resource.h" // For push tool cursor 00147 #include "sgcolour.h" // For AutoScroll preference 00148 #include "statline.h" 00149 #include "cartprov.h" 00150 00151 // define this to disable use of DragManagerOp to drag colours 00152 //#define DISABLE_COLOUR_DRAGS 00153 00154 // --------- **** 00155 // DocColours (doccolor.h) currently provide a special debugging form of MakeRef... 00156 // that trace usage of indexedcolours back to the file/line where they were first 00157 // referenced. However, the colourbar creates many temp. ref.s during redraws, 00158 // so we disable this debugging stuff for this file. This is fairly safe, as we 00159 // are reasonably sure that the colour bar treats IndexedColours with proper respect. 00160 #undef MakeRefToIndexedColour 00161 // --------- 00162 00163 00164 // Default preference styles for the colour bar (size of strip cells and scrollbar) 00165 // Note that the Create function reads the preference and clips it to 0..MAXDEFAULTSIZES range 00166 typedef struct 00167 { 00168 INT32 Cell; 00169 INT32 Scrollbar; 00170 } ColBarDefaultSizeInfo; 00171 00172 const INT32 MAXDEFAULTSIZES = 4; 00173 ColBarDefaultSizeInfo ColBarDefaultSize[MAXDEFAULTSIZES] = 00174 { 00175 {12, 0}, // Small (no scroll bar) 00176 {16, 0}, // Medium (no scroll bar) 00177 {16, 9}, // Medium 00178 {24, 11} // Large 00179 }; 00180 00181 00182 /******************************************************************************************** 00183 00184 Preference: ColourBarMode 00185 Section: Displays 00186 Range: 0..3 00187 Purpose: Specifies the 'size' at which the colour bar is displayed, with 00188 values of: 00189 00190 MonoOn 00191 0 Small 00192 1 Medium, no scrollbar 00193 2 Medium with scrollbar (default) 00194 3 Large 00195 MonoOff 00196 00197 Notes: Normal preference, available from the options dialogue. 00198 SeeAlso: ColourEditDlg 00199 00200 ********************************************************************************************/ 00201 00202 static INT32 DefaultSizeIndex = 2; // User preference 'ColourBarMode'- indexes the above array 00203 00204 00205 /******************************************************************************************** 00206 00207 Preference: ColourCellsDivided 00208 Section: Displays 00209 Range: 0 (off) or 1 (on) 00210 Purpose: If set to 0, colour cells in the colour line will butt up against each 00211 other. If set to 1, a single pixel grey line will be used to divide the 00212 cells, to make them easier to distinguish. 00213 00214 ********************************************************************************************/ 00215 00216 static INT32 ColourCellsDivided = 0; 00217 00218 00219 00220 // Redraw Constants 00221 const INT32 SCROLLBUTTON_LEFT = 0; // Scroll button identifiers 00222 const INT32 SCROLLBUTTON_RIGHT = 1; 00223 00224 const INT32 CX_BORDER = 2; // Number of pixels of blank space around the edge 00225 const INT32 CY_BORDER = 0; // (On top of the default 1 pixel border) 00226 00227 const INT32 InterControlGap = 2; // The horizontal gap between the bar's 'controls' 00228 const INT32 ButtonWidth = 11; // Width of the scrollbar left/right buttons 00229 00230 // The following variables are calculated and filled in by SetSizes(), but 00231 // I've put some reasonable defaults in. Note that on construction, CellSize 00232 // and ScrollHeight are passed to SetSizes in order to calculate the others. 00233 00234 static INT32 BarHeight = 25; // Total height of the bar window in pixels 00235 static INT32 CellSize = 16; // Each Colour Cell is NxN pixels in size - preference 00236 static INT32 ScrollHeight = 9; // The mini scrollbar height in pixels 00237 00238 // The No-Colour 'cell' is a normal cell size 00239 #define NoColourSize (CellSize) 00240 00241 // Width and height of the edit button 00242 #define EditButtonSizeX (CellSize) 00243 #define EditButtonSizeY (CellSize) 00244 00245 00246 // Click values - this is; nothing, a colour index (0..?), or a scroll bar/arrow 00247 const INT32 CLICKED_NOTHING = 10000; // Nothing 00248 const INT32 CLICKED_INDICATORS = 10001; // Over the current colour indicators 00249 const INT32 CLICKED_LEFTSCROLL = 10002; // Over the left scroll arrow 00250 const INT32 CLICKED_RIGHTSCROLL = 10003; // Over the right scroll arrow 00251 const INT32 CLICKED_SCROLLBAR = 10004; // Over the scroll sausage 00252 const INT32 CLICKED_SCROLLBARLEFT = 10005; // Over the left end of the scrollbar 00253 const INT32 CLICKED_SCROLLBARRIGHT = 10006; // Over the right end of the scrollbar 00254 const INT32 CLICKED_SCROLLSTRIP = 10007; // Over the strip, with push modifier key 00255 const INT32 CLICKED_NOCOLOURCELL = 10008; // Over the 'No Colour' cell 00256 const INT32 CLICKED_EDITBUTTON = 10009; // Over the 'edit colour' button 00257 const INT32 CLICKED_NEWBUTTON = 10010; // Over the 'new colour' button 00258 00259 00260 // Cell values for special cell 'indices' (the no-colour cell, and no-cell-at-all-mate) 00261 const INT32 CELLINDEX_NOCOLOURCELL = -1; 00262 const INT32 CELLINDEX_NOCELL = -2; 00263 00264 00265 // Static member variables 00266 //ListComparator CColourBar::SortFunction = NULL; // We have no sort mode by default 00267 CColourBar *CColourBar::TheColourBar = NULL; // There is no bar currently available 00268 BOOL CColourBar::BarIsVisible = TRUE; // Bars will default to being visible 00269 00270 00271 IMPLEMENT_DYNAMIC_CLASS(CColourBar, wxWindow) 00272 CC_IMPLEMENT_DYNAMIC(EditButtonDragTarget, OilDragTarget) 00273 CC_IMPLEMENT_DYNAMIC(ColourLineDragTarget, OilDragTarget) 00274 00275 // Declare smart memory handling in Debug builds 00276 #define new CAM_DEBUG_NEW 00277 00278 00279 /******************************************************************************************** 00280 00281 > inline Document *SetCurrentDoc(void) 00282 00283 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00284 Created: 28/7/94 00285 Inputs: - 00286 Outputs: - 00287 Returns: The old Current Document 00288 00289 Purpose: The ColourBar works exclusively on the SELECTED Doc. 00290 Thus, on entry to any of its routines which call routines 00291 outside this file (ccolbar.cpp), it must ensure that CurrentDoc 00292 is equal to SelectedDoc. 00293 This local macro inline does this, and returns the old setting of 00294 CurrentDoc so that the caller can restore the previous CurrentDoc 00295 on exit. 00296 00297 Scope: private (to winoil\ccolbar.cpp) 00298 SeeAlso: RestoreCurrentDoc 00299 00300 ********************************************************************************************/ 00301 00302 inline Document *SetCurrentDoc(void) 00303 { 00304 Document *OldCurrentDoc = Document::GetCurrent(); 00305 Document *NewCurrentDoc = Document::GetSelected(); 00306 00307 if (NewCurrentDoc != NULL && NewCurrentDoc != OldCurrentDoc) 00308 NewCurrentDoc->SetCurrent(); 00309 00310 return(OldCurrentDoc); 00311 } 00312 00313 00314 00315 /******************************************************************************************** 00316 00317 > inline void RestoreCurrentDoc(Document *OldCurrentDoc) 00318 00319 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00320 Created: 28/7/94 00321 Inputs: The old current document to restore 00322 Outputs: - 00323 Returns: - 00324 00325 Purpose: The ColourBar works exclusively on the SELECTED Doc. 00326 After calling SetCurrentDoc on entry to a routine, you should call 00327 RestoreCurrentDoc on exit to restore the old current document./ 00328 00329 Scope: private (to winoil\ccolbar.cpp) 00330 SeeAlso: SetCurrentDoc 00331 00332 ********************************************************************************************/ 00333 00334 inline void RestoreCurrentDoc(Document *OldCurrentDoc) 00335 { 00336 if (OldCurrentDoc != NULL) 00337 OldCurrentDoc->SetCurrent(); 00338 } 00339 00340 00341 /******************************************************************************************** 00342 00343 > void EditButtonDragTarget::EditButtonDragTarget() 00344 00345 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 00346 Created: 12/1/95 00347 Inputs: - 00348 Outputs: - 00349 Returns: - 00350 Purpose: 00351 Errors: - 00352 SeeAlso: - 00353 00354 ********************************************************************************************/ 00355 EditButtonDragTarget::EditButtonDragTarget(wxWindow* TheWindow, wxRect *ClientArea) 00356 : OilDragTarget(TheWindow, ClientArea) 00357 { 00358 // TRACEUSER("Gerry", _T("EditButtonDragTarget created")); 00359 } 00360 00361 00362 00363 /******************************************************************************************** 00364 00365 > void EditButtonDragTarget::ProcessEvent(DragEventType Event, 00366 DragInformation *pDragInfo, 00367 wxPoint *pMousePos, KeyPress* pKeyPress) 00368 00369 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 00370 Created: 12/1/95 00371 Inputs: - 00372 Outputs: - 00373 Returns: - 00374 Purpose: Event Handler for Edit Drag 00375 Errors: - 00376 SeeAlso: - 00377 00378 ********************************************************************************************/ 00379 00380 BOOL EditButtonDragTarget::ProcessEvent(DragEventType Event, 00381 DragInformation *pDragInfo, 00382 wxPoint *pMousePos, KeyPress* pKeyPress) 00383 { 00384 // TRACEUSER("Gerry", _T("EditButtonDragTarget::ProcessEvent")); 00385 00386 // Not a colour drag? That is kindof unexpected, but lets exit before 00387 // we embarrass ourselves 00388 00389 if (!pDragInfo->IsKindOf(CC_RUNTIME_CLASS(ColourDragInformation))) 00390 return(FALSE); 00391 00392 switch(Event) 00393 { 00394 case DRAGEVENT_COMPLETED: 00395 if (CColourBar::TheColourBar != NULL && 00396 CColourBar::TheColourBar->m_pCurrentColourList != NULL) 00397 { 00398 if (CanDropHere(pDragInfo)) 00399 { 00400 ColourDragInformation *CDI = (ColourDragInformation *) pDragInfo; 00401 IndexedColour *Col = NULL; 00402 00403 if (CDI->IsLibraryColour()) 00404 { 00405 // We must copy the library colour into the document, but first check with 00406 // the user that this is what they intended. 00407 #ifndef WEBSTER 00408 // Camelot builds ask the user to check that this is what they want 00409 if (InformError(_R(IDE_CANTEDITLIBCOLOUR), _R(IDS_COPYLIBCOLOUR), _R(IDS_CANCEL)) == 1) 00410 Col = CDI->GetColourForDocument(Document::GetSelected()); 00411 #else 00412 // Webster builds just do it. Simplify the UI for the user 00413 Col = CDI->GetColourForDocument(Document::GetSelected()); 00414 #endif 00415 } 00416 else 00417 Col = CDI->GetInitiallyDraggedColour(); 00418 00419 if (Col != NULL) 00420 CColourBar::TheColourBar->EditAColour(CColourBar::TheColourBar->m_pCurrentColourList, Col); 00421 return(TRUE); 00422 } 00423 } 00424 break; 00425 00426 00427 case DRAGEVENT_MOUSESTOPPED: 00428 case DRAGEVENT_MOUSEMOVED: 00429 case DRAGEVENT_MOUSEIDLE: 00430 // Return TRUE to claim the mouse while over our target area, so that 00431 // our cursor shape is used 00432 return(TRUE); 00433 00434 default: 00435 break; 00436 } 00437 00438 // Allow unknown/unwanted events to pass on to other targets 00439 return(FALSE); 00440 } 00441 00442 00443 00444 /******************************************************************************************** 00445 00446 > void EditButtonDragTarget::GetCursorID() 00447 00448 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> (Rewritten, Jason) 00449 Created: 10/1/95 (25/3/96) 00450 Purpose: Set cursor over this target 00451 00452 ********************************************************************************************/ 00453 00454 UINT32 EditButtonDragTarget::GetCursorID() 00455 { 00456 // TRACEUSER("Gerry", _T("EditButtonDragTarget::GetCursorID")); 00457 00458 DragInformation *pDragInfo = DragManagerOp::GetCurrentDragInfo(); 00459 if (CanDropHere(pDragInfo)) 00460 return _R(IDC_CANDROP_EDITBUTTON); 00461 00462 return 0; 00463 } 00464 00465 00466 00467 /******************************************************************************************** 00468 00469 > virtual BOOL EditButtonDragTarget::GetStatusLineText(String_256 * TheText) 00470 00471 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> (Rewritten, Jason) 00472 Created: 15/1/95 (25/3/96) 00473 Returns: Whether String is valid 00474 Purpose: provide status line text for this target 00475 00476 ********************************************************************************************/ 00477 00478 BOOL EditButtonDragTarget::GetStatusLineText(String_256 *TheText) 00479 { 00480 // TRACEUSER("Gerry", _T("EditButtonDragTarget::GetStatusLineText")); 00481 00482 ERROR2IF(TheText==NULL,FALSE,_T("NULL string in GetStatusLineText()")); 00483 00484 // Call our helper function to find out if this can be dropped here 00485 DragInformation *pDragInfo = DragManagerOp::GetCurrentDragInfo(); 00486 if (CanDropHere(pDragInfo)) 00487 { 00488 String_256 DragString(_R(IDS_COLBAR_DRAGDROP)); 00489 *TheText = DragString; 00490 return TRUE; 00491 } 00492 00493 return FALSE; 00494 } 00495 00496 00497 00498 /******************************************************************************************** 00499 00500 > BOOL EditButtonDragTarget::CanDropHere(DragInformation *pDragInfo) 00501 00502 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00503 Created: 25/3/96 00504 00505 Returns: Whether this is something that can be dropped on the edit button 00506 00507 Purpose: Internal helper function 00508 00509 ********************************************************************************************/ 00510 00511 BOOL EditButtonDragTarget::CanDropHere(DragInformation *pDragInfo) 00512 { 00513 // TRACEUSER("Gerry", _T("EditButtonDragTarget::CanDropHere")); 00514 00515 if (Document::GetSelected() == NULL) // No selected docuement? can't edit anything then 00516 return(FALSE); 00517 00518 if (pDragInfo != NULL && pDragInfo->IsKindOf(CC_RUNTIME_CLASS(ColourDragInformation))) 00519 { 00520 ColourDragInformation *CDInfo = (ColourDragInformation *) pDragInfo; 00521 00522 // We always allow drops of library colours onto us 00523 if (CDInfo->IsLibraryColour()) 00524 return(TRUE); 00525 00526 // Get the dragged colour and the current colour list 00527 IndexedColour *Col = CDInfo->GetInitiallyDraggedColour(); 00528 00529 if (Col != NULL) // NULL means "no colour" or a library colour, which can't be edited 00530 { 00531 ColourList *ColList = NULL; 00532 if (CDInfo->GetParentDoc() != NULL) 00533 ColList = CDInfo->GetParentDoc()->GetIndexedColours(); 00534 00535 return(ColourEditDlg::CanYouEditThis(ColList, Col)); 00536 } 00537 } 00538 00539 return(FALSE); 00540 } 00541 00542 00543 /******************************************************************************************** 00544 00545 > void ColourLineDragTarget::ColourLineDragTarget() 00546 00547 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00548 Created: 20/11/95 00549 Inputs: - 00550 Outputs: - 00551 Returns: - 00552 Purpose: 00553 Errors: - 00554 SeeAlso: - 00555 00556 ********************************************************************************************/ 00557 ColourLineDragTarget::ColourLineDragTarget(wxWindow* TheWindow, wxRect *ClientArea) 00558 : OilDragTarget(TheWindow, ClientArea) 00559 { 00560 // TRACEUSER("Gerry", _T("ColourLineDragTarget created")); 00561 } 00562 00563 00564 00565 /******************************************************************************************** 00566 00567 > void ColourLineDragTarget::ProcessEvent(DragEventType Event, 00568 DragInformation *pDragInfo, 00569 wxPoint *pMousePos, KeyPress* pKeyPress) 00570 00571 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00572 Created: 20/11/95 00573 00574 Purpose: Event Handler for Edit Drag - see the base class for details 00575 00576 SeeAlso: WinoilDragTarget::ProcessEvent 00577 00578 ********************************************************************************************/ 00579 00580 BOOL ColourLineDragTarget::ProcessEvent(DragEventType Event, 00581 DragInformation *pDragInfo, 00582 wxPoint *pMousePos, KeyPress* pKeyPress) 00583 { 00584 // TRACEUSER("Gerry", _T("ColourLineDragTarget::ProcessEvent")); 00585 00586 // Not a colour drag? That is kindof unexpected, but lets exit before 00587 // we embarrass ourselves 00588 if (!pDragInfo->IsKindOf(CC_RUNTIME_CLASS(ColourDragInformation))) 00589 return(FALSE); 00590 00591 CColourBar *pColourLine = CColourBar::TheColourBar; 00592 00593 switch(Event) 00594 { 00595 case DRAGEVENT_COMPLETED: 00596 if (KeyPress::IsConstrainPressed() && 00597 pColourLine != NULL && pColourLine->m_pCurrentColourList != NULL) 00598 { 00599 IndexedColour *Col = ((ColourDragInformation *) pDragInfo)->GetInitiallyDraggedColour(); 00600 00601 // Check that the colour being dragged is in the current colour list 00602 if (Col != NULL && pColourLine->m_pCurrentColourList->FindPosition(Col) < 0) 00603 Col = NULL; 00604 00605 // If it's NULL, then it's "no colour", a library colour, or a colour we couldn't 00606 // find in the current colour line display, so we ignore it 00607 if (Col != NULL) 00608 { 00609 // The Colour 'Col' has been dragged and dropped into the colour line 00610 // with the 'constrain' key held down. In this case, the user wants 00611 // to rearrange the colour line, so we detect which colour the pointer 00612 // is over, and insert 'Col' before/after that colour. 00613 00614 BOOL ToLeft = FALSE; 00615 INT32 CellIndex = pColourLine->WhereIsMouse(*pMousePos, NULL, &ToLeft); 00616 00617 if (CellIndex >= 0) 00618 { 00619 // The colour was dropped onto a legal colour cell - move it 00620 ColourList *TheList = pColourLine->m_pCurrentColourList; 00621 ERROR3IF(TheList == NULL, _T("No current colour list!")); 00622 00623 IndexedColour *Target = (IndexedColour *) TheList->GetUndeletedHead(); 00624 while (CellIndex > 0 && Target) 00625 { 00626 Target = (IndexedColour *) TheList->GetUndeletedNext(Target); 00627 CellIndex--; 00628 } 00629 00630 // Now move the item into the appropriate position 00631 if (Target != NULL && Target != Col) 00632 { 00633 if (ToLeft) 00634 { 00635 if (TheList->GetUndeletedNext(Col) != Target) 00636 { 00637 TheList->RemoveItem(Col); 00638 TheList->InsertBefore(Target, Col); 00639 00640 // And inform the world (colour line, gallery, etc) of the change 00641 ColourManager::ColourListHasChanged(TheList); 00642 } 00643 } 00644 else 00645 { 00646 if (TheList->GetUndeletedNext(Target) != Col) 00647 { 00648 TheList->RemoveItem(Col); 00649 TheList->InsertAfter(Target, Col); 00650 00651 // And inform the world (colour line, gallery, etc) of the change 00652 ColourManager::ColourListHasChanged(TheList); 00653 } 00654 } 00655 } 00656 } 00657 } 00658 00659 return(TRUE); 00660 } 00661 break; 00662 00663 00664 case DRAGEVENT_MOUSESTOPPED: 00665 case DRAGEVENT_MOUSEMOVED: 00666 case DRAGEVENT_MOUSEIDLE: 00667 // Return TRUE to claim the mouse while over our target area, so that 00668 // our cursor shape is used 00669 return(TRUE); 00670 00671 default: 00672 break; 00673 } 00674 00675 // Allow unknown/unwanted events to pass on to other targets 00676 return(FALSE); 00677 } 00678 00679 00680 00681 /******************************************************************************************** 00682 00683 > void ColourLineDragTarget::GetCursorID() 00684 00685 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00686 Created: 20/11/95 00687 Purpose: Base Method to set cursor over this target 00688 00689 00690 ********************************************************************************************/ 00691 00692 UINT32 ColourLineDragTarget::GetCursorID() 00693 { 00694 // TRACEUSER("Gerry", _T("ColourLineDragTarget::GetCursorID")); 00695 00696 DragInformation * pDragInfo = DragManagerOp::GetCurrentDragInfo(); 00697 if (pDragInfo != NULL && KeyPress::IsConstrainPressed()) 00698 { 00699 if (pDragInfo->IsKindOf(CC_RUNTIME_CLASS(ColourDragInformation))) 00700 { 00701 IndexedColour *Col = ((ColourDragInformation *) pDragInfo)->GetInitiallyDraggedColour(); 00702 00703 if (Col != NULL) 00704 { 00705 if (CColourBar::TheColourBar != NULL) 00706 { 00707 BOOL CanDrop = FALSE; 00708 00709 // Determine if the mouse cursor should be "insert on left" or 00710 // insert on right" of the colour under the pointer 00711 BOOL ToLeft = FALSE; 00712 wxPoint MousePos = wxGetMousePosition(); 00713 MousePos = CColourBar::TheColourBar->ScreenToClient(MousePos); 00714 00715 INT32 CellIndex = CColourBar::TheColourBar->WhereIsMouse(MousePos, NULL, &ToLeft); 00716 if (CellIndex >= 0) 00717 { 00718 // The pointer is over a legal colour cell 00719 ColourList *TheList = CColourBar::TheColourBar->m_pCurrentColourList; 00720 ERROR3IF(TheList == NULL, _T("No current colour list!")); 00721 00722 IndexedColour *Target = (IndexedColour *) TheList->GetUndeletedHead(); 00723 while (CellIndex > 0 && Target != NULL) 00724 { 00725 Target = (IndexedColour *) TheList->GetUndeletedNext(Target); 00726 CellIndex--; 00727 } 00728 00729 // Now, check that it is a position in which the colour can be dropped. 00730 // We disallow any drop which will leave the colour where it was. 00731 if (Target != NULL && Target != Col) 00732 { 00733 if (ToLeft) 00734 CanDrop = (TheList->GetUndeletedNext(Col) != Target); 00735 else 00736 CanDrop = (TheList->GetUndeletedNext(Target) != Col); 00737 } 00738 00739 // If we are sure it's OK to drop here, we return the cursor to use 00740 if (CanDrop) 00741 { 00742 if (ToLeft) 00743 return _R(IDC_DROPLEFT); 00744 00745 return _R(IDC_DROPRIGHT); 00746 } 00747 00748 // else drop out to "no-drop" cursor 00749 } 00750 } 00751 } 00752 } 00753 } 00754 00755 // Ask for "can't drop here" cursor. Really ought to rename this resource ID soon! 00756 return _R(IDC_DRAGGING_COLOUR); 00757 } 00758 00759 00760 00761 /******************************************************************************************** 00762 00763 > virtual BOOL ColourLineDragTarget::GetStatusLineText(String_256 * TheText) 00764 00765 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00766 Created: 20/11/95 00767 Returns: Whether String is valid 00768 Purpose: provide status line text for this target 00769 00770 ********************************************************************************************/ 00771 00772 BOOL ColourLineDragTarget::GetStatusLineText(String_256 * TheText) 00773 { 00774 // TRACEUSER("Gerry", _T("ColourLineDragTarget::GetStatusLineText")); 00775 00776 ERROR2IF(TheText==NULL,FALSE,_T("NULL string in GetStatusLineText()")); 00777 00778 DragInformation * pDragInfo = DragManagerOp::GetCurrentDragInfo(); 00779 00780 if (pDragInfo != NULL && CColourBar::TheColourBar != NULL) 00781 { 00782 if (pDragInfo->IsKindOf(CC_RUNTIME_CLASS(ColourDragInformation))) 00783 { 00784 if (((ColourDragInformation *) pDragInfo)->GetInitiallyDraggedColour() != NULL) 00785 { 00786 // If we are sure it's OK to drop here, we return the cursor to use 00787 String_256 DragString(_R(IDS_COLBAR_REARRANGE)); 00788 *TheText = DragString; 00789 return TRUE; 00790 } 00791 } 00792 } 00793 00794 return FALSE; 00795 } 00796 00797 00798 00799 BEGIN_EVENT_TABLE( CColourBar, wxWindow ) 00800 EVT_LEFT_DOWN( CColourBar::OnLButtonDown) 00801 EVT_LEFT_DCLICK( CColourBar::OnLButtonDblClk) 00802 EVT_LEFT_UP( CColourBar::OnLButtonUp) 00803 EVT_RIGHT_DOWN( CColourBar::OnRButtonDown) 00804 EVT_RIGHT_DCLICK( CColourBar::OnRButtonDblClk) 00805 EVT_RIGHT_UP( CColourBar::OnRButtonUp) 00806 EVT_MOTION( CColourBar::OnMouseMove) 00807 EVT_TIMER( 2, CColourBar::OnTimer) 00808 EVT_PAINT( CColourBar::OnPaint) 00809 EVT_SIZE( CColourBar::OnSize) 00810 END_EVENT_TABLE() 00811 00812 00813 /******************************************************************************************** 00814 00815 > CColourBar::CColourBar() 00816 00817 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00818 Created: 17/6/94 00819 Inputs: - 00820 Outputs: - 00821 Returns: - 00822 Purpose: CColourBar constructor 00823 Notes: The ColourBar works exclusively on the SELECTED Doc. Change with care 00824 00825 ********************************************************************************************/ 00826 00827 CColourBar::CColourBar() 00828 { 00829 m_pCurrentColourList = NULL; 00830 00831 LeftmostColour = 0; // Initially, are at left end of the colourstrip 00832 00833 LastLineCell = CELLINDEX_NOCELL; // We have not drawn any indicator diamonds anywhere 00834 LastFillCell = CELLINDEX_NOCELL; 00835 LastEndCell = CELLINDEX_NOCELL; 00836 LastDiamondShape = TRUE; 00837 00838 IndentedButton = CLICKED_NOTHING; 00839 00840 m_cxLeftBorder = 1; // Automatic 1 pixel gap at left end of bar 00841 m_cyTopBorder = 0; 00842 m_cxRightBorder = 0; 00843 m_cyBottomBorder = 0; 00844 00845 TheColourBar = this; 00846 00847 MsgHandler = NULL; 00848 00849 m_DragTimer.SetOwner(this, 2); 00850 00851 DragInfo.TimerOn = 0; 00852 DragInfo.MouseCaptured = FALSE; 00853 00854 PushCursor = NULL; 00855 00856 OldBarHeight = 0; 00857 00858 // We have no current colour gallery to access the fixed gallery section colours 00859 m_pColourGallery = NULL; 00860 } 00861 00862 00863 00864 /******************************************************************************************** 00865 00866 > BOOL CColourBar::~CColourBar() 00867 00868 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00869 Created: 17/6/94 00870 Inputs: - 00871 Outputs: - 00872 Returns: - 00873 Purpose: Destroys the object, as one might expect. 00874 Notes: IMPORTANT - After calling the destructor (delete ColourBar) it is 00875 VITAL that you then call RecalcLayout() for the main frame window in 00876 which the Colour Bar is appearing (the one you passed in to PB::Create(). 00877 If you don't do this, the bar won't disappear until the next time the main 00878 window is resized or a tool is chosen. 00879 00880 The ColourBar works exclusively on the SELECTED Doc. Change with care 00881 00882 ********************************************************************************************/ 00883 00884 CColourBar::~CColourBar() 00885 { 00886 TheColourBar = NULL; // There is no longer a colour bar around 00887 00888 if (MsgHandler != NULL) 00889 delete MsgHandler; // Kill our message handler 00890 00891 ReleaseAllClaims(); // Ensure all temp. window claims (mouse/timer) released 00892 00893 if (PushCursor) 00894 delete PushCursor; 00895 } 00896 00897 00898 00899 /******************************************************************************************** 00900 00901 > BOOL CColourBar::InitPrefs(void) 00902 00903 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00904 Created: 22/6/94 00905 Inputs: - 00906 Outputs: - 00907 Returns: TRUE if the initialisation of the Colour bar prefs was successful. 00908 Purpose: Initialisation of ColourBar preference option(s) 00909 Notes: The ColourBar works exclusively on the SELECTED Doc. Change with care 00910 00911 ********************************************************************************************/ 00912 00913 BOOL CColourBar::InitPrefs(void) 00914 { 00915 if (MsgHandler == NULL) 00916 MsgHandler = new ColourBarMsgHandler; 00917 00918 if (MsgHandler == NULL) 00919 return(FALSE); 00920 00921 Camelot.DeclareSection(TEXT("Displays"), 8); 00922 Camelot.DeclarePref(TEXT("Displays"), TEXT("ColourBarMode"), &DefaultSizeIndex); 00923 Camelot.DeclarePref(TEXT("Displays"), TEXT("ColourCellsDivided"), &ColourCellsDivided); 00924 00925 return(TRUE); 00926 } 00927 00928 00929 00930 /******************************************************************************************** 00931 00932 > BOOL CColourBar::Create(CFrameWnd *ParentWnd, 00933 DWORD dwstyle = WS_CHILD | WS_VISIBLE | CBRS_BOTTOM, 00934 UINT32 nID = _R(AFX_IDW_STATUS_BAR)); 00935 00936 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00937 Created: 17/6/94 00938 Inputs: ParentWnd - The parent frame window (in Camelot, there can be only one) 00939 dwstyle, nID - you shouldn't have to mess with these (cf CStatusBar) 00940 Outputs: - 00941 Returns: TRUE if the initialisation of the Colour bar was successful. 00942 Purpose: Creates a window and associates it with this CColourBar object. The window 00943 appears at the bottom of the main frame window, just like the status bar. 00944 00945 Notes: The ColourBar works exclusively on the SELECTED Doc. Change with care 00946 00947 ********************************************************************************************/ 00948 00949 BOOL CColourBar::Create(wxWindow* pParent, UINT32 id) 00950 { 00951 if (!wxWindow::Create(pParent, id, wxDefaultPosition, wxSize(BarHeight, BarHeight), wxNO_BORDER)) 00952 return(FALSE); 00953 00954 #if FALSE 00955 ASSERT_VALID(pParentWnd); // must have a parent 00956 00957 // Create a new WndClass- this should be identical to CControlBar's WndClass but 00958 // we also would kindof like double clicks if it isn't too much trouble, Mr MFC 00959 CString WndClassName = AfxRegisterWndClass(CS_DBLCLKS, NULL, //Cursor::Arrow->Handle(), 00960 (HBRUSH)(COLOR_BTNFACE + 1)); 00961 00962 // Do we want to show this bar after it's created? 00963 BOOL Show = dwStyle & WS_VISIBLE; 00964 00965 // Make sure the style flags only has legal flags set (VC6 change) 00966 dwStyle &= CBRS_ALL; 00967 00968 #if WIN32 00969 // this element of CControlBar does not exist in MFC 2.5 16-bit 00970 m_dwStyle = dwStyle; 00971 #endif 00972 00973 // create the wxWindow* 00974 wxRect rect; 00975 rect.SetRectEmpty(); 00976 if (!CWnd::Create(WndClassName, NULL, dwStyle, rect, pParentWnd, nID)) 00977 return(FALSE); 00978 // NOTE: Parent must resize itself for control bar to be resized 00979 00980 if (Show) 00981 ShowWindow(SW_SHOW); 00982 #endif 00983 00984 InitPrefs(); 00985 SetDisplayMode(); 00986 00987 InvalidateBestSize(); 00988 00989 IndentedButton = CLICKED_NOTHING; 00990 00991 return(TRUE); 00992 } 00993 00994 00995 00996 /******************************************************************************************** 00997 00998 > wxSize CColourBar::DoGetBestSize() const 00999 01000 Author: Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com> 01001 Created: 10/03/06 01002 Inputs: - 01003 Outputs: - 01004 Returns: Best size of this window 01005 01006 ********************************************************************************************/ 01007 01008 wxSize CColourBar::DoGetBestSize() const 01009 { 01010 TRACEUSER("Gerry", _T("CColourBar::DoGetBestSize")); 01011 wxRect AvailableRect = GetParent()->GetClientRect(); 01012 AvailableRect.height = BarHeight; 01013 INT32 Height = ((CColourBar*)this)->CalculateNewBarHeight(&AvailableRect); 01014 INT32 Width = GetParent()->GetClientSize().x; 01015 01016 return(wxSize(Width, Height)); 01017 } 01018 01019 /******************************************************************************************** 01020 01021 > void CColourBar::SetSizes(INT32 NewCellSize, INT32 NewScrollbarSize) 01022 01023 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 01024 Created: 22/6/94 01025 Inputs: NewCellSize - The new size in pixels of the square colour cells 01026 This should be an even number (it is truncated if necessary) 01027 01028 NewScrollbarSize - The new height of the scroll bar in pixels 01029 01030 Outputs: - 01031 Returns: - 01032 01033 Purpose: Sets the base sizes of the colour strip and colour scroll bar 01034 in the colour bar window. Other features of the bar are automatically 01035 resized to fit the new sizing. The bar will be redrawn. If the 01036 combined height of the bar elements has now changed, the bar will 01037 be resized (by calling the parent's RecalcLayout method). 01038 01039 Notes: Setting NewScrollBarSize == 0 enters a special mode where the scroll 01040 sausage is not drawn, and the scroll arrows sit at either end of the 01041 colour strip. In this size, it is recommended that 01042 CellSize == ButtonWidth (i.e. about 10 pixels), to make the buttons 01043 square and therefore not entirely disgusting looking 01044 01045 The ColourBar works exclusively on the SELECTED Doc. Change with care 01046 01047 ********************************************************************************************/ 01048 01049 void CColourBar::SetSizes(INT32 NewCellSize, INT32 NewScrollbarSize) 01050 { 01051 ENSURE (NewCellSize >= 4 && NewCellSize <= 64, 01052 "Silly CellSize passed to CColourBar::SetSizes()"); 01053 01054 ENSURE (NewScrollbarSize == 0 || 01055 (NewScrollbarSize >= 3 && NewScrollbarSize <= 24), 01056 "Silly ScrollbarSize passed to CColourBar::SetSizes()"); 01057 01058 NewCellSize &= ~1; // Force Cellsize to be an even value 01059 01060 // BOOL ResizeFrame = (NewCellSize + NewScrollbarSize != CellSize + ScrollHeight); 01061 01062 CellSize = NewCellSize; 01063 ScrollHeight = NewScrollbarSize; 01064 01065 BarHeight = CellSize + ScrollHeight + (2 * CY_BORDER) + 01066 m_cyTopBorder + m_cyBottomBorder + 1; 01067 01068 // if (ResizeFrame) 01069 { 01070 SetMinSize(wxSize(8, BarHeight)); 01071 01072 InvalidateBestSize(); 01073 GetMainFrame()->UpdateFrameManager(); 01074 } 01075 } 01076 01077 01078 01079 /******************************************************************************************** 01080 01081 > static void CColourBar::SetDisplayMode(INT32 NewDisplayMode = -1) 01082 01083 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 01084 Created: 25/10/94 01085 01086 Inputs: NewDisplayMode - The mode (0..3) or -1 to re-read the preference value 01087 01088 Purpose: Sets the Colour Bar display mode to the new value. 01089 Current legal mode values are 0..3 (small, med, med+scroll, large) 01090 Illegal values will cause it to resort to the default mode, medium+scroll (2) 01091 The default value of -1 is used to mean 'use the preference setting'. 01092 This allows the prefs dialogue to cause the ColourBar to sit up and 01093 take notice of changed preference settings. 01094 The preference setting ColourBarMode will be set to the new value 01095 01096 Notes: This static function may be called at any time. If a colour bar is not 01097 open when the call is made, the new setting will be used for the next 01098 colour bar created. 01099 01100 ********************************************************************************************/ 01101 01102 void CColourBar::SetDisplayMode(INT32 NewDisplayMode) 01103 { 01104 if (NewDisplayMode == -1) 01105 NewDisplayMode = DefaultSizeIndex; 01106 01107 if (NewDisplayMode < 0 || NewDisplayMode >= MAXDEFAULTSIZES) 01108 NewDisplayMode = 2; 01109 01110 DefaultSizeIndex = NewDisplayMode; // Remember this as a preference setting 01111 01112 if (TheColourBar != NULL) // If there's a bar, set it to the new size 01113 { 01114 TheColourBar->SetSizes(ColBarDefaultSize[NewDisplayMode].Cell, 01115 ColBarDefaultSize[NewDisplayMode].Scrollbar); 01116 TheColourBar->Refresh(); // Force a redraw of the bar to ensure it's up to date 01117 } 01118 } 01119 01120 01121 01122 01123 /******************************************************************************************** 01124 01125 > INT32 CColourBar::GetNumberOfColours() 01126 01127 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 01128 Created: 19/3/97 01129 Inputs: - 01130 Returns: The number of colours we wish to display on the bar. 01131 Purpose: Determines the number of colours that we wish to display on the ColourBar. 01132 01133 ********************************************************************************************/ 01134 01135 INT32 CColourBar::GetNumberOfColours() 01136 { 01137 INT32 total = 0; 01138 01139 // Get the actually colours in the selected document 01140 INT32 DocColours = 0; 01141 01142 // If the user has the preference set then include and hence show the document 01143 // colours 01144 if (ColourSGallery::ShowDocumentColours) 01145 { 01146 if (m_pCurrentColourList == NULL) 01147 m_pCurrentColourList = ColourManager::GetColourList(); 01148 01149 if (m_pCurrentColourList != NULL) 01150 DocColours = (INT32) m_pCurrentColourList->GetUndeletedCount(); 01151 01152 total += DocColours; 01153 } 01154 01155 PORTNOTE("other","Removed ColourSGallery usage") 01156 #if !defined(EXCLUDE_FROM_XARALX) 01157 // try and add in any fixed sections required 01158 m_pColourGallery = ColourSGallery::GetInstance(); 01159 if (m_pColourGallery != NULL) 01160 { 01161 // This will create the groups if they're not there yet 01162 m_pColourGallery->MakeSureGroupsHaveBeenCreated(); 01163 01164 // Find the Netscape palette library 01165 SGDisplayLibColGroup * pLibGroup = m_pColourGallery->GetFirstLibGroup(); 01166 BOOL Found = FALSE; 01167 while (!Found && pLibGroup) 01168 { 01169 // Add in any items that are flagged as being required 01170 if (pLibGroup->DisplayInColourLine()) 01171 { 01172 // pLibGroup->DeVirtualise(); // This is dangerous as it may change things like current doc! 01173 // Disabled as it causes problems during start up 01174 total += pLibGroup->CountChildren(); 01175 } 01176 01177 pLibGroup = m_pColourGallery->GetNextLibGroup(pLibGroup); 01178 } 01179 } 01180 #endif 01181 return total; 01182 } 01183 01184 /******************************************************************************************** 01185 01186 > static BOOL CColourBar::EnsureLibraryColoursPresent() 01187 01188 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 01189 Created: 19/3/97 01190 Inputs: - 01191 Returns: True if worked correctly 01192 Purpose: Ensures that any colour library sections we require are present. 01193 01194 ********************************************************************************************/ 01195 01196 BOOL CColourBar::EnsureLibraryColoursPresent() 01197 { 01198 PORTNOTE("other","Removed ColourSGallery usage") 01199 #if !defined(EXCLUDE_FROM_XARALX) 01200 // try and ensure all our required colour gallery sections are present and de-virtilised 01201 ColourSGallery * pColourGallery = ColourSGallery::GetInstance(); 01202 if (pColourGallery != NULL) 01203 { 01204 // This will create the groups if they're not there yet 01205 pColourGallery->MakeSureGroupsHaveBeenCreated(); 01206 01207 // Find the Netscape palette library 01208 SGDisplayLibColGroup * pLibGroup = pColourGallery->GetFirstLibGroup(); 01209 while (pLibGroup) 01210 { 01211 // Add in any items that are flagged as being required 01212 if (pLibGroup->DisplayInColourLine()) 01213 { 01214 pLibGroup->DeVirtualise(); 01215 } 01216 01217 pLibGroup = pColourGallery->GetNextLibGroup(pLibGroup); 01218 } 01219 01220 if (TheColourBar != NULL) // If there's a bar, set it to the new size 01221 { 01222 // Force a redraw of the bar to ensure it's up to date 01223 // This checks that the size is correct 01224 PaletteHasChanged(NULL); 01225 //TheColourBar->Invalidate(); 01226 } 01227 } 01228 #endif 01229 return TRUE; 01230 } 01231 01232 /******************************************************************************************** 01233 01234 > BOOL CColourBar::IsColourPickerOverStripRect (wxWindow* colourPicker, wxPoint mousePt) 01235 01236 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 01237 Created: 22/10/99 01238 Inputs: colourPicker - The wxWindow* of the claimed colour picker control 01239 mousePt - the current mouse location that the colour picker is supplying 01240 Returns: True if mousePt is in StripRect 01241 False otherwise 01242 Throws ENSURE error if colourPicker is NOT a colour picker control 01243 Purpose: This function helps to determin how colour picker controls should 01244 behave when they are over the colour bar 01245 01246