cxWidgets 1.0
cxScrolledWindow.h
Go to the documentation of this file.
1// Copyright (c) 2026 E. Oulashin
2#ifndef __CXSCROLLEDWINDOW_H__
3#define __CXSCROLLEDWINDOW_H__
4// Copyright (c) 2005-2007 Michael H. Kinney
5
6#include "cxWindow.h"
7#include "cxFunction.h"
8#include <string>
9
10namespace cx {
11
12#define DEFAULT_CXSCROLLEDWINDOW_SEARCH_KEY '/' // Default search key
13#define DEFAULT_CXSCROLLEDWINDOW_GOTO_KEY CTRL_G // Default key to go to a line#
14#define DEFAULT_CXSCROLLEDWINDOW_ALT_PGUP_KEY '.' // Default alternate PgUp key
15#define DEFAULT_CXSCROLLEDWINDOW_ALT_PGDOWN_KEY ',' // Default alternate PgDown key
16
54{
55 public:
76 explicit cxScrolledWindow(cxWindow *pParentWindow = nullptr,
77 int pRow = 0, int pCol = 0,
78 int pHeight = DEFAULT_HEIGHT,
79 int pWidth = DEFAULT_WIDTH,
80 const std::string& pTitle = "",
81 const std::string& pMessage = "",
82 const std::string& pStatus = "",
83 eBorderStyle pBorderStyle = eBS_SINGLE_LINE,
84 cxWindow *pExtTitleWindow = nullptr,
85 cxWindow *pExtStatusWindow = nullptr,
86 bool pMessageUnderlines = false);
87
102 int pRow, int pCol, const std::string& pTitle,
103 const std::string& pMessage, const std::string& pStatus,
104 cxWindow *pExtTitleWindow = nullptr,
105 cxWindow *pExtStatusWindow = nullptr,
106 bool pMessageUnderlines = false);
107
120 const std::string& pTitle, const std::string& pMessage,
121 const std::string& pStatus,
122 cxWindow *pExtTitleWindow = nullptr,
123 cxWindow *pExtStatusWindow = nullptr,
124 bool pMessageUnderlines = false);
125
137 const std::string& pMessage, const std::string& pStatus,
138 cxWindow *pExtTitleWindow = nullptr,
139 cxWindow *pExtStatusWindow = nullptr,
140 bool pMessageUnderlines = false);
141
151 cxScrolledWindow(cxWindow *pParentWindow, const std::string& pMessage,
152 cxWindow *pExtTitleWindow = nullptr,
153 cxWindow *pExtStatusWindow = nullptr,
154 bool pMessageUnderlines = false);
155
168 cxScrolledWindow(cxWindow *pParentWindow, eHPosition pHPosition,
169 const std::string& pTitle, const std::string& pMessage,
170 const std::string& pStatus,
171 cxWindow *pExtTitleWindow = nullptr,
172 cxWindow *pExtStatusWindow = nullptr,
173 bool pMessageUnderlines = false);
174
179 cxScrolledWindow(const cxScrolledWindow& pThatWindow);
180
181 virtual ~cxScrolledWindow();
182
193 virtual long show(bool pBringToTop = true, bool pShowSubwindows = true) override;
194
209 virtual long showModal(bool pShowSelf = true, bool pBringToTop = true,
210 bool pShowSubwindows = false) override;
211
219 virtual void scrollWin(int pVertScrollAmt, int pHorizScrollAmt,
220 bool pRefresh = false);
221
225 virtual void drawMessage() override;
226
235 virtual bool move(int pNewRow, int pNewCol, bool pRefresh = true) override;
236
243 virtual void resize(int pNewHeight, int pNewWidth, bool pRefresh = false) override;
244
252 cxScrolledWindow& operator =(const cxScrolledWindow& pThatWindow);
253
259 virtual void setSearchKey(int pKey);
260
266 virtual void setGoToKey(int pKey);
267
273 virtual void useLastKeyword(bool pUseLastKeyword);
274
280 virtual void setAltPgUpKey(int pKey);
281
287 virtual void setAltPgDownKey(int pKey);
288
296 virtual void setLoopStartFunction(const std::shared_ptr<cxFunction>& pFuncPtr);
297
305 virtual void setLoopEndFunction(const std::shared_ptr<cxFunction>& pFuncPtr);
306
314 virtual std::string cxTypeStr() const override;
315
319 virtual void drawBorder() override;
320
321 protected:
325 void reCreateSubWindow();
326
342 virtual void init(int pRow, int pCol, int pHeight, int pWidth,
343 const std::string& pTitle, const std::string& pMessage,
344 const std::string& pStatus,
345 cxWindow *pParentWindow = nullptr,
346 bool pResizeVertically = false) override;
347
353 void copyCxScrolledWindowStuff(const cxScrolledWindow* pThatWindow);
354
361 int getLineNumber() const;
362
368 int getSubWinHeight() const;
369
375 int getSubWinWidth() const;
376
377 private:
378 WINDOW *mSubWindow = nullptr; // For scrolling
379 int mSubWinHeight = 0; // The height of the subwindow
380 int mSubWinWidth = 0; // The width of the subwindow
381 int mLineNumber = 0; // The topmost line# being shown from mMessageLines
382 int mHScrollOffset = 0; // Horizontal scrolling offset
383 int mSearchKey = DEFAULT_CXSCROLLEDWINDOW_SEARCH_KEY; // Key to use for searching
384 int mGoToKey = DEFAULT_CXSCROLLEDWINDOW_GOTO_KEY; // Key to use to go to a specific line#
385 int mAltPgUpKey = DEFAULT_CXSCROLLEDWINDOW_ALT_PGUP_KEY; // Alternate key for a pageUp
386 int mAltPgDownKey = DEFAULT_CXSCROLLEDWINDOW_ALT_PGDOWN_KEY; // Alternate key for a pageDown
387 std::string mSearchKeyword; // Previous keyword used for searching
388 bool mUseLastKeyword = true; // Whether or not to use mSearchKeyword for searching
389
390 // Functions to be run at various points in the input loop
391 std::shared_ptr<cxFunction> mLoopStartFunction; // At the start of each cycle
392 std::shared_ptr<cxFunction> mLoopEndFunction; // At the end of each cycle
393
394 // Handles the input loop. Returns a return code based on the
395 // user's input.
396 //
397 // Parameters:
398 // pRunOnLeaveFunction (OUT): This will store whether or not the onLeave
399 // function should run.
400 long doInputLoop(bool& pRunOnLeaveFunction);
401
409 std::string getLine(int pLineNumber);
410
411 // Scrolls to a specific line in mMessageLines.
412 // Parameters:
413 // pLineNum: The line # to which to scroll (0-based)
414 inline void goToLine(int pLineNum);
415
416 // Prompts the user for a line number and scrolls to
417 // that line.
418 void doGoToLine();
419
420 // Prompts the user for a search keyword & scrolls to
421 // the line with that keyword.
422 void doSearch();
423
424 // Puts the horizontal scroll arrows in place on the bottom border.
425 void drawHorizontalScrollArrows();
426};
427
428} // namespace cx
429
430#endif
Represents a text window with scrolling. This class is.
Definition cxScrolledWindow.h:54
cxScrolledWindow(cxWindow *pParentWindow, const std::string &pTitle, const std::string &pMessage, const std::string &pStatus, cxWindow *pExtTitleWindow=nullptr, cxWindow *pExtStatusWindow=nullptr, bool pMessageUnderlines=false)
Overridden constructor - Centers the window in the middle of the screen.
virtual void resize(int pNewHeight, int pNewWidth, bool pRefresh=false) override
Definition cxScrolledWindow.cpp:363
virtual void drawMessage() override
Definition cxScrolledWindow.cpp:271
virtual std::string cxTypeStr() const override
Returns the name of the cxWidgets class. This can be used to.
Definition cxScrolledWindow.cpp:425
virtual ~cxScrolledWindow()
Definition cxScrolledWindow.cpp:130
cxScrolledWindow & operator=(const cxScrolledWindow &pThatWindow)
Assignment operator.
Definition cxScrolledWindow.cpp:379
int getSubWinHeight() const
Returns the height of the scrollable subwindow.
Definition cxScrolledWindow.cpp:574
virtual bool move(int pNewRow, int pNewCol, bool pRefresh=true) override
Definition cxScrolledWindow.cpp:323
virtual void init(int pRow, int pCol, int pHeight, int pWidth, const std::string &pTitle, const std::string &pMessage, const std::string &pStatus, cxWindow *pParentWindow=nullptr, bool pResizeVertically=false) override
Initializes the window parameters and sets up the internal.
Definition cxScrolledWindow.cpp:503
virtual void scrollWin(int pVertScrollAmt, int pHorizScrollAmt, bool pRefresh=false)
Scrolls the window text by a certain amount.
Definition cxScrolledWindow.cpp:222
cxScrolledWindow(cxWindow *pParentWindow, const std::string &pMessage, const std::string &pStatus, cxWindow *pExtTitleWindow=nullptr, cxWindow *pExtStatusWindow=nullptr, bool pMessageUnderlines=false)
Overridden constructor - Centers the window in the middle of the screen.
virtual void setLoopStartFunction(const std::shared_ptr< cxFunction > &pFuncPtr)
Sets a function to be run at the start of each.
Definition cxScrolledWindow.cpp:415
virtual void useLastKeyword(bool pUseLastKeyword)
Sets whether to use the last keyword in new searches.
Definition cxScrolledWindow.cpp:400
int getLineNumber() const
Returns the number of the line currently being displayed.
Definition cxScrolledWindow.cpp:569
void copyCxScrolledWindowStuff(const cxScrolledWindow *pThatWindow)
Makes a copy of a cxScrolledWindow's member variables.
Definition cxScrolledWindow.cpp:512
int getSubWinWidth() const
Returns the width of the scrollable subwindow.
Definition cxScrolledWindow.cpp:579
virtual void setSearchKey(int pKey)
Sets the key to use for searching.
Definition cxScrolledWindow.cpp:390
virtual void setAltPgUpKey(int pKey)
Sets the alternate pageUp key.
Definition cxScrolledWindow.cpp:405
virtual void setGoToKey(int pKey)
Sets the key to use for going to a specific line#.
Definition cxScrolledWindow.cpp:395
virtual void setLoopEndFunction(const std::shared_ptr< cxFunction > &pFuncPtr)
Sets a function to be run at the end of each.
Definition cxScrolledWindow.cpp:420
cxScrolledWindow(cxWindow *pParentWindow, const std::string &pMessage, cxWindow *pExtTitleWindow=nullptr, cxWindow *pExtStatusWindow=nullptr, bool pMessageUnderlines=false)
Overridden constructor - Centers the window in the middle of the screen.
virtual long showModal(bool pShowSelf=true, bool pBringToTop=true, bool pShowSubwindows=false) override
Shows the window, running an input loop allowing the user to.
Definition cxScrolledWindow.cpp:177
virtual void setAltPgDownKey(int pKey)
Sets the new alternate pageDown key.
Definition cxScrolledWindow.cpp:410
cxScrolledWindow(cxWindow *pParentWindow=nullptr, int pRow=0, int pCol=0, int pHeight=DEFAULT_HEIGHT, int pWidth=DEFAULT_WIDTH, const std::string &pTitle="", const std::string &pMessage="", const std::string &pStatus="", eBorderStyle pBorderStyle=eBS_SINGLE_LINE, cxWindow *pExtTitleWindow=nullptr, cxWindow *pExtStatusWindow=nullptr, bool pMessageUnderlines=false)
Default constructor.
cxScrolledWindow(cxWindow *pParentWindow, eHPosition pHPosition, const std::string &pTitle, const std::string &pMessage, const std::string &pStatus, cxWindow *pExtTitleWindow=nullptr, cxWindow *pExtStatusWindow=nullptr, bool pMessageUnderlines=false)
Overridden constructor - Lets you specify the horizontal position.
virtual long show(bool pBringToTop=true, bool pShowSubwindows=true) override
Shows the window.
Definition cxScrolledWindow.cpp:139
void reCreateSubWindow()
Re-creates the scrollable subwindow.
Definition cxScrolledWindow.cpp:464
cxScrolledWindow(cxWindow *pParentWindow, int pRow, int pCol, const std::string &pTitle, const std::string &pMessage, const std::string &pStatus, cxWindow *pExtTitleWindow=nullptr, cxWindow *pExtStatusWindow=nullptr, bool pMessageUnderlines=false)
Overridden constructor.
virtual void drawBorder() override
Draws a border around the window.
Definition cxScrolledWindow.cpp:430
Represents a text-based window on the screen. Can contain a title, status, and a message to appear wi...
Definition cxWindow.h:195
#define DEFAULT_CXSCROLLEDWINDOW_SEARCH_KEY
Definition cxScrolledWindow.h:12
#define DEFAULT_CXSCROLLEDWINDOW_GOTO_KEY
Definition cxScrolledWindow.h:13
#define DEFAULT_CXSCROLLEDWINDOW_ALT_PGUP_KEY
Definition cxScrolledWindow.h:14
#define DEFAULT_CXSCROLLEDWINDOW_ALT_PGDOWN_KEY
Definition cxScrolledWindow.h:15
#define DEFAULT_HEIGHT
Definition cxWindow.h:68
#define DEFAULT_WIDTH
Definition cxWindow.h:69
cxBorderChars.h - Defines border characters to be used in drawing a box (i.e., in cxWindow and all it...
Definition cxApp.cpp:5
eBorderStyle
Definition cxBorderStyles.h:26
@ eBS_SINGLE_LINE
Definition cxBorderStyles.h:28
eHPosition
Definition cxPositions.h:16