OSDN Git Service

Compiler warnings are mostly removed.
[molby/Molby.git] / wxSources / MyListCtrl_orig.h
1 /*
2  *  MyListCtrl.h
3  *
4  *  Created by Toshi Nagata on 08/12/09.
5  *  Copyright 2008-2009 Toshi Nagata. All rights reserved.
6
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.
10  
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.
15
16  */
17
18 #ifndef __MyListCtrl_h__
19 #define __MyListCtrl_h__
20
21 #include "wx/listctrl.h"
22 #include "wx/generic/listctrl.h"
23
24 #include "wx/string.h"
25 #include "wx/textctrl.h"
26 #include "wx/dc.h"
27
28 class MyListCtrl;
29 extern const wxEventType MyListCtrlEvent;
30 enum {
31         MyListCtrlEvent_tableSelectionChanged,
32         MyListCtrlEvent_enableTableSelectionNotification
33 };
34
35 /*  Data source protocol  */
36 class MyListCtrlDataSource {
37 public:
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) {}
45
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) {}
50
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; }
53 };
54
55 class MyListCtrl: public wxGenericListCtrl {
56
57 public:
58         MyListCtrlDataSource *dataSource;
59         wxTextCtrl *editText;
60         int editRow, editColumn;
61         wxListItemAttr *subTitleRowAttr;  /*  Used in SetItemColor()  */
62         int dragTargetRow;
63
64         MyListCtrl();
65         virtual ~MyListCtrl();
66         
67         bool Create(wxWindow* parent, wxWindowID wid, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize);
68
69         void SetDataSource(MyListCtrlDataSource *source);
70
71         void RefreshTable();
72
73         virtual wxString OnGetItemText(long item, long column) const;
74         virtual wxListItemAttr *OnGetItemAttr(long item) const;
75
76         void StartEditing(long item, long column);
77         void EndEditing(long item, long column);
78
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);
82         
83         void SetItemTextForColumn(long item, long column, const wxString &text);
84
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);
91         
92         void OnPaintCallback(wxDC *dc);
93
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);
97         
98         void OnItemSelectionChanged(wxListEvent &event);
99         void OnTableSelectionChanged(wxCommandEvent &event);
100         void EnableSelectionChangeNotification(bool flag) { selectionChangeNotificationEnabled = flag; }
101         void OnEnableTableSelectionNotification(wxCommandEvent &event);
102
103         void OnBeginLabelEdit(wxListEvent &event);
104         void OnEndLabelEdit(wxListEvent &event);
105         void OnItemActivated(wxListEvent &event);
106         void OnBeginDrag(wxListEvent &event);
107         
108         void OnChar(wxKeyEvent &event);
109         void OnMouseDown(wxMouseEvent &event);
110         void OnPopUpMenuSelected(wxCommandEvent &event);
111         void OnLeftDClick(wxMouseEvent &event);
112         
113         void PostSelectionChangeNotification();
114         
115         bool selectionChangeNotificationSent;
116         bool selectionChangeNotificationEnabled;
117         int lastPopUpColumn, lastPopUpRow;
118
119 private:
120         DECLARE_DYNAMIC_CLASS(MyListCtrl)
121         DECLARE_EVENT_TABLE()
122 };
123
124 #endif /* __MyListCtrl_h__ */