From cef8ec09162b679c954cd562cd76d2dc02e13e21 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Mon, 6 Jul 2015 10:50:46 +0200 Subject: [PATCH] Class FSwitch: disable cursor on focus --- src/fswitch.cpp | 11 ++++++----- src/ftogglebutton.cpp | 26 ++++++++++++++++++-------- src/ftogglebutton.h | 1 + test/ui.cpp | 2 +- test/watch.cpp | 4 ++-- 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/fswitch.cpp b/src/fswitch.cpp index d07d5c0a..8a7625a5 100644 --- a/src/fswitch.cpp +++ b/src/fswitch.cpp @@ -34,11 +34,13 @@ FSwitch::~FSwitch() // destructor void FSwitch::draw() { setUpdateVTerm(false); - drawCheckButton(); drawLabel(); + drawCheckButton(); setUpdateVTerm(true); FToggleButton::draw(); + updateTerminal(); + flush_out(); } //---------------------------------------------------------------------- @@ -47,7 +49,7 @@ void FSwitch::drawCheckButton() if ( ! isVisible() ) return; - gotoxy (xpos+xmin-1+switch_offset_pos, ypos+ymin-1); + gotoxy (xpos+xmin-1+switch_offset_pos, ypos+ymin-1); if ( checked ) { @@ -58,6 +60,7 @@ void FSwitch::drawCheckButton() print (" On "); setColor (wc.button_inactive_fg, wc.button_inactive_bg); print (" Off "); + gotoxy (xpos+xmin+2+switch_offset_pos, ypos+ymin-1); } else { @@ -68,6 +71,7 @@ void FSwitch::drawCheckButton() else setColor (wc.button_hotkey_fg, wc.button_active_bg); print (" Off "); + gotoxy (xpos+xmin+6+switch_offset_pos, ypos+ymin-1); } } @@ -98,10 +102,7 @@ void FSwitch::onKeyPress (FKeyEvent* event) } if ( event->isAccepted() ) - { draw(); - updateTerminal(); - } else FToggleButton::onKeyPress(event); } diff --git a/src/ftogglebutton.cpp b/src/ftogglebutton.cpp index cfe06ac3..cd11b77b 100644 --- a/src/ftogglebutton.cpp +++ b/src/ftogglebutton.cpp @@ -151,16 +151,19 @@ void FToggleButton::draw() } } - // set the cursor to the button - setCursorPos (xpos+xmin, ypos+ymin-1); + if ( isRadioButton() || isCheckboxButton() ) + { + // set the cursor to the button + setCursorPos (xpos+xmin, ypos+ymin-1); - if ( isCursorInside() && hasFocus() ) - { - if ( isHiddenCursor() ) - showCursor(); + if ( isCursorInside() && hasFocus() ) + { + if ( isHiddenCursor() ) + showCursor(); + } + else if ( ! isHiddenCursor() ) + hideCursor(); } - else if ( ! isHiddenCursor() ) - hideCursor(); } //---------------------------------------------------------------------- @@ -254,6 +257,13 @@ bool FToggleButton::isRadioButton() const const_cast("FRadioButton") ) == 0 ); } +//---------------------------------------------------------------------- +bool FToggleButton::isCheckboxButton() const +{ + return ( strcmp (getClassName(), + const_cast("FCheckBox") ) == 0 ); +} + //---------------------------------------------------------------------- void FToggleButton::onKeyPress (FKeyEvent* event) { diff --git a/src/ftogglebutton.h b/src/ftogglebutton.h index 190ec1c2..7c4cc058 100644 --- a/src/ftogglebutton.h +++ b/src/ftogglebutton.h @@ -44,6 +44,7 @@ class FToggleButton : public FWidget void processToggle(); FButtonGroup* group() const; bool isRadioButton() const; + bool isCheckboxButton() const; virtual void onKeyPress (FKeyEvent*); public: diff --git a/test/ui.cpp b/test/ui.cpp index cd1d25ec..65c71067 100644 --- a/test/ui.cpp +++ b/test/ui.cpp @@ -286,7 +286,7 @@ MyDialog::MyDialog (FWidget* parent) : FDialog(parent) tagged_count->setGeometry(28, 4, 5, 1); tagged_count->setNumber(0); - FLabel* sum = new FLabel(L"Sum:", this); + FLabel* sum = new FLabel(L"Sum:\n123\n456", this); sum->setGeometry(20, 5, 7, 1); sum->setAlignment(fc::alignRight); diff --git a/test/watch.cpp b/test/watch.cpp index 71227856..6d8a72ee 100644 --- a/test/watch.cpp +++ b/test/watch.cpp @@ -48,7 +48,7 @@ watch::watch (FWidget* parent) : FDialog(parent) setText ("Watch"); setShadow(); int pw = parentWidget()->getWidth(); - setGeometry (1+(pw-22)/2, 3, 22, 12); + setGeometry (1+(pw-22)/2, 3, 22, 13); // Create labels time_label = new FLabel(L"Time", this); @@ -67,7 +67,7 @@ watch::watch (FWidget* parent) : FDialog(parent) // Create button FButton* quit = new FButton(L"&Quit", this); - quit->setGeometry(6, 8, 9, 1); + quit->setGeometry(6, 9, 9, 1); quit->setShadow(); quit->setFocus();