Started migrating this experiment from WPF to WinForms. Maybe this will be more featureful.

This commit is contained in:
Pietro Gagliardi 2015-11-27 10:05:13 -05:00
parent 60becb332e
commit 284c96a72a
32 changed files with 80 additions and 86 deletions

View File

@ -1,5 +1,5 @@
// 26 november 2015
#include "uipriv_wpf.hpp"
#include "uipriv_winforms.hpp"
struct uiArea {
uiWindowsControl c;

View File

@ -1,5 +1,5 @@
// 26 november 2015
#include "uipriv_wpf.hpp"
#include "uipriv_winforms.hpp"
using namespace System::Collections::Generic;

View File

@ -1,5 +1,5 @@
// 25 november 2015
#include "uipriv_wpf.hpp"
#include "uipriv_winforms.hpp"
struct uiButton {
uiWindowsControl c;

View File

@ -1,5 +1,5 @@
// 26 november 2015
#include "uipriv_wpf.hpp"
#include "uipriv_winforms.hpp"
struct uiCheckbox {
uiWindowsControl c;

View File

@ -1,5 +1,5 @@
// 26 november 2015
#include "uipriv_wpf.hpp"
#include "uipriv_winforms.hpp"
struct uiCombobox {
uiWindowsControl c;

View File

@ -1,5 +1,5 @@
// 16 august 2015
#include "uipriv_wpf.hpp"
#include "uipriv_winforms.hpp"
static uintmax_t type_uiWindowsControl = 0;
@ -10,11 +10,11 @@ uintmax_t uiWindowsControlType(void)
return type_uiWindowsControl;
}
UIElement ^genericHandle(uiControl *c)
Control ^genericHandle(uiControl *c)
{
gcroot<UIElement ^> *h;
gcroot<Control ^> *h;
h = (gcroot<UIElement ^> *) uiControlHandle(c);
h = (gcroot<Control ^> *) uiControlHandle(c);
return *h;
}

View File

@ -1,5 +1,5 @@
// 26 november 2015
#include "uipriv_wpf.hpp"
#include "uipriv_winforms.hpp"
// TODO TODO TODO AVAILABLE SINCE 4.0 TODO TODO TODO

View File

@ -1,5 +1,5 @@
// 19 november 2015
#include "uipriv_wpf.hpp"
#include "uipriv_winforms.hpp"
uiDrawPath *uiDrawNewPath(uiDrawFillMode fillMode)
{

View File

@ -1,5 +1,5 @@
// 26 november 2015
#include "uipriv_wpf.hpp"
#include "uipriv_winforms.hpp"
struct uiEntry {
uiWindowsControl c;

View File

@ -1,5 +1,5 @@
// 18 november 2015
#include "uipriv_wpf.hpp"
#include "uipriv_winforms.hpp"
struct uiGroup {
uiWindowsControl c;

View File

@ -1,5 +1,5 @@
// 26 november 2015
#include "uipriv_wpf.hpp"
#include "uipriv_winforms.hpp"
// TODO alignment
// TODO lots of padding

26
winforms/main.cpp Normal file
View File

@ -0,0 +1,26 @@
// 25 november 2015
#include "uipriv_winforms.hpp"
void initWinForms(void)
{
// TODO anything else?
// TODO return value
// TODO needed?
// Application::EnableVisualStyles();
}
void uninitWinForms(void)
{
// TODO
}
void uiMain(void)
{
Application::Run();
}
void uiQuit(void)
{
// TODO does this run later?
Application::Exit();
}

View File

@ -1,5 +1,5 @@
// 19 november 2015
#include "uipriv_wpf.hpp"
#include "uipriv_winforms.hpp"
void uiMenuItemEnable(uiMenuItem *m)
{

View File

@ -1,5 +1,5 @@
// 26 november 2015
#include "uipriv_wpf.hpp"
#include "uipriv_winforms.hpp"
struct uiProgressBar {
uiWindowsControl c;

View File

@ -1,5 +1,5 @@
// 26 november 2015
#include "uipriv_wpf.hpp"
#include "uipriv_winforms.hpp"
struct uiRadioButtons {
uiWindowsControl c;

View File

@ -1,5 +1,5 @@
// 18 november 2015
#include "uipriv_wpf.hpp"
#include "uipriv_winforms.hpp"
struct uiSeparator {
uiWindowsControl c;

View File

@ -1,5 +1,5 @@
// 18 november 2015
#include "uipriv_wpf.hpp"
#include "uipriv_winforms.hpp"
struct uiSlider {
uiWindowsControl c;

View File

@ -1,5 +1,5 @@
// 18 november 2015
#include "uipriv_wpf.hpp"
#include "uipriv_winforms.hpp"
struct uiSpinbox {
uiWindowsControl c;

View File

@ -1,5 +1,5 @@
// 26 june 2015
#include "uipriv_wpf.hpp"
#include "uipriv_winforms.hpp"
char *uiOpenFile(void)
{

View File

@ -1,5 +1,5 @@
// 26 november 2015
#include "uipriv_wpf.hpp"
#include "uipriv_winforms.hpp"
// TODO save child alignments?
// TODO scroll tabs instead of multiline tabs

View File

@ -1,5 +1,5 @@
// 25 november 2015
#include "uipriv_wpf.hpp"
#include "uipriv_winforms.hpp"
#include <string.h>
using namespace System::Text;

View File

@ -8,7 +8,7 @@ This file assumes that you have included <vccrt.h> and "ui.h" beforehand, as wel
#define __LIBUI_UI_WINDOWS_H__
#ifndef __cplusplus_cli
#error Sorry; ui_wpf.hpp can currently only be used from C++/CLI code.
#error Sorry; ui_winforms.hpp can currently only be used from C++/CLI code.
#endif
extern "C" {

View File

@ -1,24 +1,20 @@
// 25 november 2015
#include <vcclr.h>
#include "../ui.h"
#include "ui_wpf.hpp"
#include "ui_winforms.hpp"
#include "../common/uipriv.h"
#include "unmanaged.h"
#using <System.dll>
#using <WindowsBase.dll>
#using <PresentationCore.dll>
#using <PresentationFramework.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::ComponentModel;
using namespace System::Windows;
using namespace System::Windows::Controls;
using namespace System::Windows::Forms;
// text.cpp
extern String ^fromUTF8(const char *);
// control.cpp
extern UIElement ^genericHandle(uiControl *c);
extern Control ^genericHandle(uiControl *c);
typedef gcroot<Label ^> *DUMMY;
static inline DUMMY mkdummy(String ^classname)

View File

@ -8,8 +8,8 @@ extern "C" {
#endif
// main.cpp
extern void initWPF(void);
extern void uninitWPF(void);
extern void initWinForms(void);
extern void uninitWinForms(void);
// alloc.c
extern int initAlloc(void);

View File

@ -1,26 +1,24 @@
// 25 november 2015
#include "uipriv_wpf.hpp"
#include "uipriv_winforms.hpp"
// TODO save alignment of children?
ref class libuiWindow : public Window {
ref class libuiForm : public Form {
public:
uiWindow *w;
void onClosing(Object ^sender, CancelEventArgs ^e);
// void onClosing(Object ^sender, CancelEventArgs ^e);
};
struct uiWindow {
uiWindowsControl c;
gcroot<libuiWindow ^> *window;
gcroot<Border ^> *border;
int margined;
gcroot<libuiForm ^> *form;
uiControl *child;
int margined;
int (*onClosing)(uiWindow *, void *);
void *onClosingData;
gcroot<CancelEventHandler ^> *onClosingDelegate;
// gcroot<CancelEventHandler ^> *onClosingDelegate;
};
static void onDestroy(uiWindow *);
@ -32,6 +30,7 @@ uiWindowsDefineControlWithOnDestroy(
onDestroy(hthis); // on destroy
)
/*
void libuiWindow::onClosing(Object ^sender, CancelEventArgs ^e)
{
// TODO copy comments
@ -39,6 +38,7 @@ void libuiWindow::onClosing(Object ^sender, CancelEventArgs ^e)
uiControlDestroy(uiControl(this->w));
e->Cancel = true;
}
*/
static int defaultOnClosing(uiWindow *w, void *data)
{
@ -47,6 +47,7 @@ static int defaultOnClosing(uiWindow *w, void *data)
static void onDestroy(uiWindow *w)
{
/*
// first hide the window
(*(w->window))->Hide();
// take off the closing event; otherwise it will be recursed
@ -60,6 +61,7 @@ static void onDestroy(uiWindow *w)
}
// clean up remaining .net objects
delete w->border;
*/
}
static void windowCommitShow(uiControl *c)
@ -87,12 +89,12 @@ static void windowContainerUpdateState(uiControl *c)
char *uiWindowTitle(uiWindow *w)
{
return uiWindowsCLRStringToText((*(w->window))->Title);
return uiWindowsCLRStringToText((*(w->window))->Text);
}
void uiWindowSetTitle(uiWindow *w, const char *title)
{
(*(w->window))->Title = fromUTF8(title);
(*(w->window))->Text = fromUTF8(title);
}
void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data)
@ -105,11 +107,11 @@ void uiWindowSetChild(uiWindow *w, uiControl *child)
{
if (w->child != NULL) {
uiControlSetParent(w->child, NULL);
(*(w->border))->Child = nullptr;
// (*(w->border))->Child = nullptr;
}
w->child = child;
if (w->child != NULL) {
(*(w->border))->Child = genericHandle(w->child);
// (*(w->border))->Child = genericHandle(w->child);
uiControlSetParent(w->child, uiControl(w));
}
}
@ -119,16 +121,15 @@ int uiWindowMargined(uiWindow *w)
return w->margined;
}
// TODO according to http://stackoverflow.com/questions/18299107/how-to-handle-control-spacing-in-wpf-window-designer - same for rest of library
void uiWindowSetMargined(uiWindow *w, int margined)
{
w->margined = margined;
// TODO Margin or Padding?
/* // TODO margin or padding?
if (w->margined)
(*(w->border))->Margin = Thickness(10, 10, 10, 10);
else
(*(w->border))->Margin = Thickness(0, 0, 0, 0);
}
*/}
uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
{
@ -136,19 +137,16 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
w = (uiWindow *) uiNewControl(uiWindowType());
w->window = new gcroot<libuiWindow ^>();
*(w->window) = gcnew libuiWindow();
(*(w->window))->w = w;
w->form = new gcroot<libuiForm ^>();
*(w->form) = gcnew libuiForm();
(*(w->form))->w = w;
(*(w->window))->Title = fromUTF8(title);
// TODO is this the client size?
(*(w->window))->Width = width;
(*(w->window))->Height = height;
(*(w->window))->Text = fromUTF8(title);
// (*(w->window))->ClientSize = xxxxx(width, height);
// reference source indicates that this does indeed map to COLOR_BTNFACE
(*(w->window))->Background = SystemColors::ControlBrush;
// TODO background color?
w->border = new gcroot<Border ^>();
/* w->border = new gcroot<Border ^>();
*(w->border) = gcnew Border();
(*(w->window))->Content = *(w->border);
@ -156,7 +154,7 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
*(w->onClosingDelegate) = gcnew CancelEventHandler(*(w->window),
&libuiWindow::onClosing);
(*(w->window))->Closing += *(w->onClosingDelegate);
uiWindowOnClosing(w, defaultOnClosing, NULL);
*/ uiWindowOnClosing(w, defaultOnClosing, NULL);
uiWindowsFinishNewControl(w, uiWindow, window);
uiControl(w)->CommitShow = windowCommitShow;

View File

@ -1,26 +0,0 @@
// 25 november 2015
#include "uipriv_wpf.hpp"
static gcroot<Application ^> *app;
void initWPF(void)
{
app = new gcroot<Application ^>();
*app = gcnew Application();
}
void uninitWPF(void)
{
delete app;
}
void uiMain(void)
{
(*app)->Run();
}
void uiQuit(void)
{
// TODO this executes immediately, not later
(*app)->Shutdown();
}