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

Bracket.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 //                                                                   //
00031 
00032 
00033 
00034 #ifndef BRACKET_H
00035 #define BRACKET_H
00036 
00037 // optimization for GCC compiler
00038 #ifdef __GNUG__
00039 #pragma interface "Bracket.h"
00040 #endif
00041 
00042 // required includes
00043 #include "mc/ExpContainer.h"
00044 
00045 
00046 mcDEFINE_HELPER_CLASSES(mcBracket)
00047 
00048 
00049 
00050 #define mcBRACKET_SIMPLE_BRACKETS   1
00051 #define mcBRACKET_SQUARE_BRACKETS   2
00052 
00053 
00054 
00058 class mcBracketHelpers : public mcExpContainerHelpers
00059 {
00060  mcDEFINE_REFERENCE_DATA(mcBracket, mcET_BRACKET);
00061 
00062 #ifdef mcENABLE_GUI
00063 public:    // customizable variables
00064 
00070  static bool sgui_bCreateBothSymbols;
00071 
00072  static int sgui_nSpaceAboveBelow;
00073  static int sgui_nSpaceLeftRight;
00074 
00075  virtual int gui_GetSpaceAboveBelow() const  { return sgui_nSpaceAboveBelow; }
00076  virtual int gui_GetSpaceLeftRight() const  { return sgui_nSpaceLeftRight; }
00077 
00078  static wxString sgui_strLeftParentheses, sgui_strRightParentheses;
00079 
00081  static bool gui_isLeftParenthesis(const wxChar c) {
00082   return (c != 0 && sgui_strLeftParentheses.Contains(c));
00083  }
00084 
00086  static bool gui_isRightParenthesis(const wxChar c) {
00087   return (c != 0 && sgui_strRightParentheses.Contains(c));
00088  }
00089 
00090 protected:
00091 
00094  wxFont mgui_fLastFont;
00095  
00098  wxSize mgui_szBracket;
00099 
00100 public:
00101 
00103  bool mgui_bRemoveLeftBracket;
00104 
00105 #endif
00106 
00107 
00108 
00109 public:
00110 
00111  mcBracketHelpers() { data_Init(); }
00112  virtual ~mcBracketHelpers() {}
00113 
00114 
00115 
00116 #ifdef mcENABLE_DATA
00117 public:
00118 
00119 #ifdef __MCDEBUG__
00120  
00121  wxString data_BaseDebug(long flags) const {
00122   return wxT("mcBracket [\n") + 
00123    data_GetContent().data_GetDebug(
00124    mcMathCore::Get()->m_nIndentationStep, flags) + 
00125    wxT("mcBracket ]\n");
00126  }
00127 
00128 #endif
00129 
00133  int data_GetBracketDepth() const {
00134    //return data_m_nBracketType;
00135   return data_ChooseBracketType();
00136  }
00137 
00138 
00139  wxString data_GetBracketLeftSymbol(int n = -1) const;
00140  wxString data_GetBracketRightSymbol(int n = -1) const;
00141 
00142  int data_ChooseBracketType() const;
00143 
00144 #endif  // mcENABLE_DATA
00145 
00146 
00147 
00148 
00149 #ifdef mcENABLE_GUI
00150 public:
00151 
00155 
00156  // brackets begin when the user presses the '(' symbol
00157  bool gui_isBeginKey(const mcKey &ev) const {
00158   wxChar c = ev.GetKeyCode();
00159   if (!sgui_bCreateBothSymbols) // don't build mcBrackets...
00160    return FALSE;
00161   if (c == wxT('(') || c == wxT('[') || c == wxT('{'))
00162    return TRUE;
00163   return FALSE;
00164  }
00165 
00166 
00173  mcInputRes gui_BaseInput(const mcKey &key, mcElement *pnew);
00174  mcInputRes gui_HandleContentInput(mcInputRes r, mcElement *);
00175 
00176  int gui_GetContentOffsetX() const;
00177  int gui_GetContentOffsetY() const;
00178 
00179  bool gui_isLeftPosEnabled() const  { return TRUE; }
00180  bool gui_isRightPosEnabled() const  { return TRUE; }
00181 
00182  void gui_DrawContainer(wxDC &dc, int x, int y, long flags, const wxPoint &pt) const;
00183 
00185 
00186 
00190 
00191  void gui_DoRecalcBaseSize();
00192 
00193  mcInputRes gui_OnRemoveLeftBracket(mcElement *);
00194  mcInputRes gui_OnRemoveRightBracket(mcElement *);
00195 
00196  static wxFont gui_RebuildFont(const mcElementHelpers *elem, int h);
00197  
00199 
00200 #endif  // mcENABLE_GUI
00201 
00202 
00203 
00204 
00205 #ifdef mcENABLE_MATH
00206 public:
00207 
00208  //mcExpSimRes math_Distribute(mcPolynomial &, mcMonomial &);
00209  mcExpSimRes math_RemoveExp();
00210 
00211  mcExpSimRes math_ExpandContents(long flags, mcElement *newelem);
00212  mcExpSimRes math_SimplifyContents(long flags, mcElement *newelem);
00213  mcBasicOpRes math_MakeReciprocal(mcElement *);
00214  
00215  mcRealValue math_GetBaseLenght() const { return mcExpContainerHelpers::math_GetBaseLenght() + 2; }
00216  int math_GetOrderPos() const   { return 2; }
00217 
00218 #endif  // mcENABLE_MATH
00219 
00220 
00221 
00222 
00223 #ifdef mcENABLE_IO
00224 protected:
00225 
00226  wxString io_GetMathMLPresentationTag() const  { return wxT("mfenced"); }
00227 
00228 public:
00229 
00230  bool io_isBeginChar(const wxString &str) const {
00231   return io_isBracketBeginChar(str);
00232  }
00233 
00234  static bool io_isBracketBeginChar(const wxString &str) {
00235   wxChar c = str.GetChar(0);
00236   if (c == wxT('(') || c == wxT('[') || c == wxT('{'))
00237    return TRUE;
00238   return FALSE;
00239  }
00240 
00241  // inlined expr IO
00242  wxString io_GetBaseInlinedExpr() const;
00243  bool io_ImportBaseInlinedExpr(const wxString &str, int *, wxString &);
00244 
00245 #endif  // mcENABLE_IO
00246 };
00247 
00248 
00258 class mcBracket : public mcExpContainer
00259 {
00260  mcDEFINE_MAIN_CLASS(Bracket, mcExpContainer);
00261 
00262 public:
00263 
00264  mcBracket(const mcPolynomial &content)
00265  { data_SetRefData(new mcBracketHelpers()); data_SetContent(content); }
00266  
00267  bool data_isValidContainerFor(mcElementType t) const
00268   { return t == mcET_BRACKET; }
00269 
00270  int data_GetBracketDepth() const
00271   { return hlp()->data_GetBracketDepth(); }
00272 };
00273 
00274 
00275 #endif // BRACKET_H
00276 
00277 
00278 


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

[ Top ]