aboutsummaryrefslogtreecommitdiff
path: root/generic/Field.c
diff options
context:
space:
mode:
authorlecoanet2003-04-16 09:49:22 +0000
committerlecoanet2003-04-16 09:49:22 +0000
commit3261805fee19e346b4d1f84b23816daa1628764a (patch)
tree63ca1d7e4b0a3d9ae49cc0888e58033c3ef3fe22 /generic/Field.c
parenteed2656db0adae2c234c3d74af0913746ed5c444 (diff)
downloadtkzinc-3261805fee19e346b4d1f84b23816daa1628764a.zip
tkzinc-3261805fee19e346b4d1f84b23816daa1628764a.tar.gz
tkzinc-3261805fee19e346b4d1f84b23816daa1628764a.tar.bz2
tkzinc-3261805fee19e346b4d1f84b23816daa1628764a.tar.xz
Update from the Windows port and general cleanup/restructure
Diffstat (limited to 'generic/Field.c')
-rw-r--r--generic/Field.c692
1 files changed, 359 insertions, 333 deletions
diff --git a/generic/Field.c b/generic/Field.c
index 8d24264..4893633 100644
--- a/generic/Field.c
+++ b/generic/Field.c
@@ -27,13 +27,6 @@
*/
-#include <malloc.h>
-#include <string.h>
-#include <stdlib.h>
-#ifdef GLX
-#include <GL/glx.h>
-#endif
-
#include "Item.h"
#include "Types.h"
#include "WidgetInfo.h"
@@ -41,6 +34,9 @@
#include "Geo.h"
#include "tkZinc.h"
+#include <string.h>
+#include <stdlib.h>
+
static const char rcsid[] = "$Id$";
static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " $";
@@ -65,13 +61,13 @@ typedef struct _FieldStruct {
char *text;
ZnImage image;
ZnImage tile;
- ZnFont font;
+ Tk_Font font;
unsigned short flags;
- Border border_edges;
- ZnJustify alignment;
- ReliefStyle relief;
+ ZnBorder border_edges;
+ Tk_Justify alignment;
+ ZnReliefStyle relief;
ZnDim relief_thickness;
- AutoAlign auto_alignment;
+ ZnAutoAlign auto_alignment;
/* Private data */
ZnGradient *gradient;
@@ -80,9 +76,9 @@ typedef struct _FieldStruct {
short orig_y;
short corner_x;
short corner_y;
- FieldSet field_set; /* Only used by the image update callbacks */
+ ZnFieldSet field_set; /* Only used by the image update callbacks */
int insert_index;
-#ifdef GLX
+#ifdef GL
ZnTexFontInfo *tfi;
#endif
} FieldStruct, *Field;
@@ -131,10 +127,10 @@ ZnAttrConfig field_attrs[] = {
Tk_Offset(FieldStruct, flags), FIELD_VISIBLE_BIT,
ZN_COORDS_FLAG|ZN_CLFC_FLAG, False }, /* Keep ZN_COORDS_FLAG here */
- { ZN_CONFIG_END, NULL, NULL, 0, 0, 0 }
+ { ZN_CONFIG_END, NULL, NULL, 0, 0, 0, False }
};
-static void GetLabelBBox(FieldSet field_set, ZnDim *w, ZnDim *h);
+static void GetLabelBBox(ZnFieldSet field_set, ZnDim *w, ZnDim *h);
@@ -147,14 +143,14 @@ static void GetLabelBBox(FieldSet field_set, ZnDim *w, ZnDim *h);
**********************************************************************************
*/
static void
-ComputeFieldAttachment(FieldSet field_set,
- int field,
- ZnBBox *field_bbox)
+ComputeFieldAttachment(ZnFieldSet field_set,
+ unsigned int field,
+ ZnBBox *field_bbox)
{
ZnBBox ref_bbox;
ZnDim real_width, real_height;
- int ref_field, num_fields;
+ unsigned int ref_field, num_fields;
char x_attach, y_attach, x_dim, y_dim;
short width_spec, height_spec;
int x_spec, y_spec, icon_width=0, icon_height=0;
@@ -180,29 +176,29 @@ ComputeFieldAttachment(FieldSet field_set,
field_bbox->corner.x = field_bbox->corner.y = 0;
SET(fptr->flags, CACHE_OK);
- num_fields = LabelFormatNumFields(field_set->label_format);
- LabelFormatGetField(field_set->label_format, field,
- &x_attach, &y_attach, &x_dim, &y_dim,
- &x_spec, &y_spec, &width_spec, &height_spec);
+ num_fields = ZnLFNumFields(field_set->label_format);
+ ZnLFGetField(field_set->label_format, field,
+ &x_attach, &y_attach, &x_dim, &y_dim,
+ &x_spec, &y_spec, &width_spec, &height_spec);
/*
* First try to compute the field size which may be a factor
* of the field content (but not a factor of other fields).
*/
if ((fptr->image != ZnUnspecifiedImage) &&
- ((x_dim == LF_DIM_ICON) || (y_dim == LF_DIM_ICON) ||
- (x_dim == LF_DIM_AUTO) || (y_dim == LF_DIM_AUTO))) {
+ ((x_dim == ZN_LF_DIM_ICON) || (y_dim == ZN_LF_DIM_ICON) ||
+ (x_dim == ZN_LF_DIM_AUTO) || (y_dim == ZN_LF_DIM_AUTO))) {
ZnSizeOfImage(fptr->image, &icon_width, &icon_height);
}
switch (x_dim) {
- case LF_DIM_FONT:
- real_width = (ZnDim) (width_spec*ZnTextWidth(fptr->font, "N", 1)/100);
+ case ZN_LF_DIM_FONT:
+ real_width = (ZnDim) (width_spec*Tk_TextWidth(fptr->font, "N", 1)/100);
break;
- case LF_DIM_ICON:
+ case ZN_LF_DIM_ICON:
real_width = (ZnDim) (width_spec*icon_width/100);
break;
- case LF_DIM_AUTO:
+ case ZN_LF_DIM_AUTO:
{
int len = 0;
ZnDim text_width;
@@ -218,20 +214,20 @@ ComputeFieldAttachment(FieldSet field_set,
/*
* The 4 extra pixels are needed for border and padding.
*/
- text_width = (ZnDim) ZnTextWidth(fptr->font, fptr->text, len) + 4;
+ text_width = (ZnDim) Tk_TextWidth(fptr->font, fptr->text, len) + 4;
real_width = text_width < real_width ? real_width : text_width;
}
real_width += (ZnDim) width_spec;
break;
}
- case LF_DIM_LABEL:
+ case ZN_LF_DIM_LABEL:
{
ZnDim lh;
GetLabelBBox(field_set, &real_width, &lh);
break;
}
- case LF_DIM_PIXEL:
+ case ZN_LF_DIM_PIXEL:
default:
real_width = (ZnDim) width_spec;
break;
@@ -239,16 +235,16 @@ ComputeFieldAttachment(FieldSet field_set,
/*printf("field %d, width = %g\n", field, real_width);*/
switch (y_dim) {
- case LF_DIM_FONT:
+ case ZN_LF_DIM_FONT:
{
Tk_GetFontMetrics(fptr->font, &fm);
real_height = (ZnDim) (height_spec*(fm.ascent + fm.descent)/100);
break;
}
- case LF_DIM_ICON:
+ case ZN_LF_DIM_ICON:
real_height = (ZnDim) (height_spec*icon_height/100);
break;
- case LF_DIM_AUTO:
+ case ZN_LF_DIM_AUTO:
{
ZnDim text_height;
@@ -264,14 +260,14 @@ ComputeFieldAttachment(FieldSet field_set,
real_height += (ZnDim) height_spec;
break;
}
- case LF_DIM_LABEL:
+ case ZN_LF_DIM_LABEL:
{
ZnDim lw;
GetLabelBBox(field_set, &lw, &real_height);
break;
}
- case LF_DIM_PIXEL:
+ case ZN_LF_DIM_PIXEL:
default:
real_height = (ZnDim) height_spec;
break;
@@ -282,8 +278,10 @@ ComputeFieldAttachment(FieldSet field_set,
* Update the cache with the newly computed infos
* (breaking of deadlocks).
*/
- field_bbox->corner.x = fptr->corner_x = real_width;
- field_bbox->corner.y = fptr->corner_y = real_height;
+ field_bbox->corner.x = real_width;
+ field_bbox->corner.y = real_height;
+ fptr->corner_x = (short) real_width;
+ fptr->corner_y = (short) real_height;
/*
* Then try to deduce the position, resolving any attachments
@@ -293,21 +291,21 @@ ComputeFieldAttachment(FieldSet field_set,
/*
* Do the x axis.
*/
- if (x_dim != LF_DIM_LABEL) {
- if (x_attach == LF_ATTACH_PIXEL) {
+ if (x_dim != ZN_LF_DIM_LABEL) {
+ if (x_attach == ZN_LF_ATTACH_PIXEL) {
field_bbox->orig.x = (ZnPos) x_spec;
field_bbox->corner.x = field_bbox->orig.x + real_width;
}
else {
ref_field = x_spec;
field_bbox->orig.x = field_bbox->corner.x = 0;
- if ((ref_field < 0) || (ref_field >= num_fields)) {
+ if (ref_field >= num_fields) {
ZnWarning ("Attached (x) to an inexistant field geometry\n");
}
else {
ComputeFieldAttachment(field_set, ref_field, &ref_bbox);
switch (x_attach) {
- case LF_ATTACH_FWD:
+ case ZN_LF_ATTACH_FWD:
if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) {
field_bbox->orig.x = ref_bbox.corner.x;
}
@@ -316,7 +314,7 @@ ComputeFieldAttachment(FieldSet field_set,
}
field_bbox->corner.x = field_bbox->orig.x + real_width;
break;
- case LF_ATTACH_BWD:
+ case ZN_LF_ATTACH_BWD:
if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) {
field_bbox->corner.x = ref_bbox.orig.x;
}
@@ -325,11 +323,11 @@ ComputeFieldAttachment(FieldSet field_set,
}
field_bbox->orig.x = field_bbox->corner.x - real_width;
break;
- case LF_ATTACH_LEFT:
+ case ZN_LF_ATTACH_LEFT:
field_bbox->orig.x = ref_bbox.orig.x;
field_bbox->corner.x = field_bbox->orig.x + real_width;
break;
- case LF_ATTACH_RIGHT:
+ case ZN_LF_ATTACH_RIGHT:
if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) {
field_bbox->corner.x = ref_bbox.corner.x;
}
@@ -347,21 +345,21 @@ ComputeFieldAttachment(FieldSet field_set,
/*
* Then the y axis.
*/
- if (y_dim != LF_DIM_LABEL) {
- if (y_attach == LF_ATTACH_PIXEL) {
+ if (y_dim != ZN_LF_DIM_LABEL) {
+ if (y_attach == ZN_LF_ATTACH_PIXEL) {
field_bbox->orig.y = (ZnPos) y_spec;
field_bbox->corner.y = field_bbox->orig.y + real_height;
}
else {
ref_field = y_spec;
field_bbox->orig.y = field_bbox->corner.y = 0;
- if ((ref_field < 0) || (ref_field >= num_fields)) {
+ if (ref_field >= num_fields) {
ZnWarning ("Attached (y) to an inexistant field geometry\n");
}
else {
ComputeFieldAttachment(field_set, ref_field, &ref_bbox);
switch (y_attach) {
- case LF_ATTACH_FWD:
+ case ZN_LF_ATTACH_FWD:
if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) {
field_bbox->orig.y = ref_bbox.corner.y;
}
@@ -370,7 +368,7 @@ ComputeFieldAttachment(FieldSet field_set,
}
field_bbox->corner.y = field_bbox->orig.y + real_height;
break;
- case LF_ATTACH_BWD:
+ case ZN_LF_ATTACH_BWD:
if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) {
field_bbox->corner.y = ref_bbox.orig.y;
}
@@ -379,11 +377,11 @@ ComputeFieldAttachment(FieldSet field_set,
}
field_bbox->orig.y = field_bbox->corner.y - real_height;
break;
- case LF_ATTACH_LEFT:
+ case ZN_LF_ATTACH_LEFT:
field_bbox->orig.y = ref_bbox.orig.y;
field_bbox->corner.y = field_bbox->orig.y + real_height;
break;
- case LF_ATTACH_RIGHT:
+ case ZN_LF_ATTACH_RIGHT:
if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) {
field_bbox->corner.y = ref_bbox.corner.y;
}
@@ -417,10 +415,10 @@ ComputeFieldAttachment(FieldSet field_set,
**********************************************************************************
*/
static void
-ClearFieldCache(FieldSet field_set,
+ClearFieldCache(ZnFieldSet field_set,
int field)
{
- int i, num_fields;
+ unsigned int i, num_fields;
ZnBool clear_bbox;
int x_spec, y_spec;
char x_attach, y_attach, x_dim, y_dim;
@@ -441,35 +439,35 @@ ClearFieldCache(FieldSet field_set,
if (!field_set->label_format) {
return;
}
- num_fields = LabelFormatNumFields(field_set->label_format);
- if (field >= num_fields) {
+ num_fields = ZnLFNumFields(field_set->label_format);
+ if ((unsigned int) field >= num_fields) {
return;
}
- LabelFormatGetField(field_set->label_format, field,
- &x_attach, &y_attach, &x_dim, &y_dim,
- &x_spec, &y_spec, &width_spec, &height_spec);
- if ((x_dim != LF_DIM_PIXEL) || (y_dim != LF_DIM_PIXEL)) {
+ ZnLFGetField(field_set->label_format, (unsigned int) field,
+ &x_attach, &y_attach, &x_dim, &y_dim,
+ &x_spec, &y_spec, &width_spec, &height_spec);
+ if ((x_dim != ZN_LF_DIM_PIXEL) || (y_dim != ZN_LF_DIM_PIXEL)) {
CLEAR(field_set->fields[field].flags, CACHE_OK);
clear_bbox = True;
}
for (i = 0; i < num_fields; i++) {
- LabelFormatGetField(field_set->label_format, i,
- &x_attach, &y_attach, &x_dim, &y_dim,
- &x_spec, &y_spec, &width_spec, &height_spec);
- if ((x_attach == LF_ATTACH_PIXEL) && (y_attach == LF_ATTACH_PIXEL)) {
+ ZnLFGetField(field_set->label_format, i,
+ &x_attach, &y_attach, &x_dim, &y_dim,
+ &x_spec, &y_spec, &width_spec, &height_spec);
+ if ((x_attach == ZN_LF_ATTACH_PIXEL) && (y_attach == ZN_LF_ATTACH_PIXEL)) {
continue;
}
- if (x_attach != LF_ATTACH_PIXEL) {
+ if (x_attach != ZN_LF_ATTACH_PIXEL) {
if ((x_spec == field) && ISSET(field_set->fields[i].flags, CACHE_OK)) {
CLEAR(field_set->fields[i].flags, CACHE_OK);
- ClearFieldCache(field_set, i);
+ ClearFieldCache(field_set, (int) i);
clear_bbox = True;
}
}
- if (y_attach != LF_ATTACH_PIXEL) {
+ if (y_attach != ZN_LF_ATTACH_PIXEL) {
if ((y_spec == field) && ISSET(field_set->fields[i].flags, CACHE_OK)) {
CLEAR(field_set->fields[i].flags, CACHE_OK);
- ClearFieldCache(field_set, i);
+ ClearFieldCache(field_set, (int) i);
clear_bbox = True;
}
}
@@ -489,13 +487,13 @@ ClearFieldCache(FieldSet field_set,
**********************************************************************************
*/
static void
-GetLabelBBox(FieldSet field_set,
+GetLabelBBox(ZnFieldSet field_set,
ZnDim *w,
ZnDim *h)
{
ZnBBox bbox, tmp_bbox;
ZnLabelFormat lf;
- int i, num_fields;
+ unsigned int i, num_fields;
ZnDim clip_w, clip_h;
if ((field_set->label_width >= 0.0) && (field_set->label_height >= 0.0)) {
@@ -510,20 +508,20 @@ GetLabelBBox(FieldSet field_set,
return;
}
- ResetBBox(&bbox);
- num_fields = LabelFormatNumFields(lf);
+ ZnResetBBox(&bbox);
+ num_fields = ZnLFNumFields(lf);
for (i = 0; i < num_fields; i++) {
ComputeFieldAttachment(field_set, i, &tmp_bbox);
/*printf("field %d bbox %g %g %g %g\n", i, tmp_bbox.orig.x, tmp_bbox.orig.y,
tmp_bbox.corner.x, tmp_bbox.corner.y);*/
- AddBBoxToBBox(&bbox, &tmp_bbox);
+ ZnAddBBoxToBBox(&bbox, &tmp_bbox);
}
field_set->label_width = bbox.corner.x;
field_set->label_height = bbox.corner.y;
/*printf("GetLabelBBox size before clipping; w = %g, h = %g\n",
field_set->label_width, field_set->label_height);*/
- if (LabelFormatGetClipBox(lf, &clip_w, &clip_h)) {
+ if (ZnLFGetClipBox(lf, &clip_w, &clip_h)) {
if (clip_w < field_set->label_width) {
field_set->label_width = clip_w;
}
@@ -548,15 +546,15 @@ GetLabelBBox(FieldSet field_set,
**********************************************************************************
*/
static void
-GetFieldBBox(FieldSet field_set,
+GetFieldBBox(ZnFieldSet field_set,
unsigned int index,
ZnBBox *field_bbox)
{
ZnReal ox, oy;
if (field_set->label_format) {
- ox = REAL_TO_INT(field_set->label_pos.x);
- oy = REAL_TO_INT(field_set->label_pos.y);
+ ox = ZnNearestInt(field_set->label_pos.x);
+ oy = ZnNearestInt(field_set->label_pos.y);
ComputeFieldAttachment(field_set, index, field_bbox);
field_bbox->orig.x += ox;
field_bbox->orig.y += oy;
@@ -564,7 +562,7 @@ GetFieldBBox(FieldSet field_set,
field_bbox->corner.y += oy;
}
else {
- ResetBBox(field_bbox);
+ ZnResetBBox(field_bbox);
}
}
@@ -592,7 +590,7 @@ ComputeFieldTextLocation(Field fptr,
Tk_GetFontMetrics(fptr->font, &fm);
w = 0;
if (fptr->text) {
- w = ZnTextWidth(fptr->font, fptr->text, strlen(fptr->text));
+ w = Tk_TextWidth(fptr->font, fptr->text, (int) strlen(fptr->text));
}
h = fm.ascent + fm.descent;
text_bbox->orig.y = (bbox->orig.y + bbox->corner.y - h) / 2.0;
@@ -600,10 +598,10 @@ ComputeFieldTextLocation(Field fptr,
pos->y = text_bbox->orig.y + fm.ascent;
switch (fptr->alignment) {
- case ZnJustifyLeft:
+ case TK_JUSTIFY_LEFT:
text_bbox->orig.x = bbox->orig.x + 2;
break;
- case ZnJustifyRight:
+ case TK_JUSTIFY_RIGHT:
text_bbox->orig.x = bbox->corner.x - w - 2;
break;
default:
@@ -625,7 +623,7 @@ ComputeFieldTextLocation(Field fptr,
**********************************************************************************
*/
static void
-LeaderToLabel(FieldSet field_set,
+LeaderToLabel(ZnFieldSet field_set,
ZnPoint *start,
ZnPoint *end)
{
@@ -633,7 +631,7 @@ LeaderToLabel(FieldSet field_set,
ZnPoint delta, inf, sup;
ZnPos xt=0, yu=0, yw=0, xv=0;
Field fptr;
- int i;
+ unsigned int i;
ZnBBox field_bbox;
/* Intersection points : */
@@ -646,9 +644,9 @@ LeaderToLabel(FieldSet field_set,
delta.x = start->x - end->x;
delta.y = start->y - end->y;
- b_num = start->y*delta.x - start->x*delta.y;
+ b_num = (int) (start->y*delta.x - start->x*delta.y);
- for (i = 0; i < LabelFormatNumFields(field_set->label_format); i++) {
+ for (i = 0; i < ZnLFNumFields(field_set->label_format); i++) {
fptr = &field_set->fields[i];
/*
* If the field is made invisible or has no graphics of
@@ -657,8 +655,8 @@ LeaderToLabel(FieldSet field_set,
if (ISCLEAR(fptr->flags, FIELD_VISIBLE_BIT) ||
(!fptr->text &&
ISCLEAR(fptr->flags, FILLED_BIT) &&
- (fptr->border_edges == NO_BORDER) &&
- (fptr->relief == RELIEF_FLAT) &&
+ (fptr->border_edges == ZN_NO_BORDER) &&
+ (fptr->relief == ZN_RELIEF_FLAT) &&
(fptr->image == ZnUnspecifiedImage))) {
continue;
}
@@ -674,14 +672,14 @@ LeaderToLabel(FieldSet field_set,
*/
if (fptr->text &&
ISCLEAR(fptr->flags, FILLED_BIT) &&
- (fptr->border_edges == NO_BORDER) &&
- (fptr->relief == RELIEF_FLAT) &&
+ (fptr->border_edges == ZN_NO_BORDER) &&
+ (fptr->relief == ZN_RELIEF_FLAT) &&
(fptr->image == ZnUnspecifiedImage)) {
ZnBBox text_bbox;
ZnPoint text_pos; /* dummy */
int space_width;
int scan_forw, scan_back;
- space_width = ZnTextWidth(fptr->font, " ", 1);
+ space_width = Tk_TextWidth(fptr->font, " ", 1);
ComputeFieldTextLocation(fptr, &field_bbox, &text_pos, &text_bbox);
/*
@@ -799,23 +797,20 @@ LeaderToLabel(FieldSet field_set,
*
* InitFields --
*
- * Perform the init of each field in a FieldSet. The number of such
+ * Perform the init of each field in a ZnFieldSet. The number of such
* fields must have been inited before calling this fun.
*
**********************************************************************************
*/
static void
-InitFields(FieldSet field_set)
+InitFields(ZnFieldSet field_set)
{
- WidgetInfo *wi = field_set->item->wi;
+ ZnWInfo *wi = field_set->item->wi;
Field field;
unsigned int i, num_fields;
/*printf("size of a field = %d\n", sizeof(FieldStruct));*/
- if (field_set->num_fields < 0) {
- field_set->num_fields = 0;
- }
if (!field_set->num_fields) {
return;
}
@@ -838,17 +833,17 @@ InitFields(FieldSet field_set)
field->image = ZnUnspecifiedImage;
field->tile = ZnUnspecifiedImage;
field->font = Tk_GetFont(wi->interp, wi->win, Tk_NameOfFont(wi->font));
-#ifdef GLX
+#ifdef GL
field->tfi = NULL;
if (wi->render) {
field->tfi = ZnGetTexFont(wi, field->font);
}
#endif
- field->border_edges = NO_BORDER;
- field->alignment = ZnJustifyLeft;
+ field->border_edges = ZN_NO_BORDER;
+ field->alignment = TK_JUSTIFY_LEFT;
field->auto_alignment.automatic = False;
- field->relief = RELIEF_FLAT;
+ field->relief = ZN_RELIEF_FLAT;
field->relief_thickness = 2;
SET(field->flags, TEXT_ON_TOP_BIT);
@@ -868,9 +863,9 @@ InitFields(FieldSet field_set)
**********************************************************************************
*/
static void
-CloneFields(FieldSet field_set)
+CloneFields(ZnFieldSet field_set)
{
- WidgetInfo *wi = field_set->item->wi;
+ ZnWInfo *wi = field_set->item->wi;
Field field, fields_ret;
unsigned int i, num_fields;
char *text;
@@ -880,7 +875,7 @@ CloneFields(FieldSet field_set)
return;
}
if (field_set->label_format) {
- field_set->label_format = LabelFormatDuplicate(field_set->label_format);
+ field_set->label_format = ZnLFDuplicate(field_set->label_format);
}
fields_ret = (Field) ZnMalloc(num_fields*sizeof(FieldStruct));
memcpy(fields_ret, field_set->fields, num_fields*sizeof(FieldStruct));
@@ -906,7 +901,7 @@ CloneFields(FieldSet field_set)
field->fill_pattern = ZnGetImageByValue(field->fill_pattern);
}
field->font = Tk_GetFont(wi->interp, wi->win, Tk_NameOfFont(field->font));
-#ifdef GLX
+#ifdef GL
if (wi->render) {
field->tfi = ZnGetTexFont(wi, field->font);
}
@@ -932,47 +927,48 @@ CloneFields(FieldSet field_set)
**********************************************************************************
*/
static int
-ConfigureField(FieldSet fs,
+ConfigureField(ZnFieldSet fs,
int field,
int argc,
Tcl_Obj *CONST argv[],
int *flags)
{
- int i;
+ unsigned int i;
Field fptr;
ZnBBox bbox;
- WidgetInfo *wi = fs->item->wi;
+ ZnWInfo *wi = fs->item->wi;
XColor *color;
- int alpha, old_num_chars, num_chars;
-#ifdef GLX
- ZnFont old_font;
+ unsigned short alpha;
+ int old_num_chars, num_chars;
+#ifdef GL
+ Tk_Font old_font;
#endif
- if ((field == ZN_NO_PART) || (field >= fs->num_fields)) {
+ if ((field < 0) || ((unsigned int) field >= fs->num_fields)) {
Tcl_AppendResult(wi->interp, "invalid field index", NULL);
- return ZN_ERROR;
+ return TCL_ERROR;
}
fptr = &fs->fields[field];
-#ifdef GLX
+#ifdef GL
old_font = fptr->font;
#endif
old_num_chars = 0;
if (fptr->text) {
- old_num_chars = Tcl_NumUtfChars(fptr->text, strlen(fptr->text));
+ old_num_chars = Tcl_NumUtfChars(fptr->text, (int) strlen(fptr->text));
}
if (ZnConfigureAttributes(wi, fptr, field_attrs,
- argc, argv, flags) == ZN_ERROR) {
- return ZN_ERROR;
+ argc, argv, flags) == TCL_ERROR) {
+ return TCL_ERROR;
}
num_chars = 0;
if (fptr->text) {
- num_chars = Tcl_NumUtfChars(fptr->text, strlen(fptr->text));
+ num_chars = Tcl_NumUtfChars(fptr->text, (int) strlen(fptr->text));
}
if (old_num_chars != num_chars) {
- TextInfo *ti = &wi->text_info;
+ ZnTextInfo *ti = &wi->text_info;
/*
* The text has changed, update the selection and
* insertion pos to keep them valid.
@@ -995,7 +991,7 @@ ConfigureField(FieldSet fs,
}
}
-#ifdef GLX
+#ifdef GL
if (old_font != fptr->font) {
if (fptr->tfi) {
ZnFreeTexFont(fptr->tfi);
@@ -1005,30 +1001,30 @@ ConfigureField(FieldSet fs,
if (!fptr->tfi) {
Tcl_AppendResult(wi->interp, "impossible to get the texture for font \"",
Tk_NameOfFont(fptr->font), "\"", NULL);
- return ZN_ERROR;
+ return TCL_ERROR;
}
}
}
#endif
if (ISSET(*flags, ZN_REPICK_FLAG)) {
- SET(wi->events_flags, INTERNAL_NEED_REPICK);
+ SET(wi->flags, ZN_INTERNAL_NEED_REPICK);
}
if (ISSET(*flags, ZN_CLFC_FLAG)) {
ClearFieldCache(fs, field);
}
if (fptr->gradient &&
- (ISSET(*flags, ZN_BORDER_FLAG) || (fptr->relief == RELIEF_FLAT))) {
+ (ISSET(*flags, ZN_BORDER_FLAG) || (fptr->relief == ZN_RELIEF_FLAT))) {
ZnFreeGradient(fptr->gradient);
fptr->gradient = NULL;
}
- if ((fptr->relief != RELIEF_FLAT) && !fptr->gradient) {
+ if ((fptr->relief != ZN_RELIEF_FLAT) && !fptr->gradient) {
color = ZnGetGradientColor(fptr->border_color, 51.0, &alpha);
fptr->gradient = ZnGetReliefGradient(wi->interp, wi->win,
- ZnNameOfColor(color), alpha);
+ Tk_NameOfColor(color), alpha);
if (fptr->gradient == NULL) {
- return ZN_ERROR;
+ return TCL_ERROR;
}
}
@@ -1038,8 +1034,8 @@ ConfigureField(FieldSet fs,
*/
if (ISCLEAR(*flags, ZN_COORDS_FLAG) &&
fs->label_format && ISSET(*flags, ZN_DRAW_FLAG)) {
- for (i = 0; i < LabelFormatNumFields(fs->label_format); i++) {
- if (i == field) {
+ for (i = 0; i < ZnLFNumFields(fs->label_format); i++) {
+ if (i == (unsigned int) field) {
GetFieldBBox(fs, i, &bbox);
ZnDamage(wi, &bbox);
break;
@@ -1047,7 +1043,7 @@ ConfigureField(FieldSet fs,
}
}
- return ZN_OK;
+ return TCL_OK;
}
@@ -1059,22 +1055,22 @@ ConfigureField(FieldSet fs,
**********************************************************************************
*/
static int
-QueryField(FieldSet fs,
+QueryField(ZnFieldSet fs,
int field,
- int argc,
+ int argc __unused,
Tcl_Obj *CONST argv[])
{
- if ((field == ZN_NO_PART) || (field >= fs->num_fields)) {
+ if ((field < 0) || ((unsigned int) field >= fs->num_fields)) {
Tcl_AppendResult(fs->item->wi->interp, "invalid field index \"", NULL);
- return ZN_ERROR;
+ return TCL_ERROR;
}
if (ZnQueryAttribute(fs->item->wi, &fs->fields[field], field_attrs,
- argv[0]) == ZN_ERROR) {
- return ZN_ERROR;
+ argv[0]) == TCL_ERROR) {
+ return TCL_ERROR;
}
- return ZN_OK;
+ return TCL_OK;
}
@@ -1086,13 +1082,13 @@ QueryField(FieldSet fs,
**********************************************************************************
*/
static void
-FreeFields(FieldSet field_set)
+FreeFields(ZnFieldSet field_set)
{
unsigned int i, num_fields;
Field field;
if (field_set->label_format) {
- LabelFormatDelete(field_set->label_format);
+ ZnLFDelete(field_set->label_format);
}
num_fields = field_set->num_fields;
@@ -1121,7 +1117,7 @@ FreeFields(FieldSet field_set)
field->fill_pattern = ZnUnspecifiedImage;
}
Tk_FreeFont(field->font);
-#ifdef GLX
+#ifdef GL
if (field->tfi) {
ZnFreeTexFont(field->tfi);
}
@@ -1150,16 +1146,16 @@ FreeFields(FieldSet field_set)
**********************************************************************************
*/
static int
-FieldPointToChar(FieldSet fs,
- int field,
+FieldPointToChar(ZnFieldSet fs,
+ unsigned int field,
int x,
int y)
{
Field fptr;
- int num_bytes, byte_index;
+ int byte_index;
ZnBBox f_bbox, t_bbox;
ZnPoint t_orig;
- int n, dummy;
+ unsigned int num_bytes, n, dummy;
fptr = &fs->fields[field];
num_bytes = 0;
@@ -1199,16 +1195,16 @@ FieldPointToChar(FieldSet fs,
goto convrt;
}
n = Tk_MeasureChars(fptr->font, fptr->text, num_bytes,
- x + 2 - t_bbox.orig.x, TK_PARTIAL_OK, &dummy);
+ x + 2 - (int) t_bbox.orig.x, TK_PARTIAL_OK, &dummy);
byte_index = n - 1;
goto convrt;
}
/*
* Point below all lines, return the index after
* the last char.
- */
- convrt:
+ */
byte_index = num_bytes;
+ convrt:
return Tcl_NumUtfChars(fptr->text, byte_index);
}
@@ -1245,22 +1241,22 @@ WordMoveFromIndex(char *text,
}
static int
-FieldIndex(FieldSet fs,
+FieldIndex(ZnFieldSet fs,
int field,
Tcl_Obj *index_spec,
int *index)
{
Field fptr;
- WidgetInfo *wi = fs->item->wi;
- TextInfo *ti = &wi->text_info;
- int c, length;
- int x, y;
+ ZnWInfo *wi = fs->item->wi;
+ ZnTextInfo *ti = &wi->text_info;
+ unsigned int length;
+ int c, x, y;
double tmp;
char *end, *p;
- if ((field == ZN_NO_PART) || (field >= fs->num_fields)) {
+ if ((field < 0) || ((unsigned int) field >= fs->num_fields)) {
*index = 0;
- return ZN_OK;
+ return TCL_OK;
}
fptr = &fs->fields[field];
@@ -1270,10 +1266,10 @@ FieldIndex(FieldSet fs,
length = strlen(p);
if ((c == 'e') && (strncmp(p, "end", length) == 0)) {
- *index = fptr->text?Tcl_NumUtfChars(fptr->text, strlen(fptr->text)):0;
+ *index = fptr->text ? Tcl_NumUtfChars(fptr->text, (int) strlen(fptr->text)) : 0;
}
else if ((c == 'e') && (length > 1) && (strncmp(p, "eol", length) == 0)) {
- *index = fptr->text?Tcl_NumUtfChars(fptr->text, strlen(fptr->text)):0;
+ *index = fptr->text ? Tcl_NumUtfChars(fptr->text, (int) strlen(fptr->text)) : 0;
}
else if ((c == 'b') && (length > 1) && (strncmp(p, "bol", length) == 0)) {
*index = 0;
@@ -1298,7 +1294,7 @@ FieldIndex(FieldSet fs,
if ((ti->sel_item != fs->item) || (ti->sel_field != field)) {
sel_err:
Tcl_AppendResult(wi->interp, "selection isn't in field", (char *) NULL);
- return ZN_ERROR;
+ return TCL_ERROR;
}
*index = ti->sel_first;
}
@@ -1320,18 +1316,18 @@ FieldIndex(FieldSet fs,
if ((end == p) || (*end != ',')) {
goto badIndex;
}
- x = tmp;
+ x = (int) tmp;
p = end+1;
tmp = strtod(p, &end);
if ((end == p) || (*end != 0)) {
goto badIndex;
}
- y = tmp;
+ y = (int) tmp;
- *index = FieldPointToChar(fs, field, x, y);
+ *index = FieldPointToChar(fs, (unsigned int) field, x, y);
}
else if (Tcl_GetIntFromObj(wi->interp, index_spec, index) == TCL_OK) {
- int num_chars = fptr->text?Tcl_NumUtfChars(fptr->text, strlen(fptr->text)):0;
+ int num_chars = fptr->text ? Tcl_NumUtfChars(fptr->text, (int) strlen(fptr->text)) : 0;
if (*index < 0){
*index = 0;
}
@@ -1342,25 +1338,25 @@ FieldIndex(FieldSet fs,
else {
badIndex:
Tcl_AppendResult(wi->interp, "bad index \"", p, "\"", (char *) NULL);
- return ZN_ERROR;
+ return TCL_ERROR;
}
- return ZN_OK;
+ return TCL_OK;
}
static ZnBool
-FieldInsertChars(FieldSet fs,
+FieldInsertChars(ZnFieldSet fs,
int field,
int *index,
char *chars)
{
- Field fptr;
- TextInfo *ti = &fs->item->wi->text_info;
- int num_chars, num_bytes, chars_added;
- int byte_index, bytes_added = strlen(chars);
- char *new;
+ Field fptr;
+ ZnTextInfo *ti = &fs->item->wi->text_info;
+ int num_chars, num_bytes, chars_added;
+ unsigned int byte_index, bytes_added = strlen(chars);
+ char *new;
- if ((field == ZN_NO_PART) || (field >= fs->num_fields)) {
+ if ((field < 0) || ((unsigned int) field >= fs->num_fields)) {
return False;
}
@@ -1381,8 +1377,8 @@ FieldInsertChars(FieldSet fs,
if (*index > num_chars) {
*index = num_chars;
}
- byte_index = Tcl_UtfAtIndex(fptr->text, *index)-fptr->text;
- chars_added = Tcl_NumUtfChars(chars, bytes_added);
+ byte_index = Tcl_UtfAtIndex(fptr->text, *index) - fptr->text;
+ chars_added = Tcl_NumUtfChars(chars, (int) bytes_added);
new = ZnMalloc(num_bytes + bytes_added + 1);
if (fptr->text) {
@@ -1397,7 +1393,7 @@ FieldInsertChars(FieldSet fs,
/*
* Insert the new text.
*/
- strcpy(new + byte_index, chars);
+ memcpy(new + byte_index, chars, bytes_added);
fptr->text = new;
if (fptr->insert_index >= *index) {
@@ -1424,18 +1420,18 @@ FieldInsertChars(FieldSet fs,
}
static ZnBool
-FieldDeleteChars(FieldSet fs,
+FieldDeleteChars(ZnFieldSet fs,
int field,
int *first,
int *last)
{
- Field fptr;
- TextInfo *ti = &fs->item->wi->text_info;
- int char_count, byte_count;
- int num_bytes, num_chars, first_offset;
- char *new;
+ Field fptr;
+ ZnTextInfo *ti = &fs->item->wi->text_info;
+ unsigned int char_count, byte_count;
+ unsigned int num_bytes, num_chars, first_offset;
+ char *new;
- if ((field == ZN_NO_PART) || (field >= fs->num_fields)) {
+ if ((field < 0) || ((unsigned int) field >= fs->num_fields)) {
return False;
}
@@ -1444,7 +1440,7 @@ FieldDeleteChars(FieldSet fs,
num_bytes = 0;
if (fptr->text) {
num_bytes = strlen(fptr->text);
- num_chars = Tcl_NumUtfChars(fptr->text, num_bytes);
+ num_chars = Tcl_NumUtfChars(fptr->text, (int) num_bytes);
}
if (num_chars == 0) {
return False;
@@ -1453,7 +1449,7 @@ FieldDeleteChars(FieldSet fs,
if (*first < 0) {
*first = 0;
}
- if (*last >= num_chars) {
+ if (*last >= (int) num_chars) {
*last = num_chars-1;
}
if (*first > *last) {
@@ -1461,7 +1457,7 @@ FieldDeleteChars(FieldSet fs,
}
char_count = *last + 1 - *first;
first_offset = Tcl_UtfAtIndex(fptr->text, *first)-fptr->text;
- byte_count = Tcl_UtfAtIndex(fptr->text + first_offset, char_count)-
+ byte_count = Tcl_UtfAtIndex(fptr->text + first_offset, (int) char_count) -
(fptr->text+first_offset);
if (num_bytes - byte_count) {
@@ -1518,21 +1514,21 @@ FieldDeleteChars(FieldSet fs,
}
static void
-FieldCursor(FieldSet fs,
+FieldCursor(ZnFieldSet fs,
int field,
int index)
{
Field fptr;
int num_chars;
- if ((field == ZN_NO_PART) || (field >= fs->num_fields)) {
+ if ((field < 0) || ((unsigned int) field >= fs->num_fields)) {
return;
}
fptr = &fs->fields[field];
num_chars = 0;
if (fptr->text) {
- num_chars = Tcl_NumUtfChars(fptr->text, strlen(fptr->text));
+ num_chars = Tcl_NumUtfChars(fptr->text, (int) strlen(fptr->text));
}
if (index < 0) {
@@ -1547,7 +1543,7 @@ FieldCursor(FieldSet fs,
}
static int
-FieldSelection(FieldSet fs,
+FieldSelection(ZnFieldSet fs,
int field,
int offset,
char *chars,
@@ -1556,9 +1552,9 @@ FieldSelection(FieldSet fs,
Field fptr;
int count;
char const *sel_first, *sel_last;
- TextInfo *ti;
+ ZnTextInfo *ti;
- if ((field == ZN_NO_PART) || (field >= fs->num_fields)) {
+ if ((field < 0) || ((unsigned int) field >= fs->num_fields)) {
return 0;
}
ti = &fs->item->wi->text_info;
@@ -1610,10 +1606,10 @@ ComputeFieldImageLocation(Field fptr,
pm_bbox->corner.y = pm_bbox->orig.y + height;
switch (fptr->alignment) {
- case ZnJustifyLeft:
+ case TK_JUSTIFY_LEFT:
pm_bbox->orig.x = bbox->orig.x;
break;
- case ZnJustifyRight:
+ case TK_JUSTIFY_RIGHT:
pm_bbox->orig.x = bbox->corner.x - width - 1;
break;
default:
@@ -1632,14 +1628,14 @@ ComputeFieldImageLocation(Field fptr,
**********************************************************************************
*/
static void
-FieldsEngine(FieldSet field_set,
+FieldsEngine(ZnFieldSet field_set,
void (*cb)())
{
- WidgetInfo *wi = field_set->item->wi;
- int i; /* This one *NEED* to be an int */
- int num_fields, num_chars;
+ ZnWInfo *wi = field_set->item->wi;
+ /*int i; This one *NEED* to be an int */
+ unsigned int i, num_fields, num_chars;
Field fptr;
- TextInfo *ti = &wi->text_info;
+ ZnTextInfo *ti = &wi->text_info;
ZnBBox lclip_bbox, fclip_bbox, bbox, *global_clip_box;
ZnBBox tmp_bbox, text_bbox, pm_bbox;
ZnPoint pts[2];
@@ -1655,17 +1651,17 @@ FieldsEngine(FieldSet field_set,
return;
}
- if (field_set->label_format && LabelFormatNumFields(field_set->label_format)) {
- bbox.orig.x = REAL_TO_INT(field_set->label_pos.x);
- bbox.orig.y = REAL_TO_INT(field_set->label_pos.y);
+ if (field_set->label_format && ZnLFNumFields(field_set->label_format)) {
+ bbox.orig.x = ZnNearestInt(field_set->label_pos.x);
+ bbox.orig.y = ZnNearestInt(field_set->label_pos.y);
GetLabelBBox(field_set, &lwidth, &lheight);
bbox.corner.x = bbox.orig.x + lwidth;
bbox.corner.y = bbox.orig.y + lheight;
ZnCurrentClip(wi, NULL, &global_clip_box, NULL);
if (!wi->render) {
- IntersectBBox(global_clip_box, &bbox, &lclip_bbox);
- if (IsEmptyBBox(&lclip_bbox)) {
+ ZnIntersectBBox(global_clip_box, &bbox, &lclip_bbox);
+ if (ZnIsEmptyBBox(&lclip_bbox)) {
return;
}
}
@@ -1673,7 +1669,7 @@ FieldsEngine(FieldSet field_set,
lclip_bbox = bbox;
}
- num_fields = LabelFormatNumFields(field_set->label_format);
+ num_fields = ZnLFNumFields(field_set->label_format);
for (i = 0; i < num_fields; i++) {
fptr = &field_set->fields[i];
@@ -1682,8 +1678,8 @@ FieldsEngine(FieldSet field_set,
}
GetFieldBBox(field_set, i, &bbox);
- IntersectBBox(&lclip_bbox, &bbox, &fclip_bbox);
- if (IsEmptyBBox(&fclip_bbox)) {
+ ZnIntersectBBox(&lclip_bbox, &bbox, &fclip_bbox);
+ if (ZnIsEmptyBBox(&fclip_bbox)) {
continue;
}
@@ -1702,16 +1698,17 @@ FieldsEngine(FieldSet field_set,
if (fptr->text) {
if ((field_set->item == wi->focus_item) &&
- (wi->focus_field == i) && wi->got_focus && ti->cursor_on) {
+ ((unsigned int) wi->focus_field == i) &&
+ ISSET(wi->flags, ZN_GOT_FOCUS) && ti->cursor_on) {
cursor = Tk_TextWidth(fptr->font, fptr->text,
Tcl_UtfAtIndex(fptr->text,
fptr->insert_index)-fptr->text);
}
ComputeFieldTextLocation(fptr, &bbox, &text_pos, &text_bbox);
- num_chars = Tcl_NumUtfChars(fptr->text, strlen(fptr->text));
+ num_chars = Tcl_NumUtfChars(fptr->text, (int) strlen(fptr->text));
if (num_chars) {
- if ((field_set->item == ti->sel_item) && (ti->sel_field == i) &&
- (ti->sel_last >= 0) && (ti->sel_first <= num_chars)) {
+ if ((field_set->item == ti->sel_item) && ((unsigned int) ti->sel_field == i) &&
+ (ti->sel_last >= 0) && (ti->sel_first <= (int) num_chars)) {
sel_start = Tk_TextWidth(fptr->font, fptr->text,
Tcl_UtfAtIndex(fptr->text,
ti->sel_first)-fptr->text);
@@ -1720,7 +1717,7 @@ FieldsEngine(FieldSet field_set,
ti->sel_last)-fptr->text);
}
- IntersectBBox(&fclip_bbox, &text_bbox, &tmp_bbox);
+ ZnIntersectBBox(&fclip_bbox, &text_bbox, &tmp_bbox);
val = tmp_bbox.orig.x - text_bbox.orig.x;
restore |= val > 0;
@@ -1736,7 +1733,7 @@ FieldsEngine(FieldSet field_set,
if (fptr->image != ZnUnspecifiedImage) {
ComputeFieldImageLocation(fptr, &bbox, &pm_bbox);
- IntersectBBox(&fclip_bbox, &pm_bbox, &tmp_bbox);
+ ZnIntersectBBox(&fclip_bbox, &pm_bbox, &tmp_bbox);
val = tmp_bbox.orig.x - pm_bbox.orig.x;
restore |= val > 0;
@@ -1754,7 +1751,7 @@ FieldsEngine(FieldSet field_set,
/*printf("clip: %d\n", i);*/
pts[0] = fclip_bbox.orig;
pts[1] = fclip_bbox.corner;
- TRI_STRIP1(&tristrip, pts, 2, False);
+ ZnTriStrip1(&tristrip, pts, 2, False);
ZnPushClip(wi, &tristrip, True, True);
}
@@ -1779,7 +1776,7 @@ FieldsEngine(FieldSet field_set,
**********************************************************************************
*/
static void
-DrawField(WidgetInfo *wi,
+DrawField(ZnWInfo *wi,
Field fptr,
ZnBBox *bbox,
ZnBBox *pm_bbox,
@@ -1789,16 +1786,17 @@ DrawField(WidgetInfo *wi,
int sel_start,
int sel_stop)
{
- TextInfo *ti = &wi->text_info;
+ ZnTextInfo *ti = &wi->text_info;
XGCValues values;
XRectangle r;
int j, xs, num_bytes;
int pw, ph, fw, fh;
- Region clip_region;
+ TkRegion clip_region;
ZnBool simple;
- Pixmap pixmap, mask_pmap;
-
- BBox2XRect(bbox, &r);
+ Pixmap pixmap;
+ TkRegion photo_region, clip;
+
+ ZnBBox2XRect(bbox, &r);
/*
* Draw the background.
@@ -1808,7 +1806,7 @@ DrawField(WidgetInfo *wi,
if (fptr->tile != ZnUnspecifiedImage) { /* Fill tiled */
values.fill_style = FillTiled;
- values.tile = ZnImagePixmap(fptr->tile, NULL);
+ values.tile = ZnImagePixmap(fptr->tile);
values.ts_x_origin = (int) bbox->orig.x;
values.ts_y_origin = (int) bbox->orig.y;
XChangeGC(wi->dpy, wi->gc,
@@ -1817,7 +1815,7 @@ DrawField(WidgetInfo *wi,
}
else if (fptr->fill_pattern != ZnUnspecifiedImage) { /* Fill stippled */
values.fill_style = FillStippled;
- values.stipple = ZnImagePixmap(fptr->fill_pattern, NULL);
+ values.stipple = ZnImagePixmap(fptr->fill_pattern);
values.ts_x_origin = (int) bbox->orig.x;
values.ts_y_origin = (int) bbox->orig.y;
XChangeGC(wi->dpy, wi->gc,
@@ -1842,31 +1840,44 @@ DrawField(WidgetInfo *wi,
* Draw the image.
*/
if (fptr->image != ZnUnspecifiedImage) {
- pixmap = ZnImagePixmap(fptr->image, &mask_pmap);
- if (mask_pmap != ZnUnspecifiedImage) {
- ZnCurrentClip(wi, &clip_region, NULL, &simple);
- XSetClipMask(wi->dpy, wi->gc, mask_pmap);
- XSetClipOrigin(wi->dpy, wi->gc, pm_bbox->orig.x, pm_bbox->orig.y);
- }
+ pw = ZnNearestInt(pm_bbox->corner.x - pm_bbox->orig.x);
+ ph = ZnNearestInt(pm_bbox->corner.y - pm_bbox->orig.y);
+ fw = ZnNearestInt(bbox->corner.x - bbox->orig.x);
+ fh = ZnNearestInt(bbox->corner.y - bbox->orig.y);
+
+ pixmap = ZnImagePixmap(fptr->image);
+ photo_region = ZnImageRegion(fptr->image);
+ ZnCurrentClip(wi, &clip_region, NULL, &simple);
+ clip = TkCreateRegion();
/*
- * The image is clipped on the field boundary.
- * This is needed to be compatible with image coming with
- * a clip mask. The image clip mask resets the clip area in
- * the GC, so we must fake the field clipping in the copyarea.
+ * ZnImageRegion may fail: perl/Tk 800.24 doesn't support
+ * some internal TkPhoto functions.
+ * This is a workaround using a rectangular region based
+ * on the image size.
*/
- pw = REAL_TO_INT(pm_bbox->corner.x - pm_bbox->orig.x);
- ph = REAL_TO_INT(pm_bbox->corner.y - pm_bbox->orig.y);
- fw = REAL_TO_INT(bbox->corner.x - bbox->orig.x);
- fh = REAL_TO_INT(bbox->corner.y - bbox->orig.y);
- XCopyArea(wi->dpy, pixmap, wi->draw_buffer, wi->gc,
- REAL_TO_INT(bbox->orig.x-pm_bbox->orig.x),
- REAL_TO_INT(bbox->orig.y-pm_bbox->orig.y),
- MIN(pw, fw), MIN(ph, fh),
- MAX(bbox->orig.x, pm_bbox->orig.x),
- MAX(bbox->orig.y, pm_bbox->orig.y));
- if (mask_pmap != ZnUnspecifiedImage) {
- XSetRegion(wi->dpy, wi->gc, clip_region);
+ if (photo_region == NULL) {
+ XRectangle rect;
+ rect.x = rect.y = 0;
+ rect.width = pw;
+ rect.height = ph;
+ TkUnionRectWithRegion(&rect, clip, clip);
+ }
+ else {
+ ZnUnionRegion(clip, photo_region, clip);
}
+ ZnOffsetRegion(clip, (int) pm_bbox->orig.x, (int) pm_bbox->orig.y);
+ TkIntersectRegion(clip_region, clip, clip);
+ TkSetRegion(wi->dpy, wi->gc, clip);
+ XCopyArea(wi->dpy, pixmap, wi->draw_buffer, wi->gc,
+ (int) ZnNearestInt(bbox->orig.x-pm_bbox->orig.x),
+ (int) ZnNearestInt(bbox->orig.y-pm_bbox->orig.y),
+ (unsigned int) MIN(pw, fw),
+ (unsigned int) MIN(ph, fh),
+ (int) MAX(bbox->orig.x, pm_bbox->orig.x),
+ (int) MAX(bbox->orig.y, pm_bbox->orig.y));
+
+ TkSetRegion(wi->dpy, wi->gc, clip_region);
+ TkDestroyRegion(clip);
}
}
else if (fptr->text) {
@@ -1876,30 +1887,31 @@ DrawField(WidgetInfo *wi,
num_bytes = strlen(fptr->text);
if (num_bytes) {
if (sel_start >= 0) {
- values.foreground = ZnPixel(ZnGetGradientColor(ti->sel_color, 0, NULL));
+ values.foreground = ZnPixel(ZnGetGradientColor(ti->sel_color, 0.0, NULL));
values.fill_style = FillSolid;
XChangeGC(wi->dpy, wi->gc, GCForeground|GCFillStyle, &values);
XFillRectangle(wi->dpy, wi->draw_buffer, wi->gc,
- text_bbox->orig.x+sel_start, text_bbox->orig.y,
- sel_stop-sel_start,
- text_bbox->corner.y-text_bbox->orig.y);
+ (int) (text_bbox->orig.x+sel_start),
+ (int) text_bbox->orig.y,
+ (unsigned int) (sel_stop-sel_start),
+ (unsigned int) (text_bbox->corner.y-text_bbox->orig.y));
}
- values.foreground = ZnPixel(ZnGetGradientColor(fptr->color, 0, NULL));
+ values.foreground = ZnPixel(ZnGetGradientColor(fptr->color, 0.0, NULL));
values.fill_style = FillSolid;
- values.font = ZnFontId(fptr->font);
+ values.font = Tk_FontId(fptr->font);
XChangeGC(wi->dpy, wi->gc, GCForeground | GCFillStyle | GCFont, &values);
Tk_DrawChars(wi->dpy, wi->draw_buffer, wi->gc, fptr->font,
- fptr->text, num_bytes, text_pos->x, text_pos->y);
+ fptr->text, num_bytes, (int) text_pos->x, (int) text_pos->y);
}
if (cursor >= 0) {
values.line_width = ti->insert_width;
- values.foreground = ZnPixel(ZnGetGradientColor(ti->insert_color, 0, NULL));
+ values.foreground = ZnPixel(ZnGetGradientColor(ti->insert_color, 0.0, NULL));
values.fill_style = FillSolid;
XChangeGC(wi->dpy, wi->gc, GCForeground|GCLineWidth|GCFillStyle, &values);
- xs = text_bbox->orig.x + cursor;
+ xs = (int) text_bbox->orig.x + cursor;
XDrawLine(wi->dpy, wi->draw_buffer, wi->gc,
- xs, text_bbox->orig.y,
- xs, text_bbox->corner.y);
+ xs, (int) text_bbox->orig.y,
+ xs, (int) text_bbox->corner.y);
}
}
}
@@ -1907,44 +1919,44 @@ DrawField(WidgetInfo *wi,
/*
* Draw the border relief.
*/
- if ((fptr->relief != RELIEF_FLAT) && (fptr->relief_thickness > 1)) {
+ if ((fptr->relief != ZN_RELIEF_FLAT) && (fptr->relief_thickness > 1)) {
ZnDrawRectangleRelief(wi, fptr->relief, fptr->gradient,
- &r, (unsigned int) fptr->relief_thickness);
+ &r, fptr->relief_thickness);
}
/*
* Draw the border line.
*/
- if (fptr->border_edges != NO_BORDER) {
- values.foreground = ZnPixel(ZnGetGradientColor(fptr->border_color, 0, NULL));
+ if (fptr->border_edges != ZN_NO_BORDER) {
+ values.foreground = ZnPixel(ZnGetGradientColor(fptr->border_color, 0.0, NULL));
values.line_width = 0;
values.line_style = LineSolid;
values.fill_style = FillSolid;
XChangeGC(wi->dpy, wi->gc,
GCForeground | GCLineWidth | GCLineStyle | GCFillStyle, &values);
- if (fptr->border_edges & LEFT_BORDER) {
+ if (fptr->border_edges & ZN_LEFT_BORDER) {
XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, r.x, r.y,
r.x, r.y + r.height - 1);
}
- if (fptr->border_edges & RIGHT_BORDER) {
+ if (fptr->border_edges & ZN_RIGHT_BORDER) {
XDrawLine(wi->dpy, wi->draw_buffer, wi->gc,
r.x + r.width - 1, r.y,
r.x + r.width - 1, r.y + r.height - 1);
}
- if (fptr->border_edges & TOP_BORDER) {
+ if (fptr->border_edges & ZN_TOP_BORDER) {
XDrawLine(wi->dpy, wi->draw_buffer, wi->gc,
r.x, r.y, r.x + r.width - 1, r.y);
}
- if (fptr->border_edges & BOTTOM_BORDER) {
+ if (fptr->border_edges & ZN_BOTTOM_BORDER) {
XDrawLine(wi->dpy, wi->draw_buffer, wi->gc,
r.x, r.y + r.height - 1,
r.x + r.width - 1, r.y + r.height - 1);
}
- if (fptr->border_edges & OBLIQUE) {
+ if (fptr->border_edges & ZN_OBLIQUE) {
XDrawLine(wi->dpy, wi->draw_buffer, wi->gc,
r.x, r.y, r.x + r.width - 1, r.y + r.height - 1);
}
- if (fptr->border_edges & COUNTER_OBLIQUE) {
+ if (fptr->border_edges & ZN_COUNTER_OBLIQUE) {
XDrawLine(wi->dpy, wi->draw_buffer, wi->gc,
r.x, r.y + r.height - 1,
r.x + r.width - 1, r.y);
@@ -1953,7 +1965,7 @@ DrawField(WidgetInfo *wi,
}
static void
-DrawFields(FieldSet field_set)
+DrawFields(ZnFieldSet field_set)
{
FieldsEngine(field_set, DrawField);
}
@@ -1966,23 +1978,24 @@ DrawFields(FieldSet field_set)
*
**********************************************************************************
*/
-#ifdef GLX
+#ifdef GL
static void
FieldRenderCB(void *closure)
{
ZnBBox *bbox = (ZnBBox *) closure;
glBegin(GL_QUADS);
- glVertex2f(bbox->orig.x, bbox->orig.y);
- glVertex2f(bbox->orig.x, bbox->corner.y);
- glVertex2f(bbox->corner.x, bbox->corner.y);
- glVertex2f(bbox->corner.x, bbox->orig.y);
+ glVertex2d(bbox->orig.x, bbox->orig.y);
+ glVertex2d(bbox->orig.x, bbox->corner.y);
+ glVertex2d(bbox->corner.x, bbox->corner.y);
+ glVertex2d(bbox->corner.x, bbox->orig.y);
glEnd();
}
#endif
+#ifdef GL
static void
-RenderField(WidgetInfo *wi,
+RenderField(ZnWInfo *wi,
Field fptr,
ZnBBox *bbox,
ZnBBox *pm_bbox,
@@ -1992,11 +2005,11 @@ RenderField(WidgetInfo *wi,
int sel_start,
int sel_stop)
{
-#ifdef GLX
- int j, alpha, num_bytes;
+ unsigned short alpha;
+ unsigned int j, num_bytes;
XColor *color;
ZnReal xs;
- TextInfo *ti = &wi->text_info;
+ ZnTextInfo *ti = &wi->text_info;
/*
* Draw the background.
@@ -2004,7 +2017,7 @@ RenderField(WidgetInfo *wi,
if (ISSET(fptr->flags, FILLED_BIT)) {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
if (!ZnGradientFlat(fptr->fill_color)) {
-#if 0 /* TODO_GLX Faire le dégradé dans le fond des champs. */
+#if 0 /* TODO_GL Faire le dégradé dans le fond des champs. */
int type = fptr->fill_color->type;
ZnBool fast = (type == ZN_AXIAL_GRADIENT) && !fptr->grad_geo;
@@ -2024,7 +2037,7 @@ RenderField(WidgetInfo *wi,
* Setup polygon stippling.
*/
glEnable(GL_POLYGON_STIPPLE);
- glPolygonStipple(ZnImagePattern(fptr->fill_pattern, NULL));
+ glPolygonStipple(ZnImageMask(fptr->fill_pattern, NULL));
}
color = ZnGetGradientColor(fptr->fill_color, 0.0, &alpha);
alpha = ZnComposeAlpha(alpha, wi->alpha);
@@ -2059,38 +2072,38 @@ RenderField(WidgetInfo *wi,
if (fptr->tfi) {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
if (sel_start >= 0) {
- color = ZnGetGradientColor(ti->sel_color, 0, &alpha);
+ color = ZnGetGradientColor(ti->sel_color, 0.0, &alpha);
alpha = ZnComposeAlpha(alpha, wi->alpha);
glColor4us(color->red, color->green, color->blue, alpha);
glBegin(GL_QUADS);
- glVertex2f(text_bbox->orig.x+sel_start, text_bbox->orig.y);
- glVertex2f(text_bbox->orig.x+sel_stop, text_bbox->orig.y);
- glVertex2f(text_bbox->orig.x+sel_stop, text_bbox->corner.y);
- glVertex2f(text_bbox->orig.x+sel_start, text_bbox->corner.y);
+ glVertex2d(text_bbox->orig.x+sel_start, text_bbox->orig.y);
+ glVertex2d(text_bbox->orig.x+sel_stop, text_bbox->orig.y);
+ glVertex2d(text_bbox->orig.x+sel_stop, text_bbox->corner.y);
+ glVertex2d(text_bbox->orig.x+sel_start, text_bbox->corner.y);
glEnd();
}
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- color = ZnGetGradientColor(fptr->color, 0, &alpha);
+ color = ZnGetGradientColor(fptr->color, 0.0, &alpha);
alpha = ZnComposeAlpha(alpha, wi->alpha);
glColor4us(color->red, color->green, color->blue, alpha);
glBindTexture(GL_TEXTURE_2D, ZnTexFontTex(fptr->tfi));
glPushMatrix();
- glTranslatef(text_pos->x, text_pos->y, 0.0);
+ glTranslated(text_pos->x, text_pos->y, 0.0);
ZnRenderString(fptr->tfi, fptr->text, num_bytes);
glPopMatrix();
glDisable(GL_TEXTURE_2D);
}
}
if (cursor >= 0) {
- glLineWidth(ti->insert_width);
- color = ZnGetGradientColor(ti->insert_color, 0, &alpha);
+ glLineWidth((GLfloat) ti->insert_width);
+ color = ZnGetGradientColor(ti->insert_color, 0.0, &alpha);
alpha = ZnComposeAlpha(alpha, wi->alpha);
glColor4us(color->red, color->green, color->blue, alpha);
xs = text_bbox->orig.x + cursor;
glBegin(GL_LINES);
- glVertex2f(xs, text_bbox->orig.y);
- glVertex2f(xs, text_bbox->corner.y);
+ glVertex2d(xs, text_bbox->orig.y);
+ glVertex2d(xs, text_bbox->corner.y);
glEnd();
}
}
@@ -2099,7 +2112,7 @@ RenderField(WidgetInfo *wi,
/*
* Draw the border relief.
*/
- if ((fptr->relief != RELIEF_FLAT) && (fptr->relief_thickness > 1)) {
+ if ((fptr->relief != ZN_RELIEF_FLAT) && (fptr->relief_thickness > 1)) {
ZnPoint p[5];
p[0].x = bbox->orig.x;
@@ -2118,44 +2131,57 @@ RenderField(WidgetInfo *wi,
/*
* Draw the border line.
*/
- if (fptr->border_edges != NO_BORDER) {
- color = ZnGetGradientColor(fptr->border_color, 0, &alpha);
+ if (fptr->border_edges != ZN_NO_BORDER) {
+ color = ZnGetGradientColor(fptr->border_color, 0.0, &alpha);
alpha = ZnComposeAlpha(alpha, wi->alpha);
glColor4us(color->red, color->green, color->blue, alpha);
glLineWidth(1.5);
- ZnSetLineStyle(wi, LINE_SIMPLE);
+ ZnSetLineStyle(wi, ZN_LINE_SIMPLE);
glBegin(GL_LINES);
- if (fptr->border_edges & LEFT_BORDER) {
- glVertex2f(bbox->orig.x, bbox->orig.y);
- glVertex2f(bbox->orig.x, bbox->corner.y);
+ if (fptr->border_edges & ZN_LEFT_BORDER) {
+ glVertex2d(bbox->orig.x, bbox->orig.y);
+ glVertex2d(bbox->orig.x, bbox->corner.y);
}
- if (fptr->border_edges & RIGHT_BORDER) {
- glVertex2f(bbox->corner.x, bbox->orig.y);
- glVertex2f(bbox->corner.x, bbox->corner.y);
+ if (fptr->border_edges & ZN_RIGHT_BORDER) {
+ glVertex2d(bbox->corner.x, bbox->orig.y);
+ glVertex2d(bbox->corner.x, bbox->corner.y);
}
- if (fptr->border_edges & TOP_BORDER) {
- glVertex2f(bbox->orig.x, bbox->orig.y);
- glVertex2f(bbox->corner.x, bbox->orig.y);
+ if (fptr->border_edges & ZN_TOP_BORDER) {
+ glVertex2d(bbox->orig.x, bbox->orig.y);
+ glVertex2d(bbox->corner.x, bbox->orig.y);
}
- if (fptr->border_edges & BOTTOM_BORDER) {
- glVertex2f(bbox->orig.x, bbox->corner.y);
- glVertex2f(bbox->corner.x, bbox->corner.y);
+ if (fptr->border_edges & ZN_BOTTOM_BORDER) {
+ glVertex2d(bbox->orig.x, bbox->corner.y);
+ glVertex2d(bbox->corner.x, bbox->corner.y);
}
- if (fptr->border_edges & OBLIQUE) {
- glVertex2f(bbox->orig.x, bbox->orig.y);
- glVertex2f(bbox->corner.x, bbox->corner.y);
+ if (fptr->border_edges & ZN_OBLIQUE) {
+ glVertex2d(bbox->orig.x, bbox->orig.y);
+ glVertex2d(bbox->corner.x, bbox->corner.y);
}
- if (fptr->border_edges & COUNTER_OBLIQUE) {
- glVertex2f(bbox->orig.x, bbox->corner.y);
- glVertex2f(bbox->corner.x, bbox->orig.y);
+ if (fptr->border_edges & ZN_COUNTER_OBLIQUE) {
+ glVertex2d(bbox->orig.x, bbox->corner.y);
+ glVertex2d(bbox->corner.x, bbox->orig.y);
}
glEnd();
}
-#endif
}
+#else
+static void
+RenderField(ZnWInfo *wi __unused,
+ Field fptr __unused,
+ ZnBBox *bbox __unused,
+ ZnBBox *pm_bbox __unused,
+ ZnPoint *text_pos __unused,
+ ZnBBox *text_bbox __unused,
+ int cursor __unused,
+ int sel_start __unused,
+ int sel_stop __unused)
+{
+}
+#endif
static void
-RenderFields(FieldSet field_set)
+RenderFields(ZnFieldSet field_set)
{
FieldsEngine(field_set, RenderField);
}
@@ -2169,10 +2195,10 @@ RenderFields(FieldSet field_set)
**********************************************************************************
*/
static ZnBool
-IsFieldSensitive(FieldSet field_set,
+IsFieldSensitive(ZnFieldSet field_set,
int part)
{
- if ((part >= 0) && (part < field_set->num_fields)) {
+ if ((part >= 0) && ((unsigned int) part < field_set->num_fields)) {
return ISSET(field_set->fields[part].flags, FIELD_SENSITIVE_BIT);
}
else {
@@ -2196,21 +2222,22 @@ IsFieldSensitive(FieldSet field_set,
**********************************************************************************
*/
static double
-FieldsPick(FieldSet field_set,
+FieldsPick(ZnFieldSet field_set,
ZnPoint *p,
int *part)
{
Field fptr;
ZnBBox bbox;
- int i, best_field = 0;
- double new_dist, dist = 1e40;
+ unsigned int best_field = 0;
+ int i;
+ ZnReal new_dist, dist = 1e40;
if (!field_set->num_fields) {
return dist;
}
if (field_set->label_format) {
- for (i = LabelFormatNumFields(field_set->label_format)-1; i >= 0; i--) {
+ for (i = ZnLFNumFields(field_set->label_format)-1; i >= 0; i--) {
fptr = &field_set->fields[i];
if (ISCLEAR(fptr->flags, FIELD_VISIBLE_BIT) &&
@@ -2218,9 +2245,9 @@ FieldsPick(FieldSet field_set,
continue;
}
- GetFieldBBox(field_set, i, &bbox);
+ GetFieldBBox(field_set, (unsigned int) i, &bbox);
- new_dist = RectangleToPointDist(&bbox, p);
+ new_dist = ZnRectangleToPointDist(&bbox, p);
if (new_dist < dist) {
dist = new_dist;
best_field = i;
@@ -2248,20 +2275,19 @@ FieldsPick(FieldSet field_set,
**********************************************************************************
*/
static int
-FieldsToArea(FieldSet field_set,
+FieldsToArea(ZnFieldSet field_set,
ZnBBox *area)
{
Field fptr;
ZnBBox bbox;
- int inside = -1;
- int i;
+ int i, inside = -1;
ZnBool first_done = False;
if (!field_set->num_fields) {
return inside;
}
- for (i = LabelFormatNumFields(field_set->label_format)-1; i >= 0; i--) {
+ for (i = ZnLFNumFields(field_set->label_format)-1; i >= 0; i--) {
fptr = &field_set->fields[i];
if (ISCLEAR(fptr->flags, FIELD_VISIBLE_BIT) &&
@@ -2269,16 +2295,16 @@ FieldsToArea(FieldSet field_set,
continue;
}
- GetFieldBBox(field_set, i, &bbox);
+ GetFieldBBox(field_set, (unsigned int) i, &bbox);
if (!first_done) {
first_done = True;
- inside = BBoxInBBox(&bbox, area);
+ inside = ZnBBoxInBBox(&bbox, area);
if (inside == 0) {
return 0;
}
}
else {
- if (BBoxInBBox(&bbox, area) != inside) {
+ if (ZnBBoxInBBox(&bbox, area) != inside) {
return 0;
}
}
@@ -2296,16 +2322,16 @@ FieldsToArea(FieldSet field_set,
**********************************************************************************
*/
static void
-SetFieldsAutoAlign(FieldSet fs,
+SetFieldsAutoAlign(ZnFieldSet fs,
int alignment)
{
- int i;
+ unsigned int i;
Field field;
if (!fs->num_fields) {
return;
}
- if ((alignment >= AA_LEFT) && (alignment <= AA_RIGHT)) {
+ if ((alignment >= ZN_AA_LEFT) && (alignment <= ZN_AA_RIGHT)) {
for (i = 0; i < fs->num_fields; i++) {
field = &fs->fields[i];
if (field->auto_alignment.automatic) {
@@ -2316,24 +2342,24 @@ SetFieldsAutoAlign(FieldSet fs,
}
static char *
-GetFieldStruct(FieldSet fs,
- int field)
+GetFieldStruct(ZnFieldSet fs,
+ int field)
{
- if (field >= fs->num_fields) {
+ if ((unsigned int) field >= fs->num_fields) {
return NULL;
}
return (char *) &fs->fields[field];
}
-static int
-NumFields(FieldSet fs)
+static unsigned int
+NumFields(ZnFieldSet fs)
{
return fs->num_fields;
}
-struct _FIELD FIELD = {
+struct _ZnFIELD ZnFIELD = {
field_attrs,
InitFields,