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 // // 00030 00031 00032 00033 #ifndef OPERATOR_H 00034 #define OPERATOR_H 00035 00036 // optimization for GCC compiler 00037 #ifdef __GNUG__ 00038 #pragma interface "Operator.h" 00039 #endif 00040 00041 // required includes 00042 #include "mc/Decoration.h" 00043 00044 00045 00046 mcDEFINE_HELPER_CLASSES(mcOperator) 00047 00048 00049 00050 00051 00052 class mcOperatorHelpers : public mcDecorationHelpers 00053 { 00054 #ifdef mcENABLE_DATA 00055 public: // DATA variables 00056 00061 00064 mcElementType mdata_nType; 00065 00067 #define mcNUM_OPERATORS 4 00068 00071 mcKey kOpBeginChar[mcNUM_OPERATORS]; 00072 00076 static wxString strOpSymbol[mcNUM_OPERATORS]; 00077 00080 //wxString strMathMLOp[mcNUM_OPERATORS]; 00081 00083 00084 #endif 00085 00086 00087 00088 #ifdef mcENABLE_GUI 00089 protected: // GUI variables 00090 00098 static wxSize sgui_szReal[mcNUM_OPERATORS][mcELEMENTMATH_MAX_EXPDEPTH]; 00099 00101 static wxSize sgui_sz[mcELEMENTMATH_MAX_EXPDEPTH]; 00102 00105 static const mcStyleArray *sgui_pLastStyle; 00106 00107 #endif 00108 00109 00110 00111 00112 #ifdef mcENABLE_MATH 00113 protected: // MATH variables 00114 00116 int m_nPriority; 00117 00118 #endif 00119 00120 00121 00122 public: 00123 00124 mcOperatorHelpers() { 00125 mdata_nType = mcET_INVALID; 00126 } 00127 00128 virtual ~mcOperatorHelpers() {} 00129 00130 00131 00132 #ifdef mcENABLE_DATA 00133 public: 00134 00135 00137 bool data_isAllowedBefore(mcElementType type) const; 00138 00139 // shortcuts to STATIC versions 00140 int data_GetOpIndex() const { return data_GetOpIndex(data_GetType()); } 00141 wxString data_GetOpSymbol() const { return data_GetOpSymbol(data_GetType()); } 00142 00143 00144 void data_DeepCopy(const mcElementHelpers *p) { 00145 const mcOperatorHelpers *o = (const mcOperatorHelpers *)p; 00146 mdata_nType = o->mdata_nType; 00147 mcDecorationHelpers::data_DeepCopy(p); 00148 } 00149 00150 00152 static int data_GetOpIndex(mcElementType t) { 00153 mcASSERT(t != mcET_INVALID, wxT("Invalid operator type")); 00154 return t-mcET_ADDOP; 00155 } 00156 00158 static wxString data_GetOpSymbol(mcElementType t) { 00159 mcASSERT(t != mcET_INVALID, wxT("Invalid operator type")); 00160 return strOpSymbol[data_GetOpIndex(t)]; 00161 } 00162 00164 static bool data_isOp(mcElementType t) { 00165 return (t == mcET_ADDOP || t == mcET_SUBOP || 00166 t == mcET_MULTOP || t == mcET_DIVOP); 00167 } 00168 00169 #endif // mcENABLE_DATA 00170 00171 00172 00173 00174 #ifdef mcENABLE_GUI 00175 public: 00176 00180 00181 bool gui_isBeginKey(const mcKey &ev) const; 00182 00183 // operators are defined by only 1 char; thus every character 00184 // user presses after the begin char of the operator, is an end char 00185 bool gui_isEndKey(const mcKey &ev) const { return TRUE; } 00186 00187 mcMoveCursorRes gui_MoveCursor(mcMoveCursorFlag flag, long modifiers); 00188 mcInputRes gui_Input(const mcKey &ev, mcElement *newelem); 00189 int gui_MoveCursorUsingPoint(wxDC &dc, const wxPoint &p); 00190 int gui_Draw(wxDC &dc, int x, int y, long flags, const wxPoint &pt) const; 00191 int gui_GetRelCursorPos(wxDC &dc, wxPoint *pt) const; 00192 void gui_DoRecalcSize(); 00193 00194 // these doesn't apply to an operator... 00195 void gui_GetCursorPos(mcCursorPos &p) const { p.gui_Push(mcCP_BEGINEND); } 00196 void gui_SetCursorPos(const mcCursorPos &) { ; } 00197 bool gui_LetInCursor(mcCursorPos code) { return FALSE; } 00198 00201 wxSize gui_GetRealSize() const 00202 { return sgui_szReal[data_GetType()-mcET_ADDOP][gui_GetExpDepth()]; } 00203 00205 00206 #endif // mcENABLE_GUI 00207 00208 00209 00210 00211 #ifdef mcENABLE_MATH 00212 public: 00213 00215 mcRealValue math_GetLenght() const { return 1.5; } 00216 00217 00221 00225 virtual bool math_CanBeApplied(const mcElement &l, const mcElement &r) const = 0; 00226 00229 virtual mcBasicOpRes math_Apply(mcElement &, const mcElement &, mcElement *) const = 0; 00230 00233 virtual mcBasicOpRes math_ApplySimple(mcElement &, const mcElement &) const = 0; 00234 00236 virtual mcRealValue math_Evaluate(mcRealValue val, mcRealValue val2) const = 0; 00237 00238 // apply this operator between pLeft and pRight elements 00239 //virtual void SolveFirst(mcElement pLeft, mcElement pRight) = 0; 00240 bool math_Compare(const mcElement &p, long flags) const 00241 { return math_CompareThisOnly(p, flags); } 00242 //bool hasSameContentOf(const mcElement &p) const { return FALSE; } 00243 00245 #endif // mcENABLE_MATH 00246 00247 00248 00249 #ifdef mcENABLE_IO 00250 public: 00251 00252 bool io_isBeginTag(const wxXml2Node &tag) const; 00253 bool io_isBeginChar(const wxString &str) const; 00254 00255 // mathML functions 00256 wxXml2Node io_GetMathML(bool bGetPresentation) const; 00257 wxString io_GetInlinedExpr() const; 00258 00259 bool io_ImportPresentationMathML(wxXml2Node tag, wxString &pErr); 00260 bool io_ImportInlinedExpr(const wxString &, int *count, wxString &pErr); 00261 00262 #endif // mcENABLE_IO 00263 }; 00264 00265 00266 00267 00270 class mcOperator : public mcDecoration 00271 { 00272 mcDEFINE_ABSTRACT_CLASS(Operator, mcDecoration); 00273 00274 public: 00275 00276 static wxString data_GetOpSymbol(mcElementType t) 00277 { return mcOperatorHelpers::data_GetOpSymbol(t); } 00278 00279 wxString data_GetOpSymbol() const 00280 { return hlp()->data_GetOpSymbol(); } 00281 00282 bool data_isValidContainerFor(mcElementType t) const 00283 { return t == mcET_ADDOP || t == mcET_MULTOP || 00284 t == mcET_SUBOP || t == mcET_DIVOP; } 00285 00286 mcWRAPPER bool math_CanBeApplied(const mcElement &l, const mcElement &r) const 00287 { return hlp()->math_CanBeApplied(l, r); } 00288 00289 mcWRAPPER mcBasicOpRes math_Apply(mcElement &l, const mcElement &r, mcElement *pp) const 00290 { return hlp()->math_Apply(l, r, pp); } 00291 00292 mcWRAPPER mcBasicOpRes math_ApplySimple(mcElement &l, const mcElement &r) const 00293 { return hlp()->math_ApplySimple(l, r); } 00294 00295 mcWRAPPER mcRealValue math_Evaluate(mcRealValue val, mcRealValue val2) const 00296 { return hlp()->math_Evaluate(val, val2); } 00297 }; 00298 00299 00300 #endif // OPERATOR_H 00301 00302
[ Top ] |