Refactor the VGA attribute controller access code

This commit is contained in:
Markus Gans 2016-10-17 08:44:38 +02:00
parent 00c33a8d61
commit 1613d5bb55
25 changed files with 738 additions and 702 deletions

View File

@ -1,3 +1,6 @@
2016-10-17 Markus Gans <guru.mail@muenster.de>
* Refactor the VGA attribute controller access code
2016-10-15 Markus Gans <guru.mail@muenster.de> 2016-10-15 Markus Gans <guru.mail@muenster.de>
* Each virtual window gets its own virtual print cursor * Each virtual window gets its own virtual print cursor

View File

@ -731,8 +731,9 @@ void FButton::onTimer (FTimerEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButton::onAccel (FAccelEvent* ev) void FButton::onAccel (FAccelEvent* ev)
{ {
if ( isEnabled() ) if ( ! isEnabled() )
{ return;
if ( ! hasFocus() ) if ( ! hasFocus() )
{ {
FWidget* focused_widget = static_cast<FWidget*>(ev->focusedWidget()); FWidget* focused_widget = static_cast<FWidget*>(ev->focusedWidget());
@ -760,7 +761,6 @@ void FButton::onAccel (FAccelEvent* ev)
processClick(); processClick();
ev->accept(); ev->accept();
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButton::onFocusIn (FFocusEvent*) void FButton::onFocusIn (FFocusEvent*)

View File

@ -418,8 +418,9 @@ void FButtonGroup::cb_buttonToggled (FWidget* widget, void*)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FToggleButton* FButtonGroup::getFirstButton() FToggleButton* FButtonGroup::getFirstButton()
{ {
if ( ! buttonlist.empty() ) if ( buttonlist.empty() )
{ return 0;
FButtonGroup::FButtonList::const_iterator iter, end; FButtonGroup::FButtonList::const_iterator iter, end;
iter = buttonlist.begin(); iter = buttonlist.begin();
end = buttonlist.end(); end = buttonlist.end();
@ -431,7 +432,6 @@ FToggleButton* FButtonGroup::getFirstButton()
++iter; ++iter;
} }
}
return 0; return 0;
} }
@ -439,8 +439,9 @@ FToggleButton* FButtonGroup::getFirstButton()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FToggleButton* FButtonGroup::getLastButton() FToggleButton* FButtonGroup::getLastButton()
{ {
if ( ! buttonlist.empty() ) if ( buttonlist.empty() )
{ return 0;
FButtonGroup::FButtonList::const_iterator iter, begin; FButtonGroup::FButtonList::const_iterator iter, begin;
begin = buttonlist.begin(); begin = buttonlist.begin();
iter = buttonlist.end(); iter = buttonlist.end();
@ -453,7 +454,6 @@ FToggleButton* FButtonGroup::getLastButton()
return (*iter); return (*iter);
} }
while ( iter != begin ); while ( iter != begin );
}
return 0; return 0;
} }
@ -461,8 +461,9 @@ FToggleButton* FButtonGroup::getLastButton()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FButtonGroup::hasFocusedButton() bool FButtonGroup::hasFocusedButton()
{ {
if ( ! buttonlist.empty() ) if ( buttonlist.empty() )
{ return false;
FButtonGroup::FButtonList::const_iterator iter, end; FButtonGroup::FButtonList::const_iterator iter, end;
iter = buttonlist.begin(); iter = buttonlist.begin();
end = buttonlist.end(); end = buttonlist.end();
@ -474,7 +475,6 @@ bool FButtonGroup::hasFocusedButton()
++iter; ++iter;
} }
}
return false; return false;
} }
@ -482,8 +482,9 @@ bool FButtonGroup::hasFocusedButton()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FButtonGroup::hasCheckedButton() bool FButtonGroup::hasCheckedButton()
{ {
if ( ! buttonlist.empty() ) if ( buttonlist.empty() )
{ return false;
FButtonGroup::FButtonList::const_iterator iter, end; FButtonGroup::FButtonList::const_iterator iter, end;
iter = buttonlist.begin(); iter = buttonlist.begin();
end = buttonlist.end(); end = buttonlist.end();
@ -495,7 +496,6 @@ bool FButtonGroup::hasCheckedButton()
++iter; ++iter;
} }
}
return false; return false;
} }

View File

@ -48,8 +48,9 @@ void FCheckMenuItem::init (FWidget* parent)
{ {
checkable = true; checkable = true;
if ( parent ) if ( ! parent )
{ return;
if ( isMenu(parent) ) // Parent is menu if ( isMenu(parent) ) // Parent is menu
{ {
FMenu* menu_ptr = dynamic_cast<FMenu*>(parent); FMenu* menu_ptr = dynamic_cast<FMenu*>(parent);
@ -58,7 +59,6 @@ void FCheckMenuItem::init (FWidget* parent)
menu_ptr->has_checkable_items = true; menu_ptr->has_checkable_items = true;
} }
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FCheckMenuItem::processToggle() void FCheckMenuItem::processToggle()

View File

@ -253,10 +253,10 @@ void FFileDialog::clear()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int FFileDialog::numOfDirs() int FFileDialog::numOfDirs()
{ {
int n = 0; if ( dir_entries.empty() )
return 0;
if ( ! dir_entries.empty() ) int n = 0;
{
std::vector<dir_entry>::const_iterator iter, end; std::vector<dir_entry>::const_iterator iter, end;
iter = dir_entries.begin(); iter = dir_entries.begin();
end = dir_entries.end(); end = dir_entries.end();
@ -268,7 +268,6 @@ int FFileDialog::numOfDirs()
++iter; ++iter;
} }
}
return n; return n;
} }
@ -499,7 +498,9 @@ void FFileDialog::adjustSize()
FFileDialog& FFileDialog::operator = (const FFileDialog& fdlg) FFileDialog& FFileDialog::operator = (const FFileDialog& fdlg)
{ {
if ( &fdlg == this ) if ( &fdlg == this )
{
return *this; return *this;
}
else else
{ {
delete open; delete open;

View File

@ -736,8 +736,9 @@ void FLineEdit::onTimer (FTimerEvent*)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FLineEdit::onAccel (FAccelEvent* ev) void FLineEdit::onAccel (FAccelEvent* ev)
{ {
if ( isEnabled() ) if ( ! isEnabled() )
{ return;
if ( ! hasFocus() ) if ( ! hasFocus() )
{ {
FWidget* focused_widget = static_cast<FWidget*>(ev->focusedWidget()); FWidget* focused_widget = static_cast<FWidget*>(ev->focusedWidget());
@ -760,7 +761,6 @@ void FLineEdit::onAccel (FAccelEvent* ev)
ev->accept(); ev->accept();
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FLineEdit::onHide (FHideEvent*) void FLineEdit::onHide (FHideEvent*)

View File

@ -594,7 +594,7 @@ void FListBox::hide()
return; return;
blank = new char[size+1]; blank = new char[size+1];
memset(blank, ' ', uLong(size)); std::memset (blank, ' ', uLong(size));
blank[size] = '\0'; blank[size] = '\0';
for (int y=0; y < getHeight(); y++) for (int y=0; y < getHeight(); y++)
@ -612,8 +612,9 @@ void FListBox::showInsideBrackets ( int index
{ {
data[uInt(index-1)].brackets = b; data[uInt(index-1)].brackets = b;
if ( b != fc::NoBrackets ) if ( b == fc::NoBrackets )
{ return;
int len = int(data[uInt(index-1)].getText().getLength() + 2); int len = int(data[uInt(index-1)].getText().getLength() + 2);
if ( len > max_line_width ) if ( len > max_line_width )
@ -631,7 +632,6 @@ void FListBox::showInsideBrackets ( int index
} }
} }
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::setGeometry (int x, int y, int w, int h, bool adjust) void FListBox::setGeometry (int x, int y, int w, int h, bool adjust)
@ -1787,7 +1787,7 @@ void FListBox::clear()
return; return;
blank = new char[size+1]; blank = new char[size+1];
memset(blank, ' ', uLong(size)); std::memset (blank, ' ', uLong(size));
blank[size] = '\0'; blank[size] = '\0';
for (int y=0; y < getHeight()-2; y++) for (int y=0; y < getHeight()-2; y++)

View File

@ -433,8 +433,9 @@ void FMenuItem::delAccelerator (FWidget* obj)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuItem::onKeyPress (FKeyEvent* ev) void FMenuItem::onKeyPress (FKeyEvent* ev)
{ {
if ( super_menu ) if ( ! super_menu )
{ return;
if ( isMenu(super_menu) ) if ( isMenu(super_menu) )
{ {
FMenu* smenu = dynamic_cast<FMenu*>(super_menu); FMenu* smenu = dynamic_cast<FMenu*>(super_menu);
@ -456,13 +457,13 @@ void FMenuItem::onKeyPress (FKeyEvent* ev)
} }
} }
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuItem::onMouseDoubleClick (FMouseEvent* ev) void FMenuItem::onMouseDoubleClick (FMouseEvent* ev)
{ {
if ( super_menu ) if ( ! super_menu )
{ return;
const FPoint& t = ev->getTermPos(); const FPoint& t = ev->getTermPos();
int b = ev->getButton(); int b = ev->getButton();
@ -505,13 +506,13 @@ void FMenuItem::onMouseDoubleClick (FMouseEvent* ev)
} }
} }
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuItem::onMouseDown (FMouseEvent* ev) void FMenuItem::onMouseDown (FMouseEvent* ev)
{ {
if ( super_menu ) if ( ! super_menu )
{ return;
const FPoint& t = ev->getTermPos(); const FPoint& t = ev->getTermPos();
int b = ev->getButton(); int b = ev->getButton();
@ -554,13 +555,13 @@ void FMenuItem::onMouseDown (FMouseEvent* ev)
} }
} }
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuItem::onMouseUp (FMouseEvent* ev) void FMenuItem::onMouseUp (FMouseEvent* ev)
{ {
if ( super_menu ) if ( ! super_menu )
{ return;
const FPoint& t = ev->getTermPos(); const FPoint& t = ev->getTermPos();
int b = ev->getButton(); int b = ev->getButton();
@ -603,13 +604,13 @@ void FMenuItem::onMouseUp (FMouseEvent* ev)
} }
} }
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuItem::onMouseMove (FMouseEvent* ev) void FMenuItem::onMouseMove (FMouseEvent* ev)
{ {
if ( super_menu ) if ( ! super_menu )
{ return;
const FPoint& t = ev->getTermPos(); const FPoint& t = ev->getTermPos();
int b = ev->getButton(); int b = ev->getButton();
@ -652,19 +653,24 @@ void FMenuItem::onMouseMove (FMouseEvent* ev)
} }
} }
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuItem::onAccel (FAccelEvent* ev) void FMenuItem::onAccel (FAccelEvent* ev)
{ {
if ( isEnabled() && ! isSelected() ) if ( ! isEnabled() || isSelected() )
{ return;
if ( super_menu && isMenuBar(super_menu) )
if ( ! super_menu || ! isMenuBar(super_menu) )
{ {
processClicked();
return;
}
FMenuBar* mbar = dynamic_cast<FMenuBar*>(super_menu); FMenuBar* mbar = dynamic_cast<FMenuBar*>(super_menu);
if ( mbar ) if ( ! mbar )
{ return;
if ( menu ) if ( menu )
{ {
FWidget* focused_widget; FWidget* focused_widget;
@ -706,11 +712,6 @@ void FMenuItem::onAccel (FAccelEvent* ev)
} }
ev->accept(); ev->accept();
} }
}
else
processClicked();
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuItem::onFocusIn (FFocusEvent*) void FMenuItem::onFocusIn (FFocusEvent*)

View File

@ -18,8 +18,9 @@ FMenuList::FMenuList()
FMenuList::~FMenuList() // destructor FMenuList::~FMenuList() // destructor
{ {
// delete all items // delete all items
if ( ! item_list.empty() ) if ( item_list.empty() )
{ return;
std::vector<FMenuItem*>::iterator iter; std::vector<FMenuItem*>::iterator iter;
iter = item_list.begin(); iter = item_list.begin();
@ -29,7 +30,6 @@ FMenuList::~FMenuList() // destructor
iter = item_list.erase(iter); iter = item_list.erase(iter);
} }
} }
}
// public methods of FMenuList // public methods of FMenuList

View File

@ -375,7 +375,9 @@ void FMessageBox::adjustSize()
FMessageBox& FMessageBox::operator = (const FMessageBox& mbox) FMessageBox& FMessageBox::operator = (const FMessageBox& mbox)
{ {
if ( &mbox == this ) if ( &mbox == this )
{
return *this; return *this;
}
else else
{ {
for (uInt n=0; n < num_buttons; n++) for (uInt n=0; n < num_buttons; n++)

View File

@ -94,18 +94,6 @@ void FObject::delChild (FObject* obj)
} }
} }
//----------------------------------------------------------------------
bool FObject::event (FEvent* ev)
{
if ( ev->type() == fc::Timer_Event )
{
onTimer ( static_cast<FTimerEvent*>(ev) );
return true;
}
return false;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FObject::getCurrentTime (timeval &time) void FObject::getCurrentTime (timeval &time)
{ {
@ -255,6 +243,18 @@ bool FObject::delAllTimer()
} }
// protected methods of FObject // protected methods of FObject
//----------------------------------------------------------------------
bool FObject::event (FEvent* ev)
{
if ( ev->type() == fc::Timer_Event )
{
onTimer ( static_cast<FTimerEvent*>(ev) );
return true;
}
return false;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FObject::onTimer (FTimerEvent*) void FObject::onTimer (FTimerEvent*)
{ } { }

View File

@ -90,11 +90,10 @@ class FObject
bool delOwnTimer(); bool delOwnTimer();
bool delAllTimer(); bool delAllTimer();
bool isTimerInUpdating() const; bool isTimerInUpdating() const;
// Event handler
virtual bool event (FEvent*);
protected: protected:
// Event handler // Event handler
virtual bool event (FEvent*);
virtual void onTimer (FTimerEvent*); virtual void onTimer (FTimerEvent*);
private: private:

View File

@ -69,8 +69,9 @@ int FOptiMove::capDuration (char*& cap, int affcnt)
// cap - the term capability // cap - the term capability
// affcnt - the number of lines affected // affcnt - the number of lines affected
if ( cap ) if ( ! cap )
{ return LONG_DURATION;
const char* p; const char* p;
float ms = 0; float ms = 0;
@ -99,9 +100,6 @@ int FOptiMove::capDuration (char*& cap, int affcnt)
return int(ms); return int(ms);
} }
else
return LONG_DURATION;
}
// public methods of FOptiMove // public methods of FOptiMove

View File

@ -49,8 +49,9 @@ void FRadioMenuItem::init (FWidget* parent)
checkable = true; checkable = true;
radio_button = true; radio_button = true;
if ( parent ) if ( ! parent )
{ return;
if ( isMenu(parent) ) // Parent is menu if ( isMenu(parent) ) // Parent is menu
{ {
FMenu* menu_ptr = dynamic_cast<FMenu*>(parent); FMenu* menu_ptr = dynamic_cast<FMenu*>(parent);
@ -65,7 +66,6 @@ void FRadioMenuItem::init (FWidget* parent)
); );
} }
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FRadioMenuItem::processToggle() void FRadioMenuItem::processToggle()

View File

@ -92,8 +92,9 @@ void FStatusKey::processActivate()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FStatusKey::onAccel (FAccelEvent* ev) void FStatusKey::onAccel (FAccelEvent* ev)
{ {
if ( ! isActivated() ) if ( isActivated() )
{ return;
setActive(); setActive();
if ( statusbar() ) if ( statusbar() )
@ -106,7 +107,6 @@ void FStatusKey::onAccel (FAccelEvent* ev)
if ( statusbar() ) if ( statusbar() )
statusbar()->redraw(); statusbar()->redraw();
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FStatusBar* FStatusKey::statusbar() const FStatusBar* FStatusKey::statusbar() const

View File

@ -146,8 +146,9 @@ FString::FString (const std::string& s)
, bufsize(0) , bufsize(0)
, c_string(0) , c_string(0)
{ {
if ( ! s.empty() ) if ( s.empty() )
{ return;
const wchar_t* wc_string; const wchar_t* wc_string;
wc_string = c_to_wc_str(s.c_str()); wc_string = c_to_wc_str(s.c_str());
@ -157,7 +158,6 @@ FString::FString (const std::string& s)
delete[] wc_string; delete[] wc_string;
} }
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FString::FString (const char* s) FString::FString (const char* s)
@ -217,14 +217,14 @@ FString::~FString() // destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FString::initLength (uInt len) inline void FString::initLength (uInt len)
{ {
if ( len > 0 ) if ( len == 0 )
{ return;
length = len; length = len;
bufsize = FWDBUFFER + len + 1; bufsize = FWDBUFFER + len + 1;
string = new wchar_t[bufsize](); string = new wchar_t[bufsize]();
std::wmemset (string, L'\0', bufsize); std::wmemset (string, L'\0', bufsize);
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FString::_replace (const wchar_t* s) inline void FString::_replace (const wchar_t* s)

View File

@ -101,15 +101,13 @@ fc::consoleCursorStyle FTerm::console_cursor_style;
// constructors and destructor // constructors and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FTerm::FTerm() FTerm::FTerm()
: map() : color_map()
{ {
resize_term = false; resize_term = false;
if ( ! term_initialized ) if ( ! term_initialized )
{
init(); init();
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FTerm::~FTerm() // destructor FTerm::~FTerm() // destructor
@ -125,31 +123,100 @@ FTerm::~FTerm() // destructor
} }
} }
// private methods of FTerm // private methods of FTerm
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTerm::outb_Attribute_Controller (int index, int data) inline uInt16 FTerm::getInputStatusRegisterOne()
{ {
inb (AttrC_DataSwitch); // Gets the VGA input-status-register-1
outb (index & 0x1F, AttrC_Index); uInt16 misc_read = 0x3cc; // Miscellaneous output (read port)
outb (uChar(data), AttrC_DataW); uInt16 io_base = (inb(misc_read) & 0x01) ? 0x3d0 : 0x3b0;
inb (AttrC_DataSwitch); // 0x3ba : Input status 1 MDA (read port)
outb (uChar((index & 0x1F) | 0x20), AttrC_Index); // 0x3da : Input status 1 CGA (read port)
outb (uChar(data), AttrC_DataW); return io_base + 0x0a;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int FTerm::inb_Attribute_Controller (int index) uChar FTerm::readAttributeController (uChar index)
{ {
int res; // Reads a byte from the attribute controller from a given index
inb (AttrC_DataSwitch); uChar res;
outb (index & 0x1F, AttrC_Index); uInt16 attrib_cntlr_write = 0x3c0; // Attribute controller (write port)
res = inb (AttrC_DataR); uInt16 attrib_cntlr_read = 0x3c1; // Attribute controller (read port)
inb (AttrC_DataSwitch); uInt16 input_status_1 = getInputStatusRegisterOne();
outb (uChar((index & 0x1F) | 0x20), AttrC_Index);
inb (AttrC_DataR); inb (input_status_1); // switch to index mode
outb (index & 0x1f, attrib_cntlr_write);
res = inb (attrib_cntlr_read);
inb (input_status_1); // switch to data mode
index = (index & 0x1f) | 0x20; // set bit 5 (enable display)
outb (index, attrib_cntlr_write);
inb (attrib_cntlr_read);
return res; return res;
} }
//----------------------------------------------------------------------
void FTerm::writeAttributeController (uChar index, uChar data)
{
// Writes a byte from the attribute controller from a given index
uInt16 attrib_cntlr_write = 0x3c0; // Attribute controller (write port)
uInt16 input_status_1 = getInputStatusRegisterOne();
inb (input_status_1); // switch to index mode
outb (index & 0x1f, attrib_cntlr_write);
outb (data, attrib_cntlr_write);
inb (input_status_1); // switch to data mode
index = (index & 0x1f) | 0x20; // set bit 5 (enable display)
outb (index, attrib_cntlr_write);
outb (data, attrib_cntlr_write);
}
//----------------------------------------------------------------------
inline uChar FTerm::getAttributeMode()
{
// Gets the attribute mode value from the vga attribute controller
uChar attrib_mode = 0x10;
return readAttributeController(attrib_mode);
}
//----------------------------------------------------------------------
inline void FTerm::setAttributeMode(uChar data)
{
// Sets the attribute mode value from the vga attribute controller
uChar attrib_mode = 0x10;
writeAttributeController (attrib_mode, data);
}
//----------------------------------------------------------------------
int FTerm::setBlinkAsIntensity (bool on)
{
// Uses blink-bit as background intensity.
// That permits 16 colors for background
if ( getuid() != 0 ) // Direct hardware access requires root privileges
return -2;
if ( fd_tty < 0 )
return -1;
// Enable access to VGA I/O ports (from 0x3B4 with num = 0x2C)
if ( ioctl(fd_tty, KDENABIO, 0) < 0 )
return -1; // error on KDENABIO
if ( on )
setAttributeMode (getAttributeMode() & 0xF7); // clear bit 3
else
setAttributeMode (getAttributeMode() | 0x08); // set bit 3
// Disable access to VGA I/O ports
if ( ioctl(fd_tty, KDDISABIO, 0) < 0 )
return -1; // error on KDDISABIO
return 0;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int FTerm::getFramebuffer_bpp () int FTerm::getFramebuffer_bpp ()
{ {
@ -183,6 +250,7 @@ int FTerm::getFramebuffer_bpp ()
::close(fd); ::close(fd);
} }
} }
return -1; return -1;
} }
@ -313,7 +381,7 @@ int FTerm::getScreenFont()
return -1; return -1;
// initialize unused padding bytes in struct // initialize unused padding bytes in struct
memset(&font, 0, sizeof(console_font_op)); std::memset (&font, 0, sizeof(console_font_op));
font.op = KD_FONT_OP_GET; font.op = KD_FONT_OP_GET;
font.flags = 0; font.flags = 0;
@ -350,7 +418,7 @@ int FTerm::setScreenFont ( uChar* fontdata, uInt count
return -1; return -1;
// initialize unused padding bytes in struct // initialize unused padding bytes in struct
memset(&font, 0x00, sizeof(console_font_op)); std::memset (&font, 0x00, sizeof(console_font_op));
font.op = KD_FONT_OP_SET; font.op = KD_FONT_OP_SET;
font.flags = 0; font.flags = 0;
@ -445,6 +513,7 @@ int FTerm::getUnicodeMap()
else else
return -1; return -1;
} }
return 0; return 0;
} }
@ -483,34 +552,6 @@ int FTerm::setUnicodeMap (struct unimapdesc* unimap)
return -1; return -1;
} }
//----------------------------------------------------------------------
int FTerm::setBlinkAsIntensity (bool on)
{
// Uses blink-bit as background intensity.
// That permits 16 colors for background
if ( getuid() != 0 ) // Direct hardware access requires root privileges
return -2;
if ( fd_tty < 0 )
return -1;
// Enable access to VGA I/O ports (from 0x3B4 with num = 0x2C)
if ( ioctl(fd_tty, KDENABIO, 0) < 0 )
return -1; // error on KDENABIO
if ( on )
outb_Attribute_Controller (0x10, inb_Attribute_Controller(0x10) & 0xF7);
else
outb_Attribute_Controller (0x10, inb_Attribute_Controller(0x10) | 0x08);
// Disable access to VGA I/O ports
if ( ioctl(fd_tty, KDDISABIO, 0) < 0 )
return -1; // error on KDDISABIO
return 0;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FTerm::isKeyTimeout (timeval* time, register long timeout) bool FTerm::isKeyTimeout (timeval* time, register long timeout)
{ {
@ -693,7 +734,7 @@ FTerm::modifier_key& FTerm::getModifierKey()
{ {
char subcode = 6; char subcode = 6;
// fill bit field with 0 // fill bit field with 0
memset (&mod_key, 0x00, sizeof(mod_key)); std::memset (&mod_key, 0x00, sizeof(mod_key));
// TIOCLINUX, subcode=6 // TIOCLINUX, subcode=6
if ( ioctl(0, TIOCLINUX, &subcode) >= 0 ) if ( ioctl(0, TIOCLINUX, &subcode) >= 0 )
@ -2827,7 +2868,7 @@ void FTerm::resetXTermHighlightBackground()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTerm::saveColorMap() void FTerm::saveColorMap()
{ {
// ioctl (0, GIO_CMAP, &map); // ioctl (0, GIO_CMAP, &color_map);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -2855,11 +2896,11 @@ void FTerm::resetColorMap()
}; };
for (int x=0; x<16; x++) for (int x=0; x<16; x++)
{ {
map.d[x].red = CurrentColors[x].red; color_map.d[x].red = CurrentColors[x].red;
map.d[x].green = CurrentColors[x].green; color_map.d[x].green = CurrentColors[x].green;
map.d[x].blue = CurrentColors[x].blue; color_map.d[x].blue = CurrentColors[x].blue;
} }
ioctl (0, PIO_CMAP, &map); ioctl (0, PIO_CMAP, &color_map);
}*/ }*/
std::fflush(stdout); std::fflush(stdout);
@ -2957,8 +2998,9 @@ void FTerm::setEncoding (std::string enc)
// available encodings: "UTF8", "VT100", "PC" and "ASCII" // available encodings: "UTF8", "VT100", "PC" and "ASCII"
it = encoding_set->find(enc); it = encoding_set->find(enc);
if ( it != encoding_set->end() ) // found if ( it == encoding_set->end() ) // not found
{ return;
Encoding = it->second; Encoding = it->second;
assert ( Encoding == fc::UTF8 assert ( Encoding == fc::UTF8
@ -2983,7 +3025,6 @@ void FTerm::setEncoding (std::string enc)
Fputchar = &FTerm::putchar_ASCII; Fputchar = &FTerm::putchar_ASCII;
} }
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
std::string FTerm::getEncoding() std::string FTerm::getEncoding()

View File

@ -75,13 +75,6 @@
#define OSC ESC "]" // Operating system command (7-bit) #define OSC ESC "]" // Operating system command (7-bit)
#define SECDA ESC "[>c" // Secondary Device Attributes #define SECDA ESC "[>c" // Secondary Device Attributes
// VGA I/O-ports
#define VideoIOBase ( (inb(0x3CC) & 0x01) ? 0x3D0 : 0x3B0 )
#define AttrC_Index 0x3C0 // Attribute controller index
#define AttrC_DataW 0x3C0 // Attribute controller dataW
#define AttrC_DataR 0x3C1 // Attribute controller dataR
#define AttrC_DataSwitch (VideoIOBase+0x0A) // Attribute controller data switch
// parseKeyString return value // parseKeyString return value
#define NEED_MORE_DATA -1 #define NEED_MORE_DATA -1
@ -164,7 +157,7 @@ class FTerm
struct struct
{ {
dacreg d[16]; dacreg d[16];
} map; } color_map;
protected: protected:
static int stdin_no; static int stdin_no;
@ -190,8 +183,12 @@ class FTerm
// Disable assignment operator (=) // Disable assignment operator (=)
FTerm& operator = (const FTerm&); FTerm& operator = (const FTerm&);
static void outb_Attribute_Controller (int, int); static uInt16 getInputStatusRegisterOne();
static int inb_Attribute_Controller (int); static uChar readAttributeController (uChar);
static void writeAttributeController (uChar, uChar);
static uChar getAttributeMode();
static void setAttributeMode (uChar);
static int setBlinkAsIntensity (bool);
static int getFramebuffer_bpp(); static int getFramebuffer_bpp();
static int openConsole(); static int openConsole();
static int closeConsole(); static int closeConsole();
@ -201,7 +198,6 @@ class FTerm
static int setScreenFont (uChar*, uInt, uInt, uInt, bool = false); static int setScreenFont (uChar*, uInt, uInt, uInt, bool = false);
static int setUnicodeMap (struct unimapdesc*); static int setUnicodeMap (struct unimapdesc*);
static int getUnicodeMap (); static int getUnicodeMap ();
static int setBlinkAsIntensity (bool);
static void init_console(); static void init_console();
static uInt getBaudRate (const struct termios*); static uInt getBaudRate (const struct termios*);
static char* init_256colorTerminal(); static char* init_256colorTerminal();

View File

@ -485,8 +485,9 @@ void FToggleButton::onMouseDown (FMouseEvent* ev)
if ( ev->getButton() != fc::LeftButton ) if ( ev->getButton() != fc::LeftButton )
return; return;
if ( ! hasFocus() ) if ( hasFocus() )
{ return;
FWidget* focused_widget = getFocusWidget(); FWidget* focused_widget = getFocusWidget();
FFocusEvent out (fc::FocusOut_Event); FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out); FApplication::queueEvent(focused_widget, &out);
@ -504,7 +505,6 @@ void FToggleButton::onMouseDown (FMouseEvent* ev)
flush_out(); flush_out();
} }
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FToggleButton::onMouseUp (FMouseEvent* ev) void FToggleButton::onMouseUp (FMouseEvent* ev)
@ -512,8 +512,9 @@ void FToggleButton::onMouseUp (FMouseEvent* ev)
if ( ev->getButton() != fc::LeftButton ) if ( ev->getButton() != fc::LeftButton )
return; return;
if ( getTermGeometry().contains(ev->getTermPos()) ) if ( ! getTermGeometry().contains(ev->getTermPos()) )
{ return;
if ( isRadioButton() ) if ( isRadioButton() )
{ {
if ( ! checked ) if ( ! checked )
@ -527,16 +528,17 @@ void FToggleButton::onMouseUp (FMouseEvent* ev)
checked = not checked; checked = not checked;
processToggle(); processToggle();
} }
redraw(); redraw();
processClick(); processClick();
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FToggleButton::onAccel (FAccelEvent* ev) void FToggleButton::onAccel (FAccelEvent* ev)
{ {
if ( isEnabled() ) if ( ! isEnabled() )
{ return;
if ( ! hasFocus() ) if ( ! hasFocus() )
{ {
FWidget* focused_widget = static_cast<FWidget*>(ev->focusedWidget()); FWidget* focused_widget = static_cast<FWidget*>(ev->focusedWidget());
@ -574,7 +576,6 @@ void FToggleButton::onAccel (FAccelEvent* ev)
processClick(); processClick();
ev->accept(); ev->accept();
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FToggleButton::onFocusIn (FFocusEvent*) void FToggleButton::onFocusIn (FFocusEvent*)
@ -592,8 +593,9 @@ void FToggleButton::onFocusOut (FFocusEvent* out_ev)
statusBar()->drawMessage(); statusBar()->drawMessage();
} }
if ( group() ) if ( ! group() )
{ return;
if ( ! focus_inside_group && isRadioButton() ) if ( ! focus_inside_group && isRadioButton() )
{ {
focus_inside_group = true; focus_inside_group = true;
@ -622,7 +624,6 @@ void FToggleButton::onFocusOut (FFocusEvent* out_ev)
redraw(); redraw();
} }
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FToggleButton::setChecked (bool on) bool FToggleButton::setChecked (bool on)

View File

@ -39,8 +39,9 @@ FToolTip::~FToolTip() // destructor
{ {
FApplication* fapp = static_cast<FApplication*>(getRootWidget()); FApplication* fapp = static_cast<FApplication*>(getRootWidget());
if ( ! fapp->isQuit() ) if ( fapp->isQuit() )
{ return;
FWindow* parent_win = 0; FWindow* parent_win = 0;
if ( FWidget* parent = getParentWidget() ) if ( FWidget* parent = getParentWidget() )
@ -51,7 +52,6 @@ FToolTip::~FToolTip() // destructor
else else
switchToPrevWindow(); switchToPrevWindow();
} }
}
// private methods of FToolTip // private methods of FToolTip

View File

@ -58,8 +58,9 @@ FWindow::~FWindow() // destructor
void FWindow::deleteFromAlwaysOnTopList (FWidget* obj) void FWindow::deleteFromAlwaysOnTopList (FWidget* obj)
{ {
// delete the window object obj from the always-on-top list // delete the window object obj from the always-on-top list
if ( always_on_top_list && ! always_on_top_list->empty() ) if ( ! always_on_top_list || always_on_top_list->empty() )
{ return;
widgetList::iterator iter; widgetList::iterator iter;
iter = always_on_top_list->begin(); iter = always_on_top_list->begin();
@ -74,14 +75,14 @@ void FWindow::deleteFromAlwaysOnTopList (FWidget* obj)
++iter; ++iter;
} }
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWindow::processAlwaysOnTop() void FWindow::processAlwaysOnTop()
{ {
// Raise all always-on-top windows // Raise all always-on-top windows
if ( always_on_top_list && ! always_on_top_list->empty() ) if ( ! always_on_top_list || always_on_top_list->empty() )
{ return;
widgetList::iterator iter; widgetList::iterator iter;
iter = always_on_top_list->begin(); iter = always_on_top_list->begin();
@ -95,7 +96,6 @@ void FWindow::processAlwaysOnTop()
++iter; ++iter;
} }
} }
}
// protected methods of FWindow // protected methods of FWindow
@ -319,8 +319,9 @@ void FWindow::setGeometry (int x, int y, int w, int h, bool adjust)
FWidget::setGeometry (x, y, w, h, adjust); FWidget::setGeometry (x, y, w, h, adjust);
if ( vwin ) if ( ! vwin )
{ return;
if ( getWidth() != old_width || getHeight() != old_height ) if ( getWidth() != old_width || getHeight() != old_height )
{ {
FRect geometry = getTermGeometry(); FRect geometry = getTermGeometry();
@ -336,7 +337,6 @@ void FWindow::setGeometry (int x, int y, int w, int h, bool adjust)
vwin->y_offset = getTermY() - 1; vwin->y_offset = getTermY() - 1;
} }
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWindow::move (int dx, int dy) void FWindow::move (int dx, int dy)
@ -354,12 +354,6 @@ void FWindow::move (int dx, int dy)
FWindow* FWindow::getWindowWidgetAt (int x, int y) FWindow* FWindow::getWindowWidgetAt (int x, int y)
{ {
// returns the window object to the corresponding coordinates // returns the window object to the corresponding coordinates
if ( statusBar() && statusBar()->getTermGeometry().contains(x,y) )
return statusBar();
if ( menuBar() && menuBar()->getTermGeometry().contains(x,y) )
return menuBar();
if ( window_list && ! window_list->empty() ) if ( window_list && ! window_list->empty() )
{ {
widgetList::const_iterator iter, begin; widgetList::const_iterator iter, begin;
@ -761,7 +755,7 @@ bool FWindow::activatePrevWindow()
if ( w->isWindowActive() ) if ( w->isWindowActive() )
return true; return true;
if ( w && ! w->isWindowHidden() ) if ( ! w->isWindowHidden() )
{ {
setActiveWindow(w); setActiveWindow(w);
return true; return true;

View File

@ -48,8 +48,9 @@ Button::Button (FWidget* parent)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Button::setChecked (bool on) void Button::setChecked (bool on)
{ {
if ( checked != on ) if ( checked == on )
{ return;
checked = on; checked = on;
if ( checked ) if ( checked )
@ -67,7 +68,6 @@ void Button::setChecked (bool on)
redraw(); redraw();
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Button::onKeyPress (FKeyEvent* ev) void Button::onKeyPress (FKeyEvent* ev)

View File

@ -105,8 +105,9 @@ void Transparent::draw()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Transparent::onKeyPress (FKeyEvent* ev) void Transparent::onKeyPress (FKeyEvent* ev)
{ {
if ( ev ) if ( ! ev )
{ return;
if ( ev->key() == 'q' && getParentWidget() ) if ( ev->key() == 'q' && getParentWidget() )
{ {
if ( getParentWidget()->close() ) if ( getParentWidget()->close() )
@ -117,7 +118,6 @@ void Transparent::onKeyPress (FKeyEvent* ev)
else else
FDialog::onKeyPress(ev); FDialog::onKeyPress(ev);
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -147,8 +147,9 @@ class MainWindow : public FDialog
void onTimer (FTimerEvent*); void onTimer (FTimerEvent*);
void onKeyPress (FKeyEvent* ev) void onKeyPress (FKeyEvent* ev)
{ {
if ( ev ) if ( ! ev )
{ return;
if ( ev->key() == 'q' ) if ( ev->key() == 'q' )
{ {
close(); close();
@ -157,7 +158,6 @@ class MainWindow : public FDialog
else else
FDialog::onKeyPress(ev); FDialog::onKeyPress(ev);
} }
}
public: public:
// Constructor // Constructor

View File

@ -122,8 +122,9 @@ void ProgressDialog::onTimer (FTimerEvent*)
progressBar->setPercentage(++p); progressBar->setPercentage(++p);
flush_out(); flush_out();
if ( p == 100 ) if ( p != 100 )
{ return;
delOwnTimer(); delOwnTimer();
activateWindow(); activateWindow();
raiseWindow(); raiseWindow();
@ -139,7 +140,6 @@ void ProgressDialog::onTimer (FTimerEvent*)
updateTerminal(); updateTerminal();
flush_out(); flush_out();
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void ProgressDialog::cb_reset_bar (FWidget*, void*) void ProgressDialog::cb_reset_bar (FWidget*, void*)

View File

@ -339,8 +339,9 @@ Window::~Window()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Window::activateWindow (FDialog* win) void Window::activateWindow (FDialog* win)
{ {
if ( win && ! win->isWindowHidden() && ! win->isWindowActive() ) if ( ! win || win->isWindowHidden() || win->isWindowActive() )
{ return;
bool has_raised = FWindow::raiseWindow(win); bool has_raised = FWindow::raiseWindow(win);
win->activateDialog(); win->activateDialog();
@ -349,7 +350,6 @@ void Window::activateWindow (FDialog* win)
updateTerminal(); updateTerminal();
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Window::onClose (FCloseEvent* ev) void Window::onClose (FCloseEvent* ev)