4 * Created by Toshi Nagata on 08/12/09.
5 * Copyright 2008-2009 Toshi Nagata. All rights reserved.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation version 2 of the License.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
18 #ifndef __MyListCtrl_h__
19 #define __MyListCtrl_h__
21 #include "wx/listctrl.h"
22 #include "wx/generic/listctrl.h"
24 #include "wx/string.h"
25 #include "wx/textctrl.h"
29 extern const wxEventType MyListCtrlEvent;
31 MyListCtrlEvent_tableSelectionChanged,
32 MyListCtrlEvent_enableTableSelectionNotification
35 /* Data source protocol */
36 class MyListCtrlDataSource {
38 virtual int GetItemCount(MyListCtrl *ctrl) { return 0; }
39 virtual wxString GetItemText(MyListCtrl *ctrl, long row, long column) const { return _T(""); }
40 virtual int SetItemText(MyListCtrl *ctrl, long row, long column, const wxString &value) { return 0; }
41 virtual void DragSelectionToRow(MyListCtrl *ctrl, long row) {}
42 virtual bool IsItemEditable(MyListCtrl *ctrl, long row, long column) { return false; }
43 virtual bool IsDragAndDropEnabled(MyListCtrl *ctrl) { return false; }
44 virtual void OnSelectionChanged(MyListCtrl *ctrl) {}
46 // If a popup menu is attached to the cell, then returns a positive integer, and *menu_titles should
47 // contain a malloc()'ed array of char* pointers (that are also malloc()'ed or strdup()'ed)
48 virtual int HasPopUpMenu(MyListCtrl *ctrl, long row, long column, char ***menu_titles) { return 0; }
49 virtual void OnPopUpMenuSelected(MyListCtrl *ctrl, long row, long column, int selected_index) {}
51 // Return 1 if foreground color should be modified, 2 if background color should be modified, 3 if both
52 virtual int SetItemColor(MyListCtrl *ctrl, long row, long col, float *fg, float *bg) { return 0; }
55 class MyListCtrl: public wxGenericListCtrl {
58 MyListCtrlDataSource *dataSource;
60 int editRow, editColumn;
61 wxListItemAttr *subTitleRowAttr; /* Used in SetItemColor() */
65 virtual ~MyListCtrl();
67 bool Create(wxWindow* parent, wxWindowID wid, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize);
69 void SetDataSource(MyListCtrlDataSource *source);
73 virtual wxString OnGetItemText(long item, long column) const;
74 virtual wxListItemAttr *OnGetItemAttr(long item) const;
76 void StartEditing(long item, long column);
77 void EndEditing(long item, long column);
79 void GetScrollPixelsPerUnit(int *xunit, int *yunit);
80 bool GetItemRectForRowAndColumn(wxRect &rect, int row, int column);
81 bool FindItemAtPosition(const wxPoint &pos, int *row, int *column);
83 void SetItemTextForColumn(long item, long column, const wxString &text);
85 void StartEditText(int row, int column);
86 void EndEditTextAndRestart(bool setValueFlag, int newRow, int newColumn);
87 void EndEditText(bool setValueFlag = true);
88 void OnKeyDownOnEditText(wxKeyEvent &event);
89 void OnKillFocusOnEditText(wxFocusEvent &event);
90 void OnIdle(wxIdleEvent &event);
92 void OnPaintCallback(wxDC *dc);
94 /* Override the wxListCtrl functions to take care of the internal text editor */
95 bool DeleteColumn(int col);
96 bool InsertColumn(long col, const wxString &heading, int format = wxLIST_FORMAT_LEFT, int width = -1);
98 void OnItemSelectionChanged(wxListEvent &event);
99 void OnTableSelectionChanged(wxCommandEvent &event);
100 void EnableSelectionChangeNotification(bool flag) { selectionChangeNotificationEnabled = flag; }
101 void OnEnableTableSelectionNotification(wxCommandEvent &event);
103 void OnBeginLabelEdit(wxListEvent &event);
104 void OnEndLabelEdit(wxListEvent &event);
105 void OnItemActivated(wxListEvent &event);
106 void OnBeginDrag(wxListEvent &event);
108 void OnChar(wxKeyEvent &event);
109 void OnMouseDown(wxMouseEvent &event);
110 void OnPopUpMenuSelected(wxCommandEvent &event);
111 void OnLeftDClick(wxMouseEvent &event);
113 void PostSelectionChangeNotification();
115 bool selectionChangeNotificationSent;
116 bool selectionChangeNotificationEnabled;
117 int lastPopUpColumn, lastPopUpRow;
120 DECLARE_DYNAMIC_CLASS(MyListCtrl)
121 DECLARE_EVENT_TABLE()
124 #endif /* __MyListCtrl_h__ */