1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-01-03 04:14:20 +01:00

Text Selection 99% complete, replaceSelection added

This commit is contained in:
nwanua
2000-09-01 17:58:29 +00:00
parent f813ff12d4
commit cc3bbcaf4c
4 changed files with 2499 additions and 2188 deletions

View File

@@ -385,22 +385,17 @@ typedef struct WMInputPanel {
/* WMRuler: a tabstop is a linked list of tabstops,
each containing the position of the tabstop */
/* WMRuler: */
typedef struct {
int value;
struct WMTabStops *next;
} WMTabStops;
/* All indentation and tab markers are _relative_ to the left margin marker */
typedef struct {
int left; /* left margin marker */
int right; /* right margin marker */
int first; /* indentation marker for first line only */
int body; /* body indentation marker */
WMTabStops *tabs;
unsigned int *tabs; /* a growable array of tabstops */
unsigned short ntabstops:4; /* how many there are */
unsigned short left:15; /* left margin marker */
unsigned short right:15; /* right margin marker */
unsigned short first:15; /* indentation marker for first line only */
unsigned short body:15; /* body indentation marker */
} WMRulerMargins;
/* All indentation and tab markers are _relative_ to the left margin marker */
typedef void *WMHandlerID;
@@ -1457,17 +1452,17 @@ void WMPrependTextStream(WMText *tPtr, char *text);
void WMAppendTextStream(WMText *tPtr, char *text);
/* free the returned text */
/* free the text */
char * WMGetTextStream(WMText *tPtr);
/* destroy the bag */
WMBag * WMGetTextStreamObjects(WMText *tPtr);
/* free the returned text */
/* free the text */
char * WMGetTextSelected(WMText *tPtr);
/* destroy the bag */
WMBag * WMGetTextSelectedObjects(WMText *tPtr);
WMBag * WMGetTextStreamIntoBag(WMText *tPtr);
/* destroy the bag */
WMBag * WMGetTextSelectedIntoBag(WMText *tPtr);
void *WMCreateTextBlockWithObject(WMWidget *w, char *description,
WMColor *color, unsigned short first, unsigned short reserved);
@@ -1480,12 +1475,12 @@ void *WMCreateTextBlockWithText(char *text, WMFont *font,
void WMSetTextBlockProperties(void *vtb, unsigned int first,
unsigned int kanji, unsigned int underlined, int script,
unsigned int marginN);
WMRulerMargins margins);
void WMGetTextBlockProperties(void *vtb, unsigned int *first,
unsigned int *kanji, unsigned int *underlined, int *script,
unsigned int *marginN);
WMRulerMargins *margins);
void WMSetTextSelectionColor(WMText *tPtr, WMColor *color);
void WMSetTextSelectionFont(WMText *tPtr, WMFont *font);

View File

@@ -65,7 +65,7 @@ mystrcasecmp(const unsigned char *s1, const unsigned char *s2)
{
if (!*s1 || !*s2) return 0;
while (*s2 != '\0') {
if (TOLOWER (*s1) != TOLOWER (*s2))
if (TOLOWER (*s1) != TOLOWER (*s2)) /* true if *s1 == 0 ! */
return 0;
s1++;
s2++;
@@ -79,6 +79,7 @@ typedef struct _currentFormat {
WMBag *colors;
WMColor *ccolor;
WMFont *cfont;
WMRulerMargins margins;
//WMBag *aligns; // for tables...
/* the following are "nested"
i.e.: <b><b><i></b><b></i>
@@ -133,7 +134,6 @@ void parseToken(WMText *tPtr, char *token, short tk)
/* 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);
@@ -145,7 +145,6 @@ void parseToken(WMText *tPtr, char *token, short tk)
cfmt.cfont = (WMFont *)WMGetFromBag(cfmt.fonts,
WMGetBagItemCount(cfmt.fonts)-1);
} break;
case 'b':
if(!mode) {
cfmt.cfont = WMGetFontBold(scr, cfmt.cfont);
@@ -161,8 +160,8 @@ void parseToken(WMText *tPtr, char *token, short tk)
cfmt.first = True;
tb = WMCreateTextBlockWithText(NULL, cfmt.cfont,
cfmt.ccolor, cfmt.first, 0);
WMSetTextBlockProperties(tb, cfmt.first, False, (cfmt.u?1:0), 0, 0);
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;
@@ -195,7 +194,7 @@ void parseToken(WMText *tPtr, char *token, short tk)
switch(TOLOWER(*token)) {
case 's':
if(TOLOWER(*(1+token)) == 'r' && TOLOWER(*(2+token)) == 'c') {
mark = (char *)strchr(token, '=');
mark = strchr(token, '=');
if(mark) {
char img[256], *iptr;
token = mark+1;
@@ -208,7 +207,7 @@ void parseToken(WMText *tPtr, char *token, short tk)
tb = WMCreateTextBlockWithPixmap(pixmap,
iptr, cfmt.ccolor, cfmt.first, 0);
WMSetTextBlockProperties(tb, cfmt.first,
False, (cfmt.u?1:0), 0, 0);
False, (cfmt.u?1:0), 0, cfmt.margins);
WMAppendTextBlock(tPtr, tb);
cfmt.first = False;
}
@@ -291,29 +290,42 @@ void HTMLParser(WMWidget *w, void *clientData)
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;
}else wasspace = 0;
if(c == '<' && !mode) {
mode = 1;
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, 0);
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) {
@@ -338,7 +350,7 @@ void HTMLParser(WMWidget *w, void *clientData)
(WMColor *)WMGetFromBag(cfmt.colors,
WMGetBagItemCount(cfmt.colors)-1),
cfmt.first, textlen);
WMSetTextBlockProperties(tb, cfmt.first, False, (cfmt.u?1:0), 0, 0);
WMSetTextBlockProperties(tb, cfmt.first, False, (cfmt.u?1:0), 0, cfmt.margins);
WMAppendTextBlock(tPtr, tb);
cfmt.first = False;
}
@@ -399,9 +411,9 @@ main(int argc, char **argv)
WMSetTextUsesMonoFont(text, !True);
WMSetTextParser(text, HTMLParser);
#if 0
WMShowTextRuler(text, True);
WMSetTextUseFixedPitchFont(text, False);
WMSetTextHasRuler(text, True);
WMShowTextRuler(text, True);
WMSetTextHasVerticalScroller(text, True);
//WMSetTextHasHorizontalScroller(text, True);
WMFreezeText(text);
@@ -472,7 +484,8 @@ interesting widgets like this list widget: ");
tb = WMCreateTextBlockWithObject(te, "{a text object}",
WMBlackColor(scr), False, 0);
WMAppendTextBlock(text, tb);
WMSetTextHasVerticalScroller(te, False);
WMSetTextHasVerticalScroller(te, True);
WMSetTextHasHorizontalScroller(te, True);
WMRefreshText(te, 0, 0);
}

View File

@@ -1,5 +1,5 @@
/*
* WINGs WMRuler nifty ruler widget for WINGs (OK, for WMText ;-)
* WINGs WMRuler: nifty ruler widget for WINGs :-)
*
* Copyright (c) 1999-2000 Nwanua Elumeze
*
@@ -26,27 +26,29 @@
typedef struct W_Ruler {
W_Class widgetClass;
W_View *view;
W_View *pview; /* the parent's view (for drawing the line) */
W_View *pview; /* the parent's view (for drawing the line) */
WMAction *moveAction; /* what to when while moving */
WMAction *releaseAction; /* what to do when released */
WMAction *moveAction; /* what to when while moving */
WMAction *releaseAction; /* what to do when released */
void *clientData;
GC fg, bg;
WMFont *font;
WMRulerMargins margins;
int offset;
int motion; /* the position of the _moving_ marker(s) */
int end; /* the last tick on the baseline (restrict markers to it) */
int motion; /* the position of the _moving_ marker(s) */
int end; /* the last tick on the baseline (restrict markers to it) */
Pixmap drawBuffer;
struct {
unsigned int buttonPressed:1;
unsigned int whichMarker:3;
/* 0, 1, 2, 3, 4, 5, 6 */
/* none, left, right, first, body, tabstop, first & body */
unsigned int RESERVED:28;
unsigned int whichMarker:3;
/* 0, 1, 2, 3, 4, 5, 6 */
/* none, left, right, first, body, tabstop, first & body */
unsigned int buttonPressed:1;
unsigned int redraw:1;
unsigned int RESERVED:27;
} flags;
} Ruler;
@@ -66,10 +68,10 @@ drawLeftMarker(Ruler * rPtr)
{
XPoint points[4];
int xpos = (rPtr->flags.whichMarker == 1 ?
rPtr->motion : rPtr->margins.left);
rPtr->motion : rPtr->margins.left);
XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer,
rPtr->fg, xpos, 8, xpos, 22);
rPtr->fg, xpos, 8, xpos, 22);
points[0].x = xpos;
points[0].y = 1;
points[1].x = points[0].x + 6;
@@ -79,7 +81,7 @@ drawLeftMarker(Ruler * rPtr)
points[3].x = points[0].x;
points[3].y = 9;
XFillPolygon(rPtr->view->screen->display, rPtr->drawBuffer,
rPtr->fg, points, 4, Convex, CoordModeOrigin);
rPtr->fg, points, 4, Convex, CoordModeOrigin);
}
@@ -96,10 +98,10 @@ static void drawRightMarker(Ruler * rPtr)
{
XPoint points[4];
int xpos = (rPtr->flags.whichMarker == 2 ?
rPtr->motion : rPtr->margins.right);
rPtr->motion : rPtr->margins.right);
XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer,
rPtr->fg, xpos, 8, xpos, 22);
rPtr->fg, xpos, 8, xpos, 22);
points[0].x = xpos + 1;
points[0].y = 0;
points[1].x = points[0].x - 6;
@@ -109,7 +111,7 @@ static void drawRightMarker(Ruler * rPtr)
points[3].x = points[0].x;
points[3].y = 9;
XFillPolygon(rPtr->view->screen->display, rPtr->drawBuffer,
rPtr->fg, points, 4, Convex, CoordModeOrigin);
rPtr->fg, points, 4, Convex, CoordModeOrigin);
}
@@ -122,24 +124,24 @@ static void drawRightMarker(Ruler * rPtr)
static void drawFirstMarker(Ruler * rPtr)
{
int xpos = ((rPtr->flags.whichMarker == 3 || rPtr->flags.whichMarker == 6) ?
rPtr->motion : rPtr->margins.first);
rPtr->motion : rPtr->margins.first);
XFillRectangle(rPtr->view->screen->display, rPtr->drawBuffer,
rPtr->fg, xpos - 5, 10, 11, 5);
rPtr->fg, xpos - 5, 10, 11, 5);
XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer,
rPtr->fg, xpos, 12, xpos, 22);
rPtr->fg, xpos, 12, xpos, 22);
}
/* Marker for rest of body
_____
\ /
\./
\./
*/
static void drawBodyMarker(Ruler * rPtr)
{
XPoint points[4];
int xpos = ((rPtr->flags.whichMarker == 4 || rPtr->flags.whichMarker == 6) ?
rPtr->motion : rPtr->margins.body);
rPtr->motion : rPtr->margins.body);
points[0].x = xpos - 5;
points[0].y = 16;
@@ -148,19 +150,23 @@ static void drawBodyMarker(Ruler * rPtr)
points[2].x = points[0].x + 5;
points[2].y = 22;
XFillPolygon(rPtr->view->screen->display, rPtr->drawBuffer,
rPtr->fg, points, 3, Convex, CoordModeOrigin);
rPtr->fg, points, 3, Convex, CoordModeOrigin);
}
static void createDrawBuffer(Ruler * rPtr)
{
if(!rPtr->view->flags.realized)
return;
if (rPtr->drawBuffer)
XFreePixmap(rPtr->view->screen->display, rPtr->drawBuffer);
XFreePixmap(rPtr->view->screen->display, rPtr->drawBuffer);
rPtr->drawBuffer = XCreatePixmap(rPtr->view->screen->display,
rPtr->view->window, rPtr->view->size.width, 40,
rPtr->view->screen->depth);
rPtr->view->window, rPtr->view->size.width, 40,
rPtr->view->screen->depth);
XFillRectangle(rPtr->view->screen->display, rPtr->drawBuffer,
rPtr->bg, 0, 0, rPtr->view->size.width, 40);
rPtr->bg, 0, 0, rPtr->view->size.width, 40);
}
@@ -171,44 +177,47 @@ static void drawRulerOnPixmap(Ruler * rPtr)
int marks[9] =
{11, 3, 5, 3, 7, 3, 5, 3};
if (!rPtr->drawBuffer)
createDrawBuffer(rPtr);
if (!rPtr->drawBuffer || !rPtr->view->flags.realized)
return;
XFillRectangle(rPtr->view->screen->display, rPtr->drawBuffer,
rPtr->bg, 0, 0, rPtr->view->size.width, 40);
rPtr->bg, 0, 0, rPtr->view->size.width, 40);
WMDrawString(rPtr->view->screen, rPtr->drawBuffer, rPtr->fg,
rPtr->font, rPtr->margins.left + 2, 26, "0 inches", 10);
rPtr->font, rPtr->margins.left + 2, 26, "0 inches", 10);
/* marker ticks */
i = j = m = 0;
w = rPtr->view->size.width - rPtr->margins.left;
while (m < w) {
XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer,
rPtr->fg, rPtr->margins.left + m, 23,
rPtr->margins.left + m, marks[i % 8] + 23);
if (i != 0 && i % 8 == 0) {
if (j < 10)
snprintf(c, 3, "%d", ++j);
else
snprintf(c, 3, "%2d", ++j);
WMDrawString(rPtr->view->screen, rPtr->drawBuffer, rPtr->fg,
rPtr->font, rPtr->margins.left + 2 + m, 26, c, 2);
}
m = (++i) * 10;
XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer,
rPtr->fg, rPtr->margins.left + m, 23,
rPtr->margins.left + m, marks[i % 8] + 23);
if (i != 0 && i % 8 == 0) {
if (j < 10)
snprintf(c, 3, "%d", ++j);
else
snprintf(c, 3, "%2d", ++j);
WMDrawString(rPtr->view->screen, rPtr->drawBuffer, rPtr->fg,
rPtr->font, rPtr->margins.left + 2 + m, 26, c, 2);
}
m = (++i) * 10;
}
rPtr->end = rPtr->margins.left + m - 10;
if (rPtr->margins.right > rPtr->end)
rPtr->margins.right = rPtr->end;
rPtr->margins.right = rPtr->end;
/* base line */
XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer, rPtr->fg,
rPtr->margins.left, 22, rPtr->margins.left + m - 10, 22);
rPtr->margins.left, 22, rPtr->margins.left + m - 10, 22);
drawLeftMarker(rPtr);
drawRightMarker(rPtr);
drawFirstMarker(rPtr);
drawBodyMarker(rPtr);
rPtr->flags.redraw = False;
}
@@ -216,12 +225,14 @@ static void paintRuler(Ruler * rPtr)
{
WMScreen *screen = rPtr->view->screen;
if (1 || !rPtr->drawBuffer) {
drawRulerOnPixmap(rPtr);
}
if (!rPtr->drawBuffer || !rPtr->view->flags.realized)
return;
if (rPtr->flags.redraw)
drawRulerOnPixmap(rPtr);
XCopyArea(rPtr->view->screen->display, rPtr->drawBuffer,
rPtr->view->window, rPtr->bg, 0, 0, rPtr->view->size.width, 40,
0, 0);
rPtr->view->window, rPtr->bg, 0, 0, rPtr->view->size.width, 40,
0, 0);
}
@@ -229,41 +240,41 @@ static Bool
verifyMarkerMove(Ruler * rPtr, int x)
{
if (rPtr->flags.whichMarker < 1 || rPtr->flags.whichMarker > 6)
return False;
return False;
switch (rPtr->flags.whichMarker) {
case 1:
if (x > rPtr->margins.right - 10 || x < rPtr->offset ||
rPtr->margins.body + x > rPtr->margins.right - MIN_DOC_WIDTH ||
rPtr->margins.first + x > rPtr->margins.right - MIN_DOC_WIDTH)
return False;
break;
if (x > rPtr->margins.right - 10 || x < rPtr->offset ||
rPtr->margins.body + x > rPtr->margins.right - MIN_DOC_WIDTH ||
rPtr->margins.first + x > rPtr->margins.right - MIN_DOC_WIDTH)
return False;
break;
case 2:
if (x < rPtr->margins.first + MIN_DOC_WIDTH ||
x < rPtr->margins.body + MIN_DOC_WIDTH ||
x < rPtr->margins.left + MIN_DOC_WIDTH ||
x > rPtr->end) /*rPtr->view->size.width) */
return False;
break;
if (x < rPtr->margins.first + MIN_DOC_WIDTH ||
x < rPtr->margins.body + MIN_DOC_WIDTH ||
x < rPtr->margins.left + MIN_DOC_WIDTH ||
x > rPtr->end) /*rPtr->view->size.width) */
return False;
break;
case 3:
if (x >= rPtr->margins.right - MIN_DOC_WIDTH || x < rPtr->margins.left)
return False;
break;
if (x >= rPtr->margins.right - MIN_DOC_WIDTH || x < rPtr->margins.left)
return False;
break;
case 4:
if (x >= rPtr->margins.right - MIN_DOC_WIDTH || x < rPtr->margins.left)
return False;
break;
if (x >= rPtr->margins.right - MIN_DOC_WIDTH || x < rPtr->margins.left)
return False;
break;
case 6:
if (x >= rPtr->margins.right - MIN_DOC_WIDTH || x < rPtr->margins.left)
return False;
break;
if (x >= rPtr->margins.right - MIN_DOC_WIDTH || x < rPtr->margins.left)
return False;
break;
default:
return False;
return False;
}
rPtr->motion = x;
@@ -274,37 +285,37 @@ static Bool
static int whichMarker(Ruler * rPtr, int x, int y)
{
if (x < rPtr->offset || y > 22)
return 0;
return 0;
if (rPtr->margins.left - x >= -6 && y <= 9
&& (rPtr->margins.left - x <= 0) && y >= 4) {
rPtr->motion = rPtr->margins.left;
return 1;
&& (rPtr->margins.left - x <= 0) && y >= 4) {
rPtr->motion = rPtr->margins.left;
return 1;
}
if (rPtr->margins.right - x >= -1 && y <= 11
&& rPtr->margins.right - x <= 5 && y >= 4) {
rPtr->motion = rPtr->margins.right;
return 2;
&& rPtr->margins.right - x <= 5 && y >= 4) {
rPtr->motion = rPtr->margins.right;
return 2;
}
#if 0
/* both first and body? */
if (rPtr->margins.first - x <= 4 && rPtr->margins.first - x >= -5
&& rPtr->margins.body - x <= 4 && rPtr->margins.body - x >= -5
&& y >= 15 && y <= 17) {
rPtr->motion = rPtr->margins.first;
return 6;
&& rPtr->margins.body - x <= 4 && rPtr->margins.body - x >= -5
&& y >= 15 && y <= 17) {
rPtr->motion = rPtr->margins.first;
return 6;
}
#endif
if (rPtr->margins.first - x <= 4 && y <= 15
&& rPtr->margins.first - x >= -5 && y >= 10) {
rPtr->motion = rPtr->margins.first;
return 3;
&& rPtr->margins.first - x >= -5 && y >= 10) {
rPtr->motion = rPtr->margins.first;
return 3;
}
if (rPtr->margins.body - x <= 4 && y <= 21 &&
rPtr->margins.body - x >= -5 && y >= 17) {
rPtr->motion = rPtr->margins.body;
return 4;
rPtr->margins.body - x >= -5 && y >= 17) {
rPtr->motion = rPtr->margins.body;
return 4;
}
/* do tabs (5) */
@@ -312,6 +323,16 @@ static int whichMarker(Ruler * rPtr, int x, int y)
return 0;
}
static void rulerDidResize(W_ViewDelegate * self, WMView * view)
{
Ruler *rPtr = (Ruler *) view->self;
createDrawBuffer(rPtr);
rPtr->flags.redraw = True;
paintRuler(rPtr);
}
static void handleEvents(XEvent * event, void *data)
{
@@ -320,80 +341,73 @@ static void handleEvents(XEvent * event, void *data)
switch (event->type) {
case Expose:
paintRuler(rPtr);
break;
rulerDidResize(rPtr->view->delegate, rPtr->view);
break;
case MotionNotify:
if (rPtr->flags.buttonPressed
&& (event->xmotion.state & Button1Mask)) {
if (verifyMarkerMove(rPtr, event->xmotion.x)) {
GC gc = WMColorGC(WMDarkGrayColor(rPtr->view->screen));
if (rPtr->flags.buttonPressed
&& (event->xmotion.state & Button1Mask)) {
if (verifyMarkerMove(rPtr, event->xmotion.x)) {
GC gc = WMColorGC(WMDarkGrayColor(rPtr->view->screen));
if (rPtr->moveAction)
(rPtr->moveAction) (rPtr, rPtr->clientData);
paintRuler(rPtr);
XSetLineAttributes(rPtr->view->screen->display, gc, 1,
LineSolid, CapNotLast, JoinMiter);
XDrawLine(rPtr->pview->screen->display,
rPtr->pview->window,
gc, rPtr->motion + 1, 40,
rPtr->motion + 1, rPtr->pview->size.height - 5);
}
}
break;
if (rPtr->moveAction)
(rPtr->moveAction) (rPtr, rPtr->clientData);
rPtr->flags.redraw = True;
paintRuler(rPtr);
XSetLineAttributes(rPtr->view->screen->display, gc, 1,
LineSolid, CapNotLast, JoinMiter);
XDrawLine(rPtr->pview->screen->display,
rPtr->pview->window,
gc, rPtr->motion + 1, 40,
rPtr->motion + 1, rPtr->pview->size.height - 5);
}
}
break;
case ButtonPress:
if (event->xbutton.button != Button1)
return;
rPtr->flags.buttonPressed = True;
rPtr->flags.whichMarker =
whichMarker(rPtr, event->xmotion.x,
event->xmotion.y);
break;
if (event->xbutton.button != Button1)
return;
rPtr->flags.buttonPressed = True;
rPtr->flags.whichMarker =
whichMarker(rPtr, event->xmotion.x,
event->xmotion.y);
break;
case ButtonRelease:
if (event->xbutton.button != Button1)
return;
rPtr->flags.buttonPressed = False;
switch (rPtr->flags.whichMarker) {
case 1:{
int change = rPtr->margins.left - rPtr->motion;
if (event->xbutton.button != Button1)
return;
rPtr->flags.buttonPressed = False;
switch (rPtr->flags.whichMarker) {
case 1:{
int change = rPtr->margins.left - rPtr->motion;
rPtr->margins.first -= change;
rPtr->margins.body -= change;
rPtr->margins.left = rPtr->motion;
paintRuler(rPtr);
break;
}
case 2:
rPtr->margins.right = rPtr->motion;
break;
case 3:
rPtr->margins.first = rPtr->motion;
break;
case 4:
rPtr->margins.body = rPtr->motion;
break;
case 6:
rPtr->margins.first = rPtr->margins.body
= rPtr->motion;
break;
}
if (rPtr->releaseAction)
(rPtr->releaseAction) (rPtr, rPtr->clientData);
break;
rPtr->margins.first -= change;
rPtr->margins.body -= change;
rPtr->margins.left = rPtr->motion;
rPtr->flags.redraw = True;
paintRuler(rPtr);
break;
}
case 2:
rPtr->margins.right = rPtr->motion;
break;
case 3:
rPtr->margins.first = rPtr->motion;
break;
case 4:
rPtr->margins.body = rPtr->motion;
break;
case 6:
rPtr->margins.first = rPtr->margins.body
= rPtr->motion;
break;
}
if (rPtr->releaseAction)
(rPtr->releaseAction) (rPtr, rPtr->clientData);
break;
}
}
static void rulerDidResize(W_ViewDelegate * self, WMView * view)
{
Ruler *rPtr = (Ruler *) view->self;
createDrawBuffer(rPtr);
paintRuler(rPtr);
}
W_ViewDelegate _RulerViewDelegate =
{
@@ -406,7 +420,7 @@ W_ViewDelegate _RulerViewDelegate =
WMRuler *
WMCreateRuler(WMWidget * parent)
WMCreateRuler(WMWidget * parent)
{
Ruler *rPtr = wmalloc(sizeof(Ruler));
unsigned int w = WMWidgetWidth(parent);
@@ -416,10 +430,12 @@ WMRuler *
rPtr->widgetClass = WC_Ruler;
rPtr->view = W_CreateView(W_VIEW(parent));
if (!rPtr->view) {
free(rPtr);
return NULL;
free(rPtr);
return NULL;
}
rPtr->view->self = rPtr;
rPtr->drawBuffer = (Pixmap) NULL;
@@ -427,9 +443,9 @@ WMRuler *
W_ResizeView(rPtr->view, w, 40);
WMCreateEventHandler(rPtr->view, ExposureMask | StructureNotifyMask
| EnterWindowMask | LeaveWindowMask | FocusChangeMask
| ButtonReleaseMask | ButtonPressMask | KeyReleaseMask
| KeyPressMask | Button1MotionMask, handleEvents, rPtr);
| EnterWindowMask | LeaveWindowMask | FocusChangeMask
| ButtonReleaseMask | ButtonPressMask | KeyReleaseMask
| KeyPressMask | Button1MotionMask, handleEvents, rPtr);
rPtr->view->delegate = &_RulerViewDelegate;
@@ -442,9 +458,11 @@ WMRuler *
rPtr->margins.body = 22;
rPtr->margins.first = 42;
rPtr->margins.right = (w < 502 ? w : 502);
rPtr->margins.tabs = NULL;
rPtr->flags.whichMarker = 0; /* none */
rPtr->flags.whichMarker = 0; /* none */
rPtr->flags.buttonPressed = False;
rPtr->flags.redraw = True;
rPtr->moveAction = NULL;
rPtr->releaseAction = NULL;
@@ -458,12 +476,13 @@ WMRuler *
void WMSetRulerMargins(WMRuler * rPtr, WMRulerMargins margins)
{
if (!rPtr)
return;
return;
rPtr->margins.left = margins.left + rPtr->offset;
rPtr->margins.right = margins.right + rPtr->offset;
rPtr->margins.first = margins.first + rPtr->offset;
rPtr->margins.body = margins.body + rPtr->offset;
rPtr->margins.tabs = margins.tabs; /*for loop */
rPtr->margins.tabs = margins.tabs; /*for loop */
rPtr->flags.redraw = True;
paintRuler(rPtr);
}
@@ -474,8 +493,11 @@ WMGetRulerMargins(WMRuler * rPtr)
{
WMRulerMargins margins;
if (!rPtr)
return margins;
if (!rPtr) {
margins.first = margins.body = margins.left = 0;
margins.right = 100;
return margins;
}
margins.left = rPtr->margins.left - rPtr->offset;
margins.right = rPtr->margins.right - rPtr->offset;
@@ -491,7 +513,7 @@ WMGetRulerMargins(WMRuler * rPtr)
void WMSetRulerOffset(WMRuler * rPtr, int pixels)
{
if (!rPtr || pixels < 0 || pixels + MIN_DOC_WIDTH >= rPtr->view->size.width)
return;
return;
rPtr->offset = pixels;
/*rulerDidResize(rPtr, rPtr->view); */
}
@@ -500,7 +522,7 @@ void WMSetRulerOffset(WMRuler * rPtr, int pixels)
int WMGetRulerOffset(WMRuler * rPtr)
{
if (!rPtr)
return;
return;
return rPtr->offset;
}
@@ -508,7 +530,7 @@ int WMGetRulerOffset(WMRuler * rPtr)
void WMSetRulerReleaseAction(WMRuler * rPtr, WMAction * action, void *clientData)
{
if (!rPtr)
return;
return;
rPtr->releaseAction = action;
rPtr->clientData = clientData;
@@ -518,7 +540,7 @@ void WMSetRulerReleaseAction(WMRuler * rPtr, WMAction * action, void *clientData
void WMSetRulerMoveAction(WMRuler * rPtr, WMAction * action, void *clientData)
{
if (!rPtr)
return;
return;
rPtr->moveAction = action;
rPtr->clientData = clientData;
@@ -529,7 +551,7 @@ void WMSetRulerMoveAction(WMRuler * rPtr, WMAction * action, void *clientData)
int WMGetReleasedRulerMargin(WMRuler * rPtr)
{
if (!rPtr)
return 0;
return 0;
return rPtr->flags.whichMarker;
}
@@ -538,6 +560,6 @@ int WMGetReleasedRulerMargin(WMRuler * rPtr)
int WMGetGrabbedRulerMargin(WMRuler * rPtr)
{
if (!rPtr)
return 0;
return 0;
return rPtr->flags.whichMarker;
}

File diff suppressed because it is too large Load Diff