From: ewt Date: Fri, 12 Sep 1997 15:50:40 +0000 (+0000) Subject: added windows.c X-Git-Tag: r0-12~28 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3c96e6755f27cc9281d7218a29740aea3910bb50;p=thirdparty%2Fnewt.git added windows.c --- diff --git a/Makefile b/Makefile index e12a321..26fdf36 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ -LIBS = -lslang -lm -lc #-lefence +LIBS = -lslang -lm -lefence +SHLIBS = -lslang -lm -lc CFLAGS = $(RPM_OPT_FLAGS) -Wall ifeq ($(RPM_OPT_FLAGS),) @@ -16,7 +17,7 @@ LIBNEWT = libnewt.a LIBNEWTSH = libnewt.so.$(VERSION) LIBNEWTSONAME = libnewt.so.$(SONAME) LIBOBJS = newt.o button.o form.o checkbox.o entry.o label.o listbox.o \ - scrollbar.o textbox.o scale.o grid.o + scrollbar.o textbox.o scale.o grid.o windows.o SHCFLAGS = -fPIC @@ -73,7 +74,7 @@ $(SHAREDDIR): sharedlib: $(LIBNEWTSH) $(LIBNEWTSH): $(SHAREDDIR) $(SHAREDOBJS) - gcc -shared -o $(LIBNEWTSH) -Wl,-soname,$(LIBNEWTSONAME) $(SHAREDOBJS) $(LIBS) + gcc -shared -o $(LIBNEWTSH) -Wl,-soname,$(LIBNEWTSONAME) $(SHAREDOBJS) $(SHLIBS) $(SHAREDDIR)/%.o : %.c $(CC) $(SHCFLAGS) -c $(CFLAGS) -o $@ $< diff --git a/windows.c b/windows.c new file mode 100644 index 0000000..d846b50 --- /dev/null +++ b/windows.c @@ -0,0 +1,97 @@ +#include +#include +#include +#include +#include +#include + +#include "errno.h" + +static int newtvwindow(char * title, char * button1, char * button2, + char * message, va_list args) { + newtComponent b1, b2 = NULL, t, f, answer; + char * buf = NULL; + int size = 0; + int i = 0; + int width, height; + char * flowedText; + newtGrid grid, buttonGrid; + + do { + size += 1000; + if (buf) free(buf); + buf = malloc(size); + i = vsnprintf(buf, size, message, args); + } while (i == size); + + flowedText = newtReflowText(buf, 35, 5, 5, &width, &height); + if (height > 10) { + free(flowedText); + flowedText = newtReflowText(buf, 60, 5, 5, &width, &height); + } + free(buf); + + b1 = newtButton(-1, -1, button1); + t = newtTextbox(-1, -1, width, height, NEWT_TEXTBOX_WRAP); + newtTextboxSetText(t, flowedText); + free(flowedText); + + if (button2) { + b2 = newtButton(-1, -1, button2); + buttonGrid = newtCreateGrid(2, 1); + newtGridSetField(buttonGrid, 1, 0, NEWT_GRID_COMPONENT, button2, + 1, 0, 0, 0, 0, 0); + } else { + buttonGrid = newtCreateGrid(1, 1); + } + + newtGridSetField(buttonGrid, 0, 0, NEWT_GRID_COMPONENT, b1, + 0, 0, button2 ? 1 : 0, 0, 0, 0); + + grid = newtCreateGrid(1, 2); + newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, t, 0, 0, 0, 1, 0, 0); + newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, buttonGrid, 0, 0, 0, 0, 0, + NEWT_GRID_FLAG_GROWX); + newtGridWrappedWindow(grid, title); + + f = newtForm(NULL, NULL, 0); + newtFormAddComponents(f, t, b1, NULL); + + answer = newtRunForm(f); + newtGridFree(grid, 1); + + newtFormDestroy(f); + newtPopWindow(); + + if (answer == f) + return 2; + else if (answer == b2) + return 1; + + return 0; +} + +int newtWinChoice(char * title, char * button1, char * button2, + char * message, ...) { + va_list args; + int rc; + + va_start(args, message); + rc = newtvwindow(title, button1, button2, message, args); + va_end(args); + + return rc; +} + +void newtWinMessage(char * title, char * buttonText, char * text, ...) { + va_list args; + + va_start(args, text); + newtvwindow(title, buttonText, NULL, text, args); + va_end(args); +} + +void newtWinMessagev(char * title, char * buttonText, char * text, + va_list argv) { + newtvwindow(title, buttonText, NULL, text, argv); +}