Deactivate status bar key automatically

This commit is contained in:
Markus Gans 2015-10-10 03:14:14 +02:00
parent a20f3e6ab5
commit 6a92b4a956
12 changed files with 369 additions and 214 deletions

View File

@ -1,3 +1,7 @@
2015-10-10 Markus Gans <guru.mail@muenster.de>
* Deactivate a key from the status bar automatically
after getting back from the callback.
2015-10-09 Markus Gans <guru.mail@muenster.de> 2015-10-09 Markus Gans <guru.mail@muenster.de>
* Eliminate duplicate code * Eliminate duplicate code

View File

@ -948,16 +948,17 @@ void FApplication::processMouseEvent()
|| b_state.wheel_up == Pressed || b_state.wheel_up == Pressed
|| b_state.wheel_down == Pressed ) ) || b_state.wheel_down == Pressed ) )
{ {
FWidget* window = FWindow::windowWidgetAt ( mouse->getX(), FWidget* window = FWindow::windowWidgetAt ( mouse->getX()
mouse->getY() ); , mouse->getY() );
if ( window ) if ( window )
{ {
FWidget* child = childWidgetAt ( window, FWidget* child = childWidgetAt ( window
mouse->getX(), , mouse->getX()
mouse->getY() ); , mouse->getY() );
clicked_widget = (child != 0) ? child : window; clicked_widget = (child != 0) ? child : window;
} }
} }
if ( clicked_widget ) if ( clicked_widget )
{ {
FPoint localMousePos; FPoint localMousePos;
@ -976,26 +977,26 @@ void FApplication::processMouseEvent()
{ {
if ( b_state.left_button == Pressed ) if ( b_state.left_button == Pressed )
{ {
FMouseEvent m_down_ev (MouseMove_Event, FMouseEvent m_down_ev ( MouseMove_Event
localMousePos, , localMousePos
*mouse, , *mouse
LeftButton | key_state); , LeftButton | key_state );
sendEvent (clicked_widget, &m_down_ev); sendEvent (clicked_widget, &m_down_ev);
} }
if ( b_state.right_button == Pressed ) if ( b_state.right_button == Pressed )
{ {
FMouseEvent m_down_ev (MouseMove_Event, FMouseEvent m_down_ev ( MouseMove_Event
localMousePos, , localMousePos
*mouse, , *mouse
RightButton | key_state); , RightButton | key_state );
sendEvent (clicked_widget, &m_down_ev); sendEvent (clicked_widget, &m_down_ev);
} }
if ( b_state.middle_button == Pressed ) if ( b_state.middle_button == Pressed )
{ {
FMouseEvent m_down_ev (MouseMove_Event, FMouseEvent m_down_ev ( MouseMove_Event
localMousePos, , localMousePos
*mouse, , *mouse
MiddleButton | key_state); , MiddleButton | key_state );
sendEvent (clicked_widget, &m_down_ev); sendEvent (clicked_widget, &m_down_ev);
} }
} }
@ -1003,26 +1004,26 @@ void FApplication::processMouseEvent()
{ {
if ( b_state.left_button == DoubleClick ) if ( b_state.left_button == DoubleClick )
{ {
FMouseEvent m_dblclick_ev (MouseDoubleClick_Event, FMouseEvent m_dblclick_ev ( MouseDoubleClick_Event
localMousePos, , localMousePos
*mouse, , *mouse
LeftButton | key_state); , LeftButton | key_state );
sendEvent (clicked_widget, &m_dblclick_ev); sendEvent (clicked_widget, &m_dblclick_ev);
} }
else if ( b_state.left_button == Pressed ) else if ( b_state.left_button == Pressed )
{ {
FMouseEvent m_down_ev (MouseDown_Event, FMouseEvent m_down_ev ( MouseDown_Event
localMousePos, , localMousePos
*mouse, , *mouse
LeftButton | key_state); , LeftButton | key_state );
sendEvent (clicked_widget, &m_down_ev); sendEvent (clicked_widget, &m_down_ev);
} }
else if ( b_state.left_button == Released ) else if ( b_state.left_button == Released )
{ {
FMouseEvent m_up_ev (MouseUp_Event, FMouseEvent m_up_ev ( MouseUp_Event
localMousePos, , localMousePos
*mouse, , *mouse
LeftButton | key_state); , LeftButton | key_state );
FWidget* released_widget = clicked_widget; FWidget* released_widget = clicked_widget;
clicked_widget = 0; clicked_widget = 0;
sendEvent (released_widget, &m_up_ev); sendEvent (released_widget, &m_up_ev);
@ -1030,18 +1031,18 @@ void FApplication::processMouseEvent()
if ( b_state.right_button == Pressed ) if ( b_state.right_button == Pressed )
{ {
FMouseEvent m_down_ev (MouseDown_Event, FMouseEvent m_down_ev ( MouseDown_Event
localMousePos, , localMousePos
*mouse, , *mouse
RightButton | key_state); , RightButton | key_state );
sendEvent (clicked_widget, &m_down_ev); sendEvent (clicked_widget, &m_down_ev);
} }
else if ( b_state.right_button == Released ) else if ( b_state.right_button == Released )
{ {
FMouseEvent m_up_ev (MouseUp_Event, FMouseEvent m_up_ev ( MouseUp_Event
localMousePos, , localMousePos
*mouse, , *mouse
RightButton | key_state); , RightButton | key_state );
FWidget* released_widget = clicked_widget; FWidget* released_widget = clicked_widget;
clicked_widget = 0; clicked_widget = 0;
sendEvent (released_widget, &m_up_ev); sendEvent (released_widget, &m_up_ev);
@ -1049,10 +1050,10 @@ void FApplication::processMouseEvent()
if ( b_state.middle_button == Pressed ) if ( b_state.middle_button == Pressed )
{ {
FMouseEvent m_down_ev (MouseDown_Event, FMouseEvent m_down_ev ( MouseDown_Event
localMousePos, , localMousePos
*mouse, , *mouse
MiddleButton | key_state); , MiddleButton | key_state );
sendEvent (clicked_widget, &m_down_ev); sendEvent (clicked_widget, &m_down_ev);
// gnome-terminal sends no released on middle click // gnome-terminal sends no released on middle click
if ( gnome_terminal ) if ( gnome_terminal )
@ -1060,10 +1061,10 @@ void FApplication::processMouseEvent()
} }
else if ( b_state.middle_button == Released ) else if ( b_state.middle_button == Released )
{ {
FMouseEvent m_up_ev (MouseUp_Event, FMouseEvent m_up_ev ( MouseUp_Event
localMousePos, , localMousePos
*mouse, , *mouse
MiddleButton | key_state); , MiddleButton | key_state );
FWidget* released_widget = clicked_widget; FWidget* released_widget = clicked_widget;
clicked_widget = 0; clicked_widget = 0;
sendEvent (released_widget, &m_up_ev); sendEvent (released_widget, &m_up_ev);
@ -1071,20 +1072,20 @@ void FApplication::processMouseEvent()
} }
if ( b_state.wheel_up == Pressed ) if ( b_state.wheel_up == Pressed )
{ {
FWheelEvent wheel_ev (MouseWheel_Event, FWheelEvent wheel_ev ( MouseWheel_Event
localMousePos, , localMousePos
*mouse, , *mouse
WheelUp); , WheelUp );
FWidget* scroll_over_widget = clicked_widget; FWidget* scroll_over_widget = clicked_widget;
clicked_widget = 0; clicked_widget = 0;
sendEvent(scroll_over_widget, &wheel_ev); sendEvent(scroll_over_widget, &wheel_ev);
} }
if ( b_state.wheel_down == Pressed ) if ( b_state.wheel_down == Pressed )
{ {
FWheelEvent wheel_ev (MouseWheel_Event, FWheelEvent wheel_ev ( MouseWheel_Event
localMousePos, , localMousePos
*mouse, , *mouse
WheelDown); , WheelDown );
FWidget* scroll_over_widget = clicked_widget; FWidget* scroll_over_widget = clicked_widget;
clicked_widget = 0; clicked_widget = 0;
sendEvent (scroll_over_widget, &wheel_ev); sendEvent (scroll_over_widget, &wheel_ev);

View File

@ -137,9 +137,9 @@ class FApplication : public FWidget
void processResizeEvent(); void processResizeEvent();
int processTimerEvent(); int processTimerEvent();
bool processNextEvent(); bool processNextEvent();
friend class FDialog;
friend class FWidget; friend class FWidget;
friend class FWindow; friend class FWindow;
friend class FDialog;
public: public:
FApplication (int &argc, char* argv[]); // constructor FApplication (int &argc, char* argv[]); // constructor

View File

@ -2,6 +2,7 @@
// Provides: class FMenu // Provides: class FMenu
#include "fmenu.h" #include "fmenu.h"
#include "fmessagebox.h" // <----- remove later
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// class FMenu // class FMenu
@ -17,7 +18,7 @@ FMenu::FMenu(FWidget* parent)
, maxItemWidth(0) , maxItemWidth(0)
, mouse_down(false) , mouse_down(false)
{ {
init(); init(parent);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -30,7 +31,7 @@ FMenu::FMenu (FString& txt, FWidget* parent)
, mouse_down(false) , mouse_down(false)
{ {
item = new FMenuItem(txt, parent); item = new FMenuItem(txt, parent);
init(); init(parent);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -43,7 +44,7 @@ FMenu::FMenu (const std::string& txt, FWidget* parent)
, mouse_down(false) , mouse_down(false)
{ {
item = new FMenuItem(txt, parent); item = new FMenuItem(txt, parent);
init(); init(parent);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -56,7 +57,7 @@ FMenu::FMenu (const char* txt, FWidget* parent)
, mouse_down(false) , mouse_down(false)
{ {
item = new FMenuItem(txt, parent); item = new FMenuItem(txt, parent);
init(); init(parent);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -81,7 +82,7 @@ FMenu::~FMenu()
// private methods of FMenu // private methods of FMenu
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenu::init() void FMenu::init(FWidget* parent)
{ {
width = 10; width = 10;
height = 2; height = 2;
@ -107,6 +108,9 @@ void FMenu::init()
backgroundColor = wc.menu_active_bg; backgroundColor = wc.menu_active_bg;
item->setMenu(this); item->setMenu(this);
if ( parent )
setSuperMenu(parent);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -154,13 +158,20 @@ bool FMenu::isMenuBar (FWidget* w) const
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FMenuList* FMenu::superMenu() const bool FMenu::isMenu (FWidget* w) const
{
return bool ( strcmp ( w->getClassName()
, const_cast<char*>("FMenu") ) == 0 );
}
//----------------------------------------------------------------------
FWidget* FMenu::getSuperMenu() const
{ {
return super_menu; return super_menu;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenu::setSuperMenu (FMenuList* smenu) void FMenu::setSuperMenu (FWidget* smenu)
{ {
super_menu = smenu; super_menu = smenu;
} }
@ -195,6 +206,8 @@ void FMenu::draw()
clrscr(); clrscr();
drawBorder(); drawBorder();
drawItems(); drawItems();
//if ( (flags & SHADOW) != 0 )
// drawMenuShadow();
setUpdateVTerm(true); setUpdateVTerm(true);
} }
@ -365,6 +378,7 @@ void FMenu::onMouseDown (FMouseEvent* ev)
if ( ev->getButton() != LeftButton ) if ( ev->getButton() != LeftButton )
{ {
mouse_down = false; mouse_down = false;
if ( ! itemlist.empty() ) if ( ! itemlist.empty() )
{ {
std::vector<FMenuItem*>::const_iterator iter, end; std::vector<FMenuItem*>::const_iterator iter, end;
@ -374,6 +388,7 @@ void FMenu::onMouseDown (FMouseEvent* ev)
while ( iter != end ) while ( iter != end )
{ {
(*iter)->unsetSelected(); (*iter)->unsetSelected();
if ( selectedListItem == *iter )
selectedListItem = 0; selectedListItem = 0;
++iter; ++iter;
} }
@ -381,17 +396,25 @@ void FMenu::onMouseDown (FMouseEvent* ev)
redraw(); redraw();
return; return;
} }
if ( mouse_down ) if ( mouse_down )
return; return;
if ( ! isActiveWindow() )
setActiveWindow(this);
mouse_down = true; mouse_down = true;
if ( ! itemlist.empty() ) if ( ! itemlist.empty() )
{ {
std::vector<FMenuItem*>::const_iterator iter, end; std::vector<FMenuItem*>::const_iterator iter, end;
bool focus_changed = false; bool focus_changed = false;
FPoint mouse_pos;
iter = itemlist.begin(); iter = itemlist.begin();
end = itemlist.end(); end = itemlist.end();
mouse_pos = ev->getPos();
mouse_pos -= FPoint(getRightPadding(),getTopPadding());
while ( iter != end ) while ( iter != end )
{ {
@ -400,8 +423,8 @@ void FMenu::onMouseDown (FMouseEvent* ev)
x1 = (*iter)->getX(); x1 = (*iter)->getX();
x2 = (*iter)->getX() + (*iter)->getWidth() - 1; x2 = (*iter)->getX() + (*iter)->getWidth() - 1;
y = (*iter)->getY(); y = (*iter)->getY();
mouse_x = ev->getX(); mouse_x = mouse_pos.getX();
mouse_y = ev->getY(); mouse_y = mouse_pos.getY();
if ( mouse_x >= x1 if ( mouse_x >= x1
&& mouse_x <= x2 && mouse_x <= x2
@ -410,6 +433,7 @@ void FMenu::onMouseDown (FMouseEvent* ev)
{ {
if ( hasSelectedListItem() ) if ( hasSelectedListItem() )
unselectItemInList(); unselectItemInList();
(*iter)->setSelected(); (*iter)->setSelected();
selectedListItem = *iter; selectedListItem = *iter;
focus_changed = true; focus_changed = true;
@ -434,9 +458,12 @@ void FMenu::onMouseUp (FMouseEvent* ev)
{ {
std::vector<FMenuItem*>::const_iterator iter, end; std::vector<FMenuItem*>::const_iterator iter, end;
bool focus_changed = false; bool focus_changed = false;
FPoint mouse_pos;
iter = itemlist.begin(); iter = itemlist.begin();
end = itemlist.end(); end = itemlist.end();
mouse_pos = ev->getPos();
mouse_pos -= FPoint(getRightPadding(),getTopPadding());
while ( iter != end ) while ( iter != end )
{ {
@ -448,8 +475,8 @@ void FMenu::onMouseUp (FMouseEvent* ev)
if ( (*iter)->isSelected() ) if ( (*iter)->isSelected() )
{ {
int mouse_x = ev->getX(); int mouse_x = mouse_pos.getX();
int mouse_y = ev->getY(); int mouse_y = mouse_pos.getY();
if ( mouse_x >= x1 if ( mouse_x >= x1
&& mouse_x <= x2 && mouse_x <= x2
@ -473,13 +500,19 @@ void FMenu::onMouseMove (FMouseEvent* ev)
if ( ev->getButton() != LeftButton ) if ( ev->getButton() != LeftButton )
return; return;
if ( ! isActiveWindow() )
setActiveWindow(this);
if ( mouse_down && ! itemlist.empty() ) if ( mouse_down && ! itemlist.empty() )
{ {
std::vector<FMenuItem*>::const_iterator iter, end; std::vector<FMenuItem*>::const_iterator iter, end;
bool focus_changed = false; bool focus_changed = false;
FPoint mouse_pos;
iter = itemlist.begin(); iter = itemlist.begin();
end = itemlist.end(); end = itemlist.end();
mouse_pos = ev->getPos();
mouse_pos -= FPoint(getRightPadding(),getTopPadding());
while ( iter != end ) while ( iter != end )
{ {
@ -488,22 +521,54 @@ void FMenu::onMouseMove (FMouseEvent* ev)
x1 = (*iter)->getX(); x1 = (*iter)->getX();
x2 = (*iter)->getX() + (*iter)->getWidth() - 1; x2 = (*iter)->getX() + (*iter)->getWidth() - 1;
y = (*iter)->getY(); y = (*iter)->getY();
mouse_x = ev->getX(); mouse_x = mouse_pos.getX();
mouse_y = ev->getY(); mouse_y = mouse_pos.getY();
/*
FMessageBox::info (this, "Info", FString().sprintf("local(%d,%d) global(%d,%d)\n"
"iter x1=%d, x2=%d, y=%d"
, ev->getX(),ev->getY(),ev->getGlobalX(), ev->getGlobalY()
, x1, x2, y) );*/
if ( mouse_x >= x1 if ( mouse_x >= x1
&& mouse_x <= x2 && mouse_x <= x2
&& mouse_y == y && mouse_y == y )
&& ! (*iter)->isSelected() ) {
if ( (*iter)->isActivated() && ! (*iter)->isSelected() )
{ {
if ( hasSelectedListItem() )
unselectItemInList();
(*iter)->setSelected(); (*iter)->setSelected();
selectedListItem = *iter; selectedListItem = *iter;
focus_changed = true; focus_changed = true;
} }
}
else
{
if ( getGeometryGlobal().contains(ev->getGlobalPos())
&& (*iter)->isActivated()
&& (*iter)->isSelected() )
{
(*iter)->unsetSelected();
if ( selectedListItem == *iter )
selectedListItem = 0;
focus_changed = true;
}
}
++iter; ++iter;
} }
FWidget* menubar = getSuperMenu();
if ( menubar
&& isMenuBar(menubar)
&& menubar->getGeometryGlobal().contains(ev->getGlobalPos()) )
{
const FPoint& g = ev->getGlobalPos();
const FPoint& p = menubar->globalToLocalPos(g);
int b = ev->getButton();
ev = new FMouseEvent (MouseMove_Event, p, g, b);
setClickedWidget(menubar);
FMenuBar* sm = reinterpret_cast<FMenuBar*>(menubar);
sm->onMouseMove(ev);
delete ev;
}
if ( focus_changed ) if ( focus_changed )
redraw(); redraw();
} }

View File

@ -31,6 +31,7 @@
#define _FMENU_H #define _FMENU_H
#include "fwindow.h" #include "fwindow.h"
#include "fmenubar.h"
#include "fmenulist.h" #include "fmenulist.h"
#include "fmenuitem.h" #include "fmenuitem.h"
@ -47,18 +48,19 @@ class FMenu : public FWindow, public FMenuList
private: private:
FMenuItem* item; FMenuItem* item;
FMenuItem* selectedListItem; FMenuItem* selectedListItem;
FMenuList* super_menu; FWidget* super_menu;
uInt maxItemWidth; uInt maxItemWidth;
bool mouse_down; bool mouse_down;
private: private:
FMenu (const FMenu&); FMenu (const FMenu&);
FMenu& operator = (const FMenu&); FMenu& operator = (const FMenu&);
void init(); void init(FWidget*);
void menu_dimension(); void menu_dimension();
bool isMenuBar (FWidget*) const; bool isMenuBar (FWidget*) const;
FMenuList* superMenu() const; bool isMenu (FWidget*) const;
void setSuperMenu (FMenuList*); FWidget* getSuperMenu() const;
void setSuperMenu (FWidget*);
int getHotkeyPos (wchar_t*&, wchar_t*&, uInt); int getHotkeyPos (wchar_t*&, wchar_t*&, uInt);
void draw(); void draw();
void drawBorder(); void drawBorder();

View File

@ -1,6 +1,7 @@
// File: fmenubar.cpp // File: fmenubar.cpp
// Provides: class FMenuBar // Provides: class FMenuBar
#include "fapp.h"
#include "fmenubar.h" #include "fmenubar.h"
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -12,6 +13,7 @@
FMenuBar::FMenuBar(FWidget* parent) FMenuBar::FMenuBar(FWidget* parent)
: FWindow(parent) : FWindow(parent)
, mouse_down(false) , mouse_down(false)
, selectedMenuItem()
{ {
init(); init();
} }
@ -254,6 +256,7 @@ void FMenuBar::onMouseDown (FMouseEvent* ev)
if ( ev->getButton() != LeftButton ) if ( ev->getButton() != LeftButton )
{ {
mouse_down = false; mouse_down = false;
if ( ! itemlist.empty() ) if ( ! itemlist.empty() )
{ {
std::vector<FMenuItem*>::const_iterator iter, end; std::vector<FMenuItem*>::const_iterator iter, end;
@ -263,41 +266,50 @@ void FMenuBar::onMouseDown (FMouseEvent* ev)
while ( iter != end ) while ( iter != end )
{ {
(*iter)->unsetSelected(); (*iter)->unsetSelected();
if ( selectedMenuItem == *iter )
selectedMenuItem = 0;
++iter; ++iter;
} }
} }
redraw(); redraw();
return; return;
} }
if ( mouse_down ) if ( mouse_down )
return; return;
mouse_down = true; mouse_down = true;
if ( ! isActiveWindow() )
setActiveWindow(this);
if ( ! itemlist.empty() ) if ( ! itemlist.empty() )
{ {
std::vector<FMenuItem*>::const_iterator iter, end; std::vector<FMenuItem*>::const_iterator iter, end;
int mouse_x, mouse_y;
bool focus_changed = false; bool focus_changed = false;
iter = itemlist.begin(); iter = itemlist.begin();
end = itemlist.end(); end = itemlist.end();
mouse_x = ev->getX();
mouse_y = ev->getY();
//FMessageBox::info (this, "Info", FString().sprintf("local(%d,%d) global(%d,%d)", ev->getX(),ev->getY(),ev->getGlobalX(), ev->getGlobalY())); //FMessageBox::info (this, "Info", FString().sprintf("local(%d,%d) global(%d,%d)", ev->getX(),ev->getY(),ev->getGlobalX(), ev->getGlobalY()));
// #include "fmessagebox.h" // #include "fmessagebox.h"
while ( iter != end ) while ( iter != end )
{ {
int x1, x2, mouse_x, mouse_y; int x1, x2;
x1 = (*iter)->getX(); x1 = (*iter)->getX();
x2 = (*iter)->getX() + (*iter)->getWidth() - 1; x2 = (*iter)->getX() + (*iter)->getWidth() - 1;
mouse_x = ev->getX();
mouse_y = ev->getY();
if ( mouse_x >= x1 if ( mouse_x >= x1
&& mouse_x <= x2 && mouse_x <= x2
&& mouse_y == 1 ) && mouse_y == 1 )
{ {
if ( ! (*iter)->isSelected() ) if ( (*iter)->isActivated() && ! (*iter)->isSelected() )
{ {
(*iter)->setSelected(); (*iter)->setSelected();
selectedMenuItem = *iter;
focus_changed = true; focus_changed = true;
} }
if ( (*iter)->hasMenu() ) if ( (*iter)->hasMenu() )
@ -312,9 +324,13 @@ void FMenuBar::onMouseDown (FMouseEvent* ev)
} }
else else
{ {
if ( mouse_y == 1 && (*iter)->isSelected() ) if ( mouse_y == 1
&& (*iter)->isActivated()
&& (*iter)->isSelected() )
{ {
(*iter)->unsetSelected(); (*iter)->unsetSelected();
if ( selectedMenuItem == *iter )
selectedMenuItem = 0;
focus_changed = true; focus_changed = true;
} }
} }
@ -337,22 +353,24 @@ void FMenuBar::onMouseUp (FMouseEvent* ev)
if ( ! itemlist.empty() ) if ( ! itemlist.empty() )
{ {
std::vector<FMenuItem*>::const_iterator iter, end; std::vector<FMenuItem*>::const_iterator iter, end;
int mouse_x, mouse_y;
iter = itemlist.begin(); iter = itemlist.begin();
end = itemlist.end(); end = itemlist.end();
mouse_x = ev->getX();
mouse_y = ev->getY();
while ( iter != end ) while ( iter != end )
{ {
int x1, x2, mouse_x, mouse_y; int x1, x2;
x1 = (*iter)->getX(); x1 = (*iter)->getX();
x2 = (*iter)->getX() + (*iter)->getWidth() - 1; x2 = (*iter)->getX() + (*iter)->getWidth() - 1;
mouse_x = ev->getX();
mouse_y = ev->getY();
if ( mouse_x >= x1 if ( mouse_x >= x1
&& mouse_x <= x2 && mouse_x <= x2
&& mouse_y == 1 && mouse_y == 1
&& (*iter)->isActivated()
&& (*iter)->isSelected() ) && (*iter)->isSelected() )
{ {
if ( (*iter)->hasMenu() ) if ( (*iter)->hasMenu() )
@ -367,6 +385,8 @@ void FMenuBar::onMouseUp (FMouseEvent* ev)
else else
{ {
(*iter)->unsetSelected(); (*iter)->unsetSelected();
if ( selectedMenuItem == *iter )
selectedMenuItem = 0;
redraw(); redraw();
(*iter)->processClicked(); (*iter)->processClicked();
} }
@ -383,30 +403,35 @@ void FMenuBar::onMouseMove (FMouseEvent* ev)
if ( ev->getButton() != LeftButton ) if ( ev->getButton() != LeftButton )
return; return;
if ( ! isActiveWindow() )
setActiveWindow(this);
if ( mouse_down && ! itemlist.empty() ) if ( mouse_down && ! itemlist.empty() )
{ {
std::vector<FMenuItem*>::const_iterator iter, end; std::vector<FMenuItem*>::const_iterator iter, end;
int mouse_x, mouse_y;
bool focus_changed = false; bool focus_changed = false;
iter = itemlist.begin(); iter = itemlist.begin();
end = itemlist.end(); end = itemlist.end();
mouse_x = ev->getX();
mouse_y = ev->getY();
while ( iter != end ) while ( iter != end )
{ {
int x1, x2, mouse_x, mouse_y; int x1, x2;
x1 = (*iter)->getX(); x1 = (*iter)->getX();
x2 = (*iter)->getX() + (*iter)->getWidth() - 1; x2 = (*iter)->getX() + (*iter)->getWidth() - 1;
mouse_x = ev->getX();
mouse_y = ev->getY();
if ( mouse_x >= x1 if ( mouse_x >= x1
&& mouse_x <= x2 && mouse_x <= x2
&& mouse_y == 1 ) && mouse_y == 1 )
{ {
if ( ! (*iter)->isSelected() ) if ( (*iter)->isActivated() && ! (*iter)->isSelected() )
{ {
(*iter)->setSelected(); (*iter)->setSelected();
selectedMenuItem = *iter;
focus_changed = true; focus_changed = true;
} }
if ( (*iter)->hasMenu() ) if ( (*iter)->hasMenu() )
@ -421,11 +446,30 @@ void FMenuBar::onMouseMove (FMouseEvent* ev)
} }
else else
{ {
if ( mouse_y == 1 && (*iter)->isSelected() ) if ( getGeometryGlobal().contains(ev->getGlobalPos())
&& (*iter)->isActivated()
&& (*iter)->isSelected() )
{ {
(*iter)->unsetSelected(); (*iter)->unsetSelected();
if ( selectedMenuItem == *iter )
selectedMenuItem = 0;
focus_changed = true; focus_changed = true;
} }
else if ( hasSelectedMenuItem() && selectedMenuItem->hasMenu() )
{
FMenu* menu = selectedMenuItem->getMenu();
const FRect& menu_geometry = menu->getGeometryGlobal();
if ( menu_geometry.contains(ev->getGlobalPos()) )
{
const FPoint& g = ev->getGlobalPos();
const FPoint& p = menu->globalToLocalPos(g);
int b = ev->getButton();
ev = new FMouseEvent (MouseMove_Event, p, g, b);
setClickedWidget(menu);
menu->onMouseDown(ev);
}
}
} }
++iter; ++iter;
} }
@ -473,7 +517,6 @@ void FMenuBar::cb_item_activated (FWidget* widget, void*)
if ( menuitem->hasMenu() ) if ( menuitem->hasMenu() )
{ {
//beep();
FMenu* menu = menuitem->getMenu(); FMenu* menu = menuitem->getMenu();
if ( ! menu->isVisible() ) if ( ! menu->isVisible() )
{ {
@ -495,7 +538,6 @@ void FMenuBar::cb_item_deactivated (FWidget* widget, void*)
if ( menuitem->hasMenu() ) if ( menuitem->hasMenu() )
{ {
//beep();
FMenu* menu = menuitem->getMenu(); FMenu* menu = menuitem->getMenu();
if ( menu->isVisible() ) if ( menu->isVisible() )
menu->hide(); menu->hide();

View File

@ -30,8 +30,8 @@
#ifndef _FMENUBAR_H #ifndef _FMENUBAR_H
#define _FMENUBAR_H #define _FMENUBAR_H
#include "fmenulist.h"
#include "fmenu.h" #include "fmenu.h"
#include "fmenulist.h"
#include "fwindow.h" #include "fwindow.h"
@ -46,6 +46,7 @@ class FMenuBar : public FWindow, public FMenuList
{ {
private: private:
bool mouse_down; bool mouse_down;
FMenuItem* selectedMenuItem;
private: private:
FMenuBar (const FMenuBar&); FMenuBar (const FMenuBar&);
@ -67,6 +68,7 @@ class FMenuBar : public FWindow, public FMenuList
void onMouseUp (FMouseEvent*); void onMouseUp (FMouseEvent*);
void onMouseMove (FMouseEvent*); void onMouseMove (FMouseEvent*);
void hide(); void hide();
bool hasSelectedMenuItem() const;
// make every setGeometry from FWidget available // make every setGeometry from FWidget available
using FWidget::setGeometry; using FWidget::setGeometry;
void setGeometry (int, int, int, int, bool = true); void setGeometry (int, int, int, int, bool = true);
@ -84,4 +86,8 @@ class FMenuBar : public FWindow, public FMenuList
inline const char* FMenuBar::getClassName() const inline const char* FMenuBar::getClassName() const
{ return "FMenuBar"; } { return "FMenuBar"; }
//----------------------------------------------------------------------
inline bool FMenuBar::hasSelectedMenuItem() const
{ return selectedMenuItem; }
#endif // _FMENUBAR_H #endif // _FMENUBAR_H

View File

@ -3,8 +3,8 @@
#include "fmenu.h" #include "fmenu.h"
#include "fmenubar.h" #include "fmenubar.h"
#include "fmenuitem.h"
#include "fmenulist.h" #include "fmenulist.h"
#include "fmenuitem.h"
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// class FMenuItem // class FMenuItem
@ -96,12 +96,10 @@ void FMenuItem::init (FWidget* parent)
if ( parent ) if ( parent )
{ {
setSuperMenu(parent);
FMenuList* sm_list = dynamic_cast<FMenuList*>(parent); FMenuList* sm_list = dynamic_cast<FMenuList*>(parent);
if ( sm_list ) if ( sm_list )
{
setSuperMenu(sm_list);
sm_list->insert(this); sm_list->insert(this);
}
if ( isMenuBar(parent) ) // Parent is menubar if ( isMenuBar(parent) ) // Parent is menubar
{ {
@ -114,12 +112,12 @@ void FMenuItem::init (FWidget* parent)
this->addCallback this->addCallback
( (
"activate", "activate",
_METHOD_CALLBACK (superMenu(), &FMenuBar::cb_item_activated) _METHOD_CALLBACK (getSuperMenu(), &FMenuBar::cb_item_activated)
); );
this->addCallback this->addCallback
( (
"deactivate", "deactivate",
_METHOD_CALLBACK (superMenu(), &FMenuBar::cb_item_deactivated) _METHOD_CALLBACK (getSuperMenu(), &FMenuBar::cb_item_deactivated)
); );
} }
else if ( isMenu(parent) ) // Parent is menu else if ( isMenu(parent) ) // Parent is menu
@ -133,12 +131,12 @@ void FMenuItem::init (FWidget* parent)
this->addCallback this->addCallback
( (
"activate", "activate",
_METHOD_CALLBACK (superMenu(), &FMenu::cb_menuitem_activated) _METHOD_CALLBACK (getSuperMenu(), &FMenu::cb_menuitem_activated)
); );
this->addCallback this->addCallback
( (
"deactivate", "deactivate",
_METHOD_CALLBACK (superMenu(), &FMenu::cb_menuitem_deactivated) _METHOD_CALLBACK (getSuperMenu(), &FMenu::cb_menuitem_deactivated)
); );
} }
} }
@ -169,17 +167,6 @@ uChar FMenuItem::getHotkey()
return 0; return 0;
} }
//----------------------------------------------------------------------
bool FMenuItem::isMenuBar (FMenuList* ml) const
{
FWidget* menubar_ptr = dynamic_cast<FWidget*>(ml);
if ( menubar_ptr )
return isMenuBar(menubar_ptr);
else
return false;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMenuItem::isMenuBar (FWidget* w) const bool FMenuItem::isMenuBar (FWidget* w) const
{ {
@ -187,17 +174,6 @@ bool FMenuItem::isMenuBar (FWidget* w) const
, const_cast<char*>("FMenuBar") ) == 0 ); , const_cast<char*>("FMenuBar") ) == 0 );
} }
//----------------------------------------------------------------------
bool FMenuItem::isMenu (FMenuList* ml) const
{
FWidget* super_menu_ptr = dynamic_cast<FWidget*>(ml);
if ( super_menu_ptr )
return isMenu(super_menu_ptr);
else
return false;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMenuItem::isMenu (FWidget* w) const bool FMenuItem::isMenu (FWidget* w) const
{ {
@ -206,13 +182,13 @@ bool FMenuItem::isMenu (FWidget* w) const
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FMenuList* FMenuItem::superMenu() const FWidget* FMenuItem::getSuperMenu() const
{ {
return super_menu; return super_menu;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuItem::setSuperMenu (FMenuList* smenu) void FMenuItem::setSuperMenu (FWidget* smenu)
{ {
super_menu = smenu; super_menu = smenu;
} }
@ -242,7 +218,7 @@ void FMenuItem::onAccel (FAccelEvent* ev)
if ( isSelected() ) if ( isSelected() )
{ {
unsetSelected(); unsetSelected();
FWidget* w = reinterpret_cast<FWidget*>(superMenu()); FWidget* w = reinterpret_cast<FWidget*>(getSuperMenu());
if ( w && isMenuBar(w) ) if ( w && isMenuBar(w) )
w->redraw(); w->redraw();
ev->accept(); ev->accept();
@ -252,91 +228,106 @@ void FMenuItem::onAccel (FAccelEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuItem::onMouseDown (FMouseEvent* ev) void FMenuItem::onMouseDown (FMouseEvent* ev)
{ {
const FPoint& p1 = ev->getPos();
const FPoint& g = ev->getGlobalPos();
FPoint p2(p1);
int b = ev->getButton();
p2 = p1 + getPos() - FPoint(1,1);
ev = new FMouseEvent (MouseMove_Event, p2, g, b);
if ( super_menu ) if ( super_menu )
{ {
const FPoint& g = ev->getGlobalPos();
int b = ev->getButton();
if ( isMenu(super_menu) ) if ( isMenu(super_menu) )
{ {
FMenu* sm = dynamic_cast<FMenu*>(super_menu); FMenu* sm = dynamic_cast<FMenu*>(super_menu);
if ( sm ) if ( sm )
{
const FPoint& p2 = sm->globalToLocalPos(g);
ev = new FMouseEvent (MouseMove_Event, p2, g, b);
sm->onMouseDown(ev); sm->onMouseDown(ev);
delete ev;
}
} }
if ( isMenuBar(super_menu) ) if ( isMenuBar(super_menu) )
{ {
FMenuBar* mb = dynamic_cast<FMenuBar*>(super_menu); FMenuBar* mb = dynamic_cast<FMenuBar*>(super_menu);
if ( mb ) if ( mb )
{
const FPoint& p2 = mb->globalToLocalPos(g);
ev = new FMouseEvent (MouseMove_Event, p2, g, b);
mb->onMouseDown(ev); mb->onMouseDown(ev);
delete ev;
} }
} }
delete ev; }
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuItem::onMouseUp (FMouseEvent* ev) void FMenuItem::onMouseUp (FMouseEvent* ev)
{ {
const FPoint& p1 = ev->getPos();
const FPoint& g = ev->getGlobalPos();
FPoint p2(p1);
int b = ev->getButton();
p2 = p1 + getPos() - FPoint(1,1);
ev = new FMouseEvent (MouseMove_Event, p2, g, b);
if ( super_menu ) if ( super_menu )
{ {
const FPoint& g = ev->getGlobalPos();
int b = ev->getButton();
if ( isMenu(super_menu) ) if ( isMenu(super_menu) )
{ {
FMenu* sm = dynamic_cast<FMenu*>(super_menu); FMenu* sm = dynamic_cast<FMenu*>(super_menu);
if ( sm ) if ( sm )
{
const FPoint& p2 = sm->globalToLocalPos(g);
ev = new FMouseEvent (MouseMove_Event, p2, g, b);
sm->onMouseUp(ev); sm->onMouseUp(ev);
delete ev;
}
} }
if ( isMenuBar(super_menu) ) if ( isMenuBar(super_menu) )
{ {
FMenuBar* mb = dynamic_cast<FMenuBar*>(super_menu); FMenuBar* mb = dynamic_cast<FMenuBar*>(super_menu);
if ( mb ) if ( mb )
{
const FPoint& p2 = mb->globalToLocalPos(g);
ev = new FMouseEvent (MouseMove_Event, p2, g, b);
mb->onMouseUp(ev); mb->onMouseUp(ev);
delete ev;
} }
} }
delete ev; }
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuItem::onMouseMove (FMouseEvent* ev) void FMenuItem::onMouseMove (FMouseEvent* ev)
{ {
const FPoint& p1 = ev->getPos();
const FPoint& g = ev->getGlobalPos();
FPoint p2(p1);
int b = ev->getButton();
p2 = p1 + getPos() - FPoint(1,1);
ev = new FMouseEvent (MouseMove_Event, p2, g, b);
if ( super_menu ) if ( super_menu )
{ {
const FPoint& g = ev->getGlobalPos();
int b = ev->getButton();
if ( isMenu(super_menu) ) if ( isMenu(super_menu) )
{ {
FMenu* sm = dynamic_cast<FMenu*>(super_menu); FMenu* sm = dynamic_cast<FMenu*>(super_menu);
if ( sm ) if ( sm )
{
const FPoint& p2 = sm->globalToLocalPos(g);
ev = new FMouseEvent (MouseMove_Event, p2, g, b);
sm->onMouseMove(ev); sm->onMouseMove(ev);
delete ev;
}
} }
if ( isMenuBar(super_menu) ) if ( isMenuBar(super_menu) )
{ {
FMenuBar* mb = dynamic_cast<FMenuBar*>(super_menu); FMenuBar* mb = dynamic_cast<FMenuBar*>(super_menu);
if ( mb ) if ( mb )
{
const FPoint& p2 = mb->globalToLocalPos(g);
ev = new FMouseEvent (MouseMove_Event, p2, g, b);
mb->onMouseMove(ev); mb->onMouseMove(ev);
delete ev;
} }
} }
delete ev; }
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -52,19 +52,17 @@ class FMenuItem : public FWidget
int hotkey; int hotkey;
//int accel_key; //int accel_key;
FMenu* menu; FMenu* menu;
FMenuList* super_menu; FWidget* super_menu;
private: private:
FMenuItem (const FMenuItem&); FMenuItem (const FMenuItem&);
FMenuItem& operator = (const FMenuItem&); FMenuItem& operator = (const FMenuItem&);
void init (FWidget*); void init (FWidget*);
uChar getHotkey(); uChar getHotkey();
bool isMenuBar (FMenuList*) const;
bool isMenuBar (FWidget*) const; bool isMenuBar (FWidget*) const;
bool isMenu (FMenuList*) const;
bool isMenu (FWidget*) const; bool isMenu (FWidget*) const;
FMenuList* superMenu() const; FWidget* getSuperMenu() const;
void setSuperMenu (FMenuList*); void setSuperMenu (FWidget*);
void processActivate(); void processActivate();
void processDeactivate(); void processDeactivate();
void processClicked(); void processClicked();

View File

@ -94,6 +94,9 @@ void FStatusKey::onAccel (FAccelEvent* ev)
setActive(); setActive();
statusbar()->redraw(); statusbar()->redraw();
ev->accept(); ev->accept();
// unset after get back from callback
unsetActive();
statusbar()->redraw();
} }
} }
@ -440,6 +443,8 @@ void FStatusBar::onMouseUp (FMouseEvent* ev)
mouse_y = ev->getY(); mouse_y = ev->getY();
if ( mouse_x >= x1 && mouse_x <= x2 && mouse_y == 1 ) if ( mouse_x >= x1 && mouse_x <= x2 && mouse_y == 1 )
(*iter)->setActive(); (*iter)->setActive();
// unset after get back from callback
(*iter)->unsetActive();
redraw(); redraw();
} }
X = x2 + 2; X = x2 + 2;

View File

@ -2,8 +2,8 @@
// Provides: class FWidget // Provides: class FWidget
#include "fapp.h" #include "fapp.h"
#include "fstatusbar.h"
#include "fmenubar.h" #include "fmenubar.h"
#include "fstatusbar.h"
#include "fwidget.h" #include "fwidget.h"
#include "fwindow.h" #include "fwindow.h"

View File

@ -1,4 +1,4 @@
// ui.cpp // File: ui.cpp
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
@ -25,7 +25,7 @@ class ProgressDialog : public FDialog
FProgressbar* progressBar; FProgressbar* progressBar;
public: public:
explicit ProgressDialog (FWidget* parent=0); // constructor explicit ProgressDialog (FWidget* = 0); // constructor
~ProgressDialog(); // destructor ~ProgressDialog(); // destructor
void onShow (FShowEvent*); void onShow (FShowEvent*);
@ -167,7 +167,7 @@ class MyDialog : public FDialog
MyDialog& operator = (const MyDialog&); // and operator '=' MyDialog& operator = (const MyDialog&); // and operator '='
public: public:
explicit MyDialog (FWidget* parent=0); // constructor explicit MyDialog (FWidget* = 0); // constructor
~MyDialog(); // destructor ~MyDialog(); // destructor
void onClose (FCloseEvent*); void onClose (FCloseEvent*);
void cb_noFunctionMsg (FWidget*, void*); void cb_noFunctionMsg (FWidget*, void*);
@ -191,25 +191,77 @@ MyDialog::MyDialog (FWidget* parent)
: FDialog(parent) : FDialog(parent)
, myList() , myList()
{ {
/* This Code is working in progress... /* .--------------------------------------------. */
/* v This Code is working in progress v * /
FMenuBar* menubar = new FMenuBar(this); FMenuBar* Menubar = new FMenuBar(this);
FMenu* file = new FMenu("&File", menubar);
FMenu* edit = new FMenu("&Edit", menubar);
FMenuItem* open = new FMenuItem("&Open", file); FMenu* File = new FMenu("&File", Menubar);
FMenuItem* quit = new FMenuItem("&Quit", file); FMenu* Edit = new FMenu("&Edit", Menubar);
FMenu* View = new FMenu("&View", Menubar);
FMenuItem* Options = new FMenuItem("&Options", Menubar);
Options->unsetActive();
FMenuItem* Help = new FMenuItem("&Help", Menubar);
FMenuItem* cut = new FMenuItem("Cu&t", edit); FMenuItem* Open = new FMenuItem("&Open...", File);
FMenuItem* copy = new FMenuItem("&Copy", edit); FMenuItem* Quit = new FMenuItem("&Quit", File);
FMenuItem* paste = new FMenuItem("&Paste", edit);
quit->addCallback FMenuItem* Cut = new FMenuItem("Cu&t", Edit);
FMenuItem* Copy = new FMenuItem("&Copy", Edit);
FMenuItem* Paste = new FMenuItem("&Paste", Edit);
FMenuItem* Env = new FMenuItem("&Terminal info...", View);
FMenuItem* Drive = new FMenuItem("&Drive symbols...", View);
Open->addCallback
(
"clicked",
_METHOD_CALLBACK (this, &MyDialog::cb_view)
);
Quit->addCallback
( (
"clicked", "clicked",
_METHOD_CALLBACK (this, &MyDialog::cb_exitApp) _METHOD_CALLBACK (this, &MyDialog::cb_exitApp)
); );
*/ Cut->addCallback
(
"clicked",
_METHOD_CALLBACK (this, &MyDialog::cb_noFunctionMsg)
);
Copy->addCallback
(
"clicked",
_METHOD_CALLBACK (this, &MyDialog::cb_noFunctionMsg)
);
Paste->addCallback
(
"clicked",
_METHOD_CALLBACK (this, &MyDialog::cb_noFunctionMsg)
);
Env->addCallback
(
"clicked",
_METHOD_CALLBACK (this, &MyDialog::cb_info)
);
Drive->addCallback
(
"clicked",
_METHOD_CALLBACK (this, &MyDialog::cb_info)
);
Options->addCallback
(
"clicked",
_METHOD_CALLBACK (this, &MyDialog::cb_exitApp)
);
Help->addCallback
(
"clicked",
_METHOD_CALLBACK (this, &MyDialog::cb_about)
);
/ * ^ This Code is working in progress ^ */
/* '--------------------------------------------' */
FButton* MyButton1 = new FButton(this); FButton* MyButton1 = new FButton(this);
MyButton1->setGeometry(3, 3, 5, 1); MyButton1->setGeometry(3, 3, 5, 1);
MyButton1->setText(L"&SIN"); MyButton1->setText(L"&SIN");
@ -413,8 +465,7 @@ MyDialog::MyDialog (FWidget* parent)
key_F3->addCallback key_F3->addCallback
( (
"activate", "activate",
_METHOD_CALLBACK (this, &MyDialog::cb_exitApp), _METHOD_CALLBACK (this, &MyDialog::cb_exitApp)
key_F3
); );
} }
@ -447,10 +498,9 @@ void MyDialog::cb_noFunctionMsg (FWidget* widget, void*)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MyDialog::cb_about (FWidget* widget, void*) void MyDialog::cb_about (FWidget*, void*)
{ {
const char ver[] = F_VERSION; const char ver[] = F_VERSION;
FStatusKey* skey = static_cast<FStatusKey*>(widget);
FString line(2, wchar_t(fc::BoxDrawingsHorizontal)); FString line(2, wchar_t(fc::BoxDrawingsHorizontal));
FMessageBox info ( "About" FMessageBox info ( "About"
@ -460,7 +510,6 @@ void MyDialog::cb_about (FWidget* widget, void*)
, FMessageBox::Ok, 0, 0, this ); , FMessageBox::Ok, 0, 0, this );
info.setCenterText(); info.setCenterText();
info.show(); info.show();
skey->unsetActive();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -571,15 +620,11 @@ void MyDialog::cb_activateButton (FWidget* widget, void* data_ptr)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MyDialog::cb_view (FWidget* widget, void*) void MyDialog::cb_view (FWidget*, void*)
{ {
FStatusKey* skey = static_cast<FStatusKey*>(widget);
FString file = FFileDialog::fileOpenChooser (this); FString file = FFileDialog::fileOpenChooser (this);
if ( file.isNull() ) if ( file.isNull() )
{
skey->unsetActive();
return; return;
}
FDialog* view = new FDialog(this); FDialog* view = new FDialog(this);
view->setText ("viewer"); view->setText ("viewer");
@ -612,7 +657,6 @@ void MyDialog::cb_view (FWidget* widget, void*)
if ( infile.is_open() ) if ( infile.is_open() )
infile.close(); infile.close();
view->show(); view->show();
skey->unsetActive();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -625,12 +669,9 @@ void MyDialog::cb_setInput (FWidget* widget, void* data_ptr)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MyDialog::cb_exitApp (FWidget*, void* data_ptr) void MyDialog::cb_exitApp (FWidget*, void*)
{ {
FStatusKey* skey = static_cast<FStatusKey*>(data_ptr);
close(); close();
if ( skey )
skey->unsetActive();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------