Improvements for the window focus

This commit is contained in:
Markus Gans 2016-07-27 04:55:10 +02:00
parent cb468c59d2
commit a91d0566fc
5 changed files with 38 additions and 33 deletions

View File

@ -1,4 +1,4 @@
2016-07-25 Markus Gans <guru.mail@muenster.de> 2016-07-27 Markus Gans <guru.mail@muenster.de>
* Improvements for the window focus * Improvements for the window focus
2016-07-24 Markus Gans <guru.mail@muenster.de> 2016-07-24 Markus Gans <guru.mail@muenster.de>

View File

@ -19,7 +19,6 @@ FDialog::FDialog(FWidget* parent)
, maximized(false) , maximized(false)
, TitleBarClickPos() , TitleBarClickPos()
, oldGeometry() , oldGeometry()
, focus_widget(0)
, dialog_menu() , dialog_menu()
, dgl_menuitem() , dgl_menuitem()
{ {
@ -34,7 +33,6 @@ FDialog::FDialog (const FString& txt, FWidget* parent)
, maximized(false) , maximized(false)
, TitleBarClickPos() , TitleBarClickPos()
, oldGeometry() , oldGeometry()
, focus_widget(0)
, dialog_menu() , dialog_menu()
, dgl_menuitem() , dgl_menuitem()
{ {
@ -306,7 +304,7 @@ void FDialog::leaveMenu()
dialog_menu->hide(); dialog_menu->hide();
activateWindow(); activateWindow();
raiseWindow(); raiseWindow();
getFocusWidget()->setFocus(); getWindowFocusWidget()->setFocus();
redraw(); redraw();
if ( statusBar() ) if ( statusBar() )
@ -734,7 +732,7 @@ void FDialog::onMouseDoubleClick (FMouseEvent* ev)
dialog_menu->hide(); dialog_menu->hide();
activateWindow(); activateWindow();
raiseWindow(); raiseWindow();
getFocusWidget()->setFocus(); getWindowFocusWidget()->setFocus();
setClickedWidget(0); setClickedWidget(0);
if ( isModal() ) if ( isModal() )
@ -767,10 +765,13 @@ void FDialog::onWindowActive (FEvent*)
if ( ! FWidget::getFocusWidget() ) if ( ! FWidget::getFocusWidget() )
{ {
if ( focus_widget && focus_widget->isVisible() && focus_widget->isShown() ) if ( getWindowFocusWidget()
&& getWindowFocusWidget()->isVisible()
&& getWindowFocusWidget()->isShown() )
{ {
focus_widget->setFocus(); FWidget* win_focus_widget = getWindowFocusWidget();
focus_widget->redraw(); win_focus_widget->setFocus();
win_focus_widget->redraw();
} }
else else
focusFirstChild(); focusFirstChild();
@ -1013,12 +1014,13 @@ void FDialog::move (int x, int y)
void FDialog::activateDialog() void FDialog::activateDialog()
{ {
FWidget* old_focus = FWidget::getFocusWidget(); FWidget* old_focus = FWidget::getFocusWidget();
FWidget* win_focus_widget = getWindowFocusWidget();
setActiveWindow(this); setActiveWindow(this);
if ( focus_widget && numOfFocusableChildren() > 1 ) if ( win_focus_widget && numOfFocusableChildren() > 1 )
{ {
focus_widget->setFocus(); win_focus_widget->setFocus();
focus_widget->redraw(); win_focus_widget->redraw();
if ( old_focus ) if ( old_focus )
old_focus->redraw(); old_focus->redraw();
@ -1068,18 +1070,6 @@ void FDialog::setGeometry (int x, int y, int w, int h, bool adjust)
resizeArea (vwin); resizeArea (vwin);
} }
//----------------------------------------------------------------------
FWidget* FDialog::getFocusWidget() const
{
return focus_widget;
}
//----------------------------------------------------------------------
void FDialog::setFocusWidget (FWidget* obj)
{
focus_widget = obj;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FDialog::setFocus (bool on) bool FDialog::setFocus (bool on)
{ {

View File

@ -55,7 +55,6 @@ class FDialog : public FWindow
bool maximized; bool maximized;
FPoint TitleBarClickPos; FPoint TitleBarClickPos;
FRect oldGeometry; // required by move() FRect oldGeometry; // required by move()
FWidget* focus_widget;
FMenu* dialog_menu; FMenu* dialog_menu;
FMenuItem* dgl_menuitem; FMenuItem* dgl_menuitem;
@ -106,8 +105,6 @@ class FDialog : public FWindow
// make every setGeometry from FWidget available // make every setGeometry from FWidget available
using FWidget::setGeometry; using FWidget::setGeometry;
void setGeometry (int, int, int, int, bool = true); void setGeometry (int, int, int, int, bool = true);
FWidget* getFocusWidget() const;
void setFocusWidget (FWidget*);
bool setFocus(bool); bool setFocus(bool);
bool setFocus(); bool setFocus();
bool unsetFocus(); bool unsetFocus();

View File

@ -18,6 +18,7 @@ FWindow* FWindow::previous_widget = 0;
FWindow::FWindow(FWidget* parent) FWindow::FWindow(FWidget* parent)
: FWidget(parent) : FWidget(parent)
, window_active(false) , window_active(false)
, win_focus_widget(0)
{ } { }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -332,6 +333,14 @@ bool FWindow::lowerWindow (FWidget* obj)
return false; return false;
} }
//----------------------------------------------------------------------
FWindow* FWindow::getActiveWindow()
{
// returns the active FWindow object
FWindow* active_window = static_cast<FWindow*>(FApplication::active_window);
return active_window;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWindow::setActiveWindow (FWindow* 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 // returns the focused widget of this window
FWindow* active_window = static_cast<FWindow*>(FApplication::active_window); return win_focus_widget;
return active_window; }
//----------------------------------------------------------------------
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 ) if ( active_window )
{ {
FWidget* focus_widget = active_window->getFocusWidget(); FWidget* focus_widget = active_window->getWindowFocusWidget();
if ( ! active_window->isActiveWindow() ) if ( ! active_window->isActiveWindow() )
setActiveWindow(active_window); setActiveWindow(active_window);

View File

@ -44,7 +44,8 @@
class FWindow : public FWidget class FWindow : public FWidget
{ {
private: private:
bool window_active; bool window_active;
FWidget* win_focus_widget;
protected: protected:
static FWindow* previous_widget; static FWindow* previous_widget;
@ -79,8 +80,10 @@ class FWindow : public FWidget
bool raiseWindow (); bool raiseWindow ();
static bool lowerWindow (FWidget*); static bool lowerWindow (FWidget*);
bool lowerWindow (); bool lowerWindow ();
static void setActiveWindow (FWindow*);
static FWindow* getActiveWindow(); static FWindow* getActiveWindow();
static void setActiveWindow (FWindow*);
FWidget* getWindowFocusWidget() const;
void setWindowFocusWidget (FWidget*);
static void switchToPrevWindow(); static void switchToPrevWindow();
static bool activatePrevWindow(); static bool activatePrevWindow();
bool activateWindow (bool); bool activateWindow (bool);