The class declaration now has a consistent order

This commit is contained in:
Markus Gans 2016-11-02 00:37:58 +01:00
parent 1613d5bb55
commit 75b452bf52
76 changed files with 16745 additions and 16295 deletions

View File

@ -1,3 +1,6 @@
2016-11-01 Markus Gans <guru.mail@muenster.de>
* The class declaration now has a consistent order
2016-10-17 Markus Gans <guru.mail@muenster.de>
* Refactor the VGA attribute controller access code

38
doc/coding-style.txt Normal file
View File

@ -0,0 +1,38 @@
============
Coding style
============
Formatting
----------
* A new line should begin after 72 (max. 80) characters
* Use 2 spaces indent. Do not use tabs!
* Leave a space after the keywords if, switch, while, do, for, and return
* Use one blank line before and afte a for, if, switch,
while, do..while code block
* In parameter lists, leave a space after each comma
Class declaration order
-----------------------
The declaration section order is:
* public:
* protected:
* private:
Each declaration section should be in the following order:
* Using-declarations (using std::string;)
* Typedefs and Enumerations
* Constants (static const data members)
* Constructors
* Destructor
* Overloaded operators (=, +, -, +=. ...)
* Accessors (getXY)
* Mutators (setXY)
* Inquiries (isXY)
* Methods, including static methods
* Event handler methods
* Callback methods
* Data Members (except static const data members)

View File

@ -25,7 +25,7 @@ uChar FApplication::x11_button_state = 0x03;
int FApplication::quit_code = 0;
bool FApplication::quit_now = false;
std::deque<FApplication::eventPair>* FApplication::event_queue = 0;
FApplication::eventQueue* FApplication::event_queue = 0;
//----------------------------------------------------------------------
// class FApplication
@ -79,6 +79,217 @@ FApplication::~FApplication() // destructor
}
// public methods of FApplication
//----------------------------------------------------------------------
void FApplication::setMainWidget (FWidget* widget)
{
main_widget = widget;
if ( widget && ! getFocusWidget() )
rootObj->focusFirstChild();
}
//----------------------------------------------------------------------
bool FApplication::isQuit()
{
if ( rootObj )
return quit_now;
else
return true;
}
//----------------------------------------------------------------------
int FApplication::exec() // run
{
if ( quit_now )
return EXIT_FAILURE;
quit_now = false;
quit_code = 0;
enter_loop();
return quit_code;
}
//----------------------------------------------------------------------
int FApplication::enter_loop() // event loop
{
bool old_app_exit_loop;
loop_level++;
quit_now = false;
old_app_exit_loop = app_exit_loop;
app_exit_loop = false;
while ( ! (quit_now || app_exit_loop) )
processNextEvent();
app_exit_loop = old_app_exit_loop;
loop_level--;
return 0;
}
//----------------------------------------------------------------------
void FApplication::exit_loop()
{
app_exit_loop = true;
}
//----------------------------------------------------------------------
void FApplication::exit (int retcode)
{
if ( ! rootObj ) // no global app object
return;
if ( quit_now ) // don't overwrite quit code
return;
quit_now = true;
quit_code = retcode;
}
//----------------------------------------------------------------------
void FApplication::quit()
{
FApplication::exit(0);
}
//----------------------------------------------------------------------
bool FApplication::sendEvent(FObject* receiver, FEvent* event)
{
FWidget* widget;
if ( quit_now || app_exit_loop )
return false;
if ( ! receiver )
return false;
widget = static_cast<FWidget*>(receiver);
if ( modal_dialogs > 0 )
{
FWidget* window;
if ( widget->isWindowWidget() )
window = widget;
else
window = FWindow::getWindowWidget(widget);
// block events for widgets in non modal windows
if ( window
&& (window->getFlags() & fc::modal) == 0
&& ! window->isMenuWidget() )
{
switch ( event->type() )
{
case fc::KeyPress_Event:
case fc::KeyUp_Event:
case fc::KeyDown_Event:
case fc::MouseDown_Event:
case fc::MouseUp_Event:
case fc::MouseDoubleClick_Event:
case fc::MouseWheel_Event:
case fc::MouseMove_Event:
case fc::FocusIn_Event:
case fc::FocusOut_Event:
case fc::Accelerator_Event:
return false;
default:
break;
}
}
}
// throw away mouse events to disabled widgets
if ( event->type() >= fc::MouseDown_Event
&& event->type() <= fc::MouseMove_Event
&& ! widget->isEnabled() )
return false;
// sends event event directly to receiver
FApplication* w = static_cast<FApplication*>(widget);
return w->event(event); // access to a protected base class member
}
//----------------------------------------------------------------------
void FApplication::queueEvent (FObject* receiver, FEvent* event)
{
if ( ! receiver )
return;
// queue this event
eventPair Event (receiver, event);
event_queue->push_back(Event);
}
//----------------------------------------------------------------------
void FApplication::sendQueuedEvents()
{
eventQueue* events;
if ( ! eventInQueue() )
return;
events = event_queue;
while ( ! eventInQueue() )
{
sendEvent(events->front().first, events->front().second);
events->pop_front();
}
}
//----------------------------------------------------------------------
bool FApplication::eventInQueue()
{
if ( rootObj )
return ( ! event_queue->empty() );
else
return false;
}
//----------------------------------------------------------------------
bool FApplication::removeQueuedEvent(FObject* receiver)
{
bool retval;
eventQueue::iterator iter;
if ( ! eventInQueue() )
return false;
if ( ! receiver )
return false;
retval = false;
iter = event_queue->begin();
while ( iter != event_queue->end() )
{
if ( iter->first == receiver )
{
iter = event_queue->erase(iter);
retval = true;
}
else
++iter;
}
return retval;
}
//----------------------------------------------------------------------
void FApplication::print_cmd_Options ()
{
std::printf ( "\nFinalCut Options:\n"
" --encoding <name> Sets the character encoding mode\n"
" {UTF8, VT100, PC, ASCII}\n"
" --no-optimized-cursor No cursor optimisation\n"
" --vgafont Set the standard vga 8x16 font\n"
" --newfont Enables the graphical font\n" );
}
// private methods of FApplication
//----------------------------------------------------------------------
void FApplication::init()
@ -95,7 +306,7 @@ void FApplication::init()
#endif
zero_point = new FPoint(0,0);
event_queue = new std::deque<eventPair>;
event_queue = new eventQueue;
// init arrays with '\0'
std::fill_n (k_buf, sizeof(k_buf), '\0');
std::fill_n (fifo_buf, fifo_buf_size, '\0');
@ -1474,8 +1685,8 @@ void FApplication::processMouseEvent()
if ( ! (clicked_widget || is_window_menu) )
FWindow::switchToPrevWindow();
if ( statusBar() )
statusBar()->drawMessage();
if ( getStatusBar() )
getStatusBar()->drawMessage();
updateTerminal();
flush_out();
@ -1483,24 +1694,24 @@ void FApplication::processMouseEvent()
}
// unselected menu bar item
if ( ! open_menu && menuBar()
&& menuBar()->hasSelectedItem()
if ( ! open_menu && getMenuBar()
&& getMenuBar()->hasSelectedItem()
&& ! b_state.mouse_moved )
{
if ( ! menuBar()->getTermGeometry().contains(mouse_position) )
if ( ! getMenuBar()->getTermGeometry().contains(mouse_position) )
{
if ( statusBar() )
statusBar()->clearMessage();
if ( getStatusBar() )
getStatusBar()->clearMessage();
menuBar()->resetMenu();
menuBar()->redraw();
getMenuBar()->resetMenu();
getMenuBar()->redraw();
// No widget was been clicked
if ( ! clicked_widget )
FWindow::switchToPrevWindow();
if ( statusBar() )
statusBar()->drawMessage();
if ( getStatusBar() )
getStatusBar()->drawMessage();
updateTerminal();
flush_out();
@ -1764,214 +1975,3 @@ bool FApplication::processNextEvent()
return (num_events > 0);
}
// public methods of FApplication
//----------------------------------------------------------------------
void FApplication::print_cmd_Options ()
{
std::printf ( "\nFinalCut Options:\n"
" --encoding <name> Sets the character encoding mode\n"
" {UTF8, VT100, PC, ASCII}\n"
" --no-optimized-cursor No cursor optimisation\n"
" --vgafont Set the standard vga 8x16 font\n"
" --newfont Enables the graphical font\n" );
}
//----------------------------------------------------------------------
void FApplication::setMainWidget (FWidget* widget)
{
main_widget = widget;
if ( widget && ! getFocusWidget() )
rootObj->focusFirstChild();
}
//----------------------------------------------------------------------
int FApplication::exec() // run
{
if ( quit_now )
return EXIT_FAILURE;
quit_now = false;
quit_code = 0;
enter_loop();
return quit_code;
}
//----------------------------------------------------------------------
int FApplication::enter_loop() // event loop
{
bool old_app_exit_loop;
loop_level++;
quit_now = false;
old_app_exit_loop = app_exit_loop;
app_exit_loop = false;
while ( ! (quit_now || app_exit_loop) )
processNextEvent();
app_exit_loop = old_app_exit_loop;
loop_level--;
return 0;
}
//----------------------------------------------------------------------
void FApplication::exit_loop()
{
app_exit_loop = true;
}
//----------------------------------------------------------------------
void FApplication::exit (int retcode)
{
if ( ! rootObj ) // no global app object
return;
if ( quit_now ) // don't overwrite quit code
return;
quit_now = true;
quit_code = retcode;
}
//----------------------------------------------------------------------
void FApplication::quit()
{
FApplication::exit(0);
}
//----------------------------------------------------------------------
bool FApplication::isQuit()
{
if ( rootObj )
return quit_now;
else
return true;
}
//----------------------------------------------------------------------
bool FApplication::sendEvent(FObject* receiver, FEvent* event)
{
FWidget* widget;
if ( quit_now || app_exit_loop )
return false;
if ( ! receiver )
return false;
widget = static_cast<FWidget*>(receiver);
if ( modal_dialogs > 0 )
{
FWidget* window;
if ( widget->isWindowWidget() )
window = widget;
else
window = FWindow::getWindowWidget(widget);
// block events for widgets in non modal windows
if ( window
&& (window->getFlags() & fc::modal) == 0
&& ! window->isMenuWidget() )
{
switch ( event->type() )
{
case fc::KeyPress_Event:
case fc::KeyUp_Event:
case fc::KeyDown_Event:
case fc::MouseDown_Event:
case fc::MouseUp_Event:
case fc::MouseDoubleClick_Event:
case fc::MouseWheel_Event:
case fc::MouseMove_Event:
case fc::FocusIn_Event:
case fc::FocusOut_Event:
case fc::Accelerator_Event:
return false;
default:
break;
}
}
}
// throw away mouse events to disabled widgets
if ( event->type() >= fc::MouseDown_Event
&& event->type() <= fc::MouseMove_Event
&& ! widget->isEnabled() )
return false;
// sends event event directly to receiver
FApplication* w = static_cast<FApplication*>(widget);
return w->event(event); // access to a protected base class member
}
//----------------------------------------------------------------------
void FApplication::queueEvent (FObject* receiver, FEvent* event)
{
if ( ! receiver )
return;
// queue this event
eventPair Event (receiver, event);
event_queue->push_back(Event);
}
//----------------------------------------------------------------------
void FApplication::sendQueuedEvents()
{
std::deque<eventPair>* events;
if ( ! eventInQueue() )
return;
events = event_queue;
while ( ! eventInQueue() )
{
sendEvent(events->front().first, events->front().second);
events->pop_front();
}
}
//----------------------------------------------------------------------
bool FApplication::eventInQueue()
{
if ( rootObj )
return ( ! event_queue->empty() );
else
return false;
}
//----------------------------------------------------------------------
bool FApplication::removeQueuedEvent(FObject* receiver)
{
bool retval;
std::deque<eventPair>::iterator iter;
if ( ! eventInQueue() )
return false;
if ( ! receiver )
return false;
retval = false;
iter = event_queue->begin();
while ( iter != event_queue->end() )
{
if ( iter->first == receiver )
{
iter = event_queue->erase(iter);
retval = true;
}
else
++iter;
}
return retval;
}

View File

@ -54,37 +54,42 @@
class FApplication : public FWidget
{
public:
typedef std::pair<FObject*,FEvent*> eventPair;
static std::deque<eventPair>* event_queue;
// Constructor
FApplication (int&, char**& );
// Destructor
virtual ~FApplication();
// Accessors
const char* getClassName() const;
int getArgc() const;
char** getArgv() const;
FWidget* getMainWidget() const;
FWidget* getFocusWidget() const;
// Mutator
void setMainWidget (FWidget*);
// Inquiry
bool isQuit();
// Methods
int exec(); // run
int enter_loop();
void exit_loop();
static void exit (int = 0);
void quit();
static bool sendEvent (FObject*, FEvent*);
static void queueEvent (FObject*, FEvent*);
static void sendQueuedEvents ();
static bool eventInQueue();
static bool removeQueuedEvent(FObject*);
static void print_cmd_Options();
private:
int app_argc;
char** app_argv;
static int quit_code;
static bool quit_now;
static int loop_level;
static bool process_timer_event;
static FPoint* zero_point;
static uChar x11_button_state;
int key;
char k_buf[1024];
char x11_mouse[4];
char sgr_mouse[13];
char urxvt_mouse[13];
#ifdef F_HAVE_LIBGPM
Gpm_Event gpm_ev;
bool gpmMouseEvent;
enum gpmEventType
{
no_event = 0,
keyboard_event = 1,
mouse_event = 2
};
#endif
// Typedefs and Enumerations
typedef std::pair<FObject*,FEvent*> eventPair;
typedef std::deque<eventPair> eventQueue;
enum btn_state
{
@ -93,6 +98,60 @@ class FApplication : public FWidget
DoubleClick = 3
};
#ifdef F_HAVE_LIBGPM
enum gpmEventType
{
no_event = 0,
keyboard_event = 1,
mouse_event = 2
};
#endif
// Constants
static const int NEED_MORE_DATA = -1; // parseKeyString return value
// Disable copy constructor
FApplication (const FApplication&);
// Disable assignment operator (=)
FApplication& operator = (const FApplication&);
// Methods
void init();
void setExitMessage (std::string);
void cmd_options();
#ifdef F_HAVE_LIBGPM
int gpmEvent (bool = true);
bool processGpmEvent();
#endif
bool KeyPressed();
ssize_t readKey();
void processKeyboardEvent();
int modifierKeyCorrection (int& key);
bool processDialogSwitchAccelerator();
bool processAccelerator (FWidget*&);
void getX11ButtonState (int);
bool parseX11Mouse();
bool parseSGRMouse();
bool parseUrxvtMouse();
void processMouseEvent();
void processResizeEvent();
int processTimerEvent();
void processCloseWidget();
bool processNextEvent();
// Data Members
int app_argc;
char** app_argv;
int key;
#ifdef F_HAVE_LIBGPM
Gpm_Event gpm_ev;
bool gpmMouseEvent;
#endif
struct button_state // bit field
{
uChar left_button : 2; // 0..3
@ -107,6 +166,10 @@ class FApplication : public FWidget
uChar : 4; // padding bits
} b_state;
char k_buf[1024];
char x11_mouse[4];
char sgr_mouse[13];
char urxvt_mouse[13];
char fifo_buf[512];
int fifo_offset;
bool fifo_in_use;
@ -116,6 +179,13 @@ class FApplication : public FWidget
struct timeval time_keypressed;
struct timeval time_mousepressed;
FPoint new_mouse_position;
static eventQueue* event_queue;
static int quit_code;
static bool quit_now;
static int loop_level;
static bool process_timer_event;
static FPoint* zero_point;
static uChar x11_button_state;
static FWidget* move_size_widget;
static FWidget* main_widget;
static FWidget* active_window;
@ -123,39 +193,6 @@ class FApplication : public FWidget
static FWidget* clicked_widget;
static FWidget* open_menu;
private:
// Disable copy constructor
FApplication (const FApplication&);
// Disable assignment operator (=)
FApplication& operator = (const FApplication&);
void init();
void setExitMessage (std::string);
void cmd_options();
bool KeyPressed();
ssize_t readKey();
void processKeyboardEvent();
int modifierKeyCorrection (int& key);
bool processDialogSwitchAccelerator();
bool processAccelerator (FWidget*&);
void getX11ButtonState (int);
bool parseX11Mouse();
bool parseSGRMouse();
bool parseUrxvtMouse();
#ifdef F_HAVE_LIBGPM
int gpmEvent (bool = true);
bool processGpmEvent();
#endif
void processMouseEvent();
void processResizeEvent();
int processTimerEvent();
void processCloseWidget();
bool processNextEvent();
// Friend functions from FWidget
friend FWidget* FWidget::getMainWidget();
friend FWidget* FWidget::getFocusWidget() const;
@ -170,31 +207,6 @@ class FApplication : public FWidget
// Friend functions from FWindow
friend bool FWindow::activateWindow (bool);
friend FWindow* FWindow::getActiveWindow();
public:
// Constructor
FApplication (int&, char**& );
// Destructor
virtual ~FApplication();
const char* getClassName() const;
int argc() const;
char** argv() const;
FWidget* mainWidget() const;
FWidget* focusWidget() const;
static void print_cmd_Options();
void setMainWidget (FWidget*);
int exec(); // run
int enter_loop();
void exit_loop();
static void exit (int = 0);
void quit();
bool isQuit();
static bool sendEvent (FObject*, FEvent*);
static void queueEvent (FObject*, FEvent*);
static void sendQueuedEvents ();
static bool eventInQueue();
static bool removeQueuedEvent(FObject*);
};
#pragma pack(pop)
@ -205,19 +217,19 @@ inline const char* FApplication::getClassName() const
{ return "FApplication"; }
//----------------------------------------------------------------------
inline int FApplication::argc() const
inline int FApplication::getArgc() const
{ return app_argc; }
//----------------------------------------------------------------------
inline char** FApplication::argv() const
inline char** FApplication::getArgv() const
{ return app_argv; }
//----------------------------------------------------------------------
inline FWidget* FApplication::mainWidget() const
inline FWidget* FApplication::getMainWidget() const
{ return main_widget; }
//----------------------------------------------------------------------
inline FWidget* FApplication::focusWidget() const
inline FWidget* FApplication::getFocusWidget() const
{ return focus_widget; }

View File

@ -56,6 +56,368 @@ FButton::~FButton() // destructor
}
// public methods of FButton
//----------------------------------------------------------------------
void FButton::setForegroundColor (short color)
{
FWidget::setForegroundColor(color);
updateButtonColor();
}
//----------------------------------------------------------------------
void FButton::setBackgroundColor (short color)
{
FWidget::setBackgroundColor(color);
updateButtonColor();
}
//----------------------------------------------------------------------
void FButton::setHotkeyForegroundColor (short color)
{
// valid colors -1..254
if ( color == fc::Default || color >> 8 == 0 )
button_hotkey_fg = color;
}
void FButton::setFocusForegroundColor (short color)
{
// valid colors -1..254
if ( color == fc::Default || color >> 8 == 0 )
button_focus_fg = color;
updateButtonColor();
}
//----------------------------------------------------------------------
void FButton::setFocusBackgroundColor (short color)
{
// valid colors -1..254
if ( color == fc::Default || color >> 8 == 0 )
button_focus_bg = color;
updateButtonColor();
}
//----------------------------------------------------------------------
void FButton::setInactiveForegroundColor (short color)
{
// valid colors -1..254
if ( color == fc::Default || color >> 8 == 0 )
button_inactive_fg = color;
updateButtonColor();
}
//----------------------------------------------------------------------
void FButton::setInactiveBackgroundColor (short color)
{
// valid colors -1..254
if ( color == fc::Default || color >> 8 == 0 )
button_inactive_bg = color;
updateButtonColor();
}
//----------------------------------------------------------------------
bool FButton::setNoUnderline (bool on)
{
if ( on )
flags |= fc::no_underline;
else
flags &= ~fc::no_underline;
return on;
}
//----------------------------------------------------------------------
bool FButton::setEnable (bool on)
{
FWidget::setEnable(on);
if ( on )
{
flags |= fc::active;
setHotkeyAccelerator();
}
else
{
flags &= ~fc::active;
delAccelerator();
}
updateButtonColor();
return on;
}
//----------------------------------------------------------------------
bool FButton::setFocus (bool on)
{
FWidget::setFocus(on);
if ( on )
{
flags |= fc::focus;
if ( isEnabled() )
{
if ( getStatusBar() )
{
FString msg = getStatusbarMessage();
FString curMsg = getStatusBar()->getMessage();
if ( curMsg != msg )
getStatusBar()->setMessage(msg);
}
}
}
else
{
flags &= ~fc::focus;
if ( isEnabled() && getStatusBar() )
getStatusBar()->clearMessage();
}
updateButtonColor();
return on;
}
//----------------------------------------------------------------------
bool FButton::setFlat (bool on)
{
if ( on )
flags |= fc::flat;
else
flags &= ~fc::flat;
return on;
}
//----------------------------------------------------------------------
bool FButton::setShadow (bool on)
{
if ( on
&& (Encoding != fc::VT100 || isTeraTerm() )
&& Encoding != fc::ASCII )
flags |= fc::shadow;
else
flags &= ~fc::shadow;
return on;
}
//----------------------------------------------------------------------
bool FButton::setDown (bool on)
{
if ( button_down != on )
{
button_down = on;
redraw();
}
return on;
}
//----------------------------------------------------------------------
void FButton::setText (const FString& txt)
{
if ( txt )
text = txt;
else
text = "";
detectHotkey();
}
//----------------------------------------------------------------------
void FButton::hide()
{
int s, f, size;
short fg, bg;
char* blank;
FWidget* parent_widget = getParentWidget();
FWidget::hide();
if ( parent_widget )
{
fg = parent_widget->getForegroundColor();
bg = parent_widget->getBackgroundColor();
}
else
{
fg = wc.dialog_fg;
bg = wc.dialog_bg;
}
setColor (fg, bg);
s = hasShadow() ? 1 : 0;
f = isFlat() ? 1 : 0;
size = getWidth() + s + (f << 1);
if ( size < 0 )
return;
blank = new char[size+1];
std::memset(blank, ' ', uLong(size));
blank[size] = '\0';
for (int y=0; y < getHeight()+s+(f << 1); y++)
{
setPrintPos (1-f, 1+y-f);
print (blank);
}
delete[] blank;
}
//----------------------------------------------------------------------
void FButton::onKeyPress (FKeyEvent* ev)
{
int key;
if ( ! isEnabled() )
return;
key = ev->key();
switch ( key )
{
case fc::Fkey_return:
case fc::Fkey_enter:
case fc::Fkey_space:
if ( click_animation )
{
setDown();
addTimer(click_time);
}
processClick();
ev->accept();
break;
default:
break;
}
}
//----------------------------------------------------------------------
void FButton::onMouseDown (FMouseEvent* ev)
{
if ( ev->getButton() != fc::LeftButton )
{
setUp();
return;
}
if ( ! hasFocus() )
{
FWidget* focused_widget = getFocusWidget();
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
setFocus();
if ( focused_widget )
focused_widget->redraw();
if ( getStatusBar() )
getStatusBar()->drawMessage();
}
FPoint tPos = ev->getTermPos();
if ( getTermGeometry().contains(tPos) )
setDown();
}
//----------------------------------------------------------------------
void FButton::onMouseUp (FMouseEvent* ev)
{
if ( ev->getButton() != fc::LeftButton )
return;
if ( button_down )
{
setUp();
if ( getTermGeometry().contains(ev->getTermPos()) )
processClick();
}
}
//----------------------------------------------------------------------
void FButton::onMouseMove (FMouseEvent* ev)
{
if ( ev->getButton() != fc::LeftButton )
return;
FPoint tPos = ev->getTermPos();
if ( click_animation )
{
if ( getTermGeometry().contains(tPos) )
setDown();
else
setUp();
}
}
//----------------------------------------------------------------------
void FButton::onTimer (FTimerEvent* ev)
{
delTimer(ev->timerId());
setUp();
}
//----------------------------------------------------------------------
void FButton::onAccel (FAccelEvent* ev)
{
if ( ! isEnabled() )
return;
if ( ! hasFocus() )
{
FWidget* focused_widget = static_cast<FWidget*>(ev->focusedWidget());
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
setFocus();
if ( focused_widget )
focused_widget->redraw();
if ( click_animation )
setDown();
else
redraw();
if ( getStatusBar() )
getStatusBar()->drawMessage();
}
else if ( click_animation )
setDown();
if ( click_animation )
addTimer(click_time);
processClick();
ev->accept();
}
//----------------------------------------------------------------------
void FButton::onFocusIn (FFocusEvent*)
{
if ( getStatusBar() )
getStatusBar()->drawMessage();
}
//----------------------------------------------------------------------
void FButton::onFocusOut (FFocusEvent*)
{
if ( getStatusBar() )
{
getStatusBar()->clearMessage();
getStatusBar()->drawMessage();
}
}
// private methods of FButton
//----------------------------------------------------------------------
void FButton::init()
@ -386,15 +748,15 @@ void FButton::draw()
updateVTerm(true);
delete[] ButtonText;
if ( is_Focus && statusBar() )
if ( is_Focus && getStatusBar() )
{
FString msg = getStatusbarMessage();
FString curMsg = statusBar()->getMessage();
FString curMsg = getStatusBar()->getMessage();
if ( curMsg != msg )
{
statusBar()->setMessage(msg);
statusBar()->drawMessage();
getStatusBar()->setMessage(msg);
getStatusBar()->drawMessage();
}
}
}
@ -427,365 +789,3 @@ void FButton::processClick()
{
emitCallback("clicked");
}
// public methods of FButton
//----------------------------------------------------------------------
void FButton::setForegroundColor (short color)
{
FWidget::setForegroundColor(color);
updateButtonColor();
}
//----------------------------------------------------------------------
void FButton::setBackgroundColor (short color)
{
FWidget::setBackgroundColor(color);
updateButtonColor();
}
//----------------------------------------------------------------------
void FButton::setHotkeyForegroundColor (short color)
{
// valid colors -1..254
if ( color == fc::Default || color >> 8 == 0 )
button_hotkey_fg = color;
}
void FButton::setFocusForegroundColor (short color)
{
// valid colors -1..254
if ( color == fc::Default || color >> 8 == 0 )
button_focus_fg = color;
updateButtonColor();
}
//----------------------------------------------------------------------
void FButton::setFocusBackgroundColor (short color)
{
// valid colors -1..254
if ( color == fc::Default || color >> 8 == 0 )
button_focus_bg = color;
updateButtonColor();
}
//----------------------------------------------------------------------
void FButton::setInactiveForegroundColor (short color)
{
// valid colors -1..254
if ( color == fc::Default || color >> 8 == 0 )
button_inactive_fg = color;
updateButtonColor();
}
//----------------------------------------------------------------------
void FButton::setInactiveBackgroundColor (short color)
{
// valid colors -1..254
if ( color == fc::Default || color >> 8 == 0 )
button_inactive_bg = color;
updateButtonColor();
}
//----------------------------------------------------------------------
void FButton::hide()
{
int s, f, size;
short fg, bg;
char* blank;
FWidget* parent_widget = getParentWidget();
FWidget::hide();
if ( parent_widget )
{
fg = parent_widget->getForegroundColor();
bg = parent_widget->getBackgroundColor();
}
else
{
fg = wc.dialog_fg;
bg = wc.dialog_bg;
}
setColor (fg, bg);
s = hasShadow() ? 1 : 0;
f = isFlat() ? 1 : 0;
size = getWidth() + s + (f << 1);
if ( size < 0 )
return;
blank = new char[size+1];
std::memset(blank, ' ', uLong(size));
blank[size] = '\0';
for (int y=0; y < getHeight()+s+(f << 1); y++)
{
setPrintPos (1-f, 1+y-f);
print (blank);
}
delete[] blank;
}
//----------------------------------------------------------------------
bool FButton::setNoUnderline (bool on)
{
if ( on )
flags |= fc::no_underline;
else
flags &= ~fc::no_underline;
return on;
}
//----------------------------------------------------------------------
bool FButton::setEnable (bool on)
{
FWidget::setEnable(on);
if ( on )
{
flags |= fc::active;
setHotkeyAccelerator();
}
else
{
flags &= ~fc::active;
delAccelerator();
}
updateButtonColor();
return on;
}
//----------------------------------------------------------------------
bool FButton::setFocus (bool on)
{
FWidget::setFocus(on);
if ( on )
{
flags |= fc::focus;
if ( isEnabled() )
{
if ( statusBar() )
{
FString msg = getStatusbarMessage();
FString curMsg = statusBar()->getMessage();
if ( curMsg != msg )
statusBar()->setMessage(msg);
}
}
}
else
{
flags &= ~fc::focus;
if ( isEnabled() && statusBar() )
statusBar()->clearMessage();
}
updateButtonColor();
return on;
}
//----------------------------------------------------------------------
bool FButton::setFlat (bool on)
{
if ( on )
flags |= fc::flat;
else
flags &= ~fc::flat;
return on;
}
//----------------------------------------------------------------------
bool FButton::setShadow (bool on)
{
if ( on
&& (Encoding != fc::VT100 || isTeraTerm() )
&& Encoding != fc::ASCII )
flags |= fc::shadow;
else
flags &= ~fc::shadow;
return on;
}
//----------------------------------------------------------------------
bool FButton::setDown (bool on)
{
if ( button_down != on )
{
button_down = on;
redraw();
}
return on;
}
//----------------------------------------------------------------------
void FButton::onKeyPress (FKeyEvent* ev)
{
int key;
if ( ! isEnabled() )
return;
key = ev->key();
switch ( key )
{
case fc::Fkey_return:
case fc::Fkey_enter:
case fc::Fkey_space:
if ( click_animation )
{
setDown();
addTimer(click_time);
}
processClick();
ev->accept();
break;
default:
break;
}
}
//----------------------------------------------------------------------
void FButton::onMouseDown (FMouseEvent* ev)
{
if ( ev->getButton() != fc::LeftButton )
{
setUp();
return;
}
if ( ! hasFocus() )
{
FWidget* focused_widget = getFocusWidget();
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
setFocus();
if ( focused_widget )
focused_widget->redraw();
if ( statusBar() )
statusBar()->drawMessage();
}
FPoint tPos = ev->getTermPos();
if ( getTermGeometry().contains(tPos) )
setDown();
}
//----------------------------------------------------------------------
void FButton::onMouseUp (FMouseEvent* ev)
{
if ( ev->getButton() != fc::LeftButton )
return;
if ( button_down )
{
setUp();
if ( getTermGeometry().contains(ev->getTermPos()) )
processClick();
}
}
//----------------------------------------------------------------------
void FButton::onMouseMove (FMouseEvent* ev)
{
if ( ev->getButton() != fc::LeftButton )
return;
FPoint tPos = ev->getTermPos();
if ( click_animation )
{
if ( getTermGeometry().contains(tPos) )
setDown();
else
setUp();
}
}
//----------------------------------------------------------------------
void FButton::onTimer (FTimerEvent* ev)
{
delTimer(ev->timerId());
setUp();
}
//----------------------------------------------------------------------
void FButton::onAccel (FAccelEvent* ev)
{
if ( ! isEnabled() )
return;
if ( ! hasFocus() )
{
FWidget* focused_widget = static_cast<FWidget*>(ev->focusedWidget());
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
setFocus();
if ( focused_widget )
focused_widget->redraw();
if ( click_animation )
setDown();
else
redraw();
if ( statusBar() )
statusBar()->drawMessage();
}
else if ( click_animation )
setDown();
if ( click_animation )
addTimer(click_time);
processClick();
ev->accept();
}
//----------------------------------------------------------------------
void FButton::onFocusIn (FFocusEvent*)
{
if ( statusBar() )
statusBar()->drawMessage();
}
//----------------------------------------------------------------------
void FButton::onFocusOut (FFocusEvent*)
{
if ( statusBar() )
{
statusBar()->clearMessage();
statusBar()->drawMessage();
}
}
//----------------------------------------------------------------------
void FButton::setText (const FString& txt)
{
if ( txt )
text = txt;
else
text = "";
detectHotkey();
}

View File

@ -40,41 +40,19 @@
class FButton : public FWidget
{
private:
FString text;
bool button_down;
bool click_animation;
int click_time;
short button_fg;
short button_bg;
short button_hotkey_fg;
short button_focus_fg;
short button_focus_bg;
short button_inactive_fg;
short button_inactive_bg;
private:
// Disable copy constructor
FButton (const FButton&);
// Disable assignment operator (=)
FButton& operator = (const FButton&);
void init();
uChar getHotkey();
void setHotkeyAccelerator();
void detectHotkey();
void draw();
void updateButtonColor();
void processClick();
public:
// Constructors
explicit FButton (FWidget* = 0);
FButton (const FString&, FWidget* = 0);
// Destructor
virtual ~FButton();
// Accessors
const char* getClassName() const;
FString& getText();
// Mutators
void setForegroundColor (short);
void setBackgroundColor (short);
void setHotkeyForegroundColor (short);
@ -82,18 +60,6 @@ class FButton : public FWidget
void setFocusBackgroundColor (short);
void setInactiveForegroundColor (short);
void setInactiveBackgroundColor (short);
void hide();
// Event handlers
void onKeyPress (FKeyEvent*);
void onMouseDown (FMouseEvent*);
void onMouseUp (FMouseEvent*);
void onMouseMove (FMouseEvent*);
void onTimer (FTimerEvent*);
void onAccel (FAccelEvent*);
void onFocusIn (FFocusEvent*);
void onFocusOut (FFocusEvent*);
bool setNoUnderline(bool);
bool setNoUnderline();
bool unsetNoUnderline();
@ -107,22 +73,64 @@ class FButton : public FWidget
bool setFlat(bool);
bool setFlat();
bool unsetFlat();
bool isFlat() const;
bool setShadow(bool);
bool setShadow();
bool unsetShadow();
bool hasShadow() const;
bool setDown(bool);
bool setDown();
bool setUp();
bool isDown() const;
bool setClickAnimation(bool);
bool setClickAnimation();
bool unsetClickAnimation();
void setText (const FString&);
// Inquiries
bool isFlat() const;
bool isDown() const;
bool hasShadow() const;
bool hasClickAnimation();
void setText (const FString&);
FString& getText();
// Methods
void hide();
// Event handlers
void onKeyPress (FKeyEvent*);
void onMouseDown (FMouseEvent*);
void onMouseUp (FMouseEvent*);
void onMouseMove (FMouseEvent*);
void onTimer (FTimerEvent*);
void onAccel (FAccelEvent*);
void onFocusIn (FFocusEvent*);
void onFocusOut (FFocusEvent*);
private:
// Disable copy constructor
FButton (const FButton&);
// Disable assignment operator (=)
FButton& operator = (const FButton&);
// Methods
void init();
uChar getHotkey();
void setHotkeyAccelerator();
void detectHotkey();
void draw();
void updateButtonColor();
void processClick();
// Data Members
FString text;
bool button_down;
bool click_animation;
int click_time;
short button_fg;
short button_bg;
short button_hotkey_fg;
short button_focus_fg;
short button_focus_bg;
short button_inactive_fg;
short button_inactive_bg;
};
#pragma pack(pop)
@ -132,6 +140,10 @@ class FButton : public FWidget
inline const char* FButton::getClassName() const
{ return "FButton"; }
//----------------------------------------------------------------------
inline FString& FButton::getText()
{ return text; }
//----------------------------------------------------------------------
inline bool FButton::setNoUnderline()
{ return setNoUnderline(true); }
@ -168,10 +180,6 @@ inline bool FButton::setFlat()
inline bool FButton::unsetFlat()
{ return setFlat(false); }
//----------------------------------------------------------------------
inline bool FButton::isFlat() const
{ return ((flags & fc::flat) != 0); }
//----------------------------------------------------------------------
inline bool FButton::setShadow()
{ return setShadow(true); }
@ -180,10 +188,6 @@ inline bool FButton::setShadow()
inline bool FButton::unsetShadow()
{ return setShadow(false); }
//----------------------------------------------------------------------
inline bool FButton::hasShadow() const
{ return ((flags & fc::shadow) != 0); }
//----------------------------------------------------------------------
inline bool FButton::setDown()
{ return setDown(true); }
@ -192,10 +196,6 @@ inline bool FButton::setDown()
inline bool FButton::setUp()
{ return setDown(false); }
//----------------------------------------------------------------------
inline bool FButton::isDown() const
{ return button_down; }
//----------------------------------------------------------------------
inline bool FButton::setClickAnimation(bool on)
{ return click_animation = on; }
@ -208,12 +208,20 @@ inline bool FButton::setClickAnimation()
inline bool FButton::unsetClickAnimation()
{ return setClickAnimation(false); }
//----------------------------------------------------------------------
inline bool FButton::isFlat() const
{ return ((flags & fc::flat) != 0); }
//----------------------------------------------------------------------
inline bool FButton::isDown() const
{ return button_down; }
//----------------------------------------------------------------------
inline bool FButton::hasShadow() const
{ return ((flags & fc::shadow) != 0); }
//----------------------------------------------------------------------
inline bool FButton::hasClickAnimation()
{ return click_animation; }
//----------------------------------------------------------------------
inline FString& FButton::getText()
{ return text; }
#endif // _FBUTTON_H

View File

@ -36,7 +36,7 @@ FButtonGroup::FButtonGroup (const FString& txt, FWidget* parent)
//----------------------------------------------------------------------
FButtonGroup::~FButtonGroup() // destructor
{
FButtonGroup::FButtonList::iterator iter;
FButtonList::iterator iter;
if ( buttonlist.empty() )
return;
@ -50,43 +50,255 @@ FButtonGroup::~FButtonGroup() // destructor
}
}
// private methods of FButtonGroup
// public methods of FButtonGroup
//----------------------------------------------------------------------
void FButtonGroup::init()
FToggleButton* FButtonGroup::getFirstButton()
{
setTopPadding(1);
setLeftPadding(1);
setBottomPadding(1);
setRightPadding(1);
if ( buttonlist.empty() )
return 0;
FButtonList::const_iterator iter, end;
iter = buttonlist.begin();
end = buttonlist.end();
while ( iter != end )
{
if ( (*iter)->isEnabled() && (*iter)->acceptFocus() )
return (*iter);
++iter;
}
return 0;
}
//----------------------------------------------------------------------
FToggleButton* FButtonGroup::getLastButton()
{
if ( buttonlist.empty() )
return 0;
FButtonList::const_iterator iter, begin;
begin = buttonlist.begin();
iter = buttonlist.end();
do
{
--iter;
if ( (*iter)->isEnabled() && (*iter)->acceptFocus() )
return (*iter);
}
while ( iter != begin );
return 0;
}
//----------------------------------------------------------------------
bool FButtonGroup::setEnable (bool on)
{
FWidget::setEnable(on);
if ( on )
{
flags |= fc::active;
setHotkeyAccelerator();
}
else
{
flags &= ~fc::active;
delAccelerator();
}
return on;
}
//----------------------------------------------------------------------
bool FButtonGroup::setBorder(bool on)
{
if ( on )
border = true;
else
border = false;
return on;
}
//----------------------------------------------------------------------
void FButtonGroup::setText (const FString& txt)
{
text = txt;
if ( isEnabled() )
flags |= fc::active;
setForegroundColor (wc.label_fg);
setBackgroundColor (wc.label_bg);
buttonlist.clear(); // no buttons yet
{
delAccelerator();
setHotkeyAccelerator();
}
}
//----------------------------------------------------------------------
bool FButtonGroup::isRadioButton(FToggleButton* button) const
bool FButtonGroup::hasFocusedButton()
{
if ( ! button )
if ( buttonlist.empty() )
return false;
return bool ( std::strcmp ( button->getClassName()
, const_cast<char*>("FRadioButton") ) == 0 );
FButtonList::const_iterator iter, end;
iter = buttonlist.begin();
end = buttonlist.end();
while ( iter != end )
{
if ( (*iter)->hasFocus() )
return true;
++iter;
}
return false;
}
//----------------------------------------------------------------------
void FButtonGroup::directFocus()
bool FButtonGroup::hasCheckedButton()
{
if ( ! hasFocusedButton() )
{
bool found_checked = false;
if ( buttonlist.empty() )
return false;
FButtonList::const_iterator iter, end;
iter = buttonlist.begin();
end = buttonlist.end();
while ( iter != end )
{
if ( (*iter)->isChecked() )
return true;
++iter;
}
return false;
}
//----------------------------------------------------------------------
void FButtonGroup::hide()
{
int size;
short fg, bg;
char* blank;
FWidget::hide();
FWidget* parent_widget = getParentWidget();
if ( ! buttonlist.empty() )
{
FButtonList::const_iterator iter, end;
iter = buttonlist.begin();
end = buttonlist.end();
while ( iter != end )
{
(*iter)->hide();
++iter;
}
}
if ( parent_widget )
{
fg = parent_widget->getForegroundColor();
bg = parent_widget->getBackgroundColor();
}
else
{
fg = wc.dialog_fg;
bg = wc.dialog_bg;
}
setColor (fg, bg);
size = getWidth();
if ( size < 0 )
return;
blank = new char[size+1];
std::memset(blank, ' ', uLong(size));
blank[size] = '\0';
for (int y=0; y < getHeight(); y++)
{
setPrintPos (1, 1+y);
print (blank);
}
delete[] blank;
}
//----------------------------------------------------------------------
void FButtonGroup::insert (FToggleButton* button)
{
if ( ! button )
return;
if ( button->getGroup() )
button->getGroup()->remove(button);
// setChecked the first FRadioButton
if ( buttonlist.size() == 1 && isRadioButton(*buttonlist.begin()) )
(*buttonlist.begin())->setChecked();
button->setGroup(this);
buttonlist.push_back(button);
button->addCallback
(
"toggled",
_METHOD_CALLBACK (this, &FButtonGroup::cb_buttonToggled)
);
}
//----------------------------------------------------------------------
void FButtonGroup::remove (FToggleButton* button)
{
FButtonList::iterator iter;
if ( ! button || buttonlist.empty() )
return;
iter = buttonlist.begin();
while ( iter != buttonlist.end() )
{
if ( (*iter) == button )
{
iter = buttonlist.erase(iter);
button->setGroup(0);
button->delCallback(this);
break;
}
else
++iter;
}
}
//----------------------------------------------------------------------
void FButtonGroup::onMouseDown (FMouseEvent* ev)
{
if ( ev->getButton() != fc::LeftButton )
return;
directFocus();
}
//----------------------------------------------------------------------
void FButtonGroup::onAccel (FAccelEvent*)
{
directFocus();
}
//----------------------------------------------------------------------
void FButtonGroup::onFocusIn (FFocusEvent* in_ev)
{
if ( hasCheckedButton() && ! buttonlist.empty() )
{
FButtonGroup::FButtonList::const_iterator iter, end;
FButtonList::const_iterator iter, end;
iter = buttonlist.begin();
end = buttonlist.end();
@ -96,19 +308,14 @@ void FButtonGroup::directFocus()
{
if ( isRadioButton(*iter) )
{
found_checked = true;
FWidget* focused_widget = getFocusWidget();
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
in_ev->ignore();
FWidget* prev_element = getFocusWidget();
(*iter)->setFocus();
if ( focused_widget )
focused_widget->redraw();
if ( prev_element )
prev_element->redraw();
focused_widget = getFocusWidget();
if ( focused_widget )
focused_widget->redraw();
(*iter)->redraw();
}
break;
@ -118,53 +325,79 @@ void FButtonGroup::directFocus()
}
}
if ( ! found_checked )
if ( in_ev->isAccepted() )
{
FWidget* focused_widget = getFocusWidget();
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
if ( in_ev->getFocusType() == fc::FocusNextWidget )
{
in_ev->ignore();
FWidget* prev_element = getFocusWidget();
focusFirstChild();
if ( focused_widget )
focused_widget->redraw();
if ( prev_element )
prev_element->redraw();
focused_widget = getFocusWidget();
if ( focused_widget )
focused_widget->redraw();
if ( getFocusWidget() )
getFocusWidget()->redraw();
}
}
if ( statusBar() )
else if ( in_ev->getFocusType() == fc::FocusPreviousWidget )
{
statusBar()->drawMessage();
in_ev->ignore();
FWidget* prev_element = getFocusWidget();
focusLastChild();
if ( prev_element )
prev_element->redraw();
if ( getFocusWidget() )
getFocusWidget()->redraw();
}
}
if ( getStatusBar() )
{
getStatusBar()->drawMessage();
updateTerminal();
flush_out();
}
}
// protected methods of FButtonGroup
//----------------------------------------------------------------------
void FButtonGroup::draw()
void FButtonGroup::onFocusOut (FFocusEvent*)
{ }
//----------------------------------------------------------------------
void FButtonGroup::cb_buttonToggled (FWidget* widget, void*)
{
updateVTerm(false);
FToggleButton* button = static_cast<FToggleButton*>(widget);
FButtonList::const_iterator iter, end;
if ( isMonochron() )
setReverse(true);
if ( ! button->isChecked() )
return;
setColor();
if ( buttonlist.empty() )
return;
if ( border )
drawBorder();
iter = buttonlist.begin();
end = buttonlist.end();
drawLabel();
while ( iter != end )
{
if ( (*iter) != button
&& (*iter)->isChecked()
&& isRadioButton(*iter) )
{
(*iter)->unsetChecked();
if ( isMonochron() )
setReverse(false);
if ( (*iter)->isVisible() && (*iter)->isShown() )
(*iter)->redraw();
}
updateVTerm(true);
++iter;
}
}
// protected methods of FButtonGroup
//----------------------------------------------------------------------
uChar FButtonGroup::getHotkey()
{
@ -211,6 +444,27 @@ void FButtonGroup::setHotkeyAccelerator()
delAccelerator();
}
//----------------------------------------------------------------------
void FButtonGroup::draw()
{
updateVTerm(false);
if ( isMonochron() )
setReverse(true);
setColor();
if ( border )
drawBorder();
drawLabel();
if ( isMonochron() )
setReverse(false);
updateVTerm(true);
}
//----------------------------------------------------------------------
void FButtonGroup::drawLabel()
{
@ -284,243 +538,44 @@ void FButtonGroup::drawLabel()
delete[] LabelText;
}
// public methods of FButtonGroup
// private methods of FButtonGroup
//----------------------------------------------------------------------
void FButtonGroup::hide()
{
int size;
short fg, bg;
char* blank;
FWidget::hide();
FWidget* parent_widget = getParentWidget();
if ( ! buttonlist.empty() )
{
FButtonGroup::FButtonList::const_iterator iter, end;
iter = buttonlist.begin();
end = buttonlist.end();
while ( iter != end )
{
(*iter)->hide();
++iter;
}
}
if ( parent_widget )
{
fg = parent_widget->getForegroundColor();
bg = parent_widget->getBackgroundColor();
}
else
{
fg = wc.dialog_fg;
bg = wc.dialog_bg;
}
setColor (fg, bg);
size = getWidth();
if ( size < 0 )
return;
blank = new char[size+1];
std::memset(blank, ' ', uLong(size));
blank[size] = '\0';
for (int y=0; y < getHeight(); y++)
{
setPrintPos (1, 1+y);
print (blank);
}
delete[] blank;
}
//----------------------------------------------------------------------
void FButtonGroup::insert (FToggleButton* button)
bool FButtonGroup::isRadioButton(FToggleButton* button) const
{
if ( ! button )
return;
if ( button->group() )
button->group()->remove(button);
// setChecked the first FRadioButton
if ( buttonlist.size() == 1 && isRadioButton(*buttonlist.begin()) )
(*buttonlist.begin())->setChecked();
button->setGroup(this);
buttonlist.push_back(button);
button->addCallback
(
"toggled",
_METHOD_CALLBACK (this, &FButtonGroup::cb_buttonToggled)
);
}
//----------------------------------------------------------------------
void FButtonGroup::remove (FToggleButton* button)
{
FButtonGroup::FButtonList::iterator iter;
if ( ! button || buttonlist.empty() )
return;
iter = buttonlist.begin();
while ( iter != buttonlist.end() )
{
if ( (*iter) == button )
{
iter = buttonlist.erase(iter);
button->setGroup(0);
button->delCallback(this);
break;
}
else
++iter;
}
}
//----------------------------------------------------------------------
void FButtonGroup::cb_buttonToggled (FWidget* widget, void*)
{
FToggleButton* button = static_cast<FToggleButton*>(widget);
FButtonGroup::FButtonList::const_iterator iter, end;
if ( ! button->isChecked() )
return;
if ( buttonlist.empty() )
return;
iter = buttonlist.begin();
end = buttonlist.end();
while ( iter != end )
{
if ( (*iter) != button
&& (*iter)->isChecked()
&& isRadioButton(*iter) )
{
(*iter)->unsetChecked();
if ( (*iter)->isVisible() && (*iter)->isShown() )
(*iter)->redraw();
}
++iter;
}
}
//----------------------------------------------------------------------
FToggleButton* FButtonGroup::getFirstButton()
{
if ( buttonlist.empty() )
return 0;
FButtonGroup::FButtonList::const_iterator iter, end;
iter = buttonlist.begin();
end = buttonlist.end();
while ( iter != end )
{
if ( (*iter)->isEnabled() && (*iter)->acceptFocus() )
return (*iter);
++iter;
}
return 0;
}
//----------------------------------------------------------------------
FToggleButton* FButtonGroup::getLastButton()
{
if ( buttonlist.empty() )
return 0;
FButtonGroup::FButtonList::const_iterator iter, begin;
begin = buttonlist.begin();
iter = buttonlist.end();
do
{
--iter;
if ( (*iter)->isEnabled() && (*iter)->acceptFocus() )
return (*iter);
}
while ( iter != begin );
return 0;
}
//----------------------------------------------------------------------
bool FButtonGroup::hasFocusedButton()
{
if ( buttonlist.empty() )
return false;
FButtonGroup::FButtonList::const_iterator iter, end;
iter = buttonlist.begin();
end = buttonlist.end();
return bool ( std::strcmp ( button->getClassName()
, const_cast<char*>("FRadioButton") ) == 0 );
}
while ( iter != end )
//----------------------------------------------------------------------
void FButtonGroup::init()
{
setTopPadding(1);
setLeftPadding(1);
setBottomPadding(1);
setRightPadding(1);
if ( isEnabled() )
flags |= fc::active;
setForegroundColor (wc.label_fg);
setBackgroundColor (wc.label_bg);
buttonlist.clear(); // no buttons yet
}
//----------------------------------------------------------------------
void FButtonGroup::directFocus()
{
if ( ! hasFocusedButton() )
{
if ( (*iter)->hasFocus() )
return true;
bool found_checked = false;
++iter;
}
return false;
}
//----------------------------------------------------------------------
bool FButtonGroup::hasCheckedButton()
{
if ( buttonlist.empty() )
return false;
FButtonGroup::FButtonList::const_iterator iter, end;
iter = buttonlist.begin();
end = buttonlist.end();
while ( iter != end )
{
if ( (*iter)->isChecked() )
return true;
++iter;
}
return false;
}
//----------------------------------------------------------------------
void FButtonGroup::onMouseDown (FMouseEvent* ev)
{
if ( ev->getButton() != fc::LeftButton )
return;
directFocus();
}
//----------------------------------------------------------------------
void FButtonGroup::onAccel (FAccelEvent*)
{
directFocus();
}
//----------------------------------------------------------------------
void FButtonGroup::onFocusIn (FFocusEvent* in_ev)
{
if ( hasCheckedButton() && ! buttonlist.empty() )
{
FButtonGroup::FButtonList::const_iterator iter, end;
FButtonList::const_iterator iter, end;
iter = buttonlist.begin();
end = buttonlist.end();
@ -530,14 +585,19 @@ void FButtonGroup::onFocusIn (FFocusEvent* in_ev)
{
if ( isRadioButton(*iter) )
{
in_ev->ignore();
FWidget* prev_element = getFocusWidget();
found_checked = true;
FWidget* focused_widget = getFocusWidget();
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
(*iter)->setFocus();
if ( prev_element )
prev_element->redraw();
if ( focused_widget )
focused_widget->redraw();
(*iter)->redraw();
focused_widget = getFocusWidget();
if ( focused_widget )
focused_widget->redraw();
}
break;
@ -547,84 +607,27 @@ void FButtonGroup::onFocusIn (FFocusEvent* in_ev)
}
}
if ( in_ev->isAccepted() )
if ( ! found_checked )
{
if ( in_ev->getFocusType() == fc::FocusNextWidget )
{
in_ev->ignore();
FWidget* prev_element = getFocusWidget();
FWidget* focused_widget = getFocusWidget();
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
focusFirstChild();
if ( prev_element )
prev_element->redraw();
if ( focused_widget )
focused_widget->redraw();
if ( getFocusWidget() )
getFocusWidget()->redraw();
focused_widget = getFocusWidget();
if ( focused_widget )
focused_widget->redraw();
}
else if ( in_ev->getFocusType() == fc::FocusPreviousWidget )
}
if ( getStatusBar() )
{
in_ev->ignore();
FWidget* prev_element = getFocusWidget();
focusLastChild();
if ( prev_element )
prev_element->redraw();
if ( getFocusWidget() )
getFocusWidget()->redraw();
}
}
if ( statusBar() )
{
statusBar()->drawMessage();
getStatusBar()->drawMessage();
updateTerminal();
flush_out();
}
}
//----------------------------------------------------------------------
void FButtonGroup::onFocusOut (FFocusEvent*)
{ }
//----------------------------------------------------------------------
bool FButtonGroup::setEnable (bool on)
{
FWidget::setEnable(on);
if ( on )
{
flags |= fc::active;
setHotkeyAccelerator();
}
else
{
flags &= ~fc::active;
delAccelerator();
}
return on;
}
//----------------------------------------------------------------------
bool FButtonGroup::setBorder(bool on)
{
if ( on )
border = true;
else
border = false;
return on;
}
//----------------------------------------------------------------------
void FButtonGroup::setText (const FString& txt)
{
text = txt;
if ( isEnabled() )
{
delAccelerator();
setHotkeyAccelerator();
}
}

View File

@ -43,55 +43,21 @@ class FToggleButton;
class FButtonGroup : public FWidget
{
private:
FString text;
bool border;
typedef std::vector<FToggleButton*> FButtonList;
FButtonGroup::FButtonList buttonlist;
private:
// Disable copy constructor
FButtonGroup (const FButtonGroup&);
// Disable assignment operator (=)
FButtonGroup& operator = (const FButtonGroup&);
void init();
bool isRadioButton(FToggleButton*) const;
void directFocus();
protected:
virtual void draw();
uChar getHotkey();
void setHotkeyAccelerator();
void drawLabel();
public:
// Constructors
explicit FButtonGroup (FWidget* = 0);
FButtonGroup (const FString&, FWidget* = 0);
// Destructor
virtual ~FButtonGroup();
// Accessor
const char* getClassName() const;
void hide();
FToggleButton* getFirstButton();
FToggleButton* getLastButton();
bool hasFocusedButton();
bool hasCheckedButton();
// Event handlers
void onMouseDown (FMouseEvent*);
void onAccel (FAccelEvent*);
void onFocusIn (FFocusEvent*);
void onFocusOut (FFocusEvent*);
void insert (FToggleButton*);
void remove (FToggleButton*);
// Callback method
void cb_buttonToggled (FWidget*, void*);
FString& getText();
// Mutator
bool setEnable(bool);
bool setEnable();
bool unsetEnable();
@ -100,7 +66,57 @@ class FButtonGroup : public FWidget
bool setBorder();
bool unsetBorder();
void setText (const FString&);
FString& getText();
// Inquiries
bool hasFocusedButton();
bool hasCheckedButton();
// Methods
void hide();
void insert (FToggleButton*);
void remove (FToggleButton*);
// Event handlers
void onMouseDown (FMouseEvent*);
void onAccel (FAccelEvent*);
void onFocusIn (FFocusEvent*);
void onFocusOut (FFocusEvent*);
// Callback method
void cb_buttonToggled (FWidget*, void*);
protected:
// Accessor
uChar getHotkey();
// Mutator
void setHotkeyAccelerator();
// Methods
virtual void draw();
void drawLabel();
private:
// Typedef
typedef std::vector<FToggleButton*> FButtonList;
// Disable copy constructor
FButtonGroup (const FButtonGroup&);
// Disable assignment operator (=)
FButtonGroup& operator = (const FButtonGroup&);
// Inquiries
bool isRadioButton(FToggleButton*) const;
// Methods
void init();
void directFocus();
// Data Members
FString text;
bool border;
FButtonList buttonlist;
};
#pragma pack(pop)

View File

@ -45,24 +45,28 @@
class FCheckBox : public FToggleButton
{
private:
// Disable copy constructor
FCheckBox (const FCheckBox&);
// Disable assignment operator (=)
FCheckBox& operator = (const FCheckBox&);
void init();
void draw();
void drawCheckButton();
public:
// Constructors
explicit FCheckBox (FWidget* = 0);
FCheckBox (const FString&, FWidget* = 0);
// Destructor
virtual ~FCheckBox();
// Accessor
const char* getClassName() const;
private:
// Disable copy constructor
FCheckBox (const FCheckBox&);
// Disable assignment operator (=)
FCheckBox& operator = (const FCheckBox&);
// Methods
void init();
void draw();
void drawCheckButton();
};
#pragma pack(pop)

View File

@ -45,26 +45,30 @@
class FCheckMenuItem : public FMenuItem
{
private:
// Disable copy constructor
FCheckMenuItem (const FCheckMenuItem&);
// Disable assignment operator (=)
FCheckMenuItem& operator = (const FCheckMenuItem&);
void init (FWidget*);
void processToggle();
void processClicked();
public:
// Constructor
// Constructors
explicit FCheckMenuItem (FWidget* = 0);
FCheckMenuItem (FString&, FWidget* = 0);
FCheckMenuItem (const std::string&, FWidget* = 0);
FCheckMenuItem (const char*, FWidget* = 0);
// Destructor
virtual ~FCheckMenuItem();
// Accessor
const char* getClassName() const;
private:
// Disable copy constructor
FCheckMenuItem (const FCheckMenuItem&);
// Disable assignment operator (=)
FCheckMenuItem& operator = (const FCheckMenuItem&);
// Methods
void init (FWidget*);
void processToggle();
void processClicked();
};
#pragma pack(pop)

File diff suppressed because it is too large Load Diff

View File

@ -49,66 +49,57 @@
class FDialog : public FWindow
{
public:
// Using-declaration
using FWindow::setResizeable;
using FWindow::move;
using FWindow::setPos;
// Enumeration
enum DialogCode
{
Reject = 0,
Accept = 1
};
private:
FString tb_text; // title bar text
int result_code;
bool zoom_button_pressed;
bool zoom_button_active;
FPoint titlebar_click_pos;
FPoint resize_click_pos;
FRect save_geometry; // required by move/size by keyboard
FMenu* dialog_menu;
FMenuItem* dgl_menuitem;
FMenuItem* move_size_item;
FMenuItem* zoom_item;
FMenuItem* close_item;
FToolTip* tooltip;
private:
// Disable copy constructor
FDialog (const FDialog&);
// Disable assignment operator (=)
FDialog& operator = (const FDialog&);
void init();
// make every drawBorder from FWidget available
using FWidget::drawBorder;
virtual void drawBorder();
void drawTitleBar();
void leaveMenu();
void openMenu();
void selectFirstMenuItem();
void setZoomItem();
// Callback methods
void cb_move (FWidget*, void*);
void cb_zoom (FWidget*, void*);
void cb_close (FWidget*, void*);
static void addDialog (FWidget*);
static void delDialog (FWidget*);
protected:
virtual void done (int);
virtual void draw();
virtual void onShow (FShowEvent*);
virtual void onHide (FHideEvent*);
virtual void onClose (FCloseEvent*);
public:
// Constructors
explicit FDialog (FWidget* = 0);
FDialog (const FString&, FWidget* = 0);
// Destructor
virtual ~FDialog();
// Accessors
virtual const char* getClassName() const;
FString getText() const;
// Mutators
bool setFocus (bool);
bool setFocus();
bool unsetFocus();
bool setDialogWidget (bool);
bool setDialogWidget();
bool unsetDialogWidget();
bool setModal (bool);
bool setModal();
bool unsetModal();
bool setResizeable (bool);
bool setScrollable (bool);
bool setScrollable();
bool unsetScrollable();
void setText (const FString&);
// Inquiries
bool isModal();
bool isScrollable();
// Methods
void show();
void hide();
int exec();
void setPos (int, int, bool = true);
void move (int, int);
void setSize (int, int, bool = true);
void activateDialog();
// Event handlers
void onKeyPress (FKeyEvent*);
@ -122,40 +113,58 @@ class FDialog : public FWindow
void onWindowRaised (FEvent*);
void onWindowLowered (FEvent*);
void activateDialog();
protected:
// Methods
virtual void done (int);
virtual void draw();
void drawDialogShadow();
void show();
void hide();
int exec();
void setPos (int, int, bool = true);
// make every setPos from FWindow available
using FWindow::setPos;
void move (int, int);
// make every move from FWindow available
using FWindow::move;
void setSize (int, int, bool = true);
bool setFocus (bool);
bool setFocus();
bool unsetFocus();
bool setDialogWidget (bool);
bool setDialogWidget();
bool unsetDialogWidget();
bool setModal (bool);
bool setModal();
bool unsetModal();
bool isModal();
bool setResizeable (bool);
// make every setResizeable from FWindow available
using FWindow::setResizeable;
bool setScrollable (bool);
bool setScrollable();
bool unsetScrollable();
bool isScrollable();
FString getText() const;
void setText (const FString&);
// Event handlers
virtual void onShow (FShowEvent*);
virtual void onHide (FHideEvent*);
virtual void onClose (FCloseEvent*);
private:
// Using-declaration
using FWidget::drawBorder;
// Disable copy constructor
FDialog (const FDialog&);
// Disable assignment operator (=)
FDialog& operator = (const FDialog&);
// Methods
void init();
virtual void drawBorder();
void drawTitleBar();
void leaveMenu();
void openMenu();
void selectFirstMenuItem();
void setZoomItem();
static void addDialog (FWidget*);
static void delDialog (FWidget*);
// Callback methods
void cb_move (FWidget*, void*);
void cb_zoom (FWidget*, void*);
void cb_close (FWidget*, void*);
// Data Members
FString tb_text; // title bar text
int result_code;
bool zoom_button_pressed;
bool zoom_button_active;
FPoint titlebar_click_pos;
FPoint resize_click_pos;
FRect save_geometry; // required by keyboard move/size
FMenu* dialog_menu;
FMenuItem* dgl_menuitem;
FMenuItem* move_size_item;
FMenuItem* zoom_item;
FMenuItem* close_item;
FToolTip* tooltip;
// Friend function from FMenu
friend void FMenu::hideSuperMenus();
};
@ -166,6 +175,10 @@ class FDialog : public FWindow
inline const char* FDialog::getClassName() const
{ return "FDialog"; }
//----------------------------------------------------------------------
inline FString FDialog::getText() const
{ return tb_text; }
//----------------------------------------------------------------------
inline bool FDialog::setFocus()
{ return setFocus(true); }
@ -190,10 +203,6 @@ inline bool FDialog::setModal()
inline bool FDialog::unsetModal()
{ return setModal(false); }
//----------------------------------------------------------------------
inline bool FDialog::isModal()
{ return ((flags & fc::modal) != 0); }
//----------------------------------------------------------------------
inline bool FDialog::setScrollable()
{ return setScrollable(true); }
@ -202,17 +211,18 @@ inline bool FDialog::setScrollable()
inline bool FDialog::unsetScrollable()
{ return setScrollable(false); }
//----------------------------------------------------------------------
inline bool FDialog::isScrollable()
{ return ((flags & fc::scrollable) != 0); }
//----------------------------------------------------------------------
inline FString FDialog::getText() const
{ return tb_text; }
//----------------------------------------------------------------------
inline void FDialog::setText (const FString& txt)
{ tb_text = txt; }
//----------------------------------------------------------------------
inline bool FDialog::isModal()
{ return ((flags & fc::modal) != 0); }
//----------------------------------------------------------------------
inline bool FDialog::isScrollable()
{ return ((flags & fc::scrollable) != 0); }
#endif // _FDIALOG_H

View File

@ -52,24 +52,28 @@
class FDialogListMenu : public FMenu
{
private:
// Disable copy constructor
FDialogListMenu (const FDialogListMenu&);
// Disable assignment operator (=)
FDialogListMenu& operator = (const FDialogListMenu&);
void init();
public:
// Constructors
explicit FDialogListMenu (FWidget* = 0);
FDialogListMenu (FString&, FWidget* = 0);
FDialogListMenu (const std::string&, FWidget* = 0);
FDialogListMenu (const char*, FWidget* = 0);
// Destructor
virtual ~FDialogListMenu();
// Accessors
virtual const char* getClassName() const;
private:
// Disable copy constructor
FDialogListMenu (const FDialogListMenu&);
// Disable assignment operator (=)
FDialogListMenu& operator = (const FDialogListMenu&);
// Method
void init();
};
#pragma pack(pop)

View File

@ -3,15 +3,18 @@
#include "ffiledialog.h"
// non-member functions
//----------------------------------------------------------------------
static bool sortByName (const dir_entry &lhs, const dir_entry &rhs)
bool sortByName ( const FFileDialog::dir_entry& lhs
, const FFileDialog::dir_entry& rhs )
{
// lhs < rhs
return bool(strcasecmp(lhs.name, rhs.name) < 0);
}
//----------------------------------------------------------------------
static bool sortDirFirst (const dir_entry &lhs, const dir_entry &rhs)
bool sortDirFirst ( const FFileDialog::dir_entry& lhs
, const FFileDialog::dir_entry& rhs )
{
// sort directories first
if ( lhs.type == DT_DIR && rhs.type != DT_DIR )
@ -101,6 +104,366 @@ FFileDialog::~FFileDialog() // destructor
}
// public methods of FFileDialog
//----------------------------------------------------------------------
FFileDialog& FFileDialog::operator = (const FFileDialog& fdlg)
{
if ( &fdlg == this )
{
return *this;
}
else
{
delete open;
delete cancel;
delete hidden;
delete filebrowser;
delete filename;
clear();
if ( fdlg.getParentWidget() )
fdlg.getParentWidget()->addChild (this);
directory = fdlg.directory;
filter_pattern = fdlg.filter_pattern;
dlg_type = fdlg.dlg_type;
show_hidden = fdlg.show_hidden;
if ( directory )
setPath(directory);
init();
return *this;
}
}
//----------------------------------------------------------------------
const FString FFileDialog::getSelectedFile() const
{
uLong n = uLong(filebrowser->currentItem() - 1);
if ( dir_entries[n].type == DT_DIR )
return FString("");
else
return FString(dir_entries[n].name);
}
//----------------------------------------------------------------------
void FFileDialog::setPath (const FString& dir)
{
const char* dirname = dir.c_str();
char resolved_path[MAXPATHLEN];
FString r_dir;
struct stat sb;
if ( stat(dirname, &sb) != 0 )
{
directory = '/';
return;
}
if ( S_ISLNK(sb.st_mode) )
{
if ( lstat(dirname, &sb) != 0 )
{
directory = '/';
return;
}
}
if ( ! S_ISDIR(sb.st_mode) )
{
directory = '/';
return;
}
if ( realpath(dir.c_str(), resolved_path) != 0 )
r_dir = resolved_path;
else
r_dir = dir;
if ( r_dir[r_dir.getLength()-1] != '/' )
directory = r_dir + "/";
else
directory = r_dir;
}
//----------------------------------------------------------------------
void FFileDialog::setFilter (const FString& filter)
{
filter_pattern = filter;
}
//----------------------------------------------------------------------
bool FFileDialog::setShowHiddenFiles (bool on)
{
if ( on == show_hidden )
return show_hidden;
show_hidden = on;
readDir();
filebrowser->redraw();
return show_hidden;
}
//----------------------------------------------------------------------
void FFileDialog::onKeyPress (FKeyEvent* ev)
{
if ( ! isEnabled() )
return;
FDialog::onKeyPress (ev);
if ( ! filebrowser->hasFocus() )
return;
int key = ev->key();
switch ( key )
{
case fc::Fkey_erase:
case fc::Fkey_backspace:
changeDir("..");
ev->accept();
break;
default:
break;
}
}
//----------------------------------------------------------------------
int FFileDialog::readDir()
{
int start, dir_num;
const char* dir = directory.c_str();
const char* filter = filter_pattern.c_str();
errno = 0;
directory_stream = opendir(dir);
if ( ! directory_stream )
{
FMessageBox::error (this, "Can't open directory\n" + directory);
return -1;
}
clear();
while ( true )
{
errno = 0;
struct dirent* next = readdir (directory_stream);
if ( next )
{
if ( next->d_name[0] == '.' && next->d_name[1] == '\0' )
continue;
if ( ! show_hidden
&& next->d_name[0] == '.'
&& next->d_name[1] != '\0'
&& next->d_name[1] != '.' )
{
continue;
}
if ( dir[0] == '/' && dir[1] == '\0' && std::strcmp(next->d_name, "..") == 0 )
continue;
dir_entry entry;
entry.name = strdup(next->d_name);
entry.type = next->d_type;
if ( next->d_type == DT_LNK ) // symbolic link
{
char resolved_path[MAXPATHLEN] = {};
char symLink[MAXPATHLEN] = {};
std::strncpy (symLink, dir, sizeof(symLink) - 1);
std::strncat (symLink, next->d_name, sizeof(symLink) - std::strlen(symLink) - 1);
if ( realpath(symLink, resolved_path) != 0 ) // follow link
{
struct stat sb;
if ( lstat(resolved_path, &sb) == 0 )
{
if ( S_ISDIR(sb.st_mode) )
entry.type = DT_DIR;
}
}
}
if ( entry.type == DT_DIR )
dir_entries.push_back (entry);
else if ( pattern_match(filter, entry.name) )
dir_entries.push_back (entry);
else
std::free(entry.name);
}
else if (errno != 0)
{
FMessageBox::error (this, "Reading directory\n" + directory);
if ( errno != EOVERFLOW )
break;
}
else
break;
} // end while
if ( closedir (directory_stream) != 0 )
{
FMessageBox::error (this, "Closing directory\n" + directory);
return -2;
}
if ( std::strcmp((*dir_entries.begin()).name, "..") == 0 )
start=1;
else
start=0;
dir_num = numOfDirs();
// directories first
std::sort(dir_entries.begin()+start, dir_entries.end(), sortDirFirst);
// sort directories by name
std::sort(dir_entries.begin()+start, dir_entries.begin()+dir_num, sortByName);
// sort files by name
std::sort(dir_entries.begin()+dir_num, dir_entries.end(), sortByName);
// fill list with directory entries
filebrowser->clear();
if ( ! dir_entries.empty() )
{
std::vector<dir_entry>::const_iterator iter, end;
iter = dir_entries.begin();
end = dir_entries.end();
while ( iter != end )
{
if ( (*iter).type == DT_DIR )
filebrowser->insert(FString((*iter).name), fc::SquareBrackets);
else
filebrowser->insert(FString((*iter).name));
++iter;
}
}
return 0;
}
//----------------------------------------------------------------------
FString FFileDialog::fileOpenChooser ( FWidget* parent
, const FString& dirname
, const FString& filter )
{
FFileDialog* fileopen;
FString ret;
FString path = dirname;
FString file_filter = filter;
if ( path.isNull() || path.isEmpty() )
{
path = getHomeDir();
if ( path.isEmpty() || path.isEmpty() )
path = FString("/");
}
if ( file_filter.isNull() || file_filter.isEmpty() )
file_filter = FString("*");
fileopen = new FFileDialog ( path
, file_filter
, FFileDialog::Open
, parent );
if ( fileopen->exec() == FDialog::Accept )
ret = fileopen->getPath() + fileopen->getSelectedFile();
else
ret = FString();
delete fileopen;
return ret;
}
//----------------------------------------------------------------------
FString FFileDialog::fileSaveChooser ( FWidget* parent
, const FString& dirname
, const FString& filter )
{
FFileDialog* fileopen;
FString ret;
FString path = dirname;
FString file_filter = filter;
if ( path.isNull() || path.isEmpty() )
{
path = getHomeDir();
if ( path.isEmpty() || path.isEmpty() )
path = FString("/");
}
if ( file_filter.isNull() || file_filter.isEmpty() )
file_filter = FString("*");
fileopen = new FFileDialog ( path
, file_filter
, FFileDialog::Save
, parent );
if ( fileopen->exec() == FDialog::Accept )
ret = fileopen->getPath() + fileopen->getSelectedFile();
else
ret = FString();
delete fileopen;
return ret;
}
// protected methods of FFileDialog
//----------------------------------------------------------------------
void FFileDialog::adjustSize()
{
int h, X, Y, max_width, max_height;
FWidget* root_widget = getRootWidget();
if ( root_widget )
{
max_width = root_widget->getClientWidth();
max_height = root_widget->getClientHeight();
}
else
{
max_width = 80;
max_height = 24;
}
h = max_height - 6;
if ( h < 15 ) // minimum
h = 15;
if ( h > 30 ) // maximum
h = 30;
setHeight (h, false);
X = 1 + int((max_width - getWidth()) / 2);
Y = 1 + int((max_height - getHeight()) / 3);
setPos(X, Y, false);
filebrowser->setHeight (h-8, false);
hidden->setY(h-4, false);
cancel->setY(h-4, false);
open->setY(h-4, false);
FDialog::adjustSize();
printPath(directory);
}
// private methods of FFileDialog
//----------------------------------------------------------------------
void FFileDialog::init()
@ -452,353 +815,3 @@ void FFileDialog::cb_processShowHidden (FWidget*, void*)
{
setShowHiddenFiles(not show_hidden);
}
// protected methods of FFileDialog
//----------------------------------------------------------------------
void FFileDialog::adjustSize()
{
int h, X, Y, max_width, max_height;
FWidget* root_widget = getRootWidget();
if ( root_widget )
{
max_width = root_widget->getClientWidth();
max_height = root_widget->getClientHeight();
}
else
{
max_width = 80;
max_height = 24;
}
h = max_height - 6;
if ( h < 15 ) // minimum
h = 15;
if ( h > 30 ) // maximum
h = 30;
setHeight (h, false);
X = 1 + int((max_width - getWidth()) / 2);
Y = 1 + int((max_height - getHeight()) / 3);
setPos(X, Y, false);
filebrowser->setHeight (h-8, false);
hidden->setY(h-4, false);
cancel->setY(h-4, false);
open->setY(h-4, false);
FDialog::adjustSize();
printPath(directory);
}
// public methods of FFileDialog
//----------------------------------------------------------------------
FFileDialog& FFileDialog::operator = (const FFileDialog& fdlg)
{
if ( &fdlg == this )
{
return *this;
}
else
{
delete open;
delete cancel;
delete hidden;
delete filebrowser;
delete filename;
clear();
if ( fdlg.getParentWidget() )
fdlg.getParentWidget()->addChild (this);
directory = fdlg.directory;
filter_pattern = fdlg.filter_pattern;
dlg_type = fdlg.dlg_type;
show_hidden = fdlg.show_hidden;
if ( directory )
setPath(directory);
init();
return *this;
}
}
//----------------------------------------------------------------------
void FFileDialog::onKeyPress (FKeyEvent* ev)
{
if ( ! isEnabled() )
return;
FDialog::onKeyPress (ev);
if ( ! filebrowser->hasFocus() )
return;
int key = ev->key();
switch ( key )
{
case fc::Fkey_erase:
case fc::Fkey_backspace:
changeDir("..");
ev->accept();
break;
default:
break;
}
}
//----------------------------------------------------------------------
void FFileDialog::setPath (const FString& dir)
{
const char* dirname = dir.c_str();
char resolved_path[MAXPATHLEN];
FString r_dir;
struct stat sb;
if ( stat(dirname, &sb) != 0 )
{
directory = '/';
return;
}
if ( S_ISLNK(sb.st_mode) )
{
if ( lstat(dirname, &sb) != 0 )
{
directory = '/';
return;
}
}
if ( ! S_ISDIR(sb.st_mode) )
{
directory = '/';
return;
}
if ( realpath(dir.c_str(), resolved_path) != 0 )
r_dir = resolved_path;
else
r_dir = dir;
if ( r_dir[r_dir.getLength()-1] != '/' )
directory = r_dir + "/";
else
directory = r_dir;
}
//----------------------------------------------------------------------
void FFileDialog::setFilter (const FString& filter)
{
filter_pattern = filter;
}
//----------------------------------------------------------------------
const FString FFileDialog::getSelectedFile() const
{
uLong n = uLong(filebrowser->currentItem() - 1);
if ( dir_entries[n].type == DT_DIR )
return FString("");
else
return FString(dir_entries[n].name);
}
//----------------------------------------------------------------------
int FFileDialog::readDir()
{
int start, dir_num;
const char* dir = directory.c_str();
const char* filter = filter_pattern.c_str();
errno = 0;
directory_stream = opendir(dir);
if ( ! directory_stream )
{
FMessageBox::error (this, "Can't open directory\n" + directory);
return -1;
}
clear();
while ( true )
{
errno = 0;
struct dirent* next = readdir (directory_stream);
if ( next )
{
if ( next->d_name[0] == '.' && next->d_name[1] == '\0' )
continue;
if ( ! show_hidden
&& next->d_name[0] == '.'
&& next->d_name[1] != '\0'
&& next->d_name[1] != '.' )
{
continue;
}
if ( dir[0] == '/' && dir[1] == '\0' && std::strcmp(next->d_name, "..") == 0 )
continue;
dir_entry entry;
entry.name = strdup(next->d_name);
entry.type = next->d_type;
if ( next->d_type == DT_LNK ) // symbolic link
{
char resolved_path[MAXPATHLEN] = {};
char symLink[MAXPATHLEN] = {};
std::strncpy (symLink, dir, sizeof(symLink) - 1);
std::strncat (symLink, next->d_name, sizeof(symLink) - std::strlen(symLink) - 1);
if ( realpath(symLink, resolved_path) != 0 ) // follow link
{
struct stat sb;
if ( lstat(resolved_path, &sb) == 0 )
{
if ( S_ISDIR(sb.st_mode) )
entry.type = DT_DIR;
}
}
}
if ( entry.type == DT_DIR )
dir_entries.push_back (entry);
else if ( pattern_match(filter, entry.name) )
dir_entries.push_back (entry);
else
std::free(entry.name);
}
else if (errno != 0)
{
FMessageBox::error (this, "Reading directory\n" + directory);
if ( errno != EOVERFLOW )
break;
}
else
break;
} // end while
if ( closedir (directory_stream) != 0 )
{
FMessageBox::error (this, "Closing directory\n" + directory);
return -2;
}
if ( std::strcmp((*dir_entries.begin()).name, "..") == 0 )
start=1;
else
start=0;
dir_num = numOfDirs();
// directories first
std::sort(dir_entries.begin()+start, dir_entries.end(), sortDirFirst);
// sort directories by name
std::sort(dir_entries.begin()+start, dir_entries.begin()+dir_num, sortByName);
// sort files by name
std::sort(dir_entries.begin()+dir_num, dir_entries.end(), sortByName);
// fill list with directory entries
filebrowser->clear();
if ( ! dir_entries.empty() )
{
std::vector<dir_entry>::const_iterator iter, end;
iter = dir_entries.begin();
end = dir_entries.end();
while ( iter != end )
{
if ( (*iter).type == DT_DIR )
filebrowser->insert(FString((*iter).name), fc::SquareBrackets);
else
filebrowser->insert(FString((*iter).name));
++iter;
}
}
return 0;
}
//----------------------------------------------------------------------
bool FFileDialog::setShowHiddenFiles (bool on)
{
if ( on == show_hidden )
return show_hidden;
show_hidden = on;
readDir();
filebrowser->redraw();
return show_hidden;
}
//----------------------------------------------------------------------
FString FFileDialog::fileOpenChooser ( FWidget* parent
, const FString& dirname
, const FString& filter )
{
FFileDialog* fileopen;
FString ret;
FString path = dirname;
FString file_filter = filter;
if ( path.isNull() )
path = getHomeDir();
if ( file_filter.isNull() )
file_filter = FString("*");
fileopen = new FFileDialog ( path
, file_filter
, FFileDialog::Open
, parent );
if ( fileopen->exec() == FDialog::Accept )
ret = fileopen->getPath() + fileopen->getSelectedFile();
else
ret = FString();
delete fileopen;
return ret;
}
//----------------------------------------------------------------------
FString FFileDialog::fileSaveChooser ( FWidget* parent
, const FString& dirname
, const FString& filter )
{
FFileDialog* fileopen;
FString ret;
FString path = dirname;
FString file_filter = filter;
if ( path.isNull() )
path = getHomeDir();
if ( file_filter.isNull() )
file_filter = FString("*");
fileopen = new FFileDialog ( path
, file_filter
, FFileDialog::Save
, parent );
if ( fileopen->exec() == FDialog::Accept )
ret = fileopen->getPath() + fileopen->getSelectedFile();
else
ret = FString();
delete fileopen;
return ret;
}

View File

@ -57,17 +57,6 @@
#include "fterm.h"
#pragma pack(push)
#pragma pack(1)
struct dir_entry
{
char* name;
uChar type;
};
#pragma pack(pop)
//----------------------------------------------------------------------
// class FFileDialog
//----------------------------------------------------------------------
@ -78,27 +67,67 @@ struct dir_entry
class FFileDialog : public FDialog
{
public:
// Enumeration
enum DialogType
{
Open = 0,
Save = 1
};
private:
DIR* directory_stream;
std::vector<dir_entry> dir_entries;
// Constructors
explicit FFileDialog (FWidget* = 0);
FFileDialog (const FFileDialog&); // copy constructor
FFileDialog ( const FString&
, const FString&
, DialogType = FFileDialog::Open
, FWidget* = 0 );
// Destructor
~FFileDialog();
FString directory;
FString filter_pattern;
FListBox* filebrowser;
FLineEdit* filename;
FCheckBox* hidden;
FButton* cancel;
FButton* open;
DialogType dlg_type;
bool show_hidden;
// Assignment operator (=)
FFileDialog& operator = (const FFileDialog&);
// Accessors
const char* getClassName() const;
const FString getPath() const;
const FString getFilter() const;
const FString getSelectedFile() const;
bool getShowHiddenFiles();
// Mutators
void setPath (const FString&);
void setFilter (const FString&);
bool setShowHiddenFiles(bool);
bool setShowHiddenFiles();
bool unsetShowHiddenFiles();
// Event handler
void onKeyPress (FKeyEvent*);
// Methods
int readDir();
static FString fileOpenChooser ( FWidget*
, const FString& = FString()
, const FString& = FString() );
static FString fileSaveChooser ( FWidget*
, const FString& = FString()
, const FString& = FString() );
protected:
// Method
void adjustSize();
private:
// Typedef
struct dir_entry
{
char* name;
uChar type;
};
typedef std::vector<dir_entry> dirEntries;
// Method
void init();
static char* getHomeDir();
inline bool pattern_match (const char*, const char*);
@ -115,45 +144,24 @@ class FFileDialog : public FDialog
void cb_processOpen (FWidget*, void*);
void cb_processShowHidden (FWidget*, void*);
protected:
void adjustSize();
// Data Members
DIR* directory_stream;
dirEntries dir_entries;
FString directory;
FString filter_pattern;
FListBox* filebrowser;
FLineEdit* filename;
FCheckBox* hidden;
FButton* cancel;
FButton* open;
DialogType dlg_type;
bool show_hidden;
public:
// Constructors
explicit FFileDialog (FWidget* = 0);
FFileDialog (const FFileDialog&); // copy constructor
FFileDialog ( const FString&
, const FString&
, DialogType = FFileDialog::Open
, FWidget* = 0 );
// Destructor
~FFileDialog();
// Assignment operator (=)
FFileDialog& operator = (const FFileDialog&);
const char* getClassName() const;
// Event handler
void onKeyPress (FKeyEvent*);
const FString getPath() const;
void setPath (const FString&);
const FString getFilter() const;
void setFilter (const FString&);
const FString getSelectedFile() const;
int readDir();
bool setShowHiddenFiles(bool);
bool setShowHiddenFiles();
bool unsetShowHiddenFiles();
bool getShowHiddenFiles();
static FString fileOpenChooser ( FWidget*
, const FString& = FString()
, const FString& = FString() );
static FString fileSaveChooser ( FWidget*
, const FString& = FString()
, const FString& = FString() );
// Friend functions
friend bool sortByName ( const FFileDialog::dir_entry&
, const FFileDialog::dir_entry& );
friend bool sortDirFirst ( const FFileDialog::dir_entry&
, const FFileDialog::dir_entry& );
};
#pragma pack(pop)

View File

@ -51,6 +51,208 @@ FLabel::~FLabel() // destructor
}
// public methods of FLabel
//----------------------------------------------------------------------
void FLabel::setAccelWidget (FWidget* widget)
{
if ( widget )
accel_widget = widget;
accel_widget->addCallback
(
"destroy",
_METHOD_CALLBACK (this, &FLabel::cb_accel_widget_destroyed)
);
}
//----------------------------------------------------------------------
void FLabel::setAlignment (uInt align)
{
if ( align != fc::alignLeft
&& align != fc::alignCenter
&& align != fc::alignRight )
alignment = fc::alignLeft;
else
alignment = align;
}
//----------------------------------------------------------------------
bool FLabel::setEmphasis (bool on)
{
if ( emphasis != on )
emphasis = on;
return on;
}
//----------------------------------------------------------------------
bool FLabel::setReverseMode (bool on)
{
if ( reverse_mode != on )
reverse_mode = on;
return on;
}
//----------------------------------------------------------------------
bool FLabel::setEnable (bool on)
{
FWidget::setEnable(on);
if ( on )
{
flags |= fc::active;
setHotkeyAccelerator();
}
else
{
flags &= ~fc::active;
delAccelerator();
}
return on;
}
//----------------------------------------------------------------------
void FLabel::setNumber (long num)
{
setText(FString().setNumber(num));
}
//----------------------------------------------------------------------
void FLabel::setText (const FString& txt)
{
text = txt;
multiline_text = text.split("\r\n");
if ( int(multiline_text.size()) > 1 )
multiline = true;
else
multiline = false;
if ( isEnabled() )
{
delAccelerator();
setHotkeyAccelerator();
}
}
//----------------------------------------------------------------------
void FLabel::hide()
{
short fg, bg;
int size;
char* blank;
FWidget* parent_widget = getParentWidget();
FWidget::hide();
if ( parent_widget )
{
fg = parent_widget->getForegroundColor();
bg = parent_widget->getBackgroundColor();
}
else
{
fg = wc.dialog_fg;
bg = wc.dialog_bg;
}
setColor (fg, bg);
size = getWidth();
if ( size < 0 )
return;
blank = new char[size+1];
std::memset(blank, ' ', uLong(size));
blank[getWidth()] = '\0';
setPrintPos (1,1);
print (blank);
delete[] blank;
}
//----------------------------------------------------------------------
void FLabel::onMouseDown (FMouseEvent* ev)
{
if ( ev->getButton() != fc::LeftButton )
return;
if ( ! (isEnabled() && accel_widget) )
{
// send click to the parent widget
if ( FWidget* parent = getParentWidget() )
{
int b = ev->getButton();
const FPoint& tp = ev->getTermPos();
const FPoint& p = parent->termToWidgetPos(tp);
FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p, tp, b);
FApplication::sendEvent (parent, _ev);
delete _ev;
}
return;
}
if ( ! accel_widget->hasFocus() )
{
// focus the accelerator widget
FWidget* focused_widget = getFocusWidget();
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
accel_widget->setFocus();
if ( focused_widget )
focused_widget->redraw();
accel_widget->redraw();
if ( getStatusBar() )
{
accel_widget->getStatusBar()->drawMessage();
updateTerminal();
flush_out();
}
}
}
//----------------------------------------------------------------------
void FLabel::onAccel (FAccelEvent* ev)
{
if ( ! (isEnabled() && accel_widget) )
return;
if ( ! accel_widget->hasFocus() )
{
FWidget* focused_widget = static_cast<FWidget*>(ev->focusedWidget());
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
accel_widget->setFocus();
if ( focused_widget )
focused_widget->redraw();
accel_widget->redraw();
if ( getStatusBar() )
{
accel_widget->getStatusBar()->drawMessage();
updateTerminal();
flush_out();
}
}
ev->accept();
}
//----------------------------------------------------------------------
void FLabel::cb_accel_widget_destroyed (FWidget*, void*)
{
accel_widget = 0;
delAccelerator();
}
// private methods of FLabel
//----------------------------------------------------------------------
void FLabel::init()
@ -330,205 +532,3 @@ void FLabel::draw()
updateVTerm(true);
}
// public methods of FLabel
//----------------------------------------------------------------------
void FLabel::hide()
{
short fg, bg;
int size;
char* blank;
FWidget* parent_widget = getParentWidget();
FWidget::hide();
if ( parent_widget )
{
fg = parent_widget->getForegroundColor();
bg = parent_widget->getBackgroundColor();
}
else
{
fg = wc.dialog_fg;
bg = wc.dialog_bg;
}
setColor (fg, bg);
size = getWidth();
if ( size < 0 )
return;
blank = new char[size+1];
std::memset(blank, ' ', uLong(size));
blank[getWidth()] = '\0';
setPrintPos (1,1);
print (blank);
delete[] blank;
}
//----------------------------------------------------------------------
void FLabel::onMouseDown (FMouseEvent* ev)
{
if ( ev->getButton() != fc::LeftButton )
return;
if ( ! (isEnabled() && accel_widget) )
{
// send click to the parent widget
if ( FWidget* parent = getParentWidget() )
{
int b = ev->getButton();
const FPoint& tp = ev->getTermPos();
const FPoint& p = parent->termToWidgetPos(tp);
FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p, tp, b);
FApplication::sendEvent (parent, _ev);
delete _ev;
}
return;
}
if ( ! accel_widget->hasFocus() )
{
// focus the accelerator widget
FWidget* focused_widget = getFocusWidget();
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
accel_widget->setFocus();
if ( focused_widget )
focused_widget->redraw();
accel_widget->redraw();
if ( statusBar() )
{
accel_widget->statusBar()->drawMessage();
updateTerminal();
flush_out();
}
}
}
//----------------------------------------------------------------------
void FLabel::onAccel (FAccelEvent* ev)
{
if ( ! (isEnabled() && accel_widget) )
return;
if ( ! accel_widget->hasFocus() )
{
FWidget* focused_widget = static_cast<FWidget*>(ev->focusedWidget());
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
accel_widget->setFocus();
if ( focused_widget )
focused_widget->redraw();
accel_widget->redraw();
if ( statusBar() )
{
accel_widget->statusBar()->drawMessage();
updateTerminal();
flush_out();
}
}
ev->accept();
}
//----------------------------------------------------------------------
void FLabel::cb_accel_widget_destroyed (FWidget*, void*)
{
accel_widget = 0;
delAccelerator();
}
//----------------------------------------------------------------------
void FLabel::setAccelWidget (FWidget* widget)
{
if ( widget )
accel_widget = widget;
accel_widget->addCallback
(
"destroy",
_METHOD_CALLBACK (this, &FLabel::cb_accel_widget_destroyed)
);
}
//----------------------------------------------------------------------
void FLabel::setAlignment (uInt align)
{
if ( align != fc::alignLeft
&& align != fc::alignCenter
&& align != fc::alignRight )
alignment = fc::alignLeft;
else
alignment = align;
}
//----------------------------------------------------------------------
bool FLabel::setEmphasis (bool on)
{
if ( emphasis != on )
emphasis = on;
return on;
}
//----------------------------------------------------------------------
bool FLabel::setReverseMode (bool on)
{
if ( reverse_mode != on )
reverse_mode = on;
return on;
}
//----------------------------------------------------------------------
bool FLabel::setEnable (bool on)
{
FWidget::setEnable(on);
if ( on )
{
flags |= fc::active;
setHotkeyAccelerator();
}
else
{
flags &= ~fc::active;
delAccelerator();
}
return on;
}
//----------------------------------------------------------------------
void FLabel::setNumber (long num)
{
setText(FString().setNumber(num));
}
//----------------------------------------------------------------------
void FLabel::setText (const FString& txt)
{
text = txt;
multiline_text = text.split("\r\n");
if ( int(multiline_text.size()) > 1 )
multiline = true;
else
multiline = false;
if ( isEnabled() )
{
delAccelerator();
setHotkeyAccelerator();
}
}

View File

@ -40,39 +40,41 @@
class FLabel : public FWidget
{
private:
std::vector<FString> multiline_text;
bool multiline;
FString text;
uInt alignment;
short emphasis_color;
short ellipsis_color;
bool emphasis;
bool reverse_mode;
FWidget* accel_widget;
private:
// Disable copy constructor
FLabel (const FLabel&);
// Disable assignment operator (=)
FLabel& operator = (const FLabel&);
void init();
uChar getHotkey();
int getHotkeyPos (wchar_t*&, wchar_t*&, uInt);
void setHotkeyAccelerator();
int getXOffset (int);
void printLine (wchar_t*&, uInt, int, int = 0);
void draw();
public:
// Using-declaration
using FWidget::setEnable;
// Constructor
explicit FLabel (FWidget* = 0);
FLabel (const FString&, FWidget* = 0);
// Destructor
virtual ~FLabel();
// Accessors
const char* getClassName() const;
FTerm* getAccelWidget();
uInt getAlignment();
FString& getText();
// Mutators
void setAccelWidget (FWidget* = 0);
void setAlignment(uInt);
bool setEmphasis(bool);
bool setEmphasis();
bool unsetEmphasis();
bool setReverseMode(bool);
bool setReverseMode();
bool unsetReverseMode();
bool setEnable (bool);
void setNumber(long);
void setText (const FString&);
// Inquiries
bool hasEmphasis();
bool hasReverseMode();
// Methods
void hide();
// Event handlers
@ -82,23 +84,35 @@ class FLabel : public FWidget
// Callback method
void cb_accel_widget_destroyed (FWidget*, void*);
void setAccelWidget (FWidget* = 0);
FTerm* getAccelWidget();
void setAlignment(uInt);
uInt getAlignment();
bool setEmphasis(bool);
bool setEmphasis();
bool unsetEmphasis();
bool hasEmphasis();
bool setReverseMode(bool);
bool setReverseMode();
bool unsetReverseMode();
bool hasReverseMode();
using FWidget::setEnable;
bool setEnable (bool);
void setNumber(long);
void setText (const FString&);
FString& getText();
private:
// Typedef
typedef std::vector<FString> multiLineText;
// Disable copy constructor
FLabel (const FLabel&);
// Disable assignment operator (=)
FLabel& operator = (const FLabel&);
// Methods
void init();
uChar getHotkey();
int getHotkeyPos (wchar_t*&, wchar_t*&, uInt);
void setHotkeyAccelerator();
int getXOffset (int);
void printLine (wchar_t*&, uInt, int, int = 0);
void draw();
// Data Members
multiLineText multiline_text;
bool multiline;
FString text;
uInt alignment;
short emphasis_color;
short ellipsis_color;
bool emphasis;
bool reverse_mode;
FWidget* accel_widget;
};
#pragma pack(pop)
@ -116,6 +130,10 @@ inline FTerm* FLabel::getAccelWidget ()
inline uInt FLabel::getAlignment()
{ return alignment; }
//----------------------------------------------------------------------
inline FString& FLabel::getText()
{ return text; }
//----------------------------------------------------------------------
inline bool FLabel::setEmphasis()
{ return setEmphasis(true); }
@ -124,10 +142,6 @@ inline bool FLabel::setEmphasis()
inline bool FLabel::unsetEmphasis()
{ return setEmphasis(false); }
//----------------------------------------------------------------------
inline bool FLabel::hasEmphasis()
{ return emphasis; }
//----------------------------------------------------------------------
inline bool FLabel::setReverseMode()
{ return setReverseMode(true); }
@ -136,12 +150,12 @@ inline bool FLabel::setReverseMode()
inline bool FLabel::unsetReverseMode()
{ return setReverseMode(false); }
//----------------------------------------------------------------------
inline bool FLabel::hasEmphasis()
{ return emphasis; }
//----------------------------------------------------------------------
inline bool FLabel::hasReverseMode()
{ return reverse_mode; }
//----------------------------------------------------------------------
inline FString& FLabel::getText()
{ return text; }
#endif // _FLABEL_H

View File

@ -17,13 +17,13 @@ FLineEdit::FLineEdit(FWidget* parent)
, text("")
, label_text("")
, label(new FLabel("", parent))
, label_orientation(FLineEdit::label_left)
, drag_scroll(FLineEdit::noScroll)
, scroll_timer(false)
, scroll_repeat(100)
, insert_mode(true)
, cursor_pos(0)
, text_offset(0)
, label_orientation(FLineEdit::label_left)
{
init();
}
@ -34,13 +34,13 @@ FLineEdit::FLineEdit (const FString& txt, FWidget* parent)
, text(txt)
, label_text("")
, label(new FLabel("", parent))
, label_orientation(FLineEdit::label_left)
, drag_scroll(FLineEdit::noScroll)
, scroll_timer(false)
, scroll_repeat(100)
, insert_mode(true)
, cursor_pos(0)
, text_offset(0)
, label_orientation(FLineEdit::label_left)
{
init();
setText(txt);
@ -60,18 +60,14 @@ FLineEdit::~FLineEdit() // destructor
}
}
// private methods of FLineEdit
// public methods of FLineEdit
//----------------------------------------------------------------------
void FLineEdit::init()
bool FLineEdit::setEnable (bool on)
{
label->setAccelWidget(this);
setVisibleCursor();
setShadow();
FWidget::setEnable(on);
if ( hasFocus() )
flags |= fc::focus;
if ( isEnabled() )
if ( on )
{
flags |= fc::active;
@ -86,196 +82,97 @@ void FLineEdit::init()
setBackgroundColor (wc.inputfield_active_bg);
}
}
else // inactive
else
{
flags &= ~fc::active;
setForegroundColor (wc.inputfield_inactive_fg);
setBackgroundColor (wc.inputfield_inactive_bg);
}
return on;
}
//----------------------------------------------------------------------
bool FLineEdit::hasHotkey()
bool FLineEdit::setFocus (bool on)
{
if ( label_text.isEmpty() )
return 0;
FWidget::setFocus(on);
return label_text.includes('&');
}
if ( on )
{
flags |= fc::focus;
//----------------------------------------------------------------------
void FLineEdit::draw()
{
bool isFocus;
drawInputField();
isFocus = ((flags & fc::focus) != 0);
if ( isEnabled() )
{
setForegroundColor (wc.inputfield_active_focus_fg);
setBackgroundColor (wc.inputfield_active_focus_bg);
if ( isFocus && statusBar() )
if ( getStatusBar() )
{
FString msg = getStatusbarMessage();
FString curMsg = statusBar()->getMessage();
FString curMsg = getStatusBar()->getMessage();
if ( curMsg != msg )
{
statusBar()->setMessage(msg);
statusBar()->drawMessage();
getStatusBar()->setMessage(msg);
}
}
}
}
//----------------------------------------------------------------------
void FLineEdit::drawInputField()
{
bool isActiveFocus, isActive, isShadow;
int x;
FString show_text;
int active_focus = fc::active + fc::focus;
isActiveFocus = ((flags & active_focus) == active_focus);
isActive = ((flags & fc::active) != 0);
isShadow = ((flags & fc::shadow) != 0 );
updateVTerm(false);
setPrintPos (1, 1);
if ( isMonochron() )
{
setReverse(true);
print (' ');
if ( isActiveFocus )
setReverse(false);
else
setUnderline(true);
}
else if ( isActiveFocus )
{
setColor (wc.inputfield_active_focus_bg, wc.dialog_bg);
flags &= ~fc::focus;
if ( isCygwinTerminal() ) // IBM Codepage 850
print (fc::FullBlock); // █
else if ( isTeraTerm() )
print (0xdb);
if ( isEnabled() )
{
setForegroundColor (wc.inputfield_active_fg);
setBackgroundColor (wc.inputfield_active_bg);
if ( getStatusBar() )
getStatusBar()->clearMessage();
}
}
return on;
}
//----------------------------------------------------------------------
bool FLineEdit::setShadow (bool on)
{
if ( on
&& (Encoding != fc::VT100 || isTeraTerm() )
&& Encoding != fc::ASCII )
flags |= fc::shadow;
else
print (fc::RightHalfBlock); // ▐
}
else if ( isActive )
{
setColor (wc.inputfield_active_bg, wc.dialog_bg);
flags &= ~fc::shadow;
if ( isCygwinTerminal() ) // IBM Codepage 850
print (fc::FullBlock); // █
else if ( isTeraTerm() )
print (0xdb);
return on;
}
//----------------------------------------------------------------------
void FLineEdit::setText (FString txt)
{
text_offset = 0;
cursor_pos = 0;
if ( txt )
text = txt;
else
print (fc::RightHalfBlock); // ▐
}
else // isInactive
{
setColor (wc.inputfield_inactive_bg, wc.dialog_bg);
if ( isCygwinTerminal() ) // IBM Codepage 850
print (fc::FullBlock); // █
else if ( isTeraTerm() )
print (0xdb);
else
print (fc::RightHalfBlock); // ▐
}
if ( isActiveFocus && getMaxColor() < 16 )
setBold();
setColor();
show_text = text.mid(uInt(1+text_offset), uInt(getWidth()-2));
if ( isUTF8_linux_terminal() )
{
setUTF8(true);
if ( show_text )
print (show_text);
setUTF8(false);
}
else if ( show_text )
print (show_text);
x = int(show_text.getLength());
while ( x < getWidth()-1 )
{
print (' ');
x++;
}
if ( isActiveFocus && getMaxColor() < 16 )
unsetBold();
if ( isMonochron() )
{
setReverse(false);
setUnderline(false);
}
if ( isShadow )
drawShadow ();
// set the cursor to the first pos.
setCursorPos (2+cursor_pos-text_offset, 1);
updateVTerm(true);
text = "";
}
//----------------------------------------------------------------------
void FLineEdit::processActivate()
void FLineEdit::setLabelText (FString ltxt)
{
if ( ! hasFocus() )
{
setFocus();
redraw();
}
emitCallback("activate");
}
//----------------------------------------------------------------------
void FLineEdit::processChanged()
{
emitCallback("changed");
}
// protected methods of FListBox
//----------------------------------------------------------------------
void FLineEdit::adjustLabel()
{
int label_length = int(label_text.getLength());
if ( hasHotkey() )
label_length--;
assert ( label_orientation == label_above
|| label_orientation == label_left );
switch ( label_orientation )
{
case label_above:
label->setGeometry(getX(), getY()-1, label_length, 1);
break;
case label_left:
label->setGeometry(getX()-label_length, getY(), label_length, 1);
break;
}
}
//----------------------------------------------------------------------
void FLineEdit::adjustSize()
{
FWidget::adjustSize();
label_text = ltxt;
label->setText(label_text);
adjustLabel();
}
//----------------------------------------------------------------------
void FLineEdit::setLabelOrientation(label_o o)
{
label_orientation = o;
adjustLabel();
}
// public methods of FLineEdit
//----------------------------------------------------------------------
void FLineEdit::hide()
{
@ -321,87 +218,11 @@ void FLineEdit::hide()
}
//----------------------------------------------------------------------
bool FLineEdit::setEnable (bool on)
void FLineEdit::clearText()
{
FWidget::setEnable(on);
if ( on )
{
flags |= fc::active;
if ( hasFocus() )
{
setForegroundColor (wc.inputfield_active_focus_fg);
setBackgroundColor (wc.inputfield_active_focus_bg);
}
else
{
setForegroundColor (wc.inputfield_active_fg);
setBackgroundColor (wc.inputfield_active_bg);
}
}
else
{
flags &= ~fc::active;
setForegroundColor (wc.inputfield_inactive_fg);
setBackgroundColor (wc.inputfield_inactive_bg);
}
return on;
}
//----------------------------------------------------------------------
bool FLineEdit::setFocus (bool on)
{
FWidget::setFocus(on);
if ( on )
{
flags |= fc::focus;
if ( isEnabled() )
{
setForegroundColor (wc.inputfield_active_focus_fg);
setBackgroundColor (wc.inputfield_active_focus_bg);
if ( statusBar() )
{
FString msg = getStatusbarMessage();
FString curMsg = statusBar()->getMessage();
if ( curMsg != msg )
statusBar()->setMessage(msg);
}
}
}
else
{
flags &= ~fc::focus;
if ( isEnabled() )
{
setForegroundColor (wc.inputfield_active_fg);
setBackgroundColor (wc.inputfield_active_bg);
if ( statusBar() )
statusBar()->clearMessage();
}
}
return on;
}
//----------------------------------------------------------------------
bool FLineEdit::setShadow (bool on)
{
if ( on
&& (Encoding != fc::VT100 || isTeraTerm() )
&& Encoding != fc::ASCII )
flags |= fc::shadow;
else
flags &= ~fc::shadow;
return on;
text_offset = 0;
cursor_pos = 0;
text.clear();
}
//----------------------------------------------------------------------
@ -581,8 +402,8 @@ void FLineEdit::onMouseDown (FMouseEvent* ev)
redraw();
if ( statusBar() )
statusBar()->drawMessage();
if ( getStatusBar() )
getStatusBar()->drawMessage();
}
mouse_x = ev->getX();
@ -751,9 +572,9 @@ void FLineEdit::onAccel (FAccelEvent* ev)
redraw();
if ( statusBar() )
if ( getStatusBar() )
{
statusBar()->drawMessage();
getStatusBar()->drawMessage();
updateTerminal();
flush_out();
}
@ -795,9 +616,9 @@ void FLineEdit::onFocusIn (FFocusEvent*)
setXTermCursorColor("rgb:0000/0000/0000");
}
if ( statusBar() )
if ( getStatusBar() )
{
statusBar()->drawMessage();
getStatusBar()->drawMessage();
updateTerminal();
flush_out();
}
@ -806,10 +627,10 @@ void FLineEdit::onFocusIn (FFocusEvent*)
//----------------------------------------------------------------------
void FLineEdit::onFocusOut (FFocusEvent*)
{
if ( statusBar() )
if ( getStatusBar() )
{
statusBar()->clearMessage();
statusBar()->drawMessage();
getStatusBar()->clearMessage();
getStatusBar()->drawMessage();
}
if ( ! insert_mode )
@ -823,37 +644,217 @@ void FLineEdit::onFocusOut (FFocusEvent*)
}
}
// protected methods of FListBox
//----------------------------------------------------------------------
void FLineEdit::clearText()
void FLineEdit::adjustLabel()
{
text_offset = 0;
cursor_pos = 0;
text.clear();
int label_length = int(label_text.getLength());
if ( hasHotkey() )
label_length--;
assert ( label_orientation == label_above
|| label_orientation == label_left );
switch ( label_orientation )
{
case label_above:
label->setGeometry(getX(), getY()-1, label_length, 1);
break;
case label_left:
label->setGeometry(getX()-label_length, getY(), label_length, 1);
break;
}
}
//----------------------------------------------------------------------
void FLineEdit::setText (FString txt)
void FLineEdit::adjustSize()
{
text_offset = 0;
cursor_pos = 0;
FWidget::adjustSize();
adjustLabel();
}
if ( txt )
text = txt;
// private methods of FLineEdit
//----------------------------------------------------------------------
void FLineEdit::init()
{
label->setAccelWidget(this);
setVisibleCursor();
setShadow();
if ( hasFocus() )
flags |= fc::focus;
if ( isEnabled() )
{
flags |= fc::active;
if ( hasFocus() )
{
setForegroundColor (wc.inputfield_active_focus_fg);
setBackgroundColor (wc.inputfield_active_focus_bg);
}
else
text = "";
{
setForegroundColor (wc.inputfield_active_fg);
setBackgroundColor (wc.inputfield_active_bg);
}
}
else // inactive
{
setForegroundColor (wc.inputfield_inactive_fg);
setBackgroundColor (wc.inputfield_inactive_bg);
}
}
//----------------------------------------------------------------------
void FLineEdit::setLabelText (FString ltxt)
bool FLineEdit::hasHotkey()
{
label_text = ltxt;
label->setText(label_text);
adjustLabel();
if ( label_text.isEmpty() )
return 0;
return label_text.includes('&');
}
//----------------------------------------------------------------------
void FLineEdit::setLabelOrientation(label_o o)
void FLineEdit::draw()
{
label_orientation = o;
adjustLabel();
bool isFocus;
drawInputField();
isFocus = ((flags & fc::focus) != 0);
if ( isFocus && getStatusBar() )
{
FString msg = getStatusbarMessage();
FString curMsg = getStatusBar()->getMessage();
if ( curMsg != msg )
{
getStatusBar()->setMessage(msg);
getStatusBar()->drawMessage();
}
}
}
//----------------------------------------------------------------------
void FLineEdit::drawInputField()
{
bool isActiveFocus, isActive, isShadow;
int x;
FString show_text;
int active_focus = fc::active + fc::focus;
isActiveFocus = ((flags & active_focus) == active_focus);
isActive = ((flags & fc::active) != 0);
isShadow = ((flags & fc::shadow) != 0 );
updateVTerm(false);
setPrintPos (1, 1);
if ( isMonochron() )
{
setReverse(true);
print (' ');
if ( isActiveFocus )
setReverse(false);
else
setUnderline(true);
}
else if ( isActiveFocus )
{
setColor (wc.inputfield_active_focus_bg, wc.dialog_bg);
if ( isCygwinTerminal() ) // IBM Codepage 850
print (fc::FullBlock); // █
else if ( isTeraTerm() )
print (0xdb);
else
print (fc::RightHalfBlock); // ▐
}
else if ( isActive )
{
setColor (wc.inputfield_active_bg, wc.dialog_bg);
if ( isCygwinTerminal() ) // IBM Codepage 850
print (fc::FullBlock); // █
else if ( isTeraTerm() )
print (0xdb);
else
print (fc::RightHalfBlock); // ▐
}
else // isInactive
{
setColor (wc.inputfield_inactive_bg, wc.dialog_bg);
if ( isCygwinTerminal() ) // IBM Codepage 850
print (fc::FullBlock); // █
else if ( isTeraTerm() )
print (0xdb);
else
print (fc::RightHalfBlock); // ▐
}
if ( isActiveFocus && getMaxColor() < 16 )
setBold();
setColor();
show_text = text.mid(uInt(1+text_offset), uInt(getWidth()-2));
if ( isUTF8_linux_terminal() )
{
setUTF8(true);
if ( show_text )
print (show_text);
setUTF8(false);
}
else if ( show_text )
print (show_text);
x = int(show_text.getLength());
while ( x < getWidth()-1 )
{
print (' ');
x++;
}
if ( isActiveFocus && getMaxColor() < 16 )
unsetBold();
if ( isMonochron() )
{
setReverse(false);
setUnderline(false);
}
if ( isShadow )
drawShadow ();
// set the cursor to the first pos.
setCursorPos (2+cursor_pos-text_offset, 1);
updateVTerm(true);
}
//----------------------------------------------------------------------
void FLineEdit::processActivate()
{
if ( ! hasFocus() )
{
setFocus();
redraw();
}
emitCallback("activate");
}
//----------------------------------------------------------------------
void FLineEdit::processChanged()
{
emitCallback("changed");
}

View File

@ -41,60 +41,30 @@
class FLineEdit : public FWidget
{
private:
FString text;
FString label_text;
FLabel* label;
enum dragScroll
{
noScroll = 0,
scrollLeft = 1,
scrollRight = 2
};
dragScroll drag_scroll;
bool scroll_timer;
int scroll_repeat;
bool insert_mode;
int cursor_pos;
int text_offset;
public:
// Enumeration
enum label_o
{
label_above = 0,
label_left = 1
};
label_o label_orientation;
private:
// Disable copy constructor
FLineEdit (const FLineEdit&);
// Disable assignment operator (=)
FLineEdit& operator = (const FLineEdit&);
void init();
bool hasHotkey();
void draw();
void drawInputField();
void processActivate();
void processChanged();
protected:
void adjustLabel();
void adjustSize();
public:
// Constructor
explicit FLineEdit (FWidget* = 0);
FLineEdit (const FString&, FWidget* = 0);
// Destructor
virtual ~FLineEdit();
// Accessors
const char* getClassName() const;
void hide();
FString getText() const;
int getLabelOrientation();
// Mutators
void setText (FString);
void setLabelText (FString);
void setLabelOrientation(label_o);
bool setEnable(bool);
bool setEnable();
bool unsetEnable();
@ -105,8 +75,14 @@ class FLineEdit : public FWidget
bool setShadow(bool);
bool setShadow();
bool unsetShadow();
// Inquiry
bool hasShadow();
// Methods
void hide();
void clearText();
// Event handlers
void onKeyPress (FKeyEvent*);
void onMouseDown (FMouseEvent*);
@ -118,12 +94,44 @@ class FLineEdit : public FWidget
void onFocusIn (FFocusEvent*);
void onFocusOut (FFocusEvent*);
void clearText();
void setText (FString);
FString getText() const;
void setLabelText (FString);
void setLabelOrientation(label_o);
int getLabelOrientation();
protected:
void adjustLabel();
void adjustSize();
private:
// Enumeration
enum dragScroll
{
noScroll = 0,
scrollLeft = 1,
scrollRight = 2
};
// Disable copy constructor
FLineEdit (const FLineEdit&);
// Disable assignment operator (=)
FLineEdit& operator = (const FLineEdit&);
// Methods
void init();
bool hasHotkey();
void draw();
void drawInputField();
void processActivate();
void processChanged();
// Data Members
FString text;
FString label_text;
FLabel* label;
label_o label_orientation;
dragScroll drag_scroll;
bool scroll_timer;
int scroll_repeat;
bool insert_mode;
int cursor_pos;
int text_offset;
};
#pragma pack(pop)
@ -133,6 +141,14 @@ class FLineEdit : public FWidget
inline const char* FLineEdit::getClassName() const
{ return "FLineEdit"; }
//----------------------------------------------------------------------
inline FString FLineEdit::getText() const
{ return text; }
//----------------------------------------------------------------------
inline int FLineEdit::getLabelOrientation()
{ return int(label_orientation); }
//----------------------------------------------------------------------
inline bool FLineEdit::setEnable()
{ return setEnable(true); }
@ -165,12 +181,4 @@ inline bool FLineEdit::unsetShadow()
inline bool FLineEdit::hasShadow()
{ return ((flags & fc::shadow) != 0); }
//----------------------------------------------------------------------
inline FString FLineEdit::getText() const
{ return text; }
//----------------------------------------------------------------------
inline int FLineEdit::getLabelOrientation()
{ return int(label_orientation); }
#endif // _FLINEEDIT_H

File diff suppressed because it is too large Load Diff

View File

@ -44,20 +44,17 @@
class FListBoxItem
{
private:
FString text;
fc::brackets_type brackets;
bool selected;
public:
// Constructors
FListBoxItem ();
explicit FListBoxItem (FString&);
explicit FListBoxItem (const std::string&);
explicit FListBoxItem (const char*);
// Destructor
virtual ~FListBoxItem();
// Accessors
virtual FString getText() const;
protected:
@ -66,10 +63,17 @@ class FListBoxItem
void setText (const char*);
private:
// Friend classes
friend class FListBox;
// Data Members
FString text;
fc::brackets_type brackets;
bool selected;
};
#pragma pack(pop)
// FListBoxItem inline functions
//----------------------------------------------------------------------
inline FString FListBoxItem::getText() const
@ -97,7 +101,83 @@ inline void FListBoxItem::setText (const char* txt)
class FListBox : public FWidget
{
public:
// Using-declaration
using FWidget::setGeometry;
// Constructor
explicit FListBox (FWidget* = 0);
// Destructor
~FListBox();
// Accessors
const char* getClassName() const;
uInt getCount() const;
FListBoxItem getItem (int) const;
int currentItem() const;
FString& getText();
// Mutators
void setCurrentItem (int);
void selectItem (int);
void unselectItem (int);
void showInsideBrackets (int, fc::brackets_type);
void showNoBrackets (int);
void setGeometry (int, int, int, int, bool = true);
void setMultiSelection (bool);
void setMultiSelection ();
void unsetMultiSelection ();
bool setEnable (bool);
bool setEnable();
bool unsetEnable();
bool setDisable();
bool setFocus (bool);
bool setFocus();
bool unsetFocus();
void setText (const FString);
// Inquiries
bool isSelected (int) const;
bool isMultiSelection() const;
bool hasBrackets (int) const;
// Methods
void hide();
void insert ( FString
, fc::brackets_type = fc::NoBrackets
, bool = false );
void insert ( long
, fc::brackets_type = fc::NoBrackets
, bool = false );
void remove (int);
void clear();
// Event handlers
void onKeyPress (FKeyEvent*);
void onMouseDown (FMouseEvent*);
void onMouseUp (FMouseEvent*);
void onMouseMove (FMouseEvent*);
void onMouseDoubleClick (FMouseEvent*);
void onWheel (FWheelEvent*);
void onTimer (FTimerEvent*);
void onFocusIn (FFocusEvent*);
void onFocusOut (FFocusEvent*);
// Callback methods
void cb_VBarChange (FWidget*, void*);
void cb_HBarChange (FWidget*, void*);
protected:
// Methods
void adjustYOffset();
void adjustSize();
private:
// Typedef
typedef std::vector<FListBoxItem> listBoxItem;
// Enumeration
enum dragScroll
{
noScroll = 0,
@ -107,7 +187,23 @@ class FListBox : public FWidget
scrollDownSelect = 4
};
std::vector<FListBoxItem> data;
// Disable copy constructor
FListBox (const FListBox&);
// Disable assignment operator (=)
FListBox& operator = (const FListBox&);
// Methods
void init();
void draw();
void drawLabel();
void drawList();
void processClick();
void processSelect();
void processChanged();
// Data Members
listBoxItem data;
FScrollbar* vbar;
FScrollbar* hbar;
FString text;
@ -126,86 +222,6 @@ class FListBox : public FWidget
int last_yoffset;
int nf_offset;
int max_line_width;
private:
// Disable copy constructor
FListBox (const FListBox&);
// Disable assignment operator (=)
FListBox& operator = (const FListBox&);
void init();
void draw();
void drawLabel();
void drawList();
void processClick();
void processSelect();
void processChanged();
protected:
void adjustYOffset();
void adjustSize();
public:
// Constructor
explicit FListBox (FWidget* = 0);
// Destructor
~FListBox();
const char* getClassName() const;
void hide();
// Event handlers
void onKeyPress (FKeyEvent*);
void onMouseDown (FMouseEvent*);
void onMouseUp (FMouseEvent*);
void onMouseMove (FMouseEvent*);
void onMouseDoubleClick (FMouseEvent*);
void onWheel (FWheelEvent*);
void onTimer (FTimerEvent*);
void onFocusIn (FFocusEvent*);
void onFocusOut (FFocusEvent*);
// Callback methods
void cb_VBarChange (FWidget*, void*);
void cb_HBarChange (FWidget*, void*);
uInt count() const;
FListBoxItem Item (int) const;
int currentItem() const;
void setCurrentItem (int);
void selectItem (int);
void unselectItem (int);
bool isSelected (int) const;
void showInsideBrackets (int, fc::brackets_type);
void showNoBrackets (int);
bool hasBrackets (int) const;
// make every setGeometry from FWidget available
using FWidget::setGeometry;
void setGeometry (int, int, int, int, bool = true);
void setMultiSelection (bool);
void setMultiSelection ();
void unsetMultiSelection ();
bool isMultiSelection() const;
bool setEnable (bool);
bool setEnable();
bool unsetEnable();
bool setDisable();
bool setFocus (bool);
bool setFocus();
bool unsetFocus();
void insert ( FString
, fc::brackets_type = fc::NoBrackets
, bool = false );
void insert ( long
, fc::brackets_type = fc::NoBrackets
, bool = false );
void remove ( int);
void clear();
void setText (const FString);
FString& getText();
};
#pragma pack(pop)
@ -216,17 +232,21 @@ inline const char* FListBox::getClassName() const
{ return "FListBox"; }
//----------------------------------------------------------------------
inline uInt FListBox::count() const
inline uInt FListBox::getCount() const
{ return uInt(data.size()); }
//----------------------------------------------------------------------
inline FListBoxItem FListBox::Item(int index) const
inline FListBoxItem FListBox::getItem (int index) const
{ return data[uInt(index-1)]; }
//----------------------------------------------------------------------
inline int FListBox::currentItem() const
{ return current; }
//----------------------------------------------------------------------
inline FString& FListBox::getText()
{ return text; }
//----------------------------------------------------------------------
inline void FListBox::selectItem (int index)
{ data[uInt(index-1)].selected = true; }
@ -235,18 +255,10 @@ inline void FListBox::selectItem (int index)
inline void FListBox::unselectItem (int index)
{ data[uInt(index-1)].selected = false; }
//----------------------------------------------------------------------
inline bool FListBox::isSelected(int index) const
{ return data[uInt(index-1)].selected; }
//----------------------------------------------------------------------
inline void FListBox::showNoBrackets(int index)
{ data[uInt(index-1)].brackets = fc::NoBrackets; }
//----------------------------------------------------------------------
inline bool FListBox::hasBrackets(int index) const
{ return bool(data[uInt(index-1)].brackets > 0); }
//----------------------------------------------------------------------
inline void FListBox::setMultiSelection (bool on)
{ multi_select = on; }
@ -259,10 +271,6 @@ inline void FListBox::setMultiSelection()
inline void FListBox::unsetMultiSelection()
{ setMultiSelection(false); }
//----------------------------------------------------------------------
inline bool FListBox::isMultiSelection() const
{ return multi_select; }
//----------------------------------------------------------------------
inline bool FListBox::setEnable()
{ return setEnable(true); }
@ -284,7 +292,15 @@ inline bool FListBox::unsetFocus()
{ return setFocus(false); }
//----------------------------------------------------------------------
inline FString& FListBox::getText()
{ return text; }
inline bool FListBox::isSelected(int index) const
{ return data[uInt(index-1)].selected; }
//----------------------------------------------------------------------
inline bool FListBox::isMultiSelection() const
{ return multi_select; }
//----------------------------------------------------------------------
inline bool FListBox::hasBrackets(int index) const
{ return bool(data[uInt(index-1)].brackets > 0); }
#endif // _FLISTBOX_H

File diff suppressed because it is too large Load Diff

View File

@ -40,6 +40,7 @@
#include "fmenulist.h"
#include "fmenuitem.h"
//----------------------------------------------------------------------
// class FMenu
//----------------------------------------------------------------------
@ -49,31 +50,82 @@
class FMenu : public FWindow, public FMenuList
{
private:
FMenuItem* item;
FWidget* super_menu;
FMenu* open_sub_menu;
uInt max_item_width;
bool mouse_down;
bool has_checkable_items;
public:
// Constructor
explicit FMenu (FWidget* = 0);
FMenu (FString&, FWidget* = 0);
FMenu (const std::string&, FWidget* = 0);
FMenu (const char*, FWidget* = 0);
// Destructor
virtual ~FMenu();
// Accessors
virtual const char* getClassName() const;
FString getText() const;
FMenuItem* getItem() const;
// Mutators
bool setEnable(bool);
bool setEnable();
bool unsetEnable();
bool setDisable();
void setSelected();
void unsetSelected();
bool setMenuWidget (bool);
bool setMenuWidget();
bool unsetMenuWidget();
void setStatusbarMessage (FString);
void setMenu (FMenu*);
void setText (FString&);
void setText (const std::string&);
void setText (const char*);
// Inquiries
bool isEnabled() const;
bool isSelected() const;
bool hasHotkey() const;
bool hasMenu() const;
// Methods
void show();
void hide();
// Event handlers
void onKeyPress (FKeyEvent*);
void onMouseDown (FMouseEvent*);
void onMouseUp (FMouseEvent*);
void onMouseMove (FMouseEvent*);
void onAccel (FAccelEvent*);
// Callback method
void cb_menuitem_toggled (FWidget*, void*);
private:
// Disable copy constructor
FMenu (const FMenu&);
// Disable assignment operator (=)
FMenu& operator = (const FMenu&);
void init(FWidget*);
void calculateDimensions();
void adjustItems();
int adjustX(int);
// Accessors
FWidget* getSuperMenu() const;
// Mutators
void setSuperMenu (FWidget*);
// Inquiries
bool isWindowsMenu (FWidget*) const;
bool isMenuBar (FWidget*) const;
bool isMenu (FWidget*) const;
bool isRadioMenuItem (FWidget*) const;
FWidget* getSuperMenu() const;
void setSuperMenu (FWidget*);
bool isSubMenu() const;
// Methods
void init(FWidget*);
void calculateDimensions();
void adjustItems();
int adjustX(int);
void openSubMenu (FMenu*);
void hideSubMenus();
void hideSuperMenus();
@ -91,94 +143,38 @@ class FMenu : public FWindow, public FMenuList
void drawSeparator(int);
void processActivate();
public:
// Constructor
explicit FMenu (FWidget* = 0);
FMenu (FString&, FWidget* = 0);
FMenu (const std::string&, FWidget* = 0);
FMenu (const char*, FWidget* = 0);
// Destructor
virtual ~FMenu();
virtual const char* getClassName() const;
// Event handlers
void onKeyPress (FKeyEvent*);
void onMouseDown (FMouseEvent*);
void onMouseUp (FMouseEvent*);
void onMouseMove (FMouseEvent*);
void onAccel (FAccelEvent*);
void show();
void hide();
void setStatusbarMessage (FString);
FMenuItem* getItem() const;
FString getText() const;
bool setEnable(bool);
bool setEnable();
bool unsetEnable();
bool setDisable();
bool isEnabled() const;
void setSelected();
void unsetSelected();
bool isSelected() const;
bool setMenuWidget (bool);
bool setMenuWidget();
bool unsetMenuWidget();
bool hasHotkey() const;
void setMenu (FMenu*);
bool hasMenu() const;
void setText (FString&);
void setText (const std::string&);
void setText (const char*);
// Callback method
void cb_menuitem_toggled (FWidget*, void*);
private:
// Friend classes
friend class FApplication;
friend class FCheckMenuItem;
friend class FDialog;
friend class FMenuBar;
friend class FMenuItem;
friend class FRadioMenuItem;
// Data Members
FMenuItem* item;
FWidget* super_menu;
FMenu* open_sub_menu;
uInt max_item_width;
bool mouse_down;
bool has_checkable_items;
};
#pragma pack(pop)
// FMenu inline functions
//----------------------------------------------------------------------
inline FWidget* FMenu::getSuperMenu() const
{ return super_menu; }
//----------------------------------------------------------------------
inline void FMenu::setSuperMenu (FWidget* smenu)
{ super_menu = smenu; }
//----------------------------------------------------------------------
inline bool FMenu::containsMenuStructure (const FPoint& p)
{ return containsMenuStructure (p.getX(), p.getY()); }
//----------------------------------------------------------------------
inline FMenu* FMenu::superMenuAt (const FPoint& p)
{ return superMenuAt (p.getX(), p.getY()); }
//----------------------------------------------------------------------
inline const char* FMenu::getClassName() const
{ return "FMenu"; }
//----------------------------------------------------------------------
inline void FMenu::onAccel (FAccelEvent* ev)
{ item->onAccel(ev); }
inline FString FMenu::getText() const
{ return item->getText(); }
//----------------------------------------------------------------------
inline FMenuItem* FMenu::getItem() const
{ return item; }
//----------------------------------------------------------------------
inline FString FMenu::getText() const
{ return item->getText(); }
//----------------------------------------------------------------------
inline bool FMenu::setEnable(bool on)
{ return item->setEnable(on); }
@ -195,10 +191,6 @@ inline bool FMenu::unsetEnable()
inline bool FMenu::setDisable()
{ return item->setDisable(); }
//----------------------------------------------------------------------
inline bool FMenu::isEnabled() const
{ return item->isEnabled(); }
//----------------------------------------------------------------------
inline void FMenu::setSelected()
{ item->setSelected(); }
@ -207,9 +199,6 @@ inline void FMenu::setSelected()
inline void FMenu::unsetSelected()
{ item->unsetSelected(); }
//----------------------------------------------------------------------
inline bool FMenu::isSelected() const
{ return item->isSelected(); }
//----------------------------------------------------------------------
inline bool FMenu::setMenuWidget()
{ return setMenuWidget(true); }
@ -218,18 +207,10 @@ inline bool FMenu::setMenuWidget()
inline bool FMenu::unsetMenuWidget()
{ return setMenuWidget(false); }
//----------------------------------------------------------------------
inline bool FMenu::hasHotkey() const
{ return item->hasHotkey(); }
//----------------------------------------------------------------------
inline void FMenu::setMenu (FMenu* m)
{ item->setMenu(m); }
//----------------------------------------------------------------------
inline bool FMenu::hasMenu() const
{ return item->hasMenu(); }
//----------------------------------------------------------------------
inline void FMenu::setText (FString& txt)
{ item->setText(txt); }
@ -242,5 +223,41 @@ inline void FMenu::setText (const std::string& txt)
inline void FMenu::setText (const char* txt)
{ item->setText(txt); }
//----------------------------------------------------------------------
inline bool FMenu::isEnabled() const
{ return item->isEnabled(); }
//----------------------------------------------------------------------
inline bool FMenu::isSelected() const
{ return item->isSelected(); }
//----------------------------------------------------------------------
inline bool FMenu::hasHotkey() const
{ return item->hasHotkey(); }
//----------------------------------------------------------------------
inline bool FMenu::hasMenu() const
{ return item->hasMenu(); }
//----------------------------------------------------------------------
inline FWidget* FMenu::getSuperMenu() const
{ return super_menu; }
//----------------------------------------------------------------------
inline void FMenu::setSuperMenu (FWidget* smenu)
{ super_menu = smenu; }
//----------------------------------------------------------------------
inline bool FMenu::containsMenuStructure (const FPoint& p)
{ return containsMenuStructure (p.getX(), p.getY()); }
//----------------------------------------------------------------------
inline FMenu* FMenu::superMenuAt (const FPoint& p)
{ return superMenuAt (p.getX(), p.getY()); }
//----------------------------------------------------------------------
inline void FMenu::onAccel (FAccelEvent* ev)
{ item->onAccel(ev); }
#endif // _FMENU_H

View File

@ -26,6 +26,443 @@ FMenuBar::~FMenuBar()
}
// public methods of FMenuBar
//----------------------------------------------------------------------
void FMenuBar::hide()
{
int screenWidth;
short fg, bg;
char* blank;
FWindow::hide();
fg = wc.term_fg;
bg = wc.term_bg;
setColor (fg, bg);
screenWidth = getColumnNumber();
if ( screenWidth < 0 )
return;
blank = new char[screenWidth+1];
std::memset(blank, ' ', uLong(screenWidth));
blank[screenWidth] = '\0';
setPrintPos (1,1);
print (blank);
delete[] blank;
}
//----------------------------------------------------------------------
void FMenuBar::resetMenu()
{
unselectItem();
drop_down = false;
}
//----------------------------------------------------------------------
void FMenuBar::adjustSize()
{
setGeometry (1, 1, getColumnNumber(), 1, false);
adjustItems();
}
//----------------------------------------------------------------------
void FMenuBar::onKeyPress (FKeyEvent* ev)
{
switch ( ev->key() )
{
case fc::Fkey_return:
case fc::Fkey_enter:
case fc::Fkey_up:
case fc::Fkey_down:
if ( hasSelectedItem() )
{
FMenuItem* sel_item = getSelectedItem();
if ( sel_item->hasMenu() )
{
FMenuItem* first_item;
FMenu* menu = sel_item->getMenu();
sel_item->openMenu();
menu->selectFirstItem();
first_item = menu->getSelectedItem();
if ( first_item )
first_item->setFocus();
menu->redraw();
if ( getStatusBar() )
getStatusBar()->drawMessage();
redraw();
drop_down = true;
}
else if ( ev->key() == fc::Fkey_return
|| ev->key() == fc::Fkey_enter )
{
unselectItem();
redraw();
sel_item->processClicked();
}
}
ev->accept();
break;
case fc::Fkey_left:
selectPrevItem();
ev->accept();
break;
case fc::Fkey_right:
selectNextItem();
ev->accept();
break;
case fc::Fkey_escape:
case fc::Fkey_escape_mintty:
leaveMenuBar();
ev->accept();
break;
default:
break;
}
}
//----------------------------------------------------------------------
void FMenuBar::onMouseDown (FMouseEvent* ev)
{
if ( ev->getButton() != fc::LeftButton )
{
mouse_down = false;
if ( ! item_list.empty() && hasSelectedItem() )
leaveMenuBar();
else
return;
if ( getStatusBar() )
getStatusBar()->clearMessage();
return;
}
if ( mouse_down )
return;
mouse_down = true;
if ( ! isWindowActive() )
setActiveWindow(this);
if ( ! item_list.empty() )
{
std::vector<FMenuItem*>::const_iterator iter, end;
int mouse_x, mouse_y;
bool focus_changed = false;
iter = item_list.begin();
end = item_list.end();
mouse_x = ev->getX();
mouse_y = ev->getY();
while ( iter != end )
{
int x1, x2;
x1 = (*iter)->getX();
x2 = (*iter)->getX() + (*iter)->getWidth();
if ( mouse_y == 1 )
{
if ( mouse_x >= x1 && mouse_x < x2 )
{
// Mouse pointer over item
if ( (*iter)->isEnabled() && ! (*iter)->isSelected() )
{
FWidget* focused_widget = getFocusWidget();
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
(*iter)->setSelected();
(*iter)->setFocus();
if ( focused_widget && ! focused_widget->isWindowWidget() )
focused_widget->redraw();
(*iter)->openMenu();
setSelectedItem(*iter);
focus_changed = true;
if ( (*iter)->hasMenu() )
{
FMenu* menu = (*iter)->getMenu();
if ( menu->hasSelectedItem() )
{
menu->unselectItem();
menu->redraw();
drop_down = true;
}
}
}
}
else if ( (*iter)->isEnabled() && (*iter)->isSelected() )
{
(*iter)->unsetSelected();
if ( getSelectedItem() == *iter )
setSelectedItem(0);
focus_changed = true;
}
}
++iter;
}
if ( getStatusBar() )
getStatusBar()->drawMessage();
if ( focus_changed )
{
redraw();
updateTerminal();
}
}
}
//----------------------------------------------------------------------
void FMenuBar::onMouseUp (FMouseEvent* ev)
{
if ( ev->getButton() != fc::LeftButton )
return;
if ( mouse_down )
{
mouse_down = false;
if ( ! item_list.empty() )
{
int mouse_x, mouse_y;
std::vector<FMenuItem*>::const_iterator iter, end;
iter = item_list.begin();
end = item_list.end();
mouse_x = ev->getX();
mouse_y = ev->getY();
while ( iter != end )
{
int x1, x2;
x1 = (*iter)->getX();
x2 = (*iter)->getX() + (*iter)->getWidth();
if ( mouse_y == 1 )
{
if ( (*iter)->isEnabled() && (*iter)->isSelected() )
{
if ( mouse_x >= x1 && mouse_x < x2 )
{
// Mouse pointer over item
if ( (*iter)->hasMenu() )
{
FMenu* menu = (*iter)->getMenu();
if ( ! menu->hasSelectedItem() )
{
FMenuItem* first_item;
menu->selectFirstItem();
first_item = menu->getSelectedItem();
if ( first_item )
first_item->setFocus();
menu->redraw();
if ( getStatusBar() )
getStatusBar()->drawMessage();
redraw();
drop_down = true;
}
}
else
{
(*iter)->unsetSelected();
if ( getSelectedItem() == *iter )
{
setSelectedItem(0);
leaveMenuBar();
drop_down = false;
(*iter)->processClicked();
return;
}
}
}
else
{
(*iter)->unsetSelected();
if ( getSelectedItem() == *iter )
setSelectedItem(0);
redraw();
}
}
}
++iter;
}
if ( ! hasSelectedItem() )
leaveMenuBar();
}
}
}
//----------------------------------------------------------------------
void FMenuBar::onMouseMove (FMouseEvent* ev)
{
if ( ev->getButton() != fc::LeftButton )
return;
if ( ! isWindowActive() )
setActiveWindow(this);
if ( mouse_down && ! item_list.empty() )
{
std::vector<FMenuItem*>::const_iterator iter, end;
int mouse_x, mouse_y;
bool mouse_over_menubar = false;
bool focus_changed = false;
iter = item_list.begin();
end = item_list.end();
mouse_x = ev->getX();
mouse_y = ev->getY();
if ( getTermGeometry().contains(ev->getTermPos()) )
mouse_over_menubar = true;
while ( iter != end )
{
int x1, x2;
x1 = (*iter)->getX();
x2 = (*iter)->getX() + (*iter)->getWidth();
if ( mouse_x >= x1
&& mouse_x < x2
&& mouse_y == 1 )
{
// Mouse pointer over item
if ( (*iter)->isEnabled() && ! (*iter)->isSelected() )
{
FWidget* focused_widget = getFocusWidget();
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
(*iter)->setSelected();
(*iter)->setFocus();
if ( focused_widget && ! focused_widget->isWindowWidget() )
focused_widget->redraw();
(*iter)->openMenu();
setSelectedItem(*iter);
focus_changed = true;
if ( (*iter)->hasMenu() )
{
FMenu* menu = (*iter)->getMenu();
if ( menu->hasSelectedItem() )
{
menu->unselectItem();
menu->redraw();
drop_down = true;
}
}
}
else if ( getStatusBar() )
getStatusBar()->clearMessage();
}
else
{
if ( mouse_over_menubar
&& (*iter)->isEnabled()
&& (*iter)->isSelected() )
{
// Unselect selected item without mouse focus
(*iter)->unsetSelected();
if ( getSelectedItem() == *iter )
setSelectedItem(0);
focus_changed = true;
drop_down = false;
}
else if ( hasSelectedItem() && getSelectedItem()->hasMenu() )
{
// Mouse event handover to the menu
FMenu* menu = getSelectedItem()->getMenu();
const FRect& menu_geometry = menu->getTermGeometry();
if ( menu->getCount() > 0
&& menu_geometry.contains(ev->getTermPos()) )
{
FMouseEvent* _ev;
const FPoint& t = ev->getTermPos();
const FPoint& p = menu->termToWidgetPos(t);
int b = ev->getButton();
_ev = new FMouseEvent (fc::MouseMove_Event, p, t, b);
menu->mouse_down = true;
setClickedWidget(menu);
menu->onMouseMove(_ev);
delete _ev;
}
}
}
++iter;
}
if ( getStatusBar() )
getStatusBar()->drawMessage();
if ( focus_changed )
{
redraw();
updateTerminal();
}
}
}
//----------------------------------------------------------------------
void FMenuBar::onAccel (FAccelEvent* ev)
{
unselectItem();
selectFirstItem();
getSelectedItem()->setFocus();
if ( getStatusBar() )
getStatusBar()->drawMessage();
redraw();
ev->accept();
}
//----------------------------------------------------------------------
void FMenuBar::cb_item_deactivated (FWidget* widget, void*)
{
FMenuItem* menuitem = static_cast<FMenuItem*>(widget);
if ( menuitem->hasMenu() )
{
FMenu* menu = menuitem->getMenu();
menu->hide();
menu->hideSubMenus();
}
}
// private methods of FMenuBar
//----------------------------------------------------------------------
void FMenuBar::init()
@ -76,12 +513,6 @@ void FMenuBar::calculateDimensions()
}
}
//----------------------------------------------------------------------
bool FMenuBar::isMenu (FMenuItem* mi) const
{
return mi->hasMenu();
}
//----------------------------------------------------------------------
bool FMenuBar::selectNextItem()
{
@ -132,8 +563,8 @@ bool FMenuBar::selectNextItem()
menu->redraw();
}
if ( statusBar() )
statusBar()->drawMessage();
if ( getStatusBar() )
getStatusBar()->drawMessage();
redraw();
break;
@ -196,8 +627,8 @@ bool FMenuBar::selectPrevItem()
menu->redraw();
}
if ( statusBar() )
statusBar()->drawMessage();
if ( getStatusBar() )
getStatusBar()->drawMessage();
setSelectedItem(prev);
redraw();
@ -248,8 +679,8 @@ bool FMenuBar::hotkeyMenu (FKeyEvent*& ev)
menu->redraw();
if ( statusBar() )
statusBar()->drawMessage();
if ( getStatusBar() )
getStatusBar()->drawMessage();
redraw();
drop_down = true;
@ -494,452 +925,15 @@ void FMenuBar::leaveMenuBar()
resetMenu();
redraw();
if ( statusBar() )
statusBar()->clearMessage();
if ( getStatusBar() )
getStatusBar()->clearMessage();
switchToPrevWindow();
if ( statusBar() )
statusBar()->drawMessage();
if ( getStatusBar() )
getStatusBar()->drawMessage();
updateTerminal();
flush_out();
mouse_down = false;
}
// public methods of FMenuBar
//----------------------------------------------------------------------
void FMenuBar::onKeyPress (FKeyEvent* ev)
{
switch ( ev->key() )
{
case fc::Fkey_return:
case fc::Fkey_enter:
case fc::Fkey_up:
case fc::Fkey_down:
if ( hasSelectedItem() )
{
FMenuItem* sel_item = getSelectedItem();
if ( sel_item->hasMenu() )
{
FMenuItem* first_item;
FMenu* menu = sel_item->getMenu();
sel_item->openMenu();
menu->selectFirstItem();
first_item = menu->getSelectedItem();
if ( first_item )
first_item->setFocus();
menu->redraw();
if ( statusBar() )
statusBar()->drawMessage();
redraw();
drop_down = true;
}
else if ( ev->key() == fc::Fkey_return
|| ev->key() == fc::Fkey_enter )
{
unselectItem();
redraw();
sel_item->processClicked();
}
}
ev->accept();
break;
case fc::Fkey_left:
selectPrevItem();
ev->accept();
break;
case fc::Fkey_right:
selectNextItem();
ev->accept();
break;
case fc::Fkey_escape:
case fc::Fkey_escape_mintty:
leaveMenuBar();
ev->accept();
break;
default:
break;
}
}
//----------------------------------------------------------------------
void FMenuBar::onMouseDown (FMouseEvent* ev)
{
if ( ev->getButton() != fc::LeftButton )
{
mouse_down = false;
if ( ! item_list.empty() && hasSelectedItem() )
leaveMenuBar();
else
return;
if ( statusBar() )
statusBar()->clearMessage();
return;
}
if ( mouse_down )
return;
mouse_down = true;
if ( ! isWindowActive() )
setActiveWindow(this);
if ( ! item_list.empty() )
{
std::vector<FMenuItem*>::const_iterator iter, end;
int mouse_x, mouse_y;
bool focus_changed = false;
iter = item_list.begin();
end = item_list.end();
mouse_x = ev->getX();
mouse_y = ev->getY();
while ( iter != end )
{
int x1, x2;
x1 = (*iter)->getX();
x2 = (*iter)->getX() + (*iter)->getWidth();
if ( mouse_y == 1 )
{
if ( mouse_x >= x1 && mouse_x < x2 )
{
// Mouse pointer over item
if ( (*iter)->isEnabled() && ! (*iter)->isSelected() )
{
FWidget* focused_widget = getFocusWidget();
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
(*iter)->setSelected();
(*iter)->setFocus();
if ( focused_widget && ! focused_widget->isWindowWidget() )
focused_widget->redraw();
(*iter)->openMenu();
setSelectedItem(*iter);
focus_changed = true;
if ( (*iter)->hasMenu() )
{
FMenu* menu = (*iter)->getMenu();
if ( menu->hasSelectedItem() )
{
menu->unselectItem();
menu->redraw();
drop_down = true;
}
}
}
}
else if ( (*iter)->isEnabled() && (*iter)->isSelected() )
{
(*iter)->unsetSelected();
if ( getSelectedItem() == *iter )
setSelectedItem(0);
focus_changed = true;
}
}
++iter;
}
if ( statusBar() )
statusBar()->drawMessage();
if ( focus_changed )
{
redraw();
updateTerminal();
}
}
}
//----------------------------------------------------------------------
void FMenuBar::onMouseUp (FMouseEvent* ev)
{
if ( ev->getButton() != fc::LeftButton )
return;
if ( mouse_down )
{
mouse_down = false;
if ( ! item_list.empty() )
{
int mouse_x, mouse_y;
std::vector<FMenuItem*>::const_iterator iter, end;
iter = item_list.begin();
end = item_list.end();
mouse_x = ev->getX();
mouse_y = ev->getY();
while ( iter != end )
{
int x1, x2;
x1 = (*iter)->getX();
x2 = (*iter)->getX() + (*iter)->getWidth();
if ( mouse_y == 1 )
{
if ( (*iter)->isEnabled() && (*iter)->isSelected() )
{
if ( mouse_x >= x1 && mouse_x < x2 )
{
// Mouse pointer over item
if ( (*iter)->hasMenu() )
{
FMenu* menu = (*iter)->getMenu();
if ( ! menu->hasSelectedItem() )
{
FMenuItem* first_item;
menu->selectFirstItem();
first_item = menu->getSelectedItem();
if ( first_item )
first_item->setFocus();
menu->redraw();
if ( statusBar() )
statusBar()->drawMessage();
redraw();
drop_down = true;
}
}
else
{
(*iter)->unsetSelected();
if ( getSelectedItem() == *iter )
{
setSelectedItem(0);
leaveMenuBar();
drop_down = false;
(*iter)->processClicked();
return;
}
}
}
else
{
(*iter)->unsetSelected();
if ( getSelectedItem() == *iter )
setSelectedItem(0);
redraw();
}
}
}
++iter;
}
if ( ! hasSelectedItem() )
leaveMenuBar();
}
}
}
//----------------------------------------------------------------------
void FMenuBar::onMouseMove (FMouseEvent* ev)
{
if ( ev->getButton() != fc::LeftButton )
return;
if ( ! isWindowActive() )
setActiveWindow(this);
if ( mouse_down && ! item_list.empty() )
{
std::vector<FMenuItem*>::const_iterator iter, end;
int mouse_x, mouse_y;
bool mouse_over_menubar = false;
bool focus_changed = false;
iter = item_list.begin();
end = item_list.end();
mouse_x = ev->getX();
mouse_y = ev->getY();
if ( getTermGeometry().contains(ev->getTermPos()) )
mouse_over_menubar = true;
while ( iter != end )
{
int x1, x2;
x1 = (*iter)->getX();
x2 = (*iter)->getX() + (*iter)->getWidth();
if ( mouse_x >= x1
&& mouse_x < x2
&& mouse_y == 1 )
{
// Mouse pointer over item
if ( (*iter)->isEnabled() && ! (*iter)->isSelected() )
{
FWidget* focused_widget = getFocusWidget();
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
(*iter)->setSelected();
(*iter)->setFocus();
if ( focused_widget && ! focused_widget->isWindowWidget() )
focused_widget->redraw();
(*iter)->openMenu();
setSelectedItem(*iter);
focus_changed = true;
if ( (*iter)->hasMenu() )
{
FMenu* menu = (*iter)->getMenu();
if ( menu->hasSelectedItem() )
{
menu->unselectItem();
menu->redraw();
drop_down = true;
}
}
}
else if ( statusBar() )
statusBar()->clearMessage();
}
else
{
if ( mouse_over_menubar
&& (*iter)->isEnabled()
&& (*iter)->isSelected() )
{
// Unselect selected item without mouse focus
(*iter)->unsetSelected();
if ( getSelectedItem() == *iter )
setSelectedItem(0);
focus_changed = true;
drop_down = false;
}
else if ( hasSelectedItem() && getSelectedItem()->hasMenu() )
{
// Mouse event handover to the menu
FMenu* menu = getSelectedItem()->getMenu();
const FRect& menu_geometry = menu->getTermGeometry();
if ( menu->count() > 0
&& menu_geometry.contains(ev->getTermPos()) )
{
FMouseEvent* _ev;
const FPoint& t = ev->getTermPos();
const FPoint& p = menu->termToWidgetPos(t);
int b = ev->getButton();
_ev = new FMouseEvent (fc::MouseMove_Event, p, t, b);
menu->mouse_down = true;
setClickedWidget(menu);
menu->onMouseMove(_ev);
delete _ev;
}
}
}
++iter;
}
if ( statusBar() )
statusBar()->drawMessage();
if ( focus_changed )
{
redraw();
updateTerminal();
}
}
}
//----------------------------------------------------------------------
void FMenuBar::onAccel (FAccelEvent* ev)
{
unselectItem();
selectFirstItem();
getSelectedItem()->setFocus();
if ( statusBar() )
statusBar()->drawMessage();
redraw();
ev->accept();
}
//----------------------------------------------------------------------
void FMenuBar::hide()
{
int screenWidth;
short fg, bg;
char* blank;
FWindow::hide();
fg = wc.term_fg;
bg = wc.term_bg;
setColor (fg, bg);
screenWidth = getColumnNumber();
if ( screenWidth < 0 )
return;
blank = new char[screenWidth+1];
std::memset(blank, ' ', uLong(screenWidth));
blank[screenWidth] = '\0';
setPrintPos (1,1);
print (blank);
delete[] blank;
}
//----------------------------------------------------------------------
void FMenuBar::resetMenu()
{
unselectItem();
drop_down = false;
}
//----------------------------------------------------------------------
void FMenuBar::adjustSize()
{
setGeometry (1, 1, getColumnNumber(), 1, false);
adjustItems();
}
//----------------------------------------------------------------------
void FMenuBar::cb_item_deactivated (FWidget* widget, void*)
{
FMenuItem* menuitem = static_cast<FMenuItem*>(widget);
if ( menuitem->hasMenu() )
{
FMenu* menu = menuitem->getMenu();
menu->hide();
menu->hideSubMenus();
}
}

View File

@ -49,19 +49,44 @@
class FMenuBar : public FWindow, public FMenuList
{
private:
bool mouse_down;
bool drop_down;
public:
// Constructor
explicit FMenuBar (FWidget* = 0);
// Destructor
virtual ~FMenuBar();
// Accessors
virtual const char* getClassName() const;
// Methods
void hide();
void resetMenu();
void adjustSize();
// Event handlers
void onKeyPress (FKeyEvent*);
void onMouseDown (FMouseEvent*);
void onMouseUp (FMouseEvent*);
void onMouseMove (FMouseEvent*);
void onAccel (FAccelEvent*);
// Callback methods
void cb_item_deactivated (FWidget*, void*);
private:
// Disable copy constructor
FMenuBar (const FMenuBar&);
// Disable assignment operator (=)
FMenuBar& operator = (const FMenuBar&);
// Inquiry
bool isMenu (FMenuItem*) const;
// Methods
void init();
void calculateDimensions();
bool isMenu (FMenuItem*) const;
bool selectNextItem();
bool selectPrevItem();
bool hotkeyMenu (FKeyEvent*&);
@ -71,31 +96,13 @@ class FMenuBar : public FWindow, public FMenuList
void adjustItems();
void leaveMenuBar();
public:
// Constructor
explicit FMenuBar (FWidget* = 0);
// Destructor
virtual ~FMenuBar();
virtual const char* getClassName() const;
// Event handlers
void onKeyPress (FKeyEvent*);
void onMouseDown (FMouseEvent*);
void onMouseUp (FMouseEvent*);
void onMouseMove (FMouseEvent*);
void onAccel (FAccelEvent*);
void hide();
void resetMenu();
void adjustSize();
// Callback methods
void cb_item_deactivated (FWidget*, void*);
private:
// Friend classes
friend class FMenu;
friend class FMenuItem;
// Data Members
bool mouse_down;
bool drop_down;
};
#pragma pack(pop)
@ -105,4 +112,8 @@ class FMenuBar : public FWindow, public FMenuList
inline const char* FMenuBar::getClassName() const
{ return "FMenuBar"; }
//----------------------------------------------------------------------
inline bool FMenuBar::isMenu (FMenuItem* mi) const
{ return mi->hasMenu(); }
#endif // _FMENUBAR_H

View File

@ -165,218 +165,143 @@ FMenuItem::~FMenuItem() // destructor
}
// private methods of FMenuItem
// public methods of FMenuItem
//----------------------------------------------------------------------
void FMenuItem::init (FWidget* parent)
bool FMenuItem::setEnable (bool on)
{
FWidget::setEnable(on);
FWidget* super = getSuperMenu();
if ( on )
{
flags |= fc::active;
if ( super && isMenuBar(super) )
{
// Meta + hotkey
super->addAccelerator (fc::Fmkey_meta + std::tolower(hotkey), this);
}
}
else
{
flags &= ~fc::active;
if ( super && isMenuBar(super) )
super->delAccelerator (this);
}
return on;
}
//----------------------------------------------------------------------
bool FMenuItem::setFocus (bool on)
{
FWidget::setFocus(on);
if ( on )
{
flags |= fc::focus;
if ( isEnabled() )
{
if ( ! selected )
{
FMenuList* menu_list = dynamic_cast<FMenuList*>(getSuperMenu());
setSelected();
if ( menu_list )
{
menu_list->unselectItem();
menu_list->setSelectedItem(this);
}
if ( getStatusBar() )
getStatusBar()->drawMessage();
FWidget* parent = getSuperMenu();
if ( isMenuBar(parent) )
{
FMenuBar* menubar_ptr = dynamic_cast<FMenuBar*>(parent);
if ( menubar_ptr )
menubar_ptr->redraw();
}
else if ( isMenu(parent) )
{
FMenu* menu_ptr = dynamic_cast<FMenu*>(parent);
if ( menu_ptr )
menu_ptr->redraw();
}
}
if ( getStatusBar() )
{
FString msg = getStatusbarMessage();
FString curMsg = getStatusBar()->getMessage();
if ( curMsg != msg )
getStatusBar()->setMessage(msg);
}
}
}
else
{
flags &= ~fc::focus;
if ( isEnabled() && getStatusBar() )
getStatusBar()->clearMessage();
}
return on;
}
//----------------------------------------------------------------------
void FMenuItem::setSelected()
{
if ( isEnabled() )
{
selected = true;
processActivate();
}
}
//----------------------------------------------------------------------
void FMenuItem::unsetSelected()
{
selected = false;
processDeactivate();
}
//----------------------------------------------------------------------
void FMenuItem::setText (FString& txt)
{
text = txt;
text_length = text.getLength();
hotkey = hotKey();
if ( hotkey )
text_length--;
setGeometry (1,1,int(text_length+2),1, false);
if ( parent )
{
FMenuList* menu_list;
setSuperMenu (parent);
if ( accel_key )
addAccelerator (accel_key);
menu_list = dynamic_cast<FMenuList*>(parent);
if ( menu_list )
menu_list->insert(this);
if ( isMenuBar(parent) ) // Parent is menubar
{
FMenuBar* menubar_ptr = dynamic_cast<FMenuBar*>(parent);
if ( menubar_ptr )
{
menubar_ptr->calculateDimensions();
if ( hotkey ) // Meta + hotkey
menubar_ptr->addAccelerator (fc::Fmkey_meta + std::tolower(hotkey), this);
}
this->addCallback
(
"deactivate",
_METHOD_CALLBACK (parent, &FMenuBar::cb_item_deactivated)
);
}
else if ( isMenu(parent) ) // Parent is menu
{
FMenu* menu_ptr = dynamic_cast<FMenu*>(parent);
if ( menu_ptr )
menu_ptr->calculateDimensions();
}
}
if ( hasFocus() )
flags = fc::focus;
if ( isEnabled() )
flags |= fc::active;
setWidth(int(text_length));
}
//----------------------------------------------------------------------
uChar FMenuItem::hotKey()
void FMenuItem::setText (const std::string& txt)
{
uInt length;
if ( text.isEmpty() )
return 0;
length = text.getLength();
for (uInt i=0; i < length; i++)
{
try
{
if ( (i+1 < length) && (text[i] == '&') )
return uChar(text[++i]);
}
catch (const std::out_of_range&)
{
return 0;;
}
}
return 0;
FString s = FString(txt);
setText (s);
}
//----------------------------------------------------------------------
void FMenuItem::processActivate()
void FMenuItem::setText (const char* txt)
{
emitCallback("activate");
FString s = FString(txt);
setText (s);
}
//----------------------------------------------------------------------
void FMenuItem::processDeactivate()
{
emitCallback("deactivate");
}
//----------------------------------------------------------------------
void FMenuItem::createDialogList (FMenu* winmenu)
{
winmenu->clear();
if ( dialog_list && ! dialog_list->empty() )
{
widgetList::const_iterator iter, begin;
iter = begin = dialog_list->begin();
while ( iter != dialog_list->end() && *iter )
{
FDialog* win = dynamic_cast<FDialog*>(*iter);
if ( win )
{
int n = int(std::distance(begin, iter));
// get the dialog title
FString name = win->getText();
// create a new dialog list item
FMenuItem* win_item = new FMenuItem (name, winmenu);
if ( n < 9 )
win_item->addAccelerator (fc::Fmkey_1 + n); // Meta + 1..9
win_item->addCallback
(
"clicked",
_METHOD_CALLBACK (win_item, &FMenuItem::cb_switchToDialog),
dynamic_cast<FWidget::data_ptr>(win)
);
win->addCallback
(
"destroy",
_METHOD_CALLBACK (win_item, &FMenuItem::cb_destroyDialog)
);
win_item->associated_window = win;
}
++iter;
}
}
winmenu->calculateDimensions();
}
//----------------------------------------------------------------------
void FMenuItem::cb_switchToDialog (FWidget*, void* data_ptr)
{
FDialog* win = static_cast<FDialog*>(data_ptr);
if ( win )
{
FWidget* focus_widget = getFocusWidget();
FAccelEvent a_ev (fc::Accelerator_Event, focus_widget);
FApplication::sendEvent (win, &a_ev);
}
}
//----------------------------------------------------------------------
void FMenuItem::cb_destroyDialog (FWidget* widget, void*)
{
FDialog* win = static_cast<FDialog*>(widget);
FApplication* fapp = static_cast<FApplication*>(getRootWidget());
if ( win && fapp )
{
delAccelerator(win);
delCallback(win);
associated_window = 0;
}
}
//----------------------------------------------------------------------
void FMenuItem::processClicked()
{
emitCallback("clicked");
}
// protected methods of FMenuItem
//----------------------------------------------------------------------
bool FMenuItem::isWindowsMenu (FWidget* w) const
{
return ( ! w ) ? false : w->isDialogWidget();
}
//----------------------------------------------------------------------
bool FMenuItem::isMenuBar (FWidget* w) const
{
if ( ! w )
return false;
else
return bool( std::strcmp ( w->getClassName()
, const_cast<char*>("FMenuBar") ) == 0 );
}
//----------------------------------------------------------------------
bool FMenuItem::isMenu (FWidget* w) const
{
if ( ! w )
return false;
bool m1 = ( std::strcmp ( w->getClassName()
, const_cast<char*>("FMenu") ) == 0 );
bool m2 = ( std::strcmp ( w->getClassName()
, const_cast<char*>("FDialogListMenu") ) == 0 );
return bool( m1 || m2 );
}
// public methods of FMenuItem
//----------------------------------------------------------------------
void FMenuItem::addAccelerator (int key, FWidget* obj)
{
FWidget* root = getRootWidget();
@ -430,6 +355,40 @@ void FMenuItem::delAccelerator (FWidget* obj)
}
}
//----------------------------------------------------------------------
void FMenuItem::openMenu()
{
FMenu* dd_menu; // Drop-down menu
FMenu* open_menu;
if ( ! hasMenu() )
return;
dd_menu = getMenu(); // Drop-down menu
if ( dd_menu->isVisible() )
return;
open_menu = static_cast<FMenu*>(getOpenMenu());
if ( open_menu && open_menu != dd_menu )
{
open_menu->hide();
open_menu->hideSubMenus();
}
if ( dialog_index )
createDialogList (dd_menu);
setOpenMenu(dd_menu);
dd_menu->setVisible();
dd_menu->show();
dd_menu->raiseWindow(dd_menu);
dd_menu->redraw();
updateTerminal();
flush_out();
}
//----------------------------------------------------------------------
void FMenuItem::onKeyPress (FKeyEvent* ev)
{
@ -696,8 +655,8 @@ void FMenuItem::onAccel (FAccelEvent* ev)
menu->redraw();
if ( statusBar() )
statusBar()->drawMessage();
if ( getStatusBar() )
getStatusBar()->drawMessage();
mbar->redraw();
mbar->drop_down = true;
@ -716,8 +675,8 @@ void FMenuItem::onAccel (FAccelEvent* ev)
//----------------------------------------------------------------------
void FMenuItem::onFocusIn (FFocusEvent*)
{
if ( statusBar() )
statusBar()->drawMessage();
if ( getStatusBar() )
getStatusBar()->drawMessage();
}
//----------------------------------------------------------------------
@ -733,178 +692,219 @@ void FMenuItem::onFocusOut (FFocusEvent*)
mbar->redraw();
}
if ( statusBar() )
if ( getStatusBar() )
{
statusBar()->clearMessage();
statusBar()->drawMessage();
getStatusBar()->clearMessage();
getStatusBar()->drawMessage();
}
}
// protected methods of FMenuItem
//----------------------------------------------------------------------
bool FMenuItem::setEnable (bool on)
bool FMenuItem::isWindowsMenu (FWidget* w) const
{
FWidget::setEnable(on);
FWidget* super = getSuperMenu();
return ( ! w ) ? false : w->isDialogWidget();
}
if ( on )
{
flags |= fc::active;
if ( super && isMenuBar(super) )
{
// Meta + hotkey
super->addAccelerator (fc::Fmkey_meta + std::tolower(hotkey), this);
}
}
//----------------------------------------------------------------------
bool FMenuItem::isMenuBar (FWidget* w) const
{
if ( ! w )
return false;
else
{
flags &= ~fc::active;
if ( super && isMenuBar(super) )
super->delAccelerator (this);
}
return on;
return bool( std::strcmp ( w->getClassName()
, const_cast<char*>("FMenuBar") ) == 0 );
}
//----------------------------------------------------------------------
bool FMenuItem::setFocus (bool on)
bool FMenuItem::isMenu (FWidget* w) const
{
FWidget::setFocus(on);
if ( ! w )
return false;
if ( on )
{
flags |= fc::focus;
if ( isEnabled() )
{
if ( ! selected )
{
FMenuList* menu_list = dynamic_cast<FMenuList*>(getSuperMenu());
setSelected();
if ( menu_list )
{
menu_list->unselectItem();
menu_list->setSelectedItem(this);
}
if ( statusBar() )
statusBar()->drawMessage();
FWidget* parent = getSuperMenu();
if ( isMenuBar(parent) )
{
FMenuBar* menubar_ptr = dynamic_cast<FMenuBar*>(parent);
if ( menubar_ptr )
menubar_ptr->redraw();
}
else if ( isMenu(parent) )
{
FMenu* menu_ptr = dynamic_cast<FMenu*>(parent);
if ( menu_ptr )
menu_ptr->redraw();
}
}
if ( statusBar() )
{
FString msg = getStatusbarMessage();
FString curMsg = statusBar()->getMessage();
if ( curMsg != msg )
statusBar()->setMessage(msg);
}
}
}
else
{
flags &= ~fc::focus;
if ( isEnabled() && statusBar() )
statusBar()->clearMessage();
}
return on;
bool m1 = ( std::strcmp ( w->getClassName()
, const_cast<char*>("FMenu") ) == 0 );
bool m2 = ( std::strcmp ( w->getClassName()
, const_cast<char*>("FDialogListMenu") ) == 0 );
return bool( m1 || m2 );
}
// private methods of FMenuItem
//----------------------------------------------------------------------
void FMenuItem::setSelected()
void FMenuItem::init (FWidget* parent)
{
if ( isEnabled() )
{
selected = true;
processActivate();
}
}
//----------------------------------------------------------------------
void FMenuItem::unsetSelected()
{
selected = false;
processDeactivate();
}
//----------------------------------------------------------------------
void FMenuItem::openMenu()
{
FMenu* dd_menu; // Drop-down menu
FMenu* open_menu;
if ( ! hasMenu() )
return;
dd_menu = getMenu(); // Drop-down menu
if ( dd_menu->isVisible() )
return;
open_menu = static_cast<FMenu*>(getOpenMenu());
if ( open_menu && open_menu != dd_menu )
{
open_menu->hide();
open_menu->hideSubMenus();
}
if ( dialog_index )
createDialogList (dd_menu);
setOpenMenu(dd_menu);
dd_menu->setVisible();
dd_menu->show();
dd_menu->raiseWindow(dd_menu);
dd_menu->redraw();
updateTerminal();
flush_out();
}
//----------------------------------------------------------------------
void FMenuItem::setText (FString& txt)
{
text = txt;
text_length = text.getLength();
hotkey = hotKey();
if ( hotkey )
text_length--;
setWidth(int(text_length));
setGeometry (1,1,int(text_length+2),1, false);
if ( parent )
{
FMenuList* menu_list;
setSuperMenu (parent);
if ( accel_key )
addAccelerator (accel_key);
menu_list = dynamic_cast<FMenuList*>(parent);
if ( menu_list )
menu_list->insert(this);
if ( isMenuBar(parent) ) // Parent is menubar
{
FMenuBar* menubar_ptr = dynamic_cast<FMenuBar*>(parent);
if ( menubar_ptr )
{
menubar_ptr->calculateDimensions();
if ( hotkey ) // Meta + hotkey
menubar_ptr->addAccelerator (fc::Fmkey_meta + std::tolower(hotkey), this);
}
this->addCallback
(
"deactivate",
_METHOD_CALLBACK (parent, &FMenuBar::cb_item_deactivated)
);
}
else if ( isMenu(parent) ) // Parent is menu
{
FMenu* menu_ptr = dynamic_cast<FMenu*>(parent);
if ( menu_ptr )
menu_ptr->calculateDimensions();
}
}
if ( hasFocus() )
flags = fc::focus;
if ( isEnabled() )
flags |= fc::active;
}
//----------------------------------------------------------------------
void FMenuItem::setText (const std::string& txt)
uChar FMenuItem::hotKey()
{
FString s = FString(txt);
setText (s);
uInt length;
if ( text.isEmpty() )
return 0;
length = text.getLength();
for (uInt i=0; i < length; i++)
{
try
{
if ( (i+1 < length) && (text[i] == '&') )
return uChar(text[++i]);
}
catch (const std::out_of_range&)
{
return 0;;
}
}
return 0;
}
//----------------------------------------------------------------------
void FMenuItem::setText (const char* txt)
void FMenuItem::processActivate()
{
FString s = FString(txt);
setText (s);
emitCallback("activate");
}
//----------------------------------------------------------------------
void FMenuItem::processDeactivate()
{
emitCallback("deactivate");
}
//----------------------------------------------------------------------
void FMenuItem::createDialogList (FMenu* winmenu)
{
winmenu->clear();
if ( dialog_list && ! dialog_list->empty() )
{
widgetList::const_iterator iter, begin;
iter = begin = dialog_list->begin();
while ( iter != dialog_list->end() && *iter )
{
FDialog* win = dynamic_cast<FDialog*>(*iter);
if ( win )
{
int n = int(std::distance(begin, iter));
// get the dialog title
FString name = win->getText();
// create a new dialog list item
FMenuItem* win_item = new FMenuItem (name, winmenu);
if ( n < 9 )
win_item->addAccelerator (fc::Fmkey_1 + n); // Meta + 1..9
win_item->addCallback
(
"clicked",
_METHOD_CALLBACK (win_item, &FMenuItem::cb_switchToDialog),
dynamic_cast<FWidget::data_ptr>(win)
);
win->addCallback
(
"destroy",
_METHOD_CALLBACK (win_item, &FMenuItem::cb_destroyDialog)
);
win_item->associated_window = win;
}
++iter;
}
}
winmenu->calculateDimensions();
}
//----------------------------------------------------------------------
void FMenuItem::cb_switchToDialog (FWidget*, void* data_ptr)
{
FDialog* win = static_cast<FDialog*>(data_ptr);
if ( win )
{
FWidget* focus_widget = getFocusWidget();
FAccelEvent a_ev (fc::Accelerator_Event, focus_widget);
FApplication::sendEvent (win, &a_ev);
}
}
//----------------------------------------------------------------------
void FMenuItem::cb_destroyDialog (FWidget* widget, void*)
{
FDialog* win = static_cast<FDialog*>(widget);
FApplication* fapp = static_cast<FApplication*>(getRootWidget());
if ( win && fapp )
{
delAccelerator(win);
delCallback(win);
associated_window = 0;
}
}
//----------------------------------------------------------------------
void FMenuItem::processClicked()
{
emitCallback("clicked");
}

View File

@ -48,7 +48,82 @@ class FMenuList;
class FMenuItem : public FWidget
{
public:
// Using-declarations
using FWidget::addAccelerator;
using FWidget::delAccelerator;
using FWidget::setEnable;
// Constructor
explicit FMenuItem (FWidget* = 0);
FMenuItem (FString&, FWidget* = 0);
FMenuItem (const std::string&, FWidget* = 0);
FMenuItem (const char*, FWidget* = 0);
FMenuItem (int, FString&, FWidget* = 0);
FMenuItem (int, const std::string&, FWidget* = 0);
FMenuItem (int, const char*, FWidget* = 0);
// Destructor
virtual ~FMenuItem();
// Accessors
const char* getClassName() const;
int getHotkey() const;
FMenu* getMenu() const;
uInt getTextLength() const;
FString getText() const;
// Mutators
bool setEnable (bool);
bool setFocus (bool);
bool setFocus();
bool unsetFocus();
void setSelected();
void unsetSelected();
void setSeparator();
void unsetSeparator();
void setChecked();
void unsetChecked();
void setMenu (FMenu*);
void setText (FString&);
void setText (const std::string&);
void setText (const char*);
// Inquiries
bool isSelected() const;
bool isSeparator() const;
bool isChecked() const;
bool hasHotkey() const;
bool hasMenu() const;
// Methods
void addAccelerator (int, FWidget*);
void delAccelerator (FWidget*);
void openMenu();
// Event handlers
void onKeyPress (FKeyEvent*);
void onMouseDoubleClick (FMouseEvent*);
void onMouseDown (FMouseEvent*);
void onMouseUp (FMouseEvent*);
void onMouseMove (FMouseEvent*);
void onAccel (FAccelEvent*);
void onFocusIn (FFocusEvent*);
void onFocusOut (FFocusEvent*);
protected:
// Accessor
FWidget* getSuperMenu() const;
// Mutator
void setSuperMenu (FWidget*);
// Inquiries
bool isWindowsMenu (FWidget*) const;
bool isMenuBar (FWidget*) const;
bool isMenu (FWidget*) const;
// Data Members
FString text;
bool selected;
bool separator;
@ -66,9 +141,11 @@ class FMenuItem : public FWidget
private:
// Disable copy constructor
FMenuItem (const FMenuItem&);
// Disable assignment operator (=)
FMenuItem& operator = (const FMenuItem&);
// Methods
void init (FWidget*);
uChar hotKey();
void processActivate();
@ -81,71 +158,7 @@ class FMenuItem : public FWidget
virtual void processClicked();
protected:
bool isWindowsMenu (FWidget*) const;
bool isMenuBar (FWidget*) const;
bool isMenu (FWidget*) const;
FWidget* getSuperMenu() const;
void setSuperMenu (FWidget*);
public:
// Constructor
explicit FMenuItem (FWidget* = 0);
FMenuItem (FString&, FWidget* = 0);
FMenuItem (const std::string&, FWidget* = 0);
FMenuItem (const char*, FWidget* = 0);
FMenuItem (int, FString&, FWidget* = 0);
FMenuItem (int, const std::string&, FWidget* = 0);
FMenuItem (int, const char*, FWidget* = 0);
// Destructor
virtual ~FMenuItem();
const char* getClassName() const;
// make every addAccelerator from FWidget available
using FWidget::addAccelerator;
void addAccelerator (int, FWidget*);
// make every delAccelerator from FWidget available
using FWidget::delAccelerator;
void delAccelerator (FWidget*);
// Event handlers
void onKeyPress (FKeyEvent*);
void onMouseDoubleClick (FMouseEvent*);
void onMouseDown (FMouseEvent*);
void onMouseUp (FMouseEvent*);
void onMouseMove (FMouseEvent*);
void onAccel (FAccelEvent*);
void onFocusIn (FFocusEvent*);
void onFocusOut (FFocusEvent*);
// make every setEnable from FWidget available
using FWidget::setEnable;
bool setEnable(bool);
bool setFocus(bool);
bool setFocus();
bool unsetFocus();
void setSelected();
void unsetSelected();
bool isSelected() const;
void setSeparator();
void unsetSeparator();
bool isSeparator() const;
void setChecked();
void unsetChecked();
bool isChecked() const;
int getHotkey() const;
bool hasHotkey() const;
FMenu* getMenu() const;
void setMenu(FMenu*);
bool hasMenu() const;
void openMenu();
uInt getTextLength() const;
FString getText() const;
void setText (FString&);
void setText (const std::string&);
void setText (const char*);
private:
// Friend classes
friend class FDialogListMenu;
friend class FMenuList;
friend class FMenuBar;
@ -160,12 +173,20 @@ inline const char* FMenuItem::getClassName() const
{ return "FMenuItem"; }
//----------------------------------------------------------------------
inline FWidget* FMenuItem::getSuperMenu() const
{ return super_menu; }
inline int FMenuItem::getHotkey() const
{ return hotkey; }
//----------------------------------------------------------------------
inline void FMenuItem::setSuperMenu (FWidget* smenu)
{ super_menu = smenu; }
inline FMenu* FMenuItem::getMenu() const
{ return menu; }
//----------------------------------------------------------------------
inline uInt FMenuItem::getTextLength() const
{ return text_length; }
//----------------------------------------------------------------------
inline FString FMenuItem::getText() const
{ return text; }
//----------------------------------------------------------------------
inline bool FMenuItem::setFocus()
@ -175,10 +196,6 @@ inline bool FMenuItem::setFocus()
inline bool FMenuItem::unsetFocus()
{ return setFocus(false); }
//----------------------------------------------------------------------
inline bool FMenuItem::isSelected() const
{ return selected; }
//----------------------------------------------------------------------
inline void FMenuItem::setSeparator()
{
@ -193,10 +210,6 @@ inline void FMenuItem::unsetSeparator()
setFocusable();
}
//----------------------------------------------------------------------
inline bool FMenuItem::isSeparator() const
{ return separator; }
//----------------------------------------------------------------------
inline void FMenuItem::setChecked()
{ checked = true; }
@ -206,35 +219,35 @@ inline void FMenuItem::unsetChecked()
{ checked = false; }
//----------------------------------------------------------------------
inline bool FMenuItem::isChecked() const
{ return checked; }
inline void FMenuItem::setMenu(FMenu* m)
{ menu = m; }
//----------------------------------------------------------------------
inline int FMenuItem::getHotkey() const
{ return hotkey; }
inline bool FMenuItem::isSelected() const
{ return selected; }
//----------------------------------------------------------------------
inline bool FMenuItem::isSeparator() const
{ return separator; }
//----------------------------------------------------------------------
inline bool FMenuItem::isChecked() const
{ return checked; }
//----------------------------------------------------------------------
inline bool FMenuItem::hasHotkey() const
{ return bool(hotkey != 0); }
//----------------------------------------------------------------------
inline FMenu* FMenuItem::getMenu() const
{ return menu; }
//----------------------------------------------------------------------
inline void FMenuItem::setMenu(FMenu* m)
{ menu = m; }
//----------------------------------------------------------------------
inline bool FMenuItem::hasMenu() const
{ return bool(menu != 0); }
//----------------------------------------------------------------------
inline uInt FMenuItem::getTextLength() const
{ return text_length; }
inline FWidget* FMenuItem::getSuperMenu() const
{ return super_menu; }
//----------------------------------------------------------------------
inline FString FMenuItem::getText() const
{ return text; }
inline void FMenuItem::setSuperMenu (FWidget* smenu)
{ super_menu = smenu; }
#endif // _FMENUITEM_H

View File

@ -33,6 +33,50 @@ FMenuList::~FMenuList() // destructor
// public methods of FMenuList
//----------------------------------------------------------------------
void FMenuList::insert (FMenuItem* i)
{
item_list.push_back(i);
}
//----------------------------------------------------------------------
void FMenuList::remove (FMenuItem* i)
{
std::vector<FMenuItem*>::iterator iter;
if ( item_list.empty() )
return;
iter = item_list.begin();
while ( iter != item_list.end() )
{
if ( (*iter) == i )
{
iter = item_list.erase(iter);
i->setSuperMenu(0);
break;
}
else
++iter;
}
}
//----------------------------------------------------------------------
void FMenuList::remove (int pos)
{
if ( int(getCount()) < pos )
return;
item_list.erase (item_list.begin() + pos - 1);
}
//----------------------------------------------------------------------
void FMenuList::clear()
{
item_list.clear();
}
//----------------------------------------------------------------------
void FMenuList::selectFirstItem()
{
@ -68,47 +112,3 @@ void FMenuList::unselectItem()
setSelectedItem(0);
}
//----------------------------------------------------------------------
void FMenuList::insert (FMenuItem* i)
{
item_list.push_back(i);
}
//----------------------------------------------------------------------
void FMenuList::remove (FMenuItem* i)
{
std::vector<FMenuItem*>::iterator iter;
if ( item_list.empty() )
return;
iter = item_list.begin();
while ( iter != item_list.end() )
{
if ( (*iter) == i )
{
iter = item_list.erase(iter);
i->setSuperMenu(0);
break;
}
else
++iter;
}
}
//----------------------------------------------------------------------
void FMenuList::remove (int pos)
{
if ( int(count()) < pos )
return;
item_list.erase (item_list.begin() + pos - 1);
}
//----------------------------------------------------------------------
void FMenuList::clear()
{
item_list.clear();
}

View File

@ -32,6 +32,36 @@
class FMenuList
{
public:
// Constructor
explicit FMenuList();
// Destructor
virtual ~FMenuList();
// Accessors
virtual const char* getClassName() const;
uInt getCount() const;
FMenuItem* getItem (int) const;
FMenuItem* getSelectedItem() const;
// Mutators
void enableItem (int);
void disableItem (int);
void setSelectedItem (FMenuItem*);
// Inquiries
bool isSelected (int) const;
bool hasSelectedItem() const;
// Methods
virtual void insert (FMenuItem*);
virtual void remove (FMenuItem*);
void remove (int);
void clear();
void selectFirstItem();
void unselectItem();
protected:
FMenuItem* selected_item;
std::vector<FMenuItem*> item_list;
@ -39,30 +69,9 @@ class FMenuList
private:
// Disable copy constructor
FMenuList (const FMenuList&);
// Disable assignment operator (=)
FMenuList& operator = (const FMenuList&);
public:
// Constructor
explicit FMenuList();
// Destructor
virtual ~FMenuList();
virtual const char* getClassName() const;
uInt count() const;
FMenuItem* item (int) const;
void enableItem (int);
void disableItem (int);
bool isSelected (int) const;
void selectFirstItem();
void unselectItem();
FMenuItem* getSelectedItem() const;
void setSelectedItem (FMenuItem*);
bool hasSelectedItem() const;
virtual void insert (FMenuItem*);
virtual void remove (FMenuItem*);
void remove (int);
void clear();
};
#pragma pack(pop)
@ -73,13 +82,17 @@ inline const char* FMenuList::getClassName() const
{ return "FMenuList"; }
//----------------------------------------------------------------------
inline uInt FMenuList::count() const
inline uInt FMenuList::getCount() const
{ return uInt(item_list.size()); }
//----------------------------------------------------------------------
inline FMenuItem* FMenuList::item (int index) const
inline FMenuItem* FMenuList::getItem (int index) const
{ return (index > 0) ? item_list[uInt(index-1)] : 0; }
//----------------------------------------------------------------------
inline FMenuItem* FMenuList::getSelectedItem() const
{ return selected_item; }
//----------------------------------------------------------------------
inline void FMenuList::enableItem (int index)
{ item_list[uInt(index-1)]->setEnable(); }
@ -88,18 +101,14 @@ inline void FMenuList::enableItem (int index)
inline void FMenuList::disableItem (int index)
{ item_list[uInt(index-1)]->unsetEnable(); }
//----------------------------------------------------------------------
inline bool FMenuList::isSelected(int index) const
{ return (index > 0) ? item_list[uInt(index-1)]->isSelected() : false; }
//----------------------------------------------------------------------
inline FMenuItem* FMenuList::getSelectedItem() const
{ return selected_item; }
//----------------------------------------------------------------------
inline void FMenuList::setSelectedItem (FMenuItem* menuitem)
{ selected_item = menuitem; }
//----------------------------------------------------------------------
inline bool FMenuList::isSelected(int index) const
{ return (index > 0) ? item_list[uInt(index-1)]->isSelected() : false; }
//----------------------------------------------------------------------
inline bool FMenuList::hasSelectedItem() const
{ return selected_item; }

View File

@ -99,9 +99,198 @@ FMessageBox::~FMessageBox() // destructor
}
// public methods of FMessageBox
//----------------------------------------------------------------------
FMessageBox& FMessageBox::operator = (const FMessageBox& mbox)
{
if ( &mbox == this )
{
return *this;
}
else
{
for (uInt n=0; n < num_buttons; n++)
delete button[n];
delete button_digit[2];
delete button_digit[1];
delete button_digit[0];
if ( mbox.getParentWidget() )
mbox.getParentWidget()->addChild (this);
headline_text = mbox.headline_text;
text = mbox.text;
text_components = mbox.text_components;
text_split = mbox.text_split;
max_line_width = mbox.max_line_width;
center_text = mbox.center_text;
emphasis_color = mbox.emphasis_color;
num_buttons = mbox.num_buttons;
text_num_lines = mbox.text_num_lines;
setTitlebarText (mbox.getTitlebarText());
init ( *mbox.button_digit[0]
, *mbox.button_digit[1]
, *mbox.button_digit[2] );
return *this;
}
}
//----------------------------------------------------------------------
void FMessageBox::setHeadline (const FString& headline)
{
headline_text = headline;
setHeight(getHeight() + 2, true);
for (uInt n=0; n < num_buttons; n++)
button[n]->setY(getHeight()-4, false);
uInt len = headline_text.getLength();
if ( len > max_line_width )
max_line_width = len;
}
//----------------------------------------------------------------------
void FMessageBox::setHeadline (const std::string& headline)
{
FString headline_txt(headline);
setHeadline( headline_txt );
}
//----------------------------------------------------------------------
void FMessageBox::setHeadline (const char* headline)
{
FString headline_txt(headline);
setHeadline( headline_txt );
}
//----------------------------------------------------------------------
void FMessageBox::setText (const FString& txt)
{
text = txt;
calculateDimensions();
button[0]->setY(getHeight()-4, false);
if ( *button_digit[1] != 0 )
button[1]->setY(getHeight()-4, false);
if ( *button_digit[2] != 0 )
button[2]->setY(getHeight()-4, false);
adjustButtons();
}
//----------------------------------------------------------------------
void FMessageBox::setText (const std::string& txt)
{
FString message_text(txt);
setText( message_text );
}
//----------------------------------------------------------------------
void FMessageBox::setText (const char* txt)
{
FString message_text(txt);
setText( message_text );
}
//----------------------------------------------------------------------
int FMessageBox::info ( FWidget* parent
, const FString& caption
, const FString& message
, int button0
, int button1
, int button2 )
{
int reply;
FMessageBox* mbox = new FMessageBox ( caption, message
, button0, button1, button2
, parent );
reply = mbox->exec();
delete mbox;
return reply;
}
//----------------------------------------------------------------------
int FMessageBox::info ( FWidget* parent
, const FString& caption
, int num
, int button0
, int button1
, int button2 )
{
int reply;
FMessageBox* mbox = new FMessageBox ( caption
, FString().setNumber(num)
, button0, button1, button2
, parent );
reply = mbox->exec();
delete mbox;
return reply;
}
//----------------------------------------------------------------------
int FMessageBox::error ( FWidget* parent
, const FString& message
, int button0
, int button1
, int button2 )
{
int reply;
const FString caption = "Error message";
FMessageBox* mbox = new FMessageBox ( caption, message
, button0, button1, button2
, parent );
mbox->beep();
mbox->setHeadline("Warning:");
mbox->setCenterText();
mbox->setForegroundColor(mbox->wc.error_box_fg);
mbox->setBackgroundColor(mbox->wc.error_box_bg);
mbox->emphasis_color = mbox->wc.error_box_emphasis_fg;
reply = mbox->exec();
delete mbox;
return reply;
}
// protected methods of FMessageBox
//----------------------------------------------------------------------
void FMessageBox::adjustSize()
{
int X, Y, max_width, max_height;
FWidget* root_widget = getRootWidget();
if ( root_widget )
{
max_width = root_widget->getClientWidth();
max_height = root_widget->getClientHeight();
}
else
{
max_width = 80;
max_height = 24;
}
X = 1 + int((max_width-getWidth())/2);
Y = 1 + int((max_height-getHeight())/3);
setPos(X, Y, false);
FDialog::adjustSize();
}
//----------------------------------------------------------------------
void FMessageBox::cb_processClick (FWidget*, void* data_ptr)
{
int* reply = static_cast<int*>(data_ptr);
done (*reply);
}
// private methods of FMessageBox
//----------------------------------------------------------------------
void FMessageBox::init(int button0, int button1, int button2)
void FMessageBox::init (int button0, int button1, int button2)
{
calculateDimensions();
@ -336,192 +525,3 @@ void FMessageBox::adjustButtons()
}
}
}
//----------------------------------------------------------------------
void FMessageBox::cb_processClick (FWidget*, void* data_ptr)
{
int* reply = static_cast<int*>(data_ptr);
done (*reply);
}
// protected methods of FMessageBox
//----------------------------------------------------------------------
void FMessageBox::adjustSize()
{
int X, Y, max_width, max_height;
FWidget* root_widget = getRootWidget();
if ( root_widget )
{
max_width = root_widget->getClientWidth();
max_height = root_widget->getClientHeight();
}
else
{
max_width = 80;
max_height = 24;
}
X = 1 + int((max_width-getWidth())/2);
Y = 1 + int((max_height-getHeight())/3);
setPos(X, Y, false);
FDialog::adjustSize();
}
// public methods of FMessageBox
//----------------------------------------------------------------------
FMessageBox& FMessageBox::operator = (const FMessageBox& mbox)
{
if ( &mbox == this )
{
return *this;
}
else
{
for (uInt n=0; n < num_buttons; n++)
delete button[n];
delete button_digit[2];
delete button_digit[1];
delete button_digit[0];
if ( mbox.getParentWidget() )
mbox.getParentWidget()->addChild (this);
headline_text = mbox.headline_text;
text = mbox.text;
text_components = mbox.text_components;
text_split = mbox.text_split;
max_line_width = mbox.max_line_width;
center_text = mbox.center_text;
emphasis_color = mbox.emphasis_color;
num_buttons = mbox.num_buttons;
text_num_lines = mbox.text_num_lines;
setTitlebarText (mbox.getTitlebarText());
init ( *mbox.button_digit[0]
, *mbox.button_digit[1]
, *mbox.button_digit[2] );
return *this;
}
}
//----------------------------------------------------------------------
void FMessageBox::setHeadline (const FString& headline)
{
headline_text = headline;
setHeight(getHeight() + 2, true);
for (uInt n=0; n < num_buttons; n++)
button[n]->setY(getHeight()-4, false);
uInt len = headline_text.getLength();
if ( len > max_line_width )
max_line_width = len;
}
//----------------------------------------------------------------------
void FMessageBox::setHeadline (const std::string& headline)
{
FString headline_txt(headline);
setHeadline( headline_txt );
}
//----------------------------------------------------------------------
void FMessageBox::setHeadline (const char* headline)
{
FString headline_txt(headline);
setHeadline( headline_txt );
}
//----------------------------------------------------------------------
void FMessageBox::setText (const FString& txt)
{
text = txt;
calculateDimensions();
button[0]->setY(getHeight()-4, false);
if ( *button_digit[1] != 0 )
button[1]->setY(getHeight()-4, false);
if ( *button_digit[2] != 0 )
button[2]->setY(getHeight()-4, false);
adjustButtons();
}
//----------------------------------------------------------------------
void FMessageBox::setText (const std::string& txt)
{
FString message_text(txt);
setText( message_text );
}
//----------------------------------------------------------------------
void FMessageBox::setText (const char* txt)
{
FString message_text(txt);
setText( message_text );
}
//----------------------------------------------------------------------
int FMessageBox::info ( FWidget* parent
, const FString& caption
, const FString& message
, int button0
, int button1
, int button2 )
{
int reply;
FMessageBox* mbox = new FMessageBox ( caption, message
, button0, button1, button2
, parent );
reply = mbox->exec();
delete mbox;
return reply;
}
//----------------------------------------------------------------------
int FMessageBox::info ( FWidget* parent
, const FString& caption
, int num
, int button0
, int button1
, int button2 )
{
int reply;
FMessageBox* mbox = new FMessageBox ( caption
, FString().setNumber(num)
, button0, button1, button2
, parent );
reply = mbox->exec();
delete mbox;
return reply;
}
//----------------------------------------------------------------------
int FMessageBox::error ( FWidget* parent
, const FString& message
, int button0
, int button1
, int button2 )
{
int reply;
const FString caption = "Error message";
FMessageBox* mbox = new FMessageBox ( caption, message
, button0, button1, button2
, parent );
mbox->beep();
mbox->setHeadline("Warning:");
mbox->setCenterText();
mbox->setForegroundColor(mbox->wc.error_box_fg);
mbox->setBackgroundColor(mbox->wc.error_box_bg);
mbox->emphasis_color = mbox->wc.error_box_emphasis_fg;
reply = mbox->exec();
delete mbox;
return reply;
}

View File

@ -55,6 +55,7 @@
class FMessageBox : public FDialog
{
public:
// Enumeration
enum
{
Reject = 0,
@ -67,33 +68,6 @@ class FMessageBox : public FDialog
Ignore = 7
};
private:
FString headline_text;
FString text;
FString* text_components;
std::vector<FString> text_split;
uInt max_line_width;
bool center_text;
short emphasis_color;
uInt num_buttons;
uInt text_num_lines;
int* button_digit[3];
FButton* button[3];
protected:
void adjustSize();
private:
void init(int, int, int);
void calculateDimensions();
virtual void draw();
void resizeButtons();
void adjustButtons();
// Callback method
void cb_processClick (FWidget*, void*);
public:
// Constructors
explicit FMessageBox (FWidget* = 0);
FMessageBox (const FMessageBox&); // copy constructor
@ -106,24 +80,25 @@ class FMessageBox : public FDialog
// Assignment operator (=)
FMessageBox& operator = (const FMessageBox&);
// Accessor
const char* getClassName() const;
const FString getTitlebarText() const;
void setTitlebarText (const FString&);
const FString getHeadline() const;
const FString getText() const;
// Mutator
void setTitlebarText (const FString&);
void setHeadline (const FString&);
void setHeadline (const std::string&);
void setHeadline (const char*);
const FString getText() const;
bool setCenterText(bool);
bool setCenterText();
bool unsetCenterText();
void setText (const FString&);
void setText (const std::string&);
void setText (const char*);
bool setCenterText(bool);
bool setCenterText();
bool unsetCenterText();
// Methods
static int info ( FWidget*
, const FString&
, const FString&
@ -143,6 +118,36 @@ class FMessageBox : public FDialog
, int = FMessageBox::Ok
, int = 0
, int = 0 );
protected:
// Method
void adjustSize();
// Callback method
void cb_processClick (FWidget*, void*);
private:
// Typedef
typedef std::vector<FString> textLines;
// Methods
void init (int, int, int);
void calculateDimensions();
virtual void draw();
void resizeButtons();
void adjustButtons();
// Data Members
FString headline_text;
FString text;
FString* text_components;
textLines text_split;
uInt max_line_width;
bool center_text;
short emphasis_color;
uInt num_buttons;
uInt text_num_lines;
int* button_digit[3];
FButton* button[3];
};
#pragma pack(pop)
@ -156,10 +161,6 @@ inline const char* FMessageBox::getClassName() const
inline const FString FMessageBox::getTitlebarText() const
{ return FDialog::getText(); }
//----------------------------------------------------------------------
inline void FMessageBox::setTitlebarText (const FString& txt)
{ return FDialog::setText(txt); }
//----------------------------------------------------------------------
inline const FString FMessageBox::getHeadline() const
{ return headline_text; }
@ -168,6 +169,10 @@ inline const FString FMessageBox::getHeadline() const
inline const FString FMessageBox::getText() const
{ return text; }
//----------------------------------------------------------------------
inline void FMessageBox::setTitlebarText (const FString& txt)
{ return FDialog::setText(txt); }
//----------------------------------------------------------------------
inline bool FMessageBox::setCenterText(bool on)
{ return center_text = on; }

View File

@ -242,6 +242,7 @@ bool FObject::delAllTimer()
return true;
}
// protected methods of FObject
//----------------------------------------------------------------------
bool FObject::event (FEvent* ev)

View File

@ -48,8 +48,6 @@ typedef long double lDouble;
class FObject
{
public:
typedef std::list<FObject*> object_list;
struct timer_data
{
int id;
@ -58,38 +56,41 @@ class FObject
FObject* object;
};
// Typedef
typedef std::list<FObject*> object_list;
typedef std::vector<timer_data> TimerList;
static TimerList* timer_list;
private:
FObject* parent_obj;
object_list children_list;
bool has_parent;
static bool timer_modify_lock;
public:
// Constructor
explicit FObject (FObject* = 0);
// Destructor
virtual ~FObject();
// Accessors
virtual const char* getClassName() const;
FObject* getParent() const;
bool hasParent() const;
void removeParent();
object_list getChildren() const;
int numOfChildren() const;
// Inquiries
bool hasParent() const;
bool hasChildren() const;
bool isTimerInUpdating() const;
// Methods
void removeParent();
void addChild (FObject*);
void delChild (FObject*);
int numOfChildren() const;
// Timer methods
static void getCurrentTime (timeval&);
int addTimer (int);
bool delTimer (int);
bool delOwnTimer();
bool delAllTimer();
bool isTimerInUpdating() const;
// Data Members
static TimerList* timer_list;
protected:
// Event handler
@ -99,8 +100,15 @@ class FObject
private:
// Disable copy constructor
FObject (const FObject&);
// Disable assignment operator (=)
FObject& operator = (const FObject&);
// Data Members
FObject* parent_obj;
object_list children_list;
bool has_parent;
static bool timer_modify_lock;
};
#pragma pack(pop)
@ -113,30 +121,30 @@ inline const char* FObject::getClassName() const
inline FObject* FObject::getParent() const
{ return parent_obj; }
//----------------------------------------------------------------------
inline bool FObject::hasParent() const
{ return has_parent; }
//----------------------------------------------------------------------
inline void FObject::removeParent()
{ parent_obj = 0; }
//----------------------------------------------------------------------
inline FObject::object_list FObject::getChildren() const
{ return children_list; }
//----------------------------------------------------------------------
inline bool FObject::hasChildren() const
{ return bool( ! children_list.empty() ); }
//----------------------------------------------------------------------
inline int FObject::numOfChildren() const
{ return int(children_list.size()); }
//----------------------------------------------------------------------
inline bool FObject::hasParent() const
{ return has_parent; }
//----------------------------------------------------------------------
inline bool FObject::hasChildren() const
{ return bool( ! children_list.empty() ); }
//----------------------------------------------------------------------
inline bool FObject::isTimerInUpdating() const
{ return timer_modify_lock; }
//----------------------------------------------------------------------
inline void FObject::removeParent()
{ parent_obj = 0; }
//----------------------------------------------------------------------
// Operator functions for timeval

File diff suppressed because it is too large Load Diff

View File

@ -20,6 +20,8 @@
#define ESC "\033" // Escape
#define CSI ESC "[" // Control sequence introducer (7-bit)
typedef unsigned char uChar;
//----------------------------------------------------------------------
// class FOptiAttr
@ -30,79 +32,8 @@
class FOptiAttr
{
private:
typedef unsigned char uChar;
enum init_reset_tests
{
no_test = 0x00,
test_ansi_reset = 0x01, // ANSI X3.64 terminal
test_adm3_reset = 0x02, // Lear Siegler ADM-3 terminal
same_like_ue = 0x04,
same_like_se = 0x08,
same_like_me = 0x10,
all_tests = 0x1f
};
enum default_color
{
Default = -1,
Black = 0,
LightGray = 7
};
typedef struct
{
char* cap;
bool caused_reset;
} capability;
capability F_enter_bold_mode;
capability F_exit_bold_mode;
capability F_enter_dim_mode;
capability F_exit_dim_mode;
capability F_enter_italics_mode;
capability F_exit_italics_mode;
capability F_enter_underline_mode;
capability F_exit_underline_mode;
capability F_enter_blink_mode;
capability F_exit_blink_mode;
capability F_enter_reverse_mode;
capability F_exit_reverse_mode;
capability F_enter_standout_mode;
capability F_exit_standout_mode;
capability F_enter_secure_mode;
capability F_exit_secure_mode;
capability F_enter_protected_mode;
capability F_exit_protected_mode;
capability F_enter_crossed_out_mode;
capability F_exit_crossed_out_mode;
capability F_enter_dbl_underline_mode;
capability F_exit_dbl_underline_mode;
capability F_set_attributes;
capability F_exit_attribute_mode;
capability F_enter_alt_charset_mode;
capability F_exit_alt_charset_mode;
capability F_enter_pc_charset_mode;
capability F_exit_pc_charset_mode;
capability F_set_a_foreground;
capability F_set_a_background;
capability F_set_foreground;
capability F_set_background;
capability F_set_color_pair;
capability F_orig_pair;
capability F_orig_colors;
int max_color;
int attr_without_color;
bool ansi_default_color;
bool monochron;
bool fake_reverse;
bool cygwin_terminal;
char attr_buf[8192];
char* attr_ptr;
public:
// Typedef
typedef struct
{
int code; // character code
@ -126,73 +57,17 @@ class FOptiAttr
uChar inherit_bg : 1; // inherit background
} char_data;
private:
char_data on;
char_data off;
private:
// Disable copy constructor
FOptiAttr (const FOptiAttr&);
// Disable assignment operator (=)
FOptiAttr& operator = (const FOptiAttr&);
bool hasColor (char_data*&);
bool colorChange (char_data*&, char_data*&);
void resetColor (char_data*&);
void prevent_no_color_video_attributes (char_data*&);
void change_color (char_data*&, char_data*&);
bool hasAttribute (char_data*&);
bool hasNoAttribute (char_data*&);
void resetAttribute (char_data*&);
void reset (char_data*&);
bool caused_reset_attributes (char*&, uChar = all_tests);
void detectSwitchOn (char_data*&, char_data*&);
void detectSwitchOff (char_data*&, char_data*&);
bool switchOn();
bool switchOff();
bool append_sequence (char*&);
bool replace_sequence (char*&);
bool setTermBold (char_data*&);
bool unsetTermBold (char_data*&);
bool setTermDim (char_data*&);
bool unsetTermDim (char_data*&);
bool setTermItalic (char_data*&);
bool unsetTermItalic (char_data*&);
bool setTermUnderline (char_data*&);
bool unsetTermUnderline (char_data*&);
bool setTermBlink (char_data*&);
bool unsetTermBlink (char_data*&);
bool setTermReverse (char_data*&);
bool unsetTermReverse (char_data*&);
bool setTermStandout (char_data*&);
bool unsetTermStandout (char_data*&);
bool setTermInvisible (char_data*&);
bool unsetTermInvisible (char_data*&);
bool setTermProtected (char_data*&);
bool unsetTermProtected (char_data*&);
bool setTermCrossedOut (char_data*&);
bool unsetTermCrossedOut (char_data*&);
bool setTermDoubleUnderline (char_data*&);
bool unsetTermDoubleUnderline (char_data*&);
bool setTermAttributes ( char_data*&
, bool, bool, bool
, bool, bool, bool
, bool, bool, bool );
bool unsetTermAttributes (char_data*&);
bool setTermAltCharset (char_data*&);
bool unsetTermAltCharset (char_data*&);
bool setTermPCcharset (char_data*&);
bool unsetTermPCcharset (char_data*&);
bool setTermDefaultColor (char_data*&);
public:
// Constructor
explicit FOptiAttr();
// Destructor
~FOptiAttr();
static short vga2ansi (register short);
// Friend operator functions
friend bool operator == (const char_data&, const char_data&);
friend bool operator != (const char_data&, const char_data&);
// Mutators
void setMaxColor (int&);
void setNoColorVideo (int);
void setDefaultColorSupport();
@ -232,37 +107,153 @@ class FOptiAttr
void set_term_color_pair (char*&);
void set_orig_pair (char*&);
void set_orig_orig_colors (char*&);
void init();
// Methods
void init();
static short vga2ansi (register short);
char* changeAttribute (char_data*&, char_data*&);
friend bool operator == (const char_data&, const char_data&);
friend bool operator != (const char_data&, const char_data&);
private:
// Typedefs and Enumerations
typedef unsigned char uChar;
typedef struct
{
char* cap;
bool caused_reset;
} capability;
enum init_reset_tests
{
no_test = 0x00,
test_ansi_reset = 0x01, // ANSI X3.64 terminal
test_adm3_reset = 0x02, // Lear Siegler ADM-3 terminal
same_like_ue = 0x04,
same_like_se = 0x08,
same_like_me = 0x10,
all_tests = 0x1f
};
enum default_color
{
Default = -1,
Black = 0,
LightGray = 7
};
// Disable copy constructor
FOptiAttr (const FOptiAttr&);
// Disable assignment operator (=)
FOptiAttr& operator = (const FOptiAttr&);
// Mutators
bool setTermBold (char_data*&);
bool unsetTermBold (char_data*&);
bool setTermDim (char_data*&);
bool unsetTermDim (char_data*&);
bool setTermItalic (char_data*&);
bool unsetTermItalic (char_data*&);
bool setTermUnderline (char_data*&);
bool unsetTermUnderline (char_data*&);
bool setTermBlink (char_data*&);
bool unsetTermBlink (char_data*&);
bool setTermReverse (char_data*&);
bool unsetTermReverse (char_data*&);
bool setTermStandout (char_data*&);
bool unsetTermStandout (char_data*&);
bool setTermInvisible (char_data*&);
bool unsetTermInvisible (char_data*&);
bool setTermProtected (char_data*&);
bool unsetTermProtected (char_data*&);
bool setTermCrossedOut (char_data*&);
bool unsetTermCrossedOut (char_data*&);
bool setTermDoubleUnderline (char_data*&);
bool unsetTermDoubleUnderline (char_data*&);
bool setTermAttributes ( char_data*&
, bool, bool, bool
, bool, bool, bool
, bool, bool, bool );
bool unsetTermAttributes (char_data*&);
bool setTermAltCharset (char_data*&);
bool unsetTermAltCharset (char_data*&);
bool setTermPCcharset (char_data*&);
bool unsetTermPCcharset (char_data*&);
bool setTermDefaultColor (char_data*&);
// Inquiries
bool hasColor (char_data*&);
bool hasAttribute (char_data*&);
bool hasNoAttribute (char_data*&);
// Methods
bool colorChange (char_data*&, char_data*&);
void resetColor (char_data*&);
void prevent_no_color_video_attributes (char_data*&);
void change_color (char_data*&, char_data*&);
void resetAttribute (char_data*&);
void reset (char_data*&);
bool caused_reset_attributes (char*&, uChar = all_tests);
void detectSwitchOn (char_data*&, char_data*&);
void detectSwitchOff (char_data*&, char_data*&);
bool switchOn();
bool switchOff();
bool append_sequence (char*&);
bool replace_sequence (char*&);
// Data Members
capability F_enter_bold_mode;
capability F_exit_bold_mode;
capability F_enter_dim_mode;
capability F_exit_dim_mode;
capability F_enter_italics_mode;
capability F_exit_italics_mode;
capability F_enter_underline_mode;
capability F_exit_underline_mode;
capability F_enter_blink_mode;
capability F_exit_blink_mode;
capability F_enter_reverse_mode;
capability F_exit_reverse_mode;
capability F_enter_standout_mode;
capability F_exit_standout_mode;
capability F_enter_secure_mode;
capability F_exit_secure_mode;
capability F_enter_protected_mode;
capability F_exit_protected_mode;
capability F_enter_crossed_out_mode;
capability F_exit_crossed_out_mode;
capability F_enter_dbl_underline_mode;
capability F_exit_dbl_underline_mode;
capability F_set_attributes;
capability F_exit_attribute_mode;
capability F_enter_alt_charset_mode;
capability F_exit_alt_charset_mode;
capability F_enter_pc_charset_mode;
capability F_exit_pc_charset_mode;
capability F_set_a_foreground;
capability F_set_a_background;
capability F_set_foreground;
capability F_set_background;
capability F_set_color_pair;
capability F_orig_pair;
capability F_orig_colors;
char_data on;
char_data off;
int max_color;
int attr_without_color;
bool ansi_default_color;
bool monochron;
bool fake_reverse;
bool cygwin_terminal;
char attr_buf[8192];
char* attr_ptr;
};
#pragma pack(pop)
// FOptiAttr inline functions
//----------------------------------------------------------------------
inline void FOptiAttr::setMaxColor (int& c)
{ max_color = c; }
//----------------------------------------------------------------------
inline void FOptiAttr::setNoColorVideo (int attr)
{ attr_without_color = attr; }
//----------------------------------------------------------------------
inline void FOptiAttr::setDefaultColorSupport()
{ ansi_default_color = true; }
//----------------------------------------------------------------------
inline void FOptiAttr::setCygwinTerminal()
{ cygwin_terminal = true; }
//----------------------------------------------------------------------
inline bool FOptiAttr::hasNoAttribute (char_data*& attr)
{ return ! hasAttribute(attr); }
//----------------------------------------------------------------------
inline bool operator == ( const FOptiAttr::char_data& lhs,
const FOptiAttr::char_data& rhs )
@ -293,5 +284,24 @@ inline bool operator != ( const FOptiAttr::char_data& lhs,
const FOptiAttr::char_data& rhs )
{ return ! ( lhs == rhs ); }
//----------------------------------------------------------------------
inline void FOptiAttr::setMaxColor (int& c)
{ max_color = c; }
//----------------------------------------------------------------------
inline void FOptiAttr::setNoColorVideo (int attr)
{ attr_without_color = attr; }
//----------------------------------------------------------------------
inline void FOptiAttr::setDefaultColorSupport()
{ ansi_default_color = true; }
//----------------------------------------------------------------------
inline void FOptiAttr::setCygwinTerminal()
{ cygwin_terminal = true; }
//----------------------------------------------------------------------
inline bool FOptiAttr::hasNoAttribute (char_data*& attr)
{ return ! hasAttribute(attr); }
#endif // _FOPTIATTR_H

View File

@ -45,64 +45,32 @@ FOptiMove::~FOptiMove() // destructor
{ }
// private methods of FApplication
//----------------------------------------------------------------------
void FOptiMove::calculateCharDuration()
{
if ( baudrate != 0 )
{
const int baudbyte = 9; // = 7 bit + 1 parity + 1 stop
char_duration = (baudbyte * 1000 * 10)
/ (baudrate > 0 ? baudrate : 9600); // milliseconds
if ( char_duration <= 0 )
char_duration = 1;
}
else
char_duration = 1;
}
//----------------------------------------------------------------------
int FOptiMove::capDuration (char*& cap, int affcnt)
{
// calculate the duration in milliseconds of a given operation
// cap - the term capability
// affcnt - the number of lines affected
if ( ! cap )
return LONG_DURATION;
const char* p;
float ms = 0;
for (p=cap; *p; p++)
{
// check for delay with padding character
if ( p[0] == '$' && p[1] == '<' && std::strchr(p, '>') )
{
float num=0;
for (p += 2; *p != '>'; p++)
{
if ( std::isdigit(uChar(*p)) )
num = num * 10 + float(*p - '0');
else if ( *p == '*' )
num *= float(affcnt);
else if ( *p == '.' && *++p != '>' && std::isdigit(uChar(*p)) )
num += float((*p - '0') / 10.0);
}
ms += num * 10;
}
else
ms += float(char_duration);
}
return int(ms);
}
// public methods of FOptiMove
//----------------------------------------------------------------------
void FOptiMove::setBaudRate (int baud)
{
assert ( baud >= 0 );
baudrate = baud;
calculateCharDuration();
}
//----------------------------------------------------------------------
void FOptiMove::setTabStop (int t)
{
assert ( t > 0 );
tabstop = t;
}
//----------------------------------------------------------------------
void FOptiMove::setTermSize (int w, int h)
{
assert ( w > 0 );
assert ( h > 0 );
screen_width = w;
screen_height = h;
}
//----------------------------------------------------------------------
void FOptiMove::set_cursor_home (char*& cap)
{
@ -287,28 +255,236 @@ void FOptiMove::set_parm_right_cursor (char*& cap)
}
//----------------------------------------------------------------------
void FOptiMove::setBaudRate (int baud)
char* FOptiMove::moveCursor (int xold, int yold, int xnew, int ynew)
{
assert ( baud >= 0 );
char null_result[sizeof(move_buf)];
char* null_ptr = null_result;
char* move_ptr = move_buf;
char* move_xy;
int method = 0;
int new_time;
int move_time = LONG_DURATION;
baudrate = baud;
calculateCharDuration();
// Method 0: direct cursor addressing
move_xy = tgoto(F_cursor_address.cap, xnew, ynew);
if ( move_xy )
{
method = 0;
std::strncpy (move_ptr, move_xy, sizeof(move_buf) - 1);
move_time = F_cursor_address.duration;
if ( xold < 0
|| yold < 0
|| isTwoDirectionMove (xold, yold, xnew, ynew)
|| isWideMove (xold, yold, xnew, ynew) )
{
return ( move_time < LONG_DURATION ) ? move_buf : 0;
}
}
// Method 1: local movement
if ( xold >= 0 && yold >= 0 )
{
new_time = relativeMove (null_ptr, xold, yold, xnew, ynew);
if ( new_time < LONG_DURATION && new_time < move_time )
{
method = 1;
move_time = new_time;
}
}
// Method 2: carriage-return + local movement
if ( yold >= 0 && F_carriage_return.cap )
{
new_time = relativeMove (null_ptr, 0, yold, xnew, ynew);
if ( new_time < LONG_DURATION
&& F_carriage_return.duration + new_time < move_time )
{
method = 2;
move_time = F_carriage_return.duration + new_time;
}
}
// Method 3: home-cursor + local movement
if ( F_cursor_home.cap )
{
new_time = relativeMove (null_ptr, 0, 0, xnew, ynew);
if ( new_time < LONG_DURATION
&& F_cursor_home.duration + new_time < move_time )
{
method = 3;
move_time = F_cursor_home.duration + new_time;
}
}
// Method 4: home-down + local movement
if ( F_cursor_to_ll.cap )
{
new_time = relativeMove (null_ptr, 0, screen_height-1, xnew, ynew);
if ( new_time < LONG_DURATION
&& F_cursor_to_ll.duration + new_time < move_time )
{
method = 4;
move_time = F_cursor_to_ll.duration + new_time;
}
}
// Method 5: left margin for wrap to right-hand side
if ( automatic_left_margin
&& ! eat_nl_glitch
&& yold > 0
&& F_cursor_left.cap )
{
new_time = relativeMove (null_ptr, screen_width-1, yold-1, xnew, ynew);
if ( new_time < LONG_DURATION
&& F_carriage_return.cap
&& F_carriage_return.duration
+ F_cursor_left.duration + new_time < move_time )
{
method = 5;
move_time = F_carriage_return.duration
+ F_cursor_left.duration + new_time;
}
}
if ( method )
{
switch ( method )
{
case 1:
relativeMove (move_ptr, xold, yold, xnew, ynew);
break;
case 2:
if ( F_carriage_return.cap )
{
std::strncpy (move_ptr, F_carriage_return.cap, sizeof(move_buf) - 1);
move_ptr += F_carriage_return.length;
relativeMove (move_ptr, 0, yold, xnew, ynew);
}
break;
case 3:
std::strncpy (move_ptr, F_cursor_home.cap, sizeof(move_buf) - 1);
move_ptr += F_cursor_home.length;
relativeMove (move_ptr, 0, 0, xnew, ynew);
break;
case 4:
std::strncpy (move_ptr, F_cursor_to_ll.cap, sizeof(move_buf) - 1);
move_ptr += F_cursor_to_ll.length;
relativeMove (move_ptr, 0, screen_height-1, xnew, ynew);
break;
case 5:
move_buf[0] = '\0';
if ( xold >= 0 )
std::strncat ( move_ptr
, F_carriage_return.cap
, sizeof(move_buf) - std::strlen(move_ptr) - 1 );
std::strncat ( move_ptr
, F_cursor_left.cap
, sizeof(move_buf) - std::strlen(move_ptr) - 1 );
move_ptr += std::strlen(move_buf);
relativeMove (move_ptr, screen_width-1, yold-1, xnew, ynew);
break;
default:
break;
}
}
if ( move_time < LONG_DURATION )
return move_buf;
else
return 0;
}
//----------------------------------------------------------------------
void FOptiMove::setTabStop (int t)
void FOptiMove::printDurations()
{
assert ( t > 0 );
tabstop = t;
std::printf (" speed: %d baud\n", baudrate);
std::printf (" char_duration: %d ms\n", char_duration);
std::printf (" cursor_home: %d ms\n", F_cursor_home.duration);
std::printf (" cursor_to_ll: %d ms\n", F_cursor_to_ll.duration);
std::printf (" carriage_return: %d ms\n", F_carriage_return.duration);
std::printf (" tab: %d ms\n", F_tab.duration);
std::printf (" back_tab: %d ms\n", F_back_tab.duration);
std::printf (" cursor_up: %d ms\n", F_cursor_up.duration);
std::printf (" cursor_down: %d ms\n", F_cursor_down.duration);
std::printf (" cursor_left: %d ms\n", F_cursor_left.duration);
std::printf (" cursor_right: %d ms\n", F_cursor_right.duration);
std::printf (" cursor_address: %d ms\n", F_cursor_address.duration);
std::printf (" column_address: %d ms\n", F_column_address.duration);
std::printf (" row_address: %d ms\n", F_row_address.duration);
std::printf (" parm_up_cursor: %d ms\n", F_parm_up_cursor.duration);
std::printf (" parm_down_cursor: %d ms\n", F_parm_down_cursor.duration);
std::printf (" parm_left_cursor: %d ms\n", F_parm_left_cursor.duration);
std::printf ("parm_right_cursor: %d ms\n", F_parm_right_cursor.duration);
}
// private methods of FApplication
//----------------------------------------------------------------------
void FOptiMove::calculateCharDuration()
{
if ( baudrate != 0 )
{
const int baudbyte = 9; // = 7 bit + 1 parity + 1 stop
char_duration = (baudbyte * 1000 * 10)
/ (baudrate > 0 ? baudrate : 9600); // milliseconds
if ( char_duration <= 0 )
char_duration = 1;
}
else
char_duration = 1;
}
//----------------------------------------------------------------------
void FOptiMove::setTermSize (int w, int h)
int FOptiMove::capDuration (char*& cap, int affcnt)
{
assert ( w > 0 );
assert ( h > 0 );
screen_width = w;
screen_height = h;
// calculate the duration in milliseconds of a given operation
// cap - the term capability
// affcnt - the number of lines affected
if ( ! cap )
return LONG_DURATION;
const char* p;
float ms = 0;
for (p=cap; *p; p++)
{
// check for delay with padding character
if ( p[0] == '$' && p[1] == '<' && std::strchr(p, '>') )
{
float num=0;
for (p += 2; *p != '>'; p++)
{
if ( std::isdigit(uChar(*p)) )
num = num * 10 + float(*p - '0');
else if ( *p == '*' )
num *= float(affcnt);
else if ( *p == '.' && *++p != '>' && std::isdigit(uChar(*p)) )
num += float((*p - '0') / 10.0);
}
ms += num * 10;
}
else
ms += float(char_duration);
}
return int(ms);
}
//----------------------------------------------------------------------
@ -558,179 +734,3 @@ inline bool FOptiMove::isWideMove ( int xold, int yold
&& (xnew < screen_width - 1 - MOVE_LIMIT)
&& (std::abs(xnew-xold) + std::abs(ynew-yold) > MOVE_LIMIT) );
}
//----------------------------------------------------------------------
char* FOptiMove::moveCursor (int xold, int yold, int xnew, int ynew)
{
char null_result[sizeof(move_buf)];
char* null_ptr = null_result;
char* move_ptr = move_buf;
char* move_xy;
int method = 0;
int new_time;
int move_time = LONG_DURATION;
// Method 0: direct cursor addressing
move_xy = tgoto(F_cursor_address.cap, xnew, ynew);
if ( move_xy )
{
method = 0;
std::strncpy (move_ptr, move_xy, sizeof(move_buf) - 1);
move_time = F_cursor_address.duration;
if ( xold < 0
|| yold < 0
|| isTwoDirectionMove (xold, yold, xnew, ynew)
|| isWideMove (xold, yold, xnew, ynew) )
{
return ( move_time < LONG_DURATION ) ? move_buf : 0;
}
}
// Method 1: local movement
if ( xold >= 0 && yold >= 0 )
{
new_time = relativeMove (null_ptr, xold, yold, xnew, ynew);
if ( new_time < LONG_DURATION && new_time < move_time )
{
method = 1;
move_time = new_time;
}
}
// Method 2: carriage-return + local movement
if ( yold >= 0 && F_carriage_return.cap )
{
new_time = relativeMove (null_ptr, 0, yold, xnew, ynew);
if ( new_time < LONG_DURATION
&& F_carriage_return.duration + new_time < move_time )
{
method = 2;
move_time = F_carriage_return.duration + new_time;
}
}
// Method 3: home-cursor + local movement
if ( F_cursor_home.cap )
{
new_time = relativeMove (null_ptr, 0, 0, xnew, ynew);
if ( new_time < LONG_DURATION
&& F_cursor_home.duration + new_time < move_time )
{
method = 3;
move_time = F_cursor_home.duration + new_time;
}
}
// Method 4: home-down + local movement
if ( F_cursor_to_ll.cap )
{
new_time = relativeMove (null_ptr, 0, screen_height-1, xnew, ynew);
if ( new_time < LONG_DURATION
&& F_cursor_to_ll.duration + new_time < move_time )
{
method = 4;
move_time = F_cursor_to_ll.duration + new_time;
}
}
// Method 5: left margin for wrap to right-hand side
if ( automatic_left_margin
&& ! eat_nl_glitch
&& yold > 0
&& F_cursor_left.cap )
{
new_time = relativeMove (null_ptr, screen_width-1, yold-1, xnew, ynew);
if ( new_time < LONG_DURATION
&& F_carriage_return.cap
&& F_carriage_return.duration
+ F_cursor_left.duration + new_time < move_time )
{
method = 5;
move_time = F_carriage_return.duration
+ F_cursor_left.duration + new_time;
}
}
if ( method )
{
switch ( method )
{
case 1:
relativeMove (move_ptr, xold, yold, xnew, ynew);
break;
case 2:
if ( F_carriage_return.cap )
{
std::strncpy (move_ptr, F_carriage_return.cap, sizeof(move_buf) - 1);
move_ptr += F_carriage_return.length;
relativeMove (move_ptr, 0, yold, xnew, ynew);
}
break;
case 3:
std::strncpy (move_ptr, F_cursor_home.cap, sizeof(move_buf) - 1);
move_ptr += F_cursor_home.length;
relativeMove (move_ptr, 0, 0, xnew, ynew);
break;
case 4:
std::strncpy (move_ptr, F_cursor_to_ll.cap, sizeof(move_buf) - 1);
move_ptr += F_cursor_to_ll.length;
relativeMove (move_ptr, 0, screen_height-1, xnew, ynew);
break;
case 5:
move_buf[0] = '\0';
if ( xold >= 0 )
std::strncat ( move_ptr
, F_carriage_return.cap
, sizeof(move_buf) - std::strlen(move_ptr) - 1 );
std::strncat ( move_ptr
, F_cursor_left.cap
, sizeof(move_buf) - std::strlen(move_ptr) - 1 );
move_ptr += std::strlen(move_buf);
relativeMove (move_ptr, screen_width-1, yold-1, xnew, ynew);
break;
default:
break;
}
}
if ( move_time < LONG_DURATION )
return move_buf;
else
return 0;
}
//----------------------------------------------------------------------
void FOptiMove::printDurations()
{
std::printf (" speed: %d baud\n", baudrate);
std::printf (" char_duration: %d ms\n", char_duration);
std::printf (" cursor_home: %d ms\n", F_cursor_home.duration);
std::printf (" cursor_to_ll: %d ms\n", F_cursor_to_ll.duration);
std::printf (" carriage_return: %d ms\n", F_carriage_return.duration);
std::printf (" tab: %d ms\n", F_tab.duration);
std::printf (" back_tab: %d ms\n", F_back_tab.duration);
std::printf (" cursor_up: %d ms\n", F_cursor_up.duration);
std::printf (" cursor_down: %d ms\n", F_cursor_down.duration);
std::printf (" cursor_left: %d ms\n", F_cursor_left.duration);
std::printf (" cursor_right: %d ms\n", F_cursor_right.duration);
std::printf (" cursor_address: %d ms\n", F_cursor_address.duration);
std::printf (" column_address: %d ms\n", F_column_address.duration);
std::printf (" row_address: %d ms\n", F_row_address.duration);
std::printf (" parm_up_cursor: %d ms\n", F_parm_up_cursor.duration);
std::printf (" parm_down_cursor: %d ms\n", F_parm_down_cursor.duration);
std::printf (" parm_left_cursor: %d ms\n", F_parm_left_cursor.duration);
std::printf ("parm_right_cursor: %d ms\n", F_parm_right_cursor.duration);
}

View File

@ -23,12 +23,6 @@
#include <cstring>
// value for a long capability waiting time
#define LONG_DURATION 9999999
// maximum character distance to avoid direct cursor addressing
#define MOVE_LIMIT 7
//----------------------------------------------------------------------
// class FOptiMove
//----------------------------------------------------------------------
@ -38,7 +32,42 @@
class FOptiMove
{
public:
// Constructor
explicit FOptiMove (int = 0);
// Destructor
~FOptiMove();
// Mutators
void setBaudRate (int);
void setTabStop (int);
void setTermSize (int, int);
void set_cursor_home (char*&);
void set_cursor_to_ll (char*&);
void set_carriage_return (char*&);
void set_tabular (char*&);
void set_back_tab (char*&);
void set_cursor_up (char*&);
void set_cursor_down (char*&);
void set_cursor_left (char*&);
void set_cursor_right (char*&);
void set_cursor_address (char*&);
void set_column_address (char*&);
void set_row_address (char*&);
void set_parm_up_cursor (char*&);
void set_parm_down_cursor (char*&);
void set_parm_left_cursor (char*&);
void set_parm_right_cursor (char*&);
void set_auto_left_margin (bool&);
void set_eat_newline_glitch (bool&);
// Methods
char* moveCursor (int, int, int, int);
void printDurations();
private:
// Typedefs
typedef unsigned char uChar;
typedef unsigned int uInt;
@ -49,6 +78,21 @@ class FOptiMove
int length;
} capability;
// Constants
static const int LONG_DURATION = 9999999;
// value for a long capability waiting time
static const int MOVE_LIMIT = 7;
// maximum character distance to avoid direct cursor addressing
// Methods
void calculateCharDuration();
int capDuration (char*&, int);
int repeatedAppend (capability&, int, char*);
int relativeMove (char*&, int, int, int, int);
bool isTwoDirectionMove (int, int, int, int);
bool isWideMove (int, int, int, int);
// Data Members
capability F_cursor_home;
capability F_carriage_return;
capability F_cursor_to_ll;
@ -75,45 +119,6 @@ class FOptiMove
int tabstop;
int screen_width;
int screen_height;
private:
void calculateCharDuration();
int capDuration (char*&, int);
int repeatedAppend (capability&, int, char*);
int relativeMove (char*&, int, int, int, int);
bool isTwoDirectionMove (int, int, int, int);
bool isWideMove (int, int, int, int);
public:
// Constructor
explicit FOptiMove (int = 0);
// Destructor
~FOptiMove();
void setBaudRate (int);
void setTabStop (int);
void setTermSize (int, int);
void set_cursor_home (char*&);
void set_cursor_to_ll (char*&);
void set_carriage_return (char*&);
void set_tabular (char*&);
void set_back_tab (char*&);
void set_cursor_up (char*&);
void set_cursor_down (char*&);
void set_cursor_left (char*&);
void set_cursor_right (char*&);
void set_cursor_address (char*&);
void set_column_address (char*&);
void set_row_address (char*&);
void set_parm_up_cursor (char*&);
void set_parm_down_cursor (char*&);
void set_parm_left_cursor (char*&);
void set_parm_right_cursor (char*&);
void set_auto_left_margin (bool&);
void set_eat_newline_glitch (bool&);
char* moveCursor (int, int, int, int);
void printDurations();
};
#pragma pack(pop)

View File

@ -12,31 +12,6 @@ FPoint::~FPoint() // destructor
{ }
// public methods of FPoint
//----------------------------------------------------------------------
bool FPoint::isNull() const
{
return xpos == 0 && ypos == 0;
}
//----------------------------------------------------------------------
void FPoint::setX (int x)
{
xpos = short(x);
}
//----------------------------------------------------------------------
void FPoint::setY (int y)
{
ypos = short(y);
}
//----------------------------------------------------------------------
void FPoint::setPoint (int x, int y)
{
xpos = short(x);
ypos = short(y);
}
//----------------------------------------------------------------------
FPoint& FPoint::operator = (const FPoint& p)
{
@ -60,3 +35,28 @@ FPoint& FPoint::operator -= (const FPoint& p)
ypos = short(ypos - p.ypos);
return *this;
}
//----------------------------------------------------------------------
void FPoint::setX (int x)
{
xpos = short(x);
}
//----------------------------------------------------------------------
void FPoint::setY (int y)
{
ypos = short(y);
}
//----------------------------------------------------------------------
void FPoint::setPoint (int x, int y)
{
xpos = short(x);
ypos = short(y);
}
//----------------------------------------------------------------------
bool FPoint::isNull() const
{
return xpos == 0 && ypos == 0;
}

View File

@ -20,28 +20,15 @@
class FPoint
{
private:
short xpos;
short ypos;
public:
// Constructors
FPoint ();
FPoint (int, int);
// Destructor
virtual ~FPoint();
virtual const char* getClassName();
bool isNull() const;
int getX() const;
int getY() const;
short& x_ref();
short& y_ref();
void setX (int);
void setY (int);
void setPoint (int, int);
// Overloaded operators
FPoint& operator = (const FPoint&);
FPoint& operator += (const FPoint&);
FPoint& operator -= (const FPoint&);
@ -51,6 +38,26 @@ class FPoint
friend inline FPoint operator + (const FPoint&, const FPoint&);
friend inline FPoint operator - (const FPoint&, const FPoint&);
friend inline FPoint operator - (const FPoint&);
// Accessors
virtual const char* getClassName();
int getX() const;
int getY() const;
void setX (int);
void setY (int);
void setPoint (int, int);
// Inquiry
bool isNull() const;
// Point references
short& x_ref();
short& y_ref();
private:
// Data Members
short xpos;
short ypos;
};
#pragma pack(pop)
@ -68,26 +75,6 @@ inline FPoint::FPoint (int x, int y)
, ypos(short(y))
{ }
//----------------------------------------------------------------------
inline const char* FPoint::getClassName()
{ return "FPoint"; }
//----------------------------------------------------------------------
inline int FPoint::getX() const
{ return xpos; }
//----------------------------------------------------------------------
inline int FPoint::getY() const
{ return ypos; }
//----------------------------------------------------------------------
inline short& FPoint::x_ref()
{ return xpos; }
//----------------------------------------------------------------------
inline short& FPoint::y_ref()
{ return ypos; }
//----------------------------------------------------------------------
inline bool operator == (const FPoint& p1, const FPoint& p2)
{ return p1.xpos == p2.xpos && p1.ypos == p2.ypos; }
@ -108,4 +95,24 @@ inline FPoint operator - (const FPoint& p1, const FPoint& p2)
inline FPoint operator - (const FPoint& p)
{ return FPoint(-p.xpos, -p.ypos); }
//----------------------------------------------------------------------
inline const char* FPoint::getClassName()
{ return "FPoint"; }
//----------------------------------------------------------------------
inline int FPoint::getX() const
{ return xpos; }
//----------------------------------------------------------------------
inline int FPoint::getY() const
{ return ypos; }
//----------------------------------------------------------------------
inline short& FPoint::x_ref()
{ return xpos; }
//----------------------------------------------------------------------
inline short& FPoint::y_ref()
{ return ypos; }
#endif // _FPOINT_H

View File

@ -22,7 +22,141 @@ FProgressbar::FProgressbar(FWidget* parent)
FProgressbar::~FProgressbar()
{ }
// public methods of FProgressbar
//----------------------------------------------------------------------
void FProgressbar::setPercentage (int percentage_value)
{
if ( percentage_value <= percentage )
return;
if ( percentage_value > 100 )
percentage = 100;
else if ( percentage_value < 0 )
percentage = 0;
else
percentage = percentage_value;
updateVTerm(false);
if ( isVisible() )
{
drawPercentage();
drawBar();
}
updateVTerm(true);
updateTerminal();
}
//----------------------------------------------------------------------
void FProgressbar::setGeometry (int x, int y, int w, int h, bool adjust)
{
FWidget::setGeometry (x, y, w, h, adjust);
bar_length = w;
}
//----------------------------------------------------------------------
bool FProgressbar::setEnable (bool on)
{
FWidget::setEnable(on);
if ( on )
flags |= fc::active;
else
flags &= ~fc::active;
return on;
}
//----------------------------------------------------------------------
bool FProgressbar::setShadow (bool on)
{
if ( on
&& (Encoding != fc::VT100 || isTeraTerm() )
&& Encoding != fc::ASCII )
flags |= fc::shadow;
else
flags &= ~fc::shadow;
return on;
}
//----------------------------------------------------------------------
void FProgressbar::hide()
{
int s, size;
short fg, bg;
char* blank;
FWidget* parent_widget = getParentWidget();
FWidget::hide();
if ( parent_widget )
{
fg = parent_widget->getForegroundColor();
bg = parent_widget->getBackgroundColor();
}
else
{
fg = wc.dialog_fg;
bg = wc.dialog_bg;
}
setColor (fg, bg);
s = hasShadow() ? 1 : 0;
size = getWidth() + s;
if ( size < 0 )
return;
blank = new char[size+1];
std::memset(blank, ' ', uLong(size));
blank[size] = '\0';
for (int y=0; y < getHeight()+s; y++)
{
setPrintPos (1, 1 + y);
print (blank);
}
delete[] blank;
setPrintPos (getWidth() - 4, 0);
print (" "); // hide percentage
}
//----------------------------------------------------------------------
void FProgressbar::reset()
{
updateVTerm(false);
percentage = -1;
if ( isVisible() )
{
drawPercentage();
drawBar();
}
updateVTerm(true);
updateTerminal();
}
// private methods of FProgressbar
//----------------------------------------------------------------------
void FProgressbar::draw()
{
updateVTerm(false);
drawPercentage();
drawBar();
if ( (flags & fc::shadow) != 0 )
drawShadow ();
updateVTerm(true);
flush_out();
}
//----------------------------------------------------------------------
void FProgressbar::drawPercentage()
{
@ -153,138 +287,3 @@ void FProgressbar::drawBar()
updateTerminal();
flush_out();
}
// protected methods of FProgressbar
//----------------------------------------------------------------------
void FProgressbar::draw()
{
updateVTerm(false);
drawPercentage();
drawBar();
if ( (flags & fc::shadow) != 0 )
drawShadow ();
updateVTerm(true);
flush_out();
}
// public methods of FProgressbar
//----------------------------------------------------------------------
void FProgressbar::hide()
{
int s, size;
short fg, bg;
char* blank;
FWidget* parent_widget = getParentWidget();
FWidget::hide();
if ( parent_widget )
{
fg = parent_widget->getForegroundColor();
bg = parent_widget->getBackgroundColor();
}
else
{
fg = wc.dialog_fg;
bg = wc.dialog_bg;
}
setColor (fg, bg);
s = hasShadow() ? 1 : 0;
size = getWidth() + s;
if ( size < 0 )
return;
blank = new char[size+1];
std::memset(blank, ' ', uLong(size));
blank[size] = '\0';
for (int y=0; y < getHeight()+s; y++)
{
setPrintPos (1, 1 + y);
print (blank);
}
delete[] blank;
setPrintPos (getWidth() - 4, 0);
print (" "); // hide percentage
}
//----------------------------------------------------------------------
void FProgressbar::setPercentage (int percentage_value)
{
if ( percentage_value <= percentage )
return;
if ( percentage_value > 100 )
percentage = 100;
else if ( percentage_value < 0 )
percentage = 0;
else
percentage = percentage_value;
updateVTerm(false);
if ( isVisible() )
{
drawPercentage();
drawBar();
}
updateVTerm(true);
updateTerminal();
}
//----------------------------------------------------------------------
void FProgressbar::reset()
{
updateVTerm(false);
percentage = -1;
if ( isVisible() )
{
drawPercentage();
drawBar();
}
updateVTerm(true);
updateTerminal();
}
//----------------------------------------------------------------------
void FProgressbar::setGeometry (int x, int y, int w, int h, bool adjust)
{
FWidget::setGeometry (x, y, w, h, adjust);
bar_length = w;
}
//----------------------------------------------------------------------
bool FProgressbar::setEnable (bool on)
{
FWidget::setEnable(on);
if ( on )
flags |= fc::active;
else
flags &= ~fc::active;
return on;
}
//----------------------------------------------------------------------
bool FProgressbar::setShadow (bool on)
{
if ( on
&& (Encoding != fc::VT100 || isTeraTerm() )
&& Encoding != fc::ASCII )
flags |= fc::shadow;
else
flags &= ~fc::shadow;
return on;
}

View File

@ -40,31 +40,22 @@
class FProgressbar : public FWidget
{
private:
int percentage;
int bar_length;
private:
void drawPercentage();
void drawBar();
protected:
virtual void draw();
public:
// Using-declarations
using FWidget::setGeometry;
// Constructor
explicit FProgressbar(FWidget* = 0);
// Destructor
virtual ~FProgressbar();
// Accessors
const char* getClassName() const;
void hide();
int getPercentage();
// Mutators
void setPercentage (int);
void reset();
// make every setGeometry from FWidget available
using FWidget::setGeometry;
void setGeometry (int, int, int, int, bool = true);
bool setEnable (bool);
bool setEnable();
@ -73,7 +64,23 @@ class FProgressbar : public FWidget
bool setShadow (bool);
bool setShadow();
bool unsetShadow();
// Inquiries
bool hasShadow();
// Methods
void hide();
void reset();
private:
// Methods
virtual void draw();
void drawPercentage();
void drawBar();
// Data Members
int percentage;
int bar_length;
};
#pragma pack(pop)

View File

@ -45,24 +45,28 @@
class FRadioButton : public FToggleButton
{
private:
// Disable copy constructor
FRadioButton (const FRadioButton&);
// Disable assignment operator (=)
FRadioButton& operator = (const FRadioButton&);
void init();
void draw();
void drawRadioButton();
public:
// Constructors
explicit FRadioButton (FWidget* = 0);
FRadioButton (const FString&, FWidget* = 0);
// Destructor
virtual ~FRadioButton();
// Accessor
const char* getClassName() const;
private:
// Disable copy constructor
FRadioButton (const FRadioButton&);
// Disable assignment operator (=)
FRadioButton& operator = (const FRadioButton&);
// Methods
void init();
void draw();
void drawRadioButton();
};
#pragma pack(pop)

View File

@ -45,26 +45,30 @@
class FRadioMenuItem : public FMenuItem
{
private:
// Disable copy constructor
FRadioMenuItem (const FRadioMenuItem&);
// Disable assignment operator (=)
FRadioMenuItem& operator = (const FRadioMenuItem&);
void init (FWidget*);
void processToggle();
void processClicked();
public:
// Constructor
// Constructors
explicit FRadioMenuItem (FWidget* = 0);
FRadioMenuItem (FString&, FWidget* = 0);
FRadioMenuItem (const std::string&, FWidget* = 0);
FRadioMenuItem (const char*, FWidget* = 0);
// Destructor
virtual ~FRadioMenuItem();
// Accessor
const char* getClassName() const;
private:
// Disable copy constructor
FRadioMenuItem (const FRadioMenuItem&);
// Disable assignment operator (=)
FRadioMenuItem& operator = (const FRadioMenuItem&);
// Methods
void init (FWidget*);
void processToggle();
void processClicked();
};
#pragma pack(pop)

View File

@ -24,23 +24,25 @@
class FRect
{
private:
short X1;
short Y1;
short X2;
short Y2;
public:
// Constructors
FRect ();
FRect (int, int, int, int);
FRect (const FPoint&, const FPoint&);
// Destructor
virtual ~FRect();
virtual const char* getClassName();
// Overloaded operators
FRect& operator = (const FRect&);
bool isNull() const;
friend FRect operator + (const FRect&, const FPoint&);
friend FRect operator - (const FRect&, const FPoint&);
friend bool operator == (const FRect&, const FRect&);
friend bool operator != (const FRect&, const FRect&);
// Accessors
virtual const char* getClassName();
int getX1() const;
int getY1() const;
int getX2() const;
@ -55,10 +57,7 @@ class FRect
int getWidth() const;
int getHeight() const;
short& x1_ref();
short& y1_ref();
short& x2_ref();
short& y2_ref();
// Mutators
void setX1 (int);
void setY1 (int);
void setX2 (int);
@ -75,6 +74,16 @@ class FRect
void setCoordinates (const FPoint&, const FPoint&);
void setCoordinates (int, int, int, int);
// Inquiry
bool isNull() const;
// Coordinate references
short& x1_ref();
short& y1_ref();
short& x2_ref();
short& y2_ref();
// Methods
void move (int, int);
void move (const FPoint&);
bool contains (int, int) const;
@ -83,12 +92,12 @@ class FRect
bool overlap (const FRect&) const;
FRect intersect (const FRect&) const;
FRect& operator = (const FRect&);
friend FRect operator + (const FRect&, const FPoint&);
friend FRect operator - (const FRect&, const FPoint&);
friend bool operator == (const FRect&, const FRect&);
friend bool operator != (const FRect&, const FRect&);
private:
// Data Members
short X1;
short Y1;
short X2;
short Y2;
};
#pragma pack(pop)

View File

@ -67,147 +67,336 @@ FScrollbar::~FScrollbar()
delOwnTimer();
}
// private methods of FScrollbar
//----------------------------------------------------------------------
void FScrollbar::init()
{
unsetFocusable();
ignorePadding();
setGeometry(1, 1, getWidth(), getHeight());
}
//----------------------------------------------------------------------
void FScrollbar::draw()
{
updateVTerm(false);
drawButtons();
current_slider_pos = -1;
drawBar();
updateVTerm(true);
}
//----------------------------------------------------------------------
FScrollbar::sType FScrollbar::getClickedScrollType (int x, int y)
{
FScrollbar::sType stype;
if ( bar_orientation == fc::vertical )
{
if ( y == 1 )
{
stype = FScrollbar::scrollStepBackward; // decrement button
}
else if ( y >1 && y <= slider_pos+1 )
{
stype = FScrollbar::scrollPageBackward; // before slider
}
else if ( y > slider_pos+slider_length+1 && y < getHeight() )
{
stype = FScrollbar::scrollPageForward; // after slider
}
else if ( y == getHeight() )
{
stype = FScrollbar::scrollStepForward; // increment button
}
else
stype = FScrollbar::noScroll;
}
else // horizontal
{
if ( isNewFont() )
{
if ( x == 1 || x == 2 )
{
stype = FScrollbar::scrollStepBackward; // decrement button
}
else if ( x >2 && x <= slider_pos+2 )
{
stype = FScrollbar::scrollPageBackward; // before slider
}
else if ( x > slider_pos+slider_length+2 && x < getWidth()-1 )
{
stype = FScrollbar::scrollPageForward; // after slider
}
else if ( x == getWidth()-1 || x == getWidth() )
{
stype = FScrollbar::scrollStepForward; // increment button
}
else
stype = FScrollbar::noScroll;
}
else
{
if ( x == 1 )
{
stype = FScrollbar::scrollStepBackward; // decrement button
}
else if ( x >1 && x <= slider_pos+1 )
{
stype = FScrollbar::scrollPageBackward; // before slider
}
else if ( x > slider_pos+slider_length+1 && x < getWidth() )
{
stype = FScrollbar::scrollPageForward; // after slider
}
else if ( x == getWidth() )
{
stype = FScrollbar::scrollStepForward; // increment button
}
else
stype = FScrollbar::noScroll;
}
}
return stype;
}
//----------------------------------------------------------------------
void FScrollbar::processMiddleButton (int x, int y)
{
int new_val;
if ( bar_orientation == fc::vertical )
{
if ( y >1 && y < getHeight() )
{
new_val = int( round ( float(max - min) * (y - 2.0 - (slider_length/2))
/ float(bar_length - slider_length) ) );
}
else
return;
}
else // horizontal
{
int nf = isNewFont() ? 1 : 0;
if ( x > 1+nf && x < getWidth()-nf )
{
new_val = int( round ( float(max - min) * (x - 2.0 - nf - (slider_length/2))
/ float(bar_length - slider_length) ) );
}
else
return;
}
if ( new_val != val )
{
setValue(new_val);
drawBar();
updateTerminal();
scroll_type = FScrollbar::scrollJump;
processScroll();
}
}
//----------------------------------------------------------------------
void FScrollbar::processScroll()
{
emitCallback("change-value");
}
// public methods of FScrollbar
//----------------------------------------------------------------------
void FScrollbar::setMinimum (int minimum)
{
min = minimum;
calculateSliderValues();
}
//----------------------------------------------------------------------
void FScrollbar::setMaximum (int maximum)
{
max = maximum;
calculateSliderValues();
}
//----------------------------------------------------------------------
void FScrollbar::setRange(int minimum, int maximum)
{
min = minimum;
max = maximum;
calculateSliderValues();
}
//----------------------------------------------------------------------
void FScrollbar::setValue (int value)
{
val = value;
calculateSliderValues();
}
//----------------------------------------------------------------------
void FScrollbar::setSteps (float st)
{
if ( st <= 0 )
steps = 1;
else
steps = st;
if ( pageSize == 0 )
pageSize = int(float(max)/steps);
}
//----------------------------------------------------------------------
void FScrollbar::setPageSize (int document_size, int page_size)
{
if ( page_size == 0 )
{
pageSize = document_size;
steps = 1.0;
}
else
{
pageSize = page_size;
steps = float(float(document_size) / float(page_size));
}
}
//----------------------------------------------------------------------
void FScrollbar::setOrientation (int o)
{
int nf = 0;
length = (getHeight() > getWidth()) ? getHeight() : getWidth();
if ( o == fc::vertical && bar_orientation == fc::horizontal )
{
setWidth(1);
setHeight(length);
}
else if ( o == fc::horizontal && bar_orientation == fc::vertical )
{
setWidth(length);
setHeight(1);
if ( isNewFont() )
nf = 2;
}
slider_length = bar_length = length-nf-2;
bar_orientation = o;
}
//----------------------------------------------------------------------
void FScrollbar::setGeometry (int x, int y, int w, int h, bool adjust)
{
FWidget::setGeometry (x, y, w, h, adjust);
int nf = 0;
length = (h > w) ? h : w;
if ( bar_orientation == fc::vertical )
{
setWidth(isNewFont() ? 2 : 1);
setHeight(length);
}
else // horizontal
{
setWidth(length);
setHeight(1);
if ( isNewFont() )
nf = 2;
}
slider_length = bar_length = length-nf-2;
}
//----------------------------------------------------------------------
void FScrollbar::resize()
{
FWidget::resize();
setOrientation (bar_orientation);
setValue (val);
calculateSliderValues();
}
//----------------------------------------------------------------------
void FScrollbar::redraw()
{
draw();
}
//----------------------------------------------------------------------
void FScrollbar::calculateSliderValues()
{
if ( isNewFont() && bar_orientation == fc::horizontal )
bar_length = length - 4;
else
bar_length = length - 2;
slider_length = int(float(bar_length) / steps);
if ( slider_length < 1 )
slider_length = 1;
else if ( slider_length > bar_length )
slider_length = bar_length;
if ( val == min )
{
slider_pos = 0;
return;
}
if ( val == max )
{
slider_pos = bar_length - slider_length;
return;
}
slider_pos = int( round ( float((bar_length - slider_length) * val)
/ float(max - min) ) );
if ( slider_pos < 0 )
slider_pos = 0;
else if ( slider_pos > bar_length - slider_length )
slider_pos = bar_length - slider_length;
}
//----------------------------------------------------------------------
void FScrollbar::drawButtons()
{
setColor (wc.scrollbar_button_fg, wc.scrollbar_button_bg);
if ( isNewFont() )
{
setPrintPos (1,1);
if ( bar_orientation == fc::vertical )
{
print (fc::NF_rev_up_arrow1);
print (fc::NF_rev_up_arrow2);
setPrintPos (1, length);
print (fc::NF_rev_down_arrow1);
print (fc::NF_rev_down_arrow2);
}
else // horizontal
{
print (fc::NF_rev_left_arrow1);
print (fc::NF_rev_left_arrow2);
setPrintPos (length-1, 1);
print (fc::NF_rev_right_arrow1);
print (fc::NF_rev_right_arrow2);
}
}
else
{
setPrintPos (1,1);
if ( isMonochron() )
setReverse(true);
if ( bar_orientation == fc::vertical )
{
if ( isCygwinTerminal() )
print ('^');
else
print (fc::BlackUpPointingTriangle); // ▲
setPrintPos (1, length);
if ( isCygwinTerminal() )
print ('v');
else
print (fc::BlackDownPointingTriangle); // ▼
}
else // horizontal
{
print (fc::BlackLeftPointingPointer); // ◄
setPrintPos (length, 1);
print (fc::BlackRightPointingPointer); // ►
}
if ( isMonochron() )
setReverse(false);
}
}
//----------------------------------------------------------------------
void FScrollbar::drawBar()
{
if ( slider_pos != current_slider_pos )
{
int z;
updateVTerm(false);
if ( bar_orientation == fc::vertical )
{
setColor (wc.scrollbar_fg, wc.scrollbar_bg);
for (z=1; z <= slider_pos; z++)
{
setPrintPos (1, 1 + z);
if ( isNewFont() )
print (fc::NF_border_line_left); // ⎸
if ( isMonochron() || max_color < 16 )
print (fc::MediumShade); // ▒
else
print (' ');
}
setColor (wc.scrollbar_bg, wc.scrollbar_fg);
if ( isMonochron() )
setReverse(false);
for (z=1; z <= slider_length; z++)
{
setPrintPos (1, 1 + slider_pos + z);
if ( isNewFont() )
print (' ');
print (' ');
}
if ( isMonochron() )
setReverse(true);
setColor (wc.scrollbar_fg, wc.scrollbar_bg);
for (z=slider_pos+slider_length+1; z <= bar_length; z++)
{
setPrintPos (1, 1 + z);
if ( isNewFont() )
print (fc::NF_border_line_left); // ⎸
if ( isMonochron() || max_color < 16 )
print (fc::MediumShade);
else
print (' ');
}
}
else // horizontal
{
setColor (wc.scrollbar_fg, wc.scrollbar_bg);
z = 0;
if ( isNewFont() )
setPrintPos (3 + z, 1);
else
setPrintPos (2 + z, 1);
for (; z < slider_pos; z++)
{
if ( isNewFont() )
print (fc::NF_border_line_upper); // ¯
else if ( isMonochron() || max_color < 16 )
print (fc::MediumShade); // ▒
else
print (' ');
}
setColor (wc.scrollbar_bg, wc.scrollbar_fg);
if ( isMonochron() )
setReverse(false);
z = 0;
for (; z < slider_length; z++)
print (' ');
if ( isMonochron() )
setReverse(true);
setColor (wc.scrollbar_fg, wc.scrollbar_bg);
z = slider_pos + slider_length + 1;
for (; z <= bar_length; z++)
{
if ( isNewFont() )
print (fc::NF_border_line_upper); // ¯
else if ( isMonochron() || max_color < 16 )
print (fc::MediumShade); // ▒
else
print (' ');
}
}
current_slider_pos = slider_pos;
if ( isMonochron() )
setReverse(false);
updateVTerm(true);
}
}
//----------------------------------------------------------------------
void FScrollbar::onMouseDown (FMouseEvent* ev)
{
@ -402,330 +591,142 @@ void FScrollbar::onTimer (FTimerEvent*)
processScroll();
}
// private methods of FScrollbar
//----------------------------------------------------------------------
void FScrollbar::resize()
void FScrollbar::init()
{
FWidget::resize();
setOrientation (bar_orientation);
setValue (val);
calculateSliderValues();
unsetFocusable();
ignorePadding();
setGeometry(1, 1, getWidth(), getHeight());
}
//----------------------------------------------------------------------
void FScrollbar::redraw()
void FScrollbar::draw()
{
draw();
}
//----------------------------------------------------------------------
void FScrollbar::setMinimum (int minimum)
{
min = minimum;
calculateSliderValues();
}
//----------------------------------------------------------------------
void FScrollbar::setMaximum (int maximum)
{
max = maximum;
calculateSliderValues();
}
//----------------------------------------------------------------------
void FScrollbar::setRange(int minimum, int maximum)
{
min = minimum;
max = maximum;
calculateSliderValues();
}
//----------------------------------------------------------------------
void FScrollbar::setValue (int value)
{
val = value;
calculateSliderValues();
}
//----------------------------------------------------------------------
void FScrollbar::setSteps (float st)
{
if ( st <= 0 )
steps = 1;
else
steps = st;
if ( pageSize == 0 )
pageSize = int(float(max)/steps);
}
//----------------------------------------------------------------------
void FScrollbar::setPageSize (int document_size, int page_size)
{
if ( page_size == 0 )
{
pageSize = document_size;
steps = 1.0;
}
else
{
pageSize = page_size;
steps = float(float(document_size) / float(page_size));
}
}
//----------------------------------------------------------------------
void FScrollbar::calculateSliderValues()
{
if ( isNewFont() && bar_orientation == fc::horizontal )
bar_length = length - 4;
else
bar_length = length - 2;
slider_length = int(float(bar_length) / steps);
if ( slider_length < 1 )
slider_length = 1;
else if ( slider_length > bar_length )
slider_length = bar_length;
if ( val == min )
{
slider_pos = 0;
return;
}
if ( val == max )
{
slider_pos = bar_length - slider_length;
return;
}
slider_pos = int( round ( float((bar_length - slider_length) * val)
/ float(max - min) ) );
if ( slider_pos < 0 )
slider_pos = 0;
else if ( slider_pos > bar_length - slider_length )
slider_pos = bar_length - slider_length;
}
//----------------------------------------------------------------------
void FScrollbar::setOrientation (int o)
{
int nf = 0;
length = (getHeight() > getWidth()) ? getHeight() : getWidth();
if ( o == fc::vertical && bar_orientation == fc::horizontal )
{
setWidth(1);
setHeight(length);
}
else if ( o == fc::horizontal && bar_orientation == fc::vertical )
{
setWidth(length);
setHeight(1);
if ( isNewFont() )
nf = 2;
}
slider_length = bar_length = length-nf-2;
bar_orientation = o;
}
//----------------------------------------------------------------------
void FScrollbar::setGeometry (int x, int y, int w, int h, bool adjust)
{
FWidget::setGeometry (x, y, w, h, adjust);
int nf = 0;
length = (h > w) ? h : w;
if ( bar_orientation == fc::vertical )
{
setWidth(isNewFont() ? 2 : 1);
setHeight(length);
}
else // horizontal
{
setWidth(length);
setHeight(1);
if ( isNewFont() )
nf = 2;
}
slider_length = bar_length = length-nf-2;
}
//----------------------------------------------------------------------
void FScrollbar::drawBar()
{
if ( slider_pos != current_slider_pos )
{
int z;
updateVTerm(false);
if ( bar_orientation == fc::vertical )
{
setColor (wc.scrollbar_fg, wc.scrollbar_bg);
for (z=1; z <= slider_pos; z++)
{
setPrintPos (1, 1 + z);
if ( isNewFont() )
print (fc::NF_border_line_left); // ⎸
if ( isMonochron() || max_color < 16 )
print (fc::MediumShade); // ▒
else
print (' ');
}
setColor (wc.scrollbar_bg, wc.scrollbar_fg);
if ( isMonochron() )
setReverse(false);
for (z=1; z <= slider_length; z++)
{
setPrintPos (1, 1 + slider_pos + z);
if ( isNewFont() )
print (' ');
print (' ');
}
if ( isMonochron() )
setReverse(true);
setColor (wc.scrollbar_fg, wc.scrollbar_bg);
for (z=slider_pos+slider_length+1; z <= bar_length; z++)
{
setPrintPos (1, 1 + z);
if ( isNewFont() )
print (fc::NF_border_line_left); // ⎸
if ( isMonochron() || max_color < 16 )
print (fc::MediumShade);
else
print (' ');
}
}
else // horizontal
{
setColor (wc.scrollbar_fg, wc.scrollbar_bg);
z = 0;
if ( isNewFont() )
setPrintPos (3 + z, 1);
else
setPrintPos (2 + z, 1);
for (; z < slider_pos; z++)
{
if ( isNewFont() )
print (fc::NF_border_line_upper); // ¯
else if ( isMonochron() || max_color < 16 )
print (fc::MediumShade); // ▒
else
print (' ');
}
setColor (wc.scrollbar_bg, wc.scrollbar_fg);
if ( isMonochron() )
setReverse(false);
z = 0;
for (; z < slider_length; z++)
print (' ');
if ( isMonochron() )
setReverse(true);
setColor (wc.scrollbar_fg, wc.scrollbar_bg);
z = slider_pos + slider_length + 1;
for (; z <= bar_length; z++)
{
if ( isNewFont() )
print (fc::NF_border_line_upper); // ¯
else if ( isMonochron() || max_color < 16 )
print (fc::MediumShade); // ▒
else
print (' ');
}
}
current_slider_pos = slider_pos;
if ( isMonochron() )
setReverse(false);
drawButtons();
current_slider_pos = -1;
drawBar();
updateVTerm(true);
}
}
//----------------------------------------------------------------------
void FScrollbar::drawButtons()
FScrollbar::sType FScrollbar::getClickedScrollType (int x, int y)
{
setColor (wc.scrollbar_button_fg, wc.scrollbar_button_bg);
FScrollbar::sType stype;
if ( bar_orientation == fc::vertical )
{
if ( y == 1 )
{
stype = FScrollbar::scrollStepBackward; // decrement button
}
else if ( y >1 && y <= slider_pos+1 )
{
stype = FScrollbar::scrollPageBackward; // before slider
}
else if ( y > slider_pos+slider_length+1 && y < getHeight() )
{
stype = FScrollbar::scrollPageForward; // after slider
}
else if ( y == getHeight() )
{
stype = FScrollbar::scrollStepForward; // increment button
}
else
stype = FScrollbar::noScroll;
}
else // horizontal
{
if ( isNewFont() )
{
setPrintPos (1,1);
if ( x == 1 || x == 2 )
{
stype = FScrollbar::scrollStepBackward; // decrement button
}
else if ( x >2 && x <= slider_pos+2 )
{
stype = FScrollbar::scrollPageBackward; // before slider
}
else if ( x > slider_pos+slider_length+2 && x < getWidth()-1 )
{
stype = FScrollbar::scrollPageForward; // after slider
}
else if ( x == getWidth()-1 || x == getWidth() )
{
stype = FScrollbar::scrollStepForward; // increment button
}
else
stype = FScrollbar::noScroll;
}
else
{
if ( x == 1 )
{
stype = FScrollbar::scrollStepBackward; // decrement button
}
else if ( x >1 && x <= slider_pos+1 )
{
stype = FScrollbar::scrollPageBackward; // before slider
}
else if ( x > slider_pos+slider_length+1 && x < getWidth() )
{
stype = FScrollbar::scrollPageForward; // after slider
}
else if ( x == getWidth() )
{
stype = FScrollbar::scrollStepForward; // increment button
}
else
stype = FScrollbar::noScroll;
}
}
return stype;
}
//----------------------------------------------------------------------
void FScrollbar::processMiddleButton (int x, int y)
{
int new_val;
if ( bar_orientation == fc::vertical )
{
print (fc::NF_rev_up_arrow1);
print (fc::NF_rev_up_arrow2);
setPrintPos (1, length);
print (fc::NF_rev_down_arrow1);
print (fc::NF_rev_down_arrow2);
if ( y >1 && y < getHeight() )
{
new_val = int( round ( float(max - min) * (y - 2.0 - (slider_length/2))
/ float(bar_length - slider_length) ) );
}
else
return;
}
else // horizontal
{
print (fc::NF_rev_left_arrow1);
print (fc::NF_rev_left_arrow2);
setPrintPos (length-1, 1);
print (fc::NF_rev_right_arrow1);
print (fc::NF_rev_right_arrow2);
}
int nf = isNewFont() ? 1 : 0;
if ( x > 1+nf && x < getWidth()-nf )
{
new_val = int( round ( float(max - min) * (x - 2.0 - nf - (slider_length/2))
/ float(bar_length - slider_length) ) );
}
else
{
setPrintPos (1,1);
if ( isMonochron() )
setReverse(true);
if ( bar_orientation == fc::vertical )
{
if ( isCygwinTerminal() )
print ('^');
else
print (fc::BlackUpPointingTriangle); // ▲
setPrintPos (1, length);
if ( isCygwinTerminal() )
print ('v');
else
print (fc::BlackDownPointingTriangle); // ▼
}
else // horizontal
{
print (fc::BlackLeftPointingPointer); // ◄
setPrintPos (length, 1);
print (fc::BlackRightPointingPointer); // ►
return;
}
if ( isMonochron() )
setReverse(false);
if ( new_val != val )
{
setValue(new_val);
drawBar();
updateTerminal();
scroll_type = FScrollbar::scrollJump;
processScroll();
}
}
//----------------------------------------------------------------------
void FScrollbar::processScroll()
{
emitCallback("change-value");
}

View File

@ -41,6 +41,10 @@
class FScrollbar : public FWidget
{
public:
// Using-declarations
using FWidget::setGeometry;
// Enumeration
enum sType
{
noScroll = 0,
@ -53,7 +57,57 @@ class FScrollbar : public FWidget
scrollWheelDown = 7
};
// Constructors
explicit FScrollbar(FWidget* = 0);
FScrollbar (int = fc::vertical, FWidget* = 0);
// Destructor
virtual ~FScrollbar();
// Accessors
const char* getClassName() const;
int getValue() const;
sType getScrollType() const;
// Mutators
void setMinimum (int);
void setMaximum (int);
void setRange (int, int);
void setValue (int);
void setSteps (float);
void setPageSize (int, int);
void setOrientation (int);
void setGeometry (int, int, int, int, bool = true);
// Methods
void resize();
void redraw();
void calculateSliderValues();
void drawButtons();
void drawBar();
// Event handlers
void onMouseDown (FMouseEvent*);
void onMouseUp (FMouseEvent*);
void onMouseMove (FMouseEvent*);
void onWheel (FWheelEvent*);
void onTimer (FTimerEvent*);
private:
// Disable copy constructor
FScrollbar (const FScrollbar&);
// Disable assignment operator (=)
FScrollbar& operator = (const FScrollbar&);
// Methods
void init();
void draw();
sType getClickedScrollType (int, int);
void processMiddleButton (int, int);
void processScroll();
// Data Members
sType scroll_type;
bool threshold_reached;
int threshold_time;
@ -72,52 +126,6 @@ class FScrollbar : public FWidget
int length;
int bar_orientation;
int max_color;
private:
// Disable copy constructor
FScrollbar (const FScrollbar&);
// Disable assignment operator (=)
FScrollbar& operator = (const FScrollbar&);
void init();
void draw();
sType getClickedScrollType (int, int);
void processMiddleButton (int, int);
void processScroll();
public:
// Constructors
explicit FScrollbar(FWidget* = 0);
FScrollbar (int = fc::vertical, FWidget* = 0);
// Destructor
virtual ~FScrollbar();
const char* getClassName() const;
// Event handlers
void onMouseDown (FMouseEvent*);
void onMouseUp (FMouseEvent*);
void onMouseMove (FMouseEvent*);
void onWheel (FWheelEvent*);
void onTimer (FTimerEvent*);
void resize();
void redraw();
void setMinimum (int);
void setMaximum (int);
void setRange (int, int);
void setValue (int);
int getValue() const;
void setSteps (float);
void setPageSize (int, int);
void calculateSliderValues();
void setOrientation (int);
// make every setGeometry from FWidget available
using FWidget::setGeometry;
void setGeometry (int, int, int, int, bool = true);
void drawButtons();
void drawBar();
sType getScrollType() const;
};
#pragma pack(pop)

View File

@ -60,35 +60,14 @@ FStatusKey::FStatusKey (int k, const char* txt, FWidget* parent)
//----------------------------------------------------------------------
FStatusKey::~FStatusKey() // destructor
{
if ( statusbar() )
statusbar()->remove(this);
if ( getConnectedStatusbar() )
getConnectedStatusbar()->remove(this);
delAccelerator();
}
// private methods of FStatusKey
//----------------------------------------------------------------------
void FStatusKey::init (FWidget* parent)
{
setGeometry (1,1,1,1);
if ( parent && std::strcmp ( parent->getClassName()
, const_cast<char*>("FStatusBar") ) == 0 )
{
setStatusbar( static_cast<FStatusBar*>(parent) );
if ( statusbar() )
statusbar()->insert(this);
}
}
//----------------------------------------------------------------------
void FStatusKey::processActivate()
{
emitCallback("activate");
}
// public methods of FStatusKey
//----------------------------------------------------------------------
void FStatusKey::onAccel (FAccelEvent* ev)
{
@ -97,30 +76,17 @@ void FStatusKey::onAccel (FAccelEvent* ev)
setActive();
if ( statusbar() )
statusbar()->redraw();
if ( getConnectedStatusbar() )
getConnectedStatusbar()->redraw();
ev->accept();
// unset after get back from callback
unsetActive();
if ( statusbar() )
statusbar()->redraw();
if ( getConnectedStatusbar() )
getConnectedStatusbar()->redraw();
}
//----------------------------------------------------------------------
FStatusBar* FStatusKey::statusbar() const
{
return bar;
}
//----------------------------------------------------------------------
void FStatusKey::setStatusbar (FStatusBar* sb)
{
bar = sb;
}
// public methods of FStatusKey
//----------------------------------------------------------------------
void FStatusKey::setActive()
{
@ -138,6 +104,29 @@ bool FStatusKey::setMouseFocus(bool on)
}
// private methods of FStatusKey
//----------------------------------------------------------------------
void FStatusKey::init (FWidget* parent)
{
setGeometry (1,1,1,1);
if ( parent && std::strcmp ( parent->getClassName()
, const_cast<char*>("FStatusBar") ) == 0 )
{
setConnectedStatusbar (static_cast<FStatusBar*>(parent));
if ( getConnectedStatusbar() )
getConnectedStatusbar()->insert(this);
}
}
//----------------------------------------------------------------------
void FStatusKey::processActivate()
{
emitCallback("activate");
}
//----------------------------------------------------------------------
// class FStatusBar
//----------------------------------------------------------------------
@ -146,7 +135,7 @@ bool FStatusKey::setMouseFocus(bool on)
//----------------------------------------------------------------------
FStatusBar::FStatusBar(FWidget* parent)
: FWindow(parent)
, keylist()
, key_list()
, text("")
, mouse_down()
, x(-1)
@ -159,16 +148,16 @@ FStatusBar::FStatusBar(FWidget* parent)
FStatusBar::~FStatusBar()
{
// delete all keys
if ( ! keylist.empty() )
if ( ! key_list.empty() )
{
std::vector<FStatusKey*>::iterator iter;
iter = keylist.begin();
iter = key_list.begin();
while ( iter != keylist.end() )
while ( iter != key_list.end() )
{
(*iter)->setStatusbar(0);
(*iter)->setConnectedStatusbar(0);
delAccelerator (*iter);
iter = keylist.erase(iter);
iter = key_list.erase(iter);
}
}
@ -176,6 +165,401 @@ FStatusBar::~FStatusBar()
}
// public methods of FStatusBar
//----------------------------------------------------------------------
void FStatusBar::setMessage (FString& mgs)
{
text = mgs;
}
//----------------------------------------------------------------------
void FStatusBar::setMessage (const std::string& mgs)
{
FString s = FString(mgs);
setMessage (s);
}
//----------------------------------------------------------------------
void FStatusBar::setMessage (const char* mgs)
{
FString s = FString(mgs);
setMessage (s);
}
//----------------------------------------------------------------------
bool FStatusBar::hasActivatedKey()
{
if ( ! key_list.empty() )
{
std::vector<FStatusKey*>::const_iterator iter, end;
iter = key_list.begin();
end = key_list.end();
while ( iter != end )
{
if ( (*iter)->isActivated() )
return true;
++iter;
}
}
return false;
}
//----------------------------------------------------------------------
void FStatusBar::hide()
{
int screenWidth;
short fg, bg;
char* blank;
FWindow::hide();
fg = wc.term_fg;
bg = wc.term_bg;
setColor (fg, bg);
screenWidth = getColumnNumber();
if ( screenWidth < 0 )
return;
blank = new char[screenWidth+1];
std::memset(blank, ' ', uLong(screenWidth));
blank[screenWidth] = '\0';
setPrintPos (1, 1);
print (blank);
delete[] blank;
}
//----------------------------------------------------------------------
void FStatusBar::drawMessage()
{
int termWidth, space_offset;
bool isLastActiveFocus, hasKeys;
if ( ! (isVisible() ) )
return;
if ( x < 0 || x_msg < 0 )
return;
x = x_msg;
termWidth = getColumnNumber();
space_offset = 1;
hasKeys = bool(! key_list.empty());
if ( hasKeys )
{
std::vector<FStatusKey*>::const_iterator iter = key_list.end();
isLastActiveFocus = bool( (*(iter-1))->isActivated()
|| (*(iter-1))->hasMouseFocus() );
}
else
isLastActiveFocus = false;
if ( isLastActiveFocus )
space_offset = 0;
updateVTerm(false);
setColor (wc.statusbar_fg, wc.statusbar_bg);
setPrintPos (x, 1);
if ( isMonochron() )
setReverse(true);
if ( x+space_offset+3 < termWidth )
{
if ( text )
{
if ( ! isLastActiveFocus )
{
x++;
print (' ');
}
if ( hasKeys )
{
x += 2;
print (fc::BoxDrawingsVertical); // │
print (' ');
}
int msg_length = int(getMessage().getLength());
x += msg_length;
if ( x-1 <= termWidth )
print (getMessage());
else
{
print ( getMessage().left(uInt(msg_length+termWidth-x-1)) );
print ("..");
}
}
}
for (int i=x; i <= termWidth; i++)
print (' ');
if ( isMonochron() )
setReverse(false);
updateVTerm(true);
}
//----------------------------------------------------------------------
void FStatusBar::insert (FStatusKey* skey)
{
key_list.push_back (skey);
addAccelerator (skey->getKey(), skey);
skey->addCallback
(
"activate",
_METHOD_CALLBACK (this, &FStatusBar::cb_statuskey_activated)
);
}
//----------------------------------------------------------------------
void FStatusBar::remove (FStatusKey* skey)
{
std::vector<FStatusKey*>::iterator iter;
delAccelerator (skey);
if ( key_list.empty() )
return;
iter = key_list.begin();
while ( iter != key_list.end() )
{
if ( (*iter) == skey )
{
iter = key_list.erase(iter);
skey->setConnectedStatusbar(0);
break;
}
else
++iter;
}
}
//----------------------------------------------------------------------
void FStatusBar::remove (int pos)
{
if ( int(getCount()) < pos )
return;
key_list.erase (key_list.begin()+pos-1);
}
//----------------------------------------------------------------------
void FStatusBar::clear()
{
key_list.clear();
}
//----------------------------------------------------------------------
void FStatusBar::adjustSize()
{
setGeometry (1, getLineNumber(), getColumnNumber(), 1, false);
}
//----------------------------------------------------------------------
void FStatusBar::onMouseDown (FMouseEvent* ev)
{
if ( hasActivatedKey() )
return;
if ( ev->getButton() != fc::LeftButton )
{
mouse_down = false;
if ( ! key_list.empty() )
{
std::vector<FStatusKey*>::const_iterator iter, end;
iter = key_list.begin();
end = key_list.end();
while ( iter != end )
{
(*iter)->unsetMouseFocus();
++iter;
}
}
redraw();
return;
}
if ( mouse_down )
return;
mouse_down = true;
if ( ! key_list.empty() )
{
std::vector<FStatusKey*>::const_iterator iter, end;
int X = 1;
iter = key_list.begin();
end = key_list.end();
while ( iter != end )
{
int x1, x2, mouse_x, mouse_y, kname_len, txt_length;
x1 = X;
kname_len = int(getKeyName((*iter)->getKey()).getLength());
txt_length = int((*iter)->getText().getLength());
x2 = x1 + kname_len + txt_length + 1;
mouse_x = ev->getX();
mouse_y = ev->getY();
if ( mouse_x >= x1
&& mouse_x <= x2
&& mouse_y == 1
&& ! (*iter)->hasMouseFocus() )
{
(*iter)->setMouseFocus();
redraw();
}
X = x2 + 2;
++iter;
}
}
}
//----------------------------------------------------------------------
void FStatusBar::onMouseUp (FMouseEvent* ev)
{
if ( hasActivatedKey() )
return;
if ( ev->getButton() != fc::LeftButton )
return;
if ( mouse_down )
{
mouse_down = false;
if ( ! key_list.empty() )
{
std::vector<FStatusKey*>::const_iterator iter, end;
int X = 1;
iter = key_list.begin();
end = key_list.end();
while ( iter != end )
{
int x1, x2, kname_len, txt_length;
x1 = X;
kname_len = int(getKeyName((*iter)->getKey()).getLength());
txt_length = int((*iter)->getText().getLength());
x2 = x1 + kname_len + txt_length + 1;
if ( (*iter)->hasMouseFocus() )
{
int mouse_x, mouse_y;
(*iter)->unsetMouseFocus();
mouse_x = ev->getX();
mouse_y = ev->getY();
if ( mouse_x >= x1 && mouse_x <= x2 && mouse_y == 1 )
(*iter)->setActive();
// unset after get back from callback
(*iter)->unsetActive();
redraw();
}
X = x2 + 2;
++iter;
}
}
}
}
//----------------------------------------------------------------------
void FStatusBar::onMouseMove (FMouseEvent* ev)
{
if ( hasActivatedKey() )
return;
if ( ev->getButton() != fc::LeftButton )
return;
if ( mouse_down && ! key_list.empty() )
{
std::vector<FStatusKey*>::const_iterator iter, end;
bool focus_changed = false;
int X=1;
iter = key_list.begin();
end = key_list.end();
while ( iter != end )
{
int x1, x2, mouse_x, mouse_y, kname_len, txt_length;
x1 = X;
kname_len = int(getKeyName((*iter)->getKey()).getLength());
txt_length = int((*iter)->getText().getLength());
x2 = x1 + kname_len + txt_length + 1;
mouse_x = ev->getX();
mouse_y = ev->getY();
if ( mouse_x >= x1
&& mouse_x <= x2
&& mouse_y == 1 )
{
if ( ! (*iter)->hasMouseFocus() )
{
(*iter)->setMouseFocus();
focus_changed = true;
}
}
else
{
if ( (*iter)->hasMouseFocus() )
{
(*iter)->unsetMouseFocus();
focus_changed = true;
}
}
X = x2 + 2;
++iter;
}
if ( focus_changed )
redraw();
}
}
//----------------------------------------------------------------------
void FStatusBar::cb_statuskey_activated (FWidget* widget, void*)
{
if ( ! key_list.empty() )
{
std::vector<FStatusKey*>::const_iterator iter, end;
FStatusKey* statuskey = static_cast<FStatusKey*>(widget);
iter = key_list.begin();
end = key_list.end();
while ( iter != end )
{
if ( (*iter) != statuskey && (*iter)->isActivated() )
(*iter)->unsetActive();
++iter;
}
}
if ( isVisible() && isShown() )
redraw();
}
// private methods of FStatusBar
//----------------------------------------------------------------------
void FStatusBar::init()
@ -214,7 +598,7 @@ void FStatusBar::drawKeys()
screenWidth = getColumnNumber();
x = 1;
if ( keylist.empty() )
if ( key_list.empty() )
{
x_msg = 1;
return;
@ -226,8 +610,8 @@ void FStatusBar::drawKeys()
if ( isMonochron() )
setReverse(true);
iter = keylist.begin();
end = keylist.end();
iter = key_list.begin();
end = key_list.end();
while ( iter != end )
{
@ -294,7 +678,7 @@ void FStatusBar::drawKeys()
print ("..");
}
if ( iter+1 != keylist.end()
if ( iter+1 != key_list.end()
&& ( (*(iter+1))->isActivated() || (*(iter+1))->hasMouseFocus() )
&& x + int(getKeyName((*(iter+1))->getKey()).getLength()) + 3
< screenWidth )
@ -310,7 +694,7 @@ void FStatusBar::drawKeys()
if ( isMonochron() )
setReverse(true);
}
else if ( iter+1 != keylist.end() && x < screenWidth )
else if ( iter+1 != key_list.end() && x < screenWidth )
{
// not the last element
setColor (wc.statusbar_separator_fg, wc.statusbar_bg);
@ -334,398 +718,3 @@ void FStatusBar::drawKeys()
updateVTerm(true);
x_msg = x;
}
// public methods of FStatusBar
//----------------------------------------------------------------------
void FStatusBar::hide()
{
int screenWidth;
short fg, bg;
char* blank;
FWindow::hide();
fg = wc.term_fg;
bg = wc.term_bg;
setColor (fg, bg);
screenWidth = getColumnNumber();
if ( screenWidth < 0 )
return;
blank = new char[screenWidth+1];
std::memset(blank, ' ', uLong(screenWidth));
blank[screenWidth] = '\0';
setPrintPos (1, 1);
print (blank);
delete[] blank;
}
//----------------------------------------------------------------------
void FStatusBar::onMouseDown (FMouseEvent* ev)
{
if ( hasActivatedKey() )
return;
if ( ev->getButton() != fc::LeftButton )
{
mouse_down = false;
if ( ! keylist.empty() )
{
std::vector<FStatusKey*>::const_iterator iter, end;
iter = keylist.begin();
end = keylist.end();
while ( iter != end )
{
(*iter)->unsetMouseFocus();
++iter;
}
}
redraw();
return;
}
if ( mouse_down )
return;
mouse_down = true;
if ( ! keylist.empty() )
{
std::vector<FStatusKey*>::const_iterator iter, end;
int X = 1;
iter = keylist.begin();
end = keylist.end();
while ( iter != end )
{
int x1, x2, mouse_x, mouse_y, kname_len, txt_length;
x1 = X;
kname_len = int(getKeyName((*iter)->getKey()).getLength());
txt_length = int((*iter)->getText().getLength());
x2 = x1 + kname_len + txt_length + 1;
mouse_x = ev->getX();
mouse_y = ev->getY();
if ( mouse_x >= x1
&& mouse_x <= x2
&& mouse_y == 1
&& ! (*iter)->hasMouseFocus() )
{
(*iter)->setMouseFocus();
redraw();
}
X = x2 + 2;
++iter;
}
}
}
//----------------------------------------------------------------------
void FStatusBar::onMouseUp (FMouseEvent* ev)
{
if ( hasActivatedKey() )
return;
if ( ev->getButton() != fc::LeftButton )
return;
if ( mouse_down )
{
mouse_down = false;
if ( ! keylist.empty() )
{
std::vector<FStatusKey*>::const_iterator iter, end;
int X = 1;
iter = keylist.begin();
end = keylist.end();
while ( iter != end )
{
int x1, x2, kname_len, txt_length;
x1 = X;
kname_len = int(getKeyName((*iter)->getKey()).getLength());
txt_length = int((*iter)->getText().getLength());
x2 = x1 + kname_len + txt_length + 1;
if ( (*iter)->hasMouseFocus() )
{
int mouse_x, mouse_y;
(*iter)->unsetMouseFocus();
mouse_x = ev->getX();
mouse_y = ev->getY();
if ( mouse_x >= x1 && mouse_x <= x2 && mouse_y == 1 )
(*iter)->setActive();
// unset after get back from callback
(*iter)->unsetActive();
redraw();
}
X = x2 + 2;
++iter;
}
}
}
}
//----------------------------------------------------------------------
void FStatusBar::onMouseMove (FMouseEvent* ev)
{
if ( hasActivatedKey() )
return;
if ( ev->getButton() != fc::LeftButton )
return;
if ( mouse_down && ! keylist.empty() )
{
std::vector<FStatusKey*>::const_iterator iter, end;
bool focus_changed = false;
int X=1;
iter = keylist.begin();
end = keylist.end();
while ( iter != end )
{
int x1, x2, mouse_x, mouse_y, kname_len, txt_length;
x1 = X;
kname_len = int(getKeyName((*iter)->getKey()).getLength());
txt_length = int((*iter)->getText().getLength());
x2 = x1 + kname_len + txt_length + 1;
mouse_x = ev->getX();
mouse_y = ev->getY();
if ( mouse_x >= x1
&& mouse_x <= x2
&& mouse_y == 1 )
{
if ( ! (*iter)->hasMouseFocus() )
{
(*iter)->setMouseFocus();
focus_changed = true;
}
}
else
{
if ( (*iter)->hasMouseFocus() )
{
(*iter)->unsetMouseFocus();
focus_changed = true;
}
}
X = x2 + 2;
++iter;
}
if ( focus_changed )
redraw();
}
}
//----------------------------------------------------------------------
bool FStatusBar::hasActivatedKey()
{
if ( ! keylist.empty() )
{
std::vector<FStatusKey*>::const_iterator iter, end;
iter = keylist.begin();
end = keylist.end();
while ( iter != end )
{
if ( (*iter)->isActivated() )
return true;
++iter;
}
}
return false;
}
//----------------------------------------------------------------------
void FStatusBar::drawMessage()
{
int termWidth, space_offset;
bool isLastActiveFocus, hasKeys;
if ( ! (isVisible() ) )
return;
if ( x < 0 || x_msg < 0 )
return;
x = x_msg;
termWidth = getColumnNumber();
space_offset = 1;
hasKeys = bool(! keylist.empty());
if ( hasKeys )
{
std::vector<FStatusKey*>::const_iterator iter = keylist.end();
isLastActiveFocus = bool( (*(iter-1))->isActivated()
|| (*(iter-1))->hasMouseFocus() );
}
else
isLastActiveFocus = false;
if ( isLastActiveFocus )
space_offset = 0;
updateVTerm(false);
setColor (wc.statusbar_fg, wc.statusbar_bg);
setPrintPos (x, 1);
if ( isMonochron() )
setReverse(true);
if ( x+space_offset+3 < termWidth )
{
if ( text )
{
if ( ! isLastActiveFocus )
{
x++;
print (' ');
}
if ( hasKeys )
{
x += 2;
print (fc::BoxDrawingsVertical); // │
print (' ');
}
int msg_length = int(getMessage().getLength());
x += msg_length;
if ( x-1 <= termWidth )
print (getMessage());
else
{
print ( getMessage().left(uInt(msg_length+termWidth-x-1)) );
print ("..");
}
}
}
for (int i=x; i <= termWidth; i++)
print (' ');
if ( isMonochron() )
setReverse(false);
updateVTerm(true);
}
//----------------------------------------------------------------------
void FStatusBar::setMessage (FString& mgs)
{
text = mgs;
}
//----------------------------------------------------------------------
void FStatusBar::setMessage (const std::string& mgs)
{
FString s = FString(mgs);
setMessage (s);
}
//----------------------------------------------------------------------
void FStatusBar::setMessage (const char* mgs)
{
FString s = FString(mgs);
setMessage (s);
}
//----------------------------------------------------------------------
void FStatusBar::insert (FStatusKey* skey)
{
keylist.push_back (skey);
addAccelerator (skey->getKey(), skey);
skey->addCallback
(
"activate",
_METHOD_CALLBACK (this, &FStatusBar::cb_statuskey_activated)
);
}
//----------------------------------------------------------------------
void FStatusBar::remove (FStatusKey* skey)
{
std::vector<FStatusKey*>::iterator iter;
delAccelerator (skey);
if ( keylist.empty() )
return;
iter = keylist.begin();
while ( iter != keylist.end() )
{
if ( (*iter) == skey )
{
iter = keylist.erase(iter);
skey->setStatusbar(0);
break;
}
else
++iter;
}
}
//----------------------------------------------------------------------
void FStatusBar::remove (int pos)
{
if ( int(count()) < pos )
return;
keylist.erase (keylist.begin()+pos-1);
}
//----------------------------------------------------------------------
void FStatusBar::clear()
{
keylist.clear();
}
//----------------------------------------------------------------------
void FStatusBar::adjustSize()
{
setGeometry (1, getLineNumber(), getColumnNumber(), 1, false);
}
//----------------------------------------------------------------------
void FStatusBar::cb_statuskey_activated (FWidget* widget, void*)
{
if ( ! keylist.empty() )
{
std::vector<FStatusKey*>::const_iterator iter, end;
FStatusKey* statuskey = static_cast<FStatusKey*>(widget);
iter = keylist.begin();
end = keylist.end();
while ( iter != end )
{
if ( (*iter) != statuskey && (*iter)->isActivated() )
(*iter)->unsetActive();
++iter;
}
}
if ( isVisible() && isShown() )
redraw();
}

View File

@ -51,66 +51,84 @@ class FStatusBar;
class FStatusKey : public FWidget
{
private:
int key;
FString text;
bool active;
bool mouse_focus;
FStatusBar* bar;
private:
// Disable copy constructor
FStatusKey (const FStatusKey&);
// Disable assignment operator (=)
FStatusKey& operator = (const FStatusKey&);
void init (FWidget*);
void processActivate();
FStatusBar* statusbar() const;
void setStatusbar (FStatusBar*);
public:
// Constructors
explicit FStatusKey (FWidget* = 0);
FStatusKey (int, FString&, FWidget* = 0);
FStatusKey (int, const std::string&, FWidget* = 0);
FStatusKey (int, const char*, FWidget* = 0);
// Destructor
virtual ~FStatusKey();
// Accessors
virtual const char* getClassName() const;
virtual int getKey() const;
virtual FString getText() const;
// Mutators
void setActive();
void unsetActive();
bool setMouseFocus(bool);
bool setMouseFocus();
bool unsetMouseFocus();
// Inquiry
bool isActivated() const;
bool hasMouseFocus() const;
// Event handler
void onAccel (FAccelEvent*);
void setActive();
void unsetActive();
bool isActivated() const;
bool setMouseFocus(bool);
bool setMouseFocus();
bool unsetMouseFocus();
bool hasMouseFocus() const;
virtual int getKey() const;
virtual FString getText() const;
protected:
// Mutators
void setKey (int);
void setText (FString&);
void setText (const std::string&);
void setText (const char*);
private:
// Disable copy constructor
FStatusKey (const FStatusKey&);
// Disable assignment operator (=)
FStatusKey& operator = (const FStatusKey&);
// Methods
void init (FWidget*);
void processActivate();
FStatusBar* getConnectedStatusbar() const;
void setConnectedStatusbar (FStatusBar*);
// Friend class
friend class FStatusBar;
// Data Members
int key;
FString text;
bool active;
bool mouse_focus;
FStatusBar* bar;
};
#pragma pack(pop)
// FStatusKey inline functions
//----------------------------------------------------------------------
inline void FStatusKey::unsetActive()
{ active = false; }
inline const char* FStatusKey::getClassName() const
{ return "FStatusKey"; }
//----------------------------------------------------------------------
inline bool FStatusKey::isActivated() const
{ return active; }
inline int FStatusKey::getKey() const
{ return key; }
//----------------------------------------------------------------------
inline FString FStatusKey::getText() const
{ return text; }
//----------------------------------------------------------------------
inline void FStatusKey::unsetActive()
{ active = false; }
//----------------------------------------------------------------------
inline bool FStatusKey::setMouseFocus()
@ -120,18 +138,14 @@ inline bool FStatusKey::setMouseFocus()
inline bool FStatusKey::unsetMouseFocus()
{ return setMouseFocus(false); }
//----------------------------------------------------------------------
inline bool FStatusKey::isActivated() const
{ return active; }
//----------------------------------------------------------------------
inline bool FStatusKey::hasMouseFocus() const
{ return mouse_focus; }
//----------------------------------------------------------------------
inline int FStatusKey::getKey() const
{ return key; }
//----------------------------------------------------------------------
inline FString FStatusKey::getText() const
{ return text; }
//----------------------------------------------------------------------
inline void FStatusKey::setKey (int k)
{ key = k; }
@ -148,6 +162,14 @@ inline void FStatusKey::setText (const std::string& txt)
inline void FStatusKey::setText (const char* txt)
{ text = txt; }
//----------------------------------------------------------------------
inline FStatusBar* FStatusKey::getConnectedStatusbar() const
{ return bar; }
//----------------------------------------------------------------------
inline void FStatusKey::setConnectedStatusbar (FStatusBar* sb)
{ bar = sb; }
//----------------------------------------------------------------------
// class FStatusBar
@ -158,60 +180,69 @@ inline void FStatusKey::setText (const char* txt)
class FStatusBar : public FWindow
{
private:
std::vector<FStatusKey*> keylist;
FString text;
bool mouse_down;
int x;
int x_msg;
private:
// Disable copy constructor
FStatusBar (const FStatusBar&);
// Disable assignment operator (=)
FStatusBar& operator = (const FStatusBar&);
void init();
void draw();
void drawKeys();
public:
// Constructor
explicit FStatusBar (FWidget* = 0);
// Destructor
virtual ~FStatusBar();
// Accessors
virtual const char* getClassName() const;
FStatusKey* getStatusKey (int) const;
FString getMessage() const;
uInt getCount() const;
// Mutators
void activateKey (int);
void deactivateKey (int);
void setMessage (FString&);
void setMessage (const std::string&);
void setMessage (const char*);
// Inquiries
bool isActivated (int) const;
bool hasActivatedKey();
// Methods
void hide();
void drawMessage();
void clearMessage();
void insert (FStatusKey*);
void remove (FStatusKey*);
void remove (int);
void clear();
void adjustSize();
// Event handlers
void onMouseDown (FMouseEvent*);
void onMouseUp (FMouseEvent*);
void onMouseMove (FMouseEvent*);
uInt count() const;
FStatusKey* key (int) const;
void activateKey (int);
void deactivateKey (int);
bool isActivated (int) const;
bool hasActivatedKey();
void drawMessage();
void setMessage (FString&);
void setMessage (const std::string&);
void setMessage (const char*);
FString getMessage() const;
void clearMessage();
void insert (FStatusKey*);
void remove (FStatusKey*);
void remove (int);
void clear();
void adjustSize();
// Callback method
void cb_statuskey_activated (FWidget*, void*);
private:
// Typedef
typedef std::vector<FStatusKey*> keyList;
// Disable copy constructor
FStatusBar (const FStatusBar&);
// Disable assignment operator (=)
FStatusBar& operator = (const FStatusBar&);
// Methods
void init();
void draw();
void drawKeys();
// Data Members
keyList key_list;
FString text;
bool mouse_down;
int x;
int x_msg;
};
#pragma pack(pop)
@ -222,24 +253,24 @@ inline const char* FStatusBar::getClassName() const
{ return "FStatusBar"; }
//----------------------------------------------------------------------
inline uInt FStatusBar::count() const
{ return uInt(keylist.size()); }
inline FStatusKey* FStatusBar::getStatusKey (int index) const
{ return key_list[uInt(index-1)]; }
//----------------------------------------------------------------------
inline FStatusKey* FStatusBar::key(int index) const
{ return keylist[uInt(index-1)]; }
inline uInt FStatusBar::getCount() const
{ return uInt(key_list.size()); }
//----------------------------------------------------------------------
inline void FStatusBar::activateKey (int index)
{ keylist[uInt(index-1)]->setActive(); }
{ key_list[uInt(index-1)]->setActive(); }
//----------------------------------------------------------------------
inline void FStatusBar::deactivateKey (int index)
{ keylist[uInt(index-1)]->unsetActive(); }
{ key_list[uInt(index-1)]->unsetActive(); }
//----------------------------------------------------------------------
inline bool FStatusBar::isActivated(int index) const
{ return keylist[uInt(index-1)]->isActivated(); }
{ return key_list[uInt(index-1)]->isActivated(); }
//----------------------------------------------------------------------
inline FString FStatusBar::getMessage() const

View File

@ -3,6 +3,10 @@
#include "fstring.h"
// static class constant
const char* FString::bad_alloc_str = "not enough memory " \
"to alloc a new string";
//----------------------------------------------------------------------
// class FString
//----------------------------------------------------------------------
@ -107,14 +111,14 @@ FString::FString (uInt len, char c)
}
//----------------------------------------------------------------------
FString::FString (const FString& s)
: string(0)
, length(0)
, bufsize(0)
FString::FString (const FString& s) // copy constructor
: string(new wchar_t[FWDBUFFER + s.length + 1]())
, length(s.length)
, bufsize(FWDBUFFER + s.length + 1)
, c_string(0)
{
if ( s.string )
_replace (s.string);
std::wcscpy (string, s.string);
}
//----------------------------------------------------------------------
@ -213,350 +217,7 @@ FString::~FString() // destructor
}
// private methods of FString
//----------------------------------------------------------------------
inline void FString::initLength (uInt len)
{
if ( len == 0 )
return;
length = len;
bufsize = FWDBUFFER + len + 1;
string = new wchar_t[bufsize]();
std::wmemset (string, L'\0', bufsize);
}
//----------------------------------------------------------------------
inline void FString::_replace (const wchar_t* s)
{
if ( string )
delete[](string);
length = uInt(std::wcslen(s));
bufsize = FWDBUFFER + length + 1;
try
{
string = new wchar_t[bufsize]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return;
}
/* catch (std::exception& e)
{
std::cerr << "not enough memory for a new FString object "
<< e.what() << std::endl;
return;
}*/
std::wcscpy (string, s);
}
//----------------------------------------------------------------------
inline void FString::_insert (uInt pos, uInt len, const wchar_t* s)
{
if ( ! string )
{
// string is null
length = len;
bufsize = FWDBUFFER + length + 1;
try
{
string = new wchar_t[bufsize]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << " " << ex.what() << std::endl;
return;
}
std::wcscpy (string, s);
return;
}
else
{
uInt x;
if ( (length + len + 1) <= bufsize )
{
// output string <= bufsize
for (x = length; x > pos-1; x--) // shifting right side + '\0'
string[x+len] = string[x];
for (x=0; x < len; x++) // insert string
string[x+pos] = s[x];
length += len;
}
else
{
wchar_t* sptr;
// output string > bufsize
bufsize = FWDBUFFER + length + len + 1;
try
{
sptr = new wchar_t[bufsize](); // generate new string
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << " " << ex.what() << std::endl;
return;
}
uInt y = 0;
for (x=0; x < pos; x++) // left side
sptr[y++] = string[x];
for (x=0; x < len; x++) // insert string
sptr[y++] = s[x];
for (x=pos; x < length+1; x++) // right side + '\0'
sptr[y++] = string[x];
length += len;
delete[](string); // delete old string
string = sptr;
}
}
}
//----------------------------------------------------------------------
inline void FString::_remove (uInt pos, uInt len)
{
if ( (bufsize - length - 1 + len) <= FWDBUFFER )
{
// shifting left side to pos
for (uInt i=pos; (i+len) < length+1; i++)
string[i] = string[i+len];
length -= len;
}
else
{
wchar_t* sptr;
bufsize = length + 1 - len + FWDBUFFER;
try
{
sptr = new wchar_t[bufsize](); // generate new string
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << " " << ex.what() << std::endl;
return;
}
uInt x, y = 0;
for (x=0; x < pos; x++) // left side
sptr[y++] = string[x];
for (x=pos+len; x < length+1; x++) // right side + '\0'
sptr[y++] = string[x];
delete[](string); // delete old string
string = sptr;
length -= len;
}
}
//----------------------------------------------------------------------
inline char* FString::wc_to_c_str (const wchar_t* s) const
{
int mblength, size, dest_size;
const wchar_t* src;
if ( ! s ) // handle NULL string
return 0;
if ( ! *s ) // handle empty string
{
try
{
// Generate a empty string ("")
c_string = new char[1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << " " << ex.what() << std::endl;
return 0;
}
return c_string;
}
if ( c_string )
delete[](c_string);
size = int(std::wcslen(s)) + 1;
dest_size = size * int(CHAR_SIZE);
src = s;
std::mbstate_t state;
std::memset (&state, '\0', sizeof(mbstate_t));
try
{
c_string = new char[dest_size]();
// pre-initialiaze the whole string with '\0'
std::memset (c_string, '\0', size_t(dest_size));
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << " " << ex.what() << std::endl;
return 0;
}
mblength = int(std::wcsrtombs (c_string, &src, uLong(dest_size), &state));
if ( mblength == -1 && errno != EILSEQ )
{
delete[](c_string);
c_string = 0;
return const_cast<char*>("");
}
return c_string;
}
//----------------------------------------------------------------------
inline wchar_t* FString::c_to_wc_str (const char* s) const
{
int wclength, size, dest_size;
const char* src;
wchar_t* dest;
if ( ! s ) // handle NULL string
return 0;
if ( ! *s ) // handle empty string
{
try
{
// Generate a empty wide string (L"")
return (new wchar_t[1]());
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << " " << ex.what() << std::endl;
return 0;
}
}
size = int(std::strlen(s)) + 1;
dest_size = size * int(CHAR_SIZE);
src = s;
std::mbstate_t state;
std::memset (&state, '\0', sizeof(mbstate_t));
try
{
dest = new wchar_t[size]();
// pre-initialiaze the whole string with '\0'
std::wmemset (dest, L'\0', size_t(size));
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << " " << ex.what() << std::endl;
return 0;
}
wclength = int(std::mbsrtowcs (dest, &src, uLong(dest_size), &state));
if ( wclength == -1 )
{
if ( src != s )
return dest;
else
{
delete[] dest;
return 0;
}
}
if ( wclength == size )
dest[size-1] = '\0';
if ( wclength )
return dest;
else
{
delete[] dest;
return 0;
}
}
//----------------------------------------------------------------------
inline wchar_t* FString::extractToken ( wchar_t** rest
, const wchar_t* s
, const wchar_t* delim )
{
register wchar_t* token;
token = ( s ) ? const_cast<wchar_t*>(s) : *rest;
if ( ! *token )
return 0;
*rest = std::wcspbrk(token, delim);
if ( *rest )
*(*rest)++ = '\0';
else
*rest = token + std::wcslen(token);
return token;
}
// FString operators
//----------------------------------------------------------------------
std::ostream& operator << (std::ostream& outstr, const FString& s)
{
if ( s.length )
outstr << s.wc_to_c_str( s.string );
return (outstr);
}
//----------------------------------------------------------------------
std::istream& operator >> (std::istream& instr, FString& s)
{
const wchar_t* wc_str;
char buf[INPBUFFER+1];
instr.getline (buf, INPBUFFER);
wc_str = s.c_to_wc_str(buf);
if ( wc_str )
{
s._replace (wc_str);
delete[] wc_str;
}
return (instr);
}
//----------------------------------------------------------------------
std::wostream& operator << (std::wostream& outstr, const FString& s)
{
if ( s.length )
outstr << s.string;
return (outstr);
}
//----------------------------------------------------------------------
std::wistream& operator >> (std::wistream& instr, FString& s)
{
wchar_t buf[INPBUFFER+1];
instr.getline (buf, INPBUFFER);
s._replace (buf);
return (instr);
}
//----------------------------------------------------------------------
FString& FString::operator = (const FString& s)
{
@ -785,88 +446,6 @@ const FString FString::operator + (const char c)
return(tmp);
}
//----------------------------------------------------------------------
const FString operator + (const FString& s1, const FString& s2)
{
FString tmp(s1);
tmp._insert ( uInt(std::wcslen(s1.wc_str()))
, uInt(std::wcslen(s2.wc_str()))
, s2.wc_str() );
return (tmp);
}
//----------------------------------------------------------------------
const FString operator + (const FString& s, const wchar_t c)
{
FString tmp(s);
tmp._insert ( uInt(std::wcslen(s.wc_str())), 1, &c);
return (tmp);
}
//----------------------------------------------------------------------
const FString operator + (const std::wstring& s1, const FString& s2)
{
FString tmp(s1);
tmp._insert ( uInt(std::wcslen(s1.c_str()))
, uInt(std::wcslen(s2.wc_str()))
, s2.wc_str() );
return (tmp);
}
//----------------------------------------------------------------------
const FString operator + (const wchar_t* s1, const FString& s2)
{
FString tmp(s1);
tmp._insert ( uInt(std::wcslen(s1))
, uInt(std::wcslen(s2.wc_str()))
, s2.wc_str() );
return (tmp);
}
//----------------------------------------------------------------------
const FString operator + (const std::string& s1, const FString& s2)
{
FString tmp(s1);
tmp._insert ( tmp.getLength()
, uInt(std::wcslen(s2.wc_str()))
, s2.wc_str() );
return (tmp);
}
//----------------------------------------------------------------------
const FString operator + (const char* s1, const FString& s2)
{
FString tmp(s1);
tmp._insert ( tmp.getLength()
, uInt(std::wcslen(s2.wc_str()))
, s2.wc_str() );
return (tmp);
}
//----------------------------------------------------------------------
const FString operator + (const wchar_t c, const FString& s)
{
FString tmp(c);
tmp._insert (1, uInt(std::wcslen(s.wc_str())), s.wc_str());
return (tmp);
}
//----------------------------------------------------------------------
const FString operator + (const char c, const FString& s)
{
FString tmp(c);
tmp._insert (1, uInt(std::wcslen(s.wc_str())), s.wc_str());
return (tmp);
}
//----------------------------------------------------------------------
const FString operator + (const wchar_t c, const std::wstring& s)
{
FString tmp(c);
tmp._insert (1, uInt(s.length()), s.c_str());
return (tmp);
}
//----------------------------------------------------------------------
wchar_t& FString::operator [] (int pos)
{
@ -1125,7 +704,7 @@ long FString::toLong() const
p++;
}
if ( *p != L'\0' && ! std::isdigit(*p) )
if ( ! std::isdigit(*p) )
throw std::invalid_argument ("no valid number");
return num;
@ -1171,7 +750,7 @@ uLong FString::toULong() const
p++;
}
if ( *p != L'\0' && ! std::isdigit(*p) )
if ( ! std::isdigit(*p) )
throw std::invalid_argument ("no valid number");
return num;
@ -2610,3 +2189,430 @@ bool FString::includes (const char c)
s[1] = L'\0';
return (std::wcsstr(string, s) != 0);
}
// private methods of FString
//----------------------------------------------------------------------
inline void FString::initLength (uInt len)
{
if ( len == 0 )
return;
length = len;
bufsize = FWDBUFFER + len + 1;
string = new wchar_t[bufsize]();
std::wmemset (string, L'\0', bufsize);
}
//----------------------------------------------------------------------
inline void FString::_replace (const wchar_t* s)
{
if ( string )
delete[](string);
length = uInt(std::wcslen(s));
bufsize = FWDBUFFER + length + 1;
try
{
string = new wchar_t[bufsize]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return;
}
/* catch (std::exception& e)
{
std::cerr << "not enough memory for a new FString object "
<< e.what() << std::endl;
return;
}*/
std::wcscpy (string, s);
}
//----------------------------------------------------------------------
inline void FString::_insert (uInt pos, uInt len, const wchar_t* s)
{
if ( ! string )
{
// string is null
length = len;
bufsize = FWDBUFFER + length + 1;
try
{
string = new wchar_t[bufsize]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << " " << ex.what() << std::endl;
return;
}
std::wcscpy (string, s);
return;
}
else
{
uInt x;
if ( (length + len + 1) <= bufsize )
{
// output string <= bufsize
for (x = length; x > pos-1; x--) // shifting right side + '\0'
string[x+len] = string[x];
for (x=0; x < len; x++) // insert string
string[x+pos] = s[x];
length += len;
}
else
{
wchar_t* sptr;
// output string > bufsize
bufsize = FWDBUFFER + length + len + 1;
try
{
sptr = new wchar_t[bufsize](); // generate new string
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << " " << ex.what() << std::endl;
return;
}
uInt y = 0;
for (x=0; x < pos; x++) // left side
sptr[y++] = string[x];
for (x=0; x < len; x++) // insert string
sptr[y++] = s[x];
for (x=pos; x < length+1; x++) // right side + '\0'
sptr[y++] = string[x];
length += len;
delete[](string); // delete old string
string = sptr;
}
}
}
//----------------------------------------------------------------------
inline void FString::_remove (uInt pos, uInt len)
{
if ( (bufsize - length - 1 + len) <= FWDBUFFER )
{
// shifting left side to pos
for (uInt i=pos; (i+len) < length+1; i++)
string[i] = string[i+len];
length -= len;
}
else
{
wchar_t* sptr;
bufsize = length + 1 - len + FWDBUFFER;
try
{
sptr = new wchar_t[bufsize](); // generate new string
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << " " << ex.what() << std::endl;
return;
}
uInt x, y = 0;
for (x=0; x < pos; x++) // left side
sptr[y++] = string[x];
for (x=pos+len; x < length+1; x++) // right side + '\0'
sptr[y++] = string[x];
delete[](string); // delete old string
string = sptr;
length -= len;
}
}
//----------------------------------------------------------------------
inline char* FString::wc_to_c_str (const wchar_t* s) const
{
int mblength, size, dest_size;
const wchar_t* src;
if ( ! s ) // handle NULL string
return 0;
if ( ! *s ) // handle empty string
{
try
{
// Generate a empty string ("")
c_string = new char[1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << " " << ex.what() << std::endl;
return 0;
}
return c_string;
}
if ( c_string )
delete[](c_string);
size = int(std::wcslen(s)) + 1;
dest_size = size * int(CHAR_SIZE);
src = s;
std::mbstate_t state;
std::memset (&state, '\0', sizeof(mbstate_t));
try
{
c_string = new char[dest_size]();
// pre-initialiaze the whole string with '\0'
std::memset (c_string, '\0', size_t(dest_size));
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << " " << ex.what() << std::endl;
return 0;
}
mblength = int(std::wcsrtombs (c_string, &src, uLong(dest_size), &state));
if ( mblength == -1 && errno != EILSEQ )
{
delete[](c_string);
c_string = 0;
return const_cast<char*>("");
}
return c_string;
}
//----------------------------------------------------------------------
inline wchar_t* FString::c_to_wc_str (const char* s) const
{
int wclength, size, dest_size;
const char* src;
wchar_t* dest;
if ( ! s ) // handle NULL string
return 0;
if ( ! *s ) // handle empty string
{
try
{
// Generate a empty wide string (L"")
return (new wchar_t[1]());
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << " " << ex.what() << std::endl;
return 0;
}
}
size = int(std::strlen(s)) + 1;
dest_size = size * int(CHAR_SIZE);
src = s;
std::mbstate_t state;
std::memset (&state, '\0', sizeof(mbstate_t));
try
{
dest = new wchar_t[size]();
// pre-initialiaze the whole string with '\0'
std::wmemset (dest, L'\0', size_t(size));
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << " " << ex.what() << std::endl;
return 0;
}
wclength = int(std::mbsrtowcs (dest, &src, uLong(dest_size), &state));
if ( wclength == -1 )
{
if ( src != s )
return dest;
else
{
delete[] dest;
return 0;
}
}
if ( wclength == size )
dest[size-1] = '\0';
if ( wclength )
return dest;
else
{
delete[] dest;
return 0;
}
}
//----------------------------------------------------------------------
inline wchar_t* FString::extractToken ( wchar_t** rest
, const wchar_t* s
, const wchar_t* delim )
{
register wchar_t* token;
token = ( s ) ? const_cast<wchar_t*>(s) : *rest;
if ( ! *token )
return 0;
*rest = std::wcspbrk(token, delim);
if ( *rest )
*(*rest)++ = '\0';
else
*rest = token + std::wcslen(token);
return token;
}
// FString non-member operators
//----------------------------------------------------------------------
std::ostream& operator << (std::ostream& outstr, const FString& s)
{
if ( s.length )
outstr << s.wc_to_c_str( s.string );
return (outstr);
}
//----------------------------------------------------------------------
std::istream& operator >> (std::istream& instr, FString& s)
{
const wchar_t* wc_str;
char buf[FString::INPBUFFER + 1];
instr.getline (buf, FString::INPBUFFER);
wc_str = s.c_to_wc_str(buf);
if ( wc_str )
{
s._replace (wc_str);
delete[] wc_str;
}
return (instr);
}
//----------------------------------------------------------------------
std::wostream& operator << (std::wostream& outstr, const FString& s)
{
if ( s.length )
outstr << s.string;
return (outstr);
}
//----------------------------------------------------------------------
std::wistream& operator >> (std::wistream& instr, FString& s)
{
wchar_t buf[FString::INPBUFFER + 1];
instr.getline (buf, FString::INPBUFFER);
s._replace (buf);
return (instr);
}
//----------------------------------------------------------------------
const FString operator + (const FString& s1, const FString& s2)
{
FString tmp(s1);
tmp._insert ( uInt(std::wcslen(s1.wc_str()))
, uInt(std::wcslen(s2.wc_str()))
, s2.wc_str() );
return (tmp);
}
//----------------------------------------------------------------------
const FString operator + (const FString& s, const wchar_t c)
{
FString tmp(s);
tmp._insert ( uInt(std::wcslen(s.wc_str())), 1, &c);
return (tmp);
}
//----------------------------------------------------------------------
const FString operator + (const std::wstring& s1, const FString& s2)
{
FString tmp(s1);
tmp._insert ( uInt(std::wcslen(s1.c_str()))
, uInt(std::wcslen(s2.wc_str()))
, s2.wc_str() );
return (tmp);
}
//----------------------------------------------------------------------
const FString operator + (const wchar_t* s1, const FString& s2)
{
FString tmp(s1);
tmp._insert ( uInt(std::wcslen(s1))
, uInt(std::wcslen(s2.wc_str()))
, s2.wc_str() );
return (tmp);
}
//----------------------------------------------------------------------
const FString operator + (const std::string& s1, const FString& s2)
{
FString tmp(s1);
tmp._insert ( tmp.getLength()
, uInt(std::wcslen(s2.wc_str()))
, s2.wc_str() );
return (tmp);
}
//----------------------------------------------------------------------
const FString operator + (const char* s1, const FString& s2)
{
FString tmp(s1);
tmp._insert ( tmp.getLength()
, uInt(std::wcslen(s2.wc_str()))
, s2.wc_str() );
return (tmp);
}
//----------------------------------------------------------------------
const FString operator + (const wchar_t c, const FString& s)
{
FString tmp(c);
tmp._insert (1, uInt(std::wcslen(s.wc_str())), s.wc_str());
return (tmp);
}
//----------------------------------------------------------------------
const FString operator + (const char c, const FString& s)
{
FString tmp(c);
tmp._insert (1, uInt(std::wcslen(s.wc_str())), s.wc_str());
return (tmp);
}
//----------------------------------------------------------------------
const FString operator + (const wchar_t c, const std::wstring& s)
{
FString tmp(c);
tmp._insert (1, uInt(s.length()), s.c_str());
return (tmp);
}

View File

@ -34,11 +34,6 @@
#include <vector>
#define FWDBUFFER 15
#define INPBUFFER 200
#define CHAR_SIZE (sizeof(wchar_t)) // bytes per character
#define bad_alloc_str ("not enough memory to alloc a new string")
typedef unsigned char uChar;
typedef unsigned int uInt;
typedef unsigned long uLong;
@ -64,24 +59,9 @@ typedef long double lDouble;
class FString
{
public:
// Typedef
typedef const wchar_t* iterator;
private:
wchar_t* string;
uInt length;
uInt bufsize;
mutable char* c_string;
private:
void initLength (uInt);
void _replace (const wchar_t*);
void _insert (uInt, uInt, const wchar_t*);
void _remove (uInt, uInt);
char* wc_to_c_str (const wchar_t*) const;
wchar_t* c_to_wc_str (const char*) const;
wchar_t* extractToken (wchar_t**, const wchar_t*, const wchar_t*);
public:
// Constructors
FString ();
explicit FString (int);
@ -90,18 +70,112 @@ class FString
FString (uInt, wchar_t);
FString (int, char);
FString (uInt, char);
FString (const FString&); // implicit conversion constructor
FString (const FString&); // implicit conversion copy constructor
FString (const std::wstring&); // implicit conversion constructor
FString (const wchar_t*); // implicit conversion constructor
FString (const std::string&); // implicit conversion constructor
FString (const char*); // implicit conversion constructor
FString (const wchar_t); // implicit conversion constructor
FString (const char); // implicit conversion constructor
// Destructor
virtual ~FString ();
// Overloaded operators
FString& operator = (const FString&);
FString& operator = (const std::wstring&);
const FString& operator = (const wchar_t*);
FString& operator = (const std::string&);
const FString& operator = (const char*);
const FString& operator = (const wchar_t);
const FString& operator = (const char);
const FString& operator += (const FString&);
const FString& operator += (const std::wstring&);
const FString& operator += (const wchar_t*);
const FString& operator += (const std::string&);
const FString& operator += (const char*);
const FString& operator += (const wchar_t);
const FString& operator += (const char);
const FString operator + (const FString&);
const FString operator + (const std::wstring&);
const FString operator + (const wchar_t*);
const FString operator + (const std::string&);
const FString operator + (const char*);
const FString operator + (const wchar_t);
const FString operator + (const char);
wchar_t& operator [] (int);
wchar_t& operator [] (uInt);
const FString operator () (uInt, uInt);
bool operator < (const FString&) const;
bool operator < (const std::wstring&) const;
bool operator < (const wchar_t*) const;
bool operator < (const std::string&) const;
bool operator < (const char*) const;
bool operator < (const wchar_t) const;
bool operator < (const char) const;
bool operator <= (const FString&) const;
bool operator <= (const std::wstring&) const;
bool operator <= (const wchar_t*) const;
bool operator <= (const std::string&) const;
bool operator <= (const char*) const;
bool operator <= (const wchar_t) const;
bool operator <= (const char) const;
bool operator == (const FString&) const;
bool operator == (const std::wstring&) const;
bool operator == (const wchar_t*) const;
bool operator == (const std::string&) const;
bool operator == (const char*) const;
bool operator == (const wchar_t) const;
bool operator == (const char) const;
bool operator != (const FString&) const;
bool operator != (const std::wstring&) const;
bool operator != (const wchar_t*) const;
bool operator != (const std::string&) const;
bool operator != (const char*) const;
bool operator != (const wchar_t) const;
bool operator != (const char) const;
bool operator >= (const FString&) const;
bool operator >= (const std::wstring&) const;
bool operator >= (const wchar_t*) const;
bool operator >= (const std::string&) const;
bool operator >= (const char*) const;
bool operator >= (const wchar_t) const;
bool operator >= (const char) const;
bool operator > (const FString&) const;
bool operator > (const std::wstring&) const;
bool operator > (const wchar_t*) const;
bool operator > (const std::string&) const;
bool operator > (const char*) const;
bool operator > (const wchar_t) const;
bool operator > (const char) const;
operator const char* () const { return c_str(); }
// Non-member operators
friend std::ostream& operator << (std::ostream& outstr, const FString& s);
friend std::istream& operator >> (std::istream& instr, FString& s);
friend std::wostream& operator << (std::wostream& outstr, const FString& s);
friend std::wistream& operator >> (std::wistream& instr, FString& s);
friend const FString operator + (const FString&, const FString&);
friend const FString operator + (const FString&, const wchar_t);
friend const FString operator + (const std::wstring&, const FString&);
friend const FString operator + (const wchar_t*, const FString&);
friend const FString operator + (const std::string&, const FString&);
friend const FString operator + (const char*, const FString&);
friend const FString operator + (const wchar_t, const FString&);
friend const FString operator + (const char, const FString&);
friend const FString operator + (const wchar_t, const std::wstring&);
// inquiries
bool isNull() const;
bool isEmpty() const;
// Methods
uInt getLength() const;
uInt getUTF8length() const;
@ -175,94 +249,6 @@ class FString
FString& setFormatedNumber (long, char = nl_langinfo(THOUSEP)[0]);
FString& setFormatedNumber (uLong, char = nl_langinfo(THOUSEP)[0]);
friend std::ostream& operator << (std::ostream& outstr, const FString& s);
friend std::istream& operator >> (std::istream& instr, FString& s);
friend std::wostream& operator << (std::wostream& outstr, const FString& s);
friend std::wistream& operator >> (std::wistream& instr, FString& s);
FString& operator = (const FString&);
FString& operator = (const std::wstring&);
const FString& operator = (const wchar_t*);
FString& operator = (const std::string&);
const FString& operator = (const char*);
const FString& operator = (const wchar_t);
const FString& operator = (const char);
const FString& operator += (const FString&);
const FString& operator += (const std::wstring&);
const FString& operator += (const wchar_t*);
const FString& operator += (const std::string&);
const FString& operator += (const char*);
const FString& operator += (const wchar_t);
const FString& operator += (const char);
const FString operator + (const FString&);
const FString operator + (const std::wstring&);
const FString operator + (const wchar_t*);
const FString operator + (const std::string&);
const FString operator + (const char*);
const FString operator + (const wchar_t);
const FString operator + (const char);
friend const FString operator + (const FString&, const FString&);
friend const FString operator + (const FString&, const wchar_t);
friend const FString operator + (const std::wstring&, const FString&);
friend const FString operator + (const wchar_t*, const FString&);
friend const FString operator + (const std::string&, const FString&);
friend const FString operator + (const char*, const FString&);
friend const FString operator + (const wchar_t, const FString&);
friend const FString operator + (const char, const FString&);
friend const FString operator + (const wchar_t, const std::wstring&);
wchar_t& operator [] (int);
wchar_t& operator [] (uInt);
const FString operator () (uInt, uInt);
bool operator < (const FString&) const;
bool operator < (const std::wstring&) const;
bool operator < (const wchar_t*) const;
bool operator < (const std::string&) const;
bool operator < (const char*) const;
bool operator < (const wchar_t) const;
bool operator < (const char) const;
bool operator <= (const FString&) const;
bool operator <= (const std::wstring&) const;
bool operator <= (const wchar_t*) const;
bool operator <= (const std::string&) const;
bool operator <= (const char*) const;
bool operator <= (const wchar_t) const;
bool operator <= (const char) const;
bool operator == (const FString&) const;
bool operator == (const std::wstring&) const;
bool operator == (const wchar_t*) const;
bool operator == (const std::string&) const;
bool operator == (const char*) const;
bool operator == (const wchar_t) const;
bool operator == (const char) const;
bool operator != (const FString&) const;
bool operator != (const std::wstring&) const;
bool operator != (const wchar_t*) const;
bool operator != (const std::string&) const;
bool operator != (const char*) const;
bool operator != (const wchar_t) const;
bool operator != (const char) const;
bool operator >= (const FString&) const;
bool operator >= (const std::wstring&) const;
bool operator >= (const wchar_t*) const;
bool operator >= (const std::string&) const;
bool operator >= (const char*) const;
bool operator >= (const wchar_t) const;
bool operator >= (const char) const;
bool operator > (const FString&) const;
bool operator > (const std::wstring&) const;
bool operator > (const wchar_t*) const;
bool operator > (const std::string&) const;
bool operator > (const char*) const;
bool operator > (const wchar_t) const;
bool operator > (const char) const;
operator const char* () const { return c_str(); }
const FString& insert (const FString&, uInt);
const FString& insert (const wchar_t*, uInt);
const FString& insert (const char*, uInt);
@ -334,6 +320,28 @@ class FString
bool includes (const char*);
bool includes (const wchar_t);
bool includes (const char);
private:
// Constants
static const uInt FWDBUFFER = 15;
static const uInt INPBUFFER = 200;
static const uInt CHAR_SIZE = sizeof(wchar_t); // bytes per character
static const char* bad_alloc_str;
// Methods
void initLength (uInt);
void _replace (const wchar_t*);
void _insert (uInt, uInt, const wchar_t*);
void _remove (uInt, uInt);
char* wc_to_c_str (const wchar_t*) const;
wchar_t* c_to_wc_str (const char*) const;
wchar_t* extractToken (wchar_t**, const wchar_t*, const wchar_t*);
// Data Members
wchar_t* string;
uInt length;
uInt bufsize;
mutable char* c_string;
};

View File

@ -33,6 +33,66 @@ FSwitch::~FSwitch() // destructor
{ }
// public methods of FSwitch
//----------------------------------------------------------------------
void FSwitch::setText (FString txt)
{
FToggleButton::setText(txt);
switch_offset_pos = int(txt.getLength()) + 1;
}
//----------------------------------------------------------------------
void FSwitch::onKeyPress (FKeyEvent* ev)
{
switch ( ev->key() )
{
case fc::Fkey_home:
case fc::Fkey_left:
setChecked();
ev->accept();
break;
case fc::Fkey_end:
case fc::Fkey_right:
unsetChecked();
ev->accept();
break;
default:
break;
}
if ( ev->isAccepted() )
draw();
else
FToggleButton::onKeyPress(ev);
}
//----------------------------------------------------------------------
void FSwitch::onMouseDown (FMouseEvent* ev)
{
FToggleButton::onMouseDown(ev);
if ( ev->getButton() != fc::LeftButton )
return;
button_pressed = true;
draw();
}
//----------------------------------------------------------------------
void FSwitch::onMouseUp (FMouseEvent* ev)
{
FToggleButton::onMouseUp(ev);
if ( ev->getButton() != fc::LeftButton )
return;
button_pressed = false;
draw();
}
// private methods of FSwitch
//----------------------------------------------------------------------
void FSwitch::draw()
@ -143,62 +203,3 @@ void FSwitch::drawCheckButton()
setCursorPos (7 + switch_offset_pos, 1);
}
}
// public methods of FSwitch
//----------------------------------------------------------------------
void FSwitch::setText (FString txt)
{
FToggleButton::setText(txt);
switch_offset_pos = int(txt.getLength()) + 1;
}
//----------------------------------------------------------------------
void FSwitch::onKeyPress (FKeyEvent* ev)
{
switch ( ev->key() )
{
case fc::Fkey_home:
case fc::Fkey_left:
setChecked();
ev->accept();
break;
case fc::Fkey_end:
case fc::Fkey_right:
unsetChecked();
ev->accept();
break;
default:
break;
}
if ( ev->isAccepted() )
draw();
else
FToggleButton::onKeyPress(ev);
}
//----------------------------------------------------------------------
void FSwitch::onMouseDown (FMouseEvent* ev)
{
FToggleButton::onMouseDown(ev);
if ( ev->getButton() != fc::LeftButton )
return;
button_pressed = true;
draw();
}
//----------------------------------------------------------------------
void FSwitch::onMouseUp (FMouseEvent* ev)
{
FToggleButton::onMouseUp(ev);
if ( ev->getButton() != fc::LeftButton )
return;
button_pressed = false;
draw();
}

View File

@ -45,33 +45,39 @@
class FSwitch : public FToggleButton
{
private:
int switch_offset_pos;
bool button_pressed;
private:
// Disable copy constructor
FSwitch (const FSwitch&);
// Disable assignment operator (=)
FSwitch& operator = (const FSwitch&);
void draw();
void drawCheckButton();
public:
// Constructors
explicit FSwitch (FWidget* = 0);
FSwitch (const FString&, FWidget* = 0);
// Destructor
virtual ~FSwitch();
// Accessor
const char* getClassName() const;
// Mutator
void setText (FString);
// Event handlers
void onKeyPress (FKeyEvent*);
void onMouseDown (FMouseEvent*);
void onMouseUp (FMouseEvent*);
private:
// Disable copy constructor
FSwitch (const FSwitch&);
// Disable assignment operator (=)
FSwitch& operator = (const FSwitch&);
// Methods
void draw();
void drawCheckButton();
// Data Members
int switch_offset_pos;
bool button_pressed;
};
#pragma pack(pop)

File diff suppressed because it is too large Load Diff

View File

@ -75,9 +75,6 @@
#define OSC ESC "]" // Operating system command (7-bit)
#define SECDA ESC "[>c" // Secondary Device Attributes
// parseKeyString return value
#define NEED_MORE_DATA -1
//----------------------------------------------------------------------
// class FTerm
@ -88,7 +85,221 @@
class FTerm
{
public:
static struct modifier_key // bit field
{
uChar shift : 1; // 0..1
uChar alt_gr : 1; // 0..1
uChar ctrl : 1; // 0..1
uChar alt : 1; // 0..1
uChar : 4; // padding bits
} mod_key;
// Constructor
FTerm ();
// Destructor
virtual ~FTerm();
// Accessors
virtual const char* getClassName() const;
static int getLineNumber();
static int getColumnNumber();
static FString getKeyName (int);
static modifier_key& getModifierKey();
static char* getTermType();
static char* getTermName();
static uInt getTabstop();
static int getMaxColor();
static fc::consoleCursorStyle getConsoleCursor();
// Inquiries
static bool isKeyTimeout (timeval*, register long);
static bool isRaw();
static bool hasPCcharset();
static bool hasUTF8();
static bool hasVT100();
static bool hasASCII();
static bool isMonochron();
static bool isXTerminal();
static bool isRxvtTerminal();
static bool isUrxvtTerminal();
static bool isMltermTerminal();
static bool isPuttyTerminal();
static bool isKdeTerminal();
static bool isGnomeTerminal();
static bool isKtermTerminal();
static bool isTeraTerm();
static bool isCygwinTerminal();
static bool isMinttyTerm();
static bool isLinuxTerm();
static bool isScreenTerm();
static bool isTmuxTerm();
static bool isInputDataPending();
static bool isNewFont();
static bool isUTF8();
static bool isUTF8_linux_terminal();
// Mutators
static bool setCursorOptimisation (bool);
static void setConsoleCursor (fc::consoleCursorStyle, bool);
static bool setRawMode (bool);
static bool setRawMode();
static bool unsetRawMode();
static bool setCookedMode();
static bool setUTF8 (bool);
static bool setUTF8();
static bool unsetUTF8();
static bool setNonBlockingInput (bool);
static bool setNonBlockingInput();
static bool unsetNonBlockingInput();
// Methods
static int parseKeyString (char*, int, timeval*);
static bool& unprocessedInput();
static bool setVGAFont();
static bool setNewFont();
static bool setOldFont();
static char* moveCursor (int, int, int, int);
static char* enableCursor();
static char* disableCursor();
static void detectTermSize();
static void setTermSize (int, int);
static void setKDECursor (fc::kdeKonsoleCursorShape);
static const FString getXTermFont();
static const FString getXTermTitle();
static void setXTermCursorStyle (fc::xtermCursorStyle);
static void setXTermTitle (const FString&);
static void setXTermForeground (const FString&);
static void setXTermBackground (const FString&);
static void setXTermCursorColor (const FString&);
static void setXTermMouseForeground (const FString&);
static void setXTermMouseBackground (const FString&);
static void setXTermHighlightBackground (const FString&);
static void resetXTermColors();
static void resetXTermForeground();
static void resetXTermBackground();
static void resetXTermCursorColor();
static void resetXTermMouseForeground();
static void resetXTermMouseBackground();
static void resetXTermHighlightBackground();
static void saveColorMap();
static void resetColorMap();
static void setPalette (short, int, int, int);
static void setBeep (int, int);
static void resetBeep();
static void beep();
static void setEncoding (std::string);
static std::string getEncoding();
static bool scrollTermForward();
static bool scrollTermReverse();
static const FString getAnswerbackMsg();
static const FString getSecDA();
// function pointer -> static function
static int (*Fputchar)(int);
static void putstringf (const char*, ...)
#if defined(__clang__)
__attribute__((__format__ (__printf__, 1, 2)))
#elif defined(__GNUC__)
__attribute__ ((format (printf, 1, 2)))
#endif
;
static void putstring (const char*, int = 1);
static int putchar_ASCII (register int);
static int putchar_UTF8 (register int);
static int UTF8decode (char*);
protected:
// Typedefs
typedef FOptiAttr::char_data char_data;
// Methods
static void init_consoleCharMap();
static bool charEncodable (uInt);
static uInt charEncode (uInt);
static uInt charEncode (uInt, fc::encoding);
static char* changeAttribute ( char_data*&
, char_data*& );
static bool hasChangedTermSize();
static void changeTermSizeFinished();
static void xtermMouse (bool);
static void enableXTermMouse();
static void disableXTermMouse();
#ifdef F_HAVE_LIBGPM
static bool gpmMouse (bool);
static bool enableGpmMouse();
static bool disableGpmMouse();
static bool isGpmMouseEnabled();
#endif // F_HAVE_LIBGPM
static FPoint& getMousePos();
static void setMousePos (FPoint&);
static void setMousePos (short, short);
// Data Members
static int stdin_no;
static int stdout_no;
static bool NewFont;
static bool VGAFont;
static bool cursor_optimisation;
static fc::encoding Encoding;
static char exit_message[8192];
private:
// Typedefs
typedef FTermcap::tcap_map termcap_map;
typedef struct
{
uChar red;
uChar green;
uChar blue;
} dacreg;
// Constants
static const int NEED_MORE_DATA = -1; // parseKeyString return value
// Disable copy constructor
FTerm (const FTerm&);
// Disable assignment operator (=)
FTerm& operator = (const FTerm&);
// Methods
static uInt16 getInputStatusRegisterOne();
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 openConsole();
static int closeConsole();
static int isConsole();
static void identifyTermType();
static int getScreenFont();
static int setScreenFont (uChar*, uInt, uInt, uInt, bool = false);
static int setUnicodeMap (struct unimapdesc*);
static int getUnicodeMap ();
static void init_console();
static uInt getBaudRate (const struct termios*);
static char* init_256colorTerminal();
static char* parseAnswerbackMsg (char*&);
static char* parseSecDA (char*&);
static void oscPrefix();
static void oscPostfix();
static void init_alt_charset();
static void init_pc_charset();
static void init_termcaps();
static void init_encoding();
void init();
void finish();
static uInt cp437_to_unicode (uChar);
static void signal_handler (int);
// Data Members
static std::map <uChar,uChar>* vt100_alt_char;
static std::map <std::string,fc::encoding>* encoding_set;
static FTermcap::tcap_map* tcap;
@ -147,260 +358,15 @@ class FTerm
static const FString* answer_back;
static const FString* sec_da;
typedef struct
{
uChar red;
uChar green;
uChar blue;
} dacreg;
struct
{
dacreg d[16];
} color_map;
protected:
static int stdin_no;
static int stdout_no;
static bool NewFont;
static bool VGAFont;
static bool cursor_optimisation;
static fc::encoding Encoding;
static char exit_message[8192];
static struct modifier_key // bit field
{
uChar shift : 1; // 0..1
uChar alt_gr : 1; // 0..1
uChar ctrl : 1; // 0..1
uChar alt : 1; // 0..1
uChar : 4; // padding bits
} mod_key;
private:
// Disable copy constructor
FTerm (const FTerm&);
// Disable assignment operator (=)
FTerm& operator = (const FTerm&);
static uInt16 getInputStatusRegisterOne();
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 openConsole();
static int closeConsole();
static int isConsole();
static void identifyTermType();
static int getScreenFont();
static int setScreenFont (uChar*, uInt, uInt, uInt, bool = false);
static int setUnicodeMap (struct unimapdesc*);
static int getUnicodeMap ();
static void init_console();
static uInt getBaudRate (const struct termios*);
static char* init_256colorTerminal();
static char* parseAnswerbackMsg (char*&);
static char* parseSecDA (char*&);
static void oscPrefix();
static void oscPostfix();
static void init_alt_charset();
static void init_pc_charset();
static void init_termcaps();
static void init_encoding();
void init();
void finish();
static uInt cp437_to_unicode (uChar);
static void signal_handler (int);
protected:
static void init_consoleCharMap();
static bool charEncodable (uInt);
static uInt charEncode (uInt);
static uInt charEncode (uInt, fc::encoding);
static char* changeAttribute ( FOptiAttr::char_data*&
, FOptiAttr::char_data*& );
static bool hasChangedTermSize();
static void changeTermSizeFinished();
static void xtermMouse (bool);
static void enableXTermMouse();
static void disableXTermMouse();
#ifdef F_HAVE_LIBGPM
static bool gpmMouse (bool);
static bool enableGpmMouse();
static bool disableGpmMouse();
static bool isGpmMouseEnabled();
#endif // F_HAVE_LIBGPM
static FPoint& getMousePos();
static void setMousePos (FPoint&);
static void setMousePos (short, short);
public:
// Constructor
FTerm ();
// Destructor
virtual ~FTerm();
virtual const char* getClassName() const;
static bool isKeyTimeout (timeval*, register long);
static int parseKeyString (char*, int, timeval*);
static bool& unprocessedInput();
static int getLineNumber();
static int getColumnNumber();
static FString getKeyName (int);
static modifier_key& getModifierKey();
static char* getTermType();
static char* getTermName();
static uInt getTabstop();
static bool hasPCcharset();
static bool hasUTF8();
static bool hasVT100();
static bool hasASCII();
static bool isMonochron();
static bool isXTerminal();
static bool isRxvtTerminal();
static bool isUrxvtTerminal();
static bool isMltermTerminal();
static bool isPuttyTerminal();
static bool isKdeTerminal();
static bool isGnomeTerminal();
static bool isKtermTerminal();
static bool isTeraTerm();
static bool isCygwinTerminal();
static bool isMinttyTerm();
static bool isLinuxTerm();
static bool isScreenTerm();
static bool isTmuxTerm();
static bool isInputDataPending();
static bool setVGAFont();
static bool setNewFont();
static bool isNewFont();
static bool setOldFont();
static bool setCursorOptimisation (bool);
static fc::consoleCursorStyle getConsoleCursor();
static void setConsoleCursor (fc::consoleCursorStyle, bool);
static char* moveCursor (int, int, int, int);
static char* enableCursor();
static char* disableCursor();
static void detectTermSize();
static void setTermSize (int, int);
static void setKDECursor (fc::kdeKonsoleCursorShape);
static const FString getXTermFont();
static const FString getXTermTitle();
static void setXTermCursorStyle (fc::xtermCursorStyle);
static void setXTermTitle (const FString&);
static void setXTermForeground (const FString&);
static void setXTermBackground (const FString&);
static void setXTermCursorColor (const FString&);
static void setXTermMouseForeground (const FString&);
static void setXTermMouseBackground (const FString&);
static void setXTermHighlightBackground (const FString&);
static void resetXTermColors();
static void resetXTermForeground();
static void resetXTermBackground();
static void resetXTermCursorColor();
static void resetXTermMouseForeground();
static void resetXTermMouseBackground();
static void resetXTermHighlightBackground();
static void saveColorMap();
static void resetColorMap();
static void setPalette (short, int, int, int);
static int getMaxColor();
static void setBeep (int, int);
static void resetBeep();
static void beep();
static void setEncoding (std::string);
static std::string getEncoding();
static bool setNonBlockingInput (bool);
static bool setNonBlockingInput();
static bool unsetNonBlockingInput();
static bool scrollTermForward();
static bool scrollTermReverse();
static bool setUTF8 (bool);
static bool setUTF8();
static bool unsetUTF8();
static bool isUTF8();
static bool isUTF8_linux_terminal();
static bool setRawMode (bool);
static bool setRawMode();
static bool unsetRawMode();
static bool setCookedMode();
static bool isRaw();
static const FString getAnswerbackMsg();
static const FString getSecDA();
// function pointer -> static function
static int (*Fputchar)(int);
static void putstringf (const char*, ...)
#if defined(__clang__)
__attribute__((__format__ (__printf__, 1, 2)))
#elif defined(__GNUC__)
__attribute__ ((format (printf, 1, 2)))
#endif
;
static void putstring (const char*, int = 1);
static int putchar_ASCII (register int);
static int putchar_UTF8 (register int);
static int UTF8decode (char*);
};
#pragma pack(pop)
// FTerm inline functions
//----------------------------------------------------------------------
inline bool FTerm::hasChangedTermSize()
{ return resize_term; }
//----------------------------------------------------------------------
inline void FTerm::changeTermSizeFinished()
{ resize_term = false; }
//----------------------------------------------------------------------
inline void FTerm::enableXTermMouse()
{ xtermMouse(true); }
//----------------------------------------------------------------------
inline void FTerm::disableXTermMouse()
{ xtermMouse(false); }
#ifdef F_HAVE_LIBGPM
//----------------------------------------------------------------------
inline bool FTerm::enableGpmMouse()
{ return gpmMouse(true); }
//----------------------------------------------------------------------
inline bool FTerm::disableGpmMouse()
{ return gpmMouse(false); }
//----------------------------------------------------------------------
inline bool FTerm::isGpmMouseEnabled()
{ return gpm_mouse_enabled; }
#endif // F_HAVE_LIBGPM
//----------------------------------------------------------------------
inline FPoint& FTerm::getMousePos()
{ return *mouse; }
//----------------------------------------------------------------------
inline void FTerm::setMousePos (FPoint& m)
{ *mouse = m; }
//----------------------------------------------------------------------
inline void FTerm::setMousePos (short x, short y)
{ mouse->setPoint (x, y); }
//----------------------------------------------------------------------
inline bool FTerm::setNonBlockingInput()
{ return setNonBlockingInput(true); }
//----------------------------------------------------------------------
inline const char* FTerm::getClassName() const
{ return "FTerm"; }
@ -417,6 +383,14 @@ inline char* FTerm::getTermName()
inline uInt FTerm::getTabstop()
{ return FTermcap::tabstop; }
//----------------------------------------------------------------------
inline int FTerm::getMaxColor()
{ return FTermcap::max_color; }
//----------------------------------------------------------------------
inline bool FTerm::isRaw()
{ return raw_mode; }
//----------------------------------------------------------------------
inline bool FTerm::hasPCcharset()
{ return pc_charset_console; }
@ -433,10 +407,6 @@ inline bool FTerm::hasVT100()
inline bool FTerm::hasASCII()
{ return ascii_console; }
//----------------------------------------------------------------------
inline bool FTerm::isNewFont()
{ return NewFont; }
//----------------------------------------------------------------------
inline bool FTerm::isMonochron()
{ return monochron; }
@ -502,28 +472,8 @@ inline bool FTerm::isInputDataPending()
{ return input_data_pending; }
//----------------------------------------------------------------------
inline bool FTerm::setCursorOptimisation (bool on)
{ return cursor_optimisation = (on) ? true : false; }
//----------------------------------------------------------------------
inline bool FTerm::isRaw()
{ return raw_mode; }
//----------------------------------------------------------------------
inline int FTerm::getMaxColor()
{ return FTermcap::max_color; }
//----------------------------------------------------------------------
inline bool FTerm::unsetNonBlockingInput()
{ return setNonBlockingInput(false); }
//----------------------------------------------------------------------
inline bool FTerm::setUTF8()
{ return setUTF8(true); }
//----------------------------------------------------------------------
inline bool FTerm::unsetUTF8()
{ return setUTF8(false); }
inline bool FTerm::isNewFont()
{ return NewFont; }
//----------------------------------------------------------------------
inline bool FTerm::isUTF8()
@ -533,6 +483,10 @@ inline bool FTerm::isUTF8()
inline bool FTerm::isUTF8_linux_terminal()
{ return utf8_linux_terminal; }
//----------------------------------------------------------------------
inline bool FTerm::setCursorOptimisation (bool on)
{ return cursor_optimisation = (on) ? true : false; }
//----------------------------------------------------------------------
inline bool FTerm::setRawMode()
{ return setRawMode(true); }
@ -545,5 +499,63 @@ inline bool FTerm::unsetRawMode()
inline bool FTerm::setCookedMode()
{ return setRawMode(false); }
//----------------------------------------------------------------------
inline bool FTerm::setUTF8()
{ return setUTF8(true); }
//----------------------------------------------------------------------
inline bool FTerm::unsetUTF8()
{ return setUTF8(false); }
//----------------------------------------------------------------------
inline bool FTerm::setNonBlockingInput()
{ return setNonBlockingInput(true); }
//----------------------------------------------------------------------
inline bool FTerm::unsetNonBlockingInput()
{ return setNonBlockingInput(false); }
//----------------------------------------------------------------------
inline bool FTerm::hasChangedTermSize()
{ return resize_term; }
//----------------------------------------------------------------------
inline void FTerm::changeTermSizeFinished()
{ resize_term = false; }
//----------------------------------------------------------------------
inline void FTerm::enableXTermMouse()
{ xtermMouse(true); }
//----------------------------------------------------------------------
inline void FTerm::disableXTermMouse()
{ xtermMouse(false); }
#ifdef F_HAVE_LIBGPM
//----------------------------------------------------------------------
inline bool FTerm::enableGpmMouse()
{ return gpmMouse(true); }
//----------------------------------------------------------------------
inline bool FTerm::disableGpmMouse()
{ return gpmMouse(false); }
//----------------------------------------------------------------------
inline bool FTerm::isGpmMouseEnabled()
{ return gpm_mouse_enabled; }
#endif // F_HAVE_LIBGPM
//----------------------------------------------------------------------
inline FPoint& FTerm::getMousePos()
{ return *mouse; }
//----------------------------------------------------------------------
inline void FTerm::setMousePos (FPoint& m)
{ *mouse = m; }
//----------------------------------------------------------------------
inline void FTerm::setMousePos (short x, short y)
{ mouse->setPoint (x, y); }
#endif // _FTERM_H

View File

@ -15,13 +15,13 @@
//----------------------------------------------------------------------
// class FTermcap
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class FTermcap
{
public:
// Typedef
typedef struct
{
char* string;
@ -29,6 +29,27 @@ class FTermcap
}
tcap_map;
// Constructors
FTermcap()
{ }
// Destructor
~FTermcap()
{ }
// Accessor
tcap_map* getTermcapMap()
{
return tcap;
}
// Mutator
void setTermcapMap (tcap_map* t)
{
tcap = t;
}
// Data Members
static bool background_color_erase;
static bool automatic_left_margin;
static bool automatic_right_margin;
@ -40,24 +61,8 @@ class FTermcap
static uInt attr_without_color;
private:
// Data Members
static tcap_map* tcap;
public:
FTermcap()
{ }
~FTermcap()
{ }
tcap_map* getTermcapMap()
{
return tcap;
}
void setTermcapMap (tcap_map* t)
{
tcap = t;
}
};
#pragma pack(pop)

View File

@ -32,207 +32,94 @@ FTextView::~FTextView() // destructor
delete hbar;
}
// private methods of FTextView
// public methods of FTextView
//----------------------------------------------------------------------
void FTextView::init()
FString FTextView::getText() const
{
nf_offset = isNewFont() ? 1 : 0;
uInt len, rows, idx;
setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg);
if ( data.empty() )
return FString("");
vbar = new FScrollbar(fc::vertical, this);
vbar->setMinimum(0);
vbar->setValue(0);
vbar->hide();
len = 0;
rows = getRows();
hbar = new FScrollbar(fc::horizontal, this);
hbar->setMinimum(0);
hbar->setValue(0);
hbar->hide();
for (uInt i=0 ; i < rows; i++)
len += data[i].getLength() + 1;
vbar->addCallback
(
"change-value",
_METHOD_CALLBACK (this, &FTextView::cb_VBarChange)
);
hbar->addCallback
(
"change-value",
_METHOD_CALLBACK (this, &FTextView::cb_HBarChange)
);
FString s(len + 1);
idx = 0;
for (uInt i=0 ; i < rows; i++)
{
const wchar_t* p = data[i].wc_str();
if ( p )
{
while ( (s[idx++] = *p++) != 0 );
s[idx-1] = '\n';
}
else
{
s[idx++] = '\n';
}
}
s[idx-1] = 0;
return s;
}
//----------------------------------------------------------------------
void FTextView::draw()
void FTextView::setGeometry (int x, int y, int w, int h, bool adjust)
{
FWidget* parent = getParentWidget();
bool is_text_dialog;
updateVTerm(false);
setColor();
FWidget::setGeometry(x, y, w, h, adjust);
int width = getWidth();
int height = getHeight();
if ( isMonochron() )
setReverse(true);
if ( parent
&& parent->isDialogWidget()
&& isPaddingIgnored()
&& getGeometry() == FRect ( 1
, 2
, parent->getWidth()
, parent->getHeight()-1) )
if ( isNewFont() )
{
is_text_dialog = true;
vbar->setGeometry (width, 1, 2, height-1);
hbar->setGeometry (1, height, width-2, 1);
}
else
is_text_dialog = false;
{
vbar->setGeometry (width, 2, 1, height-2);
hbar->setGeometry (2, height, width-2, 1);
}
if ( ! (is_text_dialog || isNewFont()) )
drawBorder();
vbar->resize();
hbar->resize();
}
if ( isMonochron() )
setReverse(false);
//----------------------------------------------------------------------
void FTextView::setPosition (int pos)
{
int last_line = int(getRows());
if ( vbar->isVisible() )
vbar->redraw();
if ( pos < 0 || pos > last_line - getHeight() + 2 )
return;
if ( hbar->isVisible() )
hbar->redraw();
yoffset = pos;
updateVTerm(true);
if ( isVisible() )
drawText();
if ( hasFocus() && statusBar() )
{
FString msg = getStatusbarMessage();
FString curMsg = statusBar()->getMessage();
vbar->setValue (yoffset);
if ( curMsg != msg )
{
updateVTerm(false);
statusBar()->setMessage(msg);
statusBar()->drawMessage();
updateVTerm(true);
}
}
if ( vbar->isVisible() )
vbar->drawBar();
setCursorPos (getWidth(), getHeight());
updateTerminal();
flush_out();
}
//----------------------------------------------------------------------
void FTextView::drawText()
void FTextView::setText (const FString& str)
{
uInt start, end;
if ( data.empty() || getHeight() <= 2 || getWidth() <= 2 )
return;
start = 0;
end = uInt(getHeight() + nf_offset - 2);
if ( end > getRows() )
end = getRows();
updateVTerm(false);
setColor();
if ( isMonochron() )
setReverse(true);
for (uInt y=start; y < end; y++)
{
uInt i, len;
FString line;
const wchar_t* line_str;
setPrintPos (2, 2 - nf_offset + int(y));
line = data[y+uInt(yoffset)].mid ( uInt(1 + xoffset)
, uInt(getWidth() - nf_offset - 2) );
line_str = line.wc_str();
len = line.getLength();
for (i=0; i < len; i++)
{
wchar_t ch = line_str[i];
bool utf8 = (Encoding == fc::UTF8) ? true : false;
// only printable and 1 column per character
if ( ( (utf8 && std::iswprint(wint_t(ch)))
|| (!utf8 && ch < 256 && std::isprint(ch)) )
&& wcwidth(ch) == 1 )
{
print (ch);
}
else
print ('.');
}
for (; i < uInt(getWidth() - nf_offset - 2); i++)
print (' ');
}
if ( isMonochron() )
setReverse(false);
updateVTerm(true);
clear();
insert(str, -1);
}
//----------------------------------------------------------------------
void FTextView::processChanged()
{
emitCallback("changed");
}
// protected methods of FTextView
//----------------------------------------------------------------------
void FTextView::adjustSize()
{
FWidget::adjustSize();
int width = getWidth();
int height = getHeight();
int last_line = int(getRows());
int max_width = int(maxLineWidth);
if ( xoffset >= max_width - width - nf_offset )
xoffset = max_width - width - nf_offset - 1;
if ( xoffset < 0 )
xoffset = 0;
if ( yoffset > last_line - height - nf_offset + 2 )
yoffset = last_line - height - nf_offset + 2;
if ( yoffset < 0 )
yoffset = 0;
vbar->setMaximum (last_line - height + 2 - nf_offset);
vbar->setPageSize (last_line, height - 2 + nf_offset);
vbar->setX (width);
vbar->setHeight (height - 2 + nf_offset, false);
vbar->setValue (yoffset);
vbar->resize();
hbar->setMaximum (max_width - width + nf_offset + 2);
hbar->setPageSize (max_width, width - nf_offset - 2);
hbar->setY (height);
hbar->setWidth (width - 2, false);
hbar->setValue (xoffset);
hbar->resize();
if ( last_line < height + nf_offset - 1 )
vbar->hide();
else
vbar->setVisible();
if ( max_width < width - nf_offset - 1 )
hbar->hide();
else
hbar->setVisible();
}
// public methods of FTextView
//----------------------------------------------------------------------
void FTextView::hide()
{
@ -275,6 +162,132 @@ void FTextView::hide()
flush_out();
}
//----------------------------------------------------------------------
void FTextView::append (const FString& str)
{
insert(str, -1);
}
//----------------------------------------------------------------------
void FTextView::insert (const FString& str, int pos)
{
stringLines::iterator iter;
stringLines text_split;
FString s;
uLong end;
if ( pos < 0 || pos >= int(getRows()) )
pos = int(getRows());
if ( str.isEmpty() )
s = "\n";
else
s = FString(str).rtrim().expandTabs(getTabstop());
iter = data.begin();
text_split = s.split("\r\n");
end = text_split.size();
for (uInt i=0; i < end; i++)
{
uInt len;
text_split[i] = text_split[i].removeBackspaces()
.removeDel()
.replaceControlCodes()
.rtrim();
len = text_split[i].getLength();
if ( len > maxLineWidth )
{
maxLineWidth = len;
if ( len > uInt(getWidth() - nf_offset - 2) )
{
hbar->setMaximum (int(maxLineWidth) - getWidth() + nf_offset + 2);
hbar->setPageSize (int(maxLineWidth), getWidth() - nf_offset - 2);
hbar->calculateSliderValues();
if ( ! hbar->isVisible() )
hbar->setVisible();
}
}
}
data.insert (iter + pos, text_split.begin(), text_split.end());
vbar->setMaximum (int(getRows()) - getHeight() + 2 - nf_offset);
vbar->setPageSize (int(getRows()), getHeight() - 2 + nf_offset);
vbar->calculateSliderValues();
if ( ! vbar->isVisible() && int(getRows()) >= getHeight() + nf_offset - 1 )
vbar->setVisible();
if ( vbar->isVisible() && int(getRows()) < getHeight() + nf_offset - 1 )
vbar->hide();
processChanged();
}
//----------------------------------------------------------------------
void FTextView::replaceRange (const FString& str, int start, int end)
{
stringLines::iterator iter;
if ( start > end )
return;
if ( start < 0 || start >= int(getRows()) )
return;
if ( end < 0 || end >= int(getRows()) )
return;
iter = data.begin();
data.erase (iter+start, iter+end+1);
if ( ! str.isNull() )
insert(str, start);
}
//----------------------------------------------------------------------
void FTextView::clear()
{
int size;
char* blank;
data.clear();
xoffset = 0;
yoffset = 0;
maxLineWidth = 0;
vbar->setMinimum(0);
vbar->setValue(0);
vbar->hide();
hbar->setMinimum(0);
hbar->setValue(0);
hbar->hide();
// clear list from screen
setColor();
size = getWidth() - 2;
if ( size < 0 )
return;
blank = new char[size+1];
std::memset(blank, ' ', uLong(size));
blank[size] = '\0';
for (int y=0; y < getHeight() + nf_offset - 2; y++)
{
setPrintPos (2, 2 - nf_offset + y);
print (blank);
}
delete[] blank;
processChanged();
}
//----------------------------------------------------------------------
void FTextView::onKeyPress (FKeyEvent* ev)
{
@ -388,8 +401,8 @@ void FTextView::onMouseDown (FMouseEvent* ev)
if ( focused_widget )
focused_widget->redraw();
if ( statusBar() )
statusBar()->drawMessage();
if ( getStatusBar() )
getStatusBar()->drawMessage();
}
parent = getParentWidget();
@ -519,20 +532,221 @@ void FTextView::onWheel (FWheelEvent* ev)
//----------------------------------------------------------------------
void FTextView::onFocusIn (FFocusEvent*)
{
if ( statusBar() )
statusBar()->drawMessage();
if ( getStatusBar() )
getStatusBar()->drawMessage();
}
//----------------------------------------------------------------------
void FTextView::onFocusOut (FFocusEvent*)
{
if ( statusBar() )
if ( getStatusBar() )
{
statusBar()->clearMessage();
statusBar()->drawMessage();
getStatusBar()->clearMessage();
getStatusBar()->drawMessage();
}
}
// protected methods of FTextView
//----------------------------------------------------------------------
void FTextView::adjustSize()
{
FWidget::adjustSize();
int width = getWidth();
int height = getHeight();
int last_line = int(getRows());
int max_width = int(maxLineWidth);
if ( xoffset >= max_width - width - nf_offset )
xoffset = max_width - width - nf_offset - 1;
if ( xoffset < 0 )
xoffset = 0;
if ( yoffset > last_line - height - nf_offset + 2 )
yoffset = last_line - height - nf_offset + 2;
if ( yoffset < 0 )
yoffset = 0;
vbar->setMaximum (last_line - height + 2 - nf_offset);
vbar->setPageSize (last_line, height - 2 + nf_offset);
vbar->setX (width);
vbar->setHeight (height - 2 + nf_offset, false);
vbar->setValue (yoffset);
vbar->resize();
hbar->setMaximum (max_width - width + nf_offset + 2);
hbar->setPageSize (max_width, width - nf_offset - 2);
hbar->setY (height);
hbar->setWidth (width - 2, false);
hbar->setValue (xoffset);
hbar->resize();
if ( last_line < height + nf_offset - 1 )
vbar->hide();
else
vbar->setVisible();
if ( max_width < width - nf_offset - 1 )
hbar->hide();
else
hbar->setVisible();
}
// private methods of FTextView
//----------------------------------------------------------------------
void FTextView::init()
{
nf_offset = isNewFont() ? 1 : 0;
setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg);
vbar = new FScrollbar(fc::vertical, this);
vbar->setMinimum(0);
vbar->setValue(0);
vbar->hide();
hbar = new FScrollbar(fc::horizontal, this);
hbar->setMinimum(0);
hbar->setValue(0);
hbar->hide();
vbar->addCallback
(
"change-value",
_METHOD_CALLBACK (this, &FTextView::cb_VBarChange)
);
hbar->addCallback
(
"change-value",
_METHOD_CALLBACK (this, &FTextView::cb_HBarChange)
);
}
//----------------------------------------------------------------------
void FTextView::draw()
{
FWidget* parent = getParentWidget();
bool is_text_dialog;
updateVTerm(false);
setColor();
if ( isMonochron() )
setReverse(true);
if ( parent
&& parent->isDialogWidget()
&& isPaddingIgnored()
&& getGeometry() == FRect ( 1
, 2
, parent->getWidth()
, parent->getHeight() - 1) )
{
is_text_dialog = true;
}
else
is_text_dialog = false;
if ( ! (is_text_dialog || isNewFont()) )
drawBorder();
if ( isMonochron() )
setReverse(false);
if ( vbar->isVisible() )
vbar->redraw();
if ( hbar->isVisible() )
hbar->redraw();
updateVTerm(true);
drawText();
if ( hasFocus() && getStatusBar() )
{
FString msg = getStatusbarMessage();
FString curMsg = getStatusBar()->getMessage();
if ( curMsg != msg )
{
updateVTerm(false);
getStatusBar()->setMessage(msg);
getStatusBar()->drawMessage();
updateVTerm(true);
}
}
setCursorPos (getWidth(), getHeight());
updateTerminal();
flush_out();
}
//----------------------------------------------------------------------
void FTextView::drawText()
{
uInt start, end;
if ( data.empty() || getHeight() <= 2 || getWidth() <= 2 )
return;
start = 0;
end = uInt(getHeight() + nf_offset - 2);
if ( end > getRows() )
end = getRows();
updateVTerm(false);
setColor();
if ( isMonochron() )
setReverse(true);
for (uInt y=start; y < end; y++)
{
uInt i, len;
FString line;
const wchar_t* line_str;
setPrintPos (2, 2 - nf_offset + int(y));
line = data[y+uInt(yoffset)].mid ( uInt(1 + xoffset)
, uInt(getWidth() - nf_offset - 2) );
line_str = line.wc_str();
len = line.getLength();
for (i=0; i < len; i++)
{
wchar_t ch = line_str[i];
bool utf8 = (Encoding == fc::UTF8) ? true : false;
// only printable and 1 column per character
if ( ( (utf8 && std::iswprint(wint_t(ch)))
|| (!utf8 && ch < 256 && std::isprint(ch)) )
&& wcwidth(ch) == 1 )
{
print (ch);
}
else
print ('.');
}
for (; i < uInt(getWidth() - nf_offset - 2); i++)
print (' ');
}
if ( isMonochron() )
setReverse(false);
updateVTerm(true);
}
//----------------------------------------------------------------------
void FTextView::processChanged()
{
emitCallback("changed");
}
//----------------------------------------------------------------------
void FTextView::cb_VBarChange (FWidget*, void*)
{
@ -716,215 +930,3 @@ void FTextView::cb_HBarChange (FWidget*, void*)
updateTerminal();
}
}
//----------------------------------------------------------------------
void FTextView::setGeometry (int x, int y, int w, int h, bool adjust)
{
FWidget::setGeometry(x, y, w, h, adjust);
int width = getWidth();
int height = getHeight();
if ( isNewFont() )
{
vbar->setGeometry (width, 1, 2, height-1);
hbar->setGeometry (1, height, width-2, 1);
}
else
{
vbar->setGeometry (width, 2, 1, height-2);
hbar->setGeometry (2, height, width-2, 1);
}
vbar->resize();
hbar->resize();
}
//----------------------------------------------------------------------
void FTextView::setPosition (int pos)
{
int last_line = int(getRows());
if ( pos < 0 || pos > last_line - getHeight() + 2 )
return;
yoffset = pos;
if ( isVisible() )
drawText();
vbar->setValue (yoffset);
if ( vbar->isVisible() )
vbar->drawBar();
flush_out();
}
//----------------------------------------------------------------------
void FTextView::setText (const FString& str)
{
clear();
insert(str, -1);
}
//----------------------------------------------------------------------
FString FTextView::getText() const
{
uInt len, rows, idx;
if ( data.empty() )
return FString("");
len = 0;
rows = getRows();
for (uInt i=0 ; i < rows; i++)
len += data[i].getLength() + 1;
FString s(len + 1);
idx = 0;
for (uInt i=0 ; i < rows; i++)
{
const wchar_t* p = data[i].wc_str();
if ( p )
{
while ( (s[idx++] = *p++) != 0 );
s[idx-1] = '\n';
}
else
{
s[idx++] = '\n';
}
}
s[idx-1] = 0;
return s;
}
//----------------------------------------------------------------------
void FTextView::append (const FString& str)
{
insert(str, -1);
}
//----------------------------------------------------------------------
void FTextView::insert (const FString& str, int pos)
{
stringLines::iterator iter;
stringLines text_split;
FString s;
uLong end;
if ( pos < 0 || pos >= int(getRows()) )
pos = int(getRows());
if ( str.isEmpty() )
s = "\n";
else
s = FString(str).rtrim().expandTabs(getTabstop());
iter = data.begin();
text_split = s.split("\r\n");
end = text_split.size();
for (uInt i=0; i < end; i++)
{
uInt len;
text_split[i] = text_split[i].removeBackspaces()
.removeDel()
.replaceControlCodes()
.rtrim();
len = text_split[i].getLength();
if ( len > maxLineWidth )
{
maxLineWidth = len;
if ( len > uInt(getWidth() - nf_offset - 2) )
{
hbar->setMaximum (int(maxLineWidth) - getWidth() + nf_offset + 2);
hbar->setPageSize (int(maxLineWidth), getWidth() - nf_offset - 2);
hbar->calculateSliderValues();
if ( ! hbar->isVisible() )
hbar->setVisible();
}
}
}
data.insert (iter + pos, text_split.begin(), text_split.end());
vbar->setMaximum (int(getRows()) - getHeight() + 2 - nf_offset);
vbar->setPageSize (int(getRows()), getHeight() - 2 + nf_offset);
vbar->calculateSliderValues();
if ( ! vbar->isVisible() && int(getRows()) >= getHeight() + nf_offset - 1 )
vbar->setVisible();
if ( vbar->isVisible() && int(getRows()) < getHeight() + nf_offset - 1 )
vbar->hide();
processChanged();
}
//----------------------------------------------------------------------
void FTextView::replaceRange (const FString& str, int start, int end)
{
stringLines::iterator iter;
if ( start > end )
return;
if ( start < 0 || start >= int(getRows()) )
return;
if ( end < 0 || end >= int(getRows()) )
return;
iter = data.begin();
data.erase (iter+start, iter+end+1);
if ( ! str.isNull() )
insert(str, start);
}
//----------------------------------------------------------------------
void FTextView::clear()
{
int size;
char* blank;
data.clear();
xoffset = 0;
yoffset = 0;
maxLineWidth = 0;
vbar->setMinimum(0);
vbar->setValue(0);
vbar->hide();
hbar->setMinimum(0);
hbar->setValue(0);
hbar->hide();
// clear list from screen
setColor();
size = getWidth() - 2;
if ( size < 0 )
return;
blank = new char[size+1];
std::memset(blank, ' ', uLong(size));
blank[size] = '\0';
for (int y=0; y < getHeight() + nf_offset - 2; y++)
{
setPrintPos (2, 2 - nf_offset + y);
print (blank);
}
delete[] blank;
processChanged();
}

View File

@ -44,42 +44,39 @@
class FTextView : public FWidget
{
private:
typedef std::vector<FString> stringLines;
stringLines data;
FScrollbar* vbar;
FScrollbar* hbar;
int xoffset;
int yoffset;
int nf_offset;
uInt maxLineWidth;
private:
// Disable copy constructor
FTextView (const FTextView&);
// Disable assignment operator (=)
FTextView& operator = (const FTextView&);
void init();
void draw();
void drawText();
void processChanged();
// Callback methods
void cb_VBarChange (FWidget*, void*);
void cb_HBarChange (FWidget*, void*);
protected:
void adjustSize();
public:
// Using-declarations
using FWidget::setGeometry;
// Typedef
typedef std::vector<FString> stringLines;
// Constructor
explicit FTextView (FWidget* = 0);
// Destructor
~FTextView();
// Accessors
const char* getClassName() const;
uInt getColumns() const;
uInt getRows() const;
FString getText() const;
stringLines getLines() const;
// Mutators
void setGeometry (int, int, int, int, bool = true);
void setPosition (int);
void setText (const FString&);
// Methods
void hide();
void append (const FString&);
void insert (const FString&, int);
void replaceRange (const FString&, int, int);
void deleteRange (int, int);
void deleteLine (int);
void clear();
// Event handlers
void onKeyPress (FKeyEvent*);
@ -90,21 +87,35 @@ class FTextView : public FWidget
void onFocusIn (FFocusEvent*);
void onFocusOut (FFocusEvent*);
// make every setGeometry from FWidget available
using FWidget::setGeometry;
void setGeometry (int, int, int, int, bool = true);
uInt getColumns() const;
uInt getRows() const;
void setPosition (int);
void setText (const FString&);
FString getText() const;
void append (const FString&);
void insert (const FString&, int);
void replaceRange (const FString&, int, int);
void deleteRange (int, int);
void deleteLine (int);
stringLines getLines() const;
void clear();
protected:
// Method
void adjustSize();
private:
// Disable copy constructor
FTextView (const FTextView&);
// Disable assignment operator (=)
FTextView& operator = (const FTextView&);
// Methods
void init();
void draw();
void drawText();
void processChanged();
// Callback methods
void cb_VBarChange (FWidget*, void*);
void cb_HBarChange (FWidget*, void*);
// Data Members
stringLines data;
FScrollbar* vbar;
FScrollbar* hbar;
int xoffset;
int yoffset;
int nf_offset;
uInt maxLineWidth;
};
#pragma pack(pop)
@ -122,6 +133,10 @@ inline uInt FTextView::getColumns() const
inline uInt FTextView::getRows() const
{ return uInt(data.size()); }
//----------------------------------------------------------------------
inline FTextView::stringLines FTextView::getLines() const
{ return data; }
//----------------------------------------------------------------------
inline void FTextView::deleteRange (int start, int end)
{ replaceRange (FString(), start, end); }
@ -130,8 +145,4 @@ inline void FTextView::deleteRange (int start, int end)
inline void FTextView::deleteLine (int pos)
{ deleteRange (pos, pos); }
//----------------------------------------------------------------------
inline FTextView::stringLines FTextView::getLines() const
{ return data; }
#endif // _FTEXTVIEW_H

View File

@ -15,12 +15,12 @@
//----------------------------------------------------------------------
FToggleButton::FToggleButton(FWidget* parent)
: FWidget(parent)
, focus_inside_group(true)
, text()
, checked(false)
, label_offset_pos(0)
, button_width(0)
, button_group(0)
, focus_inside_group(true)
, text()
{
init();
@ -29,20 +29,20 @@ FToggleButton::FToggleButton(FWidget* parent)
{
setGroup( static_cast<FButtonGroup*>(parent) );
if ( group() )
group()->insert(this); // insert into button group
if ( getGroup() )
getGroup()->insert(this); // insert into button group
}
}
//----------------------------------------------------------------------
FToggleButton::FToggleButton (const FString& txt, FWidget* parent)
: FWidget(parent)
, focus_inside_group(true)
, text()
, checked(false)
, label_offset_pos(0)
, button_width(0)
, button_group(0)
, focus_inside_group(true)
, text()
{
init();
setText(txt);
@ -52,8 +52,8 @@ FToggleButton::FToggleButton (const FString& txt, FWidget* parent)
{
setGroup( static_cast<FButtonGroup*>(parent) );
if ( group() )
group()->insert( this ); // insert into button group
if ( getGroup() )
getGroup()->insert( this ); // insert into button group
}
}
@ -62,23 +62,43 @@ FToggleButton::~FToggleButton() // destructor
{
delAccelerator();
if ( group() )
group()->remove(this);
if ( getGroup() )
getGroup()->remove(this);
}
// private methods of FToggleButton
// public methods of FToggleButton
//----------------------------------------------------------------------
void FToggleButton::init()
void FToggleButton::setGeometry (int x, int y, int w, int h, bool adjust)
{
setGeometry (1, 1, 4, 1, false); // initialize geometry values
int min_width = button_width + int(text.getLength());
if ( hasFocus() )
flags = fc::focus;
if ( w < min_width )
w = min_width;
if ( isEnabled() )
FWidget::setGeometry(x, y, w, h, adjust);
}
//----------------------------------------------------------------------
bool FToggleButton::setNoUnderline (bool on)
{
if ( on )
flags |= fc::no_underline;
else
flags &= ~fc::no_underline;
return on;
}
//----------------------------------------------------------------------
bool FToggleButton::setEnable (bool on)
{
FWidget::setEnable(on);
if ( on )
{
flags |= fc::active;
setHotkeyAccelerator();
if ( hasFocus() )
{
@ -91,17 +111,265 @@ void FToggleButton::init()
setBackgroundColor (wc.toggle_button_active_bg);
}
}
else // inactive
else
{
setForegroundColor (wc.label_inactive_fg);
setBackgroundColor (wc.label_inactive_bg);
flags &= ~fc::active;
delAccelerator();
setForegroundColor (wc.toggle_button_inactive_fg);
setBackgroundColor (wc.toggle_button_inactive_bg);
}
return on;
}
//----------------------------------------------------------------------
bool FToggleButton::setFocus (bool on)
{
FWidget::setFocus(on);
if ( on )
{
flags |= fc::focus;
if ( isEnabled() )
{
if ( isRadioButton() )
focus_inside_group = false;
setForegroundColor (wc.toggle_button_active_focus_fg);
setBackgroundColor (wc.toggle_button_active_focus_bg);
if ( getStatusBar() )
{
FString msg = getStatusbarMessage();
FString curMsg = getStatusBar()->getMessage();
if ( curMsg != msg )
getStatusBar()->setMessage(msg);
}
}
}
else
{
flags &= ~fc::focus;
if ( isEnabled() )
{
setForegroundColor (wc.toggle_button_active_fg);
setBackgroundColor (wc.toggle_button_active_bg);
if ( getStatusBar() )
getStatusBar()->clearMessage();
}
}
return on;
}
//----------------------------------------------------------------------
bool FToggleButton::setChecked (bool on)
{
if ( checked != on )
{
checked = on;
processToggle();
}
return checked;
}
//----------------------------------------------------------------------
void FToggleButton::setText (FString txt)
{
text = txt;
setWidth(button_width + int(text.getLength()));
if ( isEnabled() )
{
delAccelerator();
setHotkeyAccelerator();
}
}
//----------------------------------------------------------------------
void FToggleButton::setGroup (FButtonGroup* btngroup)
void FToggleButton::hide()
{
button_group = btngroup;
int size;
short fg, bg;
char* blank;
FWidget* parent_widget = getParentWidget();
FWidget::hide();
if ( parent_widget )
{
fg = parent_widget->getForegroundColor();
bg = parent_widget->getBackgroundColor();
}
else
{
fg = wc.dialog_fg;
bg = wc.dialog_bg;
}
setColor (fg, bg);
size = getWidth();
if ( size < 0 )
return;
blank = new char[size+1];
std::memset(blank, ' ', uLong(size));
blank[size] = '\0';
setPrintPos (1, 1);
print (blank);
delete[] blank;
}
//----------------------------------------------------------------------
void FToggleButton::onMouseDown (FMouseEvent* ev)
{
if ( ev->getButton() != fc::LeftButton )
return;
if ( hasFocus() )
return;
FWidget* focused_widget = getFocusWidget();
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
setFocus();
if ( focused_widget )
focused_widget->redraw();
redraw();
if ( getStatusBar() )
{
getStatusBar()->drawMessage();
updateTerminal();
flush_out();
}
}
//----------------------------------------------------------------------
void FToggleButton::onMouseUp (FMouseEvent* ev)
{
if ( ev->getButton() != fc::LeftButton )
return;
if ( ! getTermGeometry().contains(ev->getTermPos()) )
return;
if ( isRadioButton() )
{
if ( ! checked )
{
checked = true;
processToggle();
}
}
else
{
checked = not checked;
processToggle();
}
redraw();
processClick();
}
//----------------------------------------------------------------------
void FToggleButton::onAccel (FAccelEvent* ev)
{
if ( ! isEnabled() )
return;
if ( ! hasFocus() )
{
FWidget* focused_widget = static_cast<FWidget*>(ev->focusedWidget());
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
setFocus();
if ( focused_widget )
focused_widget->redraw();
}
if ( isRadioButton() )
{
if ( ! checked )
{
checked = true;
processToggle();
}
}
else
{
checked = not checked;
processToggle();
}
redraw();
if ( getStatusBar() )
{
getStatusBar()->drawMessage();
updateTerminal();
flush_out();
}
processClick();
ev->accept();
}
//----------------------------------------------------------------------
void FToggleButton::onFocusIn (FFocusEvent*)
{
if ( getStatusBar() )
getStatusBar()->drawMessage();
}
//----------------------------------------------------------------------
void FToggleButton::onFocusOut (FFocusEvent* out_ev)
{
if ( getStatusBar() )
{
getStatusBar()->clearMessage();
getStatusBar()->drawMessage();
}
if ( ! getGroup() )
return;
if ( ! focus_inside_group && isRadioButton() )
{
focus_inside_group = true;
out_ev->ignore();
if ( out_ev->getFocusType() == fc::FocusNextWidget )
getGroup()->focusNextChild();
if ( out_ev->getFocusType() == fc::FocusPreviousWidget )
getGroup()->focusPrevChild();
redraw();
}
else if ( this == getGroup()->getLastButton()
&& out_ev->getFocusType() == fc::FocusNextWidget )
{
out_ev->ignore();
getGroup()->focusNextChild();
redraw();
}
else if ( this == getGroup()->getFirstButton()
&& out_ev->getFocusType() == fc::FocusPreviousWidget )
{
out_ev->ignore();
getGroup()->focusPrevChild();
redraw();
}
}
@ -153,20 +421,34 @@ void FToggleButton::setHotkeyAccelerator()
delAccelerator();
}
//----------------------------------------------------------------------
bool FToggleButton::isRadioButton() const
{
return ( std::strcmp ( getClassName()
, const_cast<char*>("FRadioButton") ) == 0 );
}
//----------------------------------------------------------------------
bool FToggleButton::isCheckboxButton() const
{
return ( std::strcmp ( getClassName()
, const_cast<char*>("FCheckBox") ) == 0 );
}
//----------------------------------------------------------------------
void FToggleButton::draw()
{
bool isFocus = ((flags & fc::focus) != 0);
if ( isFocus && statusBar() )
if ( isFocus && getStatusBar() )
{
FString msg = getStatusbarMessage();
FString curMsg = statusBar()->getMessage();
FString curMsg = getStatusBar()->getMessage();
if ( curMsg != msg )
{
statusBar()->setMessage(msg);
statusBar()->drawMessage();
getStatusBar()->setMessage(msg);
getStatusBar()->drawMessage();
}
}
@ -267,26 +549,6 @@ void FToggleButton::processToggle()
emitCallback("toggled");
}
//----------------------------------------------------------------------
FButtonGroup* FToggleButton::group() const
{
return button_group;
}
//----------------------------------------------------------------------
bool FToggleButton::isRadioButton() const
{
return ( std::strcmp ( getClassName()
, const_cast<char*>("FRadioButton") ) == 0 );
}
//----------------------------------------------------------------------
bool FToggleButton::isCheckboxButton() const
{
return ( std::strcmp ( getClassName()
, const_cast<char*>("FCheckBox") ) == 0 );
}
//----------------------------------------------------------------------
void FToggleButton::onKeyPress (FKeyEvent* ev)
{
@ -345,73 +607,24 @@ void FToggleButton::onKeyPress (FKeyEvent* ev)
}
// public methods of FToggleButton
// private methods of FToggleButton
//----------------------------------------------------------------------
void FToggleButton::hide()
void FToggleButton::setGroup (FButtonGroup* btngroup)
{
int size;
short fg, bg;
char* blank;
FWidget* parent_widget = getParentWidget();
FWidget::hide();
if ( parent_widget )
{
fg = parent_widget->getForegroundColor();
bg = parent_widget->getBackgroundColor();
}
else
{
fg = wc.dialog_fg;
bg = wc.dialog_bg;
}
setColor (fg, bg);
size = getWidth();
if ( size < 0 )
return;
blank = new char[size+1];
std::memset(blank, ' ', uLong(size));
blank[size] = '\0';
setPrintPos (1, 1);
print (blank);
delete[] blank;
button_group = btngroup;
}
//----------------------------------------------------------------------
void FToggleButton::setGeometry (int x, int y, int w, int h, bool adjust)
void FToggleButton::init()
{
int min_width = button_width + int(text.getLength());
setGeometry (1, 1, 4, 1, false); // initialize geometry values
if ( w < min_width )
w = min_width;
if ( hasFocus() )
flags = fc::focus;
FWidget::setGeometry(x, y, w, h, adjust);
}
//----------------------------------------------------------------------
bool FToggleButton::setNoUnderline (bool on)
{
if ( on )
flags |= fc::no_underline;
else
flags &= ~fc::no_underline;
return on;
}
//----------------------------------------------------------------------
bool FToggleButton::setEnable (bool on)
{
FWidget::setEnable(on);
if ( on )
if ( isEnabled() )
{
flags |= fc::active;
setHotkeyAccelerator();
if ( hasFocus() )
{
@ -424,228 +637,9 @@ bool FToggleButton::setEnable (bool on)
setBackgroundColor (wc.toggle_button_active_bg);
}
}
else
else // inactive
{
flags &= ~fc::active;
delAccelerator();
setForegroundColor (wc.toggle_button_inactive_fg);
setBackgroundColor (wc.toggle_button_inactive_bg);
}
return on;
}
//----------------------------------------------------------------------
bool FToggleButton::setFocus (bool on)
{
FWidget::setFocus(on);
if ( on )
{
flags |= fc::focus;
if ( isEnabled() )
{
if ( isRadioButton() )
focus_inside_group = false;
setForegroundColor (wc.toggle_button_active_focus_fg);
setBackgroundColor (wc.toggle_button_active_focus_bg);
if ( statusBar() )
{
FString msg = getStatusbarMessage();
FString curMsg = statusBar()->getMessage();
if ( curMsg != msg )
statusBar()->setMessage(msg);
}
}
}
else
{
flags &= ~fc::focus;
if ( isEnabled() )
{
setForegroundColor (wc.toggle_button_active_fg);
setBackgroundColor (wc.toggle_button_active_bg);
if ( statusBar() )
statusBar()->clearMessage();
}
}
return on;
}
//----------------------------------------------------------------------
void FToggleButton::onMouseDown (FMouseEvent* ev)
{
if ( ev->getButton() != fc::LeftButton )
return;
if ( hasFocus() )
return;
FWidget* focused_widget = getFocusWidget();
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
setFocus();
if ( focused_widget )
focused_widget->redraw();
redraw();
if ( statusBar() )
{
statusBar()->drawMessage();
updateTerminal();
flush_out();
}
}
//----------------------------------------------------------------------
void FToggleButton::onMouseUp (FMouseEvent* ev)
{
if ( ev->getButton() != fc::LeftButton )
return;
if ( ! getTermGeometry().contains(ev->getTermPos()) )
return;
if ( isRadioButton() )
{
if ( ! checked )
{
checked = true;
processToggle();
}
}
else
{
checked = not checked;
processToggle();
}
redraw();
processClick();
}
//----------------------------------------------------------------------
void FToggleButton::onAccel (FAccelEvent* ev)
{
if ( ! isEnabled() )
return;
if ( ! hasFocus() )
{
FWidget* focused_widget = static_cast<FWidget*>(ev->focusedWidget());
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
setFocus();
if ( focused_widget )
focused_widget->redraw();
}
if ( isRadioButton() )
{
if ( ! checked )
{
checked = true;
processToggle();
}
}
else
{
checked = not checked;
processToggle();
}
redraw();
if ( statusBar() )
{
statusBar()->drawMessage();
updateTerminal();
flush_out();
}
processClick();
ev->accept();
}
//----------------------------------------------------------------------
void FToggleButton::onFocusIn (FFocusEvent*)
{
if ( statusBar() )
statusBar()->drawMessage();
}
//----------------------------------------------------------------------
void FToggleButton::onFocusOut (FFocusEvent* out_ev)
{
if ( statusBar() )
{
statusBar()->clearMessage();
statusBar()->drawMessage();
}
if ( ! group() )
return;
if ( ! focus_inside_group && isRadioButton() )
{
focus_inside_group = true;
out_ev->ignore();
if ( out_ev->getFocusType() == fc::FocusNextWidget )
group()->focusNextChild();
if ( out_ev->getFocusType() == fc::FocusPreviousWidget )
group()->focusPrevChild();
redraw();
}
else if ( this == group()->getLastButton()
&& out_ev->getFocusType() == fc::FocusNextWidget )
{
out_ev->ignore();
group()->focusNextChild();
redraw();
}
else if ( this == group()->getFirstButton()
&& out_ev->getFocusType() == fc::FocusPreviousWidget )
{
out_ev->ignore();
group()->focusPrevChild();
redraw();
}
}
//----------------------------------------------------------------------
bool FToggleButton::setChecked (bool on)
{
if ( checked != on )
{
checked = on;
processToggle();
}
return checked;
}
//----------------------------------------------------------------------
void FToggleButton::setText (FString txt)
{
text = txt;
setWidth(button_width + int(text.getLength()));
if ( isEnabled() )
{
delAccelerator();
setHotkeyAccelerator();
setForegroundColor (wc.label_inactive_fg);
setBackgroundColor (wc.label_inactive_bg);
}
}

View File

@ -43,58 +43,23 @@ class FButtonGroup;
class FToggleButton : public FWidget
{
private:
bool focus_inside_group;
protected:
FString text;
bool checked;
int label_offset_pos;
int button_width; // plus margin spaces
FButtonGroup* button_group;
private:
// Disable copy constructor
FToggleButton (const FToggleButton&);
// Disable assignment operator (=)
FToggleButton& operator = (const FToggleButton&);
void init();
friend class FButtonGroup;
void setGroup (FButtonGroup*);
protected:
virtual void draw();
uChar getHotkey();
void setHotkeyAccelerator();
void drawLabel();
void processClick();
void processToggle();
FButtonGroup* group() const;
bool isRadioButton() const;
bool isCheckboxButton() const;
virtual void onKeyPress (FKeyEvent*);
public:
// Using-declaration
using FWidget::setGeometry;
// Constructors
explicit FToggleButton (FWidget* = 0);
FToggleButton (const FString&, FWidget* = 0);
// Destructor
virtual ~FToggleButton();
// Accessors
virtual const char* getClassName() const;
void hide();
// make every setGeometry from FWidget available
using FWidget::setGeometry;
FString& getText();
// Mutators
void setGeometry (int, int, int, int, bool = true);
// Event handlers
void onMouseDown (FMouseEvent*);
void onMouseUp (FMouseEvent*);
void onAccel (FAccelEvent*);
void onFocusIn (FFocusEvent*);
void onFocusOut (FFocusEvent*);
bool setNoUnderline (bool);
bool setNoUnderline();
bool unsetNoUnderline();
@ -108,10 +73,67 @@ class FToggleButton : public FWidget
bool setChecked (bool);
bool setChecked();
bool unsetChecked();
virtual void setText (const FString);
// Inquiries
bool isChecked();
virtual void setText (const FString);
FString& getText();
// Methods
void hide();
// Event handlers
void onMouseDown (FMouseEvent*);
void onMouseUp (FMouseEvent*);
void onAccel (FAccelEvent*);
void onFocusIn (FFocusEvent*);
void onFocusOut (FFocusEvent*);
protected:
// Accessor
uChar getHotkey();
FButtonGroup* getGroup() const;
// Mutator
void setHotkeyAccelerator();
// Inquiries
bool isRadioButton() const;
bool isCheckboxButton() const;
// Methods
virtual void draw();
void drawLabel();
void processClick();
void processToggle();
// Event handler
virtual void onKeyPress (FKeyEvent*);
// Data Members
bool checked;
int label_offset_pos;
int button_width; // plus margin spaces
private:
// Disable copy constructor
FToggleButton (const FToggleButton&);
// Disable assignment operator (=)
FToggleButton& operator = (const FToggleButton&);
// Mutator
void setGroup (FButtonGroup*);
// Methods
void init();
// Friend classes
friend class FButtonGroup;
// Data Members
FButtonGroup* button_group;
bool focus_inside_group;
FString text;
};
#pragma pack(pop)
@ -121,6 +143,10 @@ class FToggleButton : public FWidget
inline const char* FToggleButton::getClassName() const
{ return "FToggleButton"; }
//----------------------------------------------------------------------
inline FString& FToggleButton::getText()
{ return text; }
//----------------------------------------------------------------------
inline bool FToggleButton::setNoUnderline()
{ return setNoUnderline(true); }
@ -162,7 +188,7 @@ inline bool FToggleButton::isChecked()
{ return checked; }
//----------------------------------------------------------------------
inline FString& FToggleButton::getText()
{ return text; }
inline FButtonGroup* FToggleButton::getGroup() const
{ return button_group; }
#endif // _FTOGGLEBUTTON_H

View File

@ -54,6 +54,73 @@ FToolTip::~FToolTip() // destructor
}
// public methods of FToolTip
//----------------------------------------------------------------------
void FToolTip::setText (const FString& txt)
{
text = txt;
calculateDimensions();
}
//----------------------------------------------------------------------
void FToolTip::setText (const std::string& txt)
{
FString message_text(txt);
setText (message_text);
}
//----------------------------------------------------------------------
void FToolTip::setText (const char* txt)
{
FString message_text(txt);
setText (message_text);
}
//----------------------------------------------------------------------
void FToolTip::draw()
{
updateVTerm(false);
setColor();
if ( getMaxColor() < 16 )
setBold();
clearArea (vwin);
drawBorder();
for (int i=0; i < int(text_num_lines); i++)
{
setPrintPos (3, 2 + i);
print(text_components[i]);
}
unsetBold();
updateVTerm(true);
}
//----------------------------------------------------------------------
void FToolTip::show()
{
if ( ! isVisible() )
return;
FWindow::show();
}
//----------------------------------------------------------------------
void FToolTip::hide()
{
FWindow::hide();
}
//----------------------------------------------------------------------
void FToolTip::onMouseDown (FMouseEvent*)
{
setClickedWidget(0);
close();
}
// private methods of FToolTip
//----------------------------------------------------------------------
void FToolTip::init()
@ -106,70 +173,3 @@ void FToolTip::adjustSize()
calculateDimensions();
FWindow::adjustSize();
}
// public methods of FToolTip
//----------------------------------------------------------------------
void FToolTip::draw()
{
updateVTerm(false);
setColor();
if ( getMaxColor() < 16 )
setBold();
clearArea (vwin);
drawBorder();
for (int i=0; i < int(text_num_lines); i++)
{
setPrintPos (3, 2 + i);
print(text_components[i]);
}
unsetBold();
updateVTerm(true);
}
//----------------------------------------------------------------------
void FToolTip::show()
{
if ( ! isVisible() )
return;
FWindow::show();
}
//----------------------------------------------------------------------
void FToolTip::hide()
{
FWindow::hide();
}
//----------------------------------------------------------------------
void FToolTip::onMouseDown (FMouseEvent*)
{
setClickedWidget(0);
close();
}
//----------------------------------------------------------------------
void FToolTip::setText (const FString& txt)
{
text = txt;
calculateDimensions();
}
//----------------------------------------------------------------------
void FToolTip::setText (const std::string& txt)
{
FString message_text(txt);
setText( message_text );
}
//----------------------------------------------------------------------
void FToolTip::setText (const char* txt)
{
FString message_text(txt);
setText( message_text );
}

View File

@ -45,40 +45,52 @@
class FToolTip : public FWindow
{
private:
FString text;
FString* text_components;
std::vector<FString> text_split;
uInt max_line_width;
uInt text_num_lines;
private:
// Disable copy constructor
FToolTip (const FToolTip&);
// Disable assignment operator (=)
FToolTip& operator = (const FToolTip&);
void init();
void calculateDimensions();
virtual void adjustSize();
public:
// Constructor
explicit FToolTip (FWidget* = 0);
FToolTip (const FString&, FWidget* = 0);
// Destructor
virtual ~FToolTip ();
// Accessors
const char* getClassName() const;
virtual void draw();
void show();
void hide();
// Event handler
void onMouseDown (FMouseEvent*);
const FString getText() const;
// Mutators
void setText (const FString&);
void setText (const std::string&);
void setText (const char*);
// Methods
virtual void draw();
void show();
void hide();
// Event handler
void onMouseDown (FMouseEvent*);
private:
// Typedef
typedef std::vector<FString> textLines;
// Disable copy constructor
FToolTip (const FToolTip&);
// Disable assignment operator (=)
FToolTip& operator = (const FToolTip&);
// Methods
void init();
void calculateDimensions();
virtual void adjustSize();
// Data Members
FString text;
FString* text_components;
textLines text_split;
uInt max_line_width;
uInt text_num_lines;
};
#pragma pack(pop)

File diff suppressed because it is too large Load Diff

View File

@ -28,10 +28,6 @@
#include "fterm.h"
// Buffer size for character output on the terminal
#define TERMINAL_OUTPUT_BUFFER_SIZE 32768
// class forward declaration
class FWidget;
@ -45,35 +41,8 @@ class FWidget;
class FVTerm : public FObject, public FTerm
{
private:
static std::queue<int>* output_buffer;
static FOptiAttr::char_data term_attribute;
static FOptiAttr::char_data next_attribute;
static FPoint* term_pos; // terminal cursor position
static FTermcap::tcap_map* tcap;
static bool hidden_cursor;
static bool terminal_update_complete;
static bool terminal_update_pending;
static bool force_terminal_update;
static bool stop_terminal_updates;
static bool vterm_updates;
static int skipped_terminal_update;
enum covered_state
{
non_covered,
half_covered,
fully_covered
};
enum character_type
{
overlapped_character,
covered_character
};
protected:
public:
// Typedefs and Enumeration
typedef struct
{
uInt xmin;
@ -81,6 +50,8 @@ class FVTerm : public FObject, public FTerm
uInt trans_count;
} line_changes;
typedef FOptiAttr::char_data char_data;
typedef struct
{
int x_offset;
@ -96,80 +67,123 @@ class FVTerm : public FObject, public FTerm
int input_cursor_visible;
FWidget* widget;
line_changes* changes;
FOptiAttr::char_data* text;
char_data* text;
bool visible;
} term_area;
static term_area* vterm; // virtual terminal
static term_area* vdesktop; // virtual desktop
static term_area* last_area; // last used area
static term_area* active_area; // active area
term_area* print_area; // print area for this object
term_area* vwin; // virtual window
enum covered_state
{
non_covered,
half_covered,
fully_covered
};
protected:
void createArea (const FRect&, const FPoint&, FVTerm::term_area*&);
void createArea (int, int, int, int, int, int, FVTerm::term_area*&);
static void resizeArea (const FRect&, const FPoint&, FVTerm::term_area*);
static void resizeArea (int, int, int, int, int, int, FVTerm::term_area*);
static void removeArea (FVTerm::term_area*&);
static void restoreVTerm (const FRect&);
static void restoreVTerm (int, int, int, int);
static FVTerm::covered_state isCovered (const FPoint&, FVTerm::term_area*);
static FVTerm::covered_state isCovered (int, int, FVTerm::term_area*);
static void updateVTerm (bool);
static void updateVTerm (FVTerm::term_area*);
static bool updateVTermCursor (FVTerm::term_area*);
static bool isInsideArea (int, int, FVTerm::term_area*);
static void setAreaCursor (const FPoint&, bool, FVTerm::term_area*);
static void setAreaCursor (int, int, bool, FVTerm::term_area*);
static void getArea (const FPoint&, FVTerm::term_area*);
static void getArea (int, int, FVTerm::term_area*);
static void getArea (const FRect&, FVTerm::term_area*);
static void getArea (int, int, int, int, FVTerm::term_area*);
static void putArea (const FPoint&, FVTerm::term_area*);
static void putArea (int, int, FVTerm::term_area*);
static void scrollAreaForward (FVTerm::term_area*);
static void scrollAreaReverse (FVTerm::term_area*);
static void clearArea (FVTerm::term_area*);
static FOptiAttr::char_data getCharacter (character_type, const FPoint&, FVTerm*);
static FOptiAttr::char_data getCharacter (character_type, int, int, FVTerm*);
static FOptiAttr::char_data getCoveredCharacter (const FPoint&, FVTerm*);
static FOptiAttr::char_data getCoveredCharacter (int, int, FVTerm*);
static FOptiAttr::char_data getOverlappedCharacter (const FPoint&, FVTerm*);
static FOptiAttr::char_data getOverlappedCharacter (int, int, FVTerm*);
static void startTerminalUpdate();
static void finishTerminalUpdate();
private:
// Disable copy constructor
FVTerm (const FVTerm&);
// Disable assignment operator (=)
FVTerm& operator = (const FVTerm&);
void init();
void finish();
term_area* getPrintArea();
void setPrintArea (term_area*);
public:
// Constructor
explicit FVTerm (FVTerm* = 0);
// Destructor
~FVTerm();
// Accessors
virtual const char* getClassName() const;
static short getTermForegroundColor();
static short getTermBackgroundColor();
term_area* getVWin() const;
FPoint getPrintCursor();
// Mutators
static void setTermXY (register int, register int);
static bool hideCursor (bool);
static bool hideCursor();
static bool showCursor();
static bool isCursorHidden();
void setPrintCursor (const FPoint&);
void setPrintCursor (register int, register int);
void setColor (short, short);
static void setNormal();
static bool setBold (register bool);
static bool setBold();
static bool unsetBold();
static bool setDim (register bool);
static bool setDim();
static bool unsetDim();
static bool setItalic (register bool);
static bool setItalic();
static bool unsetItalic();
static bool setUnderline (register bool);
static bool setUnderline();
static bool unsetUnderline();
static bool setBlink (register bool);
static bool setBlink();
static bool unsetBlink();
static bool setReverse (register bool);
static bool setReverse();
static bool unsetReverse();
static bool setStandout (register bool);
static bool setStandout();
static bool unsetStandout();
static bool setInvisible (register bool);
static bool setInvisible();
static bool unsetInvisible();
static bool setProtected (register bool);
static bool setProtected();
static bool unsetProtected();
static bool setCrossedOut (register bool);
static bool setCrossedOut();
static bool unsetCrossedOut();
static bool setDoubleUnderline (register bool);
static bool setDoubleUnderline();
static bool unsetDoubleUnderline();
static bool setAltCharset (register bool);
static bool setAltCharset();
static bool unsetAltCharset();
static bool setPCcharset (register bool);
static bool setPCcharset();
static bool unsetPCcharset();
static bool setTransparent (register bool);
static bool setTransparent();
static bool unsetTransparent();
static bool setTransShadow (register bool);
static bool setTransShadow();
static bool unsetTransShadow();
static bool setInheritBackground (register bool);
static bool setInheritBackground();
static bool unsetInheritBackground();
// Inquiries
static bool isCursorHidden();
static bool isBold();
static bool isDim();
static bool isItalic();
static bool isUnderline();
static bool isBlink();
static bool isReverse();
static bool isStandout();
static bool isInvisible();
static bool isProtected();
static bool isCrossedOut();
static bool isDoubleUnderline();
static bool isAltCharset();
static bool isPCcharset();
static bool isTransparent();
static bool isTransShadow();
static bool isInheritBackground();
static short getTermForegroundColor();
static short getTermBackgroundColor();
FVTerm::term_area* getVWin() const;
void createVTerm (const FRect&);
void createVTerm (int, int);
static void resizeVTerm (const FRect&);
@ -181,10 +195,6 @@ class FVTerm : public FObject, public FTerm
static void processTerminalUpdate();
static bool isInsideTerminal (int, int);
void setPrintCursor (const FPoint&);
void setPrintCursor (register int, register int);
FPoint getPrintCursor();
int printf (const wchar_t*, ...);
int printf (const char*, ...)
#if defined(__clang__)
@ -194,134 +204,152 @@ class FVTerm : public FObject, public FTerm
#endif
;
int print (const std::wstring&);
int print (FVTerm::term_area*, const std::wstring&);
int print (term_area*, const std::wstring&);
int print (const wchar_t*);
int print (FVTerm::term_area*, const wchar_t*);
int print (term_area*, const wchar_t*);
int print (const char*);
int print (FVTerm::term_area*, const char*);
int print (term_area*, const char*);
int print (const std::string&);
int print (FVTerm::term_area*, const std::string&);
int print (term_area*, const std::string&);
int print (FString&);
int print (FVTerm::term_area*, FString&);
int print (term_area*, FString&);
int print (int);
int print (FVTerm::term_area*, int);
static void newFontChanges (FOptiAttr::char_data*&);
static void charsetChanges (FOptiAttr::char_data*&);
static void appendCharacter (FOptiAttr::char_data*&);
static void appendAttributes (FOptiAttr::char_data*&);
static int appendLowerRight (FOptiAttr::char_data*&);
int print (term_area*, int);
static void newFontChanges (char_data*&);
static void charsetChanges (char_data*&);
static void appendCharacter (char_data*&);
static void appendAttributes (char_data*&);
static int appendLowerRight (char_data*&);
static void appendOutputBuffer (std::string&);
static void appendOutputBuffer (const char*);
static int appendOutputBuffer (int);
static void flush_out();
void setColor (short, short);
static void setNormal();
protected:
// Enumeration
enum character_type
{
overlapped_character,
covered_character
};
static bool setBold (register bool);
static bool setBold();
static bool unsetBold();
static bool isBold();
// Methods
void createArea ( const FRect&
, const FPoint&
, term_area*& );
static bool setDim (register bool);
static bool setDim();
static bool unsetDim();
static bool isDim();
void createArea ( int, int, int, int
, int, int
, term_area*& );
static bool setItalic (register bool);
static bool setItalic();
static bool unsetItalic();
static bool isItalic();
static void resizeArea ( const FRect&
, const FPoint&
, term_area* );
static bool setUnderline (register bool);
static bool setUnderline();
static bool unsetUnderline();
static bool isUnderline();
static void resizeArea ( int, int, int, int
, int, int
, term_area* );
static bool setBlink (register bool);
static bool setBlink();
static bool unsetBlink();
static bool isBlink();
static void removeArea (term_area*&);
static void restoreVTerm (const FRect&);
static void restoreVTerm (int, int, int, int);
static bool setReverse (register bool);
static bool setReverse();
static bool unsetReverse();
static bool isReverse();
static covered_state isCovered ( const FPoint&
, term_area* );
static bool setStandout (register bool);
static bool setStandout();
static bool unsetStandout();
static bool isStandout();
static covered_state isCovered ( int, int
, term_area* );
static bool setInvisible (register bool);
static bool setInvisible();
static bool unsetInvisible();
static bool isInvisible();
static void updateVTerm (bool);
static void updateVTerm (term_area*);
static bool updateVTermCursor (term_area*);
static bool isInsideArea (int, int, term_area*);
static bool setProtected (register bool);
static bool setProtected();
static bool unsetProtected();
static bool isProtected();
static void setAreaCursor ( const FPoint&
, bool, term_area* );
static bool setCrossedOut (register bool);
static bool setCrossedOut();
static bool unsetCrossedOut();
static bool isCrossedOut();
static void setAreaCursor ( int, int
, bool, term_area*);
static bool setDoubleUnderline (register bool);
static bool setDoubleUnderline();
static bool unsetDoubleUnderline();
static bool isDoubleUnderline();
static void getArea (const FPoint&, term_area*);
static void getArea (int, int, term_area*);
static void getArea (const FRect&, term_area*);
static void getArea (int, int, int, int, term_area*);
static void putArea (const FPoint&, term_area*);
static void putArea (int, int, term_area*);
static void scrollAreaForward (term_area*);
static void scrollAreaReverse (term_area*);
static void clearArea (term_area*);
static bool setAltCharset (register bool);
static bool setAltCharset();
static bool unsetAltCharset();
static bool isAltCharset();
static char_data getCharacter ( character_type
, const FPoint&
, FVTerm* );
static bool setPCcharset (register bool);
static bool setPCcharset();
static bool unsetPCcharset();
static bool isPCcharset();
static char_data getCharacter ( character_type
, int
, int, FVTerm* );
static bool setTransparent (register bool);
static bool setTransparent();
static bool unsetTransparent();
static bool isTransparent();
static char_data getCoveredCharacter (const FPoint&, FVTerm*);
static char_data getCoveredCharacter (int, int, FVTerm*);
static char_data getOverlappedCharacter (const FPoint&, FVTerm*);
static char_data getOverlappedCharacter (int, int, FVTerm*);
static void startTerminalUpdate();
static void finishTerminalUpdate();
static bool setTransShadow (register bool);
static bool setTransShadow();
static bool unsetTransShadow();
static bool isTransShadow();
// Data Members
static term_area* vterm; // virtual terminal
static term_area* vdesktop; // virtual desktop
static term_area* last_area; // last used area
static term_area* active_area; // active area
term_area* print_area; // print area for this object
term_area* vwin; // virtual window
static bool setInheritBackground (register bool);
static bool setInheritBackground();
static bool unsetInheritBackground();
static bool isInheritBackground();
private:
// Typedef
typedef FTermcap::tcap_map termcap_map;
// Constants
static const uInt TERMINAL_OUTPUT_BUFFER_SIZE = 32768;
// Buffer size for character output on the terminal
// Disable copy constructor
FVTerm (const FVTerm&);
// Disable assignment operator (=)
FVTerm& operator = (const FVTerm&);
// Accessor
term_area* getPrintArea();
// Mutators
void setPrintArea (term_area*);
// Methods
void init();
void finish();
// Data Members
static std::queue<int>* output_buffer;
static char_data term_attribute;
static char_data next_attribute;
static FPoint* term_pos; // terminal cursor position
static termcap_map* tcap;
static bool hidden_cursor;
static bool terminal_update_complete;
static bool terminal_update_pending;
static bool force_terminal_update;
static bool stop_terminal_updates;
static bool vterm_updates;
static int skipped_terminal_update;
};
#pragma pack(pop)
// FVTerm inline functions
//----------------------------------------------------------------------
inline void FVTerm::setPrintArea (term_area* area)
{ print_area = area; }
//----------------------------------------------------------------------
inline const char* FVTerm::getClassName() const
{ return "FVTerm"; }
//----------------------------------------------------------------------
inline bool FVTerm::hideCursor()
{ return hideCursor(true); }
//----------------------------------------------------------------------
inline bool FVTerm::showCursor()
{ return hideCursor(false); }
//----------------------------------------------------------------------
inline bool FVTerm::isCursorHidden()
{ return hidden_cursor; }
//----------------------------------------------------------------------
inline short FVTerm::getTermForegroundColor()
{ return next_attribute.fg_color; }
@ -334,6 +362,14 @@ inline short FVTerm::getTermBackgroundColor()
inline FVTerm::term_area* FVTerm::getVWin() const
{ return vwin; }
//----------------------------------------------------------------------
inline bool FVTerm::hideCursor()
{ return hideCursor(true); }
//----------------------------------------------------------------------
inline bool FVTerm::showCursor()
{ return hideCursor(false); }
//----------------------------------------------------------------------
inline void FVTerm::setPrintCursor (const FPoint& pos)
{ setPrintCursor (pos.getX(), pos.getY()); }
@ -383,10 +419,6 @@ inline bool FVTerm::setBold()
inline bool FVTerm::unsetBold()
{ return setBold(false); }
//----------------------------------------------------------------------
inline bool FVTerm::isBold()
{ return next_attribute.bold; }
//----------------------------------------------------------------------
inline bool FVTerm::setDim (register bool on)
{ return (next_attribute.dim = on); }
@ -399,10 +431,6 @@ inline bool FVTerm::setDim()
inline bool FVTerm::unsetDim()
{ return setDim(false); }
//----------------------------------------------------------------------
inline bool FVTerm::isDim()
{ return next_attribute.dim; }
//----------------------------------------------------------------------
inline bool FVTerm::setItalic (register bool on)
{ return (next_attribute.italic = on); }
@ -415,10 +443,6 @@ inline bool FVTerm::setItalic()
inline bool FVTerm::unsetItalic()
{ return setItalic(false); }
//----------------------------------------------------------------------
inline bool FVTerm::isItalic()
{ return next_attribute.italic; }
//----------------------------------------------------------------------
inline bool FVTerm::setUnderline (register bool on)
{ return (next_attribute.underline = on); }
@ -431,10 +455,6 @@ inline bool FVTerm::setUnderline()
inline bool FVTerm::unsetUnderline()
{ return setUnderline(false); }
//----------------------------------------------------------------------
inline bool FVTerm::isUnderline()
{ return next_attribute.underline; }
//----------------------------------------------------------------------
inline bool FVTerm::setBlink (register bool on)
{ return (next_attribute.blink = on); }
@ -447,10 +467,6 @@ inline bool FVTerm::setBlink()
inline bool FVTerm::unsetBlink()
{ return setBlink(false); }
//----------------------------------------------------------------------
inline bool FVTerm::isBlink()
{ return next_attribute.blink; }
//----------------------------------------------------------------------
inline bool FVTerm::setReverse (register bool on)
{ return (next_attribute.reverse = on); }
@ -463,10 +479,6 @@ inline bool FVTerm::setReverse()
inline bool FVTerm::unsetReverse()
{ return setReverse(false); }
//----------------------------------------------------------------------
inline bool FVTerm::isReverse()
{ return next_attribute.reverse; }
//----------------------------------------------------------------------
inline bool FVTerm::setStandout (register bool on)
{ return (next_attribute.standout = on); }
@ -479,10 +491,6 @@ inline bool FVTerm::setStandout()
inline bool FVTerm::unsetStandout()
{ return setStandout(false); }
//----------------------------------------------------------------------
inline bool FVTerm::isStandout()
{ return next_attribute.standout; }
//----------------------------------------------------------------------
inline bool FVTerm::setInvisible (register bool on)
{ return (next_attribute.invisible = on); }
@ -495,10 +503,6 @@ inline bool FVTerm::setInvisible()
inline bool FVTerm::unsetInvisible()
{ return setInvisible(false); }
//----------------------------------------------------------------------
inline bool FVTerm::isInvisible()
{ return next_attribute.invisible; }
//----------------------------------------------------------------------
inline bool FVTerm::setProtected (register bool on)
{ return (next_attribute.protect = on); }
@ -511,10 +515,6 @@ inline bool FVTerm::setProtected()
inline bool FVTerm::unsetProtected()
{ return setProtected(false); }
//----------------------------------------------------------------------
inline bool FVTerm::isProtected()
{ return next_attribute.protect; }
//----------------------------------------------------------------------
inline bool FVTerm::setCrossedOut (register bool on)
{ return (next_attribute.crossed_out = on); }
@ -527,10 +527,6 @@ inline bool FVTerm::setCrossedOut()
inline bool FVTerm::unsetCrossedOut()
{ return setCrossedOut(false); }
//----------------------------------------------------------------------
inline bool FVTerm::isCrossedOut()
{ return next_attribute.crossed_out; }
//----------------------------------------------------------------------
inline bool FVTerm::setDoubleUnderline (register bool on)
{ return (next_attribute.dbl_underline = on); }
@ -543,10 +539,6 @@ inline bool FVTerm::setDoubleUnderline()
inline bool FVTerm::unsetDoubleUnderline()
{ return setDoubleUnderline(false); }
//----------------------------------------------------------------------
inline bool FVTerm::isDoubleUnderline()
{ return next_attribute.dbl_underline; }
//----------------------------------------------------------------------
inline bool FVTerm::setAltCharset (register bool on)
{ return (next_attribute.alt_charset = on); }
@ -559,10 +551,6 @@ inline bool FVTerm::setAltCharset()
inline bool FVTerm::unsetAltCharset()
{ return setAltCharset(false); }
//----------------------------------------------------------------------
inline bool FVTerm::isAltCharset()
{ return next_attribute.alt_charset; }
//----------------------------------------------------------------------
inline bool FVTerm::setPCcharset (register bool on)
{ return (next_attribute.pc_charset = on); }
@ -575,10 +563,6 @@ inline bool FVTerm::setPCcharset()
inline bool FVTerm::unsetPCcharset()
{ return setPCcharset(false); }
//----------------------------------------------------------------------
inline bool FVTerm::isPCcharset()
{ return next_attribute.pc_charset; }
//----------------------------------------------------------------------
inline bool FVTerm::setTransparent (register bool on)
{ return (next_attribute.transparent = on); }
@ -591,10 +575,6 @@ inline bool FVTerm::setTransparent()
inline bool FVTerm::unsetTransparent()
{ return setTransparent(false); }
//----------------------------------------------------------------------
inline bool FVTerm::isTransparent()
{ return next_attribute.transparent; }
//----------------------------------------------------------------------
inline bool FVTerm::setTransShadow (register bool on)
{ return (next_attribute.trans_shadow = on); }
@ -607,10 +587,6 @@ inline bool FVTerm::setTransShadow()
inline bool FVTerm::unsetTransShadow()
{ return setTransShadow(false); }
//----------------------------------------------------------------------
inline bool FVTerm::isTransShadow()
{ return next_attribute.trans_shadow; }
//----------------------------------------------------------------------
inline bool FVTerm::setInheritBackground (register bool on)
{ return (next_attribute.inherit_bg = on); }
@ -623,8 +599,76 @@ inline bool FVTerm::setInheritBackground()
inline bool FVTerm::unsetInheritBackground()
{ return setInheritBackground(false); }
//----------------------------------------------------------------------
inline bool FVTerm::isCursorHidden()
{ return hidden_cursor; }
//----------------------------------------------------------------------
inline bool FVTerm::isBold()
{ return next_attribute.bold; }
//----------------------------------------------------------------------
inline bool FVTerm::isDim()
{ return next_attribute.dim; }
//----------------------------------------------------------------------
inline bool FVTerm::isItalic()
{ return next_attribute.italic; }
//----------------------------------------------------------------------
inline bool FVTerm::isUnderline()
{ return next_attribute.underline; }
//----------------------------------------------------------------------
inline bool FVTerm::isBlink()
{ return next_attribute.blink; }
//----------------------------------------------------------------------
inline bool FVTerm::isReverse()
{ return next_attribute.reverse; }
//----------------------------------------------------------------------
inline bool FVTerm::isStandout()
{ return next_attribute.standout; }
//----------------------------------------------------------------------
inline bool FVTerm::isInvisible()
{ return next_attribute.invisible; }
//----------------------------------------------------------------------
inline bool FVTerm::isProtected()
{ return next_attribute.protect; }
//----------------------------------------------------------------------
inline bool FVTerm::isCrossedOut()
{ return next_attribute.crossed_out; }
//----------------------------------------------------------------------
inline bool FVTerm::isDoubleUnderline()
{ return next_attribute.dbl_underline; }
//----------------------------------------------------------------------
inline bool FVTerm::isAltCharset()
{ return next_attribute.alt_charset; }
//----------------------------------------------------------------------
inline bool FVTerm::isPCcharset()
{ return next_attribute.pc_charset; }
//----------------------------------------------------------------------
inline bool FVTerm::isTransparent()
{ return next_attribute.transparent; }
//----------------------------------------------------------------------
inline bool FVTerm::isTransShadow()
{ return next_attribute.trans_shadow; }
//----------------------------------------------------------------------
inline bool FVTerm::isInheritBackground()
{ return next_attribute.inherit_bg; }
//----------------------------------------------------------------------
inline void FVTerm::setPrintArea (term_area* area)
{ print_area = area; }
#endif // _FVTERM_H

File diff suppressed because it is too large Load Diff

View File

@ -96,16 +96,182 @@ class FMenuBar;
class FWidget : public FVTerm
{
public:
typedef std::vector<FWidget*> widgetList;
static widgetList* window_list;
static widgetList* dialog_list;
static widgetList* always_on_top_list;
static widgetList* close_widget;
// Using-declaration
using FVTerm::setColor;
struct accelerator
{
int key;
FWidget* object;
};
// Typedefs
typedef std::vector<FWidget*> widgetList;
typedef void (*FCallback)(FWidget*, void*);
typedef void (FWidget::*FMemberCallback)(FWidget*, void*);
typedef void* data_ptr;
typedef std::vector<accelerator> Accelerators;
// Constructor
explicit FWidget (FWidget* = 0);
// Destructor
~FWidget();
// Accessors
const char* getClassName() const;
FWidget* getRootWidget() const;
FWidget* getParentWidget() const;
static FWidget* getMainWidget();
virtual FWidget* getFocusWidget() const;
static FWidget* getClickedWidget();
static FWidget* getMoveSizeWidget();
static FWidget* getOpenMenu();
static FMenuBar* getMenuBar();
static FStatusBar* getStatusBar();
FString getStatusbarMessage() const;
short getForegroundColor() const; // get the primary
short getBackgroundColor() const; // widget colors
int getX() const; // positioning
int getY() const;
const FPoint getPos() const;
int getTermX() const;
int getTermY() const;
const FPoint getTermPos() const;
int getWidth() const;
int getHeight() const;
int getTopPadding() const;
int getLeftPadding() const;
int getBottomPadding() const;
int getRightPadding() const;
int getClientWidth() const;
int getClientHeight() const;
int getMaxWidth() const;
int getMaxHeight() const;
const FPoint& getShadow() const;
const FRect& getGeometry() const;
const FRect& getGeometryWithShadow();
const FRect& getTermGeometry();
const FRect& getTermGeometryWithShadow();
int getFlags() const;
FPoint getCursorPos();
FPoint getPrintPos();
std::vector<bool>& doubleFlatLine_ref (fc::sides);
// Mutators
static void setMainWidget (FWidget*);
virtual void setFocusWidget (FWidget*);
static void setClickedWidget (FWidget*);
static void setMoveSizeWidget (FWidget*);
static void setOpenMenu (FWidget*);
virtual void setStatusbarMessage (FString);
bool setVisible();
virtual bool setEnable (bool);
virtual bool setEnable();
virtual bool unsetEnable();
virtual bool setDisable();
virtual bool setVisibleCursor (bool); // input cursor visibility
virtual bool setVisibleCursor(); // for the widget
virtual bool unsetVisibleCursor();
virtual bool setFocus (bool);
virtual bool setFocus();
virtual bool unsetFocus();
void setFocusable();
void unsetFocusable();
bool ignorePadding (bool); // ignore padding from
bool ignorePadding(); // the parent widget
bool acceptPadding();
void setForegroundColor (short);
void setBackgroundColor (short);
void setColor();
virtual void setX (int, bool = true); // positioning
virtual void setY (int, bool = true);
virtual void setPos (const FPoint&, bool = true);
virtual void setPos (int, int, bool = true);
virtual void setWidth (int, bool = true);
virtual void setHeight (int, bool = true);
virtual void setSize (int, int, bool = true);
void setTopPadding (int, bool = true);
void setLeftPadding (int, bool = true);
void setBottomPadding (int, bool = true);
void setRightPadding (int, bool = true);
void setParentOffset();
void setTermOffset();
void setTermOffsetWithPadding();
void setTermSize (int, int);
virtual void setGeometry (const FRect&, bool = true);
virtual void setGeometry (int, int, int, int, bool = true);
virtual void setShadowSize (int, int);
void setMinimumSize (int, int);
void setMaximumSize (int, int);
void setFixedSize (int, int);
bool setCursorPos (const FPoint&);
bool setCursorPos (register int, register int);
void unsetCursorPos();
void setPrintPos (const FPoint&);
void setPrintPos (register int, register int);
void setDoubleFlatLine (fc::sides, bool = true);
void unsetDoubleFlatLine (fc::sides);
void setDoubleFlatLine (fc::sides, int, bool = true);
void unsetDoubleFlatLine (fc::sides, int);
// Inquiries
bool isRootWidget() const;
bool isWindowWidget() const;
bool isDialogWidget() const;
bool isMenuWidget() const;
bool isVisible() const;
bool isShown() const;
bool isEnabled() const;
bool hasVisibleCursor() const;
bool hasFocus() const;
bool acceptFocus() const; // is focusable
bool isPaddingIgnored();
// Methods
static FWidget* childWidgetAt (FWidget*, const FPoint&);
static FWidget* childWidgetAt (FWidget*, int, int);
int numOfFocusableChildren();
virtual bool close();
void clearStatusbarMessage();
void addCallback ( FString
, FCallback
, void* = null );
void addCallback ( FString
, FWidget*
, FMemberCallback
, void* = null );
void delCallback (FCallback);
void delCallback (FWidget*);
void delCallbacks();
void emitCallback (FString);
void addAccelerator (int);
virtual void addAccelerator (int, FWidget*);
void delAccelerator ();
virtual void delAccelerator (FWidget*);
virtual void redraw();
virtual void resize();
virtual void show();
virtual void hide();
virtual bool focusFirstChild(); // widget focusing
virtual bool focusLastChild();
FPoint termToWidgetPos (const FPoint&);
void detectTermSize();
virtual void move (const FPoint&);
virtual void move (int, int);
void drawShadow();
void clearShadow();
void drawFlatBorder();
void clearFlatBorder();
virtual void drawBorder (int, int, int, int);
virtual void drawBorder();
static void quit();
// Data Members
static widgetList* window_list;
Accelerators* accelerator_list;
protected:
struct callback_data
{
FString cb_signal;
@ -113,9 +279,6 @@ class FWidget : public FVTerm
data_ptr data;
};
typedef std::vector<callback_data> CallbackObjects;
CallbackObjects callback_objects;
struct member_callback_data
{
FString cb_signal;
@ -124,19 +287,39 @@ class FWidget : public FVTerm
data_ptr data;
};
// Typedefs
typedef std::vector<callback_data> CallbackObjects;
typedef std::vector<member_callback_data> MemberCallbackObjects;
MemberCallbackObjects member_callback_objects;
struct accelerator
{
int key;
FWidget* object;
};
// Mutators
virtual void setStatusBar (FStatusBar*);
virtual void setMenuBar (FMenuBar*);
typedef std::vector<accelerator> Accelerators;
Accelerators* accelerator_list;
// Methods
virtual void adjustSize();
void adjustSizeGlobal();
virtual bool focusNextChild(); // Change child
virtual bool focusPrevChild(); // focus
protected:
// Event handlers
bool event (FEvent*);
virtual void onKeyPress (FKeyEvent*);
virtual void onKeyUp (FKeyEvent*);
virtual void onKeyDown (FKeyEvent*);
virtual void onMouseDown (FMouseEvent*);
virtual void onMouseUp (FMouseEvent*);
virtual void onMouseDoubleClick (FMouseEvent*);
virtual void onWheel (FWheelEvent*);
virtual void onMouseMove (FMouseEvent*);
virtual void onFocusIn (FFocusEvent*);
virtual void onFocusOut (FFocusEvent*);
virtual void onAccel (FAccelEvent*);
virtual void onResize (FResizeEvent*);
virtual void onShow (FShowEvent*);
virtual void onHide (FHideEvent*);
virtual void onClose (FCloseEvent*);
// Data Members
static struct widget_colors
{
short term_fg;
@ -228,8 +411,27 @@ class FWidget : public FVTerm
int flags;
static uInt modal_dialogs;
static widgetList* dialog_list;
static widgetList* always_on_top_list;
static widgetList* close_widget;
CallbackObjects callback_objects;
MemberCallbackObjects member_callback_objects;
private:
// Disable copy constructor
FWidget (const FWidget&);
// Disable assignment operator (=)
FWidget& operator = (const FWidget&);
// Methods
void init();
void finish();
void processDestroy();
virtual void draw();
static void setColorTheme();
// Data Members
bool enable;
bool visible;
bool shown;
@ -308,346 +510,30 @@ class FWidget : public FVTerm
short background_color;
FString statusbar_message;
static FStatusBar* statusbar;
static FMenuBar* menubar;
static FWidget* show_root_widget;
static FWidget* redraw_root_widget;
// Friend classes
// Friend class
friend class FToggleButton;
private:
// Disable copy constructor
FWidget (const FWidget&);
// Disable assignment operator (=)
FWidget& operator = (const FWidget&);
void init();
void finish();
void processDestroy();
virtual void draw();
static void setColorTheme();
protected:
virtual void adjustSize();
void adjustSizeGlobal();
virtual void setStatusBar (FStatusBar*);
virtual void setMenuBar (FMenuBar*);
// Event handlers
bool event (FEvent*);
virtual void onKeyPress (FKeyEvent*);
virtual void onKeyUp (FKeyEvent*);
virtual void onKeyDown (FKeyEvent*);
virtual void onMouseDown (FMouseEvent*);
virtual void onMouseUp (FMouseEvent*);
virtual void onMouseDoubleClick (FMouseEvent*);
virtual void onWheel (FWheelEvent*);
virtual void onMouseMove (FMouseEvent*);
virtual void onFocusIn (FFocusEvent*);
virtual void onFocusOut (FFocusEvent*);
virtual void onAccel (FAccelEvent*);
virtual void onResize (FResizeEvent*);
virtual void onShow (FShowEvent*);
virtual void onHide (FHideEvent*);
virtual void onClose (FCloseEvent*);
// Change child focus
virtual bool focusNextChild();
virtual bool focusPrevChild();
public:
// Constructor
explicit FWidget (FWidget* = 0);
// Destructor
~FWidget();
const char* getClassName() const;
FWidget* getRootWidget() const;
static FWidget* getMainWidget();
static void setMainWidget (FWidget*);
static FWidget* childWidgetAt (FWidget*, const FPoint&);
static FWidget* childWidgetAt (FWidget*, int, int);
virtual FWidget* getFocusWidget() const;
virtual void setFocusWidget (FWidget*);
static FWidget* getClickedWidget();
static void setClickedWidget (FWidget*);
static FWidget* getMoveSizeWidget();
static void setMoveSizeWidget (FWidget*);
static FWidget* getOpenMenu();
static void setOpenMenu (FWidget*);
int numOfFocusableChildren();
FWidget* getParentWidget() const;
bool isRootWidget() const;
bool isWindowWidget() const;
bool isDialogWidget() const;
bool isMenuWidget() const;
virtual bool close();
static FStatusBar* statusBar();
static FMenuBar* menuBar();
virtual void setStatusbarMessage (FString);
void clearStatusbarMessage();
FString getStatusbarMessage();
void addCallback ( FString
, FCallback
, void* = null );
void addCallback ( FString
, FWidget*
, FMemberCallback
, void* = null );
void delCallback (FCallback);
void delCallback (FWidget*);
void delCallbacks();
void emitCallback (FString);
void addAccelerator (int);
virtual void addAccelerator (int, FWidget*);
void delAccelerator ();
virtual void delAccelerator (FWidget*);
virtual void redraw();
virtual void resize();
virtual void show();
virtual void hide();
bool setVisible();
bool isVisible() const;
bool isShown() const;
virtual bool setEnable(bool);
virtual bool setEnable();
virtual bool unsetEnable();
virtual bool setDisable();
bool isEnabled() const;
// input cursor visibility for the widget
virtual bool setVisibleCursor(bool);
virtual bool setVisibleCursor();
virtual bool unsetVisibleCursor();
bool hasVisibleCursor() const;
// widget focusing
virtual bool focusFirstChild();
virtual bool focusLastChild();
virtual bool setFocus (bool);
virtual bool setFocus();
virtual bool unsetFocus();
bool hasFocus() const;
bool acceptFocus() const;
void setFocusable();
void unsetFocusable();
// ignore padding from the parent widget
bool ignorePadding (bool);
bool ignorePadding();
bool acceptPadding();
bool isPaddingIgnored();
// get the primary widget colors
short getForegroundColor() const;
short getBackgroundColor() const;
// positioning
int getX() const;
int getY() const;
const FPoint getPos() const;
int getTermX() const;
int getTermY() const;
const FPoint getTermPos() const;
int getWidth() const;
int getHeight() const;
int getTopPadding() const;
int getLeftPadding() const;
int getBottomPadding() const;
int getRightPadding() const;
int getClientWidth() const;
int getClientHeight() const;
int getMaxWidth() const;
int getMaxHeight() const;
const FPoint& getShadow() const;
const FRect& getGeometry() const;
const FRect& getGeometryWithShadow();
const FRect& getTermGeometry();
const FRect& getTermGeometryWithShadow();
FPoint termToWidgetPos (const FPoint&);
void setForegroundColor (short);
void setBackgroundColor (short);
void setColor();
// make every setColor from FVTerm available
using FVTerm::setColor;
virtual void setX (int, bool = true);
virtual void setY (int, bool = true);
virtual void setPos (const FPoint&, bool = true);
virtual void setPos (int, int, bool = true);
virtual void setWidth (int, bool = true);
virtual void setHeight (int, bool = true);
virtual void setSize (int, int, bool = true);
void setTopPadding (int, bool = true);
void setLeftPadding (int, bool = true);
void setBottomPadding (int, bool = true);
void setRightPadding (int, bool = true);
void setParentOffset();
void setTermOffset();
void setTermOffsetWithPadding();
void detectTermSize();
void setTermSize (int, int);
virtual void setGeometry (const FRect&, bool = true);
virtual void setGeometry (int, int, int, int, bool = true);
virtual void setShadowSize (int, int);
void setMinimumSize (int, int);
void setMaximumSize (int, int);
void setFixedSize (int, int);
virtual void move (const FPoint&);
virtual void move (int, int);
int getFlags() const;
FPoint getCursorPos();
bool setCursorPos (const FPoint&);
bool setCursorPos (register int, register int);
void unsetCursorPos();
void setPrintPos (const FPoint&);
void setPrintPos (register int, register int);
FPoint getPrintPos();
void drawShadow();
void clearShadow();
void drawFlatBorder();
void clearFlatBorder();
void setDoubleFlatLine (int, bool = true);
void unsetDoubleFlatLine (int);
void setDoubleFlatLine (int, int, bool = true);
void unsetDoubleFlatLine (int, int);
std::vector<bool>& doubleFlatLine_ref (int);
virtual void drawBorder (int, int, int, int);
virtual void drawBorder();
static void quit();
};
#pragma pack(pop)
// FWidget inline functions
//----------------------------------------------------------------------
inline void FWidget::processDestroy()
{ emitCallback("destroy"); }
//----------------------------------------------------------------------
inline const char* FWidget::getClassName() const
{ return "FWidget"; }
//----------------------------------------------------------------------
inline FWidget* FWidget::childWidgetAt (FWidget* p, const FPoint& pos)
{ return childWidgetAt (p, pos.getX(), pos.getY()); }
//----------------------------------------------------------------------
inline FWidget* FWidget::getParentWidget() const
{ return static_cast<FWidget*>(getParent()); }
//----------------------------------------------------------------------
inline bool FWidget::isRootWidget() const
{ return (! hasParent()); }
//----------------------------------------------------------------------
inline void FWidget::clearStatusbarMessage()
{ statusbar_message.clear(); }
//----------------------------------------------------------------------
inline FString FWidget::getStatusbarMessage()
inline FString FWidget::getStatusbarMessage() const
{ return statusbar_message; }
//----------------------------------------------------------------------
inline void FWidget::addAccelerator (int key)
{ addAccelerator (key, this); }
//----------------------------------------------------------------------
inline void FWidget::delAccelerator()
{ delAccelerator(this); }
//----------------------------------------------------------------------
inline bool FWidget::setVisible()
{ return visible = true; }
//----------------------------------------------------------------------
inline bool FWidget::isVisible() const
{ return visible; }
//----------------------------------------------------------------------
inline bool FWidget::isShown() const
{ return shown; }
//----------------------------------------------------------------------
inline bool FWidget::isWindowWidget() const
{ return ((flags & fc::window_widget) != 0); }
//----------------------------------------------------------------------
inline bool FWidget::isDialogWidget() const
{ return ((flags & fc::dialog_widget) != 0); }
//----------------------------------------------------------------------
inline bool FWidget::isMenuWidget() const
{ return ((flags & fc::menu_widget) != 0); }
//----------------------------------------------------------------------
inline bool FWidget::isEnabled() const
{ return enable; }
//----------------------------------------------------------------------
inline bool FWidget::setVisibleCursor (bool on)
{ return visible_cursor = (on) ? true : false; }
//----------------------------------------------------------------------
inline bool FWidget::setVisibleCursor()
{ return setVisibleCursor(true); }
//----------------------------------------------------------------------
inline bool FWidget::unsetVisibleCursor()
{ return setVisibleCursor(false); }
//----------------------------------------------------------------------
inline bool FWidget::hasVisibleCursor() const
{ return visible_cursor; }
//----------------------------------------------------------------------
inline bool FWidget::setFocus()
{ return setFocus(true); }
//----------------------------------------------------------------------
inline bool FWidget::unsetFocus()
{ return setFocus(false); }
//----------------------------------------------------------------------
inline bool FWidget::hasFocus() const
{ return focus; }
//----------------------------------------------------------------------
inline bool FWidget::acceptFocus() const
{ return focusable; }
//----------------------------------------------------------------------
inline bool FWidget::ignorePadding (bool on)
{ return ignore_padding = on; }
//----------------------------------------------------------------------
inline bool FWidget::ignorePadding()
{ return ignore_padding = true; }
//----------------------------------------------------------------------
inline bool FWidget::acceptPadding()
{ return ignore_padding = false; }
//----------------------------------------------------------------------
inline bool FWidget::isPaddingIgnored()
{ return ignore_padding; }
//----------------------------------------------------------------------
inline void FWidget::setFocusable()
{ focusable = true; }
//----------------------------------------------------------------------
inline void FWidget::unsetFocusable()
{ focusable = false; }
//----------------------------------------------------------------------
inline short FWidget::getForegroundColor() const
{ return foreground_color; }
@ -680,33 +566,6 @@ inline int FWidget::getTermY() const // y-position on terminal
inline const FPoint FWidget::getTermPos() const // position on terminal
{ return FPoint(getTermX(), getTermY()); }
//----------------------------------------------------------------------
inline FPoint FWidget::termToWidgetPos (const FPoint& tPos)
{
return FPoint ( tPos.getX() + 1 - offset.getX1() - adjust_wsize.getX()
, tPos.getY() + 1 - offset.getY1() - adjust_wsize.getY() );
}
//----------------------------------------------------------------------
inline void FWidget::setForegroundColor (short color)
{
// valid colors -1..254
if ( color == fc::Default || color >> 8 == 0 )
foreground_color = color;
}
//----------------------------------------------------------------------
inline void FWidget::setBackgroundColor (short color)
{
// valid colors -1..254
if ( color == fc::Default || color >> 8 == 0 )
background_color = color;
}
//----------------------------------------------------------------------
inline void FWidget::setPos (const FPoint& p, bool adjust)
{ setPos (p.getX(), p.getY(), adjust); }
//----------------------------------------------------------------------
inline int FWidget::getWidth() const
{ return adjust_wsize.getWidth(); }
@ -794,6 +653,94 @@ inline const FRect& FWidget::getTermGeometryWithShadow()
return adjust_wsize_term_shadow;
}
//----------------------------------------------------------------------
inline int FWidget::getFlags() const
{ return flags; }
//----------------------------------------------------------------------
inline FPoint FWidget::getCursorPos()
{ return widget_cursor_position; }
//----------------------------------------------------------------------
inline bool FWidget::setVisible()
{ return visible = true; }
//----------------------------------------------------------------------
inline bool FWidget::setEnable (bool on)
{ return enable = (on) ? true : false; }
//----------------------------------------------------------------------
inline bool FWidget::setEnable()
{ return setEnable(true); }
//----------------------------------------------------------------------
inline bool FWidget::unsetEnable()
{ return setEnable(false); }
//----------------------------------------------------------------------
inline bool FWidget::setDisable()
{ return setEnable(false); }
//----------------------------------------------------------------------
inline bool FWidget::setVisibleCursor (bool on)
{ return visible_cursor = (on) ? true : false; }
//----------------------------------------------------------------------
inline bool FWidget::setVisibleCursor()
{ return setVisibleCursor(true); }
//----------------------------------------------------------------------
inline bool FWidget::unsetVisibleCursor()
{ return setVisibleCursor(false); }
//----------------------------------------------------------------------
inline bool FWidget::setFocus()
{ return setFocus(true); }
//----------------------------------------------------------------------
inline bool FWidget::unsetFocus()
{ return setFocus(false); }
//----------------------------------------------------------------------
inline void FWidget::setFocusable()
{ focusable = true; }
//----------------------------------------------------------------------
inline void FWidget::unsetFocusable()
{ focusable = false; }
//----------------------------------------------------------------------
inline bool FWidget::ignorePadding (bool on)
{ return ignore_padding = on; }
//----------------------------------------------------------------------
inline bool FWidget::ignorePadding()
{ return ignore_padding = true; }
//----------------------------------------------------------------------
inline bool FWidget::acceptPadding()
{ return ignore_padding = false; }
//----------------------------------------------------------------------
inline void FWidget::setForegroundColor (short color)
{
// valid colors -1..254
if ( color == fc::Default || color >> 8 == 0 )
foreground_color = color;
}
//----------------------------------------------------------------------
inline void FWidget::setBackgroundColor (short color)
{
// valid colors -1..254
if ( color == fc::Default || color >> 8 == 0 )
background_color = color;
}
//----------------------------------------------------------------------
inline void FWidget::setPos (const FPoint& p, bool adjust)
{ setPos (p.getX(), p.getY(), adjust); }
//----------------------------------------------------------------------
inline void FWidget::setGeometry (const FRect& box, bool adjust)
{
@ -823,18 +770,6 @@ inline void FWidget::setFixedSize (int width, int height)
size_hints.setMaximum (width, height);
}
//----------------------------------------------------------------------
inline void FWidget::move (const FPoint& pos)
{ move( pos.getX(), pos.getY() ); }
//----------------------------------------------------------------------
inline int FWidget::getFlags() const
{ return flags; }
//----------------------------------------------------------------------
inline FPoint FWidget::getCursorPos()
{ return widget_cursor_position; }
//----------------------------------------------------------------------
inline bool FWidget::setCursorPos (const FPoint& pos)
{ return setCursorPos (pos.getX(), pos.getY()); }
@ -848,19 +783,94 @@ inline void FWidget::setPrintPos (const FPoint& pos)
{ setPrintPos (pos.getX(), pos.getY()); }
//----------------------------------------------------------------------
inline void FWidget::unsetDoubleFlatLine (int side)
inline void FWidget::unsetDoubleFlatLine (fc::sides side)
{ setDoubleFlatLine(side, false); }
//----------------------------------------------------------------------
inline void FWidget::unsetDoubleFlatLine (int side, int pos)
inline void FWidget::unsetDoubleFlatLine (fc::sides side, int pos)
{ setDoubleFlatLine(side, pos, false); }
//----------------------------------------------------------------------
inline bool FWidget::isRootWidget() const
{ return (! hasParent()); }
//----------------------------------------------------------------------
inline bool FWidget::isVisible() const
{ return visible; }
//----------------------------------------------------------------------
inline bool FWidget::isShown() const
{ return shown; }
//----------------------------------------------------------------------
inline bool FWidget::isWindowWidget() const
{ return ((flags & fc::window_widget) != 0); }
//----------------------------------------------------------------------
inline bool FWidget::isDialogWidget() const
{ return ((flags & fc::dialog_widget) != 0); }
//----------------------------------------------------------------------
inline bool FWidget::isMenuWidget() const
{ return ((flags & fc::menu_widget) != 0); }
//----------------------------------------------------------------------
inline bool FWidget::isEnabled() const
{ return enable; }
//----------------------------------------------------------------------
inline bool FWidget::hasVisibleCursor() const
{ return visible_cursor; }
//----------------------------------------------------------------------
inline bool FWidget::hasFocus() const
{ return focus; }
//----------------------------------------------------------------------
inline bool FWidget::acceptFocus() const // is focusable
{ return focusable; }
//----------------------------------------------------------------------
inline bool FWidget::isPaddingIgnored()
{ return ignore_padding; }
//----------------------------------------------------------------------
inline FWidget* FWidget::childWidgetAt (FWidget* p, const FPoint& pos)
{ return childWidgetAt (p, pos.getX(), pos.getY()); }
//----------------------------------------------------------------------
inline void FWidget::clearStatusbarMessage()
{ statusbar_message.clear(); }
//----------------------------------------------------------------------
inline void FWidget::addAccelerator (int key)
{ addAccelerator (key, this); }
//----------------------------------------------------------------------
inline void FWidget::delAccelerator()
{ delAccelerator(this); }
//----------------------------------------------------------------------
inline FPoint FWidget::termToWidgetPos (const FPoint& tPos)
{
return FPoint ( tPos.getX() + 1 - offset.getX1() - adjust_wsize.getX()
, tPos.getY() + 1 - offset.getY1() - adjust_wsize.getY() );
}
//----------------------------------------------------------------------
inline void FWidget::move (const FPoint& pos)
{ move( pos.getX(), pos.getY() ); }
//----------------------------------------------------------------------
inline void FWidget::drawBorder()
{ drawBorder (1, 1, getWidth(), getHeight()); }
//----------------------------------------------------------------------
inline void FWidget::processDestroy()
{ emitCallback("destroy"); }
// NewFont elements
// Non-member elements for NewFont
//----------------------------------------------------------------------
const wchar_t NF_Drive[5] =
{

View File

@ -53,117 +53,191 @@ FWindow::~FWindow() // destructor
}
// private methods of FWindow
//----------------------------------------------------------------------
void FWindow::deleteFromAlwaysOnTopList (FWidget* obj)
{
// delete the window object obj from the always-on-top list
if ( ! always_on_top_list || always_on_top_list->empty() )
return;
widgetList::iterator iter;
iter = always_on_top_list->begin();
while ( iter != always_on_top_list->end() )
{
if ( *iter == obj )
{
always_on_top_list->erase (iter);
return;
}
++iter;
}
}
//----------------------------------------------------------------------
void FWindow::processAlwaysOnTop()
{
// Raise all always-on-top windows
if ( ! always_on_top_list || always_on_top_list->empty() )
return;
widgetList::iterator iter;
iter = always_on_top_list->begin();
while ( iter != always_on_top_list->end() )
{
delWindow (*iter);
if ( window_list )
window_list->push_back(*iter);
++iter;
}
}
// protected methods of FWindow
//----------------------------------------------------------------------
bool FWindow::event (FEvent* ev)
{
switch ( ev->type() )
{
case fc::WindowActive_Event:
onWindowActive (ev);
break;
case fc::WindowInactive_Event:
onWindowInactive (ev);
break;
case fc::WindowRaised_Event:
onWindowRaised (ev);
break;
case fc::WindowLowered_Event:
onWindowLowered (ev);
break;
default:
return FWidget::event(ev);
}
return true;
}
//----------------------------------------------------------------------
void FWindow::onWindowActive (FEvent*)
{ }
//----------------------------------------------------------------------
void FWindow::onWindowInactive (FEvent*)
{ }
//----------------------------------------------------------------------
void FWindow::onWindowRaised (FEvent*)
{ }
//----------------------------------------------------------------------
void FWindow::onWindowLowered (FEvent*)
{ }
//----------------------------------------------------------------------
void FWindow::adjustSize()
{
int old_x = getX();
int old_y = getY();
FWidget::adjustSize();
if ( zoomed )
setGeometry (1, 1, getMaxWidth(), getMaxHeight(), false);
else if ( vwin )
{
if ( getX() != old_x )
vwin->x_offset = getTermX() - 1;
if ( getY() != old_y )
vwin->y_offset = getTermY() - 1;
}
}
// public methods of FWindow
//----------------------------------------------------------------------
FWindow* FWindow::getActiveWindow()
{
// returns the active FWindow object
FWindow* active_window = static_cast<FWindow*>(FApplication::active_window);
return active_window;
}
//----------------------------------------------------------------------
FWidget* FWindow::getWindowFocusWidget() const
{
// returns the focused widget of this window
return win_focus_widget;
}
//----------------------------------------------------------------------
bool FWindow::setWindowWidget (bool on)
{
if ( isWindowWidget() == on )
return true;
if ( on )
{
flags |= fc::window_widget;
setTermOffset();
}
else
{
flags &= ~fc::window_widget;
setParentOffset();
}
return on;
}
//----------------------------------------------------------------------
void FWindow::setActiveWindow (FWindow* window)
{
// activate FWindow object window
widgetList::const_iterator iter, end;
if ( ! window_list )
return;
if ( window_list->empty() )
return;
iter = window_list->begin();
end = window_list->end();
while ( iter != end )
{
if ( *iter == window )
{
if ( ! window->isWindowActive() )
{
window->activateWindow();
FEvent ev(fc::WindowActive_Event);
FApplication::sendEvent(window, &ev);
}
}
else
{
FWindow* w = static_cast<FWindow*>(*iter);
if ( w->isWindowActive() )
{
w->deactivateWindow();
FEvent ev(fc::WindowInactive_Event);
FApplication::sendEvent(*iter, &ev);
}
}
++iter;
}
}
//----------------------------------------------------------------------
void FWindow::setWindowFocusWidget (FWidget* obj)
{
// set focus widget of this window
win_focus_widget = obj;
}
//----------------------------------------------------------------------
bool FWindow::activateWindow (bool on)
{
// activate/deactivate this window
if ( on )
{
FApplication::active_window = this;
active_area = getVWin();
}
return window_active = (on) ? true : false;
}
//----------------------------------------------------------------------
bool FWindow::setResizeable (bool on)
{
if ( on )
flags |= fc::resizeable;
else
flags &= ~fc::resizeable;
return on;
}
//----------------------------------------------------------------------
bool FWindow::setTransparentShadow (bool on)
{
if ( on )
{
flags |= fc::shadow;
flags |= fc::trans_shadow;
setShadowSize (2,1);
}
else
{
flags &= ~fc::shadow;
flags &= ~fc::trans_shadow;
setShadowSize (0,0);
}
return on;
}
//----------------------------------------------------------------------
bool FWindow::setShadow (bool on)
{
if ( isMonochron() )
return false;
if ( on )
{
flags |= fc::shadow;
flags &= ~fc::trans_shadow;
setShadowSize (1,1);
}
else
{
flags &= ~fc::shadow;
flags &= ~fc::trans_shadow;
setShadowSize (0,0);
}
return on;
}
//----------------------------------------------------------------------
bool FWindow::setAlwaysOnTop (bool on)
{
if ( isAlwaysOnTop() == on )
return true;
if ( on )
{
flags |= fc::always_on_top;
if ( always_on_top_list )
{
deleteFromAlwaysOnTopList (this);
always_on_top_list->push_back (this);
}
}
else
{
flags &= ~fc::always_on_top;
deleteFromAlwaysOnTopList (this);
}
return on;
}
//----------------------------------------------------------------------
bool FWindow::isWindowHidden() const
{
// returns the window hidden state
if ( vwin )
return ! vwin->visible;
else
return false;
}
//----------------------------------------------------------------------
void FWindow::drawBorder()
{
@ -608,90 +682,6 @@ bool FWindow::zoomWindow()
return zoomed;
}
//----------------------------------------------------------------------
bool FWindow::setWindowWidget (bool on)
{
if ( isWindowWidget() == on )
return true;
if ( on )
{
flags |= fc::window_widget;
setTermOffset();
}
else
{
flags &= ~fc::window_widget;
setParentOffset();
}
return on;
}
//----------------------------------------------------------------------
FWindow* FWindow::getActiveWindow()
{
// returns the active FWindow object
FWindow* active_window = static_cast<FWindow*>(FApplication::active_window);
return active_window;
}
//----------------------------------------------------------------------
void FWindow::setActiveWindow (FWindow* window)
{
// activate FWindow object window
widgetList::const_iterator iter, end;
if ( ! window_list )
return;
if ( window_list->empty() )
return;
iter = window_list->begin();
end = window_list->end();
while ( iter != end )
{
if ( *iter == window )
{
if ( ! window->isWindowActive() )
{
window->activateWindow();
FEvent ev(fc::WindowActive_Event);
FApplication::sendEvent(window, &ev);
}
}
else
{
FWindow* w = static_cast<FWindow*>(*iter);
if ( w->isWindowActive() )
{
w->deactivateWindow();
FEvent ev(fc::WindowInactive_Event);
FApplication::sendEvent(*iter, &ev);
}
}
++iter;
}
}
//----------------------------------------------------------------------
FWidget* FWindow::getWindowFocusWidget() const
{
// returns the focused widget of this window
return win_focus_widget;
}
//----------------------------------------------------------------------
void FWindow::setWindowFocusWidget (FWidget* obj)
{
// set focus widget of this window
win_focus_widget = obj;
}
//----------------------------------------------------------------------
void FWindow::switchToPrevWindow()
{
@ -716,8 +706,8 @@ void FWindow::switchToPrevWindow()
if ( w
&& w != active_window
&& ! (w->isWindowHidden() || w->isWindowActive())
&& w != static_cast<FWindow*>(statusBar())
&& w != static_cast<FWindow*>(menuBar()) )
&& w != static_cast<FWindow*>(getStatusBar())
&& w != static_cast<FWindow*>(getMenuBar()) )
{
setActiveWindow(w);
break;
@ -765,81 +755,6 @@ bool FWindow::activatePrevWindow()
return false;
}
//----------------------------------------------------------------------
bool FWindow::activateWindow (bool on)
{
// activate/deactivate this window
if ( on )
{
FApplication::active_window = this;
active_area = getVWin();
}
return window_active = (on) ? true : false;
}
//----------------------------------------------------------------------
bool FWindow::isWindowHidden() const
{
// returns the window hidden state
if ( vwin )
return ! vwin->visible;
else
return false;
}
//----------------------------------------------------------------------
bool FWindow::setResizeable (bool on)
{
if ( on )
flags |= fc::resizeable;
else
flags &= ~fc::resizeable;
return on;
}
//----------------------------------------------------------------------
bool FWindow::setTransparentShadow (bool on)
{
if ( on )
{
flags |= fc::shadow;
flags |= fc::trans_shadow;
setShadowSize (2,1);
}
else
{
flags &= ~fc::shadow;
flags &= ~fc::trans_shadow;
setShadowSize (0,0);
}
return on;
}
//----------------------------------------------------------------------
bool FWindow::setShadow (bool on)
{
if ( isMonochron() )
return false;
if ( on )
{
flags |= fc::shadow;
flags &= ~fc::trans_shadow;
setShadowSize (1,1);
}
else
{
flags &= ~fc::shadow;
flags &= ~fc::trans_shadow;
setShadowSize (0,0);
}
return on;
}
//----------------------------------------------------------------------
void FWindow::setShadowSize (int right, int bottom)
{
@ -858,27 +773,112 @@ void FWindow::setShadowSize (int right, int bottom)
}
}
// protected methods of FWindow
//----------------------------------------------------------------------
bool FWindow::setAlwaysOnTop (bool on)
void FWindow::adjustSize()
{
if ( isAlwaysOnTop() == on )
return true;
int old_x = getX();
int old_y = getY();
FWidget::adjustSize();
if ( on )
if ( zoomed )
setGeometry (1, 1, getMaxWidth(), getMaxHeight(), false);
else if ( vwin )
{
flags |= fc::always_on_top;
if ( getX() != old_x )
vwin->x_offset = getTermX() - 1;
if ( always_on_top_list )
{
deleteFromAlwaysOnTopList (this);
always_on_top_list->push_back (this);
if ( getY() != old_y )
vwin->y_offset = getTermY() - 1;
}
}
//----------------------------------------------------------------------
bool FWindow::event (FEvent* ev)
{
switch ( ev->type() )
{
case fc::WindowActive_Event:
onWindowActive (ev);
break;
case fc::WindowInactive_Event:
onWindowInactive (ev);
break;
case fc::WindowRaised_Event:
onWindowRaised (ev);
break;
case fc::WindowLowered_Event:
onWindowLowered (ev);
break;
default:
return FWidget::event(ev);
}
return true;
}
//----------------------------------------------------------------------
void FWindow::onWindowActive (FEvent*)
{ }
//----------------------------------------------------------------------
void FWindow::onWindowInactive (FEvent*)
{ }
//----------------------------------------------------------------------
void FWindow::onWindowRaised (FEvent*)
{ }
//----------------------------------------------------------------------
void FWindow::onWindowLowered (FEvent*)
{ }
// private methods of FWindow
//----------------------------------------------------------------------
void FWindow::deleteFromAlwaysOnTopList (FWidget* obj)
{
// delete the window object obj from the always-on-top list
if ( ! always_on_top_list || always_on_top_list->empty() )
return;
widgetList::iterator iter;
iter = always_on_top_list->begin();
while ( iter != always_on_top_list->end() )
{
if ( *iter == obj )
{
always_on_top_list->erase (iter);
return;
}
++iter;
}
}
//----------------------------------------------------------------------
void FWindow::processAlwaysOnTop()
{
// Raise all always-on-top windows
if ( ! always_on_top_list || always_on_top_list->empty() )
return;
widgetList::iterator iter;
iter = always_on_top_list->begin();
while ( iter != always_on_top_list->end() )
{
delWindow (*iter);
if ( window_list )
window_list->push_back(*iter);
++iter;
}
}
else
{
flags &= ~fc::always_on_top;
deleteFromAlwaysOnTopList (this);
}
return on;
}

View File

@ -48,25 +48,87 @@
class FWindow : public FWidget
{
private:
bool window_active;
bool zoomed;
FWidget* win_focus_widget;
FRect normalGeometry;
public:
// Using-declaration
using FWidget::drawBorder;
using FWidget::setPos;
using FWidget::setGeometry;
using FWidget::move;
// Constructor
explicit FWindow (FWidget* = 0);
// Destructor
~FWindow ();
// Accessors
const char* getClassName() const;
static FWindow* getWindowWidget (FWidget*);
static int getWindowLayer (FWidget*);
static FWindow* getActiveWindow();
FWidget* getWindowFocusWidget() const;
// Mutators
bool setWindowWidget (bool);
bool setWindowWidget();
bool unsetWindowWidget();
static void setActiveWindow (FWindow*);
void setWindowFocusWidget (FWidget*);
bool activateWindow (bool);
bool activateWindow();
bool deactivateWindow();
virtual bool setResizeable (bool);
virtual bool setResizeable();
bool unsetResizeable();
bool setTransparentShadow (bool);
bool setTransparentShadow();
bool unsetTransparentShadow();
bool setShadow (bool);
bool setShadow();
bool unsetShadow();
bool setAlwaysOnTop (bool);
bool setAlwaysOnTop();
bool unsetAlwaysOnTop();
// Inquiries
bool isZoomed() const;
bool isWindowActive() const;
bool isWindowHidden() const;
bool isResizeable() const;
bool isAlwaysOnTop() const;
bool hasTransparentShadow() const;
bool hasShadow() const;
// Methods
virtual void drawBorder();
virtual void show();
virtual void hide();
virtual void setX (int, bool = true);
virtual void setY (int, bool = true);
virtual void setPos (int, int, bool = true);
virtual void setWidth (int, bool = true);
virtual void setHeight (int, bool = true);
virtual void setSize (int, int, bool = true);
void setGeometry (int, int, int, int, bool = true);
virtual void move (int, int);
static FWindow* getWindowWidgetAt (const FPoint&);
static FWindow* getWindowWidgetAt (int, int);
static void addWindow (FWidget*);
static void delWindow (FWidget*);
static void swapWindow (FWidget*, FWidget*);
static bool raiseWindow (FWidget*);
bool raiseWindow ();
static bool lowerWindow (FWidget*);
bool lowerWindow ();
bool zoomWindow ();
static void switchToPrevWindow();
static bool activatePrevWindow();
virtual void setShadowSize (int, int);
protected:
static FWindow* previous_window;
// Method
virtual void adjustSize();
private:
// Disable copy constructor
FWindow (const FWindow&);
// Disable assignment operator (=)
FWindow& operator = (const FWindow&);
static void deleteFromAlwaysOnTopList (FWidget*);
static void processAlwaysOnTop();
protected:
// Event handlers
bool event (FEvent*);
virtual void onWindowActive (FEvent*);
@ -74,78 +136,25 @@ class FWindow : public FWidget
virtual void onWindowRaised (FEvent*);
virtual void onWindowLowered (FEvent*);
virtual void adjustSize();
// Data Members
static FWindow* previous_window;
public:
// Constructor
explicit FWindow (FWidget* = 0);
// Destructor
~FWindow ();
private:
// Disable copy constructor
FWindow (const FWindow&);
const char* getClassName() const;
// make every drawBorder from FWidget available
using FWidget::drawBorder;
virtual void drawBorder();
virtual void show();
virtual void hide();
virtual void setX (int, bool = true);
virtual void setY (int, bool = true);
virtual void setPos (int, int, bool = true);
// make every setPos from FWidget available
using FWidget::setPos;
virtual void setWidth (int, bool = true);
virtual void setHeight (int, bool = true);
virtual void setSize (int, int, bool = true);
// make every setGeometry from FWidget available
using FWidget::setGeometry;
void setGeometry (int, int, int, int, bool = true);
virtual void move (int, int);
// make every move from FWidget available
using FWidget::move;
static FWindow* getWindowWidgetAt (const FPoint&);
static FWindow* getWindowWidgetAt (int, int);
static void addWindow (FWidget*);
static void delWindow (FWidget*);
static FWindow* getWindowWidget (FWidget*);
static int getWindowLayer (FWidget*);
static void swapWindow (FWidget*, FWidget*);
static bool raiseWindow (FWidget*);
bool raiseWindow ();
static bool lowerWindow (FWidget*);
bool lowerWindow ();
bool zoomWindow ();
bool isZoomed() const;
bool setWindowWidget (bool);
bool setWindowWidget();
bool unsetWindowWidget();
static FWindow* getActiveWindow();
static void setActiveWindow (FWindow*);
FWidget* getWindowFocusWidget() const;
void setWindowFocusWidget (FWidget*);
static void switchToPrevWindow();
static bool activatePrevWindow();
bool activateWindow (bool);
bool activateWindow();
bool deactivateWindow();
bool isWindowActive() const;
bool isWindowHidden() const;
virtual bool setResizeable (bool);
virtual bool setResizeable();
bool unsetResizeable();
bool isResizeable();
bool setTransparentShadow (bool);
bool setTransparentShadow();
bool unsetTransparentShadow();
bool hasTransparentShadow();
bool setShadow (bool);
bool setShadow();
bool unsetShadow();
bool hasShadow();
virtual void setShadowSize (int, int);
bool setAlwaysOnTop (bool);
bool setAlwaysOnTop();
bool unsetAlwaysOnTop();
bool isAlwaysOnTop();
// Disable assignment operator (=)
FWindow& operator = (const FWindow&);
// Methods
static void deleteFromAlwaysOnTopList (FWidget*);
static void processAlwaysOnTop();
// Data Members
bool window_active;
bool zoomed;
FWidget* win_focus_widget;
FRect normalGeometry;
};
#pragma pack(pop)
@ -155,22 +164,6 @@ class FWindow : public FWidget
inline const char* FWindow::getClassName() const
{ return "FWindow"; }
//----------------------------------------------------------------------
inline FWindow* FWindow::getWindowWidgetAt (const FPoint& pos)
{ return getWindowWidgetAt (pos.getX(), pos.getY()); }
//----------------------------------------------------------------------
inline bool FWindow::raiseWindow()
{ return raiseWindow(this); }
//----------------------------------------------------------------------
inline bool FWindow::lowerWindow()
{ return lowerWindow(this); }
//----------------------------------------------------------------------
inline bool FWindow::isZoomed() const
{ return zoomed; }
//----------------------------------------------------------------------
inline bool FWindow::setWindowWidget()
{ return setWindowWidget(true); }
@ -187,10 +180,6 @@ inline bool FWindow::activateWindow()
inline bool FWindow::deactivateWindow()
{ return activateWindow(false); }
//----------------------------------------------------------------------
inline bool FWindow::isWindowActive() const
{ return window_active; }
//----------------------------------------------------------------------
inline bool FWindow::setResizeable()
{ return setResizeable(true); }
@ -199,10 +188,6 @@ inline bool FWindow::setResizeable()
inline bool FWindow::unsetResizeable()
{ return setResizeable(false); }
//----------------------------------------------------------------------
inline bool FWindow::isResizeable()
{ return ((flags & fc::resizeable) != 0); }
//----------------------------------------------------------------------
inline bool FWindow::setTransparentShadow()
{ return setTransparentShadow(true); }
@ -211,10 +196,6 @@ inline bool FWindow::setTransparentShadow()
inline bool FWindow::unsetTransparentShadow()
{ return setTransparentShadow(false); }
//----------------------------------------------------------------------
inline bool FWindow::hasTransparentShadow()
{ return ((flags & fc::trans_shadow) != 0); }
//----------------------------------------------------------------------
inline bool FWindow::setShadow()
{ return setShadow(true); }
@ -223,10 +204,6 @@ inline bool FWindow::setShadow()
inline bool FWindow::unsetShadow()
{ return setShadow(false); }
//----------------------------------------------------------------------
inline bool FWindow::hasShadow()
{ return ((flags & fc::shadow) != 0); }
//----------------------------------------------------------------------
inline bool FWindow::setAlwaysOnTop()
{ return setAlwaysOnTop(true); }
@ -236,8 +213,39 @@ inline bool FWindow::unsetAlwaysOnTop()
{ return setAlwaysOnTop(false); }
//----------------------------------------------------------------------
inline bool FWindow::isAlwaysOnTop()
inline bool FWindow::isZoomed() const
{ return zoomed; }
//----------------------------------------------------------------------
inline bool FWindow::isWindowActive() const
{ return window_active; }
//----------------------------------------------------------------------
inline bool FWindow::isResizeable() const
{ return ((flags & fc::resizeable) != 0); }
//----------------------------------------------------------------------
inline bool FWindow::isAlwaysOnTop() const
{ return ((flags & fc::always_on_top) != 0); }
//----------------------------------------------------------------------
inline bool FWindow::hasTransparentShadow() const
{ return ((flags & fc::trans_shadow) != 0); }
//----------------------------------------------------------------------
inline bool FWindow::hasShadow() const
{ return ((flags & fc::shadow) != 0); }
//----------------------------------------------------------------------
inline FWindow* FWindow::getWindowWidgetAt (const FPoint& pos)
{ return getWindowWidgetAt (pos.getX(), pos.getY()); }
//----------------------------------------------------------------------
inline bool FWindow::raiseWindow()
{ return raiseWindow(this); }
//----------------------------------------------------------------------
inline bool FWindow::lowerWindow()
{ return lowerWindow(this); }
#endif // _FWINDOW_H

View File

@ -25,17 +25,19 @@ const lDouble PI = 3.141592653589793238L;
class Button : public FButton
{
private:
bool checked;
public:
// Constructor
explicit Button (FWidget* = 0);
// Method
void setChecked(bool);
// Event handler
void onKeyPress (FKeyEvent*);
private:
// Data Member
bool checked;
};
#pragma pack(pop)
@ -91,7 +93,34 @@ void Button::onKeyPress (FKeyEvent* ev)
class Calc : public FDialog
{
public:
// Constructor
explicit Calc (FWidget* parent=0);
// Destructor
~Calc();
// Event handlers
void onKeyPress (FKeyEvent*);
void onAccel (FAccelEvent*);
void onClose (FCloseEvent*);
// Callback method
void cb_buttonClicked (FWidget*, void*);
private:
// Methods
void drawDispay();
virtual void draw();
bool isDataEntryKey(int);
bool isOperatorKey(int);
void setDisplay (lDouble);
void setInfixOperator(char);
void clearInfixOperator();
void calcInfixOperator();
void adjustSize();
// Data Members
bool error;
bool arcus_mode;
bool hyperbolic_mode;
@ -151,31 +180,6 @@ class Calc : public FDialog
std::stack<stack_data> bracket_stack;
std::map<Calc::button, Button*> calculator_buttons;
private:
void drawDispay();
virtual void draw();
bool isDataEntryKey(int);
bool isOperatorKey(int);
void setDisplay (lDouble);
void setInfixOperator(char);
void clearInfixOperator();
void calcInfixOperator();
void adjustSize();
public:
// Constructor
explicit Calc (FWidget* parent=0);
// Destructor
~Calc();
// Event handlers
void onKeyPress (FKeyEvent*);
void onAccel (FAccelEvent*);
void onClose (FCloseEvent*);
// Callback method
void cb_buttonClicked (FWidget*, void*);
};
#pragma pack(pop)

View File

@ -13,19 +13,21 @@
class Mandelbrot : public FDialog
{
private:
virtual void draw();
void adjustSize();
public:
// Constructor
explicit Mandelbrot (FWidget* = 0);
// Destructor
~Mandelbrot();
// Callback methods
void onAccel (FAccelEvent*);
void onClose (FCloseEvent*);
private:
// Methods
virtual void draw();
void adjustSize();
};
#pragma pack(pop)

View File

@ -20,13 +20,23 @@
class Menu : public FDialog
{
public:
// Constructor
explicit Menu (FWidget* = 0);
// Destructor
~Menu();
private:
// Disable copy constructor
Menu (const Menu&);
// Disable assignment operator (=)
Menu& operator = (const Menu&);
// Methods
void defaultCallback (FMenuList*);
void adjustSize();
// Event handler
void onClose (FCloseEvent*);
@ -34,14 +44,6 @@ class Menu : public FDialog
// Callback methods
void cb_message (FWidget*, void*);
void cb_exitApp (FWidget*, void*);
void adjustSize();
public:
// Constructor
explicit Menu (FWidget* = 0);
// Destructor
~Menu();
};
#pragma pack(pop)
@ -204,9 +206,9 @@ Menu::~Menu()
//----------------------------------------------------------------------
void Menu::defaultCallback (FMenuList* mb)
{
for (uInt i=1; i <= mb->count(); i++)
for (uInt i=1; i <= mb->getCount(); i++)
{
FMenuItem* item = mb->item(int(i));
FMenuItem* item = mb->getItem(int(i));
if ( item
&& item->isEnabled()
@ -229,6 +231,16 @@ void Menu::defaultCallback (FMenuList* mb)
}
}
//----------------------------------------------------------------------
void Menu::adjustSize()
{
int pw = getParentWidget()->getWidth();
int ph = getParentWidget()->getHeight();
setX (1 + (pw - getWidth()) / 2, false);
setY (1 + (ph - getHeight()) / 4, false);
FDialog::adjustSize();
}
//----------------------------------------------------------------------
void Menu::onClose (FCloseEvent* ev)
{
@ -259,16 +271,6 @@ void Menu::cb_exitApp (FWidget*, void*)
close();
}
//----------------------------------------------------------------------
void Menu::adjustSize()
{
int pw = getParentWidget()->getWidth();
int ph = getParentWidget()->getHeight();
setX (1 + (pw - getWidth()) / 2, false);
setY (1 + (ph - getHeight()) / 4, false);
FDialog::adjustSize();
}
//----------------------------------------------------------------------
// main part

View File

@ -14,24 +14,10 @@
class AttribDlg : public FDialog
{
private:
FButton* next_button;
FButton* back_button;
public:
short bgcolor;
private:
// Disable copy constructor
AttribDlg (const AttribDlg&);
// Disable assignment operator (=)
AttribDlg& operator = (const AttribDlg&);
void adjustSize();
public:
// Constructor
explicit AttribDlg (FWidget* = 0);
// Destructor
~AttribDlg();
@ -43,15 +29,32 @@ class AttribDlg : public FDialog
// Callback methods
void cb_next (FWidget* = 0, void* = 0);
void cb_back (FWidget* = 0, void* = 0);
// 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;
};
#pragma pack(pop)
//----------------------------------------------------------------------
AttribDlg::AttribDlg (FWidget* parent)
: FDialog(parent)
, bgcolor(wc.label_bg)
, next_button()
, back_button()
, bgcolor(wc.label_bg)
{
resetXTermForeground();
resetXTermBackground();
@ -173,17 +176,10 @@ void AttribDlg::adjustSize()
class AttribDemo : public FWidget
{
private:
int colors;
private:
void printColorLine();
void printAltCharset();
void draw();
public:
// Constructor
explicit AttribDemo (FWidget* = 0);
// Destructor
~AttribDemo()
{ }
@ -192,9 +188,19 @@ class AttribDemo : public FWidget
void onWheel (FWheelEvent* ev)
{
AttribDlg* p = dynamic_cast<AttribDlg*>(getParentWidget());
if ( p )
p->onWheel(ev);
}
private:
// Methods
void printColorLine();
void printAltCharset();
void draw();
// Data Member
int colors;
};
#pragma pack(pop)

View File

@ -13,11 +13,12 @@ class timer : public FWidget
explicit timer (FWidget* = 0);
protected:
// Method
void draw();
// Event handlers
void onTimer (FTimerEvent*);
void onAccel (FAccelEvent*);
void draw();
};
//----------------------------------------------------------------------
@ -36,6 +37,19 @@ timer::timer (FWidget* parent)
wc.term_bg = fc::Default;
}
//----------------------------------------------------------------------
void timer::draw()
{
setNormal();
setColor (fc::Default, fc::Default);
clearArea (vdesktop);
setPrintPos (1,1);
print ("---------------\n");
print ("Press Q to quit\n");
print ("---------------\n");
setAreaCursor (1, 4, true, vdesktop);
}
//----------------------------------------------------------------------
void timer::onTimer (FTimerEvent* ev)
{
@ -66,19 +80,6 @@ void timer::onAccel (FAccelEvent* ev)
ev->accept();
}
//----------------------------------------------------------------------
void timer::draw()
{
setNormal();
setColor (fc::Default, fc::Default);
clearArea (vdesktop);
setPrintPos (1,1);
print ("---------------\n");
print ("Press Q to quit\n");
print ("---------------\n");
setAreaCursor (1, 4, true, vdesktop);
}
//----------------------------------------------------------------------
// main part

View File

@ -18,6 +18,7 @@
class Transparent : public FDialog
{
public:
// Typedef and Enumeration
typedef enum ttype
{
transparent = 0,
@ -25,25 +26,28 @@ class Transparent : public FDialog
inherit_background = 2
} trans_type;
private:
trans_type type;
public:
// Constructor
explicit Transparent (FWidget* = 0, trans_type = transparent);
// Destructor
~Transparent();
private:
// Disable copy constructor
Transparent (const Transparent&);
// Disable assignment operator (=)
Transparent& operator = (const Transparent&);
// Method
void draw();
// Event handlers
void onKeyPress (FKeyEvent* ev);
public:
// Constructor
explicit Transparent (FWidget* = 0, trans_type = transparent);
// Destructor
~Transparent();
// Data Members
trans_type type;
};
#pragma pack(pop)

View File

@ -15,11 +15,11 @@
class ProgressDialog : public FDialog
{
private:
FProgressbar* progressBar;
FButton* reset;
FButton* more;
FButton* quit;
public:
// Constructor
explicit ProgressDialog (FWidget* = 0);
// Destructor
~ProgressDialog();
private:
// Disable copy constructor
@ -36,11 +36,11 @@ class ProgressDialog : public FDialog
void cb_more_bar (FWidget*, void*);
void cb_exit_bar (FWidget*, void*);
public:
// Constructor
explicit ProgressDialog (FWidget* = 0);
// Destructor
~ProgressDialog();
// Data Members
FProgressbar* progressBar;
FButton* reset;
FButton* more;
FButton* quit;
};
#pragma pack(pop)
@ -134,8 +134,8 @@ void ProgressDialog::onTimer (FTimerEvent*)
quit->setEnable();
redraw();
if ( statusBar() )
statusBar()->drawMessage();
if ( getStatusBar() )
getStatusBar()->drawMessage();
updateTerminal();
flush_out();
@ -170,8 +170,13 @@ void ProgressDialog::cb_exit_bar (FWidget*, void*)
class TextWindow : public FDialog
{
private:
FTextView* scrollText;
public:
// Constructor
explicit TextWindow (FWidget* = 0);
// Destructor
~TextWindow();
void append (const FString&);
private:
// Disable copy constructor
@ -181,13 +186,8 @@ class TextWindow : public FDialog
void adjustSize();
public:
// Constructor
explicit TextWindow (FWidget* = 0);
// Destructor
~TextWindow();
void append (const FString&);
// Data Members
FTextView* scrollText;
};
#pragma pack(pop)
@ -238,10 +238,11 @@ void TextWindow::adjustSize()
class MyDialog : public FDialog
{
private:
FLineEdit* myLineEdit;
FListBox* myList;
FString clipboard;
public:
// Constructor
explicit MyDialog (FWidget* = 0);
// Destructor
~MyDialog();
private:
// Disable copy constructor
@ -272,11 +273,10 @@ class MyDialog : public FDialog
void adjustSize();
public:
// Constructor
explicit MyDialog (FWidget* = 0);
// Destructor
~MyDialog();
// Data Members
FLineEdit* myLineEdit;
FListBox* myList;
FString clipboard;
};
#pragma pack(pop)
@ -518,7 +518,7 @@ MyDialog::MyDialog (FWidget* parent)
FLabel* sum_count = new FLabel (this);
sum_count->setGeometry(29, 5, 5, 3);
sum_count->setNumber (myList->count());
sum_count->setNumber (myList->getCount());
// Statusbar at the bottom
FStatusBar* statusbar = new FStatusBar (this);
@ -790,7 +790,7 @@ void MyDialog::cb_updateNumber (FWidget* widget, void* data_ptr)
FListBox* list = static_cast<FListBox*>(widget);
FLabel* num = static_cast<FLabel*>(data_ptr);
int select_num = 0;
uInt end = list->count();
uInt end = list->getCount();
for (uInt n=1; n <= end; n++)
if ( list->isSelected(int(n)) )
@ -858,7 +858,7 @@ void MyDialog::cb_setInput (FWidget* widget, void* data_ptr)
{
FListBox* ListBox = static_cast<FListBox*>(widget);
FLineEdit* lineedit = static_cast<FLineEdit*>(data_ptr);
lineedit->setText( ListBox->Item(ListBox->currentItem()).getText() );
lineedit->setText( ListBox->getItem(ListBox->currentItem()).getText() );
lineedit->redraw();
}

View File

@ -17,27 +17,14 @@
class watch : public FDialog
{
private:
bool sec;
private:
FLabel* time_label;
FLabel* time_str;
FSwitch* clock_sw;
FSwitch* seconds_sw;
private:
// Disable copy constructor
watch (const watch&);
// Disable assignment operator (=)
watch& operator = (const watch&);
public:
// Constructor
explicit watch (FWidget* = 0);
// Destructor
~watch();
// Method
void printTime();
// Event handlers
@ -50,7 +37,22 @@ class watch : public FDialog
void cb_exitApp (FWidget*, void*);
protected:
// Method
void adjustSize();
private:
// Disable copy constructor
watch (const watch&);
// Disable assignment operator (=)
watch& operator = (const watch&);
// Data Members
bool sec;
FLabel* time_label;
FLabel* time_str;
FSwitch* clock_sw;
FSwitch* seconds_sw;
};
#pragma pack(pop)

View File

@ -19,32 +19,33 @@
class smallWindow : public FDialog
{
private:
FLabel* left_arrow;
FLabel* right_arrow;
FLabel* top_left_label;
FLabel* top_right_label;
FLabel* bottom_label;
public:
// Constructor
explicit smallWindow (FWidget* = 0);
// Destructor
~smallWindow();
private:
// Disable copy constructor
smallWindow (const smallWindow&);
// Disable assignment operator (=)
smallWindow& operator = (const smallWindow&);
// Method
void adjustSize();
// Event handlers
void onShow (FShowEvent*);
void onTimer (FTimerEvent*);
public:
// Constructor
explicit smallWindow (FWidget* = 0);
// Destructor
~smallWindow();
void append (const FString&);
// Data Members
FLabel* left_arrow;
FLabel* right_arrow;
FLabel* top_left_label;
FLabel* top_right_label;
FLabel* bottom_label;
};
#pragma pack(pop)
@ -164,7 +165,15 @@ void smallWindow::onTimer (FTimerEvent*)
class Window : public FDialog
{
public:
// Constructor
explicit Window (FWidget* = 0);
// Destructor
~Window();
private:
// Typedef
typedef struct
{
bool is_open;
@ -172,15 +181,16 @@ class Window : public FDialog
FDialog* dgl;
}
win_data;
std::vector<win_data*> windows;
private:
// Disable copy constructor
Window (const Window&);
// Disable assignment operator (=)
Window& operator = (const Window&);
// Method
void activateWindow (FDialog*);
void adjustSize();
// Event handlers
void onClose (FCloseEvent*);
@ -193,13 +203,8 @@ class Window : public FDialog
void cb_exitApp (FWidget*, void*);
void cb_destroyWindow (FWidget*, void*);
void adjustSize();
public:
// Constructor
explicit Window (FWidget* = 0);
// Destructor
~Window();
// Data Members
std::vector<win_data*> windows;
};
#pragma pack(pop)
@ -351,6 +356,41 @@ void Window::activateWindow (FDialog* win)
updateTerminal();
}
//----------------------------------------------------------------------
void Window::adjustSize()
{
int w,h,X,Y,dx,dy;
std::vector<win_data*>::const_iterator iter, begin;
w = getRootWidget()->getWidth();
h = getRootWidget()->getHeight();
X = int(1 + (w - 40) / 2);
Y = int(1 + (h - 22) / 2);
dx = (w > 80) ? (w - 80) / 2 : 0;
dy = (h > 24) ? (h - 24) / 2 : 0;
if ( Y < 2)
Y = 2;
setPos (X, Y);
iter = begin = windows.begin();
while ( iter != windows.end() )
{
if ( (*iter)->is_open )
{
int x,y,n;
n = int(std::distance(begin, iter));
x = dx + 5 + (n%3)*25 + int(n/3)*3;
y = dy + 11 + int(n/3)*3;
(*iter)->dgl->setPos (x, y);
}
++iter;
}
FDialog::adjustSize();
}
//----------------------------------------------------------------------
void Window::onClose (FCloseEvent* ev)
{
@ -524,40 +564,6 @@ void Window::cb_destroyWindow (FWidget*, void* data_ptr)
win_dat->is_open = false;
}
//----------------------------------------------------------------------
void Window::adjustSize()
{
int w,h,X,Y,dx,dy;
std::vector<win_data*>::const_iterator iter, begin;
w = getRootWidget()->getWidth();
h = getRootWidget()->getHeight();
X = int(1 + (w - 40) / 2);
Y = int(1 + (h - 22) / 2);
dx = (w > 80) ? (w - 80) / 2 : 0;
dy = (h > 24) ? (h - 24) / 2 : 0;
if ( Y < 2)
Y = 2;
setPos (X, Y);
iter = begin = windows.begin();
while ( iter != windows.end() )
{
if ( (*iter)->is_open )
{
int x,y,n;
n = int(std::distance(begin, iter));
x = dx + 5 + (n%3)*25 + int(n/3)*3;
y = dy + 11 + int(n/3)*3;
(*iter)->dgl->setPos (x, y);
}
++iter;
}
FDialog::adjustSize();
}
//----------------------------------------------------------------------
// main part