Skip to content

Commit

Permalink
KEY_CODE: Refactor KEY_CODE from 'hconsole' lib into 'tools' lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
AmokHuginnsson committed Oct 25, 2018
1 parent 191bc8d commit 392d99c
Show file tree
Hide file tree
Showing 23 changed files with 210 additions and 115 deletions.
4 changes: 2 additions & 2 deletions _aux/msvcxx/emu_unistd.cxx
Expand Up @@ -25,7 +25,7 @@
#include "msvcxx.hxx"
#include "emu_signals.hxx"

#include "hconsole/console.hxx"
#include "tools/keycode.hxx"

using namespace std;
using namespace yaal;
Expand Down Expand Up @@ -539,7 +539,7 @@ DWORD win_read_console_key( void ) {
}
}
break;
} else if ( key == hconsole::KEY<'['>::ctrl ) { // ESC, set flag for later
} else if ( key == KEY<'['>::ctrl ) { // ESC, set flag for later
escSeen = true;
continue;
} else if ( ( key >= 0xD800 ) && ( key <= 0xDBFF ) ) {
Expand Down
29 changes: 20 additions & 9 deletions hconsole/console.cxx
Expand Up @@ -22,6 +22,7 @@ M_VCSID( "$Id: " __TID__ " $" )
#include "hcore/unicode.hxx"
#include "tools/tools.hxx"
#include "tools/hterminal.hxx"
#include "tools/keycode.hxx"
#include "hconsole.hxx"

/* curses system header is polluted with huge number of macros
Expand All @@ -47,7 +48,7 @@ namespace yaal {

namespace hconsole {

static_assert( KEY_CODE::SPECIAL_KEY > KEY_MAX, "ncurses key codes overlap with KEY_CODE codes" );
static_assert( KEY_CODE::BASE > KEY_MAX, "ncurses key codes overlap with KEY_CODE codes" );

#ifdef HAVE_ASCII_GRAPHICS
int GLYPH::ARROW::DOWN;
Expand Down Expand Up @@ -632,12 +633,20 @@ void HConsole::ungetch( int code_ ) {
default:
break;
}
int codes[] = { 0, 0, 0 };
int codeCount( 0 );
if ( code_ >= KEY_CODE::COMMAND_BASE ) {
code_ -= KEY_CODE::COMMAND_BASE;
M_ENSURE( ::ungetch( code_ ) != ERR );
code_ = KEY<>::ctrl_r( _commandComposeCharacter_ );
codes[codeCount ++] = KEY<>::ctrl_r( _commandComposeCharacter_ );
}
if ( code_ >= KEY_CODE::META_BASE ) {
code_ -= KEY_CODE::META_BASE;
codes[codeCount ++] = KEY_CODE::ESCAPE;
}
codes[codeCount ++] = code_;
for ( int i( codeCount - 1 ); i >= 0; -- i ) {
M_ENSURE( ::ungetch( codes[i] ) != ERR );
}
M_ENSURE( ::ungetch( code_ ) != ERR );
if ( ! _event.unique() ) {
notify_keyboard();
}
Expand Down Expand Up @@ -673,7 +682,7 @@ int HConsole::get_key( void ) const {
M_ENSURE( noecho() != ERR );
M_ENSURE( ::fflush( nullptr ) == 0 );
int key( wgetch( static_cast<WINDOW*>( _window ) ) );
M_ASSERT( key < KEY_CODE::SPECIAL_KEY );
M_ASSERT( key < KEY_CODE::BASE );
if ( key == KEY_CODE::ESCAPE ) {
M_ENSURE( nodelay( static_cast<WINDOW*>( _window ), true ) != ERR );
key = wgetch( static_cast<WINDOW*>( _window ) );
Expand Down Expand Up @@ -840,13 +849,15 @@ int HConsole::wait_for_user_input( int& key_, mouse::OMouse& mouse_, int timeOut
int eventType( 0 );
if ( error > 0 ) {
if ( fds[0] != -1 ) {
key_ = get_key(), eventType = EVENT::KEYBOARD;
if ( key_ == KEY_MOUSE )
key_ = get_key();
eventType = EVENT::KEYBOARD;
if ( key_ == KEY_MOUSE ) {
eventType = 0;
}
}
if ( ( key_ == KEY_MOUSE )
|| ( _mouseDes && ( fds[1] != -1 ) ) )
if ( ( key_ == KEY_MOUSE ) || ( _mouseDes && ( fds[1] != -1 ) ) ) {
eventType |= EVENT::MOUSE, static_cast<void>( mouse::mouse_get( mouse_ ) );
}
}
return ( eventType );
M_EPILOG
Expand Down
70 changes: 0 additions & 70 deletions hconsole/console.hxx
Expand Up @@ -19,53 +19,6 @@ namespace yaal {
*/
namespace hconsole {

/*! \brief Special key codes.
*/
struct KEY_CODE {
static int const ESCAPE = 27;
/* Coincidentally KEY_MAX from ncurses is 0777 which is 511. */
static int const SPECIAL_KEY = 0x400;
static int const PAGE_UP = SPECIAL_KEY;
static int const PAGE_DOWN = PAGE_UP + 1;
static int const DOWN = PAGE_DOWN + 1;
static int const UP = DOWN + 1;
static int const LEFT = UP + 1;
static int const RIGHT = LEFT + 1;
static int const HOME = RIGHT + 1;
static int const END = HOME + 1;
static int const DELETE = END + 1;
static int const INSERT = DELETE + 1;
static int const BACKSPACE = INSERT + 1;
static int const F1 = BACKSPACE + 1;
static int const F2 = F1 + 1;
static int const F3 = F2 + 1;
static int const F4 = F3 + 1;
static int const F5 = F4 + 1;
static int const F6 = F5 + 1;
static int const F7 = F6 + 1;
static int const F8 = F7 + 1;
static int const F9 = F8 + 1;
static int const F10 = F9 + 1;
static int const F11 = F10 + 1;
static int const F12 = F11 + 1;
static int const F13 = F12 + 1;
static int const F14 = F13 + 1;
static int const F15 = F14 + 1;
static int const F16 = F15 + 1;
static int const F17 = F16 + 1;
static int const F18 = F17 + 1;
static int const F19 = F18 + 1;
static int const F20 = F19 + 1;
static int const F21 = F20 + 1;
static int const F22 = F21 + 1;
static int const F23 = F22 + 1;
static int const F24 = F23 + 1;
static int const MOUSE = F24 + 1;
static int const CONTROL_BASE = 96;
static int const META_BASE = 0x04000;
static int const COMMAND_BASE = 0x08000;
};

/*! \brief Quasi graphic glyphs.
*/
struct GLYPH {
Expand Down Expand Up @@ -134,29 +87,6 @@ enum class CURSOR {
VERY_VISIBLE
};

/*! \brief Get special key code values.
*
* \tparam code - basic input code.
* \retval meta - META modified code.
* \retval ctrl - CONTROL modified code.
* \retval commercial - CONTROL-x modified code (command).
*/
template<int code = 0>
struct KEY {
static int const meta = code + KEY_CODE::META_BASE;
static int meta_r( int code_ ) {
return ( code_ + KEY_CODE::META_BASE );
}
static int const ctrl = code - KEY_CODE::CONTROL_BASE;
static int ctrl_r( int code_ ) {
return ( code_ - KEY_CODE::CONTROL_BASE );
}
static int const command = code + KEY_CODE::COMMAND_BASE;
static int command_r( int code_ ) {
return ( code_ + KEY_CODE::COMMAND_BASE );
}
};

/*! \brief TUI input events types.
*/
struct EVENT {
Expand Down
1 change: 1 addition & 0 deletions hconsole/hcomboboxwidget.cxx
Expand Up @@ -8,6 +8,7 @@ M_VCSID( "$Id: " __TID__ " $" )
#include "hcomboboxwidget.hxx"
#include "tools/hxml.hxx"
#include "hconsole/hwindow.hxx"
#include "tools/keycode.hxx"

using namespace yaal;
using namespace yaal::hcore;
Expand Down
1 change: 1 addition & 0 deletions hconsole/hdatewidget.cxx
Expand Up @@ -6,6 +6,7 @@
M_VCSID( "$Id: " __ID__ " $" )
M_VCSID( "$Id: " __TID__ " $" )
#include "hdatewidget.hxx"
#include "tools/keycode.hxx"

using namespace yaal::hcore;
using namespace yaal::tools;
Expand Down
6 changes: 4 additions & 2 deletions hconsole/heditwidget.cxx
Expand Up @@ -12,6 +12,7 @@ M_VCSID( "$Id: " __TID__ " $" )
#include "heditwidget.hxx"
#include "hwindow.hxx"
#include "hcore/hlog.hxx"
#include "tools/keycode.hxx"
#include "tools/hxml.hxx"

using namespace yaal::hcore;
Expand Down Expand Up @@ -210,12 +211,13 @@ int HEditWidget::go_to_eow( int length_ ) {

int HEditWidget::kill_line( void ) {
M_PROLOG
if ( ! _readOnly ) {
bool doKill( ! ( _readOnly || _varTmpBuffer.is_empty() ) );
if ( doKill ) {
_varTmpBuffer.set_at( 0, 0_ycp );
_widgetOffset = 0;
_cursorPosition = 0;
}
return ( ! _readOnly ? 0 : 1 );
return ( doKill ? 0 : 1 );
M_EPILOG
}

Expand Down
1 change: 1 addition & 0 deletions hconsole/hlistwidget.cxx
Expand Up @@ -14,6 +14,7 @@ M_VCSID( "$Id: " __TID__ " $" )
#include "hconsole.hxx"
#include "tools/hxml.hxx"
#include "hconsole/hwindow.hxx"
#include "tools/keycode.hxx"
#include "tools/hexpression.hxx"

using namespace yaal;
Expand Down
1 change: 1 addition & 0 deletions hconsole/hlogpad.cxx
Expand Up @@ -4,6 +4,7 @@
M_VCSID( "$Id: " __ID__ " $" )
M_VCSID( "$Id: " __TID__ " $" )
#include "hlogpad.hxx"
#include "tools/keycode.hxx"

using namespace yaal::hcore;
using namespace yaal::tools;
Expand Down
2 changes: 2 additions & 0 deletions hconsole/hmainwindow.cxx
Expand Up @@ -5,8 +5,10 @@ M_VCSID( "$Id: " __ID__ " $" )
M_VCSID( "$Id: " __TID__ " $" )
#include "hmainwindow.hxx"
#include "hcore/memory.hxx"
#include "tools/keycode.hxx"

using namespace yaal::hcore;
using namespace yaal::tools;
using namespace yaal::hconsole::list_widget_helper;

namespace yaal {
Expand Down
1 change: 1 addition & 0 deletions hconsole/hstatusbarwidget.cxx
Expand Up @@ -13,6 +13,7 @@ M_VCSID( "$Id: " __TID__ " $" )
#include "hsearchablewidget.hxx"
#include "hcore/hformat.hxx"
#include "hcore/hlog.hxx"
#include "tools/keycode.hxx"

using namespace yaal::hcore;
using namespace yaal::tools;
Expand Down
1 change: 1 addition & 0 deletions hconsole/htimewidget.cxx
Expand Up @@ -4,6 +4,7 @@
M_VCSID( "$Id: " __ID__ " $" )
M_VCSID( "$Id: " __TID__ " $" )
#include "htimewidget.hxx"
#include "tools/keycode.hxx"

using namespace yaal::hcore;
using namespace yaal::tools;
Expand Down
1 change: 1 addition & 0 deletions hconsole/htreewidget.cxx
Expand Up @@ -7,6 +7,7 @@ M_VCSID( "$Id: " __ID__ " $" )
M_VCSID( "$Id: " __TID__ " $" )
#include "htreewidget.hxx"
#include "hwindow.hxx"
#include "tools/keycode.hxx"

using namespace yaal::hcore;
using namespace yaal::tools;
Expand Down
3 changes: 2 additions & 1 deletion hconsole/htuiprocess.cxx
Expand Up @@ -14,6 +14,7 @@ M_VCSID( "$Id: " __TID__ " $" )
#include "hconsole.hxx"
#include "hmainwindow.hxx"
#include "mouse.hxx"
#include "tools/keycode.hxx"

#ifdef __DEBUGGER_BABUNI__
#include "hcore/hlog.hxx"
Expand Down Expand Up @@ -77,7 +78,7 @@ void HTUIProcess::init_tui( yaal::hcore::HString const& processName_, HWindow::p
register_postprocess_handler( CTRLS_COUNT, ctrls, call( &HTUIProcess::handler_refresh, this, _1 ) );
register_postprocess_handler( KEY<'x'>::command, nullptr, call( &HTUIProcess::handler_quit, this, _1 ) );
if ( _useMouse_ != USE_MOUSE::NO ) {
register_postprocess_handler( KEY_CODE::MOUSE, nullptr, call( &HTUIProcess::handler_mouse, this, _1 ) );
register_preprocess_handler( KEY_CODE::MOUSE, nullptr, call( &HTUIProcess::handler_mouse, this, _1 ) );
}
if ( !! mainWindow_ ) {
mainWindow = mainWindow_;
Expand Down
6 changes: 4 additions & 2 deletions hconsole/hwidget.cxx
Expand Up @@ -98,17 +98,19 @@ HWidget::~HWidget( void ) {
void HWidget::enable( bool enable_ ) {
M_PROLOG
_enabled = enable_;
if ( ! _enabled )
if ( ! _enabled ) {
_focused = false;
}
schedule_repaint();
return;
M_EPILOG
}

int HWidget::process_input( int code_ ) {
M_PROLOG
if ( ! _valid )
if ( ! _valid ) {
update();
}
return ( do_process_input( code_ ) );
M_EPILOG
}
Expand Down
17 changes: 15 additions & 2 deletions hconsole/hwidgetlist.cxx
Expand Up @@ -54,6 +54,16 @@ void HWidgetList::add_widget( HWidget::ptr_t widget_ ) {
M_EPILOG
}

void HWidgetList::sync_focus( void ) {
M_PROLOG
if ( _focused != _list.end() ) {
(*_focused)->enable( true );
(*_focused)->set_focus();
}
return;
M_EPILOG
}

void HWidgetList::refresh_all( bool force_ ) {
M_PROLOG
bool focusedNeedRepaint( (*_focused)->need_repaint() );
Expand All @@ -71,8 +81,9 @@ void HWidgetList::refresh_all( bool force_ ) {

void HWidgetList::update_all( void ) {
M_PROLOG
for ( model_t::iterator it( _list.begin() ), end( _list.end() ); it != end; ++ it )
for ( model_t::iterator it( _list.begin() ), end( _list.end() ); it != end; ++ it ) {
(*it)->update();
}
return;
M_EPILOG
}
Expand All @@ -96,15 +107,17 @@ void HWidgetList::hit_test_all( mouse::OMouse& mouse_ ) {
HWidget* HWidgetList::get_widget_by_no( int offset_ ) {
M_PROLOG
model_t::iterator it = _list.begin();
while ( offset_ -- > 0 )
while ( offset_ -- > 0 ) {
++ it;
}
return ( &**it );
M_EPILOG
}

void HWidgetList::pop_front( void ) {
M_PROLOG
_list.pop_front();
return;
M_EPILOG
}

Expand Down
1 change: 1 addition & 0 deletions hconsole/hwidgetlist.hxx
Expand Up @@ -37,6 +37,7 @@ public:
HWidget* get_widget_by_no( int );
void exchange( int, int );
void reorder_widgets( widget_order_t const& );
void sync_focus( void );
};

typedef yaal::hcore::HExceptionT<HWidgetList> HWidgetListException;
Expand Down
7 changes: 5 additions & 2 deletions hconsole/hwindow.cxx
Expand Up @@ -10,6 +10,7 @@ M_VCSID( "$Id: " __TID__ " $" )
#include "htuiprocess.hxx"
#include "hcore/hlog.hxx"
#include "hwidgetfactory.hxx"
#include "tools/keycode.hxx"

using namespace yaal::hcore;
using namespace yaal::tools;
Expand Down Expand Up @@ -52,6 +53,7 @@ HWindow::~HWindow( void ) {
void HWindow::init( void ) {
M_PROLOG
do_init();
_widgets.sync_focus();
return;
M_EPILOG
}
Expand Down Expand Up @@ -165,8 +167,9 @@ bool HWindow::handler_jump_direct( HEvent const& event_ ) {
* see console.h for details
*/
HWidgetList::cyclic_iterator it = _focusedChild;
if ( keyPress.get_key_code() & 0x0ff00 ) {
_widgets.next_enabled( static_cast<char>( keyPress.get_key_code() ) );
code_point_t::value_type keyCode( static_cast<code_point_t::value_type>( keyPress.get_key_code() ) );
if ( ( keyCode >= KEY_CODE::META_BASE ) && ( keyCode < KEY_CODE::COMMAND_BASE ) ) {
_widgets.next_enabled( static_cast<char>( keyCode ) );
if ( _focusedChild != it ) {
consumed = true;
}
Expand Down

0 comments on commit 392d99c

Please sign in to comment.