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