]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/control.cpp
3ed6d787a06b4a06557ccda762420ac9f962899b
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxControl class 
   4 // Author:      David Webster 
   8 // Copyright:   (c) Julian Smart and Markus Holzem 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "control.h" 
  16 // For compilers that support precompilation, includes "wx.h". 
  17 #include "wx/wxprec.h" 
  22 #include "wx/dcclient.h" 
  23 #include "wx/scrolwin.h" 
  25 #include "wx/os2/private.h" 
  26 #include "wx/control.h" 
  28 IMPLEMENT_ABSTRACT_CLASS(wxControl
, wxWindow
) 
  30 BEGIN_EVENT_TABLE(wxControl
, wxWindow
) 
  31     EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground
) 
  35 wxControl::wxControl() 
  38 #if WXWIN_COMPATIBILITY 
  40 #endif // WXWIN_COMPATIBILITY 
  41 } // end of wxControl::wxControl 
  43 bool wxControl::Create( 
  50 , const wxValidator
&                rValidator
 
  52 , const wxString
&                   rsName
 
  55     bool                            bRval 
= wxWindow::Create( pParent
 
  65         SetValidator(rValidator
); 
  69 } // end of wxControl::Create 
  71 wxControl::~wxControl() 
  73     m_isBeingDeleted 
= TRUE
; 
  76 bool wxControl::OS2CreateControl( 
  83 , const wxValidator
&                rValidator
 
  85 , const wxString
&                   rsName
 
  89     // Even if it's possible to create controls without parents in some port, 
  90     // it should surely be discouraged because it doesn't work at all under 
  93     if (!CreateBase( pParent
 
 104     pParent
->AddChild(this); 
 106 } // end of wxControl::OS2CreateControl 
 108 bool wxControl::OS2CreateControl( 
 109   const wxChar
*                     zClassname
 
 111 , const wxPoint
&                    rPos
 
 112 , const wxSize
&                     rSize
 
 113 , const wxString
&                   rsLabel
 
 117     int                          nX 
= rPos
.x 
== -1 ? 0 : rPos
.x
; 
 118     int                          nY 
= rPos
.y 
== -1 ? 0 : rPos
.y
; 
 119     int                          nW 
= rSize
.x 
== -1 ? 0 : rSize
.x
; 
 120     int                          nH 
= rSize
.y 
== -1 ? 0 : rSize
.y
; 
 122     // Doesn't do anything at all under OS/2 
 124     if (dwExstyle 
== (WXDWORD
)-1) 
 126         dwExstyle 
= GetExStyle(dwStyle
); 
 129     wxWindow
*                       pParent 
= GetParent(); 
 135     if ((strcmp(zClassname
, "COMBOBOX")) == 0) 
 136         zClass 
= WC_COMBOBOX
; 
 137     else if ((strcmp(zClassname
, "STATIC")) == 0) 
 139     else if ((strcmp(zClassname
, "BUTTON")) == 0) 
 141     dwStyle 
|= WS_VISIBLE
; 
 143     m_hWnd 
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle 
 144                                        ,(PSZ
)zClass              
// Window class 
 145                                        ,(PSZ
)rsLabel
.c_str()     // Initial Text 
 146                                        ,(ULONG
)dwStyle           
// Style flags 
 147                                        ,(LONG
)0                  // X pos of origin 
 148                                        ,(LONG
)0                  // Y pos of origin 
 149                                        ,(LONG
)0                  // control width 
 150                                        ,(LONG
)0                  // control height 
 151                                        ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent 
 152                                        ,HWND_TOP                 
// initial z position 
 153                                        ,(ULONG
)GetId()           // Window identifier 
 154                                        ,NULL                     
// no control data 
 155                                        ,NULL                     
// no Presentation parameters 
 161         wxLogError(wxT("Failed to create a control of class '%s'"), zClassname
); 
 167     // Subclass again for purposes of dialog editing mode 
 172     // Controls use the same font and colours as their parent dialog by default 
 175     if (nW 
== 0 || nH 
== 0) 
 178 } // end of wxControl::OS2CreateControl 
 180 wxSize 
wxControl::DoGetBestSize() const 
 182     return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
); 
 183 } // end of wxControl::DoGetBestSize 
 185 bool wxControl::ProcessCommand(wxCommandEvent
& event
) 
 187 #if WXWIN_COMPATIBILITY 
 190         (void)(*m_callback
)(this, event
); 
 195 #endif // WXWIN_COMPATIBILITY 
 197     return GetEventHandler()->ProcessEvent(event
); 
 200 WXHBRUSH 
wxControl::OnCtlColor( 
 209     HPS                             hPS 
= (HPS
)hWxDC
; // pass in a PS handle in OS/2 
 210     wxColour                        vColFore 
= GetForegroundColour(); 
 211     wxColour                        vColBack 
= GetBackgroundColour(); 
 213     if (GetParent()->GetTransparentBackground()) 
 214         ::GpiSetBackMix(hPS
, BM_LEAVEALONE
); 
 216         ::GpiSetBackMix(hPS
, BM_OVERPAINT
); 
 218     ::GpiSetBackColor(hPS
, vColBack
.GetPixel()); 
 219     ::GpiSetColor(hPS
, vColFore
.GetPixel()); 
 221     wxBrush
*                        pBrush 
= wxTheBrushList
->FindOrCreateBrush( vColBack
 
 224     return (WXHBRUSH
)pBrush
->GetResourceHandle(); 
 225 } // end of wxControl::OnCtlColor 
 227 void wxControl::OnEraseBackground( 
 232     HPS                             hPS 
= rEvent
.GetDC()->GetHPS(); 
 235     ::GpiSetPS(hPS
, &vSize
, PU_PELS 
| GPIF_DEFAULT
); 
 236     ::WinQueryWindowRect((HWND
)GetHwnd(), &vRect
); 
 237     ::WinFillRect(hPS
, &vRect
, GetBackgroundColour().GetPixel()); 
 238 } // end of wxControl::OnEraseBackground 
 240 WXDWORD 
wxControl::GetExStyle( 
 245     // Meaningless under OS/2, just return what was sent 
 247     WXDWORD                         exStyle 
= rStyle
; 
 250 } // end of wxControl::GetExStyle 
 252 // --------------------------------------------------------------------------- 
 254 // --------------------------------------------------------------------------- 
 256 // Call this repeatedly for several wnds to find the overall size 
 258 // Call it initially with -1 for all values in rect. 
 259 // Keep calling for other widgets, and rect will be modified 
 260 // to calculate largest bounding rectangle. 
 266     int                             nLeft 
= pRect
->xLeft
; 
 267     int                             nRight 
= pRect
->xRight
; 
 268     int                             nTop 
= pRect
->yTop
; 
 269     int                             nBottom 
= pRect
->yBottom
; 
 271     ::WinQueryWindowRect((HWND
)hWnd
, pRect
); 
 276     if (nLeft 
< pRect
->xLeft
) 
 277         pRect
->xLeft 
= nLeft
; 
 279     if (nRight 
> pRect
->xRight
) 
 280         pRect
->xRight 
= nRight
; 
 282     if (nTop 
< pRect
->yTop
) 
 285     if (nBottom 
> pRect
->yBottom
) 
 286         pRect
->yBottom 
= nBottom
; 
 287 } // end of wxFindMaxSize