]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/stattext.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/os2/stattext.cpp 
   3 // Purpose:     wxStaticText 
   4 // Author:      David Webster 
   8 // Copyright:   (c) David Webster 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  15 #include "wx/stattext.h" 
  21     #include "wx/scrolwin.h" 
  24 #include "wx/os2/private.h" 
  27 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
) 
  29 bool wxStaticText::Create( wxWindow
*        pParent
, 
  31                            const wxString
&  rsLabel
, 
  35                            const wxString
&  rsName 
) 
  39         pParent
->AddChild(this); 
  41     SetBackgroundColour(pParent
->GetBackgroundColour()) ; 
  42     SetForegroundColour(pParent
->GetForegroundColour()) ; 
  44     if ( vId 
== wxID_ANY 
) 
  45         m_windowId 
= (int)NewControlId(); 
  52     int nHeight 
= rSize
.y
; 
  54     m_windowStyle 
= lStyle
; 
  58     // Used to have DT_VCENTER but that doesn't work correctly with 
  59     // multiline strings and DT_WORDBREAK. Accept a reasonable 
  61     lSstyle 
= WS_VISIBLE 
| SS_TEXT 
| DT_WORDBREAK 
| DT_MNEMONIC
; 
  62     if (m_windowStyle 
& wxALIGN_CENTRE
) 
  64     else if (m_windowStyle 
& wxALIGN_RIGHT
) 
  69     m_hWnd 
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle 
  70                                        ,WC_STATIC                
// Window class 
  72                                        ,(ULONG
)lSstyle           
// Style flags 
  73                                        ,0L, 0L, 0L, 0L           // Origin -- 0 size 
  74                                        ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent 
  75                                        ,HWND_TOP                 
// initial z position 
  76                                        ,(ULONG
)m_windowId        
// Window identifier 
  77                                        ,NULL                     
// no control data 
  78                                        ,NULL                     
// no Presentation parameters 
  81     wxCHECK_MSG(m_hWnd
, false, wxT("Failed to create static ctrl")); 
  83     LONG lColor 
= (LONG
)wxBLACK
->GetPixel(); 
  85     ::WinSetPresParam( m_hWnd
 
  90     lColor 
= (LONG
)m_backgroundColour
.GetPixel(); 
  92     ::WinSetPresParam( m_hWnd
 
  99     SetFont(*wxSMALL_FONT
); 
 102     SetSize( nX
, nY
, nWidth
, nHeight 
); 
 107 } // end of wxStaticText::Create 
 109 wxSize 
wxStaticText::DoGetBestSize() const 
 111     wxString 
sText(GetLabel()); 
 112     int      nWidthTextMax 
= 0; 
 114     int      nHeightTextTotal 
= 0; 
 115     int      nHeightLineDefault 
= 0; 
 118     bool     bLastWasTilde 
= false; 
 120     for (const wxChar 
*pc 
= sText
; ; pc
++) 
 122         if ( *pc 
== wxT('\n') || *pc 
== wxT('\0') ) 
 127                 // We can't use GetTextExtent - it will return 0 for both width 
 128                 // and height and an empty line should count in height 
 131                 if (!nHeightLineDefault
) 
 132                     nHeightLineDefault 
= nHeightLine
; 
 133                 if (!nHeightLineDefault
) 
 134                     GetTextExtent(wxT("W"), NULL
, &nHeightLineDefault
); 
 135                 nHeightTextTotal 
+= nHeightLineDefault
; 
 139                 GetTextExtent( sCurLine
 
 143                 if (nWidthLine 
> nWidthTextMax
) 
 144                     nWidthTextMax 
= nWidthLine
; 
 145                 nHeightTextTotal 
+= nHeightLine
; 
 148             if ( *pc 
== wxT('\n') ) 
 160             // We shouldn't take into account the '~' which just introduces the 
 161             // mnemonic characters and so are not shown on the screen -- except 
 162             // when it is preceded by another '~' in which case it stands for a 
 169                     bLastWasTilde 
= true; 
 172                     // Skip the statement adding pc to curLine below 
 178                 // It is a literal tilde 
 180                 bLastWasTilde 
= false; 
 185     return wxSize( nWidthTextMax
 
 188 } // end of wxStaticText::DoGetBestSize 
 190 void wxStaticText::DoSetSize( 
 199     // We need to refresh the window after changing its size as the standard 
 200     // control doesn't always update itself properly. 
 202     wxStaticTextBase::DoSetSize( nX
 
 209     // eventually update label (if ellipsizing is on): 
 213 } // end of wxStaticText::DoSetSize 
 215 bool wxStaticText::SetFont( 
 219     bool                            bRet 
= wxControl::SetFont(rFont
); 
 222     // Adjust the size of the window to fit to the label unless autoresizing is 
 225     if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) ) 
 227         DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH 
| wxSIZE_AUTO_HEIGHT
); 
 230 } // end of wxStaticText::SetFont 
 232 void wxStaticText::SetLabel( 
 233   const wxString
&                   rsLabel
 
 236     m_labelOrig 
= rsLabel
;       // save original label 
 238     // OS/2 does not support neither ellipsize nor markup in static text: 
 240     DoSetLabel(GetEllipsizedLabelWithoutMarkup()); 
 243     // Adjust the size of the window to fit to the label unless autoresizing is 
 246     if (!(GetWindowStyle() & wxST_NO_AUTORESIZE
) && 
 254         GetPosition(&vX
, &vY
); 
 255         GetSize(&vWidth
, &vHeight
); 
 256         if (!(vX 
== -1 && vY 
== -1 && vWidth 
== -1 && vHeight 
== -1)) 
 257             DoSetSize(vX
, vY
, vWidth
, vHeight
, wxSIZE_AUTO_WIDTH 
| wxSIZE_AUTO_HEIGHT
); 
 259             DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH 
| wxSIZE_AUTO_HEIGHT
); 
 261 } // end of wxStaticText::SetLabel 
 263 MRESULT 
wxStaticText::OS2WindowProc( 
 269     return wxWindow::OS2WindowProc( uMsg
 
 273 } // end of wxStaticText::OS2WindowProc 
 276 // for wxST_ELLIPSIZE_* support: 
 278 void wxStaticText::DoSetLabel(const wxString
& str
) 
 280     wxString sLabel 
= ::wxPMTextToLabel(str
); 
 281     ::WinSetWindowText(GetHwnd(), sLabel
.c_str()); 
 284 wxString 
wxStaticText::DoGetLabel() const 
 286     return wxGetWindowText(GetHwnd());