]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/os2/listbox.cpp | |
3 | // Purpose: wxListBox | |
4 | // Author: David Webster | |
5 | // Modified by: | |
6 | // Created: 10/09/99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) David Webster | |
9 | // Licence: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // For compilers that support precompilation, includes "wx.h". | |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #if wxUSE_LISTBOX | |
16 | ||
17 | #include "wx/listbox.h" | |
18 | ||
19 | #ifndef WX_PRECOMP | |
20 | #include "wx/dynarray.h" | |
21 | #include "wx/settings.h" | |
22 | #include "wx/brush.h" | |
23 | #include "wx/font.h" | |
24 | #include "wx/dc.h" | |
25 | #include "wx/dcscreen.h" | |
26 | #include "wx/utils.h" | |
27 | #include "wx/scrolwin.h" | |
28 | #include "wx/log.h" | |
29 | #include "wx/window.h" | |
30 | #endif | |
31 | ||
32 | #include "wx/os2/dcclient.h" | |
33 | #include "wx/os2/private.h" | |
34 | ||
35 | #define INCL_M | |
36 | #include <os2.h> | |
37 | ||
38 | #if wxUSE_OWNER_DRAWN | |
39 | #include "wx/ownerdrw.h" | |
40 | #endif | |
41 | ||
42 | IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControlWithItems) | |
43 | ||
44 | // ============================================================================ | |
45 | // list box item declaration and implementation | |
46 | // ============================================================================ | |
47 | ||
48 | #if wxUSE_OWNER_DRAWN | |
49 | ||
50 | class wxListBoxItem : public wxOwnerDrawn | |
51 | { | |
52 | public: | |
53 | wxListBoxItem(wxListBox *parent) | |
54 | { m_parent = parent; } | |
55 | ||
56 | wxListBox *GetParent() const | |
57 | { return m_parent; } | |
58 | ||
59 | int GetIndex() const | |
60 | { return m_parent->GetItemIndex(const_cast<wxListBoxItem*>(this)); } | |
61 | ||
62 | wxString GetName() const | |
63 | { return m_parent->GetString(GetIndex()); } | |
64 | ||
65 | private: | |
66 | wxListBox *m_parent; | |
67 | }; | |
68 | ||
69 | wxOwnerDrawn* wxListBox::CreateItem( size_t WXUNUSED(n) ) | |
70 | { | |
71 | return new wxListBoxItem(this); | |
72 | } // end of wxListBox::CreateItem | |
73 | ||
74 | #endif //USE_OWNER_DRAWN | |
75 | ||
76 | // ============================================================================ | |
77 | // list box control implementation | |
78 | // ============================================================================ | |
79 | ||
80 | // Listbox item | |
81 | wxListBox::wxListBox() | |
82 | { | |
83 | m_nNumItems = 0; | |
84 | m_nSelected = 0; | |
85 | } // end of wxListBox::wxListBox | |
86 | ||
87 | bool wxListBox::Create( | |
88 | wxWindow* pParent | |
89 | , wxWindowID vId | |
90 | , const wxPoint& rPos | |
91 | , const wxSize& rSize | |
92 | , const wxArrayString& asChoices | |
93 | , long lStyle | |
94 | , const wxValidator& rValidator | |
95 | , const wxString& rsName | |
96 | ) | |
97 | { | |
98 | wxCArrayString chs(asChoices); | |
99 | ||
100 | return Create(pParent, vId, rPos, rSize, chs.GetCount(), chs.GetStrings(), | |
101 | lStyle, rValidator, rsName); | |
102 | } | |
103 | ||
104 | bool wxListBox::Create( wxWindow* pParent, | |
105 | wxWindowID vId, | |
106 | const wxPoint& rPos, | |
107 | const wxSize& rSize, | |
108 | int n, | |
109 | const wxString asChoices[], | |
110 | long lStyle, | |
111 | const wxValidator& rValidator, | |
112 | const wxString& rsName ) | |
113 | { | |
114 | m_nNumItems = 0; | |
115 | m_hWnd = 0; | |
116 | m_nSelected = 0; | |
117 | ||
118 | SetName(rsName); | |
119 | #if wxUSE_VALIDATORS | |
120 | SetValidator(rValidator); | |
121 | #endif | |
122 | ||
123 | if (pParent) | |
124 | pParent->AddChild(this); | |
125 | ||
126 | wxSystemSettings vSettings; | |
127 | ||
128 | SetBackgroundColour(vSettings.GetColour(wxSYS_COLOUR_WINDOW)); | |
129 | SetForegroundColour(pParent->GetForegroundColour()); | |
130 | ||
131 | m_windowId = (vId == -1) ? (int)NewControlId() : vId; | |
132 | ||
133 | int nX = rPos.x; | |
134 | int nY = rPos.y; | |
135 | int nWidth = rSize.x; | |
136 | int nHeight = rSize.y; | |
137 | ||
138 | m_windowStyle = lStyle; | |
139 | ||
140 | lStyle = WS_VISIBLE; | |
141 | ||
142 | if (m_windowStyle & wxCLIP_SIBLINGS ) | |
143 | lStyle |= WS_CLIPSIBLINGS; | |
144 | if (m_windowStyle & wxLB_MULTIPLE) | |
145 | lStyle |= LS_MULTIPLESEL; | |
146 | else if (m_windowStyle & wxLB_EXTENDED) | |
147 | lStyle |= LS_EXTENDEDSEL; | |
148 | if (m_windowStyle & wxLB_HSCROLL) | |
149 | lStyle |= LS_HORZSCROLL; | |
150 | if (m_windowStyle & wxLB_OWNERDRAW) | |
151 | lStyle |= LS_OWNERDRAW; | |
152 | ||
153 | // | |
154 | // Without this style, you get unexpected heights, so e.g. constraint layout | |
155 | // doesn't work properly | |
156 | // | |
157 | lStyle |= LS_NOADJUSTPOS; | |
158 | ||
159 | m_hWnd = (WXHWND)::WinCreateWindow( GetWinHwnd(pParent) // Parent | |
160 | ,WC_LISTBOX // Default Listbox class | |
161 | ,"LISTBOX" // Control's name | |
162 | ,lStyle // Initial Style | |
163 | ,0, 0, 0, 0 // Position and size | |
164 | ,GetWinHwnd(pParent) // Owner | |
165 | ,HWND_TOP // Z-Order | |
166 | ,(HMENU)m_windowId // Id | |
167 | ,NULL // Control Data | |
168 | ,NULL // Presentation Parameters | |
169 | ); | |
170 | if (m_hWnd == 0) | |
171 | { | |
172 | return false; | |
173 | } | |
174 | ||
175 | // | |
176 | // Subclass again for purposes of dialog editing mode | |
177 | // | |
178 | SubclassWin(m_hWnd); | |
179 | ||
180 | LONG lUi; | |
181 | ||
182 | for (lUi = 0; lUi < (LONG)n; lUi++) | |
183 | { | |
184 | Append(asChoices[lUi]); | |
185 | } | |
186 | wxFont* pTextFont = new wxFont( 10 | |
187 | ,wxMODERN | |
188 | ,wxNORMAL | |
189 | ,wxNORMAL | |
190 | ); | |
191 | SetFont(*pTextFont); | |
192 | ||
193 | // | |
194 | // Set OS/2 system colours for Listbox items and highlighting | |
195 | // | |
196 | wxColour vColour; | |
197 | ||
198 | vColour = wxSystemSettingsNative::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); | |
199 | ||
200 | LONG lColor = (LONG)vColour.GetPixel(); | |
201 | ||
202 | ::WinSetPresParam( m_hWnd | |
203 | ,PP_HILITEFOREGROUNDCOLOR | |
204 | ,sizeof(LONG) | |
205 | ,(PVOID)&lColor | |
206 | ); | |
207 | vColour = wxSystemSettingsNative::GetColour(wxSYS_COLOUR_HIGHLIGHT); | |
208 | lColor = (LONG)vColour.GetPixel(); | |
209 | ::WinSetPresParam( m_hWnd | |
210 | ,PP_HILITEBACKGROUNDCOLOR | |
211 | ,sizeof(LONG) | |
212 | ,(PVOID)&lColor | |
213 | ); | |
214 | ||
215 | SetXComp(0); | |
216 | SetYComp(0); | |
217 | SetSize( nX | |
218 | ,nY | |
219 | ,nWidth | |
220 | ,nHeight | |
221 | ); | |
222 | delete pTextFont; | |
223 | return true; | |
224 | } // end of wxListBox::Create | |
225 | ||
226 | wxListBox::~wxListBox() | |
227 | { | |
228 | Clear(); | |
229 | } // end of wxListBox::~wxListBox | |
230 | ||
231 | void wxListBox::SetupColours() | |
232 | { | |
233 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); | |
234 | SetForegroundColour(GetParent()->GetForegroundColour()); | |
235 | } // end of wxListBox::SetupColours | |
236 | ||
237 | // ---------------------------------------------------------------------------- | |
238 | // implementation of wxListBoxBase methods | |
239 | // ---------------------------------------------------------------------------- | |
240 | ||
241 | void wxListBox::DoSetFirstItem(int N) | |
242 | { | |
243 | wxCHECK_RET( IsValid(N), | |
244 | wxT("invalid index in wxListBox::SetFirstItem") ); | |
245 | ||
246 | ::WinSendMsg(GetHwnd(), LM_SETTOPINDEX, MPFROMLONG(N), (MPARAM)0); | |
247 | } // end of wxListBox::DoSetFirstItem | |
248 | ||
249 | void wxListBox::DoDeleteOneItem(unsigned int n) | |
250 | { | |
251 | wxCHECK_RET( IsValid(n), | |
252 | wxT("invalid index in wxListBox::Delete") ); | |
253 | ||
254 | #if wxUSE_OWNER_DRAWN | |
255 | delete m_aItems[n]; | |
256 | m_aItems.RemoveAt(n); | |
257 | #endif // wxUSE_OWNER_DRAWN | |
258 | ||
259 | ::WinSendMsg(GetHwnd(), LM_DELETEITEM, (MPARAM)n, (MPARAM)0); | |
260 | m_nNumItems--; | |
261 | } // end of wxListBox::DoSetFirstItem | |
262 | ||
263 | int wxListBox::DoInsertItems(const wxArrayStringsAdapter & items, | |
264 | unsigned int pos, | |
265 | void **clientData, | |
266 | wxClientDataType type) | |
267 | { | |
268 | long lIndex = 0; | |
269 | LONG lIndexType = 0; | |
270 | bool incrementPos = false; | |
271 | ||
272 | if (IsSorted()) | |
273 | lIndexType = LIT_SORTASCENDING; | |
274 | else if (pos == GetCount()) | |
275 | lIndexType = LIT_END; | |
276 | else | |
277 | { | |
278 | lIndexType = (LONG)pos; | |
279 | incrementPos = true; | |
280 | } | |
281 | ||
282 | int n = wxNOT_FOUND; | |
283 | ||
284 | unsigned int count = items.GetCount(); | |
285 | for (unsigned int i = 0; i < count; i++) | |
286 | { | |
287 | n = (int)::WinSendMsg(GetHwnd(), LM_INSERTITEM, (MPARAM)lIndexType, (MPARAM)items[i].wx_str()); | |
288 | if (n < 0) | |
289 | { | |
290 | wxLogLastError(wxT("WinSendMsg(LM_INSERTITEM)")); | |
291 | n = wxNOT_FOUND; | |
292 | break; | |
293 | } | |
294 | ++m_nNumItems; | |
295 | ||
296 | #if wxUSE_OWNER_DRAWN | |
297 | if (HasFlag(wxLB_OWNERDRAW)) | |
298 | { | |
299 | wxOwnerDrawn* pNewItem = CreateItem(n); // dummy argument | |
300 | pNewItem->SetFont(GetFont()); | |
301 | m_aItems.Insert(pNewItem, n); | |
302 | } | |
303 | #endif | |
304 | AssignNewItemClientData(n, clientData, i, type); | |
305 | ||
306 | if (incrementPos) | |
307 | ++lIndexType; | |
308 | } | |
309 | ||
310 | return n; | |
311 | } // end of wxListBox::DoInsertAppendItemsWithData | |
312 | ||
313 | void wxListBox::DoClear() | |
314 | { | |
315 | #if wxUSE_OWNER_DRAWN | |
316 | if ( m_windowStyle & wxLB_OWNERDRAW ) | |
317 | { | |
318 | WX_CLEAR_ARRAY(m_aItems); | |
319 | } | |
320 | #endif // wxUSE_OWNER_DRAWN | |
321 | ::WinSendMsg(GetHwnd(), LM_DELETEALL, (MPARAM)0, (MPARAM)0); | |
322 | ||
323 | m_nNumItems = 0; | |
324 | } // end of wxListBox::Clear | |
325 | ||
326 | void wxListBox::DoSetSelection( int N, bool bSelect) | |
327 | { | |
328 | wxCHECK_RET( IsValid(N), | |
329 | wxT("invalid index in wxListBox::SetSelection") ); | |
330 | ::WinSendMsg( GetHwnd() | |
331 | ,LM_SELECTITEM | |
332 | ,MPFROMLONG(N) | |
333 | ,(MPARAM)bSelect | |
334 | ); | |
335 | if(m_windowStyle & wxLB_OWNERDRAW) | |
336 | Refresh(); | |
337 | } // end of wxListBox::SetSelection | |
338 | ||
339 | bool wxListBox::IsSelected( int N ) const | |
340 | { | |
341 | wxCHECK_MSG( IsValid(N), false, | |
342 | wxT("invalid index in wxListBox::Selected") ); | |
343 | ||
344 | LONG lItem; | |
345 | ||
346 | if (GetWindowStyleFlag() & wxLB_EXTENDED) | |
347 | { | |
348 | if (N == 0) | |
349 | lItem = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION, (MPARAM)LIT_FIRST, (MPARAM)0)); | |
350 | else | |
351 | lItem = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION, (MPARAM)(N - 1), (MPARAM)0)); | |
352 | } | |
353 | else | |
354 | { | |
355 | lItem = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION, (MPARAM)LIT_FIRST, (MPARAM)0)); | |
356 | } | |
357 | return (lItem == (LONG)N && lItem != LIT_NONE); | |
358 | } // end of wxListBox::IsSelected | |
359 | ||
360 | void* wxListBox::DoGetItemClientData(unsigned int n) const | |
361 | { | |
362 | wxCHECK_MSG( IsValid(n), NULL, | |
363 | wxT("invalid index in wxListBox::GetClientData") ); | |
364 | ||
365 | return((void *)::WinSendMsg(GetHwnd(), LM_QUERYITEMHANDLE, MPFROMLONG(n), (MPARAM)0)); | |
366 | } // end of wxListBox::DoGetItemClientData | |
367 | ||
368 | void wxListBox::DoSetItemClientData(unsigned int n, void* pClientData) | |
369 | { | |
370 | wxCHECK_RET( IsValid(n), | |
371 | wxT("invalid index in wxListBox::SetClientData") ); | |
372 | ||
373 | ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, MPFROMLONG(n), MPFROMP(pClientData)); | |
374 | } // end of wxListBox::DoSetItemClientData | |
375 | ||
376 | bool wxListBox::HasMultipleSelection() const | |
377 | { | |
378 | return (m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED); | |
379 | } // end of wxListBox::HasMultipleSelection | |
380 | ||
381 | int wxListBox::GetSelections( wxArrayInt& raSelections ) const | |
382 | { | |
383 | int nCount = 0; | |
384 | LONG lItem; | |
385 | ||
386 | ||
387 | raSelections.Empty(); | |
388 | if (HasMultipleSelection()) | |
389 | { | |
390 | lItem = LONGFROMMR(::WinSendMsg( GetHwnd() | |
391 | ,LM_QUERYSELECTION | |
392 | ,(MPARAM)LIT_FIRST | |
393 | ,(MPARAM)0 | |
394 | ) | |
395 | ); | |
396 | if (lItem != LIT_NONE) | |
397 | { | |
398 | nCount++; | |
399 | while ((lItem = LONGFROMMR(::WinSendMsg( GetHwnd() | |
400 | ,LM_QUERYSELECTION | |
401 | ,(MPARAM)lItem | |
402 | ,(MPARAM)0 | |
403 | ) | |
404 | )) != LIT_NONE) | |
405 | { | |
406 | nCount++; | |
407 | } | |
408 | raSelections.Alloc(nCount); | |
409 | lItem = LONGFROMMR(::WinSendMsg( GetHwnd() | |
410 | ,LM_QUERYSELECTION | |
411 | ,(MPARAM)LIT_FIRST | |
412 | ,(MPARAM)0 | |
413 | ) | |
414 | ); | |
415 | ||
416 | raSelections.Add((int)lItem); | |
417 | while ((lItem = LONGFROMMR(::WinSendMsg( GetHwnd() | |
418 | ,LM_QUERYSELECTION | |
419 | ,(MPARAM)lItem | |
420 | ,(MPARAM)0 | |
421 | ) | |
422 | )) != LIT_NONE) | |
423 | { | |
424 | raSelections.Add((int)lItem); | |
425 | } | |
426 | return nCount; | |
427 | } | |
428 | } | |
429 | else // single-selection listbox | |
430 | { | |
431 | lItem = LONGFROMMR(::WinSendMsg( GetHwnd() | |
432 | ,LM_QUERYSELECTION | |
433 | ,(MPARAM)LIT_FIRST | |
434 | ,(MPARAM)0 | |
435 | ) | |
436 | ); | |
437 | raSelections.Add((int)lItem); | |
438 | return 1; | |
439 | } | |
440 | return 0; | |
441 | } // end of wxListBox::GetSelections | |
442 | ||
443 | int wxListBox::GetSelection() const | |
444 | { | |
445 | wxCHECK_MSG( !HasMultipleSelection(), | |
446 | -1, | |
447 | wxT("GetSelection() can't be used with multiple-selection " | |
448 | "listboxes, use GetSelections() instead.") ); | |
449 | ||
450 | return(LONGFROMMR(::WinSendMsg( GetHwnd() | |
451 | ,LM_QUERYSELECTION | |
452 | ,(MPARAM)LIT_FIRST | |
453 | ,(MPARAM)0 | |
454 | ) | |
455 | )); | |
456 | } // end of wxListBox::GetSelection | |
457 | ||
458 | wxString wxListBox::GetString(unsigned int n) const | |
459 | { | |
460 | LONG lLen = 0; | |
461 | wxChar* zBuf; | |
462 | wxString sResult; | |
463 | ||
464 | wxCHECK_MSG( IsValid(n), wxEmptyString, | |
465 | wxT("invalid index in wxListBox::GetClientData") ); | |
466 | ||
467 | lLen = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXTLENGTH, (MPARAM)n, (MPARAM)0)); | |
468 | zBuf = new wxChar[lLen + 1]; | |
469 | ::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXT, MPFROM2SHORT((SHORT)n, (SHORT)lLen), (MPARAM)zBuf); | |
470 | zBuf[lLen] = '\0'; | |
471 | sResult = zBuf; | |
472 | delete [] zBuf; | |
473 | return sResult; | |
474 | } // end of wxListBox::GetString | |
475 | ||
476 | void wxListBox::SetString(unsigned int n, const wxString& rsString) | |
477 | { | |
478 | wxCHECK_RET( IsValid(n), | |
479 | wxT("invalid index in wxListBox::SetString") ); | |
480 | ||
481 | // | |
482 | // Remember the state of the item | |
483 | // | |
484 | bool bWasSelected = IsSelected(n); | |
485 | void* pOldData = NULL; | |
486 | wxClientData* pOldObjData = NULL; | |
487 | ||
488 | if ( HasClientUntypedData() ) | |
489 | pOldData = GetClientData(n); | |
490 | else if ( HasClientObjectData() ) | |
491 | pOldObjData = GetClientObject(n); | |
492 | ||
493 | // | |
494 | // Delete and recreate it | |
495 | // | |
496 | ::WinSendMsg( GetHwnd() | |
497 | ,LM_DELETEITEM | |
498 | ,(MPARAM)n | |
499 | ,(MPARAM)0 | |
500 | ); | |
501 | ||
502 | int nNewN = n; | |
503 | ||
504 | if (n == (m_nNumItems - 1)) | |
505 | nNewN = -1; | |
506 | ||
507 | ::WinSendMsg( GetHwnd() | |
508 | ,LM_INSERTITEM | |
509 | ,(MPARAM)nNewN | |
510 | ,(MPARAM)rsString.wx_str() | |
511 | ); | |
512 | ||
513 | // | |
514 | // Restore the client data | |
515 | // | |
516 | if (pOldData) | |
517 | SetClientData(n, pOldData); | |
518 | else if (pOldObjData) | |
519 | SetClientObject(n, pOldObjData); | |
520 | ||
521 | // | |
522 | // We may have lost the selection | |
523 | // | |
524 | if (bWasSelected) | |
525 | Select(n); | |
526 | } // end of wxListBox::SetString | |
527 | ||
528 | unsigned int wxListBox::GetCount() const | |
529 | { | |
530 | return m_nNumItems; | |
531 | } | |
532 | ||
533 | // ---------------------------------------------------------------------------- | |
534 | // helpers | |
535 | // ---------------------------------------------------------------------------- | |
536 | ||
537 | wxSize wxListBox::DoGetBestSize() const | |
538 | { | |
539 | // | |
540 | // Find the widest string | |
541 | // | |
542 | int nLine; | |
543 | int nListbox = 0; | |
544 | int nCx; | |
545 | int nCy; | |
546 | wxFont vFont = (wxFont)GetFont(); | |
547 | ||
548 | for (unsigned int i = 0; i < m_nNumItems; i++) | |
549 | { | |
550 | wxString vStr(GetString(i)); | |
551 | ||
552 | GetTextExtent( vStr, &nLine, NULL ); | |
553 | if (nLine > nListbox) | |
554 | nListbox = nLine; | |
555 | } | |
556 | ||
557 | // | |
558 | // Give it some reasonable default value if there are no strings in the | |
559 | // list. | |
560 | // | |
561 | if (nListbox == 0) | |
562 | nListbox = 100; | |
563 | ||
564 | // | |
565 | // The listbox should be slightly larger than the widest string | |
566 | // | |
567 | wxGetCharSize( GetHWND() | |
568 | ,&nCx | |
569 | ,&nCy | |
570 | ,&vFont | |
571 | ); | |
572 | nListbox += 3 * nCx; | |
573 | ||
574 | int hListbox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy) * (wxMax(m_nNumItems, 7)); | |
575 | ||
576 | return wxSize( nListbox | |
577 | ,hListbox | |
578 | ); | |
579 | } // end of wxListBox::DoGetBestSize | |
580 | ||
581 | // ---------------------------------------------------------------------------- | |
582 | // callbacks | |
583 | // ---------------------------------------------------------------------------- | |
584 | ||
585 | bool wxListBox::OS2Command( | |
586 | WXUINT uParam | |
587 | , WXWORD WXUNUSED(wId)) | |
588 | { | |
589 | wxEventType eEvtType; | |
590 | ||
591 | if (uParam == LN_SELECT) | |
592 | { | |
593 | eEvtType = wxEVT_COMMAND_LISTBOX_SELECTED; | |
594 | } | |
595 | else if (uParam == LN_ENTER) | |
596 | { | |
597 | eEvtType = wxEVT_COMMAND_LISTBOX_DOUBLECLICKED; | |
598 | } | |
599 | else | |
600 | { | |
601 | // | |
602 | // Some event we're not interested in | |
603 | // | |
604 | return false; | |
605 | } | |
606 | wxCommandEvent vEvent( eEvtType | |
607 | ,m_windowId | |
608 | ); | |
609 | ||
610 | vEvent.SetEventObject(this); | |
611 | ||
612 | wxArrayInt aSelections; | |
613 | int n; | |
614 | int nCount = GetSelections(aSelections); | |
615 | ||
616 | if (nCount > 0) | |
617 | { | |
618 | n = aSelections[0]; | |
619 | if (HasClientObjectData()) | |
620 | vEvent.SetClientObject(GetClientObject(n)); | |
621 | else if ( HasClientUntypedData() ) | |
622 | vEvent.SetClientData(GetClientData(n)); | |
623 | vEvent.SetString(GetString(n)); | |
624 | } | |
625 | else | |
626 | { | |
627 | n = -1; | |
628 | } | |
629 | vEvent.SetInt(n); | |
630 | return HandleWindowEvent(vEvent); | |
631 | } // end of wxListBox::OS2Command | |
632 | ||
633 | // ---------------------------------------------------------------------------- | |
634 | // wxCheckListBox support | |
635 | // ---------------------------------------------------------------------------- | |
636 | ||
637 | #if wxUSE_OWNER_DRAWN | |
638 | ||
639 | // | |
640 | // Drawing | |
641 | // ------- | |
642 | // | |
643 | #define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1) | |
644 | ||
645 | long wxListBox::OS2OnMeasure(WXMEASUREITEMSTRUCT* pItem) | |
646 | { | |
647 | if (!pItem) | |
648 | pItem = (WXMEASUREITEMSTRUCT*)new OWNERITEM; | |
649 | ||
650 | POWNERITEM pMeasureStruct = (POWNERITEM)pItem; | |
651 | wxScreenDC vDc; | |
652 | ||
653 | // | |
654 | // Only owner-drawn control should receive this message | |
655 | // | |
656 | wxCHECK( ((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), FALSE ); | |
657 | ||
658 | vDc.SetFont(GetFont()); | |
659 | ||
660 | wxCoord vHeight; | |
661 | wxCoord vWidth; | |
662 | ||
663 | GetSize( &vWidth | |
664 | ,NULL | |
665 | ); | |
666 | ||
667 | pMeasureStruct->rclItem.xRight = (USHORT)vWidth; | |
668 | pMeasureStruct->rclItem.xLeft = 0; | |
669 | pMeasureStruct->rclItem.yTop = 0; | |
670 | pMeasureStruct->rclItem.yBottom = 0; | |
671 | ||
672 | vHeight = (wxCoord)(vDc.GetCharHeight() * 2.5); | |
673 | pMeasureStruct->rclItem.yTop = (USHORT)vHeight; | |
674 | ||
675 | return long(MRFROM2SHORT((USHORT)vHeight, (USHORT)vWidth)); | |
676 | } // end of wxListBox::OS2OnMeasure | |
677 | ||
678 | bool wxListBox::OS2OnDraw ( | |
679 | WXDRAWITEMSTRUCT* pItem | |
680 | ) | |
681 | { | |
682 | POWNERITEM pDrawStruct = (POWNERITEM)pItem; | |
683 | int eAction = 0; | |
684 | int eStatus = 0; | |
685 | ||
686 | // | |
687 | // Only owner-drawn control should receive this message | |
688 | // | |
689 | wxCHECK(((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), false); | |
690 | ||
691 | ||
692 | // | |
693 | // The item may be -1 for an empty listbox | |
694 | // | |
695 | if (pDrawStruct->idItem == -1L) | |
696 | return false; | |
697 | ||
698 | wxListBoxItem* pData = (wxListBoxItem*)m_aItems[pDrawStruct->idItem]; | |
699 | ||
700 | wxClientDC vDc(this); | |
701 | wxPMDCImpl *impl = (wxPMDCImpl*) vDc.GetImpl(); | |
702 | wxPoint pt1( pDrawStruct->rclItem.xLeft, pDrawStruct->rclItem.yTop ); | |
703 | wxPoint pt2( pDrawStruct->rclItem.xRight, pDrawStruct->rclItem.yBottom ); | |
704 | wxRect vRect( pt1, pt2 ); | |
705 | ||
706 | impl->SetHPS(pDrawStruct->hps); | |
707 | ||
708 | if (pDrawStruct->fsAttribute == pDrawStruct->fsAttributeOld) | |
709 | { | |
710 | // | |
711 | // Entire Item needs to be redrawn (either it has reappeared from | |
712 | // behind another window or is being displayed for the first time | |
713 | // | |
714 | eAction = wxOwnerDrawn::wxODDrawAll; | |
715 | ||
716 | if (pDrawStruct->fsAttribute & MIA_HILITED) | |
717 | { | |
718 | // | |
719 | // If it is currently selected we let the system handle it | |
720 | // | |
721 | eStatus |= wxOwnerDrawn::wxODSelected; | |
722 | } | |
723 | if (pDrawStruct->fsAttribute & MIA_CHECKED) | |
724 | { | |
725 | // | |
726 | // If it is currently checked we draw our own | |
727 | // | |
728 | eStatus |= wxOwnerDrawn::wxODChecked; | |
729 | pDrawStruct->fsAttributeOld = pDrawStruct->fsAttribute &= ~MIA_CHECKED; | |
730 | } | |
731 | if (pDrawStruct->fsAttribute & MIA_DISABLED) | |
732 | { | |
733 | // | |
734 | // If it is currently disabled we let the system handle it | |
735 | // | |
736 | eStatus |= wxOwnerDrawn::wxODDisabled; | |
737 | } | |
738 | // | |
739 | // Don't really care about framed (indicationg focus) or NoDismiss | |
740 | // | |
741 | } | |
742 | else | |
743 | { | |
744 | if (pDrawStruct->fsAttribute & MIA_HILITED) | |
745 | { | |
746 | eAction = wxOwnerDrawn::wxODDrawAll; | |
747 | eStatus |= wxOwnerDrawn::wxODSelected; | |
748 | // | |
749 | // Keep the system from trying to highlight with its bogus colors | |
750 | // | |
751 | pDrawStruct->fsAttributeOld = pDrawStruct->fsAttribute &= ~MIA_HILITED; | |
752 | } | |
753 | else if (!(pDrawStruct->fsAttribute & MIA_HILITED)) | |
754 | { | |
755 | eAction = wxOwnerDrawn::wxODDrawAll; | |
756 | eStatus = 0; | |
757 | // | |
758 | // Keep the system from trying to highlight with its bogus colors | |
759 | // | |
760 | pDrawStruct->fsAttribute = pDrawStruct->fsAttributeOld &= ~MIA_HILITED; | |
761 | } | |
762 | else | |
763 | { | |
764 | // | |
765 | // For now we don't care about anything else | |
766 | // just ignore the entire message! | |
767 | // | |
768 | return true; | |
769 | } | |
770 | } | |
771 | return pData->OnDrawItem( vDc | |
772 | ,vRect | |
773 | ,(wxOwnerDrawn::wxODAction)eAction | |
774 | ,(wxOwnerDrawn::wxODStatus)(eStatus | wxOwnerDrawn::wxODHidePrefix) | |
775 | ); | |
776 | } // end of wxListBox::OS2OnDraw | |
777 | ||
778 | #endif // ndef for wxUSE_OWNER_DRAWN | |
779 | ||
780 | #endif // wxUSE_LISTBOX |