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