]> git.saurik.com Git - wxWidgets.git/blob - src/msw/listbox.cpp
Cured problem introduced by LEAVE/ENTER OnIdle code; bugs in gauge sizing
[wxWidgets.git] / src / msw / listbox.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: listbox.cpp
3 // Purpose: wxListBox
4 // Author: Julian Smart
5 // Modified by: Vadim Zeitlin (owner drawn stuff)
6 // Created:
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "listbox.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/listbox.h"
25 #include "wx/settings.h"
26 #endif
27
28 #include "wx/msw/private.h"
29
30 #include <windows.h>
31 #include <windowsx.h>
32
33 #ifdef __GNUWIN32__
34 #include <wx/msw/gnuwin32/extra.h>
35 #endif
36
37 #ifdef GetCharWidth
38 #undef GetCharWidth
39 #endif
40
41 #if USE_OWNER_DRAWN
42 #include "wx/ownerdrw.h"
43 #endif
44
45 #include "wx/dynarray.h"
46 #include "wx/log.h"
47
48 #if !USE_SHARED_LIBRARY
49 IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl)
50 #endif
51
52 // ============================================================================
53 // list box item declaration and implementation
54 // ============================================================================
55
56 #if USE_OWNER_DRAWN
57
58 class wxListBoxItem : public wxOwnerDrawn
59 {
60 public:
61 wxListBoxItem(const wxString& str = "");
62 };
63
64 wxListBoxItem::wxListBoxItem(const wxString& str) : wxOwnerDrawn(str, FALSE)
65 {
66 // no bitmaps/checkmarks
67 SetMarginWidth(0);
68 }
69
70 wxOwnerDrawn *wxListBox::CreateItem(uint n)
71 {
72 return new wxListBoxItem();
73 }
74
75 #endif //USE_OWNER_DRAWN
76
77 // ============================================================================
78 // list box control implementation
79 // ============================================================================
80
81 // this macro is dangerous but still better than tons of (HWND)GetHWND()
82 #define hwnd (HWND)GetHWND()
83
84 bool wxListBox::MSWCommand(const WXUINT param, const WXWORD WXUNUSED(id))
85 {
86 /*
87 if (param == LBN_SELCANCEL)
88 {
89 event.extraLong = FALSE;
90 }
91 */
92 if (param == LBN_SELCHANGE)
93 {
94 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId);
95 wxArrayInt aSelections;
96 int count = GetSelections(aSelections);
97 if ( count > 0 )
98 {
99 event.m_commandInt = aSelections[0] ;
100 event.m_clientData = GetClientData(event.m_commandInt);
101 wxString str(GetString(event.m_commandInt));
102 if (str != "")
103 event.m_commandString = copystring((char *)(const char *)str);
104 }
105 else
106 {
107 event.m_commandInt = -1 ;
108 event.m_commandString = copystring("") ;
109 }
110
111 event.SetEventObject( this );
112 ProcessCommand(event);
113 if (event.m_commandString)
114 delete[] event.m_commandString ;
115 return TRUE;
116 }
117 else if (param == LBN_DBLCLK)
118 {
119 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, m_windowId);
120 event.SetEventObject( this );
121 if ( !GetEventHandler()->ProcessEvent(event) )
122 {
123 #if WXWIN_COMPATIBILITY
124 wxWindow *parent = (wxWindow *)GetParent();
125 if (parent)
126 parent->GetEventHandler()->OnDefaultAction(this);
127 #endif
128 return TRUE;
129 }
130 }
131 return FALSE;
132 }
133
134 // Listbox item
135 wxListBox::wxListBox(void)
136 {
137 m_noItems = 0;
138 m_selected = 0;
139 }
140
141 bool wxListBox::Create(wxWindow *parent, const wxWindowID id,
142 const wxPoint& pos,
143 const wxSize& size,
144 const int n, const wxString choices[],
145 const long style,
146 const wxValidator& validator,
147 const wxString& name)
148 {
149 m_noItems = n;
150 m_hWnd = 0;
151 m_selected = 0;
152
153 SetName(name);
154 SetValidator(validator);
155
156 if (parent) parent->AddChild(this);
157
158 wxSystemSettings settings;
159 SetBackgroundColour(settings.GetSystemColour(wxSYS_COLOUR_WINDOW));
160 SetForegroundColour(parent->GetDefaultForegroundColour());
161
162 m_windowId = ( id == -1 ) ? (int)NewControlId() : id;
163
164 int x = pos.x;
165 int y = pos.y;
166 int width = size.x;
167 int height = size.y;
168 m_windowStyle = style;
169
170 DWORD wstyle = WS_VSCROLL | WS_TABSTOP | LBS_NOTIFY | LBS_HASSTRINGS;
171 if (m_windowStyle & wxLB_MULTIPLE)
172 wstyle |= LBS_MULTIPLESEL;
173 else if (m_windowStyle & wxLB_EXTENDED)
174 wstyle |= LBS_EXTENDEDSEL;
175
176 if (m_windowStyle & wxLB_ALWAYS_SB)
177 wstyle |= LBS_DISABLENOSCROLL ;
178 if (m_windowStyle & wxLB_HSCROLL)
179 wstyle |= WS_HSCROLL;
180 if (m_windowStyle & wxLB_SORT)
181 wstyle |= LBS_SORT;
182
183 #if USE_OWNER_DRAWN
184 if ( m_windowStyle & wxLB_OWNERDRAW ) {
185 // we don't support LBS_OWNERDRAWVARIABLE yet
186 wstyle |= LBS_OWNERDRAWFIXED;
187 }
188 #endif
189 // Without this style, you get unexpected heights, so e.g. constraint layout
190 // doesn't work properly
191 wstyle |= LBS_NOINTEGRALHEIGHT;
192
193 bool want3D;
194 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ;
195
196 // Even with extended styles, need to combine with WS_BORDER
197 // for them to look right.
198 if ( want3D || (m_windowStyle & wxSIMPLE_BORDER)
199 || (m_windowStyle & wxRAISED_BORDER)
200 || (m_windowStyle & wxSUNKEN_BORDER)
201 || (m_windowStyle & wxDOUBLE_BORDER) ) {
202 wstyle |= WS_BORDER;
203 }
204
205 HWND wx_list = CreateWindowEx(exStyle, "LISTBOX", NULL,
206 wstyle | WS_CHILD,
207 0, 0, 0, 0,
208 (HWND)parent->GetHWND(), (HMENU)m_windowId,
209 wxGetInstance(), NULL);
210
211 m_hWnd = (WXHWND)wx_list;
212
213 #if CTL3D
214 if (want3D)
215 {
216 Ctl3dSubclassCtl(wx_list);
217 m_useCtl3D = TRUE;
218 }
219 #endif
220
221 // Subclass again to catch messages
222 SubclassWin((WXHWND)wx_list);
223
224 uint ui;
225 for (ui = 0; ui < (uint)n; ui++) {
226 SendMessage(wx_list, LB_ADDSTRING, 0, (LPARAM)(const char *)choices[ui]);
227 }
228
229 #if USE_OWNER_DRAWN
230 if ( m_windowStyle & wxLB_OWNERDRAW ) {
231 for (ui = 0; ui < (uint)n; ui++) {
232 // create new item which will process WM_{DRAW|MEASURE}ITEM messages
233 wxOwnerDrawn *pNewItem = CreateItem(ui);
234 pNewItem->SetName(choices[ui]);
235 m_aItems.Add(pNewItem);
236 ListBox_SetItemData(wx_list, ui, pNewItem);
237 }
238 }
239 #endif
240
241 if ((m_windowStyle & wxLB_MULTIPLE) == 0)
242 SendMessage(wx_list, LB_SETCURSEL, 0, 0);
243
244 SetFont(* parent->GetFont());
245
246 SetSize(x, y, width, height);
247
248 ShowWindow(wx_list, SW_SHOW);
249
250 return TRUE;
251 }
252
253 wxListBox::~wxListBox(void)
254 {
255 #if USE_OWNER_DRAWN
256 uint uiCount = m_aItems.Count();
257 while ( uiCount-- != 0 ) {
258 delete m_aItems[uiCount];
259 }
260 #endif
261
262 DELETEA(m_selections);
263 }
264
265 void wxListBox::SetupColours(void)
266 {
267 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW));
268 SetForegroundColour(GetParent()->GetDefaultForegroundColour());
269 }
270
271 void wxListBox::SetFirstItem(const int N)
272 {
273 SendMessage(hwnd,LB_SETTOPINDEX,(WPARAM)N,(LPARAM)0) ;
274 }
275
276 void wxListBox::SetFirstItem(const wxString& s)
277 {
278 int N = FindString(s) ;
279
280 if (N>=0)
281 SetFirstItem(N) ;
282 }
283
284 void wxListBox::Delete(const int N)
285 {
286 SendMessage(hwnd, LB_DELETESTRING, N, 0);
287 m_noItems --;
288 SetHorizontalExtent("");
289 }
290
291 void wxListBox::Append(const wxString& item)
292 {
293 int index = ListBox_AddString(hwnd, item);
294 m_noItems ++;
295
296 #if USE_OWNER_DRAWN
297 if ( m_windowStyle & wxLB_OWNERDRAW ) {
298 wxOwnerDrawn *pNewItem = CreateItem(-1); // dummy argument
299 pNewItem->SetName(item);
300 m_aItems.Add(pNewItem);
301 ListBox_SetItemData(hwnd, index, pNewItem);
302 }
303 #endif
304
305 SetHorizontalExtent(item);
306 }
307
308 void wxListBox::Append(const wxString& item, char *Client_data)
309 {
310 int index = ListBox_AddString(hwnd, item);
311 m_noItems ++;
312
313 #if USE_OWNER_DRAWN
314 if ( m_windowStyle & wxLB_OWNERDRAW ) {
315 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
316 // in OnMeasure/OnDraw.
317 wxFAIL_MSG("Can't use client data with owner-drawn listboxes");
318 }
319 else
320 #endif
321 ListBox_SetItemData(hwnd, index, Client_data);
322
323 SetHorizontalExtent(item);
324 }
325
326 void wxListBox::Set(const int n, const wxString *choices, char** clientData)
327 {
328 ShowWindow(hwnd, SW_HIDE);
329 ListBox_ResetContent(hwnd);
330 int i;
331 for (i = 0; i < n; i++)
332 {
333 ListBox_AddString(hwnd, choices[i]);
334 if ( clientData )
335 ListBox_SetItemData(hwnd, i, clientData[i]);
336 }
337 m_noItems = n;
338
339 #if USE_OWNER_DRAWN
340 if ( m_windowStyle & wxLB_OWNERDRAW ) {
341 // first delete old items
342 uint ui = m_aItems.Count();
343 while ( ui-- != 0 ) {
344 delete m_aItems[ui];
345 }
346 m_aItems.Empty();
347
348 // then create new ones
349 for (ui = 0; ui < (uint)n; ui++) {
350 wxOwnerDrawn *pNewItem = CreateItem(ui);
351 pNewItem->SetName(choices[ui]);
352 m_aItems.Add(pNewItem);
353 ListBox_SetItemData(hwnd, ui, pNewItem);
354
355 wxASSERT_MSG(clientData[ui] == NULL,
356 "Can't use client data with owner-drawn listboxes");
357 }
358 }
359 #endif
360
361 SetHorizontalExtent("");
362 ShowWindow(hwnd, SW_SHOW);
363 }
364
365 int wxListBox::FindString(const wxString& s) const
366 {
367 int pos = ListBox_FindStringExact(hwnd, (WPARAM)-1, s);
368 if (pos == LB_ERR)
369 return -1;
370 else
371 return pos;
372 }
373
374 void wxListBox::Clear(void)
375 {
376 ListBox_ResetContent(hwnd);
377
378 m_noItems = 0;
379 ListBox_GetHorizontalExtent(hwnd);
380 }
381
382 void wxListBox::SetSelection(const int N, const bool select)
383 {
384 if ((m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED))
385 SendMessage(hwnd, LB_SETSEL, select, N);
386 else
387 {
388 int N1 = N;
389 if (!select)
390 N1 = -1;
391 SendMessage(hwnd, LB_SETCURSEL, N1, 0);
392 }
393 }
394
395 bool wxListBox::Selected(const int N) const
396 {
397 return SendMessage(hwnd, LB_GETSEL, N, 0) == 0 ? FALSE : TRUE;
398 }
399
400 void wxListBox::Deselect(const int N)
401 {
402 if ((m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED))
403 SendMessage(hwnd, LB_SETSEL, FALSE, N);
404 }
405
406 char *wxListBox::GetClientData(const int N) const
407 {
408 return (char *)SendMessage(hwnd, LB_GETITEMDATA, N, 0);
409 }
410
411 void wxListBox::SetClientData(const int N, char *Client_data)
412 {
413 if ( ListBox_SetItemData(hwnd, N, Client_data) == LB_ERR )
414 wxLogDebug("LB_SETITEMDATA failed");
415 }
416
417 // Return number of selections and an array of selected integers
418 int wxListBox::GetSelections(wxArrayInt& aSelections) const
419 {
420 aSelections.Empty();
421
422 if ((m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED))
423 {
424 int no_sel = ListBox_GetSelCount(hwnd);
425 if (no_sel != 0) {
426 int *selections = new int[no_sel];
427 if ( ListBox_GetSelItems(hwnd, no_sel, selections) == LB_ERR ) {
428 wxFAIL_MSG("This listbox can't have single-selection style!");
429 }
430
431 aSelections.Alloc(no_sel);
432 for ( int n = 0; n < no_sel; n++ )
433 aSelections.Add(selections[n]);
434
435 delete [] selections;
436 }
437
438 return no_sel;
439 }
440 else // single-selection listbox
441 {
442 aSelections.Add(ListBox_GetCurSel(hwnd));
443
444 return 1;
445 }
446 }
447
448 // Get single selection, for single choice list items
449 int wxListBox::GetSelection() const
450 {
451 wxCHECK_MSG( !(m_windowStyle & wxLB_MULTIPLE) &&
452 !(m_windowStyle & wxLB_EXTENDED),
453 -1,
454 "GetSelection() can't be used with multiple-selection "
455 "listboxes, use GetSelections() instead." );
456
457 return ListBox_GetCurSel(hwnd);
458 }
459
460 // Find string for position
461 wxString wxListBox::GetString(const int N) const
462 {
463 if (N < 0 || N > m_noItems)
464 return wxString("");
465
466 int len = (int)SendMessage(hwnd, LB_GETTEXT, N, (LONG)wxBuffer);
467 wxBuffer[len] = 0;
468 return wxString(wxBuffer);
469 }
470
471 void wxListBox::SetSize(const int x, const int y, const int width, const int height, const int sizeFlags)
472 {
473 int currentX, currentY;
474 GetPosition(&currentX, &currentY);
475
476 int x1 = x;
477 int y1 = y;
478 int w1 = width;
479 int h1 = height;
480
481 if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
482 x1 = currentX;
483 if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
484 y1 = currentY;
485
486 // If we're prepared to use the existing size, then...
487 if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
488 {
489 GetSize(&w1, &h1);
490 }
491
492 int cx; // button font dimensions
493 int cy;
494
495 wxGetCharSize(GetHWND(), &cx, &cy,GetFont());
496
497 float control_width, control_height, control_x, control_y;
498
499 // Deal with default size (using -1 values)
500 if (w1<=0)
501 w1 = DEFAULT_ITEM_WIDTH;
502
503 if (h1<=0)
504 h1 = DEFAULT_ITEM_HEIGHT;
505
506 control_x = (float)x1;
507 control_y = (float)y1;
508 control_width = (float)w1;
509 control_height = (float)h1;
510
511 // Calculations may have made size too small
512 if (control_height <= 0)
513 control_height = (float)DEFAULT_ITEM_HEIGHT;
514
515 if (control_width <= 0)
516 control_width = (float)DEFAULT_ITEM_WIDTH;
517
518 // wxDebugMsg("About to set the listbox height to %d", (int)control_height);
519 MoveWindow(hwnd, (int)control_x, (int)control_y,
520 (int)control_width, (int)control_height, TRUE);
521
522 /*
523 #if WXWIN_COMPATIBILITY
524 GetEventHandler()->OldOnSize(width, height);
525 #else
526 wxSizeEvent event(wxSize(width, height), m_windowId);
527 event.eventObject = this;
528 GetEventHandler()->ProcessEvent(event);
529 #endif
530 */
531
532 }
533
534 // Windows-specific code to set the horizontal extent of
535 // the listbox, if necessary. If s is non-NULL, it's
536 // used to calculate the horizontal extent.
537 // Otherwise, all strings are used.
538 void wxListBox::SetHorizontalExtent(const wxString& s)
539 {
540 // Only necessary if we want a horizontal scrollbar
541 if (!(m_windowStyle & wxHSCROLL))
542 return;
543 TEXTMETRIC lpTextMetric;
544
545 if (s != "")
546 {
547 int existingExtent = (int)SendMessage(hwnd, LB_GETHORIZONTALEXTENT, 0, 0L);
548 HDC dc = GetWindowDC(hwnd);
549 HFONT oldFont = 0;
550 if (GetFont() && GetFont()->GetResourceHandle())
551 oldFont = ::SelectObject(dc, (HFONT) GetFont()->GetResourceHandle());
552
553 GetTextMetrics(dc, &lpTextMetric);
554 SIZE extentXY;
555 ::GetTextExtentPoint(dc, (LPSTR) (const char *)s, s.Length(), &extentXY);
556 int extentX = (int)(extentXY.cx + lpTextMetric.tmAveCharWidth);
557
558 if (oldFont)
559 ::SelectObject(dc, oldFont);
560
561 ReleaseDC(hwnd, dc);
562 if (extentX > existingExtent)
563 SendMessage(hwnd, LB_SETHORIZONTALEXTENT, LOWORD(extentX), 0L);
564 return;
565 }
566 else
567 {
568 int largestExtent = 0;
569 HDC dc = GetWindowDC(hwnd);
570 HFONT oldFont = 0;
571 if (GetFont() && GetFont()->GetResourceHandle())
572 oldFont = ::SelectObject(dc, (HFONT) GetFont()->GetResourceHandle());
573
574 GetTextMetrics(dc, &lpTextMetric);
575 int i;
576 for (i = 0; i < m_noItems; i++)
577 {
578 int len = (int)SendMessage(hwnd, LB_GETTEXT, i, (LONG)wxBuffer);
579 wxBuffer[len] = 0;
580 SIZE extentXY;
581 ::GetTextExtentPoint(dc, (LPSTR)wxBuffer, len, &extentXY);
582 int extentX = (int)(extentXY.cx + lpTextMetric.tmAveCharWidth);
583 if (extentX > largestExtent)
584 largestExtent = extentX;
585 }
586 if (oldFont)
587 ::SelectObject(dc, oldFont);
588
589 ReleaseDC(hwnd, dc);
590 SendMessage(hwnd, LB_SETHORIZONTALEXTENT, LOWORD(largestExtent), 0L);
591 }
592 }
593
594 void
595 wxListBox::InsertItems(const int nItems, const wxString items[], const int pos)
596 {
597 int i;
598 for (i = 0; i < nItems; i++)
599 ListBox_InsertString(hwnd, i + pos, items[i]);
600 m_noItems += nItems;
601
602 #if USE_OWNER_DRAWN
603 if ( m_windowStyle & wxLB_OWNERDRAW ) {
604 for ( i = 0; i < nItems; i++ ) {
605 wxOwnerDrawn *pNewItem = CreateItem((uint)(pos + i));
606 pNewItem->SetName(items[i]);
607 m_aItems.Insert(pNewItem, (uint)(pos + i));
608 ListBox_SetItemData(hwnd, i, pNewItem);
609 }
610 }
611 #endif
612
613 SetHorizontalExtent("");
614 }
615
616 void wxListBox::SetString(const int N, const wxString& s)
617 {
618 int sel = GetSelection();
619
620 char *oldData = (char *)wxListBox::GetClientData(N);
621
622 SendMessage(hwnd, LB_DELETESTRING, N, 0);
623
624 int newN = N;
625 if (N == (m_noItems - 1))
626 newN = -1;
627
628 SendMessage(hwnd, LB_INSERTSTRING, newN, (LPARAM) (const char *)s);
629 if (oldData)
630 wxListBox::SetClientData(N, oldData);
631
632 // Selection may have changed
633 if (sel >= 0)
634 SetSelection(sel);
635
636 #if USE_OWNER_DRAWN
637 if ( m_windowStyle & wxLB_OWNERDRAW )
638 // update item's text
639 m_aItems[N]->SetName(s);
640 #endif //USE_OWNER_DRAWN
641 }
642
643 int wxListBox::Number (void) const
644 {
645 return m_noItems;
646 }
647
648 // For single selection items only
649 wxString wxListBox::GetStringSelection (void) const
650 {
651 int sel = GetSelection ();
652 if (sel > -1)
653 return this->GetString (sel);
654 else
655 return wxString("");
656 }
657
658 bool wxListBox::SetStringSelection (const wxString& s, const bool flag)
659 {
660 int sel = FindString (s);
661 if (sel > -1)
662 {
663 SetSelection (sel, flag);
664 return TRUE;
665 }
666 else
667 return FALSE;
668 }
669
670 // Is this the right thing? Won't setselection generate a command
671 // event too? No! It'll just generate a setselection event.
672 // But we still can't have this being called whenever a real command
673 // is generated, because it sets the selection, which will already
674 // have been done! (Unless we have an optional argument for calling
675 // by the actual window system, or a separate function, ProcessCommand)
676 void wxListBox::Command (wxCommandEvent & event)
677 {
678 if (event.m_extraLong)
679 SetSelection (event.m_commandInt);
680 else
681 {
682 Deselect (event.m_commandInt);
683 return;
684 }
685 ProcessCommand (event);
686 }
687
688 WXHBRUSH wxListBox::OnCtlColor(const WXHDC pDC, const WXHWND pWnd, const WXUINT nCtlColor,
689 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
690 {
691 #if CTL3D
692 if ( m_useCtl3D )
693 {
694 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
695 return (WXHBRUSH) hbrush;
696 }
697 #endif
698
699 if (GetParent()->GetTransparentBackground())
700 SetBkMode((HDC) pDC, TRANSPARENT);
701 else
702 SetBkMode((HDC) pDC, OPAQUE);
703
704 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
705 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
706
707 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
708
709 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
710 // has a zero usage count.
711 backgroundBrush->RealizeResource();
712 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
713 }
714
715 long wxListBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
716 {
717 switch (nMsg)
718 {
719 case WM_INITDIALOG:
720 case WM_ACTIVATE:
721 case WM_SETFOCUS:
722 case WM_KILLFOCUS:
723 case WM_CREATE:
724 case WM_PAINT:
725 case WM_QUERYDRAGICON:
726 case WM_SIZE:
727 case WM_RBUTTONDOWN:
728 case WM_RBUTTONUP:
729 case WM_RBUTTONDBLCLK:
730 case WM_MBUTTONDOWN:
731 case WM_MBUTTONUP:
732 case WM_MBUTTONDBLCLK:
733 case WM_LBUTTONDOWN:
734 case WM_LBUTTONUP:
735 case WM_LBUTTONDBLCLK:
736 case WM_MOUSEMOVE:
737 case WM_DESTROY:
738 case WM_COMMAND:
739 case WM_NOTIFY:
740 case WM_MENUSELECT:
741 case WM_INITMENUPOPUP:
742 case WM_DRAWITEM:
743 case WM_MEASUREITEM:
744 case WM_KEYDOWN:
745 case WM_KEYUP:
746 case WM_CHAR: // Always an ASCII character
747 case WM_HSCROLL:
748 case WM_VSCROLL:
749 case WM_CTLCOLORBTN:
750 case WM_CTLCOLORDLG:
751 case WM_CTLCOLORLISTBOX:
752 case WM_CTLCOLORMSGBOX:
753 case WM_CTLCOLORSCROLLBAR:
754 case WM_CTLCOLORSTATIC:
755 case WM_CTLCOLOREDIT:
756 case WM_SYSCOLORCHANGE:
757 case WM_ERASEBKGND:
758 case WM_MDIACTIVATE:
759 case WM_DROPFILES:
760 case WM_QUERYENDSESSION:
761 case WM_CLOSE:
762 case WM_GETMINMAXINFO:
763 case WM_NCHITTEST:
764 return MSWDefWindowProc(nMsg, wParam, lParam );
765 }
766 return wxControl::MSWWindowProc(nMsg, wParam, lParam);
767 }
768
769 #if USE_OWNER_DRAWN
770
771 // drawing
772 // -------
773
774 // space beneath/above each row in pixels
775 // "standard" checklistbox use 1 here, some might prefer 2. 0 is ugly.
776 #define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1)
777
778 // the height is the same for all items
779 // ## should be changed for LBS_OWNERDRAWVARIABLE style listboxes
780 // NB: can't forward this to wxListBoxItem because LB_SETITEMDATA
781 // message is not yet sent when we get here!
782 bool wxListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT *item)
783 {
784 // only owner-drawn control should receive this message
785 wxCHECK( ((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), FALSE );
786
787 MEASUREITEMSTRUCT *pStruct = (MEASUREITEMSTRUCT *)item;
788
789 wxDC dc;
790 dc.SetHDC((WXHDC)CreateIC("DISPLAY", NULL, NULL, 0));
791 dc.SetFont(wxSystemSettings::GetSystemFont(wxSYS_ANSI_VAR_FONT));
792
793 pStruct->itemHeight = dc.GetCharHeight() + 2*OWNER_DRAWN_LISTBOX_EXTRA_SPACE;
794 pStruct->itemWidth = dc.GetCharWidth();
795
796 return TRUE;
797 }
798
799 // forward the message to the appropriate item
800 bool wxListBox::MSWOnDraw(WXDRAWITEMSTRUCT *item)
801 {
802 // only owner-drawn control should receive this message
803 wxCHECK( ((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), FALSE );
804
805 DRAWITEMSTRUCT *pStruct = (DRAWITEMSTRUCT *)item;
806 wxListBoxItem *pItem = (wxListBoxItem *)SendMessage(hwnd, LB_GETITEMDATA,
807 pStruct->itemID, 0);
808
809 wxCHECK( (int)pItem != LB_ERR, FALSE );
810
811 wxDC dc;
812 dc.SetHDC((WXHDC)pStruct->hDC, FALSE);
813 wxRect rect(pStruct->rcItem.left, pStruct->rcItem.top,
814 pStruct->rcItem.right - pStruct->rcItem.left,
815 pStruct->rcItem.bottom - pStruct->rcItem.top);
816
817 return pItem->OnDrawItem(dc, rect,
818 (wxOwnerDrawn::wxODAction)pStruct->itemAction,
819 (wxOwnerDrawn::wxODStatus)pStruct->itemState);
820 }
821
822 #endif
823 // USE_OWNER_DRAWN