Logo Search packages:      
Sourcecode: calcoo version File versions

gtkaux.c

/*
 * Calcoo: gtkaux.c
 *
 * Copyright (C) 2001, 2002 Alexei Kaminski
 *
 * auxiliary functions for operations with gtk widgets
 * no functions related to specific calcoo tasks
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <gtk/gtk.h>
#include <gdk/gdk.h>

#include "codes.h"
#include "body.h"
#include "defaults.h"
#include "gtkaux_headers.h"
#include "aux_headers.h"
#include "io_headers.h" 

void create_fg_pixmap(GtkWidget **pixmap_widget, char **pixmap_xpm)
/* creates a monochrome gtk pixmap having the color of the gtk foreground 
 * out of the given pixmap */
{
      GdkPixmap *pixmap, *all_black;
      GdkBitmap *mask;
      int w, h, tmp1, tmp2;
      int i;
      char *black_bits;
      int bitmap_size;

      /* getting the transparency mask from the original pixmap */
      pixmap = gdk_pixmap_create_from_xpm_d ( 
                    (body->main_window)->window,
                  &(mask),
                  &(body->style)->bg[GTK_STATE_NORMAL],
                  (gchar **) pixmap_xpm 
             );

      /* getting the size of the original pixmap */
      sscanf(pixmap_xpm[0],"%d %d %d %d", &w, &h, &tmp1, &tmp2);

      /* 7 and 8 here are not magic numbers! 
       * 8 is the number of bits in a byte
       * 7 is 8 - 1 */
      bitmap_size = ((w + 7) / 8) * h;

      /* creating a bitmap with all bits on, 
       * of the size of the original pixmap */
      black_bits = calloc(sizeof(char), bitmap_size);

        /* turning on all the pixels in the bitmap */
      for (i = 0; i < bitmap_size; i++)
            black_bits[i] = 0xff;

      /* creating a bitmap with all pixels having the color of foreground, 
       * of the size of the original pixmap */
      all_black = gdk_pixmap_create_from_data(
            (body->main_window)->window,
            black_bits,
            w, h,
            -1,
            &(body->style)->fg[GTK_STATE_FOR_CALCOO_FOREGROUND_COLOR],
            &(body->style)->bg[GTK_STATE_NORMAL]);
      
      if (CONVERT_ICONS_TO_FOREGROUND_COLOR)
            /* imposing the transparency mask of the original pixmap
             * onto the foreground rectangle */
            *pixmap_widget = gtk_pixmap_new(all_black, mask);
      else
            *pixmap_widget = gtk_pixmap_new(pixmap, mask);

      free(black_bits);
      gdk_pixmap_unref(pixmap);
      gdk_pixmap_unref(all_black);
      gdk_bitmap_unref(mask);
}

void create_n_put_pixmap(GtkWidget **pixmap_widget, int x, int y, 
                   char **pixmap_xpm)
{
      create_fg_pixmap(pixmap_widget, pixmap_xpm);
      gtk_fixed_put(GTK_FIXED(body->fixer), *pixmap_widget, x, y);
}

void own_selection(GtkWidget *widget)
{
      gtk_selection_owner_set (widget, GDK_SELECTION_PRIMARY, 
                         GDK_CURRENT_TIME);
}

void set_selection( GtkWidget        *widget, 
                GtkSelectionData *selection_data,
                guint             info,
                guint             time_stamp,
                gpointer          data )
{
      gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING, 8, 
                        body->char_display, 
                        strlen(body->char_display));
}

void request_selection(GtkWidget *widget)
{
      static GdkAtom atomos = GDK_NONE;
        if(atomos == GDK_NONE)
                atomos = gdk_atom_intern("STRING", FALSE);
        gtk_selection_convert(widget, GDK_SELECTION_PRIMARY, atomos, 
                        GDK_CURRENT_TIME);
}

void get_selection(GtkWidget *widget, GtkSelectionData *data, gpointer val)
{
      gchar *buff;
      int success;
      double x;

      if(data->length < 0) /* the selection could not be retrieved */
            return;
      buff = strcat(data->data,"\n");
      success = sscanf(buff,"%lf", &x);
      if (success)
            clicked_code_paste(x);
}


Generated by  Doxygen 1.6.0   Back to index