Fix wxTextCtrl size computation in wxGTK
Also improve wxTreeTextCtrl positioning in wxTreeCtrl. See #23001, #23610, #23623. (cherry picked from commit 27aa7e90a7882faeb9da42375e95ebba855ae1ca)
This commit is contained in:
parent
ad91e9d35a
commit
8ab4cac7a9
@ -338,6 +338,7 @@ wxGTK:
|
||||
- Allow selecting and copying text in wxMessageDialog (Ian McInerney, #23039).
|
||||
- Fix initial size of top-level window on Wayland (#23041).
|
||||
- Improve size and behaviour of in-place editor in wxTreeCtrl (taler21, #23001).
|
||||
- Also improve size compuation of wxTextCtrl (Alex Shvartzkop, #23610).
|
||||
|
||||
wxMSW:
|
||||
|
||||
|
@ -438,26 +438,21 @@ wxTreeTextCtrl::wxTreeTextCtrl(wxGenericTreeCtrl *owner,
|
||||
wxRect rect;
|
||||
m_owner->GetBoundingRect(m_itemEdited, rect, true);
|
||||
|
||||
// corrects position and size for better appearance
|
||||
#ifdef __WXMSW__
|
||||
rect.x -= 5;
|
||||
rect.width += 10;
|
||||
#elif defined(__WXGTK__)
|
||||
rect.x -= 5;
|
||||
rect.y -= 2;
|
||||
rect.width += 8;
|
||||
rect.height += 4;
|
||||
#endif // platforms
|
||||
|
||||
const wxSize textSize = rect.GetSize();
|
||||
wxSize fullSize = GetSizeFromTextSize(textSize);
|
||||
|
||||
// Ensure that the text field covers tree item.
|
||||
fullSize.x = wxMax(fullSize.x, textSize.x + 5);
|
||||
|
||||
// Correct position for better appearance.
|
||||
#ifdef __WXMSW__
|
||||
rect.x -= 5;
|
||||
#else
|
||||
rect.x -= (fullSize.x - textSize.x) / 2;
|
||||
#endif
|
||||
|
||||
if ( fullSize.y > textSize.y )
|
||||
{
|
||||
// It's ok to extend the rect to the right horizontally, which happens
|
||||
// when we just change its size without changing its position below,
|
||||
// but when extending it vertically, we need to keep it centered.
|
||||
rect.y -= (fullSize.y - textSize.y + 1) / 2;
|
||||
}
|
||||
rect.y -= (fullSize.y - textSize.y) / 2;
|
||||
|
||||
// Also check that the control fits into the parent window.
|
||||
const int totalWidth = m_owner->GetClientSize().x;
|
||||
|
@ -366,12 +366,17 @@ wxSize wxControl::GTKGetPreferredSize(GtkWidget* widget) const
|
||||
wxSize wxControl::GTKGetEntryMargins(GtkEntry* entry) const
|
||||
{
|
||||
wxSize size;
|
||||
gtk_entry_get_layout_offsets(entry, &size.x, &size.y);
|
||||
|
||||
#ifdef __WXGTK3__
|
||||
GtkBorder border;
|
||||
GtkStyleContext* sc = gtk_widget_get_style_context(GTK_WIDGET(entry));
|
||||
gtk_style_context_get_padding(sc, gtk_style_context_get_state(sc), &border);
|
||||
GtkStateFlags state = gtk_style_context_get_state(sc);
|
||||
|
||||
GtkBorder padding, border;
|
||||
gtk_style_context_get_padding(sc, state, &padding);
|
||||
gtk_style_context_get_border(sc, state, &border);
|
||||
|
||||
size.x += padding.left + padding.right + border.left + border.right;
|
||||
size.y += padding.top + padding.bottom + border.top + border.bottom;
|
||||
#else
|
||||
if (gtk_entry_get_has_frame(entry))
|
||||
{
|
||||
@ -402,10 +407,10 @@ wxSize wxControl::GTKGetEntryMargins(GtkEntry* entry) const
|
||||
}
|
||||
}
|
||||
#endif // GTK+ 2.10+
|
||||
#endif
|
||||
|
||||
size.x += border.left + border.right;
|
||||
size.y += border.top + border.bottom;
|
||||
#endif
|
||||
|
||||
return size;
|
||||
}
|
||||
|
@ -2161,29 +2161,11 @@ wxSize wxTextCtrl::DoGetSizeFromTextSize(int xlen, int ylen) const
|
||||
|
||||
if ( IsSingleLine() )
|
||||
{
|
||||
if ( HasFlag(wxBORDER_NONE) )
|
||||
{
|
||||
#ifdef __WXGTK3__
|
||||
tsize.IncBy(9, 0);
|
||||
#else
|
||||
tsize.IncBy(4, 0);
|
||||
#endif // GTK3
|
||||
}
|
||||
else
|
||||
{
|
||||
// default height
|
||||
tsize.y = GTKGetPreferredSize(m_widget).y;
|
||||
#ifdef __WXGTK3__
|
||||
// Add the margins we have previously set.
|
||||
tsize.IncBy( GTKGetEntryMargins(GetEntry()) );
|
||||
#else
|
||||
// For GTK 2 these margins are too big, so hard code something more
|
||||
// reasonable, this is not great but should be fine considering
|
||||
// that it's very unlikely that GTK 2 is going to evolve, making
|
||||
// this inappropriate.
|
||||
tsize.IncBy(20, 0);
|
||||
#endif
|
||||
}
|
||||
// Default height
|
||||
tsize.y = GTKGetPreferredSize(m_widget).y;
|
||||
|
||||
// Add padding + border size
|
||||
tsize.x += GTKGetEntryMargins(GetEntry()).x;
|
||||
}
|
||||
|
||||
//multiline
|
||||
|
Loading…
Reference in New Issue
Block a user