From 7dd7455b23eb16ad92e63662941219ee8499f0f4 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sun, 19 Jun 2016 20:32:03 +0200 Subject: [PATCH] Fixes some status bar update issues and focus problems --- ChangeLog | 4 ++++ src/fapp.cpp | 19 ++++++++++++------- src/fdialog.cpp | 3 +++ src/fmenubar.cpp | 7 +++---- src/fterm.cpp | 3 +++ src/fwidget.cpp | 14 +++++++++++++- src/fwindow.cpp | 33 ++++++++++++++++++++++++++++++++- src/fwindow.h | 3 ++- 8 files changed, 72 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7ea309f2..bb4cb7fa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-06-19 Markus Gans + * Clear status bar text in FMenuBar::leaveMenuBar() + * Fixes some status bar update issues and focus problems + 2016-06-18 Markus Gans * Improved status bar text updating at window change diff --git a/src/fapp.cpp b/src/fapp.cpp index 8c0ddb86..695ee728 100644 --- a/src/fapp.cpp +++ b/src/fapp.cpp @@ -983,13 +983,7 @@ void FApplication::processMouseEvent() // No widget was been clicked if ( ! clicked_widget ) - { - // activate previous window - FWindow::activatePrevWindow(); - FWindow::raiseWindow (FWindow::getActiveWindow()); - FWindow::getActiveWindow()->getFocusWidget()->setFocus(); - FWindow::getActiveWindow()->redraw(); - } + FWindow::switchToPrevWindow(); if ( statusBar() ) statusBar()->drawMessage(); updateTerminal(); @@ -997,14 +991,25 @@ void FApplication::processMouseEvent() } } + // unselected menu bar item if ( ! open_menu && menuBar() && menuBar()->hasSelectedItem() && ! b_state.mouse_moved ) { if ( ! menuBar()->getGeometryGlobal().contains(*mouse) ) { + if ( statusBar() ) + statusBar()->clearMessage(); menuBar()->resetMenu(); menuBar()->redraw(); + + // No widget was been clicked + if ( ! clicked_widget ) + FWindow::switchToPrevWindow(); + if ( statusBar() ) + statusBar()->drawMessage(); + updateTerminal(); + flush_out(); } } diff --git a/src/fdialog.cpp b/src/fdialog.cpp index 4ccb03a6..d6997595 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -755,6 +755,9 @@ void FDialog::onWindowInactive (FEvent*) { if ( isVisible() && isEnabled() ) drawTitleBar(); + + if ( hasFocus() ) + unsetFocus(); } //---------------------------------------------------------------------- diff --git a/src/fmenubar.cpp b/src/fmenubar.cpp index 5eca0a53..a0143fc0 100644 --- a/src/fmenubar.cpp +++ b/src/fmenubar.cpp @@ -468,10 +468,9 @@ void FMenuBar::leaveMenuBar() { resetMenu(); redraw(); - activatePrevWindow(); - raiseWindow (getActiveWindow()); - getActiveWindow()->getFocusWidget()->setFocus(); - getActiveWindow()->redraw(); + if ( statusBar() ) + statusBar()->clearMessage(); + switchToPrevWindow(); if ( statusBar() ) statusBar()->drawMessage(); updateTerminal(); diff --git a/src/fterm.cpp b/src/fterm.cpp index 944ba3e0..04849405 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -3433,6 +3433,7 @@ void FTerm::setPalette (short index, int r, int g, int b) //---------------------------------------------------------------------- void FTerm::xtermMouse (bool on) { + // activate/deactivate the xterm mouse support if ( ! mouse_support ) return; if ( on ) @@ -3455,6 +3456,7 @@ void FTerm::xtermMouse (bool on) //---------------------------------------------------------------------- bool FTerm::gpmMouse (bool on) { + // activate/deactivate the gpm mouse support if ( ! linux_terminal ) return false; @@ -3498,6 +3500,7 @@ bool FTerm::gpmMouse (bool on) //---------------------------------------------------------------------- void FTerm::setTermXY (register int x, register int y) { + // sets the hardware cursor to the given (x,y) position int term_width, term_height; char* move_str; diff --git a/src/fwidget.cpp b/src/fwidget.cpp index 343e5d9c..d47b045b 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -1468,16 +1468,28 @@ bool FWidget::setFocus(bool on) if ( on == focus ) return true; + // set widget focus if ( on && ! focus ) { + int focusable_children = numOfFocusableChildren(); + if ( FWidget::getFocusWidget() != 0 ) FWidget::getFocusWidget()->unsetFocus(); - if ( numOfFocusableChildren() == 0 ) + + if ( (!isDialog() && focusable_children == 0) + || (isDialog() && focusable_children == 1) ) + { FWidget::setFocusWidget(this); + } } + // unset widget focus + if ( ! on && focus ) + FWidget::setFocusWidget(0); + window = FWindow::getWindowWidget(this); + // set window focus if ( on && window ) { if ( ! window->isActiveWindow() ) diff --git a/src/fwindow.cpp b/src/fwindow.cpp index 74183ee3..25787b74 100644 --- a/src/fwindow.cpp +++ b/src/fwindow.cpp @@ -120,6 +120,7 @@ FWindow* FWindow::getWindowWidgetAt(int x, int y) //---------------------------------------------------------------------- void FWindow::addWindow (FWidget* obj) { + // add the window object obj to the window list if ( window_list ) window_list->push_back(obj); } @@ -127,6 +128,7 @@ void FWindow::addWindow (FWidget* obj) //---------------------------------------------------------------------- void FWindow::delWindow (FWidget* obj) { + // delete the window object obj from the window list if ( window_list && ! window_list->empty() ) { widgetList::iterator iter; @@ -147,6 +149,7 @@ void FWindow::delWindow (FWidget* obj) //---------------------------------------------------------------------- FWindow* FWindow::getWindowWidget (FWidget* obj) { + // returns the window object to the given widget obj FWidget* p_obj = obj->parentWidget(); while ( ! obj->isWindow() && p_obj ) { @@ -162,6 +165,7 @@ FWindow* FWindow::getWindowWidget (FWidget* obj) //---------------------------------------------------------------------- int FWindow::getWindowLayer (FWidget* obj) { + // returns the window layer from the widget obj widgetList::iterator iter, end; FWidget* window; @@ -194,6 +198,7 @@ int FWindow::getWindowLayer (FWidget* obj) //---------------------------------------------------------------------- void FWindow::swapWindow (FWidget* obj1, FWidget* obj2) { + // swaps the window layer between obj1 and obj2 widgetList::iterator iter, iter1, iter2, end; if ( ! window_list ) @@ -226,6 +231,7 @@ void FWindow::swapWindow (FWidget* obj1, FWidget* obj2) //---------------------------------------------------------------------- bool FWindow::raiseWindow (FWidget* obj) { + // raises the window widget obj to the top widgetList::iterator iter; if ( ! window_list ) @@ -260,6 +266,7 @@ bool FWindow::raiseWindow (FWidget* obj) //---------------------------------------------------------------------- bool FWindow::lowerWindow (FWidget* obj) { + // lowers the window widget obj to the bottom widgetList::iterator iter; if ( ! window_list ) @@ -293,6 +300,7 @@ bool FWindow::lowerWindow (FWidget* obj) //---------------------------------------------------------------------- void FWindow::setActiveWindow (FWindow* window) { + // activate FWindow object window widgetList::const_iterator iter, end; if ( ! window_list ) @@ -331,13 +339,34 @@ void FWindow::setActiveWindow (FWindow* window) //---------------------------------------------------------------------- FWindow* FWindow::getActiveWindow() { + // returns the active FWindow object FWindow* active_window = static_cast(FApplication::active_window); return active_window; } +//---------------------------------------------------------------------- +void FWindow::switchToPrevWindow() +{ + // switch to previous window + activatePrevWindow(); + + FWindow* active_window = getActiveWindow(); + if ( active_window ) + { + FWidget* focus_widget = active_window->getFocusWidget(); + if ( ! active_window->isActiveWindow() ) + setActiveWindow(active_window); + raiseWindow (active_window); + if ( focus_widget ) + focus_widget->setFocus(); + active_window->redraw(); + } +} + //---------------------------------------------------------------------- bool FWindow::activatePrevWindow() { + // activate the previous window if ( window_list && window_list->size() > 1 ) { widgetList::const_iterator iter, begin; @@ -360,8 +389,9 @@ bool FWindow::activatePrevWindow() } //---------------------------------------------------------------------- -bool FWindow::activateWindow(bool on) +bool FWindow::activateWindow (bool on) { + // activate/deactivate this window if ( on ) FApplication::active_window = this; @@ -371,6 +401,7 @@ bool FWindow::activateWindow(bool on) //---------------------------------------------------------------------- bool FWindow::isHiddenWindow() const { + // returns the window hidden state term_area* area = getVWin(); if ( area ) return ! area->visible; diff --git a/src/fwindow.h b/src/fwindow.h index 6be3d374..ccf68e79 100644 --- a/src/fwindow.h +++ b/src/fwindow.h @@ -78,8 +78,9 @@ class FWindow : public FWidget bool lowerWindow (); static void setActiveWindow (FWindow*); static FWindow* getActiveWindow(); + static void switchToPrevWindow(); static bool activatePrevWindow(); - bool activateWindow(bool); + bool activateWindow (bool); bool activateWindow(); bool deactivateWindow(); bool isActiveWindow() const;