drawctl.cpp

Go to the documentation of this file.
00001 // $Id: drawctl.cpp 1243 2006-06-04 19:41:37Z 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 #include "camtypes.h"
00101 
00102 #include "dlgevt.h"
00103 #include "drawctl.h"
00104 
00105 /*****************************************************************************
00106 
00107 This file contains the class for wxCamDrawControl, derived from
00108 wxEvtHandler. This contains a mapping allowing dialogs of ANY class
00109 derived from wxDialog to call the relevant bits of DialogManager.
00110 
00111 *****************************************************************************/
00112 
00113 DEFINE_EVENT_TYPE(wxEVT_CAMDRAWCONTROL_INVOKE)
00114 IMPLEMENT_DYNAMIC_CLASS( wxCamDrawControlEvent, wxEvent )
00115 
00116 IMPLEMENT_DYNAMIC_CLASS( wxCamDrawControl, wxControl )
00117 BEGIN_EVENT_TABLE(wxCamDrawControl, wxControl)
00118     EVT_CAMDRAWCONTROL_INVOKE(wxID_ANY, wxCamDrawControl::OnInvoke)
00119     EVT_PAINT(wxCamDrawControl::OnPaint)
00120     EVT_MOUSE_EVENTS(wxCamDrawControl::OnMouseEvent)
00121     EVT_SIZE(wxCamDrawControl::OnSize)
00122 END_EVENT_TABLE();
00123 
00124 IMPLEMENT_DYNAMIC_CLASS( wxCamDrawControlXmlHandler, wxXmlResourceHandler)
00125 
00126 /********************************************************************************************
00127 
00128 >   BOOL wxCamDrawControl::Create( wxWindow * parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
00129                      [TYPENOTE: Correct] long style, const wxValidator& validator = wxDefaultValidator,
00130                      wxCamDrawControlStyle cacstyle = (wxCamDrawControlStyle)0,
00131                      wxString opdesc = wxString(_T("")))
00132 
00133     Author:     Alex_Bligh <alex@alex.org.uk>
00134     Created:    30/12/2005
00135     Inputs:     parent - parent window
00136                 id - id to use
00137                 pos - position
00138                 size - size
00139                 style - style
00140                 validator - validator (up to here, all the same as wxControl)
00141                 cacstyle - the style of CamDrawControl to use, i.e. the flags passed
00142                 opdesc - the opdescriptor to use, OR the empty string
00143     Outputs:    None
00144     Returns:    TRUE if succeeded, FALSE if fails
00145     Purpose:    Initialize the control
00146     Errors:     via wxMessageBox
00147     SeeAlso:    -
00148 
00149 ********************************************************************************************/
00150 
00151 BOOL wxCamDrawControl::Create( wxWindow * parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
00152                      /*TYPENOTE: Correct*/ long style, const wxValidator& validator,
00153                      wxCamDrawControlStyle cacstyle,
00154                      wxString opdesc)
00155 {
00156     if (!wxControl::Create(parent, id, pos, size, style, validator))
00157         return FALSE;
00158 
00159     m_CamDrawControlStyle = cacstyle;
00160     m_OpDesc = opdesc;
00161     return TRUE;
00162 }
00163 
00164 
00165 /********************************************************************************************
00166 
00167 >   void wxCamDrawControl::OnPaint(wxPaintEvent & event)
00168 
00169 
00170     Author:     Alex_Bligh <alex@alex.org.uk>
00171     Created:    30/12/2005
00172     Inputs:     event - the event
00173     Outputs:    -
00174     Returns:    -
00175     Purpose:    Paints the control
00176     Errors:     -
00177     SeeAlso:    -
00178 
00179 ********************************************************************************************/
00180 
00181 void wxCamDrawControl::OnPaint(wxPaintEvent & event)
00182 {
00183     if (!m_Frozen)
00184     {
00185         wxCamDialogEvent RedrawEvent(wxEVT_CAMDIALOG_REDRAW, GetId());
00186         wxWindow * pParent=GetParent();
00187         if (pParent)
00188             pParent->GetEventHandler()->ProcessEvent(RedrawEvent);  
00189     }
00190 }
00191 
00192 /********************************************************************************************
00193 
00194 >   void wxCamDrawControl::OnSize(wxSizeEvent & event)
00195 
00196 
00197     Author:     Alex_Bligh <alex@alex.org.uk>
00198     Created:    30/12/2005
00199     Inputs:     event - the event
00200     Outputs:    -
00201     Returns:    -
00202     Purpose:    Handles resizing of a control
00203     Errors:     -
00204     SeeAlso:    -
00205 
00206 This is passed to the containing window's event handler for information
00207 
00208 ********************************************************************************************/
00209 
00210 void wxCamDrawControl::OnSize(wxSizeEvent & event)
00211 {
00212     wxWindow * pParent=GetParent();
00213     if (pParent)
00214         pParent->GetEventHandler()->ProcessEvent(event);    
00215 
00216     event.Skip();   // Pretend we didn't handle it
00217 }
00218 
00219 
00220 /********************************************************************************************
00221 
00222 >   void wxCamDrawControl::OnMouseEvent(wxMouseEvent & event)
00223 
00224 
00225     Author:     Alex_Bligh <alex@alex.org.uk>
00226     Created:    30/12/2005
00227     Inputs:     event - the event
00228     Outputs:    -
00229     Returns:    -
00230     Purpose:    Handles mouse events
00231     Errors:     -
00232     SeeAlso:    -
00233 
00234 ********************************************************************************************/
00235 
00236 void wxCamDrawControl::OnMouseEvent(wxMouseEvent & event)
00237 {
00238     // Irritatingly wxMouseEvent does not propagate to the parent, but we expect it to.
00239     // so we have to fake it (sigh)
00240     // event.Skip(); // pretend we did not handle it, so it falls through to the dialog
00241 
00242     if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) )
00243     {
00244         wxWindow * pParent = GetParent();
00245         if (pParent && !pParent->IsBeingDeleted())
00246         {
00247             wxEvtHandler *pHandler = pParent->GetEventHandler();
00248             if (pHandler && pHandler->IsKindOf(CLASSINFO(DialogEventHandler))) // Only propagate to our own dialogs
00249             {
00250                 pHandler->ProcessEvent(event);
00251             }
00252         }
00253     }
00254 }
00255 
00256 
00257 
00258 /********************************************************************************************
00259 
00260 >   void wxCamDrawControl::OnInvoke(wxCamDrawControlEvent & event)
00261 
00262 
00263     Author:     Alex_Bligh <alex@alex.org.uk>
00264     Created:    30/12/2005
00265     Inputs:     event - the event
00266     Outputs:    -
00267     Returns:    -
00268     Purpose:    Handles deferred invoke events
00269     Errors:     -
00270     SeeAlso:    -
00271 
00272 We do not process these immediately because otherwise the application does not have a chance
00273 to redraw between undo etc. Instead we send a deferred message back to ourselves
00274 
00275 ********************************************************************************************/
00276 
00277 void wxCamDrawControl::OnInvoke(wxCamDrawControlEvent & event)
00278 {
00279     Invoke();
00280 }
00281 
00282 /********************************************************************************************
00283 
00284 >   void wxCamDrawControl::Invoke()
00285 
00286 
00287     Author:     Alex_Bligh <alex@alex.org.uk>
00288     Created:    30/12/2005
00289     Inputs:     -
00290     Outputs:    -
00291     Returns:    -
00292     Purpose:    Does the work of the button being pressed
00293     Errors:     -
00294     SeeAlso:    -
00295 
00296 We send ourselves our COMMAND event (which DialogManager picks up) and invoke the op
00297 descriptor attached ourselves.
00298 
00299 ********************************************************************************************/
00300 
00301 void wxCamDrawControl::Invoke()
00302 {
00303     if (!IsEnabled())
00304     {
00305         return; // Don't even send messages if the control is greyed
00306     }
00307 
00308     wxCommandEvent ButtonEvent(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
00309     ProcessEvent(ButtonEvent);
00310     // If it's attached to an OpDescriptor, we invoke it.
00311 //  ControlList::Get()->Invoke(this);
00312 }
00313 
00314 /********************************************************************************************
00315 
00316 >   wxCamDrawControlXmlHandler::wxCamDrawControlXmlHandler()
00317 
00318 
00319     Author:     Alex_Bligh <alex@alex.org.uk>
00320     Created:    30/12/2005
00321     Inputs:     -
00322     Outputs:    -
00323     Returns:    -
00324     Purpose:    Constructor
00325     Errors:     -
00326     SeeAlso:    -
00327 
00328 ********************************************************************************************/
00329 
00330 wxCamDrawControlXmlHandler::wxCamDrawControlXmlHandler() : wxXmlResourceHandler()
00331 {
00332     XRC_ADD_STYLE(wxCDCS_DEFAULT);
00333     XRC_ADD_STYLE(wxCDCS_SETCLIPRECT);
00334     AddWindowStyles();
00335 }
00336 
00337 /********************************************************************************************
00338 
00339 >   wxObject * wxCamDrawControlXmlHandler::DoCreateResource()
00340 
00341 
00342     Author:     Alex_Bligh <alex@alex.org.uk>
00343     Created:    30/12/2005
00344     Inputs:     -
00345     Outputs:    -
00346     Returns:    -
00347     Purpose:    Creates a wxCamDrawControl from XML
00348     Errors:     -
00349     SeeAlso:    -
00350 
00351 ********************************************************************************************/
00352 
00353 wxObject * wxCamDrawControlXmlHandler::DoCreateResource()
00354 {
00355     XRC_MAKE_INSTANCE(control, wxCamDrawControl);
00356     control->Create(m_parentAsWindow,
00357                     GetID(),
00358                     GetPosition(),
00359                     GetSize(),
00360                     (GetStyle() & ~wxBORDER_MASK) | wxNO_BORDER,
00361                     wxDefaultValidator,
00362                     (wxCamDrawControlStyle)GetStyle(_T("camdrawstyle")),
00363                     GetParamValue(_T("optoken"))
00364                     );
00365 
00366     SetupWindow(control);
00367 
00368     return control;
00369 }
00370 
00371 /********************************************************************************************
00372 
00373 >   bool [TYPENOTE: Correct] wxCamDrawControlXmlHandler::DoCreateResource()
00374 
00375 
00376     Author:     Alex_Bligh <alex@alex.org.uk>
00377     Created:    30/12/2005
00378     Inputs:     node - a pointer to the xml node
00379     Outputs:    -
00380     Returns:    TRUE if we can load it
00381     Purpose:    Determines whether or not we can handle an object type
00382     Errors:     -
00383     SeeAlso:    -
00384 
00385 ********************************************************************************************/
00386 
00387 bool /*TYPENOTE: Correct*/ wxCamDrawControlXmlHandler::CanHandle(wxXmlNode *node)
00388 {
00389     bool    fOurClass = node->GetPropVal(wxT("class"), wxEmptyString) == wxT("wxCamDrawControl");
00390     return fOurClass;
00391 
00392     // This doesn't work on some compilers (although it is identical to what's above
00393     // just not in a function implemented in a header)
00394 //  return (IsOfClass(node, wxT("wxCamDrawControl")));
00395 }

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