Fri, 11 Dec 2020 11:46:19 +0100
add drawingarea and textarea group
2 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2020 Olaf Wintermann. All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
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 | 31 | |
32 | #include <stdio.h> | |
33 | #include <stdlib.h> | |
34 | ||
35 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" | |
36 | ||
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 | 40 | |
41 | static void create_main_menu(void) { | |
42 | ui_menu("File"); | |
43 | ui_menuitem_st(UI_STOCK_OPEN, NULL, NULL); | |
44 | ||
45 | ui_menu("Edit"); | |
46 | ui_menuitem_st(UI_STOCK_UNDO, NULL, NULL); | |
47 | ui_menuitem_st(UI_STOCK_REDO, NULL, NULL); | |
48 | ||
49 | } | |
50 | ||
51 | static void create_main_toolbar(void) { | |
52 | UiContext *ctx = ui_global_context(); | |
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 | 59 | |
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 | 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 | 67 | |
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 | 73 | } |
74 | ||
75 | void menu_init(void) { | |
76 | create_main_menu(); | |
77 | create_main_toolbar(); | |
78 | } | |
79 | ||
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 | 119 | |
120 | } | |
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 | 123 | |
124 | } |