multi line static controls now calculate their width and height correctly
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2898 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
b134516c10
commit
4b5d9823ec
@ -96,73 +96,79 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id,
|
|||||||
|
|
||||||
void wxStaticText::DoSetSize(int x, int y, int width, int height, int sizeFlags)
|
void wxStaticText::DoSetSize(int x, int y, int width, int height, int sizeFlags)
|
||||||
{
|
{
|
||||||
int currentX, currentY;
|
int currentX, currentY;
|
||||||
GetPosition(¤tX, ¤tY);
|
GetPosition(¤tX, ¤tY);
|
||||||
int x1 = x;
|
|
||||||
int y1 = y;
|
|
||||||
|
|
||||||
if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
|
int x1 = x;
|
||||||
x1 = currentX;
|
int y1 = y;
|
||||||
if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
|
|
||||||
y1 = currentY;
|
|
||||||
|
|
||||||
AdjustForParentClientOrigin(x1, y1, sizeFlags);
|
if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
|
||||||
|
x1 = currentX;
|
||||||
|
if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
|
||||||
|
y1 = currentY;
|
||||||
|
|
||||||
int actualWidth = width;
|
AdjustForParentClientOrigin(x1, y1, sizeFlags);
|
||||||
int actualHeight = height;
|
|
||||||
|
|
||||||
int current_width;
|
int actualWidth = width;
|
||||||
int cyf;
|
int actualHeight = height;
|
||||||
|
|
||||||
wxString text(wxGetWindowText(GetHWND()));
|
wxString text(wxGetWindowText(GetHWND()));
|
||||||
GetTextExtent(text, ¤t_width, &cyf, NULL, NULL, & GetFont());
|
|
||||||
|
|
||||||
int ww, hh;
|
int widthTextMax = 0, widthLine,
|
||||||
GetSize(&ww, &hh);
|
heightTextTotal = 0, heightLine;
|
||||||
|
|
||||||
// If we're prepared to use the existing width, then...
|
wxString curLine;
|
||||||
if (width == -1 && ((sizeFlags & wxSIZE_AUTO_WIDTH) != wxSIZE_AUTO_WIDTH))
|
for ( const char *pc = text; ; pc++ ) {
|
||||||
actualWidth = ww;
|
if ( *pc == '\n' || *pc == '\0' ) {
|
||||||
else if (width == -1)
|
GetTextExtent(curLine, &widthLine, &heightLine);
|
||||||
{
|
if ( width > widthTextMax )
|
||||||
int cx;
|
widthTextMax = widthLine;
|
||||||
int cy;
|
heightTextTotal += heightLine;
|
||||||
wxGetCharSize(GetHWND(), &cx, &cy, & GetFont());
|
|
||||||
actualWidth = (int)(current_width + cx) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we're prepared to use the existing height, then...
|
if ( *pc == '\n' ) {
|
||||||
if (height == -1 && ((sizeFlags & wxSIZE_AUTO_HEIGHT) != wxSIZE_AUTO_HEIGHT))
|
curLine.Empty();
|
||||||
actualHeight = hh;
|
}
|
||||||
else if (height == -1)
|
else {
|
||||||
{
|
// the end of string
|
||||||
actualHeight = (int)(cyf) ;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
curLine += *pc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MoveWindow((HWND) GetHWND(), x1, y1, actualWidth, actualHeight, TRUE);
|
int ww, hh;
|
||||||
|
GetSize(&ww, &hh);
|
||||||
|
|
||||||
|
// If we're prepared to use the existing width, then...
|
||||||
|
if (width == -1 && ((sizeFlags & wxSIZE_AUTO_WIDTH) != wxSIZE_AUTO_WIDTH))
|
||||||
|
{
|
||||||
|
actualWidth = ww;
|
||||||
|
}
|
||||||
|
else if (width == -1)
|
||||||
|
{
|
||||||
|
actualWidth = widthTextMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we're prepared to use the existing height, then...
|
||||||
|
if (height == -1 && ((sizeFlags & wxSIZE_AUTO_HEIGHT) != wxSIZE_AUTO_HEIGHT))
|
||||||
|
{
|
||||||
|
actualHeight = hh;
|
||||||
|
}
|
||||||
|
else if (height == -1)
|
||||||
|
{
|
||||||
|
actualHeight = heightTextTotal;
|
||||||
|
}
|
||||||
|
|
||||||
|
MoveWindow(GetHwnd(), x1, y1, actualWidth, actualHeight, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxStaticText::SetLabel(const wxString& label)
|
void wxStaticText::SetLabel(const wxString& label)
|
||||||
{
|
{
|
||||||
wxWindow *parent = GetParent();
|
SetWindowText(GetHwnd(), label);
|
||||||
|
|
||||||
RECT rect;
|
DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
|
||||||
GetWindowRect((HWND) GetHWND(), &rect);
|
|
||||||
|
|
||||||
// Since we now have the absolute screen coords, if there's a parent we must
|
|
||||||
// subtract its top left corner
|
|
||||||
POINT point;
|
|
||||||
point.x = rect.left;
|
|
||||||
point.y = rect.top;
|
|
||||||
if (parent)
|
|
||||||
{
|
|
||||||
::ScreenToClient((HWND) parent->GetHWND(), &point);
|
|
||||||
}
|
|
||||||
|
|
||||||
int w, h;
|
|
||||||
GetTextExtent(label, &w, &h, NULL, NULL, & GetFont());
|
|
||||||
MoveWindow((HWND) GetHWND(), point.x, point.y, (int)(w + 10), (int)h, TRUE);
|
|
||||||
SetWindowText((HWND) GetHWND(), (const wxChar *)label);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WXHBRUSH wxStaticText::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
|
WXHBRUSH wxStaticText::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
|
||||||
|
Loading…
Reference in New Issue
Block a user