Code optimization at widget focus

This commit is contained in:
Markus Gans 2021-04-27 11:51:53 +02:00
parent 8d54e1c11f
commit 9ba7fc6178
15 changed files with 45 additions and 176 deletions

View File

@ -1,3 +1,6 @@
2021-04-27 Markus Gans <guru.mail@muenster.de>
* Code optimization at widget focus
2021-04-24 Markus Gans <guru.mail@muenster.de> 2021-04-24 Markus Gans <guru.mail@muenster.de>
* Fixed mutex deadlock in FLogger * Fixed mutex deadlock in FLogger

View File

@ -284,18 +284,7 @@ void FButton::onMouseDown (FMouseEvent* ev)
return; return;
} }
if ( ! hasFocus() ) setWidgetFocus(this);
{
auto focused_widget = getFocusWidget();
setFocus();
if ( focused_widget )
focused_widget->redraw();
if ( getStatusBar() )
getStatusBar()->drawMessage();
}
const FPoint tPos{ev->getTermPos()}; const FPoint tPos{ev->getTermPos()};
if ( getTermGeometry().contains(tPos) ) if ( getTermGeometry().contains(tPos) )

View File

@ -396,26 +396,15 @@ void FComboBox::onMouseDown (FMouseEvent* ev)
if ( ev->getButton() != MouseButton::Left ) if ( ev->getButton() != MouseButton::Left )
return; return;
if ( ! hasFocus() ) setWidgetFocus(this);
{
auto focused_widget = getFocusWidget();
setFocus();
if ( focused_widget )
focused_widget->redraw();
redraw();
if ( getStatusBar() )
getStatusBar()->drawMessage();
}
const int mouse_x = ev->getX(); const int mouse_x = ev->getX();
const int mouse_y = ev->getY(); const int mouse_y = ev->getY();
if ( mouse_x >= int(getWidth()) - nf if ( mouse_x >= int(getWidth()) - nf
&& mouse_x <= int(getWidth()) && mouse_y == 1 ) && mouse_x <= int(getWidth()) && mouse_y == 1 )
{ {
redraw();
if ( list_window.isHidden() ) if ( list_window.isHidden() )
showDropDown(); showDropDown();
else else
@ -633,20 +622,7 @@ void FComboBox::cb_inputFieldSwitch()
} }
else if ( ! is_editable ) else if ( ! is_editable )
{ {
if ( ! hasFocus() ) setWidgetFocus(this);
{
auto focused_widget = getFocusWidget();
setFocus();
if ( focused_widget )
focused_widget->redraw();
redraw();
if ( getStatusBar() )
getStatusBar()->drawMessage();
}
showDropDown(); showDropDown();
} }
} }

View File

@ -184,20 +184,7 @@ void FLabel::onMouseDown (FMouseEvent* ev)
return; return;
} }
if ( ! accel_widget->hasFocus() ) setWidgetFocus(accel_widget); // focus the accelerator widget
{
// focus the accelerator widget
auto focused_widget = getFocusWidget();
accel_widget->setFocus();
if ( focused_widget )
focused_widget->redraw();
accel_widget->redraw();
if ( getStatusBar() )
accel_widget->getStatusBar()->drawMessage();
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -208,19 +195,9 @@ void FLabel::onAccel (FAccelEvent* ev)
if ( ! accel_widget->hasFocus() ) if ( ! accel_widget->hasFocus() )
{ {
auto focused_widget = ev->focusedWidget(); setWidgetFocus(accel_widget);
FFocusEvent in (Event::FocusIn);
if ( focused_widget && focused_widget->isWidget() ) FApplication::sendEvent(accel_widget, &in);
{
accel_widget->setFocus();
focused_widget->redraw();
accel_widget->redraw();
FFocusEvent in (Event::FocusIn);
FApplication::sendEvent(accel_widget, &in);
if ( getStatusBar() )
accel_widget->getStatusBar()->drawMessage();
}
} }
ev->accept(); ev->accept();

View File

@ -328,20 +328,7 @@ void FLineEdit::onMouseDown (FMouseEvent* ev)
if ( ev->getButton() != MouseButton::Left || isReadOnly() ) if ( ev->getButton() != MouseButton::Left || isReadOnly() )
return; return;
if ( ! hasFocus() ) setWidgetFocus(this);
{
auto focused_widget = getFocusWidget();
setFocus();
if ( focused_widget )
focused_widget->redraw();
redraw();
if ( getStatusBar() )
getStatusBar()->drawMessage();
}
const int mouse_x = ev->getX(); const int mouse_x = ev->getX();
const int mouse_y = ev->getY(); const int mouse_y = ev->getY();
const int xmin = 2 + int(char_width_offset); const int xmin = 2 + int(char_width_offset);
@ -494,21 +481,7 @@ void FLineEdit::onAccel (FAccelEvent* ev)
if ( ! isEnabled() ) if ( ! isEnabled() )
return; return;
if ( ! hasFocus() ) setWidgetFocus(this);
{
auto focused_widget = ev->focusedWidget();
if ( focused_widget && focused_widget->isWidget() )
{
setFocus();
focused_widget->redraw();
redraw();
if ( getStatusBar() )
getStatusBar()->drawMessage();
}
}
ev->accept(); ev->accept();
} }
@ -1116,12 +1089,7 @@ inline wchar_t FLineEdit::characterFilter (const wchar_t c) const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FLineEdit::processActivate() void FLineEdit::processActivate()
{ {
if ( ! hasFocus() ) setWidgetFocus(this);
{
setFocus();
redraw();
}
emitCallback("activate"); emitCallback("activate");
} }

View File

@ -313,8 +313,7 @@ void FListBox::onMouseDown (FMouseEvent* ev)
if ( ev->getButton() == MouseButton::Right && ! isMultiSelection() ) if ( ev->getButton() == MouseButton::Right && ! isMultiSelection() )
return; return;
getWidgetFocus(); setWidgetFocus(this);
const int yoffset_before = yoffset; const int yoffset_before = yoffset;
const std::size_t current_before = current; const std::size_t current_before = current;
const int mouse_x = ev->getX(); const int mouse_x = ev->getX();
@ -1104,22 +1103,6 @@ void FListBox::recalculateVerticalBar (std::size_t element_count) const
} }
} }
//----------------------------------------------------------------------
inline void FListBox::getWidgetFocus()
{
if ( hasFocus() )
return;
auto focused_widget = getFocusWidget();
setFocus();
if ( focused_widget )
focused_widget->redraw();
if ( getStatusBar() )
getStatusBar()->drawMessage();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::multiSelection (std::size_t pos) void FListBox::multiSelection (std::size_t pos)
{ {

View File

@ -1006,18 +1006,7 @@ void FListView::onMouseDown (FMouseEvent* ev)
return; return;
} }
if ( ! hasFocus() ) setWidgetFocus(this);
{
auto focused_widget = getFocusWidget();
setFocus();
if ( focused_widget )
focused_widget->redraw();
if ( getStatusBar() )
getStatusBar()->drawMessage();
}
const int mouse_x = ev->getX(); const int mouse_x = ev->getX();
const int mouse_y = ev->getY(); const int mouse_y = ev->getY();
first_line_position_before = first_visible_line.getPosition(); first_line_position_before = first_visible_line.getPosition();

View File

@ -25,6 +25,7 @@
#include "final/fevent.h" #include "final/fevent.h"
#include "final/fscrollbar.h" #include "final/fscrollbar.h"
#include "final/fsize.h" #include "final/fsize.h"
#include "final/fstatusbar.h"
#include "final/fwidgetcolors.h" #include "final/fwidgetcolors.h"
namespace finalcut namespace finalcut
@ -246,6 +247,8 @@ void FScrollbar::onMouseDown (FMouseEvent* ev)
&& ev->getButton() != MouseButton::Middle ) && ev->getButton() != MouseButton::Middle )
return; return;
setWidgetFocus(getParentWidget());
if ( min == max ) if ( min == max )
return; return;

View File

@ -419,19 +419,7 @@ void FSpinBox::processChanged() const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FSpinBox::forceFocus() void FSpinBox::forceFocus()
{ {
if ( hasFocus() ) setWidgetFocus(this);
return;
auto focused_widget = getFocusWidget();
setFocus();
if ( focused_widget )
focused_widget->redraw();
redraw();
if ( getStatusBar() )
getStatusBar()->drawMessage();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -348,18 +348,7 @@ void FTextView::onMouseDown (FMouseEvent* ev)
if ( ev->getButton() != MouseButton::Left ) if ( ev->getButton() != MouseButton::Left )
return; return;
if ( ! hasFocus() ) setWidgetFocus(this);
{
FWidget* focused_widget = getFocusWidget();
setFocus();
if ( focused_widget )
focused_widget->redraw();
if ( getStatusBar() )
getStatusBar()->drawMessage();
}
auto parent = getParentWidget(); auto parent = getParentWidget();
if ( ! parent ) if ( ! parent )
@ -374,7 +363,6 @@ void FTextView::onMouseDown (FMouseEvent* ev)
const auto b = ev->getButton(); const auto b = ev->getButton();
const auto& tp = ev->getTermPos(); const auto& tp = ev->getTermPos();
const auto& p = parent->termToWidgetPos(tp); const auto& p = parent->termToWidgetPos(tp);
parent->setFocus();
const auto& _ev = \ const auto& _ev = \
std::make_shared<FMouseEvent>(Event::MouseDown, p, tp, b); std::make_shared<FMouseEvent>(Event::MouseDown, p, tp, b);
FApplication::sendEvent (parent, _ev.get()); FApplication::sendEvent (parent, _ev.get());
@ -395,7 +383,6 @@ void FTextView::onMouseUp (FMouseEvent* ev)
const auto b = ev->getButton(); const auto b = ev->getButton();
const auto& tp = ev->getTermPos(); const auto& tp = ev->getTermPos();
const auto& p = parent->termToWidgetPos(tp); const auto& p = parent->termToWidgetPos(tp);
parent->setFocus();
const auto& _ev = \ const auto& _ev = \
std::make_shared<FMouseEvent>(Event::MouseUp, p, tp, b); std::make_shared<FMouseEvent>(Event::MouseUp, p, tp, b);
FApplication::sendEvent (parent, _ev.get()); FApplication::sendEvent (parent, _ev.get());
@ -420,7 +407,6 @@ void FTextView::onMouseMove (FMouseEvent* ev)
const auto b = ev->getButton(); const auto b = ev->getButton();
const auto& tp = ev->getTermPos(); const auto& tp = ev->getTermPos();
const auto& p = parent->termToWidgetPos(tp); const auto& p = parent->termToWidgetPos(tp);
parent->setFocus();
const auto& _ev = \ const auto& _ev = \
std::make_shared<FMouseEvent>(Event::MouseMove, p, tp, b); std::make_shared<FMouseEvent>(Event::MouseMove, p, tp, b);
FApplication::sendEvent (parent, _ev.get()); FApplication::sendEvent (parent, _ev.get());

View File

@ -210,19 +210,7 @@ void FToggleButton::onMouseDown (FMouseEvent* ev)
if ( ev->getButton() != MouseButton::Left ) if ( ev->getButton() != MouseButton::Left )
return; return;
if ( hasFocus() ) setWidgetFocus(this);
return;
auto focused_widget = getFocusWidget();
setFocus();
if ( focused_widget )
focused_widget->redraw();
redraw();
if ( getStatusBar() )
getStatusBar()->drawMessage();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -22,6 +22,7 @@
#include "final/fapplication.h" #include "final/fapplication.h"
#include "final/fcolorpair.h" #include "final/fcolorpair.h"
#include "final/fstatusbar.h"
#include "final/fstyle.h" #include "final/fstyle.h"
#include "final/fwidget.h" #include "final/fwidget.h"
#include "final/fwidgetcolors.h" #include "final/fwidgetcolors.h"
@ -142,6 +143,24 @@ void setHotkeyViaString (FWidget* w, const FString& text)
w->delAccelerator(); w->delAccelerator();
} }
//----------------------------------------------------------------------
void setWidgetFocus (FWidget* widget)
{
if ( ! widget || widget->hasFocus() )
return;
auto focused_widget = FWidget::getFocusWidget();
widget->setFocus();
if ( focused_widget && focused_widget->isWidget() ) // old focused widget
focused_widget->redraw();
widget->redraw();
if ( FWidget::getStatusBar() )
FWidget::getStatusBar()->drawMessage();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void drawShadow (FWidget* w) void drawShadow (FWidget* w)
{ {

View File

@ -311,7 +311,6 @@ class FListBox : public FWidget
void updateDrawing (bool, bool); void updateDrawing (bool, bool);
void recalculateHorizontalBar (std::size_t, bool); void recalculateHorizontalBar (std::size_t, bool);
void recalculateVerticalBar (std::size_t) const; void recalculateVerticalBar (std::size_t) const;
void getWidgetFocus();
void multiSelection (std::size_t); void multiSelection (std::size_t);
void multiSelectionUpTo (std::size_t); void multiSelectionUpTo (std::size_t);
void wheelUp (int); void wheelUp (int);

View File

@ -100,7 +100,7 @@ class FLog : public std::stringbuf
int sync() override; int sync() override;
const LogLevel& getLevel() const; const LogLevel& getLevel() const;
LogLevel& setLevel(); LogLevel& setLevel();
const LineEnding& getEnding(); const LineEnding& getEnding() const;
LineEnding& setEnding(); LineEnding& setEnding();
private: private:
@ -151,7 +151,7 @@ inline FLog::LogLevel& FLog::setLevel()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline const FLog::LineEnding& FLog::getEnding() inline const FLog::LineEnding& FLog::getEnding() const
{ {
return end_of_line; return end_of_line;
} }

View File

@ -510,6 +510,7 @@ bool isFocusPrevKey (const FKey);
FKey getHotkey (const FString&); FKey getHotkey (const FString&);
std::size_t getHotkeyPos (const FString& src, FString& dest); std::size_t getHotkeyPos (const FString& src, FString& dest);
void setHotkeyViaString (FWidget*, const FString&); void setHotkeyViaString (FWidget*, const FString&);
void setWidgetFocus (FWidget*);
void drawShadow (FWidget*); void drawShadow (FWidget*);
void drawTransparentShadow (FWidget*); void drawTransparentShadow (FWidget*);
void drawBlockShadow (FWidget*); void drawBlockShadow (FWidget*);