changeset 2861:ef7a414f9b71

Add initial C++ binding header and example program. Still trying to figure out how it will work, but it is loosely based on GTK-- and when complete dwtestoo will replicate dwtest. Added support for building dwtestoo on Unix and Mac.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 15 Dec 2022 12:42:34 +0000
parents 9daee9d58956
children 7479ab54e014
files Makefile.in dw.hpp dwtestoo.cpp mac/Info.plist mac/finishup.sh
diffstat 5 files changed, 148 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.in	Wed Nov 23 02:17:12 2022 +0000
+++ b/Makefile.in	Thu Dec 15 12:42:34 2022 +0000
@@ -81,7 +81,7 @@
 SYSCONF_LINK_TARGET2 = $(SYSCONF_LINK_TARGET_SHARED2)
 SYSCONF_LINK_LIB2 = $(SYSCONF_LINK_LIB_SHARED2)
 
-all: $(TARGETS) dwtest
+all: $(TARGETS) dwtest dwtestoo
 
 install: installbase $(INSTALL_COMPAT) $(INSTALL_TEST)
 
@@ -109,6 +109,7 @@
 	$(INSTALL) -d $(prefix)/share/applications; \
 	$(INSTALL) -d $(prefix)/share/dwtest; \
 	$(INSTALL) dwtest $(prefix)/bin; \
+	$(INSTALL) dwtestoo $(prefix)/bin; \
 	$(INSTALL) org.dbsoft.dwindows.dwtest.desktop $(prefix)/share/applications/; \
 	$(INSTALL) image/test.png $(prefix)/share/dwtest; \
 	$(INSTALL) gtk/file.xpm $(prefix)/share/dwtest; \
@@ -134,6 +135,7 @@
 	rm -f $(prefix)/lib/pkgconfig/dwindows.pc
 	rm -f $(prefix)/bin/dwindows-config
 	rm -f $(prefix)/bin/dwtest
+	rm -f $(prefix)/bin/dwtestoo
 	rm -f $(prefix)/include/dwcompat.h
 	rm -f $(prefix)/include/dwconfig.h
 	rm -f $(prefix)/include/dw.h
@@ -163,6 +165,8 @@
 	rm -f $(DW_DIR)/*.o
 	rm -f dwtest
 	rm -rf dwtest.app
+	rm -f dwtestoo
+	rm -rf dwtestoo.app
 
 $(SYSCONF_LINK_TARGET2): $(OBJECTS2)
 	$(SYSCONF_LINK_LIB2)
@@ -188,7 +192,15 @@
 dwtest: dwtest.o
 	$(CC) -o dwtest dwtest.o $(MLFLAGS) -l$(TARGET) $(LFLAGS)
 	-chmod +x $(srcdir)/mac/finishup.sh
-	-$(srcdir)/mac/finishup.sh $(srcdir)
+	-$(srcdir)/mac/finishup.sh $(srcdir) dwtest
+
+dwtestoo.o: $(srcdir)/dwtestoo.cpp $(srcdir)/dw.h $(srcdir)/dw.hpp
+	$(CC) -c $(INCPATH) $(CCFLAGS) -o $@ $(srcdir)/dwtestoo.cpp
+
+dwtestoo: dwtestoo.o
+	$(CC) -o dwtestoo dwtestoo.o $(MLFLAGS) -l$(TARGET) $(LFLAGS)
+	-chmod +x $(srcdir)/mac/finishup.sh
+	-$(srcdir)/mac/finishup.sh $(srcdir) dwtestoo
 
 zip:
 	zip dwindows$(VER_MAJ)$(VER_MIN).zip $(srcdir)/*.txt $(srcdir)/makefile.* $(srcdir)/*.c $(srcdir)/dw.h  $(srcdir)/dwcompat.h \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dw.hpp	Thu Dec 15 12:42:34 2022 +0000
@@ -0,0 +1,96 @@
+/* Dynamic Windows C++ Language Bindings 
+ * Copyright 2022 Brian Smith
+ */
+
+#ifndef _HPP_DW
+#define _HPP_DW
+#include <dw.h>
+
+namespace DW 
+{
+
+// Base handle class which allows opaque access to 
+// The base system handles
+class Handle 
+{
+private:
+	void *handle;
+public:
+	void SetHandle(void *newhandle) { handle = newhandle; }
+	void *GetHandle() { return handle; }
+};
+
+// Widget class allows packing and style
+class Widget : public Handle
+{
+public:
+	HWND hwnd; 
+	HWND GetHWND() { return reinterpret_cast<HWND>(GetHandle()); }
+	void SetHWND(HWND newhwnd) { hwnd = newhwnd; SetHandle(reinterpret_cast<void *>(newhwnd)); }
+};
+
+// Box class is a packable object
+class Box : public Widget
+{
+};
+	
+// Top-level window class is packable
+class Window : public Box
+{
+public:
+	Window(HWND owner, const char *title, unsigned long style) { SetHWND(dw_window_new(owner, title, style)); }
+	Window(const char *title, unsigned long style) { SetHWND(dw_window_new(HWND_DESKTOP, title, style)); }
+	Window(unsigned long style) { SetHWND(dw_window_new(HWND_DESKTOP, "", style)); }
+	Window(const char *title) { SetHWND(dw_window_new(HWND_DESKTOP, title,  DW_FCF_SYSMENU | DW_FCF_TITLEBAR |
+                        DW_FCF_TASKLIST | DW_FCF_SIZEBORDER | DW_FCF_MINMAX)); }
+	Window() { SetHWND(dw_window_new(HWND_DESKTOP, "", DW_FCF_SYSMENU | DW_FCF_TITLEBAR |
+                        DW_FCF_TASKLIST | DW_FCF_SIZEBORDER | DW_FCF_MINMAX)); }
+
+	void SetText(const char *text) { dw_window_set_text(hwnd, text); }
+	void SetSize(unsigned long width, unsigned long height) { dw_window_set_size(hwnd, width, height); }
+	void Show() { dw_window_show(hwnd); }
+};
+
+class App
+{
+public:
+	App() { dw_init(TRUE, 0, NULL); }
+	App(const char *appid) { dw_app_id_set(appid, NULL); dw_init(TRUE, 0, NULL); }
+	App(const char *appid, const char *appname) { dw_app_id_set(appid, appname); dw_init(TRUE, 0, NULL); }
+	App(int argc, char *argv[]) { dw_init(TRUE, argc, argv); }
+	App(int argc, char *argv[], const char *appid) { dw_app_id_set(appid, NULL); dw_init(TRUE, argc, argv); }
+	App(int argc, char *argv[], const char *appid, const char *appname) { dw_app_id_set(appid, appname); dw_init(TRUE, argc, argv); }
+
+	void Main() { dw_main(); }
+	void MainIteration() { dw_main_iteration(); }
+	void MainQuit() { dw_main_quit(); }
+	void Exit(int exitcode) { dw_exit(exitcode); }
+};
+
+#if 0
+// Class that allows drawing, either to screen or picture (pixmap)
+class Drawable
+{
+	void DrawPoint(int x, int y);
+	void DrawLine(int x1, int y1, int x2, int y2);
+	void DrawPolygon(int flags, int x[], int y[]);
+	void DrawRect(int fill, int x, int y, int width, int height);
+	void DrawArc(int flags, int xorigin, int yorigin, int x1, int y1, int x2, int y2);
+	void DrawText(int x, int y, std::string text);
+	int BitBltStretch(int xdest, int ydest, int width, int height, HWND src, int xsrc, int ysrc, int srcwidth, int srcheight);
+	int BitBltStretch(int xdest, int ydest, int width, int height, HPIXMAP srcp, int xsrc, int ysrc, int srcwidth, int srcheight);
+	void BitBlt(int xdest, int ydest, int width, int height, HWND src, int xsrc, int ysrc);
+	void BitBlt(int xdest, int ydest, int width, int height, HPIXMAP srcp, int xsrc, int ysrc);
+};
+
+class Render : public Drawable, public Widget
+{
+};
+
+class Pixmap : public Drawable, public Handle
+{
+};
+#endif
+
+} /* namespace DW */
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtestoo.cpp	Thu Dec 15 12:42:34 2022 +0000
@@ -0,0 +1,26 @@
+#include <dw.hpp>
+
+class MyWindow : public DW::Window
+{
+public:
+  MyWindow();
+};
+
+MyWindow::MyWindow()
+{
+  SetText("Basic application");
+  SetSize(200, 200);
+}
+
+int main(int argc, char* argv[])
+{
+  DW::App *app = new DW::App(argc, argv, "org.dbsoft.dwindows.dwtestoo");
+  MyWindow *window = new MyWindow();
+
+  window->Show();
+
+  app->Main();
+  app->Exit(0);
+
+  return 0;
+}
--- a/mac/Info.plist	Wed Nov 23 02:17:12 2022 +0000
+++ b/mac/Info.plist	Thu Dec 15 12:42:34 2022 +0000
@@ -5,11 +5,11 @@
 	<key>CFBundleDevelopmentRegion</key>
 	<string>en</string>
 	<key>CFBundleExecutable</key>
-	<string>dwtest</string>
+	<string>APPNAME</string>
 	<key>CFBundleIconFile</key>
 	<string></string>
 	<key>CFBundleIdentifier</key>
-	<string>org.dbsoft.dwtest</string>
+	<string>org.dbsoft.APPNAME</string>
 	<key>CFBundleInfoDictionaryVersion</key>
 	<string>6.0</string>
 	<key>CFBundleName</key>
--- a/mac/finishup.sh	Wed Nov 23 02:17:12 2022 +0000
+++ b/mac/finishup.sh	Thu Dec 15 12:42:34 2022 +0000
@@ -3,15 +3,15 @@
 
 if [ $PLATFORM = "Darwin" ]
 then
-    mkdir -p dwtest.app/Contents/MacOS
-    mkdir -p dwtest.app/Contents/Resources
+    mkdir -p $2.app/Contents/MacOS
+    mkdir -p $2.app/Contents/Resources
 
-    cp -f $1/mac/Info.plist dwtest.app/Contents
-    cp -f $1/mac/PkgInfo dwtest.app/Contents 
-    cp -f $1/mac/file.png dwtest.app/Contents/Resources
-    cp -f $1/mac/folder.png dwtest.app/Contents/Resources
-    cp -f $1/image/test.png dwtest.app/Contents/Resources
-    cp -f dwtest dwtest.app/Contents/MacOS
+    cat $1/mac/Info.plist | sed s/APPNAME/$2/ >  $2.app/Contents/Info.plist
+    cp -f $1/mac/PkgInfo $2.app/Contents 
+    cp -f $1/mac/file.png $2.app/Contents/Resources
+    cp -f $1/mac/folder.png $2.app/Contents/Resources
+    cp -f $1/image/test.png $2.app/Contents/Resources
+    cp -f $2 $2.app/Contents/MacOS
     # Check if there is a certificate to sign with...
     if [ ! -f mac/key.crt ]; then
        if [ -f mac/key.rsa ]; then
@@ -22,11 +22,11 @@
           certtool i mac/key.crt k="`pwd`/mac/key.keychain" r=mac/key.rsa c p=moof
        else
            echo "No key pair found, cannot generate certificate... signing AdHoc."
-           codesign -s "-" dwtest.app/Contents/MacOS/dwtest
+           codesign -s "-" $2.app/Contents/MacOS/$2
        fi
     fi
     if [ -f mac/key.keychain ]; then
         echo "Signing the apllication with certificate in mac/key.crt"
-        codesign -s my-signing-identity --keychain mac/key.keychain dwtest.app/Contents/MacOS/dwtest
+        codesign -s my-signing-identity --keychain mac/key.keychain $2.app/Contents/MacOS/$2
     fi
 fi