libyui-ncurses
 
Loading...
Searching...
No Matches
NCtext.h
1/*
2 Copyright (C) 2000-2012 Novell, Inc
3 This library is free software; you can redistribute it and/or modify
4 it under the terms of the GNU Lesser General Public License as
5 published by the Free Software Foundation; either version 2.1 of the
6 License, or (at your option) version 3.0 of the License. This library
7 is distributed in the hope that it will be useful, but WITHOUT ANY
8 WARRANTY; without even the implied warranty of MERCHANTABILITY or
9 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10 License for more details. You should have received a copy of the GNU
11 Lesser General Public License along with this library; if not, write
12 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13 Floor, Boston, MA 02110-1301 USA
14*/
15
16
17/*-/
18
19 File: NCtext.h
20
21 Author: Michael Andres <ma@suse.de>
22
23/-*/
24
25#ifndef NCtext_h
26#define NCtext_h
27
28#include <iosfwd>
29#include <list>
30
31#include "NCstring.h"
32#include "NCWidget.h"
33
34class NCursesWindow;
35
37class NCtext
38{
39
40 friend std::ostream & operator<<( std::ostream & str, const NCtext & obj );
41
42public:
43
44 typedef std::list<NCstring>::iterator iterator;
45 typedef std::list<NCstring>::const_iterator const_iterator;
46
47private:
48
49 static const NCstring emptyStr;
50
51protected:
52
53 std::list<NCstring> mtext;
54
55 virtual void lset( const NCstring & ntext );
56 void lbrset( const NCstring & ntext, size_t columns );
57
58public:
59
60 NCtext( const NCstring & nstr = "" );
61 NCtext( const NCstring & nstr, size_t columns );
62
63 virtual ~NCtext();
64
65 unsigned Lines() const;
66 size_t Columns() const;
67
68 void append( const NCstring & line );
69
70 const std::list<NCstring> & Text() const { return mtext; }
71
72 const NCstring & operator[]( std::wstring::size_type idx ) const;
73
74 const_iterator begin() const { return mtext.begin(); }
75
76 const_iterator end() const { return mtext.end(); }
77};
78
79
81class NClabel : protected NCtext
82{
83
84 friend std::ostream & operator<<( std::ostream & str, const NClabel & obj );
85
86protected:
87
88 std::wstring::size_type hotline;
89
90 virtual void lset( const NCstring & ntext )
91 {
92 NCtext::lset( ntext );
93 }
94
95public:
96
97 void stripHotkey();
98
99 NClabel( const NCstring & nstr = "" )
100 : NCtext( nstr )
101 {}
102
103 virtual ~NClabel() {}
104
105 size_t width() const { return Columns(); }
106
107 unsigned height() const { return Lines(); }
108
109 wsze size() const { return wsze( Lines(), Columns() ); }
110
111 const std::list<NCstring> & getText() const { return Text(); }
112
113 void drawAt( NCursesWindow & w, chtype style, chtype hotstyle,
114 const wrect & dim,
115 const NC::ADJUST adjust = NC::TOPLEFT,
116 bool fillup = true ) const;
117
118 void drawAt( NCursesWindow & w, chtype style, chtype hotstyle,
119 const NC::ADJUST adjust = NC::TOPLEFT,
120 bool fillup = true ) const
121 {
122 drawAt( w, style, hotstyle, wrect( 0, -1 ), adjust, fillup );
123 }
124
125 void drawAt( NCursesWindow & w, chtype style, chtype hotstyle,
126 const wpos & pos,
127 const NC::ADJUST adjust = NC::TOPLEFT,
128 bool fillup = true ) const
129 {
130 drawAt( w, style, hotstyle, wrect( pos, -1 ), adjust, fillup );
131 }
132
133 void drawAt( NCursesWindow & w, chtype style, chtype hotstyle,
134 const wpos & pos, const wsze & sze,
135 const NC::ADJUST adjust = NC::TOPLEFT,
136 bool fillup = true ) const
137 {
138 drawAt( w, style, hotstyle, wrect( pos, sze ), adjust, fillup );
139 }
140
141 //
142 void drawAt( NCursesWindow & w, const NCstyle::StItem & istyle,
143 const NC::ADJUST adjust = NC::TOPLEFT,
144 bool fillup = true ) const
145 {
146 drawAt( w, istyle.label, istyle.hint, wrect( 0, -1 ), adjust, fillup );
147 }
148
149 void drawAt( NCursesWindow & w, const NCstyle::StItem & istyle,
150 const wpos & pos,
151 const NC::ADJUST adjust = NC::TOPLEFT,
152 bool fillup = true ) const
153 {
154 drawAt( w, istyle.label, istyle.hint, wrect( pos, -1 ), adjust, fillup );
155 }
156
157 void drawAt( NCursesWindow & w, const NCstyle::StItem & istyle,
158 const wpos & pos, const wsze & sze,
159 const NC::ADJUST adjust = NC::TOPLEFT,
160 bool fillup = true ) const
161 {
162 drawAt( w, istyle.label, istyle.hint, wrect( pos, sze ), adjust, fillup );
163 }
164
165 void drawAt( NCursesWindow & w, const NCstyle::StItem & istyle,
166 const wrect & dim,
167 const NC::ADJUST adjust = NC::TOPLEFT,
168 bool fillup = true ) const
169 {
170 drawAt( w, istyle.label, istyle.hint, dim, adjust, fillup );
171 }
172
173 //
174
175
176 bool hasHotkey() const { return hotline != std::wstring::npos; }
177
178 wchar_t hotkey() const { return hasHotkey() ? operator[]( hotline ).hotkey() : L'\0'; }
179
180 std::wstring::size_type hotpos() const { return hasHotkey() ? operator[]( hotline ).hotpos() : std::wstring::npos; }
181};
182
183
184#endif // NCtext_h
Definition NCstring.h:36
C++ class for windows.
Definition ncursesw.h:907
Screen position pair in the order line, column: (L, C)
Definition position.h:110
A rectangle is defined by its position and size: wpos Pos, wsze Sze.
Definition position.h:194
Screen dimension (screen size) in the order height, width: (H, W)
Definition position.h:154
ADJUST
Alignment aka justification: top/bottom, left/right, center.
Definition NCtypes.h:35
Definition NCstyle.h:347