1 /*
2 ��边的树控件
3 ��个控件有四种模式
4 0、什么也没选择,控件不需要显示任何东西
5 1、在左边的树控件选择了正在下载的任务时,列表有 图表,线程1,线程2...
6 2、在左边的树控件选择了暂停完成的任务是,列表显示文件的基本信息,有详细信息,链接等。
7 3、在左边的树控件选择了已完成的任务时,列表显示文件的基本信息,有详细信息,链接等。
8
9 ��数SwitchMode()用于切换这三种模式
10
11 ��个控件的parent是第二个垂直分割控件,当这边有特定的选择时,右边需要做相应的切换。
12 ��过调用parent提供的接口来通知parent切换显示界面。
13
14 ��行中的任务这么来设置控制树
15
16 ��息-\ (0)
17 |
18 |
19 信息提取 (-1)
20 |
21 |
22 文件管理 (-2)
23 |
24 |
25 图表进度 (-3)
26 |
27 |
28 线程1 (1)
29 |
30 |
31 ....
32 */
33 #include "righttree.h"
34 #include "rightdownsplitter.h"
35 #include "righttreeitemdata.h"
36 #include "mgapp.h"
37 #include "./icons/info.xpm"
38 #include "./icons/ant.xpm"
39 #include "./icons/diag.xpm"
40 #include "./icons/driver.xpm"
41 #include "./newicons/16/search.xpm"
42 #include "./newicons/16/detail.xpm"
43 #include "./icons/log.xpm"
44 #include <wx/imaglist.h>
45 #include <iostream>
46
47 using namespace std;
48
BEGIN_EVENT_TABLE(CRightTree,wxTreeCtrl)49 BEGIN_EVENT_TABLE( CRightTree, wxTreeCtrl )
50 EVT_TREE_SEL_CHANGED( -1, CRightTree::OnSelectChanged )
51 EVT_ERASE_BACKGROUND( CRightTree::OnErase )
52 END_EVENT_TABLE()
53
54 #define _MGSTR(s) wxGetApp().GetWxStr(s)
55
56 CRightTree::CRightTree( wxWindow* parent )
57 : wxTreeCtrl( parent, -1, wxDefaultPosition, wxDefaultSize , wxTR_DEFAULT_STYLE | wxFULL_REPAINT_ON_RESIZE )
58 {
59 wxImageList * imlist = new wxImageList( 16, 16, true, 7 );
60 imlist->Add( wxIcon( info_xpm ) );
61 imlist->Add( wxIcon( diag_xpm ) );
62 imlist->Add( wxIcon( ant_xpm ) );
63 imlist->Add( wxIcon( driver_xpm ) );
64 imlist->Add( wxIcon( search_xpm ) );
65 imlist->Add( wxIcon( log_xpm ) );
66 imlist->Add( wxIcon( detail_xpm ) );
67 AssignImageList( imlist );
68
69 }
70
71
OnSelectChanged(wxTreeEvent & event)72 void CRightTree::OnSelectChanged( wxTreeEvent& event )
73 {
74
75 wxTreeItemId id = event.GetItem();
76 CRightTreeItemData *pdata = ( CRightTreeItemData * ) GetItemData( id );
77 if( pdata == NULL ) return;
78 m_nLastSelectID = pdata->GetData();
79 ( ( CRightDownSplitter* ) GetParent() ) ->OnRightTreeSelectItem( pdata->GetData() );
80
81 //event.Skip();
82 }
83
84
DynamicLang()85 void CRightTree::DynamicLang()
86 {
87
88 wxTreeItemId child;
89 wxTreeItemIdValue cookie;
90 wxTreeItemId rid = GetRootItem();
91
92 if ( !rid.IsOk() )
93 return ;
94
95 SetItemText( rid, _MGSTR( _S_INFORMATION ) );
96
97 child = GetFirstChild( rid, cookie );
98
99 do
100 {
101
102 if ( !child.IsOk() )
103 break;
104
105 CRightTreeItemData* pdata = ( CRightTreeItemData* ) GetItemData( child );
106
107 switch ( pdata->GetData() )
108 {
109
110 case - 1:
111 SetItemText( child, _MGSTR( _S_PIONEER ) );
112 break;
113
114 case - 2:
115 SetItemText( child, _MGSTR( _S_FILEINFO ) );
116 break;
117
118 case - 3:
119 SetItemText( child, _MGSTR( _S_PROGRESS ) );
120 break;
121
122 case 1:
123
124 case 2:
125
126 case 3:
127
128 case 4:
129
130 case 5:
131
132 case 6:
133
134 case 7:
135
136 case 8:
137
138 case 9:
139
140 case 10:
141 {
142 wxString tx;
143 tx.Printf( _MGSTR( _S_THREAD ), pdata->GetData() );
144 SetItemText( child, tx );
145 }
146
147 break;
148
149 case 20:
150 SetItemText( child, _MGSTR( _S_DETAIL ) );
151 break;
152
153 case 21:
154 SetItemText( child, _MGSTR( _S_LOG ) );
155 break;
156
157 default:
158 break;
159 }
160
161 child = GetNextChild( rid, cookie );
162 }
163 while ( 1 );
164
165 }
166
ShowTask(_TaskAttr * task)167 void CRightTree::ShowTask( _TaskAttr* task )
168 {
169 DeleteAllItems();
170
171 if ( task == NULL )
172 {
173 wxTreeItemId rid;
174 rid = AddRoot( _MGSTR( _S_INFORMATION ),
175 0, //img
176 -1, //sel img = img
177 new CRightTreeItemData( 0 ) );
178
179 m_nLastSelectID = 0;
180 SelectItem( rid );
181 return ;
182 }
183
184 switch ( task->nStatus )
185 {
186
187 case _STATUS_RUNNING:
188 {
189
190 wxTreeItemId rid, old, tmp;
191 bool oldfind = false;
192
193 rid = AddRoot( _MGSTR( _S_INFORMATION ),
194 0,
195 -1,
196 new CRightTreeItemData( 0 ) );
197
198 if ( m_nLastSelectID == 0 )
199 {
200 old = rid;
201 oldfind = true;
202 }
203
204 tmp = AppendItem( rid,
205 _MGSTR( _S_PIONEER ),
206 4,
207 -1,
208 new CRightTreeItemData( -1 ) );
209
210 if ( m_nLastSelectID == -1 )
211 {
212 old = tmp;
213 oldfind = true;
214 }
215
216 tmp = AppendItem( rid,
217 _MGSTR( _S_FILEINFO ),
218 3,
219 -1,
220 new CRightTreeItemData( -2 ) );
221
222 if ( m_nLastSelectID == -2 )
223 {
224 old = tmp;
225 oldfind = true;
226 }
227
228 tmp = AppendItem( rid,
229 _MGSTR( _S_PROGRESS ),
230 1,
231 -1,
232 new CRightTreeItemData( -3 ) );
233
234 if ( m_nLastSelectID == -3 )
235 {
236 old = tmp;
237 oldfind = true;
238 }
239
240
241 for ( int i = 0; i < task->nThread; i++ )
242 {
243 wxString tx;
244 tx.Printf( _MGSTR( _S_THREAD ), i + 1 );
245 tmp = AppendItem( rid, tx, 2, -1,
246 new CRightTreeItemData( i + 1 ) );
247
248 if ( m_nLastSelectID == i + 1 )
249 {
250 old = tmp;
251 oldfind = true;
252 }
253 }
254
255
256 Expand( rid );
257
258
259 if ( oldfind )
260 {
261 SelectItem( old );
262 }
263 else
264 {
265
266 SelectItem( rid );
267 ( ( CRightDownSplitter* ) GetParent() ) ->OnRightTreeSelectItem( 0 );
268 }
269 }
270
271 break;
272
273 case _STATUS_PAUSE:
274
275 case _STATUS_WRONG:
276 //case _STATUS_FINISH:
277
278 case _STATUS_FINISH_SOFT:
279
280 case _STATUS_FINISH_PACK:
281
282 case _STATUS_FINISH_MUSIC:
283
284 case _STATUS_FINISH_ISO:
285
286 case _STATUS_FINISH_MOVIE:
287
288 case _STATUS_FINISH_PUBLISH:
289
290 case _STATUS_FINISH_PICTURE:
291
292 case _STATUS_FINISH_UNKNOW:
293
294 case _STATUS_DELETE:
295
296 case _STATUS_WAITING:
297 {
298 wxTreeItemId rid, old, tmp;
299 bool oldfind = false;
300 rid = AddRoot( _MGSTR( _S_INFORMATION ),
301 0,
302 -1,
303 new CRightTreeItemData( 0 ) );
304
305 if ( m_nLastSelectID == 0 )
306 {
307 old = rid;
308 oldfind = true;
309 }
310
311 tmp = AppendItem( rid, _MGSTR( _S_DETAIL ),
312 6,
313 -1,
314 new CRightTreeItemData( 20 ) );
315
316 if ( m_nLastSelectID == 20 )
317 {
318 old = tmp;
319 oldfind = true;
320 }
321
322 tmp = AppendItem( rid, _MGSTR( _S_LOG ),
323 5,
324 -1,
325 new CRightTreeItemData( 21 ) );
326
327 if ( m_nLastSelectID == 21 )
328 {
329 old = tmp;
330 oldfind = true;
331 }
332
333 Expand( rid );
334
335
336 if ( oldfind )
337 {
338 SelectItem( old );
339 }
340 else
341 {
342 SelectItem( rid );
343 ( ( CRightDownSplitter* ) GetParent() ) ->OnRightTreeSelectItem( 0 );
344 }
345 }
346
347 break;
348
349 default:
350 break;
351 }
352 }
353
OnErase(wxEraseEvent & event)354 void CRightTree::OnErase( wxEraseEvent& event )
355 {
356 event.Skip();
357 }
358
359