Static Box coded.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9768 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
David Webster
2001-04-16 22:24:55 +00:00
parent ca8f0290a4
commit 1f3154c809

View File

@@ -28,125 +28,165 @@
IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl) IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
bool wxStaticText::Create(wxWindow *parent, wxWindowID id, bool wxStaticText::Create(
const wxString& label, wxWindow* pParent
const wxPoint& pos, , wxWindowID vId
const wxSize& size, , const wxString& rsLabel
long style, , const wxPoint& rPos
const wxString& name) , const wxSize& rSize
, long lStyle
, const wxString& rsName
)
{ {
SetName(name); SetName(rsName);
if (parent) parent->AddChild(this); if (pParent)
pParent->AddChild(this);
SetBackgroundColour(parent->GetBackgroundColour()) ; SetBackgroundColour(pParent->GetBackgroundColour()) ;
SetForegroundColour(parent->GetForegroundColour()) ; SetForegroundColour(pParent->GetForegroundColour()) ;
if ( id == -1 ) if ( id == -1 )
m_windowId = (int)NewControlId(); m_windowId = (int)NewControlId();
else else
m_windowId = id; m_windowId = vId;
int x = pos.x; int nX = rPos.x;
int y = pos.y; int nY = rPos.y;
int width = size.x; int nWidth = rSize.x;
int height = size.y; int nHeight = rSize.y;
m_windowStyle = style; m_windowStyle = lStyle;
long lSstyle = 0L;
lSstyle = WS_VISIBLE | SS_TEXT | DT_VCENTER;
if (m_windowStyle & wxALIGN_CENTRE)
lSstyle |= DT_CENTER;
else if (m_windowStyle & wxALIGN_RIGHT)
lSstyle |= DT_RIGHT;
else
lSstyle |= DT_LEFT;
m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
,WC_STATIC // Window class
,(PSZ)rsLabel.c_str() // Initial Text
,(ULONG)lSstyle // Style flags
,0L, 0L, 0L, 0L // Origin -- 0 size
,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
,HWND_TOP // initial z position
,(ULONG)m_windowId // Window identifier
,NULL // no control data
,NULL // no Presentation parameters
);
wxCHECK_MSG(m_hWnd, FALSE, wxT("Failed to create static ctrl"));
// TODO
SubclassWin(m_hWnd); SubclassWin(m_hWnd);
wxControl::SetFont(pParent->GetFont());
SetFont(parent->GetFont()); SetSize(nX, nY, nWidth, nHeight);
SetSize(x, y, width, height);
return FALSE; return FALSE;
} } // end of wxStaticText::Create
wxSize wxStaticText::DoGetBestSize() const wxSize wxStaticText::DoGetBestSize() const
{ {
wxString text(wxGetWindowText(GetHWND())); wxString sText(wxGetWindowText(GetHWND()));
int nWidthTextMax = 0;
int nWidthLine = 0;
int nHeightTextTotal = 0;
int nHeightLineDefault = 0;
int nHeightLine = 0;
wxString sCurLine;
int widthTextMax = 0, widthLine, for ( const wxChar *pc = sText; ; pc++ )
heightTextTotal = 0, heightLineDefault = 0, heightLine = 0; {
if ( *pc == wxT('\n') || *pc == wxT('\0') )
wxString curLine; {
for ( const wxChar *pc = text; ; pc++ ) { if (!sCurLine )
if ( *pc == wxT('\n') || *pc == wxT('\0') ) { {
if ( !curLine ) { //
// we can't use GetTextExtent - it will return 0 for both width // We can't use GetTextExtent - it will return 0 for both width
// and height and an empty line should count in height // and height and an empty line should count in height
// calculation // calculation
if ( !heightLineDefault ) //
heightLineDefault = heightLine; if (!nHeightLineDefault)
if ( !heightLineDefault ) nHeightLineDefault = nHeightLine;
GetTextExtent(_T("W"), NULL, &heightLineDefault); if (!nHeightLineDefault)
GetTextExtent(_T("W"), NULL, &nHeightLineDefault);
heightTextTotal += heightLineDefault; nHeightTextTotal += nHeightLineDefault;
} }
else { else
GetTextExtent(curLine, &widthLine, &heightLine); {
if ( widthLine > widthTextMax ) GetTextExtent( sCurLine
widthTextMax = widthLine; ,&nWidthLine
heightTextTotal += heightLine; ,&nHeightLine
);
if (nWidthLine > nWidthTextMax)
nWidthTextMax = nWidthLine;
nHeightTextTotal += nHeightLine;
} }
if ( *pc == wxT('\n') ) { if ( *pc == wxT('\n') )
curLine.Empty(); {
sCurLine.Empty();
} }
else { else
// the end of string {
break; break;
} }
} }
else {
curLine += *pc;
}
}
return wxSize(widthTextMax, heightTextTotal);
}
void wxStaticText::SetLabel(const wxString& label)
{
// TODO
// adjust the size of the window to fit to the label (this behaviour is
// backward compatible and generally makes sense but we might want to still
// provide the user a way to disable it) (VZ)
DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
}
WXHBRUSH wxStaticText::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
{
// TODO:
/*
if (GetParent()->GetTransparentBackground())
SetBkMode((HDC) pDC, TRANSPARENT);
else else
SetBkMode((HDC) pDC, OPAQUE); {
sCurLine += *pc;
}
}
return wxSize( nWidthTextMax
,nHeightTextTotal
);
} // end of wxStaticText::DoGetBestSize
::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); void wxStaticText::SetLabel(
::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue())); const wxString& rsLabel
)
wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
// Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
// has a zero usage count.
// backgroundBrush->RealizeResource();
return (WXHBRUSH) backgroundBrush->GetResourceHandle();
*/
return (WXHBRUSH)0;
}
MRESULT wxStaticText::OS2WindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
{ {
// Ensure that static items get messages. Some controls don't like this ::WinSetWindowText(GetHwnd(), rsLabel.c_str());
// message to be intercepted (e.g. RichEdit), hence the tests.
// TODO: //
/* // Adjust the size of the window to fit to the label unless autoresizing is
if (nMsg == WM_NCHITTEST) // disabled
return (long)HTCLIENT; //
*/ if (!(GetWindowStyle() & wxST_NO_AUTORESIZE))
return wxWindow::OS2WindowProc(nMsg, wParam, lParam); {
} DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
}
DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
} // end of wxStaticText::SetLabel
bool wxStaticText::SetFont(
const wxFont& rFont
)
{
bool bRet = wxControl::SetFont(rFont);
//
// Adjust the size of the window to fit to the label unless autoresizing is
// disabled
//
if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
{
DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
}
return bRet;
} // end of wxStaticText::SetFont
MRESULT wxStaticText::OS2WindowProc(
WXUINT uMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
{
return wxWindow::OS2WindowProc( uMsg
,wParam
,lParam
);
} // end of wxStaticText::OS2WindowProc