]>
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 sprintf(zMsg
, "GetTextExtent for %s: Width: %ld, Height: %ld", m_strName
.c_str(), *pWidth
, *pHeight
);
89 (void)wxMessageBox( "wxWindows Menu sample"
96 // JACS: items still look too tightly packed, so adding 2 pixels.
98 (*pHeight
) = (*pHeight
) + 2;
99 m_nHeight
= *pHeight
; // remember height for use in OnDrawItem
101 } // end of wxOwnerDrawn::OnMeasureItem
103 // searching for this macro you'll find all the code where I'm using the native
104 // Win32 GDI functions and not wxWindows ones. Might help to whoever decides to
105 // port this code to X. (VZ)
107 // JACS: TODO. Why does a disabled but highlighted item still
108 // get drawn embossed? How can we tell DrawState that we don't want the
112 bool wxOwnerDrawn::OnDrawItem(
114 , const wxRect
& rRect
120 // For now we let PM deal with highlighting and framing and such in a
121 // default manner. So we leave fsAttribute and fsOldAttribute ( or
122 // fsState and fsOldState ) the same and pass it on. We may want to add
123 // code later to draw theseattributes in a more custom manner.
127 // WxWinGdi_CColour <-> RGB
129 #define ToRGB(col) OS2RGB(col.Red(), col.Green(), col.Blue())
130 #define UnRGB(col) GetRValue(col), GetGValue(col), GetBValue(col)
132 CHARBUNDLE vCbndText
;
133 CHARBUNDLE vCbndBack
;
134 HPS hPS
= rDC
.GetHPS();
138 if (eStatus
& wxODSelected
)
140 lColBack
= (DWORD
)::WinQuerySysColor( HWND_DESKTOP
141 ,SYSCLR_MENUHILITEBGND
// Light gray
144 lColText
= (DWORD
)::WinQuerySysColor( HWND_DESKTOP
145 ,SYSCLR_MENUTEXT
// Black
149 else if (eStatus
& wxODDisabled
)
151 lColBack
= (DWORD
)::WinQuerySysColor( HWND_DESKTOP
152 ,SYSCLR_MENU
// Light gray
155 lColText
= (DWORD
)::WinQuerySysColor( HWND_DESKTOP
156 ,SYSCLR_MENUDISABLEDTEXT
// dark gray
163 // Fall back to default colors if none explicitly specified
165 lColBack
= m_colBack
.Ok() ? ToRGB(m_colBack
) : ::WinQuerySysColor( HWND_DESKTOP
166 ,SYSCLR_MENU
// we are using gray for all our window backgrounds in wxWindows
169 lColText
= m_colText
.Ok() ? ToRGB(m_colText
) : ::WinQuerySysColor( HWND_DESKTOP
170 ,SYSCLR_WINDOWTEXT
// Black
174 vCbndText
.lColor
= (LONG
)lColText
;
175 vCbndBack
.lColor
= (LONG
)lColBack
;
192 // Determine where to draw and leave space for a check-mark.
194 int nX
= rRect
.x
+ GetMarginWidth();
197 // Select the font and draw the text
198 // ---------------------------------
202 // Use default font if no font set
206 m_font
.RealizeResource();
210 ::GpiSetCharSet(hPS
, LCID_DEFAULT
);
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
220 rDC
.DrawText( m_strName
229 if (IsCheckable() && !m_bmpChecked
.Ok())
231 if (eStatus
& wxODChecked
)
234 HBITMAP hBmpCheck
= ::WinGetSysBitmap(HWND_DESKTOP
, SBMP_MENUCHECK
);
236 vRect
.xLeft
= rRect
.x
;
237 vRect
.xRight
= rRect
.x
+ GetMarginWidth();
238 vRect
.yBottom
= rRect
.y
;
239 vRect
.yTop
= rRect
.y
+ m_nHeight
;
241 ::WinDrawBitmap( hPS
// PS for this menuitem
242 ,hBmpCheck
// system checkmark
243 ,NULL
// draw the whole bitmap
244 ,(PPOINTL
)&vRect
// destination -- bottom left corner of the menuitem area
247 ,DBM_NORMAL
// draw normal size
254 // For uncheckable item we use only the 'checked' bitmap
256 wxBitmap
vBmp(GetBitmap(IsCheckable() ? ((eStatus
& wxODChecked
) != 0) : TRUE
));
260 wxMemoryDC
vDCMem(&rDC
);
262 vDCMem
.SelectObject(vBmp
);
267 int nBmpWidth
= vBmp
.GetWidth();
268 int nBmpHeight
= vBmp
.GetHeight();
271 // There should be enough space!
273 wxASSERT((nBmpWidth
<= rRect
.width
) && (nBmpHeight
<= rRect
.height
));
276 //MT: blit with mask enabled.
278 rDC
.Blit( rRect
.x
+ (GetMarginWidth() - nBmpWidth
) / 2
279 ,rRect
.y
+ (m_nHeight
- nBmpHeight
) /2
289 if (eStatus
& wxODSelected
)
291 RECT vRectBmp
= { rRect
.x
293 ,rRect
.x
+ GetMarginWidth()
298 vLine
.lColor
= lColBack
;
318 #endif //wxUSE_OWNER_DRAWN