Revision: 7382
          http://mahogany.svn.sourceforge.net/mahogany/?rev=7382&view=rev
Author:   vadz
Date:     2007-10-20 16:57:15 -0700 (Sat, 20 Oct 2007)

Log Message:
-----------
added a browse button to the command in the MIME "Open with..." dialog

Modified Paths:
--------------
    trunk/M/include/gui/wxBrowseButton.h
    trunk/M/src/gui/wxBrowseButton.cpp
    trunk/M/src/gui/wxDialogLayout.cpp
    trunk/M/src/gui/wxMimeDialog.cpp

Modified: trunk/M/include/gui/wxBrowseButton.h
===================================================================
--- trunk/M/include/gui/wxBrowseButton.h        2007-10-06 16:37:15 UTC (rev 
7381)
+++ trunk/M/include/gui/wxBrowseButton.h        2007-10-20 23:57:15 UTC (rev 
7382)
@@ -19,6 +19,10 @@
 #   include <wx/textctrl.h>
 #endif // USE_PCH
 
+#if wxCHECK_VERSION(2, 9, 0)
+   #define wxHAS_TEXT_ENTRY
+#endif
+
 // forward declaration
 class MFolder;
 class WXDLLEXPORT wxStaticBitmap;
@@ -80,15 +84,37 @@
    wxTextBrowseButton(wxTextCtrl *text,
                       wxWindow *parent,
                       const wxString& tooltip)
-      : wxBrowseButton(parent, tooltip) { m_text = text; }
+      : wxBrowseButton(parent, tooltip)
+   {
+      m_text = text;
+#ifdef wxHAS_TEXT_ENTRY
+      m_textWin = text;
+#endif // wxHAS_TEXT_ENTRY
+   }
 
+#ifdef wxHAS_TEXT_ENTRY
+   wxTextBrowseButton(wxComboBox *text,
+                      wxWindow *parent,
+                      const wxString& tooltip)
+      : wxBrowseButton(parent, tooltip)
+   {
+      m_text = text;
+      m_textWin = text;
+   }
+#endif // wxHAS_TEXT_ENTRY
+
    // enable/disable associated text control with us
    virtual bool Enable(bool enable)
    {
       if ( !wxButton::Enable(enable) )
-         return FALSE;
+         return false;
 
+#ifdef wxHAS_TEXT_ENTRY
+      m_textWin->Enable(enable);
+#else // !wxHAS_TEXT_ENTRY
       m_text->Enable(enable);
+#endif // wxHAS_TEXT_ENTRY/!wxHAS_TEXT_ENTRY
+
       return wxButton::Enable(enable);
    }
 
@@ -96,11 +122,23 @@
    wxString GetText() const { return m_text->GetValue(); }
    void SetText(const wxString& text) { m_text->SetValue(text); }
 
-   // text control we're associated with
-   wxTextCtrl *GetTextCtrl() const { return m_text; }
+   // get the associated control
+   wxWindow *GetWindow() const
+   {
+#ifdef wxHAS_TEXT_ENTRY
+      return m_textWin;
+#else // !wxHAS_TEXT_ENTRY
+      return m_text;
+#endif // wxHAS_TEXT_ENTRY/!wxHAS_TEXT_ENTRY
+   }
 
 private:
+#ifdef wxHAS_TEXT_ENTRY
+   wxTextEntry *m_text;
+   wxWindow *m_textWin;
+#else // !wxHAS_TEXT_ENTRY
    wxTextCtrl *m_text;
+#endif // wxHAS_TEXT_ENTRY/!wxHAS_TEXT_ENTRY
 
    DECLARE_NO_COPY_CLASS(wxTextBrowseButton)
 };
@@ -123,13 +161,23 @@
    // existing one - this is achieved by setting existingOnly param to FALSE
    // (only for "open" buttons, it doesn't make sense for "save" ones)
    wxFileBrowseButton(wxTextCtrl *text, wxWindow *parent,
-                      bool open = TRUE, bool existingOnly = TRUE)
+                      bool open = true, bool existingOnly = true)
       : wxTextBrowseButton(text, parent, _("Browse for the file"))
    {
       m_open = open;
       m_existingOnly = existingOnly;
    }
 
+#ifdef wxHAS_TEXT_ENTRY
+   wxFileBrowseButton(wxComboBox *combo, wxWindow *parent,
+                      bool open = true, bool existingOnly = true)
+      : wxTextBrowseButton(combo, parent, _("Browse for the file"))
+   {
+      m_open = open;
+      m_existingOnly = existingOnly;
+   }
+#endif // wxHAS_TEXT_ENTRY
+
    // show the file selection dialog and fill the associated text control with
    // the name of the selected file
    virtual void DoBrowse();
@@ -250,7 +298,7 @@
    // get/set the text value: must use these functions instead of wxTextCtrl
    // methods to update the button colour as well!
    void SetValue(const wxString& text);
-   wxString GetValue() const { return GetTextCtrl()->GetValue(); }
+   wxString GetValue() const { return GetText(); }
 
 private:
    // update the button colour on screen to match m_color

Modified: trunk/M/src/gui/wxBrowseButton.cpp
===================================================================
--- trunk/M/src/gui/wxBrowseButton.cpp  2007-10-06 16:37:15 UTC (rev 7381)
+++ trunk/M/src/gui/wxBrowseButton.cpp  2007-10-20 23:57:15 UTC (rev 7382)
@@ -268,7 +268,7 @@
    m_hasText = TRUE;
 
    m_evtHandlerText = new wxColorTextEvtHandler(this);
-   GetTextCtrl()->PushEventHandler(m_evtHandlerText);
+   GetWindow()->PushEventHandler(m_evtHandlerText);
 }
 
 wxColorBrowseButton::~wxColorBrowseButton()
@@ -276,8 +276,8 @@
    // the order of control deletion is undetermined, so handle both cases
    if ( m_hasText )
    {
-      // we're deleted before the text control
-      GetTextCtrl()->PopEventHandler(TRUE /* delete it */);
+      // we're deleted before the associated control
+      GetWindow()->PopEventHandler(TRUE /* delete it */);
    }
    else
    {

Modified: trunk/M/src/gui/wxDialogLayout.cpp
===================================================================
--- trunk/M/src/gui/wxDialogLayout.cpp  2007-10-06 16:37:15 UTC (rev 7381)
+++ trunk/M/src/gui/wxDialogLayout.cpp  2007-10-20 23:57:15 UTC (rev 7382)
@@ -439,14 +439,11 @@
                                 btn, (wxTextBrowseButton **)ppButton);
 }
 
-void EnableTextWithLabel(wxWindow *parent, wxTextCtrl *control, bool bEnable)
+// this function enables or disables the window label, i.e. the static text
+// control which is supposed to precede it
+static
+void EnableWindowLabel(wxWindow *parent, wxWindow *control, bool bEnable)
 {
-   // not only enable/disable it, but also make (un)editable because it gives
-   // visual feedback
-   control->SetEditable(bEnable);
-
-   // disable the label too: this will grey it out
-
    // NB: we assume that the control ids are consecutive
    long id = wxWindow::PrevControlId(control->GetId());
    wxWindow *win = parent->FindWindow(id);
@@ -462,6 +459,15 @@
    }
 }
 
+void EnableTextWithLabel(wxWindow *parent, wxTextCtrl *control, bool bEnable)
+{
+   // not only enable/disable it, but also make (un)editable because it gives
+   // visual feedback
+   control->SetEditable(bEnable);
+
+   EnableWindowLabel(parent, control, bEnable);
+}
+
 void EnableTextWithButton(wxWindow *parent, wxTextCtrl *control, bool bEnable)
 {
    // NB: we assume that the control ids are consecutive
@@ -1037,7 +1043,10 @@
 {
    btn->Enable(bEnable);
 
-   EnableTextWithLabel(btn->GetTextCtrl(), bEnable);
+   wxWindow * const win = btn->GetWindow();
+   win->Enable(bEnable);
+
+   EnableWindowLabel(GetCanvas(), win, bEnable);
 }
 
 // enable/disable the text control with label and button

Modified: trunk/M/src/gui/wxMimeDialog.cpp
===================================================================
--- trunk/M/src/gui/wxMimeDialog.cpp    2007-10-06 16:37:15 UTC (rev 7381)
+++ trunk/M/src/gui/wxMimeDialog.cpp    2007-10-20 23:57:15 UTC (rev 7382)
@@ -33,6 +33,8 @@
 #endif // USE_PCH
 
 #include "gui/wxDialogLayout.h"
+#include "gui/wxBrowseButton.h"
+
 #include "MimeDialog.h"
 
 // ----------------------------------------------------------------------------
@@ -142,11 +144,28 @@
                         this,
                         wxID_ANY
                       );
+
    c = new wxLayoutConstraints;
+
+#if wxCHECK_VERSION(2, 9, 0)
+   // in wx 2.8 wxTextEntry doesn't exist and hence wxPTextEntry doesn't derive
+   // from it and this wouldn't compile
+   wxFileBrowseButton *btnBrowse = new wxFileBrowseButton(m_txtCommand, this);
+
    c->centreY.SameAs(m_labelCommand, wxCentreY);
-   c->left.RightOf(m_labelCommand, LAYOUT_X_MARGIN);
    c->right.SameAs(this, wxRight, 2*LAYOUT_X_MARGIN);
+   c->width.Absolute(4*GetCharWidth());
    c->height.AsIs();
+   btnBrowse->SetConstraints(c);
+
+   c = new wxLayoutConstraints;
+   c->right.SameAs(btnBrowse, wxLeft, LAYOUT_X_MARGIN);
+#else // wx < 2.9
+   c->right.SameAs(this, wxRight, 2*LAYOUT_X_MARGIN);
+#endif // wx 2.9/2.8
+   c->centreY.SameAs(m_labelCommand, wxCentreY);
+   c->left.RightOf(m_labelCommand, LAYOUT_X_MARGIN);
+   c->height.AsIs();
    m_txtCommand->SetConstraints(c);
 
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Mahogany-cvsupdates mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to