00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00031
00032
00033
00034
00035 #ifdef __GNUG__
00036 #pragma implementation "Parenthesis.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/Parenthesis.h"
00048 #include "mc/Monomial.h"
00049 #endif
00050
00051
00052
00053 mcIMPLEMENT_MAIN_CLASS(mcParenthesis, mcDecoration);
00054
00055
00056
00057 mcParenthesis mcEmptyParenthesis(NULL);
00058
00059
00060
00061
00062
00063
00064
00065 void mcParenthesisHelpers::data_OnNeighborChange()
00066 {
00067 if (mcMathCore::Get()->isGUIEnabled())
00068 gui_RebuildFont();
00069 }
00070
00071
00072
00073
00074
00075
00076 void mcParenthesisHelpers::gui_DoRecalcSize()
00077 {
00078 wxScreenDC dc;
00079
00080
00081 dc.SetFont(mgui_fLastFont);
00082 mgui_sz = gui_GetSizeOf(&dc, data_GetSymbol());
00083
00084
00085 mgui_sz.SetHeight(mgui_sz.GetHeight()+mcBracketHelpers::sgui_nSpaceAboveBelow*2);
00086 mgui_sz.SetWidth(mgui_sz.GetWidth()+mcBracketHelpers::sgui_nSpaceLeftRight*2);
00087 }
00088
00089 void mcParenthesisHelpers::gui_RebuildFont()
00090 {
00091 wxString tmp;
00092 wxScreenDC dc;
00093
00094
00095 int h = gui_GetHeightOfChar(&dc, this);
00096
00097
00098 h = mcMAX(h, gui_GetMaxHeightToNextBracket(!data_isLeftBracket()));
00099
00100
00101 if (h != mgui_sz.GetHeight()) {
00102
00103 mgui_fLastFont = mcBracketHelpers::gui_RebuildFont(this, h);
00104 gui_RecalcSize();
00105
00106
00107
00108
00109
00110 }
00111 }
00112
00113 int mcParenthesisHelpers::gui_Draw(wxDC &hDC, int Offsetx, int Offsety, long flags, const wxPoint &pt) const
00114 {
00115
00116
00117 #if 0
00118
00119 mcElement p = hlp()->GetParent();
00120 if (p && p.data_GetType() == mcET_MONOMIAL) {
00121 if (((mcMonomial &)p).gui_isCursorOn(hlp())) {
00122
00123
00124 hDC.SetBrush(*wxCYAN_BRUSH);
00125 hDC.gui_DrawRoundedRectangle(Offsetx, Offsety, gui_GetWidth(), gui_GetHeight(), 2);
00126 }
00127 }
00128 #endif
00129
00130
00131
00132
00133 gui_SelectStyle(hDC);
00134 hDC.SetFont(mgui_fLastFont);
00135 hDC.DrawText(data_GetSymbol(), Offsetx, Offsety);
00136
00137 return data_GetID();
00138 }
00139
00140 mcInputRes mcParenthesisHelpers::gui_Input(const mcKey &key, mcElement *pnew)
00141 {
00142 wxChar c = (wxChar)key.GetKeyCode();
00143
00144
00145 if (!data_hasProperty(mcEP_INITIALIZED)) {
00146 if (mcBracketHelpers::sgui_strLeftParentheses.Contains(c)) {
00147
00148
00149 mdata_bLeftBracket = TRUE;
00150
00151 } else if (mcBracketHelpers::sgui_strRightParentheses.Contains(c)) {
00152
00153
00154 mdata_bLeftBracket = FALSE;
00155
00156 } else {
00157
00158 mcASSERT(0, wxT("Which creation char did we receive ?"));
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 data_AddProperty(mcEP_INITIALIZED);
00176 gui_RecalcSize();
00177 }
00178
00179
00180 return mcDecorationHelpers::gui_Input(key, pnew);
00181 }
00182
00183
00184
00185
00186
00187
00188
00189
00190 #define START_ARRAY_SCAN(backward, arr, idx) \
00191 { \
00192 int max = (backward ? 0 : arr.data_GetCount()); \
00193 int i=idx; \
00194 while (1) { \
00195 if (backward && i < max) \
00196 break; \
00197 if (!backward && i >= max) \
00198 break; \
00199 mcElement curr = arr.data_Get(i);
00200
00201
00202 #define END_ARRAY_SCAN(backward) \
00203 if (!backward) i++; \
00204 else i--; \
00205 } \
00206 }
00207
00208
00209 int mcParenthesisHelpers::gui_GetMaxHeightToNextBracket(bool left)
00210 {
00211 return 50;
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254 }
00255
00256 bool mcParenthesisHelpers::gui_SearchInMonomial(mcMonomial &m, int *h, bool left, int idx)
00257 {
00258 START_ARRAY_SCAN(left, m, idx)
00259
00260 if (curr.data_GetType() == mcET_PARENTHESIS) {
00261
00262
00263
00264 if (mcParenthesis(curr).data_isLeftBracket() == left)
00265 return TRUE;
00266 }
00267
00268
00269
00270 if (h) *h = mcMAX(*h, curr.gui_GetHeight());
00271
00272 END_ARRAY_SCAN(left)
00273
00274 return FALSE;
00275 }
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291 bool mcParenthesisHelpers::io_isBeginChar(const wxString &str) const
00292 {
00293 if (mcBracketHelpers::sgui_bCreateBothSymbols)
00294 return FALSE;
00295
00296
00297 wxChar c = str.GetChar(0);
00298 if (mcBracketHelpers::gui_isLeftParenthesis(c) ||
00299 mcBracketHelpers::gui_isRightParenthesis(c))
00300 return TRUE;
00301
00302 return FALSE;
00303 }
00304
00305 bool mcParenthesisHelpers::io_ImportInlinedExpr(const wxString &str, int *count, wxString &pErr)
00306 {
00307 wxChar c = str.GetChar(0);
00308
00309 if (mcBracketHelpers::sgui_strLeftParentheses.Contains(c)) {
00310
00311
00312 mdata_bLeftBracket = TRUE;
00313
00314 } else if (mcBracketHelpers::sgui_strRightParentheses.Contains(c)) {
00315
00316
00317 mdata_bLeftBracket = FALSE;
00318
00319
00320 if (str.GetChar(1) == wxT('^')) {
00321
00322 wxString exp(str.Right(str.Len()-1));
00323 mcExpElementHelpers::io_GetExpSubInlinedToken(exp);
00324
00325
00326
00327 mdata_pTmpExp.data_DeleteAll();
00328 if (!mdata_pTmpExp.io_ImportInlinedExpr(exp, count, pErr))
00329 return FALSE;
00330
00331
00332 *count += 2;
00333 return TRUE;
00334 }
00335
00336 } else {
00337
00338 mcASSERT(0, wxT("Error in mcParenthesisHelpers::io_isBeginChar"));
00339 }
00340
00341 *count = 1;
00342 return TRUE;
00343 }
00344
00345
00346