libyui-ncurses  2.44.1
 All Classes Functions Variables
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 
34 class NCursesWindow;
35 
36 
37 class NCtext
38 {
39 
40  friend std::ostream & operator<<( std::ostream & STREAM, const NCtext & OBJ );
41 
42 public:
43 
44  typedef std::list<NCstring>::iterator iterator;
45  typedef std::list<NCstring>::const_iterator const_iterator;
46 
47 private:
48 
49  static const NCstring emptyStr;
50 
51 protected:
52 
53  std::list<NCstring> mtext;
54 
55  virtual void lset( const NCstring & ntext );
56  void lbrset( const NCstring & ntext, size_t columns );
57 
58 public:
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 
80 
81 class NClabel : protected NCtext
82 {
83 
84  friend std::ostream & operator<<( std::ostream & STREAM, const NClabel & OBJ );
85 
86 protected:
87 
88  std::wstring::size_type hotline;
89 
90  virtual void lset( const NCstring & ntext )
91  {
92  NCtext::lset( ntext );
93  }
94 
95 public:
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  //
119  void drawAt( NCursesWindow & w, chtype style, chtype hotstyle,
120  const NC::ADJUST adjust = NC::TOPLEFT,
121  bool fillup = true ) const
122  {
123  drawAt( w, style, hotstyle, wrect( 0, -1 ), adjust, fillup );
124  }
125 
126  void drawAt( NCursesWindow & w, chtype style, chtype hotstyle,
127  const wpos & pos,
128  const NC::ADJUST adjust = NC::TOPLEFT,
129  bool fillup = true ) const
130  {
131  drawAt( w, style, hotstyle, wrect( pos, -1 ), adjust, fillup );
132  }
133 
134  void drawAt( NCursesWindow & w, chtype style, chtype hotstyle,
135  const wpos & pos, const wsze & sze,
136  const NC::ADJUST adjust = NC::TOPLEFT,
137  bool fillup = true ) const
138  {
139  drawAt( w, style, hotstyle, wrect( pos, sze ), adjust, fillup );
140  }
141 
142  //
143  void drawAt( NCursesWindow & w, const NCstyle::StItem & istyle,
144  const NC::ADJUST adjust = NC::TOPLEFT,
145  bool fillup = true ) const
146  {
147  drawAt( w, istyle.label, istyle.hint, wrect( 0, -1 ), adjust, fillup );
148  }
149 
150  void drawAt( NCursesWindow & w, const NCstyle::StItem & istyle,
151  const wpos & pos,
152  const NC::ADJUST adjust = NC::TOPLEFT,
153  bool fillup = true ) const
154  {
155  drawAt( w, istyle.label, istyle.hint, wrect( pos, -1 ), adjust, fillup );
156  }
157 
158  void drawAt( NCursesWindow & w, const NCstyle::StItem & istyle,
159  const wpos & pos, const wsze & sze,
160  const NC::ADJUST adjust = NC::TOPLEFT,
161  bool fillup = true ) const
162  {
163  drawAt( w, istyle.label, istyle.hint, wrect( pos, sze ), adjust, fillup );
164  }
165 
166  void drawAt( NCursesWindow & w, const NCstyle::StItem & istyle,
167  const wrect & dim,
168  const NC::ADJUST adjust = NC::TOPLEFT,
169  bool fillup = true ) const
170  {
171  drawAt( w, istyle.label, istyle.hint, dim, adjust, fillup );
172  }
173 
174  //
175 
176 
177  bool hasHotkey() const { return hotline != std::wstring::npos; }
178 
179  wchar_t hotkey() const { return hasHotkey() ? operator[]( hotline ).hotkey() : L'\0'; }
180 
181  std::wstring::size_type hotpos() const { return hasHotkey() ? operator[]( hotline ).hotpos() : std::wstring::npos; }
182 };
183 
184 
185 #endif // NCtext_h
C++ class for windows.
Definition: ncursesw.h:904
Definition: NCtext.h:37
Definition: position.h:109
Definition: NCtext.h:81
Definition: position.h:154