Some code improvements

This commit is contained in:
Markus Gans 2017-08-12 20:10:27 +02:00
parent 48e737818c
commit 2a85f7e977
15 changed files with 79 additions and 77 deletions

View File

@ -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 ) if ( quit_now || app_exit_loop )
return false; return false;
@ -170,11 +169,12 @@ bool FApplication::sendEvent(FObject* receiver, FEvent* event)
if ( ! receiver->isWidget() ) if ( ! receiver->isWidget() )
return false; 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 ) if ( modal_dialogs > 0 )
{ {
FWidget* window; const FWidget* window;
if ( widget->isWindowWidget() ) if ( widget->isWindowWidget() )
window = widget; window = widget;
else 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 if ( event->type() >= fc::MouseDown_Event
&& event->type() <= fc::MouseMove_Event && event->type() <= fc::MouseMove_Event
&& ! widget->isEnabled() ) && ! widget->isEnabled() )
return false; return false;
// sends event event directly to receiver // For access to a protected base class member
FApplication* w = static_cast<FApplication*>(widget); FApplication* w = const_cast<FApplication*>(static_cast<const FApplication*>(widget));
return w->event(event); // access to a protected base class member // 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 ) if ( ! receiver )
return; return;
@ -255,7 +257,7 @@ bool FApplication::eventInQueue()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FApplication::removeQueuedEvent(FObject* receiver) bool FApplication::removeQueuedEvent (const FObject* receiver)
{ {
bool retval; bool retval;
eventQueue::iterator iter; eventQueue::iterator iter;
@ -666,7 +668,7 @@ void FApplication::processKeyboardEvent()
// windows keyboard accelerator // windows keyboard accelerator
if ( ! accpt ) if ( ! accpt )
{ {
FWidget* window = active_window; const FWidget* window = active_window;
if ( window ) if ( window )
accpt = processAccelerator (window); accpt = processAccelerator (window);
@ -675,7 +677,7 @@ void FApplication::processKeyboardEvent()
// global keyboard accelerator // global keyboard accelerator
if ( ! accpt ) if ( ! accpt )
{ {
FWidget* root_widget = getRootWidget(); const FWidget* root_widget = getRootWidget();
if ( root_widget ) if ( root_widget )
processAccelerator (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; bool accpt = false;

View File

@ -79,16 +79,16 @@ class FApplication : public FWidget
void exit_loop(); void exit_loop();
static void exit (int = 0); static void exit (int = 0);
void quit(); void quit();
static bool sendEvent (FObject*, FEvent*); static bool sendEvent (const FObject*, const FEvent*);
static void queueEvent (FObject*, FEvent*); static void queueEvent (const FObject*, const FEvent*);
static void sendQueuedEvents (); static void sendQueuedEvents ();
static bool eventInQueue(); static bool eventInQueue();
static bool removeQueuedEvent(FObject*); static bool removeQueuedEvent(const FObject*);
static void print_cmd_Options(); static void print_cmd_Options();
private: private:
// Typedefs and Enumerations // Typedefs and Enumerations
typedef std::pair<FObject*,FEvent*> eventPair; typedef std::pair<const FObject*, const FEvent*> eventPair;
typedef std::deque<eventPair> eventQueue; typedef std::deque<eventPair> eventQueue;
enum btn_state enum btn_state
@ -133,7 +133,7 @@ class FApplication : public FWidget
int linuxModifierKeyCorrection (int& key); int linuxModifierKeyCorrection (int& key);
#endif #endif
bool processDialogSwitchAccelerator(); bool processDialogSwitchAccelerator();
bool processAccelerator (FWidget*&); bool processAccelerator (const FWidget*&);
void getX11ButtonState (int); void getX11ButtonState (int);
bool parseX11Mouse(); bool parseX11Mouse();
bool parseSGRMouse(); bool parseSGRMouse();

View File

@ -984,9 +984,7 @@ void FDialog::draw()
{ {
if ( tooltip && ! getMoveSizeWidget() ) if ( tooltip && ! getMoveSizeWidget() )
{ {
if ( tooltip ) delete tooltip;
delete tooltip;
tooltip = 0; tooltip = 0;
} }
@ -1342,7 +1340,7 @@ void FDialog::openMenu()
dialog_menu->setVisible(); dialog_menu->setVisible();
drawTitleBar(); drawTitleBar();
dialog_menu->show(); dialog_menu->show();
dialog_menu->raiseWindow(dialog_menu); dialog_menu->raiseWindow();
dialog_menu->redraw(); dialog_menu->redraw();
} }
} }

View File

@ -984,7 +984,9 @@ FMenu* FMenu::superMenuAt (int x, int y)
else else
{ {
FMenu* smenu = dynamic_cast<FMenu*>(getSuperMenu()); FMenu* smenu = dynamic_cast<FMenu*>(getSuperMenu());
return smenu->superMenuAt(x,y);
if ( smenu )
return smenu->superMenuAt(x,y);
} }
} }

View File

@ -283,7 +283,7 @@ void FMenuItem::openMenu()
setOpenMenu(dd_menu); setOpenMenu(dd_menu);
dd_menu->setVisible(); dd_menu->setVisible();
dd_menu->show(); dd_menu->show();
dd_menu->raiseWindow(dd_menu); dd_menu->raiseWindow();
dd_menu->redraw(); dd_menu->redraw();
updateTerminal(); updateTerminal();
flush_out(); flush_out();

View File

@ -58,9 +58,9 @@ FMessageBox::FMessageBox (const FMessageBox& mbox)
, button() , button()
{ {
setTitlebarText (mbox.getTitlebarText()); setTitlebarText (mbox.getTitlebarText());
init ( *mbox.button_digit[0] init ( mbox.button_digit[0]
, *mbox.button_digit[1] , mbox.button_digit[1]
, *mbox.button_digit[2] ); , mbox.button_digit[2] );
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -92,10 +92,6 @@ FMessageBox::~FMessageBox() // destructor
{ {
for (uInt n=0; n < num_buttons; n++) for (uInt n=0; n < num_buttons; n++)
delete button[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++) for (uInt n=0; n < num_buttons; n++)
delete button[n]; delete button[n];
delete button_digit[2];
delete button_digit[1];
delete button_digit[0];
if ( mbox.getParentWidget() ) if ( mbox.getParentWidget() )
mbox.getParentWidget()->addChild (this); mbox.getParentWidget()->addChild (this);
@ -130,9 +122,9 @@ FMessageBox& FMessageBox::operator = (const FMessageBox& mbox)
text_num_lines = mbox.text_num_lines; text_num_lines = mbox.text_num_lines;
setTitlebarText (mbox.getTitlebarText()); setTitlebarText (mbox.getTitlebarText());
init ( *mbox.button_digit[0] init ( mbox.button_digit[0]
, *mbox.button_digit[1] , mbox.button_digit[1]
, *mbox.button_digit[2] ); , mbox.button_digit[2] );
return *this; return *this;
} }
@ -160,10 +152,10 @@ void FMessageBox::setText (const FString& txt)
calculateDimensions(); calculateDimensions();
button[0]->setY(getHeight()-4, false); button[0]->setY(getHeight()-4, false);
if ( *button_digit[1] != 0 ) if ( button_digit[1] != 0 )
button[1]->setY(getHeight()-4, false); button[1]->setY(getHeight()-4, false);
if ( *button_digit[2] != 0 ) if ( button_digit[2] != 0 )
button[2]->setY(getHeight()-4, false); button[2]->setY(getHeight()-4, false);
adjustButtons(); adjustButtons();
@ -282,9 +274,9 @@ void FMessageBox::init (int button0, int button1, int button2)
else else
num_buttons = 3; num_buttons = 3;
button_digit[0] = new int(button0); button_digit[0] = button0;
button_digit[1] = new int(button1); button_digit[1] = button1;
button_digit[2] = new int(button2); button_digit[2] = button2;
button[0] = new FButton (this); button[0] = new FButton (this);
button[0]->setText(button_text[button0]); button[0]->setText(button_text[button0]);
@ -314,33 +306,33 @@ void FMessageBox::init (int button0, int button1, int button2)
resizeButtons(); resizeButtons();
adjustButtons(); adjustButtons();
if ( *button_digit[0] != 0 ) if ( button_digit[0] != 0 )
{ {
button[0]->addCallback button[0]->addCallback
( (
"clicked", "clicked",
F_METHOD_CALLBACK (this, &FMessageBox::cb_processClick), 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 button[1]->addCallback
( (
"clicked", "clicked",
F_METHOD_CALLBACK (this, &FMessageBox::cb_processClick), 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 button[2]->addCallback
( (
"clicked", "clicked",
F_METHOD_CALLBACK (this, &FMessageBox::cb_processClick), F_METHOD_CALLBACK (this, &FMessageBox::cb_processClick),
static_cast<FWidget::data_ptr>(button_digit[2]) static_cast<FWidget::data_ptr>(&button_digit[2])
); );
} }

View File

@ -142,7 +142,7 @@ class FMessageBox : public FDialog
short emphasis_color; short emphasis_color;
uInt num_buttons; uInt num_buttons;
uInt text_num_lines; uInt text_num_lines;
int* button_digit[3]; int button_digit[3];
FButton* button[3]; FButton* button[3];
}; };
#pragma pack(pop) #pragma pack(pop)

View File

@ -293,7 +293,7 @@ bool FObject::event (FEvent* ev)
{ {
if ( ev->type() == fc::Timer_Event ) if ( ev->type() == fc::Timer_Event )
{ {
onTimer ( static_cast<FTimerEvent*>(ev) ); onTimer ( const_cast<FTimerEvent*>(static_cast<const FTimerEvent*>(ev)) );
return true; return true;
} }

View File

@ -94,7 +94,7 @@ class FScrollView : public FWidget
virtual void clearArea (int = ' '); virtual void clearArea (int = ' ');
void scrollToX (int); void scrollToX (int);
void scrollToY (int); void scrollToY (int);
void scrollTo (FPoint); void scrollTo (const FPoint&);
void scrollTo (int, int); void scrollTo (int, int);
void scrollBy (int, int); void scrollBy (int, int);
virtual void draw(); virtual void draw();
@ -219,7 +219,7 @@ inline bool FScrollView::isViewportPrint()
{ return ! use_own_print_area; } { return ! use_own_print_area; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FScrollView::scrollTo (FPoint pos) inline void FScrollView::scrollTo (const FPoint& pos)
{ scrollTo(pos.getX(), pos.getY()); } { scrollTo(pos.getX(), pos.getY()); }

View File

@ -1281,7 +1281,7 @@ bool FString::operator == (const FString& s) const
if ( ! s ) if ( ! s )
return false; return false;
if ( (string && ! s.string ) || (! string && s.string) ) if ( bool(string) != bool(s.string) )
return false; return false;
if ( ! (string || s.string) ) if ( ! (string || s.string) )
@ -1338,7 +1338,7 @@ bool FString::operator != (const FString& s) const
if ( ! s ) if ( ! s )
return true; return true;
if ( (string && ! s.string ) || (! string && s.string) ) if ( bool(string) != bool(s.string) )
return true; return true;
if ( ! (string || s.string) ) if ( ! (string || s.string) )

View File

@ -1401,7 +1401,10 @@ void FTerm::setEncoding (std::string enc)
case fc::PC: case fc::PC:
if ( xterm_terminal && utf8_console ) if ( xterm_terminal && utf8_console )
Fputchar = &FTerm::putchar_UTF8; Fputchar = &FTerm::putchar_UTF8;
// fall through else
Fputchar = &FTerm::putchar_ASCII;
break;
case fc::ASCII: case fc::ASCII:
default: default:
Fputchar = &FTerm::putchar_ASCII; Fputchar = &FTerm::putchar_ASCII;
@ -2650,15 +2653,22 @@ char* FTerm::parseSecDA (char*& current_termtype)
char* new_termtype = current_termtype; char* new_termtype = current_termtype;
bool sec_da_supported = false; bool sec_da_supported = false;
// The Linux console knows no Sec_DA // The Linux console knows no Sec_DA
if ( linux_terminal ) if ( linux_terminal )
return new_termtype; return new_termtype;
// secondary device attributes (SEC_DA) <- decTerminalID string try
sec_da = new FString(getSecDA()); {
// 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; uLong num_components;
@ -2776,7 +2786,7 @@ char* FTerm::parseSecDA (char*& current_termtype)
force_vt100 = true; // this rxvt terminal support on utf-8 force_vt100 = true; // this rxvt terminal support on utf-8
if ( std::strncmp(termtype, "rxvt-", 5) != 0 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"); new_termtype = const_cast<char*>("rxvt-16color");
break; break;

View File

@ -307,7 +307,7 @@ class FTerm
static bool isGpmMouseEnabled(); static bool isGpmMouseEnabled();
#endif // F_HAVE_LIBGPM #endif // F_HAVE_LIBGPM
static FPoint& getMousePos(); static FPoint& getMousePos();
static void setMousePos (FPoint&); static void setMousePos (const FPoint&);
static void setMousePos (short, short); static void setMousePos (short, short);
// Data Members // Data Members
@ -701,7 +701,7 @@ inline FPoint& FTerm::getMousePos()
{ return *mouse; } { return *mouse; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FTerm::setMousePos (FPoint& m) inline void FTerm::setMousePos (const FPoint& m)
{ *mouse = m; } { *mouse = m; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -490,8 +490,7 @@ int FVTerm::print (term_area* area, const FString& s)
nc.no_changes = false; nc.no_changes = false;
nc.printed = false; nc.printed = false;
if ( area if ( area->cursor_x > 0
&& area->cursor_x > 0
&& area->cursor_y > 0 && area->cursor_y > 0
&& ax < area->width + area->right_shadow && ax < area->width + area->right_shadow
&& ay < area->height + area->bottom_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 char_data nc = *iter; // next character
if ( area if ( area->cursor_x > 0
&& area->cursor_x > 0
&& area->cursor_y > 0 && area->cursor_y > 0
&& ax < area->width + area->right_shadow && ax < area->width + area->right_shadow
&& ay < area->height + area->bottom_shadow ) && ay < area->height + area->bottom_shadow )

View File

@ -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 // 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 // returns the window object to the given widget obj
FWidget* p_obj = obj->getParentWidget(); FWidget* p_obj = obj->getParentWidget();
@ -512,17 +512,17 @@ FWindow* FWindow::getWindowWidget (FWidget* obj)
} }
if ( obj->isWindowWidget() ) if ( obj->isWindowWidget() )
return static_cast<FWindow*>(obj); return const_cast<FWindow*>(static_cast<const FWindow*>(obj));
else else
return 0; return 0;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int FWindow::getWindowLayer (FWidget* obj) int FWindow::getWindowLayer (const FWidget* obj)
{ {
// returns the window layer from the widget obj // returns the window layer from the widget obj
widgetList::iterator iter, end; widgetList::iterator iter, end;
FWidget* window; const FWidget* window;
if ( ! window_list ) if ( ! window_list )
return -1; return -1;

View File

@ -63,8 +63,8 @@ class FWindow : public FWidget
// Accessors // Accessors
const char* getClassName() const; const char* getClassName() const;
static FWindow* getWindowWidget (FWidget*); static FWindow* getWindowWidget (const FWidget*);
static int getWindowLayer (FWidget*); static int getWindowLayer (const FWidget*);
static FWindow* getActiveWindow(); static FWindow* getActiveWindow();
FWidget* getWindowFocusWidget() const; FWidget* getWindowFocusWidget() const;
@ -73,7 +73,7 @@ class FWindow : public FWidget
bool setWindowWidget(); bool setWindowWidget();
bool unsetWindowWidget(); bool unsetWindowWidget();
static void setActiveWindow (FWindow*); static void setActiveWindow (FWindow*);
void setWindowFocusWidget (FWidget*); void setWindowFocusWidget (const FWidget*);
bool activateWindow (bool); bool activateWindow (bool);
bool activateWindow(); bool activateWindow();
void unsetActiveWindow(); void unsetActiveWindow();