diff --git a/ChangeLog b/ChangeLog index 6a2c7538..b0c674d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -2016-07-25 Markus Gans +2016-07-27 Markus Gans * Improvements for the window focus 2016-07-24 Markus Gans diff --git a/src/fdialog.cpp b/src/fdialog.cpp index ac10f81d..65e52031 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -19,7 +19,6 @@ FDialog::FDialog(FWidget* parent) , maximized(false) , TitleBarClickPos() , oldGeometry() - , focus_widget(0) , dialog_menu() , dgl_menuitem() { @@ -34,7 +33,6 @@ FDialog::FDialog (const FString& txt, FWidget* parent) , maximized(false) , TitleBarClickPos() , oldGeometry() - , focus_widget(0) , dialog_menu() , dgl_menuitem() { @@ -306,7 +304,7 @@ void FDialog::leaveMenu() dialog_menu->hide(); activateWindow(); raiseWindow(); - getFocusWidget()->setFocus(); + getWindowFocusWidget()->setFocus(); redraw(); if ( statusBar() ) @@ -734,7 +732,7 @@ void FDialog::onMouseDoubleClick (FMouseEvent* ev) dialog_menu->hide(); activateWindow(); raiseWindow(); - getFocusWidget()->setFocus(); + getWindowFocusWidget()->setFocus(); setClickedWidget(0); if ( isModal() ) @@ -767,10 +765,13 @@ void FDialog::onWindowActive (FEvent*) if ( ! FWidget::getFocusWidget() ) { - if ( focus_widget && focus_widget->isVisible() && focus_widget->isShown() ) + if ( getWindowFocusWidget() + && getWindowFocusWidget()->isVisible() + && getWindowFocusWidget()->isShown() ) { - focus_widget->setFocus(); - focus_widget->redraw(); + FWidget* win_focus_widget = getWindowFocusWidget(); + win_focus_widget->setFocus(); + win_focus_widget->redraw(); } else focusFirstChild(); @@ -1013,12 +1014,13 @@ void FDialog::move (int x, int y) void FDialog::activateDialog() { FWidget* old_focus = FWidget::getFocusWidget(); + FWidget* win_focus_widget = getWindowFocusWidget(); setActiveWindow(this); - if ( focus_widget && numOfFocusableChildren() > 1 ) + if ( win_focus_widget && numOfFocusableChildren() > 1 ) { - focus_widget->setFocus(); - focus_widget->redraw(); + win_focus_widget->setFocus(); + win_focus_widget->redraw(); if ( old_focus ) old_focus->redraw(); @@ -1068,18 +1070,6 @@ void FDialog::setGeometry (int x, int y, int w, int h, bool adjust) resizeArea (vwin); } -//---------------------------------------------------------------------- -FWidget* FDialog::getFocusWidget() const -{ - return focus_widget; -} - -//---------------------------------------------------------------------- -void FDialog::setFocusWidget (FWidget* obj) -{ - focus_widget = obj; -} - //---------------------------------------------------------------------- bool FDialog::setFocus (bool on) { diff --git a/src/fdialog.h b/src/fdialog.h index 5ba5a975..93917de3 100644 --- a/src/fdialog.h +++ b/src/fdialog.h @@ -55,7 +55,6 @@ class FDialog : public FWindow bool maximized; FPoint TitleBarClickPos; FRect oldGeometry; // required by move() - FWidget* focus_widget; FMenu* dialog_menu; FMenuItem* dgl_menuitem; @@ -106,8 +105,6 @@ class FDialog : public FWindow // make every setGeometry from FWidget available using FWidget::setGeometry; void setGeometry (int, int, int, int, bool = true); - FWidget* getFocusWidget() const; - void setFocusWidget (FWidget*); bool setFocus(bool); bool setFocus(); bool unsetFocus(); diff --git a/src/fwindow.cpp b/src/fwindow.cpp index 07ec208c..ed9c0b78 100644 --- a/src/fwindow.cpp +++ b/src/fwindow.cpp @@ -18,6 +18,7 @@ FWindow* FWindow::previous_widget = 0; FWindow::FWindow(FWidget* parent) : FWidget(parent) , window_active(false) + , win_focus_widget(0) { } //---------------------------------------------------------------------- @@ -332,6 +333,14 @@ bool FWindow::lowerWindow (FWidget* obj) return false; } +//---------------------------------------------------------------------- +FWindow* FWindow::getActiveWindow() +{ + // returns the active FWindow object + FWindow* active_window = static_cast(FApplication::active_window); + return active_window; +} + //---------------------------------------------------------------------- void FWindow::setActiveWindow (FWindow* window) { @@ -375,11 +384,17 @@ void FWindow::setActiveWindow (FWindow* window) } //---------------------------------------------------------------------- -FWindow* FWindow::getActiveWindow() +FWidget* FWindow::getWindowFocusWidget() const { - // returns the active FWindow object - FWindow* active_window = static_cast(FApplication::active_window); - return active_window; + // returns the focused widget of this window + return win_focus_widget; +} + +//---------------------------------------------------------------------- +void FWindow::setWindowFocusWidget (FWidget* obj) +{ + // set focus widget of this window + win_focus_widget = obj; } //---------------------------------------------------------------------- @@ -391,7 +406,7 @@ void FWindow::switchToPrevWindow() if ( active_window ) { - FWidget* focus_widget = active_window->getFocusWidget(); + FWidget* focus_widget = active_window->getWindowFocusWidget(); if ( ! active_window->isActiveWindow() ) setActiveWindow(active_window); diff --git a/src/fwindow.h b/src/fwindow.h index cf477cf0..9567dba7 100644 --- a/src/fwindow.h +++ b/src/fwindow.h @@ -44,7 +44,8 @@ class FWindow : public FWidget { private: - bool window_active; + bool window_active; + FWidget* win_focus_widget; protected: static FWindow* previous_widget; @@ -79,8 +80,10 @@ class FWindow : public FWidget bool raiseWindow (); static bool lowerWindow (FWidget*); bool lowerWindow (); - static void setActiveWindow (FWindow*); static FWindow* getActiveWindow(); + static void setActiveWindow (FWindow*); + FWidget* getWindowFocusWidget() const; + void setWindowFocusWidget (FWidget*); static void switchToPrevWindow(); static bool activatePrevWindow(); bool activateWindow (bool);