]> git.saurik.com Git - wxWidgets.git/blame - src/os2/ownerdrw.cpp
Make mouse capture checking asserts stronger and more detailed.
[wxWidgets.git] / src / os2 / ownerdrw.cpp
CommitLineData
63415778 1///////////////////////////////////////////////////////////////////////////////
f38924e8 2// Name: src/os2/ownerdrw.cpp
63415778
DW
3// Purpose: implementation of wxOwnerDrawn class
4// Author: David Webster
98fbab9e 5// Modified by: Marcin Malich
63415778 6// Created: 10/12/99
63415778 7// Copyright: (c) David Webster
65571936 8// Licence: wxWindows licence
63415778
DW
9///////////////////////////////////////////////////////////////////////////////
10
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
f38924e8
WS
14#if wxUSE_OWNER_DRAWN
15
63415778 16#include "wx/ownerdrw.h"
98fbab9e 17#include "wx/os2/private.h"
38400bb4 18#include "wx/os2/dcclient.h"
63415778 19
98fbab9e
VZ
20// ----------------------------------------------------------------------------
21// constants for base class
22// ----------------------------------------------------------------------------
23
24int wxOwnerDrawnBase::ms_defaultMargin = 3;
25
63415778
DW
26// ============================================================================
27// implementation of wxOwnerDrawn class
28// ============================================================================
29
63415778 30// draw the item
6670f564
WS
31bool wxOwnerDrawn::OnDrawItem( wxDC& rDC,
32 const wxRect& rRect,
33 wxODAction eAction,
34 wxODStatus eStatus )
63415778 35{
7172b423 36
402e2f7c 37 //
7172b423
DW
38 // Select the font and draw the text
39 // ---------------------------------
402e2f7c 40 //
402e2f7c 41
7172b423 42 CHARBUNDLE vCbnd;
38400bb4
SN
43 wxPMDCImpl *impl = (wxPMDCImpl*) rDC.GetImpl();
44 HPS hPS= impl->GetHPS();
98fbab9e 45 wxFont vFont;
7172b423
DW
46 wxColour vColBack;
47 wxColour vColText;
48 COLORREF vRef;
5afb9458 49 RECTL vRect = {rRect.x + 4, rRect.y + 1, rRect.x + (rRect.width - 2), rRect.y + rRect.height};
402e2f7c 50
ad7f3189
DW
51 memset(&vCbnd, 0, sizeof(CHARBUNDLE));
52
98fbab9e
VZ
53 GetFontToUse(vFont);
54 GetColourToUse(eStatus, vColText, vColBack);
ad7f3189 55
98fbab9e 56 rDC.SetFont(vFont);
5afb9458
DW
57 rDC.SetTextBackground(vColBack);
58 rDC.SetTextForeground(vColText);
59 rDC.SetBackgroundMode(wxTRANSPARENT);
98fbab9e 60
ad7f3189
DW
61 vCbnd.lColor = vColText.GetPixel();
62 vCbnd.lBackColor = vColBack.GetPixel();
63 ::GpiSetAttrs( hPS
64 ,PRIM_CHAR
65 ,CBB_BACK_COLOR | CBB_COLOR
66 ,0
67 ,&vCbnd
68 );
69 ::GpiSetBackMix( hPS
70 ,BM_LEAVEALONE
71 );
7172b423 72
5afb9458
DW
73 //
74 // Paint the background
75 //
76 ::WinFillRect(hPS, &vRect, vColBack.GetPixel());
402e2f7c 77
402e2f7c
DW
78 //
79 // Determine where to draw and leave space for a check-mark.
80 //
98fbab9e 81 int nX = rRect.x + GetMarginWidth();
402e2f7c 82
402e2f7c
DW
83 //
84 // Unfortunately, unlike Win32, PM has no owner drawn specific text
85 // drawing methods like ::DrawState that can cleanly handle accel
d6922577 86 // mnemonics and deal, automatically, with various states, so we have
402e2f7c 87 // to handle them ourselves. Notice Win32 can't handle \t in ownerdrawn
d6922577
JS
88 // strings either. We cannot handle mnemonics either. We display
89 // them, though, in the hope we can figure them out some day.
5afb9458 90 //
402e2f7c 91
23122f8c 92 //
98fbab9e 93 // Display main text
23122f8c 94 //
98fbab9e 95 wxString sFullString = GetItemLabel(); // need to save the original text
6670f564
WS
96 int nIndex;
97 size_t nWidth;
98 size_t nCharWidth;
99 size_t nHeight;
100 bool bFoundMnemonic = false;
5afb9458
DW
101
102 //
d6922577 103 // Deal with the mnemonic character
5afb9458 104 //
98fbab9e 105 nIndex = sFullString.Find(wxT("~"));
23122f8c 106 if (nIndex != -1)
5afb9458 107 {
6670f564 108 wxString sTmp = sFullString;
5afb9458 109
6670f564 110 bFoundMnemonic = true;
5afb9458
DW
111 sTmp.Remove(nIndex);
112 rDC.GetTextExtent( sTmp
38400bb4
SN
113 ,(wxCoord *)&nWidth
114 ,(wxCoord *)&nHeight
5afb9458 115 );
9923c37d 116 sTmp = sFullString[(size_t)(nIndex + 1)];
5afb9458 117 rDC.GetTextExtent( sTmp
38400bb4
SN
118 ,(wxCoord *)&nCharWidth
119 ,(wxCoord *)&nHeight
5afb9458 120 );
6670f564 121 sFullString.Replace(sTgt.c_str(), wxEmptyString, true);
5afb9458
DW
122 }
123
124 //
125 // Draw the main item text sans the accel text
ad7f3189
DW
126 //
127 POINTL vPntStart = {nX, rRect.y + 4};
38400bb4 128 ::GpiCharStringAt( impl->GetHPS()
ad7f3189
DW
129 ,&vPntStart
130 ,sFullString.length()
fb2c90ca 131 ,sFullString.char_str()
ad7f3189 132 );
d6922577 133 if (bFoundMnemonic)
5afb9458
DW
134 {
135 //
d6922577 136 // Underline the mnemonic -- still won't work, but at least it "looks" right
5afb9458
DW
137 //
138 wxPen vPen;
5afb9458
DW
139 POINTL vPntEnd = {nX + nWidth + nCharWidth - 3, rRect.y + 2}; //CharWidth is bit wide
140
ad7f3189
DW
141 vPntStart.x = nX + nWidth - 1;
142 vPntStart.y = rRect.y + 2; // Make it look pretty!
5afb9458
DW
143 vPen = wxPen(vColText, 1, wxSOLID); // Assuming we are always black
144 rDC.SetPen(vPen);
145 ::GpiMove(hPS, &vPntStart);
146 ::GpiLine(hPS, &vPntEnd);
147 }
23122f8c 148
6670f564 149 return true;
23122f8c 150} // end of wxOwnerDrawn::OnDrawItem
63415778 151
7e99520b 152#endif //wxUSE_OWNER_DRAWN