]>
git.saurik.com Git - wxWidgets.git/blob - src/qt/stattext.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxStaticText 
   8 // Copyright:   (c) AUTHOR 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "stattext.h" 
  16 // For compilers that support precompilation, includes "wx.h". 
  17 #include "wx/wxprec.h" 
  27 #include "wx/stattext.h" 
  28 #include "wx/msw/private.h" 
  31 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
) 
  33 bool wxStaticText::Create(wxWindow 
*parent
, wxWindowID id
, 
  34            const wxString
& label
, 
  41   if (parent
) parent
->AddChild(this); 
  43   SetBackgroundColour(parent
->GetDefaultBackgroundColour()) ; 
  44   SetForegroundColour(parent
->GetDefaultForegroundColour()) ; 
  47         m_windowId 
= (int)NewControlId(); 
  56   m_windowStyle 
= style
; 
  58   long msStyle 
= WS_CHILD
|WS_VISIBLE
; 
  59   if (m_windowStyle 
& wxALIGN_CENTRE
) 
  61   else if (m_windowStyle 
& wxALIGN_RIGHT
) 
  66   // Even with extended styles, need to combine with WS_BORDER 
  67   // for them to look right. 
  68   if ((m_windowStyle 
& wxSIMPLE_BORDER
) || (m_windowStyle 
& wxRAISED_BORDER
) || 
  69        (m_windowStyle 
& wxSUNKEN_BORDER
) || (m_windowStyle 
& wxDOUBLE_BORDER
)) 
  72   HWND static_item 
= CreateWindowEx(MakeExtendedStyle(m_windowStyle
), "STATIC", (const char *)label
, 
  74                          0, 0, 0, 0, (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
, 
  75                          wxGetInstance(), NULL
); 
  79   if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS)) 
  80     Ctl3dSubclassCtl(static_item); 
  84   m_hWnd 
= (WXHWND
)static_item
; 
  86   SubclassWin((WXHWND
)static_item
); 
  88   SetFont(* parent
->GetFont()); 
  89   SetSize(x
, y
, width
, height
); 
  93 void wxStaticText::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
) 
  95   int currentX
, currentY
; 
  96   GetPosition(¤tX
, ¤tY
); 
 100   if (x 
== -1 || (sizeFlags 
& wxSIZE_ALLOW_MINUS_ONE
)) 
 102   if (y 
== -1 || (sizeFlags 
& wxSIZE_ALLOW_MINUS_ONE
)) 
 105   AdjustForParentClientOrigin(x1
, y1
, sizeFlags
); 
 107   int actualWidth 
= width
; 
 108   int actualHeight 
= height
; 
 114   ::GetWindowText((HWND
) GetHWND(), buf
, 300); 
 115   GetTextExtent(buf
, ¤t_width
, &cyf
, NULL
, NULL
,GetFont()); 
 120   // If we're prepared to use the existing width, then... 
 121   if (width 
== -1 && ((sizeFlags 
& wxSIZE_AUTO_WIDTH
) != wxSIZE_AUTO_WIDTH
)) 
 123   else if (width 
== -1) 
 127     wxGetCharSize(GetHWND(), &cx
, &cy
,GetFont()); 
 128     actualWidth 
= (int)(current_width 
+ cx
) ; 
 131   // If we're prepared to use the existing height, then... 
 132   if (height 
== -1 && ((sizeFlags 
& wxSIZE_AUTO_HEIGHT
) != wxSIZE_AUTO_HEIGHT
)) 
 134   else if (height 
== -1) 
 136     actualHeight 
= (int)(cyf
) ; 
 139   MoveWindow((HWND
) GetHWND(), x1
, y1
, actualWidth
, actualHeight
, TRUE
); 
 142 void wxStaticText::SetLabel(const wxString
& label
) 
 147   wxWindow 
*parent 
= GetParent(); 
 148   GetWindowRect((HWND
) GetHWND(), &rect
); 
 150   // Since we now have the absolute screen coords, 
 151   // if there's a parent we must subtract its top left corner 
 157     ::ScreenToClient((HWND
) parent
->GetHWND(), &point
); 
 160   GetTextExtent(label
, &w
, &h
, NULL
, NULL
, GetFont()); 
 161   MoveWindow((HWND
) GetHWND(), point
.x
, point
.y
, (int)(w 
+ 10), (int)h
, 
 163   SetWindowText((HWND
) GetHWND(), (const char *)label
); 
 166 WXHBRUSH 
wxStaticText::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
, 
 167                         WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
) 
 173     HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam); 
 175     if (hbrush != (HBRUSH) 0) 
 178       return (HBRUSH)MSWDefWindowProc(message, wParam, lParam); 
 183   if (GetParent()->GetTransparentBackground()) 
 184     SetBkMode((HDC
) pDC
, TRANSPARENT
); 
 186     SetBkMode((HDC
) pDC
, OPAQUE
); 
 188   ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); 
 189   ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue())); 
 191   wxBrush 
*backgroundBrush 
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
); 
 193   // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush 
 194   // has a zero usage count. 
 195 //  backgroundBrush->RealizeResource(); 
 196   return (WXHBRUSH
) backgroundBrush
->GetResourceHandle(); 
 199 long wxStaticText::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
) 
 201   // Ensure that static items get messages. Some controls don't like this 
 202   // message to be intercepted (e.g. RichEdit), hence the tests. 
 203   if (nMsg 
== WM_NCHITTEST
) 
 204     return (long)HTCLIENT
; 
 206   return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);