| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: stattext.cpp |
| 3 | // Purpose: wxStaticText |
| 4 | // Author: David Webster |
| 5 | // Modified by: |
| 6 | // Created: 10/17/99 |
| 7 | // RCS-ID: $Id$ |
| 8 | // Copyright: (c) David Webster |
| 9 | // Licence: wxWindows licence |
| 10 | ///////////////////////////////////////////////////////////////////////////// |
| 11 | |
| 12 | #ifdef __GNUG__ |
| 13 | #pragma implementation "stattext.h" |
| 14 | #endif |
| 15 | |
| 16 | // For compilers that support precompilation, includes "wx.h". |
| 17 | #include "wx/wxprec.h" |
| 18 | |
| 19 | #ifndef WX_PRECOMP |
| 20 | #include "wx/event.h" |
| 21 | #include "wx/app.h" |
| 22 | #include "wx/brush.h" |
| 23 | #endif |
| 24 | |
| 25 | #include "wx/stattext.h" |
| 26 | #include "wx/os2/private.h" |
| 27 | #include <stdio.h> |
| 28 | |
| 29 | IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl) |
| 30 | |
| 31 | bool wxStaticText::Create(wxWindow *parent, wxWindowID id, |
| 32 | const wxString& label, |
| 33 | const wxPoint& pos, |
| 34 | const wxSize& size, |
| 35 | long style, |
| 36 | const wxString& name) |
| 37 | { |
| 38 | SetName(name); |
| 39 | if (parent) parent->AddChild(this); |
| 40 | |
| 41 | SetBackgroundColour(parent->GetBackgroundColour()) ; |
| 42 | SetForegroundColour(parent->GetForegroundColour()) ; |
| 43 | |
| 44 | if ( id == -1 ) |
| 45 | m_windowId = (int)NewControlId(); |
| 46 | else |
| 47 | m_windowId = id; |
| 48 | |
| 49 | int x = pos.x; |
| 50 | int y = pos.y; |
| 51 | int width = size.x; |
| 52 | int height = size.y; |
| 53 | |
| 54 | m_windowStyle = style; |
| 55 | |
| 56 | // TODO |
| 57 | SubclassWin(m_hWnd); |
| 58 | |
| 59 | SetFont(parent->GetFont()); |
| 60 | SetSize(x, y, width, height); |
| 61 | |
| 62 | return FALSE; |
| 63 | } |
| 64 | |
| 65 | wxSize wxStaticText::DoGetBestSize() const |
| 66 | { |
| 67 | wxString text(wxGetWindowText(GetHWND())); |
| 68 | |
| 69 | int widthTextMax = 0, widthLine, |
| 70 | heightTextTotal = 0, heightLineDefault = 0, heightLine = 0; |
| 71 | |
| 72 | wxString curLine; |
| 73 | for ( const wxChar *pc = text; ; pc++ ) { |
| 74 | if ( *pc == wxT('\n') || *pc == wxT('\0') ) { |
| 75 | if ( !curLine ) { |
| 76 | // we can't use GetTextExtent - it will return 0 for both width |
| 77 | // and height and an empty line should count in height |
| 78 | // calculation |
| 79 | if ( !heightLineDefault ) |
| 80 | heightLineDefault = heightLine; |
| 81 | if ( !heightLineDefault ) |
| 82 | GetTextExtent(_T("W"), NULL, &heightLineDefault); |
| 83 | |
| 84 | heightTextTotal += heightLineDefault; |
| 85 | } |
| 86 | else { |
| 87 | GetTextExtent(curLine, &widthLine, &heightLine); |
| 88 | if ( widthLine > widthTextMax ) |
| 89 | widthTextMax = widthLine; |
| 90 | heightTextTotal += heightLine; |
| 91 | } |
| 92 | |
| 93 | if ( *pc == wxT('\n') ) { |
| 94 | curLine.Empty(); |
| 95 | } |
| 96 | else { |
| 97 | // the end of string |
| 98 | break; |
| 99 | } |
| 100 | } |
| 101 | else { |
| 102 | curLine += *pc; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | return wxSize(widthTextMax, heightTextTotal); |
| 107 | } |
| 108 | |
| 109 | void wxStaticText::SetLabel(const wxString& label) |
| 110 | { |
| 111 | // TODO |
| 112 | |
| 113 | // adjust the size of the window to fit to the label (this behaviour is |
| 114 | // backward compatible and generally makes sense but we might want to still |
| 115 | // provide the user a way to disable it) (VZ) |
| 116 | DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT); |
| 117 | } |
| 118 | |
| 119 | WXHBRUSH wxStaticText::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, |
| 120 | WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
| 121 | { |
| 122 | // TODO: |
| 123 | /* |
| 124 | if (GetParent()->GetTransparentBackground()) |
| 125 | SetBkMode((HDC) pDC, TRANSPARENT); |
| 126 | else |
| 127 | SetBkMode((HDC) pDC, OPAQUE); |
| 128 | |
| 129 | ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); |
| 130 | ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue())); |
| 131 | |
| 132 | wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID); |
| 133 | // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush |
| 134 | // has a zero usage count. |
| 135 | // backgroundBrush->RealizeResource(); |
| 136 | return (WXHBRUSH) backgroundBrush->GetResourceHandle(); |
| 137 | */ |
| 138 | return (WXHBRUSH)0; |
| 139 | } |
| 140 | |
| 141 | MRESULT wxStaticText::OS2WindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) |
| 142 | { |
| 143 | // Ensure that static items get messages. Some controls don't like this |
| 144 | // message to be intercepted (e.g. RichEdit), hence the tests. |
| 145 | // TODO: |
| 146 | /* |
| 147 | if (nMsg == WM_NCHITTEST) |
| 148 | return (long)HTCLIENT; |
| 149 | */ |
| 150 | return wxWindow::OS2WindowProc(nMsg, wParam, lParam); |
| 151 | } |
| 152 | |