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