]>
Commit | Line | Data |
---|---|---|
489468fe SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/mac/listctrl_mac.cpp | |
3 | // Purpose: wxListCtrl | |
4 | // Author: Julian Smart | |
5 | // Modified by: Agron Selimaj | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | // For compilers that support precompilation, includes "wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | #if wxUSE_LISTCTRL | |
28 | ||
29 | #include "wx/listctrl.h" | |
30 | ||
31 | #ifndef WX_PRECOMP | |
32 | #include "wx/intl.h" | |
33 | #include "wx/settings.h" | |
34 | #endif | |
35 | ||
1f0c8f31 | 36 | #include "wx/osx/uma.h" |
489468fe SC |
37 | |
38 | #include "wx/imaglist.h" | |
39 | #include "wx/sysopt.h" | |
40 | #include "wx/timer.h" | |
41 | ||
42 | #include "wx/hashmap.h" | |
43 | ||
44 | #if wxUSE_EXTENDED_RTTI | |
45 | WX_DEFINE_FLAGS( wxListCtrlStyle ) | |
46 | ||
47 | wxBEGIN_FLAGS( wxListCtrlStyle ) | |
48 | // new style border flags, we put them first to | |
49 | // use them for streaming out | |
50 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) | |
51 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
52 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
53 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
54 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
55 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
56 | ||
57 | // old style border flags | |
58 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) | |
59 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
60 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
61 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
62 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
63 | wxFLAGS_MEMBER(wxBORDER) | |
64 | ||
65 | // standard window styles | |
66 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) | |
67 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
68 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
69 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
70 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) | |
71 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) | |
72 | wxFLAGS_MEMBER(wxVSCROLL) | |
73 | wxFLAGS_MEMBER(wxHSCROLL) | |
74 | ||
75 | wxFLAGS_MEMBER(wxLC_LIST) | |
76 | wxFLAGS_MEMBER(wxLC_REPORT) | |
77 | wxFLAGS_MEMBER(wxLC_ICON) | |
78 | wxFLAGS_MEMBER(wxLC_SMALL_ICON) | |
79 | wxFLAGS_MEMBER(wxLC_ALIGN_TOP) | |
80 | wxFLAGS_MEMBER(wxLC_ALIGN_LEFT) | |
81 | wxFLAGS_MEMBER(wxLC_AUTOARRANGE) | |
82 | wxFLAGS_MEMBER(wxLC_USER_TEXT) | |
83 | wxFLAGS_MEMBER(wxLC_EDIT_LABELS) | |
84 | wxFLAGS_MEMBER(wxLC_NO_HEADER) | |
85 | wxFLAGS_MEMBER(wxLC_SINGLE_SEL) | |
86 | wxFLAGS_MEMBER(wxLC_SORT_ASCENDING) | |
87 | wxFLAGS_MEMBER(wxLC_SORT_DESCENDING) | |
88 | wxFLAGS_MEMBER(wxLC_VIRTUAL) | |
89 | ||
90 | wxEND_FLAGS( wxListCtrlStyle ) | |
91 | ||
92 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl, wxControl,"wx/listctrl.h") | |
93 | ||
94 | wxBEGIN_PROPERTIES_TABLE(wxListCtrl) | |
95 | wxEVENT_PROPERTY( TextUpdated , wxEVT_COMMAND_TEXT_UPDATED , wxCommandEvent ) | |
96 | ||
97 | wxPROPERTY_FLAGS( WindowStyle , wxListCtrlStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style | |
98 | wxEND_PROPERTIES_TABLE() | |
99 | ||
100 | wxBEGIN_HANDLERS_TABLE(wxListCtrl) | |
101 | wxEND_HANDLERS_TABLE() | |
102 | ||
103 | wxCONSTRUCTOR_5( wxListCtrl , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle ) | |
104 | ||
105 | /* | |
106 | TODO : Expose more information of a list's layout etc. via appropriate objects (¢ la NotebookPageInfo) | |
107 | */ | |
108 | #else | |
109 | IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl) | |
110 | #endif | |
111 | ||
112 | IMPLEMENT_DYNAMIC_CLASS(wxListView, wxListCtrl) | |
113 | IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject) | |
114 | ||
115 | IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent) | |
116 | ||
117 | WX_DECLARE_HASH_MAP( int, wxListItem*, wxIntegerHash, wxIntegerEqual, wxListItemList ); | |
118 | ||
119 | #include "wx/listimpl.cpp" | |
120 | WX_DEFINE_LIST(wxColumnList) | |
121 | ||
122 | // so we can check for column clicks | |
123 | static const EventTypeSpec eventList[] = | |
124 | { | |
125 | { kEventClassControl, kEventControlHit }, | |
126 | { kEventClassControl, kEventControlDraw } | |
127 | }; | |
128 | ||
129 | static pascal OSStatus wxMacListCtrlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
130 | { | |
131 | OSStatus result = eventNotHandledErr ; | |
132 | ||
133 | wxMacCarbonEvent cEvent( event ) ; | |
134 | ||
135 | ControlRef controlRef ; | |
136 | cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ; | |
137 | ||
138 | wxListCtrl *window = (wxListCtrl*) data ; | |
139 | wxListEvent le( wxEVT_COMMAND_LIST_COL_CLICK, window->GetId() ); | |
140 | le.SetEventObject( window ); | |
141 | ||
142 | switch ( GetEventKind( event ) ) | |
143 | { | |
144 | // check if the column was clicked on and fire an event if so | |
145 | case kEventControlHit : | |
146 | { | |
147 | ControlPartCode result = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart, typeControlPartCode) ; | |
148 | if (result == kControlButtonPart){ | |
149 | DataBrowserPropertyID col; | |
150 | GetDataBrowserSortProperty(controlRef, &col); | |
151 | int column = col - kMinColumnId; | |
152 | le.m_col = column; | |
153 | // FIXME: we can't use the sort property for virtual listctrls | |
154 | // so we need to find a better way to determine which column was clicked... | |
155 | if (!window->IsVirtual()) | |
156 | window->HandleWindowEvent( le ); | |
157 | } | |
158 | result = CallNextEventHandler(handler, event); | |
159 | break; | |
160 | } | |
161 | case kEventControlDraw: | |
162 | { | |
163 | CGContextRef context = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef, typeCGContextRef) ; | |
164 | window->MacSetDrawingContext(context); | |
165 | result = CallNextEventHandler(handler, event); | |
166 | window->MacSetDrawingContext(NULL); | |
167 | break; | |
168 | } | |
169 | default : | |
170 | break ; | |
171 | } | |
172 | ||
173 | ||
174 | return result ; | |
175 | } | |
176 | ||
177 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler ) | |
178 | ||
179 | class wxMacListCtrlItem : public wxMacListBoxItem | |
180 | { | |
181 | public: | |
182 | wxMacListCtrlItem(); | |
183 | ||
184 | virtual void Notification(wxMacDataItemBrowserControl *owner , | |
185 | DataBrowserItemNotification message, | |
186 | DataBrowserItemDataRef itemData ) const; | |
187 | ||
188 | virtual void SetColumnInfo( unsigned int column, wxListItem* item ); | |
189 | virtual wxListItem* GetColumnInfo( unsigned int column ); | |
190 | virtual bool HasColumnInfo( unsigned int column ); | |
191 | ||
192 | virtual void SetColumnTextValue( unsigned int column, const wxString& text ); | |
193 | virtual wxString GetColumnTextValue( unsigned int column ); | |
194 | ||
195 | virtual int GetColumnImageValue( unsigned int column ); | |
196 | virtual void SetColumnImageValue( unsigned int column, int imageIndex ); | |
197 | ||
198 | virtual ~wxMacListCtrlItem(); | |
199 | protected: | |
200 | wxListItemList m_rowItems; | |
201 | }; | |
202 | ||
203 | DataBrowserDrawItemUPP gDataBrowserDrawItemUPP = NULL; | |
204 | //DataBrowserEditItemUPP gDataBrowserEditItemUPP = NULL; | |
205 | DataBrowserHitTestUPP gDataBrowserHitTestUPP = NULL; | |
206 | ||
207 | // TODO: Make a better name!! | |
208 | class wxMacDataBrowserListCtrlControl : public wxMacDataItemBrowserControl | |
209 | { | |
210 | public: | |
211 | wxMacDataBrowserListCtrlControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style ); | |
212 | wxMacDataBrowserListCtrlControl() {} | |
213 | virtual ~wxMacDataBrowserListCtrlControl(); | |
214 | ||
215 | // create a list item (can be a subclass of wxMacListBoxItem) | |
216 | ||
217 | virtual wxMacDataItem* CreateItem(); | |
218 | ||
219 | virtual void MacInsertItem( unsigned int n, wxListItem* item ); | |
220 | virtual void MacSetColumnInfo( unsigned int row, unsigned int column, wxListItem* item ); | |
221 | virtual void MacGetColumnInfo( unsigned int row, unsigned int column, wxListItem& item ); | |
222 | virtual void UpdateState(wxMacDataItem* dataItem, wxListItem* item); | |
223 | int GetFlags() { return m_flags; } | |
224 | ||
225 | protected: | |
226 | // we need to override to provide specialized handling for virtual wxListCtrls | |
227 | virtual OSStatus GetSetItemData(DataBrowserItemID itemID, | |
228 | DataBrowserPropertyID property, | |
229 | DataBrowserItemDataRef itemData, | |
230 | Boolean changeValue ); | |
231 | ||
232 | virtual void ItemNotification( | |
233 | DataBrowserItemID itemID, | |
234 | DataBrowserItemNotification message, | |
235 | DataBrowserItemDataRef itemData); | |
236 | ||
237 | virtual Boolean CompareItems(DataBrowserItemID itemOneID, | |
238 | DataBrowserItemID itemTwoID, | |
239 | DataBrowserPropertyID sortProperty); | |
240 | ||
241 | static pascal void DataBrowserDrawItemProc(ControlRef browser, | |
242 | DataBrowserItemID item, | |
243 | DataBrowserPropertyID property, | |
244 | DataBrowserItemState itemState, | |
245 | const Rect *theRect, | |
246 | SInt16 gdDepth, | |
247 | Boolean colorDevice); | |
248 | ||
249 | virtual void DrawItem(DataBrowserItemID itemID, | |
250 | DataBrowserPropertyID property, | |
251 | DataBrowserItemState itemState, | |
252 | const Rect *itemRect, | |
253 | SInt16 gdDepth, | |
254 | Boolean colorDevice); | |
255 | ||
256 | static pascal Boolean DataBrowserEditTextProc(ControlRef browser, | |
257 | DataBrowserItemID item, | |
258 | DataBrowserPropertyID property, | |
259 | CFStringRef theString, | |
260 | Rect *maxEditTextRect, | |
261 | Boolean *shrinkToFit); | |
262 | ||
263 | static pascal Boolean DataBrowserHitTestProc(ControlRef WXUNUSED(browser), | |
264 | DataBrowserItemID WXUNUSED(itemID), | |
265 | DataBrowserPropertyID WXUNUSED(property), | |
266 | const Rect *WXUNUSED(theRect), | |
267 | const Rect *WXUNUSED(mouseRect)) { return true; } | |
268 | ||
269 | virtual bool ConfirmEditText(DataBrowserItemID item, | |
270 | DataBrowserPropertyID property, | |
271 | CFStringRef theString, | |
272 | Rect *maxEditTextRect, | |
273 | Boolean *shrinkToFit); | |
274 | ||
275 | ||
276 | ||
277 | wxClientDataType m_clientDataItemsType; | |
278 | bool m_isVirtual; | |
279 | int m_flags; | |
280 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataBrowserListCtrlControl) | |
281 | }; | |
282 | ||
283 | class wxMacListCtrlEventDelegate : public wxEvtHandler | |
284 | { | |
285 | public: | |
286 | wxMacListCtrlEventDelegate( wxListCtrl* list, int id ); | |
287 | virtual bool ProcessEvent( wxEvent& event ); | |
288 | ||
289 | private: | |
290 | wxListCtrl* m_list; | |
291 | int m_id; | |
292 | }; | |
293 | ||
294 | wxMacListCtrlEventDelegate::wxMacListCtrlEventDelegate( wxListCtrl* list, int id ) | |
295 | { | |
296 | m_list = list; | |
297 | m_id = id; | |
298 | } | |
299 | ||
300 | bool wxMacListCtrlEventDelegate::ProcessEvent( wxEvent& event ) | |
301 | { | |
302 | // even though we use a generic list ctrl underneath, make sure | |
303 | // we present ourselves as wxListCtrl. | |
304 | event.SetEventObject( m_list ); | |
305 | event.SetId( m_id ); | |
306 | ||
307 | if ( !event.IsKindOf( CLASSINFO( wxCommandEvent ) ) ) | |
308 | { | |
309 | if (m_list->HandleWindowEvent( event )) | |
310 | return true; | |
311 | } | |
312 | return wxEvtHandler::ProcessEvent(event); | |
313 | } | |
314 | ||
315 | //----------------------------------------------------------------------------- | |
316 | // wxListCtrlRenameTimer (internal) | |
317 | //----------------------------------------------------------------------------- | |
318 | ||
319 | class wxListCtrlRenameTimer: public wxTimer | |
320 | { | |
321 | private: | |
322 | wxListCtrl *m_owner; | |
323 | ||
324 | public: | |
325 | wxListCtrlRenameTimer( wxListCtrl *owner ); | |
326 | void Notify(); | |
327 | }; | |
328 | ||
329 | //----------------------------------------------------------------------------- | |
330 | // wxListCtrlTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing | |
331 | //----------------------------------------------------------------------------- | |
332 | ||
333 | class wxListCtrlTextCtrlWrapper : public wxEvtHandler | |
334 | { | |
335 | public: | |
336 | // NB: text must be a valid object but not Create()d yet | |
337 | wxListCtrlTextCtrlWrapper(wxListCtrl *owner, | |
338 | wxTextCtrl *text, | |
339 | long itemEdit); | |
340 | ||
341 | wxTextCtrl *GetText() const { return m_text; } | |
342 | ||
343 | void AcceptChangesAndFinish(); | |
344 | ||
345 | protected: | |
346 | void OnChar( wxKeyEvent &event ); | |
347 | void OnKeyUp( wxKeyEvent &event ); | |
348 | void OnKillFocus( wxFocusEvent &event ); | |
349 | ||
350 | bool AcceptChanges(); | |
351 | void Finish(); | |
352 | ||
353 | private: | |
354 | wxListCtrl *m_owner; | |
355 | wxTextCtrl *m_text; | |
356 | wxString m_startValue; | |
357 | long m_itemEdited; | |
358 | bool m_finished; | |
359 | bool m_aboutToFinish; | |
360 | ||
361 | DECLARE_EVENT_TABLE() | |
362 | }; | |
363 | ||
364 | //----------------------------------------------------------------------------- | |
365 | // wxListCtrlRenameTimer (internal) | |
366 | //----------------------------------------------------------------------------- | |
367 | ||
368 | wxListCtrlRenameTimer::wxListCtrlRenameTimer( wxListCtrl *owner ) | |
369 | { | |
370 | m_owner = owner; | |
371 | } | |
372 | ||
373 | void wxListCtrlRenameTimer::Notify() | |
374 | { | |
375 | m_owner->OnRenameTimer(); | |
376 | } | |
377 | ||
378 | //----------------------------------------------------------------------------- | |
379 | // wxListCtrlTextCtrlWrapper (internal) | |
380 | //----------------------------------------------------------------------------- | |
381 | ||
382 | BEGIN_EVENT_TABLE(wxListCtrlTextCtrlWrapper, wxEvtHandler) | |
383 | EVT_CHAR (wxListCtrlTextCtrlWrapper::OnChar) | |
384 | EVT_KEY_UP (wxListCtrlTextCtrlWrapper::OnKeyUp) | |
385 | EVT_KILL_FOCUS (wxListCtrlTextCtrlWrapper::OnKillFocus) | |
386 | END_EVENT_TABLE() | |
387 | ||
388 | wxListCtrlTextCtrlWrapper::wxListCtrlTextCtrlWrapper(wxListCtrl *owner, | |
389 | wxTextCtrl *text, | |
390 | long itemEdit) | |
391 | : m_startValue(owner->GetItemText(itemEdit)), | |
392 | m_itemEdited(itemEdit) | |
393 | { | |
394 | m_owner = owner; | |
395 | m_text = text; | |
396 | m_finished = false; | |
397 | m_aboutToFinish = false; | |
398 | ||
399 | wxRect rectLabel; | |
400 | int offset = 8; | |
401 | owner->GetItemRect(itemEdit, rectLabel); | |
402 | ||
403 | m_text->Create(owner, wxID_ANY, m_startValue, | |
404 | wxPoint(rectLabel.x+offset,rectLabel.y), | |
405 | wxSize(rectLabel.width-offset,rectLabel.height)); | |
406 | m_text->SetFocus(); | |
407 | ||
408 | m_text->PushEventHandler(this); | |
409 | } | |
410 | ||
411 | void wxListCtrlTextCtrlWrapper::Finish() | |
412 | { | |
413 | if ( !m_finished ) | |
414 | { | |
415 | m_finished = true; | |
416 | ||
417 | m_text->RemoveEventHandler(this); | |
418 | m_owner->FinishEditing(m_text); | |
419 | ||
420 | wxPendingDelete.Append( this ); | |
421 | } | |
422 | } | |
423 | ||
424 | bool wxListCtrlTextCtrlWrapper::AcceptChanges() | |
425 | { | |
426 | const wxString value = m_text->GetValue(); | |
427 | ||
428 | if ( value == m_startValue ) | |
429 | // nothing changed, always accept | |
430 | return true; | |
431 | ||
432 | if ( !m_owner->OnRenameAccept(m_itemEdited, value) ) | |
433 | // vetoed by the user | |
434 | return false; | |
435 | ||
436 | // accepted, do rename the item | |
437 | m_owner->SetItemText(m_itemEdited, value); | |
438 | ||
439 | return true; | |
440 | } | |
441 | ||
442 | void wxListCtrlTextCtrlWrapper::AcceptChangesAndFinish() | |
443 | { | |
444 | m_aboutToFinish = true; | |
445 | ||
446 | // Notify the owner about the changes | |
447 | AcceptChanges(); | |
448 | ||
449 | // Even if vetoed, close the control (consistent with MSW) | |
450 | Finish(); | |
451 | } | |
452 | ||
453 | void wxListCtrlTextCtrlWrapper::OnChar( wxKeyEvent &event ) | |
454 | { | |
455 | switch ( event.m_keyCode ) | |
456 | { | |
457 | case WXK_RETURN: | |
458 | AcceptChangesAndFinish(); | |
459 | break; | |
460 | ||
461 | case WXK_ESCAPE: | |
462 | m_owner->OnRenameCancelled( m_itemEdited ); | |
463 | Finish(); | |
464 | break; | |
465 | ||
466 | default: | |
467 | event.Skip(); | |
468 | } | |
469 | } | |
470 | ||
471 | void wxListCtrlTextCtrlWrapper::OnKeyUp( wxKeyEvent &event ) | |
472 | { | |
473 | if (m_finished) | |
474 | { | |
475 | event.Skip(); | |
476 | return; | |
477 | } | |
478 | ||
479 | // auto-grow the textctrl: | |
480 | wxSize parentSize = m_owner->GetSize(); | |
481 | wxPoint myPos = m_text->GetPosition(); | |
482 | wxSize mySize = m_text->GetSize(); | |
483 | int sx, sy; | |
484 | m_text->GetTextExtent(m_text->GetValue() + _T("MM"), &sx, &sy); | |
485 | if (myPos.x + sx > parentSize.x) | |
486 | sx = parentSize.x - myPos.x; | |
487 | if (mySize.x > sx) | |
488 | sx = mySize.x; | |
489 | m_text->SetSize(sx, wxDefaultCoord); | |
490 | ||
491 | event.Skip(); | |
492 | } | |
493 | ||
494 | void wxListCtrlTextCtrlWrapper::OnKillFocus( wxFocusEvent &event ) | |
495 | { | |
496 | if ( !m_finished && !m_aboutToFinish ) | |
497 | { | |
498 | if ( !AcceptChanges() ) | |
499 | m_owner->OnRenameCancelled( m_itemEdited ); | |
500 | ||
501 | Finish(); | |
502 | } | |
503 | ||
504 | // We must let the native text control handle focus | |
505 | event.Skip(); | |
506 | } | |
507 | ||
508 | BEGIN_EVENT_TABLE(wxListCtrl, wxControl) | |
509 | EVT_LEFT_DOWN(wxListCtrl::OnLeftDown) | |
510 | EVT_LEFT_DCLICK(wxListCtrl::OnDblClick) | |
511 | EVT_MIDDLE_DOWN(wxListCtrl::OnMiddleDown) | |
512 | EVT_RIGHT_DOWN(wxListCtrl::OnRightDown) | |
513 | EVT_CHAR(wxListCtrl::OnChar) | |
514 | END_EVENT_TABLE() | |
515 | ||
516 | // ============================================================================ | |
517 | // implementation | |
518 | // ============================================================================ | |
519 | ||
520 | wxMacListControl* wxListCtrl::GetPeer() const | |
521 | { | |
522 | wxMacDataBrowserListCtrlControl *lb = wxDynamicCast(m_peer,wxMacDataBrowserListCtrlControl); | |
523 | return lb ? wx_static_cast(wxMacListControl*,lb) : 0 ; | |
524 | } | |
525 | ||
526 | // ---------------------------------------------------------------------------- | |
527 | // wxListCtrl construction | |
528 | // ---------------------------------------------------------------------------- | |
529 | ||
530 | void wxListCtrl::Init() | |
531 | { | |
532 | m_imageListNormal = NULL; | |
533 | m_imageListSmall = NULL; | |
534 | m_imageListState = NULL; | |
535 | ||
536 | // keep track of if we created our own image lists, or if they were assigned | |
537 | // to us. | |
538 | m_ownsImageListNormal = m_ownsImageListSmall = m_ownsImageListState = false; | |
539 | m_colCount = 0; | |
540 | m_count = 0; | |
541 | m_textCtrl = NULL; | |
542 | m_genericImpl = NULL; | |
543 | m_dbImpl = NULL; | |
544 | m_compareFunc = NULL; | |
545 | m_compareFuncData = 0; | |
546 | m_colsInfo = wxColumnList(); | |
547 | m_textColor = wxNullColour; | |
548 | m_bgColor = wxNullColour; | |
549 | m_textctrlWrapper = NULL; | |
550 | m_current = -1; | |
551 | m_renameTimer = new wxListCtrlRenameTimer( this ); | |
552 | } | |
553 | ||
554 | class wxGenericListCtrlHook : public wxGenericListCtrl | |
555 | { | |
556 | public: | |
557 | wxGenericListCtrlHook(wxListCtrl* parent, | |
558 | wxWindowID id, | |
559 | const wxPoint& pos, | |
560 | const wxSize& size, | |
561 | long style, | |
562 | const wxValidator& validator, | |
563 | const wxString& name) | |
564 | : wxGenericListCtrl(parent, id, pos, size, style, validator, name), | |
565 | m_nativeListCtrl(parent) | |
566 | { | |
567 | } | |
568 | ||
569 | protected: | |
570 | virtual wxListItemAttr * OnGetItemAttr(long item) const | |
571 | { | |
572 | return m_nativeListCtrl->OnGetItemAttr(item); | |
573 | } | |
574 | ||
575 | virtual int OnGetItemImage(long item) const | |
576 | { | |
577 | return m_nativeListCtrl->OnGetItemImage(item); | |
578 | } | |
579 | ||
580 | virtual int OnGetItemColumnImage(long item, long column) const | |
581 | { | |
582 | return m_nativeListCtrl->OnGetItemColumnImage(item, column); | |
583 | } | |
584 | ||
585 | virtual wxString OnGetItemText(long item, long column) const | |
586 | { | |
587 | return m_nativeListCtrl->OnGetItemText(item, column); | |
588 | } | |
589 | ||
590 | wxListCtrl* m_nativeListCtrl; | |
591 | ||
592 | }; | |
593 | ||
594 | void wxListCtrl::OnLeftDown(wxMouseEvent& event) | |
595 | { | |
596 | if ( m_textctrlWrapper ) | |
597 | { | |
598 | m_current = -1; | |
599 | m_textctrlWrapper->AcceptChangesAndFinish(); | |
600 | } | |
601 | ||
602 | int hitResult; | |
603 | long current = HitTest(event.GetPosition(), hitResult); | |
604 | if ((current == m_current) && | |
605 | (hitResult == wxLIST_HITTEST_ONITEM) && | |
606 | HasFlag(wxLC_EDIT_LABELS) ) | |
607 | { | |
608 | m_renameTimer->Start( 100, true ); | |
609 | } | |
610 | else | |
611 | { | |
612 | m_current = current; | |
613 | } | |
614 | event.Skip(); | |
615 | } | |
616 | ||
617 | void wxListCtrl::OnDblClick(wxMouseEvent& event) | |
618 | { | |
619 | m_current = -1; | |
620 | event.Skip(); | |
621 | } | |
622 | ||
623 | #if wxABI_VERSION >= 20801 | |
624 | void wxListCtrl::OnRightDown(wxMouseEvent& event) | |
625 | { | |
626 | if (m_dbImpl) | |
627 | FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, event.GetPosition()); | |
628 | event.Skip(); | |
629 | } | |
630 | ||
631 | void wxListCtrl::OnMiddleDown(wxMouseEvent& event) | |
632 | { | |
633 | if (m_dbImpl) | |
634 | FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, event.GetPosition()); | |
635 | event.Skip(); | |
636 | } | |
637 | ||
638 | void wxListCtrl::FireMouseEvent(wxEventType eventType, wxPoint position) | |
639 | { | |
640 | wxListEvent le( eventType, GetId() ); | |
641 | le.SetEventObject(this); | |
642 | le.m_pointDrag = position; | |
643 | le.m_itemIndex = -1; | |
644 | ||
645 | int flags; | |
646 | long item = HitTest(position, flags); | |
647 | if (flags & wxLIST_HITTEST_ONITEM) | |
648 | { | |
649 | le.m_itemIndex = item; | |
650 | le.m_item.m_itemId = item; | |
651 | GetItem(le.m_item); | |
652 | HandleWindowEvent(le); | |
653 | } | |
654 | } | |
655 | ||
656 | void wxListCtrl::OnChar(wxKeyEvent& event) | |
657 | { | |
658 | ||
659 | ||
660 | if (m_dbImpl) | |
661 | { | |
662 | wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetId() ); | |
663 | le.SetEventObject(this); | |
664 | le.m_code = event.GetKeyCode(); | |
665 | le.m_itemIndex = -1; | |
666 | ||
667 | if (m_current == -1) | |
668 | { | |
669 | // if m_current isn't set, check if there's been a selection | |
670 | // made before continuing | |
671 | m_current = GetNextItem(-1, wxLIST_NEXT_BELOW, wxLIST_STATE_SELECTED); | |
672 | } | |
673 | ||
674 | // We need to determine m_current ourselves when navigation keys | |
675 | // are used. Note that PAGEUP and PAGEDOWN do not alter the current | |
676 | // item on native Mac ListCtrl, so we only handle up and down keys. | |
677 | switch ( event.GetKeyCode() ) | |
678 | { | |
679 | case WXK_UP: | |
680 | if ( m_current > 0 ) | |
681 | m_current -= 1; | |
682 | else | |
683 | m_current = 0; | |
684 | ||
685 | break; | |
686 | ||
687 | case WXK_DOWN: | |
688 | if ( m_current < GetItemCount() - 1 ) | |
689 | m_current += 1; | |
690 | else | |
691 | m_current = GetItemCount() - 1; | |
692 | ||
693 | break; | |
694 | } | |
695 | ||
696 | if (m_current != -1) | |
697 | { | |
698 | le.m_itemIndex = m_current; | |
699 | le.m_item.m_itemId = m_current; | |
700 | GetItem(le.m_item); | |
701 | HandleWindowEvent(le); | |
702 | } | |
703 | } | |
704 | event.Skip(); | |
705 | } | |
706 | #endif | |
707 | ||
708 | bool wxListCtrl::Create(wxWindow *parent, | |
709 | wxWindowID id, | |
710 | const wxPoint& pos, | |
711 | const wxSize& size, | |
712 | long style, | |
713 | const wxValidator& validator, | |
714 | const wxString& name) | |
715 | { | |
716 | ||
717 | // for now, we'll always use the generic list control for ICON and LIST views, | |
718 | // because they dynamically change the number of columns on resize. | |
719 | // Also, allow the user to set it to use the list ctrl as well. | |
720 | if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL ) | |
721 | && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL ) == 1)) || | |
722 | (style & wxLC_ICON) || (style & wxLC_SMALL_ICON) || (style & wxLC_LIST) ) | |
723 | { | |
724 | m_macIsUserPane = true; | |
725 | ||
726 | long paneStyle = style; | |
727 | paneStyle &= ~wxSIMPLE_BORDER; | |
728 | paneStyle &= ~wxDOUBLE_BORDER; | |
729 | paneStyle &= ~wxSUNKEN_BORDER; | |
730 | paneStyle &= ~wxRAISED_BORDER; | |
731 | paneStyle &= ~wxSTATIC_BORDER; | |
732 | if ( !wxWindow::Create(parent, id, pos, size, paneStyle | wxNO_BORDER, name) ) | |
733 | return false; | |
734 | ||
735 | // since the generic control is a child, make sure we position it at 0, 0 | |
736 | m_genericImpl = new wxGenericListCtrlHook(this, id, wxPoint(0, 0), size, style, validator, name); | |
737 | m_genericImpl->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) ); | |
738 | return true; | |
739 | } | |
740 | ||
741 | else | |
742 | { | |
743 | m_macIsUserPane = false; | |
744 | if ( !wxWindow::Create(parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), name) ) | |
745 | return false; | |
746 | m_dbImpl = new wxMacDataBrowserListCtrlControl( this, pos, size, style ); | |
747 | m_peer = m_dbImpl; | |
748 | ||
749 | MacPostControlCreate( pos, size ); | |
750 | ||
751 | InstallControlEventHandler( m_peer->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(), | |
752 | GetEventTypeCount(eventList), eventList, this, | |
753 | (EventHandlerRef *)&m_macListCtrlEventHandler); | |
754 | } | |
755 | ||
756 | return true; | |
757 | } | |
758 | ||
759 | wxListCtrl::~wxListCtrl() | |
760 | { | |
761 | if (m_genericImpl) | |
762 | { | |
763 | m_genericImpl->PopEventHandler(/* deleteHandler = */ true); | |
764 | } | |
765 | ||
766 | if (m_ownsImageListNormal) | |
767 | delete m_imageListNormal; | |
768 | if (m_ownsImageListSmall) | |
769 | delete m_imageListSmall; | |
770 | if (m_ownsImageListState) | |
771 | delete m_imageListState; | |
772 | ||
773 | delete m_renameTimer; | |
774 | ||
775 | WX_CLEAR_LIST(wxColumnList, m_colsInfo); | |
776 | } | |
777 | ||
778 | /*static*/ | |
779 | wxVisualAttributes | |
780 | wxListCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
781 | { | |
782 | wxVisualAttributes attr; | |
783 | ||
784 | attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT ); | |
785 | attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ); | |
786 | attr.font.MacCreateFromThemeFont(kThemeViewsFont); | |
787 | ||
788 | return attr; | |
789 | } | |
790 | ||
791 | // ---------------------------------------------------------------------------- | |
792 | // set/get/change style | |
793 | // ---------------------------------------------------------------------------- | |
794 | ||
795 | // Add or remove a single window style | |
796 | void wxListCtrl::SetSingleStyle(long style, bool add) | |
797 | { | |
798 | long flag = GetWindowStyleFlag(); | |
799 | ||
800 | // Get rid of conflicting styles | |
801 | if ( add ) | |
802 | { | |
803 | if ( style & wxLC_MASK_TYPE) | |
804 | flag = flag & ~wxLC_MASK_TYPE; | |
805 | if ( style & wxLC_MASK_ALIGN ) | |
806 | flag = flag & ~wxLC_MASK_ALIGN; | |
807 | if ( style & wxLC_MASK_SORT ) | |
808 | flag = flag & ~wxLC_MASK_SORT; | |
809 | } | |
810 | ||
811 | if ( add ) | |
812 | flag |= style; | |
813 | else | |
814 | flag &= ~style; | |
815 | ||
816 | SetWindowStyleFlag(flag); | |
817 | } | |
818 | ||
819 | // Set the whole window style | |
820 | void wxListCtrl::SetWindowStyleFlag(long flag) | |
821 | { | |
822 | if ( flag != m_windowStyle ) | |
823 | { | |
824 | m_windowStyle = flag; | |
825 | ||
826 | if (m_genericImpl) | |
827 | { | |
828 | m_genericImpl->SetWindowStyleFlag(flag); | |
829 | } | |
830 | ||
831 | Refresh(); | |
832 | } | |
833 | } | |
834 | ||
835 | void wxListCtrl::DoSetSize( int x, int y, int width, int height, int sizeFlags ) | |
836 | { | |
837 | wxControl::DoSetSize(x, y, width, height, sizeFlags); | |
838 | ||
839 | if (m_genericImpl) | |
840 | m_genericImpl->SetSize(0, 0, width, height, sizeFlags); | |
841 | ||
842 | // determine if we need a horizontal scrollbar, and add it if so | |
843 | if (m_dbImpl) | |
844 | { | |
845 | int totalWidth = 0; | |
846 | for (int column = 0; column < GetColumnCount(); column++) | |
847 | { | |
848 | totalWidth += m_dbImpl->GetColumnWidth( column ); | |
849 | } | |
850 | ||
851 | if ( !(m_dbImpl->GetFlags() & wxHSCROLL) ) | |
852 | { | |
853 | Boolean vertScrollBar; | |
854 | GetDataBrowserHasScrollBars( m_dbImpl->GetControlRef(), NULL, &vertScrollBar ); | |
855 | if (totalWidth > width) | |
856 | SetDataBrowserHasScrollBars( m_dbImpl->GetControlRef(), true, vertScrollBar ); | |
857 | else | |
858 | SetDataBrowserHasScrollBars( m_dbImpl->GetControlRef(), false, vertScrollBar ); | |
859 | } | |
860 | } | |
861 | } | |
862 | ||
863 | wxSize wxListCtrl::DoGetBestSize() const | |
864 | { | |
865 | return wxWindow::DoGetBestSize(); | |
866 | } | |
867 | ||
868 | bool wxListCtrl::SetFont(const wxFont& font) | |
869 | { | |
870 | bool rv = true; | |
871 | rv = wxControl::SetFont(font); | |
872 | if (m_genericImpl) | |
873 | rv = m_genericImpl->SetFont(font); | |
874 | return rv; | |
875 | } | |
876 | ||
877 | bool wxListCtrl::SetForegroundColour(const wxColour& colour) | |
878 | { | |
879 | bool rv = true; | |
880 | if (m_genericImpl) | |
881 | rv = m_genericImpl->SetForegroundColour(colour); | |
882 | if (m_dbImpl) | |
883 | SetTextColour(colour); | |
884 | return rv; | |
885 | } | |
886 | ||
887 | bool wxListCtrl::SetBackgroundColour(const wxColour& colour) | |
888 | { | |
889 | bool rv = true; | |
890 | if (m_genericImpl) | |
891 | rv = m_genericImpl->SetBackgroundColour(colour); | |
892 | if (m_dbImpl) | |
893 | m_bgColor = colour; | |
894 | return rv; | |
895 | } | |
896 | ||
0b134cd0 | 897 | wxColour wxListCtrl::GetBackgroundColour() const |
489468fe SC |
898 | { |
899 | if (m_genericImpl) | |
900 | return m_genericImpl->GetBackgroundColour(); | |
901 | if (m_dbImpl) | |
902 | return m_bgColor; | |
903 | ||
904 | return wxNullColour; | |
905 | } | |
906 | ||
907 | // ---------------------------------------------------------------------------- | |
908 | // accessors | |
909 | // ---------------------------------------------------------------------------- | |
910 | ||
911 | // Gets information about this column | |
912 | bool wxListCtrl::GetColumn(int col, wxListItem& item) const | |
913 | { | |
914 | if (m_genericImpl) | |
915 | return m_genericImpl->GetColumn(col, item); | |
916 | ||
917 | bool success = true; | |
918 | ||
919 | if (m_dbImpl) | |
920 | { | |
921 | wxColumnList::compatibility_iterator node = m_colsInfo.Item( col ); | |
922 | wxASSERT_MSG( node, _T("invalid column index in wxMacListCtrlItem") ); | |
923 | wxListItem* column = node->GetData(); | |
924 | ||
925 | long mask = column->GetMask(); | |
926 | if (mask & wxLIST_MASK_TEXT) | |
927 | item.SetText(column->GetText()); | |
928 | if (mask & wxLIST_MASK_DATA) | |
929 | item.SetData(column->GetData()); | |
930 | if (mask & wxLIST_MASK_IMAGE) | |
931 | item.SetImage(column->GetImage()); | |
932 | if (mask & wxLIST_MASK_STATE) | |
933 | item.SetState(column->GetState()); | |
934 | if (mask & wxLIST_MASK_FORMAT) | |
935 | item.SetAlign(column->GetAlign()); | |
936 | if (mask & wxLIST_MASK_WIDTH) | |
937 | item.SetWidth(column->GetWidth()); | |
938 | } | |
939 | ||
940 | return success; | |
941 | } | |
942 | ||
943 | // Sets information about this column | |
944 | bool wxListCtrl::SetColumn(int col, wxListItem& item) | |
945 | { | |
946 | if (m_genericImpl) | |
947 | return m_genericImpl->SetColumn(col, item); | |
948 | ||
949 | if (m_dbImpl) | |
950 | { | |
951 | long mask = item.GetMask(); | |
952 | if ( col >= (int)m_colsInfo.GetCount() ) | |
953 | { | |
954 | wxListItem* listItem = new wxListItem(item); | |
955 | m_colsInfo.Append( listItem ); | |
956 | } | |
957 | else | |
958 | { | |
959 | wxListItem listItem; | |
960 | GetColumn( col, listItem ); | |
961 | ||
962 | if (mask & wxLIST_MASK_TEXT) | |
963 | listItem.SetText(item.GetText()); | |
964 | if (mask & wxLIST_MASK_DATA) | |
965 | listItem.SetData(item.GetData()); | |
966 | if (mask & wxLIST_MASK_IMAGE) | |
967 | listItem.SetImage(item.GetImage()); | |
968 | if (mask & wxLIST_MASK_STATE) | |
969 | listItem.SetState(item.GetState()); | |
970 | if (mask & wxLIST_MASK_FORMAT) | |
971 | listItem.SetAlign(item.GetAlign()); | |
972 | if (mask & wxLIST_MASK_WIDTH) | |
973 | listItem.SetWidth(item.GetWidth()); | |
974 | } | |
975 | ||
976 | // change the appearance in the databrowser. | |
977 | DataBrowserListViewHeaderDesc columnDesc; | |
978 | columnDesc.version=kDataBrowserListViewLatestHeaderDesc; | |
979 | verify_noerr( m_dbImpl->GetHeaderDesc( kMinColumnId + col, &columnDesc ) ); | |
980 | ||
981 | /* | |
982 | if (item.GetMask() & wxLIST_MASK_TEXT) | |
983 | { | |
984 | wxFontEncoding enc; | |
985 | if ( m_font.Ok() ) | |
986 | enc = GetFont().GetEncoding(); | |
987 | else | |
988 | enc = wxLocale::GetSystemEncoding(); | |
989 | wxCFStringRef cfTitle; | |
990 | cfTitle.Assign( item.GetText() , enc ); | |
991 | if(columnDesc.titleString) | |
992 | CFRelease(columnDesc.titleString); | |
993 | columnDesc.titleString = cfTitle; | |
994 | } | |
995 | */ | |
996 | ||
997 | if (item.GetMask() & wxLIST_MASK_IMAGE && item.GetImage() != -1 ) | |
998 | { | |
999 | wxImageList* imageList = GetImageList(wxIMAGE_LIST_SMALL); | |
1000 | if (imageList && imageList->GetImageCount() > 0 ) | |
1001 | { | |
1002 | wxBitmap bmp = imageList->GetBitmap( item.GetImage() ); | |
1003 | IconRef icon = bmp.GetIconRef(); | |
1004 | columnDesc.btnContentInfo.u.iconRef = icon; | |
1005 | columnDesc.btnContentInfo.contentType = kControlContentIconRef; | |
1006 | } | |
1007 | } | |
1008 | ||
1009 | verify_noerr( m_dbImpl->SetHeaderDesc( kMinColumnId + col, &columnDesc ) ); | |
1010 | ||
1011 | } | |
1012 | return true; | |
1013 | } | |
1014 | ||
1015 | int wxListCtrl::GetColumnCount() const | |
1016 | { | |
1017 | if (m_genericImpl) | |
1018 | return m_genericImpl->GetColumnCount(); | |
1019 | ||
1020 | if (m_dbImpl) | |
1021 | { | |
1022 | UInt32 count; | |
1023 | m_dbImpl->GetColumnCount(&count); | |
1024 | return count; | |
1025 | } | |
1026 | ||
1027 | return m_colCount; | |
1028 | } | |
1029 | ||
1030 | // Gets the column width | |
1031 | int wxListCtrl::GetColumnWidth(int col) const | |
1032 | { | |
1033 | if (m_genericImpl) | |
1034 | return m_genericImpl->GetColumnWidth(col); | |
1035 | ||
1036 | if (m_dbImpl) | |
1037 | { | |
1038 | return m_dbImpl->GetColumnWidth(col); | |
1039 | } | |
1040 | ||
1041 | return 0; | |
1042 | } | |
1043 | ||
1044 | // Sets the column width | |
1045 | bool wxListCtrl::SetColumnWidth(int col, int width) | |
1046 | { | |
1047 | if (m_genericImpl) | |
1048 | return m_genericImpl->SetColumnWidth(col, width); | |
1049 | ||
1050 | if (m_dbImpl) | |
1051 | { | |
1052 | if ( width == wxLIST_AUTOSIZE_USEHEADER ) | |
1053 | { | |
1054 | width = 150; // FIXME | |
1055 | } | |
1056 | ||
1057 | if (col == -1) | |
1058 | { | |
1059 | for (int column = 0; column < GetColumnCount(); column++) | |
1060 | { | |
1061 | wxListItem colInfo; | |
1062 | GetColumn(column, colInfo); | |
1063 | ||
1064 | colInfo.SetWidth(width); | |
1065 | SetColumn(column, colInfo); | |
1066 | ||
1067 | const int mywidth = (width == wxLIST_AUTOSIZE) | |
1068 | ? CalcColumnAutoWidth(column) : width; | |
1069 | m_dbImpl->SetColumnWidth(column, mywidth); | |
1070 | } | |
1071 | } | |
1072 | else | |
1073 | { | |
1074 | if ( width == wxLIST_AUTOSIZE ) | |
1075 | width = CalcColumnAutoWidth(col); | |
1076 | ||
1077 | wxListItem colInfo; | |
1078 | GetColumn(col, colInfo); | |
1079 | ||
1080 | colInfo.SetWidth(width); | |
1081 | SetColumn(col, colInfo); | |
1082 | m_dbImpl->SetColumnWidth(col, width); | |
1083 | } | |
1084 | return true; | |
1085 | } | |
1086 | ||
1087 | return false; | |
1088 | } | |
1089 | ||
1090 | // Gets the number of items that can fit vertically in the | |
1091 | // visible area of the list control (list or report view) | |
1092 | // or the total number of items in the list control (icon | |
1093 | // or small icon view) | |
1094 | int wxListCtrl::GetCountPerPage() const | |
1095 | { | |
1096 | if (m_genericImpl) | |
1097 | return m_genericImpl->GetCountPerPage(); | |
1098 | ||
1099 | if (m_dbImpl) | |
1100 | { | |
1101 | UInt16 height = 1; | |
1102 | m_dbImpl->GetDefaultRowHeight( &height ); | |
1103 | if (height > 0) | |
1104 | return GetClientSize().y / height; | |
1105 | } | |
1106 | ||
1107 | return 1; | |
1108 | } | |
1109 | ||
1110 | // Gets the edit control for editing labels. | |
1111 | wxTextCtrl* wxListCtrl::GetEditControl() const | |
1112 | { | |
1113 | if (m_genericImpl) | |
1114 | return m_genericImpl->GetEditControl(); | |
1115 | ||
1116 | return NULL; | |
1117 | } | |
1118 | ||
1119 | // Gets information about the item | |
1120 | bool wxListCtrl::GetItem(wxListItem& info) const | |
1121 | { | |
1122 | if (m_genericImpl) | |
1123 | return m_genericImpl->GetItem(info); | |
1124 | ||
1125 | if (m_dbImpl) | |
1126 | { | |
1127 | if (!IsVirtual()) | |
1128 | { | |
1129 | if (info.m_itemId >= 0 && info.m_itemId < GetItemCount()) | |
1130 | { | |
1131 | m_dbImpl->MacGetColumnInfo(info.m_itemId, info.m_col, info); | |
1132 | if (info.GetMask() & wxLIST_MASK_STATE) | |
1133 | { | |
1134 | DataBrowserItemID id = (DataBrowserItemID)m_dbImpl->GetItemFromLine(info.m_itemId); | |
1135 | if (IsDataBrowserItemSelected( m_dbImpl->GetControlRef(), id )) | |
1136 | info.SetState(info.GetState() | wxLIST_STATE_SELECTED); | |
1137 | } | |
1138 | } | |
1139 | } | |
1140 | else | |
1141 | { | |
1142 | if (info.m_itemId >= 0 && info.m_itemId < GetItemCount()) | |
1143 | { | |
1144 | info.SetText( OnGetItemText(info.m_itemId, info.m_col) ); | |
1145 | info.SetImage( OnGetItemColumnImage(info.m_itemId, info.m_col) ); | |
1146 | if (info.GetMask() & wxLIST_MASK_STATE) | |
1147 | { | |
1148 | if (IsDataBrowserItemSelected( m_dbImpl->GetControlRef(), info.m_itemId+1 )) | |
1149 | info.SetState(info.GetState() | wxLIST_STATE_SELECTED); | |
1150 | } | |
1151 | ||
1152 | wxListItemAttr* attrs = OnGetItemAttr( info.m_itemId ); | |
1153 | if (attrs) | |
1154 | { | |
1155 | info.SetFont( attrs->GetFont() ); | |
1156 | info.SetBackgroundColour( attrs->GetBackgroundColour() ); | |
1157 | info.SetTextColour( attrs->GetTextColour() ); | |
1158 | } | |
1159 | } | |
1160 | } | |
1161 | } | |
1162 | bool success = true; | |
1163 | return success; | |
1164 | } | |
1165 | ||
1166 | // Sets information about the item | |
1167 | bool wxListCtrl::SetItem(wxListItem& info) | |
1168 | { | |
1169 | if (m_genericImpl) | |
1170 | return m_genericImpl->SetItem(info); | |
1171 | ||
1172 | if (m_dbImpl) | |
1173 | m_dbImpl->MacSetColumnInfo( info.m_itemId, info.m_col, &info ); | |
1174 | ||
1175 | return true; | |
1176 | } | |
1177 | ||
1178 | long wxListCtrl::SetItem(long index, int col, const wxString& label, int imageId) | |
1179 | { | |
1180 | if (m_genericImpl) | |
1181 | return m_genericImpl->SetItem(index, col, label, imageId); | |
1182 | ||
1183 | wxListItem info; | |
1184 | info.m_text = label; | |
1185 | info.m_mask = wxLIST_MASK_TEXT; | |
1186 | info.m_itemId = index; | |
1187 | info.m_col = col; | |
1188 | if ( imageId > -1 ) | |
1189 | { | |
1190 | info.m_image = imageId; | |
1191 | info.m_mask |= wxLIST_MASK_IMAGE; | |
1192 | } | |
1193 | return SetItem(info); | |
1194 | } | |
1195 | ||
1196 | ||
1197 | // Gets the item state | |
1198 | int wxListCtrl::GetItemState(long item, long stateMask) const | |
1199 | { | |
1200 | if (m_genericImpl) | |
1201 | return m_genericImpl->GetItemState(item, stateMask); | |
1202 | ||
1203 | if (m_dbImpl) | |
1204 | { | |
1205 | if ( HasFlag(wxLC_VIRTUAL) ) | |
1206 | { | |
1207 | if (stateMask == wxLIST_STATE_SELECTED) | |
1208 | { | |
1209 | if (IsDataBrowserItemSelected( m_dbImpl->GetControlRef(), item+1 )) | |
1210 | return wxLIST_STATE_SELECTED; | |
1211 | else | |
1212 | return 0; | |
1213 | } | |
1214 | } | |
1215 | else | |
1216 | { | |
1217 | wxListItem info; | |
1218 | ||
1219 | info.m_mask = wxLIST_MASK_STATE; | |
1220 | info.m_stateMask = stateMask; | |
1221 | info.m_itemId = item; | |
1222 | ||
1223 | if (!GetItem(info)) | |
1224 | return 0; | |
1225 | ||
1226 | return info.m_state; | |
1227 | } | |
1228 | } | |
1229 | ||
1230 | return 0; | |
1231 | } | |
1232 | ||
1233 | // Sets the item state | |
1234 | bool wxListCtrl::SetItemState(long item, long state, long stateMask) | |
1235 | { | |
1236 | if (m_genericImpl) | |
1237 | return m_genericImpl->SetItemState(item, state, stateMask); | |
1238 | ||
1239 | if (m_dbImpl) | |
1240 | { | |
1241 | DataBrowserSetOption option = kDataBrowserItemsAdd; | |
1242 | if ( (stateMask & wxLIST_STATE_SELECTED) && state == 0 ) | |
1243 | option = kDataBrowserItemsRemove; | |
1244 | ||
1245 | if (item == -1) | |
1246 | { | |
1247 | if ( HasFlag(wxLC_VIRTUAL) ) | |
1248 | { | |
1249 | wxMacDataItemBrowserSelectionSuppressor suppressor(m_dbImpl); | |
1250 | m_dbImpl->SetSelectedAllItems(option); | |
1251 | } | |
1252 | else | |
1253 | { | |
1254 | for(int i = 0; i < GetItemCount();i++) | |
1255 | { | |
1256 | wxListItem info; | |
1257 | info.m_itemId = i; | |
1258 | info.m_mask = wxLIST_MASK_STATE; | |
1259 | info.m_stateMask = stateMask; | |
1260 | info.m_state = state; | |
1261 | SetItem(info); | |
1262 | } | |
1263 | } | |
1264 | } | |
1265 | else | |
1266 | { | |
1267 | if ( HasFlag(wxLC_VIRTUAL) ) | |
1268 | { | |
1269 | long itemID = item+1; | |
1270 | bool isSelected = IsDataBrowserItemSelected(m_dbImpl->GetControlRef(), (DataBrowserItemID)itemID ); | |
1271 | bool isSelectedState = (state == wxLIST_STATE_SELECTED); | |
1272 | ||
1273 | // toggle the selection state if wxListInfo state and actual state don't match. | |
1274 | if ( (stateMask & wxLIST_STATE_SELECTED) && isSelected != isSelectedState ) | |
1275 | { | |
1276 | SetDataBrowserSelectedItems(m_dbImpl->GetControlRef(), 1, (DataBrowserItemID*)&itemID, option); | |
1277 | } | |
1278 | } | |
1279 | else | |
1280 | { | |
1281 | wxListItem info; | |
1282 | info.m_itemId = item; | |
1283 | info.m_mask = wxLIST_MASK_STATE; | |
1284 | info.m_stateMask = stateMask; | |
1285 | info.m_state = state; | |
1286 | return SetItem(info); | |
1287 | } | |
1288 | } | |
1289 | } | |
1290 | return true; | |
1291 | } | |
1292 | ||
1293 | // Sets the item image | |
1294 | bool wxListCtrl::SetItemImage(long item, int image, int WXUNUSED(selImage)) | |
1295 | { | |
1296 | return SetItemColumnImage(item, 0, image); | |
1297 | } | |
1298 | ||
1299 | // Sets the item image | |
1300 | bool wxListCtrl::SetItemColumnImage(long item, long column, int image) | |
1301 | { | |
1302 | if (m_genericImpl) | |
1303 | return m_genericImpl->SetItemColumnImage(item, column, image); | |
1304 | ||
1305 | wxListItem info; | |
1306 | ||
1307 | info.m_mask = wxLIST_MASK_IMAGE; | |
1308 | info.m_image = image; | |
1309 | info.m_itemId = item; | |
1310 | info.m_col = column; | |
1311 | ||
1312 | return SetItem(info); | |
1313 | } | |
1314 | ||
1315 | // Gets the item text | |
1316 | wxString wxListCtrl::GetItemText(long item) const | |
1317 | { | |
1318 | if (m_genericImpl) | |
1319 | return m_genericImpl->GetItemText(item); | |
1320 | ||
1321 | wxListItem info; | |
1322 | ||
1323 | info.m_mask = wxLIST_MASK_TEXT; | |
1324 | info.m_itemId = item; | |
1325 | ||
1326 | if (!GetItem(info)) | |
1327 | return wxEmptyString; | |
1328 | return info.m_text; | |
1329 | } | |
1330 | ||
1331 | // Sets the item text | |
1332 | void wxListCtrl::SetItemText(long item, const wxString& str) | |
1333 | { | |
1334 | if (m_genericImpl) | |
1335 | return m_genericImpl->SetItemText(item, str); | |
1336 | ||
1337 | wxListItem info; | |
1338 | ||
1339 | info.m_mask = wxLIST_MASK_TEXT; | |
1340 | info.m_itemId = item; | |
1341 | info.m_text = str; | |
1342 | ||
1343 | SetItem(info); | |
1344 | } | |
1345 | ||
1346 | // Gets the item data | |
1347 | long wxListCtrl::GetItemData(long item) const | |
1348 | { | |
1349 | if (m_genericImpl) | |
1350 | return m_genericImpl->GetItemData(item); | |
1351 | ||
1352 | wxListItem info; | |
1353 | ||
1354 | info.m_mask = wxLIST_MASK_DATA; | |
1355 | info.m_itemId = item; | |
1356 | ||
1357 | if (!GetItem(info)) | |
1358 | return 0; | |
1359 | return info.m_data; | |
1360 | } | |
1361 | ||
1362 | // Sets the item data | |
1363 | bool wxListCtrl::SetItemPtrData(long item, wxUIntPtr data) | |
1364 | { | |
1365 | if (m_genericImpl) | |
1366 | return m_genericImpl->SetItemData(item, data); | |
1367 | ||
1368 | wxListItem info; | |
1369 | ||
1370 | info.m_mask = wxLIST_MASK_DATA; | |
1371 | info.m_itemId = item; | |
1372 | info.m_data = data; | |
1373 | ||
1374 | return SetItem(info); | |
1375 | } | |
1376 | ||
1377 | wxRect wxListCtrl::GetViewRect() const | |
1378 | { | |
1379 | wxASSERT_MSG( !HasFlag(wxLC_REPORT | wxLC_LIST), | |
1380 | _T("wxListCtrl::GetViewRect() only works in icon mode") ); | |
1381 | ||
1382 | if (m_genericImpl) | |
1383 | return m_genericImpl->GetViewRect(); | |
1384 | ||
1385 | wxRect rect; | |
1386 | return rect; | |
1387 | } | |
1388 | ||
1389 | // Gets the item rectangle | |
1390 | bool wxListCtrl::GetItemRect(long item, wxRect& rect, int code) const | |
1391 | { | |
1392 | if (m_genericImpl) | |
1393 | return m_genericImpl->GetItemRect(item, rect, code); | |
1394 | ||
1395 | ||
1396 | if (m_dbImpl) | |
1397 | { | |
1398 | DataBrowserItemID id; | |
1399 | DataBrowserPropertyID col = kMinColumnId; | |
1400 | Rect bounds; | |
1401 | DataBrowserPropertyPart part = kDataBrowserPropertyEnclosingPart; | |
1402 | if ( code == wxLIST_RECT_LABEL ) | |
1403 | part = kDataBrowserPropertyTextPart; | |
1404 | else if ( code == wxLIST_RECT_ICON ) | |
1405 | part = kDataBrowserPropertyIconPart; | |
1406 | ||
1407 | if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL) ) | |
1408 | { | |
1409 | wxMacDataItem* thisItem = m_dbImpl->GetItemFromLine(item); | |
1410 | id = (DataBrowserItemID) thisItem; | |
1411 | } | |
1412 | else | |
1413 | id = item+1; | |
1414 | ||
1415 | GetDataBrowserItemPartBounds( m_dbImpl->GetControlRef(), id, col, part, &bounds ); | |
1416 | ||
1417 | rect.x = bounds.left; | |
1418 | rect.y = bounds.top; | |
1419 | rect.width = bounds.right - bounds.left; //GetClientSize().x; // we need the width of the whole row, not just the item. | |
1420 | rect.height = bounds.bottom - bounds.top; | |
1421 | //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height); | |
1422 | } | |
1423 | return true; | |
1424 | } | |
1425 | ||
1426 | // Gets the item position | |
1427 | bool wxListCtrl::GetItemPosition(long item, wxPoint& pos) const | |
1428 | { | |
1429 | if (m_genericImpl) | |
1430 | return m_genericImpl->GetItemPosition(item, pos); | |
1431 | ||
1432 | bool success = false; | |
1433 | ||
1434 | if (m_dbImpl) | |
1435 | { | |
1436 | wxRect itemRect; | |
1437 | GetItemRect(item, itemRect); | |
1438 | pos = itemRect.GetPosition(); | |
1439 | success = true; | |
1440 | } | |
1441 | ||
1442 | return success; | |
1443 | } | |
1444 | ||
1445 | // Sets the item position. | |
1446 | bool wxListCtrl::SetItemPosition(long item, const wxPoint& pos) | |
1447 | { | |
1448 | if (m_genericImpl) | |
1449 | return m_genericImpl->SetItemPosition(item, pos); | |
1450 | ||
1451 | return false; | |
1452 | } | |
1453 | ||
1454 | // Gets the number of items in the list control | |
1455 | int wxListCtrl::GetItemCount() const | |
1456 | { | |
1457 | if (m_genericImpl) | |
1458 | return m_genericImpl->GetItemCount(); | |
1459 | ||
1460 | if (m_dbImpl) | |
1461 | return m_dbImpl->MacGetCount(); | |
1462 | ||
1463 | return m_count; | |
1464 | } | |
1465 | ||
1466 | void wxListCtrl::SetItemSpacing( int spacing, bool isSmall ) | |
1467 | { | |
1468 | if (m_genericImpl) | |
1469 | m_genericImpl->SetItemSpacing(spacing, isSmall); | |
1470 | } | |
1471 | ||
1472 | wxSize wxListCtrl::GetItemSpacing() const | |
1473 | { | |
1474 | if (m_genericImpl) | |
1475 | return m_genericImpl->GetItemSpacing(); | |
1476 | ||
1477 | return wxSize(0, 0); | |
1478 | } | |
1479 | ||
1480 | void wxListCtrl::SetItemTextColour( long item, const wxColour &col ) | |
1481 | { | |
1482 | if (m_genericImpl) | |
1483 | { | |
1484 | m_genericImpl->SetItemTextColour(item, col); | |
1485 | return; | |
1486 | } | |
1487 | ||
1488 | wxListItem info; | |
1489 | info.m_itemId = item; | |
1490 | info.SetTextColour( col ); | |
1491 | SetItem( info ); | |
1492 | } | |
1493 | ||
1494 | wxColour wxListCtrl::GetItemTextColour( long item ) const | |
1495 | { | |
1496 | if (m_genericImpl) | |
1497 | return m_genericImpl->GetItemTextColour(item); | |
1498 | ||
1499 | if (m_dbImpl) | |
1500 | { | |
1501 | wxListItem info; | |
1502 | if (GetItem(info)) | |
1503 | return info.GetTextColour(); | |
1504 | } | |
1505 | return wxNullColour; | |
1506 | } | |
1507 | ||
1508 | void wxListCtrl::SetItemBackgroundColour( long item, const wxColour &col ) | |
1509 | { | |
1510 | if (m_genericImpl) | |
1511 | { | |
1512 | m_genericImpl->SetItemBackgroundColour(item, col); | |
1513 | return; | |
1514 | } | |
1515 | ||
1516 | wxListItem info; | |
1517 | info.m_itemId = item; | |
1518 | info.SetBackgroundColour( col ); | |
1519 | SetItem( info ); | |
1520 | } | |
1521 | ||
1522 | wxColour wxListCtrl::GetItemBackgroundColour( long item ) const | |
1523 | { | |
1524 | if (m_genericImpl) | |
1525 | return m_genericImpl->GetItemBackgroundColour(item); | |
1526 | ||
1527 | if (m_dbImpl) | |
1528 | { | |
1529 | wxListItem info; | |
1530 | if (GetItem(info)) | |
1531 | return info.GetBackgroundColour(); | |
1532 | } | |
1533 | return wxNullColour; | |
1534 | } | |
1535 | ||
1536 | void wxListCtrl::SetItemFont( long item, const wxFont &f ) | |
1537 | { | |
1538 | if (m_genericImpl) | |
1539 | { | |
1540 | m_genericImpl->SetItemFont(item, f); | |
1541 | return; | |
1542 | } | |
1543 | ||
1544 | wxListItem info; | |
1545 | info.m_itemId = item; | |
1546 | info.SetFont( f ); | |
1547 | SetItem( info ); | |
1548 | } | |
1549 | ||
1550 | wxFont wxListCtrl::GetItemFont( long item ) const | |
1551 | { | |
1552 | if (m_genericImpl) | |
1553 | return m_genericImpl->GetItemFont(item); | |
1554 | ||
1555 | if (m_dbImpl) | |
1556 | { | |
1557 | wxListItem info; | |
1558 | if (GetItem(info)) | |
1559 | return info.GetFont(); | |
1560 | } | |
1561 | ||
1562 | return wxNullFont; | |
1563 | } | |
1564 | ||
1565 | // Gets the number of selected items in the list control | |
1566 | int wxListCtrl::GetSelectedItemCount() const | |
1567 | { | |
1568 | if (m_genericImpl) | |
1569 | return m_genericImpl->GetSelectedItemCount(); | |
1570 | ||
1571 | if (m_dbImpl) | |
1572 | return m_dbImpl->GetSelectedItemCount(NULL, true); | |
1573 | ||
1574 | return 0; | |
1575 | } | |
1576 | ||
1577 | // Gets the text colour of the listview | |
1578 | wxColour wxListCtrl::GetTextColour() const | |
1579 | { | |
1580 | if (m_genericImpl) | |
1581 | return m_genericImpl->GetTextColour(); | |
1582 | ||
1583 | // TODO: we need owner drawn list items to customize text color. | |
1584 | if (m_dbImpl) | |
1585 | return m_textColor; | |
1586 | ||
1587 | return wxNullColour; | |
1588 | } | |
1589 | ||
1590 | // Sets the text colour of the listview | |
1591 | void wxListCtrl::SetTextColour(const wxColour& col) | |
1592 | { | |
1593 | if (m_genericImpl) | |
1594 | { | |
1595 | m_genericImpl->SetTextColour(col); | |
1596 | return; | |
1597 | } | |
1598 | ||
1599 | if (m_dbImpl) | |
1600 | m_textColor = col; | |
1601 | } | |
1602 | ||
1603 | // Gets the index of the topmost visible item when in | |
1604 | // list or report view | |
1605 | long wxListCtrl::GetTopItem() const | |
1606 | { | |
1607 | if (m_genericImpl) | |
1608 | return m_genericImpl->GetTopItem(); | |
1609 | ||
1610 | if (m_dbImpl) | |
1611 | { | |
1612 | int flags = 0; | |
1613 | long item = HitTest( wxPoint(1, 1), flags); | |
1614 | if (flags == wxLIST_HITTEST_ONITEM) | |
1615 | return item; | |
1616 | } | |
1617 | ||
1618 | return 0; | |
1619 | } | |
1620 | ||
1621 | // Searches for an item, starting from 'item'. | |
1622 | // 'geometry' is one of | |
1623 | // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT. | |
1624 | // 'state' is a state bit flag, one or more of | |
1625 | // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT. | |
1626 | // item can be -1 to find the first item that matches the | |
1627 | // specified flags. | |
1628 | // Returns the item or -1 if unsuccessful. | |
1629 | long wxListCtrl::GetNextItem(long item, int geom, int state) const | |
1630 | { | |
1631 | if (m_genericImpl) | |
1632 | return m_genericImpl->GetNextItem(item, geom, state); | |
1633 | ||
1634 | // TODO: implement all geometry and state options? | |
1635 | if ( m_dbImpl ) | |
1636 | { | |
1637 | if ( geom == wxLIST_NEXT_ALL || geom == wxLIST_NEXT_BELOW ) | |
1638 | { | |
1639 | long count = m_dbImpl->MacGetCount() ; | |
1640 | for ( long line = item + 1 ; line < count; line++ ) | |
1641 | { | |
1642 | DataBrowserItemID id = line + 1; | |
1643 | if ( !IsVirtual() ) | |
1644 | id = (DataBrowserItemID)m_dbImpl->GetItemFromLine(line); | |
1645 | ||
1646 | if ( (state == wxLIST_STATE_DONTCARE ) ) | |
1647 | return line; | |
1648 | ||
1649 | if ( (state & wxLIST_STATE_SELECTED) && IsDataBrowserItemSelected(m_dbImpl->GetControlRef(), id ) ) | |
1650 | return line; | |
1651 | } | |
1652 | } | |
1653 | ||
1654 | if ( geom == wxLIST_NEXT_ABOVE ) | |
1655 | { | |
1656 | int item2 = item; | |
1657 | if ( item2 == -1 ) | |
1658 | item2 = m_dbImpl->MacGetCount(); | |
1659 | ||
1660 | for ( long line = item2 - 1 ; line >= 0; line-- ) | |
1661 | { | |
1662 | DataBrowserItemID id = line + 1; | |
1663 | if ( !IsVirtual() ) | |
1664 | id = (DataBrowserItemID)m_dbImpl->GetItemFromLine(line); | |
1665 | ||
1666 | if ( (state == wxLIST_STATE_DONTCARE ) ) | |
1667 | return line; | |
1668 | ||
1669 | if ( (state & wxLIST_STATE_SELECTED) && IsDataBrowserItemSelected(m_dbImpl->GetControlRef(), id ) ) | |
1670 | return line; | |
1671 | } | |
1672 | } | |
1673 | } | |
1674 | ||
1675 | return -1; | |
1676 | } | |
1677 | ||
1678 | ||
1679 | wxImageList *wxListCtrl::GetImageList(int which) const | |
1680 | { | |
1681 | if (m_genericImpl) | |
1682 | return m_genericImpl->GetImageList(which); | |
1683 | ||
1684 | if ( which == wxIMAGE_LIST_NORMAL ) | |
1685 | { | |
1686 | return m_imageListNormal; | |
1687 | } | |
1688 | else if ( which == wxIMAGE_LIST_SMALL ) | |
1689 | { | |
1690 | return m_imageListSmall; | |
1691 | } | |
1692 | else if ( which == wxIMAGE_LIST_STATE ) | |
1693 | { | |
1694 | return m_imageListState; | |
1695 | } | |
1696 | return NULL; | |
1697 | } | |
1698 | ||
1699 | void wxListCtrl::SetImageList(wxImageList *imageList, int which) | |
1700 | { | |
1701 | if (m_genericImpl) | |
1702 | { | |
1703 | m_genericImpl->SetImageList(imageList, which); | |
1704 | return; | |
1705 | } | |
1706 | ||
1707 | if ( which == wxIMAGE_LIST_NORMAL ) | |
1708 | { | |
1709 | if (m_ownsImageListNormal) delete m_imageListNormal; | |
1710 | m_imageListNormal = imageList; | |
1711 | m_ownsImageListNormal = false; | |
1712 | } | |
1713 | else if ( which == wxIMAGE_LIST_SMALL ) | |
1714 | { | |
1715 | if (m_ownsImageListSmall) delete m_imageListSmall; | |
1716 | m_imageListSmall = imageList; | |
1717 | m_ownsImageListSmall = false; | |
1718 | } | |
1719 | else if ( which == wxIMAGE_LIST_STATE ) | |
1720 | { | |
1721 | if (m_ownsImageListState) delete m_imageListState; | |
1722 | m_imageListState = imageList; | |
1723 | m_ownsImageListState = false; | |
1724 | } | |
1725 | } | |
1726 | ||
1727 | void wxListCtrl::AssignImageList(wxImageList *imageList, int which) | |
1728 | { | |
1729 | if (m_genericImpl) | |
1730 | { | |
1731 | m_genericImpl->AssignImageList(imageList, which); | |
1732 | return; | |
1733 | } | |
1734 | ||
1735 | SetImageList(imageList, which); | |
1736 | if ( which == wxIMAGE_LIST_NORMAL ) | |
1737 | m_ownsImageListNormal = true; | |
1738 | else if ( which == wxIMAGE_LIST_SMALL ) | |
1739 | m_ownsImageListSmall = true; | |
1740 | else if ( which == wxIMAGE_LIST_STATE ) | |
1741 | m_ownsImageListState = true; | |
1742 | } | |
1743 | ||
1744 | // ---------------------------------------------------------------------------- | |
1745 | // Operations | |
1746 | // ---------------------------------------------------------------------------- | |
1747 | ||
1748 | // Arranges the items | |
1749 | bool wxListCtrl::Arrange(int flag) | |
1750 | { | |
1751 | if (m_genericImpl) | |
1752 | return m_genericImpl->Arrange(flag); | |
1753 | return false; | |
1754 | } | |
1755 | ||
1756 | // Deletes an item | |
1757 | bool wxListCtrl::DeleteItem(long item) | |
1758 | { | |
1759 | if (m_genericImpl) | |
1760 | return m_genericImpl->DeleteItem(item); | |
1761 | ||
1762 | if (m_dbImpl) | |
1763 | { | |
1764 | m_dbImpl->MacDelete(item); | |
1765 | wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ITEM, GetId() ); | |
1766 | event.SetEventObject( this ); | |
1767 | event.m_itemIndex = item; | |
1768 | HandleWindowEvent( event ); | |
1769 | ||
1770 | } | |
1771 | return true; | |
1772 | } | |
1773 | ||
1774 | // Deletes all items | |
1775 | bool wxListCtrl::DeleteAllItems() | |
1776 | { | |
1777 | if (m_genericImpl) | |
1778 | return m_genericImpl->DeleteAllItems(); | |
1779 | ||
1780 | if (m_dbImpl) | |
1781 | { | |
1782 | m_dbImpl->MacClear(); | |
1783 | wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetId() ); | |
1784 | event.SetEventObject( this ); | |
1785 | HandleWindowEvent( event ); | |
1786 | } | |
1787 | return true; | |
1788 | } | |
1789 | ||
1790 | // Deletes all items | |
1791 | bool wxListCtrl::DeleteAllColumns() | |
1792 | { | |
1793 | if (m_genericImpl) | |
1794 | return m_genericImpl->DeleteAllColumns(); | |
1795 | ||
1796 | if (m_dbImpl) | |
1797 | { | |
1798 | UInt32 cols; | |
1799 | m_dbImpl->GetColumnCount(&cols); | |
1800 | for (UInt32 col = 0; col < cols; col++) | |
1801 | { | |
1802 | DeleteColumn(0); | |
1803 | } | |
1804 | } | |
1805 | ||
1806 | return true; | |
1807 | } | |
1808 | ||
1809 | // Deletes a column | |
1810 | bool wxListCtrl::DeleteColumn(int col) | |
1811 | { | |
1812 | if (m_genericImpl) | |
1813 | return m_genericImpl->DeleteColumn(col); | |
1814 | ||
1815 | if (m_dbImpl) | |
1816 | { | |
1817 | OSStatus err = m_dbImpl->RemoveColumn(col); | |
1818 | return err == noErr; | |
1819 | } | |
1820 | ||
1821 | return true; | |
1822 | } | |
1823 | ||
1824 | // Clears items, and columns if there are any. | |
1825 | void wxListCtrl::ClearAll() | |
1826 | { | |
1827 | if (m_genericImpl) | |
1828 | { | |
1829 | m_genericImpl->ClearAll(); | |
1830 | return; | |
1831 | } | |
1832 | ||
1833 | if (m_dbImpl) | |
1834 | { | |
1835 | DeleteAllItems(); | |
1836 | DeleteAllColumns(); | |
1837 | } | |
1838 | } | |
1839 | ||
1840 | wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass) | |
1841 | { | |
1842 | if (m_genericImpl) | |
1843 | return m_genericImpl->EditLabel(item, textControlClass); | |
1844 | ||
1845 | if (m_dbImpl) | |
1846 | { | |
1847 | wxCHECK_MSG( (item >= 0) && ((long)item < GetItemCount()), NULL, | |
1848 | wxT("wrong index in wxListCtrl::EditLabel()") ); | |
1849 | ||
1850 | wxASSERT_MSG( textControlClass->IsKindOf(CLASSINFO(wxTextCtrl)), | |
1851 | wxT("EditLabel() needs a text control") ); | |
1852 | ||
1853 | wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() ); | |
1854 | le.SetEventObject( this ); | |
1855 | le.m_itemIndex = item; | |
1856 | le.m_col = 0; | |
1857 | GetItem( le.m_item ); | |
1858 | ||
1859 | if ( GetParent()->HandleWindowEvent( le ) && !le.IsAllowed() ) | |
1860 | { | |
1861 | // vetoed by user code | |
1862 | return NULL; | |
1863 | } | |
1864 | ||
1865 | wxTextCtrl * const text = (wxTextCtrl *)textControlClass->CreateObject(); | |
1866 | m_textctrlWrapper = new wxListCtrlTextCtrlWrapper(this, text, item); | |
1867 | return m_textctrlWrapper->GetText(); | |
1868 | } | |
1869 | return NULL; | |
1870 | } | |
1871 | ||
1872 | // End label editing, optionally cancelling the edit | |
1873 | bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel)) | |
1874 | { | |
1875 | // TODO: generic impl. doesn't have this method - is it needed for us? | |
1876 | if (m_genericImpl) | |
1877 | return true; // m_genericImpl->EndEditLabel(cancel); | |
1878 | ||
1879 | if (m_dbImpl) | |
1880 | verify_noerr( SetDataBrowserEditItem(m_dbImpl->GetControlRef(), kDataBrowserNoItem, kMinColumnId) ); | |
1881 | return true; | |
1882 | } | |
1883 | ||
1884 | // Ensures this item is visible | |
1885 | bool wxListCtrl::EnsureVisible(long item) | |
1886 | { | |
1887 | if (m_genericImpl) | |
1888 | return m_genericImpl->EnsureVisible(item); | |
1889 | ||
1890 | if (m_dbImpl) | |
1891 | { | |
1892 | wxMacDataItem* dataItem = m_dbImpl->GetItemFromLine(item); | |
1893 | m_dbImpl->RevealItem(dataItem, kDataBrowserRevealWithoutSelecting); | |
1894 | } | |
1895 | ||
1896 | return true; | |
1897 | } | |
1898 | ||
1899 | // Find an item whose label matches this string, starting from the item after 'start' | |
1900 | // or the beginning if 'start' is -1. | |
1901 | long wxListCtrl::FindItem(long start, const wxString& str, bool partial) | |
1902 | { | |
1903 | if (m_genericImpl) | |
1904 | return m_genericImpl->FindItem(start, str, partial); | |
1905 | ||
1906 | wxString str_upper = str.Upper(); | |
1907 | ||
1908 | long idx = start; | |
1909 | if (idx < 0) | |
1910 | idx = 0; | |
1911 | long count = GetItemCount(); | |
1912 | ||
1913 | while (idx < count) | |
1914 | { | |
1915 | wxString line_upper = GetItemText(idx).Upper(); | |
1916 | if (!partial) | |
1917 | { | |
1918 | if (line_upper == str_upper ) | |
1919 | return idx; | |
1920 | } | |
1921 | else | |
1922 | { | |
1923 | if (line_upper.find(str_upper) == 0) | |
1924 | return idx; | |
1925 | } | |
1926 | ||
1927 | idx++; | |
1928 | }; | |
1929 | ||
1930 | return wxNOT_FOUND; | |
1931 | } | |
1932 | ||
1933 | // Find an item whose data matches this data, starting from the item after 'start' | |
1934 | // or the beginning if 'start' is -1. | |
1935 | long wxListCtrl::FindItem(long start, long data) | |
1936 | { | |
1937 | if (m_genericImpl) | |
1938 | return m_genericImpl->FindItem(start, data); | |
1939 | ||
1940 | long idx = start; | |
1941 | if (idx < 0) | |
1942 | idx = 0; | |
1943 | long count = GetItemCount(); | |
1944 | ||
1945 | while (idx < count) | |
1946 | { | |
1947 | if (GetItemData(idx) == data) | |
1948 | return idx; | |
1949 | idx++; | |
1950 | }; | |
1951 | ||
1952 | return wxNOT_FOUND; | |
1953 | } | |
1954 | ||
1955 | // Find an item nearest this position in the specified direction, starting from | |
1956 | // the item after 'start' or the beginning if 'start' is -1. | |
1957 | long wxListCtrl::FindItem(long start, const wxPoint& pt, int direction) | |
1958 | { | |
1959 | if (m_genericImpl) | |
1960 | return m_genericImpl->FindItem(start, pt, direction); | |
1961 | return -1; | |
1962 | } | |
1963 | ||
1964 | // Determines which item (if any) is at the specified point, | |
1965 | // giving details in 'flags' (see wxLIST_HITTEST_... flags above) | |
1966 | long | |
1967 | wxListCtrl::HitTest(const wxPoint& point, int& flags, long *ptrSubItem) const | |
1968 | { | |
1969 | if (m_genericImpl) | |
1970 | return m_genericImpl->HitTest(point, flags, ptrSubItem); | |
1971 | ||
1972 | flags = wxLIST_HITTEST_NOWHERE; | |
1973 | if (m_dbImpl) | |
1974 | { | |
1975 | int colHeaderHeight = 22; // TODO: Find a way to get this value from the db control? | |
1976 | UInt16 rowHeight = 0; | |
1977 | m_dbImpl->GetDefaultRowHeight(&rowHeight); | |
1978 | ||
1979 | int y = point.y; | |
1980 | // get the actual row by taking scroll position into account | |
1981 | UInt32 offsetX, offsetY; | |
1982 | m_dbImpl->GetScrollPosition( &offsetY, &offsetX ); | |
1983 | y += offsetY; | |
1984 | ||
1985 | if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER) ) | |
1986 | y -= colHeaderHeight; | |
1987 | ||
1988 | if ( y < 0 ) | |
1989 | return -1; | |
1990 | ||
1991 | int row = y / rowHeight; | |
1992 | DataBrowserItemID id; | |
1993 | m_dbImpl->GetItemID( (DataBrowserTableViewRowIndex) row, &id ); | |
1994 | ||
1995 | // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label | |
1996 | if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL ) ) | |
1997 | { | |
1998 | wxMacListCtrlItem* lcItem; | |
1999 | lcItem = (wxMacListCtrlItem*) id; | |
2000 | if (lcItem) | |
2001 | { | |
2002 | flags = wxLIST_HITTEST_ONITEM; | |
2003 | return row; | |
2004 | } | |
2005 | } | |
2006 | else | |
2007 | { | |
2008 | if (row < GetItemCount() ) | |
2009 | { | |
2010 | flags = wxLIST_HITTEST_ONITEM; | |
2011 | return row; | |
2012 | } | |
2013 | } | |
2014 | ||
2015 | } | |
2016 | return -1; | |
2017 | } | |
2018 | ||
2019 | int wxListCtrl::GetScrollPos(int orient) const | |
2020 | { | |
2021 | if (m_genericImpl) | |
2022 | return m_genericImpl->GetScrollPos(orient); | |
2023 | ||
2024 | if (m_dbImpl) | |
2025 | { | |
2026 | UInt32 offsetX, offsetY; | |
2027 | m_dbImpl->GetScrollPosition( &offsetY, &offsetX ); | |
2028 | if ( orient == wxHORIZONTAL ) | |
2029 | return offsetX; | |
2030 | else | |
2031 | return offsetY; | |
2032 | } | |
2033 | ||
2034 | return 0; | |
2035 | } | |
2036 | ||
2037 | // Inserts an item, returning the index of the new item if successful, | |
2038 | // -1 otherwise. | |
2039 | long wxListCtrl::InsertItem(wxListItem& info) | |
2040 | { | |
2041 | wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") ); | |
2042 | ||
2043 | if (m_genericImpl) | |
2044 | return m_genericImpl->InsertItem(info); | |
2045 | ||
2046 | if (m_dbImpl && !IsVirtual()) | |
2047 | { | |
2048 | int count = GetItemCount(); | |
2049 | ||
2050 | if (info.m_itemId > count) | |
2051 | info.m_itemId = count; | |
2052 | ||
2053 | m_dbImpl->MacInsertItem(info.m_itemId, &info ); | |
2054 | ||
2055 | wxListEvent event( wxEVT_COMMAND_LIST_INSERT_ITEM, GetId() ); | |
2056 | event.SetEventObject( this ); | |
2057 | event.m_itemIndex = info.m_itemId; | |
2058 | HandleWindowEvent( event ); | |
2059 | return info.m_itemId; | |
2060 | } | |
2061 | return -1; | |
2062 | } | |
2063 | ||
2064 | long wxListCtrl::InsertItem(long index, const wxString& label) | |
2065 | { | |
2066 | if (m_genericImpl) | |
2067 | return m_genericImpl->InsertItem(index, label); | |
2068 | ||
2069 | wxListItem info; | |
2070 | info.m_text = label; | |
2071 | info.m_mask = wxLIST_MASK_TEXT; | |
2072 | info.m_itemId = index; | |
2073 | return InsertItem(info); | |
2074 | } | |
2075 | ||
2076 | // Inserts an image item | |
2077 | long wxListCtrl::InsertItem(long index, int imageIndex) | |
2078 | { | |
2079 | if (m_genericImpl) | |
2080 | return m_genericImpl->InsertItem(index, imageIndex); | |
2081 | ||
2082 | wxListItem info; | |
2083 | info.m_image = imageIndex; | |
2084 | info.m_mask = wxLIST_MASK_IMAGE; | |
2085 | info.m_itemId = index; | |
2086 | return InsertItem(info); | |
2087 | } | |
2088 | ||
2089 | // Inserts an image/string item | |
2090 | long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex) | |
2091 | { | |
2092 | if (m_genericImpl) | |
2093 | return m_genericImpl->InsertItem(index, label, imageIndex); | |
2094 | ||
2095 | wxListItem info; | |
2096 | info.m_image = imageIndex; | |
2097 | info.m_text = label; | |
2098 | info.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT; | |
2099 | info.m_itemId = index; | |
2100 | return InsertItem(info); | |
2101 | } | |
2102 | ||
2103 | // For list view mode (only), inserts a column. | |
2104 | long wxListCtrl::InsertColumn(long col, wxListItem& item) | |
2105 | { | |
2106 | if (m_genericImpl) | |
2107 | return m_genericImpl->InsertColumn(col, item); | |
2108 | ||
2109 | if (m_dbImpl) | |
2110 | { | |
2111 | int width = item.GetWidth(); | |
2112 | if ( !(item.GetMask() & wxLIST_MASK_WIDTH) ) | |
2113 | width = 150; | |
2114 | ||
2115 | DataBrowserPropertyType type = kDataBrowserCustomType; //kDataBrowserTextType; | |
2116 | wxImageList* imageList = GetImageList(wxIMAGE_LIST_SMALL); | |
2117 | if (imageList && imageList->GetImageCount() > 0) | |
2118 | { | |
2119 | wxBitmap bmp = imageList->GetBitmap(0); | |
2120 | //if (bmp.Ok()) | |
2121 | // type = kDataBrowserIconAndTextType; | |
2122 | } | |
2123 | ||
2124 | SInt16 just = teFlushDefault; | |
2125 | if (item.GetMask() & wxLIST_MASK_FORMAT) | |
2126 | { | |
2127 | if (item.GetAlign() == wxLIST_FORMAT_LEFT) | |
2128 | just = teFlushLeft; | |
2129 | else if (item.GetAlign() == wxLIST_FORMAT_CENTER) | |
2130 | just = teCenter; | |
2131 | else if (item.GetAlign() == wxLIST_FORMAT_RIGHT) | |
2132 | just = teFlushRight; | |
2133 | } | |
2134 | m_dbImpl->InsertColumn(col, type, item.GetText(), just, width); | |
2135 | SetColumn(col, item); | |
2136 | ||
2137 | // set/remove options based on the wxListCtrl type. | |
2138 | DataBrowserTableViewColumnID id; | |
2139 | m_dbImpl->GetColumnIDFromIndex(col, &id); | |
2140 | DataBrowserPropertyFlags flags; | |
2141 | verify_noerr(m_dbImpl->GetPropertyFlags(id, &flags)); | |
2142 | if (GetWindowStyleFlag() & wxLC_EDIT_LABELS) | |
2143 | flags |= kDataBrowserPropertyIsEditable; | |
2144 | ||
2145 | if (GetWindowStyleFlag() & wxLC_VIRTUAL){ | |
2146 | flags &= ~kDataBrowserListViewSortableColumn; | |
2147 | } | |
2148 | verify_noerr(m_dbImpl->SetPropertyFlags(id, flags)); | |
2149 | } | |
2150 | ||
2151 | return col; | |
2152 | } | |
2153 | ||
2154 | long wxListCtrl::InsertColumn(long col, | |
2155 | const wxString& heading, | |
2156 | int format, | |
2157 | int width) | |
2158 | { | |
2159 | if (m_genericImpl) | |
2160 | return m_genericImpl->InsertColumn(col, heading, format, width); | |
2161 | ||
2162 | wxListItem item; | |
2163 | item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT; | |
2164 | item.m_text = heading; | |
2165 | if ( width > -1 ) | |
2166 | { | |
2167 | item.m_mask |= wxLIST_MASK_WIDTH; | |
2168 | item.m_width = width; | |
2169 | } | |
2170 | item.m_format = format; | |
2171 | ||
2172 | return InsertColumn(col, item); | |
2173 | } | |
2174 | ||
2175 | // scroll the control by the given number of pixels (exception: in list view, | |
2176 | // dx is interpreted as number of columns) | |
2177 | bool wxListCtrl::ScrollList(int dx, int dy) | |
2178 | { | |
2179 | if (m_genericImpl) | |
2180 | return m_genericImpl->ScrollList(dx, dy); | |
2181 | ||
2182 | if (m_dbImpl) | |
2183 | { | |
2184 | m_dbImpl->SetScrollPosition(dx, dy); | |
2185 | } | |
2186 | return true; | |
2187 | } | |
2188 | ||
2189 | ||
2190 | bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data) | |
2191 | { | |
2192 | if (m_genericImpl) | |
2193 | return m_genericImpl->SortItems(fn, data); | |
2194 | ||
2195 | if (m_dbImpl) | |
2196 | { | |
2197 | m_compareFunc = fn; | |
2198 | m_compareFuncData = data; | |
2199 | SortDataBrowserContainer( m_dbImpl->GetControlRef(), kDataBrowserNoItem, true); | |
2200 | ||
2201 | // we need to do this after each call, else we get a crash from wxPython when | |
2202 | // SortItems is called the second time. | |
2203 | m_compareFunc = NULL; | |
2204 | m_compareFuncData = 0; | |
2205 | } | |
2206 | ||
2207 | return true; | |
2208 | } | |
2209 | ||
2210 | void wxListCtrl::OnRenameTimer() | |
2211 | { | |
2212 | wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") ); | |
2213 | ||
2214 | EditLabel( m_current ); | |
2215 | } | |
2216 | ||
2217 | bool wxListCtrl::OnRenameAccept(long itemEdit, const wxString& value) | |
2218 | { | |
2219 | wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetId() ); | |
2220 | le.SetEventObject( this ); | |
2221 | le.m_itemIndex = itemEdit; | |
2222 | ||
2223 | GetItem( le.m_item ); | |
2224 | le.m_item.m_text = value; | |
2225 | return !HandleWindowEvent( le ) || | |
2226 | le.IsAllowed(); | |
2227 | } | |
2228 | ||
2229 | void wxListCtrl::OnRenameCancelled(long itemEdit) | |
2230 | { | |
2231 | // let owner know that the edit was cancelled | |
2232 | wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() ); | |
2233 | ||
2234 | le.SetEditCanceled(true); | |
2235 | ||
2236 | le.SetEventObject( this ); | |
2237 | le.m_itemIndex = itemEdit; | |
2238 | ||
2239 | GetItem( le.m_item ); | |
2240 | HandleWindowEvent( le ); | |
2241 | } | |
2242 | ||
2243 | // ---------------------------------------------------------------------------- | |
2244 | // virtual list controls | |
2245 | // ---------------------------------------------------------------------------- | |
2246 | ||
2247 | wxString wxListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const | |
2248 | { | |
2249 | // this is a pure virtual function, in fact - which is not really pure | |
2250 | // because the controls which are not virtual don't need to implement it | |
2251 | wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") ); | |
2252 | ||
2253 | return wxEmptyString; | |
2254 | } | |
2255 | ||
2256 | int wxListCtrl::OnGetItemImage(long WXUNUSED(item)) const | |
2257 | { | |
2258 | wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL), | |
2259 | -1, | |
2260 | wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden.")); | |
2261 | return -1; | |
2262 | } | |
2263 | ||
2264 | int wxListCtrl::OnGetItemColumnImage(long item, long column) const | |
2265 | { | |
2266 | if (!column) | |
2267 | return OnGetItemImage(item); | |
2268 | ||
2269 | return -1; | |
2270 | } | |
2271 | ||
2272 | wxListItemAttr *wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item)) const | |
2273 | { | |
2274 | wxASSERT_MSG( item >= 0 && item < GetItemCount(), | |
2275 | _T("invalid item index in OnGetItemAttr()") ); | |
2276 | ||
2277 | // no attributes by default | |
2278 | return NULL; | |
2279 | } | |
2280 | ||
2281 | void wxListCtrl::SetItemCount(long count) | |
2282 | { | |
2283 | wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") ); | |
2284 | ||
2285 | if (m_genericImpl) | |
2286 | { | |
2287 | m_genericImpl->SetItemCount(count); | |
2288 | return; | |
2289 | } | |
2290 | ||
2291 | if (m_dbImpl) | |
2292 | { | |
2293 | // we need to temporarily disable the new item creation notification | |
2294 | // procedure to speed things up | |
2295 | // FIXME: Even this doesn't seem to help much... | |
2296 | ||
2297 | // FIXME: Find a more efficient way to do this. | |
2298 | m_dbImpl->MacClear(); | |
2299 | ||
2300 | DataBrowserCallbacks callbacks; | |
2301 | DataBrowserItemNotificationUPP itemUPP; | |
2302 | GetDataBrowserCallbacks(m_dbImpl->GetControlRef(), &callbacks); | |
2303 | itemUPP = callbacks.u.v1.itemNotificationCallback; | |
2304 | callbacks.u.v1.itemNotificationCallback = 0; | |
2305 | m_dbImpl->SetCallbacks(&callbacks); | |
2306 | ::AddDataBrowserItems(m_dbImpl->GetControlRef(), kDataBrowserNoItem, | |
2307 | count, NULL, kDataBrowserItemNoProperty); | |
2308 | callbacks.u.v1.itemNotificationCallback = itemUPP; | |
2309 | m_dbImpl->SetCallbacks(&callbacks); | |
2310 | } | |
2311 | m_count = count; | |
2312 | } | |
2313 | ||
2314 | void wxListCtrl::RefreshItem(long item) | |
2315 | { | |
2316 | if (m_genericImpl) | |
2317 | { | |
2318 | m_genericImpl->RefreshItem(item); | |
2319 | return; | |
2320 | } | |
2321 | ||
2322 | if (m_dbImpl) | |
2323 | { | |
2324 | DataBrowserItemID id; | |
2325 | ||
2326 | if ( !IsVirtual() ) | |
2327 | { | |
2328 | wxMacDataItem* thisItem = m_dbImpl->GetItemFromLine(item); | |
2329 | id = (DataBrowserItemID) thisItem; | |
2330 | } | |
2331 | else | |
2332 | id = item+1; | |
2333 | ||
2334 | m_dbImpl->wxMacDataBrowserControl::UpdateItems | |
2335 | ( | |
2336 | kDataBrowserNoItem, | |
2337 | 1, &id, | |
2338 | kDataBrowserItemNoProperty, // preSortProperty | |
2339 | kDataBrowserNoItem // update all columns | |
2340 | ); | |
2341 | } | |
2342 | } | |
2343 | ||
2344 | void wxListCtrl::RefreshItems(long itemFrom, long itemTo) | |
2345 | { | |
2346 | if (m_genericImpl) | |
2347 | { | |
2348 | m_genericImpl->RefreshItems(itemFrom, itemTo); | |
2349 | return; | |
2350 | } | |
2351 | ||
2352 | if (m_dbImpl) | |
2353 | { | |
2354 | const long count = itemTo - itemFrom + 1; | |
2355 | DataBrowserItemID *ids = new DataBrowserItemID[count]; | |
2356 | ||
2357 | if ( !IsVirtual() ) | |
2358 | { | |
2359 | for ( long i = 0; i < count; i++ ) | |
2360 | { | |
2361 | wxMacDataItem* thisItem = m_dbImpl->GetItemFromLine(itemFrom+i); | |
2362 | ids[i] = (DataBrowserItemID) thisItem; | |
2363 | } | |
2364 | } | |
2365 | else | |
2366 | { | |
2367 | for ( long i = 0; i < count; i++ ) | |
2368 | ids[i] = itemFrom+i+1; | |
2369 | } | |
2370 | ||
2371 | m_dbImpl->wxMacDataBrowserControl::UpdateItems | |
2372 | ( | |
2373 | kDataBrowserNoItem, | |
2374 | count, ids, | |
2375 | kDataBrowserItemNoProperty, // preSortProperty | |
2376 | kDataBrowserNoItem // update all columns | |
2377 | ); | |
2378 | ||
2379 | delete[] ids; | |
2380 | } | |
2381 | } | |
2382 | ||
2383 | void wxListCtrl::SetDropTarget( wxDropTarget *dropTarget ) | |
2384 | { | |
2385 | #if wxUSE_DRAG_AND_DROP | |
2386 | if (m_genericImpl) | |
2387 | m_genericImpl->SetDropTarget( dropTarget ); | |
2388 | ||
2389 | if (m_dbImpl) | |
2390 | wxWindow::SetDropTarget( dropTarget ); | |
2391 | #endif | |
2392 | } | |
2393 | ||
2394 | wxDropTarget *wxListCtrl::GetDropTarget() const | |
2395 | { | |
2396 | #if wxUSE_DRAG_AND_DROP | |
2397 | if (m_genericImpl) | |
2398 | return m_genericImpl->GetDropTarget(); | |
2399 | ||
2400 | if (m_dbImpl) | |
2401 | return wxWindow::GetDropTarget(); | |
2402 | #endif | |
2403 | return NULL; | |
2404 | } | |
2405 | ||
2406 | #if wxABI_VERSION >= 20801 | |
2407 | void wxListCtrl::SetFocus() | |
2408 | { | |
2409 | if (m_genericImpl) | |
2410 | { | |
2411 | m_genericImpl->SetFocus(); | |
2412 | return; | |
2413 | } | |
2414 | ||
2415 | wxWindow::SetFocus(); | |
2416 | } | |
2417 | #endif | |
2418 | ||
2419 | // wxMac internal data structures | |
2420 | ||
2421 | wxMacListCtrlItem::~wxMacListCtrlItem() | |
2422 | { | |
2423 | WX_CLEAR_HASH_MAP( wxListItemList, m_rowItems ); | |
2424 | } | |
2425 | ||
2426 | void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl *owner , | |
2427 | DataBrowserItemNotification message, | |
2428 | DataBrowserItemDataRef WXUNUSED(itemData) ) const | |
2429 | { | |
2430 | ||
2431 | wxMacDataBrowserListCtrlControl *lb = wxDynamicCast(owner, wxMacDataBrowserListCtrlControl); | |
2432 | ||
2433 | // we want to depend on as little as possible to make sure tear-down of controls is safe | |
2434 | if ( message == kDataBrowserItemRemoved) | |
2435 | { | |
2436 | if ( lb != NULL && lb->GetClientDataType() == wxClientData_Object ) | |
2437 | { | |
2438 | delete (wxClientData*) (m_data); | |
2439 | } | |
2440 | ||
2441 | delete this; | |
2442 | return; | |
2443 | } | |
2444 | else if ( message == kDataBrowserItemAdded ) | |
2445 | { | |
2446 | // we don't issue events on adding, the item is not really stored in the list yet, so we | |
2447 | // avoid asserts by gettting out now | |
2448 | return ; | |
2449 | } | |
2450 | ||
b2680ced | 2451 | wxListCtrl *list = wxDynamicCast( owner->GetWXPeer() , wxListCtrl ); |
489468fe SC |
2452 | if ( list && lb ) |
2453 | { | |
2454 | bool trigger = false; | |
2455 | ||
2456 | wxListEvent event( wxEVT_COMMAND_LIST_ITEM_SELECTED, list->GetId() ); | |
2457 | bool isSingle = (list->GetWindowStyle() & wxLC_SINGLE_SEL) != 0; | |
2458 | ||
2459 | event.SetEventObject( list ); | |
2460 | event.m_itemIndex = owner->GetLineFromItem( this ) ; | |
2461 | event.m_item.m_itemId = event.m_itemIndex; | |
2462 | list->GetItem(event.m_item); | |
2463 | ||
2464 | switch (message) | |
2465 | { | |
2466 | case kDataBrowserItemDeselected: | |
2467 | event.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED); | |
2468 | if ( !isSingle ) | |
2469 | trigger = !lb->IsSelectionSuppressed(); | |
2470 | break; | |
2471 | ||
2472 | case kDataBrowserItemSelected: | |
2473 | trigger = !lb->IsSelectionSuppressed(); | |
2474 | break; | |
2475 | ||
2476 | case kDataBrowserItemDoubleClicked: | |
2477 | event.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); | |
2478 | trigger = true; | |
2479 | break; | |
2480 | ||
2481 | case kDataBrowserEditStarted : | |
2482 | // TODO : how to veto ? | |
2483 | event.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT ) ; | |
2484 | trigger = true ; | |
2485 | break ; | |
2486 | ||
2487 | case kDataBrowserEditStopped : | |
2488 | // TODO probably trigger only upon the value store callback, because | |
2489 | // here IIRC we cannot veto | |
2490 | event.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT ) ; | |
2491 | trigger = true ; | |
2492 | break ; | |
2493 | ||
2494 | default: | |
2495 | break; | |
2496 | } | |
2497 | ||
2498 | if ( trigger ) | |
2499 | { | |
2500 | // direct notification is not always having the listbox GetSelection() having in synch with event | |
2501 | wxPostEvent( list->GetEventHandler(), event ); | |
2502 | } | |
2503 | } | |
2504 | ||
2505 | } | |
2506 | ||
2507 | IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl, wxMacDataItemBrowserControl ) | |
2508 | ||
2509 | wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style) | |
2510 | : wxMacDataItemBrowserControl( peer, pos, size, style ) | |
2511 | { | |
2512 | OSStatus err = noErr; | |
2513 | m_clientDataItemsType = wxClientData_None; | |
2514 | m_isVirtual = false; | |
2515 | m_flags = 0; | |
2516 | ||
2517 | if ( style & wxLC_VIRTUAL ) | |
2518 | m_isVirtual = true; | |
2519 | ||
2520 | DataBrowserSelectionFlags options = kDataBrowserDragSelect; | |
2521 | if ( style & wxLC_SINGLE_SEL ) | |
2522 | { | |
2523 | options |= kDataBrowserSelectOnlyOne; | |
2524 | } | |
2525 | else | |
2526 | { | |
2527 | options |= kDataBrowserCmdTogglesSelection; | |
2528 | } | |
2529 | ||
2530 | err = SetSelectionFlags( options ); | |
2531 | verify_noerr( err ); | |
2532 | ||
2533 | DataBrowserCustomCallbacks callbacks; | |
2534 | InitializeDataBrowserCustomCallbacks( &callbacks, kDataBrowserLatestCustomCallbacks ); | |
2535 | ||
2536 | if ( gDataBrowserDrawItemUPP == NULL ) | |
2537 | gDataBrowserDrawItemUPP = NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc); | |
2538 | ||
2539 | if ( gDataBrowserHitTestUPP == NULL ) | |
2540 | gDataBrowserHitTestUPP = NewDataBrowserHitTestUPP(DataBrowserHitTestProc); | |
2541 | ||
2542 | callbacks.u.v1.drawItemCallback = gDataBrowserDrawItemUPP; | |
2543 | callbacks.u.v1.hitTestCallback = gDataBrowserHitTestUPP; | |
2544 | ||
2545 | SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks ); | |
2546 | ||
2547 | if ( style & wxLC_LIST ) | |
2548 | { | |
2549 | InsertColumn(0, kDataBrowserIconAndTextType, wxEmptyString, -1, -1); | |
2550 | verify_noerr( AutoSizeColumns() ); | |
2551 | } | |
2552 | ||
2553 | if ( style & wxLC_LIST || style & wxLC_NO_HEADER ) | |
2554 | verify_noerr( SetHeaderButtonHeight( 0 ) ); | |
2555 | ||
2556 | if ( m_isVirtual ) | |
2557 | SetSortProperty( kMinColumnId - 1 ); | |
2558 | else | |
2559 | SetSortProperty( kMinColumnId ); | |
2560 | ||
2561 | m_sortOrder = SortOrder_None; | |
2562 | ||
2563 | if ( style & wxLC_SORT_DESCENDING ) | |
2564 | { | |
2565 | SetSortOrder( kDataBrowserOrderDecreasing ); | |
2566 | } | |
2567 | else if ( style & wxLC_SORT_ASCENDING ) | |
2568 | { | |
2569 | SetSortOrder( kDataBrowserOrderIncreasing ); | |
2570 | } | |
2571 | ||
2572 | if ( style & wxLC_VRULES ) | |
2573 | { | |
2574 | verify_noerr( DataBrowserChangeAttributes(m_controlRef, kDataBrowserAttributeListViewDrawColumnDividers, kDataBrowserAttributeNone) ); | |
2575 | } | |
2576 | ||
2577 | verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite ) ); | |
2578 | verify_noerr( SetHasScrollBars( (style & wxHSCROLL) != 0 , true ) ); | |
2579 | } | |
2580 | ||
2581 | pascal Boolean wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc( | |
2582 | ControlRef browser, | |
2583 | DataBrowserItemID itemID, | |
2584 | DataBrowserPropertyID property, | |
2585 | CFStringRef theString, | |
2586 | Rect *maxEditTextRect, | |
2587 | Boolean *shrinkToFit) | |
2588 | { | |
2589 | Boolean result = false; | |
2590 | wxMacDataBrowserListCtrlControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserListCtrlControl); | |
2591 | if ( ctl != 0 ) | |
2592 | { | |
2593 | result = ctl->ConfirmEditText(itemID, property, theString, maxEditTextRect, shrinkToFit); | |
2594 | theString = CFSTR("Hello!"); | |
2595 | } | |
2596 | return result; | |
2597 | } | |
2598 | ||
2599 | bool wxMacDataBrowserListCtrlControl::ConfirmEditText( | |
2600 | DataBrowserItemID WXUNUSED(itemID), | |
2601 | DataBrowserPropertyID WXUNUSED(property), | |
2602 | CFStringRef WXUNUSED(theString), | |
2603 | Rect *WXUNUSED(maxEditTextRect), | |
2604 | Boolean *WXUNUSED(shrinkToFit)) | |
2605 | { | |
2606 | return false; | |
2607 | } | |
2608 | ||
2609 | pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc( | |
2610 | ControlRef browser, | |
2611 | DataBrowserItemID itemID, | |
2612 | DataBrowserPropertyID property, | |
2613 | DataBrowserItemState itemState, | |
2614 | const Rect *itemRect, | |
2615 | SInt16 gdDepth, | |
2616 | Boolean colorDevice) | |
2617 | { | |
2618 | wxMacDataBrowserListCtrlControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserListCtrlControl); | |
2619 | if ( ctl != 0 ) | |
2620 | { | |
2621 | ctl->DrawItem(itemID, property, itemState, itemRect, gdDepth, colorDevice); | |
2622 | } | |
2623 | } | |
2624 | ||
2625 | // routines needed for DrawItem | |
2626 | enum | |
2627 | { | |
2628 | kIconWidth = 16, | |
2629 | kIconHeight = 16, | |
2630 | kTextBoxHeight = 14, | |
2631 | kIconTextSpacingV = 2, | |
2632 | kItemPadding = 4, | |
2633 | kContentHeight = kIconHeight + kTextBoxHeight + kIconTextSpacingV | |
2634 | }; | |
2635 | ||
2636 | static void calculateCGDrawingBounds(CGRect inItemRect, CGRect *outIconRect, CGRect *outTextRect, bool hasIcon = false) | |
2637 | { | |
2638 | float textBottom; | |
2639 | float iconH, iconW = 0; | |
2640 | float padding = kItemPadding; | |
2641 | if (hasIcon) | |
2642 | { | |
2643 | iconH = kIconHeight; | |
2644 | iconW = kIconWidth; | |
2645 | padding = padding*2; | |
2646 | } | |
2647 | ||
2648 | textBottom = inItemRect.origin.y; | |
2649 | ||
2650 | *outIconRect = CGRectMake(inItemRect.origin.x + kItemPadding, | |
2651 | textBottom + kIconTextSpacingV, kIconWidth, | |
2652 | kIconHeight); | |
2653 | ||
2654 | *outTextRect = CGRectMake(inItemRect.origin.x + padding + iconW, | |
2655 | textBottom + kIconTextSpacingV, inItemRect.size.width - padding - iconW, | |
2656 | inItemRect.size.height - kIconTextSpacingV); | |
2657 | } | |
2658 | ||
2659 | void wxMacDataBrowserListCtrlControl::DrawItem( | |
2660 | DataBrowserItemID itemID, | |
2661 | DataBrowserPropertyID property, | |
2662 | DataBrowserItemState itemState, | |
2663 | const Rect *WXUNUSED(itemRect), | |
2664 | SInt16 gdDepth, | |
2665 | Boolean colorDevice) | |
2666 | { | |
2667 | wxString text; | |
2668 | wxFont font = wxNullFont; | |
2669 | int imgIndex = -1; | |
2670 | short listColumn = property - kMinColumnId; | |
2671 | ||
b2680ced | 2672 | wxListCtrl* list = wxDynamicCast( GetWXPeer() , wxListCtrl ); |
489468fe SC |
2673 | wxMacListCtrlItem* lcItem; |
2674 | wxColour color = *wxBLACK; | |
2675 | wxColour bgColor = wxNullColour; | |
2676 | ||
2677 | if (listColumn >= 0) | |
2678 | { | |
2679 | if (!m_isVirtual) | |
2680 | { | |
2681 | lcItem = (wxMacListCtrlItem*) itemID; | |
2682 | if (lcItem->HasColumnInfo(listColumn)){ | |
2683 | wxListItem* item = lcItem->GetColumnInfo(listColumn); | |
2684 | ||
2685 | // we always use the 0 column to get font and text/background colors. | |
2686 | if (lcItem->HasColumnInfo(0)) | |
2687 | { | |
2688 | wxListItem* firstItem = lcItem->GetColumnInfo(0); | |
2689 | color = firstItem->GetTextColour(); | |
2690 | bgColor = firstItem->GetBackgroundColour(); | |
2691 | font = firstItem->GetFont(); | |
2692 | } | |
2693 | ||
2694 | if (item->GetMask() & wxLIST_MASK_TEXT) | |
2695 | text = item->GetText(); | |
2696 | if (item->GetMask() & wxLIST_MASK_IMAGE) | |
2697 | imgIndex = item->GetImage(); | |
2698 | } | |
2699 | ||
2700 | } | |
2701 | else | |
2702 | { | |
2703 | long itemNum = (long)itemID-1; | |
2704 | if (itemNum >= 0 && itemNum < list->GetItemCount()) | |
2705 | { | |
2706 | text = list->OnGetItemText( itemNum, listColumn ); | |
2707 | imgIndex = list->OnGetItemColumnImage( itemNum, listColumn ); | |
2708 | wxListItemAttr* attrs = list->OnGetItemAttr( itemNum ); | |
2709 | if (attrs) | |
2710 | { | |
2711 | if (attrs->HasBackgroundColour()) | |
2712 | bgColor = attrs->GetBackgroundColour(); | |
2713 | if (attrs->HasTextColour()) | |
2714 | color = attrs->GetTextColour(); | |
2715 | if (attrs->HasFont()) | |
2716 | font = attrs->GetFont(); | |
2717 | } | |
2718 | } | |
2719 | } | |
2720 | } | |
2721 | ||
2722 | wxColour listBgColor = list->GetBackgroundColour(); | |
2723 | if (bgColor == wxNullColour) | |
2724 | bgColor = listBgColor; | |
2725 | ||
2726 | if (!font.Ok()) | |
2727 | font = list->GetFont(); | |
2728 | ||
2729 | wxCFStringRef cfString( text, wxLocale::GetSystemEncoding() ); | |
2730 | ||
2731 | Rect enclosingRect; | |
2732 | CGRect enclosingCGRect, iconCGRect, textCGRect; | |
2733 | Boolean active; | |
2734 | ThemeDrawingState savedState = NULL; | |
2735 | CGContextRef context = (CGContextRef)list->MacGetDrawingContext(); | |
2736 | RGBColor labelColor; | |
2737 | labelColor.red = 0; | |
2738 | labelColor.green = 0; | |
2739 | labelColor.blue = 0; | |
2740 | ||
2741 | RGBColor backgroundColor; | |
2742 | backgroundColor.red = 255; | |
2743 | backgroundColor.green = 255; | |
2744 | backgroundColor.blue = 255; | |
2745 | ||
2746 | GetDataBrowserItemPartBounds(GetControlRef(), itemID, property, kDataBrowserPropertyEnclosingPart, | |
2747 | &enclosingRect); | |
2748 | ||
2749 | enclosingCGRect = CGRectMake(enclosingRect.left, | |
2750 | enclosingRect.top, | |
2751 | enclosingRect.right - enclosingRect.left, | |
2752 | enclosingRect.bottom - enclosingRect.top); | |
2753 | ||
2754 | bool hasFocus = (wxWindow::FindFocus() == list); | |
2755 | active = IsControlActive(GetControlRef()); | |
2756 | ||
2757 | // don't paint the background over the vertical rule line | |
2758 | if ( list->GetWindowStyleFlag() & wxLC_VRULES ) | |
2759 | { | |
2760 | enclosingCGRect.origin.x += 1; | |
2761 | enclosingCGRect.size.width -= 1; | |
2762 | } | |
2763 | if (itemState == kDataBrowserItemIsSelected) | |
2764 | { | |
2765 | ||
2766 | GetThemeDrawingState(&savedState); | |
2767 | ||
2768 | if (active && hasFocus) | |
2769 | { | |
2770 | GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor, 32, true, &backgroundColor); | |
2771 | GetThemeTextColor(kThemeTextColorWhite, gdDepth, colorDevice, &labelColor); | |
2772 | } | |
2773 | else | |
2774 | { | |
2775 | GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor, 32, true, &backgroundColor); | |
2776 | GetThemeTextColor(kThemeTextColorBlack, gdDepth, colorDevice, &labelColor); | |
2777 | } | |
2778 | CGContextSaveGState(context); | |
2779 | ||
2780 | CGContextSetRGBFillColor(context, (CGFloat)backgroundColor.red / (CGFloat)USHRT_MAX, | |
2781 | (CGFloat)backgroundColor.green / (CGFloat)USHRT_MAX, | |
2782 | (CGFloat)backgroundColor.blue / (CGFloat)USHRT_MAX, (CGFloat) 1.0); | |
2783 | CGContextFillRect(context, enclosingCGRect); | |
2784 | ||
2785 | CGContextRestoreGState(context); | |
2786 | } | |
2787 | else | |
2788 | { | |
2789 | ||
2790 | if (color.Ok()) | |
2791 | color.GetRGBColor(&labelColor); | |
2792 | else if (list->GetTextColour().Ok()) | |
2793 | list->GetTextColour().GetRGBColor(&labelColor); | |
2794 | ||
2795 | if (bgColor.Ok()) | |
2796 | { | |
2797 | bgColor.GetRGBColor(&backgroundColor); | |
2798 | CGContextSaveGState(context); | |
2799 | ||
2800 | CGContextSetRGBFillColor(context, (CGFloat)backgroundColor.red / (CGFloat)USHRT_MAX, | |
2801 | (CGFloat)backgroundColor.green / (CGFloat)USHRT_MAX, | |
2802 | (CGFloat)backgroundColor.blue / (CGFloat)USHRT_MAX, (CGFloat) 1.0); | |
2803 | CGContextFillRect(context, enclosingCGRect); | |
2804 | ||
2805 | CGContextRestoreGState(context); | |
2806 | } | |
2807 | } | |
2808 | ||
2809 | calculateCGDrawingBounds(enclosingCGRect, &iconCGRect, &textCGRect, (imgIndex != -1) ); | |
2810 | ||
2811 | if (imgIndex != -1) | |
2812 | { | |
2813 | wxImageList* imageList = list->GetImageList(wxIMAGE_LIST_SMALL); | |
2814 | if (imageList && imageList->GetImageCount() > 0){ | |
2815 | wxBitmap bmp = imageList->GetBitmap(imgIndex); | |
2816 | IconRef icon = bmp.GetIconRef(); | |
2817 | ||
2818 | CGContextSaveGState(context); | |
2819 | CGContextTranslateCTM(context, 0,iconCGRect.origin.y + CGRectGetMaxY(iconCGRect)); | |
2820 | CGContextScaleCTM(context,1.0f,-1.0f); | |
2821 | PlotIconRefInContext(context, &iconCGRect, kAlignNone, | |
2822 | active ? kTransformNone : kTransformDisabled, NULL, | |
2823 | kPlotIconRefNormalFlags, icon); | |
2824 | ||
2825 | CGContextRestoreGState(context); | |
2826 | } | |
2827 | } | |
2828 | ||
2829 | HIThemeTextHorizontalFlush hFlush = kHIThemeTextHorizontalFlushLeft; | |
2830 | HIThemeTextInfo info; | |
2831 | bool setup = false; | |
292e5e1f | 2832 | #if wxOSX_USE_CORE_TEXT |
489468fe SC |
2833 | if ( UMAGetSystemVersion() >= 0x1050 ) |
2834 | { | |
2835 | info.version = kHIThemeTextInfoVersionOne; | |
2836 | info.fontID = kThemeViewsFont; | |
2837 | if (font.Ok()) | |
2838 | { | |
2839 | info.fontID = kThemeSpecifiedFont; | |
2840 | info.font = (CTFontRef) font.MacGetCTFont(); | |
2841 | setup = true; | |
2842 | } | |
2843 | } | |
2844 | #endif | |
292e5e1f | 2845 | #if wxOSX_USE_ATSU_TEXT |
489468fe SC |
2846 | if ( !setup ) |
2847 | { | |
2848 | info.version = kHIThemeTextInfoVersionZero; | |
2849 | info.fontID = kThemeViewsFont; | |
2850 | ||
2851 | if (font.Ok()) | |
2852 | { | |
2853 | info.fontID = font.MacGetThemeFontID(); | |
2854 | ||
2855 | ::TextSize( (short)(font.MacGetFontSize()) ) ; | |
2856 | ::TextFace( font.MacGetFontStyle() ) ; | |
2857 | } | |
2858 | } | |
2859 | #endif | |
2860 | ||
2861 | wxListItem item; | |
2862 | list->GetColumn(listColumn, item); | |
2863 | if (item.GetMask() & wxLIST_MASK_FORMAT) | |
2864 | { | |
2865 | if (item.GetAlign() == wxLIST_FORMAT_LEFT) | |
2866 | hFlush = kHIThemeTextHorizontalFlushLeft; | |
2867 | else if (item.GetAlign() == wxLIST_FORMAT_CENTER) | |
2868 | hFlush = kHIThemeTextHorizontalFlushCenter; | |
2869 | else if (item.GetAlign() == wxLIST_FORMAT_RIGHT) | |
2870 | { | |
2871 | hFlush = kHIThemeTextHorizontalFlushRight; | |
2872 | textCGRect.origin.x -= kItemPadding; // give a little extra paddding | |
2873 | } | |
2874 | } | |
2875 | ||
2876 | info.state = active ? kThemeStateActive : kThemeStateInactive; | |
2877 | info.horizontalFlushness = hFlush; | |
2878 | info.verticalFlushness = kHIThemeTextVerticalFlushCenter; | |
2879 | info.options = kHIThemeTextBoxOptionNone; | |
2880 | info.truncationPosition = kHIThemeTextTruncationEnd; | |
2881 | info.truncationMaxLines = 1; | |
2882 | ||
2883 | CGContextSaveGState(context); | |
2884 | CGContextSetRGBFillColor (context, (CGFloat)labelColor.red / (CGFloat)USHRT_MAX, | |
2885 | (CGFloat)labelColor.green / (CGFloat)USHRT_MAX, | |
2886 | (CGFloat)labelColor.blue / (CGFloat)USHRT_MAX, (CGFloat) 1.0); | |
2887 | ||
2888 | HIThemeDrawTextBox(cfString, &textCGRect, &info, context, kHIThemeOrientationNormal); | |
2889 | ||
2890 | CGContextRestoreGState(context); | |
2891 | ||
2892 | #ifndef __LP64__ | |
2893 | if (savedState != NULL) | |
2894 | SetThemeDrawingState(savedState, true); | |
2895 | #endif | |
2896 | } | |
2897 | ||
2898 | OSStatus wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID, | |
2899 | DataBrowserPropertyID property, | |
2900 | DataBrowserItemDataRef itemData, | |
2901 | Boolean changeValue ) | |
2902 | { | |
2903 | wxString text; | |
2904 | int imgIndex = -1; | |
2905 | short listColumn = property - kMinColumnId; | |
2906 | ||
2907 | OSStatus err = errDataBrowserPropertyNotSupported; | |
b2680ced | 2908 | wxListCtrl* list = wxDynamicCast( GetWXPeer() , wxListCtrl ); |
489468fe SC |
2909 | wxMacListCtrlItem* lcItem = NULL; |
2910 | ||
2911 | if (listColumn >= 0) | |
2912 | { | |
2913 | if (!m_isVirtual) | |
2914 | { | |
2915 | lcItem = (wxMacListCtrlItem*) itemID; | |
2916 | if (lcItem && lcItem->HasColumnInfo(listColumn)){ | |
2917 | wxListItem* item = lcItem->GetColumnInfo(listColumn); | |
2918 | if (item->GetMask() & wxLIST_MASK_TEXT) | |
2919 | text = item->GetText(); | |
2920 | if (item->GetMask() & wxLIST_MASK_IMAGE) | |
2921 | imgIndex = item->GetImage(); | |
2922 | } | |
2923 | } | |
2924 | else | |
2925 | { | |
2926 | long itemNum = (long)itemID-1; | |
2927 | if (itemNum >= 0 && itemNum < list->GetItemCount()) | |
2928 | { | |
2929 | text = list->OnGetItemText( itemNum, listColumn ); | |
2930 | imgIndex = list->OnGetItemColumnImage( itemNum, listColumn ); | |
2931 | } | |
2932 | } | |
2933 | } | |
2934 | ||
2935 | if ( !changeValue ) | |
2936 | { | |
2937 | switch (property) | |
2938 | { | |
2939 | case kDataBrowserItemIsEditableProperty : | |
2940 | if ( list && list->HasFlag( wxLC_EDIT_LABELS ) ) | |
2941 | { | |
2942 | verify_noerr(SetDataBrowserItemDataBooleanValue( itemData, true )); | |
2943 | err = noErr ; | |
2944 | } | |
2945 | break ; | |
2946 | default : | |
2947 | if ( property >= kMinColumnId ) | |
2948 | { | |
2949 | if (!text.IsEmpty()){ | |
2950 | wxCFStringRef cfStr( text, wxLocale::GetSystemEncoding() ); | |
2951 | err = ::SetDataBrowserItemDataText( itemData, cfStr ); | |
2952 | err = noErr; | |
2953 | } | |
2954 | ||
2955 | ||
2956 | ||
2957 | if ( imgIndex != -1 ) | |
2958 | { | |
2959 | wxImageList* imageList = list->GetImageList(wxIMAGE_LIST_SMALL); | |
2960 | if (imageList && imageList->GetImageCount() > 0){ | |
2961 | wxBitmap bmp = imageList->GetBitmap(imgIndex); | |
2962 | IconRef icon = bmp.GetIconRef(); | |
2963 | ::SetDataBrowserItemDataIcon(itemData, icon); | |
2964 | } | |
2965 | } | |
2966 | ||
2967 | } | |
2968 | break ; | |
2969 | } | |
2970 | ||
2971 | } | |
2972 | else | |
2973 | { | |
2974 | switch (property) | |
2975 | { | |
2976 | default: | |
2977 | if ( property >= kMinColumnId ) | |
2978 | { | |
2979 | short listColumn = property - kMinColumnId; | |
2980 | ||
2981 | // TODO probably send the 'end edit' from here, as we | |
2982 | // can then deal with the veto | |
2983 | CFStringRef sr ; | |
2984 | verify_noerr( GetDataBrowserItemDataText( itemData , &sr ) ) ; | |
2985 | wxCFStringRef cfStr(sr) ;; | |
2986 | if (m_isVirtual) | |
2987 | list->SetItem( (long)itemData-1 , listColumn, cfStr.AsString() ) ; | |
2988 | else | |
2989 | { | |
2990 | if (lcItem) | |
2991 | lcItem->SetColumnTextValue( listColumn, cfStr.AsString() ); | |
2992 | } | |
2993 | err = noErr ; | |
2994 | } | |
2995 | break; | |
2996 | } | |
2997 | } | |
2998 | return err; | |
2999 | } | |
3000 | ||
3001 | void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID, | |
3002 | DataBrowserItemNotification message, | |
3003 | DataBrowserItemDataRef itemData ) | |
3004 | { | |
3005 | wxMacListCtrlItem *item = NULL; | |
3006 | if ( !m_isVirtual ) | |
3007 | { | |
3008 | item = (wxMacListCtrlItem *) itemID; | |
3009 | } | |
3010 | ||
3011 | // we want to depend on as little as possible to make sure tear-down of controls is safe | |
3012 | if ( message == kDataBrowserItemRemoved ) | |
3013 | { | |
3014 | if ( item ) | |
3015 | item->Notification(this, message, itemData); | |
3016 | return; | |
3017 | } | |
3018 | else if ( message == kDataBrowserItemAdded ) | |
3019 | { | |
3020 | // we don't issue events on adding, the item is not really stored in the list yet, so we | |
3021 | // avoid asserts by getting out now | |
3022 | if ( item ) | |
3023 | item->Notification(this, message, itemData); | |
3024 | return ; | |
3025 | } | |
3026 | ||
b2680ced | 3027 | wxListCtrl *list = wxDynamicCast( GetWXPeer() , wxListCtrl ); |
489468fe SC |
3028 | if ( list ) |
3029 | { | |
3030 | bool trigger = false; | |
3031 | ||
3032 | wxListEvent event( wxEVT_COMMAND_LIST_ITEM_SELECTED, list->GetId() ); | |
3033 | ||
3034 | event.SetEventObject( list ); | |
3035 | if ( !list->IsVirtual() ) | |
3036 | { | |
3037 | DataBrowserTableViewRowIndex result = 0; | |
3038 | verify_noerr( GetItemRow( itemID, &result ) ) ; | |
3039 | event.m_itemIndex = result; | |
3040 | } | |
3041 | else | |
3042 | { | |
3043 | event.m_itemIndex = (long)itemID-1; | |
3044 | } | |
3045 | event.m_item.m_itemId = event.m_itemIndex; | |
3046 | list->GetItem(event.m_item); | |
3047 | ||
3048 | switch (message) | |
3049 | { | |
3050 | case kDataBrowserItemDeselected: | |
3051 | event.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED); | |
3052 | // as the generic implementation is also triggering this | |
3053 | // event for single selection, we do the same (different than listbox) | |
3054 | trigger = !IsSelectionSuppressed(); | |
3055 | break; | |
3056 | ||
3057 | case kDataBrowserItemSelected: | |
3058 | trigger = !IsSelectionSuppressed(); | |
3059 | ||
3060 | break; | |
3061 | ||
3062 | case kDataBrowserItemDoubleClicked: | |
3063 | event.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); | |
3064 | trigger = true; | |
3065 | break; | |
3066 | ||
3067 | case kDataBrowserEditStarted : | |
3068 | // TODO : how to veto ? | |
3069 | event.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT ) ; | |
3070 | trigger = true ; | |
3071 | break ; | |
3072 | ||
3073 | case kDataBrowserEditStopped : | |
3074 | // TODO probably trigger only upon the value store callback, because | |
3075 | // here IIRC we cannot veto | |
3076 | event.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT ) ; | |
3077 | trigger = true ; | |
3078 | break ; | |
3079 | ||
3080 | default: | |
3081 | break; | |
3082 | } | |
3083 | ||
3084 | if ( trigger ) | |
3085 | { | |
3086 | // direct notification is not always having the listbox GetSelection() having in synch with event | |
3087 | wxPostEvent( list->GetEventHandler(), event ); | |
3088 | } | |
3089 | } | |
3090 | } | |
3091 | ||
3092 | Boolean wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID, | |
3093 | DataBrowserItemID itemTwoID, | |
3094 | DataBrowserPropertyID sortProperty) | |
3095 | { | |
3096 | ||
3097 | bool retval = false; | |
3098 | wxString itemText; | |
3099 | wxString otherItemText; | |
3100 | long itemOrder; | |
3101 | long otherItemOrder; | |
3102 | ||
3103 | int colId = sortProperty - kMinColumnId; | |
3104 | ||
b2680ced | 3105 | wxListCtrl* list = wxDynamicCast( GetWXPeer() , wxListCtrl ); |
489468fe SC |
3106 | |
3107 | DataBrowserSortOrder sort; | |
3108 | verify_noerr(GetSortOrder(&sort)); | |
3109 | ||
3110 | if (colId >= 0) | |
3111 | { | |
3112 | if (!m_isVirtual) | |
3113 | { | |
3114 | wxMacListCtrlItem* item = (wxMacListCtrlItem*)itemOneID; | |
3115 | wxMacListCtrlItem* otherItem = (wxMacListCtrlItem*)itemTwoID; | |
3116 | ||
3117 | itemOrder = item->GetOrder(); | |
3118 | otherItemOrder = item->GetOrder(); | |
3119 | ||
3120 | wxListCtrlCompare func = list->GetCompareFunc(); | |
3121 | if (func != NULL) | |
3122 | { | |
3123 | long item1 = -1; | |
3124 | long item2 = -1; | |
3125 | if (item && item->HasColumnInfo(0)) | |
3126 | item1 = item->GetColumnInfo(0)->GetData(); | |
3127 | if (otherItem && otherItem->HasColumnInfo(0)) | |
3128 | item2 = otherItem->GetColumnInfo(0)->GetData(); | |
3129 | ||
3130 | if (item1 > -1 && item2 > -1) | |
3131 | { | |
3132 | int result = func(item1, item2, list->GetCompareFuncData()); | |
3133 | if (sort == kDataBrowserOrderIncreasing) | |
3134 | return result >= 0; | |
3135 | else | |
3136 | return result < 0; | |
3137 | } | |
3138 | } | |
3139 | ||
3140 | // we can't use the native control's sorting abilities, so just | |
3141 | // sort by item id. | |
3142 | return itemOrder < otherItemOrder; | |
3143 | } | |
3144 | else | |
3145 | { | |
3146 | ||
3147 | long itemNum = (long)itemOneID; | |
3148 | long otherItemNum = (long)itemTwoID; | |
3149 | ||
3150 | // virtual listctrls don't support sorting | |
3151 | return itemNum < otherItemNum; | |
3152 | } | |
3153 | } | |
3154 | else{ | |
3155 | // fallback for undefined cases | |
3156 | retval = itemOneID < itemTwoID; | |
3157 | } | |
3158 | ||
3159 | return retval; | |
3160 | } | |
3161 | ||
3162 | wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl() | |
3163 | { | |
3164 | } | |
3165 | ||
3166 | void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row, unsigned int column, wxListItem* item ) | |
3167 | { | |
3168 | wxMacDataItem* dataItem = GetItemFromLine(row); | |
3169 | wxASSERT_MSG( dataItem, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") ); | |
3170 | if (item) | |
3171 | { | |
3172 | wxMacListCtrlItem* listItem = wx_static_cast(wxMacListCtrlItem*,dataItem); | |
3173 | bool hasInfo = listItem->HasColumnInfo( column ); | |
3174 | listItem->SetColumnInfo( column, item ); | |
3175 | listItem->SetOrder(row); | |
3176 | UpdateState(dataItem, item); | |
3177 | ||
b2680ced | 3178 | wxListCtrl* list = wxDynamicCast( GetWXPeer() , wxListCtrl ); |
489468fe SC |
3179 | |
3180 | // NB: When this call was made before a control was completely shown, it would | |
3181 | // update the item prematurely (i.e. no text would be listed) and, on show, | |
3182 | // only the sorted column would be refreshed, meaning only first column text labels | |
3183 | // would be shown. Making sure not to update items until the control is visible | |
3184 | // seems to fix this issue. | |
3185 | if (hasInfo && list->IsShown()) | |
3186 | UpdateItem( wxMacDataBrowserRootContainer, listItem , kMinColumnId + column ); | |
3187 | } | |
3188 | } | |
3189 | ||
3190 | // apply changes that need to happen immediately, rather than when the | |
3191 | // databrowser control fires a callback. | |
3192 | void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem* dataItem, wxListItem* listItem) | |
3193 | { | |
3194 | bool isSelected = IsItemSelected( dataItem ); | |
3195 | bool isSelectedState = (listItem->GetState() == wxLIST_STATE_SELECTED); | |
3196 | ||
3197 | // toggle the selection state if wxListInfo state and actual state don't match. | |
3198 | if ( listItem->GetMask() & wxLIST_MASK_STATE && isSelected != isSelectedState ) | |
3199 | { | |
3200 | DataBrowserSetOption options = kDataBrowserItemsAdd; | |
3201 | if (!isSelectedState) | |
3202 | options = kDataBrowserItemsRemove; | |
3203 | SetSelectedItem(dataItem, options); | |
3204 | } | |
3205 | // TODO: Set column width if item width > than current column width | |
3206 | } | |
3207 | ||
3208 | void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row, unsigned int column, wxListItem& item ) | |
3209 | { | |
3210 | wxMacDataItem* dataItem = GetItemFromLine(row); | |
3211 | wxASSERT_MSG( dataItem, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") ); | |
3212 | // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate | |
3213 | //if (item) | |
3214 | { | |
3215 | wxMacListCtrlItem* listItem =wx_static_cast(wxMacListCtrlItem*,dataItem); | |
3216 | ||
3217 | if (!listItem->HasColumnInfo( column )) | |
3218 | return; | |
3219 | ||
3220 | wxListItem* oldItem = listItem->GetColumnInfo( column ); | |
3221 | ||
3222 | if (oldItem) | |
3223 | { | |
3224 | long mask = item.GetMask(); | |
3225 | if ( !mask ) | |
3226 | // by default, get everything for backwards compatibility | |
3227 | mask = -1; | |
3228 | ||
3229 | if ( mask & wxLIST_MASK_TEXT ) | |
3230 | item.SetText(oldItem->GetText()); | |
3231 | if ( mask & wxLIST_MASK_IMAGE ) | |
3232 | item.SetImage(oldItem->GetImage()); | |
3233 | if ( mask & wxLIST_MASK_DATA ) | |
3234 | item.SetData(oldItem->GetData()); | |
3235 | if ( mask & wxLIST_MASK_STATE ) | |
3236 | item.SetState(oldItem->GetState()); | |
3237 | if ( mask & wxLIST_MASK_WIDTH ) | |
3238 | item.SetWidth(oldItem->GetWidth()); | |
3239 | if ( mask & wxLIST_MASK_FORMAT ) | |
3240 | item.SetAlign(oldItem->GetAlign()); | |
3241 | ||
3242 | item.SetTextColour(oldItem->GetTextColour()); | |
3243 | item.SetBackgroundColour(oldItem->GetBackgroundColour()); | |
3244 | item.SetFont(oldItem->GetFont()); | |
3245 | } | |
3246 | } | |
3247 | } | |
3248 | ||
3249 | void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n, wxListItem* item ) | |
3250 | { | |
3251 | wxMacDataItemBrowserControl::MacInsert(n, item->GetText()); | |
3252 | MacSetColumnInfo(n, 0, item); | |
3253 | } | |
3254 | ||
3255 | wxMacDataItem* wxMacDataBrowserListCtrlControl::CreateItem() | |
3256 | { | |
3257 | return new wxMacListCtrlItem(); | |
3258 | } | |
3259 | ||
3260 | wxMacListCtrlItem::wxMacListCtrlItem() | |
3261 | { | |
3262 | m_rowItems = wxListItemList(); | |
3263 | } | |
3264 | ||
3265 | int wxMacListCtrlItem::GetColumnImageValue( unsigned int column ) | |
3266 | { | |
3267 | if ( HasColumnInfo(column) ) | |
3268 | return GetColumnInfo(column)->GetImage(); | |
3269 | ||
3270 | return -1; | |
3271 | } | |
3272 | ||
3273 | void wxMacListCtrlItem::SetColumnImageValue( unsigned int column, int imageIndex ) | |
3274 | { | |
3275 | if ( HasColumnInfo(column) ) | |
3276 | GetColumnInfo(column)->SetImage(imageIndex); | |
3277 | } | |
3278 | ||
3279 | wxString wxMacListCtrlItem::GetColumnTextValue( unsigned int column ) | |
3280 | { | |
3281 | if ( column == 0 ) | |
3282 | return GetLabel(); | |
3283 | ||
3284 | if ( HasColumnInfo(column) ) | |
3285 | return GetColumnInfo(column)->GetText(); | |
3286 | ||
3287 | return wxEmptyString; | |
3288 | } | |
3289 | ||
3290 | void wxMacListCtrlItem::SetColumnTextValue( unsigned int column, const wxString& text ) | |
3291 | { | |
3292 | if ( HasColumnInfo(column) ) | |
3293 | GetColumnInfo(column)->SetText(text); | |
3294 | ||
3295 | // for compatibility with superclass APIs | |
3296 | if ( column == 0 ) | |
3297 | SetLabel(text); | |
3298 | } | |
3299 | ||
3300 | wxListItem* wxMacListCtrlItem::GetColumnInfo( unsigned int column ) | |
3301 | { | |
3302 | wxASSERT_MSG( HasColumnInfo(column), _T("invalid column index in wxMacListCtrlItem") ); | |
3303 | return m_rowItems[column]; | |
3304 | } | |
3305 | ||
3306 | bool wxMacListCtrlItem::HasColumnInfo( unsigned int column ) | |
3307 | { | |
3308 | return !(m_rowItems.find( column ) == m_rowItems.end()); | |
3309 | } | |
3310 | ||
3311 | void wxMacListCtrlItem::SetColumnInfo( unsigned int column, wxListItem* item ) | |
3312 | { | |
3313 | ||
3314 | if ( !HasColumnInfo(column) ) | |
3315 | { | |
3316 | wxListItem* listItem = new wxListItem(*item); | |
3317 | m_rowItems[column] = listItem; | |
3318 | } | |
3319 | else | |
3320 | { | |
3321 | wxListItem* listItem = GetColumnInfo( column ); | |
3322 | long mask = item->GetMask(); | |
3323 | if (mask & wxLIST_MASK_TEXT) | |
3324 | listItem->SetText(item->GetText()); | |
3325 | if (mask & wxLIST_MASK_DATA) | |
3326 | listItem->SetData(item->GetData()); | |
3327 | if (mask & wxLIST_MASK_IMAGE) | |
3328 | listItem->SetImage(item->GetImage()); | |
3329 | if (mask & wxLIST_MASK_STATE) | |
3330 | listItem->SetState(item->GetState()); | |
3331 | if (mask & wxLIST_MASK_FORMAT) | |
3332 | listItem->SetAlign(item->GetAlign()); | |
3333 | if (mask & wxLIST_MASK_WIDTH) | |
3334 | listItem->SetWidth(item->GetWidth()); | |
3335 | ||
3336 | if ( item->HasAttributes() ) | |
3337 | { | |
3338 | if ( listItem->HasAttributes() ) | |
3339 | listItem->GetAttributes()->AssignFrom(*item->GetAttributes()); | |
3340 | else | |
3341 | { | |
3342 | listItem->SetTextColour(item->GetTextColour()); | |
3343 | listItem->SetBackgroundColour(item->GetBackgroundColour()); | |
3344 | listItem->SetFont(item->GetFont()); | |
3345 | } | |
3346 | } | |
3347 | } | |
3348 | } | |
3349 | ||
3350 | int wxListCtrl::CalcColumnAutoWidth(int col) const | |
3351 | { | |
3352 | int width = 0; | |
3353 | ||
3354 | for ( int i = 0; i < GetItemCount(); i++ ) | |
3355 | { | |
3356 | wxListItem info; | |
3357 | info.SetMask(wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE); | |
3358 | info.SetId(i); | |
3359 | info.SetColumn(col); | |
3360 | GetItem(info); | |
3361 | ||
3362 | const wxFont font = info.GetFont(); | |
3363 | ||
3364 | int w = 0; | |
3365 | if ( font.IsOk() ) | |
3366 | GetTextExtent(info.GetText(), &w, NULL, NULL, NULL, &font); | |
3367 | else | |
3368 | GetTextExtent(info.GetText(), &w, NULL); | |
3369 | ||
3370 | w += 2 * kItemPadding; | |
3371 | ||
3372 | if ( info.GetImage() != -1 ) | |
3373 | w += kIconWidth; | |
3374 | ||
3375 | width = wxMax(width, w); | |
3376 | } | |
3377 | ||
3378 | return width; | |
3379 | } | |
3380 | ||
3381 | #endif // wxUSE_LISTCTRL | |
3382 |