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:
@@ -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 {
|
else
|
||||||
curLine += *pc;
|
{
|
||||||
|
sCurLine += *pc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return wxSize( nWidthTextMax
|
||||||
|
,nHeightTextTotal
|
||||||
|
);
|
||||||
|
} // end of wxStaticText::DoGetBestSize
|
||||||
|
|
||||||
return wxSize(widthTextMax, heightTextTotal);
|
void wxStaticText::SetLabel(
|
||||||
}
|
const wxString& rsLabel
|
||||||
|
)
|
||||||
void wxStaticText::SetLabel(const wxString& label)
|
|
||||||
{
|
{
|
||||||
// TODO
|
::WinSetWindowText(GetHwnd(), rsLabel.c_str());
|
||||||
|
|
||||||
// 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
|
// Adjust the size of the window to fit to the label unless autoresizing is
|
||||||
// provide the user a way to disable it) (VZ)
|
// disabled
|
||||||
|
//
|
||||||
|
if (!(GetWindowStyle() & wxST_NO_AUTORESIZE))
|
||||||
|
{
|
||||||
|
DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
|
||||||
|
}
|
||||||
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
|
||||||
|
|
||||||
WXHBRUSH wxStaticText::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
|
bool wxStaticText::SetFont(
|
||||||
WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
|
const wxFont& rFont
|
||||||
|
)
|
||||||
{
|
{
|
||||||
// TODO:
|
bool bRet = wxControl::SetFont(rFont);
|
||||||
/*
|
|
||||||
if (GetParent()->GetTransparentBackground())
|
|
||||||
SetBkMode((HDC) pDC, TRANSPARENT);
|
|
||||||
else
|
|
||||||
SetBkMode((HDC) pDC, OPAQUE);
|
|
||||||
|
|
||||||
::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
|
//
|
||||||
::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
|
// 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
|
||||||
|
|
||||||
wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
|
MRESULT wxStaticText::OS2WindowProc(
|
||||||
// Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
|
WXUINT uMsg
|
||||||
// has a zero usage count.
|
, WXWPARAM wParam
|
||||||
// backgroundBrush->RealizeResource();
|
, WXLPARAM lParam
|
||||||
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
|
return wxWindow::OS2WindowProc( uMsg
|
||||||
// message to be intercepted (e.g. RichEdit), hence the tests.
|
,wParam
|
||||||
// TODO:
|
,lParam
|
||||||
/*
|
);
|
||||||
if (nMsg == WM_NCHITTEST)
|
} // end of wxStaticText::OS2WindowProc
|
||||||
return (long)HTCLIENT;
|
|
||||||
*/
|
|
||||||
return wxWindow::OS2WindowProc(nMsg, wParam, lParam);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user