OwnerDrawn updates
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9567 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1208,17 +1208,6 @@ void wxDC::DoGetTextExtent(
|
||||
if(vPtMax.x < avPoint[i].x) vPtMax.x = avPoint[i].x;
|
||||
if(vPtMax.y < avPoint[i].y) vPtMax.y = avPoint[i].y;
|
||||
}
|
||||
#if 0
|
||||
sprintf(zMsg, "Extents for %s, are: Minx: %ld, Miny: %ld, Maxx: %ld, Maxy: %ld", vPtMin.x
|
||||
, vPtMin.y
|
||||
, vPtMax.x
|
||||
, vPtMax.y
|
||||
);
|
||||
(void)wxMessageBox( "wxWindows Menu sample"
|
||||
,zMsg
|
||||
,wxICON_INFORMATION
|
||||
);
|
||||
#endif
|
||||
::GpiQueryFontMetrics( m_hPS
|
||||
,sizeof(FONTMETRICS)
|
||||
,&vFM
|
||||
|
@@ -22,68 +22,163 @@
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC, wxDC)
|
||||
|
||||
/*
|
||||
* Memory DC
|
||||
*
|
||||
*/
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Memory DC
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
wxMemoryDC::wxMemoryDC(void)
|
||||
{
|
||||
// TODO:
|
||||
/*
|
||||
m_hDC = (WXHDC) ::CreateCompatibleDC((HDC) NULL);
|
||||
m_ok = (m_hDC != 0);
|
||||
HDC hDC;
|
||||
HPS hPS;
|
||||
DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
|
||||
SIZEL vSize = {0, 0};
|
||||
|
||||
//
|
||||
// Create a memory device context
|
||||
//
|
||||
hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
|
||||
if (hDC != DEV_ERROR)
|
||||
{
|
||||
hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
|
||||
if (hPS != GPI_ERROR)
|
||||
{
|
||||
m_hPS = hPS;
|
||||
m_hDC = hDC;
|
||||
m_ok = TRUE;
|
||||
m_bOwnsDC = TRUE;
|
||||
|
||||
SetBrush(*wxWHITE_BRUSH);
|
||||
SetPen(*wxBLACK_PEN);
|
||||
|
||||
// the background mode is only used for text background
|
||||
// and is set in DrawText() to OPAQUE as required, other-
|
||||
// wise always TRANSPARENT, RR
|
||||
::SetBkMode( GetHdc(), TRANSPARENT );
|
||||
*/
|
||||
}
|
||||
|
||||
wxMemoryDC::wxMemoryDC(wxDC *old_dc)
|
||||
else
|
||||
{
|
||||
// TODO:
|
||||
/*
|
||||
old_dc->BeginDrawing();
|
||||
m_hPS = NULLHANDLE;
|
||||
m_hDC = NULLHANDLE;
|
||||
m_ok = FALSE;
|
||||
m_bOwnsDC = FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_hPS = NULLHANDLE;
|
||||
m_hDC = NULLHANDLE;
|
||||
m_ok = FALSE;
|
||||
m_bOwnsDC = FALSE;
|
||||
}
|
||||
} // end of wxMemoryDC::wxMemoryDC
|
||||
|
||||
m_hDC = (WXHDC) ::CreateCompatibleDC((HDC) old_dc->GetHDC());
|
||||
m_ok = (m_hDC != 0);
|
||||
wxMemoryDC::wxMemoryDC(
|
||||
wxDC* pOldDC
|
||||
)
|
||||
{
|
||||
HDC hDC;
|
||||
HPS hPS;
|
||||
DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
|
||||
SIZEL vSize = {0, 0};
|
||||
|
||||
old_dc->EndDrawing();
|
||||
pOldDC->BeginDrawing();
|
||||
|
||||
//
|
||||
// Create a memory device context
|
||||
//
|
||||
hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, GetHdcOf(*pOldDC));
|
||||
if (hDC != DEV_ERROR)
|
||||
{
|
||||
hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
|
||||
if (hPS != GPI_ERROR)
|
||||
{
|
||||
m_hPS = hPS;
|
||||
m_hDC = hDC;
|
||||
m_ok = TRUE;
|
||||
m_bOwnsDC = TRUE;
|
||||
pOldDC->EndDrawing();
|
||||
SetBrush(*wxWHITE_BRUSH);
|
||||
SetPen(*wxBLACK_PEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
pOldDC->EndDrawing();
|
||||
m_hPS = NULLHANDLE;
|
||||
m_hDC = NULLHANDLE;
|
||||
m_ok = FALSE;
|
||||
m_bOwnsDC = FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pOldDC->EndDrawing();
|
||||
m_hPS = NULLHANDLE;
|
||||
m_hDC = NULLHANDLE;
|
||||
m_ok = FALSE;
|
||||
m_bOwnsDC = FALSE;
|
||||
}
|
||||
} // end of wxMemoryDC::wxMemoryDC
|
||||
|
||||
// the background mode is only used for text background
|
||||
// and is set in DrawText() to OPAQUE as required, other-
|
||||
// wise always TRANSPARENT, RR
|
||||
::SetBkMode( GetHdc(), TRANSPARENT );
|
||||
*/
|
||||
wxMemoryDC::~wxMemoryDC()
|
||||
{
|
||||
if (m_hPS != NULLHANDLE)
|
||||
::GpiDestroyPS(m_hPS);
|
||||
if (m_hDC != NULLHANDLE)
|
||||
::DevCloseDC(m_hDC);
|
||||
} // end of wxMemoryDC::~wxMemoryDC
|
||||
|
||||
void wxMemoryDC::SelectObject(
|
||||
const wxBitmap& rBitmap
|
||||
)
|
||||
{
|
||||
//
|
||||
// Select old bitmap out of the device context
|
||||
//
|
||||
if (m_hOldBitmap)
|
||||
{
|
||||
::GpiSetBitmap(m_hPS, NULLHANDLE);
|
||||
if (m_vSelectedBitmap.Ok())
|
||||
{
|
||||
m_vSelectedBitmap.SetSelectedInto(NULL);
|
||||
m_vSelectedBitmap = wxNullBitmap;
|
||||
}
|
||||
}
|
||||
|
||||
wxMemoryDC::~wxMemoryDC(void)
|
||||
{
|
||||
};
|
||||
//
|
||||
// Check for whether the bitmap is already selected into a device context
|
||||
//
|
||||
wxCHECK_RET( !rBitmap.GetSelectedInto() ||
|
||||
(rBitmap.GetSelectedInto() == this),
|
||||
wxT("Bitmap is selected in another wxMemoryDC, delete the first wxMemoryDC or use SelectObject(NULL)") );
|
||||
|
||||
void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
|
||||
{
|
||||
// TODO:
|
||||
};
|
||||
m_vSelectedBitmap = rBitmap;
|
||||
|
||||
void wxMemoryDC::DoGetSize( int *width, int *height ) const
|
||||
WXHBITMAP hBmp = m_vSelectedBitmap.GetHBITMAP();
|
||||
|
||||
if (!hBmp)
|
||||
return;
|
||||
|
||||
m_vSelectedBitmap.SetSelectedInto(this);
|
||||
hBmp = (WXHBITMAP)::GpiSetBitmap(m_hPS, (HBITMAP)hBmp);
|
||||
|
||||
if (hBmp != HBM_ERROR)
|
||||
{
|
||||
wxLogLastError(wxT("SelectObject(memDC, bitmap)"));
|
||||
wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
|
||||
}
|
||||
else if (!m_hOldBitmap)
|
||||
{
|
||||
m_hOldBitmap = hBmp;
|
||||
}
|
||||
} // end of wxMemoryDC::SelectObject
|
||||
|
||||
void wxMemoryDC::DoGetSize(
|
||||
int* pWidth
|
||||
, int* pHeight
|
||||
) const
|
||||
{
|
||||
if (!m_vSelectedBitmap.Ok())
|
||||
{
|
||||
*width = 0; *height = 0;
|
||||
*pWidth = 0;
|
||||
*pHeight = 0;
|
||||
return;
|
||||
}
|
||||
*width = m_vSelectedBitmap.GetWidth();
|
||||
*height = m_vSelectedBitmap.GetHeight();
|
||||
};
|
||||
*pWidth = m_vSelectedBitmap.GetWidth();
|
||||
*pHeight = m_vSelectedBitmap.GetHeight();
|
||||
} // end of wxMemoryDC::DoGetSize
|
||||
|
||||
|
||||
|
@@ -330,7 +330,7 @@ bool wxMenu::DoInsertOrAppend(
|
||||
// Will eventually need to set the image handle somewhere into vItem.hItem
|
||||
//
|
||||
rItem.afStyle |= MIS_OWNERDRAW;
|
||||
pData = (BYTE*)pItem;
|
||||
pData = (BYTE*)NULL;
|
||||
rItem.hItem = (HBITMAP)pItem->GetBitmap().GetHBITMAP();
|
||||
pItem->m_vMenuData.afStyle = rItem.afStyle;
|
||||
pItem->m_vMenuData.hItem = rItem.hItem;
|
||||
|
@@ -75,39 +75,27 @@ bool wxOwnerDrawn::OnMeasureItem(
|
||||
|
||||
wxString sStr = wxStripMenuCodes(m_strName);
|
||||
|
||||
//
|
||||
// # without this menu items look too tightly packed (at least under Windows)
|
||||
//
|
||||
sStr += wxT('W'); // 'W' is typically the widest letter
|
||||
wxString sTgt = "\t";
|
||||
size_t nIndex;
|
||||
|
||||
nIndex = sStr.Find(sTgt.c_str());
|
||||
if (nIndex != -1)
|
||||
sStr.Remove(nIndex);
|
||||
sTgt = "~";
|
||||
nIndex = sStr.Find(sTgt.c_str());
|
||||
if (nIndex != -1)
|
||||
sStr.Replace(sTgt.c_str(), "", TRUE);
|
||||
|
||||
vDC.GetTextExtent( sStr
|
||||
,(long *)pWidth
|
||||
,(long *)pHeight
|
||||
);
|
||||
// DEBUG
|
||||
char zMsg[128];
|
||||
sprintf(zMsg, "GetTextExtent for %s: Width: %ld, Height: %ld", m_strName.c_str(), *pWidth, *pHeight);
|
||||
(void)wxMessageBox( "wxWindows Menu sample"
|
||||
,zMsg
|
||||
,wxICON_INFORMATION
|
||||
);
|
||||
// end DEBUG
|
||||
|
||||
//
|
||||
// JACS: items still look too tightly packed, so adding 2 pixels.
|
||||
//
|
||||
(*pHeight) = (*pHeight) + 2;
|
||||
m_nHeight = *pHeight; // remember height for use in OnDrawItem
|
||||
return TRUE;
|
||||
} // end of wxOwnerDrawn::OnMeasureItem
|
||||
|
||||
// searching for this macro you'll find all the code where I'm using the native
|
||||
// Win32 GDI functions and not wxWindows ones. Might help to whoever decides to
|
||||
// port this code to X. (VZ)
|
||||
|
||||
// JACS: TODO. Why does a disabled but highlighted item still
|
||||
// get drawn embossed? How can we tell DrawState that we don't want the
|
||||
// embossing?
|
||||
|
||||
// draw the item
|
||||
bool wxOwnerDrawn::OnDrawItem(
|
||||
wxDC& rDC
|
||||
@@ -117,12 +105,9 @@ bool wxOwnerDrawn::OnDrawItem(
|
||||
)
|
||||
{
|
||||
//
|
||||
// For now we let PM deal with highlighting and framing and such in a
|
||||
// default manner. So we leave fsAttribute and fsOldAttribute ( or
|
||||
// fsState and fsOldState ) the same and pass it on. We may want to add
|
||||
// code later to draw theseattributes in a more custom manner.
|
||||
//
|
||||
|
||||
// We do nothing on focus change
|
||||
if (eAction == wxODFocusChanged )
|
||||
return TRUE;
|
||||
//
|
||||
// WxWinGdi_CColour <-> RGB
|
||||
//
|
||||
@@ -137,22 +122,22 @@ bool wxOwnerDrawn::OnDrawItem(
|
||||
|
||||
if (eStatus & wxODSelected)
|
||||
{
|
||||
lColBack = (DWORD)::WinQuerySysColor( HWND_DESKTOP
|
||||
lColBack = (ULONG)::WinQuerySysColor( HWND_DESKTOP
|
||||
,SYSCLR_MENUHILITEBGND // Light gray
|
||||
,0L
|
||||
);
|
||||
lColText = (DWORD)::WinQuerySysColor( HWND_DESKTOP
|
||||
lColText = (ULONG)::WinQuerySysColor( HWND_DESKTOP
|
||||
,SYSCLR_MENUTEXT // Black
|
||||
,0L
|
||||
);
|
||||
}
|
||||
else if (eStatus & wxODDisabled)
|
||||
{
|
||||
lColBack = (DWORD)::WinQuerySysColor( HWND_DESKTOP
|
||||
lColBack = (ULONG)::WinQuerySysColor( HWND_DESKTOP
|
||||
,SYSCLR_MENU // Light gray
|
||||
,0L
|
||||
);
|
||||
lColText = (DWORD)::WinQuerySysColor( HWND_DESKTOP
|
||||
lColText = (ULONG)::WinQuerySysColor( HWND_DESKTOP
|
||||
,SYSCLR_MENUDISABLEDTEXT // dark gray
|
||||
,0L
|
||||
);
|
||||
@@ -217,11 +202,27 @@ bool wxOwnerDrawn::OnDrawItem(
|
||||
// to handle them ourselves. Notice Win32 can't handle \t in ownerdrawn
|
||||
// strings either.
|
||||
|
||||
//
|
||||
// Manually replace the tab with spaces
|
||||
//
|
||||
wxString sTgt = "\t";
|
||||
wxString sReplace = " ";
|
||||
size_t nIndex;
|
||||
|
||||
nIndex = m_strName.Find(sTgt.c_str());
|
||||
if (nIndex != -1)
|
||||
m_strName.Replace(sTgt.c_str(), sReplace.c_str(), TRUE);
|
||||
sTgt = "~";
|
||||
nIndex = m_strName.Find(sTgt.c_str());
|
||||
if (nIndex != -1)
|
||||
m_strName.Replace(sTgt.c_str(), "", TRUE);
|
||||
|
||||
rDC.DrawText( m_strName
|
||||
,nX
|
||||
,rRect.y
|
||||
,rRect.y + 4
|
||||
);
|
||||
|
||||
#if 0
|
||||
//
|
||||
// Draw the bitmap
|
||||
// ---------------
|
||||
@@ -311,8 +312,8 @@ bool wxOwnerDrawn::OnDrawItem(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
return TRUE;
|
||||
}
|
||||
} // end of wxOwnerDrawn::OnDrawItem
|
||||
|
||||
#endif //wxUSE_OWNER_DRAWN
|
||||
|
@@ -1988,13 +1988,6 @@ MRESULT wxWindow::OS2WindowProc(
|
||||
|
||||
if ( uMsg == WM_DRAWITEM )
|
||||
{
|
||||
// DEBUG
|
||||
sprintf(zMsg, "In OS2OnDrawItem, id: %d", nIdCtrl);
|
||||
(void)wxMessageBox( "wxWindows Menu sample"
|
||||
,zMsg
|
||||
,wxICON_INFORMATION
|
||||
);
|
||||
// end DEBUG
|
||||
bProcessed = OS2OnDrawItem(nIdCtrl,
|
||||
(WXDRAWITEMSTRUCT *)lParam);
|
||||
}
|
||||
@@ -2672,48 +2665,75 @@ bool wxWindow::OS2OnDrawItem(
|
||||
if (vId == 0)
|
||||
{
|
||||
POWNERITEM pMeasureStruct = (POWNERITEM)pItemStruct;
|
||||
BYTE* pData;
|
||||
wxMenuItem* pMenuItem;
|
||||
wxFrame* pFrame = (wxFrame*)this;
|
||||
wxMenuItem* pMenuItem = pFrame->GetMenuBar()->FindItem(pMeasureStruct->idItem, pMeasureStruct->hItem);
|
||||
HDC hDC = ::GpiQueryDevice(pMeasureStruct->hps);
|
||||
|
||||
wxRect vRect( pMeasureStruct->rclItem.xLeft
|
||||
,pMeasureStruct->rclItem.yBottom
|
||||
,pMeasureStruct->rclItem.xRight - pMeasureStruct->rclItem.xLeft
|
||||
,pMeasureStruct->rclItem.yTop - pMeasureStruct->rclItem.yBottom
|
||||
);
|
||||
vDc.SetHDC( hDC
|
||||
,FALSE
|
||||
);
|
||||
vDc.SetHPS(pMeasureStruct->hps);
|
||||
#if 0
|
||||
//
|
||||
// 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)pData
|
||||
);
|
||||
wxRect vRect( pMeasureStruct->rclItem.xLeft
|
||||
,pMeasureStruct->rclItem.yTop
|
||||
,pMeasureStruct->rclItem.xRight
|
||||
,pMeasureStruct->rclItem.yBottom
|
||||
);
|
||||
|
||||
wxOwnerDrawn::wxODAction eAction;
|
||||
wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
|
||||
|
||||
|
||||
int eAction = 0;
|
||||
int eStatus = 0;
|
||||
|
||||
//
|
||||
// Attribute applies to menuitems, fsState to listbox and other controls
|
||||
//
|
||||
if (pMeasureStruct->fsAttribute == pMeasureStruct->fsAttributeOld)
|
||||
{
|
||||
//
|
||||
// Entire Item needs to be redrawn (either it has reappeared from
|
||||
// behind another window or is being displayed for the first time
|
||||
//
|
||||
eAction = wxOwnerDrawn::wxODDrawAll;
|
||||
|
||||
if (pMeasureStruct->fsAttribute & MIA_HILITED)
|
||||
{
|
||||
//
|
||||
// If it is currently selected we let the system handle it
|
||||
//
|
||||
eStatus |= wxOwnerDrawn::wxODSelected;
|
||||
}
|
||||
if (pMeasureStruct->fsAttribute & MIA_CHECKED)
|
||||
{
|
||||
//
|
||||
// If it is currently checked we draw our own
|
||||
//
|
||||
eStatus |= wxOwnerDrawn::wxODChecked;
|
||||
pMeasureStruct->fsAttributeOld = pMeasureStruct->fsAttribute &= ~MIA_CHECKED;
|
||||
}
|
||||
if (pMeasureStruct->fsAttribute & MIA_DISABLED)
|
||||
{
|
||||
//
|
||||
// If it is currently disabled we let the system handle it
|
||||
//
|
||||
eStatus |= wxOwnerDrawn::wxODDisabled;
|
||||
}
|
||||
//
|
||||
// Don't really care about framed (indicationg focus) or NoDismiss
|
||||
//
|
||||
}
|
||||
else
|
||||
eAction = wxOwnerDrawn::wxODSelectChanged;
|
||||
pMenuItem = (wxMenuItem*)pData;
|
||||
{
|
||||
//
|
||||
// For now we don't care about doing our own highlighting so we'll
|
||||
// just ignore the entie message!
|
||||
//
|
||||
return TRUE;
|
||||
}
|
||||
//
|
||||
// Now redraw the item
|
||||
//
|
||||
return(pMenuItem->OnDrawItem( vDc
|
||||
,vRect
|
||||
,eAction
|
||||
,(wxOwnerDrawn::wxODStatus)pMeasureStruct->fsAttribute
|
||||
,(wxOwnerDrawn::wxODAction)eAction
|
||||
,(wxOwnerDrawn::wxODStatus)eStatus
|
||||
));
|
||||
#endif
|
||||
//
|
||||
// leave the fsAttribute and fsOldAttribute unchanged. If different,
|
||||
// the system will do the highlight or fraeming or disabling for us,
|
||||
|
Reference in New Issue
Block a user