Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

MathLine.cpp

Go to the documentation of this file.
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 // optimization for GCC compiler
00034 #ifdef __GNUG__
00035 #pragma implementation "MathLine.h"
00036 #endif
00037 
00038 // includes
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 // setup static variables
00053 int mcMathLineHelpers::sgui_nCursorWidth = 2;
00054 
00055 
00056 #ifdef mcMATHLINE_DONOT_USE_BITMAP
00057 wxPoint lastpos;
00058 #endif
00059 
00060 
00061 // global objects
00062 mcMathLine mcEmptyLine(NULL);
00063 
00064 
00065 
00066 
00067 // ----------------------------------------
00068 // mcMATHLINEDATA
00069 // ----------------------------------------
00070 
00071 #ifdef __MCDEBUG__
00072 
00073 wxString mcMathLineHelpers::data_Debug(long flags) const
00074 {
00075  wxString longstr, str;
00076  //int step = mcMathCore::Get()->m_nIndentationStep;
00077 
00078  // typically, debug info generated by mcElement::data_GetDebug() function are
00079  // very very long....
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   // returns debug info about line math object and the bitmap
00089   return longstr.Format(
00090    wxT("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n%s%s"), 
00091    str.c_str(), mcMathMngHelpers::data_Debug(flags).c_str());
00092   
00093  }
00094 
00095  // do not add any particular debug info...
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  // deep copy the math obj and then expand the bitmap
00106  mcMathMngHelpers::data_DeepCopy(mbl);
00107  gui_ExpandBmp();
00108  
00109  // copy simple data
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 // mcMATHLINE - GUI functions
00122 // ----------------------------------------
00123 
00124 void mcMathLineHelpers::gui_Init()
00125 {
00126  // default values
00127  mgui_nLastID = mgui_nCurrentID = -1;
00128  mgui_bUsingMask = FALSE;
00129 
00130  // as default, use white as background colour
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  //gui_ExpandBmp();
00146 
00147  // clear the bitmap using our background brush
00148  memDC.SelectObject(mgui_bmpMath);
00149  memDC.SetBackground(mgui_brushBmpBg);
00150  memDC.Clear();
00151 
00152  // convert from screen (or window) coord. to bitmap coord.
00153  // please note that 'p' should CONTAIN COORDINATES RELATIVE 
00154  // TO THE POINT (0;0) *NOT* TO (x;y)
00155  wxPoint newpt = pt;
00156  if (flags & mcDRW_USEPOINT) {
00157 
00158   // and transform from screen2line bitmap
00159   newpt.x -= x;
00160   newpt.y -= y;
00161  }
00162  
00163  // gui_Draw the math object on the line's bitmap with activation
00164  // and selection state; 
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  // draw the most updated bmp of the math obj
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  // thanks to wxWidgets this is a very easy operation...
00206  mgui_bmpMath.SetMask(new wxMask(mgui_bmpMath, col));
00207 
00208  // set the flag
00209  mgui_bUsingMask = TRUE;
00210 }
00211 
00212 int mcMathLineHelpers::gui_GetRelCursorPos(wxDC &dc, wxPoint *pt) const
00213 {
00214  // get cursor position
00215  int n = mcMathMngHelpers::gui_GetRelCursorPos(dc, pt);
00216  
00217  // correct the cursor pos, adding offsetx and vertically center cursor
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  // bitmap must have been already created
00230  mcASSERT(mgui_bmpMath.Ok(), wxT("Bitmap has been destroyed"));
00231  
00232  // expand the bitmap to the object size
00233  int w = gui_GetWidth();
00234  int h = gui_GetHeight();
00235  
00236  // the new width and height; set them initially as
00237  // the width and height of the current bitmap
00238  int neww=mgui_bmpMath.GetWidth(), newh=mgui_bmpMath.GetHeight();
00239  
00240  // if the bitmap is too small to store the given size, enlarge it
00241  while(newh < h)
00242   newh += mcBMP_ADDEDHEIGHT;
00243  while (neww < w)
00244   neww += mcBMP_ADDEDWIDTH;
00245  
00246  // we don't need to change anything if bmp is big enough
00247  if (mgui_bmpMath.GetWidth() == neww && mgui_bmpMath.GetHeight() == newh)
00248   return;
00249  
00250  // create a larger bitmap
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  // move the cursor in the math obj and return result code
00259  return mcMathMngHelpers::gui_MoveCursorUsingPoint(dc, pt);
00260 }
00261 
00262 void mcMathLineHelpers::gui_OnSelect(wxDC &dc, wxRect &rc)
00263 {
00264  // remember to offset the object with the mcBMP_SPACELEFT value
00265  // (see data_UpdateLineBmp function)...
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  // just convert the mcMathMng to a mcMathLine
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  // maybe we need to expand our bitmap...
00284  gui_ExpandBmp();
00285 }
00286 
00287 
00288 
00289 
00290 
00291 
00292 


Documentation generated with Doxygen on Sun Feb 6 17:10:47 2005
Visit MathStudio home page for more info

[ Top ]