// ----------------------------------------------------------------------------
#ifdef __GNUG__
- #pragma implementation "menuitem.h"
- #pragma implementation "menu.h"
+ #pragma implementation "univmenuitem.h"
+ #pragma implementation "univmenu.h"
#endif
#include "wx/wxprec.h"
{
wxSize size;
wxClientDC dc(menubar);
- dc.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
+ dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
dc.GetTextExtent(m_label, &size.x, &size.y);
// adjust for the renderer we use and store the width
{
public:
wxPopupMenuWindow(wxWindow *parent, wxMenu *menu);
+
+ ~wxPopupMenuWindow();
// override the base class version to select the first item initially
virtual void Popup(wxWindow *focus = NULL);
}
else
{
+ // return FALSE;
+
return wxEvtHandler::ProcessEvent(event);
}
}
SetCursor(wxCURSOR_ARROW);
}
+wxPopupMenuWindow::~wxPopupMenuWindow()
+{
+ // When m_popupMenu in wxMenu is deleted because it
+ // is a child of an old menu bar being deleted (note: it does
+ // not get destroyed by the wxMenu destructor, but
+ // by DestroyChildren()), m_popupMenu should be reset to NULL.
+
+ m_menu->m_popupMenu = NULL;
+}
+
// ----------------------------------------------------------------------------
// wxPopupMenuWindow current item/node handling
// ----------------------------------------------------------------------------
{
if ( node != m_nodeCurrent )
{
- if ( m_nodeCurrent )
+ wxMenuItemList::Node *nodeOldCurrent = m_nodeCurrent;
+
+ m_nodeCurrent = node;
+
+ if ( nodeOldCurrent )
{
- wxMenuItem *item = m_nodeCurrent->GetData();
+ wxMenuItem *item = nodeOldCurrent->GetData();
wxCHECK_RET( item, _T("no current item?") );
// if it was the currently opened menu, close it
RefreshItem(item);
}
- m_nodeCurrent = node;
-
if ( m_nodeCurrent )
RefreshItem(m_nodeCurrent->GetData());
}
wxMenuItemList::Node *wxPopupMenuWindow::GetPrevNode() const
{
- wxMenuItemList::Node *node = m_nodeCurrent;
- if ( !node )
- {
- // start from the end if no current item
- node = m_menu->GetMenuItems().GetLast();
- }
-
- return GetPrevNode(node);
+ // return the last node if there had been no previously selected one
+ return m_nodeCurrent ? GetPrevNode(m_nodeCurrent)
+ : m_menu->GetMenuItems().GetLast();
}
wxMenuItemList::Node *
wxMenuItemList::Node *wxPopupMenuWindow::GetNextNode() const
{
- wxMenuItemList::Node *node = m_nodeCurrent;
- if ( !node )
- {
- // start from the beginning if no current item
- node = m_menu->GetMenuItems().GetFirst();
- }
-
- return GetNextNode(node);
+ // return the first node if there had been no previously selected one
+ return m_nodeCurrent ? GetNextNode(m_nodeCurrent)
+ : m_menu->GetMenuItems().GetFirst();
}
wxMenuItemList::Node *
// never partially covered as it is always on top of everything
wxDC& dc = renderer->GetDC();
- dc.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
+ dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
// FIXME: this should be done in the renderer, however when it is fixed
// wxPopupMenuWindow::RefreshItem() should be changed too!
wxASSERT_MSG( !item->IsSeparator() && !item->IsSubMenu(),
_T("can't click this item") );
- m_menu->ClickItem(item);
+ wxMenu* menu = m_menu;
// close all menus
DismissAndNotify();
+
+ menu->ClickItem(item);
}
void wxPopupMenuWindow::OpenSubmenu(wxMenuItem *item, InputMethod how)
wxPopupMenuWindow *win = menu->m_popupMenu;
wxCHECK_MSG( win, FALSE, _T("parent menu not shown?") );
-
+
pos = ClientToScreen(pos);
if ( win->GetMenuItemFromPoint(win->ScreenToClient(pos)) )
{
wxMenu *menu = GetParent();
while ( menu )
{
+ // We are a submenu of a menu of a menubar
+ if (menu->GetMenuBar())
+ return menu->GetMenuBar();
+
win = menu->GetInvokingWindow();
if ( win )
break;
// we're probably going to crash in the caller anyhow, but try to detect
// this error as soon as possible
wxASSERT_MSG( win, _T("menu without any associated window?") );
-
+
// also remember it in this menu so that we don't have to search for it the
// next time
wxConstCast(this, wxMenu)->m_invokingWindow = win;
wxCHECK_RET( m_invokingWindow, _T("what kind of menu is this?") );
m_invokingWindow->DismissPopupMenu();
- SetInvokingWindow(NULL);
+
+ // Why reset it here? We need it for sending the event to...
+ // SetInvokingWindow(NULL);
}
}
}
{
m_popupMenu->SelectFirst();
}
-
+
// the geometry might have changed since the last time we were shown, so
// always resize
m_popupMenu->SetClientSize(GetGeometryInfo().GetSize());
// not applicabled
isChecked = -1;
}
-
+
return SendEvent(item->GetId(), isChecked);
}
int id,
const wxString& text,
const wxString& help,
- bool isCheckable,
+ wxItemKind kind,
wxMenu *subMenu)
+ : wxMenuItemBase(parentMenu, id, text, help, kind, subMenu)
{
- m_id = id;
- m_parentMenu = parentMenu;
- m_subMenu = subMenu;
-
- m_text = text;
- m_help = help;
-
- m_isCheckable = isCheckable;
- m_isEnabled = TRUE;
- m_isChecked = FALSE;
-
m_posY =
m_height = -1;
int id,
const wxString& name,
const wxString& help,
- bool isCheckable,
+ wxItemKind kind,
wxMenu *subMenu)
{
- return new wxMenuItem(parentMenu, id, name, help, isCheckable, subMenu);
+ return new wxMenuItem(parentMenu, id, name, help, kind, subMenu);
}
/* static */
void wxMenuItem::SetCheckable(bool checkable)
{
- if ( checkable != m_isCheckable )
+ if ( checkable != IsCheckable() )
{
wxMenuItemBase::SetCheckable(checkable);
m_menuShown = NULL;
m_shouldShowMenu = FALSE;
+
+ m_windowStyle |= wxNO_FULL_REPAINT_ON_RESIZE;
}
void wxMenuBar::Attach(wxFrame *frame)
SetCursor(wxCURSOR_ARROW);
- SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT));
+ SetFont(wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT));
+
+ // calculate and set our height (it won't be changed any more)
+ SetSize(-1, GetBestSize().y);
}
// remember the last frame which had us to avoid unnecessarily reparenting
void wxMenuBar::RefreshAllItemsAfter(size_t pos)
{
+ if ( !IsCreated() )
+ {
+ // no need to refresh if nothing is shown yet
+ return;
+ }
+
wxRect rect = GetItemRect(pos);
rect.width = GetClientSize().x - rect.x;
RefreshRect(rect);
wxCHECK_RET( pos != (size_t)-1,
_T("invalid item in wxMenuBar::RefreshItem") );
+ if ( !IsCreated() )
+ {
+ // no need to refresh if nothing is shown yet
+ return;
+ }
+
RefreshRect(GetItemRect(pos));
}
void wxMenuBar::DoDraw(wxControlRenderer *renderer)
{
wxDC& dc = renderer->GetDC();
- dc.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
+ dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
// redraw only the items which must be redrawn
wxRect wxMenuBar::GetItemRect(size_t pos) const
{
wxASSERT_MSG( pos < GetCount(), _T("invalid menu bar item index") );
+ wxASSERT_MSG( IsCreated(), _T("can't call this method yet") );
wxRect rect;
rect.x =
if ( GetMenuCount() > 0 )
{
wxClientDC dc(wxConstCast(this, wxMenuBar));
- dc.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
+ dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
dc.GetTextExtent(GetLabelTop(0), &size.x, &size.y);
// adjust for the renderer we use
void wxMenuBar::SelectMenu(size_t pos)
{
SetFocus();
+ wxLogTrace(_T("mousecapture"), _T("Capturing mouse from wxMenuBar::SelectMenu"));
CaptureMouse();
DoSelectMenu(pos);
{
wxCHECK_RET( pos < GetCount(), _T("invalid menu index in DoSelectMenu") );
- if ( m_current != -1 )
+ int posOld = m_current;
+
+ m_current = pos;
+
+ if ( posOld != -1 )
{
// close the previous menu
if ( IsShowingMenu() )
m_shouldShowMenu = old;
}
- RefreshItem((size_t)m_current);
+ RefreshItem((size_t)posOld);
}
- m_current = pos;
-
RefreshItem(pos);
}
}
else // on item
{
+ wxLogTrace(_T("mousecapture"), _T("Capturing mouse from wxMenuBar::OnLeftDown"));
CaptureMouse();
// show it as selected
// show the menu if we know that we should, even if we hadn't been showing
// it before (this may happen if the previous menu was disabled)
- if ( m_shouldShowMenu )
+ 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 */);
void wxMenuBar::OnKeyDown(wxKeyEvent& event)
{
- // the current item must have been set before
- wxCHECK_RET( m_current != -1, _T("where is current item?") );
+ // ensure that we have a current item - we might not have it if we're
+ // given the focus with Alt or F10 press (and under GTK+ the menubar
+ // somehow gets the keyboard events even when it doesn't have focus...)
+ if ( m_current == -1 )
+ {
+ if ( !HasCapture() )
+ {
+ SelectMenu(0);
+ }
+ else // we do have capture
+ {
+ // we always maintain a valid current item while we're in modal
+ // state (i.e. have the capture)
+ wxFAIL_MSG( _T("how did we manage to lose current item?") );
+
+ return;
+ }
+ }
int key = event.GetKeyCode();
}
else // right
{
- if ( ++currentNew == (int)count )
+ if ( ++currentNew == count )
currentNew = 0;
}
wxCHECK_RET( m_current != -1, _T("no menu to popup") );
// forgot to call DismissMenu()?
- wxASSERT_MSG( !m_menuShown, _T("shouldn't show two menu at once!") );
+ 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;
// that we pass 0 as width to position the menu exactly below the
// item, not to the right of it
wxRect rectItem = GetItemRect(m_current);
+
m_menuShown->Popup(ClientToScreen(rectItem.GetPosition()),
wxSize(0, rectItem.GetHeight()),
selectFirst);
void wxMenuBar::OnDismiss()
{
- ReleaseCapture();
+ if ( GetCapture() )
+ {
+ wxLogTrace(_T("mousecapture"), _T("Releasing mouse from wxMenuBar::OnDismiss"));
+ GetCapture()->ReleaseMouse();
+ }
if ( m_current != -1 )
{
- RefreshItem((size_t)m_current);
-
+ size_t current = m_current;
m_current = -1;
+
+ RefreshItem(current);
}
GiveAwayFocus();
#endif // 0
menu->SetInvokingWindow(this);
+
+ // wxLogDebug( "Name of invoking window %s", menu->GetInvokingWindow()->GetName().c_str() );
+
menu->Popup(ClientToScreen(wxPoint(x, y)), wxSize(0, 0));
// this is not very useful if the menu was popped up because of the mouse
void wxWindow::DismissPopupMenu()
{
wxCHECK_RET( ms_evtLoopPopup, _T("no popup menu shown") );
-
+
ms_evtLoopPopup->Exit();
}