1 // This file is part of BOINC.
2 // http://boinc.berkeley.edu
3 // Copyright (C) 2008 University of California
4 //
5 // BOINC is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU Lesser General Public License
7 // as published by the Free Software Foundation,
8 // either version 3 of the License, or (at your option) any later version.
9 //
10 // BOINC is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 // See the GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
17 
18 #ifndef BOINC_BOINCBASEVIEW_H
19 #define BOINC_BOINCBASEVIEW_H
20 
21 #if defined(__GNUG__) && !defined(__APPLE__)
22 #pragma interface "BOINCBaseView.cpp"
23 #endif
24 
25 
26 #define DEFAULT_TASK_FLAGS             wxTAB_TRAVERSAL | wxADJUST_MINSIZE | wxFULL_REPAINT_ON_RESIZE
27 #define DEFAULT_LIST_FLAGS             wxLC_REPORT | wxLC_VIRTUAL | wxLC_HRULES
28 
29 class CBOINCTaskCtrl;
30 class CBOINCListCtrl;
31 class CCheckSelectionChangedEvent;
32 struct PROJECT;
33 
34 
35 class CTaskItem : wxObject {
36 public:
37 	CTaskItem();
CTaskItem(wxString strName,wxString strDescription,wxInt32 iEventID)38 	CTaskItem( wxString strName, wxString strDescription, wxInt32 iEventID ) :
39 		m_strName(strName), m_strDescription(strDescription), m_iEventID(iEventID),
40         m_pButton(NULL), m_strWebSiteLink(wxT("")) {};
CTaskItem(wxString strName,wxString strDescription,wxString strWebSiteLink,wxInt32 iEventID)41 	CTaskItem( wxString strName, wxString strDescription, wxString strWebSiteLink, wxInt32 iEventID ) :
42 		m_strName(strName), m_strDescription(strDescription), m_iEventID(iEventID),
43         m_pButton(NULL), m_strWebSiteLink(strWebSiteLink) {};
~CTaskItem()44     ~CTaskItem() {};
45 
46     wxString                m_strName;
47     wxString                m_strNameEllipsed;
48     wxString                m_strDescription;
49     wxInt32                 m_iEventID;
50 
51     wxButton*               m_pButton;
52     wxString                m_strWebSiteLink;
53 };
54 
55 
56 class CTaskItemGroup : wxObject {
57 public:
58 	CTaskItemGroup();
CTaskItemGroup(wxString strName)59 	CTaskItemGroup( wxString strName ) :
60             m_strName(strName), m_pStaticBox(NULL), m_pStaticBoxSizer(NULL) {
61             m_Tasks.clear();
62         };
~CTaskItemGroup()63     ~CTaskItemGroup() {};
button(int i)64     wxButton* button(int i) {return m_Tasks[i]->m_pButton;}
65 
66     wxString                m_strName;
67 
68     wxStaticBox*            m_pStaticBox;
69     wxStaticBoxSizer*       m_pStaticBoxSizer;
70 
71     std::vector<CTaskItem*> m_Tasks;
72 };
73 
74 typedef bool     (*ListSortCompareFunc)(int, int);
75 
76 
77 class CBOINCBaseView : public wxPanel {
78     DECLARE_DYNAMIC_CLASS( CBOINCBaseView )
79 
80 public:
81 
82     CBOINCBaseView();
83     CBOINCBaseView(
84         wxNotebook* pNotebook
85     );
86     CBOINCBaseView(
87         wxNotebook* pNotebook,
88         wxWindowID iTaskWindowID,
89         int iTaskWindowFlags,
90         wxWindowID iListWindowID,
91         int iListWindowFlags
92     );
93 
94     ~CBOINCBaseView();
95 
96     virtual wxString&       GetViewName();
97     virtual wxString&       GetViewDisplayName();
98     virtual const char**    GetViewIcon();
99     virtual int             GetViewRefreshRate();
100     virtual int             GetViewCurrentViewPage();
101 
102     virtual wxString        GetKeyValue1(int iRowIndex);
103     virtual wxString        GetKeyValue2(int iRowIndex);
104     virtual int             FindRowIndexByKeyValues(wxString& key1, wxString& key2);
105 
106     bool                    FireOnSaveState( wxConfigBase* pConfig );
107     bool                    FireOnRestoreState( wxConfigBase* pConfig );
108 
109     virtual int             GetListRowCount();
110     void                    FireOnListRender( wxTimerEvent& event );
111     void                    FireOnListSelected( wxListEvent& event );
112     void                    FireOnListDeselected( wxListEvent& event );
113     wxString                FireOnListGetItemText( long item, long column ) const;
114     int                     FireOnListGetItemImage( long item ) const;
115 
GetProgressColumn()116     int                     GetProgressColumn() { return m_iProgressColumn; }
SetProgressColumn(int col)117     void                    SetProgressColumn(int col) { m_iProgressColumn = col; }
118     virtual double          GetProgressValue(long item);
119     virtual wxString        GetProgressText( long item);
120     virtual void            AppendColumn(int columnID);
121 
122     void                    InitSort();
123     void                    SetSortColumn(int newSortColIndex);
124 	void                    SaveSelections();
125 	void                    RestoreSelections();
126 	void                    ClearSavedSelections();
127 	void                    ClearSelections();
128     void                    RefreshTaskPane();
129 
GetListCtrl()130     CBOINCListCtrl*         GetListCtrl() { return m_pListPane; }
131 
132 #ifdef __WXMAC__
133     void                    OnKeyPressed(wxKeyEvent &event);
134 #endif
135 
136     std::vector<CTaskItemGroup*> m_TaskGroups;
137 
138     int                     m_iSortColumnID;  // ColumnID of sort column
139     bool                    m_bReverseSort;
140     wxArrayString*          m_aStdColNameOrder;
141     wxArrayInt              m_iStdColWidthOrder;
142     wxArrayInt              m_iColumnIndexToColumnID;
143     wxArrayInt              m_iColumnIDToColumnIndex;
144     int*                    m_iDefaultShownColumns;
145     int                     m_iNumDefaultShownColumns;
146 
147 
148 private:
149 
150 	wxArrayString           m_arrSelectedKeys1;     //array for remembering the current selected rows by primary key column value
151 	wxArrayString           m_arrSelectedKeys2;     //array for remembering the current selected rows by secondary key column value
152 
153 protected:
154 
155     virtual bool            OnSaveState( wxConfigBase* pConfig );
156     virtual bool            OnRestoreState( wxConfigBase* pConfig );
157 
158     virtual void            OnListRender( wxTimerEvent& event );
159     virtual void            OnListSelected( wxListEvent& event );
160     virtual void            OnListDeselected( wxListEvent& event );
161     virtual void            OnCacheHint(wxListEvent& event);
162     virtual void            OnCheckSelectionChanged(CCheckSelectionChangedEvent& event);
163     virtual void            CheckSelectionChanged();
164     virtual wxString        OnListGetItemText( long item, long column ) const;
165     virtual int             OnListGetItemImage( long item ) const;
166 
167     void                    OnColClick(wxListEvent& event);
168 
169     virtual int             GetDocCount();
170     virtual wxString        OnDocGetItemImage( long item ) const;
171     virtual wxString        OnDocGetItemAttr( long item ) const;
172 
173     virtual int             AddCacheElement();
174     virtual int             EmptyCache();
175     virtual int             GetCacheCount();
176     virtual int             RemoveCacheElement();
177     virtual int             SynchronizeCache();
178     virtual bool            SynchronizeCacheItem(wxInt32 iRowIndex, wxInt32 iColumnIndex);
179     void                    sortData();
180 
181     virtual void            EmptyTasks();
182 
183     virtual void            PreUpdateSelection();
184     virtual void            UpdateSelection();
185     virtual void            PostUpdateSelection();
186 
187     virtual void            UpdateWebsiteSelection(long lControlGroup, PROJECT* project);
188 
189 
190     bool                    _IsSelectionManagementNeeded();
191     virtual bool            IsSelectionManagementNeeded();
192 
193     bool                    _EnsureLastItemVisible();
194     virtual bool            EnsureLastItemVisible();
195 
196     static  void            append_to_status(wxString& existing, const wxString& additional);
197     static  wxString        HtmlEntityEncode(wxString strRaw);
198     static  wxString        HtmlEntityDecode(wxString strRaw);
199 
200     bool                    m_bProcessingTaskRenderEvent;
201     bool                    m_bProcessingListRenderEvent;
202 
203     bool                    m_bForceUpdateSelection;
204     bool                    m_bIgnoreUIEvents;
205     bool                    m_bNeedSort;
206 
207     int                     m_iPreviousSelectionCount;
208     long                    m_lPreviousFirstSelection;
209     int                     m_iProgressColumn;
210 
211     wxImageList *           m_SortArrows;
212     ListSortCompareFunc     m_funcSortCompare;
213     wxArrayInt              m_iSortedIndexes;
214 
215     CBOINCTaskCtrl*         m_pTaskPane;
216     CBOINCListCtrl*         m_pListPane;
217 };
218 
219 #endif
220