]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
added windows.c
authorewt <ewt>
Fri, 12 Sep 1997 15:50:40 +0000 (15:50 +0000)
committerewt <ewt>
Fri, 12 Sep 1997 15:50:40 +0000 (15:50 +0000)
Makefile
windows.c [new file with mode: 0644]

index e12a321e9172aca88c95fe40925a3b7c0777d5f0..26fdf3665cd706f875f3daa9ea9b1c26e57f1567 100644 (file)
--- 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 (file)
index 0000000..d846b50
--- /dev/null
+++ b/windows.c
@@ -0,0 +1,97 @@
+#include <errno.h>
+#include <newt.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#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);
+}