00001 00002 // MathGUI = a WYSIWYG equation editor + a powerful math engine // 00003 // Copyright (C) 2003 by Francesco Montorsi // 00004 // // 00005 // This library is free software; you can redistribute it and/or // 00006 // modify it under the terms of the GNU Lesser General Public // 00007 // License as published by the Free Software Foundation; either // 00008 // version 2.1 of the License, or (at your option) any later // 00009 // version. // 00010 // // 00011 // This library is distributed in the hope that it will be useful, // 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 00014 // GNU Lesser General Public License for more details. // 00015 // // 00016 // You should have received a copy of the GNU Lesser General Public // 00017 // License along with this program; if not, write to the Free // 00018 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, // 00019 // MA 02111-1307, USA. // 00020 // // 00021 // For any comment, suggestion or feature request, please contact // 00022 // the administrator of the project at frm@users.sourceforge.net // 00023 // // 00030 00031 00032 00033 // optimization for GCC compiler 00034 #ifdef __GNUG__ 00035 #pragma implementation "SymbolDlg.h" 00036 #endif 00037 00038 // includes 00039 #include "mg/mgprec.h" 00040 00041 #ifndef mgPRECOMP 00042 #include "mg/GUIUtils.h" 00043 #include "mg/SymbolDlg.h" 00044 #include "mg/SymPropPanel.h" 00045 #ifdef mgUSE_PALETTEFRM 00046 #include "wx/palettefrm.h" 00047 #include "wx/minibtn.h" 00048 #endif 00049 #endif 00050 00051 00052 00053 // event table 00054 IMPLEMENT_CLASS(mgSymbolPanel, wxPanel) 00055 BEGIN_EVENT_TABLE(mgSymbolPanel, wxPanel) 00056 00057 // buttons 00058 EVT_BUTTON(IDC_SYMBOLDLG_DELETE, mgSymbolPanel::OnDeleteSymbol) 00059 EVT_NOTEBOOK_PAGE_CHANGED(IDC_SYMBOLDLG_LIST, mgSymbolPanel::OnPageChanged) 00060 00061 END_EVENT_TABLE() 00062 00063 00064 // as base class, we cannot use the wxNotebookPage typedef.... 00065 IMPLEMENT_CLASS(mgSymListPage, wxPanel) 00066 BEGIN_EVENT_TABLE(mgSymListPage, wxPanel) 00067 00068 EVT_LIST_ITEM_SELECTED(IDC_SYMLISTPAGE_LISTCTRL, mgSymListPage::OnSelectionChanged) 00069 00070 END_EVENT_TABLE() 00071 00072 00073 00074 00075 // -------------------------------------------- 00076 // mgSYMBOLPANEL 00077 // -------------------------------------------- 00078 00079 mgSymbolPanel::mgSymbolPanel(wxWindow *parent, mgMathWnd *mathwnd, 00080 mgMathBox *mathbox, mcSymbolArray *arr, 00081 wxWindowID id, const wxString &title, 00082 const wxPoint &position, 00083 const wxSize& size, long style) : 00084 wxPanel(parent, id, position, size, style), 00085 mgMathBoxWndUser(mathwnd, mathbox) 00086 { 00087 // set up the dialog 00088 m_pArray = arr; 00089 BuildAll(); 00090 } 00091 00092 mgSymbolPanel::~mgSymbolPanel() 00093 { 00094 } 00095 00096 00097 void mgSymbolPanel::AddDefaultLists() 00098 { 00099 // create the properties panels 00100 mgSymVarPropPanel *m_pVarPanel = new mgSymVarPropPanel(this, -1); 00101 mgSymConstPropPanel *m_pConstPanel = new mgSymConstPropPanel(this, -1); 00102 m_pVarPanel->BuildAll(); 00103 m_pConstPanel->BuildAll(); 00104 00105 // add to the notebook the pages... 00106 m_pList->AddPage(new mgSymListPage(m_pList, m_pVarPanel, 00107 &mcSymbol::arrUnknowns, -1), wxT("Unknowns"), TRUE); 00108 m_pList->AddPage(new mgSymListPage(m_pList, m_pVarPanel, 00109 &mcSymbol::arrParameters, -1), wxT("Parameters"), TRUE); 00110 m_pList->AddPage(new mgSymListPage(m_pList, m_pConstPanel, 00111 &mcSymbol::arrConstants, -1), wxT("Constants"), TRUE); 00112 00113 // size should have changed... 00114 if (GetSizer()) GetSizer()->Layout(); 00115 } 00116 00117 void mgSymbolPanel::BuildCtrls() 00118 { 00119 // build the main notebook with the lists 00120 m_pList = new wxNotebook(this, IDC_SYMBOLDLG_LIST); 00121 } 00122 00123 void mgSymbolPanel::BuildAll() 00124 { 00125 // first of all, build the main controls of the palette 00126 BuildCtrls(); 00127 00128 // this contains the properties controls 00129 wxStaticBox *sb = new wxStaticBox(this, -1, wxT("Properties")); 00130 m_pPropertySizer = new wxStaticBoxSizer(sb, wxHORIZONTAL); 00131 //m_pPropertySizer->SetMinSize(20, 20); 00132 //m_pPropertySizer->Add(1, 1, 1, wxGROW); // add a dummy spacer... 00133 00134 // this contains the row of buttons placed in the bottom part of the dialog... 00135 wxBoxSizer *buttons = new wxBoxSizer(wxHORIZONTAL); 00136 buttons->Add(new wxButton(this, IDC_SYMBOLDLG_DELETE, 00137 wxT("Delete selected")), 1, /*wxALL |*/ wxGROW, 5); 00138 00139 // this contains both the list notebook and the button sizer 00140 wxBoxSizer *column = new wxBoxSizer(wxVERTICAL); 00141 column->Add(m_pList, 1, wxGROW | wxALL, 5); 00142 column->Add(buttons, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5); 00143 00144 // the notebook control doesn't handle correctly the minimum size... 00145 // force to be big enough 00146 wxSize sz = column->GetMinSize(); 00147 //column->SetMinSize(sz.GetWidth(), sz.GetHeight());//+80); 00148 00149 // this contains everything 00150 wxBoxSizer *main = new wxBoxSizer(wxHORIZONTAL); 00151 00152 main->Add(column, 2, wxGROW); 00153 main->Add(m_pPropertySizer, 2, wxGROW | wxALL, 5); 00154 00155 // ok, just set up everything with one call... 00156 SetSizer(main); 00157 main->SetSizeHints(this); 00158 //GetSizer()->Add(main, 1, wxGROW); 00159 } 00160 00161 void mgSymbolPanel::OnDeleteSymbol(wxCommandEvent &ev) 00162 { 00163 mgLogDebug(wxT("mgSymbolPanel::OnDeleteSymbol()")); 00164 // add the symbol currently typed in the text box in the main mcMathCore 00165 // array which is linked with this class. 00166 //m_pArray->Add(m_pText->GetValue()); 00167 00168 // syncronize the array with the list used by the GUI 00169 //Sync(); 00170 00171 // refresh the window containing the math data which must be updated 00172 /*mgMathBox *p = wxDynamicCast(m_pMathBox, mgMathBox); 00173 if (p) p->UpdateLineBmp(); 00174 m_pMathBox->Refresh();*/ 00175 } 00176 00177 void mgSymbolPanel::Sync() 00178 { 00179 // read the array & update the listctrl 00180 /*m_pList->ClearAll(); 00181 for (int i=0; i < m_pArray->GetCount(); i++) 00182 m_pList->InsertItem(i, m_pArray->GetSymbol(i));*/ 00183 } 00184 00185 void mgSymbolPanel::OnPageChanged(wxNotebookEvent &ev) 00186 { 00187 mgLogDebug(wxT("mgSymbolPanel::OnPageChanged()")); 00188 00189 // change property panel type. 00190 int i = ev.GetOldSelection(); 00191 if (i != -1) { 00192 00193 mgSymListPage *p = (mgSymListPage *)m_pList->GetPage(i); 00194 m_pPropertySizer->Hide(p->GetLinkedPropPanel()); 00195 m_pPropertySizer->Remove(p->GetLinkedPropPanel()); 00196 } 00197 00198 int n = ev.GetSelection(); 00199 mgSymListPage *p = (mgSymListPage *)m_pList->GetPage(n); 00200 m_pPropertySizer->Add(p->GetLinkedPropPanel(), 1, wxGROW); 00201 m_pPropertySizer->Show(p->GetLinkedPropPanel()); 00202 00203 // FIXME: there must be some kind of bug in wxWidgets, when using 00204 // sizers.... 00205 GetSizer()->Layout(); 00206 m_pList->Layout(); 00207 m_pPropertySizer->Layout(); 00208 GetSizer()->SetSizeHints(this); 00209 } 00210 00211 00212 00213 00214 00215 // -------------------------------------------- 00216 // mgSYMLISTPAGE 00217 // -------------------------------------------- 00218 00219 mgSymListPage::mgSymListPage(wxWindow *parent, 00220 mgSymPropPanel *prop, 00221 mcSymbolArray *array, 00222 wxWindowID id, 00223 const wxString &title, 00224 const wxPoint& pos, 00225 const wxSize& size, 00226 long style) : 00227 wxPanel(parent, id, pos, size, style) 00228 { 00229 00230 // be sure the links are okay 00231 m_pPropPanel = prop; 00232 m_pArray = array; 00233 00234 BuildAll(); 00235 } 00236 00237 00238 void mgSymListPage::BuildCtrls() 00239 { 00240 m_pList = new wxListCtrl(this, IDC_SYMLISTPAGE_LISTCTRL, wxDefaultPosition, 00241 wxDefaultSize, wxLC_LIST | wxLC_SINGLE_SEL | //wxLC_VIRTUAL | 00242 wxSUNKEN_BORDER | wxLC_EDIT_LABELS); 00243 00244 for (int i=0; i < m_pArray->data_GetCount(); i++) 00245 m_pList->InsertItem(i, m_pArray->data_GetSymbolName(i)); 00246 } 00247 00248 void mgSymListPage::BuildAll() 00249 { 00250 wxBoxSizer *main = new wxBoxSizer(wxVERTICAL); 00251 00252 BuildCtrls(); 00253 //m_pList = new wxButton(this, -1, "ciao"); 00254 main->Add(new wxStaticText(this, -1, wxT("Symbol list:")), 0, wxGROW | wxLEFT | wxTOP, 5); 00255 main->Add(m_pList, 1, wxGROW | wxALL, 5); 00256 00257 SetSizer(main); 00258 main->SetSizeHints(this); 00259 } 00260 00261 void mgSymListPage::OnSelectionChanged(wxListEvent &ev) 00262 { 00263 m_pPropPanel->LinkWithList(m_pList); 00264 m_pPropPanel->LinkWithSymbol(m_pArray->data_GetSymbol(ev.GetIndex())); 00265 } 00266 00267 00268 00269 00270 // -------------------------------------------- 00271 // mgSYMBOLPALETTE 00272 // -------------------------------------------- 00273 00274 mgSymbolPalette::mgSymbolPalette( 00275 wxMainFrame *parent, wxWindow *client, mgMathWnd *mathwnd, 00276 mgMathBox *mathbox, mcSymbolArray *arr, wxWindowID id, 00277 const wxString &title, const wxPoint &pos, const wxSize &size, 00278 long style, const wxString &name) 00279 : wxPaletteFrame(parent, id, title, pos, size, style, name) 00280 { 00281 // build everything... 00282 //wxWindow *clientwnd = client ? client : parent; 00283 00284 #ifdef mgUSE_PALETTEFRM 00285 SetClient(new mgSymbolPanel(this, mathwnd, mathbox, arr)); 00286 AddMiniButton(new wxCollapseBox(this)); 00287 SetSizeHintsUsingClientHints(); 00288 #else 00289 m_pPanel = new mgSymbolPanel(this, mathwnd, mathbox, arr); 00290 SetSize(330, 220); // an arbitrary size 00291 Update(); 00292 SendSizeEvent(); 00293 #endif 00294 } 00295 00296 mgSymbolPanel *mgSymbolPalette::GetPanel() 00297 { 00298 #ifdef mgUSE_PALETTEFRM 00299 return (mgSymbolPanel*)GetClient(); 00300 #else 00301 return (mgSymbolPanel*)m_pPanel; 00302 #endif 00303 }
[ Top ] |