BitmapP.h revision 7515ee80
1eaef79e5Smrg/*
2eaef79e5Smrg
3eaef79e5SmrgCopyright 1989, 1998  The Open Group
4eaef79e5Smrg
5eaef79e5SmrgPermission to use, copy, modify, distribute, and sell this software and its
6eaef79e5Smrgdocumentation for any purpose is hereby granted without fee, provided that
7eaef79e5Smrgthe above copyright notice appear in all copies and that both that
8eaef79e5Smrgcopyright notice and this permission notice appear in supporting
9eaef79e5Smrgdocumentation.
10eaef79e5Smrg
11eaef79e5SmrgThe above copyright notice and this permission notice shall be included
12eaef79e5Smrgin all copies or substantial portions of the Software.
13eaef79e5Smrg
14eaef79e5SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15eaef79e5SmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16eaef79e5SmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17eaef79e5SmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
18eaef79e5SmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19eaef79e5SmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20eaef79e5SmrgOTHER DEALINGS IN THE SOFTWARE.
21eaef79e5Smrg
22eaef79e5SmrgExcept as contained in this notice, the name of The Open Group shall
23eaef79e5Smrgnot be used in advertising or otherwise to promote the sale, use or
24eaef79e5Smrgother dealings in this Software without prior written authorization
25eaef79e5Smrgfrom The Open Group.
26eaef79e5Smrg
27eaef79e5Smrg*/
28eaef79e5Smrg
29eaef79e5Smrg/*
30eaef79e5Smrg * Author:  Davor Matic, MIT X Consortium
31eaef79e5Smrg */
32eaef79e5Smrg
33eaef79e5Smrg
34eaef79e5Smrg
35eaef79e5Smrg#ifndef _BitmapP_h
36eaef79e5Smrg#define _BitmapP_h
37eaef79e5Smrg
38eaef79e5Smrg#define bit int
39eaef79e5Smrg
40eaef79e5Smrg#include "Bitmap.h"
41eaef79e5Smrg#include "Requests.h"
42eaef79e5Smrg#include <X11/Xaw/SimpleP.h>
43eaef79e5Smrg
44eaef79e5Smrgtypedef struct {
45eaef79e5Smrg    Atom           *targets;
46eaef79e5Smrg    Cardinal        num_targets;
47eaef79e5Smrg    BWRequestRec   *requests;
48eaef79e5Smrg    Cardinal        num_requests;
49eaef79e5Smrg    BWRequestRec   *request[100];
50cbc4e2beSmrg
51eaef79e5Smrg} BitmapClassPart;
52eaef79e5Smrg
53eaef79e5Smrg/* Full class record declaration */
54eaef79e5Smrgtypedef struct _BitmapClassRec {
55eaef79e5Smrg  CoreClassPart          core_class;
56eaef79e5Smrg  SimpleClassPart        simple_class;
57eaef79e5Smrg  BitmapClassPart        bitmap_class;
58eaef79e5Smrg} BitmapClassRec;
59eaef79e5Smrg
60eaef79e5Smrgextern BitmapClassRec bitmapClassRec;
61eaef79e5Smrg
62eaef79e5Smrgtypedef void (*EngageProc)(Widget, BWStatus *, XtPointer, int *);
63eaef79e5Smrgtypedef void (*TerminateProc)( Widget, BWStatus *, XtPointer);
64eaef79e5Smrgtypedef void (*RemoveProc)(Widget w, BWStatus *, XtPointer);
65eaef79e5Smrg
66eaef79e5Smrg/**********/
67eaef79e5Smrgstruct _BWRequestRec {
68eaef79e5Smrg  char         *name;
69eaef79e5Smrg  int           status_size;
70eaef79e5Smrg  EngageProc    engage;
71eaef79e5Smrg  XtPointer     engage_client_data;
72eaef79e5Smrg  TerminateProc terminate;
73eaef79e5Smrg  XtPointer     terminate_client_data;
74eaef79e5Smrg  RemoveProc    remove;
75eaef79e5Smrg  XtPointer     remove_client_data;
76eaef79e5Smrg} ;
77eaef79e5Smrg
78eaef79e5Smrgtypedef struct {
79eaef79e5Smrg  Position from_x, from_y,
80eaef79e5Smrg           to_x, to_y;
81eaef79e5Smrg} BWArea;
82eaef79e5Smrg
83eaef79e5Smrgtypedef struct {
84eaef79e5Smrg    BWRequestRec *request;
85eaef79e5Smrg    XtPointer     status;
86eaef79e5Smrg    Boolean       trap;
87eaef79e5Smrg    XtPointer     call_data;
88eaef79e5Smrg} BWRequestStack;
89eaef79e5Smrg
90eaef79e5Smrgtypedef struct {
91eaef79e5Smrg    XImage   *image, *buffer;
92eaef79e5Smrg    XPoint    hot;
93eaef79e5Smrg    Position  at_x, at_y;
94eaef79e5Smrg    Boolean   fold;
95eaef79e5Smrg    Boolean   grid;
96eaef79e5Smrg    Boolean   changed;
97eaef79e5Smrg} BWZoom;
98eaef79e5Smrg
99eaef79e5Smrgtypedef struct {
100eaef79e5Smrg    Boolean   own;
101eaef79e5Smrg    Boolean   limbo;
102eaef79e5Smrg} BWSelection;
103eaef79e5Smrg
104eaef79e5Smrg/* New fields for the Bitmap widget record */
105eaef79e5Smrgtypedef struct {
106eaef79e5Smrg  /* resources */
107eaef79e5Smrg  Pixel            foreground_pixel;
108eaef79e5Smrg  Pixel            highlight_pixel;
109eaef79e5Smrg  Pixel            frame_pixel;
110eaef79e5Smrg  Pixmap           stipple;
111eaef79e5Smrg  Boolean          stippled;
112eaef79e5Smrg  Boolean          proportional;
113eaef79e5Smrg  Boolean          grid;
114eaef79e5Smrg  Dimension        grid_tolerance;
115eaef79e5Smrg  Pixmap           dashes;
116eaef79e5Smrg  Boolean          dashed;
117eaef79e5Smrg  Boolean          axes;
118eaef79e5Smrg  Boolean          resize;
119eaef79e5Smrg  Dimension        margin, squareW, squareH, width, height;
120eaef79e5Smrg  XPoint           hot;
121eaef79e5Smrg  int              button_function[5];
1227515ee80Smrg  _XtString        filename;
1237515ee80Smrg  _XtString        basename;
124eaef79e5Smrg  /* private state */
125eaef79e5Smrg  String           size;
126eaef79e5Smrg  Position         horizOffset, vertOffset;
127eaef79e5Smrg  XtActionProc     notify;
128eaef79e5Smrg  BWRequestStack  *request_stack;
129eaef79e5Smrg  Cardinal         cardinal, current;
130eaef79e5Smrg  /*Boolean          trapping;*/
131eaef79e5Smrg  XImage          *image, *buffer, *storage;
132eaef79e5Smrg  XPoint           buffer_hot;
133eaef79e5Smrg  BWArea           mark, buffer_mark;
134eaef79e5Smrg  GC               drawing_gc;
135eaef79e5Smrg  GC               highlighting_gc;
136eaef79e5Smrg  GC               frame_gc;
137eaef79e5Smrg  GC               axes_gc;
138eaef79e5Smrg  Boolean          changed;
139eaef79e5Smrg  Boolean          fold;
140eaef79e5Smrg  Boolean          zooming;
141eaef79e5Smrg  BWZoom           zoom;
142eaef79e5Smrg  XtPointer        *value;
143eaef79e5Smrg  char             status[80];
144eaef79e5Smrg  BWSelection      selection;
145eaef79e5Smrg  Boolean          stipple_change_expose_event;
146eaef79e5Smrg} BitmapPart;
147eaef79e5Smrg
148eaef79e5Smrg/* Full instance record declaration */
149eaef79e5Smrgtypedef struct _BitmapRec {
150eaef79e5Smrg  CorePart      core;
151eaef79e5Smrg  SimplePart    simple;
152eaef79e5Smrg  BitmapPart    bitmap;
153eaef79e5Smrg} BitmapRec;
154eaef79e5Smrg
155eaef79e5Smrg/* Private functions */
156eaef79e5Smrg
157eaef79e5Smrg#define Length(width, height)\
158eaef79e5Smrg        (((int)(width) + 7) / 8 * (height))
159eaef79e5Smrg
160eaef79e5Smrg#define InBitmapX(BW, x)\
161eaef79e5Smrg	(Position)(min((Position)((Dimension)(max(BW->bitmap.horizOffset,x)  -\
162eaef79e5Smrg				   BW->bitmap.horizOffset) /\
163eaef79e5Smrg				   BW->bitmap.squareW), BW->bitmap.width - 1))
164cbc4e2beSmrg
165eaef79e5Smrg#define InBitmapY(BW, y)\
166eaef79e5Smrg	(Position)(min((Position)((Dimension)(max(BW->bitmap.vertOffset, y)  -\
167eaef79e5Smrg				   BW->bitmap.vertOffset) /\
168eaef79e5Smrg				   BW->bitmap.squareH), BW->bitmap.height - 1))
169cbc4e2beSmrg
170eaef79e5Smrg#define InWindowX(BW, x)\
171eaef79e5Smrg	(Position) (BW->bitmap.horizOffset + ((x) * BW->bitmap.squareW))
172eaef79e5Smrg
173eaef79e5Smrg#define InWindowY(BW, y)\
174eaef79e5Smrg	(Position) (BW->bitmap.vertOffset + ((y) * BW->bitmap.squareH))
175cbc4e2beSmrg
176eaef79e5Smrg#define GetPixmap(BW, image)\
177eaef79e5Smrg    XCreateBitmapFromData(XtDisplay(BW), XtWindow(BW),\
178eaef79e5Smrg			  image->data, image->width, image->height)
179eaef79e5Smrg
180eaef79e5Smrg
181eaef79e5Smrg#define QuerySet(x, y) (((x) != NotSet) && ((y) != NotSet))
182eaef79e5Smrg
183eaef79e5Smrg#define bit int
184eaef79e5Smrg
185eaef79e5Smrg#define QueryZero(x, y) (((x) == 0) || ((y) == 0))
186eaef79e5Smrg
187eaef79e5Smrg#define Swap(x, y) {Position t; t = x; x = y; y = t;}
188eaef79e5Smrg
189eaef79e5Smrg#define QuerySwap(x, y) if(x > y) Swap(x, y)
190eaef79e5Smrg
191eaef79e5Smrg#define QueryInBitmap(BW, x, y)\
192eaef79e5Smrg  (((x) >= 0) && ((x) < BW->bitmap.image->width) &&\
193eaef79e5Smrg   ((y) >= 0) && ((y) < BW->bitmap.image->height))
194eaef79e5Smrg
195eaef79e5Smrg#define Value(BW, button)   (BW->bitmap.button_function[button - 1])
196eaef79e5Smrg
197eaef79e5Smrg#define CreateCleanData(length) XtCalloc(length, sizeof(char))
198eaef79e5SmrgXImage *CreateBitmapImage(BitmapWidget BW, char *data, Dimension width, Dimension height);
199eaef79e5Smrgvoid DestroyBitmapImage(XImage **image);
200eaef79e5Smrgvoid  TransferImageData(XImage *source, XImage *destination);
201cbc4e2beSmrgvoid CopyImageData(XImage *source, XImage *destination,
202cbc4e2beSmrg	      Position from_x, Position from_y,
203cbc4e2beSmrg	      Position to_x, Position to_y,
204eaef79e5Smrg	      Position at_x, Position at_y);
205eaef79e5SmrgXImage *GetImage(BitmapWidget BW, Pixmap pixmap);
206eaef79e5SmrgXImage *ConvertToBitmapImage(BitmapWidget BW, XImage *image);
207cbc4e2beSmrgXImage *ScaleBitmapImage(BitmapWidget BW, XImage *src,
208eaef79e5Smrg			 double scale_x, double scale_y);
209eaef79e5Smrg
2102b32c8f7Smrgextern Boolean DEBUG;
2112b32c8f7Smrg
212eaef79e5Smrg#endif /* _BitmapP_h */
213