libui/winforms/group.cpp

87 lines
1.7 KiB
C++
Raw Normal View History

2015-11-26 17:27:23 -06:00
// 18 november 2015
#include "uipriv_winforms.hpp"
2015-11-26 17:27:23 -06:00
struct uiGroup {
uiWindowsControl c;
2015-11-26 18:11:55 -06:00
gcroot<GroupBox ^> *groupbox;
2015-11-26 19:34:21 -06:00
uiControl *child;
2015-11-26 18:11:55 -06:00
int margined;
2015-11-26 17:27:23 -06:00
};
2015-11-26 19:34:21 -06:00
static void onDestroy(uiGroup *);
uiWindowsDefineControlWithOnDestroy(
2015-11-26 17:27:23 -06:00
uiGroup, // type name
uiGroupType, // type function
2015-11-26 19:34:21 -06:00
groupbox, // handle
onDestroy(hthis); // on destroy
2015-11-26 17:27:23 -06:00
)
2015-11-26 19:34:21 -06:00
static void onDestroy(uiGroup *g)
{
if (g->child != NULL) {
(*(g->groupbox))->Content = nullptr;
uiControlSetParent(g->child, NULL);
uiControlDestroy(g->child);
}
}
2015-11-26 17:27:23 -06:00
char *uiGroupTitle(uiGroup *g)
{
2015-11-26 18:11:55 -06:00
String ^text;
// TOOD bad cast?
text = (String ^) ((*(g->groupbox))->Header);
return uiWindowsCLRStringToText(text);
2015-11-26 17:27:23 -06:00
}
void uiGroupSetTitle(uiGroup *g, const char *title)
{
2015-11-26 18:11:55 -06:00
(*(g->groupbox))->Header = fromUTF8(title);
// TODO layout
2015-11-26 17:27:23 -06:00
}
void uiGroupSetChild(uiGroup *g, uiControl *c)
{
2015-11-26 19:34:21 -06:00
if (g->child != NULL) {
uiControlSetParent(g->child, NULL);
(*(g->groupbox))->Content = nullptr;
}
g->child = c;
if (g->child != NULL) {
(*(g->groupbox))->Content = genericHandle(g->child);
uiControlSetParent(g->child, uiControl(g));
}
2015-11-26 17:27:23 -06:00
}
int uiGroupMargined(uiGroup *g)
{
2015-11-26 18:11:55 -06:00
return g->margined;
2015-11-26 17:27:23 -06:00
}
void uiGroupSetMargined(uiGroup *g, int margined)
{
2015-11-26 19:34:21 -06:00
g->margined = margined;
// TODO Margin or Padding?
// TODO really this? or should we just use another Border?
if (g->margined)
(*(g->groupbox))->Padding = Thickness(10, 10, 10, 10);
else
(*(g->groupbox))->Padding = Thickness(0, 0, 0, 0);
2015-11-26 17:27:23 -06:00
}
uiGroup *uiNewGroup(const char *title)
{
uiGroup *g;
g = (uiGroup *) uiNewControl(uiGroupType());
2015-11-26 18:11:55 -06:00
g->groupbox = new gcroot<GroupBox ^>();
*(g->groupbox) = gcnew GroupBox();
(*(g->groupbox))->Header = fromUTF8(title);
2015-11-26 17:27:23 -06:00
2015-11-26 18:11:55 -06:00
uiWindowsFinishNewControl(g, uiGroup, groupbox);
2015-11-26 17:27:23 -06:00
return g;
}