home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 October / Chip_1997-10_cd.bin / tema / sybase / powerj / hpp.z / WTEXTBOX.HPP < prev    next >
C/C++ Source or Header  |  1997-01-24  |  11KB  |  369 lines

  1. /*************************************************************************
  2.  *
  3.  * WTextBox -- Wrapper for the Windows 95 Textbox control.
  4.  *
  5.  *
  6.  *   Events:
  7.  *
  8.  *       Change --
  9.  *
  10.  *       DataAvailable --
  11.  *
  12.  *       DataClose --
  13.  *
  14.  *       DataOpen --
  15.  *
  16.  *       DataRequest --
  17.  *
  18.  *       Update --
  19.  *
  20.  *************************************************************************/
  21.  
  22. #ifndef _WTEXTBOX_HPP_INCLUDED
  23. #define _WTEXTBOX_HPP_INCLUDED
  24.  
  25. #ifndef _WNO_PRAGMA_PUSH
  26. #pragma pack(push,8);
  27. #pragma enum int;
  28. #endif
  29.  
  30. #ifndef _WCONTROL_HPP_INCLUDED
  31. #  include "wcontrol.hpp"
  32. #endif
  33. #ifndef _WDATATRG_HPP_INCLUDED
  34. #  include "wdatatrg.hpp"
  35. #endif
  36.  
  37. class WDataSource;
  38.  
  39. enum WTextBoxScroll {
  40.     WTBScrollLineUp,
  41.     WTBScrollLineDown,
  42.     WTBScrollPageUp,
  43.     WTBScrollPageDown
  44. };
  45.  
  46. //
  47. // Textbox Styles
  48. //
  49.  
  50. #define WTextBoxDefault       ((WStyle)0x50800080L) // WS_VISIBLE|WS_BORDER|ES_LEFT|ES_AUTOHSCROLL|WS_CHILD
  51.  
  52. #define WTextBoxLeft          ((WStyle)0x00000000L) // ES_LEFT
  53. #define WTextBoxCenter        ((WStyle)0x00000001L) // ES_CENTER
  54. #define WTextBoxRight         ((WStyle)0x00000002L) // ES_RIGHT
  55. #define WTextBoxMultiLine     ((WStyle)0x00000004L) // ES_MULTILINE
  56. #define WTextBoxUpperCase     ((WStyle)0x00000008L) // ES_UPPERCASE
  57. #define WTextBoxLowerCase     ((WStyle)0x00000010L) // ES_LOWERCASE
  58. #define WTextBoxPassword      ((WStyle)0x00000020L) // ES_PASSWORD
  59. #define WTextBoxAutoVScroll   ((WStyle)0x00000040L) // ES_AUTOVSCROLL
  60. #define WTextBoxAutoHScroll   ((WStyle)0x00000080L) // ES_AUTOHSCROLL
  61. #define WTextBoxNoHideSel     ((WStyle)0x00000100L) // ES_NOHIDESEL
  62. #define WTextBoxOEMConvert    ((WStyle)0x00000400L) // ES_OEMCONVERT
  63. #define WTextBoxReadOnly      ((WStyle)0x00000800L) // ES_READONLY
  64. #define WTextBoxWantReturn    ((WStyle)0x00001000L) // ES_WANTRETURN
  65. #define WTextBoxNumber        ((WStyle)0x00002000L) // ES_NUMBER
  66.  
  67. class WCMCLASS WTextBox : public WControl {
  68.     WDeclareSubclass( WTextBox, WControl );
  69.     
  70.     public:
  71.  
  72.         WTextBox();
  73.  
  74.         ~WTextBox();
  75.  
  76.         /**************************************************************
  77.          * Properties
  78.          **************************************************************/
  79.  
  80.         // CanUndo
  81.         //
  82.         //     Read-only property.  Returns TRUE if the last edit operation
  83.         //     can be undone by calling the Undo method.
  84.  
  85.         WBool GetCanUndo() const;
  86.  
  87.         // DataColumns
  88.  
  89.         WString GetDataColumns() const;
  90.         WBool   SetDataColumns( const WString & cols );
  91.  
  92.         // DataSource
  93.  
  94.         WDataSource *GetDataSource() const;
  95.         WBool        SetDataSource( WDataSource *source );
  96.  
  97.         // FDXDataSource
  98.  
  99.         WBool SetFDXDataSource( WString * fdxDataSource );
  100.  
  101.         // EditSelection
  102.         //
  103.         //     The current selection in the edit control.  The
  104.         //     selection points start at 0 and occur between the characters.
  105.         //     When setting, set start=-1 to deselect everything,
  106.         //     or set end=-1 to select from start to end of text.
  107.  
  108.         WRange GetEditSelection() const;
  109.         WBool SetEditSelection( const WRange & editSelection );
  110.  
  111.         // FirstCharacterIndex
  112.         //
  113.         //     Read-only property.  Returns the zero-based index of
  114.         //     the first visible character.
  115.  
  116.         WULong GetFirstCharacterIndex() const;
  117.  
  118.         // FirstLineIndex
  119.         //
  120.         //     Read-only property.  Returns the zero-based index of
  121.         //     the first visible line.  (Always returns 0 for single
  122.         //     line text boxes.)
  123.  
  124.         WULong GetFirstLineIndex() const;
  125.  
  126.         // LineCount
  127.         //
  128.         //     The number of lines in the control.
  129.  
  130.         WULong GetLineCount() const;
  131.          
  132.         // Caret position
  133.         //
  134.         //      The position of caret
  135.         //
  136.         WBool   SetCaretPosition(WInt pos, WBool scrollInfoView = FALSE);
  137.         WULong  GetCaretPosition() const;
  138.  
  139.         // Margins
  140.         //
  141.         //     The margins for the multi line control.
  142.         //     If no parms are specified for the set, the margins
  143.         //     are reset to font margins.
  144.  
  145.         WBool SetMargins( const WRange & margins );
  146.         WBool SetMargins();
  147.         WRange GetMargins() const;
  148.  
  149.         // Modified
  150.         //
  151.         //     If TRUE, text has been modified since the property
  152.         //     was cleared (it is initially cleared).
  153.  
  154.         WBool GetModified() const;
  155.         WBool SetModified( WBool modified );
  156.  
  157.         // PasswordCharacter
  158.         //
  159.         //     Get/set the password character.  Note that 16-bit
  160.         //     values are used for DBCS/Unicode.
  161.  
  162.         WUShort GetPasswordCharacter() const;
  163.         WBool SetPasswordCharacter( WUShort ch );
  164.  
  165.         // ReadOnly
  166.         //
  167.         //     Determines whether edit box is read-only.
  168.  
  169.         WBool GetReadOnly() const;
  170.         WBool SetReadOnly( WBool readOnly );
  171.  
  172.         // SoftLineBreaks
  173.         //
  174.         //     Use at runtime with multiline text boxes.  If TRUE, a
  175.         //     soft line break (CR-CR-LF) is inserted at the end of each
  176.         //     line that is broken because of wordwrap.  If FALSE, all
  177.         //     such line breaks are removed and only hard line breaks
  178.         //     (CR-LF) are left.
  179.  
  180.         WBool GetSoftLineBreaks() const;
  181.         WBool SetSoftLineBreaks( WBool on );
  182.  
  183.         // TextLimit
  184.         //
  185.         //     Set/get the max # of charactes the text box can hold.
  186.         //     Setting the limit to 0 sets it to the max (32K for
  187.         //     single line, 64K for multi line).
  188.  
  189.         WULong GetTextLimit() const;
  190.         WBool  SetTextLimit( WULong limit );
  191.  
  192.         /**************************************************************
  193.          * Methods
  194.          **************************************************************/
  195.  
  196.         // AppendText
  197.         //
  198.         //     Add text to the end of the textbox.  If scroll is TRUE,
  199.         //     the caret is moved to the end of the text and the
  200.         //     text is scrolled into view.
  201.  
  202.         WBool AppendText( const WString & text, WBool scroll=TRUE );
  203.  
  204.         // CharacterIndex
  205.         //
  206.         //     Given a point in the edit control's client area, returns
  207.         //     the character index (from 0) and line index (from 0)
  208.         //     of the character.  Returns FALSE if the point is outside
  209.         //     the client area, in which case the charIndex and lineIndex
  210.         //     values are to be ignored.  Note that charIndex and lineIndex
  211.         //     are limited to 16 bits.
  212.  
  213.         WBool CharacterIndex( const WPoint & pt, WULong & charIndex ) const;
  214.         WBool CharacterIndex( const WPoint & pt, WULong & charIndex,
  215.                               WULong & lineIndex ) const;
  216.  
  217.         // Clear
  218.         //
  219.         //     Clears (deletes) the selected text in the edit control.
  220.  
  221.         void  Clear();
  222.  
  223.         // ClearUndoBuffer
  224.         //
  225.         //     Clears the undo buffer.
  226.  
  227.         WBool ClearUndoBuffer() const;
  228.  
  229.         // Copy
  230.         //
  231.         //     Copy the selected contents into the clipboard.
  232.  
  233.         WBool Copy();
  234.  
  235.         // Cut
  236.         //
  237.         //     Copy & clear the selected contents.
  238.  
  239.         void  Cut();
  240.  
  241.         // InsertText
  242.         //
  243.         //     Insert text into the control.  If text is currently
  244.         //     selected, the new text replaces it, otherwise the text
  245.         //     gets inserted at the current caret position.
  246.  
  247.         WBool InsertText( const WString & text, WBool canUndo=FALSE );
  248.  
  249.         // LineIndex
  250.         //
  251.         //     Return the line that a character is on.  If -1 (0xFFFFFFFF)
  252.         //     is passed, returns line the caret is on.
  253.  
  254.         WULong LineIndex( WULong charIndex=0xFFFFFFFF ) const;
  255.  
  256.         // Paste
  257.         //
  258.         //     Paste the contents of the clipboard.
  259.  
  260.         void  Paste();
  261.  
  262.         // CharacterPosition
  263.         //
  264.         //     Return the point (in client coordinates) that corresponds
  265.         //     to a given character position.
  266.  
  267.         WBool CharacterPosition( WPoint & point, WULong charIndex ) const;
  268.  
  269.         // Scroll
  270.         //
  271.         //     Scroll a certain number of characters and/or lines.
  272.         //     dx = # of characters, dy = # of lines.
  273.  
  274.         WBool Scroll( WTextBoxScroll scrollBy=WTBScrollLineDown ) const;
  275.         WBool Scroll( WLong dx, WLong dy=0 ) const;
  276.  
  277.         // ScrollCaret
  278.         //
  279.         //     Scroll the caret into view if not visible.
  280.  
  281.         WBool ScrollCaret() const;
  282.  
  283.         // Undo
  284.         //
  285.         //     Undo the last operation if possible.
  286.  
  287.         WBool Undo();
  288.  
  289.         /**************************************************************
  290.          * Item Properties
  291.          **************************************************************/
  292.  
  293.         // Text
  294.         //
  295.         //     The text for the given line (lines start at 0).
  296.  
  297.         WString GetText( WULong line ) const;
  298.  
  299.         // TextLength
  300.         //
  301.         //     The length of text in a given line.
  302.  
  303.         WULong GetTextLength( WULong line ) const;
  304.  
  305.  
  306.         /**************************************************************
  307.          * Overrides
  308.          **************************************************************/
  309.  
  310.         virtual WBool Scroll( const WPoint & amount, WRect * toScroll=NULL,
  311.                               WRect * clipRegion=NULL );
  312.  
  313.         virtual WColor GetBackColor( WBool getResultingColor=TRUE ) const;
  314.  
  315.         virtual WStyle GetDefaultStyle() const;
  316.  
  317.         virtual WStyle GetDefaultExtendedStyle() const;
  318.  
  319.         virtual WString GetText() const;
  320.  
  321.         virtual size_t GetTextLength() const;
  322.         
  323.         virtual WBool CloneWindow( WStyle newStyle, WStyle newExStyle,
  324.                                    void * data=NULL );
  325.  
  326.         virtual WBool ProcessCommand( WUInt id, WNotify code,
  327.                                       WNotifyInfo info, WLong & returns );
  328.  
  329.         virtual const WChar * InitializeClass();
  330.  
  331.         virtual WBool FDXIn();
  332.  
  333.         virtual WBool FDXOut();
  334.  
  335.         WBool DataOpenHandler( WTextBox *, WDataOpenEventData *ev );
  336.         WBool DataCloseHandler( WTextBox *, WDataCloseEventData *ev );
  337.         WBool DataAvailableHandler( WTextBox *, WDataAvailableEventData *ev );
  338.         WBool DataRequestHandler( WTextBox *, WDataRequestEventData *ev );
  339.  
  340.         WBool DragStartHandler( WTextBox *, WDragEventData *ev );
  341.         WBool DragDropHandler( WTextBox *, WDragEventData *ev );
  342.  
  343.     protected:
  344.  
  345.         WBool AllocDTCell();
  346.  
  347.         /**************************************************************
  348.          * Data members
  349.          **************************************************************/
  350.  
  351.     protected:
  352.  
  353.         WBool                   _ignoreChange;
  354.  
  355.     private:
  356.  
  357.         WBool                   _softLineBreaks;
  358.         WString *               _fdxDataSource;
  359.         WDataTargetCell         *_dataTarget;
  360.         WBool                   _wasEnabled;
  361. };
  362.     
  363. #ifndef _WNO_PRAGMA_PUSH
  364. #pragma enum pop;
  365. #pragma pack(pop);
  366. #endif
  367.  
  368. #endif // _WTEXTBOX_HPP_INCLUDED
  369.