1 2 /* 3 * picture2gtk - makes pictures viewable using GTK+ 4 * Copyright (c) 2003-2006 by Mattias Hultgren <mattias_hultgren@tele2.se> 5 * 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; version 2 of the License. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public 17 * License along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 */ 20 21 /* 22 This object make the picture_h::picture-object viewable using GTK+2.0 23 24 */ 25 26 #ifndef PICTURE2GTK_H_ 27 #define PICTURE2GTK_H_ 28 29 #define PICTURE2GTK_H_VERSION "v7" 30 #define PICTURE2GTK_H_DATE "2003-12 - 2006-08" 31 32 #include <gtk/gtk.h> 33 #include "vartypes.h" 34 #include "picture.h" 35 36 37 void gdkcolor_to_colorrgb( const GdkColor &src, picture_h::colorrgb &dest ); 38 void colorrgb_to_gdkcolor( const picture_h::colorrgb &src, GdkColor &dest ); 39 40 41 class picture2gtk : public picture_h::picture 42 { 43 private: 44 struct 45 { 46 int32 width,height; 47 48 int32 buffersize; 49 guchar *buffer; 50 51 GtkWidget *drawarea; 52 }raw; 53 54 friend gboolean picture2gtk_expose(GtkWidget *widget,GdkEventExpose *event,gpointer user_data); 55 friend gboolean picture2gtk_destroy(GtkWidget *widget,gpointer user_data); 56 friend gboolean picture2gtk_mousemove(GtkWidget *widget,GdkEventMotion *event,gpointer user_data); 57 friend gboolean picture2gtk_mousedown(GtkWidget *widget,GdkEventButton *event,gpointer user_data); 58 friend gboolean picture2gtk_mouseup(GtkWidget *widget,GdkEventButton *event,gpointer user_data); 59 60 void set_raw_size(int32 newwidth,int32 newheight) throw(error_obj); 61 62 public: 63 // button 1=left 2=middle 3=right 4=? 5=? 64 void (*mousemove_func)( const picture2gtk *src, int32 x, int32 y); 65 void (*mousedown_func)( const picture2gtk *src, int32 x, int32 y, int32 button); 66 void (*mouseup_func) ( const picture2gtk *src, int32 x, int32 y, int32 button); 67 68 picture2gtk(); 69 picture2gtk(const picture2gtk &src) throw(error_obj); 70 picture2gtk(int32 newwidth, int32 newheight, const picture_h::colorrgb &newcolor) throw(error_obj); 71 virtual ~picture2gtk(); 72 73 void set_size(int32 newwidth,int32 newheight) throw(error_obj); 74 75 // WARNING: this pointer may (likely) get illegal after a call to set_size, update or update_from 76 // so a tip is.. don't save the pointer get a new one 77 // you mustn't delete [] pointer...the object will handle this get_intern_buffer(void)78 inline guchar * get_intern_buffer(void) { return raw.buffer; } 79 80 void update(void) throw(error_obj); 81 82 void update_from(const picture_h::picture &src) throw(error_obj); 83 84 void connect_to_drawing_area(GtkWidget *newdrawarea); 85 void disconnect_from_drawing_area(void); 86 void force_expose(void); 87 void force_expose_line(int32 line); 88 void force_expose_col(int32 col); 89 90 void operator=(const picture2gtk &src) throw(error_obj); 91 92 // this function leaves the mousemove, mousedown & mouseup as they were 93 void operator=(const picture_h::picture &src) throw(error_obj); 94 }; 95 96 typedef picture2gtk * picture2gtk_ptr; 97 98 #endif 99