dragcol.cpp

Go to the documentation of this file.
00001 // $Id: dragcol.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 // DragCol.cpp - Colour DragInformation base class
00099 
00100 /*
00101 */
00102 
00103 
00104 #include "camtypes.h"
00105 
00106 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 #include "ccolbar.h"
00108 #include "coldlog.h"
00109 #include "colourix.h"
00110 #include "colormgr.h"
00111 #include "devcolor.h"
00112 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00113 #include "dragcol.h"
00114 #include "dragmgr.h"
00115 #include "keypress.h"
00116 #include "camframe.h"
00117 //#include "resource.h"
00118 #include "sgcolour.h"
00119 #include "camview.h"
00120 //#include "attrmgr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00121 //#include "fillattr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00122 //#include "ink.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00123 #include "lineattr.h"
00124 
00125 #include "palman.h"
00126 
00127 #include "backgrnd.h"   // OpBackground
00128 #include "keypress.h"   // KeyPress
00129 //#include "galstr.h"       // _R(IDS_DRAGCOL_DROP_SETPAGEBACKGROUND)
00130 
00131 CC_IMPLEMENT_DYNCREATE(ColourDragInformation, DragInformation)
00132 
00133 
00134 
00135 const INT32 CellSize = 16;      // X/Y size of the solid-dragged colour square
00136 
00137 
00138 
00139 // Default to non-transparent dragging
00140 INT32 ColourDragInformation::DragTransparency = 0;
00141 
00142 
00143 
00144 /********************************************************************************************
00145 
00146 >   void ColourDragInformation::InitObject(void)
00147      
00148     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00149     Created:    9/8/96
00150 
00151     Purpose:    Shared code for initialising the object - called by all constructors
00152 
00153 ********************************************************************************************/
00154 
00155 void ColourDragInformation::InitObject(void)
00156 {
00157     // Init member variables
00158     TheColour = DocColour(COLOUR_TRANS);
00159     pParentDoc = NULL;
00160     ColourName = TEXT("");
00161     LibColIsSpot = FALSE;
00162 
00163     // Set up a few things about this drag
00164     DoesSolidDrag = TRUE;
00165     
00166     // offset of colour swatch from the pointer
00167     SolidDragOffset.x = -14;
00168     SolidDragOffset.y = 4;     
00169     
00170     // size of the solid drag redraw
00171     SolidDragSize.x = CellSize;
00172     SolidDragSize.y = CellSize;
00173 }
00174 
00175 
00176 
00177 /********************************************************************************************
00178 
00179 >   void ColourDragInformation::ColourDragInformation() 
00180      
00181     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00182     Created:    12/1/95       
00183 
00184     Purpose:    Conmstructor - do not call this default constructor.
00185 
00186 ********************************************************************************************/
00187 
00188 ColourDragInformation::ColourDragInformation()
00189 {
00190     ERROR3("Default ColourDragInformation constructor called"); 
00191     InitObject();
00192 }
00193 
00194 
00195 
00196 /********************************************************************************************
00197 
00198 >   void ColourDragInformation::ColourDragInformation(IndexedColour *Colour, BOOL IsAdjust,
00199                                                         Document* pParent) 
00200      
00201     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00202     Created:    12/1/95       
00203     
00204     Inputs:     Colour      - The IndexedColour being dragged
00205                               May not be NULL
00206 
00207                 IsAdjust    - TRUE if this is an adjust-drag, FALSE if a select-drag
00208 
00209                 pParent     - Points to the parent document for the dragged colour.
00210 
00211     Purpose:    Constructor
00212                 Use this for "docuemnt colours" i.e. IndexedColours which already exist
00213                 inside a document. See the other constructor for library colours
00214 
00215 ********************************************************************************************/
00216 
00217 ColourDragInformation::ColourDragInformation(IndexedColour *Colour,BOOL IsAdjust,
00218                                                 Document* pParent)
00219                         : DragInformation(IsAdjust)
00220 {
00221     ERROR3IF(pParent == NULL, "Illegal NULL param");
00222 
00223     InitObject();
00224 
00225     // The IndexedColour we are dragging - if it's NULL, we're dragging "no colour"
00226     if (Colour != NULL)
00227         TheColour.MakeRefToIndexedColour(Colour);
00228 
00229     // The Parent document of the colour we are dragging
00230     pParentDoc = pParent;
00231 }
00232 
00233 
00234 
00235 /********************************************************************************************
00236 
00237 >   ColourDragInformation::ColourDragInformation(DocColour *Colour, BOOL IsAdjust,
00238                                                     StringBase *pColourName, BOOL IsSpot)
00239      
00240     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00241     Created:    12/1/95       
00242     
00243     Inputs:     Colour      - The Colour being dragged
00244                               May not be NULL
00245 
00246                 IsAdjust    - TRUE if this is an adjust-drag, FALSE if a select-drag
00247 
00248                 pColourName - Should not be NULL (but it won't ERROR3, because
00249                                 of GalleryColourDragInfo constructor technical reasons)
00250                                 The name of the colour being dragged
00251 
00252                 IsSpot      - TRUE if this library colour is a spot colour
00253 
00254     Purpose:    Constructor
00255                 Use this for "library colours" i.e. Colours which DON'T already exist
00256                 inside a document. See the other constructor for document colours.
00257 
00258                 When the drag finishes, the user will ask this object for a colour,
00259                 at which point, an IndexedColour will be created for them from the
00260                 given DocColour and Name string. See GetLibraryColourForDocument()
00261 
00262 ********************************************************************************************/
00263 
00264 ColourDragInformation::ColourDragInformation(DocColour *Colour, BOOL IsAdjust,
00265                                                 StringBase *pColourName, BOOL IsSpot)
00266                         : DragInformation(IsAdjust)
00267 {
00268     ERROR3IF(Colour == NULL, "Illegal NULL param");
00269 
00270     InitObject();
00271 
00272     TheColour = *Colour;
00273     LibColIsSpot = IsSpot;
00274     
00275     if (pColourName != NULL)
00276         ColourName = *pColourName;
00277 }
00278 
00279 
00280 
00281 /********************************************************************************************
00282 
00283 >   static BOOL ColourDragInformation::Init()
00284 
00285     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00286     Created:    19/3/95       
00287     Returns:    -
00288     Purpose:    Initialise any Colour Drag stuff. (eg. ini file preferences).
00289     SeeAlso:    -
00290 
00291 ********************************************************************************************/
00292 
00293 BOOL ColourDragInformation::Init()
00294 {
00295     // Setup preference for drag transparency
00296     if (GetApplication()->DeclareSection(_T("Dragging"), 1))
00297         GetApplication()->DeclarePref( NULL, _T("ColourDragTransparency"), &DragTransparency, 0, 100);
00298 
00299     return TRUE;
00300 }
00301 
00302 
00303 
00304 /********************************************************************************************
00305 
00306 >   BOOL ColourDragInformation::IsLibraryColour(void)
00307 
00308     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00309     Created:    9/8/96
00310 
00311     Returns:    TRUE if this is a "library colour" (has no parent document), or
00312                 FALSE if the dragged colour resides in a document
00313 
00314     Purpose:    To determine if the dragged colour is from a library or a document
00315 
00316     SeeAlso:    ColourDragInformation::GetParentDoc
00317 
00318 ********************************************************************************************/
00319 
00320 BOOL ColourDragInformation::IsLibraryColour(void)
00321 {
00322     return(GetParentDoc() == NULL);
00323 }
00324 
00325 
00326 
00327 /********************************************************************************************
00328 
00329 >   Document *ColourDragInformation::GetParentDoc(void)
00330 
00331     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00332     Created:    9/8/96
00333 
00334     Returns:    NULL (if this is a "library colour" (has no parent document)), or a pointer
00335                 to the Source Document from which the colour has been dragged.
00336 
00337     Purpose:    To determine the document (if any) from which a colour is being dragged
00338 
00339     SeeAlso:    ColourDragInformation::IsLibraryColour
00340 
00341 ********************************************************************************************/
00342 
00343 Document *ColourDragInformation::GetParentDoc(void)
00344 {
00345     return(pParentDoc);
00346 }
00347 
00348 
00349 
00350 /********************************************************************************************
00351 
00352 >   IndexedColour *ColourDragInformation::GetColourForDocument(Document *pDestDoc = NULL)
00353 
00354     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00355     Created:    9/8/96
00356 
00357     Inputs:     pDestDoc -  NULL, to copy the colour into the Selected document, or
00358                         a pointer to the document to copy the colour into
00359 
00360     Returns:    NULL if the colour is transparent (no colour), or
00361                 A pointer to a safe colour to be used in the given document
00362 
00363     Purpose:    To copy/merge the dragged colour into the given document. The returned
00364                 pointer is a colour which is contained in the given document, and
00365                 can be safely used within that document.
00366 
00367     SeeAlso:    ColourDragInformation::IsLibraryColour
00368 
00369 ********************************************************************************************/
00370 
00371 IndexedColour *ColourDragInformation::GetColourForDocument(Document *pDestDoc)
00372 {
00373     // If no document supplied, assume the selected docuemnt is the destination
00374     if (pDestDoc == NULL)
00375         pDestDoc = Document::GetSelected();
00376 
00377     // If there is no destination document, or if the colour is transparent, return NULL
00378     if (pDestDoc == NULL || TheColour.IsTransparent())
00379         return(NULL);
00380 
00381     // If it's a document colour and already in the destination document, return it
00382     if (pParentDoc == pDestDoc)
00383         return(TheColour.FindParentIndexedColour());
00384 
00385     // Copy the dragged colour into a temporary DocColour
00386     DocColour Temp = TheColour;
00387     IndexedColour *TempIxCol = NULL;
00388 
00389     // Check if we've got an IndexedColour to use...
00390     if (Temp.FindParentIndexedColour() == NULL)
00391     {
00392         // It's a library colour, so we must create a new IndexedColour to use
00393         TempIxCol = new IndexedColour(Temp);
00394         if (TempIxCol == NULL)
00395             return(NULL);           // Failure - return "no colour"
00396 
00397         TempIxCol->SetName(ColourName);
00398 
00399         if (LibColIsSpot)           // If a spot colour, make it so
00400             TempIxCol->SetLinkedParent(TempIxCol->FindLastLinkedParent(), COLOURTYPE_SPOT);
00401 
00402         // And make the DocColour reference it
00403         Temp.MakeRefToIndexedColour(TempIxCol);
00404     }
00405 
00406     // Ensure the colour (or a safe equivalent) is in the dest doc, by copying/merging it
00407     ColourManager::EnsureColourIsInDocument(pParentDoc, pDestDoc, &Temp);
00408 
00409     // And delete any temporary IndexedColour we created
00410     if (TempIxCol != NULL)
00411         delete TempIxCol;
00412 
00413     // And finally, return the resulting colour
00414     return(Temp.FindParentIndexedColour());
00415 }
00416 
00417 
00418 
00419 /********************************************************************************************
00420 
00421 >   virtual UINT32 ColourDragInformation::ApplyColourToSelection()
00422 
00423     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00424     Created:    15/1/95
00425 
00426     Purpose:    Applies the dragged colour to the current selection
00427                 (including copying/merging the colour into the destination document
00428                 if necessary)
00429 
00430     Notes:      Assumes that the selection will be in the Selected Document!
00431    
00432 ********************************************************************************************/
00433 
00434 void ColourDragInformation::ApplyColourToSelection()
00435 {
00436 // WEBSTER-ranbirr-12/11/96 No colour bar stuff in webster
00437 // Neville 23/5/97 Now has a Browser palette in the colour line
00438     IndexedColour *ColToUse = GetColourForDocument(NULL);
00439 
00440     // ColourToApply now references a safe colour to use, or NULL (in which case it is
00441     // used as 'no colour' by the colour bar, which is exactly what we wanted. Fabby)
00442     CColourBar::TheColourBar->ApplyColour(ColToUse, IsAdjustDrag);
00443 }
00444 
00445 
00446 
00447 /********************************************************************************************
00448 
00449 >   void ColourDragInformation::GetCursorID(DragTarget* pDragTarget)
00450 
00451     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00452     Created:    25/3/95
00453     Purpose:    Set cursor over this target
00454 
00455 
00456 ********************************************************************************************/
00457 
00458 UINT32 ColourDragInformation::GetCursorID(DragTarget* pDragTarget)
00459 {
00460     if (pDragTarget->IS_KIND_OF(ViewDragTarget))
00461     {
00462         PageDropInfo PageDropInfo;
00463         ((ViewDragTarget*)pDragTarget)->GetDropInfo(&PageDropInfo);
00464 
00465 //      NodeRenderableInk* pObjectHit   = PageDropInfo.pObjectHit;
00466         ObjectDragTarget TargetHit      = PageDropInfo.TargetHit;
00467 
00468         ClickModifiers ClickMods = ClickModifiers::GetClickModifiers();
00469         BOOL IsInside = ClickMods.Constrain;
00470 
00471 //      Removed by Will 23/1/96
00472 //      This code was needed originally, but is no longer needed as the
00473 //      colour drop testing code is much smarter and copes with the case
00474 //      that this code is testing for.
00475 
00476 //      if (!IsInside && pObjectHit && pObjectHit->IsCompound())
00477 //      {
00478 //          TargetHit = MANY_TARGET;
00479 //      }
00480 
00481         switch (TargetHit)
00482         {
00483             case FILL_TARGET:
00484                 return IsInside ? _R(IDC_DROPINSIDEONFILL) : _R(IDC_CANDROPONFILL);
00485             case LINE_TARGET:
00486                 return IsInside ? _R(IDC_DROPINSIDEONLINE) : _R(IDC_CANDROPONLINE);
00487             case STARTCOL_TARGET:
00488                 return IsInside ? _R(IDC_DROPINSIDEONFILLSTART) : _R(IDC_CANDROPONFILLSTART);
00489             case ENDCOL_TARGET:
00490                 return IsInside ? _R(IDC_DROPINSIDEONFILLEND) : _R(IDC_CANDROPONFILLEND);
00491             case ENDCOL2_TARGET:
00492                 return IsInside ? _R(IDC_DROPINSIDEONFILLEND2) : _R(IDC_CANDROPONFILLEND2);
00493             case ENDCOL3_TARGET:
00494                 return IsInside ? _R(IDC_DROPINSIDEONFILLEND3) : _R(IDC_CANDROPONFILLEND3);
00495             case MANY_TARGET:
00496                 return IsInside ? _R(IDC_DROPINSIDEONFILL) : _R(IDC_CANDROPONFILL);
00497 
00498             case NO_TARGET:
00499                 // colour drag - drop = page fill, CTRL + drop = set current fill
00500                 return IsInside ? _R(IDC_CANFILLPAGE) : _R(IDC_CANDROPONPAGE);
00501                 //return _R(IDC_CANDROPONPAGE);
00502         };
00503 
00504         return _R(IDC_CANDROPONPAGE);
00505     }
00506 
00507     return 0;
00508 }
00509 
00510 
00511 
00512 /********************************************************************************************
00513 
00514 >   virtual BOOL ColourDragInformation::GetStatusLineText(String_256 * TheText, DragTarget* pDragTarget)
00515 
00516     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00517     Created:    25/3/95
00518     Returns:    Whether String is valid
00519     Purpose:    provide status line text for this target
00520    
00521 ********************************************************************************************/
00522 
00523 BOOL ColourDragInformation::GetStatusLineText(String_256 * TheText, DragTarget* pDragTarget)
00524 {
00525     ERROR2IF(TheText==NULL,FALSE,"NULL string in GetStatusLineText()");
00526 
00527     String_256 DragString(_R(IDS_DRAGCOL_DRAGGING_COLOUR)); // "Dragging colour '");
00528 
00529     if (TheColour.IsTransparent())
00530         DragString = _R(IDS_DRAGCOL_DRAGGING_NO_COLOUR);    // "Dragging 'no colour' : ";
00531     else
00532     {
00533         IndexedColour *TheIxCol = GetInitiallyDraggedColour();
00534         if (TheIxCol != NULL)
00535             DragString += *(TheIxCol->GetName());       // Document IndexedColour
00536         else
00537             DragString += ColourName;                   // Library colour
00538 
00539         DragString += String_16(_R(IDS_DRAGCOL_DRAGGING_COLOUR_RIGHT_BIT)); // "' : ";
00540     }
00541 
00542     if (pDragTarget->IS_KIND_OF(ViewDragTarget))
00543     {
00544         PageDropInfo PageDropInfo;
00545         ((ViewDragTarget*)pDragTarget)->GetDropInfo(&PageDropInfo);
00546 
00547         NodeRenderableInk* pObjectHit   = PageDropInfo.pObjectHit;
00548         ObjectDragTarget TargetHit      = PageDropInfo.TargetHit;
00549 
00550         String_256 ObjectDesc = _R(IDS_DRAGCOL_THIS_OBJECT); //" this object";
00551 
00552         if (pObjectHit)
00553         {
00554             ObjectDesc = pObjectHit->Describe(FALSE);
00555         }
00556 
00557         ClickModifiers ClickMods = ClickModifiers::GetClickModifiers();
00558         BOOL IsInside = ClickMods.Constrain;
00559 
00560         if (!IsInside && pObjectHit && pObjectHit->IsCompound())
00561         {
00562             TargetHit = MANY_TARGET;
00563         }
00564 
00565         switch (TargetHit)
00566         {
00567             case FILL_TARGET:
00568                 DragString += String_64(_R(IDS_DRAGCOL_DROP_SET_FILL)); // "Drop to set the fill colour of this ";
00569                 DragString += ObjectDesc;
00570                 if (IsInside)
00571                     DragString += String_64(_R(IDS_DRAGCOL_ALONE)); // " alone";
00572                 break;
00573             case LINE_TARGET:
00574                 DragString += String_64(_R(IDS_DRAGCOL_DROP_SET_LINE)); //"Drop to set the line colour of this ";
00575                 DragString += ObjectDesc;
00576                 if (IsInside)
00577                     DragString += String_64(_R(IDS_DRAGCOL_ALONE)); // " alone";
00578                 break;
00579             case STARTCOL_TARGET:
00580                 DragString += String_64(_R(IDS_DRAGCOL_DROP_SET_FILL_START)); //"Drop to set the fill start colour of this ";
00581                 DragString += ObjectDesc;
00582                 break;
00583             case ENDCOL_TARGET:
00584                 DragString += String_64(_R(IDS_DRAGCOL_DROP_SET_FILL_END)); //"Drop to set the fill end colour of this ";
00585                 DragString += ObjectDesc;
00586                 break;
00587             case ENDCOL2_TARGET:
00588                 DragString += String_64(_R(IDS_DRAGCOL_DROP_SET_FILL_END2)); //"Drop to set the fill end colour of this ";
00589                 DragString += ObjectDesc;
00590                 break;
00591             case ENDCOL3_TARGET:
00592                 DragString += String_64(_R(IDS_DRAGCOL_DROP_SET_FILL_END3)); //"Drop to set the fill end colour of this ";
00593                 DragString += ObjectDesc;
00594                 break;
00595             case MANY_TARGET:
00596                 DragString += String_64(_R(IDS_DRAGCOL_DROP_SET_FILL)); //"Drop to set the fill colour of this ";
00597                 DragString += ObjectDesc;
00598                 DragString += String_64(_R(IDS_DRAGCOL_PRESS_CONTROL)); // "; Press 'Control' to drop 'Inside'";
00599                 break;
00600 
00601             case NO_TARGET:
00602                 if (IsInside)
00603                 {
00604                     DragString += String_256(_R(IDS_DRAGCOL_DROP_SETPAGEBACKGROUND)); // "Drop to set the fill colour of the page background";
00605                 }
00606                 else
00607                 {
00608                     DragString += String_64(_R(IDS_DRAGCOL_DROP_SET_CURRENT_FILL_COLOUR)); // "Drop to set the 'current fill colour' attribute";
00609                 }
00610                 break;
00611         };
00612 
00613         *TheText = DragString;
00614         return TRUE;
00615     }
00616     
00617     return FALSE;
00618 }
00619 
00620 
00621 /********************************************************************************************
00622 
00623 >   virtual UINT32 ColourDragInformation::GetCursorID()
00624 
00625     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00626     Created:    15/1/95
00627     Returns:    a cursor ID to set during this drag
00628     Purpose:    Determines what cursor to display during a colour drag
00629    
00630 ********************************************************************************************/
00631 
00632 UINT32 ColourDragInformation::GetCursorID()
00633 {
00634     return(_R(IDC_DRAGGING_COLOUR));
00635 }
00636 
00637 
00638 
00639 /********************************************************************************************
00640 
00641 >   virtual BOOL ColourDragInformation::GetStatusLineText(String_256 * TheText)
00642 
00643     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00644     Created:    15/1/95
00645 
00646     Outputs:    TheText - If it returns TRUE, this is filled in with status line text
00647     Returns:    Whether String is valid
00648 
00649     Purpose:    provide status line text for this drag
00650    
00651 ********************************************************************************************/
00652 
00653 BOOL ColourDragInformation::GetStatusLineText(String_256 *TheText)
00654 {
00655     ERROR2IF(TheText==NULL,FALSE,"NULL string in GetStatusLineText()");
00656     String_32 LineString(_R(IDS_DRAGCOL_DRAGGING_LINE_COLOUR)); // "Dragging line colour : ");
00657     String_32 FillString(_R(IDS_DRAGCOL_DRAGGING_FILL_COLOUR)); // "Dragging fill colour : ");
00658     String_256 DragString;
00659 
00660     if(IsAdjustDrag)
00661         DragString = LineString;
00662     else
00663         DragString = FillString;
00664 
00665     if (TheColour.IsTransparent())
00666         DragString = _R(IDS_DRAGCOL_DRAGGING_NO_COLOUR);    //"Dragging 'no colour'";
00667     else
00668     {
00669         IndexedColour *TheIxCol = GetInitiallyDraggedColour();
00670         if (TheIxCol != NULL)
00671             DragString += *(TheIxCol->GetName());       // Document IndexedColour
00672         else
00673             DragString += ColourName;                   // Library colour
00674     }
00675 
00676     *TheText = DragString;
00677 
00678     return TRUE;
00679 }
00680 
00681 
00682 
00683 /********************************************************************************************
00684 
00685 >   void ColourDragInformation::OnClick(INT32 Flags,POINT Point) 
00686      
00687     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00688     Created:    12/1/95       
00689     Inputs:     
00690 
00691     Purpose:    This is called if a drag was attempted but never started because it was a 
00692                 click all along. In the base class, the default action is to make the
00693                 colour bar think that the dragged colour has been clicked.
00694 
00695 ********************************************************************************************/
00696 
00697 void ColourDragInformation::OnClick(INT32 Flags, CNativePoint Point)
00698 {
00699 //  WEBSTER-ranbirr-27/03/97 No colour bar stuff in webster
00700 // Neville 23/5/97 Now has a Browser palette in the colour line
00701 
00702     if (KeyPress::IsAdjustPressed())
00703         Flags = -1;
00704 
00705     wxRect RectMouseIsIn;
00706     Point = CColourBar::TheColourBar->ScreenToClient(Point);
00707     UINT32 MousePos = CColourBar::TheColourBar->WhereIsMouse(Point, &RectMouseIsIn);
00708 
00709     CColourBar::TheColourBar->CellClicked(MousePos, (Flags < 0));
00710 }
00711 
00712 
00713 
00714 /********************************************************************************************
00715 
00716 >   void ColourDragInformation::OnDrawSolidDrag(CRect DragRect,CDC * TheDC) 
00717      
00718     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00719     Created:    12/1/95       
00720     Inputs:     TheDC - pointer to a DC ready to draw into.
00721     Outputs:    -
00722     Returns:    -
00723     Purpose:    allows the drag to draw into a Device Context - DragManager will look after
00724                 painting the background etc.
00725     Errors:     -
00726     SeeAlso:    -
00727 
00728 ********************************************************************************************/
00729 
00730 BOOL ColourDragInformation::OnDrawSolidDrag(wxPoint Origin, wxDC *TheDC)
00731 {
00732     // set up gbrush
00733 //  CPalette * OldPal = NULL;
00734 //  if (PaletteManager::UsePalette())
00735 //  {
00736 //      OldPal = PaletteManager::StartPaintPalette( TheDC );
00737 //  }
00738 
00739     GBrush GDrawBrush;
00740     GDrawBrush.Init(TheDC);
00741     GDrawBrush.Start();
00742 
00743     // get a gbrush brush
00744     Document *ScopeDoc = Document::GetSelected();
00745     ERROR2IF(ScopeDoc == NULL, FALSE, "No Selected Doc !");
00746 
00747     wxBrush* pDragBrush = new wxBrush;
00748     
00749     BOOL BrushCreate = TRUE;
00750 
00751     if (pDragBrush != NULL )
00752     {
00753         if (TheColour.IsTransparent())
00754         {
00755 //          TheDC->SetBkColor(RGB(255,255,255));        // ensure white background
00756             pDragBrush->SetStyle(wxCROSSDIAG_HATCH);
00757             pDragBrush->SetColour(wxColour(0,0,0));     // Fill with black/white cross hatch
00758         }
00759         else
00760         {
00761             DWORD ScreenWord;
00762 
00763             ColourContextRGBT *CCrgbt = (ColourContextRGBT *)
00764                         ColourManager::GetColourContext(COLOURMODEL_RGBT, DocView::GetSelected());
00765             ScreenWord = ConvertColourToScreenWord(CCrgbt, &TheColour);
00766 
00767             // create the Brush and Pen
00768             if (GDrawBrush.Available())
00769             {
00770                 GDrawBrush.GetLogBrush((COLORREF)ScreenWord, pDragBrush);
00771             }
00772             else
00773                 pDragBrush->SetColour((COLORREF)ScreenWord);
00774         }
00775 
00776         wxPen MyPen(wxColour(0,0,0));
00777 
00778         // Set the brush origin so the dither (or Hatch) patterns
00779         // don't move around as you drag.
00780 //      TheDC->SetBrushOrg(Origin.x, Origin.y);
00781         
00782         //the rectangle to draw into
00783         wxRect DrawRect(Origin.x, Origin.y, SolidDragSize.x-1, SolidDragSize.y-1);
00784 
00785         // select brushes and pens ..
00786         TheDC->SetBrush(*pDragBrush);
00787         TheDC->SetPen(MyPen);
00788 
00789         // draw the thingy. In this case, it's a colour patch, circular for a spot colour, else a square
00790 #ifndef WEBSTER // don't distinguish spots in Webster Martin 15/07/97
00791         if (!TheColour.IsTransparent() && TheColour.GetSpotParent() != NULL)
00792             TheDC->DrawEllipse(DrawRect);
00793         else
00794 #endif // WEBSTER
00795             TheDC->DrawRectangle(DrawRect);
00796                                     
00797         // clean up the dc
00798         TheDC->SetBrush(wxNullBrush);
00799         TheDC->SetPen(wxNullPen);
00800 
00801         // delete the objects
00802         delete pDragBrush;
00803     }
00804     else
00805         BrushCreate = FALSE;
00806     
00807     // Finish with GBrush
00808     GDrawBrush.Stop();
00809 //  if (OldPal)
00810 //      PaletteManager::StopPaintPalette(TheDC, OldPal);
00811     
00812     // problems !!!
00813     ERROR2IF(!BrushCreate, FALSE, "Failed to make a solid drag brush!");
00814 
00815     return TRUE;
00816 }
00817 
00818 
00819 
00820 /********************************************************************************************
00821 
00822 >   virtual INT32 ColourDragInformation::GetDragTransparency()
00823  
00824     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00825     Created:    19/3/95       
00826     Returns:    -
00827     Purpose:    Specifies how transparent a drag should be.
00828                 A value of 0, will cause a normal solid blit.
00829                 Any other value (between 0 and 100), will cause a masked blit.
00830     SeeAlso:    -
00831 
00832 ********************************************************************************************/
00833 
00834 INT32 ColourDragInformation::GetDragTransparency()
00835 {
00836     return ColourDragInformation::DragTransparency;
00837 }
00838 
00839 
00840 
00841 /********************************************************************************************
00842 
00843 >   virtual BOOL ColourDragInformation::OnPageDrop(ViewDragTarget* pDragTarget)
00844 
00845     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00846     Created:    19/3/95       
00847     Returns:    TRUE if it succeeds, FALSE if there is an error
00848 
00849     Purpose:    Called when a colour is dropped on an Object.
00850 
00851     Notes:      This routine assumes that the destination document is the SELECTED doc
00852 
00853 ********************************************************************************************/
00854 
00855 BOOL ColourDragInformation::OnPageDrop(ViewDragTarget* pDragTarget)
00856 {
00857     PageDropInfo ThePageDropInfo;
00858     ((ViewDragTarget*)pDragTarget)->GetDropInfo(&ThePageDropInfo);
00859 
00860     DocCoord DragPos            = ThePageDropInfo.DropPos;
00861     ObjectDragTarget TargetType = ThePageDropInfo.TargetHit;
00862     NodeRenderableInk* ThisNode = ThePageDropInfo.pObjectHit;
00863 
00864     // DMc 4/10/99
00865     // test for dragging & dropping onto a bevel/shadow/other compound node which
00866     // is grouped
00867     if (ThisNode)
00868     {
00869         if (ThisNode->FindParent())
00870         {
00871             if (!ThisNode->FindParent()->PromoteHitTestOnChildrenToMe())
00872             {
00873                 // any compounds with their 'promotehittest' stuff set above me ?
00874                 Node * pNode = ThisNode->FindParent();
00875                 
00876                 while (pNode)
00877                 {
00878                     if (pNode->IsAnObject())
00879                     {
00880                         if (pNode->PromoteHitTestOnChildrenToMe())
00881                         {
00882                             ThisNode = (NodeRenderableInk *)pNode;
00883                         }
00884                     }
00885                     
00886                     pNode = pNode->FindParent();
00887                 }
00888             }
00889         }
00890     }
00891 
00892     NodeAttribute *Attrib = NULL;
00893     
00894     // Get a colour to apply to the Selected doc
00895     IndexedColour *IxColToApply = GetColourForDocument(NULL);
00896 
00897     // And make a DocColour to apply
00898     DocColour ColourToApply(COLOUR_TRANS);
00899     if (IxColToApply != NULL)
00900         ColourToApply.MakeRefToIndexedColour(IxColToApply);
00901 
00902 
00903     if (TargetType == LINE_TARGET) // apply a stroke colour
00904     {
00905         // Apply a stroke colour to the object(s) we have been dropped onto
00906         Attrib = new AttrStrokeColourChange;
00907         if (Attrib == NULL)
00908             return FALSE;
00909 
00910         ((AttrStrokeColourChange *)Attrib)->SetStartColour(&ColourToApply);
00911         AttributeManager::ApplyAttribToNode(ThisNode, Attrib);
00912     }
00913     else          
00914     {
00915         // Apply a fill colour to the object(s) we have been dropped onto
00916         // This always used to be the case. If there were no objects then we
00917         // just set the current fill colour to be the new one.
00918         // Now, if no objects are the target then apply a page background colour
00919         // otherwise if control is held down set the current fill colour.
00920         
00921         BOOL Constrain = FALSE;
00922 
00923         // get object bounds
00924         DocRect pSimpleBounds;
00925         if (ThisNode)
00926             pSimpleBounds = ThisNode->GetBoundingRect();
00927         else
00928         {
00929             pSimpleBounds.MakeEmpty();
00930             // See if the control key is pressed
00931             Constrain = KeyPress::IsConstrainPressed();
00932         }
00933 
00934         // No node(s) are targetted so see if the constrain key is pressed or not
00935         if (ThisNode == NULL && Constrain)
00936         {
00937             // Use the colour to set the background
00938             // We should use the document given to us by the page info class
00939             OpBackgroundParam Param;
00940             Param.pDocColour = &ColourToApply;
00941             Param.pDoc = ThePageDropInfo.pDoc;          
00942             Param.pSpread = ThePageDropInfo.pSpread;
00943             
00944             // Obtain a pointer to the op descriptor for the create operation 
00945             OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_BACKGROUND);
00946 
00947             // Invoke the operation, passing in our parameters
00948             pOpDesc->Invoke(&Param);
00949         }
00950         else
00951         {
00952             // Apply the colour either to the targetted node(s) or as the current
00953             // fill colour, if no nodes are targetted.
00954             Attrib = new AttrColourDrop(DragPos, pSimpleBounds, ColourToApply);
00955             if (Attrib == NULL)
00956                 return FALSE;
00957 
00958             if (ThisNode)
00959                 ((AttrColourDrop*)Attrib)->SetObjectDroppedOn(ThisNode);
00960 
00961             AttributeManager::ApplyAttribToNode(ThisNode, Attrib);
00962         }
00963     }
00964 
00965     return TRUE;
00966 }
00967 

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