static void gtk_image_menu_item_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (widget); GtkImageMenuItemPrivate *priv = image_menu_item->priv; GtkAllocation widget_allocation; GtkPackDirection pack_dir; GtkWidget *parent; parent = gtk_widget_get_parent (widget); if (GTK_IS_MENU_BAR (parent)) pack_dir = gtk_menu_bar_get_child_pack_direction (GTK_MENU_BAR (parent)); else pack_dir = GTK_PACK_DIRECTION_LTR; GTK_WIDGET_CLASS (gtk_image_menu_item_parent_class)->size_allocate (widget, allocation); if (priv->image && gtk_widget_get_visible (priv->image)) { gint x, y, offset; GtkStyleContext *context; GtkStateFlags state; GtkBorder padding; GtkRequisition child_requisition; GtkAllocation child_allocation; guint toggle_spacing; gint toggle_size; toggle_size = GTK_MENU_ITEM (image_menu_item)->priv->toggle_size; gtk_widget_style_get (widget, "toggle-spacing", &toggle_spacing, NULL); /* Man this is lame hardcoding action, but I can't * come up with a solution that's really better. */ gtk_widget_get_preferred_size (priv->image, &child_requisition, NULL); gtk_widget_get_allocation (widget, &widget_allocation); context = gtk_widget_get_style_context (widget); state = gtk_widget_get_state_flags (widget); gtk_style_context_get_padding (context, state, &padding); offset = gtk_container_get_border_width (GTK_CONTAINER (image_menu_item)); if (pack_dir == GTK_PACK_DIRECTION_LTR || pack_dir == GTK_PACK_DIRECTION_RTL) { if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) == (pack_dir == GTK_PACK_DIRECTION_LTR)) x = offset + padding.left + (toggle_size - toggle_spacing - child_requisition.width) / 2; else x = widget_allocation.width - offset - padding.right - toggle_size + toggle_spacing + (toggle_size - toggle_spacing - child_requisition.width) / 2; y = (widget_allocation.height - child_requisition.height) / 2; } else { if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) == (pack_dir == GTK_PACK_DIRECTION_TTB)) y = offset + padding.top + (toggle_size - toggle_spacing - child_requisition.height) / 2; else y = widget_allocation.height - offset - padding.bottom - toggle_size + toggle_spacing + (toggle_size - toggle_spacing - child_requisition.height) / 2; x = (widget_allocation.width - child_requisition.width) / 2; } child_allocation.width = child_requisition.width; child_allocation.height = child_requisition.height; child_allocation.x = widget_allocation.x + MAX (x, 0); child_allocation.y = widget_allocation.y + MAX (y, 0); gtk_widget_size_allocate (priv->image, &child_allocation); } }
/* Border Function For Notebooks Tabs */ void hc_draw_extension (GtkStyle *style, cairo_t *cr, GtkStateType state_type, GtkShadowType shadow_type, GtkWidget *widget, const gchar *detail, gint x, gint y, gint width, gint height, GtkPositionType gap_side) { /* Fill Uses Background Color */ CairoColor *background = &HC_STYLE(style)->color_cube.bg[state_type]; /* Border Uses Foreground Color */ CairoColor *foreground = &HC_STYLE(style)->color_cube.fg[state_type]; gint line_width; gint widget_x = 0, widget_y = 0, widget_width = 0, widget_height = 0; gint clip_x = x, clip_y = y, clip_width = width, clip_height = height; /***********************************************/ /* GTK Sanity Checks */ /***********************************************/ CHECK_ARGS /***********************************************/ /* GTK Special Cases - adjust Size/Offset */ /***********************************************/ line_width = HC_STYLE(style)->edge_thickness; /* What all this is for - GTK doesn't overlap Extensions and Notebooks, but rather a tab is drawn with a "gap" side. Instead of long draw cases per gap side, perform a standard draw, but clipped to size, and overdraw edge thickness + one on gap side. To fake the apearance of overlap on edge aligned tabs increase clip by edge thickness on gap side. */ if (widget && (GE_IS_NOTEBOOK (widget))) { GtkAllocation allocation; gtk_widget_get_allocation (widget, &allocation); widget_x = (allocation.x + gtk_container_get_border_width (GTK_CONTAINER (widget))); widget_y = (allocation.y + gtk_container_get_border_width (GTK_CONTAINER (widget))); widget_width = (allocation.width - 2*gtk_container_get_border_width (GTK_CONTAINER (widget))); widget_height = (allocation.height - 2*gtk_container_get_border_width (GTK_CONTAINER (widget))); } switch (gap_side) { case GTK_POS_TOP: if (GTK_CHECK_VERSION(2,10,0) || ((widget && GE_IS_NOTEBOOK (widget)) && ((x==widget_x) || ((x + width) == (widget_x + widget_width))))) { clip_height += line_width; if (!GTK_CHECK_VERSION(2,10,0)) { height -= floor(line_width/2.0); } } y -= (line_width + 1); height += (line_width + 1); break; case GTK_POS_LEFT: if (GTK_CHECK_VERSION(2,10,0) || ((widget && GE_IS_NOTEBOOK (widget)) && ((y==widget_y) || ((y + height) == (widget_y + widget_height))))) { clip_width += line_width; if (!GTK_CHECK_VERSION(2,10,0)) { x -= floor(line_width/2.0); } } x -= (line_width + 1); width += (line_width + 1); break; default: case GTK_POS_BOTTOM: height += (line_width + 1); break; case GTK_POS_RIGHT: width += (line_width + 1); break; } /***********************************************/ /* Draw Border */ /***********************************************/ /* Clip Too Size */ cairo_rectangle(cr, clip_x, clip_y, clip_width, clip_height); cairo_clip(cr); /* Set Fill Style */ ge_cairo_set_color(cr, background); /* Fill Rectangle */ cairo_rectangle (cr, x, y, width, height); cairo_fill(cr); /* Set Line Style */ ge_cairo_set_color(cr, foreground); cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); cairo_set_line_width (cr, line_width); ge_cairo_inner_rectangle (cr, x, y, width, height); cairo_stroke(cr); }
int wxNotebook::HitTest(const wxPoint& pt, long *flags) const { GtkAllocation a; gtk_widget_get_allocation(m_widget, &a); const int x = a.x; const int y = a.y; const size_t count = GetPageCount(); size_t i = 0; #ifndef __WXGTK3__ GtkNotebook * notebook = GTK_NOTEBOOK(m_widget); if (gtk_notebook_get_scrollable(notebook)) i = g_list_position( notebook->children, notebook->first_tab ); #endif for ( ; i < count; i++ ) { wxGtkNotebookPage* pageData = GetNotebookPage(i); GtkWidget* box = pageData->m_box; const gint border = gtk_container_get_border_width(GTK_CONTAINER(box)); if ( IsPointInsideWidget(pt, box, x, y, border) ) { // ok, we're inside this tab -- now find out where, if needed if ( flags ) { if (pageData->m_image && IsPointInsideWidget(pt, pageData->m_image, x, y)) { *flags = wxBK_HITTEST_ONICON; } else if (IsPointInsideWidget(pt, pageData->m_label, x, y)) { *flags = wxBK_HITTEST_ONLABEL; } else { *flags = wxBK_HITTEST_ONITEM; } } return i; } } if ( flags ) { *flags = wxBK_HITTEST_NOWHERE; wxWindowBase * page = GetCurrentPage(); if ( page ) { // rect origin is in notebook's parent coordinates wxRect rect = page->GetRect(); // adjust it to the notebook's coordinates wxPoint pos = GetPosition(); rect.x -= pos.x; rect.y -= pos.y; if ( rect.Contains( pt ) ) *flags |= wxBK_HITTEST_ONPAGE; } } return wxNOT_FOUND; }
static void ViewAutoDrawerUpdate(ViewAutoDrawer *that, // IN gboolean immediate) // IN { ViewAutoDrawerPrivate *priv = that->priv; GtkWidget *toplevel = gtk_widget_get_toplevel(GTK_WIDGET(that)); GtkWindow *window; if (!toplevel || !gtk_widget_is_toplevel(toplevel)) { // The autoDrawer cannot function properly without a toplevel. return; } window = GTK_WINDOW(toplevel); /* * We decide to open the drawer by OR'ing several conditions. Evaluating a * condition can have the side-effect of setting 'immediate' to TRUE, so we * cannot stop evaluating the conditions after we have found one to be TRUE. */ priv->opened = FALSE; /* Is the AutoDrawer pinned? */ if (priv->pinned) { immediate = TRUE; priv->opened = TRUE; } /* Is the mouse cursor inside the event box? */ { int x; int y; gtk_widget_get_pointer(priv->evBox, &x, &y); g_assert(gtk_container_get_border_width( GTK_CONTAINER(priv->evBox)) == 0); if ( (guint)x < (guint)priv->evBox->allocation.width && (guint)y < (guint)priv->evBox->allocation.height) { priv->opened = TRUE; } } /* If there is a focused widget, is it inside the event box? */ { GtkWidget *focus; focus = gtk_window_get_focus(window); if (focus && gtk_widget_is_ancestor(focus, priv->evBox)) { /* * Override the default 'immediate' to make sure the 'over' widget * immediately appears along with the widget the focused widget. */ immediate = TRUE; priv->opened = TRUE; } } /* If input is grabbed, is it on behalf of a widget inside the event box? */ if (!priv->inputUngrabbed) { GtkWidget *grabbed = NULL; if (window->group && window->group->grabs) { grabbed = GTK_WIDGET(window->group->grabs->data); } if (!grabbed) { grabbed = gtk_grab_get_current(); } // g_assert(grabbed); if (GTK_IS_MENU(grabbed)) { /* * With cascading menus, the deepest menu owns the grab. Traverse the * menu hierarchy up until we reach the attach widget for the whole * hierarchy. */ for (;;) { GtkWidget *menuAttach; GtkWidget *menuItemParent; menuAttach = gtk_menu_get_attach_widget(GTK_MENU(grabbed)); if (!menuAttach) { /* * It is unfortunately not mandatory for a menu to have a proper * attach widget set. */ break; } grabbed = menuAttach; if (!GTK_IS_MENU_ITEM(grabbed)) { break; } menuItemParent = gtk_widget_get_parent(grabbed); g_return_if_fail(menuItemParent); if (!GTK_IS_MENU(menuItemParent)) { break; } grabbed = menuItemParent; } } if (gtk_widget_is_ancestor(grabbed, priv->evBox)) { /* * Override the default 'immediate' to make sure the 'over' widget * immediately appears along with the widget the grab happens on * behalf of. */ immediate = TRUE; priv->opened = TRUE; } } if (priv->delayConnection) { g_source_remove(priv->delayConnection); } if (immediate) { ViewAutoDrawerEnforce(that, FALSE); } else { priv->delayConnection = g_timeout_add(priv->delayValue, (GSourceFunc)ViewAutoDrawerOnEnforceDelay, that); } }
static gboolean gimp_color_bar_expose (GtkWidget *widget, GdkEventExpose *event) { GimpColorBar *bar = GIMP_COLOR_BAR (widget); cairo_t *cr; GtkAllocation allocation; cairo_surface_t *surface; cairo_pattern_t *pattern; guchar *src; guchar *dest; gint x, y; gint width, height; gint i; cr = gdk_cairo_create (event->window); gdk_cairo_region (cr, event->region); cairo_clip (cr); gtk_widget_get_allocation (widget, &allocation); x = y = gtk_container_get_border_width (GTK_CONTAINER (bar)); width = allocation.width - 2 * x; height = allocation.height - 2 * y; if (width < 1 || height < 1) return TRUE; cairo_translate (cr, allocation.x + x, allocation.y + y); cairo_rectangle (cr, 0, 0, width, height); cairo_clip (cr); surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 256, 1); for (i = 0, src = bar->buf, dest = cairo_image_surface_get_data (surface); i < 256; i++, src += 3, dest += 4) { GIMP_CAIRO_RGB24_SET_PIXEL(dest, src[0], src[1], src[2]); } cairo_surface_mark_dirty (surface); pattern = cairo_pattern_create_for_surface (surface); cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REFLECT); cairo_surface_destroy (surface); if (bar->orientation == GTK_ORIENTATION_HORIZONTAL) { cairo_scale (cr, (gdouble) width / 256.0, 1.0); } else { cairo_translate (cr, 0, height); cairo_scale (cr, 1.0, (gdouble) height / 256.0); cairo_rotate (cr, - G_PI / 2); } cairo_set_source (cr, pattern); cairo_pattern_destroy (pattern); cairo_paint (cr); cairo_destroy (cr); return TRUE; }
static void panel_frame_get_preferred_height (GtkWidget *widget, gint *minimal_height, gint *natural_height) { PanelFrame *frame = (PanelFrame *) widget; GtkBin *bin = (GtkBin *) widget; GtkStyleContext *context; GtkWidget *child; GtkBorder padding; int border_width; context = gtk_widget_get_style_context (widget); gtk_style_context_get_padding (context, gtk_widget_get_state_flags (widget), &padding); border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); *minimal_height = 1; *natural_height = 1; child = gtk_bin_get_child (bin); if (child && gtk_widget_get_visible (child)) gtk_widget_get_preferred_height (child, minimal_height, natural_height); *minimal_height += border_width; *natural_height += border_width; if (frame->edges & PANEL_EDGE_TOP) { *minimal_height += padding.top; *natural_height += padding.top; } if (frame->edges & PANEL_EDGE_BOTTOM) { *minimal_height += padding.bottom; *natural_height += padding.bottom; } }
void gimp_overlay_child_size_allocate (GimpOverlayBox *box, GimpOverlayChild *child) { GtkWidget *widget; GtkAllocation allocation; GtkRequisition child_requisition; GtkAllocation child_allocation; gint x; gint y; g_return_if_fail (GIMP_IS_OVERLAY_BOX (box)); g_return_if_fail (child != NULL); widget = GTK_WIDGET (box); gtk_widget_get_allocation (widget, &allocation); gtk_widget_get_child_requisition (child->widget, &child_requisition); child_allocation.x = 0; child_allocation.y = 0; child_allocation.width = child_requisition.width; child_allocation.height = child_requisition.height; gtk_widget_size_allocate (child->widget, &child_allocation); gtk_widget_get_allocation (child->widget, &child_allocation); if (gtk_widget_get_realized (GTK_WIDGET (widget))) { GdkRectangle old_allocation; GdkRectangle old_bounds; gdk_window_get_position (child->window, &old_allocation.x, &old_allocation.y); old_allocation.width = gdk_window_get_width (child->window); old_allocation.height = gdk_window_get_height (child->window); gimp_overlay_child_transform_bounds (child, &old_allocation, &old_bounds); gdk_window_invalidate_rect (gtk_widget_get_window (widget), &old_bounds, FALSE); gdk_window_move_resize (child->window, child_allocation.x, child_allocation.y, child_allocation.width, child_allocation.height); } cairo_matrix_init_identity (&child->matrix); /* local transform */ cairo_matrix_rotate (&child->matrix, child->angle); if (child->has_position) { x = child->x; y = child->y; } else { GdkRectangle bounds; gint border; gint available_width; gint available_height; gimp_overlay_child_transform_bounds (child, &child_allocation, &bounds); border = gtk_container_get_border_width (GTK_CONTAINER (box)); available_width = allocation.width - 2 * border; available_height = allocation.height - 2 * border; x = border; y = border; if (available_width > bounds.width) x += child->xalign * (available_width - bounds.width) - bounds.x; if (available_height > bounds.height) y += child->yalign * (available_height - bounds.height) - bounds.y; } cairo_matrix_init_translate (&child->matrix, x, y); /* local transform */ cairo_matrix_rotate (&child->matrix, child->angle); }
static void wrap_table_layout (EelWrapTable *wrap_table) { GList *iterator; EelIPoint pos; EelDimensions max_child_dimensions; EelIRect content_bounds; guint num_cols; GtkAllocation allocation; g_assert (EEL_IS_WRAP_TABLE (wrap_table)); max_child_dimensions = wrap_table_get_max_child_dimensions (wrap_table); max_child_dimensions.width = MAX (max_child_dimensions.width, 1); max_child_dimensions.height = MAX (max_child_dimensions.height, 1); content_bounds = wrap_table_get_content_bounds (wrap_table); pos.x = content_bounds.x0; pos.y = content_bounds.y0; gtk_widget_get_allocation (GTK_WIDGET (wrap_table), &allocation); num_cols = wrap_table_get_num_fitting (allocation.width - gtk_container_get_border_width (GTK_CONTAINER (wrap_table)) * 2, wrap_table->details->x_spacing, max_child_dimensions.width); if (num_cols != wrap_table->details->cols) { wrap_table->details->cols = num_cols; gtk_widget_queue_resize (GTK_WIDGET (wrap_table)); return; } for (iterator = wrap_table->details->children; iterator; iterator = iterator->next) { GtkWidget *item; item = iterator->data; if (gtk_widget_get_visible (item)) { GtkAllocation item_allocation; if (wrap_table->details->homogeneous) { item_allocation.x = pos.x; item_allocation.y = pos.y; item_allocation.width = max_child_dimensions.width; item_allocation.height = max_child_dimensions.height; if ((pos.x + max_child_dimensions.width) > content_bounds.x1) { pos.x = content_bounds.x0 + wrap_table->details->x_spacing + max_child_dimensions.width; pos.y += (max_child_dimensions.height + wrap_table->details->y_spacing); item_allocation.x = content_bounds.x0; item_allocation.y = pos.y; } else { pos.x += (wrap_table->details->x_spacing + max_child_dimensions.width); } } else { GtkRequisition item_requisition; gtk_widget_size_request (item, &item_requisition); item_allocation.x = pos.x; item_allocation.y = pos.y; item_allocation.width = item_requisition.width; item_allocation.height = item_requisition.height; g_assert (item_allocation.width <= max_child_dimensions.width); g_assert (item_allocation.height <= max_child_dimensions.height); if ((pos.x + max_child_dimensions.width) > content_bounds.x1) { pos.x = content_bounds.x0 + wrap_table->details->x_spacing + max_child_dimensions.width; pos.y += (max_child_dimensions.height + wrap_table->details->y_spacing); item_allocation.x = content_bounds.x0; item_allocation.y = pos.y; } else { pos.x += (wrap_table->details->x_spacing + max_child_dimensions.width); } switch (wrap_table->details->x_justification) { case EEL_JUSTIFICATION_MIDDLE: item_allocation.x += (max_child_dimensions.width - (int) item_allocation.width) / 2; break; case EEL_JUSTIFICATION_END: item_allocation.x += (max_child_dimensions.width - (int) item_allocation.width); break; default: break; } switch (wrap_table->details->y_justification) { case EEL_JUSTIFICATION_MIDDLE: item_allocation.y += (max_child_dimensions.height - (int) item_allocation.height) / 2; break; case EEL_JUSTIFICATION_END: item_allocation.y += (max_child_dimensions.height - (int) item_allocation.height); break; default: break; } } gtk_widget_size_allocate (item, &item_allocation); } } }
static void gtk_offscreen_box_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { GtkOffscreenBox *offscreen_box; gint start_y; guint border_width; offscreen_box = GTK_OFFSCREEN_BOX (widget); gtk_widget_set_allocation (widget, allocation); border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); if (gtk_widget_get_realized (widget)) gdk_window_move_resize (gtk_widget_get_window (widget), 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_preferred_size (offscreen_box->child1, &child_requisition, NULL); 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) 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_preferred_size (offscreen_box->child2, &child_requisition, NULL); 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) 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); } }
static void gtk_real_check_menu_item_draw_indicator (GtkCheckMenuItem *check_menu_item, cairo_t *cr) { GtkCheckMenuItemPrivate *priv = check_menu_item->priv; GtkWidget *widget; gint x, y; widget = GTK_WIDGET (check_menu_item); if (gtk_widget_is_drawable (widget)) { GtkAllocation allocation; GtkStyleContext *context; guint border_width; guint offset; guint toggle_size; guint toggle_spacing; guint horizontal_padding; guint indicator_size; GtkStateFlags state; GtkBorder padding; context = gtk_widget_get_style_context (widget); state = gtk_widget_get_state_flags (widget); gtk_style_context_get_padding (context, state, &padding); gtk_widget_get_allocation (widget, &allocation); gtk_widget_style_get (widget, "toggle-spacing", &toggle_spacing, "horizontal-padding", &horizontal_padding, "indicator-size", &indicator_size, NULL); toggle_size = GTK_MENU_ITEM (check_menu_item)->priv->toggle_size; border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); offset = border_width + padding.left + 2; if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) { x = offset + horizontal_padding + (toggle_size - toggle_spacing - indicator_size) / 2; } else { x = allocation.width - offset - horizontal_padding - toggle_size + toggle_spacing + (toggle_size - toggle_spacing - indicator_size) / 2; } y = (allocation.height - indicator_size) / 2; gtk_style_context_save (context); if (priv->inconsistent) state |= GTK_STATE_FLAG_INCONSISTENT; else if (priv->active) state |= GTK_STATE_FLAG_ACTIVE; gtk_style_context_set_state (context, state); if (priv->draw_as_radio) { gtk_style_context_add_class (context, GTK_STYLE_CLASS_RADIO); gtk_render_option (context, cr, x, y, indicator_size, indicator_size); } else { gtk_style_context_add_class (context, GTK_STYLE_CLASS_CHECK); gtk_render_check (context, cr, x, y, indicator_size, indicator_size); } gtk_style_context_restore (context); } }
static void gtk_offscreen_box_realize (GtkWidget *widget) { GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget); GtkAllocation allocation, child_area; GdkWindow *window; GdkWindowAttr attributes; gint attributes_mask; guint border_width; GtkRequisition child_requisition; int start_y = 0; gtk_widget_set_realized (widget, TRUE); border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); gtk_widget_get_allocation (widget, &allocation); attributes.x = allocation.x + border_width; attributes.y = allocation.y + border_width; attributes.width = allocation.width - 2 * border_width; attributes.height = allocation.height - 2 * border_width; attributes.window_type = GDK_WINDOW_CHILD; attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_SCROLL_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK; attributes.visual = gtk_widget_get_visual (widget); attributes.wclass = GDK_INPUT_OUTPUT; attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL; window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); gtk_widget_set_window (widget, window); gdk_window_set_user_data (window, widget); g_signal_connect (window, "pick-embedded-child", G_CALLBACK (pick_offscreen_child), offscreen_box); attributes.window_type = GDK_WINDOW_OFFSCREEN; /* Child 1 */ attributes.x = attributes.y = 0; if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1)) { gtk_widget_get_allocation (offscreen_box->child1, &child_area); attributes.width = child_area.width; attributes.height = child_area.height; start_y += child_area.height; } offscreen_box->offscreen_window1 = gdk_window_new (gdk_screen_get_root_window (gtk_widget_get_screen (widget)), &attributes, attributes_mask); gdk_window_set_user_data (offscreen_box->offscreen_window1, widget); if (offscreen_box->child1) gtk_widget_set_parent_window (offscreen_box->child1, offscreen_box->offscreen_window1); gdk_offscreen_window_set_embedder (offscreen_box->offscreen_window1, window); g_signal_connect (offscreen_box->offscreen_window1, "to-embedder", G_CALLBACK (offscreen_window_to_parent1), offscreen_box); g_signal_connect (offscreen_box->offscreen_window1, "from-embedder", G_CALLBACK (offscreen_window_from_parent1), offscreen_box); /* Child 2 */ attributes.y = start_y; child_requisition.width = child_requisition.height = 0; if (offscreen_box->child2 && gtk_widget_get_visible (offscreen_box->child2)) { gtk_widget_get_allocation (offscreen_box->child2, &child_area); attributes.width = child_area.width; attributes.height = child_area.height; } offscreen_box->offscreen_window2 = gdk_window_new (gdk_screen_get_root_window (gtk_widget_get_screen (widget)), &attributes, attributes_mask); gdk_window_set_user_data (offscreen_box->offscreen_window2, widget); if (offscreen_box->child2) gtk_widget_set_parent_window (offscreen_box->child2, offscreen_box->offscreen_window2); gdk_offscreen_window_set_embedder (offscreen_box->offscreen_window2, window); g_signal_connect (offscreen_box->offscreen_window2, "create-surface", G_CALLBACK (gdk_offscreen_box_create_alpha_image_surface), offscreen_box); g_signal_connect (offscreen_box->offscreen_window2, "to-embedder", G_CALLBACK (offscreen_window_to_parent2), offscreen_box); g_signal_connect (offscreen_box->offscreen_window2, "from-embedder", G_CALLBACK (offscreen_window_from_parent2), offscreen_box); gdk_window_show (offscreen_box->offscreen_window1); gdk_window_show (offscreen_box->offscreen_window2); }
static gboolean gtk_tearoff_menu_item_draw (GtkWidget *widget, cairo_t *cr) { GtkMenuItem *menu_item; GtkStateFlags state; GtkStyleContext *context; GtkBorder padding; gint x, y, width, height; gint right_max; guint border_width; GtkTextDirection direction; GtkWidget *parent; gdouble angle; menu_item = GTK_MENU_ITEM (widget); context = gtk_widget_get_style_context (widget); direction = gtk_widget_get_direction (widget); state = gtk_widget_get_state_flags (widget); border_width = gtk_container_get_border_width (GTK_CONTAINER (menu_item)); x = border_width; y = border_width; width = gtk_widget_get_allocated_width (widget) - border_width * 2; height = gtk_widget_get_allocated_height (widget) - border_width * 2; right_max = x + width; gtk_style_context_save (context); gtk_style_context_set_state (context, state); gtk_style_context_get_padding (context, state, &padding); if (state & GTK_STATE_FLAG_PRELIGHT) { gtk_render_background (context, cr, x, y, width, height); gtk_render_frame (context, cr, x, y, width, height); } parent = gtk_widget_get_parent (widget); if (GTK_IS_MENU (parent) && GTK_MENU (parent)->priv->torn_off) { gint arrow_x; if (menu_item->priv->toggle_size > ARROW_SIZE) { if (direction == GTK_TEXT_DIR_LTR) { arrow_x = x + (menu_item->priv->toggle_size - ARROW_SIZE)/2; angle = (3 * G_PI) / 2; } else { arrow_x = x + width - menu_item->priv->toggle_size + (menu_item->priv->toggle_size - ARROW_SIZE)/2; angle = G_PI / 2; } x += menu_item->priv->toggle_size + BORDER_SPACING; } else { if (direction == GTK_TEXT_DIR_LTR) { arrow_x = ARROW_SIZE / 2; angle = (3 * G_PI) / 2; } else { arrow_x = x + width - 2 * ARROW_SIZE + ARROW_SIZE / 2; angle = G_PI / 2; } x += 2 * ARROW_SIZE; } gtk_render_arrow (context, cr, angle, arrow_x, height / 2 - 5, ARROW_SIZE); } while (x < right_max) { gint x1, x2; if (direction == GTK_TEXT_DIR_LTR) { x1 = x; x2 = MIN (x + TEAR_LENGTH, right_max); } else { x1 = right_max - x; x2 = MAX (right_max - x - TEAR_LENGTH, 0); } gtk_render_line (context, cr, x1, y + (height - padding.bottom) / 2, x2, y + (height - padding.bottom) / 2); x += 2 * TEAR_LENGTH; } gtk_style_context_restore (context); return FALSE; }
static void thunar_location_entry_button_clicked (GtkWidget *button, ThunarLocationEntry *location_entry) { ThunarShortcutsModel *model; ThunarIconFactory *icon_factory; ThunarVfsVolume *volume; GtkIconTheme *icon_theme; const gchar *icon_name; GtkTreeIter iter; ThunarFile *file; GtkWidget *image; GtkWidget *item; GtkWidget *menu; GdkPixbuf *icon; gint icon_size; gint width; _thunar_return_if_fail (THUNAR_IS_LOCATION_ENTRY (location_entry)); _thunar_return_if_fail (GTK_IS_TOGGLE_BUTTON (button)); /* allocate a new menu */ menu = gtk_menu_new (); /* determine the icon theme and factory */ icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (button)); icon_factory = thunar_icon_factory_get_for_icon_theme (icon_theme); /* determine the icon size for menus */ gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &icon_size, &icon_size); /* load the menu items from the shortcuts model */ model = thunar_shortcuts_model_get_default (); if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter)) { do { /* determine the file and volume for the item */ gtk_tree_model_get (GTK_TREE_MODEL (model), &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_FILE, &file, THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME, &volume, -1); /* check if we have a separator here */ if (G_UNLIKELY (file == NULL && volume == NULL)) { /* generate a separator the menu */ item = gtk_separator_menu_item_new (); } else if (G_UNLIKELY (volume != NULL)) { /* generate an image menu item for the volume */ item = gtk_image_menu_item_new_with_label (thunar_vfs_volume_get_name (volume)); /* load the icon for the volume */ icon_name = thunar_vfs_volume_lookup_icon_name (volume, icon_theme); icon = thunar_icon_factory_load_icon (icon_factory, icon_name, icon_size, NULL, FALSE); if (G_LIKELY (icon != NULL)) { /* generate an image for the menu item */ image = gtk_image_new_from_pixbuf (icon); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); g_object_unref (G_OBJECT (icon)); gtk_widget_show (image); } } else { /* generate an image menu item for the file */ item = gtk_image_menu_item_new_with_label (thunar_file_get_display_name (file)); /* load the icon for the file and generate the image for the menu item */ icon = thunar_icon_factory_load_file_icon (icon_factory, file, THUNAR_FILE_ICON_STATE_DEFAULT, icon_size); image = gtk_image_new_from_pixbuf (icon); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); g_object_unref (G_OBJECT (icon)); gtk_widget_show (image); } /* connect the file and volume to the item */ g_object_set_data_full (G_OBJECT (item), I_("thunar-vfs-volume"), volume, g_object_unref); g_object_set_data_full (G_OBJECT (item), I_("thunar-file"), file, g_object_unref); /* append the new item to the menu */ g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (thunar_location_entry_item_activated), location_entry); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter)); } /* make sure the menu has atleast the same width as the location entry */ width = GTK_WIDGET (location_entry)->allocation.width - 2 * gtk_container_get_border_width (GTK_CONTAINER (location_entry)); if (G_LIKELY (menu->allocation.width < width)) gtk_widget_set_size_request (menu, width, -1); /* select the first visible or selectable item in the menu */ gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), TRUE); /* enable the button, making sure that we do not recurse on the "clicked" signal by temporarily blocking the handler */ g_signal_handlers_block_by_func (G_OBJECT (button), G_CALLBACK (thunar_location_entry_button_clicked), location_entry); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); g_signal_handlers_unblock_by_func (G_OBJECT (button), G_CALLBACK (thunar_location_entry_button_clicked), location_entry); /* run the menu, taking ownership over the menu object */ thunar_gtk_menu_run (GTK_MENU (menu), button, menu_position, location_entry, 1, gtk_get_current_event_time ()); /* disable the button, making sure that we do not recurse on the "clicked" signal by temporarily blocking the handler */ g_signal_handlers_block_by_func (G_OBJECT (button), G_CALLBACK (thunar_location_entry_button_clicked), location_entry); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE); g_signal_handlers_unblock_by_func (G_OBJECT (button), G_CALLBACK (thunar_location_entry_button_clicked), location_entry); /* clean up */ g_object_unref (G_OBJECT (icon_factory)); g_object_unref (G_OBJECT (model)); }
static void ygtk_ratio_box_size_allocate (GtkWidget *widget, GtkAllocation *allocation, GtkOrientation orientation) { YGtkRatioBox* box = YGTK_RATIO_BOX (widget); gfloat ratios_sum = 0; gint children_nb = 0; GList* i; for (i = box->children; i; i = i->next) { YGtkRatioBoxChild* child = i->data; if (!gtk_widget_get_visible (child->widget)) continue; ratios_sum += child->ratio; children_nb++; } gint spacing = children_nb ? box->spacing*(children_nb-1) : 0; int border = gtk_container_get_border_width(GTK_CONTAINER (box)); int x = allocation->x + border, y = allocation->y + border, width = allocation->width - border*2, height = allocation->height - border*2; gint length; if (orientation == GTK_ORIENTATION_HORIZONTAL) length = width - spacing; else length = height - spacing; gint child_pos = 0; for (i = box->children; i; i = i->next) { YGtkRatioBoxChild* child = i->data; if (!gtk_widget_get_visible (child->widget)) continue; //GtkRequisition min_child_req; //GtkRequisition nat_child_req; //gtk_widget_get_preferred_size (child->widget, &min_child_req, &nat_child_req); gint child_length = (child->ratio * length) / ratios_sum; if (!i->next) // last takes rest (any residual length) child_length = length - child_pos; GtkAllocation child_alloc; if (orientation == GTK_ORIENTATION_HORIZONTAL) { child_alloc.x = x + child_pos; child_alloc.y = y; child_alloc.width = child_length; child_alloc.height = height; } else { // GTK_ORIENTATION_VERTICAL child_alloc.x = x; child_alloc.y = y + child_pos; child_alloc.width = width; child_alloc.height = child_length; } child_alloc.width = MAX (child_alloc.width, 1); child_alloc.height = MAX (child_alloc.height, 1); gtk_widget_size_allocate (child->widget, &child_alloc); child_pos += child_length + box->spacing; } }
int wxNotebook::HitTest(const wxPoint& pt, long *flags) const { const gint x = m_widget->allocation.x; const gint y = m_widget->allocation.y; const size_t count = GetPageCount(); size_t i = 0; GtkNotebook * notebook = GTK_NOTEBOOK(m_widget); if (gtk_notebook_get_scrollable(notebook)) i = g_list_position( notebook->children, notebook->first_tab ); for ( ; i < count; i++ ) { wxGtkNotebookPage* nb_page = GetNotebookPage(i); GtkWidget *box = nb_page->m_box; const gint border = gtk_container_get_border_width(GTK_CONTAINER(box)); if ( IsPointInsideWidget(pt, box, x, y, border) ) { // ok, we're inside this tab -- now find out where, if needed if ( flags ) { GtkWidget *pixmap = NULL; GList *children = gtk_container_get_children(GTK_CONTAINER(box)); for ( GList *child = children; child; child = child->next ) { if (GTK_IS_IMAGE(child->data)) { pixmap = GTK_WIDGET(child->data); break; } } if ( children ) g_list_free(children); if ( pixmap && IsPointInsideWidget(pt, pixmap, x, y) ) { *flags = wxBK_HITTEST_ONICON; } else if ( IsPointInsideWidget(pt, GTK_WIDGET(nb_page->m_label), x, y) ) { *flags = wxBK_HITTEST_ONLABEL; } else { *flags = wxBK_HITTEST_ONITEM; } } return i; } } if ( flags ) { *flags = wxBK_HITTEST_NOWHERE; wxWindowBase * page = GetCurrentPage(); if ( page ) { // rect origin is in notebook's parent coordinates wxRect rect = page->GetRect(); // adjust it to the notebook's coordinates wxPoint pos = GetPosition(); rect.x -= pos.x; rect.y -= pos.y; if ( rect.Contains( pt ) ) *flags |= wxBK_HITTEST_ONPAGE; } } return wxNOT_FOUND; }
int main(int argc, char *argv[]) { GtkWidget *window, *box, *glarea; gtk_init (&argc, &argv); EGLX_main(1); if (gdk_gl_query() == FALSE) { g_print ("GL not supported !\n"); return 0; } gchar *info_str; info_str = gdk_gl_get_info(); g_print (info_str); g_free (info_str); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW(window), "Simple Wayland-EGL"); gtk_container_set_border_width (GTK_CONTAINER(window), 10); borderw = gtk_container_get_border_width (GTK_CONTAINER(window)); titlebarw = 30; /* HOW DO WE OBTAIN THAT ? */ int attrs[] = { GDK_GL_RGBA, GDK_GL_RED_SIZE,1, GDK_GL_GREEN_SIZE,1, GDK_GL_BLUE_SIZE,1, GDK_GL_DOUBLEBUFFER, GDK_GL_NONE }; guint myborder = gtk_container_get_border_width (GTK_CONTAINER(window)); glarea = GTK_WIDGET(gtk_gl_area_new(attrs)); gtk_widget_set_size_request (GTK_WIDGET(glarea), 320,240); g_signal_connect (GTK_WIDGET(window), "destroy", G_CALLBACK(gtk_main_quit), NULL); g_signal_connect (GTK_WIDGET(glarea), "draw", G_CALLBACK(draw), NULL); g_signal_connect (GTK_WIDGET(glarea), "realize", G_CALLBACK(init), NULL); g_signal_connect (GTK_WIDGET(window), "draw", G_CALLBACK(resize), NULL); box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_add (GTK_CONTAINER(box), GTK_WIDGET(glarea)); gtk_container_add (GTK_CONTAINER(window), GTK_WIDGET(box)); gtk_widget_show (window); gtk_widget_show (glarea); gtk_widget_show (box); gtk_main(); return 0; }
static gboolean gdl_dock_dock_request (GdlDockObject *object, gint x, gint y, GdlDockRequest *request) { GdlDock *dock; guint bw; gint rel_x, rel_y; GtkAllocation alloc; gboolean may_dock = FALSE; GdlDockRequest my_request; g_return_val_if_fail (GDL_IS_DOCK (object), FALSE); /* we get (x,y) in our allocation coordinates system */ dock = GDL_DOCK (object); /* Get dock size. */ gtk_widget_get_allocation (GTK_WIDGET (dock), &alloc); bw = gtk_container_get_border_width (GTK_CONTAINER (dock)); /* Get coordinates relative to our allocation area. */ rel_x = x - alloc.x; rel_y = y - alloc.y; if (request) my_request = *request; /* Check if coordinates are in GdlDock widget. */ if (rel_x > 0 && rel_x < alloc.width && rel_y > 0 && rel_y < alloc.height) { /* It's inside our area. */ may_dock = TRUE; /* Set docking indicator rectangle to the GdlDock size. */ my_request.rect.x = alloc.x + bw; my_request.rect.y = alloc.y + bw; my_request.rect.width = alloc.width - 2*bw; my_request.rect.height = alloc.height - 2*bw; /* If GdlDock has no root item yet, set the dock itself as possible target. */ if (!dock->priv->root) { my_request.position = GDL_DOCK_TOP; my_request.target = object; } else { my_request.target = dock->priv->root; /* See if it's in the border_width band. */ if (rel_x < bw) { my_request.position = GDL_DOCK_LEFT; my_request.rect.width *= SPLIT_RATIO; } else if (rel_x > alloc.width - bw) { my_request.position = GDL_DOCK_RIGHT; my_request.rect.x += my_request.rect.width * (1 - SPLIT_RATIO); my_request.rect.width *= SPLIT_RATIO; } else if (rel_y < bw) { my_request.position = GDL_DOCK_TOP; my_request.rect.height *= SPLIT_RATIO; } else if (rel_y > alloc.height - bw) { my_request.position = GDL_DOCK_BOTTOM; my_request.rect.y += my_request.rect.height * (1 - SPLIT_RATIO); my_request.rect.height *= SPLIT_RATIO; } else { /* Otherwise try our children. */ /* give them allocation coordinates (we are a GTK_NO_WINDOW) widget */ may_dock = gdl_dock_object_dock_request (GDL_DOCK_OBJECT (dock->priv->root), x, y, &my_request); } } } if (may_dock && request) *request = my_request; return may_dock; }