]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/ownerdrw.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/ownerdrw.cpp
3 // Purpose: implementation of wxOwnerDrawn class
4 // Author: David Webster
5 // Modified by: Marcin Malich
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
16 #include "wx/ownerdrw.h"
17 #include "wx/os2/private.h"
18 #include "wx/os2/dcclient.h"
20 // ----------------------------------------------------------------------------
21 // constants for base class
22 // ----------------------------------------------------------------------------
24 int wxOwnerDrawnBase::ms_defaultMargin
= 3;
26 // ============================================================================
27 // implementation of wxOwnerDrawn class
28 // ============================================================================
31 bool wxOwnerDrawn::OnDrawItem( wxDC
& rDC
,
38 // Select the font and draw the text
39 // ---------------------------------
43 wxPMDCImpl
*impl
= (wxPMDCImpl
*) rDC
.GetImpl();
44 HPS hPS
= impl
->GetHPS();
49 RECTL vRect
= {rRect
.x
+ 4, rRect
.y
+ 1, rRect
.x
+ (rRect
.width
- 2), rRect
.y
+ rRect
.height
};
51 memset(&vCbnd
, 0, sizeof(CHARBUNDLE
));
54 GetColourToUse(eStatus
, vColText
, vColBack
);
57 rDC
.SetTextBackground(vColBack
);
58 rDC
.SetTextForeground(vColText
);
59 rDC
.SetBackgroundMode(wxTRANSPARENT
);
61 vCbnd
.lColor
= vColText
.GetPixel();
62 vCbnd
.lBackColor
= vColBack
.GetPixel();
65 ,CBB_BACK_COLOR
| CBB_COLOR
74 // Paint the background
76 ::WinFillRect(hPS
, &vRect
, vColBack
.GetPixel());
79 // Determine where to draw and leave space for a check-mark.
81 int nX
= rRect
.x
+ GetMarginWidth();
84 // Unfortunately, unlike Win32, PM has no owner drawn specific text
85 // drawing methods like ::DrawState that can cleanly handle accel
86 // mnemonics and deal, automatically, with various states, so we have
87 // to handle them ourselves. Notice Win32 can't handle \t in ownerdrawn
88 // strings either. We cannot handle mnemonics either. We display
89 // them, though, in the hope we can figure them out some day.
95 wxString sFullString
= GetItemLabel(); // need to save the original text
100 bool bFoundMnemonic
= false;
103 // Deal with the mnemonic character
105 nIndex
= sFullString
.Find(wxT("~"));
108 wxString sTmp
= sFullString
;
110 bFoundMnemonic
= true;
112 rDC
.GetTextExtent( sTmp
116 sTmp
= sFullString
[(size_t)(nIndex
+ 1)];
117 rDC
.GetTextExtent( sTmp
118 ,(wxCoord
*)&nCharWidth
121 sFullString
.Replace(sTgt
.c_str(), wxEmptyString
, true);
125 // Draw the main item text sans the accel text
127 POINTL vPntStart
= {nX
, rRect
.y
+ 4};
128 ::GpiCharStringAt( impl
->GetHPS()
130 ,sFullString
.length()
131 ,sFullString
.char_str()
136 // Underline the mnemonic -- still won't work, but at least it "looks" right
139 POINTL vPntEnd
= {nX
+ nWidth
+ nCharWidth
- 3, rRect
.y
+ 2}; //CharWidth is bit wide
141 vPntStart
.x
= nX
+ nWidth
- 1;
142 vPntStart
.y
= rRect
.y
+ 2; // Make it look pretty!
143 vPen
= wxPen(vColText
, 1, wxSOLID
); // Assuming we are always black
145 ::GpiMove(hPS
, &vPntStart
);
146 ::GpiLine(hPS
, &vPntEnd
);
150 } // end of wxOwnerDrawn::OnDrawItem
152 #endif //wxUSE_OWNER_DRAWN