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