]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/stattext.cpp
5b214b098733d69fb65e94d114d3ddd10298f114
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxStaticText 
   4 // Author:      David Webster 
   8 // Copyright:   (c) David Webster 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "stattext.h" 
  16 // For compilers that support precompilation, includes "wx.h". 
  17 #include "wx/wxprec.h" 
  25 #include "wx/stattext.h" 
  26 #include "wx/os2/private.h" 
  29 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
) 
  31 bool wxStaticText::Create( 
  34 , const wxString
&                   rsLabel
 
  38 , const wxString
&                   rsName
 
  43         pParent
->AddChild(this); 
  45     SetBackgroundColour(pParent
->GetBackgroundColour()) ; 
  46     SetForegroundColour(pParent
->GetForegroundColour()) ; 
  49         m_windowId 
= (int)NewControlId(); 
  56     int                             nHeight 
= rSize
.y
; 
  58     m_windowStyle 
= lStyle
; 
  62     lSstyle 
= WS_VISIBLE 
| SS_TEXT 
| DT_VCENTER
; 
  63     if (m_windowStyle 
& wxALIGN_CENTRE
) 
  65     else if (m_windowStyle 
& wxALIGN_RIGHT
) 
  70     // If the parent is a scrolled window the controls must 
  71     // have this style or they will overlap the scrollbars 
  74         if (pParent
->IsKindOf(CLASSINFO(wxScrolledWindow
)) || 
  75             pParent
->IsKindOf(CLASSINFO(wxGenericScrolledWindow
))) 
  76             lSstyle 
|= WS_CLIPSIBLINGS
; 
  78     m_hWnd 
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle 
  79                                        ,WC_STATIC                
// Window class 
  80                                        ,(PSZ
)rsLabel
.c_str()     // Initial Text 
  81                                        ,(ULONG
)lSstyle           
// Style flags 
  82                                        ,0L, 0L, 0L, 0L           // Origin -- 0 size 
  83                                        ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent 
  84                                        ,HWND_TOP                 
// initial z position 
  85                                        ,(ULONG
)m_windowId        
// Window identifier 
  86                                        ,NULL                     
// no control data 
  87                                        ,NULL                     
// no Presentation parameters 
  90     wxCHECK_MSG(m_hWnd
, FALSE
, wxT("Failed to create static ctrl")); 
  94     vColour
.Set(wxString("BLACK")); 
  96     LONG                            lColor 
= (LONG
)vColour
.GetPixel(); 
  98     ::WinSetPresParam( m_hWnd
 
 103     lColor 
= (LONG
)m_backgroundColour
.GetPixel(); 
 105     ::WinSetPresParam( m_hWnd
 
 112     wxControl::SetFont(pParent
->GetFont()); 
 119 } // end of wxStaticText::Create 
 121 wxSize 
wxStaticText::DoGetBestSize() const 
 123     wxString                        
sText(wxGetWindowText(GetHWND())); 
 124     int                             nWidthTextMax 
= 0; 
 126     int                             nHeightTextTotal 
= 0; 
 127     int                             nHeightLineDefault 
= 0; 
 131     for (const wxChar 
*pc 
= sText
; ; pc
++) 
 133         if ( *pc 
== wxT('\n') || *pc 
== wxT('\0') ) 
 138                 // We can't use GetTextExtent - it will return 0 for both width 
 139                 // and height and an empty line should count in height 
 142                 if (!nHeightLineDefault
) 
 143                     nHeightLineDefault 
= nHeightLine
; 
 144                 if (!nHeightLineDefault
) 
 145                     GetTextExtent(_T("W"), NULL
, &nHeightLineDefault
); 
 146                 nHeightTextTotal 
+= nHeightLineDefault
; 
 150                 GetTextExtent( sCurLine
 
 154                 if (nWidthLine 
> nWidthTextMax
) 
 155                     nWidthTextMax 
= nWidthLine
; 
 156                 nHeightTextTotal 
+= nHeightLine
; 
 159             if ( *pc 
== wxT('\n') ) 
 173     return wxSize( nWidthTextMax
 
 176 } // end of wxStaticText::DoGetBestSize 
 178 void wxStaticText::DoSetSize( 
 187     // We need to refresh the window after changing its size as the standard 
 188     // control doesn't always update itself properly. 
 190     wxStaticTextBase::DoSetSize( nX
 
 197 } // end of wxStaticText::DoSetSize 
 199 bool wxStaticText::SetFont( 
 203     bool                            bRet 
= wxControl::SetFont(rFont
); 
 206     // Adjust the size of the window to fit to the label unless autoresizing is 
 209     if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) ) 
 211         DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH 
| wxSIZE_AUTO_HEIGHT
); 
 214 } // end of wxStaticText::SetFont 
 216 void wxStaticText::SetLabel( 
 217   const wxString
&                   rsLabel
 
 220     ::WinSetWindowText(GetHwnd(), rsLabel
.c_str()); 
 223     // Adjust the size of the window to fit to the label unless autoresizing is 
 226     if (!(GetWindowStyle() & wxST_NO_AUTORESIZE
)) 
 228         DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH 
| wxSIZE_AUTO_HEIGHT
); 
 230     DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH 
| wxSIZE_AUTO_HEIGHT
); 
 231 } // end of wxStaticText::SetLabel 
 233 MRESULT 
wxStaticText::OS2WindowProc( 
 239     return wxWindow::OS2WindowProc( uMsg
 
 243 } // end of wxStaticText::OS2WindowProc