comparison src/mainframe.cpp @ 1:e4aa0e7a07ad

Second release.
author pyon@macmini
date Sun, 13 Sep 2015 14:56:42 +0900
parents cb3403ca39b1
children fd4361d2cbbd
comparison
equal deleted inserted replaced
0:cb3403ca39b1 1:e4aa0e7a07ad
1 // Filename: mainframe.cpp 1 // Filename: mainframe.cpp
2 // Last Change: 2015-08-30 Sun 21:49:16. 2 // Last Change: 2015-09-13 Sun 14:43:27.
3 // 3 //
4 #include <wx/filedlg.h> 4 #include <wx/filedlg.h>
5 #include <wx/textfile.h> 5 #include <wx/textfile.h>
6 #include <wx/clipbrd.h> 6 #include <wx/clipbrd.h>
7 #include <wx/utils.h> 7 #include <wx/utils.h>
8 #include <wx/msgdlg.h> 8 #include <wx/msgdlg.h>
9 #include "wx/numdlg.h"
9 10
10 #include "mainframe.h" 11 #include "mainframe.h"
11 #include "adddialog.h" 12 #include "adddialog.h"
12 13
13 // resources 14 // resources
14 #if !defined(__WXMSW__) && !defined(__WXPM__) 15 #if !defined(__WXMSW__) && !defined(__WXPM__)
15 #include "sample.xpm" 16 #include "sample.xpm"
16 #endif 17 #endif
17 18
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
18 MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) 27 MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style )
19 : wxFrame( parent, id, title, pos, size, style ), m_timer( this, ID_TIMER ) 28 : wxFrame( parent, id, title, pos, size, style ),
20 { 29 m_timer( this, ID_TIMER ),
21 this->SetSizeHints( wxDefaultSize, wxDefaultSize ); 30 m_counter( 0 ),
31 m_period( 5 ),
32 m_bottom( true )
33 {
34 this->SetSizeHints( wxSize( 500, 450 ), wxDefaultSize );
22 this->SetBackgroundColour( wxColour( wxT("WHEAT") ) ); 35 this->SetBackgroundColour( wxColour( wxT("WHEAT") ) );
23 SetIcon( wxICON( sample ) ); 36 SetIcon( wxICON( sample ) );
24 37
25 // menu bar 38 // menu bar
26 m_menubar = new wxMenuBar( 0 ); 39 m_menubar = new wxMenuBar( 0 );
27 m_menuFile = new wxMenu(); 40 m_menuFile = new wxMenu();
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
28 wxMenuItem* m_menuItemAbout = new wxMenuItem( m_menuFile, ID_MNABOUT, wxString( wxT("About") ), wxEmptyString, wxITEM_NORMAL ); 47 wxMenuItem* m_menuItemAbout = new wxMenuItem( m_menuFile, ID_MNABOUT, wxString( wxT("About") ), wxEmptyString, wxITEM_NORMAL );
29 m_menuFile->Append( m_menuItemAbout ); 48 m_menuFile->Append( m_menuItemAbout );
30 49
31 wxMenuItem* m_menuItemExit = new wxMenuItem( m_menuFile, ID_MNEXIT, wxString( wxT("Exit") ), wxEmptyString, wxITEM_NORMAL ); 50 wxMenuItem* m_menuItemExit = new wxMenuItem( m_menuFile, ID_MNEXIT, wxString( wxT("Exit") ), wxEmptyString, wxITEM_NORMAL );
32 m_menuFile->Append( m_menuItemExit ); 51 m_menuFile->Append( m_menuItemExit );
51 wxBoxSizer* bSizerShow = new wxBoxSizer( wxHORIZONTAL ); 70 wxBoxSizer* bSizerShow = new wxBoxSizer( wxHORIZONTAL );
52 71
53 m_textCtrlShow = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY ); 72 m_textCtrlShow = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY );
54 bSizerShow->Add( m_textCtrlShow, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); 73 bSizerShow->Add( m_textCtrlShow, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
55 74
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
56 m_toggleBtn = new wxToggleButton( this, ID_TGL, wxT("ON"), wxDefaultPosition, wxSize( 60, -1 ), 0 ); 78 m_toggleBtn = new wxToggleButton( this, ID_TGL, wxT("ON"), wxDefaultPosition, wxSize( 60, -1 ), 0 );
57 bSizerShow->Add( m_toggleBtn, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); 79 bSizerShow->Add( m_toggleBtn, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
58 80
59 bSizerTop->Add( bSizerShow, 0, wxEXPAND, 5 ); 81 bSizerTop->Add( bSizerShow, 0, wxEXPAND, 5 );
60 82
61 // 83 //
62 wxBoxSizer* bSizerList = new wxBoxSizer( wxHORIZONTAL ); 84 wxBoxSizer* bSizerMain = new wxBoxSizer( wxHORIZONTAL );
63 85
64 m_listView = new wxListView( this, ID_LIST, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL ); 86 // list
65 bSizerList->Add( m_listView, 1, wxALL|wxEXPAND, 5 ); 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 );
66 wxListItem itemCol; 93 wxListItem itemCol;
67 itemCol.SetText( wxT("No") ); 94 itemCol.SetText( wxT("No") ); m_lisViewCycle->InsertColumn( COL_NO, itemCol ); m_lisViewCycle->SetColumnWidth( COL_NO, 20 );
68 m_listView->InsertColumn( 0, itemCol ); 95 itemCol.SetText( wxT("text") ); m_lisViewCycle->InsertColumn( COL_TEXT, itemCol ); m_lisViewCycle->SetColumnWidth( COL_TEXT, 80 );
69 m_listView->SetColumnWidth( 0, 40 ); 96 itemCol.SetText( wxT("o/w") ); m_lisViewCycle->InsertColumn( COL_OW, itemCol ); m_lisViewCycle->SetColumnWidth( COL_OW, 40 );
70 itemCol.SetText( wxT("text") ); 97 itemCol.SetText( wxT("live") ); m_lisViewCycle->InsertColumn( COL_MLT, itemCol ); m_lisViewCycle->SetColumnWidth( COL_MLT, 50 );
71 m_listView->InsertColumn( 1, itemCol ); 98 itemCol.SetText( wxT("active") ); m_lisViewCycle->InsertColumn( COL_MAL, itemCol ); m_lisViewCycle->SetColumnWidth( COL_MAL, 50 );
72 m_listView->SetColumnWidth( 1, 80 ); 99 itemCol.SetText( wxT("desc") ); m_lisViewCycle->InsertColumn( COL_DESC, itemCol ); m_lisViewCycle->SetColumnWidth( COL_DESC, 80 );
73 itemCol.SetText( wxT("time") ); 100 itemCol.SetText( wxT("id") ); m_lisViewCycle->InsertColumn( COL_ID, itemCol ); m_lisViewCycle->SetColumnWidth( COL_ID, 30 );
74 m_listView->InsertColumn( 2, itemCol ); 101 //m_lisViewCycle->EnableAlternateRowColours( true );
75 m_listView->SetColumnWidth( 2, 40 ); 102 bSizerList->Add( m_lisViewCycle, 1, wxALL|wxEXPAND, 5 );
76 itemCol.SetText( wxT("type") ); 103
77 m_listView->InsertColumn( 3, itemCol ); 104 m_staticTextHist = new wxStaticText( this, wxID_ANY, wxT("User input history"), wxDefaultPosition, wxDefaultSize, 0 );
78 m_listView->SetColumnWidth( 3, 40 ); 105 bSizerList->Add( m_staticTextHist, 0, wxTOP|wxLEFT|wxALIGN_BOTTOM, 5 );
79 itemCol.SetText( wxT("desc") ); 106
80 m_listView->InsertColumn( 4, itemCol ); 107 m_listBoxHist = new wxListBox( this, ID_LISTBOX, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE );
81 m_listView->SetColumnWidth( 4, 80 ); 108 bSizerList->Add( m_listBoxHist, 1, wxALL|wxEXPAND, 5 );
82 //m_listView->EnableAlternateRowColours( true ); 109
83 110 bSizerMain->Add( bSizerList, 1, wxEXPAND, 5 );
111
112 // button
84 wxBoxSizer* bSizerBtn = new wxBoxSizer( wxVERTICAL ); 113 wxBoxSizer* bSizerBtn = new wxBoxSizer( wxVERTICAL );
85 114
115 bSizerBtn->Add( 0, 20, 0, 0, 5 );
116
86 m_buttonUp = new wxButton( this, ID_BTNUP, wxT("↑"), wxDefaultPosition, wxSize( 40, -1 ), 0 ); 117 m_buttonUp = new wxButton( this, ID_BTNUP, wxT("↑"), wxDefaultPosition, wxSize( 40, -1 ), 0 );
87 bSizerBtn->Add( m_buttonUp, 0, wxALL, 5 ); 118 bSizerBtn->Add( m_buttonUp, 0, wxALL, 5 );
88 119
89 m_buttonDown = new wxButton( this, ID_BTNDOWN, wxT("↓"), wxDefaultPosition, wxSize( 40, -1 ), 0 ); 120 m_buttonDown = new wxButton( this, ID_BTNDOWN, wxT("↓"), wxDefaultPosition, wxSize( 40, -1 ), 0 );
90 bSizerBtn->Add( m_buttonDown, 0, wxALL, 5 ); 121 bSizerBtn->Add( m_buttonDown, 0, wxALL, 5 );
98 bSizerBtn->Add( 0, 0, 1, wxEXPAND, 5 ); 129 bSizerBtn->Add( 0, 0, 1, wxEXPAND, 5 );
99 130
100 m_buttonExit = new wxButton( this, ID_EXIT, wxT("Exit"), wxDefaultPosition, wxSize( 60, -1 ), 0 ); 131 m_buttonExit = new wxButton( this, ID_EXIT, wxT("Exit"), wxDefaultPosition, wxSize( 60, -1 ), 0 );
101 bSizerBtn->Add( m_buttonExit, 0, wxALL, 5 ); 132 bSizerBtn->Add( m_buttonExit, 0, wxALL, 5 );
102 133
103 bSizerList->Add( bSizerBtn, 0, wxEXPAND, 5 ); 134 bSizerMain->Add( bSizerBtn, 0, wxEXPAND, 5 );
104 bSizerTop->Add( bSizerList, 1, wxEXPAND, 5 ); 135
136 bSizerTop->Add( bSizerMain, 1, wxEXPAND, 5 );
105 137
106 this->SetSizer( bSizerTop ); 138 this->SetSizer( bSizerTop );
107 this->Layout(); 139 this->Layout();
108 140
109 this->Centre( wxBOTH ); 141 this->Centre( wxBOTH );
113 { 145 {
114 } 146 }
115 147
116 // Event Table 148 // Event Table
117 BEGIN_EVENT_TABLE( MainFrame, wxFrame ) 149 BEGIN_EVENT_TABLE( MainFrame, wxFrame )
118 EVT_MENU( ID_MNABOUT, MainFrame::OnMNAbout ) 150 EVT_MENU( ID_MNAPPDIR, MainFrame::OnMNAppdir )
119 EVT_MENU( ID_MNEXIT, MainFrame::OnMNExit ) 151 EVT_MENU( ID_MNINTERVAL, MainFrame::OnMNInterval )
120 EVT_MENU( ID_MNLDPGIN, MainFrame::OnMNLoad ) 152 EVT_MENU( ID_MNABOUT, MainFrame::OnMNAbout )
121 EVT_MENU( ID_MNSVPGIN, MainFrame::OnMNSaveAs ) 153 EVT_MENU( ID_MNEXIT, MainFrame::OnMNExit )
122 EVT_LIST_ITEM_ACTIVATED( ID_LIST, MainFrame::OnDClickItem ) 154 EVT_MENU( ID_MNLDPGIN, MainFrame::OnMNLoad )
123 EVT_LIST_ITEM_SELECTED( ID_LIST, MainFrame::OnSelectItem ) 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 )
124 EVT_TIMER( ID_TIMER, MainFrame::OnTimer ) 159 EVT_TIMER( ID_TIMER, MainFrame::OnTimer )
125 EVT_BUTTON( ID_BTNUP, MainFrame::OnBtnUp ) 160 EVT_BUTTON( ID_BTNUP, MainFrame::OnBtnUp )
126 EVT_BUTTON( ID_BTNDOWN, MainFrame::OnBtnDown ) 161 EVT_BUTTON( ID_BTNDOWN, MainFrame::OnBtnDown )
127 EVT_BUTTON( ID_BTNDEL, MainFrame::OnBtnDel ) 162 EVT_BUTTON( ID_BTNDEL, MainFrame::OnBtnDel )
128 EVT_BUTTON( ID_BTNADD, MainFrame::OnBtnAdd ) 163 EVT_BUTTON( ID_BTNADD, MainFrame::OnBtnAdd )
129 EVT_BUTTON( ID_EXIT, MainFrame::OnBtnExit ) 164 EVT_BUTTON( ID_EXIT, MainFrame::OnBtnExit )
130 EVT_TOGGLEBUTTON( ID_TGL, MainFrame::OnToggle ) 165 EVT_TOGGLEBUTTON( ID_TGL, MainFrame::OnToggle )
131 /* 166 /*
132 EVT_IDLE( MainFrame::OnIdle ) 167 EVT_IDLE( MainFrame::OnIdle )
133 EVT_CLOSE( MainFrame::OnClose ) 168 EVT_CLOSE( MainFrame::OnClose )
134 */ 169 */
135 END_EVENT_TABLE() 170 END_EVENT_TABLE()
136 171
137 /* Event Handlers & Functions */ 172 /* Event Handlers & Functions */
138 // Event Handlers 173 // Event Handlers
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
139 void MainFrame::OnMNAbout( wxCommandEvent& WXUNUSED(event) ) 188 void MainFrame::OnMNAbout( wxCommandEvent& WXUNUSED(event) )
140 { 189 {
141 wxInfoMessageBox( this ); 190 wxInfoMessageBox( this );
142 } 191 }
143 192
152 wxFileDialog fd( this, wxT("Select Plug-in file"), plugin_dir, wxEmptyString, wxT("Plug-in files (*.qbrd)|*.qbrd"), wxFD_OPEN|wxFD_FILE_MUST_EXIST ); 201 wxFileDialog fd( this, wxT("Select Plug-in file"), plugin_dir, wxEmptyString, wxT("Plug-in files (*.qbrd)|*.qbrd"), wxFD_OPEN|wxFD_FILE_MUST_EXIST );
153 if ( fd.ShowModal() == wxID_CANCEL ) return; // the user changed idea... 202 if ( fd.ShowModal() == wxID_CANCEL ) return; // the user changed idea...
154 203
155 wxTextFile file; 204 wxTextFile file;
156 file.Open( fd.GetPath() ); 205 file.Open( fd.GetPath() );
157 m_listView->DeleteAllItems(); 206 m_lisViewCycle->DeleteAllItems();
207 QH.clear();
158 for ( int i = 0, n = 0; i < file.GetLineCount(); i++ ) { 208 for ( int i = 0, n = 0; i < file.GetLineCount(); i++ ) {
159 if ( file[i].StartsWith( wxT("#") ) ) 209 if ( file[i].StartsWith( wxT("#") ) )
160 continue; 210 continue;
161 wxArrayString s = wxSplit( file[i], ',', '\\' ); 211 wxArrayString s = wxSplit( file[i], ',', '\\' );
162 212
163 m_listView->InsertItem( n, wxString::Format( wxT("%d"), n + 1 ) ); 213 m_lisViewCycle->InsertItem( n, wxString::Format( wxT("%d"), n + 1 ) );
164 m_listView->SetItem( n, 1, s[0] ); 214 m_lisViewCycle->SetItem( n, COL_TEXT, s[0] );
165 m_listView->SetItem( n, 2, s[1] ); 215 m_lisViewCycle->SetItem( n, COL_OW, s[1] );
166 m_listView->SetItem( n, 3, s[2] ); 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] );
167 n++; 220 n++;
168 } 221 }
169 file.Close(); 222 file.Close();
170 223
171 m_current = 0; 224 m_current = 0;
172 m_last = m_listView->GetItemText( m_current, 1 ); 225 m_lisViewCycle->Select( m_current, true );
173 m_listView->SetItemState( m_current, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
174 } 226 }
175 227
176 void MainFrame::OnMNSaveAs( wxCommandEvent& WXUNUSED(event) ) 228 void MainFrame::OnMNSaveAs( wxCommandEvent& WXUNUSED(event) )
177 { 229 {
178 wxString plugin_dir = wxGetCwd() + wxFILE_SEP_PATH + wxT("plugin"); 230 wxString plugin_dir = wxGetCwd() + wxFILE_SEP_PATH + wxT("plugin");
185 file.Clear(); 237 file.Clear();
186 } 238 }
187 else { 239 else {
188 file.Create(); 240 file.Create();
189 } 241 }
190 for ( int r = 0; r < m_listView->GetItemCount(); r++ ) { 242 for ( int r = 0; r < m_lisViewCycle->GetItemCount(); r++ ) {
191 wxArrayString s; 243 wxArrayString s;
192 for ( int c = 0; c < m_listView->GetColumnCount(); c++ ) { 244 for ( int c = 0; c < m_lisViewCycle->GetColumnCount(); c++ ) {
193 s.Add( m_listView->GetItemText( r, c ) ); 245 s.Add( m_lisViewCycle->GetItemText( r, c ) );
194 } 246 }
195 file.AddLine( wxJoin( s, ',', '\\' ) ); 247 file.AddLine( wxJoin( s, ',', '\\' ) );
196 } 248 }
197 file.Write(); 249 file.Write();
198 file.Close(); 250 file.Close();
199 } 251 }
200 252
201 void MainFrame::OnDClickItem( wxListEvent& event ) 253 void MainFrame::OnLViewDClickItem( wxListEvent& event )
254 {
255 wxString s = event.GetText();
256 }
257
258 void MainFrame::OnLViewSelectItem( wxListEvent& event )
202 { 259 {
203 long i = event.GetIndex(); 260 long i = event.GetIndex();
204 } 261 m_current = (int)i;
205 262 }
206 void MainFrame::OnSelectItem( wxListEvent& event ) 263
207 { 264 void MainFrame::OnLBoxDClickItem( wxCommandEvent& event )
208 long i = event.GetIndex(); 265 {
209 m_current = i; 266 wxString s = event.GetString();
210 } 267 m_counter = m_period;
211 268 if ( wxTheClipboard->Open() ) {
212 // ↑ 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 // [↑]
213 void MainFrame::OnBtnUp( wxCommandEvent& WXUNUSED(event) ) 281 void MainFrame::OnBtnUp( wxCommandEvent& WXUNUSED(event) )
214 { 282 {
215 long item = -1; 283 long item = m_lisViewCycle->GetFirstSelected();
216 item = m_listView->GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
217 if ( item == -1 || item == 0 ) return; 284 if ( item == -1 || item == 0 ) return;
218 SwapListItem( item, item - 1 ); 285 SwapListItem( item, item - 1 );
219 ReNumberList(); 286 ReNumberList();
220 } 287 }
221 288
222 // ↓ 289 // [↓]
223 void MainFrame::OnBtnDown( wxCommandEvent& WXUNUSED(event) ) 290 void MainFrame::OnBtnDown( wxCommandEvent& WXUNUSED(event) )
224 { 291 {
225 long item = -1; 292 long item = m_lisViewCycle->GetFirstSelected();
226 item = m_listView->GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); 293 if ( item == -1 || item == m_lisViewCycle->GetItemCount() - 1 ) return;
227 if ( item == -1 || item == m_listView->GetItemCount() - 1 ) return;
228 SwapListItem( item, item + 1 ); 294 SwapListItem( item, item + 1 );
229 ReNumberList(); 295 ReNumberList();
230 } 296 }
231 297
232 // − 298 // [−]
233 void MainFrame::OnBtnDel( wxCommandEvent& WXUNUSED(event) ) 299 void MainFrame::OnBtnDel( wxCommandEvent& WXUNUSED(event) )
234 { 300 {
235 long item = -1; 301 long item = m_lisViewCycle->GetFirstSelected();
236 for ( ;; ) { 302 if ( item == -1 ) return;
237 item = m_listView->GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); 303
238 if ( item == -1 ) break; 304 int id = ToInt( m_lisViewCycle->GetItemText( item, COL_ID ) );
239 m_listView->DeleteItem( item ); 305 QH.erase( id );
240 ReNumberList(); 306
241 } 307 m_lisViewCycle->DeleteItem( item );
242 } 308 ReNumberList();
243 309 }
244 // + 310
311 // [+]
245 void MainFrame::OnBtnAdd( wxCommandEvent& WXUNUSED(event) ) 312 void MainFrame::OnBtnAdd( wxCommandEvent& WXUNUSED(event) )
246 { 313 {
247 long item = -1; 314 int r;
248 for ( ;; ) { 315 long item = m_lisViewCycle->GetFirstSelected();
249 item = m_listView->GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); 316 if ( item == -1 ) r = 0;
250 if ( item == -1 ) break; 317 else r = item;
251 m_listView->InsertItem( item + 1, wxEmptyString ); 318
252 ReNumberList(); 319 AddDialog add_dlg( this, wxID_ANY, wxT("Add Item"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE );
253 } 320 if ( add_dlg.ShowModal() == wxID_OK ) {
254 /* 321 int id = CreateID();
255 AddDialog adlg( this, wxID_ANY, wxT("a"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE ); 322 QlipData* q = new QlipData;
256 if ( adlg.ShowModal() == wxID_OK ) { 323 q->id = id;
257 } 324 q->text = add_dlg.GetText();
258 */ 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") ) );
344 }
345 ReNumberList();
259 } 346 }
260 347
261 void MainFrame::OnTimer( wxTimerEvent& WXUNUSED(event) ) 348 void MainFrame::OnTimer( wxTimerEvent& WXUNUSED(event) )
262 { 349 {
350 wxString clipboard;
263 if ( wxTheClipboard->Open() ) { 351 if ( wxTheClipboard->Open() ) {
264 352 //wxMessageBox( clipboard );
265 wxTextDataObject data; 353 wxTextDataObject data;
266 wxTheClipboard->GetData( data ); 354 wxTheClipboard->GetData( data );
267 wxString s = data.GetText(); 355 clipboard = data.GetText();
268 if ( !m_last.IsSameAs( s ) ) { // the clipboard was changed by user 356 wxTheClipboard->Close();
269 wxTheClipboard->Close(); 357
270 m_textCtrlShow->SetValue( s ); 358 m_textCtrlShow->SetValue( clipboard );
271 for ( int r = 0; r < m_listView->GetItemCount(); r++ ) 359 m_textCtrlRemain->SetValue( wxT("∞") );
272 m_listView->SetItemState( r, 0, wxLIST_STATE_SELECTED ); 360 UpdateHistory( clipboard );
273 m_counter = 5; 361 }
274 m_current = 0; 362 else {
275 m_last = s; 363 return;
276 m_timer.StartOnce( (int)m_counter * 1000 ); 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++;
408 }
409
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() )
277 return; 421 return;
422
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 );
429
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 }
278 } 438 }
279 439 else {
280 wxString text = m_listView->GetItemText( m_current, 1 ); 440 int t = q->max_active_time - q->active_time;
281 wxTheClipboard->SetData( new wxTextDataObject( text ) ); 441 m_textCtrlRemain->SetValue( wxString::Format( wxT("%d"), t ) );
282 wxTheClipboard->Close(); 442 }
283 m_textCtrlShow->SetValue( text );
284 m_listView->SetItemState( ( m_current + m_listView->GetItemCount() ) % m_listView->GetItemCount() - 1, 0, wxLIST_STATE_SELECTED );
285 m_listView->SetItemState( m_current, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
286 m_last = text;
287
288 wxString time = m_listView->GetItemText( m_current, 2 );
289 time.ToLong( &m_counter, 10 );
290 m_timer.StartOnce( (int)m_counter * 1000 );
291
292 if ( m_current == m_listView->GetItemCount() - 1 ) m_current = 0;
293 else m_current++;
294 } 443 }
295 } 444 }
296 445
297 void MainFrame::OnToggle( wxCommandEvent& WXUNUSED(event) ) 446 void MainFrame::OnToggle( wxCommandEvent& WXUNUSED(event) )
298 { 447 {
299 if ( m_toggleBtn->GetValue() ) { 448 if ( m_toggleBtn->GetValue() ) {
300 m_toggleBtn->SetLabel( wxT("OFF") ); 449 m_toggleBtn->SetLabel( wxT("OFF") );
301 EnableButtons( false ); 450 EnableButtons( false );
302 if ( m_listView->GetItemCount() > 0 ) { 451 m_timer.Start( 1000 );
303 m_timer.StartOnce( 1000 );
304 }
305 } 452 }
306 else { 453 else {
307 m_timer.Stop(); 454 m_timer.Stop();
308 m_toggleBtn->SetLabel( wxT("ON") ); 455 m_toggleBtn->SetLabel( wxT("ON") );
309 EnableButtons( true ); 456 EnableButtons( true );
332 } 479 }
333 } 480 }
334 481
335 void MainFrame::ReNumberList() 482 void MainFrame::ReNumberList()
336 { 483 {
337 for ( int i = 0; i < m_listView->GetItemCount(); i++ ) { 484 for ( int r = 0; r < m_lisViewCycle->GetItemCount(); r++ ) {
338 m_listView->SetItem( i, 0, wxString::Format( wxT("%d"), i + 1 ) ); 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") ) );
339 } 491 }
340 } 492 }
341 493
342 void MainFrame::SwapListItem( long item1, long item2 ) 494 void MainFrame::SwapListItem( long item1, long item2 )
343 { 495 {
344 for ( int c = 0; c < m_listView->GetColumnCount(); c++ ) { 496 for ( int c = 0; c < m_lisViewCycle->GetColumnCount(); c++ ) {
345 wxString buf = m_listView->GetItemText( item1, c ); 497 wxString buf = m_lisViewCycle->GetItemText( item1, c );
346 m_listView->SetItem( item1, c, m_listView->GetItemText( item2, c ) ); 498 m_lisViewCycle->SetItem( item1, c, m_lisViewCycle->GetItemText( item2, c ) );
347 m_listView->SetItem( item2, c, buf ); 499 m_lisViewCycle->SetItem( item2, c, buf );
348 } 500 }
349 m_listView->SetItemState( item1, 0, wxLIST_STATE_SELECTED ); 501 m_lisViewCycle->Select( item1, false );
350 m_listView->SetItemState( item2, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); 502 m_lisViewCycle->Select( item2, true );
351 } 503 }
352 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 }
534 }
535
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