Commit 7f06e1d3 authored by claes's avatar claes

GTK added

parent d15bcfc3
/*
* Proview $Id: glow_colpalwidget_gtk.cpp,v 1.1 2007-01-04 08:07:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* 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 the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#include <stdlib.h>
#include "glow_std.h"
#include <gtk/gtk.h>
#include <gtk/gtkprivate.h>
#include "glow_colpalwidget_gtk.h"
#include "glow.h"
#include "glow_ctx.h"
#include "glow_colpalctx.h"
#include "glow_draw.h"
#include "glow_draw_gtk.h"
typedef struct _ColPalWidgetGtk ColPalWidgetGtk;
typedef struct _ColPalWidgetGtkClass ColPalWidgetGtkClass;
typedef struct {
GtkWidget *colpal;
GtkWidget *form;
GtkWidget *scroll_h;
GtkWidget *scroll_v;
int scroll_h_managed;
int scroll_v_managed;
} colpalwidget_sScroll;
struct _ColPalWidgetGtk {
GtkDrawingArea parent;
/* Private */
void *colpal_ctx;
void *draw_ctx;
int (*init_proc)(GlowCtx *ctx, void *clien_data);
int is_navigator;
void *client_data;
GtkWidget *main_colpal_widget;
GtkWidget *scroll_h;
GtkWidget *scroll_v;
GtkWidget *form;
int scroll_h_ignore;
int scroll_v_ignore;
};
struct _ColPalWidgetGtkClass {
GtkDrawingAreaClass parent_class;
};
G_DEFINE_TYPE( ColPalWidgetGtk, colpalwidgetgtk, GTK_TYPE_DRAWING_AREA);
static void scroll_callback( glow_sScroll *data)
{
colpalwidget_sScroll *scroll_data;
scroll_data = (colpalwidget_sScroll *) data->scroll_data;
if ( data->total_width <= data->window_width) {
if ( data->offset_x == 0)
data->total_width = data->window_width;
if ( scroll_data->scroll_h_managed) {
// Remove horizontal scrollbar
}
}
else {
if ( !scroll_data->scroll_h_managed) {
// Insert horizontal scrollbar
}
}
if ( data->total_height <= data->window_height) {
if ( data->offset_y == 0)
data->total_height = data->window_height;
if ( scroll_data->scroll_v_managed) {
// Remove vertical scrollbar
}
}
else {
if ( !scroll_data->scroll_v_managed) {
// Insert vertical scrollbar
}
}
if ( data->offset_x < 0) {
data->total_width += -data->offset_x;
data->offset_x = 0;
}
if ( data->offset_y < 0) {
data->total_height += -data->offset_y;
data->offset_y = 0;
}
if ( data->total_height < data->window_height + data->offset_y)
data->total_height = data->window_height + data->offset_y;
if ( data->total_width < data->window_width + data->offset_x)
data->total_width = data->window_width + data->offset_x;
if ( data->window_width < 1)
data->window_width = 1;
if ( data->window_height < 1)
data->window_height = 1;
if ( scroll_data->scroll_h_managed) {
((ColPalWidgetGtk *)scroll_data->colpal)->scroll_h_ignore = 1;
g_object_set( ((GtkScrollbar *)scroll_data->scroll_h)->range.adjustment,
"upper", (gdouble)data->total_width,
"page-size", (gdouble)data->window_width,
"value", (gdouble)data->offset_x,
NULL);
gtk_adjustment_changed(
((GtkScrollbar *)scroll_data->scroll_h)->range.adjustment);
}
if ( scroll_data->scroll_v_managed) {
((ColPalWidgetGtk *)scroll_data->colpal)->scroll_v_ignore = 1;
g_object_set( ((GtkScrollbar *)scroll_data->scroll_v)->range.adjustment,
"upper", (gdouble)data->total_height,
"page-size", (gdouble)data->window_height,
"value", (gdouble)data->offset_y,
NULL);
gtk_adjustment_changed(
((GtkScrollbar *)scroll_data->scroll_v)->range.adjustment);
}
}
static void scroll_h_action( GtkWidget *w,
gpointer data)
{
ColPalWidgetGtk *colpalw = (ColPalWidgetGtk *)data;
if ( colpalw->scroll_h_ignore) {
colpalw->scroll_h_ignore = 0;
return;
}
printf( "Horizontal scroll callback\n");
ColPalCtx *ctx = (ColPalCtx *) colpalw->colpal_ctx;
gdouble value;
g_object_get( w,
"value", &value,
NULL);
glow_scroll_horizontal( ctx, int(value), 0);
}
static void scroll_v_action( GtkWidget *w,
gpointer data)
{
ColPalWidgetGtk *colpalw = (ColPalWidgetGtk *)data;
if ( colpalw->scroll_v_ignore) {
colpalw->scroll_v_ignore = 0;
return;
}
printf( "Vertical scroll callback\n");
ColPalCtx *ctx = (ColPalCtx *) colpalw->colpal_ctx;
gdouble value;
g_object_get( w,
"value", &value,
NULL);
glow_scroll_vertical( ctx, int(value), 0);
}
static int colpal_init_proc( GtkWidget *w, GlowCtx *fctx, void *client_data)
{
colpalwidget_sScroll *scroll_data;
ColPalCtx *ctx;
ctx = (ColPalCtx *) ((ColPalWidgetGtk *) w)->colpal_ctx;
if ( ((ColPalWidgetGtk *) w)->scroll_h) {
scroll_data = (colpalwidget_sScroll *) malloc( sizeof( colpalwidget_sScroll));
scroll_data->colpal = w;
scroll_data->scroll_h = ((ColPalWidgetGtk *) w)->scroll_h;
scroll_data->scroll_v = ((ColPalWidgetGtk *) w)->scroll_v;
scroll_data->form = ((ColPalWidgetGtk *) w)->form;
scroll_data->scroll_h_managed = 1;
scroll_data->scroll_v_managed = 1;
ctx->register_scroll_callback( (void *) scroll_data, scroll_callback);
}
ctx->configure();
if ( ((ColPalWidgetGtk *) w)->init_proc)
return (((ColPalWidgetGtk *) w)->init_proc)( ctx, client_data);
else
return 1;
}
static gboolean colpalwidgetgtk_expose( GtkWidget *glow, GdkEventExpose *event)
{
((GlowDrawGtk *)((ColPalCtx *)((ColPalWidgetGtk *)glow)->colpal_ctx)->gdraw)->event_handler(
*(GdkEvent *)event);
return TRUE;
}
static gboolean colpalwidgetgtk_event( GtkWidget *glow, GdkEvent *event)
{
if ( event->type == GDK_MOTION_NOTIFY) {
GdkEvent *next = gdk_event_peek();
if ( next && next->type == GDK_MOTION_NOTIFY) {
gdk_event_free( next);
return TRUE;
}
else if ( next)
gdk_event_free( next);
}
((GlowDrawGtk *)((ColPalCtx *)((ColPalWidgetGtk *)glow)->colpal_ctx)->gdraw)->event_handler( *event);
return TRUE;
}
static void colpalwidgetgtk_realize( GtkWidget *widget)
{
GdkWindowAttr attr;
gint attr_mask;
ColPalWidgetGtk *colpal;
g_return_if_fail (widget != NULL);
g_return_if_fail (IS_COLPALWIDGETGTK( widget));
GTK_WIDGET_SET_FLAGS( widget, GTK_REALIZED);
colpal = COLPALWIDGETGTK( widget);
attr.x = widget->allocation.x;
attr.y = widget->allocation.y;
attr.width = widget->allocation.width;
attr.height = widget->allocation.height;
attr.wclass = GDK_INPUT_OUTPUT;
attr.window_type = GDK_WINDOW_CHILD;
attr.event_mask = gtk_widget_get_events( widget) |
GDK_EXPOSURE_MASK |
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_KEY_PRESS_MASK |
GDK_POINTER_MOTION_MASK |
GDK_BUTTON_MOTION_MASK |
GDK_ENTER_NOTIFY_MASK |
GDK_LEAVE_NOTIFY_MASK;
attr.visual = gtk_widget_get_visual( widget);
attr.colormap = gtk_widget_get_colormap( widget);
attr_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
widget->window = gdk_window_new( widget->parent->window, &attr, attr_mask);
widget->style = gtk_style_attach( widget->style, widget->window);
gdk_window_set_user_data( widget->window, widget);
gtk_style_set_background( widget->style, widget->window, GTK_STATE_ACTIVE);
GTK_WIDGET_SET_FLAGS( widget, GTK_CAN_FOCUS);
if ( colpal->is_navigator) {
if ( !colpal->colpal_ctx) {
ColPalWidgetGtk *main_colpal = (ColPalWidgetGtk *) colpal->main_colpal_widget;
colpal->colpal_ctx = main_colpal->colpal_ctx;
colpal->draw_ctx = main_colpal->draw_ctx;
((GlowDrawGtk *)colpal->draw_ctx)->init_nav( widget);
}
}
else {
if ( !colpal->colpal_ctx) {
colpal->draw_ctx = new GlowDrawGtk( widget,
&colpal->colpal_ctx,
colpal_init_proc,
colpal->client_data,
glow_eCtxType_ColPal);
}
}
}
static void colpalwidgetgtk_class_init( ColPalWidgetGtkClass *klass)
{
GtkWidgetClass *widget_class;
widget_class = GTK_WIDGET_CLASS( klass);
widget_class->realize = colpalwidgetgtk_realize;
widget_class->expose_event = colpalwidgetgtk_expose;
widget_class->event = colpalwidgetgtk_event;
}
static void colpalwidgetgtk_init( ColPalWidgetGtk *glow)
{
}
GtkWidget *colpalwidgetgtk_new(
int (*init_proc)(GlowCtx *ctx, void *client_data),
void *client_data)
{
ColPalWidgetGtk *w;
w = (ColPalWidgetGtk *) g_object_new( COLPALWIDGETGTK_TYPE, NULL);
w->init_proc = init_proc;
w->colpal_ctx = 0;
w->is_navigator = 0;
w->client_data = client_data;
w->scroll_h = 0;
w->scroll_v = 0;
return (GtkWidget *) w;
}
GtkWidget *scrolledcolpalwidgetgtk_new(
int (*init_proc)(GlowCtx *ctx, void *client_data),
void *client_data, GtkWidget **colpalwidget)
{
ColPalWidgetGtk *w;
GtkWidget *form = gtk_scrolled_window_new( NULL, NULL);
w = (ColPalWidgetGtk *) g_object_new( COLPALWIDGETGTK_TYPE, NULL);
w->init_proc = init_proc;
w->colpal_ctx = 0;
w->is_navigator = 0;
w->client_data = client_data;
w->scroll_h = gtk_scrolled_window_get_hscrollbar( GTK_SCROLLED_WINDOW(form));
w->scroll_v = gtk_scrolled_window_get_vscrollbar( GTK_SCROLLED_WINDOW(form));
w->scroll_h_ignore = 0;
w->scroll_v_ignore = 0;
w->form = form;
*colpalwidget = GTK_WIDGET( w);
g_signal_connect( ((GtkScrollbar *)w->scroll_h)->range.adjustment,
"value-changed", G_CALLBACK(scroll_h_action), w);
g_signal_connect( ((GtkScrollbar *)w->scroll_v)->range.adjustment,
"value-changed", G_CALLBACK(scroll_v_action), w);
GtkWidget *viewport = gtk_viewport_new( NULL, NULL);
gtk_container_add( GTK_CONTAINER(viewport), GTK_WIDGET(w));
gtk_container_add( GTK_CONTAINER(form), GTK_WIDGET(viewport));
return (GtkWidget *) form;
}
GtkWidget *colpalnavwidgetgtk_new( GtkWidget *main_colpal)
{
ColPalWidgetGtk *w;
w = (ColPalWidgetGtk *) g_object_new( COLPALWIDGETGTK_TYPE, NULL);
w->init_proc = 0;
w->colpal_ctx = 0;
w->is_navigator = 1;
w->main_colpal_widget = main_colpal;
w->client_data = 0;
w->scroll_h = 0;
w->scroll_v = 0;
w->scroll_h_ignore = 0;
w->scroll_v_ignore = 0;
return (GtkWidget *) w;
}
#if 0
GType colpalwidgetgtk_get_type(void)
{
static GType colpalwidgetgtk_type = 0;
if ( !colpalwidgetgtk_type) {
static const GTypeInfo colpalwidgetgtk_info = {
sizeof(ColPalWidgetGtkClass), NULL, NULL, (GClassInitFunc)colpalwidgetgtk_class_init,
NULL, NULL, sizeof(ColPalWidgetGtk), 1, NULL, NULL};
colpalwidgetgtk_type = g_type_register_static( G_TYPE_OBJECT, "ColPalWidgetGtk", &colpalwidgetgtk_info,
(GTypeFlags)0);
}
return colpalwidgetgtk_type;
}
#endif
/*
* Proview $Id: glow_colpalwidget_gtk.h,v 1.1 2007-01-04 08:07:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* 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 the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#include <stdlib.h>
#include "glow_std.h"
#include <gtk/gtk.h>
#include <gtk/gtkprivate.h>
#include "glow.h"
#include "glow_ctx.h"
#include "glow_growctx.h"
#define COLPALWIDGETGTK_TYPE (colpalwidgetgtk_get_type())
#define COLPALWIDGETGTK(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), COLPALWIDGETGTK_TYPE, ColPalWidgetGtk))
#define COLPALWIDGETGTK_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST((obj), COLPALWIDGETGTK, ColPalWidgetGtkClass))
#define IS_COLPALWIDGETGTK(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), COLPALWIDGETGTK_TYPE))
#define IS_COLPALWIDGETGTK_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((obj), COLPALWIDGETGTK_TYPE))
#define COLPALWIDGETGTK_GET_CLASS (G_TYPE_INSTANCE_GET_CLASS((obj), COLPALWIDGETGTK, ColPalWidgetGtkClass))
GType colpalwidgetgtk_get_type(void);
GtkWidget *colpalwidgetgtk_new(
int (*init_proc)(GlowCtx *ctx, void *client_data),
void *client_data);
GtkWidget *scrolledcolpalwidgetgtk_new(
int (*init_proc)(GlowCtx *ctx, void *client_data),
void *client_data, GtkWidget **growwidget);
GtkWidget *colpalnavwidgetgtk_new( GtkWidget *main_grow);
/*
* Proview $Id: glow_curvewidget_gtk.cpp,v 1.1 2007-01-04 08:07:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* 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 the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#include <stdlib.h>
#include "glow_std.h"
#include <gtk/gtk.h>
#include <gtk/gtkprivate.h>
#include "glow_curvewidget_gtk.h"
#include "glow.h"
#include "glow_ctx.h"
#include "glow_curvectx.h"
#include "glow_draw.h"
#include "glow_draw_gtk.h"
typedef struct _CurveWidgetGtk CurveWidgetGtk;
typedef struct _CurveWidgetGtkClass CurveWidgetGtkClass;
typedef struct {
GtkWidget *curve;
GtkWidget *form;
GtkWidget *scroll_h;
GtkWidget *scroll_v;
int scroll_h_managed;
int scroll_v_managed;
} curvewidget_sScroll;
struct _CurveWidgetGtk {
GtkDrawingArea parent;
/* Private */
void *curve_ctx;
void *draw_ctx;
int (*init_proc)(GlowCtx *ctx, void *clien_data);
int is_navigator;
int is_realized;
int realize_navigator;
void *client_data;
GtkWidget *main_curve_widget;
GtkWidget *navigator_widget;
GtkWidget *scroll_h;
GtkWidget *scroll_v;
GtkWidget *form;
int scroll_h_ignore;
int scroll_v_ignore;
};
struct _CurveWidgetGtkClass {
GtkDrawingAreaClass parent_class;
};
G_DEFINE_TYPE( CurveWidgetGtk, curvewidgetgtk, GTK_TYPE_DRAWING_AREA);
static void scroll_callback( glow_sScroll *data)
{
curvewidget_sScroll *scroll_data;
scroll_data = (curvewidget_sScroll *) data->scroll_data;
if ( data->total_width <= data->window_width) {
if ( data->offset_x == 0)
data->total_width = data->window_width;
if ( scroll_data->scroll_h_managed) {
// Remove horizontal scrollbar
}
}
else {
if ( !scroll_data->scroll_h_managed) {
// Insert horizontal scrollbar
}
}
if ( data->total_height <= data->window_height) {
if ( data->offset_y == 0)
data->total_height = data->window_height;
if ( scroll_data->scroll_v_managed) {
// Remove vertical scrollbar
}
}
else {
if ( !scroll_data->scroll_v_managed) {
// Insert vertical scrollbar
}
}
if ( data->offset_x < 0) {
data->total_width += -data->offset_x;
data->offset_x = 0;
}
if ( data->offset_y < 0) {
data->total_height += -data->offset_y;
data->offset_y = 0;
}
if ( data->total_height < data->window_height + data->offset_y)
data->total_height = data->window_height + data->offset_y;
if ( data->total_width < data->window_width + data->offset_x)
data->total_width = data->window_width + data->offset_x;
if ( data->window_width < 1)
data->window_width = 1;
if ( data->window_height < 1)
data->window_height = 1;
if ( scroll_data->scroll_h_managed) {
((CurveWidgetGtk *)scroll_data->curve)->scroll_h_ignore = 1;
g_object_set( ((GtkScrollbar *)scroll_data->scroll_h)->range.adjustment,
"upper", (gdouble)data->total_width,
"page-size", (gdouble)data->window_width,
"value", (gdouble)data->offset_x,
NULL);
gtk_adjustment_changed(
((GtkScrollbar *)scroll_data->scroll_h)->range.adjustment);
}
if ( scroll_data->scroll_v_managed) {
((CurveWidgetGtk *)scroll_data->curve)->scroll_v_ignore = 1;
g_object_set( ((GtkScrollbar *)scroll_data->scroll_v)->range.adjustment,
"upper", (gdouble)data->total_height,
"page-size", (gdouble)data->window_height,
"value", (gdouble)data->offset_y,
NULL);
gtk_adjustment_changed(
((GtkScrollbar *)scroll_data->scroll_v)->range.adjustment);
}
}
static void scroll_h_action( GtkWidget *w,
gpointer data)
{
CurveWidgetGtk *curvew = (CurveWidgetGtk *)data;
if ( curvew->scroll_h_ignore) {
curvew->scroll_h_ignore = 0;
return;
}
printf( "Horizontal scroll callback\n");
CurveCtx *ctx = (CurveCtx *) curvew->curve_ctx;
gdouble value;
g_object_get( w,
"value", &value,
NULL);
glow_scroll_horizontal( ctx, int(value), 0);
}
static void scroll_v_action( GtkWidget *w,
gpointer data)
{
CurveWidgetGtk *curvew = (CurveWidgetGtk *)data;
if ( curvew->scroll_v_ignore) {
curvew->scroll_v_ignore = 0;
return;
}
printf( "Vertical scroll callback\n");
CurveCtx *ctx = (CurveCtx *) curvew->curve_ctx;
gdouble value;
g_object_get( w,
"value", &value,
NULL);
glow_scroll_vertical( ctx, int(value), 0);
}
static int curve_init_proc( GtkWidget *w, GlowCtx *fctx, void *client_data)
{
curvewidget_sScroll *scroll_data;
CurveCtx *ctx;
ctx = (CurveCtx *) ((CurveWidgetGtk *) w)->curve_ctx;
if ( ((CurveWidgetGtk *) w)->scroll_h) {
scroll_data = (curvewidget_sScroll *) malloc( sizeof( curvewidget_sScroll));
scroll_data->curve = w;
scroll_data->scroll_h = ((CurveWidgetGtk *) w)->scroll_h;
scroll_data->scroll_v = ((CurveWidgetGtk *) w)->scroll_v;
scroll_data->form = ((CurveWidgetGtk *) w)->form;
scroll_data->scroll_h_managed = 1;
scroll_data->scroll_v_managed = 1;
ctx->register_scroll_callback( (void *) scroll_data, scroll_callback);
}
return (((CurveWidgetGtk *) w)->init_proc)( ctx, client_data);
}
static gboolean curvewidgetgtk_expose( GtkWidget *glow, GdkEventExpose *event)
{
if ( !((CurveWidgetGtk *)glow)->curve_ctx)
// Navigator not yet created
return TRUE;
((GlowDrawGtk *)((CurveCtx *)((CurveWidgetGtk *)glow)->curve_ctx)->gdraw)->event_handler(
*(GdkEvent *)event);
return TRUE;
}
static gboolean curvewidgetgtk_event( GtkWidget *glow, GdkEvent *event)
{
if ( !((CurveWidgetGtk *)glow)->curve_ctx)
// Navigator not yet created
return TRUE;
if ( event->type == GDK_MOTION_NOTIFY) {
gdk_display_flush( ((GlowDrawGtk *)((CurveCtx *)((CurveWidgetGtk *)glow)->curve_ctx)->gdraw)->display);
GdkEvent *next = gdk_event_peek();
if ( next && next->type == GDK_MOTION_NOTIFY) {
gdk_event_free( next);
return TRUE;
}
else if ( next)
gdk_event_free( next);
}
((GlowDrawGtk *)((CurveCtx *)((CurveWidgetGtk *)glow)->curve_ctx)->gdraw)->event_handler( *event);
return TRUE;
}
static void curvewidgetgtk_realize( GtkWidget *widget)
{
GdkWindowAttr attr;
gint attr_mask;
CurveWidgetGtk *curve;
g_return_if_fail (widget != NULL);
g_return_if_fail (IS_CURVEWIDGETGTK( widget));
curve = CURVEWIDGETGTK( widget);
GTK_WIDGET_SET_FLAGS( widget, GTK_REALIZED);
attr.x = widget->allocation.x;
attr.y = widget->allocation.y;
attr.width = widget->allocation.width;
attr.height = widget->allocation.height;
attr.wclass = GDK_INPUT_OUTPUT;
attr.window_type = GDK_WINDOW_CHILD;
attr.event_mask = gtk_widget_get_events( widget) |
GDK_EXPOSURE_MASK |
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_KEY_PRESS_MASK |
GDK_POINTER_MOTION_MASK |
GDK_BUTTON_MOTION_MASK |
GDK_ENTER_NOTIFY_MASK |
GDK_LEAVE_NOTIFY_MASK;
attr.visual = gtk_widget_get_visual( widget);
attr.colormap = gtk_widget_get_colormap( widget);
attr_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
widget->window = gdk_window_new( widget->parent->window, &attr, attr_mask);
widget->style = gtk_style_attach( widget->style, widget->window);
gdk_window_set_user_data( widget->window, widget);
gtk_style_set_background( widget->style, widget->window, GTK_STATE_ACTIVE);
GTK_WIDGET_SET_FLAGS( widget, GTK_CAN_FOCUS);
if ( curve->is_navigator) {
if ( !curve->curve_ctx) {
CurveWidgetGtk *main_curve = (CurveWidgetGtk *) curve->main_curve_widget;
if ( !main_curve->is_realized) {
main_curve->realize_navigator = 1;
main_curve->navigator_widget = widget;
}
else {
curve->curve_ctx = main_curve->curve_ctx;
curve->draw_ctx = main_curve->draw_ctx;
((GlowDrawGtk *)curve->draw_ctx)->init_nav( widget);
}
}
}
else {
if ( !curve->curve_ctx) {
curve->draw_ctx = new GlowDrawGtk( widget,
&curve->curve_ctx,
curve_init_proc,
curve->client_data,
glow_eCtxType_Curve);
}
if ( curve->realize_navigator) {
CurveWidgetGtk *nav_curve = (CurveWidgetGtk *) curve->navigator_widget;
nav_curve->curve_ctx = curve->curve_ctx;
nav_curve->draw_ctx = curve->draw_ctx;
((GlowDrawGtk *)nav_curve->draw_ctx)->init_nav( (GtkWidget *)nav_curve);
}
}
curve->is_realized = 1;
}
static void curvewidgetgtk_class_init( CurveWidgetGtkClass *klass)
{
GtkWidgetClass *widget_class;
widget_class = GTK_WIDGET_CLASS( klass);
widget_class->realize = curvewidgetgtk_realize;
widget_class->expose_event = curvewidgetgtk_expose;
widget_class->event = curvewidgetgtk_event;
}
static void curvewidgetgtk_init( CurveWidgetGtk *glow)
{
}
GtkWidget *curvewidgetgtk_new(
int (*init_proc)(GlowCtx *ctx, void *client_data),
void *client_data)
{
CurveWidgetGtk *w;
w = (CurveWidgetGtk *) g_object_new( CURVEWIDGETGTK_TYPE, NULL);
w->init_proc = init_proc;
w->curve_ctx = 0;
w->is_navigator = 0;
w->client_data = client_data;
w->scroll_h = 0;
w->scroll_v = 0;
return (GtkWidget *) w;
}
GtkWidget *scrolledcurvewidgetgtk_new(
int (*init_proc)(GlowCtx *ctx, void *client_data),
void *client_data, GtkWidget **curvewidget)
{
CurveWidgetGtk *w;
GtkWidget *form = gtk_scrolled_window_new( NULL, NULL);
w = (CurveWidgetGtk *) g_object_new( CURVEWIDGETGTK_TYPE, NULL);
w->init_proc = init_proc;
w->curve_ctx = 0;
w->is_navigator = 0;
w->client_data = client_data;
w->scroll_h = gtk_scrolled_window_get_hscrollbar( GTK_SCROLLED_WINDOW(form));
w->scroll_v = gtk_scrolled_window_get_vscrollbar( GTK_SCROLLED_WINDOW(form));
w->scroll_h_ignore = 0;
w->scroll_v_ignore = 0;
w->form = form;
*curvewidget = GTK_WIDGET( w);
g_signal_connect( ((GtkScrollbar *)w->scroll_h)->range.adjustment,
"value-changed", G_CALLBACK(scroll_h_action), w);
g_signal_connect( ((GtkScrollbar *)w->scroll_v)->range.adjustment,
"value-changed", G_CALLBACK(scroll_v_action), w);
GtkWidget *viewport = gtk_viewport_new( NULL, NULL);
gtk_container_add( GTK_CONTAINER(viewport), GTK_WIDGET(w));
gtk_container_add( GTK_CONTAINER(form), GTK_WIDGET(viewport));
return (GtkWidget *) form;
}
GtkWidget *curvenavwidgetgtk_new( GtkWidget *main_curve)
{
CurveWidgetGtk *w;
w = (CurveWidgetGtk *) g_object_new( CURVEWIDGETGTK_TYPE, NULL);
w->init_proc = 0;
w->curve_ctx = 0;
w->is_navigator = 1;
w->main_curve_widget = main_curve;
w->client_data = 0;
w->scroll_h = 0;
w->scroll_v = 0;
w->scroll_h_ignore = 0;
w->scroll_v_ignore = 0;
return (GtkWidget *) w;
}
#if 0
GType curvewidgetgtk_get_type(void)
{
static GType curvewidgetgtk_type = 0;
if ( !curvewidgetgtk_type) {
static const GTypeInfo curvewidgetgtk_info = {
sizeof(CurveWidgetGtkClass), NULL, NULL, (GClassInitFunc)curvewidgetgtk_class_init,
NULL, NULL, sizeof(CurveWidgetGtk), 1, NULL, NULL};
curvewidgetgtk_type = g_type_register_static( G_TYPE_OBJECT, "CurveWidgetGtk", &curvewidgetgtk_info,
(GTypeFlags)0);
}
return curvewidgetgtk_type;
}
#endif
/*
* Proview $Id: glow_curvewidget_gtk.h,v 1.1 2007-01-04 08:07:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* 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 the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#include <stdlib.h>
#include "glow_std.h"
#include <gtk/gtk.h>
#include <gtk/gtkprivate.h>
#include "glow.h"
#include "glow_ctx.h"
#include "glow_curvectx.h"
#define CURVEWIDGETGTK_TYPE (curvewidgetgtk_get_type())
#define CURVEWIDGETGTK(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CURVEWIDGETGTK_TYPE, CurveWidgetGtk))
#define CURVEWIDGETGTK_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST((obj), CURVEWIDGETGTK, CurveWidgetGtkClass))
#define IS_CURVEWIDGETGTK(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), CURVEWIDGETGTK_TYPE))
#define IS_CURVEWIDGETGTK_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((obj), CURVEWIDGETGTK_TYPE))
#define CURVEWIDGETGTK_GET_CLASS (G_TYPE_INSTANCE_GET_CLASS((obj), CURVEWIDGETGTK, CurveWidgetGtkClass))
GType curvewidgetgtk_get_type(void);
GtkWidget *curvewidgetgtk_new(
int (*init_proc)(GlowCtx *ctx, void *client_data),
void *client_data);
GtkWidget *scrolledcurvewidgetgtk_new(
int (*init_proc)(GlowCtx *ctx, void *client_data),
void *client_data, GtkWidget **curvewidget);
GtkWidget *curvenavwidgetgtk_new( GtkWidget *main_curve);
/*
* Proview $Id: glow_draw_gtk.cpp,v 1.1 2007-01-04 08:07:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* 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 the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#include "glow_std.h"
using namespace std;
#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <gdk/gdkx.h>
#include "glow.h"
#include "glow_ctx.h"
#include "glow_browctx.h"
#include "glow_growctx.h"
#include "glow_colpalctx.h"
#include "glow_curvectx.h"
#include "glow_draw_gtk.h"
#include "glow_msg.h"
#if defined IMLIB
# include <gdk_imlib.h>
#else
typedef void *GdkImlibImage;
#endif
#define max(Dragon,Eagle) ((Dragon) > (Eagle) ? (Dragon) : (Eagle))
#define min(Dragon,Eagle) ((Dragon) < (Eagle) ? (Dragon) : (Eagle))
#define DRAW_PRESS_PIX 9
typedef struct {
GtkWidget w;
int x;
int y;
int width;
int height;
GlowArrayElem *node;
int number;
GlowCtx *ctx;
} draw_sAnnotData;
typedef struct {
GlowCtx *ctx;
void (*callback_func)( GlowCtx *ctx);
guint timer_id;
} draw_sTimerCb;
typedef struct {
Pixmap pixmap[DRAW_PIXMAP_SIZE];
} draw_sPixmap;
typedef struct {
int red;
int green;
int blue;
} draw_sColor;
static char font_names[glow_eDrawFont__][DRAW_FONT_SIZE][80] = { {
"-*-Helvetica-Medium-R-Normal--8-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Bold-R-Normal--10-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Bold-R-Normal--12-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Bold-R-Normal--14-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Bold-R-Normal--14-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Bold-R-Normal--18-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Bold-R-Normal--18-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Bold-R-Normal--18-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Bold-R-Normal--24-*-*-*-P-*-ISO8859-1"
},{
"-*-Helvetica-Medium-R-Normal--8-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Medium-R-Normal--10-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Medium-R-Normal--12-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Medium-R-Normal--14-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Medium-R-Normal--14-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Medium-R-Normal--18-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Medium-R-Normal--18-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Medium-R-Normal--18-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Medium-R-Normal--24-*-*-*-P-*-ISO8859-1"
} };
static GdkEvent last_event;
static GdkColor glow_allocate_named_color( GlowDrawGtk *draw_ctx, char *named_color);
static GdkColor glow_allocate_color( GlowDrawGtk *draw_ctx, int rgb_red,
int rgb_green, int rgb_blue);
static void event_timer( GlowCtx *ctx, int time_ms);
static void cancel_event_timer(GlowCtx *ctx);
static gboolean event_timer_cb( void *ctx);
static int glow_read_color_file( char *filename, draw_sColor **color_array,
int *size);
static GdkGC *get_gc( GlowDrawGtk *draw_ctx, int i, int j)
{
if ( !draw_ctx->gcs[i][j]) {
GdkGCValues xgcv;
double r, g, b;
GlowColor::rgb_color( i, &r, &g, &b);
xgcv.foreground = glow_allocate_color( draw_ctx, int(r * 65535),
int(g * 65535), int(b * 65535));
xgcv.background = draw_ctx->background;
xgcv.cap_style = GDK_CAP_BUTT;
xgcv.line_width = j + 1;
draw_ctx->gcs[i][j] = gdk_gc_new_with_values(
draw_ctx->m_wind.window, &xgcv,
(GdkGCValuesMask)(GDK_GC_FOREGROUND | GDK_GC_BACKGROUND |
GDK_GC_LINE_WIDTH | GDK_GC_CAP_STYLE));
}
return draw_ctx->gcs[i][j];
}
static int glow_create_cursor( GlowDrawGtk *draw_ctx)
{
/* Create some cursors */
/* Cross cursor */
draw_ctx->cursors[glow_eDrawCursor_CrossHair] =
gdk_cursor_new_for_display( draw_ctx->display, GDK_CROSSHAIR);
draw_ctx->cursors[glow_eDrawCursor_DiamondCross] =
gdk_cursor_new_for_display( draw_ctx->display, GDK_DIAMOND_CROSS);
draw_ctx->cursors[glow_eDrawCursor_Hand] =
gdk_cursor_new_for_display( draw_ctx->display, GDK_HAND2);
draw_ctx->cursors[glow_eDrawCursor_BottomLeftCorner] =
gdk_cursor_new_for_display( draw_ctx->display, GDK_BOTTOM_LEFT_CORNER);
draw_ctx->cursors[glow_eDrawCursor_BottomRightCorner] =
gdk_cursor_new_for_display( draw_ctx->display, GDK_BOTTOM_RIGHT_CORNER);
draw_ctx->cursors[glow_eDrawCursor_BottomSide] =
gdk_cursor_new_for_display( draw_ctx->display, GDK_BOTTOM_SIDE);
draw_ctx->cursors[glow_eDrawCursor_TopLeftCorner] =
gdk_cursor_new_for_display( draw_ctx->display, GDK_TOP_LEFT_CORNER);
draw_ctx->cursors[glow_eDrawCursor_TopRightCorner] =
gdk_cursor_new_for_display( draw_ctx->display, GDK_TOP_RIGHT_CORNER);
draw_ctx->cursors[glow_eDrawCursor_TopSide] =
gdk_cursor_new_for_display( draw_ctx->display, GDK_TOP_SIDE);
draw_ctx->cursors[glow_eDrawCursor_RightSide] =
gdk_cursor_new_for_display( draw_ctx->display, GDK_RIGHT_SIDE);
draw_ctx->cursors[glow_eDrawCursor_LeftSide] =
gdk_cursor_new_for_display( draw_ctx->display, GDK_LEFT_SIDE);
return 1;
}
static int draw_free_gc( GlowDrawGtk *draw_ctx)
{
int i, j;
for ( i = 1; i < glow_eDrawCursor__ ; i++)
gdk_cursor_unref( draw_ctx->cursors[i]);
gdk_gc_unref( draw_ctx->gc_inverse);
for ( i = 0; i < glow_eDrawType__; i++) {
for ( j = 0; j < DRAW_TYPE_SIZE; j++) {
if ( draw_ctx->gcs[i][j])
gdk_gc_unref( draw_ctx->gcs[i][j]);
}
}
for ( i = 0; i < glow_eDrawFont__; i++) {
for ( j = 0; j < DRAW_FONT_SIZE; j++) {
gdk_font_unref( draw_ctx->font[i][j]);
}
}
return 1;
}
static int glow_create_gc( GlowDrawGtk *draw_ctx, GdkWindow *window)
{
GdkFont *font;
GdkGCValues xgcv;
int i;
draw_sColor *color_array, *color_p;
int size, sts;
/* Inverse gc */
xgcv.background = glow_allocate_named_color( draw_ctx, "black");
xgcv.foreground = draw_ctx->background;
xgcv.cap_style = GDK_CAP_BUTT;
draw_ctx->gc_inverse = gdk_gc_new_with_values(
window, &xgcv, (GdkGCValuesMask)(GDK_GC_FOREGROUND | GDK_GC_BACKGROUND |
GDK_GC_CAP_STYLE));
/* Black line gc */
xgcv.foreground = glow_allocate_named_color( draw_ctx, "black");
xgcv.background = draw_ctx->background;
xgcv.cap_style = GDK_CAP_BUTT;
for ( i = 0; i < DRAW_TYPE_SIZE; i++) {
xgcv.line_width = i + 1;
draw_ctx->gcs[glow_eDrawType_Line][i] = gdk_gc_new_with_values(
window, &xgcv, (GdkGCValuesMask)(GDK_GC_FOREGROUND | GDK_GC_BACKGROUND |
GDK_GC_LINE_WIDTH | GDK_GC_CAP_STYLE));
}
/* Erase line gc */
xgcv.foreground = draw_ctx->background;
xgcv.background = draw_ctx->background;
xgcv.cap_style = GDK_CAP_BUTT;
// xgcv.fill_rule = WindingRule;
for ( i = 0; i < DRAW_TYPE_SIZE; i++) {
xgcv.line_width = i + 1;
draw_ctx->gcs[glow_eDrawType_LineErase][i] = gdk_gc_new_with_values(
window, &xgcv, (GdkGCValuesMask)(GDK_GC_FOREGROUND | GDK_GC_BACKGROUND |
GDK_GC_LINE_WIDTH | GDK_GC_CAP_STYLE));
}
/* Red line gc */
xgcv.foreground = glow_allocate_named_color( draw_ctx, "red");
xgcv.background = draw_ctx->background;
xgcv.cap_style = GDK_CAP_BUTT;
for ( i = 0; i < DRAW_TYPE_SIZE; i++)
{
xgcv.line_width = i + 1;
draw_ctx->gcs[glow_eDrawType_LineRed][i] = gdk_gc_new_with_values(
window, &xgcv, (GdkGCValuesMask)(GDK_GC_FOREGROUND | GDK_GC_BACKGROUND |
GDK_GC_LINE_WIDTH | GDK_GC_CAP_STYLE));
}
/* Gray line gc */
xgcv.foreground = glow_allocate_named_color( draw_ctx, "gray");
xgcv.background = draw_ctx->background;
xgcv.cap_style = GDK_CAP_BUTT;
// xgcv.fill_rule = WindingRule;
for ( i = 0; i < DRAW_TYPE_SIZE; i++) {
xgcv.line_width = i + 1;
draw_ctx->gcs[glow_eDrawType_LineGray][i] = gdk_gc_new_with_values(
window, &xgcv, (GdkGCValuesMask)(GDK_GC_FOREGROUND | GDK_GC_BACKGROUND |
GDK_GC_LINE_WIDTH | GDK_GC_CAP_STYLE));
}
sts = glow_read_color_file( "/home/claes/test/ge_colors.dat", &color_array, &size);
if ( ODD(sts)) {
color_p = color_array;
for ( int j = glow_eDrawType_Color4; j <= glow_eDrawType_Color300; j++) {
if ( j - glow_eDrawType_Color4 >= size)
break;
xgcv.foreground = glow_allocate_color( draw_ctx, color_p->red,
color_p->green, color_p->blue);
xgcv.background = draw_ctx->background;
xgcv.cap_style = GDK_CAP_BUTT;
// xgcv.fill_rule = WindingRule;
for ( i = 0; i < DRAW_TYPE_SIZE; i++) {
xgcv.line_width = i + 1;
draw_ctx->gcs[j][i] = gdk_gc_new_with_values(
window, &xgcv, (GdkGCValuesMask)(GDK_GC_FOREGROUND |
GDK_GC_BACKGROUND | GDK_GC_LINE_WIDTH | GDK_GC_CAP_STYLE));
}
color_p++;
}
free( (char *) color_array);
}
/* Dashed line gc */
xgcv.foreground = glow_allocate_named_color( draw_ctx, "black");
xgcv.background = draw_ctx->background;
xgcv.line_style = GDK_LINE_ON_OFF_DASH;
xgcv.cap_style = GDK_CAP_BUTT;
for ( i = 0; i < DRAW_TYPE_SIZE; i++) {
xgcv.line_width = i + 1;
gint8 dashes = 7 + i;
draw_ctx->gcs[glow_eDrawType_LineDashed][i] = gdk_gc_new_with_values( window, &xgcv,
(GdkGCValuesMask)(GDK_GC_FOREGROUND | GDK_GC_BACKGROUND | GDK_GC_LINE_WIDTH |
GDK_GC_LINE_STYLE | GDK_GC_CAP_STYLE));
gdk_gc_set_dashes( draw_ctx->gcs[glow_eDrawType_LineDashed][i], 0, &dashes, 1);
}
/* Red dashed line gc */
xgcv.foreground = glow_allocate_named_color( draw_ctx, "red");
xgcv.background = draw_ctx->background;
xgcv.line_style = GDK_LINE_ON_OFF_DASH;
xgcv.cap_style = GDK_CAP_BUTT;
for ( i = 0; i < DRAW_TYPE_SIZE; i++) {
xgcv.line_width = i + 1;
gint8 dashes = 7 + i;
draw_ctx->gcs[glow_eDrawType_LineDashedRed][i] = gdk_gc_new_with_values( window, &xgcv,
(GdkGCValuesMask)(GDK_GC_FOREGROUND | GDK_GC_BACKGROUND | GDK_GC_LINE_WIDTH|
GDK_GC_LINE_STYLE | GDK_GC_CAP_STYLE));
gdk_gc_set_dashes( draw_ctx->gcs[glow_eDrawType_LineDashedRed][i], 0, &dashes, 1);
}
/* Text */
xgcv.foreground = glow_allocate_named_color( draw_ctx, "black");
xgcv.background = draw_ctx->background;
for ( i = 0; i < DRAW_TYPE_SIZE; i++) {
draw_ctx->gcs[glow_eDrawType_TextHelvetica][i] = gdk_gc_new_with_values(
window, &xgcv, (GdkGCValuesMask)(GDK_GC_FOREGROUND | GDK_GC_BACKGROUND));
}
for ( i = 0; i < DRAW_TYPE_SIZE; i++) {
draw_ctx->gcs[glow_eDrawType_TextHelveticaBold][i] = gdk_gc_new_with_values(
window, &xgcv, (GdkGCValuesMask)(GDK_GC_FOREGROUND | GDK_GC_BACKGROUND));
}
xgcv.foreground = draw_ctx->background;
xgcv.background = draw_ctx->background;
for ( i = 0; i < DRAW_TYPE_SIZE; i++) {
draw_ctx->gcs[glow_eDrawType_TextHelveticaErase][i] = gdk_gc_new_with_values(
window, &xgcv, (GdkGCValuesMask)(GDK_GC_FOREGROUND | GDK_GC_BACKGROUND));
}
for ( i = 0; i < DRAW_TYPE_SIZE; i++) {
draw_ctx->gcs[glow_eDrawType_TextHelveticaEraseBold][i] = gdk_gc_new_with_values(
window, &xgcv, (GdkGCValuesMask)(GDK_GC_FOREGROUND | GDK_GC_BACKGROUND));
}
for ( i = 0; i < DRAW_FONT_SIZE; i++) {
font = gdk_font_load( font_names[glow_eDrawFont_HelveticaBold][i]);
gdk_gc_set_font( draw_ctx->gcs[glow_eDrawType_TextHelveticaBold][i], font);
gdk_gc_set_font( draw_ctx->gcs[glow_eDrawType_TextHelveticaEraseBold][i], font);
draw_ctx->font[glow_eDrawFont_HelveticaBold][i] = font;
}
for ( i = 0; i < DRAW_FONT_SIZE; i++) {
font = gdk_font_load( font_names[glow_eDrawFont_Helvetica][i]);
gdk_gc_set_font( draw_ctx->gcs[glow_eDrawType_TextHelvetica][i], font);
gdk_gc_set_font( draw_ctx->gcs[glow_eDrawType_TextHelveticaErase][i], font);
draw_ctx->font[glow_eDrawFont_Helvetica][i] = font;
}
return 1;
}
static GdkColor glow_allocate_named_color( GlowDrawGtk *draw_ctx, char *named_color)
{
GdkColor color;
if ( !gdk_color_parse( named_color, &color))
gdk_color_parse( "black", &color);
gdk_colormap_alloc_color( draw_ctx->colormap, &color, FALSE, TRUE);
return color;
}
static GdkColor glow_allocate_color( GlowDrawGtk *draw_ctx, int rgb_red,
int rgb_green, int rgb_blue)
{
GdkColor color;
color.red = rgb_red;
color.green = rgb_green;
color.blue = rgb_blue;
if ( !gdk_colormap_alloc_color( draw_ctx->colormap, &color, TRUE, TRUE)) {
printf( "** Color not allocated !\n");
color = glow_allocate_named_color( draw_ctx, "black");
}
return color;
}
GlowDrawGtk::~GlowDrawGtk()
{
ctx->set_nodraw();
if ( ctx->type() == glow_eCtxType_Grow)
delete (GrowCtx *)ctx;
else
delete ctx;
draw_free_gc( this);
if ( m_wind.buffer)
g_object_unref( m_wind.buffer);
if ( m_wind.background_pixmap)
g_object_unref( m_wind.background_pixmap);
if ( nav_wind.buffer)
g_object_unref( nav_wind.buffer);
if ( nav_wind.background_pixmap)
g_object_unref( nav_wind.background_pixmap);
}
int GlowDrawGtk::init_nav( GtkWidget *nav_widget)
{
nav_wind.toplevel = nav_widget;
nav_wind.window = nav_wind.toplevel->window;
gtk_widget_modify_bg( nav_widget, GTK_STATE_NORMAL, &background);
// glow_create_gc( this, nav_wind.window);
ctx->no_nav = 0;
return 1;
}
GlowDrawGtk::GlowDrawGtk(
GtkWidget *toplevel,
void **glow_ctx,
int (*init_proc)(GtkWidget *w, GlowCtx *ctx, void *client_data),
void *client_data,
glow_eCtxType type)
: ef(0), timer_id(0), click_sensitivity(0)
{
memset( gcs, 0, sizeof(gcs));
memset( font, 0, sizeof(font));
memset( cursors, 0, sizeof(cursors));
if ( type == glow_eCtxType_Brow)
ctx = (GlowCtx *) new BrowCtx("Claes context", 20);
else if ( type == glow_eCtxType_Grow)
ctx = (GlowCtx *) new GrowCtx("Claes context", 20);
else if ( type == glow_eCtxType_ColPal)
ctx = (GlowCtx *) new ColPalCtx("Claes context", 20);
else if ( type == glow_eCtxType_Curve)
ctx = (GlowCtx *) new CurveCtx("Claes context", 20);
else
ctx = new GlowCtx("Claes context", 20);
*glow_ctx = (void *) ctx;
ctx->gdraw = this;
m_wind.toplevel = toplevel;
display = gtk_widget_get_display( m_wind.toplevel);
m_wind.window = m_wind.toplevel->window;
screen = gtk_widget_get_screen( m_wind.toplevel);
ctx->mw.window = &m_wind;
ctx->navw.window = &nav_wind;
GtkStyle *style = gtk_widget_get_style( m_wind.toplevel);
background = style->bg[GTK_STATE_NORMAL];
original_background = background;
colormap = gdk_colormap_new( gdk_visual_get_system(), TRUE);
glow_create_gc( this, m_wind.window);
glow_create_cursor( this);
get_window_size( &ctx->mw, &ctx->mw.window_width, &ctx->mw.window_height);
create_buffer( &ctx->mw);
init_proc( toplevel, ctx, client_data);
}
int GlowDrawGtk::event_handler( GdkEvent event)
{
static int button_pressed = 0;
static int button_clicked = 0;
static int button_clicked_and_pressed = 0;
static int button1_pressed = 0;
static int button2_pressed = 0;
static int button3_pressed = 0;
static int last_press_x = 0;
static int last_press_y = 0;
// cout << "Event : button_pressed " << button_pressed << " clicked " <<
// button_clicked << " c&p " << button_clicked_and_pressed << endl;
if ( event.any.window == m_wind.window) {
switch ( event.type) {
case GDK_KEY_PRESS : {
guint keysym;
keysym = event.key.keyval;
if ( (keysym >= 0x020 && keysym <= 0x20ac) ||
(keysym >= 0xFF80 && keysym <= 0xFFB9 && keysym != GDK_KP_Enter && keysym != 0xFF44)) {
char buff;
gchar *bp;
bp = gdk_keyval_name( keysym);
buff = *bp;
if ( buff >= 0x020)
ctx->event_handler( glow_eEvent_Key_Ascii, 0, 0, (int)buff, 0);
else
ctx->event_handler( glow_eEvent_Key_CtrlAscii, 0, 0, (int)buff, 0);
}
else {
switch ( keysym) {
case GDK_Return:
case GDK_KP_Enter:
case 0xFF44: // XK_KP_Enter sometimes...
ctx->event_handler( glow_eEvent_Key_Return, 0, 0, 0, 0);
break;
case GDK_Up:
ctx->event_handler( glow_eEvent_Key_Up, 0, 0, 0, 0);
break;
case GDK_Down:
ctx->event_handler( glow_eEvent_Key_Down, 0, 0, 0, 0);
break;
case GDK_Right:
ctx->event_handler( glow_eEvent_Key_Right, 0, 0, 0, 0);
break;
case GDK_Left:
ctx->event_handler( glow_eEvent_Key_Left, 0, 0, 0, 0);
break;
case GDK_Page_Up:
ctx->event_handler( glow_eEvent_Key_PageUp, 0, 0, 0, 0);
break;
case GDK_Page_Down:
ctx->event_handler( glow_eEvent_Key_PageDown, 0, 0, 0, 0);
break;
case GDK_Delete:
case GDK_BackSpace:
ctx->event_handler( glow_eEvent_Key_BackSpace, 0, 0, 0, 0);
break;
case GDK_KP_F1:
ctx->event_handler( glow_eEvent_Key_PF1, 0, 0, 0, 0);
break;
case GDK_KP_F2:
ctx->event_handler( glow_eEvent_Key_PF2, 0, 0, 0, 0);
break;
case GDK_KP_F3:
ctx->event_handler( glow_eEvent_Key_PF3, 0, 0, 0, 0);
break;
case GDK_KP_F4:
ctx->event_handler( glow_eEvent_Key_PF4, 0, 0, 0, 0);
break;
case GDK_Cancel:
ctx->event_handler( glow_eEvent_Key_Escape, 0, 0, 0, 0);
break;
case GDK_Tab:
if ( event.key.state & GDK_SHIFT_MASK)
ctx->event_handler( glow_eEvent_Key_ShiftTab, 0, 0, 0, 0);
else
ctx->event_handler( glow_eEvent_Key_Tab, 0, 0, 0, 0);
break;
default:
;
}
}
break;
}
case GDK_BUTTON_PRESS :
// cout << "Button press event" << endl;
// printf( "-- Button event: (%d,%d) button: %d time:%d\n", event.xbutton.x,
// event.xbutton.y, event.xbutton.button, event.xbutton.time);
// XSetInputFocus( display, m_wind.window,
// RevertToNone, CurrentTime);
switch ( event.button.button) {
case 1:
ctx->event_handler( glow_eEvent_MB1Down, (int)event.button.x, (int)event.button.y, 0, 0);
if ( click_sensitivity & glow_mSensitivity_MB1Click &&
!(click_sensitivity & glow_mSensitivity_MB1DoubleClick) &&
!(click_sensitivity & glow_mSensitivity_MB1Press)) {
memcpy( &last_event, &event, sizeof(event));
button_pressed = 0;
button_clicked = 1;
last_press_x = (int)event.button.x;
last_press_y = (int)event.button.y;
return 1;
}
else if ( !(click_sensitivity & glow_mSensitivity_MB1Click) &&
!(click_sensitivity & glow_mSensitivity_MB1DoubleClick) &&
click_sensitivity & glow_mSensitivity_MB1Press) {
memcpy( &last_event, &event, sizeof(event));
button_pressed = 1;
button_clicked = 0;
last_press_x = (int)event.button.x;
last_press_y = (int)event.button.y;
}
break;
case 3:
ctx->event_handler( glow_eEvent_MB3Down, (int)event.button.x, (int)event.button.y, 0, 0);
if ( click_sensitivity & glow_mSensitivity_MB3Press &&
!(click_sensitivity & glow_mSensitivity_MB3DoubleClick) &&
!(click_sensitivity & glow_mSensitivity_MB3Click)) {
ctx->event_handler( glow_eEvent_MB3Press,
(int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
return 1;
}
else if ( click_sensitivity & glow_mSensitivity_MB3Click &&
!(click_sensitivity & glow_mSensitivity_MB3DoubleClick) &&
!(click_sensitivity & glow_mSensitivity_MB3Press))
{
memcpy( &last_event, &event, sizeof(event));
button_pressed = 0;
button_clicked = 1;
last_press_x = (int)event.button.x;
last_press_y = (int)event.button.y;
return 1;
}
break;
}
/* Detect press or click event */
if ( button_clicked) {
/* Wait for release */
button_clicked_and_pressed = 1;
cancel_event_timer( ctx);
button_clicked = 0;
memcpy( &last_event, &event, sizeof(event));
button_pressed = event.button.button;
last_press_x = (int)event.button.x;
last_press_y = (int)event.button.y;
event_timer(ctx, 200);
return 1;
}
if ( !button_pressed ) {
memcpy( &last_event, &event, sizeof(event));
button_pressed = event.button.button;
last_press_x = (int)event.button.x;
last_press_y = (int)event.button.y;
event_timer(ctx, 200);
return 1;
}
else {
// cout << "Button press detected" << endl;
/* Press event, callback from timer */
button_pressed = 0;
button_clicked_and_pressed = 0;
switch ( event.button.button) {
case 1: // Button 1
button1_pressed = 1;
if ( (event.button.state & GDK_SHIFT_MASK) &&
!(event.button.state & GDK_CONTROL_MASK)) {
ctx->event_handler( glow_eEvent_MB1PressShift, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
else if ( !(event.button.state & GDK_SHIFT_MASK) &&
(event.button.state & GDK_CONTROL_MASK)) {
ctx->event_handler( glow_eEvent_MB1PressCtrl, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
else if ( (event.button.state & GDK_SHIFT_MASK) &&
(event.button.state & GDK_CONTROL_MASK)) {
ctx->event_handler( glow_eEvent_MB1PressShiftCtrl, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
else {
ctx->event_handler( glow_eEvent_MB1Press, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
break;
case 2: // Button2
button2_pressed = 1;
if ( (event.button.state & GDK_SHIFT_MASK) &&
!(event.button.state & GDK_CONTROL_MASK)) {
ctx->event_handler( glow_eEvent_MB2PressShift, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
else if ( !(event.button.state & GDK_SHIFT_MASK) &&
(event.button.state & GDK_CONTROL_MASK)) {
ctx->event_handler( glow_eEvent_MB2PressShift, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
else if ( (event.button.state & GDK_SHIFT_MASK) &&
(event.button.state & GDK_CONTROL_MASK)) {
ctx->event_handler( glow_eEvent_MB2PressShiftCtrl, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
else {
ctx->event_handler( glow_eEvent_MB2Press, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
break;
case 3: // Button3
button3_pressed = 1;
#if 0
if ( (event.button.state & GDK_SHIFT_MASK) &&
!(event.button.state & GDK_CONTROL_MASK))
ctx->event_handler( glow_eEvent_MB3PressShift, (int)event.button.x, (int)event.button.y, 0, 0);
else if ( !(event.button.state & GDK_SHIFT_MASK) &&
(event.button.state & GDK_CONTROL_MASK))
ctx->event_handler( glow_eEvent_MB3PressShift, (int)event.button.x, (int)event.button.y, 0, 0);
else if ( (event.button.state & GDK_SHIFT_MASK) &&
(event.button.state & GDK_CONTROL_MASK))
ctx->event_handler( glow_eEvent_MB3PressShiftCtrl, (int)event.button.x, (int)event.button.y, 0, 0);
else
#endif
ctx->event_handler( glow_eEvent_MB3Press, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
break;
}
}
break;
case GDK_BUTTON_RELEASE:
button1_pressed = 0;
button2_pressed = 0;
button3_pressed = 0;
// cout << "Button release event" << endl;
switch ( event.button.button) {
case Button1:
ctx->event_handler( glow_eEvent_MB1Up, (int)event.button.x, (int)event.button.y, 0, 0);
break;
}
if ( ! button_pressed ) {
if ( button_clicked) {
/* Button click, callback from timer */
// cout << "Button click detected state " << event.button.state << endl;
button_clicked = 0;
switch ( event.button.button) {
case 1: // Button1
if ( (event.button.state & GDK_SHIFT_MASK) &&
!(event.button.state & GDK_CONTROL_MASK)) {
ctx->event_handler( glow_eEvent_MB1ClickShift, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
else if ( !(event.button.state & GDK_SHIFT_MASK) &&
(event.button.state & GDK_CONTROL_MASK)) {
ctx->event_handler( glow_eEvent_MB1ClickCtrl, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
else if ( (event.button.state & GDK_SHIFT_MASK) &&
(event.button.state & GDK_CONTROL_MASK)) {
ctx->event_handler( glow_eEvent_MB1ClickShiftCtrl, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
else {
ctx->event_handler( glow_eEvent_MB1Click, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
break;
case 2: // Button2
if ( (event.button.state & GDK_SHIFT_MASK) &&
!(event.button.state & GDK_CONTROL_MASK)) {
ctx->event_handler( glow_eEvent_MB2ClickShift, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
else if ( !(event.button.state & GDK_SHIFT_MASK) &&
(event.button.state & GDK_CONTROL_MASK)) {
ctx->event_handler( glow_eEvent_MB2ClickCtrl, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
else if ( (event.button.state & GDK_SHIFT_MASK) &&
(event.button.state & GDK_CONTROL_MASK)) {
ctx->event_handler( glow_eEvent_MB2ClickShiftCtrl, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
else {
ctx->event_handler( glow_eEvent_MB2Click, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
break;
case 3: // Button3
#if 0
if ( (event.button.state & GDK_SHIFT_MASK) &&
!(event.button.state & GDK_CONTROL_MASK))
ctx->event_handler( glow_eEvent_MB3ClickShift, (int)event.button.x, (int)event.button.y, 0, 0);
else if ( !(event.button.state & GDK_SHIFT_MASK) &&
(event.button.state & GDK_CONTROL_MASK))
ctx->event_handler( glow_eEvent_MB3ClickCtrl, (int)event.button.x, (int)event.button.y, 0, 0);
else if ( (event.button.state & GDK_SHIFT_MASK) &&
(event.button.state & GDK_CONTROL_MASK))
ctx->event_handler( glow_eEvent_MB3ClickShiftCtrl, (int)event.button.x, (int)event.button.y, 0, 0);
else
#endif
ctx->event_handler( glow_eEvent_MB3Click, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
break;
}
}
else {
/* Button release */
// cout << "Button release detected" << endl;
ctx->event_handler( glow_eEvent_ButtonRelease, (int)event.button.x, (int)event.button.y, 0, 0);
}
}
else {
/* Button click */
cancel_event_timer( ctx);
if ( ! button_clicked_and_pressed) {
// cout << "Button first click detected" << endl;
/* wait for button double click */
memcpy( &last_event, &event, sizeof(event));
button_clicked = 1;
event_timer( ctx, 200);
button_pressed = 0;
return 1;
}
else {
/* Button double click */
// cout << "Button double click detected" << endl;
cancel_event_timer( ctx);
button_clicked = 0;
button_pressed = 0;
button_clicked_and_pressed = 0;
switch ( event.button.button) {
case 1: // Button1
if ( (event.button.state & GDK_SHIFT_MASK) &&
!(event.button.state & GDK_CONTROL_MASK)) {
ctx->event_handler( glow_eEvent_MB1DoubleClickShift, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
else if ( !(event.button.state & GDK_SHIFT_MASK) &&
(event.button.state & GDK_CONTROL_MASK)) {
ctx->event_handler( glow_eEvent_MB1DoubleClickCtrl, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
else if ( (event.button.state & GDK_SHIFT_MASK) &&
(event.button.state & GDK_CONTROL_MASK)) {
ctx->event_handler( glow_eEvent_MB1DoubleClickShiftCtrl, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
else {
ctx->event_handler( glow_eEvent_MB1DoubleClick, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
break;
case 2: // Button2
if ( (event.button.state & GDK_SHIFT_MASK) &&
!(event.button.state & GDK_CONTROL_MASK)) {
ctx->event_handler( glow_eEvent_MB2DoubleClickShift, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
else if ( !(event.button.state & GDK_SHIFT_MASK) &&
(event.button.state & GDK_CONTROL_MASK)) {
ctx->event_handler( glow_eEvent_MB2DoubleClickCtrl, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
else if ( (event.button.state & GDK_SHIFT_MASK) &&
(event.button.state & GDK_CONTROL_MASK)) {
ctx->event_handler( glow_eEvent_MB2DoubleClickShiftCtrl, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
else {
ctx->event_handler( glow_eEvent_MB2DoubleClick, (int)event.button.x, (int)event.button.y, 0, 0);
click_sensitivity = 0;
}
break;
case 3: // Button3
#if 0
if ( (event.button.state & GDK_SHIFT_MASK) &&
!(event.button.state & GDK_CONTROL_MASK))
ctx->event_handler( glow_eEvent_MB3DoubleClickShift, (int)event.button.x, (int)event.button.y, 0, 0);
else if ( !(event.button.state & GDK_SHIFT_MASK) &&
(event.button.state & GDK_CONTROL_MASK))
ctx->event_handler( glow_eEvent_MB3DoubleClickCtrl, (int)event.button.x, (int)event.button.y, 0, 0);
else if ( (event.button.state & GDK_SHIFT_MASK) &&
(event.button.state & GDK_CONTROL_MASK))
ctx->event_handler( glow_eEvent_MB3DoubleClickShiftCtrl, (int)event.button.x, (int)event.button.y, 0, 0);
else
ctx->event_handler( glow_eEvent_MB3DoubleClick, (int)event.button.x, (int)event.button.y, 0, 0);
#endif
break;
}
}
}
break;
case GDK_EXPOSE:
// printf( "-- Expose event.. x: %d, y: %d, w: %d, h: %d\n",
// event.expose.x,
// event.expose.y, event.expose.width, event.expose.height);
ctx->event_handler( glow_eEvent_Exposure, event.expose.area.x,
event.expose.area.y, event.expose.area.width,
event.expose.area.height);
break;
case GDK_VISIBILITY_NOTIFY :
switch ( event.visibility.state) {
case GDK_VISIBILITY_UNOBSCURED:
ctx->event_handler( glow_eEvent_VisibilityUnobscured, 0, 0, 0, 0);
break;
default:
ctx->event_handler( glow_eEvent_VisibilityObscured, 0, 0, 0, 0);
break;
}
break;
case GDK_MOTION_NOTIFY:
// printf( "-- Button1 motion event: (%d,%d)\n", event.button.x,
// event.button.y);
if ( button3_pressed) {
button3_pressed = 0;
button_pressed = 0;
button_clicked_and_pressed = 0;
}
if ( button_pressed &&
(abs( event.button.x - last_press_x) > DRAW_PRESS_PIX ||
abs( event.button.y - last_press_y) > DRAW_PRESS_PIX)) {
// printf( "Press: x %d last_x %d\n", event.button.x, last_press_x);
// printf( " y %d last_y %d\n", event.button.y, last_press_y);
event.button.x = last_press_x;
event.button.y = last_press_y;
/* Button press */
cancel_event_timer( ctx);
switch ( button_pressed) {
case 1: // Button1
button1_pressed = 1;
if ( (event.button.state & GDK_SHIFT_MASK) &&
!(event.button.state & GDK_CONTROL_MASK))
ctx->event_handler( glow_eEvent_MB1PressShift, (int)event.button.x, (int)event.button.y, 0, 0);
else if ( !(event.button.state & GDK_SHIFT_MASK) &&
(event.button.state & GDK_CONTROL_MASK))
ctx->event_handler( glow_eEvent_MB1PressCtrl, (int)event.button.x, (int)event.button.y, 0, 0);
else if ( (event.button.state & GDK_SHIFT_MASK) &&
(event.button.state & GDK_CONTROL_MASK))
ctx->event_handler( glow_eEvent_MB1PressShiftCtrl, (int)event.button.x, (int)event.button.y, 0, 0);
else
ctx->event_handler( glow_eEvent_MB1Press, (int)event.button.x, (int)event.button.y, 0, 0);
break;
case 2: // Button2
button2_pressed = 1;
if ( (event.button.state & GDK_SHIFT_MASK) &&
!(event.button.state & GDK_CONTROL_MASK))
ctx->event_handler( glow_eEvent_MB2PressShift, (int)event.button.x, (int)event.button.y, 0, 0);
else if ( !(event.button.state & GDK_SHIFT_MASK) &&
(event.button.state & GDK_CONTROL_MASK))
ctx->event_handler( glow_eEvent_MB2PressShift, (int)event.button.x, (int)event.button.y, 0, 0);
else if ( (event.button.state & GDK_SHIFT_MASK) &&
(event.button.state & GDK_CONTROL_MASK))
ctx->event_handler( glow_eEvent_MB2PressShiftCtrl, (int)event.button.x, (int)event.button.y, 0, 0);
else
ctx->event_handler( glow_eEvent_MB2Press, (int)event.button.x, (int)event.button.y, 0, 0);
break;
case 3: // Button3
button3_pressed = 1;
ctx->event_handler( glow_eEvent_MB3Press, (int)event.button.x, (int)event.button.y, 0, 0);
break;
}
button_pressed = 0;
button_clicked_and_pressed = 0;
}
if ( button1_pressed || button2_pressed || button3_pressed)
ctx->event_handler( glow_eEvent_ButtonMotion, (int)event.button.x, (int)event.button.y, 0, 0);
else
ctx->event_handler( glow_eEvent_CursorMotion, (int)event.button.x, (int)event.button.y, 0, 0);
break;
case GDK_ENTER_NOTIFY:
// printf( "-- Enter event: (%d,%d)\n", event.crossing.x,
// event.crossing.y);
ctx->event_handler( glow_eEvent_Enter, (int)event.crossing.x, (int)event.crossing.y, 0, 0);
break;
case GDK_LEAVE_NOTIFY:
// printf( "-- Leave event: (%d,%d)\n", event.crossing.x,
// event.button.y);
ctx->event_handler( glow_eEvent_Leave, (int)event.crossing.x, (int)event.crossing.y, 0, 0);
break;
case GDK_MAP:
// printf( "-- Enter event: (%d,%d)\n", event.button.x,
// event.button.y);
ctx->event_handler( glow_eEvent_Map, 0, 0, 0, 0);
break;
case GDK_UNMAP:
// printf( "-- Enter event: (%d,%d)\n", event.button.x,
// event.button.y);
ctx->event_handler( glow_eEvent_Unmap, 0, 0, 0, 0);
break;
case GDK_FOCUS_CHANGE:
// printf( "-- Focus in event\n");
break;
default:
// printf("-- Other event: %d \n", event.type);
break;
}
}
else if ( event.any.window == nav_wind.window) {
switch ( event.type) {
case GDK_BUTTON_PRESS :
// printf( "-- Button event nav: (%d,%d) button: %d\n", event.button.x,
// event.button.y, event.button.button);
switch ( event.button.button) {
case 1: // Button1
button1_pressed = 1;
ctx->event_handler_nav( glow_eEvent_MB1Press, (int)event.button.x, (int)event.button.y);
break;
case 2: // Button2
button2_pressed = 1;
ctx->event_handler_nav( glow_eEvent_MB2Press, (int)event.button.x, (int)event.button.y);
break;
case 3: // Button3
button3_pressed = 1;
break;
}
break;
case GDK_BUTTON_RELEASE :
// printf( "-- Button release event nav: (%d,%d)\n", event.button.x,
// event.button.y);
switch ( event.button.button) {
case 1: // Button1
button1_pressed = 0;
break;
case 2: // Button2
button2_pressed = 0;
break;
case 3: // Button3
button3_pressed = 0;
break;
}
ctx->event_handler_nav( glow_eEvent_ButtonRelease, (int)event.button.x, (int)event.button.y);
break;
case GDK_EXPOSE:
// printf( "-- Navigator expose event..\n" );
ctx->event_handler_nav( glow_eEvent_Exposure, 0, 0);
break;
case GDK_MOTION_NOTIFY:
// printf( "-- Button1 motion event nav: (%d,%d)\n", event.button.x,
// event.button.y);
if ( button1_pressed || button2_pressed || button3_pressed)
ctx->event_handler_nav( glow_eEvent_ButtonMotion, (int)event.button.x, (int)event.button.y);
else
ctx->event_handler_nav( glow_eEvent_CursorMotion, (int)event.button.x, (int)event.button.y);
break;
default: ;
}
}
gdk_display_flush( display);
return 1;
}
void GlowDrawGtk::enable_event( glow_eEvent event,
glow_eEventType event_type,
int (*event_cb)(GlowCtx *ctx, glow_tEvent event))
{
ctx->enable_event( event, event_type, event_cb);
}
int GlowDrawGtk::rect( GlowWind *wind, int x, int y, int width, int height,
glow_eDrawType gc_type, int idx, int highlight)
{
if ( ctx->nodraw) return 1;
DrawWindGtk *w = (DrawWindGtk *) wind->window;
if ( gc_type == glow_eDrawType_LineGray && highlight)
gc_type = glow_eDrawType_Line;
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type+highlight, idx));
if ( !w->draw_buffer_only)
gdk_draw_rectangle( w->window,
get_gc( this, gc_type+highlight, idx), 0,
x, y, width, height);
if ( w->double_buffer_on)
gdk_draw_rectangle( w->buffer,
get_gc( this, gc_type+highlight, idx), 0,
x, y, width, height);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type+highlight, idx));
return 1;
}
int GlowDrawGtk::rect_erase( GlowWind *wind, int x, int y, int width, int height,
int idx)
{
if ( ctx->nodraw) return 1;
DrawWindGtk *w = (DrawWindGtk *) wind->window;
if ( w->clip_on)
set_clip( w, get_gc( this, glow_eDrawType_LineErase, idx));
if ( !w->draw_buffer_only)
gdk_draw_rectangle( w->window,
get_gc( this, glow_eDrawType_LineErase, idx), 0,
x, y, width, height);
if ( w->double_buffer_on)
gdk_draw_rectangle( w->buffer,
get_gc( this, glow_eDrawType_LineErase, idx), 0,
x, y, width, height);
if ( w->clip_on)
reset_clip( w, get_gc( this, glow_eDrawType_LineErase, idx));
return 1;
}
int GlowDrawGtk::arrow( GlowWind *wind, int x1, int y1, int x2, int y2,
int x3, int y3,
glow_eDrawType gc_type, int idx, int highlight)
{
if ( ctx->nodraw) return 1;
GdkPoint p[4] = {{x1,y1},{x2,y2},{x3,y3},{x1,y1}};
DrawWindGtk *w = (DrawWindGtk *) wind->window;
if ( gc_type == glow_eDrawType_LineGray && highlight)
gc_type = glow_eDrawType_Line;
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type+highlight, idx));
if ( !w->draw_buffer_only)
gdk_draw_polygon( w->window,
get_gc( this, gc_type+highlight, idx), 1, p, 4);
if ( w->double_buffer_on)
gdk_draw_polygon( w->buffer,
get_gc( this, gc_type+highlight, idx), 1, p, 4);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type+highlight, idx));
return 1;
}
int GlowDrawGtk::arrow_erase( GlowWind *wind, int x1, int y1, int x2, int y2,
int x3, int y3,
int idx)
{
if ( ctx->nodraw) return 1;
GdkPoint p[4] = {{x1,y1},{x2,y2},{x3,y3},{x1,y1}};
DrawWindGtk *w = (DrawWindGtk *) wind->window;
if ( w->clip_on)
set_clip( w, get_gc( this, glow_eDrawType_LineErase, idx));
if ( !w->draw_buffer_only)
gdk_draw_polygon( w->window,
get_gc( this, glow_eDrawType_LineErase, idx), 1,
p, 4);
if ( w->double_buffer_on)
gdk_draw_polygon( w->buffer,
get_gc( this, glow_eDrawType_LineErase, idx), 1,
p, 4);
if ( w->clip_on)
reset_clip( w, get_gc( this, glow_eDrawType_LineErase, idx));
return 1;
}
int GlowDrawGtk::arc( GlowWind *wind, int x, int y, int width, int height,
int angel1, int angel2,
glow_eDrawType gc_type, int idx, int highlight)
{
if ( ctx->nodraw) return 1;
DrawWindGtk *w = (DrawWindGtk *) wind->window;
if ( gc_type == glow_eDrawType_LineGray && highlight)
gc_type = glow_eDrawType_Line;
// Fix for highlight for connections in grow
if ( highlight && ctx->type() == glow_eCtxType_Grow)
gc_type = glow_eDrawType_LineHighlight;
// if ( width < 35 && height < 35) {width++; height++;} // This looks good in Reflexion X ...
if ( angel1 >= 360)
angel1 = angel1 - angel1 / 360 * 360;
else if ( angel1 < 0)
angel1 = angel1 + ( -angel1 / 360 + 1) * 360;
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type+highlight, idx));
if ( !w->draw_buffer_only)
gdk_draw_arc( w->window,
get_gc( this, gc_type+highlight, idx), 0,
x, y, width, height, angel1*64, angel2*64);
if ( w->double_buffer_on)
gdk_draw_arc( w->buffer,
get_gc( this, gc_type+highlight, idx), 0,
x, y, width, height, angel1*64, angel2*64);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type+highlight, idx));
return 1;
}
int GlowDrawGtk::fill_arc( GlowWind *wind, int x, int y, int width, int height,
int angel1, int angel2, glow_eDrawType gc_type, int highlight)
{
if ( ctx->nodraw) return 1;
DrawWindGtk *w = (DrawWindGtk *) wind->window;
if ( gc_type == glow_eDrawType_LineGray && highlight)
gc_type = glow_eDrawType_LineRed;
if ( angel1 >= 360)
angel1 = angel1 - angel1 / 360 * 360;
else if ( angel1 < 0)
angel1 = angel1 + ( -angel1 / 360 + 1) * 360;
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type+highlight, 0));
if ( !w->draw_buffer_only)
gdk_draw_arc( w->window,
get_gc( this, gc_type+highlight, 0), 1,
x, y, width, height, angel1*64, angel2*64);
if ( w->double_buffer_on)
gdk_draw_arc( w->buffer,
get_gc( this, gc_type+highlight, 0), 1,
x, y, width, height, angel1*64, angel2*64);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type+highlight, 0));
return 1;
}
int GlowDrawGtk::arc_erase( GlowWind *wind, int x, int y, int width, int height,
int angel1, int angel2,
int idx)
{
if ( ctx->nodraw) return 1;
DrawWindGtk *w = (DrawWindGtk *) wind->window;
// if ( width < 35 && height < 35) {width++; height++;} // This looks good in Reflexion X ...
if ( angel1 >= 360)
angel1 = angel1 - angel1 / 360 * 360;
else if ( angel1 < 0)
angel1 = angel1 + ( -angel1 / 360 + 1) * 360;
if ( w->clip_on)
set_clip( w, get_gc( this, glow_eDrawType_LineErase, idx));
if ( !w->draw_buffer_only)
gdk_draw_arc( w->window,
get_gc( this, glow_eDrawType_LineErase, idx), 0,
x, y, width, height, angel1*64, angel2*64);
if ( w->double_buffer_on)
gdk_draw_arc( w->buffer,
get_gc( this, glow_eDrawType_LineErase, idx), 0,
x, y, width, height, angel1*64, angel2*64);
if ( w->clip_on)
reset_clip( w, get_gc( this, glow_eDrawType_LineErase, idx));
return 1;
}
int GlowDrawGtk::line( GlowWind *wind, int x1, int y1, int x2, int y2,
glow_eDrawType gc_type, int idx, int highlight)
{
if ( ctx->nodraw) return 1;
DrawWindGtk *w = (DrawWindGtk *) wind->window;
// Fix for highlight for connections in grow
if ( highlight && ctx->type() == glow_eCtxType_Grow)
gc_type = glow_eDrawType_LineHighlight;
if ( gc_type == glow_eDrawType_LineGray && highlight)
gc_type = glow_eDrawType_Line;
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type+highlight, idx));
if ( !w->draw_buffer_only)
gdk_draw_line( w->window,
get_gc( this, gc_type+highlight, idx),
x1, y1, x2, y2);
if ( w->double_buffer_on)
gdk_draw_line( w->buffer,
get_gc( this, gc_type+highlight, idx),
x1, y1, x2, y2);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type+highlight, idx));
return 1;
}
int GlowDrawGtk::line_dashed( GlowWind *wind, int x1, int y1, int x2, int y2,
glow_eDrawType gc_type, int idx, int highlight, glow_eLineType line_type)
{
if ( ctx->nodraw) return 1;
DrawWindGtk *w = (DrawWindGtk *) wind->window;
// Fix for highlight for connections in grow
if ( highlight && ctx->type() == glow_eCtxType_Grow)
gc_type = glow_eDrawType_LineHighlight;
if ( gc_type == glow_eDrawType_LineGray && highlight)
gc_type = glow_eDrawType_Line;
gdk_gc_set_line_attributes( get_gc( this, gc_type+highlight, idx), idx+1,
GDK_LINE_ON_OFF_DASH, GDK_CAP_BUTT, GDK_JOIN_MITER);
gint dash_offset = 0;
gint8 dashes[4];
switch ( line_type) {
case glow_eLineType_Dashed1:
dashes[0] = 1 + idx;
gdk_gc_set_dashes( get_gc( this, gc_type+highlight, idx), dash_offset, dashes, 1);
break;
case glow_eLineType_Dashed2:
dashes[0] = 1 + 2 * idx;
gdk_gc_set_dashes( get_gc( this, gc_type+highlight, idx), dash_offset, dashes, 1);
break;
case glow_eLineType_Dashed3:
dashes[0] = 1 + 3 * idx;
gdk_gc_set_dashes( get_gc( this, gc_type+highlight, idx), dash_offset, dashes, 1);
break;
case glow_eLineType_Dotted: {
dashes[0] = 1 + idx;
dashes[1] = 1 + 4 * idx;
gdk_gc_set_dashes( get_gc( this, gc_type+highlight, idx), dash_offset, dashes, 2);
break;
}
case glow_eLineType_DotDashed1: {
dashes[0] = 1 + 3 * idx;
dashes[1] = 1 + 2 * idx;
dashes[2] = 1 + idx;
dashes[3] = 1 + 2 * idx;
gdk_gc_set_dashes( get_gc( this, gc_type+highlight, idx), dash_offset, dashes, 4);
break;
}
case glow_eLineType_DotDashed2: {
dashes[0] = 1 + 6 * idx;
dashes[1] = 1 + 3 * idx;
dashes[2] = 1 + idx;
dashes[3] = 1 + 3 * idx;
gdk_gc_set_dashes( get_gc( this, gc_type+highlight, idx), dash_offset, dashes, 4);
break;
}
default: ;
}
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type+highlight, idx));
if ( !w->draw_buffer_only)
gdk_draw_line( w->window,
get_gc( this, gc_type+highlight, idx),
x1, y1, x2, y2);
if ( w->double_buffer_on)
gdk_draw_line( w->buffer,
get_gc( this, gc_type+highlight, idx),
x1, y1, x2, y2);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type+highlight, idx));
gdk_gc_set_line_attributes( get_gc( this, gc_type+highlight, idx), idx+1,
GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
return 1;
}
int GlowDrawGtk::line_erase( GlowWind *wind, int x1, int y1, int x2, int y2,
int idx)
{
if ( ctx->nodraw) return 1;
DrawWindGtk *w = (DrawWindGtk *) wind->window;
if ( w->clip_on)
set_clip( w, get_gc( this, glow_eDrawType_LineErase, idx));
if ( !w->draw_buffer_only)
gdk_draw_line( w->window,
get_gc( this, glow_eDrawType_LineErase, idx),
x1, y1, x2, y2);
if ( w->double_buffer_on)
gdk_draw_line( w->buffer,
get_gc( this, glow_eDrawType_LineErase, idx),
x1, y1, x2, y2);
if ( w->clip_on)
reset_clip( w, get_gc( this, glow_eDrawType_LineErase, idx));
return 1;
}
int GlowDrawGtk::polyline( GlowWind *wind, glow_sPointX *points, int point_cnt,
glow_eDrawType gc_type, int idx, int highlight)
{
if ( ctx->nodraw) return 1;
DrawWindGtk *w = (DrawWindGtk *) wind->window;
if ( gc_type == glow_eDrawType_LineGray && highlight)
gc_type = glow_eDrawType_Line;
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type+highlight, idx));
GdkPoint* gpoints = points_to_gdk_points( points, point_cnt);
if ( !w->draw_buffer_only)
gdk_draw_lines( w->window,
get_gc( this, gc_type+highlight, idx),
gpoints, point_cnt);
if ( w->double_buffer_on)
gdk_draw_lines( w->buffer,
get_gc( this, gc_type+highlight, idx),
gpoints, point_cnt);
free( gpoints);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type+highlight, idx));
return 1;
}
int GlowDrawGtk::fill_polyline( GlowWind *wind, glow_sPointX *points, int point_cnt,
glow_eDrawType gc_type, int highlight)
{
if ( ctx->nodraw) return 1;
DrawWindGtk *w = (DrawWindGtk *) wind->window;
if ( gc_type == glow_eDrawType_LineGray && highlight)
gc_type = glow_eDrawType_Line;
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type+highlight, 0));
GdkPoint* gpoints = points_to_gdk_points( points, point_cnt);
if ( !w->draw_buffer_only)
gdk_draw_polygon( w->window,
get_gc( this, gc_type+highlight, 0),
1, gpoints, point_cnt);
if ( w->double_buffer_on)
gdk_draw_polygon( w->buffer,
get_gc( this, gc_type+highlight, 0), 1, gpoints, point_cnt);
free( gpoints);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type+highlight, 0));
return 1;
}
int GlowDrawGtk::polyline_erase( GlowWind *wind, glow_sPointX *points, int point_cnt,
int idx)
{
if ( ctx->nodraw) return 1;
DrawWindGtk *w = (DrawWindGtk *) wind->window;
if ( w->clip_on)
set_clip( w, get_gc( this, glow_eDrawType_LineErase, idx));
GdkPoint* gpoints = points_to_gdk_points( points, point_cnt);
if ( !w->draw_buffer_only)
gdk_draw_lines( w->window,
get_gc( this, glow_eDrawType_LineErase, idx),
gpoints, point_cnt);
if ( w->double_buffer_on)
gdk_draw_lines( w->buffer,
get_gc( this, glow_eDrawType_LineErase, idx),
gpoints, point_cnt);
free( gpoints);
if ( w->clip_on)
reset_clip( w, get_gc( this, glow_eDrawType_LineErase, idx));
return 1;
}
int GlowDrawGtk::text( GlowWind *wind, int x, int y, char *text, int len,
glow_eDrawType gc_type, glow_eDrawType color, int idx, int highlight, int line)
{
if ( ctx->nodraw) return 1;
DrawWindGtk *w = (DrawWindGtk *) wind->window;
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type, idx));
int font_idx = get_font_idx( gc_type);
if ( color != glow_eDrawType_Line) {
GdkGCValues xgcv;
gdk_gc_get_values( get_gc( this, color, 0), &xgcv);
gdk_gc_set_values( get_gc( this, gc_type, idx), &xgcv,
GDK_GC_FOREGROUND);
}
if ( !w->draw_buffer_only)
gdk_draw_text( w->window,
font[font_idx][idx],
get_gc( this, gc_type, idx),
x, y, text, len);
if ( w->double_buffer_on)
gdk_draw_text( w->buffer,
font[font_idx][idx],
get_gc( this, gc_type, idx),
x, y, text, len);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type, idx));
if ( color != glow_eDrawType_Line) {
GdkGCValues xgcv;
gdk_gc_get_values( get_gc( this, glow_eDrawType_Line, 0),
&xgcv);
gdk_gc_set_values( get_gc( this, gc_type, idx), &xgcv,
GDK_GC_FOREGROUND);
}
return 1;
}
int GlowDrawGtk::text_cursor( GlowWind *wind, int x, int y, char *text, int len,
glow_eDrawType gc_type, glow_eDrawType color, int idx, int highlight, int pos)
{
if ( ctx->nodraw) return 1;
DrawWindGtk *w = (DrawWindGtk *) wind->window;
int width, height, descent;
get_text_extent( text, pos, gc_type, idx,
&width, &height, &descent);
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type, idx));
if ( !w->draw_buffer_only) {
gdk_draw_line( w->window,
get_gc( this, color, 1),
x + width, y + descent, x + width, y - height + descent);
}
if ( w->double_buffer_on) {
gdk_draw_line( w->buffer,
get_gc( this, color, 1),
x + width, y + descent, x + width, y - height + descent);
}
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type, idx));
return 1;
}
int GlowDrawGtk::text_erase( GlowWind *wind, int x, int y, char *text, int len,
glow_eDrawType gc_type, int idx, int line)
{
if ( ctx->nodraw) return 1;
DrawWindGtk *w = (DrawWindGtk *) wind->window;
if ( gc_type == glow_eDrawType_TextHelvetica)
gc_type = glow_eDrawType_TextHelveticaErase;
else if ( gc_type == glow_eDrawType_TextHelveticaBold)
gc_type = glow_eDrawType_TextHelveticaEraseBold;
int font_idx = get_font_idx( gc_type);
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type, idx));
if ( !w->draw_buffer_only)
gdk_draw_text( w->window,
font[font_idx][idx],
get_gc( this, gc_type, idx),
x, y, text, len);
if ( w->double_buffer_on)
gdk_draw_text( w->buffer,
font[font_idx][idx],
get_gc( this, gc_type, idx),
x, y, text, len);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type, idx));
return 1;
}
int GlowDrawGtk::pixmaps_create( GlowWind *wind, glow_sPixmapData *pixmap_data,
void **pixmaps)
{
return 1;
}
void GlowDrawGtk::pixmaps_delete( GlowWind *wind, void *pixmaps)
{
}
int GlowDrawGtk::pixmap( GlowWind *wind, int x, int y, glow_sPixmapData *pixmap_data,
void *pixmaps, glow_eDrawType gc_type, int idx, int highlight, int line)
{
return 1;
}
int GlowDrawGtk::pixmap_inverse( GlowWind *wind, int x, int y, glow_sPixmapData *pixmap_data,
void *pixmaps, glow_eDrawType gc_type, int idx, int line)
{
return 1;
}
int GlowDrawGtk::pixmap_erase( GlowWind *wind, int x, int y, glow_sPixmapData *pixmap_data,
void *pixmaps, glow_eDrawType gc_type, int idx, int line)
{
return 1;
}
int GlowDrawGtk::image( GlowWind *wind, int x, int y, int width, int height,
glow_tImImage image, glow_tPixmap pixmap, glow_tPixmap clip_mask)
{
DrawWindGtk *w = (DrawWindGtk *) wind->window;
if ( ctx->nodraw) return 1;
if ( width == 0 || height == 0)
return 1;
if ( clip_mask)
set_image_clip_mask( clip_mask, x, y);
else if ( w->clip_on)
set_clip( w, get_gc( this, glow_eDrawType_Line, 0));
if ( !w->draw_buffer_only)
gdk_draw_pixbuf( w->window, get_gc( this, glow_eDrawType_Line, 0),
(GdkPixbuf *)image, 0, 0, x, y, width, height,
GDK_RGB_DITHER_NONE, 0, 0);
#if 0
gdk_draw_drawable( w->window,
get_gc( this, glow_eDrawType_Line, 0),
(GdkDrawable *) pixmap,
0, 0, x, y, width, height);
#endif
if ( w->double_buffer_on)
gdk_draw_pixbuf( w->buffer, get_gc( this, glow_eDrawType_Line, 0),
(GdkPixbuf *)image, 0, 0, x, y, width, height,
GDK_RGB_DITHER_NONE, 0, 0);
#if 0
gdk_draw_drawable( w->buffer,
get_gc( this, glow_eDrawType_Line, 0),
(GdkDrawable *) pixmap,
0, 0, x, y, width, height);
#endif
if ( clip_mask)
reset_image_clip_mask();
else if ( w->clip_on)
reset_clip( w, get_gc( this, glow_eDrawType_Line, 0));
return 1;
}
int GlowDrawGtk::fill_rect( GlowWind *wind, int x, int y, int w, int h,
glow_eDrawType gc_type)
{
DrawWindGtk *ww = (DrawWindGtk *) wind->window;
if ( ctx->nodraw) return 1;
if ( ww->clip_on)
set_clip( ww, get_gc( this, gc_type, 0));
if ( !ww->draw_buffer_only)
gdk_draw_rectangle( ww->window,
get_gc( this, gc_type, 0), 1, x, y, w, h);
if ( ww->double_buffer_on)
gdk_draw_rectangle( ww->buffer,
get_gc( this, gc_type, 0), 1, x, y, w, h);
if ( ww->clip_on)
reset_clip( ww, get_gc( this, gc_type, 0));
return 1;
}
void GlowDrawGtk::clear( GlowWind *wind)
{
if ( ctx->nodraw) return;
DrawWindGtk *w = (DrawWindGtk *) wind->window;
if ( !w->double_buffer_on)
gdk_window_clear( w->window);
else
buffer_background( w);
}
void GlowDrawGtk::copy_buffer( GlowWind *wind,
int ll_x, int ll_y, int ur_x, int ur_y)
{
if ( ctx->nodraw) return;
DrawWindGtk *w = (DrawWindGtk *) wind->window;
int x0 = min( ll_x, ur_x);
int x1 = max( ll_x, ur_x);
int y0 = min( ll_y, ur_y);
int y1 = max( ll_y, ur_y);
gdk_draw_drawable( w->window,
get_gc( this, glow_eDrawType_Line, 0),
w->buffer,
x0, y0, x0, y0, x1 - x0, y1 - y0);
}
void GlowDrawGtk::get_window_size( GlowWind *wind, int *width, int *height)
{
DrawWindGtk *w = (DrawWindGtk *) wind->window;
gdk_drawable_get_size( w->window, width, height);
}
void GlowDrawGtk::set_window_size( GlowWind *wind, int width, int height)
{
DrawWindGtk *w = (DrawWindGtk *) wind->window;
if ( !w->window) return;
gdk_window_resize( w->window, width, height);
}
static gboolean draw_timer_cb( void *data)
{
draw_sTimerCb *timer_cb = (draw_sTimerCb *)data;
GlowDrawGtk *draw_ctx = (GlowDrawGtk *) timer_cb->ctx->gdraw;
(timer_cb->callback_func)(timer_cb->ctx);
gdk_display_flush( draw_ctx->display);
free( timer_cb);
return FALSE;
}
static gboolean event_timer_cb( void *ctx)
{
// printf( "Timer callback\n");
GlowDrawGtk *draw_ctx = (GlowDrawGtk *) ((GlowCtx *)ctx)->gdraw;
draw_ctx->timer_id = 0;
draw_ctx->event_handler( last_event);
return FALSE;
}
static void cancel_event_timer( GlowCtx *ctx)
{
GlowDrawGtk *draw_ctx = (GlowDrawGtk *) ctx->gdraw;
if ( draw_ctx->timer_id) {
g_source_remove( draw_ctx->timer_id);
draw_ctx->timer_id = 0;
}
// printf( "Timer removed\n");
}
static void event_timer( GlowCtx *ctx, int time_ms)
{
GlowDrawGtk *draw_ctx = (GlowDrawGtk *) ctx->gdraw;
// printf( "Add timer\n");
draw_ctx->timer_id = g_timeout_add( time_ms, event_timer_cb, ctx);
}
void GlowDrawGtk::set_timer( GlowCtx *gctx, int time_ms,
void (*callback_func)( GlowCtx *ctx), void **id)
{
draw_sTimerCb *timer_cb;
timer_cb = (draw_sTimerCb *) calloc( 1, sizeof(draw_sTimerCb));
timer_cb->ctx = gctx;
timer_cb->callback_func = callback_func;
timer_cb->timer_id = g_timeout_add( time_ms,
draw_timer_cb, timer_cb);
*id = (void *)timer_cb;
}
void GlowDrawGtk::remove_timer( void *id)
{
g_source_remove( ((draw_sTimerCb *)id)->timer_id);
free( (char *) id);
}
void GlowDrawGtk::set_cursor( GlowWind *wind, glow_eDrawCursor cursor)
{
DrawWindGtk *w = (DrawWindGtk *) wind->window;
if ( !w->window) return;
if ( cursor == glow_eDrawCursor_Normal)
gdk_window_set_cursor( w->window, NULL);
else
gdk_window_set_cursor( w->window, cursors[cursor]);
gdk_display_flush( display);
}
int GlowDrawGtk::get_text_extent( char *text, int len,
glow_eDrawType gc_type, int idx,
int *width, int *height, int *descent)
{
int text_width, text_ascent, text_descent, text_lbearing, text_rbearing;
int font_idx = get_font_idx( gc_type);
gdk_text_extents( font[font_idx][idx], text, len,
&text_lbearing, &text_rbearing, &text_width, &text_ascent,
&text_descent);
*height = text_ascent + text_descent;
*descent = text_descent;
*width = text_width;
return 1;
}
void GlowDrawGtk::copy_area( GlowWind *wind, int x, int y)
{
DrawWindGtk *w = (DrawWindGtk *) wind->window;
GdkGC *gc;
if ( ctx->nodraw) return;
int window_width, window_height;
if ( &ctx->mw == wind) {
window_width = ctx->mw.window_width;
window_height = ctx->mw.window_height;
}
else {
window_width = ctx->navw.window_width;
window_height = ctx->navw.window_height;
}
gc = get_gc( this, glow_eDrawType_Line, 3);
if ( x >= 0 && y >= 0) {
gdk_draw_drawable( w->window, gc, w->window,
0, 0, x, y, window_width-x, window_height-y);
if ( !w->double_buffer_on) {
if ( x)
gdk_window_clear_area( w->window, 0, 0,
x, window_height);
if ( y)
gdk_window_clear_area( w->window, x, 0,
window_width, y);
}
else {
gdk_draw_drawable( w->buffer, gc, w->buffer,
0, 0, x, y, window_width-x, window_height-y);
if ( x)
gdk_draw_rectangle( w->buffer,
get_gc( this, glow_eDrawType_LineErase, 0), 1,
0, 0, x, window_height);
if ( y)
gdk_draw_rectangle( w->buffer,
get_gc( this, glow_eDrawType_LineErase, 0), 1,
x, 0, window_width, y);
}
}
else if ( x <= 0 && y <= 0)
{
gdk_draw_drawable( w->window, gc, w->window,
-x, -y, 0, 0, window_width+x, window_height+y);
if ( !w->double_buffer_on) {
if ( x)
gdk_window_clear_area( w->window,
window_width+x, 0, window_width, window_height);
if ( y)
gdk_window_clear_area( w->window,
0, window_height+y, window_width+x, window_height);
}
else {
gdk_draw_drawable( w->buffer, gc, w->buffer,
-x, -y, 0, 0, window_width+x, window_height+y);
if ( x)
gdk_draw_rectangle( w->buffer,
get_gc( this, glow_eDrawType_LineErase, 0), 1,
window_width+x, 0, window_width, window_height);
if ( y)
gdk_draw_rectangle( w->buffer,
get_gc( this, glow_eDrawType_LineErase, 0), 1,
0, window_height+y, window_width+x, window_height);
}
}
else if ( x <= 0 && y >= 0)
{
gdk_draw_drawable( w->window, gc, w->window,
-x, 0, 0, y, window_width+x, window_height-y);
if ( !w->double_buffer_on) {
if ( x)
gdk_window_clear_area( w->window,
window_width+x, 0, window_width, window_height);
if ( y)
gdk_window_clear_area( w->window,
0, 0, window_width+x, y);
}
else {
gdk_draw_drawable( w->buffer, gc, w->buffer,
-x, 0, 0, y, window_width+x, window_height-y);
if ( x)
gdk_draw_rectangle( w->buffer,
get_gc( this, glow_eDrawType_LineErase, 0), 1,
window_width+x, 0, window_width, window_height);
if ( y)
gdk_draw_rectangle( w->buffer,
get_gc( this, glow_eDrawType_LineErase, 0), 1,
0, 0, window_width+x, y);
}
}
else
{
gdk_draw_drawable( w->window, gc, w->window,
0, -y, x, 0, window_width-x, window_height+y);
if ( !w->double_buffer_on) {
if ( x)
gdk_window_clear_area( w->window,
0, 0, x, window_height);
if ( y)
gdk_window_clear_area( w->window,
x, window_height+y, window_width, window_height);
}
else {
gdk_draw_drawable( w->buffer, gc, w->buffer,
0, -y, x, 0, window_width-x, window_height+y);
if ( x)
gdk_draw_rectangle( w->buffer,
get_gc( this, glow_eDrawType_LineErase, 0), 1,
0, 0, x, window_height);
if ( y)
gdk_draw_rectangle( w->buffer,
get_gc( this, glow_eDrawType_LineErase, 0), 1,
x, window_height+y, window_width, window_height);
}
}
}
void GlowDrawGtk::clear_area( GlowWind *wind, int ll_x, int ur_x, int ll_y, int ur_y)
{
if ( ctx->nodraw) return;
DrawWindGtk *w = (DrawWindGtk *) wind->window;
gdk_window_clear_area( w->window, ll_x, ll_y, ur_x - ll_x,
ur_y - ll_y);
}
void GlowDrawGtk::set_inputfocus( GlowWind *wind)
{
DrawWindGtk *w = (DrawWindGtk *) wind->window;
gdk_window_focus( w->window, GDK_CURRENT_TIME);
// gtk_widget_grab_focus( m_wind.toplevel);
}
static int glow_read_color_file( char *filename, draw_sColor **color_array,
int *size)
{
char line[80];
draw_sColor *color_p;
ifstream fp;
int nr;
int line_cnt;
float f_red, f_green, f_blue;
if ( !check_file( filename))
{
return 0;
#if 0
// No color-file exist, use default values
double r, g, b;
printf( "** Using default color palette\n");
*color_array = (draw_sColor *) calloc( 300, sizeof( draw_sColor));
*size = 0;
color_p = *color_array;
for ( int i = 3; i < 300; i++)
{
GlowColor::rgb_color( i, &r, &g, &b);
color_p->red = int( r * 65535);
color_p->green = int( g * 65535);
color_p->blue = int( b * 65535);
color_p++;
(*size)++;
}
#endif
}
else
{
printf( "** Opening color file %s\n", filename);
fp.open( filename);
#ifndef OS_VMS
if ( !fp)
return GLOW__FILEOPEN;
#endif
*color_array = (draw_sColor *) calloc( 300, sizeof( draw_sColor));
*size = 0;
line_cnt = 0;
color_p = *color_array;
while ( *size < 300)
{
fp.getline( line, sizeof( line));
if ( line[0] == 0)
break;
line_cnt++;
if ( line[0] == '!' || line[0] == '#')
continue;
nr = sscanf( line, "%f %f %f", &f_red, &f_green, &f_blue);
if ( nr != 3)
printf( "** Syntax error in file %s, line %d", filename, line_cnt);
else
{
color_p->red = int( f_red * 65535);
color_p->green = int( f_green * 65535);
color_p->blue = int( f_blue * 65535);
color_p++;
(*size)++;
}
}
fp.close();
}
return 1;
}
void GlowDrawGtk::set_background( GlowWind *wind, glow_eDrawType drawtype,
glow_tPixmap pixmap, int pixmap_width, int pixmap_height)
{
DrawWindGtk *w = (DrawWindGtk *) wind->window;
GdkGCValues xgcv;
int i;
gdk_gc_get_values( get_gc( this, drawtype, 0), &xgcv);
gdk_colormap_query_color( colormap, xgcv.foreground.pixel, &background);
// Change erase gcs
xgcv.foreground = background;
xgcv.background = background;
for ( i = 0; i < DRAW_TYPE_SIZE; i++) {
gdk_gc_set_values( get_gc( this, glow_eDrawType_LineErase, i), &xgcv,
(GdkGCValuesMask)(GDK_GC_FOREGROUND | GDK_GC_BACKGROUND));
gdk_gc_set_values( get_gc( this, glow_eDrawType_TextHelveticaErase, i), &xgcv,
(GdkGCValuesMask)(GDK_GC_FOREGROUND | GDK_GC_BACKGROUND));
gdk_gc_set_values( get_gc( this, glow_eDrawType_TextHelveticaEraseBold, i), &xgcv,
(GdkGCValuesMask)(GDK_GC_FOREGROUND | GDK_GC_BACKGROUND));
}
if ( !pixmap) {
gtk_widget_modify_bg( m_wind.toplevel, GTK_STATE_NORMAL, &background);
if ( w->buffer)
buffer_background( w);
}
else {
// GdkPixmap *gpixmap = gdk_pixmap_foreign_new( pixmap);
if ( w->background_pixmap)
g_object_unref( w->background_pixmap);
w->background_pixmap = (GdkPixmap *)pixmap;
w->background_pixmap_width = pixmap_width;
w->background_pixmap_height = pixmap_height;
gdk_window_set_back_pixmap( w->window, (GdkPixmap *)pixmap, FALSE);
if ( w->buffer)
buffer_background( w);
}
}
void GlowDrawGtk::reset_background( GlowWind *wind)
{
GdkGCValues xgcv;
background = original_background;
gtk_widget_modify_bg( m_wind.toplevel, GTK_STATE_NORMAL, &background);
// Change erase gcs
xgcv.foreground = background;
xgcv.background = background;
for ( int i = 0; i < DRAW_TYPE_SIZE; i++) {
gdk_gc_set_values( get_gc( this, glow_eDrawType_LineErase, i), &xgcv,
(GdkGCValuesMask)(GDK_GC_FOREGROUND | GDK_GC_BACKGROUND));
gdk_gc_set_values( get_gc( this, glow_eDrawType_TextHelveticaErase, i), &xgcv,
(GdkGCValuesMask)(GDK_GC_FOREGROUND | GDK_GC_BACKGROUND));
gdk_gc_set_values( get_gc( this, glow_eDrawType_TextHelveticaEraseBold, i), &xgcv,
(GdkGCValuesMask)(GDK_GC_FOREGROUND | GDK_GC_BACKGROUND));
}
}
void GlowDrawGtk::set_clip( DrawWind *wind, GdkGC *gc)
{
DrawWindGtk *w = (DrawWindGtk *) wind;
gdk_gc_set_clip_rectangle( gc, &w->clip_rectangle[w->clip_cnt-1]);
}
void GlowDrawGtk::reset_clip( DrawWind *w, GdkGC *gc)
{
gdk_gc_set_clip_rectangle( gc, NULL);
}
void GlowDrawGtk::set_image_clip_mask( glow_tPixmap pixmap, int x, int y)
{
// GdkPixmap *gpixmap = gdk_pixmap_foreign_new( pixmap);
gdk_gc_set_clip_mask( get_gc( this, glow_eDrawType_Line, 0),
(GdkPixmap *)pixmap);
gdk_gc_set_clip_origin( get_gc( this, glow_eDrawType_Line, 0), x, y);
}
void GlowDrawGtk::reset_image_clip_mask()
{
gdk_gc_set_clip_mask( get_gc( this, glow_eDrawType_Line, 0),
NULL);
gdk_gc_set_clip_origin( get_gc( this, glow_eDrawType_Line, 0), 0, 0);
}
int GlowDrawGtk::set_clip_rectangle( GlowWind *wind,
int ll_x, int ll_y, int ur_x, int ur_y)
{
DrawWindGtk *w = (DrawWindGtk *) wind->window;
if ( w->clip_cnt >= DRAW_CLIP_SIZE) {
printf("** Draw clip refuced\n");
return 0;
}
int x0, x1, y0, y1;
if ( w->clip_cnt == 0) {
x0 = min( ll_x, ur_x);
x1 = max( ll_x, ur_x);
y0 = min( ll_y, ur_y);
y1 = max( ll_y, ur_y);
}
else {
x0 = min( ll_x, ur_x);
x1 = max( ll_x, ur_x);
y0 = min( ll_y, ur_y);
y1 = max( ll_y, ur_y);
x0 = max( x0, w->clip_rectangle[w->clip_cnt-1].x);
x1 = min( x1, w->clip_rectangle[w->clip_cnt-1].x +
w->clip_rectangle[w->clip_cnt-1].width);
y0 = max( y0, w->clip_rectangle[w->clip_cnt-1].y);
y1 = min( y1, w->clip_rectangle[w->clip_cnt-1].y +
w->clip_rectangle[w->clip_cnt-1].height);
if ( x0 > x1)
x0 = x1;
if ( y0 > y1)
y0 = y1;
}
w->clip_rectangle[w->clip_cnt].x = x0;
w->clip_rectangle[w->clip_cnt].y = y0;
w->clip_rectangle[w->clip_cnt].width = x1 - x0;
w->clip_rectangle[w->clip_cnt].height = y1 - y0;
w->clip_cnt++;
w->clip_on = 1;
return 1;
}
void GlowDrawGtk::reset_clip_rectangle( GlowWind *wind)
{
DrawWindGtk *w = (DrawWindGtk *) wind->window;
if ( w->clip_cnt == 0) {
printf( "** Draw clip mismatch\n");
return;
}
w->clip_cnt--;
if ( w->clip_cnt == 0)
w->clip_on = 0;
}
int GlowDrawGtk::clip_level( GlowWind *wind)
{
DrawWindGtk *w = (DrawWindGtk *) wind->window;
return w->clip_cnt;
}
int GlowDrawGtk::draw_point( GlowWind *wind, int x1, int y1, glow_eDrawType gc_type)
{
DrawWindGtk *w = (DrawWindGtk *) wind->window;
if ( ctx->nodraw) return 1;
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type, 0));
gdk_draw_point( w->window,
get_gc( this, gc_type, 0),
x1, y1);
if ( w->double_buffer_on)
gdk_draw_point( w->buffer,
get_gc( this, gc_type, 0),
x1, y1);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type, 0));
return 1;
}
int GlowDrawGtk::draw_points( GlowWind *wind, glow_sPointX *points, int point_num,
glow_eDrawType gc_type)
{
if ( ctx->nodraw) return 1;
DrawWindGtk *w = (DrawWindGtk *) wind->window;
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type, 0));
GdkPoint* gpoints = points_to_gdk_points( points, point_num);
gdk_draw_points( w->window,
get_gc( this, gc_type, 0),
gpoints, point_num);
free( gpoints);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type, 0));
return 1;
}
void GlowDrawGtk::set_click_sensitivity( GlowWind *wind, int value)
{
click_sensitivity = value;
}
void GlowDrawGtk::draw_background( GlowWind *wind, int x, int y, int w, int h)
{
DrawWindGtk *ww = (DrawWindGtk *) wind->window;
gdk_window_clear_area( ww->window, x, y, w, h);
}
int GlowDrawGtk::create_buffer( GlowWind *wind)
{
DrawWindGtk *w = (DrawWindGtk *) wind->window;
int window_width, window_height;
if ( &ctx->mw == wind) {
window_width = ctx->mw.window_width;
window_height = ctx->mw.window_height;
}
else {
window_width = ctx->navw.window_width;
window_height = ctx->navw.window_height;
}
if ( !w->double_buffer_on || !window_width)
return 0;
if ( window_width == w->buffer_width &&
window_height == w->buffer_height)
return 0;
if ( w->buffer)
g_object_unref( w->buffer);
w->buffer = gdk_pixmap_new( w->window,
window_width, window_height, -1);
w->buffer_width = window_width;
w->buffer_height = window_height;
buffer_background( w);
return 1;
}
void GlowDrawGtk::buffer_background( DrawWind *wind)
{
DrawWindGtk *w = (DrawWindGtk *) wind;
int window_width, window_height, subwindow_x, subwindow_y;
if ( ctx->mw.window == wind) {
window_width = ctx->mw.window_width;
window_height = ctx->mw.window_height;
subwindow_x = ctx->mw.subwindow_x;
subwindow_y = ctx->mw.subwindow_y;
}
else {
window_width = ctx->navw.window_width;
window_height = ctx->navw.window_height;
subwindow_x = ctx->navw.subwindow_x;
subwindow_y = ctx->navw.subwindow_y;
}
if ( !w->double_buffer_on || !window_width)
return;
if ( w->background_pixmap) {
if ( w->clip_on)
set_clip( w, get_gc( this, glow_eDrawType_Line, 0));
if ( !((GrowCtx *)ctx)->background_tiled)
gdk_draw_drawable( w->background_pixmap,
get_gc( this, glow_eDrawType_Line, 0), w->buffer,
0, 0, 0, 0, w->buffer_width, w->buffer_height);
else {
int i, j;
for ( i = 0;
i <= w->buffer_width / w->background_pixmap_width;
i++)
for ( j = 0;
j <= w->buffer_height / w->background_pixmap_height;
j++)
gdk_draw_drawable( w->background_pixmap,
get_gc( this, glow_eDrawType_Line, 0), w->buffer,
0, 0,
i * w->background_pixmap_width,
j * w->background_pixmap_height,
w->background_pixmap_width,
w->background_pixmap_height);
}
if ( w->clip_on)
reset_clip( w, get_gc( this, glow_eDrawType_Line, 0));
}
else {
if ( w->clip_on)
set_clip( w, get_gc( this, glow_eDrawType_LineErase, 0));
gdk_draw_rectangle( w->buffer,
get_gc( this, glow_eDrawType_LineErase, 0), 1,
subwindow_x, subwindow_y, window_width, window_height);
if ( w->clip_on)
reset_clip( w, get_gc( this, glow_eDrawType_LineErase, 0));
}
}
int GlowDrawGtk::print( char *filename, double x0, double x1, int end)
{
#if defined IMLIB
#define ps_cPageHeight 820
#define ps_cPageWidth 535
#define ps_cLeftMargin 100
#define ps_cTopMargin 100
DrawWindGtk *w = &m_wind;
int width, height;
unsigned char *rgb;
unsigned char transp[3] = {255,0,255};
int i, j;
int grey;
int red, blue, green;
double scalex = 0.71;
double scaley = 0.78;
double x, y;
bool colorimage = true;
static DrawPs *ps = 0;
bool new_file = false;
int window_width = ctx->mw.window_width;
int window_height = ctx->mw.window_height;
x = ps_cLeftMargin;
y = ps_cPageHeight - ps_cTopMargin;
// imlib = Imlib_init( display);
GdkImlibImage *image;
if ( w->double_buffer_on)
image = gdk_imlib_create_image_from_drawable( w->buffer,
0, 0, 0, w->buffer_width,
w->buffer_height);
else
image = gdk_imlib_create_image_from_drawable( w->window,
0, 0, 0, window_width,
window_height);
if ( !image)
return 0;
if ( !ps) {
ps = new DrawPs( filename);
new_file = true;
ps->y = y;
}
else
y = ps->y;
width = image->rgb_width;
height = image->rgb_height;
if ( x0 != 0 || x1 != 0) {
double total_width = width / (x1 - x0);
if ( total_width * scalex > ps_cPageWidth - ps_cLeftMargin) {
x = ps_cPageWidth - total_width * scalex;
if ( x < 50) {
double scale_factor = (ps_cPageWidth - 50) / (total_width * scalex);
x = 50;
scalex = scalex * scale_factor;
scaley = scaley * scale_factor;
}
}
x += scalex * total_width * x0;
}
else if ( width * scalex > ps_cPageWidth - ps_cLeftMargin) {
x = ps_cPageWidth - width * scalex;
if ( x < 50) {
double scale_factor = (ps_cPageWidth - 50) / (width * scalex);
x = 50;
scalex = scalex * scale_factor;
scaley = scaley * scale_factor;
}
}
if ( (x0 == 0 && x1 == 0) || x1 == 1.0)
ps->y -= scaley * height;
if ( new_file) {
ps->fp <<
"%!PS-Adobe-2.0 EPSF-1.2" << endl <<
"%%Creator: Proview $Id: glow_draw_gtk.cpp,v 1.1 2007-01-04 08:07:43 claes Exp $ Glow" << endl <<
"%%EndComments" << endl << endl;
}
else
ps->fp <<
"restore" << endl;
ps->fp <<
"1.000000 1.000000 scale" << endl <<
"save" << endl <<
scalex * width << " " << scaley * height << " scale" << endl <<
"/oneline " << width << " string def" << endl <<
"/drawimage {" << endl <<
" " << width << " " << height << " 8 [" << width << " 0 0 -" << height << " 0 " << height << "]" << endl <<
" { currentfile oneline readhexstring pop }" << endl;
if ( colorimage) {
ps->fp <<
"false 3" << endl <<
"colorimage" << endl;
}
else
ps->fp <<
"image" << endl;
ps->fp <<
"} def" << endl <<
x/scalex/width << " " << (y - height*scaley)/scaley/height << " translate" << endl <<
"drawimage" << endl;
ps->fp.flags( (ps->fp.flags() & ~ios_base::dec) | ios_base::hex | ios_base::uppercase);
ps->fp.fill('0');
rgb = image->rgb_data;
j = 0;
for ( i = 0; i < image->rgb_height * image->rgb_width * 3; i+=3) {
if ( !colorimage) {
if ( *rgb == transp[0] && *(rgb+1) == transp[1] && *(rgb+2) == transp[2]) {
grey = 255;
}
else {
grey = (int) ((0.0 + *rgb + *(rgb+1) + *(rgb+2)) / 3 + 0.5);
}
rgb += 3;
ps->fp.width(2);
ps->fp << grey;
if ( ++j >= 40) {
j = 0;
ps->fp << endl;
}
}
else {
if ( *rgb == transp[0] && *(rgb+1) == transp[1] && *(rgb+2) == transp[2]) {
red = blue = green = 255;
}
else {
red = *rgb;
green = *(rgb+1);
blue = *(rgb+2);
}
rgb += 3;
ps->fp.width(2);
ps->fp << blue;
ps->fp.width(2);
ps->fp << green;
ps->fp.width(2);
ps->fp << red;
if ( ++j >= 20) {
j = 0;
ps->fp << endl;
}
}
}
if ( end) {
ps->fp << endl <<
"restore" << endl <<
"showpage" << endl;
delete ps;
ps = 0;
}
else {
ps->fp.flags( ((ps->fp.flags() & ~ios_base::hex) & ~ios_base::uppercase) | ios_base::dec);
}
gdk_imlib_destroy_image( image);
#endif
return 1;
}
GdkPoint *GlowDrawGtk::points_to_gdk_points( glow_sPointX *points, int point_cnt)
{
GdkPoint *gpoints = (GdkPoint *)malloc( point_cnt * sizeof(GdkPoint));
for ( int i = 0; i < point_cnt; i++) {
gpoints[i].x = points[i].x;
gpoints[i].y = points[i].y;
}
return gpoints;
}
int GlowDrawGtk::get_font_idx( int gc_type)
{
int font_idx;
switch( gc_type) {
case glow_eDrawType_TextHelveticaBold:
case glow_eDrawType_TextHelveticaEraseBold:
font_idx = glow_eDrawFont_HelveticaBold;
break;
default:
font_idx = glow_eDrawFont_Helvetica;
break;
}
return font_idx;
}
void GlowDrawGtk::imlib_destroy_image( glow_tImData imlib, glow_tImImage image)
{
gdk_imlib_destroy_image( (GdkImlibImage *)image);
}
void GlowDrawGtk::imlib_kill_image( glow_tImData imlib, glow_tImImage image)
{
gdk_imlib_kill_image( (GdkImlibImage *)image);
}
void GlowDrawGtk::imlib_free_pixmap( glow_tImData imlib, glow_tPixmap pixmap)
{
gdk_imlib_free_pixmap( (GdkPixmap *)pixmap);
}
glow_tImImage GlowDrawGtk::imlib_load_image( glow_tImData imlib, char *filename)
{
return (glow_tImImage) gdk_imlib_load_image( filename);
}
glow_tImImage GlowDrawGtk::imlib_clone_image( glow_tImData imlib, glow_tImImage image)
{
return (glow_tImImage) gdk_imlib_clone_image( (GdkImlibImage *)image);
}
int GlowDrawGtk::imlib_render( glow_tImData imlib, glow_tImImage image, int width, int height)
{
return gdk_imlib_render( (GdkImlibImage *)image, width, height);
}
glow_tPixmap GlowDrawGtk::imlib_move_image( glow_tImData imlib, glow_tImImage image)
{
return (glow_tPixmap) gdk_imlib_move_image( (GdkImlibImage *)image);
}
glow_tPixmap GlowDrawGtk::imlib_move_mask( glow_tImData imlib, glow_tImImage image)
{
return (glow_tPixmap) gdk_imlib_move_mask( (GdkImlibImage *)image);
}
void GlowDrawGtk::imlib_rotate_image( glow_tImData imlib, glow_tImImage image, int d)
{
gdk_imlib_rotate_image( (GdkImlibImage *)image, d);
}
void GlowDrawGtk::imlib_flip_image_vertical( glow_tImData imlib, glow_tImImage image)
{
gdk_imlib_flip_image_vertical( (GdkImlibImage *)image);
}
void GlowDrawGtk::imlib_flip_image_horizontal( glow_tImData imlib, glow_tImImage image)
{
gdk_imlib_flip_image_horizontal( (GdkImlibImage *)image);
}
void GlowDrawGtk::imlib_set_image_red_curve( glow_tImData imlib, glow_tImImage image, unsigned char *mod)
{
gdk_imlib_set_image_red_curve( (GdkImlibImage *)image, mod);
}
void GlowDrawGtk::imlib_set_image_green_curve( glow_tImData imlib, glow_tImImage image, unsigned char *mod)
{
gdk_imlib_set_image_green_curve( (GdkImlibImage *)image, mod);
}
void GlowDrawGtk::imlib_set_image_blue_curve( glow_tImData imlib, glow_tImImage image, unsigned char *mod)
{
gdk_imlib_set_image_blue_curve( (GdkImlibImage *)image, mod);
}
void GlowDrawGtk::imlib_changed_image( glow_tImData imlib, glow_tImImage image)
{
gdk_imlib_changed_image( (GdkImlibImage *)image);
}
int GlowDrawGtk::imlib_image_rgb_width( glow_tImImage image)
{
return ((GdkImlibImage *)image)->rgb_width;
}
int GlowDrawGtk::imlib_image_rgb_height( glow_tImImage image)
{
return ((GdkImlibImage *)image)->rgb_height;
}
unsigned char *GlowDrawGtk::imlib_image_rgb_data( glow_tImImage image)
{
return ((GdkImlibImage *)image)->rgb_data;
}
// Image functions
int GlowDrawGtk::image_get_width( glow_tImImage image)
{
return gdk_pixbuf_get_width( (GdkPixbuf *)image);
}
int GlowDrawGtk::image_get_height( glow_tImImage image)
{
return gdk_pixbuf_get_height( (GdkPixbuf *)image);
}
int GlowDrawGtk::image_get_rowstride( glow_tImImage image)
{
return gdk_pixbuf_get_rowstride( (GdkPixbuf *)image);
}
unsigned char *GlowDrawGtk::image_get_data( glow_tImImage image)
{
return (unsigned char *) gdk_pixbuf_get_pixels( (GdkPixbuf *)image);
}
void GlowDrawGtk::image_rotate( glow_tImImage *image, int to_rotation, int from_rotation)
{
int grot;
int drot = to_rotation - from_rotation;
drot = int( (float(drot) / 360 - floor( float(drot) / 360)) * 360);
switch ( drot) {
case 90:
grot = GDK_PIXBUF_ROTATE_CLOCKWISE;
break;
case 180:
grot = GDK_PIXBUF_ROTATE_UPSIDEDOWN;
break;
case 270:
grot = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE;
break;
default:
return;
}
GdkPixbuf *im = gdk_pixbuf_rotate_simple( (GdkPixbuf *)*image, (GdkPixbufRotation) grot);
gdk_pixbuf_unref( (GdkPixbuf *)*image);
*image = (glow_tImImage) im;
}
void GlowDrawGtk::image_flip_vertical( glow_tImImage *image)
{
GdkPixbuf *im = gdk_pixbuf_flip( (GdkPixbuf *)*image, TRUE);
gdk_pixbuf_unref( (GdkPixbuf *)*image);
*image = (glow_tImImage) im;
}
void GlowDrawGtk::image_flip_horizontal( glow_tImImage *image)
{
GdkPixbuf *im = gdk_pixbuf_flip( (GdkPixbuf *)*image, FALSE);
gdk_pixbuf_unref( (GdkPixbuf *)*image);
*image = (glow_tImImage) im;
}
void GlowDrawGtk::image_scale( int width, int height, glow_tImImage orig_im, glow_tImImage *im,
glow_tPixmap *im_pixmap, glow_tPixmap *im_mask)
{
if ( width == gdk_pixbuf_get_width((GdkPixbuf *)*im) &&
height == gdk_pixbuf_get_height((GdkPixbuf *)*im))
return;
if ( !orig_im) {
// Scale from im
if ( !*im)
return;
GdkPixbuf *im_old = (GdkPixbuf *)*im;
*im = gdk_pixbuf_scale_simple( (GdkPixbuf *)*im, width, height, GDK_INTERP_NEAREST);
gdk_pixbuf_unref( (GdkPixbuf *)im_old);
}
else {
// Scale from orig_im
if ( *im)
gdk_pixbuf_unref( (GdkPixbuf *)*im);
*im = gdk_pixbuf_scale_simple( (GdkPixbuf *)orig_im, width, height, GDK_INTERP_NEAREST);
}
}
int GlowDrawGtk::image_load( char *imagefile,
glow_tImImage *orig_im, glow_tImImage *im)
{
if ( *im)
gdk_pixbuf_unref( (GdkPixbuf *)*im);
if ( *orig_im)
gdk_pixbuf_unref( (GdkPixbuf *)*orig_im);
*orig_im = (glow_tImImage *) gdk_pixbuf_new_from_file( imagefile, 0);
*im = (glow_tImImage *) gdk_pixbuf_copy( (GdkPixbuf *)*orig_im);
return 1;
}
int GlowDrawGtk::image_render( int width, int height,
glow_tImImage orig_im, glow_tImImage *im,
glow_tPixmap *im_pixmap, glow_tPixmap *im_mask)
{
#if 0
if ( width == gdk_pixbuf_get_width((GdkPixbuf *)*im) &&
height == gdk_pixbuf_get_height((GdkPixbuf *)*im))
return 1;
image_scale( width, height, orig_im, im, 0, 0);
#endif
return 1;
}
void GlowDrawGtk::image_free( glow_tImImage image)
{
gdk_pixbuf_unref( (GdkPixbuf *)image);
}
void GlowDrawGtk::pixmap_free( glow_tPixmap pixmap)
{
}
void GlowDrawGtk::image_pixel_iter( glow_tImImage orig_image, glow_tImImage *image,
void (* pixel_cb)(void *, unsigned char *), void *userdata)
{
unsigned char *rgb, *rgb_row;
int rgb_height;
int rgb_width;
int rowstride;
int n_channels;
if ( orig_image) {
if ( image)
gdk_pixbuf_unref( (GdkPixbuf *)*image);
*image = (glow_tImImage *) gdk_pixbuf_copy( (GdkPixbuf *)orig_image);
}
else if ( !*image)
return;
rgb = gdk_pixbuf_get_pixels( (GdkPixbuf *)*image);
rgb_height = gdk_pixbuf_get_height( (GdkPixbuf *)*image);
rgb_width = gdk_pixbuf_get_width( (GdkPixbuf *)*image);
rowstride = gdk_pixbuf_get_rowstride( (GdkPixbuf *)*image);
n_channels = gdk_pixbuf_get_n_channels( (GdkPixbuf *)*image);
rgb_row = rgb;
for ( int j = 0; j < rgb_height; j++) {
rgb = rgb_row;
for ( int i = 0; i < rgb_width; i++) {
if ( n_channels >= 4 && *(rgb+3))
(pixel_cb) ( userdata, rgb);
rgb += n_channels;
}
rgb_row += rowstride;
}
}
/*
* Proview $Id: glow_draw_gtk.h,v 1.1 2007-01-04 08:07:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* 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 the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#ifndef glow_draw_gtk_h
#define glow_draw_gtk_h
#include <stdlib.h>
#include <libgnome.h>
#include <libgnomeui/libgnomeui.h>
#include <gtk/gtkprivate.h>
#include "glow_draw.h"
#define DRAW_CLIP_SIZE 10
class DrawWindGtk : public DrawWind {
public:
DrawWindGtk() : toplevel(0), shell(0), window(0), colormap(0),
buffer(0), buffer_width(0), buffer_height(0),
clip_on(0), clip_cnt(0), background_pixmap(0),
background_pixmap_width(0), background_pixmap_height(0)
{ memset( clip_rectangle, 0, sizeof(clip_rectangle)); }
GtkWidget *toplevel;
GtkWidget *shell;
GdkWindow *window;
GdkColormap *colormap;
GdkPixmap *buffer;
int buffer_width;
int buffer_height;
int clip_on;
int clip_cnt;
GdkRectangle clip_rectangle[DRAW_CLIP_SIZE];
GdkPixmap *background_pixmap;
int background_pixmap_width;
int background_pixmap_height;
};
class GlowDrawGtk : public GlowDraw {
public:
GlowDrawGtk(
GtkWidget *toplevel,
void **glow_ctx,
int (*init_proc)(GtkWidget *w, GlowCtx *ctx, void *client_data),
void *client_data,
glow_eCtxType type);
~GlowDrawGtk();
DrawWindGtk m_wind;
DrawWindGtk nav_wind;
GdkDisplay *display;
GdkScreen *screen;
GdkGC *gc;
GdkGC *gc_erase;
GdkGC *gc_inverse;
GdkGC *gcs[glow_eDrawType__][DRAW_TYPE_SIZE];
// XFontStruct *font_struct[glow_eDrawFont__][DRAW_FONT_SIZE];
GdkFont *font[glow_eDrawFont__][DRAW_FONT_SIZE];
GdkCursor *cursors[glow_eDrawCursor__];
int ef;
GdkColormap *colormap;
GdkColor background;
GdkColor original_background;
guint timer_id;
int click_sensitivity;
int event_handler( GdkEvent event);
virtual void enable_event( glow_eEvent event,
glow_eEventType event_type,
int (*event_cb)(GlowCtx *ctx, glow_tEvent event));
virtual void clear( GlowWind *w);
virtual void copy_buffer( GlowWind *w, int ll_x, int ll_y, int ur_x, int ur_y);
virtual void get_window_size( GlowWind *w, int *width, int *height);
virtual void set_window_size( GlowWind *w, int width, int height);
virtual int rect( GlowWind *w, int x, int y, int width, int height,
glow_eDrawType gc_type, int idx, int highlight);
virtual int rect_erase( GlowWind *w, int x, int y, int width, int height,
int idx);
virtual int arrow( GlowWind *w, int x1, int y1, int x2, int y2,
int x3, int y3,
glow_eDrawType gc_type, int idx, int highlight);
virtual int arrow_erase( GlowWind *w, int x1, int y1, int x2, int y2,
int x3, int y3,
int idx);
virtual int arc( GlowWind *w, int x, int y, int width, int height,
int angel1, int angel2,
glow_eDrawType gc_type, int idx, int highlight);
virtual int fill_arc( GlowWind *w, int x, int y, int width, int height,
int angel1, int angel2, glow_eDrawType gc_type, int highlight);
virtual int arc_erase( GlowWind *w, int x, int y, int width, int height,
int angel1, int angel2,
int idx);
virtual int line( GlowWind *w, int x1, int y1, int x2, int y2,
glow_eDrawType gc_type, int idx, int highlight);
virtual int line_dashed( GlowWind *w, int x1, int y1, int x2, int y2,
glow_eDrawType gc_type, int idx, int highlight, glow_eLineType line_type);
virtual int line_erase( GlowWind *w, int x1, int y1, int x2, int y2,
int idx);
virtual int polyline( GlowWind *w, glow_sPointX *points, int point_cnt,
glow_eDrawType gc_type, int idx, int highlight);
virtual int fill_polyline( GlowWind *w, glow_sPointX *points, int point_cnt,
glow_eDrawType gc_type, int highlight);
virtual int polyline_erase( GlowWind *w, glow_sPointX *points, int point_cnt,
int idx);
virtual int text( GlowWind *w, int x, int y, char *text, int len,
glow_eDrawType gc_type, glow_eDrawType color, int idx, int highlight, int line);
virtual int text_cursor( GlowWind *w, int x, int y, char *text, int len,
glow_eDrawType gc_type, glow_eDrawType color, int idx, int highlight, int pos);
virtual int text_erase( GlowWind *w, int x, int y, char *text, int len,
glow_eDrawType gc_type, int idx, int line);
virtual int fill_rect( GlowWind *w, int x, int y, int width, int height,
glow_eDrawType gc_type);
virtual int pixmaps_create( GlowWind *w, glow_sPixmapData *pixmap_data,
void **pixmaps);
virtual void pixmaps_delete( GlowWind *w, void *pixmaps);
virtual int pixmap( GlowWind *w, int x, int y, glow_sPixmapData *pixmap_data,
void *pixmaps, glow_eDrawType gc_type, int idx, int highlight, int line);
virtual int pixmap_inverse( GlowWind *w, int x, int y, glow_sPixmapData *pixmap_data,
void *pixmaps, glow_eDrawType gc_type, int idx, int line);
virtual int pixmap_erase( GlowWind *w, int x, int y, glow_sPixmapData *pixmap_data,
void *pixmaps, glow_eDrawType gc_type, int idx, int line);
virtual int image( GlowWind *w, int x, int y, int width, int height,
glow_tImImage image, glow_tPixmap pixmap, glow_tPixmap clip_mask);
virtual void set_cursor( GlowWind *w, glow_eDrawCursor cursor);
virtual int get_text_extent( char *text, int len,
glow_eDrawType gc_type, int idx,
int *width, int *height, int *descent);
virtual void copy_area( GlowWind *w, int x, int y);
virtual void clear_area( GlowWind *w, int ll_x, int ur_x, int ll_y, int ur_y);
virtual void set_inputfocus( GlowWind *w);
virtual void set_background( GlowWind *w, glow_eDrawType drawtype, glow_tPixmap pixmap,
int pixmap_width, int pixmap_height);
virtual void reset_background( GlowWind *w);
virtual void set_image_clip_mask( glow_tPixmap pixmap, int x, int y);
virtual void reset_image_clip_mask();
virtual int set_clip_rectangle( GlowWind *w, int ll_x, int ll_y, int ur_x, int ur_y);
virtual void reset_clip_rectangle( GlowWind *w);
virtual int clip_level( GlowWind *w);
virtual int draw_point( GlowWind *w, int x1, int y1, glow_eDrawType gc_type);
virtual int draw_points( GlowWind *w, glow_sPointX *points, int point_num,
glow_eDrawType gc_type);
virtual void set_click_sensitivity( GlowWind *w, int value);
virtual void draw_background( GlowWind *w, int x, int y, int w, int h);
virtual int create_buffer( GlowWind *w);
virtual void buffer_background( DrawWind *w);
virtual int print( char *filename, double x0, double x1, int end);
void set_clip( DrawWind *w, GdkGC *gc);
void reset_clip( DrawWind *w, GdkGC *gc);
virtual void set_timer( GlowCtx *gctx, int time_ms,
void (*callback_func)( GlowCtx *ctx), void **id);
virtual void remove_timer( void *id);
int init_nav( GtkWidget *nav_widget);
GdkPoint *points_to_gdk_points( glow_sPointX *points, int point_cnt);
int get_font_idx( int gc_type);
virtual void imlib_destroy_image( glow_tImData imlib, glow_tImImage image);
virtual void imlib_kill_image( glow_tImData imlib, glow_tImImage image);
virtual void imlib_free_pixmap( glow_tImData imlib, glow_tPixmap pixmap);
virtual glow_tImImage imlib_load_image( glow_tImData imlib, char *filename);
virtual glow_tImImage imlib_clone_image( glow_tImData imlib, glow_tImImage image);
virtual int imlib_render( glow_tImData imlib, glow_tImImage image, int width, int height);
virtual glow_tPixmap imlib_move_image( glow_tImData imlib, glow_tImImage image);
virtual glow_tPixmap imlib_move_mask( glow_tImData imlib, glow_tImImage image);
virtual void imlib_rotate_image( glow_tImData imlib, glow_tImImage image, int d);
virtual void imlib_flip_image_vertical( glow_tImData imlib, glow_tImImage image);
virtual void imlib_flip_image_horizontal( glow_tImData imlib, glow_tImImage image);
virtual void imlib_set_image_red_curve( glow_tImData imlib, glow_tImImage image, unsigned char *mod);
virtual void imlib_set_image_green_curve( glow_tImData imlib, glow_tImImage image, unsigned char *mod);
virtual void imlib_set_image_blue_curve( glow_tImData imlib, glow_tImImage image, unsigned char *mod);
virtual void imlib_changed_image( glow_tImData imlib, glow_tImImage image);
virtual int imlib_image_rgb_width( glow_tImImage image);
virtual int imlib_image_rgb_height( glow_tImImage image);
virtual unsigned char *imlib_image_rgb_data( glow_tImImage image);
int image_get_width( glow_tImImage image);
int image_get_height( glow_tImImage image);
int image_get_rowstride( glow_tImImage image);
unsigned char *image_get_data( glow_tImImage image);
void image_rotate( glow_tImImage *image, int to_rotation, int from_rotation);
void image_flip_vertical( glow_tImImage *image);
void image_flip_horizontal( glow_tImImage *image);
void image_scale( int width, int height, glow_tImImage orig_im, glow_tImImage *im,
glow_tPixmap *im_pixmap, glow_tPixmap *im_mask);
int image_load( char *imagefile,
glow_tImImage *orig_im, glow_tImImage *im);
int image_render( int width, int height,
glow_tImImage orig_im, glow_tImImage *im,
glow_tPixmap *im_pixmap, glow_tPixmap *im_mask);
void image_free( glow_tImImage image);
void pixmap_free( glow_tPixmap pixmap);
void image_pixel_iter( glow_tImImage orig_image, glow_tImImage *image,
void (* pixel_cb)(void *, unsigned char *), void *userdata);
};
class DrawPs {
public:
DrawPs( char *filename) : fp(filename), x(0), y(0)
{}
~DrawPs() { fp.close();}
ofstream fp;
double x;
double y;
};
#endif
/*
* Proview $Id: glow_growwidget_gtk.cpp,v 1.1 2007-01-04 08:07:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* 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 the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#include <stdlib.h>
#include "glow_std.h"
#include <gtk/gtk.h>
#include <gtk/gtkprivate.h>
#include "glow_growwidget_gtk.h"
#include "glow.h"
#include "glow_ctx.h"
#include "glow_growctx.h"
#include "glow_draw.h"
#include "glow_draw_gtk.h"
typedef struct _GrowWidgetGtk GrowWidgetGtk;
typedef struct _GrowWidgetGtkClass GrowWidgetGtkClass;
typedef struct {
GtkWidget *grow;
GtkWidget *form;
GtkWidget *scroll_h;
GtkWidget *scroll_v;
int scroll_h_managed;
int scroll_v_managed;
} growwidget_sScroll;
struct _GrowWidgetGtk {
GtkDrawingArea parent;
/* Private */
void *grow_ctx;
void *draw_ctx;
int (*init_proc)(GlowCtx *ctx, void *clien_data);
int is_navigator;
void *client_data;
GtkWidget *main_grow_widget;
GtkWidget *scroll_h;
GtkWidget *scroll_v;
GtkWidget *form;
int scroll_h_ignore;
int scroll_v_ignore;
};
struct _GrowWidgetGtkClass {
GtkDrawingAreaClass parent_class;
};
G_DEFINE_TYPE( GrowWidgetGtk, growwidgetgtk, GTK_TYPE_DRAWING_AREA);
static void scroll_callback( glow_sScroll *data)
{
growwidget_sScroll *scroll_data;
scroll_data = (growwidget_sScroll *) data->scroll_data;
if ( data->total_width <= data->window_width) {
if ( data->offset_x == 0)
data->total_width = data->window_width;
if ( scroll_data->scroll_h_managed) {
// Remove horizontal scrollbar
}
}
else {
if ( !scroll_data->scroll_h_managed) {
// Insert horizontal scrollbar
}
}
if ( data->total_height <= data->window_height) {
if ( data->offset_y == 0)
data->total_height = data->window_height;
if ( scroll_data->scroll_v_managed) {
// Remove vertical scrollbar
}
}
else {
if ( !scroll_data->scroll_v_managed) {
// Insert vertical scrollbar
}
}
if ( data->offset_x < 0) {
data->total_width += -data->offset_x;
data->offset_x = 0;
}
if ( data->offset_y < 0) {
data->total_height += -data->offset_y;
data->offset_y = 0;
}
if ( data->total_height < data->window_height + data->offset_y)
data->total_height = data->window_height + data->offset_y;
if ( data->total_width < data->window_width + data->offset_x)
data->total_width = data->window_width + data->offset_x;
if ( data->window_width < 1)
data->window_width = 1;
if ( data->window_height < 1)
data->window_height = 1;
if ( scroll_data->scroll_h_managed) {
((GrowWidgetGtk *)scroll_data->grow)->scroll_h_ignore = 1;
g_object_set( ((GtkScrollbar *)scroll_data->scroll_h)->range.adjustment,
"upper", (gdouble)data->total_width,
"page-size", (gdouble)data->window_width,
"value", (gdouble)data->offset_x,
NULL);
gtk_adjustment_changed(
((GtkScrollbar *)scroll_data->scroll_h)->range.adjustment);
}
if ( scroll_data->scroll_v_managed) {
((GrowWidgetGtk *)scroll_data->grow)->scroll_v_ignore = 1;
g_object_set( ((GtkScrollbar *)scroll_data->scroll_v)->range.adjustment,
"upper", (gdouble)data->total_height,
"page-size", (gdouble)data->window_height,
"value", (gdouble)data->offset_y,
NULL);
gtk_adjustment_changed(
((GtkScrollbar *)scroll_data->scroll_v)->range.adjustment);
}
}
static void scroll_h_action( GtkWidget *w,
gpointer data)
{
GrowWidgetGtk *groww = (GrowWidgetGtk *)data;
if ( groww->scroll_h_ignore) {
groww->scroll_h_ignore = 0;
return;
}
printf( "Horizontal scroll callback\n");
GrowCtx *ctx = (GrowCtx *) groww->grow_ctx;
gdouble value;
g_object_get( w,
"value", &value,
NULL);
glow_scroll_horizontal( ctx, int(value), 0);
}
static void scroll_v_action( GtkWidget *w,
gpointer data)
{
GrowWidgetGtk *groww = (GrowWidgetGtk *)data;
if ( groww->scroll_v_ignore) {
groww->scroll_v_ignore = 0;
return;
}
printf( "Vertical scroll callback\n");
GrowCtx *ctx = (GrowCtx *) groww->grow_ctx;
gdouble value;
g_object_get( w,
"value", &value,
NULL);
glow_scroll_vertical( ctx, int(value), 0);
}
static int grow_init_proc( GtkWidget *w, GlowCtx *fctx, void *client_data)
{
growwidget_sScroll *scroll_data;
GrowCtx *ctx;
ctx = (GrowCtx *) ((GrowWidgetGtk *) w)->grow_ctx;
if ( ((GrowWidgetGtk *) w)->scroll_h) {
scroll_data = (growwidget_sScroll *) malloc( sizeof( growwidget_sScroll));
scroll_data->grow = w;
scroll_data->scroll_h = ((GrowWidgetGtk *) w)->scroll_h;
scroll_data->scroll_v = ((GrowWidgetGtk *) w)->scroll_v;
scroll_data->form = ((GrowWidgetGtk *) w)->form;
scroll_data->scroll_h_managed = 1;
scroll_data->scroll_v_managed = 1;
ctx->register_scroll_callback( (void *) scroll_data, scroll_callback);
}
return (((GrowWidgetGtk *) w)->init_proc)( ctx, client_data);
}
static gboolean growwidgetgtk_expose( GtkWidget *glow, GdkEventExpose *event)
{
((GlowDrawGtk *)((GrowCtx *)((GrowWidgetGtk *)glow)->grow_ctx)->gdraw)->event_handler(
*(GdkEvent *)event);
return TRUE;
}
static void growwidgetgtk_grab_focus( GtkWidget *glow)
{
GTK_WIDGET_CLASS( growwidgetgtk_parent_class)->grab_focus( glow);
gdk_window_focus( glow->window, GDK_CURRENT_TIME);
}
static gboolean growwidgetgtk_event( GtkWidget *glow, GdkEvent *event)
{
if ( event->type == GDK_MOTION_NOTIFY) {
gdk_display_flush( ((GlowDrawGtk *)((GrowCtx *)((GrowWidgetGtk *)glow)->grow_ctx)->gdraw)->display);
GdkEvent *next = gdk_event_peek();
if ( next && next->type == GDK_MOTION_NOTIFY) {
gdk_event_free( next);
return TRUE;
}
else if ( next)
gdk_event_free( next);
}
((GlowDrawGtk *)((GrowCtx *)((GrowWidgetGtk *)glow)->grow_ctx)->gdraw)->event_handler( *event);
return TRUE;
}
static void growwidgetgtk_realize( GtkWidget *widget)
{
GdkWindowAttr attr;
gint attr_mask;
GrowWidgetGtk *grow;
g_return_if_fail (widget != NULL);
g_return_if_fail (IS_GROWWIDGETGTK( widget));
GTK_WIDGET_SET_FLAGS( widget, GTK_REALIZED);
grow = GROWWIDGETGTK( widget);
attr.x = widget->allocation.x;
attr.y = widget->allocation.y;
attr.width = widget->allocation.width;
attr.height = widget->allocation.height;
attr.wclass = GDK_INPUT_OUTPUT;
attr.window_type = GDK_WINDOW_CHILD;
attr.event_mask = gtk_widget_get_events( widget) |
GDK_EXPOSURE_MASK |
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_KEY_PRESS_MASK |
GDK_POINTER_MOTION_MASK |
GDK_BUTTON_MOTION_MASK |
GDK_ENTER_NOTIFY_MASK |
GDK_LEAVE_NOTIFY_MASK;
attr.visual = gtk_widget_get_visual( widget);
attr.colormap = gtk_widget_get_colormap( widget);
attr_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
widget->window = gdk_window_new( widget->parent->window, &attr, attr_mask);
widget->style = gtk_style_attach( widget->style, widget->window);
gdk_window_set_user_data( widget->window, widget);
gtk_style_set_background( widget->style, widget->window, GTK_STATE_ACTIVE);
GTK_WIDGET_SET_FLAGS( widget, GTK_CAN_FOCUS);
if ( grow->is_navigator) {
if ( !grow->grow_ctx) {
GrowWidgetGtk *main_grow = (GrowWidgetGtk *) grow->main_grow_widget;
grow->grow_ctx = main_grow->grow_ctx;
grow->draw_ctx = main_grow->draw_ctx;
((GlowDrawGtk *)grow->draw_ctx)->init_nav( widget);
}
}
else {
if ( !grow->grow_ctx) {
grow->draw_ctx = new GlowDrawGtk( widget,
&grow->grow_ctx,
grow_init_proc,
grow->client_data,
glow_eCtxType_Grow);
}
}
}
static void growwidgetgtk_class_init( GrowWidgetGtkClass *klass)
{
GtkWidgetClass *widget_class;
widget_class = GTK_WIDGET_CLASS( klass);
widget_class->realize = growwidgetgtk_realize;
widget_class->expose_event = growwidgetgtk_expose;
widget_class->event = growwidgetgtk_event;
widget_class->grab_focus = growwidgetgtk_grab_focus;
}
static void growwidgetgtk_init( GrowWidgetGtk *glow)
{
}
GtkWidget *growwidgetgtk_new(
int (*init_proc)(GlowCtx *ctx, void *client_data),
void *client_data)
{
GrowWidgetGtk *w;
w = (GrowWidgetGtk *) g_object_new( GROWWIDGETGTK_TYPE, NULL);
w->init_proc = init_proc;
w->grow_ctx = 0;
w->is_navigator = 0;
w->client_data = client_data;
w->scroll_h = 0;
w->scroll_v = 0;
return (GtkWidget *) w;
}
GtkWidget *scrolledgrowwidgetgtk_new(
int (*init_proc)(GlowCtx *ctx, void *client_data),
void *client_data, GtkWidget **growwidget)
{
GrowWidgetGtk *w;
GtkWidget *form = gtk_scrolled_window_new( NULL, NULL);
w = (GrowWidgetGtk *) g_object_new( GROWWIDGETGTK_TYPE, NULL);
w->init_proc = init_proc;
w->grow_ctx = 0;
w->is_navigator = 0;
w->client_data = client_data;
w->scroll_h = gtk_scrolled_window_get_hscrollbar( GTK_SCROLLED_WINDOW(form));
w->scroll_v = gtk_scrolled_window_get_vscrollbar( GTK_SCROLLED_WINDOW(form));
w->scroll_h_ignore = 0;
w->scroll_v_ignore = 0;
w->form = form;
*growwidget = GTK_WIDGET( w);
g_signal_connect( ((GtkScrollbar *)w->scroll_h)->range.adjustment,
"value-changed", G_CALLBACK(scroll_h_action), w);
g_signal_connect( ((GtkScrollbar *)w->scroll_v)->range.adjustment,
"value-changed", G_CALLBACK(scroll_v_action), w);
GtkWidget *viewport = gtk_viewport_new( NULL, NULL);
gtk_container_add( GTK_CONTAINER(viewport), GTK_WIDGET(w));
gtk_container_add( GTK_CONTAINER(form), GTK_WIDGET(viewport));
return (GtkWidget *) form;
}
GtkWidget *grownavwidgetgtk_new( GtkWidget *main_grow)
{
GrowWidgetGtk *w;
w = (GrowWidgetGtk *) g_object_new( GROWWIDGETGTK_TYPE, NULL);
w->init_proc = 0;
w->grow_ctx = 0;
w->is_navigator = 1;
w->main_grow_widget = main_grow;
w->client_data = 0;
w->scroll_h = 0;
w->scroll_v = 0;
w->scroll_h_ignore = 0;
w->scroll_v_ignore = 0;
return (GtkWidget *) w;
}
#if 0
GType growwidgetgtk_get_type(void)
{
static GType growwidgetgtk_type = 0;
if ( !growwidgetgtk_type) {
static const GTypeInfo growwidgetgtk_info = {
sizeof(GrowWidgetGtkClass), NULL, NULL, (GClassInitFunc)growwidgetgtk_class_init,
NULL, NULL, sizeof(GrowWidgetGtk), 1, NULL, NULL};
growwidgetgtk_type = g_type_register_static( G_TYPE_OBJECT, "GrowWidgetGtk", &growwidgetgtk_info,
(GTypeFlags)0);
}
return growwidgetgtk_type;
}
#endif
/*
* Proview $Id: glow_growwidget_gtk.h,v 1.1 2007-01-04 08:07:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* 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 the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#include <stdlib.h>
#include "glow_std.h"
#include <gtk/gtk.h>
#include <gtk/gtkprivate.h>
#include "glow.h"
#include "glow_ctx.h"
#include "glow_growctx.h"
#define GROWWIDGETGTK_TYPE (growwidgetgtk_get_type())
#define GROWWIDGETGTK(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GROWWIDGETGTK_TYPE, GrowWidgetGtk))
#define GROWWIDGETGTK_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST((obj), GROWWIDGETGTK, GrowWidgetGtkClass))
#define IS_GROWWIDGETGTK(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GROWWIDGETGTK_TYPE))
#define IS_GROWWIDGETGTK_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((obj), GROWWIDGETGTK_TYPE))
#define GROWWIDGETGTK_GET_CLASS (G_TYPE_INSTANCE_GET_CLASS((obj), GROWWIDGETGTK, GrowWidgetGtkClass))
GType growwidgetgtk_get_type(void);
GtkWidget *growwidgetgtk_new(
int (*init_proc)(GlowCtx *ctx, void *client_data),
void *client_data);
GtkWidget *scrolledgrowwidgetgtk_new(
int (*init_proc)(GlowCtx *ctx, void *client_data),
void *client_data, GtkWidget **growwidget);
GtkWidget *grownavwidgetgtk_new( GtkWidget *main_grow);
include $(pwre_dir_symbols)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(hw_name)/$(type_name)_generic.mk
ifeq ($($(type_name)_generic_mk),)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(type_name)_generic.mk
endif
ifeq ($($(type_name)_generic_mk),)
include $(pwre_kroot)/tools/bld/src/$(type_name)_generic.mk
endif
-include ../../special.mk
-include ../special.mk
-include special.mk
/*
* Proview $Id: glow_colpalwidget_motif.cpp,v 1.1 2007-01-04 08:08:00 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* 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 the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#include "glow_std.h"
#include <stdio.h>
#include <stdlib.h>
#ifdef __OS_VMS
#pragma member_alignment
#endif
#include <Xm/Xm.h>
#include <Xm/XmP.h>
#include <Xm/ScrollBar.h>
#include <Xm/Form.h>
#include <Mrm/MrmPublic.h>
#ifndef _XtIntrinsic_h
#include <X11/Intrinsic.h>
#endif
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "glow.h"
#include "glow_colpalctx.h"
#include "glow_draw_xlib.h"
#include "glow_colpalwidget_motif.h"
typedef struct {
Widget colpal;
Widget form;
Widget scroll_h;
Widget scroll_v;
int scroll_h_managed;
int scroll_v_managed;
} colpalwidget_sScroll;
static XtGeometryResult GeometryManager(
Widget w,
XtWidgetGeometry *request,
XtWidgetGeometry *reply);
static void Notify( Widget w, XEvent *event);
static void Destroy( Widget w);
static void Realize( Widget w, unsigned long *dum, XSetWindowAttributes *swa);
static void Initialize( Widget rec, Widget new_widget, ArgList arg, int *args);
static void Redisplay( Widget w, XEvent *event, Region region);
static Boolean SetValues( Widget old, Widget request, Widget new_widget);
static char defaultTranslations[] = "#replace \n\
<Btn1Up>: notify()\n\
<Btn2Up>: notify()\n\
<Btn3Up>: notify()\n\
<Btn1Down>: notify()\n\
<Btn2Down>: notify()\n\
<Btn3Down>: notify()\n\
<BtnMotion>: notify()\n\
<EnterWindow>: notify()\n\
<LeaveWindow>: notify()\n\
<VisibilityNotify>: notify()\n\
<MotionNotify>: notify()\n\
<FocusIn>: notify()\n\
<Key>Up: notify()\n\
<Key>Down: notify()\n\
<KeyDown>: notify()";
static XtActionsRec actionsList[] = { {"notify", (XtActionProc) Notify}};
ColPalClassRec colpalClassRec = {
{ /* Core class part */
(WidgetClass) &compositeClassRec, /* superclass */
"ColPal", /* class name */
sizeof(ColPalRec), /* widget size */
NULL, /* class initialize */
NULL, /* class part initialize */
FALSE, /* class inited */
(XtInitProc) Initialize, /* initialize */
NULL, /* initialize hook */
Realize, /* realize */
actionsList, /* actions */
XtNumber( actionsList), /* num actions */
NULL, /* resourses */
0, /* num resourses */
NULLQUARK, /* xrm class */
TRUE, /* compress motion */
TRUE, /* compress expsure */
TRUE, /* compress enterleave */
FALSE, /* visible interest */
Destroy, /* destroy */
XtInheritResize, /* resize */
Redisplay, /* expose */
(XtSetValuesFunc)SetValues, /* set values */
NULL, /* set values hook */
XtInheritSetValuesAlmost, /* set values almost */
NULL, /* get values hook */
NULL, /* accept focus */
XtVersionDontCheck, /* version */
NULL, /* callback offsets */
defaultTranslations, /* tm_table */
NULL, /* geometry */
NULL, /* disp accelerators */
NULL /* extension */
},
{ /* composite class record */
(XtGeometryHandler) GeometryManager, /* geometry manager */
NULL, /* change managed */
XtInheritInsertChild, /* insert child */
XtInheritDeleteChild, /* delete child */
NULL /* extension */
},
{ /* colpal class record */
NULL,
0
}
};
WidgetClass colpalWidgetClass = (WidgetClass) &colpalClassRec;
static void scroll_h_action( Widget w,
XtPointer client_data,
XtPointer call_data);
static void scroll_v_action( Widget w,
XtPointer client_data,
XtPointer call_data);
static void scroll_callback( glow_sScroll *data);
static int colpal_init_proc( Widget w, GlowCtx *fctx, void *client_data)
{
colpalwidget_sScroll *scroll_data;
ColPalCtx *ctx;
scroll_data = (colpalwidget_sScroll *) malloc( sizeof( colpalwidget_sScroll));
scroll_data->colpal = w;
scroll_data->scroll_h = ((ColPalWidget) w)->colpal.scroll_h;
scroll_data->scroll_v = ((ColPalWidget) w)->colpal.scroll_v;
scroll_data->form = ((ColPalWidget) w)->colpal.form;
scroll_data->scroll_h_managed = 1;
scroll_data->scroll_v_managed = 1;
ctx = (ColPalCtx *) ((ColPalWidget) w)->colpal.colpal_ctx;
ctx->register_scroll_callback( (void *) scroll_data, scroll_callback);
XtAddCallback( scroll_data->scroll_h, XmNvalueChangedCallback, scroll_h_action, w);
XtAddCallback( scroll_data->scroll_h, XmNdragCallback, scroll_h_action, w);
XtAddCallback( scroll_data->scroll_h, XmNincrementCallback, scroll_h_action, w);
XtAddCallback( scroll_data->scroll_h, XmNdecrementCallback, scroll_h_action, w);
XtAddCallback( scroll_data->scroll_h, XmNpageIncrementCallback, scroll_h_action, w);
XtAddCallback( scroll_data->scroll_h, XmNpageDecrementCallback, scroll_h_action, w);
XtAddCallback( scroll_data->scroll_h, XmNtoTopCallback, scroll_h_action, w);
XtAddCallback( scroll_data->scroll_h, XmNtoBottomCallback, scroll_h_action, w);
XtAddCallback( scroll_data->scroll_v, XmNvalueChangedCallback, scroll_v_action, w);
XtAddCallback( scroll_data->scroll_v, XmNdragCallback, scroll_v_action, w);
XtAddCallback( scroll_data->scroll_v, XmNincrementCallback, scroll_v_action, w);
XtAddCallback( scroll_data->scroll_v, XmNdecrementCallback, scroll_v_action, w);
XtAddCallback( scroll_data->scroll_v, XmNpageIncrementCallback, scroll_v_action, w);
XtAddCallback( scroll_data->scroll_v, XmNpageDecrementCallback, scroll_v_action, w);
XtAddCallback( scroll_data->scroll_v, XmNtoTopCallback, scroll_v_action, w);
XtAddCallback( scroll_data->scroll_v, XmNtoBottomCallback, scroll_v_action, w);
ctx->configure();
if ( ((ColPalWidget) w)->colpal.init_proc)
return (((ColPalWidget) w)->colpal.init_proc)( ctx, client_data);
else
return 1;
}
static void scroll_h_action( Widget w,
XtPointer client_data,
XtPointer call_data)
{
XmScrollBarCallbackStruct *cbs = (XmScrollBarCallbackStruct *) call_data;
ColPalCtx *ctx = (ColPalCtx *) ((ColPalWidget) client_data)->colpal.colpal_ctx;
switch( cbs->reason)
{
case XmCR_DRAG:
case XmCR_VALUE_CHANGED:
case XmCR_INCREMENT:
case XmCR_DECREMENT:
case XmCR_PAGE_INCREMENT:
case XmCR_PAGE_DECREMENT:
case XmCR_TO_TOP:
case XmCR_TO_BOTTOM:
colpal_scroll_horizontal( ctx, cbs->value, 0);
break;
}
}
static void scroll_v_action( Widget w,
XtPointer client_data,
XtPointer call_data)
{
XmScrollBarCallbackStruct *cbs = (XmScrollBarCallbackStruct *) call_data;
ColPalCtx *ctx = (ColPalCtx *) ((ColPalWidget) client_data)->colpal.colpal_ctx;
Arg arg[20];
int i;
int maximum, slider, value, bottom;
// Calculate if position is bottom
i = 0;
XtSetArg( arg[i], XmNmaximum, &maximum);i++;
XtSetArg( arg[i], XmNsliderSize, &slider);i++;
XtSetArg( arg[i], XmNvalue, &value);i++;
XtGetValues( w, arg, i);
if ( slider + value == maximum)
bottom = 1;
else
bottom = 0;
switch( cbs->reason)
{
case XmCR_DRAG:
case XmCR_VALUE_CHANGED:
case XmCR_INCREMENT:
case XmCR_DECREMENT:
case XmCR_PAGE_INCREMENT:
case XmCR_PAGE_DECREMENT:
case XmCR_TO_TOP:
case XmCR_TO_BOTTOM:
colpal_scroll_vertical( ctx, cbs->value, bottom);
break;
}
}
static void scroll_callback( glow_sScroll *data)
{
colpalwidget_sScroll *scroll_data;
Arg arg[20];
int i;
scroll_data = (colpalwidget_sScroll *) data->scroll_data;
if ( data->total_width <= data->window_width)
{
if ( data->offset_x == 0)
data->total_width = data->window_width;
if ( scroll_data->scroll_h_managed)
{
// Remove horizontal scrollbar
}
}
else
{
if ( !scroll_data->scroll_h_managed)
{
// Insert horizontal scrollbar
}
}
if ( data->total_height <= data->window_height)
{
if ( data->offset_y == 0)
data->total_height = data->window_height;
if ( scroll_data->scroll_v_managed)
{
// Remove vertical scrollbar
}
}
else
{
if ( !scroll_data->scroll_v_managed)
{
// Insert vertical scrollbar
}
}
if ( data->offset_x < 0)
data->offset_x = 0;
if ( data->offset_y < 0)
data->offset_y = 0;
if ( data->total_height < data->window_height + data->offset_y)
data->total_height = data->window_height + data->offset_y;
if ( data->total_width < data->window_width + data->offset_x)
data->total_width = data->window_width + data->offset_x;
if ( data->window_width < 1)
data->window_width = 1;
if ( data->window_height < 1)
data->window_height = 1;
if ( scroll_data->scroll_h_managed)
{
i = 0;
XtSetArg( arg[i], XmNmaximum, data->total_width);i++;
XtSetArg( arg[i], XmNsliderSize, data->window_width);i++;
XtSetArg( arg[i], XmNvalue, data->offset_x);i++;
XtSetValues( scroll_data->scroll_h, arg, i);
}
if ( scroll_data->scroll_v_managed)
{
i = 0;
XtSetArg( arg[i], XmNmaximum, data->total_height);i++;
XtSetArg( arg[i], XmNsliderSize, data->window_height);i++;
XtSetArg( arg[i], XmNvalue, data->offset_y);i++;
XtSetValues( scroll_data->scroll_v, arg, i);
}
}
static XtGeometryResult GeometryManager(
Widget w,
XtWidgetGeometry *request,
XtWidgetGeometry *reply)
{
if ( request->request_mode & CWX)
w->core.x = request->x;
if ( request->request_mode & CWY)
w->core.y = request->y;
if ( request->request_mode & CWWidth)
w->core.width = request->width;
if ( request->request_mode & CWHeight)
w->core.height = request->height;
if ( request->request_mode & CWBorderWidth)
w->core.border_width = request->border_width;
return XtGeometryYes;
}
static void Initialize( Widget rec, Widget new_widget, ArgList arg, int *args)
{
/*
ColPalWidget w;
XtManageChild( new_widget);
w = (ColPalWidget) new_widget;
*/
}
static void Redisplay( Widget w, XEvent *event, Region region)
{
((GlowDrawXLib *)((ColPalCtx *)((ColPalWidget)w)->colpal.colpal_ctx)->gdraw)->event_handler( *event);
}
static void Notify( Widget w, XEvent *event)
{
((GlowDrawXLib *)((ColPalCtx *)((ColPalWidget)w)->colpal.colpal_ctx)->gdraw)->event_handler( *event);
}
static Boolean SetValues( Widget old, Widget request, Widget new_widget)
{
return 0;
}
static void Destroy( Widget w)
{
if ( ((ColPalWidget) w)->colpal.is_navigator)
return;
delete (GlowDraw *)((ColPalWidget)w)->colpal.draw_ctx;
}
static void Realize( Widget w, unsigned long *mask, XSetWindowAttributes *swa)
{
(* colpalWidgetClass->core_class.superclass->core_class.realize)
(w, mask, swa);
if ( ((ColPalWidget) w)->colpal.is_navigator) {
if ( !((ColPalWidget) w)->colpal.colpal_ctx) {
ColPalWidget main_colpal = (ColPalWidget) ((ColPalWidget) w)->colpal.main_colpal_widget;
((ColPalWidget) w)->colpal.colpal_ctx = main_colpal->colpal.colpal_ctx;
((ColPalWidget) w)->colpal.draw_ctx = main_colpal->colpal.draw_ctx;
((GlowDrawXLib *)((ColPalWidget) w)->colpal.draw_ctx)->init_nav( w);
}
}
else {
if ( !((ColPalWidget) w)->colpal.colpal_ctx) {
((ColPalWidget) w)->colpal.draw_ctx = new GlowDrawXLib( w, &((ColPalWidget) w)->colpal.colpal_ctx,
colpal_init_proc,
((ColPalWidget) w)->colpal.client_data,
glow_eCtxType_ColPal);
}
}
}
extern "C" Widget ColPalCreate(
Widget parent,
char *name,
ArgList args,
int argCount,
int (*init_proc)(GlowCtx *ctx, void *client_data),
void *client_data
)
{
ColPalWidget w;
w = (ColPalWidget) XtCreateWidget( name, colpalWidgetClass, parent, args,
argCount);
w->colpal.init_proc = init_proc;
w->colpal.colpal_ctx = 0;
w->colpal.is_navigator = 0;
w->colpal.client_data = client_data;
return (Widget) w;
}
extern "C" Widget ScrolledColPalCreate(
Widget parent,
char *name,
ArgList args,
int argCount,
int (*init_proc)(GlowCtx *ctx, void *client_data),
void *client_data,
Widget *colpal_w
)
{
Widget form, scroll_h, scroll_v;
ColPalWidget colpal;
Arg arg[20];
int i;
int scroll_width = 15;
form = XtCreateWidget( name, xmFormWidgetClass, parent, args,
argCount);
i = 0;
XtSetArg( arg[i], XmNorientation, XmHORIZONTAL); i++;
XtSetArg( arg[i], XmNrightAttachment, XmATTACH_FORM);i++;
XtSetArg( arg[i], XmNleftAttachment, XmATTACH_FORM);i++;
XtSetArg( arg[i], XmNbottomAttachment, XmATTACH_FORM);i++;
XtSetArg( arg[i], XmNheight, scroll_width);i++;
XtSetArg( arg[i], XmNrightOffset, scroll_width);i++;
scroll_h = XtCreateWidget( "scroll_horizontal", xmScrollBarWidgetClass,
form, arg, i);
XtManageChild( scroll_h);
i = 0;
XtSetArg( arg[i], XmNorientation, XmVERTICAL); i++;
XtSetArg( arg[i], XmNtopAttachment, XmATTACH_FORM);i++;
XtSetArg( arg[i], XmNrightAttachment, XmATTACH_FORM);i++;
XtSetArg( arg[i], XmNbottomAttachment, XmATTACH_FORM);i++;
XtSetArg( arg[i], XmNwidth, scroll_width);i++;
XtSetArg( arg[i], XmNbottomOffset, scroll_width);i++;
scroll_v = XtCreateWidget( "scroll_vertical", xmScrollBarWidgetClass,
form, arg, i);
XtManageChild( scroll_v);
i = 0;
XtSetArg( arg[i], XmNtopAttachment, XmATTACH_FORM);i++;
XtSetArg( arg[i], XmNleftAttachment, XmATTACH_FORM);i++;
XtSetArg( arg[i], XmNbottomAttachment, XmATTACH_WIDGET);i++;
XtSetArg( arg[i], XmNbottomWidget, scroll_h);i++;
XtSetArg( arg[i], XmNrightAttachment, XmATTACH_WIDGET);i++;
XtSetArg( arg[i], XmNrightWidget, scroll_v);i++;
/*
XtSetArg( arg[i], XmNbottomAttachment, XmATTACH_FORM);i++;
XtSetArg( arg[i], XmNrightAttachment, XmATTACH_FORM);i++;
*/
colpal = (ColPalWidget) ColPalCreate( form, "colpal", arg, i, init_proc, client_data);
XtManageChild( (Widget) colpal);
colpal->colpal.scroll_h = scroll_h;
colpal->colpal.scroll_v = scroll_v;
colpal->colpal.form = form;
*colpal_w = (Widget) colpal;
return (Widget) form;
}
Widget ColPalCreateNav( Widget parent, char *name, ArgList args, int argCount,
Widget main_colpal)
{
ColPalWidget w;
w = (ColPalWidget) XtCreateWidget( name, colpalWidgetClass, parent, args, argCount);
w->colpal.is_navigator = 1;
w->colpal.colpal_ctx = 0;
w->colpal.main_colpal_widget = main_colpal;
return (Widget) w;
}
void ColPalCtxFromWidget( Widget w, void **ctx)
{
*ctx = ((ColPalWidget) w)->colpal.colpal_ctx;
}
/*
* Proview $Id: glow_colpalwidget_motif.h,v 1.1 2007-01-04 08:08:00 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* 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 the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#ifndef colpal_widget_h
#define colpal_widget_h
#if defined __cplusplus
extern "C" {
#endif
/* X Toolkit is compiled with member alignment */
#if defined OS_VMS
#pragma member_alignment save
#pragma member_alignment
#endif
#include <X11/CoreP.h>
#include <X11/CompositeP.h>
typedef struct {
XmOffsetPtr *offset;
int reserved;
} colpalClassPart;
typedef struct {
CoreClassPart core_class;
CompositeClassPart composite_class;
colpalClassPart colpal_class;
} ColPalClassRec, *ColPalWidgetClass;
typedef struct {
void *colpal_ctx;
void *draw_ctx;
int (*init_proc)(GlowCtx *ctx, void *clien_data);
int is_navigator;
void *client_data;
Widget main_colpal_widget;
Widget scroll_h;
Widget scroll_v;
Widget form;
} ColPalPart;
typedef struct {
CorePart core;
CompositePart composite;
ColPalPart colpal;
} ColPalRec, *ColPalWidget;
Widget ColPalCreate(
Widget parent,
char *name,
ArgList args,
int argCount,
int (*init_proc)(GlowCtx *ctx, void *client_data),
void *client_data
);
Widget ColPalCreateNav( Widget parent, char *name, ArgList args, int argCount,
Widget main_colpal);
Widget ScrolledColPalCreate(
Widget parent,
char *name,
ArgList args,
int argCount,
int (*init_proc)(GlowCtx *ctx, void *client_data),
void *client_data,
Widget *colpal_w
);
void ColPalCtxFromWidget( Widget w, void **ctx);
#if defined OS_VMS
#pragma member_alignment restore
#endif
#if defined __cplusplus
}
#endif
#endif
/* /*
* Proview $Id: glow_curvewidget.cpp,v 1.2 2005-09-01 14:57:53 claes Exp $ * Proview $Id: glow_curvewidget_motif.cpp,v 1.1 2007-01-04 08:08:00 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB. * Copyright (C) 2005 SSAB Oxelsund AB.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -39,8 +39,8 @@ ...@@ -39,8 +39,8 @@
#include "glow.h" #include "glow.h"
#include "glow_curvectx.h" #include "glow_curvectx.h"
#include "glow_draw.h" #include "glow_draw_xlib.h"
#include "glow_curvewidget.h" #include "glow_curvewidget_motif.h"
typedef struct { typedef struct {
Widget curve; Widget curve;
...@@ -349,13 +349,12 @@ static void Initialize( Widget rec, Widget new_widget, ArgList arg, int *args) ...@@ -349,13 +349,12 @@ static void Initialize( Widget rec, Widget new_widget, ArgList arg, int *args)
static void Redisplay( Widget w, XEvent *event, Region region) static void Redisplay( Widget w, XEvent *event, Region region)
{ {
draw_event_handler( (CurveCtx *)((CurveWidget)w)->curve.curve_ctx, *event); ((GlowDrawXLib *)((CurveCtx *)((CurveWidget)w)->curve.curve_ctx)->gdraw)->event_handler( *event);
} }
static void Notify( Widget w, XEvent *event) static void Notify( Widget w, XEvent *event)
{ {
((GlowDrawXLib *)((CurveCtx *)((CurveWidget)w)->curve.curve_ctx)->gdraw)->event_handler( *event);
draw_event_handler( (CurveCtx *)((CurveWidget)w)->curve.curve_ctx, *event);
} }
static Boolean SetValues( Widget old, Widget request, Widget new_widget) static Boolean SetValues( Widget old, Widget request, Widget new_widget)
...@@ -367,7 +366,7 @@ static void Destroy( Widget w) ...@@ -367,7 +366,7 @@ static void Destroy( Widget w)
{ {
if ( ((CurveWidget) w)->curve.is_navigator) if ( ((CurveWidget) w)->curve.is_navigator)
return; return;
glow_draw_delete( (GlowCtx *)((CurveWidget)w)->curve.curve_ctx); delete (GlowDraw *)((CurveWidget)w)->curve.draw_ctx;
} }
static void Realize( Widget w, unsigned long *mask, XSetWindowAttributes *swa) static void Realize( Widget w, unsigned long *mask, XSetWindowAttributes *swa)
...@@ -383,14 +382,16 @@ static void Realize( Widget w, unsigned long *mask, XSetWindowAttributes *swa) ...@@ -383,14 +382,16 @@ static void Realize( Widget w, unsigned long *mask, XSetWindowAttributes *swa)
CurveWidget main_curve = (CurveWidget) ((CurveWidget) w)->curve.main_curve_widget; CurveWidget main_curve = (CurveWidget) ((CurveWidget) w)->curve.main_curve_widget;
((CurveWidget) w)->curve.curve_ctx = main_curve->curve.curve_ctx; ((CurveWidget) w)->curve.curve_ctx = main_curve->curve.curve_ctx;
glow_draw_init_nav( w, main_curve->curve.curve_ctx); ((CurveWidget) w)->curve.draw_ctx = main_curve->curve.draw_ctx;
((GlowDrawXLib *)((CurveWidget) w)->curve.draw_ctx)->init_nav( w);
} }
} }
else else
{ {
if ( !((CurveWidget) w)->curve.curve_ctx) if ( !((CurveWidget) w)->curve.curve_ctx)
{ {
glow_draw_init( w, &((CurveWidget) w)->curve.curve_ctx, ((CurveWidget) w)->curve.draw_ctx = new GlowDrawXLib( w,
&((CurveWidget) w)->curve.curve_ctx,
curve_init_proc, curve_init_proc,
((CurveWidget) w)->curve.client_data, ((CurveWidget) w)->curve.client_data,
glow_eCtxType_Curve); glow_eCtxType_Curve);
......
/* /*
* Proview $Id: glow_curvewidget.h,v 1.2 2005-09-01 14:57:53 claes Exp $ * Proview $Id: glow_curvewidget_motif.h,v 1.1 2007-01-04 08:08:00 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB. * Copyright (C) 2005 SSAB Oxelsund AB.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -47,6 +47,7 @@ typedef struct { ...@@ -47,6 +47,7 @@ typedef struct {
typedef struct { typedef struct {
void *curve_ctx; void *curve_ctx;
void *draw_ctx;
int (*init_proc)(GlowCtx *ctx, void *clien_data); int (*init_proc)(GlowCtx *ctx, void *clien_data);
int is_navigator; int is_navigator;
void *client_data; void *client_data;
......
/*
* Proview $Id: glow_draw_xlib.cpp,v 1.1 2007-01-04 08:08:00 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* 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 the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#include "glow_std.h"
using namespace std;
#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <Xm/Xm.h>
#include <Xm/XmP.h>
#include <Mrm/MrmPublic.h>
#include <Xm/Text.h>
#include <X11/Intrinsic.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/cursorfont.h>
#define XK_MISCELLANY
#include <X11/keysymdef.h>
#include "glow.h"
#include "glow_ctx.h"
#include "glow_browctx.h"
#include "glow_growctx.h"
#include "glow_colpalctx.h"
#include "glow_curvectx.h"
#include "glow_draw_xlib.h"
#include "glow_growwidget_motif.h"
#include "glow_colpalwidget_motif.h"
#include "glow_curvewidget_motif.h"
#include "glow_msg.h"
#if defined IMLIB
# if defined OS_LYNX
# define __NO_INCLUDE_WARN__ 1
# endif
# include <X11/extensions/shape.h>
# include <Imlib.h>
# if defined OS_LYNX
# undef __NO_INCLUDE_WARN__
# endif
#else
typedef void *ImlibData;
typedef void *ImlibImage;
#endif
#define max(Dragon,Eagle) ((Dragon) > (Eagle) ? (Dragon) : (Eagle))
#define min(Dragon,Eagle) ((Dragon) < (Eagle) ? (Dragon) : (Eagle))
#define DRAW_PRESS_PIX 9
typedef struct {
Widget w;
int x;
int y;
int width;
int height;
GlowArrayElem *node;
int number;
GlowCtx *ctx;
} draw_sAnnotData;
typedef struct {
GlowCtx *ctx;
void (*callback_func)( GlowCtx *ctx);
XtIntervalId timer_id;
} draw_sTimerCb;
typedef struct {
Pixmap pixmap[DRAW_PIXMAP_SIZE];
} draw_sPixmap;
typedef struct {
int red;
int green;
int blue;
} draw_sColor;
static char font_names[glow_eDrawFont__][DRAW_FONT_SIZE][80] = { {
"-*-Helvetica-Medium-R-Normal--8-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Bold-R-Normal--10-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Bold-R-Normal--12-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Bold-R-Normal--14-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Bold-R-Normal--14-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Bold-R-Normal--18-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Bold-R-Normal--18-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Bold-R-Normal--18-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Bold-R-Normal--24-*-*-*-P-*-ISO8859-1"
},{
"-*-Helvetica-Medium-R-Normal--8-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Medium-R-Normal--10-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Medium-R-Normal--12-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Medium-R-Normal--14-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Medium-R-Normal--14-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Medium-R-Normal--18-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Medium-R-Normal--18-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Medium-R-Normal--18-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Medium-R-Normal--24-*-*-*-P-*-ISO8859-1"
} };
static XEvent last_event;
static int glow_allocate_named_color( GlowDrawXLib *draw_ctx, char *named_color);
static int glow_allocate_color( GlowDrawXLib *draw_ctx, int rgb_red,
int rgb_green, int rgb_blue);
static void event_timer( GlowCtx *ctx, int time_ms);
static void cancel_event_timer(GlowCtx *ctx);
static void event_timer_cb( GlowCtx *ctx);
static int glow_read_color_file( char *filename, draw_sColor **color_array,
int *size);
static GC get_gc( GlowDrawXLib *draw_ctx, int i, int j)
{
if ( !draw_ctx->gcs[i][j]) {
XGCValues xgcv;
double r, g, b;
GlowColor::rgb_color( i, &r, &g, &b);
xgcv.foreground = glow_allocate_color( draw_ctx, int(r * 65535),
int(g * 65535), int(b * 65535));
xgcv.background = draw_ctx->background;
xgcv.cap_style = CapButt;
xgcv.fill_rule = WindingRule;
xgcv.line_width = j + 1;
draw_ctx->gcs[i][j] = XCreateGC( draw_ctx->display,
draw_ctx->m_wind.window, GCForeground | GCBackground | GCLineWidth | GCCapStyle
| GCFillRule, &xgcv);
}
return draw_ctx->gcs[i][j];
}
static int glow_create_cursor( GlowDrawXLib *draw_ctx)
{
/* Create some cursors */
/* Cross cursor */
draw_ctx->cursors[glow_eDrawCursor_CrossHair] =
XCreateFontCursor( draw_ctx->display, XC_crosshair);
draw_ctx->cursors[glow_eDrawCursor_DiamondCross] =
XCreateFontCursor( draw_ctx->display, XC_diamond_cross);
draw_ctx->cursors[glow_eDrawCursor_Hand] =
XCreateFontCursor( draw_ctx->display, XC_hand2);
draw_ctx->cursors[glow_eDrawCursor_BottomLeftCorner] =
XCreateFontCursor( draw_ctx->display, XC_bottom_left_corner);
draw_ctx->cursors[glow_eDrawCursor_BottomRightCorner] =
XCreateFontCursor( draw_ctx->display, XC_bottom_right_corner);
draw_ctx->cursors[glow_eDrawCursor_BottomSide] =
XCreateFontCursor( draw_ctx->display, XC_bottom_side);
draw_ctx->cursors[glow_eDrawCursor_TopLeftCorner] =
XCreateFontCursor( draw_ctx->display, XC_top_left_corner);
draw_ctx->cursors[glow_eDrawCursor_TopRightCorner] =
XCreateFontCursor( draw_ctx->display, XC_top_right_corner);
draw_ctx->cursors[glow_eDrawCursor_TopSide] =
XCreateFontCursor( draw_ctx->display, XC_top_side);
draw_ctx->cursors[glow_eDrawCursor_RightSide] =
XCreateFontCursor( draw_ctx->display, XC_right_side);
draw_ctx->cursors[glow_eDrawCursor_LeftSide] =
XCreateFontCursor( draw_ctx->display, XC_left_side);
return 1;
}
static int draw_free_gc( GlowDrawXLib *draw_ctx)
{
int i, j;
for ( i = 1; i < glow_eDrawCursor__ ; i++)
XFreeCursor( draw_ctx->display, draw_ctx->cursors[i]);
XFreeGC( draw_ctx->display, draw_ctx->gc_inverse);
for ( i = 0; i < glow_eDrawType__; i++)
{
for ( j = 0; j < DRAW_TYPE_SIZE; j++) {
if ( draw_ctx->gcs[i][j])
XFreeGC( draw_ctx->display, draw_ctx->gcs[i][j]);
}
}
for ( i = 0; i < glow_eDrawFont__; i++)
{
for ( j = 0; j < DRAW_FONT_SIZE; j++)
{
// XUnloadFont( draw_ctx->display, draw_ctx->font[i][j]);
XFreeFont( draw_ctx->display, draw_ctx->font_struct[i][j]);
}
}
return 1;
}
static int glow_create_gc( GlowDrawXLib *draw_ctx, Window window)
{
Font font;
XGCValues xgcv;
int i;
draw_sColor *color_array, *color_p;
int size, sts;
/* Inverse gc */
xgcv.background = XBlackPixelOfScreen(draw_ctx->screen);
xgcv.foreground = draw_ctx->background;
xgcv.cap_style = CapButt;
draw_ctx->gc_inverse = XCreateGC( draw_ctx->display,
window, GCForeground | GCBackground | GCCapStyle, &xgcv);
/* Black line gc */
xgcv.foreground = XBlackPixelOfScreen(draw_ctx->screen);
xgcv.background = draw_ctx->background;
xgcv.cap_style = CapButt;
for ( i = 0; i < DRAW_TYPE_SIZE; i++)
{
xgcv.line_width = i + 1;
draw_ctx->gcs[glow_eDrawType_Line][i] = XCreateGC( draw_ctx->display,
window, GCForeground | GCBackground | GCLineWidth | GCCapStyle, &xgcv);
}
/* Erase line gc */
xgcv.foreground = draw_ctx->background;
xgcv.background = draw_ctx->background;
xgcv.cap_style = CapButt;
xgcv.fill_rule = WindingRule;
for ( i = 0; i < DRAW_TYPE_SIZE; i++)
{
xgcv.line_width = i + 1;
draw_ctx->gcs[glow_eDrawType_LineErase][i] = XCreateGC( draw_ctx->display,
window, GCForeground | GCBackground | GCLineWidth | GCCapStyle
| GCFillRule, &xgcv);
}
/* Red line gc */
xgcv.foreground = glow_allocate_named_color( draw_ctx, "red");
xgcv.background = draw_ctx->background;
xgcv.cap_style = CapButt;
for ( i = 0; i < DRAW_TYPE_SIZE; i++)
{
xgcv.line_width = i + 1;
draw_ctx->gcs[glow_eDrawType_LineRed][i] = XCreateGC( draw_ctx->display,
window, GCForeground | GCBackground | GCLineWidth | GCCapStyle, &xgcv);
}
/* Gray line gc */
xgcv.foreground = glow_allocate_named_color( draw_ctx, "gray");
xgcv.background = draw_ctx->background;
xgcv.cap_style = CapButt;
xgcv.fill_rule = WindingRule;
for ( i = 0; i < DRAW_TYPE_SIZE; i++)
{
xgcv.line_width = i + 1;
draw_ctx->gcs[glow_eDrawType_LineGray][i] = XCreateGC( draw_ctx->display,
window, GCForeground | GCBackground | GCLineWidth | GCCapStyle
| GCFillRule, &xgcv);
}
sts = glow_read_color_file( "/home/claes/test/ge_colors.dat", &color_array, &size);
if ( ODD(sts))
{
color_p = color_array;
for ( int j = glow_eDrawType_Color4; j <= glow_eDrawType_Color300; j++)
{
if ( j - glow_eDrawType_Color4 >= size)
break;
xgcv.foreground = glow_allocate_color( draw_ctx, color_p->red,
color_p->green, color_p->blue);
xgcv.background = draw_ctx->background;
xgcv.cap_style = CapButt;
xgcv.fill_rule = WindingRule;
for ( i = 0; i < DRAW_TYPE_SIZE; i++)
{
xgcv.line_width = i + 1;
draw_ctx->gcs[j][i] = XCreateGC( draw_ctx->display,
window, GCForeground | GCBackground | GCLineWidth | GCCapStyle
| GCFillRule, &xgcv);
}
color_p++;
}
free( (char *) color_array);
}
/* Dashed line gc */
xgcv.foreground = XBlackPixelOfScreen(draw_ctx->screen);
xgcv.background = draw_ctx->background;
xgcv.line_style = LineOnOffDash;
xgcv.cap_style = CapButt;
xgcv.dash_offset = 0;
for ( i = 0; i < DRAW_TYPE_SIZE; i++)
{
xgcv.line_width = i + 1;
xgcv.dashes = 7 + i;
draw_ctx->gcs[glow_eDrawType_LineDashed][i] = XCreateGC( draw_ctx->display,
window,
GCForeground | GCBackground | GCLineWidth| GCLineStyle | GCDashOffset |
GCDashList | GCCapStyle, &xgcv);
}
/* Red dashed line gc */
xgcv.foreground = glow_allocate_named_color( draw_ctx, "red");
xgcv.background = draw_ctx->background;
xgcv.line_style = LineOnOffDash;
xgcv.cap_style = CapButt;
xgcv.dash_offset = 0;
for ( i = 0; i < DRAW_TYPE_SIZE; i++)
{
xgcv.line_width = i + 1;
xgcv.dashes = 7 + i;
draw_ctx->gcs[glow_eDrawType_LineDashedRed][i] = XCreateGC( draw_ctx->display,
window,
GCForeground | GCBackground | GCLineWidth| GCLineStyle | GCDashOffset |
GCDashList | GCCapStyle, &xgcv);
}
/* Text */
xgcv.foreground = XBlackPixelOfScreen(draw_ctx->screen);
xgcv.background = draw_ctx->background;
for ( i = 0; i < DRAW_TYPE_SIZE; i++)
{
draw_ctx->gcs[glow_eDrawType_TextHelvetica][i] = XCreateGC( draw_ctx->display,
window, GCForeground | GCBackground, &xgcv);
}
for ( i = 0; i < DRAW_TYPE_SIZE; i++)
{
draw_ctx->gcs[glow_eDrawType_TextHelveticaBold][i] = XCreateGC( draw_ctx->display,
window, GCForeground | GCBackground, &xgcv);
}
xgcv.foreground = draw_ctx->background;
xgcv.background = draw_ctx->background;
for ( i = 0; i < DRAW_TYPE_SIZE; i++)
{
draw_ctx->gcs[glow_eDrawType_TextHelveticaErase][i] = XCreateGC( draw_ctx->display,
window, GCForeground | GCBackground, &xgcv);
}
for ( i = 0; i < DRAW_TYPE_SIZE; i++)
{
draw_ctx->gcs[glow_eDrawType_TextHelveticaEraseBold][i] = XCreateGC( draw_ctx->display,
window, GCForeground | GCBackground, &xgcv);
}
for ( i = 0; i < DRAW_FONT_SIZE; i++)
{
font = XLoadFont( draw_ctx->display,
font_names[glow_eDrawFont_HelveticaBold][i]);
XSetFont( draw_ctx->display,
draw_ctx->gcs[glow_eDrawType_TextHelveticaBold][i], font);
XSetFont( draw_ctx->display,
draw_ctx->gcs[glow_eDrawType_TextHelveticaEraseBold][i], font);
draw_ctx->font[glow_eDrawFont_HelveticaBold][i] = font;
draw_ctx->font_struct[glow_eDrawFont_HelveticaBold][i] =
XQueryFont( draw_ctx->display, font);
}
for ( i = 0; i < DRAW_FONT_SIZE; i++)
{
font = XLoadFont( draw_ctx->display, font_names[glow_eDrawFont_Helvetica][i]);
XSetFont( draw_ctx->display,
draw_ctx->gcs[glow_eDrawType_TextHelvetica][i], font);
XSetFont( draw_ctx->display,
draw_ctx->gcs[glow_eDrawType_TextHelveticaErase][i], font);
draw_ctx->font[glow_eDrawFont_Helvetica][i] = font;
draw_ctx->font_struct[glow_eDrawFont_Helvetica][i] =
XQueryFont( draw_ctx->display, font);
}
return 1;
}
static int glow_allocate_named_color( GlowDrawXLib *draw_ctx, char *named_color)
{
XColor exact_color, screen_color;
Screen *screen;
Visual *visual;
screen = draw_ctx->screen;
visual = XDefaultVisualOfScreen( screen);
if ( visual->c_class == TrueColor ||
visual->c_class == PseudoColor ||
visual->c_class == DirectColor ||
visual->c_class == StaticColor)
{
if ( XAllocNamedColor( draw_ctx->display,
XDefaultColormapOfScreen( draw_ctx->screen),
named_color, &screen_color, &exact_color))
return screen_color.pixel;
else
printf( "** Color not allocated !\n");
return XBlackPixelOfScreen( draw_ctx->screen);
}
else
{
return XBlackPixelOfScreen( draw_ctx->screen);
}
}
static int glow_allocate_color( GlowDrawXLib *draw_ctx, int rgb_red,
int rgb_green, int rgb_blue)
{
XColor exact_color;
Screen *screen;
Visual *visual;
screen = draw_ctx->screen;
visual = XDefaultVisualOfScreen( screen);
if ( visual->c_class == TrueColor ||
visual->c_class == PseudoColor ||
visual->c_class == DirectColor ||
visual->c_class == StaticColor)
{
exact_color.red = rgb_red;
exact_color.green = rgb_green;
exact_color.blue = rgb_blue;
if ( XAllocColor( draw_ctx->display,
XDefaultColormapOfScreen( draw_ctx->screen),
&exact_color))
return exact_color.pixel;
else
printf( "** Color not allocated !\n");
return XBlackPixelOfScreen( draw_ctx->screen);
}
else
{
return XBlackPixelOfScreen( draw_ctx->screen);
}
}
GlowDrawXLib::~GlowDrawXLib()
{
ctx->set_nodraw();
if ( ctx->type() == glow_eCtxType_Grow)
delete (GrowCtx *)ctx;
else
delete ctx;
draw_free_gc( this);
if ( m_wind.buffer)
XFreePixmap( display, m_wind.buffer);
if ( m_wind.background_pixmap)
XFreePixmap( display, m_wind.background_pixmap);
if ( nav_wind.buffer)
XFreePixmap( display, nav_wind.buffer);
if ( nav_wind.background_pixmap)
XFreePixmap( display, nav_wind.background_pixmap);
}
int GlowDrawXLib::init_nav( Widget nav_widget)
{
nav_wind.toplevel = nav_widget;
nav_wind.window = XtWindow( nav_wind.toplevel);
// glow_create_gc( this, nav_wind.window);
ctx->no_nav = 0;
return 1;
}
GlowDrawXLib::GlowDrawXLib(
Widget toplevel,
void **glow_ctx,
int (*init_proc)(Widget w, GlowCtx *ctx, void *client_data),
void *client_data,
glow_eCtxType type)
: ef(0), background(0), original_background(0), timer_id(0), click_sensitivity(0)
{
int i;
Arg args[20];
memset( gcs, 0, sizeof(gcs));
memset( font, 0, sizeof(font));
memset( cursors, 0, sizeof(cursors));
if ( type == glow_eCtxType_Brow)
ctx = (GlowCtx *) new BrowCtx("Claes context", 20);
else if ( type == glow_eCtxType_Grow)
ctx = (GlowCtx *) new GrowCtx("Claes context", 20);
else if ( type == glow_eCtxType_ColPal)
ctx = (GlowCtx *) new ColPalCtx("Claes context", 20);
else if ( type == glow_eCtxType_Curve)
ctx = (GlowCtx *) new CurveCtx("Claes context", 20);
else
ctx = new GlowCtx("Claes context", 20);
*glow_ctx = (void *) ctx;
ctx->gdraw = this;
m_wind.toplevel = toplevel;
display = XtDisplay( m_wind.toplevel);
m_wind.window = XtWindow( m_wind.toplevel);
screen = XtScreen( m_wind.toplevel);
ctx->mw.window = &m_wind;
ctx->navw.window = &nav_wind;
i = 0;
XtSetArg(args[i],XmNbackground, &background); i++;
XtGetValues( m_wind.toplevel ,args,i);
original_background = background;
glow_create_gc( this, m_wind.window);
glow_create_cursor( this);
#if defined IMLIB
imlib = Imlib_init( display);
#endif
get_window_size( &ctx->mw, &ctx->mw.window_width, &ctx->mw.window_height);
create_buffer( &ctx->mw);
init_proc( toplevel, ctx, client_data);
}
int GlowDrawXLib::event_handler( XEvent event)
{
static int button_pressed = 0;
static int button_clicked = 0;
static int button_clicked_and_pressed = 0;
static int button1_pressed = 0;
static int button2_pressed = 0;
static int button3_pressed = 0;
static int last_press_x = 0;
static int last_press_y = 0;
// cout << "Event : button_pressed " << button_pressed << " clicked " <<
// button_clicked << " c&p " << button_clicked_and_pressed << endl;
if ( event.xany.window == m_wind.window) {
switch ( event.type) {
case KeyPress : {
KeySym keysym;
Modifiers mod;
XtTranslateKeycode( display, event.xkey.keycode, 0, &mod,
&keysym);
keysym &= 0xFFFF;
if ( (keysym >= 0x020 && keysym <= 0x20ac) ||
(keysym >= 0xFF80 && keysym <= 0xFFB9 && keysym != XK_KP_Enter && keysym != 0xFF44)) {
char buff;
XLookupString( &event.xkey, &buff, sizeof(buff), NULL, NULL);
if ( buff >= 0x020)
ctx->event_handler( glow_eEvent_Key_Ascii, 0, 0, (int)buff, 0);
else
ctx->event_handler( glow_eEvent_Key_CtrlAscii, 0, 0, (int)buff, 0);
}
else {
switch ( keysym) {
case XK_Return:
case XK_KP_Enter:
case 0xFF44: // XK_KP_Enter sometimes...
ctx->event_handler( glow_eEvent_Key_Return, 0, 0, 0, 0);
break;
case XK_Up:
ctx->event_handler( glow_eEvent_Key_Up, 0, 0, 0, 0);
break;
case XK_Down:
ctx->event_handler( glow_eEvent_Key_Down, 0, 0, 0, 0);
break;
case XK_Right:
ctx->event_handler( glow_eEvent_Key_Right, 0, 0, 0, 0);
break;
case XK_Left:
ctx->event_handler( glow_eEvent_Key_Left, 0, 0, 0, 0);
break;
case XK_Page_Up:
ctx->event_handler( glow_eEvent_Key_PageUp, 0, 0, 0, 0);
break;
case XK_Page_Down:
ctx->event_handler( glow_eEvent_Key_PageDown, 0, 0, 0, 0);
break;
case XK_Delete:
case XK_BackSpace:
ctx->event_handler( glow_eEvent_Key_BackSpace, 0, 0, 0, 0);
break;
case XK_KP_F1:
ctx->event_handler( glow_eEvent_Key_PF1, 0, 0, 0, 0);
break;
case XK_KP_F2:
ctx->event_handler( glow_eEvent_Key_PF2, 0, 0, 0, 0);
break;
case XK_KP_F3:
ctx->event_handler( glow_eEvent_Key_PF3, 0, 0, 0, 0);
break;
case XK_KP_F4:
ctx->event_handler( glow_eEvent_Key_PF4, 0, 0, 0, 0);
break;
case XK_Cancel:
ctx->event_handler( glow_eEvent_Key_Escape, 0, 0, 0, 0);
break;
case XK_Tab:
if ( event.xkey.state & ShiftMask)
ctx->event_handler( glow_eEvent_Key_ShiftTab, 0, 0, 0, 0);
else
ctx->event_handler( glow_eEvent_Key_Tab, 0, 0, 0, 0);
break;
default:
;
}
}
break;
}
case ButtonPress :
// cout << "Button press event" << endl;
// printf( "-- Button event: (%d,%d) button: %d time:%d\n", event.xbutton.x,
// event.xbutton.y, event.xbutton.button, event.xbutton.time);
// XSetInputFocus( display, m_wind.window,
// RevertToNone, CurrentTime);
switch ( event.xbutton.button) {
case Button1:
ctx->event_handler( glow_eEvent_MB1Down, event.xbutton.x, event.xbutton.y, 0, 0);
if ( click_sensitivity & glow_mSensitivity_MB1Click &&
!(click_sensitivity & glow_mSensitivity_MB1DoubleClick) &&
!(click_sensitivity & glow_mSensitivity_MB1Press)) {
memcpy( &last_event, &event, sizeof(event));
button_pressed = 0;
button_clicked = 1;
last_press_x = event.xbutton.x;
last_press_y = event.xbutton.y;
return 1;
}
else if ( !(click_sensitivity & glow_mSensitivity_MB1Click) &&
!(click_sensitivity & glow_mSensitivity_MB1DoubleClick) &&
click_sensitivity & glow_mSensitivity_MB1Press) {
memcpy( &last_event, &event, sizeof(event));
button_pressed = 1;
button_clicked = 0;
last_press_x = event.xbutton.x;
last_press_y = event.xbutton.y;
}
break;
case Button3:
ctx->event_handler( glow_eEvent_MB3Down, event.xbutton.x, event.xbutton.y, 0, 0);
if ( click_sensitivity & glow_mSensitivity_MB3Press &&
!(click_sensitivity & glow_mSensitivity_MB3DoubleClick) &&
!(click_sensitivity & glow_mSensitivity_MB3Click)) {
ctx->event_handler( glow_eEvent_MB3Press,
event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
return 1;
}
else if ( click_sensitivity & glow_mSensitivity_MB3Click &&
!(click_sensitivity & glow_mSensitivity_MB3DoubleClick) &&
!(click_sensitivity & glow_mSensitivity_MB3Press))
{
memcpy( &last_event, &event, sizeof(event));
button_pressed = 0;
button_clicked = 1;
last_press_x = event.xbutton.x;
last_press_y = event.xbutton.y;
return 1;
}
break;
}
/* Detect press or click event */
if ( button_clicked) {
/* Wait for release */
button_clicked_and_pressed = 1;
cancel_event_timer( ctx);
button_clicked = 0;
memcpy( &last_event, &event, sizeof(event));
button_pressed = event.xbutton.button;
last_press_x = event.xbutton.x;
last_press_y = event.xbutton.y;
event_timer(ctx, 200);
return 1;
}
if ( !button_pressed ) {
memcpy( &last_event, &event, sizeof(event));
button_pressed = event.xbutton.button;
last_press_x = event.xbutton.x;
last_press_y = event.xbutton.y;
event_timer(ctx, 200);
return 1;
}
else {
// cout << "Button press detected" << endl;
/* Press event, callback from timer */
button_pressed = 0;
button_clicked_and_pressed = 0;
switch ( event.xbutton.button) {
case Button1:
button1_pressed = 1;
if ( (event.xbutton.state & ShiftMask) &&
!(event.xbutton.state & ControlMask)) {
ctx->event_handler( glow_eEvent_MB1PressShift, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
else if ( !(event.xbutton.state & ShiftMask) &&
(event.xbutton.state & ControlMask)) {
ctx->event_handler( glow_eEvent_MB1PressCtrl, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
else if ( (event.xbutton.state & ShiftMask) &&
(event.xbutton.state & ControlMask)) {
ctx->event_handler( glow_eEvent_MB1PressShiftCtrl, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
else {
ctx->event_handler( glow_eEvent_MB1Press, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
break;
case Button2:
button2_pressed = 1;
if ( (event.xbutton.state & ShiftMask) &&
!(event.xbutton.state & ControlMask)) {
ctx->event_handler( glow_eEvent_MB2PressShift, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
else if ( !(event.xbutton.state & ShiftMask) &&
(event.xbutton.state & ControlMask)) {
ctx->event_handler( glow_eEvent_MB2PressShift, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
else if ( (event.xbutton.state & ShiftMask) &&
(event.xbutton.state & ControlMask)) {
ctx->event_handler( glow_eEvent_MB2PressShiftCtrl, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
else {
ctx->event_handler( glow_eEvent_MB2Press, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
break;
case Button3:
button3_pressed = 1;
#if 0
if ( (event.xbutton.state & ShiftMask) &&
!(event.xbutton.state & ControlMask))
ctx->event_handler( glow_eEvent_MB3PressShift, event.xbutton.x, event.xbutton.y, 0, 0);
else if ( !(event.xbutton.state & ShiftMask) &&
(event.xbutton.state & ControlMask))
ctx->event_handler( glow_eEvent_MB3PressShift, event.xbutton.x, event.xbutton.y, 0, 0);
else if ( (event.xbutton.state & ShiftMask) &&
(event.xbutton.state & ControlMask))
ctx->event_handler( glow_eEvent_MB3PressShiftCtrl, event.xbutton.x, event.xbutton.y, 0, 0);
else
#endif
ctx->event_handler( glow_eEvent_MB3Press, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
break;
}
}
break;
case ButtonRelease:
button1_pressed = 0;
button2_pressed = 0;
button3_pressed = 0;
// cout << "Button release event" << endl;
switch ( event.xbutton.button) {
case Button1:
ctx->event_handler( glow_eEvent_MB1Up, event.xbutton.x, event.xbutton.y, 0, 0);
break;
}
if ( ! button_pressed ) {
if ( button_clicked) {
/* Button click, callback from timer */
// cout << "Button click detected state " << event.xbutton.state << endl;
button_clicked = 0;
switch ( event.xbutton.button) {
case Button1:
if ( (event.xbutton.state & ShiftMask) &&
!(event.xbutton.state & ControlMask)) {
ctx->event_handler( glow_eEvent_MB1ClickShift, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
else if ( !(event.xbutton.state & ShiftMask) &&
(event.xbutton.state & ControlMask)) {
ctx->event_handler( glow_eEvent_MB1ClickCtrl, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
else if ( (event.xbutton.state & ShiftMask) &&
(event.xbutton.state & ControlMask)) {
ctx->event_handler( glow_eEvent_MB1ClickShiftCtrl, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
else {
ctx->event_handler( glow_eEvent_MB1Click, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
break;
case Button2:
if ( (event.xbutton.state & ShiftMask) &&
!(event.xbutton.state & ControlMask)) {
ctx->event_handler( glow_eEvent_MB2ClickShift, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
else if ( !(event.xbutton.state & ShiftMask) &&
(event.xbutton.state & ControlMask)) {
ctx->event_handler( glow_eEvent_MB2ClickCtrl, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
else if ( (event.xbutton.state & ShiftMask) &&
(event.xbutton.state & ControlMask)) {
ctx->event_handler( glow_eEvent_MB2ClickShiftCtrl, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
else {
ctx->event_handler( glow_eEvent_MB2Click, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
break;
case Button3:
#if 0
if ( (event.xbutton.state & ShiftMask) &&
!(event.xbutton.state & ControlMask))
ctx->event_handler( glow_eEvent_MB3ClickShift, event.xbutton.x, event.xbutton.y, 0, 0);
else if ( !(event.xbutton.state & ShiftMask) &&
(event.xbutton.state & ControlMask))
ctx->event_handler( glow_eEvent_MB3ClickCtrl, event.xbutton.x, event.xbutton.y, 0, 0);
else if ( (event.xbutton.state & ShiftMask) &&
(event.xbutton.state & ControlMask))
ctx->event_handler( glow_eEvent_MB3ClickShiftCtrl, event.xbutton.x, event.xbutton.y, 0, 0);
else
#endif
ctx->event_handler( glow_eEvent_MB3Click, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
break;
}
}
else {
/* Button release */
// cout << "Button release detected" << endl;
ctx->event_handler( glow_eEvent_ButtonRelease, event.xbutton.x, event.xbutton.y, 0, 0);
}
}
else {
/* Button click */
cancel_event_timer( ctx);
if ( ! button_clicked_and_pressed) {
// cout << "Button first click detected" << endl;
/* wait for button double click */
memcpy( &last_event, &event, sizeof(event));
button_clicked = 1;
event_timer( ctx, 200);
button_pressed = 0;
return 1;
}
else {
/* Button double click */
// cout << "Button double click detected" << endl;
cancel_event_timer( ctx);
button_clicked = 0;
button_pressed = 0;
button_clicked_and_pressed = 0;
switch ( event.xbutton.button) {
case Button1:
if ( (event.xbutton.state & ShiftMask) &&
!(event.xbutton.state & ControlMask)) {
ctx->event_handler( glow_eEvent_MB1DoubleClickShift, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
else if ( !(event.xbutton.state & ShiftMask) &&
(event.xbutton.state & ControlMask)) {
ctx->event_handler( glow_eEvent_MB1DoubleClickCtrl, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
else if ( (event.xbutton.state & ShiftMask) &&
(event.xbutton.state & ControlMask)) {
ctx->event_handler( glow_eEvent_MB1DoubleClickShiftCtrl, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
else {
ctx->event_handler( glow_eEvent_MB1DoubleClick, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
break;
case Button2:
if ( (event.xbutton.state & ShiftMask) &&
!(event.xbutton.state & ControlMask)) {
ctx->event_handler( glow_eEvent_MB2DoubleClickShift, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
else if ( !(event.xbutton.state & ShiftMask) &&
(event.xbutton.state & ControlMask)) {
ctx->event_handler( glow_eEvent_MB2DoubleClickCtrl, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
else if ( (event.xbutton.state & ShiftMask) &&
(event.xbutton.state & ControlMask)) {
ctx->event_handler( glow_eEvent_MB2DoubleClickShiftCtrl, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
else {
ctx->event_handler( glow_eEvent_MB2DoubleClick, event.xbutton.x, event.xbutton.y, 0, 0);
click_sensitivity = 0;
}
break;
case Button3:
#if 0
if ( (event.xbutton.state & ShiftMask) &&
!(event.xbutton.state & ControlMask))
ctx->event_handler( glow_eEvent_MB3DoubleClickShift, event.xbutton.x, event.xbutton.y, 0, 0);
else if ( !(event.xbutton.state & ShiftMask) &&
(event.xbutton.state & ControlMask))
ctx->event_handler( glow_eEvent_MB3DoubleClickCtrl, event.xbutton.x, event.xbutton.y, 0, 0);
else if ( (event.xbutton.state & ShiftMask) &&
(event.xbutton.state & ControlMask))
ctx->event_handler( glow_eEvent_MB3DoubleClickShiftCtrl, event.xbutton.x, event.xbutton.y, 0, 0);
else
ctx->event_handler( glow_eEvent_MB3DoubleClick, event.xbutton.x, event.xbutton.y, 0, 0);
#endif
break;
}
}
}
break;
case Expose:
// printf( "-- Expose event.. x: %d, y: %d, w: %d, h: %d\n",
// event.xexpose.x,
// event.xexpose.y, event.xexpose.width, event.xexpose.height);
ctx->event_handler( glow_eEvent_Exposure, event.xexpose.x,
event.xexpose.y, event.xexpose.width, event.xexpose.height);
break;
case VisibilityNotify :
switch ( event.xvisibility.state) {
case VisibilityUnobscured:
ctx->event_handler( glow_eEvent_VisibilityUnobscured, 0, 0, 0, 0);
break;
default:
ctx->event_handler( glow_eEvent_VisibilityObscured, 0, 0, 0, 0);
break;
}
break;
case MotionNotify:
// printf( "-- Button1 motion event: (%d,%d)\n", event.xbutton.x,
// event.xbutton.y);
if ( button3_pressed) {
button3_pressed = 0;
button_pressed = 0;
button_clicked_and_pressed = 0;
}
if ( button_pressed &&
(abs( event.xbutton.x - last_press_x) > DRAW_PRESS_PIX ||
abs( event.xbutton.y - last_press_y) > DRAW_PRESS_PIX)) {
// printf( "Press: x %d last_x %d\n", event.xbutton.x, last_press_x);
// printf( " y %d last_y %d\n", event.xbutton.y, last_press_y);
event.xbutton.x = last_press_x;
event.xbutton.y = last_press_y;
/* Button press */
cancel_event_timer( ctx);
switch ( button_pressed) {
case Button1:
button1_pressed = 1;
if ( (event.xbutton.state & ShiftMask) &&
!(event.xbutton.state & ControlMask))
ctx->event_handler( glow_eEvent_MB1PressShift, event.xbutton.x, event.xbutton.y, 0, 0);
else if ( !(event.xbutton.state & ShiftMask) &&
(event.xbutton.state & ControlMask))
ctx->event_handler( glow_eEvent_MB1PressCtrl, event.xbutton.x, event.xbutton.y, 0, 0);
else if ( (event.xbutton.state & ShiftMask) &&
(event.xbutton.state & ControlMask))
ctx->event_handler( glow_eEvent_MB1PressShiftCtrl, event.xbutton.x, event.xbutton.y, 0, 0);
else
ctx->event_handler( glow_eEvent_MB1Press, event.xbutton.x, event.xbutton.y, 0, 0);
break;
case Button2:
button2_pressed = 1;
if ( (event.xbutton.state & ShiftMask) &&
!(event.xbutton.state & ControlMask))
ctx->event_handler( glow_eEvent_MB2PressShift, event.xbutton.x, event.xbutton.y, 0, 0);
else if ( !(event.xbutton.state & ShiftMask) &&
(event.xbutton.state & ControlMask))
ctx->event_handler( glow_eEvent_MB2PressShift, event.xbutton.x, event.xbutton.y, 0, 0);
else if ( (event.xbutton.state & ShiftMask) &&
(event.xbutton.state & ControlMask))
ctx->event_handler( glow_eEvent_MB2PressShiftCtrl, event.xbutton.x, event.xbutton.y, 0, 0);
else
ctx->event_handler( glow_eEvent_MB2Press, event.xbutton.x, event.xbutton.y, 0, 0);
break;
case Button3:
button3_pressed = 1;
ctx->event_handler( glow_eEvent_MB3Press, event.xbutton.x, event.xbutton.y, 0, 0);
break;
}
button_pressed = 0;
button_clicked_and_pressed = 0;
}
if ( button1_pressed || button2_pressed || button3_pressed)
ctx->event_handler( glow_eEvent_ButtonMotion, event.xbutton.x, event.xbutton.y, 0, 0);
else
ctx->event_handler( glow_eEvent_CursorMotion, event.xbutton.x, event.xbutton.y, 0, 0);
break;
case EnterNotify:
// printf( "-- Enter event: (%d,%d)\n", event.xbutton.x,
// event.xbutton.y);
ctx->event_handler( glow_eEvent_Enter, event.xbutton.x, event.xbutton.y, 0, 0);
break;
case LeaveNotify:
// printf( "-- Leave event: (%d,%d)\n", event.xbutton.x,
// event.xbutton.y);
ctx->event_handler( glow_eEvent_Leave, event.xbutton.x, event.xbutton.y, 0, 0);
break;
case MapNotify:
// printf( "-- Enter event: (%d,%d)\n", event.xbutton.x,
// event.xbutton.y);
ctx->event_handler( glow_eEvent_Map, 0, 0, 0, 0);
break;
case UnmapNotify:
// printf( "-- Enter event: (%d,%d)\n", event.xbutton.x,
// event.xbutton.y);
ctx->event_handler( glow_eEvent_Unmap, 0, 0, 0, 0);
break;
case FocusIn:
// printf( "-- Focus in event\n");
break;
default:
// printf("-- Other event: %d \n", event.type);
break;
}
}
else if ( event.xany.window == nav_wind.window) {
switch ( event.type) {
case ButtonPress :
// printf( "-- Button event nav: (%d,%d) button: %d\n", event.xbutton.x,
// event.xbutton.y, event.xbutton.button);
switch ( event.xbutton.button) {
case Button1:
button1_pressed = 1;
ctx->event_handler_nav( glow_eEvent_MB1Press, event.xbutton.x, event.xbutton.y);
break;
case Button2:
button2_pressed = 1;
ctx->event_handler_nav( glow_eEvent_MB2Press, event.xbutton.x, event.xbutton.y);
break;
case Button3:
button3_pressed = 1;
break;
}
break;
case ButtonRelease :
// printf( "-- Button release event nav: (%d,%d)\n", event.xbutton.x,
// event.xbutton.y);
switch ( event.xbutton.button) {
case Button1:
button1_pressed = 0;
break;
case Button2:
button2_pressed = 0;
break;
case Button3:
button3_pressed = 0;
break;
}
ctx->event_handler_nav( glow_eEvent_ButtonRelease, event.xbutton.x, event.xbutton.y);
break;
case Expose:
// printf( "-- Navigator expose event..\n" );
ctx->event_handler_nav( glow_eEvent_Exposure, event.xbutton.x, event.xbutton.y);
break;
case MotionNotify:
// printf( "-- Button1 motion event nav: (%d,%d)\n", event.xbutton.x,
// event.xbutton.y);
if ( button1_pressed || button2_pressed || button3_pressed)
ctx->event_handler_nav( glow_eEvent_ButtonMotion, event.xbutton.x, event.xbutton.y);
else
ctx->event_handler_nav( glow_eEvent_CursorMotion, event.xbutton.x, event.xbutton.y);
break;
}
}
XFlush( display);
return 1;
}
void GlowDrawXLib::enable_event( glow_eEvent event,
glow_eEventType event_type,
int (*event_cb)(GlowCtx *ctx, glow_tEvent event))
{
ctx->enable_event( event, event_type, event_cb);
}
int GlowDrawXLib::rect( GlowWind *wind, int x, int y, int width, int height,
glow_eDrawType gc_type, int idx, int highlight)
{
if ( ctx->nodraw) return 1;
DrawWindXLib *w = (DrawWindXLib *) wind->window;
if ( gc_type == glow_eDrawType_LineGray && highlight)
gc_type = glow_eDrawType_Line;
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type+highlight, idx));
if ( !w->draw_buffer_only)
XDrawRectangle( display, w->window,
get_gc( this, gc_type+highlight, idx),
x, y, width, height);
if ( w->double_buffer_on)
XDrawRectangle( display, w->buffer,
get_gc( this, gc_type+highlight, idx),
x, y, width, height);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type+highlight, idx));
return 1;
}
int GlowDrawXLib::rect_erase( GlowWind *wind, int x, int y, int width, int height,
int idx)
{
if ( ctx->nodraw) return 1;
DrawWindXLib *w = (DrawWindXLib *) wind->window;
if ( w->clip_on)
set_clip( w, get_gc( this, glow_eDrawType_LineErase, idx));
if ( !w->draw_buffer_only)
XDrawRectangle( display, w->window,
get_gc( this, glow_eDrawType_LineErase, idx),
x, y, width, height);
if ( w->double_buffer_on)
XDrawRectangle( display, w->buffer,
get_gc( this, glow_eDrawType_LineErase, idx),
x, y, width, height);
if ( w->clip_on)
reset_clip( w, get_gc( this, glow_eDrawType_LineErase, idx));
return 1;
}
int GlowDrawXLib::arrow( GlowWind *wind, int x1, int y1, int x2, int y2,
int x3, int y3,
glow_eDrawType gc_type, int idx, int highlight)
{
if ( ctx->nodraw) return 1;
XPoint p[4] = {{x1,y1},{x2,y2},{x3,y3},{x1,y1}};
DrawWindXLib *w = (DrawWindXLib *) wind->window;
if ( gc_type == glow_eDrawType_LineGray && highlight)
gc_type = glow_eDrawType_Line;
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type+highlight, idx));
if ( !w->draw_buffer_only)
XFillPolygon( display, w->window,
get_gc( this, gc_type+highlight, idx), p, 4, Convex, CoordModeOrigin);
if ( w->double_buffer_on)
XFillPolygon( display, w->buffer,
get_gc( this, gc_type+highlight, idx), p, 4, Convex, CoordModeOrigin);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type+highlight, idx));
return 1;
}
int GlowDrawXLib::arrow_erase( GlowWind *wind, int x1, int y1, int x2, int y2,
int x3, int y3,
int idx)
{
if ( ctx->nodraw) return 1;
XPoint p[4] = {{x1,y1},{x2,y2},{x3,y3},{x1,y1}};
DrawWindXLib *w = (DrawWindXLib *) wind->window;
if ( w->clip_on)
set_clip( w, get_gc( this, glow_eDrawType_LineErase, idx));
if ( !w->draw_buffer_only)
XFillPolygon( display, w->window,
get_gc( this, glow_eDrawType_LineErase, idx),
p, 4, Convex, CoordModeOrigin);
if ( w->double_buffer_on)
XFillPolygon( display, w->buffer,
get_gc( this, glow_eDrawType_LineErase, idx),
p, 4, Convex, CoordModeOrigin);
if ( w->clip_on)
reset_clip( w, get_gc( this, glow_eDrawType_LineErase, idx));
return 1;
}
int GlowDrawXLib::arc( GlowWind *wind, int x, int y, int width, int height,
int angel1, int angel2,
glow_eDrawType gc_type, int idx, int highlight)
{
if ( ctx->nodraw) return 1;
DrawWindXLib *w = (DrawWindXLib *) wind->window;
if ( gc_type == glow_eDrawType_LineGray && highlight)
gc_type = glow_eDrawType_Line;
// Fix for highlight for connections in grow
if ( highlight && ctx->type() == glow_eCtxType_Grow)
gc_type = glow_eDrawType_LineHighlight;
// if ( width < 35 && height < 35) {width++; height++;} // This looks good in Reflexion X ...
if ( angel1 >= 360)
angel1 = angel1 - angel1 / 360 * 360;
else if ( angel1 < 0)
angel1 = angel1 + ( -angel1 / 360 + 1) * 360;
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type+highlight, idx));
if ( !w->draw_buffer_only)
XDrawArc( display, w->window,
get_gc( this, gc_type+highlight, idx),
x, y, width, height, angel1*64, angel2*64);
if ( w->double_buffer_on)
XDrawArc( display, w->buffer,
get_gc( this, gc_type+highlight, idx),
x, y, width, height, angel1*64, angel2*64);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type+highlight, idx));
return 1;
}
int GlowDrawXLib::fill_arc( GlowWind *wind, int x, int y, int width, int height,
int angel1, int angel2, glow_eDrawType gc_type, int highlight)
{
if ( ctx->nodraw) return 1;
DrawWindXLib *w = (DrawWindXLib *) wind->window;
if ( gc_type == glow_eDrawType_LineGray && highlight)
gc_type = glow_eDrawType_LineRed;
if ( angel1 >= 360)
angel1 = angel1 - angel1 / 360 * 360;
else if ( angel1 < 0)
angel1 = angel1 + ( -angel1 / 360 + 1) * 360;
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type+highlight, 0));
if ( !w->draw_buffer_only)
XFillArc( display, w->window,
get_gc( this, gc_type+highlight, 0),
x, y, width, height, angel1*64, angel2*64);
if ( w->double_buffer_on)
XFillArc( display, w->buffer,
get_gc( this, gc_type+highlight, 0),
x, y, width, height, angel1*64, angel2*64);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type+highlight, 0));
return 1;
}
int GlowDrawXLib::arc_erase( GlowWind *wind, int x, int y, int width, int height,
int angel1, int angel2,
int idx)
{
if ( ctx->nodraw) return 1;
DrawWindXLib *w = (DrawWindXLib *) wind->window;
// if ( width < 35 && height < 35) {width++; height++;} // This looks good in Reflexion X ...
if ( angel1 >= 360)
angel1 = angel1 - angel1 / 360 * 360;
else if ( angel1 < 0)
angel1 = angel1 + ( -angel1 / 360 + 1) * 360;
if ( w->clip_on)
set_clip( w, get_gc( this, glow_eDrawType_LineErase, idx));
if ( !w->draw_buffer_only)
XDrawArc( display, w->window,
get_gc( this, glow_eDrawType_LineErase, idx),
x, y, width, height, angel1*64, angel2*64);
if ( w->double_buffer_on)
XDrawArc( display, w->buffer,
get_gc( this, glow_eDrawType_LineErase, idx),
x, y, width, height, angel1*64, angel2*64);
if ( w->clip_on)
reset_clip( w, get_gc( this, glow_eDrawType_LineErase, idx));
return 1;
}
int GlowDrawXLib::line( GlowWind *wind, int x1, int y1, int x2, int y2,
glow_eDrawType gc_type, int idx, int highlight)
{
if ( ctx->nodraw) return 1;
DrawWindXLib *w = (DrawWindXLib *) wind->window;
// Fix for highlight for connections in grow
if ( highlight && ctx->type() == glow_eCtxType_Grow)
gc_type = glow_eDrawType_LineHighlight;
if ( gc_type == glow_eDrawType_LineGray && highlight)
gc_type = glow_eDrawType_Line;
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type+highlight, idx));
if ( !w->draw_buffer_only)
XDrawLine( display, w->window,
get_gc( this, gc_type+highlight, idx),
x1, y1, x2, y2);
if ( w->double_buffer_on)
XDrawLine( display, w->buffer,
get_gc( this, gc_type+highlight, idx),
x1, y1, x2, y2);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type+highlight, idx));
return 1;
}
int GlowDrawXLib::line_dashed( GlowWind *wind, int x1, int y1, int x2, int y2,
glow_eDrawType gc_type, int idx, int highlight, glow_eLineType line_type)
{
XGCValues xgcv;
if ( ctx->nodraw) return 1;
DrawWindXLib *w = (DrawWindXLib *) wind->window;
// Fix for highlight for connections in grow
if ( highlight && ctx->type() == glow_eCtxType_Grow)
gc_type = glow_eDrawType_LineHighlight;
if ( gc_type == glow_eDrawType_LineGray && highlight)
gc_type = glow_eDrawType_Line;
xgcv.line_style = LineOnOffDash;
xgcv.dash_offset = 0;
switch ( line_type) {
case glow_eLineType_Dashed1:
xgcv.dashes = 1 + idx;
XChangeGC( display, get_gc( this, gc_type+highlight, idx),
GCLineStyle | GCDashOffset | GCDashList, &xgcv);
break;
case glow_eLineType_Dashed2:
xgcv.dashes = 1 + 2 * idx;
XChangeGC( display, get_gc( this, gc_type+highlight, idx),
GCLineStyle | GCDashOffset | GCDashList, &xgcv);
break;
case glow_eLineType_Dashed3:
xgcv.dashes = 1 + 3 * idx;
XChangeGC( display, get_gc( this, gc_type+highlight, idx),
GCLineStyle | GCDashOffset | GCDashList, &xgcv);
break;
case glow_eLineType_Dotted: {
static char list[4];
list[0] = 1 + idx;
list[1] = 1 + 4 * idx;
XSetDashes( display, get_gc( this, gc_type+highlight, idx),
0, list, 2);
XChangeGC( display, get_gc( this, gc_type+highlight, idx),
GCLineStyle | GCDashOffset, &xgcv);
break;
}
case glow_eLineType_DotDashed1: {
static char list[4];
list[0] = 1 + 3 * idx;
list[1] = 1 + 2 * idx;
list[2] = 1 + idx;
list[3] = 1 + 2 * idx;
XSetDashes( display, get_gc( this, gc_type+highlight, idx),
0, list, 4);
XChangeGC( display, get_gc( this, gc_type+highlight, idx),
GCLineStyle | GCDashOffset, &xgcv);
break;
}
case glow_eLineType_DotDashed2: {
static char list[4];
list[0] = 1 + 6 * idx;
list[1] = 1 + 3 * idx;
list[2] = 1 + idx;
list[3] = 1 + 3 * idx;
XSetDashes( display, get_gc( this, gc_type+highlight, idx),
0, list, 4);
XChangeGC( display, get_gc( this, gc_type+highlight, idx),
GCLineStyle | GCDashOffset, &xgcv);
break;
}
default: ;
}
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type+highlight, idx));
if ( !w->draw_buffer_only)
XDrawLine( display, w->window,
get_gc( this, gc_type+highlight, idx),
x1, y1, x2, y2);
if ( w->double_buffer_on)
XDrawLine( display, w->buffer,
get_gc( this, gc_type+highlight, idx),
x1, y1, x2, y2);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type+highlight, idx));
xgcv.line_style = LineSolid;
XChangeGC( display, get_gc( this, gc_type+highlight, idx),
GCLineStyle, &xgcv);
return 1;
}
int GlowDrawXLib::line_erase( GlowWind *wind, int x1, int y1, int x2, int y2,
int idx)
{
if ( ctx->nodraw) return 1;
DrawWindXLib *w = (DrawWindXLib *) wind->window;
if ( w->clip_on)
set_clip( w, get_gc( this, glow_eDrawType_LineErase, idx));
if ( !w->draw_buffer_only)
XDrawLine( display, w->window,
get_gc( this, glow_eDrawType_LineErase, idx),
x1, y1, x2, y2);
if ( w->double_buffer_on)
XDrawLine( display, w->buffer,
get_gc( this, glow_eDrawType_LineErase, idx),
x1, y1, x2, y2);
if ( w->clip_on)
reset_clip( w, get_gc( this, glow_eDrawType_LineErase, idx));
return 1;
}
int GlowDrawXLib::polyline( GlowWind *wind, glow_sPointX *points, int point_cnt,
glow_eDrawType gc_type, int idx, int highlight)
{
if ( ctx->nodraw) return 1;
DrawWindXLib *w = (DrawWindXLib *) wind->window;
if ( gc_type == glow_eDrawType_LineGray && highlight)
gc_type = glow_eDrawType_Line;
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type+highlight, idx));
if ( !w->draw_buffer_only)
XDrawLines( display, w->window,
get_gc( this, gc_type+highlight, idx),
(XPoint *) points, point_cnt, CoordModeOrigin);
if ( w->double_buffer_on)
XDrawLines( display, w->buffer,
get_gc( this, gc_type+highlight, idx),
(XPoint *) points, point_cnt, CoordModeOrigin);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type+highlight, idx));
return 1;
}
int GlowDrawXLib::fill_polyline( GlowWind *wind, glow_sPointX *points, int point_cnt,
glow_eDrawType gc_type, int highlight)
{
if ( ctx->nodraw) return 1;
DrawWindXLib *w = (DrawWindXLib *) wind->window;
if ( gc_type == glow_eDrawType_LineGray && highlight)
gc_type = glow_eDrawType_Line;
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type+highlight, 0));
if ( !w->draw_buffer_only)
XFillPolygon( display, w->window,
get_gc( this, gc_type+highlight, 0), (XPoint *) points, point_cnt,
Nonconvex, CoordModeOrigin);
if ( w->double_buffer_on)
XFillPolygon( display, w->buffer,
get_gc( this, gc_type+highlight, 0), (XPoint *) points, point_cnt,
Nonconvex, CoordModeOrigin);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type+highlight, 0));
return 1;
}
int GlowDrawXLib::polyline_erase( GlowWind *wind, glow_sPointX *points, int point_cnt,
int idx)
{
if ( ctx->nodraw) return 1;
DrawWindXLib *w = (DrawWindXLib *) wind->window;
if ( w->clip_on)
set_clip( w, get_gc( this, glow_eDrawType_LineErase, idx));
if ( !w->draw_buffer_only)
XDrawLines( display, w->window,
get_gc( this, glow_eDrawType_LineErase, idx),
(XPoint *)points, point_cnt, CoordModeOrigin);
if ( w->double_buffer_on)
XDrawLines( display, w->buffer,
get_gc( this, glow_eDrawType_LineErase, idx),
(XPoint *)points, point_cnt, CoordModeOrigin);
if ( w->clip_on)
reset_clip( w, get_gc( this, glow_eDrawType_LineErase, idx));
return 1;
}
int GlowDrawXLib::text( GlowWind *wind, int x, int y, char *text, int len,
glow_eDrawType gc_type, glow_eDrawType color, int idx, int highlight, int line)
{
if ( ctx->nodraw) return 1;
DrawWindXLib *w = (DrawWindXLib *) wind->window;
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type, idx));
if ( color != glow_eDrawType_Line) {
XGCValues xgcv;
XGetGCValues( display, get_gc( this, color, 0),
GCForeground, &xgcv);
XChangeGC( display, get_gc( this, gc_type, idx),
GCForeground, &xgcv);
}
if ( !w->draw_buffer_only)
XDrawString( display, w->window,
get_gc( this, gc_type, idx),
x, y, text, len);
if ( w->double_buffer_on)
XDrawString( display, w->buffer,
get_gc( this, gc_type, idx),
x, y, text, len);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type, idx));
if ( color != glow_eDrawType_Line) {
XGCValues xgcv;
XGetGCValues( display, get_gc( this, glow_eDrawType_Line, 0),
GCForeground, &xgcv);
XChangeGC( display, get_gc( this, gc_type, idx),
GCForeground, &xgcv);
}
return 1;
}
int GlowDrawXLib::text_cursor( GlowWind *wind, int x, int y, char *text, int len,
glow_eDrawType gc_type, glow_eDrawType color, int idx, int highlight, int pos)
{
if ( ctx->nodraw) return 1;
DrawWindXLib *w = (DrawWindXLib *) wind->window;
int width, height, descent;
get_text_extent( text, pos, gc_type, idx,
&width, &height, &descent);
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type, idx));
if ( !w->draw_buffer_only) {
XDrawLine( display, w->window,
get_gc( this, color, 1),
x + width, y + descent, x + width, y - height + descent);
}
if ( w->double_buffer_on) {
XDrawLine( display, w->buffer,
get_gc( this, color, 1),
x + width, y + descent, x + width, y - height + descent);
}
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type, idx));
return 1;
}
int GlowDrawXLib::text_erase( GlowWind *wind, int x, int y, char *text, int len,
glow_eDrawType gc_type, int idx, int line)
{
if ( ctx->nodraw) return 1;
DrawWindXLib *w = (DrawWindXLib *) wind->window;
if ( gc_type == glow_eDrawType_TextHelvetica)
gc_type = glow_eDrawType_TextHelveticaErase;
else if ( gc_type == glow_eDrawType_TextHelveticaBold)
gc_type = glow_eDrawType_TextHelveticaEraseBold;
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type, idx));
if ( !w->draw_buffer_only)
XDrawString( display, w->window,
get_gc( this, gc_type, idx),
x, y, text, len);
if ( w->double_buffer_on)
XDrawString( display, w->buffer,
get_gc( this, gc_type, idx),
x, y, text, len);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type, idx));
return 1;
}
int GlowDrawXLib::pixmaps_create( GlowWind *wind, glow_sPixmapData *pixmap_data,
void **pixmaps)
{
DrawWindXLib *w = (DrawWindXLib *) wind->window;
draw_sPixmap *pms;
glow_sPixmapDataElem *prev_pdata, *pdata = (glow_sPixmapDataElem *)pixmap_data;
int i;
pms = (draw_sPixmap *) calloc( 1, sizeof( *pms));
for ( i = 0; i < DRAW_PIXMAP_SIZE; i++)
{
if ( i == 0 ||
(i > 0 && pdata->bits != prev_pdata->bits))
pms->pixmap[i] = XCreateBitmapFromData( display,
w->window, pdata->bits, pdata->width,
pdata->height);
else
pms->pixmap[i] = pms->pixmap[i-1];
prev_pdata = pdata;
pdata++;
}
*pixmaps = (void *) pms;
return 1;
}
void GlowDrawXLib::pixmaps_delete( GlowWind *wind, void *pixmaps)
{
draw_sPixmap *pms;
int i;
pms = (draw_sPixmap *) pixmaps;
for ( i = 0; i < DRAW_PIXMAP_SIZE; i++)
{
if ( i == 0 ||
(i > 0 && pms->pixmap[i] != pms->pixmap[i-1]))
XFreePixmap( display, pms->pixmap[i]);
}
free ( pixmaps);
}
int GlowDrawXLib::pixmap( GlowWind *wind, int x, int y, glow_sPixmapData *pixmap_data,
void *pixmaps, glow_eDrawType gc_type, int idx, int highlight, int line)
{
DrawWindXLib *w = (DrawWindXLib *) wind->window;
draw_sPixmap *pms;
glow_sPixmapDataElem *pdata = (glow_sPixmapDataElem *)pixmap_data + idx;
if ( ctx->nodraw) return 1;
pms = (draw_sPixmap *) pixmaps;
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type, idx));
if ( !w->draw_buffer_only)
XCopyPlane( display, pms->pixmap[idx], w->window,
get_gc( this, gc_type, idx),
0, 0, pdata->width, pdata->height, x, y, 1);
if ( w->double_buffer_on)
XCopyPlane( display, pms->pixmap[idx], w->buffer,
get_gc( this, gc_type, idx),
0, 0, pdata->width, pdata->height, x, y, 1);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type, idx));
return 1;
}
int GlowDrawXLib::pixmap_inverse( GlowWind *wind, int x, int y, glow_sPixmapData *pixmap_data,
void *pixmaps, glow_eDrawType gc_type, int idx, int line)
{
DrawWindXLib *w = (DrawWindXLib *) wind->window;
draw_sPixmap *pms;
glow_sPixmapDataElem *pdata = (glow_sPixmapDataElem *)pixmap_data + idx;
pms = (draw_sPixmap *) pixmaps;
if ( w->clip_on)
set_clip( w, gc_inverse);
if ( !w->draw_buffer_only)
XCopyPlane( display, pms->pixmap[idx], w->window,
gc_inverse,
0, 0, pdata->width, pdata->height, x, y, 1);
if ( w->double_buffer_on)
XCopyPlane( display, pms->pixmap[idx], w->buffer,
gc_inverse,
0, 0, pdata->width, pdata->height, x, y, 1);
if ( w->clip_on)
reset_clip( w, gc_inverse);
return 1;
}
int GlowDrawXLib::pixmap_erase( GlowWind *wind, int x, int y, glow_sPixmapData *pixmap_data,
void *pixmaps, glow_eDrawType gc_type, int idx, int line)
{
DrawWindXLib *w = (DrawWindXLib *) wind->window;
glow_sPixmapDataElem *pdata = (glow_sPixmapDataElem *)pixmap_data + idx;
if ( ctx->nodraw) return 1;
// Intersection with clipmask should be calculated here...
if ( !w->draw_buffer_only)
XClearArea( display, w->window,
x, y, pdata->width, pdata->height, False);
if ( w->double_buffer_on)
XClearArea( display, w->buffer,
x, y, pdata->width, pdata->height, False);
return 1;
}
int GlowDrawXLib::image( GlowWind *wind, int x, int y, int width, int height,
glow_tImImage image, glow_tPixmap pixmap, glow_tPixmap clip_mask)
{
DrawWindXLib *w = (DrawWindXLib *) wind->window;
if ( ctx->nodraw) return 1;
if ( width == 0 || height == 0)
return 1;
if ( clip_mask)
set_image_clip_mask( clip_mask, x, y);
else if ( w->clip_on)
set_clip( w, get_gc( this, glow_eDrawType_Line, 0));
if ( !w->draw_buffer_only)
XCopyArea( display, (Pixmap)pixmap, w->window,
get_gc( this, glow_eDrawType_Line, 0),
0, 0, width, height, x, y);
if ( w->double_buffer_on)
XCopyArea( display, (Pixmap)pixmap, w->buffer,
get_gc( this, glow_eDrawType_Line, 0),
0, 0, width, height, x, y);
if ( clip_mask)
reset_image_clip_mask();
else if ( w->clip_on)
reset_clip( w, get_gc( this, glow_eDrawType_Line, 0));
return 1;
}
int GlowDrawXLib::fill_rect( GlowWind *wind, int x, int y, int w, int h,
glow_eDrawType gc_type)
{
DrawWindXLib *ww = (DrawWindXLib *) wind->window;
XPoint p[5] = {{x,y},{x+w,y},{x+w,y+h},{x,y+h},{x,y}};
if ( ctx->nodraw) return 1;
if ( ww->clip_on)
set_clip( ww, get_gc( this, gc_type, 0));
if ( !ww->draw_buffer_only)
XFillPolygon( display, ww->window,
get_gc( this, gc_type, 0), p, 5, Convex, CoordModeOrigin);
if ( ww->double_buffer_on)
XFillPolygon( display, ww->buffer,
get_gc( this, gc_type, 0), p, 5, Convex, CoordModeOrigin);
if ( ww->clip_on)
reset_clip( ww, get_gc( this, gc_type, 0));
return 1;
}
void GlowDrawXLib::clear( GlowWind *wind)
{
if ( ctx->nodraw) return;
DrawWindXLib *w = (DrawWindXLib *) wind->window;
if ( !w->double_buffer_on)
XClearWindow( display, w->window);
else
buffer_background( w);
}
void GlowDrawXLib::copy_buffer( GlowWind *wind,
int ll_x, int ll_y, int ur_x, int ur_y)
{
if ( ctx->nodraw) return;
DrawWindXLib *w = (DrawWindXLib *) wind->window;
int x0 = min( ll_x, ur_x);
int x1 = max( ll_x, ur_x);
int y0 = min( ll_y, ur_y);
int y1 = max( ll_y, ur_y);
XCopyArea( display, w->buffer, w->window,
get_gc( this, glow_eDrawType_Line, 0),
x0, y0, x1 - x0, y1 - y0, x0, y0);
}
void GlowDrawXLib::get_window_size( GlowWind *wind, int *width, int *height)
{
DrawWindXLib *w = (DrawWindXLib *) wind->window;
XWindowAttributes attr;
XGetWindowAttributes( display, w->window, &attr);
*width = attr.width;
*height = attr.height;
}
void GlowDrawXLib::set_window_size( GlowWind *wind, int width, int height)
{
DrawWindXLib *w = (DrawWindXLib *) wind->window;
XWindowChanges xwc;
if ( !w->window) return;
xwc.width = width;
xwc.height = height;
XConfigureWindow( display, w->window, CWWidth | CWHeight,
&xwc);
}
static void draw_timer_cb( draw_sTimerCb *timer_cb)
{
GlowDrawXLib *draw_ctx = (GlowDrawXLib *) timer_cb->ctx->gdraw;
(timer_cb->callback_func)(timer_cb->ctx);
XFlush( draw_ctx->display);
free( timer_cb);
}
static void event_timer_cb( GlowCtx *ctx)
{
// printf( "Timer callback\n");
GlowDrawXLib *draw_ctx = (GlowDrawXLib *) ctx->gdraw;
draw_ctx->timer_id = 0;
draw_ctx->event_handler( last_event);
}
static void cancel_event_timer( GlowCtx *ctx)
{
GlowDrawXLib *draw_ctx = (GlowDrawXLib *) ctx->gdraw;
if ( draw_ctx->timer_id) {
XtRemoveTimeOut( draw_ctx->timer_id);
draw_ctx->timer_id = 0;
}
// printf( "Timer removed\n");
// sys$cantim( ctx, 0);
}
static void event_timer( GlowCtx *ctx, int time_ms)
{
// $DESCRIPTOR (timeunitdsc, "0 0:0:0.1"); /* 0.1 second units */
// int tmo[2], tmptime[2];
// int sts;
GlowDrawXLib *draw_ctx = (GlowDrawXLib *) ctx->gdraw;
// sts = sys$bintim (&timeunitdsc, &tmo);
// lib$mult_delta_time (
// &time_ms, /* multiplier */
// &tmo); /* delta_time (modified) */
// sys$gettim (&tmptime);
// lib$add_times (&tmo, &tmptime, &tmo);
// sts = sys$setimr( draw_ctx->ef, tmo, event_timer_cb, ctx, 0);
// printf( "Add timer\n");
draw_ctx->timer_id = XtAppAddTimeOut(
XtWidgetToApplicationContext(draw_ctx->m_wind.toplevel) ,time_ms,
(XtTimerCallbackProc)event_timer_cb, ctx);
}
void GlowDrawXLib::set_timer( GlowCtx *gctx, int time_ms,
void (*callback_func)( GlowCtx *ctx), void **id)
{
draw_sTimerCb *timer_cb;
// $DESCRIPTOR (timeunitdsc, "0 0:0:0.3"); /* 0.1 second units */
// int tmo[2], tmptime[2];
// int sts;
// sts = sys$bintim (&timeunitdsc, &tmo);
// sys$gettim (&tmptime);
// lib$add_times (&tmo, &tmptime, &tmo);
timer_cb = (draw_sTimerCb *) calloc( 1, sizeof(draw_sTimerCb));
timer_cb->ctx = gctx;
timer_cb->callback_func = callback_func;
timer_cb->timer_id = XtAppAddTimeOut(
XtWidgetToApplicationContext( m_wind.toplevel) ,time_ms,
(XtTimerCallbackProc)draw_timer_cb, timer_cb);
// sts = sys$setimr( 1, tmo, draw_timer_cb, timer_cb, 0);
*id = (void *)timer_cb;
}
void GlowDrawXLib::remove_timer( void *id)
{
XtRemoveTimeOut( ((draw_sTimerCb *)id)->timer_id);
// sys$cantim( id, 0);
free( (char *) id);
}
void GlowDrawXLib::set_cursor( GlowWind *wind, glow_eDrawCursor cursor)
{
DrawWindXLib *w = (DrawWindXLib *) wind->window;
if ( !w->window) return;
if ( cursor == glow_eDrawCursor_Normal)
XUndefineCursor( display, w->window);
else
XDefineCursor( display, w->window, cursors[cursor]);
XFlush( display);
}
int GlowDrawXLib::get_text_extent( char *text, int len,
glow_eDrawType gc_type, int idx,
int *width, int *height, int *descent)
{
int text_direction, text_ascent, text_descent;
XCharStruct char_struct;
glow_eDrawFont font_idx;
switch( gc_type) {
case glow_eDrawType_TextHelvetica:
case glow_eDrawType_TextHelveticaErase:
font_idx = glow_eDrawFont_Helvetica;
break;
case glow_eDrawType_TextHelveticaBold:
case glow_eDrawType_TextHelveticaEraseBold:
font_idx = glow_eDrawFont_HelveticaBold;
break;
default:
*width = 0;
*height = 0;
return 0;
}
XTextExtents( font_struct[font_idx][idx], text, len,
&text_direction, &text_ascent, &text_descent, &char_struct);
*height = font_struct[font_idx][idx]->ascent +
font_struct[font_idx][idx]->descent;
*descent = font_struct[font_idx][idx]->descent;
*width = char_struct.width;
return 1;
}
void GlowDrawXLib::copy_area( GlowWind *wind, int x, int y)
{
DrawWindXLib *w = (DrawWindXLib *) wind->window;
GC gc;
if ( ctx->nodraw) return;
int window_width, window_height;
if ( &ctx->mw == wind) {
window_width = ctx->mw.window_width;
window_height = ctx->mw.window_height;
}
else {
window_width = ctx->navw.window_width;
window_height = ctx->navw.window_height;
}
gc = get_gc( this, glow_eDrawType_Line, 3);
if ( x >= 0 && y >= 0) {
XCopyArea( display, w->window, w->window, gc,
0, 0, window_width-x, window_height-y, x, y);
if ( !w->double_buffer_on) {
if ( x)
XClearArea( display, w->window, 0, 0,
x, window_height, 0);
if ( y)
XClearArea( display, w->window, x, 0,
window_width, y, 0);
}
else {
XCopyArea( display, w->buffer, w->buffer, gc,
0, 0, window_width-x, window_height-y, x, y);
if ( x)
XFillRectangle( display, w->buffer,
get_gc( this, glow_eDrawType_LineErase, 0),
0, 0, x, window_height);
if ( y)
XFillRectangle( display, w->buffer,
get_gc( this, glow_eDrawType_LineErase, 0),
x, 0, window_width, y);
}
}
else if ( x <= 0 && y <= 0)
{
XCopyArea( display, w->window, w->window, gc,
-x, -y, window_width+x, window_height+y, 0, 0);
if ( !w->double_buffer_on) {
if ( x)
XClearArea( display, w->window,
window_width+x, 0, window_width, window_height, 0);
if ( y)
XClearArea( display, w->window,
0, window_height+y, window_width+x, window_height, 0);
}
else {
XCopyArea( display, w->buffer, w->buffer, gc,
-x, -y, window_width+x, window_height+y, 0, 0);
if ( x)
XFillRectangle( display, w->buffer,
get_gc( this, glow_eDrawType_LineErase, 0),
window_width+x, 0, window_width, window_height);
if ( y)
XFillRectangle( display, w->buffer,
get_gc( this, glow_eDrawType_LineErase, 0),
0, window_height+y, window_width+x, window_height);
}
}
else if ( x <= 0 && y >= 0)
{
XCopyArea( display, w->window, w->window, gc,
-x, 0, window_width+x, window_height-y, 0, y);
if ( !w->double_buffer_on) {
if ( x)
XClearArea( display, w->window,
window_width+x, 0, window_width, window_height, 0);
if ( y)
XClearArea( display, w->window,
0, 0, window_width+x, y, 0);
}
else {
XCopyArea( display, w->buffer, w->buffer, gc,
-x, 0, window_width+x, window_height-y, 0, y);
if ( x)
XFillRectangle( display, w->buffer,
get_gc( this, glow_eDrawType_LineErase, 0),
window_width+x, 0, window_width, window_height);
if ( y)
XFillRectangle( display, w->buffer,
get_gc( this, glow_eDrawType_LineErase, 0),
0, 0, window_width+x, y);
}
}
else
{
XCopyArea( display, w->window, w->window, gc,
0, -y, window_width-x, window_height+y, x, 0);
if ( !w->double_buffer_on) {
if ( x)
XClearArea( display, w->window,
0, 0, x, window_height, 0);
if ( y)
XClearArea( display, w->window,
x, window_height+y, window_width, window_height, 0);
}
else {
XCopyArea( display, w->buffer, w->buffer, gc,
0, -y, window_width-x, window_height+y, x, 0);
if ( x)
XFillRectangle( display, w->buffer,
get_gc( this, glow_eDrawType_LineErase, 0),
0, 0, x, window_height);
if ( y)
XFillRectangle( display, w->buffer,
get_gc( this, glow_eDrawType_LineErase, 0),
x, window_height+y, window_width, window_height);
}
}
}
void GlowDrawXLib::clear_area( GlowWind *wind, int ll_x, int ur_x, int ll_y, int ur_y)
{
if ( ctx->nodraw) return;
DrawWindXLib *w = (DrawWindXLib *) wind->window;
XClearArea( display, w->window, ll_x, ll_y, ur_x - ll_x,
ur_y - ll_y, 0);
}
void GlowDrawXLib::set_inputfocus( GlowWind *wind)
{
DrawWindXLib *w = (DrawWindXLib *) wind->window;
XSetInputFocus( display, w->window,
RevertToNone, CurrentTime);
}
static int glow_read_color_file( char *filename, draw_sColor **color_array,
int *size)
{
char line[80];
draw_sColor *color_p;
ifstream fp;
int nr;
int line_cnt;
float f_red, f_green, f_blue;
if ( !check_file( filename))
{
return 0;
#if 0
// No color-file exist, use default values
double r, g, b;
printf( "** Using default color palette\n");
*color_array = (draw_sColor *) calloc( 300, sizeof( draw_sColor));
*size = 0;
color_p = *color_array;
for ( int i = 3; i < 300; i++)
{
GlowColor::rgb_color( i, &r, &g, &b);
color_p->red = int( r * 65535);
color_p->green = int( g * 65535);
color_p->blue = int( b * 65535);
color_p++;
(*size)++;
}
#endif
}
else
{
printf( "** Opening color file %s\n", filename);
fp.open( filename);
#ifndef OS_VMS
if ( !fp)
return GLOW__FILEOPEN;
#endif
*color_array = (draw_sColor *) calloc( 300, sizeof( draw_sColor));
*size = 0;
line_cnt = 0;
color_p = *color_array;
while ( *size < 300)
{
fp.getline( line, sizeof( line));
if ( line[0] == 0)
break;
line_cnt++;
if ( line[0] == '!' || line[0] == '#')
continue;
nr = sscanf( line, "%f %f %f", &f_red, &f_green, &f_blue);
if ( nr != 3)
printf( "** Syntax error in file %s, line %d", filename, line_cnt);
else
{
color_p->red = int( f_red * 65535);
color_p->green = int( f_green * 65535);
color_p->blue = int( f_blue * 65535);
color_p++;
(*size)++;
}
}
fp.close();
}
return 1;
}
void GlowDrawXLib::set_background( GlowWind *wind, glow_eDrawType drawtype,
glow_tPixmap pixmap, int pixmap_width, int pixmap_height)
{
DrawWindXLib *w = (DrawWindXLib *) wind->window;
XGCValues xgcv;
Arg args[20];
int i;
int sts;
sts = XGetGCValues( display, get_gc( this, drawtype, 0),
GCForeground, &xgcv);
if ( !sts)
{
cout << "** Error getting background gc" << endl;
return;
}
background = xgcv.foreground;
// Change erase gcs
xgcv.foreground = background;
xgcv.background = background;
for ( i = 0; i < DRAW_TYPE_SIZE; i++) {
XChangeGC( display, get_gc( this, glow_eDrawType_LineErase, i),
GCForeground | GCBackground, &xgcv);
XChangeGC( display, get_gc( this, glow_eDrawType_TextHelveticaErase, i),
GCForeground | GCBackground, &xgcv);
XChangeGC( display, get_gc( this, glow_eDrawType_TextHelveticaEraseBold, i),
GCForeground | GCBackground, &xgcv);
}
if ( ! pixmap) {
i = 0;
XtSetArg(args[i],XmNbackground, background); i++;
XtSetValues( w->toplevel, args, i);
if ( w->buffer)
buffer_background( w);
}
else {
if ( w->background_pixmap)
XFreePixmap( display, (Pixmap)w->background_pixmap);
w->background_pixmap = (Pixmap)pixmap;
w->background_pixmap_width = pixmap_width;
w->background_pixmap_height = pixmap_height;
XSetWindowBackgroundPixmap( display, w->window, (Pixmap)pixmap);
if ( w->buffer)
buffer_background( w);
}
}
void GlowDrawXLib::reset_background( GlowWind *wind)
{
DrawWindXLib *w = (DrawWindXLib *) wind->window;
XGCValues xgcv;
Arg args[20];
int i;
i = 0;
background = original_background;
XtSetArg(args[i],XmNbackground, background); i++;
XtSetValues( w->toplevel, args, i);
// Change erase gcs
xgcv.foreground = background;
xgcv.background = background;
for ( i = 0; i < DRAW_TYPE_SIZE; i++) {
XChangeGC( display, get_gc( this, glow_eDrawType_LineErase, i),
GCForeground | GCBackground, &xgcv);
XChangeGC( display, get_gc( this, glow_eDrawType_TextHelveticaErase, i),
GCForeground | GCBackground, &xgcv);
XChangeGC( display, get_gc( this, glow_eDrawType_TextHelveticaEraseBold, i),
GCForeground | GCBackground, &xgcv);
}
}
void GlowDrawXLib::set_clip( DrawWind *wind, GC gc)
{
DrawWindXLib *w = (DrawWindXLib *) wind;
XSetClipRectangles( display, gc, 0, 0,
&w->clip_rectangle[w->clip_cnt-1], 1, Unsorted);
}
void GlowDrawXLib::reset_clip( DrawWind *w, GC gc)
{
XSetClipMask( display, gc, None);
}
void GlowDrawXLib::set_image_clip_mask( glow_tPixmap pixmap, int x, int y)
{
XSetClipMask( display, get_gc( this, glow_eDrawType_Line, 0),
(Pixmap)pixmap);
XSetClipOrigin( display, get_gc( this, glow_eDrawType_Line, 0), x, y);
}
void GlowDrawXLib::reset_image_clip_mask()
{
XSetClipMask( display, get_gc( this, glow_eDrawType_Line, 0),
None);
XSetClipOrigin( display, get_gc( this, glow_eDrawType_Line, 0), 0, 0);
}
int GlowDrawXLib::set_clip_rectangle( GlowWind *wind,
int ll_x, int ll_y, int ur_x, int ur_y)
{
DrawWindXLib *w = (DrawWindXLib *) wind->window;
if ( w->clip_cnt >= DRAW_CLIP_SIZE) {
printf("** Draw clip refuced\n");
return 0;
}
int x0, x1, y0, y1;
if ( w->clip_cnt == 0) {
x0 = min( ll_x, ur_x);
x1 = max( ll_x, ur_x);
y0 = min( ll_y, ur_y);
y1 = max( ll_y, ur_y);
}
else {
x0 = min( ll_x, ur_x);
x1 = max( ll_x, ur_x);
y0 = min( ll_y, ur_y);
y1 = max( ll_y, ur_y);
x0 = max( x0, w->clip_rectangle[w->clip_cnt-1].x);
x1 = min( x1, w->clip_rectangle[w->clip_cnt-1].x +
w->clip_rectangle[w->clip_cnt-1].width);
y0 = max( y0, w->clip_rectangle[w->clip_cnt-1].y);
y1 = min( y1, w->clip_rectangle[w->clip_cnt-1].y +
w->clip_rectangle[w->clip_cnt-1].height);
if ( x0 > x1)
x0 = x1;
if ( y0 > y1)
y0 = y1;
}
w->clip_rectangle[w->clip_cnt].x = x0;
w->clip_rectangle[w->clip_cnt].y = y0;
w->clip_rectangle[w->clip_cnt].width = x1 - x0;
w->clip_rectangle[w->clip_cnt].height = y1 - y0;
w->clip_cnt++;
w->clip_on = 1;
return 1;
}
void GlowDrawXLib::reset_clip_rectangle( GlowWind *wind)
{
DrawWindXLib *w = (DrawWindXLib *) wind->window;
if ( w->clip_cnt == 0) {
printf( "** Draw clip mismatch\n");
return;
}
w->clip_cnt--;
if ( w->clip_cnt == 0)
w->clip_on = 0;
}
int GlowDrawXLib::clip_level( GlowWind *wind)
{
DrawWindXLib *w = (DrawWindXLib *) wind->window;
return w->clip_cnt;
}
int GlowDrawXLib::draw_point( GlowWind *wind, int x1, int y1, glow_eDrawType gc_type)
{
DrawWindXLib *w = (DrawWindXLib *) wind->window;
if ( ctx->nodraw) return 1;
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type, 0));
XDrawPoint( display, w->window,
get_gc( this, gc_type, 0),
x1, y1);
if ( w->double_buffer_on)
XDrawPoint( display, w->buffer,
get_gc( this, gc_type, 0),
x1, y1);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type, 0));
return 1;
}
int GlowDrawXLib::draw_points( GlowWind *wind, glow_sPointX *points, int point_num,
glow_eDrawType gc_type)
{
if ( ctx->nodraw) return 1;
DrawWindXLib *w = (DrawWindXLib *) wind->window;
if ( w->clip_on)
set_clip( w, get_gc( this, gc_type, 0));
XDrawPoints( display, w->window,
get_gc( this, gc_type, 0),
(XPoint *) points, point_num, CoordModeOrigin);
if ( w->clip_on)
reset_clip( w, get_gc( this, gc_type, 0));
return 1;
}
void GlowDrawXLib::set_click_sensitivity( GlowWind *wind, int value)
{
click_sensitivity = value;
}
void GlowDrawXLib::draw_background( GlowWind *wind, int x, int y, int w, int h)
{
DrawWindXLib *ww = (DrawWindXLib *) wind->window;
XClearArea( display, ww->window, x, y, w, h, False);
}
int GlowDrawXLib::create_buffer( GlowWind *wind)
{
DrawWindXLib *w = (DrawWindXLib *) wind->window;
int depth;
int window_width, window_height;
if ( &ctx->mw == wind) {
window_width = ctx->mw.window_width;
window_height = ctx->mw.window_height;
}
else {
window_width = ctx->navw.window_width;
window_height = ctx->navw.window_height;
}
if ( !w->double_buffer_on || !window_width)
return 0;
if ( window_width == w->buffer_width &&
window_height == w->buffer_height)
return 0;
if ( w->buffer)
XFreePixmap( display, w->buffer);
depth = XDefaultDepthOfScreen( screen);
w->buffer = XCreatePixmap( display, w->window,
window_width, window_height, depth);
w->buffer_width = window_width;
w->buffer_height = window_height;
buffer_background( w);
return 1;
}
void GlowDrawXLib::buffer_background( DrawWind *wind)
{
DrawWindXLib *w = (DrawWindXLib *) wind;
int window_width, window_height, subwindow_x, subwindow_y;
if ( ctx->mw.window == wind) {
window_width = ctx->mw.window_width;
window_height = ctx->mw.window_height;
subwindow_x = ctx->mw.subwindow_x;
subwindow_y = ctx->mw.subwindow_y;
}
else {
window_width = ctx->navw.window_width;
window_height = ctx->navw.window_height;
subwindow_x = ctx->navw.subwindow_x;
subwindow_y = ctx->navw.subwindow_y;
}
if ( !w->double_buffer_on || !window_width)
return;
if ( w->background_pixmap) {
if ( w->clip_on)
set_clip( w, get_gc( this, glow_eDrawType_Line, 0));
if ( !((GrowCtx *)ctx)->background_tiled)
XCopyArea( display, w->background_pixmap,
w->buffer, get_gc( this, glow_eDrawType_Line, 0),
0, 0, w->buffer_width, w->buffer_height, 0, 0);
else {
int i, j;
for ( i = 0;
i <= w->buffer_width / w->background_pixmap_width;
i++)
for ( j = 0;
j <= w->buffer_height / w->background_pixmap_height;
j++)
XCopyArea( display, w->background_pixmap,
w->buffer, get_gc( this, glow_eDrawType_Line, 0),
0, 0, w->background_pixmap_width,
w->background_pixmap_height,
i * w->background_pixmap_width,
j * w->background_pixmap_height);
}
if ( w->clip_on)
reset_clip( w, get_gc( this, glow_eDrawType_Line, 0));
}
else {
if ( w->clip_on)
set_clip( w, get_gc( this, glow_eDrawType_LineErase, 0));
XFillRectangle( display, w->buffer,
get_gc( this, glow_eDrawType_LineErase, 0),
subwindow_x, subwindow_y, window_width, window_height);
if ( w->clip_on)
reset_clip( w, get_gc( this, glow_eDrawType_LineErase, 0));
}
}
int GlowDrawXLib::print( char *filename, double x0, double x1, int end)
{
#if defined IMLIB
#define ps_cPageHeight 820
#define ps_cPageWidth 535
#define ps_cLeftMargin 100
#define ps_cTopMargin 100
DrawWindXLib *w = &m_wind;
int width, height;
unsigned char *rgb;
unsigned char transp[3] = {255,0,255};
int i, j;
int grey;
int red, blue, green;
double scalex = 0.71;
double scaley = 0.78;
double x, y;
bool colorimage = true;
static DrawPs *ps = 0;
bool new_file = false;
int window_width = ctx->mw.window_width;
int window_height = ctx->mw.window_height;
x = ps_cLeftMargin;
y = ps_cPageHeight - ps_cTopMargin;
// imlib = Imlib_init( display);
ImlibImage *image;
if ( w->double_buffer_on)
image = Imlib_create_image_from_drawable( (ImlibData *)imlib, w->buffer,
0, 0, 0, w->buffer_width,
w->buffer_height);
else
image = Imlib_create_image_from_drawable( (ImlibData *)imlib, w->window,
0, 0, 0, window_width,
window_height);
if ( !image)
return 0;
if ( !ps) {
ps = new DrawPs( filename);
new_file = true;
ps->y = y;
}
else
y = ps->y;
width = image->rgb_width;
height = image->rgb_height;
if ( x0 != 0 || x1 != 0) {
double total_width = width / (x1 - x0);
if ( total_width * scalex > ps_cPageWidth - ps_cLeftMargin) {
x = ps_cPageWidth - total_width * scalex;
if ( x < 50) {
double scale_factor = (ps_cPageWidth - 50) / (total_width * scalex);
x = 50;
scalex = scalex * scale_factor;
scaley = scaley * scale_factor;
}
}
x += scalex * total_width * x0;
}
else if ( width * scalex > ps_cPageWidth - ps_cLeftMargin) {
x = ps_cPageWidth - width * scalex;
if ( x < 50) {
double scale_factor = (ps_cPageWidth - 50) / (width * scalex);
x = 50;
scalex = scalex * scale_factor;
scaley = scaley * scale_factor;
}
}
if ( (x0 == 0 && x1 == 0) || x1 == 1.0)
ps->y -= scaley * height;
if ( new_file) {
ps->fp <<
"%!PS-Adobe-2.0 EPSF-1.2" << endl <<
"%%Creator: Proview $Id: glow_draw_xlib.cpp,v 1.1 2007-01-04 08:08:00 claes Exp $ Glow" << endl <<
"%%EndComments" << endl << endl;
}
else
ps->fp <<
"restore" << endl;
ps->fp <<
"1.000000 1.000000 scale" << endl <<
"save" << endl <<
scalex * width << " " << scaley * height << " scale" << endl <<
"/oneline " << width << " string def" << endl <<
"/drawimage {" << endl <<
" " << width << " " << height << " 8 [" << width << " 0 0 -" << height << " 0 " << height << "]" << endl <<
" { currentfile oneline readhexstring pop }" << endl;
if ( colorimage) {
ps->fp <<
"false 3" << endl <<
"colorimage" << endl;
}
else
ps->fp <<
"image" << endl;
ps->fp <<
"} def" << endl <<
x/scalex/width << " " << (y - height*scaley)/scaley/height << " translate" << endl <<
"drawimage" << endl;
ps->fp.flags( (ps->fp.flags() & ~ios_base::dec) | ios_base::hex | ios_base::uppercase);
ps->fp.fill('0');
rgb = image->rgb_data;
j = 0;
for ( i = 0; i < image->rgb_height * image->rgb_width * 3; i+=3) {
if ( !colorimage) {
if ( *rgb == transp[0] && *(rgb+1) == transp[1] && *(rgb+2) == transp[2]) {
grey = 255;
}
else {
grey = (int) ((0.0 + *rgb + *(rgb+1) + *(rgb+2)) / 3 + 0.5);
}
rgb += 3;
ps->fp.width(2);
ps->fp << grey;
if ( ++j >= 40) {
j = 0;
ps->fp << endl;
}
}
else {
if ( *rgb == transp[0] && *(rgb+1) == transp[1] && *(rgb+2) == transp[2]) {
red = blue = green = 255;
}
else {
red = *rgb;
green = *(rgb+1);
blue = *(rgb+2);
}
rgb += 3;
ps->fp.width(2);
ps->fp << blue;
ps->fp.width(2);
ps->fp << green;
ps->fp.width(2);
ps->fp << red;
if ( ++j >= 20) {
j = 0;
ps->fp << endl;
}
}
}
if ( end) {
ps->fp << endl <<
"restore" << endl <<
"showpage" << endl;
delete ps;
ps = 0;
}
else {
ps->fp.flags( ((ps->fp.flags() & ~ios_base::hex) & ~ios_base::uppercase) | ios_base::dec);
}
Imlib_destroy_image( (ImlibData *)imlib, image);
#endif
return 1;
}
void GlowDrawXLib::imlib_destroy_image( glow_tImData imlib, glow_tImImage image)
{
Imlib_destroy_image( (ImlibData *)imlib, (ImlibImage *)image);
}
void GlowDrawXLib::imlib_kill_image( glow_tImData imlib, glow_tImImage image)
{
Imlib_kill_image( (ImlibData *)imlib, (ImlibImage *)image);
}
void GlowDrawXLib::imlib_free_pixmap( glow_tImData imlib, glow_tPixmap pixmap)
{
Imlib_free_pixmap( (ImlibData *)imlib, (Pixmap)pixmap);
}
glow_tImImage GlowDrawXLib::imlib_load_image( glow_tImData imlib, char *filename)
{
return (glow_tImImage) Imlib_load_image( (ImlibData *)imlib, filename);
}
glow_tImImage GlowDrawXLib::imlib_clone_image( glow_tImData imlib, glow_tImImage image)
{
return (glow_tImImage) Imlib_clone_image( (ImlibData *)imlib, (ImlibImage *)image);
}
int GlowDrawXLib::imlib_render( glow_tImData imlib, glow_tImImage image, int width, int height)
{
return Imlib_render( (ImlibData *)imlib, (ImlibImage *)image, width, height);
}
glow_tPixmap GlowDrawXLib::imlib_move_image( glow_tImData imlib, glow_tImImage image)
{
return (glow_tPixmap) Imlib_move_image( (ImlibData *)imlib, (ImlibImage *)image);
}
glow_tPixmap GlowDrawXLib::imlib_move_mask( glow_tImData imlib, glow_tImImage image)
{
return (glow_tPixmap) Imlib_move_mask( (ImlibData *)imlib, (ImlibImage *)image);
}
void GlowDrawXLib::imlib_set_image_red_curve( glow_tImData imlib, glow_tImImage image, unsigned char *mod)
{
Imlib_set_image_red_curve( (ImlibData *)imlib, (ImlibImage *)image, mod);
}
void GlowDrawXLib::imlib_set_image_green_curve( glow_tImData imlib, glow_tImImage image, unsigned char *mod)
{
Imlib_set_image_green_curve( (ImlibData *)imlib, (ImlibImage *)image, mod);
}
void GlowDrawXLib::imlib_set_image_blue_curve( glow_tImData imlib, glow_tImImage image, unsigned char *mod)
{
Imlib_set_image_blue_curve( (ImlibData *)imlib, (ImlibImage *)image, mod);
}
void GlowDrawXLib::imlib_changed_image( glow_tImData imlib, glow_tImImage image)
{
Imlib_changed_image( (ImlibData *)imlib, (ImlibImage *)image);
}
int GlowDrawXLib::imlib_image_rgb_width( glow_tImImage image)
{
return ((ImlibImage *)image)->rgb_width;
}
int GlowDrawXLib::imlib_image_rgb_height( glow_tImImage image)
{
return ((ImlibImage *)image)->rgb_height;
}
unsigned char *GlowDrawXLib::imlib_image_rgb_data( glow_tImImage image)
{
return ((ImlibImage *)image)->rgb_data;
}
// Image functions
int GlowDrawXLib::image_get_width( glow_tImImage image)
{
return ((ImlibImage *)image)->rgb_width;
}
int GlowDrawXLib::image_get_height( glow_tImImage image)
{
return ((ImlibImage *)image)->rgb_height;
}
int GlowDrawXLib::image_get_rowstride( glow_tImImage image)
{
return ((ImlibImage *)image)->rgb_width;
}
unsigned char *GlowDrawXLib::image_get_data( glow_tImImage image)
{
return ((ImlibImage *)image)->rgb_data;
}
void GlowDrawXLib::image_rotate( glow_tImImage *image, int to_rotation, int from_rotation)
{
int drot = to_rotation - from_rotation;
drot = int( (float(drot) / 360 - floor( float(drot) / 360)) * 360);
printf( "Drot: %d\n", drot);
if ( drot) {
if ( drot == 90 || drot == 270)
Imlib_rotate_image( (ImlibData *)imlib, (ImlibImage *)*image, 1);
if ( drot == 180 || drot == 270)
Imlib_flip_image_vertical( (ImlibData *)imlib, (ImlibImage *)*image);
if ( drot == 90 || drot == 180)
Imlib_flip_image_horizontal( (ImlibData *)imlib, (ImlibImage *)*image);
}
}
void GlowDrawXLib::image_flip_vertical( glow_tImImage *image)
{
Imlib_flip_image_horizontal( (ImlibData *)imlib, (ImlibImage *)*image);
}
void GlowDrawXLib::image_flip_horizontal( glow_tImImage *image)
{
Imlib_flip_image_vertical( (ImlibData *)imlib, (ImlibImage *)*image);
}
void GlowDrawXLib::image_scale( int width, int height, glow_tImImage orig_im, glow_tImImage *im,
glow_tPixmap *im_pixmap, glow_tPixmap *im_mask)
{
#if 0
#if defined IMLIB
if ( width == ((ImlibImage *)*im)->rgb_width && height == ((ImlibImage *)*im)->rgb_height)
return;
Imlib_render( (ImlibData *)imlib, (ImlibImage *)*im, width, height);
if ( *im_pixmap)
Imlib_free_pixmap( (ImlibData *)imlib, (Pixmap)*im_pixmap);
*im_pixmap = (glow_tPixmap) Imlib_move_image( (ImlibData *)imlib, (ImlibImage *)*im);
*im_mask = (glow_tPixmap) Imlib_move_mask( (ImlibData *)imlib, (ImlibImage *)*im);
#endif
#endif
}
int GlowDrawXLib::image_load( char *imagefile,
glow_tImImage *orig_im, glow_tImImage *im)
{
#if defined IMLIB
if ( *orig_im)
Imlib_kill_image( (ImlibData *)imlib, (ImlibImage *)*orig_im);
if ( *im)
Imlib_kill_image( (ImlibData *)imlib, (ImlibImage *)*im);
*orig_im = Imlib_load_image( (ImlibData *)imlib, imagefile);
if ( !*orig_im)
return 0;
// Make a copy
*im = Imlib_clone_image( (ImlibData *)imlib, (ImlibImage *)*orig_im);
#endif
return 1;
}
int GlowDrawXLib::image_render( int width, int height,
glow_tImImage orig_im, glow_tImImage *im,
glow_tPixmap *im_pixmap, glow_tPixmap *im_mask)
{
#if defined IMLIB
if ( *im_pixmap) {
Imlib_free_pixmap( (ImlibData *)imlib, (Pixmap)*im_pixmap);
*im_pixmap = 0;
}
Imlib_render( (ImlibData *)imlib, (ImlibImage *)*im, width, height);
*im_pixmap = (glow_tPixmap) Imlib_move_image( (ImlibData *)imlib, (ImlibImage *)*im);
*im_mask = (glow_tPixmap) Imlib_move_mask( (ImlibData *)imlib, (ImlibImage *)*im);
#endif
return 1;
}
void GlowDrawXLib::image_free( glow_tImImage image)
{
Imlib_destroy_image( (ImlibData *)imlib, (ImlibImage *)image);
}
void GlowDrawXLib::pixmap_free( glow_tPixmap pixmap)
{
Imlib_free_pixmap( (ImlibData *)imlib, (Pixmap)pixmap);
}
void GlowDrawXLib::image_pixel_iter( glow_tImImage orig_image, glow_tImImage *image,
void (* pixel_cb)(void *, unsigned char *), void *userdata)
{
unsigned char *rgb;
int rgb_height;
int rgb_width;
unsigned char transp[3] = {255,0,255};
if ( orig_image) {
if ( image)
Imlib_destroy_image( (ImlibData *)imlib, (ImlibImage *)*image);
*image = Imlib_clone_image( (ImlibData *)imlib, (ImlibImage *)orig_image);
}
else if ( !image)
return;
rgb = ctx->gdraw->image_get_data( (ImlibImage *)*image);
rgb_height = image_get_height( (ImlibImage *)*image);
rgb_width = image_get_width( (ImlibImage *)*image);
for ( int i = 0; i < rgb_height * rgb_width * 3; i+=3) {
if ( *rgb == transp[0] && *(rgb+1) == transp[1] && *(rgb+2) == transp[2]) {
rgb += 3;
continue;
}
(pixel_cb) ( userdata, rgb);
rgb += 3;
}
Imlib_changed_image( (ImlibData *)imlib, (ImlibImage *)*image);
}
/*
* Proview $Id: glow_draw_xlib.h,v 1.1 2007-01-04 08:08:00 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* 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 the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#ifndef glow_draw_xlib_h
#define glow_draw_xlib_h
#include <stdlib.h>
#include <Xm/Xm.h>
#include <Mrm/MrmPublic.h>
#ifndef _XtIntrinsic_h
#include <X11/Intrinsic.h>
#endif
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#if defined OS_LINUX
#define IMLIB 1
#endif
#if defined IMLIB
# if defined OS_LYNX
# define __NO_INCLUDE_WARN__ 1
# endif
# include <X11/extensions/shape.h>
# include <Imlib.h>
# if defined OS_LYNX
# undef __NO_INCLUDE_WARN__
# endif
#else
typedef void *ImlibData;
typedef void *ImlibImage;
#endif
#include "glow_draw.h"
#define DRAW_CLIP_SIZE 10
class DrawWindXLib : public DrawWind {
public:
DrawWindXLib() : toplevel(0), shell(0), window(0),
buffer(0), buffer_width(0), buffer_height(0),
clip_on(0), clip_cnt(0),
background_pixmap(0), background_pixmap_width(0), background_pixmap_height(0)
{ memset( clip_rectangle, 0, sizeof(clip_rectangle)); }
Widget toplevel;
Widget shell;
Window window;
Pixmap buffer;
int buffer_width;
int buffer_height;
int clip_on;
int clip_cnt;
XRectangle clip_rectangle[DRAW_CLIP_SIZE];
Pixmap background_pixmap;
int background_pixmap_width;
int background_pixmap_height;
};
class GlowDrawXLib : public GlowDraw {
public:
GlowDrawXLib(
Widget toplevel,
void **glow_ctx,
int (*init_proc)(Widget w, GlowCtx *ctx, void *client_data),
void *client_data,
glow_eCtxType type);
~GlowDrawXLib();
DrawWindXLib m_wind;
DrawWindXLib nav_wind;
// Widget toplevel;
// Widget nav_shell;
// Widget nav_toplevel;
XtAppContext app_ctx;
Display *display;
// Window window;
// Window nav_window;
Screen *screen;
GC gc;
GC gc_erase;
GC gc_inverse;
GC gcs[glow_eDrawType__][DRAW_TYPE_SIZE];
XFontStruct *font_struct[glow_eDrawFont__][DRAW_FONT_SIZE];
Font font[glow_eDrawFont__][DRAW_FONT_SIZE];
int cursors[glow_eDrawCursor__];
int ef;
// int (*event_handler)(glow_eEvent event, int x, int y, int w, int h);
// int (*event_handler_nav)(glow_eEvent event, int x, int y);
unsigned long background;
unsigned long original_background;
XtIntervalId timer_id;
int click_sensitivity;
int event_handler( XEvent event);
virtual void enable_event( glow_eEvent event,
glow_eEventType event_type,
int (*event_cb)(GlowCtx *ctx, glow_tEvent event));
virtual void clear( GlowWind *w);
virtual void copy_buffer( GlowWind *w, int ll_x, int ll_y, int ur_x, int ur_y);
virtual void get_window_size( GlowWind *w, int *width, int *height);
virtual void set_window_size( GlowWind *w, int width, int height);
virtual int rect( GlowWind *w, int x, int y, int width, int height,
glow_eDrawType gc_type, int idx, int highlight);
virtual int rect_erase( GlowWind *w, int x, int y, int width, int height,
int idx);
virtual int arrow( GlowWind *w, int x1, int y1, int x2, int y2,
int x3, int y3,
glow_eDrawType gc_type, int idx, int highlight);
virtual int arrow_erase( GlowWind *w, int x1, int y1, int x2, int y2,
int x3, int y3,
int idx);
virtual int arc( GlowWind *w, int x, int y, int width, int height,
int angel1, int angel2,
glow_eDrawType gc_type, int idx, int highlight);
virtual int fill_arc( GlowWind *w, int x, int y, int width, int height,
int angel1, int angel2, glow_eDrawType gc_type, int highlight);
virtual int arc_erase( GlowWind *w, int x, int y, int width, int height,
int angel1, int angel2,
int idx);
virtual int line( GlowWind *w, int x1, int y1, int x2, int y2,
glow_eDrawType gc_type, int idx, int highlight);
virtual int line_dashed( GlowWind *w, int x1, int y1, int x2, int y2,
glow_eDrawType gc_type, int idx, int highlight, glow_eLineType line_type);
virtual int line_erase( GlowWind *w, int x1, int y1, int x2, int y2,
int idx);
virtual int polyline( GlowWind *w, glow_sPointX *points, int point_cnt,
glow_eDrawType gc_type, int idx, int highlight);
virtual int fill_polyline( GlowWind *w, glow_sPointX *points, int point_cnt,
glow_eDrawType gc_type, int highlight);
virtual int polyline_erase( GlowWind *w, glow_sPointX *points, int point_cnt,
int idx);
virtual int text( GlowWind *w, int x, int y, char *text, int len,
glow_eDrawType gc_type, glow_eDrawType color, int idx, int highlight, int line);
virtual int text_cursor( GlowWind *w, int x, int y, char *text, int len,
glow_eDrawType gc_type, glow_eDrawType color, int idx, int highlight, int pos);
virtual int text_erase( GlowWind *w, int x, int y, char *text, int len,
glow_eDrawType gc_type, int idx, int line);
virtual int fill_rect( GlowWind *w, int x, int y, int width, int height,
glow_eDrawType gc_type);
virtual int pixmaps_create( GlowWind *w, glow_sPixmapData *pixmap_data,
void **pixmaps);
virtual void pixmaps_delete( GlowWind *w, void *pixmaps);
virtual int pixmap( GlowWind *w, int x, int y, glow_sPixmapData *pixmap_data,
void *pixmaps, glow_eDrawType gc_type, int idx, int highlight, int line);
virtual int pixmap_inverse( GlowWind *w, int x, int y, glow_sPixmapData *pixmap_data,
void *pixmaps, glow_eDrawType gc_type, int idx, int line);
virtual int pixmap_erase( GlowWind *w, int x, int y, glow_sPixmapData *pixmap_data,
void *pixmaps, glow_eDrawType gc_type, int idx, int line);
virtual int image( GlowWind *w, int x, int y, int width, int height,
glow_tImImage image, glow_tPixmap pixmap, glow_tPixmap clip_mask);
virtual void set_cursor( GlowWind *w, glow_eDrawCursor cursor);
virtual int get_text_extent( char *text, int len,
glow_eDrawType gc_type, int idx,
int *width, int *height, int *descent);
virtual void copy_area( GlowWind *w, int x, int y);
virtual void clear_area( GlowWind *w, int ll_x, int ur_x, int ll_y, int ur_y);
virtual void set_inputfocus( GlowWind *w);
virtual void set_background( GlowWind *w, glow_eDrawType drawtype, glow_tPixmap pixmap,
int pixmap_width, int pixmap_height);
virtual void reset_background( GlowWind *w);
virtual void set_image_clip_mask( glow_tPixmap pixmap, int x, int y);
virtual void reset_image_clip_mask();
virtual int set_clip_rectangle( GlowWind *w, int ll_x, int ll_y, int ur_x, int ur_y);
virtual void reset_clip_rectangle( GlowWind *w);
virtual int clip_level( GlowWind *w);
virtual int draw_point( GlowWind *w, int x1, int y1, glow_eDrawType gc_type);
virtual int draw_points( GlowWind *w, glow_sPointX *points, int point_num,
glow_eDrawType gc_type);
virtual void set_click_sensitivity( GlowWind *w, int value);
virtual void draw_background( GlowWind *w, int x, int y, int w, int h);
virtual int create_buffer( GlowWind *w);
virtual void buffer_background( DrawWind *w);
virtual int print( char *filename, double x0, double x1, int end);
void set_clip( DrawWind *w, GC gc);
void reset_clip( DrawWind *w, GC gc);
virtual void set_timer( GlowCtx *gctx, int time_ms,
void (*callback_func)( GlowCtx *ctx), void **id);
virtual void remove_timer( void *id);
int init_nav( Widget nav_widget);
virtual void imlib_destroy_image( glow_tImData imlib, glow_tImImage image);
virtual void imlib_kill_image( glow_tImData imlib, glow_tImImage image);
virtual void imlib_free_pixmap( glow_tImData imlib, glow_tPixmap pixmap);
virtual glow_tImImage imlib_load_image( glow_tImData imlib, char *filename);
virtual glow_tImImage imlib_clone_image( glow_tImData imlib, glow_tImImage image);
virtual int imlib_render( glow_tImData imlib, glow_tImImage image, int width, int height);
virtual glow_tPixmap imlib_move_image( glow_tImData imlib, glow_tImImage image);
virtual glow_tPixmap imlib_move_mask( glow_tImData imlib, glow_tImImage image);
virtual void imlib_set_image_red_curve( glow_tImData imlib, glow_tImImage image, unsigned char *mod);
virtual void imlib_set_image_green_curve( glow_tImData imlib, glow_tImImage image, unsigned char *mod);
virtual void imlib_set_image_blue_curve( glow_tImData imlib, glow_tImImage image, unsigned char *mod);
virtual void imlib_changed_image( glow_tImData imlib, glow_tImImage image);
virtual int imlib_image_rgb_width( glow_tImImage image);
virtual int imlib_image_rgb_height( glow_tImImage image);
virtual unsigned char *imlib_image_rgb_data( glow_tImImage image);
int image_get_width( glow_tImImage image);
int image_get_height( glow_tImImage image);
int image_get_rowstride( glow_tImImage image);
unsigned char *image_get_data( glow_tImImage image);
void image_rotate( glow_tImImage *image, int to_rotation, int from_rotation);
void image_flip_vertical( glow_tImImage *image);
void image_flip_horizontal( glow_tImImage *image);
void image_scale( int width, int height, glow_tImImage orig_im, glow_tImImage *im,
glow_tPixmap *im_pixmap, glow_tPixmap *im_mask);
int image_load( char *imagefile,
glow_tImImage *orig_im, glow_tImImage *im);
int image_render( int width, int height,
glow_tImImage orig_im, glow_tImImage *im,
glow_tPixmap *im_pixmap, glow_tPixmap *im_mask);
void image_free( glow_tImImage image);
void pixmap_free( glow_tPixmap pixmap);
void image_pixel_iter( glow_tImImage orig_image, glow_tImImage *image,
void (* pixel_cb)(void *, unsigned char *), void *userdata);
};
class DrawPs {
public:
DrawPs( char *filename) : fp(filename), x(0), y(0)
{}
~DrawPs() { fp.close();}
ofstream fp;
double x;
double y;
};
#endif
/*
* Proview $Id: glow_growwidget_motif.cpp,v 1.1 2007-01-04 08:08:00 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* 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 the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#include "glow_std.h"
#include <stdio.h>
#include <stdlib.h>
#ifdef __OS_VMS
#pragma member_alignment
#endif
#include <Xm/Xm.h>
#include <Xm/XmP.h>
#include <Xm/ScrollBar.h>
#include <Xm/Form.h>
#include <Mrm/MrmPublic.h>
#ifndef _XtIntrinsic_h
#include <X11/Intrinsic.h>
#endif
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "glow.h"
#include "glow_growctx.h"
#include "glow_draw_xlib.h"
#include "glow_growwidget_motif.h"
typedef struct {
Widget grow;
Widget form;
Widget scroll_h;
Widget scroll_v;
int scroll_h_managed;
int scroll_v_managed;
} growwidget_sScroll;
static XtGeometryResult GeometryManager(
Widget w,
XtWidgetGeometry *request,
XtWidgetGeometry *reply);
static void Notify( Widget w, XEvent *event);
static void Destroy( Widget w);
static Boolean AcceptFocus( Widget w, Time *t);
static void Realize( Widget w, unsigned long *dum, XSetWindowAttributes *swa);
static void Initialize( Widget rec, Widget new_widget, ArgList arg, int *args);
static void Redisplay( Widget w, XEvent *event, Region region);
static Boolean SetValues( Widget old, Widget request, Widget new_widget);
static char defaultTranslations[] = "#replace \n\
<Btn1Up>: notify()\n\
<Btn2Up>: notify()\n\
<Btn3Up>: notify()\n\
<Btn1Down>: notify()\n\
<Btn2Down>: notify()\n\
<Btn3Down>: notify()\n\
<BtnMotion>: notify()\n\
<EnterWindow>: notify()\n\
<LeaveWindow>: notify()\n\
<VisibilityNotify>: notify()\n\
<MotionNotify>: notify()\n\
<FocusIn>: notify()\n\
<Map>: notify()\n\
<Unmap>: notify()\n\
<Key>Up: notify()\n\
<Key>Down: notify()\n\
<KeyDown>: notify()";
static XtActionsRec actionsList[] = { {"notify", (XtActionProc) Notify}};
GrowClassRec growClassRec = {
{ /* Core class part */
(WidgetClass) &compositeClassRec, /* superclass */
"Grow", /* class name */
sizeof(GrowRec), /* widget size */
NULL, /* class initialize */
NULL, /* class part initialize */
FALSE, /* class inited */
(XtInitProc) Initialize, /* initialize */
NULL, /* initialize hook */
Realize, /* realize */
actionsList, /* actions */
XtNumber( actionsList), /* num actions */
NULL, /* resourses */
0, /* num resourses */
NULLQUARK, /* xrm class */
TRUE, /* compress motion */
TRUE, /* compress expsure */
TRUE, /* compress enterleave */
FALSE, /* visible interest */
Destroy, /* destroy */
XtInheritResize, /* resize */
Redisplay, /* expose */
(XtSetValuesFunc)SetValues, /* set values */
NULL, /* set values hook */
XtInheritSetValuesAlmost, /* set values almost */
NULL, /* get values hook */
AcceptFocus, /* accept focus */
XtVersionDontCheck, /* version */
NULL, /* callback offsets */
defaultTranslations, /* tm_table */
NULL, /* geometry */
NULL, /* disp accelerators */
NULL /* extension */
},
{ /* composite class record */
(XtGeometryHandler) GeometryManager, /* geometry manager */
NULL, /* change managed */
XtInheritInsertChild, /* insert child */
XtInheritDeleteChild, /* delete child */
NULL /* extension */
},
{ /* grow class record */
NULL,
0
}
};
WidgetClass growWidgetClass = (WidgetClass) &growClassRec;
static void scroll_h_action( Widget w,
XtPointer client_data,
XtPointer call_data);
static void scroll_v_action( Widget w,
XtPointer client_data,
XtPointer call_data);
static void scroll_callback( glow_sScroll *data);
static int grow_init_proc( Widget w, GlowCtx *fctx, void *client_data)
{
growwidget_sScroll *scroll_data;
GrowCtx *ctx;
ctx = (GrowCtx *) ((GrowWidget) w)->grow.grow_ctx;
if ( ((GrowWidget) w)->grow.scroll_h)
{
scroll_data = (growwidget_sScroll *) malloc( sizeof( growwidget_sScroll));
scroll_data->grow = w;
scroll_data->scroll_h = ((GrowWidget) w)->grow.scroll_h;
scroll_data->scroll_v = ((GrowWidget) w)->grow.scroll_v;
scroll_data->form = ((GrowWidget) w)->grow.form;
scroll_data->scroll_h_managed = 1;
scroll_data->scroll_v_managed = 1;
ctx->register_scroll_callback( (void *) scroll_data, scroll_callback);
XtAddCallback( scroll_data->scroll_h, XmNvalueChangedCallback, scroll_h_action, w);
XtAddCallback( scroll_data->scroll_h, XmNdragCallback, scroll_h_action, w);
XtAddCallback( scroll_data->scroll_h, XmNincrementCallback, scroll_h_action, w);
XtAddCallback( scroll_data->scroll_h, XmNdecrementCallback, scroll_h_action, w);
XtAddCallback( scroll_data->scroll_h, XmNpageIncrementCallback, scroll_h_action, w);
XtAddCallback( scroll_data->scroll_h, XmNpageDecrementCallback, scroll_h_action, w);
XtAddCallback( scroll_data->scroll_h, XmNtoTopCallback, scroll_h_action, w);
XtAddCallback( scroll_data->scroll_h, XmNtoBottomCallback, scroll_h_action, w);
XtAddCallback( scroll_data->scroll_v, XmNvalueChangedCallback, scroll_v_action, w);
XtAddCallback( scroll_data->scroll_v, XmNdragCallback, scroll_v_action, w);
XtAddCallback( scroll_data->scroll_v, XmNincrementCallback, scroll_v_action, w);
XtAddCallback( scroll_data->scroll_v, XmNdecrementCallback, scroll_v_action, w);
XtAddCallback( scroll_data->scroll_v, XmNpageIncrementCallback, scroll_v_action, w);
XtAddCallback( scroll_data->scroll_v, XmNpageDecrementCallback, scroll_v_action, w);
XtAddCallback( scroll_data->scroll_v, XmNtoTopCallback, scroll_v_action, w);
XtAddCallback( scroll_data->scroll_v, XmNtoBottomCallback, scroll_v_action, w);
}
return (((GrowWidget) w)->grow.init_proc)( ctx, client_data);
}
static void scroll_h_action( Widget w,
XtPointer client_data,
XtPointer call_data)
{
XmScrollBarCallbackStruct *cbs = (XmScrollBarCallbackStruct *) call_data;
GrowCtx *ctx = (GrowCtx *) ((GrowWidget) client_data)->grow.grow_ctx;
switch( cbs->reason)
{
case XmCR_DRAG:
case XmCR_VALUE_CHANGED:
case XmCR_INCREMENT:
case XmCR_DECREMENT:
case XmCR_PAGE_INCREMENT:
case XmCR_PAGE_DECREMENT:
case XmCR_TO_TOP:
case XmCR_TO_BOTTOM:
glow_scroll_horizontal( ctx, cbs->value, 0);
break;
}
}
static void scroll_v_action( Widget w,
XtPointer client_data,
XtPointer call_data)
{
XmScrollBarCallbackStruct *cbs = (XmScrollBarCallbackStruct *) call_data;
GrowCtx *ctx = (GrowCtx *) ((GrowWidget) client_data)->grow.grow_ctx;
Arg arg[20];
int i;
int maximum, slider, value, bottom;
// Calculate if position is bottom
i = 0;
XtSetArg( arg[i], XmNmaximum, &maximum);i++;
XtSetArg( arg[i], XmNsliderSize, &slider);i++;
XtSetArg( arg[i], XmNvalue, &value);i++;
XtGetValues( w, arg, i);
if ( slider + value == maximum)
bottom = 1;
else
bottom = 0;
switch( cbs->reason)
{
case XmCR_DRAG:
case XmCR_VALUE_CHANGED:
case XmCR_INCREMENT:
case XmCR_DECREMENT:
case XmCR_PAGE_INCREMENT:
case XmCR_PAGE_DECREMENT:
case XmCR_TO_TOP:
case XmCR_TO_BOTTOM:
glow_scroll_vertical( ctx, cbs->value, bottom);
break;
}
}
static void scroll_callback( glow_sScroll *data)
{
growwidget_sScroll *scroll_data;
Arg arg[20];
int i;
scroll_data = (growwidget_sScroll *) data->scroll_data;
if ( data->total_width <= data->window_width)
{
if ( data->offset_x == 0)
data->total_width = data->window_width;
if ( scroll_data->scroll_h_managed)
{
// Remove horizontal scrollbar
}
}
else
{
if ( !scroll_data->scroll_h_managed)
{
// Insert horizontal scrollbar
}
}
if ( data->total_height <= data->window_height)
{
if ( data->offset_y == 0)
data->total_height = data->window_height;
if ( scroll_data->scroll_v_managed)
{
// Remove vertical scrollbar
}
}
else
{
if ( !scroll_data->scroll_v_managed)
{
// Insert vertical scrollbar
}
}
if ( data->offset_x < 0)
data->offset_x = 0;
if ( data->offset_y < 0)
data->offset_y = 0;
if ( data->total_height < data->window_height + data->offset_y)
data->total_height = data->window_height + data->offset_y;
if ( data->total_width < data->window_width + data->offset_x)
data->total_width = data->window_width + data->offset_x;
if ( data->window_width < 1)
data->window_width = 1;
if ( data->window_height < 1)
data->window_height = 1;
if ( scroll_data->scroll_h_managed)
{
i = 0;
XtSetArg( arg[i], XmNmaximum, data->total_width);i++;
XtSetArg( arg[i], XmNsliderSize, data->window_width);i++;
XtSetArg( arg[i], XmNvalue, data->offset_x);i++;
XtSetValues( scroll_data->scroll_h, arg, i);
}
if ( scroll_data->scroll_v_managed)
{
i = 0;
XtSetArg( arg[i], XmNmaximum, data->total_height);i++;
XtSetArg( arg[i], XmNsliderSize, data->window_height);i++;
XtSetArg( arg[i], XmNvalue, data->offset_y);i++;
XtSetValues( scroll_data->scroll_v, arg, i);
}
}
static XtGeometryResult GeometryManager(
Widget w,
XtWidgetGeometry *request,
XtWidgetGeometry *reply)
{
if ( request->request_mode & CWX)
w->core.x = request->x;
if ( request->request_mode & CWY)
w->core.y = request->y;
if ( request->request_mode & CWWidth)
w->core.width = request->width;
if ( request->request_mode & CWHeight)
w->core.height = request->height;
if ( request->request_mode & CWBorderWidth)
w->core.border_width = request->border_width;
return XtGeometryYes;
}
static void Initialize( Widget rec, Widget new_widget, ArgList arg, int *args)
{
/*
GrowWidget w;
XtManageChild( new_widget);
w = (GrowWidget) new_widget;
*/
}
static void Redisplay( Widget w, XEvent *event, Region region)
{
((GlowDrawXLib *)((GrowCtx *)((GrowWidget)w)->grow.grow_ctx)->gdraw)->event_handler( *event);
}
static void Notify( Widget w, XEvent *event)
{
((GlowDrawXLib *)((GrowCtx *)((GrowWidget)w)->grow.grow_ctx)->gdraw)->event_handler( *event);
}
static Boolean SetValues( Widget old, Widget request, Widget new_widget)
{
return 0;
}
static void Destroy( Widget w)
{
if ( ((GrowWidget) w)->grow.is_navigator)
return;
delete (GlowDraw *)((GrowWidget)w)->grow.draw_ctx;
}
static Boolean AcceptFocus( Widget w, Time *t)
{
if ( ((GrowWidget) w)->grow.is_navigator)
return 0;
((GrowCtx *)((GrowWidget)w)->grow.grow_ctx)->gdraw->set_inputfocus(
&((GrowCtx *)((GrowWidget)w)->grow.grow_ctx)->mw);
return 1;
}
static void Realize( Widget w, unsigned long *mask, XSetWindowAttributes *swa)
{
(* growWidgetClass->core_class.superclass->core_class.realize)
(w, mask, swa);
if ( ((GrowWidget) w)->grow.is_navigator) {
if ( !((GrowWidget) w)->grow.grow_ctx) {
GrowWidget main_grow = (GrowWidget) ((GrowWidget) w)->grow.main_grow_widget;
((GrowWidget) w)->grow.grow_ctx = main_grow->grow.grow_ctx;
((GrowWidget) w)->grow.draw_ctx = main_grow->grow.draw_ctx;
((GlowDrawXLib *)((GrowWidget) w)->grow.draw_ctx)->init_nav( w);
}
}
else {
if ( !((GrowWidget) w)->grow.grow_ctx) {
((GrowWidget) w)->grow.draw_ctx = new GlowDrawXLib( w, &((GrowWidget) w)->grow.grow_ctx,
grow_init_proc,
((GrowWidget) w)->grow.client_data,
glow_eCtxType_Grow);
}
}
}
extern "C" Widget GrowCreate(
Widget parent,
char *name,
ArgList args,
int argCount,
int (*init_proc)(GlowCtx *ctx, void *client_data),
void *client_data
)
{
GrowWidget w;
w = (GrowWidget) XtCreateWidget( name, growWidgetClass, parent, args,
argCount);
w->grow.init_proc = init_proc;
w->grow.grow_ctx = 0;
w->grow.is_navigator = 0;
w->grow.client_data = client_data;
w->grow.scroll_h = 0;
w->grow.scroll_v = 0;
return (Widget) w;
}
extern "C" Widget ScrolledGrowCreate(
Widget parent,
char *name,
ArgList args,
int argCount,
int (*init_proc)(GlowCtx *ctx, void *client_data),
void *client_data,
Widget *grow_w
)
{
Widget form, scroll_h, scroll_v;
GrowWidget grow;
Arg arg[20];
int i;
int scroll_width = 15;
form = XtCreateWidget( name, xmFormWidgetClass, parent, args,
argCount);
i = 0;
XtSetArg( arg[i], XmNorientation, XmHORIZONTAL); i++;
XtSetArg( arg[i], XmNrightAttachment, XmATTACH_FORM);i++;
XtSetArg( arg[i], XmNleftAttachment, XmATTACH_FORM);i++;
XtSetArg( arg[i], XmNbottomAttachment, XmATTACH_FORM);i++;
XtSetArg( arg[i], XmNheight, scroll_width);i++;
XtSetArg( arg[i], XmNrightOffset, scroll_width);i++;
scroll_h = XtCreateWidget( "scroll_horizontal", xmScrollBarWidgetClass,
form, arg, i);
XtManageChild( scroll_h);
i = 0;
XtSetArg( arg[i], XmNorientation, XmVERTICAL); i++;
XtSetArg( arg[i], XmNtopAttachment, XmATTACH_FORM);i++;
XtSetArg( arg[i], XmNrightAttachment, XmATTACH_FORM);i++;
XtSetArg( arg[i], XmNbottomAttachment, XmATTACH_FORM);i++;
XtSetArg( arg[i], XmNwidth, scroll_width);i++;
XtSetArg( arg[i], XmNbottomOffset, scroll_width);i++;
scroll_v = XtCreateWidget( "scroll_vertical", xmScrollBarWidgetClass,
form, arg, i);
XtManageChild( scroll_v);
i = 0;
XtSetArg( arg[i], XmNtopAttachment, XmATTACH_FORM);i++;
XtSetArg( arg[i], XmNleftAttachment, XmATTACH_FORM);i++;
XtSetArg( arg[i], XmNbottomAttachment, XmATTACH_WIDGET);i++;
XtSetArg( arg[i], XmNbottomWidget, scroll_h);i++;
XtSetArg( arg[i], XmNrightAttachment, XmATTACH_WIDGET);i++;
XtSetArg( arg[i], XmNrightWidget, scroll_v);i++;
/*
XtSetArg( arg[i], XmNbottomAttachment, XmATTACH_FORM);i++;
XtSetArg( arg[i], XmNrightAttachment, XmATTACH_FORM);i++;
*/
grow = (GrowWidget) GrowCreate( form, "grow", arg, i, init_proc, client_data);
XtManageChild( (Widget) grow);
grow->grow.scroll_h = scroll_h;
grow->grow.scroll_v = scroll_v;
grow->grow.form = form;
*grow_w = (Widget) grow;
return (Widget) form;
}
Widget GrowCreateNav( Widget parent, char *name, ArgList args, int argCount,
Widget main_grow)
{
GrowWidget w;
w = (GrowWidget) XtCreateWidget( name, growWidgetClass, parent, args, argCount);
w->grow.is_navigator = 1;
w->grow.grow_ctx = 0;
w->grow.main_grow_widget = main_grow;
return (Widget) w;
}
void GrowCtxFromWidget( Widget w, void **ctx)
{
*ctx = ((GrowWidget) w)->grow.grow_ctx;
}
/*
* Proview $Id: glow_growwidget_motif.h,v 1.1 2007-01-04 08:08:00 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* 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 the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#ifndef grow_widget_h
#define grow_widget_h
#if defined __cplusplus
extern "C" {
#endif
/* X Toolkit is compiled with member alignment */
#if defined OS_VMS
#pragma member_alignment save
#pragma member_alignment
#endif
#include <X11/CoreP.h>
#include <X11/CompositeP.h>
typedef struct {
XmOffsetPtr *offset;
int reserved;
} growClassPart;
typedef struct {
CoreClassPart core_class;
CompositeClassPart composite_class;
growClassPart grow_class;
} GrowClassRec, *GrowWidgetClass;
typedef struct {
void *grow_ctx;
void *draw_ctx;
int (*init_proc)(GlowCtx *ctx, void *clien_data);
int is_navigator;
void *client_data;
Widget main_grow_widget;
Widget scroll_h;
Widget scroll_v;
Widget form;
} GrowPart;
typedef struct {
CorePart core;
CompositePart composite;
GrowPart grow;
} GrowRec, *GrowWidget;
Widget GrowCreate(
Widget parent,
char *name,
ArgList args,
int argCount,
int (*init_proc)(GlowCtx *ctx, void *client_data),
void *client_data
);
Widget GrowCreateNav( Widget parent, char *name, ArgList args, int argCount,
Widget main_grow);
Widget ScrolledGrowCreate(
Widget parent,
char *name,
ArgList args,
int argCount,
int (*init_proc)(GlowCtx *ctx, void *client_data),
void *client_data,
Widget *grow_w
);
void GrowCtxFromWidget( Widget w, void **ctx);
#if defined OS_VMS
#pragma member_alignment restore
#endif
#if defined __cplusplus
}
#endif
#endif
include $(pwre_dir_symbols)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(hw_name)/$(type_name)_generic.mk
ifeq ($($(type_name)_generic_mk),)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(type_name)_generic.mk
endif
ifeq ($($(type_name)_generic_mk),)
include $(pwre_kroot)/tools/bld/src/$(type_name)_generic.mk
endif
-include ../../special.mk
-include ../special.mk
-include special.mk
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment