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

Styles.h

Go to the documentation of this file.
00001 
00002 // MathCore = 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 //                                                                   //
00032 
00033 
00034 
00035 #ifndef STYLES_H
00036 #define STYLES_H
00037 
00038 // optimization for GCC compiler
00039 #ifdef __GNUG__
00040 //#pragma interface "Styles.h"
00041 #endif
00042 
00043 
00044 // required includes
00045 #include "mc/MathTypes.h"
00046 #include "mc/MathHelpers.h"
00047 #include <wx/dc.h>
00048 
00049 
00050 
00051 // this will be defined in "Element.h" (which needs this file
00052 // for the definition of mcStyle...)
00053 class mcElement;
00054 
00055 
00058 class mcTextSettings : public mcGUIHelper
00059 {
00060 public:  // these variables are public so we can avoid a lot of
00061  // getters/setters which would provide full access anyway
00062  
00064  wxColour m_clrFg, m_clrBk;
00065  
00067  wxFont m_hFont;
00068  
00069 public:
00070  
00076  mcTextSettings(const wxColour fg, const wxColour bk, const wxString &fnt) {
00077   Set(fg, bk, fnt);
00078  }
00079  
00080  mcTextSettings() {}
00081 
00082  void DeepCopy(const mcTextSettings *p) {
00083   m_clrFg = p->m_clrFg;
00084   m_clrBk = p->m_clrBk;
00085   m_hFont = p->m_hFont;
00086  }
00087 
00088  
00091  void Set(const wxColour fg, const wxColour bk, const wxString &fnt) {
00092   SetColours(fg, bk);
00093   SetFont(fnt);
00094  }
00095 
00097  void SetFont(const wxString &fnt) {
00098   Decode(fnt);
00099  }
00100 
00102  void SetColours(const wxColour fg, const wxColour bk) {
00103   m_clrFg = fg;
00104   m_clrBk = bk;
00105  }
00106  
00110  void Decode(const wxString &fnt);
00111  
00113  void gui_Select(wxDC &hDC) const {
00114   hDC.SetTextForeground(m_clrFg);
00115   hDC.SetTextBackground(m_clrBk);
00116   hDC.SetFont(m_hFont);
00117  }
00118  
00120  bool Ok() const {
00121   return m_hFont.Ok();
00122  }
00123 
00125  void ScaleSize(float f) {
00126   m_hFont.SetPointSize((int)(m_hFont.GetPointSize()*f));
00127  }
00128 };
00129 
00130 
00131 
00134 class mcStyle : public mcGUIHelper
00135 {
00136 protected:    // member variables
00137  
00138  
00141 #define mcSTYLE_TEXTSETTINGS_NUM  6
00142  
00145 #define mcSTYLE_SPECIAL_SETTINGS  mcSTYLE_TEXTSETTINGS_NUM-1  // always the last
00146  
00147  
00149  mcTextSettings m_pTextSettings[mcSTYLE_TEXTSETTINGS_NUM];
00150  
00151  
00152 public:    // functions
00153  
00161  mcStyle(const wxColour *fg, const wxColour *bk, const wxString *fnt) {
00162   Set(fg, bk, fnt);
00163  }
00164  
00165  mcStyle() {}
00166  virtual ~mcStyle() {}
00167  
00168  
00170  bool Ok();
00171  
00174  void gui_Select(wxDC &hDC, const mcElement &e) const {
00175   m_pTextSettings[GetIndexFor(e)].gui_Select(hDC);
00176  }
00177 
00178  void DeepCopy(const mcStyle *p) {
00179   for (int i=0; i < mcSTYLE_TEXTSETTINGS_NUM; i++)
00180    m_pTextSettings[i].DeepCopy(&p->m_pTextSettings[i]);
00181  }
00182 
00183  void ScaleSize(float f) {
00184   for (int i=0; i < mcSTYLE_TEXTSETTINGS_NUM; i++)
00185    m_pTextSettings[i].ScaleSize(f);
00186  }
00187  
00188  
00189  
00193  
00196  int GetIndexFor(mcElementType t) const;
00197  
00199  int GetIndexFor(const mcElement &) const;
00200  
00202  const mcTextSettings *GetTextSettingsFor(mcElementType t) const {
00203   return &m_pTextSettings[GetIndexFor(t)];
00204  }
00205  
00207  const mcTextSettings *GetTextSettingsFor(const mcElement &p) const {
00208   return &m_pTextSettings[GetIndexFor(p)];
00209  }
00210  
00212  const mcTextSettings *GetTextSettings(int n) const {
00213   return &m_pTextSettings[n];
00214  }
00215  
00217  const mcTextSettings *GetSpecialTextSettings() const {
00218   return &m_pTextSettings[mcSTYLE_SPECIAL_SETTINGS];
00219  }
00220  
00222  
00223  
00224  
00228  
00232  void SetTextSettingsFor(mcElementType t, const wxColour fg = *wxBLACK,
00233   const wxColour bk = *wxWHITE, const wxString &str = wxEmptyString) {
00234   m_pTextSettings[GetIndexFor(t)].Set(fg, bk, str);
00235  }
00236 
00238  void SetFontFor(mcElementType t, const wxString &str) {
00239   m_pTextSettings[GetIndexFor(t)].SetFont(str);
00240  }
00241  
00244  void SetSpecialTextSettings(const wxColour fg = *wxBLACK,
00245   const wxColour bk = *wxWHITE, const wxString &str = wxEmptyString) {
00246   m_pTextSettings[mcSTYLE_SPECIAL_SETTINGS].Set(fg, bk, str);
00247  }
00248 
00250  void SetSpecialFont(const wxString &str) {
00251   m_pTextSettings[mcSTYLE_SPECIAL_SETTINGS].SetFont(str);
00252  }
00253 
00255  void Set(const wxColour *fg, const wxColour *bk, const wxString *fnt) {
00256   for (int i=0; i < mcSTYLE_TEXTSETTINGS_NUM; i++)
00257    m_pTextSettings[i].Set(fg[i], bk[i], fnt[i]);
00258  }
00259 
00262  void SetFonts(const wxString *fnt) {
00263   for (int i=0; i < mcSTYLE_TEXTSETTINGS_NUM; i++)
00264    m_pTextSettings[i].SetFont(fnt[i]);
00265  }
00266 
00268  void SetColours(const wxColour *fg, const wxColour *bk) {
00269   for (int i=0; i < mcSTYLE_TEXTSETTINGS_NUM; i++)
00270    m_pTextSettings[i].SetColours(fg[i], bk[i]);
00271  }
00272  
00274 };
00275 
00276 
00277 
00280 class mcStyleArray : public mcGUIHelper
00281 {
00282 protected:
00283 
00286  mcStyle *m_pStyles;
00287 
00301  void CreateArray();
00302 
00303 public:
00304 
00306  mcStyleArray() : m_pStyles(NULL) { CreateArray(); }
00307 
00309  mcStyleArray(const mcStyle *arr) : m_pStyles(NULL) {
00310   CreateArray();
00311   Set(arr);
00312  }
00313 
00315  mcStyleArray(const mcStyleArray *arr) : m_pStyles(NULL) {
00316   CreateArray();
00317   DeepCopy(arr);
00318  }
00319 
00321  virtual ~mcStyleArray();
00322 
00324  void DeepCopy(const mcStyleArray *);
00325  
00326 
00327 
00331 
00333  void Set(const mcStyle *arr);
00334 
00336  void Set(const mcStyle *style, int n) {
00337   m_pStyles[n].DeepCopy(style);
00338  }
00339 
00343  void ScaleSize(float f = 1.0);
00344 
00346 
00347 
00348 
00352  
00357  static int GetCount();
00358 
00361  int gui_GetStyleIndexFor(const mcElement &p) const;
00362 
00364  const mcStyle *Get(int n) const {
00365   return &m_pStyles[n];
00366  }
00367 
00369  const mcStyle *gui_GetStyleFor(const mcElement &p) const {
00370   return Get(gui_GetStyleIndexFor(p));
00371  }
00372 
00374 };
00375 
00376 #endif  // STYLES_H


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

[ Top ]