Exemplo n.º 1
0
void
modify_drawable(GdkDrawable *base, GdkGC *gc, guint32 tintcolor, gint alpha)
{
    int w, h;
    GdkPixbuf *ret, *ret2;
    static GdkColormap *cmap = NULL;

    ENTER;
    gdk_drawable_get_size (base, &w, &h);
    if (!cmap) {
        cmap = gdk_colormap_get_system ();
    }
    ret = gdk_pixbuf_get_from_drawable (NULL, base, cmap, 0, 0, 0, 0, w, h);
    if (!ret)
        RET();
    ret2 = gdk_pixbuf_composite_color_simple(ret, w, h, 
          GDK_INTERP_HYPER, alpha, MIN(w, h), tintcolor, tintcolor);

    //gdk_pixbuf_render_to_drawable (ret2, base, gc, 0, 0, 0, 0, w, h, GDK_RGB_DITHER_NONE, 0, 0);
    gdk_draw_pixbuf (base, gc, ret2, 0, 0, 0, 0, w, h, GDK_RGB_DITHER_NONE, 0, 0);
    g_object_unref(ret);
    g_object_unref(ret2);
    RET();
}
Exemplo n.º 2
0
static void
_paint_lyrics (OlScrollWindow *scroll, cairo_t *cr)
{
  ol_assert (OL_IS_SCROLL_WINDOW (scroll));
  GtkWidget *widget = GTK_WIDGET (scroll);
  ol_assert (GTK_WIDGET_REALIZED (widget));
  OlScrollWindowPrivate *priv = OL_SCROLL_WINDOW_GET_PRIVATE (scroll);
  int line_height = ol_scroll_window_get_font_height (scroll) + priv->line_margin;
  int count = ol_scroll_window_compute_line_count (scroll);
  gint width, height;
  gdk_drawable_get_size (gtk_widget_get_window (GTK_WIDGET (scroll)),
                         &width, &height);
  
  /* set the font */
  PangoLayout *layout = _get_pango (scroll, cr);
  /* paint the lyrics*/
  cairo_save (cr);
  cairo_new_path (cr);
  cairo_rectangle (cr,
                   priv->padding_x, 0,
                   width - priv->padding_x * 2,
                   height - priv->padding_y * 2);
  cairo_close_path (cr);
  cairo_clip (cr);
  int i;
  gint current_lyric_id;
  gint lrc_y;
  _calc_paint_pos (scroll,
                   &current_lyric_id,
                   &lrc_y);
  int begin = current_lyric_id - count / 2;
  int end = current_lyric_id + count / 2 + 1;
  int ypos = height / 2  - lrc_y - (count / 2 + 1) * line_height;
  cairo_set_source_rgb(cr,
                       priv->inactive_color.r,
                       priv->inactive_color.g,
                       priv->inactive_color.b);
  if (scroll->whole_lyrics != NULL) {
    for (i = begin; i < end; i++) {
      ypos += line_height;
      if (i < 0) continue;
      if (i >= scroll->whole_lyrics->len)
        break;
      pango_layout_set_text (layout,
                             g_ptr_array_index (scroll->whole_lyrics, i),
                             -1);
      cairo_save (cr);
      double ratio = _get_active_color_ratio (scroll, i);
      double alpha = 1.0;
      if (ypos < line_height / 2.0 + priv->padding_y)
        alpha = 1.0 - (line_height / 2.0 + priv->padding_y - ypos) * 1.0 / line_height * 2;
      else if (ypos > height - line_height * 1.5 - priv->padding_y)
        alpha = (height - line_height - priv->padding_y - ypos) * 1.0 / line_height * 2;
      if (alpha < 0.0) alpha = 0.0;
      cairo_set_source_rgba (cr,
                             priv->active_color.r * ratio + 
                             priv->inactive_color.r * (1 - ratio),
                             priv->active_color.g * ratio +
                             priv->inactive_color.g * (1 - ratio),
                             priv->active_color.b * ratio +
                             priv->inactive_color.b * (1 - ratio),
                             alpha);
      cairo_move_to (cr, priv->padding_x, ypos);
      pango_cairo_update_layout (cr, layout);
      pango_cairo_show_layout (cr, layout);
      cairo_restore (cr);
    }
  }
  g_object_unref (layout);
  cairo_reset_clip (cr);
  cairo_restore (cr);
}
Exemplo n.º 3
0
static gint32
shoot (GdkScreen *screen)
{
  GdkDisplay   *display;
  GdkWindow    *window;
  GdkPixbuf    *screenshot;
  GdkRegion    *shape = NULL;
  GdkRectangle  rect;
  GdkRectangle  screen_rect;
  gchar        *name  = NULL;
  gint32        image;
  gint          screen_x;
  gint          screen_y;
  gint          x, y;

  /* use default screen if we are running non-interactively */
  if (screen == NULL)
    screen = gdk_screen_get_default ();

  display = gdk_screen_get_display (screen);

  screen_rect.x      = 0;
  screen_rect.y      = 0;
  screen_rect.width  = gdk_screen_get_width (screen);
  screen_rect.height = gdk_screen_get_height (screen);

  if (shootvals.shoot_type == SHOOT_REGION)
    {
      rect.x = MIN (shootvals.x1, shootvals.x2);
      rect.y = MIN (shootvals.y1, shootvals.y2);
      rect.width  = ABS (shootvals.x2 - shootvals.x1);
      rect.height = ABS (shootvals.y2 - shootvals.y1);
    }
  else
    {
      if (shootvals.shoot_type == SHOOT_ROOT)
        {
          window = gdk_screen_get_root_window (screen);
        }
      else
        {
          window = gdk_window_foreign_new_for_display (display,
                                                       shootvals.window_id);
        }

      if (! window)
        {
          g_message (_("Specified window not found"));
          return -1;
        }

      gdk_drawable_get_size (GDK_DRAWABLE (window), &rect.width, &rect.height);
      gdk_window_get_origin (window, &x, &y);

      rect.x = x;
      rect.y = y;
    }

  if (! gdk_rectangle_intersect (&rect, &screen_rect, &rect))
    return -1;

  window = gdk_screen_get_root_window (screen);
  gdk_window_get_origin (window, &screen_x, &screen_y);

  screenshot = gdk_pixbuf_get_from_drawable (NULL, window, NULL,
                                             rect.x - screen_x,
                                             rect.y - screen_y,
                                             0, 0, rect.width, rect.height);

  gdk_display_beep (display);
  gdk_flush ();

  if (! screenshot)
    {
      g_message (_("There was an error taking the screenshot."));
      return -1;
    }

  if (shootvals.shoot_type == SHOOT_WINDOW)
    {
      name = window_get_title (display, shootvals.window_id);

      shape = window_get_shape (screen, shootvals.window_id);

      if (shape)
        gdk_region_offset (shape, x - rect.x, y - rect.y);
    }

  image = create_image (screenshot, shape, name);

  g_object_unref (screenshot);

  if (shape)
    gdk_region_destroy (shape);

  g_free (name);

  return image;
}
Exemplo n.º 4
0
void XAttGtk::change_value(int set_focus)
{
  int sts;
  GtkWidget* text_w;
  int multiline;
  char* value;
  int input_size;

  if (input_open) {
    g_object_set(cmd_input, "visible", FALSE, NULL);
    g_object_set(cmd_scrolledinput, "visible", FALSE, NULL);
    set_prompt("");
    input_open = 0;
    return;
  }

  sts = xattnav->check_attr(
      &multiline, &input_node, input_name, &value, &input_size);
  if (EVEN(sts)) {
    if (sts == XATT__NOATTRSEL)
      message('E', "No attribute is selected");
    else
      message('E', XNav::get_message(sts));
    return;
  }

  if (multiline) {
    text_w = cmd_scrolledinput;
    g_object_set(text_w, "visible", TRUE, NULL);

    int w, h;
    gdk_drawable_get_size(pane->window, &w, &h);
    gtk_paned_set_position(GTK_PANED(pane), h - 170);
    if (set_focus)
      gtk_widget_grab_focus(cmd_scrolledtextview);
    input_max_length = input_size - 1;
    input_multiline = 1;
  } else {
    text_w = cmd_input;
    g_object_set(text_w, "visible", TRUE, "max-length", input_size - 1, NULL);
    if (set_focus)
      gtk_widget_grab_focus(cmd_input);
    input_multiline = 0;
  }

  message(' ', "");

  if (value) {
    if (multiline) {
      GtkTextIter start_iter, end_iter;
      gtk_text_buffer_get_start_iter(cmd_scrolled_buffer, &start_iter);
      gtk_text_buffer_get_end_iter(cmd_scrolled_buffer, &end_iter);
      gtk_text_buffer_delete(cmd_scrolled_buffer, &start_iter, &end_iter);

      gtk_text_buffer_get_start_iter(cmd_scrolled_buffer, &start_iter);
      gtk_text_buffer_insert(cmd_scrolled_buffer, &start_iter, value, -1);

      // Select the text
      // gtk_text_buffer_get_start_iter( cmd_scrolled_buffer, &start_iter);
      // gtk_text_buffer_get_end_iter( cmd_scrolled_buffer, &end_iter);
      // gtk_text_buffer_select_range( cmd_scrolled_buffer, &start_iter,
      // &end_iter);
    } else {
      gint pos = 0;
      gtk_editable_delete_text(GTK_EDITABLE(cmd_input), 0, -1);
      gtk_editable_insert_text(
          GTK_EDITABLE(text_w), value, strlen(value), &pos);

      // Select the text
      gtk_editable_set_position(GTK_EDITABLE(cmd_input), -1);
      gtk_editable_select_region(GTK_EDITABLE(cmd_input), 0, -1);
    }
  } else {
    gtk_editable_delete_text(GTK_EDITABLE(cmd_input), 0, -1);
  }

  message(' ', "");
  set_prompt(Lng::translate("value >"));
  input_open = 1;
}
Exemplo n.º 5
0
static void
draw_icon (GtkWidget *widget, GtkIconEntryPosition icon_pos)
{
  GtkIconEntry *entry;
  GtkIconEntryPrivate *priv;
  EntryIconInfo *icon_info;
  GdkPixbuf *pixbuf;
  gint x, y, width, height;

  entry = GTK_ICON_ENTRY (widget);
  priv = GTK_ICON_ENTRY_GET_PRIVATE (entry);
  icon_info = &priv->icons[icon_pos];

  if (icon_info->pixbuf == NULL || !GTK_WIDGET_REALIZED (widget))
    return;

  if ((pixbuf = get_pixbuf_from_icon (entry, icon_pos)) == NULL)
    return;

  gdk_drawable_get_size (icon_info->window, &width, &height);

  if (width == 1 || height == 1)
    {
      /*
       * size_allocate hasn't been called yet. These are the default values.
       */
      return;
    }

  if (gdk_pixbuf_get_height (pixbuf) > height)
    {
      GdkPixbuf *temp_pixbuf;
      int scale;

      scale = height - (2 * ICON_MARGIN);

      temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
					     GDK_INTERP_BILINEAR);

      g_object_unref (pixbuf);

      pixbuf = temp_pixbuf;
    }

  x = (width  - gdk_pixbuf_get_width(pixbuf)) / 2;
  y = (height - gdk_pixbuf_get_height(pixbuf)) / 2;

  if (icon_info->insensitive)
    {
      GdkPixbuf *temp_pixbuf;

      temp_pixbuf = gdk_pixbuf_copy (pixbuf);

      gdk_pixbuf_saturate_and_pixelate (pixbuf,
					temp_pixbuf,
					0.8f,
					TRUE);
      g_object_unref (pixbuf);
      pixbuf = temp_pixbuf;
    }
  else if (icon_info->hovered)
    {
      GdkPixbuf *temp_pixbuf;

      temp_pixbuf = gdk_pixbuf_copy (pixbuf);

      colorshift_pixbuf (temp_pixbuf, pixbuf, 30);

      g_object_unref (pixbuf);

      pixbuf = temp_pixbuf;
    }

  gdk_draw_pixbuf (icon_info->window, widget->style->black_gc, pixbuf,
		   0, 0, x, y, -1, -1,
		   GDK_RGB_DITHER_NORMAL, 0, 0);

  g_object_unref (pixbuf);
}
Exemplo n.º 6
0
static gboolean
gtk_mirror_bin_expose (GtkWidget      *widget,
                        GdkEventExpose *event)
{
  GtkMirrorBin *bin = GTK_MIRROR_BIN (widget);
  gint width, height;

  if (gtk_widget_is_drawable (widget))
    {
      if (event->window == widget->window)
        {
          GdkPixmap *pixmap;
          cairo_t *cr;
          cairo_matrix_t matrix;
          cairo_pattern_t *mask;

          if (bin->child && gtk_widget_get_visible (bin->child))
            {
              pixmap = gdk_offscreen_window_get_pixmap (bin->offscreen_window);
              gdk_drawable_get_size (pixmap, &width, &height);

              cr = gdk_cairo_create (widget->window);

              cairo_save (cr);

              cairo_rectangle (cr, 0, 0, width, height);
              cairo_clip (cr);

              /* paint the offscreen child */
              gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0);
              cairo_paint (cr);

              cairo_restore (cr);

              cairo_matrix_init (&matrix, 1.0, 0.0, 0.3, 1.0, 0.0, 0.0);
              cairo_matrix_scale (&matrix, 1.0, -1.0);
              cairo_matrix_translate (&matrix, -10, - 3 * height - 10);
              cairo_transform (cr, &matrix);

              cairo_rectangle (cr, 0, height, width, height);
              cairo_clip (cr);

              gdk_cairo_set_source_pixmap (cr, pixmap, 0, height);

              /* create linear gradient as mask-pattern to fade out the source */
              mask = cairo_pattern_create_linear (0.0, height, 0.0, 2*height);
              cairo_pattern_add_color_stop_rgba (mask, 0.0,  0.0, 0.0, 0.0, 0.0);
              cairo_pattern_add_color_stop_rgba (mask, 0.25, 0.0, 0.0, 0.0, 0.01);
              cairo_pattern_add_color_stop_rgba (mask, 0.5,  0.0, 0.0, 0.0, 0.25);
              cairo_pattern_add_color_stop_rgba (mask, 0.75, 0.0, 0.0, 0.0, 0.5);
              cairo_pattern_add_color_stop_rgba (mask, 1.0,  0.0, 0.0, 0.0, 1.0);

              /* paint the reflection */
              cairo_mask (cr, mask);

              cairo_pattern_destroy (mask);
              cairo_destroy (cr);
            }
        }
      else if (event->window == bin->offscreen_window)
        {
          gtk_paint_flat_box (widget->style, event->window,
                              GTK_STATE_NORMAL, GTK_SHADOW_NONE,
                              &event->area, widget, "blah",
                              0, 0, -1, -1);

          if (bin->child)
            gtk_container_propagate_expose (GTK_CONTAINER (widget),
                                            bin->child,
                                            event);
        }
    }

  return FALSE;
}
Exemplo n.º 7
0
static GtkWidget *
pop_calendar_window(GtkWidget *parent, int orientation)
{
    GtkWidget *window;
    GtkWidget *cal;
    gint parent_x, parent_y, parent_w, parent_h;
    gint root_w, root_h;
    gint width, height, x, y;
    GtkRequisition requisition;
    GtkAllocation allocation;

    window = gtk_window_new(GTK_WINDOW_POPUP);

    cal = gtk_calendar_new();
    gtk_container_add(GTK_CONTAINER(window), cal);

    gdk_window_get_origin(GDK_WINDOW(parent->window), &parent_x, &parent_y);
    gdk_drawable_get_size(GDK_DRAWABLE(parent->window), &parent_w, &parent_h);

    root_w = gdk_screen_width();
    root_h = gdk_screen_height();

    gtk_widget_realize(GTK_WIDGET(window));

    gtk_widget_size_request(GTK_WIDGET(cal), &requisition);

    allocation.x = requisition.width;
    allocation.y = requisition.height;
    gtk_widget_size_allocate(GTK_WIDGET(cal), &allocation);

    gtk_widget_size_request(GTK_WIDGET(cal), &requisition);
    width = requisition.width;
    height = requisition.height;

    g_print("parent: %dx%d +%d+%d\n", parent_w, parent_h, parent_x, parent_y);
    g_print("root: %dx%d\n", root_w, root_h);
    g_print("calendar: %dx%d\n", width, height);

    if (orientation == GTK_ORIENTATION_VERTICAL) {
        if (parent_x < root_w / 2) {
            if (parent_y < root_h / 2) {
                /* upper left */
                x = parent_x + parent_w;
                y = parent_y;
            } else {
                /* lower left */
                x = parent_x + parent_w;
                y = parent_y + parent_h - height;
            }
        } else {
            if (parent_y < root_h / 2) {
                /* upper right */
                x = parent_x - width;
                y = parent_y;
            } else {
                /* lower right */
                x = parent_x - width;
                y = parent_y + parent_h - height;
            }
        }
    } else {
        if (parent_x < root_w / 2) {
            if (parent_y < root_h / 2) {
                /* upper left */
                x = parent_x;
                y = parent_y + parent_h;
            } else {
                /* lower left */
                x = parent_x;
                y = parent_y - height;
            }
        } else {
            if (parent_y < root_h / 2) {
                /* upper right */
                x = parent_x + parent_w - width;
                y = parent_y + parent_h;
            } else {
                /* lower right */
                x = parent_x + parent_w - width;
                y = parent_y - height;
            }
        }
    }

    gtk_window_move(GTK_WINDOW(window), x, y);
    gtk_widget_show(cal);
    gtk_widget_show(window);

    return window;
}
Exemplo n.º 8
0
static gboolean
draw_simple_image (GtkStyle       *style,
                   GdkWindow      *window,
                   GdkRectangle   *area,
                   GtkWidget      *widget,
                   ThemeMatchData *match_data,
                   gboolean        draw_center,
                   gint            x,
                   gint            y,
                   gint            width,
                   gint            height)
{
  gboolean maemo_position_theming;
  ThemeImage *image;

  if ((width == -1) && (height == -1))
    gdk_drawable_get_size (window, &width, &height);
  else if (width == -1)
    gdk_drawable_get_size (window, &width, NULL);
  else if (height == -1)
    gdk_drawable_get_size (window, NULL, &height);

  if (!(match_data->flags & THEME_MATCH_ORIENTATION))
    {
      match_data->flags |= THEME_MATCH_ORIENTATION;

      if (height > width)
	match_data->orientation = GTK_ORIENTATION_VERTICAL;
      else
	match_data->orientation = GTK_ORIENTATION_HORIZONTAL;
    }

  /* Check for maemo-position-theming to update the position data */
  if (widget && widget->parent &&
      gtk_widget_class_find_style_property (GTK_WIDGET_GET_CLASS (widget->parent),
                                            "maemo-position-theming"))
    {
      gtk_widget_style_get (widget->parent,
			    "maemo-position-theming", &maemo_position_theming,
			    NULL);
      if (maemo_position_theming)
	{
	  if (GTK_IS_BUTTON_BOX (widget->parent))
	    check_buttonbox_child_position (widget, match_data);
	  else
	    {
              /* Generic code for other kinds of containers */
	      GList *children;

	      children = gtk_container_get_children (GTK_CONTAINER (widget->parent));
	      check_child_position (widget, children, match_data);
	      g_list_free (children);
	    }
	}
    }

  image = match_theme_image (style, match_data);
  if (image)
    {
      if (image->background)
	{
	  GdkWindow *maskwin;
	  GdkBitmap *mask = NULL;
	  gboolean valid;

	  maskwin = get_window_for_shape (image, window, widget, x, y, width, height);
	  if (maskwin)
	    mask = gdk_pixmap_new (maskwin, width, height, 1);

          valid = theme_pixbuf_render (image->background, G_OBJECT_TYPE (widget),
				       window, mask, area,
				       draw_center ? COMPONENT_ALL : COMPONENT_ALL | COMPONENT_CENTER,
				       FALSE,
				       x, y, width, height);

	  if (mask)
	    {
	      if (valid)
		gdk_window_shape_combine_mask (maskwin, mask, 0, 0);
	      g_object_unref (mask);
	    }
	}

      if (image->overlay && draw_center)
        theme_pixbuf_render (image->overlay, G_OBJECT_TYPE (widget),
			     window, NULL, area, COMPONENT_ALL,
			     TRUE, 
			     x, y, width, height);

      return TRUE;
    }
  else
    return FALSE;
}
Exemplo n.º 9
0
HICON pixmap_to_hicon (GdkPixmap *pixmap, GdkBitmap *mask)
{
    ICONINFO ii;
    HICON hIcon;
    gint w = 0, h = 0;
    HANDLE hpixmap = NULL;
    HBITMAP hbitmap = NULL;

    /* Create Drawing Context */
    HDC hdc1 = NULL;
    HBITMAP hbitmaptmp1 = NULL;

    if (!pixmap) {
        return NULL;
    }

    gdk_drawable_get_size (GDK_DRAWABLE (pixmap), &w, &h);

    hpixmap = gdk_win32_drawable_get_handle (pixmap);

    /* we need the inverted mask for the XOR op */
    hdc1 = CreateCompatibleDC (NULL);
    hbitmap = CreateCompatibleBitmap (hdc1, w, h);
    hbitmaptmp1 = SelectObject (hdc1, hbitmap);

    if (mask) {
        HANDLE hmask = NULL;
        HDC hdc2 = NULL;
        HBITMAP hbitmaptmp2 = NULL;

        hmask = gdk_win32_drawable_get_handle (mask);

        hdc2 = CreateCompatibleDC (NULL);
        hbitmaptmp2 = SelectObject (hdc2, hmask);

        BitBlt (hdc1, 0,0,w,h, hdc2, 0,0, NOTSRCCOPY);

        SelectObject (hdc2, hbitmaptmp2);
        DeleteDC (hdc2);
    } else {
        RECT rect;
        GetClipBox (hdc1, &rect);
        FillRect (hdc1, &rect, GetStockObject (WHITE_BRUSH));
    }

    SelectObject (hdc1, hbitmaptmp1);
    DeleteDC (hdc1);

    ii.fIcon = TRUE;
    ii.xHotspot = ii.yHotspot = 0; /* ignored for icons */
    ii.hbmMask = hbitmap;
    ii.hbmColor = hpixmap;

    hIcon = CreateIconIndirect (&ii);
    if (!hIcon) {
        return NULL;
    }

    DeleteObject (hbitmap);

    return hIcon;
}
Exemplo n.º 10
0
G_MODULE_EXPORT void save_as(const char *filename, int type)
{

	FILE *fp;
	unsigned int i, j;
	double freq, k;
	mat_t *mat;
	matvar_t *matvar;
	int dims[2];
	char tmp[20];
	GdkPixbuf *pixbuf;
	GError *err=NULL;
	GdkColormap *cmap;
	gint width, height;
	gboolean ret = true;
	char *name;
	gdouble *tmp_data;

	name = malloc(strlen(filename) + 5);
	switch(type) {
		/* Response Codes encoded in glade file */
		case GTK_RESPONSE_DELETE_EVENT:
		case GTK_RESPONSE_CANCEL:
			break;
		case SAVE_VSA:
			/* Allow saving data when only in Time Domanin */
			if ((gtk_combo_box_get_active(GTK_COMBO_BOX(plot_domain)) != TIME_PLOT) &&
			    (gtk_combo_box_get_active(GTK_COMBO_BOX(plot_domain)) != XY_PLOT)) {
				create_blocking_popup(GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, "Invalid Plot Type",
					"Please make sure to set the Plot Type to \"Time Domanin\" before saving data.");
				return;
			}
			/* Save as Agilent VSA formatted file */
			if (!strncasecmp(&filename[strlen(filename)-4], ".txt", 4))
				strcpy(name, filename);
			else
				sprintf(name, "%s.txt", filename);

			fp = fopen(name, "w");
			if (!fp)
				break;
			fprintf(fp, "InputZoom\tTRUE\n");
			fprintf(fp, "InputCenter\t0\n");
			fprintf(fp, "InputRange\t1\n");
			fprintf(fp, "InputRefImped\t50\n");
			fprintf(fp, "XStart\t0\n");
			if (!strcmp(adc_scale, "M"))
				freq = adc_freq * 1000000;
			else if (!strcmp(adc_scale, "k"))
				freq = adc_freq * 1000;
			else {
				printf("error in writing\n");
				break;
			}

			fprintf(fp, "XDelta\t%-.17f\n", 1.0/freq);
			fprintf(fp, "XDomain\t2\n");
			fprintf(fp, "XUnit\tSec\n");
			fprintf(fp, "YUnit\tV\n");
			fprintf(fp, "FreqValidMax\t%e\n", freq / 2);
			fprintf(fp, "FreqValidMin\t-%e\n", freq / 2);
			fprintf(fp, "Y\n");

			for (j = 0; j < num_samples; j++) {
				for (i = 0; i < num_active_channels ; i++) {
					fprintf(fp, "%g", channel_data[i][j]);
					if (i < (num_active_channels - 1))
						fprintf(fp, "\t");
				}
				fprintf(fp, "\n");
			}
			fprintf(fp, "\n");
			fclose(fp);

			break;
		case SAVE_MAT:
			/* Allow saving data when only in Time Domanin */
			if (gtk_combo_box_get_active(GTK_COMBO_BOX(plot_domain)) != TIME_PLOT) {
				create_blocking_popup(GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, "Invalid Plot Type",
					"Please make sure to set the Plot Type to \"Time Domanin\" before saving data.");
				return;
			}
			/* Matlab file
			 * http://na-wiki.csc.kth.se/mediawiki/index.php/MatIO
			 */
			if (!strncasecmp(&filename[strlen(filename)-4], ".mat", 4))
				strcpy(name, filename);
			else
				sprintf(name, "%s.mat", filename);

			dims[1] = 1;
			dims[0] = num_samples;

			mat = Mat_Open(name, MAT_ACC_RDWR);
			if(mat) {
				for (i = 0; i < num_active_channels; i++) {
					sprintf(tmp, "in_voltage%d", i);
					if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(save_mat_scale))) {
						matvar = Mat_VarCreate(tmp, MAT_C_SINGLE,
								MAT_T_SINGLE, 2, dims, channel_data[i], 0);
					} else {
						tmp_data = g_new(gdouble, num_samples);
						if (channels[i].is_signed)
							k = channels[i].bits_used - 1;
						else
							k = channels[i].bits_used;

						for (j = 0; j < num_samples; j++) {
							tmp_data[j] = (gdouble)channel_data[i][j] /
									(pow(2.0, k));
						}
						matvar = Mat_VarCreate(tmp, MAT_C_DOUBLE,
								MAT_T_DOUBLE, 2, dims, tmp_data, 0);
						g_free(tmp_data);
					}
					if (!matvar)
						printf("error creating matvar on channel %i\n", i);
					else {
						Mat_VarWrite(mat, matvar, 0);
						Mat_VarFree(matvar);
					}
				}
				Mat_Close(mat);
			}
			break;
		case SAVE_CSV:
			/* Allow saving data when only in Time Domanin */
			if (gtk_combo_box_get_active(GTK_COMBO_BOX(plot_domain)) != TIME_PLOT) {
				create_blocking_popup(GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, "Invalid Plot Type",
					"Please make sure to set the Plot Type to \"Time Domanin\" before saving data.");
				return;
			}
			/* save comma seperated valus (csv) */
			if (!strncasecmp(&filename[strlen(filename)-4], ".csv", 4))
				strcpy(name, filename);
			else
				sprintf(name, "%s.csv", filename);

			fp = fopen(name, "w");
			if (!fp)
				break;

			for (j = 0; j < num_samples; j++) {
				for (i = 0; i < num_active_channels ; i++) {
					fprintf(fp, "%g", channel_data[i][j]);
					if (i < (num_active_channels - 1))
						fprintf(fp, ", ");
				}
				fprintf(fp, "\n");
			}
			fprintf(fp, "\n");
			fclose(fp);
			break;
		case SAVE_PNG:
			/* save_png */
			if (!strncasecmp(&filename[strlen(filename)-4], ".png", 4))
				strcpy(name, filename);
			else
				sprintf(name, "%s.png", filename);

			cmap = gdk_window_get_colormap(
					GDK_DRAWABLE(gtk_widget_get_window(capture_graph)));
			gdk_drawable_get_size(GDK_DRAWABLE(gtk_widget_get_window(capture_graph)),
					&width, &height);
			pixbuf = gdk_pixbuf_get_from_drawable(NULL,
					GDK_DRAWABLE(gtk_widget_get_window(capture_graph)),
					cmap, 0, 0, 0, 0, width, height);

			if (pixbuf)
				ret = gdk_pixbuf_save(pixbuf, name, "png", &err, NULL);
			if (!pixbuf || !ret)
				printf("error creating %s\n", name);
			break;
		default:
			printf("ret : %i\n", ret);
	}
	free(name);
}
Exemplo n.º 11
0
static gboolean
vik_print_preview_expose_event (GtkWidget        *widget,
                                 GdkEventExpose   *eevent,
                                 VikPrintPreview *preview)
{
  gdouble  paper_width;
  gdouble  paper_height;
  gdouble  left_margin;
  gdouble  right_margin;
  gdouble  top_margin;
  gdouble  bottom_margin;
  gdouble  scale;
  cairo_t *cr;

  paper_width = gtk_page_setup_get_paper_width (preview->page,
                                                GTK_UNIT_POINTS);
  paper_height = gtk_page_setup_get_paper_height (preview->page,
                                                  GTK_UNIT_POINTS);
  vik_print_preview_get_page_margins (preview,
                                       &left_margin,
                                       &right_margin,
                                       &top_margin,
                                       &bottom_margin);

  cr = gdk_cairo_create (gtk_widget_get_window(widget));

  scale = vik_print_preview_get_scale (preview);

  /* draw background */
  cairo_scale (cr, scale, scale);
  gdk_cairo_set_source_color (cr, &gtk_widget_get_style(widget)->white);
  cairo_rectangle (cr, 0, 0, paper_width, paper_height);
  cairo_fill (cr);

  /* draw page_margins */
  gdk_cairo_set_source_color (cr, &gtk_widget_get_style(widget)->black);
  cairo_rectangle (cr,
                   left_margin,
                   top_margin,
                   paper_width - left_margin - right_margin,
                   paper_height - top_margin - bottom_margin);
  cairo_stroke (cr);

  if (preview->dragging)
    {
      gint width, height;
      gdk_drawable_get_size(preview->drawable, &width, &height);
      cairo_rectangle (cr,
                       left_margin + preview->image_offset_x,
                       top_margin  + preview->image_offset_y,
                       (gdouble) width  * 72.0 / preview->image_xres,
                       (gdouble) height * 72.0 / preview->image_yres);
      cairo_stroke (cr);
    }
  else
    {
      GdkDrawable *drawable = preview->drawable;

      /* draw image */
      cairo_translate (cr,
                       left_margin + preview->image_offset_x,
                       top_margin  + preview->image_offset_y);

      if (preview->pixbuf == NULL)
        {
          gint width  = MIN (widget->allocation.width, 1024);
          gint height = MIN (widget->allocation.height, 1024);

          preview->pixbuf = get_thumbnail(drawable, width, height);
        }

      if (preview->pixbuf != NULL)
        {
          gint width, height;
          gdk_drawable_get_size(drawable, &width, &height);

          gdouble scale_x = ((gdouble) width /
                             gdk_pixbuf_get_width (preview->pixbuf));
          gdouble scale_y = ((gdouble) height /
                             gdk_pixbuf_get_height (preview->pixbuf));

          scale_x = scale_x * 72.0 / preview->image_xres;
          scale_y = scale_y * 72.0 / preview->image_yres;

          cairo_scale (cr, scale_x, scale_y);

          gdk_cairo_set_source_pixbuf (cr, preview->pixbuf, 0, 0);

          cairo_paint (cr);
        }
    }

  cairo_destroy (cr);

  return FALSE;
}
Exemplo n.º 12
0
gint compat_gdk_window_get_height(GdkWindow *window)
{
	gint w, h;
	gdk_drawable_get_size(window, &w, &h);
	return h;
}
Exemplo n.º 13
0
gint compat_gdk_window_get_width(GdkWindow *window)
{
	gint w, h;
	gdk_drawable_get_size(window, &w, &h);
	return w;
}
Exemplo n.º 14
0
void WdaGtk::change_value( int set_focus)
{
  int		sts;
  GtkWidget	*text_w;
  int		multiline;
  char		*value;
  int		input_size;

  if ( input_open) {
    g_object_set( cmd_input, "visible", FALSE, NULL);
    g_object_set( cmd_scrolledinput, "visible", FALSE, NULL);
    set_prompt( "");
    input_open = 0;
    return;
  }

  sts = wdanav->check_attr( &multiline, &input_node, input_name,
			    &value, &input_size);
  if ( EVEN(sts)) {
    if ( sts == WDA__NOATTRSEL)
      message( 'E', "No attribute is selected");
    else
      message( 'E', wnav_get_message( sts));
    return;
  }

  if ( multiline) {
    text_w = cmd_scrolledinput;
    g_object_set( text_w, "visible", TRUE, NULL);

    int w, h;
    gdk_drawable_get_size( pane->window, &w, &h);
    gtk_paned_set_position( GTK_PANED(pane), h - 170);
    gtk_widget_grab_focus( cmd_scrolledtextview);
    input_multiline = 1;
  }
  else {
    text_w = cmd_input;
    g_object_set( text_w, "visible", TRUE, NULL);
    gtk_widget_grab_focus( cmd_input);
    input_multiline = 0;
  }

  message( ' ', "");

  if ( value) {
    char *valueutf8 = g_convert( value, -1, "UTF-8", "ISO8859-1", NULL, NULL, NULL);

    if ( multiline) {
      GtkTextIter start_iter, end_iter;
      gtk_text_buffer_get_start_iter( cmd_scrolled_buffer, &start_iter);
      gtk_text_buffer_get_end_iter( cmd_scrolled_buffer, &end_iter);
      gtk_text_buffer_delete( cmd_scrolled_buffer, &start_iter, &end_iter);

      gtk_text_buffer_get_start_iter( cmd_scrolled_buffer, &start_iter);
      gtk_text_buffer_insert( cmd_scrolled_buffer, &start_iter, valueutf8, -1);

      // Select the text
      // gtk_text_buffer_get_start_iter( cmd_scrolled_buffer, &start_iter);
      // gtk_text_buffer_get_end_iter( cmd_scrolled_buffer, &end_iter);
      // gtk_text_buffer_select_range( cmd_scrolled_buffer, &start_iter, &end_iter);
    }
    else {
      gint pos = 0;
      gtk_editable_delete_text( GTK_EDITABLE(cmd_input), 0, -1);
      gtk_editable_insert_text( GTK_EDITABLE(text_w), valueutf8, strlen(valueutf8), &pos);

      // Select the text
      gtk_editable_set_position( GTK_EDITABLE(cmd_input), -1);
      gtk_editable_select_region( GTK_EDITABLE(cmd_input), 0, -1);
    }
    g_free( valueutf8);
  }
  else {
    gtk_editable_delete_text( GTK_EDITABLE(cmd_input), 0, -1);
  }
  set_prompt( "value >");
  input_open = 1;
}
Exemplo n.º 15
0
WdaGtk::WdaGtk( 
	GtkWidget      	*wa_parent_wid,
	void 		*wa_parent_ctx, 
	ldh_tSesContext wa_ldhses, 
	pwr_tObjid 	wa_objid,
	pwr_tClassId 	wa_classid,
	const char     *wa_attribute,
	int 		wa_editmode,
	int 		wa_advanced_user,
	int		wa_display_objectname) :
  Wda(wa_parent_ctx,wa_ldhses,wa_objid,wa_classid,wa_attribute,wa_editmode,
      wa_advanced_user,wa_display_objectname), 
  parent_wid(wa_parent_wid), wdaclass_dia(0)
{
  int sts;

  toplevel = (GtkWidget *) g_object_new( GTK_TYPE_WINDOW, 
			   "default-height", 700,
			   "default-width", 700,
			   "title", "Spreadsheet Editor",
			   NULL);

  g_signal_connect( toplevel, "delete_event", G_CALLBACK(delete_event), this);
  g_signal_connect( toplevel, "destroy", G_CALLBACK(destroy_event), this);
  g_signal_connect( toplevel, "focus-in-event", G_CALLBACK(action_inputfocus), this);

  CoWowGtk::SetWindowIcon( toplevel);

  GtkWidget *vbox = gtk_vbox_new( FALSE, 0);

  // Menu
  // Accelerators
  GtkAccelGroup *accel_g = (GtkAccelGroup *) g_object_new(GTK_TYPE_ACCEL_GROUP, NULL);
  gtk_window_add_accel_group(GTK_WINDOW(toplevel), accel_g);

  GtkMenuBar *menu_bar = (GtkMenuBar *) g_object_new(GTK_TYPE_MENU_BAR, NULL);

  // File entry
  GtkWidget *file_select_class = gtk_menu_item_new_with_mnemonic( "_Select Class");
  g_signal_connect( file_select_class, "activate", 
		    G_CALLBACK(activate_setclass), this);
  gtk_widget_add_accelerator( file_select_class, "activate", accel_g,
			      'c', GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);

  GtkWidget *file_select_attr = gtk_menu_item_new_with_mnemonic( "Select _Attribute");
  g_signal_connect( file_select_attr, "activate", 
		    G_CALLBACK(activate_setattr), this);
  gtk_widget_add_accelerator( file_select_attr, "activate", accel_g,
			      'a', GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);

  GtkWidget *file_next_attr = gtk_menu_item_new_with_mnemonic( "Next Attribute");
  g_signal_connect( file_next_attr, "activate", 
		    G_CALLBACK(activate_nextattr), this);
  gtk_widget_add_accelerator( file_next_attr, "activate", accel_g,
			      'n', GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);

  GtkWidget *file_prev_attr = gtk_menu_item_new_with_mnemonic( "Previous Attribute");
  g_signal_connect( file_prev_attr, "activate", 
		    G_CALLBACK(activate_prevattr), this);
  gtk_widget_add_accelerator( file_prev_attr, "activate", accel_g,
			      'p', GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);

  GtkWidget *file_export_text = gtk_menu_item_new_with_mnemonic( "Export to Textfile");
  g_signal_connect( file_export_text, "activate", 
		    G_CALLBACK(activate_export_text), this);

  GtkWidget *file_import_text = gtk_menu_item_new_with_mnemonic( "Import from Textfile");
  g_signal_connect( file_import_text, "activate", 
		    G_CALLBACK(activate_import_text), this);

  GtkWidget *file_print = gtk_image_menu_item_new_from_stock(GTK_STOCK_PRINT, NULL);
  g_signal_connect(file_print, "activate", G_CALLBACK(activate_print), this);

  GtkWidget *file_close = gtk_image_menu_item_new_from_stock(GTK_STOCK_CLOSE, accel_g);
  g_signal_connect(file_close, "activate", G_CALLBACK(activate_exit), this);

  GtkMenu *file_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_select_class);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_select_attr);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_next_attr);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_prev_attr);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_export_text);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_import_text);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_print);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_close);

  GtkWidget *file = gtk_menu_item_new_with_mnemonic("_File");
  gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), file);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), GTK_WIDGET(file_menu));

  // Functions entry
  GtkWidget *func_changevalue = gtk_menu_item_new_with_mnemonic( "_Change Value");
  g_signal_connect( func_changevalue, "activate", 
		    G_CALLBACK(activate_change_value), this);
  gtk_widget_add_accelerator( func_changevalue, "activate", accel_g,
			      'q', GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);

  GtkWidget *func_close_changeval = gtk_menu_item_new_with_mnemonic( "C_lose Change Value");
  g_signal_connect( func_close_changeval, "activate", 
		    G_CALLBACK(activate_close_changeval), this);
  gtk_widget_add_accelerator( func_close_changeval, "activate", accel_g,
			      't', GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);

  GtkMenu *func_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL(func_menu), func_changevalue);
  gtk_menu_shell_append(GTK_MENU_SHELL(func_menu), func_close_changeval);

  GtkWidget *functions = gtk_menu_item_new_with_mnemonic("_Functions");
  gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), functions);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(functions), GTK_WIDGET(func_menu));

  // Help entry
  GtkWidget *help_help = gtk_image_menu_item_new_from_stock(GTK_STOCK_HELP, accel_g);
  g_signal_connect(help_help, "activate", G_CALLBACK(activate_help), this);

  GtkMenu *help_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL(help_menu), help_help);

  GtkWidget *help = gtk_menu_item_new_with_mnemonic("_Help");
  gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), help);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(help), GTK_WIDGET(help_menu));

  pane = gtk_vpaned_new();

  utility = ((WUtility *)parent_ctx)->utype;
  wdanav = new WdaNavGtk( (void *)this, pane, "Plant",
		ldhses, objid, classid, attribute, wa_editmode,
		wa_advanced_user,
		wa_display_objectname, utility, &brow_widget, &sts);
  wdanav->message_cb = &Wda::message_cb;
  wdanav->change_value_cb = &Wda::change_value_cb;

  GtkWidget *statusbar = gtk_hbox_new( FALSE, 0);
  msg_label = gtk_label_new( "");
  gtk_widget_set_size_request( msg_label, -1, 25);
  cmd_prompt = gtk_label_new( "value > ");
  gtk_widget_set_size_request( cmd_prompt, -1, 25);
  cmd_entry = new CoWowEntryGtk( &value_recall);
  cmd_input = cmd_entry->widget();
  gtk_widget_set_size_request( cmd_input, -1, 25);
  g_signal_connect( cmd_input, "activate", 
		    G_CALLBACK(activate_cmd_input), this);

  gtk_box_pack_start( GTK_BOX(statusbar), msg_label, FALSE, FALSE, 0);
  gtk_box_pack_start( GTK_BOX(statusbar), cmd_prompt, FALSE, FALSE, 0);
  gtk_box_pack_start( GTK_BOX(statusbar), cmd_input, TRUE, TRUE, 0);

  gtk_box_pack_start( GTK_BOX(vbox), GTK_WIDGET(menu_bar), FALSE, FALSE, 0);
  gtk_box_pack_end( GTK_BOX(vbox), GTK_WIDGET(pane), TRUE, TRUE, 0);

  gtk_paned_pack1( GTK_PANED(pane), GTK_WIDGET(brow_widget), TRUE, TRUE);
  gtk_paned_pack2( GTK_PANED(pane), GTK_WIDGET(statusbar), FALSE, TRUE);
  
  gtk_container_add( GTK_CONTAINER(toplevel), vbox);

  cmd_scrolled_buffer = gtk_text_buffer_new( NULL);

  cmd_scrolledtextview = gtk_text_view_new_with_buffer( cmd_scrolled_buffer);
  GtkWidget *viewport = gtk_viewport_new( NULL, NULL);
  GtkWidget *scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
  gtk_container_add( GTK_CONTAINER(viewport), cmd_scrolledtextview);
  gtk_container_add( GTK_CONTAINER(scrolledwindow), viewport);

  cmd_scrolled_ok = gtk_button_new_with_label( "Ok");
  gtk_widget_set_size_request( cmd_scrolled_ok, 70, 25);
  g_signal_connect( cmd_scrolled_ok, "clicked", 
 		    G_CALLBACK(activate_cmd_scrolled_ok), this);
  cmd_scrolled_ca = gtk_button_new_with_label( "Cancel");
  gtk_widget_set_size_request( cmd_scrolled_ca, 70, 25);
  g_signal_connect( cmd_scrolled_ca, "clicked", 
 		    G_CALLBACK(activate_cmd_scrolled_ca), this);

  GtkWidget *hboxbuttons = gtk_hbox_new( TRUE, 40);
  gtk_box_pack_start( GTK_BOX(hboxbuttons), cmd_scrolled_ok, FALSE, FALSE, 0);
  gtk_box_pack_end( GTK_BOX(hboxbuttons), cmd_scrolled_ca, FALSE, FALSE, 0);

  cmd_scrolledinput = gtk_vbox_new( FALSE, 0);
  gtk_box_pack_start( GTK_BOX(cmd_scrolledinput), scrolledwindow, TRUE, TRUE, 0);
  gtk_box_pack_start( GTK_BOX(cmd_scrolledinput), hboxbuttons, FALSE, FALSE, 5);

  gtk_box_pack_start( GTK_BOX(statusbar), cmd_scrolledinput, TRUE, TRUE, 0);

  gtk_widget_show_all( toplevel);

  g_object_set( cmd_prompt, "visible", FALSE, NULL);
  g_object_set( cmd_input, "visible", FALSE, NULL);
  g_object_set( cmd_scrolledinput, "visible", FALSE, NULL);
  
  int w, h;
  gdk_drawable_get_size( pane->window, &w, &h);
  gtk_paned_set_position( GTK_PANED(pane), h - 50);

  create_class_dialog();
  wow = new CoWowGtk( toplevel);

  update_title();

  if ( utility == wb_eUtility_Wtt) {
    ((Wtt *)parent_ctx)->register_utility( (void *) this,
	wb_eUtility_SpreadsheetEditor);
  }
  ((Wda *)this)->open_class_dialog();
}
Exemplo n.º 16
0
void brush_bar(GdkDrawable *drawable, GdkGC *gc, int barWidth, int no)
{
	int width, height;
	GdkPoint points[3];

	gdk_drawable_get_size(drawable, &width, &height);
	set_foreground_color(gc, 65535*222/255, 65535*217/255, 65535*202/255);
	switch (no) {
		case 1:
			gdk_draw_rectangle(drawable, gc, TRUE, 0, height/4, barWidth-1, height/2);
			points[0].x = 7, points[0].y = height/2-5;
			points[1].x = 2, points[1].y = height/2;
			points[2].x = 7, points[2].y = height/2+5;
			set_foreground_color(gc, 65535*255/255, 65535*255/255, 65535*255/255);
			gdk_draw_polygon(drawable, gc, TRUE, points, 3);
			break;
		case 2:
			gdk_draw_rectangle(drawable, gc, TRUE, 0, 3*height/4, barWidth-1, height/4-1);
			gdk_draw_rectangle(drawable, gc, TRUE, 0, height-barWidth+1, width/4, barWidth-1);
			points[0].x = 3, points[0].y = height-10;
			points[1].x = 3, points[1].y = height-3;
			points[2].x = 10, points[2].y = height-3;
			set_foreground_color(gc, 65535*255/255, 65535*255/255, 65535*255/255);
			gdk_draw_polygon(drawable, gc, TRUE, points, 3);
			break;
		case 3:
			gdk_draw_rectangle(drawable, gc, TRUE, width/4, height-barWidth+1, width/2-1, barWidth-1);
			points[0].x = width/2, points[0].y = height-2;
			points[1].x = width/2+5, points[1].y = height-7;
			points[2].x = width/2-5, points[2].y = height-7;
			set_foreground_color(gc, 65535*255/255, 65535*255/255, 65535*255/255);
			gdk_draw_polygon(drawable, gc, TRUE, points, 3);
			break;
		case 4:
			gdk_draw_rectangle(drawable, gc, TRUE, width*3/4, height-barWidth+1, width/4, barWidth-1);
			gdk_draw_rectangle(drawable, gc, TRUE, width-barWidth+1, height*3/4, barWidth-1, height/4);
			points[0].x = width-10, points[0].y = height-3;
			points[1].x = width-3, points[1].y = height-3;
			points[2].x = width-3, points[2].y = height-10;
			set_foreground_color(gc, 65535*255/255, 65535*255/255, 65535*255/255);
			gdk_draw_polygon(drawable, gc, TRUE, points, 3);
			break;
		case 5:
			gdk_draw_rectangle(drawable, gc, TRUE, width-barWidth+1, height/4, barWidth-1, height/2);
			points[0].x = width-7, points[0].y = height/2-5;
			points[1].x = width-2, points[1].y = height/2;
			points[2].x = width-7, points[2].y = height/2+5;
			set_foreground_color(gc, 65535*255/255, 65535*255/255, 65535*255/255);
			gdk_draw_polygon(drawable, gc, TRUE, points, 3);
			break;
		case 6:
			gdk_draw_rectangle(drawable, gc, TRUE, width*3/4, 0, width/4, barWidth-1);
			gdk_draw_rectangle(drawable, gc, TRUE, width-MARGIN+1, 0, barWidth-1, height/4);
			points[0].x = width-10, points[0].y = 3;
			points[1].x = width-3, points[1].y = 3;
			points[2].x = width-3, points[2].y = 10;
			set_foreground_color(gc, 65535*255/255, 65535*255/255, 65535*255/255);
			gdk_draw_polygon(drawable, gc, TRUE, points, 3);
			break;
		case 7:
			gdk_draw_rectangle(drawable, gc, TRUE, width/4, 0, width/2, barWidth-1);
			points[0].x = width/2, points[0].y = 2;
			points[1].x = width/2-5, points[1].y = 7;
			points[2].x = width/2+5, points[2].y = 7;
			set_foreground_color(gc, 65535*255/255, 65535*255/255, 65535*255/255);
			gdk_draw_polygon(drawable, gc, TRUE, points, 3);
			break;
		case 8:
			gdk_draw_rectangle(drawable, gc, TRUE, 0, 0, barWidth-1, height/4);
			gdk_draw_rectangle(drawable, gc, TRUE, 0, 0, width/4, barWidth-1);
			points[0].x = 3, points[0].y = 3;
			points[1].x = 3, points[1].y = 10;
			points[2].x = 10, points[2].y = 3;
			set_foreground_color(gc, 65535*255/255, 65535*255/255, 65535*255/255);
			gdk_draw_polygon(drawable, gc, TRUE, points, 3);
			break;
	}
}
Exemplo n.º 17
0
/*
 * attrib_list is currently unused. This must be set to NULL or empty
 * (first attribute of None). See GLX 1.3 spec.
 */
GdkGLPixmap *
gdk_gl_pixmap_new (GdkGLConfig *glconfig,
                   GdkPixmap   *pixmap,
                   const int   *attrib_list)
{
  GdkGLPixmap *glpixmap;
  GdkGLPixmapImplWin32 *impl;

  gint width, height;
  gint depth;
  GdkPixmap *pixmap_gl = NULL;

  HBITMAP hbitmap_gl;
  HDC hdc_gl = NULL;
  PIXELFORMATDESCRIPTOR pfd;
  int pixel_format;

  HBITMAP hbitmap_gdk;
  HDC hdc_gdk = NULL;

  GDK_GL_NOTE_FUNC ();

  g_return_val_if_fail (GDK_IS_GL_CONFIG_IMPL_WIN32 (glconfig), NULL);
  g_return_val_if_fail (GDK_IS_PIXMAP (pixmap), NULL);

  /*
   * Create offscreen rendering area.
   */

  gdk_drawable_get_size (GDK_DRAWABLE (pixmap), &width, &height);
  depth = gdk_drawable_get_depth (GDK_DRAWABLE (pixmap));

  pixmap_gl = gdk_pixmap_new (NULL, width, height, depth);
  if (pixmap_gl == NULL)
    goto FAIL;

  /*
   * Source (OpenGL) DIB
   */

  hbitmap_gl = (HBITMAP) gdk_win32_drawable_get_handle (GDK_DRAWABLE (pixmap_gl));

  /* Create a memory DC. */
  hdc_gl = CreateCompatibleDC (NULL);
  if (hdc_gl == NULL)
    {
      g_warning ("cannot create a memory DC");
      goto FAIL;
    }

  /* Select the bitmap. */
  if (SelectObject (hdc_gl, hbitmap_gl) == NULL)
    {
      g_warning ("cannot select DIB");
      goto FAIL;
    }

  /*
   * Choose pixel format.
   */

  pfd = *(GDK_GL_CONFIG_PFD (glconfig));
  /* Draw to bitmap */
  pfd.dwFlags &= ~PFD_DRAW_TO_WINDOW;
  pfd.dwFlags |= PFD_DRAW_TO_BITMAP;

  /* Request pfd.cColorBits should exclude alpha bitplanes. */
  pfd.cColorBits = pfd.cRedBits + pfd.cGreenBits + pfd.cBlueBits;

  GDK_GL_NOTE_FUNC_IMPL ("ChoosePixelFormat");

  pixel_format = ChoosePixelFormat (hdc_gl, &pfd);
  if (pixel_format == 0)
    {
      g_warning ("cannot choose pixel format");
      goto FAIL;
    }

  /*
   * Set pixel format.
   */

  GDK_GL_NOTE_FUNC_IMPL ("SetPixelFormat");

  if (!SetPixelFormat (hdc_gl, pixel_format, &pfd))
    {
      g_warning ("cannot set pixel format");
      goto FAIL;
    }

  DescribePixelFormat (hdc_gl, pixel_format, sizeof (pfd), &pfd);

  GDK_GL_NOTE (MISC, g_message (" -- impl->pixel_format = 0x%x", pixel_format));
  GDK_GL_NOTE (MISC, _gdk_win32_gl_print_pfd (&pfd));

  /*
   * Destination (GDK) DIB
   */

  hbitmap_gdk = (HBITMAP) gdk_win32_drawable_get_handle (GDK_DRAWABLE (pixmap));

  /* Create a memory DC. */
  hdc_gdk = CreateCompatibleDC (hdc_gl);
  if (hdc_gdk == NULL)
    {
      g_warning ("cannot create a memory DC");
      goto FAIL;
    }

  /*
   * Instantiate the GdkGLPixmapImplWin32 object.
   */

  glpixmap = g_object_new (GDK_TYPE_GL_PIXMAP_IMPL_WIN32, NULL);
  impl = GDK_GL_PIXMAP_IMPL_WIN32 (glpixmap);

  glpixmap->drawable = GDK_DRAWABLE (pixmap);
  g_object_add_weak_pointer (G_OBJECT (glpixmap->drawable),
                             (gpointer *) &(glpixmap->drawable));

  impl->pixmap_gl = pixmap_gl;

  impl->width = width;
  impl->height = height;

  impl->pfd = pfd;
  impl->pixel_format = pixel_format;

  impl->glconfig = glconfig;
  g_object_ref (G_OBJECT (impl->glconfig));

  impl->hdc_gl = hdc_gl;

  impl->hdc_gdk = hdc_gdk;
  impl->hbitmap_gdk = hbitmap_gdk;

  impl->is_destroyed = FALSE;

  return glpixmap;

 FAIL:

  if (hdc_gdk != NULL)
    DeleteDC (hdc_gdk);

  if (hdc_gl != NULL)
    DeleteDC (hdc_gl);

  if (pixmap_gl != NULL)
    g_object_unref (G_OBJECT (pixmap_gl));

  return NULL;  
}
Exemplo n.º 18
0
static void
color_area_draw ()
{
  Color col;
  GdkColor *win_bg;
  GdkColor fg, bg, bd;
  gint rect_w, rect_h;
  gint width, height;
  gint def_width, def_height;
  gint swap_width, swap_height;
  GdkColor  mask_pattern;

  /* Check we haven't gotten initial expose yet,
   * no point in drawing anything
   */
  if (!color_area_pixmap || !color_area_gc)
    return;

  gdk_drawable_get_size (color_area_pixmap, &width, &height);

  win_bg = &(color_area->style->bg[GTK_STATE_NORMAL]);
  col = attributes_get_foreground();
  color_convert(&col, &fg);
  col = attributes_get_background();
  color_convert(&col, &bg);
  bd = color_gdk_black;

  rect_w = width * 0.65;
  rect_h = height * 0.65;

  /*  initialize the mask to transparent  */
  mask_pattern.pixel = 0;
  gdk_gc_set_foreground (mask_gc, &mask_pattern);
  gdk_draw_rectangle (color_area_mask, mask_gc, TRUE, 0, 0, -1, -1);

  /*  set the mask's gc to opaque  */
  mask_pattern.pixel = 1;
  gdk_gc_set_foreground (mask_gc, &mask_pattern);

  gdk_gc_set_foreground (color_area_gc, win_bg);
  gdk_draw_rectangle (color_area_pixmap, color_area_gc, 1,
		      0, 0, width, height);

  gdk_gc_set_foreground (color_area_gc, &bg);
  gdk_draw_rectangle (color_area_pixmap, color_area_gc, 1,
		      (width - rect_w), (height - rect_h), rect_w, rect_h);
  gdk_draw_rectangle (color_area_mask, mask_gc, TRUE,
		      (width - rect_w), (height - rect_h), rect_w, rect_h);

  if (active_color == FOREGROUND)
    gtk_paint_shadow (color_area->style, color_area_pixmap, GTK_STATE_NORMAL,
                      GTK_SHADOW_OUT,
                      NULL, color_area, NULL,
		      (width - rect_w), (height - rect_h),
                      rect_w, rect_h);
  else
    gtk_paint_shadow (color_area->style, color_area_pixmap, GTK_STATE_NORMAL,
                      GTK_SHADOW_IN,
                      NULL, color_area, NULL,
		      (width - rect_w), (height - rect_h),
                      rect_w, rect_h);

  gdk_gc_set_foreground (color_area_gc, &fg);
  gdk_draw_rectangle (color_area_pixmap, color_area_gc, 1,
		      0, 0, rect_w, rect_h);
  gdk_draw_rectangle (color_area_mask, mask_gc, TRUE,
		      0, 0, rect_w, rect_h);

  if (active_color == FOREGROUND)
    gtk_paint_shadow (color_area->style, color_area_pixmap, GTK_STATE_NORMAL,
                      GTK_SHADOW_IN,
                      NULL, color_area, NULL,
                      0, 0,
                      rect_w, rect_h);
  else
    gtk_paint_shadow (color_area->style, color_area_pixmap, GTK_STATE_NORMAL,
                      GTK_SHADOW_OUT,
                      NULL, color_area, NULL,
                      0, 0,
                      rect_w, rect_h);

  /*  draw the default pixmap  */
  gdk_drawable_get_size (default_pixmap, &def_width, &def_height);
  gdk_draw_drawable (color_area_pixmap, color_area_gc, default_pixmap,
		     0, 0, 0, height - def_height, def_width, def_height);
  gdk_draw_drawable (color_area_mask, mask_gc, default_mask,
		   0, 0, 0, height - def_height, def_width, def_height);

  /*  draw the swap pixmap  */
  gdk_drawable_get_size (swap_pixmap, &swap_width, &swap_height);
  gdk_draw_drawable (color_area_pixmap, color_area_gc, swap_pixmap,
		     0, 0, width - swap_width, 0, swap_width, swap_height);
  gdk_draw_drawable (color_area_mask, mask_gc, swap_mask,
		   0, 0, width - swap_width, 0, swap_width, swap_height);

  /*  draw the widget  */
  gdk_gc_set_clip_mask (color_area_gc, color_area_mask);
  gdk_gc_set_clip_origin (color_area_gc, 0, 0);
  gdk_draw_drawable (color_area->window, color_area_gc, color_area_pixmap,
		   0, 0, 0, 0, width, height);

  /*  reset the clip mask  */
  gdk_gc_set_clip_mask (color_area_gc, NULL);
}
Exemplo n.º 19
0
static gboolean
draw_gap_image (GtkStyle       *style,
                GdkWindow      *window,
                GdkRectangle   *area,
                GtkWidget      *widget,
                ThemeMatchData *match_data,
                gboolean        draw_center,
                gint            x,
                gint            y,
                gint            width,
                gint            height,
                GtkPositionType gap_side,
                gint            gap_x,
                gint            gap_width)
{
  ThemeImage *image;

  if ((width == -1) && (height == -1))
    gdk_drawable_get_size (window, &width, &height);
  else if (width == -1)
    gdk_drawable_get_size (window, &width, NULL);
  else if (height == -1)
    gdk_drawable_get_size (window, NULL, &height);

  if (!(match_data->flags & THEME_MATCH_ORIENTATION))
    {
      match_data->flags |= THEME_MATCH_ORIENTATION;

      if (height > width)
	match_data->orientation = GTK_ORIENTATION_VERTICAL;
      else
	match_data->orientation = GTK_ORIENTATION_HORIZONTAL;
    }

  match_data->flags |= THEME_MATCH_GAP_SIDE;
  match_data->gap_side = gap_side;

  image = match_theme_image (style, match_data);
  if (image)
    {
      gint xthickness, ythickness;
      GdkRectangle r1, r2, r3;
      guint components = COMPONENT_ALL;

      if (!draw_center)
	components |= COMPONENT_CENTER;

      if (!theme_pixbuf_get_geometry (image->gap_start, &xthickness, &ythickness))
	{
	  xthickness = style->xthickness;
	  ythickness = style->ythickness;
	}

      switch (gap_side)
	{
	case GTK_POS_TOP:
	  if (!draw_center)
	    components |= COMPONENT_NORTH_WEST | COMPONENT_NORTH | COMPONENT_NORTH_EAST;

	  r1.x      = x;
	  r1.y      = y;
	  r1.width  = gap_x;
	  r1.height = ythickness;
	  r2.x      = x + gap_x;
	  r2.y      = y;
	  r2.width  = gap_width;
	  r2.height = ythickness;
	  r3.x      = x + gap_x + gap_width;
	  r3.y      = y;
	  r3.width  = width - (gap_x + gap_width);
	  r3.height = ythickness;
	  break;

	case GTK_POS_BOTTOM:
	  if (!draw_center)
	    components |= COMPONENT_SOUTH_WEST | COMPONENT_SOUTH | COMPONENT_SOUTH_EAST;

	  r1.x      = x;
	  r1.y      = y + height - ythickness;
	  r1.width  = gap_x;
	  r1.height = ythickness;
	  r2.x      = x + gap_x;
	  r2.y      = y + height - ythickness;
	  r2.width  = gap_width;
	  r2.height = ythickness;
	  r3.x      = x + gap_x + gap_width;
	  r3.y      = y + height - ythickness;
	  r3.width  = width - (gap_x + gap_width);
	  r3.height = ythickness;
	  break;

	case GTK_POS_LEFT:
	  if (!draw_center)
	    components |= COMPONENT_NORTH_WEST | COMPONENT_WEST | COMPONENT_SOUTH_WEST;

	  r1.x      = x;
	  r1.y      = y;
	  r1.width  = xthickness;
	  r1.height = gap_x;
	  r2.x      = x;
	  r2.y      = y + gap_x;
	  r2.width  = xthickness;
	  r2.height = gap_width;
	  r3.x      = x;
	  r3.y      = y + gap_x + gap_width;
	  r3.width  = xthickness;
	  r3.height = height - (gap_x + gap_width);
	  break;

	case GTK_POS_RIGHT:
	  if (!draw_center)
	    components |= COMPONENT_NORTH_EAST | COMPONENT_EAST | COMPONENT_SOUTH_EAST;

	  r1.x      = x + width - xthickness;
	  r1.y      = y;
	  r1.width  = xthickness;
	  r1.height = gap_x;
	  r2.x      = x + width - xthickness;
	  r2.y      = y + gap_x;
	  r2.width  = xthickness;
	  r2.height = gap_width;
	  r3.x      = x + width - xthickness;
	  r3.y      = y + gap_x + gap_width;
	  r3.width  = xthickness;
	  r3.height = height - (gap_x + gap_width);
	  break;
        default:
          g_assert_not_reached ();
          break;
	}

      if (image->background)
        theme_pixbuf_render (image->background, G_OBJECT_TYPE (widget),
			     window, NULL, area, components, FALSE,
			     x, y, width, height);
      if (image->gap_start)
        theme_pixbuf_render (image->gap_start, G_OBJECT_TYPE (widget),
			     window, NULL, area, COMPONENT_ALL, FALSE,
			     r1.x, r1.y, r1.width, r1.height);
      if (image->gap)
        theme_pixbuf_render (image->gap, G_OBJECT_TYPE (widget),
			     window, NULL, area, COMPONENT_ALL, FALSE,
			     r2.x, r2.y, r2.width, r2.height);
      if (image->gap_end)
        theme_pixbuf_render (image->gap_end, G_OBJECT_TYPE (widget),
			     window, NULL, area, COMPONENT_ALL, FALSE,
			     r3.x, r3.y, r3.width, r3.height);

      return TRUE;
    }
  else
    return FALSE;
}
static void
locate_pointer_paint (GsdLocatePointerData *data,
		      cairo_t              *cr,
		      gboolean              composite)
{
  GdkColor color;
  gdouble progress, circle_progress;
  gint width, height, i;

  progress = data->progress;
  gdk_drawable_get_size (data->window, &width, &height);
  color = data->widget->style->bg[GTK_STATE_SELECTED];

  cairo_set_source_rgba (cr, 1., 1., 1., 0.);
  cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
  cairo_paint (cr);

  for (i = 0; i <= N_CIRCLES; i++)
    {
      if (progress < 0.)
	break;

      circle_progress = MIN (1., (progress * 2));
      progress -= CIRCLES_PROGRESS_INTERVAL;

      if (circle_progress >= 1.)
	continue;

      if (composite)
	{
	  cairo_set_source_rgba (cr,
				 color.red / 65535.,
				 color.green / 65535.,
				 color.blue / 65535.,
				 1 - circle_progress);
	  cairo_arc (cr,
		     width / 2,
		     height / 2,
		     circle_progress * width / 2,
		     0, 2 * G_PI);

	  cairo_fill (cr);
	  cairo_stroke (cr);
	}
      else
	{
	  cairo_set_source_rgb (cr, 0., 0., 0.);
	  cairo_set_line_width (cr, 3.);
	  cairo_arc (cr,
		     width / 2,
		     height / 2,
		     circle_progress * width / 2,
		     0, 2 * G_PI);
	  cairo_stroke (cr);

	  cairo_set_source_rgb (cr, 1., 1., 1.);
	  cairo_set_line_width (cr, 1.);
	  cairo_arc (cr,
		     width / 2,
		     height / 2,
		     circle_progress * width / 2,
		     0, 2 * G_PI);
	  cairo_stroke (cr);
	}
    }
}
Exemplo n.º 21
0
gboolean
mc_show_history (GtkWidget      *event_box, 
                         GdkEventButton *event,
		 MCData    *mc)
{
     GtkWidget *window;
     GtkWidget *scrolled_window;
     GtkListStore *store;
     GtkTreeIter iter;
     GtkTreeModel *model;
     GtkWidget    *treeview;
     GtkCellRenderer *cell_renderer;
     GtkTreeViewColumn *column;
     GtkRequisition  req;
     gchar *command_list[1];
     int i, j;
     gint win_x, win_y, width, height;
     gint entry_h, entry_x, entry_y, applet_x, applet_y;

     /* count commands stored in history list */
     for(i = 0, j = 0; i < MC_HISTORY_LIST_LENGTH; i++)
	 if(exists_history_entry(i))
	     j++;

     window = gtk_window_new(GTK_WINDOW_POPUP); 
     gtk_window_set_screen (GTK_WINDOW (window),
			    gtk_widget_get_screen (GTK_WIDGET (mc->applet)));
     gtk_window_set_policy(GTK_WINDOW(window), 0, 0, 1);
     gtk_widget_set_app_paintable (window, TRUE);
     gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_COMBO);
     /* cb */
     g_signal_connect_after(GTK_OBJECT(window),
			      "button_press_event",
			      GTK_SIGNAL_FUNC(history_popup_clicked_cb),
			      NULL);
     g_signal_connect_after (G_OBJECT (window), "key_press_event",
     		       G_CALLBACK (history_key_press_cb), NULL);

     gdk_window_get_geometry (GTK_WIDGET (mc->applet_box)->window, NULL, NULL,
         &width, &height, NULL);
     gdk_window_get_origin (mc->applet_box->window, &applet_x, &applet_y);
     gdk_window_get_position (mc->entry->window, &entry_x, &entry_y);
     gdk_drawable_get_size (mc->entry->window, NULL, &entry_h);

      win_x=applet_x + entry_x-1;
      win_y=applet_y + entry_y;

      /* size */
      gtk_widget_set_usize(GTK_WIDGET(window), width-2*(entry_x-1), 350);
     /* scrollbars */
     /* create scrolled window to put the Gtk_list widget inside */
     scrolled_window=gtk_scrolled_window_new(NULL, NULL);
     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
				    GTK_POLICY_AUTOMATIC,
				    GTK_POLICY_AUTOMATIC);
     g_signal_connect(GTK_OBJECT(scrolled_window),
			"button_release_event",
			GTK_SIGNAL_FUNC(history_popup_clicked_inside_cb),
			NULL);
     gtk_container_add(GTK_CONTAINER(window), scrolled_window);
     gtk_container_set_border_width (GTK_CONTAINER(scrolled_window), 1);
     gtk_widget_show(scrolled_window);
          
     store = gtk_list_store_new (1, G_TYPE_STRING);

     /* add history entries to list */
     if (j == 0) {
          gtk_list_store_append (store, &iter);
          gtk_list_store_set (store, &iter,0, _("No items in history"), -1);
     }
     else {	
          for(i = 0; i < MC_HISTORY_LIST_LENGTH; i++)
	      {
     	     if(exists_history_entry(i))
	     	 {
     		      command_list[0] = get_history_entry(i);
                      gtk_list_store_prepend (store, &iter);
                      gtk_list_store_set (store, &iter,0,command_list[0],-1);
		 }
	      }
     } 
     model = GTK_TREE_MODEL(store);
     treeview = gtk_tree_view_new_with_model (model);
     g_object_set_data (G_OBJECT (mc->applet), "tree", treeview);
     cell_renderer = gtk_cell_renderer_text_new ();
     column = gtk_tree_view_column_new_with_attributes (NULL, cell_renderer,
                                                       "text", 0, NULL);
     gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
     gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
     if (j == 0) {
          gtk_tree_selection_set_mode( (GtkTreeSelection *)gtk_tree_view_get_selection
                                (GTK_TREE_VIEW (treeview)),
                                 GTK_SELECTION_NONE);
     }
     else {
          gtk_tree_selection_set_mode( (GtkTreeSelection *)gtk_tree_view_get_selection
                                (GTK_TREE_VIEW (treeview)),
                                 GTK_SELECTION_SINGLE);
          g_signal_connect (G_OBJECT (treeview), "button_press_event",
     		       G_CALLBACK (history_list_button_press_cb), mc);
          g_signal_connect (G_OBJECT (treeview), "key_press_event",
     		       G_CALLBACK (history_list_key_press_cb), mc);
     }
   
     g_object_unref (G_OBJECT (model));
     gtk_container_add(GTK_CONTAINER(scrolled_window),treeview);
     gtk_widget_show (treeview); 
     
     gtk_widget_size_request (window, &req);

   
     switch (panel_applet_get_orient (mc->applet)) {
        case PANEL_APPLET_ORIENT_RIGHT:
        case PANEL_APPLET_ORIENT_LEFT:
     case PANEL_APPLET_ORIENT_DOWN:
            win_y += (entry_h+BORDER-1);
     	break;
        
     case PANEL_APPLET_ORIENT_UP:
            win_y -= (req.height+BORDER-1);
	break;
     }

     gtk_window_move (GTK_WINDOW (window), win_x, win_y);
     g_signal_connect ((gpointer) window, "expose_event",
                    G_CALLBACK (history_window_expose_event),
                    NULL);
     gtk_widget_show(window);

     /* grab focus */
     gdk_pointer_grab (window->window,
		       TRUE,
		       GDK_BUTTON_PRESS_MASK
		       | GDK_BUTTON_RELEASE_MASK
		       | GDK_ENTER_NOTIFY_MASK
		       | GDK_LEAVE_NOTIFY_MASK 
		       | GDK_POINTER_MOTION_MASK,
		       NULL,
		       NULL,
		       GDK_CURRENT_TIME); 
     gdk_keyboard_grab (window->window, TRUE, GDK_CURRENT_TIME);
     gtk_grab_add(window);
     gtk_widget_grab_focus (treeview);
 
     return FALSE;
}
Exemplo n.º 22
0
static void
on_calendar_realized(GtkWidget *widget, gpointer data)
{
    gint parent_x, parent_y, parent_w, parent_h;
    gint root_w, root_h;
    gint width, height, x, y;
    gint orientation;
    GdkScreen *screen;
    GtkWidget *parent;
    GtkRequisition requisition;

    orientation = GPOINTER_TO_INT(data);
    parent = g_object_get_data(G_OBJECT(widget), "calendar-parent");

    gdk_window_get_origin(GDK_WINDOW(parent->window), &parent_x, &parent_y);
    gdk_drawable_get_size(GDK_DRAWABLE(parent->window), &parent_w, &parent_h);

    screen = gdk_drawable_get_screen(GDK_DRAWABLE(widget->window));
    root_w = gdk_screen_get_width(GDK_SCREEN(screen));
    root_h = gdk_screen_get_height(GDK_SCREEN(screen));

    gtk_widget_size_request(GTK_WIDGET(widget), &requisition);
    width = requisition.width;
    height = requisition.height;

    /*
    g_print("parent: %dx%d +%d+%d\n", parent_w, parent_h, parent_x, parent_y);
    g_print("root: %dx%d\n", root_w, root_h);
    g_print("calendar: %dx%d\n", width, height);
    */

    if (orientation == GTK_ORIENTATION_VERTICAL) {
        if (parent_x < root_w / 2) {
            if (parent_y < root_h / 2) {
                /* upper left */
                x = parent_x + parent_w;
                y = parent_y;
            } else {
                /* lower left */
                x = parent_x + parent_w;
                y = parent_y + parent_h - height;
            }
        } else {
            if (parent_y < root_h / 2) {
                /* upper right */
                x = parent_x - width;
                y = parent_y;
            } else {
                /* lower right */
                x = parent_x - width;
                y = parent_y + parent_h - height;
            }
        }
    } else {
        if (parent_x < root_w / 2) {
            if (parent_y < root_h / 2) {
                /* upper left */
                x = parent_x;
                y = parent_y + parent_h;
            } else {
                /* lower left */
                x = parent_x;
                y = parent_y - height;
            }
        } else {
            if (parent_y < root_h / 2) {
                /* upper right */
                x = parent_x + parent_w - width;
                y = parent_y + parent_h;
            } else {
                /* lower right */
                x = parent_x + parent_w - width;
                y = parent_y - height;
            }
        }
    }

    gtk_window_move(GTK_WINDOW(widget), x, y);
}
Exemplo n.º 23
0
static PyObject *
PyGdkWindow_GetAttr(PyGdkWindow_Object *self, char *key)
{
    GdkWindow *win = PyGdkWindow_Get(self);
    gint x, y;
    GdkModifierType p_mask;

    if (!strcmp(key, "__members__"))
	return Py_BuildValue("[sssssssssssss]", "children", "colormap", "depth",
			     "height", "parent", "pointer", "pointer_state",
			     "toplevel", "type", "width", "x", "xid", "y");
    if (!strcmp(key, "width")) {
	gdk_drawable_get_size(win, &x, NULL);
	return PyInt_FromLong(x);
    }
    if (!strcmp(key, "height")) {
	gdk_drawable_get_size(win, NULL, &y);
	return PyInt_FromLong(y);
    }
    if (!strcmp(key, "x")) {
	gdk_window_get_position(win, &x, NULL);
	return PyInt_FromLong(x);
    }
    if (!strcmp(key, "y")) {
	gdk_window_get_position(win, NULL, &y);
	return PyInt_FromLong(y);
    }
    if (!strcmp(key, "colormap"))
	return PyGdkColormap_New(gdk_drawable_get_colormap(win));
    if (!strcmp(key, "pointer")) {
	gdk_window_get_pointer(win, &x, &y, NULL);
	return Py_BuildValue("(ii)", x, y);
    }
    if (!strcmp(key, "pointer_state")) {
	gdk_window_get_pointer(win, NULL, NULL, &p_mask);
	return PyInt_FromLong(p_mask);
    }
    if (!strcmp(key, "parent")) {
	GdkWindow *par = gdk_window_get_parent(win);
	if (par)
	    return PyGdkWindow_New(par);
	Py_INCREF(Py_None);
	return Py_None;
    }
    if (!strcmp(key, "toplevel"))
	return PyGdkWindow_New(gdk_window_get_toplevel(win));
    if (!strcmp(key, "children")) {
	GList *children, *tmp;
	PyObject *ret;
	children = gdk_window_get_children(win);
	if ((ret = PyList_New(0)) == NULL)
	    return NULL;
	for (tmp = children; tmp != NULL; tmp = tmp->next) {
	    PyObject *win = PyGdkWindow_New(tmp->data);
	    if (win == NULL) {
		Py_DECREF(ret);
		return NULL;
	    }
	    PyList_Append(ret, win);
	    Py_DECREF(win);
	}
	g_list_free(children);
	return ret;
    }
    if (!strcmp(key, "type"))
	return PyInt_FromLong(gdk_drawable_get_type(win));
    if (!strcmp(key, "depth")) {
	gdk_window_get_geometry(win, NULL, NULL, NULL, NULL, &x);
	return PyInt_FromLong(x);
    }
#ifdef WITH_XSTUFF
    if (!strcmp(key, "xid"))
	return PyInt_FromLong(GDK_WINDOW_XWINDOW(win));
#endif

    return Py_FindMethod(PyGdkWindow_methods, (PyObject *)self, key);
}
Exemplo n.º 24
0
void WAttGtk::change_value_close()
{
  unsigned char *s;
  int sts;

  if ( input_open) {
    if ( input_multiline) {
      gchar *text, *textutf8;
      GtkTextIter start_iter, end_iter;
      gtk_text_buffer_get_start_iter( cmd_scrolled_buffer, &start_iter);
      gtk_text_buffer_get_end_iter( cmd_scrolled_buffer, &end_iter);

      textutf8 = gtk_text_buffer_get_text( cmd_scrolled_buffer, &start_iter, &end_iter,
				       FALSE);
      text = g_convert( textutf8, -1, "ISO8859-1", "UTF-8", NULL, NULL, NULL);
      g_free( textutf8);

      // Replace ctrl characters with space
      for ( s = (unsigned char *) text; *s; s++) {
	if ( *s < ' ' && *s != 10 && *s != 13)
	  *s = ' ';
      }

      sts = wattnav->set_attr_value( input_node,
				     input_name, text);
      g_free( text);
      g_object_set( cmd_scrolledinput, "visible", FALSE, NULL);
      set_prompt( "");
      input_open = 0;

      int w, h;
      gdk_drawable_get_size( pane->window, &w, &h);
      gtk_paned_set_position( GTK_PANED(pane), h - 50);

      wattnav->redraw();
      wattnav->set_inputfocus();
    }
    else {
      char *text, *textutf8;
      textutf8 = gtk_editable_get_chars( GTK_EDITABLE(cmd_input), 0, -1);
      text = g_convert( textutf8, -1, "ISO8859-1", "UTF-8", NULL, NULL, NULL);
      g_free( textutf8);

      sts = wattnav->set_attr_value( input_node, 
				     input_name, text);
      g_free( text);
      g_object_set( cmd_input, "visible", FALSE, NULL);
      set_prompt( "");
      input_open = 0;
      if ( redraw_cb)
        (redraw_cb)( this);

      wattnav->set_inputfocus();
    }
    if ( pending_close) {
      if ( close_cb)
	(close_cb)( this);
      else
	delete this;
    }
  }
}
Exemplo n.º 25
0
XAttGtk::XAttGtk(GtkWidget* xa_parent_wid, void* xa_parent_ctx,
    pwr_sAttrRef* xa_objar, int xa_advanced_user, int* xa_sts)
    : XAtt(xa_parent_ctx, xa_objar, xa_advanced_user, xa_sts),
      parent_wid(xa_parent_wid)
{
  int sts;
  pwr_tAName title;

  *xa_sts = gdh_AttrrefToName(&objar, title, sizeof(title), cdh_mNName);
  if (EVEN(*xa_sts))
    return;

  str_StrncpyCutOff(title, title, 100, 1);

  toplevel = (GtkWidget*)g_object_new(GTK_TYPE_WINDOW, "default-height", 600,
      "default-width", 420, "title", CoWowGtk::convert_utf8(title), NULL);

  g_signal_connect(toplevel, "delete_event", G_CALLBACK(delete_event), this);
  g_signal_connect(toplevel, "destroy", G_CALLBACK(destroy_event), this);
  g_signal_connect(
      toplevel, "focus-in-event", G_CALLBACK(action_inputfocus), this);

  CoWowGtk::SetWindowIcon(toplevel);

  GtkWidget* vbox = gtk_vbox_new(FALSE, 0);

  // Menu
  // Accelerators
  GtkAccelGroup* accel_g
      = (GtkAccelGroup*)g_object_new(GTK_TYPE_ACCEL_GROUP, NULL);
  gtk_window_add_accel_group(GTK_WINDOW(toplevel), accel_g);

  GtkMenuBar* menu_bar = (GtkMenuBar*)g_object_new(GTK_TYPE_MENU_BAR, NULL);

  // File entry
  GtkWidget* file_print = gtk_image_menu_item_new_with_mnemonic(
      CoWowGtk::translate_utf8("_Print"));
  g_signal_connect(file_print, "activate", G_CALLBACK(activate_print), this);

  GtkWidget* file_close = gtk_image_menu_item_new_with_mnemonic(
      CoWowGtk::translate_utf8("_Close"));
  gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(file_close),
      gtk_image_new_from_stock("gtk-close", GTK_ICON_SIZE_MENU));
  g_signal_connect(file_close, "activate", G_CALLBACK(activate_exit), this);
  gtk_widget_add_accelerator(file_close, "activate", accel_g, 'w',
      GdkModifierType(GDK_CONTROL_MASK), GTK_ACCEL_VISIBLE);

  GtkMenu* file_menu = (GtkMenu*)g_object_new(GTK_TYPE_MENU, NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_print);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_close);

  GtkWidget* file
      = gtk_menu_item_new_with_mnemonic(CoWowGtk::translate_utf8("_File"));
  gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), file);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), GTK_WIDGET(file_menu));

  // Functions entry
  GtkWidget* func_changevalue = gtk_menu_item_new_with_mnemonic(
      CoWowGtk::translate_utf8("Change _Value"));
  g_signal_connect(
      func_changevalue, "activate", G_CALLBACK(activate_change_value), this);
  gtk_widget_add_accelerator(func_changevalue, "activate", accel_g, 'q',
      GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);

  GtkWidget* func_close_changeval = gtk_menu_item_new_with_mnemonic(
      CoWowGtk::translate_utf8("C_lose Change Value"));
  g_signal_connect(func_close_changeval, "activate",
      G_CALLBACK(activate_close_changeval), this);
  gtk_widget_add_accelerator(func_close_changeval, "activate", accel_g, 't',
      GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);

  GtkWidget* functions_open_plc = gtk_menu_item_new_with_mnemonic(
      CoWowGtk::translate_utf8("Open _Program"));
  g_signal_connect(
      functions_open_plc, "activate", G_CALLBACK(activate_open_plc), this);
  gtk_widget_add_accelerator(functions_open_plc, "activate", accel_g, 'l',
      GdkModifierType(GDK_CONTROL_MASK), GTK_ACCEL_VISIBLE);

  GtkWidget* functions_display_object = gtk_menu_item_new_with_mnemonic(
      CoWowGtk::translate_utf8("_Display object in Navigator"));
  g_signal_connect(functions_display_object, "activate",
      G_CALLBACK(activate_display_object), this);
  gtk_widget_add_accelerator(functions_display_object, "activate", accel_g, 'd',
      GdkModifierType(GDK_CONTROL_MASK), GTK_ACCEL_VISIBLE);

  GtkWidget* functions_show_cross = gtk_menu_item_new_with_mnemonic(
      CoWowGtk::translate_utf8("Show C_rossreferences"));
  g_signal_connect(
      functions_show_cross, "activate", G_CALLBACK(activate_show_cross), this);
  gtk_widget_add_accelerator(functions_show_cross, "activate", accel_g, 'r',
      GdkModifierType(GDK_CONTROL_MASK), GTK_ACCEL_VISIBLE);

  GtkWidget* functions_open_classgraph = gtk_menu_item_new_with_mnemonic(
      CoWowGtk::translate_utf8("Open _ClassGraph"));
  g_signal_connect(functions_open_classgraph, "activate",
      G_CALLBACK(activate_open_classgraph), this);
  gtk_widget_add_accelerator(functions_open_classgraph, "activate", accel_g,
      'g', GdkModifierType(GDK_CONTROL_MASK), GTK_ACCEL_VISIBLE);

  GtkMenu* func_menu = (GtkMenu*)g_object_new(GTK_TYPE_MENU, NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL(func_menu), func_changevalue);
  gtk_menu_shell_append(GTK_MENU_SHELL(func_menu), func_close_changeval);
  gtk_menu_shell_append(GTK_MENU_SHELL(func_menu), functions_open_plc);
  gtk_menu_shell_append(GTK_MENU_SHELL(func_menu), functions_display_object);
  gtk_menu_shell_append(GTK_MENU_SHELL(func_menu), functions_show_cross);
  gtk_menu_shell_append(GTK_MENU_SHELL(func_menu), functions_open_classgraph);

  GtkWidget* functions
      = gtk_menu_item_new_with_mnemonic(CoWowGtk::translate_utf8("_Functions"));
  gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), functions);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(functions), GTK_WIDGET(func_menu));

  // Help entry
  GtkWidget* help_help = gtk_image_menu_item_new_with_mnemonic(
      CoWowGtk::translate_utf8("_Help"));
  gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(help_help),
      gtk_image_new_from_stock("gtk-help", GTK_ICON_SIZE_MENU));
  g_signal_connect(help_help, "activate", G_CALLBACK(activate_help), this);
  gtk_widget_add_accelerator(
      help_help, "activate", accel_g, 'h', GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);

  GtkMenu* help_menu = (GtkMenu*)g_object_new(GTK_TYPE_MENU, NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL(help_menu), help_help);

  GtkWidget* help
      = gtk_menu_item_new_with_mnemonic(CoWowGtk::translate_utf8("_Help"));
  gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), help);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(help), GTK_WIDGET(help_menu));

  pane = gtk_vpaned_new();

  xattnav = new XAttNavGtk((void*)this, pane, xattnav_eType_Object, "Plant",
      &objar, xa_advanced_user, 0, &brow_widget, &sts);
  xattnav->message_cb = &message_cb;
  xattnav->change_value_cb = &change_value_cb;
  xattnav->popup_menu_cb = &xatt_popup_menu_cb;
  xattnav->is_authorized_cb = &xatt_is_authorized_cb;
  xattnav->init_cb = &init_cb;

  GtkWidget* statusbar = gtk_hbox_new(FALSE, 0);
  msg_label = gtk_label_new("");
  gtk_widget_set_size_request(msg_label, -1, 25);
  cmd_prompt = gtk_label_new("value > ");
  gtk_widget_set_size_request(cmd_prompt, -1, 25);
  cmd_entry = new CoWowEntryGtk(&value_recall);
  cmd_input = cmd_entry->widget();
  gtk_widget_set_size_request(cmd_input, -1, 25);
  g_signal_connect(cmd_input, "activate", G_CALLBACK(activate_cmd_input), this);

  gtk_box_pack_start(GTK_BOX(statusbar), msg_label, FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(statusbar), cmd_prompt, FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(statusbar), cmd_input, TRUE, TRUE, 0);

  gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(menu_bar), FALSE, FALSE, 0);
  gtk_box_pack_end(GTK_BOX(vbox), GTK_WIDGET(pane), TRUE, TRUE, 0);

  gtk_paned_pack1(GTK_PANED(pane), GTK_WIDGET(brow_widget), TRUE, TRUE);
  gtk_paned_pack2(GTK_PANED(pane), GTK_WIDGET(statusbar), FALSE, TRUE);

  gtk_container_add(GTK_CONTAINER(toplevel), vbox);

  cmd_scrolled_buffer = gtk_text_buffer_new(NULL);
  g_signal_connect_after(cmd_scrolled_buffer, "insert-text",
      G_CALLBACK(action_text_inserted), this);

  cmd_scrolledtextview = gtk_text_view_new_with_buffer(cmd_scrolled_buffer);
  GtkWidget* viewport = gtk_viewport_new(NULL, NULL);
  GtkWidget* scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
  gtk_container_add(GTK_CONTAINER(viewport), cmd_scrolledtextview);
  gtk_container_add(GTK_CONTAINER(scrolledwindow), viewport);

  cmd_scrolled_ok = gtk_button_new_with_label("Ok");
  gtk_widget_set_size_request(cmd_scrolled_ok, 70, 25);
  g_signal_connect(
      cmd_scrolled_ok, "clicked", G_CALLBACK(activate_cmd_scrolled_ok), this);
  cmd_scrolled_ca = gtk_button_new_with_label("Cancel");
  gtk_widget_set_size_request(cmd_scrolled_ca, 70, 25);
  g_signal_connect(
      cmd_scrolled_ca, "clicked", G_CALLBACK(activate_cmd_scrolled_ca), this);

  GtkWidget* hboxbuttons = gtk_hbox_new(TRUE, 40);
  gtk_box_pack_start(GTK_BOX(hboxbuttons), cmd_scrolled_ok, FALSE, FALSE, 0);
  gtk_box_pack_end(GTK_BOX(hboxbuttons), cmd_scrolled_ca, FALSE, FALSE, 0);

  cmd_scrolledinput = gtk_vbox_new(FALSE, 0);
  gtk_box_pack_start(GTK_BOX(cmd_scrolledinput), scrolledwindow, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(cmd_scrolledinput), hboxbuttons, FALSE, FALSE, 5);

  gtk_box_pack_start(GTK_BOX(statusbar), cmd_scrolledinput, TRUE, TRUE, 0);

  gtk_widget_show_all(toplevel);

  g_object_set(cmd_prompt, "visible", FALSE, NULL);
  g_object_set(cmd_input, "visible", FALSE, NULL);
  g_object_set(cmd_scrolledinput, "visible", FALSE, NULL);

  int w, h;
  gdk_drawable_get_size(pane->window, &w, &h);
  gtk_paned_set_position(GTK_PANED(pane), h - 50);

  *xa_sts = XATT__SUCCESS;
}
Exemplo n.º 26
0
WAttGtk::WAttGtk( 
	GtkWidget      	*wa_parent_wid,
	void 		*wa_parent_ctx, 
	ldh_tSesContext wa_ldhses, 
	pwr_sAttrRef 	wa_aref,
	int 		wa_editmode,
	int 		wa_advanced_user,
	int		wa_display_objectname) :
  WAtt(wa_parent_ctx,wa_ldhses,wa_aref,wa_editmode,wa_advanced_user,
       wa_display_objectname), parent_wid(wa_parent_wid)
{
  int sts;
  int size;
  char *namep;

  sts = ldh_AttrRefToName( ldhses, &aref, ldh_eName_Hierarchy, 
			   &namep, &size);
  if ( EVEN(sts)) return;

  toplevel = (GtkWidget *) g_object_new( GTK_TYPE_WINDOW, 
					 "default-height", 570,
					 "default-width", 410,
					 "title", CoWowGtk::convert_utf8(namep),
					 NULL);

  g_signal_connect( toplevel, "delete_event", G_CALLBACK(delete_event), this);
  g_signal_connect( toplevel, "destroy", G_CALLBACK(destroy_event), this);
  g_signal_connect( toplevel, "focus-in-event", G_CALLBACK(action_inputfocus), this);

  CoWowGtk::SetWindowIcon( toplevel);

  GtkWidget *vbox = gtk_vbox_new( FALSE, 0);

  // Menu
  // Accelerators
  GtkAccelGroup *accel_g = (GtkAccelGroup *) g_object_new(GTK_TYPE_ACCEL_GROUP, NULL);
  gtk_window_add_accel_group(GTK_WINDOW(toplevel), accel_g);

  GtkMenuBar *menu_bar = (GtkMenuBar *) g_object_new(GTK_TYPE_MENU_BAR, NULL);

  // File entry
  GtkWidget *file_close = gtk_image_menu_item_new_from_stock(GTK_STOCK_CLOSE, accel_g);
  g_signal_connect(file_close, "activate", G_CALLBACK(activate_exit), this);

  GtkWidget *file_print = gtk_image_menu_item_new_from_stock(GTK_STOCK_PRINT, accel_g);
  g_signal_connect(file_print, "activate", G_CALLBACK(activate_print), this);

  GtkMenu *file_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_print);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_close);

  GtkWidget *file = gtk_menu_item_new_with_mnemonic("_File");
  gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), file);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), GTK_WIDGET(file_menu));

  // Functions entry
  GtkWidget *func_changevalue = gtk_menu_item_new_with_mnemonic( "_Change Value");
  g_signal_connect( func_changevalue, "activate", 
		    G_CALLBACK(activate_change_value), this);
  gtk_widget_add_accelerator( func_changevalue, "activate", accel_g,
			      'q', GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);

  GtkWidget *func_close_changeval = gtk_menu_item_new_with_mnemonic( "C_lose Change Value");
  g_signal_connect( func_close_changeval, "activate", 
		    G_CALLBACK(activate_close_changeval), this);
  gtk_widget_add_accelerator( func_close_changeval, "activate", accel_g,
			      't', GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);

  GtkMenu *func_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL(func_menu), func_changevalue);
  gtk_menu_shell_append(GTK_MENU_SHELL(func_menu), func_close_changeval);

  GtkWidget *functions = gtk_menu_item_new_with_mnemonic("_Functions");
  gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), functions);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(functions), GTK_WIDGET(func_menu));

  // Help entry
  GtkWidget *help_help = gtk_image_menu_item_new_from_stock(GTK_STOCK_HELP, accel_g);
  g_signal_connect(help_help, "activate", G_CALLBACK(activate_help), this);

  GtkMenu *help_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL(help_menu), help_help);

  GtkWidget *help = gtk_menu_item_new_with_mnemonic("_Help");
  gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), help);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(help), GTK_WIDGET(help_menu));

  pane = gtk_vpaned_new();

  if ( ((WUtility *)parent_ctx)->utype == wb_eUtility_WNav)
    parent_ctx = ((WNav *)parent_ctx)->parent_ctx;
  utility = ((WUtility *)parent_ctx)->utype;
  
  wattnav = new WAttNavGtk( (void *)this, wattnav_eType_Object, pane, "Plant",
			      ldhses, aref, wa_editmode, wa_advanced_user,
			      wa_display_objectname, utility, &brow_widget, &sts);
  ((WAttNav *)wattnav)->message_cb = &WAtt::message_cb;
  ((WAttNav *)wattnav)->change_value_cb = &WAtt::change_value_cb;
  
  GtkWidget *statusbar = gtk_hbox_new( FALSE, 0);
  msg_label = gtk_label_new( "");
  gtk_widget_set_size_request( msg_label, -1, 25);
  cmd_prompt = gtk_label_new( "value > ");
  gtk_widget_set_size_request( cmd_prompt, -1, 25);
  cmd_entry = new CoWowEntryGtk( &value_recall);
  cmd_entry->set_hide_on_esc(true);
  cmd_input = cmd_entry->widget();
  gtk_widget_set_size_request( cmd_input, -1, 25);
  g_signal_connect( cmd_input, "activate", 
		    G_CALLBACK(activate_cmd_input), this);
  g_signal_connect( cmd_input, "hide",
		    G_CALLBACK(hide_cmd_input), this);

  gtk_box_pack_start( GTK_BOX(statusbar), msg_label, FALSE, FALSE, 0);
  gtk_box_pack_start( GTK_BOX(statusbar), cmd_prompt, FALSE, FALSE, 0);
  gtk_box_pack_start( GTK_BOX(statusbar), cmd_input, TRUE, TRUE, 0);

  gtk_box_pack_start( GTK_BOX(vbox), GTK_WIDGET(menu_bar), FALSE, FALSE, 0);
  gtk_box_pack_end( GTK_BOX(vbox), GTK_WIDGET(pane), TRUE, TRUE, 0);

  gtk_paned_pack1( GTK_PANED(pane), GTK_WIDGET(brow_widget), TRUE, TRUE);
  gtk_paned_pack2( GTK_PANED(pane), GTK_WIDGET(statusbar), FALSE, TRUE);
  
  gtk_container_add( GTK_CONTAINER(toplevel), vbox);

  cmd_scrolled_buffer = gtk_text_buffer_new( NULL);
  g_signal_connect_after( cmd_scrolled_buffer, "insert-text", 
 		    G_CALLBACK(action_text_inserted), this);

  cmd_scrolledtextview = gtk_text_view_new_with_buffer( cmd_scrolled_buffer);
  GtkWidget *viewport = gtk_viewport_new( NULL, NULL);
  GtkWidget *scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
  gtk_container_add( GTK_CONTAINER(viewport), cmd_scrolledtextview);
  gtk_container_add( GTK_CONTAINER(scrolledwindow), viewport);

  cmd_scrolled_ok = gtk_button_new_with_label( "Ok");
  gtk_widget_set_size_request( cmd_scrolled_ok, 70, 25);
  g_signal_connect( cmd_scrolled_ok, "clicked", 
 		    G_CALLBACK(activate_cmd_scrolled_ok), this);
  cmd_scrolled_ca = gtk_button_new_with_label( "Cancel");
  gtk_widget_set_size_request( cmd_scrolled_ca, 70, 25);
  g_signal_connect( cmd_scrolled_ca, "clicked", 
 		    G_CALLBACK(activate_cmd_scrolled_ca), this);

  GtkWidget *hboxbuttons = gtk_hbox_new( TRUE, 40);
  gtk_box_pack_start( GTK_BOX(hboxbuttons), cmd_scrolled_ok, FALSE, FALSE, 0);
  gtk_box_pack_end( GTK_BOX(hboxbuttons), cmd_scrolled_ca, FALSE, FALSE, 0);

  cmd_scrolledinput = gtk_vbox_new( FALSE, 0);
  gtk_box_pack_start( GTK_BOX(cmd_scrolledinput), scrolledwindow, TRUE, TRUE, 0);
  gtk_box_pack_start( GTK_BOX(cmd_scrolledinput), hboxbuttons, FALSE, FALSE, 5);

  gtk_box_pack_start( GTK_BOX(statusbar), cmd_scrolledinput, TRUE, TRUE, 0);

  gtk_widget_show_all( toplevel);

  g_object_set( cmd_prompt, "visible", FALSE, NULL);
  g_object_set( cmd_input, "visible", FALSE, NULL);
  g_object_set( cmd_scrolledinput, "visible", FALSE, NULL);
  
  int w, h;
  gdk_drawable_get_size( pane->window, &w, &h);
  gtk_paned_set_position( GTK_PANED(pane), h - 50);

  if ( utility == wb_eUtility_Wtt) {
    ((Wtt *)parent_ctx)->register_utility( (void *) this,
					   wb_eUtility_AttributeEditor);
  }
}
Exemplo n.º 27
0
static void
render (GtkWidget * widget)
{
  GSMColorButton *color_button = GSM_COLOR_BUTTON (widget);
  GdkColor *color, tmp_color = color_button->priv->color;
  color = &tmp_color;
  cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget));
  cairo_path_t *path = NULL;
  gint width, height;
  gdouble radius, arc_start, arc_end;
  gint highlight_factor;

  if (color_button->priv->highlight > 0) {
    highlight_factor = 8192 * color_button->priv->highlight;

    if (color->red + highlight_factor > 65535) 
      color->red = 65535;
    else
      color->red = color->red + highlight_factor;
    
    if (color->blue + highlight_factor > 65535) 
      color->blue = 65535;
    else
      color->blue = color->blue + highlight_factor;
    
    if (color->green + highlight_factor > 65535) 
      color->green = 65535;
    else
      color->green = color->green + highlight_factor;
  }
  gdk_cairo_set_source_color (cr, color);
  gdk_drawable_get_size (gtk_widget_get_window (widget), &width, &height);

  switch (color_button->priv->type)
    {
    case GSMCP_TYPE_CPU:
      //gtk_widget_set_size_request (widget, GSMCP_MIN_WIDTH, GSMCP_MIN_HEIGHT);
      cairo_paint (cr);
      cairo_set_line_width (cr, 1);
      cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
      cairo_rectangle (cr, 0.5, 0.5, width - 1, height - 1);
      cairo_stroke (cr);
      cairo_set_line_width (cr, 1);
      cairo_set_source_rgba (cr, 1, 1, 1, 0.4);
      cairo_rectangle (cr, 1.5, 1.5, width - 3, height - 3);
      cairo_stroke (cr);
      break;
    case GSMCP_TYPE_PIE:
      if (width < 32)		// 32px minimum size
	gtk_widget_set_size_request (widget, 32, 32);
      if (width < height)
	radius = width / 2;
      else
	radius = height / 2;

      arc_start = -G_PI_2 + 2 * G_PI * color_button->priv->fraction;
      arc_end = -G_PI_2;

      cairo_set_line_width (cr, 1);
      
      // Draw external stroke and fill
      if (color_button->priv->fraction < 0.01) {
        cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, 4.5,
		   0, 2 * G_PI);
      } else if (color_button->priv->fraction > 0.99) { 
        cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, radius - 2.25,
		   0, 2 * G_PI);
      } else {
        cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, radius - 2.25,
		   arc_start, arc_end);
        cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, 4.5,
		   arc_end, arc_start);
        cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, radius - 2.25,
		   arc_start, arc_start);
      }
      cairo_fill_preserve (cr);
      cairo_set_source_rgba (cr, 0, 0, 0, 0.7);
      cairo_stroke (cr);

      // Draw internal highlight
      cairo_set_source_rgba (cr, 1, 1, 1, 0.45);
      cairo_set_line_width (cr, 1);

      if (color_button->priv->fraction < 0.03) {
        cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, 3.25,
			    0, 2 * G_PI);
      } else if (color_button->priv->fraction > 0.99) {
        cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, radius - 3.5,
			    0, 2 * G_PI);
      } else {
        cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, radius - 3.5,
		 arc_start + (1 / (radius - 3.75)), 
		 arc_end - (1 / (radius - 3.75)));
        cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, 3.25,
		   arc_end - (1 / (radius - 3.75)),
                   arc_start + (1 / (radius - 3.75)));
        cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, radius - 3.5,
		 arc_start + (1 / (radius - 3.75)), 
		 arc_start + (1 / (radius - 3.75)));
      }
      cairo_stroke (cr);

      // Draw external shape
      cairo_set_line_width (cr, 1);
      cairo_set_source_rgba (cr, 0, 0, 0, 0.2);
      cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, radius - 1.25, 0,
		 G_PI * 2);
      cairo_stroke (cr);

      break;
    case GSMCP_TYPE_NETWORK_IN:
      if (color_button->priv->image_buffer == NULL)
	color_button->priv->image_buffer =
	  fill_image_buffer_from_file (cr, DATADIR "/pixmaps/gnome-system-monitor/download.svg");
      gtk_widget_set_size_request (widget, 32, 32);
      cairo_move_to (cr, 8.5, 1.5);
      cairo_line_to (cr, 23.5, 1.5);
      cairo_line_to (cr, 23.5, 11.5);
      cairo_line_to (cr, 29.5, 11.5);
      cairo_line_to (cr, 16.5, 27.5);
      cairo_line_to (cr, 15.5, 27.5);
      cairo_line_to (cr, 2.5, 11.5);
      cairo_line_to (cr, 8.5, 11.5);
      cairo_line_to (cr, 8.5, 1.5);
      cairo_close_path (cr);
      path = cairo_copy_path (cr);
      cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
      cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
      cairo_set_line_width (cr, 1);
      cairo_fill_preserve (cr);
      cairo_set_miter_limit (cr, 5.0);
      cairo_stroke (cr);
      cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
      cairo_append_path (cr, path);
      cairo_path_destroy(path);
      cairo_stroke (cr);
      cairo_set_source_surface (cr, color_button->priv->image_buffer, 0.0,
				0.0);
      cairo_paint (cr);

      break;
    case GSMCP_TYPE_NETWORK_OUT:
      if (color_button->priv->image_buffer == NULL)
	color_button->priv->image_buffer =
	  fill_image_buffer_from_file (cr, DATADIR "/pixmaps/gnome-system-monitor/upload.svg");
      gtk_widget_set_size_request (widget, 32, 32);
      cairo_move_to (cr, 16.5, 1.5);
      cairo_line_to (cr, 29.5, 17.5);
      cairo_line_to (cr, 23.5, 17.5);
      cairo_line_to (cr, 23.5, 27.5);
      cairo_line_to (cr, 8.5, 27.5);
      cairo_line_to (cr, 8.5, 17.5);
      cairo_line_to (cr, 2.5, 17.5);
      cairo_line_to (cr, 15.5, 1.5);
      cairo_line_to (cr, 16.5, 1.5);
      cairo_close_path (cr);
      path = cairo_copy_path (cr);
      cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
      cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
      cairo_set_line_width (cr, 1);
      cairo_fill_preserve (cr);
      cairo_set_miter_limit (cr, 5.0);
      cairo_stroke (cr);
      cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
      cairo_append_path (cr, path);
      cairo_path_destroy(path);
      cairo_stroke (cr);
      cairo_set_source_surface (cr, color_button->priv->image_buffer, 0.0,
				0.0);
      cairo_paint (cr);

      break;
    }
  cairo_destroy (cr);
}
Exemplo n.º 28
0
guint16 widget_height(GtkWidget *w)
{
  gint x, y;
  gdk_drawable_get_size(w->window, &x, &y);
  return(y);
}
Exemplo n.º 29
0
/****************************************************************************
  Return the dimensions of the area (container widget; maximum size) for
  the overview.
****************************************************************************/
void get_overview_area_dimensions(int *width, int *height)
{
  gdk_drawable_get_size(overview_canvas->window, width, height);
}
Exemplo n.º 30
0
guint16 widget_width(GtkWidget *w)
{
  gint x, y;
  gdk_drawable_get_size(w->window, &x, &y);
  return(x);
}