]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/widgets/dirctrl.cpp
Make wxSpinCtrlGenericBase a wxCompositeWindow.
[wxWidgets.git] / samples / widgets / dirctrl.cpp
index 1d8ad59cbd38ede41763d2df59e248ad69544dec..6a55991d552bc040cb4fdc11099618aff40dda0d 100644 (file)
@@ -6,7 +6,7 @@
 // Created:     4 Oct 2006
 // Id:          $Id$
 // Copyright:   (c) 2006 wxWindows team
 // Created:     4 Oct 2006
 // Id:          $Id$
 // Copyright:   (c) 2006 wxWindows team
-// License:     wxWindows license
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // ============================================================================
 /////////////////////////////////////////////////////////////////////////////
 
 // ============================================================================
@@ -42,6 +42,7 @@
 
 #include "wx/wupdlock.h"
 #include "wx/stdpaths.h"
 
 #include "wx/wupdlock.h"
 #include "wx/stdpaths.h"
+#include "wx/filename.h"
 
 #include "widgets.h"
 
 
 #include "widgets.h"
 
@@ -61,16 +62,16 @@ enum
 
 static const wxString stdPaths[] =
 {
 
 static const wxString stdPaths[] =
 {
-    _T("&none"),
-    _T("&config"),
-    _T("&data"),
-    _T("&documents"),
-    _T("&local data"),
-    _T("&plugins"),
-    _T("&resources"),
-    _T("&user config"),
-    _T("&user data"),
-    _T("&user local data")
+    wxT("&none"),
+    wxT("&config"),
+    wxT("&data"),
+    wxT("&documents"),
+    wxT("&local data"),
+    wxT("&plugins"),
+    wxT("&resources"),
+    wxT("&user config"),
+    wxT("&user data"),
+    wxT("&user local data")
 };
 
 enum
 };
 
 enum
@@ -111,6 +112,7 @@ protected:
     void OnStdPath(wxCommandEvent& event);
     void OnCheckBox(wxCommandEvent& event);
     void OnRadioBox(wxCommandEvent& event);
     void OnStdPath(wxCommandEvent& event);
     void OnCheckBox(wxCommandEvent& event);
     void OnRadioBox(wxCommandEvent& event);
+    void OnSelChanged(wxTreeEvent& event);
 
     // reset the control parameters
     void Reset();
 
     // reset the control parameters
     void Reset();
@@ -153,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_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()
 
 // ============================================================================
 END_EVENT_TABLE()
 
 // ============================================================================
@@ -167,6 +170,7 @@ DirCtrlWidgetsPage::DirCtrlWidgetsPage(WidgetsBookCtrl *book,
                                        wxImageList *imaglist)
                    :WidgetsPage(book, imaglist, dirctrl_xpm)
 {
                                        wxImageList *imaglist)
                    :WidgetsPage(book, imaglist, dirctrl_xpm)
 {
+    m_dirCtrl = NULL;
 }
 
 void DirCtrlWidgetsPage::CreateContent()
 }
 
 void DirCtrlWidgetsPage::CreateContent()
@@ -182,30 +186,30 @@ void DirCtrlWidgetsPage::CreateContent()
                     0, wxALL | wxALIGN_RIGHT , 5 );
 
     wxSizer *sizerUseFlags =
                     0, wxALL | wxALIGN_RIGHT , 5 );
 
     wxSizer *sizerUseFlags =
-        new wxStaticBoxSizer(wxVERTICAL, this, _T("&Flags"));
-    m_chkDirOnly = CreateCheckBoxAndAddToSizer(sizerUseFlags, _T("wxDIRCTRL_DIR_ONLY"));
-    m_chk3D      = CreateCheckBoxAndAddToSizer(sizerUseFlags, _T("wxDIRCTRL_3D_INTERNAL"));
-    m_chkFirst   = CreateCheckBoxAndAddToSizer(sizerUseFlags, _T("wxDIRCTRL_SELECT_FIRST"));
-    m_chkLabels  = CreateCheckBoxAndAddToSizer(sizerUseFlags, _T("wxDIRCTRL_EDIT_LABELS"));
-    m_chkMulti   = CreateCheckBoxAndAddToSizer(sizerUseFlags, _T("wxDIRCTRL_MULTIPLE"));
+        new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Flags"));
+    m_chkDirOnly = CreateCheckBoxAndAddToSizer(sizerUseFlags, wxT("wxDIRCTRL_DIR_ONLY"));
+    m_chk3D      = CreateCheckBoxAndAddToSizer(sizerUseFlags, wxT("wxDIRCTRL_3D_INTERNAL"));
+    m_chkFirst   = CreateCheckBoxAndAddToSizer(sizerUseFlags, wxT("wxDIRCTRL_SELECT_FIRST"));
+    m_chkLabels  = CreateCheckBoxAndAddToSizer(sizerUseFlags, wxT("wxDIRCTRL_EDIT_LABELS"));
+    m_chkMulti   = CreateCheckBoxAndAddToSizer(sizerUseFlags, wxT("wxDIRCTRL_MULTIPLE"));
     sizerLeft->Add(sizerUseFlags, wxSizerFlags().Expand().Border());
 
     wxSizer *sizerFilters =
     sizerLeft->Add(sizerUseFlags, wxSizerFlags().Expand().Border());
 
     wxSizer *sizerFilters =
-        new wxStaticBoxSizer(wxVERTICAL, this, _T("&Filters"));
+        new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Filters"));
     m_fltr[0] = CreateCheckBoxAndAddToSizer(sizerFilters, wxString::Format(wxT("all files (%s)|%s"),
                             wxFileSelectorDefaultWildcardStr, wxFileSelectorDefaultWildcardStr));
     m_fltr[1] = CreateCheckBoxAndAddToSizer(sizerFilters, wxT("C++ files (*.cpp; *.h)|*.cpp;*.h"));
     m_fltr[2] = CreateCheckBoxAndAddToSizer(sizerFilters, wxT("PNG images (*.png)|*.png"));
     sizerLeft->Add(sizerFilters, wxSizerFlags().Expand().Border());
 
     m_fltr[0] = CreateCheckBoxAndAddToSizer(sizerFilters, wxString::Format(wxT("all files (%s)|%s"),
                             wxFileSelectorDefaultWildcardStr, wxFileSelectorDefaultWildcardStr));
     m_fltr[1] = CreateCheckBoxAndAddToSizer(sizerFilters, wxT("C++ files (*.cpp; *.h)|*.cpp;*.h"));
     m_fltr[2] = CreateCheckBoxAndAddToSizer(sizerFilters, wxT("PNG images (*.png)|*.png"));
     sizerLeft->Add(sizerFilters, wxSizerFlags().Expand().Border());
 
-    wxButton *btn = new wxButton(this, DirCtrlPage_Reset, _T("&Reset"));
+    wxButton *btn = new wxButton(this, DirCtrlPage_Reset, wxT("&Reset"));
     sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
 
     // keep consistency between enum and labels of radiobox
     wxCOMPILE_TIME_ASSERT( stdPathMax == WXSIZEOF(stdPaths), EnumForRadioBoxMismatch);
 
     // middle pane
     sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
 
     // keep consistency between enum and labels of radiobox
     wxCOMPILE_TIME_ASSERT( stdPathMax == WXSIZEOF(stdPaths), EnumForRadioBoxMismatch);
 
     // middle pane
-    m_radioStdPath = new wxRadioBox(this, wxID_ANY, _T("Standard path"),
+    m_radioStdPath = new wxRadioBox(this, wxID_ANY, wxT("Standard path"),
                                     wxDefaultPosition, wxDefaultSize,
                                     WXSIZEOF(stdPaths), stdPaths, 1);
 
                                     wxDefaultPosition, wxDefaultSize,
                                     WXSIZEOF(stdPaths), stdPaths, 1);
 
@@ -300,7 +304,7 @@ void DirCtrlWidgetsPage::OnRadioBox(wxCommandEvent& WXUNUSED(event))
 {
     wxString path;
 
 {
     wxString path;
 
-    wxTheApp->SetAppName(_T("widgets"));
+    wxTheApp->SetAppName(wxT("widgets"));
     wxStandardPathsBase& stdp = wxStandardPaths::Get();
 
     switch ( m_radioStdPath->GetSelection() )
     wxStandardPathsBase& stdp = wxStandardPaths::Get();
 
     switch ( m_radioStdPath->GetSelection() )
@@ -349,11 +353,25 @@ void DirCtrlWidgetsPage::OnRadioBox(wxCommandEvent& WXUNUSED(event))
     }
 
     m_dirCtrl->SetPath(path);
     }
 
     m_dirCtrl->SetPath(path);
-    if(!m_dirCtrl->GetPath().IsSameAs(path))
+
+    // Notice that we must use wxFileName comparison instead of simple wxString
+    // comparison as the paths returned may differ by case only.
+    if ( wxFileName(m_dirCtrl->GetPath()) != path )
     {
     {
-        wxLogMessage(_T("Selected standard path and path from control do not match!"));
-        m_radioStdPath->SetSelection(stdPathUnknown);
+        wxLogMessage("Failed to go to \"%s\", the current path is \"%s\".",
+                     path, m_dirCtrl->GetPath());
     }
 }
 
     }
 }
 
+void DirCtrlWidgetsPage::OnSelChanged(wxTreeEvent& event)
+{
+    if ( m_dirCtrl )
+    {
+        wxLogMessage("Selection changed to \"%s\"",
+                     m_dirCtrl->GetPath(event.GetItem()));
+    }
+
+    event.Skip();
+}
+
 #endif // wxUSE_DIRDLG
 #endif // wxUSE_DIRDLG