]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/control.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/os2/control.cpp 
   3 // Purpose:     wxControl class 
   4 // Author:      David Webster 
   8 // Copyright:   (c) Julian Smart 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  15 #include "wx/control.h" 
  20     #include "wx/dcclient.h" 
  21     #include "wx/scrolwin.h" 
  25 #include "wx/os2/dc.h" 
  26 #include "wx/os2/private.h" 
  28 IMPLEMENT_ABSTRACT_CLASS(wxControl
, wxWindow
) 
  30 BEGIN_EVENT_TABLE(wxControl
, wxWindow
) 
  31     EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground
) 
  35 wxControl::wxControl() 
  37 } // end of wxControl::wxControl 
  39 bool wxControl::Create( wxWindow
*           pParent
, 
  44                         const wxValidator
&  rValidator
, 
  45                         const wxString
&     rsName 
) 
  47     bool                            bRval 
= wxWindow::Create( pParent
 
  57         SetValidator(rValidator
); 
  61 } // end of wxControl::Create 
  63 wxControl::~wxControl() 
  65     m_isBeingDeleted 
= true; 
  68 bool wxControl::OS2CreateControl( const wxChar
* zClassname
, 
  69                                   const wxString
& rsLabel
, 
  75     WXDWORD dwStyle 
= OS2GetStyle( lStyle
, &dwExstyle 
); 
  77     return OS2CreateControl( zClassname
 
  84 } // end of wxControl::OS2CreateControl 
  86 bool wxControl::OS2CreateControl( const wxChar
*   zClassname
, 
  90                                   const wxString
& rsLabel
, 
  94     // Doesn't do anything at all under OS/2 
  96     if (dwExstyle 
== (WXDWORD
)-1) 
  99         (void) OS2GetStyle(GetWindowStyle(), &dwExstyle
); 
 102     // All controls should have these styles (wxWidgets creates all controls 
 103     // visible by default) 
 106         dwStyle 
|= WS_VISIBLE
; 
 108     wxWindow
* pParent 
= GetParent(); 
 114     if ((wxStrcmp(zClassname
, _T("COMBOBOX"))) == 0) 
 115         zClass 
= WC_COMBOBOX
; 
 116     else if ((wxStrcmp(zClassname
, _T("STATIC"))) == 0) 
 118     else if ((wxStrcmp(zClassname
, _T("BUTTON"))) == 0) 
 120     else if ((wxStrcmp(zClassname
, _T("NOTEBOOK"))) == 0) 
 121         zClass 
= WC_NOTEBOOK
; 
 122     else if ((wxStrcmp(zClassname
, _T("CONTAINER"))) == 0) 
 123         zClass 
= WC_CONTAINER
; 
 124     if ((zClass 
== WC_STATIC
) || (zClass 
== WC_BUTTON
)) 
 125         dwStyle 
|= DT_MNEMONIC
; 
 130     if (dwStyle 
& DT_MNEMONIC
) 
 131         label 
= ::wxPMTextToLabel(m_label
); 
 135     // clipping siblings does not yet work 
 136     dwStyle 
&= ~WS_CLIPSIBLINGS
; 
 138     m_hWnd 
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle 
 139                                        ,zClass              
// Window class 
 140                                        ,label
.c_str()       // Initial Text 
 141                                        ,(ULONG
)dwStyle           
// Style flags 
 142                                        ,(LONG
)0                  // X pos of origin 
 143                                        ,(LONG
)0                  // Y pos of origin 
 144                                        ,(LONG
)0                  // control width 
 145                                        ,(LONG
)0                  // control height 
 146                                        ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent 
 147                                        ,HWND_TOP                 
// initial z position 
 148                                        ,(ULONG
)GetId()           // Window identifier 
 149                                        ,NULL                     
// no control data 
 150                                        ,NULL                     
// no Presentation parameters 
 156         wxLogError(wxT("Failed to create a control of class '%s'"), zClassname
); 
 162     // Subclass again for purposes of dialog editing mode 
 167     // Controls use the same colours as their parent dialog by default 
 171     // All OS/2 ctrls use the small font 
 173     SetFont(*wxSMALL_FONT
); 
 177     SetSize( rPos
.x
, rPos
.y
, rSize
.x
, rSize
.y 
); 
 179 } // end of wxControl::OS2CreateControl 
 181 wxSize 
wxControl::DoGetBestSize() const 
 183     return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
); 
 184 } // end of wxControl::DoGetBestSize 
 186 bool wxControl::ProcessCommand(wxCommandEvent
& event
) 
 188     return HandleWindowEvent(event
); 
 191 WXHBRUSH 
wxControl::OnCtlColor(WXHDC    hWxDC
, 
 192                                WXHWND   
WXUNUSED(hWnd
), 
 193                                WXUINT   
WXUNUSED(uCtlColor
), 
 194                                WXUINT   
WXUNUSED(uMessage
), 
 195                                WXWPARAM 
WXUNUSED(wParam
), 
 196                                WXLPARAM 
WXUNUSED(lParam
)) 
 198     HPS      hPS 
= (HPS
)hWxDC
; // pass in a PS handle in OS/2 
 199     wxColour vColFore 
= GetForegroundColour(); 
 200     wxColour vColBack 
= GetBackgroundColour(); 
 202     if (GetParent()->GetTransparentBackground()) 
 203         ::GpiSetBackMix(hPS
, BM_LEAVEALONE
); 
 205         ::GpiSetBackMix(hPS
, BM_OVERPAINT
); 
 207     ::GpiSetBackColor(hPS
, vColBack
.GetPixel()); 
 208     ::GpiSetColor(hPS
, vColFore
.GetPixel()); 
 210     wxBrush
* pBrush 
= wxTheBrushList
->FindOrCreateBrush( vColBack
 
 213     return (WXHBRUSH
)pBrush
->GetResourceHandle(); 
 214 } // end of wxControl::OnCtlColor 
 216 void wxControl::OnEraseBackground( wxEraseEvent
& rEvent 
) 
 219     wxPMDCImpl                     
*impl 
= (wxPMDCImpl
*) rEvent
.GetDC()->GetImpl(); 
 220     HPS                             hPS 
= impl
->GetHPS(); 
 223     ::GpiSetPS(hPS
, &vSize
, PU_PELS 
| GPIF_DEFAULT
); 
 224     ::WinQueryWindowRect((HWND
)GetHwnd(), &vRect
); 
 225     ::WinFillRect(hPS
, &vRect
, GetBackgroundColour().GetPixel()); 
 226 } // end of wxControl::OnEraseBackground 
 228 WXDWORD 
wxControl::OS2GetStyle( long lStyle
, WXDWORD
* pdwExstyle 
) const 
 230     long dwStyle 
= wxWindow::OS2GetStyle( lStyle
, pdwExstyle 
); 
 232     if (AcceptsFocusFromKeyboard()) 
 234         dwStyle 
|= WS_TABSTOP
; 
 237 } // end of wxControl::OS2GetStyle 
 239 void wxControl::SetLabel( const wxString
& rsLabel 
) 
 241     if(rsLabel 
!= m_label
) 
 245         if (m_dwStyle 
& DT_MNEMONIC
) 
 246             label 
= ::wxPMTextToLabel(m_label
); 
 249         ::WinSetWindowText(GetHwnd(), label
.c_str()); 
 251 } // end of wxControl::SetLabel 
 253 // --------------------------------------------------------------------------- 
 255 // --------------------------------------------------------------------------- 
 257 // Call this repeatedly for several wnds to find the overall size 
 259 // Call it initially with -1 for all values in rect. 
 260 // Keep calling for other widgets, and rect will be modified 
 261 // to calculate largest bounding rectangle. 
 267     int                             nLeft 
= pRect
->xLeft
; 
 268     int                             nRight 
= pRect
->xRight
; 
 269     int                             nTop 
= pRect
->yTop
; 
 270     int                             nBottom 
= pRect
->yBottom
; 
 272     ::WinQueryWindowRect((HWND
)hWnd
, pRect
); 
 277     if (nLeft 
< pRect
->xLeft
) 
 278         pRect
->xLeft 
= nLeft
; 
 280     if (nRight 
> pRect
->xRight
) 
 281         pRect
->xRight 
= nRight
; 
 283     if (nTop 
> pRect
->yTop
) 
 286     if (nBottom 
< pRect
->yBottom
) 
 287         pRect
->yBottom 
= nBottom
; 
 288 } // end of wxFindMaxSize