Debian Codegraph @

gdraw/ggdkdrawP.h

raw symbols SCIP
1 /* Copyright (C) 2016 by Jeremy Tan */
2 /*
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
5
6 * Redistributions of source code must retain the above copyright notice, this
7 * list of conditions and the following disclaimer.
8
9 * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
14 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
16 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
18 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
19 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
21 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25 /**
26 * \file ggdkdrawP.h
27 * \brief Private header file for the GDK backend.
28 */
29
30 #ifndef FONTFORGE_GGDKDRAWP_H
31 #define FONTFORGE_GGDKDRAWP_H
32
33 #include <fontforge-config.h>
34
35
36 #include "ffgdk.h"
37 #include "fontP.h"
38 #include "gdrawP.h"
39
40 #if (((GDK_MAJOR_VERSION == 3) && (GDK_MINOR_VERSION >= 22)) || (GDK_MAJOR_VERSION > 3))
41 # define GGDKDRAW_GDK_3_22
42 #endif
43
44 #if (((GDK_MAJOR_VERSION == 3) && (GDK_MINOR_VERSION >= 20)) || (GDK_MAJOR_VERSION > 3))
45 # define GGDKDRAW_GDK_3_20
46 #endif
47
48 #define GGDKDRAW_ADDREF(x) do { \
49 assert((x)->reference_count >= 0); \
50 (x)->reference_count++; \
51 } while(0)
52
53 #define GGDKDRAW_DECREF(x,y) do { \
54 assert((x)->reference_count > 0); \
55 (x)->reference_count--; \
56 if ((x)->reference_count == 0) { \
57 y(x); \
58 } \
59 } while(0)
60
61 // Logging
62 //To get around a 'pedantic' C99 rule that you must have at least 1 variadic arg, combine fmt into that.
63 #define Log(level, ...) LogEx(level, __func__, __FILE__, __LINE__, __VA_ARGS__)
64
65 /** An enum to make the severity of log messages human readable in code **/
66 enum {LOGNONE = 0, LOGERR = 1, LOGWARN = 2, LOGINFO = 3, LOGDEBUG = 4};
67
68 extern void LogInit(void);
69 extern void LogEx(int level, const char *funct, const char *file, int line, const char *fmt, ...) G_GNUC_PRINTF(5, 6); // General function for printing log messages to stderr
70 extern const char *GdkEventName(int code);
71 // End logging
72
73 // Astyle has issues with having 'enum visibility_state' in the function definition...
74 typedef enum visibility_state VisibilityState;
75 typedef struct ggdkwindow *GGDKWindow;
76
77 // Really GTimer should be opaque...
78 typedef struct ggdktimer { // :GTimer
79 long time_sec; // longs not int32s to match timeval
80 long time_usec;
81 int32_t repeat_time; // 0 == one shot (run once)
82 GWindow owner;
83 void *userdata;
84 struct gtimer *next; // Unused in favour of a GLib list
85 unsigned int active: 1;
86 // Extensions below
87 unsigned int stopped: 1;
88 unsigned int has_differing_repeat_time: 1;
89 int reference_count;
90 guint glib_timeout_id;
91
92 } GGDKTimer;
93
94 typedef struct ggdkbuttonstate {
95 uint32_t last_press_time;
96 GGDKWindow release_w;
97 int16_t release_x, release_y;
98 int16_t release_button;
99 int16_t cur_click;
100 int16_t double_time; // max milliseconds between release & click
101 int16_t double_wiggle; // max pixel wiggle allowed between release&click
102 bool is_pressed; // a real (non-synthetic) button is currently held down
103 } GGDKButtonState;
104
105 typedef struct ggdkkeystate {
106 GdkEventType type;
107 guint state;
108 guint keyval;
109 guint16 keycode;
110 guint8 group;
111 } GGDKKeyState;
112
113 typedef struct ggdkdndcontext {
114 GGDKWindow w;
115 int x, y;
116 int rx, ry;
117 } GGDKDNDContext;
118
119 struct seldata {
120 int32_t typeatom;
121 int32_t cnt;
122 int32_t unitsize;
123 void *data;
124 void *(*gendata)(void *, int32_t *len);
125 /* Either the data are stored here, or we use this function to generate them on the fly */
126 void (*freedata)(void *);
127 struct seldata *next;
128 };
129
130 typedef struct ggdkselectiondata {
131 /** The atom identifying the type of data held e.g. UTF8_STRING **/
132 GdkAtom type_atom;
133 /** Number of elements held **/
134 int32_t cnt;
135 /** Size per element held **/
136 int32_t unit_size;
137 /** Data of selection, or context data if generator is provided **/
138 void *data;
139 /** Function to generate selection data, or NULL if provided already **/
140 void *(*gendata)(void *, int32_t *len);
141 /** Method by which to free the data element **/
142 void (*freedata)(void *);
143 } GGDKSelectionData;
144
145 typedef struct ggdkselectioninfo {
146 /** The atom identifying this selection e.g. XA_PRIMARY/CLIPBOARD */
147 GdkAtom sel_atom;
148 /** The owner of the selection **/
149 GGDKWindow owner;
150 /** Time of owning the selection **/
151 guint32 timestamp;
152 /** Types of selection data made available **/
153 GList_Glib *datalist;
154 } GGDKSelectionInfo;
155
156 typedef struct ggdkselectiontypes {
157 /** Time at which this value was updated **/
158 guint32 timestamp;
159 /** List of types available (targets) **/
160 GdkAtom *types;
161 /** Number of targets available **/
162 int32_t len;
163 /** The selection for which we're getting targets for **/
164 GdkAtom sel_atom;
165 } GGDKSelectionTypes;
166
167 typedef struct ggdkdisplay { /* :GDisplay */
168 // Inherit GDisplay start
169 struct displayfuncs *funcs;
170 struct font_state *fontstate;
171 int16_t res;
172 GGDKWindow groot;
173 unsigned int default_visual: 1;
174 unsigned int do_dithering: 1;
175 unsigned int focusfollowsmouse: 1;
176 unsigned int top_offsets_set: 1;
177 unsigned int endian_mismatch: 1;
178 unsigned int macosx_cmd: 1; /* if set then map state=0x20 to control */
179 unsigned int twobmouse_win: 1; /* if set then map state=0x40 to mouse button 2 */
180 unsigned int devicesinit: 1; /* the devices structure has been initialized. Else call XListInputDevices */
181 unsigned int expecting_core_event: 1; /* when we move an input extension device we generally get two events, one for the device, one later for the core device. eat the core event */
182 unsigned int has_xkb: 1; /* we were able to initialize the XKB extension */
183 unsigned int supports_alpha_images: 1;
184 unsigned int supports_alpha_windows: 1;
185 int err_flag;
186 char *err_report;
187 // Inherit GDisplay end
188
189 unsigned int is_space_pressed: 1; // Used for GGDKDrawKeyState. We cheat!
190 unsigned int is_dying: 1; // Flag to indicate if we're cleaning up the display.
191
192 int top_window_count; // The number of toplevel, non-dialogue windows. When this drops to 0, the event loop stops
193 guint32 last_event_time;
194
195 GGDKSelectionInfo selinfo[sn_max]; // We implement the clipboard using the selections model
196 GGDKSelectionTypes seltypes;
197 int sel_notify_timeout;
198 GGDKDNDContext last_dd; // Drag and drop
199
200 GPtrArray *cursors; // List of cursors that the user made.
201 GGDKWindow dirty_window; // Window which called drawing functions outside of an expose event.
202 GList_Glib *timers; //List of GGDKTimer's
203 GHashTable *windows; // List of windows.
204 GQueue *mru_windows; // MRU list of toplevel windows that are good candidates to make windows transient to
205
206 GGDKButtonState bs;
207 GGDKKeyState ks;
208 GGDKWindow default_icon;
209 GPtrArray *transient_stack;
210 int restrict_count;
211
212 GMainLoop *main_loop;
213 GdkDisplay *display;
214 GdkScreen *screen;
215 GdkWindow *root;
216
217 PangoContext *pangoc_context;
218 } GGDKDisplay;
219
220 struct ggdkwindow { /* :GWindow */
221 // Inherit GWindow start
222 GGC *ggc;
223 GGDKDisplay *display;
224 int (*eh)(GWindow, GEvent *);
225 GRect pos;
226 struct ggdkwindow *parent;
227 void *user_data;
228 void *widget_data;
229 GdkWindow *w;
230 unsigned int is_visible: 1;
231 unsigned int is_pixmap: 1;
232 unsigned int is_toplevel: 1;
233 unsigned int visible_request: 1;
234 unsigned int is_dying: 1;
235 unsigned int is_popup: 1;
236 unsigned int disable_expose_requests: 1;
237 char *window_type_name;
238 //char pad[4];
239 // Inherit GWindow end
240 unsigned int is_dlg: 1;
241 unsigned int not_restricted: 1;
242 unsigned int was_positioned: 1;
243 unsigned int restrict_input_to_me: 1;/* for dialogs, no input outside of dlg */
244 unsigned int redirect_chars_to_me: 1;/* ditto, we get any input outside of us */
245 unsigned int istransient: 1; /* has transient for hint set */
246 unsigned int isverytransient: 1;
247 unsigned int is_cleaning_up: 1; //Are we running cleanup?
248 unsigned int is_centered: 1;
249 unsigned int is_waiting_for_selection: 1;
250 unsigned int is_notified_of_selection: 1;
251 unsigned int is_in_paint: 1; // Have we called gdk_window_begin_paint_region?
252 unsigned int has_had_faked_configure: 1;
253
254 int reference_count; // Knowing when to destroy is tricky...
255 guint resize_timeout; // Resizing is tricky...
256
257 GWindow redirect_from; /* only redirect input from this window and its children */
258 struct ggdkwindow *transient_owner;
259 GList_Glib *mru_link; // This window's link in the MRU list; only used for some toplevels, NULL otherwise
260
261 char *window_title;
262 GCursor current_cursor;
263
264 #ifdef GGDKDRAW_GDK_3_22
265 GdkDrawingContext *drawing_ctx;
266 #endif
267 cairo_region_t *expose_region;
268 cairo_surface_t *cs;
269 cairo_t *cc;
270 PangoLayout *pango_layout;
271 };
272
273 // Functions in ggdkcdraw.c
274
275 bool _GGDKDraw_InitPangoCairo(GGDKWindow gw);
276 void _GGDKDraw_CleanupAutoPaint(GGDKDisplay *gdisp);
277
278 #ifdef GGDKDRAW_GDK_2
279 GdkPixbuf *_GGDKDraw_Cairo2Pixbuf(cairo_surface_t *cs);
280 #else
281 cairo_region_t *_GGDKDraw_ExcludeChildRegions(GGDKWindow gw, cairo_region_t *r, bool force);
282 #endif
283
284 void GGDKDrawPushClip(GWindow w, GRect *rct, GRect *old);
285 void GGDKDrawPopClip(GWindow gw, GRect *old);
286 void GGDKDrawDrawLine(GWindow w, int32_t x, int32_t y, int32_t xend, int32_t yend, Color col);
287 void GGDKDrawDrawArrow(GWindow gw, int32_t x, int32_t y, int32_t xend, int32_t yend, int16_t arrows, Color col);
288 void GGDKDrawDrawRect(GWindow gw, GRect *rect, Color col);
289 void GGDKDrawFillRect(GWindow gw, GRect *rect, Color col);
290 void GGDKDrawFillRoundRect(GWindow gw, GRect *rect, int radius, Color col);
291 void GGDKDrawDrawEllipse(GWindow gw, GRect *rect, Color col);
292 void GGDKDrawFillEllipse(GWindow gw, GRect *rect, Color col);
293 void GGDKDrawDrawArc(GWindow gw, GRect *rect, int32_t sangle, int32_t eangle, Color col);
294 void GGDKDrawDrawPoly(GWindow gw, GPoint *pts, int16_t cnt, Color col);
295 void GGDKDrawFillPoly(GWindow gw, GPoint *pts, int16_t cnt, Color col);
296 void GGDKDrawDrawImage(GWindow gw, GImage *gimg, GRect *src, int32_t x, int32_t y);
297 void GGDKDrawDrawGlyph(GWindow gw, GImage *gimg, GRect *src, int32_t x, int32_t y);
298 void GGDKDrawDrawImageMagnified(GWindow gw, GImage *gimg, GRect *src, int32_t x, int32_t y, int32_t width, int32_t height);
299
300 void GGDKDrawDrawPixmap(GWindow gw1, GWindow gw2, GRect *src, int32_t x, int32_t y);
301
302 void GGDKDrawPathStartNew(GWindow w);
303 void GGDKDrawPathClose(GWindow w);
304 void GGDKDrawPathMoveTo(GWindow w, double x, double y);
305 void GGDKDrawPathLineTo(GWindow w, double x, double y);
306 void GGDKDrawPathCurveTo(GWindow w, double cx1, double cy1, double cx2, double cy2, double x, double y);
307 void GGDKDrawPathStroke(GWindow w, Color col);
308 void GGDKDrawPathFill(GWindow w, Color col);
309 void GGDKDrawPathFillAndStroke(GWindow w, Color fillcol, Color strokecol);
310 void GGDKDrawStartNewSubPath(GWindow w);
311 int GGDKDrawFillRuleSetWinding(GWindow w);
312 int GGDKDrawDoText8(GWindow w, int32_t x, int32_t y, const char *text, int32_t cnt, Color col, enum text_funcs drawit, struct tf_arg *arg);
313
314 void GGDKDrawPushClipOnly(GWindow w);
315 void GGDKDrawClipPreserve(GWindow w);
316
317 void GGDKDrawGetFontMetrics(GWindow gw, GFont *fi, int *as, int *ds, int *ld);
318 void GGDKDrawLayoutInit(GWindow w, char *text, int cnt, GFont *fi);
319 void GGDKDrawLayoutDraw(GWindow w, int32_t x, int32_t y, Color fg);
320 void GGDKDrawLayoutIndexToPos(GWindow w, int index, GRect *pos);
321 int GGDKDrawLayoutXYToIndex(GWindow w, int x, int y);
322 void GGDKDrawLayoutExtents(GWindow w, GRect *size);
323 void GGDKDrawLayoutSetWidth(GWindow w, int width);
324 int GGDKDrawLayoutLineCount(GWindow w);
325 int GGDKDrawLayoutLineStart(GWindow w, int l);
326
327 // END functions in ggdkcdraw.c
328
329 // Functions in ggdkcocoa.m
330
331 char *_GGDKDrawCocoa_GetClipboardText(void);
332 void _GGDKDrawCocoa_SetClipboardText(const char *text);
333
334 // END functions in ggdkcocoa.m
335
336
337 #endif /* FONTFORGE_GGDKDRAWP_H */