FFL
1.0
Finfly Foundation Library
|
00001 /* $Id: table.h 2940 2013-04-01 13:55:58Z roma $ */ 00002 #ifndef __FFL_WX_TABLE__ 00003 #define __FFL_WX_TABLE__ 00004 00005 #include <wx/panel.h> 00006 #include <wx/dialog.h> 00007 #include <wx/grid.h> 00008 #include <wx/toolbar.h> 00009 #include <wx/statusbr.h> 00010 00011 #include <co.h> 00012 00013 #include <vector> 00014 #include <list> 00015 00016 #include "xpm.h" 00017 00018 namespace ffl 00019 { 00020 00021 namespace wx 00022 { 00023 00025 class table:public wxPanel 00026 { 00027 public: 00028 00030 class command:public wxObject 00031 { 00032 public: 00033 00045 command(table& _t, int _group) throw(...); 00046 00050 virtual wxString label() const throw() = 0; 00051 00055 virtual wxString help() const throw() = 0; 00056 00060 virtual wxBitmap image() const throw() = 0; 00061 00063 virtual void execute() throw() = 0; 00064 00065 const int Id; 00066 00067 const int Group; 00068 00069 protected: 00070 00071 table& Table; 00072 00073 }; 00074 00076 typedef std::vector<command*> menu; 00077 00079 class command_alter_table:public command 00080 { 00081 public: 00082 00089 command_alter_table(table& _t, int _group) throw(...):command(_t, _group) 00090 { 00091 } 00092 00096 wxString label() const throw(){return "&Изменить структуру таблицы";} 00097 00101 wxString help() const throw(){return "Изменить структуру таблицы.";} 00102 00106 wxBitmap image() const throw(){return wxBitmap(XPM_data_table);} 00107 00109 void execute() throw(){Table.alter();} 00110 00111 }; 00112 00114 class command_save_table:public command 00115 { 00116 public: 00117 00124 command_save_table(table& _t, int _group) throw(...):command(_t, _group){} 00125 00129 wxString label() const throw(){return "&Сохранить таблицу";} 00130 00134 wxString help() const throw(){return "Сохранить структуру и данные таблицы в файл.";} 00135 00139 wxBitmap image() const throw(){return wxBitmap(XPM_table_save);} 00140 00142 void execute() throw(); 00143 00144 }; 00145 00147 class command_open_table:public command 00148 { 00149 public: 00150 00157 command_open_table(table& _t, int _group) throw(...):command(_t, _group){} 00158 00162 wxString label() const throw(){return "&Открыть таблицу";} 00163 00167 wxString help() const throw(){return "Открыть файл с таблицей.";} 00168 00172 wxBitmap image() const throw(){return wxBitmap(XPM_folder_table);} 00173 00175 void execute() throw(); 00176 00177 }; 00178 00180 class command_edit_profile:public command 00181 { 00182 public: 00183 00190 command_edit_profile(table& _t, int _group) throw(...):command(_t, _group){} 00191 00195 wxString label() const throw(){return "&Редактировать профиль";} 00196 00200 wxString help() const throw(){return "Редактировать настройки табличного редактора.";} 00201 00205 wxBitmap image() const throw(){return wxBitmap(XPM_cog_edit);} 00206 00208 void execute() throw(){profile(Table).edit(&Table);} 00209 00210 00211 }; 00212 00220 class lock 00221 { 00222 public: 00223 00228 lock(table& _t, bool _f) throw(); 00229 00231 virtual ~lock() throw(); 00232 00233 protected: 00234 00235 table& Table; 00236 00237 const bool Flip; 00238 00239 }; 00240 00241 friend class lock; 00242 00244 class profile:public lock 00245 { 00246 public: 00247 00251 profile(table& _t) throw():lock(_t, false){} 00252 00254 ~profile() throw(); 00255 00260 bool edit(wxWindow* _parent) throw(); 00261 00265 void show(wxWindow* _parent) throw(); 00266 00270 void set_toolbar(bool _f) throw(); 00271 00275 bool get_toolbar() throw(); 00276 00280 void set_statusbar(bool _f) throw(); 00281 00285 bool get_statusbar() throw(); 00286 00290 void set_drag_column_move(bool _f) throw(); 00291 00295 bool get_drag_column_move() throw(); 00296 00297 menu Menu; 00298 00299 private: 00300 00302 class dialog:public wxDialog 00303 { 00304 public: 00305 00309 dialog(ffl::wx::table::profile& _profile, wxWindow* _parent, bool _edit = true) throw(); 00310 00311 private: 00312 00313 profile& Profile; //<! Профиль таблицы. 00314 00315 wxCheckBox* HasToolBar; 00316 00317 wxCheckBox* HasStatusBar; 00318 00319 wxCheckBox* EnableDragColumn; 00320 00321 DECLARE_EVENT_TABLE() 00322 00323 void on_ok(wxCommandEvent& _e) throw(); 00324 00325 }; 00326 00327 00328 }; 00329 00331 class format:public lock 00332 { 00333 }; 00334 00341 class designer:public wxDialog 00342 { 00343 public: 00344 00356 designer(co_table& _t, wxWindow* _parent, wxWindowID _id = wxID_ANY, const wxString& _title = wxString("Структура таблицы"), const wxPoint& _pos = wxDefaultPosition, const wxSize& _size = wxDefaultSize, long _style = wxDEFAULT_DIALOG_STYLE, const wxString& _name = "ffl::wx::table::designer") throw(); 00357 00358 private: 00359 00361 class header:public wxGrid 00362 { 00363 public: 00364 00375 header(int _n, const co_column* _c, wxWindow* _parent, wxWindowID _Id = wxID_ANY, const wxPoint& _pos = wxDefaultPosition, const wxSize& _size = wxSize(-1, 200), long _style = wxWANTS_CHARS, const wxString& _name = "ffl::wx::table::designer::header") throw(); 00376 00381 void describe(co_table& _t, int _occurs = 1) throw(); 00382 00383 private: 00384 00386 enum 00387 { 00388 JNAME = 0, 00389 JDOMAIN, 00390 JWIDTH, 00391 JINF = JNAME, 00392 JSUP = JWIDTH 00393 }; 00394 00396 class storage:public wxGridTableBase 00397 { 00398 public: 00399 00405 storage(int _n, const co_column* _c) throw(...); 00406 00415 void describe(co_table& _t, int _occurs) throw(); 00416 00420 int GetNumberRows() throw(); 00421 00425 int GetNumberCols() throw() 00426 { 00427 return JSUP - JINF + 1; 00428 } 00429 00435 bool IsEmptyCell(int _i, int _j) throw(); 00436 00442 wxString GetValue(int _i, int _j) throw(); 00443 00449 long GetValueAsLong(int _i, int _j) throw(); 00450 00456 void SetValueAsLong(int _i, int _j, long _v) throw(); 00457 00463 void SetValue(int _i, int _j, const wxString& _v) throw(); 00464 00469 wxString GetRowLabelValue(int _i) throw(); 00470 00475 wxString GetColLabelValue(int _j) throw(); 00476 00483 bool CanGetValueAs(int _i, int _j, const wxString& _type) throw(); 00484 00485 private: 00486 00488 struct column 00489 { 00490 wxString Name; 00491 co_domain Domain; 00492 size_t Width; 00493 }; 00494 00496 std::vector<column> Header; 00497 00499 class attribute:public wxGridCellAttrProvider 00500 { 00501 public: 00502 00509 attribute(const std::vector<column>& _h) throw(); 00510 00512 ~attribute(); 00513 00525 wxGridCellAttr* GetAttr(int _i, int _j, wxGridCellAttr::wxAttrKind _k) const throw(); 00526 00527 private: 00528 00530 const std::vector<column>& Header; 00531 00532 wxGridCellAttr* Name; 00533 wxGridCellAttr* Type; 00534 wxGridCellAttr* Size; 00535 wxGridCellAttr* DefSize; 00536 00537 }; 00538 00539 }; 00540 00541 }; 00542 00543 co_table& Table; 00544 00545 header* Header; 00546 00547 DECLARE_EVENT_TABLE() 00548 00549 00552 void on_ok(wxCommandEvent& _e) throw(); 00553 00554 }; 00555 00570 table 00571 ( 00572 wxWindow* _parent, 00573 wxWindowID _id = wxID_ANY, 00574 int _start_menu_id = wxID_HIGHEST + 1, 00575 const wxPoint& _pos = wxDefaultPosition, 00576 const wxSize& _size = wxDefaultSize, 00577 long _style = wxTAB_TRAVERSAL, 00578 const wxString& _name = "ffl::wx::table" 00579 ) throw(); 00580 00591 table(int _start_menu_id = wxID_HIGHEST + 1) throw():StartMenuId(_start_menu_id){} 00592 00596 void set(const co_table& _t) throw(); 00597 00601 void get(co_table& _t) throw(); 00602 00609 void alter(int _occurs = 1) throw(){Grid->alter(_occurs);} 00610 00615 void save(const wxString& _file) throw(...){Grid->save(_file);} 00616 00621 wxString save() throw(...); 00622 00627 void open(const wxString& _file) throw(...){Grid->open(_file);} 00628 00632 void open() throw(...); 00633 00634 private: 00635 00642 void on_create(wxWindowCreateEvent& _e) throw(); 00643 00650 void on_command(wxCommandEvent& _e) throw(); 00651 00653 class toolbar:public wxToolBar 00654 { 00655 public: 00656 00666 toolbar(wxWindow* _parent, const std::vector<command*>& _menu) throw(); 00667 00668 private: 00669 00673 void add(const command& _c) throw(); 00674 00675 } *ToolBar; 00676 00678 class statusbar:public wxStatusBar 00679 { 00680 public: 00681 00688 statusbar(wxWindow* _parent, wxWindowID _id = wxID_ANY, long _style = wxST_SIZEGRIP, const wxString& _name = "ffl::wx::table::statusbar") throw():wxStatusBar(_parent, _id, _style, _name) 00689 { 00690 } 00691 00692 } *StatusBar; 00693 00695 class storage:public co_table, public wxGridTableBase 00696 { 00697 public: 00698 00702 int GetNumberRows() throw() 00703 { 00704 return getnrows(); 00705 } 00706 00710 int GetNumberCols() throw() 00711 { 00712 int n; 00713 describe(&n); 00714 return n; 00715 } 00716 00722 bool IsEmptyCell(int _i, int _j) throw() 00723 { 00724 int n; 00725 describe(&n); 00726 if(_i < getnrows() && _j < n) 00727 return getflag(_i, _j) == 0; 00728 return true; 00729 } 00730 00736 wxString GetValue(int _i, int _j) throw() 00737 { 00738 int n; 00739 describe(&n); 00740 if(_i < getnrows() && _j < n) 00741 return wxString(getstring(_i, _j)); 00742 else 00743 return wxEmptyString; 00744 } 00745 00751 void SetValue(int _i, int _j, const wxString& _v) throw() 00752 { 00753 int n; 00754 describe(&n); 00755 if(_i < getnrows() && _j < n) 00756 setstring(_i, _j, _v.c_str()); 00757 } 00758 00762 void set(const co_table& _t) throw(); 00763 00768 void get(co_table& _t) throw(); 00769 00776 void alter(int _occurs = 1) throw(); 00777 00782 void save(const wxString& _file) throw(...); 00783 00788 void open(const wxString& _file) throw(...); 00789 00790 private: 00791 00792 }; 00793 00795 class grid:public wxGrid 00796 { 00797 public: 00798 00807 grid(wxWindow* _parent, wxWindowID _id = wxID_ANY, const wxPoint& _pos = wxDefaultPosition, const wxSize& _size = wxDefaultSize, long _style = wxWANTS_CHARS, const wxString& _name = "ffl::wx::table::grid") throw(...):wxGrid(_parent, _id, _pos, _size, _style, _name) 00808 { 00809 SetTable(new storage(), true); 00810 } 00811 00818 void alter(int _occurs = 1) throw() 00819 { 00820 ((storage*)GetTable())->alter(_occurs); 00821 } 00822 00827 void save(const wxString& _file) throw(...){((storage*)GetTable())->save(_file);} 00828 00833 void open(const wxString& _file) throw(...){((storage*)GetTable())->open(_file);} 00834 00836 class batch 00837 { 00838 public: 00839 00843 batch(wxGrid* _g) throw():Grid(_g) 00844 { 00845 Grid->BeginBatch(); 00846 } 00847 00849 virtual ~batch() throw() 00850 { 00851 Grid->EndBatch(); 00852 } 00853 00854 protected: 00855 00856 wxGrid* Grid; 00857 00858 }; 00859 00866 class batch_and_refresh:public batch 00867 { 00868 public: 00869 00873 batch_and_refresh(wxGrid* _g) throw(); 00874 00876 ~batch_and_refresh() throw(); 00877 00878 private: 00879 00880 wxGridTableBase* Storage; 00881 00882 }; 00883 00884 } *Grid; 00885 00897 std::vector<command*> Menu; 00898 00905 const int StartMenuId; 00906 00907 DECLARE_EVENT_TABLE(); 00908 00909 }; 00910 00911 } 00912 00913 } 00914 00915 #endif