mirror of
https://github.com/gryf/wmaker.git
synced 2026-03-02 14:35:47 +01:00
changes to wmtext
This commit is contained in:
182
WINGs/WINGs.h
182
WINGs/WINGs.h
@@ -193,17 +193,6 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
WRulerLeft=0,
|
|
||||||
WRulerBody,
|
|
||||||
WRulerFirst,
|
|
||||||
WRulerRight,
|
|
||||||
WRulerBoth,
|
|
||||||
WRulerDocLeft
|
|
||||||
} WMRulerMarginType;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* drag operations */
|
/* drag operations */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
WDOperationNone,
|
WDOperationNone,
|
||||||
@@ -395,16 +384,16 @@ typedef struct WMInputPanel {
|
|||||||
} WMInputPanel;
|
} WMInputPanel;
|
||||||
|
|
||||||
|
|
||||||
/* WMRuler stuff */
|
|
||||||
/* All indentation and tab markers are _relative_ to the left margin marker */
|
|
||||||
|
|
||||||
/* a tabstop is a linked list of tabstops, each containing the position of the tabstop */
|
/* WMRuler: a tabstop is a linked list of tabstops,
|
||||||
|
each containing the position of the tabstop */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int value;
|
int value;
|
||||||
struct WMTabStops *next;
|
struct WMTabStops *next;
|
||||||
} WMTabStops;
|
} WMTabStops;
|
||||||
|
|
||||||
|
/* All indentation and tab markers are _relative_ to the left margin marker */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int left; /* left margin marker */
|
int left; /* left margin marker */
|
||||||
int right; /* right margin marker */
|
int right; /* right margin marker */
|
||||||
@@ -414,9 +403,6 @@ typedef struct {
|
|||||||
} WMRulerMargins;
|
} WMRulerMargins;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef void *WMHandlerID;
|
typedef void *WMHandlerID;
|
||||||
|
|
||||||
typedef void WMInputProc(int fd, int mask, void *clientData);
|
typedef void WMInputProc(int fd, int mask, void *clientData);
|
||||||
@@ -490,6 +476,26 @@ typedef struct WMTextFieldDelegate {
|
|||||||
} WMTextFieldDelegate;
|
} WMTextFieldDelegate;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct WMTextDelegate {
|
||||||
|
void *data;
|
||||||
|
|
||||||
|
void (*didBeginEditing)(struct WMTextDelegate *self,
|
||||||
|
WMNotification *notif);
|
||||||
|
|
||||||
|
void (*didChange)(struct WMTextDelegate *self,
|
||||||
|
WMNotification *notif);
|
||||||
|
|
||||||
|
void (*didEndEditing)(struct WMTextDelegate *self,
|
||||||
|
WMNotification *notif);
|
||||||
|
|
||||||
|
Bool (*shouldBeginEditing)(struct WMTextDelegate *self,
|
||||||
|
WMText *tPtr);
|
||||||
|
|
||||||
|
Bool (*shouldEndEditing)(struct WMTextDelegate *self,
|
||||||
|
WMText *tPtr);
|
||||||
|
} WMTextDelegate;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct WMTabViewDelegate {
|
typedef struct WMTabViewDelegate {
|
||||||
void *data;
|
void *data;
|
||||||
@@ -523,25 +529,6 @@ typedef struct WMSelectionProcs {
|
|||||||
} WMSelectionProcs;
|
} WMSelectionProcs;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef void WMParseAction(WMWidget *self, void *clientData, short type);
|
|
||||||
|
|
||||||
/* these are the things parsers (for text) do */
|
|
||||||
|
|
||||||
typedef struct _parserActions {
|
|
||||||
void *(*createParagraph) (short fmargin, short bmargin,
|
|
||||||
short rmargin, short *tabstops, short numTabs, WMAlignment a);
|
|
||||||
void (*insertParagraph) (WMText *tPtr, void *para, Bool prepend);
|
|
||||||
void *(*createPChunk) (WMPixmap *pixmap, short script, ushort ul);
|
|
||||||
void *(*createTChunk) (char *text, short chars, WMFont *font,
|
|
||||||
WMColor *color, short script, ushort ul);
|
|
||||||
void (*insertChunk) (WMText *tPtr, void *chunk, Bool prepend);
|
|
||||||
} WMParserActions;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct W_DraggingInfo WMDraggingInfo;
|
typedef struct W_DraggingInfo WMDraggingInfo;
|
||||||
|
|
||||||
|
|
||||||
@@ -805,10 +792,6 @@ void WMUnmapWidget(WMWidget *w);
|
|||||||
|
|
||||||
void WMMapWidget(WMWidget *w);
|
void WMMapWidget(WMWidget *w);
|
||||||
|
|
||||||
void WMRaiseWidget(WMWidget *w);
|
|
||||||
|
|
||||||
void WMLowerWidget(WMWidget *w);
|
|
||||||
|
|
||||||
void WMMoveWidget(WMWidget *w, int x, int y);
|
void WMMoveWidget(WMWidget *w, int x, int y);
|
||||||
|
|
||||||
void WMResizeWidget(WMWidget *w, unsigned int width, unsigned int height);
|
void WMResizeWidget(WMWidget *w, unsigned int width, unsigned int height);
|
||||||
@@ -980,8 +963,6 @@ void WMSetLabelImage(WMLabel *lPtr, WMPixmap *image);
|
|||||||
|
|
||||||
WMPixmap *WMGetLabelImage(WMLabel *lPtr);
|
WMPixmap *WMGetLabelImage(WMLabel *lPtr);
|
||||||
|
|
||||||
char *WMGetLabelText(WMLabel *lPtr);
|
|
||||||
|
|
||||||
void WMSetLabelImagePosition(WMLabel *lPtr, WMImagePosition position);
|
void WMSetLabelImagePosition(WMLabel *lPtr, WMImagePosition position);
|
||||||
|
|
||||||
void WMSetLabelTextAlignment(WMLabel *lPtr, WMAlignment alignment);
|
void WMSetLabelTextAlignment(WMLabel *lPtr, WMAlignment alignment);
|
||||||
@@ -1410,7 +1391,7 @@ WMRuler *WMCreateRuler (WMWidget *parent);
|
|||||||
|
|
||||||
void WMShowRulerTabs(WMRuler *rPtr, Bool Show);
|
void WMShowRulerTabs(WMRuler *rPtr, Bool Show);
|
||||||
|
|
||||||
int WMGetRulerMargin(WMRuler *rPtr, int which);
|
WMRulerMargins WMGetRulerMargins(WMRuler *rPtr);
|
||||||
|
|
||||||
void WMSetRulerMargins(WMRuler *rPtr, WMRulerMargins margins);
|
void WMSetRulerMargins(WMRuler *rPtr, WMRulerMargins margins);
|
||||||
|
|
||||||
@@ -1430,71 +1411,80 @@ void WMSetRulerReleaseAction(WMRuler *rPtr, WMAction *action, void *clientData);
|
|||||||
|
|
||||||
WMText *WMCreateText(WMWidget *parent);
|
WMText *WMCreateText(WMWidget *parent);
|
||||||
|
|
||||||
int WMGetTextParagraphs(WMText *tPtr);
|
|
||||||
int WMGetTextCurrentParagraph(WMText *tPtr);
|
|
||||||
void WMSetTextCurrentParagraph(WMText *tPtr, int current);
|
|
||||||
void WMRemoveTextParagraph(WMText *tPtr, int which);
|
|
||||||
|
|
||||||
int WMGetTextChunks(WMText *tPtr);
|
|
||||||
int WMGetTextCurrentChunk(WMText *tPtr);
|
|
||||||
void WMRemoveTextChunk(WMText *tPtr, int which);
|
|
||||||
void WMSetTextCurrentChunk(WMText *tPtr, int current);
|
|
||||||
|
|
||||||
void W_InsertText(WMText *tPtr, void *data, Bool prepend);
|
|
||||||
#define WMAppendTextStream(t, d) W_InsertText(t, d, False)
|
|
||||||
#define WMPrependTextStream(t, d) W_InsertText(t, d, True)
|
|
||||||
|
|
||||||
|
|
||||||
void WMSetTextParser(WMText *tPtr, WMParseAction *parser);
|
|
||||||
WMParserActions WMGetTextParserActions(WMText *tPtr);
|
|
||||||
#if 0
|
|
||||||
typedef enum {
|
|
||||||
WDPCreateParagraph=0,
|
|
||||||
WDPInsertParagraph=1,
|
|
||||||
WDPCreateText=2,
|
|
||||||
WDPCreateImage=3,
|
|
||||||
WDPInsertChunk
|
|
||||||
} WMDoParse;
|
|
||||||
void WMDoTextParse(WMText *tPtr, short action);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char * WMGetTextAll(WMText *tPtr);
|
|
||||||
void WMSetTextWriter(WMText *tPtr, WMParseAction *writer);
|
|
||||||
|
|
||||||
void WMSetTextHasHorizontalScroller(WMText *tPtr, Bool flag);
|
|
||||||
void WMSetTextHasVerticalScroller(WMText *tPtr, Bool flag);
|
|
||||||
|
|
||||||
void WMRefreshText(WMText *tPtr, int vpos, int hpos);
|
void WMRefreshText(WMText *tPtr, int vpos, int hpos);
|
||||||
|
|
||||||
void WMFreezeText(WMText *tPtr);
|
void WMFreezeText(WMText *tPtr);
|
||||||
|
|
||||||
void WMThawText(WMText *tPtr);
|
void WMThawText(WMText *tPtr);
|
||||||
|
|
||||||
void WMSetTextMonoFont(WMText *tPtr, Bool mono);
|
|
||||||
Bool WMGetTextMonoFont(WMText *tPtr);
|
|
||||||
void WMSetTextEditable(WMText *tPtr, Bool editable);
|
|
||||||
Bool WMGetTextEditable(WMText *tPtr);
|
|
||||||
void WMForceTextFocus(WMText *tPtr);
|
|
||||||
|
|
||||||
void WMSetTextAlignment(WMText *tPtr, WMAlignment alignment);
|
|
||||||
void WMIgnoreTextNewline(WMText *tPtr, Bool ignore);
|
|
||||||
|
|
||||||
|
|
||||||
Bool WMScrollText(WMText *tPtr, int amount);
|
Bool WMScrollText(WMText *tPtr, int amount);
|
||||||
Bool WMPageText(WMText *tPtr, Bool scrollUp);
|
|
||||||
|
|
||||||
|
Bool WMPageText(WMText *tPtr, Bool direction);
|
||||||
|
|
||||||
|
void WMSetTextHasHorizontalScroller(WMText *tPtr, Bool shouldhave);
|
||||||
|
|
||||||
|
void WMSetTextHasVerticalScroller(WMText *tPtr, Bool shouldhave);
|
||||||
|
|
||||||
|
void WMSetTextHasRuler(WMText *tPtr, Bool shouldhave);
|
||||||
|
|
||||||
void WMShowTextRuler(WMText *tPtr, Bool show);
|
void WMShowTextRuler(WMText *tPtr, Bool show);
|
||||||
Bool WMGetTextRulerShown(WMText *tPtr);
|
|
||||||
void WMShowTextRulerTabs(WMText *tPtr, Bool show);
|
|
||||||
void WMSetTextRulerMargin(WMText *tPtr, char which, short pixels);
|
|
||||||
short WMGetTextRulerMargin(WMText *tPtr, char which);
|
|
||||||
|
|
||||||
void WMSetTextUseFixedPitchFont(WMText *tPtr, Bool fixed);
|
void WMSetTextUseMonoFont(WMText *tPtr, Bool mono);
|
||||||
void WMSetTextDefaultColor(WMText *tPtr, WMColor *color);
|
|
||||||
|
int WMGetTextUsesMonoFont(WMText *tPtr);
|
||||||
|
|
||||||
void WMSetTextDefaultFont(WMText *tPtr, WMFont *font);
|
void WMSetTextDefaultFont(WMText *tPtr, WMFont *font);
|
||||||
void WMSetTextDefaultAlignment(WMText *tPtr, WMAlignment alignment);
|
|
||||||
|
WMFont * WMGetTextDefaultFont(WMText *tPtr);
|
||||||
|
|
||||||
|
void WMSetTextRelief(WMText *tPtr, WMReliefType relief);
|
||||||
|
|
||||||
|
void WMSetTextForegroundColor(WMText *tPtr, WMColor *color);
|
||||||
|
|
||||||
void WMSetTextBackgroundColor(WMText *tPtr, WMColor *color);
|
void WMSetTextBackgroundColor(WMText *tPtr, WMColor *color);
|
||||||
|
|
||||||
|
void WMPrependTextStream(WMText *tPtr, char *text);
|
||||||
|
|
||||||
|
void WMAppendTextStream(WMText *tPtr, char *text);
|
||||||
|
|
||||||
|
WMData * WMGetTextSelected(WMText *tPtr);
|
||||||
|
|
||||||
|
void *WMCreateTextBlockWithObject(WMWidget *w, char *description,
|
||||||
|
WMColor *color, unsigned short first, unsigned short reserved);
|
||||||
|
|
||||||
|
void *WMCreateTextBlockWithText(char *text, WMFont *font,
|
||||||
|
WMColor *color, unsigned short first, unsigned short length);
|
||||||
|
|
||||||
|
void WMSetTextBlockProperties(void *vtb, unsigned int first,
|
||||||
|
unsigned int kanji, unsigned int underlined, int script,
|
||||||
|
unsigned int marginN);
|
||||||
|
|
||||||
|
void WMGetTextBlockProperties(void *vtb, unsigned int *first,
|
||||||
|
unsigned int *kanji, unsigned int *underlined, int *script,
|
||||||
|
unsigned int *marginN);
|
||||||
|
|
||||||
|
|
||||||
|
/* parser related stuff... see how it can be done in testtext.c */
|
||||||
|
|
||||||
|
void WMSetTextParser(WMText *tPtr, WMAction *parser);
|
||||||
|
|
||||||
|
void WMSetTextWriter(WMText *tPtr, WMAction *writer);
|
||||||
|
|
||||||
|
int WMGetTextInsertType(WMText *tPtr);
|
||||||
|
|
||||||
|
int WMGetTextBlocks(WMText *tPtr);
|
||||||
|
|
||||||
|
void WMSetCurrentTextBlock(WMText *tPtr, int current);
|
||||||
|
|
||||||
|
int WMGetCurrentTextBlock(WMText *tPtr);
|
||||||
|
|
||||||
|
void WMPrependTextBlock(WMText *tPtr, void *vtb);
|
||||||
|
|
||||||
|
void WMAppendTextBlock(WMText *tPtr, void *vtb);
|
||||||
|
|
||||||
|
void *WMRemoveTextBlock(WMText *tPtr);
|
||||||
|
|
||||||
|
void WMDestroyTextBlock(WMText *tPtr, void *vtb);
|
||||||
|
|
||||||
/* ....................................................................... */
|
/* ....................................................................... */
|
||||||
|
|
||||||
@@ -1528,8 +1518,6 @@ void WMSelectTabViewItemAtIndex(WMTabView *tPtr, int index);
|
|||||||
void WMSetTabViewDelegate(WMTabView *tPtr, WMTabViewDelegate *delegate);
|
void WMSetTabViewDelegate(WMTabView *tPtr, WMTabViewDelegate *delegate);
|
||||||
|
|
||||||
|
|
||||||
WMTabViewItem *WMCreateTabViewItem(int identifier, char *label);
|
|
||||||
|
|
||||||
WMTabViewItem *WMCreateTabViewItemWithIdentifier(int identifier);
|
WMTabViewItem *WMCreateTabViewItemWithIdentifier(int identifier);
|
||||||
|
|
||||||
int WMGetTabViewItemIdentifier(WMTabViewItem *item);
|
int WMGetTabViewItemIdentifier(WMTabViewItem *item);
|
||||||
|
|||||||
810
WINGs/testtext.c
810
WINGs/testtext.c
@@ -1,31 +1,36 @@
|
|||||||
/* WINGsP.h should NEVER be included from user applications */
|
#include "WINGs.h"
|
||||||
#include <WINGsP.h>
|
#include <stdio.h>
|
||||||
#include <WINGs.h>
|
|
||||||
#include <X11/Xlib.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <ctype.h>
|
|
||||||
|
WMScreen *scr;
|
||||||
|
|
||||||
void
|
void
|
||||||
wAbort()
|
wAbort()
|
||||||
{
|
{
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void Close(WMWidget *self, void *client)
|
||||||
Close(WMWidget *self, void *client)
|
|
||||||
{
|
{
|
||||||
exit(0);
|
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 ======================= */
|
/* =============== a rudimentary HTML parser ======================= */
|
||||||
|
|
||||||
/* due to the WMSetTextParser stuff, it should not
|
/* due to the WMSetTextParser stuff, it should not
|
||||||
be too hard to add parsers. like dis :-] */
|
be too hard to add parsers. like dis :-] */
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -35,61 +40,59 @@ Close(WMWidget *self, void *client)
|
|||||||
*/
|
*/
|
||||||
unsigned char map_table[256] =
|
unsigned char map_table[256] =
|
||||||
{
|
{
|
||||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247,
|
||||||
248, 249, 250, 251, 252, 253, 254, 255};
|
248, 249, 250, 251, 252, 253, 254, 255};
|
||||||
|
|
||||||
#define TOLOWER(x) (map_table[(int)x])
|
#define TOLOWER(x) (map_table[(int)x])
|
||||||
static int
|
static int
|
||||||
mystrcasecmp(const unsigned char *s1, const unsigned char *s2)
|
mystrcasecmp(const unsigned char *s1, const unsigned char *s2)
|
||||||
{
|
{
|
||||||
if (!*s1 || !*s2) return 0;
|
if (!*s1 || !*s2) return 0;
|
||||||
while (*s2 != '\0') {
|
while (*s2 != '\0') {
|
||||||
if (TOLOWER (*s1) != TOLOWER (*s2)) /* true if *s1 == 0 ! */
|
if (TOLOWER (*s1) != TOLOWER (*s2)) /* true if *s1 == 0 ! */
|
||||||
return 0;
|
return 0;
|
||||||
s1++;
|
s1++;
|
||||||
s2++;
|
s2++;
|
||||||
}
|
}
|
||||||
return (*s1=='\0' ||!isalnum(*s1))?1:0;
|
return (*s1=='\0' ||!isalnum(*s1))?1:0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
typedef struct _currentFormat {
|
typedef struct _currentFormat {
|
||||||
void *para;
|
WMBag *fonts;
|
||||||
WMBag *fonts;
|
WMBag *colors;
|
||||||
WMBag *colors;
|
WMColor *ccolor;
|
||||||
WMColor *ccolor;
|
WMFont *cfont;
|
||||||
WMFont *cfont;
|
//WMBag *aligns; // for tables...
|
||||||
WMParserActions actions;
|
/* the following are "nested"
|
||||||
//WMBag *aligns; // for tables...
|
i.e.: <b><b><i></b><b></i>
|
||||||
/* the following are "nested"
|
1 2 1 1 2 0 get it? */
|
||||||
i.e.: <b><b><i></b><b></i>
|
short i;
|
||||||
1 2 1 1 2 0 get it? */
|
short b;
|
||||||
short i;
|
short u;
|
||||||
short b;
|
short fmargin;
|
||||||
short u;
|
short bmargin;
|
||||||
short fmargin;
|
WMAlignment align:2;
|
||||||
short bmargin;
|
short type:1;
|
||||||
WMAlignment align:2;
|
short ul:3; /* how "nested"... up to 8 levels deep */
|
||||||
short type:1;
|
short comment:1; /* ignore text till --> */
|
||||||
short ul:3; /* how "nested"... up to 8 levels deep */
|
short RESERVED:10;
|
||||||
short comment:1; /* ignore text till --> */
|
|
||||||
short RESERVED:10;
|
|
||||||
} CFMT;
|
} CFMT;
|
||||||
CFMT cfmt;
|
CFMT cfmt;
|
||||||
|
|
||||||
@@ -98,348 +101,465 @@ CFMT cfmt;
|
|||||||
#if 0
|
#if 0
|
||||||
getArg(char *t, short type, void *arg)
|
getArg(char *t, short type, void *arg)
|
||||||
{
|
{
|
||||||
short d=0;
|
short d=0;
|
||||||
while(*(++t) && !d) {
|
while(*(++t) && !d) {
|
||||||
if(type==0) {
|
if(type==0) {
|
||||||
if(*t>='0' && *t<='9') {
|
if(*t>='0' && *t<='9') {
|
||||||
sscanf(t, "%d", arg);
|
sscanf(t, "%d", arg);
|
||||||
while(*t&& (*t<'0' || *t>'9'))
|
while(*t&& (*t<'0' || *t>'9'))
|
||||||
t++;
|
t++;
|
||||||
d=1;
|
d=1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void parseToken(WMText *tPtr, char *token, short tk)
|
||||||
parseToken(WMText *tPtr, char *token, short tk)
|
|
||||||
{
|
{
|
||||||
short mode=0; /* 0 starts, 1 closes */
|
short mode=0; /* 0 starts, 1 closes */
|
||||||
WMScreen *scr = (W_VIEW(tPtr))->screen;
|
int first = True;
|
||||||
|
void *tb= NULL;
|
||||||
|
int prepend = WMGetTextInsertType(tPtr);
|
||||||
|
|
||||||
while(*token && isspace(*(token))) token++;
|
while(*token && isspace(*(token))) token++;
|
||||||
if(*token == '/') {
|
if(*token == '/') {
|
||||||
token++;
|
token++;
|
||||||
mode = 1;
|
mode = 1;
|
||||||
while(isspace(*(token))) token++;
|
while(isspace(*(token))) token++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strlen(token)==1) {
|
if(strlen(token)==1) {
|
||||||
/* nice and fast for small tokens... no need for too much brain
|
/* nice and fast for small tokens... no need for too much brain
|
||||||
power here */
|
power here */
|
||||||
switch(TOLOWER(*token)) {
|
switch(TOLOWER(*token)) {
|
||||||
case 'i':
|
case 'i':
|
||||||
if(!mode) {
|
if(!mode) {
|
||||||
cfmt.cfont = WMGetFontItalic(scr, cfmt.cfont);
|
cfmt.cfont = WMGetFontItalic(scr, cfmt.cfont);
|
||||||
WMPutInBag(cfmt.fonts, (void *)cfmt.cfont);
|
WMPutInBag(cfmt.fonts, (void *)cfmt.cfont);
|
||||||
} else { /*dun wanna remove the baseFont eh? */
|
} else { /*dun wanna remove the baseFont eh? */
|
||||||
int count = WMGetBagItemCount(cfmt.fonts);
|
int count = WMGetBagItemCount(cfmt.fonts);
|
||||||
if(count>1)
|
if(count>1)
|
||||||
WMDeleteFromBag(cfmt.fonts, count-1);
|
WMDeleteFromBag(cfmt.fonts, count-1);
|
||||||
cfmt.cfont = (WMFont *)WMGetFromBag(cfmt.fonts,
|
cfmt.cfont = (WMFont *)WMGetFromBag(cfmt.fonts,
|
||||||
WMGetBagItemCount(cfmt.fonts)-1);
|
WMGetBagItemCount(cfmt.fonts)-1);
|
||||||
} break;
|
} break;
|
||||||
case 'b':
|
case 'b':
|
||||||
if(!mode) {
|
if(!mode) {
|
||||||
cfmt.cfont = WMGetFontBold(scr, cfmt.cfont);
|
cfmt.cfont = WMGetFontBold(scr, cfmt.cfont);
|
||||||
WMPutInBag(cfmt.fonts, (void *)cfmt.cfont);
|
WMPutInBag(cfmt.fonts, (void *)cfmt.cfont);
|
||||||
} else { /*dun wanna remove the baseFont eh? */
|
} else { /*dun wanna remove the baseFont eh? */
|
||||||
int count = WMGetBagItemCount(cfmt.fonts);
|
int count = WMGetBagItemCount(cfmt.fonts);
|
||||||
if(count>1)
|
if(count>1)
|
||||||
WMDeleteFromBag(cfmt.fonts, count-1);
|
WMDeleteFromBag(cfmt.fonts, count-1);
|
||||||
cfmt.cfont = (WMFont *)WMGetFromBag(cfmt.fonts,
|
cfmt.cfont = (WMFont *)WMGetFromBag(cfmt.fonts,
|
||||||
WMGetBagItemCount(cfmt.fonts)-1);
|
WMGetBagItemCount(cfmt.fonts)-1);
|
||||||
} break;
|
} break;
|
||||||
case 'p':
|
case 'p':
|
||||||
cfmt.para = (cfmt.actions.createParagraph) (cfmt.fmargin, cfmt.bmargin,
|
first = True;
|
||||||
WMWidgetWidth(tPtr)-30, NULL, 0, cfmt.align);
|
tb = WMCreateTextBlockWithText(NULL, cfmt.cfont,
|
||||||
(cfmt.actions.insertParagraph) (tPtr, cfmt.para, cfmt.type);
|
cfmt.ccolor, first, 0);
|
||||||
cfmt.para = (cfmt.actions.createParagraph) (cfmt.fmargin, cfmt.bmargin,
|
WMSetTextBlockProperties(tb, first, False, (cfmt.u?1:0), 0, 0);
|
||||||
WMWidgetWidth(tPtr)-30, NULL, 0, cfmt.align);
|
WMAppendTextBlock(tPtr, tb);
|
||||||
(cfmt.actions.insertParagraph) (tPtr, cfmt.para, cfmt.type);
|
break;
|
||||||
break;
|
case 'u': cfmt.u = !mode; break;
|
||||||
case 'u': cfmt.u = !mode; break;
|
}
|
||||||
}
|
} else { /* the <HTML> tag is, as far as I'm concerned, useless */
|
||||||
} else { /* the <HTML> tag is, as far as I'm concerned, useless */
|
if(mystrcasecmp(token, "br")) {
|
||||||
if(mystrcasecmp(token, "br")) {
|
first = True;
|
||||||
cfmt.para = (cfmt.actions.createParagraph) (cfmt.fmargin, cfmt.bmargin,
|
}
|
||||||
WMWidgetWidth(tPtr)-30, NULL, 0, cfmt.align);
|
else if(mystrcasecmp(token, "ul")) {
|
||||||
(cfmt.actions.insertParagraph) (tPtr, cfmt.para, cfmt.type);
|
if(mode) {
|
||||||
}
|
if(cfmt.ul>1) cfmt.ul--;
|
||||||
else if(mystrcasecmp(token, "ul")) {
|
} else cfmt.ul++;
|
||||||
if(mode) {
|
if(cfmt.ul) {
|
||||||
if(cfmt.ul>1) cfmt.ul--;
|
cfmt.bmargin = cfmt.ul*30;
|
||||||
} else cfmt.ul++;
|
cfmt.fmargin = cfmt.bmargin-10;
|
||||||
if(cfmt.ul) {
|
} else cfmt.fmargin = cfmt.bmargin = 0;
|
||||||
cfmt.bmargin = cfmt.ul*30;
|
} else if(mystrcasecmp(token, "li")) {
|
||||||
cfmt.fmargin = cfmt.bmargin-10;
|
first = True;
|
||||||
} else cfmt.fmargin = cfmt.bmargin = 0;
|
//change margins... create a new margin....
|
||||||
} else if(mystrcasecmp(token, "li")) {
|
//(cfmt.fmargin, cfmt.bmargin,
|
||||||
cfmt.para = (cfmt.actions.createParagraph) (cfmt.fmargin, cfmt.bmargin,
|
} else if(mystrcasecmp(token, "align"))
|
||||||
WMWidgetWidth(tPtr)-30, NULL, 0, cfmt.align);
|
;//printf("align");
|
||||||
(cfmt.actions.insertParagraph) (tPtr, cfmt.para, cfmt.type);
|
else if(mystrcasecmp(token, "img")) {
|
||||||
} else if(mystrcasecmp(token, "align"))
|
if(!mode) {
|
||||||
;//printf("align");
|
char *mark=NULL;
|
||||||
else if(mystrcasecmp(token, "img")) {
|
WMPixmap *pixmap;
|
||||||
if(!mode) {
|
WMLabel *l;
|
||||||
char *mark=NULL;
|
token+=3;
|
||||||
WMPixmap *pixmap;
|
while(isspace(*(token))) token++;
|
||||||
void *chunk;
|
do {
|
||||||
token+=3;
|
switch(TOLOWER(*token)) {
|
||||||
while(isspace(*(token))) token++;
|
case 's':
|
||||||
do {
|
if(TOLOWER(*(1+token)) == 'r' && TOLOWER(*(2+token)) == 'c') {
|
||||||
switch(TOLOWER(*token)) {
|
mark = strchr(token, '=');
|
||||||
case 's':
|
if(mark) {
|
||||||
if(TOLOWER(*(1+token)) == 'r' && TOLOWER(*(2+token)) == 'c') {
|
char img[256], *iptr;
|
||||||
mark = strchr(token, '=');
|
token = mark+1;
|
||||||
if(mark) {
|
if(!token) return;
|
||||||
char img[256], *iptr;
|
sscanf(token, "%s", img);
|
||||||
token = mark+1;
|
iptr = img;
|
||||||
if(!token) return;
|
if(*img == '\"') { img[strlen(img)-1] = 0; iptr++;}
|
||||||
sscanf(token, "%s", img);
|
pixmap = WMCreatePixmapFromFile(scr, iptr);
|
||||||
iptr = img;
|
if(pixmap) {
|
||||||
if(*img == '\"') { img[strlen(img)-1] = 0; iptr++;}
|
l = WMCreateLabel(tPtr);
|
||||||
pixmap = WMCreatePixmapFromFile(scr, iptr);
|
WMResizeWidget(l, 48, 48);
|
||||||
chunk = (cfmt.actions.createPChunk)(pixmap, 0, False);
|
WMSetLabelRelief(l, WRFlat);
|
||||||
(cfmt.actions.insertChunk) (tPtr, chunk, False);
|
WMSetLabelImagePosition(l, WIPImageOnly);
|
||||||
printf("[%s]\n", iptr);
|
WMSetLabelImage(l, pixmap);
|
||||||
} } break; } } while(*(token++));
|
tb = WMCreateTextBlockWithObject(l,
|
||||||
}
|
iptr, cfmt.ccolor, first, 0);
|
||||||
} else if(mystrcasecmp(token, "font")) {
|
WMSetTextBlockProperties(tb, first,
|
||||||
|
False, (cfmt.u?1:0), 0, 0);
|
||||||
|
WMAppendTextBlock(tPtr, tb);
|
||||||
|
}
|
||||||
|
printf("[%s]\n", iptr);
|
||||||
|
} } break; } } while(*(token++));
|
||||||
|
}
|
||||||
|
} else if(mystrcasecmp(token, "font")) {
|
||||||
#if 0
|
#if 0
|
||||||
if(mode) {
|
if(mode) {
|
||||||
cfmt.cfont = (WMFont *)WMGetFromBag(cfmt.fonts,
|
cfmt.cfont = (WMFont *)WMGetFromBag(cfmt.fonts,
|
||||||
WMGetBagItemCount(cfmt.fonts)-1);
|
WMGetBagItemCount(cfmt.fonts)-1);
|
||||||
} else
|
} else
|
||||||
(WMColor *)WMGetFromBag(cfmt.colors,
|
(WMColor *)WMGetFromBag(cfmt.colors,
|
||||||
WMGetBagItemCount(cfmt.colors)-1),
|
WMGetBagItemCount(cfmt.colors)-1),
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if(mystrcasecmp(token, "center")) {
|
else if(mystrcasecmp(token, "center")) {
|
||||||
printf("center\n");
|
printf("center\n");
|
||||||
if(mode) cfmt.align = WALeft;
|
if(mode) cfmt.align = WALeft;
|
||||||
else cfmt.align = WACenter;
|
else cfmt.align = WACenter;
|
||||||
cfmt.para = (cfmt.actions.createParagraph) (cfmt.fmargin, cfmt.bmargin,
|
first = True;
|
||||||
WMWidgetWidth(tPtr)-30, NULL, 0, cfmt.align);
|
//change margins...
|
||||||
(cfmt.actions.insertParagraph) (tPtr, cfmt.para, cfmt.type);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//printf("parse token (%s)[%s]\n", mode?"close":"open", token);
|
//printf("parse token (%s)[%s]\n", mode?"close":"open", token);
|
||||||
#if 0
|
#if 0
|
||||||
i=0;
|
i=0;
|
||||||
//while(*token && !isspace(*(token))) token++;
|
//while(*token && !isspace(*(token))) token++;
|
||||||
//printf("A:%d a:%d z%d Z%d\n", '1', 'a', 'Z', 'z');
|
//printf("A:%d a:%d z%d Z%d\n", '1', 'a', 'Z', 'z');
|
||||||
do {
|
do {
|
||||||
if(!mm) {
|
if(!mm) {
|
||||||
if(c>=65 && c<=122) { major[i++] = c;
|
if(c>=65 && c<=122) { major[i++] = c;
|
||||||
} else if(c==' ' || c=='='){ major[i] = 0; i=0; mm=1;
|
} else if(c==' ' || c=='='){ major[i] = 0; i=0; mm=1;
|
||||||
printf("\nmajor: [%s]", major);}
|
printf("\nmajor: [%s]", major);}
|
||||||
} else {
|
} else {
|
||||||
if(c!=' ') {
|
if(c!=' ') {
|
||||||
minor[i++] = c;
|
minor[i++] = c;
|
||||||
} else { minor[i] = 0; i=0; printf(" minor: [%s] ", minor);}
|
} else { minor[i] = 0; i=0; printf(" minor: [%s] ", minor);}
|
||||||
}
|
}
|
||||||
}while((c = *(++token)));
|
}while((c = *(++token)));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//printf("parse token (%s)[%s]\n", mode?"close":"open", token);
|
//printf("parse token (%s)[%s]\n", mode?"close":"open", token);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void HTMLParser(WMWidget *w, void *clientData)
|
||||||
HTMLParser(WMWidget *w, void *clientData, short type)
|
|
||||||
{
|
{
|
||||||
static short init=1; /* have we been here at least once before? */
|
static short init=1; /* have we been here at least once before? */
|
||||||
char *stream = (char *) clientData;
|
char *stream = (char *) clientData;
|
||||||
WMText *tPtr = (WMText *)w;
|
WMText *tPtr = (WMText *)w;
|
||||||
WMScreen *scr;
|
void *tb = NULL;
|
||||||
void *chunk;
|
char c;
|
||||||
char c;
|
#define MAX_TOKEN_SIZE 255
|
||||||
#define MAX_TOKEN_SIZE 255
|
char token[MAX_TOKEN_SIZE+1];
|
||||||
char token[MAX_TOKEN_SIZE+1];
|
#define MAX_TEXT_SIZE 1023
|
||||||
#define MAX_TEXT_SIZE 1023
|
char text[MAX_TEXT_SIZE+1];
|
||||||
char text[MAX_TEXT_SIZE+1];
|
short mode=0;
|
||||||
short mode=0;
|
short tk=0, textlen=0;
|
||||||
short tk=0, txt=0;
|
short wasspace=0;
|
||||||
short wasspace=0;
|
int first = False;
|
||||||
|
|
||||||
if(!tPtr || !stream)
|
if(!tPtr || !stream)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
scr = (W_VIEW(tPtr))->screen;
|
cfmt.type = WMGetTextInsertType(tPtr);
|
||||||
cfmt.type = type;
|
if(1||init) {
|
||||||
if(init) {
|
cfmt.fonts = WMCreateBag(4); /* there sould always be at least 1 font... */
|
||||||
cfmt.actions = WMGetTextParserActions(tPtr);
|
cfmt.cfont = WMGetTextDefaultFont(tPtr);
|
||||||
cfmt.fonts = WMCreateBag(4); /* there sould always be at least 1 font... */
|
WMPutInBag(cfmt.fonts, (void *)cfmt.cfont);
|
||||||
cfmt.cfont = WMSystemFontOfSize(scr, 12);
|
cfmt.colors = WMCreateBag(4);
|
||||||
WMPutInBag(cfmt.fonts, (void *)cfmt.cfont);
|
cfmt.ccolor = WMBlackColor(scr);
|
||||||
cfmt.colors = WMCreateBag(4);
|
WMPutInBag(cfmt.colors, (void *)cfmt.ccolor);
|
||||||
cfmt.ccolor = WMBlackColor(scr);
|
cfmt.i = cfmt.b = cfmt.u = cfmt.ul = 0;
|
||||||
WMPutInBag(cfmt.colors, (void *)cfmt.ccolor);
|
cfmt.align = WALeft;
|
||||||
cfmt.i = cfmt.b = cfmt.u = cfmt.ul = 0;
|
cfmt.fmargin = cfmt.bmargin = 0;
|
||||||
cfmt.align = WALeft;
|
init = 0;
|
||||||
cfmt.fmargin = cfmt.bmargin = 0;
|
}
|
||||||
cfmt.para = (cfmt.actions.createParagraph) (cfmt.fmargin, cfmt.bmargin,
|
|
||||||
WMWidgetWidth(tPtr)-30, NULL, 0, cfmt.align);
|
|
||||||
(cfmt.actions.insertParagraph) (tPtr, cfmt.para, cfmt.type);
|
|
||||||
init = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 1
|
#if 0
|
||||||
if(strlen(stream) == 1 && stream[0] == '\n') {
|
if(strlen(stream) == 1 && stream[0] == '\n') {
|
||||||
/* sometimes if the text entered is a single char AND is a newline,
|
/* sometimes if the text entered is a single char AND is a newline,
|
||||||
the user prolly typed it */
|
the user prolly typed it */
|
||||||
cfmt.para = (cfmt.actions.createParagraph) (cfmt.fmargin, cfmt.bmargin,
|
cfmt.para = (cfmt.actions.createParagraph) (cfmt.fmargin, cfmt.bmargin,
|
||||||
WMWidgetWidth(tPtr)-30, NULL, 0, cfmt.align);
|
WMWidgetWidth(tPtr)-30, NULL, 0, cfmt.align);
|
||||||
(cfmt.actions.insertParagraph) (tPtr, cfmt.para, cfmt.type);
|
(cfmt.actions.insertParagraph) (tPtr, cfmt.para, cfmt.type);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
while( (c=*(stream++))) {
|
while( (c=*(stream++))) {
|
||||||
//printf("%c", c);
|
//printf("%c", c);
|
||||||
if(c == '\n' || c =='\t')
|
if(c == '\n' || c =='\t')
|
||||||
//c = ' '; //continue;
|
//c = ' '; //continue;
|
||||||
continue;
|
continue;
|
||||||
if(c == ' ') {
|
if(c == ' ') {
|
||||||
if(wasspace)
|
if(wasspace)
|
||||||
continue;
|
continue;
|
||||||
wasspace = 1;
|
wasspace = 1;
|
||||||
}else wasspace = 0;
|
}else wasspace = 0;
|
||||||
|
|
||||||
if(c == '<' && !mode) {
|
if(c == '<' && !mode) {
|
||||||
mode=1;
|
mode=1;
|
||||||
if(txt>0) {
|
if(textlen>0) {
|
||||||
text[txt] = 0;
|
text[textlen] = 0;
|
||||||
chunk = (cfmt.actions.createTChunk)(text, txt, cfmt.cfont,
|
tb = WMCreateTextBlockWithText(text, cfmt.cfont,
|
||||||
cfmt.ccolor, 0, (cfmt.u?1:0));
|
cfmt.ccolor, first, textlen);
|
||||||
(cfmt.actions.insertChunk) (tPtr, chunk, cfmt.type);
|
WMSetTextBlockProperties(tb, first, False, (cfmt.u?1:0), 0, 0);
|
||||||
//printf("%s\n", text);
|
WMAppendTextBlock(tPtr, tb);
|
||||||
}
|
//printf("%s\n", text);
|
||||||
txt = 0;
|
}
|
||||||
} else if(c == '>' && mode) {
|
textlen = 0;
|
||||||
token[tk] = 0;
|
} else if(c == '>' && mode) {
|
||||||
if(tk>0) parseToken(tPtr, token, tk);
|
token[tk] = 0;
|
||||||
mode=0;
|
if(tk>0) parseToken(tPtr, token, tk);
|
||||||
tk=0;
|
mode=0;
|
||||||
} else {
|
tk=0;
|
||||||
if(mode) {
|
} else {
|
||||||
if(tk < MAX_TOKEN_SIZE) token[tk++] = c;
|
if(mode) {
|
||||||
} else if(txt < MAX_TEXT_SIZE) text[txt++] = c;
|
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(tk>0) { token[tk] = 0; parseToken(tPtr, token, tk);}
|
||||||
if(txt>0) {
|
if(textlen>0) {
|
||||||
text[txt] = 0;
|
text[textlen] = 0;
|
||||||
//printf("%s\n", text);
|
//printf("%s\n", text);
|
||||||
chunk = (cfmt.actions.createTChunk)(text, txt,
|
tb = WMCreateTextBlockWithText(text,
|
||||||
(WMFont *)WMGetFromBag(cfmt.fonts,
|
(WMFont *)WMGetFromBag(cfmt.fonts,
|
||||||
WMGetBagItemCount(cfmt.fonts)-1),
|
WMGetBagItemCount(cfmt.fonts)-1),
|
||||||
(WMColor *)WMGetFromBag(cfmt.colors,
|
(WMColor *)WMGetFromBag(cfmt.colors,
|
||||||
WMGetBagItemCount(cfmt.colors)-1),
|
WMGetBagItemCount(cfmt.colors)-1),
|
||||||
0, (cfmt.u?1:0));
|
first, textlen);
|
||||||
(cfmt.actions.insertChunk) (tPtr, chunk, cfmt.type);
|
WMSetTextBlockProperties(tb, first, False, (cfmt.u?1:0), 0, 0);
|
||||||
}
|
WMAppendTextBlock(tPtr, tb);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ================= the driver ================== */
|
/* ================= the driver ================== */
|
||||||
|
|
||||||
WMWidget *win;
|
static void
|
||||||
WMText *text;
|
buttonPressCB(WMWidget *w, void *client)
|
||||||
|
|
||||||
void
|
|
||||||
NotificationObserver(void *self, WMNotification *notif)
|
|
||||||
{
|
{
|
||||||
void *object = WMGetNotificationObject(notif);
|
WMText *tPtr = (WMText *)client;
|
||||||
unsigned short w = WMWidgetWidth(win);
|
WMAppendTextStream(tPtr, NULL);
|
||||||
unsigned short h = WMWidgetHeight(win);
|
WMAppendTextStream(tPtr,
|
||||||
|
"<p><b>You</b> just <i>had</i> to press that button, didn't you? "
|
||||||
if (WMGetNotificationName(notif) == WMViewSizeDidChangeNotification) {
|
"Well, this sort of thing is bound to happen when you go about "
|
||||||
if (object == WMWidgetView(win)) {
|
" pressing buttons :-)"
|
||||||
WMResizeWidget(text, w-20, h-20);
|
"<p><p>Cheers, <p><p><u>Nwanua</u>");
|
||||||
}
|
WMRefreshText(tPtr, 0, 0);
|
||||||
}
|
|
||||||
|
|
||||||
{static int i=0;
|
|
||||||
switch(i++) {
|
|
||||||
case 0: WMSetTextHasHorizontalScroller(text, False); break;
|
|
||||||
case 1: WMSetTextHasVerticalScroller(text, False); break;
|
|
||||||
case 2: WMSetTextHasVerticalScroller(text, True); break;
|
|
||||||
case 3: WMSetTextHasHorizontalScroller(text, True); break;
|
|
||||||
default: i=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
Display *dpy;
|
Display *dpy;
|
||||||
WMScreen *scr;
|
WMWidget *win;
|
||||||
|
WMText *text;
|
||||||
|
WMRulerMargins margins;
|
||||||
|
void *tb = NULL;
|
||||||
|
|
||||||
|
|
||||||
WMInitializeApplication("WMText", &argc, argv);
|
WMInitializeApplication("WMText", &argc, argv);
|
||||||
dpy = XOpenDisplay(NULL);
|
dpy = XOpenDisplay(NULL);
|
||||||
if(!dpy) exit(1);
|
if(!dpy) { printf("no display? *sniff* :~( "); exit(1);}
|
||||||
|
|
||||||
scr = WMCreateSimpleApplicationScreen(dpy);
|
scr = WMCreateSimpleApplicationScreen(dpy);
|
||||||
|
|
||||||
win = WMCreateWindow(scr, "WMText Test");
|
win = WMCreateWindow(scr, "WMText Test");
|
||||||
WMRealizeWidget(win);
|
WMRealizeWidget(win);
|
||||||
WMResizeWidget(win, 500, 300);
|
WMResizeWidget(win, 500, 300);
|
||||||
//WMResizeWidget(win, 900, 600);
|
//WMResizeWidget(win, 900, 600);
|
||||||
WMSetWindowTitle(win,"WMText Test");
|
WMSetWindowTitle(win,"WMText Test");
|
||||||
WMSetWindowCloseAction(win, Close, NULL);
|
WMSetWindowCloseAction(win, Close, NULL);
|
||||||
|
|
||||||
text = WMCreateText(win);
|
text = WMCreateText(win);
|
||||||
WMRealizeWidget(text);
|
WMRealizeWidget(text);
|
||||||
WMResizeWidget(text, 480, 280);
|
//WMSetTextHasHorizontalScroller(text, True);
|
||||||
WMMoveWidget(text, 10, 10);
|
WMResizeWidget(text, 480, 280);
|
||||||
WMSetTextUseFixedPitchFont(text, False);
|
WMMoveWidget(text, 10, 10);
|
||||||
WMSetTextMonoFont(text, False);
|
WMSetTextRelief(text, WRSunken);
|
||||||
WMSetTextParser(text, HTMLParser);
|
WMSetTextHasVerticalScroller(text, True);
|
||||||
WMSetTextEditable(text, True);
|
WMSetTextUseMonoFont(text, !True);
|
||||||
WMFreezeText(text);
|
WMSetTextParser(text, HTMLParser);
|
||||||
if(1){
|
#if 0
|
||||||
FILE *f = fopen("./wm.html", "r");
|
WMSetTextUseFixedPitchFont(text, False);
|
||||||
char data[1024];
|
WMSetTextHasRuler(text, True);
|
||||||
if(f) {
|
WMShowTextRuler(text, True);
|
||||||
while(fgets(data, 1022,f))
|
WMSetTextHasVerticalScroller(text, True);
|
||||||
WMAppendTextStream(text, data);
|
//WMSetTextHasHorizontalScroller(text, True);
|
||||||
fclose(f);
|
WMSetTextEditable(text, True);
|
||||||
} else {
|
WMFreezeText(text);
|
||||||
WMAppendTextStream(text, "<i>can't</i> open the <u>wm.html</u> file, but here's a <B>text <I>stream <img src=foo.bar></I><BR>that</B> <U>needs</U> parsing");
|
#endif
|
||||||
}
|
|
||||||
|
//margins = WMGetTextRulerMargins(text);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
WMAppendTextStream(text,
|
||||||
|
"<p><img src=logo.xpm></i> \
|
||||||
|
<b><i>WINGs</b></i> is a <i>small</i> widget set with \
|
||||||
|
a <u>very</u> nice look and feel. Its API is <i>inspired</i> \
|
||||||
|
and its implementation borrows some ideas from interesting places.\
|
||||||
|
<p><p>
|
||||||
|
The library is limited and its design is a little sloppy, \
|
||||||
|
so it's not intended to build large or complex applications, just
|
||||||
|
<i>small</i> and complex ones. <b>:-)</b>\
|
||||||
|
<p><p> 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);
|
||||||
|
WMRealizeWidget(te);
|
||||||
|
WMResizeWidget(te, 120, 90);
|
||||||
|
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 "
|
||||||
|
"<i><b>WINGs</b></i> objects (such as this one), "
|
||||||
|
" without breaking a sweat (type in here)");
|
||||||
|
tb = WMCreateTextBlockWithObject(te, "{a text object}",
|
||||||
|
WMBlackColor(scr), False, 0);
|
||||||
|
WMAppendTextBlock(text, tb);
|
||||||
|
WMSetTextHasVerticalScroller(te, False);
|
||||||
|
WMRefreshText(te, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
WMText *te = WMCreateText(text);
|
||||||
|
WMRealizeWidget(te);
|
||||||
|
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 <i>multi-column</i> text editor in Unix for my reports, "
|
||||||
|
" now all I have to do is wait for <u>someone</u> to code it :-P");
|
||||||
|
tb = WMCreateTextBlockWithObject(te, "{a text object}",
|
||||||
|
WMBlackColor(scr), False, 0);
|
||||||
|
WMAppendTextBlock(text, tb);
|
||||||
|
WMSetTextHasVerticalScroller(te, False);
|
||||||
|
WMRefreshText(te, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//WMPrependTextStream(text, "this is prepended\n");
|
|
||||||
//WMAppendTextStream(text, "blueplanet.rtf");
|
|
||||||
|
|
||||||
|
|
||||||
WMThawText(text);
|
|
||||||
|
WMAppendTextStream(text,
|
||||||
|
" .<p><p> Not bad eh? \
|
||||||
|
<p><p> Since <i><b>WINGs</b></i> is \
|
||||||
|
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 :-). <p><p>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. "
|
||||||
|
"<p><p>(BTW, don't <i>press</i> that button that is <u>screeming</u>"
|
||||||
|
" to be pressed!");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// WMThawText(text);
|
||||||
WMRefreshText(text, 0, 0);
|
WMRefreshText(text, 0, 0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
WMAddNotificationObserver(NotificationObserver, win,
|
WMAddNotificationObserver(NotificationObserver, win,
|
||||||
WMViewSizeDidChangeNotification, WMWidgetView(win));
|
WMViewSizeDidChangeNotification, WMWidgetView(win));
|
||||||
*/
|
*/
|
||||||
WMSetViewNotifySizeChanges(WMWidgetView(win), True);
|
WMSetViewNotifySizeChanges(WMWidgetView(win), True);
|
||||||
WMMapSubwidgets(win);
|
WMMapSubwidgets(win);
|
||||||
WMMapWidget(win);
|
WMMapWidget(win);
|
||||||
|
|
||||||
WMScreenMainLoop(scr);
|
WMScreenMainLoop(scr);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
4657
WINGs/wtext.c
4657
WINGs/wtext.c
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user