Code optimization at widget focus
This commit is contained in:
parent
8d54e1c11f
commit
9ba7fc6178
|
@ -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>
|
||||
* Fixed mutex deadlock in FLogger
|
||||
|
||||
|
|
|
@ -284,18 +284,7 @@ void FButton::onMouseDown (FMouseEvent* ev)
|
|||
return;
|
||||
}
|
||||
|
||||
if ( ! hasFocus() )
|
||||
{
|
||||
auto focused_widget = getFocusWidget();
|
||||
setFocus();
|
||||
|
||||
if ( focused_widget )
|
||||
focused_widget->redraw();
|
||||
|
||||
if ( getStatusBar() )
|
||||
getStatusBar()->drawMessage();
|
||||
}
|
||||
|
||||
setWidgetFocus(this);
|
||||
const FPoint tPos{ev->getTermPos()};
|
||||
|
||||
if ( getTermGeometry().contains(tPos) )
|
||||
|
|
|
@ -396,26 +396,15 @@ void FComboBox::onMouseDown (FMouseEvent* ev)
|
|||
if ( ev->getButton() != MouseButton::Left )
|
||||
return;
|
||||
|
||||
if ( ! hasFocus() )
|
||||
{
|
||||
auto focused_widget = getFocusWidget();
|
||||
setFocus();
|
||||
|
||||
if ( focused_widget )
|
||||
focused_widget->redraw();
|
||||
|
||||
redraw();
|
||||
|
||||
if ( getStatusBar() )
|
||||
getStatusBar()->drawMessage();
|
||||
}
|
||||
|
||||
setWidgetFocus(this);
|
||||
const int mouse_x = ev->getX();
|
||||
const int mouse_y = ev->getY();
|
||||
|
||||
if ( mouse_x >= int(getWidth()) - nf
|
||||
&& mouse_x <= int(getWidth()) && mouse_y == 1 )
|
||||
{
|
||||
redraw();
|
||||
|
||||
if ( list_window.isHidden() )
|
||||
showDropDown();
|
||||
else
|
||||
|
@ -633,20 +622,7 @@ void FComboBox::cb_inputFieldSwitch()
|
|||
}
|
||||
else if ( ! is_editable )
|
||||
{
|
||||
if ( ! hasFocus() )
|
||||
{
|
||||
auto focused_widget = getFocusWidget();
|
||||
setFocus();
|
||||
|
||||
if ( focused_widget )
|
||||
focused_widget->redraw();
|
||||
|
||||
redraw();
|
||||
|
||||
if ( getStatusBar() )
|
||||
getStatusBar()->drawMessage();
|
||||
}
|
||||
|
||||
setWidgetFocus(this);
|
||||
showDropDown();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -184,20 +184,7 @@ void FLabel::onMouseDown (FMouseEvent* ev)
|
|||
return;
|
||||
}
|
||||
|
||||
if ( ! accel_widget->hasFocus() )
|
||||
{
|
||||
// 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();
|
||||
}
|
||||
setWidgetFocus(accel_widget); // focus the accelerator widget
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -208,19 +195,9 @@ void FLabel::onAccel (FAccelEvent* ev)
|
|||
|
||||
if ( ! accel_widget->hasFocus() )
|
||||
{
|
||||
auto focused_widget = ev->focusedWidget();
|
||||
|
||||
if ( focused_widget && focused_widget->isWidget() )
|
||||
{
|
||||
accel_widget->setFocus();
|
||||
focused_widget->redraw();
|
||||
accel_widget->redraw();
|
||||
setWidgetFocus(accel_widget);
|
||||
FFocusEvent in (Event::FocusIn);
|
||||
FApplication::sendEvent(accel_widget, &in);
|
||||
|
||||
if ( getStatusBar() )
|
||||
accel_widget->getStatusBar()->drawMessage();
|
||||
}
|
||||
}
|
||||
|
||||
ev->accept();
|
||||
|
|
|
@ -328,20 +328,7 @@ void FLineEdit::onMouseDown (FMouseEvent* ev)
|
|||
if ( ev->getButton() != MouseButton::Left || isReadOnly() )
|
||||
return;
|
||||
|
||||
if ( ! hasFocus() )
|
||||
{
|
||||
auto focused_widget = getFocusWidget();
|
||||
setFocus();
|
||||
|
||||
if ( focused_widget )
|
||||
focused_widget->redraw();
|
||||
|
||||
redraw();
|
||||
|
||||
if ( getStatusBar() )
|
||||
getStatusBar()->drawMessage();
|
||||
}
|
||||
|
||||
setWidgetFocus(this);
|
||||
const int mouse_x = ev->getX();
|
||||
const int mouse_y = ev->getY();
|
||||
const int xmin = 2 + int(char_width_offset);
|
||||
|
@ -494,21 +481,7 @@ void FLineEdit::onAccel (FAccelEvent* ev)
|
|||
if ( ! isEnabled() )
|
||||
return;
|
||||
|
||||
if ( ! hasFocus() )
|
||||
{
|
||||
auto focused_widget = ev->focusedWidget();
|
||||
|
||||
if ( focused_widget && focused_widget->isWidget() )
|
||||
{
|
||||
setFocus();
|
||||
focused_widget->redraw();
|
||||
redraw();
|
||||
|
||||
if ( getStatusBar() )
|
||||
getStatusBar()->drawMessage();
|
||||
}
|
||||
}
|
||||
|
||||
setWidgetFocus(this);
|
||||
ev->accept();
|
||||
}
|
||||
|
||||
|
@ -1116,12 +1089,7 @@ inline wchar_t FLineEdit::characterFilter (const wchar_t c) const
|
|||
//----------------------------------------------------------------------
|
||||
void FLineEdit::processActivate()
|
||||
{
|
||||
if ( ! hasFocus() )
|
||||
{
|
||||
setFocus();
|
||||
redraw();
|
||||
}
|
||||
|
||||
setWidgetFocus(this);
|
||||
emitCallback("activate");
|
||||
}
|
||||
|
||||
|
|
|
@ -313,8 +313,7 @@ void FListBox::onMouseDown (FMouseEvent* ev)
|
|||
if ( ev->getButton() == MouseButton::Right && ! isMultiSelection() )
|
||||
return;
|
||||
|
||||
getWidgetFocus();
|
||||
|
||||
setWidgetFocus(this);
|
||||
const int yoffset_before = yoffset;
|
||||
const std::size_t current_before = current;
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -1006,18 +1006,7 @@ void FListView::onMouseDown (FMouseEvent* ev)
|
|||
return;
|
||||
}
|
||||
|
||||
if ( ! hasFocus() )
|
||||
{
|
||||
auto focused_widget = getFocusWidget();
|
||||
setFocus();
|
||||
|
||||
if ( focused_widget )
|
||||
focused_widget->redraw();
|
||||
|
||||
if ( getStatusBar() )
|
||||
getStatusBar()->drawMessage();
|
||||
}
|
||||
|
||||
setWidgetFocus(this);
|
||||
const int mouse_x = ev->getX();
|
||||
const int mouse_y = ev->getY();
|
||||
first_line_position_before = first_visible_line.getPosition();
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "final/fevent.h"
|
||||
#include "final/fscrollbar.h"
|
||||
#include "final/fsize.h"
|
||||
#include "final/fstatusbar.h"
|
||||
#include "final/fwidgetcolors.h"
|
||||
|
||||
namespace finalcut
|
||||
|
@ -246,6 +247,8 @@ void FScrollbar::onMouseDown (FMouseEvent* ev)
|
|||
&& ev->getButton() != MouseButton::Middle )
|
||||
return;
|
||||
|
||||
setWidgetFocus(getParentWidget());
|
||||
|
||||
if ( min == max )
|
||||
return;
|
||||
|
||||
|
|
|
@ -419,19 +419,7 @@ void FSpinBox::processChanged() const
|
|||
//----------------------------------------------------------------------
|
||||
void FSpinBox::forceFocus()
|
||||
{
|
||||
if ( hasFocus() )
|
||||
return;
|
||||
|
||||
auto focused_widget = getFocusWidget();
|
||||
setFocus();
|
||||
|
||||
if ( focused_widget )
|
||||
focused_widget->redraw();
|
||||
|
||||
redraw();
|
||||
|
||||
if ( getStatusBar() )
|
||||
getStatusBar()->drawMessage();
|
||||
setWidgetFocus(this);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
|
|
@ -348,18 +348,7 @@ void FTextView::onMouseDown (FMouseEvent* ev)
|
|||
if ( ev->getButton() != MouseButton::Left )
|
||||
return;
|
||||
|
||||
if ( ! hasFocus() )
|
||||
{
|
||||
FWidget* focused_widget = getFocusWidget();
|
||||
setFocus();
|
||||
|
||||
if ( focused_widget )
|
||||
focused_widget->redraw();
|
||||
|
||||
if ( getStatusBar() )
|
||||
getStatusBar()->drawMessage();
|
||||
}
|
||||
|
||||
setWidgetFocus(this);
|
||||
auto parent = getParentWidget();
|
||||
|
||||
if ( ! parent )
|
||||
|
@ -374,7 +363,6 @@ void FTextView::onMouseDown (FMouseEvent* ev)
|
|||
const auto b = ev->getButton();
|
||||
const auto& tp = ev->getTermPos();
|
||||
const auto& p = parent->termToWidgetPos(tp);
|
||||
parent->setFocus();
|
||||
const auto& _ev = \
|
||||
std::make_shared<FMouseEvent>(Event::MouseDown, p, tp, b);
|
||||
FApplication::sendEvent (parent, _ev.get());
|
||||
|
@ -395,7 +383,6 @@ void FTextView::onMouseUp (FMouseEvent* ev)
|
|||
const auto b = ev->getButton();
|
||||
const auto& tp = ev->getTermPos();
|
||||
const auto& p = parent->termToWidgetPos(tp);
|
||||
parent->setFocus();
|
||||
const auto& _ev = \
|
||||
std::make_shared<FMouseEvent>(Event::MouseUp, p, tp, b);
|
||||
FApplication::sendEvent (parent, _ev.get());
|
||||
|
@ -420,7 +407,6 @@ void FTextView::onMouseMove (FMouseEvent* ev)
|
|||
const auto b = ev->getButton();
|
||||
const auto& tp = ev->getTermPos();
|
||||
const auto& p = parent->termToWidgetPos(tp);
|
||||
parent->setFocus();
|
||||
const auto& _ev = \
|
||||
std::make_shared<FMouseEvent>(Event::MouseMove, p, tp, b);
|
||||
FApplication::sendEvent (parent, _ev.get());
|
||||
|
|
|
@ -210,19 +210,7 @@ void FToggleButton::onMouseDown (FMouseEvent* ev)
|
|||
if ( ev->getButton() != MouseButton::Left )
|
||||
return;
|
||||
|
||||
if ( hasFocus() )
|
||||
return;
|
||||
|
||||
auto focused_widget = getFocusWidget();
|
||||
setFocus();
|
||||
|
||||
if ( focused_widget )
|
||||
focused_widget->redraw();
|
||||
|
||||
redraw();
|
||||
|
||||
if ( getStatusBar() )
|
||||
getStatusBar()->drawMessage();
|
||||
setWidgetFocus(this);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include "final/fapplication.h"
|
||||
#include "final/fcolorpair.h"
|
||||
#include "final/fstatusbar.h"
|
||||
#include "final/fstyle.h"
|
||||
#include "final/fwidget.h"
|
||||
#include "final/fwidgetcolors.h"
|
||||
|
@ -142,6 +143,24 @@ void setHotkeyViaString (FWidget* w, const FString& text)
|
|||
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)
|
||||
{
|
||||
|
|
|
@ -311,7 +311,6 @@ class FListBox : public FWidget
|
|||
void updateDrawing (bool, bool);
|
||||
void recalculateHorizontalBar (std::size_t, bool);
|
||||
void recalculateVerticalBar (std::size_t) const;
|
||||
void getWidgetFocus();
|
||||
void multiSelection (std::size_t);
|
||||
void multiSelectionUpTo (std::size_t);
|
||||
void wheelUp (int);
|
||||
|
|
|
@ -100,7 +100,7 @@ class FLog : public std::stringbuf
|
|||
int sync() override;
|
||||
const LogLevel& getLevel() const;
|
||||
LogLevel& setLevel();
|
||||
const LineEnding& getEnding();
|
||||
const LineEnding& getEnding() const;
|
||||
LineEnding& setEnding();
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -510,6 +510,7 @@ bool isFocusPrevKey (const FKey);
|
|||
FKey getHotkey (const FString&);
|
||||
std::size_t getHotkeyPos (const FString& src, FString& dest);
|
||||
void setHotkeyViaString (FWidget*, const FString&);
|
||||
void setWidgetFocus (FWidget*);
|
||||
void drawShadow (FWidget*);
|
||||
void drawTransparentShadow (FWidget*);
|
||||
void drawBlockShadow (FWidget*);
|
||||
|
|
Loading…
Reference in New Issue