home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 19.ddi / OWLINC.PAK / EDIT.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  9.9 KB  |  324 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991, 1993 by Borland International
  3. //   include\owl\edit.h
  4. //   Definition of class TEdit.  This defines the basic behavior
  5. //   of all edit controls.
  6. //----------------------------------------------------------------------------
  7. #if !defined(__OWL_EDIT_H)
  8. #define __OWL_EDIT_H
  9.  
  10. #if !defined(__OWL_STATIC_H)
  11.   #include <owl\static.h>
  12. #endif
  13. #include <owl\edit.rh>
  14.  
  15. class _OWLCLASS TValidator;
  16.  
  17. //
  18. //  class TEdit
  19. //  ----- -----
  20. //
  21. class _OWLCLASS TEdit : public TStatic {
  22.   public:
  23.     TEdit(TWindow*        parent,
  24.           int             id,
  25.           const char far* text,
  26.           int x, int y, int w, int h,
  27.           UINT            textLen = 0,
  28.           BOOL            multiline = FALSE,
  29.           TModule*        module = 0);
  30.  
  31.     TEdit(TWindow*   parent,
  32.           int        resourceId,
  33.           UINT       textLen = 0,
  34.           TModule*   module = 0);
  35.  
  36.    ~TEdit();
  37.  
  38.     //
  39.     // Accessing
  40.     //
  41.     int     GetNumLines() const;
  42.     int     GetLineLength(int lineNumber) const;
  43.     BOOL    GetLine(char far* str, int strSize, int lineNumber) const;
  44.     void    GetSubText(char far* str, UINT startPos, UINT endPos) const;
  45.     void    GetSelection(UINT& startPos, UINT& endPos) const;
  46.  
  47.     BOOL    IsModified() const;
  48.     void    ClearModify() {HandleMessage(EM_SETMODIFY);}
  49.  
  50.     int     GetLineFromPos(UINT charPos) const;
  51.     UINT    GetLineIndex(int lineNumber) const;
  52.  
  53.     UINT    Transfer(void* buffer, TTransferDirection direction);
  54.  
  55.     //
  56.     // Lock and unlock this edit control's buffer. Allows direct access to the
  57.     // text in the edit control.
  58.     //
  59.     char far* LockBuffer(UINT newSize = 0);
  60.     void    UnlockBuffer(const char far* buffer, BOOL updateHandle = FALSE);
  61.  
  62.     //
  63.     // operations
  64.     //
  65.     BOOL    DeleteSubText(UINT startPos, UINT endPos);
  66.     BOOL    DeleteLine(int lineNumber);
  67.     BOOL    DeleteSelection();
  68.     BOOL    SetSelection(UINT startPos, UINT endPos);
  69.  
  70.     void    Scroll(int horizontalUnit, int verticalUnit);
  71.     void    Insert(const char far* str);
  72.     int     Search(UINT startPos, const char far* text,
  73.                    BOOL caseSensitive=FALSE, BOOL wholeWord=FALSE,
  74.                    BOOL up=FALSE);
  75.  
  76.     void    GetRect(TRect& frmtRect) const;
  77.     void    SetRect(const TRect& frmtRect);
  78.     void    SetRectNP(const TRect& frmtRect);
  79.     void    FormatLines(BOOL addEOL);
  80.     void    SetTabStops(int numTabs, const int far* tabs);
  81.  
  82.     HLOCAL  GetHandle() const;
  83.     void    SetHandle(HLOCAL localMem);
  84.  
  85.     void    SetPasswordChar(UINT ch) {HandleMessage(EM_SETPASSWORDCHAR, ch);}
  86.  
  87.     int     GetFirstVisibleLine() const;
  88.     void    SetReadOnly(BOOL readOnly);
  89.     UINT    GetPasswordChar() const;
  90.  
  91.     EDITWORDBREAKPROC GetWordBreakProc() const;
  92.     void    SetWordBreakProc(EDITWORDBREAKPROC proc);
  93.  
  94.     //
  95.     // clipboard operations
  96.     //
  97.     BOOL    CanUndo() const;
  98.     void    EmptyUndoBuffer() {HandleMessage(EM_EMPTYUNDOBUFFER);}
  99.     void    Undo() {HandleMessage(WM_UNDO);}
  100.     void    Paste() {HandleMessage(WM_PASTE);}
  101.     void    Copy() {HandleMessage(WM_COPY);}
  102.     void    Cut() {HandleMessage(WM_CUT);}
  103.     
  104.     BOOL    IsValid(BOOL reportErr = FALSE);
  105.     void    SetValidator(TValidator* validator);
  106.     void    ValidatorError();
  107.  
  108.     //
  109.     // Override TStatic virtual member functions
  110.     //
  111.     void Clear();
  112.  
  113.   protected:
  114.     //
  115.     // command response functions
  116.     //
  117.     void    CmEditCut() {Cut();}                  // CM_EDITCUT
  118.     void    CmEditCopy() {Copy();}                // CM_EDITCOPY
  119.     void    CmEditPaste() {Paste();}              // CM_EDITPASTE
  120.     void    CmEditDelete() {DeleteSelection();}   // CM_EDITDELETE
  121.     void    CmEditClear() {Clear();}              // CM_EDITCLEAR
  122.     void    CmEditUndo() {Undo();}                // CM_EDITUNDO
  123.  
  124.     //
  125.     // command enabler functions
  126.     //
  127.     void CmSelectEnable(TCommandEnabler& commandHandler);
  128.     void CmPasteEnable(TCommandEnabler& commandHandler);
  129.     void CmCharsEnable(TCommandEnabler& commandHandler);
  130.     void CmModEnable(TCommandEnabler& commandHandler);
  131.  
  132.     //
  133.     // child id notification handled at the child
  134.     //
  135.     void    ENErrSpace();  // EN_ERRSPACE
  136.  
  137.     //
  138.     // Override TWindow virtual member functions
  139.     //
  140.     char far* GetClassName();
  141.     void      SetupWindow();
  142.  
  143.     //
  144.     // Input validation object
  145.     //
  146.     TValidator*  Validator;
  147.  
  148.     void         EvChar(UINT key, UINT repeatCount, UINT flags);
  149.     void         EvKeyDown(UINT key, UINT repeatCount, UINT flags);
  150.     UINT         EvGetDlgCode(MSG far*);
  151.     void         EvSetFocus(HWND hWndLostFocus);
  152.     void         EvKillFocus(HWND hWndGetFocus);
  153.     BOOL         CanClose();
  154.  
  155.     //
  156.     // handler for input validation message sent by parent
  157.     //
  158.     void         EvChildInvalid(HWND);
  159.  
  160.   private:
  161.     //
  162.     // hidden to prevent accidental copying or assignment
  163.     //
  164.     TEdit(const TEdit&);
  165.     TEdit& operator =(const TEdit&);
  166.  
  167.  
  168.     // Used to prevent 'oscillation' when a validated window with invalid
  169.     // input is losing focus to another validated window with invalid input
  170.     // Without this flag, the two windows will fight for focus
  171.     static TEdit* ValidatorReFocus;
  172.  
  173.   DECLARE_RESPONSE_TABLE(TEdit);
  174.   DECLARE_STREAMABLE(_OWLCLASS, TEdit, 1);
  175. };
  176.  
  177. //
  178. // edit control notification macros. methods are: void method()
  179. //
  180. // EV_EN_CHANGE(id, method)
  181. // EV_EN_ERRSPACE(id, method)
  182. // EV_EN_HSCROLL(id, method)
  183. // EV_EN_KILLFOCUS(id, method)
  184. // EV_EN_MAXTEXT(id, method)
  185. // EV_EN_SETFOCUS(id, method)
  186. // EV_EN_UPDATE(id, method)
  187. // EV_EN_VSCROLL(id, method)
  188.  
  189. //----------------------------------------------------------------------------
  190. // Inlines
  191. //----------------------------------------------------------------------------
  192.  
  193. //
  194. // returns the number of lines in the associated edit control
  195. //
  196. // note that GetNumLines returns 1 when the edit control has no text (i.e.
  197. // it has one line with no text in it). Returns zero if an error occurs
  198. //
  199. inline int TEdit::GetNumLines() const {
  200.   return (int)CONST_CAST(TEdit*,this)->HandleMessage(EM_GETLINECOUNT);
  201. }
  202.  
  203. inline BOOL TEdit::IsModified() const {
  204.   return (BOOL)CONST_CAST(TEdit*,this)->HandleMessage(EM_GETMODIFY);
  205. }
  206.  
  207. //
  208. // selects the characters in the range "startPos .. endPos"
  209. //
  210. inline BOOL TEdit::SetSelection(UINT startPos, UINT endPos) {
  211.   #if defined(__WIN32__)
  212.     return HandleMessage(EM_SETSEL, startPos, endPos) != 0;
  213.   #else
  214.     return HandleMessage(EM_SETSEL, 0, MAKELPARAM(startPos, endPos)) != 0;
  215.   #endif
  216. }
  217.  
  218. // returns the starting and ending positions of the selected text
  219. //
  220. inline void TEdit::GetSelection(UINT& startPos, UINT& endPos) const {
  221.   #if defined(__WIN32__)
  222.     CONST_CAST(TEdit*,this)->HandleMessage(EM_GETSEL, (WPARAM)&startPos, (LPARAM)&endPos);
  223.   #else
  224.     LRESULT  retValue = CONST_CAST(TEdit*,this)->HandleMessage(EM_GETSEL);
  225.     startPos = LOWORD(retValue);
  226.     endPos   = HIWORD(retValue);
  227.   #endif
  228. }
  229.  
  230. //
  231. // returns the line number associated with character index "CharPos"
  232. //
  233. // if "CharPos" is greater than the number of characters, the last line is
  234. // returned
  235. // if "CharPos" is -1, the line containing the beginning of the selection (or
  236. // the line containing the caret if no selection) is returned
  237. //
  238. inline int TEdit::GetLineFromPos(UINT charPos) const {
  239.   return (int)CONST_CAST(TEdit*,this)->HandleMessage(EM_LINEFROMCHAR, charPos);
  240. }
  241.  
  242. //
  243. // returns the character index of line number "LineNumber" or -1 if
  244. // "LineNumber" is greater than the number of lines
  245. //
  246. // if "LineNumber" is -1, the line containing the caret is used
  247. //
  248. inline UINT TEdit::GetLineIndex(int lineNumber) const {
  249.   return (int)CONST_CAST(TEdit*,this)->HandleMessage(EM_LINEINDEX, lineNumber);
  250. }
  251.  
  252. //
  253. // scrolls the text by the specified horizontal and vertical amounts
  254. //
  255. inline void TEdit::Scroll(int horizUnit, int vertUnit) {
  256.   #if defined(__WIN32__)
  257.     HandleMessage(EM_LINESCROLL, horizUnit, vertUnit);
  258.   #else
  259.     HandleMessage(EM_LINESCROLL, 0, MAKELONG(vertUnit, horizUnit));
  260.   #endif
  261. }
  262.  
  263. //
  264. // sets the selection to the "str" (does a "paste" type of action
  265. // without affecting the clipboard)
  266. //
  267. inline void TEdit::Insert(const char far* str) {
  268.   HandleMessage(EM_REPLACESEL, 0, (LPARAM)str);
  269. }
  270.  
  271. inline void TEdit::GetRect(TRect& frmtRect) const {
  272.   CONST_CAST(TEdit*,this)->HandleMessage(EM_GETRECT, 0, (LPARAM)(TRect FAR*)&frmtRect);
  273. }
  274.  
  275. inline void TEdit::SetRect(const TRect& frmtRect) {
  276.   HandleMessage(EM_SETRECT, 0, (LPARAM)(const TRect FAR*)&frmtRect);
  277. }
  278.  
  279. inline void TEdit::SetRectNP(const TRect& frmtRect) {
  280.   HandleMessage(EM_SETRECTNP, 0, (LPARAM)(const TRect FAR*)&frmtRect);
  281. }
  282.  
  283. inline void TEdit::FormatLines(BOOL addEOL) {
  284.   HandleMessage(EM_FMTLINES, addEOL);
  285. }
  286.  
  287. inline void TEdit::SetTabStops(int numTabs, const int far* tabs) {
  288.   HandleMessage(EM_SETTABSTOPS, numTabs, (LPARAM)tabs);
  289. }
  290.  
  291. inline HLOCAL TEdit::GetHandle() const {
  292.   return (HLOCAL)CONST_CAST(TEdit*,this)->HandleMessage(EM_GETHANDLE);
  293. }
  294.  
  295. inline void TEdit::SetHandle(HLOCAL localMem) {
  296.   HandleMessage(EM_SETHANDLE, (WPARAM)localMem);
  297. }
  298.  
  299. inline int TEdit::GetFirstVisibleLine() const {
  300.   return (int)CONST_CAST(TEdit*,this)->HandleMessage(EM_GETFIRSTVISIBLELINE);
  301. }
  302.  
  303. inline void TEdit::SetReadOnly(BOOL readOnly) {
  304.   HandleMessage(EM_SETREADONLY, readOnly);
  305. }
  306.  
  307. inline UINT TEdit::GetPasswordChar() const {
  308.   return (UINT)CONST_CAST(TEdit*,this)->HandleMessage(EM_GETPASSWORDCHAR);
  309. }
  310.  
  311. inline EDITWORDBREAKPROC TEdit::GetWordBreakProc() const {
  312.   return (EDITWORDBREAKPROC)CONST_CAST(TEdit*,this)->HandleMessage(EM_GETWORDBREAKPROC);
  313. }
  314.  
  315. inline void TEdit::SetWordBreakProc(EDITWORDBREAKPROC proc) {
  316.   HandleMessage(EM_SETWORDBREAKPROC, 0, (LPARAM)proc);
  317. }
  318.  
  319. inline BOOL TEdit::CanUndo() const {
  320.   return (BOOL)CONST_CAST(TEdit*,this)->HandleMessage(EM_CANUNDO);
  321. }
  322.  
  323. #endif  // __OWL_EDIT_H
  324.