wxGenericDirCtrl page for widgets sample.
authorWłodzimierz Skiba <abx@abx.art.pl>
Thu, 5 Oct 2006 10:20:32 +0000 (10:20 +0000)
committerWłodzimierz Skiba <abx@abx.art.pl>
Thu, 5 Oct 2006 10:20:32 +0000 (10:20 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41634 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/widgets/Makefile.in
samples/widgets/dirctrl.cpp [new file with mode: 0644]
samples/widgets/icons/dirctrl.xpm [new file with mode: 0644]
samples/widgets/makefile.bcc
samples/widgets/makefile.gcc
samples/widgets/makefile.vc
samples/widgets/makefile.wat
samples/widgets/widgets.bkl
samples/widgets/widgets.dsp

index e7c8b8529331d1bdd7ea0d06feb03be82b63a2ea..bab8792a0cd11c083c000c7bf1902f3b73b816fe 100644 (file)
@@ -54,6 +54,7 @@ WIDGETS_OBJECTS =  \
        widgets_clrpicker.o \
        widgets_combobox.o \
        widgets_datepick.o \
+       widgets_dirctrl.o \
        widgets_dirpicker.o \
        widgets_filepicker.o \
        widgets_fontpicker.o \
@@ -229,6 +230,9 @@ widgets_combobox.o: $(srcdir)/combobox.cpp
 widgets_datepick.o: $(srcdir)/datepick.cpp
        $(CXXC) -c -o $@ $(WIDGETS_CXXFLAGS) $(srcdir)/datepick.cpp
 
+widgets_dirctrl.o: $(srcdir)/dirctrl.cpp
+       $(CXXC) -c -o $@ $(WIDGETS_CXXFLAGS) $(srcdir)/dirctrl.cpp
+
 widgets_dirpicker.o: $(srcdir)/dirpicker.cpp
        $(CXXC) -c -o $@ $(WIDGETS_CXXFLAGS) $(srcdir)/dirpicker.cpp
 
diff --git a/samples/widgets/dirctrl.cpp b/samples/widgets/dirctrl.cpp
new file mode 100644 (file)
index 0000000..6995b79
--- /dev/null
@@ -0,0 +1,337 @@
+/////////////////////////////////////////////////////////////////////////////
+// Program:     wxWidgets Widgets Sample
+// Name:        dirctrl.cpp
+// Purpose:     Part of the widgets sample showing wxGenericDirCtrl
+// Author:      Wlodzimierz 'ABX' Skiba
+// Created:     4 Oct 2006
+// Id:          $Id$
+// Copyright:   (c) 2006 wxWindows team
+// License:     wxWindows license
+/////////////////////////////////////////////////////////////////////////////
+
+// ============================================================================
+// declarations
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+// for compilers that support precompilation, includes "wx/wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+    #pragma hdrstop
+#endif
+
+#if wxUSE_DIRDLG
+
+// for all others, include the necessary headers
+#ifndef WX_PRECOMP
+    #include "wx/sizer.h"
+    #include "wx/statbox.h"
+    #include "wx/radiobox.h"
+    #include "wx/checkbox.h"
+    #include "wx/button.h"
+    #include "wx/app.h"
+#endif
+
+#include "wx/generic/dirctrlg.h"
+
+#include "wx/wupdlock.h"
+#include "wx/stdpaths.h"
+#include "wx/msgdlg.h"
+
+#include "widgets.h"
+
+#include "icons/dirctrl.xpm"
+
+// ----------------------------------------------------------------------------
+// constants
+// ----------------------------------------------------------------------------
+
+// control ids
+enum
+{
+    DirCtrlPage_Reset = wxID_HIGHEST,
+    DirCtrlPage_SetPath,
+    DirCtrlPage_Ctrl
+};
+
+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")
+};
+
+enum
+{
+    stdPathUnknown = 0,
+    stdPathConfig,
+    stdPathData,
+    stdPathDocuments,
+    stdPathLocalData,
+    stdPathPlugins,
+    stdPathResources,
+    stdPathUserConfig,
+    stdPathUserData,
+    stdPathUserLocalData,
+    stdPathMax
+};
+
+// ----------------------------------------------------------------------------
+// CheckBoxWidgetsPage
+// ----------------------------------------------------------------------------
+
+class DirCtrlWidgetsPage : public WidgetsPage
+{
+public:
+    DirCtrlWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist);
+    virtual ~DirCtrlWidgetsPage() {}
+
+    virtual wxControl *GetWidget() const { return m_dirCtrl; }
+    virtual void RecreateWidget() { CreateDirCtrl(); }
+
+    // lazy creation of the content
+    virtual void CreateContent();
+
+protected:
+    // event handlers
+    void OnButtonSetPath(wxCommandEvent& event);
+    void OnButtonReset(wxCommandEvent& event);
+    void OnStdPath(wxCommandEvent& event);
+    void OnCheckBox(wxCommandEvent& event);
+    void OnRadioBox(wxCommandEvent& event);
+
+    // reset the control parameters
+    void Reset();
+
+    // (re)create the m_dirCtrl
+    void CreateDirCtrl();
+
+    // the controls
+    // ------------
+
+    // the control itself and the sizer it is in
+    wxGenericDirCtrl *m_dirCtrl;
+
+    // the text entries for command parameters
+    wxTextCtrl *m_path;
+
+    wxRadioBox *m_radioStdPath;
+
+    // flags
+    wxCheckBox *m_chkDirOnly,
+               *m_chk3D,
+               *m_chkFirst,
+               *m_chkFilters,
+               *m_chkLabels;
+
+private:
+    DECLARE_EVENT_TABLE()
+    DECLARE_WIDGETS_PAGE(DirCtrlWidgetsPage)
+};
+
+// ----------------------------------------------------------------------------
+// event tables
+// ----------------------------------------------------------------------------
+
+BEGIN_EVENT_TABLE(DirCtrlWidgetsPage, WidgetsPage)
+    EVT_BUTTON(DirCtrlPage_Reset, DirCtrlWidgetsPage::OnButtonReset)
+    EVT_BUTTON(DirCtrlPage_SetPath, DirCtrlWidgetsPage::OnButtonSetPath)
+    EVT_CHECKBOX(wxID_ANY, DirCtrlWidgetsPage::OnCheckBox)
+    EVT_RADIOBOX(wxID_ANY, DirCtrlWidgetsPage::OnRadioBox)
+END_EVENT_TABLE()
+
+// ============================================================================
+// implementation
+// ============================================================================
+
+IMPLEMENT_WIDGETS_PAGE(DirCtrlWidgetsPage, wxT("DirCtrl"),
+                       GENERIC_CTRLS
+                       );
+
+DirCtrlWidgetsPage::DirCtrlWidgetsPage(WidgetsBookCtrl *book,
+                                       wxImageList *imaglist)
+                   :WidgetsPage(book, imaglist, dirctrl_xpm)
+{
+}
+
+void DirCtrlWidgetsPage::CreateContent()
+{
+    wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
+
+    // left pane
+    wxStaticBox *box = new wxStaticBox(this, wxID_ANY, wxT("Dir control details"));
+
+    wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
+
+    sizerLeft->Add( CreateSizerWithTextAndButton( DirCtrlPage_SetPath , wxT("Set &path"), wxID_ANY, &m_path ),
+                    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_chkFilters = CreateCheckBoxAndAddToSizer(sizerUseFlags, _T("wxDIRCTRL_SHOW_FILTERS"));
+    m_chkLabels  = CreateCheckBoxAndAddToSizer(sizerUseFlags, _T("wxDIRCTRL_EDIT_LABELS"));
+    sizerLeft->Add(sizerUseFlags, wxSizerFlags().Expand().Border());
+
+    wxButton *btn = new wxButton(this, DirCtrlPage_Reset, _T("&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
+    m_radioStdPath = new wxRadioBox(this, wxID_ANY, _T("Standard path"),
+                                    wxDefaultPosition, wxDefaultSize,
+                                    WXSIZEOF(stdPaths), stdPaths, 1);
+
+    // right pane
+    m_dirCtrl = new wxGenericDirCtrl(
+        this,
+        DirCtrlPage_Ctrl,
+        wxDirDialogDefaultFolderStr,
+        wxDefaultPosition,
+        wxDefaultSize,
+        0
+    );
+
+    // the 3 panes panes compose the window
+    sizerTop->Add(sizerLeft, 0, (wxALL & ~wxLEFT), 10);
+    sizerTop->Add(m_radioStdPath, 0, wxGROW | wxALL , 10);
+    sizerTop->Add(m_dirCtrl, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
+
+    // final initializations
+    Reset();
+
+    SetSizer(sizerTop);
+
+    sizerTop->Fit(this);
+}
+
+void DirCtrlWidgetsPage::Reset()
+{
+    m_path->SetValue(m_dirCtrl->GetPath());
+}
+
+void DirCtrlWidgetsPage::CreateDirCtrl()
+{
+    wxWindowUpdateLocker noUpdates(this);
+
+    wxGenericDirCtrl *dirCtrl = new wxGenericDirCtrl(
+        this,
+        DirCtrlPage_Ctrl,
+        wxDirDialogDefaultFolderStr,
+        wxDefaultPosition,
+        wxDefaultSize,
+        ( m_chkDirOnly->IsChecked() ? wxDIRCTRL_DIR_ONLY : 0 ) |
+        ( m_chk3D->IsChecked() ? wxDIRCTRL_3D_INTERNAL : 0 ) |
+        ( m_chkFirst->IsChecked() ? wxDIRCTRL_SELECT_FIRST : 0 ) |
+        ( m_chkFilters->IsChecked() ? wxDIRCTRL_SHOW_FILTERS : 0 ) |
+        ( m_chkLabels->IsChecked() ? wxDIRCTRL_EDIT_LABELS : 0 )
+    );
+
+    // update sizer's child window
+    GetSizer()->Replace(m_dirCtrl, dirCtrl, true);
+
+    // update our pointer
+    delete m_dirCtrl;
+    m_dirCtrl = dirCtrl;
+
+    // relayout the sizer
+    GetSizer()->Layout();
+}
+
+// ----------------------------------------------------------------------------
+// event handlers
+// ----------------------------------------------------------------------------
+
+void DirCtrlWidgetsPage::OnButtonSetPath(wxCommandEvent& WXUNUSED(event))
+{
+    m_dirCtrl->SetPath(m_path->GetValue());
+}
+
+void DirCtrlWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
+{
+    Reset();
+
+    CreateDirCtrl();
+}
+
+void DirCtrlWidgetsPage::OnCheckBox(wxCommandEvent& WXUNUSED(event))
+{
+    CreateDirCtrl();
+}
+
+void DirCtrlWidgetsPage::OnRadioBox(wxCommandEvent& WXUNUSED(event))
+{
+    wxString path;
+
+    wxTheApp->SetAppName(_T("widgets"));
+    wxStandardPathsBase& stdp = wxStandardPaths::Get();
+
+    switch ( m_radioStdPath->GetSelection() )
+    {
+        default:
+        case stdPathUnknown:
+        case stdPathMax:
+            // leave path
+            break;
+
+        case stdPathConfig:
+            path = stdp.GetConfigDir();
+            break;
+
+        case stdPathData:
+            path = stdp.GetDataDir();
+            break;
+
+        case stdPathDocuments:
+            path = stdp.GetDocumentsDir();
+            break;
+
+        case stdPathLocalData:
+            path = stdp.GetLocalDataDir();
+            break;
+
+        case stdPathPlugins:
+            path = stdp.GetPluginsDir();
+            break;
+
+        case stdPathResources:
+            path = stdp.GetResourcesDir();
+            break;
+
+        case stdPathUserConfig:
+            path = stdp.GetUserConfigDir();
+            break;
+
+        case stdPathUserData:
+            path = stdp.GetUserDataDir();
+            break;
+
+        case stdPathUserLocalData:
+            path = stdp.GetUserLocalDataDir();
+            break;
+    }
+
+    m_dirCtrl->SetPath(path);
+    if(!m_dirCtrl->GetPath().IsSameAs(path))
+    {
+        wxLogMessage(_T("Selected standard path and path from control do not match!"));
+        m_radioStdPath->SetSelection(stdPathUnknown);
+    }
+}
+
+#endif // wxUSE_DIRDLG
diff --git a/samples/widgets/icons/dirctrl.xpm b/samples/widgets/icons/dirctrl.xpm
new file mode 100644 (file)
index 0000000..e362dfe
--- /dev/null
@@ -0,0 +1,54 @@
+/* XPM */
+static char *dirctrl_xpm[] = {
+/* columns rows colors chars-per-pixel */
+"32 32 16 1",
+"  c Gray0",
+". c #808000",
+"X c #000080",
+"o c #808080",
+"O c #000000",
+"+ c #808000",
+"@ c #000080",
+"# c none",
+"$ c #808080",
+"% c Red",
+"& c Green",
+"* c Yellow",
+"= c Blue",
+"- c Magenta",
+"; c Cyan",
+": c Gray100",
+/* pixels */
+"################################",
+"################################",
+"#                              #",
+"# :::::::::::::::::::::::::::: #",
+"# :$:::::::::::::::::::::::::: #",
+"# :$::::::  ::: :::::::::::::: #",
+"# :$::::: :: :: :::::::::::::: #",
+"# :$$$$:: :::::::::::::::::::: #",
+"# :$::::: :: :: :::::::::::::: #",
+"# :$::::::  ::: :::::::::::::: #",
+"# :$:::::::::::::::::::::::::: #",
+"# :$:::::::::::::::::::::::::: #",
+"# :$:::::::::::::::::::::::::: #",
+"# :$::::::: : :: :::   ::   :: #",
+"# :$:::::: :: :: :: ::::: :: : #",
+"# :$$$$:: ::: :: :::  :::   :: #",
+"# :$:::: :::: :: ::::: :: :: : #",
+"# :$::: ::::::  :::   ::: :: : #",
+"# :$:::::::::::::::::::::::::: #",
+"# :$:::::::::::::::::::::::::: #",
+"# :$:::::::::::::::::::::::::: #",
+"# :$::::: :: ::   :: : ::: ::: #",
+"# :$::::: :: :: :: : :  :: ::: #",
+"# :$$$$::::::::   :: : : : ::: #",
+"# :$::::: :: :: :: : : ::  ::: #",
+"# :$::::: :: ::   :: : ::: ::: #",
+"# :$:::::::::::::::::::::::::: #",
+"# :$:::::::::::::::::::::::::: #",
+"# :::::::::::::::::::::::::::: #",
+"#                              #",
+"################################",
+"################################"
+};
index e067977bc01e8f691aa79743b0bc7817a4989e7e..5398e735ef3cf08c9e7569dfc0c9af14d5087277 100644 (file)
@@ -40,6 +40,7 @@ WIDGETS_OBJECTS =  \
        $(OBJS)\widgets_clrpicker.obj \
        $(OBJS)\widgets_combobox.obj \
        $(OBJS)\widgets_datepick.obj \
+       $(OBJS)\widgets_dirctrl.obj \
        $(OBJS)\widgets_dirpicker.obj \
        $(OBJS)\widgets_filepicker.obj \
        $(OBJS)\widgets_fontpicker.obj \
@@ -267,6 +268,9 @@ $(OBJS)\widgets_combobox.obj: .\combobox.cpp
 $(OBJS)\widgets_datepick.obj: .\datepick.cpp
        $(CXX) -q -c -P -o$@ $(WIDGETS_CXXFLAGS) $**
 
+$(OBJS)\widgets_dirctrl.obj: .\dirctrl.cpp
+       $(CXX) -q -c -P -o$@ $(WIDGETS_CXXFLAGS) $**
+
 $(OBJS)\widgets_dirpicker.obj: .\dirpicker.cpp
        $(CXX) -q -c -P -o$@ $(WIDGETS_CXXFLAGS) $**
 
index 85f04769480c3a537ba800edeed3b287012e92f3..00a0b01b6ccb503d742ea4d19543d41154f2f124 100644 (file)
@@ -33,6 +33,7 @@ WIDGETS_OBJECTS =  \
        $(OBJS)\widgets_clrpicker.o \
        $(OBJS)\widgets_combobox.o \
        $(OBJS)\widgets_datepick.o \
+       $(OBJS)\widgets_dirctrl.o \
        $(OBJS)\widgets_dirpicker.o \
        $(OBJS)\widgets_filepicker.o \
        $(OBJS)\widgets_fontpicker.o \
@@ -260,6 +261,9 @@ $(OBJS)\widgets_combobox.o: ./combobox.cpp
 $(OBJS)\widgets_datepick.o: ./datepick.cpp
        $(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $<
 
+$(OBJS)\widgets_dirctrl.o: ./dirctrl.cpp
+       $(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $<
+
 $(OBJS)\widgets_dirpicker.o: ./dirpicker.cpp
        $(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $<
 
index fd41093135849d33b71eb227236767e8497f878c..78e9bb2ca407ab622adca991c7a40e41455815b5 100644 (file)
@@ -33,6 +33,7 @@ WIDGETS_OBJECTS =  \
        $(OBJS)\widgets_clrpicker.obj \
        $(OBJS)\widgets_combobox.obj \
        $(OBJS)\widgets_datepick.obj \
+       $(OBJS)\widgets_dirctrl.obj \
        $(OBJS)\widgets_dirpicker.obj \
        $(OBJS)\widgets_filepicker.obj \
        $(OBJS)\widgets_fontpicker.obj \
@@ -342,6 +343,9 @@ $(OBJS)\widgets_combobox.obj: .\combobox.cpp
 $(OBJS)\widgets_datepick.obj: .\datepick.cpp
        $(CXX) /c /nologo /TP /Fo$@ $(WIDGETS_CXXFLAGS) $**
 
+$(OBJS)\widgets_dirctrl.obj: .\dirctrl.cpp
+       $(CXX) /c /nologo /TP /Fo$@ $(WIDGETS_CXXFLAGS) $**
+
 $(OBJS)\widgets_dirpicker.obj: .\dirpicker.cpp
        $(CXX) /c /nologo /TP /Fo$@ $(WIDGETS_CXXFLAGS) $**
 
index 6f52b20ba2d744a193fa12250281966be78dc8af..ffcc50583b5bf6076bf09cc55c14cdfc9bf87454 100644 (file)
@@ -235,6 +235,7 @@ WIDGETS_OBJECTS =  &
        $(OBJS)\widgets_clrpicker.obj &
        $(OBJS)\widgets_combobox.obj &
        $(OBJS)\widgets_datepick.obj &
+       $(OBJS)\widgets_dirctrl.obj &
        $(OBJS)\widgets_dirpicker.obj &
        $(OBJS)\widgets_filepicker.obj &
        $(OBJS)\widgets_fontpicker.obj &
@@ -298,6 +299,9 @@ $(OBJS)\widgets_combobox.obj :  .AUTODEPEND .\combobox.cpp
 $(OBJS)\widgets_datepick.obj :  .AUTODEPEND .\datepick.cpp
        $(CXX) -bt=nt -zq -fo=$^@ $(WIDGETS_CXXFLAGS) $<
 
+$(OBJS)\widgets_dirctrl.obj :  .AUTODEPEND .\dirctrl.cpp
+       $(CXX) -bt=nt -zq -fo=$^@ $(WIDGETS_CXXFLAGS) $<
+
 $(OBJS)\widgets_dirpicker.obj :  .AUTODEPEND .\dirpicker.cpp
        $(CXX) -bt=nt -zq -fo=$^@ $(WIDGETS_CXXFLAGS) $<
 
index 11fa94529403ed2ddaa523e9670c280c1f21fa7f..1633e9d5b29da259d9d78d5aa4c0a5955fc523db 100644 (file)
@@ -12,6 +12,7 @@
             clrpicker.cpp
             combobox.cpp
             datepick.cpp
+            dirctrl.cpp
             dirpicker.cpp
             filepicker.cpp
             fontpicker.cpp
index 9d39f95c8a88d9490374e8ea176cad52ed78ccee..e8d22fb43ca8b6a02c089d3b69bda9a1ee0d96c4 100644 (file)
@@ -492,6 +492,10 @@ SOURCE=.\datepick.cpp
 # End Source File
 # Begin Source File
 
+SOURCE=.\dirctrl.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\dirpicker.cpp
 # End Source File
 # Begin Source File