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 TEXT_H 00035 #define TEXT_H 00036 00037 // optimization for GCC compiler 00038 #ifdef __GNUG__ 00039 #pragma interface "Text.h" 00040 #endif 00041 00042 00043 // required includes 00044 #include "mc/MathCore.h" 00045 #include "mc/Decoration.h" 00046 #include "mc/EmptyBox.h" 00047 00048 00049 mcDEFINE_HELPER_CLASSES(mcText) 00050 00051 00052 00053 00054 00055 00056 class mcTextHelpers : public mcDecorationHelpers 00057 { 00058 mcDEFINE_REFERENCE_DATA(mcText, mcET_TEXT); 00059 00060 #ifdef mcENABLE_DATA 00061 protected: 00062 00064 wxArrayString mdata_arrStr; 00065 00068 wxString mdata_strFilter; 00069 00071 bool mdata_bMultiline; 00072 #endif 00073 00074 00075 #ifdef mcENABLE_MATH 00076 public: // static 00077 00078 // An empty mcText object. 00079 static mcText *smath_pEmpty; 00080 #endif 00081 00082 00083 #ifdef mcENABLE_GUI 00084 protected: 00085 00088 int mgui_nCursorPos; 00089 00093 int mgui_nRowPos; 00094 00095 #define mcTEXT_ALIGN_LEFT 0 00096 #define mcTEXT_ALIGN_CENTER 1 00097 #define mcTEXT_ALIGN_RIGHT 2 00098 00099 public: 00100 00102 bool mgui_bDrawEmptyBoxIfEmpty; 00103 00106 mcEmptyBox *mgui_pEmptyBox; 00107 #endif 00108 00109 00110 00111 00112 public: 00113 00114 mcTextHelpers() { 00115 mdata_bMultiline = FALSE; 00116 mgui_pEmptyBox = NULL; 00117 data_Init(); 00118 } 00119 00120 virtual ~mcTextHelpers() 00121 { mcSAFE_DELETE(mgui_pEmptyBox); } 00122 00123 00124 protected: 00125 00126 void gui_Init(); 00127 00128 00129 00130 #ifdef mcENABLE_DATA 00131 public: 00132 00133 #ifdef __MCDEBUG__ 00134 wxString data_Debug(long flags) const { 00135 return wxT("mcText ") + data_GetText(); 00136 } 00137 #endif 00138 00139 void data_DeepCopy(const mcElementHelpers *p); 00140 00141 int data_GetChildrenCount() const { 00142 int n = mcElementHelpers::data_GetChildrenCount(); 00143 if (mcMathCore::Get()->isGUIEnabled()) 00144 n+=(int)(mgui_pEmptyBox != NULL); 00145 return n; 00146 } 00147 00148 const mcElement &data_GetConstChild(int n) const { 00149 mcRETURN_ELEMENT_CHILD(n, mcDecorationHelpers); 00150 if (n == 0 && mcMathCore::Get()->isGUIEnabled()) 00151 return *mgui_pEmptyBox; 00152 return mcEmptyElement; 00153 } 00154 00155 void data_SetChild(int n, const mcElement &newchild) { 00156 mcSET_ELEMENT_CHILD(n, mcDecorationHelpers, newchild); 00157 if (n == 0 && mcMathCore::Get()->isGUIEnabled()) { 00158 mcASSERT(newchild.data_GetType() == mcET_EMPTYBOX, wxT("Invalid new child")); 00159 mcSAFE_DELETE(mgui_pEmptyBox); 00160 mgui_pEmptyBox = new mcEmptyBox((const mcEmptyBox &)newchild); 00161 } 00162 } 00163 00165 bool data_isArrayEmpty() const { 00166 return mdata_arrStr.IsEmpty(); 00167 } 00168 00171 bool data_isToReject(wxChar c) const { 00172 wxString str(c, 1); 00173 if (data_GetFilter() != wxEmptyString && 00174 !data_GetFilter().Contains(str)) 00175 return TRUE; 00176 return FALSE; 00177 } 00178 00179 00180 00184 00186 void data_SetText(const wxString &str); 00187 00189 void data_SetAsMultiline() { 00190 mdata_bMultiline = TRUE; 00191 } 00192 00195 void data_SetAsSingleline() { 00196 mdata_bMultiline = FALSE; 00197 int n = mdata_arrStr.Count()-1; 00198 if (n > 0) mdata_arrStr.Remove(1, n); 00199 } 00200 00203 void data_SetFilter(const wxString &str) { 00204 mdata_strFilter = str; 00205 } 00206 00208 00209 00210 00214 00216 wxString data_GetText() const { 00217 wxString tmp; 00218 for (int i=0; i < data_GetRowCount(); i++) 00219 tmp += mdata_arrStr[i] + wxT("\n"); 00220 return tmp; 00221 } 00222 00224 wxString data_GetLongestStr() const { 00225 wxString m; 00226 for (int i=0; i < data_GetRowCount(); i++) 00227 if (mdata_arrStr[i].Len() > m.Len()) 00228 m = mdata_arrStr[i]; 00229 return m; 00230 } 00231 00233 wxString data_GetFilter() const { 00234 return mdata_strFilter; 00235 } 00236 00239 int data_GetRowCount() const { 00240 return mdata_arrStr.GetCount(); 00241 } 00242 00244 #endif // mcENABLE_DATA 00245 00246 00247 00248 00249 #ifdef mcENABLE_GUI 00250 public: 00251 00255 00257 int gui_GetRowHeight(wxDC *dc, int i) const { 00258 wxString str(wxT("1")); 00259 return gui_GetHeightOf(dc, (mdata_arrStr[i].Len() > 0) ? 00260 mdata_arrStr[i] : str); 00261 } 00262 00263 int gui_GetRowWidth(wxDC *dc, int i) const { 00264 wxString str(wxT("1")); 00265 return gui_GetWidthOf(dc, (mdata_arrStr[i].Len() > 0) ? 00266 mdata_arrStr[i] : str); 00267 } 00268 00270 00271 00272 00276 00277 bool gui_isBeginKey(const mcKey &ev) const { 00278 // user cannot allocate mcText classes; they can only 00279 // be member classes of other classes. 00280 return FALSE; 00281 } 00282 00283 bool gui_isEndKey(const mcKey &ev) const { 00284 return FALSE; 00285 } 00286 00287 void gui_GetCursorPos(mcCursorPos &) const; 00288 00289 void gui_DoRecalcSize(); 00290 void gui_OnSelect(wxDC &dc, wxRect &rc) {} 00291 void gui_SetCursorPos(const mcCursorPos &code); 00292 00293 int gui_GetRelCursorPos(wxDC &dc, wxPoint *pt) const; 00294 mcMoveCursorRes gui_MoveCursor(mcMoveCursorFlag flag, long modifiers); 00295 int gui_MoveCursorUsingPoint(wxDC &dc, const wxPoint &p); 00296 mcInputRes gui_Input(const mcKey &ev, mcElement *newelem); 00297 00298 int gui_Draw(wxDC &dc, int x, int y, long flags, int w, wxColour *color) const; 00299 int gui_Draw(wxDC &dc, int x, int y, long flags, const wxPoint &pt) const 00300 { return gui_Draw(dc, x, y, flags, 0, NULL); } 00301 00302 void gui_UpdateExpDepth(); 00303 00305 00306 #endif // mcENABLE_GUI 00307 00308 00309 00310 00311 #ifdef mcENABLE_MATH 00312 public: 00313 00315 bool math_CompareThisOnly(const mcElement &p, long flags) const; 00316 00317 #endif // mcENABLE_MATH 00318 00319 00320 00321 00322 #ifdef mcENABLE_IO 00323 public: 00324 00325 bool io_isBeginTag(const wxXml2Node &tag) const { return FALSE; } 00326 bool io_isBeginChar(const wxString &str) const { return FALSE; } 00327 00328 wxXml2Node io_GetMathML(bool bGetPresentation) const; 00329 wxString io_GetInlinedExpr() const; 00330 00331 bool io_ImportPresentationMathML(wxXml2Node tag, wxString &pErr); 00332 bool io_ImportInlinedExpr(const wxString &, int *count, wxString &pErr); 00333 00334 #endif // meNABLE_IO 00335 }; 00336 00337 00340 class mcText : public mcDecoration 00341 { 00342 mcDEFINE_MAIN_CLASS(Text, mcDecoration); 00343 00344 00345 #ifdef mcENABLE_DATA 00346 public: 00347 00348 mcWRAPPER bool data_isArrayEmpty() const 00349 { return hlp()->data_isArrayEmpty(); } 00350 00351 mcWRAPPER bool data_isToReject(wxChar c) const 00352 { return hlp()->data_isToReject(c); } 00353 00354 mcWRAPPER void data_SetText(const wxString &str) 00355 { hlp()->data_SetText(str); } 00356 00357 mcWRAPPER void data_SetAsMultiline() 00358 { hlp()->data_SetAsMultiline(); } 00359 00360 mcWRAPPER void data_SetAsSingleline() 00361 { hlp()->data_SetAsSingleline(); } 00362 00363 mcWRAPPER void data_SetFilter(const wxString &str) 00364 { hlp()->data_SetFilter(str); } 00365 00366 mcWRAPPER wxString data_GetText() const 00367 { return hlp()->data_GetText(); } 00368 00369 mcWRAPPER wxString data_GetLongestStr() const 00370 { return hlp()->data_GetLongestStr(); } 00371 00372 mcWRAPPER wxString data_GetFilter() const 00373 { return hlp()->data_GetFilter(); } 00374 00375 mcWRAPPER int data_GetRowCount() const 00376 { return hlp()->data_GetRowCount(); } 00377 00378 mcWRAPPER bool data_isValidContainerFor(mcElementType t) const 00379 { return t == mcET_TEXT; } 00380 00381 #endif // mcENABLE_DATA 00382 00383 00384 #ifdef mcENABLE_GUI 00385 public: 00386 00387 mcWRAPPER int gui_GetRowHeight(wxDC *dc, int i) const 00388 { return hlp()->gui_GetRowHeight(dc, i); } 00389 00390 mcWRAPPER int gui_GetRowWidth(wxDC *dc, int i) const 00391 { return hlp()->gui_GetRowWidth(dc, i); } 00392 00393 mcWRAPPER int gui_Draw(wxDC &dc, int x, int y, long flags, int w, wxColour *color) const 00394 { return hlp()->gui_Draw(dc, x, y, flags, w, color); } 00395 00396 #endif // mcENABLE_GUI 00397 }; 00398 00399 #endif // TEXT_H 00400
[ Top ] |