#include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "wx/textctrl.h"
#include "wxdragon.h"
#include "wxd_utils.h"
extern "C" {
WXD_EXPORTED wxd_TextCtrl_t*
wxd_TextCtrl_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;
wxTextCtrl* ctrl = new wxTextCtrl(parentWin, id, wxString::FromUTF8(value ? value : ""),
wxd_cpp_utils::to_wx(pos), wxd_cpp_utils::to_wx(size), style);
return (wxd_TextCtrl_t*)ctrl;
}
WXD_EXPORTED void
wxd_TextCtrl_SetValue(wxd_TextCtrl_t* textCtrl, const char* value)
{
wxTextCtrl* ctrl = (wxTextCtrl*)textCtrl;
if (ctrl) {
ctrl->SetValue(wxString::FromUTF8(value ? value : ""));
}
}
WXD_EXPORTED int
wxd_TextCtrl_GetValue(wxd_TextCtrl_t* textCtrl, char* buffer, int buffer_len)
{
if (!textCtrl || !buffer || buffer_len <= 0)
return -1;
wxTextCtrl* ctrl = (wxTextCtrl*)textCtrl;
wxString value = ctrl->GetValue();
return wxd_cpp_utils::copy_wxstring_to_buffer(value, buffer, (size_t)buffer_len);
}
WXD_EXPORTED void
wxd_TextCtrl_AppendText(wxd_TextCtrl_t* textCtrl, const char* text)
{
wxTextCtrl* ctrl = (wxTextCtrl*)textCtrl;
if (ctrl && text) {
ctrl->AppendText(wxString::FromUTF8(text));
}
}
WXD_EXPORTED void
wxd_TextCtrl_Clear(wxd_TextCtrl_t* textCtrl)
{
wxTextCtrl* ctrl = (wxTextCtrl*)textCtrl;
if (ctrl) {
ctrl->Clear();
}
}
WXD_EXPORTED bool
wxd_TextCtrl_IsModified(wxd_TextCtrl_t* textCtrl)
{
wxTextCtrl* ctrl = (wxTextCtrl*)textCtrl;
if (!ctrl)
return false;
return ctrl->IsModified();
}
WXD_EXPORTED void
wxd_TextCtrl_SetModified(wxd_TextCtrl_t* textCtrl, bool modified)
{
wxTextCtrl* ctrl = (wxTextCtrl*)textCtrl;
if (ctrl) {
ctrl->SetModified(modified);
}
}
WXD_EXPORTED void
wxd_TextCtrl_SetEditable(wxd_TextCtrl_t* textCtrl, bool editable)
{
wxTextCtrl* ctrl = (wxTextCtrl*)textCtrl;
if (ctrl) {
ctrl->SetEditable(editable);
}
}
WXD_EXPORTED bool
wxd_TextCtrl_IsEditable(wxd_TextCtrl_t* textCtrl)
{
wxTextCtrl* ctrl = (wxTextCtrl*)textCtrl;
if (!ctrl)
return false;
return ctrl->IsEditable();
}
WXD_EXPORTED wxd_Long_t
wxd_TextCtrl_GetInsertionPoint(wxd_TextCtrl_t* textCtrl)
{
wxTextCtrl* ctrl = (wxTextCtrl*)textCtrl;
if (!ctrl)
return 0;
return ctrl->GetInsertionPoint();
}
WXD_EXPORTED void
wxd_TextCtrl_SetInsertionPoint(wxd_TextCtrl_t* textCtrl, wxd_Long_t pos)
{
wxTextCtrl* ctrl = (wxTextCtrl*)textCtrl;
if (ctrl) {
ctrl->SetInsertionPoint(pos);
}
}
WXD_EXPORTED void
wxd_TextCtrl_SetMaxLength(wxd_TextCtrl_t* textCtrl, wxd_Long_t len)
{
wxTextCtrl* ctrl = (wxTextCtrl*)textCtrl;
if (ctrl) {
ctrl->SetMaxLength(len);
}
}
WXD_EXPORTED wxd_Long_t
wxd_TextCtrl_GetLastPosition(wxd_TextCtrl_t* textCtrl)
{
wxTextCtrl* ctrl = (wxTextCtrl*)textCtrl;
if (!ctrl)
return 0;
return ctrl->GetLastPosition();
}
WXD_EXPORTED bool
wxd_TextCtrl_IsMultiLine(wxd_TextCtrl_t* textCtrl)
{
wxTextCtrl* ctrl = (wxTextCtrl*)textCtrl;
if (!ctrl)
return false;
return ctrl->IsMultiLine();
}
WXD_EXPORTED bool
wxd_TextCtrl_IsSingleLine(wxd_TextCtrl_t* textCtrl)
{
wxTextCtrl* ctrl = (wxTextCtrl*)textCtrl;
if (!ctrl)
return false;
return ctrl->IsSingleLine();
}
WXD_EXPORTED void
wxd_TextCtrl_SetSelection(wxd_TextCtrl_t* textCtrl, wxd_Long_t from, wxd_Long_t to)
{
wxTextCtrl* ctrl = (wxTextCtrl*)textCtrl;
if (ctrl) {
ctrl->SetSelection(from, to);
}
}
WXD_EXPORTED void
wxd_TextCtrl_GetSelection(wxd_TextCtrl_t* textCtrl, wxd_Long_t* from, wxd_Long_t* to)
{
wxTextCtrl* ctrl = (wxTextCtrl*)textCtrl;
if (ctrl && from && to) {
long from_long, to_long;
ctrl->GetSelection(&from_long, &to_long);
*from = static_cast<wxd_Long_t>(from_long);
*to = static_cast<wxd_Long_t>(to_long);
}
}
WXD_EXPORTED void
wxd_TextCtrl_SelectAll(wxd_TextCtrl_t* textCtrl)
{
wxTextCtrl* ctrl = (wxTextCtrl*)textCtrl;
if (ctrl) {
ctrl->SelectAll();
}
}
WXD_EXPORTED int
wxd_TextCtrl_GetStringSelection(wxd_TextCtrl_t* textCtrl, char* buffer, int buffer_len)
{
if (!textCtrl || !buffer || buffer_len <= 0)
return -1;
wxTextCtrl* ctrl = (wxTextCtrl*)textCtrl;
wxString selection = ctrl->GetStringSelection();
return wxd_cpp_utils::copy_wxstring_to_buffer(selection, buffer, (size_t)buffer_len);
}
WXD_EXPORTED void
wxd_TextCtrl_SetInsertionPointEnd(wxd_TextCtrl_t* textCtrl)
{
wxTextCtrl* ctrl = reinterpret_cast<wxTextCtrl*>(textCtrl);
if (ctrl) {
ctrl->SetInsertionPointEnd();
}
}
}