mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-26 16:32:30 +01:00
Change to the linux kernel coding style
for arq in `git ls-files *.c`; do
echo $arq;
indent -linux -l115 $arq;
done
The different line break at 115 columns is because
I use a widescreen monitor :-)
This commit is contained in:
699
src/text.c
699
src/text.c
@@ -42,7 +42,6 @@
|
||||
(((KeySym)(keysym) >= 0x11000000) && ((KeySym)(keysym) <= 0x1100FFFF))
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
# define ENTER(X) fprintf(stderr,"Entering: %s()\n", X);
|
||||
# define LEAVE(X) fprintf(stderr,"Leaving: %s()\n", X);
|
||||
@@ -58,11 +57,11 @@ extern Cursor wCursor[WCUR_LAST];
|
||||
/********************************************************************
|
||||
* The event handler for the text-field: *
|
||||
********************************************************************/
|
||||
static void textEventHandler( WObjDescriptor *desc, XEvent *event );
|
||||
static void textEventHandler(WObjDescriptor * desc, XEvent * event);
|
||||
|
||||
static void handleExpose( WObjDescriptor *desc, XEvent *event );
|
||||
static void handleExpose(WObjDescriptor * desc, XEvent * event);
|
||||
|
||||
static void textInsert( WTextInput *wtext, char *txt );
|
||||
static void textInsert(WTextInput * wtext, char *txt);
|
||||
#if 0
|
||||
static void blink(void *data);
|
||||
#endif
|
||||
@@ -81,113 +80,101 @@ static void blink(void *data);
|
||||
* Global: modifier - the bitfield that keeps track of the modifier *
|
||||
* keys that are down *
|
||||
********************************************************************/
|
||||
static int
|
||||
handleKeyPress( WTextInput *wtext, XKeyEvent *event )
|
||||
static int handleKeyPress(WTextInput * wtext, XKeyEvent * event)
|
||||
{
|
||||
KeySym ksym;
|
||||
char buffer[32];
|
||||
int count;
|
||||
KeySym ksym;
|
||||
char buffer[32];
|
||||
int count;
|
||||
|
||||
count = XLookupString(event, buffer, 32, &ksym, NULL);
|
||||
count = XLookupString(event, buffer, 32, &ksym, NULL);
|
||||
|
||||
/* Ignore these keys: */
|
||||
if( IsFunctionKey(ksym) || IsKeypadKey(ksym) ||
|
||||
IsMiscFunctionKey(ksym) || IsPFKey(ksym) ||
|
||||
IsPrivateKeypadKey(ksym) )
|
||||
/* If we don't handle it, make sure it isn't a key that
|
||||
* the window manager needs to see */
|
||||
return False;
|
||||
/* Ignore these keys: */
|
||||
if (IsFunctionKey(ksym) || IsKeypadKey(ksym) ||
|
||||
IsMiscFunctionKey(ksym) || IsPFKey(ksym) || IsPrivateKeypadKey(ksym))
|
||||
/* If we don't handle it, make sure it isn't a key that
|
||||
* the window manager needs to see */
|
||||
return False;
|
||||
|
||||
/* Take care of the cursor keys.. ignore up and down
|
||||
* cursor keys */
|
||||
else if( IsCursorKey(ksym) )
|
||||
{
|
||||
int length = wtext->text.length;
|
||||
switch(ksym)
|
||||
{
|
||||
case XK_Home:
|
||||
case XK_Begin:
|
||||
wtext->text.endPos = 0;
|
||||
break;
|
||||
case XK_Left:
|
||||
wtext->text.endPos--;
|
||||
break;
|
||||
case XK_Right:
|
||||
wtext->text.endPos++;
|
||||
break;
|
||||
case XK_End:
|
||||
wtext->text.endPos = length;
|
||||
break;
|
||||
default:
|
||||
return False;
|
||||
}
|
||||
/* make sure that the startPos and endPos have values
|
||||
* that make sense (ie the are in [0..length] ) */
|
||||
if( wtext->text.endPos < 0 )
|
||||
wtext->text.endPos = 0;
|
||||
if( wtext->text.endPos > length )
|
||||
wtext->text.endPos = length;
|
||||
wtext->text.startPos = wtext->text.endPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(ksym)
|
||||
{
|
||||
/* Ignore these keys: */
|
||||
case XK_Escape:
|
||||
wtext->canceled = True;
|
||||
case XK_Return:
|
||||
wtext->done = True;
|
||||
break;
|
||||
case XK_Tab:
|
||||
case XK_Num_Lock:
|
||||
break;
|
||||
/* Take care of the cursor keys.. ignore up and down
|
||||
* cursor keys */
|
||||
else if (IsCursorKey(ksym)) {
|
||||
int length = wtext->text.length;
|
||||
switch (ksym) {
|
||||
case XK_Home:
|
||||
case XK_Begin:
|
||||
wtext->text.endPos = 0;
|
||||
break;
|
||||
case XK_Left:
|
||||
wtext->text.endPos--;
|
||||
break;
|
||||
case XK_Right:
|
||||
wtext->text.endPos++;
|
||||
break;
|
||||
case XK_End:
|
||||
wtext->text.endPos = length;
|
||||
break;
|
||||
default:
|
||||
return False;
|
||||
}
|
||||
/* make sure that the startPos and endPos have values
|
||||
* that make sense (ie the are in [0..length] ) */
|
||||
if (wtext->text.endPos < 0)
|
||||
wtext->text.endPos = 0;
|
||||
if (wtext->text.endPos > length)
|
||||
wtext->text.endPos = length;
|
||||
wtext->text.startPos = wtext->text.endPos;
|
||||
} else {
|
||||
switch (ksym) {
|
||||
/* Ignore these keys: */
|
||||
case XK_Escape:
|
||||
wtext->canceled = True;
|
||||
case XK_Return:
|
||||
wtext->done = True;
|
||||
break;
|
||||
case XK_Tab:
|
||||
case XK_Num_Lock:
|
||||
break;
|
||||
|
||||
case XK_Delete:
|
||||
/* delete after cursor */
|
||||
if( (wtext->text.endPos == wtext->text.startPos) &&
|
||||
(wtext->text.endPos < wtext->text.length) )
|
||||
wtext->text.endPos++;
|
||||
textInsert( wtext, "" );
|
||||
break;
|
||||
case XK_BackSpace:
|
||||
/* delete before cursor */
|
||||
if( (wtext->text.endPos == wtext->text.startPos) &&
|
||||
(wtext->text.startPos > 0) )
|
||||
wtext->text.startPos--;
|
||||
textInsert( wtext, "" );
|
||||
break;
|
||||
default:
|
||||
if (count==1 && !iscntrl(buffer[0])) {
|
||||
buffer[count] = 0;
|
||||
textInsert( wtext, buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
return True;
|
||||
case XK_Delete:
|
||||
/* delete after cursor */
|
||||
if ((wtext->text.endPos == wtext->text.startPos) &&
|
||||
(wtext->text.endPos < wtext->text.length))
|
||||
wtext->text.endPos++;
|
||||
textInsert(wtext, "");
|
||||
break;
|
||||
case XK_BackSpace:
|
||||
/* delete before cursor */
|
||||
if ((wtext->text.endPos == wtext->text.startPos) && (wtext->text.startPos > 0))
|
||||
wtext->text.startPos--;
|
||||
textInsert(wtext, "");
|
||||
break;
|
||||
default:
|
||||
if (count == 1 && !iscntrl(buffer[0])) {
|
||||
buffer[count] = 0;
|
||||
textInsert(wtext, buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
return True;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************************************************************
|
||||
* textXYtoPos *
|
||||
* given X coord, return position in array *
|
||||
********************************************************************/
|
||||
static int
|
||||
textXtoPos( WTextInput *wtext, int x )
|
||||
static int textXtoPos(WTextInput * wtext, int x)
|
||||
{
|
||||
int pos;
|
||||
x -= wtext->xOffset;
|
||||
int pos;
|
||||
x -= wtext->xOffset;
|
||||
|
||||
for( pos=0; wtext->text.txt[pos] != '\0'; pos++ )
|
||||
{
|
||||
if( x < 0 )
|
||||
break;
|
||||
else
|
||||
x -= WMWidthOfString( wtext->font, &(wtext->text.txt[pos]), 1 );
|
||||
}
|
||||
for (pos = 0; wtext->text.txt[pos] != '\0'; pos++) {
|
||||
if (x < 0)
|
||||
break;
|
||||
else
|
||||
x -= WMWidthOfString(wtext->font, &(wtext->text.txt[pos]), 1);
|
||||
}
|
||||
|
||||
return pos;
|
||||
return pos;
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
@@ -198,80 +185,73 @@ textXtoPos( WTextInput *wtext, int x )
|
||||
* Return: *
|
||||
* Global: dpy - the display *
|
||||
********************************************************************/
|
||||
WTextInput *
|
||||
wTextCreate( WCoreWindow *core, int x, int y, int width, int height )
|
||||
WTextInput *wTextCreate(WCoreWindow * core, int x, int y, int width, int height)
|
||||
{
|
||||
WTextInput *wtext;
|
||||
WTextInput *wtext;
|
||||
|
||||
ENTER("wTextCreate");
|
||||
ENTER("wTextCreate");
|
||||
|
||||
wtext = wmalloc(sizeof(WTextInput));
|
||||
wtext->core = wCoreCreate( core, x, y, width, height );
|
||||
wtext->core->descriptor.handle_anything = &textEventHandler;
|
||||
wtext->core->descriptor.handle_expose = &handleExpose;
|
||||
wtext->core->descriptor.parent_type = WCLASS_TEXT_INPUT;
|
||||
wtext->core->descriptor.parent = wtext;
|
||||
wtext = wmalloc(sizeof(WTextInput));
|
||||
wtext->core = wCoreCreate(core, x, y, width, height);
|
||||
wtext->core->descriptor.handle_anything = &textEventHandler;
|
||||
wtext->core->descriptor.handle_expose = &handleExpose;
|
||||
wtext->core->descriptor.parent_type = WCLASS_TEXT_INPUT;
|
||||
wtext->core->descriptor.parent = wtext;
|
||||
|
||||
wtext->font = core->screen_ptr->menu_entry_font;
|
||||
wtext->font = core->screen_ptr->menu_entry_font;
|
||||
|
||||
XDefineCursor( dpy, wtext->core->window, wCursor[WCUR_TEXT] );
|
||||
XDefineCursor(dpy, wtext->core->window, wCursor[WCUR_TEXT]);
|
||||
|
||||
/* setup the text: */
|
||||
wtext->text.txt = (char *)wmalloc(sizeof(char));
|
||||
wtext->text.txt[0] = '\0';
|
||||
wtext->text.length = 0;
|
||||
wtext->text.startPos = 0;
|
||||
wtext->text.endPos = 0;
|
||||
/* setup the text: */
|
||||
wtext->text.txt = (char *)wmalloc(sizeof(char));
|
||||
wtext->text.txt[0] = '\0';
|
||||
wtext->text.length = 0;
|
||||
wtext->text.startPos = 0;
|
||||
wtext->text.endPos = 0;
|
||||
|
||||
{
|
||||
XGCValues gcv;
|
||||
{
|
||||
XGCValues gcv;
|
||||
|
||||
gcv.foreground = core->screen_ptr->black_pixel;
|
||||
gcv.background = core->screen_ptr->white_pixel;
|
||||
gcv.line_width = 1;
|
||||
gcv.function = GXcopy;
|
||||
gcv.foreground = core->screen_ptr->black_pixel;
|
||||
gcv.background = core->screen_ptr->white_pixel;
|
||||
gcv.line_width = 1;
|
||||
gcv.function = GXcopy;
|
||||
|
||||
wtext->gc = XCreateGC( dpy, wtext->core->window,
|
||||
(GCForeground|GCBackground|
|
||||
GCFunction|GCLineWidth),
|
||||
&gcv );
|
||||
wtext->gc = XCreateGC(dpy, wtext->core->window,
|
||||
(GCForeground | GCBackground | GCFunction | GCLineWidth), &gcv);
|
||||
|
||||
/* set up the regular context */
|
||||
gcv.foreground = core->screen_ptr->black_pixel;
|
||||
gcv.background = core->screen_ptr->white_pixel;
|
||||
gcv.line_width = 1;
|
||||
gcv.function = GXcopy;
|
||||
/* set up the regular context */
|
||||
gcv.foreground = core->screen_ptr->black_pixel;
|
||||
gcv.background = core->screen_ptr->white_pixel;
|
||||
gcv.line_width = 1;
|
||||
gcv.function = GXcopy;
|
||||
|
||||
wtext->regGC = XCreateGC( dpy, wtext->core->window,
|
||||
(GCForeground|GCBackground|
|
||||
GCFunction|GCLineWidth),
|
||||
&gcv );
|
||||
wtext->regGC = XCreateGC(dpy, wtext->core->window,
|
||||
(GCForeground | GCBackground | GCFunction | GCLineWidth), &gcv);
|
||||
|
||||
/* set up the inverted context */
|
||||
gcv.function = GXcopyInverted;
|
||||
/* set up the inverted context */
|
||||
gcv.function = GXcopyInverted;
|
||||
|
||||
wtext->invGC = XCreateGC( dpy, wtext->core->window,
|
||||
(GCForeground|GCBackground|
|
||||
GCFunction|GCLineWidth),
|
||||
&gcv );
|
||||
wtext->invGC = XCreateGC(dpy, wtext->core->window,
|
||||
(GCForeground | GCBackground | GCFunction | GCLineWidth), &gcv);
|
||||
|
||||
/* and set the background! */
|
||||
XSetWindowBackground( dpy, wtext->core->window, gcv.background );
|
||||
}
|
||||
/* and set the background! */
|
||||
XSetWindowBackground(dpy, wtext->core->window, gcv.background);
|
||||
}
|
||||
|
||||
/* Figure out the y-offset... */
|
||||
wtext->yOffset = (height - WMFontHeight(wtext->font))/2;
|
||||
wtext->xOffset = wtext->yOffset;
|
||||
/* Figure out the y-offset... */
|
||||
wtext->yOffset = (height - WMFontHeight(wtext->font)) / 2;
|
||||
wtext->xOffset = wtext->yOffset;
|
||||
|
||||
wtext->canceled = False;
|
||||
wtext->done = False; /* becomes True when the user *
|
||||
* hits "Return" key */
|
||||
wtext->canceled = False;
|
||||
wtext->done = False; /* becomes True when the user *
|
||||
* hits "Return" key */
|
||||
|
||||
XMapRaised(dpy, wtext->core->window);
|
||||
XMapRaised(dpy, wtext->core->window);
|
||||
|
||||
LEAVE("wTextCreate");
|
||||
LEAVE("wTextCreate");
|
||||
|
||||
return wtext;
|
||||
return wtext;
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
@@ -281,27 +261,24 @@ wTextCreate( WCoreWindow *core, int x, int y, int width, int height )
|
||||
* Return: *
|
||||
* Global: dpy - the display *
|
||||
********************************************************************/
|
||||
void
|
||||
wTextDestroy( WTextInput *wtext )
|
||||
void wTextDestroy(WTextInput * wtext)
|
||||
{
|
||||
ENTER("wTextDestroy")
|
||||
|
||||
ENTER("wTextDestroy")
|
||||
#if 0
|
||||
if (wtext->magic)
|
||||
wDeleteTimerHandler(wtext->magic);
|
||||
wtext->magic = NULL;
|
||||
if (wtext->magic)
|
||||
wDeleteTimerHandler(wtext->magic);
|
||||
wtext->magic = NULL;
|
||||
#endif
|
||||
XFreeGC( dpy, wtext->gc );
|
||||
XFreeGC( dpy, wtext->regGC );
|
||||
XFreeGC( dpy, wtext->invGC );
|
||||
wfree( wtext->text.txt );
|
||||
wCoreDestroy( wtext->core );
|
||||
wfree( wtext );
|
||||
XFreeGC(dpy, wtext->gc);
|
||||
XFreeGC(dpy, wtext->regGC);
|
||||
XFreeGC(dpy, wtext->invGC);
|
||||
wfree(wtext->text.txt);
|
||||
wCoreDestroy(wtext->core);
|
||||
wfree(wtext);
|
||||
|
||||
LEAVE("wTextDestroy");
|
||||
LEAVE("wTextDestroy");
|
||||
}
|
||||
|
||||
|
||||
/* The text-field consists of a frame drawn around the outside,
|
||||
* and a textbox inside. The space between the frame and the
|
||||
* text-box is the xOffset,yOffset. When the text needs refreshing,
|
||||
@@ -310,7 +287,6 @@ wTextDestroy( WTextInput *wtext )
|
||||
* need to redraw the frame, wTextPaint will redraw the frame, and
|
||||
* then call wTextRefresh to redraw the text-box */
|
||||
|
||||
|
||||
/********************************************************************
|
||||
* textRefresh *
|
||||
* Redraw the text field. Call this after messing with the text *
|
||||
@@ -322,67 +298,60 @@ wTextDestroy( WTextInput *wtext )
|
||||
* Return: none *
|
||||
* Global: dpy - the display *
|
||||
********************************************************************/
|
||||
static void
|
||||
textRefresh(WTextInput *wtext)
|
||||
static void textRefresh(WTextInput * wtext)
|
||||
{
|
||||
WScreen *scr = wtext->core->screen_ptr;
|
||||
char *ptr = wtext->text.txt;
|
||||
int x1,x2,y1,y2;
|
||||
WScreen *scr = wtext->core->screen_ptr;
|
||||
char *ptr = wtext->text.txt;
|
||||
int x1, x2, y1, y2;
|
||||
|
||||
/* x1,y1 is the upper left corner of the text box */
|
||||
x1 = wtext->xOffset;
|
||||
y1 = wtext->yOffset;
|
||||
/* x2,y2 is the lower right corner of the text box */
|
||||
x2 = wtext->core->width - wtext->xOffset;
|
||||
y2 = wtext->core->height - wtext->yOffset;
|
||||
/* x1,y1 is the upper left corner of the text box */
|
||||
x1 = wtext->xOffset;
|
||||
y1 = wtext->yOffset;
|
||||
/* x2,y2 is the lower right corner of the text box */
|
||||
x2 = wtext->core->width - wtext->xOffset;
|
||||
y2 = wtext->core->height - wtext->yOffset;
|
||||
|
||||
/* Fill in the text field. Use the invGC to draw the rectangle,
|
||||
* becuase then it will be the background color */
|
||||
XFillRectangle(dpy, wtext->core->window, wtext->invGC,
|
||||
x1, y1, x2-x1, y2-y1);
|
||||
/* Fill in the text field. Use the invGC to draw the rectangle,
|
||||
* becuase then it will be the background color */
|
||||
XFillRectangle(dpy, wtext->core->window, wtext->invGC, x1, y1, x2 - x1, y2 - y1);
|
||||
|
||||
/* Draw the text normally */
|
||||
WMDrawImageString(scr->wmscreen, wtext->core->window,
|
||||
scr->black, scr->white, wtext->font, x1, y1, ptr,
|
||||
wtext->text.length);
|
||||
/* Draw the text normally */
|
||||
WMDrawImageString(scr->wmscreen, wtext->core->window,
|
||||
scr->black, scr->white, wtext->font, x1, y1, ptr, wtext->text.length);
|
||||
|
||||
/* Draw the selected text */
|
||||
if (wtext->text.startPos != wtext->text.endPos) {
|
||||
int sp,ep;
|
||||
/* we need sp < ep */
|
||||
if (wtext->text.startPos > wtext->text.endPos) {
|
||||
sp = wtext->text.endPos;
|
||||
ep = wtext->text.startPos;
|
||||
} else {
|
||||
sp = wtext->text.startPos;
|
||||
ep = wtext->text.endPos;
|
||||
}
|
||||
/* Draw the selected text */
|
||||
if (wtext->text.startPos != wtext->text.endPos) {
|
||||
int sp, ep;
|
||||
/* we need sp < ep */
|
||||
if (wtext->text.startPos > wtext->text.endPos) {
|
||||
sp = wtext->text.endPos;
|
||||
ep = wtext->text.startPos;
|
||||
} else {
|
||||
sp = wtext->text.startPos;
|
||||
ep = wtext->text.endPos;
|
||||
}
|
||||
|
||||
/* x1,y1 is now the upper-left of the selected area */
|
||||
x1 += WMWidthOfString(wtext->font, ptr, sp);
|
||||
/* and x2,y2 is the lower-right of the selected area */
|
||||
ptr += sp * sizeof(char);
|
||||
x2 = x1 + WMWidthOfString(wtext->font, ptr, (ep - sp));
|
||||
/* Fill in the area where the selected text will go: *
|
||||
* use the regGC to draw the rectangle, becuase then it *
|
||||
* will be the color of the non-selected text */
|
||||
XFillRectangle(dpy, wtext->core->window, wtext->regGC,
|
||||
x1, y1, x2-x1, y2-y1);
|
||||
/* x1,y1 is now the upper-left of the selected area */
|
||||
x1 += WMWidthOfString(wtext->font, ptr, sp);
|
||||
/* and x2,y2 is the lower-right of the selected area */
|
||||
ptr += sp * sizeof(char);
|
||||
x2 = x1 + WMWidthOfString(wtext->font, ptr, (ep - sp));
|
||||
/* Fill in the area where the selected text will go: *
|
||||
* use the regGC to draw the rectangle, becuase then it *
|
||||
* will be the color of the non-selected text */
|
||||
XFillRectangle(dpy, wtext->core->window, wtext->regGC, x1, y1, x2 - x1, y2 - y1);
|
||||
|
||||
/* Draw the selected text. Inverse bg and fg colors for selection */
|
||||
WMDrawImageString(scr->wmscreen, wtext->core->window,
|
||||
scr->white, scr->black, wtext->font, x1, y1, ptr,
|
||||
(ep - sp));
|
||||
}
|
||||
/* Draw the selected text. Inverse bg and fg colors for selection */
|
||||
WMDrawImageString(scr->wmscreen, wtext->core->window,
|
||||
scr->white, scr->black, wtext->font, x1, y1, ptr, (ep - sp));
|
||||
}
|
||||
|
||||
/* And draw a quick little line for the cursor position */
|
||||
x1 = WMWidthOfString(wtext->font, wtext->text.txt, wtext->text.endPos)
|
||||
+ wtext->xOffset;
|
||||
XDrawLine(dpy, wtext->core->window, wtext->regGC, x1, 2, x1,
|
||||
wtext->core->height - 3);
|
||||
/* And draw a quick little line for the cursor position */
|
||||
x1 = WMWidthOfString(wtext->font, wtext->text.txt, wtext->text.endPos)
|
||||
+ wtext->xOffset;
|
||||
XDrawLine(dpy, wtext->core->window, wtext->regGC, x1, 2, x1, wtext->core->height - 3);
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************
|
||||
* wTextPaint *
|
||||
* *
|
||||
@@ -390,22 +359,19 @@ textRefresh(WTextInput *wtext)
|
||||
* Return: *
|
||||
* Global: dpy - the display *
|
||||
********************************************************************/
|
||||
void
|
||||
wTextPaint( WTextInput *wtext )
|
||||
void wTextPaint(WTextInput * wtext)
|
||||
{
|
||||
ENTER("wTextPaint");
|
||||
ENTER("wTextPaint");
|
||||
|
||||
/* refresh */
|
||||
textRefresh( wtext );
|
||||
/* refresh */
|
||||
textRefresh(wtext);
|
||||
|
||||
/* Draw box */
|
||||
XDrawRectangle(dpy, wtext->core->window, wtext->gc, 0, 0,
|
||||
wtext->core->width-1, wtext->core->height-1);
|
||||
/* Draw box */
|
||||
XDrawRectangle(dpy, wtext->core->window, wtext->gc, 0, 0, wtext->core->width - 1, wtext->core->height - 1);
|
||||
|
||||
LEAVE("wTextPaint");
|
||||
LEAVE("wTextPaint");
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************
|
||||
* wTextGetText *
|
||||
* return the string in the text field wText. DO NOT FREE THE *
|
||||
@@ -415,13 +381,12 @@ wTextPaint( WTextInput *wtext )
|
||||
* Return: the text in the text field (NULL terminated) *
|
||||
* Global: *
|
||||
********************************************************************/
|
||||
char *
|
||||
wTextGetText( WTextInput *wtext )
|
||||
char *wTextGetText(WTextInput * wtext)
|
||||
{
|
||||
if (!wtext->canceled)
|
||||
return wtext->text.txt;
|
||||
else
|
||||
return NULL;
|
||||
if (!wtext->canceled)
|
||||
return wtext->text.txt;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
@@ -436,21 +401,20 @@ wTextGetText( WTextInput *wtext )
|
||||
* Return: none *
|
||||
* Global: *
|
||||
********************************************************************/
|
||||
void
|
||||
wTextPutText( WTextInput *wtext, char *txt )
|
||||
void wTextPutText(WTextInput * wtext, char *txt)
|
||||
{
|
||||
int length = strlen(txt);
|
||||
int length = strlen(txt);
|
||||
|
||||
/* no memory leaks! free the old txt */
|
||||
if( wtext->text.txt != NULL )
|
||||
wfree( wtext->text.txt );
|
||||
/* no memory leaks! free the old txt */
|
||||
if (wtext->text.txt != NULL)
|
||||
wfree(wtext->text.txt);
|
||||
|
||||
wtext->text.txt = (char *)wmalloc((length+1)*sizeof(char));
|
||||
strcpy(wtext->text.txt, txt );
|
||||
wtext->text.length = length;
|
||||
/* By default No text is selected, and the cursor is at the end */
|
||||
wtext->text.startPos = length;
|
||||
wtext->text.endPos = length;
|
||||
wtext->text.txt = (char *)wmalloc((length + 1) * sizeof(char));
|
||||
strcpy(wtext->text.txt, txt);
|
||||
wtext->text.length = length;
|
||||
/* By default No text is selected, and the cursor is at the end */
|
||||
wtext->text.startPos = length;
|
||||
wtext->text.endPos = length;
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
@@ -464,52 +428,48 @@ wTextPutText( WTextInput *wtext, char *txt )
|
||||
* Return: none *
|
||||
* Global: *
|
||||
********************************************************************/
|
||||
static void
|
||||
textInsert( WTextInput *wtext, char *txt )
|
||||
static void textInsert(WTextInput * wtext, char *txt)
|
||||
{
|
||||
char *newTxt;
|
||||
int newLen, txtLen, i,j;
|
||||
int sp,ep;
|
||||
char *newTxt;
|
||||
int newLen, txtLen, i, j;
|
||||
int sp, ep;
|
||||
|
||||
/* we need sp < ep */
|
||||
if( wtext->text.startPos > wtext->text.endPos )
|
||||
{
|
||||
sp = wtext->text.endPos;
|
||||
ep = wtext->text.startPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
sp = wtext->text.startPos;
|
||||
ep = wtext->text.endPos;
|
||||
}
|
||||
/* we need sp < ep */
|
||||
if (wtext->text.startPos > wtext->text.endPos) {
|
||||
sp = wtext->text.endPos;
|
||||
ep = wtext->text.startPos;
|
||||
} else {
|
||||
sp = wtext->text.startPos;
|
||||
ep = wtext->text.endPos;
|
||||
}
|
||||
|
||||
txtLen = strlen(txt);
|
||||
newLen = wtext->text.length + txtLen - (ep - sp) + 1;
|
||||
txtLen = strlen(txt);
|
||||
newLen = wtext->text.length + txtLen - (ep - sp) + 1;
|
||||
|
||||
newTxt = (char *)malloc(newLen*sizeof(char));
|
||||
newTxt = (char *)malloc(newLen * sizeof(char));
|
||||
|
||||
/* copy the old text up to sp */
|
||||
for( i=0; i<sp; i++ )
|
||||
newTxt[i] = wtext->text.txt[i];
|
||||
/* copy the old text up to sp */
|
||||
for (i = 0; i < sp; i++)
|
||||
newTxt[i] = wtext->text.txt[i];
|
||||
|
||||
/* insert new text */
|
||||
for( j=0; j<txtLen; j++,i++ )
|
||||
newTxt[i] = txt[j];
|
||||
/* insert new text */
|
||||
for (j = 0; j < txtLen; j++, i++)
|
||||
newTxt[i] = txt[j];
|
||||
|
||||
/* copy old text after ep */
|
||||
for( j=ep; j<wtext->text.length; j++,i++ )
|
||||
newTxt[i] = wtext->text.txt[j];
|
||||
/* copy old text after ep */
|
||||
for (j = ep; j < wtext->text.length; j++, i++)
|
||||
newTxt[i] = wtext->text.txt[j];
|
||||
|
||||
newTxt[i] = '\0';
|
||||
newTxt[i] = '\0';
|
||||
|
||||
/* By default No text is selected, and the cursor is at the end
|
||||
* of inserted text */
|
||||
wtext->text.startPos = sp+txtLen;
|
||||
wtext->text.endPos = sp+txtLen;
|
||||
/* By default No text is selected, and the cursor is at the end
|
||||
* of inserted text */
|
||||
wtext->text.startPos = sp + txtLen;
|
||||
wtext->text.endPos = sp + txtLen;
|
||||
|
||||
wfree(wtext->text.txt);
|
||||
wtext->text.txt = newTxt;
|
||||
wtext->text.length = newLen-1;
|
||||
wfree(wtext->text.txt);
|
||||
wtext->text.txt = newTxt;
|
||||
wtext->text.length = newLen - 1;
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
@@ -526,38 +486,36 @@ textInsert( WTextInput *wtext, char *txt )
|
||||
* Return: none *
|
||||
* Global: *
|
||||
********************************************************************/
|
||||
void
|
||||
wTextSelect( WTextInput *wtext, int start, int end )
|
||||
void wTextSelect(WTextInput * wtext, int start, int end)
|
||||
{
|
||||
if( end == -1 )
|
||||
wtext->text.endPos = wtext->text.length;
|
||||
else
|
||||
wtext->text.endPos = end;
|
||||
wtext->text.startPos = start;
|
||||
if (end == -1)
|
||||
wtext->text.endPos = wtext->text.length;
|
||||
else
|
||||
wtext->text.endPos = end;
|
||||
wtext->text.startPos = start;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void
|
||||
blink(void *data)
|
||||
static void blink(void *data)
|
||||
{
|
||||
int x;
|
||||
WTextInput *wtext = (WTextInput*)data;
|
||||
GC gc;
|
||||
int x;
|
||||
WTextInput *wtext = (WTextInput *) data;
|
||||
GC gc;
|
||||
|
||||
/* And draw a quick little line for the cursor position */
|
||||
if (wtext->blink_on) {
|
||||
gc = wtext->regGC;
|
||||
wtext->blink_on = 0;
|
||||
} else {
|
||||
gc = wtext->invGC;
|
||||
wtext->blink_on = 1;
|
||||
}
|
||||
x = WMWidthOfString( wtext->font, wtext->text.txt, wtext->text.endPos )
|
||||
+ wtext->xOffset;
|
||||
XDrawLine( dpy, wtext->core->window, gc, x, 2, x, wtext->core->height-3);
|
||||
/* And draw a quick little line for the cursor position */
|
||||
if (wtext->blink_on) {
|
||||
gc = wtext->regGC;
|
||||
wtext->blink_on = 0;
|
||||
} else {
|
||||
gc = wtext->invGC;
|
||||
wtext->blink_on = 1;
|
||||
}
|
||||
x = WMWidthOfString(wtext->font, wtext->text.txt, wtext->text.endPos)
|
||||
+ wtext->xOffset;
|
||||
XDrawLine(dpy, wtext->core->window, gc, x, 2, x, wtext->core->height - 3);
|
||||
|
||||
if (wtext->blinking)
|
||||
wtext->magic = wAddTimerHandler(CURSOR_BLINK_RATE, blink, data);
|
||||
if (wtext->blinking)
|
||||
wtext->magic = wAddTimerHandler(CURSOR_BLINK_RATE, blink, data);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -569,87 +527,80 @@ blink(void *data)
|
||||
* Return: none *
|
||||
* Global: *
|
||||
********************************************************************/
|
||||
static void
|
||||
textEventHandler( WObjDescriptor *desc, XEvent *event )
|
||||
static void textEventHandler(WObjDescriptor * desc, XEvent * event)
|
||||
{
|
||||
WTextInput *wtext = desc->parent;
|
||||
int handled = False; /* has the event been handled */
|
||||
WTextInput *wtext = desc->parent;
|
||||
int handled = False; /* has the event been handled */
|
||||
|
||||
switch( event->type )
|
||||
{
|
||||
case MotionNotify:
|
||||
/* If the button isn't down, we don't care about the
|
||||
* event, but otherwise we want to adjust the selected
|
||||
* text so we can wTextRefresh() */
|
||||
if( event->xmotion.state & (Button1Mask|Button3Mask|Button2Mask) )
|
||||
{
|
||||
PDEBUG("MotionNotify");
|
||||
handled = True;
|
||||
wtext->text.endPos = textXtoPos( wtext, event->xmotion.x );
|
||||
}
|
||||
break;
|
||||
switch (event->type) {
|
||||
case MotionNotify:
|
||||
/* If the button isn't down, we don't care about the
|
||||
* event, but otherwise we want to adjust the selected
|
||||
* text so we can wTextRefresh() */
|
||||
if (event->xmotion.state & (Button1Mask | Button3Mask | Button2Mask)) {
|
||||
PDEBUG("MotionNotify");
|
||||
handled = True;
|
||||
wtext->text.endPos = textXtoPos(wtext, event->xmotion.x);
|
||||
}
|
||||
break;
|
||||
|
||||
case ButtonPress:
|
||||
PDEBUG("ButtonPress");
|
||||
handled = True;
|
||||
wtext->text.startPos = textXtoPos( wtext, event->xbutton.x );
|
||||
wtext->text.endPos = wtext->text.startPos;
|
||||
break;
|
||||
case ButtonPress:
|
||||
PDEBUG("ButtonPress");
|
||||
handled = True;
|
||||
wtext->text.startPos = textXtoPos(wtext, event->xbutton.x);
|
||||
wtext->text.endPos = wtext->text.startPos;
|
||||
break;
|
||||
|
||||
case ButtonRelease:
|
||||
PDEBUG("ButtonRelease");
|
||||
handled = True;
|
||||
wtext->text.endPos = textXtoPos( wtext, event->xbutton.x );
|
||||
break;
|
||||
case ButtonRelease:
|
||||
PDEBUG("ButtonRelease");
|
||||
handled = True;
|
||||
wtext->text.endPos = textXtoPos(wtext, event->xbutton.x);
|
||||
break;
|
||||
|
||||
case KeyPress:
|
||||
PDEBUG("KeyPress");
|
||||
handled = handleKeyPress( wtext, &event->xkey );
|
||||
break;
|
||||
case KeyPress:
|
||||
PDEBUG("KeyPress");
|
||||
handled = handleKeyPress(wtext, &event->xkey);
|
||||
break;
|
||||
|
||||
case EnterNotify:
|
||||
PDEBUG("EnterNotify");
|
||||
handled = True;
|
||||
case EnterNotify:
|
||||
PDEBUG("EnterNotify");
|
||||
handled = True;
|
||||
#if 0
|
||||
if (!wtext->magic)
|
||||
{
|
||||
wtext->magic = wAddTimerHandler(CURSOR_BLINK_RATE, blink, wtext);
|
||||
wtext->blink_on = !wtext->blink_on;
|
||||
blink(wtext);
|
||||
wtext->blinking = 1;
|
||||
}
|
||||
if (!wtext->magic) {
|
||||
wtext->magic = wAddTimerHandler(CURSOR_BLINK_RATE, blink, wtext);
|
||||
wtext->blink_on = !wtext->blink_on;
|
||||
blink(wtext);
|
||||
wtext->blinking = 1;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
break;
|
||||
|
||||
case LeaveNotify:
|
||||
PDEBUG("LeaveNotify");
|
||||
handled = True;
|
||||
case LeaveNotify:
|
||||
PDEBUG("LeaveNotify");
|
||||
handled = True;
|
||||
#if 0
|
||||
wtext->blinking = 0;
|
||||
if (wtext->blink_on)
|
||||
blink(wtext);
|
||||
if (wtext->magic)
|
||||
wDeleteTimerHandler(wtext->magic);
|
||||
wtext->magic = NULL;
|
||||
wtext->blinking = 0;
|
||||
if (wtext->blink_on)
|
||||
blink(wtext);
|
||||
if (wtext->magic)
|
||||
wDeleteTimerHandler(wtext->magic);
|
||||
wtext->magic = NULL;
|
||||
#endif
|
||||
break;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if( handled )
|
||||
textRefresh(wtext);
|
||||
else
|
||||
WMHandleEvent(event);
|
||||
if (handled)
|
||||
textRefresh(wtext);
|
||||
else
|
||||
WMHandleEvent(event);
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
handleExpose(WObjDescriptor *desc, XEvent *event)
|
||||
static void handleExpose(WObjDescriptor * desc, XEvent * event)
|
||||
{
|
||||
wTextPaint(desc->parent);
|
||||
wTextPaint(desc->parent);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user