move code responsible for screen resize to SIGWINCH handler
[ncmpcpp.git] / src / scrollpad.h
blob0dbe17853e67234058d5354645cda933f29a8f81
1 /***************************************************************************
2 * Copyright (C) 2008-2009 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #ifndef _SCROLLPAD_H
22 #define _SCROLLPAD_H
24 #include "window.h"
25 #include "strbuffer.h"
27 namespace NCurses
29 /// Scrollpad is specialized window that can hold large portion of text and
30 /// supports scrolling if the amount of it is bigger than the window area.
31 ///
32 class Scrollpad: public Window
34 public:
35 /// Constructs an empty scrollpad with given parameters
36 /// @param startx X position of left upper corner of constructed window
37 /// @param starty Y position of left upper corner of constructed window
38 /// @param width width of constructed window
39 /// @param height height of constructed window
40 /// @param title title of constructed window
41 /// @param color base color of constructed window
42 /// @param border border of constructed window
43 ///
44 Scrollpad(size_t startx, size_t starty, size_t width, size_t height,
45 const std::string &title, Color color, Border border);
47 /// Copies the scrollpad
48 /// @param s copied scrollpad
49 ///
50 Scrollpad(const Scrollpad &s);
52 /// Prints the text stored in internal buffer to window. Note that
53 /// all changes that has been made for text stored in scrollpad won't
54 /// be visible until one invokes this function
55 ///
56 void Flush();
58 /// Searches for given string in text and sets format/color at the
59 /// beginning and end of it using val_b and val_e flags accordingly
60 /// @param val_b flag set at the beginning of found occurence of string
61 /// @param s string that function seaches for
62 /// @param val_e flag set at the end of found occurence of string
63 /// @param for_each indicates whether function searches through whole text and sets
64 /// given format for all occurences of given string or stops after first occurence
65 /// @return true if at least one occurence of the string was found, false otherwise
66 /// @see basic_buffer::SetFormatting()
67 ///
68 bool SetFormatting(short val_b, const std::basic_string<my_char_t> &s,
69 short val_e, bool for_each = 1);
71 /// Removes all format flags and colors from stored text
72 ///
73 void ForgetFormatting();
75 /// Removes all format flags and colors that was applied
76 /// by the most recent call to SetFormatting() function
77 /// @see SetFormatting()
78 /// @see basic_buffer::RemoveFormatting()
79 ///
80 void RemoveFormatting();
82 /// @return text stored in internal buffer
83 ///
84 std::basic_string<my_char_t> Content() { return itsBuffer.Str(); }
86 /// Refreshes the window
87 /// @see Window::Refresh()
88 ///
89 virtual void Refresh();
91 /// Scrolls by given amount of lines
92 /// @param where indicates where exactly one wants to go
93 /// @see Window::Scroll()
94 ///
95 virtual void Scroll(Where where);
97 /// Resizes the window
98 /// @param new_width new window's width
99 /// @param new_height new window's height
100 /// @see Window::Resize()
102 virtual void Resize(size_t new_width, size_t new_height);
104 /// Cleares the content of scrollpad
105 /// @param clear_screen indicates whether window has to be cleared imediately or not
106 /// @see Window::Clear()
108 virtual void Clear(bool clear_screen = 1);
110 /// Sets starting position to the beginning
112 void Reset();
114 /// Template function that redirects all data passed
115 /// to the scrollpad window to its internal buffer
116 /// @param obj any object that has ostream &operator<<() defined
117 /// @return reference to itself
119 template <typename T> Scrollpad &operator<<(const T &obj)
121 itsBuffer << obj;
122 return *this;
124 # ifdef _UTF8
125 Scrollpad &operator<<(const std::string &s);
126 # endif // _UTF8
128 private:
129 basic_buffer<my_char_t> itsBuffer;
131 int itsBeginning;
133 bool itsFoundForEach;
134 short itsFoundValueBegin;
135 short itsFoundValueEnd;
136 std::basic_string<my_char_t> itsFoundPattern;
138 size_t itsRealHeight;
142 #endif