libyui-ncurses
2.44.1
|
00001 /* 00002 Copyright (C) 2000-2012 Novell, Inc 00003 This library is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU Lesser General Public License as 00005 published by the Free Software Foundation; either version 2.1 of the 00006 License, or (at your option) version 3.0 of the License. This library 00007 is distributed in the hope that it will be useful, but WITHOUT ANY 00008 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00009 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00010 License for more details. You should have received a copy of the GNU 00011 Lesser General Public License along with this library; if not, write 00012 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth 00013 Floor, Boston, MA 02110-1301 USA 00014 */ 00015 00016 00017 /*-/ 00018 00019 File: NCtext.h 00020 00021 Author: Michael Andres <ma@suse.de> 00022 00023 /-*/ 00024 00025 #ifndef NCtext_h 00026 #define NCtext_h 00027 00028 #include <iosfwd> 00029 #include <list> 00030 00031 #include "NCstring.h" 00032 #include "NCWidget.h" 00033 00034 class NCursesWindow; 00035 00036 00037 class NCtext 00038 { 00039 00040 friend std::ostream & operator<<( std::ostream & STREAM, const NCtext & OBJ ); 00041 00042 public: 00043 00044 typedef std::list<NCstring>::iterator iterator; 00045 typedef std::list<NCstring>::const_iterator const_iterator; 00046 00047 private: 00048 00049 static const NCstring emptyStr; 00050 00051 protected: 00052 00053 std::list<NCstring> mtext; 00054 00055 virtual void lset( const NCstring & ntext ); 00056 void lbrset( const NCstring & ntext, size_t columns ); 00057 00058 public: 00059 00060 NCtext( const NCstring & nstr = "" ); 00061 NCtext( const NCstring & nstr, size_t columns ); 00062 00063 virtual ~NCtext(); 00064 00065 unsigned Lines() const; 00066 size_t Columns() const; 00067 00068 void append( const NCstring & line ); 00069 00070 const std::list<NCstring> & Text() const { return mtext; } 00071 00072 const NCstring & operator[]( std::wstring::size_type idx ) const; 00073 00074 const_iterator begin() const { return mtext.begin(); } 00075 00076 const_iterator end() const { return mtext.end(); } 00077 }; 00078 00079 00080 00081 class NClabel : protected NCtext 00082 { 00083 00084 friend std::ostream & operator<<( std::ostream & STREAM, const NClabel & OBJ ); 00085 00086 protected: 00087 00088 std::wstring::size_type hotline; 00089 00090 virtual void lset( const NCstring & ntext ) 00091 { 00092 NCtext::lset( ntext ); 00093 } 00094 00095 public: 00096 00097 void stripHotkey(); 00098 00099 NClabel( const NCstring & nstr = "" ) 00100 : NCtext( nstr ) 00101 {} 00102 00103 virtual ~NClabel() {} 00104 00105 size_t width() const { return Columns(); } 00106 00107 unsigned height() const { return Lines(); } 00108 00109 wsze size() const { return wsze( Lines(), Columns() ); } 00110 00111 const std::list<NCstring> & getText() const { return Text(); } 00112 00113 void drawAt( NCursesWindow & w, chtype style, chtype hotstyle, 00114 const wrect & dim, 00115 const NC::ADJUST adjust = NC::TOPLEFT, 00116 bool fillup = true ) const; 00117 00118 // 00119 void drawAt( NCursesWindow & w, chtype style, chtype hotstyle, 00120 const NC::ADJUST adjust = NC::TOPLEFT, 00121 bool fillup = true ) const 00122 { 00123 drawAt( w, style, hotstyle, wrect( 0, -1 ), adjust, fillup ); 00124 } 00125 00126 void drawAt( NCursesWindow & w, chtype style, chtype hotstyle, 00127 const wpos & pos, 00128 const NC::ADJUST adjust = NC::TOPLEFT, 00129 bool fillup = true ) const 00130 { 00131 drawAt( w, style, hotstyle, wrect( pos, -1 ), adjust, fillup ); 00132 } 00133 00134 void drawAt( NCursesWindow & w, chtype style, chtype hotstyle, 00135 const wpos & pos, const wsze & sze, 00136 const NC::ADJUST adjust = NC::TOPLEFT, 00137 bool fillup = true ) const 00138 { 00139 drawAt( w, style, hotstyle, wrect( pos, sze ), adjust, fillup ); 00140 } 00141 00142 // 00143 void drawAt( NCursesWindow & w, const NCstyle::StItem & istyle, 00144 const NC::ADJUST adjust = NC::TOPLEFT, 00145 bool fillup = true ) const 00146 { 00147 drawAt( w, istyle.label, istyle.hint, wrect( 0, -1 ), adjust, fillup ); 00148 } 00149 00150 void drawAt( NCursesWindow & w, const NCstyle::StItem & istyle, 00151 const wpos & pos, 00152 const NC::ADJUST adjust = NC::TOPLEFT, 00153 bool fillup = true ) const 00154 { 00155 drawAt( w, istyle.label, istyle.hint, wrect( pos, -1 ), adjust, fillup ); 00156 } 00157 00158 void drawAt( NCursesWindow & w, const NCstyle::StItem & istyle, 00159 const wpos & pos, const wsze & sze, 00160 const NC::ADJUST adjust = NC::TOPLEFT, 00161 bool fillup = true ) const 00162 { 00163 drawAt( w, istyle.label, istyle.hint, wrect( pos, sze ), adjust, fillup ); 00164 } 00165 00166 void drawAt( NCursesWindow & w, const NCstyle::StItem & istyle, 00167 const wrect & dim, 00168 const NC::ADJUST adjust = NC::TOPLEFT, 00169 bool fillup = true ) const 00170 { 00171 drawAt( w, istyle.label, istyle.hint, dim, adjust, fillup ); 00172 } 00173 00174 // 00175 00176 00177 bool hasHotkey() const { return hotline != std::wstring::npos; } 00178 00179 wchar_t hotkey() const { return hasHotkey() ? operator[]( hotline ).hotkey() : L'\0'; } 00180 00181 std::wstring::size_type hotpos() const { return hasHotkey() ? operator[]( hotline ).hotpos() : std::wstring::npos; } 00182 }; 00183 00184 00185 #endif // NCtext_h