1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
|
/*
Copyright (C) 2000 Paul Wilkins
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* display.c by Paul Wilkins 1/2/2000 */
#include <stdio.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <gdk_imlib.h>
#include "globals.h"
#include "read_db.h"
#include "render_image.h"
#include "file_dialog.h"
#include "draw_image.h"
#include "find_match.h"
#include "info_popup.h"
#include "display.h"
/* some callbacks */
static gint ExposeCB(GtkWidget *widget, GdkEventExpose *event, gpointer func_data);
static gint ResizeCB(GtkWidget *widget, GdkEventConfigure *event, gpointer func_data);
static gint ButtonPressEvnt(GtkWidget *widget, GdkEventButton *event, gpointer func_data);
static gint ButtonReleaseEvnt(GtkWidget *widget, GdkEventButton *event, gpointer func_data);
static gint KeyPressEvnt(GtkWidget *widget, GdkEventKey *event, gpointer func_data);
static gint KeyReleaseEvnt(GtkWidget *widget, GdkEventKey *event, gpointer func_data);
GtkWidget *setup_display(GtkWidget *parent){
int wid, hgt;
wid = 300;
hgt = 300;
/***** create an event box *****/
globals.ebox = gtk_event_box_new();
gtk_box_pack_start(GTK_BOX(parent), globals.ebox, TRUE, TRUE, 0);
gtk_widget_show(globals.ebox);
/***** create a new scrolled window. *****/
globals.picScroll = gtk_scrolled_window_new(NULL, NULL);
gtk_widget_set_usize(globals.picScroll, wid, hgt);
gtk_container_set_border_width(GTK_CONTAINER(globals.picScroll), 0);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(globals.picScroll),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add(GTK_CONTAINER(globals.ebox), globals.picScroll);
/* gtk_box_pack_start(GTK_BOX(parent), globals.picScroll, TRUE, TRUE, 0); */
gtk_widget_show(globals.picScroll);
/***** create the drawing area *****/
globals.picDA = gtk_drawing_area_new();
gtk_drawing_area_size(GTK_DRAWING_AREA(globals.picDA), wid, hgt);
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(globals.picScroll),
globals.picDA);
gtk_widget_show(globals.picDA);
/* Signals used to handle window ops */
gtk_signal_connect(GTK_OBJECT(globals.picDA), "expose_event",
(GtkSignalFunc)ExposeCB, NULL);
gtk_signal_connect(GTK_OBJECT(globals.picDA), "configure_event",
(GtkSignalFunc)ResizeCB, NULL);
/* Event signals (Input) */
gtk_signal_connect(GTK_OBJECT(globals.picDA), "button_press_event",
(GtkSignalFunc)ButtonPressEvnt, NULL);
gtk_signal_connect(GTK_OBJECT(globals.picDA), "button_release_event",
(GtkSignalFunc)ButtonReleaseEvnt, NULL);
gtk_signal_connect_after(GTK_OBJECT(globals.picDA), "key_press_event",
(GtkSignalFunc)KeyPressEvnt, NULL);
gtk_signal_connect_after(GTK_OBJECT(globals.picDA), "key_release_event",
(GtkSignalFunc)KeyReleaseEvnt, NULL);
gtk_widget_set_events(globals.picDA,
GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK |
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
GTK_WIDGET_SET_FLAGS(globals.picDA, GTK_CAN_FOCUS);
gtk_widget_grab_focus(globals.picDA);
return globals.picScroll;
}
static gint ExposeCB(GtkWidget *widget, GdkEventExpose *event, gpointer func_data){
static int picInitalized = 0;
if(picInitalized == 0){
/* save the size of the display */
globals.disp_w = gdk_screen_width();
globals.disp_h = gdk_screen_height();
picInitalized = 1;
if(globals.start_fname){
open_image(globals.start_fname);
}
}
redraw_screen(event->area.x, event->area.y, event->area.width, event->area.height);
return FALSE;
}
static gint ResizeCB(GtkWidget *widget, GdkEventConfigure *event, gpointer func_data){
int w, h;
gdk_window_get_size(GTK_WIDGET(globals.ebox)->window, &w, &h);
/* we need to tell Gtk's brain dead scrollbar when not to appear */
if(w >= globals.cur_opt.width &&
h >= globals.cur_opt.height){
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(globals.picScroll),
GTK_POLICY_NEVER, GTK_POLICY_NEVER);
} else {
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(globals.picScroll),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
}
/* dammit: let the user resize the window!
I think gtk_widget_set_usize() messes with this. */
/*
gdk_window_set_hints(GTK_WIDGET(globals.topwin)->window,
0, 0, 300, 300, 0, 0, GDK_HINT_MIN_SIZE);
*/
return TRUE;
}
static gint KeyPressEvnt(GtkWidget *widget, GdkEventKey *event, gpointer func_data){
printf("picKeyPressEvnt\n");
return TRUE;
}
static gint KeyReleaseEvnt(GtkWidget *widget, GdkEventKey *event, gpointer func_data){
printf("picKeyReleaseEvnt\n");
return TRUE;
}
static gint ButtonPressEvnt(GtkWidget *widget, GdkEventButton *event, gpointer func_data) {
int xx, yy;
xx = event->x / globals.cur_opt.pixW;
yy = event->y / globals.cur_opt.pixH;
if(event->x < 0 || event->x >= globals.cur_opt.width) return TRUE;
if(event->y < 0 || event->y >= globals.cur_opt.height) return TRUE;
if(globals.image != NULL){
if(event->button == 2){
info_popup(xx, yy);
info_prev();
} else if (event->button == 3) {
info_popup(xx, yy);
info_next();
} else if (event->button == 1) {
info_popup(xx, yy);
}
}
return TRUE;
}
static gint ButtonReleaseEvnt(GtkWidget *widget, GdkEventButton *event, gpointer func_data) {
return TRUE;
}
int resize_window(){
int x, y, w, h;
/* calculate the window size */
if(globals.cur_opt.width > globals.disp_w){
w = globals.disp_w;
x = 0;
} else {
w = globals.cur_opt.width;
x = 100;
}
if(globals.cur_opt.height > globals.disp_h){
h = globals.disp_h;
y = 0;
} else {
h = globals.cur_opt.height;
y = 100;
}
gtk_drawing_area_size(GTK_DRAWING_AREA(globals.picDA),
globals.cur_opt.width, globals.cur_opt.height);
/*
gdk_window_resize(GTK_WIDGET(globals.topwin)->window, w, h);
gtk_window_set_default_size(GTK_WINDOW(globals.mainwin), w, h);
*/
/* set the size of the window, and allow user resizing */
gtk_widget_set_usize(GTK_WIDGET(globals.picScroll), w, h);
gtk_window_set_policy(GTK_WINDOW(globals.topwin), TRUE, TRUE, TRUE);
return 1;
}
|