]> git.donarmstrong.com Git - xournal.git/blob - src/xournal.h
Release 0.3.3 (minor enhancements)
[xournal.git] / src / xournal.h
1 #include <gtk/gtk.h>
2 #include <libgnomecanvas/libgnomecanvas.h>
3
4 // PREF FILES INFO
5
6 #define CONFIG_DIR ".xournal"
7 #define MRU_FILE "recent-files"
8 #define MRU_SIZE 8 
9 #define CONFIG_FILE "config"
10
11 // DATA STRUCTURES AND CONSTANTS
12
13 #define PIXEL_MOTION_THRESHOLD 0.3
14 #define MAX_AXES 12
15 #define EPSILON 1E-7
16 #define MAX_ZOOM 20.0
17 #define DISPLAY_DPI_DEFAULT 96.0
18 #define MIN_ZOOM 0.2
19
20 #define VBOX_MAIN_NITEMS 5 // number of interface items in vboxMain
21
22 /* a string (+ aux data) that maintains a refcount */
23
24 typedef struct Refstring {
25   int nref;
26   char *s;
27   gpointer aux;
28 } Refstring;
29
30
31 /* The journal is mostly a list of pages. Each page is a list of layers,
32    and a background. Each layer is a list of items, from bottom to top.
33 */
34
35 typedef struct Background {
36   int type;
37   GnomeCanvasItem *canvas_item;
38   int color_no;
39   guint color_rgba;
40   int ruling;
41   GdkPixbuf *pixbuf;
42   Refstring *filename;
43   int file_domain;
44   int file_page_seq;
45   int pixbuf_dpi;      // for PDF only - the *current* dpi value
46   double pixbuf_scale; // for PIXMAP, this is the *current* zoom value
47                        // for PDF, this is the *requested* zoom value
48 } Background;
49
50 #define BG_SOLID 0
51 #define BG_PIXMAP 1
52 #define BG_PDF 2      // not implemented yet
53
54 #define RULING_NONE 0
55 #define RULING_LINED 1
56 #define RULING_RULED 2
57 #define RULING_GRAPH 3
58
59 #define DOMAIN_ABSOLUTE 0
60 #define DOMAIN_ATTACH 1
61 #define DOMAIN_CLONE 2  // only while loading file
62
63 typedef struct Brush {
64   int tool_type;
65   int color_no;
66   guint color_rgba;
67   int thickness_no;
68   double thickness;
69   int tool_options;
70 } Brush;
71
72 #define COLOR_BLACK      0
73 #define COLOR_BLUE       1
74 #define COLOR_RED        2
75 #define COLOR_GREEN      3
76 #define COLOR_GRAY       4
77 #define COLOR_LIGHTBLUE  5
78 #define COLOR_LIGHTGREEN 6
79 #define COLOR_MAGENTA    7
80 #define COLOR_ORANGE     8
81 #define COLOR_YELLOW     9
82 #define COLOR_WHITE     10
83 #define COLOR_OTHER     -1
84 #define COLOR_MAX       11
85
86 extern guint predef_colors_rgba[COLOR_MAX];
87 extern guint predef_bgcolors_rgba[COLOR_MAX];
88
89 #define THICKNESS_VERYFINE  0
90 #define THICKNESS_FINE      1
91 #define THICKNESS_MEDIUM    2
92 #define THICKNESS_THICK     3
93 #define THICKNESS_VERYTHICK 4
94 #define THICKNESS_MAX       5
95
96 #define TOOL_PEN          0
97 #define TOOL_ERASER       1
98 #define TOOL_HIGHLIGHTER  2
99 #define TOOL_TEXT         3
100 #define TOOL_SELECTREGION 4
101 #define TOOL_SELECTRECT   5
102 #define TOOL_VERTSPACE    6
103 #define TOOL_HAND         7
104 #define NUM_STROKE_TOOLS  3
105 #define NUM_TOOLS         8
106 #define NUM_BUTTONS       3
107
108 #define TOOLOPT_ERASER_STANDARD     0
109 #define TOOLOPT_ERASER_WHITEOUT     1
110 #define TOOLOPT_ERASER_STROKES      2
111
112 #define HILITER_ALPHA_MASK 0xffffff80
113
114 extern double predef_thickness[NUM_STROKE_TOOLS][THICKNESS_MAX];
115
116 typedef struct BBox {
117   double left, right, top, bottom;
118 } BBox;
119
120 struct UndoErasureData;
121
122 typedef struct Item {
123   int type;
124   struct Brush brush; // the brush to use, if ITEM_STROKE
125   GnomeCanvasPoints *path;
126   GnomeCanvasItem *canvas_item; // the corresponding canvas item, or NULL
127   struct BBox bbox;
128   struct UndoErasureData *erasure; // for temporary use during erasures
129 } Item;
130
131 // item type values for Item.type, UndoItem.type, ui.cur_item_type ...
132 // (not all are valid in all places)
133 #define ITEM_NONE -1
134 #define ITEM_STROKE 0
135 #define ITEM_TEMP_STROKE 1
136 #define ITEM_ERASURE 2
137 #define ITEM_SELECTRECT 3
138 #define ITEM_MOVESEL 4
139 #define ITEM_PASTE 5
140 #define ITEM_NEW_LAYER 6
141 #define ITEM_DELETE_LAYER 7
142 #define ITEM_NEW_BG_ONE 8
143 #define ITEM_NEW_BG_RESIZE 9
144 #define ITEM_PAPER_RESIZE 10
145 #define ITEM_NEW_DEFAULT_BG 11
146 #define ITEM_NEW_PAGE 13
147 #define ITEM_DELETE_PAGE 14
148 #define ITEM_REPAINTSEL 15
149 #define ITEM_MOVESEL_VERT 16
150 #define ITEM_HAND 17
151
152 typedef struct Layer {
153   GList *items; // the items on the layer, from bottom to top
154   int nitems;
155   GnomeCanvasGroup *group;
156 } Layer;
157
158 typedef struct Page {
159   GList *layers; // the layers on the page
160   int nlayers;
161   double height, width;
162   double hoffset, voffset; // offsets of canvas group rel. to canvas root
163   struct Background *bg;
164   GnomeCanvasGroup *group;
165 } Page;
166
167 typedef struct Journal {
168   GList *pages;  // the pages in the journal
169   int npages;
170   int last_attach_no; // for naming of attached backgrounds
171 } Journal;
172
173 typedef struct Selection {
174   int type;  // ITEM_SELECTRECT, ITEM_MOVESEL_VERT
175   BBox bbox; // the rectangle bbox of the selection
176   struct Layer *layer; // the layer on which the selection lives
177   double anchor_x, anchor_y, last_x, last_y; // for selection motion
178   GnomeCanvasItem *canvas_item; // if the selection box is on screen 
179   GList *items; // the selected items (a list of struct Item)
180   int move_pageno, orig_pageno; // if selection moves to a different page
181   struct Layer *move_layer;
182   float move_pagedelta;
183 } Selection;
184
185 typedef struct UIData {
186   int pageno, layerno; // the current page and layer
187   struct Page *cur_page;
188   struct Layer *cur_layer;
189   gboolean saved; // is file saved ?
190   struct Brush *cur_brush;  // the brush in use (one of brushes[...])
191   int toolno[NUM_BUTTONS+1];  // the number of the currently selected tool
192   struct Brush brushes[NUM_BUTTONS+1][NUM_STROKE_TOOLS]; // the current pen, eraser, hiliter
193   struct Brush default_brushes[NUM_STROKE_TOOLS]; // the default ones
194   gboolean ruler[NUM_BUTTONS+1]; // whether each button is in ruler mode
195   int linked_brush[NUM_BUTTONS+1]; // whether brushes are linked across buttons
196   int cur_mapping; // the current button number for mappings
197   gboolean use_erasertip;
198   int which_mouse_button; // the mouse button drawing the current path
199   struct Page default_page;  // the model for the default page
200   int layerbox_length;  // the number of entries registered in the layers combo-box
201   struct Item *cur_item; // the item being drawn, or NULL
202   int cur_item_type;
203   GnomeCanvasPoints cur_path; // the path being drawn
204   int cur_path_storage_alloc;
205   double zoom; // zoom factor, in pixels per pt
206   gboolean use_xinput; // use input devices instead of core pointer
207   gboolean allow_xinput; // allow use of xinput ?
208   gboolean discard_corepointer; // discard core pointer events in XInput mode
209   gboolean is_corestroke; // this stroke is painted with core pointer
210   int screen_width, screen_height; // initial screen size, for XInput events
211   double hand_refpt[2];
212   char *filename;
213   gchar *default_path; // default path for new notes
214   gboolean view_continuous, fullscreen, maximize_at_start;
215   gboolean in_update_page_stuff; // semaphore to avoid scrollbar retroaction
216   struct Selection *selection;
217   GdkCursor *cursor;
218   gboolean antialias_bg; // bilinear interpolation on bg pixmaps
219   gboolean progressive_bg; // rescale bg's one at a time
220   char *mrufile, *configfile; // file names for MRU & config
221   char *mru[MRU_SIZE]; // MRU data
222   GtkWidget *mrumenu[MRU_SIZE];
223   gboolean bg_apply_all_pages;
224   int window_default_width, window_default_height, scrollbar_step_increment;
225   gboolean print_ruling; // print the paper ruling ?
226   int default_unit; // the default unit for paper sizes
227   int startuptool; // the default tool at startup
228   gboolean startupruler;
229   int zoom_step_increment; // the increment in the zoom dialog box
230   double zoom_step_factor; // the multiplicative factor in zoom in/out
231   double startup_zoom;
232 #if GLIB_CHECK_VERSION(2,6,0)
233   GKeyFile *config_data;
234 #endif
235   int vertical_order[2][VBOX_MAIN_NITEMS]; // the order of interface components
236 } UIData;
237
238 #define BRUSH_LINKED 0
239 #define BRUSH_COPIED 1
240 #define BRUSH_STATIC 2
241
242 typedef struct UndoErasureData {
243   struct Item *item; // the item that got erased
244   int npos; // its position in its layer
245   int nrepl; // the number of replacement items
246   GList *replacement_items;
247 } UndoErasureData;
248
249 typedef struct UndoItem {
250   int type;
251   struct Item *item; // for ITEM_STROKE
252   struct Layer *layer; // for ITEM_STROKE, ITEM_ERASURE, ITEM_PASTE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER, ITEM_MOVESEL
253   struct Layer *layer2; // for ITEM_DELETE_LAYER with val=-1, ITEM_MOVESEL
254   struct Page *page;  // for ITEM_NEW_BG_ONE/RESIZE, ITEM_NEW_PAGE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER, ITEM_DELETE_PAGE
255   GList *erasurelist; // for ITEM_ERASURE
256   GList *itemlist;  // for ITEM_MOVESEL, ITEM_PASTE, ITEM_REPAINTSEL
257   GList *auxlist;   // for ITEM_REPAINTSEL (brushes), ITEM_MOVESEL (depths)
258   struct Background *bg;  // for ITEM_NEW_BG_ONE/RESIZE, ITEM_NEW_DEFAULT_BG
259   int val; // for ITEM_NEW_PAGE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER, ITEM_DELETE_PAGE
260   double val_x, val_y; // for ITEM_MOVESEL, ITEM_NEW_BG_RESIZE, ITEM_PAPER_RESIZE, ITEM_NEW_DEFAULT_BG
261   struct UndoItem *next;
262   int multiop;
263 } UndoItem;
264
265 #define MULTIOP_CONT_REDO 1 // not the last in a multiop, so keep redoing
266 #define MULTIOP_CONT_UNDO 2 // not the first in a multiop, so keep undoing
267
268
269 typedef struct BgPdfRequest {
270   int pageno;
271   int dpi;
272   gboolean initial_request; // if so, loop over page numbers
273   gboolean is_printing;     // this is for printing, not for display
274 } BgPdfRequest;
275
276 typedef struct BgPdfPage {
277   int dpi;
278   GdkPixbuf *pixbuf;
279 } BgPdfPage;
280
281 typedef struct BgPdf {
282   int status; // the rest only makes sense if this is not STATUS_NOT_INIT
283   int pid; // PID of the converter process
284   Refstring *filename;
285   int file_domain;
286   gchar *tmpfile_copy; // the temporary work copy of the file (in tmpdir)
287   int npages;
288   GList *pages; // a list of BgPdfPage structures
289   GList *requests; // a list of BgPdfRequest structures
290   gchar *tmpdir; // where to look for pages coming from pdf converter
291   gboolean create_pages; // create journal pages as we find stuff in PDF
292   gboolean has_failed; // has failed in the past...
293 } BgPdf;
294
295 #define STATUS_NOT_INIT 0
296 #define STATUS_IDLE     1
297 #define STATUS_RUNNING  2  // currently running child process on head(requests)
298 #define STATUS_ABORTED  3  // child process running, but head(requests) aborted
299 #define STATUS_SHUTDOWN 4  // waiting for child process to shut down
300
301 // UTILITY MACROS
302
303 // getting a component of the interface by name
304 #define GET_COMPONENT(a)  GTK_WIDGET (g_object_get_data(G_OBJECT (winMain), a))
305
306 // the margin between consecutive pages in continuous view
307 #define VIEW_CONTINUOUS_SKIP 20.0
308
309
310 // GLOBAL VARIABLES
311
312 // the main window and the canvas
313
314 extern GtkWidget *winMain;
315 extern GnomeCanvas *canvas;
316
317 // the data
318
319 extern struct Journal journal;
320 extern struct UIData ui;
321 extern struct BgPdf bgpdf;
322 extern struct UndoItem *undo, *redo;
323
324 extern double DEFAULT_ZOOM;
325
326 #define UNIT_CM 0
327 #define UNIT_IN 1
328 #define UNIT_PX 2
329 #define UNIT_PT 3