Published 2006-02-18 10:56:21
/* See original for copyright - I've removed for the example) */Click on the more bit for the full story..
// give this file a module name (bit like namespaces)
module hw.HelloWorld;
// private imports so that any code importing this,
// doesnt import these as well.
// so you dont flood the global namespace too much..
private import dui.MainWindow;
private import dui.DUI;
public:
class HelloWorld : MainWindow // it extends MainWindow..
{
private import dui.Label; // imports can go here as well..
char[char[]] testarray = [ // yah - native array's in prop. def's
"one": "1",
"two": "2"
]; // oops - this doesnt work (although it may do in the future)
// thanks to Jarrett Billingsley for spotting this..
char[][] testarray = [ // well, semi-yah limited support
1: "atest", // for assoc. array initalizers..
5: "another test",
];
this() // yeap that's the constructor..
{
super("DUI Hello World"); // like parent::_construct()
this.setBorderWidth(10); // you dont need this. , but
// I think it add's clarity.
this.add(new Label("Hello World" ~ testarray["one"]));
// string concat with the ~
// operator.
this.show();
}
}
void main(char[][] args)
{
DUI dui = DUI.dui(args); // pass parameters to Gtk+
new HelloWorld();
dui.go(); // start the main event loop
}
int main(char[][] args)and can be compiled with the simple line:
{
printf("Hello World\n");
printf("args.length = %d\n", args.length);
for (int i = 0; i < args.length; i++) {
printf("args[%d] = '%s'\n",
i,
cast(char *)args[i]);
}
return 0;
}
#dmd -I/dmd/src/phobos hello.d[suggested improvement from Jarret Billingsley] - which makes use of foreach and writefln, rather good ole printf()
int main(char[][] args)
{
writefln("Hello World");
writefln("args.length = ", args.length);
foreach (uint i, char[] arg, args) {
writefln("args[",i,'] = '%s'", arg);
}
return 0;
}
@@ -231,7 +231,7 @@The compiler error was pretty obvious, what was wrong, what line/file etc.
GtkWidget *gtkO= gtk_label_get_mnemonic_widget(gtkW());
if ( gtkO is null )
{
- null;
+ return null;
}
return new Widget(gtkO);
}
I have a suspicion that the author doesnt manually edit the Makefiles and autogenerates the from his editor, as hardcoding locations is not really the best of ideas. Anyway after those small changes, he presto, the gtk demo, and hello world on gtk work!
@@ -19,8 +19,8 @@
##########################
COMP_dui = dmd
COMP_FLAGS_dui = -c -g -O -od../obj -op
-COMP_IMPORT_dui = -I/home/ruimt/devel/D1/Dool/src:
/home/ruimt/dmd/src/phobos/:/home/ruimt/dmd/src/phobos
-LINK_LIBS_dui=-lphobos -lpthread -L/home/ruimt/devel/D1/Dool -ldool
+COMP_IMPORT_dui = -I/usr/src/dool/src:/dmd/src/phobos/:/dmd/src/phobos
+LINK_LIBS_dui=-lphobos -lpthread -L/usr/src/dool -ldool
LINK_dui=ar rcs
After that, only one other small modification seems to be needed to scintilla/gtk/ScintillaGTK.cxx
** DIFF SLIGHTLY BROKEN AS I'VE HAD TO WRAP IT TO FIT ON THE PAGE...
@@ -7,7 +7,7 @@
# To force GTK+ 2 build, define GTK2 on the make command line.
# To force GTK+ 1 build, define GTK1 on the make command line.
-.SUFFIXES: .cxx .c .o .h .a
+.SUFFIXES: .cxx .c .o .h .a .so
CC = g++
CCOMP = gcc
AR = ar
@@ -17,14 +17,15 @@
RANLIB = ranlib
endif
-COMPLIB=../bin/scintilla.a
+COMPLIB=../bin/libscintilla.a
+SHAREDLIB=../bin/libscintilla.so
+
vpath %.h ../src ../include
vpath %.cxx ../src
INCLUDEDIRS=-I ../include -I ../src
-CXXBASEFLAGS=-Wall -Wno-missing-braces
-Wno-char-subscripts -DGTK -DSCI_LEXER $(INCLUDEDIRS)
-
+CXXBASEFLAGS=-Wall -Wno-missing-braces
-Wno-char-subscripts -DGTK -DSCI_LEXER $(INCLUDEDIRS) -Dunix
ifdef NOTHREADS
THREADFLAGS=-DG_THREADS_IMPL_NONE
else
@@ -34,20 +35,20 @@
ifdef DEBUG
CXXFLAGS=-DDEBUG -g $(CXXBASEFLAGS) $(THREADFLAGS)
else
-CXXFLAGS=-DNDEBUG -Os $(CXXBASEFLAGS) $(THREADFLAGS)
+CXXFLAGS+=-DNDEBUG $(CXXBASEFLAGS) $(THREADFLAGS)
endif
# If explicit setting of GTK1 or GTK2 then use that else look for
# pkg-config which is an OK indication that GTK2 is available
ifdef GTK2
-CONFIGFLAGS=pkg-config --cflags gtk+-2.0
+CONFIGFLAGS=pkg-config --cflags gtk+-2.0 gthread-2.0 glib-2.0
MARSHALLER=scintilla-marshal.o
else
ifdef GTK1
CONFIGFLAGS=gtk-config --cflags
else
ifneq (,$(findstring /,$(shell whereis pkg-config)))
-CONFIGFLAGS=pkg-config --cflags gtk+-2.0
+CONFIGFLAGS=pkg-config --cflags gtk+-2.0 gthread-2.0 glib-2.0
MARSHALLER=scintilla-marshal.o
else
CONFIGFLAGS=gtk-config --cflags
@@ -56,7 +57,11 @@
endif
.cxx.o:
- $(CC) `$(CONFIGFLAGS)` $(CXXFLAGS) -c $<
+ $(CXX) `$(CONFIGFLAGS)` $(CXXFLAGS) -c $<
+.cxx.so:
+ $(CXX) -fPIC `$(CONFIGFLAGS)` $(CXXFLAGS) -o $@ -c $<
+
+
.c.o:
$(CCOMP) `$(CONFIGFLAGS)` $(CXXFLAGS) -w -c $<
@@ -70,24 +75,41 @@
LexLout.o LexLua.o LexMatlab.o LexMetapost.o LexMMIXAL.o LexMPT.o LexMSSQL.o \
LexNsis.o LexOthers.o LexPascal.o LexPB.o LexPerl.o LexPOV.o LexPS.o \
LexPython.o LexRebol.o LexRuby.o LexScriptol.o LexSmalltalk.o LexSpecman.o \
-LexSQL.o LexTADS3.o LexTeX.o LexVB.o LexVerilog.o LexVHDL.o LexYAML.o
+LexSQL.o LexTADS3.o LexTeX.o LexVB.o LexVerilog.o LexVHDL.o LexYAML.o
#--Autogenerated -- end of automatically generated section
-all: $(COMPLIB)
+all: static shared
+
+static: $(COMPLIB)
+shared: $(SHAREDLIB)
+
+install: install-shared
+ mkdir -p ${PREFIX}/include/scintilla
+ install -m 444 ../include/*.h ${PREFIX}/include/scintilla
+ install -m 444 ${COMPLIB} ${PREFIX}/lib
+
+install-shared:
+ install -m 444 ${SHAREDLIB} ${PREFIX}/lib
clean:
rm -f *.o $(COMPLIB)
deps:
- $(CC) -MM `$(CONFIGFLAGS)` $(CXXFLAGS) *.cxx ../src/*.cxx >deps.mak
+ $(CXX) -MM `$(CONFIGFLAGS)` $(CXXFLAGS) *.cxx ../src/*.cxx >deps.mak
-$(COMPLIB): DocumentAccessor.o WindowAccessor.o
KeyWords.o StyleContext.o Document.o CallTip.o \
+LIBOBJS = DocumentAccessor.o WindowAccessor.o
KeyWords.o StyleContext.o Document.o CallTip.o \
ScintillaBase.o ContractionState.o Editor.o
ExternalLexer.o PropSet.o PlatGTK.o \
KeyMap.o LineMarker.o ScintillaGTK.o CellBuffer.o ViewStyle.o \
- RESearch.o Style.o Indicator.o AutoComplete.o UniConversion.o XPM.o \
- $(MARSHALLER) $(LEXOBJS)
+ RESearch.o Style.o Indicator.o AutoComplete.o UniConversion.o XPM.o
$(LEXOBJS)
+
+$(COMPLIB): $(LIBOBJS)
$(AR) rc $@ $^
$(RANLIB) $@
+$(SHAREDLIB): $(addsuffix .so,$(basename $(LIBOBJS)))
+ $(CC) -shared -fPIC -o $@ -Wl,-soname,$(notdir $(SHAREDLIB)) \
+ `pkg-config --libs gtk+-2.0 gthread-2.0 glib-2.0` $^
+
+
# Automatically generate header dependencies with "make deps"
include deps.mak
@@ -47,7 +47,6 @@now running make will output a nice .so file.. - which appears to work..
#include "gtk/gtkmarshal.h"
#if GTK_MAJOR_VERSION >= 2
#include "scintilla-marshal.h"
+#include "scintilla-marshal.c"
#endif
#ifdef SCI_LEXER