]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/datectlg.cpp
Add support for wxSL_INVERSE flag. Also uses new inverse logic to make Mac vertical...
[wxWidgets.git] / src / generic / datectlg.cpp
index 27331850dd09c83bd3637de2c2a79484917a6eb8..19c8a65e1a93f92691361b15cf647da6b7080bc4 100644 (file)
 #endif
 
 #include "wx/dateevt.h"
+#include "wx/generic/datectrl.h"
 
 #include "wx/calctrl.h"
 #include "wx/popupwin.h"
+#include "wx/renderer.h"
 
 // ----------------------------------------------------------------------------
 // constants
@@ -76,7 +78,9 @@ BEGIN_EVENT_TABLE(wxDatePickerCtrlGeneric, wxDatePickerCtrlBase)
     EVT_CHILD_FOCUS(wxDatePickerCtrlGeneric::OnChildSetFocus)
 END_EVENT_TABLE()
 
-IMPLEMENT_DYNAMIC_CLASS(wxDatePickerCtrl, wxDatePickerCtrlBase)
+#ifndef wxHAS_NATIVE_DATEPICKCTRL
+    IMPLEMENT_DYNAMIC_CLASS(wxDatePickerCtrl, wxDatePickerCtrlBase)
+#endif
 
 // ----------------------------------------------------------------------------
 // creation
@@ -101,34 +105,38 @@ bool wxDatePickerCtrlGeneric::Create(wxWindow *parent,
         return false;
     }
 
-    SetWindowStyle(style | wxWANTS_CHARS);
     InheritAttributes();
 
-    wxBitmap bmp(8, 4);
-    {
-        wxMemoryDC dc;
-
-        dc.SelectObject(bmp);
-        dc.SetBrush(wxBrush(GetBackgroundColour()));
-        dc.SetPen(wxPen(GetBackgroundColour()));
-        dc.DrawRectangle(0,0, 8,4);
-
-        dc.SetBrush(wxBrush(GetForegroundColour()));
-        dc.SetPen(wxPen(GetForegroundColour()));
-        wxPoint pt[3] = { wxPoint(0,0), wxPoint(6,0), wxPoint(3,3) };
-        dc.DrawPolygon(3, pt);
-        dc.SelectObject(wxNullBitmap);
-    }
-
-    m_txt=new wxTextCtrl(this, CTRLID_TXT);
+    m_txt = new wxTextCtrl(this, CTRLID_TXT);
     m_txt->Connect(wxID_ANY, wxID_ANY, wxEVT_KEY_DOWN,
-                   (wxObjectEventFunction)&wxDatePickerCtrlGeneric::OnEditKey,
+                   (wxObjectEventFunction)
+                   (wxEventFunction)
+                   (wxCharEventFunction)
+                   &wxDatePickerCtrlGeneric::OnEditKey,
                    0, this);
     m_txt->Connect(wxID_ANY, wxID_ANY, wxEVT_KILL_FOCUS,
-                   (wxObjectEventFunction)&wxDatePickerCtrlGeneric::OnKillFocus,
+                   (wxObjectEventFunction)
+                   (wxEventFunction)
+                   (wxFocusEventFunction)
+                   &wxDatePickerCtrlGeneric::OnKillFocus,
                    0, this);
 
-    m_btn = new wxBitmapButton(this, CTRLID_BTN, bmp);
+    const int height = m_txt->GetBestSize().y - 4; // FIXME: fudge
+    wxBitmap bmp(height, height);
+    {
+        wxMemoryDC dc;
+        dc.SelectObject(bmp);
+        wxRendererNative::Get().DrawComboBoxDropButton
+                                (
+                                    this,
+                                    dc,
+                                    wxRect(0, 0, height, height)
+                                );
+    }
+
+    wxBitmapButton *btn = new wxBitmapButton(this, CTRLID_BTN, bmp);
+    btn->SetMargins(0, 0);
+    m_btn = btn;
 
     m_popup = new wxPopupWindow(this);
     m_popup->SetFont(GetFont());
@@ -140,28 +148,49 @@ bool wxDatePickerCtrlGeneric::Create(wxWindow *parent,
                                wxPoint(0,0), wxDefaultSize,
                                wxCAL_SHOW_HOLIDAYS | wxSUNKEN_BORDER);
     m_cal->Connect(CTRLID_CAL, CTRLID_CAL, wxEVT_CALENDAR_SEL_CHANGED,
-                   (wxObjectEventFunction)&wxDatePickerCtrlGeneric::OnSelChange,
+                   (wxObjectEventFunction)
+                   (wxEventFunction)
+                   (wxCalendarEventFunction)
+                   &wxDatePickerCtrlGeneric::OnSelChange,
                    0, this);
     m_cal->Connect(wxID_ANY, wxID_ANY, wxEVT_KEY_DOWN,
-                   (wxObjectEventFunction)&wxDatePickerCtrlGeneric::OnCalKey,
+                   (wxObjectEventFunction)
+                   (wxEventFunction)
+                   (wxCharEventFunction)
+                   &wxDatePickerCtrlGeneric::OnCalKey,
                    0, this);
     m_cal->Connect(CTRLID_CAL, CTRLID_CAL, wxEVT_CALENDAR_DOUBLECLICKED,
-                   (wxObjectEventFunction)&wxDatePickerCtrlGeneric::OnSelChange,
+                   (wxObjectEventFunction)
+                   (wxEventFunction)
+                   (wxCalendarEventFunction)
+                   &wxDatePickerCtrlGeneric::OnSelChange,
                    0, this);
     m_cal->Connect(CTRLID_CAL, CTRLID_CAL, wxEVT_CALENDAR_DAY_CHANGED,
-                   (wxObjectEventFunction)&wxDatePickerCtrlGeneric::OnSelChange,
+                   (wxObjectEventFunction)
+                   (wxEventFunction)
+                   (wxCalendarEventFunction)
+                   &wxDatePickerCtrlGeneric::OnSelChange,
                    0, this);
     m_cal->Connect(CTRLID_CAL, CTRLID_CAL, wxEVT_CALENDAR_MONTH_CHANGED,
-                   (wxObjectEventFunction)&wxDatePickerCtrlGeneric::OnSelChange,
+                   (wxObjectEventFunction)
+                   (wxEventFunction)
+                   (wxCalendarEventFunction)
+                   &wxDatePickerCtrlGeneric::OnSelChange,
                    0, this);
     m_cal->Connect(CTRLID_CAL, CTRLID_CAL, wxEVT_CALENDAR_YEAR_CHANGED,
-                   (wxObjectEventFunction)&wxDatePickerCtrlGeneric::OnSelChange,
+                   (wxObjectEventFunction)
+                   (wxEventFunction)
+                   (wxCalendarEventFunction)
+                   &wxDatePickerCtrlGeneric::OnSelChange,
                    0, this);
 
     wxWindow *yearControl = m_cal->GetYearControl();
 
     Connect(wxID_ANY, wxID_ANY, wxEVT_SET_FOCUS,
-            (wxObjectEventFunction)&wxDatePickerCtrlGeneric::OnSetFocus);
+                   (wxObjectEventFunction)
+                   (wxEventFunction)
+                   (wxFocusEventFunction)
+                   &wxDatePickerCtrlGeneric::OnSetFocus);
 
     wxClientDC dc(yearControl);
     dc.SetFont(m_font);
@@ -208,7 +237,7 @@ bool wxDatePickerCtrlGeneric::Create(wxWindow *parent,
     m_popup->SetClientSize(panel->GetSize());
     m_popup->Hide();
 
-    return TRUE;
+    return true;
 }
 
 
@@ -272,7 +301,7 @@ bool wxDatePickerCtrlGeneric::Show(bool show)
 {
     if ( !wxControl::Show(show) )
     {
-        return FALSE;
+        return false;
     }
 
     if (!show)
@@ -284,7 +313,7 @@ bool wxDatePickerCtrlGeneric::Show(bool show)
         }
     }
 
-    return TRUE;
+    return true;
 }
 
 
@@ -292,7 +321,7 @@ bool wxDatePickerCtrlGeneric::Enable(bool enable)
 {
     if ( !wxControl::Enable(enable) )
     {
-        return FALSE;
+        return false;
     }
 
     if (!enable)
@@ -302,7 +331,7 @@ bool wxDatePickerCtrlGeneric::Enable(bool enable)
     }
     if (m_btn)
         m_btn->Enable(enable);
-    return TRUE;
+    return true;
 }
 
 // ----------------------------------------------------------------------------
@@ -323,7 +352,7 @@ bool wxDatePickerCtrlGeneric::SetFormat(const wxChar *fmt)
     if (m_txt)
     {
         currentText = m_txt->GetValue();
-        if (!currentText.IsEmpty())
+        if (!currentText.empty())
             currentDate.ParseFormat(currentText, m_format);
     }
     wxDateTime dt;
@@ -379,7 +408,7 @@ bool wxDatePickerCtrlGeneric::SetFormat(const wxChar *fmt)
 
         m_txt->SetValidator(tv);
 
-        if (!currentText.IsEmpty())
+        if (!currentText.empty())
             m_txt->SetValue(currentDate.Format(m_format));
     }
     return true;
@@ -391,7 +420,7 @@ wxDateTime wxDatePickerCtrlGeneric::GetValue() const
     wxDateTime dt;
     wxString txt=m_txt->GetValue();
 
-    if (!txt.IsEmpty())
+    if (!txt.empty())
         dt.ParseFormat(txt, m_format);
 
     return dt;
@@ -437,7 +466,7 @@ void wxDatePickerCtrlGeneric::DropDown(bool down)
         if (down)
         {
             wxDateTime dt;
-            if (!m_txt->GetValue().IsEmpty())
+            if (!m_txt->GetValue().empty())
                 dt.ParseFormat(m_txt->GetValue(), m_format);
 
             if (dt.IsValid())
@@ -482,7 +511,7 @@ void wxDatePickerCtrlGeneric::OnChildSetFocus(wxChildFocusEvent &ev)
 }
 
 
-void wxDatePickerCtrlGeneric::OnClick(wxCommandEvent& event)
+void wxDatePickerCtrlGeneric::OnClick(wxCommandEvent& WXUNUSED(event))
 {
     if (m_ignoreDrop)
     {
@@ -497,7 +526,7 @@ void wxDatePickerCtrlGeneric::OnClick(wxCommandEvent& event)
 }
 
 
-void wxDatePickerCtrlGeneric::OnSetFocus(wxFocusEvent &ev)
+void wxDatePickerCtrlGeneric::OnSetFocus(wxFocusEvent& WXUNUSED(ev))
 {
     if (m_txt)
     {
@@ -547,7 +576,7 @@ void wxDatePickerCtrlGeneric::OnText(wxCommandEvent &ev)
     // If the date isn't valid, the user's probable in the middle of typing
     wxString txt=m_txt->GetValue();
     wxDateTime dt;
-    if (!txt.IsEmpty())
+    if (!txt.empty())
     {
         dt.ParseFormat(txt, m_format);
         if (!dt.IsValid())