diff options
author | nyamatongwe <unknown> | 2011-05-01 14:28:53 +1000 |
---|---|---|
committer | nyamatongwe <unknown> | 2011-05-01 14:28:53 +1000 |
commit | cd0686dea3cdef5e01eed81a252f2b524e45f44a (patch) | |
tree | c0ff5b0ee02d1cece5f545b48bf952bb2410a657 | |
parent | 9c2334c4e4033b6ba3eb3b4834c302e8f27d4c37 (diff) | |
download | scintilla-mirror-cd0686dea3cdef5e01eed81a252f2b524e45f44a.tar.gz |
Use accessor function for adjustments and scrollbars for GTK+ 3.
-rw-r--r-- | gtk/PlatGTK.cxx | 11 | ||||
-rw-r--r-- | gtk/ScintillaGTK.cxx | 58 |
2 files changed, 63 insertions, 6 deletions
diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx index 9891bd4e0..a89b1e4f5 100644 --- a/gtk/PlatGTK.cxx +++ b/gtk/PlatGTK.cxx @@ -2501,9 +2501,13 @@ void ListBoxX::Select(int n) { int total = Length(); GtkAdjustment *adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(list)); +#if GTK_CHECK_VERSION(3,0,0) + gfloat value = ((gfloat)n / total) * (gtk_adjustment_get_upper(adj) - gtk_adjustment_get_lower(adj)) + + gtk_adjustment_get_lower(adj) - gtk_adjustment_get_page_size(adj) / 2; +#else gfloat value = ((gfloat)n / total) * (adj->upper - adj->lower) + adj->lower - adj->page_size / 2; - +#endif // Get cell height int row_width; int row_height; @@ -2522,8 +2526,13 @@ void ListBoxX::Select(int n) { } // Clamp it. value = (value < 0)? 0 : value; +#if GTK_CHECK_VERSION(3,0,0) + value = (value > (gtk_adjustment_get_upper(adj) - gtk_adjustment_get_page_size(adj)))? + (gtk_adjustment_get_upper(adj) - gtk_adjustment_get_page_size(adj)) : value; +#else value = (value > (adj->upper - adj->page_size))? (adj->upper - adj->page_size) : value; +#endif // Set it. gtk_adjustment_set_value(adj, value); diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx index fcfb4529a..5c21fe157 100644 --- a/gtk/ScintillaGTK.cxx +++ b/gtk/ScintillaGTK.cxx @@ -118,8 +118,8 @@ class ScintillaGTK : public ScintillaBase { Window wText; Window scrollbarv; Window scrollbarh; - GtkObject *adjustmentv; - GtkObject *adjustmenth; + GtkAdjustment *adjustmentv; + GtkAdjustment *adjustmenth; int scrollBarWidth; int scrollBarHeight; @@ -683,7 +683,7 @@ void ScintillaGTK::Initialise() { // Avoid background drawing flash gtk_widget_set_double_buffered(widtxt, FALSE); gtk_widget_set_size_request(widtxt, 100, 100); - adjustmentv = gtk_adjustment_new(0.0, 0.0, 201.0, 1.0, 20.0, 20.0); + adjustmentv = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 201.0, 1.0, 20.0, 20.0)); scrollbarv = gtk_vscrollbar_new(GTK_ADJUSTMENT(adjustmentv)); #if GTK_CHECK_VERSION(2,20,0) gtk_widget_set_can_focus(PWidget(scrollbarv), FALSE); @@ -695,7 +695,7 @@ void ScintillaGTK::Initialise() { gtk_widget_set_parent(PWidget(scrollbarv), PWidget(wMain)); gtk_widget_show(PWidget(scrollbarv)); - adjustmenth = gtk_adjustment_new(0.0, 0.0, 101.0, 1.0, 20.0, 20.0); + adjustmenth = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 101.0, 1.0, 20.0, 20.0)); scrollbarh = gtk_hscrollbar_new(GTK_ADJUSTMENT(adjustmenth)); #if GTK_CHECK_VERSION(2,20,0) gtk_widget_set_can_focus(PWidget(scrollbarh), FALSE); @@ -1051,6 +1051,17 @@ bool ScintillaGTK::ModifyScrollBars(int nMax, int nPage) { bool modified = false; int pageScroll = LinesToScroll(); +#if GTK_CHECK_VERSION(3,0,0) + if (gtk_adjustment_get_upper(adjustmentv) != (nMax + 1) || + gtk_adjustment_get_page_size(adjustmentv) != nPage || + gtk_adjustment_get_page_increment(adjustmentv) != pageScroll) { + gtk_adjustment_set_upper(adjustmentv, nMax + 1); + gtk_adjustment_set_page_size(adjustmentv, nPage); + gtk_adjustment_set_page_increment(adjustmentv, pageScroll); + gtk_adjustment_changed(GTK_ADJUSTMENT(adjustmentv)); + modified = true; + } +#else if (GTK_ADJUSTMENT(adjustmentv)->upper != (nMax + 1) || GTK_ADJUSTMENT(adjustmentv)->page_size != nPage || GTK_ADJUSTMENT(adjustmentv)->page_increment != pageScroll) { @@ -1060,6 +1071,7 @@ bool ScintillaGTK::ModifyScrollBars(int nMax, int nPage) { gtk_adjustment_changed(GTK_ADJUSTMENT(adjustmentv)); modified = true; } +#endif PRectangle rcText = GetTextRectangle(); int horizEndPreferred = scrollWidth; @@ -1068,6 +1080,19 @@ bool ScintillaGTK::ModifyScrollBars(int nMax, int nPage) { unsigned int pageWidth = rcText.Width(); unsigned int pageIncrement = pageWidth / 3; unsigned int charWidth = vs.styles[STYLE_DEFAULT].aveCharWidth; +#if GTK_CHECK_VERSION(3,0,0) + if (gtk_adjustment_get_upper(adjustmenth) != horizEndPreferred || + gtk_adjustment_get_page_size(adjustmenth) != pageWidth || + gtk_adjustment_get_page_increment(adjustmenth) != pageIncrement || + gtk_adjustment_get_step_increment(adjustmenth) != charWidth) { + gtk_adjustment_set_upper(adjustmenth, horizEndPreferred); + gtk_adjustment_set_page_size(adjustmenth, pageWidth); + gtk_adjustment_set_page_increment(adjustmenth, pageIncrement); + gtk_adjustment_set_step_increment(adjustmenth, charWidth); + gtk_adjustment_changed(GTK_ADJUSTMENT(adjustmenth)); + modified = true; + } +#else if (GTK_ADJUSTMENT(adjustmenth)->upper != horizEndPreferred || GTK_ADJUSTMENT(adjustmenth)->page_size != pageWidth || GTK_ADJUSTMENT(adjustmenth)->page_increment != pageIncrement || @@ -1079,6 +1104,7 @@ bool ScintillaGTK::ModifyScrollBars(int nMax, int nPage) { gtk_adjustment_changed(GTK_ADJUSTMENT(adjustmenth)); modified = true; } +#endif return modified; } @@ -1600,8 +1626,16 @@ void ScintillaGTK::Resize(int width, int height) { //printf("Resize %d %d\n", width, height); // Not always needed, but some themes can have different sizes of scrollbars +#if GTK_CHECK_VERSION(3,0,0) + GtkRequisition requisition; + gtk_widget_get_requisition(PWidget(scrollbarv), &requisition); + scrollBarWidth = requisition.width; + gtk_widget_get_requisition(PWidget(scrollbarh), &requisition); + scrollBarHeight = requisition.height; +#else scrollBarWidth = GTK_WIDGET(PWidget(scrollbarv))->requisition.width; scrollBarHeight = GTK_WIDGET(PWidget(scrollbarh))->requisition.height; +#endif // These allocations should never produce negative sizes as they would wrap around to huge // unsigned numbers inside GTK+ causing warnings. @@ -1649,10 +1683,16 @@ void ScintillaGTK::Resize(int width, int height) { gtk_widget_size_allocate(GTK_WIDGET(PWidget(wText)), &alloc); } -static void SetAdjustmentValue(GtkObject *object, int value) { +static void SetAdjustmentValue(GtkAdjustment *object, int value) { GtkAdjustment *adjustment = GTK_ADJUSTMENT(object); +#if GTK_CHECK_VERSION(3,0,0) + int maxValue = static_cast<int>( + gtk_adjustment_get_upper(adjustment) - gtk_adjustment_get_page_size(adjustment)); +#else int maxValue = static_cast<int>( adjustment->upper - adjustment->page_size); +#endif + if (value > maxValue) value = maxValue; if (value < 0) @@ -2220,7 +2260,11 @@ gboolean ScintillaGTK::Expose(GtkWidget *, GdkEventExpose *ose) { void ScintillaGTK::ScrollSignal(GtkAdjustment *adj, ScintillaGTK *sciThis) { try { +#if GTK_CHECK_VERSION(3,0,0) + sciThis->ScrollTo(static_cast<int>(gtk_adjustment_get_value(adj)), false); +#else sciThis->ScrollTo(static_cast<int>(adj->value), false); +#endif } catch (...) { sciThis->errorStatus = SC_STATUS_FAILURE; } @@ -2228,7 +2272,11 @@ void ScintillaGTK::ScrollSignal(GtkAdjustment *adj, ScintillaGTK *sciThis) { void ScintillaGTK::ScrollHSignal(GtkAdjustment *adj, ScintillaGTK *sciThis) { try { +#if GTK_CHECK_VERSION(3,0,0) + sciThis->HorizontalScrollTo(static_cast<int>(gtk_adjustment_get_value(adj) * 2)); +#else sciThis->HorizontalScrollTo(static_cast<int>(adj->value * 2)); +#endif } catch (...) { sciThis->errorStatus = SC_STATUS_FAILURE; } |