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 // 26 november 2015
#include "uipriv_wpf.hpp" #include "uipriv_winforms.hpp"
struct uiArea { struct uiArea {
uiWindowsControl c; uiWindowsControl c;

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
// 16 august 2015 // 16 august 2015
#include "uipriv_wpf.hpp" #include "uipriv_winforms.hpp"
static uintmax_t type_uiWindowsControl = 0; static uintmax_t type_uiWindowsControl = 0;
@ -10,11 +10,11 @@ uintmax_t uiWindowsControlType(void)
return type_uiWindowsControl; 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; return *h;
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
// 26 november 2015 // 26 november 2015
#include "uipriv_wpf.hpp" #include "uipriv_winforms.hpp"
// TODO alignment // TODO alignment
// TODO lots of padding // 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 // 19 november 2015
#include "uipriv_wpf.hpp" #include "uipriv_winforms.hpp"
void uiMenuItemEnable(uiMenuItem *m) void uiMenuItemEnable(uiMenuItem *m)
{ {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
// 25 november 2015 // 25 november 2015
#include "uipriv_wpf.hpp" #include "uipriv_winforms.hpp"
#include <string.h> #include <string.h>
using namespace System::Text; 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__ #define __LIBUI_UI_WINDOWS_H__
#ifndef __cplusplus_cli #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 #endif
extern "C" { extern "C" {

View File

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

View File

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

View File

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