Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

SymPropPanel.cpp

Go to the documentation of this file.
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 "SymPropPanel.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 #endif
00046 
00047 
00048 
00049 // event table
00050 IMPLEMENT_CLASS(mgSymPropPanel, wxPanel)
00051 BEGIN_EVENT_TABLE(mgSymPropPanel, wxPanel)
00052 
00053    // buttons
00054    EVT_BUTTON(IDC_SYMPROP_ADD, mgSymPropPanel::OnAddSymbolBtn)
00055    EVT_BUTTON(IDC_SYMPROP_SET, mgSymPropPanel::OnSetSymbolBtn)
00056 END_EVENT_TABLE()
00057 
00058 
00059 IMPLEMENT_CLASS(mgSymVarPropPanel, mgSymPropPanel)
00060 BEGIN_EVENT_TABLE(mgSymVarPropPanel, mgSymPropPanel)
00061 END_EVENT_TABLE()
00062 
00063 IMPLEMENT_CLASS(mgSymConstPropPanel, mgSymPropPanel)
00064 BEGIN_EVENT_TABLE(mgSymConstPropPanel, mgSymPropPanel)
00065 END_EVENT_TABLE()
00066 
00067 
00068 
00069 
00070 
00071 
00072 // --------------------------------------------
00073 // mgSYMPROPPANEL
00074 // --------------------------------------------
00075 
00076 mgSymPropPanel::mgSymPropPanel(wxWindow *parent,
00077       wxWindowID id, 
00078       const wxString &title,
00079       const wxPoint& pos,
00080       const wxSize& size,
00081       long style) :
00082       wxPanel(parent, id, pos, size, style)
00083 {
00084    m_pList = NULL;
00085    //BuildAll();
00086 }
00087       
00088 mgSymPropPanel::~mgSymPropPanel()
00089 {
00090    // delete the filter
00091    mcSAFE_DELETE(mdata_pFilter);
00092 }
00093 
00094 void mgSymPropPanel::BuildCtrls()
00095 {
00096    m_pNameBox = new mgMathBox(this, -1);
00097 
00098    m_pNameBox->DisableContextMenu();
00099    m_pNameBox->SetStyleArray(mcMathMngHelpers::sgui_pSmallStyles);
00100    m_pNameBox->DisableSelection();
00101    m_pNameBox->SetSizeHintsToFitContents();
00102 
00103    // set up the filter for the 
00104    mdata_pFilter = new mcFilter(mcFILTER_INCLUDE_ELEMENT_LIST, mcET_SYMBOL, 1);
00105    mdata_pFilter->SetMaxInstancesFor(mcET_MONOMIAL, 1);
00106    m_pNameBox->GetMathObj().data_SetFilter(mdata_pFilter);
00107 }
00108 
00109 void mgSymPropPanel::BuildAll()
00110 {
00111    wxBoxSizer *main = new wxBoxSizer(wxVERTICAL);
00112 
00113    // first build the controls
00114    BuildCtrls();
00115 
00116    // set up the field which allows the
00117    wxBoxSizer *name = new wxBoxSizer(wxHORIZONTAL);
00118    name->Add(new wxStaticText(this, -1, wxT("Symbol:")), 0, wxALIGN_CENTER | wxALL, 5);
00119    name->Add(m_pNameBox, 1, wxGROW | wxALL, 5);
00120    
00121    // call the derived class own method
00122    main->Add(name, 1, wxGROW);
00123    AddSpecificCtrlsSizer(main);
00124 
00125    // then, add the buttons
00126    wxBoxSizer *btn = new wxBoxSizer(wxHORIZONTAL);
00127    btn->Add(new wxButton(this, IDC_SYMPROP_SET, wxT("Save")), 
00128       1, wxALL, 5);
00129    btn->Add(new wxButton(this, IDC_SYMPROP_ADD, wxT("Add as new")), 
00130       1, wxRIGHT | wxTOP | wxBOTTOM, 5);
00131    main->Add(btn, 0, wxGROW);    // don't let the buttons steal precious space
00132 
00133    SetSizer(main);
00134    main->SetSizeHints(this);
00135 }
00136 
00137 void mgSymPropPanel::OnAddSymbolBtn(wxCommandEvent &ev)
00138 {
00139    mgLogDebug(wxT("mgSymPropPanel::OnAddSymbol()"));
00140 
00141    // call the derived class function
00142    OnAddSymbol();
00143 }
00144 
00145 void mgSymPropPanel::OnSetSymbolBtn(wxCommandEvent &ev)
00146 {
00147    mgLogDebug(wxT("mgSymPropPanel::OnSetSymbol()"));
00148 
00149    // call the derived class function
00150    OnSetSymbol();
00151 }
00152 
00153 void mgSymPropPanel::LinkWithSymbol(mcSymbolProperties *s)
00154 {
00155    // change internal pointer...
00156    m_pSymbol = s;
00157 
00158    // ... and update property panel
00159    Update();
00160 }
00161 
00162 void mgSymPropPanel::LinkWithList(wxListCtrl *p)
00163 {
00164    m_pList = p;
00165 
00166    // we don't need to update anything...
00167 }
00168 
00169 void mgSymPropPanel::Update()
00170 {
00171    wxKeyEvent ev(wxEVT_CHAR);
00172    ev.m_keyCode = m_pSymbol->m_strSymbol.GetChar(0);
00173    
00174    // sync the symbol name
00175    m_pNameBox->Clean();
00176 
00177    // these two need to be reset...
00178    m_pNameBox->GetMathObj().data_SetFilter(mdata_pFilter);
00179    m_pNameBox->SetStyleArray(mcMathMngHelpers::sgui_pSmallStyles);
00180 
00181    if (m_pSymbol->m_fEncoding != wxFONTENCODING_DEFAULT)
00182       m_pNameBox->OnSpecialChar(ev);
00183    else
00184       m_pNameBox->OnChar(ev);
00185 }
00186 
00187 wxString mgSymPropPanel::GetName()
00188 {
00189    return m_pNameBox->GetInlinedExpr();
00190 }
00191 
00192 
00193 
00194 
00195 // --------------------------------------------
00196 // mgSYMVARPROPPANEL
00197 // --------------------------------------------
00198 
00199 void mgSymVarPropPanel::AddSpecificCtrlsSizer(wxSizer *p)
00200 {
00201    // add the "range" edit box
00202    m_pRangeBox = new mgMathBox(this, -1);
00203    p->Add(new wxStaticText(this, -1, wxT("Domain:")), 0, wxGROW | wxALL, 5);
00204    p->Add(m_pRangeBox, 1, wxGROW | wxALL, 5);
00205 }
00206 
00207 void mgSymVarPropPanel::OnAddSymbol()
00208 {
00209 }
00210 
00211 void mgSymVarPropPanel::OnSetSymbol()
00212 {
00213 }
00214 
00215 
00216 
00217 
00218 // --------------------------------------------
00219 // mgSYMCONSTPROPPANEL
00220 // --------------------------------------------
00221 
00222 void mgSymConstPropPanel::AddSpecificCtrlsSizer(wxSizer *p)
00223 {
00224    // the wxFILTER_NUMERIC flag allows only digits + wxT(".") and "," to be typed
00225    // into the window: exactly what we want...
00226    wxTextValidator tv(wxFILTER_NUMERIC, &m_strValue);
00227 
00228    m_pValue = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, 
00229       wxDefaultSize, wxTE_CENTRE, tv);
00230    m_pValue->SetMaxLength(SYMCONSTPROP_MAX_VALUE_LENGHT);      // set max # of digits
00231 
00232    // add to the sizer the text ctrl + a little description
00233    p->Add(new wxStaticText(this, -1, wxT("Value:")), 0, wxGROW | wxALL, 5);
00234    p->Add(m_pValue, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5);
00235 }
00236 
00237 void mgSymConstPropPanel::Update()
00238 {
00239    // print the value with 10 decimal digits of precision
00240    wxString fmt = wxString::Format(wxT("%%.%df"), SYMCONSTPROP_MAX_VALUE_LENGHT);
00241    wxString str = wxString::Format(fmt, m_pSymbol->m_fValue.GetSmartStr().c_str());
00242    m_pValue->SetValue(str.Left(SYMCONSTPROP_MAX_VALUE_LENGHT));
00243 
00244    // update the remaining fields...
00245    mgSymPropPanel::Update();
00246 }
00247 
00248 void mgSymConstPropPanel::OnAddSymbol()
00249 {
00250    if (m_pList == NULL)
00251       return;
00252 
00253    m_pList->InsertItem(m_pList->GetItemCount(), GetName());
00254 }
00255 
00256 void mgSymConstPropPanel::OnSetSymbol()
00257 {
00258    double tmp;
00259    m_pValue->GetValue().ToDouble(&tmp);
00260 
00261    // save the value of the textctrl in the symbol...
00262    m_pSymbol->m_fValue = tmp;
00263 }
00264 
00265 
00266 


Documentation generated with Doxygen on Sun Feb 6 17:19:26 2005
Visit MathStudio home page for more info

[ Top ]