ui/wpf/UIwrapper/UIwrapper/controls.cpp

Sun, 07 Apr 2024 12:36:07 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 07 Apr 2024 12:36:07 +0200
branch
newapi
changeset 278
a8faf8757450
parent 135
b9dc9cdfa23a
permissions
-rw-r--r--

implement ui_dialog_create (GTK)



#include "stdafx.h"
#include <stdio.h>

#include "controls.h"

#using "UIcore.dll"

/* ------------------------------ Buttons ------------------------------ */

UI_EXPORT void* __stdcall UIbutton(gcroot<UI::Container^> *container, char *label, UIcallback f, void *eventdata) {
	gcroot<Button^> *button = new gcroot<Button^>();

	EventWrapper ^evt = gcnew EventWrapper(f, eventdata);
	RoutedEventHandler ^handler = gcnew RoutedEventHandler(evt, &EventWrapper::Callback);

	*button = UI::Controls::Button(*container, gcnew String(label), handler);
	return button;
}


/* ------------------------------ Labels ------------------------------ */

UI_EXPORT void* __stdcall UIlabel(gcroot<UI::Container^> *container, char *label, int alignment) {
	gcroot<Label^> *control = new gcroot<Label^>();
	*control = UI::Controls::Label(*container, gcnew String(label), alignment);
	return control;
}

UI_EXPORT void* __stdcall UIspace(gcroot<UI::Container^> *container) {
	gcroot<Label^> *control = new gcroot<Label^>();
	*control = UI::Controls::Space(*container);
	return control;
}

UI_EXPORT void* __stdcall UIseparator(gcroot<UI::Container^> *container) {
	gcroot<Separator^> *control = new gcroot<Separator^>();
	*control = UI::Controls::Separator(*container);
	return control;
}



/* ------------------------------ Textarea ------------------------------ */

UI_EXPORT void* __stdcall UItextarea(gcroot<UI::Container^> *container, char *text) {
	String ^str = nullptr;
	if (text) {
		str = gcnew String(text);
	}
	
	gcroot<UI::TextArea^> *textarea = new gcroot<UI::TextArea^>();
	*textarea = gcnew UI::TextArea(*container, str, true);

	return textarea;
}

UI_EXPORT void  __stdcall UItextarea_set(gcroot<UI::TextArea^> *textarea, char *str) {
	(*textarea)->SetText(gcnew String(str));
}

UI_EXPORT char* __stdcall UItextarea_get(gcroot<UI::TextArea^> *textarea) {
	String ^str = (*textarea)->GetText();
	return (char*)(void*)Marshal::StringToHGlobalAnsi(str);
}

UI_EXPORT char* __stdcall UItextarea_getsubstr(gcroot<UI::TextArea^> *textarea, int begin, int end) {
	String ^str = (*textarea)->GetSubString(begin, end);
	return (char*)(void*)Marshal::StringToHGlobalAnsi(str);
}

UI_EXPORT void __stdcall UItextarea_insert(gcroot<UI::TextArea^> *textarea, int position, char *str) {
	// TODO
}

UI_EXPORT int __stdcall UItextarea_position(gcroot<UI::TextArea^> *textarea) {
	return (*textarea)->Position();
}

UI_EXPORT void __stdcall UItextarea_selection(gcroot<UI::TextArea^> *textarea, int *begin, int *end) {
	// TODO
}

UI_EXPORT int __stdcall UItextarea_length(gcroot<UI::TextArea^> *textarea) {
	return (*textarea)->Length();
}

UI_EXPORT void __stdcall UItextarea_remove(gcroot<UI::TextArea^> *textarea, int begin, int end) {
	// TODO
}

UI_EXPORT void __stdcall UIfreestr(char *str) {
	Marshal::FreeHGlobal((IntPtr)(void*)str);
}


/* ------------------------------ Textfield ------------------------------ */

UI_EXPORT void* __stdcall UItextfield(gcroot<UI::Container^> *container, char *text) {
	String ^str = nullptr;
	if (text) {
		str = gcnew String(text);
	}

	gcroot<UI::TextArea^> *textfield = new gcroot<UI::TextArea^>();
	*textfield = gcnew UI::TextArea(*container, str, false);

	return textfield;
}

mercurial