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 #ifdef __GNUG__
00035 #pragma implementation "MathLine.h"
00036 #endif
00037
00038
00039 #include "mc/mcprec.h"
00040 #ifdef __BORLANDC__
00041 #pragma hdrstop
00042 #endif
00043
00044 #ifndef mcPRECOMP
00045 #include "mc/MathCore.h"
00046 #include "mc/MathLine.h"
00047 #include "mc/Text.h"
00048 #endif
00049
00050
00051
00052
00053 int mcMathLineHelpers::sgui_nCursorWidth = 2;
00054
00055
00056 #ifdef mcMATHLINE_DONOT_USE_BITMAP
00057 wxPoint lastpos;
00058 #endif
00059
00060
00061
00062 mcMathLine mcEmptyLine(NULL);
00063
00064
00065
00066
00067
00068
00069
00070
00071 #ifdef __MCDEBUG__
00072
00073 wxString mcMathLineHelpers::data_Debug(long flags) const
00074 {
00075 wxString longstr, str;
00076
00077
00078
00079
00080 longstr.Alloc(2048);
00081
00082 if ((flags & mcMATHLINE_DBG_BITMAP) &&
00083 mcMathCore::Get()->isGUIEnabled()) {
00084
00085 str.Format(wxT("mcMathLine: OBJECT SIZE = %d;%d BITMAP SIZE = %d;%d\n"),
00086 gui_GetWidth(), gui_GetHeight(), mgui_bmpMath.GetWidth(), mgui_bmpMath.GetHeight());
00087
00088
00089 return longstr.Format(
00090 wxT("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n%s%s"),
00091 str.c_str(), mcMathMngHelpers::data_Debug(flags).c_str());
00092
00093 }
00094
00095
00096 return mcMathMngHelpers::data_Debug(flags);
00097 }
00098
00099 #endif
00100
00101 void mcMathLineHelpers::data_DeepCopy(const mcElementHelpers *p)
00102 {
00103 const mcMathLineHelpers *mbl = (const mcMathLineHelpers *)p;
00104
00105
00106 mcMathMngHelpers::data_DeepCopy(mbl);
00107 gui_ExpandBmp();
00108
00109
00110 mgui_nLastID = mbl->mgui_nLastID;
00111 mgui_nCurrentID = mbl->mgui_nCurrentID;
00112 mgui_bUsingMask = mbl->mgui_bUsingMask;
00113 mgui_brushBmpBg = mbl->mgui_brushBmpBg;
00114 }
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 void mcMathLineHelpers::gui_Init()
00125 {
00126
00127 mgui_nLastID = mgui_nCurrentID = -1;
00128 mgui_bUsingMask = FALSE;
00129
00130
00131 mgui_brushBmpBg = *wxWHITE_BRUSH;
00132
00133 if (mcMathCore::Get()->isGUIEnabled()) {
00134 mgui_bmpMath.Create(mcBMP_STDWIDTH+mcBMP_SPACELEFT,
00135 mcBMP_STDHEIGHT+mcBMP_SPACERIGHT);
00136 gui_ExpandBmp();
00137 }
00138
00139 mcMathMngHelpers::gui_Init();
00140 }
00141
00142 int mcMathLineHelpers::gui_UpdateBmp(int x, int y, long flags, const wxPoint &pt)
00143 {
00144 wxMemoryDC memDC;
00145
00146
00147
00148 memDC.SelectObject(mgui_bmpMath);
00149 memDC.SetBackground(mgui_brushBmpBg);
00150 memDC.Clear();
00151
00152
00153
00154
00155 wxPoint newpt = pt;
00156 if (flags & mcDRW_USEPOINT) {
00157
00158
00159 newpt.x -= x;
00160 newpt.y -= y;
00161 }
00162
00163
00164
00165 mgui_nLastID = mgui_nCurrentID;
00166 mgui_nCurrentID = gui_Draw(memDC, mcBMP_SPACELEFT, 0, flags, newpt);
00167 memDC.SelectObject(wxNullBitmap);
00168
00169 #ifdef mcMATHLINE_DONOT_USE_BITMAP
00170 if (p != mcDRW_NONACTIVE && p != mcDRW_ALLACTIVE)
00171 lastpos = *p;
00172 #endif
00173 return mgui_nCurrentID;
00174 }
00175
00176 int mcMathLineHelpers::gui_DrawBmp(wxDC &dc, int x, int y) const
00177 {
00178 #ifndef mcMATHLINE_DONOT_USE_BITMAP
00179 wxMemoryDC memDC;
00180
00181
00182 if (!mgui_bUsingMask) {
00183
00184 memDC.SelectObject(mgui_bmpMath);
00185 dc.Blit(x, y, gui_GetWidth(), gui_GetHeight(), &memDC, 0, 0);
00186 memDC.SelectObject(wxNullBitmap);
00187
00188 } else {
00189
00190 memDC.SelectObject(mgui_bmpMath);
00191 dc.Blit(x, y, gui_GetWidth(), gui_GetHeight(), &memDC, 0, 0, wxCOPY, TRUE);
00192 memDC.SelectObject(wxNullBitmap);
00193 }
00194
00195 #else
00196 wxPoint pt(lastpos.x+x, lastpos.y+y);
00197 m_objMath.gui_Draw(dc, x+BMP_SPACELEFT, y, flags, &pt);
00198 #endif
00199
00200 return mgui_nCurrentID;
00201 }
00202
00203 void mcMathLineHelpers::gui_SetMask(const wxColour &col)
00204 {
00205
00206 mgui_bmpMath.SetMask(new wxMask(mgui_bmpMath, col));
00207
00208
00209 mgui_bUsingMask = TRUE;
00210 }
00211
00212 int mcMathLineHelpers::gui_GetRelCursorPos(wxDC &dc, wxPoint *pt) const
00213 {
00214
00215 int n = mcMathMngHelpers::gui_GetRelCursorPos(dc, pt);
00216
00217
00218 pt->x += mcBMP_SPACELEFT;
00219 pt->y += (gui_GetHeight()-gui_GetHeight())/2;
00220
00221 return n;
00222 }
00223
00224 void mcMathLineHelpers::gui_ExpandBmp()
00225 {
00226 if (!mcMathCore::Get()->isGUIEnabled())
00227 return;
00228
00229
00230 mcASSERT(mgui_bmpMath.Ok(), wxT("Bitmap has been destroyed"));
00231
00232
00233 int w = gui_GetWidth();
00234 int h = gui_GetHeight();
00235
00236
00237
00238 int neww=mgui_bmpMath.GetWidth(), newh=mgui_bmpMath.GetHeight();
00239
00240
00241 while(newh < h)
00242 newh += mcBMP_ADDEDHEIGHT;
00243 while (neww < w)
00244 neww += mcBMP_ADDEDWIDTH;
00245
00246
00247 if (mgui_bmpMath.GetWidth() == neww && mgui_bmpMath.GetHeight() == newh)
00248 return;
00249
00250
00251 mgui_bmpMath.Create(neww, newh);
00252 }
00253
00254 int mcMathLineHelpers::gui_MoveCursorUsingPoint(wxDC &dc, const wxPoint &p)
00255 {
00256 wxPoint pt(p.x-mcBMP_SPACELEFT, p.y);
00257
00258
00259 return mcMathMngHelpers::gui_MoveCursorUsingPoint(dc, pt);
00260 }
00261
00262 void mcMathLineHelpers::gui_OnSelect(wxDC &dc, wxRect &rc)
00263 {
00264
00265
00266 rc.Offset(-mcBMP_SPACELEFT, 0);
00267 mcMathMngHelpers::gui_OnSelect(dc, rc);
00268 }
00269
00270 mcElement mcMathLineHelpers::gui_GetSelection() const
00271 {
00272 mcMathMng mng(mcMathMngHelpers::gui_GetSelection());
00273
00274
00275 return mcMathLine(mng);
00276 }
00277
00278 void mcMathLineHelpers::gui_DoRecalcSize()
00279 {
00280 mcMathMngHelpers::gui_DoRecalcSize();
00281 mgui_sz.SetWidth(mgui_sz.GetWidth()+mcBMP_SPACELEFT+mcBMP_SPACERIGHT);
00282
00283
00284 gui_ExpandBmp();
00285 }
00286
00287
00288
00289
00290
00291
00292