2 #include <libgnomecanvas/libgnomecanvas.h>
3 #include <poppler/glib/poppler.h>
6 /* uncomment this line if you experience event-processing problems
7 and want to list the input events received by xournal. Caution, lots
8 of output (redirect to a file). */
10 #define ENABLE_XINPUT_BUGFIX
11 /* comment out this line if you are experiencing calibration problems with
12 XInput and want to try things differently. This will probably break
13 on-the-fly display rotation after application startup, though. */
15 #define FILE_DIALOG_SIZE_BUGFIX
16 /* ugly, but should help users with versions of GTK+ that suffer from the
17 "tiny file dialog" syndrome, without hurting those with well-behaved
18 versions of GTK+. Comment out if you'd prefer not to include this fix. */
22 #define CONFIG_DIR ".xournal"
23 #define MRU_FILE "recent-files"
25 #define CONFIG_FILE "config"
27 // DATA STRUCTURES AND CONSTANTS
29 #define PIXEL_MOTION_THRESHOLD 0.3
33 #define DISPLAY_DPI_DEFAULT 96.0
35 #define RESIZE_MARGIN 6.0
36 #define MAX_SAFE_RENDER_DPI 720 // max dpi at which PDF bg's get rendered
38 #define VBOX_MAIN_NITEMS 5 // number of interface items in vboxMain
40 /* a string (+ aux data) that maintains a refcount */
42 typedef struct Refstring {
49 /* The journal is mostly a list of pages. Each page is a list of layers,
50 and a background. Each layer is a list of items, from bottom to top.
53 typedef struct Background {
55 GnomeCanvasItem *canvas_item;
63 double pixbuf_scale; // for PIXMAP, this is the *current* zoom value
64 // for PDF, this is the *requested* zoom value
65 int pixel_height, pixel_width; // PDF only: pixel size of current pixbuf
70 #define BG_PDF 2 // not implemented yet
73 #define RULING_LINED 1
74 #define RULING_RULED 2
75 #define RULING_GRAPH 3
77 #define DOMAIN_ABSOLUTE 0
78 #define DOMAIN_ATTACH 1
79 #define DOMAIN_CLONE 2 // only while loading file
81 typedef struct Brush {
88 gboolean ruler, recognizer, variable_width;
96 #define COLOR_LIGHTBLUE 5
97 #define COLOR_LIGHTGREEN 6
98 #define COLOR_MAGENTA 7
99 #define COLOR_ORANGE 8
100 #define COLOR_YELLOW 9
101 #define COLOR_WHITE 10
102 #define COLOR_OTHER -1
105 extern guint predef_colors_rgba[COLOR_MAX];
106 extern guint predef_bgcolors_rgba[COLOR_MAX];
108 #define THICKNESS_VERYFINE 0
109 #define THICKNESS_FINE 1
110 #define THICKNESS_MEDIUM 2
111 #define THICKNESS_THICK 3
112 #define THICKNESS_VERYTHICK 4
113 #define THICKNESS_MAX 5
116 #define TOOL_ERASER 1
117 #define TOOL_HIGHLIGHTER 2
119 #define TOOL_SELECTREGION 4
120 #define TOOL_SELECTRECT 5
121 #define TOOL_VERTSPACE 6
123 #define NUM_STROKE_TOOLS 3
125 #define NUM_BUTTONS 3
127 #define TOOLOPT_ERASER_STANDARD 0
128 #define TOOLOPT_ERASER_WHITEOUT 1
129 #define TOOLOPT_ERASER_STROKES 2
131 extern double predef_thickness[NUM_STROKE_TOOLS][THICKNESS_MAX];
133 typedef struct BBox {
134 double left, right, top, bottom;
137 struct UndoErasureData;
139 typedef struct Item {
141 struct Brush brush; // the brush to use, if ITEM_STROKE
142 // 'brush' also contains color info for text items
143 GnomeCanvasPoints *path;
145 GnomeCanvasItem *canvas_item; // the corresponding canvas item, or NULL
147 struct UndoErasureData *erasure; // for temporary use during erasures
148 // the following fields for ITEM_TEXT:
152 GtkWidget *widget; // the widget while text is being edited (ITEM_TEMP_TEXT)
155 // item type values for Item.type, UndoItem.type, ui.cur_item_type ...
156 // (not all are valid in all places)
158 #define ITEM_STROKE 0
159 #define ITEM_TEMP_STROKE 1
160 #define ITEM_ERASURE 2
161 #define ITEM_SELECTRECT 3
162 #define ITEM_MOVESEL 4
164 #define ITEM_NEW_LAYER 6
165 #define ITEM_DELETE_LAYER 7
166 #define ITEM_NEW_BG_ONE 8
167 #define ITEM_NEW_BG_RESIZE 9
168 #define ITEM_PAPER_RESIZE 10
169 #define ITEM_NEW_DEFAULT_BG 11
170 #define ITEM_NEW_PAGE 13
171 #define ITEM_DELETE_PAGE 14
172 #define ITEM_REPAINTSEL 15
173 #define ITEM_MOVESEL_VERT 16
176 #define ITEM_TEMP_TEXT 19
177 #define ITEM_TEXT_EDIT 20
178 #define ITEM_TEXT_ATTRIB 21
179 #define ITEM_RESIZESEL 22
180 #define ITEM_RECOGNIZER 23
182 typedef struct Layer {
183 GList *items; // the items on the layer, from bottom to top
185 GnomeCanvasGroup *group;
188 typedef struct Page {
189 GList *layers; // the layers on the page
191 double height, width;
192 double hoffset, voffset; // offsets of canvas group rel. to canvas root
193 struct Background *bg;
194 GnomeCanvasGroup *group;
197 typedef struct Journal {
198 GList *pages; // the pages in the journal
200 int last_attach_no; // for naming of attached backgrounds
203 typedef struct Selection {
204 int type; // ITEM_SELECTRECT, ITEM_MOVESEL_VERT
205 BBox bbox; // the rectangle bbox of the selection
206 struct Layer *layer; // the layer on which the selection lives
207 double anchor_x, anchor_y, last_x, last_y; // for selection motion
208 gboolean resizing_top, resizing_bottom, resizing_left, resizing_right; // for selection resizing
209 double new_x1, new_x2, new_y1, new_y2; // for selection resizing
210 GnomeCanvasItem *canvas_item; // if the selection box is on screen
211 GList *items; // the selected items (a list of struct Item)
212 int move_pageno, orig_pageno; // if selection moves to a different page
213 struct Layer *move_layer;
214 float move_pagedelta;
217 typedef struct UIData {
218 int pageno, layerno; // the current page and layer
219 struct Page *cur_page;
220 struct Layer *cur_layer;
221 gboolean saved; // is file saved ?
222 struct Brush *cur_brush; // the brush in use (one of brushes[...])
223 int toolno[NUM_BUTTONS+1]; // the number of the currently selected tool
224 struct Brush brushes[NUM_BUTTONS+1][NUM_STROKE_TOOLS]; // the current pen, eraser, hiliter
225 struct Brush default_brushes[NUM_STROKE_TOOLS]; // the default ones
226 int linked_brush[NUM_BUTTONS+1]; // whether brushes are linked across buttons
227 int cur_mapping; // the current button number for mappings
228 gboolean button_switch_mapping; // button clicks switch button 1 mappings
229 gboolean use_erasertip;
230 int which_mouse_button; // the mouse button drawing the current path
231 int which_unswitch_button; // if button_switch_mapping, the mouse button that switched the mapping
232 struct Page default_page; // the model for the default page
233 int layerbox_length; // the number of entries registered in the layers combo-box
234 struct Item *cur_item; // the item being drawn, or NULL
236 GnomeCanvasPoints cur_path; // the path being drawn
237 gdouble *cur_widths; // width array for the path being drawn
238 int cur_path_storage_alloc;
239 int cur_widths_storage_alloc;
240 double zoom; // zoom factor, in pixels per pt
241 gboolean use_xinput; // use input devices instead of core pointer
242 gboolean allow_xinput; // allow use of xinput ?
243 gboolean discard_corepointer; // discard core pointer events in XInput mode
244 gboolean pressure_sensitivity; // use pen pressure to control stroke width?
245 double width_minimum_multiplier, width_maximum_multiplier; // calibration for pressure sensitivity
246 gboolean is_corestroke; // this stroke is painted with core pointer
247 GdkDevice *stroke_device; // who's painting this stroke
248 int screen_width, screen_height; // initial screen size, for XInput events
249 double hand_refpt[2];
250 int hand_scrollto_cx, hand_scrollto_cy;
251 gboolean hand_scrollto_pending;
253 gchar *default_path; // default path for new notes
254 gboolean view_continuous, fullscreen, maximize_at_start;
255 gboolean in_update_page_stuff; // semaphore to avoid scrollbar retroaction
256 struct Selection *selection;
258 gboolean progressive_bg; // update PDF bg's one at a time
259 char *mrufile, *configfile; // file names for MRU & config
260 char *mru[MRU_SIZE]; // MRU data
261 GtkWidget *mrumenu[MRU_SIZE];
262 gboolean bg_apply_all_pages;
263 int window_default_width, window_default_height, scrollbar_step_increment;
264 gboolean print_ruling; // print the paper ruling ?
265 int default_unit; // the default unit for paper sizes
266 int startuptool; // the default tool at startup
267 int zoom_step_increment; // the increment in the zoom dialog box
268 double zoom_step_factor; // the multiplicative factor in zoom in/out
270 gboolean autoload_pdf_xoj;
271 #if GLIB_CHECK_VERSION(2,6,0)
272 GKeyFile *config_data;
274 int vertical_order[2][VBOX_MAIN_NITEMS]; // the order of interface components
275 gchar *default_font_name, *font_name;
276 gdouble default_font_size, font_size;
277 gulong resize_signal_handler;
278 gdouble hiliter_opacity;
279 guint hiliter_alpha_mask;
280 gboolean left_handed; // left-handed mode?
281 gboolean auto_save_prefs; // auto-save preferences ?
282 gboolean shorten_menus; // shorten menus ?
283 gchar *shorten_menu_items; // which items to hide
284 gboolean is_sel_cursor; // displaying a selection-related cursor
285 #if GTK_CHECK_VERSION(2,10,0)
286 GtkPrintSettings *print_settings;
290 #define BRUSH_LINKED 0
291 #define BRUSH_COPIED 1
292 #define BRUSH_STATIC 2
294 typedef struct UndoErasureData {
295 struct Item *item; // the item that got erased
296 int npos; // its position in its layer
297 int nrepl; // the number of replacement items
298 GList *replacement_items;
301 typedef struct UndoItem {
303 struct Item *item; // for ITEM_STROKE, ITEM_TEXT, ITEM_TEXT_EDIT, ITEM_TEXT_ATTRIB
304 struct Layer *layer; // for ITEM_STROKE, ITEM_ERASURE, ITEM_PASTE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER, ITEM_MOVESEL, ITEM_TEXT, ITEM_TEXT_EDIT, ITEM_RECOGNIZER
305 struct Layer *layer2; // for ITEM_DELETE_LAYER with val=-1, ITEM_MOVESEL
306 struct Page *page; // for ITEM_NEW_BG_ONE/RESIZE, ITEM_NEW_PAGE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER, ITEM_DELETE_PAGE
307 GList *erasurelist; // for ITEM_ERASURE, ITEM_RECOGNIZER
308 GList *itemlist; // for ITEM_MOVESEL, ITEM_PASTE, ITEM_REPAINTSEL, ITEM_RESIZESEL
309 GList *auxlist; // for ITEM_REPAINTSEL (brushes), ITEM_MOVESEL (depths)
310 struct Background *bg; // for ITEM_NEW_BG_ONE/RESIZE, ITEM_NEW_DEFAULT_BG
311 int val; // for ITEM_NEW_PAGE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER, ITEM_DELETE_PAGE
312 double val_x, val_y; // for ITEM_MOVESEL, ITEM_NEW_BG_RESIZE, ITEM_PAPER_RESIZE, ITEM_NEW_DEFAULT_BG, ITEM_TEXT_ATTRIB, ITEM_RESIZESEL
313 double scaling_x, scaling_y; // for ITEM_RESIZESEL
314 gchar *str; // for ITEM_TEXT_EDIT, ITEM_TEXT_ATTRIB
315 struct Brush *brush; // for ITEM_TEXT_ATTRIB
316 struct UndoItem *next;
320 #define MULTIOP_CONT_REDO 1 // not the last in a multiop, so keep redoing
321 #define MULTIOP_CONT_UNDO 2 // not the first in a multiop, so keep undoing
324 typedef struct BgPdfRequest {
329 typedef struct BgPdfPage {
332 int pixel_height, pixel_width; // pixel size of pixbuf
335 typedef struct BgPdf {
336 int status; // the rest only makes sense if this is not STATUS_NOT_INIT
337 guint pid; // the identifier of the idle callback
340 gchar *file_contents; // buffer containing a copy of file data
341 gsize file_length; // size of above buffer
343 GList *pages; // a list of BgPdfPage structures
344 GList *requests; // a list of BgPdfRequest structures
345 gboolean has_failed; // has failed in the past...
346 PopplerDocument *document; // the poppler document
349 #define STATUS_NOT_INIT 0
350 #define STATUS_READY 1 // things are initialized and can work
351 // there used to be more possible values, things got streamlined...
355 // getting a component of the interface by name
356 #define GET_COMPONENT(a) GTK_WIDGET (g_object_get_data(G_OBJECT (winMain), a))
358 // the margin between consecutive pages in continuous view
359 #define VIEW_CONTINUOUS_SKIP 20.0
364 // the main window and the canvas
366 extern GtkWidget *winMain;
367 extern GnomeCanvas *canvas;
371 extern struct Journal journal;
372 extern struct UIData ui;
373 extern struct BgPdf bgpdf;
374 extern struct UndoItem *undo, *redo;
376 extern double DEFAULT_ZOOM;