application/menu.c

Fri, 11 Dec 2020 11:46:19 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 11 Dec 2020 11:46:19 +0100
changeset 3
c04433993fbb
parent 2
ea89bbb0c4c8
child 4
d8e8f34e65ee
permissions
-rw-r--r--

add drawingarea and textarea group

2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2020 Olaf Wintermann. All rights reserved.
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "menu.h"
3
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
30 #include "window.h"
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include <stdio.h>
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include <stdlib.h>
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 static UiInteger *tb_sidebar;
3
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
38 static UiInteger *tb_singleview;
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
39 static UiInteger *tb_dualview;
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 static void create_main_menu(void) {
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 ui_menu("File");
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 ui_menuitem_st(UI_STOCK_OPEN, NULL, NULL);
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 ui_menu("Edit");
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 ui_menuitem_st(UI_STOCK_UNDO, NULL, NULL);
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 ui_menuitem_st(UI_STOCK_REDO, NULL, NULL);
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 }
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 static void create_main_toolbar(void) {
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 UiContext *ctx = ui_global_context();
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 tb_sidebar = ui_int_new(ctx, NULL);
3
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
54 tb_singleview = ui_int_new(ctx, NULL);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
55 tb_dualview = ui_int_new(ctx, NULL);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
56 tb_sidebar->observers = ui_add_observer(tb_sidebar->observers, action_show_sidebar, NULL);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
57 tb_singleview->observers = ui_add_observer(tb_singleview->observers, action_singleview, NULL);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
58 tb_dualview->observers = ui_add_observer(tb_dualview->observers, action_dualview, NULL);
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 ui_toolitem_toggle("show-sidebar", "Sidebar", NULL, tb_sidebar);
3
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
61 ui_toolitem_toggle("singleview", "S", NULL, tb_singleview);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
62 ui_toolitem_toggle("dualview", "D", NULL, tb_dualview);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
63
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 tb_sidebar->value = 1;
3
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
65 tb_singleview->value = 0;
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
66 tb_dualview->value = 1;
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 ui_toolbar_add_default("show-sidebar");
3
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
69 ui_toolbar_add_default("@separator");
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
70 ui_toolbar_add_default("singleview");
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
71 ui_toolbar_add_default("dualview");
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
72 ui_toolbar_add_default("@separator");
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 }
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 void menu_init(void) {
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 create_main_menu();
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 create_main_toolbar();
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 }
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 void action_show_sidebar(UiEvent *event, void *udata) {
3
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
81 WindowData *w = event->window;
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
82 ui_set_visible(w->sidebar, event->intval);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
83 }
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
84
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
85 static void change_view(WindowData *w, int dual) {
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
86 if(dual) {
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
87 ui_set_visible(w->browser, TRUE);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
88 ui_set_visible(w->editor, TRUE);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
89 } else {
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
90 UiBool e, b;
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
91 if(w->editorIsOpen) {
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
92 e = TRUE;
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
93 b = FALSE;
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
94 } else {
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
95 e = FALSE;
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
96 b = TRUE;
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
97 }
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
98 ui_set_visible(w->browser, b);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
99 ui_set_visible(w->editor, e);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
100 }
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
101 }
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
102
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
103 void action_dualview(UiEvent *event, void *udata) {
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
104 int s = event->intval == 1 ? 0 : 1;
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
105 tb_singleview->set(tb_singleview, s);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
106 change_view(event->window, event->intval);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
107 }
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
108
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
109 void action_singleview(UiEvent *event, void *udata) {
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
110 int s = event->intval == 1 ? 0 : 1;
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
111 tb_dualview->set(tb_dualview, s);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
112 change_view(event->window, s);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
113 }
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
114
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
115
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
116
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
117
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
118 void action_test1(UiEvent *event, void *udata) {
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 }
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121
3
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
122 void action_test2(UiEvent *event, void *udata) {
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 }

mercurial