// Created: 25.08.00
// RCS-ID: $Id$
// Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
-// Licence: wxWindows license
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// headers
// ----------------------------------------------------------------------------
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "univmenuitem.h"
#pragma implementation "univmenu.h"
#endif
{
public:
wxPopupMenuWindow(wxWindow *parent, wxMenu *menu);
-
+
~wxPopupMenuWindow();
// override the base class version to select the first item initially
}
// find the menu item at given position
- wxMenuItemList::Node *GetMenuItemFromPoint(const wxPoint& pt) const;
+ wxMenuItemList::compatibility_iterator GetMenuItemFromPoint(const wxPoint& pt) const;
// refresh the given item
void RefreshItem(wxMenuItem *item);
void ResetCurrent();
// set the current node and item withotu refreshing anything
- void SetCurrent(wxMenuItemList::Node *node);
+ void SetCurrent(wxMenuItemList::compatibility_iterator node);
+ virtual bool SetCurrent(bool doit = true){return wxPopupTransientWindow::SetCurrent(doit);};
// change the current item refreshing the old and new items
- void ChangeCurrent(wxMenuItemList::Node *node);
+ void ChangeCurrent(wxMenuItemList::compatibility_iterator 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
bool HasOpenSubmenu() const { return m_hasOpenSubMenu; }
// get previous node after the current one
- wxMenuItemList::Node *GetPrevNode() const;
+ wxMenuItemList::compatibility_iterator GetPrevNode() const;
// get previous node before the given one, wrapping if it's the first one
- wxMenuItemList::Node *GetPrevNode(wxMenuItemList::Node *node) const;
+ wxMenuItemList::compatibility_iterator GetPrevNode(wxMenuItemList::compatibility_iterator node) const;
// get next node after the current one
- wxMenuItemList::Node *GetNextNode() const;
+ wxMenuItemList::compatibility_iterator GetNextNode() const;
// get next node after the given one, wrapping if it's the last one
- wxMenuItemList::Node *GetNextNode(wxMenuItemList::Node *node) const;
+ wxMenuItemList::compatibility_iterator GetNextNode(wxMenuItemList::compatibility_iterator node) const;
private:
// the menu we show
wxMenu *m_menu;
// the menu node corresponding to the current item
- wxMenuItemList::Node *m_nodeCurrent;
+ wxMenuItemList::compatibility_iterator m_nodeCurrent;
// do we currently have an opened submenu?
bool m_hasOpenSubMenu;
else
{
// return FALSE;
-
+
return wxEvtHandler::ProcessEvent(event);
}
}
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;
}
// ----------------------------------------------------------------------------
void wxPopupMenuWindow::ResetCurrent()
{
- SetCurrent(NULL);
+#if wxUSE_STL
+ SetCurrent(wxMenuItemList::compatibility_iterator());
+#else
+ SetCurrent((wxwxMenuItemListNode *)NULL);
+#endif
}
-void wxPopupMenuWindow::SetCurrent(wxMenuItemList::Node *node)
+void wxPopupMenuWindow::SetCurrent(wxMenuItemList::compatibility_iterator node)
{
m_nodeCurrent = node;
}
-void wxPopupMenuWindow::ChangeCurrent(wxMenuItemList::Node *node)
+void wxPopupMenuWindow::ChangeCurrent(wxMenuItemList::compatibility_iterator node)
{
if ( node != m_nodeCurrent )
{
- wxMenuItemList::Node *nodeOldCurrent = m_nodeCurrent;
+ wxMenuItemList::compatibility_iterator nodeOldCurrent = m_nodeCurrent;
m_nodeCurrent = node;
}
}
-wxMenuItemList::Node *wxPopupMenuWindow::GetPrevNode() const
+wxMenuItemList::compatibility_iterator 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();
}
-wxMenuItemList::Node *
-wxPopupMenuWindow::GetPrevNode(wxMenuItemList::Node *node) const
+wxMenuItemList::compatibility_iterator
+wxPopupMenuWindow::GetPrevNode(wxMenuItemList::compatibility_iterator node) const
{
if ( node )
{
return node;
}
-wxMenuItemList::Node *wxPopupMenuWindow::GetNextNode() const
+wxMenuItemList::compatibility_iterator 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();
}
-wxMenuItemList::Node *
-wxPopupMenuWindow::GetNextNode(wxMenuItemList::Node *node) const
+wxMenuItemList::compatibility_iterator
+wxPopupMenuWindow::GetNextNode(wxMenuItemList::compatibility_iterator node) const
{
if ( node )
{
// wxPopupMenuWindow geometry
// ----------------------------------------------------------------------------
-wxMenuItemList::Node *
+wxMenuItemList::compatibility_iterator
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::Node *node = m_menu->GetMenuItems().GetFirst();
+ for ( wxMenuItemList::compatibility_iterator node = m_menu->GetMenuItems().GetFirst();
node;
node = node->GetNext() )
{
}
}
+#if wxUSE_STL
+ return wxMenuItemList::compatibility_iterator();
+#else
return NULL;
+#endif
}
// ----------------------------------------------------------------------------
wxCoord y = 0;
const wxMenuGeometryInfo& gi = m_menu->GetGeometryInfo();
- for ( wxMenuItemList::Node *node = m_menu->GetMenuItems().GetFirst();
+ for ( wxMenuItemList::compatibility_iterator 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()
);
// close all menus
DismissAndNotify();
-
+
menu->ClickItem(item);
}
wxPopupMenuWindow *win = menu->m_popupMenu;
wxCHECK_MSG( win, FALSE, _T("parent menu not shown?") );
-
+
pos = ClientToScreen(pos);
if ( win->GetMenuItemFromPoint(win->ScreenToClient(pos)) )
{
void wxPopupMenuWindow::OnLeftUp(wxMouseEvent& event)
{
- wxMenuItemList::Node *node = GetMenuItemFromPoint(event.GetPosition());
+ wxMenuItemList::compatibility_iterator node = GetMenuItemFromPoint(event.GetPosition());
if ( node )
{
ActivateItem(node->GetData(), WithMouse);
void wxPopupMenuWindow::ProcessMouseMove(const wxPoint& pt)
{
- wxMenuItemList::Node *node = GetMenuItemFromPoint(pt);
+ wxMenuItemList::compatibility_iterator node = GetMenuItemFromPoint(pt);
// don't reset current to NULL here, we only do it when the mouse leaves
// the window (see below)
if ( resetCurrent )
{
+#if wxUSE_STL
+ ChangeCurrent(wxMenuItemList::compatibility_iterator());
+#else
ChangeCurrent(NULL);
+#endif
}
}
{
bool up = key == WXK_UP;
- wxMenuItemList::Node *nodeStart = up ? GetPrevNode()
+ wxMenuItemList::compatibility_iterator nodeStart = up ? GetPrevNode()
: GetNextNode(),
- *node = nodeStart;
+ 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
}
}
// 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::Node *nodeStart = GetNextNode();
+ wxMenuItemList::compatibility_iterator nodeStart = GetNextNode();
// do we have more than one item with this accel?
bool notUnique = FALSE;
// loop through all items searching for the item with this
// accel
- wxMenuItemList::Node *node = nodeStart,
- *nodeFound = NULL;
+ wxMenuItemList::compatibility_iterator node = nodeStart,
+#if wxUSE_STL
+ nodeFound = wxMenuItemList::compatibility_iterator();
+#else
+ nodeFound = NULL;
+#endif
for ( ;; )
{
item = node->GetData();
m_geometry = NULL;
m_popupMenu = NULL;
+
+ m_startRadioGroup = -1;
}
wxMenu::~wxMenu()
}
}
-bool wxMenu::DoAppend(wxMenuItem *item)
+void wxMenu::EndRadioGroup()
+{
+ // we're not inside a radio group any longer
+ m_startRadioGroup = -1;
+}
+
+wxMenuItem* wxMenu::DoAppend(wxMenuItem *item)
{
+ #if 0
+ // not used at all
+ bool check = FALSE;
+ #endif
+
+ if ( item->GetKind() == wxITEM_RADIO )
+ {
+ int count = GetMenuItemCount();
+
+ if ( m_startRadioGroup == -1 )
+ {
+ // start a new radio group
+ m_startRadioGroup = count;
+
+ // 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);
+
+ if ( node )
+ {
+ node->GetData()->SetRadioGroupEnd(count);
+ }
+ else
+ {
+ wxFAIL_MSG( _T("where is the radio group start item?") );
+ }
+ }
+ }
+ else // not a radio item
+ {
+ EndRadioGroup();
+ }
+
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
// 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();
-
+
// 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);
}
}
// try our submenus
- for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst();
+ for ( wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
node;
node = node->GetNext() )
{
m_posY =
m_height = -1;
+ m_radioGroup.start = -1;
+ m_isRadioGroupStart = FALSE;
+
+ m_bmpDisabled = wxNullBitmap;
+
UpdateAccelInfo();
}
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::Check(bool check)
{
- if ( check != m_isChecked )
+ wxCHECK_RET( IsCheckable(), wxT("only checkable items may be checked") );
+
+ if ( m_isChecked == check )
+ return;
+
+ if ( GetKind() == wxITEM_RADIO )
{
- wxMenuItemBase::Check(check);
+ // it doesn't make sense to uncheck a radio item - what would this do?
+ if ( !check )
+ return;
- NotifyMenu();
+ // get the index of this item in the menu
+ const wxMenuItemList& items = m_parentMenu->GetMenuItems();
+ int pos = items.IndexOf(this);
+ wxCHECK_RET( pos != wxNOT_FOUND,
+ _T("menuitem not found in the menu items list?") );
+
+ // get the radio group range
+ int start,
+ end;
+
+ if ( m_isRadioGroupStart )
+ {
+ // we already have all information we need
+ start = pos;
+ end = m_radioGroup.end;
+ }
+ else // next radio group item
+ {
+ // get the radio group end from the start item
+ start = m_radioGroup.start;
+ end = items.Item(start)->GetData()->m_radioGroup.end;
+ }
+
+ // also uncheck all the other items in this radio group
+ wxMenuItemList::compatibility_iterator node = items.Item(start);
+ for ( int n = start; n <= end && node; n++ )
+ {
+ if ( n != pos )
+ {
+ node->GetData()->m_isChecked = FALSE;
+ }
+ node = node->GetNext();
+ }
}
+
+ wxMenuItemBase::Check(check);
+
+ NotifyMenu();
+}
+
+// radio group stuff
+// -----------------
+
+void wxMenuItem::SetAsRadioGroupStart()
+{
+ m_isRadioGroupStart = TRUE;
+}
+
+void wxMenuItem::SetRadioGroupStart(int start)
+{
+ wxASSERT_MSG( !m_isRadioGroupStart,
+ _T("should only be called for the next radio items") );
+
+ m_radioGroup.start = start;
+}
+
+void wxMenuItem::SetRadioGroupEnd(int end)
+{
+ wxASSERT_MSG( m_isRadioGroupStart,
+ _T("should only be called for the first radio item") );
+
+ m_radioGroup.end = end;
}
// ----------------------------------------------------------------------------
m_menuShown = NULL;
m_shouldShowMenu = FALSE;
-
- // m_windowStyle |= wxNO_FULL_REPAINT_ON_RESIZE;
}
void wxMenuBar::Attach(wxFrame *frame)
bool wxMenuBar::ProcessAccelEvent(const wxKeyEvent& event)
{
size_t n = 0;
- for ( wxMenuList::Node *node = m_menus.GetFirst();
+ for ( wxMenuList::compatibility_iterator node = m_menus.GetFirst();
node;
node = node->GetNext(), n++ )
{
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;
wxLog::FlushActive();
// some controls update themselves from OnIdle() call - let them do it
- wxIdleEvent event;
- wxTheApp->ProcessEvent(event);
+ wxTheApp->ProcessIdle();
// if the window hadn't been refreshed yet, the menu can adversely affect
// its next OnPaint() handler execution - i.e. scrolled window refresh
#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();
}