#include <wx/wxprec.h>
#include <wx/wx.h>
#include "wx/rearrangectrl.h"
#include "wx/window.h"
#include "wx/string.h"
#include "wx/arrstr.h"
#include "../include/wxdragon.h"
#include "../include/array_string.h"
#include "wxd_utils.h"
static void wxArrayIntToCArray(const wxArrayInt& wxArray, int* cArray, int arraySize) {
int size = wxMin(wxArray.GetCount(), static_cast<size_t>(arraySize));
for (int i = 0; i < size; ++i) {
cArray[i] = wxArray[i];
}
}
static wxArrayInt CArrayToWxArrayInt(const int* cArray, int arraySize) {
wxArrayInt wxArray;
for (int i = 0; i < arraySize; ++i) {
wxArray.Add(cArray[i]);
}
return wxArray;
}
extern "C" {
wxd_RearrangeList_t* wxd_RearrangeList_Create(
wxd_Window_t* parent,
wxd_Id id,
wxd_Point pos,
wxd_Size size,
const int* order,
int orderCount,
const char** items,
int itemsCount,
wxd_Style_t style
) {
wxWindow* wxParent = (wxWindow*)parent;
if (!wxParent) return nullptr;
wxArrayInt wxOrder = CArrayToWxArrayInt(order, orderCount);
wxArrayString wxItems;
for (int i = 0; i < itemsCount; ++i) {
if (items[i]) {
wxItems.Add(wxString::FromUTF8(items[i]));
}
}
wxRearrangeList* list = new wxRearrangeList(
wxParent,
id,
wxPoint(pos.x, pos.y),
wxSize(size.width, size.height),
wxOrder,
wxItems,
style
);
return (wxd_RearrangeList_t*)list;
}
void wxd_RearrangeList_GetCurrentOrder(
wxd_RearrangeList_t* self,
int* orderArray,
int arraySize
) {
wxRearrangeList* list = (wxRearrangeList*)self;
if (!list || !orderArray) return;
wxArrayIntToCArray(list->GetCurrentOrder(), orderArray, arraySize);
}
bool wxd_RearrangeList_MoveCurrentUp(wxd_RearrangeList_t* self) {
wxRearrangeList* list = (wxRearrangeList*)self;
if (!list) return false;
return list->MoveCurrentUp();
}
bool wxd_RearrangeList_MoveCurrentDown(wxd_RearrangeList_t* self) {
wxRearrangeList* list = (wxRearrangeList*)self;
if (!list) return false;
return list->MoveCurrentDown();
}
bool wxd_RearrangeList_CanMoveCurrentUp(wxd_RearrangeList_t* self) {
wxRearrangeList* list = (wxRearrangeList*)self;
if (!list) return false;
return list->CanMoveCurrentUp();
}
bool wxd_RearrangeList_CanMoveCurrentDown(wxd_RearrangeList_t* self) {
wxRearrangeList* list = (wxRearrangeList*)self;
if (!list) return false;
return list->CanMoveCurrentDown();
}
int wxd_RearrangeList_GetSelection(wxd_RearrangeList_t* self) {
wxRearrangeList* list = (wxRearrangeList*)self;
if (!list) return -1;
return list->GetSelection();
}
void wxd_RearrangeList_SetSelection(wxd_RearrangeList_t* self, int index, bool select) {
wxRearrangeList* list = (wxRearrangeList*)self;
if (!list) return;
list->SetSelection(index, select);
}
int wxd_RearrangeList_GetString(
wxd_RearrangeList_t* self,
int index,
char* buffer,
int bufferSize
) {
wxRearrangeList* list = (wxRearrangeList*)self;
if (!list || !buffer || bufferSize <= 0) return -1;
if (index < 0 || index >= static_cast<int>(list->GetCount())) {
return -1;
}
wxString item = list->GetString(index);
return wxd_cpp_utils::copy_wxstring_to_buffer(item, buffer, static_cast<size_t>(bufferSize));
}
unsigned int wxd_RearrangeList_GetCount(wxd_RearrangeList_t* self) {
wxRearrangeList* list = (wxRearrangeList*)self;
if (!list) return 0;
return list->GetCount();
}
bool wxd_RearrangeList_IsChecked(wxd_RearrangeList_t* self, int index) {
wxRearrangeList* list = (wxRearrangeList*)self;
if (!list) return false;
if (index < 0 || index >= static_cast<int>(list->GetCount())) {
return false;
}
wxArrayInt order = list->GetCurrentOrder();
for (size_t i = 0; i < order.GetCount(); ++i) {
int value = order[i];
if (value == index) {
return true; } else if (value == ~index) {
return false; }
}
return false; }
void wxd_RearrangeList_Check(wxd_RearrangeList_t* self, unsigned int index, bool check) {
wxRearrangeList* list = (wxRearrangeList*)self;
if (!list) {
return;
}
list->Check(index, check);
}
}