00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00030
00031
00032
00033
00034
00035 #ifdef __GNUG__
00036 #pragma implementation "Operator.h"
00037 #endif
00038
00039
00040 #include "mc/mcprec.h"
00041 #ifdef __BORLANDC__
00042 #pragma hdrstop
00043 #endif
00044
00045 #ifndef mcPRECOMP
00046 #include <wx/dcscreen.h>
00047 #include "mc/Operator.h"
00048 #include "mc/MathUtils.h"
00049 #endif
00050
00051
00052
00053 mcIMPLEMENT_ABSTRACT_CLASS(mcOperator, mcElement);
00054
00055
00056
00057 wxString mcOperatorHelpers::strOpSymbol[] = { wxT("+"), wxT("-"), wxT("*"), wxT("/:") };
00058 wxSize mcOperatorHelpers::sgui_szReal[mcNUM_OPERATORS][mcELEMENTMATH_MAX_EXPDEPTH];
00059 wxSize mcOperatorHelpers::sgui_sz[mcELEMENTMATH_MAX_EXPDEPTH];
00060 const mcStyleArray *mcOperatorHelpers::sgui_pLastStyle = NULL;
00061
00062
00063
00064
00065
00066
00067
00068
00069 bool mcOperatorHelpers::data_isAllowedBefore(mcElementType type) const
00070 {
00071 if (mcOperatorHelpers::data_isOp(type))
00072 return FALSE;
00073 return TRUE;
00074 }
00075
00076
00077
00078
00079
00080
00081
00082 void mcOperatorHelpers::gui_DoRecalcSize()
00083 {
00084 if (gui_GetStyleArray() == sgui_pLastStyle) {
00085
00086 mcGUILOG(wxT("mcOperatorHelpers::gui_DoRecalcSize - skipped an operator recalc process"));
00087 mgui_sz = sgui_sz[gui_GetExpDepth()];
00088 return;
00089 }
00090
00091 mcGUILOG(wxT("mcOperatorHelpers::gui_DoRecalcSize - recalculating ALL operator' sizes"));
00092 sgui_pLastStyle = gui_GetStyleArray();
00093 wxScreenDC dc;
00094
00095
00096
00097
00098
00099 for (int j=0; j < mcELEMENTMATH_MAX_EXPDEPTH; j++) {
00100
00101
00102 gui_GetStyleArray()->Get(j)->gui_Select(dc, this);
00103 sgui_sz[j].Set(-1, -1);
00104
00105 for (int i=0; i < mcNUM_OPERATORS; i++) {
00106 wxString str = strOpSymbol[i].GetChar(0);
00107
00108 int w = gui_GetWidthOf(&dc, str);
00109 int h = gui_GetHeightOf(&dc, str);
00110
00111 sgui_sz[j].SetWidth(mcMAX(w, sgui_sz[j].GetWidth()));
00112 sgui_sz[j].SetHeight(mcMAX(h, sgui_sz[j].GetHeight()));
00113
00114
00115 sgui_szReal[i][j].Set(w, h);
00116 }
00117 }
00118
00119
00120 mgui_sz = sgui_sz[gui_GetExpDepth()];
00121 }
00122
00123 int mcOperatorHelpers::gui_Draw(wxDC &hDC, int x, int y, long flags, const wxPoint &pt) const
00124 {
00125 wxSize real(gui_GetRealSize());
00126 mcGUILOG(wxT("mcOperatorHelpers::gui_Draw [%s] - size [%d;%d], real size [%d;%d]"),
00127 mcTXTTHIS, mgui_sz.GetWidth(), mgui_sz.GetHeight(),
00128 real.GetWidth(), real.GetHeight());
00129
00130
00131 gui_SelectStyle(hDC);
00132
00133 hDC.DrawText(data_GetOpSymbol(),
00134 x+(mgui_sz.GetWidth()-real.GetWidth())/2,
00135 y+(mgui_sz.GetHeight()-real.GetHeight())/2);
00136
00137 return data_GetID();
00138 }
00139
00140 mcInputRes mcOperatorHelpers::gui_Input(const mcKey &key, mcElement *)
00141 {
00142 wxString str = (wxChar)key.GetKeyCode();
00143
00144
00145
00146 mcASSERT(data_GetOpSymbol().Contains(str),
00147 wxT("Given char wasn't the right symbol for this operator"));
00148
00149
00150 gui_RecalcSize();
00151
00152 return mcIR_OKAY;
00153 }
00154
00155 mcMoveCursorRes mcOperatorHelpers::gui_MoveCursor(mcMoveCursorFlag flag, long modifiers)
00156 {
00157
00158
00159 mcASSERT(0, wxT("Code should never get here; cursor position is wrong"));
00160
00161
00162
00163
00164
00165
00166 return mcMCR_OKAY;
00167 }
00168
00169 int mcOperatorHelpers::gui_MoveCursorUsingPoint(wxDC &dc, const wxPoint &p)
00170 {
00171 mcASSERT(0, wxT("Code should never get here; cursor position is wrong"));
00172
00173
00174 return mcMCR_OKAY;
00175 }
00176
00177 int mcOperatorHelpers::gui_GetRelCursorPos(wxDC &hDC, wxPoint *pt) const
00178 {
00179
00180
00181 mcASSERT(0, wxT("Code should never get here; cursor position is wrong"));
00182 pt->x = 0;
00183 pt->y = 0;
00184
00185
00186 return gui_GetHeight();
00187 }
00188
00189 bool mcOperatorHelpers::gui_isBeginKey(const mcKey &key) const
00190 {
00191 wxString str = (wxChar)key.GetKeyCode();
00192 if (key.GetKeyCode() != 0 && key.GetModifiers() == 0 &&
00193 data_GetOpSymbol().Contains(str))
00194 return TRUE;
00195 return FALSE;
00196 }
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 bool mcOperatorHelpers::io_isBeginTag(const wxXml2Node &tag) const
00207 {
00208 if (tag.GetName().CmpNoCase(wxT("mo")) != 0)
00209 return FALSE;
00210 if (tag.GetChildren().GetType() != wxXML_TEXT_NODE)
00211 return FALSE;
00212
00213 wxString str = tag.GetChildren().GetContent();
00214 for (int n=0; n < mcNUM_OPERATORS; n++)
00215 if (strOpSymbol[n].Contains(str))
00216 return n;
00217
00218 return FALSE;
00219 }
00220
00221 bool mcOperatorHelpers::io_isBeginChar(const wxString &str) const
00222 {
00223 if (data_GetOpSymbol().Contains(str))
00224 return TRUE;
00225 return FALSE;
00226 }
00227
00228 wxXml2Node mcOperatorHelpers::io_GetMathML(bool bGetPresentation) const
00229 {
00230
00231 return wxXml2Node(wxXML_TEXT_NODE, wxXml2EmptyDoc, wxT("mo"), data_GetOpSymbol());
00232 }
00233
00234 wxString mcOperatorHelpers::io_GetInlinedExpr() const
00235 {
00236 return data_GetOpSymbol().Left(1);
00237 }
00238
00239 bool mcOperatorHelpers::io_ImportPresentationMathML(wxXml2Node tag, wxString &pErr)
00240 {
00241 mcASSERT(tag.GetName() == wxT("mo"), wxT("Error in mcOperatorHelpers::io_isBeginTag()"));
00242
00243 if (tag.GetChildren().GetType() != wxXML_TEXT_NODE) {
00244
00245
00246 pErr = wxT("The MathML to import is not valid MathML 2.0\n")
00247 wxT("or there was an error while parsing it.");
00248 return FALSE;
00249 }
00250
00251
00252 wxString str = tag.GetChildren().GetContent();
00253 mcASSERT(data_GetOpSymbol().Contains(str),
00254 wxT("Error in mcOperatorHelpers::io_isBeginTag"));
00255
00256 return TRUE;
00257
00258 }
00259
00260 bool mcOperatorHelpers::io_ImportInlinedExpr(const wxString &str, int *count, wxString &pErr)
00261 {
00262 wxString opchar(str.GetChar(0));
00263 mcASSERT(data_GetOpSymbol().Contains(opchar),
00264 wxT("Error in mcOperatorHelpers::io_isBeginChar"));
00265
00266
00267 *count = 1;
00268 return TRUE;
00269 }
00270
00271
00272
00273
00274
00275
00276
00277