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