2015-10-29 21:10:50 +01:00
|
|
|
// File: keyboard.cpp
|
|
|
|
|
|
|
|
#include "final.h"
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class keyboard
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class keyboard : public FWidget
|
|
|
|
{
|
|
|
|
public:
|
2016-09-30 04:55:28 +02:00
|
|
|
// Constructor
|
2015-10-29 21:10:50 +01:00
|
|
|
explicit keyboard (FWidget* = 0);
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2015-10-29 21:10:50 +01:00
|
|
|
protected:
|
2016-09-30 04:55:28 +02:00
|
|
|
// Event handlers
|
2015-10-29 21:10:50 +01:00
|
|
|
void onKeyPress (FKeyEvent*);
|
|
|
|
void onAccel (FAccelEvent*);
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2016-01-08 01:00:05 +01:00
|
|
|
void draw();
|
2015-10-29 21:10:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
keyboard::keyboard (FWidget* parent)
|
|
|
|
: FWidget(parent)
|
|
|
|
{
|
2016-01-08 01:00:05 +01:00
|
|
|
resetXTermForeground();
|
|
|
|
resetXTermBackground();
|
2016-01-10 00:56:52 +01:00
|
|
|
wc.term_fg = fc::Default;
|
|
|
|
wc.term_bg = fc::Default;
|
2015-10-29 21:10:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void keyboard::onKeyPress (FKeyEvent* ev)
|
|
|
|
{
|
|
|
|
int key_id = ev->key();
|
2016-10-08 02:54:32 +02:00
|
|
|
bool is_last_line = false;
|
|
|
|
|
|
|
|
if ( getPrintPos().getY() == getLineNumber() )
|
|
|
|
is_last_line = true;
|
|
|
|
|
|
|
|
printf ("Key %s (id %d)\n", getKeyName(key_id).c_str(), key_id);
|
|
|
|
|
|
|
|
if ( is_last_line )
|
|
|
|
scrollAreaForward (vdesktop);
|
|
|
|
|
|
|
|
setAreaCursor (1, getPrintPos().getY(), true, vdesktop);
|
2015-10-29 21:10:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void keyboard::onAccel (FAccelEvent* ev)
|
|
|
|
{
|
|
|
|
quit();
|
|
|
|
ev->accept();
|
|
|
|
}
|
|
|
|
|
2016-01-08 01:00:05 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void keyboard::draw()
|
|
|
|
{
|
2016-10-11 04:57:36 +02:00
|
|
|
setPrintPos (1,1);
|
2016-01-08 01:00:05 +01:00
|
|
|
print ("---------------\n");
|
|
|
|
print ("Press Q to quit\n");
|
|
|
|
print ("---------------\n");
|
2016-10-08 02:54:32 +02:00
|
|
|
setAreaCursor (1, 4, true, vdesktop);
|
2016-01-08 01:00:05 +01:00
|
|
|
}
|
2015-10-29 21:10:50 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// main part
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int main (int argc, char* argv[])
|
|
|
|
{
|
|
|
|
FApplication app(argc, argv);
|
2016-11-27 00:41:34 +01:00
|
|
|
app.setForegroundColor(fc::Default);
|
|
|
|
app.setBackgroundColor(fc::Default);
|
2016-01-08 01:00:05 +01:00
|
|
|
keyboard key(&app);
|
|
|
|
key.addAccelerator('q');
|
|
|
|
app.setMainWidget(&key);
|
|
|
|
key.show();
|
2015-10-29 21:10:50 +01:00
|
|
|
return app.exec();
|
|
|
|
}
|