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. */
17 #define CONFIG_DIR ".xournal"
18 #define MRU_FILE "recent-files"
20 #define CONFIG_FILE "config"
22 // DATA STRUCTURES AND CONSTANTS
24 #define PIXEL_MOTION_THRESHOLD 0.3
28 #define DISPLAY_DPI_DEFAULT 96.0
30 #define RESIZE_MARGIN 6.0
31 #define MAX_SAFE_RENDER_DPI 720 // max dpi at which PDF bg's get rendered
33 #define VBOX_MAIN_NITEMS 5 // number of interface items in vboxMain
35 /* a string (+ aux data) that maintains a refcount */
37 typedef struct Refstring {
44 /* The journal is mostly a list of pages. Each page is a list of layers,
45 and a background. Each layer is a list of items, from bottom to top.
48 typedef struct Background {
50 GnomeCanvasItem *canvas_item;
58 double pixbuf_scale; // for PIXMAP, this is the *current* zoom value
59 // for PDF, this is the *requested* zoom value
60 int pixel_height, pixel_width; // PDF only: pixel size of current pixbuf
65 #define BG_PDF 2 // not implemented yet
68 #define RULING_LINED 1
69 #define RULING_RULED 2
70 #define RULING_GRAPH 3
72 #define DOMAIN_ABSOLUTE 0
73 #define DOMAIN_ATTACH 1
74 #define DOMAIN_CLONE 2 // only while loading file
76 typedef struct Brush {
83 gboolean ruler, recognizer, variable_width;
91 #define COLOR_LIGHTBLUE 5
92 #define COLOR_LIGHTGREEN 6
93 #define COLOR_MAGENTA 7
94 #define COLOR_ORANGE 8
95 #define COLOR_YELLOW 9
96 #define COLOR_WHITE 10
97 #define COLOR_OTHER -1
100 extern guint predef_colors_rgba[COLOR_MAX];
101 extern guint predef_bgcolors_rgba[COLOR_MAX];
103 #define THICKNESS_VERYFINE 0
104 #define THICKNESS_FINE 1
105 #define THICKNESS_MEDIUM 2
106 #define THICKNESS_THICK 3
107 #define THICKNESS_VERYTHICK 4
108 #define THICKNESS_MAX 5
111 #define TOOL_ERASER 1
112 #define TOOL_HIGHLIGHTER 2
114 #define TOOL_SELECTREGION 4
115 #define TOOL_SELECTRECT 5
116 #define TOOL_VERTSPACE 6
118 #define NUM_STROKE_TOOLS 3
120 #define NUM_BUTTONS 3
122 #define TOOLOPT_ERASER_STANDARD 0
123 #define TOOLOPT_ERASER_WHITEOUT 1
124 #define TOOLOPT_ERASER_STROKES 2
126 extern double predef_thickness[NUM_STROKE_TOOLS][THICKNESS_MAX];
128 typedef struct BBox {
129 double left, right, top, bottom;
132 struct UndoErasureData;
134 typedef struct Item {
136 struct Brush brush; // the brush to use, if ITEM_STROKE
137 // 'brush' also contains color info for text items
138 GnomeCanvasPoints *path;
140 GnomeCanvasItem *canvas_item; // the corresponding canvas item, or NULL
142 struct UndoErasureData *erasure; // for temporary use during erasures
143 // the following fields for ITEM_TEXT:
147 GtkWidget *widget; // the widget while text is being edited (ITEM_TEMP_TEXT)
150 // item type values for Item.type, UndoItem.type, ui.cur_item_type ...
151 // (not all are valid in all places)
153 #define ITEM_STROKE 0
154 #define ITEM_TEMP_STROKE 1
155 #define ITEM_ERASURE 2
156 #define ITEM_SELECTRECT 3
157 #define ITEM_MOVESEL 4
159 #define ITEM_NEW_LAYER 6
160 #define ITEM_DELETE_LAYER 7
161 #define ITEM_NEW_BG_ONE 8
162 #define ITEM_NEW_BG_RESIZE 9
163 #define ITEM_PAPER_RESIZE 10
164 #define ITEM_NEW_DEFAULT_BG 11
165 #define ITEM_NEW_PAGE 13
166 #define ITEM_DELETE_PAGE 14
167 #define ITEM_REPAINTSEL 15
168 #define ITEM_MOVESEL_VERT 16
171 #define ITEM_TEMP_TEXT 19
172 #define ITEM_TEXT_EDIT 20
173 #define ITEM_TEXT_ATTRIB 21
174 #define ITEM_RESIZESEL 22
175 #define ITEM_RECOGNIZER 23
177 typedef struct Layer {
178 GList *items; // the items on the layer, from bottom to top
180 GnomeCanvasGroup *group;
183 typedef struct Page {
184 GList *layers; // the layers on the page
186 double height, width;
187 double hoffset, voffset; // offsets of canvas group rel. to canvas root
188 struct Background *bg;
189 GnomeCanvasGroup *group;
192 typedef struct Journal {
193 GList *pages; // the pages in the journal
195 int last_attach_no; // for naming of attached backgrounds
198 typedef struct Selection {
199 int type; // ITEM_SELECTRECT, ITEM_MOVESEL_VERT
200 BBox bbox; // the rectangle bbox of the selection
201 struct Layer *layer; // the layer on which the selection lives
202 double anchor_x, anchor_y, last_x, last_y; // for selection motion
203 gboolean resizing_top, resizing_bottom, resizing_left, resizing_right; // for selection resizing
204 double new_x1, new_x2, new_y1, new_y2; // for selection resizing
205 GnomeCanvasItem *canvas_item; // if the selection box is on screen
206 GList *items; // the selected items (a list of struct Item)
207 int move_pageno, orig_pageno; // if selection moves to a different page
208 struct Layer *move_layer;
209 float move_pagedelta;
212 typedef struct UIData {
213 int pageno, layerno; // the current page and layer
214 struct Page *cur_page;
215 struct Layer *cur_layer;
216 gboolean saved; // is file saved ?
217 struct Brush *cur_brush; // the brush in use (one of brushes[...])
218 int toolno[NUM_BUTTONS+1]; // the number of the currently selected tool
219 struct Brush brushes[NUM_BUTTONS+1][NUM_STROKE_TOOLS]; // the current pen, eraser, hiliter
220 struct Brush default_brushes[NUM_STROKE_TOOLS]; // the default ones
221 int linked_brush[NUM_BUTTONS+1]; // whether brushes are linked across buttons
222 int cur_mapping; // the current button number for mappings
223 gboolean use_erasertip;
224 int which_mouse_button; // the mouse button drawing the current path
225 struct Page default_page; // the model for the default page
226 int layerbox_length; // the number of entries registered in the layers combo-box
227 struct Item *cur_item; // the item being drawn, or NULL
229 GnomeCanvasPoints cur_path; // the path being drawn
230 gdouble *cur_widths; // width array for the path being drawn
231 int cur_path_storage_alloc;
232 int cur_widths_storage_alloc;
233 double zoom; // zoom factor, in pixels per pt
234 gboolean use_xinput; // use input devices instead of core pointer
235 gboolean allow_xinput; // allow use of xinput ?
236 gboolean discard_corepointer; // discard core pointer events in XInput mode
237 gboolean pressure_sensitivity; // use pen pressure to control stroke width?
238 double width_minimum_multiplier, width_maximum_multiplier; // calibration for pressure sensitivity
239 gboolean is_corestroke; // this stroke is painted with core pointer
240 int screen_width, screen_height; // initial screen size, for XInput events
241 double hand_refpt[2];
242 int hand_scrollto_cx, hand_scrollto_cy;
243 gboolean hand_scrollto_pending;
245 gchar *default_path; // default path for new notes
246 gboolean view_continuous, fullscreen, maximize_at_start;
247 gboolean in_update_page_stuff; // semaphore to avoid scrollbar retroaction
248 struct Selection *selection;
250 gboolean antialias_bg; // bilinear interpolation on bg pixmaps
251 gboolean progressive_bg; // rescale bg's one at a time
252 char *mrufile, *configfile; // file names for MRU & config
253 char *mru[MRU_SIZE]; // MRU data
254 GtkWidget *mrumenu[MRU_SIZE];
255 gboolean bg_apply_all_pages;
256 int window_default_width, window_default_height, scrollbar_step_increment;
257 gboolean print_ruling; // print the paper ruling ?
258 int default_unit; // the default unit for paper sizes
259 int startuptool; // the default tool at startup
260 int zoom_step_increment; // the increment in the zoom dialog box
261 double zoom_step_factor; // the multiplicative factor in zoom in/out
263 #if GLIB_CHECK_VERSION(2,6,0)
264 GKeyFile *config_data;
266 int vertical_order[2][VBOX_MAIN_NITEMS]; // the order of interface components
267 gchar *default_font_name, *font_name;
268 gdouble default_font_size, font_size;
269 gulong resize_signal_handler;
270 gdouble hiliter_opacity;
271 guint hiliter_alpha_mask;
272 gboolean left_handed; // left-handed mode?
273 gboolean auto_save_prefs; // auto-save preferences ?
274 gboolean shorten_menus; // shorten menus ?
275 gchar *shorten_menu_items; // which items to hide
276 gboolean is_sel_cursor; // displaying a selection-related cursor
279 #define BRUSH_LINKED 0
280 #define BRUSH_COPIED 1
281 #define BRUSH_STATIC 2
283 typedef struct UndoErasureData {
284 struct Item *item; // the item that got erased
285 int npos; // its position in its layer
286 int nrepl; // the number of replacement items
287 GList *replacement_items;
290 typedef struct UndoItem {
292 struct Item *item; // for ITEM_STROKE, ITEM_TEXT, ITEM_TEXT_EDIT, ITEM_TEXT_ATTRIB
293 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
294 struct Layer *layer2; // for ITEM_DELETE_LAYER with val=-1, ITEM_MOVESEL
295 struct Page *page; // for ITEM_NEW_BG_ONE/RESIZE, ITEM_NEW_PAGE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER, ITEM_DELETE_PAGE
296 GList *erasurelist; // for ITEM_ERASURE, ITEM_RECOGNIZER
297 GList *itemlist; // for ITEM_MOVESEL, ITEM_PASTE, ITEM_REPAINTSEL, ITEM_RESIZESEL
298 GList *auxlist; // for ITEM_REPAINTSEL (brushes), ITEM_MOVESEL (depths)
299 struct Background *bg; // for ITEM_NEW_BG_ONE/RESIZE, ITEM_NEW_DEFAULT_BG
300 int val; // for ITEM_NEW_PAGE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER, ITEM_DELETE_PAGE
301 double val_x, val_y; // for ITEM_MOVESEL, ITEM_NEW_BG_RESIZE, ITEM_PAPER_RESIZE, ITEM_NEW_DEFAULT_BG, ITEM_TEXT_ATTRIB, ITEM_RESIZESEL
302 double scaling_x, scaling_y; // for ITEM_RESIZESEL
303 gchar *str; // for ITEM_TEXT_EDIT, ITEM_TEXT_ATTRIB
304 struct Brush *brush; // for ITEM_TEXT_ATTRIB
305 struct UndoItem *next;
309 #define MULTIOP_CONT_REDO 1 // not the last in a multiop, so keep redoing
310 #define MULTIOP_CONT_UNDO 2 // not the first in a multiop, so keep undoing
313 typedef struct BgPdfRequest {
318 typedef struct BgPdfPage {
321 int pixel_height, pixel_width; // pixel size of pixbuf
324 typedef struct BgPdf {
325 int status; // the rest only makes sense if this is not STATUS_NOT_INIT
326 guint pid; // the identifier of the idle callback
329 gchar *file_contents; // buffer containing a copy of file data
330 gsize file_length; // size of above buffer
332 GList *pages; // a list of BgPdfPage structures
333 GList *requests; // a list of BgPdfRequest structures
334 gboolean has_failed; // has failed in the past...
335 PopplerDocument *document; // the poppler document
338 #define STATUS_NOT_INIT 0
339 #define STATUS_READY 1 // things are initialized and can work
340 // there used to be more possible values, things got streamlined...
344 // getting a component of the interface by name
345 #define GET_COMPONENT(a) GTK_WIDGET (g_object_get_data(G_OBJECT (winMain), a))
347 // the margin between consecutive pages in continuous view
348 #define VIEW_CONTINUOUS_SKIP 20.0
353 // the main window and the canvas
355 extern GtkWidget *winMain;
356 extern GnomeCanvas *canvas;
360 extern struct Journal journal;
361 extern struct UIData ui;
362 extern struct BgPdf bgpdf;
363 extern struct UndoItem *undo, *redo;
365 extern double DEFAULT_ZOOM;