#include "../include/wxdragon.h"
#include "wxd_utils.h"
#include <wx/wx.h>
#include <wx/bmpcbox.h>
#include <wx/bitmap.h>
#include <wx/arrstr.h>
extern "C" {
WXD_EXPORTED wxd_BitmapComboBox_t* wxd_BitmapComboBox_Create(
wxd_Window_t* parent,
wxd_Id id,
const char* value,
wxd_Point pos,
wxd_Size size,
wxd_Style_t style
) {
wxWindow* parentWin = (wxWindow*)parent;
if (!parentWin) return nullptr;
wxString wxValue = wxString::FromUTF8(value ? value : "");
wxBitmapComboBox* combo = new wxBitmapComboBox(
parentWin,
id,
wxValue,
wxd_cpp_utils::to_wx(pos),
wxd_cpp_utils::to_wx(size),
wxArrayString(), style
);
return (wxd_BitmapComboBox_t*)combo;
}
WXD_EXPORTED void wxd_BitmapComboBox_Append(
wxd_BitmapComboBox_t* self,
const char* item,
wxd_Bitmap_t* bitmap ) {
wxBitmapComboBox* cb = (wxBitmapComboBox*)self;
if (!cb) return;
wxString wxItem = wxString::FromUTF8(item ? item : "");
wxBitmap* wxBmp = (wxBitmap*)bitmap;
if (wxBmp && wxBmp->IsOk()) {
cb->Append(wxItem, *wxBmp);
} else {
cb->Append(wxItem);
}
}
WXD_EXPORTED void wxd_BitmapComboBox_Clear(wxd_BitmapComboBox_t* self) {
wxBitmapComboBox* cb = (wxBitmapComboBox*)self;
if (cb) {
cb->Clear();
}
}
WXD_EXPORTED int wxd_BitmapComboBox_GetSelection(wxd_BitmapComboBox_t* self) {
wxBitmapComboBox* cb = (wxBitmapComboBox*)self;
if (!cb) return wxNOT_FOUND;
return cb->GetSelection();
}
WXD_EXPORTED void wxd_BitmapComboBox_SetSelection(wxd_BitmapComboBox_t* self, int index) {
wxBitmapComboBox* cb = (wxBitmapComboBox*)self;
if (cb) {
cb->SetSelection(index);
}
}
WXD_EXPORTED int wxd_BitmapComboBox_GetString(wxd_BitmapComboBox_t* self, int index, char* buffer, int buffer_len) {
wxBitmapComboBox* cb = (wxBitmapComboBox*)self;
if (!cb) return 0;
if (index < 0 || (unsigned int)index >= cb->GetCount()) {
if (buffer && buffer_len > 0) buffer[0] = '\0';
return 0;
}
wxString item = cb->GetString((unsigned int)index);
size_t needed_len_no_null = wxd_cpp_utils::copy_wxstring_to_buffer(item, buffer, (size_t)buffer_len);
return (int)(needed_len_no_null + 1);
}
WXD_EXPORTED unsigned int wxd_BitmapComboBox_GetCount(wxd_BitmapComboBox_t* self) {
wxBitmapComboBox* cb = (wxBitmapComboBox*)self;
if (!cb) return 0;
return cb->GetCount();
}
WXD_EXPORTED void wxd_BitmapComboBox_SetValue(wxd_BitmapComboBox_t* self, const char* value) {
wxBitmapComboBox* cb = (wxBitmapComboBox*)self;
if (cb) {
cb->SetValue(wxString::FromUTF8(value ? value : ""));
}
}
WXD_EXPORTED int wxd_BitmapComboBox_GetValue(wxd_BitmapComboBox_t* self, char* buffer, int buffer_len) {
wxBitmapComboBox* cb = (wxBitmapComboBox*)self;
if (!cb) {
if (buffer && buffer_len > 0) buffer[0] = '\0';
return 0;
}
wxString value = cb->GetValue();
size_t needed_len_no_null = wxd_cpp_utils::copy_wxstring_to_buffer(value, buffer, (size_t)buffer_len);
return (int)(needed_len_no_null + 1);
}
WXD_EXPORTED wxd_Bitmap_t* wxd_BitmapComboBox_GetItemBitmap(wxd_BitmapComboBox_t* self, unsigned int n) {
wxBitmapComboBox* cb = (wxBitmapComboBox*)self;
if (!cb || n >= cb->GetCount()) return nullptr;
wxBitmap bmp = cb->GetItemBitmap(n);
if (!bmp.IsOk()) return nullptr;
return (wxd_Bitmap_t*)new wxBitmap(bmp);
}
WXD_EXPORTED void wxd_BitmapComboBox_SetItemBitmap(wxd_BitmapComboBox_t* self, unsigned int n, wxd_Bitmap_t* bitmap) {
wxBitmapComboBox* cb = (wxBitmapComboBox*)self;
if (!cb || n >= cb->GetCount()) return;
wxBitmap* wxBmp = (wxBitmap*)bitmap;
cb->SetItemBitmap(n, (wxBmp && wxBmp->IsOk()) ? *wxBmp : wxNullBitmap);
}
}