diff --git a/ChangeLog b/ChangeLog index 2a78c303..ad3cb22a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ +2016-07-03 Markus Gans + * Add the new class FDialogListMenu to switch between dialog menus + * More consistent method names: + rename parentWidget() to getParentWidget() + 2016-06-27 Markus Gans - * Fix the use after free bug for previous_widget + * Fix the use-after-free bug for previous_widget 2016-06-26 Markus Gans * Bug fix for FWindow::activatePrevWindow() diff --git a/doc/TODO b/doc/TODO index 12d522c6..d601759a 100644 --- a/doc/TODO +++ b/doc/TODO @@ -23,7 +23,6 @@ Missing Features - FDialog title button [▲] and [▼] should maximized or restore the window size on a resizeable dialog - A possibility to change the window size dynamically with the mouse -- Add a window switcher on the right side of the status bar - Add a scrolling area with on-demand scroll bars for FButtonGroup - Adding for flexible layouts a FGrid widget container that organizes its child widgets in rows and columns diff --git a/src/Makefile.am b/src/Makefile.am index 1e091270..3f65c0e5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,6 +24,7 @@ libfinal_la_SOURCES = \ flabel.cpp \ flistbox.cpp \ fmenu.cpp \ + fdialoglistmenu.cpp \ fmenubar.cpp \ fmenuitem.cpp \ fradiomenuitem.cpp \ @@ -65,6 +66,7 @@ finalcutinclude_HEADERS = \ flineedit.h \ flistbox.h \ fmenu.h \ + fdialoglistmenu.h \ fmenubar.h \ fmenuitem.h \ fradiomenuitem.h \ diff --git a/src/Makefile.clang b/src/Makefile.clang index 6eaf0b67..b4774e90 100644 --- a/src/Makefile.clang +++ b/src/Makefile.clang @@ -21,6 +21,7 @@ INCLUDE_HEADERS = \ flineedit.h \ flistbox.h \ fmenu.h \ + fdialoglistmenu.h \ fmenubar.h \ fradiomenuitem.h \ fcheckmenuitem.h \ @@ -67,6 +68,7 @@ OBJS = \ flabel.o \ flistbox.o \ fmenu.o \ + fdialoglistmenu.o \ fmenubar.o \ fmenuitem.o \ fradiomenuitem.o \ diff --git a/src/Makefile.gcc b/src/Makefile.gcc index f0fcb33b..abbff6b3 100644 --- a/src/Makefile.gcc +++ b/src/Makefile.gcc @@ -21,6 +21,7 @@ INCLUDE_HEADERS = \ flineedit.h \ flistbox.h \ fmenu.h \ + fdialoglistmenu.h \ fmenubar.h \ fradiomenuitem.h \ fcheckmenuitem.h \ @@ -67,6 +68,7 @@ OBJS = \ flabel.o \ flistbox.o \ fmenu.o \ + fdialoglistmenu.o \ fmenubar.o \ fmenuitem.o \ fradiomenuitem.o \ diff --git a/src/Makefile.in b/src/Makefile.in index 425ef931..1409a602 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -131,11 +131,11 @@ libfinal_la_LIBADD = am_libfinal_la_OBJECTS = fstring.lo fpoint.lo frect.lo fscrollbar.lo \ fprogressbar.lo flineedit.lo fbutton.lo fbuttongroup.lo \ ftogglebutton.lo fradiobutton.lo fcheckbox.lo fswitch.lo \ - flabel.lo flistbox.lo fmenu.lo fmenubar.lo fmenuitem.lo \ - fradiomenuitem.lo fcheckmenuitem.lo fmenulist.lo fdialog.lo \ - fwindow.lo fmessagebox.lo ffiledialog.lo ftextview.lo \ - fstatusbar.lo fterm.lo fevent.lo foptiattr.lo foptimove.lo \ - fapp.lo fwidget.lo fobject.lo + flabel.lo flistbox.lo fmenu.lo fdialoglistmenu.lo fmenubar.lo \ + fmenuitem.lo fradiomenuitem.lo fcheckmenuitem.lo fmenulist.lo \ + fdialog.lo fwindow.lo fmessagebox.lo ffiledialog.lo \ + ftextview.lo fstatusbar.lo fterm.lo fevent.lo foptiattr.lo \ + foptimove.lo fapp.lo fwidget.lo fobject.lo libfinal_la_OBJECTS = $(am_libfinal_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) @@ -388,6 +388,7 @@ libfinal_la_SOURCES = \ flabel.cpp \ flistbox.cpp \ fmenu.cpp \ + fdialoglistmenu.cpp \ fmenubar.cpp \ fmenuitem.cpp \ fradiomenuitem.cpp \ @@ -427,6 +428,7 @@ finalcutinclude_HEADERS = \ flineedit.h \ flistbox.h \ fmenu.h \ + fdialoglistmenu.h \ fmenubar.h \ fmenuitem.h \ fradiomenuitem.h \ @@ -535,6 +537,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fcheckbox.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fcheckmenuitem.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fdialog.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fdialoglistmenu.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fevent.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ffiledialog.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/flabel.Plo@am__quote@ diff --git a/src/fbutton.cpp b/src/fbutton.cpp index 883f9c50..5a60d43f 100644 --- a/src/fbutton.cpp +++ b/src/fbutton.cpp @@ -168,8 +168,8 @@ void FButton::draw() if ( is_Flat ) clearFlatBorder(); clearShadow(); - setColor ( parentWidget()->getForegroundColor() - , parentWidget()->getBackgroundColor() ); + setColor ( getParentWidget()->getForegroundColor() + , getParentWidget()->getBackgroundColor() ); for (int y=1; y <= height; y++) { gotoxy (xpos+xmin-1, ypos+ymin-2+y); @@ -232,7 +232,7 @@ void FButton::draw() } else if ( ! isMonochron() ) { - setColor (button_bg, parentWidget()->getBackgroundColor()); + setColor (button_bg, getParentWidget()->getBackgroundColor()); gotoxy (xpos+xmin-1+d, ypos+ymin-1); for (int y=1; y <= height; y++) { @@ -252,8 +252,8 @@ void FButton::draw() && (is_Flat || ! hasShadow() || isMonochron()) ) { // clear the right █ from button down - setColor ( parentWidget()->getForegroundColor() - , parentWidget()->getBackgroundColor() ); + setColor ( getParentWidget()->getForegroundColor() + , getParentWidget()->getBackgroundColor() ); for (int y=1; y <= height; y++) { if ( isMonochron() ) @@ -341,8 +341,8 @@ void FButton::draw() if ( is_NonFlatShadow && ! button_down ) { - setColor ( parentWidget()->getForegroundColor() - , parentWidget()->getBackgroundColor() ); + setColor ( getParentWidget()->getForegroundColor() + , getParentWidget()->getBackgroundColor() ); print(' '); // restore background after button down drawShadow(); } @@ -462,8 +462,8 @@ void FButton::hide() FWidget::hide(); - fg = parentWidget()->getForegroundColor(); - bg = parentWidget()->getBackgroundColor(); + fg = getParentWidget()->getForegroundColor(); + bg = getParentWidget()->getBackgroundColor(); setColor (fg, bg); s = hasShadow() ? 1 : 0; diff --git a/src/fbuttongroup.cpp b/src/fbuttongroup.cpp index 211ae33e..4719dafc 100644 --- a/src/fbuttongroup.cpp +++ b/src/fbuttongroup.cpp @@ -280,8 +280,8 @@ void FButtonGroup::hide() } } - fg = parentWidget()->getForegroundColor(); - bg = parentWidget()->getBackgroundColor(); + fg = getParentWidget()->getForegroundColor(); + bg = getParentWidget()->getBackgroundColor(); setColor (fg, bg); size = width; diff --git a/src/fdialog.cpp b/src/fdialog.cpp index 4b3e4150..7f39b58d 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -55,7 +55,7 @@ FDialog::~FDialog() // destructor const FRect& geometry = getGeometryGlobalShadow(); restoreVTerm (geometry); - parentWidget()->redraw(); + getParentWidget()->redraw(); } if ( window_list && ! window_list->empty() ) @@ -164,7 +164,7 @@ void FDialog::drawBorder() { short fg; if ( ! isRootWidget() ) - fg = parentWidget()->getForegroundColor(); + fg = getParentWidget()->getForegroundColor(); else fg = wc.term_fg; for (int y=y1; y <= y2; y++) diff --git a/src/fdialoglistmenu.cpp b/src/fdialoglistmenu.cpp new file mode 100644 index 00000000..7bdc860f --- /dev/null +++ b/src/fdialoglistmenu.cpp @@ -0,0 +1,55 @@ +// File: fdialoglistmenu.cpp +// Provides: class FDialogListMenu + + +#include "fdialoglistmenu.h" + +//---------------------------------------------------------------------- +// class FDialogListMenu +//---------------------------------------------------------------------- + +// constructor and destructor +//---------------------------------------------------------------------- +FDialogListMenu::FDialogListMenu(FWidget* parent) + : FMenu(parent) +{ + init(); +} + +//---------------------------------------------------------------------- +FDialogListMenu::FDialogListMenu (FString& txt, FWidget* parent) + : FMenu(txt, parent) +{ + init(); +} + + +//---------------------------------------------------------------------- +FDialogListMenu::FDialogListMenu (const std::string& txt, FWidget* parent) + : FMenu(txt, parent) +{ + init(); +} + + +//---------------------------------------------------------------------- +FDialogListMenu::FDialogListMenu (const char* txt, FWidget* parent) + : FMenu(txt, parent) +{ + init(); +} + + +//---------------------------------------------------------------------- +FDialogListMenu::~FDialogListMenu() +{ } + + +// private methods of FMenu +//---------------------------------------------------------------------- +void FDialogListMenu::init() +{ + FMenuItem* menuitem = getItem(); + if ( menuitem ) + menuitem->dialog_list = true; +} diff --git a/src/fdialoglistmenu.h b/src/fdialoglistmenu.h new file mode 100644 index 00000000..4cb97a60 --- /dev/null +++ b/src/fdialoglistmenu.h @@ -0,0 +1,71 @@ +// File: fdialoglistmenu.h +// Provides: class FDialogListMenu +// +// Inheritance diagram +// ═══════════════════ +// +// ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏ +// ▕ FObject ▏ ▕ FTerm ▏ +// ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏ +// ▲ ▲ +// │ │ +// └─────┬─────┘ +// │ +// ▕▔▔▔▔▔▔▔▔▔▏ +// ▕ FWidget ▏ +// ▕▁▁▁▁▁▁▁▁▁▏ +// ▲ +// │ +// ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▔▔▏ +// ▕ FWindow ▏ ▕ FMenuList ▏ +// ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▁▁▏ +// ▲ ▲ +// │ │ +// └─────┬─────┘ +// │ +// ▕▔▔▔▔▔▔▔▏ +// ▕ FMenu ▏ +// ▕▁▁▁▁▁▁▁▏ +// ▲ +// │ +// ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▔▔▏ +// ▕ FDialogListMenu ▏- - - - - -▕ FMenuItem ▏ +// ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏1 1▕▁▁▁▁▁▁▁▁▁▁▁▏ + +#ifndef _FDIALOGLISTMENU_H +#define _FDIALOGLISTMENU_H + +#include "fmenu.h" + + +//---------------------------------------------------------------------- +// class FDialogListMenu +//---------------------------------------------------------------------- + +#pragma pack(push) +#pragma pack(1) + +class FDialogListMenu : public FMenu +{ + private: + FDialogListMenu (const FDialogListMenu&); + FDialogListMenu& operator = (const FDialogListMenu&); + void init(); + + public: + explicit FDialogListMenu (FWidget* = 0); // constructor + FDialogListMenu (FString&, FWidget* = 0); + FDialogListMenu (const std::string&, FWidget* = 0); + FDialogListMenu (const char*, FWidget* = 0); + virtual ~FDialogListMenu(); // destructor + virtual const char* getClassName() const; +}; +#pragma pack(pop) + + +// FDialogListMenu inline functions +//---------------------------------------------------------------------- +inline const char* FDialogListMenu::getClassName() const +{ return "FDialogListMenu"; } + +#endif // _FDIALOGLISTMENU_H diff --git a/src/ffiledialog.cpp b/src/ffiledialog.cpp index 9841e028..18fdc250 100644 --- a/src/ffiledialog.cpp +++ b/src/ffiledialog.cpp @@ -46,7 +46,7 @@ FFileDialog::FFileDialog(FWidget* parent) //---------------------------------------------------------------------- FFileDialog::FFileDialog (const FFileDialog& fdlg) - : FDialog(fdlg.parentWidget()) + : FDialog(fdlg.getParentWidget()) , directory_stream(0) , dir_entries() , directory(fdlg.directory) @@ -110,8 +110,8 @@ void FFileDialog::init() width = 15; if ( width < 20 ) width = 20; - x = 1 + int((parentWidget()->getWidth()-width)/2); - y = 1 + int((parentWidget()->getHeight()-height)/3); + x = 1 + int((getParentWidget()->getWidth()-width)/2); + y = 1 + int((getParentWidget()->getHeight()-height)/3); if ( dlg_type == FFileDialog::Save ) FDialog::setText("Save file"); @@ -476,7 +476,7 @@ FFileDialog& FFileDialog::operator = (const FFileDialog& fdlg) delete filename; clear(); - fdlg.parentWidget()->addChild (this); + fdlg.getParentWidget()->addChild (this); directory = fdlg.directory; filter_pattern = fdlg.filter_pattern; diff --git a/src/final.h b/src/final.h index fea9802b..4e75331e 100644 --- a/src/final.h +++ b/src/final.h @@ -20,6 +20,7 @@ #include "ftextview.h" #include "flineedit.h" #include "fmenu.h" +#include "fdialoglistmenu.h" #include "fmenubar.h" #include "fmenuitem.h" #include "fcheckmenuitem.h" diff --git a/src/flabel.cpp b/src/flabel.cpp index fb08ac44..c1171dee 100644 --- a/src/flabel.cpp +++ b/src/flabel.cpp @@ -60,8 +60,8 @@ void FLabel::init() unsetFocusable(); - foregroundColor = parentWidget()->getForegroundColor(); - backgroundColor = parentWidget()->getBackgroundColor(); + foregroundColor = getParentWidget()->getForegroundColor(); + backgroundColor = getParentWidget()->getBackgroundColor(); } //---------------------------------------------------------------------- @@ -321,8 +321,8 @@ void FLabel::hide() FWidget::hide(); - fg = parentWidget()->getForegroundColor(); - bg = parentWidget()->getBackgroundColor(); + fg = getParentWidget()->getForegroundColor(); + bg = getParentWidget()->getBackgroundColor(); setColor (fg, bg); blank = new char[width+1]; diff --git a/src/flineedit.cpp b/src/flineedit.cpp index e6310367..5975ac71 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -280,8 +280,8 @@ void FLineEdit::hide() FWidget::hide(); - fg = parentWidget()->getForegroundColor(); - bg = parentWidget()->getBackgroundColor(); + fg = getParentWidget()->getForegroundColor(); + bg = getParentWidget()->getBackgroundColor(); setColor (fg, bg); s = hasShadow() ? 1 : 0; size = width + s; diff --git a/src/flistbox.cpp b/src/flistbox.cpp index 2a09b8cd..f167a8a9 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -540,8 +540,8 @@ void FListBox::hide() FWidget::hide(); - fg = parentWidget()->getForegroundColor(); - bg = parentWidget()->getBackgroundColor(); + fg = getParentWidget()->getForegroundColor(); + bg = getParentWidget()->getBackgroundColor(); setColor (fg, bg); n = isNewFont() ? 1 : 0; diff --git a/src/fmenu.cpp b/src/fmenu.cpp index da54fdf3..5ab73ac5 100644 --- a/src/fmenu.cpp +++ b/src/fmenu.cpp @@ -106,7 +106,7 @@ void FMenu::init(FWidget* parent) bottom_padding = 1; right_padding = 1; createArea (vwin); - setGeometry (1, 1 , 10, 2, false); // initialize geometry values + setGeometry (1, 1, 10, 2, false); // initialize geometry values setTransparentShadow(); window_object = true; menu_object = true; diff --git a/src/fmenubar.cpp b/src/fmenubar.cpp index 236ce43e..ddddeaac 100644 --- a/src/fmenubar.cpp +++ b/src/fmenubar.cpp @@ -581,41 +581,38 @@ void FMenuBar::onMouseDown (FMouseEvent* ev) x1 = (*iter)->getX(); x2 = (*iter)->getX() + (*iter)->getWidth(); - if ( mouse_x >= x1 - && mouse_x < x2 - && mouse_y == 1 ) + if ( mouse_y == 1 ) { - // Mouse pointer over item - if ( (*iter)->isEnabled() && ! (*iter)->isSelected() ) + if ( mouse_x >= x1 + && mouse_x < x2 ) { - FWidget* focused_widget = getFocusWidget(); - FFocusEvent out (fc::FocusOut_Event); - FApplication::queueEvent(focused_widget, &out); - (*iter)->setSelected(); - (*iter)->setFocus(); - if ( focused_widget ) - focused_widget->redraw(); - (*iter)->openMenu(); - setSelectedItem(*iter); - focus_changed = true; - - if ( (*iter)->hasMenu() ) + // Mouse pointer over item + if ( (*iter)->isEnabled() && ! (*iter)->isSelected() ) { - FMenu* menu = (*iter)->getMenu(); - if ( menu->hasSelectedItem() ) + FWidget* focused_widget = getFocusWidget(); + FFocusEvent out (fc::FocusOut_Event); + FApplication::queueEvent(focused_widget, &out); + (*iter)->setSelected(); + (*iter)->setFocus(); + if ( focused_widget ) + focused_widget->redraw(); + (*iter)->openMenu(); + setSelectedItem(*iter); + focus_changed = true; + + if ( (*iter)->hasMenu() ) { - menu->unselectItem(); - menu->redraw(); - drop_down = true; + FMenu* menu = (*iter)->getMenu(); + if ( menu->hasSelectedItem() ) + { + menu->unselectItem(); + menu->redraw(); + drop_down = true; + } } } } - } - else - { - if ( mouse_y == 1 - && (*iter)->isEnabled() - && (*iter)->isSelected() ) + else if ( (*iter)->isEnabled() && (*iter)->isSelected() ) { (*iter)->unsetSelected(); if ( getSelectedItem() == *iter ) @@ -625,8 +622,10 @@ void FMenuBar::onMouseDown (FMouseEvent* ev) } ++iter; } + if ( statusBar() ) statusBar()->drawMessage(); + if ( focus_changed ) { redraw(); @@ -661,56 +660,53 @@ void FMenuBar::onMouseUp (FMouseEvent* ev) x1 = (*iter)->getX(); x2 = (*iter)->getX() + (*iter)->getWidth(); - if ( mouse_x >= x1 - && mouse_x < x2 - && mouse_y == 1 - && (*iter)->isEnabled() - && (*iter)->isSelected() ) + if ( mouse_y == 1 ) { - // 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 - { - if ( mouse_y == 1 + if ( mouse_x >= x1 + && mouse_x < x2 && (*iter)->isEnabled() && (*iter)->isSelected() ) + { + // 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 if ( (*iter)->isEnabled() && (*iter)->isSelected() ) { (*iter)->unsetSelected(); if ( getSelectedItem() == *iter ) setSelectedItem(0); redraw(); } + ++iter; } - ++iter; } if ( ! hasSelectedItem() ) leaveMenuBar(); @@ -901,3 +897,4 @@ void FMenuBar::cb_item_deactivated (FWidget* widget, void*) menu->hideSubMenus(); } } + diff --git a/src/fmenubar.h b/src/fmenubar.h index 73699cb4..04fc78be 100644 --- a/src/fmenubar.h +++ b/src/fmenubar.h @@ -45,8 +45,8 @@ class FMenuBar : public FWindow, public FMenuList { private: - bool mouse_down; - bool drop_down; + bool mouse_down; + bool drop_down; private: FMenuBar (const FMenuBar&); diff --git a/src/fmenuitem.cpp b/src/fmenuitem.cpp index 6e66c06f..31ff0f71 100644 --- a/src/fmenuitem.cpp +++ b/src/fmenuitem.cpp @@ -22,12 +22,13 @@ FMenuItem::FMenuItem (FWidget* parent) , separator(false) , checkable(false) , checked(false) + , radio_button(false) + , dialog_list(false) , text_length(0) , hotkey(0) , accel_key(0) , menu(0) , super_menu(0) - , radio_button(false) { init (parent); } @@ -40,12 +41,13 @@ FMenuItem::FMenuItem (FString& txt, FWidget* parent) , separator(false) , checkable(false) , checked(false) + , radio_button(false) + , dialog_list(false) , text_length(0) , hotkey(0) , accel_key(0) , menu(0) , super_menu(0) - , radio_button(false) { init (parent); } @@ -58,12 +60,13 @@ FMenuItem::FMenuItem (const std::string& txt, FWidget* parent) , separator(false) , checkable(false) , checked(false) + , radio_button(false) + , dialog_list(false) , text_length(0) , hotkey(0) , accel_key(0) , menu(0) , super_menu(0) - , radio_button(false) { init (parent); } @@ -76,12 +79,13 @@ FMenuItem::FMenuItem (const char* txt, FWidget* parent) , separator(false) , checkable(false) , checked(false) + , radio_button(false) + , dialog_list(false) , text_length(0) , hotkey(0) , accel_key(0) , menu(0) , super_menu(0) - , radio_button(false) { init (parent); } @@ -94,12 +98,13 @@ FMenuItem::FMenuItem (int k, FString& txt, FWidget* parent) , separator(false) , checkable(false) , checked(false) + , radio_button(false) + , dialog_list(false) , text_length(0) , hotkey(0) , accel_key(k) , menu(0) , super_menu(0) - , radio_button(false) { init (parent); } @@ -112,12 +117,13 @@ FMenuItem::FMenuItem (int k, const std::string& txt, FWidget* parent) , separator(false) , checkable(false) , checked(false) + , radio_button(false) + , dialog_list(false) , text_length(0) , hotkey(0) , accel_key(k) , menu(0) , super_menu(0) - , radio_button(false) { init (parent); } @@ -130,12 +136,13 @@ FMenuItem::FMenuItem (int k, const char* txt, FWidget* parent) , separator(false) , checkable(false) , checked(false) + , radio_button(false) + , dialog_list(false) , text_length(0) , hotkey(0) , accel_key(k) , menu(0) , super_menu(0) - , radio_button(false) { init (parent); } @@ -239,6 +246,53 @@ void FMenuItem::processDeactivate() emitCallback("deactivate"); } +//---------------------------------------------------------------------- +void FMenuItem::createDialogList (FMenu* winmenu) +{ + winmenu->clear(); + + if ( window_list && ! window_list->empty() ) + { + widgetList::const_iterator iter, begin; + iter = window_list->end(); + begin = window_list->begin(); + + do + { + --iter; + if ( (*iter)->isDialog() ) + { + FDialog* win = dynamic_cast(*iter); + FString win_title = win->getText(); + FMenuItem* win_item = new FMenuItem (win_title, winmenu); + win_item->addCallback + ( + "clicked", + _METHOD_CALLBACK (this, &FMenuItem::cb_switchToDialog), + dynamic_cast(win) + ); + } + } + while ( iter != begin ); + } + winmenu->menu_dimension(); +} + +//---------------------------------------------------------------------- +void FMenuItem::cb_switchToDialog (FWidget*, void* data_ptr) +{ + FDialog* win = static_cast(data_ptr); + if ( win && ! win->isHiddenWindow() && ! win->isActiveWindow() ) + { + FWindow::setActiveWindow(win); + FWidget* focus_widget = win->getFocusWidget(); + FWindow::raiseWindow (win); + if ( focus_widget ) + focus_widget->setFocus(); + win->redraw(); + } +} + //---------------------------------------------------------------------- void FMenuItem::processClicked() { @@ -256,15 +310,18 @@ bool FMenuItem::isWindowsMenu (FWidget* w) const //---------------------------------------------------------------------- bool FMenuItem::isMenuBar (FWidget* w) const { - return bool ( strcmp ( w->getClassName() - , const_cast("FMenuBar") ) == 0 ); + return bool( strcmp ( w->getClassName() + , const_cast("FMenuBar") ) == 0 ); } //---------------------------------------------------------------------- bool FMenuItem::isMenu (FWidget* w) const { - return bool ( strcmp ( w->getClassName() - , const_cast("FMenu") ) == 0 ); + bool m1 = ( strcmp ( w->getClassName() + , const_cast("FMenu") ) == 0 ); + bool m2 = ( strcmp ( w->getClassName() + , const_cast("FDialogListMenu") ) == 0 ); + return bool( m1 || m2 ); } @@ -279,7 +336,7 @@ void FMenuItem::addAccelerator (int key, FWidget* obj) while ( super && strncmp ( super->getClassName() , const_cast("FMenu"), 5) == 0 ) { - super = super->parentWidget(); + super = super->getParentWidget(); } if ( super ) @@ -314,7 +371,7 @@ void FMenuItem::delAccelerator (FWidget* obj) while ( super && strncmp ( super->getClassName() , const_cast("FMenu"), 5) == 0 ) { - super = super->parentWidget(); + super = super->getParentWidget(); } if ( super ) @@ -754,6 +811,8 @@ void FMenuItem::openMenu() open_menu->hide(); open_menu->hideSubMenus(); } + if ( dialog_list ) + createDialogList (dd_menu); setOpenMenu(dd_menu); dd_menu->setVisible(); diff --git a/src/fmenuitem.h b/src/fmenuitem.h index df82cc66..1004ae04 100644 --- a/src/fmenuitem.h +++ b/src/fmenuitem.h @@ -48,12 +48,13 @@ class FMenuItem : public FWidget bool separator; bool checkable; bool checked; + bool radio_button; + bool dialog_list; uInt text_length; int hotkey; int accel_key; FMenu* menu; FWidget* super_menu; - bool radio_button; private: FMenuItem (const FMenuItem&); @@ -62,6 +63,8 @@ class FMenuItem : public FWidget uChar hotKey(); void processActivate(); void processDeactivate(); + void createDialogList (FMenu*); + void cb_switchToDialog (FWidget*, void*); virtual void processClicked(); protected: @@ -124,6 +127,7 @@ class FMenuItem : public FWidget void setText (const char*); private: + friend class FDialogListMenu; friend class FMenuList; friend class FMenuBar; friend class FMenu; diff --git a/src/fmessagebox.cpp b/src/fmessagebox.cpp index 4c4db0be..315b8242 100644 --- a/src/fmessagebox.cpp +++ b/src/fmessagebox.cpp @@ -44,7 +44,7 @@ FMessageBox::FMessageBox(FWidget* parent) //---------------------------------------------------------------------- FMessageBox::FMessageBox (const FMessageBox& mbox) - : FDialog(mbox.parentWidget()) + : FDialog(mbox.getParentWidget()) , headline_text(mbox.headline_text) , text(mbox.text) , text_components(mbox.text_components) @@ -208,8 +208,8 @@ void FMessageBox::msg_dimension() w = int(maxLineWidth + 4); if ( w < 20 ) w = 20; - x = 1 + int((parentWidget()->getWidth()-w)/2); - y = 1 + int((parentWidget()->getHeight()-h)/3); + x = 1 + int((getParentWidget()->getWidth()-w)/2); + y = 1 + int((getParentWidget()->getHeight()-h)/3); setGeometry (x, y, w, h); } @@ -354,7 +354,7 @@ FMessageBox& FMessageBox::operator = (const FMessageBox& mbox) delete button_digit[1]; delete button_digit[0]; - mbox.parentWidget()->addChild (this); + mbox.getParentWidget()->addChild (this); headline_text = mbox.headline_text; text = mbox.text; diff --git a/src/fprogressbar.cpp b/src/fprogressbar.cpp index 42b8142f..22a4d29b 100644 --- a/src/fprogressbar.cpp +++ b/src/fprogressbar.cpp @@ -25,8 +25,8 @@ FProgressbar::~FProgressbar() //---------------------------------------------------------------------- void FProgressbar::drawPercentage() { - setColor ( parentWidget()->getForegroundColor() - , parentWidget()->getBackgroundColor() ); + setColor ( getParentWidget()->getForegroundColor() + , getParentWidget()->getBackgroundColor() ); if ( isMonochron() ) setReverse(true); gotoxy (xpos+xmin+width-5, ypos+ymin-2); @@ -68,10 +68,10 @@ void FProgressbar::drawBar() if ( round(length) >= 1) setColor ( wc.progressbar_fg - , parentWidget()->getBackgroundColor() ); + , getParentWidget()->getBackgroundColor() ); else setColor ( wc.progressbar_bg - , parentWidget()->getBackgroundColor() ); + , getParentWidget()->getBackgroundColor() ); if ( ! isMonochron() && getMaxColor() >= 16 ) { @@ -160,8 +160,8 @@ void FProgressbar::hide() FWidget::hide(); - fg = parentWidget()->getForegroundColor(); - bg = parentWidget()->getBackgroundColor(); + fg = getParentWidget()->getForegroundColor(); + bg = getParentWidget()->getBackgroundColor(); setColor (fg, bg); s = hasShadow() ? 1 : 0; diff --git a/src/ftextview.cpp b/src/ftextview.cpp index e40121a1..800763ea 100644 --- a/src/ftextview.cpp +++ b/src/ftextview.cpp @@ -196,8 +196,8 @@ void FTextView::hide() FWidget::hide(); - fg = parentWidget()->getForegroundColor(); - bg = parentWidget()->getBackgroundColor(); + fg = getParentWidget()->getForegroundColor(); + bg = getParentWidget()->getBackgroundColor(); setColor (fg, bg); n = isNewFont() ? 1 : 0; diff --git a/src/ftogglebutton.cpp b/src/ftogglebutton.cpp index 9031dcbc..522bd0fa 100644 --- a/src/ftogglebutton.cpp +++ b/src/ftogglebutton.cpp @@ -352,8 +352,8 @@ void FToggleButton::hide() FWidget::hide(); - fg = parentWidget()->getForegroundColor(); - bg = parentWidget()->getBackgroundColor(); + fg = getParentWidget()->getForegroundColor(); + bg = getParentWidget()->getBackgroundColor(); setColor (fg, bg); size = width; diff --git a/src/fwidget.cpp b/src/fwidget.cpp index c026e140..543bb78e 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -170,6 +170,7 @@ void FWidget::init() void FWidget::finish() { delete accelerator_list; + accelerator_list = 0; if ( close_widget ) { @@ -401,19 +402,19 @@ void FWidget::adjustSize() } else if ( ignore_padding ) { - xmin = parentWidget()->xpos + parentWidget()->xmin - 1; - ymin = parentWidget()->ypos + parentWidget()->ymin - 1; - xmax = parentWidget()->xpos + parentWidget()->xmin - 2 - + parentWidget()->width; - ymax = parentWidget()->ypos + parentWidget()->ymin - 2 - + parentWidget()->height; + xmin = getParentWidget()->xpos + getParentWidget()->xmin - 1; + ymin = getParentWidget()->ypos + getParentWidget()->ymin - 1; + xmax = getParentWidget()->xpos + getParentWidget()->xmin - 2 + + getParentWidget()->width; + ymax = getParentWidget()->ypos + getParentWidget()->ymin - 2 + + getParentWidget()->height; } else { - xmin = parentWidget()->client_xmin; - ymin = parentWidget()->client_ymin; - xmax = parentWidget()->client_xmax; - ymax = parentWidget()->client_ymax; + xmin = getParentWidget()->client_xmin; + ymin = getParentWidget()->client_ymin; + xmax = getParentWidget()->client_xmax; + ymax = getParentWidget()->client_ymax; } xpos = widgetSize.getX(); ypos = widgetSize.getY(); @@ -569,7 +570,7 @@ bool FWidget::event (FEvent* ev) } if ( kev->isAccepted() || widget->isRootWidget() ) break; - widget = widget->parentWidget(); + widget = widget->getParentWidget(); } } break; @@ -587,7 +588,7 @@ bool FWidget::event (FEvent* ev) widget->onKeyDown(kev); if ( kev->isAccepted() || widget->isRootWidget() ) break; - widget = widget->parentWidget(); + widget = widget->getParentWidget(); } } break; @@ -845,12 +846,12 @@ bool FWidget::focusPrevChild() FWidget* FWidget::getRootWidget() const { FWidget* obj = const_cast(this); - FWidget* p_obj = parentWidget(); + FWidget* p_obj = getParentWidget(); while ( ! obj->isRootWidget() && p_obj ) { obj = p_obj; - p_obj = p_obj->parentWidget(); + p_obj = p_obj->getParentWidget(); } return obj; } @@ -1119,7 +1120,7 @@ void FWidget::addAccelerator (int key, FWidget* obj) if ( ! window ) window = getRootWidget(); if ( window == statusbar || window == menubar ) - window = FWindow::getWindowWidget(parentWidget()); + window = FWindow::getWindowWidget(getParentWidget()); if ( window && window->accelerator_list ) window->accelerator_list->push_back(accel); } @@ -1132,7 +1133,7 @@ void FWidget::delAccelerator (FWidget* obj) if ( ! window ) window = getRootWidget(); if ( window == statusbar || window == menubar ) - window = FWindow::getWindowWidget(parentWidget()); + window = FWindow::getWindowWidget(getParentWidget()); if ( window && window->accelerator_list && ! window->accelerator_list->empty() ) @@ -1351,7 +1352,7 @@ void FWidget::hide() if ( ! focusPrevChild() ) { FWidget::getFocusWidget()->unsetFocus(); - FWidget::setFocusWidget(parentWidget()); + FWidget::setFocusWidget(getParentWidget()); } } FHideEvent hide_ev (fc::Hide_Event); @@ -1472,10 +1473,10 @@ bool FWidget::setFocus (bool on) if ( on && ! focus ) { int focusable_children = numOfFocusableChildren(); - + if ( FWidget::getFocusWidget() != 0 ) FWidget::getFocusWidget()->unsetFocus(); - + if ( (!isDialog() && focusable_children == 0) || (isDialog() && focusable_children == 1) ) { diff --git a/src/fwidget.h b/src/fwidget.h index b4fea9bb..1a93faa8 100644 --- a/src/fwidget.h +++ b/src/fwidget.h @@ -329,7 +329,7 @@ class FWidget : public FObject, public FTerm static FWidget* getOpenMenu(); static void setOpenMenu(FWidget*); int numOfFocusableChildren(); - FWidget* parentWidget() const; + FWidget* getParentWidget() const; bool isRootWidget() const; bool isWindow() const; bool isDialog() const; @@ -543,7 +543,7 @@ inline FWidget* FWidget::childWidgetAt (FWidget* p, const FPoint& pos) { return childWidgetAt (p, pos.getX(), pos.getY()); } //---------------------------------------------------------------------- -inline FWidget* FWidget::parentWidget() const +inline FWidget* FWidget::getParentWidget() const { return static_cast(getParent()); } //---------------------------------------------------------------------- diff --git a/src/fwindow.cpp b/src/fwindow.cpp index 287ab97b..ea9c9299 100644 --- a/src/fwindow.cpp +++ b/src/fwindow.cpp @@ -157,11 +157,11 @@ void FWindow::delWindow (FWidget* obj) FWindow* FWindow::getWindowWidget (FWidget* obj) { // returns the window object to the given widget obj - FWidget* p_obj = obj->parentWidget(); + FWidget* p_obj = obj->getParentWidget(); while ( ! obj->isWindow() && p_obj ) { obj = p_obj; - p_obj = p_obj->parentWidget(); + p_obj = p_obj->getParentWidget(); } if ( obj->isWindow() ) return static_cast(obj); diff --git a/test/calculator.cpp b/test/calculator.cpp index 2ac18eb0..04b93fb0 100644 --- a/test/calculator.cpp +++ b/test/calculator.cpp @@ -41,7 +41,7 @@ Button::Button (FWidget* parent) { } //---------------------------------------------------------------------- -void Button::setChecked(bool on) +void Button::setChecked (bool on) { if ( checked != on ) { @@ -948,8 +948,8 @@ void Calc::cb_buttonClicked (FWidget*, void* data_ptr) //---------------------------------------------------------------------- void Calc::adjustSize() { - int pw = parentWidget()->getWidth(); - int ph = parentWidget()->getHeight(); + int pw = getParentWidget()->getWidth(); + int ph = getParentWidget()->getHeight(); setX (1 + (pw - getWidth()) / 2, false); setY (1 + (ph - getHeight()) / 2, false); FDialog::adjustSize(); diff --git a/test/mandelbrot.cpp b/test/mandelbrot.cpp index 5b672d35..ff395e3d 100644 --- a/test/mandelbrot.cpp +++ b/test/mandelbrot.cpp @@ -114,8 +114,8 @@ void Mandelbrot::onClose (FCloseEvent* ev) //---------------------------------------------------------------------- void Mandelbrot::adjustSize() { - int h = parentWidget()->getHeight() - 1; - int w = parentWidget()->getWidth() - 10; + int h = getParentWidget()->getHeight() - 1; + int w = getParentWidget()->getWidth() - 10; setGeometry(6, 1, w, h, false); FDialog::adjustSize(); } diff --git a/test/menu.cpp b/test/menu.cpp index 24fa2d6e..d6487ab3 100644 --- a/test/menu.cpp +++ b/test/menu.cpp @@ -251,8 +251,8 @@ void Menu::cb_exitApp (FWidget*, void*) //---------------------------------------------------------------------- void Menu::adjustSize() { - int pw = parentWidget()->getWidth(); - int ph = parentWidget()->getHeight(); + int pw = getParentWidget()->getWidth(); + int ph = getParentWidget()->getHeight(); setX (1 + (pw - getWidth()) / 2, false); setY (1 + (ph - getHeight()) / 4, false); FDialog::adjustSize(); diff --git a/test/term-attributes.cpp b/test/term-attributes.cpp index 643471ea..e28ec640 100644 --- a/test/term-attributes.cpp +++ b/test/term-attributes.cpp @@ -133,8 +133,8 @@ void AttribDlg::cb_back (FWidget*, void*) //---------------------------------------------------------------------- void AttribDlg::adjustSize() { - int x = ((parentWidget()->getWidth() - getWidth()) / 2 ); - int y = ((parentWidget()->getHeight() - getHeight()) / 2 ) + 1; + int x = ((getParentWidget()->getWidth() - getWidth()) / 2 ); + int y = ((getParentWidget()->getHeight() - getHeight()) / 2 ) + 1; if ( x < 1 ) x = 1; if ( y < 1 ) @@ -170,7 +170,7 @@ class AttribDemo : public FWidget { } void onWheel (FWheelEvent* ev) { - AttribDlg* p = dynamic_cast(parentWidget()); + AttribDlg* p = dynamic_cast(getParentWidget()); if ( p ) p->onWheel(ev); } @@ -236,7 +236,7 @@ void AttribDemo::draw() // test alternate character set printAltCharset(); - for (int y=0; y < parentWidget()->getHeight()-7; y++) + for (int y=0; y < getParentWidget()->getHeight()-7; y++) { gotoxy ( xpos + xmin - 1, ypos + ymin + y ); diff --git a/test/ui.cpp b/test/ui.cpp index 112609aa..cf36352b 100644 --- a/test/ui.cpp +++ b/test/ui.cpp @@ -45,7 +45,7 @@ ProgressDialog::ProgressDialog (FWidget* parent) , more() , quit() { - setGeometry (int((this->parentWidget()->getWidth()-40)/2), 7, 40, 10); + setGeometry (int((this->getParentWidget()->getWidth()-40)/2), 7, 40, 10); setText("Progress bar"); setTransparentShadow(); //setModal(); @@ -220,6 +220,8 @@ MyDialog::MyDialog (FWidget* parent) FMenuItem* Options = new FMenuItem ("&Options", Menubar); Options->setStatusbarMessage ("Set program defaults"); Options->setDisable(); + FDialogListMenu* Window = new FDialogListMenu ("&Window", Menubar); + Window->setStatusbarMessage ("List of all the active dialogs"); FMenuItem* Help = new FMenuItem ("&Help", Menubar); Help->setStatusbarMessage ("Show version and copyright information"); @@ -740,7 +742,8 @@ void MyDialog::cb_view (FWidget*, void* data_ptr) return; FDialog* view = new FDialog(this); - view->setText ("Viewer"); + FString filename(basename(const_cast(file.c_str()))); + view->setText ("Viewer: " + filename); view->setGeometry (1+int((getRootWidget()->getWidth()-60)/2), int(getRootWidget()->getHeight()/6), 60, @@ -790,9 +793,9 @@ void MyDialog::cb_exitApp (FWidget*, void*) //---------------------------------------------------------------------- void MyDialog::adjustSize() { - int h = parentWidget()->getHeight() - 4; + int h = getParentWidget()->getHeight() - 4; setHeight (h, false); - int X = int((parentWidget()->getWidth() - getWidth()) / 2); + int X = int((getParentWidget()->getWidth() - getWidth()) / 2); if ( X < 1 ) X = 1; setX (X, false); diff --git a/test/watch.cpp b/test/watch.cpp index c3d06b1b..dab58aa6 100644 --- a/test/watch.cpp +++ b/test/watch.cpp @@ -56,7 +56,7 @@ watch::watch (FWidget* parent) { setText ("Watch"); setShadow(); - int pw = parentWidget()->getWidth(); + int pw = getParentWidget()->getWidth(); setGeometry (1+(pw-22)/2, 3, 22, 13); // Create labels @@ -191,7 +191,7 @@ void watch::cb_exitApp (FWidget*, void*) //---------------------------------------------------------------------- void watch::adjustSize() { - int pw = parentWidget()->getWidth(); + int pw = getParentWidget()->getWidth(); setX (1+(pw-22)/2, false); FDialog::adjustSize(); }