Refactoring of some functions

This commit is contained in:
Markus Gans 2018-02-24 18:13:42 +01:00
parent 1435d9d362
commit e0f4872d6e
6 changed files with 253 additions and 204 deletions

View File

@ -25,7 +25,8 @@
// function prototypes // function prototypes
void cb_quit (FWidget*, FWidget::data_ptr); void cb_quit (FWidget*, FWidget::data_ptr);
void populateChoice (std::vector<FRadioButton*>&, FButtonGroup*);
void preset (std::vector<FRadioButton*>&);
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// callback functions // callback functions
@ -36,6 +37,52 @@ void cb_quit (FWidget*, FWidget::data_ptr data)
dlg->close(); dlg->close();
} }
//----------------------------------------------------------------------
void populateChoice (std::vector<FRadioButton*>& os, FButtonGroup* group)
{
os[0] = new FRadioButton("AIX", group);
os[1] = new FRadioButton("Cygwin", group);
os[2] = new FRadioButton("FreeBSD", group);
os[3] = new FRadioButton("HP-UX", group);
os[4] = new FRadioButton("Linux", group);
os[5] = new FRadioButton("Mac OS X", group);
os[6] = new FRadioButton("NetBSD", group);
os[7] = new FRadioButton("OpenBSD", group);
os[8] = new FRadioButton("Solaris", group);
}
//----------------------------------------------------------------------
void preset (std::vector<FRadioButton*>& os)
{
#if defined(_AIX)
os[0]->setChecked();
os[0]->setFocus();
#elif defined(__CYGWIN__)
os[1]->setChecked();
os[1]->setFocus();
#elif defined(__FreeBSD__)
os[2]->setChecked();
os[2]->setFocus();
#elif defined(__hpux)
os[3]->setChecked();
os[3]->setFocus();
#elif defined(__linux__)
os[4]->setChecked();
os[4]->setFocus();
#elif defined(__APPLE__) && defined(__MACH__)
os[5]->setChecked();
os[5]->setFocus();
#elif defined(__NetBSD__)
os[6]->setChecked();
os[6]->setFocus();
#elif defined(__OpenBSD__)
os[7]->setChecked();
os[7]->setFocus();
#elif defined(__sun) && defined(__SVR4)
os[8]->setChecked();
os[8]->setFocus();
#endif
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// main part // main part
@ -63,57 +110,16 @@ int main (int argc, char* argv[])
checkButtonGroup->setGeometry (2, 1, 16, 7); checkButtonGroup->setGeometry (2, 1, 16, 7);
// Create radio buttons // Create radio buttons
FRadioButton* os1 = new FRadioButton("AIX", checkButtonGroup); std::vector<FRadioButton*> os (9);
FRadioButton* os2 = new FRadioButton("Cygwin", checkButtonGroup); populateChoice (os, checkButtonGroup);
FRadioButton* os3 = new FRadioButton("FreeBSD", checkButtonGroup);
FRadioButton* os4 = new FRadioButton("HP-UX", checkButtonGroup);
FRadioButton* os5 = new FRadioButton("Linux", checkButtonGroup);
FRadioButton* os6 = new FRadioButton("Mac OS X", checkButtonGroup);
FRadioButton* os7 = new FRadioButton("NetBSD", checkButtonGroup);
FRadioButton* os8 = new FRadioButton("OpenBSD", checkButtonGroup);
FRadioButton* os9 = new FRadioButton("Solaris", checkButtonGroup);
// Set the radio button geometry // Set the radio button geometry
// => checkButtonGroup->setScrollSize(...) is not required // => checkButtonGroup->setScrollSize(...) is not required
// because a FButtonGroup is self-adjusting // because a FButtonGroup is self-adjusting
os1->setGeometry(1, 1, 12, 1); for (uInt i = 0; i < os.size(); i++)
os2->setGeometry(1, 2, 12, 1); os[i]->setGeometry(1, int(1 + i), 12, 1);
os3->setGeometry(1, 3, 12, 1);
os4->setGeometry(1, 4, 12, 1);
os5->setGeometry(1, 5, 12, 1);
os6->setGeometry(1, 6, 12, 1);
os7->setGeometry(1, 7, 12, 1);
os8->setGeometry(1, 8, 12, 1);
os9->setGeometry(1, 9, 12, 1);
#if defined(_AIX) preset(os);
os1->setChecked();
os1->setFocus();
#elif defined(__CYGWIN__)
os2->setChecked();
os2->setFocus();
#elif defined(__FreeBSD__)
os3->setChecked();
os3->setFocus();
#elif defined(__hpux)
os4->setChecked();
os4->setFocus();
#elif defined(__linux__)
os5->setChecked();
os5->setFocus();
#elif defined(__APPLE__) && defined(__MACH__)
os6->setChecked();
os6->setFocus();
#elif defined(__NetBSD__)
os7->setChecked();
os7->setFocus();
#elif defined(__OpenBSD__)
os8->setChecked();
os8->setFocus();
#elif defined(__sun) && defined(__SVR4)
os9->setChecked();
os9->setFocus();
#endif
// Scroll to the focused child element // Scroll to the focused child element
FFocusEvent cfi (fc::ChildFocusIn_Event); FFocusEvent cfi (fc::ChildFocusIn_Event);

View File

@ -274,6 +274,10 @@ class MyDialog : public FDialog
// Method // Method
void initMenu(); void initMenu();
void initMenuCallbacks(); void initMenuCallbacks();
void initFileMenuCallbacks();
void initEditMenuCallbacks();
void initViewMenuCallbacks();
void initHelpMenuCallback();
void initStatusBar(); void initStatusBar();
void initStatusBarCallbacks(); void initStatusBarCallbacks();
void initWidgets(); void initWidgets();
@ -443,7 +447,16 @@ void MyDialog::initMenu()
void MyDialog::initMenuCallbacks() void MyDialog::initMenuCallbacks()
{ {
// Menu function callbacks // Menu function callbacks
initFileMenuCallbacks();
initEditMenuCallbacks();
initViewMenuCallbacks();
initHelpMenuCallback();
}
//----------------------------------------------------------------------
void MyDialog::initFileMenuCallbacks()
{
// File menu
Open->addCallback Open->addCallback
( (
"clicked", "clicked",
@ -456,6 +469,33 @@ void MyDialog::initMenuCallbacks()
F_METHOD_CALLBACK (this, &FApplication::cb_exitApp) F_METHOD_CALLBACK (this, &FApplication::cb_exitApp)
); );
// System files submenu
File1->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_view),
static_cast<FWidget::data_ptr>(File1)
);
File2->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_view),
static_cast<FWidget::data_ptr>(File2)
);
File3->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_view),
static_cast<FWidget::data_ptr>(File3)
);
}
//----------------------------------------------------------------------
void MyDialog::initEditMenuCallbacks()
{
// Edit menu
Cut->addCallback Cut->addCallback
( (
"clicked", "clicked",
@ -479,7 +519,12 @@ void MyDialog::initMenuCallbacks()
"clicked", "clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_clearInput) F_METHOD_CALLBACK (this, &MyDialog::cb_clearInput)
); );
}
//----------------------------------------------------------------------
void MyDialog::initViewMenuCallbacks()
{
// View menu
Env->addCallback Env->addCallback
( (
"clicked", "clicked",
@ -491,33 +536,16 @@ void MyDialog::initMenuCallbacks()
"clicked", "clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_drives) F_METHOD_CALLBACK (this, &MyDialog::cb_drives)
); );
}
//----------------------------------------------------------------------
void MyDialog::initHelpMenuCallback()
{
Help->addCallback Help->addCallback
( (
"clicked", "clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_about) F_METHOD_CALLBACK (this, &MyDialog::cb_about)
); );
File1->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_view),
static_cast<FWidget::data_ptr>(File1)
);
File2->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_view),
static_cast<FWidget::data_ptr>(File2)
);
File3->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_view),
static_cast<FWidget::data_ptr>(File3)
);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -178,13 +178,17 @@ class FMenu : public FWindow, public FMenuList
void hideSubMenus(); void hideSubMenus();
void hideSuperMenus(); void hideSuperMenus();
bool mouseDownOverList (FPoint); bool mouseDownOverList (FPoint);
void mouseDownSubmenu (FMenuItem*);
void mouseDownSelection (FMenuItem*, bool&);
bool mouseUpOverList (FPoint); bool mouseUpOverList (FPoint);
bool mouseMoveOverList (FPoint, mouseStates&); void mouseMoveOverList (FPoint, mouseStates&);
void mouseMoveSelection (FMenuItem*, mouseStates&);
void mouseMoveDeselection (FMenuItem*, mouseStates&);
void mouseUpOverBorder(); void mouseUpOverBorder();
void mouseMoveOverBorder (mouseStates&); void mouseMoveOverBorder (mouseStates&);
void passEventToSubMenu (FMouseEvent*& ev); void passEventToSubMenu (FMouseEvent*&);
void passEventToSuperMenu (FMouseEvent*& ev); void passEventToSuperMenu (FMouseEvent*&);
void passEventToMenuBar (FMouseEvent*& ev); void passEventToMenuBar (FMouseEvent*&);
bool containsMenuStructure (const FPoint&); bool containsMenuStructure (const FPoint&);
bool containsMenuStructure (int, int); bool containsMenuStructure (int, int);
FMenu* superMenuAt (const FPoint&); FMenu* superMenuAt (const FPoint&);

View File

@ -667,26 +667,26 @@ void FMenu::hideSuperMenus()
// hide all menus to the top // hide all menus to the top
FWidget* super = getSuperMenu(); FWidget* super = getSuperMenu();
if ( super ) if ( ! super )
{ return;
if ( isMenuBar(super) )
{
FMenuBar* mbar = static_cast<FMenuBar*>(super);
if ( mbar->hasSelectedItem() ) if ( isMenuBar(super) )
mbar->leaveMenuBar(); {
} FMenuBar* mbar = static_cast<FMenuBar*>(super);
else if ( isMenu(super) )
{ if ( mbar->hasSelectedItem() )
FMenu* m = static_cast<FMenu*>(super); mbar->leaveMenuBar();
m->hide(); }
m->hideSuperMenus(); else if ( isMenu(super) )
} {
else if ( isWindowsMenu(super) ) FMenu* m = static_cast<FMenu*>(super);
{ m->hide();
FDialog* dgl = static_cast<FDialog*>(super); m->hideSuperMenus();
dgl->leaveMenu(); }
} else if ( isWindowsMenu(super) )
{
FDialog* dgl = static_cast<FDialog*>(super);
dgl->leaveMenu();
} }
} }
@ -712,58 +712,8 @@ bool FMenu::mouseDownOverList (FPoint mouse_pos)
&& mouse_y == y ) && mouse_y == y )
{ {
// Mouse pointer over item // Mouse pointer over item
if ( hasSelectedItem() ) mouseDownSubmenu (*iter);
{ mouseDownSelection (*iter, focus_changed);
FMenuItem* sel_item = getSelectedItem();
if ( sel_item
&& sel_item->hasMenu()
&& sel_item->getMenu() == opened_sub_menu )
{
if ( sel_item != *iter )
hideSubMenus();
else
{
// unselect sub menu items
opened_sub_menu->unselectItem();
raiseWindow (opened_sub_menu);
opened_sub_menu->redraw();
sel_item->setFocus();
if ( getStatusBar() )
getStatusBar()->drawMessage();
updateTerminal();
flush_out();
}
}
}
if ( ! (*iter)->isSelected() )
{
unselectItem();
FWidget* focused_widget = getFocusWidget();
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
(*iter)->setSelected();
setSelectedItem(*iter);
(*iter)->setFocus();
if ( focused_widget )
focused_widget->redraw();
if ( getStatusBar() )
getStatusBar()->drawMessage();
if ( (*iter)->hasMenu() )
{
FMenu* sub_menu = (*iter)->getMenu();
if ( ! sub_menu->isVisible() )
shown_sub_menu = sub_menu;
}
focus_changed = true;
}
} }
++iter; ++iter;
@ -772,6 +722,66 @@ bool FMenu::mouseDownOverList (FPoint mouse_pos)
return focus_changed; return focus_changed;
} }
//----------------------------------------------------------------------
void FMenu::mouseDownSubmenu (FMenuItem* m_item)
{
if ( ! hasSelectedItem() )
return;
FMenuItem* sel_item = getSelectedItem();
if ( ! sel_item
|| ! sel_item->hasMenu()
|| sel_item->getMenu() != opened_sub_menu )
return;
if ( sel_item != m_item )
hideSubMenus();
else
{
// unselect sub menu items
opened_sub_menu->unselectItem();
raiseWindow (opened_sub_menu);
opened_sub_menu->redraw();
sel_item->setFocus();
if ( getStatusBar() )
getStatusBar()->drawMessage();
updateTerminal();
flush_out();
}
}
//----------------------------------------------------------------------
void FMenu::mouseDownSelection (FMenuItem* m_item, bool& focus_changed)
{
if ( m_item->isSelected() )
return;
unselectItem();
FWidget* focused_widget = getFocusWidget();
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
m_item->setSelected();
setSelectedItem(m_item);
m_item->setFocus();
focus_changed = true;
if ( focused_widget )
focused_widget->redraw();
if ( getStatusBar() )
getStatusBar()->drawMessage();
if ( m_item->hasMenu() )
{
FMenu* sub_menu = m_item->getMenu();
if ( ! sub_menu->isVisible() )
shown_sub_menu = sub_menu;
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMenu::mouseUpOverList (FPoint mouse_pos) bool FMenu::mouseUpOverList (FPoint mouse_pos)
{ {
@ -833,10 +843,9 @@ bool FMenu::mouseUpOverList (FPoint mouse_pos)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMenu::mouseMoveOverList (FPoint mouse_pos, mouseStates& ms) void FMenu::mouseMoveOverList (FPoint mouse_pos, mouseStates& ms)
{ {
std::vector<FMenuItem*>::const_iterator iter, last; std::vector<FMenuItem*>::const_iterator iter, last;
bool isOverList = false;
iter = item_list.begin(); iter = item_list.begin();
last = item_list.end(); last = item_list.end();
mouse_pos -= FPoint(getRightPadding(), getTopPadding()); mouse_pos -= FPoint(getRightPadding(), getTopPadding());
@ -849,67 +858,67 @@ bool FMenu::mouseMoveOverList (FPoint mouse_pos, mouseStates& ms)
, mouse_x = mouse_pos.getX() , mouse_x = mouse_pos.getX()
, mouse_y = mouse_pos.getY(); , mouse_y = mouse_pos.getY();
if ( mouse_x >= x1 if ( mouse_x >= x1 && mouse_x < x2 && mouse_y == y )
&& mouse_x < x2 mouseMoveSelection (*iter, ms);
&& mouse_y == y )
{
if ( (*iter)->isEnabled()
&& ! (*iter)->isSelected()
&& ! (*iter)->isSeparator() )
{
// Mouse pointer over item
FWidget* focused_widget = getFocusWidget();
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
(*iter)->setSelected();
setSelectedItem(*iter);
(*iter)->setFocus();
if ( focused_widget )
focused_widget->redraw();
if ( getStatusBar() )
getStatusBar()->drawMessage();
// Sub menu handling
if ( (*iter)->hasMenu() )
{
FMenu* sub_menu = (*iter)->getMenu();
if ( ! sub_menu->isVisible() )
shown_sub_menu = sub_menu;
}
else if ( opened_sub_menu )
ms.hide_sub_menu = true;
ms.focus_changed = true;
}
if ( ! (*iter)->isSeparator() )
isOverList = true;
}
else else
{ mouseMoveDeselection (*iter, ms);
if ( ms.mouse_over_menu
&& (*iter)->isEnabled()
&& (*iter)->isSelected()
&& ! ms.mouse_over_submenu )
{
// Unselect selected item without mouse focus
(*iter)->unsetSelected();
(*iter)->unsetFocus();
if ( getSelectedItem() == *iter )
setSelectedItem(0);
ms.focus_changed = true;
}
}
++iter; ++iter;
} }
}
return isOverList; //----------------------------------------------------------------------
void FMenu::mouseMoveSelection (FMenuItem* m_item, mouseStates& ms)
{
if ( ! m_item->isEnabled()
|| m_item->isSelected()
|| m_item->isSeparator() )
return;
// Mouse pointer over item
FWidget* focused_widget = getFocusWidget();
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
m_item->setSelected();
setSelectedItem(m_item);
m_item->setFocus();
ms.focus_changed = true;
if ( focused_widget )
focused_widget->redraw();
if ( getStatusBar() )
getStatusBar()->drawMessage();
// Sub menu handling
if ( m_item->hasMenu() )
{
FMenu* sub_menu = m_item->getMenu();
if ( ! sub_menu->isVisible() )
shown_sub_menu = sub_menu;
}
else if ( opened_sub_menu )
ms.hide_sub_menu = true;
}
//----------------------------------------------------------------------
void FMenu::mouseMoveDeselection (FMenuItem* m_item, mouseStates& ms)
{
if ( ! ms.mouse_over_menu
|| ! m_item->isEnabled()
|| ! m_item->isSelected()
|| ms.mouse_over_submenu )
return;
// Unselect selected item without mouse focus
m_item->unsetSelected();
m_item->unsetFocus();
if ( getSelectedItem() == m_item )
setSelectedItem(0);
ms.focus_changed = true;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -117,7 +117,9 @@ FObject* FObject::getChild (int index) const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FObject::isChild (FObject* obj) const bool FObject::isChild (FObject* obj) const
{ {
while ( FObject* p_obj = obj->getParent() ) FObject* p_obj = 0;
while ( obj && (p_obj = obj->getParent()) )
{ {
obj = p_obj; obj = p_obj;

View File

@ -295,10 +295,10 @@ void FTextView::insert (const FString& str, int pos)
vbar->setPageSize (int(getRows()), getTextHeight()); vbar->setPageSize (int(getRows()), getTextHeight());
vbar->calculateSliderValues(); vbar->calculateSliderValues();
if ( ! vbar->isVisible() && int(getRows()) >= getTextHeight() + 1 ) if ( ! vbar->isVisible() && int(getRows()) > getTextHeight() )
vbar->setVisible(); vbar->setVisible();
if ( vbar->isVisible() && int(getRows()) < getTextHeight() + 1 ) if ( vbar->isVisible() && int(getRows()) <= getTextHeight() )
vbar->hide(); vbar->hide();
processChanged(); processChanged();