The focus and active flag is set centrally in FWidget

This commit is contained in:
Markus Gans 2017-06-05 16:11:25 +02:00
parent b4b95f7b45
commit 526e193fb7
17 changed files with 25 additions and 173 deletions

View File

@ -1,3 +1,6 @@
2017-06-05 Markus Gans <guru.mail@muenster.de>
* The focus and active flag is set centrally in FWidget
2017-05-20 Markus Gans <guru.mail@muenster.de> 2017-05-20 Markus Gans <guru.mail@muenster.de>
* Recalculate the horizontal FListBox scroll bar size * Recalculate the horizontal FListBox scroll bar size
on lazy conversion on lazy conversion

View File

@ -136,15 +136,9 @@ bool FButton::setEnable (bool on)
FWidget::setEnable(on); FWidget::setEnable(on);
if ( on ) if ( on )
{
flags |= fc::active;
setHotkeyAccelerator(); setHotkeyAccelerator();
}
else else
{
flags &= ~fc::active;
delAccelerator(); delAccelerator();
}
updateButtonColor(); updateButtonColor();
return on; return on;
@ -157,8 +151,6 @@ bool FButton::setFocus (bool on)
if ( on ) if ( on )
{ {
flags |= fc::focus;
if ( isEnabled() ) if ( isEnabled() )
{ {
if ( getStatusBar() ) if ( getStatusBar() )
@ -173,8 +165,6 @@ bool FButton::setFocus (bool on)
} }
else else
{ {
flags &= ~fc::focus;
if ( isEnabled() && getStatusBar() ) if ( isEnabled() && getStatusBar() )
getStatusBar()->clearMessage(); getStatusBar()->clearMessage();
} }
@ -432,12 +422,6 @@ void FButton::init()
setForegroundColor (wc.button_active_fg); setForegroundColor (wc.button_active_fg);
setBackgroundColor (wc.button_active_bg); setBackgroundColor (wc.button_active_bg);
setShadow(); setShadow();
if ( hasFocus() )
flags = fc::focus;
if ( isEnabled() )
flags |= fc::active;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -90,15 +90,9 @@ bool FButtonGroup::setEnable (bool on)
FWidget::setEnable(on); FWidget::setEnable(on);
if ( on ) if ( on )
{
flags |= fc::active;
setHotkeyAccelerator(); setHotkeyAccelerator();
}
else else
{
flags &= ~fc::active;
delAccelerator(); delAccelerator();
}
return on; return on;
} }

View File

@ -72,19 +72,6 @@ FDialog::~FDialog() // destructor
// public methods of FDialog // public methods of FDialog
//----------------------------------------------------------------------
bool FDialog::setFocus (bool on)
{
FWidget::setFocus(on);
if ( on )
flags |= fc::focus;
else
flags &= ~fc::focus;
return on;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FDialog::setDialogWidget (bool on) bool FDialog::setDialogWidget (bool on)
{ {
@ -1065,13 +1052,6 @@ void FDialog::init()
setTransparentShadow(); setTransparentShadow();
setForegroundColor (wc.dialog_fg); setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg); setBackgroundColor (wc.dialog_bg);
if ( hasFocus() )
flags |= fc::focus;
if ( isEnabled() )
flags |= fc::active;
old_focus = FWidget::getFocusWidget(); old_focus = FWidget::getFocusWidget();
if ( old_focus ) if ( old_focus )

View File

@ -73,9 +73,6 @@ class FDialog : public FWindow
FString getText() const; FString getText() const;
// Mutators // Mutators
bool setFocus (bool);
bool setFocus();
bool unsetFocus();
bool setDialogWidget (bool); bool setDialogWidget (bool);
bool setDialogWidget(); bool setDialogWidget();
bool unsetDialogWidget(); bool unsetDialogWidget();
@ -179,14 +176,6 @@ inline const char* FDialog::getClassName() const
inline FString FDialog::getText() const inline FString FDialog::getText() const
{ return tb_text; } { return tb_text; }
//----------------------------------------------------------------------
inline bool FDialog::setFocus()
{ return setFocus(true); }
//----------------------------------------------------------------------
inline bool FDialog::unsetFocus()
{ return setFocus(false); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FDialog::setDialogWidget() inline bool FDialog::setDialogWidget()
{ return setDialogWidget(true); } { return setDialogWidget(true); }

View File

@ -100,15 +100,9 @@ bool FLabel::setEnable (bool on)
FWidget::setEnable(on); FWidget::setEnable(on);
if ( on ) if ( on )
{
flags |= fc::active;
setHotkeyAccelerator(); setHotkeyAccelerator();
}
else else
{
flags &= ~fc::active;
delAccelerator(); delAccelerator();
}
return on; return on;
} }
@ -261,10 +255,6 @@ void FLabel::cb_accel_widget_destroyed (FWidget*, data_ptr)
void FLabel::init() void FLabel::init()
{ {
FWidget* parent_widget = getParentWidget(); FWidget* parent_widget = getParentWidget();
if ( isEnabled() )
flags |= fc::active;
unsetFocusable(); unsetFocusable();
if ( parent_widget ) if ( parent_widget )

View File

@ -62,8 +62,6 @@ bool FLineEdit::setEnable (bool on)
if ( on ) if ( on )
{ {
flags |= fc::active;
if ( hasFocus() ) if ( hasFocus() )
{ {
setForegroundColor (wc.inputfield_active_focus_fg); setForegroundColor (wc.inputfield_active_focus_fg);
@ -77,7 +75,6 @@ bool FLineEdit::setEnable (bool on)
} }
else else
{ {
flags &= ~fc::active;
setForegroundColor (wc.inputfield_inactive_fg); setForegroundColor (wc.inputfield_inactive_fg);
setBackgroundColor (wc.inputfield_inactive_bg); setBackgroundColor (wc.inputfield_inactive_bg);
} }
@ -92,8 +89,6 @@ bool FLineEdit::setFocus (bool on)
if ( on ) if ( on )
{ {
flags |= fc::focus;
if ( isEnabled() ) if ( isEnabled() )
{ {
setForegroundColor (wc.inputfield_active_focus_fg); setForegroundColor (wc.inputfield_active_focus_fg);
@ -111,8 +106,6 @@ bool FLineEdit::setFocus (bool on)
} }
else else
{ {
flags &= ~fc::focus;
if ( isEnabled() ) if ( isEnabled() )
{ {
setForegroundColor (wc.inputfield_active_fg); setForegroundColor (wc.inputfield_active_fg);
@ -645,13 +638,8 @@ void FLineEdit::init()
setVisibleCursor(); setVisibleCursor();
setShadow(); setShadow();
if ( hasFocus() )
flags |= fc::focus;
if ( isEnabled() ) if ( isEnabled() )
{ {
flags |= fc::active;
if ( hasFocus() ) if ( hasFocus() )
{ {
setForegroundColor (wc.inputfield_active_focus_fg); setForegroundColor (wc.inputfield_active_focus_fg);

View File

@ -182,19 +182,6 @@ void FListBox::setGeometry (int x, int y, int w, int h, bool adjust)
} }
} }
//----------------------------------------------------------------------
bool FListBox::setEnable (bool on)
{
FWidget::setEnable(on);
if ( on )
flags |= fc::active;
else
flags &= ~fc::active;
return on;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FListBox::setFocus (bool on) bool FListBox::setFocus (bool on)
{ {
@ -202,8 +189,6 @@ bool FListBox::setFocus (bool on)
if ( on ) if ( on )
{ {
flags |= fc::focus;
if ( getStatusBar() ) if ( getStatusBar() )
{ {
const FString& msg = getStatusbarMessage(); const FString& msg = getStatusbarMessage();
@ -215,8 +200,6 @@ bool FListBox::setFocus (bool on)
} }
else else
{ {
flags &= ~fc::focus;
if ( getStatusBar() ) if ( getStatusBar() )
getStatusBar()->clearMessage(); getStatusBar()->clearMessage();
} }
@ -1444,12 +1427,6 @@ inline FString& FListBox::getString (listBoxItems::iterator iter)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::init() void FListBox::init()
{ {
if ( hasFocus() )
flags = fc::focus;
if ( isEnabled() )
flags |= fc::active;
setForegroundColor (wc.dialog_fg); setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg); setBackgroundColor (wc.dialog_bg);

View File

@ -143,9 +143,6 @@ class FListBox : public FWidget
void setMultiSelection (bool); void setMultiSelection (bool);
void setMultiSelection (); void setMultiSelection ();
void unsetMultiSelection (); void unsetMultiSelection ();
bool setEnable (bool);
bool setEnable();
bool unsetEnable();
bool setDisable(); bool setDisable();
bool setFocus (bool); bool setFocus (bool);
bool setFocus(); bool setFocus();
@ -403,14 +400,6 @@ inline void FListBox::setMultiSelection()
inline void FListBox::unsetMultiSelection() inline void FListBox::unsetMultiSelection()
{ setMultiSelection(false); } { setMultiSelection(false); }
//----------------------------------------------------------------------
inline bool FListBox::setEnable()
{ return setEnable(true); }
//----------------------------------------------------------------------
inline bool FListBox::unsetEnable()
{ return setEnable(false); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FListBox::setDisable() inline bool FListBox::setDisable()
{ return setEnable(false); } { return setEnable(false); }

View File

@ -94,8 +94,6 @@ bool FMenuItem::setEnable (bool on)
if ( on ) if ( on )
{ {
flags |= fc::active;
if ( super && isMenuBar(super) ) if ( super && isMenuBar(super) )
{ {
// Meta + hotkey // Meta + hotkey
@ -104,8 +102,6 @@ bool FMenuItem::setEnable (bool on)
} }
else else
{ {
flags &= ~fc::active;
if ( super && isMenuBar(super) ) if ( super && isMenuBar(super) )
super->delAccelerator (this); super->delAccelerator (this);
} }
@ -120,8 +116,6 @@ bool FMenuItem::setFocus (bool on)
if ( on ) if ( on )
{ {
flags |= fc::focus;
if ( isEnabled() ) if ( isEnabled() )
{ {
if ( ! selected ) if ( ! selected )
@ -168,8 +162,6 @@ bool FMenuItem::setFocus (bool on)
} }
else else
{ {
flags &= ~fc::focus;
if ( isEnabled() && getStatusBar() ) if ( isEnabled() && getStatusBar() )
getStatusBar()->clearMessage(); getStatusBar()->clearMessage();
} }
@ -690,12 +682,6 @@ void FMenuItem::init (FWidget* parent)
menu_ptr->calculateDimensions(); menu_ptr->calculateDimensions();
} }
} }
if ( hasFocus() )
flags = fc::focus;
if ( isEnabled() )
flags |= fc::active;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -53,19 +53,6 @@ void FProgressbar::setGeometry (int x, int y, int w, int h, bool adjust)
bar_length = w; bar_length = w;
} }
//----------------------------------------------------------------------
bool FProgressbar::setEnable (bool on)
{
FWidget::setEnable(on);
if ( on )
flags |= fc::active;
else
flags &= ~fc::active;
return on;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FProgressbar::setShadow (bool on) bool FProgressbar::setShadow (bool on)
{ {

View File

@ -57,10 +57,6 @@ class FProgressbar : public FWidget
// Mutators // Mutators
void setPercentage (int); void setPercentage (int);
void setGeometry (int, int, int, int, bool = true); void setGeometry (int, int, int, int, bool = true);
bool setEnable (bool);
bool setEnable();
bool unsetEnable();
bool setDisable();
bool setShadow (bool); bool setShadow (bool);
bool setShadow(); bool setShadow();
bool unsetShadow(); bool unsetShadow();
@ -94,18 +90,6 @@ inline const char* FProgressbar::getClassName() const
inline int FProgressbar::getPercentage() inline int FProgressbar::getPercentage()
{ return percentage; } { return percentage; }
//----------------------------------------------------------------------
inline bool FProgressbar::setEnable()
{ return setEnable(true); }
//----------------------------------------------------------------------
inline bool FProgressbar::unsetEnable()
{ return setEnable(false); }
//----------------------------------------------------------------------
inline bool FProgressbar::setDisable()
{ return setEnable(false); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FProgressbar::setShadow() inline bool FProgressbar::setShadow()
{ return setShadow(true); } { return setShadow(true); }

View File

@ -466,12 +466,9 @@ wchar_t& FString::operator [] (uInt pos)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
const FString FString::operator () (uInt pos, uInt len) const FString& FString::operator () ()
{ {
assert ( (pos < length) && ((pos+len) <= length) ); return (*this);
FString tmp(L"");
tmp._insert (0, len, string + pos);
return (tmp);
} }

View File

@ -108,7 +108,7 @@ class FString
wchar_t& operator [] (int); wchar_t& operator [] (int);
wchar_t& operator [] (uInt); wchar_t& operator [] (uInt);
const FString operator () (uInt, uInt); const FString& operator () ();
bool operator < (const FString&) const; bool operator < (const FString&) const;
bool operator < (const std::wstring&) const; bool operator < (const std::wstring&) const;

View File

@ -102,7 +102,6 @@ bool FToggleButton::setEnable (bool on)
if ( on ) if ( on )
{ {
flags |= fc::active;
setHotkeyAccelerator(); setHotkeyAccelerator();
if ( hasFocus() ) if ( hasFocus() )
@ -118,7 +117,6 @@ bool FToggleButton::setEnable (bool on)
} }
else else
{ {
flags &= ~fc::active;
delAccelerator(); delAccelerator();
setForegroundColor (wc.toggle_button_inactive_fg); setForegroundColor (wc.toggle_button_inactive_fg);
setBackgroundColor (wc.toggle_button_inactive_bg); setBackgroundColor (wc.toggle_button_inactive_bg);
@ -134,8 +132,6 @@ bool FToggleButton::setFocus (bool on)
if ( on ) if ( on )
{ {
flags |= fc::focus;
if ( isEnabled() ) if ( isEnabled() )
{ {
if ( isRadioButton() ) if ( isRadioButton() )
@ -156,8 +152,6 @@ bool FToggleButton::setFocus (bool on)
} }
else else
{ {
flags &= ~fc::focus;
if ( isEnabled() ) if ( isEnabled() )
{ {
setForegroundColor (wc.toggle_button_active_fg); setForegroundColor (wc.toggle_button_active_fg);
@ -633,13 +627,8 @@ void FToggleButton::init()
{ {
setGeometry (1, 1, 4, 1, false); // initialize geometry values setGeometry (1, 1, 4, 1, false); // initialize geometry values
if ( hasFocus() )
flags = fc::focus;
if ( isEnabled() ) if ( isEnabled() )
{ {
flags |= fc::active;
if ( hasFocus() ) if ( hasFocus() )
{ {
setForegroundColor (wc.toggle_button_active_focus_fg); setForegroundColor (wc.toggle_button_active_focus_fg);

View File

@ -61,6 +61,9 @@ FWidget::FWidget (FWidget* parent, bool disable_alt_screen)
, background_color(fc::Default) , background_color(fc::Default)
, statusbar_message() , statusbar_message()
{ {
if ( isEnabled() )
flags |= fc::active;
if ( ! parent ) if ( ! parent )
{ {
assert ( ! rootObject assert ( ! rootObject
@ -306,6 +309,17 @@ void FWidget::setStatusbarMessage (const FString& msg)
statusbar_message = msg; statusbar_message = msg;
} }
//----------------------------------------------------------------------
bool FWidget::setEnable (bool on)
{
if ( on )
flags |= fc::active;
else
flags &= ~fc::active;
return enable = (on) ? true : false;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FWidget::setFocus (bool on) bool FWidget::setFocus (bool on)
{ {
@ -315,6 +329,11 @@ bool FWidget::setFocus (bool on)
if ( ! enable ) if ( ! enable )
return false; return false;
if ( on )
flags |= fc::focus;
else
flags &= ~fc::focus;
if ( on == focus ) if ( on == focus )
return true; return true;

View File

@ -685,10 +685,6 @@ inline FPoint FWidget::getCursorPos()
inline bool FWidget::setVisible() inline bool FWidget::setVisible()
{ return visible = true; } { return visible = true; }
//----------------------------------------------------------------------
inline bool FWidget::setEnable (bool on)
{ return enable = (on) ? true : false; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FWidget::setEnable() inline bool FWidget::setEnable()
{ return setEnable(true); } { return setEnable(true); }