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