1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-03-13 13:15:45 +01:00

Guess what? Yep, another wmtext update. Now this was all, please go to

your homes.
This commit is contained in:
dan
2000-06-22 23:01:27 +00:00
parent c87c53fbe5
commit 9d4dae947b

View File

@@ -13,22 +13,18 @@
/* if monoFont, ignore pixmaps, colors, fonts, script, underline */ /* if monoFont, ignore pixmaps, colors, fonts, script, underline */
//#include <WINGs.h>
#include <WMaker.h> #include <WMaker.h>
#include <WINGsP.h> #include <WINGsP.h>
#include <X11/keysym.h> #include <X11/keysym.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include <ctype.h> #include <ctype.h>
#if 0
#include "wruler.h"
#include "wtext.h"
#endif
void wgdbFree(void *ptr) void wgdbFree(void *ptr)
{ if(!ptr) printf("err... cannot "); {
printf("gdbFree [%p]\n", ptr); if(!ptr) printf("err... cannot ");
wfree(ptr); printf("gdbFree [%p]\n", ptr);
wfree(ptr);
} }
@@ -59,7 +55,7 @@ typedef struct _Chunk {
short ul:1; /* underlined or not */ short ul:1; /* underlined or not */
ChunkType type:1; /* a "Text" or "Image" chunk */ ChunkType type:1; /* a "Text" or "Image" chunk */
short script:4; /* script in points: negative for subscript */ short script:4; /* script in points: negative for subscript */
//hrmm selec... /* hrmm selec... */
ushort selected; ushort selected;
ushort sStart; ushort sStart;
ushort sEnd; ushort sEnd;
@@ -97,48 +93,48 @@ typedef struct _Paragraph {
static char *default_bullet[] = { static char *default_bullet[] = {
"6 6 4 1", "6 6 4 1",
" c None s None", ". c black", " c None s None", ". c black",
"X c white", "o c #808080", "X c white", "o c #808080",
" ... ", " ... ",
".XX.. ", ".XX.. ",
".XX..o", ".XX..o",
".....o", ".....o",
" ...oo", " ...oo",
" ooo "}; " ooo "};
/* this is really a shrunk down version of the original /* this is really a shrunk down version of the original
"broken" icon... I did not draw it, I simply shrunk it */ "broken" icon... I did not draw it, I simply shrunk it */
static char * unk_xpm[] = { static char * unk_xpm[] = {
"24 24 17 1", "24 24 17 1",
" c None", ". c #0B080C", "+ c #13A015", "@ c #5151B8", " c None", ". c #0B080C", "+ c #13A015", "@ c #5151B8",
"# c #992719", "$ c #5B1C20", "% c #1DF51D", "& c #D1500D", "* c #2F304A", "# c #992719", "$ c #5B1C20", "% c #1DF51D", "& c #D1500D", "* c #2F304A",
"= c #0C6A0C", "- c #F2F1DE", "; c #D59131", "> c #B2B083", ", c #DD731A", "= c #0C6A0C", "- c #F2F1DE", "; c #D59131", "> c #B2B083", ", c #DD731A",
"' c #CC3113", ") c #828238", "! c #6A6A94", "' c #CC3113", ") c #828238", "! c #6A6A94",
"......!@@@@@@@....$$....", "......!@@@@@@@....$$....",
"...@!@@@@@@@**...$#'....", "...@!@@@@@@@**...$#'....",
"..!!@@@@@@@@.......#....", "..!!@@@@@@@@.......#....",
"..!@@@@@@@@@*.......$...", "..!@@@@@@@@@*.......$...",
".!@@@#,,#*@@*..*>.*.#...", ".!@@@#,,#*@@*..*>.*.#...",
"*@@@@#'',,@@@...---!....", "*@@@@#'',,@@@...---!....",
"!@@@@@*.#;*@@..!--->....", "!@@@@@*.#;*@@..!--->....",
"@@@@@@@@#,.@@..!----@...", "@@@@@@@@#,.@@..!----@...",
"!@@@@@@*#;'$...!----@...", "!@@@@@@*#;'$...!----@...",
"*@@@@@@..'&;;#.)----)...", "*@@@@@@..'&;;#.)----)...",
".@@@@@@..$..&'.>----)...", ".@@@@@@..$..&'.>----)...",
".@@@@@@**---,'>-----!...", ".@@@@@@**---,'>-----!...",
".@@@@@@**---,'>-----@...", ".@@@@@@**---,'>-----@...",
"..@@@@@@@---;;;,;---....", "..@@@@@@@---;;;,;---....",
"..*@@@@*@--->#',;,-*.)..", "..*@@@@*@--->#',;,-*.)..",
"........)---->)@;#!..>..", "........)---->)@;#!..>..",
".....)----------;$..>)..", ".....)----------;$..>)..",
"=%%%*.*!-------);..)-*..", "=%%%*.*!-------);..)-*..",
"=%%%%+...*)>!@*$,.>--...", "=%%%%+...*)>!@*$,.>--...",
"*+++++++.......*$@-->...", "*+++++++.......*$@-->...",
"............**@)!)>->...", "............**@)!)>->...",
"........................", "........................",
"........................", "........................",
"........................"}; "........................"};
typedef struct W_Text { typedef struct W_Text {
W_Class widgetClass; /* the class number of this widget */ W_Class widgetClass; /* the class number of this widget */
@@ -213,7 +209,7 @@ typedef struct W_Text {
#define MIN_DOC_WIDTH 200 #define MIN_DOC_WIDTH 200
typedef struct _LocalMargins { typedef struct _LocalMargins {
short left, right, first, body; short left, right, first, body;
} LocalMargins; } LocalMargins;
typedef struct _MyTextItems { typedef struct _MyTextItems {
char text[MAX_WORD_LENGTH+1]; char text[MAX_WORD_LENGTH+1];
@@ -328,7 +324,7 @@ myDrawText(Text *tPtr, Paragraph *para, MyTextItems *items,
items[i].text, items[i].chars); items[i].text, items[i].chars);
} else { } else {
mx_descent = WMIN(mx_descent, -(items[i].pix->height-3)); mx_descent = WMIN(mx_descent, -(items[i].pix->height-3));
/* replace -3 wif descent... */ /* replace -3 wif descent... */
line_height = WMAX(line_height, items[i].pix->height); line_height = WMAX(line_height, items[i].pix->height);
if(para->align == WARight || para->align == WACenter) { if(para->align == WARight || para->align == WACenter) {
line_width += items[i].pix->width; line_width += items[i].pix->width;
@@ -460,7 +456,7 @@ drawTChunkPart(Text *tPtr, Chunk *chunk, char *bufr, LocalMargins m,
{ {
short t_chunk_width, p_width, chars; short t_chunk_width, p_width, chars;
WMFont *font = (tPtr->monoFont)?tPtr->dFont:chunk->font; WMFont *font = (tPtr->monoFont)?tPtr->dFont:chunk->font;
/* if(doc->clickstart.yes && doc->clickstart.done) return; */ /* if(doc->clickstart.yes && doc->clickstart.done) return; */
if(len==0) return; if(len==0) return;
p_width = m.right - WMIN(m.first, m.body); p_width = m.right - WMIN(m.first, m.body);
@@ -737,9 +733,9 @@ calcDocExtents(Text *tPtr)
/* If any part of a paragraph is viewable, the entire /* If any part of a paragraph is viewable, the entire
paragraph is drawn on an otherwise empty (XFreePixmap) pixmap. paragraph is drawn on an otherwise empty (XFreePixmap) pixmap.
The actual viewable parts of the paragraph(s) are then pieced The actual viewable parts of the paragraph(s) are then pieced
together via paintText: together via paintText:
------------------------------------------- -------------------------------------------
|| this is a paragraph in this document|| || this is a paragraph in this document||
@@ -762,7 +758,7 @@ together via paintText:
------------------------------------------- -------------------------------------------
simple, right? Performance: the best of both worlds... simple, right? Performance: the best of both worlds...
o fast scrolling: no need to rewrite what's already o fast scrolling: no need to rewrite what's already
on the screen, simply XCopy it. on the screen, simply XCopy it.
o fast typing: only change current para, then simply o fast typing: only change current para, then simply
@@ -815,7 +811,7 @@ paintText(Text *tPtr)
if(tPtr->hasVscroller) vS = 21; if(tPtr->hasVscroller) vS = 21;
if(tPtr->hasHscroller) hS = 21; if(tPtr->hasHscroller) hS = 21;
//XClearWindow(tPtr->view->screen->display, tPtr->view->window); //XClearWindow(tPtr->view->screen->display, tPtr->view->window);
lmargin = WMGetRulerMargin(tPtr->ruler, WRulerDocLeft); lmargin = WMGetRulerMargin(tPtr->ruler, WRulerDocLeft);
if(tPtr->paragraphs) { if(tPtr->paragraphs) {
@@ -857,7 +853,7 @@ paintText(Text *tPtr)
vS+1, rh+5, lmargin-vS, tPtr->visibleH+rh+5-vS, False); vS+1, rh+5, lmargin-vS, tPtr->visibleH+rh+5-vS, False);
// from the "selection" days... // from the "selection" days...
W_DrawRelief(tPtr->view->screen, WMWidgetXID(tPtr), W_DrawRelief(tPtr->view->screen, WMWidgetXID(tPtr),
tPtr->sRect.pos.x, tPtr->sRect.pos.y, tPtr->sRect.pos.x, tPtr->sRect.pos.y,
tPtr->sRect.size.width, tPtr->sRect.size.height, tPtr->relief); tPtr->sRect.size.width, tPtr->sRect.size.height, tPtr->relief);
@@ -1046,23 +1042,23 @@ scrollersCallBack(WMWidget *w, void *self)
#if 0 #if 0
case WSKnobSlot: case WSKnobSlot:
case WSNoPart: case WSNoPart:
float vmax = (float)(tPtr->docHeight); float vmax = (float)(tPtr->docHeight);
((float)tPtr->vpos)/(vmax - (float)tPtr->visibleH), ((float)tPtr->vpos)/(vmax - (float)tPtr->visibleH),
(float)tPtr->visibleH/vmax); (float)tPtr->visibleH/vmax);
dimple =where mouse is. dimple =where mouse is.
#endif #endif
break; break;
} }
scroll = (tPtr->vpos != tPtr->prevVpos); scroll = (tPtr->vpos != tPtr->prevVpos);
tPtr->prevVpos = tPtr->vpos; tPtr->prevVpos = tPtr->vpos;
} }
if(w == tPtr->hscroller) if(w == tPtr->hscroller)
; ;
//need scrollv || scrollh //need scrollv || scrollh
if(scroll) { if(scroll) {
/* /*
if(0&&dimple) { if(0&&dimple) {
if(tPtr->rulerShown) if(tPtr->rulerShown)
XClearArea(tPtr->view->screen->display, tPtr->view->window, 22, 47, XClearArea(tPtr->view->screen->display, tPtr->view->window, 22, 47,
@@ -1071,11 +1067,11 @@ dimple =where mouse is.
XClearArea(tPtr->view->screen->display, tPtr->view->window, 22, 2, XClearArea(tPtr->view->screen->display, tPtr->view->window, 22, 2,
tPtr->view->size.width-24, tPtr->view->size.height-4, True); tPtr->view->size.width-24, tPtr->view->size.height-4, True);
} }
*/ */
updateScrollers(tPtr); updateScrollers(tPtr);
drawDocumentPartsOnPixmap(tPtr, False); drawDocumentPartsOnPixmap(tPtr, False);
paintText(tPtr); paintText(tPtr);
} }
} }
@@ -1177,14 +1173,14 @@ cursorToTextPosition(Text *tPtr, int x, int y)
if(line_width+tPtr->clicked.x >= x) { if(line_width+tPtr->clicked.x >= x) {
line_width -= _width; line_width -= _width;
done = True; done = True;
printf("break\n"); printf("break\n");
break; break;
} } } }
if(0&&chunk->next) { if(0&&chunk->next) {
if(chunk->next->type == ctImage) { if(chunk->next->type == ctImage) {
if(x+10 < line_width+chunk->next->pixmap->width) { if(x+10 < line_width+chunk->next->pixmap->width) {
printf("true\n"); printf("true\n");
done = True; done = True;
} } } } } }
} else { } else {
@@ -1240,7 +1236,7 @@ deleteTextInteractively(Text *tPtr, DeleteType type)
case dtBackSpace: /* delete _before_ cursor */ case dtBackSpace: /* delete _before_ cursor */
if(chunk->chars > 1) { if(chunk->chars > 1) {
pos = tPtr->tpos-1; pos = tPtr->tpos-1;
printf("here %d\n", pos); printf("here %d\n", pos);
if(pos>0) { if(pos>0) {
w = WMWidthOfString(font, &chunk->text[pos], 1); w = WMWidthOfString(font, &chunk->text[pos], 1);
memmove(&(chunk->text[pos]), memmove(&(chunk->text[pos]),
@@ -1282,7 +1278,7 @@ printf("here %d\n", pos);
putParagraphOnPixmap(tPtr, para, True); putParagraphOnPixmap(tPtr, para, True);
drawDocumentPartsOnPixmap(tPtr, False); drawDocumentPartsOnPixmap(tPtr, False);
updateScrollers(tPtr); updateScrollers(tPtr);
paintText(tPtr); paintText(tPtr);
//cursorToTextPosition(tPtr, tPtr->clicked.x-w, tPtr->clicked.y); //cursorToTextPosition(tPtr, tPtr->clicked.x-w, tPtr->clicked.y);
} else WMRefreshText(tPtr, tPtr->vpos, tPtr->hpos); } else WMRefreshText(tPtr, tPtr->vpos, tPtr->hpos);
} }
@@ -1373,10 +1369,10 @@ insertTextInteractively(Text *tPtr, char *text)
} else if(chunk->type == ctImage) { } else if(chunk->type == ctImage) {
WMPrependTextStream(tPtr, text); WMPrependTextStream(tPtr, text);
printf("\n\nprepe\n\n"); printf("\n\nprepe\n\n");
} else { } else {
if(tPtr->tpos > chunk->chars) { if(tPtr->tpos > chunk->chars) {
printf("\n\nmore\n\n"); printf("\n\nmore\n\n");
tPtr->tpos = chunk->chars; tPtr->tpos = chunk->chars;
} }
@@ -1391,8 +1387,8 @@ printf("\n\nmore\n\n");
memmove(&chunk->text[tPtr->tpos], text, 1); memmove(&chunk->text[tPtr->tpos], text, 1);
chunk->chars++; chunk->chars++;
tPtr->tpos++; tPtr->tpos++;
//doc->clickstart.cursor.x += //doc->clickstart.cursor.x +=
//WMWidthOfString(chunk->fmt->font, text,len); //WMWidthOfString(chunk->fmt->font, text,len);
} }
} }
@@ -1402,10 +1398,10 @@ printf("\n\nmore\n\n");
putParagraphOnPixmap(tPtr, para, True); putParagraphOnPixmap(tPtr, para, True);
drawDocumentPartsOnPixmap(tPtr, False); drawDocumentPartsOnPixmap(tPtr, False);
updateScrollers(tPtr); updateScrollers(tPtr);
paintText(tPtr); paintText(tPtr);
//cursorToTextPosition(tPtr, tPtr->clicked.x+w, tPtr->clicked.y); //cursorToTextPosition(tPtr, tPtr->clicked.x+w, tPtr->clicked.y);
//check for "sneppah tahw" with blank paras... //check for "sneppah tahw" with blank paras...
//paintText(tPtr); //paintText(tPtr);
} }
} }
@@ -1419,14 +1415,14 @@ selectRegion(Text *tPtr, int x, int y)
if(tPtr->sRect.pos.y<0) tPtr->sRect.pos.y=0; if(tPtr->sRect.pos.y<0) tPtr->sRect.pos.y=0;
tPtr->sRect.size.height = abs(tPtr->clicked.y-y); tPtr->sRect.size.height = abs(tPtr->clicked.y-y);
/* /*
while(y>tPtr->visibleH && tPtr->vpos < tPtr->docHeight-tPtr->visibleH) { while(y>tPtr->visibleH && tPtr->vpos < tPtr->docHeight-tPtr->visibleH) {
WMRefreshText(tPtr, tPtr->vpos+16, tPtr->hpos); WMRefreshText(tPtr, tPtr->vpos+16, tPtr->hpos);
} }
*/ */
//printf("%d %d \n", y, tPtr->vpos); //printf("%d %d \n", y, tPtr->vpos);
//foreach para in selection... //foreach para in selection...
drawDocumentPartsOnPixmap(tPtr, True); drawDocumentPartsOnPixmap(tPtr, True);
paintText(tPtr); paintText(tPtr);
} }
@@ -1485,7 +1481,7 @@ handleTextKeyPress(Text *tPtr, XEvent *event)
case XK_Down: case XK_Down:
case XK_Up: case XK_Up:
noCChunk: { short h = tPtr->clheight-2; noCChunk: { short h = tPtr->clheight-2;
if(ksym==XK_Down) h = -h; if(ksym==XK_Down) h = -h;
cursorToTextPosition(tPtr, tPtr->clicked.x, tPtr->clicked.y-h); cursorToTextPosition(tPtr, tPtr->clicked.x, tPtr->clicked.y-h);
} break; } break;
@@ -1575,10 +1571,10 @@ requestHandler(WMView *view, Atom selection, Atom target,
if(!tPtr->ownsSelection || !tPtr->paragraphs) return NULL; if(!tPtr->ownsSelection || !tPtr->paragraphs) return NULL;
//printf("got here\n"); //printf("got here\n");
if (target == XA_STRING || target == TEXT || target == COMPOUND_TEXT) { if (target == XA_STRING || target == TEXT || target == COMPOUND_TEXT) {
//for bleh in selection... //for bleh in selection...
char *s = NULL; char *s = NULL;
Paragraph *para = tPtr->paragraphs; Paragraph *para = tPtr->paragraphs;
Chunk *chunk = NULL; Chunk *chunk = NULL;
@@ -1601,14 +1597,14 @@ requestHandler(WMView *view, Atom selection, Atom target,
data = WMCreateDataWithBytes(s, strlen(s)); data = WMCreateDataWithBytes(s, strlen(s));
first = False; first = False;
} else { } else {
printf("append: %c %d\n", *s, strlen(s)); printf("append: %c %d\n", *s, strlen(s));
WMAppendDataBytes(data, s, strlen(s)); WMAppendDataBytes(data, s, strlen(s));
} }
//gdbFree(s); //gdbFree(s);
} } } } } }
#if 0 #if 0
printf("len is %d [%d %d] %d \n", len, chunk->sStart, chunk->sEnd, printf("len is %d [%d %d] %d \n", len, chunk->sStart, chunk->sEnd,
chunk->chars); chunk->chars);
#endif #endif
chunk = chunk->next; chunk = chunk->next;
} }
@@ -1655,7 +1651,7 @@ static WMSelectionProcs selectionHandler = {
requestHandler, lostHandler, NULL }; requestHandler, lostHandler, NULL };
static void static void
_notification(void *observerData, WMNotification *notification) _notification(void *observerData, WMNotification *notification)
{ {
WMText *to = (WMText *)observerData; WMText *to = (WMText *)observerData;
WMText *tw = (WMText *)WMGetNotificationClientData(notification); WMText *tw = (WMText *)WMGetNotificationClientData(notification);
@@ -1783,7 +1779,7 @@ handleNonTextEvents(XEvent *event, void *data)
} }
//printf("handleNonTextEvents\n"); //printf("handleNonTextEvents\n");
} }
@@ -2104,7 +2100,7 @@ WMCreateText(WMWidget *parent)
tPtr->docWidth = 0; tPtr->docWidth = 0;
tPtr->docHeight = 0; tPtr->docHeight = 0;
tPtr->dBulletPix = WMCreatePixmapFromXPMData(tPtr->view->screen, tPtr->dBulletPix = WMCreatePixmapFromXPMData(tPtr->view->screen,
default_bullet); default_bullet);
tPtr->dUnknownImg = WMCreatePixmapFromXPMData(tPtr->view->screen, tPtr->dUnknownImg = WMCreatePixmapFromXPMData(tPtr->view->screen,
unk_xpm); unk_xpm);
@@ -2158,9 +2154,9 @@ WMCreateText(WMWidget *parent)
WMShowTextRuler(tPtr, False); WMShowTextRuler(tPtr, False);
WMSetTextHasHorizontalScroller(tPtr, False); WMSetTextHasHorizontalScroller(tPtr, False);
WMSetTextHasVerticalScroller(tPtr, True); WMSetTextHasVerticalScroller(tPtr, True);
//printf("the sizeof chunk is %d\n", sizeof(Chunk)); //printf("the sizeof chunk is %d\n", sizeof(Chunk));
//printf("the sizeof para is %d\n", sizeof(Paragraph)); //printf("the sizeof para is %d\n", sizeof(Paragraph));
//printf("the sizeof text is %d\n", sizeof(Text)); //printf("the sizeof text is %d\n", sizeof(Text));
return tPtr; return tPtr;
} }
@@ -2186,7 +2182,7 @@ WMRemoveTextParagraph(WMText *tPtr, int which)
prior->next = removed->next; prior->next = removed->next;
} }
wgdbFree(removed); wgdbFree(removed);
// removeChunks // removeChunks
removed = NULL; removed = NULL;
} }
@@ -2248,7 +2244,7 @@ WMGetTextCurrentParagraph(WMText *tPtr)
} }
/* set what is known as the currentChunk within the currently /* set what is known as the currentChunk within the currently
selected currentPara (or the first paragraph in the document). */ selected currentPara (or the first paragraph in the document). */
void void
WMSetTextCurrentChunk(WMText *tPtr, int current) WMSetTextCurrentChunk(WMText *tPtr, int current)
{ {
@@ -2538,20 +2534,20 @@ WMRefreshText(WMText *tPtr, int vpos, int hpos)
tPtr->visibleW, tPtr->visibleH, True); tPtr->visibleW, tPtr->visibleH, True);
calcDocExtents(tPtr); calcDocExtents(tPtr);
/* /*
printf("vpos:%d tPtr->docHeight%d tPtr->visibleH%d \n", printf("vpos:%d tPtr->docHeight%d tPtr->visibleH%d \n",
vpos, tPtr->docHeight, tPtr->visibleH); vpos, tPtr->docHeight, tPtr->visibleH);
*/ */
// tPtr->vpos = vpos; // tPtr->vpos = vpos;
/* /*
if(vpos < 0 || tPtr->docHeight < tPtr->visibleH) if(vpos < 0 || tPtr->docHeight < tPtr->visibleH)
tPtr->vpos = 0; tPtr->vpos = 0;
else if(vpos-tPtr->visibleH>tPtr->docHeight) else if(vpos-tPtr->visibleH>tPtr->docHeight)
tPtr->vpos = vpos-tPtr->docHeight-tPtr->visibleH-tPtr->docHeight; tPtr->vpos = vpos-tPtr->docHeight-tPtr->visibleH-tPtr->docHeight;
else else
tPtr->vpos = tPtr->docHeight-tPtr->visibleH; tPtr->vpos = tPtr->docHeight-tPtr->visibleH;
*/ */
if(hpos < 0 || hpos > tPtr->docWidth) if(hpos < 0 || hpos > tPtr->docWidth)