]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/datecontrols.cpp
initial native implementation of wxCalendarCtrl for MSW
[wxWidgets.git] / src / msw / datecontrols.cpp
diff --git a/src/msw/datecontrols.cpp b/src/msw/datecontrols.cpp
new file mode 100644 (file)
index 0000000..e850351
--- /dev/null
@@ -0,0 +1,86 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        src/msw/datecontrols.cpp
+// Purpose:     implementation of date controls helper functions
+// Author:      Vadim Zeitlin
+// Created:     2008-04-04
+// RCS-ID:      $Id$
+// Copyright:   (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
+// Licence:     wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
+// ============================================================================
+// declarations
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+// for compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+    #pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+#endif // WX_PRECOMP
+
+#if wxUSE_DATEPICKCTRL || wxUSE_CALENDARCTRL
+
+#include "wx/msw/private/datecontrols.h"
+
+#include "wx/dynlib.h"
+
+// ============================================================================
+// implementation
+// ============================================================================
+
+bool wxMSWDateControls::CheckInitialization()
+{
+    // although we already call InitCommonControls() in app.cpp which is
+    // supposed to initialize all common controls, in comctl32.dll 4.72 (and
+    // presumably earlier versions 4.70 and 4.71, date time picker not being
+    // supported in < 4.70 anyhow) it does not do it and we have to initialize
+    // it explicitly
+
+    // this is initially set to -1 to indicate that we need to perform the
+    // initialization and gets set to false or true depending on its result
+    static int s_initResult = -1; // MT-ok: used from GUI thread only
+    if ( s_initResult == -1 )
+    {
+        // in any case do nothing the next time, the result won't change and
+        // it's enough to give the error only once
+        s_initResult = false;
+
+        if ( wxApp::GetComCtl32Version() < 470 )
+        {
+            wxLogError(_("This system doesn't support date controls, please upgrade your version of comctl32.dll"));
+
+            return false;
+        }
+
+#if wxUSE_DYNLIB_CLASS
+        INITCOMMONCONTROLSEX icex;
+        icex.dwSize = sizeof(icex);
+        icex.dwICC = ICC_DATE_CLASSES;
+
+        wxDynamicLibrary dllComCtl32(_T("comctl32.dll") , wxDL_VERBATIM);
+
+        if ( dllComCtl32.IsLoaded() )
+        {
+            typedef BOOL (WINAPI *ICCEx_t)(INITCOMMONCONTROLSEX *);
+            wxDYNLIB_FUNCTION( ICCEx_t, InitCommonControlsEx, dllComCtl32 );
+
+            if ( pfnInitCommonControlsEx )
+            {
+                s_initResult = (*pfnInitCommonControlsEx)(&icex);
+            }
+        }
+#endif // wxUSE_DYNLIB_CLASS
+    }
+
+    return s_initResult != 0;
+}
+
+#endif // wxUSE_DATEPICKCTRL || wxUSE_CALENDARCTRL