image_expose_event(GtkWidget* widget, GdkEventExpose*, wxToolBarTool* tool) #endif { const wxBitmap& bitmap = tool->GetDisabledBitmap(); if (tool->IsEnabled() || !bitmap.IsOk()) return false; // draw disabled bitmap ourselves, GtkImage has no way to specify it GtkAllocation alloc; gtk_widget_get_allocation(widget, &alloc); GtkRequisition req; gtk_widget_get_requisition(widget, &req); #ifdef __WXGTK3__ const int x = (alloc.width - req.width) / 2; const int y = (alloc.height - req.height) / 2; bitmap.Draw(cr, x, y); #else const int x = alloc.x + (alloc.width - req.width) / 2; const int y = alloc.y + (alloc.height - req.height) / 2; gdk_draw_pixbuf( gtk_widget_get_window(widget), gtk_widget_get_style(widget)->black_gc, bitmap.GetPixbuf(), 0, 0, x, y, -1, -1, GDK_RGB_DITHER_NORMAL, 0, 0); #endif return true; }
/** * Access GtkWidget's requisition field, a GtkRequisition struct. * * This implementation also [is forced to] get on with calling * gtk_widget_size_request() on the assumption that the Requisition isn't * much use without data in it. */ JNIEXPORT void JNICALL Java_org_gnome_gtk_GtkWidgetOverride_gtk_1widget_1get_1requisition ( JNIEnv* env, jclass cls, jlong _self, jlong _requisition ) { GtkRequisition temp = { 0, }; GtkRequisition* requisition; GtkWidget* self; // convert parameter self self = (GtkWidget*) _self; // convert parameter requisition requisition = (GtkRequisition*) _requisition; /* * To avoid the necessity to instantiate the silly GtkRequisition * struct as a complete object Java side (along with attendant * GtkRequisitionOverride code to allocate them), we take a fairly * sharp shortcut here: we will programatically get on with it and * call size_request() here. */ gtk_widget_size_request(self, &temp); gtk_widget_get_requisition(self, requisition); // cleanup parameter self // cleanup parameter requisition }
static void posfunc(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer user_data) { GtkWidget *w = GTK_WIDGET(user_data); GdkWindow *win = gtk_widget_get_window(w); int i = get_selector_state(GX_SELECTOR(w)); gint n = g_list_length(gtk_container_get_children(GTK_CONTAINER(menu))); GtkRequisition req; gtk_widget_get_requisition(GTK_WIDGET(menu), &req); gdk_window_get_origin(win, x, y); *x += w->allocation.x; *y += w->allocation.y - (req.height * i) / n; *push_in = TRUE; }
static void menu_pos(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, GtkWidget *widget) { int ox, oy, w, h; kano_feedback_plugin_t *plugin = lxpanel_plugin_get_data(widget); GtkAllocation allocation; gtk_widget_get_allocation(GTK_WIDGET(widget), &allocation); gdk_window_get_origin(gtk_widget_get_window(widget), &ox, &oy); /* FIXME The X origin is being truncated for some reason, reset it from the allocaation. */ ox = allocation.x; #if GTK_CHECK_VERSION(2,20,0) GtkRequisition requisition; gtk_widget_get_requisition(GTK_WIDGET(menu), &requisition); w = requisition.width; h = requisition.height; #else w = GTK_WIDGET(menu)->requisition.width; h = GTK_WIDGET(menu)->requisition.height; #endif if (panel_get_orientation(plugin->panel) == GTK_ORIENTATION_HORIZONTAL) { *x = ox; if (*x + w > gdk_screen_width()) *x = ox + allocation.width - w; *y = oy - h; if (*y < 0) *y = oy + allocation.height; } else { *x = ox + allocation.width; if (*x > gdk_screen_width()) *x = ox - w; *y = oy; if (*y + h > gdk_screen_height()) *y = oy + allocation.height - h; } /* Debugging prints */ /*printf("widget: x,y=%d,%d w,h=%d,%d\n", ox, oy, allocation.width, allocation.height ); printf("w-h %d %d\n", w, h); */ *push_in = TRUE; return; }
static void tab_completion_popup_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data) { TabCompData *td = data; gint height; PangoLayout *layout; PangoRectangle strong_pos, weak_pos; gint length; gint xoffset, yoffset; GtkRequisition req; GdkScreen *screen; gint monitor_num; GdkRectangle monitor; GtkRequisition requisition; GtkAllocation allocation; gdk_window_get_origin(gtk_widget_get_window(GTK_WIDGET(td->entry)), x, y); screen = gtk_widget_get_screen(GTK_WIDGET(menu)); monitor_num = gdk_screen_get_monitor_at_window(screen, gtk_widget_get_window(GTK_WIDGET(td->entry))); gdk_screen_get_monitor_geometry(screen, monitor_num, &monitor); gtk_widget_size_request(GTK_WIDGET(menu), &req); length = strlen(gtk_entry_get_text(GTK_ENTRY(td->entry))); gtk_entry_get_layout_offsets(GTK_ENTRY(td->entry), &xoffset, &yoffset); layout = gtk_entry_get_layout(GTK_ENTRY(td->entry)); pango_layout_get_cursor_pos(layout, length, &strong_pos, &weak_pos); *x += strong_pos.x / PANGO_SCALE + xoffset; gtk_widget_get_requisition(td->entry, &requisition); gtk_widget_get_allocation(td->entry, &allocation); height = MIN(requisition.height, allocation.height); if (req.height > monitor.y + monitor.height - *y - height && *y - monitor.y > monitor.y + monitor.height - *y) { height = MIN(*y - monitor.y, req.height); gtk_widget_set_size_request(GTK_WIDGET(menu), -1, height); *y -= height; } else { *y += height; } }
void ChromeClient::contentsSizeChanged(Frame* frame, const IntSize& size) const { // We need to queue a resize request only if the size changed, // otherwise we get into an infinite loop! GtkWidget* widget = GTK_WIDGET(m_webView); GtkRequisition requisition; #if GTK_CHECK_VERSION(2, 20, 0) gtk_widget_get_requisition(widget, &requisition); #else requisition = widget->requisition; #endif if (gtk_widget_get_realized(widget) && (requisition.height != size.height()) || (requisition.width != size.width())) gtk_widget_queue_resize_no_redraw(widget); }
gboolean popup_menu_position_clamp(GtkMenu *menu, gint *x, gint *y, gint height) { gboolean adjusted = FALSE; gint w, h; gint xw, xh; GtkRequisition requisition; gtk_widget_get_requisition(GTK_WIDGET(menu), &requisition); w = requisition.width; h = requisition.height; xw = gdk_screen_width(); xh = gdk_screen_height(); if (*x + w > xw) { *x = xw - w; adjusted = TRUE; } if (*y + h > xh) { if (height) { *y = MAX(0, *y - h - height); } else { *y = xh - h; } adjusted = TRUE; }; if (*x < 0) { *x = 0; adjusted = TRUE; } if (*y < 0) { *y = 0; adjusted = TRUE; } return adjusted; }
static void gimp_view_update_callback (GimpViewRenderer *renderer, GimpView *view) { GtkWidget *widget = GTK_WIDGET (view); GtkRequisition requisition; gint width; gint height; gtk_widget_get_requisition (widget, &requisition); width = renderer->width + 2 * renderer->border_width; height = renderer->height + 2 * renderer->border_width; if (width != requisition.width || height != requisition.height) { gtk_widget_queue_resize (widget); } else { gtk_widget_queue_draw (widget); } }
void brasero_file_chooser_customize (GtkWidget *widget, gpointer null_data) { /* we explore everything until we reach a treeview (there are two) */ if (GTK_IS_TREE_VIEW (widget)) { GtkTargetList *list; GdkAtom target; gboolean found; guint num; list = gtk_drag_source_get_target_list (widget); target = gdk_atom_intern ("text/uri-list", TRUE); found = gtk_target_list_find (list, target, &num); /* FIXME: should we unref them ? apparently not according to * the warning messages we get if we do */ if (found && gtk_tree_selection_get_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (widget))) == GTK_SELECTION_MULTIPLE) { GtkTreeModel *model; /* This is done because GtkFileChooser does not use a * GtkListStore or GtkTreeStore any more. */ egg_tree_multi_drag_add_drag_support (GTK_TREE_VIEW (widget)); model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget)); if (model) { GType type; type = G_OBJECT_TYPE (model); brasero_enable_multi_DND_for_model_type (type); } else g_signal_connect (widget, "notify::model", G_CALLBACK (brasero_file_chooser_notify_model), NULL); } } else if (GTK_IS_BUTTON (widget)) { GtkWidget *image; gchar *stock_id = NULL; image = gtk_button_get_image (GTK_BUTTON (widget)); if (!GTK_IS_IMAGE (image)) return; gtk_image_get_stock (GTK_IMAGE (image), &stock_id, NULL); if (stock_id && (!strcmp (stock_id,GTK_STOCK_ADD) || !strcmp (stock_id, GTK_STOCK_REMOVE))) { GtkRequisition request; gint width; GtkWidget *parent; /* This is to avoid having the left part too small */ parent = gtk_widget_get_parent (widget); gtk_widget_get_requisition (parent, &request); width = request.width; gtk_widget_get_preferred_size (parent, &request, NULL); if (request.width >= width) gtk_widget_set_size_request (parent, request.width, request.height); gtk_widget_hide (widget); } } else if (GTK_IS_CONTAINER (widget)) { if (GTK_IS_PANED (widget)) { GtkWidget *left; /* This is to allow the left part to be shrunk as much * as the user want. */ left = gtk_paned_get_child1 (GTK_PANED (widget)); g_object_ref (left); gtk_container_remove (GTK_CONTAINER (widget), left); gtk_paned_pack1 (GTK_PANED (widget), left, TRUE, TRUE); g_object_unref (left); g_signal_connect (widget, "size-allocate", G_CALLBACK (brasero_file_chooser_allocation_changed), NULL); } gtk_container_foreach (GTK_CONTAINER (widget), brasero_file_chooser_customize, NULL); } }
bool sc_adjust_window(girara_session_t* session, girara_argument_t* argument, girara_event_t* UNUSED(event), unsigned int UNUSED(t)) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); zathura_t* zathura = session->global.data; g_return_val_if_fail(argument != NULL, false); unsigned int pages_per_row = 1; girara_setting_get(session, "pages-per-row", &pages_per_row); unsigned int first_page_column = 1; girara_setting_get(session, "first-page-column", &first_page_column); int padding = 1; girara_setting_get(zathura->ui.session, "page-padding", &padding); if (zathura->ui.page_widget == NULL || zathura->document == NULL) { goto error_ret; } float old_zoom = zathura_document_get_scale(zathura->document); zathura_document_set_adjust_mode(zathura->document, argument->n); if (argument->n == ZATHURA_ADJUST_NONE) { /* there is nothing todo */ goto error_ret; } /* get window size */ GtkAllocation allocation; gtk_widget_get_allocation(session->gtk.view, &allocation); unsigned int width = allocation.width; unsigned int height = allocation.height; /* scrollbar spacing */ gint spacing; gtk_widget_style_get(session->gtk.view, "scrollbar_spacing", &spacing, NULL); width -= spacing; /* correct view size */ if (gtk_widget_get_visible(GTK_WIDGET(session->gtk.inputbar)) == true) { gtk_widget_get_allocation(session->gtk.inputbar, &allocation); height += allocation.height; } double scale = 1.0; unsigned int cell_height = 0, cell_width = 0; unsigned int document_height = 0, document_width = 0; zathura_document_set_scale(zathura->document, scale); zathura_document_get_cell_size(zathura->document, &cell_height, &cell_width); zathura_get_document_size(zathura, cell_height, cell_width, &document_height, &document_width); double page_ratio = (double)cell_height / (double)document_width; double window_ratio = (double)height / (double)width; if (argument->n == ZATHURA_ADJUST_WIDTH || (argument->n == ZATHURA_ADJUST_BESTFIT && page_ratio < window_ratio)) { scale = (double)(width - (pages_per_row - 1) * padding) / (double)(pages_per_row * cell_width); zathura_document_set_scale(zathura->document, scale); bool show_scrollbars = false; girara_setting_get(session, "show-scrollbars", &show_scrollbars); if (show_scrollbars) { /* If the document is taller than the view, there's a vertical * scrollbar; we need to substract its width from the view's width. */ zathura_get_document_size(zathura, cell_height, cell_width, &document_height, &document_width); if (height < document_height) { GtkWidget* vscrollbar = gtk_scrolled_window_get_vscrollbar( GTK_SCROLLED_WINDOW(session->gtk.view)); if (vscrollbar != NULL) { GtkRequisition requisition; gtk_widget_get_requisition(vscrollbar, &requisition); if (0 < requisition.width && (unsigned)requisition.width < width) { width -= requisition.width; scale = (double)(width - (pages_per_row - 1) * padding) / (double)(pages_per_row * cell_width); zathura_document_set_scale(zathura->document, scale); } } } } } else if (argument->n == ZATHURA_ADJUST_BESTFIT) { scale = (double)height / (double)cell_height; zathura_document_set_scale(zathura->document, scale); } else { goto error_ret; } /* keep position */ readjust_view_after_zooming(zathura, old_zoom, false); /* re-render all pages */ render_all(zathura); error_ret: return false; }
/** * \brief Get a widget showing one icon with another overlaid on top of it. * * The base icon is always centralised, the other icon can be positioned. * The overlay icon is ignored if pos=OVERLAY_NONE is used * * \param window top-level window widget * \param icon the base icon * \param overlay the icon to overlay * \param pos how to align the overlay widget, or OVERLAY_NONE for no overlay * \param border_x size of the border around the base icon (left and right) * \param border_y size of the border around the base icon (top and bottom) */ GtkWidget *stock_pixmap_widget_with_overlay(StockPixmap icon, StockPixmap overlay, OverlayPosition pos, gint border_x, gint border_y) { cairo_surface_t *stock_pixmap = NULL; GdkPixbuf *stock_pixbuf = NULL; GtkWidget *widget = NULL; GtkWidget *stock_wid = NULL; GtkRequisition requisition; OverlayData *data = NULL; data = g_new0(OverlayData, 1); stock_wid = stock_pixmap_widget(icon); gtk_widget_get_requisition(stock_wid, &requisition); #if !GTK_CHECK_VERSION(3, 0, 0) if (gtk_image_get_storage_type(GTK_IMAGE(stock_wid)) == GTK_IMAGE_PIXMAP) data->is_pixmap = TRUE; else #endif data->is_pixmap = FALSE; if (data->is_pixmap) { cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(stock_wid)); stock_pixmap = cairo_get_target(cr); cairo_surface_reference(stock_pixmap); cairo_destroy(cr); data->base_pixmap = stock_pixmap; data->base_height = requisition.height; data->base_width = requisition.width; gtk_widget_destroy(stock_wid); if (pos == OVERLAY_NONE) { data->overlay_pixmap = NULL; } else { stock_wid = stock_pixmap_widget(overlay); cr = gdk_cairo_create(gtk_widget_get_window(stock_wid)); stock_pixmap = cairo_get_target(cr); cairo_surface_reference(stock_pixmap); cairo_destroy(cr); data->overlay_pixmap = stock_pixmap; data->overlay_height = requisition.height; data->overlay_width = requisition.width; gtk_widget_destroy(stock_wid); } } else { data->is_pixmap = FALSE; stock_pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(stock_wid)); g_object_ref(stock_pixbuf); data->base_pixbuf = stock_pixbuf; data->base_height = requisition.height; data->base_width = requisition.width; gtk_widget_destroy(stock_wid); if (pos == OVERLAY_NONE) { data->overlay_pixmap = NULL; } else { stock_wid = stock_pixmap_widget(overlay); stock_pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(stock_wid)); g_object_ref(stock_pixbuf); data->overlay_pixbuf = stock_pixbuf; data->overlay_height = requisition.height; data->overlay_width = requisition.width; gtk_widget_destroy(stock_wid); } } data->position = pos; data->border_x = border_x; data->border_y = border_y; data->highlight = FALSE; widget = gtk_drawing_area_new(); gtk_widget_set_size_request(widget, data->base_width + border_x * 2, data->base_height + border_y * 2); #if !GTK_CHECK_VERSION(3, 0, 0) g_signal_connect(G_OBJECT(widget), "expose_event", G_CALLBACK(pixmap_with_overlay_expose_event_cb), data); #else g_signal_connect(G_OBJECT(widget), "draw", G_CALLBACK(pixmap_with_overlay_expose_event_cb), data); #endif g_signal_connect(G_OBJECT(widget), "destroy", G_CALLBACK(pixmap_with_overlay_destroy_cb), data); g_object_set_data(G_OBJECT(widget), "highlight", &(data->highlight)); return widget; }