2015-12-24 02:37:01 +01:00
|
|
|
// File: term-attributes.cpp
|
|
|
|
|
2017-08-24 00:47:35 +02:00
|
|
|
#include "fapplication.h"
|
2016-01-08 01:00:05 +01:00
|
|
|
#include "fbutton.h"
|
2015-12-24 02:37:01 +01:00
|
|
|
#include "fdialog.h"
|
|
|
|
#include "fmessagebox.h"
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class AttribDlg
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
class AttribDlg : public FDialog
|
|
|
|
{
|
|
|
|
public:
|
2016-09-30 04:55:28 +02:00
|
|
|
// Constructor
|
|
|
|
explicit AttribDlg (FWidget* = 0);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2016-09-30 04:55:28 +02:00
|
|
|
// Destructor
|
|
|
|
~AttribDlg();
|
|
|
|
|
|
|
|
// Event handlers
|
2015-12-24 02:37:01 +01:00
|
|
|
void onAccel (FAccelEvent*);
|
2016-01-10 00:56:52 +01:00
|
|
|
void onWheel (FWheelEvent*);
|
2015-12-24 02:37:01 +01:00
|
|
|
void onClose (FCloseEvent*);
|
2016-09-30 04:55:28 +02:00
|
|
|
|
|
|
|
// Callback methods
|
2017-02-24 00:30:07 +01:00
|
|
|
void cb_next (FWidget* = 0, data_ptr = 0);
|
|
|
|
void cb_back (FWidget* = 0, data_ptr = 0);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
// Data Members
|
|
|
|
short bgcolor;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Disable copy constructor
|
|
|
|
AttribDlg (const AttribDlg&);
|
|
|
|
// Disable assignment operator (=)
|
|
|
|
AttribDlg& operator = (const AttribDlg&);
|
|
|
|
|
|
|
|
// Method
|
|
|
|
void adjustSize();
|
|
|
|
|
|
|
|
// Data Members
|
|
|
|
FButton* next_button;
|
|
|
|
FButton* back_button;
|
|
|
|
|
2015-12-24 02:37:01 +01:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
AttribDlg::AttribDlg (FWidget* parent)
|
|
|
|
: FDialog(parent)
|
2016-11-02 00:37:58 +01:00
|
|
|
, bgcolor(wc.label_bg)
|
2016-01-08 01:00:05 +01:00
|
|
|
, next_button()
|
|
|
|
, back_button()
|
2015-12-24 02:37:01 +01:00
|
|
|
{
|
2016-01-08 01:00:05 +01:00
|
|
|
resetXTermForeground();
|
|
|
|
resetXTermBackground();
|
|
|
|
setText ( "A terminal attributes test ("
|
|
|
|
+ FString(getTermType())
|
|
|
|
+ ")");
|
|
|
|
|
|
|
|
next_button = new FButton("&Next >", this);
|
2017-08-27 09:50:30 +02:00
|
|
|
next_button->setGeometry(getWidth() - 13, getHeight() - 4, 10, 1);
|
2016-01-08 01:00:05 +01:00
|
|
|
next_button->addAccelerator(fc::Fkey_right);
|
|
|
|
back_button = new FButton("< &Back", this);
|
2017-08-27 09:50:30 +02:00
|
|
|
back_button->setGeometry(getWidth() - 25, getHeight() - 4, 10, 1);
|
2016-01-08 01:00:05 +01:00
|
|
|
back_button->addAccelerator(fc::Fkey_left);
|
|
|
|
|
|
|
|
// Add function callbacks
|
|
|
|
next_button->addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
2017-04-09 20:08:53 +02:00
|
|
|
F_METHOD_CALLBACK (this, &AttribDlg::cb_next)
|
2016-01-08 01:00:05 +01:00
|
|
|
);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-01-08 01:00:05 +01:00
|
|
|
back_button->addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
2017-04-09 20:08:53 +02:00
|
|
|
F_METHOD_CALLBACK (this, &AttribDlg::cb_back)
|
2016-01-08 01:00:05 +01:00
|
|
|
);
|
2015-12-24 02:37:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
AttribDlg::~AttribDlg()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void AttribDlg::onAccel (FAccelEvent* ev)
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
ev->accept();
|
|
|
|
}
|
|
|
|
|
2016-01-10 00:56:52 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void AttribDlg::onWheel (FWheelEvent* ev)
|
|
|
|
{
|
|
|
|
int wheel = ev->getWheel();
|
|
|
|
|
2016-01-17 02:57:08 +01:00
|
|
|
if ( wheel == fc::WheelUp )
|
2016-01-10 00:56:52 +01:00
|
|
|
cb_next();
|
2016-01-17 02:57:08 +01:00
|
|
|
else if ( wheel == fc::WheelDown )
|
2016-01-10 00:56:52 +01:00
|
|
|
cb_back();
|
|
|
|
}
|
|
|
|
|
2015-12-24 02:37:01 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void AttribDlg::onClose (FCloseEvent* ev)
|
|
|
|
{
|
|
|
|
int ret = FMessageBox::info ( this, "Quit"
|
|
|
|
, "Do you really want\n"
|
|
|
|
"to quit the program ?"
|
|
|
|
, FMessageBox::Yes
|
|
|
|
, FMessageBox::No );
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-12-24 02:37:01 +01:00
|
|
|
if ( ret == FMessageBox::Yes )
|
|
|
|
ev->accept();
|
|
|
|
else
|
|
|
|
ev->ignore();
|
|
|
|
}
|
|
|
|
|
2016-01-08 01:00:05 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-02-24 00:30:07 +01:00
|
|
|
void AttribDlg::cb_next (FWidget*, data_ptr)
|
2016-01-08 01:00:05 +01:00
|
|
|
{
|
|
|
|
if ( isMonochron() )
|
|
|
|
return;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-01-08 01:00:05 +01:00
|
|
|
bgcolor++;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-01-08 01:00:05 +01:00
|
|
|
if ( bgcolor >= getMaxColor() )
|
2016-01-10 00:56:52 +01:00
|
|
|
bgcolor = fc::Default;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-01-08 01:00:05 +01:00
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-02-24 00:30:07 +01:00
|
|
|
void AttribDlg::cb_back (FWidget*, data_ptr)
|
2016-01-08 01:00:05 +01:00
|
|
|
{
|
|
|
|
if ( isMonochron() )
|
|
|
|
return;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-01-08 01:00:05 +01:00
|
|
|
bgcolor--;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-01-10 00:56:52 +01:00
|
|
|
if ( bgcolor < fc::Default )
|
2016-01-08 01:00:05 +01:00
|
|
|
bgcolor = short(getMaxColor() - 1);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-01-08 01:00:05 +01:00
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
2015-12-24 02:37:01 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void AttribDlg::adjustSize()
|
|
|
|
{
|
2017-08-27 09:50:30 +02:00
|
|
|
int x = ((getParentWidget()->getWidth() - getWidth()) / 2);
|
|
|
|
int y = ((getParentWidget()->getHeight() - getHeight()) / 2) + 1;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-01-17 02:57:08 +01:00
|
|
|
if ( x < 1 )
|
|
|
|
x = 1;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-01-17 02:57:08 +01:00
|
|
|
if ( y < 1 )
|
|
|
|
y = 1;
|
2016-01-08 01:00:05 +01:00
|
|
|
|
|
|
|
setGeometry(x, y, 69, 21, false);
|
2017-08-27 09:50:30 +02:00
|
|
|
next_button->setGeometry(getWidth() - 13, getHeight() - 4, 10, 1, false);
|
|
|
|
back_button->setGeometry(getWidth() - 25, getHeight() - 4, 10, 1, false);
|
2015-12-24 02:37:01 +01:00
|
|
|
FDialog::adjustSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class AttribDemo
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
class AttribDemo : public FWidget
|
|
|
|
{
|
|
|
|
public:
|
2016-09-30 04:55:28 +02:00
|
|
|
// Constructor
|
|
|
|
explicit AttribDemo (FWidget* = 0);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2016-09-30 04:55:28 +02:00
|
|
|
// Destructor
|
|
|
|
~AttribDemo()
|
2015-12-24 02:37:01 +01:00
|
|
|
{ }
|
2016-09-30 04:55:28 +02:00
|
|
|
|
|
|
|
// Event handler
|
2016-01-10 00:56:52 +01:00
|
|
|
void onWheel (FWheelEvent* ev)
|
|
|
|
{
|
2016-07-03 20:08:39 +02:00
|
|
|
AttribDlg* p = dynamic_cast<AttribDlg*>(getParentWidget());
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2016-01-10 06:47:40 +01:00
|
|
|
if ( p )
|
|
|
|
p->onWheel(ev);
|
2016-01-10 00:56:52 +01:00
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Methods
|
|
|
|
void printColorLine();
|
|
|
|
void printAltCharset();
|
|
|
|
void draw();
|
|
|
|
|
|
|
|
// Data Member
|
|
|
|
int colors;
|
2015-12-24 02:37:01 +01:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
2016-01-08 01:00:05 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
AttribDemo::AttribDemo (FWidget* parent)
|
|
|
|
: FWidget(parent)
|
|
|
|
, colors(getMaxColor())
|
|
|
|
{
|
|
|
|
if ( isMonochron() )
|
|
|
|
colors = 1;
|
|
|
|
else if ( colors > 16 )
|
|
|
|
colors = 16;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-01-08 01:00:05 +01:00
|
|
|
unsetFocusable();
|
|
|
|
}
|
|
|
|
|
2015-12-24 02:37:01 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void AttribDemo::printColorLine()
|
|
|
|
{
|
2016-01-08 01:00:05 +01:00
|
|
|
AttribDlg* parent = static_cast<AttribDlg*>(getParent());
|
|
|
|
|
2017-08-27 09:50:30 +02:00
|
|
|
for (short color = 0; color < colors; color++)
|
2015-12-24 02:37:01 +01:00
|
|
|
{
|
2016-01-08 01:00:05 +01:00
|
|
|
setColor (color, parent->bgcolor);
|
2015-12-24 02:37:01 +01:00
|
|
|
print (" # ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-08 01:00:05 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void AttribDemo::printAltCharset()
|
|
|
|
{
|
|
|
|
AttribDlg* parent = static_cast<AttribDlg*>(getParent());
|
|
|
|
|
|
|
|
if ( ! isMonochron() )
|
|
|
|
setColor (wc.label_fg, wc.label_bg);
|
|
|
|
|
2016-10-11 04:57:36 +02:00
|
|
|
setPrintPos (1,1);
|
2016-01-08 01:00:05 +01:00
|
|
|
print("alternate charset: ");
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-01-10 00:56:52 +01:00
|
|
|
if ( parent->bgcolor == fc::Default )
|
2016-01-08 01:00:05 +01:00
|
|
|
{
|
2016-01-10 00:56:52 +01:00
|
|
|
setColor (fc::Default, fc::Default);
|
2016-01-08 01:00:05 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( parent->bgcolor == 0 || parent->bgcolor == 16 )
|
|
|
|
setColor (fc::White, parent->bgcolor);
|
|
|
|
else
|
|
|
|
setColor (fc::Black, parent->bgcolor);
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-01-08 01:00:05 +01:00
|
|
|
setAltCharset();
|
|
|
|
print("`abcdefghijklmnopqrstuvwxyz{|}~");
|
|
|
|
unsetAltCharset();
|
|
|
|
print(" ");
|
|
|
|
}
|
|
|
|
|
2015-12-24 02:37:01 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void AttribDemo::draw()
|
|
|
|
{
|
2016-01-08 01:00:05 +01:00
|
|
|
// test alternate character set
|
|
|
|
printAltCharset();
|
|
|
|
|
2017-08-27 09:50:30 +02:00
|
|
|
for (int y = 0; y < getParentWidget()->getHeight() - 7; y++)
|
2015-12-24 02:37:01 +01:00
|
|
|
{
|
2017-08-27 09:50:30 +02:00
|
|
|
setPrintPos (1, 2 + y);
|
2016-01-08 01:00:05 +01:00
|
|
|
|
|
|
|
if ( ! isMonochron() )
|
|
|
|
setColor (wc.label_fg, wc.label_bg);
|
|
|
|
|
|
|
|
switch (y)
|
2015-12-24 02:37:01 +01:00
|
|
|
{
|
2016-01-08 01:00:05 +01:00
|
|
|
case 0:
|
|
|
|
print(" Dim: ");
|
|
|
|
setDim();
|
|
|
|
printColorLine();
|
|
|
|
unsetDim();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
print(" Normal: ");
|
|
|
|
setNormal();
|
|
|
|
printColorLine();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
print(" Bold: ");
|
|
|
|
setBold();
|
|
|
|
printColorLine();
|
|
|
|
unsetBold();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
print(" Bold+Dim: ");
|
|
|
|
setBold();
|
|
|
|
setDim();
|
|
|
|
printColorLine();
|
|
|
|
unsetDim();
|
|
|
|
unsetBold();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
print(" Italic: ");
|
|
|
|
setItalic();
|
|
|
|
printColorLine();
|
|
|
|
unsetItalic();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
print(" Underline: ");
|
|
|
|
setUnderline();
|
|
|
|
printColorLine();
|
|
|
|
unsetUnderline();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
print(" Double underline: ");
|
|
|
|
setDoubleUnderline();
|
|
|
|
printColorLine();
|
|
|
|
unsetDoubleUnderline();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
print(" Crossed-out: ");
|
|
|
|
setCrossedOut();
|
|
|
|
printColorLine();
|
|
|
|
unsetCrossedOut();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
print(" Blink: ");
|
|
|
|
setBlink();
|
|
|
|
printColorLine();
|
|
|
|
unsetBlink();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 9:
|
|
|
|
print(" Reverse: ");
|
|
|
|
setReverse();
|
|
|
|
printColorLine();
|
|
|
|
unsetReverse();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 10:
|
|
|
|
print(" Standout: ");
|
|
|
|
setStandout();
|
|
|
|
printColorLine();
|
|
|
|
unsetStandout();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 11:
|
|
|
|
print(" Invisible: ");
|
|
|
|
setInvisible();
|
|
|
|
printColorLine();
|
|
|
|
unsetInvisible();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 12:
|
|
|
|
print(" Protected: ");
|
|
|
|
setProtected();
|
|
|
|
printColorLine();
|
|
|
|
unsetProtected();
|
2015-12-24 02:37:01 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-08 01:00:05 +01:00
|
|
|
if ( ! isMonochron() )
|
|
|
|
setColor(wc.label_fg, wc.label_bg);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-10-11 04:57:36 +02:00
|
|
|
setPrintPos (1, 15);
|
2016-01-17 02:57:08 +01:00
|
|
|
short bg = static_cast<AttribDlg*>(getParent())->bgcolor;
|
|
|
|
print (" Background color:");
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-01-17 02:57:08 +01:00
|
|
|
if ( bg == fc::Default )
|
2016-01-17 23:37:52 +01:00
|
|
|
print (" default");
|
2016-01-17 02:57:08 +01:00
|
|
|
else
|
|
|
|
printf ( " %d", bg);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-10-11 04:57:36 +02:00
|
|
|
setPrintPos (16, 17);
|
2016-01-08 01:00:05 +01:00
|
|
|
print ("Change background color ->");
|
2015-12-24 02:37:01 +01:00
|
|
|
}
|
|
|
|
|
2016-01-10 00:56:52 +01:00
|
|
|
|
2015-12-24 02:37:01 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// main part
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int main (int argc, char* argv[])
|
|
|
|
{
|
|
|
|
// Create the application object
|
|
|
|
FApplication app (argc, argv);
|
|
|
|
|
|
|
|
// Create a dialog box object.
|
|
|
|
// This object will be automatically deleted by
|
|
|
|
// the parent object "app" (FObject destructor).
|
|
|
|
AttribDlg* dialog = new AttribDlg(&app);
|
|
|
|
|
2016-01-08 01:00:05 +01:00
|
|
|
dialog->setGeometry (6, 2, 69, 21);
|
2015-12-24 02:37:01 +01:00
|
|
|
dialog->addAccelerator('q'); // press 'q' to quit
|
|
|
|
dialog->setShadow();
|
|
|
|
|
|
|
|
AttribDemo* demo = new AttribDemo(dialog);
|
2016-01-08 01:00:05 +01:00
|
|
|
demo->setGeometry (1,1,67,19);
|
2015-12-24 02:37:01 +01:00
|
|
|
|
|
|
|
app.setMainWidget(dialog);
|
|
|
|
dialog->show();
|
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
}
|