]> git.saurik.com Git - wxWidgets.git/blob - src/msw/datecontrols.cpp
simplify code so it always returns the same object
[wxWidgets.git] / src / msw / datecontrols.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/datecontrols.cpp
3 // Purpose: implementation of date controls helper functions
4 // Author: Vadim Zeitlin
5 // Created: 2008-04-04
6 // RCS-ID: $Id$
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #ifndef WX_PRECOMP
27 #include "wx/app.h"
28 #include "wx/msw/wrapcctl.h"
29 #endif // WX_PRECOMP
30
31 #if wxUSE_DATEPICKCTRL || wxUSE_CALENDARCTRL
32
33 #include "wx/msw/private/datecontrols.h"
34
35 #include "wx/dynlib.h"
36
37 // ============================================================================
38 // implementation
39 // ============================================================================
40
41 bool wxMSWDateControls::CheckInitialization()
42 {
43 // although we already call InitCommonControls() in app.cpp which is
44 // supposed to initialize all common controls, in comctl32.dll 4.72 (and
45 // presumably earlier versions 4.70 and 4.71, date time picker not being
46 // supported in < 4.70 anyhow) it does not do it and we have to initialize
47 // it explicitly
48
49 // this is initially set to -1 to indicate that we need to perform the
50 // initialization and gets set to false or true depending on its result
51 static int s_initResult = -1; // MT-ok: used from GUI thread only
52 if ( s_initResult == -1 )
53 {
54 // in any case do nothing the next time, the result won't change and
55 // it's enough to give the error only once
56 s_initResult = false;
57
58 if ( wxApp::GetComCtl32Version() < 470 )
59 {
60 wxLogError(_("This system doesn't support date controls, please upgrade your version of comctl32.dll"));
61
62 return false;
63 }
64
65 #if wxUSE_DYNLIB_CLASS
66 INITCOMMONCONTROLSEX icex;
67 icex.dwSize = sizeof(icex);
68 icex.dwICC = ICC_DATE_CLASSES;
69
70 // see comment in wxApp::GetComCtl32Version() explaining the
71 // use of wxLoadedDLL
72 wxLoadedDLL dllComCtl32(wxT("comctl32.dll"));
73 if ( dllComCtl32.IsLoaded() )
74 {
75 wxLogNull noLog;
76
77 typedef BOOL (WINAPI *ICCEx_t)(INITCOMMONCONTROLSEX *);
78 wxDYNLIB_FUNCTION( ICCEx_t, InitCommonControlsEx, dllComCtl32 );
79
80 if ( pfnInitCommonControlsEx )
81 {
82 s_initResult = (*pfnInitCommonControlsEx)(&icex);
83 }
84 }
85 #endif // wxUSE_DYNLIB_CLASS
86 }
87
88 return s_initResult != 0;
89 }
90
91 #endif // wxUSE_DATEPICKCTRL || wxUSE_CALENDARCTRL