Skip to content

Commit 6b5483f

Browse files
committed
Remove system icon support from Image API
Eliminated the ability to create images from platform-specific system icons across all platforms. Removed related methods, documentation, and C API functions. This simplifies the image API and reduces platform-specific code.
1 parent 0329088 commit 6b5483f

File tree

10 files changed

+18
-193
lines changed

10 files changed

+18
-193
lines changed

examples/tray_icon_example/main.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ int main() {
4646
trayIcon->SetTitle("Test App");
4747
trayIcon->SetTooltip("This is a test tray icon");
4848

49-
// Try to set a system icon (using a system-provided icon)
50-
auto icon = nativeapi::Image::FromSystemIcon("NSImageNameStatusAvailable");
51-
trayIcon->SetIcon(icon);
52-
5349
// Set up event listeners
5450
trayIcon->AddListener<TrayIconClickedEvent>(
5551
[](const TrayIconClickedEvent& event) {
@@ -180,4 +176,4 @@ int main() {
180176
// Cleanup
181177
delete should_exit;
182178
return 0;
183-
}
179+
}

src/capi/image_c.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,6 @@ native_image_t native_image_from_base64(const char* base64_data) {
4848
return nullptr;
4949
}
5050

51-
// Create an image from a platform-specific system icon
52-
native_image_t native_image_from_system_icon(const char* icon_name) {
53-
if (!icon_name) {
54-
return nullptr;
55-
}
56-
57-
try {
58-
auto image = Image::FromSystemIcon(icon_name);
59-
if (image) {
60-
auto size = image->GetSize();
61-
if (size.width > 0 && size.height > 0) {
62-
return new std::shared_ptr<Image>(image);
63-
}
64-
}
65-
} catch (...) {
66-
// Handle exceptions
67-
}
68-
69-
return nullptr;
70-
}
71-
7251
// Destroy an image and release its resources
7352
void native_image_destroy(native_image_t image) {
7453
if (image) {

src/capi/image_c.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,6 @@ native_image_t native_image_from_file(const char* file_path);
4141
FFI_PLUGIN_EXPORT
4242
native_image_t native_image_from_base64(const char* base64_data);
4343

44-
/**
45-
* Create an image from a platform-specific system icon
46-
* @param icon_name Platform-specific system icon name/identifier
47-
* @return Image handle, or NULL if icon not found
48-
*/
49-
FFI_PLUGIN_EXPORT
50-
native_image_t native_image_from_system_icon(const char* icon_name);
51-
5244
/**
5345
* Destroy an image and release its resources
5446
* @param image The image to destroy

src/image.h

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ namespace nativeapi {
2222
* Features:
2323
* - Load images from file paths
2424
* - Load images from base64-encoded strings
25-
* - Platform-specific system icon support
2625
* - Automatic format detection and conversion
2726
* - Memory-efficient internal representation
2827
*
2928
* @note This class uses the PIMPL idiom to hide platform-specific
3029
* implementation details and ensure binary compatibility.
3130
*
3231
* @note All Image instances must be created using static factory methods
33-
* (FromFile, FromBase64, FromSystemIcon). Empty/null images are represented
32+
* (FromFile, FromBase64). Empty/null images are represented
3433
* using std::shared_ptr<Image>{nullptr}.
3534
*
3635
* @note Assignment operations are not supported to avoid resource management
@@ -146,31 +145,6 @@ class Image : public NativeObjectProvider {
146145
*/
147146
static std::shared_ptr<Image> FromBase64(const std::string& base64_data);
148147

149-
/**
150-
* @brief Create an image from a platform-specific system icon.
151-
*
152-
* Creates an image using a system-provided icon identifier. The available
153-
* icons and their identifiers are platform-specific.
154-
*
155-
* @param icon_name Platform-specific system icon name/identifier
156-
* @return A shared pointer to the created Image, or nullptr if icon not found
157-
*
158-
* @note System icon names vary by platform:
159-
* - macOS: NSImage names (e.g., "NSApplicationIcon", "NSFolder")
160-
* - Windows: System icon IDs (e.g., "IDI_APPLICATION", "IDI_WARNING")
161-
* - Linux: FreeDesktop icon names (e.g., "application-exit", "folder")
162-
*
163-
* @example
164-
* ```cpp
165-
* // macOS
166-
* auto image = Image::FromSystemIcon("NSApplicationIcon");
167-
*
168-
* // Cross-platform generic names (if supported)
169-
* auto warningIcon = Image::FromSystemIcon("warning");
170-
* ```
171-
*/
172-
static std::shared_ptr<Image> FromSystemIcon(const std::string& icon_name);
173-
174148
/**
175149
* @brief Get the size of the image in pixels.
176150
*

src/platform/linux/image_linux.cpp

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -178,49 +178,6 @@ std::shared_ptr<Image> Image::FromBase64(const std::string& base64_data) {
178178
return image;
179179
}
180180

181-
std::shared_ptr<Image> Image::FromSystemIcon(const std::string& icon_name) {
182-
auto image = std::shared_ptr<Image>(new Image());
183-
184-
// Try to load icon from the current icon theme
185-
GtkIconTheme* icon_theme = gtk_icon_theme_get_default();
186-
if (!icon_theme) {
187-
return nullptr;
188-
}
189-
190-
// Try to load icon at default size (48x48)
191-
GtkIconInfo* icon_info = gtk_icon_theme_lookup_icon(
192-
icon_theme, icon_name.c_str(), 48, GTK_ICON_LOOKUP_FORCE_SIZE);
193-
194-
if (icon_info) {
195-
GError* error = nullptr;
196-
GdkPixbuf* pixbuf = gtk_icon_info_load_icon(icon_info, &error);
197-
198-
if (pixbuf) {
199-
image->pimpl_->pixbuf_ = pixbuf;
200-
image->pimpl_->source_ = icon_name;
201-
202-
// Get actual image size
203-
int width = gdk_pixbuf_get_width(pixbuf);
204-
int height = gdk_pixbuf_get_height(pixbuf);
205-
image->pimpl_->size_ = {static_cast<double>(width),
206-
static_cast<double>(height)};
207-
image->pimpl_->format_ = "System";
208-
} else {
209-
if (error) {
210-
g_error_free(error);
211-
}
212-
g_object_unref(icon_info);
213-
return nullptr;
214-
}
215-
216-
g_object_unref(icon_info);
217-
} else {
218-
return nullptr;
219-
}
220-
221-
return image;
222-
}
223-
224181
Size Image::GetSize() const {
225182
return pimpl_->size_;
226183
}

src/platform/macos/image_macos.mm

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -127,27 +127,6 @@
127127
return image;
128128
}
129129

130-
std::shared_ptr<Image> Image::FromSystemIcon(const std::string& icon_name) {
131-
auto image = std::shared_ptr<Image>(new Image());
132-
133-
NSString* nsIconName = [NSString stringWithUTF8String:icon_name.c_str()];
134-
NSImage* nsImage = [NSImage imageWithSystemSymbolName:nsIconName accessibilityDescription:nil];
135-
136-
if (nsImage) {
137-
image->pimpl_->ns_image_ = [nsImage copy];
138-
image->pimpl_->source_ = icon_name;
139-
140-
// Get actual image size
141-
NSSize nsSize = [nsImage size];
142-
image->pimpl_->size_ = {static_cast<double>(nsSize.width), static_cast<double>(nsSize.height)};
143-
image->pimpl_->format_ = "System";
144-
} else {
145-
return nullptr;
146-
}
147-
148-
return image;
149-
}
150-
151130
Size Image::GetSize() const {
152131
return pimpl_->size_;
153132
}

src/platform/windows/image_windows.cpp

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -260,55 +260,6 @@ std::shared_ptr<Image> Image::FromBase64(const std::string& base64_data) {
260260
return image;
261261
}
262262

263-
std::shared_ptr<Image> Image::FromSystemIcon(const std::string& icon_name) {
264-
EnsureGdiplusInitialized();
265-
auto image = std::shared_ptr<Image>(new Image());
266-
267-
HICON hIcon = nullptr;
268-
269-
// Try to load predefined system icons
270-
if (icon_name == "IDI_APPLICATION" || icon_name == "application") {
271-
hIcon = LoadIcon(NULL, IDI_APPLICATION);
272-
} else if (icon_name == "IDI_ERROR" || icon_name == "error") {
273-
hIcon = LoadIcon(NULL, IDI_ERROR);
274-
} else if (icon_name == "IDI_QUESTION" || icon_name == "question") {
275-
hIcon = LoadIcon(NULL, IDI_QUESTION);
276-
} else if (icon_name == "IDI_WARNING" || icon_name == "warning") {
277-
hIcon = LoadIcon(NULL, IDI_WARNING);
278-
} else if (icon_name == "IDI_INFORMATION" || icon_name == "information") {
279-
hIcon = LoadIcon(NULL, IDI_INFORMATION);
280-
} else if (icon_name == "IDI_WINLOGO" || icon_name == "winlogo") {
281-
hIcon = LoadIcon(NULL, IDI_WINLOGO);
282-
} else if (icon_name == "IDI_SHIELD" || icon_name == "shield") {
283-
hIcon = LoadIcon(NULL, IDI_SHIELD);
284-
}
285-
286-
if (hIcon) {
287-
Gdiplus::Bitmap* bitmap = Gdiplus::Bitmap::FromHICON(hIcon);
288-
289-
if (bitmap && bitmap->GetLastStatus() == Gdiplus::Ok) {
290-
image->pimpl_->bitmap_ = bitmap;
291-
image->pimpl_->source_ = icon_name;
292-
293-
// Get actual image size
294-
UINT width = bitmap->GetWidth();
295-
UINT height = bitmap->GetHeight();
296-
image->pimpl_->size_ = {static_cast<double>(width),
297-
static_cast<double>(height)};
298-
image->pimpl_->format_ = "System";
299-
} else {
300-
if (bitmap) {
301-
delete bitmap;
302-
}
303-
return nullptr;
304-
}
305-
} else {
306-
return nullptr;
307-
}
308-
309-
return image;
310-
}
311-
312263
Size Image::GetSize() const {
313264
return pimpl_->size_;
314265
}

src/platform/windows/menu_windows.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include <windows.h>
2+
#include <iostream>
23
#include <memory>
34
#include <optional>
45
#include <vector>
5-
#include <iostream>
66
#include "../../foundation/id_allocator.h"
77
#include "../../image.h"
88
#include "../../menu.h"
@@ -93,7 +93,6 @@ HWND GetMainWindowForCurrentThread() {
9393
// First try to get the foreground window
9494
HWND hwnd = nullptr;
9595

96-
9796
// Use EnumWindows to find the main window
9897
struct EnumData {
9998
HWND main_window;

src/platform/windows/tray_icon_windows.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,12 @@ class TrayIcon::Impl {
3333
using RightClickedCallback = std::function<void(TrayIconId)>;
3434
using DoubleClickedCallback = std::function<void(TrayIconId)>;
3535

36-
Impl()
37-
: hwnd_(nullptr),
38-
icon_handle_(nullptr),
39-
owns_window_(false) {
36+
Impl() : hwnd_(nullptr), icon_handle_(nullptr), owns_window_(false) {
4037
tray_icon_id_ = IdAllocator::Allocate<TrayIcon>();
4138
}
4239

43-
Impl(HWND hwnd, bool owns_window,
40+
Impl(HWND hwnd,
41+
bool owns_window,
4442
ClickedCallback clicked_callback,
4543
RightClickedCallback right_clicked_callback,
4644
DoubleClickedCallback double_clicked_callback)
@@ -85,17 +83,18 @@ class TrayIcon::Impl {
8583
UINT message,
8684
WPARAM wparam,
8785
LPARAM lparam) {
88-
if (message == WM_USER + 1 && wparam == static_cast<WPARAM>(tray_icon_id_)) {
86+
if (message == WM_USER + 1 &&
87+
wparam == static_cast<WPARAM>(tray_icon_id_)) {
8988
if (lparam == WM_LBUTTONUP) {
90-
std::cout << "TrayIcon: Left button clicked, tray_icon_id = " << tray_icon_id_
91-
<< std::endl;
89+
std::cout << "TrayIcon: Left button clicked, tray_icon_id = "
90+
<< tray_icon_id_ << std::endl;
9291
// Call clicked callback
9392
if (clicked_callback_) {
9493
clicked_callback_(tray_icon_id_);
9594
}
9695
} else if (lparam == WM_RBUTTONUP) {
97-
std::cout << "TrayIcon: Right button clicked, tray_icon_id = " << tray_icon_id_
98-
<< std::endl;
96+
std::cout << "TrayIcon: Right button clicked, tray_icon_id = "
97+
<< tray_icon_id_ << std::endl;
9998
// Call right clicked callback
10099
if (right_clicked_callback_) {
101100
right_clicked_callback_(tray_icon_id_);
@@ -173,7 +172,8 @@ TrayIcon::TrayIcon(void* native_tray_icon) {
173172
} else {
174173
// Wrap existing native tray icon
175174
// In a real implementation, you'd extract HWND from the tray parameter
176-
// For now, this is mainly used by TrayManager for creating uninitialized icons
175+
// For now, this is mainly used by TrayManager for creating uninitialized
176+
// icons
177177
}
178178

179179
// Initialize the Impl with the window handle
@@ -192,10 +192,9 @@ TrayIcon::TrayIcon(void* native_tray_icon) {
192192
this->Emit<TrayIconDoubleClickedEvent>(id);
193193
};
194194

195-
pimpl_ = std::make_unique<Impl>(hwnd, owns_window,
196-
std::move(clicked_callback),
197-
std::move(right_clicked_callback),
198-
std::move(double_clicked_callback));
195+
pimpl_ = std::make_unique<Impl>(
196+
hwnd, owns_window, std::move(clicked_callback),
197+
std::move(right_clicked_callback), std::move(double_clicked_callback));
199198
} else {
200199
// Failed to create window, create uninitialized Impl
201200
pimpl_ = std::make_unique<Impl>();

src/tray_icon_event.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ class TrayIconEvent : public Event {
2828
*/
2929
class TrayIconClickedEvent : public TrayIconEvent {
3030
public:
31-
TrayIconClickedEvent(TrayIconId tray_icon_id)
32-
: tray_icon_id_(tray_icon_id) {}
31+
TrayIconClickedEvent(TrayIconId tray_icon_id) : tray_icon_id_(tray_icon_id) {}
3332

3433
TrayIconId GetTrayIconId() const { return tray_icon_id_; }
3534

0 commit comments

Comments
 (0)