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