Ownerdrawn menu updates
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9550 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -125,6 +125,15 @@ public:
|
|||||||
//
|
//
|
||||||
int FindAccel(int nId) const;
|
int FindAccel(int nId) const;
|
||||||
#endif // wxUSE_ACCEL
|
#endif // wxUSE_ACCEL
|
||||||
|
//
|
||||||
|
// OS/2 specific Find
|
||||||
|
//
|
||||||
|
wxMenuItem* FindItem(int id, ULONG hItem, wxMenu **menu = NULL) const;
|
||||||
|
//virtual function hiding suppression
|
||||||
|
int FindItem(const wxString& rsString) const
|
||||||
|
{ return wxMenuBase::FindItem(rsString); }
|
||||||
|
wxMenuItem* FindItem(int id, wxMenu **menu = NULL) const
|
||||||
|
{ return wxMenuBase::FindItem(id, menu); }
|
||||||
|
|
||||||
//
|
//
|
||||||
// All OS/2PM Menu's have one of these
|
// All OS/2PM Menu's have one of these
|
||||||
@@ -219,7 +228,10 @@ public:
|
|||||||
virtual wxMenuItem* FindItem( int nId
|
virtual wxMenuItem* FindItem( int nId
|
||||||
,wxMenu** ppMenu = NULL
|
,wxMenu** ppMenu = NULL
|
||||||
) const;
|
) const;
|
||||||
|
virtual wxMenuItem* FindItem( int nId
|
||||||
|
,ULONG hItem
|
||||||
|
,wxMenu** ppMenu = NULL
|
||||||
|
) const;
|
||||||
virtual void EnableTop( size_t nPos
|
virtual void EnableTop( size_t nPos
|
||||||
,bool bFlag
|
,bool bFlag
|
||||||
);
|
);
|
||||||
|
@@ -265,6 +265,7 @@ bool wxMenu::DoInsertOrAppend(
|
|||||||
{
|
{
|
||||||
ERRORID vError;
|
ERRORID vError;
|
||||||
wxString sError;
|
wxString sError;
|
||||||
|
char zMsg[128];
|
||||||
#if wxUSE_ACCEL
|
#if wxUSE_ACCEL
|
||||||
UpdateAccel(pItem);
|
UpdateAccel(pItem);
|
||||||
#endif // wxUSE_ACCEL
|
#endif // wxUSE_ACCEL
|
||||||
@@ -325,12 +326,14 @@ bool wxMenu::DoInsertOrAppend(
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Want to get {Measure|Draw}Item messages?
|
// Want to get {Measure|Draw}Item messages?
|
||||||
// item draws itself, pass pointer to it in data parameter
|
// item draws itself, passing pointer to data doesn't work in OS/2
|
||||||
// Will eventually need to set the image handle somewhere into vItem.hItem
|
// Will eventually need to set the image handle somewhere into vItem.hItem
|
||||||
//
|
//
|
||||||
rItem.afStyle |= MIS_OWNERDRAW;
|
rItem.afStyle |= MIS_OWNERDRAW;
|
||||||
pData = (BYTE*)pItem;
|
pData = (BYTE*)pItem;
|
||||||
// vItem.hItem = ????
|
rItem.hItem = (HBITMAP)pItem->GetBitmap().GetHBITMAP();
|
||||||
|
pItem->m_vMenuData.afStyle = rItem.afStyle;
|
||||||
|
pItem->m_vMenuData.hItem = rItem.hItem;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
@@ -358,6 +361,21 @@ bool wxMenu::DoInsertOrAppend(
|
|||||||
,(MPARAM)&rItem
|
,(MPARAM)&rItem
|
||||||
,(MPARAM)pData
|
,(MPARAM)pData
|
||||||
);
|
);
|
||||||
|
#if wxUSE_OWNER_DRAWN
|
||||||
|
if (pItem->IsOwnerDrawn())
|
||||||
|
{
|
||||||
|
BOOL rc;
|
||||||
|
MENUITEM vMenuItem;
|
||||||
|
|
||||||
|
::WinSendMsg( GetHmenu()
|
||||||
|
,MM_QUERYITEM
|
||||||
|
,MPFROM2SHORT( (USHORT)pItem->GetId()
|
||||||
|
,(USHORT)(FALSE)
|
||||||
|
)
|
||||||
|
,&vMenuItem
|
||||||
|
);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (rc == MIT_MEMERROR || rc == MIT_ERROR)
|
if (rc == MIT_MEMERROR || rc == MIT_ERROR)
|
||||||
{
|
{
|
||||||
vError = ::WinGetLastError(vHabmain);
|
vError = ::WinGetLastError(vHabmain);
|
||||||
@@ -618,6 +636,42 @@ wxWindow* wxMenu::GetWindow() const
|
|||||||
return NULL;
|
return NULL;
|
||||||
} // end of wxMenu::GetWindow
|
} // end of wxMenu::GetWindow
|
||||||
|
|
||||||
|
// recursive search for item by id
|
||||||
|
wxMenuItem* wxMenu::FindItem(
|
||||||
|
int nItemId
|
||||||
|
, ULONG hItem
|
||||||
|
, wxMenu** ppItemMenu
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
if ( ppItemMenu )
|
||||||
|
*ppItemMenu = NULL;
|
||||||
|
|
||||||
|
wxMenuItem* pItem = NULL;
|
||||||
|
|
||||||
|
for ( wxMenuItemList::Node *node = m_items.GetFirst();
|
||||||
|
node && !pItem;
|
||||||
|
node = node->GetNext() )
|
||||||
|
{
|
||||||
|
pItem = node->GetData();
|
||||||
|
|
||||||
|
if ( pItem->GetId() == nItemId && pItem->m_vMenuData.hItem == hItem)
|
||||||
|
{
|
||||||
|
if ( ppItemMenu )
|
||||||
|
*ppItemMenu = (wxMenu *)this;
|
||||||
|
}
|
||||||
|
else if ( pItem->IsSubMenu() )
|
||||||
|
{
|
||||||
|
pItem = pItem->GetSubMenu()->FindItem(nItemId, hItem, ppItemMenu);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// don't exit the loop
|
||||||
|
pItem = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pItem;
|
||||||
|
} // end of wxMenu::FindItem
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Menu Bar
|
// Menu Bar
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -1090,4 +1144,25 @@ wxMenuItem* wxMenuBar::FindItem(
|
|||||||
return pItem;
|
return pItem;
|
||||||
} // end of wxMenuBar::FindItem
|
} // end of wxMenuBar::FindItem
|
||||||
|
|
||||||
|
wxMenuItem* wxMenuBar::FindItem(
|
||||||
|
int nId
|
||||||
|
, ULONG hItem
|
||||||
|
, wxMenu** ppItemMenu
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
if (ppItemMenu)
|
||||||
|
*ppItemMenu = NULL;
|
||||||
|
|
||||||
|
wxMenuItem* pItem = NULL;
|
||||||
|
size_t nCount = GetMenuCount();
|
||||||
|
|
||||||
|
for (size_t i = 0; !pItem && (i < nCount); i++)
|
||||||
|
{
|
||||||
|
pItem = m_menus[i]->FindItem( nId
|
||||||
|
,hItem
|
||||||
|
,ppItemMenu
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return pItem;
|
||||||
|
} // end of wxMenuBar::FindItem
|
||||||
|
|
||||||
|
@@ -1983,15 +1983,24 @@ MRESULT wxWindow::OS2WindowProc(
|
|||||||
case WM_DRAWITEM:
|
case WM_DRAWITEM:
|
||||||
case WM_MEASUREITEM:
|
case WM_MEASUREITEM:
|
||||||
{
|
{
|
||||||
int idCtrl = (UINT)wParam;
|
int nIdCtrl = (UINT)wParam;
|
||||||
|
char zMsg[128];
|
||||||
|
|
||||||
if ( uMsg == WM_DRAWITEM )
|
if ( uMsg == WM_DRAWITEM )
|
||||||
{
|
{
|
||||||
bProcessed = OS2OnDrawItem(idCtrl,
|
// DEBUG
|
||||||
|
sprintf(zMsg, "In OS2OnDrawItem, id: %d", nIdCtrl);
|
||||||
|
(void)wxMessageBox( "wxWindows Menu sample"
|
||||||
|
,zMsg
|
||||||
|
,wxICON_INFORMATION
|
||||||
|
);
|
||||||
|
// end DEBUG
|
||||||
|
bProcessed = OS2OnDrawItem(nIdCtrl,
|
||||||
(WXDRAWITEMSTRUCT *)lParam);
|
(WXDRAWITEMSTRUCT *)lParam);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bProcessed = OS2OnMeasureItem(idCtrl,
|
bProcessed = OS2OnMeasureItem(nIdCtrl,
|
||||||
(WXMEASUREITEMSTRUCT *)lParam);
|
(WXMEASUREITEMSTRUCT *)lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2656,22 +2665,22 @@ bool wxWindow::OS2OnDrawItem(
|
|||||||
{
|
{
|
||||||
wxDC vDc;
|
wxDC vDc;
|
||||||
|
|
||||||
|
#if wxUSE_OWNER_DRAWN
|
||||||
//
|
//
|
||||||
// Is it a menu item?
|
// Is it a menu item?
|
||||||
//
|
//
|
||||||
if (vId == 0)
|
if (vId == 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
#if wxUSE_OWNER_DRAWN
|
|
||||||
POWNERITEM pMeasureStruct = (POWNERITEM)pItemStruct;
|
POWNERITEM pMeasureStruct = (POWNERITEM)pItemStruct;
|
||||||
wxMenuItem vMenuItem;
|
BYTE* pData;
|
||||||
|
wxMenuItem* pMenuItem;
|
||||||
HDC hDC = ::GpiQueryDevice(pMeasureStruct->hps);
|
HDC hDC = ::GpiQueryDevice(pMeasureStruct->hps);
|
||||||
|
|
||||||
vDc.SetHDC( hDC
|
vDc.SetHDC( hDC
|
||||||
,FALSE
|
,FALSE
|
||||||
);
|
);
|
||||||
vDc.SetHPS(pMeasureStruct->hps);
|
vDc.SetHPS(pMeasureStruct->hps);
|
||||||
|
#if 0
|
||||||
//
|
//
|
||||||
// We stored the CMenuItem itself into the menuitem text field so now
|
// We stored the CMenuItem itself into the menuitem text field so now
|
||||||
// we need to extract it.
|
// we need to extract it.
|
||||||
@@ -2681,9 +2690,8 @@ bool wxWindow::OS2OnDrawItem(
|
|||||||
,MPFROM2SHORT( (USHORT)pMeasureStruct->idItem
|
,MPFROM2SHORT( (USHORT)pMeasureStruct->idItem
|
||||||
,(SHORT)(sizeof(wxMenuItem))
|
,(SHORT)(sizeof(wxMenuItem))
|
||||||
)
|
)
|
||||||
,(PSZ)&vMenuItem
|
,(PSZ)pData
|
||||||
);
|
);
|
||||||
|
|
||||||
wxRect vRect( pMeasureStruct->rclItem.xLeft
|
wxRect vRect( pMeasureStruct->rclItem.xLeft
|
||||||
,pMeasureStruct->rclItem.yTop
|
,pMeasureStruct->rclItem.yTop
|
||||||
,pMeasureStruct->rclItem.xRight
|
,pMeasureStruct->rclItem.xRight
|
||||||
@@ -2699,12 +2707,13 @@ bool wxWindow::OS2OnDrawItem(
|
|||||||
eAction = wxOwnerDrawn::wxODDrawAll;
|
eAction = wxOwnerDrawn::wxODDrawAll;
|
||||||
else
|
else
|
||||||
eAction = wxOwnerDrawn::wxODSelectChanged;
|
eAction = wxOwnerDrawn::wxODSelectChanged;
|
||||||
|
pMenuItem = (wxMenuItem*)pData;
|
||||||
return(vMenuItem.OnDrawItem( vDc
|
return(pMenuItem->OnDrawItem( vDc
|
||||||
,vRect
|
,vRect
|
||||||
,eAction
|
,eAction
|
||||||
,(wxOwnerDrawn::wxODStatus)pMeasureStruct->fsAttribute
|
,(wxOwnerDrawn::wxODStatus)pMeasureStruct->fsAttribute
|
||||||
));
|
));
|
||||||
|
#endif
|
||||||
//
|
//
|
||||||
// leave the fsAttribute and fsOldAttribute unchanged. If different,
|
// leave the fsAttribute and fsOldAttribute unchanged. If different,
|
||||||
// the system will do the highlight or fraeming or disabling for us,
|
// the system will do the highlight or fraeming or disabling for us,
|
||||||
@@ -2730,30 +2739,21 @@ bool wxWindow::OS2OnMeasureItem(
|
|||||||
//
|
//
|
||||||
// Is it a menu item?
|
// Is it a menu item?
|
||||||
//
|
//
|
||||||
if (lId == 0)
|
if (lId == 65536) // I really don't like this...has to be a better indicator
|
||||||
{
|
{
|
||||||
POWNERITEM pMeasureStruct = (POWNERITEM)pItemStruct;
|
POWNERITEM pMeasureStruct = (POWNERITEM)pItemStruct;
|
||||||
wxMenuItem vMenuItem;
|
char zData[sizeof(wxMenuItem)];
|
||||||
|
|
||||||
//
|
char zMsg[128];
|
||||||
// We stored the CMenuItem itself into the menuitem text field so now
|
|
||||||
// we need to extract it.
|
|
||||||
//
|
|
||||||
::WinSendMsg( pMeasureStruct->hItem
|
|
||||||
,MM_QUERYITEMTEXT
|
|
||||||
,MPFROM2SHORT( (USHORT)pMeasureStruct->idItem
|
|
||||||
,(SHORT)(sizeof(wxMenuItem))
|
|
||||||
)
|
|
||||||
,(PSZ)&vMenuItem
|
|
||||||
);
|
|
||||||
wxCHECK(vMenuItem.IsKindOf(CLASSINFO(wxMenuItem)), FALSE);
|
|
||||||
|
|
||||||
size_t lWidth = (size_t)(pMeasureStruct->rclItem.xRight - pMeasureStruct->rclItem.xLeft);
|
if (IsKindOf(CLASSINFO(wxFrame)))
|
||||||
size_t lHeight = (size_t)(pMeasureStruct->rclItem.yTop - pMeasureStruct->rclItem.yBottom);
|
{
|
||||||
|
wxFrame* pFrame = (wxFrame*)this;
|
||||||
|
wxMenuItem* pMenuItem = pFrame->GetMenuBar()->FindItem(pMeasureStruct->idItem, pMeasureStruct->hItem);
|
||||||
|
|
||||||
return(vMenuItem.OnMeasureItem( &lWidth
|
wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
|
||||||
,&lHeight
|
return(pMenuItem->OnMeasureItem(&pMeasureStruct->rclItem));
|
||||||
));
|
}
|
||||||
}
|
}
|
||||||
wxWindow* pItem = FindItem(id);
|
wxWindow* pItem = FindItem(id);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user