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

MultDivOp.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 "MultDivOp.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/MultDivOp.h"
00046  #include "mc/ElementArray.h"
00047 #endif
00048 
00049 
00050 
00051 mcIMPLEMENT_MAIN_CLASS(mcMultDivOp, mcOperator);
00052 
00053 
00054 // setup customizable variables
00055 bool mcMultDivOpHelpers::sgui_bUseColon = TRUE;
00056 
00057 
00058 
00059 
00060 
00061 // -----------------
00062 // mcMULTDIVOP
00063 // -----------------
00064 
00065 mcMultDivOp::mcMultDivOp(mcElementType t)
00066 {
00067  // be sure that everything is okay
00068  mcASSERT(t == mcET_DIVOP || 
00069   t == mcET_MULTOP, wxT("Invalid element type"));
00070  
00071  mcCREATE_HELPER_CLASSES(mcMultDivOp);
00072  
00073  // we are now ready
00074  data_AddProperty(mcEP_INITIALIZED);
00075  if (hlp()->data_GetType() != t)
00076   hlp()->mdata_nType = t;
00077 }
00078 
00079 
00080 
00081 
00082 // -----------------
00083 // mcMULTDIVOPGUI
00084 // -----------------
00085 
00086 bool mcMultDivOpHelpers::gui_isBeginKey(const mcKey &key) const
00087 {
00088  if (data_isMultOp())
00089   return mcOperatorHelpers::gui_isBeginKey(key);
00090 
00091  wxChar str = (wxChar)key.GetKeyCode();
00092  if (key.GetModifiers() == 0 && data_GetOpSymbol().GetChar(0) == str)
00093   return TRUE;
00094  if (key.GetModifiers() == SHIFT_KEY && data_GetOpSymbol().GetChar(1) == str)
00095   return TRUE;
00096  return FALSE;
00097 }
00098 
00099 void mcMultDivOpHelpers::gui_DoRecalcSize()
00100 {
00101  /*if (data_isDivOp()) {
00102 
00103  */ // standard version is okay for us
00104   mcOperatorHelpers::gui_DoRecalcSize();
00105  /* return;
00106  }
00107 
00108  mgui_sz = gui_GetSizeOfChar(NULL, this);
00109  mgui_sz.SetWidth((int)(mgui_sz.GetWidth()*0.8));
00110  mgui_sz.SetHeight((int)(mgui_sz.GetHeight()*0.8));*/
00111 }
00112 
00113 int mcMultDivOpHelpers::gui_Draw(wxDC &hDC, int Offsetx, int Offsety, long flags, const wxPoint &pt) const
00114 {
00115  if (mgui_sz.GetWidth() == 0 || mgui_sz.GetHeight() == 0)
00116   return -1;
00117  
00118  if (data_isDivOp()) {
00119 
00120   // draw the symbol using correct colors and fonts
00121   gui_SelectStyle(hDC);
00122   
00123   hDC.DrawText(data_GetOpSymbol().GetChar(sgui_bUseColon),
00124    Offsetx+(mgui_sz.GetWidth()-gui_GetRealSize().GetWidth())/2,
00125    Offsety+(mgui_sz.GetHeight()-gui_GetRealSize().GetHeight())/2);
00126   
00127  } else {
00128   
00129   // select font and colors; to do this we don't have to use
00130   // the standard mcElementHelpers::sgui_SelectStyle(&hDC, hlp()); istruction...
00131   hDC.SetPen(*wxBLACK_PEN);
00132   hDC.SetBrush(*wxBLACK_BRUSH);
00133   
00134   int l = mcMIN(mgui_sz.GetWidth()/5, mgui_sz.GetHeight()/5);
00135   
00136   // draw a circle centered in the rect defined by mgui_sz
00137   // and the point (Offsetx;Offsety)
00138   hDC.DrawEllipse(wxPoint(Offsetx+mgui_sz.GetWidth()/2-l, 
00139         Offsety+mgui_sz.GetHeight()/2-l),
00140       wxSize(2*l, 2*l));
00141  }
00142  
00143  if (!(flags & mcDRW_NONACTIVE))
00144   return data_GetID();
00145  return -1;
00146 }
00147 
00148 
00149 
00150 
00151 // -----------------
00152 // mcMULTDIVOPIO
00153 // -----------------
00154 
00155 wxXml2Node mcMultDivOpHelpers::io_GetMathML(bool bGetPresentation) const
00156 {
00157  /*wxString str;
00158 
00159  // copy in the array the presentation markup for hlp() operator, and return the
00160  // number of characters copied
00161  if (hlp()->data_hasProperty(mcEP_HIDDEN))
00162   str = wxT("⁢");
00163  else
00164   str = ;*/
00165 
00166  // create the subnode
00167  return wxXml2Node(wxXML_TEXT_NODE, wxXml2EmptyDoc, wxT("mo"), wxT("⊗"));
00168 }
00169 
00170 bool mcMultDivOpHelpers::io_ImportPresentationMathML(wxXml2Node tag, wxString &pErr)
00171 {
00172  mcASSERT(tag.GetName() == wxT("mo"), wxT("Error in mcOperator::io_isBeginTag()"));
00173 
00174  if (tag.GetChildren().GetType() != wxXML_TEXT_NODE) {
00175 
00176   // ooooooops
00177   pErr = wxT("The MathML to import is not valid MathML 2.0\n")
00178     wxT("or there was an error while parsing it.");
00179   return FALSE;
00180  }
00181 
00182  // extract data, but don't check it
00183  wxString str = tag.GetChildren().GetContent();
00184  return TRUE;
00185 }
00186 
00187 
00188 
00189 
00190 // -------------------------------------
00191 // All the mcOperator-derived classes
00192 // -------------------------------------
00193 
00194 bool mcMultDivOpHelpers::math_CanBeApplied(const mcElement &l, const mcElement &r) const
00195 { 
00196  if (data_isMultOp())
00197   return l.math_CanBeMultWith(r); 
00198  return l.math_CanBeDivBy(r);
00199 }
00200 
00201 mcBasicOpRes mcMultDivOpHelpers::math_ApplySimple(mcElement &p1, const mcElement &p2) const
00202 {
00203  if (!math_CanBeApplied(p1, p2))
00204   return mcBOR_INVALID;
00205 
00206  if (data_isMultOp())
00207   p1.math_SimpleMultiplyBy(p2);
00208  else
00209   p1.math_SimpleDivideBy(p2);
00210 
00211  return mcBOR_REMOVE_OPERAND;
00212 }
00213 
00214 mcBasicOpRes mcMultDivOpHelpers::math_Apply(mcElement &p1, const mcElement &p2, mcElement *pp) const
00215 {
00216  if (!math_CanBeApplied(p1, p2))
00217   return mcBOR_INVALID;
00218 
00219  if (data_isMultOp())
00220   return p1.math_MultiplyBy(p2, pp);
00221  return p1.math_DivideBy(p2, pp);
00222 }
00223 
00224 
00225 
00226 


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

[ Top ]