]>
Commit | Line | Data |
---|---|---|
a340b80d | 1 | ///////////////////////////////////////////////////////////////////////////// |
93f7f8be | 2 | // Name: src/msw/combo.cpp |
a57d600f | 3 | // Purpose: wxMSW wxComboCtrl |
a340b80d VZ |
4 | // Author: Jaakko Salli |
5 | // Modified by: | |
6 | // Created: Apr-30-2006 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2005 Jaakko Salli | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #include "wx/wxprec.h" | |
21 | ||
22 | #ifdef __BORLANDC__ | |
23 | #pragma hdrstop | |
24 | #endif | |
25 | ||
a57d600f | 26 | #if wxUSE_COMBOCTRL |
a340b80d VZ |
27 | |
28 | #ifndef WX_PRECOMP | |
29 | #include "wx/log.h" | |
30 | #include "wx/combobox.h" | |
31 | #include "wx/dcclient.h" | |
32 | #include "wx/settings.h" | |
33 | #include "wx/dialog.h" | |
2835f3cf | 34 | #include "wx/stopwatch.h" |
a340b80d VZ |
35 | #endif |
36 | ||
37 | #include "wx/dcbuffer.h" | |
a340b80d VZ |
38 | #include "wx/combo.h" |
39 | ||
974a12f8 | 40 | #include "wx/msw/registry.h" |
f100b1c3 | 41 | #if wxUSE_UXTHEME |
a340b80d | 42 | #include "wx/msw/uxtheme.h" |
f100b1c3 | 43 | #endif |
888dde65 | 44 | #include "wx/msw/dc.h" |
a340b80d VZ |
45 | |
46 | // Change to #if 1 to include tmschema.h for easier testing of theme | |
47 | // parameters. | |
48 | #if 0 | |
49 | #include <tmschema.h> | |
c905c0d6 | 50 | #include <VSStyle.h> |
a340b80d VZ |
51 | #else |
52 | //---------------------------------- | |
53 | #define EP_EDITTEXT 1 | |
54 | #define ETS_NORMAL 1 | |
55 | #define ETS_HOT 2 | |
56 | #define ETS_SELECTED 3 | |
57 | #define ETS_DISABLED 4 | |
58 | #define ETS_FOCUSED 5 | |
59 | #define ETS_READONLY 6 | |
60 | #define ETS_ASSIST 7 | |
61 | #define TMT_FILLCOLOR 3802 | |
62 | #define TMT_TEXTCOLOR 3803 | |
63 | #define TMT_BORDERCOLOR 3801 | |
64 | #define TMT_EDGEFILLCOLOR 3808 | |
c905c0d6 VZ |
65 | #define TMT_BGTYPE 4001 |
66 | ||
67 | #define BT_IMAGEFILE 0 | |
68 | #define BT_BORDERFILL 1 | |
69 | ||
70 | #define CP_DROPDOWNBUTTON 1 | |
71 | #define CP_BACKGROUND 2 // This and above are Vista and later only | |
72 | #define CP_TRANSPARENTBACKGROUND 3 | |
73 | #define CP_BORDER 4 | |
74 | #define CP_READONLY 5 | |
75 | #define CP_DROPDOWNBUTTONRIGHT 6 | |
76 | #define CP_DROPDOWNBUTTONLEFT 7 | |
77 | #define CP_CUEBANNER 8 | |
78 | ||
79 | #define CBXS_NORMAL 1 | |
80 | #define CBXS_HOT 2 | |
81 | #define CBXS_PRESSED 3 | |
82 | #define CBXS_DISABLED 4 | |
83 | ||
84 | #define CBXSR_NORMAL 1 | |
85 | #define CBXSR_HOT 2 | |
86 | #define CBXSR_PRESSED 3 | |
87 | #define CBXSR_DISABLED 4 | |
88 | ||
89 | #define CBXSL_NORMAL 1 | |
90 | #define CBXSL_HOT 2 | |
91 | #define CBXSL_PRESSED 3 | |
92 | #define CBXSL_DISABLED 4 | |
93 | ||
94 | #define CBTBS_NORMAL 1 | |
95 | #define CBTBS_HOT 2 | |
96 | #define CBTBS_DISABLED 3 | |
97 | #define CBTBS_FOCUSED 4 | |
98 | ||
99 | #define CBB_NORMAL 1 | |
100 | #define CBB_HOT 2 | |
101 | #define CBB_FOCUSED 3 | |
102 | #define CBB_DISABLED 4 | |
103 | ||
104 | #define CBRO_NORMAL 1 | |
105 | #define CBRO_HOT 2 | |
106 | #define CBRO_PRESSED 3 | |
107 | #define CBRO_DISABLED 4 | |
108 | ||
109 | #define CBCB_NORMAL 1 | |
110 | #define CBCB_HOT 2 | |
111 | #define CBCB_PRESSED 3 | |
112 | #define CBCB_DISABLED 4 | |
113 | ||
a340b80d VZ |
114 | #endif |
115 | ||
116 | ||
117 | #define NATIVE_TEXT_INDENT_XP 4 | |
118 | #define NATIVE_TEXT_INDENT_CLASSIC 2 | |
119 | ||
30be036c RR |
120 | #define COMBOBOX_ANIMATION_RESOLUTION 10 |
121 | ||
974a12f8 | 122 | #define COMBOBOX_ANIMATION_DURATION 200 // In milliseconds |
a340b80d | 123 | |
53a64063 | 124 | #define wxMSW_DESKTOP_USERPREFERENCESMASK_COMBOBOXANIM (1<<2) |
30be036c RR |
125 | |
126 | ||
a340b80d VZ |
127 | // ============================================================================ |
128 | // implementation | |
129 | // ============================================================================ | |
130 | ||
131 | ||
a57d600f VZ |
132 | BEGIN_EVENT_TABLE(wxComboCtrl, wxComboCtrlBase) |
133 | EVT_PAINT(wxComboCtrl::OnPaintEvent) | |
134 | EVT_MOUSE_EVENTS(wxComboCtrl::OnMouseEvent) | |
53a64063 | 135 | #if wxUSE_COMBOCTRL_POPUP_ANIMATION |
30be036c | 136 | EVT_TIMER(wxID_ANY, wxComboCtrl::OnTimerEvent) |
53a64063 | 137 | #endif |
a340b80d VZ |
138 | END_EVENT_TABLE() |
139 | ||
140 | ||
a57d600f | 141 | IMPLEMENT_DYNAMIC_CLASS(wxComboCtrl, wxComboCtrlBase) |
a340b80d | 142 | |
a57d600f | 143 | void wxComboCtrl::Init() |
a340b80d VZ |
144 | { |
145 | } | |
146 | ||
a57d600f | 147 | bool wxComboCtrl::Create(wxWindow *parent, |
a340b80d VZ |
148 | wxWindowID id, |
149 | const wxString& value, | |
150 | const wxPoint& pos, | |
151 | const wxSize& size, | |
152 | long style, | |
153 | const wxValidator& validator, | |
154 | const wxString& name) | |
155 | { | |
156 | ||
157 | // Set border | |
158 | long border = style & wxBORDER_MASK; | |
159 | ||
f100b1c3 | 160 | #if wxUSE_UXTHEME |
a340b80d | 161 | wxUxThemeEngine* theme = wxUxThemeEngine::GetIfActive(); |
f100b1c3 | 162 | #endif |
a340b80d VZ |
163 | |
164 | if ( !border ) | |
165 | { | |
f100b1c3 | 166 | #if wxUSE_UXTHEME |
a340b80d VZ |
167 | if ( theme ) |
168 | { | |
c905c0d6 | 169 | // For XP, have 1-width custom border, for older version use sunken |
a340b80d VZ |
170 | border = wxBORDER_NONE; |
171 | m_widthCustomBorder = 1; | |
172 | } | |
173 | else | |
f100b1c3 | 174 | #endif |
a340b80d VZ |
175 | border = wxBORDER_SUNKEN; |
176 | ||
177 | style = (style & ~(wxBORDER_MASK)) | border; | |
178 | } | |
179 | ||
180 | // create main window | |
a57d600f | 181 | if ( !wxComboCtrlBase::Create(parent, |
93f7f8be WS |
182 | id, |
183 | value, | |
184 | pos, | |
185 | size, | |
186 | style | wxFULL_REPAINT_ON_RESIZE, | |
fda62793 | 187 | validator, |
93f7f8be | 188 | name) ) |
a340b80d VZ |
189 | return false; |
190 | ||
f100b1c3 | 191 | #if wxUSE_UXTHEME |
c905c0d6 VZ |
192 | if ( theme ) |
193 | { | |
194 | if ( ::wxGetWinVersion() >= wxWinVersion_Vista ) | |
195 | m_iFlags |= wxCC_BUTTON_STAYS_DOWN |wxCC_BUTTON_COVERS_BORDER; | |
196 | } | |
f100b1c3 | 197 | #endif |
c905c0d6 | 198 | |
a340b80d VZ |
199 | if ( style & wxCC_STD_BUTTON ) |
200 | m_iFlags |= wxCC_POPUP_ON_MOUSE_UP; | |
201 | ||
9cb80f3f JS |
202 | // Prepare background for double-buffering or better background theme |
203 | // support, whichever is possible. | |
204 | SetDoubleBuffered(true); | |
205 | if ( !IsDoubleBuffered() ) | |
206 | SetBackgroundStyle( wxBG_STYLE_PAINT ); | |
207 | ||
a340b80d | 208 | // Create textctrl, if necessary |
fda62793 | 209 | CreateTextCtrl( wxNO_BORDER ); |
a340b80d VZ |
210 | |
211 | // Add keyboard input handlers for main control and textctrl | |
b445b6a7 | 212 | InstallInputHandlers(); |
a340b80d | 213 | |
170acdc9 RD |
214 | // SetInitialSize should be called last |
215 | SetInitialSize(size); | |
a340b80d VZ |
216 | |
217 | return true; | |
218 | } | |
219 | ||
a57d600f | 220 | wxComboCtrl::~wxComboCtrl() |
a340b80d VZ |
221 | { |
222 | } | |
223 | ||
a57d600f | 224 | void wxComboCtrl::OnResize() |
a340b80d VZ |
225 | { |
226 | // | |
227 | // Recalculates button and textctrl areas | |
228 | ||
a340b80d VZ |
229 | // Technically Classic Windows style combo has more narrow button, |
230 | // but the native renderer doesn't paint it well like that. | |
231 | int btnWidth = 17; | |
232 | CalculateAreas(btnWidth); | |
233 | ||
234 | // Position textctrl using standard routine | |
30e92ba3 | 235 | PositionTextCtrl(); |
a340b80d VZ |
236 | } |
237 | ||
238 | // Draws non-XP GUI dotted line around the focus area | |
239 | static void wxMSWDrawFocusRect( wxDC& dc, const wxRect& rect ) | |
240 | { | |
241 | #if !defined(__WXWINCE__) | |
242 | /* | |
243 | RECT mswRect; | |
244 | mswRect.left = rect.x; | |
245 | mswRect.top = rect.y; | |
246 | mswRect.right = rect.x + rect.width; | |
247 | mswRect.bottom = rect.y + rect.height; | |
248 | HDC hdc = (HDC) dc.GetHDC(); | |
249 | SetMapMode(hdc,MM_TEXT); // Just in case... | |
250 | DrawFocusRect(hdc,&mswRect); | |
251 | */ | |
252 | // FIXME: Use DrawFocusRect code above (currently it draws solid line | |
253 | // for caption focus but works ok for other stuff). | |
254 | // Also, this code below may not work in future wx versions, since | |
255 | // it employs wxCAP_BUTT hack to have line of width 1. | |
256 | dc.SetLogicalFunction(wxINVERT); | |
257 | ||
cb129171 | 258 | wxPen pen(*wxBLACK, 1, wxPENSTYLE_DOT); |
a340b80d VZ |
259 | pen.SetCap(wxCAP_BUTT); |
260 | dc.SetPen(pen); | |
261 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
262 | ||
263 | dc.DrawRectangle(rect); | |
264 | ||
265 | dc.SetLogicalFunction(wxCOPY); | |
266 | #else | |
267 | dc.SetLogicalFunction(wxINVERT); | |
268 | ||
269 | dc.SetPen(wxPen(*wxBLACK,1,wxDOT)); | |
270 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
271 | ||
272 | dc.DrawRectangle(rect); | |
273 | ||
274 | dc.SetLogicalFunction(wxCOPY); | |
275 | #endif | |
276 | } | |
277 | ||
278 | // draw focus background on area in a way typical on platform | |
0d203f87 VZ |
279 | void |
280 | wxComboCtrl::PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const | |
a340b80d | 281 | { |
f100b1c3 | 282 | #if wxUSE_UXTHEME |
a340b80d | 283 | wxUxThemeHandle hTheme(this, L"COMBOBOX"); |
f100b1c3 | 284 | #endif |
a340b80d VZ |
285 | |
286 | wxSize sz = GetClientSize(); | |
287 | bool isEnabled; | |
c905c0d6 | 288 | bool doDrawFocusRect; // also selected |
a340b80d VZ |
289 | |
290 | // For smaller size control (and for disabled background) use less spacing | |
291 | int focusSpacingX; | |
292 | int focusSpacingY; | |
293 | ||
294 | if ( !(flags & wxCONTROL_ISSUBMENU) ) | |
295 | { | |
296 | // Drawing control | |
297 | isEnabled = IsEnabled(); | |
c905c0d6 | 298 | doDrawFocusRect = ShouldDrawFocus(); |
a340b80d | 299 | |
f100b1c3 | 300 | #if wxUSE_UXTHEME |
a340b80d VZ |
301 | // Windows-style: for smaller size control (and for disabled background) use less spacing |
302 | if ( hTheme ) | |
303 | { | |
304 | // WinXP Theme | |
305 | focusSpacingX = isEnabled ? 2 : 1; | |
306 | focusSpacingY = sz.y > (GetCharHeight()+2) && isEnabled ? 2 : 1; | |
307 | } | |
308 | else | |
f100b1c3 | 309 | #endif |
a340b80d VZ |
310 | { |
311 | // Classic Theme | |
312 | if ( isEnabled ) | |
313 | { | |
314 | focusSpacingX = 1; | |
315 | focusSpacingY = 1; | |
316 | } | |
317 | else | |
318 | { | |
319 | focusSpacingX = 0; | |
320 | focusSpacingY = 0; | |
321 | } | |
322 | } | |
323 | } | |
324 | else | |
325 | { | |
326 | // Drawing a list item | |
327 | isEnabled = true; // they are never disabled | |
c905c0d6 | 328 | doDrawFocusRect = flags & wxCONTROL_SELECTED ? true : false; |
a340b80d VZ |
329 | |
330 | focusSpacingX = 0; | |
331 | focusSpacingY = 0; | |
332 | } | |
333 | ||
334 | // Set the background sub-rectangle for selection, disabled etc | |
335 | wxRect selRect(rect); | |
336 | selRect.y += focusSpacingY; | |
337 | selRect.height -= (focusSpacingY*2); | |
8e5ec129 WS |
338 | |
339 | int wcp = 0; | |
340 | ||
341 | if ( !(flags & wxCONTROL_ISSUBMENU) ) | |
342 | wcp += m_widthCustomPaint; | |
343 | ||
344 | selRect.x += wcp + focusSpacingX; | |
345 | selRect.width -= wcp + (focusSpacingX*2); | |
a340b80d | 346 | |
d3b9f782 | 347 | //wxUxThemeEngine* theme = NULL; |
0d203f87 VZ |
348 | //if ( hTheme ) |
349 | // theme = wxUxThemeEngine::GetIfActive(); | |
a340b80d | 350 | |
3b9ba64c | 351 | wxColour fgCol; |
a340b80d | 352 | wxColour bgCol; |
c905c0d6 VZ |
353 | bool doDrawDottedEdge = false; |
354 | bool doDrawSelRect = true; | |
355 | ||
356 | // TODO: doDrawDottedEdge = true when focus has arrived to control via tab. | |
357 | // (and other cases which are not that apparent). | |
a340b80d VZ |
358 | |
359 | if ( isEnabled ) | |
360 | { | |
361 | // If popup is hidden and this control is focused, | |
362 | // then draw the focus-indicator (selbgcolor background etc.). | |
c905c0d6 | 363 | if ( doDrawFocusRect ) |
a340b80d | 364 | { |
c905c0d6 VZ |
365 | // NB: We can't really use XP visual styles to get TMT_TEXTCOLOR since |
366 | // it is not properly defined for combo boxes. Instead, they expect | |
367 | // you to use DrawThemeText. | |
368 | // | |
369 | // Here is, however, sample code how to get theme colours: | |
370 | // | |
371 | // COLORREF cref; | |
372 | // theme->GetThemeColor(hTheme,EP_EDITTEXT,ETS_NORMAL,TMT_TEXTCOLOR,&cref); | |
373 | // dc.SetTextForeground( wxRGBToColour(cref) ); | |
374 | if ( (m_iFlags & wxCC_FULL_BUTTON) && !(flags & wxCONTROL_ISSUBMENU) ) | |
a340b80d | 375 | { |
c905c0d6 | 376 | // Vista style read-only combo |
3b9ba64c JS |
377 | fgCol = GetForegroundColour(); |
378 | bgCol = GetBackgroundColour(); | |
c905c0d6 VZ |
379 | doDrawSelRect = false; |
380 | doDrawDottedEdge = true; | |
a340b80d VZ |
381 | } |
382 | else | |
a340b80d | 383 | { |
3b9ba64c | 384 | fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); |
a340b80d | 385 | bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); |
a340b80d VZ |
386 | } |
387 | } | |
388 | else | |
389 | { | |
3b9ba64c | 390 | fgCol = GetForegroundColour(); |
c905c0d6 VZ |
391 | bgCol = GetBackgroundColour(); |
392 | doDrawSelRect = false; | |
a340b80d VZ |
393 | } |
394 | } | |
395 | else | |
396 | { | |
3b9ba64c | 397 | fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT); |
c905c0d6 | 398 | bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); |
a340b80d VZ |
399 | } |
400 | ||
3b9ba64c | 401 | dc.SetTextForeground(fgCol); |
a340b80d | 402 | dc.SetBrush(bgCol); |
c905c0d6 VZ |
403 | if ( doDrawSelRect ) |
404 | { | |
405 | dc.SetPen(bgCol); | |
406 | dc.DrawRectangle(selRect); | |
407 | } | |
408 | ||
409 | if ( doDrawDottedEdge ) | |
410 | wxMSWDrawFocusRect(dc, selRect); | |
a340b80d | 411 | |
118f5fbd RR |
412 | // Don't clip exactly to the selection rectangle so we can draw |
413 | // to the non-selected area in front of it. | |
414 | wxRect clipRect(rect.x,rect.y, | |
415 | (selRect.x+selRect.width)-rect.x-1,rect.height); | |
416 | dc.SetClippingRegion(clipRect); | |
a340b80d VZ |
417 | } |
418 | ||
a57d600f | 419 | void wxComboCtrl::OnPaintEvent( wxPaintEvent& WXUNUSED(event) ) |
a340b80d VZ |
420 | { |
421 | // TODO: Convert drawing in this function to Windows API Code | |
422 | ||
423 | wxSize sz = GetClientSize(); | |
9cb80f3f JS |
424 | wxDC* dcPtr = wxAutoBufferedPaintDCFactory(this); |
425 | wxDC& dc = *dcPtr; | |
a340b80d | 426 | |
c905c0d6 VZ |
427 | const wxRect& rectButton = m_btnArea; |
428 | wxRect rectTextField = m_tcArea; | |
a340b80d | 429 | wxColour bgCol = GetBackgroundColour(); |
c905c0d6 | 430 | |
d6f2a891 VZ |
431 | #if wxUSE_UXTHEME |
432 | const bool isEnabled = IsEnabled(); | |
433 | ||
888dde65 RR |
434 | wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl(); |
435 | HDC hDc = GetHdcOf(*impl); | |
c905c0d6 | 436 | HWND hWnd = GetHwndOf(this); |
a340b80d VZ |
437 | |
438 | wxUxThemeEngine* theme = NULL; | |
439 | wxUxThemeHandle hTheme(this, L"COMBOBOX"); | |
a340b80d | 440 | |
c905c0d6 VZ |
441 | if ( hTheme ) |
442 | theme = wxUxThemeEngine::GetIfActive(); | |
d6f2a891 | 443 | #endif // wxUSE_UXTHEME |
c905c0d6 VZ |
444 | |
445 | wxRect borderRect(0,0,sz.x,sz.y); | |
446 | ||
a340b80d VZ |
447 | if ( m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE ) |
448 | { | |
c905c0d6 VZ |
449 | borderRect = m_tcArea; |
450 | borderRect.Inflate(1); | |
a340b80d VZ |
451 | } |
452 | ||
c905c0d6 VZ |
453 | int drawButFlags = 0; |
454 | ||
f100b1c3 | 455 | #if wxUSE_UXTHEME |
a340b80d VZ |
456 | if ( hTheme ) |
457 | { | |
c905c0d6 VZ |
458 | const bool useVistaComboBox = ::wxGetWinVersion() >= wxWinVersion_Vista; |
459 | ||
460 | RECT rFull; | |
461 | wxCopyRectToRECT(borderRect, rFull); | |
462 | ||
463 | RECT rButton; | |
464 | wxCopyRectToRECT(rectButton, rButton); | |
465 | ||
466 | RECT rBorder; | |
467 | wxCopyRectToRECT(borderRect, rBorder); | |
468 | ||
469 | bool isNonStdButton = (m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE) || | |
470 | (m_iFlags & wxCC_IFLAG_HAS_NONSTANDARD_BUTTON); | |
471 | ||
472 | // | |
473 | // Get some states for themed drawing | |
474 | int butState; | |
a340b80d | 475 | |
a340b80d | 476 | if ( !isEnabled ) |
c905c0d6 VZ |
477 | { |
478 | butState = CBXS_DISABLED; | |
479 | } | |
480 | // Vista will display the drop-button as depressed always | |
481 | // when the popup window is visilbe | |
482 | else if ( (m_btnState & wxCONTROL_PRESSED) || | |
483 | (useVistaComboBox && !IsPopupWindowState(Hidden)) ) | |
484 | { | |
485 | butState = CBXS_PRESSED; | |
486 | } | |
487 | else if ( m_btnState & wxCONTROL_CURRENT ) | |
488 | { | |
489 | butState = CBXS_HOT; | |
490 | } | |
a340b80d | 491 | else |
c905c0d6 VZ |
492 | { |
493 | butState = CBXS_NORMAL; | |
494 | } | |
495 | ||
496 | int comboBoxPart = 0; // For XP, use the 'default' part | |
497 | RECT* rUseForBg = &rBorder; | |
498 | ||
499 | bool drawFullButton = false; | |
500 | int bgState = butState; | |
501 | const bool isFocused = (FindFocus() == GetMainWindowOfCompositeControl()) ? true : false; | |
a340b80d | 502 | |
c905c0d6 | 503 | if ( useVistaComboBox ) |
a340b80d | 504 | { |
c905c0d6 VZ |
505 | // FIXME: Either SetBackgroundColour or GetBackgroundColour |
506 | // doesn't work under Vista, so here's a temporary | |
507 | // workaround. | |
508 | bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); | |
a340b80d | 509 | |
c905c0d6 VZ |
510 | // Draw the entire control as a single button? |
511 | if ( !isNonStdButton ) | |
512 | { | |
513 | if ( HasFlag(wxCB_READONLY) ) | |
514 | drawFullButton = true; | |
515 | } | |
516 | ||
517 | if ( drawFullButton ) | |
518 | { | |
519 | comboBoxPart = CP_READONLY; | |
520 | rUseForBg = &rFull; | |
521 | ||
522 | // It should be safe enough to update this flag here. | |
523 | m_iFlags |= wxCC_FULL_BUTTON; | |
524 | } | |
525 | else | |
526 | { | |
527 | comboBoxPart = CP_BORDER; | |
528 | m_iFlags &= ~wxCC_FULL_BUTTON; | |
a340b80d | 529 | |
c905c0d6 VZ |
530 | if ( isFocused ) |
531 | bgState = CBB_FOCUSED; | |
532 | else | |
533 | bgState = CBB_NORMAL; | |
534 | } | |
a340b80d VZ |
535 | } |
536 | ||
c905c0d6 VZ |
537 | // |
538 | // Draw parent's background, if necessary | |
539 | RECT* rUseForTb = NULL; | |
a340b80d | 540 | |
c905c0d6 VZ |
541 | if ( theme->IsThemeBackgroundPartiallyTransparent( hTheme, comboBoxPart, bgState ) ) |
542 | rUseForTb = &rFull; | |
543 | else if ( m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE ) | |
544 | rUseForTb = &rButton; | |
a340b80d | 545 | |
c905c0d6 VZ |
546 | if ( rUseForTb ) |
547 | theme->DrawThemeParentBackground( hWnd, hDc, rUseForTb ); | |
a340b80d | 548 | |
c905c0d6 VZ |
549 | // |
550 | // Draw the control background (including the border) | |
551 | if ( m_widthCustomBorder > 0 ) | |
552 | { | |
553 | theme->DrawThemeBackground( hTheme, hDc, comboBoxPart, bgState, rUseForBg, NULL ); | |
554 | } | |
555 | else | |
556 | { | |
557 | // No border. We can't use theme, since it cannot be relied on | |
558 | // to deliver borderless drawing, even with DrawThemeBackgroundEx. | |
559 | dc.SetBrush(bgCol); | |
560 | dc.SetPen(bgCol); | |
561 | dc.DrawRectangle(borderRect); | |
562 | } | |
a340b80d | 563 | |
c905c0d6 VZ |
564 | // |
565 | // Draw the drop-button | |
566 | if ( !isNonStdButton ) | |
567 | { | |
568 | drawButFlags = Button_BitmapOnly; | |
a340b80d | 569 | |
c905c0d6 VZ |
570 | int butPart = CP_DROPDOWNBUTTON; |
571 | ||
572 | if ( useVistaComboBox ) | |
573 | { | |
574 | if ( drawFullButton ) | |
575 | { | |
576 | // We need to alter the button style slightly before | |
577 | // drawing the actual button (but it was good above | |
578 | // when background etc was done). | |
579 | if ( butState == CBXS_HOT || butState == CBXS_PRESSED ) | |
580 | butState = CBXS_NORMAL; | |
581 | } | |
582 | ||
583 | if ( m_btnSide == wxRIGHT ) | |
584 | butPart = CP_DROPDOWNBUTTONRIGHT; | |
585 | else | |
586 | butPart = CP_DROPDOWNBUTTONLEFT; | |
587 | ||
588 | } | |
589 | theme->DrawThemeBackground( hTheme, hDc, butPart, butState, &rButton, NULL ); | |
590 | } | |
591 | else if ( useVistaComboBox && | |
592 | (m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE) ) | |
593 | { | |
594 | // We'll do this, because DrawThemeParentBackground | |
595 | // doesn't seem to be reliable on Vista. | |
596 | drawButFlags |= Button_PaintBackground; | |
597 | } | |
598 | } | |
599 | else | |
f100b1c3 | 600 | #endif |
c905c0d6 VZ |
601 | { |
602 | // Windows 2000 and earlier | |
603 | drawButFlags = Button_PaintBackground; | |
a340b80d | 604 | |
c905c0d6 VZ |
605 | dc.SetBrush(bgCol); |
606 | dc.SetPen(bgCol); | |
607 | dc.DrawRectangle(borderRect); | |
93f7f8be | 608 | } |
a340b80d | 609 | |
c905c0d6 VZ |
610 | // Button rendering (may only do the bitmap on button, depending on the flags) |
611 | DrawButton( dc, rectButton, drawButFlags ); | |
a340b80d | 612 | |
c905c0d6 | 613 | // Paint required portion of the custom image on the control |
6d0ce565 | 614 | if ( (!m_text || m_widthCustomPaint) ) |
a340b80d VZ |
615 | { |
616 | wxASSERT( m_widthCustomPaint >= 0 ); | |
617 | ||
618 | // this is intentionally here to allow drawed rectangle's | |
619 | // right edge to be hidden | |
620 | if ( m_text ) | |
c905c0d6 | 621 | rectTextField.width = m_widthCustomPaint; |
a340b80d VZ |
622 | |
623 | dc.SetFont( GetFont() ); | |
624 | ||
c905c0d6 | 625 | dc.SetClippingRegion(rectTextField); |
6d0ce565 | 626 | if ( m_popupInterface ) |
c905c0d6 | 627 | m_popupInterface->PaintComboControl(dc,rectTextField); |
6d0ce565 | 628 | else |
c905c0d6 | 629 | wxComboPopup::DefaultPaintComboControl(this,dc,rectTextField); |
a340b80d | 630 | } |
9cb80f3f JS |
631 | |
632 | delete dcPtr; | |
a340b80d VZ |
633 | } |
634 | ||
a57d600f | 635 | void wxComboCtrl::OnMouseEvent( wxMouseEvent& event ) |
a340b80d | 636 | { |
1efad474 RR |
637 | int mx = event.m_x; |
638 | bool isOnButtonArea = m_btnArea.Contains(mx,event.m_y); | |
a340b80d VZ |
639 | int handlerFlags = isOnButtonArea ? wxCC_MF_ON_BUTTON : 0; |
640 | ||
a340b80d VZ |
641 | if ( PreprocessMouseEvent(event,isOnButtonArea) ) |
642 | return; | |
643 | ||
644 | if ( (m_windowStyle & (wxCC_SPECIAL_DCLICK|wxCB_READONLY)) == wxCB_READONLY ) | |
645 | { | |
646 | // if no textctrl and no special double-click, then the entire control acts | |
647 | // as a button | |
648 | handlerFlags |= wxCC_MF_ON_BUTTON; | |
649 | if ( HandleButtonMouseEvent(event,handlerFlags) ) | |
650 | return; | |
651 | } | |
652 | else | |
653 | { | |
1efad474 RR |
654 | if ( isOnButtonArea || HasCapture() || |
655 | (m_widthCustomPaint && mx < (m_tcArea.x+m_widthCustomPaint)) ) | |
a340b80d | 656 | { |
1efad474 RR |
657 | handlerFlags |= wxCC_MF_ON_CLICK_AREA; |
658 | ||
a340b80d VZ |
659 | if ( HandleButtonMouseEvent(event,handlerFlags) ) |
660 | return; | |
661 | } | |
662 | else if ( m_btnState ) | |
663 | { | |
664 | // otherwise need to clear the hover status | |
665 | m_btnState = 0; | |
666 | RefreshRect(m_btnArea); | |
667 | } | |
668 | } | |
669 | ||
670 | // | |
671 | // This will handle left_down and left_dclick events outside button in a Windows-like manner. | |
672 | // See header file for further information on this method. | |
673 | HandleNormalMouseEvent(event); | |
674 | ||
675 | } | |
676 | ||
30be036c | 677 | #if wxUSE_COMBOCTRL_POPUP_ANIMATION |
974a12f8 RR |
678 | static wxUint32 GetUserPreferencesMask() |
679 | { | |
680 | static wxUint32 userPreferencesMask = 0; | |
681 | static bool valueSet = false; | |
682 | ||
683 | if ( valueSet ) | |
684 | return userPreferencesMask; | |
685 | ||
53a64063 JS |
686 | wxRegKey* pKey = NULL; |
687 | wxRegKey key1(wxRegKey::HKCU, wxT("Software\\Policies\\Microsoft\\Control Panel")); | |
688 | wxRegKey key2(wxRegKey::HKCU, wxT("Software\\Policies\\Microsoft\\Windows\\Control Panel")); | |
689 | wxRegKey key3(wxRegKey::HKCU, wxT("Control Panel\\Desktop")); | |
690 | ||
691 | if ( key1.Exists() ) | |
692 | pKey = &key1; | |
693 | else if ( key2.Exists() ) | |
694 | pKey = &key2; | |
695 | else if ( key3.Exists() ) | |
696 | pKey = &key3; | |
697 | ||
698 | if ( pKey && pKey->Open(wxRegKey::Read) ) | |
974a12f8 RR |
699 | { |
700 | wxMemoryBuffer buf; | |
53a64063 JS |
701 | if ( pKey->HasValue(wxT("UserPreferencesMask")) && |
702 | pKey->QueryValue(wxT("UserPreferencesMask"), buf) ) | |
974a12f8 RR |
703 | { |
704 | if ( buf.GetDataLen() >= 4 ) | |
705 | { | |
53a64063 JS |
706 | wxUint32* p = (wxUint32*) buf.GetData(); |
707 | userPreferencesMask = *p; | |
974a12f8 RR |
708 | } |
709 | } | |
710 | } | |
711 | ||
712 | valueSet = true; | |
713 | ||
714 | return userPreferencesMask; | |
715 | } | |
716 | #endif | |
717 | ||
30be036c | 718 | #if wxUSE_COMBOCTRL_POPUP_ANIMATION |
952555f7 | 719 | void wxComboCtrl::DoTimerEvent() |
974a12f8 | 720 | { |
30be036c | 721 | bool stopTimer = false; |
974a12f8 | 722 | |
ce5f620a | 723 | wxWindow* win = GetPopupWindow(); |
30be036c | 724 | wxWindow* popup = GetPopupControl()->GetControl(); |
974a12f8 | 725 | |
30be036c RR |
726 | // Popup was hidden before it was fully shown? |
727 | if ( IsPopupWindowState(Hidden) ) | |
728 | { | |
729 | stopTimer = true; | |
730 | } | |
731 | else | |
732 | { | |
733 | wxLongLong t = ::wxGetLocalTimeMillis(); | |
734 | const wxRect& rect = m_animRect; | |
974a12f8 | 735 | |
30be036c RR |
736 | int pos = (int) (t-m_animStart).GetLo(); |
737 | if ( pos < COMBOBOX_ANIMATION_DURATION ) | |
974a12f8 | 738 | { |
30be036c RR |
739 | int height = rect.height; |
740 | //int h0 = rect.height; | |
741 | int h = (((pos*256)/COMBOBOX_ANIMATION_DURATION)*height)/256; | |
742 | int y = (height - h); | |
974a12f8 RR |
743 | if ( y < 0 ) |
744 | y = 0; | |
745 | ||
30be036c | 746 | if ( m_animFlags & ShowAbove ) |
974a12f8 | 747 | { |
30be036c | 748 | win->SetSize( rect.x, rect.y + height - h, rect.width, h ); |
974a12f8 RR |
749 | } |
750 | else | |
751 | { | |
ce5f620a JS |
752 | // Note that apparently Move() should be called after |
753 | // SetSize() to reduce (or even eliminate) animation garbage | |
974a12f8 | 754 | win->SetSize( rect.x, rect.y, rect.width, h ); |
ce5f620a | 755 | popup->Move( 0, -y ); |
974a12f8 | 756 | } |
974a12f8 | 757 | } |
30be036c RR |
758 | else |
759 | { | |
760 | stopTimer = true; | |
761 | } | |
762 | } | |
974a12f8 | 763 | |
30be036c RR |
764 | if ( stopTimer ) |
765 | { | |
30be036c RR |
766 | m_animTimer.Stop(); |
767 | DoShowPopup( m_animRect, m_animFlags ); | |
ce5f620a JS |
768 | popup->Move( 0, 0 ); |
769 | ||
770 | // Do a one final refresh to clean up the rare cases of animation | |
771 | // garbage | |
772 | win->Refresh(); | |
974a12f8 | 773 | } |
30be036c | 774 | } |
974a12f8 RR |
775 | #endif |
776 | ||
30be036c RR |
777 | #if wxUSE_COMBOCTRL_POPUP_ANIMATION |
778 | bool wxComboCtrl::AnimateShow( const wxRect& rect, int flags ) | |
779 | { | |
780 | if ( GetUserPreferencesMask() & wxMSW_DESKTOP_USERPREFERENCESMASK_COMBOBOXANIM ) | |
781 | { | |
782 | m_animStart = ::wxGetLocalTimeMillis(); | |
783 | m_animRect = rect; | |
784 | m_animFlags = flags; | |
785 | ||
786 | wxWindow* win = GetPopupWindow(); | |
787 | win->SetSize( rect.x, rect.y, rect.width, 0 ); | |
788 | win->Show(); | |
789 | ||
790 | m_animTimer.SetOwner( this, wxID_ANY ); | |
791 | m_animTimer.Start( COMBOBOX_ANIMATION_RESOLUTION, wxTIMER_CONTINUOUS ); | |
792 | ||
952555f7 | 793 | DoTimerEvent(); |
30be036c RR |
794 | |
795 | return false; | |
796 | } | |
797 | ||
974a12f8 RR |
798 | return true; |
799 | } | |
30be036c | 800 | #endif |
974a12f8 | 801 | |
a57d600f | 802 | wxCoord wxComboCtrl::GetNativeTextIndent() const |
a340b80d | 803 | { |
f100b1c3 | 804 | #if wxUSE_UXTHEME |
a340b80d VZ |
805 | if ( wxUxThemeEngine::GetIfActive() ) |
806 | return NATIVE_TEXT_INDENT_XP; | |
f100b1c3 | 807 | #endif |
a340b80d VZ |
808 | return NATIVE_TEXT_INDENT_CLASSIC; |
809 | } | |
810 | ||
b445b6a7 VZ |
811 | bool wxComboCtrl::IsKeyPopupToggle(const wxKeyEvent& event) const |
812 | { | |
9e68717c | 813 | const bool isPopupShown = IsPopupShown(); |
b445b6a7 | 814 | |
9e68717c | 815 | switch ( event.GetKeyCode() ) |
b445b6a7 | 816 | { |
9e68717c VZ |
817 | case WXK_F4: |
818 | // F4 toggles the popup in the native comboboxes, so emulate them | |
819 | if ( !event.AltDown() ) | |
820 | return true; | |
821 | break; | |
822 | ||
823 | case WXK_ESCAPE: | |
824 | if ( isPopupShown ) | |
825 | return true; | |
826 | break; | |
827 | ||
828 | case WXK_DOWN: | |
829 | case WXK_UP: | |
293987e8 VS |
830 | case WXK_NUMPAD_DOWN: |
831 | case WXK_NUMPAD_UP: | |
87b37087 JS |
832 | // Arrow keys (and mouse wheel) toggle the popup in the native |
833 | // combo boxes | |
834 | if ( event.AltDown() ) | |
9e68717c | 835 | return true; |
9e68717c | 836 | break; |
b445b6a7 VZ |
837 | } |
838 | ||
839 | return false; | |
840 | } | |
a340b80d | 841 | |
a57d600f | 842 | #endif // wxUSE_COMBOCTRL |