00001 00002 // Name: wxGuiTest/CREventFactory.cpp 00003 // Author: Reinhold Fuereder 00004 // Created: 2004 00005 // Copyright: (c) 2005 Reinhold Fuereder 00006 // Licence: wxWindows licence 00007 // 00008 // $Id$ 00010 00011 #ifdef __GNUG__ 00012 #pragma implementation "CREventFactory.h" 00013 #endif 00014 00015 #include "CREventFactory.h" 00016 00017 #include <wx/notebook.h> 00018 #include <wx/treectrl.h> 00019 00020 #include "CapturedEvents/CRButtonClickEvent.h" 00021 #include "CapturedEvents/CRMenuSelectionEvent.h" 00022 #include "CapturedEvents/CRTextUpdateEvent.h" 00023 #include "CapturedEvents/CRNotebookPageChangeEvent.h" 00024 #include "CapturedEvents/CRChoiceSelectionEvent.h" 00025 #include "CapturedEvents/CRRadioBoxSelectionEvent.h" 00026 #include "CapturedEvents/CRCheckBoxClickEvent.h" 00027 #include "CapturedEvents/CRSliderUpdateEvent.h" 00028 #include "CapturedEvents/CRSpinCtrlUpdateEvent.h" 00029 #include "CapturedEvents/CRTreeSelectionChangingEvent.h" 00030 #include "CapturedEvents/CRTreeItemRightClickEvent.h" 00031 00032 namespace wxTst { 00033 00034 00035 // Init single instance: 00036 CREventFactory *CREventFactory::ms_instance = NULL; 00037 00038 00039 CREventFactory::CREventFactory () 00040 { 00041 // Nothing to do 00042 } 00043 00044 00045 CREventFactory::~CREventFactory () 00046 { 00047 // Nothing to do 00048 } 00049 00050 00051 CREventFactory * CREventFactory::GetInstance () 00052 { 00053 if (ms_instance == NULL) { 00054 00055 ms_instance = new CREventFactory (); 00056 } 00057 return ms_instance; 00058 } 00059 00060 00061 void CREventFactory::Destroy () 00062 { 00063 if (ms_instance != NULL) { 00064 00065 delete ms_instance; 00066 ms_instance = NULL; 00067 } 00068 } 00069 00070 00071 CRCapturedEvent * CREventFactory::CreateEvent (const wxEvent &event) const 00072 { 00073 int type = event.GetEventType (); 00074 if (type == wxEVT_COMMAND_BUTTON_CLICKED) { 00075 00076 return new CRButtonClickEvent (event.Clone ()); 00077 00078 } else if (type == wxEVT_COMMAND_MENU_SELECTED) { 00079 00080 return new CRMenuSelectionEvent (event.Clone ()); 00081 00082 } else if (type == wxEVT_COMMAND_TEXT_UPDATED) { 00083 00084 return new CRTextUpdateEvent (event.Clone ()); 00085 00086 } else if (type == wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED) { 00087 00088 // Clone() method not implemented: 00089 //return new CRNotebookPageChangeEvent (new wxNoteevent.Clone ()); 00090 //wxNotebookEvent *orig = wxDynamicCast (event, wxNotebookEvent); 00091 wxNotebookEvent &orig = (wxNotebookEvent &)(event); 00092 wxNotebookEvent *clone = new wxNotebookEvent (orig.GetEventType (), 00093 orig.GetId (), orig.GetSelection (), orig.GetOldSelection ()); 00094 clone->SetEventObject (orig.GetEventObject ()); 00095 return new CRNotebookPageChangeEvent (clone); 00096 00097 } else if (type == wxEVT_COMMAND_CHOICE_SELECTED) { 00098 00099 return new CRChoiceSelectionEvent (event.Clone ()); 00100 00101 } else if (type == wxEVT_COMMAND_RADIOBOX_SELECTED) { 00102 00103 return new CRRadioBoxSelectionEvent (event.Clone ()); 00104 00105 } else if (type == wxEVT_COMMAND_CHECKBOX_CLICKED) { 00106 00107 return new CRCheckBoxClickEvent (event.Clone ()); 00108 00109 } else if (type == wxEVT_COMMAND_SLIDER_UPDATED) { 00110 00111 return new CRSliderUpdateEvent (event.Clone ()); 00112 00113 } else if (type == wxEVT_COMMAND_SPINCTRL_UPDATED) { 00114 00115 return new CRSpinCtrlUpdateEvent (event.Clone ()); 00116 00117 } else if (type == wxEVT_COMMAND_TREE_SEL_CHANGING) { 00118 00119 // Clone() method not implemented: 00120 //return return new CRTreeSelectionChangingEvent (event.Clone ()); 00121 //wxTreeEvent *orig = wxDynamicCast (event, wxTreeEvent); 00122 wxTreeEvent &orig = (wxTreeEvent &)(event); 00123 // It seems that right clicking on an unselected tree item first 00124 // creates a changing event without setting the affected tree item: 00125 if (orig.GetItem ().IsOk ()) { 00126 00127 wxTreeEvent *clone = new wxTreeEvent (orig.GetEventType (), 00128 orig.GetId ()); 00129 clone->SetItem (orig.GetItem ()); 00130 clone->SetPoint (orig.GetPoint ()); 00131 clone->SetLabel (orig.GetLabel ()); 00132 clone->SetEventObject (orig.GetEventObject ()); 00133 return new CRTreeSelectionChangingEvent (clone); 00134 } 00135 00136 } else if (type == wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK) { 00137 00138 // Clone() method not implemented: 00139 //return return new CRTreeItemRightClickEvent (event.Clone ()); 00140 //wxTreeEvent *orig = wxDynamicCast (event, wxTreeEvent); 00141 wxTreeEvent &orig = (wxTreeEvent &)(event); 00142 // It seems that right clicking on an unselected tree item first 00143 // creates a changing event without setting the affected tree item: 00144 if (orig.GetItem ().IsOk ()) { 00145 00146 wxTreeEvent *clone = new wxTreeEvent (orig.GetEventType (), 00147 orig.GetId ()); 00148 clone->SetItem (orig.GetItem ()); 00149 clone->SetPoint (orig.GetPoint ()); 00150 clone->SetLabel (orig.GetLabel ()); 00151 clone->SetEventObject (orig.GetEventObject ()); 00152 return new CRTreeItemRightClickEvent (clone); 00153 } 00154 } 00155 00156 return NULL; 00157 } 00158 00159 } // End namespace wxTst 00160