@@ -20,24 +20,12 @@ Revision History:
2020#pragma once
2121
2222#include " outputStream.hpp"
23-
2423#include " ../buffer/out/OutputCellRect.hpp"
25- #include " ../buffer/out/TextAttribute.hpp"
2624#include " ../buffer/out/textBuffer.hpp"
27- #include " ../buffer/out/textBufferCellIterator.hpp"
28- #include " ../buffer/out/textBufferTextIterator.hpp"
29-
30- #include " IIoProvider.hpp"
31- #include " ../terminal/parser/stateMachine.hpp"
32-
33- #include " ../server/ObjectHeader.h"
34-
3525#include " ../interactivity/inc/IWindowMetrics.hpp"
36-
37- #include " ../renderer/inc/FontInfo.hpp"
3826#include " ../renderer/inc/FontInfoDesired.hpp"
27+ #include " ../server/ObjectHeader.h"
3928
40- #include " ../types/inc/Viewport.hpp"
4129class ConversionAreaInfo ; // forward decl window. circular reference
4230
4331class SCREEN_INFORMATION : public ConsoleObjectHeader , public Microsoft ::Console::IIoProvider
@@ -62,233 +50,177 @@ class SCREEN_INFORMATION : public ConsoleObjectHeader, public Microsoft::Console
6250 SCREEN_INFORMATION* self;
6351 };
6452
65- [[nodiscard]] static NTSTATUS CreateInstance (_In_ til::size coordWindowSize,
66- const FontInfo fontInfo,
67- _In_ til::size coordScreenBufferSize,
68- const TextAttribute defaultAttributes,
69- const TextAttribute popupAttributes,
70- const UINT uiCursorSize,
71- _Outptr_ SCREEN_INFORMATION** const ppScreen);
72-
73- ~SCREEN_INFORMATION () override ;
74-
75- void GetScreenBufferInformation (_Out_ til::size* pcoordSize,
76- _Out_ til::point* pcoordCursorPosition,
77- _Out_ til::inclusive_rect* psrWindow,
78- _Out_ PWORD pwAttributes,
79- _Out_ til::size* pcoordMaximumWindowSize,
80- _Out_ PWORD pwPopupAttributes,
81- _Out_writes_ (COLOR_TABLE_SIZE) LPCOLORREF lpColorTable) const ;
82-
83- void GetRequiredConsoleSizeInPixels (_Out_ til::size* const pRequiredSize) const ;
84-
85- void MakeCurrentCursorVisible ();
86- void MakeCursorVisible (til::point position);
87- void SnapOnInput (WORD vkey);
88- SnapOnScopeExit SnapOnOutput () noexcept ;
89-
90- void ClipToScreenBuffer (_Inout_ til::inclusive_rect* const psrClip) const ;
91-
92- til::size GetMinWindowSizeInCharacters (const til::size coordFontSize = { 1 , 1 }) const ;
93- til::size GetMaxWindowSizeInCharacters (const til::size coordFontSize = { 1 , 1 }) const ;
94- til::size GetLargestWindowSizeInCharacters (const til::size coordFontSize = { 1 , 1 }) const ;
95- til::size GetScrollBarSizesInCharacters () const ;
96-
97- Microsoft::Console::Types::Viewport GetBufferSize () const ;
98- Microsoft::Console::Types::Viewport GetTerminalBufferSize () const ;
99-
100- til::size GetScreenFontSize () const ;
101- void UpdateFont (const FontInfo* const pfiNewFont);
102- void RefreshFontWithRenderer ();
103-
104- [[nodiscard]] NTSTATUS ResizeScreenBuffer (const til::size coordNewScreenSize, const bool fDoScrollBarUpdate );
105-
10653 struct ScrollBarState
10754 {
10855 til::size maxSize;
10956 til::rect viewport;
11057 bool isAltBuffer = false ;
11158 };
112- void UpdateScrollBars ();
113- ScrollBarState FetchScrollBarState ();
114-
115- bool IsMaximizedBoth () const ;
116- bool IsMaximizedX () const ;
117- bool IsMaximizedY () const ;
118-
119- const Microsoft::Console::Types::Viewport& GetViewport () const noexcept ;
120- void SetViewport (const Microsoft::Console::Types::Viewport& newViewport, const bool updateBottom);
121- Microsoft::Console::Types::Viewport GetVirtualViewport () const noexcept ;
122- Microsoft::Console::Types::Viewport GetVtPageArea () const noexcept ;
123-
124- void ProcessResizeWindow (const til::rect* const prcClientNew, const til::rect* const prcClientOld);
125- void SetViewportSize (const til::size* const pcoordSize);
126-
127- // Forwarders to Window if we're the active buffer.
128- [[nodiscard]] NTSTATUS SetViewportOrigin (const bool fAbsolute , const til::point coordWindowOrigin, const bool updateBottom);
129-
130- bool SendNotifyBeep () const ;
131- bool PostUpdateWindowSize () const ;
132-
133- // TODO: MSFT 9355062 these methods should probably be a part of construction/destruction. http://osgvsowi/9355062
134- static void s_InsertScreenBuffer (_In_ SCREEN_INFORMATION* const pScreenInfo);
135- static void s_RemoveScreenBuffer (_In_ SCREEN_INFORMATION* const pScreenInfo);
136-
137- TextBufferCellIterator GetCellDataAt (const til::point at) const ;
138- TextBufferCellIterator GetCellLineDataAt (const til::point at) const ;
139- TextBufferCellIterator GetCellDataAt (const til::point at, const Microsoft::Console::Types::Viewport limit) const ;
140- TextBufferTextIterator GetTextDataAt (const til::point at) const ;
141- TextBufferTextIterator GetTextLineDataAt (const til::point at) const ;
142- TextBufferTextIterator GetTextDataAt (const til::point at, const Microsoft::Console::Types::Viewport limit) const ;
143-
144- OutputCellIterator Write (const OutputCellIterator it);
145-
146- OutputCellIterator Write (const OutputCellIterator it,
147- const til::point target,
148- const std::optional<bool > wrap = true );
149-
150- OutputCellIterator WriteRect (const OutputCellIterator it,
151- const Microsoft::Console::Types::Viewport viewport);
15259
153- void WriteRect (const OutputCellRect& data,
154- const til::point location);
155-
156- void ClearTextData ();
157-
158- std::pair<til::point, til::point> GetWordBoundary (const til::point position) const ;
159-
160- TextBuffer& GetTextBuffer () noexcept ;
161- const TextBuffer& GetTextBuffer () const noexcept ;
60+ ~SCREEN_INFORMATION () override ;
16261
16362#pragma region IIoProvider
16463 SCREEN_INFORMATION& GetActiveOutputBuffer () override ;
16564 const SCREEN_INFORMATION& GetActiveOutputBuffer () const override ;
16665 InputBuffer* const GetActiveInputBuffer () const override ;
16766#pragma endregion
16867
169- DWORD OutputMode{ ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT };
68+ // NOTE: If your method has 200 chars worth of parameters, and it's hard to read
69+ // without wrapping, chance is you're doing it wrong. This is also true here.
70+ // Should have been a default constructor + setters / builder pattern.
71+ // GetScreenBufferInformation could return a struct. And so on.
17072
171- short WheelDelta{ 0 };
172- short HWheelDelta{ 0 };
173-
174- private:
175- std::unique_ptr<TextBuffer> _textBuffer{ nullptr };
176-
177- public:
178- SCREEN_INFORMATION* Next{ nullptr };
179- BYTE WriteConsoleDbcsLeadByte[2 ]{ 0 , 0 };
180- BYTE FillOutDbcsLeadChar{ 0 };
181-
182- UINT ScrollScale{ 1u };
73+ // Creation
74+ [[nodiscard]] static NTSTATUS CreateInstance (til::size windowSize, FontInfo fontInfo, til::size screenBufferSize, TextAttribute defaultAttributes, TextAttribute popupAttributes, UINT cursorSize, SCREEN_INFORMATION** screen);
75+ static void s_InsertScreenBuffer (SCREEN_INFORMATION* screenInfo);
76+ static void s_RemoveScreenBuffer (SCREEN_INFORMATION* screenInfo);
18377
78+ // Buffer
79+ TextBuffer& GetTextBuffer () noexcept ;
80+ const TextBuffer& GetTextBuffer () const noexcept ;
18481 bool IsActiveScreenBuffer () const ;
185-
186- const Microsoft::Console::VirtualTerminal::StateMachine& GetStateMachine () const ;
187- Microsoft::Console::VirtualTerminal::StateMachine& GetStateMachine ();
188-
189- void SetCursorInformation (const ULONG Size,
190- const bool Visible) noexcept ;
191-
192- void SetCursorType (const CursorType Type, const bool setMain = false ) noexcept ;
193-
194- void SetCursorDBMode (const bool DoubleCursor);
195- [[nodiscard]] NTSTATUS SetCursorPosition (til::point Position);
196-
82+ [[nodiscard]] NTSTATUS ResizeScreenBuffer (til::size newScreenSize, bool doScrollBarUpdate);
83+ [[nodiscard]] NTSTATUS ResizeWithReflow (til::size newScreenSize);
84+ [[nodiscard]] NTSTATUS ResizeTraditional (til::size newScreenSize);
19785 [[nodiscard]] NTSTATUS UseAlternateScreenBuffer (const TextAttribute& initAttributes);
19886 void UseMainScreenBuffer ();
199-
20087 SCREEN_INFORMATION& GetMainBuffer ();
20188 const SCREEN_INFORMATION& GetMainBuffer () const ;
20289 const SCREEN_INFORMATION* GetAltBuffer () const noexcept ;
20390 SCREEN_INFORMATION& GetActiveBuffer ();
20491 const SCREEN_INFORMATION& GetActiveBuffer () const ;
205-
20692 const TextAttribute& GetAttributes () const noexcept ;
20793 const TextAttribute& GetPopupAttributes () const noexcept ;
208-
20994 void SetAttributes (const TextAttribute& attributes);
21095 void SetPopupAttributes (const TextAttribute& popupAttributes);
211- void SetDefaultAttributes (const TextAttribute& attributes,
212- const TextAttribute& popupAttributes );
96+ void SetDefaultAttributes (const TextAttribute& attributes, const TextAttribute& popupAttributes);
97+ void ProcessResizeWindow ( const til::rect* clientNew, const til::rect* clientOld );
21398
214- void UpdateBottom ();
99+ // Cursor
100+ [[nodiscard]] NTSTATUS SetCursorPosition (til::point Position);
101+ void MakeCurrentCursorVisible ();
102+ void MakeCursorVisible (til::point position);
103+ void SnapOnInput (WORD vkey);
104+ SnapOnScopeExit SnapOnOutput () noexcept ;
105+ void SetCursorInformation (ULONG size, bool visible) noexcept ;
106+ void SetCursorType (CursorType type, bool setMain = false ) noexcept ;
107+ void SetCursorDBMode (bool doubleCursor);
108+
109+ // I/O
110+ const Microsoft::Console::VirtualTerminal::StateMachine& GetStateMachine () const ;
111+ Microsoft::Console::VirtualTerminal::StateMachine& GetStateMachine ();
112+ TextBufferCellIterator GetCellDataAt (til::point at) const ;
113+ TextBufferCellIterator GetCellLineDataAt (til::point at) const ;
114+ TextBufferCellIterator GetCellDataAt (til::point at, Microsoft::Console::Types::Viewport limit) const ;
115+ TextBufferTextIterator GetTextDataAt (til::point at) const ;
116+ TextBufferTextIterator GetTextLineDataAt (til::point at) const ;
117+ TextBufferTextIterator GetTextDataAt (til::point at, Microsoft::Console::Types::Viewport limit) const ;
118+ OutputCellIterator Write (OutputCellIterator it);
119+ OutputCellIterator Write (OutputCellIterator it, til::point target, std::optional<bool > wrap = true );
120+ OutputCellIterator WriteRect (OutputCellIterator it, Microsoft::Console::Types::Viewport viewport);
121+ void WriteRect (const OutputCellRect& data, til::point location);
122+ void ClearTextData ();
215123
124+ // Rendering / Viewport
216125 FontInfo& GetCurrentFont () noexcept ;
217126 const FontInfo& GetCurrentFont () const noexcept ;
218-
219127 FontInfoDesired& GetDesiredFont () noexcept ;
220128 const FontInfoDesired& GetDesiredFont () const noexcept ;
129+ til::size GetScreenFontSize () const ;
130+ void UpdateFont (const FontInfo* newFont);
131+ void RefreshFontWithRenderer ();
132+ [[nodiscard]] NTSTATUS SetViewportOrigin (bool absolute, til::point coordWindowOrigin, bool updateBottom);
133+ const Microsoft::Console::Types::Viewport& GetViewport () const noexcept ;
134+ void SetViewport (const Microsoft::Console::Types::Viewport& newViewport, bool updateBottom);
135+ void SetViewportSize (const til::size* size);
136+ void UpdateBottom ();
137+ Microsoft::Console::Types::Viewport GetVirtualViewport () const noexcept ;
138+ Microsoft::Console::Types::Viewport GetVtPageArea () const noexcept ;
221139
222- [[nodiscard]] NTSTATUS ResizeWithReflow (const til::size coordnewScreenSize);
223- [[nodiscard]] NTSTATUS ResizeTraditional (const til::size coordNewScreenSize);
140+ // Windowing
141+ til::size GetScrollBarSizesInCharacters () const ;
142+ void UpdateScrollBars ();
143+ ScrollBarState FetchScrollBarState ();
144+ bool IsMaximizedBoth () const ;
145+ bool IsMaximizedX () const ;
146+ bool IsMaximizedY () const ;
147+ bool PostUpdateWindowSize () const ;
224148
149+ // General Information
150+ void GetScreenBufferInformation (til::size* size, til::point* cursorPosition, til::inclusive_rect* window, PWORD attributes, til::size* maximumWindowSize, PWORD popupAttributes, LPCOLORREF colorTable) const ;
151+ void GetRequiredConsoleSizeInPixels (til::size* requiredSize) const ;
152+ til::size GetMinWindowSizeInCharacters (til::size fontSize = { 1 , 1 }) const ;
153+ til::size GetMaxWindowSizeInCharacters (til::size fontSize = { 1 , 1 }) const ;
154+ til::size GetLargestWindowSizeInCharacters (til::size fontSize = { 1 , 1 }) const ;
155+
156+ // Helpers
157+ void ClipToScreenBuffer (til::inclusive_rect* clip) const ;
158+ std::pair<til::point, til::point> GetWordBoundary (til::point position) const ;
159+ Microsoft::Console::Types::Viewport GetBufferSize () const ;
160+ Microsoft::Console::Types::Viewport GetTerminalBufferSize () const ;
161+ bool SendNotifyBeep () const ;
225162 bool ConptyCursorPositionMayBeWrong () const noexcept ;
226163 void SetConptyCursorPositionMayBeWrong () noexcept ;
227164 void ResetConptyCursorPositionMayBeWrong () noexcept ;
228165 void WaitForConptyCursorPositionToBeSynchronized () noexcept ;
229166
230- private:
231- SCREEN_INFORMATION (_In_ Microsoft::Console::Interactivity::IWindowMetrics* pMetrics,
232- const TextAttribute popupAttributes,
233- const FontInfo fontInfo);
234-
235- Microsoft::Console::Interactivity::IWindowMetrics* _pConsoleWindowMetrics;
167+ DWORD OutputMode = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
168+ short WheelDelta = 0 ;
169+ short HWheelDelta = 0 ;
170+ SCREEN_INFORMATION* Next = nullptr ;
171+ BYTE WriteConsoleDbcsLeadByte[2 ] = { 0 , 0 };
172+ BYTE FillOutDbcsLeadChar = 0 ;
173+ UINT ScrollScale = 1 ;
236174
237- [[nodiscard]] HRESULT _AdjustScreenBufferHelper (const til::rect* const prcClientNew,
238- const til::size coordBufferOld,
239- _Out_ til::size* const pcoordClientNewCharacters);
240- [[nodiscard]] HRESULT _AdjustScreenBuffer (const til::rect* const prcClientNew);
241- void _CalculateViewportSize (const til::rect* const prcClientArea, _Out_ til::size* const pcoordSize);
242- void _AdjustViewportSize (const til::rect* const prcClientNew, const til::rect* const prcClientOld, const til::size* const pcoordSize);
243- void _InternalSetViewportSize (const til::size* pcoordSize, const bool fResizeFromTop , const bool fResizeFromLeft );
244- void _makeCursorVisible ();
245-
246- static void s_CalculateScrollbarVisibility (const til::rect* const prcClientArea,
247- const til::size* const pcoordBufferSize,
248- const til::size* const pcoordFontSize,
249- _Out_ bool * const pfIsHorizontalVisible,
250- _Out_ bool * const pfIsVerticalVisible);
175+ private:
176+ SCREEN_INFORMATION (Microsoft::Console::Interactivity::IWindowMetrics* metrics, TextAttribute popupAttributes, FontInfo fontInfo);
251177
178+ // Construction
252179 [[nodiscard]] NTSTATUS _InitializeOutputStateMachine ();
253180 void _FreeOutputStateMachine ();
254181
255- [[nodiscard]] NTSTATUS _CreateAltBuffer (const TextAttribute& initAttributes,
256- _Out_ SCREEN_INFORMATION** const ppsiNewScreenBuffer);
257-
182+ // Buffer
183+ [[nodiscard]] HRESULT _AdjustScreenBufferHelper (const til::rect* clientNew, til::size bufferOld, til::size* clientNewCharacters);
184+ [[nodiscard]] HRESULT _AdjustScreenBuffer (const til::rect* clientNew);
185+ [[nodiscard]] NTSTATUS _CreateAltBuffer (const TextAttribute& initAttributes, SCREEN_INFORMATION** newScreenBuffer);
258186 bool _IsAltBuffer () const ;
259187 bool _IsInPtyMode () const ;
260188 bool _IsInVTMode () const ;
261189
262- ConhostInternalGetSet _api{ *this };
190+ // Cursor
191+ void _makeCursorVisible ();
263192
264- std::shared_ptr<Microsoft::Console::VirtualTerminal::StateMachine> _stateMachine{ nullptr };
193+ // Rendering / Viewport
194+ void _CalculateViewportSize (const til::rect* clientArea, til::size* size);
195+ void _AdjustViewportSize (const til::rect* clientNew, const til::rect* clientOld, const til::size* size);
196+ void _InternalSetViewportSize (const til::size* size, bool resizeFromTop, bool resizeFromLeft);
197+
198+ // Windowing
199+ static void s_CalculateScrollbarVisibility (const til::rect* clientArea, const til::size* bufferSize, const til::size* fontSize, bool * horizontalVisible, bool * verticalVisible);
200+ static void _handleDeferredResize (SCREEN_INFORMATION& siMain);
265201
202+ Microsoft::Console::Interactivity::IWindowMetrics* _pConsoleWindowMetrics;
203+ std::unique_ptr<TextBuffer> _textBuffer{ nullptr };
204+ ConhostInternalGetSet _api{ *this };
205+ std::shared_ptr<Microsoft::Console::VirtualTerminal::StateMachine> _stateMachine;
266206 // Specifies which coordinates of the screen buffer are visible in the
267207 // window client (the "viewport" into the buffer)
268208 Microsoft::Console::Types::Viewport _viewport;
269-
270- SCREEN_INFORMATION* _psiAlternateBuffer{ nullptr }; // The VT "Alternate" screen buffer.
271- SCREEN_INFORMATION* _psiMainBuffer{ nullptr }; // A pointer to the main buffer, if this is the alternate buffer.
272-
273- til::rect _rcAltSavedClientNew{};
274- til::rect _rcAltSavedClientOld{};
275- bool _fAltWindowChanged{ false };
276-
209+ SCREEN_INFORMATION* _psiAlternateBuffer = nullptr ; // The VT "Alternate" screen buffer.
210+ SCREEN_INFORMATION* _psiMainBuffer = nullptr ; // A pointer to the main buffer, if this is the alternate buffer.
211+ til::rect _rcAltSavedClientNew;
212+ til::rect _rcAltSavedClientOld;
213+ bool _fAltWindowChanged = false ;
277214 TextAttribute _PopupAttributes;
278-
279215 FontInfo _currentFont;
280216 FontInfoDesired _desiredFont;
281-
282217 // Tracks the last virtual position the viewport was at. This is not
283218 // affected by the user scrolling the viewport, only when API calls cause
284219 // the viewport to move (SetBufferInfo, WriteConsole, etc)
285- til::CoordType _virtualBottom{ 0 };
286-
287- std::optional<til::size> _deferredPtyResize{ std::nullopt };
220+ til::CoordType _virtualBottom = 0 ;
221+ std::optional<til::size> _deferredPtyResize;
288222 std::atomic<bool > _conptyCursorPositionMayBeWrong = false ;
289223
290- static void _handleDeferredResize (SCREEN_INFORMATION& siMain);
291-
292224#ifdef UNIT_TESTING
293225 friend class TextBufferIteratorTests ;
294226 friend class ScreenBufferTests ;
0 commit comments