]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxEVT_COMMAND_DIRCTRL_CHANGED for wxDirCtrl selection changes.
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 1 Nov 2012 17:15:08 +0000 (17:15 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 1 Nov 2012 17:15:08 +0000 (17:15 +0000)
This makes it much simpler to react to the changes in the control, update the
sample to show it.

Closes #14792.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72842 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/generic/dirctrlg.h
interface/wx/dirctrl.h
samples/widgets/dirctrl.cpp
src/generic/dirctrlg.cpp

index 2eca88837231a71864581a13d55cee9f7fa5bf0d..0d329b68762801c569c536a81dd4101a896b0bd2 100644 (file)
@@ -581,6 +581,7 @@ All (GUI):
 - Close wxLogWindow automatically if it's the last remaining top level window.
 - Implement clipping for wxSVGFileDC (Steve Benbow).
 - Added wxDirCtrl::GetPath() (troelsk).
+- Added wxEVT_COMMAND_DIRCTRL_CHANGED event (troelsk).
 
 wxGTK:
 
index 450c8624d76192d84832474f069b807777052c60..af6ab5de586830f2d29b63fd095f093e68cd0ca5 100644 (file)
@@ -111,6 +111,7 @@ public:
     void OnCollapseItem(wxTreeEvent &event );
     void OnBeginEditItem(wxTreeEvent &event );
     void OnEndEditItem(wxTreeEvent &event );
+    void OnTreeSelChange(wxTreeEvent &event);
     void OnSize(wxSizeEvent &event );
 
     // Try to expand as much of the given path as possible.
@@ -210,6 +211,13 @@ private:
     wxDECLARE_NO_COPY_CLASS(wxGenericDirCtrl);
 };
 
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_COMMAND_DIRCTRL_CHANGED, wxTreeEvent );
+
+#define wx__DECLARE_DIRCTRL_EVT(evt, id, fn) \
+    wx__DECLARE_EVT1(wxEVT_COMMAND_DIRCTRL_ ## evt, id, wxTreeEventHandler(fn))
+
+#define EVT_DIRCTRL_CHANGED(id, fn) wx__DECLARE_DIRCTRL_EVT(CHANGED, id, fn)
+
 //-----------------------------------------------------------------------------
 // wxDirFilterListCtrl
 //-----------------------------------------------------------------------------
index 9fe8b21fff3d8f6d3896b967686eb4d53781dc78..34560ed1e3681b7dde762d664f31a656f57cc57f 100644 (file)
@@ -47,6 +47,12 @@ enum
     @library{wxcore}
     @category{ctrl}
     @appearance{genericdirctrl.png}
+    @event{EVT_DIRCTRL_CHANGED(id, func)}
+          Selected directory has changed.
+          Processes a @c wxEVT_COMMAND_DIRCTRL_CHANGED event type.
+          Notice that this event is generated even for the changes done by the
+          program itself and not only those done by the user.
+          @since 2.9.5
 */
 class wxGenericDirCtrl : public wxControl
 {
index 0698b926de071b9bdedf4287c76eef72dad052e8..6a55991d552bc040cb4fdc11099618aff40dda0d 100644 (file)
@@ -112,6 +112,7 @@ protected:
     void OnStdPath(wxCommandEvent& event);
     void OnCheckBox(wxCommandEvent& event);
     void OnRadioBox(wxCommandEvent& event);
+    void OnSelChanged(wxTreeEvent& event);
 
     // reset the control parameters
     void Reset();
@@ -154,6 +155,7 @@ BEGIN_EVENT_TABLE(DirCtrlWidgetsPage, WidgetsPage)
     EVT_BUTTON(DirCtrlPage_SetPath, DirCtrlWidgetsPage::OnButtonSetPath)
     EVT_CHECKBOX(wxID_ANY, DirCtrlWidgetsPage::OnCheckBox)
     EVT_RADIOBOX(wxID_ANY, DirCtrlWidgetsPage::OnRadioBox)
+    EVT_DIRCTRL_CHANGED(DirCtrlPage_Ctrl, DirCtrlWidgetsPage::OnSelChanged)
 END_EVENT_TABLE()
 
 // ============================================================================
@@ -168,6 +170,7 @@ DirCtrlWidgetsPage::DirCtrlWidgetsPage(WidgetsBookCtrl *book,
                                        wxImageList *imaglist)
                    :WidgetsPage(book, imaglist, dirctrl_xpm)
 {
+    m_dirCtrl = NULL;
 }
 
 void DirCtrlWidgetsPage::CreateContent()
@@ -360,4 +363,15 @@ void DirCtrlWidgetsPage::OnRadioBox(wxCommandEvent& WXUNUSED(event))
     }
 }
 
+void DirCtrlWidgetsPage::OnSelChanged(wxTreeEvent& event)
+{
+    if ( m_dirCtrl )
+    {
+        wxLogMessage("Selection changed to \"%s\"",
+                     m_dirCtrl->GetPath(event.GetItem()));
+    }
+
+    event.Skip();
+}
+
 #endif // wxUSE_DIRDLG
index 4b25f874a2a330526b373cd93510a401d049da0c..7eba8af2f918dc25ed1d72287d1121160bd45276 100644 (file)
@@ -102,6 +102,12 @@ extern WXDLLEXPORT_DATA(const char) wxFileSelectorDefaultWildcardStr[];
 
 bool wxIsDriveAvailable(const wxString& dirName);
 
+// ----------------------------------------------------------------------------
+// events
+// ----------------------------------------------------------------------------
+
+wxDEFINE_EVENT( wxEVT_COMMAND_DIRCTRL_CHANGED, wxTreeEvent );
+
 // ----------------------------------------------------------------------------
 // wxGetAvailableDrives, for WINDOWS, DOS, OS2, MAC, UNIX (returns "/")
 // ----------------------------------------------------------------------------
@@ -441,6 +447,7 @@ BEGIN_EVENT_TABLE(wxGenericDirCtrl, wxControl)
   EVT_TREE_ITEM_COLLAPSED     (wxID_TREECTRL, wxGenericDirCtrl::OnCollapseItem)
   EVT_TREE_BEGIN_LABEL_EDIT   (wxID_TREECTRL, wxGenericDirCtrl::OnBeginEditItem)
   EVT_TREE_END_LABEL_EDIT     (wxID_TREECTRL, wxGenericDirCtrl::OnEndEditItem)
+  EVT_TREE_SEL_CHANGED        (wxID_TREECTRL, wxGenericDirCtrl::OnTreeSelChange)
   EVT_SIZE                    (wxGenericDirCtrl::OnSize)
 END_EVENT_TABLE()
 
@@ -694,6 +701,17 @@ void wxGenericDirCtrl::OnEndEditItem(wxTreeEvent &event)
     }
 }
 
+void wxGenericDirCtrl::OnTreeSelChange(wxTreeEvent &event)
+{
+    wxTreeEvent changedEvent(wxEVT_COMMAND_DIRCTRL_CHANGED, GetId());
+
+    changedEvent.SetItem(event.GetItem());
+    changedEvent.SetClientObject(m_treeCtrl->GetItemData(event.GetItem()));
+
+    GetEventHandler()->SafelyProcessEvent(changedEvent);
+    event.Skip();
+}
+
 void wxGenericDirCtrl::OnExpandItem(wxTreeEvent &event)
 {
     wxTreeItemId parentId = event.GetItem();