]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/ownerdrw.cpp
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
);
79 // # without this menu items look too tightly packed (at least under Windows)
81 sStr
+= wxT('W'); // 'W' is typically the widest letter
82 vDC
.GetTextExtent( sStr
88 // JACS: items still look too tightly packed, so adding 2 pixels.
90 (*pHeight
) = (*pHeight
) + 2;
91 m_nHeight
= *pHeight
; // remember height for use in OnDrawItem
93 } // end of wxOwnerDrawn::OnMeasureItem
95 // searching for this macro you'll find all the code where I'm using the native
96 // Win32 GDI functions and not wxWindows ones. Might help to whoever decides to
97 // port this code to X. (VZ)
99 // JACS: TODO. Why does a disabled but highlighted item still
100 // get drawn embossed? How can we tell DrawState that we don't want the
104 bool wxOwnerDrawn::OnDrawItem(
106 , const wxRect
& rRect
112 // For now we let PM deal with highlighting and framing and such in a
113 // default manner. So we leave fsAttribute and fsOldAttribute ( or
114 // fsState and fsOldState ) the same and pass it on. We may want to add
115 // code later to draw theseattributes in a more custom manner.
119 // WxWinGdi_CColour <-> RGB
121 #define ToRGB(col) OS2RGB(col.Red(), col.Green(), col.Blue())
122 #define UnRGB(col) GetRValue(col), GetGValue(col), GetBValue(col)
124 CHARBUNDLE vCbndText
;
125 CHARBUNDLE vCbndBack
;
126 HPS hPS
= rDC
.GetHPS();
130 if (eStatus
& wxODSelected
)
132 lColBack
= (DWORD
)::WinQuerySysColor( HWND_DESKTOP
133 ,SYSCLR_MENUHILITEBGND
// Light gray
136 lColText
= (DWORD
)::WinQuerySysColor( HWND_DESKTOP
137 ,SYSCLR_MENUTEXT
// Black
141 else if (eStatus
& wxODDisabled
)
143 lColBack
= (DWORD
)::WinQuerySysColor( HWND_DESKTOP
144 ,SYSCLR_MENU
// Light gray
147 lColText
= (DWORD
)::WinQuerySysColor( HWND_DESKTOP
148 ,SYSCLR_MENUDISABLEDTEXT
// dark gray
155 // Fall back to default colors if none explicitly specified
157 lColBack
= m_colBack
.Ok() ? ToRGB(m_colBack
) : ::WinQuerySysColor( HWND_DESKTOP
158 ,SYSCLR_MENU
// we are using gray for all our window backgrounds in wxWindows
161 lColText
= m_colText
.Ok() ? ToRGB(m_colText
) : ::WinQuerySysColor( HWND_DESKTOP
162 ,SYSCLR_WINDOWTEXT
// Black
166 vCbndText
.lColor
= (LONG
)lColText
;
167 vCbndBack
.lColor
= (LONG
)lColBack
;
184 // Determine where to draw and leave space for a check-mark.
186 int nX
= rRect
.x
+ GetMarginWidth();
189 // Select the font and draw the text
190 // ---------------------------------
194 // Use default font if no font set
198 m_font
.RealizeResource();
202 ::GpiSetCharSet(hPS
, LCID_DEFAULT
);
206 // Unfortunately, unlike Win32, PM has no owner drawn specific text
207 // drawing methods like ::DrawState that can cleanly handle accel
208 // pneumonics and deal, automatically, with various states, so we have
209 // to handle them ourselves. Notice Win32 can't handle \t in ownerdrawn
212 rDC
.DrawText( m_strName
221 if (IsCheckable() && !m_bmpChecked
.Ok())
223 if (eStatus
& wxODChecked
)
226 HBITMAP hBmpCheck
= ::WinGetSysBitmap(HWND_DESKTOP
, SBMP_MENUCHECK
);
228 vRect
.xLeft
= rRect
.x
;
229 vRect
.xRight
= rRect
.x
+ GetMarginWidth();
230 vRect
.yBottom
= rRect
.y
;
231 vRect
.yTop
= rRect
.y
+ m_nHeight
;
233 ::WinDrawBitmap( hPS
// PS for this menuitem
234 ,hBmpCheck
// system checkmark
235 ,NULL
// draw the whole bitmap
236 ,(PPOINTL
)&vRect
// destination -- bottom left corner of the menuitem area
239 ,DBM_NORMAL
// draw normal size
246 // For uncheckable item we use only the 'checked' bitmap
248 wxBitmap
vBmp(GetBitmap(IsCheckable() ? ((eStatus
& wxODChecked
) != 0) : TRUE
));
252 wxMemoryDC
vDCMem(&rDC
);
254 vDCMem
.SelectObject(vBmp
);
259 int nBmpWidth
= vBmp
.GetWidth();
260 int nBmpHeight
= vBmp
.GetHeight();
263 // There should be enough space!
265 wxASSERT((nBmpWidth
<= rRect
.width
) && (nBmpHeight
<= rRect
.height
));
268 //MT: blit with mask enabled.
270 rDC
.Blit( rRect
.x
+ (GetMarginWidth() - nBmpWidth
) / 2
271 ,rRect
.y
+ (m_nHeight
- nBmpHeight
) /2
281 if (eStatus
& wxODSelected
)
283 RECT vRectBmp
= { rRect
.x
285 ,rRect
.x
+ GetMarginWidth()
290 vLine
.lColor
= lColBack
;
310 #endif //wxUSE_OWNER_DRAWN