Some code improvements
This commit is contained in:
parent
48e737818c
commit
2a85f7e977
30
src/fapp.cpp
30
src/fapp.cpp
|
@ -157,10 +157,9 @@ void FApplication::quit()
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
bool FApplication::sendEvent(FObject* receiver, FEvent* event)
|
||||
bool FApplication::sendEvent ( const FObject* receiver
|
||||
, const FEvent* event )
|
||||
{
|
||||
FWidget* widget;
|
||||
|
||||
if ( quit_now || app_exit_loop )
|
||||
return false;
|
||||
|
||||
|
@ -170,11 +169,12 @@ bool FApplication::sendEvent(FObject* receiver, FEvent* event)
|
|||
if ( ! receiver->isWidget() )
|
||||
return false;
|
||||
|
||||
widget = static_cast<FWidget*>(receiver);
|
||||
const FWidget* r_widget = static_cast<const FWidget*>(receiver);
|
||||
FWidget* widget = const_cast<FWidget*>(r_widget);
|
||||
|
||||
if ( modal_dialogs > 0 )
|
||||
{
|
||||
FWidget* window;
|
||||
const FWidget* window;
|
||||
if ( widget->isWindowWidget() )
|
||||
window = widget;
|
||||
else
|
||||
|
@ -206,19 +206,21 @@ bool FApplication::sendEvent(FObject* receiver, FEvent* event)
|
|||
}
|
||||
}
|
||||
|
||||
// throw away mouse events to disabled widgets
|
||||
// Throw away mouse events for 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
|
||||
// For access to a protected base class member
|
||||
FApplication* w = const_cast<FApplication*>(static_cast<const FApplication*>(widget));
|
||||
// Sends event event directly to receiver
|
||||
return w->event(const_cast<FEvent*>(event));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FApplication::queueEvent (FObject* receiver, FEvent* event)
|
||||
void FApplication::queueEvent ( const FObject* receiver
|
||||
, const FEvent* event )
|
||||
{
|
||||
if ( ! receiver )
|
||||
return;
|
||||
|
@ -255,7 +257,7 @@ bool FApplication::eventInQueue()
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
bool FApplication::removeQueuedEvent(FObject* receiver)
|
||||
bool FApplication::removeQueuedEvent (const FObject* receiver)
|
||||
{
|
||||
bool retval;
|
||||
eventQueue::iterator iter;
|
||||
|
@ -666,7 +668,7 @@ void FApplication::processKeyboardEvent()
|
|||
// windows keyboard accelerator
|
||||
if ( ! accpt )
|
||||
{
|
||||
FWidget* window = active_window;
|
||||
const FWidget* window = active_window;
|
||||
|
||||
if ( window )
|
||||
accpt = processAccelerator (window);
|
||||
|
@ -675,7 +677,7 @@ void FApplication::processKeyboardEvent()
|
|||
// global keyboard accelerator
|
||||
if ( ! accpt )
|
||||
{
|
||||
FWidget* root_widget = getRootWidget();
|
||||
const FWidget* root_widget = getRootWidget();
|
||||
|
||||
if ( root_widget )
|
||||
processAccelerator (root_widget);
|
||||
|
@ -1022,7 +1024,7 @@ bool FApplication::processDialogSwitchAccelerator()
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
bool FApplication::processAccelerator (FWidget*& widget)
|
||||
bool FApplication::processAccelerator (const FWidget*& widget)
|
||||
{
|
||||
bool accpt = false;
|
||||
|
||||
|
|
10
src/fapp.h
10
src/fapp.h
|
@ -79,16 +79,16 @@ class FApplication : public FWidget
|
|||
void exit_loop();
|
||||
static void exit (int = 0);
|
||||
void quit();
|
||||
static bool sendEvent (FObject*, FEvent*);
|
||||
static void queueEvent (FObject*, FEvent*);
|
||||
static bool sendEvent (const FObject*, const FEvent*);
|
||||
static void queueEvent (const FObject*, const FEvent*);
|
||||
static void sendQueuedEvents ();
|
||||
static bool eventInQueue();
|
||||
static bool removeQueuedEvent(FObject*);
|
||||
static bool removeQueuedEvent(const FObject*);
|
||||
static void print_cmd_Options();
|
||||
|
||||
private:
|
||||
// Typedefs and Enumerations
|
||||
typedef std::pair<FObject*,FEvent*> eventPair;
|
||||
typedef std::pair<const FObject*, const FEvent*> eventPair;
|
||||
typedef std::deque<eventPair> eventQueue;
|
||||
|
||||
enum btn_state
|
||||
|
@ -133,7 +133,7 @@ class FApplication : public FWidget
|
|||
int linuxModifierKeyCorrection (int& key);
|
||||
#endif
|
||||
bool processDialogSwitchAccelerator();
|
||||
bool processAccelerator (FWidget*&);
|
||||
bool processAccelerator (const FWidget*&);
|
||||
void getX11ButtonState (int);
|
||||
bool parseX11Mouse();
|
||||
bool parseSGRMouse();
|
||||
|
|
|
@ -984,9 +984,7 @@ void FDialog::draw()
|
|||
{
|
||||
if ( tooltip && ! getMoveSizeWidget() )
|
||||
{
|
||||
if ( tooltip )
|
||||
delete tooltip;
|
||||
|
||||
delete tooltip;
|
||||
tooltip = 0;
|
||||
}
|
||||
|
||||
|
@ -1342,7 +1340,7 @@ void FDialog::openMenu()
|
|||
dialog_menu->setVisible();
|
||||
drawTitleBar();
|
||||
dialog_menu->show();
|
||||
dialog_menu->raiseWindow(dialog_menu);
|
||||
dialog_menu->raiseWindow();
|
||||
dialog_menu->redraw();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -984,7 +984,9 @@ FMenu* FMenu::superMenuAt (int x, int y)
|
|||
else
|
||||
{
|
||||
FMenu* smenu = dynamic_cast<FMenu*>(getSuperMenu());
|
||||
return smenu->superMenuAt(x,y);
|
||||
|
||||
if ( smenu )
|
||||
return smenu->superMenuAt(x,y);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -283,7 +283,7 @@ void FMenuItem::openMenu()
|
|||
setOpenMenu(dd_menu);
|
||||
dd_menu->setVisible();
|
||||
dd_menu->show();
|
||||
dd_menu->raiseWindow(dd_menu);
|
||||
dd_menu->raiseWindow();
|
||||
dd_menu->redraw();
|
||||
updateTerminal();
|
||||
flush_out();
|
||||
|
|
|
@ -58,9 +58,9 @@ FMessageBox::FMessageBox (const FMessageBox& mbox)
|
|||
, button()
|
||||
{
|
||||
setTitlebarText (mbox.getTitlebarText());
|
||||
init ( *mbox.button_digit[0]
|
||||
, *mbox.button_digit[1]
|
||||
, *mbox.button_digit[2] );
|
||||
init ( mbox.button_digit[0]
|
||||
, mbox.button_digit[1]
|
||||
, mbox.button_digit[2] );
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -92,10 +92,6 @@ FMessageBox::~FMessageBox() // destructor
|
|||
{
|
||||
for (uInt n=0; n < num_buttons; n++)
|
||||
delete button[n];
|
||||
|
||||
delete button_digit[2];
|
||||
delete button_digit[1];
|
||||
delete button_digit[0];
|
||||
}
|
||||
|
||||
|
||||
|
@ -112,10 +108,6 @@ FMessageBox& FMessageBox::operator = (const FMessageBox& mbox)
|
|||
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);
|
||||
|
||||
|
@ -130,9 +122,9 @@ FMessageBox& FMessageBox::operator = (const FMessageBox& mbox)
|
|||
text_num_lines = mbox.text_num_lines;
|
||||
|
||||
setTitlebarText (mbox.getTitlebarText());
|
||||
init ( *mbox.button_digit[0]
|
||||
, *mbox.button_digit[1]
|
||||
, *mbox.button_digit[2] );
|
||||
init ( mbox.button_digit[0]
|
||||
, mbox.button_digit[1]
|
||||
, mbox.button_digit[2] );
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
@ -160,10 +152,10 @@ void FMessageBox::setText (const FString& txt)
|
|||
calculateDimensions();
|
||||
button[0]->setY(getHeight()-4, false);
|
||||
|
||||
if ( *button_digit[1] != 0 )
|
||||
if ( button_digit[1] != 0 )
|
||||
button[1]->setY(getHeight()-4, false);
|
||||
|
||||
if ( *button_digit[2] != 0 )
|
||||
if ( button_digit[2] != 0 )
|
||||
button[2]->setY(getHeight()-4, false);
|
||||
|
||||
adjustButtons();
|
||||
|
@ -282,9 +274,9 @@ void FMessageBox::init (int button0, int button1, int button2)
|
|||
else
|
||||
num_buttons = 3;
|
||||
|
||||
button_digit[0] = new int(button0);
|
||||
button_digit[1] = new int(button1);
|
||||
button_digit[2] = new int(button2);
|
||||
button_digit[0] = button0;
|
||||
button_digit[1] = button1;
|
||||
button_digit[2] = button2;
|
||||
|
||||
button[0] = new FButton (this);
|
||||
button[0]->setText(button_text[button0]);
|
||||
|
@ -314,33 +306,33 @@ void FMessageBox::init (int button0, int button1, int button2)
|
|||
resizeButtons();
|
||||
adjustButtons();
|
||||
|
||||
if ( *button_digit[0] != 0 )
|
||||
if ( button_digit[0] != 0 )
|
||||
{
|
||||
button[0]->addCallback
|
||||
(
|
||||
"clicked",
|
||||
F_METHOD_CALLBACK (this, &FMessageBox::cb_processClick),
|
||||
static_cast<FWidget::data_ptr>(button_digit[0])
|
||||
static_cast<FWidget::data_ptr>(&button_digit[0])
|
||||
);
|
||||
}
|
||||
|
||||
if ( *button_digit[1] != 0 )
|
||||
if ( button_digit[1] != 0 )
|
||||
{
|
||||
button[1]->addCallback
|
||||
(
|
||||
"clicked",
|
||||
F_METHOD_CALLBACK (this, &FMessageBox::cb_processClick),
|
||||
static_cast<FWidget::data_ptr>(button_digit[1])
|
||||
static_cast<FWidget::data_ptr>(&button_digit[1])
|
||||
);
|
||||
}
|
||||
|
||||
if ( *button_digit[2] != 0 )
|
||||
if ( button_digit[2] != 0 )
|
||||
{
|
||||
button[2]->addCallback
|
||||
(
|
||||
"clicked",
|
||||
F_METHOD_CALLBACK (this, &FMessageBox::cb_processClick),
|
||||
static_cast<FWidget::data_ptr>(button_digit[2])
|
||||
static_cast<FWidget::data_ptr>(&button_digit[2])
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ class FMessageBox : public FDialog
|
|||
short emphasis_color;
|
||||
uInt num_buttons;
|
||||
uInt text_num_lines;
|
||||
int* button_digit[3];
|
||||
int button_digit[3];
|
||||
FButton* button[3];
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
|
|
@ -293,7 +293,7 @@ bool FObject::event (FEvent* ev)
|
|||
{
|
||||
if ( ev->type() == fc::Timer_Event )
|
||||
{
|
||||
onTimer ( static_cast<FTimerEvent*>(ev) );
|
||||
onTimer ( const_cast<FTimerEvent*>(static_cast<const FTimerEvent*>(ev)) );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ class FScrollView : public FWidget
|
|||
virtual void clearArea (int = ' ');
|
||||
void scrollToX (int);
|
||||
void scrollToY (int);
|
||||
void scrollTo (FPoint);
|
||||
void scrollTo (const FPoint&);
|
||||
void scrollTo (int, int);
|
||||
void scrollBy (int, int);
|
||||
virtual void draw();
|
||||
|
@ -219,7 +219,7 @@ inline bool FScrollView::isViewportPrint()
|
|||
{ return ! use_own_print_area; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FScrollView::scrollTo (FPoint pos)
|
||||
inline void FScrollView::scrollTo (const FPoint& pos)
|
||||
{ scrollTo(pos.getX(), pos.getY()); }
|
||||
|
||||
|
||||
|
|
|
@ -1281,7 +1281,7 @@ bool FString::operator == (const FString& s) const
|
|||
if ( ! s )
|
||||
return false;
|
||||
|
||||
if ( (string && ! s.string ) || (! string && s.string) )
|
||||
if ( bool(string) != bool(s.string) )
|
||||
return false;
|
||||
|
||||
if ( ! (string || s.string) )
|
||||
|
@ -1338,7 +1338,7 @@ bool FString::operator != (const FString& s) const
|
|||
if ( ! s )
|
||||
return true;
|
||||
|
||||
if ( (string && ! s.string ) || (! string && s.string) )
|
||||
if ( bool(string) != bool(s.string) )
|
||||
return true;
|
||||
|
||||
if ( ! (string || s.string) )
|
||||
|
|
|
@ -1401,7 +1401,10 @@ void FTerm::setEncoding (std::string enc)
|
|||
case fc::PC:
|
||||
if ( xterm_terminal && utf8_console )
|
||||
Fputchar = &FTerm::putchar_UTF8;
|
||||
// fall through
|
||||
else
|
||||
Fputchar = &FTerm::putchar_ASCII;
|
||||
break;
|
||||
|
||||
case fc::ASCII:
|
||||
default:
|
||||
Fputchar = &FTerm::putchar_ASCII;
|
||||
|
@ -2650,15 +2653,22 @@ char* FTerm::parseSecDA (char*& current_termtype)
|
|||
char* new_termtype = current_termtype;
|
||||
bool sec_da_supported = false;
|
||||
|
||||
|
||||
// The Linux console knows no Sec_DA
|
||||
if ( linux_terminal )
|
||||
return new_termtype;
|
||||
|
||||
// secondary device attributes (SEC_DA) <- decTerminalID string
|
||||
sec_da = new FString(getSecDA());
|
||||
try
|
||||
{
|
||||
// secondary device attributes (SEC_DA) <- decTerminalID string
|
||||
sec_da = new FString(getSecDA());
|
||||
}
|
||||
|
||||
if ( sec_da && sec_da->getLength() > 5 )
|
||||
catch (const std::bad_alloc&)
|
||||
{
|
||||
return new_termtype;
|
||||
}
|
||||
|
||||
if ( sec_da->getLength() > 5 )
|
||||
{
|
||||
uLong num_components;
|
||||
|
||||
|
@ -2776,7 +2786,7 @@ char* FTerm::parseSecDA (char*& current_termtype)
|
|||
force_vt100 = true; // this rxvt terminal support on utf-8
|
||||
|
||||
if ( std::strncmp(termtype, "rxvt-", 5) != 0
|
||||
|| std::strncmp(termtype, "rxvt-cygwin-native", 5) == 0 )
|
||||
&& std::strncmp(termtype, "rxvt-cygwin-native", 18) == 0 )
|
||||
new_termtype = const_cast<char*>("rxvt-16color");
|
||||
break;
|
||||
|
||||
|
|
|
@ -307,7 +307,7 @@ class FTerm
|
|||
static bool isGpmMouseEnabled();
|
||||
#endif // F_HAVE_LIBGPM
|
||||
static FPoint& getMousePos();
|
||||
static void setMousePos (FPoint&);
|
||||
static void setMousePos (const FPoint&);
|
||||
static void setMousePos (short, short);
|
||||
|
||||
// Data Members
|
||||
|
@ -701,7 +701,7 @@ inline FPoint& FTerm::getMousePos()
|
|||
{ return *mouse; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FTerm::setMousePos (FPoint& m)
|
||||
inline void FTerm::setMousePos (const FPoint& m)
|
||||
{ *mouse = m; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
|
|
@ -490,8 +490,7 @@ int FVTerm::print (term_area* area, const FString& s)
|
|||
nc.no_changes = false;
|
||||
nc.printed = false;
|
||||
|
||||
if ( area
|
||||
&& area->cursor_x > 0
|
||||
if ( area->cursor_x > 0
|
||||
&& area->cursor_y > 0
|
||||
&& ax < area->width + area->right_shadow
|
||||
&& ay < area->height + area->bottom_shadow )
|
||||
|
@ -627,8 +626,7 @@ int FVTerm::print (term_area* area, const std::vector<char_data>& termString)
|
|||
|
||||
char_data nc = *iter; // next character
|
||||
|
||||
if ( area
|
||||
&& area->cursor_x > 0
|
||||
if ( area->cursor_x > 0
|
||||
&& area->cursor_y > 0
|
||||
&& ax < area->width + area->right_shadow
|
||||
&& ay < area->height + area->bottom_shadow )
|
||||
|
|
|
@ -136,10 +136,10 @@ void FWindow::setActiveWindow (FWindow* window)
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FWindow::setWindowFocusWidget (FWidget* obj)
|
||||
void FWindow::setWindowFocusWidget (const FWidget* obj)
|
||||
{
|
||||
// set focus widget of this window
|
||||
win_focus_widget = obj;
|
||||
win_focus_widget = const_cast<FWidget*>(obj);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -500,7 +500,7 @@ void FWindow::delWindow (FWidget* obj)
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
FWindow* FWindow::getWindowWidget (FWidget* obj)
|
||||
FWindow* FWindow::getWindowWidget (const FWidget* obj)
|
||||
{
|
||||
// returns the window object to the given widget obj
|
||||
FWidget* p_obj = obj->getParentWidget();
|
||||
|
@ -512,17 +512,17 @@ FWindow* FWindow::getWindowWidget (FWidget* obj)
|
|||
}
|
||||
|
||||
if ( obj->isWindowWidget() )
|
||||
return static_cast<FWindow*>(obj);
|
||||
return const_cast<FWindow*>(static_cast<const FWindow*>(obj));
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
int FWindow::getWindowLayer (FWidget* obj)
|
||||
int FWindow::getWindowLayer (const FWidget* obj)
|
||||
{
|
||||
// returns the window layer from the widget obj
|
||||
widgetList::iterator iter, end;
|
||||
FWidget* window;
|
||||
const FWidget* window;
|
||||
|
||||
if ( ! window_list )
|
||||
return -1;
|
||||
|
|
|
@ -63,8 +63,8 @@ class FWindow : public FWidget
|
|||
|
||||
// Accessors
|
||||
const char* getClassName() const;
|
||||
static FWindow* getWindowWidget (FWidget*);
|
||||
static int getWindowLayer (FWidget*);
|
||||
static FWindow* getWindowWidget (const FWidget*);
|
||||
static int getWindowLayer (const FWidget*);
|
||||
static FWindow* getActiveWindow();
|
||||
FWidget* getWindowFocusWidget() const;
|
||||
|
||||
|
@ -73,7 +73,7 @@ class FWindow : public FWidget
|
|||
bool setWindowWidget();
|
||||
bool unsetWindowWidget();
|
||||
static void setActiveWindow (FWindow*);
|
||||
void setWindowFocusWidget (FWidget*);
|
||||
void setWindowFocusWidget (const FWidget*);
|
||||
bool activateWindow (bool);
|
||||
bool activateWindow();
|
||||
void unsetActiveWindow();
|
||||
|
|
Loading…
Reference in New Issue