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

Decoration.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 "Decoration.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 "mc/Element.h"
00047  #include "mc/Decoration.h"
00048  #include "mc/MathCore.h"
00049  #include "mc/Monomial.h"
00050 #endif
00051 
00052 
00053 
00054 mcIMPLEMENT_ABSTRACT_CLASS(mcDecoration, mcElement);
00055 
00056 
00057 
00058 // ----------------------------------------
00059 // mcDECORATIONGUI
00060 // ----------------------------------------
00061 
00062 bool mcDecorationHelpers::gui_isEndKey(const mcKey &key) const
00063 {
00064  if (mcMathCore::Get()->MatchEditKeys(key))
00065   return FALSE;
00066  return TRUE;
00067 }
00068 
00069 mcInputRes mcDecorationHelpers::gui_Input(const mcKey &key, mcElement *)
00070 {
00071  // we must intercept the first keypress sent to us, since it is the
00072  // creation character and it should be discarded...
00073  if (!data_hasProperty(mcEP_INITIALIZED)) {
00074   data_AddProperty(mcEP_INITIALIZED);
00075   gui_RecalcSize();
00076 
00077   // next character will be handled....
00078   return mcIR_OKAY;
00079  }
00080 
00081  // handle delete & cancel keys
00082  if (mcMathCore::Get()->m_pDeleteKey->MatchKey(key) ||
00083   mcMathCore::Get()->m_pCancelKey->MatchKey(key))
00084   return mcIR_DELETE_THIS;
00085 
00086  // replace this empty box with the new element stored in pnew
00087  return mcIR_OKAY;
00088 }
00089 
00090 mcMoveCursorRes mcDecorationHelpers::gui_MoveCursor(mcMoveCursorFlag flag, long modifiers)
00091 {
00092  // manage cursor movement for empty boxes
00093  if (flag == mcMCF_UP) return mcMCR_SETFOCUS_ABOVE;
00094  if (flag == mcMCF_DOWN) return mcMCR_SETFOCUS_BELOW;
00095  if (flag == mcMCF_LEFT && gui_GetCursorPos().isBegin()) return mcMCR_SETFOCUS_PREVIOUS;
00096  if (flag == mcMCF_RIGHT && gui_GetCursorPos().isEnd()) return mcMCR_SETFOCUS_NEXT;
00097 
00098  if (flag == mcMCF_LEFT)
00099   mgui_nCursorPos = mcDECORATION_LEFT;
00100  if (flag == mcMCF_RIGHT)
00101   mgui_nCursorPos = mcDECORATION_RIGHT;
00102 
00103  // flag should be MC_USEPOINT...
00104  return mcMCR_OKAY;
00105 }
00106 
00107 int mcDecorationHelpers::gui_MoveCursorUsingPoint(wxDC &, const wxPoint &p)
00108 {
00109  if (p.x > gui_GetWidth()/2)
00110   mgui_nCursorPos = mcDECORATION_RIGHT;
00111  else
00112   mgui_nCursorPos = mcDECORATION_LEFT;
00113  return mcMCR_OKAY;
00114 }
00115 
00116 int mcDecorationHelpers::gui_GetRelCursorPos(wxDC &, wxPoint *pt) const
00117 {
00118  int m = (gui_GetCursorPos().isBegin()) ? 0 : 1;
00119 
00120  // cursor can be placed only on left/right of this element
00121  pt->x = gui_GetWidth()*m;
00122  pt->y = 0;
00123 
00124  // cursor height
00125  return gui_GetHeight();
00126 }
00127 
00128 void mcDecorationHelpers::gui_SetCursorPos(const mcCursorPos &code)
00129 {
00130  if (code.isBegin())
00131   mgui_nCursorPos = mcDECORATION_LEFT;
00132  if (code.isEnd())
00133   mgui_nCursorPos = mcDECORATION_RIGHT;
00134 }
00135 
00136 void mcDecorationHelpers::gui_GetCursorPos(mcCursorPos &cp) const
00137 {
00138  if (mgui_nCursorPos == mcDECORATION_LEFT)
00139   cp.gui_Push(mcCP_BEGIN);
00140  else if (mgui_nCursorPos == mcDECORATION_RIGHT)
00141   cp.gui_Push(mcCP_END);
00142  else
00143   cp.gui_Push(mgui_nCursorPos); // this should not be used by mcDecoration !!!
00144 }
00145 
00146 
00147 
00148 // ----------------------------------------
00149 // mcDECORATIONIO
00150 // ----------------------------------------
00151 
00152 wxXml2Node mcDecorationHelpers::io_GetMathML(bool bGetPresentation) const
00153 {
00154  mcUNUSED(bGetPresentation);
00155 
00156  // use a new tag (both for presentation & content MathML)
00157  // specific for MathCore: MDECORATION
00158  return wxXml2Node(wxXML_ELEMENT_NODE, wxXml2EmptyDoc, wxT("mdecoration"));
00159 }
00160 
00161 wxString mcDecorationHelpers::io_GetInlinedExpr() const
00162 {
00163  // a decoration usually doesn't have any inlined expression equivalent...
00164  return wxT("~");
00165 }
00166 
00167 bool mcDecorationHelpers::io_ImportPresentationMathML(wxXml2Node tag, wxString &pErr)
00168 {
00169  mcASSERT(tag.GetName() == wxT("mdecoration"), wxT("Error in mcDecorationHelpers::io_isBeginTag()"));
00170 
00171  if (tag.GetChildren() != NULL) {
00172   pErr = wxT("A decoration tag (specific for MathCore, not part of MathML 2.0)\n")
00173     wxT("cannot contain children.");
00174   return FALSE;
00175  }
00176 
00177  return TRUE;
00178 }
00179 
00180 bool mcDecorationHelpers::io_ImportInlinedExpr(const wxString &, int *count, wxString &pErr)
00181 {
00182  // FIXME: is this correct ?
00183  *count = 0;
00184  pErr = wxT("");
00185  
00186  return TRUE;
00187 }
00188 
00189 
00190 
00191 // ----------------------------------------
00192 // mcDECORATIONMATH
00193 // ----------------------------------------
00194 
00195 mcMonomial mcDecorationHelpers::math_GetGCD(const mcElement &) const
00196 { return mcEmptyElement; }
00197 
00198 mcMonomial mcDecorationHelpers::math_GetLCM(const mcElement &) const
00199 { return mcEmptyElement; }
00200 


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

[ Top ]