1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
|
/*
* mainwindow.c
*
* Colloquium - A tiny presentation program
*
* Copyright (c) 2012 Thomas White <taw@bitwiz.org.uk>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include <assert.h>
#include <gdk/gdkkeysyms.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "presentation.h"
#include "mainwindow.h"
#include "render.h"
#include "frame.h"
#include "slideshow.h"
/* Update a slide, once it's been edited in some way. */
static void rerender_slide(struct presentation *p, PangoContext *pc)
{
int w, h;
struct slide *s = p->cur_edit_slide;
free_render_buffers(s);
w = p->thumb_slide_width;
h = (p->slide_height/p->slide_width) * w;
s->rendered_thumb = render_slide(s, w, h);
w = p->edit_slide_width;
h = (p->slide_height/p->slide_width) * w;
s->rendered_edit = render_slide(s, w, h);
w = s->parent->proj_slide_width;
h = (s->parent->slide_height/s->parent->slide_width) * w;
s->rendered_proj = render_slide(s, w, h);
}
/* Ensure that "edit" and "proj" renderings are in order */
static void render_edit_and_proj(struct presentation *p, PangoContext *pc)
{
int w, h;
struct slide *s = p->cur_edit_slide;
if ( s->rendered_edit == NULL ) {
w = p->edit_slide_width;
h = (p->slide_height/p->slide_width) * w;
s->rendered_edit = render_slide(s, w, h);
}
if ( s->rendered_proj == NULL ) {
w = s->parent->proj_slide_width;
h = (s->parent->slide_height/s->parent->slide_width) * w;
s->rendered_proj = render_slide(s, w, h);
}
}
/* Force a redraw of the editor window */
void redraw_editor(struct presentation *p)
{
gint w, h;
w = gtk_widget_get_allocated_width(GTK_WIDGET(p->drawingarea));
h = gtk_widget_get_allocated_height(GTK_WIDGET(p->drawingarea));
gtk_widget_queue_draw_area(p->drawingarea, 0, 0, w, h);
}
static void add_ui_sig(GtkUIManager *ui, GtkWidget *widget,
GtkContainer *container)
{
gtk_box_pack_start(GTK_BOX(container), widget, FALSE, FALSE, 0);
if ( GTK_IS_TOOLBAR(widget) ) {
gtk_toolbar_set_show_arrow(GTK_TOOLBAR(widget), TRUE);
}
}
static gint quit_sig(GtkWidget *widget, struct presentation *p)
{
return 0;
}
static void show_error(struct presentation *p, const char *message)
{
GtkWidget *window;
window = gtk_message_dialog_new(GTK_WINDOW(p->window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_WARNING,
GTK_BUTTONS_CLOSE, message);
gtk_window_set_title(GTK_WINDOW(window), "Error");
g_signal_connect_swapped(window, "response",
G_CALLBACK(gtk_widget_destroy), window);
gtk_widget_show(window);
}
static void update_toolbar(struct presentation *p)
{
GtkWidget *d;
int cur_slide_number;
d = gtk_ui_manager_get_widget(p->ui, "/ui/displaywindowtoolbar/first");
gtk_widget_set_sensitive(GTK_WIDGET(d), TRUE);
d = gtk_ui_manager_get_widget(p->ui, "/ui/displaywindowtoolbar/prev");
gtk_widget_set_sensitive(GTK_WIDGET(d), TRUE);
d = gtk_ui_manager_get_widget(p->ui, "/ui/displaywindowtoolbar/next");
gtk_widget_set_sensitive(GTK_WIDGET(d), TRUE);
d = gtk_ui_manager_get_widget(p->ui, "/ui/displaywindowtoolbar/last");
gtk_widget_set_sensitive(GTK_WIDGET(d), TRUE);
cur_slide_number = slide_number(p, p->cur_edit_slide);
if ( cur_slide_number == 0 ) {
d = gtk_ui_manager_get_widget(p->ui,
"/ui/displaywindowtoolbar/first");
gtk_widget_set_sensitive(GTK_WIDGET(d), FALSE);
d = gtk_ui_manager_get_widget(p->ui,
"/ui/displaywindowtoolbar/prev");
gtk_widget_set_sensitive(GTK_WIDGET(d), FALSE);
}
if ( cur_slide_number == p->num_slides-1 ) {
d = gtk_ui_manager_get_widget(p->ui,
"/ui/displaywindowtoolbar/next");
gtk_widget_set_sensitive(GTK_WIDGET(d), FALSE);
d = gtk_ui_manager_get_widget(p->ui,
"/ui/displaywindowtoolbar/last");
gtk_widget_set_sensitive(GTK_WIDGET(d), FALSE);
}
}
static gint open_response_sig(GtkWidget *d, gint response,
struct presentation *p)
{
if ( response == GTK_RESPONSE_ACCEPT ) {
char *filename;
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(d));
if ( p->completely_empty ) {
if ( load_presentation(p, filename) ) {
show_error(p, "Failed to open presentation");
}
p->cur_edit_slide = p->slides[0];
rerender_slide(p, p->pc);
update_toolbar(p);
} else {
struct presentation *p;
/* FIXME */
p = new_presentation();
if ( load_presentation(p, filename) ) {
show_error(p, "Failed to open presentation");
} else {
open_mainwindow(p);
}
}
g_free(filename);
}
gtk_widget_destroy(d);
return 0;
}
static gint open_sig(GtkWidget *widget, struct presentation *p)
{
GtkWidget *d;
d = gtk_file_chooser_dialog_new("Open Presentation",
GTK_WINDOW(p->window),
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
g_signal_connect(G_OBJECT(d), "response",
G_CALLBACK(open_response_sig), p);
gtk_widget_show_all(d);
return 0;
}
static gint new_sig(GtkWidget *widget, struct presentation *pnn)
{
struct presentation *p;
p = new_presentation();
if ( p != NULL ) {
p->cur_edit_slide = add_slide(p, 0);
p->completely_empty = 1;
open_mainwindow(p);
}
return 0;
}
static gint saveas_response_sig(GtkWidget *d, gint response,
struct presentation *p)
{
if ( response == GTK_RESPONSE_ACCEPT ) {
char *filename;
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(d));
if ( save_presentation(p, filename) ) {
show_error(p, "Failed to save presentation");
}
g_free(filename);
}
gtk_widget_destroy(d);
return 0;
}
static gint saveas_sig(GtkWidget *widget, struct presentation *p)
{
GtkWidget *d;
d = gtk_file_chooser_dialog_new("Save Presentation",
GTK_WINDOW(p->window),
GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
NULL);
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(d),
TRUE);
g_signal_connect(G_OBJECT(d), "response",
G_CALLBACK(saveas_response_sig), p);
gtk_widget_show_all(d);
return 0;
}
static gint save_sig(GtkWidget *widget, struct presentation *p)
{
if ( p->filename == NULL ) {
return saveas_sig(widget, p);
}
save_presentation(p, p->filename);
return 0;
}
static gint save_ss_response_sig(GtkWidget *d, gint response,
struct presentation *p)
{
if ( response == GTK_RESPONSE_ACCEPT ) {
char *filename;
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(d));
/* FIXME */
//if ( save_stylesheet(p->ss, filename) ) {
// show_error(p, "Failed to save style sheet");
//}
g_free(filename);
}
gtk_widget_destroy(d);
return 0;
}
static gint save_ss_sig(GtkWidget *widget, struct presentation *p)
{
GtkWidget *d;
d = gtk_file_chooser_dialog_new("Save Style sheet",
GTK_WINDOW(p->window),
GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
NULL);
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(d),
TRUE);
g_signal_connect(G_OBJECT(d), "response",
G_CALLBACK(save_ss_response_sig), p);
gtk_widget_show_all(d);
return 0;
}
static gint export_pdf_response_sig(GtkWidget *d, gint response,
struct presentation *p)
{
if ( response == GTK_RESPONSE_ACCEPT ) {
char *filename;
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(d));
/* FIXME */
//if ( export_pdf(p, filename) ) {
// show_error(p, "Failed to export as PDF");
//}
g_free(filename);
}
gtk_widget_destroy(d);
return 0;
}
static gint export_pdf_sig(GtkWidget *widget, struct presentation *p)
{
GtkWidget *d;
d = gtk_file_chooser_dialog_new("Export PDF",
GTK_WINDOW(p->window),
GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
NULL);
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(d),
TRUE);
g_signal_connect(G_OBJECT(d), "response",
G_CALLBACK(export_pdf_response_sig), p);
gtk_widget_show_all(d);
return 0;
}
static gint about_sig(GtkWidget *widget, struct presentation *p)
{
GtkWidget *window;
const gchar *authors[] = {
"Thomas White <taw@bitwiz.org.uk>",
NULL
};
window = gtk_about_dialog_new();
gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW(p->window));
gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(window),
"Colloquium");
gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(window),
PACKAGE_VERSION);
gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(window),
"(c) 2012 Thomas White <taw@bitwiz.org.uk>");
gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(window),
"A tiny presentation program");
gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(window),
"(c) 2012 Thomas White <taw@bitwiz.org.uk>\n");
gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(window),
"http://www.bitwiz.org.uk/");
gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(window), authors);
g_signal_connect(window, "response", G_CALLBACK(gtk_widget_destroy),
NULL);
gtk_widget_show_all(window);
return 0;
}
static gint start_slideshow_sig(GtkWidget *widget, struct presentation *p)
{
try_start_slideshow(p);
return FALSE;
}
/* Change the editor's slide to "np" */
void change_edit_slide(struct presentation *p, struct slide *np)
{
/* If this slide is not being shown on the projector, we can free the
* buffers */
if ( p->cur_proj_slide != p->cur_edit_slide ) {
free_render_buffers_except_thumb(p->cur_edit_slide);
}
p->cur_edit_slide = np;
render_edit_and_proj(p, p->pc);
set_selection(p, NULL);
update_toolbar(p);
redraw_editor(p);
//if ( p->notes != NULL ) {
// notify_notes_slide_changed(p, np);
//}
if ( (p->slideshow != NULL) && p->slideshow_linked ) {
change_proj_slide(p, np);
} /* else leave the slideshow alone */
}
static gint add_slide_sig(GtkWidget *widget, struct presentation *p)
{
struct slide *new;
int cur_slide_number;
cur_slide_number = slide_number(p, p->cur_edit_slide);
new = add_slide(p, cur_slide_number);
change_edit_slide(p, new);
return FALSE;
}
static gint first_slide_sig(GtkWidget *widget, struct presentation *p)
{
change_edit_slide(p, p->slides[0]);
return FALSE;
}
static gint prev_slide_sig(GtkWidget *widget, struct presentation *p)
{
int cur_slide_number;
cur_slide_number = slide_number(p, p->cur_edit_slide);
if ( cur_slide_number == 0 ) return FALSE;
change_edit_slide(p, p->slides[cur_slide_number-1]);
return FALSE;
}
static gint next_slide_sig(GtkWidget *widget, struct presentation *p)
{
int cur_slide_number;
cur_slide_number = slide_number(p, p->cur_edit_slide);
if ( cur_slide_number == p->num_slides-1 ) return FALSE;
change_edit_slide(p, p->slides[cur_slide_number+1]);
return FALSE;
}
static gint last_slide_sig(GtkWidget *widget, struct presentation *p)
{
change_edit_slide(p, p->slides[p->num_slides-1]);
return FALSE;
}
static gint open_stylesheet_sig(GtkWidget *widget, struct presentation *p)
{
/* FIXME */
//if ( p->stylesheetwindow == NULL ) {
// p->stylesheetwindow = open_stylesheet(p);
//} /* else already open */
return FALSE;
}
static gint open_notes_sig(GtkWidget *widget, struct presentation *p)
{
/* FIXME */
//open_notes(p);
return FALSE;
}
static void do_slide_update(struct presentation *p, PangoContext *pc)
{
rerender_slide(p, p->pc);
redraw_editor(p);
if ( (p->slideshow != NULL)
&& (p->cur_edit_slide == p->cur_proj_slide) )
{
redraw_slideshow(p);
}
}
static gint add_furniture(GtkWidget *widget, struct presentation *p)
{
gchar *name;
struct style *sty;
struct frame *fr;
g_object_get(G_OBJECT(widget), "label", &name, NULL);
sty = find_style(p->ss, name);
g_free(name);
if ( sty == NULL ) return 0;
fr = add_subframe(p->cur_edit_slide->top);
fr->style = sty;
set_edit(p, p->cur_edit_slide);
fr->sc = "Hello";
set_selection(p, fr);
do_slide_update(p, p->pc);
return 0;
}
static void update_style_menus(struct presentation *p)
{
GtkWidget *menu;
GtkWidget *item;
struct slide_template *t;
TemplateIterator *iter;
int i, j, n;
for ( i=0; i<p->n_menu_rebuild; i++ ) {
gtk_widget_destroy(p->menu_rebuild_list[i]);
}
free(p->menu_rebuild_list);
/* Add the styles to the "Insert" menu */
menu = gtk_ui_manager_get_widget(p->ui, "/displaywindow/insert");
menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menu));
item = gtk_separator_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
n = 0;
for ( t = template_first(p->ss, &iter);
t != NULL;
t = template_next(p->ss, iter) )
{
n += t->n_styles;
n += 1; /* The top level */
}
p->menu_rebuild_list = calloc(n, sizeof(GtkWidget *));
if ( p->menu_rebuild_list == NULL ) return;
j = 0;
for ( t = template_first(p->ss, &iter);
t != NULL;
t = template_next(p->ss, iter) )
{
GtkWidget *submenu;
submenu = gtk_menu_new();
item = gtk_menu_item_new_with_label(t->name);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
p->menu_rebuild_list[j++] = item;
for ( i=0; i<t->n_styles; i++ ) {
struct style *s = t->styles[i];
item = gtk_menu_item_new_with_label(s->name);
gtk_menu_shell_append(GTK_MENU_SHELL(submenu), item);
p->menu_rebuild_list[j++] = item;
g_signal_connect(G_OBJECT(item), "activate",
G_CALLBACK(add_furniture), p);
}
}
}
static void add_menu_bar(struct presentation *p, GtkWidget *vbox)
{
GError *error = NULL;
GtkWidget *toolbar;
GtkActionEntry entries[] = {
{ "FileAction", NULL, "_File", NULL, NULL, NULL },
{ "NewAction", GTK_STOCK_NEW, "_New",
NULL, NULL, G_CALLBACK(new_sig) },
{ "OpenAction", GTK_STOCK_OPEN, "_Open...",
NULL, NULL, G_CALLBACK(open_sig) },
{ "SaveAction", GTK_STOCK_SAVE, "_Save",
NULL, NULL, G_CALLBACK(save_sig) },
{ "SaveAsAction", GTK_STOCK_SAVE_AS, "Save _As...",
NULL, NULL, G_CALLBACK(saveas_sig) },
{ "SaveStyleAction", GTK_STOCK_SAVE_AS, "Save St_ylesheet",
NULL, NULL, G_CALLBACK(save_ss_sig) },
{ "ExportPDFAction", GTK_STOCK_SAVE_AS, "Export PDF",
NULL, NULL, G_CALLBACK(export_pdf_sig) },
{ "QuitAction", GTK_STOCK_QUIT, "_Quit",
NULL, NULL, G_CALLBACK(quit_sig) },
{ "EditAction", NULL, "_Edit", NULL, NULL, NULL },
{ "UndoAction", GTK_STOCK_UNDO, "_Undo",
NULL, NULL, NULL },
{ "RedoAction", GTK_STOCK_REDO, "_Redo",
NULL, NULL, NULL },
{ "CutAction", GTK_STOCK_CUT, "Cut",
NULL, NULL, NULL },
{ "CopyAction", GTK_STOCK_COPY, "Copy",
NULL, NULL, NULL },
{ "PasteAction", GTK_STOCK_PASTE, "Paste",
NULL, NULL, NULL },
{ "DeleteAction", GTK_STOCK_DELETE, "Delete",
NULL, NULL, NULL },
{ "EditStyleAction", NULL, "Stylesheet...",
NULL, NULL, G_CALLBACK(open_stylesheet_sig) },
{ "InsertAction", NULL, "_Insert", NULL, NULL, NULL },
{ "NewSlideAction", GTK_STOCK_ADD, "_New Slide",
NULL, NULL, G_CALLBACK(add_slide_sig) },
{ "ToolsAction", NULL, "_Tools", NULL, NULL, NULL },
{ "TSlideshowAction", GTK_STOCK_FULLSCREEN, "_Start slideshow",
"F5", NULL, G_CALLBACK(start_slideshow_sig) },
{ "NotesAction", NULL, "_Open slide notes",
"F5", NULL, G_CALLBACK(open_notes_sig) },
{ "PrefsAction", GTK_STOCK_PREFERENCES, "_Preferences",
NULL, NULL, NULL },
{ "HelpAction", NULL, "_Help", NULL, NULL, NULL },
{ "AboutAction", GTK_STOCK_ABOUT, "_About...",
NULL, NULL, G_CALLBACK(about_sig) },
{ "SlideshowAction", GTK_STOCK_FULLSCREEN, "Start Presentation",
NULL, NULL, G_CALLBACK(start_slideshow_sig) },
{ "AddSlideAction", GTK_STOCK_ADD, "Add Slide",
NULL, NULL, G_CALLBACK(add_slide_sig) },
{ "ButtonFirstSlideAction", GTK_STOCK_GOTO_FIRST, "First Slide",
NULL, NULL, G_CALLBACK(first_slide_sig) },
{ "ButtonPrevSlideAction", GTK_STOCK_GO_BACK, "Previous Slide",
NULL, NULL, G_CALLBACK(prev_slide_sig) },
{ "ButtonNextSlideAction", GTK_STOCK_GO_FORWARD, "Next Slide",
NULL, NULL, G_CALLBACK(next_slide_sig) },
{ "ButtonLastSlideAction", GTK_STOCK_GOTO_LAST, "Last Slide",
NULL, NULL, G_CALLBACK(last_slide_sig) },
};
guint n_entries = G_N_ELEMENTS(entries);
p->action_group = gtk_action_group_new("mainwindow");
gtk_action_group_add_actions(p->action_group, entries, n_entries, p);
p->ui = gtk_ui_manager_new();
gtk_ui_manager_insert_action_group(p->ui, p->action_group, 0);
g_signal_connect(p->ui, "add_widget", G_CALLBACK(add_ui_sig), vbox);
if ( gtk_ui_manager_add_ui_from_file(p->ui,
DATADIR"/colloquium/colloquium.ui", &error) == 0 ) {
fprintf(stderr, "Error loading main window menu bar: %s\n",
error->message);
return;
}
gtk_window_add_accel_group(GTK_WINDOW(p->window),
gtk_ui_manager_get_accel_group(p->ui));
gtk_ui_manager_ensure_update(p->ui);
toolbar = gtk_ui_manager_get_widget(p->ui, "/displaywindowtoolbar");
gtk_toolbar_insert(GTK_TOOLBAR(toolbar),
gtk_separator_tool_item_new(), -1);
update_style_menus(p);
update_toolbar(p);
}
static gint close_sig(GtkWidget *window, struct presentation *p)
{
free_presentation(p);
return 0;
}
static void draw_editing_box(cairo_t *cr, struct frame *fr)
{
const double dash[] = {2.0, 2.0};
double xmin, ymin, width, height;
double ptot_w, ptot_h;
xmin = fr->x;
ymin = fr->y;
width = fr->w;
height = fr->h;
cairo_new_path(cr);
cairo_rectangle(cr, xmin, ymin, width, height);
cairo_set_source_rgb(cr, 0.0, 0.69, 1.0);
cairo_set_line_width(cr, 0.5);
cairo_stroke(cr);
cairo_new_path(cr);
ptot_w = fr->lop.pad_l + fr->lop.pad_r;
ptot_h = fr->lop.pad_t + fr->lop.pad_b;
cairo_rectangle(cr, xmin+fr->lop.pad_l, ymin+fr->lop.pad_t,
width-ptot_w, height-ptot_h);
cairo_set_dash(cr, dash, 2, 0.0);
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
cairo_set_line_width(cr, 0.1);
cairo_stroke(cr);
cairo_set_dash(cr, NULL, 0, 0.0);
}
static void draw_caret(cairo_t *cr, struct frame *fr)
{
#if 0
double xposd, yposd, cx;
double clow, chigh;
PangoRectangle pos;
const double t = 1.8;
pango_layout_get_cursor_pos(o->layout,
o->insertion_point+o->insertion_trail,
&pos, NULL);
xposd = pos.x/PANGO_SCALE;
cx = o->base.x - o->offs_x + xposd;
yposd = pos.y/PANGO_SCALE;
clow = o->base.y - o->offs_y + yposd;
chigh = clow + (pos.height/PANGO_SCALE);
cairo_move_to(cr, cx, clow);
cairo_line_to(cr, cx, chigh);
cairo_move_to(cr, cx-t, clow-t);
cairo_line_to(cr, cx, clow);
cairo_move_to(cr, cx+t, clow-t);
cairo_line_to(cr, cx, clow);
cairo_move_to(cr, cx-t, chigh+t);
cairo_line_to(cr, cx, chigh);
cairo_move_to(cr, cx+t, chigh+t);
cairo_line_to(cr, cx, chigh);
cairo_set_source_rgb(cr, 0.86, 0.0, 0.0);
cairo_set_line_width(cr, 1.0);
cairo_stroke(cr);
#endif
}
static void draw_overlay(cairo_t *cr, struct presentation *p)
{
int i;
for ( i=0; i<p->n_selection; i++ ) {
draw_editing_box(cr, p->selection[i]);
}
/* If only one frame is selected, draw the caret */
if ( p->n_selection == 1 ) {
draw_caret(cr, p->selection[0]);
}
}
static gboolean draw_sig(GtkWidget *da, cairo_t *cr,
struct presentation *p)
{
double xoff, yoff;
int width, height;
width = gtk_widget_get_allocated_width(GTK_WIDGET(da));
height = gtk_widget_get_allocated_height(GTK_WIDGET(da));
/* Overall background */
cairo_rectangle(cr, 0.0, 0.0, width, height);
if ( (p->slideshow != NULL) && !p->slideshow_linked ) {
cairo_set_source_rgb(cr, 1.0, 0.3, 0.2);
} else {
cairo_set_source_rgb(cr, 0.9, 0.9, 0.9);
}
cairo_fill(cr);
/* Get the overall size */
xoff = (width - p->slide_width)/2.0;
yoff = (height - p->slide_height)/2.0;
p->border_offs_x = xoff; p->border_offs_y = yoff;
/* Draw the slide from the cache */
if ( p->cur_edit_slide->rendered_edit != NULL ) {
cairo_rectangle(cr, xoff, yoff, p->slide_width, p->slide_height);
cairo_set_source_surface(cr, p->cur_edit_slide->rendered_edit,
xoff, yoff);
cairo_fill(cr);
} else {
fprintf(stderr, "Current slide not rendered yet!\n");
}
cairo_translate(cr, xoff, yoff);
draw_overlay(cr, p);
return FALSE;
}
void update_titlebar(struct presentation *p)
{
get_titlebar_string(p);
if ( p->window != NULL ) {
char *title;
title = malloc(strlen(p->titlebar)+14);
sprintf(title, "%s - Colloquium", p->titlebar);
gtk_window_set_title(GTK_WINDOW(p->window), title);
free(title);
}
}
static gint realise_sig(GtkWidget *da, struct presentation *p)
{
/* FIXME: Can do this "properly" by setting up a separate font map */
p->pc = gtk_widget_get_pango_context(da);
rerender_slide(p, p->pc);
return FALSE;
}
static gboolean im_commit_sig(GtkIMContext *im, gchar *str,
struct presentation *p)
{
if ( p->n_selection == 0 ) {
if ( str[0] == 'b' ) {
check_toggle_blank(p);
} else {
printf("IM keypress: %s\n", str);
}
return FALSE;
}
//im_commit(p->editing_object, str); FIXME!
return FALSE;
}
static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event,
struct presentation *p)
{
gboolean r;
/* Throw the event to the IM context and let it sort things out */
r = gtk_im_context_filter_keypress(GTK_IM_CONTEXT(p->im_context),
event);
if ( r ) return FALSE; /* IM ate it */
switch ( event->keyval ) {
case GDK_KEY_Page_Up :
prev_slide_sig(NULL, p);
break;
case GDK_KEY_Page_Down :
next_slide_sig(NULL, p);
break;
case GDK_KEY_Escape :
if ( p->slideshow != NULL ) end_slideshow(p);
set_selection(p, NULL);
redraw_editor(p);
break;
case GDK_KEY_Return :
//im_commit(p->editing_object, "\n"); FIXME!
break;
case GDK_KEY_B :
case GDK_KEY_b :
if ( p->slideshow != NULL ) {
//if ( p->prefs->b_splits ) {
toggle_slideshow_link(p);
//} else {
// p->ss_blank = 1-p->ss_blank;
// redraw_slideshow(p);
//}
}
break;
}
return FALSE;
}
int open_mainwindow(struct presentation *p)
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *sw;
GdkWindow *win;
if ( p->window != NULL ) {
fprintf(stderr, "Presentation window is already open!\n");
return 1;
}
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
p->window = window;
update_titlebar(p);
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(close_sig), p);
vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
p->edit_slide_width = 1024;
p->proj_slide_width = 2048;
p->thumb_slide_width = 320; /* FIXME: Completely made up */
p->drawingarea = gtk_drawing_area_new();
sw = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw),
p->drawingarea);
gtk_widget_set_size_request(GTK_WIDGET(p->drawingarea),
p->slide_width + 20,
p->slide_height + 20);
add_menu_bar(p, vbox);
gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0);
g_signal_connect(G_OBJECT(p->drawingarea), "realize",
G_CALLBACK(realise_sig), p);
gtk_widget_set_can_focus(GTK_WIDGET(p->drawingarea), TRUE);
gtk_widget_add_events(GTK_WIDGET(p->drawingarea),
GDK_POINTER_MOTION_HINT_MASK
| GDK_BUTTON1_MOTION_MASK
| GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
| GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
g_signal_connect(G_OBJECT(p->drawingarea), "draw",
G_CALLBACK(draw_sig), p);
/* Keyboard and input method stuff */
p->im_context = gtk_im_multicontext_new();
win = gtk_widget_get_window(p->drawingarea);
gtk_im_context_set_client_window(GTK_IM_CONTEXT(p->im_context), win);
g_signal_connect(G_OBJECT(p->im_context), "commit",
G_CALLBACK(im_commit_sig), p);
g_signal_connect(G_OBJECT(p->drawingarea), "key-press-event",
G_CALLBACK(key_press_sig), p);
/* Default size */
gtk_window_set_default_size(GTK_WINDOW(p->window), 1024+100, 768+100);
gtk_window_set_resizable(GTK_WINDOW(p->window), TRUE);
assert(p->num_slides > 0);
gtk_widget_grab_focus(GTK_WIDGET(p->drawingarea));
gtk_widget_show_all(window);
return 0;
}
|