oilruler.cpp

Go to the documentation of this file.
00001 // $Id: oilruler.cpp 1535 2006-07-25 16:50:32Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 /*
00100 */
00101 
00102 #include "camtypes.h"
00103 
00104 // WEBSTER - markn 15/1/97
00105 // No rulers in Webster
00106 #ifndef WEBSTER
00107 
00108 //#include "ensure.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 #include "oilruler.h"
00110 //#include "mainfrm.h"
00111 //#include "camafx.h"
00112 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00113 //#include "mario.h"
00114 //#include "winrect.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00115 #include "camview.h"
00116 #include "rulers.h"
00117 //#include "fonts.h"
00118 #include "guides.h"
00119 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00120 #include "camelot.h"
00121 #include "statline.h"
00122 //#include "ed.h"
00123 #include "ctrlhelp.h"
00124 //#include "ops.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00125 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00126 //#include "richard2.h" // For naughty inline strings...
00127 #include "basebar.h"
00128 #include "brushmsg.h"
00129 #include "cartprov.h"
00130 
00131 //#ifdef _DEBUG
00132 //  #undef THIS_FILE
00133 //  static char BASED_CODE THIS_FILE[] = __FILE__;
00134 //#endif
00135 
00136 #define MAJOR_GRAT_LEN 6
00137 #define MIN_PIXEL_GRATICULE_SPACING_X 5
00138 #define MIN_PIXEL_GRATICULE_SPACING_Y 5
00139 
00140 // statics ...
00141 String_256*         OILRuler::FontName         = NULL; /*String_256(_R(IDS_OILRULER_SMALL_FONTS)); "Small Fonts";*/ // - read from config
00142 INT32               OILRuler::FontSize         = 7;             // read from config
00143 INT32               OILRuler::RenderWidth      = 0;     // this is set up on app start up
00144 UINT32              OILRuler::RulerWidth       = 0;     // actually offset to next bar (based on RenderWidth)
00145 INT32               OILRuler::CharHeight       = 0;
00146 INT32               OILRuler::CharWidth        = 0;
00147 DocView*            OILRuler::pPaintDocView    = NULL;
00148 wxDC*               OILRuler::pPaintDC         = NULL;
00149 wxSize              OILRuler::RulerToDocOffset = wxSize(0,0);
00150 OpGuidelineParam    OILRuler::NewGuidelineParam;
00151 
00152 
00154 //                                   OILRuler Base Class
00156 
00157 IMPLEMENT_DYNAMIC_CLASS(OILRuler, wxWindow)
00158 
00159 // Declare smart memory handling in Debug builds
00160 #define new CAM_DEBUG_NEW
00161 
00162 BEGIN_EVENT_TABLE( OILRuler, wxWindow )
00163     EVT_LEFT_DOWN(      OILRuler::OnLButtonDown)
00164     EVT_LEFT_DCLICK(    OILRuler::OnLButtonDblClk)
00165     EVT_LEFT_UP(        OILRuler::OnLButtonUp)
00166     EVT_MIDDLE_DOWN(    OILRuler::OnMButtonDown)
00167     EVT_MIDDLE_DCLICK(  OILRuler::OnMButtonDblClk)
00168     EVT_MIDDLE_UP(      OILRuler::OnMButtonUp)
00169     EVT_RIGHT_DOWN(     OILRuler::OnRButtonDown)
00170     EVT_RIGHT_DCLICK(   OILRuler::OnRButtonDblClk)
00171     EVT_RIGHT_UP(       OILRuler::OnRButtonUp)
00172     EVT_MOTION(         OILRuler::OnMouseMove)
00173     EVT_PAINT(          OILRuler::OnPaint)
00174     EVT_SET_FOCUS(      OILRuler::OnFocus)
00175 END_EVENT_TABLE()
00176 
00177 
00178 /********************************************************************************************
00179 >   static BOOL OILRuler::Init()
00180 
00181     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
00182     Created:    25/9/95
00183     Returns:    FALSE if fails
00184     Purpose:    read the font name and size for the ruler from config
00185                 and use this to determine the size of the rulers
00186 ********************************************************************************************/
00187 
00188 BOOL OILRuler::Init()
00189 {
00190     if (FontName == NULL)
00191         FontName = new String_256(_R(IDS_OILRULER_SMALL_FONTS));
00192 
00193     BOOL ok=GetApplication()->DeclareSection(_T("Rulers"), 2);
00194     if (ok && FontName != NULL) ok=GetApplication()->DeclarePref(_T("Rulers"), _T("FontName"), FontName);
00195     if (ok) ok=GetApplication()->DeclarePref(_T("Rulers"), _T("FontSize"), &FontSize, 2,72);
00196     if (!ok)
00197         return FALSE;
00198     ERROR2IF(FontName == NULL,FALSE,"OILRuler::SetRenderWidth() - couldn't create a string_256 - eek !");
00199     if (FontName->Length()==0)
00200         FontName->Load(_R(IDS_OILRULER_SMALL_FONTS));
00201     ERROR2IF(FontName->Length()==0,FALSE,"OILRuler::SetRenderWidth() - invalid FontName in config");
00202 
00203     WinRect WinTextSize;
00204     ok=GetTextSize(&WinTextSize, _T("8"));
00205     if (!ok)
00206         return FALSE;
00207 
00208     CharHeight  = WinTextSize.GetHeight();
00209     CharWidth   = WinTextSize.GetWidth();
00210     RenderWidth = CharWidth*3 + 4;
00211 
00212     return TRUE;
00213 }
00214 
00215 
00216 /********************************************************************************************
00217 >   static void OILRuler::Deinit()
00218 
00219     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00220     Created:    15/11/95
00221     Purpose:    return memory 'new'd by the Init function
00222 ********************************************************************************************/
00223 
00224 void OILRuler::Deinit()
00225 {
00226     if(FontName != NULL)
00227     {
00228         delete FontName;
00229         FontName = NULL;
00230     }
00231 }
00232 
00233 
00234 
00235 
00236 /********************************************************************************************
00237 >   static wxFont OILRuler::GetRulerFont()
00238 
00239     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00240     Created:    28/Jun/2006
00241     Purpose:    Get a stock font for use in rulers
00242 ********************************************************************************************/
00243 
00244 wxFont OILRuler::GetRulerFont()
00245 {
00246 PORTNOTE("ruler", "Temporarilly replace font factory with direct wxFont access")
00247 #if !defined(EXCLUDE_FROM_XARALX)
00248         wxFont font = FontFactory::GetFont(STOCKFONT_RULERS);
00249 #else
00250     wxFont FixedFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
00251     FixedFont.SetPointSize(OILRuler::FontSize);     // 6 is too small, 7 is too big, really...
00252 
00253     return FixedFont;
00254 #endif
00255 }
00256 
00257 
00258 
00259 
00260 /********************************************************************************************
00261 >   void OILRuler::PatB(wxDC* pDC, INT32 x, INT32 y, INT32 dx, INT32 dy, wxColour rgb)
00262 
00263     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00264     Created:    14/3/94
00265     Inputs:     hDC - destination DC
00266                 x,y,dx,dy - rectangle to fill
00267                 rgb - colour to fill with
00268     Purpose:    Paints a rectangle in the given (dithered) colour
00269 ********************************************************************************************/
00270 
00271 void OILRuler::PatB(wxDC* pDC, INT32 x, INT32 y, INT32 dx, INT32 dy, wxColour rgb)
00272 {
00273     wxRect rect;
00274     rect.x  = x;
00275     rect.y  = y;
00276     rect.width  = dx;
00277     rect.height = dy;
00278 
00279     wxBrush brush(rgb);
00280     pDC->SetBrush(brush);
00281     pDC->DrawRectangle(rect);
00282 }
00283 
00284 
00285 
00286 
00287 /********************************************************************************************
00288 >   OILRuler::OILRuler()
00289 
00290     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00291     Created:    25/8/95
00292     Purpose:    Creates an OILRuler object.
00293 ********************************************************************************************/
00294                     
00295 OILRuler::OILRuler()
00296 { 
00297     InDrag       = FALSE;
00298     pKernelRuler = NULL;
00299 
00300     // if ruler has a border, the ruler has a one pixel black border,
00301     // one side of this border overlaps with the adjacent bar etc
00302     // so the offset to the next bar etc must only account for 1 of the 2 border pixels
00303     ERROR3IF(RenderWidth==0,"OILRuler::OILRuler() - RenderWidth==0 (not initialised!)");
00304 
00305     RulerWidth = RenderWidth;
00306 }
00307 
00308 
00309 /********************************************************************************************
00310 >   BOOL OILRuler::Create(CCamView* pOwnerView, INT32 id)
00311 
00312     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00313     Created:    5/3/94
00314     Inputs:     pParentWindow - 
00315     Returns:    FALSE if fails
00316     Purpose:    Creates the ruler window.
00317 ********************************************************************************************/
00318                     
00319 BOOL OILRuler::Create(CCamView* pOwnerView, INT32 id)
00320 { 
00321     ERROR2IF(pOwnerView==NULL, FALSE, "DockingBar must have a Parent");
00322     
00323     m_pOwnerView = pOwnerView;
00324 
00325     if (!wxWindow::Create(pOwnerView->GetParentFrame(), id, wxDefaultPosition, wxSize(RulerWidth, RulerWidth), wxNO_BORDER))
00326         return(FALSE);
00327 
00328     PostCreate();
00329 
00330     return TRUE;
00331 }
00332 
00333 
00334 /********************************************************************************************
00335 >   virtual BOOL OILRuler::StartDrag(UINT32 nFlags, wxPoint point)
00336 
00337     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00338     Created:    5/3/94
00339     Returns:    FALSE if fails
00340     Purpose:    base StartDrag function  - don't call
00341 ********************************************************************************************/
00342                     
00343 BOOL OILRuler::StartDrag(UINT32 nFlags, wxPoint point)
00344 { 
00345     return TRUE;
00346 }
00347 
00348 /********************************************************************************************
00349 >   BOOL OILRuler::StartToolDrag(ClickModifiers Mods, wxPoint point, String_256* OpToken, void* Params)
00350 
00351     Author:     Martin Wuerthner <xara@mw-software.com>
00352     Created:    12/07/06
00353     Input:      Mods - the click modifiers (as passed to OnRulerClick)
00354                 point - the pointer position (as passed to OnRulerClick)
00355                 OpToken - name of the operation to invoke
00356                 Params - an opaque pointer to the parameters for the operation
00357     Returns:    FALSE if fails
00358     Purpose:    StartDrag function for tool drags.
00359 ********************************************************************************************/
00360                     
00361 BOOL OILRuler::StartToolDrag(ClickModifiers Mods, OilCoord point, String_256* pOpToken, OpParam* pParam)
00362 {
00363     if (m_pOwnerView != NULL)
00364     {
00365         DocView* pDocView = m_pOwnerView->GetDocViewPtr();
00366         wxPoint ClientPoint = point.ToWin(pDocView);
00367         m_pOwnerView->InvokeDragOp(pOpToken, pParam, Mods, ClientPoint);
00368         return TRUE;
00369     }
00370 
00371     return FALSE;
00372 }
00373 
00374 /*********************************************************************************************
00375 >   void OILRuler::ShowRuler(BOOL show)
00376 
00377     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00378     Created:    25/8/95
00379     Inputs:     show - FALSE to hide the ruler
00380     Purpose:    Shows or hides this ruler
00381 **********************************************************************************************/ 
00382 
00383 void OILRuler::ShowRuler(BOOL show)
00384 {
00385     Show(show);
00386     
00387     BROADCAST_TO_ALL(ScreenChangeMsg());
00388 
00389     if (show)
00390     {
00391         // we need to take into account camelots new floating toolbar ....
00392 
00393 PORTNOTE("ruler", "Removed code to move floating toolbars")
00394 #if !defined(EXCLUDE_FROM_XARALX)
00395         DockBarType DockBarType;// = DOCKBAR_FLOAT;
00396         KernelBarPos * pKernelBarPos;
00397 
00398         // find out where the toolbar is docked
00399         GetMainFrame()->GetBarPosInfo(&(String_32 ("Toolbar")), &DockBarType, &pKernelBarPos);
00400 
00401         if (DockBarType == DOCKBAR_FLOAT)
00402         {
00403             RECT MainFrameWindowRect;
00404             ::GetWindowRect (GetSafeHwnd (), &MainFrameWindowRect);
00405 
00406             POINT ToolbarTL;
00407             ToolbarTL.x = pKernelBarPos->x;
00408             ToolbarTL.y = pKernelBarPos->y;
00409 
00410             if (PtInRect (&MainFrameWindowRect, ToolbarTL))
00411             {
00412                 KernelBarPos NewToolBarPos = *pKernelBarPos;
00413                 BaseBar* PtrToToolBar = BaseBar::GetPtrToToolBar ();
00414                 
00415                 // then we need to move the toolbar ....
00416                 if (IsHorizontal ())
00417                 {
00418                     INT32 dy = MainFrameWindowRect.bottom - ToolbarTL.y;
00419                     NewToolBarPos.y += dy;
00420                 }
00421                 else // its the vertical ruler
00422                 {
00423                     INT32 dx = MainFrameWindowRect.right - ToolbarTL.x;
00424                     NewToolBarPos.x += dx;
00425                 }
00426 
00427                 if (PtrToToolBar)
00428                 {
00429                     PtrToToolBar->MoveBar ((WPARAM) DOCKBAR_FLOAT, (LPARAM) &NewToolBarPos);
00430                 }
00431             }
00432         }
00433 #endif
00434     }
00435 } 
00436 
00437 
00438 /*********************************************************************************************
00439 >   void OILRuler::UpdateRuler()
00440 
00441     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00442     Created:    25/8/95
00443     Inputs:     -
00444     Purpose:    Redraw the whole ruler
00445 **********************************************************************************************/ 
00446 
00447 void OILRuler::UpdateRuler()
00448 {
00449     Refresh();
00450     Update();
00451 } 
00452 
00453 
00454 /********************************************************************************************
00455 >   virtual OILRuler::~OILRuler()
00456 
00457     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00458     Created:    25/8/95
00459     Purpose:    Destroys an OILRuler object 
00460 ********************************************************************************************/
00461 
00462 OILRuler::~OILRuler()
00463 {
00464 }
00465  
00466 
00467 /*********************************************************************************************
00468 >   void OILRuler::OnPaint( wxPaintEvent &evnt )
00469 
00470     Author:     Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
00471     Created:    ages ago
00472     Inputs:     -
00473     Outputs:    -
00474     Returns:    -
00475     Purpose:    Redraws the colour bar
00476     Errors:     -
00477 
00478 **********************************************************************************************/ 
00479 void OILRuler::OnPaint( wxPaintEvent &evnt )
00480 {
00481     // Always create this so that the area is validated
00482     wxPaintDC dc(this);
00483 
00484     if (!CCamApp::IsDisabled())
00485     {
00486         DoPaint(&dc);
00487     }
00488 }
00489 
00490 
00491 
00492 /*********************************************************************************************
00493 >   void OILRuler::DoPaint(wxDC* pDC)
00494 
00495     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00496     Created:    25/8/95
00497     Purpose:    Paints the client area of the Ruler which isn't covered by child windows,
00498                 in response to a WM_PAINT message.
00499 **********************************************************************************************/
00500 
00501 void OILRuler::DoPaint(wxDC* pDC)
00502 {
00503     // get and validate a few pointers before we start
00504     DocView* pDocView = m_pOwnerView->GetDocViewPtr();
00505     if (pDocView==NULL)
00506     {
00507         ERROR2RAW("OILRuler::OnPaint() - pDocView==NULL");
00508         return;
00509     }
00510     wxWindow* pRenderWnd=pDocView->GetRenderWindow();
00511     if (pRenderWnd==NULL)
00512     {
00513         ERROR2RAW("OILRuler::OnPaint() - pRenderWnd==NULL");
00514         return;
00515     }
00516 
00517     // get the update region in docview OilCoords
00518     WinRect RulerUpdateRect;
00519     pDC->GetClippingBox(&RulerUpdateRect.x, &RulerUpdateRect.y, &RulerUpdateRect.width, &RulerUpdateRect.height);
00520     if (RulerUpdateRect.IsEmpty())
00521         RulerUpdateRect = GetClientRect();
00522     OilRect UpdateOilRect = ClientToOil(pDocView,RulerUpdateRect);
00523 
00524     // cache the offsets from ruler to doc window relative coords
00525     // note only x valid when painting horizontal ruler and only y valid for painting vertical ruler
00526     WinRect UpdateRect = ClientToOtherClient(pRenderWnd,RulerUpdateRect);
00527     ERROR3IF(UpdateRect.GetWidth()!=RulerUpdateRect.GetWidth() || UpdateRect.GetHeight()!=RulerUpdateRect.GetHeight(),"OILRuler::OnPaint() - ruler and doc window have incompatible coordinate spaces");
00528     RulerToDocOffset = wxSize(UpdateRect.x-RulerUpdateRect.x, UpdateRect.GetBottomEx()-RulerUpdateRect.GetBottomEx());
00529 
00530 
00531     // read the necessary colours
00532     wxColour BackCol  = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
00533     wxColour TopLeft  = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT);
00534     wxColour BotRight = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW);
00535     wxColour TextCol  = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT);
00536 
00537     // get info about client rect
00538     wxRect ClientRect = GetClientRect();
00539     INT32 left   = ClientRect.x;
00540     INT32 top    = ClientRect.y;
00541     INT32 width  = ClientRect.GetWidth();
00542     INT32 height = ClientRect.GetHeight();
00543     INT32 right  = left + width;
00544     INT32 bottom = top  + height;
00545 //  if (IsHorizontal() && height!=RenderWidth || !IsHorizontal() && width!=RenderWidth)
00546 //      ERROR3_PF(("OILRuler::OnPaint() - ruler client size (%d,%d) and RenderWidth (%d) incompatible!",width,height,RenderWidth));
00547 
00548     // render the background
00549     wxPen penNoOutline(BackCol, 0, wxTRANSPARENT);
00550     pDC->SetPen(penNoOutline);
00551 //  PatB(pDC, left,top, width,height, BackCol);     // Unneeded?
00552     
00553     // paint borders to be over written by graticules
00554     if (IsHorizontal())
00555     {
00556         PatB(pDC, left,top,  width,1,  TopLeft);    // horizontal ruler top    hi-light
00557         PatB(pDC, left,bottom-1, width,1, BotRight);    // horizontal ruler bottom lo-light
00558     }
00559     else
00560     {
00561         PatB(pDC, left,top,  1,height, TopLeft);    // vertical ruler left  hi-light
00562         PatB(pDC,  right-1,top, 1,height, BotRight);    // vertical ruler right lo-light
00563     }
00564 
00565     pDC->SetPen(wxPen(*wxBLACK, 1, wxSOLID));       // Restore previous Pen
00566 
00567     // get the kernel to render the ruler
00568     if (pKernelRuler)
00569     {
00570         // store pointers to CDC and DocView required for redraw
00571         pPaintDC      = pDC;
00572         pPaintDocView = pDocView;
00573 
00574         // set up DC objects required to draw the ruler
00575         pDC->SetTextForeground(TextCol);
00576         pDC->SetBackgroundMode(wxTRANSPARENT);
00577         pDC->SetFont(GetRulerFont());
00578 
00579         // draw the ruler
00580         pKernelRuler->Redraw(&UpdateOilRect);
00581 
00582         pPaintDC = NULL;
00583         pPaintDocView = NULL;
00584     }
00585 
00586     pDC->SetPen(penNoOutline);
00587 
00588     // paint the bits of the border that need to cover the ruler rendering
00589 PORTNOTE("rulers", "Removed attempt to draw ruler ends because ScrollWindow seems to ignore specified area (WXGTK)")
00590 #if !defined(EXCLUDE_FROM_XARALX)
00591     if (IsHorizontal())
00592     {
00593         PatB(pDC,   left,top,    1,height,   BackCol);  // horizontal ruler light grey left edge
00594         PatB(pDC, left+1,top+1,  1,height-2, TopLeft);  // horizontal ruler left  hi-light
00595         PatB(pDC,  right,top+1, -1,height-1, BotRight); // horizontal ruler right lo-light
00596     }
00597     else
00598     {
00599         PatB(pDC,   left,top,    width-1,1,  BackCol);  // vertical ruler top light grey top edge
00600         PatB(pDC, left+1,top+1,  width-2,1,  TopLeft);  // vertical ruler top    hi-light
00601         PatB(pDC, left+1,bottom, width-1,-1, BotRight); // vertical ruler bottom lo-light
00602     }
00603 #endif
00604 
00605     pDC->SetPen(wxPen(*wxBLACK, 1, wxSOLID));       // Restore previous Pen
00606 
00607 }
00608 
00609 
00610 /*********************************************************************************************
00611 >   BOOL OILRuler::DrawMinorGraticule(OilCoord GratOilPos, INT32 ExtraSize=0)
00612 
00613     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
00614     Created:    3/9/95
00615     Inputs:     GratOilPos - position of graticule on ruler in OilCoords
00616                              only x used for horizontal ruler (and y for vrtical)
00617                 ExtraSize  - 0,1,2 extra number of pixels to add onto graticule size
00618     Returns:    FALSE if fails
00619     Purpose:    Draw a minor graticule on the horizontal/vertical ruler
00620     Also see:   DrawMajorGraticule()
00621 **********************************************************************************************/ 
00622 
00623 BOOL OILRuler::DrawMinorGraticule(OilCoord GratOilPos, INT32 ExtraSize)
00624 {
00625     ERROR2IF(pPaintDC     ==NULL,FALSE,"OILRuler::DrawMinorGraticule() - pPaintDC==NULL");
00626     ERROR2IF(pPaintDocView==NULL,FALSE,"OILRuler::DrawMinorGraticule() - pPaintDocView==NULL");
00627 
00628     // convert to ruler relative win coords
00629     WinCoord GratWinPos=GratOilPos.ToWin(pPaintDocView);
00630     GratWinPos -= RulerToDocOffset;
00631 
00632     // determine the size and orientation of the graticule
00633     INT32 MinorGratLen = RenderWidth/6 + ExtraSize;
00634     WinRect GratWinRect;
00635     if (IsHorizontal())
00636         GratWinRect = WinRect(GratWinPos.x, RenderWidth-MinorGratLen, GratWinPos.x+1, RenderWidth);
00637     else
00638         GratWinRect = WinRect(RenderWidth-MinorGratLen, GratWinPos.y-1, RenderWidth, GratWinPos.y);
00639 
00640     // draw the graticule
00641     pPaintDC->DrawRectangle(GratWinRect);
00642 
00643     return TRUE;
00644 }
00645 
00646 
00647 /********************************************************************************************
00648 >   void OILRuler::OnLButtonDown(wxMouseEvent& event);
00649 
00650     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00651     Created:    30/Jun/2006
00652     Inputs:     event - wxMouseEvent object
00653     Outputs:    -
00654     Returns:    -
00655     Purpose:    Handle mouse event
00656 
00657 ********************************************************************************************/
00658                     
00659 void OILRuler::OnLButtonDown(wxMouseEvent& event)
00660 {
00661     UINT32 nFlags = ClickModifiers::SynthesizeMouseEventFlags(event);
00662     BOOL bHandled = HandleRulerDragEvent(MK_LBUTTON, nFlags, (WinCoord)event.GetPosition(), CLICKTYPE_SINGLE);
00663 
00664     if (!bHandled)
00665         StartDrag(nFlags, event.GetPosition());
00666 }
00667 
00668 
00669 /********************************************************************************************
00670 >   void OILRuler::OnLButtonDblClk(wxMouseEvent& event);
00671 
00672     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
00673     Created:    7/10/95
00674     Inputs:     nFlags - 
00675                 point  - 
00676     Purpose:    handle left button double clicks
00677 ********************************************************************************************/
00678                     
00679 void OILRuler::OnLButtonDblClk(wxMouseEvent& event)
00680 {
00681     wxPoint point = event.GetPosition();
00682     UINT32 nFlags = ClickModifiers::SynthesizeMouseEventFlags(event);
00683     BOOL bHandled = HandleRulerDragEvent(MK_LBUTTON, nFlags, (WinCoord)point, CLICKTYPE_DOUBLE);
00684 
00685     if (!bHandled)
00686     {
00687         // get a few pointers
00688         DocView* pDocView = m_pOwnerView->GetDocViewPtr();
00689         Spread*  pSpread  = pKernelRuler->GetpRulerPair()->GetpSpread();
00690         if (pDocView==NULL || pSpread==NULL)
00691         {
00692             ERROR3("OILRuler::OnLButtonDblClk() - pDocView==NULL || pSpread==NULL");
00693             return;
00694         }
00695     
00696         OilCoord MouseOilPos    = ClientToOil(pDocView,point);
00697         DocCoord MouseSpreadPos = MouseOilPos.ToDoc(pSpread,pDocView).ToSpread(pSpread,pDocView);
00698         CSnap SnapObject(pDocView,pSpread);
00699         SnapObject.Snap(&MouseSpreadPos,FALSE);
00700     
00701         if (IsHorizontal())
00702             OpNewGuideline::SetNewGuidelineParam(GUIDELINE_VERT, MouseSpreadPos.x);
00703         else
00704             OpNewGuideline::SetNewGuidelineParam(GUIDELINE_HORZ, MouseSpreadPos.y);
00705     
00706         OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_NEWGUIDELINE2);
00707         if (pOpDesc!=NULL)
00708             pOpDesc->Invoke();
00709         else
00710             ERROR3("OILRuler::OnLButtonDblClk() - FindOpDescriptor(OPTOKEN_NEWGUIDELINE) failed");
00711     }
00712 }
00713 
00714 
00715 /********************************************************************************************
00716 >   void OILRuler::OnLButtonUp(wxMouseEvent& event);
00717 
00718     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00719     Created:    30/Jun/2006
00720     Inputs:     event - wxMouseEvent object
00721     Outputs:    -
00722     Returns:    -
00723     Purpose:    Handle mouse event
00724 
00725 ********************************************************************************************/
00726                     
00727 void OILRuler::OnLButtonUp(wxMouseEvent& event)
00728 {
00729     BOOL bHandled = HandleRulerUpEvent(MK_LBUTTON, (WinCoord)event.GetPosition());
00730 
00731     if (!bHandled)
00732     {
00733         // We do nothing in this case
00734     }
00735 }
00736 
00737 
00738 /********************************************************************************************
00739 >   void OILRuler::OnMButtonDown(wxMouseEvent& event);
00740 
00741     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00742     Created:    30/Jun/2006
00743     Inputs:     event - wxMouseEvent object
00744     Outputs:    -
00745     Returns:    -
00746     Purpose:    Handle mouse event
00747 
00748 ********************************************************************************************/
00749                     
00750 void OILRuler::OnMButtonDown(wxMouseEvent& event)
00751 {
00752     UINT32 nFlags = ClickModifiers::SynthesizeMouseEventFlags(event);
00753     BOOL bHandled = HandleRulerDragEvent(MK_MBUTTON, nFlags, (WinCoord)event.GetPosition(), CLICKTYPE_SINGLE);
00754 
00755     if (!bHandled)
00756     {
00757         // We do nothing in this case
00758     }
00759 }
00760 
00761 
00762 /********************************************************************************************
00763 >   void OILRuler::OnMButtonDblClk(wxMouseEvent& event);
00764 
00765     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00766     Created:    30/Jun/2006
00767     Inputs:     event - wxMouseEvent object
00768     Outputs:    -
00769     Returns:    -
00770     Purpose:    Handle mouse event
00771 
00772 ********************************************************************************************/
00773                     
00774 void OILRuler::OnMButtonDblClk(wxMouseEvent& event)
00775 {
00776     UINT32 nFlags = ClickModifiers::SynthesizeMouseEventFlags(event);
00777     BOOL bHandled = HandleRulerDragEvent(MK_MBUTTON, nFlags, event.GetPosition(), CLICKTYPE_DOUBLE);
00778 
00779     if (!bHandled)
00780     {
00781         // We do nothing in this case
00782     }
00783 }
00784 
00785 
00786 /********************************************************************************************
00787 >   void OILRuler::OnMButtonUp(wxMouseEvent& event);
00788 
00789     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00790     Created:    30/Jun/2006
00791     Inputs:     event - wxMouseEvent object
00792     Outputs:    -
00793     Returns:    -
00794     Purpose:    Handle mouse event
00795 
00796 ********************************************************************************************/
00797                     
00798 void OILRuler::OnMButtonUp(wxMouseEvent& event)
00799 {
00800     BOOL bHandled = HandleRulerUpEvent(MK_MBUTTON, event.GetPosition());
00801 
00802     if (!bHandled)
00803     {
00804         // We do nothing in this case
00805     }
00806 }
00807 
00808 
00809 /********************************************************************************************
00810 >   void OILRuler::OnRButtonDown(wxMouseEvent& event);
00811 
00812     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00813     Created:    30/Jun/2006
00814     Inputs:     event - wxMouseEvent object
00815     Outputs:    -
00816     Returns:    -
00817     Purpose:    Handle mouse event
00818 
00819 ********************************************************************************************/
00820                     
00821 void OILRuler::OnRButtonDown(wxMouseEvent& event)
00822 {
00823     UINT32 nFlags = ClickModifiers::SynthesizeMouseEventFlags(event);
00824     BOOL bHandled = HandleRulerDragEvent(MK_RBUTTON, nFlags, event.GetPosition(), CLICKTYPE_SINGLE);
00825 
00826     if (!bHandled)
00827     {
00828         // We do nothing in this case
00829     }
00830 }
00831 
00832 
00833 /********************************************************************************************
00834 >   void OILRuler::OnRButtonDblClk(wxMouseEvent& event);
00835 
00836     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00837     Created:    30/Jun/2006
00838     Inputs:     event - wxMouseEvent object
00839     Outputs:    -
00840     Returns:    -
00841     Purpose:    Handle mouse event
00842 
00843 ********************************************************************************************/
00844                     
00845 void OILRuler::OnRButtonDblClk(wxMouseEvent& event)
00846 {
00847     UINT32 nFlags = ClickModifiers::SynthesizeMouseEventFlags(event);
00848     BOOL bHandled = HandleRulerDragEvent(MK_RBUTTON, nFlags, event.GetPosition(), CLICKTYPE_DOUBLE);
00849 
00850     if (!bHandled)
00851     {
00852         // We do nothing in this case
00853     }
00854 }
00855 
00856 
00857 /********************************************************************************************
00858 >   void OILRuler::OnRButtonUp(wxMouseEvent& event);
00859 
00860     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
00861     Created:    9/10/95
00862     Inputs:     nFlags - 
00863                 point  -
00864     Purpose:    Handle left button up events - pop-up context sensitive menu
00865 ********************************************************************************************/
00866                     
00867 void OILRuler::OnRButtonUp(wxMouseEvent& event)
00868 {
00869     wxPoint point = event.GetPosition();
00870     BOOL bHandled = HandleRulerUpEvent(MK_RBUTTON, point);
00871 
00872     if (!bHandled)
00873     {
00874         // get a few pointers - no error checking yet!
00875         DocView* pDocView = m_pOwnerView->GetDocViewPtr();
00876         Spread*  pSpread  = pKernelRuler->GetpRulerPair()->GetpSpread();
00877         if (pDocView==NULL || pSpread==NULL)
00878         {
00879             ERROR3("OILRuler::OnLButtonUp() - pDocView==NULL || pSpread==NULL");
00880             return;
00881         }
00882     
00883         // convert to spread coords
00884         OilCoord MouseOilPos    = ClientToOil(pDocView,point);
00885         DocCoord MouseSpreadPos = MouseOilPos.ToDoc(pSpread,pDocView).ToSpread(pSpread,pDocView);
00886         CSnap SnapObject(pDocView,pSpread);
00887         SnapObject.Snap(&MouseSpreadPos,FALSE);
00888     
00889         // precharge static buffer with all the info to insert a new guide
00890         // at the click point on the off chance this is the option the user chooses from
00891         // the menu - as it is not poosible to pass params via the pop-up menu system
00892         if (IsHorizontal())
00893             GuidelinePropDlg::SetNewGuidelineParams(GUIDELINE_VERT, MouseSpreadPos.x);
00894         else
00895             GuidelinePropDlg::SetNewGuidelineParams(GUIDELINE_HORZ, MouseSpreadPos.y);
00896     //  // insert immediate (witout dialog)
00897     //  if (IsHorizontal())
00898     //      OpNewGuideline::SetNewGuidelineParam(GUIDELINE_VERT, MouseSpreadPos.x);
00899     //  else
00900     //      OpNewGuideline::SetNewGuidelineParam(GUIDELINE_HORZ, MouseSpreadPos.y);
00901     
00902         RulerContextMenu* pRulerMenu = new RulerContextMenu;
00903         pRulerMenu->Show();
00904     }
00905 }
00906 
00907 
00908 
00909 
00910 /********************************************************************************************
00911 >   BOOL OILRuler::HandleRulerDragEvent(UINT32 Button, UINT32 nFlags, wxPoint point, ClickType t)
00912 
00913     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00914     Created:    ages ago
00915     Inputs:     Button - the actual button being pressed for a click/double click event.
00916                 nFlags - The mouse button flags
00917                 point - the coordinate of the mouse cursor
00918                 t -  the kind of mouse event (button up/down, move, drag start/finish etc.)
00919     Outputs:    -
00920     Returns:    -
00921     Purpose:    Gathers together Windows information about a mouse event and passes it on to
00922                 the kernel, by calling DocView::OnClick()
00923                 HandleDragEvent needs to be called from OnTimer code so rather than 
00924                 synthesizing a wxMouseEvent object this function has been left taking 
00925                 non-wx params
00926     Errors:     -
00927     Scope:      Private
00928     SeeAlso:    CCamView::GetClickMods(); CCamView::OnLButtonDown(); CCamView::OnRButtonDown()
00929                 DocView::OnClick()
00930 
00931 ********************************************************************************************/ 
00932 
00933 /********************************************************************************************
00934 
00935 Technical notes (by Tim):
00936 
00937 The Button is parameter is necessary, because sometimes when we get the *first* button
00938 down event, nFlags has more than one mouse button bit set.  This only happens when you
00939 rampantly click buttons very quickly but nevertheless we *do* need to know which button
00940 was pressed, otherwise we never release the drag event and we end up with button-up-drag
00941 city.
00942 
00943 I assume this is due to some latency in Windows, e.g., it gets a button down event, and
00944 while preparing it goes and reads the mouse button state and meanwhile another button has
00945 been pressed so we get a button down event with nFlags indicating more than one button
00946 is down.
00947 
00948 ********************************************************************************************/ 
00949 
00950 BOOL OILRuler::HandleRulerDragEvent(UINT32 Button, UINT32 nFlags, WinCoord point, ClickType t)
00951 {
00952     if (pKernelRuler==NULL)
00953         return FALSE;
00954 
00955     DocView* pDocView = m_pOwnerView->GetDocViewPtr();
00956 
00957     if (DocView::GetSelected() != pDocView)
00958     {
00959         // If selected doc is null, let's select it anyway.
00960         if (DocView::GetSelected() == NULL)
00961         {
00962             // We're in a weird state that should never happen but does - a document
00963             // has the focus, but isn't selected
00964             Document* pKDoc =NULL;
00965             if(pDocView)
00966                 pKDoc = pDocView->GetDoc();
00967 
00968             if (pKDoc)
00969             {
00970                 Document::SetSelectedViewAndSpread(pKDoc, pDocView, NULL);
00971             }
00972             
00973         }
00974         return FALSE;
00975     }
00976 
00977     SetCurrentStates();
00978 
00979     // Find out which buttons etc are down.
00980     m_LastClickMods = ClickModifiers::GetClickModifiers(nFlags);
00981 
00982     // If it's the first single click, then reset the drag delay timer, and ask for a 
00983     // Windows timer.
00984     if (((t == CLICKTYPE_SINGLE) || (t == CLICKTYPE_DOUBLE)) && 
00985         (m_FirstClickButton == 0))
00986     {
00987         // Remember this event.
00988         m_LastClickPoint = point;
00989         m_LastClickType = t;
00990         m_LastClickButton = Button;
00991         m_FirstClickButton = Button;
00992 //      m_DragTimer.Sample();
00993 
00994         // Ask the system for a timer.
00995         // The timer is used to generate DragPointerIdle events, which are not directly
00996         // supported by Windows.
00997 //      UINT32 rate = 100;
00998 PORTNOTE("other","Removed reading of keyboard autorepeat rate")
00999 #ifndef EXCLUDE_FROM_XARALX
01000         ::SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, &rate, 0);
01001 #endif
01002 
01003 //      m_DragIdleTimer.Start(rate);
01004     }
01005 
01006     // Convert the click position to OIL coordinates before passing to the kernel.
01007     OilCoord ocoord = ClientToOil(pDocView, point);
01008     // Only the ordinate in the main ruler direction should be converted, the coordinate
01009     // translation does not make any sense in the other direction. Instead, we keep the
01010     // window-relative coordinate but we change it in such a way that the paper side of
01011     // the ruler is coordinate 0 because the Kernel does not know the RenderWidth of the
01012     // ruler and the paper side is the significant side where the blobs are drawn.
01013     if (IsHorizontal())
01014         ocoord.y = RenderWidth - point.y;
01015     else
01016         ocoord.x = RenderWidth - point.x;
01017     // pass only left clicks to the ruler
01018     if (Button == MK_LBUTTON)
01019         return pKernelRuler->OnRulerClick(ocoord, t, m_LastClickMods);
01020     return FALSE;
01021 }
01022 
01023 
01024 
01025 /*********************************************************************************************
01026 >   BOOL OILRuler::HandleRulerUpEvent(UINT32 Button, WinCoord point)
01027 
01028     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
01029     Created:    9th Sept 1993
01030     Inputs:     Button - which mouse button has been released.
01031                 nFlags - The mouse button flags.
01032                 point - the coordinate of the mouse cursor.
01033     Outputs:    -
01034     Returns:    -
01035     Purpose:    Finishes the current drag, if there is one, by elucidating the state of
01036                 the buttons etc and calling DragDFinished() in the kernel (DocView).  Called
01037                 whenever a mouse button is released.
01038     Errors:     -
01039     Scope:      Private
01040     SeeAlso:    CCamView::GetClickMods(); CCamView::OnLButtonDown(); CCamView::OnRButtonDown()
01041                 DocView::OnClick()
01042 
01043 **********************************************************************************************/ 
01044 
01045 BOOL OILRuler::HandleRulerUpEvent(UINT32 Button, WinCoord point)
01046 {
01047     if (pKernelRuler==NULL)
01048         return FALSE;
01049 
01050     DocView* pDocView = m_pOwnerView->GetDocViewPtr();
01051 
01052     if (DocView::GetSelected() != pDocView)
01053     {
01054 //      ENSURE(pCurrentDragOp == NULL, "Drag operation in a view that isn't 'selected' !!");
01055         return FALSE;
01056     }
01057 
01058     // Set Current states...
01059     SetCurrentStates();
01060 
01061     // Convert WinCoord click point to OilCoord AND take any ruler offsets into account
01062     OilCoord ocoord = ClientToOil(pDocView, point);
01063 
01064     // Was the button that went up the first one that went down?
01065     if (Button==m_FirstClickButton)
01066     {
01067         //Yes it was.
01068         //Is there a drag currently running?
01069 /*      if (m_pCurrentDragOp != NULL)
01070         {
01071             // Yes there is.
01072             // Release the capture and terminate the drag.  Note that we try to release
01073             // the mouse capture as soon as possible after a drag has finished, in case the
01074             // DragFinished method below brings up a dialog box or something.
01075             if (GetRenderWindow() && GetRenderWindow()->GetCapture()==GetRenderWindow())
01076                 GetRenderWindow()->ReleaseMouse();
01077             return pKernelRuler->DragFinished(m_pCurrentDragOp, ocoord, m_LastClickMods, TRUE);
01078 
01079         }
01080         else
01081 */      {
01082             // No drag is currently running
01083             // Kill the timer started in HandleDragEvent(), 
01084             // as we don't want to wait for a drag anymore.
01085 //          m_DragIdleTimer.Stop();
01086 
01087             m_FirstClickButton = 0;
01088 
01089             //Then pass the Up-Click message to CCamView::OnClick
01090             return pKernelRuler->OnRulerClick(ocoord, CLICKTYPE_UP, m_LastClickMods);
01091         }
01092     }
01093     else
01094     {
01095         //No, the button that went up was not the first one to go down.
01096         //In that case, we expect the first button that went down is still down and
01097         //hence there is a drag running.
01098         //Is there a drag running?
01099 /*      if (m_pCurrentDragOp != NULL)
01100         {
01101             //Yes, as expected.
01102             //Pass the Up-Click message to CCamView::OnClick
01103             return pKernelRuler->OnRulerClick(ocoord, CLICKTYPE_UP, m_LastClickMods);
01104         }
01105 */
01106     }
01107 
01108     return FALSE;
01109 }
01110 
01111 
01112 
01113 
01114 /********************************************************************************************
01115 >   void OILRuler::OnMouseMove(wxMouseEvent& event);
01116 
01117     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
01118     Created:    8/10/95
01119     Inputs:     nFlags - 
01120                 point  - 
01121     Purpose:    handle mouse moves over the ruler
01122 ********************************************************************************************/
01123                     
01124 void OILRuler::OnMouseMove(wxMouseEvent& event)
01125 {
01126 //  UINT32 nFlags = ClickModifiers::SynthesizeMouseEventFlags(event);
01127     wxPoint MousePos = event.GetPosition();
01128 
01129     static wxPoint OldMousePos = wxPoint(0,0);
01130     if (MousePos==OldMousePos)
01131         return;
01132 
01133     StatusLine* pStatusLine=GetApplication()->GetpStatusLine();
01134     if (pStatusLine)
01135     {
01136         String_256 Text("");
01137         GetStatusLineText(&Text, WinCoord(MousePos.x, MousePos.y), this);
01138         pStatusLine->UpdateText(&Text, STATUSLINE_SELDESC_STATBAR);
01139     }
01140 
01141 /*  Attempt to update mouse followers when pointer over ruler
01142     Doesn't work...
01143     DocView* pView = m_pOwnerView->GetDocViewPtr();
01144     if (pView!=NULL)
01145     {
01146         wxWindow* pRenderWnd=pView->GetRenderWindow();
01147         wxPoint wcoord = ClientToOtherClient(pRenderWnd, MousePos);
01148         OilCoord ocoord = ( (WinCoord *)&wcoord )->ToOil(pView, TRUE);
01149         Spread* pSpread = Document::GetSelectedSpread();
01150         DocCoord dcoord = ocoord.ToDoc(pSpread, pView);
01151         RulerPair* pRulerPair = pView->GetpRulerPair();
01152         if (pRulerPair!=NULL)
01153             pRulerPair->UpdateMouseFollowers(&dcoord);
01154     }
01155 */
01156 
01157     OldMousePos = MousePos;
01158 }
01159 
01160 
01161 /******************************************************************************
01162 >   BOOL OILRuler::GetStatusLineText(String_256* pText, WinCoord MousePos, CWindowID hWnd)
01163 
01164     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
01165     Created:    8/10/95
01166     Inputs:     MousePos - position in window
01167                 hWnd     - handle of window
01168     Outputs:    pText    -
01169     Returns:    TRUE if ptext hold valid text, else FALSE if not over a pane
01170     Purpose:    if over a ruler return status line help
01171 ******************************************************************************/
01172 
01173 BOOL OILRuler::GetStatusLineText(String_256* pText, WinCoord MousePos, CWindowID hWnd)
01174 {
01175     ERROR2IF(pText==NULL,FALSE,"OILRuler::GetStatusLineText() - pText==NULL");
01176 
01177     if (this!=hWnd)
01178         return FALSE;
01179 
01180     // allow the current tool to set the status line if it claims the ruler
01181     DocView* pDocView = m_pOwnerView->GetDocViewPtr();
01182     OilCoord ocoord = ClientToOil(pDocView, MousePos);
01183     if (pKernelRuler->GetStatusLineText(pText, ocoord))
01184         return TRUE;
01185 
01186     UINT32 StatusHelpID = IsHorizontal() ? _R(IDS_HRULER_SH) : _R(IDS_VRULER_SH);
01187     return (pText->Load(StatusHelpID)!=0);
01188 }
01189 
01190 
01191 /********************************************************************************************
01192 >   BOOL OILRuler::GetMinGraticuleSpacing(OilRect* pSpacing, DocView* pDocView)
01193 
01194     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
01195     Created:    4/9/95
01196     Inputs:     pDocView - 
01197     Outputs:    pSpacing - 
01198     Returns:    minimum graticule spacing in OilCords
01199 ********************************************************************************************/
01200                     
01201 BOOL OILRuler::GetMinGraticuleSpacing(OilRect* pSpacing, DocView* pDocView)
01202 {
01203     ERROR2IF(pSpacing==NULL,FALSE,"OILRuler::GetMinGraticuleSpacing() - pSpacing==NULL");
01204     ERROR2IF(pDocView==NULL,FALSE,"OILRuler::GetMinGraticuleSpacing() - pDocView==NULL");
01205 
01206     WinCoord WinSpacing(MIN_PIXEL_GRATICULE_SPACING_X,-MIN_PIXEL_GRATICULE_SPACING_Y);
01207     pSpacing->lo=OilCoord(0,0);
01208     pSpacing->hi=WinSpacing.ToOil(pDocView);
01209     return TRUE;
01210 }
01211 
01212 
01213 /********************************************************************************************
01214 >   static BOOL OILRuler::GetTextSize(OilRect* pTextSize, LPCTSTR str, DocView* pDocView)
01215 
01216     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
01217     Created:    4/9/95
01218     Inputs:     pText    -
01219                 pDocView - 
01220     Outputs:    pTextSize - x,y size of text in OilCoords
01221     Returns:    FALSE if fails
01222 ********************************************************************************************/
01223                     
01224 BOOL OILRuler::GetTextSize(OilRect* pTextSize, LPCTSTR str, DocView* pDocView)
01225 {
01226     ERROR2IF(pTextSize==NULL,FALSE,"OILRuler::GetTextSize() - pTextSize==NULL");
01227     ERROR2IF( pDocView==NULL,FALSE,"OILRuler::GetTextSize() - pDocView==NULL");
01228 
01229     WinRect WinTextSize;
01230     BOOL ok=GetTextSize(&WinTextSize, str);
01231     if (!ok)
01232         return FALSE;
01233 
01234     *pTextSize = WinTextSize.ToOil(pDocView);
01235     return TRUE;
01236 }
01237 
01238 
01239 /********************************************************************************************
01240 >   static BOOL OILRuler::GetTextSize(WinRect* pTextSize, LPCTSTR str)
01241 
01242     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
01243     Created:    4/9/95
01244     Inputs:     pText     -
01245     Outputs:    pTextSize - x,y size of text in WinCoords
01246     Returns:    FALSE if fails
01247 ********************************************************************************************/
01248                     
01249 BOOL OILRuler::GetTextSize(WinRect* pTextSize, LPCTSTR str)
01250 {
01251     ERROR2IF(pTextSize==NULL,FALSE,"OILRuler::GetTextSize() - pTextSize==NULL");
01252     ERROR2IF(      str==NULL,FALSE,"OILRuler::GetTextSize() - pText==NULL");
01253 
01254     try
01255     {
01256         // create a screen compatible DC to find the size of the text
01257         wxScreenDC dc;
01258 
01259         wxFont font = GetRulerFont();
01260         dc.SetFont(font);
01261 
01262         wxSize TextSize(0,0);
01263         wxString Text(str);
01264         dc.GetTextExtent(Text, &TextSize.x, &TextSize.y);
01265         pTextSize->x   = 0;
01266         pTextSize->y    = 0;
01267         pTextSize->SetRightEx(TextSize.x);
01268         pTextSize->SetBottomEx(TextSize.y);
01269 
01270     }
01271     catch (...)
01272     {
01273         ERROR2(FALSE, "OILRuler::GetTextSize() - failed to create dc");
01274     }
01275 
01276     return TRUE;
01277 }
01278 
01279 
01280 /********************************************************************************************
01281 >   WinRect OILRuler::ClientToOtherClient(wxWindow* pOtherCWnd, WinRect WR)
01282 
01283     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
01284     Created:    7/10/95
01285     Inputs:     pOtherCWnd - window to which to make rect relative to
01286                 WR         - win rect to convert
01287     Returns:    WinRect    - converted win rect
01288     Purpose:    Convert rect relative to this window to rect relative to another window
01289     Note:       Nice if this was in a parent CCWnd class
01290 ********************************************************************************************/
01291 
01292 WinRect OILRuler::ClientToOtherClient(wxWindow* pOtherCWnd, WinRect WR)
01293 {
01294     wxPoint tl = WR.GetTopLeft();
01295     wxPoint br = WR.GetBottomRightEx();
01296 
01297     ClientToScreen(tl);
01298     ClientToScreen(br);
01299     pOtherCWnd->ScreenToClient(tl);
01300     pOtherCWnd->ScreenToClient(br);
01301 
01302     WR.SetTopLeft(tl);
01303     WR.SetBottomRightEx(br);
01304 
01305     return WR;
01306 }
01307 
01308 
01309 /********************************************************************************************
01310 >   wxPoint OILRuler::ClientToOtherClient(wxWindow* pOtherCWnd, wxPoint point)
01311 
01312     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
01313     Created:    7/10/95
01314     Inputs:     pOtherCWnd - window to which to make rect relative to
01315                 point      - win coord to convert
01316     Returns:    WinCoord   - converted win coord
01317     Purpose:    Convert coord relative to this window to coord relative to another window
01318     Note:       Nice if this was in a parent CCWnd class
01319 ********************************************************************************************/
01320 
01321 wxPoint OILRuler::ClientToOtherClient(wxWindow* pOtherCWnd, wxPoint point)
01322 {
01323     ClientToScreen(point);
01324     pOtherCWnd->ScreenToClient(point);
01325     return point;
01326 }
01327 
01328 
01329 /********************************************************************************************
01330 >   OilRect OILRuler::ClientToOil(DocView* pDocView, WinRect WR)
01331 
01332     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
01333     Created:    7/10/95
01334     Inputs:     pDocView    - associated doc view
01335                 WR          - win rect to convert
01336     Returns:    OilRect     - converted win rect
01337     Purpose:    Convert a (client) rect relative to this window to a document Oil rect
01338     Note:       Nice if this was in CWnd class but this is MFC, could do with a CCWnd class
01339 ********************************************************************************************/
01340 
01341 OilRect OILRuler::ClientToOil(DocView* pDocView, WinRect WR)
01342 {
01343     wxWindow* pRenderWnd = pDocView->GetRenderWindow();
01344     ERROR2IF(pRenderWnd==NULL,OilRect(OilCoord(0,0),OilCoord(0,0)),"OILRuler::ClientToOil() - pRenderWnd==NULL");
01345     return ClientToOtherClient(pRenderWnd,WR).ToOil(pDocView);
01346 }
01347 
01348 
01349 /********************************************************************************************
01350 >   OilCoord OILRuler::ClientToOil(DocView* pDocView, wxPoint point)
01351 
01352     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
01353     Created:    7/10/95
01354     Inputs:     pDocView    - associated doc view
01355                 point       - win coord to convert
01356     Returns:    OilCoord    - converted win coord
01357     Purpose:    Convert a (client) coord relative to this window to a document Oil coord
01358     Note:       Nice if this was in CWnd class but this is MFC, could do with a CCWnd class
01359 ********************************************************************************************/
01360 
01361 OilCoord OILRuler::ClientToOil(DocView* pDocView, wxPoint point)
01362 {
01363     wxWindow* pRenderWnd = pDocView->GetRenderWindow();
01364     ERROR2IF(pRenderWnd==NULL,OilCoord(0,0),"OILRuler::ClientToOil() - pRenderWnd==NULL");
01365     wxPoint DocPoint = ClientToOtherClient(pRenderWnd,point);
01366     return WinCoord(DocPoint.x,DocPoint.y).ToOil(pDocView);
01367 }
01368 
01369 
01370 /*********************************************************************************************
01371 >   BOOL OILRuler::PaintMouseFollower(OilCoord OilPos, DocView* pDocView,
01372                                       MouseFollowerRenderType RenderType)
01373 
01374     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
01375     Created:    29/9/95
01376     Inputs:     OilPos     - position of mouse for which to draw x/y follower
01377                 pDocView   - 
01378                 RenderType - RenderOn/RenderOff (not yet used - just inverts previous state)
01379     Returns:    FALSE if fails
01380     Purpose:    interface to DrawMouseFollower()
01381 **********************************************************************************************/
01382 
01383 BOOL OILRuler::PaintMouseFollower(OilCoord OilPos, DocView* pDocView,
01384                                   MouseFollowerRenderType RenderType)
01385 {
01386     // get hold of a dc (if in middle of OnPaint(), pPaintDC should be valid)
01387     wxDC* pDC = pPaintDC;
01388     if (pDC)
01389     {
01390         BOOL ok = DrawMouseFollower(OilPos, pDocView, RenderType, pDC);
01391         return ok;
01392     }
01393 
01394     wxPaintDC dc(this);
01395     BOOL ok = DrawMouseFollower(OilPos, pDocView, RenderType, &dc);
01396 
01397     return ok;
01398 }
01399 
01400 /*********************************************************************************************
01401 >   BOOL OILRuler::DrawMouseFollower(OilCoord OilPos, DocView* pDocView,
01402                                      MouseFollowerRenderType RenderType, CDC* pDC)
01403 
01404     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
01405     Created:    29/9/95
01406     Inputs:     OilPos     - position of mouse for which to draw x/y follower
01407                 pDocView   - 
01408                 RenderType - RenderOn/RenderOff (not yet used - just inverts previous state)
01409                 pDC        - 
01410     Returns:    FALSE if fails
01411     Purpose:    Draw an horizontal or vetical mouse follower
01412 **********************************************************************************************/
01413 
01414 BOOL OILRuler::DrawMouseFollower(OilCoord OilPos, DocView* pDocView,
01415                                  MouseFollowerRenderType RenderType, wxDC* pDC)
01416 {
01417     ERROR2IF(pDocView==NULL,FALSE,"OILRuler::DrawMouseFollower() - pDocView==NULL");
01418     ERROR2IF(     pDC==NULL,FALSE,"OILRuler::DrawMouseFollower() - pDC==NULL");
01419 
01420     // convert follower position to a rectangle to render
01421     WinCoord WinPos = OilPos.ToWin(pDocView);
01422     WinRect FollowerWinRect;
01423     if(IsHorizontal())
01424         FollowerWinRect = WinRect(WinPos.x,0,WinPos.x,RenderWidth);
01425     else
01426         FollowerWinRect = WinRect(0,WinPos.y-1,RenderWidth,WinPos.y-1);
01427 
01428     // set up dc and draw
01429     wxPen pen(*wxGREEN, 1, wxSOLID);
01430     pDC->SetPen(pen);
01431     pDC->SetLogicalFunction(wxINVERT);
01432     pDC->DrawLine(FollowerWinRect.GetLeft(), FollowerWinRect.GetTop(), FollowerWinRect.GetRightEx(), FollowerWinRect.GetBottomEx());
01433     pDC->SetLogicalFunction(wxCOPY);
01434 
01435     return TRUE;
01436 }
01437 
01438 /********************************************************************************************
01439 >   BOOL OILRuler::HighlightSection(OilCoord Lo, OilCoord Hi)
01440 
01441     Author:     Martin Wuerthner <xara@mw-software.com>
01442     Created:    07/07/06
01443     Inputs:     Lo, Hi - determines the ruler section to be redrawn
01444     Returns:    FALSE if fails
01445     Purpose:    Highlight a rectangular section of the ruler
01446 
01447 ********************************************************************************************/
01448 
01449 BOOL OILRuler::HighlightSection(OilCoord Lo, OilCoord Hi)
01450 {
01451     ERROR2IF(pPaintDC==NULL,FALSE,"OILRuler::HighlightSection - pPaintDC==NULL");
01452 
01453     // convert to ruler relative win coords
01454     WinCoord RectLoWinPos = Lo.ToWin(pPaintDocView);
01455     WinCoord RectHiWinPos = Hi.ToWin(pPaintDocView);
01456 
01457     RectLoWinPos -= RulerToDocOffset;
01458     RectHiWinPos -= RulerToDocOffset;
01459 
01460     if (IsHorizontal())
01461     {
01462         RectLoWinPos.y = 0;
01463         Hi.y = RenderWidth;
01464     }
01465     else
01466     {
01467         Lo.x = 0;
01468         Hi.x = RenderWidth;
01469     }
01470 
01471     WinRect HighlightWinRect(RectLoWinPos.x, RectLoWinPos.y, RectHiWinPos.x, RectHiWinPos.y);
01472 
01473     pPaintDC->SetBrush(wxBrush(wxColour(*wxWHITE)));
01474     pPaintDC->SetPen(*wxTRANSPARENT_PEN);
01475     pPaintDC->DrawRectangle(HighlightWinRect);
01476     pPaintDC->SetPen(wxPen(*wxBLACK, 1, wxSOLID));      // Restore previous pen (as expected by further drawing)
01477     return TRUE;
01478 }
01479 
01480 /********************************************************************************************
01481 >   BOOL OILRuler::DrawBitmap(OilCoord Pos, ResourceID BitmapID)
01482 
01483     Author:     Martin Wuerthner <xara@mw-software.com>
01484     Created:    07/07/06
01485     Inputs:     Pos - the position on the ruler (only ordinate in ruler direction is significant)
01486                 BitmapID - the resource id of the bitmap
01487     Returns:    FALSE if fails
01488     Purpose:    Display a bitmap at a specific ruler position, centered around the requested
01489                 position in the ruler direction, aligned with the ruler edge in the other
01490                 direction
01491     
01492 ********************************************************************************************/
01493 
01494 BOOL OILRuler::DrawBitmap(OilCoord Pos, ResourceID BitmapID)
01495 {
01496     ERROR2IF(pPaintDC==NULL,FALSE,"OILRuler::DrawBitmap() - pPaintDC==NULL");
01497 
01498     wxBitmap* pBitmap = CamArtProvider::Get()->FindBitmap(BitmapID);
01499     ERROR2IF(pBitmap==NULL,FALSE,"OILRuler::DrawBitmap - could not find bitmap");
01500 
01501     INT32 BitmapWidth = pBitmap->GetWidth();
01502     INT32 BitmapHeight = pBitmap->GetHeight();
01503 
01504     // convert to ruler relative win coords
01505     WinCoord WinPos = Pos.ToWin(pPaintDocView);
01506     WinPos -= RulerToDocOffset;
01507 
01508     if (IsHorizontal())
01509     {
01510         // centered around requested position, aligned with bottom of ruler
01511         WinPos.x -= BitmapWidth / 2;
01512         WinPos.y = RenderWidth - BitmapHeight;
01513     }
01514     else
01515     {
01516         // centered around requested position, aligned with right hand side of ruler
01517         WinPos.x = RenderWidth - BitmapWidth;
01518         WinPos.y -= BitmapHeight / 2;
01519     }
01520     pPaintDC->DrawBitmap(*pBitmap, WinPos.x, WinPos.y, true);
01521     return TRUE;
01522 }
01523 
01524 /********************************************************************************************
01525 >   void OILRuler::SetCurrentStates( wxFocusEvent& event )
01526 
01527     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01528     Created:    15/6/96
01529     Inputs:     -
01530     Purpose:    Set the  View and Document current
01531     SeeAlso:    
01532 ********************************************************************************************/
01533 
01534 void OILRuler::SetCurrentStates()
01535 {
01536     if (m_pOwnerView)
01537     {
01538         DocView* pDocView = m_pOwnerView->GetDocViewPtr();
01539         if (pDocView)
01540         {
01541             pDocView->SetCurrent();
01542             Document* pKernelDoc = pDocView->GetDoc();
01543             if (pKernelDoc)
01544                 pKernelDoc->SetCurrent();
01545         }
01546     }
01547 }
01548 
01549 /********************************************************************************************
01550 >   void OILRuler::OnFocus()
01551 
01552     Author:     Luke_Hart (Xara Group Ltd) <lukeh@xara.com>
01553     Created:    17/07/06
01554     Inputs:     -
01555     Purpose:    The rulers shouldn't get focues (unless they ever decided to
01556                 handle arrow movement...)
01557     SeeAlso:    
01558 ********************************************************************************************/
01559 
01560 void OILRuler::OnFocus( wxFocusEvent& event )
01561 {
01562     // Put the focus back into active view
01563     TRACEUSER( "jlh92", _T("NO, that control is not allowed focus") );
01564     AfxGetApp().GiveActiveCanvasFocus();
01565 }
01566 
01568 //              OILHorizontalRuler
01570 
01571 IMPLEMENT_DYNAMIC_CLASS(OILHorizontalRuler, wxWindow)
01572 
01573 /********************************************************************************************
01574 >   OILHorizontalRuler::OILHorizontalRuler()
01575 
01576     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01577     Created:    5/3/94
01578     Purpose:    Creates an OILHorizontalRuler object.
01579 ********************************************************************************************/
01580                     
01581 OILHorizontalRuler::OILHorizontalRuler()
01582 {
01583     pLegend = NULL; 
01584 }
01585 
01586 
01587 /********************************************************************************************
01588 >   OILHorizontalRuler::~OILHorizontalRuler()
01589 
01590     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01591     Created:    5/3/94
01592     Purpose:    destructor for OILHorizontalRuler object - delete the legend label;.
01593 ********************************************************************************************/
01594                     
01595 OILHorizontalRuler::~OILHorizontalRuler()
01596 {
01597     if (pLegend)
01598     {
01599         delete pLegend;
01600         pLegend=NULL;
01601     }    
01602 }
01603 
01604 
01605 /********************************************************************************************
01606 >   virtual BOOL OILHorizontalRuler::PostCreate()
01607 
01608     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01609     Created:    5/3/94
01610     Returns:    FALSE if fails
01611     Purpose:    Called from the base class  Create() to create the legend label.
01612 ********************************************************************************************/
01613                     
01614 BOOL OILHorizontalRuler::PostCreate()
01615 {
01616     pLegend = new LegendLabel;
01617     if (pLegend == NULL)
01618         return FALSE;
01619 
01620 //  pLegend->Create(this, -1);
01621     pLegend->Create(this, m_pOwnerView->GetParentFrame(), -1);
01622 
01623     return TRUE;
01624 }
01625 
01626 
01627 /********************************************************************************************
01628 >   virtual BOOL OILHorizontalRuler::ScrollRuler()
01629 
01630     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01631     Created:    5/3/94
01632     Purpose:    Scroll the ruler
01633 ********************************************************************************************/
01634                     
01635 void OILHorizontalRuler::ScrollRuler(INT32 amount)
01636 { 
01637     WinRect ClipRect;
01638     ClipRect = GetClientRect();
01639 //  ClipRect.x+=1;
01640 //  ClipRect.SetWidth(ClipRect.GetWidth()-2);
01641 
01642     ScrollWindow(amount, 0, &ClipRect);
01643     Update();
01644 }
01645 
01646 
01647 /********************************************************************************************
01648 >   virtual BOOL OILHorizontalRuler::StartDrag(UINT32 nFlags, wxPoint point)
01649 
01650     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01651     Created:    5/3/94
01652     Returns:    FALSE if fails
01653     Purpose:    StartDrag function .
01654 ********************************************************************************************/
01655                     
01656 BOOL OILHorizontalRuler::StartDrag(UINT32 nFlags, wxPoint point)
01657 { 
01658     NewGuidelineParam.Method    = GUIDELINEOPMETHOD_NEW_DRAG;
01659     NewGuidelineParam.Type      = GUIDELINE_HORZ;
01660 
01661     String_256 OpToken(OPTOKEN_GUIDELINE);
01662 
01663     if (m_pOwnerView != NULL)
01664         m_pOwnerView->InvokeDragOp(&OpToken ,&NewGuidelineParam, nFlags, point);
01665 
01666     return TRUE;
01667 }
01668 
01669 
01670 /*********************************************************************************************
01671 >   virtual void OILHorizontalRuler::CalcPosFromParentClient(wxRect* lpRect)
01672 
01673     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
01674     Created:    ages ago
01675     Inputs:     A long pointer to a rectangle which describes the dimensions of the client
01676                 area of the window containing the scroller.
01677     Outputs:    Changes lpRect to the position a horizontal ruler would occupy
01678                 normally, ie. along the top of the owning window.
01679     Purpose:    Called by CCamView when its size changes, so it knows where to reposition
01680                 the CHorzScroller.
01681 **********************************************************************************************/ 
01682 
01683 void OILHorizontalRuler::CalcPosFromParentClient(WinRect* lpRect)
01684 {
01685     WinRect parentRect;
01686     parentRect = m_pOwnerView->GetParentFrame()->GetClientRect();
01687     
01688     lpRect->x   = parentRect.x + RulerWidth;
01689     lpRect->y    = parentRect.y;
01690     lpRect->SetRightEx(parentRect.GetRightEx()); //+1);
01691     lpRect->SetBottomEx(parentRect.y  + RulerWidth);
01692     
01693 }
01694 
01695 
01696 /*********************************************************************************************
01697 >   BOOL OILHorizontalRuler::DrawMajorGraticule(OilCoord GratOilPos, LPCTSTR str)
01698 
01699     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
01700     Created:    3/9/95
01701     Inputs:     GratOilPos - position of graticule on ruler in OilCoords (y ignored)
01702                 pGratLabel - label for the graticule
01703     Returns:    FALSE if fails
01704     Purpose:    Draw a major graticule on the horizontal ruler
01705     Note:       Must be called from within the scope of the OILRuler::OnPaint()
01706                 as it is this function which is responsible for creating a DC
01707                 and selecting the correct objects into it
01708 **********************************************************************************************/ 
01709 
01710 BOOL OILHorizontalRuler::DrawMajorGraticule(OilCoord GratOilPos, LPCTSTR str)
01711 {
01712     ERROR2IF(str          ==NULL,FALSE,"OILHorizontalRuler::DrawMajorGraticule() - pGrtaLabel==NULL");
01713     ERROR2IF(pPaintDC     ==NULL,FALSE,"OILHorizontalRuler::DrawMajorGraticule() - pPaintDC==NULL");
01714     ERROR2IF(pPaintDocView==NULL,FALSE,"OILHorizontalRuler::DrawMajorGraticule() - pPaintDocView==NULL");
01715 
01716     // convert to ruler relative win coords
01717     WinCoord GratWinPos = GratOilPos.ToWin(pPaintDocView);
01718     GratWinPos -= RulerToDocOffset;
01719 
01720     // draw the major graticule in 2 halves with a gap for the text between
01721     INT32 GratLen = MAJOR_GRAT_LEN;
01722     WinRect GratWinRect(GratWinPos.x, RenderWidth-MAJOR_GRAT_LEN, GratWinPos.x+1, RenderWidth);
01723     pPaintDC->DrawRectangle(GratWinRect);
01724 
01725     // draw the graticule label (centred about grat pos)
01726     wxSize TextSize(0,0);
01727     wxString Text(str);
01728     pPaintDC->GetTextExtent(Text, &TextSize.x, &TextSize.y);
01729 
01730     INT32   Textx    = GratWinPos.x-TextSize.x/2;               // centre text about grat (+1 for gap to right - left inclusive)
01731     INT32   Texty    = RenderWidth-(GratLen+TextSize.y);
01732     pPaintDC->DrawText(Text, Textx, Texty);                     // actual digits drawn 1 pixel beyond, and 2 pixels below this point
01733 
01734     return TRUE;
01735 }
01736 
01737 
01738 /*********************************************************************************************
01739 >   BOOL OILHorizontalRuler::PositionLegend()
01740 
01741     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
01742     Created:    3/9/95
01743     Returns:    FALSE if fails
01744     Purpose:    Ask the Legend Label to position itself
01745 **********************************************************************************************/ 
01746 
01747 BOOL OILHorizontalRuler::PositionLegend()
01748 {
01749 //  ERROR2IF(pLegend==NULL,FALSE,"OILHorizontalRuler::PositionLegend() - pLegend==NULL");
01750     if (pLegend==NULL)
01751     {
01752         TRACE( _T("This should never be NULL but is regularly on Win95 implying the creation order is wrong\n"));
01753         return FALSE;
01754     }
01755 
01756     return pLegend->PositionLegend();
01757 }
01758 
01759 
01760 /*********************************************************************************************
01761 >   BOOL OILHorizontalRuler::SetLegendText(StringBase* pText)
01762 
01763     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
01764     Created:    3/9/95
01765     Returns:    FALSE if fails
01766     Purpose:    Ask the Legend Label to position itself
01767 **********************************************************************************************/ 
01768 
01769 BOOL OILHorizontalRuler::SetLegendText(StringBase* pText)
01770 {
01771 //  ERROR2IF(pLegend==NULL,FALSE,"OILHorizontalRuler::SetLegendText() - pLegend==NULL");
01772     if (pLegend==NULL)
01773     {
01774         TRACE( _T("This should never be NULL but is regularly on Win95 implying the creation order is wrong\n"));
01775         return FALSE;
01776     }
01777 
01778     return pLegend->SetLegendText(pText);
01779 }
01780 
01781 
01782 /*********************************************************************************************
01783 >   void OILHorizontalRuler::ShowRuler(BOOL show)
01784 
01785     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
01786     Created:    25/8/95
01787     Inputs:     show - FALSE to hide the ruler
01788     Purpose:    Shows or hides this ruler
01789 **********************************************************************************************/ 
01790 
01791 void OILHorizontalRuler::ShowRuler(BOOL show)
01792 {
01793     OILRuler::ShowRuler(show);
01794     if (pLegend)
01795         pLegend->ShowLabel(show);
01796 } 
01797 
01798 
01800 //              OILVerticalRuler
01802 
01803 IMPLEMENT_DYNAMIC_CLASS(OILVerticalRuler, wxWindow)
01804 
01805 /********************************************************************************************
01806 >   OILVerticalRuler::OILVerticalRuler()
01807 
01808     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01809     Created:    5/3/94
01810     Purpose:    Creates an OILVerticalRuler object.
01811 ********************************************************************************************/
01812                     
01813 OILVerticalRuler::OILVerticalRuler()
01814 { 
01815 }
01816 
01817 
01818 /********************************************************************************************
01819 >   virtual BOOL OILVerticalRuler::PostCreate()
01820 
01821     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01822     Created:    5/3/94
01823     Returns:    FALSE if fails
01824     Purpose:    Called from the base class  Create()- does nothing at the moment.
01825 ********************************************************************************************/
01826                     
01827 BOOL OILVerticalRuler::PostCreate()
01828 { 
01829     return TRUE;
01830 }
01831 
01832 
01833 /********************************************************************************************
01834 >   virtual BOOL OILVerticalRuler::ScrollRuler()
01835 
01836     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01837     Created:    5/3/94
01838     Returns:    -
01839     Purpose:    Scroll the ruler
01840 ********************************************************************************************/
01841                     
01842 void OILVerticalRuler::ScrollRuler(INT32 amount)
01843 { 
01844     WinRect ClipRect;
01845     ClipRect = GetClientRect();
01846 //  ClipRect.y+=1;
01847 //  ClipRect.SetHeight(ClipRect.GetHeight()-2);
01848 
01849     ScrollWindow(0, amount, &ClipRect);
01850     Update();
01851 }
01852 
01853 
01854 /********************************************************************************************
01855 >   virtual BOOL OILVerticalRuler::StartDrag(UINT32 nFlags, wxPoint point)
01856 
01857     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01858     Created:    5/3/94
01859     Returns:    FALSE if fails
01860     Purpose:    Sends a start vertical guideline drag message.
01861 ********************************************************************************************/
01862                     
01863 BOOL OILVerticalRuler::StartDrag(UINT32 nFlags, wxPoint point)
01864 { 
01865     NewGuidelineParam.Method    = GUIDELINEOPMETHOD_NEW_DRAG;
01866     NewGuidelineParam.Type      = GUIDELINE_VERT;
01867 
01868     String_256 OpToken(OPTOKEN_GUIDELINE);
01869 
01870     if (m_pOwnerView != NULL)
01871         m_pOwnerView->InvokeDragOp(&OpToken, &NewGuidelineParam, nFlags, point);
01872 
01873     return TRUE;
01874 }
01875 
01876 
01877 /*********************************************************************************************
01878 >   virtual void OILVerticalRuler::CalcPosFromParentClient(wxRect* lpRect)
01879 
01880     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
01881     Created:    ages ago
01882     Inputs:     A long pointer to a rectangle which describes the dimensions of the client
01883                 area of the window containing the scroller.
01884     Outputs:    Changes lpRect to the position a vretical rulerr would occupy
01885                 normally, ie. along the left side of the owning window.
01886     Purpose:    Called by CCamView when its size changes, so it knows where to reposition
01887                 the CVertical ruler.
01888 **********************************************************************************************/ 
01889 
01890 void OILVerticalRuler::CalcPosFromParentClient(WinRect* lpRect)
01891 {
01892     WinRect parentRect;
01893     parentRect = m_pOwnerView->GetParentFrame()->GetClientRect();
01894 
01895     lpRect->x   = parentRect.x;
01896     lpRect->y    = parentRect.y  + RulerWidth;
01897     lpRect->SetRightEx(parentRect.x + RulerWidth);
01898     lpRect->SetBottomEx(parentRect.GetBottomEx()); //+1);
01899 }
01900 
01901 
01902 /*********************************************************************************************
01903 >   BOOL OILVerticalRuler::DrawMajorGraticule(OilCoord GratOilPos, LPCTSTR str)
01904 
01905     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
01906     Created:    3/9/95
01907     Inputs:     GratOilPos - position of graticule on ruler in OilCoords (y ignored)
01908                 pGratLabel - label for the graticule
01909     Returns:    FALSE if fails
01910     Purpose:    Draw a major graticule on the horizontal ruler
01911     Note:       Must be called from within the scope of the OILRuler::OnPaint()
01912                 as it is this function which is responsible for creating a DC
01913                 and selecting the correct objects into it
01914 **********************************************************************************************/ 
01915 
01916 BOOL OILVerticalRuler::DrawMajorGraticule(OilCoord GratOilPos, LPCTSTR str)
01917 {
01918     ERROR2IF(str          ==NULL,FALSE,"OILVerticalRuler::DrawMajorGraticule() - pGrtaLabel==NULL");
01919     ERROR2IF(pPaintDC     ==NULL,FALSE,"OILVerticalRuler::DrawMajorGraticule() - pPaintDC==NULL");
01920     ERROR2IF(pPaintDocView==NULL,FALSE,"OILVerticalRuler::DrawMajorGraticule() - pPaintDocView==NULL");
01921 
01922     // convert to ruler relative win coords
01923     WinCoord GratWinPos = GratOilPos.ToWin(pPaintDocView);
01924     GratWinPos -= RulerToDocOffset;
01925 
01926     wxString Text(str);
01927 
01928     // get width of gap for text
01929     INT32 TextLen  = Text.Length();
01930     INT32 GapWidth = CharWidth*max(2,TextLen)+1;        // +1 for gap to right (left already included)
01931 
01932     // draw the major graticule in 2 halves with a gap for the text between
01933     INT32 GratLen = min(MAJOR_GRAT_LEN,RenderWidth-(GapWidth+1));
01934     WinRect GratWinRect(RenderWidth-GratLen, GratWinPos.y-1, RenderWidth, GratWinPos.y);
01935     pPaintDC->DrawRectangle(GratWinRect);
01936 
01937     // draw the graticule label (centred about grat pos)
01938     wxSize TextSize(0,0);
01939     pPaintDC->GetTextExtent(Text, &TextSize.x, &TextSize.y);
01940     INT32   TextWidth = TextSize.x+1;
01941     INT32   Offset    = (GapWidth-TextWidth)/2;                 // offset to centre text in text gap (if proportional font)
01942     INT32   Textx     = RenderWidth-GratLen-(TextWidth+Offset);
01943     INT32   Texty     = GratWinPos.y-TextSize.y/2-1;
01944     pPaintDC->DrawText(Text, Textx, Texty);                     // actual digits drawn 1 pixel beyond, and 2 pixels below this point
01945 
01946     return TRUE;
01947 }
01948 
01949 
01951 //                                   OriginGadget Class
01953 
01954 IMPLEMENT_DYNAMIC_CLASS(OriginGadget, wxWindow)
01955 
01956 BEGIN_EVENT_TABLE( OriginGadget, wxWindow )
01957     EVT_LEFT_DOWN(      OriginGadget::OnLButtonDown)
01958     EVT_LEFT_DCLICK(    OriginGadget::OnLButtonDblClk)
01959     EVT_RIGHT_UP(       OriginGadget::OnRButtonUp)
01960     EVT_MOTION(         OriginGadget::OnMouseMove)
01961     EVT_PAINT(          OriginGadget::OnPaint)
01962 END_EVENT_TABLE()
01963 
01964 /********************************************************************************************
01965 >   OriginGadget::OriginGadget()
01966 
01967     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01968     Created:    25/8/95
01969     Purpose:    Creates an OILDockingBar object.
01970 ********************************************************************************************/
01971                     
01972 OriginGadget::OriginGadget()
01973 { 
01974     pGlyph = NULL;
01975     pGlyph = CamArtProvider::Get()->FindBitmap(_R(IDB_ORIGINBMP)); //, (CamArtFlags)(CAF_DEFAULT|(Disabled?CAF_GREYED:0)));
01976 }
01977 
01978 
01979 /*********************************************************************************************
01980 >   void OriginGadget::ShowGadget(BOOL show)
01981 
01982     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
01983     Created:    25/8/95
01984     Inputs:     show - FALSE to hide gadet
01985     Purpose:    Shows or hides this gadget
01986 **********************************************************************************************/ 
01987 
01988 void OriginGadget::ShowGadget(BOOL show)
01989 {
01990     Show(show);
01991 }
01992 
01993  
01994 /********************************************************************************************
01995 >   virtual OriginGadget::~OriginGadget()
01996 
01997     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
01998     Created:    25/8/95
01999     Purpose:    Destroys an OriginGadget object 
02000 ********************************************************************************************/
02001 
02002 OriginGadget::~OriginGadget()
02003 {
02004     // NOTE: CamArtProvider owns pGlyph and will delete it itself
02005 }
02006 
02007 
02008 /*********************************************************************************************
02009 >   void OriginGadget::OnPaint( wxPaintEvent &evnt )
02010 
02011     Author:     Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
02012     Created:    ages ago
02013     Inputs:     -
02014     Outputs:    -
02015     Returns:    -
02016     Purpose:    Redraws the colour bar
02017     Errors:     -
02018 
02019 **********************************************************************************************/ 
02020 void OriginGadget::OnPaint( wxPaintEvent &evnt )
02021 {
02022     // Always create this so that the area is validated
02023     wxPaintDC dc(this);
02024 
02025     if (!CCamApp::IsDisabled())
02026     {
02027         DoPaint(&dc);
02028     }
02029 }
02030 
02031 
02032 
02033 /********************************************************************************************
02034 >   void OriginGadget::DoPaint(wxDC* pDC)
02035 
02036     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
02037     Created:    25/8/95
02038     Purpose:    Paints the client area of the Origin Gadget
02039                 Mask plots the origin glyph
02040 ********************************************************************************************/
02041 
02042 void OriginGadget::DoPaint(wxDC* pDC)
02043 {
02044     // read the necessary colours
02045     wxColour BackCol  = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
02046     wxColour TopLeft  = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT);
02047     wxColour BotRight = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW);
02048     wxColour TextCol  = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT);
02049 
02050     // get info about client rect
02051     wxRect ClientRect = GetClientRect();
02052     INT32 left   = ClientRect.x;
02053     INT32 top    = ClientRect.y;
02054     INT32 width  = ClientRect.GetWidth();
02055     INT32 height = ClientRect.GetHeight();
02056     INT32 right  = left + width;
02057     INT32 bottom = top  + height;
02058 
02059     // render the background
02060     wxPen penNoOutline(BackCol, 0, wxTRANSPARENT);
02061     pDC->SetPen(penNoOutline);
02062     OILRuler::PatB(pDC, left,top, width,height, BackCol);
02063     
02064     pDC->SetBackgroundMode(wxTRANSPARENT);
02065 
02066     // plot the little orign bitmap in the centre of this window
02067     INT32 BitmapSize = 15;  
02068     INT32 offset     = (width-BitmapSize)/2;
02069     pDC->DrawBitmap(*pGlyph, offset, offset, true);
02070 
02071     // paint the hi/lo lights
02072     OILRuler::PatB(pDC,  left,top,    width-1,1,        TopLeft);       // top
02073     OILRuler::PatB(pDC,  left,top,          1,height-1, TopLeft);       // left
02074     OILRuler::PatB(pDC,  left,bottom,   width,-1,       BotRight);  // bottom
02075     OILRuler::PatB(pDC, right,top,         -1,height,   BotRight);  // right
02076 }
02077 
02078 
02079 /*********************************************************************************************
02080 >   virtual void OriginGadget::CalcPosFromParentClient(WinRect* lpRect)
02081 
02082     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
02083     Created:    25/8/95
02084     Inputs:     A long pointer to a rectangle which describes the dimensions of the client
02085                 area of the window containing the gadget.
02086     Outputs:    Changes lpRect to the position a horizontal scroll bar would occupy
02087                 normally, ie. along the bottom of the owning window.
02088     Purpose:    Called by CCamView when its size changes, so it knows where to reposition
02089                 the OriginGadget.
02090 **********************************************************************************************/ 
02091 
02092 void OriginGadget::CalcPosFromParentClient(WinRect* lpRect)
02093 {
02094     wxRect parentRect;
02095     parentRect = m_pOwnerView->GetParentFrame()->GetClientRect();
02096 
02097     lpRect->x   = parentRect.x ;
02098     lpRect->y    = parentRect.y;
02099     lpRect->SetRightEx(parentRect.x + OILRuler::GetWidth());
02100     lpRect->SetBottomEx(parentRect.y  + OILRuler::GetWidth());
02101 
02102     // we need to take into account camelots new floating toolbar ....
02103 
02104 PORTNOTE("ruler", "Removed use of Kernel toolbars")
02105 #if !defined(EXCLUDE_FROM_XARALX)
02106     DockBarType DockBarType;// = DOCKBAR_FLOAT;
02107     KernelBarPos * pKernelBarPos;
02108 
02109     // find out where the toolbar is docked
02110     GetMainFrame()->GetBarPosInfo(&(String_32 ("Toolbar")), &DockBarType, &pKernelBarPos);
02111 
02112     if (DockBarType == DOCKBAR_FLOAT)
02113     {
02114         RECT MainFrameWindowRect = *lpRect;
02115         //::GetWindowRect (GetSafeHwnd (), &MainFrameWindowRect);
02116         ClientToScreen (&MainFrameWindowRect);
02117 
02118         POINT ToolbarTL;
02119         ToolbarTL.x = pKernelBarPos->x;
02120         ToolbarTL.y = pKernelBarPos->y;
02121 
02122         if (PtInRect (&MainFrameWindowRect, ToolbarTL))
02123         {
02124             KernelBarPos NewToolBarPos = *pKernelBarPos;
02125             BaseBar* PtrToToolBar = BaseBar::GetPtrToToolBar ();
02126             
02127             INT32 dy = MainFrameWindowRect.bottom - ToolbarTL.y;
02128             INT32 dx = MainFrameWindowRect.right - ToolbarTL.x;
02129 
02130             NewToolBarPos.y += dy;
02131             NewToolBarPos.x += dx;
02132 
02133             if (PtrToToolBar)
02134             {
02135                 PtrToToolBar->MoveBar ((WPARAM) DOCKBAR_FLOAT, (LPARAM) &NewToolBarPos);
02136             }
02137         }
02138     }
02139 #endif
02140     
02141 }
02142 
02143 
02144 /********************************************************************************************
02145 >   BOOL OriginGadget::Create(CCamView* pOwnerView, INT32 id)
02146 
02147     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
02148     Created:    5/3/94
02149     Inputs:     pParentWindow - 
02150     Returns:    FALSE if fails
02151     Purpose:    Creates an OriginGadget object.
02152 ********************************************************************************************/
02153 
02154 BOOL OriginGadget::Create(CCamView* pOwnerView, INT32 id)
02155 { 
02156     ENSURE(pOwnerView,"DockingBar must have a Parent");
02157 
02158     m_pOwnerView = pOwnerView;
02159 
02160     if (!wxWindow::Create(pOwnerView->GetParentFrame(), id, wxDefaultPosition, wxSize(OILRuler::GetWidth(), OILRuler::GetWidth()), wxNO_BORDER))
02161         return(FALSE);
02162 
02163     return TRUE;
02164 }
02165 
02166 
02167 /********************************************************************************************
02168 >   void OriginGadget::OnLButtonDown(wxMouseEvent& event);
02169 
02170     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
02171     Created:    5/3/94
02172     Inputs:     nFlags - 
02173                 point  - 
02174     Purpose:    handle left button downs
02175 ********************************************************************************************/
02176                     
02177 void OriginGadget::OnLButtonDown(wxMouseEvent& event)
02178 {
02179     UINT32 nFlags = ClickModifiers::SynthesizeMouseEventFlags(event);
02180     wxPoint point = event.GetPosition();
02181 
02182     String_256 OpToken(OPTOKEN_SPREADORIGIN);
02183 
02184     if (m_pOwnerView != NULL)
02185         m_pOwnerView->InvokeDragOp(&OpToken, NULL, nFlags, point);
02186 }
02187 
02188 
02189 /********************************************************************************************
02190 >   void OriginGadget::OnRButtonUp(wxMouseEvent& event);
02191 
02192     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
02193     Created:    9/10/95
02194     Inputs:     nFlags - 
02195                 point  -
02196     Purpose:    Handle left button up events - pop-up context sensitive menu
02197 ********************************************************************************************/
02198                     
02199 void OriginGadget::OnRButtonUp(wxMouseEvent& event)
02200 {
02201 //  UINT32 nFlags = ClickModifiers::SynthesizeMouseEventFlags(event);
02202     wxPoint point = event.GetPosition();
02203 
02204     OriginContextMenu* pOriginMenu = new OriginContextMenu;
02205     pOriginMenu->Show();
02206 }
02207 
02208 
02209 /********************************************************************************************
02210 >   void OriginGadget::OnLButtonDblClk(wxMouseEvent& event);
02211 
02212     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
02213     Created:    7/10/95
02214     Inputs:     nFlags - 
02215                 point  - 
02216     Purpose:    handle left button double clicks
02217 ********************************************************************************************/
02218                     
02219 void OriginGadget::OnLButtonDblClk(wxMouseEvent& event)
02220 {
02221     /*UINT32 nFlags =*/ ClickModifiers::SynthesizeMouseEventFlags(event);
02222     wxPoint point = event.GetPosition();
02223 
02224     if (OpResetSpreadOrigin::GetState(NULL,NULL).Greyed==FALSE)
02225     {
02226         OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_RESETSPREADORIGIN);
02227         if (pOpDesc!=NULL)
02228             pOpDesc->Invoke();
02229         else
02230             ERROR3("OriginGadget::OnLButtonDblClk() - FindOpDescriptor(OPTOKEN_RESETSPREADORIGIN) failed");
02231     }
02232 }
02233 
02234 
02235 /********************************************************************************************
02236 >   void OriginGadget::OnMouseMove(wxMouseEvent& event);
02237 
02238     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
02239     Created:    8/10/95
02240     Inputs:     nFlags - 
02241                 point  - 
02242     Purpose:    handle mouse moves over Origin
02243 ********************************************************************************************/
02244                     
02245 void OriginGadget::OnMouseMove(wxMouseEvent& event)
02246 {
02247 //  UINT32 nFlags = ClickModifiers::SynthesizeMouseEventFlags(event);
02248     wxPoint MousePos = event.GetPosition();
02249 
02250     static wxPoint OldMousePos = wxPoint(0,0);
02251     if (MousePos==OldMousePos)
02252         return;
02253 
02254 PORTNOTE("rulers", "Bubble help removed from OriginGadget")
02255 #if !defined(EXCLUDE_FROM_XARALX)
02256     ControlHelper::DoBubbleHelpOn(GetSafeHwnd(), 0, BubbleHelpCallBack,this);
02257 #endif
02258 
02259     StatusLine* pStatusLine=GetApplication()->GetpStatusLine();
02260     if (pStatusLine)
02261     {
02262         String_256 Text("");
02263         GetStatusLineText(&Text, WinCoord(MousePos.x, MousePos.y), this);
02264         pStatusLine->UpdateText(&Text, STATUSLINE_SELDESC_STATBAR);
02265     }
02266 
02267     OldMousePos = MousePos;
02268 }
02269 
02270 
02271 /******************************************************************************
02272 >   static TCHAR* OriginGadget::BubbleHelpCallBack(CWindowID hWnd, UINT32 PaneIndex, void* UserData)
02273 
02274     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
02275     Created:    8/10/95
02276     Purpose:    Bubble help call back handler
02277                 (called some time after call to DoBubbleHelpOn() if mouse ha not moved)
02278     Inputs:     hWnd     - not used
02279                 PaneID   - not used
02280                 UserData - not used
02281     Returns:    pointer to text, or NULL if fails
02282 ******************************************************************************/
02283 
02284 PORTNOTE("rulers", "Bubble help removed from OriginGadget")
02285 #if !defined(EXCLUDE_FROM_XARALX)
02286 TCHAR* OriginGadget::BubbleHelpCallBack(CWindowID, UINT32 PaneIndex, void*)
02287 {
02288     static String_64 BubbleHelpText("");
02289 
02290     BubbleHelpText.Load(_R(IDS_ORIGIN_BH));
02291 
02292     return (TCHAR*)BubbleHelpText;
02293 }
02294 #endif
02295 
02296 
02297 /******************************************************************************
02298 >   BOOL OriginGadget::GetStatusLineText(String_256* pText, WinCoord MousePos, CWindowID hWnd)
02299 
02300     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
02301     Created:    8/10/95
02302     Inputs:     MousePos - position in window (not used)
02303                 hWnd     - handle of window
02304     Outputs:    pText    -
02305     Returns:    TRUE if ptext hold valid text, else FALSE if not over a pane
02306     Purpose:    if over origin gadget return status line help
02307 ******************************************************************************/
02308 
02309 BOOL OriginGadget::GetStatusLineText(String_256* pText, WinCoord MousePos, CWindowID hWnd)
02310 {
02311     ERROR2IF(pText==NULL,FALSE,"OILRuler::GetStatusLineText() - pText==NULL");
02312 
02313     if (this!=hWnd)
02314         return FALSE;
02315 
02316     return (pText->Load(_R(IDS_ORIGIN_SH))!=0);
02317 }
02318 
02319 
02321 //      LegendLabel Class
02323 
02324 IMPLEMENT_DYNAMIC_CLASS(LegendLabel, wxWindow)
02325 
02326 BEGIN_EVENT_TABLE( LegendLabel, wxWindow )
02327     EVT_LEFT_DOWN(      LegendLabel::OnLButtonDown)
02328     EVT_LEFT_DCLICK(    LegendLabel::OnLButtonDblClk)
02329     EVT_RIGHT_UP(       LegendLabel::OnRButtonUp)
02330     EVT_MOTION(         LegendLabel::OnMouseMove)
02331     EVT_PAINT(          LegendLabel::OnPaint)
02332 END_EVENT_TABLE()
02333 
02334 /********************************************************************************************
02335 >   LegendLabel::LegendLabel()
02336 
02337     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
02338     Created:    25/8/95
02339     Purpose:    Creates an OILDockingBar object.
02340 ********************************************************************************************/
02341                     
02342 LegendLabel::LegendLabel()
02343 {
02344     LegendText = _R(IDS_OILRULER_INCHES); // "Inches";
02345     LegendWidth = 0;
02346     LegendHeight = 0;
02347     m_pHorzRuler = NULL;
02348 }
02349 
02350 
02351 /*********************************************************************************************
02352 >   void LegendLabel::ShowLabel(BOOL show)
02353 
02354     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
02355     Created:    25/8/95
02356     Inputs:     show - FALSE to hide label
02357     Purpose:    Shows or hides this label
02358 **********************************************************************************************/ 
02359 
02360 void LegendLabel::ShowLabel(BOOL show)
02361 {
02362     Show(show);
02363 }
02364 
02365  
02366 /********************************************************************************************
02367 >   virtual LegendLabel::~LegendLabel()
02368 
02369     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
02370     Created:    25/8/95
02371     Purpose:    Destroys an LegendLabel object 
02372 ********************************************************************************************/
02373 
02374 LegendLabel::~LegendLabel()
02375 {
02376 }
02377 
02378 
02379 /*********************************************************************************************
02380 >   void LegendLabel::OnPaint( wxPaintEvent &evnt )
02381 
02382     Author:     Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
02383     Created:    ages ago
02384     Inputs:     -
02385     Outputs:    -
02386     Returns:    -
02387     Purpose:    Redraws the colour bar
02388     Errors:     -
02389 
02390 **********************************************************************************************/ 
02391 void LegendLabel::OnPaint( wxPaintEvent &evnt )
02392 {
02393     // Always create this so that the area is validated
02394     wxPaintDC dc(this);
02395 
02396     if (!CCamApp::IsDisabled())
02397     {
02398         DoPaint(&dc);
02399     }
02400 }
02401 
02402 
02403 
02404 /********************************************************************************************
02405 >   afx_msg void LegendLabel::DoPaint(wxDC* pDC)
02406 
02407     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
02408     Created:    25/8/95
02409     Purpose:    Paints the client area of the Legend Label
02410 ********************************************************************************************/
02411 
02412 void LegendLabel::DoPaint(wxDC* pDC)
02413 {
02414     // read the necessary colours
02415     wxColour BackCol  = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
02416     wxColour TopLeft  = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT);
02417     wxColour BotRight = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW);
02418     wxColour TextCol  = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT);
02419 
02420     // get info about client rect
02421     wxRect ClientRect = GetClientRect();
02422     INT32 left   = ClientRect.x;
02423     INT32 top    = ClientRect.y;
02424     INT32 width  = ClientRect.GetWidth();
02425     INT32 height = ClientRect.GetHeight();
02426     INT32 right  = left + width;
02427     INT32 bottom = top  + height;
02428 
02429     // render the background
02430     wxPen penNoOutline(BackCol, 0, wxTRANSPARENT);
02431     pDC->SetPen(penNoOutline);
02432     OILRuler::PatB(pDC, left,top, width,height, BackCol);
02433     
02434     // set up dc to paint transparent black text in correct font
02435     pDC->SetTextForeground(TextCol);
02436     pDC->SetBackgroundMode(wxTRANSPARENT);
02437     pDC->SetFont(OILRuler::GetRulerFont());
02438 
02439     // now draw the legend text formated into the client area
02440     wxString Text((LPCTSTR)LegendText);
02441     pDC->DrawText(Text, ClientRect.x+3, ClientRect.y+1);
02442 
02443     // paint hi/lo light
02444     OILRuler::PatB(pDC,  left,top,    width-1,1,        TopLeft);       // top
02445     OILRuler::PatB(pDC,  left,top,          1,height-1, TopLeft);       // left
02446     OILRuler::PatB(pDC,  left,bottom,   width,-1,       BotRight);  // bottom
02447     OILRuler::PatB(pDC, right,top,         -1,height,   BotRight);  // right
02448 }
02449 
02450 
02451 /*********************************************************************************************
02452 >   virtual void LegendLabel::SetLegendText(StringBase* pText)
02453 
02454     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
02455     Created:    25/8/95
02456     Returns:    FALSE if fails
02457     Purpose:    Called to set legend text - resize and reposition Legend.
02458 **********************************************************************************************/ 
02459 
02460 BOOL LegendLabel::SetLegendText(StringBase* pText)
02461 {
02462     ERROR2IF(pText==NULL,FALSE,"SetLegendText called with a NULL string");
02463     LegendText = *pText;
02464     
02465     BOOL ok=SetLegendSize();
02466     if (ok)
02467     {
02468         ok=PositionLegend();
02469         Refresh();
02470         Update();
02471     }
02472 
02473     return ok;
02474 }
02475 
02476 
02477 /*********************************************************************************************
02478 >   virtual BOOL LegendLabel::SetLegendSize()
02479 
02480     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
02481     Created:    25/8/95
02482     Returns:    FALSE if fails
02483     Purpose:    Sets the width of the window to fit the legend text.
02484     Note:       The actual Legend window may be 1 pixel larger to ensure that 
02485                 it is vertically centred correctly in ruler (ie gap above == gap below)
02486 **********************************************************************************************/ 
02487 
02488 BOOL LegendLabel::SetLegendSize()
02489 {
02490     WinRect WinTextSize;
02491     BOOL ok=OILRuler::GetTextSize(&WinTextSize, (LPCTSTR)LegendText);
02492     if (!ok)
02493         return FALSE;
02494 
02495     LegendHeight = WinTextSize.GetHeight() +2;      // add pixel border top and bottom
02496     LegendWidth  = WinTextSize.GetWidth()  +2+7;    // add border + 3 pixel gap each end + pixel to right to balance 1 to left
02497 
02498     return TRUE;
02499 }
02500 
02501 
02502 /*********************************************************************************************
02503 >   virtual BOOL LegendLabel::PositionLegend()
02504 
02505     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
02506     Created:    25/8/95
02507     Returns:    FALSE if fails
02508     Purpose:    Called by Horizontal ruler to position the LegendLabel.
02509 **********************************************************************************************/ 
02510 
02511 BOOL LegendLabel::PositionLegend()
02512 {
02513     // get the client area of the horizontal ruler
02514     ERROR2IF(m_pHorzRuler==NULL, FALSE, "No Horz ruler pointer in LegendLable::PositionLegend");
02515 
02516     WinRect ParentRect;
02517     ParentRect = m_pHorzRuler->GetClientRect();
02518     
02519     // determine position of window
02520     WinRect LegendRect;
02521     LegendRect.y      = (ParentRect.GetHeight()-LegendHeight)/2;        // centre vertically
02522     LegendRect.x   = ParentRect.GetWidth()-LegendWidth-LegendRect.y-6;  // align right with same gap as vertical (plus a bit)
02523     LegendRect.SetWidth(LegendWidth);                                   // and this gap plus some from right end of ruler
02524     LegendRect.SetHeight(LegendHeight);                                 // with same gap at bottom
02525 TRACEUSER("Phil", _T("LegendRect %d %d %d %d\n"), LegendRect.x, LegendRect.y, LegendRect.width, LegendRect.height);
02526 
02527     // actually move the window
02528     SetSize(LegendRect);
02529 
02530     return TRUE;
02531 }
02532 
02533 
02534 /********************************************************************************************
02535 >   BOOL LegendLabel::Create(OILHorizontalRuler* pHorzRuler, wxWindow* pParentWindow, INT32 id)
02536 
02537     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
02538     Created:    5/3/94
02539     Inputs:     pParentWindow - 
02540     Returns:    FALSE if fails
02541     Purpose:    Creates an LegendLabel object.
02542 ********************************************************************************************/
02543                     
02544 BOOL LegendLabel::Create(OILHorizontalRuler* pHorzRuler, wxWindow* pParentWindow, INT32 id)
02545 { 
02546     ERROR2IF(pHorzRuler==NULL, FALSE, "DockingBar must have a Parent");
02547     ERROR2IF(pParentWindow==NULL, FALSE, "DockingBar must have a Parent");
02548 
02549     m_pHorzRuler = pHorzRuler;
02550 
02551     if (!wxWindow::Create(pParentWindow, id, wxDefaultPosition, wxSize(10, 20), wxNO_BORDER))
02552         return(FALSE);
02553 
02554     return TRUE;
02555 }
02556 
02557 
02558 /********************************************************************************************
02559 >   void LegendLabel::OnLButtonDown(wxMouseEvent& event);
02560 
02561     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
02562     Created:    7/10/95
02563     Inputs:     nFlags - 
02564                 point  - 
02565     Purpose:    handle left button down events - pass on to parent ruler
02566 ********************************************************************************************/
02567                     
02568 void LegendLabel::OnLButtonDown(wxMouseEvent& event)
02569 {
02570 //  ((OILHorizontalRuler*)GetParent())->OnLButtonDown(event);
02571     m_pHorzRuler->OnLButtonDown(event);
02572 }
02573 
02574 
02575 /********************************************************************************************
02576 >   void LegendLabel::OnRButtonUp(wxMouseEvent& event);
02577 
02578     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
02579     Created:    7/10/95
02580     Inputs:     nFlags - 
02581                 point  - 
02582     Purpose:    handle left button up events -  pass on to parent ruler
02583 ********************************************************************************************/
02584                     
02585 void LegendLabel::OnRButtonUp(wxMouseEvent& event)
02586 {
02587 //  ((OILHorizontalRuler*)GetParent())->OnRButtonUp(event);
02588     m_pHorzRuler->OnRButtonUp(event);
02589 }
02590 
02591 
02592 /********************************************************************************************
02593 >   void LegendLabel::OnLButtonDblClk(wxMouseEvent& event);
02594 
02595     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
02596     Created:    7/10/95
02597     Inputs:     nFlags - 
02598                 point  - 
02599     Purpose:    handle left button double click events - pass on to parent ruler
02600 ********************************************************************************************/
02601                     
02602 void LegendLabel::OnLButtonDblClk(wxMouseEvent& event)
02603 {
02604 //  ((OILHorizontalRuler*)GetParent())->OnLButtonDblClk(event);
02605     m_pHorzRuler->OnLButtonDblClk(event);
02606 }
02607 
02608 
02609 /********************************************************************************************
02610 >   void LegendLabel::OnMouseMove(wxMouseEvent& event);
02611 
02612     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
02613     Created:    8/10/95
02614     Inputs:     nFlags - 
02615                 point  - 
02616     Purpose:    handle mousemoves over ruler legend label
02617 ********************************************************************************************/
02618                     
02619 void LegendLabel::OnMouseMove(wxMouseEvent& event)
02620 {
02621 //  UINT32 nFlags = ClickModifiers::SynthesizeMouseEventFlags(event);
02622     wxPoint MousePos = event.GetPosition();
02623 
02624     static wxPoint OldMousePos = wxPoint(0,0);
02625     if (MousePos==OldMousePos)
02626         return;
02627 
02628     StatusLine* pStatusLine=GetApplication()->GetpStatusLine();
02629     if (pStatusLine)
02630     {
02631         String_256 Text("");
02632         GetStatusLineText(&Text, WinCoord(MousePos.x, MousePos.y), this);
02633         pStatusLine->UpdateText(&Text,STATUSLINE_SELDESC_STATBAR);
02634     }
02635 
02636     OldMousePos = MousePos;
02637 }
02638 
02639 
02640 /******************************************************************************
02641 >   BOOL LegendLabel::GetStatusLineText(String_256* pText, WinCoord MousePos, CWindowID hWnd)
02642 
02643     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
02644     Created:    8/10/95
02645     Inputs:     MousePos - position in window (not used)
02646                 hWnd     - handle of window
02647     Outputs:    pText    -
02648     Returns:    TRUE if ptext hold valid text, else FALSE if not over a pane
02649     Purpose:    if over a ruler legend return status line help
02650 ******************************************************************************/
02651 
02652 BOOL LegendLabel::GetStatusLineText(String_256* pText, WinCoord MousePos, CWindowID hWnd)
02653 {
02654     ERROR2IF(pText==NULL,FALSE,"LegendLabel::GetStatusLineText() - pText==NULL");
02655 
02656     if (this!=hWnd)
02657         return FALSE;
02658 
02659     return (pText->Load(_R(IDS_RULER_LEGEND_SH))!=0);
02660 }
02661 
02662 
02663 /********************************************************************************************
02664 >   wxPoint LegendLabel::ClientToParentClient(wxPoint point)
02665 
02666     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
02667     Created:    7/10/95
02668     Inputs:     point - 
02669     Returns:    the point relative to the parent window
02670     Purpose:    convert coord relative to this window to a coord relative to the parent window
02671     Note:       Nice if this was in a parent CCWnd class
02672 ********************************************************************************************/
02673                     
02674 wxPoint LegendLabel::ClientToParentClient(wxPoint point)
02675 {
02676     ClientToScreen(point);
02677 //  GetParent()->ScreenToClient(point);
02678     m_pHorzRuler->ScreenToClient(point);
02679     return point;
02680 }
02681 
02682 #endif  // WEBSTER

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