#include <wx/wxprec.h>
#include <wx/wx.h>
#include "../include/wxdragon.h"
#include <wx/window.h>
#include <wx/editlbox.h>
#define TO_WX_EDITABLELB(x) ((wxEditableListBox*)(x))
wxd_Window_t* wxd_EditableListBox_New(wxd_Window_t* parent,
int id,
const char* label,
int x, int y,
int width, int height,
int64_t style) {
wxString wx_label = WXD_STR_TO_WX_STRING_UTF8_NULL_OK(label);
wxEditableListBox* editablelistbox = new wxEditableListBox(
(wxWindow*)parent,
id,
wx_label,
wxPoint(x, y),
wxSize(width, height),
style
);
return (wxd_Window_t*)editablelistbox;
}
char** wxd_EditableListBox_GetStrings(wxd_Window_t* self, int* count) {
if (!self) {
if (count) *count = 0;
return nullptr;
}
wxArrayString strings;
TO_WX_EDITABLELB(self)->GetStrings(strings);
if (count) *count = strings.GetCount();
if (strings.GetCount() == 0) {
return nullptr;
}
char** result = (char**)malloc(strings.GetCount() * sizeof(char*));
if (!result) {
if (count) *count = 0;
return nullptr;
}
for (size_t i = 0; i < strings.GetCount(); i++) {
wxString str = strings[i];
size_t len = str.ToUTF8().length() + 1;
char* buffer = (char*)malloc(len);
if (buffer) {
strcpy(buffer, str.ToUTF8());
result[i] = buffer;
} else {
result[i] = nullptr;
}
}
return result;
}
void wxd_EditableListBox_SetStrings(wxd_Window_t* self, const char** strings, int count) {
if (!self || !strings || count < 0) {
return;
}
wxArrayString wx_strings;
for (int i = 0; i < count; i++) {
if (strings[i]) {
wx_strings.Add(wxString::FromUTF8(strings[i]));
} else {
wx_strings.Add(wxString());
}
}
TO_WX_EDITABLELB(self)->SetStrings(wx_strings);
}
void wxd_EditableListBox_AddString(wxd_Window_t* self, const char* string) {
if (!self) {
return;
}
wxString wx_string = WXD_STR_TO_WX_STRING_UTF8_NULL_OK(string);
wxArrayString strings;
TO_WX_EDITABLELB(self)->GetStrings(strings);
strings.Add(wx_string);
TO_WX_EDITABLELB(self)->SetStrings(strings);
}
wxd_Window_t* wxd_EditableListBox_GetListCtrl(wxd_Window_t* self) {
if (!self) {
return NULL;
}
wxListCtrl* list_ctrl = TO_WX_EDITABLELB(self)->GetListCtrl();
return (wxd_Window_t*)list_ctrl;
}
wxd_ArrayString_t* wxd_EditableListBox_CopyStringsToArrayString(wxd_Window_t* self_ptr) {
if (!self_ptr) return nullptr;
wxEditableListBox* el = (wxEditableListBox*)self_ptr;
if (!el) return nullptr;
wxArrayString* result_array = new wxArrayString(); el->GetStrings(*result_array);
return (wxd_ArrayString_t*)result_array;
}