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