/////////////////////////////////////////////////////////////////////////////
-// Name: univ/menu.cpp
+// Name: src/univ/menu.cpp
// Purpose: wxMenuItem, wxMenu and wxMenuBar implementation
// Author: Vadim Zeitlin
// Modified by:
// headers
// ----------------------------------------------------------------------------
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
- #pragma implementation "univmenuitem.h"
- #pragma implementation "univmenu.h"
-#endif
-
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
+#if wxUSE_MENUS
+
+#include "wx/menu.h"
+#include "wx/stockitem.h"
+
#ifndef WX_PRECOMP
#include "wx/dynarray.h"
#include "wx/control.h" // for FindAccelIndex()
- #include "wx/menu.h"
#include "wx/settings.h"
#include "wx/accel.h"
#include "wx/log.h"
+ #include "wx/frame.h"
+ #include "wx/dcclient.h"
#endif // WX_PRECOMP
-#if wxUSE_MENUS
-
#include "wx/popupwin.h"
#include "wx/evtloop.h"
-#include "wx/dcclient.h"
-#include "wx/frame.h"
#include "wx/univ/renderer.h"
#include "wx/msw/private.h"
#endif // __WXMSW__
+typedef wxMenuItemList::compatibility_iterator wxMenuItemIter;
+
// ----------------------------------------------------------------------------
// wxMenuInfo contains all extra information about top level menus we need
// ----------------------------------------------------------------------------
m_width = 0;
}
- void SetEnabled(bool enabled = TRUE) { m_isEnabled = enabled; }
+ void SetEnabled(bool enabled = true) { m_isEnabled = enabled; }
// accessors
public:
wxPopupMenuWindow(wxWindow *parent, wxMenu *menu);
- ~wxPopupMenuWindow();
+ virtual ~wxPopupMenuWindow();
// override the base class version to select the first item initially
virtual void Popup(wxWindow *focus = NULL);
// override the base class version to dismiss any open submenus
virtual void Dismiss();
- // notify the menu when the window disappears from screen
- virtual void OnDismiss();
-
// called when a submenu is dismissed
- void OnSubmenuDismiss() { m_hasOpenSubMenu = FALSE; }
+ void OnSubmenuDismiss(bool dismissParent);
+
+ // the default wxMSW wxPopupTransientWindow::OnIdle disables the capture
+ // when the cursor is inside the popup, which dsables the menu tracking
+ // so override it to do nothing
+#ifdef __WXMSW__
+ void OnIdle(wxIdleEvent& WXUNUSED(event)) { }
+#endif
// get the currently selected item (may be NULL)
wxMenuItem *GetCurrentItem() const
}
// find the menu item at given position
- wxMenuItemList::compatibility_iterator GetMenuItemFromPoint(const wxPoint& pt) const;
+ wxMenuItemIter GetMenuItemFromPoint(const wxPoint& pt) const;
// refresh the given item
void RefreshItem(wxMenuItem *item);
// preselect the first item
- void SelectFirst() { SetCurrent(m_menu->GetMenuItems().GetFirst()); }
+ void SelectFirst() { SetCurrentItem(m_menu->GetMenuItems().GetFirst()); }
- // process the key event, return TRUE if done
+ // process the key event, return true if done
bool ProcessKeyDown(int key);
// process mouse move event
WithMouse
};
+ // notify the menu when the window disappears from screen
+ virtual void OnDismiss();
+
// draw the menu inside this window
virtual void DoDraw(wxControlRenderer *renderer);
// reset the current item and node
void ResetCurrent();
- // set the current node and item withotu refreshing anything
- void SetCurrent(wxMenuItemList::compatibility_iterator node);
- virtual bool SetCurrent(bool doit = true){return wxPopupTransientWindow::SetCurrent(doit);};
+ // set the current node and item without refreshing anything
+ void SetCurrentItem(wxMenuItemIter node);
// change the current item refreshing the old and new items
- void ChangeCurrent(wxMenuItemList::compatibility_iterator node);
+ void ChangeCurrent(wxMenuItemIter node);
// activate item, i.e. call either ClickItem() or OpenSubmenu() depending
- // on what it is, return TRUE if something was done (i.e. it's not a
+ // on what it is, return true if something was done (i.e. it's not a
// separator...)
bool ActivateItem(wxMenuItem *item, InputMethod how = WithKeyboard);
bool HasOpenSubmenu() const { return m_hasOpenSubMenu; }
// get previous node after the current one
- wxMenuItemList::compatibility_iterator GetPrevNode() const;
+ wxMenuItemIter GetPrevNode() const;
// get previous node before the given one, wrapping if it's the first one
- wxMenuItemList::compatibility_iterator GetPrevNode(wxMenuItemList::compatibility_iterator node) const;
+ wxMenuItemIter GetPrevNode(wxMenuItemIter node) const;
// get next node after the current one
- wxMenuItemList::compatibility_iterator GetNextNode() const;
+ wxMenuItemIter GetNextNode() const;
// get next node after the given one, wrapping if it's the last one
- wxMenuItemList::compatibility_iterator GetNextNode(wxMenuItemList::compatibility_iterator node) const;
+ wxMenuItemIter GetNextNode(wxMenuItemIter node) const;
private:
// the menu we show
wxMenu *m_menu;
// the menu node corresponding to the current item
- wxMenuItemList::compatibility_iterator m_nodeCurrent;
+ wxMenuItemIter m_nodeCurrent;
// do we currently have an opened submenu?
bool m_hasOpenSubMenu;
}
else
{
- // return FALSE;
+ // return false;
return wxEvtHandler::ProcessEvent(event);
}
EVT_LEFT_UP(wxPopupMenuWindow::OnLeftUp)
EVT_MOTION(wxPopupMenuWindow::OnMouseMove)
EVT_LEAVE_WINDOW(wxPopupMenuWindow::OnMouseLeave)
+#ifdef __WXMSW__
+ EVT_IDLE(wxPopupMenuWindow::OnIdle)
+#endif
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxMenuBar, wxMenuBarBase)
wxPopupMenuWindow::wxPopupMenuWindow(wxWindow *parent, wxMenu *menu)
{
m_menu = menu;
- m_hasOpenSubMenu = FALSE;
+ m_hasOpenSubMenu = false;
ResetCurrent();
void wxPopupMenuWindow::ResetCurrent()
{
-#if wxUSE_STL
- SetCurrent(wxMenuItemList::compatibility_iterator());
-#else
- SetCurrent((wxwxMenuItemListNode *)NULL);
-#endif
+ SetCurrentItem(wxMenuItemIter());
}
-void wxPopupMenuWindow::SetCurrent(wxMenuItemList::compatibility_iterator node)
+void wxPopupMenuWindow::SetCurrentItem(wxMenuItemIter node)
{
m_nodeCurrent = node;
}
-void wxPopupMenuWindow::ChangeCurrent(wxMenuItemList::compatibility_iterator node)
+void wxPopupMenuWindow::ChangeCurrent(wxMenuItemIter node)
{
- if ( node != m_nodeCurrent )
+ if ( !m_nodeCurrent || !node || (node != m_nodeCurrent) )
{
- wxMenuItemList::compatibility_iterator nodeOldCurrent = m_nodeCurrent;
+ wxMenuItemIter nodeOldCurrent = m_nodeCurrent;
m_nodeCurrent = node;
if ( item->IsSubMenu() && item->GetSubMenu()->IsShown() )
{
item->GetSubMenu()->Dismiss();
- OnSubmenuDismiss();
+ OnSubmenuDismiss( false );
}
RefreshItem(item);
}
}
-wxMenuItemList::compatibility_iterator wxPopupMenuWindow::GetPrevNode() const
+wxMenuItemIter wxPopupMenuWindow::GetPrevNode() const
{
// return the last node if there had been no previously selected one
return m_nodeCurrent ? GetPrevNode(m_nodeCurrent)
- : m_menu->GetMenuItems().GetLast();
+ : wxMenuItemIter(m_menu->GetMenuItems().GetLast());
}
-wxMenuItemList::compatibility_iterator
-wxPopupMenuWindow::GetPrevNode(wxMenuItemList::compatibility_iterator node) const
+wxMenuItemIter
+wxPopupMenuWindow::GetPrevNode(wxMenuItemIter node) const
{
if ( node )
{
return node;
}
-wxMenuItemList::compatibility_iterator wxPopupMenuWindow::GetNextNode() const
+wxMenuItemIter wxPopupMenuWindow::GetNextNode() const
{
// return the first node if there had been no previously selected one
return m_nodeCurrent ? GetNextNode(m_nodeCurrent)
- : m_menu->GetMenuItems().GetFirst();
+ : wxMenuItemIter(m_menu->GetMenuItems().GetFirst());
}
-wxMenuItemList::compatibility_iterator
-wxPopupMenuWindow::GetNextNode(wxMenuItemList::compatibility_iterator node) const
+wxMenuItemIter
+wxPopupMenuWindow::GetNextNode(wxMenuItemIter node) const
{
if ( node )
{
wxPopupTransientWindow::Popup(focus);
+ // the base class no-longer captures the mouse automatically when Popup
+ // is called, so do it here to allow the menu tracking to work
+ if ( !HasCapture() )
+ CaptureMouse();
+
#ifdef __WXMSW__
// ensure that this window is really on top of everything: without using
// SetWindowPos() it can be covered by its parent menu which is not
wxCHECK_RET( win, _T("opened submenu is not opened?") );
win->Dismiss();
- OnSubmenuDismiss();
+ OnSubmenuDismiss( false );
}
wxPopupTransientWindow::Dismiss();
+
+ ResetCurrent();
}
void wxPopupMenuWindow::OnDismiss()
{
// when we are dismissed because the user clicked elsewhere or we lost
// focus in any other way, hide the parent menu as well
- HandleDismiss(TRUE);
+ HandleDismiss(true);
}
-void wxPopupMenuWindow::HandleDismiss(bool dismissParent)
+void wxPopupMenuWindow::OnSubmenuDismiss(bool WXUNUSED(dismissParent))
{
- ResetCurrent();
+ m_hasOpenSubMenu = false;
+}
+void wxPopupMenuWindow::HandleDismiss(bool dismissParent)
+{
m_menu->OnDismiss(dismissParent);
}
void wxPopupMenuWindow::DismissAndNotify()
{
Dismiss();
- HandleDismiss(TRUE);
+ HandleDismiss(true);
}
// ----------------------------------------------------------------------------
// wxPopupMenuWindow geometry
// ----------------------------------------------------------------------------
-wxMenuItemList::compatibility_iterator
+wxMenuItemIter
wxPopupMenuWindow::GetMenuItemFromPoint(const wxPoint& pt) const
{
// we only use the y coord normally, but still check x in case the point is
if ( wxWindow::HitTest(pt) == wxHT_WINDOW_INSIDE )
{
wxCoord y = 0;
- for ( wxMenuItemList::compatibility_iterator node = m_menu->GetMenuItems().GetFirst();
+ for ( wxMenuItemIter node = m_menu->GetMenuItems().GetFirst();
node;
node = node->GetNext() )
{
}
}
-#if wxUSE_STL
- return wxMenuItemList::compatibility_iterator();
-#else
- return NULL;
-#endif
+ return wxMenuItemIter();
}
// ----------------------------------------------------------------------------
wxCoord y = 0;
const wxMenuGeometryInfo& gi = m_menu->GetGeometryInfo();
- for ( wxMenuItemList::compatibility_iterator node = m_menu->GetMenuItems().GetFirst();
+ for ( wxMenuItemIter node = m_menu->GetMenuItems().GetFirst();
node;
node = node->GetNext() )
{
if ( item == GetCurrentItem() )
flags |= wxCONTROL_SELECTED;
+ wxBitmap bmp;
+
+ if ( !item->IsEnabled() )
+ {
+ bmp = item->GetDisabledBitmap();
+ }
+
+ if ( !bmp.Ok() )
+ {
+ // strangely enough, for unchecked item we use the
+ // "checked" bitmap because this is the default one - this
+ // explains this strange boolean expression
+ bmp = item->GetBitmap(!item->IsCheckable() || item->IsChecked());
+ }
+
rend->DrawMenuItem
(
dc,
gi,
item->GetLabel(),
item->GetAccelString(),
- // strangely enough, for unchecked item we use the
- // "checked" bitmap because this is the default one - this
- // explains this strange boolean expression
- item->GetBitmap(!item->IsCheckable() || item->IsChecked()),
+ bmp,
flags,
item->GetAccelIndex()
);
wxSize(m_menu->GetGeometryInfo().GetSize().x, 0),
how == WithKeyboard /* preselect first item then */);
- m_hasOpenSubMenu = TRUE;
+ m_hasOpenSubMenu = true;
}
bool wxPopupMenuWindow::ActivateItem(wxMenuItem *item, InputMethod how)
// don't activate disabled items
if ( !item || !item->IsEnabled() )
{
- return FALSE;
+ return false;
}
// normal menu items generate commands, submenus can be opened and
}
else // separator, can't activate
{
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
// ----------------------------------------------------------------------------
{
wxPopupMenuWindow *win = menu->m_popupMenu;
- wxCHECK_MSG( win, FALSE, _T("parent menu not shown?") );
+ wxCHECK_MSG( win, false, _T("parent menu not shown?") );
pos = ClientToScreen(pos);
if ( win->GetMenuItemFromPoint(win->ScreenToClient(pos)) )
{
// eat the event
- return TRUE;
+ return true;
}
//else: it is outside the parent menu as well, do dismiss this one
}
}
- return FALSE;
+ return false;
}
void wxPopupMenuWindow::OnLeftUp(wxMouseEvent& event)
{
- wxMenuItemList::compatibility_iterator node = GetMenuItemFromPoint(event.GetPosition());
+ wxMenuItemIter node = GetMenuItemFromPoint(event.GetPosition());
if ( node )
{
ActivateItem(node->GetData(), WithMouse);
void wxPopupMenuWindow::ProcessMouseMove(const wxPoint& pt)
{
- wxMenuItemList::compatibility_iterator node = GetMenuItemFromPoint(pt);
+ wxMenuItemIter node = GetMenuItemFromPoint(pt);
// don't reset current to NULL here, we only do it when the mouse leaves
// the window (see below)
if ( node )
{
- if ( node != m_nodeCurrent )
+ if ( !m_nodeCurrent || (node != m_nodeCurrent) )
{
ChangeCurrent(node);
else
{
// this menu is the last opened
- resetCurrent = TRUE;
+ resetCurrent = true;
}
if ( resetCurrent )
{
-#if wxUSE_STL
- ChangeCurrent(wxMenuItemList::compatibility_iterator());
-#else
- ChangeCurrent(NULL);
-#endif
+ ChangeCurrent(wxMenuItemIter());
}
}
void wxPopupMenuWindow::OnKeyDown(wxKeyEvent& event)
{
- if ( !ProcessKeyDown(event.GetKeyCode()) )
+ wxMenuBar *menubar = m_menu->GetMenuBar();
+
+ if ( menubar )
+ {
+ menubar->ProcessEvent(event);
+ }
+ else if ( !ProcessKeyDown(event.GetKeyCode()) )
{
event.Skip();
}
// to open it inspit of this)
if ( HasOpenSubmenu() )
{
- wxCHECK_MSG( CanOpen(item), FALSE,
+ wxCHECK_MSG( CanOpen(item), false,
_T("has open submenu but another item selected?") );
if ( item->GetSubMenu()->ProcessKeyDown(key) )
- return TRUE;
+ return true;
}
- bool processed = TRUE;
+ bool processed = true;
// handle the up/down arrows, home, end, esc and return here, pass the
// left/right arrows to the menu bar except when the right arrow can be
// menubar
if ( !m_menu->GetParent() )
{
- processed = FALSE;
+ processed = false;
break;
}
case WXK_ESCAPE:
// close just this menu
Dismiss();
- HandleDismiss(FALSE);
+ HandleDismiss(false);
break;
case WXK_RETURN:
{
bool up = key == WXK_UP;
- wxMenuItemList::compatibility_iterator nodeStart = up ? GetPrevNode()
- : GetNextNode(),
- node = nodeStart;
+ wxMenuItemIter nodeStart = up ? GetPrevNode() : GetNextNode(),
+ node = nodeStart;
while ( node && node->GetData()->IsSeparator() )
{
node = up ? GetPrevNode(node) : GetNextNode(node);
{
// nothing but separators and disabled items in this
// menu, break out
-#if wxUSE_STL
- node = wxMenuItemList::compatibility_iterator();
-#else
- node = NULL;
-#endif
+ node = wxMenuItemIter();
}
}
}
else
{
- processed = FALSE;
+ processed = false;
}
}
break;
}
else
{
- processed = FALSE;
+ processed = false;
}
break;
default:
// look for the menu item starting with this letter
- if ( wxIsalnum(key) )
+ if ( wxIsalnum((wxChar)key) )
{
// we want to start from the item after this one because
// if we're already on the item with the given accel we want to
// go to the next one, not to stay in place
- wxMenuItemList::compatibility_iterator nodeStart = GetNextNode();
+ wxMenuItemIter nodeStart = GetNextNode();
// do we have more than one item with this accel?
- bool notUnique = FALSE;
+ bool notUnique = false;
// translate everything to lower case before comparing
- wxChar chAccel = wxTolower(key);
+ wxChar chAccel = (wxChar)wxTolower(key);
// loop through all items searching for the item with this
// accel
- wxMenuItemList::compatibility_iterator node = nodeStart,
-#if wxUSE_STL
- nodeFound = wxMenuItemList::compatibility_iterator();
-#else
- nodeFound = NULL;
-#endif
+ wxMenuItemIter nodeFound,
+ node = nodeStart;
for ( ;; )
{
item = node->GetData();
}
else // we already had found such item
{
- notUnique = TRUE;
+ notUnique = true;
// no need to continue further, we won't find
// anything we don't already know
//else: just select it but don't activate as the user might
// have wanted to activate another item
- // skip "processed = FALSE" below
+ // skip "processed = false" below
break;
}
}
- processed = FALSE;
+ processed = false;
}
return processed;
m_startRadioGroup = -1;
}
-bool wxMenu::DoAppend(wxMenuItem *item)
+wxMenuItem* wxMenu::DoAppend(wxMenuItem *item)
{
- #if 0
- // not used at all
- bool check = FALSE;
- #endif
-
if ( item->GetKind() == wxITEM_RADIO )
{
int count = GetMenuItemCount();
// for now it has just one element
item->SetAsRadioGroupStart();
item->SetRadioGroupEnd(m_startRadioGroup);
-
- // ensure that we have a checked item in the radio group
- #if 0
- // not used at all
- check = TRUE;
- #endif
}
else // extend the current radio group
{
// we need to update its end item
item->SetRadioGroupStart(m_startRadioGroup);
- wxMenuItemList::compatibility_iterator node = GetMenuItems().Item(m_startRadioGroup);
+ wxMenuItemIter node = GetMenuItems().Item(m_startRadioGroup);
if ( node )
{
}
if ( !wxMenuBase::DoAppend(item) )
- return FALSE;
+ return NULL;
OnItemAdded(item);
- return TRUE;
+ return item;
}
-bool wxMenu::DoInsert(size_t pos, wxMenuItem *item)
+wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item)
{
if ( !wxMenuBase::DoInsert(pos, item) )
- return FALSE;
+ return NULL;
OnItemAdded(item);
- return TRUE;
+ return item;
}
wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
wxWindow *wxMenu::GetRootWindow() const
{
- if ( m_menuBar )
+ if ( GetMenuBar() )
{
// simple case - a normal menu attached to the menubar
- return m_menuBar;
+ return GetMenuBar();
}
// we're a popup menu but the trouble is that only the top level popup menu
wxPopupMenuWindow *win = m_menuParent->m_popupMenu;
if ( win )
{
- win->OnSubmenuDismiss();
+ win->OnSubmenuDismiss( true );
}
else
{
{
// dismissParent is recursive
m_menuParent->Dismiss();
- m_menuParent->OnDismiss(TRUE);
+ m_menuParent->OnDismiss(true);
}
}
else // no parent menu
bool wxMenu::ProcessKeyDown(int key)
{
- wxCHECK_MSG( m_popupMenu, FALSE,
+ wxCHECK_MSG( m_popupMenu, false,
_T("can't process key events if not shown") );
return m_popupMenu->ProcessKeyDown(key);
}
// try our submenus
- for ( wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
+ for ( wxMenuItemIter node = GetMenuItems().GetFirst();
node;
node = node->GetNext() )
{
// try its elements
if ( item->GetSubMenu()->ProcessAccelEvent(event) )
{
- return TRUE;
+ return true;
}
}
}
- return FALSE;
+ return false;
}
void wxMenu::AddAccelFor(wxMenuItem *item)
: wxMenuItemBase(parentMenu, id, text, help, kind, subMenu)
{
m_posY =
- m_height = -1;
+ m_height = wxDefaultCoord;
m_radioGroup.start = -1;
- m_isRadioGroupStart = FALSE;
+ m_isRadioGroupStart = false;
+
+ m_bmpDisabled = wxNullBitmap;
UpdateAccelInfo();
}
if ( text != m_text )
{
// first call the base class version to change m_text
+ // (and also check if we don't have a stock menu item)
wxMenuItemBase::SetText(text);
UpdateAccelInfo();
}
// also uncheck all the other items in this radio group
- wxMenuItemList::compatibility_iterator node = items.Item(start);
+ wxMenuItemIter node = items.Item(start);
for ( int n = start; n <= end && node; n++ )
{
if ( n != pos )
{
- node->GetData()->m_isChecked = FALSE;
+ node->GetData()->m_isChecked = false;
}
node = node->GetNext();
}
void wxMenuItem::SetAsRadioGroupStart()
{
- m_isRadioGroupStart = TRUE;
+ m_isRadioGroupStart = true;
}
void wxMenuItem::SetRadioGroupStart(int start)
m_menuShown = NULL;
- m_shouldShowMenu = FALSE;
+ m_shouldShowMenu = false;
+}
+
+wxMenuBar::wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long WXUNUSED(style))
+{
+ Init();
+
+ for (size_t i = 0; i < n; ++i )
+ Append(menus[i], titles[i]);
}
void wxMenuBar::Attach(wxFrame *frame)
else // not created yet, do it now
{
// we have no way to return the error from here anyhow :-(
- (void)Create(frame, -1);
+ (void)Create(frame, wxID_ANY);
SetCursor(wxCURSOR_ARROW);
SetFont(wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT));
// calculate and set our height (it won't be changed any more)
- SetSize(-1, GetBestSize().y);
+ SetSize(wxDefaultCoord, GetBestSize().y);
}
// remember the last frame which had us to avoid unnecessarily reparenting
bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
{
if ( !wxMenuBarBase::Insert(pos, menu, title) )
- return FALSE;
+ return false;
wxMenuInfo *info = new wxMenuInfo(title);
m_menuInfos.Insert(info, pos);
RefreshAllItemsAfter(pos);
- return TRUE;
+ return true;
}
wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
bool wxMenuBar::IsEnabledTop(size_t pos) const
{
- wxCHECK_MSG( pos < GetCount(), FALSE, _T("invalid index in IsEnabledTop") );
+ wxCHECK_MSG( pos < GetCount(), false, _T("invalid index in IsEnabledTop") );
return m_menuInfos[pos].IsEnabled();
}
wxString wxMenuBar::GetLabelTop(size_t pos) const
{
- wxCHECK_MSG( pos < GetCount(), _T(""), _T("invalid index in GetLabelTop") );
+ wxCHECK_MSG( pos < GetCount(), wxEmptyString, _T("invalid index in GetLabelTop") );
return m_menuInfos[pos].GetLabel();
}
if ( IsShowingMenu() )
{
// restore m_shouldShowMenu flag after DismissMenu() which resets
- // it to FALSE
+ // it to false
bool old = m_shouldShowMenu;
DismissMenu();
}
else // on item
{
- wxLogTrace(_T("mousecapture"), _T("Capturing mouse from wxMenuBar::OnLeftDown"));
+ wxLogTrace(_T("mousecapture"), _T("Capturing mouse from wxMenuBar::OnLeftDown"));
CaptureMouse();
// show it as selected
RefreshItem((size_t)m_current);
// show the menu
- PopupCurrentMenu(FALSE /* don't select first item - as Windows does */);
+ PopupCurrentMenu(false /* don't select first item - as Windows does */);
}
}
}
static wxPoint s_ptLast;
if ( pt == s_ptLast )
{
- return FALSE;
+ return false;
}
s_ptLast = pt;
int currentNew = GetMenuFromPoint(pt);
if ( (currentNew == -1) || (currentNew == m_current) )
{
- return FALSE;
+ return false;
}
// select the new active item
if ( m_shouldShowMenu && !m_menuShown)
{
// open the new menu if the old one we closed had been opened
- PopupCurrentMenu(FALSE /* don't select first item - as Windows does */);
+ PopupCurrentMenu(false /* don't select first item - as Windows does */);
}
- return TRUE;
+ return true;
}
void wxMenuBar::OnKeyDown(wxKeyEvent& event)
// the menu when up/down one is
switch ( key )
{
- case WXK_MENU:
+ case WXK_ALT:
// Alt must be processed at wxWindow level too
event.Skip();
// fall through
int wxMenuBar::FindNextItemForAccel(int idxStart, int key, bool *unique) const
{
- if ( !wxIsalnum(key) )
+ if ( !wxIsalnum((wxChar)key) )
{
// we only support letters/digits as accels
return -1;
// do we have more than one item with this accel?
if ( unique )
- *unique = TRUE;
+ *unique = true;
// translate everything to lower case before comparing
- wxChar chAccel = wxTolower(key);
+ wxChar chAccel = (wxChar)wxTolower(key);
// the index of the item with this accel
int idxFound = -1;
else // we already had found such item
{
if ( unique )
- *unique = FALSE;
+ *unique = false;
// no need to continue further, we won't find
// anything we don't already know
if ( node->GetData()->ProcessAccelEvent(event) )
{
// menu processed it
- return TRUE;
+ return true;
}
}
}
// not found
- return FALSE;
+ return false;
}
#endif // wxUSE_ACCEL
wxASSERT_MSG( !m_menuShown, _T("shouldn't show two menus at once!") );
// in any case, we should show it - even if we won't
- m_shouldShowMenu = TRUE;
+ m_shouldShowMenu = true;
if ( IsEnabledTop(m_current) )
{
// item, not to the right of it
wxRect rectItem = GetItemRect(m_current);
+ m_menuShown->SetInvokingWindow(m_frameLast);
+
m_menuShown->Popup(ClientToScreen(rectItem.GetPosition()),
wxSize(0, rectItem.GetHeight()),
selectFirst);
void wxMenuBar::OnDismissMenu(bool dismissMenuBar)
{
- m_shouldShowMenu = FALSE;
+ m_shouldShowMenu = false;
m_menuShown = NULL;
if ( dismissMenuBar )
{
void wxMenuBar::OnDismiss()
{
- if ( GetCapture() )
- {
+ if ( ReleaseMouseCapture() )
wxLogTrace(_T("mousecapture"), _T("Releasing mouse from wxMenuBar::OnDismiss"));
- GetCapture()->ReleaseMouse();
- }
if ( m_current != -1 )
{
GiveAwayFocus();
}
+bool wxMenuBar::ReleaseMouseCapture()
+{
+#ifdef __WXX11__
+ // With wxX11, when a menu is closed by clicking away from it, a control
+ // under the click will still get an event, even though the menu has the
+ // capture (bug?). So that control may already have taken the capture by
+ // this point, preventing us from releasing the menu's capture. So to work
+ // around this, we release both captures, then put back the control's
+ // capture.
+ wxWindow *capture = GetCapture();
+ if ( capture )
+ {
+ capture->ReleaseMouse();
+
+ if ( capture == this )
+ return true;
+
+ bool had = HasCapture();
+
+ if ( had )
+ ReleaseMouse();
+
+ capture->CaptureMouse();
+
+ return had;
+ }
+#else
+ if ( HasCapture() )
+ {
+ ReleaseMouse();
+ return true;
+ }
+#endif
+ return false;
+}
+
void wxMenuBar::GiveAwayFocus()
{
GetFrame()->SetFocus();
bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y)
{
- wxCHECK_MSG( !ms_evtLoopPopup, FALSE,
+ wxCHECK_MSG( !ms_evtLoopPopup, false,
_T("can't show more than one popup menu at a time") );
#ifdef __WXMSW__
// wxLogDebug( "Name of invoking window %s", menu->GetInvokingWindow()->GetName().c_str() );
- menu->Popup(ClientToScreen(wxPoint(x, y)), wxSize(0, 0));
+ menu->Popup(ClientToScreen(wxPoint(x, y)), wxSize(0,0));
// this is not very useful if the menu was popped up because of the mouse
// click but I think it is nice to do when it appears because of a key
ms_evtLoopPopup = NULL;
// remove the handler
- PopEventHandler(TRUE /* delete it */);
+ PopEventHandler(true /* delete it */);
menu->SetInvokingWindow(NULL);
SetCursor(cursorOld);
#endif // __WXMSW__
- return TRUE;
+ return true;
}
void wxWindow::DismissPopupMenu()
}
#endif // wxUSE_MENUS
-