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