From 1613d5bb557c1bfcc44f92d8dc1684c4d9f2eef2 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Mon, 17 Oct 2016 08:44:38 +0200 Subject: [PATCH] Refactor the VGA attribute controller access code --- ChangeLog | 3 + src/fbutton.cpp | 46 ++--- src/fbuttongroup.cpp | 90 ++++----- src/fcheckmenuitem.cpp | 16 +- src/ffiledialog.cpp | 23 +-- src/flineedit.cpp | 40 ++-- src/flistbox.cpp | 30 +-- src/fmenuitem.cpp | 403 +++++++++++++++++++++-------------------- src/fmenulist.cpp | 18 +- src/fmessagebox.cpp | 2 + src/fobject.cpp | 24 +-- src/fobject.h | 3 +- src/foptimove.cpp | 60 +++--- src/fradiomenuitem.cpp | 24 +-- src/fstatusbar.cpp | 22 +-- src/fstring.cpp | 32 ++-- src/fterm.cpp | 193 ++++++++++++-------- src/fterm.h | 18 +- src/ftogglebutton.cpp | 175 +++++++++--------- src/ftooltip.cpp | 20 +- src/fwindow.cpp | 84 ++++----- test/calculator.cpp | 34 ++-- test/transparent.cpp | 34 ++-- test/ui.cpp | 30 +-- test/windows.cpp | 16 +- 25 files changed, 738 insertions(+), 702 deletions(-) diff --git a/ChangeLog b/ChangeLog index ab45fc7d..e61d6a84 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2016-10-17 Markus Gans + * Refactor the VGA attribute controller access code + 2016-10-15 Markus Gans * Each virtual window gets its own virtual print cursor diff --git a/src/fbutton.cpp b/src/fbutton.cpp index 32535a59..e4b28b50 100644 --- a/src/fbutton.cpp +++ b/src/fbutton.cpp @@ -731,35 +731,35 @@ void FButton::onTimer (FTimerEvent* ev) //---------------------------------------------------------------------- void FButton::onAccel (FAccelEvent* ev) { - if ( isEnabled() ) + if ( ! isEnabled() ) + return; + + if ( ! hasFocus() ) { - if ( ! hasFocus() ) - { - FWidget* focused_widget = static_cast(ev->focusedWidget()); - FFocusEvent out (fc::FocusOut_Event); - FApplication::queueEvent(focused_widget, &out); - setFocus(); + FWidget* focused_widget = static_cast(ev->focusedWidget()); + FFocusEvent out (fc::FocusOut_Event); + FApplication::queueEvent(focused_widget, &out); + setFocus(); - if ( focused_widget ) - focused_widget->redraw(); - - if ( click_animation ) - setDown(); - else - redraw(); - - if ( statusBar() ) - statusBar()->drawMessage(); - } - else if ( click_animation ) - setDown(); + if ( focused_widget ) + focused_widget->redraw(); if ( click_animation ) - addTimer(click_time); + setDown(); + else + redraw(); - processClick(); - ev->accept(); + if ( statusBar() ) + statusBar()->drawMessage(); } + else if ( click_animation ) + setDown(); + + if ( click_animation ) + addTimer(click_time); + + processClick(); + ev->accept(); } //---------------------------------------------------------------------- diff --git a/src/fbuttongroup.cpp b/src/fbuttongroup.cpp index 4c9bbdfc..5b871193 100644 --- a/src/fbuttongroup.cpp +++ b/src/fbuttongroup.cpp @@ -418,19 +418,19 @@ void FButtonGroup::cb_buttonToggled (FWidget* widget, void*) //---------------------------------------------------------------------- FToggleButton* FButtonGroup::getFirstButton() { - if ( ! buttonlist.empty() ) + if ( buttonlist.empty() ) + return 0; + + FButtonGroup::FButtonList::const_iterator iter, end; + iter = buttonlist.begin(); + end = buttonlist.end(); + + while ( iter != end ) { - FButtonGroup::FButtonList::const_iterator iter, end; - iter = buttonlist.begin(); - end = buttonlist.end(); + if ( (*iter)->isEnabled() && (*iter)->acceptFocus() ) + return (*iter); - while ( iter != end ) - { - if ( (*iter)->isEnabled() && (*iter)->acceptFocus() ) - return (*iter); - - ++iter; - } + ++iter; } return 0; @@ -439,21 +439,21 @@ FToggleButton* FButtonGroup::getFirstButton() //---------------------------------------------------------------------- FToggleButton* FButtonGroup::getLastButton() { - if ( ! buttonlist.empty() ) + if ( buttonlist.empty() ) + return 0; + + FButtonGroup::FButtonList::const_iterator iter, begin; + begin = buttonlist.begin(); + iter = buttonlist.end(); + + do { - FButtonGroup::FButtonList::const_iterator iter, begin; - begin = buttonlist.begin(); - iter = buttonlist.end(); + --iter; - do - { - --iter; - - if ( (*iter)->isEnabled() && (*iter)->acceptFocus() ) - return (*iter); - } - while ( iter != begin ); + if ( (*iter)->isEnabled() && (*iter)->acceptFocus() ) + return (*iter); } + while ( iter != begin ); return 0; } @@ -461,19 +461,19 @@ FToggleButton* FButtonGroup::getLastButton() //---------------------------------------------------------------------- bool FButtonGroup::hasFocusedButton() { - if ( ! buttonlist.empty() ) + if ( buttonlist.empty() ) + return false; + + FButtonGroup::FButtonList::const_iterator iter, end; + iter = buttonlist.begin(); + end = buttonlist.end(); + + while ( iter != end ) { - FButtonGroup::FButtonList::const_iterator iter, end; - iter = buttonlist.begin(); - end = buttonlist.end(); + if ( (*iter)->hasFocus() ) + return true; - while ( iter != end ) - { - if ( (*iter)->hasFocus() ) - return true; - - ++iter; - } + ++iter; } return false; @@ -482,19 +482,19 @@ bool FButtonGroup::hasFocusedButton() //---------------------------------------------------------------------- bool FButtonGroup::hasCheckedButton() { - if ( ! buttonlist.empty() ) + if ( buttonlist.empty() ) + return false; + + FButtonGroup::FButtonList::const_iterator iter, end; + iter = buttonlist.begin(); + end = buttonlist.end(); + + while ( iter != end ) { - FButtonGroup::FButtonList::const_iterator iter, end; - iter = buttonlist.begin(); - end = buttonlist.end(); + if ( (*iter)->isChecked() ) + return true; - while ( iter != end ) - { - if ( (*iter)->isChecked() ) - return true; - - ++iter; - } + ++iter; } return false; diff --git a/src/fcheckmenuitem.cpp b/src/fcheckmenuitem.cpp index 39a217bc..9e4dbb60 100644 --- a/src/fcheckmenuitem.cpp +++ b/src/fcheckmenuitem.cpp @@ -48,15 +48,15 @@ void FCheckMenuItem::init (FWidget* parent) { checkable = true; - if ( parent ) - { - if ( isMenu(parent) ) // Parent is menu - { - FMenu* menu_ptr = dynamic_cast(parent); + if ( ! parent ) + return; - if ( menu_ptr ) - menu_ptr->has_checkable_items = true; - } + if ( isMenu(parent) ) // Parent is menu + { + FMenu* menu_ptr = dynamic_cast(parent); + + if ( menu_ptr ) + menu_ptr->has_checkable_items = true; } } diff --git a/src/ffiledialog.cpp b/src/ffiledialog.cpp index 32e19b42..db0b93f5 100644 --- a/src/ffiledialog.cpp +++ b/src/ffiledialog.cpp @@ -253,21 +253,20 @@ void FFileDialog::clear() //---------------------------------------------------------------------- int FFileDialog::numOfDirs() { + if ( dir_entries.empty() ) + return 0; + int n = 0; + std::vector::const_iterator iter, end; + iter = dir_entries.begin(); + end = dir_entries.end(); - if ( ! dir_entries.empty() ) + while ( iter != end ) { - std::vector::const_iterator iter, end; - iter = dir_entries.begin(); - end = dir_entries.end(); + if ( (*iter).type == DT_DIR && std::strcmp((*iter).name, ".") != 0 ) + n++; - while ( iter != end ) - { - if ( (*iter).type == DT_DIR && std::strcmp((*iter).name, ".") != 0 ) - n++; - - ++iter; - } + ++iter; } return n; @@ -499,7 +498,9 @@ void FFileDialog::adjustSize() FFileDialog& FFileDialog::operator = (const FFileDialog& fdlg) { if ( &fdlg == this ) + { return *this; + } else { delete open; diff --git a/src/flineedit.cpp b/src/flineedit.cpp index f661d8fb..af7696ad 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -736,30 +736,30 @@ void FLineEdit::onTimer (FTimerEvent*) //---------------------------------------------------------------------- void FLineEdit::onAccel (FAccelEvent* ev) { - if ( isEnabled() ) + if ( ! isEnabled() ) + return; + + if ( ! hasFocus() ) { - if ( ! hasFocus() ) + FWidget* focused_widget = static_cast(ev->focusedWidget()); + FFocusEvent out (fc::FocusOut_Event); + FApplication::queueEvent(focused_widget, &out); + setFocus(); + + if ( focused_widget ) + focused_widget->redraw(); + + redraw(); + + if ( statusBar() ) { - FWidget* focused_widget = static_cast(ev->focusedWidget()); - FFocusEvent out (fc::FocusOut_Event); - FApplication::queueEvent(focused_widget, &out); - setFocus(); - - if ( focused_widget ) - focused_widget->redraw(); - - redraw(); - - if ( statusBar() ) - { - statusBar()->drawMessage(); - updateTerminal(); - flush_out(); - } + statusBar()->drawMessage(); + updateTerminal(); + flush_out(); } - - ev->accept(); } + + ev->accept(); } //---------------------------------------------------------------------- diff --git a/src/flistbox.cpp b/src/flistbox.cpp index 5dba0eb9..75bccfff 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -594,7 +594,7 @@ void FListBox::hide() return; blank = new char[size+1]; - memset(blank, ' ', uLong(size)); + std::memset (blank, ' ', uLong(size)); blank[size] = '\0'; for (int y=0; y < getHeight(); y++) @@ -612,23 +612,23 @@ void FListBox::showInsideBrackets ( int index { data[uInt(index-1)].brackets = b; - if ( b != fc::NoBrackets ) + if ( b == fc::NoBrackets ) + return; + + int len = int(data[uInt(index-1)].getText().getLength() + 2); + + if ( len > max_line_width ) { - int len = int(data[uInt(index-1)].getText().getLength() + 2); + max_line_width = len; - if ( len > max_line_width ) + if ( len >= getWidth() - nf_offset - 3 ) { - max_line_width = len; + hbar->setMaximum(max_line_width - getWidth() + nf_offset + 4); + hbar->setPageSize(max_line_width, getWidth() - nf_offset - 4); + hbar->setValue (xoffset); - if ( len >= getWidth() - nf_offset - 3 ) - { - hbar->setMaximum(max_line_width - getWidth() + nf_offset + 4); - hbar->setPageSize(max_line_width, getWidth() - nf_offset - 4); - hbar->setValue (xoffset); - - if ( ! hbar->isVisible() ) - hbar->setVisible(); - } + if ( ! hbar->isVisible() ) + hbar->setVisible(); } } } @@ -1787,7 +1787,7 @@ void FListBox::clear() return; blank = new char[size+1]; - memset(blank, ' ', uLong(size)); + std::memset (blank, ' ', uLong(size)); blank[size] = '\0'; for (int y=0; y < getHeight()-2; y++) diff --git a/src/fmenuitem.cpp b/src/fmenuitem.cpp index c1efd91f..addb8564 100644 --- a/src/fmenuitem.cpp +++ b/src/fmenuitem.cpp @@ -433,27 +433,27 @@ void FMenuItem::delAccelerator (FWidget* obj) //---------------------------------------------------------------------- void FMenuItem::onKeyPress (FKeyEvent* ev) { - if ( super_menu ) + if ( ! super_menu ) + return; + + if ( isMenu(super_menu) ) { - if ( isMenu(super_menu) ) + FMenu* smenu = dynamic_cast(super_menu); + + if ( smenu ) + smenu->onKeyPress(ev); + } + + if ( isMenuBar(super_menu) ) + { + FMenuBar* mbar = dynamic_cast(super_menu); + + if ( mbar ) { - FMenu* smenu = dynamic_cast(super_menu); + if ( mbar->hotkeyMenu(ev) ) + return; - if ( smenu ) - smenu->onKeyPress(ev); - } - - if ( isMenuBar(super_menu) ) - { - FMenuBar* mbar = dynamic_cast(super_menu); - - if ( mbar ) - { - if ( mbar->hotkeyMenu(ev) ) - return; - - mbar->onKeyPress(ev); - } + mbar->onKeyPress(ev); } } } @@ -461,48 +461,48 @@ void FMenuItem::onKeyPress (FKeyEvent* ev) //---------------------------------------------------------------------- void FMenuItem::onMouseDoubleClick (FMouseEvent* ev) { - if ( super_menu ) + if ( ! super_menu ) + return; + + const FPoint& t = ev->getTermPos(); + int b = ev->getButton(); + + if ( isMenu(super_menu) ) { - const FPoint& t = ev->getTermPos(); - int b = ev->getButton(); + FMenu* smenu = dynamic_cast(super_menu); - if ( isMenu(super_menu) ) + if ( smenu ) { - FMenu* smenu = dynamic_cast(super_menu); - - if ( smenu ) - { - const FPoint& p2 = smenu->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, t, b); - smenu->onMouseDoubleClick(_ev); - delete _ev; - } + const FPoint& p2 = smenu->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, t, b); + smenu->onMouseDoubleClick(_ev); + delete _ev; } + } - if ( isMenuBar(super_menu) ) + if ( isMenuBar(super_menu) ) + { + FMenuBar* mbar = dynamic_cast(super_menu); + + if ( mbar ) { - FMenuBar* mbar = dynamic_cast(super_menu); - - if ( mbar ) - { - const FPoint& p2 = mbar->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, t, b); - mbar->onMouseDoubleClick(_ev); - delete _ev; - } + const FPoint& p2 = mbar->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, t, b); + mbar->onMouseDoubleClick(_ev); + delete _ev; } + } - if ( isWindowsMenu(super_menu) ) + if ( isWindowsMenu(super_menu) ) + { + FDialog* dgl = dynamic_cast(super_menu); + + if ( dgl ) { - FDialog* dgl = dynamic_cast(super_menu); - - if ( dgl ) - { - const FPoint& p2 = dgl->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, t, b); - dgl->onMouseDoubleClick(_ev); - delete _ev; - } + const FPoint& p2 = dgl->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, t, b); + dgl->onMouseDoubleClick(_ev); + delete _ev; } } } @@ -510,48 +510,48 @@ void FMenuItem::onMouseDoubleClick (FMouseEvent* ev) //---------------------------------------------------------------------- void FMenuItem::onMouseDown (FMouseEvent* ev) { - if ( super_menu ) + if ( ! super_menu ) + return; + + const FPoint& t = ev->getTermPos(); + int b = ev->getButton(); + + if ( isMenu(super_menu) ) { - const FPoint& t = ev->getTermPos(); - int b = ev->getButton(); + FMenu* smenu = dynamic_cast(super_menu); - if ( isMenu(super_menu) ) + if ( smenu ) { - FMenu* smenu = dynamic_cast(super_menu); - - if ( smenu ) - { - const FPoint& p2 = smenu->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, t, b); - smenu->onMouseDown(_ev); - delete _ev; - } + const FPoint& p2 = smenu->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, t, b); + smenu->onMouseDown(_ev); + delete _ev; } + } - if ( isMenuBar(super_menu) ) + if ( isMenuBar(super_menu) ) + { + FMenuBar* mbar = dynamic_cast(super_menu); + + if ( mbar ) { - FMenuBar* mbar = dynamic_cast(super_menu); - - if ( mbar ) - { - const FPoint& p2 = mbar->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, t, b); - mbar->onMouseDown(_ev); - delete _ev; - } + const FPoint& p2 = mbar->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, t, b); + mbar->onMouseDown(_ev); + delete _ev; } + } - if ( isWindowsMenu(super_menu) ) + if ( isWindowsMenu(super_menu) ) + { + FDialog* dgl = dynamic_cast(super_menu); + + if ( dgl ) { - FDialog* dgl = dynamic_cast(super_menu); - - if ( dgl ) - { - const FPoint& p2 = dgl->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, t, b); - dgl->onMouseDown(_ev); - delete _ev; - } + const FPoint& p2 = dgl->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, t, b); + dgl->onMouseDown(_ev); + delete _ev; } } } @@ -559,48 +559,48 @@ void FMenuItem::onMouseDown (FMouseEvent* ev) //---------------------------------------------------------------------- void FMenuItem::onMouseUp (FMouseEvent* ev) { - if ( super_menu ) + if ( ! super_menu ) + return; + + const FPoint& t = ev->getTermPos(); + int b = ev->getButton(); + + if ( isMenu(super_menu) ) { - const FPoint& t = ev->getTermPos(); - int b = ev->getButton(); + FMenu* smenu = dynamic_cast(super_menu); - if ( isMenu(super_menu) ) + if ( smenu ) { - FMenu* smenu = dynamic_cast(super_menu); - - if ( smenu ) - { - const FPoint& p2 = smenu->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b); - smenu->onMouseUp(_ev); - delete _ev; - } + const FPoint& p2 = smenu->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b); + smenu->onMouseUp(_ev); + delete _ev; } + } - if ( isMenuBar(super_menu) ) + if ( isMenuBar(super_menu) ) + { + FMenuBar* mbar = dynamic_cast(super_menu); + + if ( mbar ) { - FMenuBar* mbar = dynamic_cast(super_menu); - - if ( mbar ) - { - const FPoint& p2 = mbar->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b); - mbar->onMouseUp(_ev); - delete _ev; - } + const FPoint& p2 = mbar->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b); + mbar->onMouseUp(_ev); + delete _ev; } + } - if ( isWindowsMenu(super_menu) ) + if ( isWindowsMenu(super_menu) ) + { + FDialog* dgl = dynamic_cast(super_menu); + + if ( dgl ) { - FDialog* dgl = dynamic_cast(super_menu); - - if ( dgl ) - { - const FPoint& p2 = dgl->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b); - dgl->onMouseUp(_ev); - delete _ev; - } + const FPoint& p2 = dgl->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b); + dgl->onMouseUp(_ev); + delete _ev; } } } @@ -608,48 +608,48 @@ void FMenuItem::onMouseUp (FMouseEvent* ev) //---------------------------------------------------------------------- void FMenuItem::onMouseMove (FMouseEvent* ev) { - if ( super_menu ) + if ( ! super_menu ) + return; + + const FPoint& t = ev->getTermPos(); + int b = ev->getButton(); + + if ( isMenu(super_menu) ) { - const FPoint& t = ev->getTermPos(); - int b = ev->getButton(); + FMenu* smenu = dynamic_cast(super_menu); - if ( isMenu(super_menu) ) + if ( smenu ) { - FMenu* smenu = dynamic_cast(super_menu); - - if ( smenu ) - { - const FPoint& p2 = smenu->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b); - smenu->onMouseMove(_ev); - delete _ev; - } + const FPoint& p2 = smenu->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b); + smenu->onMouseMove(_ev); + delete _ev; } + } - if ( isMenuBar(super_menu) ) + if ( isMenuBar(super_menu) ) + { + FMenuBar* mbar = dynamic_cast(super_menu); + + if ( mbar ) { - FMenuBar* mbar = dynamic_cast(super_menu); - - if ( mbar ) - { - const FPoint& p2 = mbar->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b); - mbar->onMouseMove(_ev); - delete _ev; - } + const FPoint& p2 = mbar->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b); + mbar->onMouseMove(_ev); + delete _ev; } + } - if ( isWindowsMenu(super_menu) ) + if ( isWindowsMenu(super_menu) ) + { + FDialog* dgl = dynamic_cast(super_menu); + + if ( dgl ) { - FDialog* dgl = dynamic_cast(super_menu); - - if ( dgl ) - { - const FPoint& p2 = dgl->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b); - dgl->onMouseMove(_ev); - delete _ev; - } + const FPoint& p2 = dgl->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b); + dgl->onMouseMove(_ev); + delete _ev; } } } @@ -657,59 +657,60 @@ void FMenuItem::onMouseMove (FMouseEvent* ev) //---------------------------------------------------------------------- void FMenuItem::onAccel (FAccelEvent* ev) { - if ( isEnabled() && ! isSelected() ) + if ( ! isEnabled() || isSelected() ) + return; + + if ( ! super_menu || ! isMenuBar(super_menu) ) { - if ( super_menu && isMenuBar(super_menu) ) - { - FMenuBar* mbar = dynamic_cast(super_menu); - - if ( mbar ) - { - if ( menu ) - { - FWidget* focused_widget; - - if ( mbar->getSelectedItem() ) - mbar->getSelectedItem()->unsetSelected(); - - setSelected(); - mbar->selected_item = this; - openMenu(); - - focused_widget = static_cast(ev->focusedWidget()); - FFocusEvent out (fc::FocusOut_Event); - FApplication::queueEvent(focused_widget, &out); - menu->unselectItem(); - menu->selectFirstItem(); - - if ( menu->getSelectedItem() ) - menu->getSelectedItem()->setFocus(); - - if ( focused_widget ) - focused_widget->redraw(); - - menu->redraw(); - - if ( statusBar() ) - statusBar()->drawMessage(); - - mbar->redraw(); - mbar->drop_down = true; - } - else - { - unsetSelected(); - mbar->selected_item = 0; - mbar->redraw(); - processClicked(); - mbar->drop_down = false; - } - ev->accept(); - } - } - else - processClicked(); + processClicked(); + return; } + + FMenuBar* mbar = dynamic_cast(super_menu); + + if ( ! mbar ) + return; + + if ( menu ) + { + FWidget* focused_widget; + + if ( mbar->getSelectedItem() ) + mbar->getSelectedItem()->unsetSelected(); + + setSelected(); + mbar->selected_item = this; + openMenu(); + + focused_widget = static_cast(ev->focusedWidget()); + FFocusEvent out (fc::FocusOut_Event); + FApplication::queueEvent(focused_widget, &out); + menu->unselectItem(); + menu->selectFirstItem(); + + if ( menu->getSelectedItem() ) + menu->getSelectedItem()->setFocus(); + + if ( focused_widget ) + focused_widget->redraw(); + + menu->redraw(); + + if ( statusBar() ) + statusBar()->drawMessage(); + + mbar->redraw(); + mbar->drop_down = true; + } + else + { + unsetSelected(); + mbar->selected_item = 0; + mbar->redraw(); + processClicked(); + mbar->drop_down = false; + } + ev->accept(); } //---------------------------------------------------------------------- diff --git a/src/fmenulist.cpp b/src/fmenulist.cpp index 5b0aac5d..798cdca7 100644 --- a/src/fmenulist.cpp +++ b/src/fmenulist.cpp @@ -18,16 +18,16 @@ FMenuList::FMenuList() FMenuList::~FMenuList() // destructor { // delete all items - if ( ! item_list.empty() ) - { - std::vector::iterator iter; - iter = item_list.begin(); + if ( item_list.empty() ) + return; - while ( iter != item_list.end() ) - { - (*iter)->setSuperMenu(0); - iter = item_list.erase(iter); - } + std::vector::iterator iter; + iter = item_list.begin(); + + while ( iter != item_list.end() ) + { + (*iter)->setSuperMenu(0); + iter = item_list.erase(iter); } } diff --git a/src/fmessagebox.cpp b/src/fmessagebox.cpp index 535a4b51..d0e5e31f 100644 --- a/src/fmessagebox.cpp +++ b/src/fmessagebox.cpp @@ -375,7 +375,9 @@ void FMessageBox::adjustSize() FMessageBox& FMessageBox::operator = (const FMessageBox& mbox) { if ( &mbox == this ) + { return *this; + } else { for (uInt n=0; n < num_buttons; n++) diff --git a/src/fobject.cpp b/src/fobject.cpp index da9e5302..dc692b86 100644 --- a/src/fobject.cpp +++ b/src/fobject.cpp @@ -94,18 +94,6 @@ void FObject::delChild (FObject* obj) } } -//---------------------------------------------------------------------- -bool FObject::event (FEvent* ev) -{ - if ( ev->type() == fc::Timer_Event ) - { - onTimer ( static_cast(ev) ); - return true; - } - - return false; -} - //---------------------------------------------------------------------- void FObject::getCurrentTime (timeval &time) { @@ -255,6 +243,18 @@ bool FObject::delAllTimer() } // protected methods of FObject +//---------------------------------------------------------------------- +bool FObject::event (FEvent* ev) +{ + if ( ev->type() == fc::Timer_Event ) + { + onTimer ( static_cast(ev) ); + return true; + } + + return false; +} + //---------------------------------------------------------------------- void FObject::onTimer (FTimerEvent*) { } diff --git a/src/fobject.h b/src/fobject.h index b1b40ad8..d360e1c9 100644 --- a/src/fobject.h +++ b/src/fobject.h @@ -90,11 +90,10 @@ class FObject bool delOwnTimer(); bool delAllTimer(); bool isTimerInUpdating() const; - // Event handler - virtual bool event (FEvent*); protected: // Event handler + virtual bool event (FEvent*); virtual void onTimer (FTimerEvent*); private: diff --git a/src/foptimove.cpp b/src/foptimove.cpp index 88413ee8..9f1e1009 100644 --- a/src/foptimove.cpp +++ b/src/foptimove.cpp @@ -69,38 +69,36 @@ int FOptiMove::capDuration (char*& cap, int affcnt) // cap - the term capability // affcnt - the number of lines affected - if ( cap ) - { - const char* p; - float ms = 0; - - for (p=cap; *p; p++) - { - // check for delay with padding character - if ( p[0] == '$' && p[1] == '<' && std::strchr(p, '>') ) - { - float num=0; - - for (p += 2; *p != '>'; p++) - { - if ( std::isdigit(uChar(*p)) ) - num = num * 10 + float(*p - '0'); - else if ( *p == '*' ) - num *= float(affcnt); - else if ( *p == '.' && *++p != '>' && std::isdigit(uChar(*p)) ) - num += float((*p - '0') / 10.0); - } - - ms += num * 10; - } - else - ms += float(char_duration); - } - - return int(ms); - } - else + if ( ! cap ) return LONG_DURATION; + + const char* p; + float ms = 0; + + for (p=cap; *p; p++) + { + // check for delay with padding character + if ( p[0] == '$' && p[1] == '<' && std::strchr(p, '>') ) + { + float num=0; + + for (p += 2; *p != '>'; p++) + { + if ( std::isdigit(uChar(*p)) ) + num = num * 10 + float(*p - '0'); + else if ( *p == '*' ) + num *= float(affcnt); + else if ( *p == '.' && *++p != '>' && std::isdigit(uChar(*p)) ) + num += float((*p - '0') / 10.0); + } + + ms += num * 10; + } + else + ms += float(char_duration); + } + + return int(ms); } diff --git a/src/fradiomenuitem.cpp b/src/fradiomenuitem.cpp index f1ac177f..dcbec49b 100644 --- a/src/fradiomenuitem.cpp +++ b/src/fradiomenuitem.cpp @@ -49,21 +49,21 @@ void FRadioMenuItem::init (FWidget* parent) checkable = true; radio_button = true; - if ( parent ) + if ( ! parent ) + return; + + if ( isMenu(parent) ) // Parent is menu { - if ( isMenu(parent) ) // Parent is menu - { - FMenu* menu_ptr = dynamic_cast(parent); + FMenu* menu_ptr = dynamic_cast(parent); - if ( menu_ptr ) - menu_ptr->has_checkable_items = true; + if ( menu_ptr ) + menu_ptr->has_checkable_items = true; - this->addCallback - ( - "toggled", - _METHOD_CALLBACK (parent, &FMenu::cb_menuitem_toggled) - ); - } + this->addCallback + ( + "toggled", + _METHOD_CALLBACK (parent, &FMenu::cb_menuitem_toggled) + ); } } diff --git a/src/fstatusbar.cpp b/src/fstatusbar.cpp index a03f30c1..759c9b2e 100644 --- a/src/fstatusbar.cpp +++ b/src/fstatusbar.cpp @@ -92,20 +92,20 @@ void FStatusKey::processActivate() //---------------------------------------------------------------------- void FStatusKey::onAccel (FAccelEvent* ev) { - if ( ! isActivated() ) - { - setActive(); + if ( isActivated() ) + return; - if ( statusbar() ) - statusbar()->redraw(); + setActive(); - ev->accept(); - // unset after get back from callback - unsetActive(); + if ( statusbar() ) + statusbar()->redraw(); - if ( statusbar() ) - statusbar()->redraw(); - } + ev->accept(); + // unset after get back from callback + unsetActive(); + + if ( statusbar() ) + statusbar()->redraw(); } //---------------------------------------------------------------------- diff --git a/src/fstring.cpp b/src/fstring.cpp index 13b8bdc7..45772dce 100644 --- a/src/fstring.cpp +++ b/src/fstring.cpp @@ -146,16 +146,16 @@ FString::FString (const std::string& s) , bufsize(0) , c_string(0) { - if ( ! s.empty() ) - { - const wchar_t* wc_string; - wc_string = c_to_wc_str(s.c_str()); + if ( s.empty() ) + return; - if ( wc_string ) - { - _replace( wc_string ); - delete[] wc_string; - } + const wchar_t* wc_string; + wc_string = c_to_wc_str(s.c_str()); + + if ( wc_string ) + { + _replace( wc_string ); + delete[] wc_string; } } @@ -217,13 +217,13 @@ FString::~FString() // destructor //---------------------------------------------------------------------- inline void FString::initLength (uInt len) { - if ( len > 0 ) - { - length = len; - bufsize = FWDBUFFER + len + 1; - string = new wchar_t[bufsize](); - std::wmemset (string, L'\0', bufsize); - } + if ( len == 0 ) + return; + + length = len; + bufsize = FWDBUFFER + len + 1; + string = new wchar_t[bufsize](); + std::wmemset (string, L'\0', bufsize); } //---------------------------------------------------------------------- diff --git a/src/fterm.cpp b/src/fterm.cpp index 1e178be0..af3be819 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -101,14 +101,12 @@ fc::consoleCursorStyle FTerm::console_cursor_style; // constructors and destructor //---------------------------------------------------------------------- FTerm::FTerm() - : map() + : color_map() { resize_term = false; if ( ! term_initialized ) - { init(); - } } //---------------------------------------------------------------------- @@ -125,31 +123,100 @@ FTerm::~FTerm() // destructor } } + // private methods of FTerm //---------------------------------------------------------------------- -void FTerm::outb_Attribute_Controller (int index, int data) +inline uInt16 FTerm::getInputStatusRegisterOne() { - inb (AttrC_DataSwitch); - outb (index & 0x1F, AttrC_Index); - outb (uChar(data), AttrC_DataW); - inb (AttrC_DataSwitch); - outb (uChar((index & 0x1F) | 0x20), AttrC_Index); - outb (uChar(data), AttrC_DataW); + // Gets the VGA input-status-register-1 + uInt16 misc_read = 0x3cc; // Miscellaneous output (read port) + uInt16 io_base = (inb(misc_read) & 0x01) ? 0x3d0 : 0x3b0; + // 0x3ba : Input status 1 MDA (read port) + // 0x3da : Input status 1 CGA (read port) + return io_base + 0x0a; } //---------------------------------------------------------------------- -int FTerm::inb_Attribute_Controller (int index) +uChar FTerm::readAttributeController (uChar index) { - int res; - inb (AttrC_DataSwitch); - outb (index & 0x1F, AttrC_Index); - res = inb (AttrC_DataR); - inb (AttrC_DataSwitch); - outb (uChar((index & 0x1F) | 0x20), AttrC_Index); - inb (AttrC_DataR); + // Reads a byte from the attribute controller from a given index + uChar res; + uInt16 attrib_cntlr_write = 0x3c0; // Attribute controller (write port) + uInt16 attrib_cntlr_read = 0x3c1; // Attribute controller (read port) + uInt16 input_status_1 = getInputStatusRegisterOne(); + + inb (input_status_1); // switch to index mode + outb (index & 0x1f, attrib_cntlr_write); + res = inb (attrib_cntlr_read); + + inb (input_status_1); // switch to data mode + index = (index & 0x1f) | 0x20; // set bit 5 (enable display) + outb (index, attrib_cntlr_write); + inb (attrib_cntlr_read); return res; } +//---------------------------------------------------------------------- +void FTerm::writeAttributeController (uChar index, uChar data) +{ + // Writes a byte from the attribute controller from a given index + uInt16 attrib_cntlr_write = 0x3c0; // Attribute controller (write port) + uInt16 input_status_1 = getInputStatusRegisterOne(); + + inb (input_status_1); // switch to index mode + outb (index & 0x1f, attrib_cntlr_write); + outb (data, attrib_cntlr_write); + + inb (input_status_1); // switch to data mode + index = (index & 0x1f) | 0x20; // set bit 5 (enable display) + outb (index, attrib_cntlr_write); + outb (data, attrib_cntlr_write); +} + +//---------------------------------------------------------------------- +inline uChar FTerm::getAttributeMode() +{ + // Gets the attribute mode value from the vga attribute controller + uChar attrib_mode = 0x10; + return readAttributeController(attrib_mode); +} + +//---------------------------------------------------------------------- +inline void FTerm::setAttributeMode(uChar data) +{ + // Sets the attribute mode value from the vga attribute controller + uChar attrib_mode = 0x10; + writeAttributeController (attrib_mode, data); +} + +//---------------------------------------------------------------------- +int FTerm::setBlinkAsIntensity (bool on) +{ + // Uses blink-bit as background intensity. + // That permits 16 colors for background + + if ( getuid() != 0 ) // Direct hardware access requires root privileges + return -2; + + if ( fd_tty < 0 ) + return -1; + + // Enable access to VGA I/O ports (from 0x3B4 with num = 0x2C) + if ( ioctl(fd_tty, KDENABIO, 0) < 0 ) + return -1; // error on KDENABIO + + if ( on ) + setAttributeMode (getAttributeMode() & 0xF7); // clear bit 3 + else + setAttributeMode (getAttributeMode() | 0x08); // set bit 3 + + // Disable access to VGA I/O ports + if ( ioctl(fd_tty, KDDISABIO, 0) < 0 ) + return -1; // error on KDDISABIO + + return 0; +} + //---------------------------------------------------------------------- int FTerm::getFramebuffer_bpp () { @@ -183,6 +250,7 @@ int FTerm::getFramebuffer_bpp () ::close(fd); } } + return -1; } @@ -313,7 +381,7 @@ int FTerm::getScreenFont() return -1; // initialize unused padding bytes in struct - memset(&font, 0, sizeof(console_font_op)); + std::memset (&font, 0, sizeof(console_font_op)); font.op = KD_FONT_OP_GET; font.flags = 0; @@ -350,7 +418,7 @@ int FTerm::setScreenFont ( uChar* fontdata, uInt count return -1; // initialize unused padding bytes in struct - memset(&font, 0x00, sizeof(console_font_op)); + std::memset (&font, 0x00, sizeof(console_font_op)); font.op = KD_FONT_OP_SET; font.flags = 0; @@ -445,6 +513,7 @@ int FTerm::getUnicodeMap() else return -1; } + return 0; } @@ -483,34 +552,6 @@ int FTerm::setUnicodeMap (struct unimapdesc* unimap) return -1; } -//---------------------------------------------------------------------- -int FTerm::setBlinkAsIntensity (bool on) -{ - // Uses blink-bit as background intensity. - // That permits 16 colors for background - - if ( getuid() != 0 ) // Direct hardware access requires root privileges - return -2; - - if ( fd_tty < 0 ) - return -1; - - // Enable access to VGA I/O ports (from 0x3B4 with num = 0x2C) - if ( ioctl(fd_tty, KDENABIO, 0) < 0 ) - return -1; // error on KDENABIO - - if ( on ) - outb_Attribute_Controller (0x10, inb_Attribute_Controller(0x10) & 0xF7); - else - outb_Attribute_Controller (0x10, inb_Attribute_Controller(0x10) | 0x08); - - // Disable access to VGA I/O ports - if ( ioctl(fd_tty, KDDISABIO, 0) < 0 ) - return -1; // error on KDDISABIO - - return 0; -} - //---------------------------------------------------------------------- bool FTerm::isKeyTimeout (timeval* time, register long timeout) { @@ -693,7 +734,7 @@ FTerm::modifier_key& FTerm::getModifierKey() { char subcode = 6; // fill bit field with 0 - memset (&mod_key, 0x00, sizeof(mod_key)); + std::memset (&mod_key, 0x00, sizeof(mod_key)); // TIOCLINUX, subcode=6 if ( ioctl(0, TIOCLINUX, &subcode) >= 0 ) @@ -2827,7 +2868,7 @@ void FTerm::resetXTermHighlightBackground() //---------------------------------------------------------------------- void FTerm::saveColorMap() { - // ioctl (0, GIO_CMAP, &map); + // ioctl (0, GIO_CMAP, &color_map); } //---------------------------------------------------------------------- @@ -2855,11 +2896,11 @@ void FTerm::resetColorMap() }; for (int x=0; x<16; x++) { - map.d[x].red = CurrentColors[x].red; - map.d[x].green = CurrentColors[x].green; - map.d[x].blue = CurrentColors[x].blue; + color_map.d[x].red = CurrentColors[x].red; + color_map.d[x].green = CurrentColors[x].green; + color_map.d[x].blue = CurrentColors[x].blue; } - ioctl (0, PIO_CMAP, &map); + ioctl (0, PIO_CMAP, &color_map); }*/ std::fflush(stdout); @@ -2957,31 +2998,31 @@ void FTerm::setEncoding (std::string enc) // available encodings: "UTF8", "VT100", "PC" and "ASCII" it = encoding_set->find(enc); - if ( it != encoding_set->end() ) // found + if ( it == encoding_set->end() ) // not found + return; + + Encoding = it->second; + + assert ( Encoding == fc::UTF8 + || Encoding == fc::VT100 + || Encoding == fc::PC + || Encoding == fc::ASCII ); + + // set the new Fputchar function pointer + switch ( int(Encoding) ) { - Encoding = it->second; + case fc::UTF8: + Fputchar = &FTerm::putchar_UTF8; + break; - assert ( Encoding == fc::UTF8 - || Encoding == fc::VT100 - || Encoding == fc::PC - || Encoding == fc::ASCII ); - - // set the new Fputchar function pointer - switch ( int(Encoding) ) - { - case fc::UTF8: + case fc::VT100: + case fc::PC: + if ( xterm_terminal && utf8_console ) Fputchar = &FTerm::putchar_UTF8; - break; - - case fc::VT100: - case fc::PC: - if ( xterm_terminal && utf8_console ) - Fputchar = &FTerm::putchar_UTF8; - // fall through - case fc::ASCII: - default: - Fputchar = &FTerm::putchar_ASCII; - } + // fall through + case fc::ASCII: + default: + Fputchar = &FTerm::putchar_ASCII; } } diff --git a/src/fterm.h b/src/fterm.h index fb832c1e..092b9c87 100644 --- a/src/fterm.h +++ b/src/fterm.h @@ -75,13 +75,6 @@ #define OSC ESC "]" // Operating system command (7-bit) #define SECDA ESC "[>c" // Secondary Device Attributes -// VGA I/O-ports -#define VideoIOBase ( (inb(0x3CC) & 0x01) ? 0x3D0 : 0x3B0 ) -#define AttrC_Index 0x3C0 // Attribute controller index -#define AttrC_DataW 0x3C0 // Attribute controller dataW -#define AttrC_DataR 0x3C1 // Attribute controller dataR -#define AttrC_DataSwitch (VideoIOBase+0x0A) // Attribute controller data switch - // parseKeyString return value #define NEED_MORE_DATA -1 @@ -164,7 +157,7 @@ class FTerm struct { dacreg d[16]; - } map; + } color_map; protected: static int stdin_no; @@ -190,8 +183,12 @@ class FTerm // Disable assignment operator (=) FTerm& operator = (const FTerm&); - static void outb_Attribute_Controller (int, int); - static int inb_Attribute_Controller (int); + static uInt16 getInputStatusRegisterOne(); + static uChar readAttributeController (uChar); + static void writeAttributeController (uChar, uChar); + static uChar getAttributeMode(); + static void setAttributeMode (uChar); + static int setBlinkAsIntensity (bool); static int getFramebuffer_bpp(); static int openConsole(); static int closeConsole(); @@ -201,7 +198,6 @@ class FTerm static int setScreenFont (uChar*, uInt, uInt, uInt, bool = false); static int setUnicodeMap (struct unimapdesc*); static int getUnicodeMap (); - static int setBlinkAsIntensity (bool); static void init_console(); static uInt getBaudRate (const struct termios*); static char* init_256colorTerminal(); diff --git a/src/ftogglebutton.cpp b/src/ftogglebutton.cpp index e5d9afa7..d9012200 100644 --- a/src/ftogglebutton.cpp +++ b/src/ftogglebutton.cpp @@ -485,24 +485,24 @@ void FToggleButton::onMouseDown (FMouseEvent* ev) if ( ev->getButton() != fc::LeftButton ) return; - if ( ! hasFocus() ) + if ( hasFocus() ) + return; + + FWidget* focused_widget = getFocusWidget(); + FFocusEvent out (fc::FocusOut_Event); + FApplication::queueEvent(focused_widget, &out); + setFocus(); + + if ( focused_widget ) + focused_widget->redraw(); + + redraw(); + + if ( statusBar() ) { - FWidget* focused_widget = getFocusWidget(); - FFocusEvent out (fc::FocusOut_Event); - FApplication::queueEvent(focused_widget, &out); - setFocus(); - - if ( focused_widget ) - focused_widget->redraw(); - - redraw(); - - if ( statusBar() ) - { - statusBar()->drawMessage(); - updateTerminal(); - flush_out(); - } + statusBar()->drawMessage(); + updateTerminal(); + flush_out(); } } @@ -512,68 +512,69 @@ void FToggleButton::onMouseUp (FMouseEvent* ev) if ( ev->getButton() != fc::LeftButton ) return; - if ( getTermGeometry().contains(ev->getTermPos()) ) + if ( ! getTermGeometry().contains(ev->getTermPos()) ) + return; + + if ( isRadioButton() ) { - if ( isRadioButton() ) + if ( ! checked ) { - if ( ! checked ) - { - checked = true; - processToggle(); - } - } - else - { - checked = not checked; + checked = true; processToggle(); } - redraw(); - processClick(); } + else + { + checked = not checked; + processToggle(); + } + + redraw(); + processClick(); } //---------------------------------------------------------------------- void FToggleButton::onAccel (FAccelEvent* ev) { - if ( isEnabled() ) + if ( ! isEnabled() ) + return; + + if ( ! hasFocus() ) { - if ( ! hasFocus() ) - { - FWidget* focused_widget = static_cast(ev->focusedWidget()); - FFocusEvent out (fc::FocusOut_Event); - FApplication::queueEvent(focused_widget, &out); - setFocus(); + FWidget* focused_widget = static_cast(ev->focusedWidget()); + FFocusEvent out (fc::FocusOut_Event); + FApplication::queueEvent(focused_widget, &out); + setFocus(); - if ( focused_widget ) - focused_widget->redraw(); - } + if ( focused_widget ) + focused_widget->redraw(); + } - if ( isRadioButton() ) + if ( isRadioButton() ) + { + if ( ! checked ) { - if ( ! checked ) - { - checked = true; - processToggle(); - } - } - else - { - checked = not checked; + checked = true; processToggle(); } - - redraw(); - - if ( statusBar() ) - { - statusBar()->drawMessage(); - updateTerminal(); - flush_out(); - } - - processClick(); - ev->accept(); } + else + { + checked = not checked; + processToggle(); + } + + redraw(); + + if ( statusBar() ) + { + statusBar()->drawMessage(); + updateTerminal(); + flush_out(); + } + + processClick(); + ev->accept(); } //---------------------------------------------------------------------- @@ -592,35 +593,35 @@ void FToggleButton::onFocusOut (FFocusEvent* out_ev) statusBar()->drawMessage(); } - if ( group() ) + if ( ! group() ) + return; + + if ( ! focus_inside_group && isRadioButton() ) { - if ( ! focus_inside_group && isRadioButton() ) - { - focus_inside_group = true; - out_ev->ignore(); + focus_inside_group = true; + out_ev->ignore(); - if ( out_ev->getFocusType() == fc::FocusNextWidget ) - group()->focusNextChild(); - - if ( out_ev->getFocusType() == fc::FocusPreviousWidget ) - group()->focusPrevChild(); - - redraw(); - } - else if ( this == group()->getLastButton() - && out_ev->getFocusType() == fc::FocusNextWidget ) - { - out_ev->ignore(); + if ( out_ev->getFocusType() == fc::FocusNextWidget ) group()->focusNextChild(); - redraw(); - } - else if ( this == group()->getFirstButton() - && out_ev->getFocusType() == fc::FocusPreviousWidget ) - { - out_ev->ignore(); + + if ( out_ev->getFocusType() == fc::FocusPreviousWidget ) group()->focusPrevChild(); - redraw(); - } + + redraw(); + } + else if ( this == group()->getLastButton() + && out_ev->getFocusType() == fc::FocusNextWidget ) + { + out_ev->ignore(); + group()->focusNextChild(); + redraw(); + } + else if ( this == group()->getFirstButton() + && out_ev->getFocusType() == fc::FocusPreviousWidget ) + { + out_ev->ignore(); + group()->focusPrevChild(); + redraw(); } } diff --git a/src/ftooltip.cpp b/src/ftooltip.cpp index a598acb0..7ace7232 100644 --- a/src/ftooltip.cpp +++ b/src/ftooltip.cpp @@ -39,18 +39,18 @@ FToolTip::~FToolTip() // destructor { FApplication* fapp = static_cast(getRootWidget()); - if ( ! fapp->isQuit() ) - { - FWindow* parent_win = 0; + if ( fapp->isQuit() ) + return; - if ( FWidget* parent = getParentWidget() ) - parent_win = getWindowWidget(parent); + FWindow* parent_win = 0; - if ( parent_win ) - setActiveWindow (parent_win); - else - switchToPrevWindow(); - } + if ( FWidget* parent = getParentWidget() ) + parent_win = getWindowWidget(parent); + + if ( parent_win ) + setActiveWindow (parent_win); + else + switchToPrevWindow(); } diff --git a/src/fwindow.cpp b/src/fwindow.cpp index a390411d..ff94b5b7 100644 --- a/src/fwindow.cpp +++ b/src/fwindow.cpp @@ -58,21 +58,21 @@ FWindow::~FWindow() // destructor void FWindow::deleteFromAlwaysOnTopList (FWidget* obj) { // delete the window object obj from the always-on-top list - if ( always_on_top_list && ! always_on_top_list->empty() ) + if ( ! always_on_top_list || always_on_top_list->empty() ) + return; + + widgetList::iterator iter; + iter = always_on_top_list->begin(); + + while ( iter != always_on_top_list->end() ) { - widgetList::iterator iter; - iter = always_on_top_list->begin(); - - while ( iter != always_on_top_list->end() ) + if ( *iter == obj ) { - if ( *iter == obj ) - { - always_on_top_list->erase (iter); - return; - } - - ++iter; + always_on_top_list->erase (iter); + return; } + + ++iter; } } @@ -80,20 +80,20 @@ void FWindow::deleteFromAlwaysOnTopList (FWidget* obj) void FWindow::processAlwaysOnTop() { // Raise all always-on-top windows - if ( always_on_top_list && ! always_on_top_list->empty() ) + if ( ! always_on_top_list || always_on_top_list->empty() ) + return; + + widgetList::iterator iter; + iter = always_on_top_list->begin(); + + while ( iter != always_on_top_list->end() ) { - widgetList::iterator iter; - iter = always_on_top_list->begin(); + delWindow (*iter); - while ( iter != always_on_top_list->end() ) - { - delWindow (*iter); + if ( window_list ) + window_list->push_back(*iter); - if ( window_list ) - window_list->push_back(*iter); - - ++iter; - } + ++iter; } } @@ -319,22 +319,22 @@ void FWindow::setGeometry (int x, int y, int w, int h, bool adjust) FWidget::setGeometry (x, y, w, h, adjust); - if ( vwin ) - { - if ( getWidth() != old_width || getHeight() != old_height ) - { - FRect geometry = getTermGeometry(); - geometry.move(-1,-1); - resizeArea (geometry, getShadow(), vwin); - } - else - { - if ( getX() != old_x ) - vwin->x_offset = getTermX() - 1; + if ( ! vwin ) + return; - if ( getY() != old_y ) - vwin->y_offset = getTermY() - 1; - } + if ( getWidth() != old_width || getHeight() != old_height ) + { + FRect geometry = getTermGeometry(); + geometry.move(-1,-1); + resizeArea (geometry, getShadow(), vwin); + } + else + { + if ( getX() != old_x ) + vwin->x_offset = getTermX() - 1; + + if ( getY() != old_y ) + vwin->y_offset = getTermY() - 1; } } @@ -354,12 +354,6 @@ void FWindow::move (int dx, int dy) FWindow* FWindow::getWindowWidgetAt (int x, int y) { // returns the window object to the corresponding coordinates - if ( statusBar() && statusBar()->getTermGeometry().contains(x,y) ) - return statusBar(); - - if ( menuBar() && menuBar()->getTermGeometry().contains(x,y) ) - return menuBar(); - if ( window_list && ! window_list->empty() ) { widgetList::const_iterator iter, begin; @@ -761,7 +755,7 @@ bool FWindow::activatePrevWindow() if ( w->isWindowActive() ) return true; - if ( w && ! w->isWindowHidden() ) + if ( ! w->isWindowHidden() ) { setActiveWindow(w); return true; diff --git a/test/calculator.cpp b/test/calculator.cpp index b273c62c..840b6647 100644 --- a/test/calculator.cpp +++ b/test/calculator.cpp @@ -48,25 +48,25 @@ Button::Button (FWidget* parent) //---------------------------------------------------------------------- void Button::setChecked (bool on) { - if ( checked != on ) + if ( checked == on ) + return; + + checked = on; + + if ( checked ) { - checked = on; - - if ( checked ) - { - setBackgroundColor(fc::Cyan); - setFocusForegroundColor(fc::White); - setFocusBackgroundColor(fc::Cyan); - } - else - { - setBackgroundColor(wc.button_active_bg); - setFocusForegroundColor(wc.button_active_focus_fg); - setFocusBackgroundColor(wc.button_active_focus_bg); - } - - redraw(); + setBackgroundColor(fc::Cyan); + setFocusForegroundColor(fc::White); + setFocusBackgroundColor(fc::Cyan); } + else + { + setBackgroundColor(wc.button_active_bg); + setFocusForegroundColor(wc.button_active_focus_fg); + setFocusBackgroundColor(wc.button_active_focus_bg); + } + + redraw(); } //---------------------------------------------------------------------- diff --git a/test/transparent.cpp b/test/transparent.cpp index 980015b7..864c1641 100644 --- a/test/transparent.cpp +++ b/test/transparent.cpp @@ -105,18 +105,18 @@ void Transparent::draw() //---------------------------------------------------------------------- void Transparent::onKeyPress (FKeyEvent* ev) { - if ( ev ) + if ( ! ev ) + return; + + if ( ev->key() == 'q' && getParentWidget() ) { - if ( ev->key() == 'q' && getParentWidget() ) - { - if ( getParentWidget()->close() ) - ev->accept(); - else - ev->ignore(); - } + if ( getParentWidget()->close() ) + ev->accept(); else - FDialog::onKeyPress(ev); + ev->ignore(); } + else + FDialog::onKeyPress(ev); } @@ -147,16 +147,16 @@ class MainWindow : public FDialog void onTimer (FTimerEvent*); void onKeyPress (FKeyEvent* ev) { - if ( ev ) + if ( ! ev ) + return; + + if ( ev->key() == 'q' ) { - if ( ev->key() == 'q' ) - { - close(); - ev->accept(); - } - else - FDialog::onKeyPress(ev); + close(); + ev->accept(); } + else + FDialog::onKeyPress(ev); } public: diff --git a/test/ui.cpp b/test/ui.cpp index 65e17a5b..9328a1da 100644 --- a/test/ui.cpp +++ b/test/ui.cpp @@ -122,23 +122,23 @@ void ProgressDialog::onTimer (FTimerEvent*) progressBar->setPercentage(++p); flush_out(); - if ( p == 100 ) - { - delOwnTimer(); - activateWindow(); - raiseWindow(); - reset->setEnable(); - reset->setFocus(); - more->setEnable(); - quit->setEnable(); - redraw(); + if ( p != 100 ) + return; - if ( statusBar() ) - statusBar()->drawMessage(); + delOwnTimer(); + activateWindow(); + raiseWindow(); + reset->setEnable(); + reset->setFocus(); + more->setEnable(); + quit->setEnable(); + redraw(); - updateTerminal(); - flush_out(); - } + if ( statusBar() ) + statusBar()->drawMessage(); + + updateTerminal(); + flush_out(); } //---------------------------------------------------------------------- diff --git a/test/windows.cpp b/test/windows.cpp index b9e19715..4c87b6cb 100644 --- a/test/windows.cpp +++ b/test/windows.cpp @@ -339,16 +339,16 @@ Window::~Window() //---------------------------------------------------------------------- void Window::activateWindow (FDialog* win) { - if ( win && ! win->isWindowHidden() && ! win->isWindowActive() ) - { - bool has_raised = FWindow::raiseWindow(win); - win->activateDialog(); + if ( ! win || win->isWindowHidden() || win->isWindowActive() ) + return; - if ( has_raised ) - win->redraw(); + bool has_raised = FWindow::raiseWindow(win); + win->activateDialog(); - updateTerminal(); - } + if ( has_raised ) + win->redraw(); + + updateTerminal(); } //----------------------------------------------------------------------