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 PARENTHESIS_H 00035 #define PARENTHESIS_H 00036 00037 // optimization for GCC compiler 00038 #ifdef __GNUG__ 00039 #pragma interface "Parenthesis.h" 00040 #endif 00041 00042 // required includes 00043 #include "mc/Bracket.h" 00044 00045 00046 00047 00048 mcDEFINE_HELPER_CLASSES(mcParenthesis) 00049 00050 class mcParenthesis; 00051 extern mcParenthesis mcEmptyParenthesis; 00052 00053 00054 00055 00059 class mcParenthesisHelpers : public mcDecorationHelpers 00060 { 00061 mcDEFINE_REFERENCE_DATA(mcParenthesis, mcET_PARENTHESIS); 00062 00063 #ifdef mcENABLE_DATA 00064 protected: 00065 00068 bool mdata_bLeftBracket; 00069 00070 public: 00071 00075 mcPolynomial mdata_pTmpExp; 00076 00077 #endif 00078 00079 00080 00081 public: 00082 00083 mcParenthesisHelpers() { 00084 mdata_bLeftBracket = FALSE; 00085 data_AddProperty(mcEP_NOTIFY_NEIGHBOR_CHANGE); 00086 data_Init(); 00087 } 00088 00089 virtual ~mcParenthesisHelpers() { /*mcSAFE_DELETE(mdata_pTmpExp) */} 00090 00091 00092 00093 #ifdef mcENABLE_DATA 00094 public: 00095 00096 #ifdef __MCDEBUG__ 00097 wxString data_Debug(long flags) const { 00098 wxString str = data_GetSymbol(); 00099 if (mcMathCore::Get()->isGUIEnabled()) 00100 str = data_GetSymbol(); 00101 return wxT("mcParenthesis ") + str + wxT("\n"); 00102 } 00103 #endif 00104 00105 void data_DeepCopy(const mcElementHelpers *p) { 00106 const mcParenthesisHelpers *t = (const mcParenthesisHelpers *)p; 00107 mdata_bLeftBracket = t->mdata_bLeftBracket; 00108 mdata_pTmpExp.data_DeepCopy(t->mdata_pTmpExp); 00109 mcDecorationHelpers::data_DeepCopy(p); 00110 } 00111 00113 bool data_isLeftBracket() const { 00114 return mdata_bLeftBracket; 00115 } 00116 00120 wxString data_GetSymbol() const { 00121 return (data_isLeftBracket() ? wxT("(") : wxT(")")); 00122 } 00123 00124 void data_SetAsLeftBracket() { mdata_bLeftBracket = TRUE; } 00125 void data_SetAsRightBracket() { mdata_bLeftBracket = FALSE; } 00126 00127 void data_OnNeighborChange(); 00128 00129 #endif // mcENABLE_DATA 00130 00131 00132 00133 00134 00135 #ifdef mcENABLE_GUI 00136 protected: 00137 00140 wxFont mgui_fLastFont; 00141 00143 bool gui_SearchInMonomial(mcMonomial &m, int *h, bool left, int idx); 00144 int gui_GetMaxHeightToNextBracket(bool left); 00145 void gui_RebuildFont(); 00146 00147 public: 00148 00149 00154 00155 bool gui_isBeginKey(const mcKey &ev) const { 00156 wxChar c = ev.GetKeyCode(); 00157 if (mcBracketHelpers::sgui_bCreateBothSymbols) // build only mcBrackets 00158 return FALSE; 00159 if (mcBracketHelpers::gui_isLeftParenthesis(c) || 00160 mcBracketHelpers::gui_isRightParenthesis(c)) 00161 return TRUE; 00162 return FALSE; 00163 } 00164 00165 int gui_Draw(wxDC &dc, int x, int y, long flags, const wxPoint &pt) const; 00166 mcInputRes gui_Input(const mcKey &key, mcElement *pnew); 00167 void gui_DoRecalcSize(); 00168 00170 00171 #endif // mcENABLE_GUI 00172 00173 00174 00175 00176 #ifdef mcENABLE_IO 00177 public: 00178 00179 bool io_isBeginTag(const wxXml2Node &tag) const { return FALSE; } 00180 bool io_isBeginChar(const wxString &str) const; 00181 00182 bool io_ImportPresentationMathML(wxXml2Node tag, wxString &pErr) { return FALSE;} 00183 bool io_ImportInlinedExpr(const wxString &str, int *count, wxString &pErr); 00184 00185 wxString io_GetInlinedExpr() { return data_GetSymbol(); } 00186 00187 #endif // mcENABLE_IO 00188 00189 }; 00190 00191 00198 class mcParenthesis : public mcDecoration 00199 { 00200 mcDEFINE_MAIN_CLASS(Parenthesis, mcDecoration); 00201 00202 public: 00203 00204 bool data_isValidContainerFor(mcElementType t) const 00205 { return t == mcET_PARENTHESIS; } 00206 00207 mcWRAPPER bool data_isLeftBracket() const 00208 { return hlp()->data_isLeftBracket(); } 00209 mcWRAPPER wxString data_GetSymbol() const 00210 { return hlp()->data_GetSymbol(); } 00211 00212 mcWRAPPER void data_SetAsLeftBracket() 00213 { hlp()->data_SetAsLeftBracket(); } 00214 mcWRAPPER void data_SetAsRightBracket() 00215 { hlp()->data_SetAsRightBracket(); } 00216 }; 00217 00218 00219 #endif // PARENTHESIS_H 00220 00221 00222
[ Top ] |