Sun, 29 Sep 2024 19:06:29 +0200
fix simple window (libadwaita)
78
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | // Dies ist die Haupt-DLL. |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | #include "stdafx.h" |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | #include <stdio.h> |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | #include "toolkit.h" |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | #using "UIcore.dll" |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | |
135
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
10 | static UIcallback startup_func; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
11 | void *startup_data; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
12 | static UIcallback open_func; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
13 | void *open_data; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
14 | static UIcallback exit_func; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
15 | void *exit_data; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
16 | |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
17 | public ref class AppCallbacks : public UI::IApplicationCallbacks { |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
18 | public: |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
19 | UIcallback startupFunc = NULL; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
20 | void *startupData = NULL; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
21 | UIcallback openFunc = NULL; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
22 | void *openData = NULL; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
23 | UIcallback exitFunc = NULL; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
24 | void *exitData = NULL; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
25 | |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
26 | virtual void __clrcall OnStartup() { |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
27 | if (startupFunc) { |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
28 | startupFunc(NULL, startupData); |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
29 | } |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
30 | } |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
31 | virtual void __clrcall OnOpen() { |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
32 | if (openFunc) { |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
33 | openFunc(NULL, openData); |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
34 | } |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
35 | } |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
36 | virtual void __clrcall OnExit() { |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
37 | if (exitFunc) { |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
38 | exitFunc(NULL, exitData); |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
39 | } |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
40 | } |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
41 | }; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
42 | |
78
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | void* ObjectToPtr(Object ^obj) { |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | GCHandle handle = GCHandle::Alloc(obj); |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | IntPtr pointer = GCHandle::ToIntPtr(handle); |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | return pointer.ToPointer(); |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | } |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | Object^ PtrToObject(void *ptr) { |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | GCHandle h = GCHandle::FromIntPtr(IntPtr(ptr)); |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | Object^ object = h.Target; |
137
c9b8b9e0cfe8
adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
53 | //h.Free(); |
78
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | return object; |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | } |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | |
81
5eb765a7a793
added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
78
diff
changeset
|
57 | // EventWrapper |
5eb765a7a793
added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
78
diff
changeset
|
58 | |
83
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
59 | ObjEventWrapper::ObjEventWrapper(UIcallback callback, void *eventdata) { |
81
5eb765a7a793
added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
78
diff
changeset
|
60 | this->callback = callback; |
83
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
61 | this->eventdata = eventdata; |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
62 | action = gcnew Action<IntPtr>(this, &ObjEventWrapper::Callback); |
81
5eb765a7a793
added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
78
diff
changeset
|
63 | } |
5eb765a7a793
added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
78
diff
changeset
|
64 | |
83
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
65 | Action<IntPtr>^ ObjEventWrapper::GetAction() { |
81
5eb765a7a793
added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
78
diff
changeset
|
66 | return action; |
5eb765a7a793
added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
78
diff
changeset
|
67 | } |
5eb765a7a793
added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
78
diff
changeset
|
68 | |
83
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
69 | void ObjEventWrapper::Callback(IntPtr uiobj) { |
82
0cdb8089a29f
added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
81
diff
changeset
|
70 | if (callback) { |
83
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
71 | callback(uiobj.ToPointer(), eventdata); |
82
0cdb8089a29f
added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
81
diff
changeset
|
72 | } |
81
5eb765a7a793
added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
78
diff
changeset
|
73 | } |
78
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | |
83
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
75 | |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
76 | EventWrapper::EventWrapper(UIcallback callback, void *eventdata) { |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
77 | this->callback = callback; |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
78 | this->eventdata = eventdata; |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
79 | } |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
80 | |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
81 | void EventWrapper::Callback(Object ^sender, RoutedEventArgs ^e) { |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
82 | if (callback) { |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
83 | callback(NULL, eventdata); |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
84 | } |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
85 | } |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
86 | |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
87 | |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
88 | |
78
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | UI_EXPORT void __stdcall UIinit(char *appname) { |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | UI::Application ^app = UI::Application::GetInstance(); |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | app->Name = gcnew String(appname); |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | } |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | |
135
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
94 | UI_EXPORT void __stdcall UIonstartup(UIcallback f, void *userdata) { |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
95 | startup_func = f; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
96 | startup_data = userdata; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
97 | } |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
98 | |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
99 | UI_EXPORT void __stdcall UIonopen(UIcallback f, void *userdata) { |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
100 | open_func = f; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
101 | open_data = userdata; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
102 | } |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
103 | |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
104 | UI_EXPORT void __stdcall UIonexit(UIcallback f, void *userdata) { |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
105 | exit_func = f; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
106 | exit_data = userdata; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
107 | } |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
108 | |
78
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | UI_EXPORT void __stdcall UImain() { |
135
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
110 | AppCallbacks ^ac = gcnew AppCallbacks(); |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
111 | ac->startupFunc = startup_func; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
112 | ac->startupData = startup_data; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
113 | ac->openFunc = open_func; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
114 | ac->openData = open_data; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
115 | ac->exitFunc = exit_func; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
116 | ac->exitData = exit_data; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
117 | |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
118 | UI::Application ^app = UI::Application::GetInstance(); |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
119 | app->callbacks = ac; |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
120 | |
b9dc9cdfa23a
refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
83
diff
changeset
|
121 | Thread ^thread = app->Start(); |
78
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | thread->Join(); |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | } |
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | |
83
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
125 | UI_EXPORT void __stdcall UIshow(gcroot<UI::MainWindow^> *window) { |
a38aec91bd66
added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
126 | (*window)->ShowWindow(); |
78
135920fe441b
added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | } |