]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/stattext.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/msw/stattext.cpp 
   3 // Purpose:     wxStaticText 
   4 // Author:      Julian Smart 
   8 // Copyright:   (c) Julian Smart 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  21 #include "wx/stattext.h" 
  27     #include "wx/dcclient.h" 
  28     #include "wx/settings.h" 
  31 #include "wx/msw/private.h" 
  33 #if wxUSE_EXTENDED_RTTI 
  34 WX_DEFINE_FLAGS( wxStaticTextStyle 
) 
  36 wxBEGIN_FLAGS( wxStaticTextStyle 
) 
  37     // new style border flags, we put them first to 
  38     // use them for streaming out 
  39     wxFLAGS_MEMBER(wxBORDER_SIMPLE
) 
  40     wxFLAGS_MEMBER(wxBORDER_SUNKEN
) 
  41     wxFLAGS_MEMBER(wxBORDER_DOUBLE
) 
  42     wxFLAGS_MEMBER(wxBORDER_RAISED
) 
  43     wxFLAGS_MEMBER(wxBORDER_STATIC
) 
  44     wxFLAGS_MEMBER(wxBORDER_NONE
) 
  46     // old style border flags 
  47     wxFLAGS_MEMBER(wxSIMPLE_BORDER
) 
  48     wxFLAGS_MEMBER(wxSUNKEN_BORDER
) 
  49     wxFLAGS_MEMBER(wxDOUBLE_BORDER
) 
  50     wxFLAGS_MEMBER(wxRAISED_BORDER
) 
  51     wxFLAGS_MEMBER(wxSTATIC_BORDER
) 
  52     wxFLAGS_MEMBER(wxBORDER
) 
  54     // standard window styles 
  55     wxFLAGS_MEMBER(wxTAB_TRAVERSAL
) 
  56     wxFLAGS_MEMBER(wxCLIP_CHILDREN
) 
  57     wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
) 
  58     wxFLAGS_MEMBER(wxWANTS_CHARS
) 
  59     wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
) 
  60     wxFLAGS_MEMBER(wxALWAYS_SHOW_SB 
) 
  61     wxFLAGS_MEMBER(wxVSCROLL
) 
  62     wxFLAGS_MEMBER(wxHSCROLL
) 
  64     wxFLAGS_MEMBER(wxST_NO_AUTORESIZE
) 
  65     wxFLAGS_MEMBER(wxALIGN_LEFT
) 
  66     wxFLAGS_MEMBER(wxALIGN_RIGHT
) 
  67     wxFLAGS_MEMBER(wxALIGN_CENTRE
) 
  69 wxEND_FLAGS( wxStaticTextStyle 
) 
  71 IMPLEMENT_DYNAMIC_CLASS_XTI(wxStaticText
, wxControl
,"wx/stattext.h") 
  73 wxBEGIN_PROPERTIES_TABLE(wxStaticText
) 
  74     wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) 
  75     wxPROPERTY_FLAGS( WindowStyle 
, wxStaticTextStyle 
, long , SetWindowStyleFlag 
, GetWindowStyleFlag 
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style 
  76 wxEND_PROPERTIES_TABLE() 
  78 wxBEGIN_HANDLERS_TABLE(wxStaticText
) 
  79 wxEND_HANDLERS_TABLE() 
  81 wxCONSTRUCTOR_6( wxStaticText 
, wxWindow
* , Parent 
, wxWindowID 
, Id 
, wxString 
, Label 
, wxPoint 
, Position 
, wxSize 
, Size 
, long , WindowStyle 
) 
  83 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
) 
  86 bool wxStaticText::Create(wxWindow 
*parent
, 
  88                           const wxString
& label
, 
  94     if ( !CreateControl(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) ) 
  97     if ( !MSWCreateControl(wxT("STATIC"), label
, pos
, size
) ) 
 103 wxBorder 
wxStaticText::GetDefaultBorder() const 
 105     return wxBORDER_NONE
; 
 108 WXDWORD 
wxStaticText::MSWGetStyle(long style
, WXDWORD 
*exstyle
) const 
 110     WXDWORD msStyle 
= wxControl::MSWGetStyle(style
, exstyle
); 
 112     // translate the alignment flags to the Windows ones 
 114     // note that both wxALIGN_LEFT and SS_LEFT are equal to 0 so we shouldn't 
 115     // test for them using & operator 
 116     if ( style 
& wxALIGN_CENTRE 
) 
 117         msStyle 
|= SS_CENTER
; 
 118     else if ( style 
& wxALIGN_RIGHT 
) 
 123     // this style is necessary to receive mouse events 
 124     msStyle 
|= SS_NOTIFY
; 
 129 wxSize 
wxStaticText::DoGetBestSize() const 
 131     wxClientDC 
dc(wx_const_cast(wxStaticText 
*, this)); 
 132     wxFont 
font(GetFont()); 
 134         font 
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
); 
 138     wxCoord widthTextMax
, heightTextTotal
; 
 139     dc
.GetMultiLineTextExtent(::wxStripMenuCodes(GetLabel()), 
 140         &widthTextMax
, &heightTextTotal
); 
 145 #endif // __WXWINCE__ 
 147     // border takes extra space 
 149     // TODO: this is probably not wxStaticText-specific and should be moved 
 151     switch ( GetBorder() ) 
 153         case wxBORDER_STATIC
: 
 154         case wxBORDER_SIMPLE
: 
 158         case wxBORDER_SUNKEN
: 
 162         case wxBORDER_RAISED
: 
 163         case wxBORDER_DOUBLE
: 
 168             wxFAIL_MSG( _T("unknown border style") ); 
 175     widthTextMax 
+= 2*border
; 
 176     heightTextTotal 
+= 2*border
; 
 178     wxSize 
best(widthTextMax
, heightTextTotal
); 
 183 void wxStaticText::DoSetSize(int x
, int y
, int w
, int h
, int sizeFlags
) 
 185     // we need to refresh the window after changing its size as the standard 
 186     // control doesn't always update itself properly 
 187     wxStaticTextBase::DoSetSize(x
, y
, w
, h
, sizeFlags
); 
 192 void wxStaticText::SetLabel(const wxString
& label
) 
 194     wxStaticTextBase::SetLabel(label
); 
 196     // adjust the size of the window to fit to the label unless autoresizing is 
 198     if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) ) 
 200         InvalidateBestSize(); 
 201         DoSetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, 
 202                   wxSIZE_AUTO_WIDTH 
| wxSIZE_AUTO_HEIGHT
); 
 207 bool wxStaticText::SetFont(const wxFont
& font
) 
 209     bool ret 
= wxControl::SetFont(font
); 
 211     // adjust the size of the window to fit to the label unless autoresizing is 
 213     if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) ) 
 215         InvalidateBestSize(); 
 216         DoSetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, 
 217                   wxSIZE_AUTO_WIDTH 
| wxSIZE_AUTO_HEIGHT
); 
 223 #endif // wxUSE_STATTEXT