Mercurial > mercurial > hgweb_qlipbrd.cgi
diff src/mainframe.cpp @ 1:e4aa0e7a07ad
Second release.
author | pyon@macmini |
---|---|
date | Sun, 13 Sep 2015 14:56:42 +0900 |
parents | cb3403ca39b1 |
children | fd4361d2cbbd |
line wrap: on
line diff
--- a/src/mainframe.cpp Sun Aug 30 21:53:19 2015 +0900 +++ b/src/mainframe.cpp Sun Sep 13 14:56:42 2015 +0900 @@ -1,11 +1,12 @@ // Filename: mainframe.cpp -// Last Change: 2015-08-30 Sun 21:49:16. +// Last Change: 2015-09-13 Sun 14:43:27. // #include <wx/filedlg.h> #include <wx/textfile.h> #include <wx/clipbrd.h> #include <wx/utils.h> #include <wx/msgdlg.h> +#include "wx/numdlg.h" #include "mainframe.h" #include "adddialog.h" @@ -15,16 +16,34 @@ #include "sample.xpm" #endif +#define COL_NO 0 +#define COL_TEXT 1 +#define COL_OW 2 +#define COL_MLT 3 +#define COL_MAL 4 +#define COL_DESC 5 +#define COL_ID 6 + MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) - : wxFrame( parent, id, title, pos, size, style ), m_timer( this, ID_TIMER ) + : wxFrame( parent, id, title, pos, size, style ), + m_timer( this, ID_TIMER ), + m_counter( 0 ), + m_period( 5 ), + m_bottom( true ) { - this->SetSizeHints( wxDefaultSize, wxDefaultSize ); + this->SetSizeHints( wxSize( 500, 450 ), wxDefaultSize ); this->SetBackgroundColour( wxColour( wxT("WHEAT") ) ); SetIcon( wxICON( sample ) ); // menu bar m_menubar = new wxMenuBar( 0 ); m_menuFile = new wxMenu(); + wxMenuItem* m_menuItemAppdir = new wxMenuItem( m_menuFile, ID_MNAPPDIR, wxString( wxT("Open App Forlder") ), wxEmptyString, wxITEM_NORMAL ); + m_menuFile->Append( m_menuItemAppdir ); + + wxMenuItem* m_menuItemInterval = new wxMenuItem( m_menuFile, ID_MNINTERVAL, wxString( wxT("Set Interval") ), wxEmptyString, wxITEM_NORMAL ); + m_menuFile->Append( m_menuItemInterval ); + wxMenuItem* m_menuItemAbout = new wxMenuItem( m_menuFile, ID_MNABOUT, wxString( wxT("About") ), wxEmptyString, wxITEM_NORMAL ); m_menuFile->Append( m_menuItemAbout ); @@ -53,36 +72,48 @@ m_textCtrlShow = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY ); bSizerShow->Add( m_textCtrlShow, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + m_textCtrlRemain = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 40, -1 ), wxTE_READONLY|wxTE_CENTER ); + bSizerShow->Add( m_textCtrlRemain, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5 ); + m_toggleBtn = new wxToggleButton( this, ID_TGL, wxT("ON"), wxDefaultPosition, wxSize( 60, -1 ), 0 ); bSizerShow->Add( m_toggleBtn, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); bSizerTop->Add( bSizerShow, 0, wxEXPAND, 5 ); // - wxBoxSizer* bSizerList = new wxBoxSizer( wxHORIZONTAL ); + wxBoxSizer* bSizerMain = new wxBoxSizer( wxHORIZONTAL ); - m_listView = new wxListView( this, ID_LIST, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL ); - bSizerList->Add( m_listView, 1, wxALL|wxEXPAND, 5 ); + // list + wxBoxSizer* bSizerList = new wxBoxSizer( wxVERTICAL ); + + m_staticTextCycle = new wxStaticText( this, wxID_ANY, wxT("Cycle list"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerList->Add( m_staticTextCycle, 0, wxTOP|wxLEFT|wxALIGN_BOTTOM, 5 ); + + m_lisViewCycle = new wxListView( this, ID_LISTVIEW, wxDefaultPosition, wxSize( -1, 100 ), wxLC_REPORT|wxLC_SINGLE_SEL ); wxListItem itemCol; - itemCol.SetText( wxT("No") ); - m_listView->InsertColumn( 0, itemCol ); - m_listView->SetColumnWidth( 0, 40 ); - itemCol.SetText( wxT("text") ); - m_listView->InsertColumn( 1, itemCol ); - m_listView->SetColumnWidth( 1, 80 ); - itemCol.SetText( wxT("time") ); - m_listView->InsertColumn( 2, itemCol ); - m_listView->SetColumnWidth( 2, 40 ); - itemCol.SetText( wxT("type") ); - m_listView->InsertColumn( 3, itemCol ); - m_listView->SetColumnWidth( 3, 40 ); - itemCol.SetText( wxT("desc") ); - m_listView->InsertColumn( 4, itemCol ); - m_listView->SetColumnWidth( 4, 80 ); - //m_listView->EnableAlternateRowColours( true ); + itemCol.SetText( wxT("No") ); m_lisViewCycle->InsertColumn( COL_NO, itemCol ); m_lisViewCycle->SetColumnWidth( COL_NO, 20 ); + itemCol.SetText( wxT("text") ); m_lisViewCycle->InsertColumn( COL_TEXT, itemCol ); m_lisViewCycle->SetColumnWidth( COL_TEXT, 80 ); + itemCol.SetText( wxT("o/w") ); m_lisViewCycle->InsertColumn( COL_OW, itemCol ); m_lisViewCycle->SetColumnWidth( COL_OW, 40 ); + itemCol.SetText( wxT("live") ); m_lisViewCycle->InsertColumn( COL_MLT, itemCol ); m_lisViewCycle->SetColumnWidth( COL_MLT, 50 ); + itemCol.SetText( wxT("active") ); m_lisViewCycle->InsertColumn( COL_MAL, itemCol ); m_lisViewCycle->SetColumnWidth( COL_MAL, 50 ); + itemCol.SetText( wxT("desc") ); m_lisViewCycle->InsertColumn( COL_DESC, itemCol ); m_lisViewCycle->SetColumnWidth( COL_DESC, 80 ); + itemCol.SetText( wxT("id") ); m_lisViewCycle->InsertColumn( COL_ID, itemCol ); m_lisViewCycle->SetColumnWidth( COL_ID, 30 ); + //m_lisViewCycle->EnableAlternateRowColours( true ); + bSizerList->Add( m_lisViewCycle, 1, wxALL|wxEXPAND, 5 ); + m_staticTextHist = new wxStaticText( this, wxID_ANY, wxT("User input history"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerList->Add( m_staticTextHist, 0, wxTOP|wxLEFT|wxALIGN_BOTTOM, 5 ); + + m_listBoxHist = new wxListBox( this, ID_LISTBOX, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE ); + bSizerList->Add( m_listBoxHist, 1, wxALL|wxEXPAND, 5 ); + + bSizerMain->Add( bSizerList, 1, wxEXPAND, 5 ); + + // button wxBoxSizer* bSizerBtn = new wxBoxSizer( wxVERTICAL ); + bSizerBtn->Add( 0, 20, 0, 0, 5 ); + m_buttonUp = new wxButton( this, ID_BTNUP, wxT("↑"), wxDefaultPosition, wxSize( 40, -1 ), 0 ); bSizerBtn->Add( m_buttonUp, 0, wxALL, 5 ); @@ -100,8 +131,9 @@ m_buttonExit = new wxButton( this, ID_EXIT, wxT("Exit"), wxDefaultPosition, wxSize( 60, -1 ), 0 ); bSizerBtn->Add( m_buttonExit, 0, wxALL, 5 ); - bSizerList->Add( bSizerBtn, 0, wxEXPAND, 5 ); - bSizerTop->Add( bSizerList, 1, wxEXPAND, 5 ); + bSizerMain->Add( bSizerBtn, 0, wxEXPAND, 5 ); + + bSizerTop->Add( bSizerMain, 1, wxEXPAND, 5 ); this->SetSizer( bSizerTop ); this->Layout(); @@ -115,19 +147,22 @@ // Event Table BEGIN_EVENT_TABLE( MainFrame, wxFrame ) - EVT_MENU( ID_MNABOUT, MainFrame::OnMNAbout ) - EVT_MENU( ID_MNEXIT, MainFrame::OnMNExit ) - EVT_MENU( ID_MNLDPGIN, MainFrame::OnMNLoad ) - EVT_MENU( ID_MNSVPGIN, MainFrame::OnMNSaveAs ) - EVT_LIST_ITEM_ACTIVATED( ID_LIST, MainFrame::OnDClickItem ) - EVT_LIST_ITEM_SELECTED( ID_LIST, MainFrame::OnSelectItem ) + EVT_MENU( ID_MNAPPDIR, MainFrame::OnMNAppdir ) + EVT_MENU( ID_MNINTERVAL, MainFrame::OnMNInterval ) + EVT_MENU( ID_MNABOUT, MainFrame::OnMNAbout ) + EVT_MENU( ID_MNEXIT, MainFrame::OnMNExit ) + EVT_MENU( ID_MNLDPGIN, MainFrame::OnMNLoad ) + EVT_MENU( ID_MNSVPGIN, MainFrame::OnMNSaveAs ) + EVT_LIST_ITEM_ACTIVATED( ID_LISTVIEW, MainFrame::OnLViewDClickItem ) + EVT_LIST_ITEM_SELECTED( ID_LISTVIEW, MainFrame::OnLViewSelectItem ) + EVT_LISTBOX_DCLICK( ID_LISTBOX, MainFrame::OnLBoxDClickItem ) EVT_TIMER( ID_TIMER, MainFrame::OnTimer ) - EVT_BUTTON( ID_BTNUP, MainFrame::OnBtnUp ) + EVT_BUTTON( ID_BTNUP, MainFrame::OnBtnUp ) EVT_BUTTON( ID_BTNDOWN, MainFrame::OnBtnDown ) - EVT_BUTTON( ID_BTNDEL, MainFrame::OnBtnDel ) - EVT_BUTTON( ID_BTNADD, MainFrame::OnBtnAdd ) + EVT_BUTTON( ID_BTNDEL, MainFrame::OnBtnDel ) + EVT_BUTTON( ID_BTNADD, MainFrame::OnBtnAdd ) EVT_BUTTON( ID_EXIT, MainFrame::OnBtnExit ) - EVT_TOGGLEBUTTON( ID_TGL, MainFrame::OnToggle ) + EVT_TOGGLEBUTTON( ID_TGL, MainFrame::OnToggle ) /* EVT_IDLE( MainFrame::OnIdle ) EVT_CLOSE( MainFrame::OnClose ) @@ -136,6 +171,20 @@ /* Event Handlers & Functions */ // Event Handlers +void MainFrame::OnMNAppdir( wxCommandEvent& WXUNUSED(event) ) +{ + wxString app_dir = wxGetCwd(); + wxString execmd = wxT("explorer ") + app_dir; + wxExecute( execmd ); +} + +void MainFrame::OnMNInterval( wxCommandEvent& WXUNUSED(event) ) +{ + long t = wxGetNumberFromUser( wxT("text changed by user is preserved specified period."), wxT("Input 1-60[sec]."), wxT("Setting"), 5, 1, 60, this, wxDefaultPosition ); + if ( t != -1 ) // canceled + m_period = (int)t; +} + void MainFrame::OnMNAbout( wxCommandEvent& WXUNUSED(event) ) { wxInfoMessageBox( this ); @@ -154,23 +203,26 @@ wxTextFile file; file.Open( fd.GetPath() ); - m_listView->DeleteAllItems(); + m_lisViewCycle->DeleteAllItems(); + QH.clear(); for ( int i = 0, n = 0; i < file.GetLineCount(); i++ ) { if ( file[i].StartsWith( wxT("#") ) ) continue; wxArrayString s = wxSplit( file[i], ',', '\\' ); - m_listView->InsertItem( n, wxString::Format( wxT("%d"), n + 1 ) ); - m_listView->SetItem( n, 1, s[0] ); - m_listView->SetItem( n, 2, s[1] ); - m_listView->SetItem( n, 3, s[2] ); + m_lisViewCycle->InsertItem( n, wxString::Format( wxT("%d"), n + 1 ) ); + m_lisViewCycle->SetItem( n, COL_TEXT, s[0] ); + m_lisViewCycle->SetItem( n, COL_OW, s[1] ); + m_lisViewCycle->SetItem( n, COL_MLT, s[2] ); + m_lisViewCycle->SetItem( n, COL_MAL, s[3] ); + m_lisViewCycle->SetItem( n, COL_DESC, s[4] ); + m_lisViewCycle->SetItem( n, COL_ID, s[5] ); n++; } file.Close(); m_current = 0; - m_last = m_listView->GetItemText( m_current, 1 ); - m_listView->SetItemState( m_current, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); + m_lisViewCycle->Select( m_current, true ); } void MainFrame::OnMNSaveAs( wxCommandEvent& WXUNUSED(event) ) @@ -187,10 +239,10 @@ else { file.Create(); } - for ( int r = 0; r < m_listView->GetItemCount(); r++ ) { + for ( int r = 0; r < m_lisViewCycle->GetItemCount(); r++ ) { wxArrayString s; - for ( int c = 0; c < m_listView->GetColumnCount(); c++ ) { - s.Add( m_listView->GetItemText( r, c ) ); + for ( int c = 0; c < m_lisViewCycle->GetColumnCount(); c++ ) { + s.Add( m_lisViewCycle->GetItemText( r, c ) ); } file.AddLine( wxJoin( s, ',', '\\' ) ); } @@ -198,99 +250,196 @@ file.Close(); } -void MainFrame::OnDClickItem( wxListEvent& event ) +void MainFrame::OnLViewDClickItem( wxListEvent& event ) { - long i = event.GetIndex(); + wxString s = event.GetText(); } -void MainFrame::OnSelectItem( wxListEvent& event ) +void MainFrame::OnLViewSelectItem( wxListEvent& event ) { long i = event.GetIndex(); - m_current = i; + m_current = (int)i; } -// ↑ +void MainFrame::OnLBoxDClickItem( wxCommandEvent& event ) +{ + wxString s = event.GetString(); + m_counter = m_period; + if ( wxTheClipboard->Open() ) { + wxTheClipboard->SetData( new wxTextDataObject( s ) ); + wxTheClipboard->Close(); + m_listBoxHist->Delete( event.GetSelection() ); + m_listBoxHist->Insert( s, 0 ); + m_textCtrlShow->SetValue( s ); + m_textCtrlRemain->SetValue( wxString::Format( wxT("%d"), m_period ) ); + } + m_listBoxHist->Deselect( event.GetInt() ); + m_listBoxHist->SetSelection( 0 ); +} + +// [↑] void MainFrame::OnBtnUp( wxCommandEvent& WXUNUSED(event) ) { - long item = -1; - item = m_listView->GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); + long item = m_lisViewCycle->GetFirstSelected(); if ( item == -1 || item == 0 ) return; SwapListItem( item, item - 1 ); ReNumberList(); } -// ↓ +// [↓] void MainFrame::OnBtnDown( wxCommandEvent& WXUNUSED(event) ) { - long item = -1; - item = m_listView->GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); - if ( item == -1 || item == m_listView->GetItemCount() - 1 ) return; + long item = m_lisViewCycle->GetFirstSelected(); + if ( item == -1 || item == m_lisViewCycle->GetItemCount() - 1 ) return; SwapListItem( item, item + 1 ); ReNumberList(); } -// − +// [−] void MainFrame::OnBtnDel( wxCommandEvent& WXUNUSED(event) ) { - long item = -1; - for ( ;; ) { - item = m_listView->GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); - if ( item == -1 ) break; - m_listView->DeleteItem( item ); - ReNumberList(); - } + long item = m_lisViewCycle->GetFirstSelected(); + if ( item == -1 ) return; + + int id = ToInt( m_lisViewCycle->GetItemText( item, COL_ID ) ); + QH.erase( id ); + + m_lisViewCycle->DeleteItem( item ); + ReNumberList(); } -// + +// [+] void MainFrame::OnBtnAdd( wxCommandEvent& WXUNUSED(event) ) { - long item = -1; - for ( ;; ) { - item = m_listView->GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); - if ( item == -1 ) break; - m_listView->InsertItem( item + 1, wxEmptyString ); - ReNumberList(); + int r; + long item = m_lisViewCycle->GetFirstSelected(); + if ( item == -1 ) r = 0; + else r = item; + + AddDialog add_dlg( this, wxID_ANY, wxT("Add Item"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE ); + if ( add_dlg.ShowModal() == wxID_OK ) { + int id = CreateID(); + QlipData* q = new QlipData; + q->id = id; + q->text = add_dlg.GetText(); + q->overwrite = add_dlg.GetOverwrite(); + q->max_active_time = add_dlg.GetMaxActiveTime(); + q->max_live_time = q->overwrite ? add_dlg.GetMaxLiveTime() : 0; + q->desc = add_dlg.GetDesc(); + q->active_time = 0; + q->live_time = 0; + QH[id] = q; + + m_lisViewCycle->InsertItem( r, wxEmptyString ); + m_lisViewCycle->SetItem( r, COL_TEXT, q->text ); + m_lisViewCycle->SetItem( r, COL_OW, wxString::Format( wxT("%s"), q->overwrite ? wxT("true") : wxT("false") ) ); + m_lisViewCycle->SetItem( r, COL_MAL, wxString::Format( wxT("-- / %d"), q->max_active_time ) ); + m_lisViewCycle->SetItem( r, COL_MLT, wxString::Format( wxT("-- / %d"), q->max_live_time ) ); + m_lisViewCycle->SetItem( r, COL_DESC, q->desc ); + m_lisViewCycle->SetItem( r, COL_ID, wxString::Format( wxT("%d"), id ) ); + if ( q->overwrite ) + m_lisViewCycle->SetItemBackgroundColour( r, wxColour( wxT("MEDIUM GOLDENROD") ) ); + else + m_lisViewCycle->SetItemBackgroundColour( r, wxColour( wxT("WHITE") ) ); } - /* - AddDialog adlg( this, wxID_ANY, wxT("a"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE ); - if ( adlg.ShowModal() == wxID_OK ) { - } - */ + ReNumberList(); } void MainFrame::OnTimer( wxTimerEvent& WXUNUSED(event) ) { + wxString clipboard; if ( wxTheClipboard->Open() ) { - + //wxMessageBox( clipboard ); wxTextDataObject data; wxTheClipboard->GetData( data ); - wxString s = data.GetText(); - if ( !m_last.IsSameAs( s ) ) { // the clipboard was changed by user - wxTheClipboard->Close(); - m_textCtrlShow->SetValue( s ); - for ( int r = 0; r < m_listView->GetItemCount(); r++ ) - m_listView->SetItemState( r, 0, wxLIST_STATE_SELECTED ); - m_counter = 5; - m_current = 0; - m_last = s; - m_timer.StartOnce( (int)m_counter * 1000 ); - return; + clipboard = data.GetText(); + wxTheClipboard->Close(); + + m_textCtrlShow->SetValue( clipboard ); + m_textCtrlRemain->SetValue( wxT("∞") ); + UpdateHistory( clipboard ); + } + else { + return; + } + + long list_num = m_lisViewCycle->GetItemCount(); + if ( list_num == 0 ) return; + + if ( m_lisViewCycle->GetSelectedItemCount() == 0 ) { + m_lisViewCycle->Select( 0, true ); + m_current = 0; + } + + AddStackTime(); + UpdateView(); + int r = GetEmptyStack(); + if ( r != -1 && m_bottom ) { + m_timer.Stop(); + + int id = ToInt( m_lisViewCycle->GetItemText( r, COL_ID ) ); + QH[id]->text = clipboard; + m_lisViewCycle->SetItem( r, COL_TEXT, clipboard ); + + wxSleep( 2 ); + m_timer.Start( -1 ); + m_current = 0; + m_lisViewCycle->Select( 0, true ); + return; + } + + // Main Cycle + if ( list_num == 1 ) { + if ( m_counter == m_period ) { + m_counter = 0; + if ( wxTheClipboard->Open() ) { + wxString s = m_lisViewCycle->GetItemText( 0, COL_TEXT ); + wxTheClipboard->SetData( new wxTextDataObject( s ) ); + wxTheClipboard->Close(); + m_textCtrlShow->SetValue( s ); + m_textCtrlRemain->SetValue( wxT("∞") ); + } + } + else { + wxString t = wxString::Format( wxT("%d"), m_period - m_counter ); + m_textCtrlShow->SetValue( clipboard ); + m_textCtrlRemain->SetValue( t ); + m_counter++; } - wxString text = m_listView->GetItemText( m_current, 1 ); - wxTheClipboard->SetData( new wxTextDataObject( text ) ); - wxTheClipboard->Close(); - m_textCtrlShow->SetValue( text ); - m_listView->SetItemState( ( m_current + m_listView->GetItemCount() ) % m_listView->GetItemCount() - 1, 0, wxLIST_STATE_SELECTED ); - m_listView->SetItemState( m_current, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); - m_last = text; + m_lisViewCycle->Select( 0, true ); + m_current = 0; + m_bottom = true; + } + else { + long item = m_lisViewCycle->GetFirstSelected(); + m_current = (int)item; + + int id = ToInt( m_lisViewCycle->GetItemText( item, COL_ID ) ); + QlipData* q = QH[id]; + if ( q->overwrite && !q->IsAlive() ) + return; - wxString time = m_listView->GetItemText( m_current, 2 ); - time.ToLong( &m_counter, 10 ); - m_timer.StartOnce( (int)m_counter * 1000 ); + if ( q->IsArrived() ) { + m_lisViewCycle->Select( m_current, false ); + if ( ++m_current == list_num ) m_bottom = true; + else m_bottom = false; + m_current = m_current % list_num; + m_lisViewCycle->Select( m_current, true ); - if ( m_current == m_listView->GetItemCount() - 1 ) m_current = 0; - else m_current++; + if ( wxTheClipboard->Open() ) { + int id = ToInt( m_lisViewCycle->GetItemText( m_current, COL_ID ) ); + QlipData* qn = QH[id]; + wxTheClipboard->SetData( new wxTextDataObject( qn->text ) ); + wxTheClipboard->Close(); + m_textCtrlShow->SetValue( qn->text ); + m_textCtrlRemain->SetValue( wxString::Format( wxT("%d"), qn->max_active_time ) ); + } + } + else { + int t = q->max_active_time - q->active_time; + m_textCtrlRemain->SetValue( wxString::Format( wxT("%d"), t ) ); + } } } @@ -299,9 +448,7 @@ if ( m_toggleBtn->GetValue() ) { m_toggleBtn->SetLabel( wxT("OFF") ); EnableButtons( false ); - if ( m_listView->GetItemCount() > 0 ) { - m_timer.StartOnce( 1000 ); - } + m_timer.Start( 1000 ); } else { m_timer.Stop(); @@ -334,19 +481,98 @@ void MainFrame::ReNumberList() { - for ( int i = 0; i < m_listView->GetItemCount(); i++ ) { - m_listView->SetItem( i, 0, wxString::Format( wxT("%d"), i + 1 ) ); + for ( int r = 0; r < m_lisViewCycle->GetItemCount(); r++ ) { + m_lisViewCycle->SetItem( r, COL_NO, wxString::Format( wxT("%d"), r + 1 ) ); + wxString s = m_lisViewCycle->GetItemText( r, COL_OW ); + if ( s.IsSameAs( wxT("true") ) ) + m_lisViewCycle->SetItemBackgroundColour( r, wxColour( wxT("MEDIUM GOLDENROD") ) ); + else + m_lisViewCycle->SetItemBackgroundColour( r, wxColour( wxT("WHITE") ) ); } } void MainFrame::SwapListItem( long item1, long item2 ) { - for ( int c = 0; c < m_listView->GetColumnCount(); c++ ) { - wxString buf = m_listView->GetItemText( item1, c ); - m_listView->SetItem( item1, c, m_listView->GetItemText( item2, c ) ); - m_listView->SetItem( item2, c, buf ); + for ( int c = 0; c < m_lisViewCycle->GetColumnCount(); c++ ) { + wxString buf = m_lisViewCycle->GetItemText( item1, c ); + m_lisViewCycle->SetItem( item1, c, m_lisViewCycle->GetItemText( item2, c ) ); + m_lisViewCycle->SetItem( item2, c, buf ); } - m_listView->SetItemState( item1, 0, wxLIST_STATE_SELECTED ); - m_listView->SetItemState( item2, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); + m_lisViewCycle->Select( item1, false ); + m_lisViewCycle->Select( item2, true ); +} + +int MainFrame::CreateID() +{ + long max_id = 1; + if ( m_lisViewCycle->GetItemCount() == 0 ) + return max_id; + + wxArrayString id; + for ( int r = 0; r < m_lisViewCycle->GetItemCount(); r++ ) { + wxString buf = m_lisViewCycle->GetItemText( r, COL_ID ); + id.Add( buf ); + } + id.Sort(); + wxString max = id.Last(); + max.ToLong( &max_id, 10 ); + return ++max_id; +} + +void MainFrame::AddStackTime() +{ + QlipDataHash::iterator it; + for ( it = QH.begin(); it != QH.end(); it++ ) { + int id = it->first; + QlipData* q = it->second; + if ( q->overwrite ) { + if ( ++q->live_time == q->max_live_time ) + q->Kill(); + } + QH[id] = q; + } } +void MainFrame::UpdateView() +{ + for ( int r = 0; r < m_lisViewCycle->GetItemCount(); r++ ) { + int id = ToInt( m_lisViewCycle->GetItemText( r, COL_ID ) ); + + m_lisViewCycle->SetItem( r, COL_TEXT, QH[id]->text ); + + wxString at = wxString::Format( wxT("%d / %d"), QH[id]->active_time, QH[id]->max_active_time ); + m_lisViewCycle->SetItem( r, COL_MAL, at ); + + wxString lt = wxT("-- / --"); + if ( QH[id]->overwrite ) + lt = wxString::Format( wxT("%d / %d"), QH[id]->live_time, QH[id]->max_live_time ); + m_lisViewCycle->SetItem( r, COL_MLT, lt ); + } +} + +void MainFrame::UpdateHistory( wxString s ) +{ + if ( s.IsEmpty() ) return; + int row = m_listBoxHist->FindString( s, true ); + if ( row != wxNOT_FOUND ) + m_listBoxHist->Delete( row ); + m_listBoxHist->Insert( s, 0 ); +} + +int MainFrame::GetEmptyStack() +{ + int row = -1; + for ( int r = 0; r < m_lisViewCycle->GetItemCount(); r++ ) { + int id = ToInt( m_lisViewCycle->GetItemText( r, COL_ID ) ); + if ( QH[(int)id]->text.IsEmpty() ) row = r; + } + return row; +} + +int MainFrame::ToInt( wxString s ) +{ + long n = 0; + s.ToLong( &n, 10 ); + return n; +} +