-0.50.20
- - changes to support Asian languages properly
-
-0.50.19-2
- - don't build newt-python2 sub package
-
1.59 -> 0.50.10
- added support for help
- added cusor on/off stuff
CVSTAG = r$(subst .,-,$(VERSION))
SONAME = @SONAME@
-PROGS = test test-j whiptail whiptcl.so testgrid testgrid-j testtree testtree-j
+PROGS = test whiptail whiptcl.so testgrid testtree
TESTOBJS = test.o
-TESTJOBJS = test-j.o
NDIALOGOBJS = whiptail.o dialogboxes.o
WHIPTCLOBJS = whiptcl.o dialogboxes.o
LIBNEWT = libnewt.a
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 windows.o buttonbar.o \
- checkboxtree.o eawidth.o
+ checkboxtree.o
SHCFLAGS = -fPIC
#--------------------------------------
-SOURCES = $(subst .o,.c,$(TESTOBJS) $(TESTJOBJS) $(NDIALOGOBJS) $(LIBOBJS))
+SOURCES = $(subst .o,.c,$(TESTOBJS) $(NDIALOGOBJS) $(LIBOBJS))
SHAREDDIR = shared
SHAREDOBJS = $(patsubst %,$(SHAREDDIR)/%, $(LIBOBJS))
test: $(TESTOBJS) $(LIBNEWT)
gcc -g -o test $(TESTOBJS) $(LIBNEWT) $(LIBS) -static
-test-j: $(TESTJOBJS) $(LIBNEWT)
- gcc -g -o test-j $(TESTJOBJS) $(LIBNEWT) $(LIBS) -static
-
testgrid: testgrid.o $(LIBNEWT)
gcc -g -o testgrid testgrid.o $(LIBNEWT) $(LIBS)
-testgrid-j: testgrid-j.o $(LIBNEWT)
- gcc -g -o testgrid-j testgrid-j.o $(LIBNEWT) $(LIBS)
-
testtree: testtree.o $(LIBNEWT)
gcc -g -o testtree testtree.o $(LIBNEWT) $(LIBS)
-testtree-j: testtree-j.o $(LIBNEWT)
- gcc -g -o testtree-j testtree-j.o $(LIBNEWT) $(LIBS)
-
_snackmodule.so: snackmodule.o $(LIBNEWTSH)
gcc --shared $(SHCFLAGS) -o _snackmodule.so snackmodule.o -L . $(LIBNEWTSH)
#include "newt.h"
#include "newt_pr.h"
-#include "eawidth.h"
struct button {
char * text;
static newtComponent createButton(int left, int row, const char * text, int compact) {
newtComponent co;
struct button * bu;
- int width = get_east_asia_str_width (NULL, text, 0);
co = malloc(sizeof(*co));
bu = malloc(sizeof(struct button));
if (bu->compact) {
co->height = 1;
- co->width = width + 3;
+ co->width = strlen(text) + 3;
} else {
co->height = 4;
- co->width = width + 5;
+ co->width = strlen(text) + 5;
}
co->top = row;
co->left = left;
co->takesFocus = 1;
co->isMapped = 0;
- co->isLabel = 0;
newtGotorc(co->top, co->left);
#include "newt.h"
#include "newt_pr.h"
-#include "eawidth.h"
enum type { CHECK, RADIO };
co->callback = NULL;
co->height = 1;
- co->width = get_east_asia_str_width (NULL, text, 0) + 4;
+ co->width = strlen(text) + 4;
co->top = top;
co->left = left;
co->takesFocus = 1;
- co->isLabel = 0;
return co;
}
#include "newt.h"
#include "newt_pr.h"
-#include "eawidth.h"
struct items {
char * text;
int flags, int * indexes) {
struct items * curList, * newNode, * item;
struct items ** listPtr = NULL;
- int i, index, numIndexes, width;
+ int i, index, numIndexes;
struct CheckboxTree * ct = co->data;
numIndexes = 0;
item->depth = numIndexes - 1;
i = 4 + (3 * item->depth);
- width = get_east_asia_str_width (NULL, text, 0);
- if ((width + i + ct->pad) > co->width) {
- co->width = width + i + ct->pad;
+ if ((strlen(text) + i + ct->pad) > co->width) {
+ co->width = strlen(text) + i + ct->pad;
}
return 0;
co->height = height;
co->width = 0;
co->isMapped = 0;
- co->isLabel = 0;
ct->itemlist = NULL;
ct->firstItem = NULL;
ct->currItem = NULL;
{
struct CheckboxTree * ct;
struct items * item;
- int i, width;
+ int i;
if (!co) return;
ct = co->data;
item->text = strdup(text);
i = 4 + (3 * item->depth);
- width = get_east_asia_str_width (NULL, text, 0);
- if ((width + i + ct->pad) > co->width) {
- co->width = width + i + ct->pad;
+ if ((strlen(text) + i + ct->pad) > co->width) {
+ co->width = strlen(text) + i + ct->pad;
}
ctDraw(co);
AC_INIT(newt_pr.h)
AC_CONFIG_HEADER(config.h)
-VERSION=0.50.20
+VERSION=0.50.19
SONAME=0.50
AC_SUBST(VERSION)
AC_SUBST(SONAME)
#include "dialogboxes.h"
#include "newt.h"
#include "popt.h"
-#include "eawidth.h"
/* globals -- ick */
static int buttonHeight = 1;
int maxTagWidth = 0;
int maxTextWidth = 0;
int scrollFlag;
- int w;
struct {
const char * text;
const char * tag;
} else
itemInfo[numItems].text = "";
- if ((w = get_east_asia_str_width (NULL, itemInfo[numItems].text, 0)) > (unsigned int)maxTextWidth)
- maxTextWidth = w;
- if ((w = get_east_asia_str_width (NULL, itemInfo[numItems].tag, 0)) > (unsigned int)maxTagWidth)
- maxTagWidth = w;
+ if (strlen(itemInfo[numItems].text) > (unsigned int)maxTextWidth)
+ maxTextWidth = strlen(itemInfo[numItems].text);
+ if (strlen(itemInfo[numItems].tag) > (unsigned int)maxTagWidth)
+ maxTagWidth = strlen(itemInfo[numItems].tag);
numItems++;
}
char buf[80], format[20];
int maxWidth = 0;
int top;
- int w;
struct {
const char * text;
const char * tag;
else
cbStates[numBoxes] = ' ';
- if ((w = get_east_asia_str_width (NULL, cbInfo[numBoxes].tag, 0)) > (unsigned int)maxWidth)
- maxWidth = w;
+ if (strlen(cbInfo[numBoxes].tag) > (unsigned int)maxWidth)
+ maxWidth = strlen(cbInfo[numBoxes].tag);
numBoxes++;
}
int
get_east_asia_str_width (const char *locale_name, const char *s, int x) {
size_t n;
+ int rc;
n = strlen(s) + 1;
- return get_east_asia_str_n_width (locale_name, s, n, x);
+ rc = get_east_asia_str_n_width (locale_name, s, n, x);
+ if (rc == INT_MAX)
+ return strlen (s);
+ return rc;
}
#if TEST_GET_EAST_ASIA_STR_WIDTH
+++ /dev/null
-#include <stddef.h>
-
-typedef enum {
- ambiguous, neutral, narrow, half_width, wide, full_width
-} east_asia_type;
-
-/**
- * get_east_asia_type returns the character classification of a given
- * Unicode character according to Unicode Technical
- * Report 11.
- *
- * @param unicode the Unicode/ISO-10646 character to get the type of
- * @return the classification of the character, according to
- * UAX#11 data.
- */
-east_asia_type get_east_asia_type(wchar_t unicode);
-
-/**
- * get_east_asia_width measures the amount of space a multibyte string
- * takes an a traditional fixed width terminal such
- * as xterm in character cells.
- *
- * @param locale_name used to determine the if character width should
- * be interpreted as CJK or Asian in the case of
- * Greek and Cyrillic characters. If NULL, it will
- * use setlocale() to determine the LC_CTYPE setting.
- * @param s the multibyte string to measure the width of.
- * @param x the current cursor position, used to handle the
- * calculation of tab widths. 0 is the first column.
- * @return the number of fixed width character cells the string
- * takes up. If the string is an illegal multibyte
- * string, or a memory error or other occurs, INT_MAX
- * is returned and errno is set.
- */
-int get_east_asia_str_width(const char *locale_name, const char *s, int x);
-int get_east_asia_str_n_width (const char *locale_name, const char *s, size_t n, int x);
-int east_asia_mblen (const char *locale_name, const char *s, size_t n, int x);
#include "newt.h"
#include "newt_pr.h"
-#include "eawidth.h"
struct entry {
int flags;
char ** resultPtr, int flags) {
newtComponent co;
struct entry * en;
- int w;
co = malloc(sizeof(*co));
en = malloc(sizeof(struct entry));
co->width = width;
co->isMapped = 0;
co->callback = NULL;
- co->isLabel = 0;
co->ops = &entryOps;
else
co->takesFocus = 0;
- if (initialValue && (w = get_east_asia_str_width (NULL, initialValue, 0)) > (unsigned int)width) {
- en->bufAlloced = w + 1;
+ if (initialValue && strlen(initialValue) > (unsigned int)width) {
+ en->bufAlloced = strlen(initialValue) + 1;
}
en->buf = malloc(en->bufAlloced);
en->resultPtr = resultPtr;
#include <stdlib.h>
#include <sys/select.h>
#include <sys/time.h>
-#include <string.h>
#ifdef USE_GPM
#include <ctype.h>
#include "newt.h"
#include "newt_pr.h"
-#include "eawidth.h"
-
-struct label {
- char *text;
- int length;
-};
#ifdef USE_GPM
/*....................................... The connection data structure */
co->top = -1;
co->left = -1;
co->isMapped = 0;
- co->isLabel = 0;
co->takesFocus = 0; /* we may have 0 components */
co->ops = &formOps;
void newtFormAddComponent(newtComponent co, newtComponent newco) {
struct form * form = co->data;
- int i, j, k, l, xmap, ymap, x, y;
- char *map, *s = NULL;
co->takesFocus = 1;
form->currComp = form->numComps;
form->numComps++;
-
- /* check multibyte char broken */
- /* create text map */
- xmap = 0;
- ymap = 0;
- for ( i = 0; i < form->numComps; i++ ) {
- if ((form->elements[i].co->top + form->elements[i].co->height) > ymap )
- ymap = form->elements[i].co->top + form->elements[i].co->height;
- if ((form->elements[i].co->left + form->elements[i].co->width) > xmap )
- xmap = form->elements[i].co->left + form->elements[i].co->width;
- }
- map = (char *)calloc ((xmap+1) * (ymap+1), sizeof (char));
-
-#define MAP(x,y) *(map + ((x)*ymap + (y)))
-
- /* create non-label components map */
- for ( i = 0; i < form->numComps; i++ ) {
- if ( form->elements[i].co->isLabel == 0 && form->elements[i].co->left >= 0 && form->elements[i].co->top >= 0 ) {
- for ( x = 0; x < form->elements[i].co->width; x++ ) {
- for ( y = 0; y < form->elements[i].co->height; y++ )
- MAP (form->elements[i].co->left+x, form->elements[i].co->top+y) = 1;
- }
- }
- }
-
- /* check label overlap */
- for ( i = 0; i < form->numComps; i++ ) {
- if ( form->elements[i].co->isLabel != 0 ) {
- y = form->elements[i].co->top;
- l = form->elements[i].co->left;
- if ( y >= 0 && l >= 0 ) {
- for ( j = 0; j < form->elements[i].co->width; j++ ) {
- if ( MAP (j+l, y) != 0 ) {
- if ( MAP (j+l, y) != 1 ) {
- /* if label is here, move label */
- while ( MAP (form->elements[i].co->left, y) != 0 )
- form->elements[i].co->left++;
- } else {
- /* if label is overlapping, cut label */
- if ((j+l) == form->elements[i].co->left ) {
- free (((struct label *)form->elements[i].co->data)->text);
- ((struct label *)form->elements[i].co->data)->text = malloc (1);
- ((struct label *)form->elements[i].co->data)->text[0] = 0;
- ((struct label *)form->elements[i].co->data)->length = 0;
- form->elements[i].co->width = 0;
- } else {
- x = 0;
- while (x < j) {
- s = &((struct label *)form->elements[i].co->data)->text[x];
- k = east_asia_mblen (NULL, s, strlen (s), 0);
- if ( k <= 0 ) break;
- else {
- if ((x+k) < j ) x += k;
- else break;
- }
- }
- s = ((struct label *)form->elements[i].co->data)->text;
- ((struct label *)form->elements[i].co->data)->text = realloc(s, x+1);
- ((struct label *)form->elements[i].co->data)->text[x] = 0;
- ((struct label *)form->elements[i].co->data)->length = strlen (s);
- form->elements[i].co->width = get_east_asia_str_width (NULL, s, 0);
- }
- }
- } else
- MAP (j+l, y) = 2;
- }
- }
- }
- }
- free (map);
}
void newtFormAddComponents(newtComponent co, ...) {
free(form->elements);
free(form);
free(co);
- newtResizeScreen(1);
}
newtComponent newtRunForm(newtComponent co) {
#include "newt.h"
#include "newt_pr.h"
-#include "eawidth.h"
struct gridField {
enum newtGridElement type;
}
void newtGridWrappedWindow(newtGrid grid, char * title) {
- int width, height, offset = 0, w;
+ int width, height, offset = 0;
newtGridGetSize(grid, &width, &height);
- w = get_east_asia_str_width (NULL, title, 0);
- if (width < (w + 2)) {
- offset = ((w + 2) - width) / 2;
- width = w + 2;
+ if (width < strlen(title) + 2) {
+ offset = ((strlen(title) + 2) - width) / 2;
+ width = strlen(title) + 2;
}
newtCenteredWindow(width + 2, height + 2, title);
newtGridPlace(grid, 1 + offset, 1);
#include "newt.h"
#include "newt_pr.h"
-#include "eawidth.h"
struct label {
char * text;
co->ops = &labelOps;
co->height = 1;
- co->width = get_east_asia_str_width (NULL, text, 0);
+ co->width = strlen(text);
co->top = top;
co->left = left;
co->takesFocus = 0;
- co->isLabel = 1;
la->length = strlen(text);
la->text = strdup(text);
int newLength;
struct label * la = co->data;
- newLength = get_east_asia_str_width (NULL, text, 0);
+ newLength = strlen(text);
if (newLength <= la->length) {
memset(la->text, ' ', la->length);
memcpy(la->text, text, newLength);
#include "newt.h"
#include "newt_pr.h"
-#include "eawidth.h"
+
/* Linked list of items in the listbox */
struct items {
co->ops = &listboxOps;
co->takesFocus = 1;
co->callback = NULL;
- co->isLabel = 0;
updateWidth(co, li, 5);
void newtListboxSetEntry(newtComponent co, int num, const char * text) {
struct listbox * li = co->data;
- int i, w;
+ int i;
struct items *item;
for(i = 0, item = li->boxItems; item != NULL && i < num;
free(item->text);
item->text = strdup(text);
}
- w = get_east_asia_str_width (NULL, text, 0);
- if (li->userHasSetWidth == 0 && w > li->curWidth) {
- updateWidth(co, li, w);
+ if (li->userHasSetWidth == 0 && strlen(text) > li->curWidth) {
+ updateWidth(co, li, strlen(text));
}
if (num >= li->startShowItem && num <= li->startShowItem + co->height)
const void * data) {
struct listbox * li = co->data;
struct items *item;
- int w;
if(li->boxItems) {
for (item = li->boxItems; item->next != NULL; item = item->next);
item = li->boxItems = malloc(sizeof(struct items));
}
- w = get_east_asia_str_width (NULL, text, 0);
- if (!li->userHasSetWidth && text && (w > li->curWidth))
- updateWidth(co, li, w);
+ if (!li->userHasSetWidth && text && (strlen(text) > li->curWidth))
+ updateWidth(co, li, strlen(text));
item->text = strdup(text); item->data = data; item->next = NULL;
item->isSelected = 0;
const void * data, void * key) {
struct listbox * li = co->data;
struct items *item, *t;
- int w;
if (li->boxItems) {
if (key) {
item->next = NULL;
}
- w = get_east_asia_str_width (NULL, text, 0);
- if (!li->userHasSetWidth && text && (w > li->curWidth))
- updateWidth(co, li, w);
+ if (!li->userHasSetWidth && text && (strlen(text) > li->curWidth))
+ updateWidth(co, li, strlen(text));
item->text = strdup(text?text:"(null)"); item->data = data;
item->isSelected = 0;
if (!li->userHasSetWidth) {
widest = 0;
for (item = li->boxItems; item != NULL; item = item->next)
- if ((t = get_east_asia_str_width (NULL, item->text, 0)) > widest) widest = t;
+ if ((t = strlen(item->text)) > widest) widest = t;
}
if (li->currItem >= num)
#include <sys/types.h>
#include <termios.h>
#include <unistd.h>
-#include <locale.h>
#include "newt.h"
#include "newt_pr.h"
newtRefresh();
}
+#if defined(THIS_DOESNT_WORK)
void newtResizeScreen(int redraw) {
newtPushHelpLine("");
if (redraw)
SLsmg_refresh();
}
+#endif
int newtInit(void) {
char * MonoValue, * MonoEnv = "NEWT_MONO";
- /* initialize locale */
- setlocale (LC_ALL, "");
-
/* use the version variable just to be sure it gets included */
strlen(version);
Summary: A development library for text mode user interfaces.
Name: newt
-%define version 0.50.20
+%define version 0.50.19
Version: %{version}
Release: 1
Copyright: LGPL
Group: System Environment/Libraries
Source: ftp://ftp.redhat.com/pub/redhat/code/newt/newt-%{version}.tar.gz
-BuildRequires: python,perl
+BuildRequires: python,python2,perl
Requires: slang
Provides: snack
BuildRoot: %{_tmppath}/%{name}-%{version}-%{root}
# cheat... build python2 stuff here
make clean
-#perl -pi -e "s/python1.5/python2.0/g" *
+perl -pi -e "s/python1.5/python2.0/g" *
./configure
make instroot=$RPM_BUILD_ROOT install
make instroot=$RPM_BUILD_ROOT install-sh
-#python -c 'from compileall import *; compile_dir("'$RPM_BUILD_ROOT'/usr/lib/python2.0",10,"/usr/lib/python2.0")'
+python -c 'from compileall import *; compile_dir("'$RPM_BUILD_ROOT'/usr/lib/python2.0",10,"/usr/lib/python2.0")'
%clean
/usr/lib/libnewt.a
/usr/lib/libnewt.so
-#%files python2
-#%defattr (-,root,root)
-#/usr/lib/python2.0
+%files python2
+%defattr (-,root,root)
+/usr/lib/python2.0
%changelog
-* Mon Jan 22 2001 Than Ngo <than@redhat.com>
-- don't build newt-python2 sub package.
-
* Fri Dec 15 2000 Trond Eivind Glomsrød <teg@redhat.com>
- use %%{_tmppath}
- add python2 subpackage, with such support
int top, left;
int takesFocus;
int isMapped;
- int isLabel;
struct componentOps * ops;
co->top = top;
co->left = left;
co->takesFocus = 0;
- co->isLabel = 0;
sc->fullValue = fullValue;
sc->charsSet = 0;
co->height = height;
co->width = 1;
co->takesFocus = 0;
- co->isLabel = 0;
return co;
}
+++ /dev/null
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <signal.h>
-
-#include "newt.h"
-
-struct callbackInfo {
- newtComponent en;
- char * state;
-};
-
-void disableCallback(newtComponent co, void * data) {
- struct callbackInfo * cbi = data;
-
- if (*cbi->state == ' ') {
- newtEntrySetFlags(cbi->en, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
- } else {
- newtEntrySetFlags(cbi->en, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
- }
-
- newtRefresh();
-}
-
-void suspend(void * d) {
- newtSuspend();
- raise(SIGTSTP);
- newtResume();
-}
-
-int main(void) {
- newtComponent b1, b2, r1, r2, r3, e2, e3, l1, l2, l3, scale;
- newtComponent lb, t, rsf, answer;
- newtComponent cs[10];
- newtComponent f, chklist, e1;
- struct callbackInfo cbis[3];
- char results[10];
- char * enr2, * enr3, * scaleVal;
- void ** selectedList;
- int i, numsel;
- char buf[20];
-
- newtInit();
- newtCls();
-
- newtSetSuspendCallback(suspend, NULL);
-
- newtDrawRootText(0, 0, "Newt ¥Æ¥¹¥È¥×¥í¥°¥é¥à");
- newtPushHelpLine(NULL);
- newtDrawRootText(-50, 0, "¥ë¡¼¥È¥Æ¥¥¹¥È");
-
- newtOpenWindow(2, 2, 30, 10, "£±ÈÖÌܤΥ¦¥£¥ó¥É¥¦");
- newtOpenWindow(10, 5, 65, 16, "¥¦¥£¥ó¥É¥¦£²");
-
- f = newtForm(NULL, NULL, 0);
- chklist = newtForm(NULL, NULL, 0);
-
- b1 = newtButton(3, 1, "½ªÎ»");
- b2 = newtButton(18, 1, "¹¹¿·");
- r1 = newtRadiobutton(20, 10, "ÁªÂò»è£±", 0, NULL);
- r2 = newtRadiobutton(20, 11, "ÁªÂò»è£²", 1, r1);
- r3 = newtRadiobutton(20, 12, "ÁªÂò»è£³", 0, r2);
- rsf = newtForm(NULL, NULL, 0);
- newtFormAddComponents(rsf, r1, r2, r3, NULL);
- newtFormSetBackground(rsf, NEWT_COLORSET_CHECKBOX);
-
- for (i = 0; i < 10; i++) {
- sprintf(buf, "¥Á¥§¥Ã¥¯ %d", i);
- cs[i] = newtCheckbox(3, 10 + i, buf, ' ', NULL, &results[i]);
- newtFormAddComponent(chklist, cs[i]);
- }
-
- l1 = newtLabel(3, 6, "¥¹¥±¡¼¥ë:");
- l2 = newtLabel(3, 7, "¥¹¥¯¥í¡¼¥ë:");
- l3 = newtLabel(3, 8, "¥Ò¥É¥¥¥ó:");
- e1 = newtEntry(12, 6, "", 20, &scaleVal, 0);
- e2 = newtEntry(12, 7, "ɸ½à", 20, &enr2, NEWT_FLAG_SCROLL);
- e3 = newtEntry(12, 8, NULL, 20, &enr3, NEWT_FLAG_HIDDEN);
-
- cbis[0].state = &results[0];
- cbis[0].en = e1;
- newtComponentAddCallback(cs[0], disableCallback, &cbis[0]);
-
- scale = newtScale(3, 14, 32, 100);
-
- newtFormSetHeight(chklist, 3);
-
- newtFormAddComponents(f, b1, b2, l1, l2, l3, e1, e2, e3, chklist, NULL);
- newtFormAddComponents(f, rsf, scale, NULL);
-
- lb = newtListbox(45, 1, 6, NEWT_FLAG_MULTIPLE | NEWT_FLAG_BORDER |
- NEWT_FLAG_SCROLL);
- newtListboxAppendEntry(lb, "£±ÈÖÌÜ", (void *) 1);
- newtListboxAppendEntry(lb, "£²ÈÖÌÜ", (void *) 2);
- newtListboxAppendEntry(lb, "£³ÈÖÌÜ", (void *) 3);
- newtListboxAppendEntry(lb, "£´ÈÖÌÜ", (void *) 4);
- newtListboxAppendEntry(lb, "£¶ÈÖÌÜ", (void *) 6);
- newtListboxAppendEntry(lb, "£·ÈÖÌÜ", (void *) 7);
- newtListboxAppendEntry(lb, "£¸ÈÖÌÜ", (void *) 8);
- newtListboxAppendEntry(lb, "£¹ÈÖÌÜ", (void *) 9);
- newtListboxAppendEntry(lb, "£±£°ÈÖÌÜ", (void *) 10);
-
- newtListboxInsertEntry(lb, "£µÈÖÌÜ", (void *) 5, (void *) 4);
- newtListboxInsertEntry(lb, "£±£±ÈÖÌÜ", (void *) 11, (void *) 10);
- newtListboxDeleteEntry(lb, (void *) 11);
-
- t = newtTextbox(45, 10, 17, 5, NEWT_FLAG_WRAP);
- newtTextboxSetText(t, "¤³¤ì¤Ï¥Æ¥¥¹¥È¤Î¥µ¥ó¥×¥ë¤Ç¤¹¡£\nÀµ¾ï¤Ëɽ¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¤«¡©\n¤³¤ì¤ÏñÆÈ¹Ô¤Ç¤¹¡£\n¤³¤ì¤Ïɽ¼¨¤µ¤ì¤Æ¤Ï¤¤¤±¤Þ¤»¤ó");
-
- newtFormAddComponents(f, lb, t, NULL);
- newtRefresh();
-
- do {
- answer = newtRunForm(f);
-
- if (answer == b2) {
- newtScaleSet(scale, atoi(scaleVal));
- newtRefresh();
- answer = NULL;
- }
- } while (!answer);
-
- scaleVal = strdup(scaleVal);
- enr2 = strdup(enr2);
- enr3 = strdup(enr3);
-
- selectedList = newtListboxGetSelection(lb, &numsel);
-
- newtFormDestroy(f);
-
- newtPopWindow();
- newtPopWindow();
- newtFinished();
-
- printf("got string 1: %s\n", scaleVal);
- printf("got string 2: %s\n", enr2);
- printf("got string 3: %s\n", enr3);
-
- if(selectedList) {
- printf("\nSelected listbox items:\n");
- for(i = 0; i < numsel; i++)
- puts(selectedList[i]);
- }
-
- return 0;
-}
+++ /dev/null
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <signal.h>
-
-#include "newt.h"
-
-int main(void) {
- newtComponent b1, b2, b3, b4;
- newtComponent answer, f, t;
- newtGrid grid, subgrid;
- char * flowedText;
- int textWidth, textHeight, rc;
- char * menuContents[] = { "°ì", "Æó", "»°", "»Í", "¸Þ", NULL };
- char * entries[10];
- struct newtWinEntry autoEntries[] = {
- { "¥¨¥ó¥È¥ê", entries + 0, 0 },
- { "Ê̤Υ¨¥ó¥È¥ê", entries + 1, 0 },
- { "»°ÈÖÌܤΥ¨¥ó¥È¥ê", entries + 2, 0 },
- { "»ÍÈÖÌܤΥ¨¥ó¥È¥ê", entries + 3, 0 },
- { NULL, NULL, 0 } };
-
- memset(entries, 0, sizeof(entries));
-
- newtInit();
- newtCls();
-
- b1 = newtCheckbox(-1, -1, "¥Æ¥¹¥È¤Î¤¿¤á¤Î¤«¤Ê¤êŤ¤¥Á¥§¥Ã¥¯¥Ü¥Ã¥¯¥¹", ' ', NULL, NULL);
- b2 = newtButton(-1, -1, "Ê̤Υܥ¿¥ó");
- b3 = newtButton(-1, -1, "¤·¤«¤·¡¢¤·¤«¤·");
- b4 = newtButton(-1, -1, "¤·¤«¤·²¿¤À¤í¤¦¡©");
-
- f = newtForm(NULL, NULL, 0);
-
- grid = newtCreateGrid(2, 2);
- newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, b1, 0, 0, 0, 0,
- NEWT_ANCHOR_RIGHT, 0);
- newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0);
- newtGridSetField(grid, 1, 0, NEWT_GRID_COMPONENT, b3, 0, 0, 0, 0, 0, 0);
- newtGridSetField(grid, 1, 1, NEWT_GRID_COMPONENT, b4, 0, 0, 0, 0, 0, 0);
-
-
- newtFormAddComponents(f, b1, b2, b3, b4, NULL);
-
- newtGridWrappedWindow(grid, "°ìÈÖÌܤΥ¦¥£¥ó¥É¥¦");
- newtGridFree(grid, 1);
-
- answer = newtRunForm(f);
-
- newtFormDestroy(f);
- newtPopWindow();
-
- flowedText = newtReflowText("¤³¤ì¤Ï¤«¤Ê¤ê¥Æ¥¥¹¥È¤é¤·¤¤¤â¤Î¤Ç¤¹¡£40¥«¥é¥à"
- "¤ÎŤµ¤Ç¡¢¥é¥Ã¥Ô¥ó¥°¤¬¹Ô¤ï¤ì¤Þ¤¹¡£"
- "ÁÇÁᤤ¡¢Ãã¿§¤Î¸Ñ¤¬¤Î¤í¤Þ¤Ê¸¤¤òÈô¤Ó"
- "±Û¤¨¤¿¤Î¤òÃΤäƤ뤫¤¤?\n\n"
- "¾¤Ë¤ªÃΤ餻¤¹¤ë¤³¤È¤È¤·¤Æ¡¢Å¬Åö¤Ë²þ¹Ô¤ò¤¹¤ë"
- "¤³¤È¤¬½ÅÍפǤ¹¡£",
- 40, 5, 5, &textWidth, &textHeight);
- t = newtTextbox(-1, -1, textWidth, textHeight, NEWT_FLAG_WRAP);
- newtTextboxSetText(t, flowedText);
- free(flowedText);
-
-
- b1 = newtButton(-1, -1, "λ²ò");
- b2 = newtButton(-1, -1, "¥¥ã¥ó¥»¥ë");
-
- grid = newtCreateGrid(1, 2);
- subgrid = newtCreateGrid(2, 1);
-
- newtGridSetField(subgrid, 0, 0, NEWT_GRID_COMPONENT, b1, 0, 0, 0, 0, 0, 0);
- newtGridSetField(subgrid, 1, 0, NEWT_GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0);
-
- newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, t, 0, 0, 0, 1, 0, 0);
- newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, subgrid, 0, 0, 0, 0, 0,
- NEWT_GRID_FLAG_GROWX);
- newtGridWrappedWindow(grid, "Ê̤ÎÎã");
- newtGridDestroy(grid, 1);
-
- f = newtForm(NULL, NULL, 0);
- newtFormAddComponents(f, b1, t, b2, NULL);
- answer = newtRunForm(f);
-
- newtPopWindow();
- newtFormDestroy(f);
-
- newtWinMessage("¥·¥ó¥×¥ë", "λ²ò", "¤³¤ì¤Ï¥·¥ó¥×¥ë¤Ê¥á¥Ã¥»¡¼¥¸¥¦¥£¥ó¥É¥¦¤Ç¤¹");
- newtWinChoice("¥·¥ó¥×¥ë", "λ²ò", "¥¥ã¥ó¥»¥ë", "¤³¤ì¤Ï¥·¥ó¥×¥ë¤ÊÁªÂò¥¦¥£¥ó¥É¥¦¤Ç¤¹");
-
- textWidth = 0;
- rc = newtWinMenu("¥Æ¥¹¥È¥á¥Ë¥å¡¼", "¤³¤ì¤Ï newtWinMenu() ¥³¡¼¥ë¤Î¥µ¥ó¥×¥ë"
- "¤Ç¤¹¡£ ¥¹¥¯¥í¡¼¥ë¥Ð¡¼¤ÏɬÍפ˱þ¤¸¤Æ¤Ä¤¤¤¿¤ê¡¢ "
- "¤Ä¤«¤Ê¤«¤Ã¤¿¤ê¤·¤Þ¤¹¡£", 50, 5, 5, 3,
- menuContents, &textWidth, "λ²ò", "¥¥ã¥ó¥»¥ë", NULL);
-
- rc = newtWinEntries("¥Æ¥¥¹¥È newtWinEntries()", "¤³¤ì¤Ï newtWinEntries()"
- "¥³¡¼¥ë¤Î¥µ¥ó¥×¥ë¤Ç¤¹¡£¤¿¤¤¤Ø¤ó´Êñ¤Ë¤¿¤¯¤µ¤ó¤ÎÆþÎϤò"
- "°·¤¦¤³¤È¤¬¤Ç¤¤Þ¤¹¡£", 50, 5, 5, 20, autoEntries, "λ²ò",
- "¥¥ã¥ó¥»¥ë", NULL);
-
- newtFinished();
-
- printf("rc = 0x%x item = %d\n", rc, textWidth);
-
- return 0;
-}
+++ /dev/null
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <signal.h>
-
-#include "newt.h"
-
-int main(void) {
- newtGrid grid;
- newtComponent checktree;
- newtComponent button;
- newtComponent form;
- newtComponent answer;
- void ** result, **ptr;
- int numselected, i, j;
- int * list;
-
- newtInit();
- newtCls();
-
- checktree = newtCheckboxTreeMulti(-1, -1, 10, " ab", NEWT_FLAG_SCROLL);
- newtCheckboxTreeAddItem(checktree, "¥Ê¥ó¥Ð¡¼", (void *) 2, 0,
- NEWT_ARG_APPEND, NEWT_ARG_LAST);
- newtCheckboxTreeAddItem(checktree, "ËÜÅö¤ËËÜÅö¤ËŤ¤¥â¥Î",
- (void *) 3, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
- newtCheckboxTreeAddItem(checktree, "¥Ê¥ó¥Ð¡¼£µ", (void *) 5,
- NEWT_FLAG_SELECTED,
- NEWT_ARG_APPEND, NEWT_ARG_LAST);
- newtCheckboxTreeAddItem(checktree, "¥Ê¥ó¥Ð¡¼£¶", (void *) 6, 0,
- NEWT_ARG_APPEND, NEWT_ARG_LAST);
- newtCheckboxTreeAddItem(checktree, "¥Ê¥ó¥Ð¡¼£·", (void *) 7,
- NEWT_FLAG_SELECTED,
- NEWT_ARG_APPEND, NEWT_ARG_LAST);
- newtCheckboxTreeAddItem(checktree, "¥Ê¥ó¥Ð¡¼£¸", (void *) 8, 0,
- NEWT_ARG_APPEND, NEWT_ARG_LAST);
- newtCheckboxTreeAddItem(checktree, "¥Ê¥ó¥Ð¡¼£¹", (void *) 9, 0,
- NEWT_ARG_APPEND, NEWT_ARG_LAST);
- newtCheckboxTreeAddItem(checktree, "¥Ê¥ó¥Ð¡¼£±£°", (void *) 10,
- NEWT_FLAG_SELECTED,
- NEWT_ARG_APPEND, NEWT_ARG_LAST);
- newtCheckboxTreeAddItem(checktree, "¥Ê¥ó¥Ð¡¼£±£±", (void *) 11, 0,
- NEWT_ARG_APPEND, NEWT_ARG_LAST);
- newtCheckboxTreeAddItem(checktree, "¥Ê¥ó¥Ð¡¼£±£²", (void *) 12,
- NEWT_FLAG_SELECTED,
- NEWT_ARG_APPEND, NEWT_ARG_LAST);
-
- newtCheckboxTreeAddItem(checktree, "¥«¥é¡¼", (void *) 1, 0,
- 0, NEWT_ARG_LAST);
- newtCheckboxTreeAddItem(checktree, "ÀÖ¿§", (void *) 100, 0,
- 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
- newtCheckboxTreeAddItem(checktree, "Çò¿§", (void *) 101, 0,
- 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
- newtCheckboxTreeAddItem(checktree, "ÀÄ¿§", (void *) 102, 0,
- 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
-
- newtCheckboxTreeAddItem(checktree, "¥Ê¥ó¥Ð¡¼£´", (void *) 4, 0,
- 3, NEWT_ARG_LAST);
-
- newtCheckboxTreeAddItem(checktree, "°ì·å¤Î¿ô»ú", (void *) 200, 0,
- 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
- newtCheckboxTreeAddItem(checktree, "°ì", (void *) 201, 0,
- 1, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
- newtCheckboxTreeAddItem(checktree, "Æó", (void *) 202, 0,
- 1, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
- newtCheckboxTreeAddItem(checktree, "»°", (void *) 203, 0,
- 1, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
- newtCheckboxTreeAddItem(checktree, "»Í", (void *) 204, 0,
- 1, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
-
- newtCheckboxTreeAddItem(checktree, "Æó·å¤Î¿ô»ú", (void *) 300, 0,
- 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
- newtCheckboxTreeAddItem(checktree, "½½", (void *) 210, 0,
- 1, 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
- newtCheckboxTreeAddItem(checktree, "½½°ì", (void *) 211, 0,
- 1, 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
- newtCheckboxTreeAddItem(checktree, "½½Æó", (void *) 212, 0,
- 1, 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
- newtCheckboxTreeAddItem(checktree, "½½»°", (void *) 213, 0,
- 1, 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
-
- button = newtButton(-1, -1, "½ªÎ»");
-
- grid = newtCreateGrid(1, 2);
- newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, checktree, 0, 0, 0, 1,
- NEWT_ANCHOR_RIGHT, 0);
- newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, button, 0, 0, 0, 0,
- 0, 0);
-
- newtGridWrappedWindow(grid, "¥Á¥§¥Ã¥¯¥Ü¥Ã¥¯¥¹¥Ä¥ê¡¼¥Æ¥¹¥È");
- newtGridFree(grid, 1);
-
- form = newtForm(NULL, NULL, 0);
- newtFormAddComponents(form, checktree, button, NULL);
-
- answer = newtRunForm(form);
-
- newtFinished();
-
- result = newtCheckboxTreeGetSelection(checktree, &numselected);
- ptr = result;
- if (!result || !numselected)
- printf("none selected\n");
- else
- printf("Current selection (all) (%d):\n", numselected);
- for (i = 0; i < numselected; i++) {
- j = (int) *ptr++;
- printf("%d\n", j);
- }
- result = newtCheckboxTreeGetMultiSelection(checktree, &numselected, 'b');
- ptr = result;
- if (!result || !numselected)
- printf("none selected\n");
- else
- printf("Current selection (b) (%d):\n",numselected);
- for (i = 0; i < numselected; i++) {
- j = (int) *ptr++;
- printf("%d\n", j);
- }
-
- if (result)
- free(result);
-
- list = newtCheckboxTreeFindItem(checktree, (void *) 213);
- printf("path:");
- for (i = 0; list && list[i] != NEWT_ARG_LAST; i++)
- printf(" %d", list[i]);
- printf("\n");
-
- newtFormDestroy(form);
-
- return 0;
-}
#include <slang.h>
#include <stdlib.h>
#include <string.h>
-#include <limits.h>
#include "newt.h"
#include "newt_pr.h"
-#include "eawidth.h"
struct textbox {
char ** lines;
co->left = left;
co->takesFocus = 0;
co->width = width;
- co->isLabel = 0;
tb->doWrap = flags & NEWT_FLAG_WRAP;
tb->numLines = 0;
int howbad = 0;
int height = 0;
int kanji = 0;
- int w, w2;
- w = get_east_asia_str_width (NULL, text, 0);
if (resultPtr) {
- /* XXX I think this will work */
- result = malloc(w * 2 + 2);
- *result = '\0';
+ /* XXX I think this will work */
+ result = malloc(strlen(text) + (strlen(text) / width) + 2);
+ *result = '\0';
}
while (*text) {
kanji = 0;
- end = strchr(text, '\n');
- if (!end)
- end = text + strlen(text);
-
- while (*text && text <= end) {
- char *ptr;
-
- ptr = (char *)malloc (sizeof (char)*((end-text)+1));
- strncpy (ptr, text, end - text);
- *(ptr + (end-text)) = 0;
- w2 = get_east_asia_str_width (NULL, ptr, 0);
- free (ptr);
- if (w2 < width) {
- if (result) {
- strncat(result, text, end - text);
- strcat(result, "\n");
- }
- height++;
-
- if (w2 < (width / 2))
- howbad += ((width / 2) - w2) / 2;
- text = end;
- if (*text) text++;
- } else {
- int is_space = 0, into_kanji = 0;
- char *spcptr = NULL;
-
- chptr = text;
- i = 0;
- while ( i < (width - 1)) {
- kanji = east_asia_mblen (NULL, chptr, end - chptr, 0);
- if ( kanji == INT_MAX || kanji <= 0 ) kanji = 1;
- else {
- if ( kanji == 1 ) {
- if ( is_space == 0 ) {
- if (isspace(*chptr)) {
- is_space = 1;
- }
- else if ( into_kanji == 1 ) {
- if (!spcptr) spcptr = chptr;
- is_space = 1;
- }
- } else {
- if (!spcptr) spcptr = chptr;
- else if (isspace(*chptr)) {
- spcptr = NULL;
- is_space = 1;
- }
- }
- } else {
- into_kanji = 1;
- is_space = 0;
- spcptr = NULL;
- }
- if ((i+kanji) < (width - 1)) i += kanji;
- else break;
- }
- chptr = chptr + kanji;
- }
- if ( is_space != 0 && spcptr-text > 1 ) chptr = spcptr;
- howbad += width - (chptr - text) + 1;
- if ( result ) {
- strncat (result, text, chptr - text);
- strcat (result, "\n");
- }
- height++;
- text = chptr;
- while (east_asia_mblen (NULL, text, end - text, 0) == 1 && isspace(*text)) text++;
- }
+ end = strchr(text, '\n');
+ if (!end)
+ end = text + strlen(text);
+
+ while (*text && text <= end) {
+ if (end - text < width) {
+ if (result) {
+ strncat(result, text, end - text);
+ strcat(result, "\n");
+ height++;
}
+
+ if (end - text < (width / 2))
+ howbad += ((width / 2) - (end - text)) / 2;
+ text = end;
+ if (*text) text++;
+ } else {
+ chptr = text;
+ kanji = 0;
+ for ( i = 0; i < width - 1; i++ ) {
+ if ( !iseuckanji(*chptr)) {
+ kanji = 0;
+ } else if ( kanji == 1 ) {
+ kanji = 2;
+ } else {
+ kanji = 1;
+ }
+ chptr++;
+ }
+ if (kanji == 0) {
+ while (chptr > text && !isspace(*chptr)) chptr--;
+ while (chptr > text && isspace(*chptr)) chptr--;
+ chptr++;
+ }
+
+ if (chptr-text == 1 && !isspace(*chptr))
+ chptr = text + width - 1;
+
+ if (chptr > text)
+ howbad += width - (chptr - text) + 1;
+ if (result) {
+ if (kanji == 1) {
+ strncat(result, text, chptr - text + 1 );
+ chptr++;
+ kanji = 0;
+ } else {
+ strncat(result, text, chptr - text );
+ }
+ strcat(result, "\n");
+ height++;
+ }
+
+ if (isspace(*chptr))
+ text = chptr + 1;
+ else
+ text = chptr;
+ while (isspace(*text)) text++;
+ }
}
+ }
+
if (badness) *badness = howbad;
if (resultPtr) *resultPtr = result;
if (heightPtr) *heightPtr = height;
newtFormDestroy(f);
newtPopWindow();
- newtResizeScreen(1);
if (answer == f)
return NULL;
va_start(args, message);
rc = newtvwindow(title, button1, button2, NULL, message, args);
- newtResizeScreen(1);
va_end(args);
if (rc == button1)
void newtWinMessagev(char * title, char * buttonText, char * text,
va_list argv) {
newtvwindow(title, buttonText, NULL, NULL, text, argv);
- newtResizeScreen(1);
}
int newtWinTernary(char * title, char * button1, char * button2,
va_start(args, message);
rc = newtvwindow(title, button1, button2, button3, message, args);
- newtResizeScreen(1);
va_end(args);
if (rc == button1)
buttonName = va_arg(args, char *);
}
- newtResizeScreen(1);
va_end(button1);
buttonBar = newtCreateGrid(numButtons, 1);
newtFormDestroy(form);
newtPopWindow();
- newtResizeScreen(1);
-
return rc;
}
newtFormDestroy(form);
newtPopWindow();
- newtResizeScreen(1);
return rc;
}