*** empty log message ***
[wxWidgets.git] / src / os2 / listctrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: listctrl.cpp
3 // Purpose: wxListCtrl. See also Robert's generic wxListCtrl
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "listctrl.h"
14 #endif
15
16 #include "wx/stubs/textctrl.h"
17 #include "wx/stubs/listctrl.h"
18
19 #if !USE_SHARED_LIBRARY
20 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)
21 IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
22
23 #endif
24
25 wxListCtrl::wxListCtrl()
26 {
27 m_imageListNormal = NULL;
28 m_imageListSmall = NULL;
29 m_imageListState = NULL;
30 m_baseStyle = 0;
31 m_colCount = 0;
32 }
33
34 bool wxListCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
35 long style, const wxValidator& validator, const wxString& name)
36 {
37 m_imageListNormal = NULL;
38 m_imageListSmall = NULL;
39 m_imageListState = NULL;
40 m_colCount = 0;
41
42 SetValidator(validator);
43 SetName(name);
44
45 m_windowStyle = style;
46
47 SetParent(parent);
48
49 m_windowId = (id == -1) ? NewControlId() : id;
50
51 if (parent) parent->AddChild(this);
52
53 // TODO create list control
54 return TRUE;
55 }
56
57 wxListCtrl::~wxListCtrl()
58 {
59 }
60
61 // Add or remove a single window style
62 void wxListCtrl::SetSingleStyle(long style, bool add)
63 {
64 long flag = GetWindowStyleFlag();
65
66 // Get rid of conflicting styles
67 if ( add )
68 {
69 if ( style & wxLC_MASK_TYPE)
70 flag = flag & ~wxLC_MASK_TYPE ;
71 if ( style & wxLC_MASK_ALIGN )
72 flag = flag & ~wxLC_MASK_ALIGN ;
73 if ( style & wxLC_MASK_SORT )
74 flag = flag & ~wxLC_MASK_SORT ;
75 }
76
77 if ( flag & style )
78 {
79 if ( !add )
80 flag -= style;
81 }
82 else
83 {
84 if ( add )
85 {
86 flag |= style;
87 }
88 }
89
90 m_windowStyle = flag;
91
92 /* TODO RecreateWindow(); */
93 }
94
95 // Set the whole window style
96 void wxListCtrl::SetWindowStyleFlag(long flag)
97 {
98 m_windowStyle = flag;
99
100 /* TODO RecreateWindow(); */
101 }
102
103
104 // Gets information about this column
105 bool wxListCtrl::GetColumn(int col, wxListItem& item) const
106 {
107 // TODO
108 return FALSE;
109 }
110
111 // Sets information about this column
112 bool wxListCtrl::SetColumn(int col, wxListItem& item)
113 {
114 // TODO
115 return FALSE;
116 }
117
118 // Gets the column width
119 int wxListCtrl::GetColumnWidth(int col) const
120 {
121 // TODO
122 return 0;
123 }
124
125 // Sets the column width
126 bool wxListCtrl::SetColumnWidth(int col, int width)
127 {
128 // TODO
129 return FALSE;
130 }
131
132 // Gets the number of items that can fit vertically in the
133 // visible area of the list control (list or report view)
134 // or the total number of items in the list control (icon
135 // or small icon view)
136 int wxListCtrl::GetCountPerPage() const
137 {
138 // TODO
139 return 0;
140 }
141
142 // Gets the edit control for editing labels.
143 wxTextCtrl* wxListCtrl::GetEditControl() const
144 {
145 return m_textCtrl;
146 }
147
148 // Gets information about the item
149 bool wxListCtrl::GetItem(wxListItem& info) const
150 {
151 // TODO
152 return FALSE;
153 }
154
155 // Sets information about the item
156 bool wxListCtrl::SetItem(wxListItem& info)
157 {
158 // TODO
159 return FALSE;
160 }
161
162 long wxListCtrl::SetItem(long index, int col, const wxString& label, int imageId)
163 {
164 wxListItem info;
165 info.m_text = label;
166 info.m_mask = wxLIST_MASK_TEXT;
167 info.m_itemId = index;
168 info.m_col = col;
169 if ( imageId > -1 )
170 {
171 info.m_image = imageId;
172 info.m_mask |= wxLIST_MASK_IMAGE;
173 }
174 return SetItem(info);
175 }
176
177
178 // Gets the item state
179 int wxListCtrl::GetItemState(long item, long stateMask) const
180 {
181 wxListItem info;
182
183 info.m_mask = wxLIST_MASK_STATE ;
184 info.m_stateMask = stateMask;
185 info.m_itemId = item;
186
187 if (!GetItem(info))
188 return 0;
189
190 return info.m_state;
191 }
192
193 // Sets the item state
194 bool wxListCtrl::SetItemState(long item, long state, long stateMask)
195 {
196 wxListItem info;
197
198 info.m_mask = wxLIST_MASK_STATE ;
199 info.m_state = state;
200 info.m_stateMask = stateMask;
201 info.m_itemId = item;
202
203 return SetItem(info);
204 }
205
206 // Sets the item image
207 bool wxListCtrl::SetItemImage(long item, int image, int selImage)
208 {
209 wxListItem info;
210
211 info.m_mask = wxLIST_MASK_IMAGE ;
212 info.m_image = image;
213 info.m_itemId = item;
214
215 return SetItem(info);
216 }
217
218 // Gets the item text
219 wxString wxListCtrl::GetItemText(long item) const
220 {
221 wxListItem info;
222
223 info.m_mask = wxLIST_MASK_TEXT ;
224 info.m_itemId = item;
225
226 if (!GetItem(info))
227 return wxString("");
228 return info.m_text;
229 }
230
231 // Sets the item text
232 void wxListCtrl::SetItemText(long item, const wxString& str)
233 {
234 wxListItem info;
235
236 info.m_mask = wxLIST_MASK_TEXT ;
237 info.m_itemId = item;
238 info.m_text = str;
239
240 SetItem(info);
241 }
242
243 // Gets the item data
244 long wxListCtrl::GetItemData(long item) const
245 {
246 wxListItem info;
247
248 info.m_mask = wxLIST_MASK_DATA ;
249 info.m_itemId = item;
250
251 if (!GetItem(info))
252 return 0;
253 return info.m_data;
254 }
255
256 // Sets the item data
257 bool wxListCtrl::SetItemData(long item, long data)
258 {
259 wxListItem info;
260
261 info.m_mask = wxLIST_MASK_DATA ;
262 info.m_itemId = item;
263 info.m_data = data;
264
265 return SetItem(info);
266 }
267
268 // Gets the item rectangle
269 bool wxListCtrl::GetItemRect(long item, wxRect& rect, int code) const
270 {
271 // TODO
272 return FALSE;
273 }
274
275 // Gets the item position
276 bool wxListCtrl::GetItemPosition(long item, wxPoint& pos) const
277 {
278 // TODO
279 return FALSE;
280 }
281
282 // Sets the item position.
283 bool wxListCtrl::SetItemPosition(long item, const wxPoint& pos)
284 {
285 // TODO
286 return FALSE;
287 }
288
289 // Gets the number of items in the list control
290 int wxListCtrl::GetItemCount() const
291 {
292 // TODO
293 return FALSE;
294 }
295
296 // Retrieves the spacing between icons in pixels.
297 // If small is TRUE, gets the spacing for the small icon
298 // view, otherwise the large icon view.
299 int wxListCtrl::GetItemSpacing(bool isSmall) const
300 {
301 // TODO
302 return FALSE;
303 }
304
305 // Gets the number of selected items in the list control
306 int wxListCtrl::GetSelectedItemCount() const
307 {
308 // TODO
309 return FALSE;
310 }
311
312 // Gets the text colour of the listview
313 wxColour wxListCtrl::GetTextColour() const
314 {
315 // TODO
316 return wxColour();
317 }
318
319 // Sets the text colour of the listview
320 void wxListCtrl::SetTextColour(const wxColour& col)
321 {
322 // TODO
323 }
324
325 // Gets the index of the topmost visible item when in
326 // list or report view
327 long wxListCtrl::GetTopItem() const
328 {
329 // TODO
330 return 0;
331 }
332
333 // Searches for an item, starting from 'item'.
334 // 'geometry' is one of
335 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
336 // 'state' is a state bit flag, one or more of
337 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
338 // item can be -1 to find the first item that matches the
339 // specified flags.
340 // Returns the item or -1 if unsuccessful.
341 long wxListCtrl::GetNextItem(long item, int geom, int state) const
342 {
343 // TODO
344 return 0;
345 }
346
347 wxImageList *wxListCtrl::GetImageList(int which) const
348 {
349 if ( which == wxIMAGE_LIST_NORMAL )
350 {
351 return m_imageListNormal;
352 }
353 else if ( which == wxIMAGE_LIST_SMALL )
354 {
355 return m_imageListSmall;
356 }
357 else if ( which == wxIMAGE_LIST_STATE )
358 {
359 return m_imageListState;
360 }
361 return NULL;
362 }
363
364 void wxListCtrl::SetImageList(wxImageList *imageList, int which)
365 {
366 int flags = 0;
367 if ( which == wxIMAGE_LIST_NORMAL )
368 {
369 m_imageListNormal = imageList;
370 }
371 else if ( which == wxIMAGE_LIST_SMALL )
372 {
373 m_imageListSmall = imageList;
374 }
375 else if ( which == wxIMAGE_LIST_STATE )
376 {
377 m_imageListState = imageList;
378 }
379 // TODO set image list
380 }
381
382 // Operations
383 ////////////////////////////////////////////////////////////////////////////
384
385 // Arranges the items
386 bool wxListCtrl::Arrange(int flag)
387 {
388 // TODO
389 return FALSE;
390 }
391
392 // Deletes an item
393 bool wxListCtrl::DeleteItem(long item)
394 {
395 // TODO
396 return FALSE;
397 }
398
399 // Deletes all items
400 bool wxListCtrl::DeleteAllItems()
401 {
402 // TODO
403 return FALSE;
404 }
405
406 // Deletes all items
407 bool wxListCtrl::DeleteAllColumns()
408 {
409 // TODO
410 return FALSE;
411 }
412
413 // Deletes a column
414 bool wxListCtrl::DeleteColumn(int col)
415 {
416 // TODO
417 return FALSE;
418 }
419
420 // Clears items, and columns if there are any.
421 void wxListCtrl::ClearAll()
422 {
423 DeleteAllItems();
424 if ( m_colCount > 0 )
425 DeleteAllColumns();
426 }
427
428 // Edit the label
429 wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass)
430 {
431 // TODO
432 return NULL;
433 }
434
435 // End label editing, optionally cancelling the edit
436 bool wxListCtrl::EndEditLabel(bool cancel)
437 {
438 // TODO
439 return FALSE;
440 }
441
442 // Ensures this item is visible
443 bool wxListCtrl::EnsureVisible(long item)
444 {
445 // TODO
446 return FALSE;
447 }
448
449 // Find an item whose label matches this string, starting from the item after 'start'
450 // or the beginning if 'start' is -1.
451 long wxListCtrl::FindItem(long start, const wxString& str, bool partial)
452 {
453 // TODO
454 return FALSE;
455 }
456
457 // Find an item whose data matches this data, starting from the item after 'start'
458 // or the beginning if 'start' is -1.
459 long wxListCtrl::FindItem(long start, long data)
460 {
461 // TODO
462 return 0;
463 }
464
465 // Find an item nearest this position in the specified direction, starting from
466 // the item after 'start' or the beginning if 'start' is -1.
467 long wxListCtrl::FindItem(long start, const wxPoint& pt, int direction)
468 {
469 // TODO
470 return 0;
471 }
472
473 // Determines which item (if any) is at the specified point,
474 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
475 long wxListCtrl::HitTest(const wxPoint& point, int& flags)
476 {
477 // TODO
478 return 0;
479 }
480
481 // Inserts an item, returning the index of the new item if successful,
482 // -1 otherwise.
483 long wxListCtrl::InsertItem(wxListItem& info)
484 {
485 // TODO
486 return 0;
487 }
488
489 long wxListCtrl::InsertItem(long index, const wxString& label)
490 {
491 wxListItem info;
492 info.m_text = label;
493 info.m_mask = wxLIST_MASK_TEXT;
494 info.m_itemId = index;
495 return InsertItem(info);
496 }
497
498 // Inserts an image item
499 long wxListCtrl::InsertItem(long index, int imageIndex)
500 {
501 wxListItem info;
502 info.m_image = imageIndex;
503 info.m_mask = wxLIST_MASK_IMAGE;
504 info.m_itemId = index;
505 return InsertItem(info);
506 }
507
508 // Inserts an image/string item
509 long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex)
510 {
511 wxListItem info;
512 info.m_image = imageIndex;
513 info.m_text = label;
514 info.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT;
515 info.m_itemId = index;
516 return InsertItem(info);
517 }
518
519 // For list view mode (only), inserts a column.
520 long wxListCtrl::InsertColumn(long col, wxListItem& item)
521 {
522 // TODO
523 return 0;
524 }
525
526 long wxListCtrl::InsertColumn(long col, const wxString& heading, int format,
527 int width)
528 {
529 wxListItem item;
530 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
531 item.m_text = heading;
532 if ( width > -1 )
533 {
534 item.m_mask |= wxLIST_MASK_WIDTH;
535 item.m_width = width;
536 }
537 item.m_format = format;
538
539 return InsertColumn(col, item);
540 }
541
542 // Scrolls the list control. If in icon, small icon or report view mode,
543 // x specifies the number of pixels to scroll. If in list view mode, x
544 // specifies the number of columns to scroll.
545 // If in icon, small icon or list view mode, y specifies the number of pixels
546 // to scroll. If in report view mode, y specifies the number of lines to scroll.
547 bool wxListCtrl::ScrollList(int dx, int dy)
548 {
549 // TODO
550 return FALSE;
551 }
552
553 // Sort items.
554
555 // fn is a function which takes 3 long arguments: item1, item2, data.
556 // item1 is the long data associated with a first item (NOT the index).
557 // item2 is the long data associated with a second item (NOT the index).
558 // data is the same value as passed to SortItems.
559 // The return value is a negative number if the first item should precede the second
560 // item, a positive number of the second item should precede the first,
561 // or zero if the two items are equivalent.
562
563 // data is arbitrary data to be passed to the sort function.
564 bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data)
565 {
566 // TODO
567 return FALSE;
568 }
569
570 // List item structure
571 wxListItem::wxListItem()
572 {
573 m_mask = 0;
574 m_itemId = 0;
575 m_col = 0;
576 m_state = 0;
577 m_stateMask = 0;
578 m_image = 0;
579 m_data = 0;
580
581 m_format = wxLIST_FORMAT_CENTRE;
582 m_width = 0;
583 }
584
585 // List event
586 IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxCommandEvent)
587
588 wxListEvent::wxListEvent(wxEventType commandType, int id):
589 wxCommandEvent(commandType, id)
590 {
591 m_code = 0;
592 m_itemIndex = 0;
593 m_col = 0;
594 m_cancelled = FALSE;
595 }
596