Example #1
0
void
greeter_item_update_text (GreeterItemInfo *info)
{
  char *text;
  if (info && info->item &&
      GNOME_IS_CANVAS_TEXT (info->item) &&
      GREETER_ITEM_TYPE_IS_TEXT (info))
    {
      text = mdm_common_expand_text (info->data.text.orig_text);

      g_object_set (G_OBJECT (info->item),
		    "markup", text,
		    NULL);

      g_free (text);
    }

}
Example #2
0
/* Calculate the requested minimum size of the item */
static void
greeter_item_size_request (GreeterItemInfo *item,
			   GtkRequisition  *requisition_out,
			   gint             parent_width,
			   gint             parent_height,
			   GnomeCanvas     *canvas)
{
  GtkRequisition *req;
  GtkRequisition box_requisition = {0, 0}; 
  int set_width = 0;
  int set_height = 0;
  
  if (item->has_requisition)
    {
      *requisition_out = item->requisition;
      return;
    }

  req = &item->requisition;
  
  req->width = 0;
  req->height = 0;

  if (item->width_type == GREETER_ITEM_SIZE_BOX ||
      item->height_type == GREETER_ITEM_SIZE_BOX)
    {
      greeter_size_request_box (item,
				&box_requisition,
				canvas);
    }

  switch (item->width_type)
    {
    case GREETER_ITEM_SIZE_ABSOLUTE:
      set_width = (item->width > 0) ? item->width : parent_width + item->width;
      break;
    case GREETER_ITEM_SIZE_RELATIVE:
      set_width = item->width*parent_width / 100.0;
      break;
    case GREETER_ITEM_SIZE_BOX:
      set_width = box_requisition.width;
      break;
    case GREETER_ITEM_SIZE_SCALE:
    case GREETER_ITEM_SIZE_UNSET:
      break;
    }

  switch (item->height_type)
    {
    case GREETER_ITEM_SIZE_ABSOLUTE:
      set_height = (item->height > 0) ? item->height : parent_height + item->height;
      break;
    case GREETER_ITEM_SIZE_RELATIVE:
      set_height = item->height*parent_height / 100.0;
      break;
    case GREETER_ITEM_SIZE_BOX:
      set_height = box_requisition.height;
      break;
    case GREETER_ITEM_SIZE_SCALE:
    case GREETER_ITEM_SIZE_UNSET:
      break;
    }

  if (item->item_type == GREETER_ITEM_TYPE_LABEL)
    {
      int width, height;
      char *text;
      int max_width = G_MAXINT;

      /* This is not the ugly hack you're looking for.
       * You can go about your business.
       * Move Along
       */
      text = mdm_common_expand_text (item->data.text.orig_text);

      if (set_width > 0)
	      max_width = set_width;

      if (item->data.text.max_width < max_width)
	      max_width = item->data.text.max_width;

      if (item->data.text.max_screen_percent_width/100.0 * mdm_wm_screen.width < max_width)
	      max_width = item->data.text.max_screen_percent_width/100.0 * mdm_wm_screen.width;

      greeter_canvas_item_break_set_string (item,
					    text,
					    TRUE /* markup */,
					    max_width,
					    &width,
					    &height,
					    canvas,
					    NULL /* real_item */);

      req->width = width;
      req->height = height;

      g_free (text);
    }

  if (item->item_type == GREETER_ITEM_TYPE_PIXMAP)
    {
      req->width = gdk_pixbuf_get_width (item->data.pixmap.pixbufs[0]);
      req->height = gdk_pixbuf_get_height (item->data.pixmap.pixbufs[0]);
    }

  if (item->item_type == GREETER_ITEM_TYPE_SVG)
    {
      GdkPixbuf *svg;

      svg = rsvg_pixbuf_from_file (item->data.pixmap.files[0], NULL);
      req->width = gdk_pixbuf_get_width (svg);
      req->height = gdk_pixbuf_get_height (svg);
      g_object_unref (svg);
    }

  if (item->item_type == GREETER_ITEM_TYPE_BUTTON)
    {
#define ITEM_BUTTON_MIN_RECOMMANDED_WIDTH_OFFSET 15      
#define ITEM_BUTTON_MIN_RECOMMANDED_HEIGHT_OFFSET 10
      PangoLayout *layout;
      int pango_width, pango_height;
      int pix_width, pix_height;
      
      GtkWidget *dummy_w = gtk_button_new ();
      
      layout = gtk_widget_create_pango_layout (dummy_w, item->data.text.orig_text);
       
      pango_layout_get_size (layout, &pango_width, &pango_height);
      
      pix_height = PANGO_PIXELS (pango_height) + ITEM_BUTTON_MIN_RECOMMANDED_HEIGHT_OFFSET;
      pix_width = PANGO_PIXELS (pango_width) + ITEM_BUTTON_MIN_RECOMMANDED_WIDTH_OFFSET;

      if (pix_width > item->parent->box_min_width)
	req->width = pix_width;
      else
	req->width = item->parent->box_min_width;

      if (pix_height > item->parent->box_min_height)
	req->height = pix_height;
      else
	req->height = item->parent->box_min_height;
    }
 
  if (req->width > 0 && req->height > 0)
    {
      if (item->width_type == GREETER_ITEM_SIZE_SCALE && set_height > 0)
        set_width = (req->width * set_height) / req->height;
      else if (item->height_type == GREETER_ITEM_SIZE_SCALE && set_width > 0)
        set_height = (req->height * set_width) / req->width;
    }
  
  if (set_width > 0)
    req->width = set_width;
  if (set_height > 0)
    req->height = set_height;

  *requisition_out = item->requisition;
  item->has_requisition = TRUE;
}