dragpick.cpp

Go to the documentation of this file.
00001 // $Id: dragcol.cpp 1149 2006-05-22 08:50:00Z 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 "dragpick.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(ColourPickerDragInformation, 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 ColourPickerDragInformation::DragTransparency = 0;
00141 
00142 
00143 
00144 /********************************************************************************************
00145 
00146 >   void ColourPickerDragInformation::InitObject(void)
00147      
00148     Author:     Alex Bligh <alex@alex.org.uk>
00149     Created:    30/05/2006
00150 
00151     Purpose:    Shared code for initialising the object - called by all constructors
00152 
00153 ********************************************************************************************/
00154 
00155 void ColourPickerDragInformation::InitObject(void)
00156 {
00157     // Init member variables
00158     TheColour = DocColour(COLOUR_TRANS);
00159     m_Status=NO_COLOUR;
00160 
00161     // Set up a few things about this drag
00162     DoesSolidDrag = TRUE;
00163     
00164     // offset of colour swatch from the pointer
00165     SolidDragOffset.x = 14;
00166     SolidDragOffset.y = 4;     
00167     
00168     // size of the solid drag redraw
00169     SolidDragSize.x = CellSize;
00170     SolidDragSize.y = CellSize;
00171 }
00172 
00173 
00174 
00175 /********************************************************************************************
00176 
00177 >   void ColourPickerDragInformation::ColourPickerDragInformation() 
00178      
00179     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00180     Created:    12/1/95       
00181 
00182     Purpose:    Constructor
00183 
00184 ********************************************************************************************/
00185 
00186 ColourPickerDragInformation::ColourPickerDragInformation()
00187 {
00188     InitObject();
00189 }
00190 
00191 
00192 /********************************************************************************************
00193 
00194 >   static BOOL ColourPickerDragInformation::Init()
00195 
00196     Author:     Alex Bligh <alex@alex.org.uk>
00197     Created:    30/05/2006
00198     Returns:    -
00199     Purpose:    Initialise any Colour Drag stuff. (eg. ini file preferences).
00200     SeeAlso:    -
00201 
00202 ********************************************************************************************/
00203 
00204 BOOL ColourPickerDragInformation::Init()
00205 {
00206     // Setup preference for drag transparency
00207     if (GetApplication()->DeclareSection(_T("Dragging"), 1))
00208         GetApplication()->DeclarePref( NULL, _T("ColourPickerDragTransparency"), &DragTransparency, 0, 100);
00209 
00210     return TRUE;
00211 }
00212 
00213 
00214 
00215 
00216 /********************************************************************************************
00217 
00218 >   void ColourPickerDragInformation::GetCursorID(DragTarget* pDragTarget)
00219 
00220     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00221     Created:    25/3/95
00222     Purpose:    Set cursor over this target
00223 
00224 
00225 ********************************************************************************************/
00226 
00227 UINT32 ColourPickerDragInformation::GetCursorID(DragTarget* pDragTarget)
00228 {
00229     return GetCursorID();
00230 }
00231 
00232 
00233 
00234 /********************************************************************************************
00235 
00236 >   virtual BOOL ColourPickerDragInformation::GetStatusLineText(String_256 * TheText, DragTarget* pDragTarget)
00237 
00238     Author:     Alex Bligh <alex@alex.org.uk>
00239     Created:    30/05/2006
00240     Returns:    Whether String is valid
00241     Purpose:    provide status line text for this target
00242    
00243 ********************************************************************************************/
00244 
00245 BOOL ColourPickerDragInformation::GetStatusLineText(String_256 * TheText, DragTarget* pDragTarget)
00246 {
00247     return GetStatusLineText(TheText);
00248 }
00249 
00250 
00251 /********************************************************************************************
00252 
00253 >   virtual UINT32 ColourPickerDragInformation::GetCursorID()
00254 
00255     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00256     Created:    15/1/95
00257     Returns:    a cursor ID to set during this drag
00258     Purpose:    Determines what cursor to display during a colour drag
00259    
00260 ********************************************************************************************/
00261 
00262 UINT32 ColourPickerDragInformation::GetCursorID()
00263 {
00264     switch (m_Status)
00265     {
00266         case DOC_COLOUR:
00267             return _R(IDC_COLOURPICKERCURSORDOC);
00268         case SCREEN_COLOUR:
00269             return _R(IDC_COLOURPICKERCURSOR);
00270         case COLOURBAR_COLOUR:
00271             return _R(IDC_COLOURPICKERCURSORCOLBAR);
00272         default:
00273             break;
00274     }
00275 
00276     return(_R(IDC_COLOURPICKERCURSORNOREAD));
00277 }
00278 
00279 
00280 
00281 /********************************************************************************************
00282 
00283 >   virtual BOOL ColourPickerDragInformation::GetStatusLineText(String_256 * TheText)
00284 
00285     Author:     Alex Bligh <alex@alex.org.uk>
00286     Created:    30/05/2006
00287 
00288     Outputs:    TheText - If it returns TRUE, this is filled in with status line text
00289     Returns:    Whether String is valid
00290 
00291     Purpose:    provide status line text for this drag
00292    
00293 ********************************************************************************************/
00294 
00295 BOOL ColourPickerDragInformation::GetStatusLineText(String_256 *TheText)
00296 {
00297     ResourceID r;
00298     switch (m_Status)
00299     {
00300         case DOC_COLOUR:
00301             r = _R(IDS_DRAGGINGCOLOURPICKERTOOLDOCRC);
00302             break;
00303         case SCREEN_COLOUR:
00304             r = _R(IDS_DRAGGINGCOLOURPICKERTOOLRS);
00305             break;
00306         case COLOURBAR_COLOUR:
00307             r = _R(IDS_DRAGGINGCOLOURPICKERTOOLCOLOURBARRC);
00308             break;
00309         default:
00310             r = _R(IDS_DRAGGINGCOLOURPICKERTOOLNOREAD);
00311     }
00312 
00313     *TheText=String_256(r);
00314     return TRUE;
00315 }
00316 
00317 
00318 
00319 
00320 /********************************************************************************************
00321 
00322 >   void ColourPickerDragInformation::OnDrawSolidDrag(CRect DragRect,CDC * TheDC) 
00323      
00324     Author:     Alex Bligh <alex@alex.org.uk>
00325     Created:    30/05/2006
00326     Inputs:     TheDC - pointer to a DC ready to draw into.
00327     Outputs:    -
00328     Returns:    -
00329     Purpose:    allows the drag to draw into a Device Context - DragManager will look after
00330                 painting the background etc.
00331     Errors:     -
00332     SeeAlso:    -
00333 
00334 ********************************************************************************************/
00335 
00336 BOOL ColourPickerDragInformation::OnDrawSolidDrag(wxPoint Origin, wxDC *TheDC)
00337 {
00338     if (m_Status == NO_COLOUR)
00339         return FALSE;   
00340 
00341     // set up gbrush
00342 //  CPalette * OldPal = NULL;
00343 //  if (PaletteManager::UsePalette())
00344 //  {
00345 //      OldPal = PaletteManager::StartPaintPalette( TheDC );
00346 //  }
00347 
00348     GBrush GDrawBrush;
00349     GDrawBrush.Init(TheDC);
00350     GDrawBrush.Start();
00351 
00352     // get a gbrush brush
00353     Document *ScopeDoc = Document::GetSelected();
00354     ERROR2IF(ScopeDoc == NULL, FALSE, "No Selected Doc !");
00355 
00356     wxBrush* pDragBrush = new wxBrush;
00357     
00358     BOOL BrushCreate = TRUE;
00359 
00360     if (pDragBrush != NULL )
00361     {
00362         if (TheColour.IsTransparent())
00363         {
00364 //          TheDC->SetBkColor(RGB(255,255,255));        // ensure white background
00365             pDragBrush->SetStyle(wxCROSSDIAG_HATCH);
00366             pDragBrush->SetColour(wxColour(0,0,0));     // Fill with black/white cross hatch
00367         }
00368         else
00369         {
00370             DWORD ScreenWord;
00371 
00372             ColourContextRGBT *CCrgbt = (ColourContextRGBT *)
00373                         ColourManager::GetColourContext(COLOURMODEL_RGBT, DocView::GetSelected());
00374             ScreenWord = ConvertColourToScreenWord(CCrgbt, &TheColour);
00375 
00376             // create the Brush and Pen
00377             if (GDrawBrush.Available())
00378             {
00379                 GDrawBrush.GetLogBrush((COLORREF)ScreenWord, pDragBrush);
00380             }
00381             else
00382                 pDragBrush->SetColour((COLORREF)ScreenWord);
00383         }
00384 
00385         wxPen MyPen(wxColour(0,0,0));
00386 
00387         // Set the brush origin so the dither (or Hatch) patterns
00388         // don't move around as you drag.
00389 //      TheDC->SetBrushOrg(Origin.x, Origin.y);
00390         
00391         //the rectangle to draw into
00392         wxRect DrawRect(Origin.x, Origin.y, SolidDragSize.x-1, SolidDragSize.y-1);
00393 
00394         // select brushes and pens ..
00395         TheDC->SetBrush(*pDragBrush);
00396         TheDC->SetPen(MyPen);
00397 
00398         // draw the thingy. In this case, it's a colour patch, circular for a spot colour, else a square
00399 #ifndef WEBSTER // don't distinguish spots in Webster Martin 15/07/97
00400         if (!TheColour.IsTransparent() && TheColour.GetSpotParent() != NULL)
00401             TheDC->DrawEllipse(DrawRect);
00402         else
00403 #endif // WEBSTER
00404             TheDC->DrawRectangle(DrawRect);
00405                                     
00406         // clean up the dc
00407         TheDC->SetBrush(wxNullBrush);
00408         TheDC->SetPen(wxNullPen);
00409 
00410         // delete the objects
00411         delete pDragBrush;
00412     }
00413     else
00414         BrushCreate = FALSE;
00415     
00416     // Finish with GBrush
00417     GDrawBrush.Stop();
00418 //  if (OldPal)
00419 //      PaletteManager::StopPaintPalette(TheDC, OldPal);
00420     
00421     // problems !!!
00422     ERROR2IF(!BrushCreate, FALSE, "Failed to make a solid drag brush!");
00423 
00424     return TRUE;
00425 }
00426 
00427 
00428 
00429 /********************************************************************************************
00430 
00431 >   virtual INT32 ColourPickerDragInformation::GetDragTransparency()
00432  
00433     Author:     Alex Bligh <alex@alex.org.uk>
00434     Created:    30/05/2006
00435     Returns:    -
00436     Purpose:    Specifies how transparent a drag should be.
00437                 A value of 0, will cause a normal solid blit.
00438                 Any other value (between 0 and 100), will cause a masked blit.
00439     SeeAlso:    -
00440 
00441 ********************************************************************************************/
00442 
00443 INT32 ColourPickerDragInformation::GetDragTransparency()
00444 {
00445     return ColourPickerDragInformation::DragTransparency;
00446 }
00447 
00448 
00449 /********************************************************************************************
00450 
00451 >   virtual BOOL ColourPickerDragInformation::OnMouseMove(wxPoint p)
00452  
00453     Author:     Alex Bligh <alex@alex.org.uk>
00454     Created:    30/05/2006
00455     Returns:    -
00456     Purpose:    Called on a mouse move. Find the doc colour under point p
00457     SeeAlso:    -
00458 
00459 ********************************************************************************************/
00460 
00461 BOOL ColourPickerDragInformation::OnMouseMove(wxPoint p)
00462 {
00463     Status OldStatus = m_Status;
00464     m_Status = SCREEN_COLOUR;
00465     DocColour col(COLOUR_TRANS);
00466 
00467     CWindowID   WinID=::wxChildWindowFromPoint(p, FALSE, -1);
00468     DocView*    pDocView=NULL;
00469     Spread*     pSpread=NULL;
00470     WinCoord    WndPos(0,0);
00471     DocCoord    DocPos(0,0);
00472 
00473     ColourEditDlg* pColourEditDlg = ColourEditDlg::GetColourEditDlg ();
00474     // Check we can't pick from the colour picker
00475     wxWindow * w = WinID;
00476     while (w)
00477     {
00478         if (pColourEditDlg && (w==pColourEditDlg->WindowID))
00479         {
00480             // No picking colours from the colour editor
00481             m_Status = NO_COLOUR;
00482             break;
00483         }
00484         if (w->IsKindOf(CLASSINFO(CColourBar)))
00485         {
00486             wxPoint cpoint = w->ScreenToClient(p);
00487             if (((CColourBar*) w)->IsColourPickerOverStripRect (w, cpoint))
00488             {
00489                 IndexedColour * pIndexedColour = NULL;
00490                 m_Status = COLOURBAR_COLOUR;
00491                 ((CColourBar*) w)->DoColourPickerColour (w, cpoint, &pIndexedColour);
00492                 if (pIndexedColour)
00493                 {
00494                     // Disassociate from indexed colour
00495                     DocColour Temp;
00496                     Temp.MakeRefToIndexedColour(pIndexedColour);
00497                     INT32 r, g, b;
00498                     Temp.GetRGBValue(&r, &g, &b);
00499                     col = DocColour(r, g, b);
00500                 }
00501                 break;
00502             }
00503         }
00504         w=w->GetParent();
00505     }
00506 
00507     Pixel32bpp Pix;
00508     NodeRenderableInk* pNode = NULL;
00509 
00510     if (m_Status == SCREEN_COLOUR)
00511     {
00512         if (WinID != NULL)
00513             pDocView=CCamView::GetDocViewFromWindowID(WinID);
00514     
00515         if (pDocView != NULL)
00516         {
00517             OilCoord OilPos = WndPos.ToOil(pDocView, TRUE);
00518             pSpread = pDocView->OilToSpreadCoord(OilPos, &DocPos);
00519         }
00520     
00521         if (pDocView)       // were over an active (or inactive document)
00522         {
00523             if (pDocView==DocView::GetSelected())
00524             {
00525                 pNode = NodeRenderableInk::FindSimpleAtPointForColourPicker (pSpread, DocPos, Pix);
00526                 m_Status = DOC_COLOUR;
00527             }
00528             else
00529             {   
00530                 m_Status = SCREEN_COLOUR;
00531             }
00532         }
00533     }
00534 
00535     switch (m_Status)
00536     {
00537         case DOC_COLOUR:
00538         {
00539             const double conversion = 1.0/255.0;
00540                             
00541             FIXED24 rValF24 = Pix.Red * conversion;
00542             FIXED24 gValF24 = Pix.Green * conversion;
00543             FIXED24 bValF24 = Pix.Blue * conversion;
00544             FIXED24 tValF24 = Pix.Alpha * conversion;
00545             
00546             //DocColour* TheColour = new DocColour (rValF24, gValF24, bValF24);
00547             ColourRGBT TheColourRGBT;
00548             TheColourRGBT.Red = rValF24;
00549             TheColourRGBT.Green = gValF24;
00550             TheColourRGBT.Blue = bValF24;
00551             TheColourRGBT.Transparent = tValF24;
00552             col = DOCCOLOUR_RGBT(&TheColourRGBT);//DocColour (rValF24, gValF24, bValF24);
00553         }
00554 
00555         case SCREEN_COLOUR:
00556         {
00557             wxColour c(*wxBLACK);
00558             ScreenDC.GetPixel(p, &c);
00559 
00560             const double conversion = 1.0/255.0;
00561 
00562             FIXED24 rValF24 = c.Red() * conversion;
00563             FIXED24 gValF24 = c.Green() * conversion;
00564             FIXED24 bValF24 = c.Blue() * conversion;
00565 
00566             col=DocColour(rValF24, gValF24, bValF24);
00567         }
00568 
00569         case COLOURBAR_COLOUR:
00570         default:
00571             break;
00572 
00573     }
00574 
00575     if ((OldStatus != m_Status ) || (col !=TheColour))
00576     {
00577         TheColour = col;
00578 
00579         // COLOURBAR_COLOUR has already updated the colour picker
00580         if ((m_Status != NO_COLOUR) && (m_Status != COLOURBAR_COLOUR))
00581         {
00582             IndexedColour* theIndexedColour = ColourManager::GenerateNewUnnamedColour (ColourManager::GetColourList(), &TheColour);
00583     
00584             // Tell the colour edit dlg about the node that this colour came
00585             // from so it can block attribute application if its the same node
00586             if (pColourEditDlg && theIndexedColour)
00587                 pColourEditDlg->SetEditingColour (theIndexedColour, pNode);
00588             //pColourEditDlg->SetEditingColour (theIndexedColour);
00589         }
00590 
00591     }
00592 
00593     return TRUE;
00594 }

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