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