Add the new class FDialogListMenu to switch between dialog menus

This commit is contained in:
Markus Gans 2016-07-03 20:08:39 +02:00
parent 0c4b3a3a14
commit 71b5b16865
34 changed files with 375 additions and 171 deletions

View File

@ -1,5 +1,10 @@
2016-07-03 Markus Gans <guru.mail@muenster.de>
* Add the new class FDialogListMenu to switch between dialog menus
* More consistent method names:
rename parentWidget() to getParentWidget()
2016-06-27 Markus Gans <guru.mail@muenster.de> 2016-06-27 Markus Gans <guru.mail@muenster.de>
* Fix the use after free bug for previous_widget * Fix the use-after-free bug for previous_widget
2016-06-26 Markus Gans <guru.mail@muenster.de> 2016-06-26 Markus Gans <guru.mail@muenster.de>
* Bug fix for FWindow::activatePrevWindow() * Bug fix for FWindow::activatePrevWindow()

View File

@ -23,7 +23,6 @@ Missing Features
- FDialog title button [▲] and [▼] should maximized or restore - FDialog title button [▲] and [▼] should maximized or restore
the window size on a resizeable dialog the window size on a resizeable dialog
- A possibility to change the window size dynamically with the mouse - 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 - Add a scrolling area with on-demand scroll bars for FButtonGroup
- Adding for flexible layouts a FGrid widget container that organizes - Adding for flexible layouts a FGrid widget container that organizes
its child widgets in rows and columns its child widgets in rows and columns

View File

@ -24,6 +24,7 @@ libfinal_la_SOURCES = \
flabel.cpp \ flabel.cpp \
flistbox.cpp \ flistbox.cpp \
fmenu.cpp \ fmenu.cpp \
fdialoglistmenu.cpp \
fmenubar.cpp \ fmenubar.cpp \
fmenuitem.cpp \ fmenuitem.cpp \
fradiomenuitem.cpp \ fradiomenuitem.cpp \
@ -65,6 +66,7 @@ finalcutinclude_HEADERS = \
flineedit.h \ flineedit.h \
flistbox.h \ flistbox.h \
fmenu.h \ fmenu.h \
fdialoglistmenu.h \
fmenubar.h \ fmenubar.h \
fmenuitem.h \ fmenuitem.h \
fradiomenuitem.h \ fradiomenuitem.h \

View File

@ -21,6 +21,7 @@ INCLUDE_HEADERS = \
flineedit.h \ flineedit.h \
flistbox.h \ flistbox.h \
fmenu.h \ fmenu.h \
fdialoglistmenu.h \
fmenubar.h \ fmenubar.h \
fradiomenuitem.h \ fradiomenuitem.h \
fcheckmenuitem.h \ fcheckmenuitem.h \
@ -67,6 +68,7 @@ OBJS = \
flabel.o \ flabel.o \
flistbox.o \ flistbox.o \
fmenu.o \ fmenu.o \
fdialoglistmenu.o \
fmenubar.o \ fmenubar.o \
fmenuitem.o \ fmenuitem.o \
fradiomenuitem.o \ fradiomenuitem.o \

View File

@ -21,6 +21,7 @@ INCLUDE_HEADERS = \
flineedit.h \ flineedit.h \
flistbox.h \ flistbox.h \
fmenu.h \ fmenu.h \
fdialoglistmenu.h \
fmenubar.h \ fmenubar.h \
fradiomenuitem.h \ fradiomenuitem.h \
fcheckmenuitem.h \ fcheckmenuitem.h \
@ -67,6 +68,7 @@ OBJS = \
flabel.o \ flabel.o \
flistbox.o \ flistbox.o \
fmenu.o \ fmenu.o \
fdialoglistmenu.o \
fmenubar.o \ fmenubar.o \
fmenuitem.o \ fmenuitem.o \
fradiomenuitem.o \ fradiomenuitem.o \

View File

@ -131,11 +131,11 @@ libfinal_la_LIBADD =
am_libfinal_la_OBJECTS = fstring.lo fpoint.lo frect.lo fscrollbar.lo \ am_libfinal_la_OBJECTS = fstring.lo fpoint.lo frect.lo fscrollbar.lo \
fprogressbar.lo flineedit.lo fbutton.lo fbuttongroup.lo \ fprogressbar.lo flineedit.lo fbutton.lo fbuttongroup.lo \
ftogglebutton.lo fradiobutton.lo fcheckbox.lo fswitch.lo \ ftogglebutton.lo fradiobutton.lo fcheckbox.lo fswitch.lo \
flabel.lo flistbox.lo fmenu.lo fmenubar.lo fmenuitem.lo \ flabel.lo flistbox.lo fmenu.lo fdialoglistmenu.lo fmenubar.lo \
fradiomenuitem.lo fcheckmenuitem.lo fmenulist.lo fdialog.lo \ fmenuitem.lo fradiomenuitem.lo fcheckmenuitem.lo fmenulist.lo \
fwindow.lo fmessagebox.lo ffiledialog.lo ftextview.lo \ fdialog.lo fwindow.lo fmessagebox.lo ffiledialog.lo \
fstatusbar.lo fterm.lo fevent.lo foptiattr.lo foptimove.lo \ ftextview.lo fstatusbar.lo fterm.lo fevent.lo foptiattr.lo \
fapp.lo fwidget.lo fobject.lo foptimove.lo fapp.lo fwidget.lo fobject.lo
libfinal_la_OBJECTS = $(am_libfinal_la_OBJECTS) libfinal_la_OBJECTS = $(am_libfinal_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@) AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
@ -388,6 +388,7 @@ libfinal_la_SOURCES = \
flabel.cpp \ flabel.cpp \
flistbox.cpp \ flistbox.cpp \
fmenu.cpp \ fmenu.cpp \
fdialoglistmenu.cpp \
fmenubar.cpp \ fmenubar.cpp \
fmenuitem.cpp \ fmenuitem.cpp \
fradiomenuitem.cpp \ fradiomenuitem.cpp \
@ -427,6 +428,7 @@ finalcutinclude_HEADERS = \
flineedit.h \ flineedit.h \
flistbox.h \ flistbox.h \
fmenu.h \ fmenu.h \
fdialoglistmenu.h \
fmenubar.h \ fmenubar.h \
fmenuitem.h \ fmenuitem.h \
fradiomenuitem.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)/fcheckbox.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fcheckmenuitem.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)/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)/fevent.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ffiledialog.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@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/flabel.Plo@am__quote@

View File

@ -168,8 +168,8 @@ void FButton::draw()
if ( is_Flat ) if ( is_Flat )
clearFlatBorder(); clearFlatBorder();
clearShadow(); clearShadow();
setColor ( parentWidget()->getForegroundColor() setColor ( getParentWidget()->getForegroundColor()
, parentWidget()->getBackgroundColor() ); , getParentWidget()->getBackgroundColor() );
for (int y=1; y <= height; y++) for (int y=1; y <= height; y++)
{ {
gotoxy (xpos+xmin-1, ypos+ymin-2+y); gotoxy (xpos+xmin-1, ypos+ymin-2+y);
@ -232,7 +232,7 @@ void FButton::draw()
} }
else if ( ! isMonochron() ) else if ( ! isMonochron() )
{ {
setColor (button_bg, parentWidget()->getBackgroundColor()); setColor (button_bg, getParentWidget()->getBackgroundColor());
gotoxy (xpos+xmin-1+d, ypos+ymin-1); gotoxy (xpos+xmin-1+d, ypos+ymin-1);
for (int y=1; y <= height; y++) for (int y=1; y <= height; y++)
{ {
@ -252,8 +252,8 @@ void FButton::draw()
&& (is_Flat || ! hasShadow() || isMonochron()) ) && (is_Flat || ! hasShadow() || isMonochron()) )
{ {
// clear the right █ from button down // clear the right █ from button down
setColor ( parentWidget()->getForegroundColor() setColor ( getParentWidget()->getForegroundColor()
, parentWidget()->getBackgroundColor() ); , getParentWidget()->getBackgroundColor() );
for (int y=1; y <= height; y++) for (int y=1; y <= height; y++)
{ {
if ( isMonochron() ) if ( isMonochron() )
@ -341,8 +341,8 @@ void FButton::draw()
if ( is_NonFlatShadow && ! button_down ) if ( is_NonFlatShadow && ! button_down )
{ {
setColor ( parentWidget()->getForegroundColor() setColor ( getParentWidget()->getForegroundColor()
, parentWidget()->getBackgroundColor() ); , getParentWidget()->getBackgroundColor() );
print(' '); // restore background after button down print(' '); // restore background after button down
drawShadow(); drawShadow();
} }
@ -462,8 +462,8 @@ void FButton::hide()
FWidget::hide(); FWidget::hide();
fg = parentWidget()->getForegroundColor(); fg = getParentWidget()->getForegroundColor();
bg = parentWidget()->getBackgroundColor(); bg = getParentWidget()->getBackgroundColor();
setColor (fg, bg); setColor (fg, bg);
s = hasShadow() ? 1 : 0; s = hasShadow() ? 1 : 0;

View File

@ -280,8 +280,8 @@ void FButtonGroup::hide()
} }
} }
fg = parentWidget()->getForegroundColor(); fg = getParentWidget()->getForegroundColor();
bg = parentWidget()->getBackgroundColor(); bg = getParentWidget()->getBackgroundColor();
setColor (fg, bg); setColor (fg, bg);
size = width; size = width;

View File

@ -55,7 +55,7 @@ FDialog::~FDialog() // destructor
const FRect& geometry = getGeometryGlobalShadow(); const FRect& geometry = getGeometryGlobalShadow();
restoreVTerm (geometry); restoreVTerm (geometry);
parentWidget()->redraw(); getParentWidget()->redraw();
} }
if ( window_list && ! window_list->empty() ) if ( window_list && ! window_list->empty() )
@ -164,7 +164,7 @@ void FDialog::drawBorder()
{ {
short fg; short fg;
if ( ! isRootWidget() ) if ( ! isRootWidget() )
fg = parentWidget()->getForegroundColor(); fg = getParentWidget()->getForegroundColor();
else else
fg = wc.term_fg; fg = wc.term_fg;
for (int y=y1; y <= y2; y++) for (int y=y1; y <= y2; y++)

55
src/fdialoglistmenu.cpp Normal file
View File

@ -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;
}

71
src/fdialoglistmenu.h Normal file
View File

@ -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

View File

@ -46,7 +46,7 @@ FFileDialog::FFileDialog(FWidget* parent)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FFileDialog::FFileDialog (const FFileDialog& fdlg) FFileDialog::FFileDialog (const FFileDialog& fdlg)
: FDialog(fdlg.parentWidget()) : FDialog(fdlg.getParentWidget())
, directory_stream(0) , directory_stream(0)
, dir_entries() , dir_entries()
, directory(fdlg.directory) , directory(fdlg.directory)
@ -110,8 +110,8 @@ void FFileDialog::init()
width = 15; width = 15;
if ( width < 20 ) if ( width < 20 )
width = 20; width = 20;
x = 1 + int((parentWidget()->getWidth()-width)/2); x = 1 + int((getParentWidget()->getWidth()-width)/2);
y = 1 + int((parentWidget()->getHeight()-height)/3); y = 1 + int((getParentWidget()->getHeight()-height)/3);
if ( dlg_type == FFileDialog::Save ) if ( dlg_type == FFileDialog::Save )
FDialog::setText("Save file"); FDialog::setText("Save file");
@ -476,7 +476,7 @@ FFileDialog& FFileDialog::operator = (const FFileDialog& fdlg)
delete filename; delete filename;
clear(); clear();
fdlg.parentWidget()->addChild (this); fdlg.getParentWidget()->addChild (this);
directory = fdlg.directory; directory = fdlg.directory;
filter_pattern = fdlg.filter_pattern; filter_pattern = fdlg.filter_pattern;

View File

@ -20,6 +20,7 @@
#include "ftextview.h" #include "ftextview.h"
#include "flineedit.h" #include "flineedit.h"
#include "fmenu.h" #include "fmenu.h"
#include "fdialoglistmenu.h"
#include "fmenubar.h" #include "fmenubar.h"
#include "fmenuitem.h" #include "fmenuitem.h"
#include "fcheckmenuitem.h" #include "fcheckmenuitem.h"

View File

@ -60,8 +60,8 @@ void FLabel::init()
unsetFocusable(); unsetFocusable();
foregroundColor = parentWidget()->getForegroundColor(); foregroundColor = getParentWidget()->getForegroundColor();
backgroundColor = parentWidget()->getBackgroundColor(); backgroundColor = getParentWidget()->getBackgroundColor();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -321,8 +321,8 @@ void FLabel::hide()
FWidget::hide(); FWidget::hide();
fg = parentWidget()->getForegroundColor(); fg = getParentWidget()->getForegroundColor();
bg = parentWidget()->getBackgroundColor(); bg = getParentWidget()->getBackgroundColor();
setColor (fg, bg); setColor (fg, bg);
blank = new char[width+1]; blank = new char[width+1];

View File

@ -280,8 +280,8 @@ void FLineEdit::hide()
FWidget::hide(); FWidget::hide();
fg = parentWidget()->getForegroundColor(); fg = getParentWidget()->getForegroundColor();
bg = parentWidget()->getBackgroundColor(); bg = getParentWidget()->getBackgroundColor();
setColor (fg, bg); setColor (fg, bg);
s = hasShadow() ? 1 : 0; s = hasShadow() ? 1 : 0;
size = width + s; size = width + s;

View File

@ -540,8 +540,8 @@ void FListBox::hide()
FWidget::hide(); FWidget::hide();
fg = parentWidget()->getForegroundColor(); fg = getParentWidget()->getForegroundColor();
bg = parentWidget()->getBackgroundColor(); bg = getParentWidget()->getBackgroundColor();
setColor (fg, bg); setColor (fg, bg);
n = isNewFont() ? 1 : 0; n = isNewFont() ? 1 : 0;

View File

@ -581,9 +581,10 @@ void FMenuBar::onMouseDown (FMouseEvent* ev)
x1 = (*iter)->getX(); x1 = (*iter)->getX();
x2 = (*iter)->getX() + (*iter)->getWidth(); x2 = (*iter)->getX() + (*iter)->getWidth();
if ( mouse_y == 1 )
{
if ( mouse_x >= x1 if ( mouse_x >= x1
&& mouse_x < x2 && mouse_x < x2 )
&& mouse_y == 1 )
{ {
// Mouse pointer over item // Mouse pointer over item
if ( (*iter)->isEnabled() && ! (*iter)->isSelected() ) if ( (*iter)->isEnabled() && ! (*iter)->isSelected() )
@ -611,11 +612,7 @@ void FMenuBar::onMouseDown (FMouseEvent* ev)
} }
} }
} }
else else if ( (*iter)->isEnabled() && (*iter)->isSelected() )
{
if ( mouse_y == 1
&& (*iter)->isEnabled()
&& (*iter)->isSelected() )
{ {
(*iter)->unsetSelected(); (*iter)->unsetSelected();
if ( getSelectedItem() == *iter ) if ( getSelectedItem() == *iter )
@ -625,8 +622,10 @@ void FMenuBar::onMouseDown (FMouseEvent* ev)
} }
++iter; ++iter;
} }
if ( statusBar() ) if ( statusBar() )
statusBar()->drawMessage(); statusBar()->drawMessage();
if ( focus_changed ) if ( focus_changed )
{ {
redraw(); redraw();
@ -661,9 +660,10 @@ void FMenuBar::onMouseUp (FMouseEvent* ev)
x1 = (*iter)->getX(); x1 = (*iter)->getX();
x2 = (*iter)->getX() + (*iter)->getWidth(); x2 = (*iter)->getX() + (*iter)->getWidth();
if ( mouse_y == 1 )
{
if ( mouse_x >= x1 if ( mouse_x >= x1
&& mouse_x < x2 && mouse_x < x2
&& mouse_y == 1
&& (*iter)->isEnabled() && (*iter)->isEnabled()
&& (*iter)->isSelected() ) && (*iter)->isSelected() )
{ {
@ -698,20 +698,16 @@ void FMenuBar::onMouseUp (FMouseEvent* ev)
} }
} }
} }
else else if ( (*iter)->isEnabled() && (*iter)->isSelected() )
{
if ( mouse_y == 1
&& (*iter)->isEnabled()
&& (*iter)->isSelected() )
{ {
(*iter)->unsetSelected(); (*iter)->unsetSelected();
if ( getSelectedItem() == *iter ) if ( getSelectedItem() == *iter )
setSelectedItem(0); setSelectedItem(0);
redraw(); redraw();
} }
}
++iter; ++iter;
} }
}
if ( ! hasSelectedItem() ) if ( ! hasSelectedItem() )
leaveMenuBar(); leaveMenuBar();
} }
@ -901,3 +897,4 @@ void FMenuBar::cb_item_deactivated (FWidget* widget, void*)
menu->hideSubMenus(); menu->hideSubMenus();
} }
} }

View File

@ -22,12 +22,13 @@ FMenuItem::FMenuItem (FWidget* parent)
, separator(false) , separator(false)
, checkable(false) , checkable(false)
, checked(false) , checked(false)
, radio_button(false)
, dialog_list(false)
, text_length(0) , text_length(0)
, hotkey(0) , hotkey(0)
, accel_key(0) , accel_key(0)
, menu(0) , menu(0)
, super_menu(0) , super_menu(0)
, radio_button(false)
{ {
init (parent); init (parent);
} }
@ -40,12 +41,13 @@ FMenuItem::FMenuItem (FString& txt, FWidget* parent)
, separator(false) , separator(false)
, checkable(false) , checkable(false)
, checked(false) , checked(false)
, radio_button(false)
, dialog_list(false)
, text_length(0) , text_length(0)
, hotkey(0) , hotkey(0)
, accel_key(0) , accel_key(0)
, menu(0) , menu(0)
, super_menu(0) , super_menu(0)
, radio_button(false)
{ {
init (parent); init (parent);
} }
@ -58,12 +60,13 @@ FMenuItem::FMenuItem (const std::string& txt, FWidget* parent)
, separator(false) , separator(false)
, checkable(false) , checkable(false)
, checked(false) , checked(false)
, radio_button(false)
, dialog_list(false)
, text_length(0) , text_length(0)
, hotkey(0) , hotkey(0)
, accel_key(0) , accel_key(0)
, menu(0) , menu(0)
, super_menu(0) , super_menu(0)
, radio_button(false)
{ {
init (parent); init (parent);
} }
@ -76,12 +79,13 @@ FMenuItem::FMenuItem (const char* txt, FWidget* parent)
, separator(false) , separator(false)
, checkable(false) , checkable(false)
, checked(false) , checked(false)
, radio_button(false)
, dialog_list(false)
, text_length(0) , text_length(0)
, hotkey(0) , hotkey(0)
, accel_key(0) , accel_key(0)
, menu(0) , menu(0)
, super_menu(0) , super_menu(0)
, radio_button(false)
{ {
init (parent); init (parent);
} }
@ -94,12 +98,13 @@ FMenuItem::FMenuItem (int k, FString& txt, FWidget* parent)
, separator(false) , separator(false)
, checkable(false) , checkable(false)
, checked(false) , checked(false)
, radio_button(false)
, dialog_list(false)
, text_length(0) , text_length(0)
, hotkey(0) , hotkey(0)
, accel_key(k) , accel_key(k)
, menu(0) , menu(0)
, super_menu(0) , super_menu(0)
, radio_button(false)
{ {
init (parent); init (parent);
} }
@ -112,12 +117,13 @@ FMenuItem::FMenuItem (int k, const std::string& txt, FWidget* parent)
, separator(false) , separator(false)
, checkable(false) , checkable(false)
, checked(false) , checked(false)
, radio_button(false)
, dialog_list(false)
, text_length(0) , text_length(0)
, hotkey(0) , hotkey(0)
, accel_key(k) , accel_key(k)
, menu(0) , menu(0)
, super_menu(0) , super_menu(0)
, radio_button(false)
{ {
init (parent); init (parent);
} }
@ -130,12 +136,13 @@ FMenuItem::FMenuItem (int k, const char* txt, FWidget* parent)
, separator(false) , separator(false)
, checkable(false) , checkable(false)
, checked(false) , checked(false)
, radio_button(false)
, dialog_list(false)
, text_length(0) , text_length(0)
, hotkey(0) , hotkey(0)
, accel_key(k) , accel_key(k)
, menu(0) , menu(0)
, super_menu(0) , super_menu(0)
, radio_button(false)
{ {
init (parent); init (parent);
} }
@ -239,6 +246,53 @@ void FMenuItem::processDeactivate()
emitCallback("deactivate"); 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<FDialog*>(*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<FWidget::data_ptr>(win)
);
}
}
while ( iter != begin );
}
winmenu->menu_dimension();
}
//----------------------------------------------------------------------
void FMenuItem::cb_switchToDialog (FWidget*, void* data_ptr)
{
FDialog* win = static_cast<FDialog*>(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() void FMenuItem::processClicked()
{ {
@ -263,8 +317,11 @@ bool FMenuItem::isMenuBar (FWidget* w) const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMenuItem::isMenu (FWidget* w) const bool FMenuItem::isMenu (FWidget* w) const
{ {
return bool ( strcmp ( w->getClassName() bool m1 = ( strcmp ( w->getClassName()
, const_cast<char*>("FMenu") ) == 0 ); , const_cast<char*>("FMenu") ) == 0 );
bool m2 = ( strcmp ( w->getClassName()
, const_cast<char*>("FDialogListMenu") ) == 0 );
return bool( m1 || m2 );
} }
@ -279,7 +336,7 @@ void FMenuItem::addAccelerator (int key, FWidget* obj)
while ( super && strncmp ( super->getClassName() while ( super && strncmp ( super->getClassName()
, const_cast<char*>("FMenu"), 5) == 0 ) , const_cast<char*>("FMenu"), 5) == 0 )
{ {
super = super->parentWidget(); super = super->getParentWidget();
} }
if ( super ) if ( super )
@ -314,7 +371,7 @@ void FMenuItem::delAccelerator (FWidget* obj)
while ( super && strncmp ( super->getClassName() while ( super && strncmp ( super->getClassName()
, const_cast<char*>("FMenu"), 5) == 0 ) , const_cast<char*>("FMenu"), 5) == 0 )
{ {
super = super->parentWidget(); super = super->getParentWidget();
} }
if ( super ) if ( super )
@ -754,6 +811,8 @@ void FMenuItem::openMenu()
open_menu->hide(); open_menu->hide();
open_menu->hideSubMenus(); open_menu->hideSubMenus();
} }
if ( dialog_list )
createDialogList (dd_menu);
setOpenMenu(dd_menu); setOpenMenu(dd_menu);
dd_menu->setVisible(); dd_menu->setVisible();

View File

@ -48,12 +48,13 @@ class FMenuItem : public FWidget
bool separator; bool separator;
bool checkable; bool checkable;
bool checked; bool checked;
bool radio_button;
bool dialog_list;
uInt text_length; uInt text_length;
int hotkey; int hotkey;
int accel_key; int accel_key;
FMenu* menu; FMenu* menu;
FWidget* super_menu; FWidget* super_menu;
bool radio_button;
private: private:
FMenuItem (const FMenuItem&); FMenuItem (const FMenuItem&);
@ -62,6 +63,8 @@ class FMenuItem : public FWidget
uChar hotKey(); uChar hotKey();
void processActivate(); void processActivate();
void processDeactivate(); void processDeactivate();
void createDialogList (FMenu*);
void cb_switchToDialog (FWidget*, void*);
virtual void processClicked(); virtual void processClicked();
protected: protected:
@ -124,6 +127,7 @@ class FMenuItem : public FWidget
void setText (const char*); void setText (const char*);
private: private:
friend class FDialogListMenu;
friend class FMenuList; friend class FMenuList;
friend class FMenuBar; friend class FMenuBar;
friend class FMenu; friend class FMenu;

View File

@ -44,7 +44,7 @@ FMessageBox::FMessageBox(FWidget* parent)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FMessageBox::FMessageBox (const FMessageBox& mbox) FMessageBox::FMessageBox (const FMessageBox& mbox)
: FDialog(mbox.parentWidget()) : FDialog(mbox.getParentWidget())
, headline_text(mbox.headline_text) , headline_text(mbox.headline_text)
, text(mbox.text) , text(mbox.text)
, text_components(mbox.text_components) , text_components(mbox.text_components)
@ -208,8 +208,8 @@ void FMessageBox::msg_dimension()
w = int(maxLineWidth + 4); w = int(maxLineWidth + 4);
if ( w < 20 ) if ( w < 20 )
w = 20; w = 20;
x = 1 + int((parentWidget()->getWidth()-w)/2); x = 1 + int((getParentWidget()->getWidth()-w)/2);
y = 1 + int((parentWidget()->getHeight()-h)/3); y = 1 + int((getParentWidget()->getHeight()-h)/3);
setGeometry (x, y, w, h); setGeometry (x, y, w, h);
} }
@ -354,7 +354,7 @@ FMessageBox& FMessageBox::operator = (const FMessageBox& mbox)
delete button_digit[1]; delete button_digit[1];
delete button_digit[0]; delete button_digit[0];
mbox.parentWidget()->addChild (this); mbox.getParentWidget()->addChild (this);
headline_text = mbox.headline_text; headline_text = mbox.headline_text;
text = mbox.text; text = mbox.text;

View File

@ -25,8 +25,8 @@ FProgressbar::~FProgressbar()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FProgressbar::drawPercentage() void FProgressbar::drawPercentage()
{ {
setColor ( parentWidget()->getForegroundColor() setColor ( getParentWidget()->getForegroundColor()
, parentWidget()->getBackgroundColor() ); , getParentWidget()->getBackgroundColor() );
if ( isMonochron() ) if ( isMonochron() )
setReverse(true); setReverse(true);
gotoxy (xpos+xmin+width-5, ypos+ymin-2); gotoxy (xpos+xmin+width-5, ypos+ymin-2);
@ -68,10 +68,10 @@ void FProgressbar::drawBar()
if ( round(length) >= 1) if ( round(length) >= 1)
setColor ( wc.progressbar_fg setColor ( wc.progressbar_fg
, parentWidget()->getBackgroundColor() ); , getParentWidget()->getBackgroundColor() );
else else
setColor ( wc.progressbar_bg setColor ( wc.progressbar_bg
, parentWidget()->getBackgroundColor() ); , getParentWidget()->getBackgroundColor() );
if ( ! isMonochron() && getMaxColor() >= 16 ) if ( ! isMonochron() && getMaxColor() >= 16 )
{ {
@ -160,8 +160,8 @@ void FProgressbar::hide()
FWidget::hide(); FWidget::hide();
fg = parentWidget()->getForegroundColor(); fg = getParentWidget()->getForegroundColor();
bg = parentWidget()->getBackgroundColor(); bg = getParentWidget()->getBackgroundColor();
setColor (fg, bg); setColor (fg, bg);
s = hasShadow() ? 1 : 0; s = hasShadow() ? 1 : 0;

View File

@ -196,8 +196,8 @@ void FTextView::hide()
FWidget::hide(); FWidget::hide();
fg = parentWidget()->getForegroundColor(); fg = getParentWidget()->getForegroundColor();
bg = parentWidget()->getBackgroundColor(); bg = getParentWidget()->getBackgroundColor();
setColor (fg, bg); setColor (fg, bg);
n = isNewFont() ? 1 : 0; n = isNewFont() ? 1 : 0;

View File

@ -352,8 +352,8 @@ void FToggleButton::hide()
FWidget::hide(); FWidget::hide();
fg = parentWidget()->getForegroundColor(); fg = getParentWidget()->getForegroundColor();
bg = parentWidget()->getBackgroundColor(); bg = getParentWidget()->getBackgroundColor();
setColor (fg, bg); setColor (fg, bg);
size = width; size = width;

View File

@ -170,6 +170,7 @@ void FWidget::init()
void FWidget::finish() void FWidget::finish()
{ {
delete accelerator_list; delete accelerator_list;
accelerator_list = 0;
if ( close_widget ) if ( close_widget )
{ {
@ -401,19 +402,19 @@ void FWidget::adjustSize()
} }
else if ( ignore_padding ) else if ( ignore_padding )
{ {
xmin = parentWidget()->xpos + parentWidget()->xmin - 1; xmin = getParentWidget()->xpos + getParentWidget()->xmin - 1;
ymin = parentWidget()->ypos + parentWidget()->ymin - 1; ymin = getParentWidget()->ypos + getParentWidget()->ymin - 1;
xmax = parentWidget()->xpos + parentWidget()->xmin - 2 xmax = getParentWidget()->xpos + getParentWidget()->xmin - 2
+ parentWidget()->width; + getParentWidget()->width;
ymax = parentWidget()->ypos + parentWidget()->ymin - 2 ymax = getParentWidget()->ypos + getParentWidget()->ymin - 2
+ parentWidget()->height; + getParentWidget()->height;
} }
else else
{ {
xmin = parentWidget()->client_xmin; xmin = getParentWidget()->client_xmin;
ymin = parentWidget()->client_ymin; ymin = getParentWidget()->client_ymin;
xmax = parentWidget()->client_xmax; xmax = getParentWidget()->client_xmax;
ymax = parentWidget()->client_ymax; ymax = getParentWidget()->client_ymax;
} }
xpos = widgetSize.getX(); xpos = widgetSize.getX();
ypos = widgetSize.getY(); ypos = widgetSize.getY();
@ -569,7 +570,7 @@ bool FWidget::event (FEvent* ev)
} }
if ( kev->isAccepted() || widget->isRootWidget() ) if ( kev->isAccepted() || widget->isRootWidget() )
break; break;
widget = widget->parentWidget(); widget = widget->getParentWidget();
} }
} }
break; break;
@ -587,7 +588,7 @@ bool FWidget::event (FEvent* ev)
widget->onKeyDown(kev); widget->onKeyDown(kev);
if ( kev->isAccepted() || widget->isRootWidget() ) if ( kev->isAccepted() || widget->isRootWidget() )
break; break;
widget = widget->parentWidget(); widget = widget->getParentWidget();
} }
} }
break; break;
@ -845,12 +846,12 @@ bool FWidget::focusPrevChild()
FWidget* FWidget::getRootWidget() const FWidget* FWidget::getRootWidget() const
{ {
FWidget* obj = const_cast<FWidget*>(this); FWidget* obj = const_cast<FWidget*>(this);
FWidget* p_obj = parentWidget(); FWidget* p_obj = getParentWidget();
while ( ! obj->isRootWidget() && p_obj ) while ( ! obj->isRootWidget() && p_obj )
{ {
obj = p_obj; obj = p_obj;
p_obj = p_obj->parentWidget(); p_obj = p_obj->getParentWidget();
} }
return obj; return obj;
} }
@ -1119,7 +1120,7 @@ void FWidget::addAccelerator (int key, FWidget* obj)
if ( ! window ) if ( ! window )
window = getRootWidget(); window = getRootWidget();
if ( window == statusbar || window == menubar ) if ( window == statusbar || window == menubar )
window = FWindow::getWindowWidget(parentWidget()); window = FWindow::getWindowWidget(getParentWidget());
if ( window && window->accelerator_list ) if ( window && window->accelerator_list )
window->accelerator_list->push_back(accel); window->accelerator_list->push_back(accel);
} }
@ -1132,7 +1133,7 @@ void FWidget::delAccelerator (FWidget* obj)
if ( ! window ) if ( ! window )
window = getRootWidget(); window = getRootWidget();
if ( window == statusbar || window == menubar ) if ( window == statusbar || window == menubar )
window = FWindow::getWindowWidget(parentWidget()); window = FWindow::getWindowWidget(getParentWidget());
if ( window if ( window
&& window->accelerator_list && window->accelerator_list
&& ! window->accelerator_list->empty() ) && ! window->accelerator_list->empty() )
@ -1351,7 +1352,7 @@ void FWidget::hide()
if ( ! focusPrevChild() ) if ( ! focusPrevChild() )
{ {
FWidget::getFocusWidget()->unsetFocus(); FWidget::getFocusWidget()->unsetFocus();
FWidget::setFocusWidget(parentWidget()); FWidget::setFocusWidget(getParentWidget());
} }
} }
FHideEvent hide_ev (fc::Hide_Event); FHideEvent hide_ev (fc::Hide_Event);

View File

@ -329,7 +329,7 @@ class FWidget : public FObject, public FTerm
static FWidget* getOpenMenu(); static FWidget* getOpenMenu();
static void setOpenMenu(FWidget*); static void setOpenMenu(FWidget*);
int numOfFocusableChildren(); int numOfFocusableChildren();
FWidget* parentWidget() const; FWidget* getParentWidget() const;
bool isRootWidget() const; bool isRootWidget() const;
bool isWindow() const; bool isWindow() const;
bool isDialog() const; bool isDialog() const;
@ -543,7 +543,7 @@ inline FWidget* FWidget::childWidgetAt (FWidget* p, const FPoint& pos)
{ return childWidgetAt (p, pos.getX(), pos.getY()); } { return childWidgetAt (p, pos.getX(), pos.getY()); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FWidget* FWidget::parentWidget() const inline FWidget* FWidget::getParentWidget() const
{ return static_cast<FWidget*>(getParent()); } { return static_cast<FWidget*>(getParent()); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -157,11 +157,11 @@ void FWindow::delWindow (FWidget* obj)
FWindow* FWindow::getWindowWidget (FWidget* obj) FWindow* FWindow::getWindowWidget (FWidget* obj)
{ {
// returns the window object to the given widget 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 ) while ( ! obj->isWindow() && p_obj )
{ {
obj = p_obj; obj = p_obj;
p_obj = p_obj->parentWidget(); p_obj = p_obj->getParentWidget();
} }
if ( obj->isWindow() ) if ( obj->isWindow() )
return static_cast<FWindow*>(obj); return static_cast<FWindow*>(obj);

View File

@ -948,8 +948,8 @@ void Calc::cb_buttonClicked (FWidget*, void* data_ptr)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Calc::adjustSize() void Calc::adjustSize()
{ {
int pw = parentWidget()->getWidth(); int pw = getParentWidget()->getWidth();
int ph = parentWidget()->getHeight(); int ph = getParentWidget()->getHeight();
setX (1 + (pw - getWidth()) / 2, false); setX (1 + (pw - getWidth()) / 2, false);
setY (1 + (ph - getHeight()) / 2, false); setY (1 + (ph - getHeight()) / 2, false);
FDialog::adjustSize(); FDialog::adjustSize();

View File

@ -114,8 +114,8 @@ void Mandelbrot::onClose (FCloseEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Mandelbrot::adjustSize() void Mandelbrot::adjustSize()
{ {
int h = parentWidget()->getHeight() - 1; int h = getParentWidget()->getHeight() - 1;
int w = parentWidget()->getWidth() - 10; int w = getParentWidget()->getWidth() - 10;
setGeometry(6, 1, w, h, false); setGeometry(6, 1, w, h, false);
FDialog::adjustSize(); FDialog::adjustSize();
} }

View File

@ -251,8 +251,8 @@ void Menu::cb_exitApp (FWidget*, void*)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Menu::adjustSize() void Menu::adjustSize()
{ {
int pw = parentWidget()->getWidth(); int pw = getParentWidget()->getWidth();
int ph = parentWidget()->getHeight(); int ph = getParentWidget()->getHeight();
setX (1 + (pw - getWidth()) / 2, false); setX (1 + (pw - getWidth()) / 2, false);
setY (1 + (ph - getHeight()) / 4, false); setY (1 + (ph - getHeight()) / 4, false);
FDialog::adjustSize(); FDialog::adjustSize();

View File

@ -133,8 +133,8 @@ void AttribDlg::cb_back (FWidget*, void*)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void AttribDlg::adjustSize() void AttribDlg::adjustSize()
{ {
int x = ((parentWidget()->getWidth() - getWidth()) / 2 ); int x = ((getParentWidget()->getWidth() - getWidth()) / 2 );
int y = ((parentWidget()->getHeight() - getHeight()) / 2 ) + 1; int y = ((getParentWidget()->getHeight() - getHeight()) / 2 ) + 1;
if ( x < 1 ) if ( x < 1 )
x = 1; x = 1;
if ( y < 1 ) if ( y < 1 )
@ -170,7 +170,7 @@ class AttribDemo : public FWidget
{ } { }
void onWheel (FWheelEvent* ev) void onWheel (FWheelEvent* ev)
{ {
AttribDlg* p = dynamic_cast<AttribDlg*>(parentWidget()); AttribDlg* p = dynamic_cast<AttribDlg*>(getParentWidget());
if ( p ) if ( p )
p->onWheel(ev); p->onWheel(ev);
} }
@ -236,7 +236,7 @@ void AttribDemo::draw()
// test alternate character set // test alternate character set
printAltCharset(); printAltCharset();
for (int y=0; y < parentWidget()->getHeight()-7; y++) for (int y=0; y < getParentWidget()->getHeight()-7; y++)
{ {
gotoxy ( xpos + xmin - 1, gotoxy ( xpos + xmin - 1,
ypos + ymin + y ); ypos + ymin + y );

View File

@ -45,7 +45,7 @@ ProgressDialog::ProgressDialog (FWidget* parent)
, more() , more()
, quit() , quit()
{ {
setGeometry (int((this->parentWidget()->getWidth()-40)/2), 7, 40, 10); setGeometry (int((this->getParentWidget()->getWidth()-40)/2), 7, 40, 10);
setText("Progress bar"); setText("Progress bar");
setTransparentShadow(); setTransparentShadow();
//setModal(); //setModal();
@ -220,6 +220,8 @@ MyDialog::MyDialog (FWidget* parent)
FMenuItem* Options = new FMenuItem ("&Options", Menubar); FMenuItem* Options = new FMenuItem ("&Options", Menubar);
Options->setStatusbarMessage ("Set program defaults"); Options->setStatusbarMessage ("Set program defaults");
Options->setDisable(); Options->setDisable();
FDialogListMenu* Window = new FDialogListMenu ("&Window", Menubar);
Window->setStatusbarMessage ("List of all the active dialogs");
FMenuItem* Help = new FMenuItem ("&Help", Menubar); FMenuItem* Help = new FMenuItem ("&Help", Menubar);
Help->setStatusbarMessage ("Show version and copyright information"); Help->setStatusbarMessage ("Show version and copyright information");
@ -740,7 +742,8 @@ void MyDialog::cb_view (FWidget*, void* data_ptr)
return; return;
FDialog* view = new FDialog(this); FDialog* view = new FDialog(this);
view->setText ("Viewer"); FString filename(basename(const_cast<char*>(file.c_str())));
view->setText ("Viewer: " + filename);
view->setGeometry (1+int((getRootWidget()->getWidth()-60)/2), view->setGeometry (1+int((getRootWidget()->getWidth()-60)/2),
int(getRootWidget()->getHeight()/6), int(getRootWidget()->getHeight()/6),
60, 60,
@ -790,9 +793,9 @@ void MyDialog::cb_exitApp (FWidget*, void*)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MyDialog::adjustSize() void MyDialog::adjustSize()
{ {
int h = parentWidget()->getHeight() - 4; int h = getParentWidget()->getHeight() - 4;
setHeight (h, false); setHeight (h, false);
int X = int((parentWidget()->getWidth() - getWidth()) / 2); int X = int((getParentWidget()->getWidth() - getWidth()) / 2);
if ( X < 1 ) if ( X < 1 )
X = 1; X = 1;
setX (X, false); setX (X, false);

View File

@ -56,7 +56,7 @@ watch::watch (FWidget* parent)
{ {
setText ("Watch"); setText ("Watch");
setShadow(); setShadow();
int pw = parentWidget()->getWidth(); int pw = getParentWidget()->getWidth();
setGeometry (1+(pw-22)/2, 3, 22, 13); setGeometry (1+(pw-22)/2, 3, 22, 13);
// Create labels // Create labels
@ -191,7 +191,7 @@ void watch::cb_exitApp (FWidget*, void*)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void watch::adjustSize() void watch::adjustSize()
{ {
int pw = parentWidget()->getWidth(); int pw = getParentWidget()->getWidth();
setX (1+(pw-22)/2, false); setX (1+(pw-22)/2, false);
FDialog::adjustSize(); FDialog::adjustSize();
} }