libyui-ncurses  2.44.1
/usr/src/RPM/BUILD/libyui-ncurses-2.44.1/src/NCFrame.cc
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:       NCFrame.cc
00020 
00021    Author:     Michael Andres <ma@suse.de>
00022 
00023 /-*/
00024 
00025 #define  YUILogComponent "ncurses"
00026 #include <yui/YUILog.h>
00027 #include "NCurses.h"
00028 #include "NCFrame.h"
00029 
00030 
00031 NCFrame::NCFrame( YWidget * parent, const std::string & nlabel )
00032         : YFrame( parent, nlabel )
00033         , NCWidget( parent )
00034 {
00035     yuiDebug() << std::endl;
00036     wstate = NC::WSdumb;
00037     framedim.Pos = wpos( 1 );
00038     framedim.Sze = wsze( 2 );
00039     setLabel( YFrame::label() );
00040     hotlabel = &label;
00041 }
00042 
00043 
00044 NCFrame::~NCFrame()
00045 {
00046     yuiDebug() << std::endl;
00047 }
00048 
00049 
00050 int NCFrame::preferredWidth()
00051 {
00052     defsze.W = hasChildren() ? firstChild()->preferredWidth() : 0;
00053 
00054     if ( label.width() > ( unsigned )defsze.W )
00055         defsze.W = label.width();
00056 
00057     defsze.W += framedim.Sze.W;
00058 
00059     return defsze.W;
00060 }
00061 
00062 
00063 int NCFrame::preferredHeight()
00064 {
00065     defsze.H  = hasChildren() ? firstChild()->preferredHeight() : 0;
00066     defsze.H += framedim.Sze.H;
00067 
00068     return defsze.H;
00069 }
00070 
00071 
00072 void NCFrame::setSize( int newwidth, int newheight )
00073 {
00074     wsze csze( newheight, newwidth );
00075     wRelocate( wpos( 0 ), csze );
00076     csze = wsze::max( 0, csze - framedim.Sze );
00077 
00078     if ( hasChildren() )
00079         firstChild()->setSize( csze.W, csze.H );
00080 }
00081 
00082 
00083 void NCFrame::setLabel( const std::string & nlabel )
00084 {
00085     YFrame::setLabel( nlabel );
00086     label = NCstring( YFrame::label() );
00087     label.stripHotkey();
00088     Redraw();
00089 }
00090 
00091 
00092 void NCFrame::setEnabled( bool do_bv )
00093 {
00094     // Use setEnabled() from the parent, it should work out (#256707) :-)
00095     NCWidget::setEnabled( do_bv );
00096     YFrame::setEnabled( do_bv );
00097 }
00098 
00099 
00100 bool NCFrame::gotBuddy()
00101 {
00102     if ( !label.hasHotkey() )
00103         return false;
00104 
00105     for ( tnode<NCWidget*> * c = this->Next();
00106           c && c->IsDescendantOf( this );
00107           c = c->Next() )
00108     {
00109         if ( c->Value()->GetState() != NC::WSdumb )
00110             return true;
00111     }
00112 
00113     return false;
00114 }
00115 
00116 
00117 void NCFrame::wRedraw()
00118 {
00119     if ( !win )
00120         return;
00121 
00122     chtype bg = wStyle().dumb.text;
00123     win->bkgd( bg );
00124     win->box();
00125 
00126     if ( gotBuddy() )
00127         label.drawAt( *win, widgetStyle(), wpos( 0, 1 ),
00128                       wsze( 1, win->width() - 2 ), NC::TOPLEFT, false );
00129     else
00130         label.drawAt( *win, bg, bg, wpos( 0, 1 ),
00131                       wsze( 1, win->width() - 2 ), NC::TOPLEFT, false );
00132 }
00133 
 All Classes Functions Variables