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

mgMathBox Class Reference

#include <MathBox.h>

List of all members.


Detailed Description

A window using a mcMathOrSystem to create the ouput.

mgMathBox class works as a normal wxWindow; so you can allocate, delete or copy mgMathBox windows without problems.

mgMathBox can be considered as a "math text control": a control where math expressions can be typed using all MathCore and MathGUI facilities.

Through EnableXXXX() and DisableXXXX() you can modify the behaviour of the window.

Definition at line 160 of file MathBox.h.

Public Member Functions

 mgMathBox (wxWindow *parent, wxWindowID id=-1, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxSUNKEN_BORDER|wxNO_FULL_REPAINT_ON_RESIZE, const wxString &name=wxT("mgMathBox"))
 Default constructor. Builds and initialize this window.
 mgMathBox (const mgMathBox &tocopy)
 Copy constructor.
virtual ~mgMathBox ()
 Destructor.
Miscellaneous functions
Some miscellaneous functions.

void DeepCopy (const mgMathBox &)
 Copies in this object all the data of the given mathbox.
mcMathOrSystem & GetMathObj ()
 Returns a pointer to the contained mcMathOrSystem.
const mcMathOrSystem & GetMathObj () const
void EnableInput (bool bEnable=TRUE)
 Enables/disables the keyboard input for this window (by default, it's on).
void EnableSelection (bool bEnable=TRUE)
 Enables/disables the selection for this window (by default, it's on).
void EnableContextMenu (bool bEnable=TRUE)
 Enables/disables the context menu for this window (by default, it's on).
void EnablePreProcessing (bool bEnable=TRUE)
 Enables/disables the preprocessing of messages under Win32.
void DisableInput ()
void DisableSelection ()
void DisableContextMenu ()
void DisablePreProcessing ()
void SetClientEvtHandler (wxEvtHandler *p)
 Sets the client event handler which will receive the mgEVT_ACTIVE_ELEM_CHANGED notification events.
mcElement GetActiveElem (const wxPoint &pos, const wxPoint &pt) const
 Returns the currently active element (that is, the element which is currently under the mouse cursor).
mcElement GetElemFromID (int id) const
 Returns the element with the given ID or NULL if there is no element with such an ID in this box.
wxString GetDebug () const
 Returns a string with debug info about this window.
GUI functions regarding SIZE and POSITION
Functions which make graphical input/output easier; most of these have the same name and behave like mcElementGUI functions.

void FitContents ()
 Updates the size of the window adapting it to the size of the contained math data, plus some corner space around it.
void SetSizeHintsToFitContents ()
 Sets the size hints for this window.
wxSize GetContentSize () const
 Returns the size of the mcMathOrSystem contained with also the empty space which is left by mgMathBox around it.
void Clean ()
 Deletes all the data from the window: data lines, bitmaps and everything else; then, adds a new empty line and selects it.
int GetXPos () const
 Returns the x-offset of the contained math data.
int GetYPos () const
 Returns the y-offset of the contained math data.
wxRect GetRectOfContents ()
 Returns a wxRect initialized with the math content's bounding box.
UPDATE functions
Functions which update the internal state of this mgMathBox.

int UpdateMathBmp (long flags, const wxPoint &p=wxDefaultPosition)
 Updates the bitmap in the mcMathLine structure for the n-th line, using the given flags (and eventually the given point object).
void UpdateContentPos ()
 Updates the math content's position using the current client size.
void UpdateCaretPos ()
 Updates the cursor position after a change in the size of the selected line; you should refresh the window after a call to this function, or, at least, redraw the selected line.
void UpdateCaret ()
 Updates the caret of this window, eventually showing/hiding it.
void UpdateMathBmpWithCurrentPos ()
 Updates the bitmap in the mcMathLine structure for the n-th line, using the current mouse position as argument for UpdateMathBmp.
void ForceBmpUpdate ()
 Forces the update of the entire math contents.
Miscellaneous


void RedrawMath (wxDC &dc, int x, int y)
 Redraws the math contents on the screen, after hiding the caret.
void GetContextMenu (wxMenu &, const mcElement &selected) const
 Returns the context menu with all the available commands for the currently selected element, which is given.
void CheckReturnFlag (int res)
 Checks the return code of the mcElement::MoveCursor function.
void ResetGUI ()
 Resets all the GUI of the mcMathOrSystem.
bool isSelecting () const
 Returns TRUE if the user is dragging a selection rectangle.
void ResetSelectionRect ()
 Resets the selection rectangle to a NULL rect.
void DeSelect ()
 Deselects the contained math data.
void SetStyleArray (mcStyleArray *p)
 Changes the array of styles used by this window.
Context menu handlers
Various functions which are born to handle context menu commands but can be safely called also from external functions which handle, for example, toolbars or menus...

void InsertFraction ()
void InsertRadical ()
void InsertFunction ()
void EditExponent ()
void EditSubscript ()
void Cut (const mcElement &sel=mcEmptyElement)
void CopyAsPlainText (const mcElement &sel=mcEmptyElement)
void CopyAsMathML (const mcElement &sel=mcEmptyElement)
void Paste (const mcElement &sel=mcEmptyElement)
void EmbedAsFractionNum (const mcElement &sel=mcEmptyElement)
void EmbedAsFractionDen (const mcElement &sel=mcEmptyElement)
void EmbedAsRadical (const mcElement &sel=mcEmptyElement)
wxWindow's EVENT HANDLERS
Functions linked with wxWindow's events.

void OnSetFocus (wxFocusEvent &)
void OnFocusLost (wxFocusEvent &)
void OnTimer (wxTimerEvent &)
void OnPaint (wxPaintEvent &)
void OnSize (wxSizeEvent &)
void OnLDown (wxMouseEvent &)
void OnLUp (wxMouseEvent &)
void OnRUp (wxMouseEvent &)
void OnMouseMove (wxMouseEvent &)
void OnSetCursor (wxSetCursorEvent &)
void OnLeaveWindow (wxMouseEvent &)
void OnCtxMenuItem (wxCommandEvent &)
void OnChar (wxKeyEvent &)
void OnSpecialChar (wxKeyEvent &)
Line management functions
These are the functions used by mgMathBox to handle mcMathLine structures.

void AppendEditCommands (wxMenu &)
IO functions
Functions which are used to import/export the math data.

bool Export (bool bXHTML, const wxString &filename, const wxString &title, bool bUpperTag=FALSE, bool bMPSupp=FALSE, bool bUseNS=FALSE, const wxString &ns=wxEmptyString, const wxString &href=wxEmptyString, int indstep=2) const
 Just choose a filename and a title for a new page, and this function will magically create a complete file containing all the mathematical data currently displayed in this window.
bool Export (bool bXHTML, wxOutputStream &str, const wxString &title, bool bUpperTag=FALSE, bool bMPSupp=FALSE, bool bUseNS=FALSE, const wxString &ns=wxEmptyString, const wxString &href=wxEmptyString, int indstep=2) const
 Exports the math data and works exactly as the other Export overload but it accepts a wxOutputStream instead of a file name.
wxString GetExportPreview (bool bXHTML, const wxString &title, bool bUpperTag=FALSE, bool bMathPlayerSupport=FALSE, bool bUseNS=FALSE, const wxString &ns=wxEmptyString, const wxString &href=wxEmptyString, int indentstep=2) const
 Returns an (usually) huge wxString containing the exported XHTML/XML math data.
wxXml2Node GetMathML (bool bGetPresentation) const
 Returns the root node associated with the mcMathOrSystem contained in this box.
wxString GetInlinedExpr () const
 Gets the inlined expression for the math contents.
bool Import (int type, const wxString &filename, wxString *pDesc=NULL)
 Imports XHTML/XML math data.
bool ImportMathML (wxXml2Node pDoc, wxString *pErr)
 Imports MathML already parsed, eventually returning the error description (if an errors occurs, the function returns FALSE).
bool ImportInlinedExpr (const wxString &str)
 Imports the given inlined expression.
wxString ConvertString (const wxString &str) const
 A little utility function which converts "\n" as the native character/pair of characters used to represent newlines (that is "\r\n" on win32), if bUseNativeNewLines is TRUE.

Static Public Attributes

static int nSpaceAround = 5
 Space between the math systems and the left border.
static int nCursorWidth = 2
 Cursor width (in pixels).
static bool bUseNativeNewLines = TRUE
 If TRUE, then all the strings exported by the IO functions and by the GUI functions which output strings in the clipboard, will contain newlines encoded in the native format of the OS this program is running on.
static mgMathBoxCmd cmd [mgMBC_LAST+1]
 The list of the commands (ID+description) shown in the context menu.

Protected Member Functions

void Init ()
 Inits the window's own variables. Must be called by constructors only.
mgCaretGetCaret () const
 Returns the caret associated with this window (can be NULL).

Protected Attributes

mcMathOrSystem m_mathContent
 The mcMathOrSystem object contained in this box.
wxPoint m_ptPos
 The current position of the mcMathOrSystem in client coordinates.
wxRect m_rcSelection
 The last selection rectangle.
mcElement m_eSelection
 The last selection.
wxEvtHandler * m_pClient
 The event handler which receives the mgEVT_ACTIVE_ELEM_CHANGED custom events.
bool m_bProcSpecialChar
 If TRUE, we are processing a special character: that is, a character which must be considered as mapped with the 'special' font of mcStyle...
bool m_bAutoExpand
 If TRUE, this window automatically expands when the math content becomes too big.
bool m_bInputEnabled
 If FALSE, this window will refuse any keyboard input and the caret will not be displayed.
bool m_bSelectionEnabled
 If FALSE, the user won't be able to draw selection rects and thus he won't be able to select anything in the window.
bool m_bContextMenuEnabled
 If FALSE, the user won't be able to popup the context menu and thus he won't be able to directly modify the math contents (even if an external function can always call GetMathObj()->MATH_FUNCTION to perform some operation...).
bool m_bPreProcessingEnabled


Constructor & Destructor Documentation

mgMathBox::mgMathBox const mgMathBox tocopy  )  [inline]
 

Copy constructor.

Deep copies the given mgMathBox into this object.

Parameters:
tocopy The box to copy.

Definition at line 284 of file MathBox.h.

References DeepCopy().

virtual mgMathBox::~mgMathBox  )  [inline, virtual]
 

Destructor.

Destroys everything associated with this window, also math data.

Definition at line 288 of file MathBox.h.


Member Function Documentation

void mgMathBox::CheckReturnFlag int  res  ) 
 

Checks the return code of the mcElement::MoveCursor function.

Essentially, this function deselects the math expression if an user clicked on an area not containing any element.

Definition at line 427 of file MathBox.cpp.

void mgMathBox::DeepCopy const mgMathBox  ) 
 

Copies in this object all the data of the given mathbox.

The mathdata associated with this object after a deep copy will be totally independent from original data.

Definition at line 191 of file MathBox.cpp.

References m_bProcSpecialChar, m_mathContent, and m_rcSelection.

Referenced by mgResizeableMathBox::DeepCopy(), and mgMathBox().

bool mgMathBox::Export bool  bXHTML,
wxOutputStream &  str,
const wxString &  title,
bool  bUpperTag = FALSE,
bool  bMPSupp = FALSE,
bool  bUseNS = FALSE,
const wxString &  ns = wxEmptyString,
const wxString &  href = wxEmptyString,
int  indstep = 2
const
 

Exports the math data and works exactly as the other Export overload but it accepts a wxOutputStream instead of a file name.

Parameters:
str The output stream where all the XHTML/XML data is copied.

Definition at line 1199 of file MathBox.cpp.

References m_mathContent.

bool mgMathBox::Export bool  bXHTML,
const wxString &  filename,
const wxString &  title,
bool  bUpperTag = FALSE,
bool  bMPSupp = FALSE,
bool  bUseNS = FALSE,
const wxString &  ns = wxEmptyString,
const wxString &  href = wxEmptyString,
int  indstep = 2
const
 

Just choose a filename and a title for a new page, and this function will magically create a complete file containing all the mathematical data currently displayed in this window.

Because of the lack of a MathML implementation on Internet Explorer, this function will also inform the user, if the program is running on a Win32 system, that he will need an external program to view the file with IE: a link to MathPlayer homepage will be displayed.

This function can export the data both as XHTML and as XML. The differences between the two files are just on the headers, but the XML file needs some external XSL files (the XML file that is created is linked with the XSL files of MathStudio 'XSL' subfolder with absolute path link).

Parameters:
bXHTML If TRUE, an XHTML is exported; otherwise a pure XML file.
filename The name of a new XHTML/XML file that will be created.
title The title of the new XHTML/XML file.
bUpperTag If TRUE, tags are exported in UPPERCASE.
bMPSupp If TRUE, then math player support is enabled, adding some specific tags...
bUseNS If TRUE, then a namespace is used for MathML tags.
ns If bUseNS == TRUE, then this is the namespace used.
href 
indstep NOT WORKING
Returns:
TRUE if everything went okay. FALSE if something was wrong; if something was wrong, the function will also advise the user with a message box.

Definition at line 1155 of file MathBox.cpp.

Referenced by GetExportPreview().

void mgMathBox::ForceBmpUpdate  ) 
 

Forces the update of the entire math contents.

This function should not be used to often if you want to avoid flickering.

Definition at line 377 of file MathBox.cpp.

References GetXPos(), GetYPos(), m_mathContent, and RedrawMath().

Referenced by ResetGUI().

wxString mgMathBox::GetExportPreview bool  bXHTML,
const wxString &  title,
bool  bUpperTag = FALSE,
bool  bMathPlayerSupport = FALSE,
bool  bUseNS = FALSE,
const wxString &  ns = wxEmptyString,
const wxString &  href = wxEmptyString,
int  indentstep = 2
const
 

Returns an (usually) huge wxString containing the exported XHTML/XML math data.

It accepts the same parameters as the Export function.

Definition at line 1184 of file MathBox.cpp.

References Export().

wxXml2Node mgMathBox::GetMathML bool  bGetPresentation  )  const [inline]
 

Returns the root node associated with the mcMathOrSystem contained in this box.

For more info see mcMathOrSystem::GetMathML().

Definition at line 622 of file MathBox.h.

References m_mathContent.

Referenced by mgResizeableMathBox::GetMathML().

void mgMathBox::RedrawMath wxDC &  dc,
int  x,
int  y
 

Redraws the math contents on the screen, after hiding the caret.

This function automatically calls UpdateCaret() before exiting, so that the caret is restored, if necessary. Since drawing could be corrupted if done when the caret is blinking in the blit area, the direct call m_mathContent.gui_DrawBmp(....); should NEVER be used.

Definition at line 400 of file MathBox.cpp.

References mgCaret::ForceHide(), GetCaret(), m_mathContent, and UpdateCaret().

Referenced by ForceBmpUpdate(), and UpdateMathBmp().

void mgMathBox::SetClientEvtHandler wxEvtHandler *  p  )  [inline]
 

Sets the client event handler which will receive the mgEVT_ACTIVE_ELEM_CHANGED notification events.

By default, client event handler is set, by constructor, as the parent window. Use NULL to disable mgEVT_ACTIVE_ELEM_CHANGED notification events.

Definition at line 338 of file MathBox.h.

References m_pClient.

void mgMathBox::SetSizeHintsToFitContents  ) 
 

Sets the size hints for this window.

Setting "size hints" means that, after this call, this window will not be able to have a size smaller than the contents size.

Definition at line 252 of file MathBox.cpp.

References FitContents(), and GetContentSize().

void mgMathBox::UpdateContentPos  ) 
 

Updates the math content's position using the current client size.

This function alters the m_ptPos variable.

Definition at line 269 of file MathBox.cpp.

References GetContentSize(), and m_ptPos.

Referenced by FitContents(), and ResetGUI().

int mgMathBox::UpdateMathBmp long  flags,
const wxPoint &  p = wxDefaultPosition
 

Updates the bitmap in the mcMathLine structure for the n-th line, using the given flags (and eventually the given point object).

If mcMathSystem::gui_NeedsRefresh() returns TRUE after the update, then the function redraws the math bitmap (without erasing the background or calling the Refresh() function to avoid flickering).

Parameters:
flags The flags given to the mcMathSystem::gui_UpdateBmp function.
p A valid wxPoint class, if you want to save in the bitmap also an eventual activation state.
Returns:
The ID of the active element.

Definition at line 323 of file MathBox.cpp.

References GetXPos(), GetYPos(), m_mathContent, m_pClient, and RedrawMath().

Referenced by UpdateMathBmpWithCurrentPos().


Member Data Documentation

bool mgMathBox::bUseNativeNewLines = TRUE [static]
 

If TRUE, then all the strings exported by the IO functions and by the GUI functions which output strings in the clipboard, will contain newlines encoded in the native format of the OS this program is running on.

If FALSE, all strings exported will contain newlines as "\n" (which are not correctly recognized as newlines under win32 and mac).

Definition at line 66 of file MathBox.cpp.

Referenced by ConvertString().

mgMathBoxCmd mgMathBox::cmd [static]
 

Initial value:

 
{
   
   { mgMBC_CUT, wxT("Cut") },
   { mgMBC_COPY_ASPLAIN, wxT("Copy as plain text") },
   { mgMBC_COPY_ASMATHML, wxT("Copy as MathML") },
   { mgMBC_PASTE, wxT("Paste") },
   { mgMBC_SELECTALL, wxT("Select all") },

   { mgMBC_CREATENEW_ANDLINE, wxT("Create a new line connected with AND") },
   { mgMBC_CREATENEW_ORLINE, wxT("Create a new line connected with OR") },
   { mgMBC_SIMPLEEND, wxT("") },

   
   { mgMBC_EMBED_NUMFRACTION, wxT("Embed as num of a fraction") },
   { mgMBC_EMBED_DENFRACTION, wxT("Embed as den of a fraction") },
   { mgMBC_EMBED_RADICAL, wxT("Embed into a radical") },
   { mgMBC_EMBED_BRACKET, wxT("Bracketize") },  
   { mgMBC_ADVEND, wxT("") },





   { mgMBC_LAST, wxT("") }
}
The list of the commands (ID+description) shown in the context menu.

These commands are usually called also from menus or toolbars, and this variable can be very useful in this case to synchronize toolbar & menu items' descriptions with the context menu items.

Definition at line 69 of file MathBox.cpp.

Referenced by GetContextMenu().

bool mgMathBox::m_bInputEnabled [protected]
 

If FALSE, this window will refuse any keyboard input and the caret will not be displayed.

Otherwise, normal input behaviour is used.

Definition at line 207 of file MathBox.h.

Referenced by UpdateCaret().

wxRect mgMathBox::m_rcSelection [protected]
 

The last selection rectangle.

This value is affected mainly by: 1) the m_bInputEnabled variable which forces the window to the standard cursor instead of the IBEAM one 2) the selection system status: when dragging a selection rectangle, the cursor is changed to the standard one.

Definition at line 179 of file MathBox.h.

Referenced by DeepCopy(), isSelecting(), and ResetSelectionRect().


The documentation for this class was generated from the following files:

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

[ Top ]