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 #if defined(__GNUG__) && !defined(__APPLE__) 00035 #pragma implementation "OptFontSettingsPanel.h" 00036 #endif 00037 00038 // includes 00039 #include "mg/mgprec.h" 00040 #include <wx/statline.h> // not included in wxprec.h 00041 00042 #ifndef mgPRECOMP 00043 #include "mc/MathCore.h" 00044 #include "mg/OptDlg.h" 00045 #include "mg/OptFontSettings.h" 00046 #include "mg/MathBox.h" 00047 #include <wx/clrbtn.h> 00048 #endif 00049 00050 00051 00052 // setup static vars 00053 // WARNING: this list must be changed if the mcStyle::GetIndexFor() function 00054 // changes.... 00055 wxString mgOptFontSettingsPanel::m_strSettingsLabel[] = { 00056 wxT("Operators"), wxT("Numbers"), wxT("Functions"), 00057 wxT("Subscripts"), wxT("Symbols"), wxT("Specials") 00058 }; 00059 00060 00061 00062 00063 // event table 00064 IMPLEMENT_DYNAMIC_CLASS(mgOptFontSettingsPanel, mgOptBasePanel ) 00065 BEGIN_EVENT_TABLE(mgOptFontSettingsPanel, mgOptBasePanel ) 00066 00067 EVT_CHOICE(OPTIONSDLG_FONTPANEL_EXPDEPTH, mgOptFontSettingsPanel::OnExpDepthChange) 00068 00069 #if wxCHECK_VERSION(2, 5, 0) 00070 EVT_ACTIVE_ELEM_CHANGED(OPTIONSDLG_FONTPANEL_PREVIEWBOX, mgOptFontSettingsPanel::OnActiveElemChange) 00071 #endif 00072 00073 END_EVENT_TABLE() 00074 00075 00076 00077 00078 // -------------------------------------------- 00079 // mgOPTFONTSETTINGSPANEL 00080 // -------------------------------------------- 00081 00082 mgOptFontSettingsPanel::mgOptFontSettingsPanel() 00083 { 00084 m_pFontFaces = NULL; 00085 00086 00087 // using the following array, we make this panel easily updateable: 00088 // to add/delete a mcTextSettings row in the panel, only the following 00089 // array and the #GetSettingsFromBaseID function must be modified... 00090 00091 int i; 00092 for (i=0; i < OPTIONSDLG_FONTPANEL_NUMSETTINGS; i++) 00093 m_nBaseID[i] = OPTIONSDLG_FONTPANEL_SETTINGBASEID+ 00094 OPTIONSDLG_FONTPANEL_SETTING_IDOFFSET*i; 00095 } 00096 00097 mgOptFontSettingsPanel::~mgOptFontSettingsPanel() 00098 { 00099 mgSAFE_DELETE_ARRAY(m_pFontFaces); 00100 } 00101 00102 const mcTextSettings &mgOptFontSettingsPanel::GetSettingsFromBaseID(const mcStyle *p, int id) 00103 { 00104 // search which ID matches which font panel 00105 for (int i=0; i < OPTIONSDLG_FONTPANEL_NUMSETTINGS; i++) 00106 if (id == m_nBaseID[i]) 00107 return *p->GetTextSettings(i); 00108 00109 mcASSERT(0, wxT("No text settings tied to the given ID...")); 00110 00111 // just to make compiler happy 00112 return *p->GetTextSettings(0); 00113 } 00114 00115 const mcTextSettings &mgOptFontSettingsPanel::GetSettingsFromBaseID(int expdepth, int id) 00116 { 00117 const mcStyle *p = m_pPreviewBox->GetMathObj().gui_GetStyle(expdepth); 00118 return GetSettingsFromBaseID(p, id); 00119 } 00120 00121 00122 00123 00124 void mgOptFontSettingsPanel::BuildCtrls() 00125 { 00126 // prepare the array of choices 00127 int n = mcELEMENTMATH_MAX_EXPDEPTH; 00128 wxString *arrstr = new wxString[n]; 00129 for (int i=0; i < n; i++) 00130 arrstr[i] = wxString::Format(wxT("%d"), i); 00131 00132 // build the exp-depth choice control 00133 m_pExpDepthChoice = new wxChoice(this, OPTIONSDLG_FONTPANEL_EXPDEPTH, 00134 wxDefaultPosition, wxDefaultSize, n, arrstr); 00135 00136 // create the preview window, initializing it with some simple math, 00137 // which just show as many font-settings as possible... 00138 m_pPreviewBox = new mgMathBox(this, OPTIONSDLG_FONTPANEL_PREVIEWBOX); 00139 m_pPreviewBox->ImportInlinedExpr(wxT("123ab^2x^4+sin(x_1)>0")); 00140 m_pPreviewBox->ResetGUI(); 00141 m_pPreviewBox->FitContents(); 00142 m_pPreviewBox->DisableInput(); 00143 m_pPreviewBox->DisableSelection(); 00144 m_pPreviewBox->DisableContextMenu(); 00145 00146 // cleanup 00147 delete [] arrstr; 00148 } 00149 00150 void mgOptFontSettingsPanel::BuildFontSettings(wxFlexGridSizer *table, const wxString &label, int id) 00151 { 00152 // create the label for this row in the sizer 00153 table->Add(new wxStaticText(this, -1, label, wxDefaultPosition, 00154 wxDefaultSize, wxALIGN_CENTRE), 1, wxALL | wxALIGN_CENTER_VERTICAL, 5); 00155 00156 // create, with right ids, the various controls 00157 wxComboBox *cb = new wxComboBox(this, id+OPTIONSDLG_FONTPANEL_FONTFACE_IDOFFSET, 00158 wxEmptyString, wxDefaultPosition, wxDefaultSize, m_fntEnumerator.GetCount(), 00159 m_pFontFaces, wxCB_READONLY); 00160 table->Add(cb, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5); 00161 00162 wxTextCtrl *tc = new wxTextCtrl(this, id+OPTIONSDLG_FONTPANEL_FONTSIZE_IDOFFSET, 00163 wxEmptyString, wxDefaultPosition, wxSize(40, -1), wxTE_CENTRE); 00164 table->Add(tc, 1, wxALL | wxALIGN_CENTER, 5); 00165 00166 table->Add(new wxColourButton(this, id+OPTIONSDLG_FONTPANEL_FGCOL_IDOFFSET, 00167 wxColour(0, 0, 0)), 1, wxGROW | wxALL, 5); 00168 00169 table->Add(new wxColourButton(this, id+OPTIONSDLG_FONTPANEL_BKCOL_IDOFFSET, 00170 wxColour(255, 255, 255)), 1, wxGROW | wxALL, 5); 00171 } 00172 00173 void mgOptFontSettingsPanel::Setup( const wxString &itemLabel ) 00174 { 00175 int i, max; 00176 00177 // build all controls 00178 BuildCtrls(); 00179 00180 // creates a static box equal to the panel that will be associated with 00181 // the static box sizer object 00182 wxStaticBox *sb = new wxStaticBox( this, -1, itemLabel, wxDefaultPosition, 00183 wxDefaultSize, wxTHICK_FRAME ); 00184 00185 // creates a wxStaticBoxSizer object that will be bounded with 00186 // the main static box 00187 wxStaticBoxSizer *mainSizer = new wxStaticBoxSizer(sb, wxVERTICAL); 00188 00189 // create the exponent depth list box and its description 00190 wxBoxSizer *expdepth = new wxBoxSizer(wxHORIZONTAL); 00191 expdepth->Add(new wxStaticText(this, -1, wxT("Show font settings for exponent depth:")), 00192 0, wxALL | wxALIGN_CENTER, 5); 00193 expdepth->Add(m_pExpDepthChoice, 0, wxGROW | wxALL | wxALIGN_CENTER, 5); 00194 00195 wxBoxSizer *tmp = new wxBoxSizer(wxVERTICAL); 00196 tmp->Add(new wxStaticText(this, -1, wxT("Each exponent level has some ") 00197 wxT("font settings associated with it; through this panel, \n") 00198 wxT("you can modify each of them and immediately see the ") 00199 wxT("results in the preview window.\n\n") 00200 wxT("If you move the mouse over the preview window, the exponent ") 00201 wxT("depth will be changed\nto reflect the exponent depth of the ") 00202 wxT("element under the mouse cursor.")), 0, wxALL, 5); 00203 tmp->Add(expdepth, 1, wxGROW); 00204 00205 // create the table containing all the settings... it must have 00206 // five columns: label + font face + font size + fg col + bk col 00207 wxFlexGridSizer *table = new wxFlexGridSizer(5); 00208 table->Add(5, 5, 1, wxGROW | wxRIGHT); 00209 table->Add(new wxStaticText(this, -1, wxT("Font face"), 00210 wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE), 1, 00211 wxGROW | wxLEFT | wxRIGHT, 10); 00212 table->Add(new wxStaticText(this, -1, wxT("Font size"), 00213 wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE), 1, 00214 wxGROW | wxLEFT | wxRIGHT, 10); 00215 table->Add(new wxStaticText(this, -1, wxT("Foreground color"), 00216 wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE), 1, 00217 wxGROW | wxLEFT | wxRIGHT, 10); 00218 table->Add(new wxStaticText(this, -1, wxT("Background color"), 00219 wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE), 1, 00220 wxGROW | wxLEFT | wxRIGHT, 10); 00221 00222 // add all font settings sizers "rows".... 00223 m_fntEnumerator.EnumerateFacenames(); 00224 m_pFontFaces = m_fntEnumerator.GetFacenamesArray(); 00225 for (i=0; i < OPTIONSDLG_FONTPANEL_NUMSETTINGS; i++) 00226 BuildFontSettings(table, m_strSettingsLabel[i], m_nBaseID[i]); 00227 00228 // make all rows and all columns (except the first) as growable 00229 for (i=1, max=table->GetChildren().GetCount()/table->GetCols(); i < max; i++) 00230 #if wxCHECK_VERSION(2, 5, 1) 00231 table->AddGrowableRow(i, 1);//(i == 0 ? 0 : 1)); 00232 #else 00233 table->AddGrowableRow(i); 00234 #endif 00235 for (i=1; i < table->GetCols(); i++) 00236 table->AddGrowableCol(i); 00237 00238 // add everything to the main sizer 00239 mainSizer->Add(tmp, 0, wxGROW); 00240 00241 mainSizer->Add(new wxStaticLine(this, -1), 0, wxGROW | wxALL, 5); 00242 mainSizer->Add(new wxStaticText(this, -1, wxT("Preview:")), 0, wxALL, 5); 00243 mainSizer->Add(m_pPreviewBox, 5, wxGROW | wxALL, 5); 00244 mainSizer->Add(new wxStaticLine(this, -1), 0, wxGROW | wxALL, 5); 00245 00246 mainSizer->Add(table, 12, wxGROW | wxALL, 5); 00247 00248 // set up sizer 00249 SetSizer(mainSizer); 00250 mainSizer->SetSizeHints(this); 00251 00252 // and, finally, synchronize with current font settings... 00253 00254 wxCommandEvent ev(wxEVT_COMMAND_COMBOBOX_SELECTED, 00255 OPTIONSDLG_FONTPANEL_EXPDEPTH); 00256 m_pExpDepthChoice->SetSelection(0); 00257 OnExpDepthChange(ev); 00258 00259 mgLogDebug(wxT("mgOptFontSettingsPanel::Setup() - everything okay")); 00260 } 00261 00262 mgOptDlg::mgOptChangedType mgOptFontSettingsPanel::CommitChanges( wxConfig* config ) 00263 { 00264 for (int j=0; j < m_pExpDepthChoice->GetSelection(); j++) 00265 for (int i=0; i < OPTIONSDLG_FONTPANEL_NUMSETTINGS; i++) 00266 SaveSettings(m_nBaseID[i], (mcTextSettings &)GetSettingsFromBaseID(j, m_nBaseID[i])); 00267 00268 mgLogDebug( wxT("mgOptFontSettingsPanel::CommitChanges()\n") ); 00269 return mgOptDlg::OptChanged_None; 00270 } 00271 00272 00273 00274 00275 // just to avoid a lot of repetition of these two lines 00276 #define GETWND(idoffset) \ 00277 wnd = FindWindowById(id+idoffset, this); \ 00278 mcASSERT(wnd, wxT("Error in the build process")); 00279 00280 00281 void mgOptFontSettingsPanel::ReadSettings(int id, const mcTextSettings &p) 00282 { 00283 wxWindow *wnd = NULL; 00284 00285 GETWND(OPTIONSDLG_FONTPANEL_FONTFACE_IDOFFSET); 00286 ((wxComboBox *)wnd)->SetValue(p.m_hFont.GetFaceName()); 00287 00288 int n = p.m_hFont.GetPointSize(); 00289 GETWND(OPTIONSDLG_FONTPANEL_FONTSIZE_IDOFFSET); 00290 ((wxTextCtrl *)wnd)->SetValue(wxString::Format(wxT("%d"), n)); 00291 00292 GETWND(OPTIONSDLG_FONTPANEL_FGCOL_IDOFFSET); 00293 ((wxColourButton *)wnd)->SetColour(p.m_clrFg); 00294 00295 GETWND(OPTIONSDLG_FONTPANEL_BKCOL_IDOFFSET); 00296 ((wxColourButton *)wnd)->SetColour(p.m_clrBk); 00297 } 00298 00299 void mgOptFontSettingsPanel::SaveSettings(int id, mcTextSettings &p) 00300 { 00301 wxWindow *wnd = NULL; 00302 00303 // do exactly the inverse process done in #ReadSettings... 00304 00305 GETWND(OPTIONSDLG_FONTPANEL_FONTFACE_IDOFFSET); 00306 p.m_hFont.SetFaceName(((wxComboBox *)wnd)->GetValue()); 00307 00308 long n; 00309 GETWND(OPTIONSDLG_FONTPANEL_FONTSIZE_IDOFFSET); 00310 ((wxTextCtrl *)wnd)->GetValue().ToLong(&n, 10); 00311 p.m_hFont.SetPointSize(n); 00312 00313 GETWND(OPTIONSDLG_FONTPANEL_FGCOL_IDOFFSET); 00314 p.m_clrFg = ((wxColourButton *)wnd)->GetColour(); 00315 00316 GETWND(OPTIONSDLG_FONTPANEL_BKCOL_IDOFFSET); 00317 p.m_clrBk = ((wxColourButton *)wnd)->GetColour(); 00318 } 00319 00320 00321 00322 00323 // event handlers 00324 00325 void mgOptFontSettingsPanel::OnExpDepthChange(wxCommandEvent &ev) 00326 { 00327 // get the style we must synchronize the controls on... 00328 const mcStyle *p = m_pPreviewBox->GetMathObj().gui_GetStyle(m_pExpDepthChoice->GetSelection()); 00329 00330 // synchronize all "rows" 00331 for (int i=0; i < OPTIONSDLG_FONTPANEL_NUMSETTINGS; i++) 00332 ReadSettings(m_nBaseID[i], GetSettingsFromBaseID(p, m_nBaseID[i])); 00333 00334 mgLogDebug( wxT("mgOptFontSettingsPanel::OnExpDepthChange() - ") 00335 wxT("synchronized with the font-settings...") ); 00336 } 00337 00338 void mgOptFontSettingsPanel::OnActiveElemChange(wxCommandEvent &ev) 00339 { 00340 // the EXTRA LONG member of the event should contain the ID 00341 // of the new active element... 00342 int id = ev.GetExtraLong(); 00343 if (id == -1) 00344 return; 00345 00346 // search the active element in the mathbox 00347 const mcElement p = m_pPreviewBox->GetElemFromID(id); 00348 if (p == NULL) 00349 return; 00350 00351 // then, change the current exp depth to reflect the active 00352 // element exponent depth. 00353 /*int n = p->data_GetExpDepth(); 00354 m_pExpDepthChoice->SetSelection(n); 00355 00356 mgLogDebug( wxT("mgOptFontSettingsPanel::OnActiveElemChange() - ") 00357 wxT("changed exponent depth to %d"), n); 00358 OnExpDepthChange(ev);*/ 00359 } 00360 00361
[ Top ] |