Merge branch 'scintilla/gtk-3-20' into gtk-3-20-fixes
This commit is contained in:
commit
75063e9159
@ -1263,6 +1263,30 @@ ListBox *ListBox::Allocate() {
|
|||||||
return lb;
|
return lb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int treeViewGetRowHeight(GtkTreeView *view) {
|
||||||
|
#if GTK_CHECK_VERSION(3,0,0)
|
||||||
|
// This version sometimes reports erroneous results on GTK2, but the GTK2
|
||||||
|
// version is inaccurate for GTK 3.14.
|
||||||
|
GdkRectangle rect;
|
||||||
|
GtkTreePath *path = gtk_tree_path_new_first();
|
||||||
|
gtk_tree_view_get_background_area(view, path, NULL, &rect);
|
||||||
|
gtk_tree_path_free(path);
|
||||||
|
return rect.height;
|
||||||
|
#else
|
||||||
|
int row_height=0;
|
||||||
|
int vertical_separator=0;
|
||||||
|
int expander_size=0;
|
||||||
|
GtkTreeViewColumn *column = gtk_tree_view_get_column(view, 0);
|
||||||
|
gtk_tree_view_column_cell_get_size(column, NULL, NULL, NULL, NULL, &row_height);
|
||||||
|
gtk_widget_style_get(GTK_WIDGET(view),
|
||||||
|
"vertical-separator", &vertical_separator,
|
||||||
|
"expander-size", &expander_size, NULL);
|
||||||
|
row_height += vertical_separator;
|
||||||
|
row_height = Platform::Maximum(row_height, expander_size);
|
||||||
|
return row_height;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// SmallScroller, a GtkScrolledWindow that can shrink very small, as
|
// SmallScroller, a GtkScrolledWindow that can shrink very small, as
|
||||||
// gtk_widget_set_size_request() cannot shrink widgets on GTK3
|
// gtk_widget_set_size_request() cannot shrink widgets on GTK3
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -1287,10 +1311,20 @@ G_DEFINE_TYPE(SmallScroller, small_scroller, GTK_TYPE_SCROLLED_WINDOW)
|
|||||||
|
|
||||||
#if GTK_CHECK_VERSION(3,0,0)
|
#if GTK_CHECK_VERSION(3,0,0)
|
||||||
static void small_scroller_get_preferred_height(GtkWidget *widget, gint *min, gint *nat) {
|
static void small_scroller_get_preferred_height(GtkWidget *widget, gint *min, gint *nat) {
|
||||||
|
GtkWidget *child = gtk_bin_get_child(GTK_BIN(widget));
|
||||||
|
if (GTK_IS_TREE_VIEW(child)) {
|
||||||
|
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(child));
|
||||||
|
int n_rows = gtk_tree_model_iter_n_children(model, NULL);
|
||||||
|
int row_height = treeViewGetRowHeight(GTK_TREE_VIEW(child));
|
||||||
|
|
||||||
|
*min = MAX(1, row_height);
|
||||||
|
*nat = MAX(*min, n_rows * row_height);
|
||||||
|
} else {
|
||||||
GTK_WIDGET_CLASS(small_scroller_parent_class)->get_preferred_height(widget, min, nat);
|
GTK_WIDGET_CLASS(small_scroller_parent_class)->get_preferred_height(widget, min, nat);
|
||||||
if (*min > 1)
|
if (*min > 1)
|
||||||
*min = 1;
|
*min = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
static void small_scroller_size_request(GtkWidget *widget, GtkRequisition *req) {
|
static void small_scroller_size_request(GtkWidget *widget, GtkRequisition *req) {
|
||||||
GTK_WIDGET_CLASS(small_scroller_parent_class)->size_request(widget, req);
|
GTK_WIDGET_CLASS(small_scroller_parent_class)->size_request(widget, req);
|
||||||
@ -1456,7 +1490,7 @@ void ListBoxX::SetFont(Font &scint_font) {
|
|||||||
if (cssProvider) {
|
if (cssProvider) {
|
||||||
PangoFontDescription *pfd = PFont(scint_font)->pfd;
|
PangoFontDescription *pfd = PFont(scint_font)->pfd;
|
||||||
std::ostringstream ssFontSetting;
|
std::ostringstream ssFontSetting;
|
||||||
ssFontSetting << "GtkTreeView { ";
|
ssFontSetting << "GtkTreeView, treeview { ";
|
||||||
ssFontSetting << "font-family: " << pango_font_description_get_family(pfd) << "; ";
|
ssFontSetting << "font-family: " << pango_font_description_get_family(pfd) << "; ";
|
||||||
ssFontSetting << "font-size:";
|
ssFontSetting << "font-size:";
|
||||||
ssFontSetting << static_cast<double>(pango_font_description_get_size(pfd)) / PANGO_SCALE;
|
ssFontSetting << static_cast<double>(pango_font_description_get_size(pfd)) / PANGO_SCALE;
|
||||||
@ -1486,28 +1520,8 @@ int ListBoxX::GetVisibleRows() const {
|
|||||||
return desiredVisibleRows;
|
return desiredVisibleRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ListBoxX::GetRowHeight()
|
int ListBoxX::GetRowHeight() {
|
||||||
{
|
return treeViewGetRowHeight(GTK_TREE_VIEW(list));
|
||||||
#if GTK_CHECK_VERSION(3,0,0)
|
|
||||||
// This version sometimes reports erroneous results on GTK2, but the GTK2
|
|
||||||
// version is inaccurate for GTK 3.14.
|
|
||||||
GdkRectangle rect;
|
|
||||||
GtkTreePath *path = gtk_tree_path_new_first();
|
|
||||||
gtk_tree_view_get_background_area(GTK_TREE_VIEW(list), path, NULL, &rect);
|
|
||||||
return rect.height;
|
|
||||||
#else
|
|
||||||
int row_height=0;
|
|
||||||
int vertical_separator=0;
|
|
||||||
int expander_size=0;
|
|
||||||
GtkTreeViewColumn *column = gtk_tree_view_get_column(GTK_TREE_VIEW(list), 0);
|
|
||||||
gtk_tree_view_column_cell_get_size(column, NULL, NULL, NULL, NULL, &row_height);
|
|
||||||
gtk_widget_style_get(PWidget(list),
|
|
||||||
"vertical-separator", &vertical_separator,
|
|
||||||
"expander-size", &expander_size, NULL);
|
|
||||||
row_height += vertical_separator;
|
|
||||||
row_height = Platform::Maximum(row_height, expander_size);
|
|
||||||
return row_height;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PRectangle ListBoxX::GetDesiredRect() {
|
PRectangle ListBoxX::GetDesiredRect() {
|
||||||
@ -1534,12 +1548,35 @@ PRectangle ListBoxX::GetDesiredRect() {
|
|||||||
int row_height = GetRowHeight();
|
int row_height = GetRowHeight();
|
||||||
#if GTK_CHECK_VERSION(3,0,0)
|
#if GTK_CHECK_VERSION(3,0,0)
|
||||||
GtkStyleContext *styleContextFrame = gtk_widget_get_style_context(PWidget(frame));
|
GtkStyleContext *styleContextFrame = gtk_widget_get_style_context(PWidget(frame));
|
||||||
GtkBorder padding, border;
|
GtkStateFlags stateFlagsFrame = gtk_style_context_get_state(styleContextFrame);
|
||||||
gtk_style_context_get_padding(styleContextFrame, GTK_STATE_FLAG_NORMAL, &padding);
|
GtkBorder padding, border, border_border = { 0, 0, 0, 0 };
|
||||||
gtk_style_context_get_border(styleContextFrame, GTK_STATE_FLAG_NORMAL, &border);
|
gtk_style_context_get_padding(styleContextFrame, stateFlagsFrame, &padding);
|
||||||
|
gtk_style_context_get_border(styleContextFrame, stateFlagsFrame, &border);
|
||||||
|
|
||||||
|
# if GTK_CHECK_VERSION(3,20,0)
|
||||||
|
// on GTK 3.20 the frame border is in a sub-node "border".
|
||||||
|
// Unfortunately we need to be built against 3.20 to be able to support this, as it requires
|
||||||
|
// new API.
|
||||||
|
GtkStyleContext *styleContextFrameBorder = gtk_style_context_new();
|
||||||
|
GtkWidgetPath *widget_path = gtk_widget_path_copy(gtk_style_context_get_path(styleContextFrame));
|
||||||
|
gtk_widget_path_append_type(widget_path, GTK_TYPE_BORDER); // dummy type
|
||||||
|
gtk_widget_path_iter_set_object_name(widget_path, -1, "border");
|
||||||
|
gtk_style_context_set_path(styleContextFrameBorder, widget_path);
|
||||||
|
gtk_widget_path_free(widget_path);
|
||||||
|
gtk_style_context_get_border(styleContextFrameBorder, stateFlagsFrame, &border_border);
|
||||||
|
g_object_unref(styleContextFrameBorder);
|
||||||
|
# else // < 3.20
|
||||||
|
if (gtk_check_version(3, 20, 0) == NULL) {
|
||||||
|
// default to 1px all around as it's likely what it is, and so we don't miss 2px height
|
||||||
|
// on GTK 3.20 when built against an earlier version.
|
||||||
|
border_border.top = border_border.bottom = border_border.left = border_border.right = 1;
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
height = (rows * row_height
|
height = (rows * row_height
|
||||||
+ padding.top + padding.bottom
|
+ padding.top + padding.bottom
|
||||||
+ border.top + border.bottom
|
+ border.top + border.bottom
|
||||||
|
+ border_border.top + border_border.bottom
|
||||||
+ 2 * gtk_container_get_border_width(GTK_CONTAINER(PWidget(list))));
|
+ 2 * gtk_container_get_border_width(GTK_CONTAINER(PWidget(list))));
|
||||||
#else
|
#else
|
||||||
height = (rows * row_height
|
height = (rows * row_height
|
||||||
@ -1560,6 +1597,7 @@ PRectangle ListBoxX::GetDesiredRect() {
|
|||||||
#if GTK_CHECK_VERSION(3,0,0)
|
#if GTK_CHECK_VERSION(3,0,0)
|
||||||
rc.right += (padding.left + padding.right
|
rc.right += (padding.left + padding.right
|
||||||
+ border.left + border.right
|
+ border.left + border.right
|
||||||
|
+ border_border.left + border_border.right
|
||||||
+ 2 * gtk_container_get_border_width(GTK_CONTAINER(PWidget(list))));
|
+ 2 * gtk_container_get_border_width(GTK_CONTAINER(PWidget(list))));
|
||||||
#else
|
#else
|
||||||
rc.right += 2 * (PWidget(frame)->style->xthickness
|
rc.right += 2 * (PWidget(frame)->style->xthickness
|
||||||
|
@ -472,8 +472,10 @@ void ScintillaGTK::RealizeThis(GtkWidget *widget) {
|
|||||||
#else
|
#else
|
||||||
gdk_window_set_user_data(gtk_widget_get_window(widget), widget);
|
gdk_window_set_user_data(gtk_widget_get_window(widget), widget);
|
||||||
#endif
|
#endif
|
||||||
|
#if !GTK_CHECK_VERSION(3,18,0)
|
||||||
gtk_style_context_set_background(gtk_widget_get_style_context(widget),
|
gtk_style_context_set_background(gtk_widget_get_style_context(widget),
|
||||||
gtk_widget_get_window(widget));
|
gtk_widget_get_window(widget));
|
||||||
|
#endif
|
||||||
gdk_window_show(gtk_widget_get_window(widget));
|
gdk_window_show(gtk_widget_get_window(widget));
|
||||||
UnRefCursor(cursor);
|
UnRefCursor(cursor);
|
||||||
#else
|
#else
|
||||||
@ -1223,7 +1225,9 @@ bool ScintillaGTK::ModifyScrollBars(int nMax, int nPage) {
|
|||||||
gtk_adjustment_set_upper(adjustmentv, nMax + 1);
|
gtk_adjustment_set_upper(adjustmentv, nMax + 1);
|
||||||
gtk_adjustment_set_page_size(adjustmentv, nPage);
|
gtk_adjustment_set_page_size(adjustmentv, nPage);
|
||||||
gtk_adjustment_set_page_increment(adjustmentv, pageScroll);
|
gtk_adjustment_set_page_increment(adjustmentv, pageScroll);
|
||||||
|
#if !GTK_CHECK_VERSION(3,18,0)
|
||||||
gtk_adjustment_changed(GTK_ADJUSTMENT(adjustmentv));
|
gtk_adjustment_changed(GTK_ADJUSTMENT(adjustmentv));
|
||||||
|
#endif
|
||||||
modified = true;
|
modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1242,7 +1246,9 @@ bool ScintillaGTK::ModifyScrollBars(int nMax, int nPage) {
|
|||||||
gtk_adjustment_set_page_size(adjustmenth, pageWidth);
|
gtk_adjustment_set_page_size(adjustmenth, pageWidth);
|
||||||
gtk_adjustment_set_page_increment(adjustmenth, pageIncrement);
|
gtk_adjustment_set_page_increment(adjustmenth, pageIncrement);
|
||||||
gtk_adjustment_set_step_increment(adjustmenth, charWidth);
|
gtk_adjustment_set_step_increment(adjustmenth, charWidth);
|
||||||
|
#if !GTK_CHECK_VERSION(3,18,0)
|
||||||
gtk_adjustment_changed(GTK_ADJUSTMENT(adjustmenth));
|
gtk_adjustment_changed(GTK_ADJUSTMENT(adjustmenth));
|
||||||
|
#endif
|
||||||
modified = true;
|
modified = true;
|
||||||
}
|
}
|
||||||
if (modified && (paintState == painting)) {
|
if (modified && (paintState == painting)) {
|
||||||
@ -1769,8 +1775,17 @@ void ScintillaGTK::Resize(int width, int height) {
|
|||||||
|
|
||||||
alloc.x = 0;
|
alloc.x = 0;
|
||||||
alloc.y = 0;
|
alloc.y = 0;
|
||||||
alloc.width = Platform::Maximum(1, width - verticalScrollBarWidth);
|
alloc.width = 1;
|
||||||
alloc.height = Platform::Maximum(1, height - horizontalScrollBarHeight);
|
alloc.height = 1;
|
||||||
|
#if GTK_CHECK_VERSION(3, 0, 0)
|
||||||
|
// please GTK 3.20 and ask wText what size it wants, although we know it doesn't really need
|
||||||
|
// anything special as it's ours.
|
||||||
|
gtk_widget_get_preferred_size(PWidget(wText), &requisition, NULL);
|
||||||
|
alloc.width = requisition.width;
|
||||||
|
alloc.height = requisition.height;
|
||||||
|
#endif
|
||||||
|
alloc.width = Platform::Maximum(alloc.width, width - verticalScrollBarWidth);
|
||||||
|
alloc.height = Platform::Maximum(alloc.height, height - horizontalScrollBarHeight);
|
||||||
gtk_widget_size_allocate(GTK_WIDGET(PWidget(wText)), &alloc);
|
gtk_widget_size_allocate(GTK_WIDGET(PWidget(wText)), &alloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user