Sun, 17 Nov 2024 15:21:50 +0100
add public function for getting the UiContext UCX mempool
213 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2017 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 "pch.h" | |
30 | ||
31 | #include "icons.h" | |
373
2eede3d98aba
implement windows condvar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
218
diff
changeset
|
32 | #include "../ui/icons.h" |
213 | 33 | |
34 | #include <stdlib.h> | |
35 | #include <string.h> | |
36 | ||
215
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
37 | #include "util.h" |
213 | 38 | |
216
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
39 | #include <Windows.h> |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
40 | #include <Shellapi.h> |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
41 | |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
42 | |
213 | 43 | using namespace winrt; |
44 | using namespace Microsoft::UI::Xaml; | |
45 | using namespace Microsoft::UI::Xaml::Controls; | |
46 | using namespace Windows::UI::Xaml::Interop; | |
47 | using namespace winrt::Windows::Foundation; | |
48 | using namespace winrt::Microsoft::UI::Xaml::Controls::Primitives; | |
216
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
49 | using namespace winrt::Microsoft::UI::Xaml::Media::Imaging; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
50 | //using namespace Windows::Storage::Streams; |
213 | 51 | |
216
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
52 | static UiIcon* sys_folder_icon16; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
53 | static UiIcon* sys_file_icon16; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
54 | |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
55 | static UiIcon* sys_folder_icon32; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
56 | static UiIcon* sys_file_icon32; |
213 | 57 | |
58 | std::unordered_map<std::string, Symbol> ui_symbol_icons = { | |
59 | {"Accept", Symbol::Accept }, | |
60 | {"Account", Symbol::Account }, | |
61 | {"Add", Symbol::Add }, | |
62 | {"AddFriend", Symbol::AddFriend }, | |
63 | {"Admin", Symbol::Admin }, | |
64 | {"AlignCenter", Symbol::AlignCenter }, | |
65 | {"AlignLeft", Symbol::AlignLeft }, | |
66 | {"AlignRight", Symbol::AlignRight }, | |
67 | {"AllApps", Symbol::AllApps }, | |
68 | {"Attach", Symbol::Attach }, | |
69 | {"AttachCamera", Symbol::AttachCamera }, | |
70 | {"Audio", Symbol::Audio }, | |
71 | {"Back", Symbol::Back }, | |
72 | {"BackToWindow", Symbol::BackToWindow }, | |
73 | {"BlockContact", Symbol::BlockContact }, | |
74 | {"Bold", Symbol::Bold }, | |
75 | {"Bookmarks", Symbol::Bookmarks }, | |
76 | {"BrowsePhotos", Symbol::BrowsePhotos }, | |
77 | {"Bullets", Symbol::Bullets }, | |
78 | {"Calculator", Symbol::Calculator }, | |
79 | {"Calendar", Symbol::Calendar }, | |
80 | {"CalendarDay", Symbol::CalendarDay }, | |
81 | {"CalendarReply", Symbol::CalendarReply }, | |
82 | {"CalendarWeek", Symbol::CalendarWeek }, | |
83 | {"Camera", Symbol::Camera }, | |
84 | {"Cancel", Symbol::Cancel }, | |
85 | {"Caption", Symbol::Caption }, | |
86 | {"CellPhone", Symbol::CellPhone }, | |
87 | {"Character", Symbol::Character }, | |
88 | {"Clear", Symbol::Clear }, | |
89 | {"ClearSelection", Symbol::ClearSelection }, | |
90 | {"Clock", Symbol::Clock }, | |
91 | {"ClosedCaption", Symbol::ClosedCaption }, | |
92 | {"ClosePane", Symbol::ClosePane }, | |
93 | {"Comment", Symbol::Comment }, | |
94 | {"Contact", Symbol::Contact }, | |
95 | {"Contact2", Symbol::Contact2 }, | |
96 | {"ContactInfo", Symbol::ContactInfo }, | |
97 | {"ContactPresence", Symbol::ContactPresence }, | |
98 | {"Copy", Symbol::Copy }, | |
99 | {"Crop", Symbol::Crop }, | |
100 | {"Cut", Symbol::Cut }, | |
101 | {"Delete", Symbol::Delete }, | |
102 | {"Directions", Symbol::Directions }, | |
103 | {"DisableUpdates", Symbol::DisableUpdates }, | |
104 | {"DisconnectDrive", Symbol::DisconnectDrive }, | |
105 | {"Dislike", Symbol::Dislike }, | |
106 | {"DockBottom", Symbol::DockBottom }, | |
107 | {"DockLeft", Symbol::DockLeft }, | |
108 | {"DockRight", Symbol::DockRight }, | |
109 | {"Document", Symbol::Document }, | |
110 | {"Download", Symbol::Download }, | |
111 | {"Edit", Symbol::Edit }, | |
112 | {"Emoji", Symbol::Emoji }, | |
113 | {"Emoji2", Symbol::Emoji2 }, | |
114 | {"Favorite", Symbol::Favorite }, | |
115 | {"Filter", Symbol::Filter }, | |
116 | {"Find", Symbol::Find }, | |
117 | {"Flag", Symbol::Flag }, | |
118 | {"Folder", Symbol::Folder }, | |
119 | {"Font", Symbol::Font }, | |
120 | {"FontColor", Symbol::FontColor }, | |
121 | {"FontDecrease", Symbol::FontDecrease }, | |
122 | {"FontIncrease", Symbol::FontIncrease }, | |
123 | {"FontSize", Symbol::FontSize }, | |
124 | {"Forward", Symbol::Forward }, | |
125 | {"FourBars", Symbol::FourBars }, | |
126 | {"FullScreen", Symbol::FullScreen }, | |
127 | {"GlobalNavigationButton", Symbol::GlobalNavigationButton }, | |
128 | {"Globe", Symbol::Globe }, | |
129 | {"Go", Symbol::Go }, | |
130 | {"GoToStart", Symbol::GoToStart }, | |
131 | {"GoToToday", Symbol::GoToToday }, | |
132 | {"HangUp", Symbol::HangUp }, | |
133 | {"Help", Symbol::Help }, | |
134 | {"HideBcc", Symbol::HideBcc }, | |
135 | {"Highlight", Symbol::Highlight }, | |
136 | {"Home", Symbol::Home }, | |
137 | {"Import", Symbol::Import }, | |
138 | {"ImportAll", Symbol::ImportAll }, | |
139 | {"Important", Symbol::Important }, | |
140 | {"Italic", Symbol::Italic }, | |
141 | {"Keyboard", Symbol::Keyboard }, | |
142 | {"LeaveChat", Symbol::LeaveChat }, | |
143 | {"Library", Symbol::Library }, | |
144 | {"Like", Symbol::Like }, | |
145 | {"LikeDislike", Symbol::LikeDislike }, | |
146 | {"Link", Symbol::Link }, | |
147 | {"List", Symbol::List }, | |
148 | {"Mail", Symbol::Mail }, | |
149 | {"MailFilled", Symbol::MailFilled }, | |
150 | {"MailForward", Symbol::MailForward }, | |
151 | {"MailReply", Symbol::MailReply }, | |
152 | {"MailReplyAll", Symbol::MailReplyAll }, | |
153 | {"Manage", Symbol::Manage }, | |
154 | {"Map", Symbol::Map }, | |
155 | {"MapDrive", Symbol::MapDrive }, | |
156 | {"MapPin", Symbol::MapPin }, | |
157 | {"Memo", Symbol::Memo }, | |
158 | {"Message", Symbol::Message }, | |
159 | {"Microphone", Symbol::Microphone }, | |
160 | {"More", Symbol::More }, | |
161 | {"MoveToFolder", Symbol::MoveToFolder }, | |
162 | {"MusicInfo", Symbol::MusicInfo }, | |
163 | {"Mute", Symbol::Mute }, | |
164 | {"NewFolder", Symbol::NewFolder }, | |
165 | {"NewWindow", Symbol::NewWindow }, | |
166 | {"Next", Symbol::Next }, | |
167 | {"OneBar", Symbol::OneBar }, | |
168 | {"OpenFile", Symbol::OpenFile }, | |
169 | {"OpenLocal", Symbol::OpenLocal }, | |
170 | {"OpenPane", Symbol::OpenPane }, | |
171 | {"OpenWith", Symbol::OpenWith }, | |
172 | {"Orientation", Symbol::Orientation }, | |
173 | {"OtherUser", Symbol::OtherUser }, | |
174 | {"OutlineStar", Symbol::OutlineStar }, | |
175 | {"Page", Symbol::Page }, | |
176 | {"Page2", Symbol::Page2 }, | |
177 | {"Paste", Symbol::Paste }, | |
178 | {"Pause", Symbol::Pause }, | |
179 | {"People", Symbol::People }, | |
180 | {"Permissions", Symbol::Permissions }, | |
181 | {"Phone", Symbol::Phone }, | |
182 | {"PhoneBook", Symbol::PhoneBook }, | |
183 | {"Pictures", Symbol::Pictures }, | |
184 | {"Pin", Symbol::Pin }, | |
185 | {"Placeholder", Symbol::Placeholder }, | |
186 | {"Play", Symbol::Play }, | |
187 | {"PostUpdate", Symbol::PostUpdate }, | |
188 | {"Preview", Symbol::Preview }, | |
189 | {"PreviewLink", Symbol::PreviewLink }, | |
190 | {"Previous", Symbol::Previous }, | |
191 | {"Print", Symbol::Print }, | |
192 | {"Priority", Symbol::Priority }, | |
193 | {"ProtectedDocument", Symbol::ProtectedDocument }, | |
194 | {"Read", Symbol::Read }, | |
195 | {"Redo", Symbol::Redo }, | |
196 | {"Refresh", Symbol::Refresh }, | |
197 | {"Remote", Symbol::Remote }, | |
198 | {"Remove", Symbol::Remove }, | |
199 | {"Rename", Symbol::Rename }, | |
200 | {"Repair", Symbol::Repair }, | |
201 | {"RepeatAll", Symbol::RepeatAll }, | |
202 | {"RepeatOne", Symbol::RepeatOne }, | |
203 | {"ReportHacked", Symbol::ReportHacked }, | |
204 | {"ReShare", Symbol::ReShare }, | |
205 | {"Rotate", Symbol::Rotate }, | |
206 | {"RotateCamera", Symbol::RotateCamera }, | |
207 | {"Save", Symbol::Save }, | |
208 | {"SaveLocal", Symbol::SaveLocal }, | |
209 | {"Scan", Symbol::Scan }, | |
210 | {"SelectAll", Symbol::SelectAll }, | |
211 | {"Send", Symbol::Send }, | |
212 | {"SetLockScreen", Symbol::SetLockScreen }, | |
213 | {"SetTile", Symbol::SetTile }, | |
214 | {"Setting", Symbol::Setting }, | |
215 | {"Share", Symbol::Share }, | |
216 | {"Shop", Symbol::Shop }, | |
217 | {"ShowBcc", Symbol::ShowBcc }, | |
218 | {"ShowResults", Symbol::ShowResults }, | |
219 | {"Shuffle", Symbol::Shuffle }, | |
220 | {"SlideShow", Symbol::SlideShow }, | |
221 | {"SolidStar", Symbol::SolidStar }, | |
222 | {"Sort", Symbol::Sort }, | |
223 | {"Stop", Symbol::Stop }, | |
224 | {"StopSlideShow", Symbol::StopSlideShow }, | |
225 | {"Street", Symbol::Street }, | |
226 | {"Switch", Symbol::Switch }, | |
227 | {"SwitchApps", Symbol::SwitchApps }, | |
228 | {"Sync", Symbol::Sync }, | |
229 | {"SyncFolder", Symbol::SyncFolder }, | |
230 | {"Tag", Symbol::Tag }, | |
231 | {"Target", Symbol::Target }, | |
232 | {"ThreeBars", Symbol::ThreeBars }, | |
233 | {"TouchPointer", Symbol::TouchPointer }, | |
234 | {"Trim", Symbol::Trim }, | |
235 | {"TwoBars", Symbol::TwoBars }, | |
236 | {"TwoPage", Symbol::TwoPage }, | |
237 | {"Underline", Symbol::Underline }, | |
238 | {"Undo", Symbol::Undo }, | |
239 | {"UnFavorite", Symbol::UnFavorite }, | |
240 | {"UnPin", Symbol::UnPin }, | |
241 | {"UnSyncFolder", Symbol::UnSyncFolder }, | |
242 | {"Up", Symbol::Up }, | |
243 | {"Upload", Symbol::Upload }, | |
244 | {"Video", Symbol::Video }, | |
245 | {"VideoChat", Symbol::VideoChat }, | |
246 | {"View", Symbol::View }, | |
247 | {"ViewAll", Symbol::ViewAll }, | |
248 | {"Volume", Symbol::Volume }, | |
249 | {"WebCam", Symbol::WebCam }, | |
250 | {"World", Symbol::World }, | |
251 | {"XboxOneConsole", Symbol::XboxOneConsole }, | |
252 | {"ZeroBars", Symbol::ZeroBars }, | |
253 | {"Zoom", Symbol::Zoom }, | |
254 | {"ZoomIn", Symbol::ZoomIn }, | |
255 | {"ZoomOut", Symbol::ZoomOut } | |
256 | }; | |
257 | ||
258 | winrt::Microsoft::UI::Xaml::Controls::IconElement ui_get_icon(const char* name) { | |
259 | if (ui_symbol_icons.find(name) == ui_symbol_icons.end()) { | |
260 | SymbolIcon no_icon = { nullptr }; | |
261 | return no_icon; | |
262 | } | |
263 | ||
264 | Symbol symbol = ui_symbol_icons[name]; | |
265 | SymbolIcon icon = SymbolIcon(symbol); | |
266 | return icon; | |
267 | } | |
215
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
268 | |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
269 | |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
270 | // symbol icon implementation |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
271 | UiSymbolIcon::UiSymbolIcon(winrt::Microsoft::UI::Xaml::Controls::Symbol sym) { |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
272 | symbol = sym; |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
273 | } |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
274 | |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
275 | UiSymbolIcon::~UiSymbolIcon() { |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
276 | |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
277 | } |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
278 | |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
279 | winrt::Microsoft::UI::Xaml::Controls::IconElement UiSymbolIcon::getIcon() { |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
280 | return SymbolIcon(symbol); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
281 | } |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
282 | |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
283 | // image icon implementation |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
284 | UiImageIcon::UiImageIcon(const char* uristr) { |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
285 | wchar_t* wuri = str2wstr(uristr, nullptr); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
286 | Windows::Foundation::Uri uri{ wuri }; |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
287 | this->uri = uri; |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
288 | free(wuri); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
289 | } |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
290 | |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
291 | UiImageIcon::~UiImageIcon() { |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
292 | |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
293 | } |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
294 | |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
295 | winrt::Microsoft::UI::Xaml::Controls::IconElement UiImageIcon::getIcon() { |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
296 | BitmapIcon icon = BitmapIcon(); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
297 | icon.UriSource(uri); |
216
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
298 | ImageIcon img = ImageIcon(); |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
299 | img.Source(); |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
300 | return icon; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
301 | } |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
302 | |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
303 | // bitmap icon implementation |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
304 | UiBitmapIcon::UiBitmapIcon(winrt::Microsoft::UI::Xaml::Media::Imaging::BitmapSource bitmap) { |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
305 | this->bitmap = bitmap; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
306 | } |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
307 | |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
308 | UiBitmapIcon::~UiBitmapIcon() { |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
309 | |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
310 | } |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
311 | |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
312 | winrt::Microsoft::UI::Xaml::Controls::IconElement UiBitmapIcon::getIcon() { |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
313 | ImageIcon icon = ImageIcon(); |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
314 | icon.Source(bitmap); |
215
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
315 | return icon; |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
316 | } |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
317 | |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
318 | UIEXPORT UiIcon* ui_icon(const char* name, size_t size) { |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
319 | Symbol symbol = ui_symbol_icons[name]; |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
320 | UiSymbolIcon* icon = new UiSymbolIcon(symbol); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
321 | return icon; |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
322 | } |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
323 | |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
324 | |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
325 | UIEXPORT UiIcon* ui_imageicon(const char* file) { |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
326 | return new UiImageIcon(file); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
327 | } |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
328 | |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
329 | UIEXPORT void ui_icon_free(UiIcon* icon) { |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
330 | delete icon; |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
331 | } |
216
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
332 | |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
333 | |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
334 | struct __declspec(uuid("905a0fef-bc53-11df-8c49-001e4fc686da")) IBufferByteAccess : ::IUnknown |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
335 | { |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
336 | virtual HRESULT __stdcall Buffer(uint8_t** value) = 0; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
337 | }; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
338 | |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
339 | |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
340 | |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
341 | winrt::Microsoft::UI::Xaml::Media::Imaging::WriteableBitmap ui_dllicon2bitmap(const char* dll, int iconindex, bool large) { |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
342 | WriteableBitmap wbitmap = { nullptr }; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
343 | |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
344 | // get the icon from the dll |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
345 | HICON hicon_small; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
346 | HICON hicon_large; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
347 | if (ExtractIconExA(dll, iconindex, &hicon_large, &hicon_small, 1) > 0) { |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
348 | HICON hicon = large ? hicon_large : hicon_small; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
349 | |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
350 | // convert icon to (gdi) bitmap |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
351 | ICONINFO info; |
218
d06e7e8e53e1
implement table activate/selection events (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
352 | info.hbmColor = nullptr; |
d06e7e8e53e1
implement table activate/selection events (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
353 | info.hbmMask = nullptr; |
216
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
354 | if (GetIconInfo(hicon, &info)) { |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
355 | BITMAP bitmap; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
356 | if (GetObjectW(info.hbmColor, sizeof(BITMAP), &bitmap) != 0) { |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
357 | size_t bitmap_size = bitmap.bmWidthBytes * bitmap.bmHeight; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
358 | char *bitmap_data = (char*)malloc(bitmap_size); |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
359 | |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
360 | // get the pixel data |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
361 | if (GetBitmapBits(info.hbmColor, bitmap_size, bitmap_data) != 0) { |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
362 | WriteableBitmap wb = WriteableBitmap(bitmap.bmWidth, bitmap.bmHeight); |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
363 | void *wb_data = wb.PixelBuffer().data(); |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
364 | memcpy(wb_data, bitmap_data, bitmap_size); |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
365 | wbitmap = wb; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
366 | } |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
367 | free(bitmap_data); |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
368 | } |
218
d06e7e8e53e1
implement table activate/selection events (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
369 | if (info.hbmMask) { |
d06e7e8e53e1
implement table activate/selection events (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
370 | DeleteObject(info.hbmMask); |
d06e7e8e53e1
implement table activate/selection events (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
371 | } |
d06e7e8e53e1
implement table activate/selection events (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
372 | if (info.hbmColor) { |
d06e7e8e53e1
implement table activate/selection events (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
373 | DeleteObject(info.hbmColor); |
d06e7e8e53e1
implement table activate/selection events (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
374 | } |
216
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
375 | } |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
376 | |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
377 | DestroyIcon(hicon_small); |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
378 | DestroyIcon(hicon_large); |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
379 | } |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
380 | |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
381 | return wbitmap; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
382 | } |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
383 | |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
384 | UiIcon* ui_dllicon(const char* dll, int iconindex, bool large) { |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
385 | WriteableBitmap wbitmap = ui_dllicon2bitmap(dll, iconindex, large); |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
386 | return new UiBitmapIcon(wbitmap); |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
387 | } |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
388 | |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
389 | UIEXPORT UiIcon* ui_foldericon(size_t size) { |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
390 | bool large = true; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
391 | UiIcon** sys_folder_icon = &sys_folder_icon32; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
392 | if (size <= 24) { |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
393 | large = false; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
394 | sys_folder_icon = &sys_folder_icon16; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
395 | } |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
396 | |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
397 | if (*sys_folder_icon) { |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
398 | return *sys_folder_icon; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
399 | } |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
400 | |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
401 | UiIcon* icon = ui_dllicon("shell32.dll", 3, large); |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
402 | *sys_folder_icon = icon; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
403 | return icon; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
404 | } |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
405 | |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
406 | UIEXPORT UiIcon* ui_fileicon(size_t size) { |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
407 | bool large = true; |
217
b9798109c7d2
fix ui_fileicon (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
408 | UiIcon** sys_folder_icon = &sys_file_icon32; |
216
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
409 | if (size <= 24) { |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
410 | large = false; |
217
b9798109c7d2
fix ui_fileicon (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
411 | sys_folder_icon = &sys_file_icon16; |
216
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
412 | } |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
413 | |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
414 | if (*sys_folder_icon) { |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
415 | return *sys_folder_icon; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
416 | } |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
417 | |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
418 | UiIcon* icon = ui_dllicon("shell32.dll", 0, large); |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
419 | *sys_folder_icon = icon; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
420 | return icon; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
421 | } |