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

EmptyBox.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 //                                                                   //
00031 
00032 
00033 
00034 // optimization for GCC compiler
00035 #ifdef __GNUG__
00036 #pragma implementation "EmptyBox.cpp"
00037 #endif
00038 
00039 // includes
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/MathCore.h"
00048  #include "mc/ElementArray.h"
00049  #include "mc/EmptyBox.h"
00050  #include "mc/Parenthesis.h"
00051 #endif
00052 
00053 
00054 mcIMPLEMENT_MAIN_CLASS(mcEmptyBox, mcDecoration);
00055 
00056 
00057 // setup customizable variables
00058 float mcEmptyBoxHelpers::sgui_fEmptyBoxCharWidth =
00059 #ifdef __WXMSW__
00060  3.0f;
00061 #else
00062  2.0f;
00063 #endif
00064 float mcEmptyBoxHelpers::sgui_fEmptyBoxCharHeight = 0.8f;
00065 wxBrush *mcEmptyBoxHelpers::sgui_pEmptyBoxBrush = NULL;
00066 
00067 // This is the special key which must be used to create a new fraction
00068 // through the mcElementGUI input system. It is set in 
00069 // mcMathCore::Setugui(), as all other static variables (see that 
00070 // function for more info about this), to "x+127".
00071 // This is not a simple CTRL+127 combination because gui_isBeginKey() will
00072 // return TRUE only if the given key is set as a special key.
00073 mcKey *mcEmptyBoxHelpers::sgui_pNewEmptyBox = NULL;
00074 
00075 
00076 
00077 
00078 
00079 // ----------------------------------------
00080 // mcEMPTYBOXGUI
00081 // ----------------------------------------
00082 
00083 bool mcEmptyBoxHelpers::gui_isEndKey(const mcKey &key) const
00084 { 
00085  // the mcMonomial, which are always the parents of mcEmptyBox,
00086  // should be able to handle the mcIR_REPLACE_THIS flag even if the
00087  // replacement element is a mult/div op; this is why we check here,
00088  // for mcAddOp and mcSubOp only...
00089  //
00090  // IMPORTANT: we also make an exception for right mcParentheses:
00091  //            they are handled by mcMonomial...
00092  //
00093  mcElementType m = mcElementHelpers::gui_isKeyBeginKey(key);
00094  wxChar c = key.GetKeyCode();
00095 
00096  if (m == mcET_ADDOP || m == mcET_SUBOP || 
00097   (m == mcET_PARENTHESIS && mcBracketHelpers::gui_isRightParenthesis(c)))
00098   return TRUE;
00099 
00100  return FALSE;
00101 }
00102 
00103 void mcEmptyBoxHelpers::gui_DoRecalcSize()
00104 {
00105  wxScreenDC dc;
00106 
00107  // Returns the size (in pixels) of an empty box.
00108  // You can't use directly m_fEmptyBoxCharWidth/HEIGHT
00109  // values to get empty boxeswxT(' size: they')re expressed in 'character'
00110  // units; this function works as a characters2pixels converter.
00111  mgui_sz = wxSize((int)(gui_GetWidthOfChar(&dc, this)*sgui_fEmptyBoxCharWidth),
00112     (int)(gui_GetHeightOfChar(&dc, this)*sgui_fEmptyBoxCharHeight));
00113 }
00114 
00115 mcInputRes mcEmptyBoxHelpers::gui_Input(const mcKey &key, mcElement *e)
00116 {
00117  mcElementType m;
00118 
00119  // except for m_pDeleteKey, and the first character received immediately
00120  // after allocation, all the characters typed in an empty box
00121  // replace the empty box itself...
00122  if (!data_hasProperty(mcEP_INITIALIZED)) {
00123 
00124   // we're now ready to work...
00125   data_AddProperty(mcEP_INITIALIZED);
00126   gui_RecalcSize();
00127 
00128   return mcIR_OKAY;
00129  }
00130 
00131  // handle delete & cancel keys
00132  if (mcMathCore::Get()->m_pDeleteKey->MatchKey(key) ||
00133   mcMathCore::Get()->m_pCancelKey->MatchKey(key))
00134   return mcIR_DIRECT_DELETE;
00135 
00136  // create a new element with the given key
00137  if (((m=mcElementHelpers::gui_isKeyBeginKey(key)) != mcET_INVALID)) {
00138 
00139   // create a new element of the right type
00140   mcElement replacement = mcElementHelpers::data_NewElem(m);
00141   replacement.gui_Input(key, NULL);
00142   (*e) = replacement;
00143 
00144  } else {
00145 
00146   // not a delete/cancel key nor a new class begin char ?
00147   mcMathCore::Get()->SyntaxError(wxT("Unrecognized character"));
00148   return mcIR_OKAY;
00149  }
00150 
00151  // replace this empty box with the new element stored in pnew
00152  return mcIR_REPLACE_THIS;
00153 }
00154 
00155 mcInsertRes mcEmptyBoxHelpers::gui_Insert(const mcElement &toinsert, mcElement *newelem)
00156 {
00157  //(*newelem) = mcElement(this);
00158  (*newelem) = toinsert;
00159  return mcINSR_REPLACE_THIS;
00160 }
00161 
00162 mcMoveCursorRes mcEmptyBoxHelpers::gui_MoveCursor(mcMoveCursorFlag flag, long modifiers)
00163 {
00164  // manage cursor movement for empty boxes
00165  if (flag == mcMCF_LEFT) return mcMCR_SETFOCUS_PREVIOUS;
00166  if (flag == mcMCF_RIGHT) return mcMCR_SETFOCUS_NEXT;
00167  if (flag == mcMCF_UP) return mcMCR_SETFOCUS_ABOVE;
00168  if (flag == mcMCF_DOWN) return mcMCR_SETFOCUS_BELOW;
00169 
00170  // flag should be MC_USEPOINT...
00171  return mcMCR_OKAY;
00172 }
00173 
00174 int mcEmptyBoxHelpers::gui_MoveCursorUsingPoint(wxDC &, const wxPoint &)
00175 {
00176  // we don't have any cursor variable because, if the
00177  // cursor is inside this element, it can be placed
00178  // in one position only...
00179  return mcMCR_OKAY;
00180 }
00181 
00182 int mcEmptyBoxHelpers::gui_GetRelCursorPos(wxDC &, wxPoint *pt) const
00183 {
00184  int h = (int)((gui_GetHeight()/100.)*70.);
00185 
00186  // cursor is always at the beginning....
00187  pt->x = (int)((gui_GetWidth()/100.)*49.); // place cursor at the 49% of the empty box
00188  pt->y = (gui_GetHeight()-h)/2;
00189 
00190  // cursor height = empty box height
00191  return h;//gui_GetHeight();
00192 }
00193 
00194 int mcEmptyBoxHelpers::gui_Draw(wxDC &dc, int x, int y, long flags, const wxPoint &pt) const
00195 {
00196  // draw the rect filled with the right color
00197  dc.SetBrush(*sgui_pEmptyBoxBrush);
00198  dc.SetPen(*wxBLACK_PEN);
00199  dc.DrawRectangle(x, y, gui_GetWidth(), gui_GetHeight());
00200 
00201  if (flags & mcDRW_USEPOINT || flags & mcDRW_ALLACTIVE)
00202   return data_GetID();
00203  return mcDRW_NOACTIVEELEM;
00204 }
00205 
00206 
00207 
00208 
00209 
00210 
00211 // ----------------------------------------
00212 // mcEMPTYBOXIO
00213 // ----------------------------------------
00214 
00215 wxXml2Node mcEmptyBoxHelpers::io_GetMathML(bool bGetPresentation) const
00216 {
00217  mcUNUSED(bGetPresentation);
00218  
00219  // use a new tag (both for presentation & content MathML)
00220  // specific for MathCore: MEMPTYBOX
00221  return wxXml2Node(wxXML_ELEMENT_NODE, wxXml2EmptyDoc, wxT("memptybox"));
00222 }
00223 
00224 wxString mcEmptyBoxHelpers::io_GetInlinedExpr() const
00225 {
00226  // an emptybox cannot be exported nor in MathML nor as an inlined expr
00227  return io_GetInlinedExprTag();
00228 }
00229 
00230 bool mcEmptyBoxHelpers::io_ImportPresentationMathML(wxXml2Node tag, wxString &pErr)
00231 {
00232  mcASSERT(tag.GetName() == wxT("memptybox"), wxT("Error in mcEmptyBoxHelpers::io_isBeginTag()"));
00233 
00234  if (tag.GetChildren() != NULL) {
00235   pErr = wxT("An empty box tag (specific for MathCore, not part of MathML 2.0)\n")
00236     wxT("cannot contain children.");
00237   return FALSE;
00238  }
00239 
00240  return TRUE;
00241 }
00242 
00243 
00244 


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

[ Top ]