File: | tests/print-editor.c |
Warning: | line 1012, column 8 This statement is never executed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | #include <math.h> |
2 | #include <pango/pangocairo.h> |
3 | #include <ctk/ctk.h> |
4 | |
5 | static CtkWidget *main_window; |
6 | static char *filename = NULL((void*)0); |
7 | static CtkPageSetup *page_setup = NULL((void*)0); |
8 | static CtkPrintSettings *settings = NULL((void*)0); |
9 | static gboolean file_changed = FALSE(0); |
10 | static CtkTextBuffer *buffer; |
11 | static CtkWidget *statusbar; |
12 | static GList *active_prints = NULL((void*)0); |
13 | |
14 | static void |
15 | update_title (CtkWindow *window) |
16 | { |
17 | char *basename; |
18 | char *title; |
19 | |
20 | if (filename == NULL((void*)0)) |
21 | basename = g_strdup ("Untitled")g_strdup_inline ("Untitled"); |
22 | else |
23 | basename = g_path_get_basename (filename); |
24 | |
25 | title = g_strdup_printf ("Simple Editor with printing - %s", basename); |
26 | g_free (basename); |
27 | |
28 | ctk_window_set_title (window, title); |
29 | g_free (title); |
30 | } |
31 | |
32 | static void |
33 | update_statusbar (void) |
34 | { |
35 | gchar *msg; |
36 | gint row, col; |
37 | CtkTextIter iter; |
38 | const char *print_str; |
39 | |
40 | ctk_statusbar_pop (CTK_STATUSBAR (statusbar)((((CtkStatusbar*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((statusbar)), ((ctk_statusbar_get_type ())))))), 0); |
41 | |
42 | ctk_text_buffer_get_iter_at_mark (buffer, |
43 | &iter, |
44 | ctk_text_buffer_get_insert (buffer)); |
45 | |
46 | row = ctk_text_iter_get_line (&iter); |
47 | col = ctk_text_iter_get_line_offset (&iter); |
48 | |
49 | print_str = ""; |
50 | if (active_prints) |
51 | { |
52 | CtkPrintOperation *op = active_prints->data; |
53 | print_str = ctk_print_operation_get_status_string (op); |
54 | } |
55 | |
56 | msg = g_strdup_printf ("%d, %d%s %s", |
57 | row, col, |
58 | file_changed?" - Modified":"", |
59 | print_str); |
60 | |
61 | ctk_statusbar_push (CTK_STATUSBAR (statusbar)((((CtkStatusbar*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((statusbar)), ((ctk_statusbar_get_type ())))))), 0, msg); |
62 | |
63 | g_free (msg); |
64 | } |
65 | |
66 | static void |
67 | update_ui (void) |
68 | { |
69 | update_title (CTK_WINDOW (main_window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((main_window)), ((ctk_window_get_type ()))))))); |
70 | update_statusbar (); |
71 | } |
72 | |
73 | static char * |
74 | get_text (void) |
75 | { |
76 | CtkTextIter start, end; |
77 | |
78 | ctk_text_buffer_get_start_iter (buffer, &start); |
79 | ctk_text_buffer_get_end_iter (buffer, &end); |
80 | return ctk_text_buffer_get_text (buffer, &start, &end, FALSE(0)); |
81 | } |
82 | |
83 | static void |
84 | set_text (const char *text, gsize len) |
85 | { |
86 | ctk_text_buffer_set_text (buffer, text, len); |
87 | file_changed = FALSE(0); |
88 | update_ui (); |
89 | } |
90 | |
91 | static void |
92 | load_file (const char *open_filename) |
93 | { |
94 | CtkWidget *error_dialog; |
95 | char *contents; |
96 | GError *error; |
97 | gsize len; |
98 | |
99 | error_dialog = NULL((void*)0); |
100 | error = NULL((void*)0); |
101 | if (g_file_get_contents (open_filename, &contents, &len, &error)) |
102 | { |
103 | if (g_utf8_validate (contents, len, NULL((void*)0))) |
104 | { |
105 | filename = g_strdup (open_filename)g_strdup_inline (open_filename); |
106 | set_text (contents, len); |
107 | g_free (contents); |
108 | } |
109 | else |
110 | { |
111 | error_dialog = ctk_message_dialog_new (CTK_WINDOW (main_window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((main_window)), ((ctk_window_get_type ())))))), |
112 | CTK_DIALOG_DESTROY_WITH_PARENT, |
113 | CTK_MESSAGE_ERROR, |
114 | CTK_BUTTONS_CLOSE, |
115 | "Error loading file %s:\n%s", |
116 | open_filename, |
117 | "Not valid utf8"); |
118 | } |
119 | } |
120 | else |
121 | { |
122 | error_dialog = ctk_message_dialog_new (CTK_WINDOW (main_window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((main_window)), ((ctk_window_get_type ())))))), |
123 | CTK_DIALOG_DESTROY_WITH_PARENT, |
124 | CTK_MESSAGE_ERROR, |
125 | CTK_BUTTONS_CLOSE, |
126 | "Error loading file %s:\n%s", |
127 | open_filename, |
128 | error->message); |
129 | |
130 | g_error_free (error); |
131 | } |
132 | if (error_dialog) |
133 | { |
134 | g_signal_connect (error_dialog, "response", G_CALLBACK (ctk_widget_destroy), NULL)g_signal_connect_data ((error_dialog), ("response"), (((GCallback ) (ctk_widget_destroy))), (((void*)0)), ((void*)0), (GConnectFlags ) 0); |
135 | ctk_widget_show (error_dialog); |
136 | } |
137 | } |
138 | |
139 | |
140 | static void |
141 | save_file (const char *save_filename) |
142 | { |
143 | char *text = get_text (); |
144 | GError *error; |
145 | |
146 | error = NULL((void*)0); |
147 | if (g_file_set_contents (save_filename, |
148 | text, -1, &error)) |
149 | { |
150 | if (save_filename != filename) |
151 | { |
152 | g_free (filename); |
153 | filename = g_strdup (save_filename)g_strdup_inline (save_filename); |
154 | } |
155 | file_changed = FALSE(0); |
156 | update_ui (); |
157 | } |
158 | else |
159 | { |
160 | CtkWidget *error_dialog; |
161 | |
162 | error_dialog = ctk_message_dialog_new (CTK_WINDOW (main_window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((main_window)), ((ctk_window_get_type ())))))), |
163 | CTK_DIALOG_DESTROY_WITH_PARENT, |
164 | CTK_MESSAGE_ERROR, |
165 | CTK_BUTTONS_CLOSE, |
166 | "Error saving to file %s:\n%s", |
167 | filename, |
168 | error->message); |
169 | |
170 | g_signal_connect (error_dialog, "response", G_CALLBACK (ctk_widget_destroy), NULL)g_signal_connect_data ((error_dialog), ("response"), (((GCallback ) (ctk_widget_destroy))), (((void*)0)), ((void*)0), (GConnectFlags ) 0); |
171 | ctk_widget_show (error_dialog); |
172 | |
173 | g_error_free (error); |
174 | } |
175 | } |
176 | |
177 | |
178 | typedef struct { |
179 | char *text; |
180 | PangoLayout *layout; |
181 | GList *page_breaks; |
182 | CtkWidget *font_button; |
183 | char *font; |
184 | } PrintData; |
185 | |
186 | static void |
187 | begin_print (CtkPrintOperation *operation, |
188 | CtkPrintContext *context, |
189 | PrintData *print_data) |
190 | { |
191 | PangoFontDescription *desc; |
192 | double width, height; |
193 | double page_height; |
194 | GList *page_breaks; |
195 | int num_lines; |
196 | int line; |
197 | |
198 | width = ctk_print_context_get_width (context); |
199 | height = ctk_print_context_get_height (context); |
200 | |
201 | print_data->layout = ctk_print_context_create_pango_layout (context); |
202 | |
203 | desc = pango_font_description_from_string (print_data->font); |
204 | pango_layout_set_font_description (print_data->layout, desc); |
205 | pango_font_description_free (desc); |
206 | |
207 | pango_layout_set_width (print_data->layout, width * PANGO_SCALE1024); |
208 | |
209 | pango_layout_set_text (print_data->layout, print_data->text, -1); |
210 | |
211 | num_lines = pango_layout_get_line_count (print_data->layout); |
212 | |
213 | page_breaks = NULL((void*)0); |
214 | page_height = 0; |
215 | |
216 | for (line = 0; line < num_lines; line++) |
217 | { |
218 | PangoLayoutLine *layout_line; |
219 | PangoRectangle ink_rect, logical_rect; |
220 | double line_height; |
221 | |
222 | layout_line = pango_layout_get_line (print_data->layout, line); |
223 | pango_layout_line_get_extents (layout_line, &ink_rect, &logical_rect); |
224 | |
225 | line_height = logical_rect.height / 1024.0; |
226 | |
227 | if (page_height + line_height > height) |
228 | { |
229 | page_breaks = g_list_prepend (page_breaks, GINT_TO_POINTER (line)((gpointer) (glong) (line))); |
230 | page_height = 0; |
231 | } |
232 | |
233 | page_height += line_height; |
234 | } |
235 | |
236 | page_breaks = g_list_reverse (page_breaks); |
237 | ctk_print_operation_set_n_pages (operation, g_list_length (page_breaks) + 1); |
238 | |
239 | print_data->page_breaks = page_breaks; |
240 | } |
241 | |
242 | static void |
243 | draw_page (CtkPrintOperation *operation G_GNUC_UNUSED__attribute__ ((__unused__)), |
244 | CtkPrintContext *context, |
245 | int page_nr, |
246 | PrintData *print_data) |
247 | { |
248 | cairo_t *cr; |
249 | GList *pagebreak; |
250 | int start, end, i; |
251 | PangoLayoutIter *iter; |
252 | double start_pos; |
253 | |
254 | if (page_nr == 0) |
255 | start = 0; |
256 | else |
257 | { |
258 | pagebreak = g_list_nth (print_data->page_breaks, page_nr - 1); |
259 | start = GPOINTER_TO_INT (pagebreak->data)((gint) (glong) (pagebreak->data)); |
260 | } |
261 | |
262 | pagebreak = g_list_nth (print_data->page_breaks, page_nr); |
263 | if (pagebreak == NULL((void*)0)) |
264 | end = pango_layout_get_line_count (print_data->layout); |
265 | else |
266 | end = GPOINTER_TO_INT (pagebreak->data)((gint) (glong) (pagebreak->data)); |
267 | |
268 | cr = ctk_print_context_get_cairo_context (context); |
269 | |
270 | cairo_set_source_rgb (cr, 0, 0, 0); |
271 | |
272 | i = 0; |
273 | start_pos = 0; |
274 | iter = pango_layout_get_iter (print_data->layout); |
275 | do |
276 | { |
277 | PangoRectangle logical_rect; |
278 | |
279 | if (i >= start) |
280 | { |
281 | PangoLayoutLine *line; |
282 | int baseline; |
283 | |
284 | line = pango_layout_iter_get_line (iter); |
285 | |
286 | pango_layout_iter_get_line_extents (iter, NULL((void*)0), &logical_rect); |
287 | baseline = pango_layout_iter_get_baseline (iter); |
288 | |
289 | if (i == start) |
290 | start_pos = logical_rect.y / 1024.0; |
291 | |
292 | cairo_move_to (cr, logical_rect.x / 1024.0, baseline / 1024.0 - start_pos); |
293 | |
294 | pango_cairo_show_layout_line (cr, line); |
295 | } |
296 | i++; |
297 | } |
298 | while (i < end && |
299 | pango_layout_iter_next_line (iter)); |
300 | |
301 | pango_layout_iter_free (iter); |
302 | } |
303 | |
304 | static void |
305 | status_changed_cb (CtkPrintOperation *op, |
306 | gpointer user_data G_GNUC_UNUSED__attribute__ ((__unused__))) |
307 | { |
308 | if (ctk_print_operation_is_finished (op)) |
309 | { |
310 | active_prints = g_list_remove (active_prints, op); |
311 | g_object_unref (op); |
312 | } |
313 | update_statusbar (); |
314 | } |
315 | |
316 | static CtkWidget * |
317 | create_custom_widget (CtkPrintOperation *operation, |
318 | PrintData *data) |
319 | { |
320 | CtkWidget *vbox, *hbox, *font, *label; |
321 | |
322 | ctk_print_operation_set_custom_tab_label (operation, "Other"); |
323 | vbox = ctk_box_new (CTK_ORIENTATION_VERTICAL, 0); |
324 | ctk_container_set_border_width (CTK_CONTAINER (vbox)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((vbox)), ((ctk_container_get_type ())))))), 12); |
325 | |
326 | hbox = ctk_box_new (CTK_ORIENTATION_HORIZONTAL, 8); |
327 | ctk_box_pack_start (CTK_BOX (vbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((vbox)), ((ctk_box_get_type ())))))), hbox, FALSE(0), FALSE(0), 0); |
328 | ctk_widget_show (hbox); |
329 | |
330 | label = ctk_label_new ("Font:"); |
331 | ctk_box_pack_start (CTK_BOX (hbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((hbox)), ((ctk_box_get_type ())))))), label, FALSE(0), FALSE(0), 0); |
332 | ctk_widget_show (label); |
333 | |
334 | font = ctk_font_button_new_with_font (data->font); |
335 | ctk_box_pack_start (CTK_BOX (hbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((hbox)), ((ctk_box_get_type ())))))), font, FALSE(0), FALSE(0), 0); |
336 | ctk_widget_show (font); |
337 | data->font_button = font; |
338 | |
339 | return vbox; |
340 | } |
341 | |
342 | static void |
343 | custom_widget_apply (CtkPrintOperation *operation G_GNUC_UNUSED__attribute__ ((__unused__)), |
344 | CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)), |
345 | PrintData *data) |
346 | { |
347 | const char *selected_font; |
348 | selected_font = ctk_font_chooser_get_font (CTK_FONT_CHOOSER (data->font_button)((((CtkFontChooser*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((data->font_button)), ((ctk_font_chooser_get_type ())) ))))); |
349 | |
350 | g_free (data->font); |
351 | data->font = g_strdup (selected_font)g_strdup_inline (selected_font); |
352 | } |
353 | |
354 | typedef struct |
355 | { |
356 | CtkPrintOperation *op; |
357 | CtkPrintOperationPreview *preview; |
358 | CtkPrintContext *context; |
359 | CtkWidget *spin; |
360 | CtkWidget *area; |
361 | gint page; |
362 | PrintData *data; |
363 | gdouble dpi_x, dpi_y; |
364 | } PreviewOp; |
365 | |
366 | static gboolean |
367 | preview_draw (CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)), |
368 | cairo_t *cr, |
369 | gpointer data) |
370 | { |
371 | PreviewOp *pop = data; |
372 | cairo_t *prev_cr; |
373 | double dpi_x, dpi_y; |
374 | |
375 | prev_cr = ctk_print_context_get_cairo_context (pop->context); |
376 | cairo_reference (prev_cr); |
377 | dpi_x = ctk_print_context_get_dpi_x (pop->context); |
378 | dpi_y = ctk_print_context_get_dpi_y (pop->context); |
379 | |
380 | ctk_print_context_set_cairo_context (pop->context, |
381 | cr, dpi_x, dpi_y); |
382 | ctk_print_operation_preview_render_page (pop->preview, |
383 | pop->page - 1); |
384 | ctk_print_context_set_cairo_context (pop->context, |
385 | prev_cr, dpi_x, dpi_y); |
386 | cairo_destroy (prev_cr); |
387 | |
388 | return TRUE(!(0)); |
389 | } |
390 | |
391 | static void |
392 | preview_ready (CtkPrintOperationPreview *preview G_GNUC_UNUSED__attribute__ ((__unused__)), |
393 | CtkPrintContext *context G_GNUC_UNUSED__attribute__ ((__unused__)), |
394 | gpointer data) |
395 | { |
396 | PreviewOp *pop = data; |
397 | gint n_pages; |
398 | |
399 | g_object_get (pop->op, "n-pages", &n_pages, NULL((void*)0)); |
400 | |
401 | ctk_spin_button_set_range (CTK_SPIN_BUTTON (pop->spin)((((CtkSpinButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((pop->spin)), ((ctk_spin_button_get_type ())))))), |
402 | 1.0, n_pages); |
403 | |
404 | g_signal_connect (pop->area, "draw",g_signal_connect_data ((pop->area), ("draw"), (((GCallback ) (preview_draw))), (pop), ((void*)0), (GConnectFlags) 0) |
405 | G_CALLBACK (preview_draw),g_signal_connect_data ((pop->area), ("draw"), (((GCallback ) (preview_draw))), (pop), ((void*)0), (GConnectFlags) 0) |
406 | pop)g_signal_connect_data ((pop->area), ("draw"), (((GCallback ) (preview_draw))), (pop), ((void*)0), (GConnectFlags) 0); |
407 | |
408 | ctk_widget_queue_draw (pop->area); |
409 | } |
410 | |
411 | static void |
412 | preview_got_page_size (CtkPrintOperationPreview *preview G_GNUC_UNUSED__attribute__ ((__unused__)), |
413 | CtkPrintContext *context, |
414 | CtkPageSetup *page_setup, |
415 | gpointer data) |
416 | { |
417 | PreviewOp *pop = data; |
418 | CtkAllocation allocation; |
419 | CtkPaperSize *paper_size; |
420 | double w, h; |
421 | cairo_t *cr; |
422 | gdouble dpi_x, dpi_y; |
423 | |
424 | paper_size = ctk_page_setup_get_paper_size (page_setup); |
425 | |
426 | w = ctk_paper_size_get_width (paper_size, CTK_UNIT_INCH); |
427 | h = ctk_paper_size_get_height (paper_size, CTK_UNIT_INCH); |
428 | |
429 | cr = cdk_cairo_create (ctk_widget_get_window (pop->area)); |
430 | |
431 | ctk_widget_get_allocation (pop->area, &allocation); |
432 | dpi_x = allocation.width/w; |
433 | dpi_y = allocation.height/h; |
434 | |
435 | if (fabs (dpi_x - pop->dpi_x) > 0.001 || |
436 | fabs (dpi_y - pop->dpi_y) > 0.001) |
437 | { |
438 | ctk_print_context_set_cairo_context (context, cr, dpi_x, dpi_y); |
439 | pop->dpi_x = dpi_x; |
440 | pop->dpi_y = dpi_y; |
441 | } |
442 | |
443 | pango_cairo_update_layout (cr, pop->data->layout); |
444 | cairo_destroy (cr); |
445 | } |
446 | |
447 | static void |
448 | update_page (CtkSpinButton *widget, |
449 | gpointer data) |
450 | { |
451 | PreviewOp *pop = data; |
452 | |
453 | pop->page = ctk_spin_button_get_value_as_int (widget); |
454 | ctk_widget_queue_draw (pop->area); |
455 | } |
456 | |
457 | static void |
458 | preview_destroy (CtkWindow *window G_GNUC_UNUSED__attribute__ ((__unused__)), |
459 | PreviewOp *pop) |
460 | { |
461 | ctk_print_operation_preview_end_preview (pop->preview); |
462 | g_object_unref (pop->op); |
463 | |
464 | g_free (pop); |
465 | } |
466 | |
467 | static gboolean |
468 | preview_cb (CtkPrintOperation *op, |
469 | CtkPrintOperationPreview *preview, |
470 | CtkPrintContext *context, |
471 | CtkWindow *parent G_GNUC_UNUSED__attribute__ ((__unused__)), |
472 | gpointer data) |
473 | { |
474 | CtkWidget *window, *close, *page, *hbox, *vbox, *da; |
475 | gdouble width, height; |
476 | cairo_t *cr; |
477 | PreviewOp *pop; |
478 | PrintData *print_data = data; |
479 | |
480 | pop = g_new0 (PreviewOp, 1)((PreviewOp *) g_malloc0_n ((1), sizeof (PreviewOp))); |
481 | |
482 | pop->data = print_data; |
483 | |
484 | width = 200; |
485 | height = 300; |
486 | window = ctk_window_new (CTK_WINDOW_TOPLEVEL); |
487 | ctk_window_set_transient_for (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((window)), ((ctk_window_get_type ())))))), |
488 | CTK_WINDOW (main_window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((main_window)), ((ctk_window_get_type ()))))))); |
489 | vbox = ctk_box_new (CTK_ORIENTATION_VERTICAL, 0); |
490 | ctk_container_add (CTK_CONTAINER (window)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((window)), ((ctk_container_get_type ())))))), vbox); |
491 | hbox = ctk_box_new (CTK_ORIENTATION_HORIZONTAL, 0); |
492 | ctk_box_pack_start (CTK_BOX (vbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((vbox)), ((ctk_box_get_type ())))))), hbox, |
493 | FALSE(0), FALSE(0), 0); |
494 | page = ctk_spin_button_new_with_range (1, 100, 1); |
495 | ctk_box_pack_start (CTK_BOX (hbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((hbox)), ((ctk_box_get_type ())))))), page, FALSE(0), FALSE(0), 0); |
496 | |
497 | close = ctk_button_new_with_label ("Close"); |
498 | ctk_box_pack_start (CTK_BOX (hbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((hbox)), ((ctk_box_get_type ())))))), close, FALSE(0), FALSE(0), 0); |
499 | |
500 | da = ctk_drawing_area_new (); |
501 | ctk_widget_set_size_request (CTK_WIDGET (da)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((da)), ((ctk_widget_get_type ())))))), width, height); |
502 | ctk_box_pack_start (CTK_BOX (vbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((vbox)), ((ctk_box_get_type ())))))), da, TRUE(!(0)), TRUE(!(0)), 0); |
503 | |
504 | ctk_widget_realize (da); |
505 | |
506 | cr = cdk_cairo_create (ctk_widget_get_window (da)); |
507 | |
508 | /* TODO: What dpi to use here? This will be used for pagination.. */ |
509 | ctk_print_context_set_cairo_context (context, cr, 72, 72); |
510 | cairo_destroy (cr); |
511 | |
512 | pop->op = g_object_ref (op)((__typeof__ (op)) (g_object_ref) (op)); |
513 | pop->preview = preview; |
514 | pop->context = context; |
515 | pop->spin = page; |
516 | pop->area = da; |
517 | pop->page = 1; |
518 | |
519 | g_signal_connect (page, "value-changed",g_signal_connect_data ((page), ("value-changed"), (((GCallback ) (update_page))), (pop), ((void*)0), (GConnectFlags) 0) |
520 | G_CALLBACK (update_page), pop)g_signal_connect_data ((page), ("value-changed"), (((GCallback ) (update_page))), (pop), ((void*)0), (GConnectFlags) 0); |
521 | g_signal_connect_swapped (close, "clicked",g_signal_connect_data ((close), ("clicked"), (((GCallback) (ctk_widget_destroy ))), (window), ((void*)0), G_CONNECT_SWAPPED) |
522 | G_CALLBACK (ctk_widget_destroy), window)g_signal_connect_data ((close), ("clicked"), (((GCallback) (ctk_widget_destroy ))), (window), ((void*)0), G_CONNECT_SWAPPED); |
523 | |
524 | g_signal_connect (preview, "ready",g_signal_connect_data ((preview), ("ready"), (((GCallback) (preview_ready ))), (pop), ((void*)0), (GConnectFlags) 0) |
525 | G_CALLBACK (preview_ready), pop)g_signal_connect_data ((preview), ("ready"), (((GCallback) (preview_ready ))), (pop), ((void*)0), (GConnectFlags) 0); |
526 | g_signal_connect (preview, "got-page-size",g_signal_connect_data ((preview), ("got-page-size"), (((GCallback ) (preview_got_page_size))), (pop), ((void*)0), (GConnectFlags ) 0) |
527 | G_CALLBACK (preview_got_page_size), pop)g_signal_connect_data ((preview), ("got-page-size"), (((GCallback ) (preview_got_page_size))), (pop), ((void*)0), (GConnectFlags ) 0); |
528 | |
529 | g_signal_connect (window, "destroy",g_signal_connect_data ((window), ("destroy"), (((GCallback) ( preview_destroy))), (pop), ((void*)0), (GConnectFlags) 0) |
530 | G_CALLBACK (preview_destroy), pop)g_signal_connect_data ((window), ("destroy"), (((GCallback) ( preview_destroy))), (pop), ((void*)0), (GConnectFlags) 0); |
531 | |
532 | ctk_widget_show_all (window); |
533 | |
534 | return TRUE(!(0)); |
535 | } |
536 | |
537 | static void |
538 | print_done (CtkPrintOperation *op, |
539 | CtkPrintOperationResult res, |
540 | PrintData *print_data) |
541 | { |
542 | GError *error = NULL((void*)0); |
543 | |
544 | if (res == CTK_PRINT_OPERATION_RESULT_ERROR) |
545 | { |
546 | |
547 | CtkWidget *error_dialog; |
548 | |
549 | ctk_print_operation_get_error (op, &error); |
550 | |
551 | error_dialog = ctk_message_dialog_new (CTK_WINDOW (main_window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((main_window)), ((ctk_window_get_type ())))))), |
552 | CTK_DIALOG_DESTROY_WITH_PARENT, |
553 | CTK_MESSAGE_ERROR, |
554 | CTK_BUTTONS_CLOSE, |
555 | "Error printing file:\n%s", |
556 | error ? error->message : "no details"); |
557 | g_signal_connect (error_dialog, "response", G_CALLBACK (ctk_widget_destroy), NULL)g_signal_connect_data ((error_dialog), ("response"), (((GCallback ) (ctk_widget_destroy))), (((void*)0)), ((void*)0), (GConnectFlags ) 0); |
558 | ctk_widget_show (error_dialog); |
559 | } |
560 | else if (res == CTK_PRINT_OPERATION_RESULT_APPLY) |
561 | { |
562 | if (settings != NULL((void*)0)) |
563 | g_object_unref (settings); |
564 | settings = g_object_ref (ctk_print_operation_get_print_settings (op))((__typeof__ (ctk_print_operation_get_print_settings (op))) ( g_object_ref) (ctk_print_operation_get_print_settings (op))); |
565 | } |
566 | |
567 | g_free (print_data->text); |
568 | g_free (print_data->font); |
569 | g_free (print_data); |
570 | |
571 | if (!ctk_print_operation_is_finished (op)) |
572 | { |
573 | g_object_ref (op)((__typeof__ (op)) (g_object_ref) (op)); |
574 | active_prints = g_list_append (active_prints, op); |
575 | update_statusbar (); |
576 | |
577 | /* This ref is unref:ed when we get the final state change */ |
578 | g_signal_connect (op, "status_changed",g_signal_connect_data ((op), ("status_changed"), (((GCallback ) (status_changed_cb))), (((void*)0)), ((void*)0), (GConnectFlags ) 0) |
579 | G_CALLBACK (status_changed_cb), NULL)g_signal_connect_data ((op), ("status_changed"), (((GCallback ) (status_changed_cb))), (((void*)0)), ((void*)0), (GConnectFlags ) 0); |
580 | } |
581 | } |
582 | |
583 | static void |
584 | end_print (CtkPrintOperation *op G_GNUC_UNUSED__attribute__ ((__unused__)), |
585 | CtkPrintContext *context G_GNUC_UNUSED__attribute__ ((__unused__)), |
586 | PrintData *print_data) |
587 | { |
588 | g_list_free (print_data->page_breaks); |
589 | print_data->page_breaks = NULL((void*)0); |
590 | g_object_unref (print_data->layout); |
591 | print_data->layout = NULL((void*)0); |
592 | } |
593 | |
594 | static void |
595 | print_or_preview (GSimpleAction *action G_GNUC_UNUSED__attribute__ ((__unused__)), |
596 | CtkPrintOperationAction print_action) |
597 | { |
598 | CtkPrintOperation *print; |
599 | PrintData *print_data; |
600 | |
601 | print_data = g_new0 (PrintData, 1)((PrintData *) g_malloc0_n ((1), sizeof (PrintData))); |
602 | |
603 | print_data->text = get_text (); |
604 | print_data->font = g_strdup ("Sans 12")g_strdup_inline ("Sans 12"); |
605 | |
606 | print = ctk_print_operation_new (); |
607 | |
608 | ctk_print_operation_set_track_print_status (print, TRUE(!(0))); |
609 | |
610 | if (settings != NULL((void*)0)) |
611 | ctk_print_operation_set_print_settings (print, settings); |
612 | |
613 | if (page_setup != NULL((void*)0)) |
614 | ctk_print_operation_set_default_page_setup (print, page_setup); |
615 | |
616 | g_signal_connect (print, "begin_print", G_CALLBACK (begin_print), print_data)g_signal_connect_data ((print), ("begin_print"), (((GCallback ) (begin_print))), (print_data), ((void*)0), (GConnectFlags) 0 ); |
617 | g_signal_connect (print, "end-print", G_CALLBACK (end_print), print_data)g_signal_connect_data ((print), ("end-print"), (((GCallback) ( end_print))), (print_data), ((void*)0), (GConnectFlags) 0); |
618 | g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), print_data)g_signal_connect_data ((print), ("draw_page"), (((GCallback) ( draw_page))), (print_data), ((void*)0), (GConnectFlags) 0); |
619 | g_signal_connect (print, "create_custom_widget", G_CALLBACK (create_custom_widget), print_data)g_signal_connect_data ((print), ("create_custom_widget"), ((( GCallback) (create_custom_widget))), (print_data), ((void*)0) , (GConnectFlags) 0); |
620 | g_signal_connect (print, "custom_widget_apply", G_CALLBACK (custom_widget_apply), print_data)g_signal_connect_data ((print), ("custom_widget_apply"), (((GCallback ) (custom_widget_apply))), (print_data), ((void*)0), (GConnectFlags ) 0); |
621 | g_signal_connect (print, "preview", G_CALLBACK (preview_cb), print_data)g_signal_connect_data ((print), ("preview"), (((GCallback) (preview_cb ))), (print_data), ((void*)0), (GConnectFlags) 0); |
622 | |
623 | g_signal_connect (print, "done", G_CALLBACK (print_done), print_data)g_signal_connect_data ((print), ("done"), (((GCallback) (print_done ))), (print_data), ((void*)0), (GConnectFlags) 0); |
624 | |
625 | ctk_print_operation_set_export_filename (print, "test.pdf"); |
626 | |
627 | #if 0 |
628 | ctk_print_operation_set_allow_async (print, TRUE(!(0))); |
629 | #endif |
630 | ctk_print_operation_run (print, print_action, CTK_WINDOW (main_window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((main_window)), ((ctk_window_get_type ())))))), NULL((void*)0)); |
631 | |
632 | g_object_unref (print); |
633 | } |
634 | |
635 | static void |
636 | activate_page_setup (GSimpleAction *action G_GNUC_UNUSED__attribute__ ((__unused__)), |
637 | GVariant *parameter G_GNUC_UNUSED__attribute__ ((__unused__)), |
638 | gpointer user_data G_GNUC_UNUSED__attribute__ ((__unused__))) |
639 | { |
640 | CtkPageSetup *new_page_setup; |
641 | |
642 | new_page_setup = ctk_print_run_page_setup_dialog (CTK_WINDOW (main_window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((main_window)), ((ctk_window_get_type ())))))), |
643 | page_setup, settings); |
644 | |
645 | if (page_setup) |
646 | g_object_unref (page_setup); |
647 | |
648 | page_setup = new_page_setup; |
649 | } |
650 | |
651 | static void |
652 | activate_print (GSimpleAction *action, |
653 | GVariant *parameter G_GNUC_UNUSED__attribute__ ((__unused__)), |
654 | gpointer user_data G_GNUC_UNUSED__attribute__ ((__unused__))) |
655 | { |
656 | print_or_preview (action, CTK_PRINT_OPERATION_ACTION_PRINT_DIALOG); |
657 | } |
658 | |
659 | static void |
660 | activate_preview (GSimpleAction *action, |
661 | GVariant *parameter G_GNUC_UNUSED__attribute__ ((__unused__)), |
662 | gpointer user_data G_GNUC_UNUSED__attribute__ ((__unused__))) |
663 | { |
664 | print_or_preview (action, CTK_PRINT_OPERATION_ACTION_PREVIEW); |
665 | } |
666 | |
667 | static void |
668 | activate_save_as (GSimpleAction *action G_GNUC_UNUSED__attribute__ ((__unused__)), |
669 | GVariant *parameter G_GNUC_UNUSED__attribute__ ((__unused__)), |
670 | gpointer user_data G_GNUC_UNUSED__attribute__ ((__unused__))) |
671 | { |
672 | CtkWidget *dialog; |
673 | gint response; |
674 | |
675 | dialog = ctk_file_chooser_dialog_new ("Select file", |
676 | CTK_WINDOW (main_window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((main_window)), ((ctk_window_get_type ())))))), |
677 | CTK_FILE_CHOOSER_ACTION_SAVE, |
678 | "_Cancel", CTK_RESPONSE_CANCEL, |
679 | "_Save", CTK_RESPONSE_OK, |
680 | NULL((void*)0)); |
681 | ctk_dialog_set_default_response (CTK_DIALOG (dialog)((((CtkDialog*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog)), ((ctk_dialog_get_type ())))))), CTK_RESPONSE_OK); |
682 | response = ctk_dialog_run (CTK_DIALOG (dialog)((((CtkDialog*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog)), ((ctk_dialog_get_type ()))))))); |
683 | |
684 | if (response == CTK_RESPONSE_OK) |
685 | { |
686 | char *save_filename; |
687 | |
688 | save_filename = ctk_file_chooser_get_filename (CTK_FILE_CHOOSER (dialog)((((CtkFileChooser*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog)), ((ctk_file_chooser_get_type ()))))))); |
689 | save_file (save_filename); |
690 | g_free (save_filename); |
691 | } |
692 | |
693 | ctk_widget_destroy (dialog); |
694 | } |
695 | |
696 | static void |
697 | activate_save (GSimpleAction *action, |
698 | GVariant *parameter G_GNUC_UNUSED__attribute__ ((__unused__)), |
699 | gpointer user_data G_GNUC_UNUSED__attribute__ ((__unused__))) |
700 | { |
701 | if (filename == NULL((void*)0)) |
702 | activate_save_as (action, NULL((void*)0), NULL((void*)0)); |
703 | else |
704 | save_file (filename); |
705 | } |
706 | |
707 | static void |
708 | activate_open (GSimpleAction *action G_GNUC_UNUSED__attribute__ ((__unused__)), |
709 | GVariant *parameter G_GNUC_UNUSED__attribute__ ((__unused__)), |
710 | gpointer user_data G_GNUC_UNUSED__attribute__ ((__unused__))) |
711 | { |
712 | CtkWidget *dialog; |
713 | gint response; |
714 | |
715 | dialog = ctk_file_chooser_dialog_new ("Select file", |
716 | CTK_WINDOW (main_window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((main_window)), ((ctk_window_get_type ())))))), |
717 | CTK_FILE_CHOOSER_ACTION_OPEN, |
718 | "_Cancel", CTK_RESPONSE_CANCEL, |
719 | "_Open", CTK_RESPONSE_OK, |
720 | NULL((void*)0)); |
721 | ctk_dialog_set_default_response (CTK_DIALOG (dialog)((((CtkDialog*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog)), ((ctk_dialog_get_type ())))))), CTK_RESPONSE_OK); |
722 | response = ctk_dialog_run (CTK_DIALOG (dialog)((((CtkDialog*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog)), ((ctk_dialog_get_type ()))))))); |
723 | |
724 | if (response == CTK_RESPONSE_OK) |
725 | { |
726 | char *open_filename; |
727 | |
728 | open_filename = ctk_file_chooser_get_filename (CTK_FILE_CHOOSER (dialog)((((CtkFileChooser*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog)), ((ctk_file_chooser_get_type ()))))))); |
729 | load_file (open_filename); |
730 | g_free (open_filename); |
731 | } |
732 | |
733 | ctk_widget_destroy (dialog); |
734 | } |
735 | |
736 | static void |
737 | activate_new (GSimpleAction *action G_GNUC_UNUSED__attribute__ ((__unused__)), |
738 | GVariant *parameter G_GNUC_UNUSED__attribute__ ((__unused__)), |
739 | gpointer user_data G_GNUC_UNUSED__attribute__ ((__unused__))) |
740 | { |
741 | g_free (filename); |
742 | filename = NULL((void*)0); |
743 | set_text ("", 0); |
744 | } |
745 | |
746 | static void |
747 | activate_about (GSimpleAction *action G_GNUC_UNUSED__attribute__ ((__unused__)), |
748 | GVariant *parameter G_GNUC_UNUSED__attribute__ ((__unused__)), |
749 | gpointer user_data G_GNUC_UNUSED__attribute__ ((__unused__))) |
750 | { |
751 | const gchar *authors[] = { |
752 | "Alexander Larsson", |
753 | NULL((void*)0) |
754 | }; |
755 | ctk_show_about_dialog (CTK_WINDOW (main_window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((main_window)), ((ctk_window_get_type ())))))), |
756 | "name", "Print Test Editor", |
757 | "logo-icon-name", "text-editor", |
758 | "version", "0.1", |
759 | "copyright", "(C) Red Hat, Inc", |
760 | "comments", "Program to demonstrate CTK+ printing.", |
761 | "authors", authors, |
762 | NULL((void*)0)); |
763 | } |
764 | |
765 | static void |
766 | activate_quit (GSimpleAction *action G_GNUC_UNUSED__attribute__ ((__unused__)), |
767 | GVariant *parameter G_GNUC_UNUSED__attribute__ ((__unused__)), |
768 | gpointer user_data) |
769 | { |
770 | CtkApplication *app = user_data; |
771 | GList *list, *next; |
772 | |
773 | list = ctk_application_get_windows (app); |
774 | while (list) |
775 | { |
776 | CtkWidget *win; |
777 | |
778 | win = list->data; |
779 | next = list->next; |
780 | |
781 | ctk_widget_destroy (CTK_WIDGET (win)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((win)), ((ctk_widget_get_type ()))))))); |
782 | |
783 | list = next; |
784 | } |
785 | } |
786 | |
787 | static GActionEntry app_entries[] = { |
788 | { .name = "new", .activate = activate_new }, |
789 | { .name = "open", .activate = activate_open }, |
790 | { .name = "save", .activate = activate_save }, |
791 | { .name = "save-as", .activate = activate_save_as }, |
792 | { .name = "quit", .activate = activate_quit }, |
793 | { .name = "about", .activate = activate_about }, |
794 | { .name = "page-setup", .activate = activate_page_setup }, |
795 | { .name = "preview", .activate = activate_preview }, |
796 | { .name = "print", .activate = activate_print } |
797 | }; |
798 | |
799 | static const gchar ui_info[] = |
800 | "<interface>" |
801 | " <menu id='appmenu'>" |
802 | " <section>" |
803 | " <item>" |
804 | " <attribute name='label'>_About</attribute>" |
805 | " <attribute name='action'>app.about</attribute>" |
806 | " <attribute name='accel'><Primary>a</attribute>" |
807 | " </item>" |
808 | " </section>" |
809 | " <section>" |
810 | " <item>" |
811 | " <attribute name='label'>_Quit</attribute>" |
812 | " <attribute name='action'>app.quit</attribute>" |
813 | " <attribute name='accel'><Primary>q</attribute>" |
814 | " </item>" |
815 | " </section>" |
816 | " </menu>" |
817 | " <menu id='menubar'>" |
818 | " <submenu>" |
819 | " <attribute name='label'>_File</attribute>" |
820 | " <section>" |
821 | " <item>" |
822 | " <attribute name='label'>_New</attribute>" |
823 | " <attribute name='action'>app.new</attribute>" |
824 | " <attribute name='accel'><Primary>n</attribute>" |
825 | " </item>" |
826 | " <item>" |
827 | " <attribute name='label'>_Open</attribute>" |
828 | " <attribute name='action'>app.open</attribute>" |
829 | " </item>" |
830 | " <item>" |
831 | " <attribute name='label'>_Save</attribute>" |
832 | " <attribute name='action'>app.save</attribute>" |
833 | " <attribute name='accel'><Primary>s</attribute>" |
834 | " </item>" |
835 | " <item>" |
836 | " <attribute name='label'>Save _As...</attribute>" |
837 | " <attribute name='action'>app.save-as</attribute>" |
838 | " <attribute name='accel'><Primary>s</attribute>" |
839 | " </item>" |
840 | " </section>" |
841 | " <section>" |
842 | " <item>" |
843 | " <attribute name='label'>Page Setup</attribute>" |
844 | " <attribute name='action'>app.page-setup</attribute>" |
845 | " </item>" |
846 | " <item>" |
847 | " <attribute name='label'>Preview</attribute>" |
848 | " <attribute name='action'>app.preview</attribute>" |
849 | " </item>" |
850 | " <item>" |
851 | " <attribute name='label'>Print</attribute>" |
852 | " <attribute name='action'>app.print</attribute>" |
853 | " </item>" |
854 | " </section>" |
855 | " </submenu>" |
856 | " </menu>" |
857 | "</interface>"; |
858 | |
859 | static void |
860 | buffer_changed_callback (CtkTextBuffer *buffer G_GNUC_UNUSED__attribute__ ((__unused__))) |
861 | { |
862 | file_changed = TRUE(!(0)); |
863 | update_statusbar (); |
864 | } |
865 | |
866 | static void |
867 | mark_set_callback (CtkTextBuffer *buffer G_GNUC_UNUSED__attribute__ ((__unused__)), |
868 | const CtkTextIter *new_location G_GNUC_UNUSED__attribute__ ((__unused__)), |
869 | CtkTextMark *mark G_GNUC_UNUSED__attribute__ ((__unused__)), |
870 | gpointer data G_GNUC_UNUSED__attribute__ ((__unused__))) |
871 | { |
872 | update_statusbar (); |
873 | } |
874 | |
875 | static gint |
876 | command_line (GApplication *application G_GNUC_UNUSED__attribute__ ((__unused__)), |
877 | GApplicationCommandLine *command_line) |
878 | { |
879 | int argc; |
880 | char **argv; |
881 | |
882 | argv = g_application_command_line_get_arguments (command_line, &argc); |
883 | |
884 | if (argc == 2) |
885 | load_file (argv[1]); |
886 | |
887 | return 0; |
888 | } |
889 | |
890 | static void |
891 | startup (GApplication *app) |
892 | { |
893 | CtkBuilder *builder; |
894 | GMenuModel *appmenu; |
895 | GMenuModel *menubar; |
896 | |
897 | builder = ctk_builder_new (); |
898 | ctk_builder_add_from_string (builder, ui_info, -1, NULL((void*)0)); |
899 | |
900 | appmenu = (GMenuModel *)ctk_builder_get_object (builder, "appmenu"); |
901 | menubar = (GMenuModel *)ctk_builder_get_object (builder, "menubar"); |
902 | |
903 | ctk_application_set_app_menu (CTK_APPLICATION (app)((((CtkApplication*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((app)), ((ctk_application_get_type ())))))), appmenu); |
904 | ctk_application_set_menubar (CTK_APPLICATION (app)((((CtkApplication*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((app)), ((ctk_application_get_type ())))))), menubar); |
905 | |
906 | g_object_unref (builder); |
907 | } |
908 | |
909 | static void |
910 | activate (GApplication *app) |
911 | { |
912 | CtkWidget *box; |
913 | CtkWidget *bar; |
914 | CtkWidget *sw; |
915 | CtkWidget *contents; |
916 | |
917 | main_window = ctk_application_window_new (CTK_APPLICATION (app)((((CtkApplication*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((app)), ((ctk_application_get_type ()))))))); |
918 | ctk_window_set_icon_name (CTK_WINDOW (main_window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((main_window)), ((ctk_window_get_type ())))))), "text-editor"); |
919 | ctk_window_set_default_size (CTK_WINDOW (main_window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((main_window)), ((ctk_window_get_type ())))))), 400, 600); |
920 | update_title (CTK_WINDOW (main_window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((main_window)), ((ctk_window_get_type ()))))))); |
921 | |
922 | box = ctk_box_new (CTK_ORIENTATION_VERTICAL, 0); |
923 | ctk_container_add (CTK_CONTAINER (main_window)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((main_window)), ((ctk_container_get_type ())))))), box); |
924 | |
925 | bar = ctk_menu_bar_new (); |
926 | ctk_widget_show (bar); |
927 | ctk_container_add (CTK_CONTAINER (box)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((box)), ((ctk_container_get_type ())))))), bar); |
928 | |
929 | /* Create document */ |
930 | sw = ctk_scrolled_window_new (NULL((void*)0), NULL((void*)0)); |
931 | |
932 | ctk_scrolled_window_set_policy (CTK_SCROLLED_WINDOW (sw)((((CtkScrolledWindow*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((sw)), ((ctk_scrolled_window_get_type ()))) ))), |
933 | CTK_POLICY_AUTOMATIC, |
934 | CTK_POLICY_AUTOMATIC); |
935 | |
936 | ctk_scrolled_window_set_shadow_type (CTK_SCROLLED_WINDOW (sw)((((CtkScrolledWindow*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((sw)), ((ctk_scrolled_window_get_type ()))) ))), |
937 | CTK_SHADOW_IN); |
938 | |
939 | ctk_widget_set_vexpand (sw, TRUE(!(0))); |
940 | ctk_container_add (CTK_CONTAINER (box)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((box)), ((ctk_container_get_type ())))))), sw); |
941 | |
942 | contents = ctk_text_view_new (); |
943 | ctk_widget_grab_focus (contents); |
944 | |
945 | ctk_container_add (CTK_CONTAINER (sw)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sw)), ((ctk_container_get_type ())))))), |
946 | contents); |
947 | |
948 | /* Create statusbar */ |
949 | statusbar = ctk_statusbar_new (); |
950 | ctk_container_add (CTK_CONTAINER (box)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((box)), ((ctk_container_get_type ())))))), statusbar); |
951 | |
952 | /* Show text widget info in the statusbar */ |
953 | buffer = ctk_text_view_get_buffer (CTK_TEXT_VIEW (contents)((((CtkTextView*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((contents)), ((ctk_text_view_get_type ()))))))); |
954 | |
955 | g_signal_connect_object (buffer, |
956 | "changed", |
957 | G_CALLBACK (buffer_changed_callback)((GCallback) (buffer_changed_callback)), |
958 | NULL((void*)0), |
959 | 0); |
960 | |
961 | g_signal_connect_object (buffer, |
962 | "mark_set", /* cursor moved */ |
963 | G_CALLBACK (mark_set_callback)((GCallback) (mark_set_callback)), |
964 | NULL((void*)0), |
965 | 0); |
966 | |
967 | update_ui (); |
968 | |
969 | ctk_widget_show_all (main_window); |
970 | } |
971 | |
972 | int |
973 | main (int argc, char **argv) |
974 | { |
975 | CtkApplication *app; |
976 | GError *error = NULL((void*)0); |
977 | |
978 | ctk_init (NULL((void*)0), NULL((void*)0)); |
979 | |
980 | settings = ctk_print_settings_new_from_file ("print-settings.ini", &error); |
981 | if (error) { |
982 | g_print ("Failed to load print settings: %s\n", error->message); |
983 | g_clear_error (&error); |
984 | |
985 | settings = ctk_print_settings_new (); |
986 | } |
987 | g_assert (settings != NULL)do { if (settings != ((void*)0)) ; else g_assertion_message_expr (((gchar*) 0), "print-editor.c", 987, ((const char*) (__func__ )), "settings != NULL"); } while (0); |
988 | |
989 | page_setup = ctk_page_setup_new_from_file ("page-setup.ini", &error); |
990 | if (error) { |
991 | g_print ("Failed to load page setup: %s\n", error->message); |
992 | g_clear_error (&error); |
993 | } |
994 | |
995 | app = ctk_application_new ("org.ctk.PrintEditor", 0); |
996 | |
997 | g_action_map_add_action_entries (G_ACTION_MAP (app)((((GActionMap*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((app)), ((g_action_map_get_type ())))))), |
998 | app_entries, G_N_ELEMENTS (app_entries)(sizeof (app_entries) / sizeof ((app_entries)[0])), |
999 | app); |
1000 | |
1001 | g_signal_connect (app, "startup", G_CALLBACK (startup), NULL)g_signal_connect_data ((app), ("startup"), (((GCallback) (startup ))), (((void*)0)), ((void*)0), (GConnectFlags) 0); |
1002 | g_signal_connect (app, "activate", G_CALLBACK (activate), NULL)g_signal_connect_data ((app), ("activate"), (((GCallback) (activate ))), (((void*)0)), ((void*)0), (GConnectFlags) 0); |
1003 | g_signal_connect (app, "command-line", G_CALLBACK (command_line), NULL)g_signal_connect_data ((app), ("command-line"), (((GCallback) (command_line))), (((void*)0)), ((void*)0), (GConnectFlags) 0 ); |
1004 | |
1005 | g_application_run (G_APPLICATION (app)((((GApplication*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((app)), ((g_application_get_type ())))))), argc, argv); |
1006 | |
1007 | if (!ctk_print_settings_to_file (settings, "print-settings.ini", &error)) { |
1008 | g_print ("Failed to save print settings: %s\n", error->message); |
1009 | g_clear_error (&error); |
1010 | } |
1011 | if (page_setup && |
1012 | !ctk_page_setup_to_file (page_setup, "page-setup.ini", &error)) { |
This statement is never executed | |
1013 | g_print ("Failed to save page setup: %s\n", error->message); |
1014 | g_clear_error (&error); |
1015 | } |
1016 | |
1017 | return 0; |
1018 | } |