0
|
1 // Filename: mainframe.cpp
|
1
|
2 // Last Change: 2015-09-13 Sun 14:43:27.
|
0
|
3 //
|
|
4 #include <wx/filedlg.h>
|
|
5 #include <wx/textfile.h>
|
|
6 #include <wx/clipbrd.h>
|
|
7 #include <wx/utils.h>
|
|
8 #include <wx/msgdlg.h>
|
1
|
9 #include "wx/numdlg.h"
|
0
|
10
|
|
11 #include "mainframe.h"
|
|
12 #include "adddialog.h"
|
|
13
|
|
14 // resources
|
|
15 #if !defined(__WXMSW__) && !defined(__WXPM__)
|
|
16 #include "sample.xpm"
|
|
17 #endif
|
|
18
|
1
|
19 #define COL_NO 0
|
|
20 #define COL_TEXT 1
|
|
21 #define COL_OW 2
|
|
22 #define COL_MLT 3
|
|
23 #define COL_MAL 4
|
|
24 #define COL_DESC 5
|
|
25 #define COL_ID 6
|
|
26
|
0
|
27 MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style )
|
1
|
28 : wxFrame( parent, id, title, pos, size, style ),
|
|
29 m_timer( this, ID_TIMER ),
|
|
30 m_counter( 0 ),
|
|
31 m_period( 5 ),
|
|
32 m_bottom( true )
|
0
|
33 {
|
1
|
34 this->SetSizeHints( wxSize( 500, 450 ), wxDefaultSize );
|
0
|
35 this->SetBackgroundColour( wxColour( wxT("WHEAT") ) );
|
|
36 SetIcon( wxICON( sample ) );
|
|
37
|
|
38 // menu bar
|
|
39 m_menubar = new wxMenuBar( 0 );
|
|
40 m_menuFile = new wxMenu();
|
1
|
41 wxMenuItem* m_menuItemAppdir = new wxMenuItem( m_menuFile, ID_MNAPPDIR, wxString( wxT("Open App Forlder") ), wxEmptyString, wxITEM_NORMAL );
|
|
42 m_menuFile->Append( m_menuItemAppdir );
|
|
43
|
|
44 wxMenuItem* m_menuItemInterval = new wxMenuItem( m_menuFile, ID_MNINTERVAL, wxString( wxT("Set Interval") ), wxEmptyString, wxITEM_NORMAL );
|
|
45 m_menuFile->Append( m_menuItemInterval );
|
|
46
|
0
|
47 wxMenuItem* m_menuItemAbout = new wxMenuItem( m_menuFile, ID_MNABOUT, wxString( wxT("About") ), wxEmptyString, wxITEM_NORMAL );
|
|
48 m_menuFile->Append( m_menuItemAbout );
|
|
49
|
|
50 wxMenuItem* m_menuItemExit = new wxMenuItem( m_menuFile, ID_MNEXIT, wxString( wxT("Exit") ), wxEmptyString, wxITEM_NORMAL );
|
|
51 m_menuFile->Append( m_menuItemExit );
|
|
52
|
|
53 m_menubar->Append( m_menuFile, wxT("File") );
|
|
54
|
|
55 m_menuPlugin = new wxMenu();
|
|
56 wxMenuItem* m_menuItemLoadPgin = new wxMenuItem( m_menuPlugin, ID_MNLDPGIN, wxString( wxT("Load") ), wxEmptyString, wxITEM_NORMAL );
|
|
57 m_menuPlugin->Append( m_menuItemLoadPgin );
|
|
58
|
|
59 wxMenuItem* m_menuItemSavePgin = new wxMenuItem( m_menuPlugin, ID_MNSVPGIN, wxString( wxT("Save as") ), wxEmptyString, wxITEM_NORMAL );
|
|
60 m_menuPlugin->Append( m_menuItemSavePgin );
|
|
61
|
|
62 m_menubar->Append( m_menuPlugin, wxT("Plugin") );
|
|
63
|
|
64 this->SetMenuBar( m_menubar );
|
|
65
|
|
66 // controls
|
|
67 wxBoxSizer* bSizerTop = new wxBoxSizer( wxVERTICAL );
|
|
68
|
|
69 //
|
|
70 wxBoxSizer* bSizerShow = new wxBoxSizer( wxHORIZONTAL );
|
|
71
|
|
72 m_textCtrlShow = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY );
|
|
73 bSizerShow->Add( m_textCtrlShow, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
74
|
1
|
75 m_textCtrlRemain = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 40, -1 ), wxTE_READONLY|wxTE_CENTER );
|
|
76 bSizerShow->Add( m_textCtrlRemain, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5 );
|
|
77
|
0
|
78 m_toggleBtn = new wxToggleButton( this, ID_TGL, wxT("ON"), wxDefaultPosition, wxSize( 60, -1 ), 0 );
|
|
79 bSizerShow->Add( m_toggleBtn, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
80
|
|
81 bSizerTop->Add( bSizerShow, 0, wxEXPAND, 5 );
|
|
82
|
|
83 //
|
1
|
84 wxBoxSizer* bSizerMain = new wxBoxSizer( wxHORIZONTAL );
|
0
|
85
|
1
|
86 // list
|
|
87 wxBoxSizer* bSizerList = new wxBoxSizer( wxVERTICAL );
|
|
88
|
|
89 m_staticTextCycle = new wxStaticText( this, wxID_ANY, wxT("Cycle list"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
90 bSizerList->Add( m_staticTextCycle, 0, wxTOP|wxLEFT|wxALIGN_BOTTOM, 5 );
|
|
91
|
|
92 m_lisViewCycle = new wxListView( this, ID_LISTVIEW, wxDefaultPosition, wxSize( -1, 100 ), wxLC_REPORT|wxLC_SINGLE_SEL );
|
0
|
93 wxListItem itemCol;
|
1
|
94 itemCol.SetText( wxT("No") ); m_lisViewCycle->InsertColumn( COL_NO, itemCol ); m_lisViewCycle->SetColumnWidth( COL_NO, 20 );
|
|
95 itemCol.SetText( wxT("text") ); m_lisViewCycle->InsertColumn( COL_TEXT, itemCol ); m_lisViewCycle->SetColumnWidth( COL_TEXT, 80 );
|
|
96 itemCol.SetText( wxT("o/w") ); m_lisViewCycle->InsertColumn( COL_OW, itemCol ); m_lisViewCycle->SetColumnWidth( COL_OW, 40 );
|
|
97 itemCol.SetText( wxT("live") ); m_lisViewCycle->InsertColumn( COL_MLT, itemCol ); m_lisViewCycle->SetColumnWidth( COL_MLT, 50 );
|
|
98 itemCol.SetText( wxT("active") ); m_lisViewCycle->InsertColumn( COL_MAL, itemCol ); m_lisViewCycle->SetColumnWidth( COL_MAL, 50 );
|
|
99 itemCol.SetText( wxT("desc") ); m_lisViewCycle->InsertColumn( COL_DESC, itemCol ); m_lisViewCycle->SetColumnWidth( COL_DESC, 80 );
|
|
100 itemCol.SetText( wxT("id") ); m_lisViewCycle->InsertColumn( COL_ID, itemCol ); m_lisViewCycle->SetColumnWidth( COL_ID, 30 );
|
|
101 //m_lisViewCycle->EnableAlternateRowColours( true );
|
|
102 bSizerList->Add( m_lisViewCycle, 1, wxALL|wxEXPAND, 5 );
|
0
|
103
|
1
|
104 m_staticTextHist = new wxStaticText( this, wxID_ANY, wxT("User input history"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
105 bSizerList->Add( m_staticTextHist, 0, wxTOP|wxLEFT|wxALIGN_BOTTOM, 5 );
|
|
106
|
|
107 m_listBoxHist = new wxListBox( this, ID_LISTBOX, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE );
|
|
108 bSizerList->Add( m_listBoxHist, 1, wxALL|wxEXPAND, 5 );
|
|
109
|
|
110 bSizerMain->Add( bSizerList, 1, wxEXPAND, 5 );
|
|
111
|
|
112 // button
|
0
|
113 wxBoxSizer* bSizerBtn = new wxBoxSizer( wxVERTICAL );
|
|
114
|
1
|
115 bSizerBtn->Add( 0, 20, 0, 0, 5 );
|
|
116
|
0
|
117 m_buttonUp = new wxButton( this, ID_BTNUP, wxT("↑"), wxDefaultPosition, wxSize( 40, -1 ), 0 );
|
|
118 bSizerBtn->Add( m_buttonUp, 0, wxALL, 5 );
|
|
119
|
|
120 m_buttonDown = new wxButton( this, ID_BTNDOWN, wxT("↓"), wxDefaultPosition, wxSize( 40, -1 ), 0 );
|
|
121 bSizerBtn->Add( m_buttonDown, 0, wxALL, 5 );
|
|
122
|
|
123 m_buttonDel = new wxButton( this, ID_BTNDEL, wxT("-"), wxDefaultPosition, wxSize( 40, -1 ), 0 );
|
|
124 bSizerBtn->Add( m_buttonDel, 0, wxALL, 5 );
|
|
125
|
|
126 m_buttonAdd = new wxButton( this, ID_BTNADD, wxT("+"), wxDefaultPosition, wxSize( 40, -1 ), 0 );
|
|
127 bSizerBtn->Add( m_buttonAdd, 0, wxALL, 5 );
|
|
128
|
|
129 bSizerBtn->Add( 0, 0, 1, wxEXPAND, 5 );
|
|
130
|
|
131 m_buttonExit = new wxButton( this, ID_EXIT, wxT("Exit"), wxDefaultPosition, wxSize( 60, -1 ), 0 );
|
|
132 bSizerBtn->Add( m_buttonExit, 0, wxALL, 5 );
|
|
133
|
1
|
134 bSizerMain->Add( bSizerBtn, 0, wxEXPAND, 5 );
|
|
135
|
|
136 bSizerTop->Add( bSizerMain, 1, wxEXPAND, 5 );
|
0
|
137
|
|
138 this->SetSizer( bSizerTop );
|
|
139 this->Layout();
|
|
140
|
|
141 this->Centre( wxBOTH );
|
|
142 }
|
|
143
|
|
144 MainFrame::~MainFrame()
|
|
145 {
|
|
146 }
|
|
147
|
|
148 // Event Table
|
|
149 BEGIN_EVENT_TABLE( MainFrame, wxFrame )
|
1
|
150 EVT_MENU( ID_MNAPPDIR, MainFrame::OnMNAppdir )
|
|
151 EVT_MENU( ID_MNINTERVAL, MainFrame::OnMNInterval )
|
|
152 EVT_MENU( ID_MNABOUT, MainFrame::OnMNAbout )
|
|
153 EVT_MENU( ID_MNEXIT, MainFrame::OnMNExit )
|
|
154 EVT_MENU( ID_MNLDPGIN, MainFrame::OnMNLoad )
|
|
155 EVT_MENU( ID_MNSVPGIN, MainFrame::OnMNSaveAs )
|
|
156 EVT_LIST_ITEM_ACTIVATED( ID_LISTVIEW, MainFrame::OnLViewDClickItem )
|
|
157 EVT_LIST_ITEM_SELECTED( ID_LISTVIEW, MainFrame::OnLViewSelectItem )
|
|
158 EVT_LISTBOX_DCLICK( ID_LISTBOX, MainFrame::OnLBoxDClickItem )
|
0
|
159 EVT_TIMER( ID_TIMER, MainFrame::OnTimer )
|
1
|
160 EVT_BUTTON( ID_BTNUP, MainFrame::OnBtnUp )
|
0
|
161 EVT_BUTTON( ID_BTNDOWN, MainFrame::OnBtnDown )
|
1
|
162 EVT_BUTTON( ID_BTNDEL, MainFrame::OnBtnDel )
|
|
163 EVT_BUTTON( ID_BTNADD, MainFrame::OnBtnAdd )
|
0
|
164 EVT_BUTTON( ID_EXIT, MainFrame::OnBtnExit )
|
1
|
165 EVT_TOGGLEBUTTON( ID_TGL, MainFrame::OnToggle )
|
0
|
166 /*
|
|
167 EVT_IDLE( MainFrame::OnIdle )
|
|
168 EVT_CLOSE( MainFrame::OnClose )
|
|
169 */
|
|
170 END_EVENT_TABLE()
|
|
171
|
|
172 /* Event Handlers & Functions */
|
|
173 // Event Handlers
|
1
|
174 void MainFrame::OnMNAppdir( wxCommandEvent& WXUNUSED(event) )
|
|
175 {
|
|
176 wxString app_dir = wxGetCwd();
|
|
177 wxString execmd = wxT("explorer ") + app_dir;
|
|
178 wxExecute( execmd );
|
|
179 }
|
|
180
|
|
181 void MainFrame::OnMNInterval( wxCommandEvent& WXUNUSED(event) )
|
|
182 {
|
|
183 long t = wxGetNumberFromUser( wxT("text changed by user is preserved specified period."), wxT("Input 1-60[sec]."), wxT("Setting"), 5, 1, 60, this, wxDefaultPosition );
|
|
184 if ( t != -1 ) // canceled
|
|
185 m_period = (int)t;
|
|
186 }
|
|
187
|
0
|
188 void MainFrame::OnMNAbout( wxCommandEvent& WXUNUSED(event) )
|
|
189 {
|
|
190 wxInfoMessageBox( this );
|
|
191 }
|
|
192
|
|
193 void MainFrame::OnMNExit( wxCommandEvent& WXUNUSED(event) )
|
|
194 {
|
|
195 Close();
|
|
196 }
|
|
197
|
|
198 void MainFrame::OnMNLoad( wxCommandEvent& WXUNUSED(event) )
|
|
199 {
|
|
200 wxString plugin_dir = wxGetCwd() + wxFILE_SEP_PATH + wxT("plugin");
|
|
201 wxFileDialog fd( this, wxT("Select Plug-in file"), plugin_dir, wxEmptyString, wxT("Plug-in files (*.qbrd)|*.qbrd"), wxFD_OPEN|wxFD_FILE_MUST_EXIST );
|
|
202 if ( fd.ShowModal() == wxID_CANCEL ) return; // the user changed idea...
|
|
203
|
|
204 wxTextFile file;
|
|
205 file.Open( fd.GetPath() );
|
1
|
206 m_lisViewCycle->DeleteAllItems();
|
|
207 QH.clear();
|
0
|
208 for ( int i = 0, n = 0; i < file.GetLineCount(); i++ ) {
|
|
209 if ( file[i].StartsWith( wxT("#") ) )
|
|
210 continue;
|
|
211 wxArrayString s = wxSplit( file[i], ',', '\\' );
|
|
212
|
1
|
213 m_lisViewCycle->InsertItem( n, wxString::Format( wxT("%d"), n + 1 ) );
|
|
214 m_lisViewCycle->SetItem( n, COL_TEXT, s[0] );
|
|
215 m_lisViewCycle->SetItem( n, COL_OW, s[1] );
|
|
216 m_lisViewCycle->SetItem( n, COL_MLT, s[2] );
|
|
217 m_lisViewCycle->SetItem( n, COL_MAL, s[3] );
|
|
218 m_lisViewCycle->SetItem( n, COL_DESC, s[4] );
|
|
219 m_lisViewCycle->SetItem( n, COL_ID, s[5] );
|
0
|
220 n++;
|
|
221 }
|
|
222 file.Close();
|
|
223
|
|
224 m_current = 0;
|
1
|
225 m_lisViewCycle->Select( m_current, true );
|
0
|
226 }
|
|
227
|
|
228 void MainFrame::OnMNSaveAs( wxCommandEvent& WXUNUSED(event) )
|
|
229 {
|
|
230 wxString plugin_dir = wxGetCwd() + wxFILE_SEP_PATH + wxT("plugin");
|
|
231 wxFileDialog fd( this, wxT("Save Plug-in file"), plugin_dir , wxEmptyString, wxT("Plug-in files (*.qbrd)|*.qbrd"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT );
|
|
232 if ( fd.ShowModal() == wxID_CANCEL ) return; // the user changed idea...
|
|
233
|
|
234 wxTextFile file( fd.GetPath() );
|
|
235 if ( file.Exists() ) {
|
|
236 file.Open();
|
|
237 file.Clear();
|
|
238 }
|
|
239 else {
|
|
240 file.Create();
|
|
241 }
|
1
|
242 for ( int r = 0; r < m_lisViewCycle->GetItemCount(); r++ ) {
|
0
|
243 wxArrayString s;
|
1
|
244 for ( int c = 0; c < m_lisViewCycle->GetColumnCount(); c++ ) {
|
|
245 s.Add( m_lisViewCycle->GetItemText( r, c ) );
|
0
|
246 }
|
|
247 file.AddLine( wxJoin( s, ',', '\\' ) );
|
|
248 }
|
|
249 file.Write();
|
|
250 file.Close();
|
|
251 }
|
|
252
|
1
|
253 void MainFrame::OnLViewDClickItem( wxListEvent& event )
|
0
|
254 {
|
1
|
255 wxString s = event.GetText();
|
0
|
256 }
|
|
257
|
1
|
258 void MainFrame::OnLViewSelectItem( wxListEvent& event )
|
0
|
259 {
|
|
260 long i = event.GetIndex();
|
1
|
261 m_current = (int)i;
|
0
|
262 }
|
|
263
|
1
|
264 void MainFrame::OnLBoxDClickItem( wxCommandEvent& event )
|
|
265 {
|
|
266 wxString s = event.GetString();
|
|
267 m_counter = m_period;
|
|
268 if ( wxTheClipboard->Open() ) {
|
|
269 wxTheClipboard->SetData( new wxTextDataObject( s ) );
|
|
270 wxTheClipboard->Close();
|
|
271 m_listBoxHist->Delete( event.GetSelection() );
|
|
272 m_listBoxHist->Insert( s, 0 );
|
|
273 m_textCtrlShow->SetValue( s );
|
|
274 m_textCtrlRemain->SetValue( wxString::Format( wxT("%d"), m_period ) );
|
|
275 }
|
|
276 m_listBoxHist->Deselect( event.GetInt() );
|
|
277 m_listBoxHist->SetSelection( 0 );
|
|
278 }
|
|
279
|
|
280 // [↑]
|
0
|
281 void MainFrame::OnBtnUp( wxCommandEvent& WXUNUSED(event) )
|
|
282 {
|
1
|
283 long item = m_lisViewCycle->GetFirstSelected();
|
0
|
284 if ( item == -1 || item == 0 ) return;
|
|
285 SwapListItem( item, item - 1 );
|
|
286 ReNumberList();
|
|
287 }
|
|
288
|
1
|
289 // [↓]
|
0
|
290 void MainFrame::OnBtnDown( wxCommandEvent& WXUNUSED(event) )
|
|
291 {
|
1
|
292 long item = m_lisViewCycle->GetFirstSelected();
|
|
293 if ( item == -1 || item == m_lisViewCycle->GetItemCount() - 1 ) return;
|
0
|
294 SwapListItem( item, item + 1 );
|
|
295 ReNumberList();
|
|
296 }
|
|
297
|
1
|
298 // [−]
|
0
|
299 void MainFrame::OnBtnDel( wxCommandEvent& WXUNUSED(event) )
|
|
300 {
|
1
|
301 long item = m_lisViewCycle->GetFirstSelected();
|
|
302 if ( item == -1 ) return;
|
|
303
|
|
304 int id = ToInt( m_lisViewCycle->GetItemText( item, COL_ID ) );
|
|
305 QH.erase( id );
|
|
306
|
|
307 m_lisViewCycle->DeleteItem( item );
|
|
308 ReNumberList();
|
0
|
309 }
|
|
310
|
1
|
311 // [+]
|
0
|
312 void MainFrame::OnBtnAdd( wxCommandEvent& WXUNUSED(event) )
|
|
313 {
|
1
|
314 int r;
|
|
315 long item = m_lisViewCycle->GetFirstSelected();
|
|
316 if ( item == -1 ) r = 0;
|
|
317 else r = item;
|
|
318
|
|
319 AddDialog add_dlg( this, wxID_ANY, wxT("Add Item"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE );
|
|
320 if ( add_dlg.ShowModal() == wxID_OK ) {
|
|
321 int id = CreateID();
|
|
322 QlipData* q = new QlipData;
|
|
323 q->id = id;
|
|
324 q->text = add_dlg.GetText();
|
|
325 q->overwrite = add_dlg.GetOverwrite();
|
|
326 q->max_active_time = add_dlg.GetMaxActiveTime();
|
|
327 q->max_live_time = q->overwrite ? add_dlg.GetMaxLiveTime() : 0;
|
|
328 q->desc = add_dlg.GetDesc();
|
|
329 q->active_time = 0;
|
|
330 q->live_time = 0;
|
|
331 QH[id] = q;
|
|
332
|
|
333 m_lisViewCycle->InsertItem( r, wxEmptyString );
|
|
334 m_lisViewCycle->SetItem( r, COL_TEXT, q->text );
|
|
335 m_lisViewCycle->SetItem( r, COL_OW, wxString::Format( wxT("%s"), q->overwrite ? wxT("true") : wxT("false") ) );
|
|
336 m_lisViewCycle->SetItem( r, COL_MAL, wxString::Format( wxT("-- / %d"), q->max_active_time ) );
|
|
337 m_lisViewCycle->SetItem( r, COL_MLT, wxString::Format( wxT("-- / %d"), q->max_live_time ) );
|
|
338 m_lisViewCycle->SetItem( r, COL_DESC, q->desc );
|
|
339 m_lisViewCycle->SetItem( r, COL_ID, wxString::Format( wxT("%d"), id ) );
|
|
340 if ( q->overwrite )
|
|
341 m_lisViewCycle->SetItemBackgroundColour( r, wxColour( wxT("MEDIUM GOLDENROD") ) );
|
|
342 else
|
|
343 m_lisViewCycle->SetItemBackgroundColour( r, wxColour( wxT("WHITE") ) );
|
0
|
344 }
|
1
|
345 ReNumberList();
|
0
|
346 }
|
|
347
|
|
348 void MainFrame::OnTimer( wxTimerEvent& WXUNUSED(event) )
|
|
349 {
|
1
|
350 wxString clipboard;
|
0
|
351 if ( wxTheClipboard->Open() ) {
|
1
|
352 //wxMessageBox( clipboard );
|
0
|
353 wxTextDataObject data;
|
|
354 wxTheClipboard->GetData( data );
|
1
|
355 clipboard = data.GetText();
|
|
356 wxTheClipboard->Close();
|
|
357
|
|
358 m_textCtrlShow->SetValue( clipboard );
|
|
359 m_textCtrlRemain->SetValue( wxT("∞") );
|
|
360 UpdateHistory( clipboard );
|
|
361 }
|
|
362 else {
|
|
363 return;
|
|
364 }
|
|
365
|
|
366 long list_num = m_lisViewCycle->GetItemCount();
|
|
367 if ( list_num == 0 ) return;
|
|
368
|
|
369 if ( m_lisViewCycle->GetSelectedItemCount() == 0 ) {
|
|
370 m_lisViewCycle->Select( 0, true );
|
|
371 m_current = 0;
|
|
372 }
|
|
373
|
|
374 AddStackTime();
|
|
375 UpdateView();
|
|
376 int r = GetEmptyStack();
|
|
377 if ( r != -1 && m_bottom ) {
|
|
378 m_timer.Stop();
|
|
379
|
|
380 int id = ToInt( m_lisViewCycle->GetItemText( r, COL_ID ) );
|
|
381 QH[id]->text = clipboard;
|
|
382 m_lisViewCycle->SetItem( r, COL_TEXT, clipboard );
|
|
383
|
|
384 wxSleep( 2 );
|
|
385 m_timer.Start( -1 );
|
|
386 m_current = 0;
|
|
387 m_lisViewCycle->Select( 0, true );
|
|
388 return;
|
|
389 }
|
|
390
|
|
391 // Main Cycle
|
|
392 if ( list_num == 1 ) {
|
|
393 if ( m_counter == m_period ) {
|
|
394 m_counter = 0;
|
|
395 if ( wxTheClipboard->Open() ) {
|
|
396 wxString s = m_lisViewCycle->GetItemText( 0, COL_TEXT );
|
|
397 wxTheClipboard->SetData( new wxTextDataObject( s ) );
|
|
398 wxTheClipboard->Close();
|
|
399 m_textCtrlShow->SetValue( s );
|
|
400 m_textCtrlRemain->SetValue( wxT("∞") );
|
|
401 }
|
|
402 }
|
|
403 else {
|
|
404 wxString t = wxString::Format( wxT("%d"), m_period - m_counter );
|
|
405 m_textCtrlShow->SetValue( clipboard );
|
|
406 m_textCtrlRemain->SetValue( t );
|
|
407 m_counter++;
|
0
|
408 }
|
|
409
|
1
|
410 m_lisViewCycle->Select( 0, true );
|
|
411 m_current = 0;
|
|
412 m_bottom = true;
|
|
413 }
|
|
414 else {
|
|
415 long item = m_lisViewCycle->GetFirstSelected();
|
|
416 m_current = (int)item;
|
|
417
|
|
418 int id = ToInt( m_lisViewCycle->GetItemText( item, COL_ID ) );
|
|
419 QlipData* q = QH[id];
|
|
420 if ( q->overwrite && !q->IsAlive() )
|
|
421 return;
|
0
|
422
|
1
|
423 if ( q->IsArrived() ) {
|
|
424 m_lisViewCycle->Select( m_current, false );
|
|
425 if ( ++m_current == list_num ) m_bottom = true;
|
|
426 else m_bottom = false;
|
|
427 m_current = m_current % list_num;
|
|
428 m_lisViewCycle->Select( m_current, true );
|
0
|
429
|
1
|
430 if ( wxTheClipboard->Open() ) {
|
|
431 int id = ToInt( m_lisViewCycle->GetItemText( m_current, COL_ID ) );
|
|
432 QlipData* qn = QH[id];
|
|
433 wxTheClipboard->SetData( new wxTextDataObject( qn->text ) );
|
|
434 wxTheClipboard->Close();
|
|
435 m_textCtrlShow->SetValue( qn->text );
|
|
436 m_textCtrlRemain->SetValue( wxString::Format( wxT("%d"), qn->max_active_time ) );
|
|
437 }
|
|
438 }
|
|
439 else {
|
|
440 int t = q->max_active_time - q->active_time;
|
|
441 m_textCtrlRemain->SetValue( wxString::Format( wxT("%d"), t ) );
|
|
442 }
|
0
|
443 }
|
|
444 }
|
|
445
|
|
446 void MainFrame::OnToggle( wxCommandEvent& WXUNUSED(event) )
|
|
447 {
|
|
448 if ( m_toggleBtn->GetValue() ) {
|
|
449 m_toggleBtn->SetLabel( wxT("OFF") );
|
|
450 EnableButtons( false );
|
1
|
451 m_timer.Start( 1000 );
|
0
|
452 }
|
|
453 else {
|
|
454 m_timer.Stop();
|
|
455 m_toggleBtn->SetLabel( wxT("ON") );
|
|
456 EnableButtons( true );
|
|
457 }
|
|
458 }
|
|
459
|
|
460 void MainFrame::OnBtnExit( wxCommandEvent& WXUNUSED(event) )
|
|
461 {
|
|
462 Close();
|
|
463 }
|
|
464
|
|
465 // Functions
|
|
466 void MainFrame::EnableButtons( bool enable )
|
|
467 {
|
|
468 if ( enable ) {
|
|
469 m_buttonUp->Enable( true );
|
|
470 m_buttonDown->Enable( true );
|
|
471 m_buttonDel->Enable( true );
|
|
472 m_buttonAdd->Enable( true );
|
|
473 }
|
|
474 else {
|
|
475 m_buttonUp->Enable( false );
|
|
476 m_buttonDown->Enable( false );
|
|
477 m_buttonDel->Enable( false );
|
|
478 m_buttonAdd->Enable( false );
|
|
479 }
|
|
480 }
|
|
481
|
|
482 void MainFrame::ReNumberList()
|
|
483 {
|
1
|
484 for ( int r = 0; r < m_lisViewCycle->GetItemCount(); r++ ) {
|
|
485 m_lisViewCycle->SetItem( r, COL_NO, wxString::Format( wxT("%d"), r + 1 ) );
|
|
486 wxString s = m_lisViewCycle->GetItemText( r, COL_OW );
|
|
487 if ( s.IsSameAs( wxT("true") ) )
|
|
488 m_lisViewCycle->SetItemBackgroundColour( r, wxColour( wxT("MEDIUM GOLDENROD") ) );
|
|
489 else
|
|
490 m_lisViewCycle->SetItemBackgroundColour( r, wxColour( wxT("WHITE") ) );
|
0
|
491 }
|
|
492 }
|
|
493
|
|
494 void MainFrame::SwapListItem( long item1, long item2 )
|
|
495 {
|
1
|
496 for ( int c = 0; c < m_lisViewCycle->GetColumnCount(); c++ ) {
|
|
497 wxString buf = m_lisViewCycle->GetItemText( item1, c );
|
|
498 m_lisViewCycle->SetItem( item1, c, m_lisViewCycle->GetItemText( item2, c ) );
|
|
499 m_lisViewCycle->SetItem( item2, c, buf );
|
0
|
500 }
|
1
|
501 m_lisViewCycle->Select( item1, false );
|
|
502 m_lisViewCycle->Select( item2, true );
|
|
503 }
|
|
504
|
|
505 int MainFrame::CreateID()
|
|
506 {
|
|
507 long max_id = 1;
|
|
508 if ( m_lisViewCycle->GetItemCount() == 0 )
|
|
509 return max_id;
|
|
510
|
|
511 wxArrayString id;
|
|
512 for ( int r = 0; r < m_lisViewCycle->GetItemCount(); r++ ) {
|
|
513 wxString buf = m_lisViewCycle->GetItemText( r, COL_ID );
|
|
514 id.Add( buf );
|
|
515 }
|
|
516 id.Sort();
|
|
517 wxString max = id.Last();
|
|
518 max.ToLong( &max_id, 10 );
|
|
519 return ++max_id;
|
|
520 }
|
|
521
|
|
522 void MainFrame::AddStackTime()
|
|
523 {
|
|
524 QlipDataHash::iterator it;
|
|
525 for ( it = QH.begin(); it != QH.end(); it++ ) {
|
|
526 int id = it->first;
|
|
527 QlipData* q = it->second;
|
|
528 if ( q->overwrite ) {
|
|
529 if ( ++q->live_time == q->max_live_time )
|
|
530 q->Kill();
|
|
531 }
|
|
532 QH[id] = q;
|
|
533 }
|
0
|
534 }
|
|
535
|
1
|
536 void MainFrame::UpdateView()
|
|
537 {
|
|
538 for ( int r = 0; r < m_lisViewCycle->GetItemCount(); r++ ) {
|
|
539 int id = ToInt( m_lisViewCycle->GetItemText( r, COL_ID ) );
|
|
540
|
|
541 m_lisViewCycle->SetItem( r, COL_TEXT, QH[id]->text );
|
|
542
|
|
543 wxString at = wxString::Format( wxT("%d / %d"), QH[id]->active_time, QH[id]->max_active_time );
|
|
544 m_lisViewCycle->SetItem( r, COL_MAL, at );
|
|
545
|
|
546 wxString lt = wxT("-- / --");
|
|
547 if ( QH[id]->overwrite )
|
|
548 lt = wxString::Format( wxT("%d / %d"), QH[id]->live_time, QH[id]->max_live_time );
|
|
549 m_lisViewCycle->SetItem( r, COL_MLT, lt );
|
|
550 }
|
|
551 }
|
|
552
|
|
553 void MainFrame::UpdateHistory( wxString s )
|
|
554 {
|
|
555 if ( s.IsEmpty() ) return;
|
|
556 int row = m_listBoxHist->FindString( s, true );
|
|
557 if ( row != wxNOT_FOUND )
|
|
558 m_listBoxHist->Delete( row );
|
|
559 m_listBoxHist->Insert( s, 0 );
|
|
560 }
|
|
561
|
|
562 int MainFrame::GetEmptyStack()
|
|
563 {
|
|
564 int row = -1;
|
|
565 for ( int r = 0; r < m_lisViewCycle->GetItemCount(); r++ ) {
|
|
566 int id = ToInt( m_lisViewCycle->GetItemText( r, COL_ID ) );
|
|
567 if ( QH[(int)id]->text.IsEmpty() ) row = r;
|
|
568 }
|
|
569 return row;
|
|
570 }
|
|
571
|
|
572 int MainFrame::ToInt( wxString s )
|
|
573 {
|
|
574 long n = 0;
|
|
575 s.ToLong( &n, 10 );
|
|
576 return n;
|
|
577 }
|
|
578
|