]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/ownerdrw.cpp
a270099a340e4c69bf4ffad246fcca9b6aac1fb2
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/ownerdrw.cpp
3 // Purpose: implementation of wxOwnerDrawn class
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
20 #include "wx/window.h"
21 #include "wx/msw/private.h"
23 #include "wx/bitmap.h"
24 #include "wx/dcmemory.h"
31 #include "wx/ownerdrw.h"
32 #include "wx/menuitem.h"
35 // ============================================================================
36 // implementation of wxOwnerDrawn class
37 // ============================================================================
43 wxOwnerDrawn::wxOwnerDrawn(
50 m_bCheckable
= bCheckable
;
51 m_bOwnerDrawn
= FALSE
;
53 m_nMarginWidth
= ms_nLastMarginWidth
;
55 m_font
= *wxNORMAL_FONT
;
56 } // end of wxOwnerDrawn::wxOwnerDrawn
58 size_t wxOwnerDrawn::ms_nDefaultMarginWidth
= 15;
60 size_t wxOwnerDrawn::ms_nLastMarginWidth
= ms_nDefaultMarginWidth
;
67 bool wxOwnerDrawn::OnMeasureItem(
74 vDC
.SetFont(GetFont());
76 wxString sStr
= wxStripMenuCodes(m_strName
);
81 nIndex
= sStr
.Find(sTgt
.c_str());
85 nIndex
= sStr
.Find(sTgt
.c_str());
87 sStr
.Replace(sTgt
.c_str(), "", TRUE
);
89 vDC
.GetTextExtent( sStr
94 (*pHeight
) = (*pHeight
) + 2;
95 m_nHeight
= *pHeight
; // remember height for use in OnDrawItem
97 } // end of wxOwnerDrawn::OnMeasureItem
100 bool wxOwnerDrawn::OnDrawItem(
102 , const wxRect
& rRect
108 // We do nothing on focus change
110 if (eAction
== wxODFocusChanged
)
114 // Select the font and draw the text
115 // ---------------------------------
119 HPS hPS
= rDC
.GetHPS();
126 // Use default font if no font set
130 m_font
.RealizeResource();
134 ::GpiSetCharSet(hPS
, LCID_DEFAULT
);
136 if (eStatus
& wxODSelected
)
138 vRef
= (ULONG
)::WinQuerySysColor( HWND_DESKTOP
139 ,SYSCLR_MENUHILITEBGND
// Light gray
142 vColBack
.Set( GetRValue(vRef
)
146 vColText
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENUTEXT
);
148 else if (eStatus
& wxODDisabled
)
150 vRef
= (ULONG
)::WinQuerySysColor( HWND_DESKTOP
151 ,SYSCLR_MENU
// Light gray
154 vColBack
.Set( GetRValue(vRef
)
158 vRef
= (ULONG
)::WinQuerySysColor( HWND_DESKTOP
159 ,SYSCLR_MENUDISABLEDTEXT
// dark gray
162 vColText
.Set( GetRValue(vRef
)
170 // Fall back to default colors if none explicitly specified
172 vRef
= ::WinQuerySysColor( HWND_DESKTOP
173 ,SYSCLR_MENU
// we are using gray for all our window backgrounds in wxWindows
176 vColBack
.Set( GetRValue(vRef
)
180 vRef
= ::WinQuerySysColor( HWND_DESKTOP
181 ,SYSCLR_WINDOWTEXT
// Black
184 vColText
.Set( GetRValue(vRef
)
189 vRef
= vColBack
.GetPixel();
190 vCbnd
.lBackColor
= (LONG
)vRef
;
192 vRef
= vColText
.GetPixel();
193 vCbnd
.lColor
= (LONG
)vRef
;
195 sprintf(zMsg
, "Color: %ld", vRef
);
196 wxMessageBox( "wxWindows Menu Sample"
203 ,CBB_COLOR
| CBB_BACK_COLOR
209 // Determine where to draw and leave space for a check-mark.
211 int nX
= rRect
.x
+ GetMarginWidth();
214 // Unfortunately, unlike Win32, PM has no owner drawn specific text
215 // drawing methods like ::DrawState that can cleanly handle accel
216 // pneumonics and deal, automatically, with various states, so we have
217 // to handle them ourselves. Notice Win32 can't handle \t in ownerdrawn
221 // Manually replace the tab with spaces
223 wxString sTgt
= "\t";
224 wxString sReplace
= " ";
227 nIndex
= m_strName
.Find(sTgt
.c_str());
229 m_strName
.Replace(sTgt
.c_str(), sReplace
.c_str(), TRUE
);
231 nIndex
= m_strName
.Find(sTgt
.c_str());
233 m_strName
.Replace(sTgt
.c_str(), "", TRUE
);
238 vPoint
.y
= rRect
.y
+ 4;
239 ::GpiCharStringAt( hPS
242 ,(PCH
)m_strName
.c_str()
250 if (IsCheckable() && !m_bmpChecked
.Ok())
252 if (eStatus
& wxODChecked
)
255 HBITMAP hBmpCheck
= ::WinGetSysBitmap(HWND_DESKTOP
, SBMP_MENUCHECK
);
257 vRect
.xLeft
= rRect
.x
;
258 vRect
.xRight
= rRect
.x
+ GetMarginWidth();
259 vRect
.yBottom
= rRect
.y
;
260 vRect
.yTop
= rRect
.y
+ m_nHeight
;
262 ::WinDrawBitmap( hPS
// PS for this menuitem
263 ,hBmpCheck
// system checkmark
264 ,NULL
// draw the whole bitmap
265 ,(PPOINTL
)&vRect
// destination -- bottom left corner of the menuitem area
268 ,DBM_NORMAL
// draw normal size
275 // For uncheckable item we use only the 'checked' bitmap
277 wxBitmap
vBmp(GetBitmap(IsCheckable() ? ((eStatus
& wxODChecked
) != 0) : TRUE
));
281 wxMemoryDC
vDCMem(&rDC
);
283 vDCMem
.SelectObject(vBmp
);
288 int nBmpWidth
= vBmp
.GetWidth();
289 int nBmpHeight
= vBmp
.GetHeight();
292 // There should be enough space!
294 wxASSERT((nBmpWidth
<= rRect
.width
) && (nBmpHeight
<= rRect
.height
));
297 //MT: blit with mask enabled.
299 rDC
.Blit( rRect
.x
+ (GetMarginWidth() - nBmpWidth
) / 2
300 ,rRect
.y
+ (m_nHeight
- nBmpHeight
) /2
310 if (eStatus
& wxODSelected
)
312 RECT vRectBmp
= { rRect
.x
314 ,rRect
.x
+ GetMarginWidth()
319 vLine
.lColor
= lColBack
;
337 } // end of wxOwnerDrawn::OnDrawItem
339 #endif //wxUSE_OWNER_DRAWN