plugins/consoles/rcons/server/win32/TextView.h
changeset 0 7f656887cf89
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // TextView.h
       
     2 // 
       
     3 // Copyright (c) 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "Eclipse Public License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 // 
       
     9 // Initial Contributors:
       
    10 // Accenture - Initial contribution
       
    11 //
       
    12 
       
    13 #ifndef __TEXTVIEW_H__
       
    14 #define __TEXTVIEW_H__
       
    15 
       
    16 #if _MSC_VER > 1000
       
    17 #pragma once
       
    18 #endif // _MSC_VER > 1000
       
    19 
       
    20 #include "base.h"
       
    21 #include "TextBuffer.h"
       
    22 
       
    23 class CWindow;
       
    24 
       
    25 
       
    26 class CTextView : public CBase, public MTextBufferObserver
       
    27 	{
       
    28 public:
       
    29 	static CTextView* New(CWindow& aWindow, CTextBuffer& aTextBuffer, int aWidthInChars, int aHeightInChars);
       
    30 	virtual ~CTextView();
       
    31 	void EnableCursor();
       
    32 	void DisableCursor();
       
    33 	void BeginUpdate();
       
    34 	void EndUpdate();
       
    35 	void Draw() const;
       
    36 	void HandleFocusGained();
       
    37 	void HandleFocusLost();
       
    38 	void SetSize(int aWidth, int aHeight);
       
    39 	void GetSize(int& aWidth, int& aHeight) const;
       
    40 	void SetHorzScrollPosition(int aPosX);
       
    41 	void SetVertScrollPosition(int aPosY);
       
    42 	void StartSelection(int aPosX, int aPosY);
       
    43 	void AdjustSelection(int aPosX, int aPosY);
       
    44 	void EndSelection(int aPosX, int aPosY);
       
    45 	void SelectWord(int aPosX, int aPosY);
       
    46 	int CharHeight() const;
       
    47 	int CharWidth() const;
       
    48 	bool SelectionAvailable() const;
       
    49 	LPTSTR Selection() const;
       
    50 	void ClearSelection();
       
    51 	void SetDimmed(bool aDimmed);
       
    52 	void ScrollToEndIfNeeded();
       
    53 private:
       
    54 	CTextView(CWindow& aWindow, CTextBuffer& aTextBuffer);
       
    55 	void Construct(int aWidthInChars, int aHeightInChars);
       
    56 private: // From MTextBufferObserver.
       
    57 	virtual void HandleTextBufferChange(int aPosX, int aPosY, PTCHAR aPtr, int aLength);
       
    58 	virtual void HandleTextBufferScroll();
       
    59 	virtual void HandleTextBufferCursorChange();
       
    60 	virtual void HandleTextBufferCleared();
       
    61 private:
       
    62 	void SetCursorVisibility();
       
    63 	bool CursorInView() const;
       
    64 	void GetCursorPixelPos(int& aX, int& aY) const;
       
    65 	void SetCursorPos();
       
    66 	void ResetBufferPos();
       
    67 	void SetBufferPos(int aPosX, int aPosY);
       
    68 	void MoveBuffer(int aDiffY);
       
    69 	void ConfigureScrollBars(bool aReset);
       
    70 	void ReDraw() const;
       
    71 	void GetViewRect(int aCharPosX, int aCharPosY, int aNumChars, RECT& aRect) const;
       
    72 	void GetViewRect(int aCharPosX1, int aCharPosY1, int aCharPosX2, int aCharPosY2, RECT& aRect) const;
       
    73 	bool RectVisible(const RECT& aRect) const;
       
    74 	bool LineVisible(int aLinePos) const;
       
    75 	bool TopLineVisible() const;
       
    76 	bool BottomLineVisible() const;
       
    77 	int TotalBufferHeight() const;
       
    78 	int MinBufferPosY() const;
       
    79 	int MaxBufferPosY() const;
       
    80 	void GetVisibleLines(const RECT& aRect, int& aFrom, int& aTo) const;
       
    81 	void MapBufCharToBufPix(int aBufCharPosX, int aBufCharPosY, int& aBufPixPosX, int& aBufPixPosY) const;
       
    82 	void MapBufPixToViewPix(int aBufPixPosX, int aBufPixPosY, int& aViewPixPosX, int& aViewPixPosY) const;
       
    83 	void MapBufPixToBufChar(int aBufPixPosX, int aBufPixPosY, int& aBufCharPosX, int& aBufCharPosY) const;
       
    84 	void MapViewPixToBufPix(int aViewPixPosX, int aViewPixPosY, int& aBufPixPosX, int& aBufPixPosY) const;
       
    85 	void MapScrollPosToBufPix(int aScrollPosX, int aScrollPosY, int& aBufPixPosX, int& aBufPixPosY) const;
       
    86 	void GetSelectionRect(RECT& aRect) const;
       
    87 	void ScrollSelection();
       
    88 private:
       
    89 	CWindow& iWindow;
       
    90 	CTextBuffer& iTextBuffer;
       
    91 	HFONT iFont;
       
    92 	int iCharWidth;			///< Character width in pixels.
       
    93 	int iCharHeight;		///< Character height in pixels.
       
    94 	int iViewWidth;
       
    95 	int iViewHeight;
       
    96 	int iBufferPosX;
       
    97 	int iBufferPosY;
       
    98 	int iNumOverflowLines;
       
    99 	bool iCursorEnabled;
       
   100 	bool iUpdating;
       
   101 	bool iCursorHidden;
       
   102 	bool iFocused;
       
   103 	int iSelectionX1;		///< In buffer character coordinates.
       
   104 	int iSelectionY1;		///<        "             "
       
   105 	int iSelectionX2;		///<        "             "
       
   106 	int iSelectionY2;		///<        "             "
       
   107 	bool iSelecting;
       
   108 	bool iDimmed;
       
   109 	};
       
   110 
       
   111 
       
   112 
       
   113 /*
       
   114         /-- (iBufferPosX, iBufferPosY) in pixels relative to view.
       
   115        /
       
   116       |----------------------------------------------------------------|
       
   117       |                                                                |
       
   118       |                                                                |
       
   119       |                                                                |
       
   120       |                                                                |
       
   121       |                                                                |
       
   122       |                                                                |
       
   123       |        /-- (0, 0) in Windows pixel coordinates.                |
       
   124       |       /                                                        |
       
   125       |   i  |-------------------------------------------------|       |
       
   126       |   V  |                                               |-|       |
       
   127       |   i  |                                               | |       |
       
   128       |   e  |                                               | |       |
       
   129       |   w  |                                               | |       |
       
   130       |   H  |                                               | |       |
       
   131       |   e  |                                               | |       |
       
   132       |   i  |                                               | |       |
       
   133       |   g  |                                               | |       |
       
   134       |   h  |-|---------------------------------------------|-|       |
       
   135       |   t  |-------------------------------------------------|       |
       
   136       |                                                                |
       
   137       |      <----------- iViewWidth (in pixels) ----------->          |
       
   138       |                                                                |
       
   139       |                                                                |
       
   140       |                                                                |
       
   141       |                                                                |
       
   142       |                                                                |
       
   143       |                                                                |
       
   144       |----------------------------------------------------------------|
       
   145 */
       
   146 
       
   147 #endif // __TEXTVIEW_H__