X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e39af974ef7846e26686ae39d74e4696c1fef0c3..3be8026d1dcc96b8fb4f9e991020f94ec70ec4f7:/src/univ/menu.cpp diff --git a/src/univ/menu.cpp b/src/univ/menu.cpp index a4e1176552..acad3b9451 100644 --- a/src/univ/menu.cpp +++ b/src/univ/menu.cpp @@ -17,7 +17,7 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "univmenuitem.h" #pragma implementation "univmenu.h" #endif @@ -75,7 +75,7 @@ public: m_width = 0; } - void SetEnabled(bool enabled = TRUE) { m_isEnabled = enabled; } + void SetEnabled(bool enabled = true) { m_isEnabled = enabled; } // accessors @@ -123,7 +123,7 @@ class wxPopupMenuWindow : public wxPopupTransientWindow { public: wxPopupMenuWindow(wxWindow *parent, wxMenu *menu); - + ~wxPopupMenuWindow(); // override the base class version to select the first item initially @@ -136,7 +136,7 @@ public: virtual void OnDismiss(); // called when a submenu is dismissed - void OnSubmenuDismiss() { m_hasOpenSubMenu = FALSE; } + void OnSubmenuDismiss(bool dismissParent); // get the currently selected item (may be NULL) wxMenuItem *GetCurrentItem() const @@ -145,7 +145,7 @@ public: } // 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); @@ -153,7 +153,7 @@ public: // preselect the first item void SelectFirst() { SetCurrent(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 @@ -183,13 +183,14 @@ protected: 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 + // on what it is, return true if something was done (i.e. it's not a // separator...) bool ActivateItem(wxMenuItem *item, InputMethod how = WithKeyboard); @@ -216,23 +217,23 @@ protected: 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; @@ -257,8 +258,8 @@ public: } else { - // return FALSE; - + // return false; + return wxEvtHandler::ProcessEvent(event); } } @@ -303,7 +304,7 @@ END_EVENT_TABLE() wxPopupMenuWindow::wxPopupMenuWindow(wxWindow *parent, wxMenu *menu) { m_menu = menu; - m_hasOpenSubMenu = FALSE; + m_hasOpenSubMenu = false; ResetCurrent(); @@ -328,19 +329,23 @@ wxPopupMenuWindow::~wxPopupMenuWindow() 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; @@ -353,7 +358,7 @@ void wxPopupMenuWindow::ChangeCurrent(wxMenuItemList::Node *node) if ( item->IsSubMenu() && item->GetSubMenu()->IsShown() ) { item->GetSubMenu()->Dismiss(); - OnSubmenuDismiss(); + OnSubmenuDismiss( false ); } RefreshItem(item); @@ -364,15 +369,15 @@ void wxPopupMenuWindow::ChangeCurrent(wxMenuItemList::Node *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 ) { @@ -387,15 +392,15 @@ wxPopupMenuWindow::GetPrevNode(wxMenuItemList::Node *node) const 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 ) { @@ -458,7 +463,7 @@ void wxPopupMenuWindow::Dismiss() wxCHECK_RET( win, _T("opened submenu is not opened?") ); win->Dismiss(); - OnSubmenuDismiss(); + OnSubmenuDismiss( false ); } wxPopupTransientWindow::Dismiss(); @@ -468,7 +473,16 @@ 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::OnSubmenuDismiss(bool dismissParent) +{ + m_hasOpenSubMenu = false; + + // we are closing whole menu so remove current highlight + if ( dismissParent ) + ResetCurrent(); } void wxPopupMenuWindow::HandleDismiss(bool dismissParent) @@ -481,14 +495,14 @@ void wxPopupMenuWindow::HandleDismiss(bool dismissParent) void wxPopupMenuWindow::DismissAndNotify() { Dismiss(); - HandleDismiss(TRUE); + HandleDismiss(true); } // ---------------------------------------------------------------------------- // 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 @@ -496,7 +510,7 @@ wxPopupMenuWindow::GetMenuItemFromPoint(const wxPoint& pt) const 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() ) { @@ -510,7 +524,11 @@ wxPopupMenuWindow::GetMenuItemFromPoint(const wxPoint& pt) const } } +#if wxUSE_STL + return wxMenuItemList::compatibility_iterator(); +#else return NULL; +#endif } // ---------------------------------------------------------------------------- @@ -544,7 +562,7 @@ void wxPopupMenuWindow::DoDraw(wxControlRenderer *renderer) 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() ) { @@ -576,6 +594,21 @@ void wxPopupMenuWindow::DoDraw(wxControlRenderer *renderer) 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, @@ -583,10 +616,7 @@ void wxPopupMenuWindow::DoDraw(wxControlRenderer *renderer) 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() ); @@ -611,7 +641,7 @@ void wxPopupMenuWindow::ClickItem(wxMenuItem *item) // close all menus DismissAndNotify(); - + menu->ClickItem(item); } @@ -627,7 +657,7 @@ void wxPopupMenuWindow::OpenSubmenu(wxMenuItem *item, InputMethod how) 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) @@ -635,7 +665,7 @@ 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 @@ -650,10 +680,10 @@ bool wxPopupMenuWindow::ActivateItem(wxMenuItem *item, InputMethod how) } else // separator, can't activate { - return FALSE; + return false; } - return TRUE; + return true; } // ---------------------------------------------------------------------------- @@ -675,24 +705,24 @@ bool wxPopupMenuWindow::ProcessLeftDown(wxMouseEvent& event) { 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::Node *node = GetMenuItemFromPoint(event.GetPosition()); + wxMenuItemList::compatibility_iterator node = GetMenuItemFromPoint(event.GetPosition()); if ( node ) { ActivateItem(node->GetData(), WithMouse); @@ -726,7 +756,7 @@ void wxPopupMenuWindow::OnMouseMove(wxMouseEvent& event) 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) @@ -812,12 +842,16 @@ void wxPopupMenuWindow::OnMouseLeave(wxMouseEvent& event) else { // this menu is the last opened - resetCurrent = TRUE; + resetCurrent = true; } if ( resetCurrent ) { +#if wxUSE_STL + ChangeCurrent(wxMenuItemList::compatibility_iterator()); +#else ChangeCurrent(NULL); +#endif } } @@ -841,14 +875,14 @@ bool wxPopupMenuWindow::ProcessKeyDown(int key) // 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 @@ -860,7 +894,7 @@ bool wxPopupMenuWindow::ProcessKeyDown(int key) // menubar if ( !m_menu->GetParent() ) { - processed = FALSE; + processed = false; break; } @@ -869,7 +903,7 @@ bool wxPopupMenuWindow::ProcessKeyDown(int key) case WXK_ESCAPE: // close just this menu Dismiss(); - HandleDismiss(FALSE); + HandleDismiss(false); break; case WXK_RETURN: @@ -889,9 +923,9 @@ bool wxPopupMenuWindow::ProcessKeyDown(int key) { 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); @@ -900,7 +934,11 @@ bool wxPopupMenuWindow::ProcessKeyDown(int key) { // nothing but separators and disabled items in this // menu, break out +#if wxUSE_STL + node = wxMenuItemList::compatibility_iterator(); +#else node = NULL; +#endif } } @@ -910,7 +948,7 @@ bool wxPopupMenuWindow::ProcessKeyDown(int key) } else { - processed = FALSE; + processed = false; } } break; @@ -923,29 +961,33 @@ bool wxPopupMenuWindow::ProcessKeyDown(int key) } 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::Node *nodeStart = GetNextNode(); + wxMenuItemList::compatibility_iterator 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::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(); @@ -965,7 +1007,7 @@ bool wxPopupMenuWindow::ProcessKeyDown(int key) } 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 @@ -998,12 +1040,12 @@ bool wxPopupMenuWindow::ProcessKeyDown(int key) //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; @@ -1089,10 +1131,8 @@ void wxMenu::EndRadioGroup() m_startRadioGroup = -1; } -bool wxMenu::DoAppend(wxMenuItem *item) +wxMenuItem* wxMenu::DoAppend(wxMenuItem *item) { - bool check = FALSE; - if ( item->GetKind() == wxITEM_RADIO ) { int count = GetMenuItemCount(); @@ -1105,15 +1145,12 @@ bool wxMenu::DoAppend(wxMenuItem *item) // for now it has just one element item->SetAsRadioGroupStart(); item->SetRadioGroupEnd(m_startRadioGroup); - - // ensure that we have a checked item in the radio group - check = TRUE; } else // extend the current radio group { // we need to update its end item item->SetRadioGroupStart(m_startRadioGroup); - wxMenuItemList::Node *node = GetMenuItems().Item(m_startRadioGroup); + wxMenuItemList::compatibility_iterator node = GetMenuItems().Item(m_startRadioGroup); if ( node ) { @@ -1131,21 +1168,21 @@ bool wxMenu::DoAppend(wxMenuItem *item) } 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) @@ -1196,10 +1233,10 @@ void wxMenu::Detach() 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 @@ -1218,7 +1255,7 @@ wxWindow *wxMenu::GetRootWindow() const // We are a submenu of a menu of a menubar if (menu->GetMenuBar()) return menu->GetMenuBar(); - + win = menu->GetInvokingWindow(); if ( win ) break; @@ -1229,7 +1266,7 @@ wxWindow *wxMenu::GetRootWindow() const // 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; @@ -1279,7 +1316,7 @@ void wxMenu::OnDismiss(bool dismissParent) wxPopupMenuWindow *win = m_menuParent->m_popupMenu; if ( win ) { - win->OnSubmenuDismiss(); + win->OnSubmenuDismiss( true ); } else { @@ -1291,7 +1328,7 @@ void wxMenu::OnDismiss(bool dismissParent) { // dismissParent is recursive m_menuParent->Dismiss(); - m_menuParent->OnDismiss(TRUE); + m_menuParent->OnDismiss(true); } } else // no parent menu @@ -1306,7 +1343,7 @@ void wxMenu::OnDismiss(bool dismissParent) 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); } @@ -1326,7 +1363,7 @@ void wxMenu::Popup(const wxPoint& pos, const wxSize& size, bool selectFirst) { m_popupMenu->SelectFirst(); } - + // the geometry might have changed since the last time we were shown, so // always resize m_popupMenu->SetClientSize(GetGeometryInfo().GetSize()); @@ -1357,7 +1394,7 @@ void wxMenu::Dismiss() 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); @@ -1378,7 +1415,7 @@ bool wxMenu::ClickItem(wxMenuItem *item) // not applicabled isChecked = -1; } - + return SendEvent(item->GetId(), isChecked); } @@ -1398,7 +1435,7 @@ bool wxMenu::ProcessAccelEvent(const wxKeyEvent& event) } // try our submenus - for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst(); + for ( wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst(); node; node = node->GetNext() ) { @@ -1408,12 +1445,12 @@ bool wxMenu::ProcessAccelEvent(const wxKeyEvent& event) // try its elements if ( item->GetSubMenu()->ProcessAccelEvent(event) ) { - return TRUE; + return true; } } } - return FALSE; + return false; } void wxMenu::AddAccelFor(wxMenuItem *item) @@ -1455,10 +1492,12 @@ wxMenuItem::wxMenuItem(wxMenu *parentMenu, : 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(); } @@ -1584,12 +1623,12 @@ void wxMenuItem::Check(bool check) } // also uncheck all the other items in this radio group - wxMenuItemList::Node *node = items.Item(start); + wxMenuItemList::compatibility_iterator 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(); } @@ -1605,7 +1644,7 @@ void wxMenuItem::Check(bool check) void wxMenuItem::SetAsRadioGroupStart() { - m_isRadioGroupStart = TRUE; + m_isRadioGroupStart = true; } void wxMenuItem::SetRadioGroupStart(int start) @@ -1636,9 +1675,7 @@ void wxMenuBar::Init() m_menuShown = NULL; - m_shouldShowMenu = FALSE; - - m_windowStyle |= wxNO_FULL_REPAINT_ON_RESIZE; + m_shouldShowMenu = false; } void wxMenuBar::Attach(wxFrame *frame) @@ -1662,14 +1699,14 @@ 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 @@ -1704,14 +1741,14 @@ bool wxMenuBar::Append(wxMenu *menu, const wxString& title) 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) @@ -1775,7 +1812,7 @@ void wxMenuBar::EnableTop(size_t pos, bool enable) 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(); } @@ -1795,7 +1832,7 @@ void wxMenuBar::SetLabelTop(size_t pos, const wxString& label) 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(); } @@ -1986,7 +2023,7 @@ void wxMenuBar::DoSelectMenu(size_t pos) if ( IsShowingMenu() ) { // restore m_shouldShowMenu flag after DismissMenu() which resets - // it to FALSE + // it to false bool old = m_shouldShowMenu; DismissMenu(); @@ -2055,14 +2092,14 @@ void wxMenuBar::OnLeftDown(wxMouseEvent& event) } 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 */); } } } @@ -2089,7 +2126,7 @@ bool wxMenuBar::ProcessMouseEvent(const wxPoint& pt) static wxPoint s_ptLast; if ( pt == s_ptLast ) { - return FALSE; + return false; } s_ptLast = pt; @@ -2098,7 +2135,7 @@ bool wxMenuBar::ProcessMouseEvent(const wxPoint& pt) int currentNew = GetMenuFromPoint(pt); if ( (currentNew == -1) || (currentNew == m_current) ) { - return FALSE; + return false; } // select the new active item @@ -2109,10 +2146,10 @@ bool wxMenuBar::ProcessMouseEvent(const wxPoint& pt) 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) @@ -2148,7 +2185,7 @@ 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 @@ -2256,7 +2293,7 @@ void wxMenuBar::OnKeyDown(wxKeyEvent& event) 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; @@ -2264,10 +2301,10 @@ int wxMenuBar::FindNextItemForAccel(int idxStart, int key, bool *unique) const // 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; @@ -2304,7 +2341,7 @@ int wxMenuBar::FindNextItemForAccel(int idxStart, int key, bool *unique) const 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 @@ -2335,7 +2372,7 @@ int wxMenuBar::FindNextItemForAccel(int idxStart, int key, bool *unique) const 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++ ) { @@ -2345,13 +2382,13 @@ bool wxMenuBar::ProcessAccelEvent(const wxKeyEvent& event) if ( node->GetData()->ProcessAccelEvent(event) ) { // menu processed it - return TRUE; + return true; } } } // not found - return FALSE; + return false; } #endif // wxUSE_ACCEL @@ -2368,7 +2405,7 @@ void wxMenuBar::PopupCurrentMenu(bool selectFirst) 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) ) { @@ -2383,6 +2420,8 @@ void wxMenuBar::PopupCurrentMenu(bool selectFirst) // 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); @@ -2406,7 +2445,7 @@ void wxMenuBar::DismissMenu() void wxMenuBar::OnDismissMenu(bool dismissMenuBar) { - m_shouldShowMenu = FALSE; + m_shouldShowMenu = false; m_menuShown = NULL; if ( dismissMenuBar ) { @@ -2446,7 +2485,7 @@ wxEventLoop *wxWindow::ms_evtLoopPopup = NULL; 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__ @@ -2473,10 +2512,10 @@ bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y) #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)); + + 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 @@ -2496,7 +2535,7 @@ bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y) ms_evtLoopPopup = NULL; // remove the handler - PopEventHandler(TRUE /* delete it */); + PopEventHandler(true /* delete it */); menu->SetInvokingWindow(NULL); @@ -2504,13 +2543,13 @@ bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y) SetCursor(cursorOld); #endif // __WXMSW__ - return TRUE; + return true; } void wxWindow::DismissPopupMenu() { wxCHECK_RET( ms_evtLoopPopup, _T("no popup menu shown") ); - + ms_evtLoopPopup->Exit(); }