]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: listbox.cpp | |
3 | // Purpose: wxListBox | |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: ??/??/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) AUTHOR | |
9 | // Licence: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "listbox.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/app.h" | |
17 | #include "wx/listbox.h" | |
18 | #include "wx/settings.h" | |
19 | #include "wx/toplevel.h" | |
20 | #include "wx/dynarray.h" | |
21 | #include "wx/log.h" | |
22 | ||
23 | #include "wx/utils.h" | |
24 | ||
25 | #if !USE_SHARED_LIBRARY | |
26 | IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl) | |
27 | ||
28 | BEGIN_EVENT_TABLE(wxListBox, wxControl) | |
29 | EVT_SIZE( wxListBox::OnSize ) | |
30 | END_EVENT_TABLE() | |
31 | #endif | |
32 | ||
33 | #include "wx/mac/uma.h" | |
34 | ||
35 | ||
36 | typedef struct { | |
37 | unsigned short instruction; | |
38 | void (*function)(); | |
39 | } ldefRec, *ldefPtr, **ldefHandle; | |
40 | ||
41 | extern "C" | |
42 | { | |
43 | static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect *drawRect, | |
44 | Cell cell, short dataOffset, short dataLength, | |
45 | ListHandle listHandle ) ; | |
46 | } | |
47 | ||
48 | static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect *drawRect, | |
49 | Cell cell, short dataOffset, short dataLength, | |
50 | ListHandle listHandle ) | |
51 | { | |
52 | FontInfo fontInfo; | |
53 | GrafPtr savePort; | |
54 | GrafPtr grafPtr; | |
55 | RgnHandle savedClipRegion; | |
56 | SInt32 savedPenMode; | |
57 | wxListBox* list; | |
58 | GetPort(&savePort); | |
59 | SetPort((**listHandle).port); | |
60 | grafPtr = (**listHandle).port ; | |
61 | // typecast our refCon | |
62 | list = (wxListBox*) GetControlReference( (ControlHandle) GetListRefCon(listHandle) ); | |
63 | ||
64 | // Calculate the cell rect. | |
65 | ||
66 | switch( message ) { | |
67 | case lInitMsg: | |
68 | break; | |
69 | ||
70 | case lCloseMsg: | |
71 | break; | |
72 | ||
73 | case lDrawMsg: | |
74 | { | |
75 | const wxString text = list->m_stringArray[cell.v] ; | |
76 | ||
77 | // Save the current clip region, and set the clip region to the area we are about | |
78 | // to draw. | |
79 | ||
80 | savedClipRegion = NewRgn(); | |
81 | GetClip( savedClipRegion ); | |
82 | ||
83 | ClipRect( drawRect ); | |
84 | EraseRect( drawRect ); | |
85 | ||
86 | MoveTo(drawRect->left + 4 , drawRect->top + 10 ); | |
87 | ::TextFont( kFontIDMonaco ) ; | |
88 | ::TextSize( 9 ); | |
89 | ::TextFace( 0 ) ; | |
90 | ||
91 | DrawText(text, 0 , text.Length()); | |
92 | // If the cell is hilited, do the hilite now. Paint the cell contents with the | |
93 | // appropriate QuickDraw transform mode. | |
94 | ||
95 | if( isSelected ) { | |
96 | savedPenMode = GetPortPenMode( grafPtr ); | |
97 | SetPortPenMode( grafPtr, hilitetransfermode ); | |
98 | PaintRect( drawRect ); | |
99 | SetPortPenMode( grafPtr, savedPenMode ); | |
100 | } | |
101 | ||
102 | // Restore the saved clip region. | |
103 | ||
104 | SetClip( savedClipRegion ); | |
105 | DisposeRgn( savedClipRegion ); | |
106 | } | |
107 | break; | |
108 | case lHiliteMsg: | |
109 | ||
110 | // Hilite or unhilite the cell. Paint the cell contents with the | |
111 | // appropriate QuickDraw transform mode. | |
112 | ||
113 | GetPort( &grafPtr ); | |
114 | savedPenMode = GetPortPenMode( grafPtr ); | |
115 | SetPortPenMode( grafPtr, hilitetransfermode ); | |
116 | PaintRect( drawRect ); | |
117 | SetPortPenMode( grafPtr, savedPenMode ); | |
118 | break; | |
119 | default : | |
120 | break ; | |
121 | } | |
122 | SetPort(savePort); | |
123 | } | |
124 | ||
125 | extern "C" void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon) ; | |
126 | const short kwxMacListWithVerticalScrollbar = 128 ; | |
127 | ||
128 | // ============================================================================ | |
129 | // list box control implementation | |
130 | // ============================================================================ | |
131 | ||
132 | // Listbox item | |
133 | wxListBox::wxListBox() | |
134 | { | |
135 | m_noItems = 0; | |
136 | m_selected = 0; | |
137 | m_macList = NULL ; | |
138 | } | |
139 | ||
140 | static ListDefUPP macListDefUPP = NULL ; | |
141 | ||
142 | bool wxListBox::Create(wxWindow *parent, wxWindowID id, | |
143 | const wxPoint& pos, | |
144 | const wxSize& size, | |
145 | int n, const wxString choices[], | |
146 | long style, | |
147 | const wxValidator& validator, | |
148 | const wxString& name) | |
149 | { | |
150 | m_noItems = 0 ; // this will be increased by our append command | |
151 | m_selected = 0; | |
152 | ||
153 | Rect bounds ; | |
154 | Str255 title ; | |
155 | ||
156 | MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ; | |
157 | ||
158 | ListDefSpec listDef; | |
159 | listDef.defType = kListDefUserProcType; | |
160 | if ( macListDefUPP == NULL ) | |
161 | { | |
162 | macListDefUPP = NewListDefUPP( wxMacListDefinition ); | |
163 | } | |
164 | listDef.u.userProc = macListDefUPP ; | |
165 | ||
166 | #if TARGET_CARBON | |
167 | Size asize; | |
168 | ||
169 | ||
170 | CreateListBoxControl( parent->MacGetRootWindow(), &bounds, false, 0, 1, false, true, | |
171 | 14, 14, false, &listDef, &m_macControl ); | |
172 | ||
173 | GetControlData(m_macControl, kControlNoPart, kControlListBoxListHandleTag, | |
174 | sizeof(ListHandle), (Ptr) &m_macList, &asize); | |
175 | ||
176 | SetControlReference(m_macControl, (long) this); | |
177 | SetControlVisibility(m_macControl, false, false); | |
178 | ||
179 | #else | |
180 | ||
181 | long result ; | |
182 | ||
183 | m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , | |
184 | kwxMacListWithVerticalScrollbar , 0 , 0, | |
185 | kControlListBoxProc , (long) this ) ; | |
186 | ::GetControlData( m_macControl , kControlNoPart , kControlListBoxListHandleTag , | |
187 | sizeof( ListHandle ) , (char*) &m_macList , &result ) ; | |
188 | ||
189 | HLock( (Handle) m_macList ) ; | |
190 | ldefHandle ldef ; | |
191 | ldef = (ldefHandle) NewHandle( sizeof(ldefRec) ) ; | |
192 | if ( (**m_macList).listDefProc != NULL ) | |
193 | { | |
194 | (**ldef).instruction = 0x4EF9; /* JMP instruction */ | |
195 | (**ldef).function = (void(*)()) listDef.u.userProc; | |
196 | (**m_macList).listDefProc = (Handle) ldef ; | |
197 | } | |
198 | ||
199 | Point pt = (**m_macList).cellSize ; | |
200 | pt.v = 14 ; | |
201 | LCellSize( pt , m_macList ) ; | |
202 | LAddColumn( 1 , 0 , m_macList ) ; | |
203 | #endif | |
204 | OptionBits options = 0; | |
205 | if ( style & wxLB_MULTIPLE ) | |
206 | { | |
207 | options += lNoExtend ; | |
208 | } | |
209 | else if ( style & wxLB_EXTENDED ) | |
210 | { | |
211 | options += lExtendDrag ; | |
212 | } | |
213 | else | |
214 | { | |
215 | options = lOnlyOne ; | |
216 | } | |
217 | SetListSelectionFlags(m_macList, options); | |
218 | ||
219 | MacPostControlCreate() ; | |
220 | ||
221 | for ( int i = 0 ; i < n ; i++ ) | |
222 | { | |
223 | Append( choices[i] ) ; | |
224 | } | |
225 | ||
226 | LSetDrawingMode( true , m_macList ) ; | |
227 | ||
228 | return TRUE; | |
229 | } | |
230 | ||
231 | wxListBox::~wxListBox() | |
232 | { | |
233 | Free() ; | |
234 | if ( m_macList ) | |
235 | { | |
236 | #if !TARGET_CARBON | |
237 | DisposeHandle( (**m_macList).listDefProc ) ; | |
238 | (**m_macList).listDefProc = NULL ; | |
239 | #endif | |
240 | m_macList = NULL ; | |
241 | } | |
242 | } | |
243 | ||
244 | void wxListBox::Free() | |
245 | { | |
246 | #if wxUSE_OWNER_DRAWN | |
247 | if ( m_windowStyle & wxLB_OWNERDRAW ) | |
248 | { | |
249 | size_t uiCount = m_aItems.Count(); | |
250 | while ( uiCount-- != 0 ) { | |
251 | delete m_aItems[uiCount]; | |
252 | } | |
253 | ||
254 | m_aItems.Clear(); | |
255 | } | |
256 | else | |
257 | #endif // wxUSE_OWNER_DRAWN | |
258 | if ( HasClientObjectData() ) | |
259 | { | |
260 | for ( size_t n = 0; n < (size_t)m_noItems; n++ ) | |
261 | { | |
262 | delete GetClientObject(n); | |
263 | } | |
264 | } | |
265 | } | |
266 | ||
267 | void wxListBox::DoSetSize(int x, int y, | |
268 | int width, int height, | |
269 | int sizeFlags ) | |
270 | { | |
271 | wxControl::DoSetSize( x , y , width , height , sizeFlags ) ; | |
272 | #if TARGET_CARBON | |
273 | Rect bounds ; | |
274 | GetControlBounds( m_macControl , &bounds ) ; | |
275 | ControlRef control = GetListVerticalScrollBar( m_macList ) ; | |
276 | if ( control ) | |
277 | { | |
278 | Rect scrollbounds ; | |
279 | GetControlBounds( control , &scrollbounds ) ; | |
280 | if( scrollbounds.right != bounds.right + 1 ) | |
281 | { | |
282 | UMAMoveControl( control , bounds.right - (scrollbounds.right - scrollbounds.left) + 1 , | |
283 | scrollbounds.top ) ; | |
284 | } | |
285 | } | |
286 | #endif | |
287 | } | |
288 | void wxListBox::DoSetFirstItem(int N) | |
289 | { | |
290 | MacScrollTo( N ) ; | |
291 | } | |
292 | ||
293 | void wxListBox::Delete(int N) | |
294 | { | |
295 | wxCHECK_RET( N >= 0 && N < m_noItems, | |
296 | wxT("invalid index in wxListBox::Delete") ); | |
297 | ||
298 | #if wxUSE_OWNER_DRAWN | |
299 | delete m_aItems[N]; | |
300 | m_aItems.RemoveAt(N); | |
301 | #else // !wxUSE_OWNER_DRAWN | |
302 | if ( HasClientObjectData() ) | |
303 | { | |
304 | delete GetClientObject(N); | |
305 | } | |
306 | #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN | |
307 | m_stringArray.Remove( N ) ; | |
308 | m_dataArray.RemoveAt( N ) ; | |
309 | m_noItems --; | |
310 | ||
311 | MacDelete( N ) ; | |
312 | } | |
313 | ||
314 | int wxListBox::DoAppend(const wxString& item) | |
315 | { | |
316 | int index = m_noItems ; | |
317 | if( wxApp::s_macDefaultEncodingIsPC ) | |
318 | { | |
319 | m_stringArray.Add( wxMacMakeMacStringFromPC( item ) ) ; | |
320 | m_dataArray.Add( NULL ); | |
321 | } | |
322 | else { | |
323 | m_stringArray.Add( item ) ; | |
324 | m_dataArray.Add( NULL ); | |
325 | } | |
326 | m_noItems ++; | |
327 | DoSetItemClientData( index , NULL ) ; | |
328 | MacAppend( item ) ; | |
329 | ||
330 | return index ; | |
331 | } | |
332 | ||
333 | void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData) | |
334 | { | |
335 | MacSetRedraw( false ) ; | |
336 | Clear() ; | |
337 | int n = choices.GetCount(); | |
338 | ||
339 | for( int i = 0 ; i < n ; ++i ) | |
340 | { | |
341 | if ( clientData ) | |
342 | { | |
343 | #if wxUSE_OWNER_DRAWN | |
344 | wxASSERT_MSG(clientData[i] == NULL, | |
345 | wxT("Can't use client data with owner-drawn listboxes")); | |
346 | #else // !wxUSE_OWNER_DRAWN | |
347 | Append( choices[i] , clientData[i] ) ; | |
348 | #endif | |
349 | } | |
350 | else | |
351 | Append( choices[i] ) ; | |
352 | } | |
353 | ||
354 | #if wxUSE_OWNER_DRAWN | |
355 | if ( m_windowStyle & wxLB_OWNERDRAW ) { | |
356 | // first delete old items | |
357 | size_t ui = m_aItems.Count(); | |
358 | while ( ui-- != 0 ) { | |
359 | delete m_aItems[ui]; | |
360 | } | |
361 | m_aItems.Empty(); | |
362 | ||
363 | // then create new ones | |
364 | for ( ui = 0; ui < (size_t)m_noItems; ui++ ) { | |
365 | wxOwnerDrawn *pNewItem = CreateItem(ui); | |
366 | pNewItem->SetName(choices[ui]); | |
367 | m_aItems.Add(pNewItem); | |
368 | } | |
369 | } | |
370 | #endif // wxUSE_OWNER_DRAWN | |
371 | MacSetRedraw( true ) ; | |
372 | } | |
373 | ||
374 | bool wxListBox::HasMultipleSelection() const | |
375 | { | |
376 | return (m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED); | |
377 | } | |
378 | ||
379 | int wxListBox::FindString(const wxString& st) const | |
380 | { | |
381 | wxString s ; | |
382 | if( wxApp::s_macDefaultEncodingIsPC ) | |
383 | { | |
384 | s = wxMacMakeMacStringFromPC( st ) ; | |
385 | } | |
386 | else | |
387 | s = st ; | |
388 | ||
389 | if ( s.Right(1) == "*" ) | |
390 | { | |
391 | wxString search = s.Left( s.Length() - 1 ) ; | |
392 | int len = search.Length() ; | |
393 | Str255 s1 , s2 ; | |
394 | ||
395 | #if TARGET_CARBON | |
396 | c2pstrcpy( (StringPtr) s2 , search.c_str() ) ; | |
397 | #else | |
398 | strcpy( (char *) s2 , search.c_str() ) ; | |
399 | c2pstr( (char *) s2 ) ; | |
400 | #endif | |
401 | ||
402 | for ( int i = 0 ; i < m_noItems ; ++ i ) | |
403 | { | |
404 | #if TARGET_CARBON | |
405 | c2pstrcpy( (StringPtr) s1 , m_stringArray[i].Left( len ).c_str() ) ; | |
406 | #else | |
407 | strcpy( (char *) s1 , m_stringArray[i].Left( len ).c_str() ) ; | |
408 | c2pstr( (char *) s1 ) ; | |
409 | #endif | |
410 | if ( EqualString( s1 , s2 , false , false ) ) | |
411 | return i ; | |
412 | } | |
413 | if ( s.Left(1) == "*" && s.Length() > 1 ) | |
414 | { | |
415 | s.MakeLower() ; | |
416 | for ( int i = 0 ; i < m_noItems ; ++i ) | |
417 | { | |
418 | if ( GetString(i).Lower().Matches(s) ) | |
419 | return i ; | |
420 | } | |
421 | } | |
422 | ||
423 | } | |
424 | else | |
425 | { | |
426 | Str255 s1 , s2 ; | |
427 | ||
428 | #if TARGET_CARBON | |
429 | c2pstrcpy( (StringPtr) s2 , s.c_str() ) ; | |
430 | #else | |
431 | strcpy( (char *) s2 , s.c_str() ) ; | |
432 | c2pstr( (char *) s2 ) ; | |
433 | #endif | |
434 | ||
435 | for ( int i = 0 ; i < m_noItems ; ++ i ) | |
436 | { | |
437 | #if TARGET_CARBON | |
438 | c2pstrcpy( (StringPtr) s1 , m_stringArray[i].c_str() ) ; | |
439 | #else | |
440 | strcpy( (char *) s1 , m_stringArray[i].c_str() ) ; | |
441 | c2pstr( (char *) s1 ) ; | |
442 | #endif | |
443 | if ( EqualString( s1 , s2 , false , false ) ) | |
444 | return i ; | |
445 | } | |
446 | } | |
447 | return -1; | |
448 | } | |
449 | ||
450 | void wxListBox::Clear() | |
451 | { | |
452 | Free(); | |
453 | m_noItems = 0; | |
454 | m_stringArray.Empty() ; | |
455 | m_dataArray.Empty() ; | |
456 | MacClear() ; | |
457 | } | |
458 | ||
459 | void wxListBox::SetSelection(int N, bool select) | |
460 | { | |
461 | wxCHECK_RET( N >= 0 && N < m_noItems, | |
462 | "invalid index in wxListBox::SetSelection" ); | |
463 | MacSetSelection( N , select ) ; | |
464 | GetSelections( m_selectionPreImage ) ; | |
465 | } | |
466 | ||
467 | bool wxListBox::IsSelected(int N) const | |
468 | { | |
469 | wxCHECK_MSG( N >= 0 && N < m_noItems, FALSE, | |
470 | "invalid index in wxListBox::Selected" ); | |
471 | ||
472 | return MacIsSelected( N ) ; | |
473 | } | |
474 | ||
475 | void *wxListBox::DoGetItemClientData(int N) const | |
476 | { | |
477 | wxCHECK_MSG( N >= 0 && N < m_noItems, NULL, | |
478 | wxT("invalid index in wxListBox::GetClientData")); | |
479 | ||
480 | return (void *)m_dataArray[N]; | |
481 | } | |
482 | ||
483 | wxClientData *wxListBox::DoGetItemClientObject(int N) const | |
484 | { | |
485 | return (wxClientData *) DoGetItemClientData( N ) ; | |
486 | } | |
487 | ||
488 | void wxListBox::DoSetItemClientData(int N, void *Client_data) | |
489 | { | |
490 | wxCHECK_RET( N >= 0 && N < m_noItems, | |
491 | "invalid index in wxListBox::SetClientData" ); | |
492 | ||
493 | #if wxUSE_OWNER_DRAWN | |
494 | if ( m_windowStyle & wxLB_OWNERDRAW ) | |
495 | { | |
496 | // client data must be pointer to wxOwnerDrawn, otherwise we would crash | |
497 | // in OnMeasure/OnDraw. | |
498 | wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes")); | |
499 | } | |
500 | #endif // wxUSE_OWNER_DRAWN | |
501 | wxASSERT_MSG( m_dataArray.GetCount() >= N , "invalid client_data array" ) ; | |
502 | ||
503 | if ( m_dataArray.GetCount() > N ) | |
504 | { | |
505 | m_dataArray[N] = (char*) Client_data ; | |
506 | } | |
507 | else | |
508 | { | |
509 | m_dataArray.Add( (char*) Client_data ) ; | |
510 | } | |
511 | } | |
512 | ||
513 | void wxListBox::DoSetItemClientObject(int n, wxClientData* clientData) | |
514 | { | |
515 | DoSetItemClientData(n, clientData); | |
516 | } | |
517 | ||
518 | // Return number of selections and an array of selected integers | |
519 | int wxListBox::GetSelections(wxArrayInt& aSelections) const | |
520 | { | |
521 | return MacGetSelections( aSelections ) ; | |
522 | } | |
523 | ||
524 | // Get single selection, for single choice list items | |
525 | int wxListBox::GetSelection() const | |
526 | { | |
527 | return MacGetSelection() ; | |
528 | } | |
529 | ||
530 | // Find string for position | |
531 | wxString wxListBox::GetString(int N) const | |
532 | { | |
533 | if( wxApp::s_macDefaultEncodingIsPC ) | |
534 | { | |
535 | return wxMacMakePCStringFromMac( m_stringArray[N] ) ; | |
536 | } | |
537 | else | |
538 | return m_stringArray[N] ; | |
539 | } | |
540 | ||
541 | void wxListBox::DoInsertItems(const wxArrayString& items, int pos) | |
542 | { | |
543 | wxCHECK_RET( pos >= 0 && pos <= m_noItems, | |
544 | wxT("invalid index in wxListBox::InsertItems") ); | |
545 | ||
546 | int nItems = items.GetCount(); | |
547 | ||
548 | for ( int i = 0 ; i < nItems ; i++ ) | |
549 | { | |
550 | m_stringArray.Insert( items[i] , pos + i ) ; | |
551 | m_dataArray.Insert( NULL , pos + i ) ; | |
552 | MacInsert( pos + i , items[i] ) ; | |
553 | } | |
554 | ||
555 | m_noItems += nItems; | |
556 | } | |
557 | ||
558 | void wxListBox::SetString(int N, const wxString& s) | |
559 | { | |
560 | wxString str ; | |
561 | if( wxApp::s_macDefaultEncodingIsPC ) | |
562 | { | |
563 | str = wxMacMakeMacStringFromPC( s ) ; | |
564 | } | |
565 | else | |
566 | str = s ; | |
567 | m_stringArray[N] = str ; | |
568 | MacSet( N , s ) ; | |
569 | } | |
570 | ||
571 | wxSize wxListBox::DoGetBestSize() const | |
572 | { | |
573 | return wxSize(100, 100); | |
574 | } | |
575 | ||
576 | int wxListBox::GetCount() const | |
577 | { | |
578 | return m_noItems; | |
579 | } | |
580 | ||
581 | void wxListBox::SetupColours() | |
582 | { | |
583 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW)); | |
584 | SetForegroundColour(GetParent()->GetForegroundColour()); | |
585 | } | |
586 | ||
587 | void wxListBox::Refresh(bool eraseBack, const wxRect *rect) | |
588 | { | |
589 | wxControl::Refresh( eraseBack , rect ) ; | |
590 | // MacRedrawControl() ; | |
591 | } | |
592 | ||
593 | #if wxUSE_OWNER_DRAWN | |
594 | ||
595 | class wxListBoxItem : public wxOwnerDrawn | |
596 | { | |
597 | public: | |
598 | wxListBoxItem(const wxString& str = ""); | |
599 | }; | |
600 | ||
601 | wxListBoxItem::wxListBoxItem(const wxString& str) : wxOwnerDrawn(str, FALSE) | |
602 | { | |
603 | // no bitmaps/checkmarks | |
604 | SetMarginWidth(0); | |
605 | } | |
606 | ||
607 | wxOwnerDrawn *wxListBox::CreateItem(size_t n) | |
608 | { | |
609 | return new wxListBoxItem(); | |
610 | } | |
611 | ||
612 | #endif //USE_OWNER_DRAWN | |
613 | ||
614 | // ============================================================================ | |
615 | // list box control implementation | |
616 | // ============================================================================ | |
617 | ||
618 | void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon) | |
619 | { | |
620 | wxListBox* list; | |
621 | // typecast our refCon | |
622 | list = (wxListBox*)refCon; | |
623 | ||
624 | MoveTo(cellRect->left + 4 , cellRect->top + 10 ); | |
625 | const wxString text = list->m_stringArray[lCell.v] ; | |
626 | ::TextFont( kFontIDMonaco ) ; | |
627 | ::TextSize( 9 ); | |
628 | ::TextFace( 0 ) ; | |
629 | DrawText(text, 0 , text.Length()); | |
630 | ||
631 | } | |
632 | ||
633 | void wxListBox::MacDelete( int N ) | |
634 | { | |
635 | LDelRow( 1 , N , m_macList) ; | |
636 | Refresh(); | |
637 | } | |
638 | ||
639 | void wxListBox::MacInsert( int n , const char * text) | |
640 | { | |
641 | Cell cell = { 0 , 0 } ; | |
642 | cell.v = n ; | |
643 | LAddRow( 1 , cell.v , m_macList ) ; | |
644 | // LSetCell(text, strlen(text), cell, m_macList); | |
645 | Refresh(); | |
646 | } | |
647 | ||
648 | void wxListBox::MacAppend( const char * text) | |
649 | { | |
650 | Cell cell = { 0 , 0 } ; | |
651 | cell.v = (**m_macList).dataBounds.bottom ; | |
652 | LAddRow( 1 , cell.v , m_macList ) ; | |
653 | // LSetCell(text, strlen(text), cell, m_macList); | |
654 | Refresh(); | |
655 | } | |
656 | ||
657 | void wxListBox::MacClear() | |
658 | { | |
659 | LDelRow( (**m_macList).dataBounds.bottom , 0 , m_macList ) ; | |
660 | Refresh(); | |
661 | } | |
662 | ||
663 | void wxListBox::MacSetSelection( int n , bool select ) | |
664 | { | |
665 | Cell cell = { 0 , 0 } ; | |
666 | if ( ! (m_windowStyle & wxLB_MULTIPLE) ) | |
667 | { | |
668 | if ( LGetSelect( true , &cell , m_macList ) ) | |
669 | { | |
670 | LSetSelect( false , cell , m_macList ) ; | |
671 | } | |
672 | } | |
673 | ||
674 | cell.v = n ; | |
675 | LSetSelect( select , cell , m_macList ) ; | |
676 | LAutoScroll( m_macList ) ; | |
677 | Refresh(); | |
678 | } | |
679 | ||
680 | bool wxListBox::MacIsSelected( int n ) const | |
681 | { | |
682 | Cell cell = { 0 , 0 } ; | |
683 | cell.v = n ; | |
684 | return LGetSelect( false , &cell , m_macList ) ; | |
685 | } | |
686 | ||
687 | void wxListBox::MacDestroy() | |
688 | { | |
689 | // DisposeExtLDEFInfo( m_macList ) ; | |
690 | } | |
691 | ||
692 | int wxListBox::MacGetSelection() const | |
693 | { | |
694 | Cell cell = { 0 , 0 } ; | |
695 | if ( LGetSelect( true , &cell , m_macList ) ) | |
696 | return cell.v ; | |
697 | else | |
698 | return -1 ; | |
699 | } | |
700 | ||
701 | int wxListBox::MacGetSelections( wxArrayInt& aSelections ) const | |
702 | { | |
703 | int no_sel = 0 ; | |
704 | ||
705 | aSelections.Empty(); | |
706 | ||
707 | Cell cell = { 0 , 0 } ; | |
708 | cell.v = 0 ; | |
709 | ||
710 | while ( LGetSelect( true , &cell , m_macList ) ) | |
711 | { | |
712 | aSelections.Add( cell.v ) ; | |
713 | no_sel++ ; | |
714 | cell.v++ ; | |
715 | } | |
716 | return no_sel ; | |
717 | } | |
718 | ||
719 | void wxListBox::MacSet( int n , const char * text ) | |
720 | { | |
721 | // our implementation does not store anything in the list | |
722 | // so we just have to redraw | |
723 | Cell cell = { 0 , 0 } ; | |
724 | cell.v = n ; | |
725 | // LSetCell(text, strlen(text), cell, m_macList); | |
726 | Refresh(); | |
727 | } | |
728 | ||
729 | void wxListBox::MacScrollTo( int n ) | |
730 | { | |
731 | // TODO implement scrolling | |
732 | } | |
733 | ||
734 | void wxListBox::OnSize( const wxSizeEvent &event) | |
735 | { | |
736 | Point pt; | |
737 | ||
738 | #if TARGET_CARBON | |
739 | GetListCellSize(m_macList, &pt); | |
740 | #else | |
741 | pt = (**m_macList).cellSize ; | |
742 | #endif | |
743 | pt.h = m_width - 15 ; | |
744 | LCellSize( pt , m_macList ) ; | |
745 | } | |
746 | ||
747 | void wxListBox::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) | |
748 | { | |
749 | Boolean wasDoubleClick = false ; | |
750 | long result ; | |
751 | ||
752 | ::GetControlData( m_macControl , kControlNoPart , kControlListBoxDoubleClickTag , sizeof( wasDoubleClick ) , (char*) &wasDoubleClick , &result ) ; | |
753 | if ( !wasDoubleClick ) | |
754 | { | |
755 | MacDoClick() ; | |
756 | } | |
757 | else | |
758 | { | |
759 | MacDoDoubleClick() ; | |
760 | } | |
761 | } | |
762 | ||
763 | void wxListBox::MacSetRedraw( bool doDraw ) | |
764 | { | |
765 | LSetDrawingMode( doDraw , m_macList ) ; | |
766 | ||
767 | } | |
768 | ||
769 | void wxListBox::MacDoClick() | |
770 | { | |
771 | wxArrayInt aSelections; | |
772 | int n, count = GetSelections(aSelections); | |
773 | ||
774 | if ( count == m_selectionPreImage.GetCount() ) | |
775 | { | |
776 | bool hasChanged = false ; | |
777 | for ( int i = 0 ; i < count ; ++i ) | |
778 | { | |
779 | if ( aSelections[i] != m_selectionPreImage[i] ) | |
780 | { | |
781 | hasChanged = true ; | |
782 | break ; | |
783 | } | |
784 | } | |
785 | if ( !hasChanged ) | |
786 | { | |
787 | return ; | |
788 | } | |
789 | } | |
790 | ||
791 | m_selectionPreImage = aSelections; | |
792 | ||
793 | wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId); | |
794 | event.SetEventObject( this ); | |
795 | ||
796 | if ( count > 0 ) | |
797 | { | |
798 | n = aSelections[0]; | |
799 | if ( HasClientObjectData() ) | |
800 | event.SetClientObject( GetClientObject(n) ); | |
801 | else if ( HasClientUntypedData() ) | |
802 | event.SetClientData( GetClientData(n) ); | |
803 | event.SetString( GetString(n) ); | |
804 | } | |
805 | else | |
806 | { | |
807 | n = -1; | |
808 | } | |
809 | ||
810 | event.m_commandInt = n; | |
811 | ||
812 | GetEventHandler()->ProcessEvent(event); | |
813 | } | |
814 | ||
815 | void wxListBox::MacDoDoubleClick() | |
816 | { | |
817 | wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, m_windowId); | |
818 | event.SetEventObject( this ); | |
819 | GetEventHandler()->ProcessEvent(event) ; | |
820 | } |