-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathui_edit.c
113 lines (92 loc) · 3.38 KB
/
ui_edit.c
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
/*
* Copyright (c) 2021 Justin Meiners
*
* 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, version 2.
*
* 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/>.
*/
#include "ui.h"
static
void edit_menu_(Widget w, XtPointer a, XtPointer b)
{
size_t item = (size_t)a;
switch (item)
{
case 0:
paint_undo(&g_paint_ctx);
ui_refresh_drawing(1);
break;
case 1:
paint_redo(&g_paint_ctx);
ui_refresh_drawing(1);
break;
case 2:
paint_cut(&g_paint_ctx);
ui_refresh_drawing(0);
break;
case 3:
paint_copy(&g_paint_ctx);
break;
case 4:
paint_paste(&g_paint_ctx);
ui_refresh_drawing(0);
ui_refresh_tool();
break;
case 5:
paint_select_clear(&g_paint_ctx);
ui_refresh_drawing(0);
ui_refresh_tool();
break;
case 6:
paint_select_all(&g_paint_ctx);
ui_refresh_drawing(0);
ui_refresh_tool();
break;
}
}
void ui_setup_edit_menu(Widget menubar)
{
// accelerator format: https://www.x.org/releases/X11R7.5/doc/Xt/Xt.pdf
XmString undo_str = XmStringCreateLocalized("Undo");
XmString undo_key = XmStringCreateLocalized("Ctrl+Z");
XmString redo_str = XmStringCreateLocalized("Redo");
XmString redo_key = XmStringCreateLocalized("Ctrl+Y");
XmString cut_str = XmStringCreateLocalized("Cut");
XmString cut_key = XmStringCreateLocalized("Ctrl+X");
XmString copy_str = XmStringCreateLocalized("Copy");
XmString copy_key = XmStringCreateLocalized("Ctrl+C");
XmString paste_str = XmStringCreateLocalized("Paste");
XmString paste_key = XmStringCreateLocalized("Ctrl+V");
XmString clear_str = XmStringCreateLocalized("Clear Selection");
XmString clear_key = XmStringCreateLocalized("Ctrl+Shift+A");
XmString select_str = XmStringCreateLocalized("Select All");
XmString select_key = XmStringCreateLocalized("Ctrl+A");
XmVaCreateSimplePulldownMenu(menubar, "edit_menu", 1, edit_menu_,
XmVaPUSHBUTTON, undo_str, 'U', "Ctrl<Key>z", undo_key,
XmVaPUSHBUTTON, redo_str, 'R', "Ctrl<Key>y", redo_key,
XmVaSEPARATOR,
XmVaPUSHBUTTON, cut_str, 't', "Ctrl<Key>x", cut_key,
XmVaPUSHBUTTON, copy_str, 'C', "Ctrl<Key>c", copy_key,
XmVaPUSHBUTTON, paste_str, 'P', "Ctrl<Key>v", paste_key,
XmVaPUSHBUTTON, clear_str, 'l', "Ctrl Shift<Key>a", clear_key,
XmVaPUSHBUTTON, select_str, 'A', "Ctrl<Key>a", select_key,
NULL);
XmStringFree(paste_str);
XmStringFree(paste_key);
XmStringFree(copy_str);
XmStringFree(copy_key);
XmStringFree(cut_str);
XmStringFree(cut_key);
XmStringFree(redo_str);
XmStringFree(redo_key);
XmStringFree(undo_key);
XmStringFree(undo_str);
}