reflexion 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.doc/ext/reflex/application.cpp +19 -1
- data/.doc/ext/reflex/chase_constraint.cpp +84 -0
- data/.doc/ext/reflex/clipboard.cpp +65 -0
- data/.doc/ext/reflex/constraint.cpp +135 -0
- data/.doc/ext/reflex/key_event.cpp +6 -6
- data/.doc/ext/reflex/link_constraint.cpp +178 -0
- data/.doc/ext/reflex/menu.cpp +302 -0
- data/.doc/ext/reflex/native.cpp +22 -4
- data/.doc/ext/reflex/pin.cpp +156 -0
- data/.doc/ext/reflex/pointer.cpp +2 -0
- data/.doc/ext/reflex/pointer_event.cpp +1 -1
- data/.doc/ext/reflex/reflex.cpp +42 -7
- data/.doc/ext/reflex/selector.cpp +4 -4
- data/.doc/ext/reflex/snap_constraint.cpp +125 -0
- data/.doc/ext/reflex/style_length.cpp +3 -2
- data/.doc/ext/reflex/view.cpp +96 -23
- data/.doc/ext/reflex/wheel_constraint.cpp +142 -0
- data/.doc/ext/reflex/window.cpp +59 -17
- data/.github/workflows/release-gem.yml +10 -1
- data/.github/workflows/test.yml +9 -0
- data/ChangeLog.md +30 -0
- data/README.md +1 -0
- data/VERSION +1 -1
- data/ext/reflex/application.cpp +21 -1
- data/ext/reflex/chase_constraint.cpp +89 -0
- data/ext/reflex/clipboard.cpp +69 -0
- data/ext/reflex/constraint.cpp +146 -0
- data/ext/reflex/key_event.cpp +6 -6
- data/ext/reflex/link_constraint.cpp +194 -0
- data/ext/reflex/menu.cpp +330 -0
- data/ext/reflex/native.cpp +22 -4
- data/ext/reflex/pin.cpp +165 -0
- data/ext/reflex/pointer.cpp +2 -0
- data/ext/reflex/pointer_event.cpp +1 -1
- data/ext/reflex/reflex.cpp +42 -7
- data/ext/reflex/selector.cpp +4 -4
- data/ext/reflex/selector.h +1 -1
- data/ext/reflex/snap_constraint.cpp +135 -0
- data/ext/reflex/style_length.cpp +3 -2
- data/ext/reflex/view.cpp +117 -37
- data/ext/reflex/wheel_constraint.cpp +154 -0
- data/ext/reflex/window.cpp +65 -18
- data/include/reflex/application.h +9 -0
- data/include/reflex/clipboard.h +53 -0
- data/include/reflex/constraint.h +275 -0
- data/include/reflex/defs.h +204 -195
- data/include/reflex/event.h +2 -0
- data/include/reflex/menu.h +120 -0
- data/include/reflex/pin.h +68 -0
- data/include/reflex/pointer.h +4 -0
- data/include/reflex/ruby/clipboard.h +23 -0
- data/include/reflex/ruby/constraint.h +94 -0
- data/include/reflex/ruby/menu.h +103 -0
- data/include/reflex/ruby/pin.h +40 -0
- data/include/reflex/ruby/view.h +36 -0
- data/include/reflex/ruby/window.h +36 -18
- data/include/reflex/view.h +39 -12
- data/include/reflex/window.h +17 -4
- data/include/reflex.h +5 -0
- data/lib/reflex/chase_constraint.rb +15 -0
- data/lib/reflex/clipboard.rb +19 -0
- data/lib/reflex/constraint.rb +29 -0
- data/lib/reflex/extension.rb +1 -1
- data/lib/reflex/helper.rb +28 -0
- data/lib/reflex/key_event.rb +7 -12
- data/lib/reflex/link_constraint.rb +31 -0
- data/lib/reflex/menu.rb +76 -0
- data/lib/reflex/pin.rb +39 -0
- data/lib/reflex/pointer.rb +18 -0
- data/lib/reflex/pointer_event.rb +1 -1
- data/lib/reflex/snap_constraint.rb +28 -0
- data/lib/reflex/view.rb +56 -4
- data/lib/reflex/wheel_constraint.rb +28 -0
- data/lib/reflex/wheel_event.rb +9 -0
- data/lib/reflex.rb +15 -6
- data/pod.rake +4 -2
- data/reflex.gemspec +3 -3
- data/samples/constraint.rb +152 -0
- data/samples/menu.rb +29 -0
- data/src/application.cpp +21 -2
- data/src/application.h +5 -0
- data/src/clipboard.cpp +81 -0
- data/src/constraint.cpp +1662 -0
- data/src/constraint.h +64 -0
- data/src/event.cpp +7 -1
- data/src/event.h +1 -2
- data/src/ios/application.mm +5 -0
- data/src/ios/clipboard.mm +44 -0
- data/src/ios/event.h +6 -2
- data/src/ios/event.mm +31 -12
- data/src/ios/menu.mm +36 -0
- data/src/ios/view_controller.mm +45 -12
- data/src/ios/window.mm +6 -0
- data/src/menu.cpp +325 -0
- data/src/menu.h +65 -0
- data/src/osx/app_delegate.mm +74 -125
- data/src/osx/application.mm +16 -0
- data/src/osx/clipboard.mm +45 -0
- data/src/osx/event.mm +40 -10
- data/src/osx/menu.h +25 -0
- data/src/osx/menu.mm +372 -0
- data/src/osx/native_window.mm +27 -0
- data/src/osx/opengl_view.mm +51 -0
- data/src/osx/window.mm +11 -0
- data/src/pin.cpp +137 -0
- data/src/pointer.cpp +27 -16
- data/src/pointer.h +6 -0
- data/src/sdl/application.cpp +5 -0
- data/src/sdl/clipboard.cpp +39 -0
- data/src/sdl/event.cpp +20 -3
- data/src/sdl/event.h +6 -3
- data/src/sdl/menu.cpp +35 -0
- data/src/sdl/window.cpp +26 -8
- data/src/view.cpp +313 -52
- data/src/view.h +18 -2
- data/src/win32/application.cpp +5 -0
- data/src/win32/clipboard.cpp +210 -0
- data/src/win32/event.cpp +11 -1
- data/src/win32/event.h +2 -0
- data/src/win32/menu.cpp +352 -0
- data/src/win32/menu.h +27 -0
- data/src/win32/window.cpp +62 -0
- data/src/win32/window.h +3 -0
- data/src/window.cpp +235 -22
- data/src/window.h +13 -2
- data/src/world.cpp +77 -14
- data/src/world.h +9 -2
- data/test/helper.rb +7 -0
- data/test/test_application.rb +11 -0
- data/test/test_chase_constraint.rb +124 -0
- data/test/test_clipboard.rb +54 -0
- data/test/test_constraint.rb +186 -0
- data/test/test_key_event.rb +6 -0
- data/test/test_link_constraint.rb +239 -0
- data/test/test_menu.rb +207 -0
- data/test/test_pin.rb +65 -0
- data/test/test_pointer.rb +23 -9
- data/test/test_pointer_event.rb +1 -1
- data/test/test_snap_constraint.rb +142 -0
- data/test/test_view.rb +113 -23
- data/test/test_wheel_constraint.rb +127 -0
- data/test/test_wheel_event.rb +15 -9
- data/test/test_window.rb +10 -0
- metadata +82 -8
data/src/menu.cpp
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
#include "menu.h"
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
#include <algorithm>
|
|
5
|
+
#include <rays/point.h>
|
|
6
|
+
#include "reflex/exception.h"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
namespace Reflex
|
|
10
|
+
{
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
Menu::Data::Data ()
|
|
14
|
+
{
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
Menu::Data::~Data ()
|
|
18
|
+
{
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
Menu::Menu (const char* label)
|
|
23
|
+
: self(Menu_create_data())
|
|
24
|
+
{
|
|
25
|
+
if (label) set_label(label);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
Menu::~Menu ()
|
|
29
|
+
{
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
void
|
|
33
|
+
Menu::popup (coord x, coord y)
|
|
34
|
+
{
|
|
35
|
+
Menu_popup(this, NULL, x, y);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
void
|
|
39
|
+
Menu::popup (const Point& position)
|
|
40
|
+
{
|
|
41
|
+
Menu_popup(this, NULL, position.x, position.y);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
void
|
|
45
|
+
Menu::popup (View* view, coord x, coord y)
|
|
46
|
+
{
|
|
47
|
+
Menu_popup(this, view, x, y);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
void
|
|
51
|
+
Menu::popup (View* view, const Point& position)
|
|
52
|
+
{
|
|
53
|
+
Menu_popup(this, view, position.x, position.y);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
void
|
|
57
|
+
Menu::add_child (Menu* child, int index)
|
|
58
|
+
{
|
|
59
|
+
if (!child)
|
|
60
|
+
argument_error(__FILE__, __LINE__);
|
|
61
|
+
|
|
62
|
+
if (child->parent() == this)
|
|
63
|
+
return;
|
|
64
|
+
|
|
65
|
+
if (child->parent())
|
|
66
|
+
argument_error(__FILE__, __LINE__);
|
|
67
|
+
|
|
68
|
+
ChildList* children = self->children();
|
|
69
|
+
if (index < 0 || (int) children->size() < index)
|
|
70
|
+
index = (int) children->size();
|
|
71
|
+
|
|
72
|
+
children->insert(children->begin() + (size_t) index, child);
|
|
73
|
+
|
|
74
|
+
child->self->parent.reset(this);
|
|
75
|
+
|
|
76
|
+
Menu_child_added(this, child, index);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
void
|
|
80
|
+
Menu::remove_child (Menu* child)
|
|
81
|
+
{
|
|
82
|
+
if (!child || child->parent() != this)
|
|
83
|
+
return;
|
|
84
|
+
|
|
85
|
+
auto* children = self->pchildren.get();
|
|
86
|
+
if (!children) return;
|
|
87
|
+
|
|
88
|
+
auto it = std::find(children->begin(), children->end(), child);
|
|
89
|
+
if (it == children->end()) return;
|
|
90
|
+
|
|
91
|
+
children->erase(it);
|
|
92
|
+
if (children->empty())
|
|
93
|
+
self->pchildren.reset();
|
|
94
|
+
|
|
95
|
+
child->self->parent.reset();
|
|
96
|
+
|
|
97
|
+
Menu_child_removed(this, child);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
void
|
|
101
|
+
Menu::clear_children ()
|
|
102
|
+
{
|
|
103
|
+
while (self->pchildren && !self->pchildren->empty())
|
|
104
|
+
remove_child(self->pchildren->back().get());
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static void
|
|
108
|
+
find_all_children (
|
|
109
|
+
Menu::ChildList* result, const Menu* menu, const Selector& selector,
|
|
110
|
+
bool recursive)
|
|
111
|
+
{
|
|
112
|
+
auto* children = menu->self->pchildren.get();
|
|
113
|
+
if (!children) return;
|
|
114
|
+
|
|
115
|
+
for (auto& child : *children)
|
|
116
|
+
{
|
|
117
|
+
if (!child)
|
|
118
|
+
invalid_state_error(__FILE__, __LINE__);
|
|
119
|
+
|
|
120
|
+
if (child->selector().contains(selector))
|
|
121
|
+
result->push_back(child);
|
|
122
|
+
|
|
123
|
+
if (recursive)
|
|
124
|
+
find_all_children(result, child.get(), selector, true);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
Menu::ChildList
|
|
129
|
+
Menu::find_children (const Selector& selector, bool recursive) const
|
|
130
|
+
{
|
|
131
|
+
ChildList result;
|
|
132
|
+
find_all_children(&result, this, selector, recursive);
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
static bool
|
|
137
|
+
is_separator_label (const char* s)
|
|
138
|
+
{
|
|
139
|
+
if (!s || !*s) return false;
|
|
140
|
+
for (const char* p = s; *p; ++p)
|
|
141
|
+
if (*p != '-') return false;
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
void
|
|
146
|
+
Menu::set_label (const char* label)
|
|
147
|
+
{
|
|
148
|
+
if (!label) label = "";
|
|
149
|
+
if (label == self->label)
|
|
150
|
+
return;
|
|
151
|
+
|
|
152
|
+
self->label = label;
|
|
153
|
+
self->separator = is_separator_label(label);
|
|
154
|
+
|
|
155
|
+
Menu_update(this);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const char*
|
|
159
|
+
Menu::label () const
|
|
160
|
+
{
|
|
161
|
+
return self->label.c_str();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
void
|
|
165
|
+
Menu::enable (bool state)
|
|
166
|
+
{
|
|
167
|
+
if (state == self->enabled)
|
|
168
|
+
return;
|
|
169
|
+
|
|
170
|
+
self->enabled = state;
|
|
171
|
+
Menu_update(this);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
bool
|
|
175
|
+
Menu::is_enabled () const
|
|
176
|
+
{
|
|
177
|
+
return self->enabled;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
void
|
|
181
|
+
Menu::check (bool state)
|
|
182
|
+
{
|
|
183
|
+
if (state == self->checked)
|
|
184
|
+
return;
|
|
185
|
+
|
|
186
|
+
self->checked = state;
|
|
187
|
+
Menu_update(this);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
bool
|
|
191
|
+
Menu::is_checked () const
|
|
192
|
+
{
|
|
193
|
+
return self->checked;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
void
|
|
197
|
+
Menu::set_shortcut (const char* key, uint modifiers)
|
|
198
|
+
{
|
|
199
|
+
if (!key) key = "";
|
|
200
|
+
if (key == self->key && modifiers == self->modifiers)
|
|
201
|
+
return;
|
|
202
|
+
|
|
203
|
+
self->key = key;
|
|
204
|
+
self->modifiers = modifiers;
|
|
205
|
+
Menu_update(this);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const char*
|
|
209
|
+
Menu::shortcut_key () const
|
|
210
|
+
{
|
|
211
|
+
return self->key.c_str();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
uint
|
|
215
|
+
Menu::shortcut_modifiers () const
|
|
216
|
+
{
|
|
217
|
+
return self->modifiers;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
void
|
|
221
|
+
Menu::set_image (const Image& image)
|
|
222
|
+
{
|
|
223
|
+
self->image = image;
|
|
224
|
+
Menu_update(this);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const Image&
|
|
228
|
+
Menu::image () const
|
|
229
|
+
{
|
|
230
|
+
return self->image;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
bool
|
|
234
|
+
Menu::is_separator () const
|
|
235
|
+
{
|
|
236
|
+
return self->separator;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
Menu*
|
|
240
|
+
Menu::parent ()
|
|
241
|
+
{
|
|
242
|
+
return self->parent;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const Menu*
|
|
246
|
+
Menu::parent () const
|
|
247
|
+
{
|
|
248
|
+
return const_cast<Menu*>(this)->parent();
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
size_t
|
|
252
|
+
Menu::size () const
|
|
253
|
+
{
|
|
254
|
+
return self->pchildren ? self->pchildren->size() : 0;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
bool
|
|
258
|
+
Menu::empty () const
|
|
259
|
+
{
|
|
260
|
+
return self->pchildren ? self->pchildren->empty() : true;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
static Menu::ChildList empty_children;
|
|
264
|
+
|
|
265
|
+
Menu::iterator
|
|
266
|
+
Menu::begin ()
|
|
267
|
+
{
|
|
268
|
+
if (!self->pchildren) return empty_children.begin();
|
|
269
|
+
return self->pchildren->begin();
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
Menu::const_iterator
|
|
273
|
+
Menu::begin () const
|
|
274
|
+
{
|
|
275
|
+
if (!self->pchildren) return empty_children.begin();
|
|
276
|
+
return self->pchildren->begin();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
Menu::iterator
|
|
280
|
+
Menu::end ()
|
|
281
|
+
{
|
|
282
|
+
if (!self->pchildren) return empty_children.end();
|
|
283
|
+
return self->pchildren->end();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
Menu::const_iterator
|
|
287
|
+
Menu::end () const
|
|
288
|
+
{
|
|
289
|
+
if (!self->pchildren) return empty_children.end();
|
|
290
|
+
return self->pchildren->end();
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
void
|
|
294
|
+
Menu::on_show (Event* e)
|
|
295
|
+
{
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
void
|
|
299
|
+
Menu::on_hide (Event* e)
|
|
300
|
+
{
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
void
|
|
304
|
+
Menu::on_open_submenu (Event* e)
|
|
305
|
+
{
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
void
|
|
309
|
+
Menu::on_close_submenu (Event* e)
|
|
310
|
+
{
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
void
|
|
314
|
+
Menu::on_click (Event* e)
|
|
315
|
+
{
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
SelectorPtr*
|
|
319
|
+
Menu::get_selector_ptr ()
|
|
320
|
+
{
|
|
321
|
+
return &self->pselector;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
}// Reflex
|
data/src/menu.h
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// -*- c++ -*-
|
|
2
|
+
#pragma once
|
|
3
|
+
#ifndef __REFLEX_SRC_MENU_H__
|
|
4
|
+
#define __REFLEX_SRC_MENU_H__
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
#include <memory>
|
|
8
|
+
#include <rays/image.h>
|
|
9
|
+
#include "reflex/menu.h"
|
|
10
|
+
#include "selector.h"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
namespace Reflex
|
|
14
|
+
{
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
struct Menu::Data
|
|
18
|
+
{
|
|
19
|
+
|
|
20
|
+
Xot::WeakRef<Menu> parent;
|
|
21
|
+
|
|
22
|
+
String label, key;
|
|
23
|
+
|
|
24
|
+
Image image;
|
|
25
|
+
|
|
26
|
+
uint modifiers = MOD_NONE;
|
|
27
|
+
|
|
28
|
+
bool enabled = true;
|
|
29
|
+
|
|
30
|
+
bool checked = false;
|
|
31
|
+
|
|
32
|
+
bool separator = false;
|
|
33
|
+
|
|
34
|
+
std::unique_ptr<ChildList> pchildren;
|
|
35
|
+
|
|
36
|
+
SelectorPtr pselector;
|
|
37
|
+
|
|
38
|
+
Data ();
|
|
39
|
+
|
|
40
|
+
virtual ~Data ();
|
|
41
|
+
|
|
42
|
+
ChildList* children ()
|
|
43
|
+
{
|
|
44
|
+
if (!pchildren) pchildren.reset(new ChildList);
|
|
45
|
+
return pchildren.get();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
};// Menu::Data
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
Menu::Data* Menu_create_data ();
|
|
52
|
+
|
|
53
|
+
void Menu_update (Menu* menu);
|
|
54
|
+
|
|
55
|
+
void Menu_popup (Menu* menu, View* view, coord x, coord y);
|
|
56
|
+
|
|
57
|
+
void Menu_child_added (Menu* parent, Menu* child, int index);
|
|
58
|
+
|
|
59
|
+
void Menu_child_removed (Menu* parent, Menu* child);
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
}// Reflex
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
#endif//EOH
|
data/src/osx/app_delegate.mm
CHANGED
|
@@ -6,6 +6,74 @@
|
|
|
6
6
|
#import <Cocoa/Cocoa.h>
|
|
7
7
|
#include "reflex/event.h"
|
|
8
8
|
#include "reflex/exception.h"
|
|
9
|
+
#include "menu.h"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
static Reflex::Menu::Ref
|
|
13
|
+
create_menu (
|
|
14
|
+
const char* label, const char* name, SEL action = NULL,
|
|
15
|
+
const char* key = NULL, uint modifiers = Reflex::MOD_COMMAND)
|
|
16
|
+
{
|
|
17
|
+
Reflex::Menu* item = new Reflex::Menu(label);
|
|
18
|
+
item->set_name(name);
|
|
19
|
+
if (key) item->set_shortcut(key, modifiers);
|
|
20
|
+
Reflex::Menu_set_native_action(item, action);
|
|
21
|
+
return item;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static Reflex::Menu::Ref
|
|
25
|
+
create_sep ()
|
|
26
|
+
{
|
|
27
|
+
return new Reflex::Menu("-");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static Reflex::Menu::Ref
|
|
31
|
+
create_application_menu (Reflex::Application* application)
|
|
32
|
+
{
|
|
33
|
+
using namespace Reflex;
|
|
34
|
+
|
|
35
|
+
String name = application->name();
|
|
36
|
+
if (!name.empty()) name = " " + name;
|
|
37
|
+
|
|
38
|
+
Menu::Ref app = create_menu("Application", "application");
|
|
39
|
+
Menu::Ref services = create_menu("Services", "services");
|
|
40
|
+
|
|
41
|
+
app->add_child(create_menu(("About" + name).c_str(), "about", @selector(showAbout)));
|
|
42
|
+
app->add_child(create_sep());
|
|
43
|
+
app->add_child(create_menu("Preferences", "preferences", @selector(showPreference), ","));
|
|
44
|
+
app->add_child(create_sep());
|
|
45
|
+
app->add_child(services.get());
|
|
46
|
+
app->add_child(create_sep());
|
|
47
|
+
app->add_child(create_menu(("Hide" + name).c_str(), "hide", @selector(hide:), "h"));
|
|
48
|
+
app->add_child(create_menu(
|
|
49
|
+
"Hide Others", "hide_others", @selector(hideOtherApplications:),
|
|
50
|
+
"h", MOD_OPTION | MOD_COMMAND));
|
|
51
|
+
app->add_child(create_menu("ShowAll", "show_all", @selector(unhideAllApplications:)));
|
|
52
|
+
app->add_child(create_sep());
|
|
53
|
+
app->add_child(create_menu(("Quit" + name).c_str(), "quit", @selector(quit), "q"));
|
|
54
|
+
|
|
55
|
+
[NSApp setServicesMenu: Menu_get_nssubmenu(services)];
|
|
56
|
+
if ([NSApp respondsToSelector: @selector(setAppleMenu:)])
|
|
57
|
+
[NSApp performSelector: @selector(setAppleMenu:) withObject: Menu_get_nssubmenu(app)];
|
|
58
|
+
|
|
59
|
+
return app;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static Reflex::Menu::Ref
|
|
63
|
+
create_window_menu ()
|
|
64
|
+
{
|
|
65
|
+
Reflex::Menu::Ref win = create_menu("Window", "window");
|
|
66
|
+
|
|
67
|
+
win->add_child(create_menu("Minimize", "minimize", @selector(performMiniaturize:), "m"));
|
|
68
|
+
win->add_child(create_menu("Zoom", "zoom", @selector(performZoom:)));
|
|
69
|
+
win->add_child(create_sep());
|
|
70
|
+
win->add_child(create_menu(
|
|
71
|
+
"Bring All to Front", "bring_all_to_front", @selector(arrangeInFront:)));
|
|
72
|
+
|
|
73
|
+
[NSApp setWindowsMenu: Menu_get_nssubmenu(win)];
|
|
74
|
+
|
|
75
|
+
return win;
|
|
76
|
+
}
|
|
9
77
|
|
|
10
78
|
|
|
11
79
|
@implementation ReflexAppDelegate
|
|
@@ -105,7 +173,12 @@
|
|
|
105
173
|
|
|
106
174
|
- (void) applicationWillFinishLaunching: (NSNotification*) notification
|
|
107
175
|
{
|
|
108
|
-
[
|
|
176
|
+
if (!application || [NSApp mainMenu]) return;
|
|
177
|
+
|
|
178
|
+
Reflex::Menu::Ref menu = new Reflex::Menu();
|
|
179
|
+
menu->add_child(create_application_menu(application));
|
|
180
|
+
menu->add_child(create_window_menu());
|
|
181
|
+
application->set_menu(menu);
|
|
109
182
|
}
|
|
110
183
|
|
|
111
184
|
- (void) applicationDidFinishLaunching: (NSNotification*) notification
|
|
@@ -138,128 +211,4 @@
|
|
|
138
211
|
[self unbind];
|
|
139
212
|
}
|
|
140
213
|
|
|
141
|
-
- (BOOL) setupApplicationMenu: (NSMenu*) parent
|
|
142
|
-
{
|
|
143
|
-
if (!application || !parent) return NO;
|
|
144
|
-
|
|
145
|
-
NSMenu* menu = [[[NSMenu alloc]
|
|
146
|
-
initWithTitle: @"Application"]
|
|
147
|
-
autorelease];
|
|
148
|
-
if ([NSApp respondsToSelector: @selector(setAppleMenu:)])
|
|
149
|
-
[NSApp performSelector: @selector(setAppleMenu:) withObject: menu];
|
|
150
|
-
|
|
151
|
-
NSString* name = !application->self->name.empty() ?
|
|
152
|
-
[NSString stringWithUTF8String: application->self->name.c_str()] : @"";
|
|
153
|
-
if ([name length] > 0)
|
|
154
|
-
name = [@" " stringByAppendingString: name];
|
|
155
|
-
|
|
156
|
-
NSMenu* submenu = nil;
|
|
157
|
-
NSMenuItem* item = nil;
|
|
158
|
-
|
|
159
|
-
[menu
|
|
160
|
-
addItemWithTitle: [@"About" stringByAppendingString: name]
|
|
161
|
-
action: @selector(showAbout)
|
|
162
|
-
keyEquivalent: @""];
|
|
163
|
-
|
|
164
|
-
[menu addItem: [NSMenuItem separatorItem]];
|
|
165
|
-
|
|
166
|
-
[menu
|
|
167
|
-
addItemWithTitle: @"Preferences"
|
|
168
|
-
action: @selector(showPreference)
|
|
169
|
-
keyEquivalent: @","];
|
|
170
|
-
|
|
171
|
-
[menu addItem: [NSMenuItem separatorItem]];
|
|
172
|
-
|
|
173
|
-
item = [menu
|
|
174
|
-
addItemWithTitle: @"Services"
|
|
175
|
-
action: nil
|
|
176
|
-
keyEquivalent: @""];
|
|
177
|
-
submenu = [[[NSMenu alloc] initWithTitle: @"Services"] autorelease];
|
|
178
|
-
[item setSubmenu: submenu];
|
|
179
|
-
[NSApp setServicesMenu: submenu];
|
|
180
|
-
|
|
181
|
-
[menu addItem: [NSMenuItem separatorItem]];
|
|
182
|
-
|
|
183
|
-
[menu
|
|
184
|
-
addItemWithTitle: [@"Hide" stringByAppendingString: name]
|
|
185
|
-
action: @selector(hide:)
|
|
186
|
-
keyEquivalent: @"h"];
|
|
187
|
-
|
|
188
|
-
item = [menu
|
|
189
|
-
addItemWithTitle: @"Hide Others"
|
|
190
|
-
action: @selector(hideOtherApplications:)
|
|
191
|
-
keyEquivalent: @"h"];
|
|
192
|
-
[item setKeyEquivalentModifierMask: NSAlternateKeyMask | NSCommandKeyMask];
|
|
193
|
-
|
|
194
|
-
[menu
|
|
195
|
-
addItemWithTitle: @"ShowAll"
|
|
196
|
-
action: @selector(unhideAllApplications:)
|
|
197
|
-
keyEquivalent: @""];
|
|
198
|
-
|
|
199
|
-
[menu addItem: [NSMenuItem separatorItem]];
|
|
200
|
-
|
|
201
|
-
[menu
|
|
202
|
-
addItemWithTitle: [@"Quit" stringByAppendingString: name]
|
|
203
|
-
action: @selector(quit)
|
|
204
|
-
keyEquivalent: @"q"];
|
|
205
|
-
|
|
206
|
-
item =
|
|
207
|
-
[parent addItemWithTitle: @"Application" action: nil keyEquivalent: @""];
|
|
208
|
-
[parent setSubmenu: menu forItem: item];
|
|
209
|
-
|
|
210
|
-
return YES;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
- (BOOL) setupWindowMenu: (NSMenu*) parent
|
|
214
|
-
{
|
|
215
|
-
if (!parent) return NO;
|
|
216
|
-
|
|
217
|
-
NSMenu* menu = [[[NSMenu alloc]
|
|
218
|
-
initWithTitle: @"Window"]
|
|
219
|
-
autorelease];
|
|
220
|
-
|
|
221
|
-
[menu
|
|
222
|
-
addItemWithTitle: @"Minimize"
|
|
223
|
-
action: @selector(performMiniaturize:)
|
|
224
|
-
keyEquivalent: @"m"];
|
|
225
|
-
|
|
226
|
-
[menu
|
|
227
|
-
addItemWithTitle: @"Zoom"
|
|
228
|
-
action: @selector(performZoom:)
|
|
229
|
-
keyEquivalent: @""];
|
|
230
|
-
|
|
231
|
-
[menu addItem: [NSMenuItem separatorItem]];
|
|
232
|
-
|
|
233
|
-
[menu
|
|
234
|
-
addItemWithTitle: @"Bring All to Front"
|
|
235
|
-
action: @selector(arrangeInFront:)
|
|
236
|
-
keyEquivalent: @""];
|
|
237
|
-
|
|
238
|
-
NSMenuItem* item =
|
|
239
|
-
[parent addItemWithTitle: @"Window" action: nil keyEquivalent: @""];
|
|
240
|
-
[parent setSubmenu: menu forItem: item];
|
|
241
|
-
|
|
242
|
-
[NSApp setWindowsMenu: menu];
|
|
243
|
-
|
|
244
|
-
return YES;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
- (BOOL) setupMenu
|
|
248
|
-
{
|
|
249
|
-
if ([NSApp mainMenu]) return NO;
|
|
250
|
-
|
|
251
|
-
NSMenu* menu = [[[NSMenu alloc] initWithTitle: @"MainMenu"] autorelease];
|
|
252
|
-
|
|
253
|
-
if (
|
|
254
|
-
![self setupApplicationMenu: menu] ||
|
|
255
|
-
![self setupWindowMenu: menu])
|
|
256
|
-
{
|
|
257
|
-
return NO;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
[NSApp setMainMenu: menu];
|
|
261
|
-
|
|
262
|
-
return YES;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
214
|
@end// ReflexAppDelegate
|
data/src/osx/application.mm
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
#import <AppKit/NSApplication.h>
|
|
6
6
|
#include "reflex/exception.h"
|
|
7
7
|
#include "reflex/debug.h"
|
|
8
|
+
#include "menu.h"
|
|
9
|
+
#include "window.h"
|
|
10
|
+
#import "native_window.h"
|
|
8
11
|
#import "app_delegate.h"
|
|
9
12
|
|
|
10
13
|
|
|
@@ -33,6 +36,19 @@ namespace Reflex
|
|
|
33
36
|
return Application_get_data(const_cast<Application*>(app));
|
|
34
37
|
}
|
|
35
38
|
|
|
39
|
+
void
|
|
40
|
+
Application_set_menu (Application* app, Menu* menu)
|
|
41
|
+
{
|
|
42
|
+
for (auto it = app->window_begin(), end = app->window_end(); it != end; ++it)
|
|
43
|
+
{
|
|
44
|
+
Window* win = it->get();
|
|
45
|
+
if (win->menu() && Window_get_data(win).native.isMainWindow)
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Menu_apply_to_main_menu(menu);
|
|
50
|
+
}
|
|
51
|
+
|
|
36
52
|
|
|
37
53
|
ApplicationData::ApplicationData ()
|
|
38
54
|
: delegate(nil)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// -*- objc -*-
|
|
2
|
+
#include "reflex/clipboard.h"
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
#import <AppKit/NSPasteboard.h>
|
|
6
|
+
#include "reflex/exception.h"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
namespace Reflex
|
|
10
|
+
{
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
void
|
|
14
|
+
set_clipboard (const Clipboard& clipboard)
|
|
15
|
+
{
|
|
16
|
+
const char* text = clipboard.text();
|
|
17
|
+
NSString* nstext = nil;
|
|
18
|
+
if (text)
|
|
19
|
+
{
|
|
20
|
+
nstext = [NSString stringWithUTF8String: text];
|
|
21
|
+
if (!nstext)
|
|
22
|
+
argument_error(__FILE__, __LINE__);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
NSPasteboard* pasteboard = NSPasteboard.generalPasteboard;
|
|
26
|
+
[pasteboard clearContents];
|
|
27
|
+
|
|
28
|
+
if (nstext)
|
|
29
|
+
[pasteboard setString: nstext forType: NSPasteboardTypeString];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
Clipboard
|
|
33
|
+
get_clipboard ()
|
|
34
|
+
{
|
|
35
|
+
Clipboard clipboard;
|
|
36
|
+
|
|
37
|
+
NSString* nstext = [NSPasteboard.generalPasteboard stringForType: NSPasteboardTypeString];
|
|
38
|
+
const char* text = nstext ? nstext.UTF8String : NULL;
|
|
39
|
+
if (text) clipboard.set_text(text);
|
|
40
|
+
|
|
41
|
+
return clipboard;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
}// Reflex
|