void ScrollbarThemeGtk::paintThumb(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect) { GtkWidget* widget = getWidgetForScrollbar(scrollbar); gboolean activateSlider; gtk_widget_style_get(widget, "activate-slider", &activateSlider, NULL); GtkStateType stateType = GTK_STATE_NORMAL; GtkShadowType shadowType = GTK_SHADOW_OUT; if (activateSlider && scrollbar->pressedPart() == ThumbPart) { stateType = GTK_STATE_ACTIVE; shadowType = GTK_SHADOW_IN; } else if (scrollbar->pressedPart() == ThumbPart || scrollbar->hoveredPart() == ThumbPart) stateType = GTK_STATE_PRELIGHT; // The adjustment controls the rendering of the scrollbar thumb. If it's not set // properly the theme may not draw the thumb borders properly. GtkAdjustment* adjustment = gtk_range_get_adjustment(GTK_RANGE(widget)); gtk_adjustment_set_value(adjustment, scrollbar->currentPos()); gtk_adjustment_set_lower(adjustment, 0); gtk_adjustment_set_upper(adjustment, scrollbar->maximum()); GtkOrientation orientation = GTK_ORIENTATION_HORIZONTAL; if (scrollbar->orientation() == VerticalScrollbar) { gtk_adjustment_set_page_size(adjustment, rect.height()); orientation = GTK_ORIENTATION_VERTICAL; } else gtk_adjustment_set_page_size(adjustment, rect.width()); WidgetRenderingContext widgetContext(context, rect); IntRect sliderRect(IntPoint(), rect.size()); widgetContext.gtkPaintSlider(sliderRect, widget, stateType, shadowType, "slider", orientation); }
void ddisplay_update_scrollbars(DDisplay *ddisp) { Rectangle *extents = &ddisp->diagram->data->extents; Rectangle *visible = &ddisp->visible; GtkAdjustment *hsbdata, *vsbdata; hsbdata = ddisp->hsbdata; /* Horizontal: */ gtk_adjustment_set_lower (hsbdata, MIN(extents->left, visible->left)); gtk_adjustment_set_upper (hsbdata, MAX(extents->right, visible->right)); gtk_adjustment_set_page_size (hsbdata, visible->right - visible->left - 0.0001); /* remove some to fix strange behaviour in gtk_range_adjustment_changed */ gtk_adjustment_set_page_increment (hsbdata, (visible->right - visible->left) / 2.0); gtk_adjustment_set_step_increment (hsbdata, (visible->right - visible->left) / 10.0); gtk_adjustment_set_value (hsbdata, visible->left); g_signal_emit_by_name (G_OBJECT (ddisp->hsbdata), "changed"); /* Vertical: */ vsbdata = ddisp->vsbdata; gtk_adjustment_set_lower (vsbdata, MIN(extents->top, visible->top)); gtk_adjustment_set_upper (vsbdata, MAX(extents->bottom, visible->bottom)); gtk_adjustment_set_page_size (vsbdata, visible->bottom - visible->top - 0.00001); /* remove some to fix strange behaviour in gtk_range_adjustment_changed */ gtk_adjustment_set_page_increment (vsbdata, (visible->bottom - visible->top) / 2.0); gtk_adjustment_set_step_increment (vsbdata, (visible->bottom - visible->top) / 10.0); gtk_adjustment_set_value (vsbdata, visible->top); g_signal_emit_by_name (G_OBJECT (ddisp->vsbdata), "changed"); }
void gSlider::init() { GtkAdjustment* adj = gtk_range_get_adjustment(GTK_RANGE(widget)); //if (_min == _max) // _max = _min + 1; if (_value < _min) _value = _min; else if (_value > _max) _value = _max; if (g_typ == Type_gSlider) { gtk_range_set_range(GTK_RANGE(widget), (gdouble)_min, (gdouble)_max); gtk_range_set_increments(GTK_RANGE(widget), (gdouble)_step, (gdouble)_page_step); } else { gtk_range_set_range(GTK_RANGE(widget), (gdouble)_min, (gdouble)_max + _page_step); gtk_range_set_increments(GTK_RANGE(widget), (gdouble)_step, (gdouble)_page_step); gtk_adjustment_set_page_size(adj, _page_step); } gtk_range_set_value(GTK_RANGE(widget), _value); #ifndef GTK3 gtk_range_set_update_policy(GTK_RANGE(widget), _tracking ? GTK_UPDATE_CONTINUOUS : GTK_UPDATE_DISCONTINUOUS); #endif checkInverted(); }
JNIEXPORT void JNICALL Java_org_gnome_gtk_GtkAdjustment_gtk_1adjustment_1set_1page_1size ( JNIEnv* env, jclass cls, jlong _self, jdouble _value ) { GtkAdjustment* self; gdouble value; // convert parameter self self = (GtkAdjustment*) _self; // convert parameter value value = (gdouble) _value; // call function gtk_adjustment_set_page_size(self, value); // cleanup parameter self // cleanup parameter value }
void test_scroll (void) { GtkScrollbar *scbar_v = (GtkScrollbar*) gtk_vscrollbar_new (NULL); uzbl.gui.bar_v = gtk_range_get_adjustment((GtkRange*) scbar_v); gtk_adjustment_set_lower(uzbl.gui.bar_v, 0); gtk_adjustment_set_upper(uzbl.gui.bar_v, 100); gtk_adjustment_set_page_size(uzbl.gui.bar_v, 5); /* scroll vertical end should scroll it to upper - page_size */ parse_cmd_line("scroll vertical end", NULL); g_assert_cmpfloat(gtk_adjustment_get_value(uzbl.gui.bar_v), ==, 95); /* scroll vertical begin should scroll it to lower */ parse_cmd_line("scroll vertical begin", NULL); g_assert_cmpfloat(gtk_adjustment_get_value(uzbl.gui.bar_v), ==, 0); /* scroll vertical can scroll by pixels */ parse_cmd_line("scroll vertical 15", NULL); g_assert_cmpfloat(gtk_adjustment_get_value(uzbl.gui.bar_v), ==, 15); parse_cmd_line("scroll vertical -10", NULL); g_assert_cmpfloat(gtk_adjustment_get_value(uzbl.gui.bar_v), ==, 5); /* scroll vertical can scroll by a percentage of the page size */ parse_cmd_line("scroll vertical 100%", NULL); g_assert_cmpfloat(gtk_adjustment_get_value(uzbl.gui.bar_v), ==, 10); parse_cmd_line("scroll vertical 150%", NULL); g_assert_cmpfloat(gtk_adjustment_get_value(uzbl.gui.bar_v), ==, 17.5); /* scroll_horz behaves basically the same way. */ }
static void dma_sparse_view_update_adjustement (DmaSparseView *view) { PangoLayout *layout; GdkRectangle text_area; int height; gtk_text_view_get_visible_rect(GTK_TEXT_VIEW (view), &text_area); layout = gtk_widget_create_pango_layout (GTK_WIDGET(view), "0123456789ABCDEFGHIJKLMNOPQRSTUVWWYZ,"); pango_layout_get_pixel_size(layout, NULL, &height); g_object_unref (G_OBJECT (layout)); view->priv->line_by_page = text_area.height / height; view->priv->char_by_line = 8; if (view->priv->vadjustment != NULL) { GtkAdjustment *vadj = view->priv->vadjustment; gdouble step_increment, page_size; step_increment = view->priv->char_by_line; page_size = (view->priv->line_by_page - 1) * step_increment; gtk_adjustment_set_step_increment (vadj, step_increment); gtk_adjustment_set_page_size (vadj, page_size); gtk_adjustment_set_page_increment (vadj, page_size * 0.9); gtk_adjustment_changed (vadj); } }
void Scrollbar::setPageSize(int size) { XOJ_CHECK_TYPE(Scrollbar); gtk_adjustment_set_page_size(this->adj, size); // Check value within range this->setValue(this->value); }
void update_vscrollbar (DenemoProject * gui) { if(Denemo.non_interactive) return; GtkAdjustment *adj = GTK_ADJUSTMENT (Denemo.vadjustment); gtk_adjustment_set_upper (adj, g_list_length (gui->movement->thescore) + 1.0); gtk_adjustment_set_page_size (adj, gui->movement->bottom_staff - gui->movement->top_staff + 1.0); gtk_adjustment_set_page_increment (adj, gui->movement->bottom_staff - gui->movement->top_staff + 1.0); gtk_adjustment_set_value (adj, gui->movement->top_staff); gtk_adjustment_changed (adj); //gtk_range_slider_update (GTK_RANGE (Denemo.vscrollbar)); }
/** * update_hscrollbar should be called as a cleanup whenever * si->leftmeasurenum or si->rightmeasurenum may have been altered, * e.g., by preceding calls to set_rightmeasurenum; or when the * number of measures may have changed. */ void update_hscrollbar (DenemoProject * gui) { if(Denemo.non_interactive) return; GtkAdjustment *adj = GTK_ADJUSTMENT (Denemo.hadjustment); gdouble upper = g_list_length (gui->movement->measurewidths) + 1.0, page_size = gui->movement->rightmeasurenum - gui->movement->leftmeasurenum + 1.0; gdouble left = gtk_adjustment_get_value (adj); gtk_adjustment_set_upper (adj, upper); gtk_adjustment_set_page_size (adj, page_size); gtk_adjustment_set_page_increment (adj, page_size); gtk_adjustment_set_value (adj, gui->movement->leftmeasurenum); gtk_adjustment_changed (adj); //g_debug("steps %d Difference %d\n",transition_steps, (gint)(left-gui->movement->leftmeasurenum)); set_viewport_transition ((gint) (gui->movement->leftmeasurenum) - left); }
static void gtk_experiment_transcript_reconfigure(GtkExperimentTranscript *trans) { GtkWidget *widget = GTK_WIDGET(trans); gtk_adjustment_set_page_size(GTK_ADJUSTMENT(trans->priv->time_adjustment), (gdouble)PX_TO_TIME(widget->allocation.height)); GOBJECT_UNREF_SAFE(trans->priv->layer_text); trans->priv->layer_text = gdk_pixmap_new(gtk_widget_get_window(widget), widget->allocation.width, widget->allocation.height, -1); pango_layout_set_width(trans->priv->layer_text_layout, widget->allocation.width*PANGO_SCALE); gtk_experiment_transcript_text_layer_redraw(trans); }
void wxScrollHelper::DoAdjustScrollbar(GtkRange* range, int pixelsPerLine, int winSize, int virtSize, int *pos, int *lines, int *linesPerPage) { if (!range) return; int upper; int page_size; if (pixelsPerLine > 0 && winSize > 0 && winSize < virtSize) { upper = (virtSize + pixelsPerLine - 1) / pixelsPerLine; page_size = winSize / pixelsPerLine; *lines = upper; *linesPerPage = page_size; } else { // GtkRange won't allow upper == lower, so for disabled state use [0,1] // with a page size of 1. This will also clamp position to 0. upper = 1; page_size = 1; *lines = 0; *linesPerPage = 0; } gtk_range_set_increments(range, 1, page_size); gtk_adjustment_set_page_size(gtk_range_get_adjustment(range), page_size); gtk_range_set_range(range, 0, upper); // ensure that the scroll position is always in valid range if (*pos > *lines) *pos = *lines; }
static gint moz_gtk_scrollbar_thumb_paint(GtkThemeWidgetType widget, GdkDrawable* drawable, GdkRectangle* rect, GdkRectangle* cliprect, GtkWidgetState* state, GtkTextDirection direction) { GtkStateType state_type = (state->inHover || state->active) ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL; GtkShadowType shadow_type = GTK_SHADOW_OUT; GtkStyle* style; GtkScrollbar *scrollbar; GtkAdjustment *adj; gboolean activate_slider; ensure_scrollbar_widget(); if (widget == MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL) scrollbar = GTK_SCROLLBAR(gParts->horizScrollbarWidget); else scrollbar = GTK_SCROLLBAR(gParts->vertScrollbarWidget); gtk_widget_set_direction(GTK_WIDGET(scrollbar), direction); /* Make sure to set the scrollbar range before painting so that everything is drawn properly. At least the bluecurve (and maybe other) themes don't draw the top or bottom black line surrounding the scrollbar if the theme thinks that it's butted up against the scrollbar arrows. Note the increases of the clip rect below. */ /* Changing the cliprect is pretty bogus. This lets themes draw outside the frame, which means we don't invalidate them correctly. See bug 297508. But some themes do seem to need it. So we modify the frame's overflow area to account for what we're doing here; see nsNativeThemeGTK::GetWidgetOverflow. */ adj = gtk_range_get_adjustment(GTK_RANGE(scrollbar)); if (widget == MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL) { cliprect->x -= 1; cliprect->width += 2; gtk_adjustment_set_page_size(adj, rect->width); } else { cliprect->y -= 1; cliprect->height += 2; gtk_adjustment_set_page_size(adj, rect->height); } #if GTK_CHECK_VERSION(2, 14, 0) gtk_adjustment_configure(adj, state->curpos, 0, state->maxpos, gtk_adjustment_get_step_increment(adj), gtk_adjustment_get_page_increment(adj), gtk_adjustment_get_page_size(adj)); #else adj->lower = 0; adj->value = state->curpos; adj->upper = state->maxpos; gtk_adjustment_changed(adj); #endif style = gtk_widget_get_style(GTK_WIDGET(scrollbar)); gtk_widget_style_get(GTK_WIDGET(scrollbar), "activate-slider", &activate_slider, NULL); if (activate_slider && state->active) { shadow_type = GTK_SHADOW_IN; state_type = GTK_STATE_ACTIVE; } TSOffsetStyleGCs(style, rect->x, rect->y); gtk_paint_slider(style, drawable, state_type, shadow_type, cliprect, GTK_WIDGET(scrollbar), "slider", rect->x, rect->y, rect->width, rect->height, (widget == MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL) ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL); return MOZ_GTK_SUCCESS; }
/** * @param ddisp The diagram display object that a window is created for * @param width Diagram widgth * @param height Diagram Height * @param title Window title * @param use_mbar Flag to indicate whether to add a menubar to the window */ void create_display_shell(DDisplay *ddisp, int width, int height, char *title, int use_mbar) { GtkWidget *table, *widget; GtkWidget *status_hbox; GtkWidget *root_vbox = NULL; GtkWidget *zoom_hbox, *zoom_label; int s_width, s_height; if (app_is_interactive() && is_integrated_ui()) { use_integrated_ui_for_display_shell(ddisp, title); return; } ddisp->is_standalone_window = TRUE; ddisp->container = NULL; s_width = gdk_screen_width (); s_height = gdk_screen_height (); if (width > s_width) width = s_width; if (height > s_height) height = s_height; /* The toplevel shell */ ddisp->shell = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (ddisp->shell), title); gtk_window_set_role (GTK_WINDOW (ddisp->shell), "diagram_window"); gtk_window_set_icon_name (GTK_WINDOW (ddisp->shell), "dia"); gtk_window_set_default_size(GTK_WINDOW (ddisp->shell), width, height); /* set_icon_name needs registered theme icons, not always available: provide fallback */ if (!gtk_window_get_icon (GTK_WINDOW (ddisp->shell))) { static GdkPixbuf *pixbuf = NULL; if (!pixbuf) pixbuf = gdk_pixbuf_new_from_inline(-1, dia_diagram_icon, FALSE, NULL); if (pixbuf) gtk_window_set_icon (GTK_WINDOW (ddisp->shell), pixbuf); } g_object_set_data (G_OBJECT (ddisp->shell), "user_data", (gpointer) ddisp); _ddisplay_setup_events (ddisp, ddisp->shell); /* following two not shared with integrated UI */ g_signal_connect (G_OBJECT (ddisp->shell), "delete_event", G_CALLBACK (ddisplay_delete), ddisp); g_signal_connect (G_OBJECT (ddisp->shell), "destroy", G_CALLBACK (ddisplay_destroy), ddisp); /* the table containing all widgets */ table = gtk_table_new (4, 3, FALSE); gtk_table_set_col_spacing (GTK_TABLE (table), 0, 1); gtk_table_set_col_spacing (GTK_TABLE (table), 1, 2); gtk_table_set_row_spacing (GTK_TABLE (table), 0, 1); gtk_table_set_row_spacing (GTK_TABLE (table), 1, 2); gtk_container_set_border_width (GTK_CONTAINER (table), 2); if (use_mbar) { root_vbox = gtk_vbox_new (FALSE, 1); gtk_container_add (GTK_CONTAINER (ddisp->shell), root_vbox); gtk_box_pack_end (GTK_BOX (root_vbox), table, TRUE, TRUE, 0); } else { gtk_container_add (GTK_CONTAINER (ddisp->shell), table); } /* scrollbars, rulers, canvas, menu popup button */ if (!use_mbar) { ddisp->origin = gtk_button_new(); #if GTK_CHECK_VERSION(2,18,0) gtk_widget_set_can_focus (ddisp->origin, FALSE); #else GTK_WIDGET_UNSET_FLAGS(ddisp->origin, GTK_CAN_FOCUS); #endif widget = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_OUT); gtk_container_add(GTK_CONTAINER(ddisp->origin), widget); gtk_widget_set_tooltip_text(widget, _("Diagram menu.")); gtk_widget_show(widget); g_signal_connect(G_OBJECT(ddisp->origin), "button_press_event", G_CALLBACK(origin_button_press), ddisp); } else { ddisp->origin = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME (ddisp->origin), GTK_SHADOW_OUT); } _ddisplay_setup_rulers (ddisp, ddisp->shell, table); _ddisplay_setup_scrollbars (ddisp, table, width, height); _ddisplay_setup_navigation (ddisp, table); ddisp->canvas = create_canvas (ddisp); /* pack all remaining widgets */ gtk_table_attach (GTK_TABLE (table), ddisp->origin, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach (GTK_TABLE (table), ddisp->canvas, 1, 2, 1, 2, GTK_EXPAND | GTK_SHRINK | GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0); /* TODO rob use per window accel */ ddisp->accel_group = menus_get_display_accels (); gtk_window_add_accel_group(GTK_WINDOW(ddisp->shell), ddisp->accel_group); if (use_mbar) { ddisp->menu_bar = menus_create_display_menubar (&ddisp->ui_manager, &ddisp->actions); g_assert (ddisp->menu_bar); gtk_box_pack_start (GTK_BOX (root_vbox), ddisp->menu_bar, FALSE, TRUE, 0); } /* the statusbars */ status_hbox = gtk_hbox_new (FALSE, 2); /* Zoom status pseudo-optionmenu */ ddisp->zoom_status = create_zoom_widget(ddisp); zoom_hbox = gtk_hbox_new(FALSE, 0); zoom_label = gtk_label_new(_("Zoom")); gtk_box_pack_start (GTK_BOX(zoom_hbox), zoom_label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX(zoom_hbox), ddisp->zoom_status, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (status_hbox), zoom_hbox, FALSE, FALSE, 0); /* Grid on/off button */ ddisp->grid_status = dia_toggle_button_new_with_icons(dia_on_grid_icon, dia_off_grid_icon); g_signal_connect(G_OBJECT(ddisp->grid_status), "toggled", G_CALLBACK (grid_toggle_snap), ddisp); gtk_widget_set_tooltip_text(ddisp->grid_status, _("Toggles snap-to-grid for this window.")); gtk_box_pack_start (GTK_BOX (status_hbox), ddisp->grid_status, FALSE, FALSE, 0); ddisp->mainpoint_status = dia_toggle_button_new_with_icons(dia_mainpoints_on_icon, dia_mainpoints_off_icon); g_signal_connect(G_OBJECT(ddisp->mainpoint_status), "toggled", G_CALLBACK (interface_toggle_mainpoint_magnetism), ddisp); gtk_widget_set_tooltip_text(ddisp->mainpoint_status, _("Toggles object snapping for this window.")); gtk_box_pack_start (GTK_BOX (status_hbox), ddisp->mainpoint_status, FALSE, FALSE, 0); /* Statusbar */ ddisp->modified_status = gtk_statusbar_new (); gtk_box_pack_start (GTK_BOX (status_hbox), ddisp->modified_status, TRUE, TRUE, 0); gtk_table_attach (GTK_TABLE (table), status_hbox, 0, 3, 3, 4, GTK_FILL, GTK_FILL, 0, 0); display_rulers_show (ddisp); gtk_widget_show (ddisp->zoom_status); gtk_widget_show (zoom_hbox); gtk_widget_show (zoom_label); gtk_widget_show (ddisp->grid_status); gtk_widget_show (ddisp->mainpoint_status); gtk_widget_show (ddisp->modified_status); gtk_widget_show (status_hbox); gtk_widget_show (table); if (use_mbar) { gtk_widget_show (ddisp->menu_bar); gtk_widget_show (root_vbox); } gtk_widget_show (ddisp->shell); /* before showing up, checking canvas's REAL size */ if (use_mbar && ddisp->hrule->allocation.width > width) { /* The menubar is not shrinkable, so the shell will have at least * the menubar's width. If the diagram's requested width is smaller, * the canvas will be enlarged to fit the place. In this case, we * need to adjust the horizontal scrollbar according to the size * that will be allocated, which the same as the hrule got. */ width = ddisp->hrule->allocation.width; gtk_adjustment_set_upper (ddisp->hsbdata, width); gtk_adjustment_set_page_increment (ddisp->hsbdata, (width - 1) / 4); gtk_adjustment_set_page_size (ddisp->hsbdata, width - 1); gtk_adjustment_changed (GTK_ADJUSTMENT(ddisp->hsbdata)); } gtk_widget_show (ddisp->canvas); /* set the focus to the canvas area */ gtk_widget_grab_focus (ddisp->canvas); }
static void dma_data_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { DmaDataView *view = DMA_DATA_VIEW (widget); GtkStyle *style; GtkAllocation child_allocation; GtkRequisition range_requisition; GtkRequisition address_requisition; GtkRequisition data_requisition; GtkRequisition ascii_requisition; gint width; gint height; gint bytes_by_line; gint step; guint border_width; gboolean need_fill = FALSE; gtk_widget_set_allocation (widget, allocation); gtk_widget_get_child_requisition (view->range, &range_requisition); border_width = gtk_container_get_border_width (GTK_CONTAINER (view)); style = gtk_widget_get_style (widget); dma_data_view_address_size_request (view, &address_requisition); dma_data_view_data_size_request (view, &data_requisition); dma_data_view_ascii_size_request (view, &ascii_requisition); /* Compute number of byte per line */ width = allocation->width - 2 * border_width - (view->shadow_type == GTK_SHADOW_NONE ? 0 : 2 * style->xthickness) - ADDRESS_BORDER - ASCII_BORDER - SCROLLBAR_SPACING - range_requisition.width - address_requisition.width - data_requisition.width * view->char_by_byte - ascii_requisition.width; step = (ascii_requisition.width + data_requisition.width * (view->char_by_byte + 1)); for (bytes_by_line = 1; width >= step * bytes_by_line; bytes_by_line *= 2) { width -= step * bytes_by_line; } if (bytes_by_line != view->bytes_by_line) { need_fill = TRUE; view->bytes_by_line = bytes_by_line; } /* Compute number of line by page */ height = allocation->height - 2 * border_width - (view->shadow_type == GTK_SHADOW_NONE ? 0 : 2 * style->ythickness); if (view->line_by_page != (height / address_requisition.height)) { need_fill = TRUE; view->line_by_page = (height / address_requisition.height); } child_allocation.y = allocation->y + border_width; child_allocation.height = MAX (1, (gint) allocation->height - (gint) border_width * 2); /* Scroll bar */ child_allocation.x = allocation->x + allocation->width - border_width - range_requisition.width; child_allocation.width = range_requisition.width; gtk_widget_size_allocate (view->range, &child_allocation); child_allocation.x = allocation->x + border_width; /* Frame */ if (view->shadow_type != GTK_SHADOW_NONE) { GtkStyle *style = gtk_widget_get_style (widget); view->frame.x = allocation->x + border_width; view->frame.y = allocation->y + border_width; view->frame.width = allocation->width - range_requisition.width - SCROLLBAR_SPACING - 2 * border_width; view->frame.height = allocation->height - 2 * border_width; child_allocation.x += style->xthickness; child_allocation.y += style->ythickness; child_allocation.height -= 2 * style->ythickness; } /* Address */ child_allocation.width = address_requisition.width; gtk_widget_size_allocate (view->address, &child_allocation); child_allocation.x += child_allocation.width; child_allocation.x += ADDRESS_BORDER; /* Data */ child_allocation.width = (view->bytes_by_line * (view->char_by_byte + 1) - 1) * data_requisition.width; gtk_widget_size_allocate (view->data, &child_allocation); child_allocation.x += child_allocation.width; child_allocation.x += ASCII_BORDER; /* Ascii */ child_allocation.width = view->bytes_by_line * ascii_requisition.width; gtk_widget_size_allocate (view->ascii, &child_allocation); child_allocation.x += child_allocation.width; if (need_fill) { gdouble page_increment, page_size, upper; page_increment = view->bytes_by_line * (view->line_by_page - 1); upper = gtk_adjustment_get_upper (view->buffer_range); page_size = (gulong) upper % view->bytes_by_line + page_increment; gtk_adjustment_set_step_increment (view->buffer_range, view->bytes_by_line); gtk_adjustment_set_page_increment (view->buffer_range, page_increment); gtk_adjustment_set_page_size (view->buffer_range, page_size); if (view->start + page_size > upper) { view->start = upper - page_size + view->bytes_by_line - 1; view->start -= view->start % view->bytes_by_line; } dma_data_view_refresh (view); } }
void zoom_amnt(double invalue, bool from_mouse) { // for now, just zoom relative double value; double offsetx1, offsety1; double offsetx2, offsety2; double page_sizex, page_sizey; double mousex, mousey; double hsc_psize, vsc_psize; // block scroll signals for scrollbars // while adjusting canvas scaling, scroll amount g_signal_handler_block(hscroll, hscroll_id); g_signal_handler_block(vscroll, vscroll_id); if (!invalue || (fldstate.zoom_amnt * invalue) < 1) { // set zoom to 100% fldstate.zoom_amnt = 1; gtk_adjustment_set_page_size(hscroll, fldstate.width); gtk_adjustment_set_page_size(vscroll, fldstate.height); fldstate.fieldx = 0; fldstate.fieldy = 0; hsc_psize = gtk_adjustment_get_page_size(hscroll); vsc_psize = gtk_adjustment_get_page_size(vscroll); gtk_adjustment_configure(hscroll, 0.0, 0.0, fldstate.width, hsc_psize / 10, hsc_psize / 10 * 9, hsc_psize); gtk_adjustment_configure(vscroll, 0.0, 0.0, fldstate.height, vsc_psize / 10, vsc_psize / 10 * 9, vsc_psize); canvas_move(drill, 0, 0); g_signal_handler_unblock(hscroll, hscroll_id); g_signal_handler_unblock(vscroll, vscroll_id); return; } else { // zoom and scale the canvas value = invalue; // get the old page size offsetx1 = gtk_adjustment_get_upper(hscroll) / fldstate.zoom_amnt; offsety1 = gtk_adjustment_get_upper(vscroll) / fldstate.zoom_amnt; // new zoom factor fldstate.zoom_amnt *= value; // new page size page_sizex = gtk_adjustment_get_upper(hscroll) / fldstate.zoom_amnt; page_sizey = gtk_adjustment_get_upper(vscroll) / fldstate.zoom_amnt; // change scrollbars gtk_adjustment_configure(hscroll, fldstate.fieldx, 0.0, fldstate.width, page_sizex / 10, page_sizex / 10 * 9, page_sizex); gtk_adjustment_configure(vscroll, fldstate.fieldy, 0.0, fldstate.height, page_sizey / 10, page_sizey / 10 * 9, page_sizey); // calculate base offset after zoom offsetx2 = (offsetx1 - page_sizex) / 2; offsety2 = (offsety1 - page_sizey) / 2; if (from_mouse) { // get mouse position // use it in canvas offset mousex = fldstate.mousex; mousey = fldstate.mousey; // translate mouse position to pixel values field_to_pixel(&mousex, &mousey); // calculate a mouse offset factor mousex = 2*(mousex - fldstate.fieldx) / offsetx1; mousey = 2*(mousey - fldstate.fieldy) / offsety1; } else { // don't use mouse for zoom offset mousex = 1; mousey = 1; } // offset the canvas after zooming based on mouse position canvas_move(drill, offsetx2*mousex, offsety2*mousey); // release scrollbars g_signal_handler_unblock(hscroll, hscroll_id); g_signal_handler_unblock(vscroll, vscroll_id); return; } return; }