mgui/wysiwyg.h

Go to the documentation of this file.
00001 /** 
00002  * \file mgui/wysiwyg.h
00003  * \brief Definitions for MGUI::CTRL_EDIT_TEXT_WYSIWYG classes.
00004  *
00005  * WYSIWYG = What You See Is What You Get
00006  *
00007  * \if NODOC
00008  * $Id: wysiwyg.h_v 1.6 2003/10/03 19:58:19 linux32build!build Exp $
00009  *
00010  * $Log: wysiwyg.h_v $
00011  * Revision 1.6  2003/10/03 19:58:19  linux32build!build
00012  * Doxygen
00013  *
00014  * Revision 1.5  2003/10/01 22:36:11  dwilliss
00015  * *** empty log message ***
00016  *
00017  * Revision 1.4  2003/10/01 22:32:41  dwilliss
00018  * doxygen
00019  *
00020  * Revision 1.3  2003/09/15 13:49:32  fileserver!dwilliss
00021  * Doxygen
00022  *
00023  * Revision 1.2  2003/04/09 20:52:21  dwilliss
00024  * Don't use _T in templates.  MAc's ctype.h defines a global _T
00025  *
00026  * Revision 1.1  2002/10/09 22:26:51  dwilliss
00027  * Initial revision
00028  *
00029  * \endif
00030  **/
00031 
00032 #ifndef  INC_MGUI_WYSIWYG_H
00033 #define  INC_MGUI_WYSIWYG_H
00034 
00035 #ifndef INC_MGUI_CTRL_H
00036 #include <mgui/ctrl.h>
00037 #endif
00038 
00039 #ifndef  INC_MI32_SIMPLEAR_H
00040 #include <mi32/simplear.h>
00041 #endif
00042 
00043 struct TEXTSTYLE;
00044 
00045 namespace MGUI {
00046 
00047 
00048 //===================================================================================================================
00049 //! Multi-line text 'edit' control.
00050 class CTRL_EDIT_TEXT_WYSIWYG : public MGUI::CTRL {
00051    public:
00052 
00053       enum FLAGS {
00054          FLAG_Default =       0x0000,
00055          FLAG_ReadOnly =      0x0001,     //!< User cannot change value
00056          };
00057 
00058       //! Constructor.
00059       CTRL_EDIT_TEXT_WYSIWYG (
00060          );
00061 
00062       //! Destructor.
00063       virtual ~CTRL_EDIT_TEXT_WYSIWYG (
00064          );
00065 
00066       //! Determine if the last edit operation can be undone by a call to the Undo member function.
00067       bool CanUndo (
00068          ) const
00069       #ifdef WIN32_MFC
00070          { return (m_ctrl.CanUndo() != FALSE); }
00071       #endif
00072          ;
00073 
00074       //! Clear entire control to empty string.
00075       void ClearValue (
00076          bool notify = true                  //!< Call OnChangeValue() if control has already been created
00077          );
00078 
00079       //! Clear the current selection
00080       void ClearSelection (
00081          )
00082       #ifdef WIN32_MFC
00083          { m_ctrl.Clear(); }
00084       #endif
00085          ;
00086 
00087       //! Cut the current selection to the clipboard
00088       void CutSelection (
00089          )
00090       #ifdef WIN32_MFC
00091          { m_ctrl.Cut(); }
00092       #endif
00093          ;
00094 
00095       //! Copy the current selection to the clipboard
00096       void CopySelection (
00097          )
00098       #ifdef WIN32_MFC
00099          { m_ctrl.Copy(); }
00100       #endif
00101          ;
00102 
00103       //! Create control.
00104       void Create (
00105          MGUI::LAYOUT_PANE_BASE& ParentPane, //!< Parent pane
00106          int width = 0,                      //!< Width in 'typical' characters, minimum if can expand based on sizealign
00107          int height = 0,                     //!< Height lines, minimum if can expand based on sizealign
00108          FLAGS flags = FLAG_Default,
00109          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedHeight
00110          );
00111 
00112    #ifdef WIN32_MFC
00113       //! Get reference to MFC control (MFC only).
00114       CRichEditCtrl& GetCtrl (
00115          ) { return (m_ctrl); }
00116    #endif
00117 
00118       //! Determines the topmost visible line in an edit control.
00119       //! Returns the zero-based index of the topmost visible line. For single-line edit controls, 
00120       //!   the return value is 0.
00121       int GetFirstVisibleLine (
00122          ) const
00123       #ifdef WIN32_MFC
00124          { return (m_ctrl.GetFirstVisibleLine()); }
00125       #endif
00126          ;
00127 
00128       //! Get the number of lines in the edit control.
00129       int GetLineCount (
00130          ) const
00131       #ifdef WIN32_MFC
00132          { return (m_ctrl.GetLineCount()); }
00133       #endif
00134          ;
00135 
00136       //! Retrieves the line number of the line that contains the specified character index.
00137       //! Returns the zero-based line number of the line containing the character index specified by nIndex. 
00138       //! If nIndex is -1, the number of the line that contains the first character of the selection 
00139       //! is returned. If there is no selection, the current line number is returned.
00140       int GetLineFromChar (
00141          int nIndex = -1
00142          ) const
00143       #ifdef WIN32_MFC
00144          { return (m_ctrl.LineFromChar(nIndex)); }
00145       #endif
00146          ;
00147 
00148       //! Retrieves the character index of a line within a multiple-line edit control.
00149       //! Returns the character index of the line specified in nLine or -1 if the specified line 
00150       //! number is greater then the number of lines in the edit control.
00151       int GetLineIndex (
00152          int nLine = -1
00153          )
00154       #ifdef WIN32_MFC
00155          { return (m_ctrl.LineIndex(nLine)); }
00156       #endif
00157          ;
00158 
00159       //! Retrieves the character index of a line within a multiple-line edit control.
00160       //! Return value is the length (in bytes) of the line specified by nLine.
00161       //! nLine specifies the character index of a character in the line whose length is to be 
00162       //! retrieved. If this parameter is -1, the length of the current line (the line that 
00163       //! contains the caret) is returned, not including the length of any selected text 
00164       //! within the line. 
00165       int GetLineLength (
00166          int nLine = -1
00167          )
00168       #ifdef WIN32_MFC
00169          { return (m_ctrl.LineLength(nLine)); }
00170       #endif
00171          ;
00172 
00173       //! Returns true if contents of the edit-control have been modified, false if not.
00174       //!   Use SetModify() to reset.
00175       const bool GetModify (
00176          ) const
00177       #ifdef WIN32_MFC
00178          { return (m_ctrl.GetModify() != FALSE); }
00179       #endif
00180          ;
00181 
00182       //! Get the current selection of the edit control.
00183       //!   If nStartChar == nEndChar, nothing is selected.
00184       void GetSelection (
00185          int& nStartChar,     //!< Receives the first character in the current selection
00186          int& nEndChar        //!< Receives the first non-selected character past the end of the current selection
00187          ) const
00188       #ifdef WIN32_MFC
00189          { m_ctrl.GetSel(nStartChar,nEndChar); }
00190       #endif
00191          ;
00192 
00193       //! Get the text style at the specified offset
00194       //! No effect unless created with the FLAG_WYSIWYG flag
00195       void GetStyle (
00196          TEXTSTYLE& style,
00197          int offset = -1      //!< Offset to get style at.  -1 for style at cursor
00198          ) const;
00199 
00200       //! Get current string value.
00201       const MISTRING& GetValue (
00202          ) const { return (m_value); }
00203 
00204       //! Hide the cursor (a.k.a. caret).
00205       void HideCursor (
00206          )
00207       #ifdef WIN32_MFC
00208          { m_ctrl.HideCaret(); }
00209       #endif
00210          ;
00211 
00212       //! Scrolls the text of a multiple-line edit control
00213       void LineScroll (
00214          int nLines,       //!< Specifies the number of lines to scroll vertically
00215          int nChars = 0    //!< Specifies the number of character positions to scroll horizontally
00216          )
00217       #ifdef WIN32_MFC
00218          { m_ctrl.LineScroll(nLines,nChars); }
00219       #endif
00220          ;
00221 
00222       //! Paste the clipboard contents at the current location
00223       void Paste (
00224          )
00225       #ifdef WIN32_MFC
00226          { m_ctrl.Paste(); }
00227       #endif
00228          ;
00229 
00230    #ifdef WIN32_MFC
00231       //! Called to process messages before translation.
00232       virtual bool PreTranslateMessageHook (
00233          MSG *pMsg
00234          );
00235    #endif
00236 
00237       //! Get the current cursor (a.k.a. caret) location.
00238       void SetCursorPos (
00239          int nCharIndex,
00240          bool bScroll = true  //!< True to scroll so cursor is visible in the window.
00241          );
00242 
00243       //! Get the current cursor (a.k.a. caret) location
00244       void SetCursorPos (
00245          int line,
00246          int col,
00247          bool bScroll = true  //!< True to scroll so cursor is visible in the window.
00248          )
00249       #ifdef WIN32_MFC
00250          { SetCursorPos(m_ctrl.LineIndex(line) + col, bScroll); }
00251       #endif
00252          ;
00253 
00254    #ifdef WIN32_MFC
00255       //! Set the font for the control (MFC only).
00256       void SetFont (
00257          const char* faceName,
00258          int pointSize     //!< in 10ths of a point
00259          ) {
00260          if (m_font.CreatePointFont(pointSize, faceName)) {
00261             m_ctrl.SetFont(&m_font);
00262             }
00263          }
00264    #endif
00265 
00266       //! Set or clear the "modified" state of the edit control.
00267       void SetModify (
00268          bool modified = true
00269          )
00270       #ifdef WIN32_MFC
00271          { m_ctrl.SetModify(modified); }
00272       #endif
00273          ;
00274 
00275       //! Set whether value is read-only or not.
00276       void SetReadOnly (
00277          bool ReadOnly = true                //!< True if read only, false if not
00278          ) {
00279       #ifdef WIN32_MFC
00280          m_ctrl.SetReadOnly(ReadOnly);
00281       #else
00282          MxSetTextEditable(m_widget,!ReadOnly);
00283       #endif
00284          }
00285 
00286       //! Select range of characters in string.
00287       void SetSelection (
00288          int StartChar = 0,                  //!< Starting character position in string, 0 for beginning
00289          int EndChar = -1,                   //!< Ending character position, -1 for end of string
00290          bool NoScroll = true                //!< Indicates whether to scroll caret into view
00291          )
00292       #ifdef WIN32_MFC
00293          { m_ctrl.SetSel(StartChar,EndChar,NoScroll); }
00294       #endif
00295          ;
00296 
00297       //! Get the text style of the current selection, or at the current
00298       //! cursor position (if nothing is selected)
00299       //! No effect unless created with the FLAG_WYSIWYG flag
00300       void SetStyle (
00301          const TEXTSTYLE& style
00302          );
00303 
00304       //! Get the text style of a range of text.
00305       //! No effect unless created with the FLAG_WYSIWYG flag
00306       void SetStyle (
00307          const TEXTSTYLE& style,
00308          int start,           //!< Starting offset to modify
00309          int end              //!< Ending offset to modify
00310          );
00311 
00312    #ifdef WIN32_MFC
00313       //! Set equal tab stops (MFC only);
00314       //! Call this function to set the tab stops in a multiple-line edit control. 
00315       //! When text is copied to a multiple-line edit control, any tab character in 
00316       //! the text will cause space to be generated up to the next tab stop.
00317       //!   The default is one tab stop every 32 dialog units.
00318       void SetTabStops (
00319          int cxEachStop    //!< tab stops are to be set at every cxEachStop dialog units 
00320          ) { m_ctrl.SetTabStops(cxEachStop); }
00321    #endif
00322 
00323    #ifdef WIN32_MFC
00324       //! Set variable tab stops.
00325       //! Call this function to set the tab stops in a multiple-line edit control. 
00326       //! When text is copied to a multiple-line edit control, any tab character in 
00327       //! the text will cause space to be generated up to the next tab stop.
00328       //!   The default is one tab stop every 32 dialog units.
00329       void SetTabStops (
00330          SIMPLE_ARRAY<int> stops //!< Array of stops
00331          ) { m_ctrl.SetTabStops(stops.GetNumItems(), stops); }
00332    #endif
00333 
00334       //! Set current string value with validation.
00335       //! OnValidate() will be called and if valid, the string will be updated.
00336       //! No comparison is made with the current string value.
00337       void SetValue (
00338          const UNICODE* string,              //!< New string to set
00339          bool notify = true                  //!< Call OnChangeValue() if string actually updated
00340          );
00341 
00342       //! Show the cursor (a.k.a. caret)
00343       void ShowCursor (
00344          )
00345       #ifdef WIN32_MFC
00346          { m_ctrl.ShowCaret(); }
00347       #endif
00348          ;
00349 
00350       //! Undo the last edit
00351       void Undo (
00352          )
00353       #ifdef WIN32_MFC
00354          { m_ctrl.Undo(); }
00355       #endif
00356          ;
00357 
00358    protected:
00359 
00360    #ifdef WIN32_MFC
00361       class MyEdit : public CRichEditCtrl {
00362          public:
00363             MyEdit (
00364                CTRL_EDIT_TEXT_WYSIWYG& guictrl
00365                ): m_guictrl(guictrl)
00366                { }
00367             virtual ~MyEdit (
00368                ) { }
00369             virtual BOOL PreCreateWindow (CREATESTRUCT& cs);
00370          protected:
00371             afx_msg void OnChange ();
00372             afx_msg void OnKillFocus ();
00373             DECLARE_MESSAGE_MAP()
00374          private:
00375             #ifndef GENERATING_DOXYGEN_OUTPUT
00376             CTRL_EDIT_TEXT_WYSIWYG& m_guictrl;
00377             #endif // GENERATING_DOXYGEN_OUTPUT
00378          };
00379       friend class MyEdit;
00380       MyEdit m_ctrl;
00381    #endif
00382 
00383    #ifdef X_NATIVE
00384       bool m_UserEdited;
00385       Widget m_TraversalWidget;
00386       XmTraversalDirection m_TraversalDir;
00387       bool m_InternalModify;
00388    #endif
00389    #ifdef WIN32_MFC
00390       CFont m_font;
00391    #endif
00392       bool m_HasValue;
00393       MISTRING m_value;
00394 
00395       bool GetEditStr (
00396          MISTRING& str
00397          ) const;
00398 
00399       //! Called when user presses <Enter> in edit control.
00400       //! Derived class must call corresponding base class method BEFORE performing its own processing.
00401       virtual void OnActivate ();
00402 
00403       //! Called when value is changed after validation.
00404       //! Derived class must call corresponding base class method BEFORE performing its own processing.
00405       //! If the user modifies the text in the edit control this will not be called until the control loses "focus".
00406       virtual void OnChangeValue ();
00407 
00408       //! Called when user modifies the text in the edit control.
00409       //! Derived class must call corresponding base class method BEFORE performing its own processing.
00410       //! The actual value does not get updated until the control loses focus or GetValue() is called.
00411       virtual void OnUserEdit ();
00412 
00413       //! Called internally to update text control from specified string.
00414       void UpdateCtrl (
00415          const MISTRING& string
00416          );
00417 
00418       //! Called internally to update control-specific data from edit control.
00419       //! Derived class must call corresponding base class method AFTER performing its own processing.
00420       virtual void UpdateValue (bool notify = true);
00421 
00422    #ifdef X_NATIVE
00423       static void CB_Activate (Widget, CTRL_EDIT_TEXT_WYSIWYG*, void*);
00424       static void CB_Focus (Widget, CTRL_EDIT_TEXT_WYSIWYG*, void*);
00425       static void CB_LosingFocus (Widget, CTRL_EDIT_TEXT_WYSIWYG*, void*);
00426       static void CB_ModifyVerify (Widget, CTRL_EDIT_TEXT_WYSIWYG*, void*);
00427       static void CB_ValueChanged (Widget, CTRL_EDIT_TEXT_WYSIWYG*, void*);
00428    #endif
00429 
00430       //! Copy constructor and assignment operator are private and unimplemented
00431       CTRL_EDIT_TEXT_WYSIWYG (const CTRL_EDIT_TEXT_WYSIWYG&);
00432       CTRL_EDIT_TEXT_WYSIWYG& operator= (const CTRL_EDIT_TEXT_WYSIWYG&);
00433    };
00434 
00435 DEFINE_ENUM_OPERATORS(MGUI::CTRL_EDIT_TEXT_WYSIWYG::FLAGS);
00436 
00437 
00438 //-------------------------------------------------------------------------------------------------------------------
00439 //! Convenience template for multiline text 'edit' control to allow method in container class to be called.
00440 template <class _CT> class CTRL_EDIT_TEXT_WYSIWYG_T : public MGUI::CTRL_EDIT_TEXT_WYSIWYG {
00441    public:
00442       //! Constructor.
00443       explicit CTRL_EDIT_TEXT_WYSIWYG_T (
00444          _CT *pContainer = 0
00445          ): m_pContainer(pContainer), m_pfOnChangeValue(0)
00446          { }
00447 
00448       //! Set container pointer.
00449       //! Container may also be specified in constructor.
00450       void SetContainer (
00451          _CT *pContainer
00452          ) { m_pContainer = pContainer; }
00453 
00454       //! Set container method to call for OnChangeValue().
00455       void SetFuncChangeValue (
00456          void (_CT::*pfOnChangeValue)()
00457          ) { m_pfOnChangeValue = pfOnChangeValue; };
00458 
00459    private:
00460       #ifndef GENERATING_DOXYGEN_OUTPUT
00461       _CT *m_pContainer;
00462       void (_CT::*m_pfOnChangeValue)();
00463 
00464       virtual void OnChangeValue (
00465          ) {
00466          CTRL_EDIT_TEXT_WYSIWYG::OnChangeValue();
00467          if (m_pContainer != 0) (m_pContainer->*m_pfOnChangeValue)();
00468          }
00469       #endif // GENERATING_DOXYGEN_OUTPUT
00470    };
00471 
00472 
00473 //===================================================================================================================
00474 
00475 }  // End of MGUI namespace
00476 
00477 #endif   // INC_MGUI_CTRL_H

Generated on Thu Aug 12 06:18:30 2004 for TNTsdk by doxygen 1.3.4-20031026