1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-25 16:02:33 +01:00

changed indentation to use spaces only

This commit is contained in:
dan
2004-10-12 21:28:27 +00:00
parent 5912898b06
commit 6830b05716
240 changed files with 35951 additions and 35773 deletions

View File

@@ -1,4 +1,4 @@
/********************************************************************\
/********************************************************************
* text.c -- a basic text field *
* Copyright (C) 1997 Robin D. Clark *
* *
@@ -20,7 +20,7 @@
* Internet: rclark@cs.hmc.edu *
* Address: 609 8th Street *
* Huntington Beach, CA 92648-4632 *
\********************************************************************/
********************************************************************/
#include "wconfig.h"
@@ -39,7 +39,7 @@
/* X11R5 don't have this */
#ifndef IsPrivateKeypadKey
#define IsPrivateKeypadKey(keysym) \
(((KeySym)(keysym) >= 0x11000000) && ((KeySym)(keysym) <= 0x1100FFFF))
(((KeySym)(keysym) >= 0x11000000) && ((KeySym)(keysym) <= 0x1100FFFF))
#endif
@@ -55,9 +55,9 @@
extern Cursor wCursor[WCUR_LAST];
/********************************************************************\
/********************************************************************
* The event handler for the text-field: *
\********************************************************************/
********************************************************************/
static void textEventHandler( WObjDescriptor *desc, XEvent *event );
static void handleExpose( WObjDescriptor *desc, XEvent *event );
@@ -67,7 +67,7 @@ static void textInsert( WTextInput *wtext, char *txt );
static void blink(void *data);
#endif
/********************************************************************\
/********************************************************************
* handleKeyPress *
* handle cursor keys, regular keys, etc. Inserts characters in *
* text field, at cursor position, if it is a "Normal" key. If *
@@ -80,226 +80,226 @@ static void blink(void *data);
* Return: True, unless the ksym is ignored *
* Global: modifier - the bitfield that keeps track of the modifier *
* keys that are down *
\********************************************************************/
********************************************************************/
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;
/* Take care of the cursor keys.. ignore up and down
* cursor keys */
else if( IsCursorKey(ksym) )
/* 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
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;
}
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;
}
/********************************************************************\
* textXYtoPos *
/********************************************************************
* textXYtoPos *
* given X coord, return position in array *
\********************************************************************/
********************************************************************/
static int
textXtoPos( WTextInput *wtext, int x )
{
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 );
}
return pos;
}
{
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 );
}
return pos;
}
/********************************************************************
* wTextCreate *
* create an instance of a text class *
* *
* Args: *
* Return: *
* Global: dpy - the display *
\********************************************************************/
********************************************************************/
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 );
/* 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 );
/* set up the inverted context */
gcv.function = GXcopyInverted;
wtext->invGC = XCreateGC( dpy, wtext->core->window,
wtext->gc = XCreateGC( dpy, wtext->core->window,
(GCForeground|GCBackground|
GCFunction|GCLineWidth),
&gcv );
/* and set the background! */
XSetWindowBackground( dpy, wtext->core->window, gcv.background );
/* 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 );
/* set up the inverted context */
gcv.function = GXcopyInverted;
wtext->invGC = XCreateGC( dpy, wtext->core->window,
(GCForeground|GCBackground|
GCFunction|GCLineWidth),
&gcv );
/* 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;
wtext->canceled = False;
wtext->done = False; /* becomes True when the user *
* hits "Return" key */
/* Figure out the y-offset... */
wtext->yOffset = (height - WMFontHeight(wtext->font))/2;
wtext->xOffset = wtext->yOffset;
XMapRaised(dpy, wtext->core->window);
LEAVE("wTextCreate");
return wtext;
}
wtext->canceled = False;
wtext->done = False; /* becomes True when the user *
* hits "Return" key */
/********************************************************************\
XMapRaised(dpy, wtext->core->window);
LEAVE("wTextCreate");
return wtext;
}
/********************************************************************
* wTextDestroy *
* *
* Args: wtext - the text field *
* Return: *
* Global: dpy - the display *
\********************************************************************/
********************************************************************/
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 );
LEAVE("wTextDestroy");
}
XFreeGC( dpy, wtext->gc );
XFreeGC( dpy, wtext->regGC );
XFreeGC( dpy, wtext->invGC );
wfree( wtext->text.txt );
wCoreDestroy( wtext->core );
wfree( wtext );
LEAVE("wTextDestroy");
}
/* The text-field consists of a frame drawn around the outside,
@@ -311,7 +311,7 @@ wTextDestroy( WTextInput *wtext )
* then call wTextRefresh to redraw the text-box */
/********************************************************************\
/********************************************************************
* textRefresh *
* Redraw the text field. Call this after messing with the text *
* field. wTextRefresh re-draws the inside of the text field. If *
@@ -321,7 +321,7 @@ wTextDestroy( WTextInput *wtext )
* Args: wtext - the text field *
* Return: none *
* Global: dpy - the display *
\********************************************************************/
********************************************************************/
static void
textRefresh(WTextInput *wtext)
{
@@ -383,30 +383,30 @@ textRefresh(WTextInput *wtext)
}
/********************************************************************\
/********************************************************************
* wTextPaint *
* *
* Args: wtext - the text field *
* Return: *
* Global: dpy - the display *
\********************************************************************/
********************************************************************/
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 *
* RETURNED STRING! *
@@ -414,17 +414,17 @@ wTextPaint( WTextInput *wtext )
* Args: wtext - the text field *
* Return: the text in the text field (NULL terminated) *
* Global: *
\********************************************************************/
********************************************************************/
char *
wTextGetText( WTextInput *wtext )
{
if (!wtext->canceled)
return wtext->text.txt;
else
return NULL;
}
{
if (!wtext->canceled)
return wtext->text.txt;
else
return NULL;
}
/********************************************************************\
/********************************************************************
* wTextPutText *
* Put the string txt in the text field wText. The text field *
* needs to be explicitly refreshed after wTextPutText by calling *
@@ -435,25 +435,25 @@ wTextGetText( WTextInput *wtext )
* txt - the new text string... freed by the text field! *
* Return: none *
* Global: *
\********************************************************************/
********************************************************************/
void
wTextPutText( WTextInput *wtext, char *txt )
{
int length = strlen(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;
}
{
int length = strlen(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;
}
/********************************************************************
* textInsert *
* Insert some text at the cursor. (if startPos != endPos, *
* replace the selected text, otherwise insert) *
@@ -463,56 +463,56 @@ wTextPutText( WTextInput *wtext, char *txt )
* txt - the new text string... freed by the text field! *
* Return: none *
* Global: *
\********************************************************************/
********************************************************************/
static void
textInsert( WTextInput *wtext, char *txt )
{
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;
}
txtLen = strlen(txt);
newLen = wtext->text.length + txtLen - (ep - sp) + 1;
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];
/* 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];
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;
wfree(wtext->text.txt);
wtext->text.txt = newTxt;
wtext->text.length = newLen-1;
}
{
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;
}
txtLen = strlen(txt);
newLen = wtext->text.length + txtLen - (ep - sp) + 1;
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];
/* 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];
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;
wfree(wtext->text.txt);
wtext->text.txt = newTxt;
wtext->text.length = newLen-1;
}
/********************************************************************
* wTextSelect *
* Select some text. If start == end, then the cursor is moved *
* to that position. If end == -1, then the text from start to *
@@ -525,16 +525,16 @@ textInsert( WTextInput *wtext, char *txt )
* end - the end of the selected text *
* Return: none *
* Global: *
\********************************************************************/
********************************************************************/
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
@@ -543,108 +543,108 @@ blink(void *data)
int x;
WTextInput *wtext = (WTextInput*)data;
GC gc;
/* And draw a quick little line for the cursor position */
/* And draw a quick little line for the cursor position */
if (wtext->blink_on) {
gc = wtext->regGC;
wtext->blink_on = 0;
gc = wtext->regGC;
wtext->blink_on = 0;
} else {
gc = wtext->invGC;
wtext->blink_on = 1;
gc = wtext->invGC;
wtext->blink_on = 1;
}
x = WMWidthOfString( wtext->font, wtext->text.txt, wtext->text.endPos )
+ wtext->xOffset;
+ 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);
wtext->magic = wAddTimerHandler(CURSOR_BLINK_RATE, blink, data);
}
#endif
/********************************************************************\
/********************************************************************
* textEventHandler -- handles and dispatches all the events that *
* the text field class supports *
* *
* Args: desc - all we need to know about this object *
* Return: none *
* Global: *
\********************************************************************/
********************************************************************/
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 )
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;
/* 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;
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;
PDEBUG("ButtonRelease");
handled = True;
wtext->text.endPos = textXtoPos( wtext, event->xbutton.x );
break;
case KeyPress:
PDEBUG("KeyPress");
handled = handleKeyPress( wtext, &event->xkey );
break;
PDEBUG("KeyPress");
handled = handleKeyPress( wtext, &event->xkey );
break;
case EnterNotify:
PDEBUG("EnterNotify");
handled = True;
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;
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;
break;
}
if( handled )
textRefresh(wtext);
else
WMHandleEvent(event);
return;
}
if( handled )
textRefresh(wtext);
else
WMHandleEvent(event);
return;
}
static void