summaryrefslogtreecommitdiff
path: root/include/X11/XprintAppUtil/xpapputil.h
blob: d7159bb14480f4f3e4ec3a86f1b1ff7ac8172510 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175

/*
 * $Xorg:xpapputil.h,v 1.1 2002/06/10 02:54:18 gisburn Exp $
 * 
 * xpapputil - Application level utility library for Xprint
 *
 * 
Copyright 2002-2004 Roland Mainz <roland.mainz@nrubsig.org>

All Rights Reserved.

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
 *
 * Author:  Roland Mainz <roland.mainz@nrubsig.org>
 */

#ifndef XPAPPUTILS_H
#define XPAPPUTILS_H 1
 
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/XprintUtil/xprintutil.h>

#ifdef DEBUG
#define XPAU_RETURN_IF_FAIL(expr, return_code) \
    if( !(expr) ) { \
      printf("XPAU_RETURN_IF_FAIL(file %s, line %d): " #expr ", returning " #return_code "\n", __FILE__, __LINE__); \
      return (return_code); \
    }

#define XPAU_DEBUG(x) x

#else

#define XPAU_RETURN_IF_FAIL(expr, return_code) \
    if( !(expr) ) { \
      return (return_code); \
    }

#define XPAU_DEBUG(x)
#endif /* DEBUG */

/*
 * Struct for XpauGetContext(), XpauReleaseContext()
 * 
 */
typedef struct
{
    Display                 *pdpy;
    XPContext                pcontext;
    int                      xp_event_base,
                             xp_error_base;

    Bool                     inJob;
    Bool                     inDocument;
    Bool                     inPage;

    void                    *print_to_filehandle;
    Screen                  *pscreen;
    int                      pscreennumber;
    long                     document_dpi_x,
                             document_dpi_y;
    
    XpuSupportedFlags        supported_job_attributes;
    XpuSupportedFlags        supported_doc_attributes;
    XpuSupportedFlags        supported_page_attributes;
    
    XpuMediumSourceSizeList  medium_list;
    int                      medium_num_list_entries;
    XpuResolutionList        resolution_list;
    int                      resolution_num_list_entries;
    XpuOrientationList       orientation_list;
    int                      orientation_num_list_entries;
    XpuPlexList              plex_list;
    int                      plex_num_list_entries;
} XpauContext;


#define XpauVFilename      (1L<<0)
#define XpauVMedium        (1L<<1)
#define XpauVResolution    (1L<<2)
#define XpauVOrientation   (1L<<3)
#define XpauVPlex          (1L<<4)
#define XpauVCopies        (1L<<5)
#define XpauVTitle         (1L<<6)
#define XpauVAll (XpauVFilename    | \
                  XpauVMedium      | \
                  XpauVResolution  | \
                  XpauVOrientation | \
                  XpauVPlex        | \
                  XpauVCopies      | \
                  XpauVTitle)

typedef unsigned long XpauFlags;

typedef struct
{
  const char              *title;
  long                     copies;
} XpauJobValues;

typedef struct
{
  XpuMediumSourceSizeRec  *medium;
  XpuResolutionRec        *resolution;
  XpuOrientationRec       *orientation;
  XpuPlexRec              *plex;
  long                     copies;
} XpauDocValues;

typedef struct
{
  XpuMediumSourceSizeRec  *medium;
  XpuResolutionRec        *resolution;
  XpuOrientationRec       *orientation;
  XpuPlexRec              *plex;
} XpauPageValues;

typedef enum {
  XpAuError_success = 0, 
  XpAuError_unspecified_error, 
  XpAuError_errno,      /* check |errno| for error */
  XpAuError_error_no_memory, 
  XpAuError_unexpected_eos, 
  XpAuError_unknown_argument, 
  XpAuError_unsupported_medium, 
  XpAuError_unsupported_resolution, 
  XpAuError_unsupported_orientation, 
  XpAuError_unsupported_plex,
  XpAuError_unsupported_copy_count,
  XpAuError_unsupported_job_name,
  XpAuError_no_dpi_set,
  XpAuError_not_inside_job,
  XpAuError_not_inside_document,
  XpAuError_not_inside_page,
  XpAuError_inside_job,
  XpAuError_inside_document,
  XpAuError_inside_page
} XpAuErrorValue;

/* Prototypes */
XpauContext *  XpauGetContext( const char *printername );
void           XpauReleaseContext( XpauContext *context );
XpAuErrorValue XpauParseArgs( XpauContext *context,
                              XpauFlags *jobvaluemask, XpauJobValues *jobvalues,
                              XpauFlags *docvaluemask, XpauDocValues *docvalues,
                              char **jobfilename,
                              const char *argument_string );
XpAuErrorValue XpauSetJobValues( XpauContext *context, XpauFlags valuemask, XpauJobValues *Xpaujobvalues );
XpAuErrorValue XpauSetDocValues( XpauContext *context, XpauFlags valuemask, XpauDocValues *Xpaudocvalues );
XpAuErrorValue XpauSetPageValues( XpauContext *context, XpauFlags valuemask, XpauPageValues *Xpaupagevalues );
XpAuErrorValue XpauStartJob( XpauContext *context, const char *printerfile );
XpAuErrorValue XpauEndJob( XpauContext *context );
XpAuErrorValue XpauStartDocument( XpauContext *context, XPDocumentType type );
XpAuErrorValue XpauEndDocument( XpauContext *context );
XpAuErrorValue XpauStartPage( XpauContext *context, Window pwin );
XpAuErrorValue XpauEndPage( XpauContext *context );
void           XpauWaitForPrintNotify(XpauContext *context, int type);
const char    *XpAuErrorValueToString(XpAuErrorValue value);
#endif /* !XPAPPUTILS_H */