libyui-ncurses  2.44.1
 All Classes Functions Variables
NCFrame.cc
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: NCFrame.cc
20 
21  Author: Michael Andres <ma@suse.de>
22 
23 /-*/
24 
25 #define YUILogComponent "ncurses"
26 #include <yui/YUILog.h>
27 #include "NCurses.h"
28 #include "NCFrame.h"
29 
30 
31 NCFrame::NCFrame( YWidget * parent, const std::string & nlabel )
32  : YFrame( parent, nlabel )
33  , NCWidget( parent )
34 {
35  yuiDebug() << std::endl;
36  wstate = NC::WSdumb;
37  framedim.Pos = wpos( 1 );
38  framedim.Sze = wsze( 2 );
39  setLabel( YFrame::label() );
40  hotlabel = &label;
41 }
42 
43 
44 NCFrame::~NCFrame()
45 {
46  yuiDebug() << std::endl;
47 }
48 
49 
50 int NCFrame::preferredWidth()
51 {
52  defsze.W = hasChildren() ? firstChild()->preferredWidth() : 0;
53 
54  if ( label.width() > ( unsigned )defsze.W )
55  defsze.W = label.width();
56 
57  defsze.W += framedim.Sze.W;
58 
59  return defsze.W;
60 }
61 
62 
63 int NCFrame::preferredHeight()
64 {
65  defsze.H = hasChildren() ? firstChild()->preferredHeight() : 0;
66  defsze.H += framedim.Sze.H;
67 
68  return defsze.H;
69 }
70 
71 
72 void NCFrame::setSize( int newwidth, int newheight )
73 {
74  wsze csze( newheight, newwidth );
75  wRelocate( wpos( 0 ), csze );
76  csze = wsze::max( 0, csze - framedim.Sze );
77 
78  if ( hasChildren() )
79  firstChild()->setSize( csze.W, csze.H );
80 }
81 
82 
83 void NCFrame::setLabel( const std::string & nlabel )
84 {
85  YFrame::setLabel( nlabel );
86  label = NCstring( YFrame::label() );
87  label.stripHotkey();
88  Redraw();
89 }
90 
91 
92 void NCFrame::setEnabled( bool do_bv )
93 {
94  // Use setEnabled() from the parent, it should work out (#256707) :-)
95  NCWidget::setEnabled( do_bv );
96  YFrame::setEnabled( do_bv );
97 }
98 
99 
100 bool NCFrame::gotBuddy()
101 {
102  if ( !label.hasHotkey() )
103  return false;
104 
105  for ( tnode<NCWidget*> * c = this->Next();
106  c && c->IsDescendantOf( this );
107  c = c->Next() )
108  {
109  if ( c->Value()->GetState() != NC::WSdumb )
110  return true;
111  }
112 
113  return false;
114 }
115 
116 
117 void NCFrame::wRedraw()
118 {
119  if ( !win )
120  return;
121 
122  chtype bg = wStyle().dumb.text;
123  win->bkgd( bg );
124  win->box();
125 
126  if ( gotBuddy() )
127  label.drawAt( *win, widgetStyle(), wpos( 0, 1 ),
128  wsze( 1, win->width() - 2 ), NC::TOPLEFT, false );
129  else
130  label.drawAt( *win, bg, bg, wpos( 0, 1 ),
131  wsze( 1, win->width() - 2 ), NC::TOPLEFT, false );
132 }
133 
int bkgd(const chtype ch)
Definition: ncursesw.h:1443
virtual void setEnabled(bool do_bv)
Definition: NCFrame.cc:92
Definition: position.h:109
virtual void setEnabled(bool do_bv)=0
Definition: NCWidget.cc:391
Definition: position.h:154
int width() const
Definition: ncursesw.h:1075