Mercurial > mercurial > hgweb_qlipbrd.cgi
changeset 0:cb3403ca39b1
First release.
author | pyon@macmini |
---|---|
date | Sun, 30 Aug 2015 21:53:19 +0900 |
parents | |
children | e4aa0e7a07ad |
files | Makefile image/sample.ico image/sample.xpm include/adddialog.h include/main.h include/mainframe.h src/adddialog.cpp src/main.cpp src/mainframe.cpp |
diffstat | 9 files changed, 829 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Sun Aug 30 21:53:19 2015 +0900 @@ -0,0 +1,100 @@ +# Makefile for wxWidgets Application +# Last Change: 2015-08-30 Sun 12:54:13. +# by Takayuki Mutoh +# + +PROGNAME = QlipBoard + +### Variables ### +OBJDIR = ./obj +CXX = g++ +vpath %.cpp ./src +vpath %.h ./include + +# For Microsoft Windows +ifdef COMSPEC +WXCXXFLAGS = -I/local/lib/wx/include/msw-unicode-static-3.0 -I/local/include/wx-3.0 -D_LARGEFILE_SOURCE=unknown -D__WXMSW__ -mthreads +WXLIBS = -L/local/lib -Wl,--subsystem,windows -mwindows /local/lib/libwx_mswu_richtext-3.0.a /local/lib/libwx_mswu_xrc-3.0.a /local/lib/libwx_mswu_webview-3.0.a /local/lib/libwx_mswu_qa-3.0.a /local/lib/libwx_baseu_net-3.0.a /local/lib/libwx_mswu_html-3.0.a /local/lib/libwx_mswu_adv-3.0.a /local/lib/libwx_mswu_core-3.0.a /local/lib/libwx_baseu_xml-3.0.a /local/lib/libwx_baseu-3.0.a -lwxregexu-3.0 -lwxexpat-3.0 -lwxtiff-3.0 -lwxjpeg-3.0 -lwxpng-3.0 -lwxzlib-3.0 -lrpcrt4 -loleaut32 -lole32 -luuid -lwinspool -lwinmm -lshell32 -lcomctl32 -lcomdlg32 -ladvapi32 -lwsock32 -lgdi32 +EXECUTABLE = $(PROGNAME).exe +CXXFLAGS = $(WXCXXFLAGS) -I./include -I./image +LIBS = $(WXLIBS) -static-libgcc -static-libstdc++ + +# For Apple OSX +else +WXROOT = /opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.0 +WXCXXFLAGS = -I$(WXROOT)/lib/wx/include/osx_cocoa-unicode-3.0 -I$(WXROOT)/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXMAC__ -D__WXOSX__ -D__WXOSX_COCOA__ +WXLIBS = -L$(WXROOT)/lib -framework IOKit -framework Carbon -framework Cocoa -framework AudioToolbox -framework System -framework OpenGL -lwx_osx_cocoau_xrc-3.0 -lwx_osx_cocoau_webview-3.0 -lwx_osx_cocoau_html-3.0 -lwx_osx_cocoau_qa-3.0 -lwx_osx_cocoau_adv-3.0 -lwx_osx_cocoau_core-3.0 -lwx_osx_cocoau_richtext-3.0 -lwx_baseu_xml-3.0 -lwx_baseu_net-3.0 -lwx_baseu-3.0 + +EXECUTABLE = $(PROGNAME).app/Contents/Pkginfo +CXXFLAGS = $(WXCXXFLAGS) -I./include -I./image +LIBS = $(WXLIBS) + +endif + + +# Objects +OBJ = $(OBJDIR)/main.o \ + $(OBJDIR)/mainframe.o \ + $(OBJDIR)/adddialog.o + +ifdef COMSPEC +OBJMSW = $(OBJ) $(OBJDIR)/sample_rc.o +endif + + +### Targets ### +all: $(EXECUTABLE) + +ifdef COMSPEC +$(PROGNAME): $(OBJMSW) + $(CXX) $^ -o $@ $(LIBS) +else +$(PROGNAME): $(OBJ) + $(CXX) $^ -o $@ $(LIBS) +endif + +$(OBJDIR)/main.o: main.cpp main.h mainframe.h + -mkdir -p $(OBJDIR) + $(CXX) -c $< -o $@ $(CXXFLAGS) + +$(OBJDIR)/mainframe.o: mainframe.cpp mainframe.h + $(CXX) -c $< -o $@ $(CXXFLAGS) + +$(OBJDIR)/adddialog.o: adddialog.cpp adddialog.h + $(CXX) -c $< -o $@ $(CXXFLAGS) + + +ifdef COMSPEC +$(OBJDIR)/sample_rc.o: sample.rc + windres -i sample.rc -o $@ -I/local/include/wx-3.0 +endif + +$(EXECUTABLE): $(PROGNAME) +ifdef COMSPEC + strip --strip-all $(EXECUTABLE) + ./$(PROGNAME).exe +else + -mkdir -p $(PROGNAME).app/Contents + -mkdir -p $(PROGNAME).app/Contents/MacOS + -mkdir -p $(PROGNAME).app/Contents/Resources + + sed -e "s/IDENTIFIER/$(PROGNAME)/" \ + -e "s/EXECUTABLE/$(PROGNAME)/" \ + -e "s/VERSION/0.0/" \ + Info.plist.in > $(PROGNAME).app/Contents/Info.plist + + echo -n "APPL????" > $(EXECUTABLE) + + ln -f $(PROGNAME) $(PROGNAME).app/Contents/MacOS/$(PROGNAME) + cp -f wxmac.icns $(PROGNAME).app/Contents/Resources/wxmac.icns + + open $(PROGNAME).app +endif + +clean: + rm -f $(PROGNAME) $(PROGNAME).exe + rm -f $(OBJDIR)/*.o + rm -rf $(PROGNAME).app + +.PHONY: all clean +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/image/sample.xpm Sun Aug 30 21:53:19 2015 +0900 @@ -0,0 +1,92 @@ +/* XPM */ +//static char *sample_xpm[] = { +const char *sample_xpm[] = { +/* columns rows colors chars-per-pixel */ +"32 32 53 1 ", +" c #FAFA00000202", +". c #FEFE00000000", +"X c red", +"o c #F9F900000505", +"O c #F5F500000909", +"+ c #F6F600000808", +"@ c #EBEB00001111", +"# c #DADA00002424", +"$ c #D8D800002626", +"% c #C3C300003B3B", +"& c #C6C600003838", +"* c #C4C400003A3A", +"= c #C1C100003D3D", +"- c #B7B700004747", +"; c #BCBC00004040", +": c #BEBE00004040", +"> c #ABAB00005151", +", c #AAAA00005353", +"< c #ABAB00005353", +"1 c #999900006565", +"2 c #959500006969", +"3 c #5F5F00009F9F", +"4 c #777700008787", +"5 c #737300008B8B", +"6 c #6D6D00009090", +"7 c #616100009D9D", +"8 c #626200009C9C", +"9 c #54540000AAAA", +"0 c #47470000B7B7", +"q c #44440000BABA", +"w c #42420000BCBC", +"e c #2B2B0000D3D3", +"r c #29290000D5D5", +"t c #28280000D6D6", +"y c #25250000D9D9", +"u c #20200000DEDE", +"i c #17170000E7E7", +"p c #1A1A0000E3E3", +"a c #19190000E5E5", +"s c #13130000EBEB", +"d c #14140000EAEA", +"f c #10100000EDED", +"g c #09090000F3F3", +"h c #0D0D0000F1F1", +"j c #0C0C0000F2F2", +"k c #03030000FBFB", +"l c #04040000FAFA", +"z c #01010000FCFC", +"x c #00000000FDFD", +"c c #01010000FDFD", +"v c #00000000FEFE", +"b c blue", +"n c None", +/* pixels */ +"nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn", +"nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn", +"nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn", +"nnnnnnnnnnnn...........nnnnnnnnn", +"nnnnnnnnn.................nnnnnn", +"nnnnnnn....................nnnnn", +"nnnnnn.....................nnnnn", +"nnnnn.....................nnnnnn", +"nnnnn........nnnnnnn......nnnnnn", +"nnnn.......nnnnnnnnnnnn...nnnnnn", +"nnnn.......nnnnnnnnnnnnn..nnnnnn", +"nnnn.......nnnnnnnnnnnnnnnnnnnnn", +"nnnn.........nnnnnnnnnnnnnnnnnnn", +"nnnn............nnnnnnnnnnnnnnnn", +"nnnnn...............nnnnnnnnnnnn", +"nnnnnn................nnnnnnnnnn", +"nnnnnnn................nnnnnnnnn", +"nnnnnnnnnn.<0ibfq<..*4qabbbbbnnn", +"nnnnnnnnnnbbbbbbbb5.bbbbbbbbbbnn", +"nnnnnnnnnnbbbnnnfbb*bb9-@nnbbbbn", +"nnnnnnnnnbbbnnnnnbb7u*...nnnbbbn", +"nn..nnnnnbbbnnnnnbbr.....nnbbbnn", +"nn....nnnbbbnnnnnbbf...bbbbbbnnn", +"nn......nbbbnnnn.bbb...bbbbbbbnn", +"nn.......gbb....Obbf....nnnbbbbn", +"n........ubb$...$bbr...nnnnnbbbn", +"n........3bb1...2bb7u*nnnnnnbbbn", +"nn.......*bba*.*ibb<bbbnnnnbbbbn", +"nnnnnn....6bbbbbbbgnbbbbbbbbbbnn", +"nnnnnnnnnnnnbbbbbnnnnbbbbbbbnnnn", +"nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn", +"nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn" +};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/adddialog.h Sun Aug 30 21:53:19 2015 +0900 @@ -0,0 +1,50 @@ +// Filename: adddialog.h +// Last Change: 2015-08-30 Sun 16:00:48. +// + +#ifndef __ADDDLG_H__ +#define __ADDDLG_H__ + +#include <wx/string.h> +#include <wx/stattext.h> +#include <wx/gdicmn.h> +#include <wx/textctrl.h> +#include <wx/choice.h> +#include <wx/sizer.h> +#include <wx/button.h> +#include <wx/dialog.h> + +class AddDialog : public wxDialog +{ + private: + + protected: + wxStaticText* m_staticText; + + wxStaticText* m_staticTextText; + wxTextCtrl* m_textCtrlText; + wxStaticText* m_staticTextText2; + + wxStaticText* m_staticTextType; + wxChoice* m_choiceType; + wxStaticText* m_staticTextType2; + + wxStaticText* m_staticTextTime; + wxTextCtrl* m_textCtrlTime; + wxStaticText* m_staticTextTime2; + + wxStaticText* m_staticTextDesc; + wxTextCtrl* m_textCtrlDesc; + wxStaticText* m_staticTextDesc2; + + wxButton* m_buttonAdd; + wxButton* m_buttonCancel; + + public: + AddDialog( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Set values"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE ); + ~AddDialog(); + +}; + +#endif //__ADDDLG_H__ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/main.h Sun Aug 30 21:53:19 2015 +0900 @@ -0,0 +1,21 @@ +// Filename : main.h +// Last Change: 2015-08-26 Wed 19:50:46. +// +#include <wx/wx.h> +#include <wx/help.h> + +// private classes +// Define a new application type, each program should derive a class from wxApp +class MyApp : public wxApp +{ + DECLARE_CLASS( MyApp ) +public: + MyApp(); + ~MyApp(); + + virtual bool OnInit(); + virtual int OnExit(); +}; + +DECLARE_APP(MyApp) +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/mainframe.h Sun Aug 30 21:53:19 2015 +0900 @@ -0,0 +1,95 @@ +// Filename: mainframe.h +// Last Change: 2015-08-30 Sun 20:35:50. +// +#ifndef __MAINFRAME_H__ +#define __MAINFRAME_H__ + +#include <wx/listctrl.h> +#include <wx/gdicmn.h> +#include <wx/font.h> +#include <wx/colour.h> +#include <wx/settings.h> +#include <wx/string.h> +#include <wx/stattext.h> +#include <wx/button.h> +#include <wx/tglbtn.h> +#include <wx/sizer.h> +#include <wx/icon.h> +#include <wx/menu.h> +#include <wx/frame.h> +#include <wx/timer.h> + +class MainFrame : public wxFrame +{ + DECLARE_EVENT_TABLE() + private: + wxTimer m_timer; + int m_current; + long m_counter; + wxString m_last; + + protected: + enum + { + ID_MNABOUT = wxID_HIGHEST + 1, + ID_MNEXIT, + ID_MNLDPGIN, + ID_MNSVPGIN, + + ID_TIMER, + ID_TGL, + ID_LIST, + + ID_BTNUP, + ID_BTNDOWN, + ID_BTNDEL, + ID_BTNADD, + ID_EXIT, + }; + + wxMenuBar* m_menubar; + wxMenu* m_menuFile; + wxMenu* m_menuPlugin; + + wxTextCtrl* m_textCtrlShow; + wxToggleButton* m_toggleBtn; + + wxListView* m_listView; + + wxButton* m_buttonUp; + wxButton* m_buttonDown; + wxButton* m_buttonDel; + wxButton* m_buttonAdd; + wxButton* m_buttonExit; + + public: + MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ); + ~MainFrame(); + + // Event Handlers + void OnMNAbout( wxCommandEvent& ); + void OnMNExit( wxCommandEvent& ); + void OnMNLoad( wxCommandEvent& ); + void OnMNSaveAs( wxCommandEvent& ); + + void OnDClickItem( wxListEvent& ); + void OnSelectItem( wxListEvent& ); + + void OnToggle( wxCommandEvent& ); + void OnTimer( wxTimerEvent& ); + + void OnBtnUp( wxCommandEvent& ); + void OnBtnDown( wxCommandEvent& ); + void OnBtnDel( wxCommandEvent& ); + void OnBtnAdd( wxCommandEvent& ); + void OnBtnExit( wxCommandEvent& ); + + // Functions + void EnableButtons( bool ); + void SwapListItem( long, long ); + void ReNumberList(); + void DoProcess(); +}; + +#endif //__MAINFRAME_H__ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/adddialog.cpp Sun Aug 30 21:53:19 2015 +0900 @@ -0,0 +1,86 @@ +// Filename: adddialog.cpp +// Last Change: 2015-08-30 Sun 16:02:17. +// + +#include "adddialog.h" + +AddDialog::AddDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) + : wxDialog( parent, id, title, pos, size, style ) +{ + this->SetSizeHints( wxDefaultSize, wxDefaultSize ); + + wxBoxSizer* bSizerTop = new wxBoxSizer( wxVERTICAL ); + + m_staticText = new wxStaticText( this, wxID_ANY, wxT("Specify Empty text to use User input(Ctrl-c).\nDescription is option."), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerTop->Add( m_staticText, 0, wxALL|wxEXPAND, 10 ); + + wxFlexGridSizer* fgSizer = new wxFlexGridSizer( 0, 3, 0, 0 ); + fgSizer->SetFlexibleDirection( wxBOTH ); + fgSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); + + // text + m_staticTextText = new wxStaticText( this, wxID_ANY, wxT("Text"), wxDefaultPosition, wxDefaultSize, 0 ); + fgSizer->Add( m_staticTextText, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); + + m_textCtrlText = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + fgSizer->Add( m_textCtrlText, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_staticTextText2 = new wxStaticText( this, wxID_ANY, wxT("Strings to paste"), wxDefaultPosition, wxDefaultSize, 0 ); + fgSizer->Add( m_staticTextText2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + // type + m_staticTextType = new wxStaticText( this, wxID_ANY, wxT("Type"), wxDefaultPosition, wxDefaultSize, 0 ); + fgSizer->Add( m_staticTextType, 0, wxALL|wxALIGN_RIGHT, 5 ); + + wxString m_choiceTypeChoices[] = { wxT("a"), wxT("ab"), wxT("cc"), }; + int m_choiceTypeNChoices = sizeof( m_choiceTypeChoices ) / sizeof( wxString ); + m_choiceType = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_choiceTypeNChoices, m_choiceTypeChoices, 0 ); + fgSizer->Add( m_choiceType, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_staticTextType2 = new wxStaticText( this, wxID_ANY, wxT("Ring / Queue / Stack"), wxDefaultPosition, wxDefaultSize, 0 ); + fgSizer->Add( m_staticTextType2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + // time + m_staticTextTime = new wxStaticText( this, wxID_ANY, wxT("Time"), wxDefaultPosition, wxDefaultSize, 0 ); + fgSizer->Add( m_staticTextTime, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); + + m_textCtrlTime = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + fgSizer->Add( m_textCtrlTime, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_staticTextTime2 = new wxStaticText( this, wxID_ANY, wxT("interval"), wxDefaultPosition, wxDefaultSize, 0 ); + fgSizer->Add( m_staticTextTime2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + // desc + m_staticTextDesc = new wxStaticText( this, wxID_ANY, wxT("Desc"), wxDefaultPosition, wxDefaultSize, 0 ); + fgSizer->Add( m_staticTextDesc, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); + + m_textCtrlDesc = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + fgSizer->Add( m_textCtrlDesc, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_staticTextDesc2 = new wxStaticText( this, wxID_ANY, wxT("Description"), wxDefaultPosition, wxDefaultSize, 0 ); + fgSizer->Add( m_staticTextDesc2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + bSizerTop->Add( fgSizer, 1, wxEXPAND, 5 ); + + wxBoxSizer* bSizerBtn = new wxBoxSizer( wxHORIZONTAL ); + + m_buttonAdd = new wxButton( this, wxID_OK, wxT("Add"), wxDefaultPosition, wxDefaultSize, 0 ); + m_buttonAdd->SetDefault(); + bSizerBtn->Add( m_buttonAdd, 0, wxALL, 5 ); + + m_buttonCancel = new wxButton( this, wxID_CANCEL, wxT("Cancel"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerBtn->Add( m_buttonCancel, 0, wxALL, 5 ); + + bSizerTop->Add( bSizerBtn, 0, wxALIGN_RIGHT, 5 ); + + this->SetSizer( bSizerTop ); + this->Layout(); + bSizerTop->Fit( this ); + + this->Centre( wxBOTH ); +} + +AddDialog::~AddDialog() +{ +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main.cpp Sun Aug 30 21:53:19 2015 +0900 @@ -0,0 +1,33 @@ +// Filename : main.cpp +// Last Change: 2015-08-26 Wed 19:51:32. +// +#include "main.h" +#include "mainframe.h" + +IMPLEMENT_APP(MyApp) + +IMPLEMENT_CLASS( MyApp, wxApp ) + +MyApp::MyApp() +{ +} + +MyApp::~MyApp() +{ +} + +bool MyApp::OnInit() +{ + if ( !wxApp::OnInit() ) return false; + + MainFrame *mainframe = new MainFrame( NULL, wxID_ANY, wxT("QlipBoard"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE ); + mainframe->Show( true ); + + return true; +} + +int MyApp::OnExit() +{ + return 0; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/mainframe.cpp Sun Aug 30 21:53:19 2015 +0900 @@ -0,0 +1,352 @@ +// Filename: mainframe.cpp +// Last Change: 2015-08-30 Sun 21:49:16. +// +#include <wx/filedlg.h> +#include <wx/textfile.h> +#include <wx/clipbrd.h> +#include <wx/utils.h> +#include <wx/msgdlg.h> + +#include "mainframe.h" +#include "adddialog.h" + +// resources +#if !defined(__WXMSW__) && !defined(__WXPM__) + #include "sample.xpm" +#endif + +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 ) +{ + this->SetSizeHints( wxDefaultSize, wxDefaultSize ); + this->SetBackgroundColour( wxColour( wxT("WHEAT") ) ); + SetIcon( wxICON( sample ) ); + + // menu bar + m_menubar = new wxMenuBar( 0 ); + m_menuFile = new wxMenu(); + wxMenuItem* m_menuItemAbout = new wxMenuItem( m_menuFile, ID_MNABOUT, wxString( wxT("About") ), wxEmptyString, wxITEM_NORMAL ); + m_menuFile->Append( m_menuItemAbout ); + + wxMenuItem* m_menuItemExit = new wxMenuItem( m_menuFile, ID_MNEXIT, wxString( wxT("Exit") ), wxEmptyString, wxITEM_NORMAL ); + m_menuFile->Append( m_menuItemExit ); + + m_menubar->Append( m_menuFile, wxT("File") ); + + m_menuPlugin = new wxMenu(); + wxMenuItem* m_menuItemLoadPgin = new wxMenuItem( m_menuPlugin, ID_MNLDPGIN, wxString( wxT("Load") ), wxEmptyString, wxITEM_NORMAL ); + m_menuPlugin->Append( m_menuItemLoadPgin ); + + wxMenuItem* m_menuItemSavePgin = new wxMenuItem( m_menuPlugin, ID_MNSVPGIN, wxString( wxT("Save as") ), wxEmptyString, wxITEM_NORMAL ); + m_menuPlugin->Append( m_menuItemSavePgin ); + + m_menubar->Append( m_menuPlugin, wxT("Plugin") ); + + this->SetMenuBar( m_menubar ); + + // controls + wxBoxSizer* bSizerTop = new wxBoxSizer( wxVERTICAL ); + + // + wxBoxSizer* bSizerShow = new wxBoxSizer( wxHORIZONTAL ); + + m_textCtrlShow = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY ); + bSizerShow->Add( m_textCtrlShow, 1, wxALL|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 ); + + m_listView = new wxListView( this, ID_LIST, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL ); + bSizerList->Add( m_listView, 1, wxALL|wxEXPAND, 5 ); + 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 ); + + wxBoxSizer* bSizerBtn = new wxBoxSizer( wxVERTICAL ); + + m_buttonUp = new wxButton( this, ID_BTNUP, wxT("↑"), wxDefaultPosition, wxSize( 40, -1 ), 0 ); + bSizerBtn->Add( m_buttonUp, 0, wxALL, 5 ); + + m_buttonDown = new wxButton( this, ID_BTNDOWN, wxT("↓"), wxDefaultPosition, wxSize( 40, -1 ), 0 ); + bSizerBtn->Add( m_buttonDown, 0, wxALL, 5 ); + + m_buttonDel = new wxButton( this, ID_BTNDEL, wxT("-"), wxDefaultPosition, wxSize( 40, -1 ), 0 ); + bSizerBtn->Add( m_buttonDel, 0, wxALL, 5 ); + + m_buttonAdd = new wxButton( this, ID_BTNADD, wxT("+"), wxDefaultPosition, wxSize( 40, -1 ), 0 ); + bSizerBtn->Add( m_buttonAdd, 0, wxALL, 5 ); + + bSizerBtn->Add( 0, 0, 1, wxEXPAND, 5 ); + + 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 ); + + this->SetSizer( bSizerTop ); + this->Layout(); + + this->Centre( wxBOTH ); +} + +MainFrame::~MainFrame() +{ +} + +// 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_TIMER( ID_TIMER, MainFrame::OnTimer ) + 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_EXIT, MainFrame::OnBtnExit ) + EVT_TOGGLEBUTTON( ID_TGL, MainFrame::OnToggle ) + /* + EVT_IDLE( MainFrame::OnIdle ) + EVT_CLOSE( MainFrame::OnClose ) + */ +END_EVENT_TABLE() + +/* Event Handlers & Functions */ +// Event Handlers +void MainFrame::OnMNAbout( wxCommandEvent& WXUNUSED(event) ) +{ + wxInfoMessageBox( this ); +} + +void MainFrame::OnMNExit( wxCommandEvent& WXUNUSED(event) ) +{ + Close(); +} + +void MainFrame::OnMNLoad( wxCommandEvent& WXUNUSED(event) ) +{ + wxString plugin_dir = wxGetCwd() + wxFILE_SEP_PATH + wxT("plugin"); + wxFileDialog fd( this, wxT("Select Plug-in file"), plugin_dir, wxEmptyString, wxT("Plug-in files (*.qbrd)|*.qbrd"), wxFD_OPEN|wxFD_FILE_MUST_EXIST ); + if ( fd.ShowModal() == wxID_CANCEL ) return; // the user changed idea... + + wxTextFile file; + file.Open( fd.GetPath() ); + m_listView->DeleteAllItems(); + 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] ); + 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 ); +} + +void MainFrame::OnMNSaveAs( wxCommandEvent& WXUNUSED(event) ) +{ + wxString plugin_dir = wxGetCwd() + wxFILE_SEP_PATH + wxT("plugin"); + wxFileDialog fd( this, wxT("Save Plug-in file"), plugin_dir , wxEmptyString, wxT("Plug-in files (*.qbrd)|*.qbrd"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT ); + if ( fd.ShowModal() == wxID_CANCEL ) return; // the user changed idea... + + wxTextFile file( fd.GetPath() ); + if ( file.Exists() ) { + file.Open(); + file.Clear(); + } + else { + file.Create(); + } + for ( int r = 0; r < m_listView->GetItemCount(); r++ ) { + wxArrayString s; + for ( int c = 0; c < m_listView->GetColumnCount(); c++ ) { + s.Add( m_listView->GetItemText( r, c ) ); + } + file.AddLine( wxJoin( s, ',', '\\' ) ); + } + file.Write(); + file.Close(); +} + +void MainFrame::OnDClickItem( wxListEvent& event ) +{ + long i = event.GetIndex(); +} + +void MainFrame::OnSelectItem( wxListEvent& event ) +{ + long i = event.GetIndex(); + m_current = i; +} + +// ↑ +void MainFrame::OnBtnUp( wxCommandEvent& WXUNUSED(event) ) +{ + long item = -1; + item = m_listView->GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); + 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; + 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(); + } +} + +// + +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(); + } + /* + AddDialog adlg( this, wxID_ANY, wxT("a"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE ); + if ( adlg.ShowModal() == wxID_OK ) { + } + */ +} + +void MainFrame::OnTimer( wxTimerEvent& WXUNUSED(event) ) +{ + if ( wxTheClipboard->Open() ) { + + 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; + } + + 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; + + wxString time = m_listView->GetItemText( m_current, 2 ); + time.ToLong( &m_counter, 10 ); + m_timer.StartOnce( (int)m_counter * 1000 ); + + if ( m_current == m_listView->GetItemCount() - 1 ) m_current = 0; + else m_current++; + } +} + +void MainFrame::OnToggle( wxCommandEvent& WXUNUSED(event) ) +{ + if ( m_toggleBtn->GetValue() ) { + m_toggleBtn->SetLabel( wxT("OFF") ); + EnableButtons( false ); + if ( m_listView->GetItemCount() > 0 ) { + m_timer.StartOnce( 1000 ); + } + } + else { + m_timer.Stop(); + m_toggleBtn->SetLabel( wxT("ON") ); + EnableButtons( true ); + } +} + +void MainFrame::OnBtnExit( wxCommandEvent& WXUNUSED(event) ) +{ + Close(); +} + +// Functions +void MainFrame::EnableButtons( bool enable ) +{ + if ( enable ) { + m_buttonUp->Enable( true ); + m_buttonDown->Enable( true ); + m_buttonDel->Enable( true ); + m_buttonAdd->Enable( true ); + } + else { + m_buttonUp->Enable( false ); + m_buttonDown->Enable( false ); + m_buttonDel->Enable( false ); + m_buttonAdd->Enable( false ); + } +} + +void MainFrame::ReNumberList() +{ + for ( int i = 0; i < m_listView->GetItemCount(); i++ ) { + m_listView->SetItem( i, 0, wxString::Format( wxT("%d"), i + 1 ) ); + } +} + +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 ); + } + m_listView->SetItemState( item1, 0, wxLIST_STATE_SELECTED ); + m_listView->SetItemState( item2, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); +} +