]>
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 
   8 // Copyright:   (c) David Webster 
   9 // Licence:     wxWindows licence 
  10 /////////////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  17 #include "wx/ownerdrw.h" 
  18 #include "wx/os2/private.h" 
  19 #include "wx/os2/dcclient.h" 
  21 // ---------------------------------------------------------------------------- 
  22 // constants for base class 
  23 // ---------------------------------------------------------------------------- 
  25 int wxOwnerDrawnBase::ms_defaultMargin 
= 3; 
  27 // ============================================================================ 
  28 // implementation of wxOwnerDrawn class 
  29 // ============================================================================ 
  32 bool wxOwnerDrawn::OnDrawItem( wxDC
& rDC
, 
  39     // Select the font and draw the text 
  40     // --------------------------------- 
  44     wxPMDCImpl                      
*impl 
= (wxPMDCImpl
*) rDC
.GetImpl(); 
  45     HPS                             hPS
= impl
->GetHPS(); 
  50     RECTL                           vRect 
= {rRect
.x 
+ 4, rRect
.y 
+ 1, rRect
.x 
+ (rRect
.width 
- 2), rRect
.y 
+ rRect
.height
}; 
  52     memset(&vCbnd
, 0, sizeof(CHARBUNDLE
)); 
  55     GetColourToUse(eStatus
, vColText
, vColBack
); 
  58     rDC
.SetTextBackground(vColBack
); 
  59     rDC
.SetTextForeground(vColText
); 
  60     rDC
.SetBackgroundMode(wxTRANSPARENT
); 
  62     vCbnd
.lColor     
= vColText
.GetPixel(); 
  63     vCbnd
.lBackColor 
= vColBack
.GetPixel(); 
  66                   ,CBB_BACK_COLOR 
| CBB_COLOR
 
  75     // Paint the background 
  77     ::WinFillRect(hPS
, &vRect
, vColBack
.GetPixel()); 
  80     // Determine where to draw and leave space for a check-mark. 
  82     int nX 
= rRect
.x 
+ GetMarginWidth(); 
  85     // Unfortunately, unlike Win32, PM has no owner drawn specific text 
  86     // drawing methods like ::DrawState that can cleanly handle accel 
  87     // mnemonics and deal, automatically, with various states, so we have 
  88     // to handle them ourselves. Notice Win32 can't handle \t in ownerdrawn 
  89     // strings either.  We cannot handle mnemonics either.  We display 
  90     // them, though, in the hope we can figure them out some day. 
  96     wxString sFullString 
= GetItemLabel(); // need to save the original text 
 101     bool     bFoundMnemonic 
= false; 
 104     // Deal with the mnemonic character 
 106     nIndex 
= sFullString
.Find(wxT("~")); 
 109         wxString sTmp 
= sFullString
; 
 111         bFoundMnemonic 
= true; 
 113         rDC
.GetTextExtent( sTmp
 
 117         sTmp 
= sFullString
[(size_t)(nIndex 
+ 1)]; 
 118         rDC
.GetTextExtent( sTmp
 
 119                           ,(wxCoord 
*)&nCharWidth
 
 122         sFullString
.Replace(sTgt
.c_str(), wxEmptyString
, true); 
 126     // Draw the main item text sans the accel text 
 128     POINTL                      vPntStart 
= {nX
, rRect
.y 
+ 4}; 
 129     ::GpiCharStringAt( impl
->GetHPS() 
 131                       ,sFullString
.length() 
 132                       ,sFullString
.char_str() 
 137         // Underline the mnemonic -- still won't work, but at least it "looks" right 
 140         POINTL                      vPntEnd 
= {nX 
+ nWidth 
+ nCharWidth 
- 3, rRect
.y 
+ 2}; //CharWidth is bit wide 
 142         vPntStart
.x 
= nX 
+ nWidth 
- 1; 
 143         vPntStart
.y 
= rRect
.y 
+ 2; // Make it look pretty! 
 144         vPen 
= wxPen(vColText
, 1, wxSOLID
); // Assuming we are always black 
 146         ::GpiMove(hPS
, &vPntStart
); 
 147         ::GpiLine(hPS
, &vPntEnd
); 
 151 } // end of wxOwnerDrawn::OnDrawItem 
 153 #endif //wxUSE_OWNER_DRAWN