dlgevt.cpp

Go to the documentation of this file.
00001 // $Id: dlgevt.cpp 1729 2006-08-30 12:48:48Z luke $
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 "camelot.h"
00103 #include "dlgevt.h"
00104 #include "dlgmgr.h"
00105 #include "camframe.h"
00106 //#include "dialogop.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 #include "ctrllist.h"
00108 #include "dropdown.h"
00109 #include "griddropdown.h"
00110 
00111 const TCHAR * DialogEventHandler::DefaultString = _T("[Event Name Not Found]\0");
00112 EventNumberToName * DialogEventHandler::pHash = NULL;
00113 DialogEventHandler * DialogEventHandler::m_GrimReaper = NULL;
00114 
00115 /*****************************************************************************
00116 
00117 This file contains the class for DialogEventHandler, derived from
00118 wxEvtHandler. This contains a mapping allowing dialogs of ANY class
00119 derived from wxDialog to call the relevant bits of DialogManager.
00120 
00121 *****************************************************************************/
00122 
00123 IMPLEMENT_CLASS( DialogEventHandler, wxEvtHandler )
00124 BEGIN_EVENT_TABLE(DialogEventHandler, wxEvtHandler)
00125     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, DialogEventHandler::CommandEvent)
00126     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, DialogEventHandler::CommandEvent)
00127     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, DialogEventHandler::CommandEvent)
00128     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_LISTBOX_SELECTED, DialogEventHandler::CommandEvent)
00129     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, DialogEventHandler::CommandEvent)
00130     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, DialogEventHandler::CommandEvent)
00131     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, DialogEventHandler::CommandEvent)    // only with WXWIN_COMPATIBILITY_EVENT_TYPES
00132     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_TEXT_ENTER, DialogEventHandler::CommandEvent)  // only with WXWIN_COMPATIBILITY_EVENT_TYPES
00133     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_TEXT_URL, DialogEventHandler::CommandEvent)        // only with WXWIN_COMPATIBILITY_EVENT_TYPES
00134     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_TEXT_MAXLEN, DialogEventHandler::CommandEvent) // only with WXWIN_COMPATIBILITY_EVENT_TYPES
00135     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, DialogEventHandler::CommandEvent)
00136     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_SLIDER_UPDATED, DialogEventHandler::CommandEvent)
00137     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_RADIOBOX_SELECTED, DialogEventHandler::CommandEvent)
00138     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_RADIOBUTTON_SELECTED, DialogEventHandler::CommandEvent)
00139 //  EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_SCROLLBAR_UPDATED, DialogEventHandler::CommandEvent) // Obselete - see wxWVT_SCROLL
00140     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_VLBOX_SELECTED, DialogEventHandler::CommandEvent)
00141     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_COMBOBOX_SELECTED, DialogEventHandler::CommandEvent)
00142     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_TOOL_RCLICKED, DialogEventHandler::CommandEvent)
00143     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_TOOL_ENTER, DialogEventHandler::CommandEvent)
00144     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, DialogEventHandler::CommandEvent)
00145     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_TREE_SEL_CHANGED, DialogEventHandler::CommandEvent)
00146     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, DialogEventHandler::CommandEvent)
00147     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, DialogEventHandler::CommandEvent)
00148 /*
00149     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED, DialogEventHandler::CommandEvent)
00150     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING, DialogEventHandler::CommandEvent)
00151     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED, DialogEventHandler::CommandEvent)
00152     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING, DialogEventHandler::CommandEvent)
00153     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED, DialogEventHandler::CommandEvent)
00154     EVT_COMMAND (wxID_ANY, wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING, DialogEventHandler::CommandEvent)
00155 */
00156     EVT_COMMAND_SCROLL (wxID_ANY, DialogEventHandler::ScrollEvent)
00157     EVT_SCROLL  (DialogEventHandler::ScrollEvent)
00158     EVT_CLOSE   (DialogEventHandler::CloseEvent)
00159     EVT_WINDOW_DESTROY  (DialogEventHandler::WindowDestroyEvent)
00160     EVT_MOUSE_EVENTS (DialogEventHandler::MouseEvent)
00161     EVT_CHILD_FOCUS( DialogEventHandler::OnChildFocus )
00162     EVT_SET_FOCUS( DialogEventHandler::OnSetFocus )
00163     EVT_CAMDIALOG_DEFERREDMSG (wxID_ANY, DialogEventHandler::CamDialogEvent)
00164     EVT_CAMDIALOG_GRIMREAPER (wxID_ANY, DialogEventHandler::GrimReaperEvent)
00165     EVT_CAMDIALOG_REDRAW (wxID_ANY, DialogEventHandler::CamDialogEvent)
00166     EVT_MOVE    (DialogEventHandler::MoveEvent)
00167     EVT_SIZE    (DialogEventHandler::SizeEvent)
00168 
00169 END_EVENT_TABLE();
00170 
00171 DEFINE_EVENT_TYPE(wxEVT_CAMDIALOG_DEFERREDMSG)
00172 DEFINE_EVENT_TYPE(wxEVT_CAMDIALOG_GRIMREAPER)
00173 DEFINE_EVENT_TYPE(wxEVT_CAMDIALOG_REDRAW)
00174 IMPLEMENT_DYNAMIC_CLASS( wxCamDialogEvent, wxEvent )
00175 
00176 CC_IMPLEMENT_DYNAMIC(DlgEvtTimer, KernelTimer);
00177 
00178 
00179 /********************************************************************************************
00180 
00181 >   void DialogEvtTimer::OnNotify()
00182 
00183     Author:     Alex_Bligh <alex@alex.org.uk>
00184     Created:    15/05/2005
00185     Inputs:     None
00186     Outputs:    None
00187     Returns:    -
00188     Purpose:    Act on a timer event
00189     Errors:     -
00190     SeeAlso:    -
00191 
00192 ********************************************************************************************/
00193 
00194 void DlgEvtTimer::Notify()
00195 {
00196     if (m_lpfnTimer)
00197     {
00198         (*m_lpfnTimer)(m_Param);
00199     }
00200     else
00201     {
00202         //  We need to send a DIM_TIMER to the DialogOp
00203         BROADCAST_TO_CLASS(DialogMsg(m_pEvtHandler->pwxWindow, DIM_TIMER, 0, (UINT_PTR)m_IDEvent, 0), DialogOp);
00204     }
00205 }
00206 
00207 /********************************************************************************************
00208 
00209 >   DialogEventHandler::DialogEventHandler()
00210 
00211 
00212     Author:     Alex_Bligh <alex@alex.org.uk>
00213     Created:    02/12/2005
00214     Inputs:     -
00215     Outputs:    -
00216     Returns:    -
00217     Purpose:    Constructor
00218     Errors:     -
00219     SeeAlso:    -
00220 
00221 ********************************************************************************************/
00222 
00223 DialogEventHandler::DialogEventHandler()
00224 {
00225     pwxWindow = NULL;
00226     pDialogOp = NULL;
00227     ID=0;
00228     wxAUImanaged=FALSE;
00229     m_GrimReaperSent=FALSE;
00230 }
00231 
00232 
00233 /********************************************************************************************
00234 
00235 >   DialogEventHandler::DialogEventHandler(DialogOp * pOp)
00236 
00237 
00238     Author:     Alex_Bligh <alex@alex.org.uk>
00239     Created:    02/12/2005
00240     Inputs:     -
00241     Outputs:    -
00242     Returns:    -
00243     Purpose:    Constructor
00244     Errors:     -
00245     SeeAlso:    -
00246 
00247 ********************************************************************************************/
00248 
00249 DialogEventHandler::DialogEventHandler(DialogOp * pOp)
00250 {
00251     pwxWindow = NULL;
00252     pDialogOp = pOp;
00253     ID=0;
00254     wxAUImanaged=FALSE;
00255     m_GrimReaperSent=FALSE;
00256     m_TimerHash.clear();
00257 }
00258 
00259 /********************************************************************************************
00260 
00261 >   DialogEventHandler::~DialogEventHandler()
00262 
00263 
00264     Author:     Alex_Bligh <alex@alex.org.uk>
00265     Created:    02/12/2005
00266     Inputs:     -
00267     Outputs:    -
00268     Returns:    -
00269     Purpose:    Destructor
00270     Errors:     -
00271     SeeAlso:    -
00272 
00273 Note we don't normally delete these directly - we Destroy() them, which is safe even within the
00274 event handler itself
00275 
00276 ********************************************************************************************/
00277 
00278 DialogEventHandler::~DialogEventHandler()
00279 {
00280     // clear out the kernel timers so they don't go off - this should have been done by Destroy()
00281     while (!m_TimerHash.empty())
00282     {
00283         IntegerToKernelTimer::iterator current = m_TimerHash.begin();
00284         DlgEvtTimer * t=current->second;
00285         m_TimerHash.erase(current);
00286         if (t)
00287             delete t;
00288     }
00289     // for good measure
00290     m_TimerHash.clear();
00291 }
00292 
00293 /********************************************************************************************
00294 
00295 >   DialogEventHandler::Destroy()
00296 
00297 
00298     Author:     Alex_Bligh <alex@alex.org.uk>
00299     Created:    02/12/2005
00300     Inputs:     -
00301     Outputs:    -
00302     Returns:    -
00303     Purpose:    Disconnect the DialogEventHandler from its pDialogOp and schedule destruction
00304     Errors:     -
00305     SeeAlso:    -
00306 
00307 Note we don't normally delete these directly - we Destroy() them, which is safe even within the
00308 event handler itself
00309 
00310 ********************************************************************************************/
00311 
00312 void DialogEventHandler::Destroy()
00313 {
00314     if (this == m_GrimReaper)
00315     {
00316         // Grim Reaper cannot delete itself as its in its own event handler. It must be
00317         // explicitly deleted on deinit
00318         ERROR3("You cannot destroy the Grim Reaper that easily!");
00319         return;
00320     }
00321 
00322     if (!m_GrimReaperSent)
00323     {
00324         // clear out the kernel timers so they don't go off after Destroy()
00325         while (!m_TimerHash.empty())
00326         {
00327             IntegerToKernelTimer::iterator current = m_TimerHash.begin();
00328             DlgEvtTimer * t=current->second;
00329             m_TimerHash.erase(current);
00330             if (t)
00331                 delete t;
00332         }
00333         // for good measure
00334         m_TimerHash.clear();
00335 
00336         // Disconnect from the DialogOp
00337         if (pDialogOp)
00338             pDialogOp->pEvtHandler=NULL;
00339         
00340         // Zap out all the variables
00341         pDialogOp = NULL;
00342         pwxWindow = NULL;
00343         ID = 0;
00344         wxCamDialogEvent deferredevent (wxEVT_CAMDIALOG_GRIMREAPER, 0, DialogMsg(NULL, DIM_NONE, 0, (UINT_PTR)(void *)(this),0));
00345         if (m_GrimReaper)
00346         {
00347             m_GrimReaper->AddPendingEvent(deferredevent);
00348             return;
00349         }
00350         else
00351         {
00352             ERROR3("Can't call upon the grim reaper. Leaking memory");
00353         }
00354         m_GrimReaperSent = TRUE; // Don't do another
00355     }
00356 }
00357 
00358 
00359 /********************************************************************************************
00360 
00361 >   DialogEventHandler::GrimReaperEvent(wxCamDialogEvent& event)
00362 
00363 
00364     Author:     Alex_Bligh <alex@alex.org.uk>
00365     Created:    02/12/2005
00366     Inputs:     event - the wxEvent
00367     Outputs:    -
00368     Returns:    -
00369     Purpose:    Called when we need to kill off a DialogEventHandler
00370     Errors:     -
00371     SeeAlso:    -
00372 
00373 For some reason we can't declare this guy static.
00374 
00375 ********************************************************************************************/
00376 
00377 
00378 void DialogEventHandler::GrimReaperEvent(wxCamDialogEvent& event)
00379 {
00380     WXTYPE EventType = event.GetEventType();
00381     if (!(event.IsKindOf(CLASSINFO(wxCamDialogEvent)) && (EventType == wxEVT_CAMDIALOG_GRIMREAPER)))
00382     {
00383         ERROR3("Grim Reaper called with bad parameters");
00384         return;
00385     }
00386     
00387     if (this != m_GrimReaper)
00388     {
00389         ERROR3("Grim Reaper event sent to an event handler other than the GrimReaper");
00390         return;
00391     }
00392 
00393     DialogEventHandler * pEvtHandler = (DialogEventHandler *)(void *)event.msg.DlgMsgParam;
00394     if (!pEvtHandler->IsKindOf(CLASSINFO(DialogEventHandler)))
00395     {
00396         ERROR3("Grim Reaper called with a non event handler parameter");
00397         return;
00398     }
00399 
00400     if (pEvtHandler == this)
00401     {
00402         ERROR3("The grim reaper cannot kill itself"); // we are in our own event handler, so this would be bad
00403         return;
00404     }
00405 
00406     TRACEUSER("amb", _T("Grim reaper reaped an event handler at %016llx"), pEvtHandler);
00407     delete pEvtHandler;
00408 }
00409 
00410 /********************************************************************************************
00411 
00412 >   DialogEventHandler::CommandEvent(wxCommandEvent& event)
00413 
00414 
00415     Author:     Alex_Bligh <alex@alex.org.uk>
00416     Created:    02/12/2005
00417     Inputs:     event - the wxEvent
00418     Outputs:    -
00419     Returns:    -
00420     Purpose:    Passes an event to DialogManager::Event
00421     Errors:     -
00422     SeeAlso:    -
00423 
00424 ********************************************************************************************/
00425 
00426 
00427 void DialogEventHandler::CommandEvent(wxCommandEvent& event)
00428 {
00429     DialogManager::Event(this, event);
00430 }
00431 
00432 /********************************************************************************************
00433 
00434 >   DialogEventHandler::ScrollEvent(wxScrollEvent& event)
00435 
00436 
00437     Author:     Alex_Bligh <alex@alex.org.uk>
00438     Created:    02/12/2005
00439     Inputs:     event - the wxEvent
00440     Outputs:    -
00441     Returns:    -
00442     Purpose:    Passes an event to DialogManager::Event
00443     Errors:     -
00444     SeeAlso:    -
00445 
00446 ********************************************************************************************/
00447 
00448 
00449 void DialogEventHandler::ScrollEvent(wxScrollEvent& event)
00450 {
00451     DialogManager::Event(this, event);
00452 }
00453 
00454 /********************************************************************************************
00455 
00456 >   DialogEventHandler::MouseEvent(wxMouseEvent& event)
00457 
00458 
00459     Author:     Alex_Bligh <alex@alex.org.uk>
00460     Created:    02/12/2005
00461     Inputs:     event - the wxEvent
00462     Outputs:    -
00463     Returns:    -
00464     Purpose:    Passes an event to DialogManager::Event
00465     Errors:     -
00466     SeeAlso:    -
00467 
00468 ********************************************************************************************/
00469 
00470 
00471 void DialogEventHandler::MouseEvent(wxMouseEvent& event)
00472 {
00473     DialogManager::Event(this, event);
00474 }
00475 
00476 /********************************************************************************************
00477 
00478 >   DialogEventHandler::CloseEvent(wxCloseEvent& event)
00479 
00480 
00481     Author:     Alex_Bligh <alex@alex.org.uk>
00482     Created:    02/12/2005
00483     Inputs:     event - the wxEvent
00484     Outputs:    -
00485     Returns:    -
00486     Purpose:    Passes an event to DialogManager::Event
00487     Errors:     -
00488     SeeAlso:    -
00489 
00490 ********************************************************************************************/
00491 
00492 
00493 void DialogEventHandler::CloseEvent(wxCloseEvent& event)
00494 {
00495     DialogManager::Event(this, event);
00496 }
00497 
00498 /********************************************************************************************
00499 
00500 >   DialogEventHandler::WindowDestroyEvent(wxWindowDestroyEvent& event)
00501 
00502 
00503     Author:     Alex_Bligh <alex@alex.org.uk>
00504     Created:    02/12/2005
00505     Inputs:     event - the wxEvent
00506     Outputs:    -
00507     Returns:    -
00508     Purpose:    Passes an event to DialogManager::Event
00509     Errors:     -
00510     SeeAlso:    -
00511 
00512 ********************************************************************************************/
00513 
00514 
00515 void DialogEventHandler::WindowDestroyEvent(wxWindowDestroyEvent& event)
00516 {
00517     if (!event.IsKindOf(CLASSINFO(wxWindowDestroyEvent)))
00518         return; // How did that get here?
00519 
00520     DialogManager::Event(this, event);
00521 
00522     // we are only interested in our window being destroyed from now on, as opposed to
00523     // children of our window
00524     if (event.GetEventObject() != pwxWindow)
00525         return;
00526 
00527     // Now diassociate all the window controls
00528     // Note this may have already been done by DialogManager, but in that case (a) pwxWindow won't
00529     // be non-NULL, and (b) we'll have removed the EventHandler from the queue, so we won't be
00530     // called anyway
00531     if (pwxWindow)
00532     {
00533         DropDown::KillDropDownsByWindow(pwxWindow);
00534         CGridDropDown::KillDropDownsByWindow(pwxWindow);
00535         ControlList::Get()->RemoveWindowAndChildren(pwxWindow);
00536     }
00537 
00538     if (!m_GrimReaperSent)
00539     {
00540         m_GrimReaperSent= TRUE; // Stop DialogManager::Delete() from doing anything
00541         TRACE(_T("DialogEventHandler::CloseEvent called on window which has been closed other than through DialogManager\n"));
00542         TRACE(_T("This should never happen. Cleaning up the horrible mess as best we can\n"));
00543         if (pDialogOp)
00544         {
00545             // there is a running DialogOp. Let's try ending it
00546             pDialogOp->End();
00547         }
00548         m_GrimReaperSent = FALSE; // ensure Destroy() works
00549         Destroy(); // Destroy ourselves (as opposed to the window) if this hasn't happened already
00550     }
00551 }
00552 
00553 /********************************************************************************************
00554 
00555 >   DialogEventHandler::OnChildFocus(wxChildFocusEvent& event)
00556 
00557 
00558     Author:     Luke_Hart <alex@alex.org.uk>
00559     Created:    02/05/06
00560     Inputs:     event - the wxEvent
00561     Outputs:    -
00562     Returns:    -
00563     Purpose:    Gives the event back to the page if need be
00564     Errors:     -
00565     SeeAlso:    -
00566 
00567 ********************************************************************************************/
00568 
00569 
00570 void DialogEventHandler::OnChildFocus(wxChildFocusEvent &event)
00571 {
00572     // Check if focus is going to an always focus object (may need more tests
00573     // as more controls come online). If so just return allowing focus to stay
00574     wxWindow*   pWnd = (wxWindow*)event.GetEventObject();
00575 
00576     TRACEUSER("luke", _T("DialogEventHandler::OnSetFocus %s"), pWnd->GetClassInfo()->GetClassName());
00577 
00578     if( pWnd->IsKindOf( CLASSINFO(wxTextCtrl) ) ||
00579         pWnd->IsKindOf( CLASSINFO(wxSliderCombo) ) ||
00580         pWnd->IsKindOf( CLASSINFO(wxComboBox) ) ||
00581         pWnd->IsKindOf( CLASSINFO(wxOwnerDrawnComboBox) ) ||
00582         pWnd->IsKindOf( CLASSINFO(wxComboCtrl) ) )
00583     {
00584         TRACEUSER("luke", _T("DialogEventHandler::OnSetFocus Focus undisturbed 1"));
00585         return;
00586     }
00587 
00588     // Scan down ancestors looking for either wxPanels (always non-modal) and
00589     // wxDailogs (can be modal, so we check)
00590     while( NULL != pWnd && !pWnd->IsKindOf( CLASSINFO(wxPanel) ) )
00591     {
00592         // Dialogs may-be modal so check
00593         if( pWnd->IsKindOf( CLASSINFO(wxDialog) ) )
00594         {
00595             if( ((wxDialog*)pWnd)->IsModal() )
00596             {
00597                 TRACEUSER("luke", _T("Focus undisturbed 2"));
00598                 return;
00599             }
00600 
00601             // Non-modal dialog so do focus handling
00602             break;
00603         }
00604 
00605         pWnd = pWnd->GetParent();
00606     }
00607 
00608     TRACEUSER("luke", _T("DialogEventHandler::OnSetFocus Focus back to canvas"));
00609     // Put the focus back into active view
00610     TRACEUSER( "luke", _T("NO, that control is not allowed focus") );
00611     AfxGetApp().GiveActiveCanvasFocus();
00612 }
00613 
00614 /********************************************************************************************
00615 
00616 >   DialogEventHandler::OnSetFocus(wxFocusEvent& event)
00617 
00618 
00619     Author:     Luke_Hart <alex@alex.org.uk>
00620     Created:    02/05/06
00621     Inputs:     event - the wxEvent
00622     Outputs:    -
00623     Returns:    -
00624     Purpose:    Passes an event to DialogManager::Event
00625     Errors:     -
00626     SeeAlso:    -
00627 
00628 ********************************************************************************************/
00629 
00630 
00631 void DialogEventHandler::OnSetFocus(wxFocusEvent &event)
00632 {
00633     TRACEUSER( "luke", _T("OnSetFocus") );
00634     
00635     // Do nothing for the time being
00636     event.Skip();
00637 }
00638 
00639 
00640 /********************************************************************************************
00641 
00642 >   DialogEventHandler::CamDialogEvent(wxCamDialogEvent& event)
00643 
00644 
00645     Author:     Alex_Bligh <alex@alex.org.uk>
00646     Created:    02/12/2005
00647     Inputs:     event - the wxEvent
00648     Outputs:    -
00649     Returns:    -
00650     Purpose:    Passes an event to DialogManager::Event
00651     Errors:     -
00652     SeeAlso:    -
00653 
00654 ********************************************************************************************/
00655 
00656 
00657 void DialogEventHandler::CamDialogEvent(wxCamDialogEvent& event)
00658 {
00659     DialogManager::Event(this, event);
00660 }
00661 
00662 /********************************************************************************************
00663 
00664 >   DialogEventHandler::MoveEvent(wxMoveEvent& event)
00665 
00666 
00667     Author:     Alex_Bligh <alex@alex.org.uk>
00668     Created:    02/12/2005
00669     Inputs:     event - the wxEvent
00670     Outputs:    -
00671     Returns:    -
00672     Purpose:    Passes an event to DialogManager::Event
00673     Errors:     -
00674     SeeAlso:    -
00675 
00676 ********************************************************************************************/
00677 
00678 
00679 void DialogEventHandler::MoveEvent(wxMoveEvent& event)
00680 {
00681     DialogManager::Event(this, event);
00682 
00683     // We pretend we didn't handle it, since dialogs with sizers etc. will need it
00684     event.Skip();
00685 }
00686 
00687 /********************************************************************************************
00688 
00689 >   DialogEventHandler::SizeEvent(wxSizeEvent& event)
00690 
00691 
00692     Author:     Alex_Bligh <alex@alex.org.uk>
00693     Created:    02/12/2005
00694     Inputs:     event - the wxEvent
00695     Outputs:    -
00696     Returns:    -
00697     Purpose:    Passes an event to DialogManager::Event
00698     Errors:     -
00699     SeeAlso:    -
00700 
00701 ********************************************************************************************/
00702 
00703 
00704 void DialogEventHandler::SizeEvent(wxSizeEvent& event)
00705 {
00706     DialogManager::Event(this, event);
00707     
00708     // We pretend we didn't handle it, since dialogs with sizers etc. will need it
00709     event.Skip();
00710 }
00711 
00712 /********************************************************************************************
00713 
00714 >   DialogEventHandler::NotebookEvent(wxNotebookEvent& event)
00715 
00716 
00717     Author:     Alex_Bligh <alex@alex.org.uk>
00718     Created:    02/12/2005
00719     Inputs:     event - the wxEvent
00720     Outputs:    -
00721     Returns:    -
00722     Purpose:    Passes an event to DialogManager::Event
00723     Errors:     -
00724     SeeAlso:    -
00725 
00726 ********************************************************************************************/
00727 
00728 
00729 void DialogEventHandler::NotebookEvent(wxNotebookEvent& event)
00730 {
00731     DialogManager::Event(this, event);
00732 }
00733 
00734 /********************************************************************************************
00735 
00736 >   static inline const TCHAR * DialogEventHandler::GetEventName(WXTYPE eventnum)
00737 
00738 
00739     Author:     Alex_Bligh <alex@alex.org.uk>
00740     Created:    02/12/2005
00741     Inputs:     event number
00742     Outputs:    -
00743     Returns:    pointer to a string containing the event number
00744     Purpose:    Returns a textual string corresponding with an event
00745     Errors:     -
00746     SeeAlso:    -
00747 
00748 ********************************************************************************************/
00749 
00750 #define EVTDECODE(x) if (eventnum == x) return(_T( ## x));
00751 
00752 /********************************************************************************************
00753 
00754 >   static BOOL DialogEventHandler::Init()
00755 
00756 
00757     Author:     Alex_Bligh <alex@alex.org.uk>
00758     Created:    02/12/2005
00759     Inputs:     None
00760     Outputs:    None
00761     Returns:    TRUE if succeeded, FALSE if fails
00762     Purpose:    Initialize resources
00763     Errors:     via wxMessageBox
00764     SeeAlso:    -
00765 
00766 ********************************************************************************************/
00767 
00768 BOOL DialogEventHandler::Init()
00769 {
00770     m_GrimReaper = new DialogEventHandler;
00771     if (!m_GrimReaper) return FALSE;
00772 
00773     pHash = new (EventNumberToName);
00774     if (!pHash) return FALSE;
00775 
00776     // Clear our own hash tables
00777     pHash->clear();
00778 
00779 #if _DEBUG
00780 
00781     #if 0 != wxUSE_UNICODE
00782     #define HASHEVENTNAME(x) (*pHash)[x] = (EventNameString)camStrdup(L ## #x)
00783     #else
00784     #define HASHEVENTNAME(x) (*pHash)[x] = (EventNameString)camStrdup(#x)
00785     #endif
00786 
00787     HASHEVENTNAME(wxEVT_COMMAND_BUTTON_CLICKED);
00788     HASHEVENTNAME(wxEVT_COMMAND_CHECKBOX_CLICKED);
00789     HASHEVENTNAME(wxEVT_COMMAND_CHOICE_SELECTED);
00790     HASHEVENTNAME(wxEVT_COMMAND_LISTBOX_SELECTED);
00791     HASHEVENTNAME(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
00792     HASHEVENTNAME(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED);
00793     HASHEVENTNAME(wxEVT_COMMAND_TEXT_UPDATED);
00794     HASHEVENTNAME(wxEVT_COMMAND_TEXT_ENTER);
00795     HASHEVENTNAME(wxEVT_COMMAND_TEXT_URL);
00796     HASHEVENTNAME(wxEVT_COMMAND_TEXT_MAXLEN);
00797     HASHEVENTNAME(wxEVT_COMMAND_MENU_SELECTED);
00798     HASHEVENTNAME(wxEVT_COMMAND_SLIDER_UPDATED);
00799     HASHEVENTNAME(wxEVT_COMMAND_RADIOBOX_SELECTED);
00800     HASHEVENTNAME(wxEVT_COMMAND_RADIOBUTTON_SELECTED);
00801     HASHEVENTNAME(wxEVT_COMMAND_SCROLLBAR_UPDATED);
00802     HASHEVENTNAME(wxEVT_COMMAND_VLBOX_SELECTED);
00803     HASHEVENTNAME(wxEVT_COMMAND_COMBOBOX_SELECTED);
00804     HASHEVENTNAME(wxEVT_COMMAND_TOOL_RCLICKED);
00805     HASHEVENTNAME(wxEVT_COMMAND_TOOL_ENTER);
00806     HASHEVENTNAME(wxEVT_COMMAND_SPINCTRL_UPDATED);
00807     HASHEVENTNAME(wxEVT_COMMAND_TREE_SEL_CHANGED);
00808     HASHEVENTNAME(wxEVT_SOCKET);
00809     HASHEVENTNAME(wxEVT_TIMER);
00810     HASHEVENTNAME(wxEVT_LEFT_DOWN);
00811     HASHEVENTNAME(wxEVT_LEFT_UP);
00812     HASHEVENTNAME(wxEVT_MIDDLE_DOWN);
00813     HASHEVENTNAME(wxEVT_MIDDLE_UP);
00814     HASHEVENTNAME(wxEVT_RIGHT_DOWN);
00815     HASHEVENTNAME(wxEVT_RIGHT_UP);
00816     HASHEVENTNAME(wxEVT_MOTION);
00817     HASHEVENTNAME(wxEVT_ENTER_WINDOW);
00818     HASHEVENTNAME(wxEVT_LEAVE_WINDOW);
00819     HASHEVENTNAME(wxEVT_LEFT_DCLICK);
00820     HASHEVENTNAME(wxEVT_MIDDLE_DCLICK);
00821     HASHEVENTNAME(wxEVT_RIGHT_DCLICK);
00822     HASHEVENTNAME(wxEVT_SET_FOCUS);
00823     HASHEVENTNAME(wxEVT_KILL_FOCUS);
00824     HASHEVENTNAME(wxEVT_CHILD_FOCUS);
00825     HASHEVENTNAME(wxEVT_MOUSEWHEEL);
00826     HASHEVENTNAME(wxEVT_NC_LEFT_DOWN);
00827     HASHEVENTNAME(wxEVT_NC_LEFT_UP);
00828     HASHEVENTNAME(wxEVT_NC_MIDDLE_DOWN);
00829     HASHEVENTNAME(wxEVT_NC_MIDDLE_UP);
00830     HASHEVENTNAME(wxEVT_NC_RIGHT_DOWN);
00831     HASHEVENTNAME(wxEVT_NC_RIGHT_UP);
00832     HASHEVENTNAME(wxEVT_NC_MOTION);
00833     HASHEVENTNAME(wxEVT_NC_ENTER_WINDOW);
00834     HASHEVENTNAME(wxEVT_NC_LEAVE_WINDOW);
00835     HASHEVENTNAME(wxEVT_NC_LEFT_DCLICK);
00836     HASHEVENTNAME(wxEVT_NC_MIDDLE_DCLICK);
00837     HASHEVENTNAME(wxEVT_NC_RIGHT_DCLICK);
00838     HASHEVENTNAME(wxEVT_CHAR);
00839     HASHEVENTNAME(wxEVT_CHAR_HOOK);
00840     HASHEVENTNAME(wxEVT_NAVIGATION_KEY);
00841     HASHEVENTNAME(wxEVT_KEY_DOWN);
00842     HASHEVENTNAME(wxEVT_KEY_UP);
00843 //    HASHEVENTNAME(wxEVT_HOTKEY);
00844     HASHEVENTNAME(wxEVT_SET_CURSOR);
00845     HASHEVENTNAME(wxEVT_SCROLL_TOP);
00846     HASHEVENTNAME(wxEVT_SCROLL_BOTTOM);
00847     HASHEVENTNAME(wxEVT_SCROLL_LINEUP);
00848     HASHEVENTNAME(wxEVT_SCROLL_LINEDOWN);
00849     HASHEVENTNAME(wxEVT_SCROLL_PAGEUP);
00850     HASHEVENTNAME(wxEVT_SCROLL_PAGEDOWN);
00851     HASHEVENTNAME(wxEVT_SCROLL_THUMBTRACK);
00852     HASHEVENTNAME(wxEVT_SCROLL_THUMBRELEASE);
00853     HASHEVENTNAME(wxEVT_SCROLL_CHANGED);
00854     HASHEVENTNAME(wxEVT_SCROLLWIN_TOP);
00855     HASHEVENTNAME(wxEVT_SCROLLWIN_BOTTOM);
00856     HASHEVENTNAME(wxEVT_SCROLLWIN_LINEUP);
00857     HASHEVENTNAME(wxEVT_SCROLLWIN_LINEDOWN);
00858     HASHEVENTNAME(wxEVT_SCROLLWIN_PAGEUP);
00859     HASHEVENTNAME(wxEVT_SCROLLWIN_PAGEDOWN);
00860     HASHEVENTNAME(wxEVT_SCROLLWIN_THUMBTRACK);
00861     HASHEVENTNAME(wxEVT_SCROLLWIN_THUMBRELEASE);
00862     HASHEVENTNAME(wxEVT_SIZE);
00863     HASHEVENTNAME(wxEVT_MOVE);
00864     HASHEVENTNAME(wxEVT_CLOSE_WINDOW);
00865     HASHEVENTNAME(wxEVT_END_SESSION);
00866     HASHEVENTNAME(wxEVT_QUERY_END_SESSION);
00867     HASHEVENTNAME(wxEVT_ACTIVATE_APP);
00868 //    HASHEVENTNAME(wxEVT_POWER);
00869     HASHEVENTNAME(wxEVT_ACTIVATE);
00870     HASHEVENTNAME(wxEVT_CREATE);
00871     HASHEVENTNAME(wxEVT_DESTROY);
00872     HASHEVENTNAME(wxEVT_SHOW);
00873     HASHEVENTNAME(wxEVT_ICONIZE);
00874     HASHEVENTNAME(wxEVT_MAXIMIZE);
00875     HASHEVENTNAME(wxEVT_MOUSE_CAPTURE_CHANGED);
00876     HASHEVENTNAME(wxEVT_PAINT);
00877     HASHEVENTNAME(wxEVT_ERASE_BACKGROUND);
00878     HASHEVENTNAME(wxEVT_NC_PAINT);
00879     HASHEVENTNAME(wxEVT_PAINT_ICON);
00880     HASHEVENTNAME(wxEVT_MENU_OPEN);
00881     HASHEVENTNAME(wxEVT_MENU_CLOSE);
00882     HASHEVENTNAME(wxEVT_MENU_HIGHLIGHT);
00883     HASHEVENTNAME(wxEVT_CONTEXT_MENU);
00884     HASHEVENTNAME(wxEVT_SYS_COLOUR_CHANGED);
00885     HASHEVENTNAME(wxEVT_DISPLAY_CHANGED);
00886     HASHEVENTNAME(wxEVT_SETTING_CHANGED);
00887     HASHEVENTNAME(wxEVT_QUERY_NEW_PALETTE);
00888     HASHEVENTNAME(wxEVT_PALETTE_CHANGED);
00889     HASHEVENTNAME(wxEVT_JOY_BUTTON_DOWN);
00890     HASHEVENTNAME(wxEVT_JOY_BUTTON_UP);
00891     HASHEVENTNAME(wxEVT_JOY_MOVE);
00892     HASHEVENTNAME(wxEVT_JOY_ZMOVE);
00893     HASHEVENTNAME(wxEVT_DROP_FILES);
00894     HASHEVENTNAME(wxEVT_DRAW_ITEM);
00895     HASHEVENTNAME(wxEVT_MEASURE_ITEM);
00896     HASHEVENTNAME(wxEVT_COMPARE_ITEM);
00897     HASHEVENTNAME(wxEVT_INIT_DIALOG);
00898     HASHEVENTNAME(wxEVT_IDLE);
00899     HASHEVENTNAME(wxEVT_UPDATE_UI);
00900     HASHEVENTNAME(wxEVT_SIZING);
00901     HASHEVENTNAME(wxEVT_MOVING);
00902     HASHEVENTNAME(wxEVT_HIBERNATE);
00903     HASHEVENTNAME(wxEVT_COMMAND_LEFT_CLICK);
00904     HASHEVENTNAME(wxEVT_COMMAND_LEFT_DCLICK);
00905     HASHEVENTNAME(wxEVT_COMMAND_RIGHT_CLICK);
00906     HASHEVENTNAME(wxEVT_COMMAND_RIGHT_DCLICK);
00907     HASHEVENTNAME(wxEVT_COMMAND_SET_FOCUS);
00908     HASHEVENTNAME(wxEVT_COMMAND_KILL_FOCUS);
00909     HASHEVENTNAME(wxEVT_COMMAND_ENTER);
00910     HASHEVENTNAME(wxEVT_HELP);
00911     HASHEVENTNAME(wxEVT_DETAILED_HELP);
00912 
00913     // And now our own...
00914     HASHEVENTNAME(wxEVT_CAMDIALOG_DEFERREDMSG);
00915     HASHEVENTNAME(wxEVT_CAMDIALOG_REDRAW);
00916 
00917     TRACE(_T(">>> Event name %d=%s"),wxEVT_COMMAND_BUTTON_CLICKED,GetEventName(wxEVT_COMMAND_BUTTON_CLICKED));
00918 
00919     WXTYPE EventNum=wxEVT_COMMAND_BUTTON_CLICKED;
00920     EventNumberToName::iterator i=pHash->find(EventNum);
00921     const TCHAR * text = (const TCHAR *)((i==pHash->end())?NULL:i->second);
00922     //return text?text:DefaultString;
00923     if (text)
00924     {
00925         TRACE(_T("Found text %d=%s"),EventNum,text);
00926     }
00927 
00928 #endif
00929     return TRUE;
00930 }
00931 
00932 /********************************************************************************************
00933 
00934 >   static void DialogEventHandler::DeInit()
00935 
00936 
00937     Author:     Alex_Bligh <alex@alex.org.uk>
00938     Created:    02/12/2005
00939     Inputs:     None
00940     Outputs:    None
00941     Returns:    TRUE if succeeded, FALSE if fails
00942     Purpose:    Initialize resources
00943     Errors:     via wxMessageBox
00944     SeeAlso:    -
00945 
00946 ********************************************************************************************/
00947 
00948 void DialogEventHandler::DeInit()
00949 {
00950     ::wxYield(); // Allow grim repear events to filter through
00951     if (m_GrimReaper)
00952     {
00953         delete m_GrimReaper;
00954         m_GrimReaper = NULL;
00955     }
00956 
00957     if (pHash)
00958     {
00959         EventNumberToName::iterator current;
00960         while (!pHash->empty())
00961         {
00962             current = pHash->begin();
00963             EventNameString s=current->second;
00964             pHash->erase(current);
00965             free((void *)s);
00966         }
00967         // for good measure
00968         pHash->clear();
00969         delete (pHash);
00970         pHash=NULL;
00971     }
00972 }
00973 
00974 /********************************************************************************************
00975 
00976 >   UINT32 DialogEventHandler::AddTimer((DialogOp * pDialogOp, UINT32 nIDEvent, UINT32 nElapse,
00977                         void (* lpfnTimer)(void *) =  NULL, void * param=NULL, BOOL OneShot=FALSE)
00978 
00979 
00980     Author:     Alex_Bligh <alex@alex.org.uk>
00981     Created:    02/12/2005
00982     Inputs:     parameters for the timer
00983     Outputs:    None
00984     Returns:    TRUE if succeeded, FALSE if fails
00985     Purpose:    Initialize resources
00986     Errors:     via wxMessageBox
00987     SeeAlso:    -
00988 
00989 ********************************************************************************************/
00990 
00991 UINT32 DialogEventHandler::AddTimer(DialogOp * pDialogOp, UINT32 nIDEvent, UINT32 nElapse,
00992             void (* lpfnTimer)(void *) /*= NULL*/, void * param/*=NULL*/, BOOL OneShot/*=FALSE*/)
00993 {
00994     DeleteTimer(nIDEvent);  // delete any previous timer
00995     DlgEvtTimer * pTimer = new DlgEvtTimer(this, pDialogOp, nIDEvent, lpfnTimer, param);
00996     if (!pTimer)
00997         return 0;
00998 
00999     m_TimerHash[nIDEvent]=pTimer;
01000     pTimer->Start(nElapse, OneShot);
01001     return nIDEvent;
01002 }
01003 
01004 /********************************************************************************************
01005 
01006 >   UINT32 DialogEventHandler::DeleteTimer(UINT32 nIDEvent)
01007 
01008 
01009     Author:     Alex_Bligh <alex@alex.org.uk>
01010     Created:    02/12/2005
01011     Inputs:     ID of the timer
01012     Outputs:    None
01013     Returns:    TRUE if succeeded, FALSE if fails
01014     Purpose:    Deletes a timer
01015     Errors:     -
01016     SeeAlso:    -
01017 
01018 ********************************************************************************************/
01019     
01020 BOOL DialogEventHandler::DeleteTimer(UINT32 nIDEvent)
01021 {
01022     IntegerToKernelTimer::iterator i=m_TimerHash.find(nIDEvent);
01023     if (i==m_TimerHash.end())
01024         return FALSE;
01025     m_TimerHash.erase(nIDEvent);
01026     return TRUE;
01027 }

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