2 #include <libgnomecanvas/libgnomecanvas.h>
4 /* #define INPUT_DEBUG */
5 /* uncomment this line if you experience event-processing problems
6 and want to list the input events received by xournal. Caution, lots
7 of output (redirect to a file). */
9 #define ENABLE_XINPUT_BUGFIX
10 /* comment out this line if you are experiencing calibration problems with
11 XInput and want to try things differently. This will probably break
12 on-the-fly display rotation after application startup, though. */
16 #define CONFIG_DIR ".xournal"
17 #define MRU_FILE "recent-files"
19 #define CONFIG_FILE "config"
21 // DATA STRUCTURES AND CONSTANTS
23 #define PIXEL_MOTION_THRESHOLD 0.3
27 #define DISPLAY_DPI_DEFAULT 96.0
29 #define RESIZE_MARGIN 6.0
31 #define VBOX_MAIN_NITEMS 5 // number of interface items in vboxMain
33 /* a string (+ aux data) that maintains a refcount */
35 typedef struct Refstring {
42 /* The journal is mostly a list of pages. Each page is a list of layers,
43 and a background. Each layer is a list of items, from bottom to top.
46 typedef struct Background {
48 GnomeCanvasItem *canvas_item;
56 int pixbuf_dpi; // for PDF only - the *current* dpi value
57 double pixbuf_scale; // for PIXMAP, this is the *current* zoom value
58 // for PDF, this is the *requested* zoom value
63 #define BG_PDF 2 // not implemented yet
66 #define RULING_LINED 1
67 #define RULING_RULED 2
68 #define RULING_GRAPH 3
70 #define DOMAIN_ABSOLUTE 0
71 #define DOMAIN_ATTACH 1
72 #define DOMAIN_CLONE 2 // only while loading file
74 typedef struct Brush {
81 gboolean ruler, recognizer, variable_width;
89 #define COLOR_LIGHTBLUE 5
90 #define COLOR_LIGHTGREEN 6
91 #define COLOR_MAGENTA 7
92 #define COLOR_ORANGE 8
93 #define COLOR_YELLOW 9
94 #define COLOR_WHITE 10
95 #define COLOR_OTHER -1
98 extern guint predef_colors_rgba[COLOR_MAX];
99 extern guint predef_bgcolors_rgba[COLOR_MAX];
101 #define THICKNESS_VERYFINE 0
102 #define THICKNESS_FINE 1
103 #define THICKNESS_MEDIUM 2
104 #define THICKNESS_THICK 3
105 #define THICKNESS_VERYTHICK 4
106 #define THICKNESS_MAX 5
109 #define TOOL_ERASER 1
110 #define TOOL_HIGHLIGHTER 2
112 #define TOOL_SELECTREGION 4
113 #define TOOL_SELECTRECT 5
114 #define TOOL_VERTSPACE 6
116 #define NUM_STROKE_TOOLS 3
118 #define NUM_BUTTONS 3
120 #define TOOLOPT_ERASER_STANDARD 0
121 #define TOOLOPT_ERASER_WHITEOUT 1
122 #define TOOLOPT_ERASER_STROKES 2
124 extern double predef_thickness[NUM_STROKE_TOOLS][THICKNESS_MAX];
126 typedef struct BBox {
127 double left, right, top, bottom;
130 struct UndoErasureData;
132 typedef struct Item {
134 struct Brush brush; // the brush to use, if ITEM_STROKE
135 // 'brush" also contains color info for text items
136 GnomeCanvasPoints *path;
138 GnomeCanvasItem *canvas_item; // the corresponding canvas item, or NULL
140 struct UndoErasureData *erasure; // for temporary use during erasures
141 // the following fields for ITEM_TEXT:
145 GtkWidget *widget; // the widget while text is being edited (ITEM_TEMP_TEXT)
148 // item type values for Item.type, UndoItem.type, ui.cur_item_type ...
149 // (not all are valid in all places)
151 #define ITEM_STROKE 0
152 #define ITEM_TEMP_STROKE 1
153 #define ITEM_ERASURE 2
154 #define ITEM_SELECTRECT 3
155 #define ITEM_MOVESEL 4
157 #define ITEM_NEW_LAYER 6
158 #define ITEM_DELETE_LAYER 7
159 #define ITEM_NEW_BG_ONE 8
160 #define ITEM_NEW_BG_RESIZE 9
161 #define ITEM_PAPER_RESIZE 10
162 #define ITEM_NEW_DEFAULT_BG 11
163 #define ITEM_NEW_PAGE 13
164 #define ITEM_DELETE_PAGE 14
165 #define ITEM_REPAINTSEL 15
166 #define ITEM_MOVESEL_VERT 16
169 #define ITEM_TEMP_TEXT 19
170 #define ITEM_TEXT_EDIT 20
171 #define ITEM_TEXT_ATTRIB 21
172 #define ITEM_RESIZESEL 22
173 #define ITEM_RECOGNIZER 23
175 typedef struct Layer {
176 GList *items; // the items on the layer, from bottom to top
178 GnomeCanvasGroup *group;
181 typedef struct Page {
182 GList *layers; // the layers on the page
184 double height, width;
185 double hoffset, voffset; // offsets of canvas group rel. to canvas root
186 struct Background *bg;
187 GnomeCanvasGroup *group;
190 typedef struct Journal {
191 GList *pages; // the pages in the journal
193 int last_attach_no; // for naming of attached backgrounds
196 typedef struct Selection {
197 int type; // ITEM_SELECTRECT, ITEM_MOVESEL_VERT
198 BBox bbox; // the rectangle bbox of the selection
199 struct Layer *layer; // the layer on which the selection lives
200 double anchor_x, anchor_y, last_x, last_y; // for selection motion
201 gboolean resizing_top, resizing_bottom, resizing_left, resizing_right; // for selection resizing
202 double new_x1, new_x2, new_y1, new_y2; // for selection resizing
203 GnomeCanvasItem *canvas_item; // if the selection box is on screen
204 GList *items; // the selected items (a list of struct Item)
205 int move_pageno, orig_pageno; // if selection moves to a different page
206 struct Layer *move_layer;
207 float move_pagedelta;
210 typedef struct UIData {
211 int pageno, layerno; // the current page and layer
212 struct Page *cur_page;
213 struct Layer *cur_layer;
214 gboolean saved; // is file saved ?
215 struct Brush *cur_brush; // the brush in use (one of brushes[...])
216 int toolno[NUM_BUTTONS+1]; // the number of the currently selected tool
217 struct Brush brushes[NUM_BUTTONS+1][NUM_STROKE_TOOLS]; // the current pen, eraser, hiliter
218 struct Brush default_brushes[NUM_STROKE_TOOLS]; // the default ones
219 int linked_brush[NUM_BUTTONS+1]; // whether brushes are linked across buttons
220 int cur_mapping; // the current button number for mappings
221 gboolean use_erasertip;
222 int which_mouse_button; // the mouse button drawing the current path
223 struct Page default_page; // the model for the default page
224 int layerbox_length; // the number of entries registered in the layers combo-box
225 struct Item *cur_item; // the item being drawn, or NULL
227 GnomeCanvasPoints cur_path; // the path being drawn
228 gdouble *cur_widths; // width array for the path being drawn
229 int cur_path_storage_alloc;
230 int cur_widths_storage_alloc;
231 double zoom; // zoom factor, in pixels per pt
232 gboolean use_xinput; // use input devices instead of core pointer
233 gboolean allow_xinput; // allow use of xinput ?
234 gboolean discard_corepointer; // discard core pointer events in XInput mode
235 gboolean pressure_sensitivity; // use pen pressure to control stroke width?
236 double width_minimum_multiplier, width_maximum_multiplier; // calibration for pressure sensitivity
237 gboolean is_corestroke; // this stroke is painted with core pointer
238 int screen_width, screen_height; // initial screen size, for XInput events
239 double hand_refpt[2];
240 int hand_scrollto_cx, hand_scrollto_cy;
241 gboolean hand_scrollto_pending;
243 gchar *default_path; // default path for new notes
244 gboolean view_continuous, fullscreen, maximize_at_start;
245 gboolean in_update_page_stuff; // semaphore to avoid scrollbar retroaction
246 struct Selection *selection;
248 gboolean antialias_bg; // bilinear interpolation on bg pixmaps
249 gboolean progressive_bg; // rescale bg's one at a time
250 char *mrufile, *configfile; // file names for MRU & config
251 char *mru[MRU_SIZE]; // MRU data
252 GtkWidget *mrumenu[MRU_SIZE];
253 gboolean bg_apply_all_pages;
254 int window_default_width, window_default_height, scrollbar_step_increment;
255 gboolean print_ruling; // print the paper ruling ?
256 int default_unit; // the default unit for paper sizes
257 int startuptool; // the default tool at startup
258 int zoom_step_increment; // the increment in the zoom dialog box
259 double zoom_step_factor; // the multiplicative factor in zoom in/out
261 #if GLIB_CHECK_VERSION(2,6,0)
262 GKeyFile *config_data;
264 int vertical_order[2][VBOX_MAIN_NITEMS]; // the order of interface components
265 gchar *default_font_name, *font_name;
266 gdouble default_font_size, font_size;
267 gulong resize_signal_handler;
268 gdouble hiliter_opacity;
269 guint hiliter_alpha_mask;
270 gboolean left_handed; // left-handed mode?
271 gboolean auto_save_prefs; // auto-save preferences ?
272 gboolean shorten_menus; // shorten menus ?
273 gchar *shorten_menu_items; // which items to hide
274 gboolean is_sel_cursor; // displaying a selection-related cursor
277 #define BRUSH_LINKED 0
278 #define BRUSH_COPIED 1
279 #define BRUSH_STATIC 2
281 typedef struct UndoErasureData {
282 struct Item *item; // the item that got erased
283 int npos; // its position in its layer
284 int nrepl; // the number of replacement items
285 GList *replacement_items;
288 typedef struct UndoItem {
290 struct Item *item; // for ITEM_STROKE, ITEM_TEXT, ITEM_TEXT_EDIT, ITEM_TEXT_ATTRIB
291 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
292 struct Layer *layer2; // for ITEM_DELETE_LAYER with val=-1, ITEM_MOVESEL
293 struct Page *page; // for ITEM_NEW_BG_ONE/RESIZE, ITEM_NEW_PAGE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER, ITEM_DELETE_PAGE
294 GList *erasurelist; // for ITEM_ERASURE, ITEM_RECOGNIZER
295 GList *itemlist; // for ITEM_MOVESEL, ITEM_PASTE, ITEM_REPAINTSEL, ITEM_RESIZESEL
296 GList *auxlist; // for ITEM_REPAINTSEL (brushes), ITEM_MOVESEL (depths)
297 struct Background *bg; // for ITEM_NEW_BG_ONE/RESIZE, ITEM_NEW_DEFAULT_BG
298 int val; // for ITEM_NEW_PAGE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER, ITEM_DELETE_PAGE
299 double val_x, val_y; // for ITEM_MOVESEL, ITEM_NEW_BG_RESIZE, ITEM_PAPER_RESIZE, ITEM_NEW_DEFAULT_BG, ITEM_TEXT_ATTRIB, ITEM_RESIZESEL
300 double scaling_x, scaling_y; // for ITEM_RESIZESEL
301 gchar *str; // for ITEM_TEXT_EDIT, ITEM_TEXT_ATTRIB
302 struct Brush *brush; // for ITEM_TEXT_ATTRIB
303 struct UndoItem *next;
307 #define MULTIOP_CONT_REDO 1 // not the last in a multiop, so keep redoing
308 #define MULTIOP_CONT_UNDO 2 // not the first in a multiop, so keep undoing
311 typedef struct BgPdfRequest {
314 gboolean initial_request; // if so, loop over page numbers
315 gboolean is_printing; // this is for printing, not for display
318 typedef struct BgPdfPage {
323 typedef struct BgPdf {
324 int status; // the rest only makes sense if this is not STATUS_NOT_INIT
325 int pid; // PID of the converter process
328 gchar *tmpfile_copy; // the temporary work copy of the file (in tmpdir)
330 GList *pages; // a list of BgPdfPage structures
331 GList *requests; // a list of BgPdfRequest structures
332 gchar *tmpdir; // where to look for pages coming from pdf converter
333 gboolean create_pages; // create journal pages as we find stuff in PDF
334 gboolean has_failed; // has failed in the past...
337 #define STATUS_NOT_INIT 0
338 #define STATUS_IDLE 1
339 #define STATUS_RUNNING 2 // currently running child process on head(requests)
340 #define STATUS_ABORTED 3 // child process running, but head(requests) aborted
341 #define STATUS_SHUTDOWN 4 // waiting for child process to shut down
345 // getting a component of the interface by name
346 #define GET_COMPONENT(a) GTK_WIDGET (g_object_get_data(G_OBJECT (winMain), a))
348 // the margin between consecutive pages in continuous view
349 #define VIEW_CONTINUOUS_SKIP 20.0
354 // the main window and the canvas
356 extern GtkWidget *winMain;
357 extern GnomeCanvas *canvas;
361 extern struct Journal journal;
362 extern struct UIData ui;
363 extern struct BgPdf bgpdf;
364 extern struct UndoItem *undo, *redo;
366 extern double DEFAULT_ZOOM;