This repository was archived by the owner on Jul 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathusciter.cpp
102 lines (76 loc) · 2.84 KB
/
usciter.cpp
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
#include "sciter-x-window.hpp"
#include "sciter-x-graphics.hpp"
#include "../sqlite/sciter-sqlite.h"
class uSciter: public sciter::window {
public:
uSciter() : window(SW_TITLEBAR | SW_RESIZEABLE | SW_CONTROLS | SW_MAIN | SW_GLASSY | SW_ENABLE_DEBUG) {}
int foo(int p) { return p + 42; }
//int bar(int p1, int p2) { return p1 + p2; }
//std::vector<int> vector() { return {1,2,3}; }
int get_windowHandle() {
return (int)(intptr_t)get_hwnd();
}
SOM_PASSPORT_BEGIN(uSciter)
SOM_FUNCS(
SOM_FUNC(foo),
//SOM_FUNC(bar),
//SOM_FUNC(vector),
)
SOM_PROPS(SOM_RO_VIRTUAL_PROP(windowHandle,get_windowHandle))
SOM_PASSPORT_END
/* sample of handling DOM events, click on <button#foo> here:
virtual bool handle_event(HELEMENT, BEHAVIOR_EVENT_PARAMS& params) {
sciter::dom::element target = params.heTarget;
switch (params.cmd) {
case BUTTON_CLICK:
if (target.test("button#foo")) {
target.set_html((const unsigned char*)"foo", 3);
return true;
}
}
return false;
}*/
};
#include "resources.cpp"
int uimain(std::function<int()> run ) {
// enable features to be used from script
SciterSetOption(NULL, SCITER_SET_SCRIPT_RUNTIME_FEATURES,
ALLOW_FILE_IO |
ALLOW_SOCKET_IO |
ALLOW_EVAL |
ALLOW_SYSINFO );
SciterSetGlobalAsset(new sqlite::SQLite()); // adding SQLite as a global namespace object
#ifdef _DEBUG
// sciter::debug_output_console console; //- uncomment it if you will need console window
#endif
sciter::archive::instance().open(aux::elements_of(resources)); // bind resources[] (defined in "resources.cpp") with the archive
sciter::om::hasset<uSciter> pwin = new uSciter();
// example, setting "usciter" media variable, check https://sciter.com/forums/topic/debugging-issues/
SciterSetMediaType(pwin->get_hwnd(), WSTR("desktop,usciter"));
bool loaded = false;
const std::vector<sciter::string>& argv = sciter::application::argv();
// usciter.exe -o file-to-open.htm
if (argv.size() > 1) {
sciter::string file_to_open;
for(int n = 1; n < int(argv.size()) - 1; ++n )
if( aux::chars_of(argv[n]) == const_wchars("-o") ) {
file_to_open = argv[n+1];
break;
}
if (file_to_open.length())
loaded = pwin->load(file_to_open.c_str());
}
if(!loaded)
// note: this:://app URL is dedicated to the sciter::archive content associated with the application
#if defined(WINDOWS)
pwin->load(WSTR("this://app/default-win.htm"));
#elif defined(OSX)
pwin->load(WSTR("this://app/default-osx.htm"));
#elif defined(LINUX)
pwin->load(WSTR("this://app/default-lnx.htm"));
#else // too many of them differnt
pwin->load(WSTR("this://app/default-else.htm"));
#endif // WINDOWS
pwin->expand();
return run();
}