1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/control.cpp
3 // Purpose: wxControl class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "control.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
36 #include "wx/dcclient.h"
38 #include "wx/settings.h"
41 #include "wx/control.h"
44 #include "wx/notebook.h"
45 #endif // wxUSE_NOTEBOOK
47 #include "wx/msw/private.h"
48 #include "wx/msw/uxtheme.h"
50 #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
58 IMPLEMENT_ABSTRACT_CLASS(wxControl
, wxWindow
)
60 // ============================================================================
61 // wxControl implementation
62 // ============================================================================
64 // ----------------------------------------------------------------------------
65 // wxControl ctor/dtor
66 // ----------------------------------------------------------------------------
68 wxControl::~wxControl()
70 m_isBeingDeleted
= true;
73 // ----------------------------------------------------------------------------
74 // control window creation
75 // ----------------------------------------------------------------------------
77 bool wxControl::Create(wxWindow
*parent
,
82 const wxValidator
& wxVALIDATOR_PARAM(validator
),
85 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
89 SetValidator(validator
);
95 bool wxControl::MSWCreateControl(const wxChar
*classname
,
96 const wxString
& label
,
101 WXDWORD msStyle
= MSWGetStyle(GetWindowStyle(), &exstyle
);
103 return MSWCreateControl(classname
, msStyle
, pos
, size
, label
, exstyle
);
106 bool wxControl::MSWCreateControl(const wxChar
*classname
,
110 const wxString
& label
,
113 // if no extended style given, determine it ourselves
114 if ( exstyle
== (WXDWORD
)-1 )
117 (void) MSWGetStyle(GetWindowStyle(), &exstyle
);
120 // all controls should have this style
123 // create the control visible if it's currently shown for wxWidgets
129 // choose the position for the control
130 int x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
,
131 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
,
132 w
= size
.x
== wxDefaultCoord
? 0 : size
.x
,
133 h
= size
.y
== wxDefaultCoord
? 0 : size
.y
;
135 // ... and adjust it to account for a possible parent frames toolbar
136 AdjustForParentClientOrigin(x
, y
);
138 m_hWnd
= (WXHWND
)::CreateWindowEx
140 exstyle
, // extended style
141 classname
, // the kind of control to create
142 label
, // the window name
143 style
, // the window style
144 x
, y
, w
, h
, // the window position and size
145 GetHwndOf(GetParent()), // parent
146 (HMENU
)GetId(), // child id
147 wxGetInstance(), // app instance
148 NULL
// creation parameters
153 wxLogDebug(wxT("Failed to create a control of class '%s'"), classname
);
154 wxFAIL_MSG(_T("something is very wrong, CreateWindowEx failed"));
162 Ctl3dSubclassCtl(GetHwnd());
165 #endif // wxUSE_CTL3D
167 // install wxWidgets window proc for this window
170 // set up fonts and colours
173 SetFont(GetDefaultAttributes().font
);
175 // set the size now if no initial size specified
176 SetInitialBestSize(size
);
181 // ----------------------------------------------------------------------------
183 // ----------------------------------------------------------------------------
185 wxBorder
wxControl::GetDefaultBorder() const
187 // we want to automatically give controls a sunken style (confusingly,
188 // it may not really mean sunken at all as we map it to WS_EX_CLIENTEDGE
189 // which is not sunken at all under Windows XP -- rather, just the default)
190 return wxBORDER_SUNKEN
;
193 WXDWORD
wxControl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
195 long msStyle
= wxWindow::MSWGetStyle(style
, exstyle
);
197 if ( AcceptsFocus() )
199 msStyle
|= WS_TABSTOP
;
205 wxSize
wxControl::DoGetBestSize() const
207 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
210 // This is a helper for all wxControls made with UPDOWN native control.
211 // In wxMSW it was only wxSpinCtrl derived from wxSpinButton but in
212 // WinCE of Smartphones this happens also for native wxTextCtrl,
213 // wxChoice and others.
214 wxSize
wxControl::GetBestSpinerSize(const bool is_vertical
) const
216 // take size according to layout
218 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
221 GetSystemMetrics(is_vertical
? SM_CXVSCROLL
: SM_CXHSCROLL
),
222 GetSystemMetrics(is_vertical
? SM_CYVSCROLL
: SM_CYHSCROLL
)
226 // correct size as for undocumented MSW variants cases (WinCE and perhaps others)
228 bestSize
.x
= bestSize
.y
;
230 bestSize
.y
= bestSize
.x
;
232 // double size according to layout
241 /* static */ wxVisualAttributes
242 wxControl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
244 wxVisualAttributes attrs
;
246 // old school (i.e. not "common") controls use the standard dialog font
248 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
250 // most, or at least many, of the controls use the same colours as the
251 // buttons -- others will have to override this (and possibly simply call
252 // GetCompositeControlsDefaultAttributes() from their versions)
253 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT
);
254 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
259 // another version for the "composite", i.e. non simple controls
260 /* static */ wxVisualAttributes
261 wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
263 wxVisualAttributes attrs
;
264 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
265 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
266 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
271 // ----------------------------------------------------------------------------
273 // ----------------------------------------------------------------------------
275 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
277 return GetEventHandler()->ProcessEvent(event
);
281 bool wxControl::MSWOnNotify(int idCtrl
,
285 wxEventType eventType
wxDUMMY_INITIALIZE(wxEVT_NULL
);
287 NMHDR
*hdr
= (NMHDR
*) lParam
;
291 eventType
= wxEVT_COMMAND_LEFT_CLICK
;
295 eventType
= wxEVT_COMMAND_LEFT_DCLICK
;
299 eventType
= wxEVT_COMMAND_RIGHT_CLICK
;
303 eventType
= wxEVT_COMMAND_RIGHT_DCLICK
;
307 eventType
= wxEVT_COMMAND_SET_FOCUS
;
311 eventType
= wxEVT_COMMAND_KILL_FOCUS
;
315 eventType
= wxEVT_COMMAND_ENTER
;
319 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
322 wxCommandEvent
event(wxEVT_NULL
, m_windowId
);
323 event
.SetEventType(eventType
);
324 event
.SetEventObject(this);
326 return GetEventHandler()->ProcessEvent(event
);
330 WXHBRUSH
wxControl::MSWControlColorSolid(WXHDC pDC
, wxColour colBg
)
334 ::SetTextColor(hdc
, wxColourToRGB(GetForegroundColour()));
338 ::SetBkColor(hdc
, wxColourToRGB(colBg
));
340 wxBrush
*brush
= wxTheBrushList
->FindOrCreateBrush(colBg
, wxSOLID
);
342 return (WXHBRUSH
)brush
->GetResourceHandle();
348 WXHBRUSH
wxControl::MSWControlColor(WXHDC pDC
)
350 WXHBRUSH hbr
= MSWControlColorSolid(pDC
, m_hasBgCol
? m_backgroundColour
355 ::SetBkMode((HDC
)pDC
, TRANSPARENT
);
357 #if wxUSE_UXTHEME && wxUSE_NOTEBOOK
358 if ( wxUxThemeEngine::GetIfActive() )
360 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
362 if ( win
->IsTopLevel() )
364 // don't go beyond the first top level parent
368 wxNotebook
*nbook
= wxDynamicCast(win
, wxNotebook
);
371 // return value may be NULL but it is ok: if the first parent
372 // notebook doesn't use themes, then we don't have to process
373 // this message at all, so let default processing take place
374 return nbook
->GetThemeBackgroundBrush(pDC
, this);
378 #endif // wxUSE_UXTHEME
380 // let the control deal with background itself
384 WXHBRUSH
wxControl::MSWControlColorDisabled(WXHDC pDC
)
386 return MSWControlColorSolid
389 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
)
393 // ---------------------------------------------------------------------------
395 // ---------------------------------------------------------------------------
397 // this is used in radiobox.cpp and slider95.cpp and should be removed as soon
398 // as it is not needed there any more!
400 // Call this repeatedly for several wnds to find the overall size
402 // Call it initially with wxDefaultCoord for all values in rect.
403 // Keep calling for other widgets, and rect will be modified
404 // to calculate largest bounding rectangle.
405 void wxFindMaxSize(WXHWND wnd
, RECT
*rect
)
407 int left
= rect
->left
;
408 int right
= rect
->right
;
410 int bottom
= rect
->bottom
;
412 GetWindowRect((HWND
) wnd
, rect
);
417 if (left
< rect
->left
)
420 if (right
> rect
->right
)
426 if (bottom
> rect
->bottom
)
427 rect
->bottom
= bottom
;
430 #endif // wxUSE_CONTROLS