]>
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
);
78 vDC
.GetTextExtent( sStr
83 (*pHeight
) = (*pHeight
) + 2;
84 m_nHeight
= *pHeight
; // remember height for use in OnDrawItem
86 } // end of wxOwnerDrawn::OnMeasureItem
89 bool wxOwnerDrawn::OnDrawItem(
97 // We do nothing on focus change
99 if (eAction
== wxODFocusChanged
)
103 // Select the font and draw the text
104 // ---------------------------------
108 HPS hPS
= rDC
.GetHPS();
112 RECTL vRect
= {rRect
.x
+ 4, rRect
.y
+ 1, rRect
.x
+ (rRect
.width
- 2), rRect
.y
+ rRect
.height
};
115 // Use default font if no font set
119 m_font
.RealizeResource();
123 ::GpiSetCharSet(hPS
, LCID_DEFAULT
);
127 // Base on the status of the menu item pick the right colors
129 if (eStatus
& wxODSelected
)
131 wxColour
vCol2("WHITE");
132 vColBack
.Set( (unsigned char)0
135 ); // no dark blue in color table
138 else if (eStatus
& wxODDisabled
)
140 vRef
= (ULONG
)::WinQuerySysColor( HWND_DESKTOP
141 ,SYSCLR_MENU
// Light gray
144 vColBack
.Set( GetRValue(vRef
)
148 vRef
= (ULONG
)::WinQuerySysColor( HWND_DESKTOP
149 ,SYSCLR_MENUDISABLEDTEXT
// dark gray
152 vColText
.Set( GetRValue(vRef
)
160 // Fall back to default colors if none explicitly specified
162 vRef
= ::WinQuerySysColor( HWND_DESKTOP
163 ,SYSCLR_MENU
// we are using gray for all our window backgrounds in wxWindows
166 vColBack
.Set( GetRValue(vRef
)
170 vRef
= ::WinQuerySysColor( HWND_DESKTOP
171 ,SYSCLR_WINDOWTEXT
// Black
174 vColText
.Set( GetRValue(vRef
)
179 rDC
.SetTextBackground(vColBack
);
180 rDC
.SetTextForeground(vColText
);
181 rDC
.SetBackgroundMode(wxTRANSPARENT
);
184 // Paint the background
186 ::WinFillRect(hPS
, &vRect
, vColBack
.GetPixel());
189 // Determine where to draw and leave space for a check-mark.
191 int nX
= rRect
.x
+ GetMarginWidth();
194 // Unfortunately, unlike Win32, PM has no owner drawn specific text
195 // drawing methods like ::DrawState that can cleanly handle accel
196 // pneumonics and deal, automatically, with various states, so we have
197 // to handle them ourselves. Notice Win32 can't handle \t in ownerdrawn
198 // strings either. We cannot handle mneumonics either. We display
199 // it, though, in hopes we can figure it out some day.
203 // Display main text and accel text separately to allign better
205 wxString sTgt
= "\t";
206 wxString sFullString
= m_strName
; // need to save the original text
212 bool bFoundMneumonic
= FALSE
;
213 bool bFoundAccel
= FALSE
;
216 // Deal with the tab, extracting the Accel text
218 nIndex
= sFullString
.Find(sTgt
.c_str());
222 sAccel
= sFullString
.Mid(nIndex
+ 1);
223 sFullString
.Remove(nIndex
);
227 // Deal with the mneumonic character
230 nIndex
= sFullString
.Find(sTgt
.c_str());
233 wxString sTmp
= sFullString
;
235 bFoundMneumonic
= TRUE
;
237 rDC
.GetTextExtent( sTmp
241 sTmp
= sFullString
[nIndex
+ 1];
242 rDC
.GetTextExtent( sTmp
246 sFullString
.Replace(sTgt
.c_str(), "", TRUE
);
250 // Draw the main item text sans the accel text
251 rDC
.DrawText( sFullString
258 // Underline the mneumonic -- still won't work, but at least it "looks" right
261 POINTL vPntStart
= {nX
+ nWidth
- 1, rRect
.y
+ 2}; // Make it look pretty!
262 POINTL vPntEnd
= {nX
+ nWidth
+ nCharWidth
- 3, rRect
.y
+ 2}; //CharWidth is bit wide
264 vPen
= wxPen(vColText
, 1, wxSOLID
); // Assuming we are always black
266 ::GpiMove(hPS
, &vPntStart
);
267 ::GpiLine(hPS
, &vPntEnd
);
271 // Now draw the accel text
278 rDC
.GetTextExtent( sAccel
283 // Back off the starting position from the right edge
286 ,rRect
.width
- (nWidth
+ 7) // this seems to mimic the default OS/2 positioning
295 if (IsCheckable() && !m_bmpChecked
.Ok())
297 if (eStatus
& wxODChecked
)
300 HBITMAP hBmpCheck
= ::WinGetSysBitmap(HWND_DESKTOP
, SBMP_MENUCHECK
);
302 vRect
.xLeft
= rRect
.x
;
303 vRect
.xRight
= rRect
.x
+ GetMarginWidth();
304 vRect
.yBottom
= rRect
.y
;
305 vRect
.yTop
= rRect
.y
+ m_nHeight
- 3;
307 ::WinDrawBitmap( hPS
// PS for this menuitem
308 ,hBmpCheck
// system checkmark
309 ,NULL
// draw the whole bitmap
310 ,(PPOINTL
)&vRect
// destination -- bottom left corner of the menuitem area
313 ,DBM_NORMAL
// draw normal size
320 // For uncheckable item we use only the 'checked' bitmap
322 wxBitmap
vBmp(GetBitmap(IsCheckable() ? ((eStatus
& wxODChecked
) != 0) : TRUE
));
326 wxMemoryDC
vDCMem(&rDC
);
328 vDCMem
.SelectObject(vBmp
);
333 int nBmpWidth
= vBmp
.GetWidth();
334 int nBmpHeight
= vBmp
.GetHeight();
337 // There should be enough space!
339 wxASSERT((nBmpWidth
<= rRect
.width
) && (nBmpHeight
<= rRect
.height
));
342 //MT: blit with mask enabled.
344 rDC
.Blit( rRect
.x
+ (GetMarginWidth() - nBmpWidth
) / 2
345 ,rRect
.y
+ (m_nHeight
- nBmpHeight
) /2
355 if (eStatus
& wxODSelected
)
357 RECT vRectBmp
= { rRect
.x
359 ,rRect
.x
+ GetMarginWidth()
362 POINTL vPnt1
= {2, 4}; // Leave a little background border
363 POINTL vPnt2
= {rRect
.x
+ GetMarginWidth(), rRect
.y
+ m_nHeight
- 3};
366 vLine
.lColor
= vColBack
.GetPixel();
373 ::GpiMove(hPS
, &vPnt1
);
384 } // end of wxOwnerDrawn::OnDrawItem
386 #endif //wxUSE_OWNER_DRAWN