mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-22 14:08:06 +01:00
fixed arrow navigation quirks and color mem leaks
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
#define DO_BLINK 0
|
#define DO_BLINK 0
|
||||||
|
|
||||||
/* TODO:
|
/* TODO:
|
||||||
|
* - verify what happens with XK_return in insertTextInt...
|
||||||
* - selection code... selects can be funny if it crosses over. use rect?
|
* - selection code... selects can be funny if it crosses over. use rect?
|
||||||
* - also inspect behaviour for WACenter and WARight
|
* - also inspect behaviour for WACenter and WARight
|
||||||
* - what if a widget grabs the click... howto say: "pressed me"?
|
* - what if a widget grabs the click... howto say: "pressed me"?
|
||||||
@@ -167,7 +168,8 @@ typedef struct W_Text {
|
|||||||
} Text;
|
} Text;
|
||||||
|
|
||||||
|
|
||||||
#define NOTIFY(T,C,N,A) { WMNotification *notif = WMCreateNotification(N,T,A);\
|
#define NOTIFY(T,C,N,A) {\
|
||||||
|
WMNotification *notif = WMCreateNotification(N,T,A);\
|
||||||
if ((T)->delegate && (T)->delegate->C)\
|
if ((T)->delegate && (T)->delegate->C)\
|
||||||
(*(T)->delegate->C)((T)->delegate,notif);\
|
(*(T)->delegate->C)((T)->delegate,notif);\
|
||||||
WMPostNotification(notif);\
|
WMPostNotification(notif);\
|
||||||
@@ -176,6 +178,7 @@ typedef struct W_Text {
|
|||||||
|
|
||||||
#define TYPETEXT 0
|
#define TYPETEXT 0
|
||||||
|
|
||||||
|
/* just to print blocks of text not terminated by \0 */
|
||||||
static void
|
static void
|
||||||
output(char *ptr, int len)
|
output(char *ptr, int len)
|
||||||
{
|
{
|
||||||
@@ -379,7 +382,10 @@ _selEnd: rect->x = tb->sections[s].x + lw;
|
|||||||
tb->s_end = (tb->selected? WMAX(tb->s_end, i) : i);
|
tb->s_end = (tb->selected? WMAX(tb->s_end, i) : i);
|
||||||
selected = True;
|
selected = True;
|
||||||
break;
|
break;
|
||||||
} } } }
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (selected) {
|
if (selected) {
|
||||||
rect->y = tb->sections[s]._y - tPtr->vpos;
|
rect->y = tb->sections[s]._y - tPtr->vpos;
|
||||||
@@ -626,10 +632,12 @@ paintText(Text *tPtr)
|
|||||||
WMScreen *scr = tPtr->view->screen;
|
WMScreen *scr = tPtr->view->screen;
|
||||||
Display *dpy = tPtr->view->screen->display;
|
Display *dpy = tPtr->view->screen->display;
|
||||||
Window win = tPtr->view->window;
|
Window win = tPtr->view->window;
|
||||||
|
WMColor *color;
|
||||||
|
|
||||||
if (!tPtr->view->flags.realized || !tPtr->db || tPtr->flags.frozen)
|
if (!tPtr->view->flags.realized || !tPtr->db || tPtr->flags.frozen)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
XFillRectangle(dpy, tPtr->db, tPtr->bgGC,
|
XFillRectangle(dpy, tPtr->db, tPtr->bgGC,
|
||||||
0, 0, tPtr->visible.w, tPtr->visible.h);
|
0, 0, tPtr->visible.w, tPtr->visible.h);
|
||||||
|
|
||||||
@@ -645,8 +653,11 @@ paintText(Text *tPtr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tPtr->flags.ownsSelection)
|
if (tPtr->flags.ownsSelection) {
|
||||||
greyGC = WMColorGC(WMGrayColor(scr));
|
color = WMGrayColor(scr);
|
||||||
|
greyGC = WMColorGC(color);
|
||||||
|
WMReleaseColor(color);
|
||||||
|
}
|
||||||
|
|
||||||
done = False;
|
done = False;
|
||||||
|
|
||||||
@@ -810,7 +821,10 @@ if(tb->blank) {tb->text[0] = 'F'; } */
|
|||||||
tb->sections[0].y + h - tPtr->vpos,
|
tb->sections[0].y + h - tPtr->vpos,
|
||||||
tb->sections[0].x + tb->sections[0].w - tPtr->hpos,
|
tb->sections[0].x + tb->sections[0].w - tPtr->hpos,
|
||||||
tb->sections[0].y + h - tPtr->vpos);
|
tb->sections[0].y + h - tPtr->vpos);
|
||||||
} } } }
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
_copy_area:
|
_copy_area:
|
||||||
@@ -934,8 +948,10 @@ updateCursorPosition(Text *tPtr)
|
|||||||
|
|
||||||
if (! (tb = tPtr->currentTextBlock)) {
|
if (! (tb = tPtr->currentTextBlock)) {
|
||||||
if (! (tb = tPtr->firstTextBlock)) {
|
if (! (tb = tPtr->firstTextBlock)) {
|
||||||
|
WMFont *font = tPtr->dFont;
|
||||||
tPtr->tpos = 0;
|
tPtr->tpos = 0;
|
||||||
tPtr->cursor.h = tPtr->dFont->height;
|
tPtr->cursor.h = font->height + abs(font->height-font->y);
|
||||||
|
|
||||||
tPtr->cursor.y = 2;
|
tPtr->cursor.y = 2;
|
||||||
tPtr->cursor.x = 2;
|
tPtr->cursor.x = 2;
|
||||||
return;
|
return;
|
||||||
@@ -1019,8 +1035,9 @@ cursorToTextPosition(Text *tPtr, int x, int y)
|
|||||||
|
|
||||||
if (! (tb = tPtr->currentTextBlock)) {
|
if (! (tb = tPtr->currentTextBlock)) {
|
||||||
if (! (tb = tPtr->firstTextBlock)) {
|
if (! (tb = tPtr->firstTextBlock)) {
|
||||||
|
WMFont *font = tPtr->dFont;
|
||||||
tPtr->tpos = 0;
|
tPtr->tpos = 0;
|
||||||
tPtr->cursor.h = tPtr->dFont->height;
|
tPtr->cursor.h = font->height + abs(font->height-font->y);
|
||||||
tPtr->cursor.y = 2;
|
tPtr->cursor.y = 2;
|
||||||
tPtr->cursor.x = 2;
|
tPtr->cursor.x = 2;
|
||||||
return;
|
return;
|
||||||
@@ -1350,7 +1367,8 @@ scrollersCallBack(WMWidget *w, void *self)
|
|||||||
if (tPtr->hpos<limit-16) tPtr->hpos+=16;
|
if (tPtr->hpos<limit-16) tPtr->hpos+=16;
|
||||||
else tPtr->hpos=limit;
|
else tPtr->hpos=limit;
|
||||||
scroll = True;
|
scroll = True;
|
||||||
}}break;
|
}
|
||||||
|
}break;
|
||||||
|
|
||||||
case WSDecrementPage:
|
case WSDecrementPage:
|
||||||
if(((int)tPtr->hpos - (int)width) >= 0)
|
if(((int)tPtr->hpos - (int)width) >= 0)
|
||||||
@@ -1731,8 +1749,6 @@ y = tPtr->docHeight+ss-sd;
|
|||||||
if(items && itemsSize > 0)
|
if(items && itemsSize > 0)
|
||||||
wfree(items);
|
wfree(items);
|
||||||
|
|
||||||
if (W_VIEW_REALIZED(tPtr->view) && W_VIEW_MAPPED(tPtr->view))
|
|
||||||
paintText(tPtr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1828,17 +1844,18 @@ clearText(Text *tPtr)
|
|||||||
WMEmptyArray(tPtr->gfxItems);
|
WMEmptyArray(tPtr->gfxItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* possibly remove a single character from the currentTextBlock,
|
||||||
|
or if there's a selection, remove it...
|
||||||
|
note that Delete and Backspace are treated differently */
|
||||||
static void
|
static void
|
||||||
deleteTextInteractively(Text *tPtr, KeySym ksym)
|
deleteTextInteractively(Text *tPtr, KeySym ksym)
|
||||||
{
|
{
|
||||||
TextBlock *tb;
|
TextBlock *tb;
|
||||||
Bool back = (Bool) (ksym == XK_BackSpace);
|
Bool back = (Bool) (ksym == XK_BackSpace);
|
||||||
Bool done = 1;
|
Bool done = 1, wasFirst = 0;
|
||||||
Bool wasFirst = 0;
|
|
||||||
|
|
||||||
if (!tPtr->flags.editable) {
|
if (!tPtr->flags.editable)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if ( !(tb = tPtr->currentTextBlock) )
|
if ( !(tb = tPtr->currentTextBlock) )
|
||||||
return;
|
return;
|
||||||
@@ -1892,9 +1909,13 @@ deleteTextInteractively(Text *tPtr, KeySym ksym)
|
|||||||
done = 0;
|
done = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (back? (tPtr->tpos < 1 && !done) : ( tPtr->tpos >= tb->used))
|
/* if there are no characters left to back over in the textblock,
|
||||||
|
but it still has characters to the right of the cursor: */
|
||||||
|
if ( (back? (tPtr->tpos == 0 && !done) : ( tPtr->tpos >= tb->used))
|
||||||
|| tb->graphic) {
|
|| tb->graphic) {
|
||||||
|
|
||||||
|
/* no more chars, and it's marked as blank? */
|
||||||
|
if(tb->blank) {
|
||||||
TextBlock *sibling = (back? tb->prior : tb->next);
|
TextBlock *sibling = (back? tb->prior : tb->next);
|
||||||
|
|
||||||
if(tb->used == 0 || tb->graphic)
|
if(tb->used == 0 || tb->graphic)
|
||||||
@@ -1904,6 +1925,9 @@ deleteTextInteractively(Text *tPtr, KeySym ksym)
|
|||||||
tPtr->currentTextBlock = sibling;
|
tPtr->currentTextBlock = sibling;
|
||||||
tPtr->tpos = (back? sibling->used : 0);
|
tPtr->tpos = (back? sibling->used : 0);
|
||||||
}
|
}
|
||||||
|
/* no more chars, so mark it as blank */
|
||||||
|
} else if(tb->used == 0)
|
||||||
|
tb->blank = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
layOutDocument(tPtr);
|
layOutDocument(tPtr);
|
||||||
@@ -1990,7 +2014,6 @@ insertTextInteractively(Text *tPtr, char *text, int len)
|
|||||||
} else {
|
} else {
|
||||||
if (tb->used + len >= tb->allocated) {
|
if (tb->used + len >= tb->allocated) {
|
||||||
tb->allocated = reqBlockSize(tb->used+len);
|
tb->allocated = reqBlockSize(tb->used+len);
|
||||||
printf("realloced %d... %d\n", tb->allocated, tb->used+len);
|
|
||||||
tb->text = wrealloc(tb->text, tb->allocated);
|
tb->text = wrealloc(tb->text, tb->allocated);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2228,9 +2251,6 @@ handleTextKeyPress(Text *tPtr, XEvent *event)
|
|||||||
if (((XKeyEvent *) event)->state & ControlMask)
|
if (((XKeyEvent *) event)->state & ControlMask)
|
||||||
control_pressed = True;
|
control_pressed = True;
|
||||||
buffer[XLookupString(&event->xkey, buffer, 63, &ksym, NULL)] = 0;
|
buffer[XLookupString(&event->xkey, buffer, 63, &ksym, NULL)] = 0;
|
||||||
if(!*buffer)
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
|
||||||
switch(ksym) {
|
switch(ksym) {
|
||||||
|
|
||||||
@@ -2243,7 +2263,9 @@ handleTextKeyPress(Text *tPtr, XEvent *event)
|
|||||||
if(tPtr->tpos==0) {
|
if(tPtr->tpos==0) {
|
||||||
L_imaGFX: if(tb->prior) {
|
L_imaGFX: if(tb->prior) {
|
||||||
tPtr->currentTextBlock = tb->prior;
|
tPtr->currentTextBlock = tb->prior;
|
||||||
tPtr->tpos = tPtr->currentTextBlock->used -1;
|
tPtr->tpos = tPtr->currentTextBlock->used;
|
||||||
|
if(!tb->first && tPtr->tpos > 0)
|
||||||
|
tPtr->tpos--;
|
||||||
} else tPtr->tpos = 0;
|
} else tPtr->tpos = 0;
|
||||||
} else tPtr->tpos--;
|
} else tPtr->tpos--;
|
||||||
updateCursorPosition(tPtr);
|
updateCursorPosition(tPtr);
|
||||||
@@ -2258,7 +2280,9 @@ L_imaGFX: if(tb->prior) {
|
|||||||
if(tPtr->tpos == tb->used) {
|
if(tPtr->tpos == tb->used) {
|
||||||
R_imaGFX: if(tb->next) {
|
R_imaGFX: if(tb->next) {
|
||||||
tPtr->currentTextBlock = tb->next;
|
tPtr->currentTextBlock = tb->next;
|
||||||
tPtr->tpos = 1;
|
tPtr->tpos = 0;
|
||||||
|
if(!tb->next->first && tb->next->used>0)
|
||||||
|
tPtr->tpos++;
|
||||||
} else tPtr->tpos = tb->used;
|
} else tPtr->tpos = tb->used;
|
||||||
} else tPtr->tpos++;
|
} else tPtr->tpos++;
|
||||||
updateCursorPosition(tPtr);
|
updateCursorPosition(tPtr);
|
||||||
@@ -2412,7 +2436,8 @@ handleActionEvents(XEvent *event, void *data)
|
|||||||
if ((event->xmotion.state & Button1Mask)) {
|
if ((event->xmotion.state & Button1Mask)) {
|
||||||
TextBlock *tb = tPtr->currentTextBlock;
|
TextBlock *tb = tPtr->currentTextBlock;
|
||||||
|
|
||||||
if(tPtr->flags.isOverGraphic && tb && tb->graphic && !tb->object) {
|
if(tb && tPtr->flags.isOverGraphic &&
|
||||||
|
tb->graphic && !tb->object) {
|
||||||
WMSize offs;
|
WMSize offs;
|
||||||
WMPixmap *pixmap = tb->d.pixmap;
|
WMPixmap *pixmap = tb->d.pixmap;
|
||||||
char *types[2] = {"application/X-image", NULL};
|
char *types[2] = {"application/X-image", NULL};
|
||||||
@@ -2452,7 +2477,7 @@ handleActionEvents(XEvent *event, void *data)
|
|||||||
if (tPtr->flags.waitingForSelection)
|
if (tPtr->flags.waitingForSelection)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (tPtr->flags.extendSelection) {
|
if (tPtr->flags.extendSelection && tPtr->flags.ownsSelection) {
|
||||||
selectRegion(tPtr, event->xmotion.x, event->xmotion.y);
|
selectRegion(tPtr, event->xmotion.x, event->xmotion.y);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -3092,6 +3117,7 @@ WMCreateTextForDocumentType(WMWidget *parent, WMAction *parser, WMAction *writer
|
|||||||
tPtr->flags.ignoreNewLine = False;
|
tPtr->flags.ignoreNewLine = False;
|
||||||
tPtr->flags.indentNewLine = False;
|
tPtr->flags.indentNewLine = False;
|
||||||
tPtr->flags.laidOut = False;
|
tPtr->flags.laidOut = False;
|
||||||
|
tPtr->flags.ownsSelection = False;
|
||||||
tPtr->flags.waitingForSelection = False;
|
tPtr->flags.waitingForSelection = False;
|
||||||
tPtr->flags.prepend = False;
|
tPtr->flags.prepend = False;
|
||||||
tPtr->flags.isOverGraphic = False;
|
tPtr->flags.isOverGraphic = False;
|
||||||
@@ -3522,8 +3548,11 @@ WMSetTextForegroundColor(WMText *tPtr, WMColor *color)
|
|||||||
|
|
||||||
if (color)
|
if (color)
|
||||||
tPtr->fgGC = WMColorGC(color);
|
tPtr->fgGC = WMColorGC(color);
|
||||||
else
|
else {
|
||||||
tPtr->fgGC = WMColorGC(WMBlackColor(tPtr->view->screen));
|
WMColor *color = WMBlackColor(tPtr->view->screen);
|
||||||
|
tPtr->fgGC = WMColorGC(color);
|
||||||
|
WMReleaseColor(color);
|
||||||
|
}
|
||||||
|
|
||||||
paintText(tPtr);
|
paintText(tPtr);
|
||||||
}
|
}
|
||||||
@@ -3689,13 +3718,15 @@ WMScrollText(WMText *tPtr, int amount)
|
|||||||
if (tPtr->vpos > abs(amount)) tPtr->vpos += amount;
|
if (tPtr->vpos > abs(amount)) tPtr->vpos += amount;
|
||||||
else tPtr->vpos=0;
|
else tPtr->vpos=0;
|
||||||
scroll=True;
|
scroll=True;
|
||||||
} } else {
|
}
|
||||||
|
} else {
|
||||||
int limit = tPtr->docHeight - tPtr->visible.h;
|
int limit = tPtr->docHeight - tPtr->visible.h;
|
||||||
if (tPtr->vpos < limit) {
|
if (tPtr->vpos < limit) {
|
||||||
if (tPtr->vpos < limit-amount) tPtr->vpos += amount;
|
if (tPtr->vpos < limit-amount) tPtr->vpos += amount;
|
||||||
else tPtr->vpos = limit;
|
else tPtr->vpos = limit;
|
||||||
scroll = True;
|
scroll = True;
|
||||||
} }
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (scroll && tPtr->vpos != tPtr->prevVpos) {
|
if (scroll && tPtr->vpos != tPtr->prevVpos) {
|
||||||
updateScrollers(tPtr);
|
updateScrollers(tPtr);
|
||||||
|
|||||||
Reference in New Issue
Block a user