/** * TODO: document * Borrowed from the Gimp Toolkit and modified. * */ void set_popup_position (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer user_data) { GtkWidget *widget; GtkRequisition requisition; GtkAllocation allocation; gint screen_width, menu_xpos, menu_ypos, menu_width; widget = GTK_WIDGET (user_data); gtk_widget_get_child_requisition (GTK_WIDGET (menu), &requisition); menu_width = requisition.width; gdk_window_get_origin ( gtk_widget_get_window ( widget ), &menu_xpos, &menu_ypos ); gtk_widget_get_allocation ( widget, &allocation ); menu_xpos += allocation.x; menu_ypos += allocation.y + allocation.height - 2; if ( gtk_widget_get_direction ( widget) == GTK_TEXT_DIR_RTL ) menu_xpos = menu_xpos + allocation.width - menu_width; /* Clamp the position on screen */ screen_width = gdk_screen_get_width (gtk_widget_get_screen (widget)); if (menu_xpos < 0) menu_xpos = 0; else if ((menu_xpos + menu_width) > screen_width) menu_xpos -= ((menu_xpos + menu_width) - screen_width); *x = menu_xpos; *y = menu_ypos; *push_in = TRUE; }
static void gimp_frame_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { GtkFrame *frame = GTK_FRAME (widget); GtkWidget *label_widget = gtk_frame_get_label_widget (frame); GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget)); GtkAllocation child_allocation; gtk_widget_set_allocation (widget, allocation); gimp_frame_child_allocate (frame, &child_allocation); if (child && gtk_widget_get_visible (child)) gtk_widget_size_allocate (child, &child_allocation); if (label_widget && gtk_widget_get_visible (label_widget)) { GtkAllocation label_allocation; GtkRequisition label_requisition; gint border_width; border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); gtk_widget_get_child_requisition (label_widget, &label_requisition); label_allocation.x = allocation->x + border_width; label_allocation.y = allocation->y + border_width; label_allocation.width = MAX (label_requisition.width, allocation->width - 2 * border_width); label_allocation.height = label_requisition.height; gtk_widget_size_allocate (label_widget, &label_allocation); } }
static int hippo_canvas_widget_get_content_height_request(HippoCanvasBox *box, int for_width) { HippoCanvasWidget *widget = HIPPO_CANVAS_WIDGET(box); int children_height; int widget_height; GtkRequisition req; /* get height of children and the box padding */ children_height = HIPPO_CANVAS_BOX_CLASS(hippo_canvas_widget_parent_class)->get_content_height_request(box, for_width); if (widget->widget && GTK_WIDGET_VISIBLE(widget->widget)) { /* We know a get_height_request was done first, so we can * just get widget->requisition instead of doing the size request * computation again. */ gtk_widget_get_child_requisition(widget->widget, &req); widget_height = req.height; } else { widget_height = 0; } return MAX(widget_height, children_height); }
static void gtk_hex_entry_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { GtkHexEntry *hex_entry; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_HEX_ENTRY (widget)); g_return_if_fail (allocation != NULL); widget->allocation = *allocation; hex_entry = GTK_HEX_ENTRY (widget); if (GTK_WIDGET_REALIZED (widget)) { GtkRequisition requisition; gtk_widget_get_child_requisition (widget, &requisition); gdk_window_move_resize (widget->window, allocation->x, allocation->y, requisition.width, requisition.height); queue_draw (hex_entry); } }
static void cpaf_fixed_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { GtkFixed *fixed; GtkFixedChild *child; GtkAllocation child_allocation; GtkRequisition child_requisition; GList *children; guint16 border_width; fixed = GTK_FIXED (widget); widget->allocation = *allocation; if (!GTK_WIDGET_NO_WINDOW (widget)) { if (GTK_WIDGET_REALIZED (widget)) gdk_window_move_resize (widget->window, allocation->x, allocation->y, allocation->width, allocation->height); } border_width = GTK_CONTAINER (fixed)->border_width; children = fixed->children; while (children) { child = children->data; children = children->next; if (GTK_WIDGET_VISIBLE (child->widget)) { gtk_widget_get_child_requisition (child->widget, &child_requisition); child_allocation.x = child->x + border_width; child_allocation.y = child->y + border_width; child_allocation.height = child->widget->allocation.height; child_allocation.width = child->widget->allocation.width; /* Ensure that the allocation is not smaller than the requisition (CHECKME:) */ if (child_allocation.height < child_requisition.height) child_allocation.height = child_requisition.height; if (child_allocation.width < child_requisition.width) child_allocation.width = child_requisition.width; if (GTK_WIDGET_NO_WINDOW (widget)) { child_allocation.x += widget->allocation.x; child_allocation.y += widget->allocation.y; } gtk_widget_size_allocate (child->widget, &child_allocation); } } }
static void size_allocate(GtkWidget* widget, GtkAllocation* alloc) { wxPizza* pizza = WX_PIZZA(widget); int border_x, border_y; pizza->get_border_widths(border_x, border_y); int w = alloc->width - 2 * border_x; if (w < 0) w = 0; if (gtk_widget_get_realized(widget)) { int h = alloc->height - 2 * border_y; if (h < 0) h = 0; const int x = alloc->x + border_x; const int y = alloc->y + border_y; GdkWindow* window = gtk_widget_get_window(widget); int old_x, old_y; gdk_window_get_position(window, &old_x, &old_y); if (x != old_x || y != old_y || w != gdk_window_get_width(window) || h != gdk_window_get_height(window)) { gdk_window_move_resize(window, x, y, w, h); if (border_x + border_y) { // old and new border areas need to be invalidated, // otherwise they will not be erased/redrawn properly GdkWindow* parent = gtk_widget_get_parent_window(widget); gdk_window_invalidate_rect(parent, &widget->allocation, false); gdk_window_invalidate_rect(parent, alloc, false); } } } widget->allocation = *alloc; // adjust child positions for (const GList* list = pizza->m_fixed.children; list; list = list->next) { const GtkFixedChild* child = static_cast<GtkFixedChild*>(list->data); if (gtk_widget_get_visible(child->widget)) { GtkAllocation child_alloc; // note that child positions do not take border into // account, they need to be relative to widget->window, // which has already been adjusted child_alloc.x = child->x - pizza->m_scroll_x; child_alloc.y = child->y - pizza->m_scroll_y; GtkRequisition req; gtk_widget_get_child_requisition(child->widget, &req); child_alloc.width = req.width; child_alloc.height = req.height; if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL) child_alloc.x = w - child_alloc.x - child_alloc.width; gtk_widget_size_allocate(child->widget, &child_alloc); } } }
static VALUE rg_child_requisition(VALUE self) { GtkRequisition req; gtk_widget_get_child_requisition(_SELF(self), &req); return rb_ary_new3(2, INT2NUM(req.width), INT2NUM(req.height)); }
void GtkPopupMenu::popUp(const IntSize& menuSize, const IntPoint& menuPosition, int itemCount, int selectedItem, const GdkEvent* event) { resetTypeAheadFindState(); m_menuPosition = menuPosition; gtk_menu_set_active(GTK_MENU(m_popup.get()), selectedItem); // This approach follows the one in gtkcombobox.c. GtkRequisition requisition; gtk_widget_set_size_request(m_popup.get(), -1, -1); #ifdef GTK_API_VERSION_2 gtk_widget_size_request(m_popup.get(), &requisition); #else gtk_widget_get_preferred_size(m_popup.get(), &requisition, 0); #endif gtk_widget_set_size_request(m_popup.get(), std::max(menuSize.width(), requisition.width), -1); GList* children = gtk_container_get_children(GTK_CONTAINER(m_popup.get())); GList* p = children; if (itemCount) { for (int i = 0; i < itemCount; i++) { if (i > selectedItem) break; GtkWidget* item = reinterpret_cast<GtkWidget*>(p->data); GtkRequisition itemRequisition; #ifdef GTK_API_VERSION_2 gtk_widget_get_child_requisition(item, &itemRequisition); #else gtk_widget_get_preferred_size(item, &itemRequisition, 0); #endif m_menuPosition.setY(m_menuPosition.y() - itemRequisition.height); p = g_list_next(p); } } else { // Center vertically the empty popup in the combo box area. m_menuPosition.setY(m_menuPosition.y() - menuSize.height() / 2); } g_list_free(children); guint button; guint32 activateTime; if (event) { button = event->type == GDK_BUTTON_PRESS ? event->button.button : 1; activateTime = gdk_event_get_time(event); } else { button = 1; activateTime = GDK_CURRENT_TIME; } #ifdef GTK_API_VERSION_2 gtk_menu_popup(GTK_MENU(m_popup.get()), 0, 0, reinterpret_cast<GtkMenuPositionFunc>(menuPositionFunction), this, button, activateTime); #else gtk_menu_popup_for_device(GTK_MENU(m_popup.get()), event ? gdk_event_get_device(event) : 0, 0, 0, reinterpret_cast<GtkMenuPositionFunc>(menuPositionFunction), this, 0, button, activateTime); #endif }
static void gtk_hex_entry_realize (GtkWidget *widget) { GtkHexEntry *hex_entry; GtkRequisition requisition; GdkWindowAttr attributes; gint attributes_mask; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_HEX_ENTRY (widget)); GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); hex_entry = GTK_HEX_ENTRY (widget); gtk_widget_get_child_requisition (widget, &requisition); attributes.x = widget->allocation.x; attributes.y = widget->allocation.y; attributes.width = requisition.width; attributes.height = requisition.height; attributes.window_type = GDK_WINDOW_CHILD; attributes.wclass = GDK_INPUT_OUTPUT; attributes.visual = gtk_widget_get_visual (widget); attributes.colormap = gtk_widget_get_colormap (widget); attributes.cursor = hex_entry->cursor = gdk_cursor_new (GDK_XTERM); attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK | GDK_KEY_PRESS_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON1_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK; attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP | GDK_WA_CURSOR; widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); gdk_window_set_user_data (widget->window, hex_entry); widget->style = gtk_style_attach (widget->style, widget->window); gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]); gdk_window_set_back_pixmap (widget->window, NULL, TRUE); gdk_color_alloc (gtk_widget_get_colormap (widget),&hex_entry->cursor_color); hex_entry->gc = gdk_gc_new (widget->window); gdk_gc_set_foreground (hex_entry->gc,&hex_entry->cursor_color); }
static void gtk_widget_layoutable_size_allocate (GtkLayoutable *layoutable, GtkAllocation *allocation) { GtkWidget *widget; GtkRequisition requisition; widget = GTK_WIDGET (layoutable); gtk_widget_get_child_requisition (widget, &requisition); allocation->width = requisition.width; allocation->height = requisition.height; gtk_widget_size_allocate (widget, allocation); }
static void gtk_expander_realize (GtkWidget *widget) { GtkExpanderPrivate *priv; GdkWindowAttr attributes; gint attributes_mask; gint border_width; GdkRectangle expander_rect; gint label_height; priv = GTK_EXPANDER (widget)->priv; gtk_widget_set_realized (widget, TRUE); border_width = GTK_CONTAINER (widget)->border_width; get_expander_bounds (GTK_EXPANDER (widget), &expander_rect); if (priv->label_widget && gtk_widget_get_visible (priv->label_widget)) { GtkRequisition label_requisition; gtk_widget_get_child_requisition (priv->label_widget, &label_requisition); label_height = label_requisition.height; } else label_height = 0; attributes.window_type = GDK_WINDOW_CHILD; attributes.x = widget->allocation.x + border_width; attributes.y = widget->allocation.y + border_width; attributes.width = MAX (widget->allocation.width - 2 * border_width, 1); attributes.height = MAX (expander_rect.height, label_height - 2 * border_width); attributes.wclass = GDK_INPUT_ONLY; attributes.event_mask = gtk_widget_get_events (widget) | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK; attributes_mask = GDK_WA_X | GDK_WA_Y; widget->window = gtk_widget_get_parent_window (widget); g_object_ref (widget->window); priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); gdk_window_set_user_data (priv->event_window, widget); widget->style = gtk_style_attach (widget->style, widget->window); }
void ags_scrolled_scale_box_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { AgsScrolledScaleBox *scrolled_scale_box; GtkAllocation child_allocation; GtkRequisition child_requisition; scrolled_scale_box = AGS_SCROLLED_SCALE_BOX(widget); /* viewport allocation */ gtk_widget_get_child_requisition((GtkWidget *) scrolled_scale_box->viewport, &child_requisition); child_allocation.x = allocation->x; child_allocation.y = allocation->y; child_allocation.width = allocation->width; child_allocation.height = allocation->height; gtk_widget_size_allocate((GtkWidget *) scrolled_scale_box->viewport, &child_allocation); /* box */ gtk_widget_get_child_requisition((GtkWidget *) scrolled_scale_box->scale_box, &child_requisition); child_allocation.x = 0; child_allocation.y = 0; child_allocation.width = allocation->width; child_allocation.height = child_requisition.height; gtk_widget_size_allocate((GtkWidget *) scrolled_scale_box->scale_box, &child_allocation); }
static void applet_size_request (GtkWidget *widget, GtkRequisition *requisition, TasklistData *tasklist) { int len; const int *size_hints; GtkRequisition child_req; int i; int maximum_size; int *new_size_hints; int new_len = 0; WnckTasklist *wncktl = WNCK_TASKLIST (tasklist->tasklist); gint minimum_size = 0; if (tasklist->orientation == GTK_ORIENTATION_HORIZONTAL) minimum_size = wnck_tasklist_get_minimum_width (wncktl); else minimum_size = wnck_tasklist_get_minimum_height (wncktl); gtk_widget_get_child_requisition (tasklist->applet, &child_req); size_hints = wnck_tasklist_get_size_hint_list (wncktl, &len); new_size_hints = g_new0 (int, len); /* size_hints is an array of (max, min) int pairs * where min(i) > max (i+1) * convert it to clipped values */ maximum_size = tasklist->maximum_size - minimum_size; g_assert (maximum_size >= 0); for (i = 0; i < len; i += 2) { if (size_hints[i + 1] <= maximum_size) { /* this one should be stored */ if (size_hints[i] > maximum_size) new_size_hints[new_len] = maximum_size; else new_size_hints[new_len] = size_hints[i]; new_size_hints[new_len + 1] = size_hints[i + 1]; new_len += 2; } } panel_applet_set_size_hints (PANEL_APPLET (tasklist->applet), new_size_hints, new_len, child_req.width - 1); g_free (new_size_hints); }
static void get_text_area_size (GtkIconEntry *entry, GtkAllocation *alloc) { GtkWidget *widget = GTK_WIDGET (entry); GtkRequisition requisition; gint xborder, yborder; gtk_widget_get_child_requisition (widget, &requisition); get_borders (entry, &xborder, &yborder); alloc->x = xborder; alloc->y = yborder; alloc->width = widget->allocation.width - xborder * 2; alloc->height = requisition.height - yborder * 2; }
static void gtk_pizza_allocate_child (GtkPizza *pizza, GtkPizzaChild *child) { GtkAllocation allocation; GtkRequisition requisition; allocation.x = child->x - pizza->xoffset; allocation.y = child->y - pizza->yoffset; gtk_widget_get_child_requisition (child->widget, &requisition); allocation.width = requisition.width; allocation.height = requisition.height; gtk_widget_size_allocate (child->widget, &allocation); }
extern "C" WXDLLIMPEXP_CORE void wxPopupMenuPositionCallback( GtkMenu *menu, gint *x, gint *y, gpointer user_data ) { // ensure that the menu appears entirely on screen GtkRequisition req; gtk_widget_get_child_requisition(GTK_WIDGET(menu), &req); wxSize sizeScreen = wxGetDisplaySize(); wxPoint *pos = (wxPoint*)user_data; gint xmax = sizeScreen.x - req.width, ymax = sizeScreen.y - req.height; *x = pos->x < xmax ? pos->x : xmax; *y = pos->y < ymax ? pos->y : ymax; }
static void applet_size_request (GtkWidget *widget, GtkRequisition *requisition, TasklistData *tasklist) { int len; const int *size_hints; GtkRequisition child_req; WnckTasklist *wncktl = WNCK_TASKLIST (tasklist->tasklist); gtk_widget_get_child_requisition (tasklist->applet, &child_req); size_hints = wnck_tasklist_get_size_hint_list (wncktl, &len); g_assert (len % 2 == 0); panel_applet_set_size_hints (PANEL_APPLET (tasklist->applet), size_hints, len, 0); }
static void applet_size_request(GtkWidget* widget, GtkRequisition* requisition, TasklistData* tasklist) #endif { int len; const int* size_hints; #if GTK_CHECK_VERSION (3, 0, 0) size_hints = wnck_tasklist_get_size_hint_list (WNCK_TASKLIST (tasklist->tasklist), &len); #else GtkRequisition child_req; WnckTasklist* wncktl = WNCK_TASKLIST(tasklist->tasklist); gtk_widget_get_child_requisition(tasklist->applet, &child_req); size_hints = wnck_tasklist_get_size_hint_list(wncktl, &len); #endif g_assert(len % 2 == 0); mate_panel_applet_set_size_hints(MATE_PANEL_APPLET(tasklist->applet), size_hints, len, 0); }
static void gx_selector_size_request(GtkWidget *widget, GtkRequisition *requisition) { g_assert(GX_IS_SELECTOR(widget)); GxSelector *selector = GX_SELECTOR(widget); if (!selector->model) { return; } GxSelectorPrivate *priv = selector->priv; gx_selector_create_icon(selector); if (priv->req_ok) { gtk_widget_get_child_requisition(widget, requisition); } else { GtkTreeIter iter; gint width = selector->icon_width; gint height = selector->icon_height; GtkBorder selector_border; get_selector_border(widget, &selector_border); PangoLayout *l = gtk_widget_create_pango_layout(widget, NULL); gboolean found = gtk_tree_model_get_iter_first(selector->model, &iter); while (found) { PangoRectangle logical_rect; gchar *s; gtk_tree_model_get(selector->model, &iter, 0, &s, -1); pango_layout_set_text(l, s, -1); g_free(s); pango_layout_get_pixel_extents(l, NULL, &logical_rect); width = std::max(logical_rect.width, width); height = std::max(logical_rect.height, height); found = gtk_tree_model_iter_next(selector->model, &iter); } priv->textsize.width = width; priv->textsize.height = height; height = std::max(height, selector->icon_height); requisition->width = width + selector->icon_width + selector_border.left + selector_border.right + 3 * widget->style->xthickness; requisition->height = height + selector_border.top + selector_border.bottom + 2 * widget->style->ythickness; priv->req_ok = TRUE; g_object_unref(l); } }
static void hippo_canvas_widget_get_content_height_request(HippoCanvasBox *box, int for_width, int *min_height_p, int *natural_height_p) { HippoCanvasWidget *widget = HIPPO_CANVAS_WIDGET(box); int children_min_height, children_natural_height; int widget_height; GtkRequisition req; /* get height of children and the box padding */ HIPPO_CANVAS_BOX_CLASS(hippo_canvas_widget_parent_class)->get_content_height_request(box, for_width, &children_min_height, &children_natural_height); /* Note that we get the widget's size request even if the GTK widget visibility flag is * false; that's because we are slaving GTK visibility to whether we have a nonzero * allocation (canvas item visibility), so it would make a circular mess if * our size request depended on visibility. This means you can't set visibility * on the underlying GtkWidget and expect anything sensible to happen. */ if (widget->widget) { /* We know a get_height_request was done first, so we can * just get widget->requisition instead of doing the size request * computation again. */ gtk_widget_get_child_requisition(widget->widget, &req); widget_height = req.height; } else { widget_height = 0; } if (min_height_p) *min_height_p = MAX(widget_height, children_min_height); if (natural_height_p) *natural_height_p = MAX(widget_height, children_natural_height); }
static void gimp_frame_child_allocate (GtkFrame *frame, GtkAllocation *child_allocation) { GtkWidget *widget = GTK_WIDGET (frame); GtkWidget *label_widget = gtk_frame_get_label_widget (frame); GtkAllocation allocation; gint border_width; gint spacing = 0; gint indent = gimp_frame_get_indent (widget); gtk_widget_get_allocation (widget, &allocation); border_width = gtk_container_get_border_width (GTK_CONTAINER (frame)); if (label_widget && gtk_widget_get_visible (label_widget)) { GtkRequisition child_requisition; gtk_widget_get_child_requisition (label_widget, &child_requisition); spacing += child_requisition.height; } spacing += gimp_frame_get_label_spacing (frame); if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) child_allocation->x = border_width + indent; else child_allocation->x = border_width; child_allocation->y = border_width + spacing; child_allocation->width = MAX (1, allocation.width - 2 * border_width - indent); child_allocation->height = MAX (1, allocation.height - child_allocation->y - border_width); child_allocation->x += allocation.x; child_allocation->y += allocation.y; }
static void gtk_mirror_bin_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { GtkMirrorBin *bin = GTK_MIRROR_BIN (widget); gint border_width; gint w, h; gtk_widget_set_allocation (widget, allocation); border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); w = allocation->width - border_width * 2; h = allocation->height - border_width * 2; if (gtk_widget_get_realized (widget)) gdk_window_move_resize (gtk_widget_get_window (widget), allocation->x + border_width, allocation->y + border_width, w, h); if (bin->child && gtk_widget_get_visible (bin->child)) { GtkRequisition child_requisition; GtkAllocation child_allocation; gtk_widget_get_child_requisition (bin->child, &child_requisition); child_allocation.x = 0; child_allocation.y = 0; child_allocation.height = child_requisition.height; child_allocation.width = child_requisition.width; if (gtk_widget_get_realized (widget)) gdk_window_move_resize (bin->offscreen_window, allocation->x + border_width, allocation->y + border_width, child_allocation.width, child_allocation.height); gtk_widget_size_allocate (bin->child, &child_allocation); } }
static void gtk_mirror_bin_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { GtkMirrorBin *bin = GTK_MIRROR_BIN (widget); gint border_width; gint w, h; widget->allocation = *allocation; border_width = GTK_CONTAINER (widget)->border_width; w = allocation->width - border_width * 2; h = allocation->height - border_width * 2; if (GTK_WIDGET_REALIZED (widget)) gdk_window_move_resize (widget->window, allocation->x + border_width, allocation->y + border_width, w, h); if (bin->child && GTK_WIDGET_VISIBLE (bin->child)) { GtkRequisition child_requisition; GtkAllocation child_allocation; gtk_widget_get_child_requisition (bin->child, &child_requisition); child_allocation.x = 0; child_allocation.y = 0; child_allocation.height = child_requisition.height; child_allocation.width = child_requisition.width; if (GTK_WIDGET_REALIZED (widget)) gdk_window_move_resize (bin->offscreen_window, allocation->x + border_width, allocation->y + border_width, child_allocation.width, child_allocation.height); gtk_widget_size_allocate (bin->child, &child_allocation); } }
static void gtk_image_menu_item_toggle_size_request (GtkMenuItem *menu_item, gint *requisition) { GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (menu_item); GtkPackDirection pack_dir; if (GTK_IS_MENU_BAR (GTK_WIDGET (menu_item)->parent)) pack_dir = gtk_menu_bar_get_child_pack_direction (GTK_MENU_BAR (GTK_WIDGET (menu_item)->parent)); else pack_dir = GTK_PACK_DIRECTION_LTR; *requisition = 0; if (image_menu_item->image && gtk_widget_get_visible (image_menu_item->image)) { GtkRequisition image_requisition; guint toggle_spacing; gtk_widget_get_child_requisition (image_menu_item->image, &image_requisition); gtk_widget_style_get (GTK_WIDGET (menu_item), "toggle-spacing", &toggle_spacing, NULL); if (pack_dir == GTK_PACK_DIRECTION_LTR || pack_dir == GTK_PACK_DIRECTION_RTL) { if (image_requisition.width > 0) *requisition = image_requisition.width + toggle_spacing; } else { if (image_requisition.height > 0) *requisition = image_requisition.height + toggle_spacing; } } }
void PopupMenu::show(const IntRect& rect, FrameView* view, int index) { ASSERT(client()); if (!m_popup) { m_popup = GTK_MENU(gtk_menu_new()); #if GLIB_CHECK_VERSION(2,10,0) g_object_ref_sink(G_OBJECT(m_popup)); #else g_object_ref(G_OBJECT(m_popup)); gtk_object_sink(GTK_OBJECT(m_popup)); #endif g_signal_connect(m_popup, "unmap", G_CALLBACK(menuUnmapped), this); } else gtk_container_foreach(GTK_CONTAINER(m_popup), reinterpret_cast<GtkCallback>(menuRemoveItem), this); int x, y; gdk_window_get_origin(GTK_WIDGET(view->containingWindow())->window, &x, &y); m_menuPosition = view->contentsToWindow(rect.location()); m_menuPosition = IntPoint(m_menuPosition.x() + x, m_menuPosition.y() + y + rect.height()); m_indexMap.clear(); const int size = client()->listSize(); for (int i = 0; i < size; ++i) { GtkWidget* item; if (client()->itemIsSeparator(i)) item = gtk_separator_menu_item_new(); else item = gtk_menu_item_new_with_label(client()->itemText(i).utf8().data()); m_indexMap.add(item, i); g_signal_connect(item, "activate", G_CALLBACK(menuItemActivated), this); // FIXME: Apply the RenderStyle from client()->itemStyle(i) gtk_widget_set_sensitive(item, client()->itemIsEnabled(i)); gtk_menu_shell_append(GTK_MENU_SHELL(m_popup), item); gtk_widget_show(item); } gtk_menu_set_active(m_popup, index); // The size calls are directly copied from gtkcombobox.c which is LGPL GtkRequisition requisition; gtk_widget_set_size_request(GTK_WIDGET(m_popup), -1, -1); gtk_widget_size_request(GTK_WIDGET(m_popup), &requisition); gtk_widget_set_size_request(GTK_WIDGET(m_popup), MAX(rect.width(), requisition.width), -1); GList* children = GTK_MENU_SHELL(m_popup)->children; if (size) for (int i = 0; i < size; i++) { if (i > index) break; GtkWidget* item = reinterpret_cast<GtkWidget*>(children->data); GtkRequisition itemRequisition; gtk_widget_get_child_requisition(item, &itemRequisition); m_menuPosition.setY(m_menuPosition.y() - itemRequisition.height); children = g_list_next(children); } else // Center vertically the empty popup in the combo box area m_menuPosition.setY(m_menuPosition.y() - rect.height() / 2); gtk_menu_popup(m_popup, NULL, NULL, reinterpret_cast<GtkMenuPositionFunc>(menuPositionFunction), this, 0, gtk_get_current_event_time()); }
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); } }
static void gtk_offscreen_box_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { GtkOffscreenBox *offscreen_box; gint border_width; gint start_y; widget->allocation = *allocation; offscreen_box = GTK_OFFSCREEN_BOX (widget); border_width = GTK_CONTAINER (widget)->border_width; if (gtk_widget_get_realized (widget)) gdk_window_move_resize (widget->window, allocation->x + border_width, allocation->y + border_width, allocation->width - border_width * 2, allocation->height - border_width * 2); start_y = 0; if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1)) { GtkRequisition child_requisition; GtkAllocation child_allocation; gtk_widget_get_child_requisition (offscreen_box->child1, &child_requisition); child_allocation.x = child_requisition.width * (CHILD1_SIZE_SCALE - 1.0) / 2; child_allocation.y = start_y + child_requisition.height * (CHILD1_SIZE_SCALE - 1.0) / 2; child_allocation.width = MAX (1, (gint) widget->allocation.width - 2 * border_width); child_allocation.height = child_requisition.height; start_y += CHILD1_SIZE_SCALE * child_requisition.height; if (gtk_widget_get_realized (widget)) gdk_window_move_resize (offscreen_box->offscreen_window1, child_allocation.x, child_allocation.y, child_allocation.width, child_allocation.height); child_allocation.x = child_allocation.y = 0; gtk_widget_size_allocate (offscreen_box->child1, &child_allocation); } if (offscreen_box->child2 && gtk_widget_get_visible (offscreen_box->child2)) { GtkRequisition child_requisition; GtkAllocation child_allocation; gtk_widget_get_child_requisition (offscreen_box->child2, &child_requisition); child_allocation.x = child_requisition.width * (CHILD2_SIZE_SCALE - 1.0) / 2; child_allocation.y = start_y + child_requisition.height * (CHILD2_SIZE_SCALE - 1.0) / 2; child_allocation.width = MAX (1, (gint) widget->allocation.width - 2 * border_width); child_allocation.height = child_requisition.height; start_y += CHILD2_SIZE_SCALE * child_requisition.height; if (gtk_widget_get_realized (widget)) gdk_window_move_resize (offscreen_box->offscreen_window2, child_allocation.x, child_allocation.y, child_allocation.width, child_allocation.height); child_allocation.x = child_allocation.y = 0; gtk_widget_size_allocate (offscreen_box->child2, &child_allocation); } }
gint notification_window_open(const gchar *message, const gchar *submessage, guint timeout) { GtkWidget *window; GtkWidget *vbox; GtkWidget *msglabel; GtkWidget *sublabel; GdkRectangle rect; gint x, y; GtkRequisition requisition; if (notify_window.window) { notification_window_destroy(); } window = gtk_window_new(GTK_WINDOW_POPUP); gtk_window_set_title(GTK_WINDOW(window), _("Notification")); gtk_window_set_wmclass(GTK_WINDOW(window), "notification", "Sylpheed"); gtk_container_set_border_width(GTK_CONTAINER(window), 8); gtk_widget_set_events(window, GDK_EXPOSURE_MASK|GDK_BUTTON_MOTION_MASK|GDK_POINTER_MOTION_MASK|GDK_POINTER_MOTION_HINT_MASK|GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK|GDK_ENTER_NOTIFY_MASK|GDK_LEAVE_NOTIFY_MASK); gtk_window_set_skip_taskbar_hint(GTK_WINDOW(window), TRUE); gtk_window_set_gravity(GTK_WINDOW(window), GDK_GRAVITY_SOUTH_EAST); gtk_widget_set_size_request(window, NOTIFICATIONWINDOW_WIDTH, -1); gtk_widget_realize(window); gdk_window_set_type_hint(window->window, GDK_WINDOW_TYPE_HINT_NOTIFICATION); /* move window bottom-right */ get_work_area(&rect); x = rect.x + rect.width - NOTIFICATIONWINDOW_WIDTH - 2; if (x < 0) x = 0; y = rect.y + rect.height - NOTIFICATIONWINDOW_HEIGHT - 2; if (y < 0) y = 0; gtk_window_move(GTK_WINDOW(window), x, y); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(nwin_destroy_cb), NULL); g_signal_connect(G_OBJECT(window), "button_press_event", G_CALLBACK(nwin_button_pressed), NULL); g_signal_connect(G_OBJECT(window), "enter_notify_event", G_CALLBACK(nwin_entered), NULL); g_signal_connect(G_OBJECT(window), "motion_notify_event", G_CALLBACK(nwin_motion_notify), NULL); vbox = gtk_vbox_new(FALSE, 8); gtk_container_add(GTK_CONTAINER(window), vbox); msglabel = gtk_label_new(message); gtk_box_pack_start(GTK_BOX(vbox), msglabel, FALSE, FALSE, 0); sublabel = gtk_label_new(""); gtk_label_set_ellipsize(GTK_LABEL(sublabel), PANGO_ELLIPSIZE_END); gtk_label_set_markup(GTK_LABEL(sublabel), submessage); gtk_box_pack_start(GTK_BOX(vbox), sublabel, FALSE, FALSE, 0); gtk_label_set_justify(GTK_LABEL(sublabel), GTK_JUSTIFY_LEFT); gtk_misc_set_alignment(GTK_MISC(sublabel), 0.0, 0.5); gtk_widget_show_all(window); /* adjust window size and position */ gtk_widget_get_child_requisition(window, &requisition); notify_window.width = NOTIFICATIONWINDOW_WIDTH; notify_window.height = MAX(requisition.height, NOTIFICATIONWINDOW_HEIGHT); gtk_widget_set_size_request(window, NOTIFICATIONWINDOW_WIDTH, notify_window.height); y = rect.y + rect.height - notify_window.height - 2; if (y < 0) y = 0; gtk_window_move(GTK_WINDOW(window), x, y); if (timeout == 0) timeout = 1; notify_window.notify_tag = g_timeout_add(timeout * 1000, notify_timeout_cb, NULL); debug_print("notification window created\n"); notify_window.window = window; notify_window.msglabel = msglabel; notify_window.sublabel = sublabel; notify_window.x = x; notify_window.y = y; notify_window.fade_length = 0; notify_window.fade_count = 0; notify_window.notify_event_count = 0; notify_window.timeout = timeout; return 0; }
/* We use HILDON_CAPTION_SPACING to make it look a bit nicer */ static void hildon_caption_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { GtkAllocation child_alloc; GtkAllocation caption_alloc; GtkRequisition req, child_req = {0}; GtkWidget *child = NULL; HildonCaptionPrivate *priv = NULL; gboolean rtl; g_assert (HILDON_IS_CAPTION (widget)); priv = HILDON_CAPTION_GET_PRIVATE (widget); /* Get the rtl status */ rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL); /* Position the caption to its allocated location */ if (GTK_WIDGET_REALIZED (widget)) gdk_window_move_resize (widget->window, allocation->x + GTK_CONTAINER (widget)->border_width, allocation->y + GTK_CONTAINER (widget)->border_width, MAX (allocation->width - GTK_CONTAINER (widget)->border_width * 2, 0), MAX (allocation->height - GTK_CONTAINER (widget)->border_width * 2, 0)); child = GTK_BIN (widget)->child; if (child) gtk_widget_get_child_requisition (child, &child_req); widget->allocation = *allocation; gtk_widget_get_child_requisition (priv->caption_area, &req); child_alloc.height = caption_alloc.height = allocation->height; child_alloc.width = caption_alloc.width = allocation->width; child_alloc.x = caption_alloc.x = caption_alloc.y = child_alloc.y = 0; /* Center the captioned widget */ if (rtl) { if (caption_alloc.width > child_req.width + HILDON_CAPTION_SPACING) { caption_alloc.x = caption_alloc.width - req.width; child_alloc.width = child_req.width; } caption_alloc.width -= child_req.width + HILDON_CAPTION_SPACING * 2; } else { if (child_alloc.width > req.width + HILDON_CAPTION_SPACING) { child_alloc.x += req.width + HILDON_CAPTION_SPACING * 2; caption_alloc.width = req.width; } /* Leave at least the space of the HILDON_CAPTION_SPACING in the left */ caption_alloc.x = HILDON_CAPTION_SPACING; /* Leave room for the other drawable parts of the caption control */ child_alloc.width -= req.width + HILDON_CAPTION_SPACING * 2; } /* Give the child at least its minimum requisition, unless it is expandable */ if (! priv->expand && child && GTK_WIDGET_VISIBLE(child)) { child_alloc.width = MIN (child_alloc.width, child_req.width); child_alloc.height = MIN (child_alloc.height, child_req.height); /* Center the child */ child_alloc.y = (allocation->height - child_alloc.height - 2 * GTK_CONTAINER (widget)->border_width)/2; } /* Ensure there are no negative dimensions */ if (child_alloc.width < 0) { caption_alloc.width = req.width + child_alloc.width; child_alloc.width = 0; caption_alloc.width = MAX (caption_alloc.width, 0); } if (rtl) child_alloc.x = caption_alloc.x - child_req.width - HILDON_CAPTION_SPACING * 2; child_alloc.height = MAX (child_alloc.height, 0); caption_alloc.height = MAX (caption_alloc.height, 0); if (child && GTK_WIDGET_VISIBLE(child) ) gtk_widget_size_allocate (child, &child_alloc ); gtk_widget_size_allocate (priv->caption_area, &caption_alloc); }
static void matenu_menu_bar_real_size_allocate (GtkWidget* base, GdkRectangle* a) { MatenuMenuBar * self; gboolean need_reset_bg_pixmap; gint delta_x; gint delta_y; gboolean _tmp0_ = FALSE; gboolean _tmp1_ = FALSE; gboolean _tmp2_ = FALSE; GdkRectangle _tmp3_ = {0}; GdkRectangle oa; GtkRequisition or = {0}; self = (MatenuMenuBar*) base; need_reset_bg_pixmap = FALSE; delta_x = (*a).x - ((GtkWidget*) self)->allocation.x; delta_y = (*a).y - ((GtkWidget*) self)->allocation.y; if (delta_x != 0) { _tmp2_ = TRUE; } else { _tmp2_ = delta_y != 0; } if (_tmp2_) { _tmp1_ = TRUE; } else { _tmp1_ = (*a).width != ((GtkWidget*) self)->allocation.width; } if (_tmp1_) { _tmp0_ = TRUE; } else { _tmp0_ = (*a).height != ((GtkWidget*) self)->allocation.height; } if (_tmp0_) { need_reset_bg_pixmap = TRUE; } matenu_menu_bar_get_background (self)->offset_x = matenu_menu_bar_get_background (self)->offset_x + delta_x; matenu_menu_bar_get_background (self)->offset_y = matenu_menu_bar_get_background (self)->offset_y + delta_y; GTK_WIDGET_CLASS (matenu_menu_bar_parent_class)->size_allocate ((GtkWidget*) GTK_MENU_BAR (self), a); oa = (_tmp3_.x = 0, _tmp3_.y = 0, _tmp3_.width = 0, _tmp3_.height = 0, _tmp3_); gtk_widget_get_child_requisition ((GtkWidget*) self->priv->_overflown_arrow, &or); switch (gtk_menu_bar_get_pack_direction ((GtkMenuBar*) self)) { case GTK_PACK_DIRECTION_TTB: { oa.height = or.height; oa.width = (*a).width; oa.x = 0; oa.y = (*a).height - oa.height; break; } case GTK_PACK_DIRECTION_BTT: { oa.height = or.height; oa.width = (*a).width; oa.x = 0; oa.y = 0; break; } case GTK_PACK_DIRECTION_RTL: { oa.height = (*a).height; oa.width = or.width; oa.x = 0; oa.y = 0; break; } default: { oa.width = or.width; oa.height = (*a).height; oa.x = (*a).width - oa.width; oa.y = 0; break; } } gtk_widget_size_allocate ((GtkWidget*) self->priv->_overflown_arrow, &oa); if (matenu_menu_bar_get_overflown (self)) { gtk_widget_set_child_visible ((GtkWidget*) self->priv->_overflown_arrow, TRUE); { gint i; i = 0; { gboolean _tmp4_; _tmp4_ = TRUE; while (TRUE) { MatenuItem* item; MatenuItem* _tmp5_; GtkWidget* child; if (!_tmp4_) { i++; } _tmp4_ = FALSE; if (!(i < matenu_shell_get_length ((MatenuShell*) self))) { break; } item = matenu_shell_get_item ((MatenuShell*) self, i); child = _g_object_ref0 ((_tmp5_ = item, GTK_IS_WIDGET (_tmp5_) ? ((GtkWidget*) _tmp5_) : NULL)); gtk_widget_set_child_visible (child, !matenu_menu_bar_child_need_overflown_arrow (self, child)); _g_object_unref0 (child); _g_object_unref0 (item); } } } } else { gtk_widget_set_child_visible ((GtkWidget*) self->priv->_overflown_arrow, FALSE); { gint i; i = 0; { gboolean _tmp6_; _tmp6_ = TRUE; while (TRUE) { MatenuItem* item; MatenuItem* _tmp7_; GtkWidget* child; if (!_tmp6_) { i++; } _tmp6_ = FALSE; if (!(i < matenu_shell_get_length ((MatenuShell*) self))) { break; } item = matenu_shell_get_item ((MatenuShell*) self, i); child = _g_object_ref0 ((_tmp7_ = item, GTK_IS_WIDGET (_tmp7_) ? ((GtkWidget*) _tmp7_) : NULL)); gtk_widget_set_child_visible (child, TRUE); _g_object_unref0 (child); _g_object_unref0 (item); } } } } if (need_reset_bg_pixmap) { matenu_menu_bar_reset_bg_pixmap (self); } }