From 81f5124cec81cc292b79e3abc73917d0fdb23c5e Mon Sep 17 00:00:00 2001 From: nwanua Date: Fri, 29 Sep 2000 04:50:56 +0000 Subject: [PATCH] *** empty log message *** --- WINGs/README | 10 +- WINGs/Tests/testtext.c | 573 ---------------------------------------------- WINGs/WINGs.h | 20 +- WINGs/fontmanager.c | 38 ++-- WINGs/wtext.c | 605 +++++++++++++++++++++++++++---------------------- 5 files changed, 369 insertions(+), 877 deletions(-) delete mode 100644 WINGs/Tests/testtext.c diff --git a/WINGs/README b/WINGs/README index d3751322..03ebd685 100644 --- a/WINGs/README +++ b/WINGs/README @@ -1,11 +1,11 @@ - WINGs - WINGs Is Not GNUstep + WINGs - WINGs Is Not GNUstep - by + by - Alfredo Kengi Kojima - - kojima@windowmaker.org + Alfredo Kengi Kojima + + kojima@windowmaker.org WINGs is a small widget set with the N*XTSTEP look and feel. It's API diff --git a/WINGs/Tests/testtext.c b/WINGs/Tests/testtext.c deleted file mode 100644 index e6ec8013..00000000 --- a/WINGs/Tests/testtext.c +++ /dev/null @@ -1,573 +0,0 @@ - -#include -#include - -#include "WINGs.h" - - -WMScreen *scr; - - -void -wAbort() -{ - exit(0); -} - - -void Close(WMWidget *self, void *client) -{ - exit(0); -} - -extern WMFont * WMGetFontPlain(WMScreen *scrPtr, WMFont *font); - -extern WMFont * WMGetFontBold(WMScreen *scrPtr, WMFont *font); - -extern WMFont * WMGetFontItalic(WMScreen *scrPtr, WMFont *font); - -extern WMFont * WMGetFontOfSize(WMScreen *scrPtr, WMFont *font, int size); - - - - -/* =============== a rudimentary HTML parser ======================= */ - -/* due to the WMSetTextParser stuff, it should not -be too hard to add parsers. like dis :-] */ - - -/* - * A hack to speed up caseless_equal. Thanks to Quincey Koziol for - * developing it for the "chimera" folks so I could use it 7 years later ;-) - * Constraint: nothing but '\0' may map to 0 - */ -unsigned char map_table[256] = -{ -0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, -17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, -33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, -49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, -97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, -111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 91, 92, -93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, -108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, -122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, -136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, -150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, -164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, -178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, -192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, -206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, -220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, -234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, -248, 249, 250, 251, 252, 253, 254, 255}; - -#define TOLOWER(x) (map_table[(int)x]) -static int -mystrcasecmp(const unsigned char *s1, const unsigned char *s2) -{ - if (!*s1 || !*s2) return 0; - while (*s2 != '\0') { - if (TOLOWER (*s1) != TOLOWER (*s2)) /* true if *s1 == 0 ! */ - return 0; - s1++; - s2++; - } - return (*s1=='\0' ||!isalnum(*s1))?1:0; -} - - -typedef struct _currentFormat { - WMBag *fonts; - WMBag *colors; - WMColor *ccolor; - WMFont *cfont; - WMRulerMargins margins; - //WMBag *aligns; // for tables... - /* the following are "nested" - i.e.: - 1 2 1 1 2 0 get it? */ - short i; - short b; - short u; - short fmargin; - short bmargin; - short first:1; - short type:1; - WMAlignment align:2; - short ul:3; /* how "nested"... up to 8 levels deep */ - short comment:1; /* ignore text till --> */ - short RESERVED:10; -} CFMT; -CFMT cfmt; - - - -#if 0 -getArg(char *t, short type, void *arg) -{ - short d=0; - while(*(++t) && !d) { - if(type==0) { - if(*t>='0' && *t<='9') { - sscanf(t, "%d", arg); - while(*t&& (*t<'0' || *t>'9')) - t++; - d=1; - } - } - } -} -#endif - -void parseToken(WMText *tPtr, char *token, short tk) -{ - short mode=0; /* 0 starts, 1 closes */ - void *tb= NULL; - int prepend = WMGetTextInsertType(tPtr); - - while(*token && isspace(*(token))) token++; - if(*token == '/') { - token++; - mode = 1; - while(isspace(*(token))) token++; - } - - if(strlen(token)==1) { - /* nice and fast for small tokens... no need for too much brain - power here */ - switch(TOLOWER(*token)) { - case 'i': - if(!mode) { - cfmt.cfont = WMGetFontItalic(scr, cfmt.cfont); - WMPutInBag(cfmt.fonts, (void *)cfmt.cfont); - } else { /*dun wanna remove the baseFont eh? */ - int count = WMGetBagItemCount(cfmt.fonts); - if(count>1) - WMDeleteFromBag(cfmt.fonts, count-1); - cfmt.cfont = (WMFont *)WMGetFromBag(cfmt.fonts, - WMGetBagItemCount(cfmt.fonts)-1); - } break; - case 'b': - if(!mode) { - cfmt.cfont = WMGetFontBold(scr, cfmt.cfont); - WMPutInBag(cfmt.fonts, (void *)cfmt.cfont); - } else { /*dun wanna remove the baseFont eh? */ - int count = WMGetBagItemCount(cfmt.fonts); - if(count>1) - WMDeleteFromBag(cfmt.fonts, count-1); - cfmt.cfont = (WMFont *)WMGetFromBag(cfmt.fonts, - WMGetBagItemCount(cfmt.fonts)-1); - } break; - case 'p': - cfmt.first = True; - tb = WMCreateTextBlockWithText(NULL, cfmt.cfont, - cfmt.ccolor, cfmt.first, 0); - WMSetTextBlockProperties(tb, cfmt.first, False, (cfmt.u?1:0), 0, cfmt.margins); - //WMAppendTextBlock(tPtr, tb); - cfmt.first = False; - break; - case 'u': cfmt.u = !mode; break; - } - } else { /* the tag is, as far as I'm concerned, useless */ - if(mystrcasecmp(token, "br")) { - cfmt.first = True; - } - else if(mystrcasecmp(token, "ul")) { - if(mode) { - if(cfmt.ul>1) cfmt.ul--; - } else cfmt.ul++; - if(cfmt.ul) { - cfmt.bmargin = cfmt.ul*30; - cfmt.fmargin = cfmt.bmargin-10; - } else cfmt.fmargin = cfmt.bmargin = 0; - } else if(mystrcasecmp(token, "li")) { - cfmt.first = True; -//change margins... create a new margin.... - //(cfmt.fmargin, cfmt.bmargin, - } else if(mystrcasecmp(token, "align")) - ;//printf("align"); - else if(mystrcasecmp(token, "img")) { - if(!mode) { - char *mark=NULL; - WMPixmap *pixmap; - token+=3; - while(isspace(*(token))) token++; - do { - switch(TOLOWER(*token)) { - case 's': - if(TOLOWER(*(1+token)) == 'r' && TOLOWER(*(2+token)) == 'c') { - mark = strchr(token, '='); - if(mark) { - char img[256], *iptr; - token = mark+1; - if(!token) return; - sscanf(token, "%s", img); - iptr = img; - if(*img == '\"') { img[strlen(img)-1] = 0; iptr++;} - pixmap = WMCreatePixmapFromFile(scr, iptr); - if(pixmap) { - tb = WMCreateTextBlockWithPixmap(pixmap, - iptr, cfmt.ccolor, cfmt.first, 0); - WMSetTextBlockProperties(tb, cfmt.first, - False, (cfmt.u?1:0), 0, cfmt.margins); - WMAppendTextBlock(tPtr, tb); - cfmt.first = False; - } - printf("[%s]\n", iptr); - } } break; } } while(*(token++)); - } - } else if(mystrcasecmp(token, "font")) { -#if 0 - if(mode) { - cfmt.cfont = (WMFont *)WMGetFromBag(cfmt.fonts, - WMGetBagItemCount(cfmt.fonts)-1); - } else - (WMColor *)WMGetFromBag(cfmt.colors, - WMGetBagItemCount(cfmt.colors)-1), -#endif - } - else if(mystrcasecmp(token, "center")) { -printf("center\n"); - if(mode) cfmt.align = WALeft; - else cfmt.align = WACenter; - cfmt.first = True; -//change margins... - } - } - - - - - //printf("parse token (%s)[%s]\n", mode?"close":"open", token); -#if 0 - i=0; - //while(*token && !isspace(*(token))) token++; -//printf("A:%d a:%d z%d Z%d\n", '1', 'a', 'Z', 'z'); - do { - if(!mm) { - if(c>=65 && c<=122) { major[i++] = c; - } else if(c==' ' || c=='='){ major[i] = 0; i=0; mm=1; - printf("\nmajor: [%s]", major);} - } else { - if(c!=' ') { - minor[i++] = c; - } else { minor[i] = 0; i=0; printf(" minor: [%s] ", minor);} - } - }while((c = *(++token))); -#endif - - - //printf("parse token (%s)[%s]\n", mode?"close":"open", token); -} - -void HTMLParser(WMWidget *w, void *clientData) -{ - static short init=1; /* have we been here at least once before? */ - char *stream = (char *) clientData; - WMText *tPtr = (WMText *)w; - void *tb = NULL; - char c; - #define MAX_TOKEN_SIZE 255 - char token[MAX_TOKEN_SIZE+1]; - #define MAX_TEXT_SIZE 1023 - char text[MAX_TEXT_SIZE+1]; - short mode=0; - short tk=0, textlen=0; - short wasspace=0; - - if(!tPtr || !stream) - return; - - cfmt.type = WMGetTextInsertType(tPtr); - if(1||init) { - cfmt.fonts = WMCreateBag(4); /* there sould always be at least 1 font... */ - cfmt.cfont = WMGetTextDefaultFont(tPtr); - WMPutInBag(cfmt.fonts, (void *)cfmt.cfont); - cfmt.colors = WMCreateBag(4); - cfmt.ccolor = WMBlackColor(scr); - WMPutInBag(cfmt.colors, (void *)cfmt.ccolor); - cfmt.i = cfmt.b = cfmt.u = cfmt.ul = 0; - cfmt.align = WALeft; - cfmt.fmargin = cfmt.bmargin = 0; - init = 0; - } - -#if 0 - if(strlen(stream) == 1 && stream[0] == '\n') { - /* sometimes if the text entered is a single char AND is a newline, - the user prolly typed it */ - cfmt.para = (cfmt.actions.createParagraph) (cfmt.fmargin, cfmt.bmargin, - WMWidgetWidth(tPtr)-30, NULL, 0, cfmt.align); - (cfmt.actions.insertParagraph) (tPtr, cfmt.para, cfmt.type); - return; - } -#endif - - -/* -*/ - - while( (c=*(stream++))) { -//printf("%c", c); - if(c == '\n' || c =='\t') - //c = ' '; //continue; - continue; - if(c == ' ') { - if(wasspace) - continue; - wasspace = 1; - }else wasspace = 0; - - if(c == '<' && !mode) { - mode=1; - if(textlen>0) { - text[textlen] = 0; - tb = WMCreateTextBlockWithText(text, cfmt.cfont, - cfmt.ccolor, cfmt.first, textlen); - WMSetTextBlockProperties(tb, cfmt.first, False, (cfmt.u?1:0), 0, cfmt.margins); - WMAppendTextBlock(tPtr, tb); - cfmt.first = False; -//printf("%s\n", text); - } - textlen = 0; - } else if(c == '>' && mode) { - token[tk] = 0; - if(tk>0) parseToken(tPtr, token, tk); - mode=0; - tk=0; - } else { - if(mode) { - if(tk < MAX_TOKEN_SIZE) token[tk++] = c; - } else if(textlen < MAX_TEXT_SIZE) text[textlen++] = c; - } - } - - if(tk>0) { token[tk] = 0; parseToken(tPtr, token, tk);} - if(textlen>0) { - text[textlen] = 0; - //printf("%s\n", text); - tb = WMCreateTextBlockWithText(text, - (WMFont *)WMGetFromBag(cfmt.fonts, - WMGetBagItemCount(cfmt.fonts)-1), - (WMColor *)WMGetFromBag(cfmt.colors, - WMGetBagItemCount(cfmt.colors)-1), - cfmt.first, textlen); - WMSetTextBlockProperties(tb, cfmt.first, False, (cfmt.u?1:0), 0, cfmt.margins); - WMAppendTextBlock(tPtr, tb); - cfmt.first = False; - } - -} - - -/* ================= the driver ================== */ - -Display *dpy; - -static void -buttonPressCB(WMWidget *w, void *client) -{ - WMText *tPtr = (WMText *)client; - WMAppendTextStream(tPtr, NULL); - XBell(dpy, 0); - WMAppendTextStream(tPtr, - "

You just had to press that button, didn't you? " - "Well, this sort of thing is bound to happen when you go about " - " pressing buttons :-)" - "

Cheers,

Nwanua"); - WMRefreshText(tPtr, 0, 0); -} - -int -main(int argc, char **argv) -{ - WMWidget *win; - WMText *text; - WMRulerMargins margins; - void *tb = NULL; - - printf("copy and paste this string: \n - here is some bold italic underlined text :-) \n"); - - WMInitializeApplication("WMText", &argc, argv); - dpy = XOpenDisplay(NULL); - if(!dpy) { printf("no display? *sniff* :~( "); exit(1);} - - scr = WMCreateSimpleApplicationScreen(dpy); - - win = WMCreateWindow(scr, "WMText Test"); - WMRealizeWidget(win); - WMResizeWidget(win, 500, 300); - //WMResizeWidget(win, 900, 600); - WMSetWindowTitle(win,"WMText Test"); - WMSetWindowCloseAction(win, Close, NULL); - - text = WMCreateText(win); - WMRealizeWidget(text); - WMSetTextHasRuler(text, True); - //WMSetTextHasHorizontalScroller(text, True); - WMResizeWidget(text, 480, 280); - WMMoveWidget(text, 10, 10); - WMSetTextRelief(text, WRSunken); - WMSetTextHasVerticalScroller(text, True); - WMSetTextUsesMonoFont(text, !True); - WMSetTextParser(text, HTMLParser); -#if 0 - WMShowTextRuler(text, True); - WMSetTextUseFixedPitchFont(text, False); - WMSetTextHasRuler(text, True); - WMSetTextHasVerticalScroller(text, True); - //WMSetTextHasHorizontalScroller(text, True); - WMFreezeText(text); -#endif - - //margins = WMGetTextRulerMargins(text); - - -#if 1 - - - WMAppendTextStream(text, -"README:

\ -WINGs is a small widget set with \ -a very nice look and feel. Its API is inspired \ -and its implementation borrows some ideas from interesting places.\ -

-The library is limited and its design is a little sloppy, \ -so it's not intended to build large or complex applications, just -small and complex ones. :-)\ -

Apart from the usual buttons and labels, it has some \ -interesting widgets like this list widget: "); - - { - WMList *list = WMCreateList(text); - char t[20]; - int i; - - WMResizeWidget(list, 60, 60); - for (i=0; i<7; i++) { - sprintf(t, "Item %i", i); - WMAddListItem(list, t); - } - - tb = WMCreateTextBlockWithObject(list, "{a list object or somesuch}", - WMBlackColor(scr), False, 0); - WMAppendTextBlock(text, tb); - - } - - - WMAppendTextStream(text, " a colour well such as this one: "); - { - WMColorWell *well; - well = WMCreateColorWell(text); - WMResizeWidget(well, 60, 40); - WMSetColorWellColor(well, - WMCreateRGBColor(scr, 0, 0, 0x8888, True)); - tb = WMCreateTextBlockWithObject(well, "{a button object}", - WMBlackColor(scr), False, 0); - WMAppendTextBlock(text, tb); - } - - WMAppendTextStream(text, - ", as well as a text widget: "); - - { - WMText *te = WMCreateText(text); - WMResizeWidget(te, 140, 120); - WMSetTextParser(te, HTMLParser); - WMSetTextRelief(te, WRFlat); - // WMSetTextBackgroundColor(te, WMCreateNamedColor(scr, "Red", False)); - WMSetTextDefaultFont(te, WMSystemFontOfSize(scr, 10)); - WMAppendTextStream(te, "into which you can easily embed other " - "WINGs objects (such as this text object), " - " as well as pixmaps (thus) " - "without breaking a sweat (type in here)"); - tb = WMCreateTextBlockWithObject(te, "{a text object}", - WMBlackColor(scr), False, 0); - WMAppendTextBlock(text, tb); - WMSetTextHasVerticalScroller(te, True); - WMSetTextHasHorizontalScroller(te, True); - WMRefreshText(te, 0, 0); - } - - { - WMText *te = WMCreateText(text); - WMResizeWidget(te, 120, 90); - WMSetTextParser(te, HTMLParser); - WMSetTextRelief(te, WRFlat); - // WMSetTextBackgroundColor(te, WMCreateNamedColor(scr, "Red", False)); - WMSetTextDefaultFont(te, WMSystemFontOfSize(scr, 10)); - WMAppendTextStream(te, "I always wanted to be able to have " - "a multi-column text editor in Unix for my reports, " - " now all I have to do is wait for someone to code it :-P"); - tb = WMCreateTextBlockWithObject(te, "{a text object}", - WMBlackColor(scr), False, 0); - WMAppendTextBlock(text, tb); - WMSetTextHasVerticalScroller(te, False); - WMRefreshText(te, 0, 0); - } - - - - - - WMAppendTextStream(text, -" .

Not bad eh? \ -

SinceWINGsis \ -written in C and is sort of \ -low-level, it is \ -small and faster than say, Motif or even Athena (just you try -embedding and clicking on buttons"); - - { - WMButton *b = WMCreateCommandButton(text); - WMSetButtonText(b, "like me"); - WMSetButtonAction(b, buttonPressCB, text); - WMResizeWidget(b, 60, 15); - tb = WMCreateTextBlockWithObject(b, "{a button object}", - WMBlackColor(scr), False, 0); - WMAppendTextBlock(text, tb); - } - - WMAppendTextStream(text, -" with those other tool-kits :-).

Knowing Xlib will help you to \ -workaround some of its limitations, although you'll probably be able to \ -write something like a trivial tic-tac-toe game "); - - { - WMTextField *t = WMCreateTextField(text); - WMInsertTextFieldText(t, "or an interesting text editor", 0); - WMResizeWidget(t, 160, 20); - WMSetTextFieldBordered(t, True); - WMSetTextFieldBeveled(t, True); - tb = WMCreateTextBlockWithObject(t, "{a textfield object}", - WMGrayColor(scr), False, 0); - WMAppendTextBlock(text, tb); - } - - - WMAppendTextStream(text, " without knowing much Xlib. " - "

(BTW, don't press that button that is screeming" - " to be pressed!"); -#endif - - - -// WMThawText(text); - WMRefreshText(text, 0, 0); - -/* - WMAddNotificationObserver(NotificationObserver, win, - WMViewSizeDidChangeNotification, WMWidgetView(win)); -*/ - WMSetViewNotifySizeChanges(WMWidgetView(win), True); - WMMapSubwidgets(win); - WMMapWidget(win); - - WMScreenMainLoop(scr); - return 0; -} - diff --git a/WINGs/WINGs.h b/WINGs/WINGs.h index ac47bb7c..fab8c1c6 100644 --- a/WINGs/WINGs.h +++ b/WINGs/WINGs.h @@ -393,8 +393,7 @@ typedef struct WMInputPanel { /* WMRuler: */ typedef struct { - unsigned short *tabs; /* a growable array of tabstops */ - unsigned short ntabstops; /* how many there are */ + WMArray *tabs; /* a growable array of tabstops */ unsigned short left; /* left margin marker */ unsigned short right; /* right margin marker */ unsigned short first; /* indentation marker for first line only */ @@ -699,6 +698,11 @@ WMFont *WMBoldSystemFontOfSize(WMScreen *scrPtr, int size); XFontSet WMGetFontFontSet(WMFont *font); +WMFont * WMGetFontPlain(WMScreen *scr, WMFont *font); +WMFont * WMGetFontBold(WMScreen *scr, WMFont *font); +WMFont * WMGetFontItalic(WMScreen *scr, WMFont *font); +WMFont * WMGetFontOfSize(WMScreen *scr, WMFont *font, int size); + /* ....................................................................... */ WMPixmap *WMRetainPixmap(WMPixmap *pixmap); @@ -1499,11 +1503,11 @@ char * WMGetTextStream(WMText *tPtr); /* free the text */ char * WMGetTextSelected(WMText *tPtr); -/* destroy the bag */ -WMBag * WMGetTextStreamIntoBag(WMText *tPtr); +/* destroy the array */ +WMArray * WMGetTextStreamIntoArray(WMText *tPtr); -/* destroy the bag */ -WMBag * WMGetTextSelectedIntoBag(WMText *tPtr); +/* destroy the array */ +WMArray* WMGetTextSelectedIntoArray(WMText *tPtr); void WMSetTextSelectionColor(WMText *tPtr, WMColor *color); @@ -1518,10 +1522,10 @@ void WMSetTextParser(WMText *tPtr, WMAction *parser); void WMSetTextWriter(WMText *tPtr, WMAction *writer); void *WMCreateTextBlockWithObject(WMText *tPtr, WMWidget *w, char *description, - WMColor *color, unsigned short first, unsigned short reserved); + WMColor *color, unsigned short first, unsigned short extraInfo); void *WMCreateTextBlockWithPixmap(WMText *tPtr, WMPixmap *p, char *description, - WMColor *color, unsigned short first, unsigned short reserved); + WMColor *color, unsigned short first, unsigned short extraInfo); void *WMCreateTextBlockWithText(WMText *tPtr, char *text, WMFont *font, WMColor *color, unsigned short first, unsigned short length); diff --git a/WINGs/fontmanager.c b/WINGs/fontmanager.c index dce8f9ff..9ae01f61 100644 --- a/WINGs/fontmanager.c +++ b/WINGs/fontmanager.c @@ -30,48 +30,58 @@ changeFontProp(char *fname, char *newprop, int which) WMFont * -WMGetFontPlain(WMScreen *scrPtr, WMFont *font) +WMGetFontPlain(WMScreen *scr, WMFont *font) { - if(!scrPtr || !font) - return NULL; + if(!scr || !font) + return font; + return font; } WMFont * -WMGetFontBold(WMScreen *scrPtr, WMFont *font) +WMGetFontBold(WMScreen *scr, WMFont *font) { WMFont *newfont=NULL; char fname[256]; - if(!scrPtr || !font) - return NULL; + + if(!scr || !font) + return font; + snprintf(fname, 255, font->name); changeFontProp(fname, "bold", 2); - newfont = WMCreateNormalFont(scrPtr, fname); + newfont = WMCreateNormalFont(scr, fname); + if(!newfont) newfont = font; + return newfont; } WMFont * -WMGetFontItalic(WMScreen *scrPtr, WMFont *font) +WMGetFontItalic(WMScreen *scr, WMFont *font) { WMFont *newfont=NULL; char fname[256]; - if(!scrPtr || !font) - return NULL; + + if(!scr || !font) + return font; + snprintf(fname, 255, font->name); changeFontProp(fname, "o", 3); - newfont = WMCreateNormalFont(scrPtr, fname); + newfont = WMCreateNormalFont(scr, fname); + if(!newfont) newfont = font; + return newfont; } WMFont * -WMGetFontOfSize(WMScreen *scrPtr, WMFont *font, int size) +WMGetFontOfSize(WMScreen *scr, WMFont *font, int size) { - if(!scrPtr || !font || size<1) - return NULL; + if(!scr || !font || size<1) + return font; + return font; } diff --git a/WINGs/wtext.c b/WINGs/wtext.c index 30462138..0ceed11d 100644 --- a/WINGs/wtext.c +++ b/WINGs/wtext.c @@ -18,6 +18,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + #include "WINGsP.h" #include #include @@ -31,6 +32,8 @@ WMFont * WMGetFontOfSize(WMScreen *scrPtr, WMFont *font, int size); /* TODO: * + * - FIX html parser: 1. foo should STILL BE BOLD! + * - 2. " foo > bar " should not confuse it. * - change Bag stuffs to WMArray * - assess danger of destroying widgets whose actions link to other pages * - integrate WMGetFont* functions into WINGs proper (fontpanel)? @@ -154,6 +157,7 @@ typedef struct W_Text { WMAction *parser; WMAction *writer; + WMTextDelegate *delegate; WMRulerMargins *margins; /* an array of margins */ @@ -165,7 +169,6 @@ typedef struct W_Text { unsigned int ownsSelection:1; /* "I ownz the current selection!" */ unsigned int pointerGrabbed:1;/* "heh, gib me pointer" */ unsigned int buttonHeld:1; /* the user is holding down the button */ - unsigned int waitingForSelection:1; /* dum dee dumm... */ unsigned int extendSelection:1; /* shift-drag to select more regions */ unsigned int rulerShown:1; /* whether the ruler is shown or not */ @@ -178,7 +181,9 @@ typedef struct W_Text { unsigned int needsRefresh:1; /* in case of Append/Deletes */ unsigned int ignoreNewLine:1;/* turn it into a ' ' in streams > 1 */ unsigned int laidOut:1; /* have the TextBlocks all been laid out */ + unsigned int waitingForSelection:1; /* I don't wanna wait in vain... */ unsigned int prepend:1; /* prepend=1, append=0 (for parsers) */ + unsigned int parsingHTML:1; /* how to interpret a stream of text */ WMAlignment alignment:2; /* the alignment for text */ WMReliefType relief:3; /* the relief to display with */ unsigned int RESERVED:2; @@ -186,6 +191,14 @@ typedef struct W_Text { } Text; +#define NOTIFY(T,C,N,A) { WMNotification *notif = WMCreateNotification(N,T,A);\ + if ((T)->delegate && (T)->delegate->C)\ + (*(T)->delegate->C)((T)->delegate,notif);\ + WMPostNotification(notif);\ + WMReleaseNotification(notif);} + + + /* * A hack to speed up caseless_equal. Thanks to Quincey Koziol for * developing it for the "chimera" folks so I could use it 7 years later ;-) @@ -206,7 +219,7 @@ static unsigned char map_table[256] = { 220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237, 238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255}; -#define MAX_TB_PER_LINE 64 +void HTMLParser(Text *tPtr, char *stream); #define MAX_TOKEN_SIZE 255 #define MAX_TEXT_SIZE 1023 @@ -251,7 +264,6 @@ getMarginNumber(Text *tPtr, WMRulerMargins *margins) - static int newMargin(Text *tPtr, WMRulerMargins *margins) { @@ -1160,6 +1172,9 @@ layOutLine(Text *tPtr, myLineItems *items, int nitems, int x, int y) TextBlock *tb; TextBlock *tbsame=NULL; + if(!items || nitems == 0) + return 0; + for(i=0; iflags.laidOut; /* line height changed? */ - int prev_y, nitems=0, x=0, y=0, lw = 0, width=0; + unsigned int x, y=0, prev_y, lw = 0, width=0, bmargin; + + Bool lhc = !tPtr->flags.laidOut; /* line height changed? */ + char *start=NULL, *mark=NULL; - int begin, end; + unsigned int begin, end; if (tPtr->flags.frozen) return; @@ -1316,6 +1335,9 @@ layOutDocument(Text *tPtr) return; tPtr->docWidth = tPtr->visible.w; + x = 0;//tPtr->margins[tb->marginN].first; +printf("x:%d\n", x); + bmargin = tPtr->margins[tb->marginN].body; if (0&&tPtr->flags.laidOut) { tb = tPtr->currentTextBlock; @@ -1350,9 +1372,10 @@ printf("2 prev_y %d \n\n", tb->sections[tb->nsections-1]._y); tb->nsections = 0; } - if (tb->first) { + if (tb->first && tb != tPtr->firstTextBlock) { y += layOutLine(tPtr, items, nitems, x, y); - x = 0;//tb->margins.first; + x = 0*tPtr->margins[tb->marginN].first; + bmargin = tPtr->margins[tb->marginN].body; nitems = 0; lw = 0; } @@ -1371,14 +1394,18 @@ printf("%d %d\n", width, tPtr->visible.w); } lw += width; - if (lw >= tPtr->visible.w - x - || nitems >= MAX_TB_PER_LINE) { + if (lw >= tPtr->visible.w - x ) { y += layOutLine(tPtr, items, nitems, x, y); nitems = 0; - x = 0;//tb->margins.first; + x = 0*bmargin; lw = width; } + if(nitems + 1> itemsSize) { + items = wrealloc(items, + (++itemsSize)*sizeof(myLineItems)); + } + items[nitems].tb = tb; items[nitems].begin = 0; items[nitems].end = 0; @@ -1421,14 +1448,18 @@ printf("%d %d\n", width, tPtr->visible.w); lw += width; } - if ((lw >= tPtr->visible.w - x) - || nitems >= MAX_TB_PER_LINE) { + if (lw >= tPtr->visible.w - x) { y += layOutLine(tPtr, items, nitems, x, y); lw = width; - x = 0;//tb->margins.first; + x = bmargin; nitems = 0; } + if(nitems + 1 > itemsSize) { + items = wrealloc(items, + (++itemsSize)*sizeof(myLineItems)); + } + items[nitems].tb = tb; items[nitems].begin = begin; items[nitems].end = end; @@ -1463,6 +1494,9 @@ printf("%d %d\n", width, tPtr->visible.w); } tPtr->flags.laidOut = True; + + if(items && itemsSize > 0) + wfree(items); } @@ -1497,9 +1531,9 @@ textDidResize(W_ViewDelegate *self, WMView *view) } } - tPtr->visible.x = (tPtr->vS)?21:1; + tPtr->visible.x = (tPtr->vS)?24:4; tPtr->visible.y = (tPtr->ruler && tPtr->flags.rulerShown)?43:3; - tPtr->visible.w = tPtr->view->size.width - tPtr->visible.x - 2; + tPtr->visible.w = tPtr->view->size.width - tPtr->visible.x - 8; tPtr->visible.h = tPtr->view->size.height - tPtr->visible.y; tPtr->visible.h -= (tPtr->hS)?20:0; tPtr->margins[0].right = tPtr->visible.w; @@ -1759,39 +1793,6 @@ selectRegion(Text *tPtr, int x, int y) } -static void -pasteText(WMView *view, Atom selection, Atom target, Time timestamp, - void *cdata, WMData *data) -{ - Text *tPtr = (Text *)view->self; - char *str; - - tPtr->flags.waitingForSelection = False; - if (data) { - str = (char*)WMDataBytes(data); - if (0&&tPtr->parser) { - /* parser is not yet well behaved to do this properly..*/ - (tPtr->parser) (tPtr, (void *) str); - } else { - insertTextInteractively(tPtr, str, strlen(str)); - } - } else { - int n; - str = XFetchBuffer(tPtr->view->screen->display, &n, 0); - if (str) { - str[n] = 0; - if (0&&tPtr->parser) { - /* parser is not yet well behaved to do this properly..*/ - (tPtr->parser) (tPtr, (void *) str); - } else { - insertTextInteractively(tPtr, str, n); - } - XFree(str); - } - } -} - - static void releaseSelection(Text *tPtr) { @@ -1808,34 +1809,30 @@ releaseSelection(Text *tPtr) WMRefreshText(tPtr, tPtr->vpos, tPtr->hpos); } -static WMData * -requestHandler(WMView *view, Atom selection, Atom target, - void *cdata, Atom *type) + +WMData* +requestHandler(WMView *view, Atom selection, Atom target, void *cdata, + Atom *type) { Text *tPtr = view->self; Display *dpy = tPtr->view->screen->display; + Atom _TARGETS; Atom TEXT = XInternAtom(dpy, "TEXT", False); Atom COMPOUND_TEXT = XInternAtom(dpy, "COMPOUND_TEXT", False); - Atom _TARGETS; - WMData *data; - - if (target == XA_STRING || target == TEXT || target == COMPOUND_TEXT) { - char *text = WMGetTextSelected(tPtr); + WMData *data = NULL; - if(text) { - WMData *data = WMCreateDataWithBytes(text, strlen(text)); - WMSetDataFormat(data, 8); - wfree(text); - *type = target; - return data; - } - } else if(target == XInternAtom(dpy, "PIXMAP", False)) { - data = WMCreateDataWithBytes("paste a pixmap", 14); - WMSetDataFormat(data, 8); + if (target == XA_STRING || target == TEXT || target == COMPOUND_TEXT) { + char *text = WMGetTextSelected(tPtr); + + if (text) { +printf("got text [%s]\n", text); + data = WMCreateDataWithBytes(text, strlen(text)); + WMSetDataFormat(data, 8); + } *type = target; return data; - } + } else printf("didn't get it\n"); _TARGETS = XInternAtom(dpy, "TARGETS", False); if (target == _TARGETS) { @@ -1853,10 +1850,9 @@ requestHandler(WMView *view, Atom selection, Atom target, *type = target; return data; } - + return NULL; -} - +} static void lostHandler(WMView *view, Atom selection, void *cdata) @@ -1868,15 +1864,16 @@ static WMSelectionProcs selectionHandler = { requestHandler, lostHandler, NULL }; + static void ownershipObserver(void *observerData, WMNotification *notification) { - WMText *to = (WMText *)observerData; - WMText *tw = (WMText *)WMGetNotificationClientData(notification); - if (to != tw) - lostHandler(to->view, XA_PRIMARY, NULL); + // if (observerData != WMGetNotificationClientData(notification)) + lostHandler(WMWidgetView(observerData), XA_PRIMARY, NULL); +printf("lost ownership\n"); } + static void fontChanged(void *observerData, WMNotification *notification) { @@ -1902,15 +1899,16 @@ handleTextKeyPress(Text *tPtr, XEvent *event) if (((XKeyEvent *) event)->state & ControlMask) control_pressed = True; buffer[XLookupString(&event->xkey, buffer, 1, &ksym, NULL)] = 0; - + switch(ksym) { case XK_Right: - WMScrollText(tPtr, -14); +WMScrollText(tPtr, -14); case XK_Left: { - //TextBlock *tb = tPtr->currentTextBlock; - //int x = tPtr->cursor.x + tPtr->visible.x; - //int y = tPtr->visible.y + tPtr->cursor.y + tPtr->cursor.h; + TextBlock *tb = tPtr->currentTextBlock; + int x = tPtr->cursor.x + tPtr->visible.x; + int y = tPtr->visible.y + tPtr->cursor.y + tPtr->cursor.h; + int w, pos; #if 0 if(!tb) @@ -1930,7 +1928,7 @@ handleTextKeyPress(Text *tPtr, XEvent *event) 3 + tPtr->visible.y + tPtr->cursor.y + tPtr->cursor.h - tPtr->vpos); if(x == tPtr->cursor.x + tPtr->visible.x) { - printf("same %d %d\n", x, tPtr->cursor.x + tPtr->visible.x); +printf("same %d %d\n", x, tPtr->cursor.x + tPtr->visible.x); cursorToTextPosition(tPtr, tPtr->visible.x, 3 + tPtr->visible.y + tPtr->cursor.y + tPtr->cursor.h); } @@ -2023,8 +2021,6 @@ handleActionEvents(XEvent *event, void *data) return; } - if (tPtr->flags.waitingForSelection) - return; if (tPtr->flags.focused) { XGrabPointer(dpy, W_VIEW(tPtr)->window, False, PointerMotionMask|ButtonPressMask|ButtonReleaseMask, @@ -2046,15 +2042,20 @@ handleActionEvents(XEvent *event, void *data) case MotionNotify: + if (tPtr->flags.pointerGrabbed) { tPtr->flags.pointerGrabbed = False; XUngrabPointer(dpy, CurrentTime); } + if(tPtr->flags.waitingForSelection) + break; + if ((event->xmotion.state & Button1Mask)) { if (!tPtr->flags.ownsSelection) { - WMCreateSelectionHandler(tPtr->view, XA_PRIMARY, - event->xbutton.time, &selectionHandler, NULL); + WMCreateSelectionHandler(tPtr->view, + XA_PRIMARY, event->xbutton.time, + &selectionHandler, NULL); tPtr->flags.ownsSelection = True; } selectRegion(tPtr, event->xmotion.x, event->xmotion.y); @@ -2063,11 +2064,24 @@ handleActionEvents(XEvent *event, void *data) case ButtonPress: + tPtr->flags.buttonHeld = True; + + if (tPtr->flags.pointerGrabbed) { + tPtr->flags.pointerGrabbed = False; + XUngrabPointer(dpy, CurrentTime); + break; + } + + if (tPtr->flags.waitingForSelection) + break; + if (tPtr->flags.extendSelection) { selectRegion(tPtr, event->xmotion.x, event->xmotion.y); return; } + + if (event->xbutton.button == Button1) { if (!tPtr->flags.focused) { @@ -2079,29 +2093,19 @@ handleActionEvents(XEvent *event, void *data) releaseSelection(tPtr); cursorToTextPosition(tPtr, event->xmotion.x, event->xmotion.y); paintText(tPtr); - if (tPtr->flags.pointerGrabbed) { - tPtr->flags.pointerGrabbed = False; - XUngrabPointer(dpy, CurrentTime); - break; - } - } + } - if (event->xbutton.button == WINGsConfiguration.mouseWheelDown) + if (event->xbutton.button + == WINGsConfiguration.mouseWheelDown) { WMScrollText(tPtr, -16); - else if (event->xbutton.button == WINGsConfiguration.mouseWheelUp) - WMScrollText(tPtr, 16); - break; - - case ButtonRelease: - tPtr->flags.buttonHeld = False; - if (tPtr->flags.pointerGrabbed) { - tPtr->flags.pointerGrabbed = False; - XUngrabPointer(dpy, CurrentTime); break; - } - if (event->xbutton.button == WINGsConfiguration.mouseWheelDown - || event->xbutton.button == WINGsConfiguration.mouseWheelUp) + } + + if (event->xbutton.button + == WINGsConfiguration.mouseWheelUp) { + WMScrollText(tPtr, 16); break; + } if (event->xbutton.button == Button2) { char *text = NULL; @@ -2112,25 +2116,48 @@ handleActionEvents(XEvent *event, void *data) break; } +#if 0 if (!WMRequestSelection(tPtr->view, XA_PRIMARY, XA_STRING, event->xbutton.time, pasteText, NULL)) { +#endif +{ + text = XFetchBuffer(tPtr->view->screen->display, &n, 0); - if (text) { + + if (text) { text[n] = 0; - if (0&&tPtr->parser) { - /* parser is not yet well behaved to do this properly..*/ + + if (tPtr->parser) (tPtr->parser) (tPtr, (void *) text); - } else { - insertTextInteractively(tPtr, text, n-1); - } + else + insertTextInteractively(tPtr, text, n); + XFree(text); - } else tPtr->flags.waitingForSelection = True; - } } + NOTIFY(tPtr, didChange, WMTextDidChangeNotification, + (void*)WMInsertTextEvent); - break; + } else { + tPtr->flags.waitingForSelection = True; + } + } + break; + } - } + case ButtonRelease: + + tPtr->flags.buttonHeld = False; + + if (tPtr->flags.pointerGrabbed) { + tPtr->flags.pointerGrabbed = False; + XUngrabPointer(dpy, CurrentTime); + break; + } + + if (tPtr->flags.waitingForSelection) + break; + } + } @@ -2199,6 +2226,7 @@ handleEvents(XEvent *event, void *data) #endif break; + case DestroyNotify: clearText(tPtr); if(tPtr->hS) @@ -2229,10 +2257,10 @@ handleEvents(XEvent *event, void *data) static void -insertPlainText(WMText *tPtr, char *text) +insertText(WMText *tPtr, char *text) { - char *start, *mark; void *tb = NULL; + char *start, *mark; if (!text) { clearText(tPtr); @@ -2376,7 +2404,7 @@ getStream(WMText *tPtr, int sel) { TextBlock *tb = NULL; char *text = NULL; - unsigned long length = 0, where = 0; + unsigned long where = 0; if (!tPtr) return NULL; @@ -2390,30 +2418,6 @@ getStream(WMText *tPtr, int sel) return text; } - - /* first, how large a buffer would we want? */ - while (tb) { - - if (!tb->graphic || (tb->graphic && !tPtr->flags.monoFont)) { - - - if (!sel || (tb->graphic && tb->selected)) { - length += tb->used; - if (!tPtr->flags.ignoreNewLine && (tb->first || tb->blank)) - length += 1; - if (tb->graphic) - length += 2; /* field markers 0xFA and size */ - } else if (sel && tb->selected) { - length += (tb->s_end - tb->s_begin); - if (!tPtr->flags.ignoreNewLine && (tb->first || tb->blank)) - length += 1; - } - } - - tb = tb->next; - } - - text = wmalloc(length+1); /* +1 for the end of string, let's be nice */ tb = tPtr->firstTextBlock; while (tb) { @@ -2421,18 +2425,29 @@ getStream(WMText *tPtr, int sel) if (!sel || (tb->graphic && tb->selected)) { - if (!tPtr->flags.ignoreNewLine && (tb->first || tb->blank)) + if (!tPtr->flags.ignoreNewLine && (tb->first || tb->blank)) { + text = wrealloc(text, 1); text[where++] = '\n'; + } + if(tb->graphic) { + text = wrealloc(text, 2); text[where++] = 0xFA; text[where++] = tb->used; } + + text = wrealloc(text, tb->used); memcpy(&text[where], tb->text, tb->used); where += tb->used; } else if (sel && tb->selected) { - if (!tPtr->flags.ignoreNewLine && (tb->first || tb->blank)) + + if (!tPtr->flags.ignoreNewLine && (tb->first || tb->blank)) { + text = wrealloc(text, 1); text[where++] = '\n'; + } + + text = wrealloc(text, (tb->s_end - tb->s_begin)); memcpy(&text[where], &tb->text[tb->s_begin], tb->s_end - tb->s_begin); where += tb->s_end - tb->s_begin; @@ -2442,6 +2457,7 @@ getStream(WMText *tPtr, int sel) tb = tb->next; } + text = wrealloc(text, 1); /* +1 for the end of string, let's be nice */ text[where] = 0; return text; } @@ -2555,7 +2571,8 @@ WMCreateText(WMWidget *parent) |KeyReleaseMask|KeyPressMask|Button1MotionMask, handleActionEvents, tPtr); - WMAddNotificationObserver(ownershipObserver, tPtr, "_lostOwnership", tPtr); + WMAddNotificationObserver(ownershipObserver, tPtr, + "_lostOwnership", tPtr); #if 0 WMSetViewDragDestinationProcs(tPtr->view, &_DragDestinationProcs); @@ -2606,7 +2623,6 @@ WMCreateText(WMWidget *parent) tPtr->flags.ownsSelection = False; tPtr->flags.pointerGrabbed = False; tPtr->flags.buttonHeld = False; - tPtr->flags.waitingForSelection = False; tPtr->flags.extendSelection = False; tPtr->flags.frozen = False; tPtr->flags.cursorShown = True; @@ -2615,8 +2631,10 @@ WMCreateText(WMWidget *parent) tPtr->flags.needsRefresh = False; tPtr->flags.ignoreNewLine = False; tPtr->flags.laidOut = False; + tPtr->flags.waitingForSelection = False; tPtr->flags.prepend = False; - tPtr->flags.relief = WRFlat; + tPtr->flags.parsingHTML = False; + tPtr->flags.relief = WRSunken; tPtr->flags.alignment = WALeft; return tPtr; @@ -2625,8 +2643,7 @@ WMCreateText(WMWidget *parent) void WMPrependTextStream(WMText *tPtr, char *text) { - if (!tPtr) - return; + CHECK_CLASS(tPtr, WC_Text); if(!text) releaseSelection(tPtr); @@ -2635,7 +2652,7 @@ WMPrependTextStream(WMText *tPtr, char *text) if (text && tPtr->parser) (tPtr->parser) (tPtr, (void *) text); else - insertPlainText(tPtr, text); + insertText(tPtr, text); tPtr->flags.needsRefresh = True; } @@ -2644,8 +2661,7 @@ WMPrependTextStream(WMText *tPtr, char *text) void WMAppendTextStream(WMText *tPtr, char *text) { - if (!tPtr) - return; + CHECK_CLASS(tPtr, WC_Text); if(!text) releaseSelection(tPtr); @@ -2654,7 +2670,7 @@ WMAppendTextStream(WMText *tPtr, char *text) if (text && tPtr->parser) (tPtr->parser) (tPtr, (void *) text); else - insertPlainText(tPtr, text); + insertText(tPtr, text); tPtr->flags.needsRefresh = True; @@ -2664,28 +2680,41 @@ WMAppendTextStream(WMText *tPtr, char *text) char * WMGetTextStream(WMText *tPtr) { + CHECK_CLASS(tPtr, WC_Text); return getStream(tPtr, 0); } char * WMGetTextSelected(WMText *tPtr) { + CHECK_CLASS(tPtr, WC_Text); return getStream(tPtr, 1); } WMBag * WMGetTextStreamIntoBag(WMText *tPtr) { + CHECK_CLASS(tPtr, WC_Text); return getStreamIntoBag(tPtr, 0); } WMBag * WMGetTextSelectedIntoBag(WMText *tPtr) { + CHECK_CLASS(tPtr, WC_Text); return getStreamIntoBag(tPtr, 1); } +void +WMSetTextDelegate(WMText *tPtr, WMTextDelegate *delegate) +{ + CHECK_CLASS(tPtr, WC_Text); + + tPtr->delegate = delegate; +} + + void * WMCreateTextBlockWithObject(WMText *tPtr, WMWidget *w, char *description, WMColor *color, @@ -2868,11 +2897,16 @@ WMPrependTextBlock(WMText *tPtr, void *vtb) if (!tPtr->lastTextBlock || !tPtr->firstTextBlock) { tb->next = tb->prior = NULL; + tb->first = True; tPtr->lastTextBlock = tPtr->firstTextBlock = tPtr->currentTextBlock = tb; return; } + if(!tb->first) { + tb->marginN = tPtr->currentTextBlock->marginN; + } + tb->next = tPtr->currentTextBlock; tb->prior = tPtr->currentTextBlock->prior; if (tPtr->currentTextBlock->prior) @@ -2911,11 +2945,16 @@ WMAppendTextBlock(WMText *tPtr, void *vtb) if (!tPtr->lastTextBlock || !tPtr->firstTextBlock) { tb->next = tb->prior = NULL; + tb->first = True; tPtr->lastTextBlock = tPtr->firstTextBlock = tPtr->currentTextBlock = tb; return; } + if(!tb->first) { + tb->marginN = tPtr->currentTextBlock->marginN; + } + tb->next = tPtr->currentTextBlock->next; tb->prior = tPtr->currentTextBlock; if (tPtr->currentTextBlock->next) @@ -3407,11 +3446,91 @@ WMFindInTextStream(WMText *tPtr, char *needle) wfree(haystack); return result; } + +/* would be nice to have in WINGs proper... */ +static void +changeFontProp(char *fname, char *newprop, int which) +{ + char before[128], prop[128], after[128]; + char *ptr, *bptr; + int part=0; + if(!fname || !prop) + return; + + ptr = fname; + bptr = before; + while (*ptr) { + if(*ptr == '-') { + *bptr = 0; + if(part==which) bptr = prop; + else if(part==which+1) bptr = after; + *bptr++ = *ptr; + part++; + } else { + *bptr++ = *ptr; + } ptr++; + }*bptr = 0; + snprintf(fname, 255, "%s-%s%s", before, newprop, after); +} + + +WMFont * +WMGetFontPlain(WMScreen *scrPtr, WMFont *font) +{ + WMFont *nfont=NULL; + if(!scrPtr|| !font) + return NULL; + return font; + +} + + +WMFont * +WMGetFontBold(WMScreen *scrPtr, WMFont *font) +{ + WMFont *newfont=NULL; + char fname[256]; + if(!scrPtr || !font) + return NULL; + snprintf(fname, 255, font->name); + changeFontProp(fname, "bold", 2); + newfont = WMCreateNormalFont(scrPtr, fname); + if(!newfont) + newfont = font; + return newfont; +} + + + +WMFont * +WMGetFontItalic(WMScreen *scrPtr, WMFont *font) +{ + WMFont *newfont=NULL; + char fname[256]; + if(!scrPtr || !font) + return NULL; + snprintf(fname, 255, font->name); + changeFontProp(fname, "o", 3); + newfont = WMCreateNormalFont(scrPtr, fname); + if(!newfont) + newfont = font; + return newfont; +} + +WMFont * +WMGetFontOfSize(WMScreen *scrPtr, WMFont *font, int size) +{ + WMFont *nfont=NULL; + if(!scrPtr || !font || size<1) + return NULL; + return font; +} + + -#if 0 typedef struct _currentFormat { WMBag *fonts; WMBag *colors; @@ -3457,34 +3576,61 @@ getArg(char *t, short type, void *arg) void parseToken(WMText *tPtr, char *token, short tk) { - short mode=0; /* 0 starts, 1 closes */ + short open=0; /* 0 starts, 1 closes */ void *tb= NULL; int prepend = WMGetTextInsertType(tPtr); + WMScreen *scr = tPtr->view->screen; - while(*token && isspace(*(token))) token++; - if(*token == '/') { + if(tk == -1) { + WMAppendTextBlock(tPtr, WMCreateTextBlockWithText(tPtr, + NULL, cfmt.cfont, cfmt.ccolor, True, 0)); + return; + } + + + while(*token && *token == ' ') token++; - mode = 1; - while(isspace(*(token))) token++; - } + + if(*token == '/') { + token++; + open = 1; + + while(*token == ' ') + token++; + } + + if(!tPtr->flags.parsingHTML) { + if(mystrcasecmp(token, "html")) { +printf("got HTMLLLL: [%s]\n", token); + tPtr->flags.parsingHTML = True; + } else { + WMAppendTextBlock(tPtr, WMCreateTextBlockWithText(tPtr, + token, cfmt.cfont, cfmt.ccolor, cfmt.first, strlen(token))); + } + + return; + } + if(strlen(token)==1) { /* nice and fast for small tokens... no need for too much brain power here */ switch(TOLOWER(*token)) { case 'i': - if(!mode) { + if(!open) { cfmt.cfont = WMGetFontItalic(scr, cfmt.cfont); WMPutInBag(cfmt.fonts, (void *)cfmt.cfont); } else { /*dun wanna remove the baseFont eh? */ int count = WMGetBagItemCount(cfmt.fonts); - if(count>1) + if(count>1) { WMDeleteFromBag(cfmt.fonts, count-1); + } cfmt.cfont = (WMFont *)WMGetFromBag(cfmt.fonts, WMGetBagItemCount(cfmt.fonts)-1); - } break; + }printf("i\n"); break; + case 'b': - if(!mode) { + if(!open) { cfmt.cfont = WMGetFontBold(scr, cfmt.cfont); WMPutInBag(cfmt.fonts, (void *)cfmt.cfont); } else { /*dun wanna remove the baseFont eh? */ @@ -3496,20 +3642,20 @@ void parseToken(WMText *tPtr, char *token, short tk) } break; case 'p': cfmt.first = True; - tb = WMCreateTextBlockWithText(NULL, cfmt.cfont, + tb = WMCreateTextBlockWithText(tPtr, NULL, cfmt.cfont, cfmt.ccolor, cfmt.first, 0); - WMSetTextBlockProperties(tb, cfmt.first, False, (cfmt.u?1:0), 0, cfmt.margins); - //WMAppendTextBlock(tPtr, tb); + // WMSetTextBlockProperties(tb, cfmt.first, False, (cfmt.u?1:0), 0, cfmt.margins); + WMAppendTextBlock(tPtr, tb); cfmt.first = False; break; - case 'u': cfmt.u = !mode; break; + case 'u': cfmt.u = !open; break; } - } else { /* the tag is, as far as I'm concerned, useless */ + } else { if(mystrcasecmp(token, "br")) { cfmt.first = True; } else if(mystrcasecmp(token, "ul")) { - if(mode) { + if(open) { if(cfmt.ul>1) cfmt.ul--; } else cfmt.ul++; if(cfmt.ul) { @@ -3520,14 +3666,17 @@ void parseToken(WMText *tPtr, char *token, short tk) cfmt.first = True; //change margins... create a new margin.... //(cfmt.fmargin, cfmt.bmargin, + } else if(mystrcasecmp(token, "html")) { + tPtr->flags.parsingHTML = !open; + } else if(mystrcasecmp(token, "align")) ;//printf("align"); else if(mystrcasecmp(token, "img")) { - if(!mode) { + if(!open) { char *mark=NULL; WMPixmap *pixmap; token+=3; - while(isspace(*(token))) token++; + while(*token == ' ') token++; do { switch(TOLOWER(*token)) { case 's': @@ -3542,10 +3691,10 @@ void parseToken(WMText *tPtr, char *token, short tk) if(*img == '\"') { img[strlen(img)-1] = 0; iptr++;} pixmap = WMCreatePixmapFromFile(scr, iptr); if(pixmap) { - tb = WMCreateTextBlockWithPixmap(pixmap, + tb = WMCreateTextBlockWithPixmap(tPtr, pixmap, iptr, cfmt.ccolor, cfmt.first, 0); - WMSetTextBlockProperties(tb, cfmt.first, - False, (cfmt.u?1:0), 0, cfmt.margins); + // WMSetTextBlockProperties(tb, cfmt.first, + // False, (cfmt.u?1:0), 0, cfmt.margins); WMAppendTextBlock(tPtr, tb); cfmt.first = False; } @@ -3554,7 +3703,7 @@ void parseToken(WMText *tPtr, char *token, short tk) } } else if(mystrcasecmp(token, "font")) { #if 0 - if(mode) { + if(open) { cfmt.cfont = (WMFont *)WMGetFromBag(cfmt.fonts, WMGetBagItemCount(cfmt.fonts)-1); } else @@ -3564,7 +3713,7 @@ void parseToken(WMText *tPtr, char *token, short tk) } else if(mystrcasecmp(token, "center")) { printf("center\n"); - if(mode) cfmt.align = WALeft; + if(open) cfmt.align = WALeft; else cfmt.align = WACenter; cfmt.first = True; //change margins... @@ -3574,7 +3723,7 @@ printf("center\n"); - //printf("parse token (%s)[%s]\n", mode?"close":"open", token); + //printf("parse token (%s)[%s]\n", open?"close":"open", token); #if 0 i=0; //while(*token && !isspace(*(token))) token++; @@ -3593,105 +3742,7 @@ printf("center\n"); #endif - //printf("parse token (%s)[%s]\n", mode?"close":"open", token); + //printf("parse token (%s)[%s]\n", open?"close":"open", token); } -void HTMLParser(WMWidget *w, void *clientData) -{ - static short init=1; /* have we been here at least once before? */ - char *stream = (char *) clientData; - WMText *tPtr = (WMText *)w; - void *tb = NULL; - char c; - char token[MAX_TOKEN_SIZE+1]; - char text[MAX_TEXT_SIZE+1]; - short mode=0; - short tk=0, textlen=0; - short wasspace=0; - - if(!tPtr || !stream) - return; - - cfmt.type = WMGetTextInsertType(tPtr); - if(1||init) { - cfmt.fonts = WMCreateBag(4); /* there sould always be at least 1 font... */ - cfmt.cfont = WMGetTextDefaultFont(tPtr); - WMPutInBag(cfmt.fonts, (void *)cfmt.cfont); - cfmt.colors = WMCreateBag(4); - cfmt.ccolor = WMBlackColor(scr); - WMPutInBag(cfmt.colors, (void *)cfmt.ccolor); - cfmt.i = cfmt.b = cfmt.u = cfmt.ul = 0; - cfmt.align = WALeft; - cfmt.fmargin = cfmt.bmargin = 0; - init = 0; - } - -#if 0 - if(strlen(stream) == 1 && stream[0] == '\n') { - /* sometimes if the text entered is a single char AND is a newline, - the user prolly typed it */ - cfmt.para = (cfmt.actions.createParagraph) (cfmt.fmargin, cfmt.bmargin, - WMWidgetWidth(tPtr)-30, NULL, 0, cfmt.align); - (cfmt.actions.insertParagraph) (tPtr, cfmt.para, cfmt.type); - return; - } -#endif - - -/* -*/ - - while( (c=*(stream++))) { -//printf("%c", c); - if(c == '\n' || c =='\t') - //c = ' '; //continue; - continue; - if(c == ' ') { - if(wasspace) - continue; - wasspace = 1; - }else wasspace = 0; - - if(c == '<' && !mode) { - mode=1; - if(textlen>0) { - text[textlen] = 0; - tb = WMCreateTextBlockWithText(text, cfmt.cfont, - cfmt.ccolor, cfmt.first, textlen); - WMSetTextBlockProperties(tb, cfmt.first, False, (cfmt.u?1:0), 0, cfmt.margins); - WMAppendTextBlock(tPtr, tb); - cfmt.first = False; -//printf("%s\n", text); - } - textlen = 0; - } else if(c == '>' && mode) { - token[tk] = 0; - if(tk>0) parseToken(tPtr, token, tk); - mode=0; - tk=0; - } else { - if(mode) { - if(tk < MAX_TOKEN_SIZE) token[tk++] = c; - } else if(textlen < MAX_TEXT_SIZE) text[textlen++] = c; - } - } - - if(tk>0) { token[tk] = 0; parseToken(tPtr, token, tk);} - if(textlen>0) { - text[textlen] = 0; - //printf("%s\n", text); - tb = WMCreateTextBlockWithText(text, - (WMFont *)WMGetFromBag(cfmt.fonts, - WMGetBagItemCount(cfmt.fonts)-1), - (WMColor *)WMGetFromBag(cfmt.colors, - WMGetBagItemCount(cfmt.colors)-1), - cfmt.first, textlen); - WMSetTextBlockProperties(tb, cfmt.first, False, (cfmt.u?1:0), 0, cfmt.margins); - WMAppendTextBlock(tPtr, tb); - cfmt.first = False; - } - -} - -#endif -- 2.11.4.GIT