From 526e193fb76a2d9a5e32a104b78ea6f8fefe4a3a Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Mon, 5 Jun 2017 16:11:25 +0200 Subject: [PATCH] The focus and active flag is set centrally in FWidget --- ChangeLog | 3 +++ src/fbutton.cpp | 16 ---------------- src/fbuttongroup.cpp | 6 ------ src/fdialog.cpp | 20 -------------------- src/fdialog.h | 11 ----------- src/flabel.cpp | 10 ---------- src/flineedit.cpp | 12 ------------ src/flistbox.cpp | 23 ----------------------- src/flistbox.h | 11 ----------- src/fmenuitem.cpp | 14 -------------- src/fprogressbar.cpp | 13 ------------- src/fprogressbar.h | 16 ---------------- src/fstring.cpp | 7 ++----- src/fstring.h | 2 +- src/ftogglebutton.cpp | 11 ----------- src/fwidget.cpp | 19 +++++++++++++++++++ src/fwidget.h | 4 ---- 17 files changed, 25 insertions(+), 173 deletions(-) diff --git a/ChangeLog b/ChangeLog index f5123f5c..3e96cba6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2017-06-05 Markus Gans + * The focus and active flag is set centrally in FWidget + 2017-05-20 Markus Gans * Recalculate the horizontal FListBox scroll bar size on lazy conversion diff --git a/src/fbutton.cpp b/src/fbutton.cpp index b6dee224..5aea9e98 100644 --- a/src/fbutton.cpp +++ b/src/fbutton.cpp @@ -136,15 +136,9 @@ bool FButton::setEnable (bool on) FWidget::setEnable(on); if ( on ) - { - flags |= fc::active; setHotkeyAccelerator(); - } else - { - flags &= ~fc::active; delAccelerator(); - } updateButtonColor(); return on; @@ -157,8 +151,6 @@ bool FButton::setFocus (bool on) if ( on ) { - flags |= fc::focus; - if ( isEnabled() ) { if ( getStatusBar() ) @@ -173,8 +165,6 @@ bool FButton::setFocus (bool on) } else { - flags &= ~fc::focus; - if ( isEnabled() && getStatusBar() ) getStatusBar()->clearMessage(); } @@ -432,12 +422,6 @@ void FButton::init() setForegroundColor (wc.button_active_fg); setBackgroundColor (wc.button_active_bg); setShadow(); - - if ( hasFocus() ) - flags = fc::focus; - - if ( isEnabled() ) - flags |= fc::active; } //---------------------------------------------------------------------- diff --git a/src/fbuttongroup.cpp b/src/fbuttongroup.cpp index 6f3b818c..efdf81d8 100644 --- a/src/fbuttongroup.cpp +++ b/src/fbuttongroup.cpp @@ -90,15 +90,9 @@ bool FButtonGroup::setEnable (bool on) FWidget::setEnable(on); if ( on ) - { - flags |= fc::active; setHotkeyAccelerator(); - } else - { - flags &= ~fc::active; delAccelerator(); - } return on; } diff --git a/src/fdialog.cpp b/src/fdialog.cpp index ba58984f..af971187 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -72,19 +72,6 @@ FDialog::~FDialog() // destructor // 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) { @@ -1065,13 +1052,6 @@ void FDialog::init() setTransparentShadow(); setForegroundColor (wc.dialog_fg); setBackgroundColor (wc.dialog_bg); - - if ( hasFocus() ) - flags |= fc::focus; - - if ( isEnabled() ) - flags |= fc::active; - old_focus = FWidget::getFocusWidget(); if ( old_focus ) diff --git a/src/fdialog.h b/src/fdialog.h index afb4cf39..7f62398e 100644 --- a/src/fdialog.h +++ b/src/fdialog.h @@ -73,9 +73,6 @@ class FDialog : public FWindow FString getText() const; // Mutators - bool setFocus (bool); - bool setFocus(); - bool unsetFocus(); bool setDialogWidget (bool); bool setDialogWidget(); bool unsetDialogWidget(); @@ -179,14 +176,6 @@ inline const char* FDialog::getClassName() const inline FString FDialog::getText() const { return tb_text; } -//---------------------------------------------------------------------- -inline bool FDialog::setFocus() -{ return setFocus(true); } - -//---------------------------------------------------------------------- -inline bool FDialog::unsetFocus() -{ return setFocus(false); } - //---------------------------------------------------------------------- inline bool FDialog::setDialogWidget() { return setDialogWidget(true); } diff --git a/src/flabel.cpp b/src/flabel.cpp index 26bda948..5f74f166 100644 --- a/src/flabel.cpp +++ b/src/flabel.cpp @@ -100,15 +100,9 @@ bool FLabel::setEnable (bool on) FWidget::setEnable(on); if ( on ) - { - flags |= fc::active; setHotkeyAccelerator(); - } else - { - flags &= ~fc::active; delAccelerator(); - } return on; } @@ -261,10 +255,6 @@ void FLabel::cb_accel_widget_destroyed (FWidget*, data_ptr) void FLabel::init() { FWidget* parent_widget = getParentWidget(); - - if ( isEnabled() ) - flags |= fc::active; - unsetFocusable(); if ( parent_widget ) diff --git a/src/flineedit.cpp b/src/flineedit.cpp index 1a6bc9fe..4e732431 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -62,8 +62,6 @@ bool FLineEdit::setEnable (bool on) if ( on ) { - flags |= fc::active; - if ( hasFocus() ) { setForegroundColor (wc.inputfield_active_focus_fg); @@ -77,7 +75,6 @@ bool FLineEdit::setEnable (bool on) } else { - flags &= ~fc::active; setForegroundColor (wc.inputfield_inactive_fg); setBackgroundColor (wc.inputfield_inactive_bg); } @@ -92,8 +89,6 @@ bool FLineEdit::setFocus (bool on) if ( on ) { - flags |= fc::focus; - if ( isEnabled() ) { setForegroundColor (wc.inputfield_active_focus_fg); @@ -111,8 +106,6 @@ bool FLineEdit::setFocus (bool on) } else { - flags &= ~fc::focus; - if ( isEnabled() ) { setForegroundColor (wc.inputfield_active_fg); @@ -645,13 +638,8 @@ void FLineEdit::init() setVisibleCursor(); setShadow(); - if ( hasFocus() ) - flags |= fc::focus; - if ( isEnabled() ) { - flags |= fc::active; - if ( hasFocus() ) { setForegroundColor (wc.inputfield_active_focus_fg); diff --git a/src/flistbox.cpp b/src/flistbox.cpp index 205f2c65..5c8b9218 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -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) { @@ -202,8 +189,6 @@ bool FListBox::setFocus (bool on) if ( on ) { - flags |= fc::focus; - if ( getStatusBar() ) { const FString& msg = getStatusbarMessage(); @@ -215,8 +200,6 @@ bool FListBox::setFocus (bool on) } else { - flags &= ~fc::focus; - if ( getStatusBar() ) getStatusBar()->clearMessage(); } @@ -1444,12 +1427,6 @@ inline FString& FListBox::getString (listBoxItems::iterator iter) //---------------------------------------------------------------------- void FListBox::init() { - if ( hasFocus() ) - flags = fc::focus; - - if ( isEnabled() ) - flags |= fc::active; - setForegroundColor (wc.dialog_fg); setBackgroundColor (wc.dialog_bg); diff --git a/src/flistbox.h b/src/flistbox.h index be92859b..f55e4438 100644 --- a/src/flistbox.h +++ b/src/flistbox.h @@ -143,9 +143,6 @@ class FListBox : public FWidget void setMultiSelection (bool); void setMultiSelection (); void unsetMultiSelection (); - bool setEnable (bool); - bool setEnable(); - bool unsetEnable(); bool setDisable(); bool setFocus (bool); bool setFocus(); @@ -403,14 +400,6 @@ inline void FListBox::setMultiSelection() inline void FListBox::unsetMultiSelection() { setMultiSelection(false); } -//---------------------------------------------------------------------- -inline bool FListBox::setEnable() -{ return setEnable(true); } - -//---------------------------------------------------------------------- -inline bool FListBox::unsetEnable() -{ return setEnable(false); } - //---------------------------------------------------------------------- inline bool FListBox::setDisable() { return setEnable(false); } diff --git a/src/fmenuitem.cpp b/src/fmenuitem.cpp index b297f6e6..bc68f793 100644 --- a/src/fmenuitem.cpp +++ b/src/fmenuitem.cpp @@ -94,8 +94,6 @@ bool FMenuItem::setEnable (bool on) if ( on ) { - flags |= fc::active; - if ( super && isMenuBar(super) ) { // Meta + hotkey @@ -104,8 +102,6 @@ bool FMenuItem::setEnable (bool on) } else { - flags &= ~fc::active; - if ( super && isMenuBar(super) ) super->delAccelerator (this); } @@ -120,8 +116,6 @@ bool FMenuItem::setFocus (bool on) if ( on ) { - flags |= fc::focus; - if ( isEnabled() ) { if ( ! selected ) @@ -168,8 +162,6 @@ bool FMenuItem::setFocus (bool on) } else { - flags &= ~fc::focus; - if ( isEnabled() && getStatusBar() ) getStatusBar()->clearMessage(); } @@ -690,12 +682,6 @@ void FMenuItem::init (FWidget* parent) menu_ptr->calculateDimensions(); } } - - if ( hasFocus() ) - flags = fc::focus; - - if ( isEnabled() ) - flags |= fc::active; } //---------------------------------------------------------------------- diff --git a/src/fprogressbar.cpp b/src/fprogressbar.cpp index dbb35bfd..7d4bf394 100644 --- a/src/fprogressbar.cpp +++ b/src/fprogressbar.cpp @@ -53,19 +53,6 @@ void FProgressbar::setGeometry (int x, int y, int w, int h, bool adjust) 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) { diff --git a/src/fprogressbar.h b/src/fprogressbar.h index bdee46dc..27a04821 100644 --- a/src/fprogressbar.h +++ b/src/fprogressbar.h @@ -57,10 +57,6 @@ class FProgressbar : public FWidget // Mutators void setPercentage (int); void setGeometry (int, int, int, int, bool = true); - bool setEnable (bool); - bool setEnable(); - bool unsetEnable(); - bool setDisable(); bool setShadow (bool); bool setShadow(); bool unsetShadow(); @@ -94,18 +90,6 @@ inline const char* FProgressbar::getClassName() const inline int FProgressbar::getPercentage() { 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() { return setShadow(true); } diff --git a/src/fstring.cpp b/src/fstring.cpp index dbe3506a..844cfcfe 100644 --- a/src/fstring.cpp +++ b/src/fstring.cpp @@ -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) ); - FString tmp(L""); - tmp._insert (0, len, string + pos); - return (tmp); + return (*this); } diff --git a/src/fstring.h b/src/fstring.h index b4bf42ca..338940fc 100644 --- a/src/fstring.h +++ b/src/fstring.h @@ -108,7 +108,7 @@ class FString wchar_t& operator [] (int); wchar_t& operator [] (uInt); - const FString operator () (uInt, uInt); + const FString& operator () (); bool operator < (const FString&) const; bool operator < (const std::wstring&) const; diff --git a/src/ftogglebutton.cpp b/src/ftogglebutton.cpp index f18c27b8..c4d75432 100644 --- a/src/ftogglebutton.cpp +++ b/src/ftogglebutton.cpp @@ -102,7 +102,6 @@ bool FToggleButton::setEnable (bool on) if ( on ) { - flags |= fc::active; setHotkeyAccelerator(); if ( hasFocus() ) @@ -118,7 +117,6 @@ bool FToggleButton::setEnable (bool on) } else { - flags &= ~fc::active; delAccelerator(); setForegroundColor (wc.toggle_button_inactive_fg); setBackgroundColor (wc.toggle_button_inactive_bg); @@ -134,8 +132,6 @@ bool FToggleButton::setFocus (bool on) if ( on ) { - flags |= fc::focus; - if ( isEnabled() ) { if ( isRadioButton() ) @@ -156,8 +152,6 @@ bool FToggleButton::setFocus (bool on) } else { - flags &= ~fc::focus; - if ( isEnabled() ) { setForegroundColor (wc.toggle_button_active_fg); @@ -633,13 +627,8 @@ void FToggleButton::init() { setGeometry (1, 1, 4, 1, false); // initialize geometry values - if ( hasFocus() ) - flags = fc::focus; - if ( isEnabled() ) { - flags |= fc::active; - if ( hasFocus() ) { setForegroundColor (wc.toggle_button_active_focus_fg); diff --git a/src/fwidget.cpp b/src/fwidget.cpp index b1dc9c74..73ef6e0d 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -61,6 +61,9 @@ FWidget::FWidget (FWidget* parent, bool disable_alt_screen) , background_color(fc::Default) , statusbar_message() { + if ( isEnabled() ) + flags |= fc::active; + if ( ! parent ) { assert ( ! rootObject @@ -306,6 +309,17 @@ void FWidget::setStatusbarMessage (const FString& 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) { @@ -315,6 +329,11 @@ bool FWidget::setFocus (bool on) if ( ! enable ) return false; + if ( on ) + flags |= fc::focus; + else + flags &= ~fc::focus; + if ( on == focus ) return true; diff --git a/src/fwidget.h b/src/fwidget.h index cf986671..f3f33d0a 100644 --- a/src/fwidget.h +++ b/src/fwidget.h @@ -685,10 +685,6 @@ inline FPoint FWidget::getCursorPos() inline bool FWidget::setVisible() { return visible = true; } -//---------------------------------------------------------------------- -inline bool FWidget::setEnable (bool on) -{ return enable = (on) ? true : false; } - //---------------------------------------------------------------------- inline bool FWidget::setEnable() { return setEnable(true); }