diff options
author | Kaleb Keithley <kaleb@freedesktop.org> | 2003-11-14 16:48:48 +0000 |
---|---|---|
committer | Kaleb Keithley <kaleb@freedesktop.org> | 2003-11-14 16:48:48 +0000 |
commit | 384ac455a6cd5d23dfa24f9939f3ec04f1e5de46 (patch) | |
tree | caf2569ba305a1d32fed698546a300d6bb22a6a3 | |
parent | 81ad93fde745d556aaa3880deabf3674bb3db49e (diff) | |
download | xorg-lib-libXaw-384ac455a6cd5d23dfa24f9939f3ec04f1e5de46.tar.gz |
XFree86 4.3.0.1xf86-4_3_0_1PRE_xf86-4_3_0_1
105 files changed, 31041 insertions, 21359 deletions
diff --git a/include/X11/Xaw/AsciiSink.h b/include/X11/Xaw/AsciiSink.h index d88288f..2f0a216 100644 --- a/include/X11/Xaw/AsciiSink.h +++ b/include/X11/Xaw/AsciiSink.h @@ -48,15 +48,14 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/AsciiSink.h,v 1.6 2001/12/14 19:54:38 dawes Exp $ */ #ifndef _XawAsciiSink_h #define _XawAsciiSink_h -/*********************************************************************** - * +/* * AsciiSink Object - * - ***********************************************************************/ + */ #include <X11/Xaw/TextSink.h> @@ -75,16 +74,9 @@ SOFTWARE. #define XtNecho "echo" /* Class record constants */ - extern WidgetClass asciiSinkObjectClass; typedef struct _AsciiSinkClassRec *AsciiSinkObjectClass; typedef struct _AsciiSinkRec *AsciiSinkObject; -/************************************************************ - * - * Public Functions. - * - ************************************************************/ - -#endif /* _XawAsciiSrc_h */ +#endif /* _XawAsciiSink_h */ diff --git a/include/X11/Xaw/AsciiSinkP.h b/include/X11/Xaw/AsciiSinkP.h index 02b9d39..7c19dd0 100644 --- a/include/X11/Xaw/AsciiSinkP.h +++ b/include/X11/Xaw/AsciiSinkP.h @@ -49,36 +49,23 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ - -/* - * asciiSinkP.h - Private definitions for asciiSink object - * - */ +/* $XFree86: xc/lib/Xaw/AsciiSinkP.h,v 1.10 2001/12/14 19:54:38 dawes Exp $ */ #ifndef _XawAsciiSinkP_h #define _XawAsciiSinkP_h -/*********************************************************************** - * +/* * AsciiSink Object Private Data - * - ***********************************************************************/ - + */ #include <X11/Xaw/TextSinkP.h> #include <X11/Xaw/AsciiSink.h> -/************************************************************ - * - * New fields for the AsciiSink object class record. - * - ************************************************************/ - +/* New fields for the AsciiSink object class record */ typedef struct _AsciiSinkClassPart { - int foo; + XtPointer extension; } AsciiSinkClassPart; /* Full class record declaration */ - typedef struct _AsciiSinkClassRec { ObjectClassPart object_class; TextSinkClassPart text_sink_class; @@ -89,24 +76,22 @@ extern AsciiSinkClassRec asciiSinkClassRec; /* New fields for the AsciiSink object record */ typedef struct { - /* public resources */ + /* resources */ XFontStruct *font; /* Font to draw in. */ Boolean echo; Boolean display_nonprinting; - /* private state */ + /* private */ GC normgc, invgc, xorgc; - Pixmap insertCursorOn; + XawTextPosition cursor_position; XawTextInsertState laststate; short cursor_x, cursor_y; /* Cursor Location. */ +#ifndef OLDXAW + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } AsciiSinkPart; -/**************************************************************** - * - * Full instance record declaration - * - ****************************************************************/ - +/* Full instance record declaration */ typedef struct _AsciiSinkRec { ObjectPart object; TextSinkPart text_sink; @@ -114,4 +99,3 @@ typedef struct _AsciiSinkRec { } AsciiSinkRec; #endif /* _XawAsciiSinkP_h */ - diff --git a/include/X11/Xaw/AsciiSrc.h b/include/X11/Xaw/AsciiSrc.h index c174b01..289a8c1 100644 --- a/include/X11/Xaw/AsciiSrc.h +++ b/include/X11/Xaw/AsciiSrc.h @@ -25,6 +25,7 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/AsciiSrc.h,v 1.8 2001/12/14 19:54:38 dawes Exp $ */ /* @@ -51,7 +52,6 @@ in this Software without prior written authorization from The Open Group. Name Class RepType Default Value ---- ----- ------- ------------- - callback Callback Callback (none) dataCompression DataCompression Boolean True length Length int (internal) pieceSize PieceSize int BUFSIZ @@ -61,24 +61,17 @@ in this Software without prior written authorization from The Open Group. */ -/* Class record constants */ - extern WidgetClass asciiSrcObjectClass; typedef struct _AsciiSrcClassRec *AsciiSrcObjectClass; typedef struct _AsciiSrcRec *AsciiSrcObject; -/* - * Just to make people's lives a bit easier. - */ - #define AsciiSourceObjectClass AsciiSrcObjectClass #define AsciiSourceObject AsciiSrcObject /* - * Resource Definitions. + * Resource Definitions */ - #define XtCDataCompression "DataCompression" #define XtCPieceSize "PieceSize" #define XtCType "Type" @@ -94,68 +87,89 @@ typedef struct _AsciiSrcRec *AsciiSrcObject; #define XtEstring "string" #define XtEfile "file" -typedef enum {XawAsciiFile, XawAsciiString} XawAsciiType; +typedef enum { + XawAsciiFile, + XawAsciiString +} XawAsciiType; -/************************************************************ - * - * Public routines - * - ************************************************************/ +/* + * Public routines + */ _XFUNCPROTOBEGIN -/* Function Name: XawAsciiSourceFreeString - * Description: Frees the string returned by a get values call - * on the string when the source is of type string. - * Arguments: w - the AsciiSrc object. - * Returns: none. +/* + * Function: + * XawAsciiSourceFreeString + * + * Parameters: + * w - AsciiSrc object + * + * Description: + * Frees the string returned by a get values call + * on the string when the source is of type string. */ +void XawAsciiSourceFreeString +( + Widget w + ); -extern void XawAsciiSourceFreeString( -#if NeedFunctionPrototypes - Widget /* w */ -#endif -); - -/* Function Name: XawAsciiSave - * Description: Saves all the pieces into a file or string as required. - * Arguments: w - the asciiSrc Object. - * Returns: TRUE if the save was successful. +/* + * Function: + * XawAsciiSave + * + * Arguments: + * w - asciiSrc Object. + * + * Description: + * Saves all the pieces into a file or string as required. + * + * Returns: + * True if the save was successful */ +Bool XawAsciiSave +( + Widget w + ); -extern Boolean XawAsciiSave( -#if NeedFunctionPrototypes - Widget /* w */ -#endif -); - -/* Function Name: XawAsciiSaveAsFile - * Description: Save the current buffer as a file. - * Arguments: w - the asciiSrc object. - * name - name of the file to save this file into. - * Returns: True if the save was successful. +/* + * Function: + * XawAsciiSaveAsFile + * + * Parameters: + * w - asciiSrc object + * name - name of the file to save this file into + * + * Description: + * Save the current buffer as a file. + * + * Returns: + * True if the save was successful */ +Bool XawAsciiSaveAsFile +( + Widget w, + _Xconst char *name + ); -extern Boolean XawAsciiSaveAsFile( -#if NeedFunctionPrototypes - Widget /* w */, - _Xconst char* /* name */ -#endif -); - -/* Function Name: XawAsciiSourceChanged - * Description: Returns true if the source has changed since last saved. - * Arguments: w - the asciiSource object. - * Returns: a Boolean (see description). +/* + * Function: + * XawAsciiSourceChanged + * + * Parameters: + * w - asciiSource object + * + * Description: + * Returns true if the source has changed since last saved. + * + * Returns: + * a Boolean (see description) */ - -extern Boolean XawAsciiSourceChanged( -#if NeedFunctionPrototypes - Widget /* w */ -#endif -); +Bool XawAsciiSourceChanged +( + Widget w + ); _XFUNCPROTOEND #endif /* _XawAsciiSrc_h */ - diff --git a/include/X11/Xaw/AsciiSrcP.h b/include/X11/Xaw/AsciiSrcP.h index de69cf1..c12aba6 100644 --- a/include/X11/Xaw/AsciiSrcP.h +++ b/include/X11/Xaw/AsciiSrcP.h @@ -49,6 +49,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/AsciiSrcP.h,v 1.9 2001/12/14 19:54:38 dawes Exp $ */ /* * AsciiSrcP.h - Private Header for Ascii Text Source. @@ -64,23 +65,12 @@ SOFTWARE. * kit@expo.lcs.mit.edu */ -/* - * TextSrcP.h - Private definitions for AsciiSrc object - * - */ - #ifndef _XawAsciiSrcP_h #define _XawAsciiSrcP_h #include <X11/Xaw/TextSrcP.h> #include <X11/Xaw/AsciiSrc.h> -/************************************************************ - * - * Private declarations. - * - ************************************************************/ - #ifdef L_tmpnam #define TMPSIZ L_tmpnam #else @@ -91,27 +81,19 @@ SOFTWARE. #endif #endif -#define MAGIC_VALUE ((XawTextPosition) -1) /* Magic value. */ - -#define streq(a, b) ( strcmp((a), (b)) == 0 ) - typedef struct _Piece { /* Piece of the text file of BUFSIZ allocated - characters. */ - char * text; /* The text in this buffer. */ - XawTextPosition used; /* The number of characters of this buffer - that have been used. */ - struct _Piece *prev, *next; /* linked list pointers. */ + characters */ + char *text; /* The text in this buffer */ + XawTextPosition used; /* The number of characters of this buffer + that have been used */ + struct _Piece *prev, *next; /* linked list pointers */ } Piece; -/************************************************************ - * - * New fields for the AsciiSrc object class record. - * - ************************************************************/ - -typedef struct _AsciiSrcClassPart { char foo; } AsciiSrcClassPart; +typedef struct _AsciiSrcClassPart { + XtPointer extension; +} AsciiSrcClassPart; -/* Full class record declaration */ +/* Full class record */ typedef struct _AsciiSrcClassRec { ObjectClassPart object_class; TextSrcClassPart text_src_class; @@ -120,47 +102,44 @@ typedef struct _AsciiSrcClassRec { extern AsciiSrcClassRec asciiSrcClassRec; -/* New fields for the AsciiSrc object record */ - +/* New fields for the AsciiSrc object */ typedef struct _AsciiSrcPart { - - /* Resources. */ - - char *string; /* either the string, or the - file name, depending upon the type. */ - XawAsciiType type; /* either string or disk. */ - XawTextPosition piece_size; /* Size of text buffer for each piece. */ - Boolean data_compression; /* compress to minimum memory automatically + /* resources */ + char *string; /* either the string, or the + file name, depending upon the type */ + XawAsciiType type; /* either string or disk */ + XawTextPosition piece_size; /* Size of text buffer for each piece */ + Boolean data_compression; /* compress to minimum memory automatically on save? */ - XtCallbackList callback; /* A callback list to call when the source is - changed. */ - Boolean use_string_in_place; /* Use the string passed in place. */ - int ascii_length; /* length field for ascii string emulation. */ +#ifdef OLDXAW + XtCallbackList callback; +#endif + Boolean use_string_in_place;/* Use the string passed in place */ + int ascii_length; /* length field for ascii string emulation */ #ifdef ASCII_DISK - String filename; /* name of file for Compatability. */ + String filename; /* name of file for Compatability */ #endif /* ASCII_DISK */ -/* Private data. */ - - Boolean is_tempfile; /* Is this a temporary file? */ - Boolean changes; /* Has this file been edited? */ - Boolean allocated_string; /* Have I allocated the - string in ascii_src->string? */ - XawTextPosition length; /* length of file */ - Piece * first_piece; /* first piece of the text. */ + /* private */ + Boolean is_tempfile; /* Is this a temporary file? */ +#ifdef OLDXAW + Boolean changes; +#endif + Boolean allocated_string; /* Have I allocated the + string in ascii_src->string? */ + XawTextPosition length; /* length of file */ + Piece *first_piece; /* first piece of the text */ +#ifndef OLDXAW + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } AsciiSrcPart; -/**************************************************************** - * - * Full instance record declaration - * - ****************************************************************/ - +/* instance record */ typedef struct _AsciiSrcRec { - ObjectPart object; - TextSrcPart text_src; - AsciiSrcPart ascii_src; + ObjectPart object; + TextSrcPart text_src; + AsciiSrcPart ascii_src; } AsciiSrcRec; #endif /* _XawAsciiSrcP_h */ diff --git a/include/X11/Xaw/AsciiText.h b/include/X11/Xaw/AsciiText.h index 6f60c27..1df99cf 100644 --- a/include/X11/Xaw/AsciiText.h +++ b/include/X11/Xaw/AsciiText.h @@ -48,18 +48,13 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ - -/*********************************************************************** - * - * AsciiText Widget - * - ***********************************************************************/ +/* $XFree86: xc/lib/Xaw/AsciiText.h,v 1.6 2001/12/14 19:54:39 dawes Exp $ */ /* - * AsciiText.c - Public header file for AsciiText Widget. + * AsciiText.h - Public header file for AsciiText Widget * * This Widget is intended to be used as a simple front end to the - * text widget with an ascii source and ascii sink attached to it. + * text widget with an ascii source and ascii sink attached to it * * Date: June 29, 1989 * @@ -67,17 +62,10 @@ SOFTWARE. * MIT X Consortium * kit@expo.lcs.mit.edu */ - #ifndef _AsciiText_h #define _AsciiText_h -/**************************************************************** - * - * AsciiText widgets - * - ****************************************************************/ - -#include <X11/Xaw/Text.h> /* AsciiText is a subclass of Text */ +#include <X11/Xaw/Text.h> #include <X11/Xaw/AsciiSrc.h> #include <X11/Xaw/MultiSrc.h> @@ -121,21 +109,14 @@ SOFTWARE. (see also *Src.h and *Sink.h) */ -/* - * Everything else we need is in StringDefs.h or Text.h - */ - typedef struct _AsciiTextClassRec *AsciiTextWidgetClass; typedef struct _AsciiRec *AsciiWidget; extern WidgetClass asciiTextWidgetClass; -/************************************************************ - * - * Disk and String Emulation Info. - * - ************************************************************/ - +/* + * Disk and String Emulation Info + */ #ifdef ASCII_STRING extern WidgetClass asciiStringWidgetClass; #endif diff --git a/include/X11/Xaw/AsciiTextP.h b/include/X11/Xaw/AsciiTextP.h index a525d67..68907e1 100644 --- a/include/X11/Xaw/AsciiTextP.h +++ b/include/X11/Xaw/AsciiTextP.h @@ -48,12 +48,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ - -/*********************************************************************** - * - * AsciiText Widget - * - ***********************************************************************/ +/* $XFree86: xc/lib/Xaw/AsciiTextP.h,v 1.9 2001/12/14 19:54:39 dawes Exp $ */ /* * AsciiText.c - Private header file for AsciiText Widget. @@ -76,7 +71,9 @@ SOFTWARE. #include <X11/Xaw/AsciiSrc.h> #include <X11/Xaw/MultiSrc.h> -typedef struct {int empty;} AsciiClassPart; +typedef struct { + XtPointer extension; +} AsciiClassPart; typedef struct _AsciiTextClassRec { CoreClassPart core_class; @@ -87,7 +84,12 @@ typedef struct _AsciiTextClassRec { extern AsciiTextClassRec asciiTextClassRec; -typedef struct { char foo; /* keep compiler happy. */ } AsciiPart; +typedef struct { + int resource; +#ifndef OLDXAW + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif +} AsciiPart; typedef struct _AsciiRec { CorePart core; @@ -96,15 +98,13 @@ typedef struct _AsciiRec { AsciiPart ascii; } AsciiRec; -/************************************************************ - * - * Ascii String Emulation widget. - * - ************************************************************/ - +/* + * Ascii String Emulation widget + */ #ifdef ASCII_STRING - -typedef struct {int empty;} AsciiStringClassPart; +typedef struct { + XtPointer extension; +} AsciiStringClassPart; typedef struct _AsciiStringClassRec { CoreClassPart core_class; @@ -116,7 +116,12 @@ typedef struct _AsciiStringClassRec { extern AsciiStringClassRec asciiStringClassRec; -typedef struct { char foo; /* keep compiler happy. */ } AsciiStringPart; +typedef struct { + int resource; +#ifndef OLDXAW + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif +} AsciiStringPart; typedef struct _AsciiStringRec { CorePart core; @@ -125,18 +130,15 @@ typedef struct _AsciiStringRec { AsciiPart ascii; AsciiStringPart ascii_str; } AsciiStringRec; - #endif /* ASCII_STRING */ #ifdef ASCII_DISK - -/************************************************************ - * - * Ascii Disk Emulation widget. - * - ************************************************************/ - -typedef struct {int empty;} AsciiDiskClassPart; +/* + * Ascii Disk Emulation widget + */ +typedef struct { + XtPointer extension; +} AsciiDiskClassPart; typedef struct _AsciiDiskClassRec { CoreClassPart core_class; @@ -148,7 +150,12 @@ typedef struct _AsciiDiskClassRec { extern AsciiDiskClassRec asciiDiskClassRec; -typedef struct { char foo; /* keep compiler happy. */ } AsciiDiskPart; +typedef struct { + char resource; +#ifndef OLDXAW + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif +} AsciiDiskPart; typedef struct _AsciiDiskRec { CorePart core; diff --git a/include/X11/Xaw/Box.h b/include/X11/Xaw/Box.h index d265feb..7ea8815 100644 --- a/include/X11/Xaw/Box.h +++ b/include/X11/Xaw/Box.h @@ -49,19 +49,18 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/Box.h,v 1.8 2001/12/14 19:54:39 dawes Exp $ */ #ifndef _XawBox_h #define _XawBox_h #include <X11/Xmu/Converters.h> -/*********************************************************************** - * +/* * Box Widget (subclass of CompositeClass) - * - ***********************************************************************/ + */ -/* Parameters: +/* Resources: Name Class RepType Default Value ---- ----- ------- ------------- @@ -69,6 +68,7 @@ SOFTWARE. border BorderColor Pixel XtDefaultForeground borderWidth BorderWidth Dimension 1 destroyCallback Callback Pointer NULL + displayList DisplayList XawDisplayList* NULL hSpace HSpace Dimension 4 height Height Dimension 0 mappedWhenManaged MappedWhenManaged Boolean True @@ -80,15 +80,26 @@ SOFTWARE. */ - -/* New fields */ #ifndef _XtStringDefs_h_ #define XtNhSpace "hSpace" #define XtNvSpace "vSpace" #endif -/* Class record constants */ +#ifndef OLDXAW +#ifndef XawNdisplayList +#define XawNdisplayList "displayList" +#endif + +#ifndef XawCDisplayList +#define XawCDisplayList "DisplayList" +#endif + +#ifndef XawRDisplayList +#define XawRDisplayList "XawDisplayList" +#endif +#endif /* OLDXAW */ +/* Class record constants */ extern WidgetClass boxWidgetClass; typedef struct _BoxClassRec *BoxWidgetClass; diff --git a/include/X11/Xaw/BoxP.h b/include/X11/Xaw/BoxP.h index ecd7b35..bc1607e 100644 --- a/include/X11/Xaw/BoxP.h +++ b/include/X11/Xaw/BoxP.h @@ -49,26 +49,22 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ - -/* - * BoxP.h - Private definitions for Box widget - * - */ +/* $XFree86: xc/lib/Xaw/BoxP.h,v 1.11 2001/12/14 19:54:39 dawes Exp $ */ #ifndef _XawBoxP_h #define _XawBoxP_h -/*********************************************************************** - * +/* * Box Widget Private Data - * - ***********************************************************************/ - + */ #include <X11/Xaw/Box.h> #include <X11/Xmu/Converters.h> +#include <X11/Xaw/XawInit.h> /* New fields for the Box widget class record */ -typedef struct {int empty;} BoxClassPart; +typedef struct { + XtPointer extension; +} BoxClassPart; /* Full class record declaration */ typedef struct _BoxClassRec { @@ -82,22 +78,22 @@ extern BoxClassRec boxClassRec; /* New fields for the Box widget record */ typedef struct { /* resources */ - Dimension h_space, v_space; + Dimension h_space, v_space; XtOrientation orientation; /* private state */ - Dimension preferred_width, preferred_height; - Dimension last_query_width, last_query_height; + Dimension preferred_width, preferred_height; + Dimension last_query_width, last_query_height; XtGeometryMask last_query_mode; +#ifndef OLDXAW + XawDisplayList *display_list; + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } BoxPart; - -/**************************************************************** - * +/* * Full instance record declaration - * - ****************************************************************/ - + */ typedef struct _BoxRec { CorePart core; CompositePart composite; diff --git a/include/X11/Xaw/Command.h b/include/X11/Xaw/Command.h index a9738d2..95f98df 100644 --- a/include/X11/Xaw/Command.h +++ b/include/X11/Xaw/Command.h @@ -46,6 +46,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/Command.h,v 1.6 2001/12/14 19:54:39 dawes Exp $ */ #ifndef _XawCommand_h #define _XawCommand_h @@ -71,6 +72,7 @@ SOFTWARE. cursorName Cursor String NULL depth Depth int parent's depth destroyCallback Callback XtCallbackList NULL + displayList DisplayList XawDisplayList* NULL encoding Encoding UnsignedChar XawTextEncoding8bit font Font XFontStruct* XtDefaultFont foreground Foreground Pixel XtDefaultForeground diff --git a/include/X11/Xaw/CommandP.h b/include/X11/Xaw/CommandP.h index 4c4db90..541281c 100644 --- a/include/X11/Xaw/CommandP.h +++ b/include/X11/Xaw/CommandP.h @@ -49,47 +49,32 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ - -/* - * CommandP.h - Private definitions for Command widget - * - */ +/* $XFree86: xc/lib/Xaw/CommandP.h,v 1.8 2001/12/14 19:54:39 dawes Exp $ */ #ifndef _XawCommandP_h #define _XawCommandP_h +/* + * Command Widget Private Data + */ #include <X11/Xaw/Command.h> #include <X11/Xaw/LabelP.h> -/*********************************************************************** - * - * Command Widget Private Data - * - ***********************************************************************/ - typedef enum { - HighlightNone, /* Do not highlight. */ - HighlightWhenUnset, /* Highlight only when unset, this is + HighlightNone, /* Do not highlight */ + HighlightWhenUnset, /* Highlight only when unset, this is to preserve current command widget - functionality. */ - HighlightAlways /* Always highlight, lets the toggle widget - and other subclasses do the right thing. */ + functionality */ + HighlightAlways /* Always highlight, lets the toggle widget + and other subclasses do the right thing */ } XtCommandHighlight; -/************************************ - * - * Class structure - * - ***********************************/ - - - /* New fields for the Command widget class record */ -typedef struct _CommandClass - { - int makes_compiler_happy; /* not used */ - } CommandClassPart; +/* New fields for the Command widget class record */ +typedef struct _CommandClass { + XtPointer extension; +} CommandClassPart; - /* Full class record declaration */ +/* Full class record declaration */ typedef struct _CommandClassRec { CoreClassPart core_class; SimpleClassPart simple_class; @@ -99,13 +84,7 @@ typedef struct _CommandClassRec { extern CommandClassRec commandClassRec; -/*************************************** - * - * Instance (widget) structure - * - **************************************/ - - /* New fields for the Command widget record */ +/* New fields for the Command widget record */ typedef struct { /* resources */ Dimension highlight_thickness; @@ -117,16 +96,17 @@ typedef struct { GC inverse_GC; Boolean set; XtCommandHighlight highlighted; + /* more resources */ int shape_style; Dimension corner_round; -} CommandPart; - - -/* XtEventsPtr eventTable;*/ +#ifndef OLDXAW + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif +} CommandPart; - /* Full widget declaration */ +/* Full widget declaration */ typedef struct _CommandRec { CorePart core; SimplePart simple; @@ -135,5 +115,3 @@ typedef struct _CommandRec { } CommandRec; #endif /* _XawCommandP_h */ - - diff --git a/include/X11/Xaw/Dialog.h b/include/X11/Xaw/Dialog.h index 2000702..5ad325a 100644 --- a/include/X11/Xaw/Dialog.h +++ b/include/X11/Xaw/Dialog.h @@ -46,24 +46,19 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/Dialog.h,v 1.6 2001/12/14 19:54:39 dawes Exp $ */ #ifndef _XawDialog_h #define _XawDialog_h #include <X11/Xaw/Form.h> -/*********************************************************************** - * - * Dialog Widget - * - ***********************************************************************/ - -/* Parameters: +/* Resources: Name Class RepType Default Value ---- ----- ------- ------------- background Background Pixel XtDefaultBackground - border BorderColor Pixel XtDefaultForeground + borderColor BorderColor Pixel XtDefaultForeground borderWidth BorderWidth Dimension 1 destroyCallback Callback Pointer NULL height Height Dimension computed at create @@ -88,19 +83,17 @@ extern WidgetClass dialogWidgetClass; _XFUNCPROTOBEGIN -extern void XawDialogAddButton( -#if NeedFunctionPrototypes - Widget /* dialog */, - _Xconst char* /* name */, - XtCallbackProc /* function */, - XtPointer /* client_data */ -#endif -); - -extern char *XawDialogGetValueString( -#if NeedFunctionPrototypes - Widget /* w */ -#endif +void XawDialogAddButton +( + Widget dialog, + _Xconst char *name, + XtCallbackProc function, + XtPointer client_data + ); + +char *XawDialogGetValueString +( + Widget w ); _XFUNCPROTOEND diff --git a/include/X11/Xaw/DialogP.h b/include/X11/Xaw/DialogP.h index e230f90..43e0425 100644 --- a/include/X11/Xaw/DialogP.h +++ b/include/X11/Xaw/DialogP.h @@ -47,8 +47,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ - -/* Private definitions for Dialog widget */ +/* $XFree86: xc/lib/Xaw/DialogP.h,v 1.9 2001/12/14 19:54:39 dawes Exp $ */ #ifndef _DialogP_h #define _DialogP_h @@ -56,7 +55,9 @@ SOFTWARE. #include <X11/Xaw/Dialog.h> #include <X11/Xaw/FormP.h> -typedef struct {int empty;} DialogClassPart; +typedef struct { + XtPointer extension; +} DialogClassPart; typedef struct _DialogClassRec { CoreClassPart core_class; @@ -70,13 +71,17 @@ extern DialogClassRec dialogClassRec; typedef struct _DialogPart { /* resources */ - String label; /* description of the dialog */ - String value; /* for the user response */ - Pixmap icon; /* icon bitmap */ - /* private data */ - Widget iconW; /* widget to display the icon */ - Widget labelW; /* widget to display description*/ - Widget valueW; /* user response TextWidget */ + String label; /* description of the dialog */ + String value; /* for the user response */ + Pixmap icon; /* icon bitmap */ + + /* private */ + Widget iconW; /* widget to display the icon */ + Widget labelW; /* widget to display description */ + Widget valueW; /* user response TextWidget */ +#ifndef OLDXAW + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } DialogPart; typedef struct _DialogRec { @@ -87,7 +92,9 @@ typedef struct _DialogRec { DialogPart dialog; } DialogRec; -typedef struct {int empty;} DialogConstraintsPart; +typedef struct { + XtPointer extension; +} DialogConstraintsPart; typedef struct _DialogConstraintsRec { FormConstraintsPart form; diff --git a/include/X11/Xaw/Form.h b/include/X11/Xaw/Form.h index d12ed0b..e8aaeb9 100644 --- a/include/X11/Xaw/Form.h +++ b/include/X11/Xaw/Form.h @@ -47,19 +47,14 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/Form.h,v 1.9 2001/12/14 19:54:40 dawes Exp $ */ #ifndef _XawForm_h #define _XawForm_h #include <X11/Intrinsic.h> -/*********************************************************************** - * - * Form Widget - * - ***********************************************************************/ - -/* Parameters: +/* Resources: Name Class RepType Default Value ---- ----- ------- ------------- @@ -68,6 +63,7 @@ SOFTWARE. borderWidth BorderWidth Dimension 1 defaultDistance Thickness int 4 destroyCallback Callback Pointer NULL + displayList DisplayList XawDisplayList* NULL height Height Dimension computed at realize mappedWhenManaged MappedWhenManaged Boolean True sensitive Sensitive Boolean True @@ -112,8 +108,6 @@ SOFTWARE. #define XtCEdge "Edge" #define XtCWidget "Widget" -#ifndef _XawEdgeType_e -#define _XawEdgeType_e typedef enum { XawChainTop, /* Keep this edge a constant distance from the top of the form */ @@ -124,17 +118,8 @@ typedef enum { XawChainRight, /* Keep this edge a constant distance from the right of the form */ XawRubber /* Keep this edge a proportional distance - from the edges of the form*/ + from the edges of the form */ } XawEdgeType; -#endif /* _XawEdgeType_e */ - -/* - * Unfortunatly I missed this definition for R4, so I cannot - * protect it with XAW_BC, it looks like this particular problem is - * one that we will have to live with for a while. - * - * Chris D. Peterson - 3/23/90. - */ #define XtEdgeType XawEdgeType @@ -144,6 +129,26 @@ typedef enum { #define XtChainRight XawChainRight #define XtRubber XawRubber +#define XtEchainLeft "chainLeft" +#define XtEchainRight "chainRight" +#define XtEchainTop "chainTop" +#define XtEchainBottom "chainBottom" +#define XtErubber "rubber" + +#ifndef OLDXAW +#ifndef XawNdisplayList +#define XawNdisplayList "displayList" +#endif + +#ifndef XawCDisplayList +#define XawCDisplayList "DisplayList" +#endif + +#ifndef XawRDisplayList +#define XawRDisplayList "XawDisplayList" +#endif +#endif + typedef struct _FormClassRec *FormWidgetClass; typedef struct _FormRec *FormWidget; @@ -151,16 +156,15 @@ extern WidgetClass formWidgetClass; _XFUNCPROTOBEGIN -extern void XawFormDoLayout( -#if NeedFunctionPrototypes - Widget /* w */, +void XawFormDoLayout +( + Widget w, #if NeedWidePrototypes - /* Boolean */ int /* do_layout */ + Bool do_layout #else - Boolean /* do_layout */ -#endif + Boolean do_layout #endif -); + ); _XFUNCPROTOEND diff --git a/include/X11/Xaw/FormP.h b/include/X11/Xaw/FormP.h index b2456c0..f77843f 100644 --- a/include/X11/Xaw/FormP.h +++ b/include/X11/Xaw/FormP.h @@ -46,35 +46,38 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/FormP.h,v 1.14 2001/12/19 21:37:30 dawes Exp $ */ /* Form widget private definitions */ #ifndef _XawFormP_h #define _XawFormP_h +#include <X11/Xfuncproto.h> + #include <X11/Xaw/Form.h> +#include <X11/Xaw/XawInit.h> + +_XFUNCPROTOBEGIN #define XtREdgeType "EdgeType" -typedef enum {LayoutPending, LayoutInProgress, LayoutDone} LayoutState; -#define XtInheritLayout ((Boolean (*)())_XtInherit) +typedef enum { + LayoutPending, + LayoutInProgress, + LayoutDone +} LayoutState; + +#define XtInheritLayout \ +((Boolean (*)(FormWidget, unsigned int, unsigned int, Bool))_XtInherit) typedef struct { - Boolean (*layout)(/* FormWidget, Dimension, Dimension */); + Boolean(*layout)(FormWidget, unsigned int, unsigned int, Bool); +#ifndef OLDXAW + XtPointer extension; +#endif } FormClassPart; -/* - * Layout( - * FormWidget w - the widget whose children are to be configured - * Dimension w, h - bounding box of layout to be calculated - * - * Stores preferred geometry in w->form.preferred_{width,height}. - * If w->form.resize_in_layout is True, then a geometry request - * may be made for the preferred bounding box if necessary. - * - * Returns True if a geometry request was granted, False otherwise. - */ - typedef struct _FormClassRec { CoreClassPart core_class; CompositeClassPart composite_class; @@ -87,13 +90,18 @@ extern FormClassRec formClassRec; typedef struct _FormPart { /* resources */ int default_spacing; /* default distance between children */ - /* private state */ - Dimension old_width, old_height; /* last known dimensions */ + + /* private */ + Dimension old_width, old_height; /* reference value for *_virtual */ int no_refigure; /* no re-layout while > 0 */ Boolean needs_relayout; /* next time no_refigure == 0 */ Boolean resize_in_layout; /* should layout() do geom request? */ Dimension preferred_width, preferred_height; /* cached from layout */ - Boolean resize_is_no_op; /* Causes resize to take not action. */ + Boolean resize_is_no_op; /* Causes resize to take not action */ +#ifndef OLDXAW + XawDisplayList *display_list; + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } FormPart; typedef struct _FormRec { @@ -104,39 +112,31 @@ typedef struct _FormRec { } FormRec; typedef struct _FormConstraintsPart { -/* - * Constraint Resources. - */ - XtEdgeType top, bottom, /* where to drag edge on resize */ - left, right; + /* resources */ + XtEdgeType top, bottom, left, right;/* where to drag edge on resize */ int dx; /* desired horiz offset */ int dy; /* desired vertical offset */ Widget horiz_base; /* measure dx from here if non-null */ Widget vert_base; /* measure dy from here if non-null */ - Boolean allow_resize; /* TRUE if child may request resize */ + Boolean allow_resize; /* True if child may request resize */ -/* - * Private contstraint resources. - */ - -/* - * What the size of this child would be if we did not impose the - * constraint the width and height must be greater than zero (0). - */ + /* private */ short virtual_width, virtual_height; - -/* - * Temporary Storage for children's new possible possition. - */ - - Position new_x, new_y; - + Position new_x, new_y; LayoutState layout_state; /* temporary layout state */ - Boolean deferred_resize; /* was resized while no_refigure is set */ + Boolean deferred_resize;/* was resized while no_refigure is set */ +#ifndef OLDXAW + short virtual_x, virtual_y; + XtPointer pad[2]; /* leave some space for further optimizations + * in the form widget geometry + */ +#endif } FormConstraintsPart; typedef struct _FormConstraintsRec { FormConstraintsPart form; } FormConstraintsRec, *FormConstraints; +_XFUNCPROTOEND + #endif /* _XawFormP_h */ diff --git a/include/X11/Xaw/Grip.h b/include/X11/Xaw/Grip.h index fdf751f..4f08213 100644 --- a/include/X11/Xaw/Grip.h +++ b/include/X11/Xaw/Grip.h @@ -46,6 +46,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/Grip.h,v 1.7 2001/12/14 19:54:40 dawes Exp $ */ /* * Grip.h - Public Definitions for Grip widget (used by VPane Widget) @@ -57,13 +58,7 @@ SOFTWARE. #include <X11/Xaw/Simple.h> -/*************************************************************************** - * - * Grip Widget - * - **************************************************************************/ - -/* Parameters: +/* Resources: Name Class RepType Default Value ---- ----- ------- ------------- @@ -88,11 +83,11 @@ SOFTWARE. #define XtNgripTranslations "gripTranslations" typedef struct _XawGripCallData { - XEvent *event; /* the event causing the GripAction */ - String *params; /* the TranslationTable params */ - Cardinal num_params; /* count of params */ + XEvent *event; /* the event causing the GripAction */ + String *params; /* the TranslationTable params */ + Cardinal num_params; /* count of params */ } XawGripCallDataRec, *XawGripCallData, - GripCallDataRec, *GripCallData; /* supported for R4 compatibility */ + GripCallDataRec, *GripCallData; /* supported for R4 compatibility */ /* Class Record Constant */ diff --git a/include/X11/Xaw/GripP.h b/include/X11/Xaw/GripP.h index 4e89917..21cc845 100644 --- a/include/X11/Xaw/GripP.h +++ b/include/X11/Xaw/GripP.h @@ -49,11 +49,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ - -/* - * GripP.h - Private definitions for Grip widget (Used by VPane Widget) - * - */ +/* $XFree86: xc/lib/Xaw/GripP.h,v 1.8 2001/12/14 19:54:40 dawes Exp $ */ #ifndef _XawGripP_h #define _XawGripP_h @@ -61,18 +57,14 @@ SOFTWARE. #include <X11/Xaw/Grip.h> #include <X11/Xaw/SimpleP.h> -/***************************************************************************** - * - * Grip Widget Private Data - * - *****************************************************************************/ - #define DEFAULT_GRIP_SIZE 8 -/* New fields for the Grip widget class record */ -typedef struct {int empty;} GripClassPart; +/* New fields for the Grip widget class */ +typedef struct { + XtPointer extension; +} GripClassPart; -/* Full Class record declaration */ +/* Full Class record */ typedef struct _GripClassRec { CoreClassPart core_class; SimpleClassPart simple_class; @@ -81,22 +73,19 @@ typedef struct _GripClassRec { extern GripClassRec gripClassRec; -/* New fields for the Grip widget record */ +/* New fields for the Grip widget */ typedef struct { - XtCallbackList grip_action; + XtCallbackList grip_action; +#ifndef OLDXAW + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } GripPart; -/***************************************************************************** - * - * Full instance record declaration - * - ****************************************************************************/ - +/* Full instance record */ typedef struct _GripRec { - CorePart core; - SimplePart simple; - GripPart grip; + CorePart core; + SimplePart simple; + GripPart grip; } GripRec; #endif /* _XawGripP_h */ - diff --git a/include/X11/Xaw/Label.h b/include/X11/Xaw/Label.h index 03696ae..f0a2be0 100644 --- a/include/X11/Xaw/Label.h +++ b/include/X11/Xaw/Label.h @@ -46,15 +46,14 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/Label.h,v 1.7 2001/12/14 19:54:40 dawes Exp $ */ #ifndef _XawLabel_h #define _XawLabel_h -/*********************************************************************** - * +/* * Label Widget - * - ***********************************************************************/ + */ #include <X11/Xaw/Simple.h> @@ -69,7 +68,7 @@ SOFTWARE. cursor Cursor Cursor None cursorName Cursor String NULL destroyCallback Callback XtCallbackList NULL - encoding Encoding unsigned char XawTextEncoding8bit + encoding Encoding UnsignedChar XawTextEncoding8bit font Font XFontStruct* XtDefaultFont foreground Foreground Pixel XtDefaultForeground height Height Dimension text height @@ -118,6 +117,14 @@ SOFTWARE. #define XtCBitmap "Bitmap" #endif +#ifndef XtNlabelX +#define XtNlabelX "labelX" +#endif + +#ifndef XtNlabelY +#define XtNlabelY "labelY" +#endif + /* Class record constants */ extern WidgetClass labelWidgetClass; diff --git a/include/X11/Xaw/LabelP.h b/include/X11/Xaw/LabelP.h index 384c55e..41a9bd0 100644 --- a/include/X11/Xaw/LabelP.h +++ b/include/X11/Xaw/LabelP.h @@ -49,27 +49,21 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ - -/* - * LabelP.h - Private definitions for Label widget - * - */ +/* $XFree86: xc/lib/Xaw/LabelP.h,v 1.8 2001/12/14 19:54:40 dawes Exp $ */ #ifndef _XawLabelP_h #define _XawLabelP_h -/*********************************************************************** - * +/* * Label Widget Private Data - * - ***********************************************************************/ - + */ #include <X11/Xaw/Label.h> #include <X11/Xaw/SimpleP.h> /* New fields for the Label widget class record */ - -typedef struct {int foo;} LabelClassPart; +typedef struct { + XtPointer extension; +} LabelClassPart; /* Full class record declaration */ typedef struct _LabelClassRec { @@ -106,15 +100,14 @@ typedef struct { Dimension label_len; int lbm_y; /* where in label */ unsigned int lbm_width, lbm_height; /* size of pixmap */ +#ifndef OLDXAW + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } LabelPart; - -/**************************************************************** - * +/* * Full instance record declaration - * - ****************************************************************/ - + */ typedef struct _LabelRec { CorePart core; SimplePart simple; diff --git a/include/X11/Xaw/List.h b/include/X11/Xaw/List.h index e40e1a5..b693411 100644 --- a/include/X11/Xaw/List.h +++ b/include/X11/Xaw/List.h @@ -23,6 +23,7 @@ Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/List.h,v 1.8 2001/12/14 19:54:40 dawes Exp $ */ /* This is the List widget, it is useful to display a list, without the * overhead of having a widget for each item in the list. It allows @@ -37,12 +38,6 @@ in this Software without prior written authorization from The Open Group. #ifndef _XawList_h #define _XawList_h -/*********************************************************************** - * - * List Widget - * - ***********************************************************************/ - #include <X11/Xaw/Simple.h> /* Resources: @@ -50,7 +45,7 @@ in this Software without prior written authorization from The Open Group. Name Class RepType Default Value ---- ----- ------- ------------- background Background Pixel XtDefaultBackground - border BorderColor Pixel XtDefaultForeground + borderColor BorderColor Pixel XtDefaultForeground borderWidth BorderWidth Dimension 1 callback Callback XtCallbackList NULL **6 columnSpacing Spacing Dimension 6 @@ -65,7 +60,7 @@ in this Software without prior written authorization from The Open Group. insensitiveBorder Insensitive Pixmap Gray internalHeight Height Dimension 2 internalWidth Width Dimension 4 - list List String * NULL **2 + list List String* NULL **2 longest Longest int 0 **3 **4 mappedWhenManaged MappedWhenManaged Boolean True numberStrings NumberStrings int 0 **4 @@ -110,11 +105,9 @@ in this Software without prior written authorization from The Open Group. */ - /* - * Value returned when there are no highlighted objects. + * Value returned when there are no highlighted objects */ - #define XAW_LIST_NONE -1 #define XtCList "List" @@ -133,6 +126,7 @@ in this Software without prior written authorization from The Open Group. #define XtNpasteBuffer "pasteBuffer" #define XtNrowSpacing "rowSpacing" #define XtNverticalList "verticalList" +#define XtNshowCurrent "showCurrent" #ifndef XtNfontSet #define XtNfontSet "fontSet" @@ -142,94 +136,101 @@ in this Software without prior written authorization from The Open Group. #define XtCFontSet "FontSet" #endif -/* Class record constants */ - extern WidgetClass listWidgetClass; typedef struct _ListClassRec *ListWidgetClass; typedef struct _ListRec *ListWidget; -/* The list return structure. */ - +/* list return structure */ typedef struct _XawListReturnStruct { String string; int list_index; } XawListReturnStruct; -/****************************************************************** - * - * Exported Functions - * - *****************************************************************/ - _XFUNCPROTOBEGIN -/* Function Name: XawListChange. - * Description: Changes the list being used and shown. - * Arguments: w - the list widget. - * list - the new list. - * nitems - the number of items in the list. - * longest - the length (in Pixels) of the longest element - * in the list. - * resize - if TRUE the the list widget will - * try to resize itself. - * Returns: none. - * NOTE: If nitems of longest are <= 0 then they will be caluculated. - * If nitems is <= 0 then the list needs to be NULL terminated. +/* + * Function: + * XawListChange + * + * Parameters: + * w - list widget + * list - new list + * nitems - number of items in the list + * longest - length (in Pixels) of the longest element in the list + * resize - if True the the list widget will try to resize itself + * + * Description: + * Changes the list being used and shown. + * + * Note: + * If nitems of longest are <= 0 then they will be caluculated + * If nitems is <= 0 then the list needs to be NULL terminated */ - -extern void XawListChange( -#if NeedFunctionPrototypes - Widget /* w */, - String* /* list */, - int /* nitems */, - int /* longest */, +void XawListChange +( + Widget w, + String *list, + int nitems, + int longest, #if NeedWidePrototypes - /* Boolean */ int /* resize */ + int resize #else - Boolean /* resize */ -#endif + Boolean resize #endif -); + ); -/* Function Name: XawListUnhighlight - * Description: unlights the current highlighted element. - * Arguments: w - the widget. - * Returns: none. +/* + * Function: + * XawListUnhighlight + * + * Parameters: + * w - list widget + * + * Description: + * Unlights the current highlighted element. */ +void XawListUnhighlight +( + Widget w + ); -extern void XawListUnhighlight( -#if NeedFunctionPrototypes - Widget /* w */ -#endif -); - -/* Function Name: XawListHighlight - * Description: Highlights the given item. - * Arguments: w - the list widget. - * item - the item to highlight. - * Returns: none. +/* + * Function: + * XawListHighlight + * + * Parameters: + * w - list widget + * item - item to highlight + * + * Description: + * Highlights the given item. */ - -extern void XawListHighlight( -#if NeedFunctionPrototypes - Widget /* w */, - int /* item */ -#endif -); +void XawListHighlight +( + Widget w, + int item + ); -/* Function Name: XawListShowCurrent - * Description: returns the currently highlighted object. - * Arguments: w - the list widget. - * Returns: the info about the currently highlighted object. +/* + * Function: + * XawListShowCurrent + * + * Paraneters: + * w - list widget + * + * Description: + * Returns the currently highlighted object. + * + * Returns: + * The info about the currently highlighted object */ -extern XawListReturnStruct * XawListShowCurrent( -#if NeedFunctionPrototypes - Widget /* w */ -#endif -); +XawListReturnStruct *XawListShowCurrent +( + Widget w + ); _XFUNCPROTOEND diff --git a/include/X11/Xaw/ListP.h b/include/X11/Xaw/ListP.h index f492559..12915f0 100644 --- a/include/X11/Xaw/ListP.h +++ b/include/X11/Xaw/ListP.h @@ -23,11 +23,10 @@ Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/ListP.h,v 1.9 2001/12/14 19:54:40 dawes Exp $ */ /* - * ListP.h - Private definitions for List widget - * * This is a List widget. It allows the user to select an item in a list and * notifies the application through a callback function. * @@ -39,12 +38,9 @@ in this Software without prior written authorization from The Open Group. #ifndef _XawListP_h #define _XawListP_h -/*********************************************************************** - * +/* * List Widget Private Data - * - ***********************************************************************/ - + */ #include <X11/Xaw/SimpleP.h> #include <X11/Xaw/List.h> @@ -52,11 +48,12 @@ in this Software without prior written authorization from The Open Group. #define OUT_OF_RANGE -1 #define OKAY 0 -/* New fields for the List widget class record */ - -typedef struct {int foo;} ListClassPart; +/* New fields for the List widget class */ +typedef struct { + XtPointer extension; +} ListClassPart; -/* Full class record declaration */ +/* Full class record */ typedef struct _ListClassRec { CoreClassPart core_class; SimpleClassPart simple_class; @@ -65,47 +62,53 @@ typedef struct _ListClassRec { extern ListClassRec listClassRec; -/* New fields for the List widget record */ +/* New fields for the List widget */ typedef struct { /* resources */ - Pixel foreground; - Dimension internal_width, /* if not 3d, user sets directly. */ - internal_height, - column_space, /* half of *_space is add on top/bot/left of*/ - row_space; /* each item's text bounding box. half added to longest for right */ - int default_cols; - Boolean force_cols, - paste, - vertical_cols; - int longest; /* in pixels */ - int nitems; /* number of items in the list. */ + Pixel foreground; + Dimension internal_width; /* if not 3d, user sets directly */ + Dimension internal_height; + Dimension column_space; /* half of *_space is add on + top/bot/left of */ + Dimension row_space; /* each item's text bounding box + half added to longest for right */ + int default_cols; + Boolean force_cols; + Boolean paste; + Boolean vertical_cols; + int longest; /* in pixels */ + int nitems; XFontStruct *font; - XFontSet fontset; /* Sheeran, Omron KK, 93/03/05 */ - String * list; /* for i18n, always in multibyte format */ + XFontSet fontset; /* Sheeran, Omron KK, 93/03/05 */ + String *list; /* for i18n, always in multibyte + format */ XtCallbackList callback; - /* private state */ - int is_highlighted, /* set to the item currently highlighted. */ - highlight, /* set to the item that should be highlighted.*/ - col_width, /* width of each column. */ - row_height, /* height of each row. */ - nrows, /* number of rows in the list. */ - ncols; /* number of columns in the list. */ - GC normgc, /* a couple of GC's. */ - revgc, - graygc; /* used when inactive. */ - - int freedoms; /* flags for resizing height and width */ - + /* private */ + int is_highlighted; /* set to the item currently + highlighted */ + int highlight; /* set to the item that should be + highlighted */ + int col_width; /* width of each column */ + int row_height; /* height of each row */ + int nrows; /* number of rows in the list */ + int ncols; /* number of columns in the list */ + GC normgc; + GC revgc; + GC graygc; + int freedoms; /* flags for resizing height + and width */ +#ifndef OLDXAW + int selected; + Boolean show_current; + char pad1[(sizeof(XtPointer) - sizeof(Boolean)) + + (sizeof(XtPointer) - sizeof(int))]; + XtPointer pad2[2]; /* for future use and keep binary compatability */ +#endif } ListPart; -/**************************************************************** - * - * Full instance record declaration - * - ****************************************************************/ - +/* Full instance record */ typedef struct _ListRec { CorePart core; SimplePart simple; diff --git a/include/X11/Xaw/MenuButtoP.h b/include/X11/Xaw/MenuButtoP.h index 47f415f..ed168f1 100644 --- a/include/X11/Xaw/MenuButtoP.h +++ b/include/X11/Xaw/MenuButtoP.h @@ -22,12 +22,7 @@ Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ - -/*********************************************************************** - * - * MenuButton Widget - * - ***********************************************************************/ +/* $XFree86: xc/lib/Xaw/MenuButtoP.h,v 1.8 2001/12/14 19:54:41 dawes Exp $ */ /* * MenuButtonP.h - Private Header file for MenuButton widget. @@ -48,44 +43,32 @@ in this Software without prior written authorization from The Open Group. #include <X11/Xaw/MenuButton.h> #include <X11/Xaw/CommandP.h> -/************************************ - * - * Class structure - * - ***********************************/ - - - /* New fields for the MenuButton widget class record */ -typedef struct _MenuButtonClass -{ - int makes_compiler_happy; /* not used */ +/* New fields for the MenuButton widget class */ +typedef struct _MenuButtonClass { + XtPointer extension; } MenuButtonClassPart; - /* Full class record declaration */ +/* class record declaration */ typedef struct _MenuButtonClassRec { - CoreClassPart core_class; - SimpleClassPart simple_class; - LabelClassPart label_class; - CommandClassPart command_class; - MenuButtonClassPart menuButton_class; + CoreClassPart core_class; + SimpleClassPart simple_class; + LabelClassPart label_class; + CommandClassPart command_class; + MenuButtonClassPart menuButton_class; } MenuButtonClassRec; extern MenuButtonClassRec menuButtonClassRec; -/*************************************** - * - * Instance (widget) structure - * - **************************************/ - - /* New fields for the MenuButton widget record */ +/* New fields for the MenuButton widget */ typedef struct { - /* resources */ - String menu_name; - + /* resources */ + String menu_name; +#ifndef OLDXAW + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } MenuButtonPart; - /* Full widget declaration */ +/* widget declaration */ typedef struct _MenuButtonRec { CorePart core; SimplePart simple; @@ -95,5 +78,3 @@ typedef struct _MenuButtonRec { } MenuButtonRec; #endif /* _XawMenuButtonP_h */ - - diff --git a/include/X11/Xaw/MenuButton.h b/include/X11/Xaw/MenuButton.h index ebab47a..949dbc5 100644 --- a/include/X11/Xaw/MenuButton.h +++ b/include/X11/Xaw/MenuButton.h @@ -23,6 +23,7 @@ Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/MenuButton.h,v 1.6 2001/12/14 19:54:41 dawes Exp $ */ /*********************************************************************** * @@ -59,6 +60,7 @@ in this Software without prior written authorization from The Open Group. callback Callback Pointer NULL cursor Cursor Cursor None destroyCallback Callback Pointer NULL + displayList DisplayList XawDisplayList* NULL font Font XFontStruct* XtDefaultFont foreground Foreground Pixel XtDefaultForeground height Height Dimension text height diff --git a/include/X11/Xaw/MultiSink.h b/include/X11/Xaw/MultiSink.h index d010c31..c1d9e05 100644 --- a/include/X11/Xaw/MultiSink.h +++ b/include/X11/Xaw/MultiSink.h @@ -70,15 +70,14 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/MultiSink.h,v 1.6 2001/12/14 19:54:41 dawes Exp $ */ #ifndef _XawMultiSink_h #define _XawMultiSink_h -/*********************************************************************** - * +/* * MultiSink Object - * - ***********************************************************************/ + */ #include <X11/Xaw/TextSink.h> @@ -106,12 +105,9 @@ SOFTWARE. #endif /* Class record constants */ - extern WidgetClass multiSinkObjectClass; typedef struct _MultiSinkClassRec *MultiSinkObjectClass; typedef struct _MultiSinkRec *MultiSinkObject; - -#endif /* _XawMultiSrc_h */ -/* DON'T ADD STUFF AFTER THIS #endif */ +#endif /* _XawMultiSink_h */ diff --git a/include/X11/Xaw/MultiSinkP.h b/include/X11/Xaw/MultiSinkP.h index 3a4b38d..a84d53f 100644 --- a/include/X11/Xaw/MultiSinkP.h +++ b/include/X11/Xaw/MultiSinkP.h @@ -71,36 +71,25 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ - -/* - * multiSinkP.h - Private definitions for multiSink object - * - */ +/* $XFree86: xc/lib/Xaw/MultiSinkP.h,v 1.9 2001/12/14 19:54:41 dawes Exp $ */ #ifndef _XawMultiSinkP_h #define _XawMultiSinkP_h -/*********************************************************************** - * - * MultiSink Object Private Data - * - ***********************************************************************/ +#include <X11/Xfuncproto.h> +/* + * MultiSink Object Private Data + */ #include <X11/Xaw/TextSinkP.h> #include <X11/Xaw/MultiSink.h> -/************************************************************ - * - * New fields for the MultiSink object class record. - * - ************************************************************/ - +/* new fields for the MultiSink object class */ typedef struct _MultiSinkClassPart { - int foo; + XtPointer extension; } MultiSinkClassPart; /* Full class record declaration */ - typedef struct _MultiSinkClassRec { ObjectClassPart object_class; TextSinkClassPart text_sink_class; @@ -111,46 +100,42 @@ extern MultiSinkClassRec multiSinkClassRec; /* New fields for the MultiSink object record */ typedef struct { - /* public resources */ + /* resources */ Boolean echo; Boolean display_nonprinting; - /* private state */ + /* private */ GC normgc, invgc, xorgc; - Pixmap insertCursorOn; + XawTextPosition cursor_position; XawTextInsertState laststate; - short cursor_x, cursor_y; /* Cursor Location. */ - XFontSet fontset; /* font set to draw */ + short cursor_x, cursor_y; /* Cursor Location */ + XFontSet fontset; /* font set to draw */ +#ifndef OLDXAW + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } MultiSinkPart; -/**************************************************************** - * - * Full instance record declaration - * - ****************************************************************/ - +/* Full instance record declaration */ typedef struct _MultiSinkRec { ObjectPart object; TextSinkPart text_sink; MultiSinkPart multi_sink; } MultiSinkRec; - -/******************************************** - * +/* * Semi-private functions * for use by other Xaw modules only - * - *******************************************/ - -extern void _XawMultiSinkPosToXY( -#if NeedFunctionPrototypes - Widget /* w */, - XawTextPosition /* pos */, - Position * /* x */, - Position * /*y */ -#endif + */ +_XFUNCPROTOBEGIN + +void _XawMultiSinkPosToXY +( + Widget w, + XawTextPosition pos, + Position *x, + Position *y ); -#endif /* _XawMultiSinkP_h */ +_XFUNCPROTOEND +#endif /* _XawMultiSinkP_h */ diff --git a/include/X11/Xaw/MultiSrc.h b/include/X11/Xaw/MultiSrc.h index 9ac060d..90d38ed 100644 --- a/include/X11/Xaw/MultiSrc.h +++ b/include/X11/Xaw/MultiSrc.h @@ -49,6 +49,7 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/MultiSrc.h,v 1.7 2001/12/14 19:54:41 dawes Exp $ */ /* * This file was modified from AsciiSrc.h. @@ -60,13 +61,11 @@ in this Software without prior written authorization from The Open Group. #define _XawMultiSrc_h #include <X11/Xaw/TextSrc.h> -/*Xfuncproto.h included by Intrinsic.h*/ /* Resources: Name Class RepType Default Value ---- ----- ------- ------------- - callback Callback Callback (none) dataCompression DataCompression Boolean True length Length int (internal) pieceSize PieceSize int BUFSIZ @@ -76,24 +75,14 @@ in this Software without prior written authorization from The Open Group. */ -/* Class record constants */ - extern WidgetClass multiSrcObjectClass; typedef struct _MultiSrcClassRec *MultiSrcObjectClass; typedef struct _MultiSrcRec *MultiSrcObject; -/* - * Just to make people's lives a bit easier. - */ - #define MultiSourceObjectClass MultiSrcObjectClass #define MultiSourceObject MultiSrcObject -/* - * Resource Definitions. - */ - #define XtCDataCompression "DataCompression" #define XtCPieceSize "PieceSize" #define XtCType "Type" @@ -123,28 +112,22 @@ typedef struct _MultiSrcRec *MultiSrcObject; _XFUNCPROTOBEGIN +void XawMultiSourceFreeString +( + Widget w + ); -extern void XawMultiSourceFreeString( -#if NeedFunctionPrototypes - Widget /* w */ -#endif -); - -extern Boolean _XawMultiSave( -#if NeedFunctionPrototypes - Widget /* w */ -#endif -); - -extern Boolean _XawMultiSaveAsFile( -#if NeedFunctionPrototypes - Widget /* w */, - _Xconst char* /* name */ -#endif +Bool _XawMultiSave +( + Widget w ); +Bool _XawMultiSaveAsFile +( + Widget w, + _Xconst char *name + ); _XFUNCPROTOEND -#endif /* _XawMultiSrc_h - Don't add anything after this line. */ - +#endif /* _XawMultiSrc_h */ diff --git a/include/X11/Xaw/MultiSrcP.h b/include/X11/Xaw/MultiSrcP.h index 00426db..1931019 100644 --- a/include/X11/Xaw/MultiSrcP.h +++ b/include/X11/Xaw/MultiSrcP.h @@ -71,6 +71,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/MultiSrcP.h,v 1.9 2001/12/14 19:54:41 dawes Exp $ */ /* * MultiSrcP.h - Private Header for Multi Text Source. @@ -87,11 +88,6 @@ SOFTWARE. */ /* - * TextSrcP.h - Private definitions for MultiSrc object - * - */ - -/* * This file was changed from AsciiSrcP.h. * * By Li Yuhong, Sept. 18, 1990 @@ -100,15 +96,10 @@ SOFTWARE. #ifndef _XawMultiSrcP_h #define _XawMultiSrcP_h +#include <X11/Xfuncproto.h> #include <X11/Xaw/TextSrcP.h> #include <X11/Xaw/MultiSrc.h> -/************************************************************ - * - * Private declarations. - * - ************************************************************/ - #ifdef L_tmpnam #define TMPSIZ L_tmpnam #else @@ -119,27 +110,20 @@ SOFTWARE. #endif #endif -#define MAGIC_VALUE ((XawTextPosition) -1) /* Magic value. */ - -#define streq(a, b) ( strcmp((a), (b)) == 0 ) - typedef struct _MultiPiece { /* Piece of the text file of BUFSIZ allocated - characters. */ - wchar_t* text; /* The text in this buffer. */ - XawTextPosition used; /* The number of characters of this buffer - that have been used. */ - struct _MultiPiece *prev, *next; /* linked list pointers. */ + characters */ + wchar_t* text; /* The text in this buffer */ + XawTextPosition used; /* The number of characters of this buffer + that have been used */ + struct _MultiPiece *prev, *next; /* linked list pointers */ } MultiPiece; -/************************************************************ - * - * New fields for the MultiSrc object class record. - * - ************************************************************/ - -typedef struct _MultiSrcClassPart { char foo; } MultiSrcClassPart; +/* New fields for the MultiSrc object class */ +typedef struct _MultiSrcClassPart { + XtPointer extension; +} MultiSrcClassPart; -/* Full class record declaration */ +/* Full class record */ typedef struct _MultiSrcClassRec { ObjectClassPart object_class; TextSrcClassPart text_src_class; @@ -148,50 +132,51 @@ typedef struct _MultiSrcClassRec { extern MultiSrcClassRec multiSrcClassRec; -/* New fields for the MultiSrc object record */ - +/* New fields for the MultiSrc object */ typedef struct _MultiSrcPart { + /* resources */ + XIC ic; /* for X Input Method */ + XtPointer string; /* either the string, or the file name, depend- + ing upon the `type'. ALWAYS IN MB FORMAT */ + XawAsciiType type; /* either string or disk */ + XawTextPosition piece_size; /* Size of text buffer for each piece */ + Boolean data_compression; /* compress to minimum memory automatically + on save? */ +#ifdef OLDXAW + XtCallbackList callback; +#endif + Boolean use_string_in_place;/* Use the string passed in place */ + int multi_length; /* length field for multi string emulation */ - /* Resources. */ + /* private */ - XIC ic; /* for X Input Method. */ - XtPointer string; /* either the string, or the file name, depend- - ing upon the `type'. ALWAYS IN MB FORMAT. */ - XawAsciiType type; /* either string or disk. */ - XawTextPosition piece_size; /* Size of text buffer for each piece. */ - Boolean data_compression; /* compress to minimum memory automatically - on save? */ - XtCallbackList callback; /* A callback list to call when the source is - changed. */ - Boolean use_string_in_place; /* Use the string passed in place. */ - int multi_length; /* length field for multi string emulation. */ - -/* Private data. */ - - Boolean is_tempfile; /* Is this a temporary file? */ - Boolean changes; /* Has this file been edited? */ - Boolean allocated_string; /* Have I allocated the - string in multi_src->string? */ - XawTextPosition length; /* length of file - IN CHARACTERS, NOT BYTES. */ - MultiPiece * first_piece; /* first piece of the text. */ + Boolean is_tempfile; /* Is this a temporary file? */ +#ifdef OLDXAW + Boolean changes; +#endif + Boolean allocated_string; /* Have I allocated the + string in multi_src->string? */ + XawTextPosition length; /* length of file - IN CHARACTERS, NOT BYTES */ + MultiPiece *first_piece; /* first piece of the text */ +#ifndef OLDXAW + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } MultiSrcPart; -/**************************************************************** - * - * Full instance record declaration - * - ****************************************************************/ - +/* Full instance record */ typedef struct _MultiSrcRec { ObjectPart object; TextSrcPart text_src; MultiSrcPart multi_src; } MultiSrcRec; -#if NeedFunctionPrototypes -extern void _XawMultiSourceFreeString( Widget ); -#else -extern void _XawMultiSourceFreeString(); -#endif +_XFUNCPROTOBEGIN + +void _XawMultiSourceFreeString +( + Widget w + ); + +_XFUNCPROTOEND -#endif /* _XawMultiSrcP_h --- Don't add anything after this line. */ +#endif /* _XawMultiSrcP_h */ diff --git a/include/X11/Xaw/Paned.h b/include/X11/Xaw/Paned.h index 1f6c29e..3e4b050 100644 --- a/include/X11/Xaw/Paned.h +++ b/include/X11/Xaw/Paned.h @@ -49,6 +49,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/Paned.h,v 1.7 2001/12/14 19:54:41 dawes Exp $ */ /* * Paned.h - Paned Composite Widget's public header file. @@ -68,12 +69,6 @@ SOFTWARE. #include <X11/Intrinsic.h> #include <X11/Xmu/Converters.h> -/**************************************************************** - * - * Vertical Paned Widget (SubClass of CompositeClass) - * - ****************************************************************/ - /* RESOURCES: Name Class RepType Default Value @@ -117,7 +112,7 @@ CONSTRAINT RESOURCES: allowResize Boolean Boolean False max Max Dimension unlimited min Min Dimension Grip Size - preferredPaneSize PerferredPaneSize Dimension PANED_ASK_CHILD + preferredPaneSize PreferredPaneSize Dimension PANED_ASK_CHILD resizeToPreferred Boolean Boolean False showGrip ShowGrip Boolean True skipAdjust Boolean Boolean False @@ -127,7 +122,6 @@ CONSTRAINT RESOURCES: #define PANED_ASK_CHILD 0 #define PANED_GRIP_SIZE 0 -/* New Fields */ #define XtNallowResize "allowResize" #define XtNbetweenCursor "betweenCursor" #define XtNverticalBetweenCursor "verticalBetweenCursor" @@ -163,92 +157,107 @@ extern WidgetClass panedWidgetClass; typedef struct _PanedClassRec *PanedWidgetClass; typedef struct _PanedRec *PanedWidget; -/************************************************************ - * +/* * Public Procedures - * - ************************************************************/ + */ _XFUNCPROTOBEGIN -/* Function Name: XawPanedSetMinMax - * Description: Sets the min and max size for a pane. - * Arguments: widget - the widget that is a child of the Paned widget. - * min, max - the new min and max size for the pane. - * Returns: none. +/* + * Function: + * XawPanedSetMinMax + * + * Parameters: + * widget - widget that is a child of the Paned widget + * min - new min and max size for the pane + * max - "" + * + * Description: + * Sets the min and max size for a pane. */ +void XawPanedSetMinMax +( + Widget w, + int min, + int max + ); -extern void XawPanedSetMinMax( -#if NeedFunctionPrototypes - Widget /* w */, - int /* min */, - int /* max */ -#endif -); - -/* Function Name: XawPanedGetMinMax - * Description: Gets the min and max size for a pane. - * Arguments: widget - the widget that is a child of the Paned widget. - ** RETURNED ** min, max - the current min and max size for the pane. - * Returns: none. +/* + * Function: + * XawPanedGetMinMax + * + * Parameters: + * widget - widget that is a child of the Paned widget + * min - return the current min and max size for the pane + * max - "" + * + * Description: + * Gets the min and max size for a pane. */ +void XawPanedGetMinMax +( + Widget w, + int *min_return, + int *max_return + ); -extern void XawPanedGetMinMax( -#if NeedFunctionPrototypes - Widget /* w */, - int * /* min_return */, - int * /* max_return */ -#endif -); - -/* Function Name: XawPanedSetRefigureMode - * Description: Allows a flag to be set the will inhibit - * the paned widgets relayout routine. - * Arguments: w - the paned widget. - * mode - if FALSE then inhibit refigure. - * Returns: none. +/* + * Function: + * XawPanedSetRefigureMode + * + * Parameters: + * w - paned widget + * mode - if False then inhibit refigure + * + * Description: + * Allows a flag to be set the will inhibit the paned widgets + * relayout routine. */ - -extern void XawPanedSetRefigureMode( -#if NeedFunctionPrototypes - Widget /* w */, +void XawPanedSetRefigureMode +( + Widget w, #if NeedWidePrototypes - /* Boolean */ int /* mode */ + int mode #else - Boolean /* mode */ + Boolean mode #endif -#endif -); + ); -/* Function Name: XawPanedGetNumSub - * Description: Returns the number of panes in the paned widget. - * Arguments: w - the paned widget. - * Returns: the number of panes in the paned widget. +/* + * Function: + * XawPanedGetNumSub + * + * Parameters: + * w - paned widget + * + * Returns: + * Number of panes in the paned widget. */ +int XawPanedGetNumSub +( + Widget w + ); -extern int XawPanedGetNumSub( -#if NeedFunctionPrototypes - Widget /* w */ -#endif -); - -/* Function Name: XawPanedAllowResize - * Description: Allows a flag to be set that determines if the paned - * widget will allow geometry requests from this child - * Arguments: widget - a child of the paned widget. - * Returns: none. +/* + * Function: + * XawPanedAllowResize + * + * Parameters: + * widget - child of the paned widget + * + * Description: + * Allows a flag to be set that determines if the paned widget will + * allow geometry requests from this child */ - -extern void XawPanedAllowResize( -#if NeedFunctionPrototypes - Widget /* w */, +void XawPanedAllowResize +( + Widget w, #if NeedWidePrototypes - /* Boolean */ int /* allow_resize */ + int allow_resize #else - Boolean /* allow_resize */ -#endif + Boolean allow_resize #endif -); + ); _XFUNCPROTOEND diff --git a/include/X11/Xaw/PanedP.h b/include/X11/Xaw/PanedP.h index 32b909f..863d2a2 100644 --- a/include/X11/Xaw/PanedP.h +++ b/include/X11/Xaw/PanedP.h @@ -47,10 +47,9 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/PanedP.h,v 1.8 2001/12/14 19:54:41 dawes Exp $ */ /* - * PanedP.h - Paned Composite Widget's private header file. - * * Updated and significantly modified from the Athena VPaned Widget. * * Date: March 1, 1989 @@ -65,16 +64,9 @@ SOFTWARE. #include <X11/Xaw/Paned.h> -/********************************************************************* - * - * Paned Widget Private Data - * - *********************************************************************/ - /* New fields for the Paned widget class record */ - typedef struct _PanedClassPart { - int foo; /* keep compiler happy. */ + XtPointer extension; } PanedClassPart; /* Full Class record declaration */ @@ -82,38 +74,37 @@ typedef struct _PanedClassRec { CoreClassPart core_class; CompositeClassPart composite_class; ConstraintClassPart constraint_class; - PanedClassPart paned_class; + PanedClassPart paned_class; } PanedClassRec; extern PanedClassRec panedClassRec; /* Paned constraint record */ typedef struct _PanedConstraintsPart { - /* Resources. */ + /* Resources */ Dimension min; /* Minimum height */ Dimension max; /* Maximum height */ - Boolean allow_resize; /* TRUE iff child resize requests are ok */ - Boolean show_grip; /* TRUE iff child will have grip below it, - when it is not the bottom pane. */ - Boolean skip_adjust; /* TRUE iff child's height should not be */ - /* changed without explicit user action. */ + Boolean allow_resize; /* True if child resize requests are ok */ + Boolean show_grip; /* True if child will have grip below it, + when it is not the bottom pane */ + Boolean skip_adjust; /* True if child's height should not be + changed without explicit user action */ int position; /* position location in Paned (relative to other children) ** NIY ** */ Dimension preferred_size; /* The Preferred size of the pane. - Iff this is zero then ask child for size.*/ + If this is zero then ask child for size*/ Boolean resize_to_pref; /* resize this pane to its preferred size on a resize or change managed after - realize. */ + realize */ - /* Private state. */ + /* Private state */ Position delta; /* Desired Location */ - Position olddelta; /* The last value of dy. */ + Position olddelta; /* The last value of dy */ Boolean paned_adjusted_me; /* Has the vpaned adjusted this widget w/o user interaction to make things fit? */ Dimension wp_size; /* widget's preferred size */ - int size; /* the size the widget will actually get. */ + int size; /* the size the widget will actually get */ Widget grip; /* The grip for this child */ - } PanedConstraintsPart, *Pane; typedef struct _PanedConstraintsRec { @@ -121,14 +112,13 @@ typedef struct _PanedConstraintsRec { } PanedConstraintsRec, *PanedConstraints; /* - * The Pane Stack Structure. + * The Pane Stack Structure */ - typedef struct _PaneStack { - struct _PaneStack * next; /* The next element on the stack. */ - Pane pane; /* The pane in this element on the stack. */ - int start_size; /* The size of this element when it was pushed - onto the stack. */ + struct _PaneStack *next; /* The next element on the stack */ + Pane pane; /* The pane in this element on the stack */ + int start_size; /* The size of this element when it + was pushed onto the stack */ } PaneStack; /* New Fields for the Paned widget record */ @@ -139,9 +129,9 @@ typedef struct { Boolean refiguremode; /* Whether to refigure changes right now */ XtTranslations grip_translations; /* grip translation table */ - Pixel internal_bp; /* color of internal borders. */ - Dimension internal_bw; /* internal border width. */ - XtOrientation orientation; /* Orientation of paned widget. */ + Pixel internal_bp; /* color of internal borders */ + Dimension internal_bw; /* internal border width */ + XtOrientation orientation; /* Orientation of paned widget */ Cursor cursor; /* Cursor for paned window */ Cursor grip_cursor; /* inactive grip cursor */ @@ -151,42 +141,40 @@ typedef struct { Cursor v_adjust_this_cursor; /* active vert grip cursor: T */ Cursor h_adjust_this_cursor; /* active horiz grip cursor: T */ - /* vertical. */ + /* vertical */ Cursor adjust_upper_cursor; /* active grip cursor: U */ Cursor adjust_lower_cursor; /* active grip cursor: D */ - /* horizontal. */ - Cursor adjust_left_cursor; /* active grip cursor: U */ - Cursor adjust_right_cursor; /* active grip cursor: D */ + /* horizontal */ + Cursor adjust_left_cursor; /* active grip cursor: U */ + Cursor adjust_right_cursor; /* active grip cursor: D */ /* private */ Boolean recursively_called; /* for ChangeManaged */ Boolean resize_children_to_pref; /* override constrain resources and resize all children to - preferred size. */ + preferred size */ int start_loc; /* mouse origin when adjusting */ Widget whichadd; /* Which pane to add changes to */ Widget whichsub; /* Which pane to sub changes from */ GC normgc; /* GC to use when drawing borders */ GC invgc; /* GC to use when erasing borders */ - GC flipgc; /* GC to use when animating - borders */ + GC flipgc; /* GC to use when animating borders */ int num_panes; /* count of managed panes */ - PaneStack * stack; /* The pane stack for this widget.*/ + PaneStack *stack; /* The pane stack for this widget */ +#ifndef OLDXAW + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } PanedPart; -/************************************************************************** - * +/* * Full instance record declaration - * - **************************************************************************/ - + */ typedef struct _PanedRec { - CorePart core; + CorePart core; CompositePart composite; ConstraintPart constraint; - PanedPart paned; + PanedPart paned; } PanedRec; #endif /* _XawPanedP_h */ -/* DON'T ADD STUFF AFTER THIS #endif */ diff --git a/include/X11/Xaw/Panner.h b/include/X11/Xaw/Panner.h index 037b257..cc1ddf8 100644 --- a/include/X11/Xaw/Panner.h +++ b/include/X11/Xaw/Panner.h @@ -25,6 +25,7 @@ in this Software without prior written authorization from The Open Group. * * Author: Jim Fulton, MIT X Consortium */ +/* $XFree86: xc/lib/Xaw/Panner.h,v 1.6 2001/12/14 19:54:41 dawes Exp $ */ #ifndef _XawPanner_h #define _XawPanner_h @@ -36,9 +37,9 @@ in this Software without prior written authorization from The Open Group. * * Panner Widget (subclass of Simple) * - * This widget is used to represent navigation in a 2d coordinate system. + * This widget is used to represent navigation in a 2d coordinate system * - * Parameters: + * Resources: * * Name Class Type Default * ---- ----- ---- ------- @@ -64,7 +65,6 @@ in this Software without prior written authorization from The Open Group. * *****************************************************************************/ - /* new instance and class names */ #ifndef _XtStringDefs_h_ #define XtNresize "resize" #define XtCResize "Resize" @@ -99,7 +99,6 @@ in this Software without prior written authorization from The Open Group. #define XtNsliderHeight "sliderHeight" #define XtCSliderHeight "SliderHeight" - /* external declarations */ extern WidgetClass pannerWidgetClass; typedef struct _PannerClassRec *PannerWidgetClass; diff --git a/include/X11/Xaw/PannerP.h b/include/X11/Xaw/PannerP.h index a952b02..1d185f2 100644 --- a/include/X11/Xaw/PannerP.h +++ b/include/X11/Xaw/PannerP.h @@ -25,25 +25,29 @@ in this Software without prior written authorization from The Open Group. * * Author: Jim Fulton, MIT X Consortium */ +/* $XFree86: xc/lib/Xaw/PannerP.h,v 1.8 2001/12/14 19:54:41 dawes Exp $ */ #ifndef _XawPannerP_h #define _XawPannerP_h #include <X11/Xaw/Panner.h> -#include <X11/Xaw/SimpleP.h> /* parent */ +#include <X11/Xaw/SimpleP.h> -typedef struct { /* new fields in widget class */ - int dummy; +/* new fields in widget class */ +typedef struct { + XtPointer extension; } PannerClassPart; -typedef struct _PannerClassRec { /* Panner widget class */ +/* Panner widget class */ +typedef struct _PannerClassRec { CoreClassPart core_class; SimpleClassPart simple_class; PannerClassPart panner_class; } PannerClassRec; -typedef struct { /* new fields in widget */ - /* resources... */ +/* new fields in widget */ +typedef struct { + /* resources */ XtCallbackList report_callbacks; /* callback/Callback */ Boolean allow_off; /* allowOff/AllowOff */ Boolean resize_to_pref; /* resizeToPreferred/Boolean */ @@ -59,8 +63,9 @@ typedef struct { /* new fields in widget */ Dimension slider_width; /* sliderWidth/SliderWidth */ Dimension slider_height; /* sliderHeight/SliderHeight */ Dimension internal_border; /* internalBorderWidth/BorderWidth */ - String stipple_name; /* backgroundStipple/BackgroundStipple */ - /* private data... */ + String stipple_name; /* backgroundStipple/BackgroundStipple + */ + /* private */ GC slider_gc; /* background of slider */ GC shadow_gc; /* edge of slider and shadow */ GC xor_gc; /* for doing XOR tmp graphics */ @@ -78,6 +83,9 @@ typedef struct { /* new fields in widget */ Boolean shadow_valid; /* true if rects are valid */ XRectangle shadow_rects[2]; /* location of shadows */ Position last_x, last_y; /* previous location of knob */ +#ifndef OLDXAW + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } PannerPart; typedef struct _PannerRec { @@ -86,18 +94,15 @@ typedef struct _PannerRec { PannerPart panner; } PannerRec; -#define PANNER_HSCALE(pw,val) ((pw)->panner.haspect * ((double) (val))) -#define PANNER_VSCALE(pw,val) ((pw)->panner.vaspect * ((double) (val))) +#define PANNER_HSCALE(pw,val) ((pw)->panner.haspect * ((double)(val))) +#define PANNER_VSCALE(pw,val) ((pw)->panner.vaspect * ((double)(val))) #define PANNER_DSCALE(pw,val) (Dimension) \ - ((((unsigned long) (val)) * (unsigned long) pw->panner.default_scale) / 100L) -#define PANNER_DEFAULT_SCALE 8 /* percent */ +((((unsigned long)(val)) * (unsigned long)pw->panner.default_scale) / 100L) +#define PANNER_DEFAULT_SCALE 8 /* percent */ #define PANNER_OUTOFRANGE -30000 -/* - * external declarations - */ extern PannerClassRec pannerClassRec; #endif /* _XawPannerP_h */ diff --git a/include/X11/Xaw/Porthole.h b/include/X11/Xaw/Porthole.h index 0eb3419..774463d 100644 --- a/include/X11/Xaw/Porthole.h +++ b/include/X11/Xaw/Porthole.h @@ -25,6 +25,7 @@ in this Software without prior written authorization from The Open Group. * * Author: Jim Fulton, MIT X Consortium */ +/* $XFree86: xc/lib/Xaw/Porthole.h,v 1.6 2001/12/14 19:54:41 dawes Exp $ */ #ifndef _XawPorthole_h #define _XawPorthole_h @@ -55,8 +56,6 @@ in this Software without prior written authorization from The Open Group. * *****************************************************************************/ - /* external declarations */ - extern WidgetClass portholeWidgetClass; typedef struct _PortholeClassRec *PortholeWidgetClass; typedef struct _PortholeRec *PortholeWidget; diff --git a/include/X11/Xaw/PortholeP.h b/include/X11/Xaw/PortholeP.h index e5d6ba6..74524b9 100644 --- a/include/X11/Xaw/PortholeP.h +++ b/include/X11/Xaw/PortholeP.h @@ -25,27 +25,32 @@ in this Software without prior written authorization from The Open Group. * * Author: Jim Fulton, MIT X Consortium */ +/* $XFree86: xc/lib/Xaw/PortholeP.h,v 1.8 2001/12/14 19:54:41 dawes Exp $ */ #ifndef _XawPortholeP_h #define _XawPortholeP_h #include <X11/Xaw/Porthole.h> -typedef struct { /* new fields in widget class */ - int dummy; +/* new fields in widget class */ +typedef struct { + XtPointer extension; } PortholeClassPart; -typedef struct _PortholeClassRec { /* Porthole widget class */ +/* widget class */ +typedef struct _PortholeClassRec { CoreClassPart core_class; CompositeClassPart composite_class; PortholeClassPart porthole_class; } PortholeClassRec; - -typedef struct { /* new fields in widget */ - /* resources... */ +/* new fields in widget */ +typedef struct { + /* resources */ XtCallbackList report_callbacks; /* callback/Callback */ - /* private data... */ +#ifndef OLDXAW + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } PortholePart; typedef struct _PortholeRec { @@ -54,11 +59,6 @@ typedef struct _PortholeRec { PortholePart porthole; } PortholeRec; - -/* - * external declarations - */ extern PortholeClassRec portholeClassRec; - #endif /* _XawPortholeP_h */ diff --git a/include/X11/Xaw/Repeater.h b/include/X11/Xaw/Repeater.h index 49232cd..d548c3b 100644 --- a/include/X11/Xaw/Repeater.h +++ b/include/X11/Xaw/Repeater.h @@ -25,6 +25,7 @@ in this Software without prior written authorization from The Open Group. * * Author: Jim Fulton, MIT X Consortium */ +/* $XFree86: xc/lib/Xaw/Repeater.h,v 1.6 2001/12/14 19:54:42 dawes Exp $ */ #ifndef _XawRepeater_h #define _XawRepeater_h @@ -35,7 +36,7 @@ in this Software without prior written authorization from The Open Group. * * Repeater Widget (subclass of Command) * - * This widget is a push button that repeatedly fires when held down. + * This widget is a push button that repeatedly fires when held down * * Parameters: * @@ -52,7 +53,6 @@ in this Software without prior written authorization from The Open Group. * *****************************************************************************/ - /* new instance and class names */ #define XtNdecay "decay" #define XtCDecay "Decay" #define XtNinitialDelay "initialDelay" @@ -67,7 +67,6 @@ in this Software without prior written authorization from The Open Group. #define XtCStopCallback "StopCallback" - /* external declarations */ extern WidgetClass repeaterWidgetClass; typedef struct _RepeaterClassRec *RepeaterWidgetClass; diff --git a/include/X11/Xaw/RepeaterP.h b/include/X11/Xaw/RepeaterP.h index 0c82c4c..3336e23 100644 --- a/include/X11/Xaw/RepeaterP.h +++ b/include/X11/Xaw/RepeaterP.h @@ -25,6 +25,7 @@ in this Software without prior written authorization from The Open Group. * * Author: Jim Fulton, MIT X Consortium */ +/* $XFree86: xc/lib/Xaw/RepeaterP.h,v 1.8 2001/12/14 19:54:42 dawes Exp $ */ #ifndef _XawRepeaterP_h #define _XawRepeaterP_h @@ -32,11 +33,13 @@ in this Software without prior written authorization from The Open Group. #include <X11/Xaw/CommandP.h> #include <X11/Xaw/Repeater.h> -typedef struct { /* new fields in widget class */ - int dummy; +/* new fields in widget class */ +typedef struct { + XtPointer extension; } RepeaterClassPart; -typedef struct _RepeaterClassRec { /* Repeater widget class */ +/* repeater widget class */ +typedef struct _RepeaterClassRec { CoreClassPart core_class; SimpleClassPart simple_class; LabelClassPart label_class; @@ -44,8 +47,8 @@ typedef struct _RepeaterClassRec { /* Repeater widget class */ RepeaterClassPart repeater_class; } RepeaterClassRec; -typedef struct { /* new fields in widget */ - /* resources... */ +typedef struct { + /* resources */ int initial_delay; /* initialDelay/Delay */ int repeat_delay; /* repeatDelay/Delay */ int minimum_delay; /* minimumDelay/MinimumDelay */ @@ -53,9 +56,13 @@ typedef struct { /* new fields in widget */ Boolean flash; /* flash/Boolean */ XtCallbackList start_callbacks; /* startCallback/StartCallback */ XtCallbackList stop_callbacks; /* stopCallback/StopCallback */ - /* private data... */ + + /* private */ int next_delay; /* next amount for timer */ XtIntervalId timer; /* timer that will fire */ +#ifndef OLDXAW + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } RepeaterPart; typedef struct _RepeaterRec { @@ -66,14 +73,12 @@ typedef struct _RepeaterRec { RepeaterPart repeater; } RepeaterRec; -#define REP_DEF_DECAY 5 /* milliseconds */ -#define REP_DEF_INITIAL_DELAY 200 /* milliseconds */ -#define REP_DEF_MINIMUM_DELAY 10 /* milliseconds */ -#define REP_DEF_REPEAT_DELAY 50 /* milliseconds */ + /* milliseconds */ +#define REP_DEF_DECAY 5 +#define REP_DEF_INITIAL_DELAY 200 +#define REP_DEF_MINIMUM_DELAY 10 +#define REP_DEF_REPEAT_DELAY 50 -/* - * external declarations - */ extern RepeaterClassRec repeaterClassRec; #endif /* _XawRepeaterP_h */ diff --git a/include/X11/Xaw/Scrollbar.h b/include/X11/Xaw/Scrollbar.h index 877f81f..38ec481 100644 --- a/include/X11/Xaw/Scrollbar.h +++ b/include/X11/Xaw/Scrollbar.h @@ -47,15 +47,14 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/Scrollbar.h,v 1.7 2001/12/14 19:54:42 dawes Exp $ */ #ifndef _Scrollbar_h #define _Scrollbar_h -/**************************************************************** - * +/* * Scrollbar Widget - * - ****************************************************************/ + */ #include <X11/Xmu/Converters.h> #include <X11/Xfuncproto.h> @@ -107,10 +106,6 @@ SOFTWARE. */ -/* - * Most things we need are in StringDefs.h - */ - #define XtCMinimumThumb "MinimumThumb" #define XtCShown "Shown" #define XtCTopOfThumb "TopOfThumb" @@ -125,18 +120,17 @@ extern WidgetClass scrollbarWidgetClass; _XFUNCPROTOBEGIN -extern void XawScrollbarSetThumb( -#if NeedFunctionPrototypes - Widget /* scrollbar */, +void XawScrollbarSetThumb +( + Widget scrollbar, #if NeedWidePrototypes - /* float */ double /* top */, - /* float */ double /* shown */ + double top, + double shown #else - float /* top */, - float /* shown */ -#endif + float top, + float shown #endif -); + ); _XFUNCPROTOEND diff --git a/include/X11/Xaw/ScrollbarP.h b/include/X11/Xaw/ScrollbarP.h index 250afbb..ec0e15d 100644 --- a/include/X11/Xaw/ScrollbarP.h +++ b/include/X11/Xaw/ScrollbarP.h @@ -49,6 +49,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/ScrollbarP.h,v 1.8 2001/12/14 19:54:42 dawes Exp $ */ #ifndef _ScrollbarP_h #define _ScrollbarP_h @@ -57,32 +58,34 @@ SOFTWARE. #include <X11/Xaw/SimpleP.h> typedef struct { - /* public */ - Pixel foreground; /* thumb foreground color */ - XtOrientation orientation; /* horizontal or vertical */ + /* resources */ + Pixel foreground; /* thumb foreground color */ + XtOrientation orientation; /* horizontal or vertical */ XtCallbackList scrollProc; /* proportional scroll */ XtCallbackList thumbProc; /* jump (to position) scroll */ XtCallbackList jumpProc; /* same as thumbProc but pass data by ref */ - Pixmap thumb; /* thumb color */ - Cursor upCursor; /* scroll up cursor */ - Cursor downCursor; /* scroll down cursor */ - Cursor leftCursor; /* scroll left cursor */ - Cursor rightCursor; /* scroll right cursor */ - Cursor verCursor; /* scroll vertical cursor */ - Cursor horCursor; /* scroll horizontal cursor */ - float top; /* What percent is above the win's top */ - float shown; /* What percent is shown in the win */ - Dimension length; /* either height or width */ - Dimension thickness; /* either width or height */ - Dimension min_thumb; /* minium size for the thumb. */ + Pixmap thumb; /* thumb pixmap */ + Cursor upCursor; /* scroll up cursor */ + Cursor downCursor; /* scroll down cursor */ + Cursor leftCursor; /* scroll left cursor */ + Cursor rightCursor; /* scroll right cursor */ + Cursor verCursor; /* scroll vertical cursor */ + Cursor horCursor; /* scroll horizontal cursor */ + float top; + float shown; + Dimension length; /* either height or width */ + Dimension thickness; /* either width or height */ + Dimension min_thumb; /* minium size for the thumb */ /* private */ - Cursor inactiveCursor; /* The normal cursor for scrollbar */ - char direction; /* a scroll has started; which direction */ - GC gc; /* a (shared) gc */ - Position topLoc; /* Pixel that corresponds to top */ - Dimension shownLength; /* Num pixels corresponding to shown */ - + Cursor inactiveCursor; /* The normal cursor for scrollbar */ + char direction; /* a scroll has started; which direction */ + GC gc; /* a (shared) gc */ + Position topLoc; /* Pixel that corresponds to top */ + Dimension shownLength; /* Num pixels corresponding to shown */ +#ifndef OLDXAW + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } ScrollbarPart; typedef struct _ScrollbarRec { @@ -91,7 +94,9 @@ typedef struct _ScrollbarRec { ScrollbarPart scrollbar; } ScrollbarRec; -typedef struct {int empty;} ScrollbarClassPart; +typedef struct { + XtPointer extension; +} ScrollbarClassPart; typedef struct _ScrollbarClassRec { CoreClassPart core_class; diff --git a/include/X11/Xaw/Simple.h b/include/X11/Xaw/Simple.h index e50cccf..ffcd59b 100644 --- a/include/X11/Xaw/Simple.h +++ b/include/X11/Xaw/Simple.h @@ -46,18 +46,13 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/Simple.h,v 1.9 2001/12/14 19:54:42 dawes Exp $ */ #ifndef _Simple_h #define _Simple_h #include <X11/Xmu/Converters.h> -/**************************************************************** - * - * Simple widgets - * - ****************************************************************/ - /* Resources: Name Class RepType Default Value @@ -68,12 +63,14 @@ SOFTWARE. cursor Cursor Cursor None cursorName Cursor String NULL destroyCallback Callback Pointer NULL + displayList DisplayList XawDisplayList* NULL height Height Dimension 0 insensitiveBorder Insensitive Pixmap Gray mappedWhenManaged MappedWhenManaged Boolean True pointerColor Foreground Pixel XtDefaultForeground pointerColorBackground Background Pixel XtDefaultBackground sensitive Sensitive Boolean True + tip Tip String NULL width Width Dimension 0 x Position Position 0 y Position Position 0 @@ -94,6 +91,23 @@ SOFTWARE. #define XtNinternational "international" #endif +#ifndef OLDXAW +#ifndef XawNdisplayList +#define XawNdisplayList "displayList" +#endif + +#ifndef XawCDisplayList +#define XawCDisplayList "DisplayList" +#endif + +#ifndef XawRDisplayList +#define XawRDisplayList "XawDisplayList" +#endif + +#define XtNtip "tip" +#define XtCTip "Tip" +#endif /* OLDXAW */ + typedef struct _SimpleClassRec *SimpleWidgetClass; typedef struct _SimpleRec *SimpleWidget; diff --git a/include/X11/Xaw/SimpleMenP.h b/include/X11/Xaw/SimpleMenP.h index 6e6dc7d..d7c8d01 100644 --- a/include/X11/Xaw/SimpleMenP.h +++ b/include/X11/Xaw/SimpleMenP.h @@ -24,6 +24,7 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. * */ +/* $XFree86: xc/lib/Xaw/SimpleMenP.h,v 1.13 2001/12/14 19:54:42 dawes Exp $ */ /* * SimpleMenuP.h - Private Header file for SimpleMenu widget. @@ -41,58 +42,60 @@ in this Software without prior written authorization from The Open Group. #include <X11/Xaw/SimpleMenu.h> #include <X11/Xaw/SmeP.h> #include <X11/ShellP.h> +#include <X11/Xaw/XawInit.h> typedef struct { - XtPointer extension; /* For future needs. */ + XtPointer extension; /* For future needs */ } SimpleMenuClassPart; typedef struct _SimpleMenuClassRec { - CoreClassPart core_class; - CompositeClassPart composite_class; - ShellClassPart shell_class; - OverrideShellClassPart override_shell_class; - SimpleMenuClassPart simpleMenu_class; + CoreClassPart core_class; + CompositeClassPart composite_class; + ShellClassPart shell_class; + OverrideShellClassPart override_shell_class; + SimpleMenuClassPart simpleMenu_class; } SimpleMenuClassRec; extern SimpleMenuClassRec simpleMenuClassRec; typedef struct _SimpleMenuPart { - /* resources */ - - String label_string; /* The string for the label or NULL. */ - SmeObject label; /* If label_string is non-NULL then this is - the label widget. */ - WidgetClass label_class; /* Widget Class of the menu label object. */ - - Dimension top_margin; /* Top and bottom margins. */ - Dimension bottom_margin; - Dimension row_height; /* height of each row (menu entry) */ - - Cursor cursor; /* The menu's cursor. */ - SmeObject popup_entry; /* The entry to position the cursor on for - when using XawPositionSimpleMenu. */ - Boolean menu_on_screen; /* Force the menus to be fully on the screen.*/ - int backing_store; /* What type of backing store to use. */ - - /* private state */ - - Boolean recursive_set_values; /* contain a possible infinite loop. */ - - Boolean menu_width; /* If true then force width to remain + String label_string; /* The string for the label or NULL */ + SmeObject label; /* If label_string is non-NULL then this is + the label widget */ + WidgetClass label_class; /* Widget Class of the menu label object */ + Dimension top_margin; /* Top and bottom margins */ + Dimension bottom_margin; + Dimension row_height; /* height of each row (menu entry) */ + Cursor cursor; /* The menu's cursor */ + SmeObject popup_entry; /* The entry to position the cursor on for + when using XawPositionSimpleMenu */ + Boolean menu_on_screen; /* Force the menus to be fully on the screen*/ + int backing_store; /* What type of backing store to use */ + + /* private */ + Boolean recursive_set_values; /* contain a possible infinite loop */ + Boolean menu_width; /* If true then force width to remain core.width */ - Boolean menu_height; /* Just like menu_width, but for height. */ - - SmeObject entry_set; /* The entry that is currently set or - highlighted. */ + Boolean menu_height; /* Just like menu_width, but for height */ + SmeObject entry_set; /* The entry that is currently set or + highlighted */ +#ifndef OLDXAW + Dimension left_margin; + Dimension right_margin; + XawDisplayList *display_list; + Widget sub_menu; + unsigned char state; + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } SimpleMenuPart; typedef struct _SimpleMenuRec { - CorePart core; - CompositePart composite; - ShellPart shell; - OverrideShellPart override; - SimpleMenuPart simple_menu; + CorePart core; + CompositePart composite; + ShellPart shell; + OverrideShellPart override; + SimpleMenuPart simple_menu; } SimpleMenuRec; #endif /* _SimpleMenuP_h */ diff --git a/include/X11/Xaw/SimpleMenu.h b/include/X11/Xaw/SimpleMenu.h index 3a59fc1..8048a90 100644 --- a/include/X11/Xaw/SimpleMenu.h +++ b/include/X11/Xaw/SimpleMenu.h @@ -25,6 +25,7 @@ in this Software without prior written authorization from The Open Group. * * Author: Chris D. Peterson, MIT X Consortium */ +/* $XFree86: xc/lib/Xaw/SimpleMenu.h,v 1.8 2001/12/14 19:54:43 dawes Exp $ */ /* * SimpleMenu.h - Public Header file for SimpleMenu widget. @@ -49,13 +50,11 @@ in this Software without prior written authorization from The Open Group. #include <X11/Shell.h> #include <X11/Xmu/Converters.h> -/**************************************************************** - * +/* * SimpleMenu widget - * - ****************************************************************/ + */ -/* SimpleMenu Resources: +/* Resources: Name Class RepType Default Value ---- ----- ------- ------------- @@ -68,15 +67,18 @@ in this Software without prior written authorization from The Open Group. columnWidth ColumnWidth Dimension Width of widest text cursor Cursor Cursor None destroyCallback Callback Pointer NULL + displayList DisplayList XawDisplayList* NULL height Height Dimension 0 label Label String NULL (No label) labelClass LabelClass Pointer smeBSBObjectClass + leftMargin HorizontalMargins Dimension 0 mappedWhenManaged MappedWhenManaged Boolean True + rightMargin HorizontalMargins Dimension 0 rowHeight RowHeight Dimension Height of Font sensitive Sensitive Boolean True topMargin VerticalMargins Dimension VerticalSpace width Width Dimension 0 - x Position Position 0n + x Position Position 0 y Position Position 0 */ @@ -94,56 +96,76 @@ extern WidgetClass simpleMenuWidgetClass; #define XtNpopupOnEntry "popupOnEntry" #define XtNrowHeight "rowHeight" #define XtNtopMargin "topMargin" +#define XtNleftMargin "leftMargin" +#define XtNrightMargin "rightMargin" #define XtCColumnWidth "ColumnWidth" #define XtCLabelClass "LabelClass" #define XtCMenuOnScreen "MenuOnScreen" #define XtCPopupOnEntry "PopupOnEntry" #define XtCRowHeight "RowHeight" + #define XtCVerticalMargins "VerticalMargins" -/************************************************************ - * - * Public Functions. - * - ************************************************************/ +#ifndef OLDXAW +#define XtCHorizontalMargins "HorizontalMargins" +#define XawNdisplayList "displayList" +#define XawCDisplayList "DisplayList" +#define XawRDisplayList "XawDisplayList" +#endif + +/* + * Public Functions + */ _XFUNCPROTOBEGIN -/* Function Name: XawSimpleMenuAddGlobalActions - * Description: adds the global actions to the simple menu widget. - * Arguments: app_con - the appcontext. - * Returns: none. +/* + * Function: + * XawSimpleMenuAddGlobalActions + * + * Parameters: + * app_con - appcontext + * + * Description: + * Adds the global actions to the simple menu widget. */ +void XawSimpleMenuAddGlobalActions +( + XtAppContext app_con + ); -extern void XawSimpleMenuAddGlobalActions( -#if NeedFunctionPrototypes - XtAppContext /* app_con */ -#endif -); - -/* Function Name: XawSimpleMenuGetActiveEntry - * Description: Gets the currently active (set) entry. - * Arguments: w - the smw widget. - * Returns: the currently set entry or NULL if none is set. +/* + * Function: + * XawSimpleMenuGetActiveEntry + * + * Parameters: + * w - smw widget + * + * Description: + * Gets the currently active (set) entry. + * + * Returns: + * The currently set entry or NULL if none is set */ +Widget XawSimpleMenuGetActiveEntry +( + Widget w + ); -extern Widget XawSimpleMenuGetActiveEntry( -#if NeedFunctionPrototypes - Widget /* w */ -#endif -); - -/* Function Name: XawSimpleMenuClearActiveEntry - * Description: Unsets the currently active (set) entry. - * Arguments: w - the smw widget. - * Returns: none. +/* + * Function: + * XawSimpleMenuClearActiveEntry + * + * Parameters: + * w - smw widget + * + * Description: + * Unsets the currently active (set) entry. */ - -extern void XawSimpleMenuClearActiveEntry( -#if NeedFunctionPrototypes - Widget /* w */ -#endif +void XawSimpleMenuClearActiveEntry +( + Widget w ); _XFUNCPROTOEND diff --git a/include/X11/Xaw/SimpleP.h b/include/X11/Xaw/SimpleP.h index d052629..d48cd13 100644 --- a/include/X11/Xaw/SimpleP.h +++ b/include/X11/Xaw/SimpleP.h @@ -47,17 +47,27 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/SimpleP.h,v 1.13 2001/12/19 21:37:31 dawes Exp $ */ #ifndef _SimpleP_h #define _SimpleP_h +#include <X11/Xfuncproto.h> + #include <X11/Xaw/Simple.h> +_XFUNCPROTOBEGIN + +#include <X11/Xaw/XawInit.h> + typedef struct { - Boolean (*change_sensitive)(/* widget */); + Bool (*change_sensitive)(Widget); +#ifndef OLDXAW + XtPointer extension; +#endif } SimpleClassPart; -#define XtInheritChangeSensitive ((Boolean (*)())_XtInherit) +#define XtInheritChangeSensitive ((Bool (*)(Widget))_XtInherit) typedef struct _SimpleClassRec { CoreClassPart core_class; @@ -68,13 +78,18 @@ extern SimpleClassRec simpleClassRec; typedef struct { /* resources */ - Cursor cursor; - Pixmap insensitive_border; - String cursor_name; /* cursor specified by name. */ - - Pixel pointer_fg, pointer_bg; /* Pointer colors. */ - Boolean international; - /* private state */ + Cursor cursor; + Pixmap insensitive_border; + String cursor_name; /* cursor specified by name */ + Pixel pointer_fg, pointer_bg; /* Pointer colors */ + Boolean international; + + /* private */ +#ifndef OLDXAW + XawDisplayList *display_list; + String tip; + XtPointer pad[3]; /* for future use and keep binary compatability */ +#endif } SimplePart; typedef struct _SimpleRec { @@ -82,4 +97,6 @@ typedef struct _SimpleRec { SimplePart simple; } SimpleRec; +_XFUNCPROTOEND + #endif /* _SimpleP_h */ diff --git a/include/X11/Xaw/Sme.h b/include/X11/Xaw/Sme.h index 8315aa1..dc9a565 100644 --- a/include/X11/Xaw/Sme.h +++ b/include/X11/Xaw/Sme.h @@ -23,10 +23,9 @@ Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/Sme.h,v 1.6 2001/12/14 19:54:43 dawes Exp $ */ /* - * Sme.h - Public Header file for Sme object. - * * This is the public header file for the Athena Sme object. * It is intended to be used with the simple menu widget. * @@ -43,13 +42,7 @@ in this Software without prior written authorization from The Open Group. #include <X11/Intrinsic.h> #include <X11/RectObj.h> -/**************************************************************** - * - * Sme Object - * - ****************************************************************/ - -/* Simple Menu Entry Resources: +/* Resources: Name Class RepType Default Value ---- ----- ------- ------------- @@ -58,7 +51,7 @@ in this Software without prior written authorization from The Open Group. height Height Dimension 0 sensitive Sensitive Boolean True width Width Dimension 0 - x Position Position 0n + x Position Position 0 y Position Position 0 */ @@ -72,8 +65,8 @@ in this Software without prior written authorization from The Open Group. #endif -typedef struct _SmeClassRec* SmeObjectClass; -typedef struct _SmeRec* SmeObject; +typedef struct _SmeClassRec *SmeObjectClass; +typedef struct _SmeRec *SmeObject; extern WidgetClass smeObjectClass; diff --git a/include/X11/Xaw/SmeBSB.h b/include/X11/Xaw/SmeBSB.h index 0a7bc40..d337755 100644 --- a/include/X11/Xaw/SmeBSB.h +++ b/include/X11/Xaw/SmeBSB.h @@ -23,6 +23,7 @@ Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/SmeBSB.h,v 1.7 2001/12/14 19:54:43 dawes Exp $ */ /* * SmeBSB.h - Public Header file for SmeBSB object. @@ -42,15 +43,8 @@ in this Software without prior written authorization from The Open Group. #define _SmeBSB_h #include <X11/Xmu/Converters.h> - #include <X11/Xaw/Sme.h> -/**************************************************************** - * - * SmeBSB object - * - ****************************************************************/ - /* BSB Menu Entry Resources: Name Class RepType Default Value @@ -63,12 +57,13 @@ in this Software without prior written authorization from The Open Group. label Label String Name of entry leftBitmap LeftBitmap Pixmap None leftMargin HorizontalMargins Dimension 4 + menuName MenuName String NULL rightBitmap RightBitmap Pixmap None rightMargin HorizontalMargins Dimension 4 sensitive Sensitive Boolean True vertSpace VertSpace int 25 width Width Dimension 0 - x Position Position 0n + x Position Position 0 y Position Position 0 */ @@ -84,6 +79,9 @@ extern WidgetClass smeBSBObjectClass; #define XtNrightMargin "rightMargin" #define XtNvertSpace "vertSpace" +#define XtNmenuName "menuName" +#define XtCMenuName "MenuName" + #ifndef XtNfontSet #define XtNfontSet "fontSet" #endif diff --git a/include/X11/Xaw/SmeBSBP.h b/include/X11/Xaw/SmeBSBP.h index c3521eb..bc3a65a 100644 --- a/include/X11/Xaw/SmeBSBP.h +++ b/include/X11/Xaw/SmeBSBP.h @@ -25,32 +25,19 @@ in this Software without prior written authorization from The Open Group. * * Author: Chris D. Peterson, MIT X Consortium */ - -/* - * SmeP.h - Private definitions for Sme object - * - */ +/* $XFree86: xc/lib/Xaw/SmeBSBP.h,v 1.9 2001/12/14 19:54:43 dawes Exp $ */ #ifndef _XawSmeBSBP_h #define _XawSmeBSBP_h -/*********************************************************************** - * +/* * Sme Object Private Data - * - ***********************************************************************/ - + */ #include <X11/Xaw/SmeP.h> #include <X11/Xaw/SmeBSB.h> -/************************************************************ - * - * New fields for the Sme Object class record. - * - ************************************************************/ - typedef struct _SmeBSBClassPart { - XtPointer extension; + XtPointer extension; } SmeBSBClassPart; /* Full class record declaration */ @@ -65,48 +52,43 @@ extern SmeBSBClassRec smeBSBClassRec; /* New fields for the Sme Object record */ typedef struct { /* resources */ - String label; /* The entry label. */ - int vert_space; /* extra vert space to leave, as a percentage - of the font height of the label. */ - Pixmap left_bitmap, right_bitmap; /* bitmaps to show. */ - Dimension left_margin, right_margin; /* left and right margins. */ - Pixel foreground; /* foreground color. */ - XFontStruct * font; /* The font to show label in. */ - XFontSet fontset; /* or fontset*/ - XtJustify justify; /* Justification for the label. */ - -/* private resources. */ - - Boolean set_values_area_cleared; /* Remember if we need to unhighlight. */ - GC norm_gc; /* noral color gc. */ - GC rev_gc; /* reverse color gc. */ - GC norm_gray_gc; /* Normal color (grayed out) gc. */ - GC invert_gc; /* gc for flipping colors. */ - - Dimension left_bitmap_width; /* size of each bitmap. */ + String label; /* The entry label */ + int vert_space; /* extra vert space to leave, as a + percentage of the font height of + the label */ + Pixmap left_bitmap, right_bitmap; /* bitmaps to show */ + Dimension left_margin, right_margin;/* left and right margins */ + Pixel foreground; /* foreground color */ + XFontStruct *font; /* The font to show label in */ + XFontSet fontset; /* or fontset */ + XtJustify justify; /* Justification for the label. */ + + /* private */ + Boolean set_values_area_cleared; /* do we need to unhighlight? */ + GC norm_gc; /* noral color gc */ + GC rev_gc; /* reverse color gc */ + GC norm_gray_gc; /* Normal color (grayed out) gc */ + GC invert_gc; /* gc for flipping colors */ + Dimension left_bitmap_width; /* size of each bitmap */ Dimension left_bitmap_height; Dimension right_bitmap_width; Dimension right_bitmap_height; +#ifndef OLDXAW + /* new resources */ + String menu_name; /* name of nested sub menu or NULL */ + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } SmeBSBPart; -/**************************************************************** - * +/* * Full instance record declaration - * - ****************************************************************/ - + */ typedef struct _SmeBSBRec { - ObjectPart object; - RectObjPart rectangle; - SmePart sme; - SmeBSBPart sme_bsb; + ObjectPart object; + RectObjPart rectangle; + SmePart sme; + SmeBSBPart sme_bsb; } SmeBSBRec; -/************************************************************ - * - * Private declarations. - * - ************************************************************/ - #endif /* _XawSmeBSBP_h */ diff --git a/include/X11/Xaw/SmeLine.h b/include/X11/Xaw/SmeLine.h index bd529f3..e5d09d3 100644 --- a/include/X11/Xaw/SmeLine.h +++ b/include/X11/Xaw/SmeLine.h @@ -24,10 +24,9 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. * */ +/* $XFree86: xc/lib/Xaw/SmeLine.h,v 1.6 2001/12/14 19:54:43 dawes Exp $ */ /* - * SmeLine.h - Public Header file for SmeLine object. - * * This is the public header file for the Athena SmeLine object. * It is intended to be used with the simple menu widget. * @@ -44,13 +43,7 @@ in this Software without prior written authorization from The Open Group. #include <X11/Xaw/Sme.h> #include <X11/Xmu/Converters.h> -/**************************************************************** - * - * SmeLine Object - * - ****************************************************************/ - -/* Menu Entry Resources: +/* Resources: Name Class RepType Default Value ---- ----- ------- ------------- @@ -59,7 +52,7 @@ in this Software without prior written authorization from The Open Group. height Height Dimension 0 sensitive Sensitive Boolean True width Width Dimension 0 - x Position Position 0n + x Position Position 0 y Position Position 0 */ @@ -70,8 +63,8 @@ in this Software without prior written authorization from The Open Group. #define XtNlineWidth "lineWidth" #define XtNstipple "stipple" -typedef struct _SmeLineClassRec* SmeLineObjectClass; -typedef struct _SmeLineRec* SmeLineObject; +typedef struct _SmeLineClassRec *SmeLineObjectClass; +typedef struct _SmeLineRec *SmeLineObject; extern WidgetClass smeLineObjectClass; diff --git a/include/X11/Xaw/SmeLineP.h b/include/X11/Xaw/SmeLineP.h index 32831f7..07f12a7 100644 --- a/include/X11/Xaw/SmeLineP.h +++ b/include/X11/Xaw/SmeLineP.h @@ -25,35 +25,23 @@ in this Software without prior written authorization from The Open Group. * * Author: Chris D. Peterson, MIT X Consortium */ - -/* - * SmeLineP.h - Private definitions for SmeLine widget - * - */ +/* $XFree86: xc/lib/Xaw/SmeLineP.h,v 1.8 2001/12/14 19:54:43 dawes Exp $ */ #ifndef _XawSmeLineP_h #define _XawSmeLineP_h -/*********************************************************************** - * +/* * SmeLine Widget Private Data - * - ***********************************************************************/ - + */ #include <X11/Xaw/SmeP.h> #include <X11/Xaw/SmeLine.h> -/************************************************************ - * - * New fields for the SmeLine widget class record. - * - ************************************************************/ - +/* New fields for the SmeLine widget class */ typedef struct _SmeLineClassPart { - XtPointer extension; + XtPointer extension; } SmeLineClassPart; -/* Full class record declaration */ +/* Full class record */ typedef struct _SmeLineClassRec { RectObjClassPart rect_class; SmeClassPart sme_class; @@ -62,35 +50,26 @@ typedef struct _SmeLineClassRec { extern SmeLineClassRec smeLineClassRec; -/* New fields for the SmeLine widget record */ +/* New fields for the SmeLine widget */ typedef struct { /* resources */ - Pixel foreground; /* Foreground color. */ - Pixmap stipple; /* Line Stipple. */ - Dimension line_width; /* Width of the line. */ - - /* private data. */ - - GC gc; /* Graphics context for drawing line. */ + Pixel foreground; /* Foreground color */ + Pixmap stipple; /* Line Stipple */ + Dimension line_width; /* Width of the line */ + + /* private */ + GC gc; /* Graphics context for drawing line */ +#ifndef OLDXAW + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } SmeLinePart; -/**************************************************************** - * - * Full instance record declaration - * - ****************************************************************/ - +/* Full instance record */ typedef struct _SmeLineRec { - ObjectPart object; - RectObjPart rectangle; - SmePart sme; - SmeLinePart sme_line; + ObjectPart object; + RectObjPart rectangle; + SmePart sme; + SmeLinePart sme_line; } SmeLineRec; -/************************************************************ - * - * Private declarations. - * - ************************************************************/ - #endif /* _XawSmeLineP_h */ diff --git a/include/X11/Xaw/SmeP.h b/include/X11/Xaw/SmeP.h index 9a5d9fd..02b8018 100644 --- a/include/X11/Xaw/SmeP.h +++ b/include/X11/Xaw/SmeP.h @@ -23,10 +23,9 @@ Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/SmeP.h,v 1.9 2001/12/19 21:37:31 dawes Exp $ */ /* - * SmeP.h - Private Header file for Sme object. - * * This is the private header file for the Athena Sme object. * This object is intended to be used with the simple menu widget. * @@ -40,28 +39,24 @@ in this Software without prior written authorization from The Open Group. #ifndef _XawSmeP_h #define _XawSmeP_h -/*********************************************************************** - * +/* * Sme Widget Private Data - * - ***********************************************************************/ + */ +#include <X11/Xfuncproto.h> #include <X11/Xaw/Sme.h> -/************************************************************ - * - * New fields for the Sme widget class record. - * - ************************************************************/ +_XFUNCPROTOBEGIN +/* New fields for the Sme widget class */ typedef struct _SmeClassPart { - void (*highlight)(); - void (*unhighlight)(); - void (*notify)(); - XtPointer extension; + XtWidgetProc highlight; + XtWidgetProc unhighlight; + XtWidgetProc notify; + XtPointer extension; } SmeClassPart; -/* Full class record declaration */ +/* Full class record */ typedef struct _SmeClassRec { RectObjClassPart rect_class; SmeClassPart sme_class; @@ -69,36 +64,27 @@ typedef struct _SmeClassRec { extern SmeClassRec smeClassRec; -/* New fields for the Sme widget record */ +/* New fields for the Sme widget */ typedef struct { /* resources */ - XtCallbackList callbacks; /* The callback list */ - Boolean international; - + XtCallbackList callbacks; + Boolean international; +#ifndef OLDXAW + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } SmePart; -/**************************************************************** - * - * Full instance record declaration - * - ****************************************************************/ - +/* Full instance record */ typedef struct _SmeRec { - ObjectPart object; - RectObjPart rectangle; - SmePart sme; + ObjectPart object; + RectObjPart rectangle; + SmePart sme; } SmeRec; -/************************************************************ - * - * Private declarations. - * - ************************************************************/ - -typedef void (*_XawEntryVoidFunc)(); - -#define XtInheritHighlight ((_XawEntryVoidFunc) _XtInherit) +#define XtInheritHighlight ((XtWidgetProc)_XtInherit) #define XtInheritUnhighlight XtInheritHighlight #define XtInheritNotify XtInheritHighlight +_XFUNCPROTOEND + #endif /* _XawSmeP_h */ diff --git a/include/X11/Xaw/StripCharP.h b/include/X11/Xaw/StripCharP.h index 19584cf..062b744 100644 --- a/include/X11/Xaw/StripCharP.h +++ b/include/X11/Xaw/StripCharP.h @@ -49,6 +49,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/StripCharP.h,v 1.8 2001/12/14 19:54:43 dawes Exp $ */ #ifndef _XawStripChartP_h #define _XawStripChartP_h @@ -57,50 +58,53 @@ SOFTWARE. #include <X11/Xaw/SimpleP.h> #define NO_GCS 0 -#define FOREGROUND 1 << 0 -#define HIGHLIGHT 1 << 1 +#define FOREGROUND (1 << 0) +#define HIGHLIGHT (1 << 1) #define ALL_GCS (FOREGROUND | HIGHLIGHT) -/* New fields for the stripChart widget instance record */ - +/* new fields for the stripChart widget */ typedef struct { - Pixel fgpixel; /* color index for graph */ - Pixel hipixel; /* color index for lines */ - GC fgGC; /* graphics context for fgpixel */ - GC hiGC; /* graphics context for hipixel */ - - /* start of graph stuff */ + /* resources */ + Pixel fgpixel; /* color index for graph */ + Pixel hipixel; /* color index for lines */ + GC fgGC; /* graphics context for fgpixel */ + GC hiGC; /* graphics context for hipixel */ - int update; /* update frequence */ - int scale; /* scale factor */ - int min_scale; /* smallest scale factor */ - int interval; /* data point interval */ - XPoint * points ; /* Poly point for repairing graph lines. */ - double max_value; /* Max Value in window */ - double valuedata[2048];/* record of data points */ + /* private */ + int update; /* update frequence */ + int scale; /* scale factor */ + int min_scale; /* smallest scale factor */ + int interval; /* data point interval */ + XPoint *points; /* Poly point for repairing graph lines */ + double max_value; /* Max Value in window */ + double valuedata[2048]; /* record of data points */ XtIntervalId interval_id; - XtCallbackList get_value; /* proc to call to fetch load pt */ - int jump_val; /* Amount to jump on each scroll. */ + XtCallbackList get_value; /* proc to call to fetch load pt */ + int jump_val; /* Amount to jump on each scroll */ +#ifndef OLDXAW + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } StripChartPart; -/* Full instance record declaration */ +/* instance record declaration */ typedef struct _StripChartRec { - CorePart core; - SimplePart simple; - StripChartPart strip_chart; + CorePart core; + SimplePart simple; + StripChartPart strip_chart; } StripChartRec; -/* New fields for the StripChart widget class record */ -typedef struct {int dummy;} StripChartClassPart; +/* new fields for the StripChart widget class record */ +typedef struct { + XtPointer extension; +} StripChartClassPart; -/* Full class record declaration. */ +/* class record declaration */ typedef struct _StripChartClassRec { - CoreClassPart core_class; - SimpleClassPart simple_class; - StripChartClassPart strip_chart_class; + CoreClassPart core_class; + SimpleClassPart simple_class; + StripChartClassPart strip_chart_class; } StripChartClassRec; -/* Class pointer. */ extern StripChartClassRec stripChartClassRec; #endif /* _XawStripChartP_h */ diff --git a/include/X11/Xaw/StripChart.h b/include/X11/Xaw/StripChart.h index 325a6db..b6c2f0f 100644 --- a/include/X11/Xaw/StripChart.h +++ b/include/X11/Xaw/StripChart.h @@ -46,6 +46,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/StripChart.h,v 1.6 2001/12/14 19:54:44 dawes Exp $ */ #ifndef _XawStripChart_h #define _XawStripChart_h @@ -116,4 +117,3 @@ typedef struct _StripChartClassRec *StripChartWidgetClass; extern WidgetClass stripChartWidgetClass; #endif /* _XawStripChart_h */ -/* DON'T ADD STUFF AFTER THIS #endif */ diff --git a/include/X11/Xaw/Template.c b/include/X11/Xaw/Template.c index 8f9ba8b..17180d6 100644 --- a/include/X11/Xaw/Template.c +++ b/include/X11/Xaw/Template.c @@ -25,69 +25,171 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/Template.c,v 1.9 2001/12/14 19:54:44 dawes Exp $ */ #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> -#include "TemplateP.h" +#include <X11/Xaw/TemplateP.h> -static XtResource resources[] = { +/* + * Class Methods + */ +static void TemplateInitialize(Widget, Widget, ArgList, Cardinal*); + +/* + * Prototypes + */ +static Bool TemplateFunction(TemplateWidget, int, int, Bool); + +/* + * Actions + */ +static void TemplateAction(Widget, XEvent*, String*, Cardinal*); + +/* + * Initialization + */ #define offset(field) XtOffsetOf(TemplateRec, template.field) - /* {name, class, type, size, offset, default_type, default_addr}, */ - { XtNtemplateResource, XtCTemplateResource, XtRTemplateResource, - sizeof(char*), offset(resource), XtRString, (XtPointer) "default" }, -#undef offset +static XtResource resources[] = { +/*{ + name, + class, + type, + size, + offset, + default_type, + default_addr + },*/ + { + XtNtemplateResource, + XtCTemplateResource, + XtRTemplateResource, + sizeof(char*), + offset(resource), + XtRString, + (XtPointer)"default" + }, }; - -static void TemplateAction(/* Widget, XEvent*, String*, Cardinal* */); +#undef offset static XtActionsRec actions[] = { - /* {name, procedure}, */ + /*{name, procedure},*/ {"template", TemplateAction}, }; static char translations[] = -"<Key>: template() \n\ -"; +"<Key>:" "template()\n" +; +#define Superclass (&widgetClassRec) TemplateClassRec templateClassRec = { - { /* core fields */ - /* superclass */ (WidgetClass) &widgetClassRec, - /* class_name */ "Template", - /* widget_size */ sizeof(TemplateRec), - /* class_initialize */ NULL, - /* class_part_initialize */ NULL, - /* class_inited */ FALSE, - /* initialize */ NULL, - /* initialize_hook */ NULL, - /* realize */ XtInheritRealize, - /* actions */ actions, - /* num_actions */ XtNumber(actions), - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure */ TRUE, - /* compress_enterleave */ TRUE, - /* visible_interest */ FALSE, - /* destroy */ NULL, - /* resize */ NULL, - /* expose */ NULL, - /* set_values */ NULL, - /* set_values_hook */ NULL, - /* set_values_almost */ XtInheritSetValuesAlmost, - /* get_values_hook */ NULL, - /* accept_focus */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ translations, - /* query_geometry */ XtInheritQueryGeometry, - /* display_accelerator */ XtInheritDisplayAccelerator, - /* extension */ NULL + /* core */ + { + (WidgetClass)Superclass, /* superclass */ + "Template", /* class_name */ + sizeof(TemplateRec), /* widget_size */ + NULL, /* class_initialize */ + NULL, /* class_part_initialize */ + False, /* class_inited */ + TemplateInitialize, /* initialize */ + NULL, /* initialize_hook */ + XtInheritRealize, /* realize */ + actions, /* actions */ + XtNumber(actions), /* num_actions */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + True, /* compress_motion */ + True, /* compress_exposure */ + True, /* compress_enterleave */ + False, /* visible_interest */ + NULL, /* destroy */ + NULL, /* resize */ + NULL, /* expose */ + NULL, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + NULL, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + translations, /* tm_table */ + XtInheritQueryGeometry, /* query_geometry */ + XtInheritDisplayAccelerator, /* display_accelerator */ + NULL, /* extension */ }, - { /* template fields */ - /* empty */ 0 + /* template */ + { + NULL, /* extension */ } }; WidgetClass templateWidgetClass = (WidgetClass)&templateClassRec; + +/* + * Implementation + */ +/* + * Function: + * TemplateInitialize + * + * Parameters: + * request - requested widget + * w - the widget + * args - arguments + * num_args - number of arguments + * + * Description: + * Initializes widget instance. + */ +/*ARGSUSED*/ +static void +TemplateInitialize(Widget request, Widget w, ArgList args, Cardinal *num_args) +{ + TemplateWidget tw = (TemplateWidget)w; + + tw->template.private = NULL; +} + +/* + * Function: + * TemplateFunction + * + * Parameters: + * tw - template widget + * x - x coordinate + * y - y coordinate + * force - force action + * + * Description: + * This function does nothing. + * + * Return: + * Parameter force + */ +/*ARGSUSED*/ +static Bool +TemplateFunction(TemplateWidget tw, int x, int y, Bool force) +{ + return (force); +} + +/* + * Function: + * TemplateAction + * + * Parameters: + * w - template widget + * event - event that caused this action + * params - parameters + * num_params - number of parameters + * + * Description: + * This function does nothing. + */ +/*ARGSUSED*/ +static void +TemplateAction(Widget w, XEvent *event, String *params, Cardinal *num_params) +{ +} diff --git a/include/X11/Xaw/Template.h b/include/X11/Xaw/Template.h index d51e228..ec2df82 100644 --- a/include/X11/Xaw/Template.h +++ b/include/X11/Xaw/Template.h @@ -25,6 +25,7 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/Template.h,v 1.6 2001/12/14 19:54:44 dawes Exp $ */ #ifndef _Template_h #define _Template_h @@ -55,18 +56,15 @@ in this Software without prior written authorization from The Open Group. */ /* define any special resource names here that are not in <X11/StringDefs.h> */ - #define XtNtemplateResource "templateResource" #define XtCTemplateResource "TemplateResource" /* declare specific TemplateWidget class and instance datatypes */ - -typedef struct _TemplateClassRec* TemplateWidgetClass; -typedef struct _TemplateRec* TemplateWidget; +typedef struct _TemplateClassRec *TemplateWidgetClass; +typedef struct _TemplateRec *TemplateWidget; /* declare the class constant */ - extern WidgetClass templateWidgetClass; #endif /* _Template_h */ diff --git a/include/X11/Xaw/TemplateP.h b/include/X11/Xaw/TemplateP.h index 08488ed..29e36fb 100644 --- a/include/X11/Xaw/TemplateP.h +++ b/include/X11/Xaw/TemplateP.h @@ -25,21 +25,21 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ - +/* $XFree86: xc/lib/Xaw/TemplateP.h,v 1.7 2001/12/14 19:54:44 dawes Exp $ */ #ifndef _TemplateP_h #define _TemplateP_h #include <X11/Xaw/Template.h> + /* include superclass private header file */ #include <X11/CoreP.h> /* define unique representation types not found in <X11/StringDefs.h> */ - #define XtRTemplateResource "TemplateResource" typedef struct { - int empty; + XtPointer extension; } TemplateClassPart; typedef struct _TemplateClassRec { @@ -52,7 +52,8 @@ extern TemplateClassRec templateClassRec; typedef struct { /* resources */ char* resource; - /* private state */ + /* private */ + char *private; } TemplatePart; typedef struct _TemplateRec { diff --git a/include/X11/Xaw/Text.h b/include/X11/Xaw/Text.h index 84f2a3f..b04175a 100644 --- a/include/X11/Xaw/Text.h +++ b/include/X11/Xaw/Text.h @@ -46,6 +46,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/Text.h,v 1.15 2001/12/14 19:54:44 dawes Exp $ */ #ifndef _XawText_h #define _XawText_h @@ -53,7 +54,6 @@ SOFTWARE. #include <X11/Xaw/Simple.h> /* - Text widget Class: textWidgetClass Class Name: Text @@ -67,11 +67,14 @@ SOFTWARE. bottomMargin Margin Position 2 displayPosition TextPosition XawTextPosition 0 insertPosition TextPosition XawTextPosition 0 + justify JustifyMode JustifyMode left + leftColumn Column Column 0 + rightColumn Column Column 0 leftMargin Margin Position 2 - resize Resize XawTextResizeMode XawTextResizeNever rightMargin Margin Position 4 - scrollHorizontal Scroll XawTextScrollMode XawtextScrollNever - scrollVertical Scroll XawTextScrollMode XawtextScrollNever + positionCallback Callback Callback NULL + scrollHorizontal Scroll Boolean False + scrollVertical Scroll Boolean False selectTypes SelectTypes Pointer see documentation textSink TextSink Widget NULL textSource TextSource Widget NULL @@ -83,26 +86,82 @@ SOFTWARE. typedef long XawTextPosition; -typedef enum { XawtextScrollNever, - XawtextScrollWhenNeeded, XawtextScrollAlways} XawTextScrollMode; - -typedef enum { XawtextWrapNever, - XawtextWrapLine, XawtextWrapWord} XawTextWrapMode; - -typedef enum { XawtextResizeNever, XawtextResizeWidth, - XawtextResizeHeight, XawtextResizeBoth} XawTextResizeMode; +#ifndef notdef +typedef enum { + XawtextScrollNever, + XawtextScrollWhenNeeded, + XawtextScrollAlways +} XawTextScrollMode; + +typedef enum { + XawtextResizeNever, + XawtextResizeWidth, + XawtextResizeHeight, + XawtextResizeBoth +} XawTextResizeMode; +#endif -typedef enum {XawsdLeft, XawsdRight} XawTextScanDirection; -typedef enum {XawtextRead, XawtextAppend, XawtextEdit} XawTextEditType; -typedef enum {XawselectNull, XawselectPosition, XawselectChar, XawselectWord, - XawselectLine, XawselectParagraph, XawselectAll} XawTextSelectType; +typedef enum { + XawtextWrapNever, + XawtextWrapLine, + XawtextWrapWord +} XawTextWrapMode; + +typedef enum { + XawsdLeft, + XawsdRight +} XawTextScanDirection; + +typedef enum { + XawtextRead, + XawtextAppend, + XawtextEdit +} XawTextEditType; + +typedef enum { + XawselectNull, + XawselectPosition, + XawselectChar, + XawselectWord, + XawselectLine, + XawselectParagraph, + XawselectAll, + XawselectAlphaNumeric +} XawTextSelectType; + +typedef enum { + XawjustifyLeft, + XawjustifyRight, + XawjustifyCenter, + XawjustifyFull +} XawTextJustifyMode; typedef struct { int firstPos; int length; char *ptr; unsigned long format; - } XawTextBlock, *XawTextBlockPtr; +} XawTextBlock, *XawTextBlockPtr; + +#ifndef OLDXAW +typedef struct { + int line_number; + int column_number; + XawTextPosition insert_position; + XawTextPosition last_position; + Boolean overwrite_mode; +} XawTextPositionInfo; + +typedef struct { + XawTextPosition left, right; + XawTextBlock *block; +} XawTextPropertyInfo; + +typedef struct _XawTextAnchor XawTextAnchor; +typedef struct _XawTextEntity XawTextEntity; +typedef struct _XawTextProperty XawTextProperty; +typedef struct _XawTextPropertyList XawTextPropertyList; +#endif #include <X11/Xaw/TextSink.h> #include <X11/Xaw/TextSrc.h> @@ -110,16 +169,15 @@ typedef struct { #define XtEtextScrollNever "never" #define XtEtextScrollWhenNeeded "whenneeded" #define XtEtextScrollAlways "always" - -#define XtEtextWrapNever "never" -#define XtEtextWrapLine "line" -#define XtEtextWrapWord "word" - #define XtEtextResizeNever "never" #define XtEtextResizeWidth "width" #define XtEtextResizeHeight "height" #define XtEtextResizeBoth "both" +#define XtEtextWrapNever "never" +#define XtEtextWrapLine "line" +#define XtEtextWrapWord "word" + #define XtNautoFill "autoFill" #define XtNbottomMargin "bottomMargin" #define XtNdialogHOffset "dialogHOffset" @@ -128,41 +186,56 @@ typedef struct { #define XtNdisplayPosition "displayPosition" #define XtNleftMargin "leftMargin" #define XtNrightMargin "rightMargin" +#define XtNpositionCallback "positionCallback" #define XtNscrollVertical "scrollVertical" #define XtNscrollHorizontal "scrollHorizontal" #define XtNselectTypes "selectTypes" #define XtNtopMargin "topMargin" #define XtNwrap "wrap" +#define XtCColumn "Column" +#define XtNleftColumn "leftColumn" +#define XtNrightColumn "rightColumn" + +#define XtCJustifyMode XtCJustify +#define XtNjustifyMode XtNjustify +#define XtEtextJustifyLeft "left" +#define XtEtextJustifyRight "right" +#define XtEtextJustifyCenter "center" +#define XtEtextJustifyFull "full" + #define XtCAutoFill "AutoFill" -#define XtCScroll "Scroll" #define XtCSelectTypes "SelectTypes" #define XtCWrap "Wrap" +#ifndef notdef +#define XtCScroll "Scroll" +#endif #ifndef _XtStringDefs_h_ #define XtNinsertPosition "insertPosition" +#ifndef notdef #define XtNresize "resize" -#define XtNselection "selection" #define XtCResize "Resize" #endif +#define XtNselection "selection" +#endif -/* Return Error code for XawTextSearch */ - +/* return Error code for XawTextSearch */ #define XawTextSearchError (-12345L) -/* Return codes from XawTextReplace */ - +/* return codes from XawTextReplace */ #define XawReplaceError -1 #define XawEditDone 0 #define XawEditError 1 #define XawPositionError 2 +/* XrmQuark is not unsigned long */ +#define XawTextFormat(tw,fmt) ((unsigned long)_XawTextFormat(tw) == (fmt)) + extern unsigned long FMT8BIT; extern unsigned long XawFmt8Bit; extern unsigned long XawFmtWide; -/* Class record constants */ - extern WidgetClass textWidgetClass; typedef struct _TextClassRec *TextWidgetClass; @@ -170,140 +243,131 @@ typedef struct _TextRec *TextWidget; _XFUNCPROTOBEGIN -extern XrmQuark _XawTextFormat( -#if NeedFunctionPrototypes - TextWidget /* tw */ -#endif -); - -extern void XawTextDisplay( -#if NeedFunctionPrototypes - Widget /* w */ -#endif -); - -extern void XawTextEnableRedisplay( -#if NeedFunctionPrototypes - Widget /* w */ -#endif -); - -extern void XawTextDisableRedisplay( -#if NeedFunctionPrototypes - Widget /* w */ -#endif -); - -extern void XawTextSetSelectionArray( -#if NeedFunctionPrototypes - Widget /* w */, - XawTextSelectType* /* sarray */ -#endif -); - -extern void XawTextGetSelectionPos( -#if NeedFunctionPrototypes - Widget /* w */, - XawTextPosition* /* begin_return */, - XawTextPosition* /* end_return */ -#endif -); - -extern void XawTextSetSource( -#if NeedFunctionPrototypes - Widget /* w */, - Widget /* source */, - XawTextPosition /* position */ -#endif -); - -extern int XawTextReplace( -#if NeedFunctionPrototypes - Widget /* w */, - XawTextPosition /* start */, - XawTextPosition /* end */, - XawTextBlock* /* text */ -#endif -); - -extern XawTextPosition XawTextTopPosition( -#if NeedFunctionPrototypes - Widget /* w */ -#endif -); - -extern void XawTextSetInsertionPoint( -#if NeedFunctionPrototypes - Widget /* w */, - XawTextPosition /* position */ -#endif -); - -extern XawTextPosition XawTextGetInsertionPoint( -#if NeedFunctionPrototypes - Widget /* w */ -#endif -); - -extern void XawTextUnsetSelection( -#if NeedFunctionPrototypes - Widget /* w */ -#endif +XrmQuark _XawTextFormat +( + TextWidget tw + ); + +void XawTextDisplay +( + Widget w + ); + +void XawTextEnableRedisplay +( + Widget w + ); + +void XawTextDisableRedisplay +( + Widget w + ); + +void XawTextSetSelectionArray +( + Widget w, + XawTextSelectType *sarray + ); + +void XawTextGetSelectionPos +( + Widget w, + XawTextPosition *begin_return, + XawTextPosition *end_return + ); + +void XawTextSetSource +( + Widget w, + Widget source, + XawTextPosition top + ); + +int XawTextReplace +( + Widget w, + XawTextPosition start, + XawTextPosition end, + XawTextBlock *text + ); + +XawTextPosition XawTextTopPosition +( + Widget w + ); + +XawTextPosition XawTextLastPosition +( + Widget w + ); + +void XawTextSetInsertionPoint +( + Widget w, + XawTextPosition position + ); + +XawTextPosition XawTextGetInsertionPoint +( + Widget w + ); + +void XawTextUnsetSelection +( + Widget w + ); + +void XawTextSetSelection +( + Widget w, + XawTextPosition left, + XawTextPosition right + ); + +void XawTextInvalidate +( + Widget w, + XawTextPosition from, + XawTextPosition to ); -extern void XawTextSetSelection( -#if NeedFunctionPrototypes - Widget /* w */, - XawTextPosition /* left */, - XawTextPosition /* right */ -#endif -); - -extern void XawTextInvalidate( -#if NeedFunctionPrototypes - Widget /* w */, - XawTextPosition /* from */, - XawTextPosition /* to */ -#endif -); +Widget XawTextGetSource +( + Widget w + ); -extern Widget XawTextGetSource( -#if NeedFunctionPrototypes - Widget /* w */ -#endif -); +Widget XawTextGetSink +( + Widget w + ); -extern XawTextPosition XawTextSearch( -#if NeedFunctionPrototypes - Widget /* w */, +XawTextPosition XawTextSearch +( + Widget w, #if NeedWidePrototypes - /* XawTextScanDirection */ int /* dir */, + int dir, #else - XawTextScanDirection /* dir */, -#endif - XawTextBlock* /* text */ + XawTextScanDirection dir, #endif -); + XawTextBlock *text + ); -extern void XawTextDisplayCaret( -#if NeedFunctionPrototypes - Widget /* w */, +void XawTextDisplayCaret +( + Widget w, #if NeedWidePrototypes - /* Boolean */ int /* visible */ + int visible #else - Boolean /* visible */ -#endif + Boolean visible #endif -); + ); _XFUNCPROTOEND /* - * For R3 compatability only. + * For R3 compatability only */ - #include <X11/Xaw/AsciiSrc.h> #include <X11/Xaw/AsciiSink.h> #endif /* _XawText_h */ -/* DON'T ADD STUFF AFTER THIS #endif */ diff --git a/include/X11/Xaw/TextP.h b/include/X11/Xaw/TextP.h index f679db1..cf11b85 100644 --- a/include/X11/Xaw/TextP.h +++ b/include/X11/Xaw/TextP.h @@ -49,117 +49,135 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/TextP.h,v 3.22 2001/12/19 21:37:31 dawes Exp $ */ #ifndef _XawTextP_h #define _XawTextP_h +#include <X11/Xfuncproto.h> + #include <X11/Xaw/Text.h> #include <X11/Xaw/SimpleP.h> -/**************************************************************** - * - * Text widget private - * - ****************************************************************/ -#define MAXCUT 30000 /* Maximum number of characters that can be cut. */ +_XFUNCPROTOBEGIN + +#define MAXCUT 30000 /* Maximum number of characters that can be cut */ -#define GETLASTPOS XawTextSourceScan(ctx->text.source, 0, \ - XawstAll, XawsdRight, 1, TRUE) +#define XawTextGetLastPosition(ctx) \ + XawTextSourceScan((ctx)->text.source, 0, \ + XawstAll, XawsdRight, 1, True) +#define GETLASTPOS XawTextGetLastPosition(ctx) -#define zeroPosition ((XawTextPosition) 0) +#define zeroPosition ((XawTextPosition)0) extern XtActionsRec _XawTextActionsTable[]; extern Cardinal _XawTextActionsTableCount; -#define XawLF 0x0a -#define XawCR 0x0d -#define XawTAB 0x09 -#define XawBS 0x08 -#define XawSP 0x20 -#define XawDEL 0x7f -#define XawESC 0x1b +#define XawLF 0x0a +#define XawCR 0x0d +#define XawTAB 0x09 +#define XawBS 0x08 +#define XawSP 0x20 +#define XawDEL 0x7f +#define XawESC 0x1b #define XawBSLASH '\\' /* constants that subclasses may want to know */ #define DEFAULT_TEXT_HEIGHT ((Dimension)~0) +#define DEFAULT_TAB_SIZE 8 /* displayable text management data structures */ - typedef struct { - XawTextPosition position; - Position y; - Dimension textWidth; + XawTextPosition position; + Position y; +#ifndef OLDXAW + unsigned int textWidth; +#else + Dimension textWidth; +#endif } XawTextLineTableEntry, *XawTextLineTableEntryPtr; typedef struct { - XawTextPosition left, right; + XawTextPosition left, right; XawTextSelectType type; - Atom* selections; - int atom_count; - int array_size; + Atom *selections; + int atom_count; + int array_size; } XawTextSelection; typedef struct _XawTextSelectionSalt { - struct _XawTextSelectionSalt *next; + struct _XawTextSelectionSalt *next; XawTextSelection s; /* * The element "contents" stores the CT string which is gotten in the - * function _XawTextSaltAwaySelection(). + * function _XawTextSaltAwaySelection() */ char *contents; int length; } XawTextSelectionSalt; +#ifndef OLDXAW +typedef struct _XawTextKillRing { + struct _XawTextKillRing *next; + char *contents; + int length; + unsigned refcount; + unsigned long format; +} XawTextKillRing; + +extern XawTextKillRing *xaw_text_kill_ring; +#endif + /* Line Tables are n+1 long - last position displayed is in last lt entry */ typedef struct { - XawTextPosition top; /* Top of the displayed text. */ - int lines; /* How many lines in this table. */ - XawTextLineTableEntry *info; /* A dynamic array, one entry per line */ + XawTextPosition top; /* Top of the displayed text */ + int lines; /* How many lines in this table */ +#ifndef OLDXAW + int base_line; /* line number of first entry */ +#endif + XawTextLineTableEntry *info; /* A dynamic array, one entry per line */ } XawTextLineTable, *XawTextLineTablePtr; - typedef struct _XawTextMargin { - Position left, right, top, bottom; + Position left, right, top, bottom; } XawTextMargin; -#define VMargins(ctx) ( (ctx)->text.margin.top + (ctx)->text.margin.bottom ) -#define HMargins(ctx) ( (ctx)->text.margin.left + (ctx)->text.margin.right ) +typedef struct _XmuScanline XmuTextUpdate; + +#define VMargins(ctx) ((ctx)->text.margin.top + (ctx)->text.margin.bottom) +#define HMargins(ctx) ((ctx)->text.left_margin + (ctx)->text.margin.right) +#define RVMargins(ctx) ((ctx)->text.r_margin.top + (ctx)->text.r_margin.bottom) +#define RHMargins(ctx) ((ctx)->text.r_margin.left + (ctx)->text.r_margin.right) #define IsPositionVisible(ctx, pos) \ - (pos >= ctx->text.lt.info[0].position && \ +(pos >= ctx->text.lt.info[0].position && \ pos < ctx->text.lt.info[ctx->text.lt.lines].position) /* - * Search & Replace data structure. + * Search & Replace data structure */ - struct SearchAndReplace { - Boolean selection_changed; /* flag so that the selection cannot be + Boolean selection_changed; /* flag so that the selection cannot be changed out from underneath query-replace.*/ - Widget search_popup; /* The poppup widget that allows searches.*/ - Widget label1; /* The label widgets for the search window. */ - Widget label2; - Widget left_toggle; /* The left search toggle radioGroup. */ - Widget right_toggle; /* The right search toggle radioGroup. */ - Widget rep_label; /* The Replace label string. */ - Widget rep_text; /* The Replace text field. */ - Widget search_text; /* The Search text field. */ - Widget rep_one; /* The Replace one button. */ - Widget rep_all; /* The Replace all button. */ + Widget search_popup; /* The poppup widget that allows searches.*/ + Widget label1; /* The label widgets for the search window. */ + Widget label2; + Widget left_toggle; /* The left search toggle radioGroup. */ + Widget right_toggle; /* The right search toggle radioGroup. */ + Widget rep_label; /* The Replace label string. */ + Widget rep_text; /* The Replace text field. */ + Widget search_text; /* The Search text field. */ + Widget rep_one; /* The Replace one button. */ + Widget rep_all; /* The Replace all button. */ +#ifndef OLDXAW + Widget case_sensitive; /* The "Case Sensitive" toggle */ +#endif }; - -/* Private Text Definitions */ - -typedef int (*ActionProc)(); /* New fields for the Text widget class record */ - -typedef struct {int empty;} TextClassPart; - -struct text_move { - int h, v; - struct text_move * next; -}; +typedef struct { + XtPointer extension; +} TextClassPart; /* Full class record declaration */ typedef struct _TextClassRec { @@ -173,116 +191,131 @@ extern TextClassRec textClassRec; /* New fields for the Text widget record */ typedef struct _TextPart { /* resources */ + Widget source, sink; + XawTextPosition insertPos; + XawTextSelection s; + XawTextSelectType *sarray; /* Array to cycle for selections */ + XawTextSelectionSalt *salt; /* salted away selections */ + int left_margin; + int dialog_horiz_offset, dialog_vert_offset; /* position for popup dialog */ + Boolean display_caret; /* insertion pt visible iff T */ + Boolean auto_fill; /* Auto fill mode? */ + XawTextScrollMode scroll_vert, scroll_horiz; + XawTextWrapMode wrap; /* The type of wrapping */ + XawTextResizeMode resize; + XawTextMargin r_margin; /* The real margins */ +#ifndef OLDXAW + XtCallbackList position_callbacks; +#else + XtPointer pad1; +#endif - Widget source, sink; - XawTextPosition insertPos; - XawTextSelection s; - XawTextSelectType *sarray; /* Array to cycle for selections. */ - XawTextSelectionSalt *salt; /* salted away selections */ - int options; /* wordbreak, scroll, etc. */ - int dialog_horiz_offset; /* position for popup dialog */ - int dialog_vert_offset; /* position for popup dialog */ - Boolean display_caret; /* insertion pt visible iff T */ - Boolean auto_fill; /* Auto fill mode? */ - XawTextScrollMode scroll_vert, scroll_horiz; /*what type of scrollbars.*/ - XawTextWrapMode wrap; /* The type of wrapping. */ - XawTextResizeMode resize; /* what to resize */ - XawTextMargin r_margin; /* The real margins. */ - XtCallbackList unrealize_callbacks; /* used for scrollbars */ - /* private state */ - - XawTextMargin margin; /* The current margins. */ - XawTextLineTable lt; + XawTextMargin margin; /* The current margins */ + XawTextLineTable lt; XawTextScanDirection extendDir; - XawTextSelection origSel; /* the selection being modified */ - Time lasttime; /* timestamp of last processed action */ - Time time; /* time of last key or button action */ - Position ev_x, ev_y; /* x, y coords for key or button action */ - Widget vbar, hbar; /* The scroll bars (none = NULL). */ - struct SearchAndReplace * search;/* Search and replace structure. */ - Widget file_insert; /* The file insert popup widget. */ - XawTextPosition *updateFrom; /* Array of start positions for update. */ - XawTextPosition *updateTo; /* Array of end positions for update. */ - int numranges; /* How many update ranges there are. */ - int maxranges; /* How many ranges we have space for */ - XawTextPosition lastPos; /* Last position of source. */ - GC gc; - Boolean showposition; /* True if we need to show the position. */ - Boolean hasfocus; /* TRUE if we currently have input focus.*/ - Boolean update_disabled; /* TRUE if display updating turned off */ - Boolean single_char; /* Single character replaced. */ - XawTextPosition old_insert; /* Last insertPos for batched updates */ - short mult; /* Multiplier. */ - struct text_move * copy_area_offsets; /* Text offset area (linked list) */ + XawTextSelection origSel; /* the selection being modified */ + Time lasttime; /* timestamp of last processed action */ + Time time; /* time of last key or button action */ + Position ev_x, ev_y; /* x, y coords for key or button action */ + Widget vbar, hbar; /* The scroll bars (none = NULL) */ + struct SearchAndReplace *search; /* Search and replace structure */ + Widget file_insert; /* The file insert popup widget */ + XmuTextUpdate *update; /* Position intervals to update */ +#ifndef OLDXAW + int line_number; + short column_number; + unsigned char kill_ring; + Boolean selection_state; +#else + XtPointer pad2; + int pad3; +#endif + int from_left; /* Cursor position */ + XawTextPosition lastPos; /* Last position of source */ + GC gc; + Boolean showposition; /* True if we need to show the position */ + Boolean hasfocus; /* TRUE if we currently have input focus*/ + Boolean update_disabled; /* TRUE if display updating turned off */ + Boolean clear_to_eol; /* Clear to eol when painting text? */ + XawTextPosition old_insert; /* Last insertPos for batched updates */ + short mult; /* Multiplier */ +#ifndef OLDXAW + XawTextKillRing *kill_ring_ptr; +#else + XtPointer pad4; +#endif /* private state, shared w/Source and Sink */ - Boolean redisplay_needed; /* in SetValues */ - XawTextSelectionSalt *salt2; /* salted away selections */ + Boolean redisplay_needed; /* in SetValues */ + XawTextSelectionSalt *salt2; /* salted away selections */ + +#ifndef OLDXAW + char numeric; + char source_changed; + Boolean overwrite; /* Overwrite mode */ + + /* new resources and states, for text edition + * Note: a fixed width font is required for these resources/states. + */ + short left_column, right_column; + XawTextJustifyMode justify; + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } TextPart; -/************************************************************* - * - * Resource types private to Text widget. - * - *************************************************************/ - -#define XtRScrollMode "ScrollMode" -#define XtRWrapMode "WrapMode" -#define XtRResizeMode "ResizeMode" - -/**************************************************************** - * - * Full instance record declaration - * - ****************************************************************/ +#define XtRWrapMode "WrapMode" +#define XtRScrollMode "ScrollMode" +#define XtRResizeMode "ResizeMode" +#define XtRJustifyMode "JustifyMode" +/* full instance record */ typedef struct _TextRec { CorePart core; SimplePart simple; TextPart text; } TextRec; -/******************************************** - * +/* * Semi-private functions * for use by other Xaw modules only - * - *******************************************/ - -extern void _XawTextBuildLineTable ( -#if NeedFunctionPrototypes - TextWidget /*ctx*/, - XawTextPosition /*top pos*/, - _XtBoolean /* force_rebuild */ -#endif -); - -extern char* _XawTextGetSTRING( -#if NeedFunctionPrototypes - TextWidget /*ctx*/, - XawTextPosition /*left*/, - XawTextPosition /*right*/ -#endif -); - -extern void _XawTextSaltAwaySelection( -#if NeedFunctionPrototypes - TextWidget /*ctx*/, - Atom* /*selections*/, - int /*num_atoms*/ -#endif -); - -extern void _XawTextPosToXY( -#if NeedFunctionPrototypes - Widget /* w */, - XawTextPosition /* pos */, - Position * /* x */, - Position * /*y */ -#endif -); + */ +void _XawTextBuildLineTable +( + TextWidget ctx, + XawTextPosition top_pos, + _XtBoolean force_rebuild + ); + +char *_XawTextGetSTRING +( + TextWidget ctx, + XawTextPosition left, + XawTextPosition right + ); + +void _XawTextSaltAwaySelection +( + TextWidget ctx, + Atom *selections, + int num_atoms + ); + +void _XawTextPosToXY +( + Widget w, + XawTextPosition pos, + Position *x, + Position *y + ); + +void _XawTextNeedsUpdating +( + TextWidget ctx, + XawTextPosition left, + XawTextPosition right + ); + +_XFUNCPROTOEND #endif /* _XawTextP_h */ - - diff --git a/include/X11/Xaw/TextSink.h b/include/X11/Xaw/TextSink.h index f5ce84b..b379de9 100644 --- a/include/X11/Xaw/TextSink.h +++ b/include/X11/Xaw/TextSink.h @@ -48,6 +48,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/TextSink.h,v 1.10 2001/12/14 19:54:45 dawes Exp $ */ #ifndef _XawTextSink_h #define _XawTextSink_h @@ -67,7 +68,7 @@ SOFTWARE. font Font XFontStruct * XtDefaultFont foreground Foreground Pixel XtDefaultForeground background Background Pixel XtDefaultBackground - + cursorColor Color Pixel XtDefaultForeground */ /* Class record constants */ @@ -79,239 +80,285 @@ typedef struct _TextSinkRec *TextSinkObject; typedef enum {XawisOn, XawisOff} XawTextInsertState; -/************************************************************ - * - * Public Functions. - * - ************************************************************/ +#ifndef OLDXAW +#ifndef XtNcursorColor +#define XtNcursorColor "cursorColor" +#endif +#define XawNtextProperties "textProperties" +#define XawCTextProperties "TextProperties" +#define XawRTextProperties "XawTextProperties" +#endif + +/* + * Public Functions + */ _XFUNCPROTOBEGIN -/* Function Name: XawTextSinkDisplayText - * Description: Stub function that in subclasses will display text. - * Arguments: w - the TextSink Object. - * x, y - location to start drawing text. - * pos1, pos2 - location of starting and ending points - * in the text buffer. - * highlight - hightlight this text? - * Returns: none. +/* + * Function: + * XawTextSinkDisplayText * - * This function doesn't actually display anything, it is only a place - * holder. + * Parameters: + * w - the TextSink Object + * x - location to start drawing text + * y - "" + * pos1 - location of starting and ending points in the text buffer + * pos2 - "" + * highlight - hightlight this text? + * + * Description: + * Stub function that in subclasses will display text. + * + * Note: + * This function doesn't actually display anything, it is only a place + * holder. */ - -extern void XawTextSinkDisplayText( -#if NeedFunctionPrototypes - Widget /* w */, +void XawTextSinkDisplayText +( + Widget w, #if NeedWidePrototypes - /* Position */ int /* x */, - /* Position */ int /* y */, + int x, + int y, #else - Position /* x */, - Position /* y */, + Position x, + Position y, #endif - XawTextPosition /* pos1 */, - XawTextPosition /* pos2 */, + XawTextPosition pos1, + XawTextPosition pos2, #if NeedWidePrototypes - /* Boolean */ int /* highlight */ + int highlight #else - Boolean /* highlight */ -#endif + Boolean highlight #endif -); + ); -/* Function Name: XawTextSinkInsertCursor - * Description: Places the InsertCursor. - * Arguments: w - the TextSink Object. - * x, y - location for the cursor. - * staye - whether to turn the cursor on, or off. - * Returns: none. +/* + * Function: + * XawTextSinkInsertCursor + * + * Parameters: + * w - the TextSink Object. + * x - location for the cursor. + * y - "" + * state - whether to turn the cursor on, or off + * + * Description: + * Places the InsertCursor. * - * This function doesn't actually display anything, it is only a place - * holder. + * Note: + * This function doesn't actually display anything, it is only a place + * holder. */ - -extern void XawTextSinkInsertCursor( -#if NeedFunctionPrototypes - Widget /* w */, +void XawTextSinkInsertCursor +( + Widget w, #if NeedWidePrototypes - /* Position */ int /* x */, - /* Position */ int /* y */, - /* XawTextInsertState */ int /* state */ + int x, + int y, + int state #else - Position /* x */, - Position /* y */, - XawTextInsertState /* state */ -#endif + Position x, + Position y, + XawTextInsertState state #endif -); + ); -/* Function Name: XawTextSinkClearToBackground - * Description: Clears a region of the sink to the background color. - * Arguments: w - the TextSink Object. - * x, y - location of area to clear. - * width, height - size of area to clear - * Returns: void. +/* + * Function: + * XawTextSinkClearToBackground * - * This function doesn't actually display anything, it is only a place - * holder. + * Parameters: + * w - TextSink Object + * x - location of area to clear + * y - "" + * width - size of area to clear + * height - "" + * + * Description: + * Clears a region of the sink to the background color. + * + * Note: + * This function doesn't actually display anything, it is only a place + * holder. */ - -extern void XawTextSinkClearToBackground( -#if NeedFunctionPrototypes - Widget /* w */, +void XawTextSinkClearToBackground +( + Widget w, #if NeedWidePrototypes - /* Position */ int /* x */, - /* Position */ int /* y */, - /* Dimension */ int /* width */, - /* Dimension */ int /* height */ + int x, + int y, + unsigned int width, + unsigned int height #else - Position /* x */, - Position /* y */, - Dimension /* width */, - Dimension /* height */ -#endif + Position x, + Position y, + Dimension width, + Dimension height #endif -); + ); -/* Function Name: XawTextSinkFindPosition - * Description: Finds a position in the text. - * Arguments: w - the TextSink Object. - * fromPos - reference position. - * fromX - reference location. - * width, - width of section to paint text. - * stopAtWordBreak - returned position is a word break? - * resPos - Position to return. *** RETURNED *** - * resWidth - Width actually used. *** RETURNED *** - * resHeight - Height actually used. *** RETURNED *** - * Returns: none (see above). +/* + * Function: + * XawTextSinkFindPosition + * + * Parameters: + * w - TextSink Object + * fromPos - reference position + * fromX - reference location + * width - width of section to paint text + * stopAtWordBreak - returned position is a word break? + * resPos - Position to return + * resWidth - Width actually used + * resHeight - Height actually used + * + * Description: + * Finds a position in the text. */ - -extern void XawTextSinkFindPosition( -#if NeedFunctionPrototypes - Widget /* w */, - XawTextPosition /* fromPos */, - int /* fromX */, - int /* width */, +void XawTextSinkFindPosition +( + Widget w, + XawTextPosition fromPos, + int fromX, + int width, #if NeedWidePrototypes - /* Boolean */ int /* stopAtWordBreak */, + int stopAtWordBreak, #else - Boolean /* stopAtWordBreak */, -#endif - XawTextPosition* /* pos_return */, - int* /* width_return */, - int* /* height_return */ + Boolean stopAtWordBreak, #endif -); + XawTextPosition* pos_return, + int *width_return, + int *height_return + ); -/* Function Name: XawTextSinkFindDistance - * Description: Find the Pixel Distance between two text Positions. - * Arguments: w - the TextSink Object. - * fromPos - starting Position. - * fromX - x location of starting Position. - * toPos - end Position. - * resWidth - Distance between fromPos and toPos. - * resPos - Acutal toPos used. - * resHeight - Height required by this text. - * Returns: none. +/* + * Function: + * XawTextSinkFindDistance + * + * Parameters: + * w - TextSink Object + * fromPos - starting Position + * fromX - x location of starting Position + * toPos - end Position + * resWidth - Distance between fromPos and toPos + * resPos - Acutal toPos used + * resHeight - Height required by this text + * + * Description: + * Find the Pixel Distance between two text Positions. */ +void XawTextSinkFindDistance +( + Widget w, + XawTextPosition fromPos, + int fromX, + XawTextPosition toPos, + int *width_return, + XawTextPosition *pos_return, + int *height_return + ); -extern void XawTextSinkFindDistance ( -#if NeedFunctionPrototypes - Widget /* w */, - XawTextPosition /* fromPos */, - int /* fromX */, - XawTextPosition /* toPos */, - int* /* width_return */, - XawTextPosition* /* pos_return */, - int* /* height_return */ -#endif -); - -/* Function Name: XawTextSinkResolve - * Description: Resloves a location to a position. - * Arguments: w - the TextSink Object. - * pos - a reference Position. - * fromx - a reference Location. - * width - width to move. - * resPos - the resulting position. - * Returns: none +/* + * Function: + * XawTextSinkResolve + * + * Parameters: + * w - TextSink Object + * pos - reference Position + * fromx - reference Location + * width - width to move + * resPos - resulting position + * + * Description: + * Resloves a location to a position. */ +void XawTextSinkResolve +( + Widget w, + XawTextPosition fromPos, + int fromX, + int width, + XawTextPosition *pos_return + ); -extern void XawTextSinkResolve( -#if NeedFunctionPrototypes - Widget /* w */, - XawTextPosition /* fromPos */, - int /* fromX */, - int /* width */, - XawTextPosition* /* pos_return */ -#endif -); - -/* Function Name: XawTextSinkMaxLines - * Description: Finds the Maximum number of lines that will fit in - * a given height. - * Arguments: w - the TextSink Object. - * height - height to fit lines into. - * Returns: the number of lines that will fit. +/* + * Function: + * XawTextSinkMaxLines + * + * Parameters: + * w - TextSink Object + * height - height to fit lines into + * + * Returns: + * Number of lines that will fit + * + * Description: + * Finds the Maximum number of lines that will fit in a given height. */ - -extern int XawTextSinkMaxLines( -#if NeedFunctionPrototypes - Widget /* w */, +int XawTextSinkMaxLines +( + Widget w, #if NeedWidePrototypes - /* Dimension */ int /* height */ + unsigned int height #else - Dimension /* height */ + Dimension height #endif -#endif -); + ); -/* Function Name: XawTextSinkMaxHeight - * Description: Finds the Minium height that will contain a given number - * lines. - * Arguments: w - the TextSink Object. - * lines - the number of lines. - * Returns: the height. +/* + * Function: + * XawTextSinkMaxHeight + * + * Parameters: + * w - TextSink Object + * lines - number of lines + * + * Returns: + * Height + * + * Description: + * Finds the Minium height that will contain a given number lines. */ - -extern int XawTextSinkMaxHeight( -#if NeedFunctionPrototypes - Widget /* w */, - int /* lines */ -#endif +int XawTextSinkMaxHeight +( + Widget w, + int lines ); -/* Function Name: XawTextSinkSetTabs - * Description: Sets the Tab stops. - * Arguments: w - the TextSink Object. - * tab_count - the number of tabs in the list. - * tabs - the text positions of the tabs. - * Returns: none +/* + * Function: + * XawTextSinkSetTabs + * + * Parameters: + * w - TextSink Object + * tab_count - number of tabs in the list + * tabs - text positions of the tabs + * Description: + * Sets the Tab stops. */ - -extern void XawTextSinkSetTabs( -#if NeedFunctionPrototypes - Widget /* w */, - int /* tab_count */, - int* /* tabs */ -#endif +void XawTextSinkSetTabs +( + Widget w, + int tab_count, + int *tabs ); -/* Function Name: XawTextSinkGetCursorBounds - * Description: Finds the bounding box for the insert curor (caret). - * Arguments: w - the TextSinkObject. - * rect - an X rectance containing the cursor bounds. - * Returns: none (fills in rect). +/* + * Function: + * XawTextSinkGetCursorBounds + * + * Parameters: + * w - TextSink Object + * rect - X rectance containing the cursor bounds + * Description: + * Finds the bounding box for the insert curor (caret). */ - -extern void XawTextSinkGetCursorBounds( -#if NeedFunctionPrototypes - Widget /* w */, - XRectangle* /* rect_return */ -#endif +void XawTextSinkGetCursorBounds +( + Widget w, + XRectangle *rect_return ); _XFUNCPROTOEND -#endif /* _XawTextSrc_h */ +#endif /* _XawTextSink_h */ diff --git a/include/X11/Xaw/TextSinkP.h b/include/X11/Xaw/TextSinkP.h index 9645145..122f7da 100644 --- a/include/X11/Xaw/TextSinkP.h +++ b/include/X11/Xaw/TextSinkP.h @@ -49,45 +49,153 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ - -/* - * TextSinkP.h - Private definitions for TextSink object - * - */ +/* $XFree86: xc/lib/Xaw/TextSinkP.h,v 1.12 2001/12/14 19:54:45 dawes Exp $ */ #ifndef _XawTextSinkP_h #define _XawTextSinkP_h -/*********************************************************************** - * +/* * TextSink Object Private Data - * - ***********************************************************************/ - + */ #include <X11/Xaw/TextSink.h> -#include <X11/Xaw/TextP.h> /* This source works with the Text widget. */ -#include <X11/Xaw/TextSrcP.h> /* This source works with the Text Source. */ +#include <X11/Xaw/TextP.h> /* This sink works with the Text widget */ +#include <X11/Xaw/TextSrcP.h> /* This sink works with the Text Source */ +#include <X11/Xmu/Xmu.h> + +#ifndef OLDXAW +/* font/fontset defined? */ +#define XAW_TPROP_FONT (1<<0) +#define XAW_TPROP_FONTSET (1<<1) + +/* extra attributes */ +#define XAW_TPROP_FOREGROUND (1<<2) +#define XAW_TPROP_BACKGROUND (1<<3) +#define XAW_TPROP_FPIXMAP (1<<4) +#define XAW_TPROP_BPIXMAP (1<<5) +#define XAW_TPROP_UNDERLINE (1<<6) +#define XAW_TPROP_OVERSTRIKE (1<<7) +#define XAW_TPROP_SUBSCRIPT (1<<8) +#define XAW_TPROP_SUPERSCRIPT (1<<9) + +/* xlfd attributes */ +#define XAW_TPROP_FOUNDRY (1<<0) +#define XAW_TPROP_FAMILY (1<<1) +#define XAW_TPROP_WEIGHT (1<<2) +#define XAW_TPROP_SLANT (1<<3) +#define XAW_TPROP_SETWIDTH (1<<4) +#define XAW_TPROP_ADDSTYLE (1<<5) +#define XAW_TPROP_PIXELSIZE (1<<6) +#define XAW_TPROP_POINTSIZE (1<<7) +#define XAW_TPROP_RESX (1<<8) +#define XAW_TPROP_RESY (1<<9) +#define XAW_TPROP_SPACING (1<<10) +#define XAW_TPROP_AVGWIDTH (1<<11) +#define XAW_TPROP_REGISTRY (1<<12) +#define XAW_TPROP_ENCODING (1<<13) +struct _XawTextProperty { /* to be extended/modified */ + XrmQuark identifier, code; + unsigned long mask; + XFontStruct *font; + XFontSet fontset; + Pixel foreground, background; + Pixmap foreground_pixmap, background_pixmap; + XrmQuark xlfd; + + unsigned long xlfd_mask; + XrmQuark foundry, family, weight, slant, setwidth, addstyle, pixel_size, + point_size, res_x, res_y, spacing, avgwidth, registry, encoding; + + short underline_position, underline_thickness; +}; + +struct _XawTextPropertyList { + XrmQuark identifier; + Screen *screen; + Colormap colormap; + int depth; + XawTextProperty **properties; + Cardinal num_properties; + XawTextPropertyList *next; +}; + +typedef struct _XawTextPaintStruct XawTextPaintStruct; +struct _XawTextPaintStruct { + XawTextPaintStruct *next; + int x, y, width; + char *text; /* formatted text */ + Cardinal length; /* length of text */ + XawTextProperty *property; + int max_ascent, max_descent; + XmuArea *backtabs; + Boolean highlight; +}; + +typedef struct { + XmuArea *clip, *hightabs; /* clip list */ + XawTextPaintStruct *paint, *bearings; /* drawing information */ +} XawTextPaintList; + +typedef struct { + XtPointer next_extension; + XrmQuark record_type; + long version; + Cardinal record_size; + Bool (*BeginPaint)(Widget); + void (*PreparePaint)(Widget, int, int, + XawTextPosition, XawTextPosition, Bool); + void (*DoPaint)(Widget); + Bool (*EndPaint)(Widget); +} TextSinkExtRec, *TextSinkExt; +#endif + +typedef void (*_XawSinkDisplayTextProc) + (Widget, int, int, XawTextPosition, XawTextPosition, Bool); + +typedef void (*_XawSinkInsertCursorProc) + (Widget, int, int, XawTextInsertState); -/************************************************************ - * - * New fields for the TextSink object class record. - * - ************************************************************/ +typedef void (*_XawSinkClearToBackgroundProc) + (Widget, int, int, unsigned int, unsigned int); + +typedef void (*_XawSinkFindPositionProc) + (Widget, XawTextPosition, int, int, Bool, XawTextPosition*, int*, int*); + +typedef void (*_XawSinkFindDistanceProc) + (Widget, XawTextPosition, int, XawTextPosition, int*, + XawTextPosition*, int*); + +typedef void (*_XawSinkResolveProc) + (Widget, XawTextPosition, int, int, XawTextPosition*); + +typedef int (*_XawSinkMaxLinesProc) + (Widget, unsigned int); + +typedef int (*_XawSinkMaxHeightProc) + (Widget, int); + +typedef void (*_XawSinkSetTabsProc) + (Widget, int, short*); + +typedef void (*_XawSinkGetCursorBoundsProc) + (Widget, XRectangle*); typedef struct _TextSinkClassPart { - void (*DisplayText)(); - void (*InsertCursor)(); - void (*ClearToBackground)(); - void (*FindPosition)(); - void (*FindDistance)(); - void (*Resolve)(); - int (*MaxLines)(); - int (*MaxHeight)(); - void (*SetTabs)(); - void (*GetCursorBounds)(); + _XawSinkDisplayTextProc DisplayText; + _XawSinkInsertCursorProc InsertCursor; + _XawSinkClearToBackgroundProc ClearToBackground; + _XawSinkFindPositionProc FindPosition; + _XawSinkFindDistanceProc FindDistance; + _XawSinkResolveProc Resolve; + _XawSinkMaxLinesProc MaxLines; + _XawSinkMaxHeightProc MaxHeight; + _XawSinkSetTabsProc SetTabs; + _XawSinkGetCursorBoundsProc GetCursorBounds; +#ifndef OLDXAW + TextSinkExt extension; +#endif } TextSinkClassPart; -/* Full class record declaration */ +/* Full class record */ typedef struct _TextSinkClassRec { ObjectClassPart object_class; TextSinkClassPart text_sink_class; @@ -95,48 +203,104 @@ typedef struct _TextSinkClassRec { extern TextSinkClassRec textSinkClassRec; -/* New fields for the TextSink object record */ +/* New fields for the TextSink object */ typedef struct { /* resources */ - Pixel foreground; /* Foreground color. */ - Pixel background; /* Background color. */ + Pixel foreground; /* Foreground color */ + Pixel background; /* Background color */ - /* private state. */ - Position *tabs; /* The tab stops as pixel values. */ - short *char_tabs; /* The tabs stops as character values. */ - int tab_count; /* number of items in tabs */ + /* private */ + Position *tabs; /* The tab stops as pixel values */ + short *char_tabs; /* The tabs stops as character values */ + int tab_count; /* number of items in tabs */ +#ifndef OLDXAW + /* more resources */ + Pixel cursor_color; + XawTextPropertyList *properties; + XawTextPaintList *paint; + XtPointer pad[2]; /* for future use and keep binary compatability */ +#endif } TextSinkPart; -/**************************************************************** - * - * Full instance record declaration - * - ****************************************************************/ - +/* Full instance record */ typedef struct _TextSinkRec { - ObjectPart object; - TextSinkPart text_sink; + ObjectPart object; + TextSinkPart text_sink; } TextSinkRec; -/************************************************************ - * - * Private declarations. - * - ************************************************************/ - -typedef int (*_XawSinkIntFunc)(); -typedef void (*_XawSinkVoidFunc)(); - -#define XtInheritDisplayText ((_XawSinkVoidFunc) _XtInherit) -#define XtInheritInsertCursor ((_XawSinkVoidFunc) _XtInherit) -#define XtInheritClearToBackground ((_XawSinkVoidFunc) _XtInherit) -#define XtInheritFindPosition ((_XawSinkVoidFunc) _XtInherit) -#define XtInheritFindDistance ((_XawSinkVoidFunc) _XtInherit) -#define XtInheritResolve ((_XawSinkVoidFunc) _XtInherit) -#define XtInheritMaxLines ((_XawSinkIntFunc) _XtInherit) -#define XtInheritMaxHeight ((_XawSinkIntFunc) _XtInherit) -#define XtInheritSetTabs ((_XawSinkVoidFunc) _XtInherit) -#define XtInheritGetCursorBounds ((_XawSinkVoidFunc) _XtInherit) +/* Semi private routines */ +#ifndef OLDXAW +XawTextPropertyList *XawTextSinkConvertPropertyList +( + String name, + String spec, + Screen *screen, + Colormap Colormap, + int depth + ); + +XawTextProperty *XawTextSinkGetProperty +( + Widget w, + XrmQuark property + ); + +XawTextProperty *XawTextSinkCopyProperty +( + Widget w, + XrmQuark property + ); + +XawTextProperty *XawTextSinkAddProperty +( + Widget w, + XawTextProperty *property + ); + +XawTextProperty *XawTextSinkCombineProperty +( + Widget w, + XawTextProperty *result_in_out, + XawTextProperty *property, + Bool override + ); + +Bool XawTextSinkBeginPaint +( + Widget w + ); + +void XawTextSinkPreparePaint +( + Widget w, + int y, + int line, + XawTextPosition from, + XawTextPosition to, + Bool highlight +); + +void XawTextSinkDoPaint +( + Widget w + ); + +Bool XawTextSinkEndPaint +( + Widget w + ); +#endif + +#define XtInheritDisplayText ((_XawSinkDisplayTextProc)_XtInherit) +#define XtInheritInsertCursor ((_XawSinkInsertCursorProc)_XtInherit) +#define XtInheritClearToBackground ((_XawSinkClearToBackgroundProc)_XtInherit) +#define XtInheritFindPosition ((_XawSinkFindPositionProc)_XtInherit) +#define XtInheritFindDistance ((_XawSinkFindDistanceProc)_XtInherit) +#define XtInheritResolve ((_XawSinkResolveProc)_XtInherit) +#define XtInheritMaxLines ((_XawSinkMaxLinesProc)_XtInherit) +#define XtInheritMaxHeight ((_XawSinkMaxHeightProc)_XtInherit) +#define XtInheritSetTabs ((_XawSinkSetTabsProc)_XtInherit) +#define XtInheritGetCursorBounds ((_XawSinkGetCursorBoundsProc)_XtInherit) #endif /* _XawTextSinkP_h */ diff --git a/include/X11/Xaw/TextSrc.h b/include/X11/Xaw/TextSrc.h index b976174..c978e73 100644 --- a/include/X11/Xaw/TextSrc.h +++ b/include/X11/Xaw/TextSrc.h @@ -48,189 +48,233 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/TextSrc.h,v 1.13 2002/02/10 02:40:08 paulo Exp $ */ #ifndef _XawTextSrc_h #define _XawTextSrc_h -/*********************************************************************** - * - * TextSrc Object - * - ***********************************************************************/ - #include <X11/Xaw/Text.h> /* Resources: Name Class RepType Default Value ---- ----- ------- ------------- + callback Callback Callback NULL editType EditType XawTextEditType XawtextRead + enableUndo Undo Boolean False + sourceChanged Changed Boolean False */ /* Class record constants */ - extern WidgetClass textSrcObjectClass; typedef struct _TextSrcClassRec *TextSrcObjectClass; typedef struct _TextSrcRec *TextSrcObject; -typedef enum {XawstPositions, XawstWhiteSpace, XawstEOL, XawstParagraph, - XawstAll} XawTextScanType; -typedef enum {Normal, Selected }highlightType; -typedef enum {XawsmTextSelect, XawsmTextExtend} XawTextSelectionMode; -typedef enum {XawactionStart, XawactionAdjust, XawactionEnd} - XawTextSelectionAction; - -/* - * Error Conditions: - */ +typedef enum { + XawstPositions, + XawstWhiteSpace, + XawstEOL, + XawstParagraph, + XawstAll, + XawstAlphaNumeric + } XawTextScanType; + +typedef enum { + Normal, + Selected +} highlightType; + +typedef enum { + XawsmTextSelect, + XawsmTextExtend +} XawTextSelectionMode; + +typedef enum { + XawactionStart, + XawactionAdjust, + XawactionEnd +} XawTextSelectionAction; #define XawTextReadError -1 #define XawTextScanError -1 -/************************************************************ - * - * Public Functions. - * - ************************************************************/ +#ifndef OLDXAW +#define XtNenableUndo "enableUndo" +#define XtCUndo "Undo" -_XFUNCPROTOBEGIN +#define XtNsourceChanged "sourceChanged" +#define XtCChanged "Changed" + +#define XtNpropertyCallback "propertyCallback" +#endif -/* Function Name: XawTextSourceRead - * Description: This function reads the source. - * Arguments: w - the TextSrc Object. - * pos - position of the text to retreive. - * RETURNED text - text block that will contain returned text. - * length - maximum number of characters to read. - * Returns: The number of characters read into the buffer. +/* + * Public Functions */ +_XFUNCPROTOBEGIN -extern XawTextPosition XawTextSourceRead( -#if NeedFunctionPrototypes - Widget /* w */, - XawTextPosition /* pos */, - XawTextBlock* /* text_return */, - int /* length */ -#endif -); - -/* Function Name: XawTextSourceReplace. - * Description: Replaces a block of text with new text. - * Arguments: src - the Text Source Object. - * startPos, endPos - ends of text that will be removed. - * text - new text to be inserted into buffer at startPos. - * Returns: XawEditError or XawEditDone. +/* + * Function: + * XawTextSourceRead + * + * Parameters: + * w - TextSrc Object + * pos - position of the text to retreive + * text - text block that will contain returned text + * length - maximum number of characters to read + * + * Description: + * This function reads the source. + * + * Returns: + * The number of characters read into the buffer */ +XawTextPosition XawTextSourceRead +( + Widget w, + XawTextPosition pos, + XawTextBlock *text_return, + int length + ); -extern int XawTextSourceReplace ( -#if NeedFunctionPrototypes - Widget /* w */, - XawTextPosition /* start */, - XawTextPosition /* end */, - XawTextBlock* /* text */ -#endif -); - -/* Function Name: XawTextSourceScan - * Description: Scans the text source for the number and type - * of item specified. - * Arguments: w - the TextSrc Object. - * position - the position to start scanning. - * type - type of thing to scan for. - * dir - direction to scan. - * count - which occurance if this thing to search for. - * include - whether or not to include the character found in - * the position that is returned. - * Returns: The position of the text. +/* + * Function: + * XawTextSourceReplace * + * Parameters: + * src - Text Source Object + * startPos - ends of text that will be removed + * endPos - "" + * text - new text to be inserted into buffer at startPos + * + * Description: + * Replaces a block of text with new text + * + * Returns: + * XawEditError or XawEditDone */ +int XawTextSourceReplace +( + Widget w, + XawTextPosition start, + XawTextPosition end, + XawTextBlock *text + ); -extern XawTextPosition XawTextSourceScan( -#if NeedFunctionPrototypes - Widget /* w */, - XawTextPosition /* position */, -#if NeedWidePrototypes - /* XawTextScanType */ int /* type */, - /* XawTextScanDirection */ int /* dir */, -#else - XawTextScanType /* type */, - XawTextScanDirection /* dir */, -#endif - int /* count */, +/* + * Function: + * XawTextSourceScan + * + * Parameters: + * w - TextSrc Object + * position - position to start scanning + * type - type of thing to scan for + * dir - direction to scan + * count - which occurance if this thing to search for + * include - whether or not to include the character found in + * the position that is returned. + * + * Description: + * Scans the text source for the number and type of item specified. + * + * Returns: + * The position of the text + */ +XawTextPosition XawTextSourceScan +( + Widget w, + XawTextPosition position, #if NeedWidePrototypes - /* Boolean */ int /* include */ + int type, + int dir, + int count, + int include #else - Boolean /* include */ -#endif + XawTextScanType type, + XawTextScanDirection dir, + int count, + Boolean include #endif -); - -/* Function Name: XawTextSourceSearch - * Description: Searchs the text source for the text block passed - * Arguments: w - the TextSource Object. - * position - the position to start scanning. - * dir - direction to scan. - * text - the text block to search for. - * Returns: The position of the text we are searching for or - * XawTextSearchError. - */ + ); -extern XawTextPosition XawTextSourceSearch( -#if NeedFunctionPrototypes - Widget /* w */, - XawTextPosition /* position */, +/* + * Function: + * XawTextSourceSearch + * + * Parameters: + * w - TextSource Object + * position - position to start scanning + * dir - direction to search + * text - the text block to search for + * + * Description: + * Searchs the text source for the text block passed. + * + * Returns: + * The position of the text we are searching for or XawTextSearchError + */ +XawTextPosition XawTextSourceSearch +( + Widget w, + XawTextPosition position, #if NeedWidePrototypes - /* XawTextScanDirection */ int /* dir */, + int dir, #else - XawTextScanDirection /* dir */, -#endif - XawTextBlock* /* text */ + XawTextScanDirection dir, #endif -); - -/* Function Name: XawTextSourceConvertSelection - * Description: Dummy selection converter. - * Arguments: w - the TextSrc object. - * selection - the current selection atom. - * target - the current target atom. - * type - the type to conver the selection to. - * RETURNED value, length - the return value that has been converted. - * RETURNED format - the format of the returned value. - * Returns: TRUE if the selection has been converted. + XawTextBlock *text + ); + +/* + * Function: + * XawTextSourceConvertSelection + * + * Parameters: + * w - TextSrc object + * selection - current selection atom + * target - current target atom + * type - type to conver the selection to + * value - return value that has been converted + * length - "" + * format - format of the returned value * + * Returns: + * True if the selection has been converted */ +Boolean XawTextSourceConvertSelection +( + Widget w, + Atom *selection, + Atom *target, + Atom *type, + XtPointer *value_return, + unsigned long *length_return, + int *format_return + ); -extern Boolean XawTextSourceConvertSelection( -#if NeedFunctionPrototypes - Widget /* w */, - Atom* /* selection */, - Atom* /* target */, - Atom* /* type */, - XtPointer* /* value_return */, - unsigned long* /* length_return */, - int* /* format_return */ -#endif -); - -/* Function Name: XawTextSourceSetSelection - * Description: allows special setting of the selection. - * Arguments: w - the TextSrc object. - * left, right - bounds of the selection. - * selection - the selection atom. - * Returns: none +/* + * Function: + * XawTextSourceSetSelection + * + * Parameters: + * w - TextSrc object + * left - bounds of the selection + * right - "" + * selection - selection atom + * + * Description: + * Allows special setting of the selection. */ - -extern void XawTextSourceSetSelection( -#if NeedFunctionPrototypes - Widget /* w */, - XawTextPosition /* start */, - XawTextPosition /* end */, - Atom /* selection */ -#endif -); +void XawTextSourceSetSelection +( + Widget w, + XawTextPosition start, + XawTextPosition end, + Atom selection + ); _XFUNCPROTOEND #endif /* _XawTextSrc_h */ -/* DON'T ADD STUFF AFTER THIS #endif */ diff --git a/include/X11/Xaw/TextSrcP.h b/include/X11/Xaw/TextSrcP.h index c85f404..02f62ae 100644 --- a/include/X11/Xaw/TextSrcP.h +++ b/include/X11/Xaw/TextSrcP.h @@ -49,30 +49,43 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ - -/* - * TextSrcP.h - Private definitions for TextSrc object - * - */ +/* $XFree86: xc/lib/Xaw/TextSrcP.h,v 1.15 2001/12/19 21:37:31 dawes Exp $ */ #ifndef _XawTextSrcP_h #define _XawTextSrcP_h -/*********************************************************************** - * +/* * TextSrc Object Private Data - * - ***********************************************************************/ + */ +#include <X11/Xfuncproto.h> #include <X11/Xaw/TextSrc.h> -#include <X11/Xaw/TextP.h> /* This source works with the Text widget. */ - -/************************************************************ - * - * New fields for the TextSrc object class record. - * - ************************************************************/ +#include <X11/Xaw/TextP.h> /* This source works with the Text widget */ + +_XFUNCPROTOBEGIN + +#ifndef OLDXAW +struct _XawTextAnchor { + XawTextPosition position; + XawTextEntity *entities, *cache; +}; + +#define XAW_TENTF_HIDE 0x0001 +#define XAW_TENTF_READ 0x0002 +#define XAW_TENTF_REPLACE 0x0004 +struct _XawTextEntity { + short type; + short flags; + XawTextEntity *next; + XtPointer data; + XawTextPosition offset; /* from the anchor */ + Cardinal length; + XrmQuark property; +}; +#endif +#if 0 /* no longer used */ +/* New fields for the TextSrc object class */ typedef struct { XtPointer next_extension; XrmQuark record_type; @@ -80,17 +93,40 @@ typedef struct { Cardinal record_size; int (*Input)(); } TextSrcExtRec, *TextSrcExt; +#endif + +typedef XawTextPosition (*_XawSrcReadProc) + (Widget, XawTextPosition, XawTextBlock*, int); + +typedef int (*_XawSrcReplaceProc) + (Widget, XawTextPosition, XawTextPosition, XawTextBlock*); + +typedef XawTextPosition (*_XawSrcScanProc) + (Widget, XawTextPosition, XawTextScanType, XawTextScanDirection, + int, Bool); + +typedef XawTextPosition (*_XawSrcSearchProc) + (Widget, XawTextPosition, XawTextScanDirection, XawTextBlock*); + +typedef void (*_XawSrcSetSelectionProc) + (Widget, XawTextPosition, XawTextPosition, Atom); + +typedef Boolean (*_XawSrcConvertSelectionProc) + (Widget, Atom*, Atom*, Atom*, XtPointer*, unsigned long*, int*); typedef struct _TextSrcClassPart { - XawTextPosition (*Read)(); - int (*Replace)(); - XawTextPosition (*Scan)(); - XawTextPosition (*Search)(); - void (*SetSelection)(); - Boolean (*ConvertSelection)(); + _XawSrcReadProc Read; + _XawSrcReplaceProc Replace; + _XawSrcScanProc Scan; + _XawSrcSearchProc Search; + _XawSrcSetSelectionProc SetSelection; + _XawSrcConvertSelectionProc ConvertSelection; +#ifndef OLDXAW + XtPointer extension; +#endif } TextSrcClassPart; -/* Full class record declaration */ +/* Full class record */ typedef struct _TextSrcClassRec { ObjectClassPart object_class; TextSrcClassPart textSrc_class; @@ -98,66 +134,131 @@ typedef struct _TextSrcClassRec { extern TextSrcClassRec textSrcClassRec; -/* New fields for the TextSrc object record */ +#ifndef OLDXAW +typedef struct _XawTextUndo XawTextUndo; +#endif + +/* New fields for the TextSrc object */ typedef struct { /* resources */ - XawTextEditType edit_mode; - XrmQuark text_format; /* 2 formats: FMT8BIT for Ascii */ - /* FMTWIDE for ISO 10646 */ + XawTextEditType edit_mode; + XrmQuark text_format; /* 2 formats: FMT8BIT for Ascii + FMTWIDE for ISO 10646 */ +#ifndef OLDXAW + XtCallbackList callback; /* A callback list to call when the + source is changed */ + Boolean changed; + Boolean enable_undo; + + /* private state */ + Boolean undo_state; /* to protect undo manipulation */ + XawTextUndo *undo; + WidgetList text; /* TextWidget's using this source */ + Cardinal num_text; + XtCallbackList property_callback; + XawTextAnchor **anchors; + int num_anchors; + XtPointer pad[1]; /* for future use and keep binary compatability */ +#endif } TextSrcPart; -/**************************************************************** - * - * Full instance record declaration - * - ****************************************************************/ - +/* Full instance record */ typedef struct _TextSrcRec { - ObjectPart object; - TextSrcPart textSrc; + ObjectPart object; + TextSrcPart textSrc; } TextSrcRec; -/****************************************************************** - * +/* * Semiprivate declarations of functions used in other modules - * - ******************************************************************/ - -char* _XawTextWCToMB( -#if NeedFunctionPrototypes - Display* /* d */, - wchar_t* /* wstr */, - int* /* len_in_out */ + */ +char* _XawTextWCToMB +( + Display *display, + wchar_t *wstr, + int *len_in_out + ); + +wchar_t* _XawTextMBToWC +( + Display *display, + char *str, + int *len_in_out + ); + +#ifndef OLDXAW +XawTextAnchor *XawTextSourceAddAnchor +( + Widget source, + XawTextPosition position + ); + +XawTextAnchor *XawTextSourceFindAnchor +( + Widget source, + XawTextPosition position + ); + +XawTextAnchor *XawTextSourceNextAnchor +( + Widget source, + XawTextAnchor *anchor + ); + +XawTextAnchor *XawTextSourcePrevAnchor +( + Widget source, + XawTextAnchor *anchor + ); + +XawTextAnchor *XawTextSourceRemoveAnchor +( + Widget source, + XawTextAnchor *anchor + ); + +Bool XawTextSourceAnchorAndEntity +( + Widget w, + XawTextPosition position, + XawTextAnchor **anchor_return, + XawTextEntity **entity_return + ); + +XawTextEntity *XawTextSourceAddEntity +( + Widget source, + int type, + int flags, + XtPointer data, + XawTextPosition position, + Cardinal length, + XrmQuark property + ); + +void XawTextSourceClearEntities +( + Widget w, + XawTextPosition left, + XawTextPosition right + ); #endif -); -wchar_t* _XawTextMBToWC( -#if NeedFunctionPrototypes - Display* /* d */, - char* /* str */, - int* /* len_in_out */ +#if 0 /* no longer used */ +typedef XawTextPosition (*_XawTextPositionFunc)(); #endif -); - -/************************************************************ - * - * Private declarations. - * - ************************************************************/ -typedef Boolean (*_XawBooleanFunc)(); -typedef int (*_XawIntFunc)(); -typedef XawTextPosition (*_XawTextPositionFunc)(); -typedef void (*_XawTextVoidFunc)(); - -#define XtInheritInput ((_XawTextPositionFunc) _XtInherit) -#define XtInheritRead ((_XawTextPositionFunc) _XtInherit) -#define XtInheritReplace ((_XawIntFunc) _XtInherit) -#define XtInheritScan ((_XawTextPositionFunc) _XtInherit) -#define XtInheritSearch ((_XawTextPositionFunc) _XtInherit) -#define XtInheritSetSelection ((_XawTextVoidFunc) _XtInherit) -#define XtInheritConvertSelection ((_XawBooleanFunc) _XtInherit) +#define XtInheritInput ((_XawTextPositionFunc)_XtInherit) +#define XtInheritRead ((_XawSrcReadProc)_XtInherit) +#define XtInheritReplace ((_XawSrcReplaceProc)_XtInherit) +#define XtInheritScan ((_XawSrcScanProc)_XtInherit) +#define XtInheritSearch ((_XawSrcSearchProc)_XtInherit) +#define XtInheritSetSelection ((_XawSrcSetSelectionProc)_XtInherit) +#define XtInheritConvertSelection ((_XawSrcConvertSelectionProc)_XtInherit) +#if 0 #define XtTextSrcExtVersion 1 #define XtTextSrcExtTypeString "XT_TEXTSRC_EXT" +#endif + +_XFUNCPROTOEND #endif /* _XawTextSrcP_h */ diff --git a/include/X11/Xaw/Toggle.h b/include/X11/Xaw/Toggle.h index a433bd0..68bb742 100644 --- a/include/X11/Xaw/Toggle.h +++ b/include/X11/Xaw/Toggle.h @@ -23,6 +23,7 @@ Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/Toggle.h,v 1.6 2001/12/14 19:54:45 dawes Exp $ */ /* * ToggleP.h - Private definitions for Toggle widget @@ -37,12 +38,6 @@ in this Software without prior written authorization from The Open Group. #ifndef _XawToggle_h #define _XawToggle_h -/*********************************************************************** - * - * Toggle Widget - * - ***********************************************************************/ - #include <X11/Xaw/Command.h> /* Resources: @@ -60,6 +55,7 @@ in this Software without prior written authorization from The Open Group. callback Callback Pointer NULL cursor Cursor Cursor None destroyCallback Callback Pointer NULL + displayList DisplayList XawDisplayList* NULL font Font XFontStructx* XtDefaultFont foreground Foreground Pixel XtDefaultForeground height Height Dimension text height @@ -86,10 +82,8 @@ in this Software without prior written authorization from The Open Group. /* * These should be in StringDefs.h but aren't so we will define - * them here if they are needed. + * them here if they are needed */ - - #define XtCWidget "Widget" #define XtCState "State" #define XtCRadioGroup "RadioGroup" @@ -108,68 +102,79 @@ extern WidgetClass toggleWidgetClass; typedef struct _ToggleClassRec *ToggleWidgetClass; typedef struct _ToggleRec *ToggleWidget; - -/************************************************************ - * +/* * Public Functions - * - ************************************************************/ + */ _XFUNCPROTOBEGIN -/* Function Name: XawToggleChangeRadioGroup - * Description: Allows a toggle widget to change radio lists. - * Arguments: w - The toggle widget to change lists. - * radio_group - any widget in the new list. - * Returns: none. +/* + * Function: + * XawToggleChangeRadioGroup + * + * Parameters: + * w - toggle widget to change lists + * radio_group - any widget in the new list + * + * Description: + * Allows a toggle widget to change radio lists. */ +void XawToggleChangeRadioGroup +( + Widget w, + Widget radio_group + ); -extern void XawToggleChangeRadioGroup( -#if NeedFunctionPrototypes - Widget /* w */, - Widget /* radio_group */ -#endif -); - -/* Function Name: XawToggleGetCurrent - * Description: Returns the RadioData associated with the toggle +/* + * Function: + * XawToggleGetCurrent + * + * Parameters: + * radio_group - any toggle widget in the toggle list + * + * Description: + * Returns the RadioData associated with the toggle * widget that is currently active in a toggle list. - * Arguments: radio_group - any toggle widget in the toggle list. - * Returns: The XtNradioData associated with the toggle widget. + * Returns: + * The XtNradioData associated with the toggle widget */ -extern XtPointer XawToggleGetCurrent( -#if NeedFunctionPrototypes - Widget /* radio_group */ -#endif -); - -/* Function Name: XawToggleSetCurrent - * Description: Sets the Toggle widget associated with the - * radio_data specified. - * Arguments: radio_group - any toggle widget in the toggle list. - * radio_data - radio data of the toggle widget to set. - * Returns: none. - */ +XtPointer XawToggleGetCurrent +( + Widget radio_group + ); -extern void XawToggleSetCurrent( -#if NeedFunctionPrototypes - Widget /* radio_group */, - XtPointer /* radio_data */ -#endif -); - -/* Function Name: XawToggleUnsetCurrent - * Description: Unsets all Toggles in the radio_group specified. - * Arguments: radio_group - any toggle widget in the toggle list. - * Returns: none. +/* + * Function: + * XawToggleSetCurrent + * + * Parameters: + * radio_group - any toggle widget in the toggle list + * radio_data - radio data of the toggle widget to set + * + * Description: + * Sets the Toggle widget associated with the radio_data specified. */ +void XawToggleSetCurrent +( + Widget radio_group, + XtPointer radio_data + ); -extern void XawToggleUnsetCurrent( -#if NeedFunctionPrototypes - Widget /* radio_group */ -#endif -); +/* + * Function: + * XawToggleUnsetCurrent + * + * Parameters: + * radio_group - any toggle widget in the toggle list + * + * Description: + * Unsets all Toggles in the radio_group specified. + */ +void XawToggleUnsetCurrent +( + Widget radio_group + ); _XFUNCPROTOEND diff --git a/include/X11/Xaw/ToggleP.h b/include/X11/Xaw/ToggleP.h index bacee25..e9afe41 100644 --- a/include/X11/Xaw/ToggleP.h +++ b/include/X11/Xaw/ToggleP.h @@ -25,10 +25,9 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/ToggleP.h,v 1.8 2001/12/14 19:54:45 dawes Exp $ */ /* - * ToggleP.h - Private definitions for Toggle widget - * * Author: Chris D. Peterson * MIT X Consortium * kit@expo.lcs.mit.edu @@ -43,68 +42,54 @@ in this Software without prior written authorization from The Open Group. #include <X11/Xaw/Toggle.h> #include <X11/Xaw/CommandP.h> -/*********************************************************************** - * +/* * Toggle Widget Private Data - * - ***********************************************************************/ - -#define streq(a, b) ( strcmp((a), (b)) == 0 ) + */ +#define streq(a, b) (strcmp((a), (b)) == 0) typedef struct _RadioGroup { - struct _RadioGroup *prev, *next; /* Pointers to other elements in group. */ - Widget widget; /* Widget corrosponding to this element. */ + struct _RadioGroup *prev, *next; /* Pointers to other elements in group */ + Widget widget; /* Widget corrosponding to this element */ } RadioGroup; -/************************************ - * - * Class structure - * - ***********************************/ - - /* New fields for the Toggle widget class record */ +/* New fields for the Toggle widget class */ typedef struct _ToggleClass { XtActionProc Set; XtActionProc Unset; XtPointer extension; } ToggleClassPart; - /* Full class record declaration */ +/* class record declaration */ typedef struct _ToggleClassRec { CoreClassPart core_class; SimpleClassPart simple_class; LabelClassPart label_class; CommandClassPart command_class; - ToggleClassPart toggle_class; + ToggleClassPart toggle_class; } ToggleClassRec; extern ToggleClassRec toggleClassRec; -/*************************************** - * - * Instance (widget) structure - * - **************************************/ - - /* New fields for the Toggle widget record */ +/* New fields for the Toggle widget */ typedef struct { /* resources */ - Widget widget; - XtPointer radio_data; - - /* private data */ - RadioGroup * radio_group; + Widget widget; + XtPointer radio_data; + + /* private */ + RadioGroup *radio_group; +#ifndef OLDXAW + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } TogglePart; - /* Full widget declaration */ +/* Full widget declaration */ typedef struct _ToggleRec { - CorePart core; - SimplePart simple; - LabelPart label; - CommandPart command; - TogglePart toggle; + CorePart core; + SimplePart simple; + LabelPart label; + CommandPart command; + TogglePart toggle; } ToggleRec; #endif /* _XawToggleP_h */ - - diff --git a/include/X11/Xaw/Tree.h b/include/X11/Xaw/Tree.h index 9e45d47..30697bb 100644 --- a/include/X11/Xaw/Tree.h +++ b/include/X11/Xaw/Tree.h @@ -48,6 +48,7 @@ in this Software without prior written authorization from The Open Group. * additional blank space to make the structure of the graph easier to see * as well as to support vertical trees. */ +/* $XFree86: xc/lib/Xaw/Tree.h,v 1.7 2001/12/14 19:54:45 dawes Exp $ */ #ifndef _XawTree_h @@ -105,6 +106,20 @@ in this Software without prior written authorization from The Open Group. #define XtCGravity "Gravity" #define XtRGC "GC" + +#ifndef OLDXAW +#ifndef XawNdisplayList +#define XawNdisplayList "displayList" +#endif + +#ifndef XawCDisplayList +#define XawCDisplayList "DisplayList" +#endif + +#ifndef XawRDisplayList +#define XawRDisplayList "XawDisplayList" +#endif +#endif /* external declarations */ extern WidgetClass treeWidgetClass; @@ -113,11 +128,10 @@ typedef struct _TreeRec *TreeWidget; _XFUNCPROTOBEGIN -extern void XawTreeForceLayout ( -#if NeedFunctionPrototypes - Widget /* tree */ -#endif -); +void XawTreeForceLayout +( + Widget tree + ); _XFUNCPROTOEND diff --git a/include/X11/Xaw/TreeP.h b/include/X11/Xaw/TreeP.h index 3b4e0ff..3a09170 100644 --- a/include/X11/Xaw/TreeP.h +++ b/include/X11/Xaw/TreeP.h @@ -48,6 +48,7 @@ in this Software without prior written authorization from The Open Group. * additional blank space to make the structure of the graph easier to see * as well as to support vertical trees. */ +/* $XFree86: xc/lib/Xaw/TreeP.h,v 1.7 2001/12/14 19:54:45 dawes Exp $ */ #ifndef _XawTreeP_h @@ -56,7 +57,7 @@ in this Software without prior written authorization from The Open Group. #include <X11/Xaw/Tree.h> typedef struct _TreeClassPart { - int ignore; + XtPointer extension; } TreeClassPart; typedef struct _TreeClassRec { @@ -82,6 +83,10 @@ typedef struct { Dimension *largest; /* list of largest per depth */ int n_largest; /* number of elements in largest */ Dimension maxwidth, maxheight; /* for shrink wrapping */ +#ifndef OLDXAW + XawDisplayList *display_list; + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } TreePart; @@ -107,6 +112,11 @@ typedef struct _TreeConstraintsPart { Dimension bbsubwidth, bbsubheight; /* bounding box of sub tree */ Dimension bbwidth, bbheight; /* bounding box including node */ Position x, y; +#ifndef OLDXAW + XtPointer pad[2]; /* leave some space for future optimizations, and + * keep binary compatability + */ +#endif } TreeConstraintsPart; typedef struct _TreeConstraintsRec { diff --git a/include/X11/Xaw/VendorEP.h b/include/X11/Xaw/VendorEP.h index 37d65ef..30c6fe3 100644 --- a/include/X11/Xaw/VendorEP.h +++ b/include/X11/Xaw/VendorEP.h @@ -51,6 +51,7 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/VendorEP.h,v 1.6 2001/12/14 19:54:45 dawes Exp $ */ #ifndef _VendorEP_h #define _VendorEP_h @@ -70,6 +71,9 @@ typedef struct { Widget parent; XawImPart im; XawIcPart ic; +#ifndef OLDXAW + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } XawVendorShellExtPart; typedef struct XawVendorShellExtRec { diff --git a/include/X11/Xaw/Viewport.h b/include/X11/Xaw/Viewport.h index 6f09420..b242ff2 100644 --- a/include/X11/Xaw/Viewport.h +++ b/include/X11/Xaw/Viewport.h @@ -46,6 +46,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ********************************************************/ +/* $XFree86: xc/lib/Xaw/Viewport.h,v 1.7 2001/12/14 19:54:46 dawes Exp $ */ #ifndef _XawViewport_h #define _XawViewport_h @@ -63,7 +64,7 @@ SOFTWARE. border BorderColor Pixel XtDefaultForeground borderWidth BorderWidth Dimension 1 destroyCallback Callback Pointer NULL - foreceBars Boolean Boolean False + forceBars Boolean Boolean False height Height Dimension 0 mappedWhenManaged MappedWhenManaged Boolean True reportCallback ReportCallback Pointer NULL @@ -76,7 +77,6 @@ SOFTWARE. */ -/* fields added to Form */ #ifndef _XtStringDefs_h_ #define XtNforceBars "forceBars" #define XtNallowHoriz "allowHoriz" @@ -92,31 +92,29 @@ typedef struct _ViewportRec *ViewportWidget; _XFUNCPROTOBEGIN -extern void XawViewportSetLocation ( -#if NeedFunctionPrototypes - Widget /* gw */, +void XawViewportSetLocation +( + Widget gw, #if NeedWidePrototypes - /* float */ double /* xoff */, - /* float */ double /* yoff */ + double xoff, + double yoff #else - float /* xoff */, - float /* yoff */ + float xoff, + float yoff #endif -#endif -); + ); -extern void XawViewportSetCoordinates ( -#if NeedFunctionPrototypes - Widget /* gw */, +void XawViewportSetCoordinates +( + Widget gw, #if NeedWidePrototypes - /* Position */ int /* x */, - /* Position */ int /* y */ + int x, + int y #else - Position /* x */, - Position /* y */ -#endif + Position x, + Position y #endif -); + ); _XFUNCPROTOEND diff --git a/include/X11/Xaw/ViewportP.h b/include/X11/Xaw/ViewportP.h index 6792426..4801885 100644 --- a/include/X11/Xaw/ViewportP.h +++ b/include/X11/Xaw/ViewportP.h @@ -49,6 +49,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ********************************************************/ +/* $XFree86: xc/lib/Xaw/ViewportP.h,v 1.8 2001/12/14 19:54:46 dawes Exp $ */ #ifndef _ViewportP_h #define _ViewportP_h @@ -56,7 +57,9 @@ SOFTWARE. #include <X11/Xaw/Viewport.h> #include <X11/Xaw/FormP.h> -typedef struct {int empty;} ViewportClassPart; +typedef struct { + XtPointer extension; +} ViewportClassPart; typedef struct _ViewportClassRec { CoreClassPart core_class; @@ -70,20 +73,24 @@ extern ViewportClassRec viewportClassRec; typedef struct _ViewportPart { /* resources */ - Boolean forcebars; /* Whether we should always display */ - /* the selected scrollbars. */ - Boolean allowhoriz; /* Whether we allow horizontal scrollbars. */ - Boolean allowvert; /* Whether we allow vertical scrollbars. */ - Boolean usebottom; /* True iff horiz bars appear at bottom. */ - Boolean useright; /* True iff vert bars appear at right. */ - XtCallbackList report_callbacks; /* when size/position changes */ - /* private state */ + Boolean forcebars; /* Whether we should always display + the selected scrollbars */ + Boolean allowhoriz; /* Whether we allow horizontal scrollbars */ + Boolean allowvert; /* Whether we allow vertical scrollbars */ + Boolean usebottom; /* True if horiz bars appear at bottom */ + Boolean useright; /* True if vert bars appear at right */ + XtCallbackList report_callbacks;/* when size/position changes */ + + /* private */ Widget clip, child; /* The clipping and (scrolled) child widgets */ - Widget horiz_bar, vert_bar;/* What scrollbars we currently have. */ + Widget horiz_bar, vert_bar; /* What scrollbars we currently have */ +#ifndef OLDXAW + XtPointer pad[4]; /* for future use and keep binary compatability */ +#endif } ViewportPart; typedef struct _ViewportRec { - CorePart core; + CorePart core; CompositePart composite; ConstraintPart constraint; FormPart form; @@ -91,10 +98,7 @@ typedef struct _ViewportRec { } ViewportRec; typedef struct { - /* resources */ - - /* private state */ - Boolean reparented; /* True if child has been re-parented */ + Bool reparented; /* True if child has been re-parented */ } ViewportConstraintsPart; typedef struct _ViewportConstraintsRec { diff --git a/include/X11/Xaw/XawImP.h b/include/X11/Xaw/XawImP.h index 1974a19..4f70554 100644 --- a/include/X11/Xaw/XawImP.h +++ b/include/X11/Xaw/XawImP.h @@ -51,6 +51,7 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/XawImP.h,v 3.9 2001/12/14 19:54:46 dawes Exp $ */ #ifndef _XawImP_h #define _XawImP_h @@ -74,8 +75,7 @@ in this Software without prior written authorization from The Open Group. #define CICursorP (1 << 5) #define CILineS (1 << 6) -typedef struct _XawImPart -{ +typedef struct _XawImPart { XIM xim; XrmResourceList resources; Cardinal num_resources; @@ -86,8 +86,7 @@ typedef struct _XawImPart String preedit_type; } XawImPart; -typedef struct _XawIcTablePart -{ +typedef struct _XawIcTablePart { Widget widget; XIC xic; XIMStyle input_style; @@ -104,8 +103,7 @@ typedef struct _XawIcTablePart struct _XawIcTablePart *next; } XawIcTablePart, *XawIcTableList; -typedef struct _XawIcPart -{ +typedef struct _XawIcPart { XIMStyle input_style; Boolean shared_ic; XawIcTableList shared_ic_table; @@ -113,111 +111,103 @@ typedef struct _XawIcPart XawIcTableList ic_table; } XawIcPart; -typedef struct _contextDataRec -{ +typedef struct _contextDataRec { Widget parent; Widget ve; } contextDataRec; -typedef struct _contextErrDataRec -{ +typedef struct _contextErrDataRec { Widget widget; XIM xim; } contextErrDataRec; -void _XawImResizeVendorShell( -#if NeedFunctionPrototypes - Widget /* w */ -#endif -); - -Dimension _XawImGetShellHeight( -#if NeedFunctionPrototypes - Widget /* w */ -#endif -); - -void _XawImRealize( -#if NeedFunctionPrototypes - Widget /* w */ -#endif -); - -void _XawImInitialize( -#if NeedFunctionPrototypes - Widget, /* w */ - Widget /* ext */ -#endif -); - -void _XawImReconnect( -#if NeedFunctionPrototypes - Widget /* w */ -#endif -); - -void _XawImRegister( -#if NeedFunctionPrototypes - Widget /* w */ -#endif -); +void _XawImResizeVendorShell +( + Widget w + ); -void _XawImUnregister( -#if NeedFunctionPrototypes - Widget /* w */ -#endif +Dimension _XawImGetShellHeight +( + Widget w ); -void _XawImSetValues( -#if NeedFunctionPrototypes - Widget, /* w */ - ArgList, /* args */ - Cardinal /* num_args */ -#endif +void _XawImRealize +( + Widget w + ); + +void _XawImInitialize +( + Widget w, + Widget ext + ); + +void _XawImReconnect +( + Widget w + ); + +void _XawImRegister +( + Widget w + ); + +void _XawImUnregister +( + Widget w + ); + +void _XawImSetValues +( + Widget w, + ArgList args, + Cardinal num_args + ); + +void _XawImSetFocusValues +( + Widget w, + ArgList args, + Cardinal num_args ); -void _XawImSetFocusValues( -#if NeedFunctionPrototypes - Widget, /* w */ - ArgList, /* args */ - Cardinal /* num_args */ -#endif -); - -void _XawImUnsetFocus( -#if NeedFunctionPrototypes - Widget /* w */ -#endif -); - -int _XawImWcLookupString( -#if NeedFunctionPrototypes - Widget, /* w */ - XKeyPressedEvent*, /* event */ - wchar_t*, /* buffer_return */ - int, /* bytes_buffer */ - KeySym*, /* keysym_return */ - Status* /* status return */ -#endif -); - -int _XawImGetImAreaHeight( -#if NeedFunctionPrototypes - Widget /* w */ -#endif -); - -void _XawImCallVendorShellExtResize( -#if NeedFunctionPrototypes - Widget /* w */ -#endif -); - -void _XawImDestroy( -#if NeedFunctionPrototypes - Widget, /* w */ - Widget /* ext */ -#endif -); +void _XawImUnsetFocus +( + Widget w + ); + +int _XawImWcLookupString +( + Widget w, + XKeyPressedEvent *event, + wchar_t *buffer_return, + int bytes_buffer, + KeySym *keysym_return + ); + +int _XawLookupString +( + Widget w, + XKeyEvent *event, + char *buffer_return, + int buffer_size, + KeySym *keysym_return + ); + +int _XawImGetImAreaHeight +( + Widget w + ); + +void _XawImCallVendorShellExtResize +( + Widget w + ); + +void _XawImDestroy +( + Widget w, + Widget ext + ); #endif /* _XawImP_h */ diff --git a/include/X11/Xaw/XawInit.h b/include/X11/Xaw/XawInit.h index 53de0ef..57c330c 100644 --- a/include/X11/Xaw/XawInit.h +++ b/include/X11/Xaw/XawInit.h @@ -22,11 +22,30 @@ Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/XawInit.h,v 1.13 2001/12/14 19:54:46 dawes Exp $ */ + +#ifndef _XawInit_h +#define _XawInit_h + +#define XawVendor "XFree86" + +#ifdef OLDXAW +#define XawVersion 6700002L +#else +#define XawVersion 7000002L + +typedef struct _XawDL XawDisplayList; +#endif /* OLDXAW */ #include <X11/Xfuncproto.h> _XFUNCPROTOBEGIN -extern void XawInitializeWidgetSet(); /* called from ClassInit procs */ +void XawInitializeWidgetSet(void); +#ifndef OLDXAW +void XawInitializeDefaultConverters(void); +#endif _XFUNCPROTOEND + +#endif /* _XawInit_h */ diff --git a/src/AllWidgets.c b/src/AllWidgets.c index 5a0ad0b..a6fc390 100644 --- a/src/AllWidgets.c +++ b/src/AllWidgets.c @@ -25,6 +25,7 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/AllWidgets.c,v 1.4 2001/12/14 19:54:38 dawes Exp $ */ #include <X11/IntrinsicP.h> #include <X11/Xmu/WidgetNode.h> @@ -35,9 +36,6 @@ extern WidgetClass asciiSrcObjectClass; extern WidgetClass asciiTextWidgetClass; extern WidgetClass boxWidgetClass; extern WidgetClass commandWidgetClass; -extern WidgetClass compositeWidgetClass; -extern WidgetClass constraintWidgetClass; -extern WidgetClass coreWidgetClass; extern WidgetClass dialogWidgetClass; extern WidgetClass formWidgetClass; extern WidgetClass gripWidgetClass; @@ -46,12 +44,10 @@ extern WidgetClass listWidgetClass; extern WidgetClass menuButtonWidgetClass; extern WidgetClass multiSinkObjectClass; extern WidgetClass multiSrcObjectClass; -extern WidgetClass objectClass; extern WidgetClass overrideShellWidgetClass; extern WidgetClass panedWidgetClass; extern WidgetClass pannerWidgetClass; extern WidgetClass portholeWidgetClass; -extern WidgetClass rectObjClass; extern WidgetClass repeaterWidgetClass; extern WidgetClass scrollbarWidgetClass; extern WidgetClass shellWidgetClass; diff --git a/src/AsciiSink.c b/src/AsciiSink.c index ddf6115..fe812d9 100644 --- a/src/AsciiSink.c +++ b/src/AsciiSink.c @@ -46,647 +46,1901 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/AsciiSink.c,v 1.28 2002/09/08 02:29:47 paulo Exp $ */ #include <stdio.h> - -#include <X11/Xatom.h> +#include <stdlib.h> #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> +#include <X11/Xatom.h> #include <X11/Xaw/XawInit.h> #include <X11/Xaw/AsciiSinkP.h> -#include <X11/Xaw/AsciiSrcP.h> /* For source function defs. */ -#include <X11/Xaw/TextP.h> /* I also reach into the text widget. */ +#include <X11/Xaw/AsciiSrcP.h> +#include <X11/Xaw/TextP.h> +#include "Private.h" #ifdef GETLASTPOS -#undef GETLASTPOS /* We will use our own GETLASTPOS. */ +#undef GETLASTPOS /* We will use our own GETLASTPOS */ #endif -#define GETLASTPOS XawTextSourceScan(source, (XawTextPosition) 0, XawstAll, XawsdRight, 1, TRUE) +#define GETLASTPOS \ + XawTextSourceScan(source, 0, XawstAll, XawsdRight, 1, True) -static void Initialize(), Destroy(); -static Boolean SetValues(); -static int MaxLines(), MaxHeight(); -static void SetTabs(); +/* + * Class Methods + */ +static void XawAsciiSinkClassPartInitialize(WidgetClass); +static void XawAsciiSinkInitialize(Widget, Widget, ArgList, Cardinal*); +static void XawAsciiSinkDestroy(Widget); +static void XawAsciiSinkResize(Widget); +static Boolean XawAsciiSinkSetValues(Widget, Widget, Widget, + ArgList, Cardinal*); +static int MaxLines(Widget, unsigned int); +static int MaxHeight(Widget, int); +static void SetTabs(Widget, int, short*); +static void DisplayText(Widget, int, int, + XawTextPosition, XawTextPosition, Bool); +static void InsertCursor(Widget, int, int, XawTextInsertState); +static void FindPosition(Widget, XawTextPosition, int, int, Bool, + XawTextPosition*, int*, int*); +static void FindDistance(Widget, XawTextPosition, int, XawTextPosition, int*, + XawTextPosition*, int*); +static void Resolve(Widget, XawTextPosition, int, int, XawTextPosition*); +static void GetCursorBounds(Widget, XRectangle*); +#ifndef OLDXAW +static void AsciiPreparePaint(Widget, int, int, + XawTextPosition, XawTextPosition, Bool); +static void AsciiDoPaint(Widget); +#endif -static void DisplayText(), InsertCursor(), FindPosition(); -static void FindDistance(), Resolve(), GetCursorBounds(); +/* + * Prototypes + */ +static void GetGC(AsciiSinkObject); +static int CharWidth(AsciiSinkObject, XFontStruct*, int, unsigned int); +static unsigned int PaintText(Widget w, GC gc, int x, int y, + char *buf, int len, Bool); -#define offset(field) XtOffsetOf(AsciiSinkRec, ascii_sink.field) +/* + * Defined in TextSink.c + */ +void _XawTextSinkClearToBackground(Widget, int, int, unsigned, unsigned); +/* + * Initialization + */ +#define offset(field) XtOffsetOf(AsciiSinkRec, ascii_sink.field) static XtResource resources[] = { - {XtNfont, XtCFont, XtRFontStruct, sizeof (XFontStruct *), - offset(font), XtRString, XtDefaultFont}, - {XtNecho, XtCOutput, XtRBoolean, sizeof(Boolean), - offset(echo), XtRImmediate, (XtPointer) True}, - {XtNdisplayNonprinting, XtCOutput, XtRBoolean, sizeof(Boolean), - offset(display_nonprinting), XtRImmediate, (XtPointer) True}, + { + XtNfont, + XtCFont, + XtRFontStruct, + sizeof(XFontStruct*), + offset(font), + XtRString, + XtDefaultFont + }, + { + XtNecho, + XtCOutput, + XtRBoolean, + sizeof(Boolean), + offset(echo), + XtRImmediate, + (XtPointer)True + }, + { + XtNdisplayNonprinting, + XtCOutput, + XtRBoolean, + sizeof(Boolean), + offset(display_nonprinting), + XtRImmediate, + (XtPointer) + True + }, }; #undef offset -#define SuperClass (&textSinkClassRec) +#define Superclass (&textSinkClassRec) AsciiSinkClassRec asciiSinkClassRec = { + /* object */ { -/* core_class fields */ - /* superclass */ (WidgetClass) SuperClass, - /* class_name */ "AsciiSink", - /* widget_size */ sizeof(AsciiSinkRec), - /* class_initialize */ XawInitializeWidgetSet, - /* class_part_initialize */ NULL, - /* class_inited */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* obj1 */ NULL, - /* obj2 */ NULL, - /* obj3 */ 0, - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* obj4 */ FALSE, - /* obj5 */ FALSE, - /* obj6 */ FALSE, - /* obj7 */ FALSE, - /* destroy */ Destroy, - /* obj8 */ NULL, - /* obj9 */ NULL, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* obj10 */ NULL, - /* get_values_hook */ NULL, - /* obj11 */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* obj12 */ NULL, - /* obj13 */ NULL, - /* obj14 */ NULL, - /* extension */ NULL + (WidgetClass)Superclass, /* superclass */ + "AsciiSink", /* class_name */ + sizeof(AsciiSinkRec), /* widget_size */ + XawInitializeWidgetSet, /* class_initialize */ + XawAsciiSinkClassPartInitialize, /* class_part_initialize */ + False, /* class_inited */ + XawAsciiSinkInitialize, /* initialize */ + NULL, /* initialize_hook */ + NULL, /* obj1 */ + NULL, /* obj2 */ + 0, /* obj3 */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + False, /* obj4 */ + False, /* obj5 */ + False, /* obj6 */ + False, /* obj7 */ + XawAsciiSinkDestroy, /* destroy */ + (XtProc)XawAsciiSinkResize, /* obj8 */ + NULL, /* obj9 */ + XawAsciiSinkSetValues, /* set_values */ + NULL, /* set_values_hook */ + NULL, /* obj10 */ + NULL, /* get_values_hook */ + NULL, /* obj11 */ + XtVersion, /* version */ + NULL, /* callback_private */ + NULL, /* obj12 */ + NULL, /* obj13 */ + NULL, /* obj14 */ + NULL, /* extension */ }, -/* text_sink_class fields */ + /* text_sink */ { - /* DisplayText */ DisplayText, - /* InsertCursor */ InsertCursor, - /* ClearToBackground */ XtInheritClearToBackground, - /* FindPosition */ FindPosition, - /* FindDistance */ FindDistance, - /* Resolve */ Resolve, - /* MaxLines */ MaxLines, - /* MaxHeight */ MaxHeight, - /* SetTabs */ SetTabs, - /* GetCursorBounds */ GetCursorBounds + DisplayText, /* DisplayText */ + InsertCursor, /* InsertCursor */ + XtInheritClearToBackground, /* ClearToBackground */ + FindPosition, /* FindPosition */ + FindDistance, /* FindDistance */ + Resolve, /* Resolve */ + MaxLines, /* MaxLines */ + MaxHeight, /* MaxHeight */ + SetTabs, /* SetTabs */ + GetCursorBounds, /* GetCursorBounds */ +#ifndef OLDXAW + NULL /* extension */ +#endif }, -/* ascii_sink_class fields */ + /* ascii_sink */ { - /* unused */ 0 + NULL, /* extension */ } }; WidgetClass asciiSinkObjectClass = (WidgetClass)&asciiSinkClassRec; -/* Utilities */ +/* + * Implementation + */ +static void +XawAsciiSinkClassPartInitialize(WidgetClass wc) +{ +#ifndef OLDXAW + AsciiSinkObjectClass cclass = (AsciiSinkObjectClass)wc; + XrmQuark record_type = XrmPermStringToQuark("TextSink"); + TextSinkExt ext = cclass->text_sink_class.extension; + + while (ext) { + if (ext->record_type == record_type && + ext->version == 1) { + ext->PreparePaint = AsciiPreparePaint; + ext->DoPaint = AsciiDoPaint; + break; + } + ext = (TextSinkExt)ext->next_extension; + } + if (ext == NULL) + XtError("TextSinkClass: cannot resolve extension.\n"); +#endif +} -static int -CharWidth (w, x, c) -Widget w; -int x; -unsigned char c; +static int +CharWidth(AsciiSinkObject sink, XFontStruct *font, int x, unsigned int c) { - int i, width, nonPrinting; - AsciiSinkObject sink = (AsciiSinkObject) w; - XFontStruct *font = sink->ascii_sink.font; - Position *tab; + int width = 0; - if ( c == XawLF ) return(0); + if (c == XawLF) + return (0); if (c == XawTAB) { - /* Adjust for Left Margin. */ - x -= ((TextWidget) XtParent(w))->text.margin.left; - - if (x >= (int)XtParent(w)->core.width) return 0; - for (i = 0, tab = sink->text_sink.tabs ; - i < sink->text_sink.tab_count ; i++, tab++) { - if (x < *tab) { - if (*tab < (int)XtParent(w)->core.width) - return *tab - x; - else - return 0; + int i; + Position *tab; + + width = x; + /* Adjust for Left Margin */ + x -= ((TextWidget)XtParent((Widget)sink))->text.left_margin; + + i = 0; + tab = sink->text_sink.tabs; + /*CONSTCOND*/ + while (1) { + if (x >= 0 && x < *tab) + return (*tab - x); + /* Start again */ + if (++i >= sink->text_sink.tab_count) { + x -= *tab; + i = 0; + tab = sink->text_sink.tabs; + if (width == x) + return (0); } + else + ++tab; } - return 0; + /*NOTREACHED*/ } - if ( (nonPrinting = (c < (unsigned char) XawSP)) ) - if (sink->ascii_sink.display_nonprinting) - c += '@'; - else { - c = XawSP; - nonPrinting = False; + if ((c & 0177) < XawSP || c == 0177) { + if (sink->ascii_sink.display_nonprinting) { + if (c > 0177) { + width = CharWidth(sink, font, x, '\\'); + width += CharWidth(sink, font, x, ((c >> 6) & 7) + '0'); + width += CharWidth(sink, font, x, ((c >> 3) & 7) + '0'); + c = (c & 7) + '0'; + } + else { + width = CharWidth(sink, font, x, '^'); + if ((c |= 0100) == 0177) + c = '?'; + } } + else + c = XawSP; + } - if (font->per_char && - (c >= font->min_char_or_byte2 && c <= font->max_char_or_byte2)) - width = font->per_char[c - font->min_char_or_byte2].width; + if (font->per_char + && (c >= font->min_char_or_byte2 && c <= font->max_char_or_byte2)) + width += font->per_char[c - font->min_char_or_byte2].width; else - width = font->min_bounds.width; + width += font->min_bounds.width; - if (nonPrinting) - width += CharWidth(w, x, (unsigned char) '^'); + return (width); +} + +#ifndef OLDXAW +static int +GetTextWidth(TextWidget ctx, int current_width, XFontStruct *font, + XawTextPosition from, int length) +{ + int i, width = 0; + XawTextBlock block; + XawTextPosition pos = from; + + while (length > 0) { + pos = XawTextSourceRead(ctx->text.source, from, &block, length); + length -= pos - from; + from = pos; + for (i = 0; i < block.length; i++) + width += CharWidth((AsciiSinkObject)ctx->text.sink, font, + current_width + width, + (unsigned char)block.ptr[i]); + } - return width; + return (width); } -/* Function Name: PaintText - * Description: Actually paints the text into the windoe. - * Arguments: w - the text widget. - * gc - gc to paint text with. - * x, y - location to paint the text. - * buf, len - buffer and length of text to paint. - * Returns: the width of the text painted, or 0. +static +void CalculateBearing(TextWidget ctx, XawTextPosition position, int x, int y, + int ascent, int descent, Bool highlight, Bool right) +{ +/* + * Sample case: + * + * lbearing| width |rbearing + * | | + * | #### + * | ### | + * | #### | + * | #### | + * | ########## | + * | #### | + * | #### | + * | #### | + * | #### | + * |### | + * #### | + * | | * - * NOTE: If this string attempts to paint past the end of the window - * then this function will return zero. */ + AsciiSinkObject sink = (AsciiSinkObject)ctx->text.sink; + XawTextAnchor *anchor; + XawTextEntity *entity; + XawTextProperty *property; + XawTextPaintStruct *paint; + XawTextBlock block; + XFontStruct *font; + + property = NULL; + if (XawTextSourceAnchorAndEntity(ctx->text.source, position, + &anchor, &entity) && + (property = XawTextSinkGetProperty((Widget)sink, + entity->property)) != NULL && + (property->mask & XAW_TPROP_FONT)) + font = property->font; + else + font = sink->ascii_sink.font; + if (right) { + if (font->max_bounds.rbearing > 0) { + int rbearing = font->max_bounds.rbearing - font->max_bounds.width; + unsigned char c; + + (void)XawTextSourceRead(ctx->text.source, position, &block, 1); + c = *(unsigned char*)block.ptr; + if (c == '\t' || c == '\n') + c = ' '; + else if ((c & 0177) < XawSP || c == 0177) { + if (sink->ascii_sink.display_nonprinting) + c = c > 0177 ? (c & 7) + '0' : c + '@'; + else + c = ' '; + } + if (font->per_char && + (c >= font->min_char_or_byte2 && c <= font->max_char_or_byte2)) + rbearing = font->per_char[c - font->min_char_or_byte2].rbearing - + font->per_char[c - font->min_char_or_byte2].width; + if (rbearing > 0) { + paint = XtNew(XawTextPaintStruct); + paint->next = sink->text_sink.paint->bearings; + sink->text_sink.paint->bearings = paint; + paint->x = x - (paint->width = CharWidth(sink, font, 0, c)); + paint->y = y + ascent; + paint->property = property; + paint->max_ascent = ascent; + paint->max_descent = descent; + paint->backtabs = NULL; + paint->highlight = highlight; + paint->length = 1; + paint->text = XtMalloc(1); + paint->text[0] = c; + } + } + } + else { + if (font->min_bounds.lbearing < 0) { + int lbearing = font->min_bounds.lbearing; + unsigned char c; + + (void)XawTextSourceRead(ctx->text.source, position, &block, 1); + c = *(unsigned char*)block.ptr; + if (c == '\t' || c == '\n') + c = ' '; + else if ((c & 0177) < XawSP || c == 0177) { + if (sink->ascii_sink.display_nonprinting) + c = c > 0177 ? '\\' : c + '^'; + else + c = ' '; + } + if (font->per_char && + (c >= font->min_char_or_byte2 && c <= font->max_char_or_byte2)) + lbearing = font->per_char[c - font->min_char_or_byte2].lbearing; + if (lbearing < 0) { + paint = XtNew(XawTextPaintStruct); + paint->next = sink->text_sink.paint->bearings; + sink->text_sink.paint->bearings = paint; + paint->x = x; + paint->width = -CharWidth(sink, font, 0, c); + paint->y = y + ascent; + paint->property = property; + paint->max_ascent = ascent; + paint->max_descent = descent; + paint->backtabs = NULL; + paint->highlight = highlight; + paint->length = 1; + paint->text = XtMalloc(1); + paint->text[0] = c; + } + } + } +} -static Dimension -PaintText(w, gc, x, y, buf, len) -Widget w; -GC gc; -Position x, y; -unsigned char * buf; -int len; +static void +AsciiPreparePaint(Widget w, int y, int line, + XawTextPosition from, XawTextPosition to, Bool highlight) { - AsciiSinkObject sink = (AsciiSinkObject) w; - TextWidget ctx = (TextWidget) XtParent(w); - - Position max_x; - Dimension width = XTextWidth(sink->ascii_sink.font, (char *) buf, len); - max_x = (Position) ctx->core.width; - - if ( ((int) width) <= -x) /* Don't draw if we can't see it. */ - return(width); - - XDrawImageString(XtDisplay(ctx), XtWindow(ctx), gc, - (int) x, (int) y, (char *) buf, len); - if ( (((Position) width + x) > max_x) && (ctx->text.margin.right != 0) ) { - x = ctx->core.width - ctx->text.margin.right; - width = ctx->text.margin.right; - XFillRectangle(XtDisplay((Widget) ctx), XtWindow( (Widget) ctx), - sink->ascii_sink.normgc, (int) x, - (int) y - sink->ascii_sink.font->ascent, - (unsigned int) width, - (unsigned int) (sink->ascii_sink.font->ascent + - sink->ascii_sink.font->descent)); - return(0); - } - return(width); + static XmuSegment segment; + static XmuScanline next; + static XmuScanline scanline = {0, &segment, &next}; + static XmuArea area = {&scanline}; + + TextWidget ctx = (TextWidget)XtParent(w); + AsciiSinkObject sink = (AsciiSinkObject)ctx->text.sink; + XawTextPosition left, right, pos, pos2, tmp, length; + XawTextAnchor *anchor; + XawTextEntity *entity; + XawTextProperty *property; + int i, ascent = 0, descent = 0, xl, xr, x = ctx->text.left_margin, bufsiz; + XawTextBlock block; + XFontStruct *font; + XawTextPaintStruct *paint; + + if (!sink->ascii_sink.echo) + return; + + /* pass 1: calculate ascent/descent values and x coordinate */ + /* XXX the MAX ascent/descent value should be in the line table XXX */ + /* XXX the x coordinate can be a parameter, but since it is required + to calculate the ascent/descent, do it here to avoid an extra + search in the entities */ + pos = tmp = left = ctx->text.lt.info[line].position; + right = ctx->text.lt.info[line + 1].position; + right = XawMin(right, ctx->text.lastPos + 1); + while (pos < right) { + if (XawTextSourceAnchorAndEntity(ctx->text.source, pos, + &anchor, &entity)) { + if ((property = XawTextSinkGetProperty((Widget)sink, + entity->property)) != NULL && + (property->mask & XAW_TPROP_FONT)) + font = property->font; + else + font = sink->ascii_sink.font; + tmp = pos; + pos = anchor->position + entity->offset + entity->length; + if ((length = XawMin(from, pos) - tmp) > 0) + x += GetTextWidth(ctx, x, font, tmp, length); + ascent = XawMax(font->ascent, ascent); + descent = XawMax(font->descent, descent); + } + else if (anchor) { + ascent = XawMax(sink->ascii_sink.font->ascent, ascent); + descent = XawMax(sink->ascii_sink.font->descent, descent); + while (entity && pos < right) { + tmp = pos; + if ((pos = anchor->position + entity->offset) < tmp) + pos = tmp; + else { + if ((length = XawMin(from, pos) - tmp) > 0) { + x += GetTextWidth(ctx, x, sink->ascii_sink.font, tmp, + length); + tmp += length; + } + if (pos < right) { + pos += entity->length; + if ((property = XawTextSinkGetProperty((Widget)sink, + entity->property)) != NULL && + (property->mask & XAW_TPROP_FONT)) + font = property->font; + else + font = sink->ascii_sink.font; + if ((length = XawMin(from, pos) - tmp) > 0) + x += GetTextWidth(ctx, x, font, tmp, length); + ascent = XawMax(font->ascent, ascent); + descent = XawMax(font->descent, descent); + } + } + entity = entity->next; + } + + if (anchor->entities == NULL) { + tmp = XawMin(pos, from); + if ((length = from - tmp) > 0) + x += GetTextWidth(ctx, x, sink->ascii_sink.font, tmp, length); + break; + } + } + else { + tmp = XawMin(pos, from); + if ((length = from - tmp) > 0) + x += GetTextWidth(ctx, x, sink->ascii_sink.font, tmp, length); + ascent = XawMax(sink->ascii_sink.font->ascent, ascent); + descent = XawMax(sink->ascii_sink.font->descent, descent); + break; + } + } + if (!ascent) + ascent = sink->ascii_sink.font->ascent; + if (!descent) + descent = sink->ascii_sink.font->descent; + + xl = x; + + /* pass 2: feed the XawTextPaintStruct lists */ + pos = from; + while (pos < to) { + paint = XtNew(XawTextPaintStruct); + paint->next = sink->text_sink.paint->paint; + sink->text_sink.paint->paint = paint; + paint->x = x; + paint->y = y + ascent; + paint->property = NULL; + paint->max_ascent = ascent; + paint->max_descent = descent; + paint->backtabs = NULL; + paint->highlight = highlight; + + tmp = pos; + if (XawTextSourceAnchorAndEntity(ctx->text.source, pos, + &anchor, &entity)) { + pos = anchor->position + entity->offset + entity->length; + if ((paint->property = XawTextSinkGetProperty((Widget)sink, + entity->property)) != NULL && + (paint->property->mask & XAW_TPROP_FONT)) + font = paint->property->font; + else + font = sink->ascii_sink.font; + } + else { + if (anchor) { + while (entity && anchor->position + entity->offset < pos) + entity = entity->next; + if (entity) + pos = anchor->position + entity->offset; + else + pos = to; + } + else + pos = to; + font = sink->ascii_sink.font; + } + pos = XawMin(pos, to); + length = pos - tmp; + + paint->text = XtMalloc(bufsiz = pos - tmp + 4); + paint->length = 0; + segment.x1 = x; + + pos2 = tmp; + while (length > 0) { + pos2 = XawTextSourceRead(ctx->text.source, tmp, &block, length); + length = pos - pos2; + tmp = pos2; + for (i = 0; i < block.length; i++) { + unsigned char c = (unsigned char)block.ptr[i]; + + if (paint->length + 4 > bufsiz) + paint->text = XtRealloc(paint->text, bufsiz += 32); + paint->text[paint->length] = c; + if (c == '\n') { + x += CharWidth(sink, font, 0, ' '); + continue; + } + if (c == '\t') { + x += XTextWidth(font, paint->text, paint->length); + segment.x2 = x + CharWidth(sink, font, x, '\t'); + + if (XmuValidSegment(&segment)) { + if (!highlight && (paint->property && + (paint->property->mask & XAW_TPROP_BACKGROUND))) { + if (ascent > font->ascent) { + scanline.y = y; + next.y = y + ascent - font->ascent; + XmuAreaOr(sink->text_sink.paint->clip, &area); + } + if (descent >= font->descent) { + scanline.y = y + ascent + font->descent; + next.y = scanline.y + descent - font->descent + 1; + XmuAreaOr(sink->text_sink.paint->clip, &area); + } + if (paint->backtabs == NULL) + paint->backtabs = XmuCreateArea(); + scanline.y = y + ascent - font->ascent; + next.y = y + ascent + font->descent; + XmuAreaOr(paint->backtabs, &area); + } + else { + scanline.y = y; + next.y = ctx->text.lt.info[line + 1].y; + if (highlight) { + if (!sink->text_sink.paint->hightabs) + sink->text_sink.paint->hightabs = + XmuCreateArea(); + XmuAreaOr(sink->text_sink.paint->hightabs, &area); + } + else + XmuAreaOr(sink->text_sink.paint->clip, &area); + } + } + + paint->width = segment.x2 - segment.x1; + x = segment.x1 = segment.x2; + + if (paint->length == 0) { + paint->x = x; + continue; + } + paint->text = XtRealloc(paint->text, paint->length); + property = paint->property; + paint = XtNew(XawTextPaintStruct); + paint->next = sink->text_sink.paint->paint; + sink->text_sink.paint->paint = paint; + paint->x = x; + paint->y = y + ascent; + paint->property = property; + paint->max_ascent = ascent; + paint->max_descent = descent; + paint->backtabs = NULL; + paint->highlight = highlight; + paint->text = XtMalloc(bufsiz = pos - tmp - length + + block.length - i + 4); + paint->length = 0; + continue; + } + if ((c & 0177) < XawSP || c == 0177) { + if (sink->ascii_sink.display_nonprinting) { + if (c > 0177) { + paint->text[paint->length++] = '\\'; + paint->text[paint->length++] = ((c >> 6) & 7) + '0'; + paint->text[paint->length++] = ((c >> 3) & 7) + '0'; + paint->text[paint->length] = (c & 7) + '0'; + } + else { + c |= 0100; + paint->text[paint->length++] = '^'; + paint->text[paint->length] = c == 0177 ? '?' : c; + } + } + else + paint->text[paint->length] = ' '; + } + paint->length++; + } + } + + x += XTextWidth(font, paint->text, paint->length); + segment.x2 = x; + if (XmuValidSegment(&segment)) { + /* erase only what really is needed */ + /*if (!highlight || (paint->property && + (paint->property->mask & XAW_TPROP_BACKGROUND))) { + if (ascent > font->ascent) { + scanline.y = y; + next.y = y + ascent - font->ascent; + XmuAreaOr(sink->text_sink.paint->clip, &area); + } + if (descent > font->descent) { + scanline.y = y + ascent + font->descent; + next.y = scanline.y + descent - font->descent; + XmuAreaOr(sink->text_sink.paint->clip, &area); + } + } + else*/ { + scanline.y = y; + next.y = ctx->text.lt.info[line + 1].y; + XmuAreaOr(sink->text_sink.paint->clip, &area); + } + } + + paint->width = x - segment.x1; + } + + xr = x; + + /* pass 3: bearing clipping */ + if (left < from) { + CalculateBearing(ctx, from - 1, xl, y, ascent, descent, highlight, True); + if (ctx->text.s.left < ctx->text.s.right) { + if (ctx->text.s.right == from) + CalculateBearing(ctx, from, xl, y, ascent, descent, True, False); + else if (ctx->text.s.left == from) + CalculateBearing(ctx, from, xl, y, ascent, descent, False, False); + } + } + right = XawMin(right, ctx->text.lastPos); + if (right >= to && to > from) { + if (to < right) + CalculateBearing(ctx, to, xr, y, ascent, descent, highlight, False); + if (ctx->text.s.left < ctx->text.s.right) { + if (ctx->text.s.right == to) + CalculateBearing(ctx, to - 1, xr, y, ascent, descent, False, True); + else if (ctx->text.s.left == to) + CalculateBearing(ctx, to - 1, xr, y, ascent, descent, True, True); + } + } +} + +static int +qcmp_paint_struct(_Xconst void *left, _Xconst void *right) +{ + return ((*(XawTextPaintStruct**)left)->property - + (*(XawTextPaintStruct**)right)->property); } -/* Sink Object Functions */ +static void +AsciiDoPaint(Widget w) +{ + TextWidget ctx = (TextWidget)XtParent(w); + AsciiSinkObject sink = (AsciiSinkObject)ctx->text.sink; + XmuScanline *scan; + XmuSegment *seg; + XawTextPaintList *list = sink->text_sink.paint; +#if 0 + XawTextPaintStruct *base, *head; +#endif + XawTextPaintStruct *paint = list->paint; + XawTextProperty *property; + XFontStruct *font = NULL; + XRectangle *rects; + int n_rects, i_rects; + GC gc; + Bool highlight; + XRectangle rect; + int width, height, line_width = -1; + XGCValues values; + + /* pass 1: clear clipping areas */ + /* XXX Don't use XDrawImageString because the font may be italic, and + will get incorrectly drawn. Probably, it could be a good idea to + check if this is the case, and do special processing. But this + will need to be checked if required. */ + for (scan = list->clip->scanline; scan && scan->next; scan = scan->next) + for (seg = scan->segment; seg; seg = seg->next) + _XawTextSinkClearToBackground(ctx->text.sink, + seg->x1, scan->y, + seg->x2 - seg->x1, + scan->next->y - scan->y); + + /* pass 2: optimize drawing list to avoid too much GC change requests */ + /* XXX this assumes there will not exist entities drawn over other + entities. */ +#if 0 + while (paint) { + base = paint; + head = paint->next; + while (head) { + if (head->property == paint->property) { + base->next = head->next; + head->next = paint->next; + paint->next = head; + paint = head; + } + base = head; + head = head->next; + } + paint = paint->next; + } +#endif + if (paint && paint->next) { + XawTextPaintStruct **paints; + int i = 0, n_paints = 0; + + while (paint) { + paint = paint->next; + ++n_paints; + } + paints = (XawTextPaintStruct**) + XtMalloc(n_paints * sizeof(XawTextPaintStruct)); + paint = list->paint; + while (paint) { + paints[i++] = paint; + paint = paint->next; + } + qsort((void*)paints, n_paints, sizeof(XawTextPaintStruct*), + qcmp_paint_struct); + list->paint = paints[0]; + for (i = 0; i < n_paints - 1; i++) + paints[i]->next = paints[i + 1]; + paints[i]->next = NULL; + XtFree((XtPointer)paints); + } + + /* pass 3: clip gc */ + gc = sink->ascii_sink.normgc; + + rect.x = ctx->text.r_margin.left; + rect.y = ctx->text.r_margin.top; + width = (int)XtWidth(ctx) - RHMargins(ctx); + height = (int)XtHeight(ctx) - RVMargins(ctx); + rect.width = width; + rect.height = height; + if (width >= 0 && height >= 0) + XSetClipRectangles(XtDisplay((Widget)ctx), gc, + 0, 0, &rect, 1, Unsorted); + else + XSetClipMask(XtDisplay((Widget)ctx), gc, None); + + /* pass 4: draw backgrounds */ + paint = list->paint; + property = NULL; + rects = NULL; + i_rects = n_rects = 0; + while (paint) { + if (paint->property && (paint->property->mask & XAW_TPROP_BACKGROUND)) { + if (property != paint->property) { + if (i_rects) + XFillRectangles(XtDisplay(ctx), XtWindow(ctx), gc, + rects, i_rects); + i_rects = 0; + property = paint->property; + if (property->mask & XAW_TPROP_FONT) + font = property->font; + else + font = sink->ascii_sink.font; + XSetForeground(XtDisplay(ctx), gc, property->background); + } + if (i_rects <= n_rects) + rects = (XRectangle*) + XtRealloc((XtPointer)rects, sizeof(XRectangle) * + ++n_rects); + rects[i_rects].x = paint->x; + rects[i_rects].y = paint->y - font->ascent; + rects[i_rects].width = paint->width; + rects[i_rects++].height = font->ascent + font->descent; + + if (paint->backtabs) { + for (scan = paint->backtabs->scanline; scan && scan->next; + scan = scan->next) + for (seg = scan->segment; seg; seg = seg->next) { + if (i_rects <= n_rects) + rects = (XRectangle*) + XtRealloc((XtPointer)rects, sizeof(XRectangle) * + ++n_rects); + rects[i_rects].x = seg->x1; + rects[i_rects].y = scan->y; + rects[i_rects].width = seg->x2 - seg->x1; + rects[i_rects++].height = scan->next->y - scan->y; + } + } + + + } + paint = paint->next; + } + if (i_rects) + XFillRectangles(XtDisplay(ctx), XtWindow(ctx), gc, rects, i_rects); + + paint = list->paint; + i_rects = 0; + while (paint) { + if (paint->highlight) { + if (i_rects == 0) + XSetForeground(XtDisplay(ctx), gc, sink->text_sink.cursor_color); + if (i_rects <= n_rects) + rects = (XRectangle*) + XtRealloc((XtPointer)rects, sizeof(XRectangle) * + ++n_rects); + rects[i_rects].x = paint->x; + rects[i_rects].y = paint->y - paint->max_ascent; + rects[i_rects].width = paint->width; + rects[i_rects++].height = paint->max_ascent + paint->max_descent + 1; + } + paint = paint->next; + } + if (list->hightabs) { + for (scan = list->hightabs->scanline; scan && scan->next; + scan = scan->next) + for (seg = scan->segment; seg; seg = seg->next) { + if (i_rects == 0) + XSetForeground(XtDisplay(ctx), gc, + sink->text_sink.cursor_color); + if (i_rects <= n_rects) + rects = (XRectangle*) + XtRealloc((XtPointer)rects, sizeof(XRectangle) * + ++n_rects); + rects[i_rects].x = seg->x1; + rects[i_rects].y = scan->y; + rects[i_rects].width = seg->x2 - seg->x1; + rects[i_rects++].height = scan->next->y - scan->y; + } + } + + if (i_rects) + XFillRectangles(XtDisplay(ctx), XtWindow(ctx), gc, rects, i_rects); + if (rects) + XtFree((XtPointer)rects); + + /* pass 5: draw text! */ + paint = list->paint; + if (paint && (property = paint->property) == NULL) { + font = sink->ascii_sink.font; + XSetFont(XtDisplay(ctx), gc, font->fid); + if (!paint->highlight) + XSetForeground(XtDisplay(ctx), gc, sink->text_sink.foreground); + } + else + property = NULL; + highlight = False; + while (paint) { + if (!highlight && paint->highlight) + XSetForeground(XtDisplay(ctx), gc, sink->text_sink.background); + if (highlight || paint->highlight || paint->property != property) { + if (!paint->property || !(paint->property->mask & XAW_TPROP_FONT)) + font = sink->ascii_sink.font; + else + font = paint->property->font; + XSetFont(XtDisplay(ctx), gc, font->fid); + if (!paint->highlight) { + if (!paint->property || + !(paint->property->mask & XAW_TPROP_FOREGROUND)) + XSetForeground(XtDisplay(ctx), gc, + sink->text_sink.foreground); + else + XSetForeground(XtDisplay(ctx), gc, + paint->property->foreground); + } + highlight = paint->highlight; + property = paint->property; + } + + if (paint->x < XtWidth(ctx) && paint->x + paint->width > 0) { + XDrawString(XtDisplay(ctx), XtWindow(ctx), gc, paint->x, paint->y, + paint->text, paint->length); + if (property) { + if (property->mask & XAW_TPROP_UNDERLINE) { + if (line_width != property->underline_thickness) { + values.line_width = line_width = + property->underline_thickness; + XChangeGC(XtDisplay(ctx), gc, GCLineWidth, &values); + } + + XDrawLine(XtDisplay(ctx), XtWindow(ctx), gc, paint->x, + paint->y + property->underline_position, + paint->x + paint->width, + paint->y + property->underline_position); + } + if (property->mask & XAW_TPROP_OVERSTRIKE) { + if (line_width != property->underline_thickness) { + values.line_width = line_width = + property->underline_thickness; + XChangeGC(XtDisplay(ctx), gc, GCLineWidth, &values); + } + + XDrawLine(XtDisplay(ctx), XtWindow(ctx), gc, paint->x, + paint->y - (font->ascent>>1) + (font->descent>>1), + paint->x + paint->width, + paint->y - (font->ascent>>1) + (font->descent>>1)); + } + } + } + + paint = paint->next; + } + + /* pass 6: bearing clipping */ + /* dont care on order of drawing or caching of state (by now) */ + paint = list->bearings; + while (paint) { + XRectangle rect; + + if (paint->highlight) + XSetForeground(XtDisplay(ctx), gc, sink->text_sink.background); + if (!paint->property || !(paint->property->mask & XAW_TPROP_FONT)) + font = sink->ascii_sink.font; + else + font = paint->property->font; + XSetFont(XtDisplay(ctx), gc, font->fid); + if (!paint->highlight) { + if (!paint->property || + !(paint->property->mask & XAW_TPROP_FOREGROUND)) + XSetForeground(XtDisplay(ctx), gc, sink->text_sink.foreground); + else + XSetForeground(XtDisplay(ctx), gc, paint->property->foreground); + } + if (paint->x < XtWidth(ctx) && paint->x + paint->width > 0) { + rect.x = paint->x + paint->width; + rect.width = XawAbs(paint->width); /* more than enough */ + rect.y = paint->y - font->ascent; + rect.height = rect.y + font->ascent + font->descent; + XSetClipRectangles(XtDisplay((Widget)ctx), gc, + 0, 0, &rect, 1, Unsorted); + XDrawString(XtDisplay(ctx), XtWindow(ctx), gc, paint->x, paint->y, + paint->text, paint->length); + } + paint = paint->next; + } +} +#endif /* - * This function does not know about drawing more than one line of text. + * Function: + * PaintText + * + * Parameters: + * w - text sink object + * gc - gc to paint text with + * x - location to paint the text + * y - "" + * buf - buffer and length of text to paint. + * len - "" + * clear_bg - clear background before drawing ? + * + * Description: + * Actually paints the text into the window. + * + * Returns: + * the width of the text painted */ - -static void -DisplayText(w, x, y, pos1, pos2, highlight) -Widget w; -Position x, y; -Boolean highlight; -XawTextPosition pos1, pos2; +static unsigned int +PaintText(Widget w, GC gc, int x, int y, char *buf, int len, Bool clear_bg) { - AsciiSinkObject sink = (AsciiSinkObject) w; - Widget source = XawTextGetSource(XtParent(w)); - unsigned char buf[BUFSIZ]; + AsciiSinkObject sink = (AsciiSinkObject)w; + TextWidget ctx = (TextWidget)XtParent(w); + int width = XTextWidth(sink->ascii_sink.font, buf, len); + + if ((x > XtWidth(ctx)) || width <= -x) /* Don't draw if we can't see it */ + return (width); + + if (clear_bg) { + _XawTextSinkClearToBackground(w, x, y - sink->ascii_sink.font->ascent, + width, sink->ascii_sink.font->ascent + + sink->ascii_sink.font->descent); + XDrawString(XtDisplay(ctx), XtWindow(ctx), gc, x, y, buf, len); + } + else + XDrawImageString(XtDisplay(ctx), XtWindow(ctx), gc, x, y, buf, len); + + return (width); +} +static void +DisplayText(Widget w, int x, int y, + XawTextPosition pos1, XawTextPosition pos2, Bool highlight) +{ + TextWidget ctx = (TextWidget)XtParent(w); + AsciiSinkObject sink = (AsciiSinkObject)w; + XFontStruct *font = sink->ascii_sink.font; + Widget source = XawTextGetSource(XtParent(w)); + unsigned char buf[260]; int j, k; XawTextBlock blk; - GC gc = highlight ? sink->ascii_sink.invgc : sink->ascii_sink.normgc; - GC invgc = highlight ? sink->ascii_sink.normgc : sink->ascii_sink.invgc; + GC gc, invgc, tabgc; + int max_x; + Bool clear_bg; + + if (!sink->ascii_sink.echo || !ctx->text.lt.lines) + return; + + max_x = (int)XtWidth(ctx) - ctx->text.r_margin.right; + clear_bg = !highlight && ctx->core.background_pixmap != XtUnspecifiedPixmap; - if (!sink->ascii_sink.echo) return; + gc = highlight ? sink->ascii_sink.invgc : sink->ascii_sink.normgc; + invgc = highlight ? sink->ascii_sink.normgc : sink->ascii_sink.invgc; + + if (highlight && sink->ascii_sink.xorgc) + tabgc = sink->ascii_sink.xorgc; + else + tabgc = invgc; y += sink->ascii_sink.font->ascent; - for ( j = 0 ; pos1 < pos2 ; ) { - pos1 = XawTextSourceRead(source, pos1, &blk, (int) pos2 - pos1); + for (j = 0; pos1 < pos2;) { + pos1 = XawTextSourceRead(source, pos1, &blk, pos2 - pos1); for (k = 0; k < blk.length; k++) { - if (j >= BUFSIZ) { /* buffer full, dump the text. */ - x += PaintText(w, gc, x, y, buf, j); + if (j >= sizeof(buf) - 4) { /* buffer full, dump the text */ + if ((x += PaintText(w, gc, x, y, (char*)buf, j, clear_bg)) + >= max_x) + return; j = 0; } buf[j] = blk.ptr[k]; - if (buf[j] == XawLF) /* line feeds ('\n') are not printed. */ - continue; + if (buf[j] == XawLF) /* line feeds ('\n') are not printed */ + continue; else if (buf[j] == '\t') { - Position temp = 0; - Dimension width; - - if ((j != 0) && ((temp = PaintText(w, gc, x, y, buf, j)) == 0)) - return; - - x += temp; - width = CharWidth(w, x, (unsigned char) '\t'); - XFillRectangle(XtDisplayOfObject(w), XtWindowOfObject(w), - invgc, (int) x, - (int) y - sink->ascii_sink.font->ascent, - (unsigned int) width, - (unsigned int) (sink->ascii_sink.font->ascent + - sink->ascii_sink.font->descent)); - x += width; + int width; + + if (j != 0 + && (x += PaintText(w, gc, x, y, (char*)buf, j, clear_bg)) + >= max_x) + return; + + if ((width = CharWidth(sink, font, x, '\t')) > -x) { + if (clear_bg) + _XawTextSinkClearToBackground(w, x, y-font->ascent, width, + font->ascent+font->descent); + else + XFillRectangle(XtDisplayOfObject(w), XtWindowOfObject(w), + tabgc, x, y - font->ascent, width, + font->ascent + font->descent); + } + + if ((x += width) >= max_x) + return; + j = -1; } - else if ( buf[j] < (unsigned char) ' ' ) { - if (sink->ascii_sink.display_nonprinting) { - buf[j + 1] = buf[j] + '@'; - buf[j] = '^'; - j++; + else if ((buf[j] & 0177) < XawSP || buf[j] == 0177) { + if (sink->ascii_sink.display_nonprinting) { + unsigned char c = buf[j]; + + if (c > 0177) { + buf[j++] = '\\'; + buf[j++] = ((c >> 6) & 7) + '0'; + buf[j++] = ((c >> 3) & 7) + '0'; + buf[j] = (c & 7) + '0'; + } + else { + c |= 0100; + buf[j++] = '^'; + buf[j] = c == 0177 ? '?' : c; + } } else - buf[j] = ' '; + buf[j] = ' '; } j++; } } - if (j > 0) - (void) PaintText(w, gc, x, y, buf, j); -} -#define insertCursor_width 6 -#define insertCursor_height 3 -static char insertCursor_bits[] = {0x0c, 0x1e, 0x33}; - -static Pixmap -CreateInsertCursor(s) -Screen *s; -{ - return (XCreateBitmapFromData (DisplayOfScreen(s), RootWindowOfScreen(s), - insertCursor_bits, insertCursor_width, insertCursor_height)); + if (j > 0) + (void)PaintText(w, gc, x, y, (char*)buf, j, clear_bg); } -/* Function Name: GetCursorBounds - * Description: Returns the size and location of the cursor. - * Arguments: w - the text object. - * RETURNED rect - an X rectangle to return the cursor bounds in. - * Returns: none. +/* + * Function: + * GetCursorBounds + * + * Parameters: + * w - text sink object + * rect - X rectangle to return the cursor bounds + * + * Description: + * Returns the size and location of the cursor. */ - static void -GetCursorBounds(w, rect) -Widget w; -XRectangle * rect; +GetCursorBounds(Widget w, XRectangle *rect) { - AsciiSinkObject sink = (AsciiSinkObject) w; + AsciiSinkObject sink = (AsciiSinkObject)w; + XFontStruct *font = sink->ascii_sink.font; + unsigned char ch; +#ifndef OLDXAW + TextWidget ctx = (TextWidget)XtParent(w); + XawTextBlock block; + XawTextAnchor *anchor; + XawTextEntity *entity; + XawTextProperty *property; + + if (XawTextSourceAnchorAndEntity(XawTextGetSource(XtParent(w)), + sink->ascii_sink.cursor_position, + &anchor, &entity)) { + if ((property = XawTextSinkGetProperty((Widget)sink, + entity->property)) != NULL && + (property->mask & XAW_TPROP_FONT)) + font = property->font; + } + (void)XawTextSourceRead(XawTextGetSource((Widget)ctx), + ctx->text.insertPos, &block, 1); + if (!block.length || block.ptr[0] == '\n' || block.ptr[0] == '\t') + ch = ' '; + else if ((*((unsigned char*)block.ptr) & 0177) < XawSP || + *(unsigned char*)block.ptr == 0177) { + if (sink->ascii_sink.display_nonprinting) + ch = *((unsigned char*)block.ptr) > 0177 ? '\\' : '^'; + else + ch = ' '; + } + else + ch = *(unsigned char*)block.ptr; +#else + ch = ' '; +#endif + + rect->width = CharWidth(sink, font, 0, ch); + rect->height = font->descent + font->ascent + 1; - rect->width = (unsigned short) insertCursor_width; - rect->height = (unsigned short) insertCursor_height; - rect->x = sink->ascii_sink.cursor_x - (short) (rect->width / 2); - rect->y = sink->ascii_sink.cursor_y - (short) rect->height; + rect->x = sink->ascii_sink.cursor_x; + rect->y = sink->ascii_sink.cursor_y - font->ascent; } -/* - * The following procedure manages the "insert" cursor. +/* this function is required to support diferent fonts and correctly place + * the cursor. There are better ways to calculate the base line, but there is + * no place/code (yet) to store this information. */ +static int +FindCursorY(TextWidget ctx, XawTextPosition position) +{ + int y, line, ascent; + AsciiSinkObject sink = (AsciiSinkObject)ctx->text.sink; +#ifndef OLDXAW + XawTextAnchor *anchor; + XawTextEntity *entity; + XawTextProperty *property; + XawTextPosition left, right; +#endif + + for (line = 0; line < ctx->text.lt.lines; line++) + if (position < ctx->text.lt.info[line + 1].position) + break; + + y = ctx->text.lt.info[line].y; +#ifndef OLDXAW + ascent = 0; + left = ctx->text.lt.info[line].position; + right = ctx->text.lt.info[line + 1].position; + right = XawMin(right, ctx->text.lastPos + 1); + while (left < right) { + if (XawTextSourceAnchorAndEntity(ctx->text.source, left, + &anchor, &entity)) { + if ((property = XawTextSinkGetProperty((Widget)sink, + entity->property)) != NULL && + (property->mask & XAW_TPROP_FONT)) + ascent = XawMax(property->font->ascent, ascent); + else + ascent = XawMax(sink->ascii_sink.font->ascent, ascent); + left = anchor->position + entity->offset + entity->length; + } + else if (anchor) { + ascent = XawMax(sink->ascii_sink.font->ascent, ascent); + while (entity) { + XawTextPosition tmp = anchor->position + entity->offset + entity->length; + + if (tmp > left && tmp < right) { + left = tmp; + if ((property = XawTextSinkGetProperty((Widget)sink, + entity->property)) != NULL && + (property->mask & XAW_TPROP_FONT)) + ascent = XawMax(property->font->ascent, ascent); + else + ascent = XawMax(sink->ascii_sink.font->ascent, ascent); + } + entity = entity->next; + } + if (entity == NULL) + break; + } + else { + ascent = XawMax(sink->ascii_sink.font->ascent, ascent); + break; + } + } + if (!ascent) + ascent = sink->ascii_sink.font->ascent; +#else + ascent = sink->ascii_sink.font->ascent; +#endif + + return (y + ascent); +} static void -InsertCursor (w, x, y, state) -Widget w; -Position x, y; -XawTextInsertState state; +InsertCursor(Widget w, int x, int y, XawTextInsertState state) { - AsciiSinkObject sink = (AsciiSinkObject) w; - Widget text_widget = XtParent(w); - XRectangle rect; + AsciiSinkObject sink = (AsciiSinkObject)w; + XFontStruct *font = sink->ascii_sink.font; + TextWidget ctx = (TextWidget)XtParent(w); + XawTextPosition position = XawTextGetInsertionPoint((Widget)ctx); + Boolean overflow = (x & 0xffff8000) != 0; +#ifndef OLDXAW + XawTextAnchor *anchor; + XawTextEntity *entity; + XawTextProperty *property; +#endif - sink->ascii_sink.cursor_x = x; - sink->ascii_sink.cursor_y = y; + if (XtIsRealized((Widget)ctx)) { + int fheight; + XawTextBlock block; + XawTextPosition selection_start, selection_end; + Boolean has_selection; + + if (!sink->ascii_sink.echo) { + if (sink->ascii_sink.laststate != state) { + int width = CharWidth(sink, font, 0, ' ') - 1; + + x = ctx->text.margin.left; + y = ctx->text.margin.top; + font = sink->ascii_sink.font; + fheight = font->ascent + font->descent; + if (state == XawisOn) { + if (ctx->text.hasfocus) + XFillRectangle(XtDisplay(ctx), XtWindow(ctx), + sink->ascii_sink.xorgc, x, y, + width + 1, fheight + 1); + else + XDrawRectangle(XtDisplay(ctx), XtWindow(ctx), + sink->ascii_sink.xorgc, x, y, + width, fheight); - GetCursorBounds(w, &rect); - if (state != sink->ascii_sink.laststate && XtIsRealized(text_widget)) - XCopyPlane(XtDisplay(text_widget), - sink->ascii_sink.insertCursorOn, - XtWindow(text_widget), sink->ascii_sink.xorgc, - 0, 0, (unsigned int) rect.width, (unsigned int) rect.height, - (int) rect.x, (int) rect.y, 1); + } + else + _XawTextSinkClearToBackground(w, x, y, + width + 1, fheight + 1); + } + sink->ascii_sink.cursor_x = x; + sink->ascii_sink.cursor_y = y; + sink->ascii_sink.laststate = state; + return; + } + + + XawTextGetSelectionPos((Widget)ctx, &selection_start, &selection_end); + has_selection = selection_start != selection_end; + + if (sink->ascii_sink.laststate != state) { + unsigned char ch; + +#ifndef OLDXAW + if (XawTextSourceAnchorAndEntity(ctx->text.source, + position, &anchor, &entity) && + (property = XawTextSinkGetProperty((Widget)sink, + entity->property)) != NULL && + (property->mask & XAW_TPROP_FONT)) + font = property->font; + else + font = sink->ascii_sink.font; +#endif + + fheight = font->ascent + font->descent; + (void)XawTextSourceRead(XawTextGetSource((Widget)ctx), + position, &block, 1); + if (!block.length || block.ptr[0] == '\n' || block.ptr[0] == '\t') + ch = ' '; + else if ((*((unsigned char*)block.ptr) & 0177) < XawSP + || *(unsigned char*)block.ptr == 0177) { + if (sink->ascii_sink.display_nonprinting) + ch = *((unsigned char*)block.ptr) > 0177 ? '\\' : '^'; + else + ch = ' '; + } + else + ch = *(unsigned char*)block.ptr; + + y = FindCursorY(ctx, position); + if (ctx->text.hasfocus && !has_selection) + XFillRectangle(XtDisplay(ctx), XtWindow(ctx), + sink->ascii_sink.xorgc, x, y - font->ascent, + CharWidth(sink, font, 0, ch), fheight + 1); + else + XDrawRectangle(XtDisplay(ctx), XtWindow(ctx), + sink->ascii_sink.xorgc, x, y - font->ascent, + CharWidth(sink, font, 0, ch) - 1, fheight); + } + } + + sink->ascii_sink.cursor_x = overflow ? -16384 : x; + sink->ascii_sink.cursor_y = y; sink->ascii_sink.laststate = state; + sink->ascii_sink.cursor_position = position; } /* - * Given two positions, find the distance between them. + * Given two positions, find the distance between them */ - static void -FindDistance (w, fromPos, fromx, toPos, resWidth, resPos, resHeight) -Widget w; -XawTextPosition fromPos; /* First position. */ -int fromx; /* Horizontal location of first position. */ -XawTextPosition toPos; /* Second position. */ -int *resWidth; /* Distance between fromPos and resPos. */ -XawTextPosition *resPos; /* Actual second position used. */ -int *resHeight; /* Height required. */ +FindDistance(Widget w, XawTextPosition fromPos, int fromx, + XawTextPosition toPos, int *resWidth, + XawTextPosition *resPos, int *resHeight) { - AsciiSinkObject sink = (AsciiSinkObject) w; - Widget source = XawTextGetSource(XtParent(w)); - - XawTextPosition index, lastPos; +#ifndef OLDXAW + AsciiSinkObject sink = (AsciiSinkObject)w; + TextWidget ctx = (TextWidget)XtParent(w); + XFontStruct *font = sink->ascii_sink.font; + Widget source = ctx->text.source; + XawTextPosition idx, pos; unsigned char c; XawTextBlock blk; + int i, rWidth, ascent = 0, descent = 0; + XawTextAnchor *anchor; + XawTextEntity *entity; + XawTextProperty *property; + Cardinal length; + Bool done = False; + + pos = idx = fromPos; + rWidth = 0; + c = 0; + + while (!done) { + if (XawTextSourceAnchorAndEntity(source, pos, &anchor, &entity)) { + length = anchor->position + entity->offset + entity->length; + length = XawMin(toPos, length) - pos; + if ((property = XawTextSinkGetProperty((Widget)sink, + entity->property)) != NULL && + (property->mask & XAW_TPROP_FONT)) + font = property->font; + else + font = sink->ascii_sink.font; + } + else { + if (anchor) { + while (entity && anchor->position + entity->offset < pos) + entity = entity->next; + if (entity) { + length = anchor->position + entity->offset; + length = XawMin(toPos, length) - pos; + } + else + length = XawMin(toPos - pos, 4096); + } + else + length = XawMin(toPos - pos, 4096); + font = sink->ascii_sink.font; + } + + ascent = XawMax(font->ascent, ascent); + descent = XawMax(font->descent, descent); + + pos = XawTextSourceRead(source, pos, &blk, length); + if (blk.length == 0 && pos == idx) /* eof reached */ + break; + + idx = blk.firstPos; + for (i = 0; idx < toPos; i++, idx++) { + if (i >= blk.length) + break; + c = blk.ptr[i]; + rWidth += CharWidth(sink, font, fromx + rWidth, c); + if (c == XawLF) { + idx++; + done = True; + break; + } + } + if (idx >= toPos) + break; + } - /* we may not need this */ - lastPos = GETLASTPOS; - XawTextSourceRead(source, fromPos, &blk, (int) toPos - fromPos); - *resWidth = 0; - for (index = fromPos; index != toPos && index < lastPos; index++) { - if (index - blk.firstPos >= blk.length) - XawTextSourceRead(source, index, &blk, (int) toPos - fromPos); - c = blk.ptr[index - blk.firstPos]; - *resWidth += CharWidth(w, fromx + *resWidth, c); + *resPos = idx; + *resWidth = rWidth; + *resHeight = ascent + descent + 1; +#else + AsciiSinkObject sink = (AsciiSinkObject)w; + TextWidget ctx = (TextWidget)XtParent(w); + XFontStruct *font = sink->ascii_sink.font; + Widget source = ctx->text.source; + XawTextPosition idx, pos; + unsigned char c; + XawTextBlock blk; + int i, rWidth; + + pos = XawTextSourceRead(source, fromPos, &blk, toPos - fromPos); + rWidth = 0; + for (i = 0, idx = fromPos; idx < toPos; i++, idx++) { + if (i >= blk.length) { + i = 0; + pos = XawTextSourceRead(source, pos, &blk, toPos - pos); + if (blk.length == 0) + break; + } + c = blk.ptr[i]; + rWidth += CharWidth(sink, font, fromx + rWidth, c); if (c == XawLF) { - index++; + idx++; break; } } - *resPos = index; - *resHeight = sink->ascii_sink.font->ascent +sink->ascii_sink.font->descent; -} + *resPos = idx; + *resWidth = rWidth; + *resHeight = font->ascent + font->descent + 1; +#endif +} static void -FindPosition(w, fromPos, fromx, width, stopAtWordBreak, - resPos, resWidth, resHeight) -Widget w; -XawTextPosition fromPos; /* Starting position. */ -int fromx; /* Horizontal location of starting position.*/ -int width; /* Desired width. */ -int stopAtWordBreak; /* Whether the resulting position should be at - a word break. */ -XawTextPosition *resPos; /* Resulting position. */ -int *resWidth; /* Actual width used. */ -int *resHeight; /* Height required. */ +FindPosition(Widget w, XawTextPosition fromPos, int fromx, int width, + Bool stopAtWordBreak, XawTextPosition *resPos, + int *resWidth, int *resHeight) { - AsciiSinkObject sink = (AsciiSinkObject) w; - Widget source = XawTextGetSource(XtParent(w)); - - XawTextPosition lastPos, index, whiteSpacePosition; - int lastWidth, whiteSpaceWidth; +#ifndef OLDXAW + AsciiSinkObject sink = (AsciiSinkObject)w; + TextWidget ctx = (TextWidget)XtParent(w); + Widget source = ctx->text.source; + XFontStruct *font = sink->ascii_sink.font; + XawTextPosition idx, pos, whiteSpacePosition = 0; + int i, lastWidth, whiteSpaceWidth, rWidth, ascent = 0, descent = 0; Boolean whiteSpaceSeen; unsigned char c; XawTextBlock blk; + XawTextAnchor *anchor; + XawTextEntity *entity; + XawTextProperty *property; + Cardinal length; + Bool done = False; + + pos = idx = fromPos; + rWidth = lastWidth = whiteSpaceWidth = 0; + whiteSpaceSeen = False; + c = 0; + + while (!done) { + font = sink->ascii_sink.font; + if (XawTextSourceAnchorAndEntity(source, pos, &anchor, &entity)) { + length = anchor->position + entity->offset + entity->length - pos; + if ((property = XawTextSinkGetProperty((Widget)sink, + entity->property)) != NULL && + (property->mask & XAW_TPROP_FONT)) + font = property->font; + } + else { + if (anchor) { + while (entity && anchor->position + entity->offset < pos) + entity = entity->next; + if (entity) + length = anchor->position + entity->offset - pos; + else + length = 4096; + } + else + length = 4096; + } + + ascent = XawMax(font->ascent, ascent); + descent = XawMax(font->descent, descent); - lastPos = GETLASTPOS; + pos = XawTextSourceRead(source, pos, &blk, length); + if (blk.length == 0 && pos == idx) /* eof reached */ + break; + + idx = blk.firstPos; + for (i = 0; rWidth <= width && i < blk.length; i++, idx++) { + c = blk.ptr[i]; + lastWidth = rWidth; + rWidth += CharWidth(sink, font, fromx + rWidth, c); + + if (c == XawLF) { + idx++; + done = True; + break; + } + else if ((c == XawSP || c == XawTAB) && rWidth <= width) { + whiteSpaceSeen = True; + whiteSpacePosition = idx; + whiteSpaceWidth = rWidth; + } + } + if (rWidth > width) + break; + } + + if (rWidth > width && idx > fromPos) { + idx--; + rWidth = lastWidth; + if (stopAtWordBreak && whiteSpaceSeen) { + idx = whiteSpacePosition + 1; + rWidth = whiteSpaceWidth; + } + } + + if (idx >= ctx->text.lastPos && c != XawLF) + idx = ctx->text.lastPos + 1; - XawTextSourceRead(source, fromPos, &blk, BUFSIZ); - *resWidth = 0; - whiteSpaceSeen = FALSE; + *resPos = idx; + *resWidth = rWidth; + *resHeight = ascent + descent + 1; +#else + AsciiSinkObject sink = (AsciiSinkObject)w; + TextWidget ctx = (TextWidget)XtParent(w); + Widget source = ctx->text.source; + XFontStruct *font = sink->ascii_sink.font; + XawTextPosition idx, pos, whiteSpacePosition = 0; + int i, lastWidth, whiteSpaceWidth, rWidth; + Boolean whiteSpaceSeen; + unsigned char c; + XawTextBlock blk; + + pos = XawTextSourceRead(source, fromPos, &blk, BUFSIZ); + rWidth = lastWidth = whiteSpaceWidth = 0; + whiteSpaceSeen = False; c = 0; - for (index = fromPos; *resWidth <= width && index < lastPos; index++) { - lastWidth = *resWidth; - if (index - blk.firstPos >= blk.length) - XawTextSourceRead(source, index, &blk, BUFSIZ); - c = blk.ptr[index - blk.firstPos]; - *resWidth += CharWidth(w, fromx + *resWidth, c); - - if ((c == XawSP || c == XawTAB) && *resWidth <= width) { - whiteSpaceSeen = TRUE; - whiteSpacePosition = index; - whiteSpaceWidth = *resWidth; + + for (i = 0, idx = fromPos; rWidth <= width; i++, idx++) { + if (i >= blk.length) { + i = 0; + pos = XawTextSourceRead(source, pos, &blk, BUFSIZ); + if (blk.length == 0) + break; } + c = blk.ptr[i]; + lastWidth = rWidth; + rWidth += CharWidth(sink, font, fromx + rWidth, c); + if (c == XawLF) { - index++; + idx++; break; } + else if ((c == XawSP || c == XawTAB) && rWidth <= width) { + whiteSpaceSeen = True; + whiteSpacePosition = idx; + whiteSpaceWidth = rWidth; + } } - if (*resWidth > width && index > fromPos) { - *resWidth = lastWidth; - index--; + + if (rWidth > width && idx > fromPos) { + idx--; + rWidth = lastWidth; if (stopAtWordBreak && whiteSpaceSeen) { - index = whiteSpacePosition + 1; - *resWidth = whiteSpaceWidth; + idx = whiteSpacePosition + 1; + rWidth = whiteSpaceWidth; } } - if (index == lastPos && c != XawLF) index = lastPos + 1; - *resPos = index; - *resHeight = sink->ascii_sink.font->ascent +sink->ascii_sink.font->descent; + + if (idx >= ctx->text.lastPos && c != XawLF) + idx = ctx->text.lastPos + 1; + + *resPos = idx; + *resWidth = rWidth; + *resHeight = font->ascent + font->descent + 1; +#endif } static void -Resolve (w, pos, fromx, width, leftPos, rightPos) -Widget w; -XawTextPosition pos; -int fromx, width; -XawTextPosition *leftPos, *rightPos; +Resolve(Widget w, XawTextPosition pos, int fromx, int width, + XawTextPosition *pos_return) { int resWidth, resHeight; Widget source = XawTextGetSource(XtParent(w)); - FindPosition(w, pos, fromx, width, FALSE, leftPos, &resWidth, &resHeight); - if (*leftPos > GETLASTPOS) - *leftPos = GETLASTPOS; - *rightPos = *leftPos; + FindPosition(w, pos, fromx, width, False, pos_return, &resWidth, &resHeight); + if (*pos_return > GETLASTPOS) + *pos_return = GETLASTPOS; } static void -GetGC(sink) -AsciiSinkObject sink; +GetGC(AsciiSinkObject sink) { - XtGCMask valuemask = (GCFont | - GCGraphicsExposures | GCForeground | GCBackground ); + XtGCMask valuemask = (GCFont | GCGraphicsExposures | GCClipXOrigin | + GCForeground | GCBackground); XGCValues values; + /* XXX We dont want do share a gc that will change the clip-mask */ + values.clip_x_origin = (long)sink; + values.clip_mask = None; values.font = sink->ascii_sink.font->fid; - values.graphics_exposures = (Bool) FALSE; - + values.graphics_exposures = False; + values.foreground = sink->text_sink.foreground; values.background = sink->text_sink.background; - sink->ascii_sink.normgc = XtGetGC((Widget)sink, valuemask, &values); - + sink->ascii_sink.normgc = XtAllocateGC((Widget)sink, 0, valuemask, &values, + GCClipMask | GCFont | GCForeground | + GCBackground, 0); + values.foreground = sink->text_sink.background; +#ifndef OLDXAW + values.background = sink->text_sink.cursor_color; +#else values.background = sink->text_sink.foreground; - sink->ascii_sink.invgc = XtGetGC((Widget)sink, valuemask, &values); - - values.function = GXxor; - values.background = (unsigned long) 0L; /* (pix ^ 0) = pix */ - values.foreground = (sink->text_sink.background ^ - sink->text_sink.foreground); - valuemask = GCGraphicsExposures | GCFunction | GCForeground | GCBackground; - - sink->ascii_sink.xorgc = XtGetGC((Widget)sink, valuemask, &values); -} +#endif + sink->ascii_sink.invgc = XtAllocateGC((Widget)sink, 0, valuemask, &values, + GCClipMask | GCFont, 0); + valuemask |= GCFunction; + values.function = GXxor; +#ifndef OLDXAW + values.foreground = sink->text_sink.background ^ sink->text_sink.cursor_color; +#else + values.foreground = sink->text_sink.background ^ sink->text_sink.foreground; +#endif + values.background = 0L; + sink->ascii_sink.xorgc = XtAllocateGC((Widget)sink, 0, valuemask, + &values, GCClipMask | GCFont, 0); -/***** Public routines *****/ + XawAsciiSinkResize((Widget)sink); +} -/* Function Name: Initialize - * Description: Initializes the TextSink Object. - * Arguments: request, new - the requested and new values for the object - * instance. - * Returns: none. +/* Function: + * XawAsciiSinkInitialize * + * Parameters: + * request - the requested and new values for the object instance + * cnew - "" + * + * Description: + * Initializes the TextSink Object. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -Initialize(request, new, args, num_args) -Widget request, new; -ArgList args; -Cardinal *num_args; +XawAsciiSinkInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - AsciiSinkObject sink = (AsciiSinkObject) new; + AsciiSinkObject sink = (AsciiSinkObject)cnew; GetGC(sink); - - sink->ascii_sink.insertCursorOn= CreateInsertCursor(XtScreenOfObject(new)); + + sink->ascii_sink.cursor_position = 0; sink->ascii_sink.laststate = XawisOff; sink->ascii_sink.cursor_x = sink->ascii_sink.cursor_y = 0; } -/* Function Name: Destroy - * Description: This function cleans up when the object is - * destroyed. - * Arguments: w - the AsciiSink Object. - * Returns: none. +/* + * Function: + * XawAsciiSinkDestroy + * + * Parameters: + * w - AsciiSink Object + * + * Description: + * This function cleans up when the object is destroyed. */ - static void -Destroy(w) -Widget w; +XawAsciiSinkDestroy(Widget w) { - AsciiSinkObject sink = (AsciiSinkObject) w; + AsciiSinkObject sink = (AsciiSinkObject)w; + + XtReleaseGC(w, sink->ascii_sink.normgc); + XtReleaseGC(w, sink->ascii_sink.invgc); + XtReleaseGC(w, sink->ascii_sink.xorgc); - XtReleaseGC(w, sink->ascii_sink.normgc); - XtReleaseGC(w, sink->ascii_sink.invgc); - XtReleaseGC(w, sink->ascii_sink.xorgc); - XFreePixmap(XtDisplayOfObject(w), sink->ascii_sink.insertCursorOn); + sink->ascii_sink.normgc = + sink->ascii_sink.invgc = + sink->ascii_sink.xorgc = NULL; } -/* Function Name: SetValues - * Description: Sets the values for the AsciiSink - * Arguments: current - current state of the object. - * request - what was requested. - * new - what the object will become. - * Returns: True if redisplay is needed. - */ +static void +XawAsciiSinkResize(Widget w) +{ + TextWidget ctx = (TextWidget)XtParent(w); + AsciiSinkObject sink = (AsciiSinkObject)w; + XRectangle rect; + int width, height; + + if (w->core.widget_class != asciiSinkObjectClass) + return; + + rect.x = ctx->text.r_margin.left; + rect.y = ctx->text.r_margin.top; + width = (int)XtWidth(ctx) - RHMargins(ctx); + height = (int)XtHeight(ctx) - RVMargins(ctx); + rect.width = width; + rect.height = height; + + if (sink->ascii_sink.normgc) { + if (width >= 0 && height >= 0) + XSetClipRectangles(XtDisplay((Widget)ctx), sink->ascii_sink.normgc, + 0, 0, &rect, 1, Unsorted); + else + XSetClipMask(XtDisplay((Widget)ctx), sink->ascii_sink.normgc, None); + } + if (sink->ascii_sink.invgc) { + if (width >= 0 && height >= 0) + XSetClipRectangles(XtDisplay((Widget)ctx), sink->ascii_sink.invgc, + 0, 0, &rect, 1, Unsorted); + else + XSetClipMask(XtDisplay((Widget)ctx), sink->ascii_sink.invgc, None); + } + if (sink->ascii_sink.xorgc) { + if (width >= 0 && height >= 0) + XSetClipRectangles(XtDisplay((Widget)ctx), sink->ascii_sink.xorgc, + 0, 0, &rect, 1, Unsorted); + else + XSetClipMask(XtDisplay((Widget)ctx), sink->ascii_sink.xorgc, None); + } +} -/* ARGSUSED */ +/* + * Function: + * XawAsciiSinkSetValues + * + * Parameters: + * current - current state of the object + * request - what was requested + * cnew - what the object will become + * + * Description: + * Sets the values for the AsciiSink. + * + * Returns: + * True if redisplay is needed + */ +/*ARGSUSED*/ static Boolean -SetValues(current, request, new, args, num_args) -Widget current, request, new; -ArgList args; -Cardinal *num_args; +XawAsciiSinkSetValues(Widget current, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - AsciiSinkObject w = (AsciiSinkObject) new; - AsciiSinkObject old_w = (AsciiSinkObject) current; + AsciiSinkObject w = (AsciiSinkObject)cnew; + AsciiSinkObject old_w = (AsciiSinkObject)current; if (w->ascii_sink.font != old_w->ascii_sink.font || w->text_sink.background != old_w->text_sink.background - || w->text_sink.foreground != old_w->text_sink.foreground) { - XtReleaseGC((Widget)w, w->ascii_sink.normgc); - XtReleaseGC((Widget)w, w->ascii_sink.invgc); - XtReleaseGC((Widget)w, w->ascii_sink.xorgc); + || w->text_sink.foreground != old_w->text_sink.foreground +#ifndef OLDXAW + || w->text_sink.cursor_color != old_w->text_sink.cursor_color + || w->text_sink.properties != old_w->text_sink.properties +#endif + ) { +#ifdef OLDXAW + XtReleaseGC(cnew, w->ascii_sink.normgc); + XtReleaseGC(cnew, w->ascii_sink.invgc); + XtReleaseGC(cnew, w->ascii_sink.xorgc); GetGC(w); - ((TextWidget)XtParent(new))->text.redisplay_needed = True; - } else { - if ( (w->ascii_sink.echo != old_w->ascii_sink.echo) || - (w->ascii_sink.display_nonprinting != - old_w->ascii_sink.display_nonprinting) ) - ((TextWidget)XtParent(new))->text.redisplay_needed = True; - } - - return False; +#endif + ((TextWidget)XtParent(cnew))->text.redisplay_needed = True; + } + else if (w->ascii_sink.echo != old_w->ascii_sink.echo + || w->ascii_sink.display_nonprinting + != old_w->ascii_sink.display_nonprinting) + ((TextWidget)XtParent(cnew))->text.redisplay_needed = True; +#ifndef OLDXAW + if (w->text_sink.properties != old_w->text_sink.properties) { + XawTextProperty *property = + XawTextSinkGetProperty(cnew, XrmStringToQuark("default")); + + if (property) { + if (property->mask & XAW_TPROP_FONT) + w->ascii_sink.font = property->font; + if (property->mask & XAW_TPROP_FOREGROUND) + w->text_sink.foreground = property->foreground; + if (property->mask & XAW_TPROP_BACKGROUND) + w->text_sink.background = property->background; + } + } +#endif + + return (False); } -/* Function Name: MaxLines - * Description: Finds the Maximum number of lines that will fit in - * a given height. - * Arguments: w - the AsciiSink Object. - * height - height to fit lines into. - * Returns: the number of lines that will fit. +/* + * Function: + * MaxLines + * + * Parameters: + * w - AsciiSink Object + * height - height to fit lines into + * + * Description: + * Finds the Maximum number of lines that will fit in a given height. + * + * Returns: + * The number of lines that will fit */ - -/* ARGSUSED */ +/*ARGSUSED*/ static int -MaxLines(w, height) -Widget w; -Dimension height; +MaxLines(Widget w, unsigned int height) { - AsciiSinkObject sink = (AsciiSinkObject) w; - int font_height; + AsciiSinkObject sink = (AsciiSinkObject)w; + int font_height; + + font_height = sink->ascii_sink.font->ascent + sink->ascii_sink.font->descent + 1; - font_height = sink->ascii_sink.font->ascent + sink->ascii_sink.font->descent; - return( ((int) height) / font_height ); + return ((int)height / font_height); } -/* Function Name: MaxHeight - * Description: Finds the Minium height that will contain a given number - * lines. - * Arguments: w - the AsciiSink Object. - * lines - the number of lines. - * Returns: the height. +/* + * Function: + * MaxHeight + * + * Parameters: + * w - AsciiSink Object + * lines - number of lines + * + * Description: + * Finds the Minium height that will contain a given number lines. + * + * Returns: + * the height */ - -/* ARGSUSED */ static int -MaxHeight(w, lines) -Widget w; -int lines; +MaxHeight(Widget w, int lines) { - AsciiSinkObject sink = (AsciiSinkObject) w; + AsciiSinkObject sink = (AsciiSinkObject)w; - return(lines * (sink->ascii_sink.font->ascent + - sink->ascii_sink.font->descent)); + return (lines * (sink->ascii_sink.font->ascent + + sink->ascii_sink.font->descent + 1)); } -/* Function Name: SetTabs - * Description: Sets the Tab stops. - * Arguments: w - the AsciiSink Object. - * tab_count - the number of tabs in the list. - * tabs - the text positions of the tabs. - * Returns: none +/* + * Function: + * SetTabs + * + * Parameters: + * w - AsciiSink Object + * tab_count - number of tabs in the list + * tabs - text positions of the tabs + * + * Description: + * Sets the Tab stops. */ - static void -SetTabs(w, tab_count, tabs) -Widget w; -int tab_count; -short *tabs; +SetTabs(Widget w, int tab_count, short *tabs) { - AsciiSinkObject sink = (AsciiSinkObject) w; - int i; - Atom XA_FIGURE_WIDTH; - unsigned long figure_width = 0; - XFontStruct *font = sink->ascii_sink.font; + AsciiSinkObject sink = (AsciiSinkObject)w; + int i; + Atom XA_FIGURE_WIDTH; + unsigned long figure_width = 0; + XFontStruct *font = sink->ascii_sink.font; -/* - * Find the figure width of the current font. - */ + /* + * Find the figure width of the current font + */ + XA_FIGURE_WIDTH = XInternAtom(XtDisplayOfObject(w), "FIGURE_WIDTH", False); + if (XA_FIGURE_WIDTH != None + && (!XGetFontProperty(font, XA_FIGURE_WIDTH, &figure_width) + || figure_width == 0)) { + if (font->per_char && font->min_char_or_byte2 <= '$' + && font->max_char_or_byte2 >= '$') + figure_width = font->per_char['$' - font->min_char_or_byte2].width; + else + figure_width = font->max_bounds.width; + } + + if (tab_count > sink->text_sink.tab_count) { + sink->text_sink.tabs = (Position *) + XtRealloc((char*)sink->text_sink.tabs, tab_count * sizeof(Position)); + sink->text_sink.char_tabs = (short *) + XtRealloc((char*)sink->text_sink.char_tabs, tab_count * sizeof(short)); + } - XA_FIGURE_WIDTH = XInternAtom(XtDisplayOfObject(w), "FIGURE_WIDTH", FALSE); - if ( (XA_FIGURE_WIDTH != None) && - ( (!XGetFontProperty(font, XA_FIGURE_WIDTH, &figure_width)) || - (figure_width == 0)) ) - if (font->per_char && font->min_char_or_byte2 <= '$' && - font->max_char_or_byte2 >= '$') - figure_width = font->per_char['$' - font->min_char_or_byte2].width; - else - figure_width = font->max_bounds.width; - - if (tab_count > sink->text_sink.tab_count) { - sink->text_sink.tabs = (Position *) - XtRealloc((char *) sink->text_sink.tabs, - (Cardinal) (tab_count * sizeof(Position))); - sink->text_sink.char_tabs = (short *) - XtRealloc((char *) sink->text_sink.char_tabs, - (Cardinal) (tab_count * sizeof(short))); - } + for (i = 0 ; i < tab_count ; i++) { + sink->text_sink.tabs[i] = tabs[i] * figure_width; + sink->text_sink.char_tabs[i] = tabs[i]; + } - for ( i = 0 ; i < tab_count ; i++ ) { - sink->text_sink.tabs[i] = tabs[i] * figure_width; - sink->text_sink.char_tabs[i] = tabs[i]; - } - - sink->text_sink.tab_count = tab_count; + sink->text_sink.tab_count = tab_count; #ifndef NO_TAB_FIX - { TextWidget ctx = (TextWidget)XtParent(w); - ctx->text.redisplay_needed = True; - _XawTextBuildLineTable(ctx, ctx->text.lt.top, TRUE); - } + { + TextWidget ctx = (TextWidget)XtParent(w); + ctx->text.redisplay_needed = True; + _XawTextBuildLineTable(ctx, ctx->text.lt.top, True); + } #endif } diff --git a/src/AsciiSrc.c b/src/AsciiSrc.c index f377640..4e45979 100644 --- a/src/AsciiSrc.c +++ b/src/AsciiSrc.c @@ -26,1294 +26,1763 @@ in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/AsciiSrc.c,v 1.34 2002/11/21 16:22:52 paulo Exp $ */ + /* * AsciiSrc.c - AsciiSrc object. (For use with the text widget). * */ -#include <X11/IntrinsicP.h> #include <stdio.h> +#include <stdlib.h> #include <ctype.h> #include <errno.h> +#include <X11/IntrinsicP.h> #include <X11/StringDefs.h> #include <X11/Xos.h> -#ifndef X_NOT_STDC_ENV -#include <stdlib.h> -#endif #include <X11/Xfuncs.h> +#include <X11/Xmu/CharSet.h> +#include <X11/Xmu/Misc.h> #include <X11/Xaw/XawInit.h> #include <X11/Xaw/AsciiSrcP.h> -#include <X11/Xmu/Misc.h> -#include <X11/Xmu/CharSet.h> -#include <X11/Xaw/MultiSrcP.h> +#include <X11/Xaw/MultiSrcP.h> +#ifndef OLDXAW +#include <X11/Xaw/TextSinkP.h> +#include <X11/Xaw/AsciiSinkP.h> +#endif +#include "Private.h" +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> #if (defined(ASCII_STRING) || defined(ASCII_DISK)) -# include <X11/Xaw/AsciiText.h> /* for Widget Classes. */ +#include <X11/Xaw/AsciiText.h> /* for Widget Classes */ #endif +#ifdef X_NOT_POSIX +#define Off_t long +#define Size_t unsigned int +#else +#define Off_t off_t +#define Size_t size_t +#endif -/**************************************************************** - * - * Full class record constant - * - ****************************************************************/ +#define MAGIC_VALUE ((XawTextPosition)-1) +#define streq(a, b) (strcmp((a), (b)) == 0) -/* Private Data */ +/* + * Class Methods + */ +static void XawAsciiSrcClassInitialize(void); +static void XawAsciiSrcDestroy(Widget); +static void XawAsciiSrcGetValuesHook(Widget, ArgList, Cardinal*); +static void XawAsciiSrcInitialize(Widget, Widget, ArgList, Cardinal*); +static Boolean XawAsciiSrcSetValues(Widget, Widget, Widget, + ArgList, Cardinal*); +static XawTextPosition ReadText(Widget, XawTextPosition, XawTextBlock*, int); +static int ReplaceText(Widget, XawTextPosition, XawTextPosition, + XawTextBlock*); +static XawTextPosition Scan(Widget, XawTextPosition, XawTextScanType, + XawTextScanDirection, int, Bool); +static XawTextPosition Search(Widget, XawTextPosition, XawTextScanDirection, + XawTextBlock*); -static int magic_value = MAGIC_VALUE; +/* + * Prototypes + */ +static Piece *AllocNewPiece(AsciiSrcObject, Piece*); +static void BreakPiece(AsciiSrcObject, Piece*); +static Boolean CvtAsciiTypeToString(Display*, XrmValuePtr, Cardinal*, + XrmValuePtr, XrmValuePtr, XtPointer*); +static void CvtStringToAsciiType(XrmValuePtr, Cardinal*, + XrmValuePtr, XrmValuePtr); +static Piece *FindPiece(AsciiSrcObject, XawTextPosition, XawTextPosition*); +static void FreeAllPieces(AsciiSrcObject); +static FILE *InitStringOrFile(AsciiSrcObject, Bool); +static void LoadPieces(AsciiSrcObject, FILE*, char*); +static void RemoveOldStringOrFile(AsciiSrcObject, Bool); +static void RemovePiece(AsciiSrcObject, Piece*); +static String StorePiecesInString(AsciiSrcObject); +static Bool WriteToFile(String, String, unsigned); +static Bool WritePiecesToFile(AsciiSrcObject, String); +static void GetDefaultPieceSize(Widget, int, XrmValue*); -#define offset(field) XtOffsetOf(AsciiSrcRec, ascii_src.field) +/* + * More Prototypes + */ +#ifdef ASCII_DISK +Widget XawAsciiDiskSourceCreate(Widget, ArgList, Cardinal); +#endif +#ifdef ASCII_STRING +Widget XawStringSourceCreate(Widget, ArgList, Cardinal); +void XawTextSetLastPos(Widget, XawTextPosition); +#endif +/* + * Initialization + */ +#define offset(field) XtOffsetOf(AsciiSrcRec, ascii_src.field) static XtResource resources[] = { - {XtNstring, XtCString, XtRString, sizeof (char *), - offset(string), XtRString, NULL}, - {XtNtype, XtCType, XtRAsciiType, sizeof (XawAsciiType), - offset(type), XtRImmediate, (XtPointer)XawAsciiString}, - {XtNdataCompression, XtCDataCompression, XtRBoolean, sizeof (Boolean), - offset(data_compression), XtRImmediate, (XtPointer) TRUE}, - {XtNpieceSize, XtCPieceSize, XtRInt, sizeof (XawTextPosition), - offset(piece_size), XtRImmediate, (XtPointer) BUFSIZ}, - {XtNcallback, XtCCallback, XtRCallback, sizeof(XtPointer), - offset(callback), XtRCallback, (XtPointer)NULL}, - {XtNuseStringInPlace, XtCUseStringInPlace, XtRBoolean, sizeof (Boolean), - offset(use_string_in_place), XtRImmediate, (XtPointer) FALSE}, - {XtNlength, XtCLength, XtRInt, sizeof (int), - offset(ascii_length), XtRInt, (XtPointer) &magic_value}, - + { + XtNstring, + XtCString, + XtRString, + sizeof(char*), + offset(string), + XtRString, + NULL + }, + { + XtNtype, + XtCType, + XtRAsciiType, + sizeof(XawAsciiType), + offset(type), + XtRImmediate, + (XtPointer)XawAsciiString + }, + { + XtNdataCompression, + XtCDataCompression, + XtRBoolean, + sizeof(Boolean), + offset(data_compression), + XtRImmediate, + (XtPointer)True + }, + { + XtNpieceSize, + XtCPieceSize, + XtRInt, + sizeof(XawTextPosition), + offset(piece_size), + XtRCallProc, + (XtPointer)GetDefaultPieceSize + }, +#ifdef OLDXAW + { + XtNcallback, + XtCCallback, + XtRCallback, + sizeof(XtPointer), + offset(callback), + XtRCallback, + (XtPointer)NULL + }, +#endif + { + XtNuseStringInPlace, + XtCUseStringInPlace, + XtRBoolean, + sizeof(Boolean), + offset(use_string_in_place), + XtRImmediate, + (XtPointer)False + }, + { + XtNlength, + XtCLength, + XtRInt, + sizeof(int), + offset(ascii_length), + XtRImmediate, + (XtPointer)MAGIC_VALUE + }, #ifdef ASCII_DISK - {XtNfile, XtCFile, XtRString, sizeof (String), - offset(filename), XtRString, NULL}, + { + XtNfile, + XtCFile, + XtRString, + sizeof(String), + offset(filename), + XtRString, + NULL + }, #endif /* ASCII_DISK */ }; #undef offset -static XawTextPosition Scan(), Search(), ReadText(); -static int ReplaceText(); -static Piece * FindPiece(), * AllocNewPiece(); -static FILE * InitStringOrFile(); -static void FreeAllPieces(), RemovePiece(), BreakPiece(), LoadPieces(); -static void RemoveOldStringOrFile(), CvtStringToAsciiType(); -static void ClassInitialize(), Initialize(), Destroy(), GetValuesHook(); -static String MyStrncpy(), StorePiecesInString(); -static Boolean SetValues(), WriteToFile(); -#ifdef X_NOT_STDC_ENV -extern int errno; -#endif -#ifdef X_NOT_POSIX -#define Off_t long -#define Size_t unsigned int -#else -#define Off_t off_t -#define Size_t size_t -#endif - -#define superclass (&textSrcClassRec) +#define Superclass (&textSrcClassRec) AsciiSrcClassRec asciiSrcClassRec = { + /* object */ { -/* core_class fields */ - /* superclass */ (WidgetClass) superclass, - /* class_name */ "AsciiSrc", - /* widget_size */ sizeof(AsciiSrcRec), - /* class_initialize */ ClassInitialize, - /* class_part_initialize */ NULL, - /* class_inited */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* realize */ NULL, - /* actions */ NULL, - /* num_actions */ 0, - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ FALSE, - /* compress_exposure */ FALSE, - /* compress_enterleave */ FALSE, - /* visible_interest */ FALSE, - /* destroy */ Destroy, - /* resize */ NULL, - /* expose */ NULL, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* set_values_almost */ NULL, - /* get_values_hook */ GetValuesHook, - /* accept_focus */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ NULL, - /* query_geometry */ NULL, - /* display_accelerator */ NULL, - /* extension */ NULL + (WidgetClass)Superclass, /* superclass */ + "AsciiSrc", /* class_name */ + sizeof(AsciiSrcRec), /* widget_size */ + XawAsciiSrcClassInitialize, /* class_initialize */ + NULL, /* class_part_initialize */ + False, /* class_inited */ + XawAsciiSrcInitialize, /* initialize */ + NULL, /* initialize_hook */ + NULL, /* realize */ + NULL, /* actions */ + 0, /* num_actions */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + False, /* compress_motion */ + False, /* compress_exposure */ + False, /* compress_enterleave */ + False, /* visible_interest */ + XawAsciiSrcDestroy, /* destroy */ + NULL, /* resize */ + NULL, /* expose */ + XawAsciiSrcSetValues, /* set_values */ + NULL, /* set_values_hook */ + NULL, /* set_values_almost */ + XawAsciiSrcGetValuesHook, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + NULL, /* tm_table */ + NULL, /* query_geometry */ + NULL, /* display_accelerator */ + NULL, /* extension */ }, -/* textSrc_class fields */ + /* text_src */ { - /* Read */ ReadText, - /* Replace */ ReplaceText, - /* Scan */ Scan, - /* Search */ Search, - /* SetSelection */ XtInheritSetSelection, - /* ConvertSelection */ XtInheritConvertSelection + ReadText, /* Read */ + ReplaceText, /* Replace */ + Scan, /* Scan */ + Search, /* Search */ + XtInheritSetSelection, /* SetSelection */ + XtInheritConvertSelection, /* ConvertSelection */ }, -/* asciiSrc_class fields */ + /* ascii_src */ { - /* Keep the compiler happy */ '\0' - } + NULL, /* extension */ + }, }; WidgetClass asciiSrcObjectClass = (WidgetClass)&asciiSrcClassRec; -/************************************************************ - * - * Semi-Public Interfaces. - * - ************************************************************/ +static XrmQuark Qstring, Qfile; -/* Function Name: ClassInitialize - * Description: Class Initialize routine, called only once. - * Arguments: none. - * Returns: none. +/* + * Implementation + */ +/* + * Function: + * XawAsciiSrcClassInitialize() + * + * Description: + * Initializes the asciiSrcObjectClass and install the converters for + * AsciiType <-> String. */ - static void -ClassInitialize() +XawAsciiSrcClassInitialize(void) { - XawInitializeWidgetSet(); - XtAddConverter( XtRString, XtRAsciiType, CvtStringToAsciiType, - NULL, (Cardinal) 0); + XawInitializeWidgetSet(); + Qstring = XrmPermStringToQuark(XtEstring); + Qfile = XrmPermStringToQuark(XtEfile); + XtAddConverter(XtRString, XtRAsciiType, CvtStringToAsciiType, NULL, 0); + XtSetTypeConverter(XtRAsciiType, XtRString, CvtAsciiTypeToString, + NULL, 0, XtCacheNone, NULL); } -/* Function Name: Initialize - * Description: Initializes the simple menu widget - * Arguments: request - the widget requested by the argument list. - * new - the new widget with both resource and non - * resource values. - * Returns: none. +/* + * Function: + * XawAsciiSrcInitialize + * + * Parameters: + * request - widget requested by the argument list + * cnew - new widget with both resource and non resource values + * args - (unused) + * num_args - (unused) + * + * Description: + * Initializes the ascii src object. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -Initialize(request, new, args, num_args) -Widget request, new; -ArgList args; -Cardinal *num_args; +XawAsciiSrcInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - AsciiSrcObject src = (AsciiSrcObject) new; - FILE * file; - -/* - * Set correct flags (override resources) depending upon widget class. - */ + AsciiSrcObject src = (AsciiSrcObject)cnew; + FILE *file; - src->text_src.text_format = XawFmt8Bit; /* data format. */ + /* + * Set correct flags (override resources) depending upon widget class + */ + src->text_src.text_format = XawFmt8Bit; #ifdef ASCII_DISK - if (XtIsSubclass(XtParent(new), asciiDiskWidgetClass)) { - src->ascii_src.type = XawAsciiFile; - src->ascii_src.string = src->ascii_src.filename; - } + if (XtIsSubclass(XtParent(cnew), asciiDiskWidgetClass)) { + src->ascii_src.type = XawAsciiFile; + src->ascii_src.string = src->ascii_src.filename; + } #endif #ifdef ASCII_STRING - if (XtIsSubclass(XtParent(new), asciiStringWidgetClass)) { - src->ascii_src.use_string_in_place = TRUE; - src->ascii_src.type = XawAsciiString; - } + if (XtIsSubclass(XtParent(cnew), asciiStringWidgetClass)) { + src->ascii_src.use_string_in_place = True; + src->ascii_src.type = XawAsciiString; + } #endif - src->ascii_src.changes = FALSE; - src->ascii_src.allocated_string = FALSE; +#ifdef OLDXAW + src->ascii_src.changes = False; +#else + src->text_src.changed = False; +#endif + src->ascii_src.allocated_string = False; + + if (src->ascii_src.use_string_in_place && src->ascii_src.string == NULL) + src->ascii_src.use_string_in_place = False; - file = InitStringOrFile(src, src->ascii_src.type == XawAsciiFile); - LoadPieces(src, file, NULL); + file = InitStringOrFile(src, src->ascii_src.type == XawAsciiFile); + LoadPieces(src, file, NULL); - if (file != NULL) fclose(file); + if (file != NULL) + fclose(file); } -/* Function Name: ReadText - * Description: This function reads the source. - * Arguments: w - the AsciiSource widget. - * pos - position of the text to retreive. - * RETURNED text - text block that will contain returned text. - * length - maximum number of characters to read. - * Returns: The number of characters read into the buffer. +/* + * Function: + * ReadText + * + * Parameters: + * w - AsciiSource widget + * pos - position of the text to retreive. + * text - text block that will contain returned text + * length - maximum number of characters to read + * + * Description: + * This function reads the source. + * + * Returns: + * The character position following the retrieved text. */ - static XawTextPosition -ReadText(w, pos, text, length) -Widget w; -XawTextPosition pos; -XawTextBlock *text; -int length; +ReadText(Widget w, XawTextPosition pos, XawTextBlock *text, int length) { - AsciiSrcObject src = (AsciiSrcObject) w; - XawTextPosition count, start; - Piece * piece = FindPiece(src, pos, &start); - - text->firstPos = pos; - text->ptr = piece->text + (pos - start); - count = piece->used - (pos - start); - text->length = (length > count) ? count : length; - return(pos + text->length); -} + AsciiSrcObject src = (AsciiSrcObject)w; + XawTextPosition count, start; + Piece *piece; +#ifndef OLDXAW + XawTextAnchor *anchor; + XawTextEntity *entity; + XawTextPosition offset, end = pos + length; + Bool state; + + end = XawMin(end, src->ascii_src.length); + while ((state = XawTextSourceAnchorAndEntity(w, pos, &anchor, &entity)) && + (entity->flags & XAW_TENTF_HIDE)) + pos = anchor->position + entity->offset + entity->length; + if (state == False || + !(entity->flags & XAW_TENTF_REPLACE)) { + while (entity) { + offset = anchor->position + entity->offset; + if (offset >= end) + break; + if (offset > pos && + (entity->flags & (XAW_TENTF_HIDE | XAW_TENTF_REPLACE))) { + end = XawMin(end, offset); + break; + } + if ((entity = entity->next) == NULL && + (anchor = XawTextSourceNextAnchor(w, anchor)) != NULL) + entity = anchor->entities; + } + } + else if (state && (entity->flags & XAW_TENTF_REPLACE) && pos < end) { + XawTextBlock *block = (XawTextBlock*)entity->data; + + offset = anchor->position + entity->offset; + end = XawMin(end, offset + block->length); + if ((length = end - pos) < 0) + length = 0; + text->length = length; + text->format = XawFmt8Bit; + if (length == 0) { + text->firstPos = end = offset + entity->length; + text->ptr = ""; + } + else { + text->firstPos = pos; + text->ptr = block->ptr + (pos - offset); + if (pos + length < offset + block->length) + end = pos + length; /* there is data left to be read */ + else + end = offset + entity->length; + } -/* Function Name: ReplaceText. - * Description: Replaces a block of text with new text. - * Arguments: w - the AsciiSource widget. - * startPos, endPos - ends of text that will be removed. - * text - new text to be inserted into buffer at startPos. - * Returns: XawEditError or XawEditDone. - */ + return (end); + } -/*ARGSUSED*/ -static int -ReplaceText (w, startPos, endPos, text) -Widget w; -XawTextPosition startPos, endPos; -XawTextBlock *text; -{ - AsciiSrcObject src = (AsciiSrcObject) w; - Piece *start_piece, *end_piece, *temp_piece; - XawTextPosition start_first, end_first; - int length, firstPos; + if ((length = end - pos) < 0) + length = 0; +#endif + + piece = FindPiece(src, pos, &start); + text->firstPos = pos; + text->ptr = piece->text + (pos - start); + count = piece->used - (pos - start); + text->length = Max(0, (length > count) ? count : length); + text->format = XawFmt8Bit; + + return (pos + text->length); +} /* - * Editing a read only source is not allowed. + * Function: + * ReplaceText + * + * Parameters: + * w - AsciiSource object + * startPos - ends of text that will be replaced + * endPos - "" + * text - new text to be inserted into buffer at startPos + * + * Description: + * Replaces a block of text with new text. + * + * Returns: + * XawEditDone on success, XawEditError otherwise */ +/*ARGSUSED*/ +static int +ReplaceText(Widget w, XawTextPosition startPos, XawTextPosition endPos, + XawTextBlock *text) +{ + AsciiSrcObject src = (AsciiSrcObject)w; + Piece *start_piece, *end_piece, *temp_piece; + XawTextPosition start_first, end_first; + int length, firstPos; - if (src->text_src.edit_mode == XawtextRead) - return(XawEditError); - - start_piece = FindPiece(src, startPos, &start_first); - end_piece = FindPiece(src, endPos, &end_first); + /* + * Editing a read only source is not allowed + */ + if (src->text_src.edit_mode == XawtextRead) + return (XawEditError); - src->ascii_src.changes = TRUE; /* We have changed the buffer. */ + start_piece = FindPiece(src, startPos, &start_first); + end_piece = FindPiece(src, endPos, &end_first); -/* - * Remove Old Stuff. - */ +#ifndef OLDXAW + /* + * This is a big hack, but I can't think about a clever way to know + * if the character being moved forward has a negative lbearing. + * + */ + if (start_piece->used) { + int i; + + for (i = 0; i < src->text_src.num_text; i++) { + int line; + TextWidget ctx = (TextWidget)src->text_src.text[i]; + + for (line = 0; line < ctx->text.lt.lines; line++) + if (startPos < ctx->text.lt.info[line + 1].position) + break; + if (i < ctx->text.lt.lines && + startPos > ctx->text.lt.info[i].position) { + AsciiSinkObject sink = (AsciiSinkObject)ctx->text.sink; + XawTextAnchor *anchor; + XawTextEntity *entity; + XawTextProperty *property; + XFontStruct *font; + + if (XawTextSourceAnchorAndEntity(w, startPos, &anchor, &entity) && + (property = XawTextSinkGetProperty(ctx->text.sink, + entity->property)) != NULL && + (property->mask & XAW_TPROP_FONT)) + font = property->font; + else + font = sink->ascii_sink.font; + + if (font->min_bounds.lbearing < 0) { + int lbearing = font->min_bounds.lbearing; + unsigned char c = *(unsigned char*) + (start_piece->text + (startPos - start_first)); + + if (c == '\t' || c == '\n') + c = ' '; + else if ((c & 0177) < XawSP || c == 0177) { + if (sink->ascii_sink.display_nonprinting) + c = c > 0177 ? '\\' : c + '^'; + else + c = ' '; + } + if (font->per_char && + (c >= font->min_char_or_byte2 && c <= font->max_char_or_byte2)) + lbearing = font->per_char[c - font->min_char_or_byte2].lbearing; + if (lbearing < 0) + _XawTextNeedsUpdating(ctx, startPos - 1, startPos); + } + } + } + } - if (start_piece != end_piece) { - temp_piece = start_piece->next; -/* - * If empty and not the only piece then remove it. - */ +#endif - if ( ((start_piece->used = startPos - start_first) == 0) && - !((start_piece->next == NULL) && (start_piece->prev == NULL)) ) - RemovePiece(src, start_piece); + /* + * Remove Old Stuff + */ + if (start_piece != end_piece) { + temp_piece = start_piece->next; + + /* + * If empty and not the only piece then remove it. + */ + if (((start_piece->used = startPos - start_first) == 0) + && !(start_piece->next == NULL && start_piece->prev == NULL)) + RemovePiece(src, start_piece); + + while (temp_piece != end_piece) { + temp_piece = temp_piece->next; + RemovePiece(src, temp_piece->prev); + } - while (temp_piece != end_piece) { - temp_piece = temp_piece->next; - RemovePiece(src, temp_piece->prev); - } - end_piece->used -= endPos - end_first; - if (end_piece->used != 0) - MyStrncpy(end_piece->text, (end_piece->text + endPos - end_first), - (int) end_piece->used); - } - else { /* We are fully in one piece. */ - if ( (start_piece->used -= endPos - startPos) == 0) { - if ( !((start_piece->next == NULL) && (start_piece->prev == NULL)) ) - RemovePiece(src, start_piece); + end_piece->used -= endPos - end_first; + if (end_piece->used != 0) + memmove(end_piece->text, end_piece->text + endPos - end_first, + (unsigned)end_piece->used); } - else { - MyStrncpy(start_piece->text + (startPos - start_first), - start_piece->text + (endPos - start_first), - (int) (start_piece->used - (startPos - start_first)) ); - if ( src->ascii_src.use_string_in_place && - ((src->ascii_src.length - (endPos - startPos)) < - (src->ascii_src.piece_size - 1)) ) - start_piece->text[src->ascii_src.length - (endPos - startPos)] = '\0'; + else { /* We are fully in one piece */ + if ((start_piece->used -= endPos - startPos) == 0) { + if (!(start_piece->next == NULL && start_piece->prev == NULL)) + RemovePiece(src, start_piece); + } + else { + memmove(start_piece->text + (startPos - start_first), + start_piece->text + (endPos - start_first), + (unsigned)(start_piece->used - (startPos - start_first))); + if (src->ascii_src.use_string_in_place + && src->ascii_src.length - (endPos - startPos) + < src->ascii_src.piece_size - 1) + start_piece->text[src->ascii_src.length - (endPos - startPos)] = + '\0'; + } } - } - src->ascii_src.length += -(endPos - startPos) + text->length; + src->ascii_src.length += -(endPos - startPos) + text->length; - if ( text->length != 0) { + if ( text->length != 0) { + /* + * Put in the New Stuff + */ + start_piece = FindPiece(src, startPos, &start_first); - /* - * Put in the New Stuff. - */ - - start_piece = FindPiece(src, startPos, &start_first); - - length = text->length; - firstPos = text->firstPos; - - while (length > 0) { - char * ptr; - int fill; - - if (src->ascii_src.use_string_in_place) { - if (start_piece->used == (src->ascii_src.piece_size - 1)) { - /* - * If we are in ascii string emulation mode. Then the - * string is not allowed to grow. - */ - start_piece->used = src->ascii_src.length = - src->ascii_src.piece_size - 1; - start_piece->text[src->ascii_src.length] = '\0'; - return(XawEditError); - } - } + length = text->length; + firstPos = text->firstPos; + + while (length > 0) { + char *ptr; + int fill; + + if (src->ascii_src.use_string_in_place) { + if (start_piece->used == src->ascii_src.piece_size - 1) { + /* + * If we are in ascii string emulation mode. Then the + * string is not allowed to grow + */ + start_piece->used = src->ascii_src.length = + src->ascii_src.piece_size - 1; + start_piece->text[src->ascii_src.length] = '\0'; + return (XawEditError); + } + } + if (start_piece->used == src->ascii_src.piece_size) { + BreakPiece(src, start_piece); + start_piece = FindPiece(src, startPos, &start_first); + } - if (start_piece->used == src->ascii_src.piece_size) { - BreakPiece(src, start_piece); - start_piece = FindPiece(src, startPos, &start_first); - } - - fill = Min((int)(src->ascii_src.piece_size - start_piece->used), length); - - ptr = start_piece->text + (startPos - start_first); - MyStrncpy(ptr + fill, ptr, - (int) start_piece->used - (startPos - start_first)); - strncpy(ptr, text->ptr + firstPos, fill); - - startPos += fill; - firstPos += fill; - start_piece->used += fill; - length -= fill; - } - } + fill = Min((int)(src->ascii_src.piece_size - start_piece->used), + length); - if (src->ascii_src.use_string_in_place) - start_piece->text[start_piece->used] = '\0'; + ptr = start_piece->text + (startPos - start_first); + memmove(ptr + fill, ptr, + (unsigned)(start_piece->used - (startPos - start_first))); + memcpy(ptr, text->ptr + firstPos, (unsigned)fill); - XtCallCallbacks(w, XtNcallback, NULL); /* Call callbacks, we have changed - the buffer. */ + startPos += fill; + firstPos += fill; + start_piece->used += fill; + length -= fill; + } + } - return(XawEditDone); -} + if (src->ascii_src.use_string_in_place) + start_piece->text[start_piece->used] = '\0'; -/* Function Name: Scan - * Description: Scans the text source for the number and type - * of item specified. - * Arguments: w - the AsciiSource widget. - * position - the position to start scanning. - * type - type of thing to scan for. - * dir - direction to scan. - * count - which occurance if this thing to search for. - * include - whether or not to include the character found in - * the position that is returned. - * Returns: the position of the item found. - * - * Note: While there are only 'n' characters in the file there are n+1 - * possible cursor positions (one before the first character and - * one after the last character. - */ +#ifdef OLDXAW + src->ascii_src.changes = True; + XtCallCallbacks(w, XtNcallback, NULL); +#endif -static -XawTextPosition -Scan (w, position, type, dir, count, include) -Widget w; -XawTextPosition position; -XawTextScanType type; -XawTextScanDirection dir; -int count; -Boolean include; -{ - AsciiSrcObject src = (AsciiSrcObject) w; - int inc; - Piece* piece; - XawTextPosition first, first_eol_position; - char* ptr; - - if (type == XawstAll) { /* Optomize this common case. */ - if (dir == XawsdRight) - return(src->ascii_src.length); - return(0); /* else. */ - } - - if (position > src->ascii_src.length) - position = src->ascii_src.length; - - if ( dir == XawsdRight ) { - if (position == src->ascii_src.length) -/* - * Scanning right from src->ascii_src.length??? - */ - return(src->ascii_src.length); - inc = 1; - } - else { - if (position == 0) - return(0); /* Scanning left from 0??? */ - inc = -1; - position--; - } - - piece = FindPiece(src, position, &first); + return (XawEditDone); +} /* - * If the buffer is empty then return 0. + * Function: + * Scan + * + * Parameters: + * w - AsciiSource object + * position - position to start scanning + * type - type of thing to scan for + * dir - direction to scan + * count - which occurance if this thing to search for. + * include - whether or not to include the character found in + * the position that is returned + * + * Description: + * Scans the text source for the number and type of item specified. + * + * Returns: + * The position of the item found + * + * Note: + * While there are only 'n' characters in the file there are n+1 + * possible cursor positions (one before the first character and + * one after the last character */ - - if ( piece->used == 0 ) return(0); - - ptr = (position - first) + piece->text; - - switch (type) { - case XawstEOL: - case XawstParagraph: - case XawstWhiteSpace: - for ( ; count > 0 ; count-- ) { - Boolean non_space = FALSE, first_eol = TRUE; - /* CONSTCOND */ - while (TRUE) { - unsigned char c = *ptr; - - ptr += inc; - position += inc; - - if (type == XawstWhiteSpace) { - if (isspace(c)) { - if (non_space) - break; - } - else - non_space = TRUE; +static XawTextPosition +Scan(Widget w, register XawTextPosition position, XawTextScanType type, + XawTextScanDirection dir, int count, Bool include) +{ + AsciiSrcObject src = (AsciiSrcObject)w; + Piece *piece; + XawTextPosition first, first_eol_position = 0; + register char *ptr, *lim; + register int cnt = count; + register unsigned char c; + + if (dir == XawsdLeft) { + if (position <= 0) + return (0); + --position; + } + else if (position >= src->ascii_src.length) + return (src->ascii_src.length); + + piece = FindPiece(src, position, &first); + if (piece->used == 0) + return (0); + + ptr = (position - first) + piece->text; + + if (dir == XawsdRight) { + lim = piece->text + piece->used; + switch (type) { + case XawstEOL: + case XawstParagraph: + case XawstWhiteSpace: + case XawstAlphaNumeric: + for (; cnt > 0; cnt--) { + Bool non_space = False, first_eol = True; + + /*CONSTCOND*/ + while (True) { + if (ptr >= lim) { + piece = piece->next; + if (piece == NULL) /* End of text */ + return (src->ascii_src.length); + ptr = piece->text; + lim = piece->text + piece->used; + } + + c = *ptr++; + ++position; + + if (type == XawstEOL) { + if (c == '\n') + break; + } + else if (type == XawstAlphaNumeric) { + if (!isalnum(c)) { + if (non_space) + break; + } + else + non_space = True; + } + else if (type == XawstWhiteSpace) { + if (isspace(c)) { + if (non_space) + break; + } + else + non_space = True; + } + else { /* XawstParagraph */ + if (first_eol) { + if (c == '\n') { + first_eol_position = position; + first_eol = False; + } + } + else if (c == '\n') + break; + else if (!isspace(c)) + first_eol = True; + } + } + } + break; + case XawstPositions: + position += count; + return (position < src->ascii_src.length ? + position : src->ascii_src.length); + case XawstAll: + return (src->ascii_src.length); + default: + break; } - else if (type == XawstEOL) { - if (c == '\n') break; + if (!include) { + if (type == XawstParagraph) + position = first_eol_position; + if (count) + --position; } - else { /* XawstParagraph */ - if (first_eol) { - if (c == '\n') { - first_eol_position = position; - first_eol = FALSE; - } - } - else - if ( c == '\n') - break; - else if ( !isspace(c) ) - first_eol = TRUE; - } - - - if ( ptr < piece->text ) { - piece = piece->prev; - if (piece == NULL) /* Begining of text. */ - return(0); - ptr = piece->text + piece->used - 1; + } + else { + lim = piece->text; + switch (type) { + case XawstEOL: + case XawstParagraph: + case XawstWhiteSpace: + case XawstAlphaNumeric: + for (; cnt > 0; cnt--) { + Bool non_space = False, first_eol = True; + + /*CONSTCOND*/ + while (True) { + if (ptr < lim) { + piece = piece->prev; + if (piece == NULL) /* Begining of text */ + return (0); + ptr = piece->text + piece->used - 1; + lim = piece->text; + } + + c = *ptr--; + --position; + + if (type == XawstEOL) { + if (c == '\n') + break; + } + else if (type == XawstAlphaNumeric) { + if (!isalnum(c)) { + if (non_space) + break; + } + else + non_space = True; + } + else if (type == XawstWhiteSpace) { + if (isspace(c)) { + if (non_space) + break; + } + else + non_space = True; + } + else { /* XawstParagraph */ + if (first_eol) { + if (c == '\n') { + first_eol_position = position; + first_eol = False; + } + } + else if (c == '\n') + break; + else if (!isspace(c)) + first_eol = True; + } + } + } + break; + case XawstPositions: + position -= count - 1; + return (position > 0 ? position : 0); + case XawstAll: + return (0); + default: + break; } - else if ( ptr >= (piece->text + piece->used) ) { - piece = piece->next; - if (piece == NULL) /* End of text. */ - return(src->ascii_src.length); - ptr = piece->text; + if (!include) { + if (type == XawstParagraph) + position = first_eol_position; + if (count) + ++position; } - } + position++; } - if (!include) { - if ( type == XawstParagraph) - position = first_eol_position; - position -= inc; - } - break; - case XawstPositions: - position += count * inc; - break; -/* case XawstAll: ---- handled in special code above */ - } - - if ( dir == XawsdLeft ) - position++; - - if (position >= src->ascii_src.length) - return(src->ascii_src.length); - if (position < 0) - return(0); - - return(position); + + return (position); } -/* Function Name: Search - * Description: Searchs the text source for the text block passed - * Arguments: w - the AsciiSource Widget. - * position - the position to start scanning. - * dir - direction to scan. - * text - the text block to search for. - * Returns: the position of the item found. +/* + * Function: + * Search + * + * Parameters: + * w - AsciiSource object + * position - the position to start scanning + * dir - direction to scan + * text - text block to search for + * + * Description: + * Searchs the text source for the text block passed. + * + * Returns: + * The position of the item found */ - static XawTextPosition -Search(w, position, dir, text) -Widget w; -XawTextPosition position; -XawTextScanDirection dir; -XawTextBlock * text; +Search(Widget w, register XawTextPosition position, XawTextScanDirection dir, + XawTextBlock *text) { - AsciiSrcObject src = (AsciiSrcObject) w; - int inc, count = 0; - char * ptr; - Piece * piece; - char * buf; - XawTextPosition first; - - if ( dir == XawsdRight ) - inc = 1; - else { - inc = -1; - if (position == 0) - return(XawTextSearchError); /* scanning left from 0??? */ - position--; - } - - buf = XtMalloc((unsigned)sizeof(unsigned char) * text->length); - strncpy(buf, (text->ptr + text->firstPos), text->length); - piece = FindPiece(src, position, &first); - ptr = (position - first) + piece->text; - - /* CONSTCOND */ - while (TRUE) { - if (*ptr == ((dir == XawsdRight) ? *(buf + count) - : *(buf + text->length - count - 1)) ) { - if (count == (text->length - 1)) - break; - else - count++; - } - else { - if (count != 0) { - position -=inc * count; - ptr -= inc * count; - } - count = 0; + AsciiSrcObject src = (AsciiSrcObject)w; + register int count = 0; + register char *ptr, c; + char *str; + Piece *piece; + char *buf; + XawTextPosition first; + int cnt, case_sensitive; + + if (dir == XawsdLeft) { + if (position == 0) + return (XawTextSearchError); + position--; } - ptr += inc; - position += inc; - - while ( ptr < piece->text ) { - piece = piece->prev; - if (piece == NULL) { /* Begining of text. */ - XtFree(buf); - return(XawTextSearchError); - } - ptr = piece->text + piece->used - 1; + buf = XtMalloc((unsigned)sizeof(unsigned char) * text->length); + memcpy(buf, text->ptr, (unsigned)text->length); + piece = FindPiece(src, position, &first); + ptr = (position - first) + piece->text; + case_sensitive = text->firstPos; + + if (dir == XawsdRight) { + str = buf; + c = *str; + /*CONSTCOND*/ + while (1) { + if (*ptr++ == c + || (case_sensitive && isalpha(c) && isalpha(ptr[-1]) + && toupper(c) == toupper(ptr[-1]))) { + if (++count == text->length) + break; + c = *++str; + } + else if (count) { + ptr -= count; + str -= count; + position -= count; + count = 0; + c = *str; + + if (ptr < piece->text) { + do { + cnt = piece->text - ptr; + piece = piece->prev; + if (piece == NULL) { + XtFree(buf); + return (XawTextSearchError); + } + ptr = piece->text + piece->used - cnt; + } while (ptr < piece->text); + } + } + position++; + if (ptr >= (piece->text + piece->used)) { + do { + cnt = ptr - (piece->text + piece->used); + piece = piece->next; + if (piece == NULL) { + XtFree(buf); + return (XawTextSearchError); + } + ptr = piece->text + cnt; + } while (ptr >= (piece->text + piece->used)); + } + } + + position -= text->length - 1; } - - while ( ptr >= (piece->text + piece->used) ) { - piece = piece->next; - if (piece == NULL) { /* End of text. */ - XtFree(buf); - return(XawTextSearchError); - } - ptr = piece->text; + else { + str = buf + text->length - 1; + c = *str; + /*CONSTCOND*/ + while (1) { + if (*ptr-- == c + || (case_sensitive && isalpha(c) && isalpha(ptr[1]) + && toupper(c) == toupper(ptr[1]))) { + if (++count == text->length) + break; + c = *--str; + } + else if (count) { + ptr += count; + str += count; + position += count; + count = 0; + c = *str; + + if (ptr >= (piece->text + piece->used)) { + do { + cnt = ptr - (piece->text + piece->used); + piece = piece->next; + if (piece == NULL) { + XtFree(buf); + return (XawTextSearchError); + } + ptr = piece->text + cnt; + } while (ptr >= (piece->text + piece->used)); + } + } + position--; + if (ptr < piece->text) { + do { + cnt = piece->text - ptr; + piece = piece->prev; + if (piece == NULL) { + XtFree(buf); + return (XawTextSearchError); + } + ptr = piece->text + piece->used - cnt; + } while (ptr < piece->text); + } + } } - } - XtFree(buf); - if (dir == XawsdLeft) - return(position); - return(position - (text->length - 1)); + XtFree(buf); + + return (position); } -/* Function Name: SetValues - * Description: Sets the values for the AsciiSource. - * Arguments: current - current state of the widget. - * request - what was requested. - * new - what the widget will become. - * Returns: True if redisplay is needed. +/* + * Function: + * XawAsciiSrcSetValues + * + * Parameters: + * current - current state of the widget + * request - what was requested + * cnew - what the widget will become + * args - representation of changed resources + * num_args - number of resources that have changed + * + * Description: + * Sets the values for the AsciiSource. + * + * Returns: + * True if redisplay is needed */ - -/* ARGSUSED */ static Boolean -SetValues(current, request, new, args, num_args) -Widget current, request, new; -ArgList args; -Cardinal * num_args; +XawAsciiSrcSetValues(Widget current, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - AsciiSrcObject src = (AsciiSrcObject) new; - AsciiSrcObject old_src = (AsciiSrcObject) current; - Boolean total_reset = FALSE, string_set = FALSE; - FILE * file; - int i; - - if ( old_src->ascii_src.use_string_in_place != - src->ascii_src.use_string_in_place ) { - XtAppWarning( XtWidgetToApplicationContext(new), - "AsciiSrc: The XtNuseStringInPlace resource may not be changed."); - src->ascii_src.use_string_in_place = - old_src->ascii_src.use_string_in_place; - } - - for (i = 0; i < *num_args ; i++ ) - if (streq(args[i].name, XtNstring)) { - string_set = TRUE; - break; - } - - if ( string_set || (old_src->ascii_src.type != src->ascii_src.type) ) { - RemoveOldStringOrFile(old_src, string_set); /* remove old info. */ - file = InitStringOrFile(src, string_set); /* Init new info. */ - LoadPieces(src, file, NULL); /* load new info into internal buffers. */ - if (file != NULL) fclose(file); - XawTextSetSource( XtParent(new), new, 0); /* Tell text widget - what happened. */ - total_reset = TRUE; - } - - if ( old_src->ascii_src.ascii_length != src->ascii_src.ascii_length ) - src->ascii_src.piece_size = src->ascii_src.ascii_length; - - if ( !total_reset && - (old_src->ascii_src.piece_size != src->ascii_src.piece_size) ) { - String string = StorePiecesInString(old_src); - FreeAllPieces(old_src); - LoadPieces(src, NULL, string); - XtFree(string); - } - - return(FALSE); + AsciiSrcObject src = (AsciiSrcObject)cnew; + AsciiSrcObject old_src = (AsciiSrcObject)current; + Bool total_reset = False, string_set = False; + FILE *file; + unsigned int i; + + if (old_src->ascii_src.use_string_in_place + != src->ascii_src.use_string_in_place) { + XtAppWarning(XtWidgetToApplicationContext(cnew), + "AsciiSrc: The XtNuseStringInPlace resource may " + "not be changed."); + src->ascii_src.use_string_in_place = + old_src->ascii_src.use_string_in_place; + } + + for (i = 0; i < *num_args ; i++) + if (streq(args[i].name, XtNstring)) { + string_set = True; + break; + } + + if (string_set || (old_src->ascii_src.type != src->ascii_src.type)) { + RemoveOldStringOrFile(old_src, string_set); /* remove old info */ + file = InitStringOrFile(src, string_set); /* Init new info */ + LoadPieces(src, file, NULL); /* load new info into internal buffers */ + if (file != NULL) + fclose(file); +#ifndef OLDXAW + for (i = 0; i < src->text_src.num_text; i++) + /* Tell text widget what happened */ + XawTextSetSource(src->text_src.text[i], cnew, 0); +#else + XawTextSetSource(XtParent(cnew), cnew, 0); +#endif + total_reset = True; + } + + if (old_src->ascii_src.ascii_length != src->ascii_src.ascii_length) + src->ascii_src.piece_size = src->ascii_src.ascii_length + 1; + + if (!total_reset && + old_src->ascii_src.piece_size != src->ascii_src.piece_size) { + String string = StorePiecesInString(old_src); + + FreeAllPieces(old_src); + LoadPieces(src, NULL, string); + XtFree(string); + } + + return (False); } -/* Function Name: GetValuesHook - * Description: This is a get values hook routine that sets the - * values specific to the ascii source. - * Arguments: w - the AsciiSource Widget. - * args - the argument list. - * num_args - the number of args. - * Returns: none. +/* + * Function: + * XawAsciiSrcGetValuesHook + * + * Parameters: + * w - AsciiSource Widget + * args - argument list + * num_args - number of args + * + * Description: + * This is a get values hook routine that sets the + * values specific to the ascii source. */ - static void -GetValuesHook(w, args, num_args) -Widget w; -ArgList args; -Cardinal * num_args; +XawAsciiSrcGetValuesHook(Widget w, ArgList args, Cardinal *num_args) { - AsciiSrcObject src = (AsciiSrcObject) w; - int i; - - if (src->ascii_src.type == XawAsciiString) { - for (i = 0; i < *num_args ; i++ ) - if (streq(args[i].name, XtNstring)) { - if (src->ascii_src.use_string_in_place) { - *((char **) args[i].value) = src->ascii_src.first_piece->text; - } - else { - if (XawAsciiSave(w)) /* If save sucessful. */ - *((char **) args[i].value) = src->ascii_src.string; - } - break; - } - } -} - -/* Function Name: Destroy - * Description: Destroys an ascii source (frees all data) - * Arguments: src - the Ascii source Widget to free. - * Returns: none. - */ + AsciiSrcObject src = (AsciiSrcObject)w; + unsigned int i; + + if (src->ascii_src.type == XawAsciiString) { + for (i = 0; i < *num_args ; i++) + if (streq(args[i].name, XtNstring)) { + if (src->ascii_src.use_string_in_place) + *((char **)args[i].value) = src->ascii_src.first_piece->text; + else if (XawAsciiSave(w)) /* If save sucessful */ + *((char **)args[i].value) = src->ascii_src.string; + break; + } + } + } -static void -Destroy (w) -Widget w; +/* + * Function: + * XawAsciiSrcDestroy + * + * Parameters: + * src - Ascii source object to free + * + * Description: + * Destroys an ascii source (frees all data) + */ +static void +XawAsciiSrcDestroy(Widget w) { - RemoveOldStringOrFile((AsciiSrcObject) w, True); + RemoveOldStringOrFile((AsciiSrcObject) w, True); } -/************************************************************ - * +/* * Public routines + */ +/* + * Function: + * XawAsciiSourceFreeString * - ************************************************************/ - -/* Function Name: XawAsciiSourceFreeString - * Description: Frees the string returned by a get values call - * on the string when the source is of type string. - * Arguments: w - the AsciiSrc widget. - * Returns: none. + * Parameters: + * w - AsciiSrc widget + * + * Description: + * Frees the string returned by a get values call + * on the string when the source is of type string. */ - void -#if NeedFunctionPrototypes XawAsciiSourceFreeString(Widget w) -#else -XawAsciiSourceFreeString(w) -Widget w; -#endif { - AsciiSrcObject src = (AsciiSrcObject) w; - - /* If the src is really a multi, call the multi routine.*/ - - if ( XtIsSubclass( w, multiSrcObjectClass ) ) { - _XawMultiSourceFreeString( w ); - return; - } - - else if ( !XtIsSubclass( w, asciiSrcObjectClass ) ) { - XtErrorMsg("bad argument", "asciiSource", "XawError", - "XawAsciiSourceFreeString's parameter must be an asciiSrc or multiSrc.", - NULL, NULL); - } - - if (src->ascii_src.allocated_string && src->ascii_src.type != XawAsciiFile) { - src->ascii_src.allocated_string = FALSE; - XtFree(src->ascii_src.string); - src->ascii_src.string = NULL; - } + AsciiSrcObject src = (AsciiSrcObject)w; + + /* If the src is really a multi, call the multi routine */ + if (XtIsSubclass(w, multiSrcObjectClass)) { + _XawMultiSourceFreeString(w); + return; + } + else if (!XtIsSubclass(w, asciiSrcObjectClass)) { + XtErrorMsg("bad argument", "asciiSource", "XawError", + "XawAsciiSourceFreeString's parameter must be " + "an asciiSrc or multiSrc.", + NULL, NULL); + } + + if (src->ascii_src.allocated_string && src->ascii_src.type != XawAsciiFile) { + src->ascii_src.allocated_string = False; + XtFree(src->ascii_src.string); + src->ascii_src.string = NULL; + } } -/* Function Name: XawAsciiSave - * Description: Saves all the pieces into a file or string as required. - * Arguments: w - the asciiSrc Widget. - * Returns: TRUE if the save was successful. +/* + * Function: + * XawAsciiSave + * + * Parameters: + * w - asciiSrc Widget + * + * Description: + * Saves all the pieces into a file or string as required. + * + * Returns: + * True if the save was successful */ - -Boolean -#if NeedFunctionPrototypes +Bool XawAsciiSave(Widget w) -#else -XawAsciiSave(w) -Widget w; -#endif { - AsciiSrcObject src = (AsciiSrcObject) w; + AsciiSrcObject src = (AsciiSrcObject)w; - /* If the src is really a multi, call the multi save. */ + /* If the src is really a multi, call the multi save */ + if (XtIsSubclass(w, multiSrcObjectClass )) + return (_XawMultiSave(w)); - if ( XtIsSubclass( w, multiSrcObjectClass ) ) - return( _XawMultiSave( w ) ); - - else if ( !XtIsSubclass( w, asciiSrcObjectClass ) ) { - XtErrorMsg("bad argument", "asciiSource", "XawError", - "XawAsciiSave's parameter must be an asciiSrc or multiSrc.", + else if (!XtIsSubclass(w, asciiSrcObjectClass)) + XtErrorMsg("bad argument", "asciiSource", "XawError", + "XawAsciiSave's parameter must be an asciiSrc or multiSrc.", NULL, NULL); - } - -/* - * If using the string in place then there is no need to play games - * to get the internal info into a readable string. - */ - - if (src->ascii_src.use_string_in_place) - return(TRUE); - if (src->ascii_src.type == XawAsciiFile) { - char * string; + /* + * If using the string in place then there is no need to play games + * to get the internal info into a readable string. + */ + if (src->ascii_src.use_string_in_place) + return (True); - if (!src->ascii_src.changes) /* No changes to save. */ - return(TRUE); + if (src->ascii_src.type == XawAsciiFile) { +#ifdef OLDXAW + if (!src->ascii_src.changes) +#else + if (!src->text_src.changed) /* No changes to save */ +#endif + return (True); - string = StorePiecesInString(src); + if (WritePiecesToFile(src, src->ascii_src.string) == False) + return (False); + } + else { + if (src->ascii_src.allocated_string == True) + XtFree(src->ascii_src.string); + else + src->ascii_src.allocated_string = True; - if (WriteToFile(string, src->ascii_src.string) == FALSE) { - XtFree(string); - return(FALSE); + src->ascii_src.string = StorePiecesInString(src); } - XtFree(string); - } - else { - if (src->ascii_src.allocated_string == TRUE) - XtFree(src->ascii_src.string); - else - src->ascii_src.allocated_string = TRUE; - - src->ascii_src.string = StorePiecesInString(src); - } - src->ascii_src.changes = FALSE; - return(TRUE); +#ifdef OLDXAW + src->ascii_src.changes = False; +#else + src->text_src.changed = False; +#endif + + return (True); } -/* Function Name: XawAsciiSaveAsFile - * Description: Save the current buffer as a file. - * Arguments: w - the AsciiSrc widget. - * name - name of the file to save this file into. - * Returns: True if the save was sucessful. +/* + * Function: + * XawAsciiSaveAsFile + * + * Arguments: + * w - AsciiSrc widget + * name - name of the file to save this file into + * + * Description: + * Save the current buffer as a file. + * + * Returns: + * True if the save was sucessful */ - -Boolean -#if NeedFunctionPrototypes -XawAsciiSaveAsFile(Widget w, _Xconst char* name) -#else -XawAsciiSaveAsFile(w, name) -Widget w; -String name; -#endif +Bool +XawAsciiSaveAsFile(Widget w, _Xconst char *name) { - AsciiSrcObject src = (AsciiSrcObject) w; - String string; - Boolean ret; + AsciiSrcObject src = (AsciiSrcObject)w; + Bool ret; - /* If the src is really a multi, call the multi save. - */ + /* If the src is really a multi, call the multi save */ - if ( XtIsSubclass( w, multiSrcObjectClass ) ) - return( _XawMultiSaveAsFile( w, name ) ); + if (XtIsSubclass( w, multiSrcObjectClass)) + return (_XawMultiSaveAsFile(w, name)); - else if ( !XtIsSubclass( w, asciiSrcObjectClass ) ) { - XtErrorMsg("bad argument", "asciiSource", "XawError", - "XawAsciiSaveAsFile's 1st parameter must be an asciiSrc or multiSrc.", + else if (!XtIsSubclass(w, asciiSrcObjectClass)) + XtErrorMsg("bad argument", "asciiSource", "XawError", + "XawAsciiSaveAsFile's 1st parameter must be an " + "asciiSrc or multiSrc.", NULL, NULL); - } - string = StorePiecesInString(src); + if (src->ascii_src.type == XawAsciiFile) + ret = WritePiecesToFile(src, (String)name); + else { + String string = StorePiecesInString(src); + + ret = WriteToFile(string, (String)name, src->ascii_src.length); + XtFree(string); + } - ret = WriteToFile(string, name); - XtFree(string); - return(ret); + return (ret); } -/* Function Name: XawAsciiSourceChanged - * Description: Returns true if the source has changed since last saved. - * Arguments: w - the ascii source widget. - * Returns: a Boolean (see description). +/* + * Function: + * XawAsciiSourceChanged + * + * Parameters: + * w - ascii source widget + * + * Description: + * Returns true if the source has changed since last saved. + * + * Returns: + * A Boolean (see description). */ - -Boolean -#if NeedFunctionPrototypes +Bool XawAsciiSourceChanged(Widget w) +{ +#ifdef OLDXAW + if (XtIsSubclass(w, multiSrcObjectClass)) + return (((MultiSrcObject)w)->multi_src.changes); + + if (XtIsSubclass(w, asciiSrcObjectClass)) + return (((AsciiSrcObject)w)->ascii_src.changes); #else -XawAsciiSourceChanged(w) -Widget w; + if (XtIsSubclass(w, textSrcObjectClass)) + return (((TextSrcObject)w)->textSrc.changed); #endif -{ - if ( XtIsSubclass( w, multiSrcObjectClass ) ) - return( ( (MultiSrcObject) w )->multi_src.changes ); + XtErrorMsg("bad argument", "asciiSource", "XawError", + "XawAsciiSourceChanged parameter must be an " + "asciiSrc or multiSrc.", + NULL, NULL); - if ( XtIsSubclass( w, asciiSrcObjectClass ) ) - return( ( (AsciiSrcObject) w)->ascii_src.changes ); + return (True); +} - XtErrorMsg("bad argument", "asciiSource", "XawError", - "XawAsciiSourceChanged parameter must be an asciiSrc or multiSrc.", - NULL, NULL); +/* + * Private Functions + */ +static void +RemoveOldStringOrFile(AsciiSrcObject src, Bool checkString) +{ + FreeAllPieces(src); - return( True ); /* for gcc -Wall */ + if (checkString && src->ascii_src.allocated_string) { + XtFree(src->ascii_src.string); + src->ascii_src.allocated_string = False; + src->ascii_src.string = NULL; + } } - -/************************************************************ + +/* + * Function: + * WriteToFile * - * Private Functions. + * Parameters: + * string - string to write + * name - the name of the file * - ************************************************************/ - -static void -RemoveOldStringOrFile(src, checkString) -AsciiSrcObject src; -Boolean checkString; + * Description: + * Write the string specified to the begining of the file specified. + * + * Returns: + * returns True if sucessful, False otherwise + */ +static Bool +WriteToFile(String string, String name, unsigned length) { - FreeAllPieces(src); + int fd; - if (checkString && src->ascii_src.allocated_string) { - XtFree(src->ascii_src.string); - src->ascii_src.allocated_string = False; - src->ascii_src.string = NULL; - } + if ((fd = creat(name, 0666)) == -1 + || write(fd, string, length) == -1) + return (False); + + if (close(fd) == -1) + return (False); + + return (True); } -/* Function Name: WriteToFile - * Description: Write the string specified to the begining of the file - * specified. - * Arguments: string - string to write. - * name - the name of the file - * Returns: returns TRUE if sucessful, FALSE otherwise. +/* + * Function: + * WritePiecesToFile + * + * Parameters: + * src - ascii source object + * name - name of the file + * + * Description: + * Almost identical to WriteToFile, but only works for ascii src objects + * of type XawAsciiFile. This function avoids allocating temporary memory, + * what can be useful when editing very large files. + * + * Returns: + * returns True if sucessful, False otherwise */ - -static Boolean -WriteToFile(string, name) -String string, name; +static Bool +WritePiecesToFile(AsciiSrcObject src, String name) { - int fd; - - if ( ((fd = creat(name, 0666)) == -1 ) || - (write(fd, string, sizeof(unsigned char) * strlen(string)) == -1) ) - return(FALSE); + Piece *piece; + int fd; + + if (src->ascii_src.data_compression) { + Piece *tmp; + + piece = src->ascii_src.first_piece; + while (piece) { + int bytes = src->ascii_src.piece_size - piece->used; + + if (bytes > 0 && (tmp = piece->next) != NULL) { + bytes = XawMin(bytes, tmp->used); + memcpy(piece->text + piece->used, tmp->text, bytes); + memmove(tmp->text, tmp->text + bytes, tmp->used - bytes); + piece->used += bytes; + if ((tmp->used -= bytes) == 0) { + RemovePiece(src, tmp); + continue; + } + } + piece = piece->next; + } + } - if ( close(fd) == -1 ) - return(FALSE); + if ((fd = creat(name, 0666)) == -1) + return (False); - return(TRUE); + for (piece = src->ascii_src.first_piece; piece; piece = piece->next) + if (write(fd, piece->text, piece->used) == -1) + return (False); + + if (close(fd) == -1) + return (False); + + return (True); } -/* Function Name: StorePiecesInString - * Description: store the pieces in memory into a standard ascii string. - * Arguments: data - the ascii pointer data. - * Returns: none. +/* + * Function: + * StorePiecesInString + * + * Parameters: + * data - ascii pointer data + * + * Description: + * Store the pieces in memory into a standard ascii string. */ - static String -StorePiecesInString(src) -AsciiSrcObject src; +StorePiecesInString(AsciiSrcObject src) { - String string; - XawTextPosition first; - Piece * piece; + String string; + XawTextPosition first; + Piece *piece; - string = XtMalloc((unsigned) sizeof(unsigned char) * - src->ascii_src.length + 1); - - for (first = 0, piece = src->ascii_src.first_piece ; piece != NULL; - first += piece->used, piece = piece->next) - strncpy(string + first, piece->text, piece->used); + string = XtMalloc((unsigned)(src->ascii_src.length + 1)); - string[src->ascii_src.length] = '\0'; /* NULL terminate this sucker. */ + for (first = 0, piece = src->ascii_src.first_piece ; piece != NULL; + first += piece->used, piece = piece->next) + memcpy(string + first, piece->text, (unsigned)piece->used); -/* - * This will refill all pieces to capacity. - */ + string[src->ascii_src.length] = '\0'; - if (src->ascii_src.data_compression) { - FreeAllPieces(src); - LoadPieces(src, NULL, string); - } + /* + * This will refill all pieces to capacity + */ + if (src->ascii_src.data_compression) { + FreeAllPieces(src); + LoadPieces(src, NULL, string); + } - return(string); + return (string); } -/* Function Name: InitStringOrFile. - * Description: Initializes the string or file. - * Arguments: src - the AsciiSource. - * Returns: none - May exit though. +/* + * Function: + * InitStringOrFile + * + * Parameters: + * src - AsciiSource + * + * Description: + * Initializes the string or file. */ - static FILE * -InitStringOrFile(src, newString) -AsciiSrcObject src; -Boolean newString; +InitStringOrFile(AsciiSrcObject src, Bool newString) { - char * open_mode; - FILE * file; - char fileName[TMPSIZ]; + mode_t open_mode = 0; + const char *fdopen_mode = NULL; + int fd; + FILE *file; if (src->ascii_src.type == XawAsciiString) { - if (src->ascii_src.string == NULL) src->ascii_src.length = 0; - else if (! src->ascii_src.use_string_in_place) { + else if (!src->ascii_src.use_string_in_place) { src->ascii_src.string = XtNewString(src->ascii_src.string); src->ascii_src.allocated_string = True; src->ascii_src.length = strlen(src->ascii_src.string); } if (src->ascii_src.use_string_in_place) { + if (src->ascii_src.string != NULL) src->ascii_src.length = strlen(src->ascii_src.string); /* In case the length resource is incorrectly set */ if (src->ascii_src.length > src->ascii_src.ascii_length) src->ascii_src.ascii_length = src->ascii_src.length; - if (src->ascii_src.ascii_length == MAGIC_VALUE) + if (src->ascii_src.ascii_length == MAGIC_VALUE) src->ascii_src.piece_size = src->ascii_src.length; else src->ascii_src.piece_size = src->ascii_src.ascii_length + 1; } - - return(NULL); + + return (NULL); } -/* - * type is XawAsciiFile. - */ - - src->ascii_src.is_tempfile = FALSE; + /* + * type is XawAsciiFile + */ + src->ascii_src.is_tempfile = False; switch (src->text_src.edit_mode) { - case XawtextRead: - if (src->ascii_src.string == NULL) - XtErrorMsg("NoFile", "asciiSourceCreate", "XawError", - "Creating a read only disk widget and no file specified.", - NULL, 0); - open_mode = "r"; - break; - case XawtextAppend: - case XawtextEdit: - if (src->ascii_src.string == NULL) { - src->ascii_src.string = fileName; - (void) tmpnam(src->ascii_src.string); - src->ascii_src.is_tempfile = TRUE; - open_mode = "w"; - } else - open_mode = "r+"; - break; - default: - XtErrorMsg("badMode", "asciiSourceCreate", "XawError", - "Bad editMode for ascii source; must be Read, Append or Edit.", - NULL, NULL); + case XawtextRead: + if (src->ascii_src.string == NULL) + XtErrorMsg("NoFile", "asciiSourceCreate", "XawError", + "Creating a read only disk widget and no file specified.", + NULL, 0); + open_mode = O_RDONLY; + fdopen_mode = "r"; + break; + case XawtextAppend: + case XawtextEdit: + if (src->ascii_src.string == NULL) { + src->ascii_src.string = "*ascii-src*"; + src->ascii_src.is_tempfile = True; + } + else { +/* O_NOFOLLOW is a FreeBSD & Linux extension */ +#ifdef O_NOFOLLOW + open_mode = O_RDWR | O_NOFOLLOW; +#else + open_mode = O_RDWR; /* unsafe; subject to race conditions */ +#endif /* O_NOFOLLOW */ + fdopen_mode = "r+"; + } + break; + default: + XtErrorMsg("badMode", "asciiSourceCreate", "XawError", + "Bad editMode for ascii source; must be Read, " + "Append or Edit.", + NULL, NULL); } - /* Allocate new memory for the temp filename, because it is held in - * a stack variable, not static memory. This widget does not need - * to keep the private state field is_tempfile -- it is only accessed - * in this routine, and its former setting is unused. - */ + /* If is_tempfile, allocate a private copy of the text + * Unlikely to be changed, just to set allocated_string */ if (newString || src->ascii_src.is_tempfile) { src->ascii_src.string = XtNewString(src->ascii_src.string); - src->ascii_src.allocated_string = TRUE; + src->ascii_src.allocated_string = True; } - + if (!src->ascii_src.is_tempfile) { - if ((file = fopen(src->ascii_src.string, open_mode)) != 0) { - (void) fseek(file, (Off_t)0, 2); - src->ascii_src.length = (XawTextPosition) ftell(file); - return file; - } else { + if ((fd = open(src->ascii_src.string, open_mode, 0666)) != -1) { + if ((file = fdopen(fd, fdopen_mode))) { + (void)fseek(file, 0, SEEK_END); + src->ascii_src.length = (XawTextPosition)ftell(file); + return (file); + } + } + { String params[2]; Cardinal num_params = 2; - + params[0] = src->ascii_src.string; params[1] = strerror(errno); XtAppWarningMsg(XtWidgetToApplicationContext((Widget)src), "openError", "asciiSourceCreate", "XawWarning", "Cannot open file %s; %s", params, &num_params); } - } + } src->ascii_src.length = 0; - return((FILE *)NULL); + return (NULL); } static void -LoadPieces(src, file, string) -AsciiSrcObject src; -FILE * file; -char * string; +LoadPieces(AsciiSrcObject src, FILE *file, char *string) { - char *local_str, *ptr; - Piece * piece = NULL; - XawTextPosition left; + char *ptr; + Piece *piece = NULL; + XawTextPosition left; + + if (string == NULL) { + if (src->ascii_src.type == XawAsciiFile) { + if (src->ascii_src.length != 0) { + int len; + + left = 0; + fseek(file, 0, 0); + while (left < src->ascii_src.length) { + ptr = XtMalloc((unsigned)src->ascii_src.piece_size); + if ((len = fread(ptr, (Size_t)sizeof(unsigned char), + (Size_t)src->ascii_src.piece_size, file)) < 0) + XtErrorMsg("readError", "asciiSourceCreate", "XawError", + "fread returned error.", NULL, NULL); + piece = AllocNewPiece(src, piece); + piece->text = ptr; + piece->used = XawMin(len, src->ascii_src.piece_size); + left += piece->used; + } + } + else { + piece = AllocNewPiece(src, NULL); + piece->text = XtMalloc((unsigned)src->ascii_src.piece_size); + piece->used = 0; + } + return; + } + else + string = src->ascii_src.string; + } - if (string == NULL) { - if (src->ascii_src.type == XawAsciiFile) { - local_str = XtMalloc((unsigned) (src->ascii_src.length + 1) - * sizeof(unsigned char)); - if (src->ascii_src.length != 0) { - fseek(file, (Off_t)0, 0); - src->ascii_src.length = fread(local_str, (Size_t)sizeof(unsigned char), - (Size_t)src->ascii_src.length, file); - if (src->ascii_src.length <= 0) - XtErrorMsg("readError", "asciiSourceCreate", "XawError", - "fread returned error.", NULL, NULL); - } - local_str[src->ascii_src.length] = '\0'; + if (src->ascii_src.use_string_in_place) { + piece = AllocNewPiece(src, piece); + piece->used = XawMin(src->ascii_src.length, src->ascii_src.piece_size); + piece->text = src->ascii_src.string; + return; } - else - local_str = src->ascii_src.string; - } - else - local_str = string; - - if (src->ascii_src.use_string_in_place) { - piece = AllocNewPiece(src, piece); - piece->used = Min(src->ascii_src.length, src->ascii_src.piece_size); - piece->text = src->ascii_src.string; - return; - } - - ptr = local_str; - left = src->ascii_src.length; - - do { - piece = AllocNewPiece(src, piece); - - piece->text = XtMalloc((unsigned)src->ascii_src.piece_size - * sizeof(unsigned char)); - piece->used = Min(left, src->ascii_src.piece_size); - if (piece->used != 0) - strncpy(piece->text, ptr, piece->used); - - left -= piece->used; - ptr += piece->used; - } while (left > 0); - - if ( (src->ascii_src.type == XawAsciiFile) && (string == NULL) ) - XtFree(local_str); + + ptr = string; + left = src->ascii_src.length; + do { + piece = AllocNewPiece(src, piece); + + piece->text = XtMalloc((unsigned)src->ascii_src.piece_size); + piece->used = XawMin(left, src->ascii_src.piece_size); + if (piece->used != 0) + memcpy(piece->text, ptr, (unsigned)piece->used); + + left -= piece->used; + ptr += piece->used; + } while (left > 0); } -/* Function Name: AllocNewPiece - * Description: Allocates a new piece of memory. - * Arguments: src - The AsciiSrc Widget. - * prev - the piece just before this one, or NULL. - * Returns: the allocated piece. +/* + * Function: + * AllocNewPiece + * + * Parameters: + * src - AsciiSrc Widget + * prev - piece just before this one, or NULL + * + * Description: + * Allocates a new piece of memory. + * + * Returns: + * The allocated piece */ - static Piece * -AllocNewPiece(src, prev) -AsciiSrcObject src; -Piece * prev; +AllocNewPiece(AsciiSrcObject src, Piece *prev) { - Piece * piece = XtNew(Piece); - - if (prev == NULL) { - src->ascii_src.first_piece = piece; - piece->next = NULL; - } - else { - if (prev->next != NULL) - (prev->next)->prev = piece; - piece->next = prev->next; - prev->next = piece; - } - - piece->prev = prev; - - return(piece); + Piece *piece = XtNew(Piece); + + if (prev == NULL) { + src->ascii_src.first_piece = piece; + piece->next = NULL; + } + else { + if (prev->next != NULL) + (prev->next)->prev = piece; + piece->next = prev->next; + prev->next = piece; + } + + piece->prev = prev; + + return (piece); } -/* Function Name: FreeAllPieces - * Description: Frees all the pieces - * Arguments: src - The AsciiSrc Widget. - * Returns: none. +/* + * Function: + * FreeAllPieces + * + * Parameters: + * src - AsciiSrc Widget + * + * Description: + * Frees all the pieces. */ - -static void -FreeAllPieces(src) -AsciiSrcObject src; +static void +FreeAllPieces(AsciiSrcObject src) { - Piece * next, * first = src->ascii_src.first_piece; + Piece *next, * first = src->ascii_src.first_piece; - if (first->prev != NULL) - (void) printf("Xaw AsciiSrc Object: possible memory leak in FreeAllPieces().\n"); +#ifdef DEBUG + if (first->prev != NULL) + printf("Xaw AsciiSrc Object: possible memory leak in FreeAllPieces().\n"); +#endif - for ( ; first != NULL ; first = next ) { - next = first->next; - RemovePiece(src, first); - } + for (; first != NULL ; first = next) { + next = first->next; + RemovePiece(src, first); + } } - -/* Function Name: RemovePiece - * Description: Removes a piece from the list. - * Arguments: - * piece - the piece to remove. - * Returns: none. - */ +/* + * Function: + * RemovePiece + * + * Parameters: + * piece - piece to remove + * + * Description: + * Removes a piece from the list. + */ static void -RemovePiece(src, piece) -AsciiSrcObject src; -Piece * piece; +RemovePiece(AsciiSrcObject src, Piece *piece) { - if (piece->prev == NULL) - src->ascii_src.first_piece = piece->next; - else - (piece->prev)->next = piece->next; + if (piece->prev == NULL) + src->ascii_src.first_piece = piece->next; + else + piece->prev->next = piece->next; - if (piece->next != NULL) - (piece->next)->prev = piece->prev; + if (piece->next != NULL) + piece->next->prev = piece->prev; - if (!src->ascii_src.use_string_in_place) - XtFree(piece->text); + if (!src->ascii_src.use_string_in_place) + XtFree(piece->text); - XtFree((char *)piece); + XtFree((char *)piece); } -/* Function Name: FindPiece - * Description: Finds the piece containing the position indicated. - * Arguments: src - The AsciiSrc Widget. - * position - the position that we are searching for. - * RETURNED first - the position of the first character in this piece. - * Returns: piece - the piece that contains this position. +/* + * Function: + * FindPiece + * + * Parameters: + * src - AsciiSrc Widget + * position - position that we are searching for + * first - position of the first character in this piece (return) + * + * Description: + * Finds the piece containing the position indicated. + * + * Returns: + * the piece that contains this position */ - static Piece * -FindPiece(src, position, first) -AsciiSrcObject src; -XawTextPosition position, *first; +FindPiece(AsciiSrcObject src, XawTextPosition position, XawTextPosition *first) { - Piece * old_piece, * piece = src->ascii_src.first_piece; - XawTextPosition temp; + Piece *old_piece, *piece; + XawTextPosition temp; + + for (old_piece = NULL, piece = src->ascii_src.first_piece, temp = 0; + piece; old_piece = piece, piece = piece->next) + if ((temp += piece->used) > position) { + *first = temp - piece->used; + return (piece); + } - for ( temp = 0 ; piece != NULL ; temp += piece->used, piece = piece->next ) { - *first = temp; - old_piece = piece; + *first = temp - (old_piece ? old_piece->used : 0); - if ((temp + piece->used) > position) - return(piece); - } - return(old_piece); /* if we run off the end the return the last piece */ + return (old_piece); /* if we run off the end the return the last piece */ } -/* Function Name: MyStrncpy - * Description: Just like string copy, but slower and will always - * work on overlapping strings. - * Arguments: (same as strncpy) - s1, s2 - strings to copy (2->1). - * n - the number of chars to copy. - * Returns: s1. +/* + * Function: + * BreakPiece + * + * Parameters: + * src - AsciiSrc Widget + * piece - piece to break + * + * Description: + * Breaks a full piece into two new pieces. */ - -static String -MyStrncpy(s1, s2, n) -char * s1, * s2; -int n; +#define HALF_PIECE (src->ascii_src.piece_size >> 1) +static void +BreakPiece(AsciiSrcObject src, Piece *piece) { - char buf[256]; - char* temp; - - if (n == 0) return s1; + Piece *cnew = AllocNewPiece(src, piece); - if (n < sizeof buf) temp = buf; - else temp = XtMalloc((unsigned)sizeof(unsigned char) * n); + cnew->text = XtMalloc((unsigned)src->ascii_src.piece_size); + memcpy(cnew->text, piece->text + HALF_PIECE, + (unsigned)(src->ascii_src.piece_size - HALF_PIECE)); + piece->used = HALF_PIECE; + cnew->used = src->ascii_src.piece_size - HALF_PIECE; +} - strncpy(temp, s2, n); /* Saber has a bug that causes it to generate*/ - strncpy(s1, temp, n); /* a bogus warning message here (CDP 6/32/89)*/ +/*ARGSUSED*/ +static void +CvtStringToAsciiType(XrmValuePtr args, Cardinal *num_args, + XrmValuePtr fromVal, XrmValuePtr toVal) +{ + static XawAsciiType type; + XrmQuark q; + char name[7]; + + XmuNCopyISOLatin1Lowered(name, (char *)fromVal->addr, sizeof(name)); + q = XrmStringToQuark(name); + + if (q == Qstring) + type = XawAsciiString; + else if (q == Qfile) + type = XawAsciiFile; + else { + toVal->size = 0; + toVal->addr = NULL; + XtStringConversionWarning((char *)fromVal->addr, XtRAsciiType); + } - if (temp != buf) XtFree(temp); - return s1; + toVal->size = sizeof(XawAsciiType); + toVal->addr = (XPointer)&type; } - -/* Function Name: BreakPiece - * Description: Breaks a full piece into two new pieces. - * Arguments: src - The AsciiSrc Widget. - * piece - the piece to break. - * Returns: none. - */ - -#define HALF_PIECE (src->ascii_src.piece_size/2) -static void -BreakPiece(src, piece) -AsciiSrcObject src; -Piece * piece; +/*ARGSUSED*/ +static Boolean +CvtAsciiTypeToString(Display *dpy, XrmValuePtr args, Cardinal *num_args, + XrmValuePtr fromVal, XrmValuePtr toVal, + XtPointer *data) { - Piece * new = AllocNewPiece(src, piece); - - new->text = XtMalloc(src->ascii_src.piece_size * sizeof(unsigned char)); - strncpy(new->text, piece->text + HALF_PIECE, - src->ascii_src.piece_size - HALF_PIECE); - piece->used = HALF_PIECE; - new->used = src->ascii_src.piece_size - HALF_PIECE; + static String buffer; + Cardinal size; + + switch (*(XawAsciiType *)fromVal->addr) { + case XawAsciiFile: + buffer = XtEfile; + break; + case XawAsciiString: + buffer = XtEstring; + break; + default: + XawTypeToStringWarning(dpy, XtRAsciiType); + toVal->addr = NULL; + toVal->size = 0; + return (False); + } + + size = strlen(buffer) + 1; + if (toVal->addr != NULL) { + if (toVal->size < size) { + toVal->size = size; + return (False); + } + strcpy((char *)toVal->addr, buffer); + } + else + toVal->addr = (XPointer)buffer; + toVal->size = sizeof(String); + + return (True); } -/* ARGSUSED */ +/*ARGSUSED*/ static void -CvtStringToAsciiType(args, num_args, fromVal, toVal) -XrmValuePtr args; /* unused */ -Cardinal *num_args; /* unused */ -XrmValuePtr fromVal; -XrmValuePtr toVal; +GetDefaultPieceSize(Widget w, int offset, XrmValue *value) { - static XawAsciiType type; - static XrmQuark XtQEstring = NULLQUARK; - static XrmQuark XtQEfile; - XrmQuark q; - char lowerName[40]; - - if (XtQEstring == NULLQUARK) { - XtQEstring = XrmPermStringToQuark(XtEstring); - XtQEfile = XrmPermStringToQuark(XtEfile); - } - - if (strlen ((char*)fromVal->addr) < sizeof lowerName) { - XmuCopyISOLatin1Lowered(lowerName, (char *) fromVal->addr); - q = XrmStringToQuark(lowerName); - - if (q == XtQEstring) type = XawAsciiString; - else if (q == XtQEfile) type = XawAsciiFile; - else { - toVal->size = 0; - toVal->addr = NULL; - return; + static XPointer pagesize; + + if (pagesize == 0) { + pagesize = (XPointer)((long)_XawGetPageSize()); + if (pagesize < (XPointer)BUFSIZ) + pagesize = (XPointer)BUFSIZ; } - toVal->size = sizeof type; - toVal->addr = (XPointer) &type; - return; - } - toVal->size = 0; - toVal->addr = NULL; + + value->addr = (XPointer)&pagesize; } #if (defined(ASCII_STRING) || defined(ASCII_DISK)) @@ -1321,37 +1790,40 @@ XrmValuePtr toVal; #endif #ifdef ASCII_STRING -/************************************************************ - * +/* * Compatability functions. + */ +/* + * Function: + * AsciiStringSourceCreate + * + * Parameters: + * parent - widget that will own this source + * args - the argument list + * num_args - "" + * + * Description: + * Creates a string source. * - ************************************************************/ - -/* Function Name: AsciiStringSourceCreate - * Description: Creates a string source. - * Arguments: parent - the widget that will own this source. - * args, num_args - the argument list. - * Returns: a pointer to the new text source. + * Returns: + * A pointer to the new text source. */ - Widget -XawStringSourceCreate(parent, args, num_args) -Widget parent; -ArgList args; -Cardinal num_args; +XawStringSourceCreate(Widget parent, ArgList args, Cardinal num_args) { - XawTextSource src; - ArgList ascii_args; - Arg temp[2]; - - XtSetArg(temp[0], XtNtype, XawAsciiString); - XtSetArg(temp[1], XtNuseStringInPlace, TRUE); - ascii_args = XtMergeArgLists(temp, TWO, args, num_args); - - src = XtCreateWidget("genericAsciiString", asciiSrcObjectClass, parent, - ascii_args, num_args + TWO); - XtFree((char *)ascii_args); - return(src); + XawTextSource src; + ArgList ascii_args; + Arg temp[2]; + + XtSetArg(temp[0], XtNtype, XawAsciiString); + XtSetArg(temp[1], XtNuseStringInPlace, True); + ascii_args = XtMergeArgLists(temp, TWO, args, num_args); + + src = XtCreateWidget("genericAsciiString", asciiSrcObjectClass, parent, + ascii_args, num_args + TWO); + XtFree((char *)ascii_args); + + return (src); } /* @@ -1360,49 +1832,52 @@ Cardinal num_args; * * Chris D. Peterson 8/31/89. */ - -void -XawTextSetLastPos (w, lastPos) -Widget w; -XawTextPosition lastPos; +void +XawTextSetLastPos(Widget w, XawTextPosition lastPos) { - AsciiSrcObject src = (AsciiSrcObject) XawTextGetSource(w); + AsciiSrcObject src = (AsciiSrcObject)XawTextGetSource(w); - src->ascii_src.piece_size = lastPos; + src->ascii_src.piece_size = lastPos; } #endif /* ASCII_STRING */ #ifdef ASCII_DISK -/* Function Name: AsciiDiskSourceCreate - * Description: Creates a disk source. - * Arguments: parent - the widget that will own this source. - * args, num_args - the argument list. - * Returns: a pointer to the new text source. +/* + * Function: + * AsciiDiskSourceCreate + * + * Parameters: + * parent - widget that will own this source + * args - argument list + * num_args - "" + * + * Description: + * Creates a disk source. + * + * Returns: + * A pointer to the new text source */ - Widget -XawDiskSourceCreate(parent, args, num_args) -Widget parent; -ArgList args; -Cardinal num_args; +XawDiskSourceCreate(Widget parent, ArgList args, Cardinal num_args) { - XawTextSource src; - ArgList ascii_args; - Arg temp[1]; - int i; - - XtSetArg(temp[0], XtNtype, XawAsciiFile); - ascii_args = XtMergeArgLists(temp, ONE, args, num_args); - num_args++; - - for (i = 0; i < num_args; i++) - if (streq(ascii_args[i].name, XtNfile) || - streq(ascii_args[i].name, XtCFile)) - ascii_args[i].name = XtNstring; - - src = XtCreateWidget("genericAsciiDisk", asciiSrcObjectClass, parent, - ascii_args, num_args); - XtFree((char *)ascii_args); - return(src); + XawTextSource src; + ArgList ascii_args; + Arg temp[1]; + int i; + + XtSetArg(temp[0], XtNtype, XawAsciiFile); + ascii_args = XtMergeArgLists(temp, ONE, args, num_args); + num_args++; + + for (i = 0; i < num_args; i++) + if (streq(ascii_args[i].name, XtNfile) + || streq(ascii_args[i].name, XtCFile)) + ascii_args[i].name = XtNstring; + + src = XtCreateWidget("genericAsciiDisk", asciiSrcObjectClass, parent, + ascii_args, num_args); + XtFree((char *)ascii_args); + + return (src); } #endif /* ASCII_DISK */ diff --git a/src/AsciiText.c b/src/AsciiText.c index 3a6427f..f197679 100644 --- a/src/AsciiText.c +++ b/src/AsciiText.c @@ -46,18 +46,13 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ - -/*********************************************************************** - * - * AsciiText Widget - * - ***********************************************************************/ +/* $XFree86: xc/lib/Xaw/AsciiText.c,v 3.10 2001/12/14 19:54:39 dawes Exp $ */ /* - * AsciiText.c - Source code for AsciiText Widget. + * AsciiText.c - Source code for AsciiText Widget * * This Widget is intended to be used as a simple front end to the - * text widget with an ascii source and ascii sink attached to it. + * text widget with an ascii source and ascii sink attached to it * * Date: June 29, 1989 * @@ -69,267 +64,294 @@ SOFTWARE. #include <stdio.h> #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> - -#include <X11/Xaw/XawInit.h> -#include <X11/Xaw/Cardinals.h> #include <X11/Xaw/AsciiTextP.h> -#include <X11/Xaw/AsciiSrc.h> +#include <X11/Xaw/AsciiSrcP.h> #include <X11/Xaw/AsciiSink.h> -#include <X11/Xaw/MultiSrc.h> +#include <X11/Xaw/Cardinals.h> #include <X11/Xaw/MultiSinkP.h> +#include <X11/Xaw/MultiSrc.h> #include <X11/Xaw/XawImP.h> +#include <X11/Xaw/XawInit.h> +#include "Private.h" #define TAB_COUNT 32 -static void Initialize(), Destroy(); +/* + * Class Methods + */ +static void XawAsciiInitialize(Widget, Widget, ArgList, Cardinal*); +static void XawAsciiDestroy(Widget); +/* + * From TextSrc.c + */ +void _XawSourceAddText(Widget, Widget); +void _XawSourceRemoveText(Widget, Widget, Bool); + +#define Superclass (&textClassRec) AsciiTextClassRec asciiTextClassRec = { - { /* core fields */ - /* superclass */ (WidgetClass) &textClassRec, - /* class_name */ "Text", - /* widget_size */ sizeof(AsciiRec), - /* class_initialize */ XawInitializeWidgetSet, - /* class_part_init */ NULL, - /* class_inited */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* realize */ XtInheritRealize, - /* actions */ NULL, - /* num_actions */ 0, - /* resources */ NULL, - /* num_resource */ 0, - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure*/ XtExposeGraphicsExpose | XtExposeNoExpose, - /* compress_enterleave*/ TRUE, - /* visible_interest */ FALSE, - /* destroy */ Destroy, - /* resize */ XtInheritResize, - /* expose */ XtInheritExpose, - /* set_values */ NULL, - /* set_values_hook */ NULL, - /* set_values_almost*/ XtInheritSetValuesAlmost, - /* get_values_hook */ NULL, - /* accept_focus */ XtInheritAcceptFocus, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ XtInheritTranslations, - /* query_geometry */ XtInheritQueryGeometry + /* core */ + { + (WidgetClass)Superclass, /* superclass */ + "Text", /* class_name */ + sizeof(AsciiRec), /* widget_size */ + XawInitializeWidgetSet, /* class_initialize */ + NULL, /* class_part_init */ + False, /* class_inited */ + XawAsciiInitialize, /* initialize */ + NULL, /* initialize_hook */ + XtInheritRealize, /* realize */ + NULL, /* actions */ + 0, /* num_actions */ + NULL, /* resources */ + 0, /* num_resource */ + NULLQUARK, /* xrm_class */ + True, /* compress_motion */ + XtExposeGraphicsExpose | /* compress_exposure */ + XtExposeNoExpose, + True, /* compress_enterleave */ + False, /* visible_interest */ + XawAsciiDestroy, /* destroy */ + XtInheritResize, /* resize */ + XtInheritExpose, /* expose */ + NULL, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + NULL, /* get_values_hook */ + XtInheritAcceptFocus, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + XtInheritTranslations, /* tm_table */ + XtInheritQueryGeometry, /* query_geometry */ + }, + /* simple */ + { + XtInheritChangeSensitive, /* change_sensitive */ }, - { /* Simple fields */ - /* change_sensitive */ XtInheritChangeSensitive + /* text */ + { + NULL, /* extension */ }, - { /* text fields */ - /* empty */ 0 + /* ascii */ + { + NULL, /* extension */ }, - { /* ascii fields */ - /* empty */ 0 - } }; WidgetClass asciiTextWidgetClass = (WidgetClass)&asciiTextClassRec; - -static void -Initialize(request, new, args, num_args) -Widget request, new; -ArgList args; -Cardinal *num_args; -{ - AsciiWidget w = (AsciiWidget) new; - int i; - int tabs[TAB_COUNT], tab; - - MultiSinkObject sink; - - /* superclass Initialize can't set the following, - * as it didn't know the source or sink when it was called */ - - if (request->core.height == DEFAULT_TEXT_HEIGHT) - new->core.height = DEFAULT_TEXT_HEIGHT; - - - /* This is the main change for internationalization. */ - - if ( w->simple.international == True ) { /* The multi* are international. */ - - w->text.source = XtCreateWidget( "textSource", multiSrcObjectClass, - new, args, *num_args ); - w->text.sink = XtCreateWidget( "textSink", multiSinkObjectClass, - new, args, *num_args ); - } - else { - - w->text.source = XtCreateWidget( "textSource", asciiSrcObjectClass, - new, args, *num_args ); - w->text.sink = XtCreateWidget( "textSink", asciiSinkObjectClass, - new, args, *num_args ); - } - - if (w->core.height == DEFAULT_TEXT_HEIGHT) - w->core.height = VMargins(w) + XawTextSinkMaxHeight(w->text.sink, 1); - - for (i=0, tab=0 ; i < TAB_COUNT ; i++) - tabs[i] = (tab += 8); - - XawTextSinkSetTabs(w->text.sink, TAB_COUNT, tabs); - - XawTextDisableRedisplay(new); - XawTextEnableRedisplay(new); - - - /* If we are using a MultiSink we need to tell the input method stuff. */ - - if ( w->simple.international == True ) { - Arg list[4]; - Cardinal ac = 0; - - sink = (MultiSinkObject)w->text.sink; - _XawImRegister( new ); - XtSetArg (list[ac], XtNfontSet, sink->multi_sink.fontset); ac++; - XtSetArg (list[ac], XtNinsertPosition, w->text.insertPos); ac++; - XtSetArg (list[ac], XtNforeground, sink->text_sink.foreground); ac++; - XtSetArg (list[ac], XtNbackground, sink->text_sink.background); ac++; - _XawImSetValues(new, list, ac); - } -} - -static void -Destroy(w) -Widget w; -{ - /* Disconnect input method */ - - if ( ((AsciiWidget)w)->simple.international == True ) - _XawImUnregister( w ); - - if (w == XtParent(((AsciiWidget)w)->text.source)) - XtDestroyWidget( ((AsciiWidget)w)->text.source ); - - if (w == XtParent(((AsciiWidget)w)->text.sink)) - XtDestroyWidget( ((AsciiWidget)w)->text.sink ); -} - #ifdef ASCII_STRING - -/************************************************************ - * - * Ascii String Compatibility Code. - * - ************************************************************/ - AsciiStringClassRec asciiStringClassRec = { - { /* core fields */ - /* superclass */ (WidgetClass) &asciiTextClassRec, - /* class_name */ "Text", - /* widget_size */ sizeof(AsciiStringRec), - /* class_initialize */ NULL, - /* class_part_init */ NULL, - /* class_inited */ FALSE, - /* initialize */ NULL, - /* initialize_hook */ NULL, - /* realize */ XtInheritRealize, - /* actions */ NULL, - /* num_actions */ 0, - /* resources */ NULL, - /* num_ resource */ 0, - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure*/ XtExposeGraphicsExpose, - /* compress_enterleave*/ TRUE, - /* visible_interest */ FALSE, - /* destroy */ NULL, - /* resize */ XtInheritResize, - /* expose */ XtInheritExpose, - /* set_values */ NULL, - /* set_values_hook */ NULL, - /* set_values_almost*/ XtInheritSetValuesAlmost, - /* get_values_hook */ NULL, - /* accept_focus */ XtInheritAcceptFocus, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ XtInheritTranslations, - /* query_geometry */ XtInheritQueryGeometry + /* core */ + { + (WidgetClass)&asciiTextClassRec, /* superclass */ + "Text", /* class_name */ + sizeof(AsciiStringRec), /* widget_size */ + NULL, /* class_initialize */ + NULL, /* class_part_init */ + False, /* class_inited */ + NULL, /* initialize */ + NULL, /* initialize_hook */ + XtInheritRealize, /* realize */ + NULL, /* actions */ + 0, /* num_actions */ + NULL, /* resources */ + 0, /* num_resource */ + NULLQUARK, /* xrm_class */ + True, /* compress_motion */ + XtExposeGraphicsExpose | /* compress_exposure */ + XtExposeNoExpose, + True, /* compress_enterleave */ + False, /* visible_interest */ + NULL, /* destroy */ + XtInheritResize, /* resize */ + XtInheritExpose, /* expose */ + NULL, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + NULL, /* get_values_hook */ + XtInheritAcceptFocus, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + XtInheritTranslations, /* tm_table */ + XtInheritQueryGeometry, /* query_geometry */ + }, + /* simple */ + { + XtInheritChangeSensitive, /* change_sensitive */ }, - { /* Simple fields */ - /* change_sensitive */ XtInheritChangeSensitive + /* text */ + { + NULL, /* extension */ }, - { /* text fields */ - /* empty */ 0 + /* ascii */ + { + NULL, /* extension */ + }, + /* string */ + { + NULL, /* extension */ }, - { /* ascii fields */ - /* empty */ 0 - } }; WidgetClass asciiStringWidgetClass = (WidgetClass)&asciiStringClassRec; - #endif /* ASCII_STRING */ #ifdef ASCII_DISK - -/************************************************************ - * - * Ascii Disk Compatibility Code. - * - ************************************************************/ - AsciiDiskClassRec asciiDiskClassRec = { - { /* core fields */ - /* superclass */ (WidgetClass) &asciiTextClassRec, - /* class_name */ "Text", - /* widget_size */ sizeof(AsciiDiskRec), - /* class_initialize */ NULL, - /* class_part_init */ NULL, - /* class_inited */ FALSE, - /* initialize */ NULL, - /* initialize_hook */ NULL, - /* realize */ XtInheritRealize, - /* actions */ NULL, - /* num_actions */ 0, - /* resources */ NULL, - /* num_ resource */ 0, - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure*/ XtExposeGraphicsExpose, - /* compress_enterleave*/ TRUE, - /* visible_interest */ FALSE, - /* destroy */ NULL, - /* resize */ XtInheritResize, - /* expose */ XtInheritExpose, - /* set_values */ NULL, - /* set_values_hook */ NULL, - /* set_values_almost*/ XtInheritSetValuesAlmost, - /* get_values_hook */ NULL, - /* accept_focus */ XtInheritAcceptFocus, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ XtInheritTranslations, - /* query_geometry */ XtInheritQueryGeometry + /* core */ + { + (WidgetClass)&asciiTextClassRec, /* superclass */ + "Text", /* class_name */ + sizeof(AsciiDiskRec), /* widget_size */ + NULL, /* class_initialize */ + NULL, /* class_part_init */ + False, /* class_inited */ + NULL, /* initialize */ + NULL, /* initialize_hook */ + XtInheritRealize, /* realize */ + NULL, /* actions */ + 0, /* num_actions */ + NULL, /* resources */ + 0, /* num_resource */ + NULLQUARK, /* xrm_class */ + True, /* compress_motion */ + True, /* compress_exposure */ + XtExposeGraphicsExpose | /* compress_enterleave */ + XtExposeNoExpose, + False, /* visible_interest */ + NULL, /* destroy */ + XtInheritResize, /* resize */ + XtInheritExpose, /* expose */ + NULL, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + NULL, /* get_values_hook */ + XtInheritAcceptFocus, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + XtInheritTranslations, /* tm_table */ + XtInheritQueryGeometry, /* query_geometry */ + }, + /* simple */ + { + XtInheritChangeSensitive, /* change_sensitive */ }, - { /* Simple fields */ - /* change_sensitive */ XtInheritChangeSensitive + /* text */ + { + NULL, /* extension */ }, - { /* text fields */ - /* empty */ 0 + /* ascii */ + { + NULL, /* extension */ + }, + /* disk */ + { + NULL, /* extension */ }, - { /* ascii fields */ - /* empty */ 0 - } }; WidgetClass asciiDiskWidgetClass = (WidgetClass)&asciiDiskClassRec; - #endif /* ASCII_DISK */ +/* + * Implementation + */ +static void +XawAsciiInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) +{ + AsciiWidget w = (AsciiWidget)cnew; + int i; + int tabs[TAB_COUNT], tab; + + MultiSinkObject sink; + + /* superclass Initialize can't set the following, + * as it didn't know the source or sink when it was called + */ + if (XtHeight(request) == DEFAULT_TEXT_HEIGHT) + XtHeight(cnew) = DEFAULT_TEXT_HEIGHT; + + /* This is the main change for internationalization */ + if (w->simple.international == True) { /* The multi* are international */ + if (w->text.sink == NULL) + w->text.sink = XtCreateWidget("textSink", multiSinkObjectClass, + cnew, args, *num_args); + else if (!XtIsSubclass(w->text.sink, multiSinkObjectClass)) + XtError("Sink object is not a subclass of multiSink"); + + if (w->text.source == NULL) + w->text.source = XtCreateWidget("textSource", multiSrcObjectClass, + cnew, args, *num_args); + else if (!XtIsSubclass(w->text.source, multiSrcObjectClass)) + XtError("Source object is not a subclass of multiSrc"); +#ifndef OLDXAW + else + _XawSourceAddText(w->text.source, cnew); +#endif + } + else { + if (w->text.sink == NULL) + w->text.sink = XtCreateWidget("textSink", asciiSinkObjectClass, + cnew, args, *num_args); + else if (!XtIsSubclass(w->text.source, asciiSinkObjectClass)) + XtError("Sink object is not a subclass of asciiSink"); + + if (w->text.source == NULL) + w->text.source = XtCreateWidget("textSource", asciiSrcObjectClass, + cnew, args, *num_args); + else if (!XtIsSubclass(w->text.source, asciiSrcObjectClass)) + XtError("Source object is not a subclass of asciiSrc"); +#ifndef OLDXAW + else + _XawSourceAddText(w->text.source, cnew); +#endif + } + + if (XtHeight(w) == DEFAULT_TEXT_HEIGHT) + XtHeight(w) = VMargins(w) + XawTextSinkMaxHeight(w->text.sink, 1); + + for (i = 0, tab = 0; i < TAB_COUNT; i++) + tabs[i] = (tab += 8); + + XawTextSinkSetTabs(w->text.sink, TAB_COUNT, tabs); + XawTextDisableRedisplay(cnew); + XawTextEnableRedisplay(cnew); + _XawImRegister(cnew); + /* If we are using a MultiSink we need to tell the input method stuff */ + if (w->simple.international == True) { + Arg list[4]; + Cardinal ac = 0; + sink = (MultiSinkObject)w->text.sink; + XtSetArg(list[ac], XtNfontSet, sink->multi_sink.fontset); ac++; + XtSetArg(list[ac], XtNinsertPosition, w->text.insertPos); ac++; + XtSetArg(list[ac], XtNforeground, sink->text_sink.foreground); ac++; + XtSetArg(list[ac], XtNbackground, sink->text_sink.background); ac++; + _XawImSetValues(cnew, list, ac); + } +} +static void +XawAsciiDestroy(Widget w) +{ + AsciiWidget ascii = (AsciiWidget)w; + _XawImUnregister(w); + if (w == XtParent(ascii->text.sink)) + XtDestroyWidget(ascii->text.sink); - - - +#ifdef OLDXAW + if (w == XtParent(ascii->text.source)) + XtDestroyWidget(ascii->text.source); +#else + _XawSourceRemoveText(ascii->text.source, w, + ascii->text.source && + w == XtParent(ascii->text.source)); +#endif +} @@ -46,121 +46,161 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/Box.c,v 1.15 2001/12/14 19:54:39 dawes Exp $ */ +#include <X11/IntrinsicP.h> +#include <X11/StringDefs.h> +#include <X11/Xmu/Misc.h> +#include <X11/Xaw/BoxP.h> +#include <X11/Xaw/XawInit.h> +#include "Private.h" -/* - * Box.c - Box composite widget - * +/* + * Class Methods */ +static void XawBoxChangeManaged(Widget); +static void XawBoxClassInitialize(void); +#ifndef OLDXAW +static void XawBoxExpose(Widget, XEvent*, Region); +#endif +static XtGeometryResult XawBoxGeometryManager(Widget, XtWidgetGeometry*, + XtWidgetGeometry*); +static void XawBoxInitialize(Widget, Widget, ArgList, Cardinal*); +static XtGeometryResult XawBoxQueryGeometry(Widget, XtWidgetGeometry*, + XtWidgetGeometry*); +static void XawBoxRealize(Widget, Mask*, XSetWindowAttributes*); +static void XawBoxResize(Widget); +static Boolean XawBoxSetValues(Widget, Widget, Widget, + ArgList, Cardinal*); -#include <X11/IntrinsicP.h> -#include <X11/StringDefs.h> -#include <X11/Xmu/Misc.h> -#include <X11/Xaw/XawInit.h> -#include <X11/Xaw/BoxP.h> +/* + * Prototypes + */ +static void DoLayout(BoxWidget, unsigned int, unsigned int, + Dimension*, Dimension*, Bool); +static Bool TryNewLayout(BoxWidget); -/**************************************************************** - * - * Box Resources - * - ****************************************************************/ +/* + * Initialization + */ +#ifndef OLDXAW +static XtActionsRec actions[] = { + {"set-values", XawSetValuesAction}, + {"get-values", XawGetValuesAction}, + {"declare", XawDeclareAction}, + {"call-proc", XawCallProcAction}, +}; +#endif static XtResource resources[] = { - { XtNhSpace, XtCHSpace, XtRDimension, sizeof(Dimension), - XtOffsetOf(BoxRec, box.h_space), - XtRImmediate, (XtPointer)4 }, - { XtNvSpace, XtCVSpace, XtRDimension, sizeof(Dimension), - XtOffsetOf(BoxRec, box.v_space), - XtRImmediate, (XtPointer)4 }, - { XtNorientation, XtCOrientation, XtROrientation, sizeof(XtOrientation), - XtOffsetOf(BoxRec, box.orientation), - XtRImmediate, (XtPointer)XtorientVertical }, + { + XtNhSpace, + XtCHSpace, + XtRDimension, + sizeof(Dimension), + XtOffsetOf(BoxRec, box.h_space), + XtRImmediate, + (XtPointer)4 + }, + { + XtNvSpace, + XtCVSpace, + XtRDimension, + sizeof(Dimension), + XtOffsetOf(BoxRec, box.v_space), + XtRImmediate, + (XtPointer)4 + }, + { + XtNorientation, + XtCOrientation, + XtROrientation, + sizeof(XtOrientation), + XtOffsetOf(BoxRec, box.orientation), + XtRImmediate, + (XtPointer)XtorientVertical + }, +#ifndef OLDXAW + { + XawNdisplayList, + XawCDisplayList, + XawRDisplayList, + sizeof(XawDisplayList*), + XtOffsetOf(BoxRec, box.display_list), + XtRImmediate, + NULL + }, +#endif }; -/**************************************************************** - * - * Full class record constant - * - ****************************************************************/ - -static void ClassInitialize(); -static void Initialize(); -static void Realize(); -static void Resize(); -static Boolean SetValues(); -static XtGeometryResult GeometryManager(); -static void ChangeManaged(); -static XtGeometryResult PreferredSize(); - BoxClassRec boxClassRec = { + /* core */ + { + (WidgetClass)&compositeClassRec, /* superclass */ + "Box", /* class_name */ + sizeof(BoxRec), /* widget_size */ + XawBoxClassInitialize, /* class_initialize */ + NULL, /* class_part_init */ + False, /* class_inited */ + XawBoxInitialize, /* initialize */ + NULL, /* initialize_hook */ + XawBoxRealize, /* realize */ +#ifndef OLDXAW + actions, /* actions */ + XtNumber(actions), /* num_actions */ +#else + NULL, /* actions */ + 0, /* num_actions */ +#endif + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + True, /* compress_motion */ + True, /* compress_exposure */ + True, /* compress_enterleave */ + False, /* visible_interest */ + NULL, /* destroy */ + XawBoxResize, /* resize */ +#ifndef OLDXAW + XawBoxExpose, /* expose */ +#else + NULL, /* expose */ +#endif + XawBoxSetValues, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + NULL, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + NULL, /* tm_table */ + XawBoxQueryGeometry, /* query_geometry */ + XtInheritDisplayAccelerator, /* display_accelerator */ + NULL, /* extension */ + }, + /* composite */ + { + XawBoxGeometryManager, /* geometry_manager */ + XawBoxChangeManaged, /* change_managed */ + XtInheritInsertChild, /* insert_child */ + XtInheritDeleteChild, /* delete_child */ + NULL, /* extension */ + }, + /* box */ { -/* core_class fields */ - /* superclass */ (WidgetClass) &compositeClassRec, - /* class_name */ "Box", - /* widget_size */ sizeof(BoxRec), - /* class_initialize */ ClassInitialize, - /* class_part_init */ NULL, - /* class_inited */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* realize */ Realize, - /* actions */ NULL, - /* num_actions */ 0, - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure */ TRUE, - /* compress_enterleave*/ TRUE, - /* visible_interest */ FALSE, - /* destroy */ NULL, - /* resize */ Resize, - /* expose */ NULL, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* set_values_almost */ XtInheritSetValuesAlmost, - /* get_values_hook */ NULL, - /* accept_focus */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ NULL, - /* query_geometry */ PreferredSize, - /* display_accelerator*/ XtInheritDisplayAccelerator, - /* extension */ NULL - },{ -/* composite_class fields */ - /* geometry_manager */ GeometryManager, - /* change_managed */ ChangeManaged, - /* insert_child */ XtInheritInsertChild, - /* delete_child */ XtInheritDeleteChild, - /* extension */ NULL - },{ -/* Box class fields */ - /* empty */ 0, - } + NULL, /* extension */ + }, }; WidgetClass boxWidgetClass = (WidgetClass)&boxClassRec; - -/**************************************************************** - * - * Private Routines - * - ****************************************************************/ - /* - * * Do a layout, either actually assigning positions, or just calculating size. * Returns minimum width and height that will preserve the same layout. - * */ - -static void DoLayout(bbw, width, height, reply_width, reply_height, position) - BoxWidget bbw; - Dimension width, height; - Dimension *reply_width, *reply_height; /* bounding box */ - Boolean position; /* actually reposition the windows? */ +static void +DoLayout(BoxWidget bbw, unsigned int width, unsigned int height, + Dimension *reply_width, Dimension *reply_height, Bool position) { Boolean vbox = (bbw->box.orientation == XtorientVertical); Cardinal i; @@ -169,18 +209,20 @@ static void DoLayout(bbw, width, height, reply_width, reply_height, position) Dimension bw, bh; /* Width and height needed for current widget */ Dimension h_space; /* Local copy of bbw->box.h_space */ Widget widget; /* Current widget */ - int num_mapped_children = 0; + unsigned int num_mapped_children = 0; /* Box width and height */ h_space = bbw->box.h_space; w = 0; for (i = 0; i < bbw->composite.num_children; i++) { - if ( bbw->composite.children[i]->core.width > w ) - w = bbw->composite.children[i]->core.width; + if (XtIsManaged(bbw->composite.children[i]) + && bbw->composite.children[i]->core.width > w) + w = bbw->composite.children[i]->core.width; } w += h_space; - if ( w > width ) width = w; + if (w > width) + width = w; h = bbw->box.v_space; /* Line width and height */ @@ -190,13 +232,14 @@ static void DoLayout(bbw, width, height, reply_width, reply_height, position) for (i = 0; i < bbw->composite.num_children; i++) { widget = bbw->composite.children[i]; if (widget->core.managed) { - if (widget->core.mapped_when_managed) num_mapped_children++; + if (widget->core.mapped_when_managed) + num_mapped_children++; /* Compute widget width */ - bw = widget->core.width + 2*widget->core.border_width + h_space; + bw = XtWidth(widget) + (XtBorderWidth(widget)<<1) + h_space; if ((Dimension)(lw + bw) > width) { if (lw > h_space) { /* At least one widget on this line, and - * can't fit any more. Start new line if vbox. + * can't fit any more. Start new line if vbox */ AssignMax(w, lw); if (vbox) { @@ -207,12 +250,12 @@ static void DoLayout(bbw, width, height, reply_width, reply_height, position) } else if (!position) { /* too narrow for this widget; we'll assume we can grow */ - DoLayout(bbw, lw + bw, height, reply_width, + DoLayout(bbw, (unsigned)(lw + bw), height, reply_width, reply_height, position); return; } } - if (position && (lw != widget->core.x || h != widget->core.y)) { + if (position && (lw != XtX(widget) || h != XtY(widget))) { /* It would be nice to use window gravity, but there isn't * sufficient fine-grain control to nicely handle all * situations (e.g. when only the height changes -- @@ -226,47 +269,51 @@ static void DoLayout(bbw, width, height, reply_width, reply_height, position) * force extra exposures as children occlude each other. */ if (XtIsRealized(widget) && widget->core.mapped_when_managed) - XUnmapWindow( XtDisplay(widget), XtWindow(widget) ); + XUnmapWindow( XtDisplay(widget), XtWindow(widget)); XtMoveWidget(widget, (int)lw, (int)h); } lw += bw; - bh = widget->core.height + 2*widget->core.border_width; + bh = XtHeight(widget) + (XtBorderWidth(widget) << 1); AssignMax(lh, bh); - } /* if managed */ - } /* for */ + } + } if (!vbox && width && lw > width && lh < height) { /* reduce width if too wide and height not filled */ Dimension sw = lw, sh = lh; - Dimension width_needed; + Dimension width_needed = width; XtOrientation orientation = bbw->box.orientation; + bbw->box.orientation = XtorientVertical; while (sh < height && sw > width) { width_needed = sw; - DoLayout(bbw, sw-1, height, &sw, &sh, False); + DoLayout(bbw, (unsigned)(sw-1), height, &sw, &sh, False); } - if (sh < height) width_needed = sw; + if (sh < height) + width_needed = sw; if (width_needed != lw) { - DoLayout(bbw,width_needed,height,reply_width,reply_height,position); + DoLayout(bbw, width_needed, height, + reply_width, reply_height, position); bbw->box.orientation = orientation; return; } bbw->box.orientation = orientation; } - if ( vbox && ( ( width < w ) || ( width < lw ) ) ) { - AssignMax(w, lw); - DoLayout( bbw, w, height, reply_width, reply_height, position ); - return; + if (vbox && (width < w || width < lw)) { + AssignMax(w, lw); + DoLayout(bbw, w, height, reply_width, reply_height, position); + return; } - if (position && XtIsRealized((Widget)bbw)) { + if (position && XtIsRealized((Widget)bbw)) { if (bbw->composite.num_children == num_mapped_children) - XMapSubwindows( XtDisplay((Widget)bbw), XtWindow((Widget)bbw) ); + XMapSubwindows(XtDisplay((Widget)bbw), XtWindow((Widget)bbw)); else { - int i = bbw->composite.num_children; + int ii = bbw->composite.num_children; Widget *childP = bbw->composite.children; - for (; i > 0; childP++, i--) - if (XtIsRealized(*childP) && XtIsManaged(*childP) && - (*childP)->core.mapped_when_managed) + + for (; ii > 0; childP++, ii--) + if (XtIsRealized(*childP) && XtIsManaged(*childP) + && (*childP)->core.mapped_when_managed) XtMapWidget(*childP); } } @@ -282,17 +329,14 @@ static void DoLayout(bbw, width, height, reply_width, reply_height, position) } /* - * - * Calculate preferred size, given constraining box, caching it in the widget. - * + * Calculate preferred size, given constraining box, caching it in the widget */ - -static XtGeometryResult PreferredSize(widget, constraint, preferred) - Widget widget; - XtWidgetGeometry *constraint, *preferred; +static XtGeometryResult +XawBoxQueryGeometry(Widget widget, XtWidgetGeometry *constraint, + XtWidgetGeometry *preferred) { BoxWidget w = (BoxWidget)widget; - Dimension width /*, height */; + Dimension width; Dimension preferred_width = w->box.preferred_width; Dimension preferred_height = w->box.preferred_height; @@ -300,23 +344,23 @@ static XtGeometryResult PreferredSize(widget, constraint, preferred) if (constraint->request_mode == 0) /* parent isn't going to change w or h, so nothing to re-compute */ - return XtGeometryYes; + return (XtGeometryYes); - if (constraint->request_mode == w->box.last_query_mode && - (!(constraint->request_mode & CWWidth) || - constraint->width == w->box.last_query_width) && - (!(constraint->request_mode & CWHeight) || - constraint->height == w->box.last_query_height)) { + if (constraint->request_mode == w->box.last_query_mode + && (!(constraint->request_mode & CWWidth) + || constraint->width == w->box.last_query_width) + && (!(constraint->request_mode & CWHeight) + || constraint->height == w->box.last_query_height)) { /* same query; current preferences are still valid */ preferred->request_mode = CWWidth | CWHeight; preferred->width = preferred_width; preferred->height = preferred_height; - if (constraint->request_mode == (CWWidth | CWHeight) && - constraint->width == preferred_width && - constraint->height == preferred_height) - return XtGeometryYes; + if (constraint->request_mode == (CWWidth | CWHeight) + && constraint->width == preferred_width + && constraint->height == preferred_height) + return (XtGeometryYes); else - return XtGeometryAlmost; + return (XtGeometryAlmost); } /* else gotta do it the long way... @@ -330,8 +374,8 @@ static XtGeometryResult PreferredSize(widget, constraint, preferred) if (constraint->request_mode & CWWidth) width = constraint->width; - else /* if (constraint->request_mode & CWHeight) */ { - /* let's see if I can become any narrower */ + else { /* if (constraint->request_mode & CWHeight) */ + /* let's see if I can become any narrower */ width = 0; constraint->width = 65535; } @@ -340,31 +384,28 @@ static XtGeometryResult PreferredSize(widget, constraint, preferred) height = (constraint->request_mode & CWHeight) ? constraint->height : *preferred_height; */ - DoLayout(w, width, (Dimension)0, - &preferred_width, &preferred_height, FALSE); + DoLayout(w, width, 0, &preferred_width, &preferred_height, False); - if (constraint->request_mode & CWHeight && - preferred_height > constraint->height) { + if (constraint->request_mode & CWHeight + && preferred_height > constraint->height) { /* find minimum width for this height */ - if (preferred_width > constraint->width) { - /* punt; over-constrained */ - } - else { + if (preferred_width <= constraint->width) { width = preferred_width; do { /* find some width big enough to stay within this height */ - width *= 2; - if (width > constraint->width) width = constraint->width; - DoLayout(w, width, 0, &preferred_width, &preferred_height, FALSE); - } while (preferred_height > constraint->height && - width < constraint->width); + width <<= 1; + if (width > constraint->width) + width = constraint->width; + DoLayout(w, width, 0, &preferred_width, &preferred_height, False); + } while (preferred_height > constraint->height + && width < constraint->width); if (width != constraint->width) { do { /* find minimum width */ width = preferred_width; - DoLayout(w, preferred_width-1, 0, - &preferred_width, &preferred_height, FALSE); + DoLayout(w, (unsigned)(preferred_width - 1), 0, + &preferred_width, &preferred_height, False); } while (preferred_height < constraint->height); /* one last time */ - DoLayout(w, width, 0, &preferred_width, &preferred_height, FALSE); + DoLayout(w, width, 0, &preferred_width, &preferred_height, False); } } } @@ -376,241 +417,256 @@ static XtGeometryResult PreferredSize(widget, constraint, preferred) if (constraint->request_mode == (CWWidth|CWHeight) && constraint->width == preferred_width && constraint->height == preferred_height) - return XtGeometryYes; - else - return XtGeometryAlmost; + return (XtGeometryYes); + return (XtGeometryAlmost); } /* - * * Actually layout the box - * */ - -static void Resize(w) - Widget w; +static void +XawBoxResize(Widget w) { - Dimension junk; - - DoLayout((BoxWidget)w, w->core.width, w->core.height, &junk, &junk, TRUE); + Dimension tmp; -} /* Resize */ + DoLayout((BoxWidget)w, XtWidth(w), XtHeight(w), &tmp, &tmp, True); +} /* - * * Try to do a new layout within the current width and height; * if that fails try to resize and do it within the box returne - * by PreferredSize. + * by XawBoxQueryGeometry * * TryNewLayout just says if it's possible, and doesn't actually move the kids */ - -static Boolean TryNewLayout(bbw) - BoxWidget bbw; +static Bool +TryNewLayout(BoxWidget bbw) { Dimension preferred_width, preferred_height; Dimension proposed_width, proposed_height; int iterations; - DoLayout( bbw, bbw->core.width, bbw->core.height, - &preferred_width, &preferred_height, FALSE ); + DoLayout(bbw, bbw->core.width, bbw->core.height, + &preferred_width, &preferred_height, False); /* at this point, preferred_width is guaranteed to not be greater than bbw->core.width unless some child is larger, so there's no point in re-computing another layout */ - if ((bbw->core.width == preferred_width) && - (bbw->core.height == preferred_height)) { - /* Same size */ - return (TRUE); - } + if (XtWidth(bbw) == preferred_width && XtHeight(bbw) == preferred_height) + return (True); - /* let's see if our parent will go for a new size. */ + /* let's see if our parent will go for a new size */ iterations = 0; proposed_width = preferred_width; proposed_height = preferred_height; do { switch (XtMakeResizeRequest((Widget)bbw,proposed_width,proposed_height, - &proposed_width, &proposed_height)) - { + &proposed_width, &proposed_height)) { case XtGeometryYes: - return (TRUE); - + return (True); case XtGeometryNo: if (iterations > 0) /* protect from malicious parents who change their minds */ - DoLayout( bbw, bbw->core.width, bbw->core.height, - &preferred_width, &preferred_height, FALSE ); - if ((preferred_width <= bbw->core.width) && - (preferred_height <= bbw->core.height)) - return (TRUE); + DoLayout(bbw, bbw->core.width, bbw->core.height, + &preferred_width, &preferred_height, False); + if (preferred_width <= XtWidth(bbw) + && preferred_height <= XtHeight(bbw)) + return (True); else - return (FALSE); - + return (False); case XtGeometryAlmost: if (proposed_height >= preferred_height && proposed_width >= preferred_width) { - /* * Take it, and assume the parent knows what it is doing. * * The parent must accept this since it was returned in * almost. - * */ - (void) XtMakeResizeRequest( (Widget)bbw, - proposed_width, proposed_height, - &proposed_width, &proposed_height); - return(TRUE); + (void)XtMakeResizeRequest((Widget)bbw, + proposed_width, proposed_height, + &proposed_width, &proposed_height); + return (True); } else if (proposed_width != preferred_width) { /* recalc bounding box; height might change */ DoLayout(bbw, proposed_width, 0, - &preferred_width, &preferred_height, FALSE); + &preferred_width, &preferred_height, False); proposed_height = preferred_height; } - else { /* proposed_height != preferred_height */ + else { /* proposed_height != preferred_height */ XtWidgetGeometry constraints, reply; + constraints.request_mode = CWHeight; constraints.height = proposed_height; - (void)PreferredSize((Widget)bbw, &constraints, &reply); + (void)XawBoxQueryGeometry((Widget)bbw, &constraints, &reply); proposed_width = preferred_width; } + /*FALLTHROUGH*/ + default: + break; } iterations++; } while (iterations < 10); - return (FALSE); + + return (False); } /* - * * Geometry Manager * * 'reply' is unused; we say only yeay or nay, never almost. - * */ - /*ARGSUSED*/ -static XtGeometryResult GeometryManager(w, request, reply) - Widget w; - XtWidgetGeometry *request; - XtWidgetGeometry *reply; /* RETURN */ - +static XtGeometryResult +XawBoxGeometryManager(Widget w, XtWidgetGeometry *request, + XtWidgetGeometry *reply) { Dimension width, height, borderWidth; BoxWidget bbw; /* Position request always denied */ - if ((request->request_mode & CWX && request->x != w->core.x) || - (request->request_mode & CWY && request->y != w->core.y)) + if (((request->request_mode & CWX) && request->x != XtX(w)) + || ((request->request_mode & CWY) && request->y != XtY(w))) return (XtGeometryNo); /* Size changes must see if the new size can be accomodated */ if (request->request_mode & (CWWidth | CWHeight | CWBorderWidth)) { - /* Make all three fields in the request valid */ if ((request->request_mode & CWWidth) == 0) - request->width = w->core.width; + request->width = XtWidth(w); if ((request->request_mode & CWHeight) == 0) - request->height = w->core.height; + request->height = XtHeight(w); if ((request->request_mode & CWBorderWidth) == 0) - request->border_width = w->core.border_width; + request->border_width = XtBorderWidth(w); /* Save current size and set to new size */ - width = w->core.width; - height = w->core.height; - borderWidth = w->core.border_width; - w->core.width = request->width; - w->core.height = request->height; - w->core.border_width = request->border_width; - - /* Decide if new layout works: (1) new widget is smaller, - (2) new widget fits in existing Box, (3) Box can be - expanded to allow new widget to fit */ + width = XtWidth(w); + height = XtHeight(w); + borderWidth = XtBorderWidth(w); + XtWidth(w) = request->width; + XtHeight(w) = request->height; + XtBorderWidth(w) = request->border_width; + + /* Decide if new layout works: + (1) new widget is smaller, + (2) new widget fits in existing Box, + (3) Box can be expanded to allow new widget to fit + */ bbw = (BoxWidget) w->core.parent; -/* whenever a child changes his geometry, we attempt to - * change ours to be the minimum enclosing size... - if (((request->width + request->border_width <= width + borderWidth) && - (request->height + request->border_width <= height + borderWidth)) - || bbw->box.preferred_width < bbw->core.width - || bbw->box.preferred_height < bbw->core.height - || TryNewLayout(bbw)) { - */ if (TryNewLayout(bbw)) { /* Fits in existing or new space, relayout */ (*XtClass((Widget)bbw)->core_class.resize)((Widget)bbw); return (XtGeometryYes); - } else { + } + else { /* Cannot satisfy request, change back to original geometry */ - w->core.width = width; - w->core.height = height; - w->core.border_width = borderWidth; + XtWidth(w) = width; + XtHeight(w) = height; + XtBorderWidth(w) = borderWidth; return (XtGeometryNo); } - }; /* if any size changes requested */ + } /* Any stacking changes don't make a difference, so allow if that's all */ return (XtGeometryYes); } -static void ChangeManaged(w) - Widget w; +static void +XawBoxChangeManaged(Widget w) { /* Reconfigure the box */ - (void) TryNewLayout((BoxWidget)w); - Resize(w); + (void)TryNewLayout((BoxWidget)w); + XawBoxResize(w); } -static void ClassInitialize() +static void +XawBoxClassInitialize(void) { XawInitializeWidgetSet(); - XtAddConverter( XtRString, XtROrientation, XmuCvtStringToOrientation, - (XtConvertArgList)NULL, (Cardinal)0 ); + XtAddConverter(XtRString, XtROrientation, XmuCvtStringToOrientation, + NULL, 0); + XtSetTypeConverter(XtROrientation, XtRString, XmuCvtOrientationToString, + NULL, 0, XtCacheNone, NULL); } -/* ARGSUSED */ -static void Initialize(request, new, args, num_args) - Widget request, new; - ArgList args; - Cardinal *num_args; +/*ARGSUSED*/ +static void +XawBoxInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - BoxWidget newbbw = (BoxWidget)new; + BoxWidget newbbw = (BoxWidget)cnew; newbbw->box.last_query_mode = CWWidth | CWHeight; newbbw->box.last_query_width = newbbw->box.last_query_height = 0; newbbw->box.preferred_width = Max(newbbw->box.h_space, 1); newbbw->box.preferred_height = Max(newbbw->box.v_space, 1); - if (newbbw->core.width == 0) - newbbw->core.width = newbbw->box.preferred_width; + if (XtWidth(newbbw) == 0) + XtWidth(newbbw) = newbbw->box.preferred_width; - if (newbbw->core.height == 0) - newbbw->core.height = newbbw->box.preferred_height; + if (XtHeight(newbbw) == 0) + XtHeight(newbbw) = newbbw->box.preferred_height; +} -} /* Initialize */ +static void +XawBoxRealize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes) +{ +#ifndef OLDXAW + XawPixmap *pixmap; +#endif + + XtCreateWindow(w, InputOutput, (Visual *)CopyFromParent, + *valueMask, attributes); + +#ifndef OLDXAW + if (w->core.background_pixmap > XtUnspecifiedPixmap) { + pixmap = XawPixmapFromXPixmap(w->core.background_pixmap, XtScreen(w), + w->core.colormap, w->core.depth); + if (pixmap && pixmap->mask) + XawReshapeWidget(w, pixmap); + } +#endif +} -static void Realize(w, valueMask, attributes) - Widget w; - Mask *valueMask; - XSetWindowAttributes *attributes; +/*ARGSUSED*/ +static Boolean +XawBoxSetValues(Widget current, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - attributes->bit_gravity = NorthWestGravity; - *valueMask |= CWBitGravity; - - XtCreateWindow( w, (unsigned)InputOutput, (Visual *)CopyFromParent, - *valueMask, attributes); -} /* Realize */ - -/* ARGSUSED */ -static Boolean SetValues(current, request, new, args, num_args) - Widget current, request, new; - ArgList args; - Cardinal *num_args; + /* need to relayout if h_space or v_space change */ +#ifndef OLDXAW + BoxWidget b_old = (BoxWidget)current; + BoxWidget b_new = (BoxWidget)cnew; + + if (b_old->core.background_pixmap != b_new->core.background_pixmap) { + XawPixmap *opix, *npix; + + opix = XawPixmapFromXPixmap(b_old->core.background_pixmap, + XtScreen(b_old), b_old->core.colormap, + b_old->core.depth); + npix = XawPixmapFromXPixmap(b_new->core.background_pixmap, + XtScreen(b_new), b_new->core.colormap, + b_new->core.depth); + if ((npix && npix->mask) || (opix && opix->mask)) + XawReshapeWidget(cnew, npix); + } +#endif /* OLDXAW */ + + return (False); +} + +#ifndef OLDXAW +static void +XawBoxExpose(Widget w, XEvent *event, Region region) { - /* need to relayout if h_space or v_space change */ + BoxWidget xaw = (BoxWidget)w; - return False; + if (xaw->box.display_list) + XawRunDisplayList(w, xaw->box.display_list, event, region); } +#endif /* OLDXAW */ diff --git a/src/Command.c b/src/Command.c index 8e20493..1bb46c2 100644 --- a/src/Command.c +++ b/src/Command.c @@ -46,6 +46,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/Command.c,v 1.15 2002/07/04 17:04:20 paulo Exp $ */ /* * Command.c - Command button widget @@ -54,51 +55,101 @@ SOFTWARE. #include <stdio.h> #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> +#include <X11/extensions/shape.h> +#include <X11/Xmu/Converters.h> +#include <X11/Xmu/Drawing.h> #include <X11/Xmu/Misc.h> -#include <X11/Xaw/XawInit.h> #include <X11/Xaw/CommandP.h> -#include <X11/Xmu/Converters.h> -#include <X11/extensions/shape.h> +#include <X11/Xaw/XawInit.h> +#include "Private.h" #define DEFAULT_HIGHLIGHT_THICKNESS 2 #define DEFAULT_SHAPE_HIGHLIGHT 32767 +#define STR_EQUAL(str1, str2) (str1 == str2 || strcmp(str1, str2) == 0) -/**************************************************************** - * - * Full class record constant - * - ****************************************************************/ +/* + * Class Methods + */ +static void XawCommandClassInitialize(void); +static void XawCommandDestroy(Widget); +static void XawCommandInitialize(Widget, Widget, ArgList, Cardinal*); +static void XawCommandRealize(Widget, Mask*, XSetWindowAttributes*); +static void XawCommandResize(Widget); +static void XawCommandRedisplay(Widget, XEvent*, Region); +static Boolean XawCommandSetValues(Widget, Widget, Widget, ArgList, Cardinal*); +static void XawCommandGetValuesHook(Widget, ArgList, Cardinal*); +static Bool ChangeSensitive(Widget); + +/* + * Prototypes + */ +static GC Get_GC(CommandWidget, Pixel, Pixel); +static void PaintCommandWidget(Widget, XEvent*, Region, Bool); +static Region HighlightRegion(CommandWidget); +static Bool ShapeButton(CommandWidget, Bool); +static void XawCommandToggle(Widget); -/* Private Data */ +/* + * Actions + */ +static void Highlight(Widget, XEvent*, String*, Cardinal*); +static void Notify(Widget, XEvent*, String*, Cardinal*); +static void Reset(Widget, XEvent*, String*, Cardinal*); +static void Set(Widget, XEvent*, String*, Cardinal*); +static void Unhighlight(Widget, XEvent*, String*, Cardinal*); +static void Unset(Widget, XEvent*, String*, Cardinal*); +/* + * Initialization + */ static char defaultTranslations[] = - "<EnterWindow>: highlight() \n\ - <LeaveWindow>: reset() \n\ - <Btn1Down>: set() \n\ - <Btn1Up>: notify() unset() "; +"<Enter>:" "highlight()\n" +"<Leave>:" "reset()\n" +"<Btn1Down>:" "set()\n" +"<Btn1Up>:" "notify() unset()\n" +; #define offset(field) XtOffsetOf(CommandRec, field) static XtResource resources[] = { - {XtNcallback, XtCCallback, XtRCallback, sizeof(XtPointer), - offset(command.callbacks), XtRCallback, (XtPointer)NULL}, - {XtNhighlightThickness, XtCThickness, XtRDimension, sizeof(Dimension), - offset(command.highlight_thickness), XtRImmediate, - (XtPointer) DEFAULT_SHAPE_HIGHLIGHT}, - {XtNshapeStyle, XtCShapeStyle, XtRShapeStyle, sizeof(int), - offset(command.shape_style), XtRImmediate, (XtPointer)XawShapeRectangle}, - {XtNcornerRoundPercent, XtCCornerRoundPercent, - XtRDimension, sizeof(Dimension), - offset(command.corner_round), XtRImmediate, (XtPointer) 25} + { + XtNcallback, + XtCCallback, + XtRCallback, + sizeof(XtPointer), + offset(command.callbacks), + XtRCallback, + NULL + }, + { + XtNhighlightThickness, + XtCThickness, + XtRDimension, + sizeof(Dimension), + offset(command.highlight_thickness), + XtRImmediate, + (XtPointer)DEFAULT_SHAPE_HIGHLIGHT + }, + { + XtNshapeStyle, + XtCShapeStyle, + XtRShapeStyle, + sizeof(int), + offset(command.shape_style), + XtRImmediate, + (XtPointer)XawShapeRectangle + }, + { + XtNcornerRoundPercent, + XtCCornerRoundPercent, + XtRDimension, + sizeof(Dimension), + offset(command.corner_round), + XtRImmediate, + (XtPointer)25 + }, }; #undef offset -static Boolean SetValues(); -static void Initialize(), Redisplay(), Set(), Reset(), Notify(), Unset(); -static void Highlight(), Unhighlight(), Destroy(), PaintCommandWidget(); -static void ClassInitialize(); -static Boolean ShapeButton(); -static void Realize(), Resize(); - static XtActionsRec actionsList[] = { {"set", Set}, {"notify", Notify}, @@ -111,480 +162,496 @@ static XtActionsRec actionsList[] = { #define SuperClass ((LabelWidgetClass)&labelClassRec) CommandClassRec commandClassRec = { + /* core */ { - (WidgetClass) SuperClass, /* superclass */ + (WidgetClass)SuperClass, /* superclass */ "Command", /* class_name */ sizeof(CommandRec), /* size */ - ClassInitialize, /* class_initialize */ + XawCommandClassInitialize, /* class_initialize */ NULL, /* class_part_initialize */ - FALSE, /* class_inited */ - Initialize, /* initialize */ + False, /* class_inited */ + XawCommandInitialize, /* initialize */ NULL, /* initialize_hook */ - Realize, /* realize */ + XawCommandRealize, /* realize */ actionsList, /* actions */ XtNumber(actionsList), /* num_actions */ resources, /* resources */ - XtNumber(resources), /* resource_count */ + XtNumber(resources), /* num_resources */ NULLQUARK, /* xrm_class */ - FALSE, /* compress_motion */ - TRUE, /* compress_exposure */ - TRUE, /* compress_enterleave */ - FALSE, /* visible_interest */ - Destroy, /* destroy */ - Resize, /* resize */ - Redisplay, /* expose */ - SetValues, /* set_values */ + False, /* compress_motion */ + True, /* compress_exposure */ + True, /* compress_enterleave */ + False, /* visible_interest */ + XawCommandDestroy, /* destroy */ + XawCommandResize, /* resize */ + XawCommandRedisplay, /* expose */ + XawCommandSetValues, /* set_values */ NULL, /* set_values_hook */ XtInheritSetValuesAlmost, /* set_values_almost */ - NULL, /* get_values_hook */ + XawCommandGetValuesHook, /* get_values_hook */ NULL, /* accept_focus */ XtVersion, /* version */ NULL, /* callback_private */ defaultTranslations, /* tm_table */ XtInheritQueryGeometry, /* query_geometry */ XtInheritDisplayAccelerator, /* display_accelerator */ - NULL /* extension */ - }, /* CoreClass fields initialization */ + NULL, /* extension */ + }, + /* simple */ { - XtInheritChangeSensitive /* change_sensitive */ - }, /* SimpleClass fields initialization */ + ChangeSensitive, /* change_sensitive */ + }, + /* label */ { - 0, /* field not used */ - }, /* LabelClass fields initialization */ + 0, /* not used */ + }, + /* command */ { - 0, /* field not used */ - }, /* CommandClass fields initialization */ + 0, /* not used */ + }, }; - /* for public consumption */ -WidgetClass commandWidgetClass = (WidgetClass) &commandClassRec; - -/**************************************************************** - * - * Private Procedures - * - ****************************************************************/ +WidgetClass commandWidgetClass = (WidgetClass)&commandClassRec; +/* + * Implementation + */ static GC -Get_GC(cbw, fg, bg) -CommandWidget cbw; -Pixel fg, bg; +Get_GC(CommandWidget cbw, Pixel fg, Pixel bg) { - XGCValues values; + XGCValues values; - values.foreground = fg; - values.background = bg; - values.font = cbw->label.font->fid; - values.cap_style = CapProjecting; + values.foreground = fg; + values.background = bg; + values.font = cbw->label.font->fid; + values.cap_style = CapProjecting; - if (cbw->command.highlight_thickness > 1 ) - values.line_width = cbw->command.highlight_thickness; - else - values.line_width = 0; + if (cbw->command.highlight_thickness > 1) + values.line_width = cbw->command.highlight_thickness; + else + values.line_width = 0; - if ( cbw->simple.international == True ) - return XtAllocateGC((Widget)cbw, 0, - (GCForeground|GCBackground|GCLineWidth|GCCapStyle), - &values, GCFont, 0 ); - else - return XtGetGC((Widget)cbw, - (GCForeground|GCBackground|GCFont|GCLineWidth|GCCapStyle), - &values); + if (cbw->simple.international == True) + return (XtAllocateGC((Widget)cbw, 0, + GCForeground | GCBackground | GCLineWidth | + GCCapStyle, &values, GCFont, 0)); + else + return (XtGetGC((Widget)cbw, + GCForeground | GCBackground | GCFont | GCLineWidth | + GCCapStyle, &values)); } - -/* ARGSUSED */ +/*ARGSUSED*/ static void -Initialize(request, new, args, num_args) -Widget request, new; -ArgList args; /* unused */ -Cardinal *num_args; /* unused */ +XawCommandInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - CommandWidget cbw = (CommandWidget) new; - int shape_event_base, shape_error_base; - - if (cbw->command.shape_style != XawShapeRectangle - && !XShapeQueryExtension(XtDisplay(new), &shape_event_base, - &shape_error_base)) - cbw->command.shape_style = XawShapeRectangle; - if (cbw->command.highlight_thickness == DEFAULT_SHAPE_HIGHLIGHT) { - if (cbw->command.shape_style != XawShapeRectangle) - cbw->command.highlight_thickness = 0; - else - cbw->command.highlight_thickness = DEFAULT_HIGHLIGHT_THICKNESS; - } - - cbw->command.normal_GC = Get_GC(cbw, cbw->label.foreground, - cbw->core.background_pixel); - cbw->command.inverse_GC = Get_GC(cbw, cbw->core.background_pixel, - cbw->label.foreground); - XtReleaseGC(new, cbw->label.normal_GC); - cbw->label.normal_GC = cbw->command.normal_GC; - - cbw->command.set = FALSE; - cbw->command.highlighted = HighlightNone; + CommandWidget cbw = (CommandWidget)cnew; + int shape_event_base, shape_error_base; + + if (cbw->command.shape_style != XawShapeRectangle && + !XShapeQueryExtension(XtDisplay(cnew), &shape_event_base, + &shape_error_base)) + cbw->command.shape_style = XawShapeRectangle; + + if (cbw->command.highlight_thickness == DEFAULT_SHAPE_HIGHLIGHT) { + if (cbw->command.shape_style != XawShapeRectangle) + cbw->command.highlight_thickness = 0; + else + cbw->command.highlight_thickness = DEFAULT_HIGHLIGHT_THICKNESS; + } + + cbw->command.normal_GC = Get_GC(cbw, cbw->label.foreground, + cbw->core.background_pixel); + cbw->command.inverse_GC = Get_GC(cbw, cbw->core.background_pixel, + cbw->label.foreground); + XtReleaseGC(cnew, cbw->label.normal_GC); + cbw->label.normal_GC = cbw->command.normal_GC; + + cbw->command.set = False; + cbw->command.highlighted = HighlightNone; } static Region -HighlightRegion(cbw) -CommandWidget cbw; +HighlightRegion(CommandWidget cbw) { - static Region outerRegion = NULL, innerRegion, emptyRegion; - XRectangle rect; - - if (cbw->command.highlight_thickness == 0 || - cbw->command.highlight_thickness > - (Dimension) ((Dimension) Min(cbw->core.width, cbw->core.height)/2)) - return(NULL); - - if (outerRegion == NULL) { - /* save time by allocating scratch regions only once. */ - outerRegion = XCreateRegion(); - innerRegion = XCreateRegion(); - emptyRegion = XCreateRegion(); - } - - rect.x = rect.y = 0; - rect.width = cbw->core.width; - rect.height = cbw->core.height; - XUnionRectWithRegion( &rect, emptyRegion, outerRegion ); - rect.x = rect.y = cbw->command.highlight_thickness; - rect.width -= cbw->command.highlight_thickness * 2; - rect.height -= cbw->command.highlight_thickness * 2; - XUnionRectWithRegion( &rect, emptyRegion, innerRegion ); - XSubtractRegion( outerRegion, innerRegion, outerRegion ); - return outerRegion; + static Region outerRegion = NULL, innerRegion, emptyRegion; + XRectangle rect; + + if (cbw->command.highlight_thickness == 0 || + cbw->command.highlight_thickness > Min(XtWidth(cbw), XtHeight(cbw)) / 2) + return (NULL); + + if (outerRegion == NULL) { + /* save time by allocating scratch regions only once. */ + outerRegion = XCreateRegion(); + innerRegion = XCreateRegion(); + emptyRegion = XCreateRegion(); + } + + rect.x = rect.y = 0; + rect.width = XtWidth(cbw); + rect.height = XtHeight(cbw); + XUnionRectWithRegion(&rect, emptyRegion, outerRegion); + rect.x = rect.y = cbw->command.highlight_thickness; + rect.width -= cbw->command.highlight_thickness * 2; + rect.height -= cbw->command.highlight_thickness * 2; + XUnionRectWithRegion(&rect, emptyRegion, innerRegion); + XSubtractRegion(outerRegion, innerRegion, outerRegion); + + return (outerRegion); } /*************************** -* * Action Procedures -* ***************************/ +static void +XawCommandToggle(Widget w) +{ + CommandWidget xaw = (CommandWidget)w; + Arg args[2]; + Cardinal num_args; + + num_args = 0; + XtSetArg(args[num_args], XtNbackground, + xaw->label.foreground); ++num_args; + XtSetArg(args[num_args], XtNforeground, + xaw->core.background_pixel); ++num_args; + XtSetValues(w, args, num_args); +} -/* ARGSUSED */ +/*ARGSUSED*/ static void -Set(w,event,params,num_params) -Widget w; -XEvent *event; -String *params; /* unused */ -Cardinal *num_params; /* unused */ +Set(Widget w, XEvent *event, String *params, Cardinal *num_params) { - CommandWidget cbw = (CommandWidget)w; + CommandWidget cbw = (CommandWidget)w; - if (cbw->command.set) - return; + if (cbw->command.set) + return; - cbw->command.set= TRUE; - if (XtIsRealized(w)) - PaintCommandWidget(w, event, (Region) NULL, TRUE); + XawCommandToggle(w); + cbw->command.set= True; } -/* ARGSUSED */ +/*ARGSUSED*/ static void -Unset(w,event,params,num_params) -Widget w; -XEvent *event; -String *params; /* unused */ -Cardinal *num_params; +Unset(Widget w, XEvent *event, String *params, Cardinal *num_params) { - CommandWidget cbw = (CommandWidget)w; + CommandWidget cbw = (CommandWidget)w; - if (!cbw->command.set) - return; + if (!cbw->command.set) + return; - cbw->command.set = FALSE; - if (XtIsRealized(w)) { - XClearWindow(XtDisplay(w), XtWindow(w)); - PaintCommandWidget(w, event, (Region) NULL, TRUE); - } + cbw->command.set = False; + XawCommandToggle(w); } -/* ARGSUSED */ +/*ARGSUSED*/ static void -Reset(w,event,params,num_params) -Widget w; -XEvent *event; -String *params; /* unused */ -Cardinal *num_params; /* unused */ +Reset(Widget w, XEvent *event, String *params, Cardinal *num_params) { - CommandWidget cbw = (CommandWidget)w; + CommandWidget cbw = (CommandWidget)w; - if (cbw->command.set) { - cbw->command.highlighted = HighlightNone; - Unset(w, event, params, num_params); - } else - Unhighlight(w, event, params, num_params); + if (cbw->command.set) { + cbw->command.highlighted = HighlightNone; + Unset(w, event, params, num_params); + } + else + Unhighlight(w, event, params, num_params); } -/* ARGSUSED */ +/*ARGSUSED*/ static void -Highlight(w,event,params,num_params) -Widget w; -XEvent *event; -String *params; -Cardinal *num_params; +Highlight(Widget w, XEvent *event, String *params, Cardinal *num_params) { - CommandWidget cbw = (CommandWidget)w; - - if ( *num_params == (Cardinal) 0) - cbw->command.highlighted = HighlightWhenUnset; - else { - if ( *num_params != (Cardinal) 1) - XtWarning("Too many parameters passed to highlight action table."); - switch (params[0][0]) { - case 'A': - case 'a': - cbw->command.highlighted = HighlightAlways; - break; - default: - cbw->command.highlighted = HighlightWhenUnset; - break; + CommandWidget cbw = (CommandWidget)w; + + if (*num_params == (Cardinal)0) + cbw->command.highlighted = HighlightWhenUnset; + else { + if (*num_params != (Cardinal)1) + XtWarning("Too many parameters passed to highlight action table."); + switch (params[0][0]) { + case 'A': + case 'a': + cbw->command.highlighted = HighlightAlways; + break; + default: + cbw->command.highlighted = HighlightWhenUnset; + break; + } } - } - if (XtIsRealized(w)) - PaintCommandWidget(w, event, HighlightRegion(cbw), TRUE); + if (XtIsRealized(w)) + PaintCommandWidget(w, event, HighlightRegion(cbw), True); } -/* ARGSUSED */ +/*ARGSUSED*/ static void -Unhighlight(w,event,params,num_params) -Widget w; -XEvent *event; -String *params; /* unused */ -Cardinal *num_params; /* unused */ +Unhighlight(Widget w, XEvent *event, String *params, Cardinal *num_params) { - CommandWidget cbw = (CommandWidget)w; + CommandWidget cbw = (CommandWidget)w; - cbw->command.highlighted = HighlightNone; - if (XtIsRealized(w)) - PaintCommandWidget(w, event, HighlightRegion(cbw), TRUE); + cbw->command.highlighted = HighlightNone; + if (XtIsRealized(w)) + PaintCommandWidget(w, event, HighlightRegion(cbw), True); } -/* ARGSUSED */ +/*ARGSUSED*/ static void -Notify(w,event,params,num_params) -Widget w; -XEvent *event; -String *params; /* unused */ -Cardinal *num_params; /* unused */ +Notify(Widget w, XEvent *event, String *params, Cardinal *num_params) { - CommandWidget cbw = (CommandWidget)w; - - /* check to be sure state is still Set so that user can cancel - the action (e.g. by moving outside the window, in the default - bindings. - */ - if (cbw->command.set) - XtCallCallbackList(w, cbw->command.callbacks, (XtPointer) NULL); + CommandWidget cbw = (CommandWidget)w; + + /* check to be sure state is still Set so that user can cancel + the action (e.g. by moving outside the window, in the default + bindings. + */ + if (cbw->command.set) + XtCallCallbackList(w, cbw->command.callbacks, (XtPointer) NULL); } -/* - * Repaint the widget window - */ - -/************************ -* -* REDISPLAY (DRAW) -* -************************/ - -/* ARGSUSED */ -static void -Redisplay(w, event, region) -Widget w; -XEvent *event; -Region region; +static void +XawCommandRedisplay(Widget w, XEvent *event, Region region) { - PaintCommandWidget(w, event, region, FALSE); + PaintCommandWidget(w, event, region, False); } -/* Function Name: PaintCommandWidget - * Description: Paints the command widget. - * Arguments: w - the command widget. - * region - region to paint (passed to the superclass). +/* + * Function: + * PaintCommandWidget + * Parameters: + * w - command widget + * region - region to paint (passed to the superclass) * change - did it change either set or highlight state? - * Returns: none */ - static void -PaintCommandWidget(w, event, region, change) -Widget w; -XEvent *event; -Region region; -Boolean change; +PaintCommandWidget(Widget w, XEvent *event, Region region, Bool change) { - CommandWidget cbw = (CommandWidget) w; - Boolean very_thick; - GC norm_gc, rev_gc; + CommandWidget cbw = (CommandWidget)w; + Bool very_thick; + GC norm_gc, rev_gc; - very_thick = cbw->command.highlight_thickness > - (Dimension)((Dimension) Min(cbw->core.width, cbw->core.height)/2); - - if (cbw->command.set) { - cbw->label.normal_GC = cbw->command.inverse_GC; - XFillRectangle(XtDisplay(w), XtWindow(w), cbw->command.normal_GC, - 0, 0, cbw->core.width, cbw->core.height); - region = NULL; /* Force label to repaint text. */ - } - else - cbw->label.normal_GC = cbw->command.normal_GC; + very_thick = cbw->command.highlight_thickness + > Min(XtWidth(cbw), XtHeight(cbw)) / 2; - if (cbw->command.highlight_thickness <= 0) - { - (*SuperClass->core_class.expose) (w, event, region); - return; - } + if (cbw->command.highlight_thickness == 0) { + (*SuperClass->core_class.expose) (w, event, region); + return; + } -/* - * If we are set then use the same colors as if we are not highlighted. - */ + /* + * If we are set then use the same colors as if we are not highlighted + */ - if (cbw->command.set == (cbw->command.highlighted == HighlightNone)) { - norm_gc = cbw->command.inverse_GC; - rev_gc = cbw->command.normal_GC; - } - else { - norm_gc = cbw->command.normal_GC; - rev_gc = cbw->command.inverse_GC; - } - - if ( !( (!change && (cbw->command.highlighted == HighlightNone)) || - ((cbw->command.highlighted == HighlightWhenUnset) && - (cbw->command.set))) ) { - if (very_thick) { - cbw->label.normal_GC = norm_gc; /* Give the label the right GC. */ - XFillRectangle(XtDisplay(w),XtWindow(w), rev_gc, - 0, 0, cbw->core.width, cbw->core.height); + if (cbw->command.highlighted != HighlightNone) { + norm_gc = cbw->command.inverse_GC; + rev_gc = cbw->command.normal_GC; } else { - /* wide lines are centered on the path, so indent it */ - int offset = cbw->command.highlight_thickness/2; - XDrawRectangle(XtDisplay(w),XtWindow(w), rev_gc, offset, offset, - cbw->core.width - cbw->command.highlight_thickness, - cbw->core.height - cbw->command.highlight_thickness); + norm_gc = cbw->command.normal_GC; + rev_gc = cbw->command.inverse_GC; + } + + if (!((!change && cbw->command.highlighted == HighlightNone) + || (cbw->command.highlighted == HighlightWhenUnset + && cbw->command.set))) { + if (very_thick) + XFillRectangle(XtDisplay(w),XtWindow(w), rev_gc, + 0, 0, XtWidth(cbw), XtHeight(cbw)); + else { + /* wide lines are centered on the path, so indent it */ + if (cbw->core.background_pixmap != XtUnspecifiedPixmap && + rev_gc == cbw->command.inverse_GC) { + XClearArea(XtDisplay(w), XtWindow(w), + 0, 0, XtWidth(cbw), cbw->command.highlight_thickness, + False); + XClearArea(XtDisplay(w), XtWindow(w), + 0, cbw->command.highlight_thickness, + cbw->command.highlight_thickness, + XtHeight(cbw) - (cbw->command.highlight_thickness<<1), + False); + XClearArea(XtDisplay(w), XtWindow(w), + XtWidth(cbw) - cbw->command.highlight_thickness, + cbw->command.highlight_thickness, + cbw->command.highlight_thickness, + XtHeight(cbw) - (cbw->command.highlight_thickness<<1), + False); + XClearArea(XtDisplay(w), XtWindow(w), + 0, XtHeight(cbw) - cbw->command.highlight_thickness, + XtWidth(cbw), cbw->command.highlight_thickness, + False); + } + else { + int offset = cbw->command.highlight_thickness / 2; + + XDrawRectangle(XtDisplay(w),XtWindow(w), rev_gc, offset, offset, + XtWidth(cbw) - cbw->command.highlight_thickness, + XtHeight(cbw) - cbw->command.highlight_thickness); + } + } } - } - (*SuperClass->core_class.expose) (w, event, region); + + (*SuperClass->core_class.expose)(w, event, region); } static void -Destroy(w) -Widget w; +XawCommandDestroy(Widget w) { - CommandWidget cbw = (CommandWidget) w; + CommandWidget cbw = (CommandWidget)w; - /* so Label can release it */ - if (cbw->label.normal_GC == cbw->command.normal_GC) - XtReleaseGC( w, cbw->command.inverse_GC ); - else - XtReleaseGC( w, cbw->command.normal_GC ); + /* Label will release cbw->command.normal_GC */ + XtReleaseGC(w, cbw->command.inverse_GC); } -/* - * Set specified arguments into widget - */ - -/* ARGSUSED */ +/*ARGSUSED*/ static Boolean -SetValues (current, request, new, args, num_args) -Widget current, request, new; -ArgList args; -Cardinal *num_args; +XawCommandSetValues(Widget current, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - CommandWidget oldcbw = (CommandWidget) current; - CommandWidget cbw = (CommandWidget) new; - Boolean redisplay = False; + CommandWidget oldcbw = (CommandWidget)current; + CommandWidget cbw = (CommandWidget)cnew; + Boolean redisplay = False; - if ( oldcbw->core.sensitive != cbw->core.sensitive && !cbw->core.sensitive) { - /* about to become insensitive */ - cbw->command.set = FALSE; - cbw->command.highlighted = HighlightNone; - redisplay = TRUE; - } - - if ( (oldcbw->label.foreground != cbw->label.foreground) || - (oldcbw->core.background_pixel != cbw->core.background_pixel) || - (oldcbw->command.highlight_thickness != - cbw->command.highlight_thickness) || - (oldcbw->label.font != cbw->label.font) ) - { - if (oldcbw->label.normal_GC == oldcbw->command.normal_GC) - /* Label has release one of these */ - XtReleaseGC(new, cbw->command.inverse_GC); - else - XtReleaseGC(new, cbw->command.normal_GC); + if (oldcbw->core.sensitive != cbw->core.sensitive && !cbw->core.sensitive) { + cbw->command.highlighted = HighlightNone; + redisplay = True; + } - cbw->command.normal_GC = Get_GC(cbw, cbw->label.foreground, - cbw->core.background_pixel); - cbw->command.inverse_GC = Get_GC(cbw, cbw->core.background_pixel, - cbw->label.foreground); - XtReleaseGC(new, cbw->label.normal_GC); - cbw->label.normal_GC = (cbw->command.set - ? cbw->command.inverse_GC - : cbw->command.normal_GC); - - redisplay = True; - } - - if ( XtIsRealized(new) - && oldcbw->command.shape_style != cbw->command.shape_style - && !ShapeButton(cbw, TRUE)) - { - cbw->command.shape_style = oldcbw->command.shape_style; - } + if (cbw->command.set) { + unsigned int i; + Pixel foreground, background; + + foreground = oldcbw->label.foreground; + background = oldcbw->core.background_pixel; + for (i = 0; i < *num_args; i++) { + if (STR_EQUAL(args[i].name, XtNforeground)) + background = cbw->label.foreground; + else if (STR_EQUAL(args[i].name, XtNbackground)) + foreground = cbw->core.background_pixel; + } + cbw->label.foreground = foreground; + cbw->core.background_pixel = background; + } + + if (oldcbw->label.foreground != cbw->label.foreground + || oldcbw->core.background_pixel != cbw->core.background_pixel + || oldcbw->command.highlight_thickness + != cbw->command.highlight_thickness + || oldcbw->label.font != cbw->label.font) { + XtReleaseGC(cnew, cbw->command.inverse_GC); + + cbw->command.normal_GC = Get_GC(cbw, cbw->label.foreground, + cbw->core.background_pixel); + cbw->command.inverse_GC = Get_GC(cbw, cbw->core.background_pixel, + cbw->label.foreground); + XtReleaseGC(cnew, cbw->label.normal_GC); + cbw->label.normal_GC = cbw->command.normal_GC; + + redisplay = True; + } - return (redisplay); + if (XtIsRealized(cnew) + && oldcbw->command.shape_style != cbw->command.shape_style + && !ShapeButton(cbw, True)) + cbw->command.shape_style = oldcbw->command.shape_style; + + return (redisplay); } -static void ClassInitialize() +static void +XawCommandGetValuesHook(Widget w, ArgList args, Cardinal *num_args) { - XawInitializeWidgetSet(); - XtSetTypeConverter( XtRString, XtRShapeStyle, XmuCvtStringToShapeStyle, - (XtConvertArgList)NULL, 0, XtCacheNone, (XtDestructor)NULL ); + CommandWidget cbw = (CommandWidget)w; + unsigned int i; + + for (i = 0; i < *num_args; i++) { + if (STR_EQUAL(args[i].name, XtNforeground)) + *((String*)args[i].value) = cbw->command.set ? + (String)cbw->core.background_pixel : (String)cbw->label.foreground; + else if (STR_EQUAL(args[i].name, XtNbackground)) + *((String*)args[i].value) = cbw->command.set ? + (String)cbw->label.foreground : (String)cbw->core.background_pixel; + } } +static void +XawCommandClassInitialize(void) +{ + XawInitializeWidgetSet(); + XtSetTypeConverter(XtRString, XtRShapeStyle, XmuCvtStringToShapeStyle, + NULL, 0, XtCacheNone, NULL); + XtSetTypeConverter(XtRShapeStyle, XtRString, XmuCvtShapeStyleToString, + NULL, 0, XtCacheNone, NULL); +} -static Boolean -ShapeButton(cbw, checkRectangular) -CommandWidget cbw; -Boolean checkRectangular; +static Bool +ShapeButton(CommandWidget cbw, Bool checkRectangular) { - Dimension corner_size; + Dimension corner_size = 0; - if ( (cbw->command.shape_style == XawShapeRoundedRectangle) ) { - corner_size = (cbw->core.width < cbw->core.height) ? cbw->core.width - : cbw->core.height; - corner_size = (int) (corner_size * cbw->command.corner_round) / 100; + if (cbw->command.shape_style == XawShapeRoundedRectangle) { + corner_size = XtWidth(cbw) < XtHeight(cbw) ? + XtWidth(cbw) : XtHeight(cbw); + corner_size = (corner_size * cbw->command.corner_round) / 100; } if (checkRectangular || cbw->command.shape_style != XawShapeRectangle) { - if (!XmuReshapeWidget((Widget) cbw, cbw->command.shape_style, + if (!XmuReshapeWidget((Widget)cbw, cbw->command.shape_style, corner_size, corner_size)) { cbw->command.shape_style = XawShapeRectangle; - return(False); + return (False); } } - return(TRUE); + + return (True); } -static void Realize(w, valueMask, attributes) - Widget w; - Mask *valueMask; - XSetWindowAttributes *attributes; +static void +XawCommandRealize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes) { (*commandWidgetClass->core_class.superclass->core_class.realize) (w, valueMask, attributes); - ShapeButton( (CommandWidget) w, FALSE); + ShapeButton((CommandWidget)w, False); } -static void Resize(w) - Widget w; +static void +XawCommandResize(Widget w) { if (XtIsRealized(w)) - ShapeButton( (CommandWidget) w, FALSE); + ShapeButton((CommandWidget)w, False); (*commandWidgetClass->core_class.superclass->core_class.resize)(w); } + +static Bool +ChangeSensitive(Widget w) +{ + CommandWidget cbw = (CommandWidget)w; + + if (XtIsRealized(w)) { + if (XtIsSensitive(w)) { + if (w->core.border_pixmap != XtUnspecifiedPixmap) + XSetWindowBorderPixmap(XtDisplay(w), XtWindow(w), + w->core.border_pixmap); + else + XSetWindowBorder(XtDisplay(w), XtWindow(w), + w->core.border_pixel); + } + else { + if (cbw->simple.insensitive_border == None) + cbw->simple.insensitive_border = + XmuCreateStippledPixmap(XtScreen(w), + w->core.border_pixel, + cbw->command.set ? + cbw->label.foreground : + w->core.background_pixel, + w->core.depth); + XSetWindowBorderPixmap(XtDisplay(w), XtWindow(w), + cbw->simple.insensitive_border); + } + } + + return (False); +} diff --git a/src/Dialog.c b/src/Dialog.c index fe77938..e2e8315 100644 --- a/src/Dialog.c +++ b/src/Dialog.c @@ -46,177 +46,214 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ - -/* NOTE: THIS IS NOT A WIDGET! Rather, this is an interface to a widget. - It implements policy, and gives a (hopefully) easier-to-use interface - than just directly making your own form. */ - +/* $XFree86: xc/lib/Xaw/Dialog.c,v 1.8 2001/12/14 19:54:39 dawes Exp $ */ #include <X11/IntrinsicP.h> -#include <X11/Xos.h> #include <X11/StringDefs.h> +#include <X11/Xos.h> #include <X11/Xmu/Misc.h> - -#include <X11/Xaw/XawInit.h> #include <X11/Xaw/AsciiText.h> +#include <X11/Xaw/Cardinals.h> #include <X11/Xaw/Command.h> #include <X11/Xaw/Label.h> #include <X11/Xaw/DialogP.h> -#include <X11/Xaw/Cardinals.h> +#include <X11/Xaw/XawInit.h> +#include "Private.h" /* * After we have set the string in the value widget we set the * string to a magic value. So that when a SetValues request is made - * on the dialog value we will notice it, and reset the string. + * on the dialog value we will notice it, and reset the string */ +#define MAGIC_VALUE ((char *)3) -#define MAGIC_VALUE ((char *) 3) +#define streq(a,b) (strcmp((a), (b)) == 0) -#define streq(a,b) (strcmp( (a), (b) ) == 0) +/* + * Class Methods + */ +static void XawDialogConstraintInitialize(Widget, Widget, + ArgList, Cardinal*); +static void XawDialogGetValuesHook(Widget, ArgList, Cardinal*); +static void XawDialogInitialize(Widget, Widget, ArgList, Cardinal*); +static Boolean XawDialogSetValues(Widget, Widget, Widget, + ArgList, Cardinal*); +/* + * Prototypes + */ +static void CreateDialogValueWidget(Widget); + +/* + * Initialization + */ static XtResource resources[] = { - {XtNlabel, XtCLabel, XtRString, sizeof(String), - XtOffsetOf(DialogRec, dialog.label), XtRString, NULL}, - {XtNvalue, XtCValue, XtRString, sizeof(String), - XtOffsetOf(DialogRec, dialog.value), XtRString, NULL}, - {XtNicon, XtCIcon, XtRBitmap, sizeof(Pixmap), - XtOffsetOf(DialogRec, dialog.icon), XtRImmediate, 0}, + { + XtNlabel, + XtCLabel, + XtRString, + sizeof(String), + XtOffsetOf(DialogRec, dialog.label), + XtRString, + NULL + }, + { + XtNvalue, + XtCValue, + XtRString, + sizeof(String), + XtOffsetOf(DialogRec, dialog.value), + XtRString, + NULL + }, + { + XtNicon, + XtCIcon, + XtRBitmap, + sizeof(Pixmap), + XtOffsetOf(DialogRec, dialog.icon), + XtRImmediate, + 0 + }, }; -static void Initialize(), ConstraintInitialize(), CreateDialogValueWidget(), - GetValuesHook(); - -static Boolean SetValues(); - DialogClassRec dialogClassRec = { - { /* core_class fields */ - /* superclass */ (WidgetClass) &formClassRec, - /* class_name */ "Dialog", - /* widget_size */ sizeof(DialogRec), - /* class_initialize */ XawInitializeWidgetSet, - /* class_part init */ NULL, - /* class_inited */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* realize */ XtInheritRealize, - /* actions */ NULL, - /* num_actions */ 0, - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure */ TRUE, - /* compress_enterleave*/ TRUE, - /* visible_interest */ FALSE, - /* destroy */ NULL, - /* resize */ XtInheritResize, - /* expose */ XtInheritExpose, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* set_values_almost */ XtInheritSetValuesAlmost, - /* get_values_hook */ GetValuesHook, - /* accept_focus */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ NULL, - /* query_geometry */ XtInheritQueryGeometry, - /* display_accelerator*/ XtInheritDisplayAccelerator, - /* extension */ NULL + /* core */ + { + (WidgetClass)&formClassRec, /* superclass */ + "Dialog", /* class_name */ + sizeof(DialogRec), /* widget_size */ + XawInitializeWidgetSet, /* class_initialize */ + NULL, /* class_part init */ + False, /* class_inited */ + XawDialogInitialize, /* initialize */ + NULL, /* initialize_hook */ + XtInheritRealize, /* realize */ + NULL, /* actions */ + 0, /* num_actions */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + True, /* compress_motion */ + True, /* compress_exposure */ + True, /* compress_enterleave */ + False, /* visible_interest */ + NULL, /* destroy */ + XtInheritResize, /* resize */ + XtInheritExpose, /* expose */ + XawDialogSetValues, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + XawDialogGetValuesHook, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + NULL, /* tm_table */ + XtInheritQueryGeometry, /* query_geometry */ + XtInheritDisplayAccelerator, /* display_accelerator */ + NULL, /* extension */ }, - { /* composite_class fields */ - /* geometry_manager */ XtInheritGeometryManager, - /* change_managed */ XtInheritChangeManaged, - /* insert_child */ XtInheritInsertChild, - /* delete_child */ XtInheritDeleteChild, - /* extension */ NULL + /* composite */ + { + XtInheritGeometryManager, /* geometry_manager */ + XtInheritChangeManaged, /* change_managed */ + XtInheritInsertChild, /* insert_child */ + XtInheritDeleteChild, /* delete_child */ + NULL, /* extension */ }, - { /* constraint_class fields */ - /* subresourses */ NULL, - /* subresource_count */ 0, - /* constraint_size */ sizeof(DialogConstraintsRec), - /* initialize */ ConstraintInitialize, - /* destroy */ NULL, - /* set_values */ NULL, - /* extension */ NULL + /* constraint */ + { + NULL, /* subresourses */ + 0, /* subresource_count */ + sizeof(DialogConstraintsRec), /* constraint_size */ + XawDialogConstraintInitialize, /* initialize */ + NULL, /* destroy */ + NULL, /* set_values */ + NULL, /* extension */ }, - { /* form_class fields */ - /* layout */ XtInheritLayout + /* form */ + { + XtInheritLayout, /* layout */ }, - { /* dialog_class fields */ - /* empty */ 0 + /* dialog */ + { + NULL, /* extension */ } }; WidgetClass dialogWidgetClass = (WidgetClass)&dialogClassRec; -/* ARGSUSED */ -static void Initialize(request, new, args, num_args) -Widget request, new; -ArgList args; -Cardinal *num_args; +/* + * Implementation + */ +/*ARGSUSED*/ +static void +XawDialogInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - DialogWidget dw = (DialogWidget)new; + DialogWidget dw = (DialogWidget)cnew; Arg arglist[9]; Cardinal arg_cnt = 0; - XtSetArg(arglist[arg_cnt], XtNborderWidth, 0); arg_cnt++; - XtSetArg(arglist[arg_cnt], XtNleft, XtChainLeft); arg_cnt++; + XtSetArg(arglist[arg_cnt], XtNborderWidth, 0); arg_cnt++; + XtSetArg(arglist[arg_cnt], XtNleft, XtChainLeft); arg_cnt++; if (dw->dialog.icon != (Pixmap)0) { - XtSetArg(arglist[arg_cnt], XtNbitmap, dw->dialog.icon); arg_cnt++; - XtSetArg(arglist[arg_cnt], XtNright, XtChainLeft); arg_cnt++; - dw->dialog.iconW = - XtCreateManagedWidget( "icon", labelWidgetClass, - new, arglist, arg_cnt ); + XtSetArg(arglist[arg_cnt], XtNbitmap, dw->dialog.icon); arg_cnt++; + XtSetArg(arglist[arg_cnt], XtNright, XtChainLeft); arg_cnt++; + dw->dialog.iconW = XtCreateManagedWidget("icon", labelWidgetClass, + cnew, arglist, arg_cnt); arg_cnt = 2; - XtSetArg(arglist[arg_cnt], XtNfromHoriz, dw->dialog.iconW);arg_cnt++; - } else dw->dialog.iconW = (Widget)NULL; + XtSetArg(arglist[arg_cnt], XtNfromHoriz, dw->dialog.iconW); arg_cnt++; + } + else + dw->dialog.iconW = NULL; - XtSetArg(arglist[arg_cnt], XtNlabel, dw->dialog.label); arg_cnt++; - XtSetArg(arglist[arg_cnt], XtNright, XtChainRight); arg_cnt++; + XtSetArg(arglist[arg_cnt], XtNlabel, dw->dialog.label); arg_cnt++; + XtSetArg(arglist[arg_cnt], XtNright, XtChainRight); arg_cnt++; - dw->dialog.labelW = XtCreateManagedWidget( "label", labelWidgetClass, - new, arglist, arg_cnt); + dw->dialog.labelW = XtCreateManagedWidget("label", labelWidgetClass, + cnew, arglist, arg_cnt); - if (dw->dialog.iconW != (Widget)NULL && - (dw->dialog.labelW->core.height < dw->dialog.iconW->core.height)) { - XtSetArg( arglist[0], XtNheight, dw->dialog.iconW->core.height ); - XtSetValues( dw->dialog.labelW, arglist, ONE ); + if (dw->dialog.iconW != NULL && + XtHeight(dw->dialog.labelW) < XtHeight(dw->dialog.iconW)) { + XtSetArg(arglist[0], XtNheight, XtHeight(dw->dialog.iconW)); + XtSetValues(dw->dialog.labelW, arglist, 1); } if (dw->dialog.value != NULL) - CreateDialogValueWidget( (Widget) dw); + CreateDialogValueWidget((Widget)dw); else dw->dialog.valueW = NULL; } -/* ARGSUSED */ -static void ConstraintInitialize(request, new, args, num_args) -Widget request, new; -ArgList args; -Cardinal *num_args; +/*ARGSUSED*/ +static void +XawDialogConstraintInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - DialogWidget dw = (DialogWidget)new->core.parent; - DialogConstraints constraint = (DialogConstraints)new->core.constraints; + DialogWidget dw = (DialogWidget)cnew->core.parent; + DialogConstraints constraint = (DialogConstraints)cnew->core.constraints; - if (!XtIsSubclass(new, commandWidgetClass)) /* if not a button */ - return; /* then just use defaults */ + if (!XtIsSubclass(cnew, commandWidgetClass)) /* if not a button */ + return; /* then just use defaults */ constraint->form.left = constraint->form.right = XtChainLeft; if (dw->dialog.valueW == NULL) - constraint->form.vert_base = dw->dialog.labelW; + constraint->form.vert_base = dw->dialog.labelW; else - constraint->form.vert_base = dw->dialog.valueW; + constraint->form.vert_base = dw->dialog.valueW; if (dw->composite.num_children > 1) { WidgetList children = dw->composite.children; Widget *childP; + for (childP = children + dw->composite.num_children - 1; - childP >= children; childP-- ) { + childP >= children; childP-- ) { if (*childP == dw->dialog.labelW || *childP == dw->dialog.valueW) - break; + break; if (XtIsManaged(*childP) && - XtIsSubclass(*childP, commandWidgetClass)) { - constraint->form.horiz_base = *childP; + XtIsSubclass(*childP, commandWidgetClass)) { + constraint->form.horiz_base = *childP; break; } } @@ -226,222 +263,198 @@ Cardinal *num_args; #define ICON 0 #define LABEL 1 #define NUM_CHECKS 2 - -/* ARGSUSED */ -static Boolean SetValues(current, request, new, in_args, in_num_args) -Widget current, request, new; -ArgList in_args; -Cardinal *in_num_args; +/*ARGSUSED*/ +static Boolean +XawDialogSetValues(Widget current, Widget request, Widget cnew, + ArgList in_args, Cardinal *in_num_args) { - DialogWidget w = (DialogWidget)new; + DialogWidget w = (DialogWidget)cnew; DialogWidget old = (DialogWidget)current; Arg args[5]; Cardinal num_args; - int i; - Boolean checks[NUM_CHECKS]; + unsigned int i; + Bool checks[NUM_CHECKS]; for (i = 0; i < NUM_CHECKS; i++) - checks[i] = FALSE; + checks[i] = False; for (i = 0; i < *in_num_args; i++) { if (streq(XtNicon, in_args[i].name)) - checks[ICON] = TRUE; - if (streq(XtNlabel, in_args[i].name)) - checks[LABEL] = TRUE; + checks[ICON] = True; + else if (streq(XtNlabel, in_args[i].name)) + checks[LABEL] = True; } if (checks[ICON]) { - if (w->dialog.icon != (Pixmap)0) { - XtSetArg( args[0], XtNbitmap, w->dialog.icon ); - if (old->dialog.iconW != (Widget)NULL) { - XtSetValues( old->dialog.iconW, args, ONE ); - } else { - XtSetArg( args[1], XtNborderWidth, 0); - XtSetArg( args[2], XtNleft, XtChainLeft); - XtSetArg( args[3], XtNright, XtChainLeft); - w->dialog.iconW = - XtCreateWidget( "icon", labelWidgetClass, - new, args, FOUR ); + if (w->dialog.icon != 0) { + XtSetArg(args[0], XtNbitmap, w->dialog.icon); + if (old->dialog.iconW != NULL) + XtSetValues(old->dialog.iconW, args, 1); + else { + XtSetArg(args[1], XtNborderWidth, 0); + XtSetArg(args[2], XtNleft, XtChainLeft); + XtSetArg(args[3], XtNright, XtChainLeft); + w->dialog.iconW = XtCreateWidget("icon", labelWidgetClass, + cnew, args, 4); ((DialogConstraints)w->dialog.labelW->core.constraints)-> form.horiz_base = w->dialog.iconW; XtManageChild(w->dialog.iconW); } - } else if (old->dialog.icon != (Pixmap)0) { + } + else if (old->dialog.icon != 0) { ((DialogConstraints)w->dialog.labelW->core.constraints)-> - form.horiz_base = (Widget)NULL; + form.horiz_base = NULL; XtDestroyWidget(old->dialog.iconW); - w->dialog.iconW = (Widget)NULL; + w->dialog.iconW = NULL; } } - if ( checks[LABEL] ) { - num_args = 0; - XtSetArg( args[num_args], XtNlabel, w->dialog.label ); num_args++; - if (w->dialog.iconW != (Widget)NULL && - (w->dialog.labelW->core.height <= w->dialog.iconW->core.height)) { - XtSetArg(args[num_args], XtNheight, w->dialog.iconW->core.height); + if (checks[LABEL]) { + num_args = 0; + XtSetArg(args[num_args], XtNlabel, w->dialog.label); num_args++; + if (w->dialog.iconW != NULL && + XtHeight(w->dialog.labelW) <= XtHeight(w->dialog.iconW)) { + XtSetArg(args[num_args], XtNheight, XtHeight(w->dialog.iconW)); num_args++; } - XtSetValues( w->dialog.labelW, args, num_args ); + XtSetValues(w->dialog.labelW, args, num_args); } - if ( w->dialog.value != old->dialog.value ) { - if (w->dialog.value == NULL) /* only get here if it - wasn't NULL before. */ + if (w->dialog.value != old->dialog.value) { + if (w->dialog.value == NULL) /* only get here if it + wasn't NULL before */ XtDestroyWidget(old->dialog.valueW); - else if (old->dialog.value == NULL) { /* create a new value widget. */ - w->core.width = old->core.width; - w->core.height = old->core.height; -#ifdef notdef -/* this would be correct if Form had the same semantics on Resize - * as on MakeGeometryRequest. Unfortunately, Form botched it, so - * any subclasses will currently have to deal with the fact that - * we're about to change our real size. - */ - w->form.resize_in_layout = False; - CreateDialogValueWidget( (Widget) w); - w->core.width = w->form.preferred_width; - w->core.height = w->form.preferred_height; - w->form.resize_in_layout = True; -#else /*notdef*/ - CreateDialogValueWidget( (Widget) w); -#endif /*notdef*/ + else if (old->dialog.value == NULL) { /* create a new value widget */ + XtWidth(w) = XtWidth(old); + XtHeight(w) = XtHeight(old); + CreateDialogValueWidget(cnew); } - else { /* Widget ok, just change string. */ - Arg args[1]; - XtSetArg(args[0], XtNstring, w->dialog.value); - XtSetValues(w->dialog.valueW, args, ONE); + else { /* Widget ok, just change string */ + Arg nargs[1]; + + XtSetArg(nargs[0], XtNstring, w->dialog.value); + XtSetValues(w->dialog.valueW, nargs, 1); w->dialog.value = MAGIC_VALUE; } } - return False; + + return (False); } -/* Function Name: GetValuesHook - * Description: This is a get values hook routine that gets the - * values in the dialog. - * Arguments: w - the Text Widget. - * args - the argument list. - * num_args - the number of args. - * Returns: none. +/* + * Function: + * XawDialogGetValuesHook + * + * Parameters: + * w - Dialog Widget + * args - argument list + * num_args - number of args + * + * Description: + * This is a get values hook routine that gets the values in the dialog. */ - static void -GetValuesHook(w, args, num_args) -Widget w; -ArgList args; -Cardinal * num_args; +XawDialogGetValuesHook(Widget w, ArgList args, Cardinal *num_args) { - Arg a[1]; - String s; - DialogWidget src = (DialogWidget) w; - int i; + Arg a[1]; + String s; + DialogWidget src = (DialogWidget)w; + unsigned int i; - for (i=0; i < *num_args; i++) - if (streq(args[i].name, XtNvalue)) { - XtSetArg(a[0], XtNstring, &s); - XtGetValues(src->dialog.valueW, a, 1); - *((char **) args[i].value) = s; - } + for (i = 0; i < *num_args; i++) + if (streq(args[i].name, XtNvalue)) { + XtSetArg(a[0], XtNstring, &s); + XtGetValues(src->dialog.valueW, a, 1); + *((char **)args[i].value) = s; + } + else if (streq(args[i].name, XtNlabel)) { + XtSetArg(a[0], XtNlabel, &s); + XtGetValues(src->dialog.labelW, a, 1); + *((char **)args[i].value) = s; + } } - -/* Function Name: CreateDialogValueWidget - * Description: Creates the dialog widgets value widget. - * Arguments: w - the dialog widget. - * Returns: none. +/* + * Function: + * CreateDialogValueWidget * - * must be called only when w->dialog.value is non-nil. + * Parameters: + * w - dialog widget + * + * Description: + * Creates the dialog widgets value widget. + * + * Note + * Must be called only when w->dialog.value is non-nil */ - static void -CreateDialogValueWidget(w) -Widget w; +CreateDialogValueWidget(Widget w) { - DialogWidget dw = (DialogWidget) w; + DialogWidget dw = (DialogWidget)w; Arg arglist[10]; Cardinal num_args = 0; -#ifdef notdef - XtSetArg(arglist[num_args], XtNwidth, - dw->dialog.labelW->core.width); num_args++; /* ||| hack */ -#endif /*notdef*/ XtSetArg(arglist[num_args], XtNstring, dw->dialog.value); num_args++; XtSetArg(arglist[num_args], XtNresizable, True); num_args++; - XtSetArg(arglist[num_args], XtNresize, XawtextResizeBoth); num_args++; XtSetArg(arglist[num_args], XtNeditType, XawtextEdit); num_args++; XtSetArg(arglist[num_args], XtNfromVert, dw->dialog.labelW); num_args++; XtSetArg(arglist[num_args], XtNleft, XtChainLeft); num_args++; XtSetArg(arglist[num_args], XtNright, XtChainRight); num_args++; dw->dialog.valueW = XtCreateWidget("value", asciiTextWidgetClass, - w, arglist, num_args); + w, arglist, num_args); /* if the value widget is being added after buttons, - * then the buttons need new layout constraints. + * then the buttons need new layout constraints */ if (dw->composite.num_children > 1) { WidgetList children = dw->composite.children; Widget *childP; + for (childP = children + dw->composite.num_children - 1; childP >= children; childP-- ) { if (*childP == dw->dialog.labelW || *childP == dw->dialog.valueW) continue; + if (XtIsManaged(*childP) && - XtIsSubclass(*childP, commandWidgetClass)) { - ((DialogConstraints)(*childP)->core.constraints)-> + XtIsSubclass(*childP, commandWidgetClass)) { + ((DialogConstraints)(*childP)->core.constraints)-> form.vert_base = dw->dialog.valueW; } } } XtManageChild(dw->dialog.valueW); -/* - * Value widget gets the keyboard focus. - */ - + /* + * Value widget gets the keyboard focus + */ XtSetKeyboardFocus(w, dw->dialog.valueW); dw->dialog.value = MAGIC_VALUE; } - void -#if NeedFunctionPrototypes XawDialogAddButton(Widget dialog, _Xconst char* name, XtCallbackProc function, XtPointer param) -#else -XawDialogAddButton(dialog, name, function, param) -Widget dialog; -String name; -XtCallbackProc function; -XtPointer param; -#endif { -/* - * Correct Constraints are all set in ConstraintInitialize(). - */ + /* + * Correct Constraints are all set in ConstraintInitialize() + */ Widget button; - button = XtCreateManagedWidget( name, commandWidgetClass, dialog, - (ArgList)NULL, (Cardinal)0 ); + button = XtCreateManagedWidget(name, commandWidgetClass, dialog, NULL, 0); - if (function != NULL) /* don't add NULL callback func. */ - XtAddCallback(button, XtNcallback, function, param); + if (function != NULL) /* don't add NULL callback func */ + XtAddCallback(button, XtNcallback, function, param); } - char * -#if NeedFunctionPrototypes XawDialogGetValueString(Widget w) -#else -XawDialogGetValueString(w) -Widget w; -#endif { Arg args[1]; - char * value; + char *value; XtSetArg(args[0], XtNstring, &value); - XtGetValues( ((DialogWidget)w)->dialog.valueW, args, ONE); + XtGetValues(((DialogWidget)w)->dialog.valueW, args, 1); + return(value); } @@ -47,234 +47,449 @@ SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/Form.c,v 1.21 2001/12/14 19:54:39 dawes Exp $ */ + #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> -#include <X11/Xmu/Converters.h> #include <X11/Xmu/CharSet.h> -#include <X11/Xaw/XawInit.h> +#include <X11/Xmu/Converters.h> #include <X11/Xaw/FormP.h> +#include <X11/Xaw/XawInit.h> +#include "Private.h" -/* Private Definitions */ +/* + * Class Methods + */ +static void XawFormChangeManaged(Widget); +static void XawFormClassInitialize(void); +static void XawFormClassPartInitialize(WidgetClass); +static void XawFormConstraintInitialize(Widget, Widget, ArgList, Cardinal*); +static Boolean XawFormConstraintSetValues(Widget, Widget, Widget, + ArgList, Cardinal*); +static XtGeometryResult XawFormGeometryManager(Widget, XtWidgetGeometry*, + XtWidgetGeometry*); +static void XawFormInitialize(Widget, Widget, ArgList, Cardinal*); +#ifndef OLDXAW +static void XawFormRealize(Widget, Mask*, XSetWindowAttributes*); +static void XawFormRedisplay(Widget, XEvent*, Region); +#endif +static XtGeometryResult XawFormQueryGeometry(Widget, XtWidgetGeometry*, + XtWidgetGeometry*); +static void XawFormResize(Widget); +static Boolean XawFormSetValues(Widget, Widget, Widget, ArgList, Cardinal*); +static Boolean Layout(FormWidget, unsigned int, unsigned int, Bool); -static int default_value = -99999; +/* + * Prototypes + */ +static void _CvtStringToEdgeType(XrmValuePtr, Cardinal*, + XrmValuePtr, XrmValuePtr); +static Bool ChangeFormGeometry(Widget, Bool, unsigned int, unsigned int, + Dimension*, Dimension*); +Boolean CvtEdgeTypeToString(Display*, XrmValuePtr, Cardinal*, + XrmValuePtr, XrmValuePtr, XtPointer*); +static void LayoutChild(Widget); +static int TransformCoord(int, unsigned int, unsigned int, XtEdgeType); +static void ResizeChildren(Widget); +/* + * Initialization + */ +#ifndef OLDXAW +static XtActionsRec actions[] = { + {"set-values", XawSetValuesAction}, + {"get-values", XawGetValuesAction}, + {"declare", XawDeclareAction}, + {"call-proc", XawCallProcAction}, +}; +#endif + +static XrmQuark QchainLeft, QchainRight, QchainTop, QchainBottom, Qrubber; + +#define default_value -99999 #define Offset(field) XtOffsetOf(FormRec, form.field) static XtResource resources[] = { - {XtNdefaultDistance, XtCThickness, XtRInt, sizeof(int), - Offset(default_spacing), XtRImmediate, (XtPointer)4} + { + XtNdefaultDistance, + XtCThickness, + XtRInt, + sizeof(int), + Offset(default_spacing), + XtRImmediate, + (XtPointer)4 + }, +#ifndef OLDXAW + { + XawNdisplayList, + XawCDisplayList, + XawRDisplayList, + sizeof(XawDisplayList*), + Offset(display_list), + XtRImmediate, + NULL + }, +#endif }; #undef Offset -static XtEdgeType defEdge = XtRubber; +#define defEdge XtRubber #define Offset(field) XtOffsetOf(FormConstraintsRec, form.field) static XtResource formConstraintResources[] = { - {XtNtop, XtCEdge, XtREdgeType, sizeof(XtEdgeType), - Offset(top), XtREdgeType, (XtPointer)&defEdge}, - {XtNbottom, XtCEdge, XtREdgeType, sizeof(XtEdgeType), - Offset(bottom), XtREdgeType, (XtPointer)&defEdge}, - {XtNleft, XtCEdge, XtREdgeType, sizeof(XtEdgeType), - Offset(left), XtREdgeType, (XtPointer)&defEdge}, - {XtNright, XtCEdge, XtREdgeType, sizeof(XtEdgeType), - Offset(right), XtREdgeType, (XtPointer)&defEdge}, - {XtNhorizDistance, XtCThickness, XtRInt, sizeof(int), - Offset(dx), XtRInt, (XtPointer) &default_value}, - {XtNfromHoriz, XtCWidget, XtRWidget, sizeof(Widget), - Offset(horiz_base), XtRWidget, (XtPointer)NULL}, - {XtNvertDistance, XtCThickness, XtRInt, sizeof(int), - Offset(dy), XtRInt, (XtPointer) &default_value}, - {XtNfromVert, XtCWidget, XtRWidget, sizeof(Widget), - Offset(vert_base), XtRWidget, (XtPointer)NULL}, - {XtNresizable, XtCBoolean, XtRBoolean, sizeof(Boolean), - Offset(allow_resize), XtRImmediate, (XtPointer) FALSE}, + { + XtNtop, + XtCEdge, + XtREdgeType, + sizeof(XtEdgeType), + Offset(top), + XtRImmediate, + (XtPointer)defEdge + }, + { + XtNbottom, + XtCEdge, + XtREdgeType, + sizeof(XtEdgeType), + Offset(bottom), + XtRImmediate, + (XtPointer)defEdge + }, + { + XtNleft, + XtCEdge, + XtREdgeType, + sizeof(XtEdgeType), + Offset(left), + XtRImmediate, + (XtPointer)defEdge + }, + { + XtNright, + XtCEdge, + XtREdgeType, + sizeof(XtEdgeType), + Offset(right), + XtRImmediate, + (XtPointer)defEdge + }, + { + XtNhorizDistance, + XtCThickness, + XtRInt, + sizeof(int), + Offset(dx), + XtRImmediate, + (XtPointer)default_value + }, + { + XtNfromHoriz, + XtCWidget, + XtRWidget, + sizeof(Widget), + Offset(horiz_base), + XtRWidget, + NULL + }, + { + XtNvertDistance, + XtCThickness, + XtRInt, + sizeof(int), + Offset(dy), + XtRImmediate, + (XtPointer)default_value + }, + { + XtNfromVert, + XtCWidget, + XtRWidget, + sizeof(Widget), + Offset(vert_base), + XtRWidget, + NULL + }, + { + XtNresizable, + XtCBoolean, + XtRBoolean, + sizeof(Boolean), + Offset(allow_resize), + XtRImmediate, + (XtPointer)False + }, }; #undef Offset -static void ClassInitialize(), ClassPartInitialize(), Initialize(), Resize(); -static void ConstraintInitialize(); -static Boolean SetValues(), ConstraintSetValues(); -static XtGeometryResult GeometryManager(), PreferredGeometry(); -static void ChangeManaged(); -static Boolean Layout(); - -static void LayoutChild(), ResizeChildren(); - FormClassRec formClassRec = { - { /* core_class fields */ - /* superclass */ (WidgetClass) &constraintClassRec, - /* class_name */ "Form", - /* widget_size */ sizeof(FormRec), - /* class_initialize */ ClassInitialize, - /* class_part_init */ ClassPartInitialize, - /* class_inited */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* realize */ XtInheritRealize, - /* actions */ NULL, - /* num_actions */ 0, - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure */ TRUE, - /* compress_enterleave*/ TRUE, - /* visible_interest */ FALSE, - /* destroy */ NULL, - /* resize */ Resize, - /* expose */ XtInheritExpose, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* set_values_almost */ XtInheritSetValuesAlmost, - /* get_values_hook */ NULL, - /* accept_focus */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ NULL, - /* query_geometry */ PreferredGeometry, - /* display_accelerator*/ XtInheritDisplayAccelerator, - /* extension */ NULL + /* core */ + { + (WidgetClass)&constraintClassRec, /* superclass */ + "Form", /* class_name */ + sizeof(FormRec), /* widget_size */ + XawFormClassInitialize, /* class_initialize */ + XawFormClassPartInitialize, /* class_part_init */ + False, /* class_inited */ + XawFormInitialize, /* initialize */ + NULL, /* initialize_hook */ +#ifndef OLDXAW + XawFormRealize, /* realize */ + actions, /* actions */ + XtNumber(actions), /* num_actions */ +#else + XtInheritRealize, /* realize */ + NULL, /* actions */ + 0, /* num_actions */ +#endif + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + True, /* compress_motion */ + True, /* compress_exposure */ + True, /* compress_enterleave */ + False, /* visible_interest */ + NULL, /* destroy */ + XawFormResize, /* resize */ +#ifndef OLDXAW + XawFormRedisplay, /* expose */ +#else + XtInheritExpose, /* expose */ +#endif + XawFormSetValues, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + NULL, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + NULL, /* tm_table */ + XawFormQueryGeometry, /* query_geometry */ + XtInheritDisplayAccelerator, /* display_accelerator */ + NULL, /* extension */ }, - { /* composite_class fields */ - /* geometry_manager */ GeometryManager, - /* change_managed */ ChangeManaged, - /* insert_child */ XtInheritInsertChild, - /* delete_child */ XtInheritDeleteChild, - /* extension */ NULL + /* composite */ + { + XawFormGeometryManager, /* geometry_manager */ + XawFormChangeManaged, /* change_managed */ + XtInheritInsertChild, /* insert_child */ + XtInheritDeleteChild, /* delete_child */ + NULL, /* extension */ }, - { /* constraint_class fields */ - /* subresourses */ formConstraintResources, - /* subresource_count */ XtNumber(formConstraintResources), - /* constraint_size */ sizeof(FormConstraintsRec), - /* initialize */ ConstraintInitialize, - /* destroy */ NULL, - /* set_values */ ConstraintSetValues, - /* extension */ NULL + /* constraint */ + { + formConstraintResources, /* subresourses */ + XtNumber(formConstraintResources), /* subresource_count */ + sizeof(FormConstraintsRec), /* constraint_size */ + XawFormConstraintInitialize, /* initialize */ + NULL, /* destroy */ + XawFormConstraintSetValues, /* set_values */ + NULL, /* extension */ + }, + /* form */ + { + Layout, /* layout */ }, - { /* form_class fields */ - /* layout */ Layout - } }; WidgetClass formWidgetClass = (WidgetClass)&formClassRec; -/**************************************************************** - * - * Private Procedures - * - ****************************************************************/ +/* + * Implementation + */ +#ifndef OLDXAW +static void +XawFormRealize(Widget w, Mask *mask, XSetWindowAttributes *attr) +{ + XawPixmap *pixmap; + (*formWidgetClass->core_class.superclass->core_class.realize)(w, mask, attr); -static XrmQuark XtQChainLeft, XtQChainRight, XtQChainTop, - XtQChainBottom, XtQRubber; + if (w->core.background_pixmap > XtUnspecifiedPixmap) { + pixmap = XawPixmapFromXPixmap(w->core.background_pixmap, XtScreen(w), + w->core.colormap, w->core.depth); + if (pixmap && pixmap->mask) + XawReshapeWidget(w, pixmap); + } +} -/* ARGSUSED */ -static void _CvtStringToEdgeType(args, num_args, fromVal, toVal) - XrmValuePtr args; /* unused */ - Cardinal *num_args; /* unused */ - XrmValuePtr fromVal; - XrmValuePtr toVal; +static void +XawFormRedisplay(Widget w, XEvent *event, Region region) { - static XtEdgeType edgeType; - XrmQuark q; - char lowerName[40]; - - if (strlen ((char*) fromVal->addr) < sizeof lowerName) { - XmuCopyISOLatin1Lowered (lowerName, (char*)fromVal->addr); - q = XrmStringToQuark(lowerName); - if (q == XtQChainLeft) edgeType = XtChainLeft; - else if (q == XtQChainRight) edgeType = XtChainRight; - else if (q == XtQChainTop) edgeType = XtChainTop; - else if (q == XtQChainBottom) edgeType = XtChainBottom; - else if (q == XtQRubber) edgeType = XtRubber; + FormWidget xaw = (FormWidget)w; + + if (xaw->form.display_list) + XawRunDisplayList(w, xaw->form.display_list, event, region); +} +#endif + +/*ARGSUSED*/ +static void +_CvtStringToEdgeType(XrmValuePtr args, Cardinal *num_args, + XrmValuePtr fromVal, XrmValuePtr toVal) +{ + static XtEdgeType edgeType; + XrmQuark q; + char name[12]; + + XmuNCopyISOLatin1Lowered(name, (char*)fromVal->addr, sizeof(name)); + q = XrmStringToQuark(name); + + if (q == QchainLeft) + edgeType = XtChainLeft; + else if (q == QchainRight) + edgeType = XtChainRight; + else if (q == QchainTop) + edgeType = XtChainTop; + else if (q == QchainBottom) + edgeType = XtChainBottom; + else if (q == Qrubber) + edgeType = XtRubber; else { - toVal->size = 0; - toVal->addr = NULL; - return; + XtStringConversionWarning(fromVal->addr, XtREdgeType); + toVal->size = 0; + toVal->addr = NULL; + return; + } + + toVal->size = sizeof(XtEdgeType); + toVal->addr = (XPointer)&edgeType; +} + +/*ARGSUSED*/ +Boolean +CvtEdgeTypeToString(Display *dpy, XrmValuePtr args, Cardinal *num_args, + XrmValuePtr fromVal, XrmValuePtr toVal, XtPointer *data) +{ + static String buffer; + Cardinal size; + + switch (*(XtEdgeType *)fromVal->addr) { + case XtChainLeft: + buffer = XtEchainLeft; + break; + case XtChainRight: + buffer = XtEchainRight; + break; + case XtChainTop: + buffer = XtEchainTop; + break; + case XtChainBottom: + buffer = XtEchainBottom; + break; + case XtRubber: + buffer = XtErubber; + break; + default: + XawTypeToStringWarning(dpy, XtREdgeType); + toVal->addr = NULL; + toVal->size = 0; + return (False); } - toVal->size = sizeof edgeType; - toVal->addr = (XPointer) &edgeType; - return; - } - toVal->addr = NULL; - toVal->size = 0; + + size = strlen(buffer) + 1; + if (toVal->addr != NULL) { + if (toVal->size < size) { + toVal->size = size; + return (False); + } + strcpy((char *)toVal->addr, buffer); + } + else + toVal->addr = (XPointer)buffer; + toVal->size = sizeof(String); + + return (True); } -static void ClassInitialize() +static void +XawFormClassInitialize(void) { static XtConvertArgRec parentCvtArgs[] = { {XtBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.parent), - sizeof(Widget)} + sizeof(Widget)} }; + + char name[12]; + XawInitializeWidgetSet(); - XtQChainLeft = XrmPermStringToQuark("chainleft"); - XtQChainRight = XrmPermStringToQuark("chainright"); - XtQChainTop = XrmPermStringToQuark("chaintop"); - XtQChainBottom = XrmPermStringToQuark("chainbottom"); - XtQRubber = XrmPermStringToQuark("rubber"); - - XtAddConverter( XtRString, XtREdgeType, _CvtStringToEdgeType, - (XtConvertArgList)NULL, 0 ); - XtSetTypeConverter (XtRString, XtRWidget, XmuNewCvtStringToWidget, - parentCvtArgs, XtNumber(parentCvtArgs), XtCacheNone, - (XtDestructor)NULL); + XmuNCopyISOLatin1Lowered(name, XtEchainLeft, sizeof(name)); + QchainLeft = XrmStringToQuark(name); + XmuNCopyISOLatin1Lowered(name, XtEchainRight, sizeof(name)); + QchainRight = XrmStringToQuark(name); + XmuNCopyISOLatin1Lowered(name, XtEchainTop, sizeof(name)); + QchainTop = XrmStringToQuark(name); + XmuNCopyISOLatin1Lowered(name, XtEchainBottom, sizeof(name)); + QchainBottom = XrmStringToQuark(name); + XmuNCopyISOLatin1Lowered(name, XtErubber, sizeof(name)); + Qrubber = XrmStringToQuark(name); + + XtAddConverter(XtRString, XtREdgeType, _CvtStringToEdgeType, NULL, 0); + XtSetTypeConverter(XtREdgeType, XtRString, CvtEdgeTypeToString, + NULL, 0, XtCacheNone, NULL); + XtSetTypeConverter(XtRString, XtRWidget, XmuNewCvtStringToWidget, + parentCvtArgs, XtNumber(parentCvtArgs), XtCacheNone, + NULL); + XtSetTypeConverter(XtRWidget, XtRString, XmuCvtWidgetToString, + NULL, 0, XtCacheNone, NULL); } -static void ClassPartInitialize(class) - WidgetClass class; +static void +XawFormClassPartInitialize(WidgetClass cclass) { - FormWidgetClass c = (FormWidgetClass)class; - FormWidgetClass super = (FormWidgetClass) - c->core_class.superclass; + FormWidgetClass c = (FormWidgetClass)cclass; + FormWidgetClass super = (FormWidgetClass)c->core_class.superclass; if (c->form_class.layout == XtInheritLayout) c->form_class.layout = super->form_class.layout; } -/* ARGSUSED */ -static void Initialize(request, new, args, num_args) - Widget request, new; - ArgList args; - Cardinal *num_args; +/*ARGSUSED*/ +static void +XawFormInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - FormWidget fw = (FormWidget)new; + FormWidget fw = (FormWidget)cnew; - fw->form.old_width = fw->core.width; - fw->form.old_height = fw->core.height; + fw->form.old_width = fw->form.old_height = 0; fw->form.no_refigure = False; fw->form.needs_relayout = False; fw->form.resize_in_layout = True; fw->form.resize_is_no_op = False; } -/* Function Name: ChangeFormGeometry - * Description: Ask the parent to change the form widget's geometry. - * Arguments: w - the Form widget. - * query_only - TRUE if this is only a query. - * width, height - the new width and height. - * ret_width, ret_height - the actual size the form is allowed - * to resize to. - * Returns: TRUE of children may always be resized. +/* + * Function: + * ChangeFormGeometry + * + * Parameters: + * w - Form widget + * query_only - is only a query? + * width - new width and height + * height - "" + * ret_width - actual size the form is allowed to resize to (return) + * ret_height - "" + * + * Description: + * Ask the parent to change the form widget's geometry. + * + * Returns: + * True of children may always be resized */ - -static Boolean -ChangeFormGeometry(w, query_only, width, height, ret_width, ret_height) -Widget w; -Boolean query_only; -Dimension width, height; -Dimension *ret_width, *ret_height; +static Bool +ChangeFormGeometry(Widget w, Bool query_only, + unsigned int width, unsigned int height, + Dimension *ret_width, Dimension *ret_height) { - FormWidget fw = (FormWidget) w; + FormWidget fw = (FormWidget)w; Boolean always_resize_children; XtGeometryResult result; XtWidgetGeometry request, return_request; /* * If we are already at the desired size then there is no need - * to ask our parent of we can change size. + * to ask our parent of we can change size */ - - if ( (width == fw->core.width) && (height == fw->core.height) ) - return(TRUE); + if (width == XtWidth(fw) && height == XtHeight(fw)) + return (True); request.width = width; request.height = height; @@ -283,46 +498,51 @@ Dimension *ret_width, *ret_height; request.request_mode |= XtCWQueryOnly; /* - * Do no invoke the resize rules if our size changes here. + * Do no invoke the resize rules if our size changes here */ - - fw->form.resize_is_no_op = TRUE; + fw->form.resize_is_no_op = True; result = XtMakeGeometryRequest(w, &request, &return_request); if (result == XtGeometryAlmost) { request = return_request; - (void) XtMakeGeometryRequest(w, &request, &return_request); - always_resize_children = FALSE; + (void)XtMakeGeometryRequest(w, &request, &return_request); + always_resize_children = False; } else - always_resize_children = (result == XtGeometryYes); + always_resize_children = result == XtGeometryYes; - fw->form.resize_is_no_op = FALSE; + fw->form.resize_is_no_op = False; if (ret_width != NULL) *ret_width = request.width; if (ret_height != NULL) *ret_height = request.height; - return(always_resize_children); + return (always_resize_children); } -/* Function Name: Layout - * Description: Moves all the children around. - * Arguments: fw - the Form widget. - * width, height - ** UNUSED **. - * force_relayout - will force the children to be - * moved, even if some go past the edge - * of the form. - * Returns: True if the children are allowed to move from their - * current locations to the new ones. +/* + * Function: + * Layout + * + * Parameters: + * fw - Form widget + * width - unused + * height - "" + * force_relayout - will force the children to be moved, even if some + * go past the edge of the form + * + * Description: + * Moves all the children around. + * + * Returns: + * True if the children are allowed to move from their + * current locations to the new ones. */ - -/* ARGSUSED */ -static Boolean Layout(fw, width, height, force_relayout) - FormWidget fw; - Dimension width, height; - Boolean force_relayout; +/*ARGSUSED*/ +static Boolean +Layout(FormWidget fw, unsigned int width, unsigned int height, + Bool force_relayout) { int num_children = fw->composite.num_children; WidgetList children = fw->composite.children; @@ -345,13 +565,13 @@ static Boolean Layout(fw, width, height, force_relayout) LayoutChild(*childP); - x = form->form.new_x + (*childP)->core.width + - ((*childP)->core.border_width << 1); + x = form->form.new_x + XtWidth(*childP) + + (XtBorderWidth(*childP) << 1); if (x > (int)maxx) maxx = x; - y = form->form.new_y + (*childP)->core.height + - ((*childP)->core.border_width << 1); + y = form->form.new_y + XtHeight(*childP) + + (XtBorderWidth(*childP) << 1); if (y > (int)maxy) maxy = y; } @@ -363,485 +583,525 @@ static Boolean Layout(fw, width, height, force_relayout) if (fw->form.resize_in_layout) { Boolean always_resize_children; - always_resize_children = - ChangeFormGeometry( (Widget) fw, FALSE, maxx, maxy, - (Dimension *)NULL, (Dimension *)NULL); + always_resize_children = + ChangeFormGeometry((Widget)fw, False, maxx, maxy, NULL, NULL); +#ifdef OLDXAW fw->form.old_width = fw->core.width; fw->form.old_height = fw->core.height; - - ret_val = (always_resize_children || ( (fw->core.width >= maxx) && - (fw->core.height >= maxy))); +#endif if (force_relayout) - ret_val = TRUE; + ret_val = True; + else + ret_val = always_resize_children || + (XtWidth(fw) >= maxx && XtHeight(fw) >= maxy); if (ret_val) - ResizeChildren((Widget) fw); + ResizeChildren((Widget)fw); } else ret_val = False; fw->form.needs_relayout = False; - return ret_val; + + return (ret_val); } -/* Function Name: ResizeChildren - * Description: Resizes all children to new_x and new_y. - * Arguments: w - the form widget. - * Returns: none. +/* + * Function: + * ResizeChildren + * + * Parameters: + * w - form widget + * + * Description: + * Resizes all children to new_x and new_y. */ - -static void ResizeChildren(w) -Widget w; +static void +ResizeChildren(Widget w) { - FormWidget fw = (FormWidget) w; + FormWidget fw = (FormWidget)w; int num_children = fw->composite.num_children; WidgetList children = fw->composite.children; Widget *childP; for (childP = children; childP - children < num_children; childP++) { FormConstraints form; + Position x, y; - if (!XtIsManaged(*childP)) + if (!XtIsManaged(*childP)) continue; form = (FormConstraints)(*childP)->core.constraints; + + if (fw->form.old_width && fw->form.old_height) { + x = TransformCoord(form->form.new_x, fw->form.old_width, + XtWidth(fw), form->form.left); + y = TransformCoord(form->form.new_y, fw->form.old_height, + XtHeight(fw), form->form.top); + } + else { + x = form->form.new_x; + y = form->form.new_y; + } + if (fw->form.no_refigure) { -/* - * I am changing the widget wrapper w/o modifing the window. This is - * risky, but I can get away with it since I am the parent of this - * widget, and he must ask me for any geometry changes. - * - * The window will be updated when no_refigure is set back to False. - */ - (*childP)->core.x = form->form.new_x; - (*childP)->core.y = form->form.new_y; + /* + * I am changing the widget wrapper w/o modifing the window. This is + * risky, but I can get away with it since I am the parent of this + * widget, and he must ask me for any geometry changes + * + * The window will be updated when no_refigure is set back to False + */ + XtX(*childP) = x; + XtY(*childP) = y; } else - XtMoveWidget(*childP, form->form.new_x, form->form.new_y); + XtMoveWidget(*childP, x, y); } } - -static void LayoutChild(w) - Widget w; +static void +LayoutChild(Widget w) { FormConstraints form = (FormConstraints)w->core.constraints; Widget ref; switch (form->form.layout_state) { - - case LayoutPending: - form->form.layout_state = LayoutInProgress; - break; - - case LayoutDone: - return; - - case LayoutInProgress: - { - String subs[2]; - Cardinal num_subs = 2; - subs[0] = w->core.name; - subs[1] = w->core.parent->core.name; - XtAppWarningMsg(XtWidgetToApplicationContext(w), - "constraintLoop","xawFormLayout","XawToolkitError", - "constraint loop detected while laying out child '%s' in FormWidget '%s'", - subs, &num_subs); - return; - } + case LayoutPending: + form->form.layout_state = LayoutInProgress; + break; + case LayoutDone: + return; + case LayoutInProgress: { + String subs[2]; + Cardinal num_subs = 2; + subs[0] = w->core.name; + subs[1] = w->core.parent->core.name; + + XtAppWarningMsg(XtWidgetToApplicationContext(w), + "constraintLoop", "xawFormLayout", "XawToolkitError", + "constraint loop detected while laying out " + "child '%s' in FormWidget '%s'", + subs, &num_subs); + } return; } form->form.new_x = form->form.dx; form->form.new_y = form->form.dy; - if ((ref = form->form.horiz_base) != (Widget)NULL) { - FormConstraints ref_form = (FormConstraints) ref->core.constraints; + if ((ref = form->form.horiz_base) != NULL) { + FormConstraints ref_form = (FormConstraints)ref->core.constraints; LayoutChild(ref); - form->form.new_x += (ref_form->form.new_x + - ref->core.width + (ref->core.border_width << 1)); + form->form.new_x += ref_form->form.new_x + XtWidth(ref) + + (XtBorderWidth(ref) << 1); } - if ((ref = form->form.vert_base) != (Widget)NULL) { - FormConstraints ref_form = (FormConstraints) ref->core.constraints; + if ((ref = form->form.vert_base) != NULL) { + FormConstraints ref_form = (FormConstraints)ref->core.constraints; LayoutChild(ref); - form->form.new_y += (ref_form->form.new_y + - ref->core.height + (ref->core.border_width << 1)); + form->form.new_y += ref_form->form.new_y + XtHeight(ref) + + (XtBorderWidth(ref) << 1); } form->form.layout_state = LayoutDone; } - -static Position TransformCoord(loc, old, new, type) - Position loc; - Dimension old, new; - XtEdgeType type; +static int +TransformCoord(int loc, unsigned int old, unsigned int cnew, XtEdgeType type) { if (type == XtRubber) { - if ( ((int) old) > 0) - loc = (int)(loc * new) / (int)old; + if ((int)old > 0) + loc = (int)(loc * ((double)cnew / (double)old)); } else if (type == XtChainBottom || type == XtChainRight) - loc += (Position)new - (Position)old; - - /* I don't see any problem with returning values less than zero. */ + loc += (int)cnew - (int)old; return (loc); } -static void Resize(w) - Widget w; +static void +XawFormResize(Widget w) { FormWidget fw = (FormWidget)w; WidgetList children = fw->composite.children; int num_children = fw->composite.num_children; Widget *childP; - Position x, y; - Dimension width, height; + int x, y; + int width, height; + Boolean unmap = XtIsRealized(w) && w->core.mapped_when_managed && + XtIsManaged(w); + + if (unmap) + XtUnmapWidget(w); if (!fw->form.resize_is_no_op) for (childP = children; childP - children < num_children; childP++) { - FormConstraints form= (FormConstraints)(*childP)->core.constraints; - if (!XtIsManaged(*childP)) continue; - x = TransformCoord( (*childP)->core.x, fw->form.old_width, - fw->core.width, form->form.left ); - y = TransformCoord( (*childP)->core.y, fw->form.old_height, - fw->core.height, form->form.top ); - - form->form.virtual_width = - TransformCoord((Position)((*childP)->core.x - + form->form.virtual_width - + 2 * (*childP)->core.border_width), - fw->form.old_width, fw->core.width, - form->form.right ) - - (x + 2 * (*childP)->core.border_width); - - form->form.virtual_height = - TransformCoord((Position)((*childP)->core.y - + form->form.virtual_height - + 2 * (*childP)->core.border_width), - fw->form.old_height, fw->core.height, - form->form.bottom ) - - ( y + 2 * (*childP)->core.border_width); - - width = (Dimension) - (form->form.virtual_width < 1) ? 1 : form->form.virtual_width; - height = (Dimension) - (form->form.virtual_height < 1) ? 1 : form->form.virtual_height; - - XtConfigureWidget(*childP,x,y, (Dimension)width, (Dimension)height, - (*childP)->core.border_width ); + FormConstraints form = (FormConstraints)(*childP)->core.constraints; + + if (!XtIsManaged(*childP)) + continue; + +#ifndef OLDXAW + x = TransformCoord(form->form.virtual_x, fw->form.old_width, + XtWidth(fw), form->form.left); + y = TransformCoord(form->form.virtual_y, fw->form.old_height, + XtHeight(fw), form->form.top); + width = TransformCoord(form->form.virtual_x + + form->form.virtual_width + + (XtBorderWidth(*childP) << 1), + fw->form.old_width, XtWidth(fw), + form->form.right) - + (x + (XtBorderWidth(*childP) << 1)); + height = TransformCoord(form->form.virtual_y + + form->form.virtual_height + + (XtBorderWidth(*childP) << 1), + fw->form.old_height, XtHeight(fw), + form->form.bottom) - + (y + (XtBorderWidth(*childP) << 1)); +#else + x = TransformCoord(XtX(*childP), fw->form.old_width, + XtWidth(fw), form->form.left); + y = TransformCoord(XtY(*childP), fw->form.old_height, + XtHeight(fw), form->form.top); + width = TransformCoord(XtX(*childP) + form->form.virtual_width + + (XtBorderWidth(*childP) << 1), + fw->form.old_width, XtWidth(fw), + form->form.right) - + (x + (XtBorderWidth(*childP) << 1)); + height = TransformCoord(XtY(*childP) + form->form.virtual_height + + (XtBorderWidth(*childP) << 1), + fw->form.old_height, XtHeight(fw), + form->form.bottom) - + (y + (XtBorderWidth(*childP) << 1)); + form->form.virtual_width = width; + form->form.virtual_height = height; +#endif + + width = width < 1 ? 1 : width; + height = height < 1 ? 1 : height; + + XtConfigureWidget(*childP, x, y, width, height, + XtBorderWidth(*childP)); } - fw->form.old_width = fw->core.width; - fw->form.old_height = fw->core.height; -} + if (unmap) + XtMapWidget(w); -/* - * I don't want to even think about what ``Almost'' would mean - Chris. - */ +#ifdef OLDXAW + fw->form.old_width = XtWidth(fw); + fw->form.old_height = XtHeight(fw); +#endif +} -/* ARGSUSED */ -static XtGeometryResult GeometryManager(w, request, reply) - Widget w; - XtWidgetGeometry *request; - XtWidgetGeometry *reply; /* RETURN */ +/*ARGSUSED*/ +static XtGeometryResult +XawFormGeometryManager(Widget w, XtWidgetGeometry *request, + XtWidgetGeometry *reply) { Dimension old_width, old_height; - FormWidget fw = (FormWidget) XtParent(w); - FormConstraints form = (FormConstraints) w->core.constraints; + FormWidget fw = (FormWidget)XtParent(w); + FormConstraints form = (FormConstraints)w->core.constraints; XtWidgetGeometry allowed; XtGeometryResult ret_val; - if ((request->request_mode & ~(XtCWQueryOnly | CWWidth | CWHeight)) || - !form->form.allow_resize) { - + if ((request->request_mode & (unsigned)~(XtCWQueryOnly | CWWidth | CWHeight)) + || !form->form.allow_resize) { /* If GeometryManager is invoked during a SetValues call on a child - * then it is necessary to compute a new layout if ConstraintSetValues - * allowed any constraint changes. */ - - if (fw->form.needs_relayout) + * then it is necessary to compute a new layout if ConstraintSetValues + * allowed any constraint changes + */ + if (fw->form.needs_relayout) (*((FormWidgetClass)fw->core.widget_class)->form_class.layout) (fw, 0, 0, True); - return(XtGeometryNo); + return (XtGeometryNo); } if (request->request_mode & CWWidth) allowed.width = request->width; else - allowed.width = w->core.width; + allowed.width = XtWidth(w); if (request->request_mode & CWHeight) allowed.height = request->height; else - allowed.height = w->core.height; - - if (allowed.width == w->core.width && allowed.height == w->core.height) { + allowed.height = XtHeight(w); + if (allowed.width == XtWidth(w) && allowed.height == XtHeight(w)) { /* If GeometryManager is invoked during a SetValues call on a child - * then it is necessary to compute a new layout if ConstraintSetValues - * allowed any constraint changes. */ - - if (fw->form.needs_relayout) + * then it is necessary to compute a new layout if ConstraintSetValues + * allowed any constraint changes + */ + if (fw->form.needs_relayout) (*((FormWidgetClass)fw->core.widget_class)->form_class.layout) (fw, 0, 0, True); - return(XtGeometryNo); + return (XtGeometryNo); } /* - * Remember the old size, and then set the size to the requested size. + * Remember the old size, and then set the size to the requested size */ - - old_width = w->core.width; - old_height = w->core.height; - w->core.width = allowed.width; - w->core.height = allowed.height; + old_width = XtWidth(w); + old_height = XtHeight(w); + XtWidth(w) = allowed.width; + XtHeight(w) = allowed.height; if (request->request_mode & XtCWQueryOnly) { Boolean always_resize_children; Dimension ret_width, ret_height; - fw->form.resize_in_layout = FALSE; + fw->form.resize_in_layout = False; (*((FormWidgetClass)fw->core.widget_class)->form_class.layout) - ( fw, w->core.width, w->core.height, - FALSE ); + (fw, XtWidth(w), XtHeight(w), False); /* - * Reset the size of this child back to what it used to be. + * Reset the size of this child back to what it used to be */ + XtWidth(w) = old_width; + XtHeight(w) = old_height; - w->core.width = old_width; - w->core.height = old_height; - - fw->form.resize_in_layout = TRUE; + fw->form.resize_in_layout = True; - always_resize_children = ChangeFormGeometry(w, TRUE, + always_resize_children = ChangeFormGeometry(w, True, fw->form.preferred_width, fw->form.preferred_height, &ret_width, &ret_height); - if (always_resize_children || - ((ret_width >= fw->form.preferred_width) && - (ret_height >= fw->form.preferred_height))) - { + if (always_resize_children + || (ret_width >= fw->form.preferred_width + && ret_height >= fw->form.preferred_height)) ret_val = XtGeometryYes; - } else ret_val = XtGeometryNo; } else { if ((*((FormWidgetClass)fw->core.widget_class)->form_class.layout) - ( fw, w->core.width, w->core.height, - FALSE)) - { - form->form.virtual_width = w->core.width; /* reset virtual */ - form->form.virtual_height = w->core.height; /* width and height. */ + (fw, XtWidth(w), XtHeight(w), False)) { + Widget *childP; + int num_children = fw->composite.num_children; + WidgetList children = fw->composite.children; + if (fw->form.no_refigure) { -/* - * I am changing the widget wrapper w/o modifing the window. This is - * risky, but I can get away with it since I am the parent of this - * widget, and he must ask me for any geometry changes. - * - * The window will be updated when no_refigure is set back to False. - */ + /* + * I am changing the widget wrapper w/o modifing the window. + * This is risky, but I can get away with it since I am the + * parent of this widget, and he must ask me for any geometry + * changes + * + * The window will be updated when no_refigure is set back + * to False + */ form->form.deferred_resize = True; ret_val = XtGeometryDone; } - else + else ret_val = XtGeometryYes; + + /* + * Resets everything. + */ + fw->form.old_width = XtWidth(fw); + fw->form.old_height = XtHeight(fw); + for (childP = children; childP - children < num_children; childP++) { + Widget nw = *childP; + + if (XtIsManaged(nw)) { + FormConstraints nform = (FormConstraints)nw->core.constraints; + +#ifndef OLDXAW + nform->form.virtual_x = XtX(nw); + nform->form.virtual_y = XtY(nw); +#endif + nform->form.virtual_width = XtWidth(nw); + nform->form.virtual_height = XtHeight(nw); + } + } } else { - w->core.width = old_width; - w->core.height = old_height; + XtWidth(w) = old_width; + XtHeight(w) = old_height; ret_val = XtGeometryNo; } } - return(ret_val); + return (ret_val); } - -/* ARGSUSED */ -static Boolean SetValues(current, request, new, args, num_args) - Widget current, request, new; - ArgList args; - Cardinal *num_args; +/*ARGSUSED*/ +static Boolean +XawFormSetValues(Widget current, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - return( FALSE ); -} +#ifndef OLDXAW + FormWidget f_old = (FormWidget)current; + FormWidget f_new = (FormWidget)cnew; + + if (f_old->core.background_pixmap != f_new->core.background_pixmap) { + XawPixmap *opix, *npix; + + opix = XawPixmapFromXPixmap(f_old->core.background_pixmap, XtScreen(f_old), + f_old->core.colormap, f_old->core.depth); + npix = XawPixmapFromXPixmap(f_new->core.background_pixmap, XtScreen(f_new), + f_new->core.colormap, f_new->core.depth); + if ((npix && npix->mask) || (opix && opix->mask)) + XawReshapeWidget(cnew, npix); + } +#endif /* OLDXAW */ + return (False); +} /* ARGSUSED */ -static void ConstraintInitialize(request, new, args, num_args) - Widget request, new; - ArgList args; - Cardinal *num_args; +static void +XawFormConstraintInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - FormConstraints form = (FormConstraints)new->core.constraints; - FormWidget fw = (FormWidget)new->core.parent; + FormConstraints form = (FormConstraints)cnew->core.constraints; + FormWidget fw = (FormWidget)cnew->core.parent; - form->form.virtual_width = (int) new->core.width; - form->form.virtual_height = (int) new->core.height; +#ifndef OLDXAW + form->form.virtual_x = XtX(cnew); + form->form.virtual_y = XtY(cnew); +#endif + form->form.virtual_width = XtWidth(cnew); + form->form.virtual_height = XtHeight(cnew); if (form->form.dx == default_value) - form->form.dx = fw->form.default_spacing; + form->form.dx = fw->form.default_spacing; if (form->form.dy == default_value) - form->form.dy = fw->form.default_spacing; + form->form.dy = fw->form.default_spacing; form->form.deferred_resize = False; } /*ARGSUSED*/ -static Boolean ConstraintSetValues(current, request, new, args, num_args) - Widget current, request, new; - ArgList args; - Cardinal *num_args; +static Boolean +XawFormConstraintSetValues(Widget current, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - FormConstraints cfc = (FormConstraints) current->core.constraints; - FormConstraints nfc = (FormConstraints) new->core.constraints; - - if (cfc->form.top != nfc->form.top || - cfc->form.bottom != nfc->form.bottom || - cfc->form.left != nfc->form.left || - cfc->form.right != nfc->form.right || - cfc->form.dx != nfc->form.dx || - cfc->form.dy != nfc->form.dy || - cfc->form.horiz_base != nfc->form.horiz_base || - cfc->form.vert_base != nfc->form.vert_base) { - - FormWidget fp = (FormWidget) XtParent(new); - - /* If there are no subclass ConstraintSetValues procedures remaining - * to be invoked, and if there is no geometry request about to be - * made, then invoke the new layout now; else defer it. */ - - if (XtClass(XtParent(new)) == formWidgetClass && - current->core.x == new->core.x && - current->core.y == new->core.y && - current->core.width == new->core.width && - current->core.height == new->core.height && - current->core.border_width == new->core.border_width) - Layout(fp, 0, 0, True); - else fp->form.needs_relayout = True; - } - return( FALSE ); + FormConstraints cfc = (FormConstraints)current->core.constraints; + FormConstraints nfc = (FormConstraints)cnew->core.constraints; + + if (cfc->form.top != nfc->form.top || cfc->form.bottom != nfc->form.bottom + || cfc->form.left != nfc->form.left || cfc->form.right != nfc->form.right + || cfc->form.dx != nfc->form.dx || cfc->form.dy != nfc->form.dy + || cfc->form.horiz_base != nfc->form.horiz_base + || cfc->form.vert_base != nfc->form.vert_base) { + FormWidget fp = (FormWidget)XtParent(cnew); + + /* If there are no subclass ConstraintSetValues procedures remaining + * to be invoked, and if there is no geometry request about to be + * made, then invoke the new layout now; else defer it + */ + if (XtClass(XtParent(cnew)) == formWidgetClass + && XtX(current) == XtX(cnew) + && XtY(current) == XtY(cnew) + && XtWidth(current) == XtWidth(cnew) + && XtHeight(current) == XtHeight(cnew) + && XtBorderWidth(current) == XtBorderWidth(cnew)) + Layout(fp, 0, 0, True); + else + fp->form.needs_relayout = True; + } + + return (False); } -static void ChangeManaged(w) - Widget w; +static void +XawFormChangeManaged(Widget w) { - FormWidget fw = (FormWidget)w; - FormConstraints form; - WidgetList children, childP; - int num_children = fw->composite.num_children; - Widget child; - - /* - * Reset virtual width and height for all children. - */ - - for (children = childP = fw->composite.children ; - childP - children < num_children; childP++) { - child = *childP; - if (XtIsManaged(child)) { - form = (FormConstraints)child->core.constraints; - -/* - * If the size is one (1) then we must not change the virtual sizes, as - * they contain useful information. If someone actually wants a widget of - * width or height one (1) in a form widget he will lose, can't win them all. - * - * Chris D. Peterson 2/9/89. - */ - - if ( child->core.width != 1) - form->form.virtual_width = (int) child->core.width; - if ( child->core.height != 1) - form->form.virtual_height = (int) child->core.height; + FormWidget fw = (FormWidget)w; + FormConstraints form; + WidgetList children, childP; + int num_children = fw->composite.num_children; + Widget child; + + (*((FormWidgetClass)w->core.widget_class)->form_class.layout) + (fw, XtWidth(w), XtHeight(w), True); + + fw->form.old_width = XtWidth(w); + fw->form.old_height = XtHeight(w); + for (children = childP = fw->composite.children; + childP - children < num_children; + childP++) { + child = *childP; + if (!XtIsManaged(child)) + continue; + form = (FormConstraints)child->core.constraints; +#ifndef OLDXAW + form->form.virtual_x = XtX(child); + form->form.virtual_y = XtY(child); +#endif + form->form.virtual_width = XtWidth(child); + form->form.virtual_height = XtHeight(child); } - } - (*((FormWidgetClass)w->core.widget_class)->form_class.layout) - ((FormWidget) w, w->core.width, - w->core.height, TRUE); } - -static XtGeometryResult PreferredGeometry( widget, request, reply ) - Widget widget; - XtWidgetGeometry *request, *reply; +static XtGeometryResult +XawFormQueryGeometry(Widget widget, XtWidgetGeometry *request, + XtWidgetGeometry *reply) { FormWidget w = (FormWidget)widget; - + reply->width = w->form.preferred_width; reply->height = w->form.preferred_height; reply->request_mode = CWWidth | CWHeight; - if ( request->request_mode & (CWWidth | CWHeight) == - (CWWidth | CWHeight) - && request->width == reply->width - && request->height == reply->height) - return XtGeometryYes; - else if (reply->width == w->core.width && reply->height == w->core.height) - return XtGeometryNo; - else - return XtGeometryAlmost; -} + if ((request->request_mode & (CWWidth | CWHeight)) == (CWWidth | CWHeight) + && request->width == reply->width + && request->height == reply->height) + return (XtGeometryYes); + else if (reply->width == XtWidth(w) && reply->height == XtHeight(w)) + return (XtGeometryNo); -/********************************************************************** - * - * Public routines - * - **********************************************************************/ + return (XtGeometryAlmost); +} -/* +/* + * Public routines + */ +/* * Set or reset figuring (ignored if not realized) */ - void -#if NeedFunctionPrototypes XawFormDoLayout(Widget w, #if NeedWidePrototypes - int doit) + Bool force #else - Boolean doit) -#endif -#else -XawFormDoLayout(w, doit) -Widget w; -Boolean doit; + Boolean force #endif +) { Widget *childP; FormWidget fw = (FormWidget)w; int num_children = fw->composite.num_children; WidgetList children = fw->composite.children; - if ( ((fw->form.no_refigure = !doit) == TRUE) || !XtIsRealized(w) ) + if ((fw->form.no_refigure = !force) == True || !XtIsRealized(w)) return; for (childP = children; childP - children < num_children; childP++) { - Widget w = *childP; - if (XtIsManaged(w)) { - FormConstraints form = (FormConstraints)w->core.constraints; + Widget nw = *childP; + + if (XtIsManaged(nw)) { + FormConstraints form = (FormConstraints)nw->core.constraints; /* * Xt Configure widget is too smart, and optimizes out - * my changes. + * my changes */ + XMoveResizeWindow(XtDisplay(nw), XtWindow(nw), + XtX(nw), XtY(nw), XtWidth(nw), XtHeight(nw)); - XMoveResizeWindow(XtDisplay(w), XtWindow(w), - w->core.x, w->core.y, - w->core.width, w->core.height); - - if (form->form.deferred_resize && - XtClass(w)->core_class.resize != (XtWidgetProc) NULL) { - (*(XtClass(w)->core_class.resize))(w); + if (form) + if (form->form.deferred_resize && + XtClass(nw)->core_class.resize != NULL) { + (*(XtClass(nw)->core_class.resize))(nw); form->form.deferred_resize = False; - } + } } } } @@ -46,6 +46,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/Grip.c,v 1.8 2001/12/14 19:54:40 dawes Exp $ */ /* * Grip.c - Grip Widget (Used by Paned Widget) @@ -53,87 +54,126 @@ SOFTWARE. */ #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> -#include <X11/Xaw/XawInit.h> #include <X11/Xaw/GripP.h> +#include <X11/Xaw/XawInit.h> + +/* + * Prototypes + */ +static void +GripAction(Widget, XEvent*, String*, Cardinal*); +/* + * Initialization + */ static XtResource resources[] = { - {XtNwidth, XtCWidth, XtRDimension, sizeof(Dimension), - XtOffsetOf(GripRec, core.width), XtRImmediate, - (XtPointer) DEFAULT_GRIP_SIZE}, - {XtNheight, XtCHeight, XtRDimension, sizeof(Dimension), - XtOffsetOf(GripRec, core.height), XtRImmediate, - (XtPointer) DEFAULT_GRIP_SIZE}, - {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), - XtOffsetOf(GripRec, core.background_pixel), XtRString, - XtDefaultForeground}, - {XtNborderWidth, XtCBorderWidth, XtRDimension, sizeof(Dimension), - XtOffsetOf(GripRec, core.border_width), XtRImmediate, (XtPointer)0}, - {XtNcallback, XtCCallback, XtRCallback, sizeof(XtPointer), - XtOffsetOf(GripRec, grip.grip_action), XtRCallback, NULL}, + { + XtNwidth, + XtCWidth, + XtRDimension, + sizeof(Dimension), + XtOffsetOf(GripRec, core.width), + XtRImmediate, + (XtPointer)DEFAULT_GRIP_SIZE + }, + { + XtNheight, + XtCHeight, + XtRDimension, + sizeof(Dimension), + XtOffsetOf(GripRec, core.height), + XtRImmediate, + (XtPointer)DEFAULT_GRIP_SIZE + }, + { + XtNforeground, + XtCForeground, + XtRPixel, + sizeof(Pixel), + XtOffsetOf(GripRec, core.background_pixel), + XtRString, + XtDefaultForeground + }, + { + XtNborderWidth, + XtCBorderWidth, + XtRDimension, + sizeof(Dimension), + XtOffsetOf(GripRec, core.border_width), + XtRImmediate, + (XtPointer)0 + }, + { + XtNcallback, + XtCCallback, + XtRCallback, + sizeof(XtPointer), + XtOffsetOf(GripRec, grip.grip_action), + XtRCallback, + NULL + }, }; -static void GripAction( /* Widget, XEvent*, String*, Cardinal */ ); - static XtActionsRec actionsList[] = { {"GripAction", GripAction}, }; -#define SuperClass (&simpleClassRec) +#define Superclass (&simpleClassRec) GripClassRec gripClassRec = { + /* core */ { -/* core class fields */ - /* superclass */ (WidgetClass) SuperClass, - /* class name */ "Grip", - /* size */ sizeof(GripRec), - /* class initialize */ XawInitializeWidgetSet, - /* class_part_init */ NULL, - /* class_inited */ FALSE, - /* initialize */ NULL, - /* initialize_hook */ NULL, - /* realize */ XtInheritRealize, - /* actions */ actionsList, - /* num_actions */ XtNumber(actionsList), - /* resources */ resources, - /* resource_count */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure */ TRUE, - /* compress_enterleave*/ TRUE, - /* visible_interest */ FALSE, - /* destroy */ NULL, - /* resize */ NULL, - /* expose */ NULL, - /* set_values */ NULL, - /* set_values_hook */ NULL, - /* set_values_almost */ XtInheritSetValuesAlmost, - /* get_values_hook */ NULL, - /* accept_focus */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ NULL, - /* query_geometry */ XtInheritQueryGeometry, - /* display_accelerator*/ XtInheritDisplayAccelerator, - /* extension */ NULL + (WidgetClass)Superclass, /* superclass */ + "Grip", /* class name */ + sizeof(GripRec), /* size */ + XawInitializeWidgetSet, /* class initialize */ + NULL, /* class_part_init */ + False, /* class_inited */ + NULL, /* initialize */ + NULL, /* initialize_hook */ + XtInheritRealize, /* realize */ + actionsList, /* actions */ + XtNumber(actionsList), /* num_actions */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + True, /* compress_motion */ + True, /* compress_exposure */ + True, /* compress_enterleave */ + False, /* visible_interest */ + NULL, /* destroy */ + NULL, /* resize */ + XtInheritExpose, /* expose */ + NULL, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + NULL, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + NULL, /* tm_table */ + XtInheritQueryGeometry, /* query_geometry */ + XtInheritDisplayAccelerator, /* display_accelerator */ + NULL, /* extension */ }, -/* Simple class fields initialization */ + /* simple */ { - /* change_sensitive */ XtInheritChangeSensitive + XtInheritChangeSensitive, /* change_sensitive */ }, -/* Grip class fields initialization */ + /* grip */ { - /* not used */ 0 + NULL, /* extension */ } }; -WidgetClass gripWidgetClass = (WidgetClass) &gripClassRec; +WidgetClass gripWidgetClass = (WidgetClass)&gripClassRec; -static void GripAction( widget, event, params, num_params ) - Widget widget; - XEvent *event; - String *params; - Cardinal *num_params; +/* + * Implementation + */ +static void +GripAction(Widget widget, XEvent *event, String *params, Cardinal *num_params) { XawGripCallDataRec call_data; @@ -141,5 +181,5 @@ static void GripAction( widget, event, params, num_params ) call_data.params = params; call_data.num_params = *num_params; - XtCallCallbacks( widget, XtNcallback, (XtPointer)&call_data ); + XtCallCallbacks(widget, XtNcallback, (XtPointer)&call_data); } diff --git a/src/Label.c b/src/Label.c index c43391b..b5004d6 100644 --- a/src/Label.c +++ b/src/Label.c @@ -46,30 +46,20 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/Label.c,v 1.13 2001/12/14 19:54:40 dawes Exp $ */ -/* - * Label.c - Label widget - * - */ - +#include <stdio.h> +#include <ctype.h> #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> #include <X11/Xos.h> -#include <X11/Xaw/XawInit.h> -#include <X11/Xaw/LabelP.h> #include <X11/Xmu/Converters.h> #include <X11/Xmu/Drawing.h> -#include <stdio.h> -#include <ctype.h> - -/* needed for abs() */ -#ifndef X_NOT_STDC_ENV -#include <stdlib.h> -#else -int abs(); -#endif +#include <X11/Xaw/LabelP.h> +#include <X11/Xaw/XawInit.h> +#include "Private.h" -#define streq(a,b) (strcmp( (a), (b) ) == 0) +#define streq(a, b) (strcmp((a), (b)) == 0) #define MULTI_LINE_LABEL 32767 @@ -77,123 +67,230 @@ int abs(); #define WORD64 #endif -/**************************************************************** - * - * Full class record constant - * - ****************************************************************/ +/* + * Class Methods + */ +static void XawLabelClassInitialize(void); +static void XawLabelDestroy(Widget); +static void XawLabelInitialize(Widget, Widget, ArgList, Cardinal*); +static XtGeometryResult XawLabelQueryGeometry(Widget, XtWidgetGeometry*, + XtWidgetGeometry*); +static void XawLabelRedisplay(Widget, XEvent*, Region); +static void XawLabelResize(Widget); +static Boolean XawLabelSetValues(Widget, Widget, Widget, + ArgList, Cardinal*); -/* Private Data */ +/* + * Prototypes + */ +#ifdef WORD64 +static int _XawLabelWidth16(XFontStruct*, char*, int); +static void _XawLabelDraw16(Display*, Drawable, GC, int, int, char*, int); +#endif +static void compute_bitmap_offsets(LabelWidget); +static void GetGrayGC(LabelWidget); +static void GetNormalGC(LabelWidget); +static void _Reposition(LabelWidget, unsigned int, unsigned int, + Position*, Position*); +static void set_bitmap_info(LabelWidget); +static void SetTextWidthAndHeight(LabelWidget); +/* + * Initialization + */ #define offset(field) XtOffsetOf(LabelRec, field) static XtResource resources[] = { - {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), - offset(label.foreground), XtRString, XtDefaultForeground}, - {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *), - offset(label.font),XtRString, XtDefaultFont}, - {XtNfontSet, XtCFontSet, XtRFontSet, sizeof(XFontSet ), - offset(label.fontset),XtRString, XtDefaultFontSet}, - {XtNlabel, XtCLabel, XtRString, sizeof(String), - offset(label.label), XtRString, NULL}, - {XtNencoding, XtCEncoding, XtRUnsignedChar, sizeof(unsigned char), - offset(label.encoding), XtRImmediate, (XtPointer)XawTextEncoding8bit}, - {XtNjustify, XtCJustify, XtRJustify, sizeof(XtJustify), - offset(label.justify), XtRImmediate, (XtPointer)XtJustifyCenter}, - {XtNinternalWidth, XtCWidth, XtRDimension, sizeof(Dimension), - offset(label.internal_width), XtRImmediate, (XtPointer)4}, - {XtNinternalHeight, XtCHeight, XtRDimension, sizeof(Dimension), - offset(label.internal_height), XtRImmediate, (XtPointer)2}, - {XtNleftBitmap, XtCLeftBitmap, XtRBitmap, sizeof(Pixmap), - offset(label.left_bitmap), XtRImmediate, (XtPointer) None}, - {XtNbitmap, XtCPixmap, XtRBitmap, sizeof(Pixmap), - offset(label.pixmap), XtRImmediate, (XtPointer)None}, - {XtNresize, XtCResize, XtRBoolean, sizeof(Boolean), - offset(label.resize), XtRImmediate, (XtPointer)True}, + { + XtNforeground, + XtCForeground, + XtRPixel, + sizeof(Pixel), + offset(label.foreground), + XtRString, + XtDefaultForeground + }, + { + XtNfont, + XtCFont, + XtRFontStruct, + sizeof(XFontStruct*), + offset(label.font), + XtRString, + XtDefaultFont + }, + { + XtNfontSet, + XtCFontSet, + XtRFontSet, + sizeof(XFontSet), + offset(label.fontset), + XtRString, + XtDefaultFontSet + }, + { + XtNlabel, + XtCLabel, + XtRString, + sizeof(String), + offset(label.label), + XtRString, + NULL + }, + { + XtNencoding, + XtCEncoding, + XtRUnsignedChar, + sizeof(unsigned char), + offset(label.encoding), + XtRImmediate, + (XtPointer)XawTextEncoding8bit + }, + { + XtNjustify, + XtCJustify, + XtRJustify, + sizeof(XtJustify), + offset(label.justify), + XtRImmediate, + (XtPointer)XtJustifyCenter + }, + { + XtNinternalWidth, + XtCWidth, + XtRDimension, + sizeof(Dimension), + offset(label.internal_width), + XtRImmediate, + (XtPointer)4 + }, + { + XtNinternalHeight, + XtCHeight, + XtRDimension, + sizeof(Dimension), + offset(label.internal_height), + XtRImmediate, + (XtPointer)2 + }, + { + XtNleftBitmap, + XtCLeftBitmap, + XtRBitmap, + sizeof(Pixmap), + offset(label.left_bitmap), + XtRImmediate, + (XtPointer)None + }, + { + XtNbitmap, + XtCPixmap, + XtRBitmap, + sizeof(Pixmap), + offset(label.pixmap), + XtRImmediate, + (XtPointer)None + }, + { + XtNresize, + XtCResize, + XtRBoolean, + sizeof(Boolean), + offset(label.resize), + XtRImmediate, + (XtPointer)True + }, + { + XtNlabelX, + XtCPosition, + XtRPosition, + sizeof(Position), + offset(label.label_x), + XtRImmediate, + (XtPointer)0 + }, + { + XtNlabelY, + XtCPosition, + XtRPosition, + sizeof(Position), + offset(label.label_y), + XtRImmediate, + (XtPointer)0 + }, }; #undef offset -static void Initialize(); -static void Resize(); -static void Redisplay(); -static Boolean SetValues(); -static void ClassInitialize(); -static void Destroy(); -static XtGeometryResult QueryGeometry(); - +#define Superclass (&simpleClassRec) LabelClassRec labelClassRec = { + /* core */ { -/* core_class fields */ - /* superclass */ (WidgetClass) &simpleClassRec, - /* class_name */ "Label", - /* widget_size */ sizeof(LabelRec), - /* class_initialize */ ClassInitialize, - /* class_part_initialize */ NULL, - /* class_inited */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* realize */ XtInheritRealize, - /* actions */ NULL, - /* num_actions */ 0, - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure */ TRUE, - /* compress_enterleave */ TRUE, - /* visible_interest */ FALSE, - /* destroy */ Destroy, - /* resize */ Resize, - /* expose */ Redisplay, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* set_values_almost */ XtInheritSetValuesAlmost, - /* get_values_hook */ NULL, - /* accept_focus */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ NULL, - /* query_geometry */ QueryGeometry, - /* display_accelerator */ XtInheritDisplayAccelerator, - /* extension */ NULL + (WidgetClass)&simpleClassRec, /* superclass */ + "Label", /* class_name */ + sizeof(LabelRec), /* widget_size */ + XawLabelClassInitialize, /* class_initialize */ + NULL, /* class_part_initialize */ + False, /* class_inited */ + XawLabelInitialize, /* initialize */ + NULL, /* initialize_hook */ + XtInheritRealize, /* realize */ + NULL, /* actions */ + 0, /* num_actions */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + True, /* compress_motion */ + True, /* compress_exposure */ + True, /* compress_enterleave */ + False, /* visible_interest */ + XawLabelDestroy, /* destroy */ + XawLabelResize, /* resize */ + XawLabelRedisplay, /* expose */ + XawLabelSetValues, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + NULL, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + NULL, /* tm_table */ + XawLabelQueryGeometry, /* query_geometry */ + XtInheritDisplayAccelerator, /* display_accelerator */ + NULL, /* extension */ }, -/* Simple class fields initialization */ + /* simple */ { - /* change_sensitive */ XtInheritChangeSensitive + XtInheritChangeSensitive, /* change_sensitive */ }, -/* Label class fields initialization */ + /* label */ { - /* ignore */ 0 + NULL, /* extension */ } }; + WidgetClass labelWidgetClass = (WidgetClass)&labelClassRec; -/**************************************************************** - * - * Private Procedures - * - ****************************************************************/ -static void ClassInitialize() +/* + * Implementation + */ +static void +XawLabelClassInitialize(void) { XawInitializeWidgetSet(); - XtAddConverter( XtRString, XtRJustify, XmuCvtStringToJustify, - (XtConvertArgList)NULL, 0 ); + XtAddConverter(XtRString, XtRJustify, XmuCvtStringToJustify, NULL, 0); + XtSetTypeConverter(XtRJustify, XtRString, XmuCvtJustifyToString, + NULL, 0, XtCacheNone, NULL); } #ifndef WORD64 - #define TXT16 XChar2b - #else - #define TXT16 char static XChar2b *buf2b; static int buf2blen = 0; -_XawLabelWidth16(fs, str, n) - XFontStruct *fs; - char *str; - int n; +static int +_XawLabelWidth16(XFontStruct *fs, char *str, int n) { int i; XChar2b *ptr; @@ -206,16 +303,13 @@ _XawLabelWidth16(fs, str, n) ptr->byte1 = *str++; ptr->byte2 = *str++; } - return XTextWidth16(fs, buf2b, n); + + return (XTextWidth16(fs, buf2b, n)); } -_XawLabelDraw16(dpy, d, gc, x, y, str, n) - Display *dpy; - Drawable d; - GC gc; - int x, y; - char *str; - int n; +static void +_XawLabelDraw16(Display *dpy, Drawable d, GC gc, int x, int y, + char *str, int n) { int i; XChar2b *ptr; @@ -233,119 +327,117 @@ _XawLabelDraw16(dpy, d, gc, x, y, str, n) #define XTextWidth16 _XawLabelWidth16 #define XDrawString16 _XawLabelDraw16 - #endif /* WORD64 */ /* * Calculate width and height of displayed text in pixels */ - -static void SetTextWidthAndHeight(lw) - LabelWidget lw; +static void +SetTextWidthAndHeight(LabelWidget lw) { XFontStruct *fs = lw->label.font; - char *nl; if (lw->label.pixmap != None) { Window root; int x, y; unsigned int width, height, bw, depth; + if (XGetGeometry(XtDisplay(lw), lw->label.pixmap, &root, &x, &y, - &width, &height, &bw, &depth)) { + &width, &height, &bw, &depth)) { lw->label.label_height = height; lw->label.label_width = width; lw->label.label_len = depth; return; } } - if ( lw->simple.international == True ) { - - XFontSet fset = lw->label.fontset; - XFontSetExtents *ext = XExtentsOfFontSet(fset); - - lw->label.label_height = ext->max_ink_extent.height; - if (lw->label.label == NULL) { - lw->label.label_len = 0; - lw->label.label_width = 0; - } - else if ((nl = index(lw->label.label, '\n')) != NULL) { - char *label; - lw->label.label_len = MULTI_LINE_LABEL; - lw->label.label_width = 0; - for (label = lw->label.label; nl != NULL; nl = index(label, '\n')) { - int width = XmbTextEscapement(fset, label, (int)(nl - label)); - - if (width > (int)lw->label.label_width) - lw->label.label_width = width; - label = nl + 1; - if (*label) - lw->label.label_height += - ext->max_ink_extent.height; - } - if (*label) { - int width = XmbTextEscapement(fset, label, strlen(label)); - - if (width > (int) lw->label.label_width) - lw->label.label_width = width; - } - } else { - lw->label.label_len = strlen(lw->label.label); - lw->label.label_width = - XmbTextEscapement(fset, lw->label.label, (int) lw->label.label_len); - } - - } else { - - lw->label.label_height = fs->max_bounds.ascent + fs->max_bounds.descent; - if (lw->label.label == NULL) { - lw->label.label_len = 0; - lw->label.label_width = 0; - } - else if ((nl = index(lw->label.label, '\n')) != NULL) { + if (lw->simple.international == True) { + XFontSet fset = lw->label.fontset; + XFontSetExtents *ext = XExtentsOfFontSet(fset); + + lw->label.label_height = ext->max_ink_extent.height; + if (lw->label.label == NULL) { + lw->label.label_len = 0; + lw->label.label_width = 0; + } + else if ((nl = index(lw->label.label, '\n')) != NULL) { char *label; - lw->label.label_len = MULTI_LINE_LABEL; - lw->label.label_width = 0; - for (label = lw->label.label; nl != NULL; nl = index(label, '\n')) { - int width; - - if (lw->label.encoding) - width = XTextWidth16(fs, (TXT16*)label, (int)(nl - label)/2); - else + + lw->label.label_len = MULTI_LINE_LABEL; + lw->label.label_width = 0; + for (label = lw->label.label; nl != NULL; nl = index(label, '\n')) { + int width = XmbTextEscapement(fset, label, (int)(nl - label)); + + if (width > (int)lw->label.label_width) + lw->label.label_width = width; + label = nl + 1; + if (*label) + lw->label.label_height += ext->max_ink_extent.height; + } + if (*label) { + int width = XmbTextEscapement(fset, label, strlen(label)); + + if (width > (int)lw->label.label_width) + lw->label.label_width = width; + } + } + else { + lw->label.label_len = strlen(lw->label.label); + lw->label.label_width = + XmbTextEscapement(fset, lw->label.label, lw->label.label_len); + } + } + else { + lw->label.label_height = fs->max_bounds.ascent + fs->max_bounds.descent; + if (lw->label.label == NULL) { + lw->label.label_len = 0; + lw->label.label_width = 0; + } + else if ((nl = index(lw->label.label, '\n')) != NULL) { + char *label; + + lw->label.label_len = MULTI_LINE_LABEL; + lw->label.label_width = 0; + for (label = lw->label.label; nl != NULL; nl = index(label, '\n')) { + int width; + + if (lw->label.encoding) + width = XTextWidth16(fs, (TXT16*)label, (int)(nl - label) / 2); + else width = XTextWidth(fs, label, (int)(nl - label)); - if (width > (int)lw->label.label_width) + if (width > (int)lw->label.label_width) lw->label.label_width = width; - label = nl + 1; - if (*label) + label = nl + 1; + if (*label) lw->label.label_height += - fs->max_bounds.ascent + fs->max_bounds.descent; + fs->max_bounds.ascent + fs->max_bounds.descent; } if (*label) { - int width = XTextWidth(fs, label, strlen(label)); + int width = XTextWidth(fs, label, strlen(label)); - if (lw->label.encoding) - width = XTextWidth16(fs, (TXT16*)label, (int)strlen(label)/2); - else + if (lw->label.encoding) + width = XTextWidth16(fs, (TXT16*)label, strlen(label) / 2); + else width = XTextWidth(fs, label, strlen(label)); - if (width > (int) lw->label.label_width) + if (width > (int) lw->label.label_width) lw->label.label_width = width; } - } else { + } + else { lw->label.label_len = strlen(lw->label.label); if (lw->label.encoding) - lw->label.label_width = + lw->label.label_width = XTextWidth16(fs, (TXT16*)lw->label.label, - (int) lw->label.label_len/2); + (int)lw->label.label_len / 2); else - lw->label.label_width = - XTextWidth(fs, lw->label.label, (int) lw->label.label_len); - } - + lw->label.label_width = + XTextWidth(fs, lw->label.label, (int)lw->label.label_len); + } } } -static void GetnormalGC(lw) - LabelWidget lw; +static void +GetNormalGC(LabelWidget lw) { XGCValues values; @@ -354,21 +446,20 @@ static void GetnormalGC(lw) values.font = lw->label.font->fid; values.graphics_exposures = False; - if ( lw->simple.international == True ) - /* Since Xmb/wcDrawString eats the font, I must use XtAllocateGC. */ - lw->label.normal_GC = XtAllocateGC( - (Widget)lw, 0, - (unsigned) GCForeground | GCBackground | GCGraphicsExposures, - &values, GCFont, 0 ); + if (lw->simple.international == True) + /* Since Xmb/wcDrawString eats the font, I must use XtAllocateGC */ + lw->label.normal_GC = XtAllocateGC((Widget)lw, 0, + GCForeground | GCBackground | + GCGraphicsExposures, + &values, GCFont, 0); else - lw->label.normal_GC = XtGetGC( - (Widget)lw, - (unsigned) GCForeground | GCBackground | GCFont | GCGraphicsExposures, - &values); + lw->label.normal_GC = XtGetGC((Widget)lw, + GCForeground | GCBackground | GCFont | + GCGraphicsExposures, &values); } -static void GetgrayGC(lw) - LabelWidget lw; +static void +GetGrayGC(LabelWidget lw) { XGCValues values; @@ -383,119 +474,90 @@ static void GetgrayGC(lw) values.graphics_exposures = False; lw->label.stipple = values.tile; - if ( lw->simple.international == True ) - /* Since Xmb/wcDrawString eats the font, I must use XtAllocateGC. */ - lw->label.gray_GC = XtAllocateGC((Widget)lw, 0, - (unsigned) GCForeground | GCBackground | - GCTile | GCFillStyle | - GCGraphicsExposures, - &values, GCFont, 0); - else - lw->label.gray_GC = XtGetGC((Widget)lw, - (unsigned) GCForeground | GCBackground | - GCFont | GCTile | GCFillStyle | - GCGraphicsExposures, - &values); + if (lw->simple.international == True) + /* Since Xmb/wcDrawString eats the font, I must use XtAllocateGC */ + lw->label.gray_GC = XtAllocateGC((Widget)lw, 0, + GCForeground | GCBackground | + GCTile | GCFillStyle | + GCGraphicsExposures, + &values, GCFont, 0); + else + lw->label.gray_GC = XtGetGC((Widget)lw, + GCForeground | GCBackground | + GCFont | GCTile | GCFillStyle | + GCGraphicsExposures, + &values); } -static void compute_bitmap_offsets (lw) - LabelWidget lw; +static void +compute_bitmap_offsets(LabelWidget lw) { /* * bitmap will be eventually be displayed at * (internal_width, internal_height + lbm_y) */ - if (lw->label.lbm_height != 0) { - lw->label.lbm_y = (lw->core.height - - (lw->label.internal_height * 2 + + if (lw->label.lbm_height != 0) + lw->label.lbm_y = (XtHeight(lw) - (lw->label.internal_height * 2 + lw->label.lbm_height)) / 2; - } else { + else lw->label.lbm_y = 0; - } } - -static void set_bitmap_info (lw) - LabelWidget lw; +static void +set_bitmap_info(LabelWidget lw) { Window root; int x, y; unsigned int bw, depth; - if (!(lw->label.left_bitmap && - XGetGeometry (XtDisplay(lw), lw->label.left_bitmap, &root, &x, &y, + if (!(lw->label.left_bitmap + && XGetGeometry(XtDisplay(lw), lw->label.left_bitmap, &root, &x, &y, &lw->label.lbm_width, &lw->label.lbm_height, - &bw, &depth))) { + &bw, &depth))) lw->label.lbm_width = lw->label.lbm_height = 0; - } - compute_bitmap_offsets (lw); -} - + compute_bitmap_offsets(lw); +} -/* ARGSUSED */ -static void Initialize(request, new, args, num_args) - Widget request, new; - ArgList args; - Cardinal *num_args; +/*ARGSUSED*/ +static void +XawLabelInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - LabelWidget lw = (LabelWidget) new; + LabelWidget lw = (LabelWidget)cnew; if (lw->label.label == NULL) - lw->label.label = XtNewString(lw->core.name); - else { - lw->label.label = XtNewString(lw->label.label); - } + lw->label.label = XtNewString(lw->core.name); + else + lw->label.label = XtNewString(lw->label.label); - GetnormalGC(lw); - GetgrayGC(lw); + GetNormalGC(lw); + GetGrayGC(lw); SetTextWidthAndHeight(lw); - if (lw->core.height == 0) - lw->core.height = lw->label.label_height + - 2 * lw->label.internal_height; + if (XtHeight(lw) == 0) + XtHeight(lw) = lw->label.label_height + 2 * lw->label.internal_height; - set_bitmap_info (lw); /* need core.height */ + set_bitmap_info(lw); /* need core.height */ - if (lw->core.width == 0) /* need label.lbm_width */ - lw->core.width = (lw->label.label_width + - 2 * lw->label.internal_width + - LEFT_OFFSET(lw)); + if (XtWidth(lw) == 0) /* need label.lbm_width */ + XtWidth(lw) = lw->label.label_width + 2 * lw->label.internal_width + + LEFT_OFFSET(lw); lw->label.label_x = lw->label.label_y = 0; - (*XtClass(new)->core_class.resize) ((Widget)lw); - -} /* Initialize */ - -/* - * Repaint the widget window - */ + (*XtClass(cnew)->core_class.resize)((Widget)lw); +} -/* ARGSUSED */ -static void Redisplay(gw, event, region) - Widget gw; - XEvent *event; - Region region; +/*ARGSUSED*/ +static void +XawLabelRedisplay(Widget gw, XEvent *event, Region region) { - LabelWidget w = (LabelWidget) gw; + LabelWidget w = (LabelWidget)gw; GC gc; - /* - * now we'll see if we need to draw the rest of the label - */ - if (region != NULL) { - int x = w->label.label_x; - unsigned int width = w->label.label_width; - if (w->label.lbm_width) { - if (w->label.label_x > (x = w->label.internal_width)) - width += w->label.label_x - x; - } - if (XRectInRegion(region, x, w->label.label_y, - width, w->label.label_height) == RectangleOut){ - return; - } - } + if (*Superclass->core_class.expose != NULL) + (*Superclass->core_class.expose)(gw, event, region); gc = XtIsSensitive(gw) ? w->label.normal_GC : w->label.gray_GC; #ifdef notdef @@ -507,75 +569,72 @@ static void Redisplay(gw, event, region) int len = w->label.label_len; char *label = w->label.label; Position y = w->label.label_y + w->label.font->max_bounds.ascent; - Position ksy = w->label.label_y; + Position ksy = w->label.label_y; /* display left bitmap */ - if (w->label.left_bitmap && w->label.lbm_width != 0) { + if (w->label.left_bitmap && w->label.lbm_width != 0) XCopyPlane (XtDisplay(gw), w->label.left_bitmap, XtWindow(gw), gc, - 0, 0, w->label.lbm_width, w->label.lbm_height, - (int) w->label.internal_width, - (int) w->label.internal_height + w->label.lbm_y, - (unsigned long) 1L); - } - - if ( w->simple.international == True ) { + 0, 0, w->label.lbm_width, w->label.lbm_height, + w->label.internal_width, + w->label.internal_height + w->label.lbm_y, 1L); + if (w->simple.international == True) { XFontSetExtents *ext = XExtentsOfFontSet(w->label.fontset); - ksy += abs(ext->max_ink_extent.y); - - if (len == MULTI_LINE_LABEL) { - char *nl; - while ((nl = index(label, '\n')) != NULL) { - XmbDrawString(XtDisplay(w), XtWindow(w), w->label.fontset, gc, - w->label.label_x, ksy, label, (int)(nl - label)); - ksy += ext->max_ink_extent.height; - label = nl + 1; - } - len = strlen(label); - } - if (len) - XmbDrawString(XtDisplay(w), XtWindow(w), w->label.fontset, gc, - w->label.label_x, ksy, label, len); + ksy += XawAbs(ext->max_ink_extent.y); - } else { /*international false, so use R5 routine */ + if (len == MULTI_LINE_LABEL) { + char *nl; + while ((nl = index(label, '\n')) != NULL) { + XmbDrawString(XtDisplay(w), XtWindow(w), w->label.fontset, + gc, w->label.label_x, ksy, label, + (int)(nl - label)); + ksy += ext->max_ink_extent.height; + label = nl + 1; + } + len = strlen(label); + } + if (len) + XmbDrawString(XtDisplay(w), XtWindow(w), w->label.fontset, gc, + w->label.label_x, ksy, label, len); + } + else { if (len == MULTI_LINE_LABEL) { - char *nl; - while ((nl = index(label, '\n')) != NULL) { + char *nl; + + while ((nl = index(label, '\n')) != NULL) { if (w->label.encoding) - XDrawString16(XtDisplay(gw), XtWindow(gw), gc, - w->label.label_x, y, - (TXT16*)label, (int)(nl - label)/2); + XDrawString16(XtDisplay(gw), XtWindow(gw), gc, + w->label.label_x, y, + (TXT16*)label, (int)(nl - label) / 2); else - XDrawString(XtDisplay(gw), XtWindow(gw), gc, - w->label.label_x, y, label, (int)(nl - label)); + XDrawString(XtDisplay(gw), XtWindow(gw), gc, + w->label.label_x, y, label, (int)(nl - label)); y += w->label.font->max_bounds.ascent + - w->label.font->max_bounds.descent; + w->label.font->max_bounds.descent; label = nl + 1; - } - len = strlen(label); + } + len = strlen(label); } if (len) { - if (w->label.encoding) + if (w->label.encoding) XDrawString16(XtDisplay(gw), XtWindow(gw), gc, - w->label.label_x, y, (TXT16*)label, len/2); - else + w->label.label_x, y, (TXT16*)label, len / 2); + else XDrawString(XtDisplay(gw), XtWindow(gw), gc, - w->label.label_x, y, label, len); + w->label.label_x, y, label, len); } - - } /*endif international*/ - - } else if (w->label.label_len == 1) { /* depth */ + } + } + else if (w->label.label_len == 1) XCopyPlane(XtDisplay(gw), w->label.pixmap, XtWindow(gw), gc, - 0, 0, w->label.label_width, w->label.label_height, - w->label.label_x, w->label.label_y, 1L); - } else { + 0, 0, w->label.label_width, w->label.label_height, + w->label.label_x, w->label.label_y, 1L); + else XCopyArea(XtDisplay(gw), w->label.pixmap, XtWindow(gw), gc, - 0, 0, w->label.label_width, w->label.label_height, - w->label.label_x, w->label.label_y); - } + 0, 0, w->label.label_width, w->label.label_height, + w->label.label_x, w->label.label_y); #ifdef notdef if (region != NULL) @@ -583,190 +642,176 @@ static void Redisplay(gw, event, region) #endif /* notdef */ } -static void _Reposition(lw, width, height, dx, dy) - LabelWidget lw; - Dimension width, height; - Position *dx, *dy; +static void +_Reposition(LabelWidget lw, unsigned int width, unsigned int height, + Position *dx, Position *dy) { Position newPos; Position leftedge = lw->label.internal_width + LEFT_OFFSET(lw); switch (lw->label.justify) { - - case XtJustifyLeft : + case XtJustifyLeft: newPos = leftedge; break; - - case XtJustifyRight : - newPos = width - - (lw->label.label_width + lw->label.internal_width); + case XtJustifyRight: + newPos = width - (lw->label.label_width + lw->label.internal_width); break; - - case XtJustifyCenter : + case XtJustifyCenter: + /*FALLTRHOUGH*/ default: - newPos = (int)(width - lw->label.label_width) / 2; + newPos = (int)(width - lw->label.label_width) >> 1; break; } if (newPos < (Position)leftedge) newPos = leftedge; *dx = newPos - lw->label.label_x; lw->label.label_x = newPos; - *dy = (newPos = (int)(height - lw->label.label_height) / 2) - - lw->label.label_y; + + newPos = (height - lw->label.label_height) >> 1; + *dy = newPos - lw->label.label_y; lw->label.label_y = newPos; - return; } -static void Resize(w) - Widget w; +static void +XawLabelResize(Widget w) { LabelWidget lw = (LabelWidget)w; Position dx, dy; - _Reposition(lw, w->core.width, w->core.height, &dx, &dy); - compute_bitmap_offsets (lw); + _Reposition(lw, XtWidth(w), XtHeight(w), &dx, &dy); + compute_bitmap_offsets(lw); } -/* - * Set specified arguments into widget - */ - #define PIXMAP 0 #define WIDTH 1 #define HEIGHT 2 #define NUM_CHECKS 3 - -static Boolean SetValues(current, request, new, args, num_args) - Widget current, request, new; - ArgList args; - Cardinal *num_args; +static Boolean +XawLabelSetValues(Widget current, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - LabelWidget curlw = (LabelWidget) current; - LabelWidget reqlw = (LabelWidget) request; - LabelWidget newlw = (LabelWidget) new; - int i; + LabelWidget curlw = (LabelWidget)current; + LabelWidget reqlw = (LabelWidget)request; + LabelWidget newlw = (LabelWidget)cnew; + unsigned int i; Boolean was_resized = False, redisplay = False, checks[NUM_CHECKS]; for (i = 0; i < NUM_CHECKS; i++) - checks[i] = FALSE; + checks[i] = False; for (i = 0; i < *num_args; i++) { if (streq(XtNbitmap, args[i].name)) - checks[PIXMAP] = TRUE; - if (streq(XtNwidth, args[i].name)) - checks[WIDTH] = TRUE; - if (streq(XtNheight, args[i].name)) - checks[HEIGHT] = TRUE; + checks[PIXMAP] = True; + else if (streq(XtNwidth, args[i].name)) + checks[WIDTH] = True; + else if (streq(XtNheight, args[i].name)) + checks[HEIGHT] = True; } - if (newlw->label.label == NULL) { + if (newlw->label.label == NULL) newlw->label.label = newlw->core.name; - } /* * resize on bitmap change */ - if (curlw->label.left_bitmap != newlw->label.left_bitmap) { + if (curlw->label.left_bitmap != newlw->label.left_bitmap) was_resized = True; - } if (curlw->label.encoding != newlw->label.encoding) was_resized = True; - if ( (curlw->label.fontset != newlw->label.fontset) && - curlw->simple.international ){ + if (curlw->label.fontset != newlw->label.fontset && + curlw->simple.international) was_resized = True; - } + if (curlw->label.label != newlw->label.label) { - if (curlw->label.label != curlw->core.name) - XtFree( (char *)curlw->label.label ); + if (curlw->label.label != curlw->core.name) + XtFree((char *)curlw->label.label); + + if (newlw->label.label != newlw->core.name) + newlw->label.label = XtNewString(newlw->label.label); - if (newlw->label.label != newlw->core.name) { - newlw->label.label = XtNewString( newlw->label.label ); - } was_resized = True; } if (was_resized || (curlw->label.font != newlw->label.font) || - (curlw->label.justify != newlw->label.justify) || checks[PIXMAP]) { - + curlw->label.justify != newlw->label.justify || checks[PIXMAP]) { SetTextWidthAndHeight(newlw); was_resized = True; } - /* recalculate the window size if something has changed. */ + /* recalculate the window size if something has changed */ if (newlw->label.resize && was_resized) { - if ((curlw->core.height == reqlw->core.height) && !checks[HEIGHT]) - newlw->core.height = (newlw->label.label_height + - 2 * newlw->label.internal_height); + if (XtHeight(curlw) == XtHeight(reqlw) && !checks[HEIGHT]) + XtHeight(newlw) = newlw->label.label_height + + (newlw->label.internal_height << 1); - set_bitmap_info (newlw); + set_bitmap_info(newlw); - if ((curlw->core.width == reqlw->core.width) && !checks[WIDTH]) - newlw->core.width = (newlw->label.label_width + - LEFT_OFFSET(newlw) + - 2 * newlw->label.internal_width); + if (XtWidth(curlw) == XtWidth(reqlw) && !checks[WIDTH]) + XtWidth(newlw) = newlw->label.label_width + LEFT_OFFSET(newlw) + + (newlw->label.internal_width << 1); } if (curlw->label.foreground != newlw->label.foreground || curlw->core.background_pixel != newlw->core.background_pixel - || curlw->label.font->fid != newlw->label.font->fid ) { - - /* The Fontset is not in the GC - don't make a new GC if FS changes! */ - - XtReleaseGC(new, curlw->label.normal_GC); - XtReleaseGC(new, curlw->label.gray_GC); - XmuReleaseStippledPixmap( XtScreen(current), curlw->label.stipple ); - GetnormalGC(newlw); - GetgrayGC(newlw); + || curlw->label.font->fid != newlw->label.font->fid) { + /* The Fontset is not in the GC - don't make a new GC if FS changes! */ + XtReleaseGC(cnew, curlw->label.normal_GC); + XtReleaseGC(cnew, curlw->label.gray_GC); + XmuReleaseStippledPixmap(XtScreen(current), curlw->label.stipple); + GetNormalGC(newlw); + GetGrayGC(newlw); redisplay = True; } - if ((curlw->label.internal_width != newlw->label.internal_width) - || (curlw->label.internal_height != newlw->label.internal_height) + if (curlw->label.label_x != newlw->label.label_x || + curlw->label.label_y != newlw->label.label_y) + redisplay = True; + + if (curlw->label.internal_width != newlw->label.internal_width + || curlw->label.internal_height != newlw->label.internal_height || was_resized) { /* Resize() will be called if geometry changes succeed */ Position dx, dy; - _Reposition(newlw, curlw->core.width, curlw->core.height, &dx, &dy); + + _Reposition(newlw, XtWidth(curlw), XtHeight(curlw), &dx, &dy); } - return was_resized || redisplay || - XtIsSensitive(current) != XtIsSensitive(new); + return (was_resized || redisplay || + XtIsSensitive(current) != XtIsSensitive(cnew)); } -static void Destroy(w) - Widget w; +static void +XawLabelDestroy(Widget w) { LabelWidget lw = (LabelWidget)w; - if ( lw->label.label != lw->core.name ) - XtFree( lw->label.label ); - XtReleaseGC( w, lw->label.normal_GC ); - XtReleaseGC( w, lw->label.gray_GC); - XmuReleaseStippledPixmap( XtScreen(w), lw->label.stipple ); + if (lw->label.label != lw->core.name) + XtFree(lw->label.label); + XtReleaseGC(w, lw->label.normal_GC); + XtReleaseGC(w, lw->label.gray_GC); + XmuReleaseStippledPixmap(XtScreen(w), lw->label.stipple); } - -static XtGeometryResult QueryGeometry(w, intended, preferred) - Widget w; - XtWidgetGeometry *intended, *preferred; +static XtGeometryResult +XawLabelQueryGeometry(Widget w, XtWidgetGeometry *intended, + XtWidgetGeometry *preferred) { LabelWidget lw = (LabelWidget)w; preferred->request_mode = CWWidth | CWHeight; - preferred->width = (lw->label.label_width + - 2 * lw->label.internal_width + - LEFT_OFFSET(lw)); - preferred->height = lw->label.label_height + - 2 * lw->label.internal_height; - if ( ((intended->request_mode & (CWWidth | CWHeight)) - == (CWWidth | CWHeight)) && - intended->width == preferred->width && - intended->height == preferred->height) - return XtGeometryYes; - else if (preferred->width == w->core.width && - preferred->height == w->core.height) - return XtGeometryNo; - else - return XtGeometryAlmost; + preferred->width = lw->label.label_width + + (lw->label.internal_width << 1) + LEFT_OFFSET(lw); + preferred->height = lw->label.label_height + + (lw->label.internal_height << 1); + + if (((intended->request_mode & (CWWidth | CWHeight)) == (CWWidth | CWHeight)) + && intended->width == preferred->width + && intended->height == preferred->height) + return (XtGeometryYes); + else if (preferred->width == XtWidth(w) && preferred->height == XtHeight(w)) + return (XtGeometryNo); + + return (XtGeometryAlmost); } @@ -23,6 +23,7 @@ Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/List.c,v 1.17 2001/12/14 19:54:40 dawes Exp $ */ /* * List.c - List widget @@ -37,171 +38,304 @@ in this Software without prior written authorization from The Open Group. #include <stdio.h> #include <ctype.h> - #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> - #include <X11/Xmu/Drawing.h> - -#include <X11/Xaw/XawInit.h> #include <X11/Xaw/ListP.h> - -/* These added so widget knows whether its height, width are user selected. -I also added the freedoms member of the list widget part. */ +#include <X11/Xaw/XawInit.h> +#include "Private.h" #define HeightLock 1 #define WidthLock 2 #define LongestLock 4 -#define HeightFree( w ) !(((ListWidget)(w))->list.freedoms & HeightLock ) -#define WidthFree( w ) !(((ListWidget)(w))->list.freedoms & WidthLock ) -#define LongestFree( w ) !(((ListWidget)(w))->list.freedoms & LongestLock ) +#define HeightFree(w) !(((ListWidget)(w))->list.freedoms & HeightLock) +#define WidthFree(w) !(((ListWidget)(w))->list.freedoms & WidthLock) +#define LongestFree(w) !(((ListWidget)(w))->list.freedoms & LongestLock) -/* - * Default Translation table. - */ +#define MaxSize 32767 -static char defaultTranslations[] = - "<Btn1Down>: Set()\n\ - <Btn1Up>: Notify()"; +/* + * Class Methods + */ +static void XawListDestroy(Widget); +static void XawListInitialize(Widget, Widget, ArgList, Cardinal*); +static XtGeometryResult XawListQueryGeometry(Widget, XtWidgetGeometry*, + XtWidgetGeometry*); +static void XawListRedisplay(Widget, XEvent*, Region); +static void XawListResize(Widget); +static Boolean XawListSetValues(Widget, Widget, Widget, ArgList, Cardinal*); -/**************************************************************** - * - * Full class record constant - * - ****************************************************************/ +/* + * Prototypes + */ +static void CalculatedValues(Widget); +static void ChangeSize(Widget, unsigned int, unsigned int); +static void ClipToShadowInteriorAndLongest(ListWidget, GC*, unsigned int); +static int CvtToItem(Widget, int, int, int*); +static void FindCornerItems(Widget, XEvent*, int*, int*); +static void GetGCs(Widget); +static void HighlightBackground(Widget, int, int, GC); +static Bool ItemInRectangle(Widget, int, int, int); +static Bool Layout(Widget, Bool, Bool, Dimension*, Dimension*); +static void PaintItemName(Widget, int); +static void ResetList(Widget, Bool, Bool); -/* Private Data */ +/* + * Actions + */ +static void Notify(Widget, XEvent*, String*, Cardinal*); +static void Set(Widget, XEvent*, String*, Cardinal*); +static void Unset(Widget, XEvent*, String*, Cardinal*); -#define offset(field) XtOffset(ListWidget, field) +/* + * Initialization + */ +static char defaultTranslations[] = +"<Btn1Down>:" "Set()\n" +"<Btn1Up>:" "Notify()\n" +; +#define offset(field) XtOffsetOf(ListRec, field) static XtResource resources[] = { - {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), - offset(list.foreground), XtRString, XtDefaultForeground}, - {XtNcursor, XtCCursor, XtRCursor, sizeof(Cursor), - offset(simple.cursor), XtRString, "left_ptr"}, - {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *), - offset(list.font),XtRString, XtDefaultFont}, - {XtNfontSet, XtCFontSet, XtRFontSet, sizeof(XFontSet ), - offset(list.fontset),XtRString, XtDefaultFontSet}, - {XtNlist, XtCList, XtRPointer, sizeof(char **), - offset(list.list), XtRString, NULL}, - {XtNdefaultColumns, XtCColumns, XtRInt, sizeof(int), - offset(list.default_cols), XtRImmediate, (XtPointer)2}, - {XtNlongest, XtCLongest, XtRInt, sizeof(int), - offset(list.longest), XtRImmediate, (XtPointer)0}, - {XtNnumberStrings, XtCNumberStrings, XtRInt, sizeof(int), - offset(list.nitems), XtRImmediate, (XtPointer)0}, - {XtNpasteBuffer, XtCBoolean, XtRBoolean, sizeof(Boolean), - offset(list.paste), XtRImmediate, (XtPointer) False}, - {XtNforceColumns, XtCColumns, XtRBoolean, sizeof(Boolean), - offset(list.force_cols), XtRImmediate, (XtPointer) False}, - {XtNverticalList, XtCBoolean, XtRBoolean, sizeof(Boolean), - offset(list.vertical_cols), XtRImmediate, (XtPointer) False}, - {XtNinternalWidth, XtCWidth, XtRDimension, sizeof(Dimension), - offset(list.internal_width), XtRImmediate, (XtPointer)2}, - {XtNinternalHeight, XtCHeight, XtRDimension, sizeof(Dimension), - offset(list.internal_height), XtRImmediate, (XtPointer)2}, - {XtNcolumnSpacing, XtCSpacing, XtRDimension, sizeof(Dimension), - offset(list.column_space), XtRImmediate, (XtPointer)6}, - {XtNrowSpacing, XtCSpacing, XtRDimension, sizeof(Dimension), - offset(list.row_space), XtRImmediate, (XtPointer)2}, - {XtNcallback, XtCCallback, XtRCallback, sizeof(XtPointer), - offset(list.callback), XtRCallback, NULL}, + { + XtNforeground, + XtCForeground, + XtRPixel, + sizeof(Pixel), + offset(list.foreground), + XtRString, + XtDefaultForeground + }, + { + XtNcursor, + XtCCursor, + XtRCursor, + sizeof(Cursor), + offset(simple.cursor), + XtRString, + "left_ptr" + }, + { + XtNfont, + XtCFont, + XtRFontStruct, + sizeof(XFontStruct*), + offset(list.font), + XtRString, + XtDefaultFont + }, + { + XtNfontSet, + XtCFontSet, + XtRFontSet, + sizeof(XFontSet), + offset(list.fontset), + XtRString, + XtDefaultFontSet + }, + { + XtNlist, + XtCList, + XtRPointer, + sizeof(char**), + offset(list.list), +#ifdef notyet + XtRStringArray, +#else + XtRString, +#endif + NULL + }, + { + XtNdefaultColumns, + XtCColumns, + XtRInt, + sizeof(int), + offset(list.default_cols), + XtRImmediate, + (XtPointer)2 + }, + { + XtNlongest, + XtCLongest, + XtRInt, + sizeof(int), + offset(list.longest), + XtRImmediate, + (XtPointer)0 + }, + { + XtNnumberStrings, + XtCNumberStrings, + XtRInt, + sizeof(int), + offset(list.nitems), + XtRImmediate, + (XtPointer)0 + }, + { + XtNpasteBuffer, + XtCBoolean, + XtRBoolean, + sizeof(Boolean), + offset(list.paste), + XtRImmediate, + (XtPointer)False + }, + { + XtNforceColumns, + XtCColumns, + XtRBoolean, + sizeof(Boolean), + offset(list.force_cols), + XtRImmediate, + (XtPointer)False + }, + { + XtNverticalList, + XtCBoolean, + XtRBoolean, + sizeof(Boolean), + offset(list.vertical_cols), + XtRImmediate, + (XtPointer)False + }, + { + XtNinternalWidth, + XtCWidth, + XtRDimension, + sizeof(Dimension), + offset(list.internal_width), + XtRImmediate, + (XtPointer)2 + }, + { + XtNinternalHeight, + XtCHeight, + XtRDimension, + sizeof(Dimension), + offset(list.internal_height), + XtRImmediate, + (XtPointer)2 + }, + { + XtNcolumnSpacing, + XtCSpacing, + XtRDimension, + sizeof(Dimension), + offset(list.column_space), + XtRImmediate, + (XtPointer)6 + }, + { + XtNrowSpacing, + XtCSpacing, + XtRDimension, + sizeof(Dimension), + offset(list.row_space), + XtRImmediate, + (XtPointer)2 + }, + { + XtNcallback, + XtCCallback, + XtRCallback, + sizeof(XtPointer), + offset(list.callback), + XtRCallback, + NULL + }, +#ifndef OLDXAW + { + XtNshowCurrent, + XtCBoolean, + XtRBoolean, + sizeof(Boolean), + offset(list.show_current), + XtRImmediate, + (XtPointer)False + }, +#endif }; - -static void Initialize(); -static void ChangeSize(); -static void Resize(); -static void Redisplay(); -static void Destroy(); -static Boolean Layout(); -static XtGeometryResult PreferredGeom(); -static Boolean SetValues(); -static void Notify(), Set(), Unset(); +#undef offset static XtActionsRec actions[] = { - {"Notify", Notify}, - {"Set", Set}, - {"Unset", Unset}, + {"Notify", Notify}, + {"Set", Set}, + {"Unset", Unset}, }; +#define Superclass (&simpleClassRec) ListClassRec listClassRec = { + /* core */ { -/* core_class fields */ - /* superclass */ (WidgetClass) &simpleClassRec, - /* class_name */ "List", - /* widget_size */ sizeof(ListRec), - /* class_initialize */ XawInitializeWidgetSet, - /* class_part_initialize */ NULL, - /* class_inited */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* realize */ XtInheritRealize, - /* actions */ actions, - /* num_actions */ XtNumber(actions), - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure */ FALSE, - /* compress_enterleave */ TRUE, - /* visible_interest */ FALSE, - /* destroy */ Destroy, - /* resize */ Resize, - /* expose */ Redisplay, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* set_values_almost */ XtInheritSetValuesAlmost, - /* get_values_hook */ NULL, - /* accept_focus */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ defaultTranslations, - /* query_geometry */ PreferredGeom, + (WidgetClass)Superclass, /* superclass */ + "List", /* class_name */ + sizeof(ListRec), /* widget_size */ + XawInitializeWidgetSet, /* class_initialize */ + NULL, /* class_part_initialize */ + False, /* class_inited */ + XawListInitialize, /* initialize */ + NULL, /* initialize_hook */ + XtInheritRealize, /* realize */ + actions, /* actions */ + XtNumber(actions), /* num_actions */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + True, /* compress_motion */ + False, /* compress_exposure */ + True, /* compress_enterleave */ + False, /* visible_interest */ + XawListDestroy, /* destroy */ + XawListResize, /* resize */ + XawListRedisplay, /* expose */ + XawListSetValues, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + NULL, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + defaultTranslations, /* tm_table */ + XawListQueryGeometry, /* query_geometry */ }, -/* Simple class fields initialization */ + /* simple */ { - /* change_sensitive */ XtInheritChangeSensitive + XtInheritChangeSensitive, /* change_sensitive */ }, -/* List class fields initialization */ + /* list */ { - /* not used */ 0 + NULL, /* extension */ }, }; WidgetClass listWidgetClass = (WidgetClass)&listClassRec; -/**************************************************************** - * - * Private Procedures - * - ****************************************************************/ - -static void GetGCs(w) -Widget w; +/* + * Implementation + */ +static void +GetGCs(Widget w) { XGCValues values; - ListWidget lw = (ListWidget) w; + ListWidget lw = (ListWidget)w; values.foreground = lw->list.foreground; values.font = lw->list.font->fid; - if ( lw->simple.international == True ) - lw->list.normgc = XtAllocateGC( w, 0, (unsigned) GCForeground, - &values, GCFont, 0 ); + if (lw->simple.international == True) + lw->list.normgc = XtAllocateGC(w, 0, GCForeground, &values, GCFont, 0); else - lw->list.normgc = XtGetGC( w, (unsigned) GCForeground | GCFont, - &values); + lw->list.normgc = XtGetGC(w, GCForeground | GCFont, &values); values.foreground = lw->core.background_pixel; - if ( lw->simple.international == True ) - lw->list.revgc = XtAllocateGC( w, 0, (unsigned) GCForeground, - &values, GCFont, 0 ); + if (lw->simple.international == True) + lw->list.revgc = XtAllocateGC(w, 0, GCForeground, &values, GCFont, 0); else - lw->list.revgc = XtGetGC( w, (unsigned) GCForeground | GCFont, - &values); + lw->list.revgc = XtGetGC(w, GCForeground | GCFont, &values); values.tile = XmuCreateStippledPixmap(XtScreen(w), lw->list.foreground, @@ -209,97 +343,94 @@ Widget w; lw->core.depth); values.fill_style = FillTiled; - if ( lw->simple.international == True ) - lw->list.graygc = XtAllocateGC( w, 0, (unsigned) GCTile | GCFillStyle, - &values, GCFont, 0 ); + if (lw->simple.international == True) + lw->list.graygc = XtAllocateGC(w, 0, GCTile | GCFillStyle, + &values, GCFont, 0); else - lw->list.graygc = XtGetGC( w, (unsigned) GCFont | GCTile | GCFillStyle, - &values); + lw->list.graygc = XtGetGC(w, GCFont | GCTile | GCFillStyle, &values); } - -/* CalculatedValues() - * - * does routine checks/computations that must be done after data changes - * but won't hurt if accidently called - * - * These calculations were needed in SetValues. They were in ResetList. - * ResetList called ChangeSize, which made an XtGeometryRequest. You - * MAY NOT change your geometry from within a SetValues. (Xt man, - * sect. 9.7.2) So, I factored these changes out. */ - -static void CalculatedValues( w ) -Widget w; +static void +CalculatedValues(Widget w) { int i, len; + ListWidget lw = (ListWidget)w; - ListWidget lw = (ListWidget) w; - - /* If list is NULL then the list will just be the name of the widget. */ - + /* If list is NULL then the list will just be the name of the widget */ if (lw->list.list == NULL) { - lw->list.list = &(lw->core.name); - lw->list.nitems = 1; + lw->list.list = &lw->core.name; + lw->list.nitems = 1; } - /* Get number of items. */ - + /* Get number of items */ if (lw->list.nitems == 0) - for ( ; lw->list.list[lw->list.nitems] != NULL ; lw->list.nitems++); - - /* Get column width. */ - - if ( LongestFree( lw ) ) { + for (; lw->list.list[lw->list.nitems] != NULL ; lw->list.nitems++) + ; - lw->list.longest = 0; /* so it will accumulate real longest below */ + /* Get column width */ + if (LongestFree(lw)) { + lw->list.longest = 0; /* so it will accumulate real longest below */ - for ( i = 0 ; i < lw->list.nitems; i++) { - if ( lw->simple.international == True ) - len = XmbTextEscapement(lw->list.fontset, lw->list.list[i], - strlen(lw->list.list[i])); - else - len = XTextWidth(lw->list.font, lw->list.list[i], - strlen(lw->list.list[i])); - if (len > lw->list.longest) - lw->list.longest = len; - } + for (i = 0 ; i < lw->list.nitems; i++) { + if (lw->simple.international == True) + len = XmbTextEscapement(lw->list.fontset, lw->list.list[i], + strlen(lw->list.list[i])); + else + len = XTextWidth(lw->list.font, lw->list.list[i], + strlen(lw->list.list[i])); + if (len > lw->list.longest) + lw->list.longest = len; + } } lw->list.col_width = lw->list.longest + lw->list.column_space; } -/* Function Name: ResetList - * Description: Resets the new list when important things change. - * Arguments: w - the widget. - * changex, changey - allow the height or width to change? +/* + * Function: + * ResetList + * + * Parameters: + * w - list widget + * changex - allow the height or width to change? + * changey - "" * - * Returns: TRUE if width or height have been changed + * Description: + * Resets the new list when important things change. + * + * Returns: + * True if width or height have been changed */ - static void -ResetList( w, changex, changey ) -Widget w; -Boolean changex, changey; +ResetList(Widget w, Bool changex, Bool changey) { - Dimension width = w->core.width; - Dimension height = w->core.height; + Dimension width = XtWidth(w); + Dimension height = XtHeight(w); - CalculatedValues( w ); + CalculatedValues(w); - if( Layout( w, changex, changey, &width, &height ) ) - ChangeSize( w, width, height ); + if (Layout(w, changex, changey, &width, &height)) { + if (XtIsComposite(XtParent(w))) + ChangeSize(w, width, height); + else { + XtWidth(w) = width; + XtHeight(w) = height; + } + } } -/* Function Name: ChangeSize. - * Description: Laysout the widget. - * Arguments: w - the widget to try change the size of. - * Returns: none. +/* + * Function: + * ChangeSize + * + * Parameters: + * w - widget to try change the size of + * + * Description: + * Laysout the widget. */ - static void -ChangeSize(w, width, height) -Widget w; -Dimension width, height; +ChangeSize(Widget w, unsigned int width, unsigned int height) { XtWidgetGeometry request, reply; @@ -307,144 +438,134 @@ Dimension width, height; request.width = width; request.height = height; - switch ( XtMakeGeometryRequest(w, &request, &reply) ) { - case XtGeometryYes: - break; - case XtGeometryNo: - break; - case XtGeometryAlmost: - Layout(w, (request.height != reply.height), - (request.width != reply.width), - &(reply.width), &(reply.height)); - request = reply; - switch (XtMakeGeometryRequest(w, &request, &reply) ) { + switch (XtMakeGeometryRequest(w, &request, &reply)) { case XtGeometryYes: case XtGeometryNo: break; case XtGeometryAlmost: + Layout(w, request.height != reply.height, + request.width != reply.width, &reply.width, &reply.height); request = reply; - Layout(w, FALSE, FALSE, &(request.width), &(request.height)); - request.request_mode = CWWidth | CWHeight; - XtMakeGeometryRequest(w, &request, &reply); - break; - default: - XtAppWarning(XtWidgetToApplicationContext(w), - "List Widget: Unknown geometry return."); - break; + switch (XtMakeGeometryRequest(w, &request, &reply)) { + case XtGeometryYes: + case XtGeometryNo: + break; + case XtGeometryAlmost: + request = reply; + Layout(w, False, False, &request.width, &request.height); + request.request_mode = CWWidth | CWHeight; + XtMakeGeometryRequest(w, &request, &reply); + /*FALLTROUGH*/ + default: + break; } - break; - default: - XtAppWarning(XtWidgetToApplicationContext(w), - "List Widget: Unknown geometry return."); - break; + /*FALLTROUGH*/ + default: + break; } } -/* Function Name: Initialize - * Description: Function that initilizes the widget instance. - * Arguments: junk - NOT USED. - * new - the new widget. - * Returns: none - */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -Initialize(junk, new, args, num_args) -Widget junk, new; -ArgList args; -Cardinal *num_args; +XawListInitialize(Widget temp1, Widget cnew, ArgList args, Cardinal *num_args) { - ListWidget lw = (ListWidget) new; - -/* - * Initialize all private resources. - */ + ListWidget lw = (ListWidget)cnew; + /* + * Initialize all private resources + */ /* record for posterity if we are free */ - lw->list.freedoms = (lw->core.width != 0) * WidthLock + - (lw->core.height != 0) * HeightLock + - (lw->list.longest != 0) * LongestLock; + lw->list.freedoms = ((XtWidth(lw) != 0) * WidthLock + + (XtHeight(lw) != 0) * HeightLock + + (lw->list.longest != 0) * LongestLock); - GetGCs(new); + GetGCs(cnew); - /* Set row height. based on font or fontset */ - - if (lw->simple.international == True ) - lw->list.row_height = - XExtentsOfFontSet(lw->list.fontset)->max_ink_extent.height - + lw->list.row_space; + /* Set row height, based on font or fontset */ + if (lw->simple.international == True) + lw->list.row_height = + XExtentsOfFontSet(lw->list.fontset)->max_ink_extent.height + + lw->list.row_space; else - lw->list.row_height = lw->list.font->max_bounds.ascent - + lw->list.font->max_bounds.descent - + lw->list.row_space; + lw->list.row_height = lw->list.font->max_bounds.ascent + + lw->list.font->max_bounds.descent + + lw->list.row_space; - ResetList( new, WidthFree( lw ), HeightFree( lw ) ); + ResetList(cnew, WidthFree(lw), HeightFree(lw)); lw->list.highlight = lw->list.is_highlighted = NO_HIGHLIGHT; +} -} /* Initialize */ - -/* Function Name: CvtToItem - * Description: Converts Xcoord to item number of item containing that - * point. - * Arguments: w - the list widget. - * xloc, yloc - x location, and y location. - * Returns: the item number. +/* + * Function: + * CvtToItem + * + * Parameters: + * w - list widget + * xloc - x location + * yloc - y location + * + * Description: + * Converts Xcoord to item number of item containing that point. + * + * Returns: + * Item number */ - static int -CvtToItem(w, xloc, yloc, item) -Widget w; -int xloc, yloc; -int *item; +CvtToItem(Widget w, int xloc, int yloc, int *item) { int one, another; - ListWidget lw = (ListWidget) w; + ListWidget lw = (ListWidget)w; int ret_val = OKAY; if (lw->list.vertical_cols) { - one = lw->list.nrows * ((xloc - (int) lw->list.internal_width) - / lw->list.col_width); - another = (yloc - (int) lw->list.internal_height) - / lw->list.row_height; - /* If out of range, return minimum possible value. */ + one = lw->list.nrows * ((xloc - (int)lw->list.internal_width) + / lw->list.col_width); + another = (yloc - (int)lw->list.internal_height) / lw->list.row_height; + /* If out of range, return minimum possible value */ if (another >= lw->list.nrows) { another = lw->list.nrows - 1; ret_val = OUT_OF_RANGE; } } else { - one = (lw->list.ncols * ((yloc - (int) lw->list.internal_height) - / lw->list.row_height)) ; - /* If in right margin handle things right. */ - another = (xloc - (int) lw->list.internal_width) / lw->list.col_width; + one = (lw->list.ncols * ((yloc - (int)lw->list.internal_height) + / lw->list.row_height)); + /* If in right margin handle things right */ + another = (xloc - (int)lw->list.internal_width) / lw->list.col_width; if (another >= lw->list.ncols) { another = lw->list.ncols - 1; ret_val = OUT_OF_RANGE; } } - if ((xloc < 0) || (yloc < 0)) - ret_val = OUT_OF_RANGE; - if (one < 0) one = 0; - if (another < 0) another = 0; + if (xloc < 0 || yloc < 0) + ret_val = OUT_OF_RANGE; + if (one < 0) + one = 0; + if (another < 0) + another = 0; *item = one + another; - if (*item >= lw->list.nitems) return(OUT_OF_RANGE); - return(ret_val); + if (*item >= lw->list.nitems) + return (OUT_OF_RANGE); + + return (ret_val); } -/* Function Name: FindCornerItems. - * Description: Find the corners of the rectangle in item space. - * Arguments: w - the list widget. - * event - the event structure that has the rectangle it it. - * ul_ret, lr_ret - the corners ** RETURNED **. - * Returns: none. +/* + * Function: + * FindCornerItems + * + * Arguments: + * w - list widget + * event - event structure that has the rectangle it it + * ul_ret - the corners (return) + * lr_ret - "" + * + * Description: + * Find the corners of the rectangle in item space. */ - static void -FindCornerItems(w, event, ul_ret, lr_ret) -Widget w; -XEvent * event; -int *ul_ret, *lr_ret; +FindCornerItems(Widget w, XEvent *event, int *ul_ret, int *lr_ret) { int xloc, yloc; @@ -456,36 +577,39 @@ int *ul_ret, *lr_ret; CvtToItem(w, xloc, yloc, lr_ret); } -/* Function Name: ItemInRectangle - * Description: returns TRUE if the item passed is in the given rectangle. - * Arguments: w - the list widget. - * ul, lr - corners of the rectangle in item space. - * item - item to check. - * Returns: TRUE if the item passed is in the given rectangle. +/* + * Function: + * ItemInRectangle + * + * Parameters: + * w - list widget + * ul - corners of the rectangle in item space + * lr - "" + * item - item to check + * + * Returns: + * True if the item passed is in the given rectangle */ - -static Boolean -ItemInRectangle(w, ul, lr, item) -Widget w; -int ul, lr, item; +static Bool +ItemInRectangle(Widget w, int ul, int lr, int item) { - ListWidget lw = (ListWidget) w; + ListWidget lw = (ListWidget)w; int mod_item; int things; if (item < ul || item > lr) - return(FALSE); + return (False); if (lw->list.vertical_cols) - things = lw->list.nrows; + things = lw->list.nrows; else - things = lw->list.ncols; + things = lw->list.ncols; mod_item = item % things; - if ( (mod_item >= ul % things) && (mod_item <= lr % things ) ) - return(TRUE); - return(FALSE); -} + if ((mod_item >= ul % things) && (mod_item <= lr % things)) + return (True); + return (False); +} /* HighlightBackground() * @@ -494,42 +618,37 @@ int ul, lr, item; * simple calculation and probably much faster than using Xlib and a clip mask. * * x, y - ul corner of the area item occupies. - * gc - the gc to use to paint this rectangle */ - + * gc - the gc to use to paint this rectangle + */ static void -HighlightBackground( w, x, y, gc ) -Widget w; -int x, y; -GC gc; +HighlightBackground(Widget w, int x, int y, GC gc) { - ListWidget lw = (ListWidget) w; - - /* easy to clip the rectangle by hand and probably alot faster than Xlib */ - - Dimension width = lw->list.col_width; - Dimension height = lw->list.row_height; - Dimension frame_limited_width = w->core.width - lw->list.internal_width - x; - Dimension frame_limited_height= w->core.height- lw->list.internal_height- y; + ListWidget lw = (ListWidget)w; + Dimension width = lw->list.col_width; + Dimension height = lw->list.row_height; + Dimension frame_limited_width = XtWidth(w) - lw->list.internal_width - x; + Dimension frame_limited_height= XtHeight(w) - lw->list.internal_height - y; /* Clip the rectangle width and height to the edge of the drawable area */ - - if ( width > frame_limited_width ) - width = frame_limited_width; - if ( height> frame_limited_height) - height = frame_limited_height; + if (width > frame_limited_width) + width = frame_limited_width; + if (height > frame_limited_height) + height = frame_limited_height; /* Clip the rectangle x and y to the edge of the drawable area */ - - if ( x < lw->list.internal_width ) { - width = width - ( lw->list.internal_width - x ); - x = lw->list.internal_width; + if (x < lw->list.internal_width) { + width = width - (lw->list.internal_width - x); + x = lw->list.internal_width; } - if ( y < lw->list.internal_height) { - height = height - ( lw->list.internal_height - x ); - y = lw->list.internal_height; + if (y < lw->list.internal_height) { + height = height - (lw->list.internal_height - y); + y = lw->list.internal_height; } - XFillRectangle( XtDisplay( w ), XtWindow( w ), gc, x, y, - width, height ); + + if (gc == lw->list.revgc && lw->core.background_pixmap != XtUnspecifiedPixmap) + XClearArea(XtDisplay(w), XtWindow(w), x, y, width, height, False); + else + XFillRectangle(XtDisplay(w), XtWindow(w), gc, x, y, width, height); } @@ -540,185 +659,159 @@ GC gc; * prevents erasing the shadow. It also clips against the value longest. * If the user doesn't set longest, this has no effect (as longest is the * maximum of all item lengths). If the user does specify, say, 80 pixel - * columns, though, this prevents items from overwriting other items. */ - -static void ClipToShadowInteriorAndLongest(lw, gc_p, x) - ListWidget lw; - GC* gc_p; - Dimension x; + * columns, though, this prevents items from overwriting other items. + */ +static void +ClipToShadowInteriorAndLongest(ListWidget lw, GC *gc_p, unsigned int x) { XRectangle rect; rect.x = x; rect.y = lw->list.internal_height; - rect.height = lw->core.height - lw->list.internal_height * 2; - rect.width = lw->core.width - lw->list.internal_width - x; - if ( rect.width > lw->list.longest ) - rect.width = lw->list.longest; + rect.height = XtHeight(lw) - (lw->list.internal_height << 1); + rect.width = XtWidth(lw) - lw->list.internal_width - x; + if (rect.width > lw->list.longest) + rect.width = lw->list.longest; - XSetClipRectangles( XtDisplay((Widget)lw),*gc_p,0,0,&rect,1,YXBanded ); + XSetClipRectangles(XtDisplay((Widget)lw), *gc_p, 0, 0, &rect, 1, YXBanded); } - -/* PaintItemName() - * - * paints the name of the item in the appropriate location. - * w - the list widget. - * item - the item to draw. - * - * NOTE: no action taken on an unrealized widget. */ - static void -PaintItemName(w, item) -Widget w; -int item; +PaintItemName(Widget w, int item) { - char * str; + char *str; GC gc; int x, y, str_y; - ListWidget lw = (ListWidget) w; + ListWidget lw = (ListWidget)w; XFontSetExtents *ext = XExtentsOfFontSet(lw->list.fontset); - if (!XtIsRealized(w)) return; /* Just in case... */ + if (!XtIsRealized(w) || item > lw->list.nitems) + return; if (lw->list.vertical_cols) { x = lw->list.col_width * (item / lw->list.nrows) + lw->list.internal_width; - y = lw->list.row_height * (item % lw->list.nrows) + y = lw->list.row_height * (item % lw->list.nrows) + lw->list.internal_height; } else { - x = lw->list.col_width * (item % lw->list.ncols) + x = lw->list.col_width * (item % lw->list.ncols) + lw->list.internal_width; - y = lw->list.row_height * (item / lw->list.ncols) + y = lw->list.row_height * (item / lw->list.ncols) + lw->list.internal_height; } if ( lw->simple.international == True ) - str_y = y + abs(ext->max_ink_extent.y); + str_y = y + XawAbs(ext->max_ink_extent.y); else - str_y = y + lw->list.font->max_bounds.ascent; + str_y = y + lw->list.font->max_bounds.ascent; if (item == lw->list.is_highlighted) { - if (item == lw->list.highlight) { - gc = lw->list.revgc; + if (item == lw->list.highlight) { + gc = lw->list.revgc; HighlightBackground(w, x, y, lw->list.normgc); } - else { + else { if (XtIsSensitive(w)) - gc = lw->list.normgc; + gc = lw->list.normgc; else - gc = lw->list.graygc; + gc = lw->list.graygc; HighlightBackground(w, x, y, lw->list.revgc); lw->list.is_highlighted = NO_HIGHLIGHT; - } + } } else { - if (item == lw->list.highlight) { - gc = lw->list.revgc; + if (item == lw->list.highlight) { + gc = lw->list.revgc; HighlightBackground(w, x, y, lw->list.normgc); lw->list.is_highlighted = item; } else { if (XtIsSensitive(w)) - gc = lw->list.normgc; + gc = lw->list.normgc; else - gc = lw->list.graygc; + gc = lw->list.graygc; } } /* List's overall width contains the same number of inter-column - column_space's as columns. There should thus be a half - column_width margin on each side of each column. - The row case is symmetric. */ + column_space's as columns. There should thus be a half + column_width margin on each side of each column. + The row case is symmetric */ - x += lw->list.column_space / 2; - str_y += lw->list.row_space / 2; + x += lw->list.column_space >> 1; + str_y += lw->list.row_space >> 1; str = lw->list.list[item]; /* draw it */ - ClipToShadowInteriorAndLongest( lw, &gc, x ); + ClipToShadowInteriorAndLongest(lw, &gc, x); - if ( lw->simple.international == True ) - XmbDrawString( XtDisplay( w ), XtWindow( w ), lw->list.fontset, - gc, x, str_y, str, strlen( str ) ); + if (lw->simple.international == True) + XmbDrawString(XtDisplay(w), XtWindow(w), lw->list.fontset, + gc, x, str_y, str, strlen(str)); else - XDrawString( XtDisplay( w ), XtWindow( w ), - gc, x, str_y, str, strlen( str ) ); + XDrawString(XtDisplay(w), XtWindow(w), gc, x, str_y, str, strlen(str)); - XSetClipMask( XtDisplay( w ), gc, None ); + XSetClipMask(XtDisplay(w), gc, None); } - -/* Redisplay() - * - * Repaints the widget window on expose events. - * w - the list widget. - * event - the expose event for this repaint. - * junk - not used, unless three-d patch enabled. */ - -/* ARGSUSED */ static void -Redisplay(w, event, junk) -Widget w; -XEvent *event; -Region junk; +XawListRedisplay(Widget w, XEvent *event, Region region) { - int item; /* an item to work with. */ - int ul_item, lr_item; /* corners of items we need to paint. */ - ListWidget lw = (ListWidget) w; + int item; /* an item to work with */ + int ul_item, lr_item; /* corners of items we need to paint */ + ListWidget lw = (ListWidget)w; - if (event == NULL) { /* repaint all. */ - ul_item = 0; + if (event == NULL) { + ul_item = 0; lr_item = lw->list.nrows * lw->list.ncols - 1; XClearWindow(XtDisplay(w), XtWindow(w)); } else - FindCornerItems(w, event, &ul_item, &lr_item); + FindCornerItems(w, event, &ul_item, &lr_item); + + if (Superclass->core_class.expose) + (Superclass->core_class.expose)(w, event, region); - for (item = ul_item; (item <= lr_item && item < lw->list.nitems) ; item++) - if (ItemInRectangle(w, ul_item, lr_item, item)) - PaintItemName(w, item); + for (item = ul_item; item <= lr_item && item < lw->list.nitems; item++) + if (ItemInRectangle(w, ul_item, lr_item, item)) + PaintItemName(w, item); } - -/* PreferredGeom() +/* XawListQueryGeometry() * * This tells the parent what size we would like to be * given certain constraints. * w - the widget. * intended - what the parent intends to do with us. - * requested - what we want to happen. */ - + * requested - what we want to happen */ static XtGeometryResult -PreferredGeom(w, intended, requested) -Widget w; -XtWidgetGeometry *intended, *requested; +XawListQueryGeometry(Widget w, XtWidgetGeometry *intended, + XtWidgetGeometry *requested) { Dimension new_width, new_height; - Boolean change, width_req, height_req; + Bool change, width_req, height_req; width_req = intended->request_mode & CWWidth; height_req = intended->request_mode & CWHeight; if (width_req) - new_width = intended->width; + new_width = intended->width; else - new_width = w->core.width; + new_width = XtWidth(w); if (height_req) - new_height = intended->height; + new_height = intended->height; else - new_height = w->core.height; + new_height = XtHeight(w); requested->request_mode = 0; -/* - * We only care about our height and width. - */ - - if ( !width_req && !height_req) - return(XtGeometryYes); + /* + * We only care about our height and width + */ + if (!width_req && !height_req) + return (XtGeometryYes); change = Layout(w, !width_req, !height_req, &new_width, &new_height); @@ -728,329 +821,331 @@ XtWidgetGeometry *intended, *requested; requested->height = new_height; if (change) - return(XtGeometryAlmost); - return(XtGeometryYes); -} - + return (XtGeometryAlmost); -/* Resize() - * - * resizes the widget, by changing the number of rows and columns. */ + return (XtGeometryYes); +} static void -Resize(w) - Widget w; +XawListResize(Widget w) { Dimension width, height; - width = w->core.width; - height = w->core.height; + width = XtWidth(w); + height = XtHeight(w); - if (Layout(w, FALSE, FALSE, &width, &height)) + if (Layout(w, False, False, &width, &height)) XtAppWarning(XtWidgetToApplicationContext(w), - "List Widget: Size changed when it shouldn't have when resising."); + "List Widget: Size changed when it shouldn't " + "have when resising."); } - /* Layout() * * lays out the item in the list. * w - the widget. - * xfree, yfree - TRUE if we are free to resize the widget in - * this direction. + * xfree, yfree - True if we are free to resize the widget in + * this direction. * width, height- the is the current width and height that we are going - * we are going to layout the list widget to, - * depending on xfree and yfree of course. - * - * RETURNS: TRUE if width or height have been changed. */ - -static Boolean -Layout(w, xfree, yfree, width, height) -Widget w; -Boolean xfree, yfree; -Dimension *width, *height; + * we are going to layout the list widget to, + * depending on xfree and yfree of course. + * + * Return: + * True if width or height have been changed */ +static Bool +Layout(Widget w, Bool xfree, Bool yfree, Dimension *width, Dimension *height) { - ListWidget lw = (ListWidget) w; - Boolean change = FALSE; - -/* - * If force columns is set then always use number of columns specified - * by default_cols. - */ - + ListWidget lw = (ListWidget)w; + Bool change = False; + unsigned long width2 = 0, height2 = 0; + + /* + * If force columns is set then always use number of columns specified + * by default_cols + */ if (lw->list.force_cols) { - lw->list.ncols = lw->list.default_cols; - if (lw->list.ncols <= 0) lw->list.ncols = 1; - /* 12/3 = 4 and 10/3 = 4, but 9/3 = 3 */ - lw->list.nrows = ( ( lw->list.nitems - 1) / lw->list.ncols) + 1 ; - if (xfree) { /* If allowed resize width. */ - - /* this counts the same number - of inter-column column_space 's as columns. There should thus be a - half column_space margin on each side of each column...*/ - - *width = lw->list.ncols * lw->list.col_width - + 2 * lw->list.internal_width; - change = TRUE; + lw->list.ncols = lw->list.default_cols; + if (lw->list.ncols <= 0) + lw->list.ncols = 1; + lw->list.nrows = ((lw->list.nitems - 1) / lw->list.ncols) + 1; + if (xfree) { + /* this counts the same number + of inter-column column_space 's as columns. There should thus + be a half column_space margin on each side of each column...*/ + width2 = lw->list.ncols * lw->list.col_width + + (lw->list.internal_width << 1); + change = True; } - if (yfree) { /* If allowed resize height. */ - *height = (lw->list.nrows * lw->list.row_height) - + 2 * lw->list.internal_height; - change = TRUE; + if (yfree) { + height2 = lw->list.nrows * lw->list.row_height + + (lw->list.internal_height << 1); + change = True; } - return(change); } -/* - * If both width and height are free to change the use default_cols - * to determine the number columns and set new width and height to - * just fit the window. - */ - - if (xfree && yfree) { - lw->list.ncols = lw->list.default_cols; - if (lw->list.ncols <= 0) lw->list.ncols = 1; - lw->list.nrows = ( ( lw->list.nitems - 1) / lw->list.ncols) + 1 ; - *width = lw->list.ncols * lw->list.col_width - + 2 * lw->list.internal_width; - *height = (lw->list.nrows * lw->list.row_height) - + 2 * lw->list.internal_height; - change = TRUE; + /* + * If both width and height are free to change the use default_cols + * to determine the number columns and set new width and height to + * just fit the window + */ + else if (xfree && yfree) { + lw->list.ncols = lw->list.default_cols; + if (lw->list.ncols <= 0) { + int wid = (int)XtWidth(lw) - (int)(lw->list.internal_width << 1) + + (int)lw->list.column_space; + + if (wid <= 0 || lw->list.col_width <= 0 + || (lw->list.ncols = wid / lw->list.col_width) <= 0) + lw->list.ncols = 1; + } + width2 = lw->list.ncols * lw->list.col_width + + (lw->list.internal_width << 1); + height2 = (lw->list.nrows * lw->list.row_height) + + (lw->list.internal_height << 1); + change = True; } -/* - * If the width is fixed then use it to determine the number of columns. - * If the height is free to move (width still fixed) then resize the height - * of the widget to fit the current list exactly. - */ + + /* + * If the width is fixed then use it to determine the number of columns. + * If the height is free to move (width still fixed) then resize the height + * of the widget to fit the current list exactly + */ else if (!xfree) { - lw->list.ncols = ( (int)(*width - 2 * lw->list.internal_width) - / (int)lw->list.col_width); - if (lw->list.ncols <= 0) lw->list.ncols = 1; - lw->list.nrows = ( ( lw->list.nitems - 1) / lw->list.ncols) + 1 ; - if ( yfree ) { - *height = (lw->list.nrows * lw->list.row_height) - + 2 * lw->list.internal_height; - change = TRUE; + lw->list.ncols = ((int)(*width - (lw->list.internal_width << 1)) + / (int)lw->list.col_width); + if (lw->list.ncols <= 0) + lw->list.ncols = 1; + lw->list.nrows = ((lw->list.nitems - 1) / lw->list.ncols) + 1; + if (yfree) { + height2 = lw->list.nrows * lw->list.row_height + + (lw->list.internal_height << 1); + change = True; } } -/* - * The last case is xfree and !yfree we use the height to determine - * the number of rows and then set the width to just fit the resulting - * number of columns. - */ - else if (!yfree) { /* xfree must be TRUE. */ - lw->list.nrows = (int)(*height - 2 * lw->list.internal_height) - / (int)lw->list.row_height; - if (lw->list.nrows <= 0) lw->list.nrows = 1; - lw->list.ncols = (( lw->list.nitems - 1 ) / lw->list.nrows) + 1; - *width = lw->list.ncols * lw->list.col_width - + 2 * lw->list.internal_width; - change = TRUE; - } - return(change); -} + /* + * The last case is xfree and !yfree we use the height to determine + * the number of rows and then set the width to just fit the resulting + * number of columns + */ + else if (!yfree) { + lw->list.nrows = ((int)(*height - (lw->list.internal_height << 1)) + / (int)lw->list.row_height); + if (lw->list.nrows <= 0) + lw->list.nrows = 1; + lw->list.ncols = ((lw->list.nitems - 1) / lw->list.nrows) + 1; + width2 = lw->list.ncols * lw->list.col_width + + (lw->list.internal_width << 1); + change = True; + } -/* Notify() - ACTION + if (!lw->list.force_cols && lw->list.nrows) { + /*CONSTCOND*/ + while (1) { + lw->list.nrows = ((lw->list.nitems - 1) / lw->list.ncols) + 1; + width2 = lw->list.ncols * lw->list.col_width + + (lw->list.internal_width << 1); + height2 = lw->list.nrows * lw->list.row_height + + (lw->list.internal_height << 1); + if (width2 >= MaxSize && height2 >= MaxSize) + break; + if (height2 > MaxSize) + ++lw->list.ncols; + else if (width2 > MaxSize && lw->list.ncols > 1) + --lw->list.ncols; + else + break; + } + } + if (width2) + *width = width2; + if (height2) + *height = height2; + + return (change); +} + +/* Notify() - Action * * Notifies the user that a button has been pressed, and * calls the callback; if the XtNpasteBuffer resource is true - * then the name of the item is also put in CUT_BUFFER0. */ - -/* ARGSUSED */ + * then the name of the item is also put in CUT_BUFFER0 */ +/*ARGSUSED*/ static void -Notify(w, event, params, num_params) -Widget w; -XEvent * event; -String * params; -Cardinal *num_params; +Notify(Widget w, XEvent *event, String *params, Cardinal *num_params) { - ListWidget lw = ( ListWidget ) w; + ListWidget lw = (ListWidget)w; int item, item_len; XawListReturnStruct ret_value; -/* - * Find item and if out of range then unhighlight and return. - * - * If the current item is unhighlighted then the user has aborted the - * notify, so unhighlight and return. - */ - - if ( ((CvtToItem(w, event->xbutton.x, event->xbutton.y, &item)) - == OUT_OF_RANGE) || (lw->list.highlight != item) ) { - XawListUnhighlight(w); - return; + /* + * Find item and if out of range then unhighlight and return + * + * If the current item is unhighlighted then the user has aborted the + * notify, so unhighlight and return + */ + if ((CvtToItem(w, event->xbutton.x, event->xbutton.y, &item) == OUT_OF_RANGE) + || lw->list.highlight != item) { +#ifndef OLDXAW + if (!lw->list.show_current || lw->list.selected == NO_HIGHLIGHT) + XawListUnhighlight(w); + else + XawListHighlight(w, lw->list.selected); +#else + XawListUnhighlight(w); +#endif + return; } item_len = strlen(lw->list.list[item]); - if ( lw->list.paste ) /* if XtNpasteBuffer set then paste it. */ - XStoreBytes(XtDisplay(w), lw->list.list[item], item_len); - -/* - * Call Callback function. - */ + if (lw->list.paste) /* if XtNpasteBuffer set then paste it */ + XStoreBytes(XtDisplay(w), lw->list.list[item], item_len); +#ifndef OLDXAW + lw->list.selected = item; +#endif + /* + * Call Callback function + */ ret_value.string = lw->list.list[item]; ret_value.list_index = item; - XtCallCallbacks( w, XtNcallback, (XtPointer) &ret_value); + XtCallCallbacks(w, XtNcallback, (XtPointer)&ret_value); } - -/* Unset() - ACTION +/* Unset() - Action * - * unhighlights the current element. */ - -/* ARGSUSED */ + * unhighlights the current element */ +/*ARGSUSED*/ static void -Unset(w, event, params, num_params) -Widget w; -XEvent * event; -String * params; -Cardinal *num_params; +Unset(Widget w, XEvent *event, String *params, Cardinal *num_params) { - XawListUnhighlight(w); + XawListUnhighlight(w); } - -/* Set() - ACTION +/* Set() - Action * - * Highlights the current element. */ - -/* ARGSUSED */ + * Highlights the current element */ +/*ARGSUSED*/ static void -Set(w, event, params, num_params) -Widget w; -XEvent * event; -String * params; -Cardinal *num_params; +Set(Widget w, XEvent *event, String *params, Cardinal *num_params) { - int item; - ListWidget lw = (ListWidget) w; - - if ( (CvtToItem(w, event->xbutton.x, event->xbutton.y, &item)) - == OUT_OF_RANGE) - XawListUnhighlight(w); /* Unhighlight current item. */ - else if ( lw->list.is_highlighted != item ) /* If this item is not */ - XawListHighlight(w, item); /* highlighted then do it. */ + int item; + ListWidget lw = (ListWidget)w; + +#ifndef OLDXAW + lw->list.selected = lw->list.highlight; +#endif + if (CvtToItem(w, event->xbutton.x, event->xbutton.y, &item) == OUT_OF_RANGE) + XawListUnhighlight(w); /* Unhighlight current item */ + else if (lw->list.is_highlighted != item) /* If this item is not */ + XawListHighlight(w, item); /* highlighted then do it */ } /* * Set specified arguments into widget */ - +/*ARGSUSED*/ static Boolean -SetValues(current, request, new, args, num_args) -Widget current, request, new; -ArgList args; -Cardinal *num_args; +XawListSetValues(Widget current, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - ListWidget cl = (ListWidget) current; - ListWidget rl = (ListWidget) request; - ListWidget nl = (ListWidget) new; - Boolean redraw = FALSE; + ListWidget cl = (ListWidget)current; + ListWidget rl = (ListWidget)request; + ListWidget nl = (ListWidget)cnew; + Bool redraw = False; XFontSetExtents *ext = XExtentsOfFontSet(nl->list.fontset); - /* If the request height/width is different, lock it. Unless its 0. If */ - /* neither new nor 0, leave it as it was. Not in R5. */ - if ( nl->core.width != cl->core.width ) - nl->list.freedoms |= WidthLock; - if ( nl->core.width == 0 ) - nl->list.freedoms &= ~WidthLock; - - if ( nl->core.height != cl->core.height ) - nl->list.freedoms |= HeightLock; - if ( nl->core.height == 0 ) - nl->list.freedoms &= ~HeightLock; - - if ( nl->list.longest != cl->list.longest ) - nl->list.freedoms |= LongestLock; - if ( nl->list.longest == 0 ) - nl->list.freedoms &= ~LongestLock; - - /* _DONT_ check for fontset here - it's not in GC.*/ - - if ( (cl->list.foreground != nl->list.foreground) || - (cl->core.background_pixel != nl->core.background_pixel) || - (cl->list.font != nl->list.font) ) { + /* If the request height/width is different, lock it. Unless its 0. If + neither new nor 0, leave it as it was. Not in R5 */ + if (XtWidth(nl) != XtWidth(cl)) + nl->list.freedoms |= WidthLock; + if (XtWidth(nl) == 0) + nl->list.freedoms &= ~WidthLock; + + if (XtHeight(nl) != XtHeight(cl)) + nl->list.freedoms |= HeightLock; + if (XtHeight(nl) == 0) + nl->list.freedoms &= ~HeightLock; + + if (nl->list.longest != cl->list.longest) + nl->list.freedoms |= LongestLock; + if (nl->list.longest == 0) + nl->list.freedoms &= ~LongestLock; + + if (cl->list.foreground != nl->list.foreground || + cl->core.background_pixel != nl->core.background_pixel || + cl->list.font != nl->list.font) { XGCValues values; + XGetGCValues(XtDisplay(current), cl->list.graygc, GCTile, &values); XmuReleaseStippledPixmap(XtScreen(current), values.tile); XtReleaseGC(current, cl->list.graygc); XtReleaseGC(current, cl->list.revgc); XtReleaseGC(current, cl->list.normgc); - GetGCs(new); - redraw = TRUE; + GetGCs(cnew); + redraw = True; } - if ( ( cl->list.font != nl->list.font ) && - ( cl->simple.international == False ) ) - nl->list.row_height = nl->list.font->max_bounds.ascent - + nl->list.font->max_bounds.descent + if (cl->list.font != nl->list.font && cl->simple.international == False) + nl->list.row_height = nl->list.font->max_bounds.ascent + + nl->list.font->max_bounds.descent + nl->list.row_space; - - else if ( ( cl->list.fontset != nl->list.fontset ) && - ( cl->simple.international == True ) ) - nl->list.row_height = ext->max_ink_extent.height + nl->list.row_space; + else if (cl->list.fontset != nl->list.fontset + && cl->simple.international == True) + nl->list.row_height = ext->max_ink_extent.height + nl->list.row_space; /* ...If the above two font(set) change checkers above both failed, check - if row_space was altered. If one of the above passed, row_height will - already have been re-calculated. */ - - else if ( cl->list.row_space != nl->list.row_space ) { - - if (cl->simple.international == True ) - nl->list.row_height = ext->max_ink_extent.height + nl->list.row_space; - else - nl->list.row_height = nl->list.font->max_bounds.ascent - + nl->list.font->max_bounds.descent - + nl->list.row_space; + if row_space was altered. If one of the above passed, row_height will + already have been re-calculated */ + else if (cl->list.row_space != nl->list.row_space) { + if (cl->simple.international == True) + nl->list.row_height = ext->max_ink_extent.height + nl->list.row_space; + else + nl->list.row_height = nl->list.font->max_bounds.ascent + + nl->list.font->max_bounds.descent + + nl->list.row_space; } - if ((cl->core.width != nl->core.width) || - (cl->core.height != nl->core.height) || - (cl->list.internal_width != nl->list.internal_width) || - (cl->list.internal_height != nl->list.internal_height) || - (cl->list.column_space != nl->list.column_space) || - (cl->list.row_space != nl->list.row_space) || - (cl->list.default_cols != nl->list.default_cols) || - ( (cl->list.force_cols != nl->list.force_cols) && - (rl->list.force_cols != nl->list.ncols) ) || - (cl->list.vertical_cols != nl->list.vertical_cols) || - (cl->list.longest != nl->list.longest) || - (cl->list.nitems != nl->list.nitems) || - (cl->list.font != nl->list.font) || - /* Equiv. fontsets might have different values, but the same fonts, so the - next comparison is sloppy but not dangerous. */ - (cl->list.fontset != nl->list.fontset) || - (cl->list.list != nl->list.list) ) { - - CalculatedValues( new ); - Layout( new, WidthFree( nl ), HeightFree( nl ), - &nl->core.width, &nl->core.height ); - redraw = TRUE; + if (XtWidth(cl) != XtWidth(nl) || XtHeight(cl) != XtHeight(nl) + || cl->list.internal_width != nl->list.internal_width + || cl->list.internal_height != nl->list.internal_height + || cl->list.column_space != nl->list.column_space + || cl->list.row_space != nl->list.row_space + || cl->list.default_cols != nl->list.default_cols + || (cl->list.force_cols != nl->list.force_cols + && rl->list.force_cols != nl->list.ncols) + || cl->list.vertical_cols != nl->list.vertical_cols + || cl->list.longest != nl->list.longest + || cl->list.nitems != nl->list.nitems + || cl->list.font != nl->list.font + /* Equiv. fontsets might have different values, but the same fonts, + so the next comparison is sloppy but not dangerous */ + || cl->list.fontset != nl->list.fontset + || cl->list.list != nl->list.list) { + CalculatedValues(cnew); + Layout(cnew, WidthFree(nl), HeightFree(nl), + &nl->core.width, &nl->core.height); + redraw = True; } - if (cl->list.list != nl->list.list) + if (cl->list.list != nl->list.list || cl->list.nitems != nl->list.nitems) nl->list.is_highlighted = nl->list.highlight = NO_HIGHLIGHT; - if ((cl->core.sensitive != nl->core.sensitive) || - (cl->core.ancestor_sensitive != nl->core.ancestor_sensitive)) { - nl->list.highlight = NO_HIGHLIGHT; - redraw = TRUE; + if (cl->core.sensitive != nl->core.sensitive + || cl->core.ancestor_sensitive != nl->core.ancestor_sensitive) { + nl->list.highlight = NO_HIGHLIGHT; + redraw = True; } - if (!XtIsRealized(current)) - return(FALSE); - - return(redraw); + return (redraw); } -static void Destroy(w) - Widget w; +static void +XawListDestroy(Widget w) { - ListWidget lw = (ListWidget) w; + ListWidget lw = (ListWidget)w; XGCValues values; XGetGCValues(XtDisplay(w), lw->list.graygc, GCTile, &values); @@ -1060,144 +1155,112 @@ static void Destroy(w) XtReleaseGC(w, lw->list.normgc); } -/* Exported Functions */ - -/* Function Name: XawListChange. - * Description: Changes the list being used and shown. - * Arguments: w - the list widget. - * list - the new list. - * nitems - the number of items in the list. - * longest - the length (in Pixels) of the longest element - * in the list. - * resize - if TRUE the the list widget will - * try to resize itself. - * Returns: none. - * NOTE: If nitems of longest are <= 0 then they will be calculated. - * If nitems is <= 0 then the list needs to be NULL terminated. +/* + * Function: + * XawListChange + * + * Parameters: + * w - list widget + * list - new list + * nitems - number of items in the list + * longest - length (in Pixels) of the longest element in the list + * resize - if True the the list widget will try to resize itself + * + * Description: + * Changes the list being used and shown. + * + * Note: + * If nitems of longest are <= 0 then they will be calculated + * If nitems is <= 0 then the list needs to be NULL terminated */ - void -#if NeedFunctionPrototypes -XawListChange(Widget w, char ** list, int nitems, int longest, +XawListChange(Widget w, char **list, int nitems, int longest, #if NeedWidePrototypes - int resize_it) -#else - Boolean resize_it) -#endif + int resize_it #else -XawListChange(w, list, nitems, longest, resize_it) -Widget w; -char ** list; -int nitems, longest; -Boolean resize_it; + Boolean resize_it #endif +) { - ListWidget lw = (ListWidget) w; - Dimension new_width = w->core.width; - Dimension new_height = w->core.height; + ListWidget lw = (ListWidget)w; + Dimension new_width = XtWidth(w); + Dimension new_height = XtHeight(w); lw->list.list = list; - if ( nitems <= 0 ) nitems = 0; + if (nitems <= 0) + nitems = 0; lw->list.nitems = nitems; - if ( longest <= 0 ) longest = 0; + if (longest <= 0) + longest = 0; /* If the user passes 0 meaning "calculate it", it must be free */ - if ( longest != 0 ) - lw->list.freedoms |= LongestLock; - else /* the user's word is god. */ - lw->list.freedoms &= ~LongestLock; + if (longest != 0) + lw->list.freedoms |= LongestLock; + else + lw->list.freedoms &= ~LongestLock; - if ( resize_it ) - lw->list.freedoms &= ~WidthLock & ~HeightLock; - /* else - still resize if its not locked */ + if (resize_it) + lw->list.freedoms &= ~WidthLock & ~HeightLock; lw->list.longest = longest; - CalculatedValues( w ); + CalculatedValues(w); - if( Layout( w, WidthFree( w ), HeightFree( w ), - &new_width, &new_height ) ) - ChangeSize( w, new_width, new_height ); + if (Layout(w, WidthFree(w), HeightFree(w), &new_width, &new_height)) + ChangeSize(w, new_width, new_height); lw->list.is_highlighted = lw->list.highlight = NO_HIGHLIGHT; - if ( XtIsRealized( w ) ) - Redisplay( w, (XEvent *)NULL, (Region)NULL ); + if (XtIsRealized(w)) + XawListRedisplay(w, NULL, NULL); } -/* Function Name: XawListUnhighlight - * Description: unlights the current highlighted element. - * Arguments: w - the widget. - * Returns: none. - */ - void -#if NeedFunctionPrototypes XawListUnhighlight(Widget w) -#else -XawListUnhighlight(w) -Widget w; -#endif { - ListWidget lw = ( ListWidget ) w; + ListWidget lw = (ListWidget)w; lw->list.highlight = NO_HIGHLIGHT; if (lw->list.is_highlighted != NO_HIGHLIGHT) - PaintItemName(w, lw->list.is_highlighted); /* unhighlight this one. */ + PaintItemName(w, lw->list.is_highlighted); } -/* Function Name: XawListHighlight - * Description: Highlights the given item. - * Arguments: w - the list widget. - * item - the item to hightlight. - * Returns: none. - */ - void -#if NeedFunctionPrototypes XawListHighlight(Widget w, int item) -#else -XawListHighlight(w, item) -Widget w; -int item; -#endif { - ListWidget lw = ( ListWidget ) w; + ListWidget lw = (ListWidget)w; if (XtIsSensitive(w)) { - lw->list.highlight = item; - if (lw->list.is_highlighted != NO_HIGHLIGHT) - PaintItemName(w, lw->list.is_highlighted); /* Unhighlight. */ - PaintItemName(w, item); /* HIGHLIGHT this one. */ + lw->list.highlight = item; + if (lw->list.is_highlighted != NO_HIGHLIGHT) + PaintItemName(w, lw->list.is_highlighted); + PaintItemName(w, item); } } -/* Function Name: XawListShowCurrent - * Description: returns the currently highlighted object. - * Arguments: w - the list widget. - * Returns: the info about the currently highlighted object. +/* + * Function: + * XawListShowCurrent + * + * Parameters: + * w - list widget + * + * Returns: + * Info about the currently highlighted object */ - XawListReturnStruct * -#if NeedFunctionPrototypes XawListShowCurrent(Widget w) -#else -XawListShowCurrent(w) -Widget w; -#endif { - ListWidget lw = ( ListWidget ) w; - XawListReturnStruct * ret_val; + ListWidget lw = (ListWidget)w; + XawListReturnStruct *ret_val; - ret_val = (XawListReturnStruct *) - XtMalloc (sizeof (XawListReturnStruct));/* SPARE MALLOC OK */ + ret_val = (XawListReturnStruct *)XtMalloc(sizeof(XawListReturnStruct)); ret_val->list_index = lw->list.highlight; if (ret_val->list_index == XAW_LIST_NONE) - ret_val->string = ""; + ret_val->string = ""; else - ret_val->string = lw->list.list[ ret_val->list_index ]; + ret_val->string = lw->list.list[ret_val->list_index]; - return(ret_val); + return (ret_val); } - diff --git a/src/MenuButton.c b/src/MenuButton.c index 4483009..f21dc90 100644 --- a/src/MenuButton.c +++ b/src/MenuButton.c @@ -25,12 +25,7 @@ in this Software without prior written authorization from The Open Group. * */ - -/*********************************************************************** - * - * MenuButton Widget - * - ***********************************************************************/ +/* $XFree86: xc/lib/Xaw/MenuButton.c,v 3.10 2001/12/14 19:54:41 dawes Exp $ */ /* * MenuButton.c - Source code for MenuButton widget. @@ -48,65 +43,80 @@ in this Software without prior written authorization from The Open Group. #include <stdio.h> #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> - -#include <X11/Xaw/XawInit.h> +#include <X11/Xmu/SysUtil.h> #include <X11/Xaw/MenuButtoP.h> +#include <X11/Xaw/XawInit.h> +#include "Private.h" -static void ClassInitialize(); -static void PopupMenu(); +/* + * Class Methods + */ +static void XawMenuButtonClassInitialize(void); +static void XawMenuButtonInitialize(Widget, Widget, ArgList, Cardinal*); +static void XawMenuButtonDestroy(Widget); +static Boolean XawMenuButtonSetValues(Widget, Widget, Widget, ArgList, Cardinal*); + +/* + * Actions + */ +static void PopupMenu(Widget, XEvent*, String*, Cardinal*); +/* + * Initialization + */ #define superclass ((CommandWidgetClass)&commandClassRec) static char defaultTranslations[] = -"<EnterWindow>: highlight()\n\ - <LeaveWindow>: reset()\n\ - Any<BtnDown>: reset() PopupMenu()"; +"<Enter>:" "highlight()\n" +"<Leave>:" "reset()\n" +"Any<BtnDown>:" "reset() PopupMenu()\n"; -/**************************************************************** - * - * Full class record constant - * - ****************************************************************/ - -/* Private Data */ +static char default_menu_name[] = "menu"; #define offset(field) XtOffsetOf(MenuButtonRec, field) static XtResource resources[] = { { - XtNmenuName, XtCMenuName, XtRString, sizeof(String), - offset(menu_button.menu_name), XtRString, (XtPointer)"menu"}, + XtNmenuName, + XtCMenuName, + XtRString, + sizeof(String), + offset(menu_button.menu_name), + XtRString, + (XtPointer)default_menu_name + }, }; #undef offset static XtActionsRec actionsList[] = { - {"PopupMenu", PopupMenu} + {"PopupMenu", PopupMenu}, }; MenuButtonClassRec menuButtonClassRec = { + /* core */ { - (WidgetClass) superclass, /* superclass */ + (WidgetClass)superclass, /* superclass */ "MenuButton", /* class_name */ sizeof(MenuButtonRec), /* size */ - ClassInitialize, /* class_initialize */ + XawMenuButtonClassInitialize, /* class_initialize */ NULL, /* class_part_initialize */ - FALSE, /* class_inited */ - NULL, /* initialize */ + False, /* class_inited */ + XawMenuButtonInitialize, /* initialize */ NULL, /* initialize_hook */ XtInheritRealize, /* realize */ actionsList, /* actions */ XtNumber(actionsList), /* num_actions */ resources, /* resources */ - XtNumber(resources), /* resource_count */ + XtNumber(resources), /* num_resources */ NULLQUARK, /* xrm_class */ - FALSE, /* compress_motion */ - TRUE, /* compress_exposure */ - TRUE, /* compress_enterleave */ - FALSE, /* visible_interest */ - NULL, /* destroy */ + False, /* compress_motion */ + True, /* compress_exposure */ + True, /* compress_enterleave */ + False, /* visible_interest */ + XawMenuButtonDestroy, /* destroy */ XtInheritResize, /* resize */ XtInheritExpose, /* expose */ - NULL, /* set_values */ + XawMenuButtonSetValues, /* set_values */ NULL, /* set_values_hook */ XtInheritSetValuesAlmost, /* set_values_almost */ NULL, /* get_values_hook */ @@ -116,114 +126,148 @@ MenuButtonClassRec menuButtonClassRec = { defaultTranslations, /* tm_table */ XtInheritQueryGeometry, /* query_geometry */ XtInheritDisplayAccelerator, /* display_accelerator */ - NULL /* extension */ - }, /* CoreClass fields initialization */ + NULL, /* extension */ + }, + /* simple */ { XtInheritChangeSensitive /* change_sensitive */ - }, /* SimpleClass fields initialization */ + }, + /* label */ { - 0, /* field not used */ - }, /* LabelClass fields initialization */ + NULL, /* extension */ + }, + /* command */ { - 0, /* field not used */ - }, /* CommandClass fields initialization */ + NULL, /* extension */ + }, + /* menu_button */ { - 0, /* field not used */ - } /* MenuButtonClass fields initialization */ + NULL, /* extension */ + }, }; - /* for public consumption */ -WidgetClass menuButtonWidgetClass = (WidgetClass) &menuButtonClassRec; - -/**************************************************************** - * - * Private Procedures - * - ****************************************************************/ +WidgetClass menuButtonWidgetClass = (WidgetClass)&menuButtonClassRec; -static void ClassInitialize() +/* + * Implementation + */ +static void +XawMenuButtonClassInitialize(void) { XawInitializeWidgetSet(); - XtRegisterGrabAction(PopupMenu, True, - (unsigned int)(ButtonPressMask | ButtonReleaseMask), + XtRegisterGrabAction(PopupMenu, True, + ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync); } -/* ARGSUSED */ +/*ARGSUSED*/ static void -PopupMenu(w, event, params, num_params) -Widget w; -XEvent * event; -String * params; -Cardinal * num_params; +XawMenuButtonInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - MenuButtonWidget mbw = (MenuButtonWidget) w; - Widget menu, temp; - Arg arglist[2]; - Cardinal num_args; - int menu_x, menu_y, menu_width, menu_height, button_height; - Position button_x, button_y; - - temp = w; - while(temp != NULL) { - menu = XtNameToWidget(temp, mbw->menu_button.menu_name); - if (menu == NULL) - temp = XtParent(temp); - else - break; - } - - if (menu == NULL) { - char error_buf[BUFSIZ]; - char* errorp; - int len; - char* fmt = "MenuButton: Could not find menu widget named %s."; - - if ((len = strlen (fmt) + strlen (mbw->menu_button.menu_name)) < sizeof error_buf) - errorp = error_buf; - else - errorp = XtMalloc (len + 1); - if (errorp == NULL) { - errorp = error_buf; - strcpy (errorp, "MenuButton: Could not find menu widget."); - } else - (void) sprintf(errorp, fmt, mbw->menu_button.menu_name); - XtAppWarning (XtWidgetToApplicationContext (w), errorp); - if (errorp != error_buf) XtFree (errorp); - return; - } - if (!XtIsRealized(menu)) - XtRealizeWidget(menu); - - menu_width = menu->core.width + 2 * menu->core.border_width; - button_height = w->core.height + 2 * w->core.border_width; - menu_height = menu->core.height + 2 * menu->core.border_width; - - XtTranslateCoords(w, 0, 0, &button_x, &button_y); - menu_x = button_x; - menu_y = button_y + button_height; - - if (menu_x >= 0) { - int scr_width = WidthOfScreen(XtScreen(menu)); - if (menu_x + menu_width > scr_width) - menu_x = scr_width - menu_width; - } - if (menu_x < 0) - menu_x = 0; - - if (menu_y >= 0) { - int scr_height = HeightOfScreen(XtScreen(menu)); - if (menu_y + menu_height > scr_height) - menu_y = scr_height - menu_height; - } - if (menu_y < 0) - menu_y = 0; - - num_args = 0; - XtSetArg(arglist[num_args], XtNx, menu_x); num_args++; - XtSetArg(arglist[num_args], XtNy, menu_y); num_args++; - XtSetValues(menu, arglist, num_args); - - XtPopupSpringLoaded(menu); + MenuButtonWidget mbw = (MenuButtonWidget)cnew; + + if (mbw->menu_button.menu_name != default_menu_name) + mbw->menu_button.menu_name = XtNewString(mbw->menu_button.menu_name); } +static void +XawMenuButtonDestroy(Widget w) +{ + MenuButtonWidget mbw = (MenuButtonWidget)w; + + if (mbw->menu_button.menu_name != default_menu_name) + XtFree(mbw->menu_button.menu_name); +} + +/*ARGSUSED*/ +static Boolean +XawMenuButtonSetValues(Widget current, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) +{ + MenuButtonWidget mbw_old = (MenuButtonWidget)current; + MenuButtonWidget mbw_new = (MenuButtonWidget)cnew; + + if (mbw_old->menu_button.menu_name != mbw_new->menu_button.menu_name) { + if (mbw_old->menu_button.menu_name != default_menu_name) + XtFree(mbw_old->menu_button.menu_name); + if (mbw_new->menu_button.menu_name != default_menu_name) + mbw_new->menu_button.menu_name = + XtNewString(mbw_new->menu_button.menu_name); + } + + return (False); +} + +/*ARGSUSED*/ +static void +PopupMenu(Widget w, XEvent *event, String *params, Cardinal *num_params) +{ + MenuButtonWidget mbw = (MenuButtonWidget)w; + Widget menu = NULL, temp; + Arg arglist[2]; + Cardinal num_args; + int menu_x, menu_y, menu_width, menu_height, button_height; + Position button_x, button_y; + + temp = w; + while(temp != NULL) { + menu = XtNameToWidget(temp, mbw->menu_button.menu_name); + if (menu == NULL) + temp = XtParent(temp); + else + break; + } + + if (menu == NULL) { + char error_buf[BUFSIZ]; + + (void)XmuSnprintf(error_buf, sizeof(error_buf), + "MenuButton: Could not find menu widget named %s.", + mbw->menu_button.menu_name); + XtAppWarning(XtWidgetToApplicationContext(w), error_buf); + return; + } + + if (!XtIsRealized(menu)) + XtRealizeWidget(menu); + + menu_width = XtWidth(menu) + (XtBorderWidth(menu) << 1); + button_height = XtHeight(w) + (XtBorderWidth(w) << 1); + menu_height = XtHeight(menu) + (XtBorderWidth(menu) << 1); + + XtTranslateCoords(w, 0, 0, &button_x, &button_y); + menu_x = button_x; + menu_y = button_y + button_height; + + if (menu_y >= 0) { + int scr_height = HeightOfScreen(XtScreen(menu)); + + if (menu_y + menu_height > scr_height) + menu_y = button_y - menu_height; + if (menu_y < 0) { + menu_y = scr_height - menu_height; + menu_x = button_x + XtWidth(w) + (XtBorderWidth(w) << 1); + if (menu_x + menu_width > WidthOfScreen(XtScreen(menu))) + menu_x = button_x - menu_width; + } + } + if (menu_y < 0) + menu_y = 0; + + if (menu_x >= 0) { + int scr_width = WidthOfScreen(XtScreen(menu)); + + if (menu_x + menu_width > scr_width) + menu_x = scr_width - menu_width; + } + if (menu_x < 0) + menu_x = 0; + + num_args = 0; + XtSetArg(arglist[num_args], XtNx, menu_x); num_args++; + XtSetArg(arglist[num_args], XtNy, menu_y); num_args++; + XtSetValues(menu, arglist, num_args); + + XtPopupSpringLoaded(menu); +} diff --git a/src/MultiSink.c b/src/MultiSink.c index 3f4b017..77b0c9f 100644 --- a/src/MultiSink.c +++ b/src/MultiSink.c @@ -70,6 +70,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/MultiSink.c,v 1.20 2001/12/14 19:54:41 dawes Exp $ */ #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> @@ -81,692 +82,892 @@ SOFTWARE. #include "XawI18n.h" #include <stdio.h> #include <ctype.h> +#include "Private.h" #ifdef GETLASTPOS -#undef GETLASTPOS /* We will use our own GETLASTPOS. */ +#undef GETLASTPOS /* We will use our own GETLASTPOS */ #endif -#define GETLASTPOS XawTextSourceScan(source, (XawTextPosition) 0, XawstAll, XawsdRight, 1, TRUE) +#define GETLASTPOS \ + XawTextSourceScan(source, 0, XawstAll, XawsdRight, 1, True) -static void Initialize(), Destroy(); -static Boolean SetValues(); -static int MaxLines(), MaxHeight(); -static void SetTabs(); +/* + * Class Methods + */ +static void XawMultiSinkClassInitialize(void); +static void XawMultiSinkInitialize(Widget, Widget, ArgList, Cardinal*); +static void XawMultiSinkDestroy(Widget); +static void XawMultiSinkResize(Widget); +static Boolean XawMultiSinkSetValues(Widget, Widget, Widget, + ArgList, Cardinal*); +static int MaxLines(Widget, unsigned int); +static int MaxHeight(Widget, int); +static void SetTabs(Widget, int, short*); +static void DisplayText(Widget, int, int, + XawTextPosition, XawTextPosition, Bool); +static void InsertCursor(Widget, int, int, XawTextInsertState); +static void FindPosition(Widget, XawTextPosition, int, int, Bool, + XawTextPosition*, int*, int*); +static void FindDistance(Widget, XawTextPosition, int, XawTextPosition, int*, + XawTextPosition*, int*); +static void Resolve(Widget, XawTextPosition, int, int, XawTextPosition*); +static void GetCursorBounds(Widget, XRectangle*); -static void DisplayText(), InsertCursor(), FindPosition(); -static void FindDistance(), Resolve(), GetCursorBounds(); +/* + * Prototypes + */ +static void GetGC(MultiSinkObject); +static int CharWidth(MultiSinkObject, XFontSet, int, wchar_t); +static unsigned int PaintText(Widget w, GC gc, int x, int y, + wchar_t *buf, int len, Bool); -#define offset(field) XtOffsetOf(MultiSinkRec, multi_sink.field) +/* + * Defined in TextSink.c + */ +void _XawTextSinkClearToBackground(Widget, int, int, unsigned, unsigned); + +/* + * Initialization + */ +static wchar_t wspace[2]; +#define offset(field) XtOffsetOf(MultiSinkRec, multi_sink.field) static XtResource resources[] = { - {XtNfontSet, XtCFontSet, XtRFontSet, sizeof (XFontSet), - offset(fontset), XtRString, XtDefaultFontSet}, - {XtNecho, XtCOutput, XtRBoolean, sizeof(Boolean), - offset(echo), XtRImmediate, (XtPointer) True}, - {XtNdisplayNonprinting, XtCOutput, XtRBoolean, sizeof(Boolean), - offset(display_nonprinting), XtRImmediate, (XtPointer) True}, + { + XtNfontSet, + XtCFontSet, + XtRFontSet, + sizeof(XFontSet), + offset(fontset), + XtRString, + XtDefaultFontSet + }, + { + XtNecho, + XtCOutput, + XtRBoolean, + sizeof(Boolean), + offset(echo), + XtRImmediate, + (XtPointer)True + }, + { + XtNdisplayNonprinting, + XtCOutput, + XtRBoolean, + sizeof(Boolean), + offset(display_nonprinting), + XtRImmediate, + (XtPointer)True + }, }; #undef offset #define SuperClass (&textSinkClassRec) MultiSinkClassRec multiSinkClassRec = { - { /* core_class fields */ - /* superclass */ (WidgetClass) SuperClass, - /* class_name */ "MultiSink", - /* widget_size */ sizeof(MultiSinkRec), - /* class_initialize */ XawInitializeWidgetSet, - /* class_part_initialize */ NULL, - /* class_inited */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* obj1 */ NULL, - /* obj2 */ NULL, - /* obj3 */ 0, - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* obj4 */ FALSE, - /* obj5 */ FALSE, - /* obj6 */ FALSE, - /* obj7 */ FALSE, - /* destroy */ Destroy, - /* obj8 */ NULL, - /* obj9 */ NULL, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* obj10 */ NULL, - /* get_values_hook */ NULL, - /* obj11 */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* obj12 */ NULL, - /* obj13 */ NULL, - /* obj14 */ NULL, - /* extension */ NULL + /* object */ + { + (WidgetClass)SuperClass, /* superclass */ + "MultiSink", /* class_name */ + sizeof(MultiSinkRec), /* widget_size */ + XawMultiSinkClassInitialize, /* class_initialize */ + NULL, /* class_part_initialize */ + False, /* class_inited */ + XawMultiSinkInitialize, /* initialize */ + NULL, /* initialize_hook */ + NULL, /* obj1 */ + NULL, /* obj2 */ + 0, /* obj3 */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + False, /* obj4 */ + False, /* obj5 */ + False, /* obj6 */ + False, /* obj7 */ + XawMultiSinkDestroy, /* destroy */ + (XtProc)XawMultiSinkResize, /* obj8 */ + NULL, /* obj9 */ + XawMultiSinkSetValues, /* set_values */ + NULL, /* set_values_hook */ + NULL, /* obj10 */ + NULL, /* get_values_hook */ + NULL, /* obj11 */ + XtVersion, /* version */ + NULL, /* callback_private */ + NULL, /* obj12 */ + NULL, /* obj13 */ + NULL, /* obj14 */ + NULL, /* extension */ }, - { /* text_sink_class fields */ - /* DisplayText */ DisplayText, - /* InsertCursor */ InsertCursor, - /* ClearToBackground */ XtInheritClearToBackground, - /* FindPosition */ FindPosition, - /* FindDistance */ FindDistance, - /* Resolve */ Resolve, - /* MaxLines */ MaxLines, - /* MaxHeight */ MaxHeight, - /* SetTabs */ SetTabs, - /* GetCursorBounds */ GetCursorBounds + /* text_sink */ + { + DisplayText, /* DisplayText */ + InsertCursor, /* InsertCursor */ + XtInheritClearToBackground, /* ClearToBackground */ + FindPosition, /* FindPosition */ + FindDistance, /* FindDistance */ + Resolve, /* Resolve */ + MaxLines, /* MaxLines */ + MaxHeight, /* MaxHeight */ + SetTabs, /* SetTabs */ + GetCursorBounds, /* GetCursorBounds */ }, - { /* multi_sink_class fields */ - /* unused */ 0 + /* multi_sink */ + { + NULL, /* extension */ } }; WidgetClass multiSinkObjectClass = (WidgetClass)&multiSinkClassRec; -/* Utilities */ - -static int -CharWidth (w, x, c) - Widget w; - int x; - wchar_t c; +/* + * Implementation + */ +static int +CharWidth(MultiSinkObject sink, XFontSet fontset, int x, wchar_t c) { - int i, width; - MultiSinkObject sink = (MultiSinkObject) w; - XFontSet fontset = sink->multi_sink.fontset; - Position *tab; + int width = 0; - if ( c == _Xaw_atowc(XawLF) ) return(0); + if (c == _Xaw_atowc(XawLF)) + return (0); if (c == _Xaw_atowc(XawTAB)) { + int i; + Position *tab; + + width = x; /* Adjust for Left Margin. */ - x -= ((TextWidget) XtParent(w))->text.margin.left; - - if (x >= (int)XtParent(w)->core.width) return 0; - for (i = 0, tab = sink->text_sink.tabs ; - i < sink->text_sink.tab_count ; i++, tab++) { - if (x < *tab) { - if (*tab < (int)XtParent(w)->core.width) - return *tab - x; - else - return 0; + x -= ((TextWidget)XtParent((Widget)sink))->text.left_margin; + + i = 0; + tab = sink->text_sink.tabs; + /*CONSTCOND*/ + while (1) { + if (x < *tab) + return (*tab - x); + /* Start again */ + if (++i >= sink->text_sink.tab_count) { + x -= *tab; + i = 0; + tab = sink->text_sink.tabs; + if (width == x) + return (0); } + else + ++tab; } - return 0; + /*NOTREACHED*/ } - if (XwcTextEscapement (fontset, &c, 1) == 0) + if (XwcTextEscapement(fontset, &c, 1) == 0) { if (sink->multi_sink.display_nonprinting) c = _Xaw_atowc('@'); - else { + else c = _Xaw_atowc(XawSP); - } + } - /* - * if more efficiency(suppose one column is one ASCII char) + /* + * if more efficiency(suppose one column is one ASCII char) - width = XwcGetColumn(fontset->font_charset, fontset->num_of_fonts, c) * - fontset->font_struct_list[0]->min_bounds.width; - * - * WARNING: Very Slower!!! - * - * Li Yuhong. - */ + width = XwcGetColumn(fontset->font_charset, fontset->num_of_fonts, c) * + fontset->font_struct_list[0]->min_bounds.width; + * + * WARNING: Very Slower!!! + * + * Li Yuhong. + */ width = XwcTextEscapement(fontset, &c, 1); - return width; + return (width); } -/* Function Name: PaintText - * Description: Actually paints the text into the windoe. - * Arguments: w - the text widget. - * gc - gc to paint text with. - * x, y - location to paint the text. - * buf, len - buffer and length of text to paint. - * Returns: the width of the text painted, or 0. +/* + * Function: + * PaintText * - * NOTE: If this string attempts to paint past the end of the window - * then this function will return zero. + * Parameters: + * w - text sink object + * gc - gc to paint text + * x - location to paint the text + * y - "" + * buf - buffer and length of text to paint + * len - "" + * clear_bg - clear background before drawing ? + * + * Description: + * Actually paints the text into the window. + * + * Returns: + * The width of the text painted */ - -static Dimension -PaintText(w, gc, x, y, buf, len) - Widget w; - GC gc; - Position x, y; - wchar_t* buf; - int len; +static unsigned int +PaintText(Widget w, GC gc, int x, int y, wchar_t *buf, int len, Bool clear_bg) { - MultiSinkObject sink = (MultiSinkObject) w; - TextWidget ctx = (TextWidget) XtParent(w); - + MultiSinkObject sink = (MultiSinkObject)w; + TextWidget ctx = (TextWidget)XtParent(w); XFontSet fontset = sink->multi_sink.fontset; - Position max_x; - Dimension width = XwcTextEscapement(fontset, buf, len); - XFontSetExtents *ext = XExtentsOfFontSet(fontset); - max_x = (Position) ctx->core.width; - - if ( ((int) width) <= -x) /* Don't draw if we can't see it. */ - return(width); - - XwcDrawImageString(XtDisplay(ctx), XtWindow(ctx), fontset, gc, - (int) x, (int) y, buf, len); - if ( (((Position) width + x) > max_x) && (ctx->text.margin.right != 0) ) { - x = ctx->core.width - ctx->text.margin.right; - width = ctx->text.margin.right; - XFillRectangle(XtDisplay((Widget) ctx), XtWindow( (Widget) ctx), - sink->multi_sink.normgc, (int) x, - (int) y - abs(ext->max_logical_extent.y), - (unsigned int) width, - (unsigned int) ext->max_logical_extent.height); - return(0); + unsigned int width = XwcTextEscapement(fontset, buf, len); + + if (((int)width) <= -x) /* Don't draw if we can't see it */ + return (width); + + if (clear_bg) { + XFontSetExtents *ext = XExtentsOfFontSet(fontset); + + _XawTextSinkClearToBackground(w, x, y - abs(ext->max_logical_extent.y), + width, ext->max_logical_extent.height); + XwcDrawString(XtDisplay(ctx), XtWindow(ctx), fontset, gc, x, y, buf, len); } - return(width); + else + XwcDrawImageString(XtDisplay(ctx), XtWindow(ctx), fontset, gc, + x, y, buf, len); + + return (width); } /* Sink Object Functions */ - /* - * This function does not know about drawing more than one line of text. + * This function does not know about drawing more than one line of text */ - -static void -DisplayText(w, x, y, pos1, pos2, highlight) - Widget w; - Position x, y; - Boolean highlight; - XawTextPosition pos1, pos2; +static void +DisplayText(Widget w, int x, int y, + XawTextPosition pos1, XawTextPosition pos2, Bool highlight) { - MultiSinkObject sink = (MultiSinkObject) w; + TextWidget ctx = (TextWidget)XtParent(w); + MultiSinkObject sink = (MultiSinkObject)w; + XFontSet fontset = sink->multi_sink.fontset; Widget source = XawTextGetSource(XtParent(w)); - wchar_t buf[BUFSIZ]; - XFontSetExtents *ext = XExtentsOfFontSet(sink->multi_sink.fontset); - + wchar_t buf[256]; + XFontSetExtents *ext = XExtentsOfFontSet(fontset); int j, k; XawTextBlock blk; - GC gc = highlight ? sink->multi_sink.invgc : sink->multi_sink.normgc; - GC invgc = highlight ? sink->multi_sink.normgc : sink->multi_sink.invgc; + GC gc, invgc, tabgc; + int max_x; + Bool clear_bg; + + if (!sink->multi_sink.echo || !ctx->text.lt.lines) + return; - if (!sink->multi_sink.echo) return; + max_x = (int)XtWidth(ctx) - ctx->text.r_margin.right; + clear_bg = !highlight && ctx->core.background_pixmap != XtUnspecifiedPixmap; + + gc = highlight ? sink->multi_sink.invgc : sink->multi_sink.normgc; + invgc = highlight ? sink->multi_sink.normgc : sink->multi_sink.invgc; + + if (highlight && sink->multi_sink.xorgc) + tabgc = sink->multi_sink.xorgc; + else + tabgc = invgc; y += abs(ext->max_logical_extent.y); - for ( j = 0 ; pos1 < pos2 ; ) { + for (j = 0; pos1 < pos2;) { pos1 = XawTextSourceRead(source, pos1, &blk, (int) pos2 - pos1); for (k = 0; k < blk.length; k++) { - if (j >= BUFSIZ) { /* buffer full, dump the text. */ - x += PaintText(w, gc, x, y, buf, j); + if ((unsigned) j >= (sizeof(buf) / sizeof(wchar_t)) - 1) { + /* buffer full, dump the text */ + if ((x += PaintText(w, gc, x, y, buf, j, clear_bg)) >= max_x) + return; j = 0; } buf[j] = ((wchar_t *)blk.ptr)[k]; if (buf[j] == _Xaw_atowc(XawLF)) - continue; + continue; else if (buf[j] == _Xaw_atowc(XawTAB)) { - Position temp = 0; - Dimension width; - - if ((j != 0) && ((temp = PaintText(w, gc, x, y, buf, j)) == 0)) - return; - - x += temp; - width = CharWidth(w, x, _Xaw_atowc(XawTAB)); - XFillRectangle(XtDisplayOfObject(w), XtWindowOfObject(w), - invgc, (int) x, - (int) y - abs(ext->max_logical_extent.y), - (unsigned int)width, - (unsigned int)ext->max_logical_extent.height); - x += width; - j = -1; - } - else if (XwcTextEscapement (sink->multi_sink.fontset, &buf[j], 1) == 0) { - if (sink->multi_sink.display_nonprinting) - buf[j] = _Xaw_atowc('@'); - else - buf[j] = _Xaw_atowc(' '); - } + unsigned int width; + + if (j != 0 && + (x += PaintText(w, gc, x, y, buf, j, clear_bg)) >= max_x) + return; + + width = CharWidth(sink, fontset, x, _Xaw_atowc(XawTAB)); + if (clear_bg) + _XawTextSinkClearToBackground(w, + x, y - abs(ext->max_logical_extent.y), + width, ext->max_logical_extent.height); + else + XFillRectangle(XtDisplayOfObject(w), XtWindowOfObject(w), + tabgc, x, + y - abs(ext->max_logical_extent.y), + width, + ext->max_logical_extent.height); + x += width; + j = -1; + } + else if (XwcTextEscapement(sink->multi_sink.fontset, &buf[j], 1) + == 0) { + if (sink->multi_sink.display_nonprinting) + buf[j] = _Xaw_atowc('@'); + else + buf[j] = _Xaw_atowc(XawSP); + } j++; } } - if (j > 0) - (void) PaintText(w, gc, x, y, buf, j); -} - -#define insertCursor_width 6 -#define insertCursor_height 3 -static char insertCursor_bits[] = {0x0c, 0x1e, 0x33}; -static Pixmap -CreateInsertCursor(s) - Screen *s; -{ - return (XCreateBitmapFromData (DisplayOfScreen(s), RootWindowOfScreen(s), - insertCursor_bits, insertCursor_width, insertCursor_height)); + if (j > 0) + (void)PaintText(w, gc, x, y, buf, j, clear_bg); } -/* Function Name: GetCursorBounds - * Description: Returns the size and location of the cursor. - * Arguments: w - the text object. - * RETURNED rect - an X rectangle to return the cursor bounds in. - * Returns: none. +/* + * Function: + * GetCursorBounds + * + * Parameters: + * w - text sink object + * rect - X rectangle to return the cursor bounds + * + * Description: + * Returns the size and location of the cursor. */ - static void -GetCursorBounds(w, rect) - Widget w; - XRectangle * rect; +GetCursorBounds(Widget w, XRectangle *rect) { - MultiSinkObject sink = (MultiSinkObject) w; + MultiSinkObject sink = (MultiSinkObject)w; - rect->width = (unsigned short) insertCursor_width; - rect->height = (unsigned short) insertCursor_height; - rect->x = sink->multi_sink.cursor_x - (short) (rect->width / 2); - rect->y = sink->multi_sink.cursor_y - (short) rect->height; + rect->width = CharWidth(sink, sink->multi_sink.fontset, 0, _Xaw_atowc(XawSP)); + rect->height = (XExtentsOfFontSet(sink->multi_sink.fontset) + ->max_logical_extent.height); + rect->x = sink->multi_sink.cursor_x; + rect->y = sink->multi_sink.cursor_y - (short)rect->height; } /* - * The following procedure manages the "insert" cursor. + * The following procedure manages the "insert" cursor */ - static void -InsertCursor (w, x, y, state) - Widget w; - Position x, y; - XawTextInsertState state; +InsertCursor(Widget w, int x, int y, XawTextInsertState state) { - MultiSinkObject sink = (MultiSinkObject) w; - Widget text_widget = XtParent(w); - XRectangle rect; + MultiSinkObject sink = (MultiSinkObject)w; + XFontSet fontset = sink->multi_sink.fontset; + Widget ctx = XtParent(w); + XawTextPosition position = XawTextGetInsertionPoint(ctx); + + if (XtIsRealized(ctx)) { + int fheight, fdiff; + XawTextBlock block; + wchar_t c; + XawTextPosition selection_start, selection_end; + Boolean has_selection; + XFontSetExtents *ext = XExtentsOfFontSet(fontset); + + XawTextGetSelectionPos((Widget)ctx, &selection_start, &selection_end); + has_selection = selection_start != selection_end; + + fheight = ext->max_logical_extent.height; + fdiff = fheight - abs(ext->max_logical_extent.y); + + if ((sink->multi_sink.cursor_position != position || state == XawisOff) + && !has_selection && sink->multi_sink.laststate != XawisOff) { + wchar_t *ochar; + + (void)XawTextSourceRead(XawTextGetSource(ctx), + sink->multi_sink.cursor_position, + &block, 1); + if (!block.length) + ochar = NULL; + else { + c = ((wchar_t *)block.ptr)[0]; + if (c == _Xaw_atowc(XawLF)) + ochar = NULL; + else if (c == _Xaw_atowc(XawTAB)) + ochar = wspace; + else + ochar = (wchar_t *)block.ptr; + } + + if (!ochar) + _XawTextSinkClearToBackground(w, sink->multi_sink.cursor_x, + (sink->multi_sink.cursor_y - 1 - + fheight), CharWidth(sink, fontset, + 0, wspace[0]), + fheight); + else { + if (XwcTextEscapement(sink->multi_sink.fontset, ochar, 1) != 0) + DisplayText(w, sink->multi_sink.cursor_x, + sink->multi_sink.cursor_y - 1 - fheight, + sink->multi_sink.cursor_position, + sink->multi_sink.cursor_position + 1, + False); + else + PaintText(w, sink->multi_sink.normgc, + sink->multi_sink.cursor_x, + sink->multi_sink.cursor_y - 1 - fdiff, + ochar, 1, + ctx->core.background_pixmap != XtUnspecifiedPixmap); + } + } + + if (!has_selection && state != XawisOff) { + wchar_t *nchar; + Boolean focus = ((TextWidget)ctx)->text.hasfocus; + + (void)XawTextSourceRead(XawTextGetSource(ctx), + position, &block, 1); + c = ((wchar_t *)block.ptr)[0]; + if (!block.length || c == _Xaw_atowc(XawLF) + || c == _Xaw_atowc(XawTAB)) + nchar = wspace; + else + nchar = (wchar_t *)block.ptr; + + if (focus) { + if (XwcTextEscapement(sink->multi_sink.fontset, nchar, 1) != 0) + XwcDrawImageString(XtDisplay(ctx), XtWindow(ctx), + fontset, sink->multi_sink.invgc, + x, (y - 1 - fdiff), nchar, 1); + else + DisplayText(w, x, y - 1 - fheight, + position, position + 1, True); + } + else + XDrawRectangle(XtDisplay(ctx), XtWindow(ctx), + sink->multi_sink.xorgc ? + sink->multi_sink.xorgc : sink->multi_sink.normgc, + x, y - 1 - fheight, + CharWidth(sink, fontset, 0, *nchar) - 1, + fheight - 1); + } + } sink->multi_sink.cursor_x = x; sink->multi_sink.cursor_y = y; - - GetCursorBounds(w, &rect); - if (state != sink->multi_sink.laststate && XtIsRealized(text_widget)) - XCopyPlane(XtDisplay(text_widget), - sink->multi_sink.insertCursorOn, - XtWindow(text_widget), sink->multi_sink.xorgc, - 0, 0, (unsigned int) rect.width, (unsigned int) rect.height, - (int) rect.x, (int) rect.y, 1); sink->multi_sink.laststate = state; + sink->multi_sink.cursor_position = position; } /* - * Given two positions, find the distance between them. + * Given two positions, find the distance between them */ - static void -FindDistance (w, fromPos, fromx, toPos, resWidth, resPos, resHeight) - Widget w; - XawTextPosition fromPos; /* First position. */ - int fromx; /* Horizontal location of first position. */ - XawTextPosition toPos; /* Second position. */ - int* resWidth; /* Distance between fromPos and resPos. */ - XawTextPosition* resPos; /* Actual second position used. */ - int* resHeight; /* Height required. */ +FindDistance(Widget w, XawTextPosition fromPos, int fromx, + XawTextPosition toPos, int *resWidth, + XawTextPosition *resPos, int *resHeight) { - MultiSinkObject sink = (MultiSinkObject) w; - Widget source = XawTextGetSource(XtParent(w)); - - XawTextPosition index, lastPos; + MultiSinkObject sink = (MultiSinkObject)w; + XFontSet fontset = sink->multi_sink.fontset; + TextWidget ctx = (TextWidget)XtParent(w); + Widget source = ctx->text.source; + XawTextPosition idx, pos; wchar_t c; - XFontSetExtents *ext = XExtentsOfFontSet(sink->multi_sink.fontset); + XFontSetExtents *ext = XExtentsOfFontSet(fontset); XawTextBlock blk; - - /* we may not need this */ - lastPos = GETLASTPOS; - XawTextSourceRead(source, fromPos, &blk, (int) toPos - fromPos); - *resWidth = 0; - for (index = fromPos; index != toPos && index < lastPos; index++) { - if (index - blk.firstPos >= blk.length) - XawTextSourceRead(source, index, &blk, (int) toPos - fromPos); - c = ((wchar_t *)blk.ptr)[index - blk.firstPos]; - *resWidth += CharWidth(w, fromx + *resWidth, c); + int i, rWidth; + + pos = XawTextSourceRead(source, fromPos, &blk, toPos - fromPos); + rWidth = 0; + for (i = 0, idx = fromPos; idx < toPos; i++, idx++) { + if (i >= blk.length) { + i = 0; + XawTextSourceRead(source, pos, &blk, toPos - pos); + if (blk.length == 0) + break; + } + c = ((wchar_t *)blk.ptr)[i]; + rWidth += CharWidth(sink, fontset, fromx + rWidth, c); if (c == _Xaw_atowc(XawLF)) { - index++; + idx++; break; } } - *resPos = index; + + *resPos = idx; + *resWidth = rWidth; *resHeight = ext->max_logical_extent.height; } - static void -FindPosition(w, fromPos, fromx, width, stopAtWordBreak, resPos, resWidth, resHeight) - Widget w; - XawTextPosition fromPos; /* Starting position. */ - int fromx; /* Horizontal location of starting position.*/ - int width; /* Desired width. */ - int stopAtWordBreak; /* Whether the resulting position should be at - a word break. */ - XawTextPosition *resPos; /* Resulting position. */ - int* resWidth; /* Actual width used. */ - int* resHeight; /* Height required. */ +FindPosition(Widget w, XawTextPosition fromPos, int fromx, int width, + Bool stopAtWordBreak, XawTextPosition *resPos, int *resWidth, + int *resHeight) { - MultiSinkObject sink = (MultiSinkObject) w; - Widget source = XawTextGetSource(XtParent(w)); - - XawTextPosition lastPos, index, whiteSpacePosition; - int lastWidth, whiteSpaceWidth; + MultiSinkObject sink = (MultiSinkObject)w; + TextWidget ctx = (TextWidget)XtParent(w); + Widget source = ctx->text.source; + XFontSet fontset = sink->multi_sink.fontset; + XawTextPosition idx, pos, whiteSpacePosition = 0; + int i, lastWidth, whiteSpaceWidth, rWidth; Boolean whiteSpaceSeen; wchar_t c; - XFontSetExtents *ext = XExtentsOfFontSet(sink->multi_sink.fontset); + XFontSetExtents *ext = XExtentsOfFontSet(fontset); XawTextBlock blk; - lastPos = GETLASTPOS; - - XawTextSourceRead(source, fromPos, &blk, BUFSIZ); - *resWidth = 0; - whiteSpaceSeen = FALSE; + pos = XawTextSourceRead(source, fromPos, &blk, BUFSIZ); + rWidth = lastWidth = whiteSpaceWidth = 0; + whiteSpaceSeen = False; c = 0; - for (index = fromPos; *resWidth <= width && index < lastPos; index++) { - lastWidth = *resWidth; - if (index - blk.firstPos >= blk.length) - XawTextSourceRead(source, index, &blk, BUFSIZ); - c = ((wchar_t *)blk.ptr)[index - blk.firstPos]; - *resWidth += CharWidth(w, fromx + *resWidth, c); - - if ((c == _Xaw_atowc(XawSP) || c == _Xaw_atowc(XawTAB)) && - *resWidth <= width) { - whiteSpaceSeen = TRUE; - whiteSpacePosition = index; - whiteSpaceWidth = *resWidth; + + for (i = 0, idx = fromPos; rWidth <= width; i++, idx++) { + if (i >= blk.length) { + i = 0; + pos = XawTextSourceRead(source, pos, &blk, BUFSIZ); + if (blk.length == 0) + break; } + c = ((wchar_t *)blk.ptr)[i]; + lastWidth = rWidth; + rWidth += CharWidth(sink, fontset, fromx + rWidth, c); + if (c == _Xaw_atowc(XawLF)) { - index++; + idx++; break; } + else if ((c == _Xaw_atowc(XawSP) || c == _Xaw_atowc(XawTAB)) + && rWidth <= width) { + whiteSpaceSeen = True; + whiteSpacePosition = idx; + whiteSpaceWidth = rWidth; + } } - if (*resWidth > width && index > fromPos) { - *resWidth = lastWidth; - index--; + + if (rWidth > width && idx > fromPos) { + idx--; + rWidth = lastWidth; if (stopAtWordBreak && whiteSpaceSeen) { - index = whiteSpacePosition + 1; - *resWidth = whiteSpaceWidth; + idx = whiteSpacePosition + 1; + rWidth = whiteSpaceWidth; } } - if (index == lastPos && c != _Xaw_atowc(XawLF)) index = lastPos + 1; - *resPos = index; + + if (idx >= ctx->text.lastPos && c != _Xaw_atowc(XawLF)) + idx = ctx->text.lastPos + 1; + + *resPos = idx; + *resWidth = rWidth; *resHeight = ext->max_logical_extent.height; } static void -Resolve (w, pos, fromx, width, leftPos, rightPos) - Widget w; - XawTextPosition pos; - int fromx, width; - XawTextPosition *leftPos, *rightPos; +Resolve(Widget w, XawTextPosition pos, int fromx, int width, + XawTextPosition *pos_return) { int resWidth, resHeight; Widget source = XawTextGetSource(XtParent(w)); - FindPosition(w, pos, fromx, width, FALSE, leftPos, &resWidth, &resHeight); - if (*leftPos > GETLASTPOS) - *leftPos = GETLASTPOS; - *rightPos = *leftPos; + FindPosition(w, pos, fromx, width, False, pos_return, &resWidth, &resHeight); + if (*pos_return > GETLASTPOS) + *pos_return = GETLASTPOS; } static void -GetGC(sink) - MultiSinkObject sink; +GetGC(MultiSinkObject sink) { - XtGCMask valuemask = (GCGraphicsExposures | GCForeground | GCBackground ); + XtGCMask valuemask = (GCGraphicsExposures | GCClipXOrigin | + GCForeground | GCBackground); XGCValues values; - values.graphics_exposures = (Bool) FALSE; + /* XXX We dont want do share a gc that will change the clip-mask */ + values.clip_x_origin = (long)sink; + values.clip_mask = None; + values.graphics_exposures = False; values.foreground = sink->text_sink.foreground; values.background = sink->text_sink.background; - sink->multi_sink.normgc = XtAllocateGC( (Widget)sink, 0, valuemask, &values, GCFont, 0 ); - + sink->multi_sink.normgc = XtAllocateGC((Widget)sink, 0, valuemask, &values, + GCFont | GCClipMask, 0); + values.foreground = sink->text_sink.background; +#ifndef OLDXAW + values.background = sink->text_sink.cursor_color; +#else values.background = sink->text_sink.foreground; - sink->multi_sink.invgc = XtAllocateGC( (Widget)sink, 0, valuemask, &values, GCFont, 0 ); - - values.function = GXxor; - values.background = (unsigned long) 0L; /* (pix ^ 0) = pix */ - values.foreground = (sink->text_sink.background ^ - sink->text_sink.foreground); - valuemask = GCGraphicsExposures | GCFunction | GCForeground | GCBackground; - - /* if this GC is not used for fontset rendering then AllocateGC aint needed. Dont hurt tho.*/ - sink->multi_sink.xorgc = XtAllocateGC( (Widget)sink, 0, valuemask, &values, GCFont, 0 ); -} +#endif + sink->multi_sink.invgc = XtAllocateGC((Widget)sink, 0, valuemask, &values, + GCFont | GCClipMask, 0); +#ifndef OLDXAW + if (sink->text_sink.cursor_color != sink->text_sink.foreground) { + values.foreground = sink->text_sink.cursor_color; + values.background = sink->text_sink.foreground; + sink->multi_sink.xorgc = XtAllocateGC((Widget)sink, 0, valuemask, + &values, GCFont | GCClipMask, 0); + } + else +#endif /* OLDXAW */ + sink->multi_sink.xorgc = NULL; + XawMultiSinkResize((Widget)sink); +} -/***** Public routines *****/ +static void +XawMultiSinkClassInitialize(void) +{ + wspace[0] = _Xaw_atowc(XawSP); + XawInitializeWidgetSet(); +} -/* Function Name: Initialize - * Description: Initializes the TextSink Object. - * Arguments: request, new - the requested and new values for the object - * instance. - * Returns: none. +/* + * Function: + * XawMultiSinkInitialize + * + * Parameters: + * request - requested and new values for the object instance + * cnew - "" * + * Description: + * Initializes the TextSink Object. */ - /* ARGSUSED */ static void -Initialize(request, new, args, num_args) - Widget request, new; - ArgList args; - Cardinal* num_args; +XawMultiSinkInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - MultiSinkObject sink = (MultiSinkObject) new; + MultiSinkObject sink = (MultiSinkObject)cnew; GetGC(sink); - - sink->multi_sink.insertCursorOn= CreateInsertCursor(XtScreenOfObject(new)); + + sink->multi_sink.cursor_position = 0; sink->multi_sink.laststate = XawisOff; sink->multi_sink.cursor_x = sink->multi_sink.cursor_y = 0; } -/* Function Name: Destroy - * Description: This function cleans up when the object is - * destroyed. - * Arguments: w - the MultiSink Object. - * Returns: none. +/* + * Function: + * XawMultiSinkDestroy + * + * Parameters: + * w - MultiSink Object + * + * Description: + * This function cleans up when the object is destroyed. */ - static void -Destroy(w) - Widget w; +XawMultiSinkDestroy(Widget w) { - MultiSinkObject sink = (MultiSinkObject) w; - - XtReleaseGC(w, sink->multi_sink.normgc); - XtReleaseGC(w, sink->multi_sink.invgc); - XtReleaseGC(w, sink->multi_sink.xorgc); + MultiSinkObject sink = (MultiSinkObject)w; + + XtReleaseGC(w, sink->multi_sink.normgc); + XtReleaseGC(w, sink->multi_sink.invgc); + if (sink->multi_sink.xorgc) + XtReleaseGC(w, sink->multi_sink.xorgc); + sink->multi_sink.normgc = + sink->multi_sink.invgc = + sink->multi_sink.xorgc = NULL; +} - XFreePixmap(XtDisplayOfObject(w), sink->multi_sink.insertCursorOn); +static void +XawMultiSinkResize(Widget w) +{ + TextWidget ctx = (TextWidget)XtParent(w); + MultiSinkObject sink = (MultiSinkObject)w; + XRectangle rect; + int width, height; + + if (w->core.widget_class != multiSinkObjectClass) + return; + + rect.x = ctx->text.r_margin.left; + rect.y = ctx->text.r_margin.top; + width = (int)XtWidth(ctx) - + (int)ctx->text.r_margin.right - (int)ctx->text.r_margin.left; + height = (int)XtHeight(ctx) - + (int)ctx->text.r_margin.top - (int)ctx->text.r_margin.bottom; + rect.width = width; + rect.height = height; + + if (sink->multi_sink.normgc) { + if (width >= 0 && height >= 0) + XSetClipRectangles(XtDisplay((Widget)ctx), sink->multi_sink.normgc, + 0, 0, &rect, 1, Unsorted); + else + XSetClipMask(XtDisplay((Widget)ctx), sink->multi_sink.normgc, None); + } + if (sink->multi_sink.invgc) { + if (width >= 0 && height >= 0) + XSetClipRectangles(XtDisplay((Widget)ctx), sink->multi_sink.invgc, + 0, 0, &rect, 1, Unsorted); + else + XSetClipMask(XtDisplay((Widget)ctx), sink->multi_sink.invgc, None); + } + if (sink->multi_sink.xorgc) { + if (width >= 0 && height >= 0) + XSetClipRectangles(XtDisplay((Widget)ctx), sink->multi_sink.xorgc, + 0, 0, &rect, 1, Unsorted); + else + XSetClipMask(XtDisplay((Widget)ctx), sink->multi_sink.xorgc, None); + } } -/* Function Name: SetValues - * Description: Sets the values for the MultiSink - * Arguments: current - current state of the object. - * request - what was requested. - * new - what the object will become. - * Returns: True if redisplay is needed. +/* + * Function: + * XawMultiSinkSetValues + * + * Parameters: + * current - current state of the object + * request - what was requested + * cnew - what the object will become + * + * Description: + * Sets the values for the MultiSink. + * + * Returns: + * True if redisplay is needed */ - -/* ARGSUSED */ +/*ARGSUSED*/ static Boolean -SetValues(current, request, new, args, num_args) - Widget current, request, new; - ArgList args; - Cardinal* num_args; +XawMultiSinkSetValues(Widget current, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - MultiSinkObject w = (MultiSinkObject) new; - MultiSinkObject old_w = (MultiSinkObject) current; + MultiSinkObject w = (MultiSinkObject)cnew; + MultiSinkObject old_w = (MultiSinkObject)current; /* Font set is not in the GC! Do not make a new GC when font set changes! */ - if ( w->multi_sink.fontset != old_w->multi_sink.fontset ) { - ((TextWidget)XtParent(new))->text.redisplay_needed = True; + if (w->multi_sink.fontset != old_w->multi_sink.fontset) { + ((TextWidget)XtParent(cnew))->text.redisplay_needed = True; #ifndef NO_TAB_FIX - SetTabs( w, w->text_sink.tab_count, w->text_sink.char_tabs ); + SetTabs((Widget)w, w->text_sink.tab_count, w->text_sink.char_tabs); #endif } - if ( w->text_sink.background != old_w->text_sink.background || - w->text_sink.foreground != old_w->text_sink.foreground ) { - - XtReleaseGC((Widget)w, w->multi_sink.normgc); - XtReleaseGC((Widget)w, w->multi_sink.invgc); - XtReleaseGC((Widget)w, w->multi_sink.xorgc); + if (w->text_sink.background != old_w->text_sink.background + || w->text_sink.foreground != old_w->text_sink.foreground +#ifndef OLDXAW + || w->text_sink.cursor_color != old_w->text_sink.cursor_color +#endif + ) { + XtReleaseGC(cnew, w->multi_sink.normgc); + XtReleaseGC(cnew, w->multi_sink.invgc); + if (w->multi_sink.xorgc) + XtReleaseGC(cnew, w->multi_sink.xorgc); GetGC(w); - ((TextWidget)XtParent(new))->text.redisplay_needed = True; - } else { - if ( (w->multi_sink.echo != old_w->multi_sink.echo) || - (w->multi_sink.display_nonprinting != - old_w->multi_sink.display_nonprinting) ) - ((TextWidget)XtParent(new))->text.redisplay_needed = True; + ((TextWidget)XtParent(cnew))->text.redisplay_needed = True; } - - return False; + else if (w->multi_sink.echo != old_w->multi_sink.echo + || w->multi_sink.display_nonprinting + != old_w->multi_sink.display_nonprinting) + ((TextWidget)XtParent(cnew))->text.redisplay_needed = True; + + return (False); } -/* Function Name: MaxLines - * Description: Finds the Maximum number of lines that will fit in - * a given height. - * Arguments: w - the MultiSink Object. - * height - height to fit lines into. - * Returns: the number of lines that will fit. +/* + * Function: + * MaxLines + * + * Parameters: + * w - MultiSink Object + * height - height to fit lines into + * + * Description: + * Finds the Maximum number of lines that will fit in a given height. + * + * Returns: + * The number of lines that will fit */ - -/* ARGSUSED */ +/*ARGSUSED*/ static int -MaxLines(w, height) - Widget w; - Dimension height; +MaxLines(Widget w, unsigned int height) { - MultiSinkObject sink = (MultiSinkObject) w; - int font_height; - XFontSetExtents *ext = XExtentsOfFontSet(sink->multi_sink.fontset); + MultiSinkObject sink = (MultiSinkObject)w; + int font_height; + XFontSetExtents *ext = XExtentsOfFontSet(sink->multi_sink.fontset); - font_height = ext->max_logical_extent.height; - return( ((int) height) / font_height ); + font_height = ext->max_logical_extent.height; + return (height / font_height); } -/* Function Name: MaxHeight - * Description: Finds the Minium height that will contain a given number - * lines. - * Arguments: w - the MultiSink Object. - * lines - the number of lines. - * Returns: the height. +/* + * Function: + * MaxHeight + * + * Parameters: + * w - MultiSink Object + * lines - number of lines + * + * Description: + * Finds the Minium height that will contain a given number lines. + * Returns: + * The height */ - -/* ARGSUSED */ +/*ARGSUSED*/ static int -#if NeedFunctionPrototypes -MaxHeight( - Widget w, - int lines ) -#else -MaxHeight( w, lines ) - Widget w; - int lines; -#endif +MaxHeight(Widget w, int lines) { - MultiSinkObject sink = (MultiSinkObject) w; - XFontSetExtents *ext = XExtentsOfFontSet(sink->multi_sink.fontset); + MultiSinkObject sink = (MultiSinkObject)w; + XFontSetExtents *ext = XExtentsOfFontSet(sink->multi_sink.fontset); - return(lines * ext->max_logical_extent.height); + return (lines * ext->max_logical_extent.height); } -/* Function Name: SetTabs - * Description: Sets the Tab stops. - * Arguments: w - the MultiSink Object. - * tab_count - the number of tabs in the list. - * tabs - the text positions of the tabs. - * Returns: none +/* + * Function: + * SetTabs + * + * Arguments: + * w - MultiSink Object + * tab_count - number of tabs in the list + * tabs - text positions of the tabs + * + * Description: + * Sets the Tab stops. */ - -static void -#if NeedFunctionPrototypes -SetTabs( - Widget w, - int tab_count, - short* tabs ) -#else -SetTabs( w, tab_count, tabs ) - Widget w; - int tab_count; - short* tabs; -#endif +static void +SetTabs(Widget w, int tab_count, short* tabs) { - MultiSinkObject sink = (MultiSinkObject) w; - int i; - Atom XA_FIGURE_WIDTH; - unsigned long figure_width = 0; - XFontStruct *font; - - /* - * Bug: - * Suppose the first font of fontset stores the unit of column. - * - * By Li Yuhong, Mar. 14, 1991 - */ - { XFontStruct **f_list; - char **f_name; - - (void) XFontsOfFontSet(sink->multi_sink.fontset, &f_list, &f_name); - font = f_list[0]; - } + MultiSinkObject sink = (MultiSinkObject)w; + int i; + Atom XA_FIGURE_WIDTH; + unsigned long figure_width = 0; + XFontStruct *font; -/* - * Find the figure width of the current font. - */ + /* + * Bug: + * Suppose the first font of fontset stores the unit of column. + * + * By Li Yuhong, Mar. 14, 1991 + */ + { + XFontStruct **f_list; + char **f_name; - XA_FIGURE_WIDTH = XInternAtom(XtDisplayOfObject(w), "FIGURE_WIDTH", FALSE); - if ( (XA_FIGURE_WIDTH != None) && - ( (!XGetFontProperty(font, XA_FIGURE_WIDTH, &figure_width)) || - (figure_width == 0)) ) - if (font->per_char && font->min_char_or_byte2 <= '$' && - font->max_char_or_byte2 >= '$') - figure_width = font->per_char['$' - font->min_char_or_byte2].width; - else - figure_width = font->max_bounds.width; - - if (tab_count > sink->text_sink.tab_count) { - sink->text_sink.tabs = (Position *) - XtRealloc((char *) sink->text_sink.tabs, - (Cardinal) (tab_count * sizeof(Position))); - sink->text_sink.char_tabs = (short *) - XtRealloc((char *) sink->text_sink.char_tabs, - (Cardinal) (tab_count * sizeof(short))); - } + (void)XFontsOfFontSet(sink->multi_sink.fontset, &f_list, &f_name); + font = f_list[0]; + } - for ( i = 0 ; i < tab_count ; i++ ) { - sink->text_sink.tabs[i] = tabs[i] * figure_width; - sink->text_sink.char_tabs[i] = tabs[i]; - } - - sink->text_sink.tab_count = tab_count; + /* + * Find the figure width of the current font + */ + XA_FIGURE_WIDTH = XInternAtom(XtDisplayOfObject(w), "FIGURE_WIDTH", False); + if (XA_FIGURE_WIDTH != None + && (!XGetFontProperty(font, XA_FIGURE_WIDTH, &figure_width) + || figure_width == 0)) { + if (font->per_char && font->min_char_or_byte2 <= '$' + && font->max_char_or_byte2 >= '$') + figure_width = font->per_char['$' - font->min_char_or_byte2].width; + else + figure_width = font->max_bounds.width; + } + + if (tab_count > sink->text_sink.tab_count) { + sink->text_sink.tabs = (Position *) + XtRealloc((char *)sink->text_sink.tabs, + (Cardinal)(tab_count * sizeof(Position))); + sink->text_sink.char_tabs = (short *) + XtRealloc((char *)sink->text_sink.char_tabs, + (Cardinal)(tab_count * sizeof(short))); + } + + for (i = 0 ; i < tab_count ; i++) { + sink->text_sink.tabs[i] = tabs[i] * figure_width; + sink->text_sink.char_tabs[i] = tabs[i]; + } + + sink->text_sink.tab_count = tab_count; #ifndef NO_TAB_FIX - ((TextWidget)XtParent(w))->text.redisplay_needed = True; + ((TextWidget)XtParent(w))->text.redisplay_needed = True; #endif } void -#if NeedFunctionPrototypes -_XawMultiSinkPosToXY( - Widget w, - XawTextPosition pos, - Position *x, - Position *y ) -#else -_XawMultiSinkPosToXY( w, pos, x, y ) - Widget w; - XawTextPosition pos; - Position *x, *y; -#endif +_XawMultiSinkPosToXY(Widget w, XawTextPosition pos, Position *x, Position *y) { - MultiSinkObject sink = (MultiSinkObject) ((TextWidget)w)->text.sink; - XFontSetExtents *ext = XExtentsOfFontSet( sink->multi_sink.fontset ); + MultiSinkObject sink = (MultiSinkObject)((TextWidget)w)->text.sink; + XFontSetExtents *ext = XExtentsOfFontSet(sink->multi_sink.fontset); - _XawTextPosToXY( w, pos, x, y ); - *y += abs( ext->max_logical_extent.y ); + _XawTextPosToXY(w, pos, x, y); + *y += abs(ext->max_logical_extent.y); } diff --git a/src/MultiSrc.c b/src/MultiSrc.c index 671e6b5..102f664 100644 --- a/src/MultiSrc.c +++ b/src/MultiSrc.c @@ -27,6 +27,7 @@ * * Much code taken from X11R3 String and Disk Sources. */ +/* $XFree86: xc/lib/Xaw/MultiSrc.c,v 1.29 2002/12/06 16:19:57 paulo Exp $ */ /* @@ -54,77 +55,28 @@ in this Software without prior written authorization from The Open Group. */ -/* - * MultiSrc.c - MultiSrc object. (For use with the text widget). - * - */ - +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <errno.h> #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> #include <X11/Xfuncs.h> +#include <X11/Xos.h> +#include <X11/Xmu/CharSet.h> +#include <X11/Xmu/Misc.h> #include <X11/Xaw/XawInit.h> #include <X11/Xaw/MultiSrcP.h> #include <X11/Xaw/XawImP.h> -#include <X11/Xmu/Misc.h> -#include <X11/Xmu/CharSet.h> #include "XawI18n.h" -#include <X11/Xos.h> -#include <stdio.h> -#include <ctype.h> -#include <errno.h> - -/**************************************************************** - * - * Full class record constant - * - ****************************************************************/ - -/* Private Data */ - -static int magic_value = MAGIC_VALUE; +#include "Private.h" -#define offset(field) XtOffsetOf(MultiSrcRec, multi_src.field) +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> -static XtResource resources[] = { - {XtNstring, XtCString, XtRString, sizeof (XtPointer), - offset(string), XtRPointer, NULL}, - {XtNtype, XtCType, XtRMultiType, sizeof (XawAsciiType), - offset(type), XtRImmediate, (XtPointer)XawAsciiString}, - /* not used. */ - {XtNdataCompression, XtCDataCompression, XtRBoolean, sizeof (Boolean), - offset(data_compression), XtRImmediate, (XtPointer) FALSE}, - {XtNpieceSize, XtCPieceSize, XtRInt, sizeof (XawTextPosition), - offset(piece_size), XtRImmediate, (XtPointer) BUFSIZ}, - {XtNcallback, XtCCallback, XtRCallback, sizeof(XtPointer), - offset(callback), XtRCallback, (XtPointer)NULL}, - {XtNuseStringInPlace, XtCUseStringInPlace, XtRBoolean, sizeof (Boolean), - offset(use_string_in_place), XtRImmediate, (XtPointer) FALSE}, - {XtNlength, XtCLength, XtRInt, sizeof (int), - offset(multi_length), XtRInt, (XtPointer) &magic_value}, - -}; -#undef offset - -static XawTextPosition Scan(), Search(), ReadText(); -static int ReplaceText(); -static MultiPiece * FindPiece(), * AllocNewPiece(); -static FILE * InitStringOrFile(); -static void FreeAllPieces(), RemovePiece(), BreakPiece(), LoadPieces(); -static void RemoveOldStringOrFile(), CvtStringToMultiType(); -static void ClassInitialize(), Initialize(), Destroy(), GetValuesHook(); -static String StorePiecesInString(); -static Boolean SetValues(), WriteToFile(); - -#define MyWStrncpy( t,s,wcnt ) (void) memmove( (t), (s), (wcnt)*sizeof(wchar_t)) - -#ifndef MyWStrncpy -static void (MyWStrncpy)(); -#endif - -extern char *tmpnam(); -#ifdef X_NOT_STDC_ENV -extern int errno; -#endif +#define MAGIC_VALUE ((XawTextPosition)-1) +#define streq(a, b) (strcmp((a), (b)) == 0) #ifdef X_NOT_POSIX #define Off_t long @@ -134,969 +86,1113 @@ extern int errno; #define Size_t size_t #endif -extern wchar_t* _XawTextMBToWC(); -extern char *_XawTextWCToMB(); + +/* + * Class Methods + */ +static XawTextPosition ReadText(Widget, XawTextPosition, XawTextBlock*, int); +static int ReplaceText(Widget, XawTextPosition, XawTextPosition, + XawTextBlock*); +static XawTextPosition Scan(Widget, XawTextPosition, XawTextScanType, + XawTextScanDirection, int, Bool); +static XawTextPosition Search(Widget, XawTextPosition, XawTextScanDirection, + XawTextBlock*); +static void XawMultiSrcClassInitialize(void); +static void XawMultiSrcDestroy(Widget); +static void XawMultiSrcInitialize(Widget, Widget, ArgList, Cardinal*); +static Boolean XawMultiSrcSetValues(Widget, Widget, Widget, + ArgList, Cardinal*); +static void XawMultiSrcGetValuesHook(Widget, ArgList, Cardinal*); + +/* + * Prototypes + */ +static MultiPiece *AllocNewPiece(MultiSrcObject, MultiPiece*); +static void BreakPiece(MultiSrcObject, MultiPiece*); +static Boolean CvtMultiTypeToString(Display*, XrmValuePtr, Cardinal*, + XrmValuePtr, XrmValuePtr, XtPointer*); +static void CvtStringToMultiType(XrmValuePtr, Cardinal*, + XrmValuePtr, XrmValuePtr); +static MultiPiece *FindPiece(MultiSrcObject, XawTextPosition, + XawTextPosition*); +static void FreeAllPieces(MultiSrcObject); +static FILE *InitStringOrFile(MultiSrcObject, Bool); +static void LoadPieces(MultiSrcObject, FILE*, char*); +static void RemovePiece(MultiSrcObject, MultiPiece*); +static void RemoveOldStringOrFile(MultiSrcObject, Bool); +static String StorePiecesInString(MultiSrcObject); +static Bool WriteToFile(String, String); +static void GetDefaultPieceSize(Widget, int, XrmValue*); + +/* + * Initialization + */ +#define offset(field) XtOffsetOf(MultiSrcRec, multi_src.field) +static XtResource resources[] = { + { + XtNstring, + XtCString, + XtRString, + sizeof(XtPointer), + offset(string), + XtRPointer, + NULL + }, + { + XtNtype, + XtCType, + XtRMultiType, + sizeof(XawAsciiType), + offset(type), + XtRImmediate, + (XtPointer)XawAsciiString + }, + { + XtNdataCompression, + XtCDataCompression, + XtRBoolean, + sizeof(Boolean), + offset(data_compression), + XtRImmediate, + (XtPointer)False + }, + { + XtNpieceSize, + XtCPieceSize, + XtRInt, + sizeof(XawTextPosition), + offset(piece_size), + XtRCallProc, + (XtPointer)GetDefaultPieceSize + }, +#ifdef OLDXAW + { + XtNcallback, + XtCCallback, + XtRCallback, + sizeof(XtPointer), + offset(callback), + XtRCallback, + (XtPointer)NULL + }, +#endif + { + XtNuseStringInPlace, + XtCUseStringInPlace, + XtRBoolean, + sizeof(Boolean), + offset(use_string_in_place), + XtRImmediate, + (XtPointer)False + }, + { + XtNlength, + XtCLength, + XtRInt, + sizeof(int), + offset(multi_length), + XtRImmediate, + (XtPointer)MAGIC_VALUE + }, +}; +#undef offset #define superclass (&textSrcClassRec) MultiSrcClassRec multiSrcClassRec = { - { /* object_class fields */ - /* superclass */ (WidgetClass) superclass, - /* class_name */ "MultiSrc", - /* widget_size */ sizeof(MultiSrcRec), - /* class_initialize */ ClassInitialize, - /* class_part_initialize */ NULL, - /* class_inited */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* pad */ NULL, - /* pad */ NULL, - /* pad */ 0, - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* pad */ FALSE, - /* pad */ FALSE, - /* pad */ FALSE, - /* pad */ FALSE, - /* destroy */ Destroy, - /* pad */ NULL, - /* pad */ NULL, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* pad */ NULL, - /* get_values_hook */ GetValuesHook, - /* pad */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* pad */ NULL, - /* pad */ NULL, - /* pad */ NULL, - /* extension */ NULL + /* object */ + { + (WidgetClass)superclass, /* superclass */ + "MultiSrc", /* class_name */ + sizeof(MultiSrcRec), /* widget_size */ + XawMultiSrcClassInitialize, /* class_initialize */ + NULL, /* class_part_initialize */ + False, /* class_inited */ + XawMultiSrcInitialize, /* initialize */ + NULL, /* initialize_hook */ + NULL, /* obj1 */ + NULL, /* obj2 */ + 0, /* obj3 */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + False, /* obj4 */ + False, /* obj5 */ + False, /* obj6 */ + False, /* obj7 */ + XawMultiSrcDestroy, /* destroy */ + NULL, /* obj8 */ + NULL, /* obj9 */ + XawMultiSrcSetValues, /* set_values */ + NULL, /* set_values_hook */ + NULL, /* obj10 */ + XawMultiSrcGetValuesHook, /* get_values_hook */ + NULL, /* obj11 */ + XtVersion, /* version */ + NULL, /* callback_private */ + NULL, /* obj12 */ + NULL, /* obj13 */ + NULL, /* obj14 */ + NULL, /* extension */ + }, + /* text_src */ + { + ReadText, /* Read */ + ReplaceText, /* Replace */ + Scan, /* Scan */ + Search, /* Search */ + XtInheritSetSelection, /* SetSelection */ + XtInheritConvertSelection, /* ConvertSelection */ }, - { /* textSrc_class fields */ - /* Read */ ReadText, - /* Replace */ ReplaceText, - /* Scan */ Scan, - /* Search */ Search, - /* SetSelection */ XtInheritSetSelection, - /* ConvertSelection */ XtInheritConvertSelection + /* multi_src */ + { + NULL, /* extension */ }, - { /* multiSrc_class fields */ - /* Keep the compiler happy */ '\0' - } }; WidgetClass multiSrcObjectClass = (WidgetClass)&multiSrcClassRec; -/************************************************************ - * - * Semi-Public Interfaces. - * - ************************************************************/ +static XrmQuark Qstring, Qfile; -/* Function Name: ClassInitialize - * Description: Class Initialize routine, called only once. - * Arguments: none. - * Returns: none. +/* + * Implementation */ - static void -ClassInitialize() +XawMultiSrcClassInitialize(void) { - XawInitializeWidgetSet(); - XtAddConverter( XtRString, XtRMultiType, CvtStringToMultiType, - NULL, (Cardinal) 0); + XawInitializeWidgetSet(); + Qstring = XrmPermStringToQuark(XtEstring); + Qfile = XrmPermStringToQuark(XtEfile); + XtAddConverter(XtRString, XtRMultiType, CvtStringToMultiType, NULL, 0); + XtSetTypeConverter(XtRMultiType, XtRString, CvtMultiTypeToString, NULL, 0, + XtCacheNone, NULL); } -/* Function Name: Initialize - * Description: Initializes the simple menu widget - * Arguments: request - the widget requested by the argument list. - * new - the new widget with both resource and non - * resource values. - * Returns: none. +/* + * Function: + * XawMultiSrcInitialize + * + * Parameters: + * request - widget requested by the argument list + * cnew - the new widget with both resource and non resource values + * args - (unused) + * num_args - (unused) + * + * Description: + * Initializes the multi src object */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -Initialize(request, new, args, num_args) - Widget request, new; - ArgList args; - Cardinal* num_args; +XawMultiSrcInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - MultiSrcObject src = (MultiSrcObject) new; - FILE * file; - -/* - * Set correct flags (override resources) depending upon widget class. - */ + MultiSrcObject src = (MultiSrcObject)cnew; + FILE *file; - src->multi_src.changes = FALSE; - src->multi_src.allocated_string = FALSE; + /* + * Set correct flags (override resources) depending upon widget class + */ +#ifdef OLDXAW + src->multi_src.changes = False; +#else + src->text_src.changed = False; +#endif + src->multi_src.allocated_string = False; - file = InitStringOrFile(src, src->multi_src.type == XawAsciiFile); - LoadPieces(src, file, NULL); + if (src->multi_src.use_string_in_place && src->multi_src.string == NULL) + src->multi_src.use_string_in_place = False; - if (file != NULL) fclose(file); - src->text_src.text_format = XawFmtWide; + file = InitStringOrFile(src, src->multi_src.type == XawAsciiFile); + LoadPieces(src, file, NULL); + if (file != NULL) + fclose(file); + src->text_src.text_format = XawFmtWide; } -/* Function Name: ReadText - * Description: This function reads the source. - * Arguments: w - the MultiSource widget. - * pos - position of the text to retreive. - * RETURNED text - text block that will contain returned text. - * length - maximum number of characters to read. - * Returns: The number of characters read into the buffer. +/* + * Function: + * ReadText + * + * Parameters: + * w - MultiSource object + * pos - position of the text to retrieve + * text - text block that will contain returned text + * length - maximum number of characters to read + * + * Description: + * This function reads the source. + * + * Returns: + * The character position following the retrieved text. */ - static XawTextPosition -ReadText(w, pos, text, length) - Widget w; - XawTextPosition pos; - XawTextBlock* text; - int length; +ReadText(Widget w, XawTextPosition pos, XawTextBlock *text, int length) { - MultiSrcObject src = (MultiSrcObject) w; - XawTextPosition count, start; - MultiPiece * piece = FindPiece(src, pos, &start); + MultiSrcObject src = (MultiSrcObject)w; + XawTextPosition count, start; + MultiPiece *piece = FindPiece(src, pos, &start); - text->format = XawFmtWide; - text->firstPos = pos; - text->ptr = (char *)(piece->text + (pos - start)); - count = piece->used - (pos - start); - text->length = (length > count) ? count : length; - return(pos + text->length); + text->format = XawFmtWide; + text->firstPos = pos; + text->ptr = (char *)(piece->text + (pos - start)); + count = piece->used - (pos - start); + text->length = Max(0, (length > count) ? count : length); + + return (pos + text->length); } -/* Function Name: ReplaceText. - * Description: Replaces a block of text with new text. - * Arguments: w - the MultiSource widget. - * startPos, endPos - ends of text that will be removed. - * text - new text to be inserted into buffer at startPos. - * Returns: XawEditError or XawEditDone. +/* + * Function: + * ReplaceText + * + * Parameters: + * w - MultiSource object + * startPos - ends of text that will be removed + * endPos - "" + * text - new text to be inserted into buffer at startPos + * + * Description: + * Replaces a block of text with new text. + * + * Returns: + * XawEditDone on success, XawEditError otherwise */ - /*ARGSUSED*/ static int -ReplaceText( w, startPos, endPos, u_text_p) - Widget w; - XawTextPosition startPos, endPos; - XawTextBlock* u_text_p; +ReplaceText(Widget w, XawTextPosition startPos, XawTextPosition endPos, + XawTextBlock *u_text_p) { - MultiSrcObject src = (MultiSrcObject) w; - MultiPiece *start_piece, *end_piece, *temp_piece; - XawTextPosition start_first, end_first; - int length, firstPos; - wchar_t *wptr; - Boolean local_artificial_block = False; - XawTextBlock text; - - /* STEP 1: The user handed me a text block called `u_text' that may be - * in either FMTWIDE or FMT8BIT (ie MB.) Later code needs the block - * `text' to hold FMTWIDE. So, this copies `u_text' to `text', and if - * `u_text' was MB, I knock it up to WIDE. */ - - if ( u_text_p->length == 0 ) /* if so, the block contents never ref'd. */ - text.length = 0; - - else if ( u_text_p->format == XawFmtWide) { - local_artificial_block = False; /* ie, don't have to free it ourselves*/ - text.firstPos = u_text_p->firstPos; - text.length = u_text_p->length; - text.ptr = u_text_p->ptr; - /* text.format is unneeded */ - - } else { - /* WARNING! u_text->firstPos and length are in units of CHAR, not CHARACTERS! */ - - local_artificial_block = True; /* ie, have to free it ourselves */ - text.firstPos = 0; - text.length = u_text_p->length; /* _XawTextMBToWC converts this to wchar len. */ - - text.ptr = (char*)_XawTextMBToWC( XtDisplay(XtParent(w)), - &(u_text_p->ptr[u_text_p->firstPos]), &(text.length) ); - - /* I assert the following assignment is not needed - since Step 4 - depends on length, it has no need of a terminating NULL. I think - the ASCII-version has the same needless NULL. */ - /*((wchar_t*)text.ptr)[ text.length ] = NULL;*/ - } - - - /* STEP 2: some initialization... */ - - if (src->text_src.edit_mode == XawtextRead) - return(XawEditError); - - start_piece = FindPiece(src, startPos, &start_first); - end_piece = FindPiece(src, endPos, &end_first); - - - /* STEP 3: remove the empty pieces... */ - - if (start_piece != end_piece) { - temp_piece = start_piece->next; - - /* If empty and not the only piece then remove it. */ - - if ( ((start_piece->used = startPos - start_first) == 0) && - !((start_piece->next == NULL) && (start_piece->prev == NULL)) ) - RemovePiece(src, start_piece); - - while (temp_piece != end_piece) { - temp_piece = temp_piece->next; - RemovePiece(src, temp_piece->prev); - } - end_piece->used -= endPos - end_first; - if (end_piece->used != 0) - MyWStrncpy(end_piece->text, (end_piece->text + endPos - end_first), - (int) end_piece->used); - } - else { /* We are fully in one piece. */ - if ( (start_piece->used -= endPos - startPos) == 0) { - if ( !((start_piece->next == NULL) && (start_piece->prev == NULL)) ) - RemovePiece(src, start_piece); + MultiSrcObject src = (MultiSrcObject)w; + MultiPiece *start_piece, *end_piece, *temp_piece; + XawTextPosition start_first, end_first; + int length, firstPos; + wchar_t *wptr; + Bool local_artificial_block = False; + XawTextBlock text; + + /* STEP 1: The user handed me a text block called `u_text' that may be + * in either FMTWIDE or FMT8BIT (ie MB.) Later code needs the block + * `text' to hold FMTWIDE. So, this copies `u_text' to `text', and if + * `u_text' was MB, I knock it up to WIDE + */ + if (u_text_p->length == 0) /* if so, the block contents never ref'd */ + text.length = 0; + + else if (u_text_p->format == XawFmtWide) { + local_artificial_block = False; /* don't have to free it ourselves */ + text.firstPos = u_text_p->firstPos; + text.length = u_text_p->length; + text.ptr = u_text_p->ptr; } else { - MyWStrncpy(start_piece->text + (startPos - start_first), - start_piece->text + (endPos - start_first), - (int) (start_piece->used - (startPos - start_first)) ); - if ( src->multi_src.use_string_in_place && - ((src->multi_src.length - (endPos - startPos)) < - (src->multi_src.piece_size - 1)) ) - start_piece->text[src->multi_src.length - (endPos - startPos)] = (wchar_t)0; + /* + * WARNING! u_text->firstPos and length are in units of CHAR, + * not CHARACTERS! + */ + local_artificial_block = True; /* have to free it ourselves */ + text.firstPos = 0; + text.length = u_text_p->length; /* _XawTextMBToWC converts this + * to wchar len + */ + + text.ptr = (char*)_XawTextMBToWC(XtDisplay(XtParent(w)), + &u_text_p->ptr[u_text_p->firstPos], + &text.length); + + /* I assert the following assignment is not needed - since Step 4 + depends on length, it has no need of a terminating NULL. I think + the ASCII-version has the same needless NULL. */ + /*((wchar_t*)text.ptr)[ text.length ] = NULL;*/ } - } - src->multi_src.length += text.length -(endPos - startPos); - /*((TextWidget)src->object.parent)->text.lastPos = src->multi_src.length;*/ + /* STEP 2: some initialization... */ + if (src->text_src.edit_mode == XawtextRead) + return (XawEditError); + start_piece = FindPiece(src, startPos, &start_first); + end_piece = FindPiece(src, endPos, &end_first); + /* STEP 3: remove the empty pieces... */ + if (start_piece != end_piece) { + temp_piece = start_piece->next; - /* STEP 4: insert the new stuff */ + /* If empty and not the only piece then remove it */ + if (((start_piece->used = startPos - start_first) == 0) + && !(start_piece->next == NULL && start_piece->prev == NULL)) + RemovePiece(src, start_piece); + + while (temp_piece != end_piece) { + temp_piece = temp_piece->next; + RemovePiece(src, temp_piece->prev); + } + end_piece->used -= endPos - end_first; + if (end_piece->used != 0) + memmove(end_piece->text, end_piece->text + endPos - end_first, + end_piece->used * sizeof(wchar_t)); + } + else { /* We are fully in one piece */ + if ((start_piece->used -= endPos - startPos) == 0) { + if (!(start_piece->next == NULL && start_piece->prev == NULL)) + RemovePiece(src, start_piece); + } + else { + memmove(start_piece->text + (startPos - start_first), + start_piece->text + (endPos - start_first), + (start_piece->used - (startPos - start_first)) * + sizeof(wchar_t)); + if (src->multi_src.use_string_in_place && + ((src->multi_src.length - (endPos - startPos)) + < src->multi_src.piece_size - 1)) + start_piece->text[src->multi_src.length - (endPos - startPos)] = + (wchar_t)0; + } + } - if ( text.length != 0) { + src->multi_src.length += text.length -(endPos - startPos); - start_piece = FindPiece(src, startPos, &start_first); - - length = text.length; - firstPos = text.firstPos; + /* STEP 4: insert the new stuff */ + if ( text.length != 0) { + start_piece = FindPiece(src, startPos, &start_first); + length = text.length; + firstPos = text.firstPos; - while (length > 0) { - wchar_t* ptr; - int fill; + while (length > 0) { + wchar_t *ptr; + int fill; - if (src->multi_src.use_string_in_place) { - if (start_piece->used == (src->multi_src.piece_size - 1)) { - /* - * The string is used in place, then the string - * is not allowed to grow. - */ - start_piece->used = src->multi_src.length = - src->multi_src.piece_size - 1; - /*((TextWidget)src->object.parent)->text.lastPos = src->multi_src.length;*/ - - - start_piece->text[src->multi_src.length] = (wchar_t)0; - return(XawEditError); - } - } - + if (src->multi_src.use_string_in_place) { + if (start_piece->used == src->multi_src.piece_size - 1) { + + /* + * The string is used in place, then the string + * is not allowed to grow + */ + start_piece->used = src->multi_src.length = + src->multi_src.piece_size - 1; + + start_piece->text[src->multi_src.length] = (wchar_t)0; + return (XawEditError); + } + } - if (start_piece->used == src->multi_src.piece_size) { - BreakPiece(src, start_piece); - start_piece = FindPiece(src, startPos, &start_first); - } + if (start_piece->used == src->multi_src.piece_size) { + BreakPiece(src, start_piece); + start_piece = FindPiece(src, startPos, &start_first); + } - fill = Min((int)(src->multi_src.piece_size - start_piece->used), length); + fill = Min((int)(src->multi_src.piece_size - start_piece->used), length); - ptr = start_piece->text + (startPos - start_first); - MyWStrncpy(ptr + fill, ptr, - (int) start_piece->used - (startPos - start_first)); - wptr =(wchar_t *)text.ptr; - (void)wcsncpy(ptr, wptr + firstPos, fill); + ptr = start_piece->text + (startPos - start_first); + memmove(ptr + fill, ptr, (start_piece->used - + (startPos - start_first)) * sizeof(wchar_t)); + wptr =(wchar_t *)text.ptr; + (void)wcsncpy(ptr, wptr + firstPos, fill); - startPos += fill; - firstPos += fill; - start_piece->used += fill; - length -= fill; + startPos += fill; + firstPos += fill; + start_piece->used += fill; + length -= fill; + } } - } - - if ( local_artificial_block == True ) - /* In other words, text is not the u_text that the user handed me but - one I made myself. I only care, because I need to free the string. */ + if (local_artificial_block == True) + /* In other words, text is not the u_text that the user handed me but + one I made myself. I only care, because I need to free the string */ + XtFree(text.ptr); - XFree( text.ptr ); + if (src->multi_src.use_string_in_place) + start_piece->text[start_piece->used] = (wchar_t)0; - if (src->multi_src.use_string_in_place) - start_piece->text[start_piece->used] = (wchar_t)0; - - src->multi_src.changes = TRUE; - - XtCallCallbacks(w, XtNcallback, NULL); +#ifdef OLDXAW + src->multi_src.changes = True; + XtCallCallbacks(w, XtNcallback, NULL); +#endif - return(XawEditDone); + return (XawEditDone); } -/* Function Name: Scan - * Description: Scans the text source for the number and type - * of item specified. - * Arguments: w - the MultiSource widget. - * position - the position to start scanning. - * type - type of thing to scan for. - * dir - direction to scan. - * count - which occurance if this thing to search for. - * include - whether or not to include the character found in - * the position that is returned. - * Returns: the position of the item found. +/* + * Function: + * Scan + * + * Parameters: + * w - MultiSource widget + * position - position to start scanning + * type - type of thing to scan for + * dir - direction to scan + * count - which occurance if this thing to search for + * include - whether or not to include the character found in + * the position that is returned + * + * Description: + * Scans the text source for the number and type of item specified. * - * Note: While there are only 'n' characters in the file there are n+1 - * possible cursor positions (one before the first character and - * one after the last character. + * Returns: + * The position of the item found + * + * Note: + * While there are only 'n' characters in the file there are n+1 + * possible cursor positions (one before the first character and + * one after the last character */ - -static -XawTextPosition -Scan( w, position, type, dir, count, include ) - Widget w; - XawTextPosition position; - XawTextScanType type; - XawTextScanDirection dir; - int count; - Boolean include; +static XawTextPosition +Scan(Widget w, register XawTextPosition position, XawTextScanType type, + XawTextScanDirection dir, int count, Bool include) { - MultiSrcObject src = (MultiSrcObject) w; - int inc; - MultiPiece * piece; - XawTextPosition first, first_eol_position; - wchar_t * ptr; - - if (type == XawstAll) { /* Optimize this common case. */ - if (dir == XawsdRight) - return(src->multi_src.length); - return(0); /* else. */ - } - - - /* STEP 1: basic sanity checks */ - - if (position > src->multi_src.length) - position = src->multi_src.length; - + MultiSrcObject src = (MultiSrcObject)w; + register char inc; + MultiPiece *piece; + XawTextPosition first, first_eol_position = position; + register wchar_t *ptr; + int cnt = count; + + if (type == XawstAll) { + if (dir == XawsdRight) + return (src->multi_src.length); + return (0); + } - if ( dir == XawsdRight ) { - if (position == src->multi_src.length) - return(src->multi_src.length); - inc = 1; - } - else { - if (position == 0) - return(0); - inc = -1; - position--; - } + /* STEP 1: basic sanity checks */ + if (position > src->multi_src.length) + position = src->multi_src.length; - piece = FindPiece(src, position, &first); + if (dir == XawsdRight) { + if (position == src->multi_src.length) + return (src->multi_src.length); + inc = 1; + } + else { + if (position == 0) + return (0); + inc = -1; + position--; + } - if ( piece->used == 0 ) return(0); /* i.e., buffer is empty. */ + piece = FindPiece(src, position, &first); + + if (piece->used == 0) + return (0); + + ptr = (position - first) + piece->text; + + switch (type) { + case XawstEOL: + case XawstParagraph: + case XawstWhiteSpace: + case XawstAlphaNumeric: + for (; cnt > 0 ; cnt--) { + Bool non_space = False, first_eol = True; + + /*CONSTCOND*/ + while (True) { + register wchar_t c; + + if (ptr < piece->text) { + piece = piece->prev; + if (piece == NULL) /* Begining of text */ + return (0); + ptr = piece->text + piece->used - 1; + c = *ptr; + } + else if (ptr >= piece->text + piece->used) { + piece = piece->next; + if (piece == NULL) /* End of text */ + return (src->multi_src.length); + ptr = piece->text; + } + + c = *ptr; + ptr += inc; + position += inc; + + if (type == XawstAlphaNumeric) { + if (!iswalnum(c)) { + if (non_space) + break; + } + else + non_space = True; + } + else if (type == XawstWhiteSpace) { + if (iswspace(c)) { + if (non_space) + break; + } + else + non_space = True; + } + else if (type == XawstEOL) { + if (c == _Xaw_atowc(XawLF)) + break; + } + else { /* XawstParagraph */ + if (first_eol) { + if (c == _Xaw_atowc(XawLF)) { + first_eol_position = position; + first_eol = False; + } + } + else + if (c == _Xaw_atowc(XawLF)) + break; + else if (!iswspace(c)) + first_eol = True; + } + } + } + if (!include) { + if (type == XawstParagraph) + position = first_eol_position; + if (count) + position -= inc; + } + break; + case XawstPositions: + position += count * inc; + break; + default: + break; + } - ptr = (position - first) + piece->text; + if (dir == XawsdLeft) + position++; - switch (type) { - case XawstEOL: - case XawstParagraph: - case XawstWhiteSpace: - for ( ; count > 0 ; count-- ) { - Boolean non_space = FALSE, first_eol = TRUE; - /* CONSTCOND */ - while (TRUE) { - wchar_t c = *ptr; + if (position >= src->multi_src.length) + return (src->multi_src.length); + if (position < 0) + return (0); - ptr += inc; - position += inc; - - if (type == XawstWhiteSpace) { - if (iswspace(c)) { - if (non_space) - break; - } - else - non_space = TRUE; - } - else if (type == XawstEOL) { - if (c == _Xaw_atowc(XawLF)) break; - } - else { /* XawstParagraph */ - if (first_eol) { - if (c == _Xaw_atowc(XawLF)) { - first_eol_position = position; - first_eol = FALSE; - } - } - else - if ( c == _Xaw_atowc(XawLF)) - break; - else if ( !iswspace(c) ) - first_eol = TRUE; - } - - - if ( ptr < piece->text ) { - piece = piece->prev; - if (piece == NULL) /* Begining of text. */ - return(0); - ptr = piece->text + piece->used - 1; - } - else if ( ptr >= (piece->text + piece->used) ) { - piece = piece->next; - if (piece == NULL) /* End of text. */ - return(src->multi_src.length); - ptr = piece->text; - } - } - } - if (!include) { - if ( type == XawstParagraph) - position = first_eol_position; - position -= inc; - } - break; - case XawstPositions: - position += count * inc; - break; -/* case XawstAll: ---- handled in special code above */ - } - - if ( dir == XawsdLeft ) - position++; - - if (position >= src->multi_src.length) - return(src->multi_src.length); - if (position < 0) - return(0); - - return(position); + return (position); } -/* Function Name: Search - * Description: Searchs the text source for the text block passed - * Arguments: w - the MultiSource Widget. - * position - the position to start scanning. - * dir - direction to scan. - * text - the text block to search for. - * Returns: the position of the item found. +/* + * Function: + * Search + * + * Parameters: + * w - MultiSource objecy + * position - position to start scanning + * dir - direction to scan + * text - text block to search for + * + * Description: + * Searchs the text source for the text block passed. + * + * Returns: + * The position of the item found */ - static XawTextPosition -Search(w, position, dir, text ) - Widget w; - XawTextPosition position; - XawTextScanDirection dir; - XawTextBlock* text; +Search(Widget w, register XawTextPosition position, XawTextScanDirection dir, + XawTextBlock *text) { - MultiSrcObject src = (MultiSrcObject) w; - int inc, count = 0; - wchar_t * ptr; - wchar_t* wtarget; - int wtarget_len; - Display * d = XtDisplay(XtParent(w)); - MultiPiece * piece; - wchar_t* buf; - XawTextPosition first; - - - /* STEP 1: First, a brief sanity check. */ - - if ( dir == XawsdRight ) - inc = 1; - else { - inc = -1; - if (position == 0) - return(XawTextSearchError); /* scanning left from 0??? */ - position--; - } - + MultiSrcObject src = (MultiSrcObject)w; + register int count = 0; + wchar_t *ptr; + wchar_t *wtarget; + int wtarget_len; + Display *d = XtDisplay(XtParent(w)); + MultiPiece *piece; + wchar_t *buf; + XawTextPosition first; + register char inc; + int cnt; + + /* STEP 1: First, a brief sanity check */ + if (dir == XawsdRight) + inc = 1; + else { + inc = -1; + if (position == 0) + return (XawTextSearchError); + position--; + } - /* STEP 2: Ensure I have a local wide string.. */ + /* STEP 2: Ensure I have a local wide string.. */ - /* Since this widget stores 32bit chars, I check here to see if - I'm being passed a string claiming to be 8bit chars (ie, MB text.) - If that is the case, naturally I convert to 32bit format. */ + /* Since this widget stores 32bit chars, I check here to see if + I'm being passed a string claiming to be 8bit chars (ie, MB text.) + If that is the case, naturally I convert to 32bit format */ - /*if the block was FMT8BIT, length will convert to REAL wchar count below */ - wtarget_len = text->length; + /*if the block was FMT8BIT, length will convert to REAL wchar count bellow */ + wtarget_len = text->length; - if ( text->format == XawFmtWide ) - wtarget = &( ((wchar_t*)text->ptr) [text->firstPos] ); - else - { - /* The following converts wtarget_len from byte len to wchar count */ - wtarget = _XawTextMBToWC( d, &text->ptr[ text->firstPos ], &wtarget_len ); - } - - /* OK, I can now assert that wtarget holds wide characters, wtarget_len - holds an accurate count of those characters, and that firstPos has been - effectively factored out of the following computations. */ - - - /* STEP 3: SEARCH! */ - - buf = (wchar_t *)XtMalloc((unsigned)sizeof(wchar_t) * wtarget_len ); - (void)wcsncpy(buf, wtarget, wtarget_len ); - piece = FindPiece(src, position, &first); - ptr = (position - first) + piece->text; - - /* CONSTCOND */ - while (TRUE) { - if (*ptr == ((dir == XawsdRight) ? *(buf + count) - : *(buf + wtarget_len - count - 1)) ) { - if (count == (text->length - 1)) - break; - else - count++; - } + if (text->format == XawFmtWide) + wtarget = &(((wchar_t*)text->ptr) [text->firstPos]); else { - if (count != 0) { - position -=inc * count; - ptr -= inc * count; - } - count = 0; + /* The following converts wtarget_len from byte len to wchar count */ + wtarget = _XawTextMBToWC(d, &text->ptr[text->firstPos], &wtarget_len); } - ptr += inc; - position += inc; + /* OK, I can now assert that wtarget holds wide characters, wtarget_len + holds an accurate count of those characters, and that firstPos has been + effectively factored out of the following computations */ + + /* STEP 3: SEARCH! */ + buf = (wchar_t *)XtMalloc(sizeof(wchar_t) * wtarget_len); + (void)wcsncpy(buf, wtarget, wtarget_len); + piece = FindPiece(src, position, &first); + ptr = (position - first) + piece->text; + + /*CONSTCOND*/ + while (True) { + if (*ptr == (dir == XawsdRight ? *(buf + count) + : *(buf + wtarget_len - count - 1))) { + if (count == text->length - 1) + break; + else + count++; + } + else { + if (count != 0) { + position -=inc * count; + ptr -= inc * count; + } + count = 0; + } + + ptr += inc; + position += inc; - while ( ptr < piece->text ) { - piece = piece->prev; - if (piece == NULL) { /* Begining of text. */ - XtFree((char *)buf); - return(XawTextSearchError); - } - ptr = piece->text + piece->used - 1; - } + while (ptr < piece->text) { + cnt = piece->text - ptr; + + piece = piece->prev; + if (piece == NULL) { /* Begining of text */ + XtFree((char *)buf); + return (XawTextSearchError); + } + ptr = piece->text + piece->used - cnt; + } - while ( ptr >= (piece->text + piece->used) ) { - piece = piece->next; - if (piece == NULL) { /* End of text. */ - XtFree((char *)buf); - return(XawTextSearchError); - } - ptr = piece->text; + while (ptr >= piece->text + piece->used) { + cnt = ptr - (piece->text + piece->used); + + piece = piece->next; + if (piece == NULL) { /* End of text */ + XtFree((char *)buf); + return (XawTextSearchError); + } + ptr = piece->text + cnt; + } } - } - XtFree( (char *) buf ); - if (dir == XawsdLeft) - return( position ); - return( position - ( wtarget_len - 1 ) ); + XtFree((char *)buf); + if (dir == XawsdLeft) + return(position); + + return(position - (wtarget_len - 1)); } -/* Function Name: SetValues - * Description: Sets the values for the MultiSource. - * Arguments: current - current state of the widget. - * request - what was requested. - * new - what the widget will become. - * Returns: True if redisplay is needed. +/* + * Function: + * XawMultiSrcSetValues + * + * Parameters: + * current - current state of the widget + * request - what was requested + * cnew - what the widget will become + * args - representation of resources that have changed + * num_args - number of changed resources + * + * Description: + * Sets the values for the MultiSource. + * + * Returns: + * True if redisplay is needed */ - -/* ARGSUSED */ static Boolean -SetValues(current, request, new, args, num_args) - Widget current, request, new; - ArgList args; - Cardinal* num_args; +XawMultiSrcSetValues(Widget current, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - MultiSrcObject src = (MultiSrcObject) new; - MultiSrcObject old_src = (MultiSrcObject) current; - XtAppContext app_con = XtWidgetToApplicationContext(new); - Boolean total_reset = FALSE, string_set = FALSE; - FILE * file; - int i; - - if ( old_src->multi_src.use_string_in_place != - src->multi_src.use_string_in_place ) { - XtAppWarning( app_con, - "MultiSrc: The XtNuseStringInPlace resources may not be changed."); - src->multi_src.use_string_in_place = - old_src->multi_src.use_string_in_place; - } - - for (i = 0; i < *num_args ; i++ ) - if (streq(args[i].name, XtNstring)) { - string_set = TRUE; - break; - } + MultiSrcObject src = (MultiSrcObject)cnew; + MultiSrcObject old_src = (MultiSrcObject)current; + XtAppContext app_con = XtWidgetToApplicationContext(cnew); + Bool total_reset = False, string_set = False; + FILE *file; + unsigned int i; + + if (old_src->multi_src.use_string_in_place + != src->multi_src.use_string_in_place) { + XtAppWarning(app_con, + "MultiSrc: The XtNuseStringInPlace resources " + "may not be changed."); + src->multi_src.use_string_in_place = + old_src->multi_src.use_string_in_place; + } + + for (i = 0; i < *num_args ; i++) + if (streq(args[i].name, XtNstring)) { + string_set = True; + break; + } - if ( string_set || (old_src->multi_src.type != src->multi_src.type) ) { - RemoveOldStringOrFile(old_src, string_set); - file = InitStringOrFile(src, string_set); - - /* Load pieces does this logic for us, but it shouldn't. Its messy.*/ - /*if (old_src->multi_src.type == XawAsciiString) - LoadPieces(src, NULL, src->multi_src.string); - else*/ + if (string_set || old_src->multi_src.type != src->multi_src.type) { + RemoveOldStringOrFile(old_src, string_set); + src->multi_src.allocated_string = old_src->multi_src.allocated_string; + file = InitStringOrFile(src, string_set); + LoadPieces(src, file, NULL); - if (file != NULL) fclose(file); - XawTextSetSource( XtParent(new), new, 0); /* Tell text widget - what happened. */ - total_reset = TRUE; - } - - if ( old_src->multi_src.multi_length != src->multi_src.multi_length ) - src->multi_src.piece_size = src->multi_src.multi_length; - - if ( !total_reset && (old_src->multi_src.piece_size - != src->multi_src.piece_size) ) { - String mb_string = StorePiecesInString( old_src ); - - if ( mb_string != 0 ) { - FreeAllPieces( old_src ); - LoadPieces( src, NULL, mb_string ); - XtFree( mb_string ); - } else { - /* If the buffer holds bad chars, don't touch it... */ - XtAppWarningMsg( app_con, - "convertError", "multiSource", "XawError", - XtName( XtParent( (Widget) old_src ) ), NULL, NULL ); - XtAppWarningMsg( app_con, - "convertError", "multiSource", "XawError", - "Non-character code(s) in buffer.", NULL, NULL ); - } - } - - return(FALSE); -} + if (file != NULL) + fclose(file); +#ifndef OLDXAW + for (i = 0; i < src->text_src.num_text; i++) + /* Tell text widget what happened */ + XawTextSetSource(src->text_src.text[i], cnew, 0); +#else + XawTextSetSource(XtParent(cnew), cnew, 0); +#endif + total_reset = True; + } -/* Function Name: GetValuesHook - * Description: This is a get values hook routine that sets the - * values specific to the multi source. - * Arguments: w - the MultiSource Widget. - * args - the argument list. - * num_args - the number of args. - * Returns: none. - */ + if (old_src->multi_src.multi_length != src->multi_src.multi_length) + src->multi_src.piece_size = src->multi_src.multi_length + 1; + + if ( !total_reset && old_src->multi_src.piece_size + != src->multi_src.piece_size) { + String mb_string = StorePiecesInString(old_src); + + if (mb_string != 0) { + FreeAllPieces(old_src); + LoadPieces(src, NULL, mb_string); + XtFree(mb_string); + } + else { + /* If the buffer holds bad chars, don't touch it... */ + XtAppWarningMsg(app_con, + "convertError", "multiSource", "XawError", + XtName(XtParent((Widget)old_src)), NULL, NULL); + XtAppWarningMsg(app_con, + "convertError", "multiSource", "XawError", + "Non-character code(s) in buffer.", NULL, NULL); + } + } + + return (False); +} static void -GetValuesHook(w, args, num_args) - Widget w; - ArgList args; - Cardinal* num_args; +XawMultiSrcGetValuesHook(Widget w, ArgList args, Cardinal *num_args) { - MultiSrcObject src = (MultiSrcObject) w; - int i; - - if (src->multi_src.type == XawAsciiString) { - for (i = 0; i < *num_args ; i++ ) - if (streq(args[i].name, XtNstring)) { - if (src->multi_src.use_string_in_place) { - *((char **) args[i].value) = (char *) - src->multi_src.first_piece->text; - } - else { - if (_XawMultiSave(w)) /* If save sucessful. */ - *((char **) args[i].value) = src->multi_src.string; - } - break; - } - } -} - -/* Function Name: Destroy - * Description: Destroys an multi source (frees all data) - * Arguments: src - the Multi source Widget to free. - * Returns: none. - */ + MultiSrcObject src = (MultiSrcObject)w; + unsigned int i; + + if (src->multi_src.type == XawAsciiString) { + for (i = 0; i < *num_args ; i++) { + if (streq(args[i].name, XtNstring)) { + if (src->multi_src.use_string_in_place) + *((char **)args[i].value) = (char *) + src->multi_src.first_piece->text; + else if (_XawMultiSave(w)) /* If save sucessful */ + *((char **)args[i].value) = (char *)src->multi_src.string; + break; + } + } + } +} static void -Destroy (w) - Widget w; +XawMultiSrcDestroy(Widget w) { RemoveOldStringOrFile((MultiSrcObject) w, True); } -/************************************************************ - * +/* * Public routines + */ +/* + * Function: + * XawMultiSourceFreeString * - ************************************************************/ - -/* Function Name: XawMultiSourceFreeString - * Description: Frees the string returned by a get values call + * Parameters: + * w - MultiSrc widget + * + * Description: + * Frees the string returned by a get values call * on the string when the source is of type string. - * Arguments: w - the MultiSrc widget. - * Returns: none. * + * Note: * The public interface is XawAsciiSourceFreeString! */ - void -#if NeedFunctionPrototypes -_XawMultiSourceFreeString( - Widget w) -#else -_XawMultiSourceFreeString(w) - Widget w; -#endif +_XawMultiSourceFreeString(Widget w) { - MultiSrcObject src = (MultiSrcObject) w; - -/*if (src->multi_src.allocated_string&& src->multi_src.type != XawAsciiFile) {*/ - /* ASSERT: src->multi_src.allocated_string -> we MUST free .string! */ - if ( src->multi_src.allocated_string ) { - XtFree(src->multi_src.string); - src->multi_src.allocated_string = FALSE; - src->multi_src.string = NULL; - } + MultiSrcObject src = (MultiSrcObject)w; + + if (src->multi_src.allocated_string) { + XtFree((char *)src->multi_src.string); + src->multi_src.allocated_string = False; + src->multi_src.string = NULL; + } } -/* Function Name: _XawMultiSave - * Description: Saves all the pieces into a file or string as required. - * Arguments: w - the multiSrc Widget. - * Returns: TRUE if the save was successful. +/* + * Function: + * _XawMultiSave * + * Parameters: + * w - multiSrc Widget + * + * Description: + * Saves all the pieces into a file or string as required. + * + * Returns: + * True if the save was successful + * + * Note: * The public interface is XawAsciiSave(w)! */ +Bool +_XawMultiSave(Widget w) +{ + MultiSrcObject src = (MultiSrcObject)w; + XtAppContext app_con = XtWidgetToApplicationContext(w); + char *mb_string; + + /* + * If using the string in place then there is no need to play games + * to get the internal info into a readable string + */ + if (src->multi_src.use_string_in_place) + return (True); -Boolean -#if NeedFunctionPrototypes -_XawMultiSave( - Widget w) + if (src->multi_src.type == XawAsciiFile) { +#ifdef OLDXAW + if (!src->multi_src.changes) #else -_XawMultiSave(w) - Widget w; + if (!src->text_src.changed) /* No changes to save */ #endif -{ - MultiSrcObject src = (MultiSrcObject) w; - XtAppContext app_con = XtWidgetToApplicationContext(w); - char * mb_string; + return (True); -/* - * If using the string in place then there is no need to play games - * to get the internal info into a readable string. - */ + mb_string = StorePiecesInString(src); + + if (mb_string != 0) { + if (WriteToFile(mb_string, (String)src->multi_src.string) == False) { + XtFree(mb_string); + return (False); + } + XtFree(mb_string); +#ifndef OLDXAW + src->text_src.changed = False; +#else + src->multi_src.changes = False; +#endif + return (True); + } + else { + /* If the buffer holds bad chars, don't touch it... */ + XtAppWarningMsg(app_con, + "convertError", "multiSource", "XawError", + "Due to illegal characters, file not saved.", + NULL, NULL); + return (False); + } + } + else { + /* THIS FUNCTIONALITY IS UNDOCUMENTED, probably UNNEEDED? The manual + says this routine's only function is to save files to + disk. -Sheeran */ + mb_string = StorePiecesInString(src); + + if (mb_string == 0) { + /* If the buffer holds bad chars, don't touch it... */ + XtAppWarningMsg(app_con, + "convertError", "multiSource", "XawError", + XtName(XtParent((Widget)src)), NULL, NULL); + return (False); + } - if (src->multi_src.use_string_in_place) - return(TRUE); - - if (src->multi_src.type == XawAsciiFile) { - - if (!src->multi_src.changes) /* No changes to save. */ - return(TRUE); - - mb_string = StorePiecesInString( src ); - - if ( mb_string != 0 ) { - if ( WriteToFile( mb_string, src->multi_src.string ) == FALSE ) { - XtFree( mb_string ); - return( FALSE ); - } - XtFree( mb_string ); - src->multi_src.changes = FALSE; - return( TRUE ); - } else { - /* If the buffer holds bad chars, don't touch it... */ - XtAppWarningMsg( app_con, - "convertError", "multiSource", "XawError", - "Due to illegal characters, file not saved.", NULL, NULL); - return( FALSE ); - } - } - else { - - /* THIS FUNCTIONALITY IS UNDOCUMENTED, probably UNNEEDED? The manual - says this routine's only function is to save files to disk. -Sheeran */ - - mb_string = StorePiecesInString( src ); - - if ( mb_string == 0 ) { - /* If the buffer holds bad chars, don't touch it... */ - XtAppWarningMsg( app_con, - "convertError", "multiSource", "XawError", - XtName( XtParent( (Widget) src ) ), NULL, NULL); - return( FALSE ); - } - - /* assert: mb_string holds good characters so the buffer is fine */ - if (src->multi_src.allocated_string == TRUE) - XtFree(src->multi_src.string); - else - src->multi_src.allocated_string = TRUE; + /* assert: mb_string holds good characters so the buffer is fine */ + if (src->multi_src.allocated_string == True) + XtFree((char *)src->multi_src.string); + else + src->multi_src.allocated_string = True; - src->multi_src.string = mb_string; - } - src->multi_src.changes = FALSE; - return(TRUE); + src->multi_src.string = mb_string; + } +#ifdef OLDXAW + src->multi_src.changes = False; +#else + src->text_src.changed = False; +#endif + + return (True); } -/* Function Name: XawMultiSaveAsFile - * Description: Save the current buffer as a file. - * Arguments: w - the MultiSrc widget. - * name - name of the file to save this file into. - * Returns: True if the save was sucessful. +/* + * Function: + * XawMultiSaveAsFile + * + * Parameters: + * w - MultiSrc widget + * name - name of the file to save this file into * + * Description: + * Save the current buffer as a file. + * + * Returns: + * True if the save was sucessful + * + * Note: * The public interface is XawAsciiSaveAsFile! */ - -Boolean -#if NeedFunctionPrototypes -_XawMultiSaveAsFile( - Widget w, - _Xconst char* name) -#else -_XawMultiSaveAsFile(w, name) - Widget w; - String name; -#endif +Bool +_XawMultiSaveAsFile(Widget w, _Xconst char* name) { - MultiSrcObject src = (MultiSrcObject) w; - String mb_string; - Boolean ret; - - mb_string = StorePiecesInString( src ); - - if ( mb_string != 0 ) { - ret = WriteToFile( mb_string, name ); - XtFree( mb_string ); - return( ret ); - } - - /* otherwise there was a conversion error. So print widget name too. */ - XtAppWarningMsg( XtWidgetToApplicationContext(w), - "convertError", "multiSource", "XawError", - XtName( XtParent( (Widget) src ) ), NULL, NULL); - return( False ); -} + MultiSrcObject src = (MultiSrcObject)w; + String mb_string; + Bool ret; -/************************************************************ - * - * Private Functions. - * - ************************************************************/ + mb_string = StorePiecesInString(src); + + if (mb_string != 0) { + ret = WriteToFile(mb_string, (char *)name); + XtFree(mb_string); + + return (ret); + } + /* otherwise there was a conversion error. So print widget name too */ + XtAppWarningMsg(XtWidgetToApplicationContext(w), + "convertError", "multiSource", "XawError", + XtName(XtParent(w)), NULL, NULL); + + return (False); +} + +/* + * Private Functions + */ static void -RemoveOldStringOrFile(src, checkString) - MultiSrcObject src; - Boolean checkString; +RemoveOldStringOrFile(MultiSrcObject src, Bool checkString) { - FreeAllPieces(src); + FreeAllPieces(src); - if (checkString && src->multi_src.allocated_string) { - XtFree(src->multi_src.string); - src->multi_src.allocated_string = False; - src->multi_src.string = NULL; - } + if (checkString && src->multi_src.allocated_string) { + XtFree((char *)src->multi_src.string); + src->multi_src.allocated_string = False; + src->multi_src.string = NULL; + } } -/* Function Name: WriteToFile - * Description: Write the string specified to the begining of the file - * specified. - * Arguments: string - string to write. - * name - the name of the file - * Returns: returns TRUE if sucessful, FALSE otherwise. +/* + * Function: + * WriteToFile + * + * Parameters: + * string - string to write + * name - name of the file + * + * Description: + * Write the string specified to the begining of the file specified. + * + * Returns: + * Returns True if sucessful, False otherwise */ - -static Boolean -WriteToFile(string, name) - String string, name; +static Bool +WriteToFile(String string, String name) { - int fd; + int fd; - if ( ((fd = creat(name, 0666)) == -1 ) || - (write(fd, string, sizeof(unsigned char) * strlen(string)) == -1) ) - return(FALSE); + if (((fd = creat(name, 0666)) == -1) + || (write(fd, string, strlen(string)) == -1)) + return (False); - if ( close(fd) == -1 ) - return(FALSE); + if (close(fd) == -1) + return (False); - return(TRUE); + return (True); } -/* Function Name: StorePiecesInString - * Description: store the pieces in memory into a char string. - * Arguments: src - the multiSrc to gather data from - * Returns: char *mb_string. Caller must free. - * or 0: conversion error. Caller must panic! +/* + * Function: + * StorePiecesInString + * + * Parameters: + * src - the multiSrc object to gather data from + * + * Description: + * Store the pieces in memory into a char string. + * + * Returns: + * mb_string: Caller must free + * (or) + * NULL: conversion error */ - static String -StorePiecesInString(src) - MultiSrcObject src; +StorePiecesInString(MultiSrcObject src) { - wchar_t* wc_string; - char *mb_string; - int char_count = src->multi_src.length; - XawTextPosition first; - MultiPiece * piece; - - /* I believe the char_count + 1 and the NULL termination are unneeded! FS*/ - - wc_string = (wchar_t*) XtMalloc((unsigned)(char_count + 1) * sizeof(wchar_t)); + wchar_t *wc_string; + char *mb_string; + int char_count = src->multi_src.length; + XawTextPosition first; + MultiPiece *piece; - for (first = 0, piece = src->multi_src.first_piece ; piece != NULL; - first += piece->used, piece = piece->next) - (void) wcsncpy( wc_string + first, piece->text, piece->used ); + /* I believe the char_count + 1 and the NULL termination are unneeded! FS */ + wc_string = (wchar_t*)XtMalloc((char_count + 1) * sizeof(wchar_t)); - wc_string[ char_count ] = (wchar_t)0; /* NULL terminate this sucker. */ + for (first = 0, piece = src->multi_src.first_piece ; piece != NULL; + first += piece->used, piece = piece->next) + (void)wcsncpy(wc_string + first, piece->text, piece->used); + wc_string[char_count] = 0; - /* This will refill all pieces to capacity. */ - - if ( src->multi_src.data_compression ) { - FreeAllPieces( src ); - LoadPieces( src, NULL, (char *)wc_string ); - } + /* This will refill all pieces to capacity */ + if (src->multi_src.data_compression) { + FreeAllPieces(src); + LoadPieces(src, NULL, (char *)wc_string); + } - /* Lastly, convert it to a MB format and send it back. */ + /* Lastly, convert it to a MB format and send it back */ + mb_string = _XawTextWCToMB(XtDisplayOfObject((Widget)src), + wc_string, &char_count); - mb_string = _XawTextWCToMB( XtDisplayOfObject( (Widget)src ), - wc_string, &char_count ); + /* NOTE THAT mb_string MAY BE ZERO IF THE CONVERSION FAILED */ + XtFree((char*)wc_string); - /* NOTE THAT mb_string MAY BE ZERO IF THE CONVERSION FAILED. */ - XtFree( (char*) wc_string ); - return( mb_string ); + return (mb_string); } - -/* Function Name: InitStringOrFile. - * Description: Initializes the string or file. - * Arguments: src - the MultiSource. - * Returns: none - May exit though. +/* + * Function: + * InitStringOrFile + * + * Parameters: + * src - MultiSource + * + * Description: + * Initializes the string or file. */ - static FILE * -InitStringOrFile(src, newString) - MultiSrcObject src; - Boolean newString; +InitStringOrFile(MultiSrcObject src, Bool newString) { - char * open_mode; - FILE * file; - char fileName[TMPSIZ]; + mode_t open_mode = 0; + const char *fdopen_mode = NULL; + int fd; + FILE *file; Display *d = XtDisplayOfObject((Widget)src); if (src->multi_src.type == XawAsciiString) { - if (src->multi_src.string == NULL) src->multi_src.length = 0; - else if (! src->multi_src.use_string_in_place) { + else if (!src->multi_src.use_string_in_place) { int length; - String temp = XtNewString(src->multi_src.string); - if ( src->multi_src.allocated_string ) - XtFree( src->multi_src.string ); - src->multi_src.allocated_string = True; + String temp = XtNewString((char *)src->multi_src.string); + + if (src->multi_src.allocated_string) + XtFree((char *)src->multi_src.string); + src->multi_src.allocated_string = True; src->multi_src.string = temp; - length = strlen(src->multi_src.string); + length = strlen((char *)src->multi_src.string); /* Wasteful, throwing away the WC string, but need side effect! */ - (void) _XawTextMBToWC(d, src->multi_src.string, &length); - src->multi_src.length = (XawTextPosition) length; - } else { - src->multi_src.length = strlen(src->multi_src.string); + (void)_XawTextMBToWC(d, (char *)src->multi_src.string, &length); + src->multi_src.length = (XawTextPosition)length; + } + else { + src->multi_src.length = strlen((char *)src->multi_src.string); /* In case the length resource is incorrectly set */ if (src->multi_src.length > src->multi_src.multi_length) src->multi_src.multi_length = src->multi_src.length; @@ -1107,352 +1203,415 @@ InitStringOrFile(src, newString) src->multi_src.piece_size = src->multi_src.multi_length + 1; } - /*((TextWidget)src->object.parent)->text.lastPos = src->multi_src.length;*/ - return(NULL); + return (NULL); } -/* - * type is XawAsciiFile. - */ - - src->multi_src.is_tempfile = FALSE; + /* + * type is XawAsciiFile + */ + src->multi_src.is_tempfile = False; switch (src->text_src.edit_mode) { - case XawtextRead: - if (src->multi_src.string == NULL) - XtErrorMsg("NoFile", "multiSourceCreate", "XawError", - "Creating a read only disk widget and no file specified.", - NULL, 0); - open_mode = "r"; - break; - case XawtextAppend: - case XawtextEdit: - if (src->multi_src.string == NULL) { - - if ( src->multi_src.allocated_string ) - XtFree( src->multi_src.string ); - src->multi_src.allocated_string = False; - src->multi_src.string = fileName; - - (void) tmpnam(src->multi_src.string); - src->multi_src.is_tempfile = TRUE; - open_mode = "w"; - } else - open_mode = "r+"; - break; - default: - XtErrorMsg("badMode", "multiSourceCreate", "XawError", - "Bad editMode for multi source; must be Read, Append or Edit.", - NULL, NULL); + case XawtextRead: + if (src->multi_src.string == NULL) + XtErrorMsg("NoFile", "multiSourceCreate", "XawError", + "Creating a read only disk widget and no file specified.", + NULL, 0); + open_mode = O_RDONLY; + fdopen_mode = "r"; + break; + case XawtextAppend: + case XawtextEdit: + if (src->multi_src.string == NULL) { + src->multi_src.string = "*multi-src*"; + src->multi_src.is_tempfile = True; + } + else { +/* O_NOFOLLOW is a BSD & Linux extension */ +#ifdef O_NOFOLLOW + open_mode = O_RDWR | O_NOFOLLOW; +#else + open_mode = O_RDWR; /* unsafe; subject to race conditions */ +#endif + fdopen_mode = "r+"; + } + break; + default: + XtErrorMsg("badMode", "multiSourceCreate", "XawError", + "Bad editMode for multi source; must be " + "Read, Append or Edit.", NULL, NULL); } - /* Allocate new memory for the temp filename, because it is held in - * a stack memory buffer. We must verify that all routines that set - * .string first check .allocated_string and free it - plumbing Sheeran. - */ + /* If is_tempfile, allocate a private copy of the text + * Unlikely to be changed, just to set allocated_string */ if (newString || src->multi_src.is_tempfile) { - if ( src->multi_src.allocated_string ) - XtFree( src->multi_src.string ); - src->multi_src.string = XtNewString(src->multi_src.string); - src->multi_src.allocated_string = TRUE; + String temp = XtNewString((char *)src->multi_src.string); + + if (src->multi_src.allocated_string) + XtFree((char *)src->multi_src.string); + src->multi_src.string = temp; + src->multi_src.allocated_string = True; } if (!src->multi_src.is_tempfile) { - if ((file = fopen(src->multi_src.string, open_mode)) != 0) { - (void) fseek(file, (Off_t)0, 2); - src->multi_src.length = ftell (file); - return file; - } else { + if ((fd = open((char *)src->multi_src.string, open_mode, 0666)) != -1) { + if ((file = fdopen(fd, fdopen_mode)) != NULL) { + (void)fseek(file, 0, SEEK_END); + src->multi_src.length = (XawTextPosition)ftell(file); + return(file); + } + } + { String params[2]; Cardinal num_params = 2; - params[0] = src->multi_src.string; + params[0] = (String)src->multi_src.string; params[1] = strerror(errno); XtAppWarningMsg(XtWidgetToApplicationContext((Widget)src), "openError", "multiSourceCreate", "XawWarning", "Cannot open file %s; %s", params, &num_params); } - } + } src->multi_src.length = 0; - return((FILE *)NULL); -#undef StrLen + return (NULL); } -/* LoadPieces: This routine takes either the MB contents of open file `file' or the -MB contents of string or the MB contents of src->multi_src.string and places -them in Pieces in WC format. - -CAUTION: You must have src->multi_src.length set to file length bytes -when src->multi_src.type == XawAsciiFile. src->multi_src.length must be -the length of the parameter string if string is non-NULL. */ +/* LoadPieces: This routine takes either the MB contents of open file + `file' or the MB contents of string or the MB contents of + src->multi_src.string and places them in Pieces in WC format. + CAUTION: You must have src->multi_src.length set to file length bytes + when src->multi_src.type == XawAsciiFile. src->multi_src.length must be + the length of the parameter string if string is non-NULL +*/ static void -LoadPieces(src, file, string) - MultiSrcObject src; - FILE* file; - char* string; +LoadPieces(MultiSrcObject src, FILE *file, char *string) { - Display *d = XtDisplayOfObject((Widget)src); - wchar_t* local_str, *ptr; - MultiPiece* piece = NULL; - XawTextPosition left; - int bytes = sizeof(wchar_t); - char* temp_mb_holder = NULL; - - /* - * This is tricky - the _XawTextMBtoWC converter uses its 3rd arg - * in as MB length, out as WC length. We want local_length to be - * WC count. - */ - int local_length = src->multi_src.length; - - if (string != NULL) { - /* - * ASSERT: IF our caller passed a non-null string, THEN - * src->multi_src.length is currently string's * byte count, - * AND string is in a MB format. - */ - local_str = _XawTextMBToWC(d, (char *)string, &local_length); - src->multi_src.length = (XawTextPosition) local_length; - } else if (src->multi_src.type != XawAsciiFile) { + Display *d = XtDisplayOfObject((Widget)src); + wchar_t* local_str, *ptr; + MultiPiece* piece = NULL; + XawTextPosition left; + int bytes = sizeof(wchar_t); + char* temp_mb_holder = NULL; + /* - * here, we are not changing the contents, just reloading, - * so don't change len... + * This is tricky - the _XawTextMBtoWC converter uses its 3rd arg + * in as MB length, out as WC length. We want local_length to be + * WC count. */ - local_length = src->multi_src.string ? - strlen( src->multi_src.string ) : 0; - local_str = _XawTextMBToWC( d, (char*)src->multi_src.string, &local_length ); - } else { - if (src->multi_src.length != 0) { - temp_mb_holder = - XtMalloc((unsigned)(src->multi_src.length + 1) * sizeof(unsigned char)); - fseek(file, (Off_t)0, 0); - src->multi_src.length = fread (temp_mb_holder, - (Size_t)sizeof(unsigned char), - (Size_t)src->multi_src.length, file); - if (src->multi_src.length <= 0) - XtAppErrorMsg( XtWidgetToApplicationContext ((Widget) src), - "readError", "multiSource", "XawError", - "fread returned error.", NULL, NULL); - local_length = src->multi_src.length; - local_str = _XawTextMBToWC(d, temp_mb_holder, &local_length); - src->multi_src.length = local_length; - - if ( local_str == 0 ) { - String params[2]; - Cardinal num_params; - static char err_text[] = - "<<< FILE CONTENTS NOT REPRESENTABLE IN THIS LOCALE >>>"; - - params[0] = XtName(XtParent((Widget)src)); - params[1] = src->multi_src.string; - num_params = 2; - - XtAppWarningMsg( XtWidgetToApplicationContext((Widget)src), - "readLocaleError", "multiSource", "XawError", - "%s: The file `%s' contains characters not representable in this locale.", - params, &num_params); - src->multi_src.length = sizeof err_text; - local_length = src->multi_src.length; - local_str = _XawTextMBToWC(d, err_text, &local_length); - src->multi_src.length = local_length; - } - } else { /*ASSERT that since following while loop looks at local_length - this isn't needed. Sheeran, Omron KK, 1993/07/15 - temp_mb_holder[src->multi_src.length] = '\0';*/ - local_str = (wchar_t*)temp_mb_holder; + int local_length = src->multi_src.length; + + if (string != NULL) { + /* + * ASSERT: IF our caller passed a non-null string, THEN + * src->multi_src.length is currently string's * byte count, + * AND string is in a MB format + */ + local_str = _XawTextMBToWC(d, (char *)string, &local_length); + src->multi_src.length = (XawTextPosition) local_length; + } + else if (src->multi_src.type != XawAsciiFile) { + /* + * here, we are not changing the contents, just reloading, + * so don't change len... + */ + local_length = src->multi_src.string ? + strlen((char *)src->multi_src.string) : 0; + local_str = _XawTextMBToWC(d, (char *)src->multi_src.string, + &local_length); + } + else { + if (src->multi_src.length != 0) { + temp_mb_holder = + XtMalloc((src->multi_src.length + 1) * sizeof(unsigned char)); + fseek(file, 0, 0); + src->multi_src.length = fread(temp_mb_holder, + (Size_t)sizeof(unsigned char), + (Size_t)src->multi_src.length, file); + if (src->multi_src.length <= 0) + XtAppErrorMsg(XtWidgetToApplicationContext ((Widget) src), + "readError", "multiSource", "XawError", + "fread returned error.", NULL, NULL); + local_length = src->multi_src.length; + local_str = _XawTextMBToWC(d, temp_mb_holder, &local_length); + src->multi_src.length = local_length; + + if (local_str == 0) { + String params[2]; + Cardinal num_params; + static char err_text[] = + "<<< FILE CONTENTS NOT REPRESENTABLE IN THIS LOCALE >>>"; + + params[0] = XtName(XtParent((Widget)src)); + params[1] = src->multi_src.string; + num_params = 2; + + XtAppWarningMsg(XtWidgetToApplicationContext((Widget)src), + "readLocaleError", "multiSource", "XawError", + "%s: The file `%s' contains characters " + "not representable in this locale.", + params, &num_params); + src->multi_src.length = sizeof err_text; + local_length = src->multi_src.length; + local_str = _XawTextMBToWC(d, err_text, &local_length); + src->multi_src.length = local_length; + } + } + else + /* ASSERT that since following while loop looks at local_length + this isn't needed. Sheeran, Omron KK, 1993/07/15 + temp_mb_holder[src->multi_src.length] = '\0'; */ + local_str = (wchar_t*)temp_mb_holder; } - } - if (src->multi_src.use_string_in_place) { - piece = AllocNewPiece(src, piece); - piece->used = Min(src->multi_src.length, src->multi_src.piece_size); - piece->text = (wchar_t*)src->multi_src.string; - return; - } + if (src->multi_src.use_string_in_place) { + piece = AllocNewPiece(src, piece); + piece->used = Min(src->multi_src.length, src->multi_src.piece_size); + piece->text = (wchar_t*)src->multi_src.string; + return; + } - ptr = local_str; - left = local_length; + ptr = local_str; + left = local_length; - do { - piece = AllocNewPiece(src, piece); + do { + piece = AllocNewPiece(src, piece); - piece->text = (wchar_t*)XtMalloc(src->multi_src.piece_size * bytes); - piece->used = Min(left, src->multi_src.piece_size); - if (piece->used != 0) - (void) wcsncpy(piece->text, ptr, piece->used); + piece->text = (wchar_t*)XtMalloc((unsigned)(src->multi_src.piece_size + * bytes)); + piece->used = Min(left, src->multi_src.piece_size); + if (piece->used != 0) + (void)wcsncpy(piece->text, ptr, piece->used); - left -= piece->used; - ptr += piece->used; - } while (left > 0); + left -= piece->used; + ptr += piece->used; + } while (left > 0); - if ( temp_mb_holder ) - XtFree( (char*) temp_mb_holder ); + if (temp_mb_holder) + XtFree((char*)temp_mb_holder); } - -/* Function Name: AllocNewPiece - * Description: Allocates a new piece of memory. - * Arguments: src - The MultiSrc Widget. - * prev - the piece just before this one, or NULL. - * Returns: the allocated piece. +/* + * Function: + * AllocNewPiece + * + * Parameters: + * src - MultiSrc Widget + * prev - the piece just before this one, or NULL + * + * Description: + * Allocates a new piece of memory. + * + * Returns: + * The allocated piece */ - static MultiPiece * -AllocNewPiece(src, prev) - MultiSrcObject src; - MultiPiece * prev; +AllocNewPiece(MultiSrcObject src, MultiPiece *prev) { - MultiPiece * piece = XtNew(MultiPiece); - - if (prev == NULL) { - src->multi_src.first_piece = piece; - piece->next = NULL; - } - else { - if (prev->next != NULL) - (prev->next)->prev = piece; - piece->next = prev->next; - prev->next = piece; - } + MultiPiece *piece = XtNew(MultiPiece); + + if (prev == NULL) { + src->multi_src.first_piece = piece; + piece->next = NULL; + } + else { + if (prev->next != NULL) + (prev->next)->prev = piece; + piece->next = prev->next; + prev->next = piece; + } - piece->prev = prev; + piece->prev = prev; - return(piece); + return (piece); } -/* Function Name: FreeAllPieces - * Description: Frees all the pieces - * Arguments: src - The MultiSrc Widget. - * Returns: none. +/* + * Function: + * FreeAllPieces + * + * Parameters: + * src - MultiSrc Widget + * + * Description: + * Frees all the pieces */ - static void -FreeAllPieces(src) - MultiSrcObject src; +FreeAllPieces(MultiSrcObject src) { - MultiPiece * next, * first = src->multi_src.first_piece; + MultiPiece *next, *first = src->multi_src.first_piece; - if (first->prev != NULL) - printf("Xaw MultiSrc Object: possible memory leak in FreeAllPieces().\n"); +#ifdef DEBUG + if (first->prev != NULL) + printf("Xaw MultiSrc Object: possible memory leak in FreeAllPieces().\n"); +#endif - for ( ; first != NULL ; first = next ) { - next = first->next; - RemovePiece(src, first); - } + for (; first != NULL ; first = next) { + next = first->next; + RemovePiece(src, first); + } } -/* Function Name: RemovePiece - * Description: Removes a piece from the list. - * Arguments: - * piece - the piece to remove. - * Returns: none. +/* + * Function: + * RemovePiece + * + * Parameters: + * piece - piece to remove + * + * Description: + * Removes a piece from the list. */ - static void -RemovePiece(src, piece) - MultiSrcObject src; - MultiPiece* piece; +RemovePiece(MultiSrcObject src, MultiPiece *piece) { - if (piece->prev == NULL) - src->multi_src.first_piece = piece->next; - else - (piece->prev)->next = piece->next; + if (piece->prev == NULL) + src->multi_src.first_piece = piece->next; + else + piece->prev->next = piece->next; - if (piece->next != NULL) - (piece->next)->prev = piece->prev; + if (piece->next != NULL) + piece->next->prev = piece->prev; - if (!src->multi_src.use_string_in_place) - XtFree((char *)piece->text); + if (!src->multi_src.use_string_in_place) + XtFree((char *)piece->text); - XtFree((char *)piece); + XtFree((char *)piece); } -/* Function Name: FindPiece - * Description: Finds the piece containing the position indicated. - * Arguments: src - The MultiSrc Widget. - * position - the position that we are searching for. - * RETURNED first - the position of the first character in this piece. - * Returns: piece - the piece that contains this position. +/* + * Function: + * FindPiece + * + * Parameters: + * src - MultiSrc Widget + * position - position that we are searching for + * first - position of the first character in this piece (return) + * + * Description: + * Finds the piece containing the position indicated. + * + * Returns: + * Piece that contains this position */ - static MultiPiece * -FindPiece(src, position, first) - MultiSrcObject src; - XawTextPosition position, *first; +FindPiece(MultiSrcObject src, XawTextPosition position, XawTextPosition *first) { - MultiPiece * old_piece, * piece = src->multi_src.first_piece; - XawTextPosition temp; + MultiPiece *old_piece, *piece; + XawTextPosition temp; + + for (old_piece = NULL, piece = src->multi_src.first_piece, temp = 0; + piece; old_piece = piece, piece = piece->next) + if ((temp += piece->used) > position) { + *first = temp - piece->used; + return (piece); + } - for ( temp = 0 ; piece != NULL ; temp += piece->used, piece = piece->next ) { - *first = temp; - old_piece = piece; + *first = temp - (old_piece ? old_piece->used : 0); - if ((temp + piece->used) > position) - return(piece); - } - return(old_piece); /* if we run off the end the return the last piece */ + return (old_piece); /* if we run off the end the return the last piece */ } -/* Function Name: BreakPiece - * Description: Breaks a full piece into two new pieces. - * Arguments: src - The MultiSrc Widget. - * piece - the piece to break. - * Returns: none. +/* + * Function: + * BreakPiece + * + * Parameters: + * src - MultiSrc Widget + * piece - piece to break + * + * Description: + * Breaks a full piece into two new pieces. */ - -#define HALF_PIECE (src->multi_src.piece_size/2) - +#define HALF_PIECE (src->multi_src.piece_size >> 1) static void -BreakPiece(src, piece) - MultiSrcObject src; - MultiPiece* piece; +BreakPiece(MultiSrcObject src, MultiPiece *piece) { - MultiPiece * new = AllocNewPiece(src, piece); + MultiPiece *cnew = AllocNewPiece(src, piece); - new->text = (wchar_t*)XtMalloc(src->multi_src.piece_size * sizeof(wchar_t)); - (void) wcsncpy(new->text, piece->text + HALF_PIECE, - src->multi_src.piece_size - HALF_PIECE); - piece->used = HALF_PIECE; - new->used = src->multi_src.piece_size - HALF_PIECE; + cnew->text = (wchar_t *) + XtMalloc(src->multi_src.piece_size * sizeof(wchar_t)); + (void)wcsncpy(cnew->text, piece->text + HALF_PIECE, + src->multi_src.piece_size - HALF_PIECE); + piece->used = HALF_PIECE; + cnew->used = src->multi_src.piece_size - HALF_PIECE; } -/* Convert string "XawAsciiString" and "XawAsciiFile" to quarks. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -CvtStringToMultiType(args, num_args, fromVal, toVal) - XrmValuePtr args; /* unused */ - Cardinal* num_args; /* unused */ - XrmValuePtr fromVal; - XrmValuePtr toVal; +CvtStringToMultiType(XrmValuePtr args, Cardinal *num_args, + XrmValuePtr fromVal, XrmValuePtr toVal) { - static XawAsciiType type; - static XrmQuark XtQEstring = NULLQUARK; - static XrmQuark XtQEfile; - XrmQuark q; - char lowerName[40]; - - if (XtQEstring == NULLQUARK) { - XtQEstring = XrmPermStringToQuark(XtEstring); - XtQEfile = XrmPermStringToQuark(XtEfile); - } - - if (strlen ((char*) fromVal->addr) < sizeof lowerName) { - XmuCopyISOLatin1Lowered(lowerName, (char *) fromVal->addr); - q = XrmStringToQuark(lowerName); - - if (q == XtQEstring) type = XawAsciiString; - else if (q == XtQEfile) type = XawAsciiFile; + static XawAsciiType type = XawAsciiString; + XrmQuark q; + char name[7]; + + XmuNCopyISOLatin1Lowered(name, (char *)fromVal->addr, sizeof(name)); + q = XrmStringToQuark(name); + + if (q == Qstring) + type = XawAsciiString; + if (q == Qfile) + type = XawAsciiFile; else { - toVal->size = 0; - toVal->addr = NULL; - return; + toVal->size = 0; + toVal->addr = NULL; + XtStringConversionWarning((char *)fromVal->addr, XtRAsciiType); + } + + toVal->size = sizeof(XawAsciiType); + toVal->addr = (XPointer)&type; +} + +/*ARGSUSED*/ +static Boolean +CvtMultiTypeToString(Display *dpy, XrmValuePtr args, Cardinal *num_args, + XrmValuePtr fromVal, XrmValuePtr toVal, + XtPointer *data) +{ + static String buffer; + Cardinal size; + + switch (*(XawAsciiType *)fromVal->addr) { + case XawAsciiFile: + buffer = XtEfile; + break; + case XawAsciiString: + buffer = XtEstring; + break; + default: + XawTypeToStringWarning(dpy, XtRAsciiType); + toVal->addr = NULL; + toVal->size = 0; + return (False); } - toVal->size = sizeof type; - toVal->addr = (XPointer) &type; - return; - } - toVal->size = 0; - toVal->addr = NULL; + + size = strlen(buffer) + 1; + if (toVal->addr != NULL) { + if (toVal->size < size) { + toVal->size = size; + return (False); + } + strcpy((char *)toVal->addr, buffer); + } + else + toVal->addr = (XPointer)buffer; + toVal->size = sizeof(String); + + return (True); +} + +/*ARGSUSED*/ +static void +GetDefaultPieceSize(Widget w, int offset, XrmValue *value) +{ + static XPointer pagesize; + + if (pagesize == 0) { + pagesize = (XPointer)((long)_XawGetPageSize()); + if (pagesize < (XPointer)BUFSIZ) + pagesize = (XPointer)BUFSIZ; + } + + value->addr = (XPointer)&pagesize; } diff --git a/src/Paned.c b/src/Paned.c index 2c88c37..098e353 100644 --- a/src/Paned.c +++ b/src/Paned.c @@ -46,10 +46,9 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/Paned.c,v 1.12 2001/12/14 19:54:41 dawes Exp $ */ /* - * Paned.c - Paned Composite Widget. - * * Updated and significantly modified from the Athena VPaned Widget. * * Date: March 1, 1989 @@ -62,21 +61,22 @@ SOFTWARE. #include <X11/IntrinsicP.h> #include <X11/cursorfont.h> #include <X11/StringDefs.h> - -#include <X11/Xmu/Misc.h> +#include <X11/Xmu/CharSet.h> #include <X11/Xmu/Converters.h> - -#include <X11/Xaw/XawInit.h> +#include <X11/Xmu/Misc.h> +#include <X11/Xmu/SysUtil.h> #include <X11/Xaw/Grip.h> #include <X11/Xaw/PanedP.h> - -/* I don't know why Paned.c calls _XawImCallVendorShellExtResize, but... */ #include <X11/Xaw/XawImP.h> +#include <X11/Xaw/XawInit.h> +#include "Private.h" -#include <ctype.h> - -typedef enum {UpLeftPane = 'U', LowRightPane = 'L', - ThisBorderOnly = 'T', AnyPane = 'A' } Direction; +typedef enum { + UpLeftPane = 'U', + LowRightPane = 'L', + ThisBorderOnly = 'T', + AnyPane = 'A' +} Direction; #define NO_INDEX -100 #define IS_GRIP NULL @@ -85,501 +85,640 @@ typedef enum {UpLeftPane = 'U', LowRightPane = 'L', #define HasGrip(w) (PaneInfo(w)->grip != NULL) #define IsPane(w) ((w)->core.widget_class != gripWidgetClass) #define PaneIndex(w) (PaneInfo(w)->position) -#define IsVert(w) ( (w)->paned.orientation == XtorientVertical ) +#define IsVert(w) ((w)->paned.orientation == XtorientVertical) #define ForAllPanes(pw, childP) \ - for ( (childP) = (pw)->composite.children ; \ - (childP) < (pw)->composite.children + (pw)->paned.num_panes ; \ - (childP)++ ) +for ((childP) = (pw)->composite.children; \ + (childP) < (pw)->composite.children + (pw)->paned.num_panes; \ + (childP)++) #define ForAllChildren(pw, childP) \ - for ( (childP) = (pw)->composite.children ; \ - (childP) < (pw)->composite.children + (pw)->composite.num_children ; \ - (childP)++ ) +for ((childP) = (pw)->composite.children; \ + (childP) < (pw)->composite.children + (pw)->composite.num_children; \ + (childP)++) -/***************************************************************************** - * - * Full instance record declaration - * - ****************************************************************************/ +#define PaneSize(paned, vertical) \ + ((vertical) ? XtHeight(paned) : XtWidth(paned)) + +#define GetRequestInfo(geo, vertical) \ + ((vertical) ? (geo)->height : (geo)->width) +#define SatisfiesRule1(pane, shrink) \ + (((shrink) && ((pane)->size != (pane)->min)) \ + || (!(shrink) && ((pane)->size != (pane)->max))) + +#define SatisfiesRule2(pane) \ + (!(pane)->skip_adjust || (pane)->paned_adjusted_me) + +#define SatisfiesRule3(pane, shrink) \ + ((pane)->paned_adjusted_me \ + && (((shrink) && ((int)(pane)->wp_size <= (pane)->size)) \ + || (!(shrink) && ((int)(pane)->wp_size >= (pane)->size)))) + + +/* + * Class Methods + */ +static void XawPanedClassInitialize(void); +static void XawPanedChangeManaged(Widget); +static void XawPanedDeleteChild(Widget); +static void XawPanedDestroy(Widget); +static XtGeometryResult XawPanedGeometryManager(Widget, XtWidgetGeometry*, + XtWidgetGeometry*); +static void XawPanedInitialize(Widget, Widget, ArgList, Cardinal*); +static void XawPanedInsertChild(Widget); +static Boolean XawPanedPaneSetValues(Widget, Widget, Widget, + ArgList, Cardinal*); +static void XawPanedRealize(Widget, Mask*, XSetWindowAttributes*); +static void XawPanedRedisplay(Widget, XEvent*, Region); +static void XawPanedResize(Widget); +static Boolean XawPanedSetValues(Widget, Widget, Widget, ArgList, Cardinal*); + +/* + * Prototypes + */ +static void _DrawInternalBorders(PanedWidget, GC); +static void _DrawRect(PanedWidget, GC, int, int, unsigned int, unsigned int); +static void _DrawTrackLines(PanedWidget, Bool); +static void AdjustPanedSize(PanedWidget, unsigned int, XtGeometryResult*, + Dimension*, Dimension*); +static void ChangeAllGripCursors(PanedWidget); +static Pane ChoosePaneToResize(PanedWidget, int, Direction, Bool); +static void ClearPaneStack(PanedWidget); +static void CommitGripAdjustment(PanedWidget); +static void CreateGrip(Widget); +static int GetEventLocation(PanedWidget, XEvent*); +static void GetGCs(Widget); +static void GetPaneStack(PanedWidget, Bool, Pane*, int*); +static void HandleGrip(Widget, XtPointer, XtPointer); +static void LoopAndRefigureChildren(PanedWidget, int, Direction, int*); +static void ManageAndUnmanageGrips(PanedWidget); +static void MoveGripAdjustment(PanedWidget, Widget, Direction, int); +static Bool PopPaneStack(PanedWidget); +static void PushPaneStack(PanedWidget, Pane); +static void RefigureLocations(PanedWidget, int, Direction); +static void RefigureLocationsAndCommit(Widget); +static void ReleaseGCs(Widget); +static void ResortChildren(PanedWidget); +static void SetChildrenPrefSizes(PanedWidget, unsigned int); +static void StartGripAdjustment(PanedWidget, Widget, Direction); + +/* + * Initialization + */ static char defGripTranslations[] = - "<Btn1Down>: GripAction(Start, UpLeftPane) \n\ - <Btn2Down>: GripAction(Start, ThisBorderOnly) \n\ - <Btn3Down>: GripAction(Start, LowRightPane) \n\ - <Btn1Motion>: GripAction(Move, UpLeft) \n\ - <Btn2Motion>: GripAction(Move, ThisBorder) \n\ - <Btn3Motion>: GripAction(Move, LowRight) \n\ - Any<BtnUp>: GripAction(Commit)"; +"<Btn1Down>:" "GripAction(Start,UpLeftPane)\n" +"<Btn2Down>:" "GripAction(Start,ThisBorderOnly)\n" +"<Btn3Down>:" "GripAction(Start,LowRightPane)\n" +"<Btn1Motion>:" "GripAction(Move,UpLeft)\n" +"<Btn2Motion>:" "GripAction(Move,ThisBorder)\n" +"<Btn3Motion>:" "GripAction(Move,LowRight)\n" +"Any<BtnUp>:" "GripAction(Commit)\n" +; #define offset(field) XtOffsetOf(PanedRec, paned.field) - static XtResource resources[] = { - {XtNinternalBorderColor, XtCBorderColor, XtRPixel, sizeof(Pixel), - offset(internal_bp), XtRString, - (XtPointer) XtDefaultForeground}, - {XtNinternalBorderWidth, XtCBorderWidth, XtRDimension, sizeof(Dimension), - offset(internal_bw), XtRImmediate, (XtPointer) 1}, - {XtNgripIndent, XtCGripIndent, XtRPosition, sizeof(Position), - offset(grip_indent), XtRImmediate, (XtPointer) 10}, - {XtNrefigureMode, XtCBoolean, XtRBoolean, sizeof(Boolean), - offset(refiguremode), XtRImmediate, (XtPointer) TRUE}, - {XtNgripTranslations, XtCTranslations, XtRTranslationTable, - sizeof(XtTranslations), - offset(grip_translations), XtRString, (XtPointer)defGripTranslations}, - {XtNorientation, XtCOrientation, XtROrientation, sizeof(XtOrientation), - offset(orientation), XtRImmediate, (XtPointer) XtorientVertical}, - - /* Cursors - both horiz and vertical have to work. */ - - {XtNcursor, XtCCursor, XtRCursor, sizeof(Cursor), - offset(cursor), XtRImmediate, None}, - {XtNgripCursor, XtCCursor, XtRCursor, sizeof(Cursor), - offset(grip_cursor), XtRImmediate, None}, - {XtNverticalGripCursor, XtCCursor, XtRCursor, sizeof(Cursor), - offset(v_grip_cursor), XtRString, "sb_v_double_arrow"}, - {XtNhorizontalGripCursor, XtCCursor, XtRCursor, sizeof(Cursor), - offset(h_grip_cursor), XtRString, "sb_h_double_arrow"}, - - {XtNbetweenCursor, XtCCursor, XtRCursor, sizeof(Cursor), - offset(adjust_this_cursor), XtRString, None}, - {XtNverticalBetweenCursor, XtCCursor, XtRCursor, sizeof(Cursor), - offset(v_adjust_this_cursor), XtRString, "sb_left_arrow"}, - {XtNhorizontalBetweenCursor, XtCCursor, XtRCursor, sizeof(Cursor), - offset(h_adjust_this_cursor), XtRString, "sb_up_arrow"}, - - {XtNupperCursor, XtCCursor, XtRCursor, sizeof(Cursor), - offset(adjust_upper_cursor), XtRString, "sb_up_arrow"}, - {XtNlowerCursor, XtCCursor, XtRCursor, sizeof(Cursor), - offset(adjust_lower_cursor), XtRString, "sb_down_arrow"}, - {XtNleftCursor, XtCCursor, XtRCursor, sizeof(Cursor), - offset(adjust_left_cursor), XtRString, "sb_left_arrow"}, - {XtNrightCursor, XtCCursor, XtRCursor, sizeof(Cursor), - offset(adjust_right_cursor), XtRString, "sb_right_arrow"}, + { + XtNinternalBorderColor, + XtCBorderColor, + XtRPixel, + sizeof(Pixel), + offset(internal_bp), + XtRString, + (XtPointer)XtDefaultForeground + }, + { + XtNinternalBorderWidth, + XtCBorderWidth, + XtRDimension, + sizeof(Dimension), + offset(internal_bw), + XtRImmediate, + (XtPointer)1 + }, + { + XtNgripIndent, + XtCGripIndent, + XtRPosition, + sizeof(Position), + offset(grip_indent), + XtRImmediate, + (XtPointer)10 + }, + { + XtNrefigureMode, + XtCBoolean, + XtRBoolean, + sizeof(Boolean), + offset(refiguremode), + XtRImmediate, + (XtPointer)True + }, + { + XtNgripTranslations, + XtCTranslations, + XtRTranslationTable, + sizeof(XtTranslations), + offset(grip_translations), + XtRString, + (XtPointer)defGripTranslations + }, + { + XtNorientation, + XtCOrientation, + XtROrientation, + sizeof(XtOrientation), + offset(orientation), + XtRImmediate, + (XtPointer)XtorientVertical + }, + { + XtNcursor, + XtCCursor, + XtRCursor, + sizeof(Cursor), + offset(cursor), + XtRImmediate, + None + }, + { + XtNgripCursor, + XtCCursor, + XtRCursor, + sizeof(Cursor), + offset(grip_cursor), + XtRImmediate, + None + }, + { + XtNverticalGripCursor, + XtCCursor, + XtRCursor, + sizeof(Cursor), + offset(v_grip_cursor), + XtRString, + "sb_v_double_arrow" + }, + { + XtNhorizontalGripCursor, + XtCCursor, + XtRCursor, + sizeof(Cursor), + offset(h_grip_cursor), + XtRString, + "sb_h_double_arrow" + }, + { + XtNbetweenCursor, + XtCCursor, + XtRCursor, + sizeof(Cursor), + offset(adjust_this_cursor), + XtRString, + None + }, + { + XtNverticalBetweenCursor, + XtCCursor, + XtRCursor, + sizeof(Cursor), + offset(v_adjust_this_cursor), + XtRString, + "sb_left_arrow" + }, + { + XtNhorizontalBetweenCursor, + XtCCursor, + XtRCursor, + sizeof(Cursor), + offset(h_adjust_this_cursor), + XtRString, + "sb_up_arrow" + }, + { + XtNupperCursor, + XtCCursor, + XtRCursor, + sizeof(Cursor), + offset(adjust_upper_cursor), + XtRString, + "sb_up_arrow" + }, + { + XtNlowerCursor, + XtCCursor, + XtRCursor, + sizeof(Cursor), + offset(adjust_lower_cursor), + XtRString, + "sb_down_arrow" + }, + { + XtNleftCursor, + XtCCursor, + XtRCursor, + sizeof(Cursor), + offset(adjust_left_cursor), + XtRString, + "sb_left_arrow" + }, + { + XtNrightCursor, + XtCCursor, + XtRCursor, + sizeof(Cursor), + offset(adjust_right_cursor), + XtRString, + "sb_right_arrow" + }, }; - #undef offset #define offset(field) XtOffsetOf(PanedConstraintsRec, paned.field) - static XtResource subresources[] = { - {XtNallowResize, XtCBoolean, XtRBoolean, sizeof(Boolean), - offset(allow_resize), XtRImmediate, (XtPointer) FALSE}, - {XtNposition, XtCPosition, XtRInt, sizeof(int), - offset(position), XtRImmediate, (XtPointer) 0}, - {XtNmin, XtCMin, XtRDimension, sizeof(Dimension), - offset(min), XtRImmediate, (XtPointer) PANED_GRIP_SIZE}, - {XtNmax, XtCMax, XtRDimension, sizeof(Dimension), - offset(max), XtRImmediate, (XtPointer) ~0}, - {XtNpreferredPaneSize, XtCPreferredPaneSize, XtRDimension, - sizeof(Dimension), offset(preferred_size), - XtRImmediate, (XtPointer) PANED_ASK_CHILD}, - {XtNresizeToPreferred, XtCBoolean, XtRBoolean, sizeof(Boolean), - offset(resize_to_pref), XtRImmediate, (XtPointer) FALSE}, - {XtNskipAdjust, XtCBoolean, XtRBoolean, sizeof(Boolean), - offset(skip_adjust), XtRImmediate, (XtPointer) FALSE}, - {XtNshowGrip, XtCShowGrip, XtRBoolean, sizeof(Boolean), - offset(show_grip), XtRImmediate, (XtPointer) TRUE}, + { + XtNallowResize, + XtCBoolean, + XtRBoolean, + sizeof(Boolean), + offset(allow_resize), + XtRImmediate, + (XtPointer)False + }, + { + XtNposition, + XtCPosition, + XtRInt, + sizeof(int), + offset(position), + XtRImmediate, + (XtPointer)0 + }, + { + XtNmin, + XtCMin, + XtRDimension, + sizeof(Dimension), + offset(min), + XtRImmediate, + (XtPointer)PANED_GRIP_SIZE + }, + { + XtNmax, + XtCMax, + XtRDimension, + sizeof(Dimension), + offset(max), + XtRImmediate, + (XtPointer)~0 + }, + { + XtNpreferredPaneSize, + XtCPreferredPaneSize, + XtRDimension, + sizeof(Dimension), + offset(preferred_size), + XtRImmediate, + (XtPointer)PANED_ASK_CHILD + }, + { + XtNresizeToPreferred, + XtCBoolean, + XtRBoolean, + sizeof(Boolean), + offset(resize_to_pref), + XtRImmediate, + (XtPointer)False + }, + { + XtNskipAdjust, + XtCBoolean, + XtRBoolean, + sizeof(Boolean), + offset(skip_adjust), + XtRImmediate, + (XtPointer)False + }, + { + XtNshowGrip, + XtCShowGrip, + XtRBoolean, + sizeof(Boolean), + offset(show_grip), + XtRImmediate, + (XtPointer)True + }, }; - #undef offset -static void ClassInitialize(), Initialize(); -static void Realize(), Resize(); -static void Redisplay(); -static void GetGCs(), ReleaseGCs(); -static void RefigureLocationsAndCommit(); -static Boolean SetValues(); -static XtGeometryResult GeometryManager(); -static void ChangeManaged(); -static void InsertChild(); -static void DeleteChild(); -static Boolean PaneSetValues(); -static Dimension PaneSize(), GetRequestInfo(); -static Boolean SatisfiesRule1(), SatisfiesRule2(), SatisfiesRule3(); - -static void PushPaneStack(); -static void GetPaneStack(); -static Boolean PopPaneStack(); -static void ClearPaneStack(); - #define SuperClass ((ConstraintWidgetClass)&constraintClassRec) PanedClassRec panedClassRec = { + /* core */ { -/* core class fields */ - /* superclass */ (WidgetClass) SuperClass, - /* class name */ "Paned", - /* size */ sizeof(PanedRec), - /* class_initialize */ ClassInitialize, - /* class_part init */ NULL, - /* class_inited */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* realize */ Realize, - /* actions */ NULL, - /* num_actions */ 0, - /* resources */ resources, - /* resource_count */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure */ TRUE, - /* compress_enterleave*/ TRUE, - /* visible_interest */ FALSE, - /* destroy */ ReleaseGCs, - /* resize */ Resize, - /* expose */ Redisplay, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* set_values_almost */ XtInheritSetValuesAlmost, - /* get_values_hook */ NULL, - /* accept_focus */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ NULL, - /* query_geometry */ XtInheritQueryGeometry, - /* display_accelerator*/ XtInheritDisplayAccelerator, - /* extension */ NULL - }, { -/* composite class fields */ - /* geometry_manager */ GeometryManager, - /* change_managed */ ChangeManaged, - /* insert_child */ InsertChild, - /* delete_child */ DeleteChild, - /* extension */ NULL - }, { -/* constraint class fields */ - /* subresources */ subresources, - /* subresource_count */ XtNumber(subresources), - /* constraint_size */ sizeof(PanedConstraintsRec), - /* initialize */ NULL, - /* destroy */ NULL, - /* set_values */ PaneSetValues, - /* extension */ NULL - } + (WidgetClass)SuperClass, /* superclass */ + "Paned", /* class name */ + sizeof(PanedRec), /* size */ + XawPanedClassInitialize, /* class_initialize */ + NULL, /* class_part init */ + False, /* class_inited */ + XawPanedInitialize, /* initialize */ + NULL, /* initialize_hook */ + XawPanedRealize, /* realize */ + NULL, /* actions */ + 0, /* num_actions */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + True, /* compress_motion */ + True, /* compress_exposure */ + True, /* compress_enterleave */ + False, /* visible_interest */ + XawPanedDestroy, /* destroy */ + XawPanedResize, /* resize */ + XawPanedRedisplay, /* expose */ + XawPanedSetValues, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + NULL, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + NULL, /* tm_table */ + XtInheritQueryGeometry, /* query_geometry */ + XtInheritDisplayAccelerator, /* display_accelerator */ + NULL, /* extension */ + }, + /* composite */ + { + XawPanedGeometryManager, /* geometry_manager */ + XawPanedChangeManaged, /* change_managed */ + XawPanedInsertChild, /* insert_child */ + XawPanedDeleteChild, /* delete_child */ + NULL, /* extension */ + }, + /* constraint */ + { + subresources, /* subresources */ + XtNumber(subresources), /* subresource_count */ + sizeof(PanedConstraintsRec), /* constraint_size */ + NULL, /* initialize */ + NULL, /* destroy */ + XawPanedPaneSetValues, /* set_values */ + NULL, /* extension */ + }, }; -WidgetClass panedWidgetClass = (WidgetClass) &panedClassRec; +WidgetClass panedWidgetClass = (WidgetClass)&panedClassRec; +WidgetClass vPanedWidgetClass = (WidgetClass)&panedClassRec; -/* For compatibility. */ -WidgetClass vPanedWidgetClass = (WidgetClass) &panedClassRec; - -/*********************************************************** +/* + * Implementation + */ +/* Function: + * AdjustPanedSize * - * Private Functions. + * Parameters: + * pw - paned widget to adjust + * off_size - new off_size to use + * result_ret - result of query (return) + * on_size_ret - new on_size (return) + * off_size_ret - new off_size (return) * - ************************************************************/ - -/* Function Name: AdjustPanedSize - * Description: Adjusts the size of the pane. - * Arguments: pw - the paned widget to adjust. - * off_size - the new off_size to use. - * result_ret - result of query ** RETURNED ** - * on_size_ret - the new on_size ** RETURNED ** - * off_size_ret - the new off_size ** RETURNED ** - * Returns: the amount of change in size. + * Description: + * Adjusts the size of the pane. + * + * Returns: + * amount of change in size */ - static void -AdjustPanedSize(pw, off_size, result_ret, on_size_ret, off_size_ret) -PanedWidget pw; -Dimension off_size; -XtGeometryResult * result_ret; -Dimension * on_size_ret, * off_size_ret; +AdjustPanedSize(PanedWidget pw, unsigned int off_size, + XtGeometryResult *result_ret, + Dimension *on_size_ret, Dimension *off_size_ret) { - Dimension old_size = PaneSize( (Widget) pw, IsVert(pw)); + Dimension old_size = PaneSize((Widget)pw, IsVert(pw)); Dimension newsize = 0; - Widget * childP; + Widget *childP; XtWidgetGeometry request, reply; + request.request_mode = CWWidth | CWHeight; ForAllPanes(pw, childP) { - int size = Max(PaneInfo(*childP)->size, (int)PaneInfo(*childP)->min); - AssignMin(size, (int) PaneInfo(*childP)->max); - newsize += size + pw->paned.internal_bw; + int size = Max(PaneInfo(*childP)->size, (int)PaneInfo(*childP)->min); + + AssignMin(size, (int)PaneInfo(*childP)->max); + newsize += size + pw->paned.internal_bw; } newsize -= pw->paned.internal_bw; - if (newsize < 1) newsize = 1; + if (newsize < 1) + newsize = 1; - if ( IsVert(pw) ) { - request.width = off_size; + if (IsVert(pw)) { + request.width = off_size; request.height = newsize; } else { - request.width = newsize; + request.width = newsize; request.height = off_size; } if (result_ret != NULL) { - request.request_mode |= XtCWQueryOnly; - - *result_ret = XtMakeGeometryRequest( (Widget) pw, &request, &reply ); - _XawImCallVendorShellExtResize( (Widget) pw ); - - if ( (newsize == old_size) || (*result_ret == XtGeometryNo) ) { - *on_size_ret = old_size; - *off_size_ret = off_size; - return; - } - if (*result_ret != XtGeometryAlmost) { - *on_size_ret = GetRequestInfo( &request, IsVert(pw) ); - *off_size_ret = GetRequestInfo( &request, !IsVert(pw) ); - return; - } - *on_size_ret = GetRequestInfo( &reply, IsVert(pw) ); - *off_size_ret = GetRequestInfo( &reply, !IsVert(pw) ); - return; - } - - if (newsize == old_size) return; + request.request_mode |= XtCWQueryOnly; - if (XtMakeGeometryRequest( (Widget) pw, - &request, &reply) == XtGeometryAlmost) - XtMakeGeometryRequest( (Widget) pw, &reply, &request); -} - -/* Function Name: PaneSize - * Description: returns the width or height of the pane depending - * upon the orientation we are using. - * Arguments: w - and widget. - * vertical - TRUE if this is vertically oriented pane. - * Returns: the size requested - * - * vertical - return height - * !vertical - return width - */ + *result_ret = XtMakeGeometryRequest((Widget)pw, &request, &reply); + _XawImCallVendorShellExtResize((Widget)pw); -static Dimension -PaneSize(w, vertical) -Widget w; -Boolean vertical; -{ - if (vertical) return (w->core.height); - return (w->core.width); -} + if (newsize == old_size || *result_ret == XtGeometryNo) { + *on_size_ret = old_size; + *off_size_ret = off_size; + return; + } + if (*result_ret != XtGeometryAlmost) { + *on_size_ret = GetRequestInfo(&request, IsVert(pw)); + *off_size_ret = GetRequestInfo(&request, !IsVert(pw)); + return; + } + *on_size_ret = GetRequestInfo(&reply, IsVert(pw)); + *off_size_ret = GetRequestInfo(&reply, !IsVert(pw)); + return; + } -/* Function Name: GetRequestInfo - * Description: returns request information. - * Arguments: geo_struct - a geometry struct to get information out of. - * vert - TRUE if this is a vertical paned widget. - * Returns: the request information. - */ + if (newsize == old_size) + return; -static Dimension -GetRequestInfo(geo_struct, vert) -XtWidgetGeometry * geo_struct; -Boolean vert; -{ - if ( vert ) return ( (Dimension) geo_struct->height); - return ( (Dimension) geo_struct->width); + if (XtMakeGeometryRequest((Widget)pw, &request, &reply) == XtGeometryAlmost) + XtMakeGeometryRequest((Widget)pw, &reply, &request); } -/* Function Name: ChoosePaneToResize. - * Description: This function chooses a pane to resize. - * They are chosen using the following rules: - * - * 1) size < max && size > min - * 2) skip adjust == FALSE - * 3) widget not its prefered height && - * this change will bring it closer && - * The user has not resized this pane. - * - * If no widgets are found that fits all the rules then - * rule #3 is broken. - * If there are still no widgets found than - * rule #2 is broken. - * Rule #1 is never broken. - * If no widgets are found then NULL is returned. +/* + * Function: + * ChoosePaneToResize. + * + * Parameters: + * pw - paned widget + * paneindex - index of the current pane + * dir - direction to search first + * shrink - True if we need to shrink a pane, False otherwise + * + * Description: + * This function chooses a pane to resize. + They are chosen using the following rules: + * + * 1) size < max && size > min + * 2) skip adjust == False + * 3) widget not its prefered height + * && this change will bring it closer + * && The user has not resized this pane. + * + * If no widgets are found that fits all the rules then + * rule #3 is broken. + * If there are still no widgets found than + * rule #2 is broken. + * Rule #1 is never broken. + * If no widgets are found then NULL is returned. * - * Arguments: pw - the paned widget. - * paneindex - the index of the current pane. - * dir - direction to search first. - * shrink - TRUE if we need to shrink a pane, FALSE otherwise. - * Returns: pane to resize or NULL. + * Returns: + * pane to resize or NULL */ - static Pane -ChoosePaneToResize(pw, paneindex, dir, shrink) -PanedWidget pw; -int paneindex; -Direction dir; -Boolean shrink; +ChoosePaneToResize(PanedWidget pw, int paneindex, Direction dir, Bool shrink) { Widget *childP; int rules = 3; Direction _dir = dir; int _index = paneindex; - if ( (paneindex == NO_INDEX) || (dir == AnyPane) ) { /* Use defaults. */ - _dir = LowRightPane; /* Go up. - really. */ - _index = pw->paned.num_panes - 1; /* Start the last pane, and work - backwards. */ + if (paneindex == NO_INDEX || dir == AnyPane) { /* Use defaults */ + _dir = LowRightPane; /* Go up - really */ + _index = pw->paned.num_panes - 1; /* Start the last pane, and work + backwards */ } childP = pw->composite.children + _index; - /* CONSTCOND */ - while(TRUE) { - Pane pane = PaneInfo(*childP); - - if ( (rules < 3 || SatisfiesRule3(pane, shrink)) && - (rules < 2 || SatisfiesRule2(pane)) && - (SatisfiesRule1(pane, shrink)) && - ((paneindex != PaneIndex(*childP)) || (dir == AnyPane)) ) - return(pane); - -/* - * This is counter-intuitive, but if we are resizing the pane - * above the grip we want to choose a pane below the grip to lose, - * and visa-versa. - */ - - if (_dir == LowRightPane) --childP; else ++childP; - -/* - * If we have come to and edge then reduce the rule set, and try again. - * If we are reduced the rules to none, then return NULL. - */ + /*CONSTCOND*/ + while(True) { + Pane pane = PaneInfo(*childP); - if ( (childP - pw->composite.children < 0) || - (childP - pw->composite.children >= pw->paned.num_panes) ) { - if (--rules < 1) /* less strict rules. */ - return(NULL); + if ((rules < 3 || SatisfiesRule3(pane, shrink)) + && (rules < 2 || SatisfiesRule2(pane)) + && SatisfiesRule1(pane, shrink) + && (paneindex != PaneIndex(*childP) || dir == AnyPane)) + return (pane); + + /* + * This is counter-intuitive, but if we are resizing the pane + * above the grip we want to choose a pane below the grip to lose, + * and visa-versa + */ + if (_dir == LowRightPane) + --childP; + else + ++childP; + + /* + * If we have come to and edge then reduce the rule set, and try again + * If we are reduced the rules to none, then return NULL + */ + if ((childP - pw->composite.children) < 0 || + (childP - pw->composite.children) >= pw->paned.num_panes) { + if (--rules < 1) /* less strict rules */ + return (NULL); childP = pw->composite.children + _index; } } } -/* Function Name: StatisfiesRule1 - * Description: check for to see if this pane satisfies rule 1. - * Arguments: pane - the pane to check. - * shrink -TRUE if we want to shrink this pane, FALSE otherwise - * Returns: TRUE if the rule is satisfied. - */ - -static Boolean -SatisfiesRule1(pane, shrink) -Pane pane; -Boolean shrink; -{ - return( (shrink && (pane->size != pane->min)) || - (!shrink && (pane->size != pane->max)) ); -} - -/* Function Name: StatisfiesRule2 - * Description: check for to see if this pane satisfies rule 2. - * Arguments: pane - the pane to check. - * Returns: TRUE if the rule is satisfied. - */ - -static Boolean -SatisfiesRule2(pane) -Pane pane; -{ - return(!pane->skip_adjust || pane->paned_adjusted_me); -} - -/* Function Name: StatisfiesRule3 - * Description: check for to see if this pane satisfies rule 3. - * Arguments: pane - the pane to check. - * shrink -TRUE if we want to shrink this pane, FALSE otherwise - * Returns: TRUE if the rule is satisfied. - */ - -static Boolean -SatisfiesRule3(pane, shrink) -Pane pane; -Boolean shrink; -{ - return ( pane->paned_adjusted_me && - ( (shrink && ((int)pane->wp_size <= pane->size)) || - (!shrink && ((int)pane->wp_size >= pane->size))) ); -} - -/* Function Name: LoopAndRefigureChildren. - * Description: if we are resizing either the UpleftPane or LowRight Pane - * loop through all the children to see if any will allow us - * to resize them. - * Arguments: pw - the paned widget. - * paneindex - the number of the pane border we are moving. - * dir - the pane to move (either UpLeftPane or LowRightPane). - * sizeused - current amount of space used. - * THIS VALUE IS USED AND RETURNED. - * Returns: none. +/* + * Function: + * LoopAndRefigureChildren + * + * Parameters: + * pw - paned widget + * paneindex - number of the pane border we are moving + * dir - pane to move (either UpLeftPane or LowRightPane) + * sizeused - current amount of space used (used and returned) + * + * Description: + * If we are resizing either the UpleftPane or LowRight Pane loop + * through all the children to see if any will allow us to resize them. */ - static void -LoopAndRefigureChildren(pw, paneindex, dir, sizeused) -PanedWidget pw; -int paneindex, *sizeused; -Direction dir; +LoopAndRefigureChildren(PanedWidget pw, int paneindex, Direction dir, + int *sizeused) { - int pane_size = (int) PaneSize( (Widget) pw, IsVert(pw)); + int pane_size = (int)PaneSize((Widget)pw, IsVert(pw)); Boolean shrink = (*sizeused > pane_size); - if (dir == LowRightPane) paneindex++; - - while (*sizeused != pane_size) { /* While all panes do not fit properly. */ -/* - * Choose a pane to resize. - * First look on the Pane Stack, and then go hunting for another one. - * If we fail to find a pane to resize then give up. - */ - Pane pane; + if (dir == LowRightPane) + paneindex++; + + /* While all panes do not fit properly */ + while (*sizeused != pane_size) { + /* + * Choose a pane to resize + * First look on the Pane Stack, and then go hunting for another one + * If we fail to find a pane to resize then give up + */ + Pane pane; int start_size; Dimension old; - Boolean rule3_ok = FALSE, from_stack = TRUE; + Boolean rule3_ok = False, from_stack = True; GetPaneStack(pw, shrink, &pane, &start_size); if (pane == NULL) { pane = ChoosePaneToResize(pw, paneindex, dir, shrink); if (pane == NULL) - return; /* no one to resize, give up. */ + return; /* no one to resize, give up */ rule3_ok = SatisfiesRule3(pane, shrink); - from_stack = FALSE; + from_stack = False; PushPaneStack(pw, pane); } - -/* - * Try to resize this pane so that all panes will fit, take min and max - * into account. - */ + /* + * Try to resize this pane so that all panes will fit, take min and max + * into account + */ old = pane->size; pane->size += pane_size - *sizeused; if (from_stack) { if (shrink) { - AssignMax(pane->size, start_size); - } /* don't remove these braces. */ + AssignMax(pane->size, start_size); + } /* don't remove these braces */ else - AssignMin(pane->size, start_size); + AssignMin(pane->size, start_size); - if (pane->size == start_size) (void) PopPaneStack(pw); + if (pane->size == start_size) + (void)PopPaneStack(pw); } else if (rule3_ok) { if (shrink) { - AssignMax(pane->size, (int) pane->wp_size); - } /* don't remove these braces. */ + AssignMax(pane->size, (int)pane->wp_size); + } /* don't remove these braces */ else - AssignMin(pane->size, (int) pane->wp_size); + AssignMin(pane->size, (int)pane->wp_size); } - pane->paned_adjusted_me = (pane->size != pane->wp_size); - AssignMax(pane->size, (int) pane->min); - AssignMin(pane->size, (int) pane->max); + pane->paned_adjusted_me = pane->size != pane->wp_size; + AssignMax(pane->size, (int)pane->min); + AssignMin(pane->size, (int)pane->max); *sizeused += (pane->size - old); } } -/* Function Name: RefigureLocations - * Description: refigures all locations of children. - * Arguments: pw - the paned widget. - * paneindex - child to start refiguring at. - * dir - direction to move from child. - * Returns: none. +/* + * Function: + * RefigureLocations * + * Parameters: + * pw - paned widget + * paneindex - child to start refiguring at + * dir - direction to move from child + * + * Description: + * Refigures all locations of children. * There are special arguments to paneindex and dir, they are: * paneindex - NO_INDEX. * dir - AnyPane. @@ -588,44 +727,39 @@ Direction dir; * the choosing of panes procedes in reverse order starting with the * last child. */ - static void -RefigureLocations(pw, paneindex, dir) -PanedWidget pw; -int paneindex; -Direction dir; +RefigureLocations(PanedWidget pw, int paneindex, Direction dir) { Widget *childP; - int pane_size = (int) PaneSize( (Widget) pw, IsVert(pw) ); + int pane_size = (int)PaneSize((Widget)pw, IsVert(pw)); int sizeused = 0; Position loc = 0; - if (pw->paned.num_panes == 0 || !pw->paned.refiguremode) return; - -/* - * Get an initial estimate of the size we will use. - */ + if (pw->paned.num_panes == 0 || !pw->paned.refiguremode) + return; + /* + * Get an initial estimate of the size we will use + */ ForAllPanes(pw, childP) { - Pane pane = PaneInfo(*childP); + Pane pane = PaneInfo(*childP); + AssignMax(pane->size, (int) pane->min); AssignMin(pane->size, (int) pane->max); - sizeused += (int) pane->size + (int) pw->paned.internal_bw; + sizeused += (int)pane->size + (int)pw->paned.internal_bw; } - sizeused -= (int) pw->paned.internal_bw; - - if ( (dir != ThisBorderOnly) && (sizeused != pane_size) ) - LoopAndRefigureChildren(pw, paneindex, dir, &sizeused); - -/* - * If we still are not the right size, then tell the pane that - * wanted to resize that it can't. - */ + sizeused -= (int)pw->paned.internal_bw; + if (dir != ThisBorderOnly && sizeused != pane_size) + LoopAndRefigureChildren(pw, paneindex, dir, &sizeused); - if ( (paneindex != NO_INDEX) && (dir != AnyPane) ) { + /* + * If we still are not the right size, then tell the pane that + * wanted to resize that it can't + */ + if (paneindex != NO_INDEX && dir != AnyPane) { Pane pane = PaneInfo(*(pw->composite.children + paneindex)); - Dimension old = pane->size; + Dimension old = pane->size; pane->size += pane_size - sizeused; AssignMax(pane->size, (int) pane->min); @@ -633,28 +767,30 @@ Direction dir; sizeused += pane->size - old; } -/* - * It is possible that the panes will not fit inside the vpaned widget, but - * we have tried out best. - * - * Assign each pane a location. - */ - + /* + * It is possible that the panes will not fit inside the vpaned widget, but + * we have tried out best + * + * Assign each pane a location + */ ForAllPanes(pw, childP) { - PaneInfo(*childP)->delta = loc; - loc += PaneInfo(*childP)->size + pw->paned.internal_bw; + PaneInfo(*childP)->delta = loc; + loc += PaneInfo(*childP)->size + pw->paned.internal_bw; } } -/* Function Name: CommitNewLocations - * Description: Commits all of the previously figured locations. - * Arguments: pw - the paned widget. - * Returns: none. +/* + * Function: + * CommitNewLocations + * + * Parameters: + * pw - paned widget + * + * Description: + * Commits all of the previously figured locations. */ - static void -CommitNewLocations(pw) -PanedWidget pw; +CommitNewLocations(PanedWidget pw) { Widget *childP; XWindowChanges changes; @@ -663,159 +799,157 @@ PanedWidget pw; ForAllPanes(pw, childP) { Pane pane = PaneInfo(*childP); - Widget grip = pane->grip; /* may be NULL. */ + Widget grip = pane->grip; /* may be NULL */ if (IsVert(pw)) { XtMoveWidget(*childP, (Position) 0, pane->delta); - XtResizeWidget(*childP, pw->core.width, (Dimension) pane->size, - (Dimension) 0); - - if (HasGrip(*childP)) { /* Move and Display the Grip */ - changes.x = pw->core.width - pw->paned.grip_indent - - grip->core.width - grip->core.border_width*2; - changes.y = (*childP)->core.y + (*childP)->core.height - - grip->core.height/2 - grip->core.border_width + - pw->paned.internal_bw/2; + XtResizeWidget(*childP, XtWidth(pw), pane->size, 0); + + if (HasGrip(*childP)) { /* Move and Display the Grip */ + changes.x = XtWidth(pw) - pw->paned.grip_indent - + XtWidth(grip) - (XtBorderWidth(grip) << 1); + changes.y = XtY(*childP) + XtHeight(*childP) - + (XtHeight(grip) >> 1) - XtBorderWidth(grip) + + (pw->paned.internal_bw >> 1); } } else { - XtMoveWidget(*childP, pane->delta, (Position) 0); - XtResizeWidget(*childP, (Dimension) pane->size, pw->core.height, - (Dimension) 0); - - - if (HasGrip(*childP)) { /* Move and Display the Grip */ - changes.x = (*childP)->core.x + (*childP)->core.width - - grip->core.width/2 - grip->core.border_width + - pw->paned.internal_bw/2; - changes.y = pw->core.height - pw->paned.grip_indent - - grip->core.height - grip->core.border_width*2; + XtMoveWidget(*childP, pane->delta, 0); + XtResizeWidget(*childP, pane->size, XtHeight(pw), 0); + + if (HasGrip(*childP)) { /* Move and Display the Grip */ + changes.x = XtX(*childP) + XtWidth(*childP) - + (XtWidth(grip) >> 1) - XtBorderWidth(grip) + + (pw->paned.internal_bw >> 1); + changes.y = XtHeight(pw) - pw->paned.grip_indent - + XtHeight(grip) - (XtBorderWidth(grip) << 1); } } -/* - * This should match XtMoveWidget, except that we're also insuring the - * grip is Raised in the same request. - */ + /* + * This should match XtMoveWidget, except that we're also insuring the + * grip is Raised in the same request + */ if (HasGrip(*childP)) { - grip->core.x = changes.x; - grip->core.y = changes.y; + XtX(grip) = changes.x; + XtY(grip) = changes.y; if (XtIsRealized(pane->grip)) - XConfigureWindow( XtDisplay(pane->grip), XtWindow(pane->grip), - CWX | CWY | CWStackMode, &changes ); + XConfigureWindow(XtDisplay(pane->grip), XtWindow(pane->grip), + CWX | CWY | CWStackMode, &changes); } } ClearPaneStack(pw); } -/* Function Name: RefigureLocationsAndCommit - * Description: Refigures all locations in a paned widget and - * commits them immediately. - * Arguments: pw - the paned widget. - * Returns: none +/* + * Function: + * RefigureLocationsAndCommit + * + * Parameters: + * pw - paned widget + * + * Description: + * Refigures all locations in a paned widget and commits them immediately. * * This function does nothing if any of the following are true. * o refiguremode is false. * o The widget is unrealized. * o There are no panes is the paned widget. - * - * NOTE: This is the resize Procedure for the Paned widget. */ - static void -RefigureLocationsAndCommit(w) -Widget w; +RefigureLocationsAndCommit(Widget w) { - PanedWidget pw = (PanedWidget) w; - if (pw->paned.refiguremode && XtIsRealized( (Widget) pw) && - pw->paned.num_panes > 0 ) { + PanedWidget pw = (PanedWidget)w; + + if (pw->paned.refiguremode && XtIsRealized(w) && pw->paned.num_panes > 0) { RefigureLocations(pw, NO_INDEX, AnyPane); CommitNewLocations(pw); } } -/* Function Name: _DrawRect - * Description: Draws a rectangle in the proper orientation. - * Arguments: pw - the paned widget. - * gc - gc to used for the draw. - * on_olc, off_loc - location of upper left corner of rect. - * on_size, off_size - size of rectangle. - * Returns: none +/* + * Function: + * _DrawRect + * + * Parameters: + * pw - paned widget + * gc - gc to used for the draw + * on_olc - location of upper left corner of rect + * off_loc - "" + * on_size - size of rectangle + * off_size - "" + * + * Description: + * Draws a rectangle in the proper orientation. */ - static void -_DrawRect(pw, gc, on_loc, off_loc, on_size, off_size) -PanedWidget pw; -GC gc; -int on_loc, off_loc; -unsigned int on_size, off_size; +_DrawRect(PanedWidget pw, GC gc, int on_loc, int off_loc, + unsigned int on_size, unsigned int off_size) { - if (IsVert(pw)) - XFillRectangle(XtDisplay(pw), XtWindow(pw), gc, - off_loc, on_loc, off_size, on_size); - else - XFillRectangle(XtDisplay(pw), XtWindow(pw), gc, - on_loc, off_loc, on_size, off_size); + if (IsVert(pw)) + XFillRectangle(XtDisplay((Widget)pw), XtWindow((Widget)pw), gc, + off_loc, on_loc, off_size, on_size); + else + XFillRectangle(XtDisplay((Widget)pw), XtWindow((Widget)pw), gc, + on_loc, off_loc, on_size, off_size); } -/* Function Name: _DrawInternalBorders - * Description: Draws the internal borders into the paned widget. - * Arguments: pw - the paned widget. - * gc - the GC to use to draw the borders. - * Returns: none. +/* + * Function: + * _DrawInternalBorders + * + * Parameters: + * pw - paned widget + * gc - GC to use to draw the borders + * + * Description: + * Draws the internal borders into the paned widget. */ - static void -_DrawInternalBorders(pw, gc) -PanedWidget pw; -GC gc; +_DrawInternalBorders(PanedWidget pw, GC gc) { Widget *childP; int on_loc, off_loc; unsigned int on_size, off_size; -/* - * This is an optimization. Do not paint the internal borders if - * they are the same color as the background. - */ - + /* + * This is an optimization. Do not paint the internal borders if + * they are the same color as the background + */ if (pw->core.background_pixel == pw->paned.internal_bp) return; off_loc = 0; - off_size = (unsigned int) PaneSize( (Widget) pw, !IsVert(pw) ); - on_size = (unsigned int) pw->paned.internal_bw; + off_size = (unsigned int) PaneSize((Widget)pw, !IsVert(pw)); + on_size = (unsigned int)pw->paned.internal_bw; ForAllPanes(pw, childP) { - on_loc = IsVert(pw) ? (*childP)->core.y : (*childP)->core.x; - on_loc -= (int) on_size; + on_loc = IsVert(pw) ? XtY(*childP) : XtX(*childP); + on_loc -= (int)on_size; - _DrawRect( pw, gc, on_loc, off_loc, on_size, off_size); + _DrawRect(pw, gc, on_loc, off_loc, on_size, off_size); } } +#define DrawInternalBorders(pw) \ + _DrawInternalBorders((pw), (pw)->paned.normgc) +#define EraseInternalBorders(pw) \ + _DrawInternalBorders((pw), (pw)->paned.invgc) /* - * This allows good reuse of code, as well as descriptive function names. - */ - -#define DrawInternalBorders(pw) _DrawInternalBorders((pw), (pw)->paned.normgc); -#define EraseInternalBorders(pw) _DrawInternalBorders((pw), (pw)->paned.invgc); - -/* Function Name: _DrawTrackLines - * Description: Draws the lines that animate the pane borders when the - * grips are moved. - * Arguments: pw - the Paned widget. - * erase - if True then just erase track lines, else - * draw them in. - * Returns: none. + * Function Name: + * _DrawTrackLines + * + * Parameters: + * pw - Paned widget + * erase - if True then just erase track lines, else draw them in + * + * Description: + * Draws the lines that animate the pane borders when the grips are moved. */ - static void -_DrawTrackLines(pw, erase) -PanedWidget pw; -Boolean erase; +_DrawTrackLines(PanedWidget pw, Bool erase) { Widget *childP; Pane pane; @@ -823,20 +957,19 @@ Boolean erase; unsigned int on_size, off_size; off_loc = 0; - off_size = PaneSize( (Widget) pw, !IsVert(pw)); + off_size = PaneSize((Widget)pw, !IsVert(pw)); ForAllPanes(pw, childP) { - pane = PaneInfo(*childP); - if ( erase || (pane->olddelta != pane->delta) ) { + pane = PaneInfo(*childP); + if (erase || pane->olddelta != pane->delta) { on_size = pw->paned.internal_bw; if (!erase) { - on_loc = PaneInfo(*childP)->olddelta - (int) on_size; - - _DrawRect( pw, pw->paned.flipgc, + on_loc = PaneInfo(*childP)->olddelta - (int) on_size; + _DrawRect(pw, pw->paned.flipgc, on_loc, off_loc, on_size, off_size); } - on_loc = PaneInfo(*childP)->delta - (int) on_size; + on_loc = PaneInfo(*childP)->delta - (int)on_size; _DrawRect(pw, pw->paned.flipgc, on_loc, off_loc, on_size, off_size); @@ -846,31 +979,31 @@ Boolean erase; } } +#define DrawTrackLines(pw) _DrawTrackLines((pw), False); +#define EraseTrackLines(pw) _DrawTrackLines((pw), True); /* - * This allows good reuse of code, as well as descriptive function names. - */ - -#define DrawTrackLines(pw) _DrawTrackLines((pw), FALSE); -#define EraseTrackLines(pw) _DrawTrackLines((pw), TRUE); - -/* Function Name: GetEventLocation - * Description: Converts and event to an x and y location. - * Arguments: pw - the paned widget. - * event - a pointer to an event. - * Returns: if this is a vertical pane then (y) else (x). + * Function: + * GetEventLocation + * + * Parameters: + * pw - the paned widget + * event - pointer to an event + * + * Description: + * Converts and event to an x and y location. + * + * Returns: + * if this is a vertical pane then (y) else (x) */ - static int -GetEventLocation(pw, event) -PanedWidget pw; -XEvent *event; +GetEventLocation(PanedWidget pw, XEvent *event) { int x, y; switch (event->xany.type) { - case ButtonPress: + case ButtonPress: case ButtonRelease: - x = event->xbutton.x_root; + x = event->xbutton.x_root; y = event->xbutton.y_root; break; case KeyPress: @@ -878,7 +1011,7 @@ XEvent *event; x = event->xkey.x_root; y = event->xkey.y_root; break; - case MotionNotify: + case MotionNotify: x = event->xmotion.x_root; y = event->xmotion.y_root; break; @@ -886,47 +1019,49 @@ XEvent *event; x = pw->paned.start_loc; y = pw->paned.start_loc; } + if (IsVert(pw)) - return(y); - return(x); + return (y); + + return (x); } -/* Function Name: StartGripAdjustment - * Description: Starts the grip adjustment procedure. - * Arguments: pw - the paned widget. - * grip - the grip widget selected. - * dir - the direction that we are to be moving. - * Returns: none. +/* + * Function: + * StartGripAdjustment + * + * Parameters: + * pw - paned widget + * grip - grip widget selected + * dir - direction that we are to be moving + * + * Description: + * Starts the grip adjustment procedure. */ - static void -StartGripAdjustment(pw, grip, dir) -PanedWidget pw; -Widget grip; -Direction dir; +StartGripAdjustment(PanedWidget pw, Widget grip, Direction dir) { Widget *childP; Cursor cursor; - pw->paned.whichadd = pw->paned.whichsub = (Widget) NULL; + pw->paned.whichadd = pw->paned.whichsub = NULL; if (dir == ThisBorderOnly || dir == UpLeftPane) - pw->paned.whichadd = pw->composite.children[PaneIndex(grip)]; + pw->paned.whichadd = pw->composite.children[PaneIndex(grip)]; if (dir == ThisBorderOnly || dir == LowRightPane) - pw->paned.whichsub = pw->composite.children[PaneIndex(grip) + 1]; - -/* - * Change the cursor. - */ + pw->paned.whichsub = pw->composite.children[PaneIndex(grip) + 1]; + /* + * Change the cursor + */ if (XtIsRealized(grip)) { - if ( IsVert(pw) ) { + if (IsVert(pw)) { if (dir == UpLeftPane) - cursor = pw->paned.adjust_upper_cursor; + cursor = pw->paned.adjust_upper_cursor; else if (dir == LowRightPane) - cursor = pw->paned.adjust_lower_cursor; + cursor = pw->paned.adjust_lower_cursor; else { - if ( pw->paned.adjust_this_cursor == None) + if (pw->paned.adjust_this_cursor == None) cursor = pw->paned.v_adjust_this_cursor; else cursor = pw->paned.adjust_this_cursor; @@ -934,11 +1069,11 @@ Direction dir; } else { if (dir == UpLeftPane) - cursor = pw->paned.adjust_left_cursor; + cursor = pw->paned.adjust_left_cursor; else if (dir == LowRightPane) - cursor = pw->paned.adjust_right_cursor; + cursor = pw->paned.adjust_right_cursor; else { - if (pw->paned.adjust_this_cursor == None) + if (pw->paned.adjust_this_cursor == None) cursor = pw->paned.h_adjust_this_cursor; else cursor = pw->paned.adjust_this_cursor; @@ -950,252 +1085,265 @@ Direction dir; EraseInternalBorders(pw); ForAllPanes(pw, childP) - PaneInfo(*childP)->olddelta = -99; + PaneInfo(*childP)->olddelta = -99; + + EraseTrackLines(pw); } -/* Function Name: MoveGripAdjustment - * Description: This routine moves all panes around when a grip is moved. - * Arguments: pw - the paned widget. - * grip - the grip that we are moving. - * dir - the direction the pane we are interested is w.r.t the - * grip. - * loc - location of pointer in proper direction. - * Returns: none. +/* + * Function: + * MoveGripAdjustment + * + * Parameters: + * pw - paned widget + * grip - grip that we are moving + * dir - direction the pane we are interested is w.r.t the grip + * loc - location of pointer in proper direction + * + * Description: + * This routine moves all panes around when a grip is moved. */ - static void -MoveGripAdjustment(pw, grip, dir, loc) -PanedWidget pw; -Widget grip; -Direction dir; -int loc; +MoveGripAdjustment(PanedWidget pw, Widget grip, Direction dir, int loc) { int diff, add_size = 0, sub_size = 0; diff = loc - pw->paned.start_loc; if (pw->paned.whichadd) - add_size = PaneSize(pw->paned.whichadd, IsVert(pw) ) + diff; + add_size = PaneSize(pw->paned.whichadd, IsVert(pw)) + diff; if (pw->paned.whichsub) - sub_size = PaneSize(pw->paned.whichsub, IsVert(pw) ) - diff; - -/* - * If moving this border only then do not allow either of the borders - * to go beyond the min or max size allowed. - */ - - if ( (dir == ThisBorderOnly) ) { - int old_add_size = add_size, old_sub_size; - - AssignMax(add_size, (int) PaneInfo(pw->paned.whichadd)->min); - AssignMin(add_size, (int) PaneInfo(pw->paned.whichadd)->max); - if (add_size != old_add_size) - sub_size += old_add_size - add_size; - - old_sub_size = sub_size; - AssignMax(sub_size, (int) PaneInfo(pw->paned.whichsub)->min); - AssignMin(sub_size, (int) PaneInfo(pw->paned.whichsub)->max); - if (sub_size != old_sub_size) return; /* Abort to current sizes. */ + sub_size = PaneSize(pw->paned.whichsub, IsVert(pw)) - diff; + + /* + * If moving this border only then do not allow either of the borders + * to go beyond the min or max size allowed + */ + if (dir == ThisBorderOnly) { + int old_add_size = add_size, old_sub_size; + + AssignMax(add_size, (int)PaneInfo(pw->paned.whichadd)->min); + AssignMin(add_size, (int)PaneInfo(pw->paned.whichadd)->max); + if (add_size != old_add_size) + sub_size += old_add_size - add_size; + + old_sub_size = sub_size; + AssignMax(sub_size, (int)PaneInfo(pw->paned.whichsub)->min); + AssignMin(sub_size, (int)PaneInfo(pw->paned.whichsub)->max); + if (sub_size != old_sub_size) + return; /* Abort to current sizes */ } if (add_size != 0) - PaneInfo(pw->paned.whichadd)->size = add_size; + PaneInfo(pw->paned.whichadd)->size = add_size; if (sub_size != 0) - PaneInfo(pw->paned.whichsub)->size = sub_size; + PaneInfo(pw->paned.whichsub)->size = sub_size; RefigureLocations(pw, PaneIndex(grip), dir); DrawTrackLines(pw); } -/* Function Name: CommitGripAdjustment - * Description: Commits the grip adjustment. - * Arguments: pw - the paned widget. - * Returns: none +/* + * Function: + * CommitGripAdjustment + * + * Parameters: + * pw - paned widget + * + * Description: + * Commits the grip adjustment. */ - static void -CommitGripAdjustment(pw) -PanedWidget pw; +CommitGripAdjustment(PanedWidget pw) { EraseTrackLines(pw); CommitNewLocations(pw); DrawInternalBorders(pw); -/* - * Since the user selected this size then use it as the preferred size. - */ - + /* + * Since the user selected this size then use it as the preferred size + */ if (pw->paned.whichadd) { - Pane pane = PaneInfo(pw->paned.whichadd); + Pane pane = PaneInfo(pw->paned.whichadd); + pane->wp_size = pane->size; } if (pw->paned.whichsub) { - Pane pane = PaneInfo(pw->paned.whichsub); + Pane pane = PaneInfo(pw->paned.whichsub); + pane->wp_size = pane->size; } } -/* Function Name: HandleGrip - * Description: Handles the grip manipulations. - * Arguments: grip - the grip widget that has been moved. - * junk - ** NOT USED ** - * call_data - data passed to us from the grip widget. - * Returns: none. +/* + * Function: + * HandleGrip + * + * Parameters: + * grip - grip widget that has been moved + * temp - (not used) + * call_data - data passed to us from the grip widget + * + * Description: + * Handles the grip manipulations. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -HandleGrip(grip, junk, callData) -Widget grip; -XtPointer junk, callData; +HandleGrip(Widget grip, XtPointer temp, XtPointer callData) { XawGripCallData call_data = (XawGripCallData)callData; PanedWidget pw = (PanedWidget) XtParent(grip); int loc; - char action_type; + char action_type[2], direction[2]; Cursor cursor; - Direction direction; Arg arglist[1]; - action_type = *call_data->params[0]; + if (call_data->num_params) + XmuNCopyISOLatin1Uppered(action_type, call_data->params[0], + sizeof(action_type)); - if (call_data->num_params == 0 || - (action_type == 'C' && call_data->num_params != 1) || - (action_type != 'C' && call_data->num_params != 2)) - XtError( "Paned GripAction has been passed incorrect parameters." ); + if (call_data->num_params == 0 + || (action_type[0] == 'C' && call_data->num_params != 1) + || (action_type[0] != 'C' && call_data->num_params != 2)) + XtAppError(XtWidgetToApplicationContext(grip), + "Paned GripAction has been passed incorrect parameters."); - if (islower(action_type)) action_type = toupper(action_type); + loc = GetEventLocation(pw, (XEvent *)call_data->event); - loc = GetEventLocation(pw, (XEvent *) (call_data->event)); - - if (action_type != 'C') { - if ( isupper(*call_data->params[1]) ) - direction = (Direction) *call_data->params[1]; - else - direction = (Direction) toupper(*call_data->params[1]); - } + if (action_type[0] != 'C') + XmuNCopyISOLatin1Uppered(direction, call_data->params[1], + sizeof(direction)); - switch (action_type) { + switch (action_type[0]) { case 'S': /* Start adjustment */ - pw->paned.resize_children_to_pref = FALSE; - StartGripAdjustment(pw, grip, direction); + pw->paned.resize_children_to_pref = False; + StartGripAdjustment(pw, grip, (Direction)direction[0]); pw->paned.start_loc = loc; break; - case 'M': - MoveGripAdjustment(pw, grip, direction, loc); + MoveGripAdjustment(pw, grip, (Direction)direction[0], loc); break; - case 'C': XtSetArg(arglist[0], XtNcursor, &cursor); - XtGetValues(grip, arglist, (Cardinal) 1); + XtGetValues(grip, arglist, 1); XDefineCursor(XtDisplay(grip), XtWindow(grip), cursor); CommitGripAdjustment(pw); break; - default: - XtError( "Paned GripAction(); 1st parameter invalid" ); + XtAppError(XtWidgetToApplicationContext(grip), + "Paned GripAction(); 1st parameter invalid"); + break; } } -/* Function Name: ResortChildren - * Description: Resorts the children so that all managed children - * are first. - * Arguments: pw - the paned widget. - * Returns: none. +/* + * Function: + * ResortChildren + * + * Arguments: + * pw - paned widget + * + * Description: + * Resorts the children so that all managed children are first. */ - static void -ResortChildren(pw) -PanedWidget pw; +ResortChildren(PanedWidget pw) { - Widget * unmanagedP, * childP; + Widget *unmanagedP, *childP; unmanagedP = NULL; ForAllChildren(pw, childP) { - if (!IsPane(*childP) || !XtIsManaged(*childP)) { - /* - * We only keep track of the first unmanaged pane. - */ - if (unmanagedP == NULL) - unmanagedP = childP; - } - else { /* must be a managed pane */ - /* - * If an earlier widget was not a managed pane, then swap - */ - if (unmanagedP != NULL) { - Widget child = *unmanagedP; - *unmanagedP = *childP; - *childP = child; - childP = unmanagedP; /* easiest to just back-track */ - unmanagedP = NULL; /* in case there is another managed */ + if (!IsPane(*childP) || !XtIsManaged(*childP)) { + /* + * We only keep track of the first unmanaged pane + */ + if (unmanagedP == NULL) + unmanagedP = childP; + } + else { /* must be a managed pane */ + /* + * If an earlier widget was not a managed pane, then swap + */ + if (unmanagedP != NULL) { + Widget child = *unmanagedP; + + *unmanagedP = *childP; + *childP = child; + childP = unmanagedP; /* easiest to just back-track */ + unmanagedP = NULL; /* in case there is another managed */ } } } } -/* Function Name: ManageAndUnmanageGrips - * Description: This function manages and unmanages the grips so that - * the managed state of each grip matches that of its pane. - * Arguments: pw - the paned widget. - * Returns: none. +/* + * Function: + * ManageAndUnmanageGrips + * + * Parameters: + * pw - paned widget + * + * Description: + * This function manages and unmanages the grips so that + * the managed state of each grip matches that of its pane. */ - static void -ManageAndUnmanageGrips(pw) -PanedWidget pw; +ManageAndUnmanageGrips(PanedWidget pw) { - WidgetList managed_grips, unmanaged_grips; - Widget *managedP, *unmanagedP, *childP; - Cardinal alloc_size; - - alloc_size = (Cardinal) sizeof(Widget) * pw->composite.num_children / 2; - managedP = managed_grips = (WidgetList) XtMalloc(alloc_size); - unmanagedP = unmanaged_grips = (WidgetList) XtMalloc(alloc_size); - - ForAllChildren(pw, childP) - if (IsPane(*childP) && HasGrip(*childP)) - if ( XtIsManaged(*childP) ) - *managedP++ = PaneInfo(*childP)->grip; - else - *unmanagedP++ = PaneInfo(*childP)->grip; + WidgetList managed_grips, unmanaged_grips; + Widget *managedP, *unmanagedP, *childP; + Cardinal alloc_size; + + alloc_size = sizeof(Widget) * (pw->composite.num_children >> 1); + managedP = managed_grips = (WidgetList)XtMalloc(alloc_size); + unmanagedP = unmanaged_grips = (WidgetList)XtMalloc(alloc_size); + + ForAllChildren(pw, childP) + if (IsPane(*childP) && HasGrip(*childP)) { + if (XtIsManaged(*childP)) + *managedP++ = PaneInfo(*childP)->grip; + else + *unmanagedP++ = PaneInfo(*childP)->grip; + } - if (managedP != managed_grips) { - *unmanagedP++ = *--managedP; /* Last grip is never managed */ - XtManageChildren( managed_grips, (Cardinal)(managedP - managed_grips) ); - } + if (managedP != managed_grips) { + *unmanagedP++ = *--managedP; /* Last grip is never managed */ + XtManageChildren(managed_grips, managedP - managed_grips); + } - if (unmanagedP != unmanaged_grips) - XtUnmanageChildren( unmanaged_grips, - (Cardinal)(unmanagedP - unmanaged_grips) ); + if (unmanagedP != unmanaged_grips) + XtUnmanageChildren(unmanaged_grips, unmanagedP - unmanaged_grips); - XtFree((char *)managed_grips); - XtFree((char *)unmanaged_grips); + XtFree((char *)managed_grips); + XtFree((char *)unmanaged_grips); } -/* Function Name: CreateGrip - * Description: Creates a grip widget. - * Arguments: child - the child that wants a grip to be created for it. - * Returns: none. +/* + * Function: + * CreateGrip + * + * Parameters: + * child - child that wants a grip to be created for it + * + * Description: + * Creates a grip widget. */ - static void -CreateGrip(child) -Widget child; +CreateGrip(Widget child) { - PanedWidget pw = (PanedWidget) XtParent(child); + PanedWidget pw = (PanedWidget)XtParent(child); Arg arglist[2]; Cardinal num_args = 0; Cursor cursor; XtSetArg(arglist[num_args], XtNtranslations, pw->paned.grip_translations); num_args++; - if ( (cursor = pw->paned.grip_cursor) == None ) - if (IsVert(pw)) + if ((cursor = pw->paned.grip_cursor) == None) { + if (IsVert(pw)) cursor = pw->paned.v_grip_cursor; else cursor = pw->paned.h_grip_cursor; + } XtSetArg(arglist[num_args], XtNcursor, cursor); num_args++; @@ -1203,43 +1351,41 @@ Widget child; arglist, num_args); XtAddCallback(PaneInfo(child)->grip, XtNcallback, - HandleGrip, (XtPointer) child); + HandleGrip, (XtPointer)child); } -/* Function Name: GetGCs - * Description: Gets new GC's. - * Arguments: w - the paned widget. - * Returns: none. +/* + * Function: + * GetGCs + * + * Parameters: + * w - paned widget */ - static void -GetGCs(w) -Widget w; +GetGCs(Widget w) { - PanedWidget pw = (PanedWidget) w; + PanedWidget pw = (PanedWidget)w; XtGCMask valuemask; XGCValues values; -/* - * Draw pane borders in internal border color. - */ - + /* + * Draw pane borders in internal border color + */ values.foreground = pw->paned.internal_bp; valuemask = GCForeground; pw->paned.normgc = XtGetGC(w, valuemask, &values); -/* - * Erase pane borders with background color. - */ - + /* + * Erase pane borders with background color + */ values.foreground = pw->core.background_pixel; valuemask = GCForeground; pw->paned.invgc = XtGetGC(w, valuemask, &values); -/* - * Draw Track lines (animate pane borders) in internal border color ^ bg color. - */ - + /* + * Draw Track lines (animate pane borders) in + * internal border color ^ bg color + */ values.function = GXinvert; values.plane_mask = pw->paned.internal_bp ^ pw->core.background_pixel; values.subwindow_mode = IncludeInferiors; @@ -1247,30 +1393,30 @@ Widget w; pw->paned.flipgc = XtGetGC(w, valuemask, &values); } -/* Function Name: SetChildrenPrefSizes. - * Description: Sets the preferred sizes of the children. - * Arguments: pw - the paned widget. - * Returns: none. +/* + * Function: + * SetChildrenPrefSizes + * + * Parameters: + * pw - paned widget + * + * Description: + * Sets the preferred sizes of the children. */ - static void -SetChildrenPrefSizes(pw, off_size) -PanedWidget pw; -Dimension off_size; +SetChildrenPrefSizes(PanedWidget pw, unsigned int off_size) { - Widget * childP; + Widget *childP; Boolean vert = IsVert(pw); XtWidgetGeometry request, reply; ForAllPanes(pw, childP) - if ( pw->paned.resize_children_to_pref || - (PaneInfo(*childP)->size == 0) || - (PaneInfo(*childP)->resize_to_pref) ) { - - if (PaneInfo(*childP)->preferred_size != PANED_ASK_CHILD) - PaneInfo(*childP)->wp_size=PaneInfo(*childP)->preferred_size; + if (pw->paned.resize_children_to_pref || PaneInfo(*childP)->size == 0 || + PaneInfo(*childP)->resize_to_pref) { + if (PaneInfo(*childP)->preferred_size != PANED_ASK_CHILD) + PaneInfo(*childP)->wp_size = PaneInfo(*childP)->preferred_size; else { - if( vert ) { + if(vert) { request.request_mode = CWWidth; request.width = off_size; } @@ -1279,154 +1425,156 @@ Dimension off_size; request.height = off_size; } - if ((XtQueryGeometry( *childP, &request, &reply ) - == XtGeometryAlmost) && - (reply.request_mode = (vert ? CWHeight : CWWidth))) + if ((XtQueryGeometry(*childP, &request, &reply) + == XtGeometryAlmost) + && (reply.request_mode = (vert ? CWHeight : CWWidth))) PaneInfo(*childP)->wp_size = GetRequestInfo(&reply, vert); else PaneInfo(*childP)->wp_size = PaneSize(*childP, vert); - } + } PaneInfo(*childP)->size = PaneInfo(*childP)->wp_size; - } + } } -/* Function Name: ChangeAllGripCursors - * Description: Changes all the grip cursors. - * Arguments: pw - the paned widget. - * Returns: none +/* + * Function: + * ChangeAllGripCursors + * + * Parameters: + * pw - paned widget + * + * Description: + * Changes all the grip cursors. */ - static void -ChangeAllGripCursors(pw) -PanedWidget pw; +ChangeAllGripCursors(PanedWidget pw) { - Widget * childP; + Widget *childP; ForAllPanes(pw, childP) { Arg arglist[1]; Cursor cursor; - if ( (cursor = pw->paned.grip_cursor) == None ) - if ( IsVert(pw) ) - cursor = pw->paned.v_grip_cursor; + if ((cursor = pw->paned.grip_cursor) == None) { + if (IsVert(pw)) + cursor = pw->paned.v_grip_cursor; else - cursor = pw->paned.h_grip_cursor; + cursor = pw->paned.h_grip_cursor; + } - if (HasGrip (*childP)) { + if (HasGrip(*childP)) { XtSetArg(arglist[0], XtNcursor, cursor); - XtSetValues(PaneInfo(*childP)->grip, arglist, (Cardinal) 1); + XtSetValues(PaneInfo(*childP)->grip, arglist, 1); } } } -/************************************************************ +/* + * Function: + * PushPaneStack * - * Stack Manipulation routines (Private). + * Parameters: + * pw - paned widget + * pane - pane that we are pushing * - ************************************************************/ - -/* Function Name: PushPaneStack - * Description: Pushes a value onto the pane stack. - * Arguments: pw - the paned widget. - * pane - the pane that we are pushing. - * Returns: none. + * Description: + * Pushes a value onto the pane stack. */ - static void -PushPaneStack(pw, pane) -PanedWidget pw; -Pane pane; +PushPaneStack(PanedWidget pw, Pane pane) { - PaneStack * stack = (PaneStack *) XtMalloc(sizeof(PaneStack)); + PaneStack *stack = (PaneStack *)XtMalloc(sizeof(PaneStack)); - stack->next = pw->paned.stack; - stack->pane = pane; - stack->start_size = pane->size; + stack->next = pw->paned.stack; + stack->pane = pane; + stack->start_size = pane->size; - pw->paned.stack = stack; + pw->paned.stack = stack; } -/* Function Name: GetPaneStack - * Description: Gets the top value from the pane stack. - * Arguments: pw - the paned widget. - * shrink - TRUE if we want to shrink this pane, - * FALSE otherwise. - * ** RETURNED ** pane - the pane that we are popping. - * ** RETURNED ** start_size - the size that this pane started at. - * Returns: none. +/* + * Function: + * GetPaneStack + * + * Parameters: + * pw - paned widget + * shrink - True if we want to shrink this pane, False otherwise + * pane - pane that we are popping (return) + * start_size - size that this pane started at (return) + * + * Description: + * Gets the top value from the pane stack. */ - static void -GetPaneStack(pw, shrink, pane, start_size) -PanedWidget pw; -Boolean shrink; -Pane * pane; -int * start_size; +GetPaneStack(PanedWidget pw, Bool shrink, Pane *pane, int *start_size) { - if (pw->paned.stack == NULL) { - *pane = NULL; - return; - } + if (pw->paned.stack == NULL) { + *pane = NULL; + return; + } - *pane = pw->paned.stack->pane; - *start_size = pw->paned.stack->start_size; + *pane = pw->paned.stack->pane; + *start_size = pw->paned.stack->start_size; - if (shrink != ((*pane)->size > *start_size)) *pane = NULL; + if (shrink != ((*pane)->size > *start_size)) + *pane = NULL; } -/* Function Name: PopPaneStack - * Description: Pops the top item off the pane stack. - * Arguments: pw - the paned widget. - * Returns: TRUE if this is not the last element on the stack. +/* + * Function: + * PopPaneStack + * + * Parameters: + * pw - paned widget + * + * Description: + * Pops the top item off the pane stack. + * + * Returns: True if this is not the last element on the stack */ - -static Boolean -PopPaneStack(pw) -PanedWidget pw; +static Bool +PopPaneStack(PanedWidget pw) { - PaneStack * stack = pw->paned.stack; + PaneStack *stack = pw->paned.stack; - if (stack == NULL) return(FALSE); + if (stack == NULL) + return (False); - pw->paned.stack = stack->next; - XtFree((char*)stack); + pw->paned.stack = stack->next; + XtFree((char *)stack); - if (pw->paned.stack == NULL) return(FALSE); - return(TRUE); -} - -/* Function Name: ClearPaneStack - * Description: removes all entries from the pane stack. - * Arguments: pw - the paned widget. - * Returns: none - */ + if (pw->paned.stack == NULL) + return (False); -static void -ClearPaneStack(pw) -PanedWidget pw; -{ - while(PopPaneStack(pw)); + return (True); } -/************************************************************ +/* + * Function: + * ClearPaneStack * - * Semi-public routines. + * Parameters: + * pw - paned widget * - ************************************************************/ - -/* Function Name: ClassInitialize - * Description: The Paned widgets class initialization proc. - * Arguments: none. - * Returns: none. + * Description: + * Removes all entries from the pane stack. */ +static void +ClearPaneStack(PanedWidget pw) +{ + while(PopPaneStack(pw)) + ; +} static void -ClassInitialize() +XawPanedClassInitialize(void) { XawInitializeWidgetSet(); - XtAddConverter( XtRString, XtROrientation, XmuCvtStringToOrientation, - (XtConvertArgList)NULL, (Cardinal)0 ); + XtAddConverter(XtRString, XtROrientation, XmuCvtStringToOrientation, + NULL, 0); + XtSetTypeConverter(XtROrientation, XtRString, XmuCvtOrientationToString, + NULL, 0, XtCacheNone, NULL); } /* The Geometry Manager only allows changes after Realize if @@ -1442,433 +1590,406 @@ ClassInitialize() * request will have no effect; i.e. when the requestor is already * of the desired geometry. */ - -static XtGeometryResult GeometryManager(w, request, reply) -Widget w; -XtWidgetGeometry *request, *reply; +static XtGeometryResult +XawPanedGeometryManager(Widget w, XtWidgetGeometry *request, + XtWidgetGeometry *reply) { - PanedWidget pw = (PanedWidget) XtParent(w); + PanedWidget pw = (PanedWidget)XtParent(w); XtGeometryMask mask = request->request_mode; Dimension old_size, old_wpsize, old_paned_size; Pane pane = PaneInfo(w); Boolean vert = IsVert(pw); Dimension on_size, off_size; XtGeometryResult result; - Boolean almost = FALSE; - -/* - * If any of the following is true, disallow the geometry change. - * - * o The paned widget is realized and allow_resize is false for the pane. - * o The child did not ask to change the on_size. - * o The request is not a width or height request. - * o The requested size is the same as the current size. - */ - - if ( (XtIsRealized((Widget)pw) && !pane->allow_resize) || - !(mask & ((vert) ? CWHeight : CWWidth)) || - (mask & ~(CWWidth | CWHeight)) || - (GetRequestInfo(request, vert) == PaneSize(w, vert)) ) { - return XtGeometryNo; - } - - old_paned_size = PaneSize( (Widget) pw, vert); + Boolean almost = False; + + /* + * If any of the following is true, disallow the geometry change + * + * o The paned widget is realized and allow_resize is false for the pane + * o The child did not ask to change the on_size + * o The request is not a width or height request + * o The requested size is the same as the current size + */ + + if ((XtIsRealized((Widget)pw) && !pane->allow_resize) + || !(mask & (vert ? CWHeight : CWWidth)) + ||(mask & ~(CWWidth | CWHeight)) + || GetRequestInfo(request, vert) == PaneSize(w, vert)) + return (XtGeometryNo); + + old_paned_size = PaneSize((Widget)pw, vert); old_wpsize = pane->wp_size; old_size = pane->size; pane->wp_size = pane->size = GetRequestInfo(request, vert); - AdjustPanedSize(pw, PaneSize((Widget) pw, !vert), &result, &on_size, + AdjustPanedSize(pw, PaneSize((Widget)pw, !vert), &result, &on_size, &off_size); -/* - * Fool the Refigure Locations proc to thinking that we are - * a different on_size; - */ + /* + * Fool the Refigure Locations proc to thinking that we are + * a different on_size + */ - if (result != XtGeometryNo) + if (result != XtGeometryNo) { if (vert) - pw->core.height = on_size; + XtHeight(pw) = on_size; else - pw->core.width = on_size; - + XtWidth(pw) = on_size; + } + RefigureLocations(pw, PaneIndex(w), AnyPane); -/* - * Set up reply struct and reset core on_size. - */ - + /* + * Set up reply struct and reset core on_size + */ if (vert) { - pw->core.height = old_paned_size; - reply->height = pane->size; + XtHeight(pw) = old_paned_size; + reply->height = pane->size; reply->width = off_size; } else { - pw->core.width = old_paned_size; - reply->height = off_size; + XtWidth(pw) = old_paned_size; + reply->height = off_size; reply->width = pane->size; } -/* - * IF either of the following is true. - * - * o There was a "off_size" request and the new "off_size" is different - * from that requested. - * o There was no "off_size" request and the new "off_size" is different - * - * o The "on_size" we will allow is different from that requested. - * - * THEN: set almost - */ - - if ( !((vert ? CWWidth : CWHeight) & mask)) - if (vert) - request->width = w->core.width; + /* + * IF either of the following is true + * + * o There was a "off_size" request and the new "off_size" is different + * from that requested + * o There was no "off_size" request and the new "off_size" is different + * + * o The "on_size" we will allow is different from that requested + * + * THEN: set almost + */ + if (!((vert ? CWWidth : CWHeight) & mask)) { + if (vert) + request->width = XtWidth(w); else - request->height = w->core.height; + request->height = XtHeight(w); + } almost = GetRequestInfo(request, !vert) != GetRequestInfo(reply, !vert); almost |= (GetRequestInfo(request, vert) != GetRequestInfo(reply, vert)); - if ( (mask & XtCWQueryOnly) || almost ) { + if ((mask & XtCWQueryOnly) || almost) { pane->wp_size = old_wpsize; pane->size = old_size; RefigureLocations(pw, PaneIndex(w), AnyPane); reply->request_mode = CWWidth | CWHeight; - if (almost) return XtGeometryAlmost; + if (almost) + return (XtGeometryAlmost); } else { - AdjustPanedSize(pw, PaneSize((Widget) pw, !vert), - (XtGeometryResult *)NULL, - (Dimension *)NULL, (Dimension *)NULL); - CommitNewLocations( pw ); /* layout already refigured. */ + AdjustPanedSize(pw, PaneSize((Widget) pw, !vert), NULL, NULL, NULL); + CommitNewLocations(pw); /* layout already refigured */ } - return XtGeometryDone; + + return (XtGeometryDone); } -/* ARGSUSED */ -static void Initialize(request, new, args, num_args) -Widget request, new; -ArgList args; -Cardinal *num_args; +/*ARGSUSED*/ +static void +XawPanedInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - PanedWidget pw = (PanedWidget)new; + PanedWidget pw = (PanedWidget)cnew; - GetGCs( (Widget) pw); + GetGCs((Widget)pw); pw->paned.recursively_called = False; pw->paned.stack = NULL; - pw->paned.resize_children_to_pref = TRUE; + pw->paned.resize_children_to_pref = True; pw->paned.num_panes = 0; } static void -Realize(w, valueMask, attributes) -Widget w; -Mask *valueMask; -XSetWindowAttributes *attributes; +XawPanedRealize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes) { - PanedWidget pw = (PanedWidget) w; - Widget * childP; + PanedWidget pw = (PanedWidget)w; + Widget *childP; - if ((attributes->cursor = (pw)->paned.cursor) != None) + if ((attributes->cursor = pw->paned.cursor) != None) *valueMask |= CWCursor; - (*SuperClass->core_class.realize) (w, valueMask, attributes); - -/* - * Before we commit the new locations we need to realize all the panes and - * their grips. - */ + (*SuperClass->core_class.realize)(w, valueMask, attributes); + /* + * Before we commit the new locations we need to realize all the panes and + * their grips + */ ForAllPanes(pw, childP) { - XtRealizeWidget( *childP ); - if (HasGrip (*childP)) - XtRealizeWidget( PaneInfo(*childP)->grip ); + XtRealizeWidget(*childP); + if (HasGrip(*childP)) + XtRealizeWidget(PaneInfo(*childP)->grip); } RefigureLocationsAndCommit(w); - pw->paned.resize_children_to_pref = FALSE; -} /* Realize */ + pw->paned.resize_children_to_pref = False; +} static void -ReleaseGCs(w) -Widget w; +XawPanedDestroy(Widget w) +{ + ReleaseGCs(w); +} + +static void +ReleaseGCs(Widget w) { PanedWidget pw = (PanedWidget)w; - XtReleaseGC( w, pw->paned.normgc ); - XtReleaseGC( w, pw->paned.invgc ); - XtReleaseGC( w, pw->paned.flipgc ); + XtReleaseGC(w, pw->paned.normgc); + XtReleaseGC(w, pw->paned.invgc); + XtReleaseGC(w, pw->paned.flipgc); } -static void InsertChild(w) -Widget w; +static void +XawPanedInsertChild(Widget w) { - Pane pane = PaneInfo(w); - - /* insert the child widget in the composite children list with the */ - /* superclass insert_child routine. */ - (*SuperClass->composite_class.insert_child)(w); - - if (!IsPane(w)) return; + Pane pane = PaneInfo(w); - /* ||| Panes will be added in the order they are created, temporarily */ + /* insert the child widget in the composite children list with the + superclass insert_child routine + */ + (*SuperClass->composite_class.insert_child)(w); - if ( pane->show_grip == TRUE ) { - CreateGrip(w); - if (pane->min == PANED_GRIP_SIZE) - pane->min = PaneSize(pane->grip, IsVert((PanedWidget) XtParent(w))); - } - else { - if (pane->min == PANED_GRIP_SIZE) - pane->min = 1; - pane->grip = NULL; - } + if (!IsPane(w)) + return; - pane->size = 0; - pane->paned_adjusted_me = FALSE; + if (pane->show_grip == True) { + CreateGrip(w); + if (pane->min == PANED_GRIP_SIZE) + pane->min = PaneSize(pane->grip, IsVert((PanedWidget)XtParent(w))); + } + else { + if (pane->min == PANED_GRIP_SIZE) + pane->min = 1; + pane->grip = NULL; + } -} /* InsertChild */ + pane->size = 0; + pane->paned_adjusted_me = False; +} -static void DeleteChild(w) -Widget w; +static void +XawPanedDeleteChild(Widget w) { /* remove the subwidget info and destroy the grip */ + if (IsPane(w) && HasGrip(w)) + XtDestroyWidget(PaneInfo(w)->grip); - if ( IsPane(w) && HasGrip(w) ) XtDestroyWidget(PaneInfo(w)->grip); - - /* delete the child widget in the composite children list with the */ - /* superclass delete_child routine. */ - (*SuperClass->composite_class.delete_child) (w); - -} /* DeleteChild */ + /* delete the child widget in the composite children list with the + superclass delete_child routine + */ + (*SuperClass->composite_class.delete_child)(w); +} -static void ChangeManaged(w) - Widget w; +static void +XawPanedChangeManaged(Widget w) { - PanedWidget pw = (PanedWidget)w; - Boolean vert = IsVert(pw); - Dimension size; - Widget *childP; - - if (pw->paned.recursively_called++) return; - -/* - * If the size is zero then set it to the size of the widest or tallest pane. - */ + PanedWidget pw = (PanedWidget)w; + Boolean vert = IsVert(pw); + Dimension size; + Widget *childP; - if ( (size = PaneSize( (Widget) pw, !vert )) == 0) { - size = 1; - ForAllChildren(pw, childP) - if ( XtIsManaged(*childP) && (PaneSize( *childP, !vert ) > size) ) - size = PaneSize( *childP, !vert ); - } + if (pw->paned.recursively_called++) + return; - ManageAndUnmanageGrips(pw); - pw->paned.recursively_called = False; - ResortChildren(pw); - - pw->paned.num_panes = 0; - ForAllChildren(pw, childP) - if ( IsPane(*childP) ) - if ( XtIsManaged(*childP) ) { - Pane pane = PaneInfo(*childP); - if (HasGrip(*childP)) - PaneInfo(pane->grip)->position = pw->paned.num_panes; - pane->position = pw->paned.num_panes; /*TEMPORY -CDP 3/89 */ - pw->paned.num_panes++; - } - else - break; /* This list is already sorted. */ + /* + * If the size is zero then set it to the size of the widest or tallest pane + */ - SetChildrenPrefSizes( (PanedWidget) w, size); + if ((size = PaneSize((Widget)pw, !vert)) == 0) { + size = 1; + ForAllChildren(pw, childP) + if (XtIsManaged(*childP) && (PaneSize(*childP, !vert) > size)) + size = PaneSize(*childP, !vert); + } -/* - * ForAllPanes can now be used. - */ + ManageAndUnmanageGrips(pw); + pw->paned.recursively_called = False; + ResortChildren(pw); - if ( PaneSize((Widget) pw, vert) == 0 ) - AdjustPanedSize(pw, size, (XtGeometryResult *)NULL, - (Dimension *)NULL, (Dimension *)NULL); + pw->paned.num_panes = 0; + ForAllChildren(pw, childP) + if (IsPane(*childP)) { + if (XtIsManaged(*childP)) { + Pane pane = PaneInfo(*childP); + + if (HasGrip(*childP)) + PaneInfo(pane->grip)->position = pw->paned.num_panes; + pane->position = pw->paned.num_panes; /* TEMPORY -CDP 3/89 */ + pw->paned.num_panes++; + } + else + break; /* This list is already sorted */ + } - if (XtIsRealized( (Widget) pw)) - RefigureLocationsAndCommit( (Widget) pw); + SetChildrenPrefSizes((PanedWidget) w, size); -} /* ChangeManaged */ + /* + * ForAllPanes can now be used + */ + if (PaneSize((Widget) pw, vert) == 0) + AdjustPanedSize(pw, size, NULL, NULL, NULL); -/* Function Name: Resize - * Description: The paned widget's resize proc. - * Arguments: w - the paned widget. - * Returns: none. - */ + if (XtIsRealized((Widget)pw)) + RefigureLocationsAndCommit((Widget)pw); +} static void -Resize(w) -Widget w; +XawPanedResize(Widget w) { - SetChildrenPrefSizes( (PanedWidget) w, - PaneSize(w, !IsVert((PanedWidget) w)) ); + SetChildrenPrefSizes((PanedWidget)w, + PaneSize(w, !IsVert((PanedWidget)w))); RefigureLocationsAndCommit(w); } -/* ARGSUSED */ +/*ARGSUSED*/ static void -Redisplay(w, event, region) -Widget w; -XEvent * event; /* unused. */ -Region region; /* unused. */ +XawPanedRedisplay(Widget w, XEvent *event, Region region) { - DrawInternalBorders( (PanedWidget) w); + DrawInternalBorders((PanedWidget)w); } -/* ARGSUSED */ +/*ARGSUSED*/ static Boolean -SetValues(old, request, new, args, num_args) -Widget old, request, new; -ArgList args; -Cardinal *num_args; +XawPanedSetValues(Widget old, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - PanedWidget old_pw = (PanedWidget) old; - PanedWidget new_pw = (PanedWidget) new; - Boolean redisplay = FALSE; - - if ( (old_pw->paned.cursor != new_pw->paned.cursor) && XtIsRealized(new)) - XDefineCursor(XtDisplay(new), XtWindow(new), new_pw->paned.cursor); - - if ( (old_pw->paned.internal_bp != new_pw->paned.internal_bp) || - (old_pw->core.background_pixel != new_pw->core.background_pixel) ) { - ReleaseGCs(old); - GetGCs(new); - redisplay = TRUE; + PanedWidget old_pw = (PanedWidget)old; + PanedWidget new_pw = (PanedWidget)cnew; + Boolean redisplay = False; + + if ((old_pw->paned.cursor != new_pw->paned.cursor) && XtIsRealized(cnew)) + XDefineCursor(XtDisplay(cnew), XtWindow(cnew), new_pw->paned.cursor); + + if (old_pw->paned.internal_bp != new_pw->paned.internal_bp || + old_pw->core.background_pixel != new_pw->core.background_pixel) { + ReleaseGCs(old); + GetGCs(cnew); + redisplay = True; } - if ( (old_pw->paned.grip_cursor != new_pw->paned.grip_cursor) || - (old_pw->paned.v_grip_cursor != new_pw->paned.v_grip_cursor) || - (old_pw->paned.h_grip_cursor != new_pw->paned.h_grip_cursor) ) { - ChangeAllGripCursors(new_pw); - } + if (old_pw->paned.grip_cursor != new_pw->paned.grip_cursor || + old_pw->paned.v_grip_cursor != new_pw->paned.v_grip_cursor || + old_pw->paned.h_grip_cursor != new_pw->paned.h_grip_cursor) + ChangeAllGripCursors(new_pw); - if ( IsVert(old_pw) != IsVert(new_pw)) { -/* - * We are fooling the paned widget into thinking that is needs to - * fully refigure everything, which is what we want. - */ - if (IsVert(new_pw)) - new_pw->core.width = 0; + if (IsVert(old_pw) != IsVert(new_pw)) { + /* + * We are fooling the paned widget into thinking that is needs to + * fully refigure everything, which is what we want + */ + if (IsVert(new_pw)) + XtWidth(new_pw) = 0; else - new_pw->core.height = 0; + XtHeight(new_pw) = 0; - new_pw->paned.resize_children_to_pref = TRUE; - ChangeManaged(new); /* Seems weird, but does the right thing. */ - new_pw->paned.resize_children_to_pref = FALSE; + new_pw->paned.resize_children_to_pref = True; + XawPanedChangeManaged(cnew); /* Seems weird, but does the right thing */ + new_pw->paned.resize_children_to_pref = False; if (new_pw->paned.grip_cursor == None) ChangeAllGripCursors(new_pw); - return(TRUE); + return (True); } if (old_pw->paned.internal_bw != new_pw->paned.internal_bw) { - AdjustPanedSize( new_pw, PaneSize(new, !IsVert(old_pw)), - (XtGeometryResult *)NULL, - (Dimension *)NULL, (Dimension *)NULL); - RefigureLocationsAndCommit(new); - return(TRUE); /* We have done a full configuration, return.*/ + AdjustPanedSize(new_pw, PaneSize(cnew, !IsVert(old_pw)), + NULL, NULL, NULL); + RefigureLocationsAndCommit(cnew); + return (True); /* We have done a full configuration, return */ } - if ( (old_pw->paned.grip_indent != new_pw->paned.grip_indent) && - (XtIsRealized(new)) ) { - CommitNewLocations(new_pw); - redisplay = TRUE; + if (old_pw->paned.grip_indent != new_pw->paned.grip_indent && + XtIsRealized(cnew)) { + CommitNewLocations(new_pw); + redisplay = True; } return (redisplay); -} /* SetValues */ - +} -/* ARGSUSED */ +/*ARGSUSED*/ static Boolean -PaneSetValues(old, request, new, args, num_args) -Widget old, request, new; -ArgList args; -Cardinal *num_args; +XawPanedPaneSetValues(Widget old, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { Pane old_pane = PaneInfo(old); - Pane new_pane = PaneInfo(new); - Boolean redisplay = FALSE; - - /* Check for new min and max. */ + Pane new_pane = PaneInfo(cnew); + Boolean redisplay = False; + /* Check for new min and max */ if (old_pane->min != new_pane->min || old_pane->max != new_pane->max) - XawPanedSetMinMax(new, (int)new_pane->min, (int)new_pane->max); - - /* Check for change in XtNshowGrip. */ - - if (old_pane->show_grip != new_pane->show_grip) - if (new_pane->show_grip == TRUE) { - CreateGrip(new); - if (XtIsRealized(XtParent(new))) { - if (XtIsManaged(new)) /* if paned is unrealized this will - happen automatically at realize time.*/ - XtManageChild(PaneInfo(new)->grip); /* manage the grip. */ - XtRealizeWidget(PaneInfo(new)->grip); /* realize the grip. */ - CommitNewLocations( (PanedWidget) XtParent(new) ); + XawPanedSetMinMax(cnew, (int)new_pane->min, (int)new_pane->max); + + /* Check for change in XtNshowGrip */ + if (old_pane->show_grip != new_pane->show_grip) { + if (new_pane->show_grip == True) { + CreateGrip(cnew); + if (XtIsRealized(XtParent(cnew))) { + if (XtIsManaged(cnew)) /* if paned is unrealized this will + happen automatically at realize time + */ + XtManageChild(PaneInfo(cnew)->grip); /* manage the grip */ + XtRealizeWidget(PaneInfo(cnew)->grip); /* realize the grip */ + CommitNewLocations((PanedWidget)XtParent(cnew)); } } - else if ( HasGrip(old) ) { - XtDestroyWidget( old_pane->grip ); + else if (HasGrip(old)) { + XtDestroyWidget(old_pane->grip); new_pane->grip = NULL; - redisplay = TRUE; + redisplay = True; } + } - /* ||| need to look at position changes */ - - return(redisplay); + return (redisplay); } -/************************************************************ +/* + * Public routines + */ +/* + * Function: + * XawPanedSetMinMax * - * Public routines. + * Parameters: + * widget - widget that is a child of the Paned widget + * min - new min and max size for the pane + * max - "" * - ************************************************************/ - -/* Function Name: XawPanedSetMinMax - * Description: Sets the min and max size for a pane. - * Arguments: widget - the widget that is a child of the Paned widget. - * min, max - the new min and max size for the pane. - * Returns: none. + * Description: + * Sets the min and max size for a pane. */ - void -#if NeedFunctionPrototypes XawPanedSetMinMax(Widget widget, int min, int max) -#else -XawPanedSetMinMax(widget, min, max) -Widget widget; -int min, max; -#endif { Pane pane = PaneInfo(widget); pane->min = min; pane->max = max; - RefigureLocationsAndCommit( widget->core.parent ); + RefigureLocationsAndCommit(widget->core.parent); } -/* Function Name: XawPanedGetMinMax - * Description: Gets the min and max size for a pane. - * Arguments: widget - the widget that is a child of the Paned widget. - ** RETURNED ** min, max - the current min and max size for the pane. - * Returns: none. +/* + * Function: + * XawPanedGetMinMax + * + * Parameters: + * widget - widget that is a child of the Paned widget + * min - current min and max size for the pane (return) + * max - "" + * + * Description: + * Gets the min and max size for a pane. */ - void -#if NeedFunctionPrototypes XawPanedGetMinMax(Widget widget, int *min, int *max) -#else -XawPanedGetMinMax(widget, min, max) -Widget widget; -int *min, *max; -#endif { Pane pane = PaneInfo(widget); @@ -1876,69 +1997,68 @@ int *min, *max; *max = pane->max; } -/* Function Name: XawPanedSetRefigureMode - * Description: Allows a flag to be set the will inhibit - * the paned widgets relayout routine. - * Arguments: w - the paned widget. - * mode - if FALSE then inhibit refigure. - * Returns: none. +/* + * Function: + * XawPanedSetRefigureMode + * + * Parameters: + * w - paned widget + * mode - if False then inhibit refigure + * + * Description: + * Allows a flag to be set the will inhibit + * the paned widgets relayout routine. */ - void -#if NeedFunctionPrototypes XawPanedSetRefigureMode(Widget w, #if NeedWidePrototypes - int mode) -#else - Boolean mode) -#endif + int mode #else -XawPanedSetRefigureMode(w, mode) -Widget w; -Boolean mode; + Boolean mode #endif +) { - ((PanedWidget) w)->paned.refiguremode = mode; - RefigureLocationsAndCommit( w ); + ((PanedWidget)w)->paned.refiguremode = mode; + RefigureLocationsAndCommit(w); } -/* Function Name: XawPanedGetNumSub - * Description: Returns the number of panes in the paned widget. - * Arguments: w - the paned widget. - * Returns: the number of panes in the paned widget. +/* + * Function: + * XawPanedGetNumSub + * + * Parameters: + * w - paned widget + * + * Description: + * Returns the number of panes in the paned widget. + * Returns: + * the number of panes in the paned widget */ - int -#if NeedFunctionPrototypes XawPanedGetNumSub(Widget w) -#else -XawPanedGetNumSub(w) -Widget w; -#endif { - return ((PanedWidget)w)->paned.num_panes; + return (((PanedWidget)w)->paned.num_panes); } -/* Function Name: XawPanedAllowResize - * Description: Allows a flag to be set that determines if the paned - * widget will allow geometry requests from this child - * Arguments: widget - a child of the paned widget. - * Returns: none. +/* + * Function: + * XawPanedAllowResize + * + * Parameters: + * widget - child of the paned widget + * + * Description: + * Allows a flag to be set that determines if the paned + * widget will allow geometry requests from this child. */ - void -#if NeedFunctionPrototypes XawPanedAllowResize(Widget widget, #if NeedWidePrototypes - int allow_resize) -#else - Boolean allow_resize) -#endif + int allow_resize #else -XawPanedAllowResize(widget, allow_resize) -Widget widget; -Boolean allow_resize; + Boolean allow_resize #endif +) { PaneInfo(widget)->allow_resize = allow_resize; } diff --git a/src/Panner.c b/src/Panner.c index 47f1886..d388e06 100644 --- a/src/Panner.c +++ b/src/Panner.c @@ -26,184 +26,335 @@ in this Software without prior written authorization from The Open Group. * Author: Jim Fulton, MIT X Consortium */ +/* $XFree86: xc/lib/Xaw/Panner.c,v 3.9 2001/12/14 19:54:41 dawes Exp $ */ + +#include <ctype.h> +#include <math.h> #include <X11/IntrinsicP.h> -#include <X11/StringDefs.h> /* for XtN and XtC defines */ -#include <X11/Xmu/CharSet.h> /* for XmuCompareISOLatin1() */ -#include <X11/Xaw/XawInit.h> /* for XawInitializeWidgetSet */ -#include <X11/Xaw/PannerP.h> /* us */ +#include <X11/StringDefs.h> #include <X11/Xos.h> -#include <X11/Xmu/Misc.h> /* for Min */ +#include <X11/Xmu/CharSet.h> #include <X11/Xmu/Drawing.h> -#include <ctype.h> /* for isascii() etc. */ -#include <math.h> /* for atof() */ - -extern Bool XmuDistinguishablePixels(); /* not defined in any Xmu headers */ +#include <X11/Xmu/Misc.h> +#include <X11/Xaw/PannerP.h> +#include <X11/Xaw/XawInit.h> +#include "Private.h" #if defined(ISC) && __STDC__ && !defined(ISC30) extern double atof(char *); +#else +#include <stdlib.h> /* for atof() */ #endif -static char defaultTranslations[] = - "<Btn1Down>: start() \n\ - <Btn1Motion>: move() \n\ - <Btn1Up>: notify() stop() \n\ - <Btn2Down>: abort() \n\ - :<Key>KP_Enter: set(rubberband,toggle) \n\ - <Key>space: page(+1p,+1p) \n\ - <Key>Delete: page(-1p,-1p) \n\ - :<Key>KP_Delete: page(-1p,-1p) \n\ - <Key>BackSpace: page(-1p,-1p) \n\ - <Key>Left: page(-.5p,+0) \n\ - :<Key>KP_Left: page(-.5p,+0) \n\ - <Key>Right: page(+.5p,+0) \n\ - :<Key>KP_Right: page(+.5p,+0) \n\ - <Key>Up: page(+0,-.5p) \n\ - :<Key>KP_Up: page(+0,-.5p) \n\ - <Key>Down: page(+0,+.5p) \n\ - :<Key>KP_Down: page(+0,+.5p) \n\ - <Key>Home: page(0,0) \n\ - :<Key>KP_Home: page(0,0)"; - - -static void ActionStart(), ActionStop(), ActionAbort(), ActionMove(); -static void ActionPage(), ActionNotify(), ActionSet(); - -static XtActionsRec actions[] = { - { "start", ActionStart }, /* start tmp graphics */ - { "stop", ActionStop }, /* stop tmp graphics */ - { "abort", ActionAbort }, /* punt */ - { "move", ActionMove }, /* move tmp graphics on Motion event */ - { "page", ActionPage }, /* page around usually from keyboard */ - { "notify", ActionNotify }, /* callback new position */ - { "set", ActionSet }, /* set various parameters */ -}; +/* + * Class Methods + */ +static void XawPannerDestroy(Widget); +static void XawPannerInitialize(Widget, Widget, ArgList, Cardinal*); +static XtGeometryResult XawPannerQueryGeometry(Widget, XtWidgetGeometry*, + XtWidgetGeometry*); +static void XawPannerRealize(Widget, XtValueMask*, XSetWindowAttributes*); +static void XawPannerRedisplay(Widget, XEvent*, Region); +static void XawPannerResize(Widget); +static Boolean XawPannerSetValues(Widget, Widget, Widget, ArgList, Cardinal*); +static void XawPannerSetValuesAlmost(Widget, Widget, XtWidgetGeometry*, + XtWidgetGeometry*); +/* + * Prototypes + */ +static void check_knob(PannerWidget, Bool); +static void get_default_size(PannerWidget, Dimension*, Dimension*); +static Bool get_event_xy(PannerWidget, XEvent*, int*, int*); +static void move_shadow(PannerWidget); +static int parse_page_string(char*, int, int, Bool*); +static void rescale(PannerWidget); +static void reset_shadow_gc(PannerWidget); +static void reset_slider_gc(PannerWidget); +static void reset_xor_gc(PannerWidget); +static void scale_knob(PannerWidget, Bool, Bool); /* - * resources for the panner + * Actions */ -static XtResource resources[] = { -#define poff(field) XtOffsetOf(PannerRec, panner.field) - { XtNallowOff, XtCAllowOff, XtRBoolean, sizeof(Boolean), - poff(allow_off), XtRImmediate, (XtPointer) FALSE }, - { XtNresize, XtCResize, XtRBoolean, sizeof(Boolean), - poff(resize_to_pref), XtRImmediate, (XtPointer) TRUE }, - { XtNreportCallback, XtCReportCallback, XtRCallback, sizeof(XtPointer), - poff(report_callbacks), XtRCallback, (XtPointer) NULL }, - { XtNdefaultScale, XtCDefaultScale, XtRDimension, sizeof(Dimension), - poff(default_scale), XtRImmediate, (XtPointer) PANNER_DEFAULT_SCALE }, - { XtNrubberBand, XtCRubberBand, XtRBoolean, sizeof(Boolean), - poff(rubber_band), XtRImmediate, (XtPointer) FALSE }, - { XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), - poff(foreground), XtRString, (XtPointer) XtDefaultBackground }, - { XtNinternalSpace, XtCInternalSpace, XtRDimension, sizeof(Dimension), - poff(internal_border), XtRImmediate, (XtPointer) 4 }, - { XtNlineWidth, XtCLineWidth, XtRDimension, sizeof(Dimension), - poff(line_width), XtRImmediate, (XtPointer) 0 }, - { XtNcanvasWidth, XtCCanvasWidth, XtRDimension, sizeof(Dimension), - poff(canvas_width), XtRImmediate, (XtPointer) 0 }, - { XtNcanvasHeight, XtCCanvasHeight, XtRDimension, sizeof(Dimension), - poff(canvas_height), XtRImmediate, (XtPointer) 0 }, - { XtNsliderX, XtCSliderX, XtRPosition, sizeof(Position), - poff(slider_x), XtRImmediate, (XtPointer) 0 }, - { XtNsliderY, XtCSliderY, XtRPosition, sizeof(Position), - poff(slider_y), XtRImmediate, (XtPointer) 0 }, - { XtNsliderWidth, XtCSliderWidth, XtRDimension, sizeof(Dimension), - poff(slider_width), XtRImmediate, (XtPointer) 0 }, - { XtNsliderHeight, XtCSliderHeight, XtRDimension, sizeof(Dimension), - poff(slider_height), XtRImmediate, (XtPointer) 0 }, - { XtNshadowColor, XtCShadowColor, XtRPixel, sizeof(Pixel), - poff(shadow_color), XtRString, (XtPointer) XtDefaultForeground }, - { XtNshadowThickness, XtCShadowThickness, XtRDimension, sizeof(Dimension), - poff(shadow_thickness), XtRImmediate, (XtPointer) 2 }, - { XtNbackgroundStipple, XtCBackgroundStipple, XtRString, sizeof(String), - poff(stipple_name), XtRImmediate, (XtPointer) NULL }, -#undef poff -}; +static void ActionAbort(Widget, XEvent*, String*, Cardinal*); +static void ActionMove(Widget, XEvent*, String*, Cardinal*); +static void ActionNotify(Widget, XEvent*, String*, Cardinal*); +static void ActionPage(Widget, XEvent*, String*, Cardinal*); +static void ActionSet(Widget, XEvent*, String*, Cardinal*); +static void ActionStart(Widget, XEvent*, String*, Cardinal*); +static void ActionStop(Widget, XEvent*, String*, Cardinal*); +/* + * From Xmu/Distinct.c + */ +Bool XmuDistinguishablePixels(Display*, Colormap, unsigned long*, int); /* - * widget class methods used below + * Initialization */ -static void Initialize(); /* create gc's */ -static void Realize(); /* create window */ -static void Destroy(); /* clean up widget */ -static void Resize(); /* need to rescale ourselves */ -static void Redisplay(); /* draw ourselves */ -static Boolean SetValues(); /* set all of the resources */ -static void SetValuesAlmost(); /* deal with failed setval geom req */ -static XtGeometryResult QueryGeometry(); /* say how big we would like to be */ +static char defaultTranslations[] = +"<Btn1Down>:" "start()\n" +"<Btn1Motion>:" "move()\n" +"<Btn1Up>:" "notify() stop()\n" +"<Btn2Down>:" "abort()\n" +":<Key>KP_Enter:" "set(rubberband,toggle)\n" +"<Key>space:" "page(+1p,+1p)\n" +"<Key>Delete:" "page(-1p,-1p)\n" +":<Key>KP_Delete:" "page(-1p,-1p)\n" +"<Key>BackSpace:" "page(-1p,-1p)\n" +"<Key>Left:" "page(-.5p,+0)\n" +":<Key>KP_Left:" "page(-.5p,+0)\n" +"<Key>Right:" "page(+.5p,+0)\n" +":<Key>KP_Right:" "page(+.5p,+0)\n" +"<Key>Up:" "page(+0,-.5p)\n" +":<Key>KP_Up:" "page(+0,-.5p)\n" +"<Key>Down:" "page(+0,+.5p)\n" +":<Key>KP_Down:" "page(+0,+.5p)\n" +"<Key>Home:" "page(0,0)\n" +":<Key>KP_Home:" "page(0,0)\n" +; + +static XtActionsRec actions[] = { + {"start", ActionStart}, /* start tmp graphics */ + {"stop", ActionStop}, /* stop tmp graphics */ + {"abort", ActionAbort}, /* punt */ + {"move", ActionMove}, /* move tmp graphics on Motion event */ + {"page", ActionPage}, /* page around usually from keyboard */ + {"notify", ActionNotify}, /* callback new position */ + {"set", ActionSet}, /* set various parameters */ +}; + +#define offset(field) XtOffsetOf(PannerRec, panner.field) +static XtResource resources[] = { + { + XtNallowOff, + XtCAllowOff, + XtRBoolean, + sizeof(Boolean), + offset(allow_off), + XtRImmediate, + (XtPointer)False + }, + { + XtNresize, + XtCResize, + XtRBoolean, + sizeof(Boolean), + offset(resize_to_pref), + XtRImmediate, + (XtPointer)True + }, + { + XtNreportCallback, + XtCReportCallback, + XtRCallback, + sizeof(XtPointer), + offset(report_callbacks), + XtRCallback, + NULL + }, + { + XtNdefaultScale, + XtCDefaultScale, + XtRDimension, + sizeof(Dimension), + offset(default_scale), + XtRImmediate, + (XtPointer)PANNER_DEFAULT_SCALE + }, + { + XtNrubberBand, + XtCRubberBand, + XtRBoolean, + sizeof(Boolean), + offset(rubber_band), + XtRImmediate, + (XtPointer)False + }, + { + XtNforeground, + XtCForeground, + XtRPixel, + sizeof(Pixel), + offset(foreground), + XtRString, + (XtPointer)XtDefaultBackground + }, + { + XtNinternalSpace, + XtCInternalSpace, + XtRDimension, + sizeof(Dimension), + offset(internal_border), + XtRImmediate, + (XtPointer)4 + }, + { + XtNlineWidth, + XtCLineWidth, + XtRDimension, + sizeof(Dimension), + offset(line_width), + XtRImmediate, + (XtPointer)0 + }, + { + XtNcanvasWidth, + XtCCanvasWidth, + XtRDimension, + sizeof(Dimension), + offset(canvas_width), + XtRImmediate, + (XtPointer)0 + }, + { + XtNcanvasHeight, + XtCCanvasHeight, + XtRDimension, + sizeof(Dimension), + offset(canvas_height), + XtRImmediate, + (XtPointer)0 + }, + { + XtNsliderX, + XtCSliderX, + XtRPosition, + sizeof(Position), + offset(slider_x), + XtRImmediate, + (XtPointer)0 + }, + { + XtNsliderY, + XtCSliderY, + XtRPosition, + sizeof(Position), + offset(slider_y), + XtRImmediate, + (XtPointer)0 + }, + { + XtNsliderWidth, + XtCSliderWidth, + XtRDimension, + sizeof(Dimension), + offset(slider_width), + XtRImmediate, + (XtPointer)0 + }, + { + XtNsliderHeight, + XtCSliderHeight, + XtRDimension, + sizeof(Dimension), + offset(slider_height), + XtRImmediate, + (XtPointer)0 + }, + { + XtNshadowColor, + XtCShadowColor, + XtRPixel, + sizeof(Pixel), + offset(shadow_color), + XtRString, + (XtPointer)XtDefaultForeground + }, + { + XtNshadowThickness, + XtCShadowThickness, + XtRDimension, + sizeof(Dimension), + offset(shadow_thickness), + XtRImmediate, + (XtPointer)2 + }, + { + XtNbackgroundStipple, + XtCBackgroundStipple, + XtRString, + sizeof(String), + offset(stipple_name), + XtRImmediate, + NULL + }, +}; +#undef offset +#define Superclass (&simpleClassRec) PannerClassRec pannerClassRec = { - { /* core fields */ - /* superclass */ (WidgetClass) &simpleClassRec, - /* class_name */ "Panner", - /* widget_size */ sizeof(PannerRec), - /* class_initialize */ XawInitializeWidgetSet, - /* class_part_initialize */ NULL, - /* class_inited */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* realize */ Realize, - /* actions */ actions, - /* num_actions */ XtNumber(actions), - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure */ TRUE, - /* compress_enterleave */ TRUE, - /* visible_interest */ FALSE, - /* destroy */ Destroy, - /* resize */ Resize, - /* expose */ Redisplay, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* set_values_almost */ SetValuesAlmost, - /* get_values_hook */ NULL, - /* accept_focus */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ defaultTranslations, - /* query_geometry */ QueryGeometry, - /* display_accelerator */ XtInheritDisplayAccelerator, - /* extension */ NULL + /* core */ + { + (WidgetClass)Superclass, /* superclass */ + "Panner", /* class_name */ + sizeof(PannerRec), /* widget_size */ + XawInitializeWidgetSet, /* class_initialize */ + NULL, /* class_part_initialize */ + False, /* class_inited */ + XawPannerInitialize, /* initialize */ + NULL, /* initialize_hook */ + XawPannerRealize, /* realize */ + actions, /* actions */ + XtNumber(actions), /* num_actions */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + True, /* compress_motion */ + True, /* compress_exposure */ + True, /* compress_enterleave */ + False, /* visible_interest */ + XawPannerDestroy, /* destroy */ + XawPannerResize, /* resize */ + XawPannerRedisplay, /* expose */ + XawPannerSetValues, /* set_values */ + NULL, /* set_values_hook */ + XawPannerSetValuesAlmost, /* set_values_almost */ + NULL, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + defaultTranslations, /* tm_table */ + XawPannerQueryGeometry, /* query_geometry */ + XtInheritDisplayAccelerator, /* display_accelerator */ + NULL, /* extension */ }, - { /* simple fields */ - /* change_sensitive */ XtInheritChangeSensitive + /* simple */ + { + XtInheritChangeSensitive, /* change_sensitive */ }, - { /* panner fields */ - /* ignore */ 0 + /* panner */ + { + NULL, /* extension */ } }; WidgetClass pannerWidgetClass = (WidgetClass) &pannerClassRec; -/***************************************************************************** - * * - * panner utility routines * - * * - *****************************************************************************/ - -static void reset_shadow_gc (pw) /* used when resources change */ - PannerWidget pw; +/* + * Implementation + */ +static void +reset_shadow_gc(PannerWidget pw) { XtGCMask valuemask = GCForeground; XGCValues values; unsigned long pixels[3]; - if (pw->panner.shadow_gc) XtReleaseGC ((Widget) pw, pw->panner.shadow_gc); + if (pw->panner.shadow_gc) + XtReleaseGC((Widget)pw, pw->panner.shadow_gc); pixels[0] = pw->panner.foreground; pixels[1] = pw->core.background_pixel; pixels[2] = pw->panner.shadow_color; + if (!pw->panner.stipple_name && - !XmuDistinguishablePixels (XtDisplay (pw), pw->core.colormap, - pixels, 3) && - XmuDistinguishablePixels (XtDisplay (pw), pw->core.colormap, - pixels, 2)) - { + !XmuDistinguishablePixels(XtDisplay(pw), pw->core.colormap, + pixels, 3) && + XmuDistinguishablePixels(XtDisplay(pw), pw->core.colormap, + pixels, 2)) { valuemask = GCTile | GCFillStyle; values.fill_style = FillTiled; values.tile = XmuCreateStippledPixmap(XtScreen((Widget)pw), @@ -211,11 +362,10 @@ static void reset_shadow_gc (pw) /* used when resources change */ pw->core.background_pixel, pw->core.depth); } - else - { + else { if (!pw->panner.line_width && - !XmuDistinguishablePixels (XtDisplay (pw), pw->core.colormap, - pixels, 2)) + !XmuDistinguishablePixels(XtDisplay(pw), pw->core.colormap, + pixels, 2)) pw->panner.line_width = 1; valuemask = GCForeground; values.foreground = pw->panner.shadow_color; @@ -225,33 +375,35 @@ static void reset_shadow_gc (pw) /* used when resources change */ valuemask |= GCLineWidth; } - pw->panner.shadow_gc = XtGetGC ((Widget) pw, valuemask, &values); + pw->panner.shadow_gc = XtGetGC((Widget)pw, valuemask, &values); } -static void reset_slider_gc (pw) /* used when resources change */ - PannerWidget pw; +static void +reset_slider_gc(PannerWidget pw) { XtGCMask valuemask = GCForeground; XGCValues values; - if (pw->panner.slider_gc) XtReleaseGC ((Widget) pw, pw->panner.slider_gc); + if (pw->panner.slider_gc) + XtReleaseGC((Widget)pw, pw->panner.slider_gc); values.foreground = pw->panner.foreground; - pw->panner.slider_gc = XtGetGC ((Widget) pw, valuemask, &values); + pw->panner.slider_gc = XtGetGC((Widget)pw, valuemask, &values); } -static void reset_xor_gc (pw) /* used when resources change */ - PannerWidget pw; +static void +reset_xor_gc(PannerWidget pw) { - if (pw->panner.xor_gc) XtReleaseGC ((Widget) pw, pw->panner.xor_gc); + if (pw->panner.xor_gc) + XtReleaseGC((Widget)pw, pw->panner.xor_gc); if (pw->panner.rubber_band) { XtGCMask valuemask = (GCForeground | GCFunction); XGCValues values; Pixel tmp; - tmp = ((pw->panner.foreground == pw->core.background_pixel) ? + tmp = (pw->panner.foreground == pw->core.background_pixel ? pw->panner.shadow_color : pw->panner.foreground); values.foreground = tmp ^ pw->core.background_pixel; values.function = GXxor; @@ -259,698 +411,669 @@ static void reset_xor_gc (pw) /* used when resources change */ valuemask |= GCLineWidth; values.line_width = pw->panner.line_width; } - pw->panner.xor_gc = XtGetGC ((Widget) pw, valuemask, &values); - } else { - pw->panner.xor_gc = NULL; + pw->panner.xor_gc = XtGetGC((Widget)pw, valuemask, &values); } + else + pw->panner.xor_gc = NULL; } - -static void check_knob (pw, knob) - PannerWidget pw; - Boolean knob; +static void +check_knob(PannerWidget pw, Bool knob) { - Position pad = pw->panner.internal_border * 2; - Position maxx = (((Position) pw->core.width) - pad - - ((Position) pw->panner.knob_width)); - Position maxy = (((Position) pw->core.height) - pad - - ((Position) pw->panner.knob_height)); - Position *x = (knob ? &pw->panner.knob_x : &pw->panner.tmp.x); - Position *y = (knob ? &pw->panner.knob_y : &pw->panner.tmp.y); + Position pad = pw->panner.internal_border << 1; + Position maxx = (Position)XtWidth(pw) - pad - + (Position)pw->panner.knob_width; + Position maxy = (Position)XtHeight(pw) - pad - + (Position)pw->panner.knob_height; + Position *x = knob ? &pw->panner.knob_x : &pw->panner.tmp.x; + Position *y = knob ? &pw->panner.knob_y : &pw->panner.tmp.y; /* * note that positions are already normalized (i.e. internal_border * has been subtracted out) */ - if (*x < 0) *x = 0; - if (*x > maxx) *x = maxx; + if (*x < 0) + *x = 0; + if (*x > maxx) + *x = maxx; - if (*y < 0) *y = 0; - if (*y > maxy) *y = maxy; + if (*y < 0) + *y = 0; + if (*y > maxy) + *y = maxy; if (knob) { - pw->panner.slider_x = (Position) (((double) pw->panner.knob_x) / - pw->panner.haspect + 0.5); - pw->panner.slider_y = (Position) (((double) pw->panner.knob_y) / - pw->panner.vaspect + 0.5); + pw->panner.slider_x = (Position)((double)pw->panner.knob_x + / pw->panner.haspect + 0.5); + pw->panner.slider_y = (Position)((double)pw->panner.knob_y + / pw->panner.vaspect + 0.5); pw->panner.last_x = pw->panner.last_y = PANNER_OUTOFRANGE; } } - -static void move_shadow (pw) - PannerWidget pw; +static void +move_shadow(PannerWidget pw) { if (pw->panner.shadow_thickness > 0) { - int lw = pw->panner.shadow_thickness + pw->panner.line_width * 2; + int lw = pw->panner.shadow_thickness + (pw->panner.line_width << 1); int pad = pw->panner.internal_border; - if ((int)pw->panner.knob_height > lw && (int)pw->panner.knob_width > lw) { + if (pw->panner.knob_height > lw && pw->panner.knob_width > lw) { XRectangle *r = pw->panner.shadow_rects; - r->x = (short) (pw->panner.knob_x + pad + pw->panner.knob_width); - r->y = (short) (pw->panner.knob_y + pad + lw); + + r->x = pw->panner.knob_x + pad + pw->panner.knob_width; + r->y = pw->panner.knob_y + pad + lw; r->width = pw->panner.shadow_thickness; - r->height = (unsigned short) (pw->panner.knob_height - lw); + r->height = pw->panner.knob_height - lw; r++; - r->x = (short) (pw->panner.knob_x + pad + lw); - r->y = (short) (pw->panner.knob_y + pad + pw->panner.knob_height); - r->width = (unsigned short) (pw->panner.knob_width - lw + - pw->panner.shadow_thickness); + r->x = pw->panner.knob_x + pad + lw; + r->y = pw->panner.knob_y + pad + pw->panner.knob_height; + r->width = pw->panner.knob_width - lw + pw->panner.shadow_thickness; r->height = pw->panner.shadow_thickness; - pw->panner.shadow_valid = TRUE; + pw->panner.shadow_valid = True; return; } } - pw->panner.shadow_valid = FALSE; + pw->panner.shadow_valid = False; } -static void scale_knob (pw, location, size) /* set knob size and/or loc */ - PannerWidget pw; - Boolean location, size; +static void +scale_knob(PannerWidget pw, Bool location, Bool size) { if (location) { - pw->panner.knob_x = (Position) PANNER_HSCALE (pw, pw->panner.slider_x); - pw->panner.knob_y = (Position) PANNER_VSCALE (pw, pw->panner.slider_y); + pw->panner.knob_x = (Position)PANNER_HSCALE(pw, pw->panner.slider_x); + pw->panner.knob_y = (Position)PANNER_VSCALE(pw, pw->panner.slider_y); } if (size) { Dimension width, height; - if (pw->panner.slider_width < 1) { + if (pw->panner.slider_width < 1) pw->panner.slider_width = pw->panner.canvas_width; - } - if (pw->panner.slider_height < 1) { + if (pw->panner.slider_height < 1) pw->panner.slider_height = pw->panner.canvas_height; - } - width = Min (pw->panner.slider_width, pw->panner.canvas_width); - height = Min (pw->panner.slider_height, pw->panner.canvas_height); + width = Min(pw->panner.slider_width, pw->panner.canvas_width); + height = Min(pw->panner.slider_height, pw->panner.canvas_height); - pw->panner.knob_width = (Dimension) PANNER_HSCALE (pw, width); - pw->panner.knob_height = (Dimension) PANNER_VSCALE (pw, height); + pw->panner.knob_width = (Dimension)PANNER_HSCALE(pw, width); + pw->panner.knob_height = (Dimension)PANNER_VSCALE(pw, height); } - if (!pw->panner.allow_off) check_knob (pw, TRUE); - move_shadow (pw); + if (!pw->panner.allow_off) + check_knob(pw, True); + move_shadow(pw); } -static void rescale (pw) - PannerWidget pw; +static void +rescale(PannerWidget pw) { - int hpad = pw->panner.internal_border * 2; + int hpad = pw->panner.internal_border << 1; int vpad = hpad; if (pw->panner.canvas_width < 1) - pw->panner.canvas_width = pw->core.width; + pw->panner.canvas_width = XtWidth(pw); if (pw->panner.canvas_height < 1) - pw->panner.canvas_height = pw->core.height; - - if ((int)pw->core.width <= hpad) hpad = 0; - if ((int)pw->core.height <= vpad) vpad = 0; - - pw->panner.haspect = ((double) pw->core.width - hpad) / - (double) pw->panner.canvas_width; - pw->panner.vaspect = ((double) pw->core.height - vpad) / - (double) pw->panner.canvas_height; - scale_knob (pw, TRUE, TRUE); + pw->panner.canvas_height = XtHeight(pw); + + if (XtWidth(pw) <= hpad) + hpad = 0; + if (XtHeight(pw) <= vpad) + vpad = 0; + + pw->panner.haspect = ((double)XtWidth(pw) - hpad + .5) + / (double)pw->panner.canvas_width; + pw->panner.vaspect = ((double)XtHeight(pw) - vpad + .5) + / (double)pw->panner.canvas_height; + scale_knob(pw, True, True); } - -static void get_default_size (pw, wp, hp) - PannerWidget pw; - Dimension *wp, *hp; +static void +get_default_size(PannerWidget pw, Dimension *wp, Dimension *hp) { - Dimension pad = pw->panner.internal_border * 2; - *wp = PANNER_DSCALE (pw, pw->panner.canvas_width) + pad; - *hp = PANNER_DSCALE (pw, pw->panner.canvas_height) + pad; + Dimension pad = pw->panner.internal_border << 1; + + *wp = PANNER_DSCALE(pw, pw->panner.canvas_width) + pad; + *hp = PANNER_DSCALE(pw, pw->panner.canvas_height) + pad; } -static Boolean get_event_xy (pw, event, x, y) - PannerWidget pw; - XEvent *event; - int *x, *y; +static Bool +get_event_xy(PannerWidget pw, XEvent *event, int *x, int *y) { int pad = pw->panner.internal_border; switch (event->type) { - case ButtonPress: - case ButtonRelease: - *x = event->xbutton.x - pad; - *y = event->xbutton.y - pad; - return TRUE; - - case KeyPress: - case KeyRelease: - *x = event->xkey.x - pad; - *y = event->xkey.y - pad; - return TRUE; - - case EnterNotify: - case LeaveNotify: - *x = event->xcrossing.x - pad; - *y = event->xcrossing.y - pad; - return TRUE; - - case MotionNotify: - *x = event->xmotion.x - pad; - *y = event->xmotion.y - pad; - return TRUE; - } - - return FALSE; + case ButtonPress: + case ButtonRelease: + *x = event->xbutton.x - pad; + *y = event->xbutton.y - pad; + return (True); + case KeyPress: + case KeyRelease: + *x = event->xkey.x - pad; + *y = event->xkey.y - pad; + return (True); + case EnterNotify: + case LeaveNotify: + *x = event->xcrossing.x - pad; + *y = event->xcrossing.y - pad; + return (True); + case MotionNotify: + *x = event->xmotion.x - pad; + *y = event->xmotion.y - pad; + return (True); + } + + return (False); } -static int parse_page_string (s, pagesize, canvassize, relative) - char *s; - int pagesize, canvassize; - Boolean *relative; +static int +parse_page_string(char *s, int pagesize, int canvassize, Bool *relative) { char *cp; double val = 1.0; - Boolean rel = FALSE; + Bool rel = False; /* * syntax: spaces [+-] number spaces [pc\0] spaces */ + for (; isascii(*s) && isspace(*s); s++) /* skip white space */ + ; - for (; isascii(*s) && isspace(*s); s++) ; /* skip white space */ - - if (*s == '+' || *s == '-') { /* deal with signs */ - rel = TRUE; - if (*s == '-') val = -1.0; + if (*s == '+' || *s == '-') { /* deal with signs */ + rel = True; + if (*s == '-') + val = -1.0; s++; } if (!*s) { /* if null then return nothing */ - *relative = TRUE; - return 0; + *relative = True; + return (0); } /* skip over numbers */ - for (cp = s; isascii(*s) && (isdigit(*s) || *s == '.'); s++) ; - val *= atof (cp); + for (cp = s; isascii(*s) && (isdigit(*s) || *s == '.'); s++) + ; + val *= atof(cp); /* skip blanks */ - for (; isascii(*s) && isspace(*s); s++) ; + for (; isascii(*s) && isspace(*s); s++) + ; if (*s) { /* if units */ switch (s[0]) { - case 'p': case 'P': - val *= (double) pagesize; - break; - - case 'c': case 'C': - val *= (double) canvassize; - break; + case 'p': + case 'P': + val *= (double)pagesize; + break; + case 'c': + case 'C': + val *= (double)canvassize; + break; } } *relative = rel; - return ((int) val); -} + return ((int)val); +} #define DRAW_TMP(pw) \ { \ - XDrawRectangle (XtDisplay(pw), XtWindow(pw), \ - pw->panner.xor_gc, \ - (int) (pw->panner.tmp.x + pw->panner.internal_border), \ - (int) (pw->panner.tmp.y + pw->panner.internal_border), \ - (unsigned int) (pw->panner.knob_width - 1), \ - (unsigned int) (pw->panner.knob_height - 1)); \ - pw->panner.tmp.showing = !pw->panner.tmp.showing; \ + XDrawRectangle(XtDisplay(pw), XtWindow(pw), \ + pw->panner.xor_gc, \ + pw->panner.tmp.x + pw->panner.internal_border, \ + pw->panner.tmp.y + pw->panner.internal_border, \ + pw->panner.knob_width - 1, \ + pw->panner.knob_height - 1); \ + pw->panner.tmp.showing = !pw->panner.tmp.showing; \ } #define UNDRAW_TMP(pw) \ { \ - if (pw->panner.tmp.showing) DRAW_TMP(pw); \ + if (pw->panner.tmp.showing) \ + DRAW_TMP(pw); \ } #define BACKGROUND_STIPPLE(pw) \ - XmuLocatePixmapFile (pw->core.screen, pw->panner.stipple_name, \ - pw->panner.shadow_color, pw->core.background_pixel, \ - pw->core.depth, NULL, 0, NULL, NULL, NULL, NULL) +XmuLocatePixmapFile(pw->core.screen, pw->panner.stipple_name, \ + pw->panner.shadow_color, pw->core.background_pixel, \ + pw->core.depth, NULL, 0, NULL, NULL, NULL, NULL) #define PIXMAP_OKAY(pm) ((pm) != None && (pm) != XtUnspecifiedPixmap) - -/***************************************************************************** - * * - * panner class methods * - * * - *****************************************************************************/ - - /*ARGSUSED*/ -static void Initialize (greq, gnew, args, num_args) - Widget greq, gnew; - ArgList args; - Cardinal *num_args; +static void +XawPannerInitialize(Widget greq, Widget gnew, ArgList args, Cardinal *num_args) { - PannerWidget req = (PannerWidget) greq, new = (PannerWidget) gnew; + PannerWidget req = (PannerWidget)greq, cnew = (PannerWidget)gnew; Dimension defwidth, defheight; - if (req->panner.canvas_width < 1) new->panner.canvas_width = 1; - if (req->panner.canvas_height < 1) new->panner.canvas_height = 1; + if (req->panner.canvas_width < 1) + cnew->panner.canvas_width = 1; + if (req->panner.canvas_height < 1) + cnew->panner.canvas_height = 1; if (req->panner.default_scale < 1) - new->panner.default_scale = PANNER_DEFAULT_SCALE; - - get_default_size (req, &defwidth, &defheight); - if (req->core.width < 1) new->core.width = defwidth; - if (req->core.height < 1) new->core.height = defheight; - - new->panner.shadow_gc = NULL; - reset_shadow_gc (new); /* shadowColor */ - new->panner.slider_gc = NULL; - reset_slider_gc (new); /* foreground */ - new->panner.xor_gc = NULL; - reset_xor_gc (new); /* foreground ^ background */ - - rescale (new); /* does a position check */ - new->panner.shadow_valid = FALSE; - new->panner.tmp.doing = FALSE; - new->panner.tmp.showing = FALSE; -} - + cnew->panner.default_scale = PANNER_DEFAULT_SCALE; + + get_default_size(req, &defwidth, &defheight); + if (XtWidth(req) < 1) + XtWidth(cnew) = defwidth; + if (XtHeight(req) < 1) + XtHeight(cnew) = defheight; + + cnew->panner.shadow_gc = NULL; + reset_shadow_gc(cnew); /* shadowColor */ + cnew->panner.slider_gc = NULL; + reset_slider_gc(cnew); /* foreground */ + cnew->panner.xor_gc = NULL; + reset_xor_gc(cnew); /* foreground ^ background */ + + rescale(cnew); /* does a position check */ + cnew->panner.shadow_valid = False; + cnew->panner.tmp.doing = False; + cnew->panner.tmp.showing = False; + } -static void Realize (gw, valuemaskp, attr) - Widget gw; - XtValueMask *valuemaskp; - XSetWindowAttributes *attr; +static void +XawPannerRealize(Widget gw, XtValueMask *valuemaskp, + XSetWindowAttributes *attr) { - PannerWidget pw = (PannerWidget) gw; + PannerWidget pw = (PannerWidget)gw; Pixmap pm = XtUnspecifiedPixmap; - Boolean gotpm = FALSE; + Bool gotpm = False; if (pw->core.background_pixmap == XtUnspecifiedPixmap) { - if (pw->panner.stipple_name) pm = BACKGROUND_STIPPLE (pw); + if (pw->panner.stipple_name) + pm = BACKGROUND_STIPPLE(pw); if (PIXMAP_OKAY(pm)) { attr->background_pixmap = pm; *valuemaskp |= CWBackPixmap; *valuemaskp &= ~CWBackPixel; - gotpm = TRUE; + gotpm = True; } } (*pannerWidgetClass->core_class.superclass->core_class.realize) - (gw, valuemaskp, attr); + (gw, valuemaskp, attr); - if (gotpm) XFreePixmap (XtDisplay(gw), pm); + if (gotpm) + XFreePixmap(XtDisplay(gw), pm); } - -static void Destroy (gw) - Widget gw; +static void +XawPannerDestroy(Widget gw) { - PannerWidget pw = (PannerWidget) gw; + PannerWidget pw = (PannerWidget)gw; - XtReleaseGC (gw, pw->panner.shadow_gc); - XtReleaseGC (gw, pw->panner.slider_gc); - XtReleaseGC (gw, pw->panner.xor_gc); + XtReleaseGC(gw, pw->panner.shadow_gc); + XtReleaseGC(gw, pw->panner.slider_gc); + XtReleaseGC(gw, pw->panner.xor_gc); } - -static void Resize (gw) - Widget gw; +static void +XawPannerResize(Widget gw) { - rescale ((PannerWidget) gw); + rescale((PannerWidget)gw); } - -/* ARGSUSED */ -static void Redisplay (gw, event, region) - Widget gw; - XEvent *event; - Region region; +static void +XawPannerRedisplay(Widget gw, XEvent *event, Region region) { - PannerWidget pw = (PannerWidget) gw; + PannerWidget pw = (PannerWidget)gw; Display *dpy = XtDisplay(gw); Window w = XtWindow(gw); int pad = pw->panner.internal_border; Dimension lw = pw->panner.line_width; - Dimension extra = pw->panner.shadow_thickness + lw * 2; + Dimension extra = pw->panner.shadow_thickness + (lw << 1); int kx = pw->panner.knob_x + pad, ky = pw->panner.knob_y + pad; - pw->panner.tmp.showing = FALSE; - XClearArea (XtDisplay(pw), XtWindow(pw), - (int) pw->panner.last_x - ((int) lw) + pad, - (int) pw->panner.last_y - ((int) lw) + pad, - (unsigned int) (pw->panner.knob_width + extra), - (unsigned int) (pw->panner.knob_height + extra), - False); + if (Superclass->core_class.expose) + (Superclass->core_class.expose)(gw, event, region); + + pw->panner.tmp.showing = False; + XClearArea(XtDisplay(pw), XtWindow(pw), + (int)pw->panner.last_x - ((int)lw) + pad, + (int)pw->panner.last_y - ((int)lw) + pad, + pw->panner.knob_width + extra, + pw->panner.knob_height + extra, + False); pw->panner.last_x = pw->panner.knob_x; pw->panner.last_y = pw->panner.knob_y; - XFillRectangle (dpy, w, pw->panner.slider_gc, kx, ky, - pw->panner.knob_width - 1, pw->panner.knob_height - 1); + XFillRectangle(dpy, w, pw->panner.slider_gc, kx, ky, + pw->panner.knob_width - 1, pw->panner.knob_height - 1); if (lw) - { - XDrawRectangle (dpy, w, pw->panner.shadow_gc, kx, ky, - (unsigned int) (pw->panner.knob_width - 1), - (unsigned int) (pw->panner.knob_height - 1)); - } + XDrawRectangle(dpy, w, pw->panner.shadow_gc, kx, ky, + pw->panner.knob_width - 1, pw->panner.knob_height - 1); - if (pw->panner.shadow_valid) { - XFillRectangles (dpy, w, pw->panner.shadow_gc, - pw->panner.shadow_rects, 2); - } - if (pw->panner.tmp.doing && pw->panner.rubber_band) DRAW_TMP (pw); -} + if (pw->panner.shadow_valid) + XFillRectangles(dpy, w, pw->panner.shadow_gc, pw->panner.shadow_rects, 2); + if (pw->panner.tmp.doing && pw->panner.rubber_band) + DRAW_TMP(pw); +} -/* ARGSUSED */ -static Boolean SetValues (gcur, greq, gnew, args, num_args) - Widget gcur, greq, gnew; - ArgList args; - Cardinal *num_args; +/*ARGSUSED*/ +static Boolean +XawPannerSetValues(Widget gcur, Widget greq, Widget gnew, + ArgList args, Cardinal *num_args) { - PannerWidget cur = (PannerWidget) gcur; - PannerWidget new = (PannerWidget) gnew; - Boolean redisplay = FALSE; + PannerWidget cur = (PannerWidget)gcur; + PannerWidget cnew = (PannerWidget)gnew; + Bool redisplay = False; - if (cur->panner.foreground != new->panner.foreground) { - reset_slider_gc (new); + if (cur->panner.foreground != cnew->panner.foreground) { + reset_slider_gc(cnew); if (cur->panner.foreground != cur->core.background_pixel) - reset_xor_gc (new); - redisplay = TRUE; - } else if (cur->panner.line_width != new->panner.line_width || - cur->core.background_pixel != new->core.background_pixel) { - reset_xor_gc (new); - redisplay = TRUE; - } - if (cur->panner.shadow_color != new->panner.shadow_color) { - reset_shadow_gc (new); + reset_xor_gc(cnew); + redisplay = True; + } + else if (cur->panner.line_width != cnew->panner.line_width || + cur->core.background_pixel != cnew->core.background_pixel) { + reset_xor_gc(cnew); + redisplay = True; + } + if (cur->panner.shadow_color != cnew->panner.shadow_color) { + reset_shadow_gc(cnew); if (cur->panner.foreground == cur->core.background_pixel) - reset_xor_gc (new); - redisplay = TRUE; + reset_xor_gc(cnew); + redisplay = True; } - if (cur->panner.shadow_thickness != new->panner.shadow_thickness) { - move_shadow (new); - redisplay = TRUE; + if (cur->panner.shadow_thickness != cnew->panner.shadow_thickness) { + move_shadow(cnew); + redisplay = True; } - if (cur->panner.rubber_band != new->panner.rubber_band) { - reset_xor_gc (new); - if (new->panner.tmp.doing) redisplay = TRUE; + if (cur->panner.rubber_band != cnew->panner.rubber_band) { + reset_xor_gc(cnew); + if (cnew->panner.tmp.doing) + redisplay = True; } - if ((cur->panner.stipple_name != new->panner.stipple_name || - cur->panner.shadow_color != new->panner.shadow_color || - cur->core.background_pixel != new->core.background_pixel) && - XtIsRealized(gnew)) { - Pixmap pm = (new->panner.stipple_name ? BACKGROUND_STIPPLE (new) - : XtUnspecifiedPixmap); + if ((cur->panner.stipple_name != cnew->panner.stipple_name + || cur->panner.shadow_color != cnew->panner.shadow_color + || cur->core.background_pixel != cnew->core.background_pixel) + && XtIsRealized(gnew)) { + Pixmap pm = cnew->panner.stipple_name ? + BACKGROUND_STIPPLE(cnew) : XtUnspecifiedPixmap; if (PIXMAP_OKAY(pm)) { - XSetWindowBackgroundPixmap (XtDisplay (new), XtWindow(new), pm); - XFreePixmap (XtDisplay (new), pm); - } else { - XSetWindowBackground (XtDisplay (new), XtWindow(new), - new->core.background_pixel); + XSetWindowBackgroundPixmap(XtDisplay(cnew), XtWindow(cnew), pm); + XFreePixmap(XtDisplay(cnew), pm); } - redisplay = TRUE; - } - - if (new->panner.resize_to_pref && - (cur->panner.canvas_width != new->panner.canvas_width || - cur->panner.canvas_height != new->panner.canvas_height || - cur->panner.resize_to_pref != new->panner.resize_to_pref)) { - get_default_size (new, &new->core.width, &new->core.height); - redisplay = TRUE; - } else if (cur->panner.canvas_width != new->panner.canvas_width || - cur->panner.canvas_height != new->panner.canvas_height || - cur->panner.internal_border != new->panner.internal_border) { - rescale (new); /* does a scale_knob as well */ - redisplay = TRUE; - } else { - Boolean loc = (cur->panner.slider_x != new->panner.slider_x || - cur->panner.slider_y != new->panner.slider_y); - Boolean siz = (cur->panner.slider_width != new->panner.slider_width || - cur->panner.slider_height != new->panner.slider_height); - if (loc || siz || - (cur->panner.allow_off != new->panner.allow_off && - new->panner.allow_off)) { - scale_knob (new, loc, siz); - redisplay = TRUE; + else + XSetWindowBackground(XtDisplay(cnew), XtWindow(cnew), + cnew->core.background_pixel); + + redisplay = True; + } + + if (cnew->panner.resize_to_pref && + (cur->panner.canvas_width != cnew->panner.canvas_width + || cur->panner.canvas_height != cnew->panner.canvas_height + || cur->panner.resize_to_pref != cnew->panner.resize_to_pref)) { + get_default_size(cnew, &cnew->core.width, &cnew->core.height); + redisplay = True; + } + else if (cur->panner.canvas_width != cnew->panner.canvas_width + || cur->panner.canvas_height != cnew->panner.canvas_height + || cur->panner.internal_border != cnew->panner.internal_border) { + rescale(cnew); /* does a scale_knob as well */ + redisplay = True; + } + else { + Bool loc = cur->panner.slider_x != cnew->panner.slider_x || + cur->panner.slider_y != cnew->panner.slider_y; + Bool siz = cur->panner.slider_width != cnew->panner.slider_width || + cur->panner.slider_height != cnew->panner.slider_height; + if (loc || siz || (cur->panner.allow_off != cnew->panner.allow_off + && cnew->panner.allow_off)) { + scale_knob(cnew, loc, siz); + redisplay = True; } } - return redisplay; + return (redisplay); } -static void SetValuesAlmost (gold, gnew, req, reply) - Widget gold, gnew; - XtWidgetGeometry *req, *reply; +static void +XawPannerSetValuesAlmost(Widget gold, Widget gnew, XtWidgetGeometry *req, + XtWidgetGeometry *reply) { - if (reply->request_mode == 0) { /* got turned down, so cope */ - Resize (gnew); - } + if (reply->request_mode == 0) /* got turned down, so cope */ + XawPannerResize(gnew); + (*pannerWidgetClass->core_class.superclass->core_class.set_values_almost) (gold, gnew, req, reply); } -static XtGeometryResult QueryGeometry (gw, intended, pref) - Widget gw; - XtWidgetGeometry *intended, *pref; +static XtGeometryResult +XawPannerQueryGeometry(Widget gw, XtWidgetGeometry *intended, + XtWidgetGeometry *pref) { - PannerWidget pw = (PannerWidget) gw; + PannerWidget pw = (PannerWidget)gw; pref->request_mode = (CWWidth | CWHeight); - get_default_size (pw, &pref->width, &pref->height); - - if (((intended->request_mode & (CWWidth | CWHeight)) == - (CWWidth | CWHeight)) && - intended->width == pref->width && - intended->height == pref->height) - return XtGeometryYes; - else if (pref->width == pw->core.width && pref->height == pw->core.height) - return XtGeometryNo; - else - return XtGeometryAlmost; -} + get_default_size(pw, &pref->width, &pref->height); + if (((intended->request_mode & (CWWidth | CWHeight)) == (CWWidth | CWHeight)) + && intended->width == pref->width && intended->height == pref->height) + return (XtGeometryYes); + else if (pref->width == XtWidth(pw) && pref->height == XtHeight(pw)) + return (XtGeometryNo); + + return (XtGeometryAlmost); +} -/***************************************************************************** - * * - * panner action procs * - * * - *****************************************************************************/ -/* ARGSUSED */ -static void ActionStart (gw, event, params, num_params) - Widget gw; - XEvent *event; - String *params; /* unused */ - Cardinal *num_params; /* unused */ +/*ARGSUSED*/ +static void +ActionStart(Widget gw, XEvent *event, String *params, Cardinal *num_params) { - PannerWidget pw = (PannerWidget) gw; + PannerWidget pw = (PannerWidget)gw; int x, y; - if (!get_event_xy (pw, event, &x, &y)) { - XBell (XtDisplay(gw), 0); /* should do error message */ + if (!get_event_xy(pw, event, &x, &y)) { + XBell(XtDisplay(gw), 0); return; } - pw->panner.tmp.doing = TRUE; + pw->panner.tmp.doing = True; pw->panner.tmp.startx = pw->panner.knob_x; pw->panner.tmp.starty = pw->panner.knob_y; - pw->panner.tmp.dx = (((Position) x) - pw->panner.knob_x); - pw->panner.tmp.dy = (((Position) y) - pw->panner.knob_y); + pw->panner.tmp.dx = x - pw->panner.knob_x; + pw->panner.tmp.dy = y - pw->panner.knob_y; pw->panner.tmp.x = pw->panner.knob_x; pw->panner.tmp.y = pw->panner.knob_y; - if (pw->panner.rubber_band) DRAW_TMP (pw); + if (pw->panner.rubber_band) + DRAW_TMP(pw); } -/* ARGSUSED */ -static void ActionStop (gw, event, params, num_params) - Widget gw; - XEvent *event; - String *params; /* unused */ - Cardinal *num_params; /* unused */ +/*ARGSUSED*/ +static void +ActionStop(Widget gw, XEvent *event, String *params, Cardinal *num_params) { - PannerWidget pw = (PannerWidget) gw; + PannerWidget pw = (PannerWidget)gw; int x, y; - if (get_event_xy (pw, event, &x, &y)) { - pw->panner.tmp.x = ((Position) x) - pw->panner.tmp.dx; - pw->panner.tmp.y = ((Position) y) - pw->panner.tmp.dy; - if (!pw->panner.allow_off) check_knob (pw, FALSE); + if (get_event_xy(pw, event, &x, &y)) { + pw->panner.tmp.x = x - pw->panner.tmp.dx; + pw->panner.tmp.y = y - pw->panner.tmp.dy; + if (!pw->panner.allow_off) + check_knob(pw, False); } - if (pw->panner.rubber_band) UNDRAW_TMP (pw); - pw->panner.tmp.doing = FALSE; + if (pw->panner.rubber_band) + DRAW_TMP(pw); + pw->panner.tmp.doing = False; } -/* ARGSUSED */ -static void ActionAbort (gw, event, params, num_params) - Widget gw; - XEvent *event; - String *params; /* unused */ - Cardinal *num_params; /* unused */ +static void +ActionAbort(Widget gw, XEvent *event, String *params, Cardinal *num_params) { - PannerWidget pw = (PannerWidget) gw; + PannerWidget pw = (PannerWidget)gw; - if (!pw->panner.tmp.doing) return; + if (!pw->panner.tmp.doing) + return; - if (pw->panner.rubber_band) UNDRAW_TMP (pw); + if (pw->panner.rubber_band) + UNDRAW_TMP(pw); if (!pw->panner.rubber_band) { /* restore old position */ pw->panner.tmp.x = pw->panner.tmp.startx; pw->panner.tmp.y = pw->panner.tmp.starty; - ActionNotify (gw, event, params, num_params); + ActionNotify(gw, event, params, num_params); } - pw->panner.tmp.doing = FALSE; + pw->panner.tmp.doing = False; } - -/* ARGSUSED */ -static void ActionMove (gw, event, params, num_params) - Widget gw; - XEvent *event; /* must be a motion event */ - String *params; /* unused */ - Cardinal *num_params; /* unused */ +static void +ActionMove(Widget gw, XEvent *event, String *params, Cardinal *num_params) { - PannerWidget pw = (PannerWidget) gw; + PannerWidget pw = (PannerWidget)gw; int x, y; - if (!pw->panner.tmp.doing) return; + if (!pw->panner.tmp.doing) + return; - if (!get_event_xy (pw, event, &x, &y)) { - XBell (XtDisplay(gw), 0); /* should do error message */ + if (!get_event_xy(pw, event, &x, &y)) { + XBell(XtDisplay(gw), 0); /* should do error message */ return; } - if (pw->panner.rubber_band) UNDRAW_TMP (pw); - pw->panner.tmp.x = ((Position) x) - pw->panner.tmp.dx; - pw->panner.tmp.y = ((Position) y) - pw->panner.tmp.dy; - - if (!pw->panner.rubber_band) { - ActionNotify (gw, event, params, num_params); /* does a check */ - } else { - if (!pw->panner.allow_off) check_knob (pw, FALSE); - DRAW_TMP (pw); + if (pw->panner.rubber_band) + UNDRAW_TMP(pw); + pw->panner.tmp.x = x - pw->panner.tmp.dx; + pw->panner.tmp.y = y - pw->panner.tmp.dy; + + if (!pw->panner.rubber_band) + ActionNotify(gw, event, params, num_params); + else { + if (!pw->panner.allow_off) + check_knob(pw, False); + DRAW_TMP(pw); } } -/* ARGSUSED */ -static void ActionPage (gw, event, params, num_params) - Widget gw; - XEvent *event; /* unused */ - String *params; - Cardinal *num_params; /* unused */ +static void +ActionPage(Widget gw, XEvent *event, String *params, Cardinal *num_params) { - PannerWidget pw = (PannerWidget) gw; + PannerWidget pw = (PannerWidget)gw; Cardinal zero = 0; - Boolean isin = pw->panner.tmp.doing; + Bool isin = pw->panner.tmp.doing; int x, y; - Boolean relx, rely; - int pad = pw->panner.internal_border * 2; + Bool relx, rely; + int pad = pw->panner.internal_border << 1; if (*num_params != 2) { - XBell (XtDisplay(gw), 0); + XBell(XtDisplay(gw), 0); return; } - x = parse_page_string (params[0], (int) pw->panner.knob_width, - ((int) pw->core.width) - pad, &relx); - y = parse_page_string (params[1], (int) pw->panner.knob_height, - ((int) pw->core.height) - pad, &rely); + x = parse_page_string(params[0], pw->panner.knob_width, + (int)XtWidth(pw) - pad, &relx); + y = parse_page_string(params[1], pw->panner.knob_height, + (int)XtHeight(pw) - pad, &rely); - if (relx) x += pw->panner.knob_x; - if (rely) y += pw->panner.knob_y; + if (relx) + x += pw->panner.knob_x; + if (rely) + y += pw->panner.knob_y; if (isin) { /* if in, then use move */ XEvent ev; + ev.xbutton.type = ButtonPress; ev.xbutton.x = x; ev.xbutton.y = y; - ActionMove (gw, &ev, (String *) NULL, &zero); - } else { /* else just do it */ - pw->panner.tmp.doing = TRUE; + ActionMove(gw, &ev, NULL, &zero); + } + else { + pw->panner.tmp.doing = True; pw->panner.tmp.x = x; pw->panner.tmp.y = y; - ActionNotify (gw, event, (String *) NULL, &zero); - pw->panner.tmp.doing = FALSE; + ActionNotify(gw, event, NULL, &zero); + pw->panner.tmp.doing = False; } } - -/* ARGSUSED */ -static void ActionNotify (gw, event, params, num_params) - Widget gw; - XEvent *event; /* unused */ - String *params; /* unused */ - Cardinal *num_params; /* unused */ +/*ARGSUSED*/ +static void +ActionNotify(Widget gw, XEvent *event, String *params, Cardinal *num_params) { - PannerWidget pw = (PannerWidget) gw; + PannerWidget pw = (PannerWidget)gw; - if (!pw->panner.tmp.doing) return; + if (!pw->panner.tmp.doing) + return; - if (!pw->panner.allow_off) check_knob (pw, FALSE); + if (!pw->panner.allow_off) + check_knob(pw, False); pw->panner.knob_x = pw->panner.tmp.x; pw->panner.knob_y = pw->panner.tmp.y; - move_shadow (pw); + move_shadow(pw); - pw->panner.slider_x = (Position) (((double) pw->panner.knob_x) / - pw->panner.haspect + 0.5); - pw->panner.slider_y = (Position) (((double) pw->panner.knob_y) / - pw->panner.vaspect + 0.5); + pw->panner.slider_x = (Position)((double)pw->panner.knob_x + / pw->panner.haspect + 0.5); + pw->panner.slider_y = (Position)((double) pw->panner.knob_y + / pw->panner.vaspect + 0.5); if (!pw->panner.allow_off) { Position tmp; - - if (pw->panner.slider_x > - (tmp = (((Position) pw->panner.canvas_width) - - ((Position) pw->panner.slider_width)))) - pw->panner.slider_x = tmp; - if (pw->panner.slider_x < 0) pw->panner.slider_x = 0; - if (pw->panner.slider_y > - (tmp = (((Position) pw->panner.canvas_height) - - ((Position) pw->panner.slider_height)))) - pw->panner.slider_y = tmp; - if (pw->panner.slider_y < 0) pw->panner.slider_y = 0; + + if (pw->panner.slider_x + > (tmp = (Position)pw->panner.canvas_width - + (Position)pw->panner.slider_width)) + pw->panner.slider_x = tmp; + if (pw->panner.slider_x < 0) + pw->panner.slider_x = 0; + if (pw->panner.slider_y + > (tmp = (Position)pw->panner.canvas_height - + (Position)pw->panner.slider_height)) + pw->panner.slider_y = tmp; + if (pw->panner.slider_y < 0) + pw->panner.slider_y = 0; } if (pw->panner.last_x != pw->panner.knob_x || pw->panner.last_y != pw->panner.knob_y) { XawPannerReport rep; - Redisplay (gw, (XEvent*) NULL, (Region) NULL); - rep.changed = (XawPRSliderX | XawPRSliderY); + XawPannerRedisplay(gw, NULL, NULL); + rep.changed = XawPRSliderX | XawPRSliderY; rep.slider_x = pw->panner.slider_x; rep.slider_y = pw->panner.slider_y; rep.slider_width = pw->panner.slider_width; rep.slider_height = pw->panner.slider_height; rep.canvas_width = pw->panner.canvas_width; rep.canvas_height = pw->panner.canvas_height; - XtCallCallbackList (gw, pw->panner.report_callbacks, (XtPointer) &rep); + XtCallCallbackList(gw, pw->panner.report_callbacks, (XtPointer)&rep); } } -/* ARGSUSED */ -static void ActionSet (gw, event, params, num_params) - Widget gw; - XEvent *event; /* unused */ - String *params; - Cardinal *num_params; +/*ARGSUSED*/ +static void +ActionSet(Widget gw, XEvent *event, String *params, Cardinal *num_params) { - PannerWidget pw = (PannerWidget) gw; - Boolean rb; + PannerWidget pw = (PannerWidget)gw; + Bool rb; if (*num_params < 2 || - XmuCompareISOLatin1 (params[0], "rubberband") != 0) { - XBell (XtDisplay(gw), 0); + XmuCompareISOLatin1(params[0], "rubberband") != 0) { + XBell(XtDisplay(gw), 0); return; } - if (XmuCompareISOLatin1 (params[1], "on") == 0) { - rb = TRUE; - } else if (XmuCompareISOLatin1 (params[1], "off") == 0) { - rb = FALSE; - } else if (XmuCompareISOLatin1 (params[1], "toggle") == 0) { + if (XmuCompareISOLatin1(params[1], "on") == 0) + rb = True; + else if (XmuCompareISOLatin1(params[1], "off") == 0) + rb = False; + else if (XmuCompareISOLatin1(params[1], "toggle") == 0) rb = !pw->panner.rubber_band; - } else { - XBell (XtDisplay(gw), 0); + else { + XBell(XtDisplay(gw), 0); return; } if (rb != pw->panner.rubber_band) { Arg args[1]; - XtSetArg (args[0], XtNrubberBand, rb); - XtSetValues (gw, args, (Cardinal) 1); + + XtSetArg(args[0], XtNrubberBand, rb); + XtSetValues(gw, args, 1); } } diff --git a/src/Porthole.c b/src/Porthole.c index bab271c..afe8b47 100644 --- a/src/Porthole.c +++ b/src/Porthole.c @@ -28,314 +28,324 @@ in this Software without prior written authorization from The Open Group. * This widget is a trivial clipping widget. It is typically used with a * panner or scrollbar to navigate. */ +/* $XFree86: xc/lib/Xaw/Porthole.c,v 1.7 2001/12/14 19:54:41 dawes Exp $ */ #include <X11/IntrinsicP.h> -#include <X11/StringDefs.h> /* get XtN and XtC defines */ -#include <X11/Xaw/XawInit.h> /* get Xaw initialize stuff */ -#include <X11/Xaw/PortholeP.h> /* get porthole structs */ -#include <X11/Xmu/Misc.h> /* for MAX */ - +#include <X11/StringDefs.h> +#include <X11/Xmu/Misc.h> +#include <X11/Xaw/PortholeP.h> +#include <X11/Xaw/XawInit.h> +#include "Private.h" /* - * resources for the porthole + * Class Methods */ -static XtResource resources[] = { -#define poff(field) XtOffsetOf(PortholeRec, porthole.field) - { XtNreportCallback, XtCReportCallback, XtRCallback, sizeof(XtPointer), - poff(report_callbacks), XtRCallback, (XtPointer) NULL }, -#undef poff -}; +static void XawPortholeChangeManaged(Widget); +static XtGeometryResult XawPortholeGeometryManager(Widget, XtWidgetGeometry*, + XtWidgetGeometry*); +static XtGeometryResult XawPortholeQueryGeometry(Widget, XtWidgetGeometry*, + XtWidgetGeometry*); +static void XawPortholeRealize(Widget, Mask*, XSetWindowAttributes*); +static void XawPortholeResize(Widget); +/* + * Prototypes + */ +static Widget find_child(PortholeWidget); +static void layout_child(PortholeWidget, Widget, XtWidgetGeometry*, + Position*, Position*, Dimension*, Dimension*); +static void SendReport(PortholeWidget, unsigned int); /* - * widget class methods used below + * Initialization */ -static void Realize(); /* set gravity and upcall */ -static void Resize(); /* report new size */ -static XtGeometryResult GeometryManager(); /* deal with child requests */ -static void ChangeManaged(); /* somebody added a new widget */ -static XtGeometryResult QueryGeometry(); /* say how big would like to be */ +#define offset(field) XtOffsetOf(PortholeRec, porthole.field) +static XtResource resources[] = { + { + XtNreportCallback, + XtCReportCallback, + XtRCallback, + sizeof(XtPointer), + offset(report_callbacks), + XtRCallback, + NULL + }, +}; +#undef offset +#define Superclass (&compositeClassRec) PortholeClassRec portholeClassRec = { - { /* core fields */ - /* superclass */ (WidgetClass) &compositeClassRec, - /* class_name */ "Porthole", - /* widget_size */ sizeof(PortholeRec), - /* class_initialize */ XawInitializeWidgetSet, - /* class_part_initialize */ NULL, - /* class_inited */ FALSE, - /* initialize */ NULL, - /* initialize_hook */ NULL, - /* realize */ Realize, - /* actions */ NULL, - /* num_actions */ 0, - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure */ TRUE, - /* compress_enterleave */ TRUE, - /* visible_interest */ FALSE, - /* destroy */ NULL, - /* resize */ Resize, - /* expose */ NULL, - /* set_values */ NULL, - /* set_values_hook */ NULL, - /* set_values_almost */ XtInheritSetValuesAlmost, - /* get_values_hook */ NULL, - /* accept_focus */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ NULL, - /* query_geometry */ QueryGeometry, - /* display_accelerator */ XtInheritDisplayAccelerator, - /* extension */ NULL + /* core */ + { + (WidgetClass)Superclass, /* superclass */ + "Porthole", /* class_name */ + sizeof(PortholeRec), /* widget_size */ + XawInitializeWidgetSet, /* class_initialize */ + NULL, /* class_part_initialize */ + False, /* class_inited */ + NULL, /* initialize */ + NULL, /* initialize_hook */ + XawPortholeRealize, /* realize */ + NULL, /* actions */ + 0, /* num_actions */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + True, /* compress_motion */ + True, /* compress_exposure */ + True, /* compress_enterleave */ + False, /* visible_interest */ + NULL, /* destroy */ + XawPortholeResize, /* resize */ + NULL, /* expose */ + NULL, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + NULL, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + NULL, /* tm_table */ + XawPortholeQueryGeometry, /* query_geometry */ + XtInheritDisplayAccelerator, /* display_accelerator */ + NULL, /* extension */ }, - { /* composite fields */ - /* geometry_manager */ GeometryManager, - /* change_managed */ ChangeManaged, - /* insert_child */ XtInheritInsertChild, - /* delete_child */ XtInheritDeleteChild, - /* extension */ NULL + /* composite */ + { + XawPortholeGeometryManager, /* geometry_manager */ + XawPortholeChangeManaged, /* change_managed */ + XtInheritInsertChild, /* insert_child */ + XtInheritDeleteChild, /* delete_child */ + NULL, /* extension */ + }, + { /* porthole */ + NULL, /* extension */ }, - { /* porthole fields */ - /* ignore */ 0 - } }; -WidgetClass portholeWidgetClass = (WidgetClass) &portholeClassRec; - +WidgetClass portholeWidgetClass = (WidgetClass)&portholeClassRec; -/***************************************************************************** - * * - * utility routines * - * * - *****************************************************************************/ - -static Widget find_child (pw) - PortholeWidget pw; +/* + * Implementation + */ +static Widget +find_child(PortholeWidget pw) { Widget *children; - int i; + unsigned int i; /* * Find the managed child on which we should operate. Ignore multiple - * managed children. + * managed children */ for (i = 0, children = pw->composite.children; - i < pw->composite.num_children; i++, children++) { - if (XtIsManaged(*children)) return *children; - } + i < pw->composite.num_children; i++, children++) + if (XtIsManaged(*children)) + return (*children); - return (Widget) NULL; + return (NULL); } -static void SendReport (pw, changed) - PortholeWidget pw; - unsigned int changed; +static void +SendReport(PortholeWidget pw, unsigned int changed) { - Widget child = find_child (pw); + Widget child = find_child(pw); if (pw->porthole.report_callbacks && child) { XawPannerReport prep; prep.changed = changed; - prep.slider_x = -child->core.x; /* porthole is "inner" */ - prep.slider_y = -child->core.y; /* child is outer since it is larger */ - prep.slider_width = pw->core.width; - prep.slider_height = pw->core.height; - prep.canvas_width = child->core.width; - prep.canvas_height = child->core.height; - XtCallCallbackList ((Widget)pw, pw->porthole.report_callbacks, - (XtPointer) &prep); + prep.slider_x = -XtX(child); /* porthole is "inner" */ + prep.slider_y = -XtY(child); /* child is outer since it is larger */ + prep.slider_width = XtWidth(pw); + prep.slider_height = XtHeight(pw); + prep.canvas_width = XtWidth(child); + prep.canvas_height = XtHeight(child); + XtCallCallbackList((Widget)pw, pw->porthole.report_callbacks, + (XtPointer)&prep); } } - -static void layout_child (pw, child, geomp, xp, yp, widthp, heightp) - PortholeWidget pw; - Widget child; - XtWidgetGeometry *geomp; - Position *xp, *yp; - Dimension *widthp, *heightp; +static void +layout_child(PortholeWidget pw, Widget child, XtWidgetGeometry *geomp, + Position *xp, Position *yp, Dimension *widthp, Dimension *heightp) { Position minx, miny; - *xp = child->core.x; /* default to current values */ - *yp = child->core.y; - *widthp = child->core.width; - *heightp = child->core.height; + *xp = XtX(child); /* default to current values */ + *yp = XtY(child); + *widthp = XtWidth(child); + *heightp = XtHeight(child); if (geomp) { /* mix in any requested changes */ - if (geomp->request_mode & CWX) *xp = geomp->x; - if (geomp->request_mode & CWY) *yp = geomp->y; - if (geomp->request_mode & CWWidth) *widthp = geomp->width; - if (geomp->request_mode & CWHeight) *heightp = geomp->height; + if (geomp->request_mode & CWX) + *xp = geomp->x; + if (geomp->request_mode & CWY) + *yp = geomp->y; + if (geomp->request_mode & CWWidth) + *widthp = geomp->width; + if (geomp->request_mode & CWHeight) + *heightp = geomp->height; } /* * Make sure that the child is at least as large as the porthole; there - * is no maximum size. + * is no maximum size */ - if (*widthp < pw->core.width) *widthp = pw->core.width; - if (*heightp < pw->core.height) *heightp = pw->core.height; + if (*widthp < XtWidth(pw)) *widthp = XtWidth(pw); + if (*heightp < XtHeight(pw)) *heightp = XtHeight(pw); /* * Make sure that the child is still on the screen. Note that this must - * be done *after* the size computation so that we know where to put it. + * be done *after* the size computation so that we know where to put it */ - minx = ((Position) pw->core.width) - ((Position) *widthp); - miny = ((Position) pw->core.height) - ((Position) *heightp); - - if (*xp < minx) *xp = minx; /* keep at lower right corner */ - if (*yp < miny) *yp = miny; - - if (*xp > 0) *xp = 0; /* keep at upper left corner */ - if (*yp > 0) *yp = 0; + minx = (Position)XtWidth(pw) - (Position)*widthp; + miny = (Position)XtHeight(pw) - (Position)*heightp; + + if (*xp < minx) + *xp = minx; + if (*yp < miny) + *yp = miny; + + if (*xp > 0) + *xp = 0; + if (*yp > 0) + *yp = 0; } - - -/***************************************************************************** - * * - * Porthole Widget Class Methods * - * * - *****************************************************************************/ - - -static void Realize (gw, valueMask, attributes) - Widget gw; - Mask *valueMask; - XSetWindowAttributes *attributes; +static void +XawPortholeRealize(Widget gw, Mask *valueMask, XSetWindowAttributes *attr) { - attributes->bit_gravity = NorthWestGravity; + attr->bit_gravity = NorthWestGravity; *valueMask |= CWBitGravity; - if (gw->core.width < 1) gw->core.width = 1; - if (gw->core.height < 1) gw->core.height = 1; + if (XtWidth(gw) < 1) + XtWidth(gw) = 1; + if (XtHeight(gw) < 1) + XtHeight(gw) = 1; (*portholeWidgetClass->core_class.superclass->core_class.realize) - (gw, valueMask, attributes); + (gw, valueMask, attr); } - -static void Resize (gw) - Widget gw; +static void +XawPortholeResize(Widget gw) { - PortholeWidget pw = (PortholeWidget) gw; - Widget child = find_child (pw); + PortholeWidget pw = (PortholeWidget)gw; + Widget child = find_child(pw); /* * If we have a child, we need to make sure that it is at least as big - * as we are and in the right place. + * as we are and in the right place */ if (child) { Position x, y; Dimension width, height; - layout_child (pw, child, (XtWidgetGeometry *)NULL, - &x, &y, &width, &height); - XtConfigureWidget (child, x, y, width, height, (Dimension) 0); + layout_child(pw, child, NULL, &x, &y, &width, &height); + XtConfigureWidget(child, x, y, width, height, 0); } - SendReport (pw, (unsigned int) (XawPRCanvasWidth | XawPRCanvasHeight)); + SendReport(pw, XawPRCanvasWidth | XawPRCanvasHeight); } - -static XtGeometryResult QueryGeometry (gw, intended, preferred) - Widget gw; - XtWidgetGeometry *intended, *preferred; +static XtGeometryResult +XawPortholeQueryGeometry(Widget gw, XtWidgetGeometry *intended, + XtWidgetGeometry *preferred) { - PortholeWidget pw = (PortholeWidget) gw; - Widget child = find_child (pw); + PortholeWidget pw = (PortholeWidget)gw; + Widget child = find_child(pw); if (child) { #define SIZEONLY (CWWidth | CWHeight) preferred->request_mode = SIZEONLY; - preferred->width = child->core.width; - preferred->height = child->core.height; + preferred->width = XtWidth(child); + preferred->height = XtHeight(child); - if (((intended->request_mode & SIZEONLY) == SIZEONLY) && + if ((intended->request_mode & SIZEONLY) == SIZEONLY && intended->width == preferred->width && intended->height == preferred->height) - return XtGeometryYes; - else if (preferred->width == pw->core.width && - preferred->height == pw->core.height) - return XtGeometryNo; - else - return XtGeometryAlmost; + return (XtGeometryYes); + else if (preferred->width == XtWidth(pw) && + preferred->height == XtHeight(pw)) + return (XtGeometryNo); + + return (XtGeometryAlmost); #undef SIZEONLY - } - return XtGeometryNo; -} + } + return (XtGeometryNo); +} -static XtGeometryResult GeometryManager (w, req, reply) - Widget w; - XtWidgetGeometry *req, *reply; +static XtGeometryResult +XawPortholeGeometryManager(Widget w, XtWidgetGeometry *req, + XtWidgetGeometry *reply) { PortholeWidget pw = (PortholeWidget) w->core.parent; - Widget child = find_child (pw); - Boolean okay = TRUE; + Widget child = find_child(pw); + Bool okay = True; - if (child != w) return XtGeometryNo; /* unknown child */ + if (child != w) + return (XtGeometryNo); *reply = *req; /* assume we'll grant everything */ if ((req->request_mode & CWBorderWidth) && req->border_width != 0) { - reply->border_width = 0; /* require border width of 0 */ - okay = FALSE; + reply->border_width = 0; + okay = False; } - layout_child (pw, child, req, &reply->x, &reply->y, - &reply->width, &reply->height); + layout_child(pw, child, req, &reply->x, &reply->y, + &reply->width, &reply->height); - if ((req->request_mode & CWX) && req->x != reply->x) okay = FALSE; - if ((req->request_mode & CWY) && req->x != reply->x) okay = FALSE; + if ((req->request_mode & CWX) && req->x != reply->x) + okay = False; + if ((req->request_mode & CWY) && req->x != reply->x) + okay = False; if ((req->request_mode & CWWidth) && req->width != reply->width) - okay = FALSE; + okay = False; if ((req->request_mode & CWHeight) && req->height != reply->height) - okay = FALSE; - + okay = False; /* * If we failed on anything, simply return without touching widget */ - if (!okay) return XtGeometryAlmost; + if (!okay) + return (XtGeometryAlmost); /* * If not just doing a query, update widget and send report. Note that * we will often set fields that weren't requested because we want to keep - * the child visible. + * the child visible */ if (!(req->request_mode & XtCWQueryOnly)) { unsigned int changed = 0; - if (child->core.x != reply->x) { + if (XtX(child) != reply->x) { changed |= XawPRSliderX; - child->core.x = reply->x; + XtX(child) = reply->x; } - if (child->core.y != reply->y) { + if (XtY(child) != reply->y) { changed |= XawPRSliderY; - child->core.y = reply->y; + XtY(child) = reply->y; } - if (child->core.width != reply->width) { + if (XtWidth(child) != reply->width) { changed |= XawPRSliderWidth; - child->core.width = reply->width; + XtWidth(child) = reply->width; } - if (child->core.height != reply->height) { + if (XtHeight(child) != reply->height) { changed |= XawPRSliderHeight; - child->core.height = reply->height; + XtHeight(child) = reply->height; } - if (changed) SendReport (pw, changed); + if (changed) + SendReport(pw, changed); } - return XtGeometryYes; /* success! */ + return (XtGeometryYes); /* success! */ } - -static void ChangeManaged (gw) - Widget gw; +static void +XawPortholeChangeManaged(Widget gw) { - PortholeWidget pw = (PortholeWidget) gw; + PortholeWidget pw = (PortholeWidget)gw; Widget child = find_child (pw); /* ignore extra children */ if (child) { @@ -343,23 +353,23 @@ static void ChangeManaged (gw) XtWidgetGeometry geom, retgeom; geom.request_mode = 0; - if (pw->core.width == 0) { - geom.width = child->core.width; + if (XtWidth(pw) == 0) { + geom.width = XtWidth(child); geom.request_mode |= CWWidth; } - if (pw->core.height == 0) { - geom.height = child->core.height; + if (XtHeight(pw) == 0) { + geom.height = XtHeight(child); geom.request_mode |= CWHeight; } if (geom.request_mode && - XtMakeGeometryRequest (gw, &geom, &retgeom) == XtGeometryAlmost) { - (void) XtMakeGeometryRequest (gw, &retgeom, (XtWidgetGeometry *)NULL); - } + XtMakeGeometryRequest (gw, &geom, &retgeom) + == XtGeometryAlmost) + (void)XtMakeGeometryRequest(gw, &retgeom, NULL); } - XtResizeWidget (child, Max (child->core.width, pw->core.width), - Max (child->core.height, pw->core.height), 0); + XtResizeWidget(child, Max(XtWidth(child), XtWidth(pw)), + Max(XtHeight(child), XtHeight(pw)), 0); - SendReport (pw, (unsigned int) XawPRAll); + SendReport(pw, XawPRAll); } } diff --git a/src/Repeater.c b/src/Repeater.c index a530615..6c89a1e 100644 --- a/src/Repeater.c +++ b/src/Repeater.c @@ -27,248 +27,271 @@ in this Software without prior written authorization from The Open Group. * * This widget is used for press-and-hold style buttons. */ +/* $XFree86: xc/lib/Xaw/Repeater.c,v 1.7 2001/12/14 19:54:41 dawes Exp $ */ #include <X11/IntrinsicP.h> -#include <X11/StringDefs.h> /* for XtN and XtC defines */ -#include <X11/Xaw/XawInit.h> /* for XawInitializeWidgetSet() */ -#include <X11/Xaw/RepeaterP.h> /* us */ - -static void tic(); /* clock timeout */ +#include <X11/StringDefs.h> +#include <X11/Xaw/RepeaterP.h> +#include <X11/Xaw/XawInit.h> #define DO_CALLBACK(rw) \ - XtCallCallbackList ((Widget) rw, rw->command.callbacks, (XtPointer)NULL) - +XtCallCallbackList((Widget)rw, rw->command.callbacks, NULL) -#define ADD_TIMEOUT(rw,delay) \ - XtAppAddTimeOut (XtWidgetToApplicationContext ((Widget) rw), \ - (unsigned long) delay, tic, (XtPointer) rw) +#define ADD_TIMEOUT(rw, delay) \ +XtAppAddTimeOut(XtWidgetToApplicationContext((Widget)rw), \ + delay, tic, (XtPointer)rw) #define CLEAR_TIMEOUT(rw) \ - if ((rw)->repeater.timer) { \ - XtRemoveTimeOut ((rw)->repeater.timer); \ - (rw)->repeater.timer = 0; \ - } +if ((rw)->repeater.timer) { \ + XtRemoveTimeOut((rw)->repeater.timer); \ + (rw)->repeater.timer = 0; \ +} +/* + * Class Methods + */ +static void XawRepeaterInitialize(Widget, Widget, ArgList, Cardinal*); +static void XawRepeaterDestroy(Widget); +static Boolean XawRepeaterSetValues(Widget, Widget, Widget, + ArgList, Cardinal*); /* - * Translations to give user interface of press-notify...-release_or_leave + * Prototypes */ -static char defaultTranslations[] = - "<EnterWindow>: highlight() \n\ - <LeaveWindow>: unhighlight() \n\ - <Btn1Down>: set() start() \n\ - <Btn1Up>: stop() unset() "; +static void tic(XtPointer, XtIntervalId*); +/* + * Actions + */ +static void ActionStart(Widget, XEvent*, String*, Cardinal*); +static void ActionStop(Widget, XEvent*, String*, Cardinal*); /* - * Actions added by this widget + * Initialization */ -static void ActionStart(), ActionStop(); +static char defaultTranslations[] = +"<Enter>:" "highlight()\n" +"<Leave>:" "unhighlight()\n" +"<Btn1Down>:" "set() start()\n" +"<Btn1Up>:" "stop() unset()\n" +; static XtActionsRec actions[] = { - { "start", ActionStart }, /* trigger timers */ - { "stop", ActionStop }, /* clear timers */ + {"start", ActionStart}, + {"stop", ActionStop}, }; - -/* - * New resources added by this widget - */ +#define offset(field) XtOffsetOf(RepeaterRec, repeater.field) static XtResource resources[] = { -#define off(field) XtOffsetOf(RepeaterRec, repeater.field) - { XtNdecay, XtCDecay, XtRInt, sizeof (int), - off(decay), XtRImmediate, (XtPointer) REP_DEF_DECAY }, - { XtNinitialDelay, XtCDelay, XtRInt, sizeof (int), - off(initial_delay), XtRImmediate, (XtPointer) REP_DEF_INITIAL_DELAY }, - { XtNminimumDelay, XtCMinimumDelay, XtRInt, sizeof (int), - off(minimum_delay), XtRImmediate, (XtPointer) REP_DEF_MINIMUM_DELAY }, - { XtNrepeatDelay, XtCDelay, XtRInt, sizeof (int), - off(repeat_delay), XtRImmediate, (XtPointer) REP_DEF_REPEAT_DELAY }, - { XtNflash, XtCBoolean, XtRBoolean, sizeof (Boolean), - off(flash), XtRImmediate, (XtPointer) FALSE }, - { XtNstartCallback, XtCStartCallback, XtRCallback, sizeof (XtPointer), - off(start_callbacks), XtRImmediate, (XtPointer) NULL }, - { XtNstopCallback, XtCStopCallback, XtRCallback, sizeof (XtPointer), - off(stop_callbacks), XtRImmediate, (XtPointer) NULL }, -#undef off + { + XtNdecay, + XtCDecay, + XtRInt, + sizeof(int), + offset(decay), + XtRImmediate, + (XtPointer)REP_DEF_DECAY + }, + { + XtNinitialDelay, + XtCDelay, + XtRInt, + sizeof(int), + offset(initial_delay), + XtRImmediate, + (XtPointer)REP_DEF_INITIAL_DELAY + }, + { + XtNminimumDelay, + XtCMinimumDelay, + XtRInt, + sizeof(int), + offset(minimum_delay), + XtRImmediate, + (XtPointer)REP_DEF_MINIMUM_DELAY + }, + { + XtNrepeatDelay, + XtCDelay, + XtRInt, + sizeof(int), + offset(repeat_delay), + XtRImmediate, + (XtPointer)REP_DEF_REPEAT_DELAY + }, + { + XtNflash, + XtCBoolean, + XtRBoolean, + sizeof(Boolean), + offset(flash), + XtRImmediate, + (XtPointer)False + }, + { + XtNstartCallback, + XtCStartCallback, + XtRCallback, + sizeof(XtPointer), + offset(start_callbacks), + XtRImmediate, + NULL + }, + { + XtNstopCallback, + XtCStopCallback, + XtRCallback, + sizeof(XtPointer), + offset(stop_callbacks), + XtRImmediate, + NULL + }, }; +#undef offset - -/* - * Class Methods - */ - -static void Initialize(); /* setup private data */ -static void Destroy(); /* clear timers */ -static Boolean SetValues(); /* set resources */ - +#define Superclass (&commandClassRec) RepeaterClassRec repeaterClassRec = { - { /* core fields */ - /* superclass */ (WidgetClass) &commandClassRec, - /* class_name */ "Repeater", - /* widget_size */ sizeof(RepeaterRec), - /* class_initialize */ XawInitializeWidgetSet, - /* class_part_initialize */ NULL, - /* class_inited */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* realize */ XtInheritRealize, - /* actions */ actions, - /* num_actions */ XtNumber(actions), - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure */ TRUE, - /* compress_enterleave */ TRUE, - /* visible_interest */ FALSE, - /* destroy */ Destroy, - /* resize */ XtInheritResize, - /* expose */ XtInheritExpose, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* set_values_almost */ XtInheritSetValuesAlmost, - /* get_values_hook */ NULL, - /* accept_focus */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ defaultTranslations, - /* query_geometry */ XtInheritQueryGeometry, - /* display_accelerator */ XtInheritDisplayAccelerator, - /* extension */ NULL + /* core */ + { + (WidgetClass)Superclass, /* superclass */ + "Repeater", /* class_name */ + sizeof(RepeaterRec), /* widget_size */ + XawInitializeWidgetSet, /* class_initialize */ + NULL, /* class_part_initialize */ + False, /* class_inited */ + XawRepeaterInitialize, /* initialize */ + NULL, /* initialize_hook */ + XtInheritRealize, /* realize */ + actions, /* actions */ + XtNumber(actions), /* num_actions */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + True, /* compress_motion */ + True, /* compress_exposure */ + True, /* compress_enterleave */ + False, /* visible_interest */ + XawRepeaterDestroy, /* destroy */ + XtInheritResize, /* resize */ + XtInheritExpose, /* expose */ + XawRepeaterSetValues, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + NULL, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + defaultTranslations, /* tm_table */ + XtInheritQueryGeometry, /* query_geometry */ + XtInheritDisplayAccelerator, /* display_accelerator */ + NULL, /* extension */ + }, + /* simple */ + { + XtInheritChangeSensitive, /* change_sensitive */ }, - { /* simple fields */ - /* change_sensitive */ XtInheritChangeSensitive + /* label */ + { + NULL, /* extension */ }, - { /* label fields */ - /* ignore */ 0 + /* command */ + { + NULL, /* extension */ }, - { /* command fields */ - /* ignore */ 0 + /* repeater */ + { + NULL, /* extension */ }, - { /* repeater fields */ - /* ignore */ 0 - } }; WidgetClass repeaterWidgetClass = (WidgetClass) &repeaterClassRec; -/***************************************************************************** - * * - * repeater utility routines * - * * - *****************************************************************************/ - -/* ARGSUSED */ -static void tic (client_data, id) - XtPointer client_data; - XtIntervalId *id; +/* + * Implementation + */ +/*ARGSUSED*/ +static void +tic(XtPointer client_data, XtIntervalId *id) { - RepeaterWidget rw = (RepeaterWidget) client_data; + RepeaterWidget rw = (RepeaterWidget)client_data; rw->repeater.timer = 0; /* timer is removed */ if (rw->repeater.flash) { - XtExposeProc expose; - expose = repeaterWidgetClass->core_class.superclass->core_class.expose; - XClearWindow (XtDisplay((Widget) rw), XtWindow((Widget) rw)); - rw->command.set = FALSE; - (*expose) ((Widget) rw, (XEvent *) NULL, (Region) NULL); - XClearWindow (XtDisplay((Widget) rw), XtWindow((Widget) rw)); - rw->command.set = TRUE; - (*expose) ((Widget) rw, (XEvent *) NULL, (Region) NULL); + Widget w = (Widget)rw; + + XClearWindow(XtDisplay(w), XtWindow(w)); + XtCallActionProc(w, "reset", NULL, NULL, 0); + XClearWindow(XtDisplay(w), XtWindow(w)); + XtCallActionProc(w, "set", NULL, NULL, 0); } - DO_CALLBACK (rw); + DO_CALLBACK(rw); - rw->repeater.timer = ADD_TIMEOUT (rw, rw->repeater.next_delay); + rw->repeater.timer = ADD_TIMEOUT(rw, rw->repeater.next_delay); - /* decrement delay time, but clamp */ if (rw->repeater.decay) { rw->repeater.next_delay -= rw->repeater.decay; if (rw->repeater.next_delay < rw->repeater.minimum_delay) - rw->repeater.next_delay = rw->repeater.minimum_delay; + rw->repeater.next_delay = rw->repeater.minimum_delay; } } - -/***************************************************************************** - * * - * repeater class methods * - * * - *****************************************************************************/ - -/* ARGSUSED */ -static void Initialize (greq, gnew, args, num_args) - Widget greq, gnew; - ArgList args; - Cardinal *num_args; +/*ARGSUSED*/ +static void +XawRepeaterInitialize(Widget greq, Widget gnew, + ArgList args, Cardinal *num_args) { - RepeaterWidget new = (RepeaterWidget) gnew; + RepeaterWidget cnew = (RepeaterWidget)gnew; - if (new->repeater.minimum_delay < 0) new->repeater.minimum_delay = 0; - new->repeater.timer = (XtIntervalId) 0; + if (cnew->repeater.minimum_delay < 0) + cnew->repeater.minimum_delay = 0; + cnew->repeater.timer = 0; } -static void Destroy (gw) - Widget gw; +static void +XawRepeaterDestroy(Widget gw) { - CLEAR_TIMEOUT ((RepeaterWidget) gw); + CLEAR_TIMEOUT((RepeaterWidget)gw); } -/* ARGSUSED */ -static Boolean SetValues (gcur, greq, gnew, args, num_args) - Widget gcur, greq, gnew; - ArgList args; - Cardinal *num_args; +/*ARGSUSED*/ +static Boolean +XawRepeaterSetValues(Widget gcur, Widget greq, Widget gnew, + ArgList args, Cardinal *num_args) { - RepeaterWidget cur = (RepeaterWidget) gcur; - RepeaterWidget new = (RepeaterWidget) gnew; - Boolean redisplay = FALSE; + RepeaterWidget cur = (RepeaterWidget)gcur; + RepeaterWidget cnew = (RepeaterWidget)gnew; - if (cur->repeater.minimum_delay != new->repeater.minimum_delay) { - if (new->repeater.next_delay < new->repeater.minimum_delay) - new->repeater.next_delay = new->repeater.minimum_delay; + if (cur->repeater.minimum_delay != cnew->repeater.minimum_delay) { + if (cnew->repeater.next_delay < cnew->repeater.minimum_delay) + cnew->repeater.next_delay = cnew->repeater.minimum_delay; } - return redisplay; + return (False); } -/***************************************************************************** - * * - * repeater action procs * - * * - *****************************************************************************/ - -/* ARGSUSED */ -static void ActionStart (gw, event, params, num_params) - Widget gw; - XEvent *event; - String *params; /* unused */ - Cardinal *num_params; /* unused */ +/*ARGSUSED*/ +static void +ActionStart(Widget gw, XEvent *event, String *params, Cardinal *num_params) { - RepeaterWidget rw = (RepeaterWidget) gw; + RepeaterWidget rw = (RepeaterWidget)gw; - CLEAR_TIMEOUT (rw); + CLEAR_TIMEOUT(rw); if (rw->repeater.start_callbacks) - XtCallCallbackList (gw, rw->repeater.start_callbacks, (XtPointer)NULL); + XtCallCallbackList(gw, rw->repeater.start_callbacks, NULL); - DO_CALLBACK (rw); - rw->repeater.timer = ADD_TIMEOUT (rw, rw->repeater.initial_delay); + DO_CALLBACK(rw); + rw->repeater.timer = ADD_TIMEOUT(rw, rw->repeater.initial_delay); rw->repeater.next_delay = rw->repeater.repeat_delay; } - -/* ARGSUSED */ -static void ActionStop (gw, event, params, num_params) - Widget gw; - XEvent *event; - String *params; /* unused */ - Cardinal *num_params; /* unused */ +/*ARGSUSED*/ +static void +ActionStop(Widget gw, XEvent *event, String *params, Cardinal *num_params) { - RepeaterWidget rw = (RepeaterWidget) gw; + RepeaterWidget rw = (RepeaterWidget)gw; - CLEAR_TIMEOUT ((RepeaterWidget) gw); + CLEAR_TIMEOUT((RepeaterWidget)gw); if (rw->repeater.stop_callbacks) - XtCallCallbackList (gw, rw->repeater.stop_callbacks, (XtPointer)NULL); + XtCallCallbackList(gw, rw->repeater.stop_callbacks, NULL); } - diff --git a/src/Scrollbar.c b/src/Scrollbar.c index 0493211..b56a2f8 100644 --- a/src/Scrollbar.c +++ b/src/Scrollbar.c @@ -46,89 +46,226 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ - -/* ScrollBar.c */ -/* created by weissman, Mon Jul 7 13:20:03 1986 */ -/* converted by swick, Thu Aug 27 1987 */ +/* $XFree86: xc/lib/Xaw/Scrollbar.c,v 1.13 2001/12/14 19:54:42 dawes Exp $ */ #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> - -#include <X11/Xaw/XawInit.h> -#include <X11/Xaw/ScrollbarP.h> #include <X11/Xmu/Drawing.h> +#include <X11/Xaw/ScrollbarP.h> +#include <X11/Xaw/XawInit.h> +#include "Private.h" + +#define NoButton -1 +#define PICKLENGTH(widget, x, y) \ +(((widget)->scrollbar.orientation == XtorientHorizontal) ? (x) : (y)) -/* Private definitions. */ +/* + * Class Methods + */ +static void XawScrollbarClassInitialize(void); +static void XawScrollbarDestroy(Widget); +static void XawScrollbarInitialize(Widget, Widget, ArgList, Cardinal*_args); +static void XawScrollbarRealize(Widget, Mask*, XSetWindowAttributes*); +static void XawScrollbarRedisplay(Widget, XEvent*, Region); +static void XawScrollbarResize(Widget); +static Boolean XawScrollbarSetValues(Widget, Widget, Widget, + ArgList, Cardinal*); +/* + * Prototypes + */ +static Boolean CompareEvents(XEvent*, XEvent*); +static void CreateGC(Widget); +static float FloatInRange(float, float, float); +static float FractionLoc(ScrollbarWidget, int, int); +static void ExtractPosition(XEvent*, Position*, Position*); +static int InRange(int, int, int); +static void FillArea(ScrollbarWidget, int, int, int); +static Bool LookAhead(Widget, XEvent*); +static void PaintThumb(ScrollbarWidget); +static Bool PeekNotifyEvent(Display*, XEvent*, char*); +static void SetDimensions(ScrollbarWidget); + +/* + * Actions + */ +static void EndScroll(Widget, XEvent*, String*, Cardinal*); +static void MoveThumb(Widget, XEvent*, String*, Cardinal*); +static void NotifyScroll(Widget, XEvent*, String*, Cardinal*); +static void NotifyThumb(Widget, XEvent*, String*, Cardinal*); +static void StartScroll(Widget, XEvent*, String*, Cardinal*); + +/* + * Initialization + */ static char defaultTranslations[] = - "<Btn1Down>: StartScroll(Forward) \n\ - <Btn2Down>: StartScroll(Continuous) MoveThumb() NotifyThumb() \n\ - <Btn3Down>: StartScroll(Backward) \n\ - <Btn2Motion>: MoveThumb() NotifyThumb() \n\ - <BtnUp>: NotifyScroll(Proportional) EndScroll()"; - -#ifdef bogusScrollKeys - /* examples */ - "<KeyPress>f: StartScroll(Forward) NotifyScroll(FullLength) EndScroll()" - "<KeyPress>b: StartScroll(Backward) NotifyScroll(FullLength) EndScroll()" -#endif +"<Btn1Down>:" "StartScroll(Forward)\n" +"<Btn2Down>:" "StartScroll(Continuous) MoveThumb() NotifyThumb()\n" +"<Btn3Down>:" "StartScroll(Backward)\n" +"<Btn2Motion>:" "MoveThumb() NotifyThumb()\n" +"<BtnUp>:" "NotifyScroll(Proportional) EndScroll()\n"; static float floatZero = 0.0; #define Offset(field) XtOffsetOf(ScrollbarRec, field) static XtResource resources[] = { - {XtNlength, XtCLength, XtRDimension, sizeof(Dimension), - Offset(scrollbar.length), XtRImmediate, (XtPointer) 1}, - {XtNthickness, XtCThickness, XtRDimension, sizeof(Dimension), - Offset(scrollbar.thickness), XtRImmediate, (XtPointer) 14}, - {XtNorientation, XtCOrientation, XtROrientation, sizeof(XtOrientation), - Offset(scrollbar.orientation), XtRImmediate, (XtPointer) XtorientVertical}, - {XtNscrollProc, XtCCallback, XtRCallback, sizeof(XtPointer), - Offset(scrollbar.scrollProc), XtRCallback, NULL}, - {XtNthumbProc, XtCCallback, XtRCallback, sizeof(XtPointer), - Offset(scrollbar.thumbProc), XtRCallback, NULL}, - {XtNjumpProc, XtCCallback, XtRCallback, sizeof(XtPointer), - Offset(scrollbar.jumpProc), XtRCallback, NULL}, - {XtNthumb, XtCThumb, XtRBitmap, sizeof(Pixmap), - Offset(scrollbar.thumb), XtRImmediate, (XtPointer) XtUnspecifiedPixmap}, - {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), - Offset(scrollbar.foreground), XtRString, XtDefaultForeground}, - {XtNshown, XtCShown, XtRFloat, sizeof(float), - Offset(scrollbar.shown), XtRFloat, (XtPointer)&floatZero}, - {XtNtopOfThumb, XtCTopOfThumb, XtRFloat, sizeof(float), - Offset(scrollbar.top), XtRFloat, (XtPointer)&floatZero}, - {XtNscrollVCursor, XtCCursor, XtRCursor, sizeof(Cursor), - Offset(scrollbar.verCursor), XtRString, "sb_v_double_arrow"}, - {XtNscrollHCursor, XtCCursor, XtRCursor, sizeof(Cursor), - Offset(scrollbar.horCursor), XtRString, "sb_h_double_arrow"}, - {XtNscrollUCursor, XtCCursor, XtRCursor, sizeof(Cursor), - Offset(scrollbar.upCursor), XtRString, "sb_up_arrow"}, - {XtNscrollDCursor, XtCCursor, XtRCursor, sizeof(Cursor), - Offset(scrollbar.downCursor), XtRString, "sb_down_arrow"}, - {XtNscrollLCursor, XtCCursor, XtRCursor, sizeof(Cursor), - Offset(scrollbar.leftCursor), XtRString, "sb_left_arrow"}, - {XtNscrollRCursor, XtCCursor, XtRCursor, sizeof(Cursor), - Offset(scrollbar.rightCursor), XtRString, "sb_right_arrow"}, - {XtNminimumThumb, XtCMinimumThumb, XtRDimension, sizeof(Dimension), - Offset(scrollbar.min_thumb), XtRImmediate, (XtPointer) 7}, + { + XtNlength, + XtCLength, + XtRDimension, + sizeof(Dimension), + Offset(scrollbar.length), + XtRImmediate, + (XtPointer)1 + }, + { + XtNthickness, + XtCThickness, + XtRDimension, + sizeof(Dimension), + Offset(scrollbar.thickness), + XtRImmediate, + (XtPointer)14 + }, + { + XtNorientation, + XtCOrientation, + XtROrientation, + sizeof(XtOrientation), + Offset(scrollbar.orientation), + XtRImmediate, + (XtPointer)XtorientVertical + }, + { + XtNscrollProc, + XtCCallback, + XtRCallback, + sizeof(XtPointer), + Offset(scrollbar.scrollProc), + XtRCallback, + NULL + }, + { + XtNthumbProc, + XtCCallback, + XtRCallback, + sizeof(XtPointer), + Offset(scrollbar.thumbProc), + XtRCallback, + NULL + }, + { + XtNjumpProc, + XtCCallback, + XtRCallback, + sizeof(XtPointer), + Offset(scrollbar.jumpProc), + XtRCallback, + NULL + }, + { + XtNthumb, + XtCThumb, + XtRBitmap, + sizeof(Pixmap), + Offset(scrollbar.thumb), + XtRImmediate, + (XtPointer)XtUnspecifiedPixmap + }, + { + XtNforeground, + XtCForeground, + XtRPixel, + sizeof(Pixel), + Offset(scrollbar.foreground), + XtRString, + XtDefaultForeground + }, + { + XtNshown, + XtCShown, + XtRFloat, + sizeof(float), + Offset(scrollbar.shown), + XtRFloat, + (XtPointer)&floatZero + }, + { + XtNtopOfThumb, + XtCTopOfThumb, + XtRFloat, + sizeof(float), + Offset(scrollbar.top), + XtRFloat, + (XtPointer)&floatZero + }, + { + XtNscrollVCursor, + XtCCursor, + XtRCursor, + sizeof(Cursor), + Offset(scrollbar.verCursor), + XtRString, + "sb_v_double_arrow" + }, + { + XtNscrollHCursor, + XtCCursor, + XtRCursor, + sizeof(Cursor), + Offset(scrollbar.horCursor), + XtRString, + "sb_h_double_arrow" + }, + { + XtNscrollUCursor, + XtCCursor, + XtRCursor, + sizeof(Cursor), + Offset(scrollbar.upCursor), + XtRString, + "sb_up_arrow" + }, + { + XtNscrollDCursor, + XtCCursor, + XtRCursor, + sizeof(Cursor), + Offset(scrollbar.downCursor), + XtRString, + "sb_down_arrow" + }, + { + XtNscrollLCursor, + XtCCursor, + XtRCursor, + sizeof(Cursor), + Offset(scrollbar.leftCursor), + XtRString, + "sb_left_arrow" + }, + { + XtNscrollRCursor, + XtCCursor, + XtRCursor, + sizeof(Cursor), + Offset(scrollbar.rightCursor), + XtRString, + "sb_right_arrow" + }, + { + XtNminimumThumb, + XtCMinimumThumb, + XtRDimension, + sizeof(Dimension), + Offset(scrollbar.min_thumb), + XtRImmediate, + (XtPointer)7 + }, }; #undef Offset -static void ClassInitialize(); -static void Initialize(); -static void Destroy(); -static void Realize(); -static void Resize(); -static void Redisplay(); -static Boolean SetValues(); - -static void StartScroll(); -static void MoveThumb(); -static void NotifyThumb(); -static void NotifyScroll(); -static void EndScroll(); - static XtActionsRec actions[] = { {"StartScroll", StartScroll}, {"MoveThumb", MoveThumb}, @@ -137,141 +274,142 @@ static XtActionsRec actions[] = { {"EndScroll", EndScroll}, }; - +#define Superclass (&simpleClassRec) ScrollbarClassRec scrollbarClassRec = { - { /* core fields */ - /* superclass */ (WidgetClass) &simpleClassRec, - /* class_name */ "Scrollbar", - /* size */ sizeof(ScrollbarRec), - /* class_initialize */ ClassInitialize, - /* class_part_init */ NULL, - /* class_inited */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* realize */ Realize, - /* actions */ actions, - /* num_actions */ XtNumber(actions), - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure*/ TRUE, - /* compress_enterleave*/ TRUE, - /* visible_interest */ FALSE, - /* destroy */ Destroy, - /* resize */ Resize, - /* expose */ Redisplay, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* set_values_almost */ XtInheritSetValuesAlmost, - /* get_values_hook */ NULL, - /* accept_focus */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ defaultTranslations, - /* query_geometry */ XtInheritQueryGeometry, - /* display_accelerator*/ XtInheritDisplayAccelerator, - /* extension */ NULL + /* core */ + { + (WidgetClass)&simpleClassRec, /* superclass */ + "Scrollbar", /* class_name */ + sizeof(ScrollbarRec), /* widget_size */ + XawScrollbarClassInitialize, /* class_initialize */ + NULL, /* class_part_init */ + False, /* class_inited */ + XawScrollbarInitialize, /* initialize */ + NULL, /* initialize_hook */ + XawScrollbarRealize, /* realize */ + actions, /* actions */ + XtNumber(actions), /* num_actions */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + True, /* compress_motion */ + True, /* compress_exposure */ + True, /* compress_enterleave */ + False, /* visible_interest */ + XawScrollbarDestroy, /* destroy */ + XawScrollbarResize, /* resize */ + XawScrollbarRedisplay, /* expose */ + XawScrollbarSetValues, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + NULL, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + defaultTranslations, /* tm_table */ + XtInheritQueryGeometry, /* query_geometry */ + XtInheritDisplayAccelerator, /* display_accelerator */ + NULL, /* extension */ }, - { /* simple fields */ - /* change_sensitive */ XtInheritChangeSensitive + /* simple */ + { + XtInheritChangeSensitive, /* change_sensitive */ + }, + /* scrollbar */ + { + NULL, /* extension */ }, - { /* scrollbar fields */ - /* ignore */ 0 - } - }; WidgetClass scrollbarWidgetClass = (WidgetClass)&scrollbarClassRec; -#define NoButton -1 -#define PICKLENGTH(widget, x, y) \ - ((widget->scrollbar.orientation == XtorientHorizontal) ? x : y) -#define MIN(x,y) ((x) < (y) ? (x) : (y)) -#define MAX(x,y) ((x) > (y) ? (x) : (y)) - -static void ClassInitialize() +/* + * Implementation + */ +static void +XawScrollbarClassInitialize(void) { XawInitializeWidgetSet(); - XtAddConverter( XtRString, XtROrientation, XmuCvtStringToOrientation, - NULL, (Cardinal)0 ); + XtAddConverter(XtRString, XtROrientation, XmuCvtStringToOrientation, + NULL, 0); + XtSetTypeConverter(XtROrientation, XtRString, XmuCvtOrientationToString, + NULL, 0, XtCacheNone, NULL); } /* * Make sure the first number is within the range specified by the other * two numbers. */ - -static int InRange(num, small, big) -int num, small, big; +static int +InRange(int num, int small, int big) { - return (num < small) ? small : ((num > big) ? big : num); + return ((num < small) ? small : ((num > big) ? big : num)); } /* - * Same as above, but for floating numbers. + * Same as above, but for floating numbers */ - -static float FloatInRange(num, small, big) -float num, small, big; +static float +FloatInRange(float num, float small, float big) { - return (num < small) ? small : ((num > big) ? big : num); + return ((num < small) ? small : ((num > big) ? big : num)); } - -/* Fill the area specified by top and bottom with the given pattern. */ -static float FractionLoc(w, x, y) - ScrollbarWidget w; - int x, y; +/* Fill the area specified by top and bottom with the given pattern */ +static float +FractionLoc(ScrollbarWidget w, int x, int y) { float result; - result = PICKLENGTH(w, x / (float)w->core.width, - y / (float)w->core.height); - return FloatInRange(result, 0.0, 1.0); -} + result = PICKLENGTH(w, x / (float)XtWidth(w), y / (float)XtHeight(w)); + return (FloatInRange(result, 0.0, 1.0)); +} -static void FillArea(w, top, bottom, thumb) - ScrollbarWidget w; - Position top, bottom; - int thumb; +static void +FillArea(ScrollbarWidget w, int top, int bottom, int thumb) { - Dimension length = bottom-top; + Dimension length; - if (bottom < 0) return; + top = XawMax(1, top); + if (w->scrollbar.orientation == XtorientHorizontal) + bottom = XawMin(bottom, XtWidth(w) - 1); + else + bottom = XawMin(bottom, XtHeight(w) - 1); + + if (bottom <= top) + return; + + length = bottom - top; switch(thumb) { /* Fill the new Thumb location */ - case 1: - if (w->scrollbar.orientation == XtorientHorizontal) - XFillRectangle(XtDisplay(w), XtWindow(w), - w->scrollbar.gc, top, 1, length, - w->core.height-2); - - else XFillRectangle(XtDisplay(w), XtWindow(w), w->scrollbar.gc, - 1, top, w->core.width-2, length); - - break; + case 1: + if (w->scrollbar.orientation == XtorientHorizontal) + XFillRectangle(XtDisplay(w), XtWindow(w), w->scrollbar.gc, + top, 1, length, XtHeight(w) - 2); + else + XFillRectangle(XtDisplay(w), XtWindow(w), w->scrollbar.gc, + 1, top, XtWidth(w) - 2, length); + break; /* Clear the old Thumb location */ - case 0: - if (w->scrollbar.orientation == XtorientHorizontal) - XClearArea(XtDisplay(w), XtWindow(w), top, 1, - length, w->core.height-2, FALSE); - - else XClearArea(XtDisplay(w), XtWindow(w), 1, - top, w->core.width-2, length, FALSE); - - } + case 0: + if (w->scrollbar.orientation == XtorientHorizontal) + XClearArea(XtDisplay(w), XtWindow(w), + top, 1, length, XtHeight(w) - 2, False); + else + XClearArea(XtDisplay(w), XtWindow(w), + 1, top, XtWidth(w) - 2, length, False); + break; + } } /* Paint the thumb in the area specified by w->top and w->shown. The old area is erased. The painting and erasing is done cleverly so that no flickering will occur. */ - -static void PaintThumb( w ) - ScrollbarWidget w; +static void +PaintThumb(ScrollbarWidget w) { Position oldtop, oldbot, newtop, newbot; @@ -280,76 +418,62 @@ static void PaintThumb( w ) newtop = w->scrollbar.length * w->scrollbar.top; newbot = newtop + (int)(w->scrollbar.length * w->scrollbar.shown); if (newbot < newtop + (int)w->scrollbar.min_thumb) - newbot = newtop + w->scrollbar.min_thumb; + newbot = newtop + w->scrollbar.min_thumb; w->scrollbar.topLoc = newtop; w->scrollbar.shownLength = newbot - newtop; if (XtIsRealized((Widget)w)) { - if (newtop < oldtop) FillArea(w, newtop, MIN(newbot, oldtop), 1); - if (newtop > oldtop) FillArea(w, oldtop, MIN(newtop, oldbot), 0); - if (newbot < oldbot) FillArea(w, MAX(newbot, oldtop), oldbot, 0); - if (newbot > oldbot) FillArea(w, MAX(newtop, oldbot), newbot, 1); + if (newtop < oldtop) + FillArea(w, newtop, XawMin(newbot, oldtop), 1); + if (newtop > oldtop) + FillArea(w, oldtop, XawMin(newtop, oldbot), 0); + if (newbot < oldbot) + FillArea(w, XawMax(newbot, oldtop), oldbot, 0); + if (newbot > oldbot) + FillArea(w, XawMax(newtop, oldbot), newbot, 1); } } - -static void SetDimensions(w) - ScrollbarWidget w; +static void +SetDimensions(ScrollbarWidget w) { if (w->scrollbar.orientation == XtorientVertical) { - w->scrollbar.length = w->core.height; - w->scrollbar.thickness = w->core.width; + w->scrollbar.length = XtHeight(w); + w->scrollbar.thickness = XtWidth(w); } else { - w->scrollbar.length = w->core.width; - w->scrollbar.thickness = w->core.height; + w->scrollbar.length = XtWidth(w); + w->scrollbar.thickness = XtHeight(w); } } -/* Function Name: Destroy - * Description: Called as the scrollbar is going away... - * Arguments: w - the scrollbar. - * Returns: nonw - */ - static void -Destroy(w) -Widget w; +XawScrollbarDestroy(Widget w) { - ScrollbarWidget sbw = (ScrollbarWidget) w; + ScrollbarWidget sbw = (ScrollbarWidget)w; XtReleaseGC(w, sbw->scrollbar.gc); } -/* Function Name: CreateGC - * Description: Creates the GC. - * Arguments: w - the scrollbar widget. - * Returns: none. - */ - static void -CreateGC(w) -Widget w; +CreateGC(Widget w) { - ScrollbarWidget sbw = (ScrollbarWidget) w; + ScrollbarWidget sbw = (ScrollbarWidget)w; XGCValues gcValues; XtGCMask mask; unsigned int depth = 1; - if (sbw->scrollbar.thumb == XtUnspecifiedPixmap) { - sbw->scrollbar.thumb = XmuCreateStippledPixmap (XtScreen(w), - (Pixel) 1, (Pixel) 0, - depth); - } + if (sbw->scrollbar.thumb == XtUnspecifiedPixmap) + sbw->scrollbar.thumb = XmuCreateStippledPixmap(XtScreen(w), + (Pixel)1, (Pixel)0, + depth); else if (sbw->scrollbar.thumb != None) { Window root; int x, y; unsigned int width, height, bw; - if (XGetGeometry(XtDisplay(w), sbw->scrollbar.thumb, &root, &x, &y, - &width, &height, &bw, &depth) == 0) { - XtAppError(XtWidgetToApplicationContext(w), - "Scrollbar Widget: Could not get geometry of thumb pixmap."); - } + + XGetGeometry(XtDisplay(w), sbw->scrollbar.thumb, &root, &x, &y, + &width, &height, &bw, &depth); } gcValues.foreground = sbw->scrollbar.foreground; @@ -368,175 +492,160 @@ Widget w; mask |= GCFillStyle | GCTile; } } - sbw->scrollbar.gc = XtGetGC( w, mask, &gcValues); + sbw->scrollbar.gc = XtGetGC(w, mask, &gcValues); } /* ARGSUSED */ -static void Initialize( request, new, args, num_args ) - Widget request; /* what the client asked for */ - Widget new; /* what we're going to give him */ - ArgList args; - Cardinal *num_args; +static void +XawScrollbarInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - ScrollbarWidget w = (ScrollbarWidget) new; + ScrollbarWidget w = (ScrollbarWidget)cnew; - CreateGC(new); + CreateGC(cnew); - if (w->core.width == 0) - w->core.width = (w->scrollbar.orientation == XtorientVertical) - ? w->scrollbar.thickness : w->scrollbar.length; + if (XtWidth(w) == 0) + XtWidth(w) = w->scrollbar.orientation == XtorientVertical ? + w->scrollbar.thickness : w->scrollbar.length; - if (w->core.height == 0) - w->core.height = (w->scrollbar.orientation == XtorientHorizontal) - ? w->scrollbar.thickness : w->scrollbar.length; + if (XtHeight(w) == 0) + XtHeight(w) = w->scrollbar.orientation == XtorientHorizontal ? + w->scrollbar.thickness : w->scrollbar.length; - SetDimensions( w ); + SetDimensions(w); w->scrollbar.direction = 0; w->scrollbar.topLoc = 0; w->scrollbar.shownLength = w->scrollbar.min_thumb; } -static void Realize( gw, valueMask, attributes ) - Widget gw; - Mask *valueMask; - XSetWindowAttributes *attributes; +static void +XawScrollbarRealize(Widget gw, Mask *valueMask, + XSetWindowAttributes *attributes) { - ScrollbarWidget w = (ScrollbarWidget) gw; + ScrollbarWidget w = (ScrollbarWidget)gw; - w->scrollbar.inactiveCursor = - (w->scrollbar.orientation == XtorientVertical) - ? w->scrollbar.verCursor - : w->scrollbar.horCursor; + w->scrollbar.inactiveCursor = w->scrollbar.orientation == XtorientVertical ? + w->scrollbar.verCursor : w->scrollbar.horCursor; XtVaSetValues(gw, XtNcursor, w->scrollbar.inactiveCursor, NULL); /* - * The Simple widget actually stuffs the value in the valuemask. + * The Simple widget actually stuffs the value in the valuemask */ - (*scrollbarWidgetClass->core_class.superclass->core_class.realize) (gw, valueMask, attributes); } -/* ARGSUSED */ +/*ARGSUSED*/ static Boolean -SetValues( current, request, desired, args, num_args ) -Widget current, /* what I am */ - request, /* what he wants me to be */ - desired; /* what I will become */ -ArgList args; -Cardinal *num_args; +XawScrollbarSetValues(Widget current, Widget request, Widget desired, + ArgList args, Cardinal *num_args) { - ScrollbarWidget w = (ScrollbarWidget) current; - ScrollbarWidget dw = (ScrollbarWidget) desired; - Boolean redraw = FALSE; - -/* - * If these values are outside the acceptable range ignore them... - */ + ScrollbarWidget w = (ScrollbarWidget)current; + ScrollbarWidget dw = (ScrollbarWidget)desired; + Boolean redraw = False; + /* + * If these values are outside the acceptable range ignore them... + */ if (dw->scrollbar.top < 0.0 || dw->scrollbar.top > 1.0) - dw->scrollbar.top = w->scrollbar.top; + dw->scrollbar.top = w->scrollbar.top; if (dw->scrollbar.shown < 0.0 || dw->scrollbar.shown > 1.0) - dw->scrollbar.shown = w->scrollbar.shown; + dw->scrollbar.shown = w->scrollbar.shown; -/* - * Change colors and stuff... - */ - - if ( XtIsRealized (desired) ) { - if ( (w->scrollbar.foreground != dw->scrollbar.foreground) || - (w->core.background_pixel != dw->core.background_pixel) || - (w->scrollbar.thumb != dw->scrollbar.thumb) ) - { + if (XtIsRealized (desired)) { + if (w->scrollbar.foreground != dw->scrollbar.foreground || + w->core.background_pixel != dw->core.background_pixel || + w->scrollbar.thumb != dw->scrollbar.thumb) { XtReleaseGC((Widget)dw, w->scrollbar.gc); - CreateGC( (Widget) dw); - redraw = TRUE; + CreateGC((Widget)dw); + redraw = True; } if (w->scrollbar.top != dw->scrollbar.top || w->scrollbar.shown != dw->scrollbar.shown) - redraw = TRUE; + redraw = True; } - return( redraw ); + return (redraw); } -static void Resize( gw ) - Widget gw; +static void +XawScrollbarResize(Widget gw) { /* ForgetGravity has taken care of background, but thumb may * have to move as a result of the new size. */ - SetDimensions( (ScrollbarWidget)gw ); - Redisplay( gw, (XEvent*)NULL, (Region)NULL ); + SetDimensions((ScrollbarWidget)gw); + XawScrollbarRedisplay(gw, NULL, NULL); } - -/* ARGSUSED */ -static void Redisplay( gw, event, region ) - Widget gw; - XEvent *event; - Region region; +/*ARGSUSED*/ +static void +XawScrollbarRedisplay(Widget gw, XEvent *event, Region region) { - ScrollbarWidget w = (ScrollbarWidget) gw; + ScrollbarWidget w = (ScrollbarWidget)gw; int x, y; unsigned int width, height; + if (Superclass->core_class.expose) + (*Superclass->core_class.expose)(gw, event, region); + if (w->scrollbar.orientation == XtorientHorizontal) { x = w->scrollbar.topLoc; y = 1; width = w->scrollbar.shownLength; - height = w->core.height - 2; - } else { + height = XtHeight(w) - 2; + } + else { x = 1; y = w->scrollbar.topLoc; - width = w->core.width - 2; + width = XtWidth(w) - 2; height = w->scrollbar.shownLength; } - if ( (region == NULL) || - (XRectInRegion(region, x, y, width, height) != RectangleOut) ) { - /* Forces entire thumb to be painted. */ + if (region == NULL || + XRectInRegion(region, x, y, width, height) != RectangleOut) { + /* Forces entire thumb to be painted */ w->scrollbar.topLoc = -(w->scrollbar.length + 1); - PaintThumb( w ); + PaintThumb(w); } } - -/* ARGSUSED */ -static void StartScroll( gw, event, params, num_params ) - Widget gw; - XEvent *event; - String *params; /* direction: Back|Forward|Smooth */ - Cardinal *num_params; /* we only support 1 */ +/*ARGSUSED*/ +static void +StartScroll(Widget gw, XEvent *event, String *params, Cardinal *num_params) { - ScrollbarWidget w = (ScrollbarWidget) gw; + ScrollbarWidget w = (ScrollbarWidget)gw; Cursor cursor; char direction; - if (w->scrollbar.direction != 0) return; /* if we're already scrolling */ - if (*num_params > 0) direction = *params[0]; - else direction = 'C'; + if (w->scrollbar.direction != 0) /* if we're already scrolling */ + return; + if (*num_params > 0) + direction = *params[0]; + else + direction = 'C'; w->scrollbar.direction = direction; - switch( direction ) { + switch(direction) { case 'B': - case 'b': cursor = (w->scrollbar.orientation == XtorientVertical) - ? w->scrollbar.downCursor - : w->scrollbar.rightCursor; break; - + case 'b': + cursor = w->scrollbar.orientation == XtorientVertical ? + w->scrollbar.downCursor : w->scrollbar.rightCursor; + break; case 'F': - case 'f': cursor = (w->scrollbar.orientation == XtorientVertical) - ? w->scrollbar.upCursor - : w->scrollbar.leftCursor; break; - + case 'f': + cursor = w->scrollbar.orientation == XtorientVertical ? + w->scrollbar.upCursor : w->scrollbar.leftCursor; + break; case 'C': - case 'c': cursor = (w->scrollbar.orientation == XtorientVertical) - ? w->scrollbar.rightCursor - : w->scrollbar.upCursor; break; - - default: return; /* invalid invocation */ + case 'c': + cursor = w->scrollbar.orientation == XtorientVertical ? + w->scrollbar.rightCursor : w->scrollbar.upCursor; + break; + default: + return; /* invalid invocation */ } XtVaSetValues(gw, XtNcursor, cursor, NULL); @@ -544,63 +653,63 @@ static void StartScroll( gw, event, params, num_params ) XFlush(XtDisplay(w)); } - -static Boolean CompareEvents( oldEvent, newEvent ) - XEvent *oldEvent, *newEvent; +static Boolean +CompareEvents(XEvent *oldEvent, XEvent *newEvent) { -#define Check(field) if (newEvent->field != oldEvent->field) return False; +#define Check(field) if (newEvent->field != oldEvent->field) return (False) Check(xany.display); Check(xany.type); Check(xany.window); - switch( newEvent->type ) { - case MotionNotify: - Check(xmotion.state); break; - case ButtonPress: - case ButtonRelease: - Check(xbutton.state); - Check(xbutton.button); break; - case KeyPress: - case KeyRelease: - Check(xkey.state); - Check(xkey.keycode); break; - case EnterNotify: - case LeaveNotify: - Check(xcrossing.mode); - Check(xcrossing.detail); - Check(xcrossing.state); break; + switch(newEvent->type) { + case MotionNotify: + Check(xmotion.state); + break; + case ButtonPress: + case ButtonRelease: + Check(xbutton.state); + Check(xbutton.button); + break; + case KeyPress: + case KeyRelease: + Check(xkey.state); + Check(xkey.keycode); + break; + case EnterNotify: + case LeaveNotify: + Check(xcrossing.mode); + Check(xcrossing.detail); + Check(xcrossing.state); + break; } #undef Check - return True; + return (True); } struct EventData { - XEvent *oldEvent; - int count; + XEvent *oldEvent; + int count; }; -static Bool PeekNotifyEvent( dpy, event, args ) - Display *dpy; - XEvent *event; - char *args; +static Bool +PeekNotifyEvent(Display *dpy, XEvent *event, char *args) { struct EventData *eventData = (struct EventData*)args; - return ((++eventData->count == QLength(dpy)) /* since PeekIf blocks */ + return (++eventData->count == QLength(dpy) /* since PeekIf blocks */ || CompareEvents(event, eventData->oldEvent)); } - -static Boolean LookAhead( w, event ) - Widget w; - XEvent *event; +static Bool +LookAhead(Widget w, XEvent *event) { XEvent newEvent; struct EventData eventData; - if (QLength(XtDisplay(w)) == 0) return False; + if (QLength(XtDisplay(w)) == 0) + return (False); eventData.count = 0; eventData.oldEvent = event; @@ -608,169 +717,166 @@ static Boolean LookAhead( w, event ) XPeekIfEvent(XtDisplay(w), &newEvent, PeekNotifyEvent, (char*)&eventData); if (CompareEvents(event, &newEvent)) - return True; - else - return False; -} + return (True); + return (False); +} -static void ExtractPosition( event, x, y ) - XEvent *event; - Position *x, *y; /* RETURN */ +static void +ExtractPosition(XEvent *event, Position *x, Position *y) { - switch( event->type ) { - case MotionNotify: - *x = event->xmotion.x; *y = event->xmotion.y; break; - case ButtonPress: - case ButtonRelease: - *x = event->xbutton.x; *y = event->xbutton.y; break; - case KeyPress: - case KeyRelease: - *x = event->xkey.x; *y = event->xkey.y; break; - case EnterNotify: - case LeaveNotify: - *x = event->xcrossing.x; *y = event->xcrossing.y; break; - default: - *x = 0; *y = 0; + switch(event->type) { + case MotionNotify: + *x = event->xmotion.x; + *y = event->xmotion.y; + break; + case ButtonPress: + case ButtonRelease: + *x = event->xbutton.x; + *y = event->xbutton.y; + break; + case KeyPress: + case KeyRelease: + *x = event->xkey.x; + *y = event->xkey.y; + break; + case EnterNotify: + case LeaveNotify: + *x = event->xcrossing.x; + *y = event->xcrossing.y; + break; + default: + *x = 0; + *y = 0; + break; } } -static void NotifyScroll( gw, event, params, num_params ) - Widget gw; - XEvent *event; - String *params; /* style: Proportional|FullLength */ - Cardinal *num_params; /* we only support 1 */ +static void +NotifyScroll(Widget gw, XEvent *event, String *params, Cardinal *num_params) { - ScrollbarWidget w = (ScrollbarWidget) gw; - int call_data; + ScrollbarWidget w = (ScrollbarWidget)gw; + long call_data = 0; char style; Position x, y; - if (w->scrollbar.direction == 0) return; /* if no StartScroll */ - - if (LookAhead(gw, event)) return; + if (w->scrollbar.direction == 0) /* if no StartScroll */ + return; - if (*num_params > 0) style = *params[0]; - else style = 'P'; + if (LookAhead(gw, event)) + return; - switch( style ) { - case 'P': /* Proportional */ - case 'p': ExtractPosition( event, &x, &y ); - call_data = InRange( PICKLENGTH( w, x, y ), - 0, - (int) w->scrollbar.length); break; - - case 'F': /* FullLength */ - case 'f': call_data = w->scrollbar.length; break; + if (*num_params > 0) + style = *params[0]; + else + style = 'P'; + + switch(style) { + case 'P': /* Proportional */ + case 'p': + ExtractPosition(event, &x, &y); + call_data = InRange(PICKLENGTH(w, x, y), 0, (int)w->scrollbar.length); + break; + case 'F': /* FullLength */ + case 'f': + call_data = w->scrollbar.length; + break; } - switch( w->scrollbar.direction ) { - case 'B': - case 'b': call_data = -call_data; - /* fall through */ - case 'F': - case 'f': XtCallCallbacks( gw, XtNscrollProc, (XtPointer)call_data); - break; - - case 'C': + switch(w->scrollbar.direction) { + case 'B': + case 'b': + call_data = -call_data; + /*FALLTHROUGH*/ + case 'F': + case 'f': + XtCallCallbacks(gw, XtNscrollProc, (XtPointer)call_data); + break; + case 'C': case 'c': /* NotifyThumb has already called the thumbProc(s) */ - break; + break; } } -/* ARGSUSED */ -static void EndScroll(gw, event, params, num_params ) - Widget gw; - XEvent *event; /* unused */ - String *params; /* unused */ - Cardinal *num_params; /* unused */ +/*ARGSUSED*/ +static void +EndScroll(Widget gw, XEvent *event, String *params, Cardinal *num_params) { - ScrollbarWidget w = (ScrollbarWidget) gw; + ScrollbarWidget w = (ScrollbarWidget)gw; XtVaSetValues(gw, XtNcursor, w->scrollbar.inactiveCursor, NULL); - XFlush(XtDisplay(w)); /* make sure it get propogated. */ + XFlush(XtDisplay(w)); /* make sure it get propogated */ w->scrollbar.direction = 0; } - -/* ARGSUSED */ -static void MoveThumb( gw, event, params, num_params ) - Widget gw; - XEvent *event; - String *params; /* unused */ - Cardinal *num_params; /* unused */ +/*ARGSUSED*/ +static void +MoveThumb(Widget gw, XEvent *event, String *params, Cardinal *num_params) { - ScrollbarWidget w = (ScrollbarWidget) gw; + ScrollbarWidget w = (ScrollbarWidget)gw; Position x, y; - if (w->scrollbar.direction == 0) return; /* if no StartScroll */ + if (w->scrollbar.direction == 0) /* if no StartScroll */ + return; - if (LookAhead(gw, event)) return; + if (LookAhead(gw, event)) + return; - if (!event->xmotion.same_screen) return; + if (!event->xmotion.same_screen) + return; - ExtractPosition( event, &x, &y ); + ExtractPosition(event, &x, &y); w->scrollbar.top = FractionLoc(w, x, y); - PaintThumb(w); - XFlush(XtDisplay(w)); /* re-draw it before Notifying */ } - -/* ARGSUSED */ -static void NotifyThumb( gw, event, params, num_params ) - Widget gw; - XEvent *event; - String *params; /* unused */ - Cardinal *num_params; /* unused */ +/*ARGSUSED*/ +static void +NotifyThumb(Widget gw, XEvent *event, String *params, Cardinal *num_params) { - ScrollbarWidget w = (ScrollbarWidget) gw; + ScrollbarWidget w = (ScrollbarWidget)gw; + union { + XtPointer xtp; + float xtf; + } xtpf; - if (w->scrollbar.direction == 0) return; /* if no StartScroll */ + if (w->scrollbar.direction == 0) /* if no StartScroll */ + return; - if (LookAhead(gw, event)) return; + if (LookAhead(gw, event)) + return; /* thumbProc is not pretty, but is necessary for backwards compatibility on those architectures for which it work{s,ed}; the intent is to pass a (truncated) float by value. */ - XtCallCallbacks( gw, XtNthumbProc, *(XtPointer*)&w->scrollbar.top); - XtCallCallbacks( gw, XtNjumpProc, (XtPointer)&w->scrollbar.top); -} - + xtpf.xtf = w->scrollbar.top; + XtCallCallbacks(gw, XtNthumbProc, xtpf.xtp); + XtCallCallbacks(gw, XtNjumpProc, (XtPointer)&w->scrollbar.top); + PaintThumb(w); +} -/************************************************************ - * - * Public routines. - * - ************************************************************/ - +/* + * Public routines + */ /* Set the scroll bar to the given location. */ - -#if NeedFunctionPrototypes -void XawScrollbarSetThumb(Widget gw, +void +XawScrollbarSetThumb(Widget gw, #if NeedWidePrototypes - double top, double shown) + double top, double shown #else - float top, float shown) -#endif -#else -void XawScrollbarSetThumb( gw, top, shown ) -Widget gw; -float top, shown; + float top, float shown #endif + ) { ScrollbarWidget w = (ScrollbarWidget)gw; - if (w->scrollbar.direction == 'c') return; /* if still thumbing */ + if (w->scrollbar.direction == 'c') /* if still thumbing */ + return; - w->scrollbar.top = (top > 1.0) ? 1.0 : - (top >= 0.0) ? top : - w->scrollbar.top; + w->scrollbar.top = top > 1.0 ? 1.0 : top >= 0.0 ? top : w->scrollbar.top; - w->scrollbar.shown = (shown > 1.0) ? 1.0 : - (shown >= 0.0) ? shown : - w->scrollbar.shown; - - PaintThumb( w ); + w->scrollbar.shown = shown > 1.0 ? 1.0 : shown >= 0.0 ? + shown : w->scrollbar.shown; + PaintThumb(w); } diff --git a/src/Simple.c b/src/Simple.c index 32e6980..bee0d14 100644 --- a/src/Simple.c +++ b/src/Simple.c @@ -47,117 +47,237 @@ SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/Simple.c,v 1.17 2001/12/14 19:54:42 dawes Exp $ */ + #include <stdio.h> #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> -#include <X11/Xaw/XawInit.h> -#include <X11/Xaw/SimpleP.h> #include <X11/Xmu/Drawing.h> +#include <X11/Xmu/SysUtil.h> +#include <X11/Xaw/SimpleP.h> +#include <X11/Xaw/XawInit.h> +#include "Private.h" +#ifndef OLDXAW +#include <X11/Xaw/Tip.h> +#endif -#define offset(field) XtOffsetOf(SimpleRec, simple.field) +/* + * Class Methods + */ +static Bool ChangeSensitive(Widget); +static void XawSimpleClassInitialize(void); +static void XawSimpleClassPartInitialize(WidgetClass); +#ifndef OLDXAW +static void XawSimpleInitialize(Widget, Widget, ArgList, Cardinal*); +static void XawSimpleDestroy(Widget); +static void XawSimpleExpose(Widget, XEvent*, Region); +#endif +static void XawSimpleRealize(Widget, Mask*, XSetWindowAttributes*); +static Boolean XawSimpleSetValues(Widget, Widget, Widget, ArgList, Cardinal*); + +/* + * Prototypes + */ +static void ConvertCursor(Widget); + +/* + * Initialization + */ +#ifndef OLDXAW +static XtActionsRec actions[] = { + {"set-values", XawSetValuesAction}, + {"get-values", XawGetValuesAction}, + {"declare", XawDeclareAction}, + {"call-proc", XawCallProcAction}, +}; +#endif +#define offset(field) XtOffsetOf(SimpleRec, simple.field) static XtResource resources[] = { - {XtNcursor, XtCCursor, XtRCursor, sizeof(Cursor), - offset(cursor), XtRImmediate, (XtPointer) None}, - {XtNinsensitiveBorder, XtCInsensitive, XtRPixmap, sizeof(Pixmap), - offset(insensitive_border), XtRImmediate, (XtPointer) NULL}, - {XtNpointerColor, XtCForeground, XtRPixel, sizeof(Pixel), - offset(pointer_fg), XtRString, XtDefaultForeground}, - {XtNpointerColorBackground, XtCBackground, XtRPixel, sizeof(Pixel), - offset(pointer_bg), XtRString, XtDefaultBackground}, - {XtNcursorName, XtCCursor, XtRString, sizeof(String), - offset(cursor_name), XtRString, NULL}, - {XtNinternational, XtCInternational, XtRBoolean, sizeof(Boolean), - offset(international), XtRImmediate, (XtPointer) FALSE}, + { + XtNcursor, + XtCCursor, + XtRCursor, + sizeof(Cursor), + offset(cursor), + XtRImmediate, + (XtPointer)None + }, + { + XtNinsensitiveBorder, + XtCInsensitive, + XtRPixmap, + sizeof(Pixmap), + offset(insensitive_border), + XtRImmediate, + NULL + }, + { + XtNpointerColor, + XtCForeground, + XtRPixel, + sizeof(Pixel), + offset(pointer_fg), + XtRString, + XtDefaultForeground + }, + { + XtNpointerColorBackground, + XtCBackground, + XtRPixel, + sizeof(Pixel), + offset(pointer_bg), + XtRString, + XtDefaultBackground + }, + { + XtNcursorName, + XtCCursor, + XtRString, + sizeof(String), + offset(cursor_name), + XtRString, + NULL + }, + { + XtNinternational, + XtCInternational, + XtRBoolean, + sizeof(Boolean), + offset(international), + XtRImmediate, + (XtPointer)False + }, +#ifndef OLDXAW + { + XawNdisplayList, + XawCDisplayList, + XawRDisplayList, + sizeof(XawDisplayList*), + offset(display_list), + XtRImmediate, + NULL + }, + { + XtNtip, + XtCTip, + XtRString, + sizeof(String), + offset(tip), + XtRImmediate, + NULL + }, +#endif #undef offset }; -static void ClassPartInitialize(), ClassInitialize(),Realize(),ConvertCursor(); -static Boolean SetValues(), ChangeSensitive(); - SimpleClassRec simpleClassRec = { - { /* core fields */ - /* superclass */ (WidgetClass) &widgetClassRec, - /* class_name */ "Simple", - /* widget_size */ sizeof(SimpleRec), - /* class_initialize */ ClassInitialize, - /* class_part_initialize */ ClassPartInitialize, - /* class_inited */ FALSE, - /* initialize */ NULL, - /* initialize_hook */ NULL, - /* realize */ Realize, - /* actions */ NULL, - /* num_actions */ 0, - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure */ TRUE, - /* compress_enterleave */ TRUE, - /* visible_interest */ FALSE, - /* destroy */ NULL, - /* resize */ NULL, - /* expose */ NULL, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* set_values_almost */ XtInheritSetValuesAlmost, - /* get_values_hook */ NULL, - /* accept_focus */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ NULL, - /* query_geometry */ XtInheritQueryGeometry, - /* display_accelerator */ XtInheritDisplayAccelerator, - /* extension */ NULL + /* core */ + { + (WidgetClass)&widgetClassRec, /* superclass */ + "Simple", /* class_name */ + sizeof(SimpleRec), /* widget_size */ + XawSimpleClassInitialize, /* class_initialize */ + XawSimpleClassPartInitialize, /* class_part_initialize */ + False, /* class_inited */ +#ifndef OLDXAW + XawSimpleInitialize, /* initialize */ +#else + NULL, /* initialize */ +#endif + NULL, /* initialize_hook */ + XawSimpleRealize, /* realize */ +#ifndef OLDXAW + actions, /* actions */ + XtNumber(actions), /* num_actions */ +#else + NULL, /* actions */ + 0, /* num_actions */ +#endif + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + True, /* compress_motion */ + True, /* compress_exposure */ + True, /* compress_enterleave */ + False, /* visible_interest */ +#ifndef OLDXAW + XawSimpleDestroy, /* destroy */ +#else + NULL, /* destroy */ +#endif + NULL, /* resize */ +#ifndef OLDXAW + XawSimpleExpose, /* expose */ +#else + NULL, /* expose */ +#endif + XawSimpleSetValues, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + NULL, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + NULL, /* tm_table */ + XtInheritQueryGeometry, /* query_geometry */ + XtInheritDisplayAccelerator, /* display_accelerator */ + NULL, /* extension */ + }, + /* simple */ + { + ChangeSensitive, /* change_sensitive */ }, - { /* simple fields */ - /* change_sensitive */ ChangeSensitive - } }; WidgetClass simpleWidgetClass = (WidgetClass)&simpleClassRec; -static void ClassInitialize() +static void +XawSimpleClassInitialize(void) { static XtConvertArgRec convertArg[] = { - {XtWidgetBaseOffset, (XtPointer) XtOffsetOf(WidgetRec, core.screen), - sizeof(Screen *)}, - {XtResourceString, (XtPointer) XtNpointerColor, sizeof(Pixel)}, - {XtResourceString, (XtPointer) XtNpointerColorBackground, - sizeof(Pixel)}, - {XtWidgetBaseOffset, (XtPointer) XtOffsetOf(WidgetRec, core.colormap), - sizeof(Colormap)} + { + XtWidgetBaseOffset, + (XtPointer)XtOffsetOf(WidgetRec, core.screen), + sizeof(Screen *) + }, + { + XtResourceString, + (XtPointer)XtNpointerColor, + sizeof(Pixel) + }, + { + XtResourceString, + (XtPointer)XtNpointerColorBackground, + sizeof(Pixel) + }, + { + XtWidgetBaseOffset, + (XtPointer)XtOffsetOf(WidgetRec, core.colormap), + sizeof(Colormap) + }, }; XawInitializeWidgetSet(); - XtSetTypeConverter( XtRString, XtRColorCursor, XmuCvtStringToColorCursor, - convertArg, XtNumber(convertArg), - XtCacheByDisplay, (XtDestructor)NULL); + XtSetTypeConverter(XtRString, XtRColorCursor, XmuCvtStringToColorCursor, + convertArg, XtNumber(convertArg), XtCacheByDisplay, NULL); } -static void ClassPartInitialize(class) - WidgetClass class; +static void +XawSimpleClassPartInitialize(WidgetClass cclass) { - SimpleWidgetClass c = (SimpleWidgetClass) class; - SimpleWidgetClass super = (SimpleWidgetClass) c->core_class.superclass; + SimpleWidgetClass c = (SimpleWidgetClass)cclass; + SimpleWidgetClass super = (SimpleWidgetClass)c->core_class.superclass; if (c->simple_class.change_sensitive == NULL) { char buf[BUFSIZ]; - char* bufp; - int len; - char* fmt = "%s Widget: The Simple Widget class method 'change_sensitive' is undefined.\nA function must be defined or inherited."; - if ((len = strlen (fmt) + strlen (c->core_class.class_name)) < sizeof buf) - bufp = buf; - else - bufp = XtMalloc (len + 1); - if (bufp == NULL) { - bufp = buf; - strcpy (bufp, "The Simple Widget class method 'change_sensitive' is undefined.\nA function must be defined or inherited."); - } else - (void) sprintf(bufp, fmt, c->core_class.class_name); + (void)XmuSnprintf(buf, sizeof(buf), + "%s Widget: The Simple Widget class method " + "'change_sensitive' is undefined.\nA function " + "must be defined or inherited.", + c->core_class.class_name); XtWarning(buf); - if (bufp != buf) XtFree (bufp); c->simple_class.change_sensitive = ChangeSensitive; } @@ -165,13 +285,38 @@ static void ClassPartInitialize(class) c->simple_class.change_sensitive = super->simple_class.change_sensitive; } -static void Realize(w, valueMask, attributes) - Widget w; - Mask *valueMask; - XSetWindowAttributes *attributes; +#ifndef OLDXAW +/*ARGSUSED*/ +static void +XawSimpleInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) +{ + SimpleWidget simple = (SimpleWidget)cnew; + + if (simple->simple.tip) + simple->simple.tip = XtNewString(simple->simple.tip); +} + +static void +XawSimpleDestroy(Widget w) { - Pixmap border_pixmap; - if (!XtIsSensitive(w)) { + SimpleWidget simple = (SimpleWidget)w; + + if (simple->simple.tip) + XtFree((XtPointer)simple->simple.tip); +} +#endif + +static void +XawSimpleRealize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes) +{ +#ifndef OLDXAW + XawPixmap *pixmap; +#endif + Pixmap border_pixmap = CopyFromParent; + + if (!XtIsSensitive(w)) + { /* change border to gray; have to remember the old one, * so XtDestroyWidget deletes the proper one */ if (((SimpleWidget)w)->simple.insensitive_border == None) @@ -193,99 +338,153 @@ static void Realize(w, valueMask, attributes) if ((attributes->cursor = ((SimpleWidget)w)->simple.cursor) != None) *valueMask |= CWCursor; - XtCreateWindow( w, (unsigned int)InputOutput, (Visual *)CopyFromParent, - *valueMask, attributes ); + XtCreateWindow(w, InputOutput, (Visual *)CopyFromParent, + *valueMask, attributes); if (!XtIsSensitive(w)) w->core.border_pixmap = border_pixmap; + +#ifndef OLDXAW + if (w->core.background_pixmap > XtUnspecifiedPixmap) { + pixmap = XawPixmapFromXPixmap(w->core.background_pixmap, XtScreen(w), + w->core.colormap, w->core.depth); + if (pixmap && pixmap->mask) + XawReshapeWidget(w, pixmap); + } + + if (((SimpleWidget)w)->simple.tip) + XawTipEnable(w); +#endif } -/* Function Name: ConvertCursor - * Description: Converts a name to a new cursor. - * Arguments: w - the simple widget. - * Returns: none. +/* + * Function: + * ConvertCursor + * + * Parameters: + * w - simple widget + * + * Description: + * Converts a name to a new cursor. */ - static void -ConvertCursor(w) -Widget w; +ConvertCursor(Widget w) { SimpleWidget simple = (SimpleWidget) w; XrmValue from, to; - Cursor cursor; + Cursor cursor = None; if (simple->simple.cursor_name == NULL) return; - from.addr = (XPointer) simple->simple.cursor_name; - from.size = strlen((char *) from.addr) + 1; + from.addr = (XPointer)simple->simple.cursor_name; + from.size = strlen((char *)from.addr) + 1; to.size = sizeof(Cursor); - to.addr = (XPointer) &cursor; + to.addr = (XPointer)&cursor; - if (XtConvertAndStore(w, XtRString, &from, XtRColorCursor, &to)) { - if ( cursor != None) - simple->simple.cursor = cursor; - } - else { + if (XtConvertAndStore(w, XtRString, &from, XtRColorCursor, &to)) + simple->simple.cursor = cursor; + else XtAppErrorMsg(XtWidgetToApplicationContext(w), "convertFailed","ConvertCursor","XawError", "Simple: ConvertCursor failed.", - (String *)NULL, (Cardinal *)NULL); - } + NULL, NULL); } -/* ARGSUSED */ -static Boolean SetValues(current, request, new, args, num_args) - Widget current, request, new; - ArgList args; - Cardinal *num_args; +/*ARGSUSED*/ +static Boolean +XawSimpleSetValues(Widget current, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - SimpleWidget s_old = (SimpleWidget) current; - SimpleWidget s_new = (SimpleWidget) new; - Boolean new_cursor = FALSE; + SimpleWidget s_old = (SimpleWidget)current; + SimpleWidget s_new = (SimpleWidget)cnew; + Bool new_cursor = False; - /* this disables user changes after creation*/ + /* this disables user changes after creation */ s_new->simple.international = s_old->simple.international; - if ( XtIsSensitive(current) != XtIsSensitive(new) ) - (*((SimpleWidgetClass)XtClass(new))-> - simple_class.change_sensitive) ( new ); + if (XtIsSensitive(current) != XtIsSensitive(cnew)) + (*((SimpleWidgetClass)XtClass(cnew))->simple_class.change_sensitive) + (cnew); - if (s_old->simple.cursor != s_new->simple.cursor) { - new_cursor = TRUE; - } + if (s_old->simple.cursor != s_new->simple.cursor) + new_cursor = True; -/* - * We are not handling the string cursor_name correctly here. - */ + /* + * We are not handling the string cursor_name correctly here + */ + + if (s_old->simple.pointer_fg != s_new->simple.pointer_fg || + s_old->simple.pointer_bg != s_new->simple.pointer_bg || + s_old->simple.cursor_name != s_new->simple.cursor_name) { + ConvertCursor(cnew); + new_cursor = True; + } - if ( (s_old->simple.pointer_fg != s_new->simple.pointer_fg) || - (s_old->simple.pointer_bg != s_new->simple.pointer_bg) || - (s_old->simple.cursor_name != s_new->simple.cursor_name) ) { - ConvertCursor(new); - new_cursor = TRUE; + if (new_cursor && XtIsRealized(cnew)) { + if (s_new->simple.cursor != None) + XDefineCursor(XtDisplay(cnew), XtWindow(cnew), s_new->simple.cursor); + else + XUndefineCursor(XtDisplay(cnew), XtWindow(cnew)); + } + +#ifndef OLDXAW + if (s_old->core.background_pixmap != s_new->core.background_pixmap) { + XawPixmap *opix, *npix; + + opix = XawPixmapFromXPixmap(s_old->core.background_pixmap, + XtScreen(s_old), s_old->core.colormap, + s_old->core.depth); + npix = XawPixmapFromXPixmap(s_new->core.background_pixmap, + XtScreen(s_new), s_new->core.colormap, + s_new->core.depth); + if ((npix && npix->mask) || (opix && opix->mask)) + XawReshapeWidget(cnew, npix); } - if (new_cursor && XtIsRealized(new)) - XDefineCursor(XtDisplay(new), XtWindow(new), s_new->simple.cursor); + if (s_old->simple.tip != s_new->simple.tip) { + if (s_old->simple.tip) + XtFree((XtPointer)s_old->simple.tip); + if (s_new->simple.tip) + s_new->simple.tip = XtNewString(s_new->simple.tip); + } - return False; + if (s_old->simple.tip && !s_new->simple.tip) + XawTipDisable(cnew); + else if (!s_old->simple.tip && s_new->simple.tip) + XawTipEnable(cnew); + + if (s_old->simple.display_list != s_new->simple.display_list) + return (True); +#endif /* OLDXAW */ + + return (False); } +#ifndef OLDXAW +static void +XawSimpleExpose(Widget w, XEvent *event, Region region) +{ + SimpleWidget xaw = (SimpleWidget)w; -static Boolean ChangeSensitive(w) - Widget w; + if (xaw->simple.display_list) + XawRunDisplayList(w, xaw->simple.display_list, event, region); +} +#endif + +static Bool +ChangeSensitive(Widget w) { if (XtIsRealized(w)) { if (XtIsSensitive(w)) if (w->core.border_pixmap != XtUnspecifiedPixmap) - XSetWindowBorderPixmap( XtDisplay(w), XtWindow(w), - w->core.border_pixmap ); + XSetWindowBorderPixmap(XtDisplay(w), XtWindow(w), + w->core.border_pixmap); else - XSetWindowBorder( XtDisplay(w), XtWindow(w), - w->core.border_pixel ); + XSetWindowBorder(XtDisplay(w), XtWindow(w), + w->core.border_pixel); else { if (((SimpleWidget)w)->simple.insensitive_border == None) ((SimpleWidget)w)->simple.insensitive_border = @@ -293,10 +492,10 @@ static Boolean ChangeSensitive(w) w->core.border_pixel, w->core.background_pixel, w->core.depth); - XSetWindowBorderPixmap( XtDisplay(w), XtWindow(w), - ((SimpleWidget)w)-> - simple.insensitive_border ); + XSetWindowBorderPixmap(XtDisplay(w), XtWindow(w), + ((SimpleWidget)w)->simple.insensitive_border); } } - return False; + + return (False); } diff --git a/src/SimpleMenu.c b/src/SimpleMenu.c index 516e23f..037696c 100644 --- a/src/SimpleMenu.c +++ b/src/SimpleMenu.c @@ -24,6 +24,8 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/SimpleMenu.c,v 3.22 2001/12/14 19:54:42 dawes Exp $ */ + /* * SimpleMenu.c - Source code file for SimpleMenu widget. * @@ -37,527 +39,705 @@ in this Software without prior written authorization from The Open Group. #include <stdio.h> #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> - -#include <X11/Xaw/XawInit.h> -#include <X11/Xaw/SimpleMenP.h> -#include <X11/Xaw/SmeBSB.h> -#include <X11/Xaw/Cardinals.h> - #include <X11/Xmu/Initer.h> -#include <X11/Xmu/CharSet.h> - -#define streq(a, b) ( strcmp((a), (b)) == 0 ) +#include <X11/Xmu/SysUtil.h> +#include <X11/Xaw/Cardinals.h> +#include <X11/Xaw/SimpleMenP.h> +#include <X11/Xaw/SmeBSBP.h> +#include <X11/Xaw/XawInit.h> +#include "Private.h" -#define offset(field) XtOffsetOf(SimpleMenuRec, simple_menu.field) +#define streq(a, b) (strcmp((a), (b)) == 0) -static XtResource resources[] = { +#define ForAllChildren(smw, childP) \ +for ((childP) = (SmeObject *)(smw)->composite.children; \ + (childP) < (SmeObject *)((smw)->composite.children \ + + (smw)->composite.num_children); \ + (childP)++) -/* - * Label Resources. - */ - - {XtNlabel, XtCLabel, XtRString, sizeof(String), - offset(label_string), XtRString, NULL}, - {XtNlabelClass, XtCLabelClass, XtRPointer, sizeof(WidgetClass), - offset(label_class), XtRImmediate, (XtPointer) NULL}, +#ifndef OLDXAW +#define SMW_UNMAPPING 0x01 +#define SMW_POPLEFT 0x02 +#endif /* - * Layout Resources. + * Class Methods */ - - {XtNrowHeight, XtCRowHeight, XtRDimension, sizeof(Dimension), - offset(row_height), XtRImmediate, (XtPointer) 0}, - {XtNtopMargin, XtCVerticalMargins, XtRDimension, sizeof(Dimension), - offset(top_margin), XtRImmediate, (XtPointer) 0}, - {XtNbottomMargin, XtCVerticalMargins, XtRDimension, sizeof(Dimension), - offset(bottom_margin), XtRImmediate, (XtPointer) 0}, +static void XawSimpleMenuChangeManaged(Widget); +static void XawSimpleMenuClassInitialize(void); +static void XawSimpleMenuClassPartInitialize(WidgetClass); +static XtGeometryResult XawSimpleMenuGeometryManager(Widget, XtWidgetGeometry*, + XtWidgetGeometry*); +static void XawSimpleMenuInitialize(Widget, Widget, ArgList, Cardinal*); +static void XawSimpleMenuRealize(Widget, XtValueMask*, XSetWindowAttributes*); +static void XawSimpleMenuRedisplay(Widget, XEvent*, Region); +static void XawSimpleMenuResize(Widget); +static Boolean XawSimpleMenuSetValues(Widget, Widget, Widget, + ArgList, Cardinal*); +static Boolean XawSimpleMenuSetValuesHook(Widget, ArgList, Cardinal*); +#ifndef OLDXAW +static void PopupSubMenu(SimpleMenuWidget); +static void PopdownSubMenu(SimpleMenuWidget); +static void PopupCB(Widget, XtPointer, XtPointer); +#endif /* - * Misc. Resources + * Prototypes */ - - { XtNallowShellResize, XtCAllowShellResize, XtRBoolean, sizeof(Boolean), - XtOffsetOf(SimpleMenuRec, shell.allow_shell_resize), - XtRImmediate, (XtPointer) TRUE }, - {XtNcursor, XtCCursor, XtRCursor, sizeof(Cursor), - offset(cursor), XtRImmediate, (XtPointer) None}, - {XtNmenuOnScreen, XtCMenuOnScreen, XtRBoolean, sizeof(Boolean), - offset(menu_on_screen), XtRImmediate, (XtPointer) TRUE}, - {XtNpopupOnEntry, XtCPopupOnEntry, XtRWidget, sizeof(Widget), - offset(popup_entry), XtRWidget, NULL}, - {XtNbackingStore, XtCBackingStore, XtRBackingStore, sizeof (int), - offset(backing_store), - XtRImmediate, (XtPointer) (Always + WhenMapped + NotUseful)}, -}; -#undef offset - -static char defaultTranslations[] = - "<EnterWindow>: highlight() \n\ - <LeaveWindow>: unhighlight() \n\ - <BtnMotion>: highlight() \n\ - <BtnUp>: MenuPopdown() notify() unhighlight()"; +static void AddPositionAction(XtAppContext, XPointer); +static void CalculateNewSize(Widget, Dimension*, Dimension*); +static void ChangeCursorOnGrab(Widget, XtPointer, XtPointer); +static void CreateLabel(Widget); +static SmeObject DoGetEventEntry(Widget, int, int); +static Widget FindMenu(Widget, String); +static SmeObject GetEventEntry(Widget, XEvent*); +static void Layout(Widget, Dimension*, Dimension*); +static void MakeResizeRequest(Widget); +static void MakeSetValuesRequest(Widget, unsigned int, unsigned int); +static void MoveMenu(Widget, int, int); +static void PositionMenu(Widget, XPoint*); /* - * Semi Public function definitions. + * Actions */ - -static void Redisplay(), Realize(), Resize(), ChangeManaged(); -static void Initialize(), ClassInitialize(), ClassPartInitialize(); -static Boolean SetValues(), SetValuesHook(); -static XtGeometryResult GeometryManager(); +static void Highlight(Widget, XEvent*, String*, Cardinal*); +static void Notify(Widget, XEvent*, String*, Cardinal*); +#ifndef OLDXAW +static void Popdown(Widget, XEvent*, String*, Cardinal*); +#endif +static void PositionMenuAction(Widget, XEvent*, String*, Cardinal*); +static void Unhighlight(Widget, XEvent*, String*, Cardinal*); /* - * Action Routine Definitions + * Initialization */ +#define offset(field) XtOffsetOf(SimpleMenuRec, simple_menu.field) -static void Highlight(), Unhighlight(), Notify(), PositionMenuAction(); +static XtResource resources[] = { + /* label */ + { + XtNlabel, + XtCLabel, + XtRString, + sizeof(String), + offset(label_string), + XtRString, + NULL + }, + { + XtNlabelClass, + XtCLabelClass, + XtRPointer, + sizeof(WidgetClass), + offset(label_class), + XtRImmediate, + NULL + }, + + /* layout */ + { + XtNrowHeight, + XtCRowHeight, + XtRDimension, + sizeof(Dimension), + offset(row_height), + XtRImmediate, + (XtPointer)0 + }, + { + XtNtopMargin, + XtCVerticalMargins, + XtRDimension, + sizeof(Dimension), + offset(top_margin), + XtRImmediate, + (XtPointer)0 + }, + { + XtNbottomMargin, + XtCVerticalMargins, + XtRDimension, + sizeof(Dimension), + offset(bottom_margin), + XtRImmediate, + (XtPointer)0 + }, +#ifndef OLDXAW + { + XtNleftMargin, + XtCHorizontalMargins, + XtRDimension, + sizeof(Dimension), + offset(left_margin), + XtRImmediate, + (XtPointer)0 + }, + { + XtNrightMargin, + XtCHorizontalMargins, + XtRDimension, + sizeof(Dimension), + offset(right_margin), + XtRImmediate, + (XtPointer)0 + }, +#endif -/* - * Private Function Definitions. - */ + /* misc */ + { + XtNallowShellResize, + XtCAllowShellResize, + XtRBoolean, + sizeof(Boolean), + XtOffsetOf(SimpleMenuRec, shell.allow_shell_resize), + XtRImmediate, + (XtPointer)True + }, + { + XtNcursor, + XtCCursor, + XtRCursor, + sizeof(Cursor), + offset(cursor), + XtRImmediate, + (XtPointer)None + }, + { + XtNmenuOnScreen, + XtCMenuOnScreen, + XtRBoolean, + sizeof(Boolean), + offset(menu_on_screen), + XtRImmediate, + (XtPointer)True + }, + { + XtNpopupOnEntry, + XtCPopupOnEntry, + XtRWidget, + sizeof(Widget), + offset(popup_entry), + XtRWidget, + NULL + }, + { + XtNbackingStore, + XtCBackingStore, + XtRBackingStore, + sizeof(int), + offset(backing_store), + XtRImmediate, + (XtPointer)(Always + WhenMapped + NotUseful) + }, +#ifndef OLDXAW + { + XawNdisplayList, + XawCDisplayList, + XawRDisplayList, + sizeof(XawDisplayList*), + offset(display_list), + XtRImmediate, + NULL + }, +#endif +}; +#undef offset -static void MakeSetValuesRequest(), CreateLabel(), Layout(); -static void AddPositionAction(), PositionMenu(), ChangeCursorOnGrab(); -static Dimension GetMenuWidth(), GetMenuHeight(); -static Widget FindMenu(); -static SmeObject GetEventEntry(); -static void MoveMenu(); +static char defaultTranslations[] = +"<Enter>:" "highlight()\n" +"<Leave>:" "unhighlight()\n" +"<BtnMotion>:" "highlight()\n" +#ifndef OLDXAW +"<BtnUp>:" "popdown() notify() unhighlight()\n" +#else +"<BtnUp>:" "MenuPopdown() notify() unhighlight()\n" +#endif +; static XtActionsRec actionsList[] = { {"notify", Notify}, {"highlight", Highlight}, {"unhighlight", Unhighlight}, +#ifndef OLDXAW + {"popdown", Popdown}, + {"set-values", XawSetValuesAction}, + {"get-values", XawGetValuesAction}, + {"declare", XawDeclareAction}, + {"call-proc", XawCallProcAction}, +#endif }; static CompositeClassExtensionRec extension_rec = { - /* next_extension */ NULL, - /* record_type */ NULLQUARK, - /* version */ XtCompositeExtensionVersion, - /* record_size */ sizeof(CompositeClassExtensionRec), - /* accepts_objects */ TRUE, + NULL, /* next_extension */ + NULLQUARK, /* record_type */ + XtCompositeExtensionVersion, /* version */ + sizeof(CompositeClassExtensionRec), /* record_size */ + True, /* accepts_objects */ }; -#define superclass (&overrideShellClassRec) - +#define Superclass (&overrideShellClassRec) SimpleMenuClassRec simpleMenuClassRec = { + /* core */ { - /* superclass */ (WidgetClass) superclass, - /* class_name */ "SimpleMenu", - /* size */ sizeof(SimpleMenuRec), - /* class_initialize */ ClassInitialize, - /* class_part_initialize*/ ClassPartInitialize, - /* Class init'ed */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* realize */ Realize, - /* actions */ actionsList, - /* num_actions */ XtNumber(actionsList), - /* resources */ resources, - /* resource_count */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure */ TRUE, - /* compress_enterleave*/ TRUE, - /* visible_interest */ FALSE, - /* destroy */ NULL, - /* resize */ Resize, - /* expose */ Redisplay, - /* set_values */ SetValues, - /* set_values_hook */ SetValuesHook, - /* set_values_almost */ XtInheritSetValuesAlmost, - /* get_values_hook */ NULL, - /* accept_focus */ NULL, - /* intrinsics version */ XtVersion, - /* callback offsets */ NULL, - /* tm_table */ defaultTranslations, - /* query_geometry */ NULL, - /* display_accelerator*/ NULL, - /* extension */ NULL - },{ - /* geometry_manager */ GeometryManager, - /* change_managed */ ChangeManaged, - /* insert_child */ XtInheritInsertChild, - /* delete_child */ XtInheritDeleteChild, - /* extension */ NULL - },{ - /* Shell extension */ NULL - },{ - /* Override extension */ NULL - },{ - /* Simple Menu extension*/ NULL - } + (WidgetClass)Superclass, /* superclass */ + "SimpleMenu", /* class_name */ + sizeof(SimpleMenuRec), /* size */ + XawSimpleMenuClassInitialize, /* class_initialize */ + XawSimpleMenuClassPartInitialize, /* class_part_initialize */ + False, /* class_inited */ + XawSimpleMenuInitialize, /* initialize */ + NULL, /* initialize_hook */ + XawSimpleMenuRealize, /* realize */ + actionsList, /* actions */ + XtNumber(actionsList), /* num_actions */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + True, /* compress_motion */ + True, /* compress_exposure */ + True, /* compress_enterleave */ + False, /* visible_interest */ + NULL, /* destroy */ + XawSimpleMenuResize, /* resize */ + XawSimpleMenuRedisplay, /* expose */ + XawSimpleMenuSetValues, /* set_values */ + XawSimpleMenuSetValuesHook, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + NULL, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* intrinsics version */ + NULL, /* callback offsets */ + defaultTranslations, /* tm_table */ + NULL, /* query_geometry */ + NULL, /* display_accelerator */ + NULL, /* extension */ + }, + /* composite */ + { + XawSimpleMenuGeometryManager, /* geometry_manager */ + XawSimpleMenuChangeManaged, /* change_managed */ + XtInheritInsertChild, /* insert_child */ + XtInheritDeleteChild, /* delete_child */ + NULL, /* extension */ + }, + /* shell */ + { + NULL, /* extension */ + }, + /* override */ + { + NULL, /* extension */ + }, + /* simple_menu */ + { + NULL, /* extension */ + }, }; WidgetClass simpleMenuWidgetClass = (WidgetClass)&simpleMenuClassRec; -#define ForAllChildren(smw, childP) \ - for ( (childP) = (SmeObject *) (smw)->composite.children ; \ - (childP) < (SmeObject *) ( (smw)->composite.children + \ - (smw)->composite.num_children ) ; \ - (childP)++ ) - -/************************************************************ - * - * Semi-Public Functions. +/* + * Implementation + */ +/* + * Function: + * XawSimpleMenuClassInitialize * - ************************************************************/ - -/* Function Name: ClassInitialize - * Description: Class Initialize routine, called only once. - * Arguments: none. - * Returns: none. + * Description: + * Class Initialize routine, called only once. */ - static void -ClassInitialize() +XawSimpleMenuClassInitialize(void) { - XawInitializeWidgetSet(); - XtAddConverter( XtRString, XtRBackingStore, XmuCvtStringToBackingStore, - (XtConvertArgList)NULL, (Cardinal)0 ); - XmuAddInitializer( AddPositionAction, NULL); + XawInitializeWidgetSet(); + XtAddConverter(XtRString, XtRBackingStore, XmuCvtStringToBackingStore, + NULL, 0); + XtSetTypeConverter(XtRBackingStore, XtRString, XmuCvtBackingStoreToString, + NULL, 0, XtCacheNone, NULL); + XmuAddInitializer(AddPositionAction, NULL); } -/* Function Name: ClassInitialize - * Description: Class Part Initialize routine, called for every - * subclass. Makes sure that the subclasses pick up - * the extension record. +/* + * Function: + * XawSimpleMenuClassPartInitialize * Arguments: wc - the widget class of the subclass. - * Returns: none. + * + * Description: + * Class Part Initialize routine, called for every subclass. Makes + * sure that the subclasses pick up the extension record. */ - static void -ClassPartInitialize(wc) -WidgetClass wc; +XawSimpleMenuClassPartInitialize(WidgetClass wc) { - SimpleMenuWidgetClass smwc = (SimpleMenuWidgetClass) wc; - -/* - * Make sure that our subclass gets the extension rec too. - */ + SimpleMenuWidgetClass smwc = (SimpleMenuWidgetClass)wc; + /* + * Make sure that our subclass gets the extension rec too + */ extension_rec.next_extension = smwc->composite_class.extension; smwc->composite_class.extension = (XtPointer) &extension_rec; } -/* Function Name: Initialize - * Description: Initializes the simple menu widget - * Arguments: request - the widget requested by the argument list. - * new - the new widget with both resource and non - * resource values. - * Returns: none. +/* + * Function: + * XawSimpleMenuInitialize + * + * Parameters: + * request - widget requested by the argument list + * cnew - new widget with both resource and non resource values + * + * Description: + * Initializes the simple menu widget. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -Initialize(request, new, args, num_args) -Widget request, new; -ArgList args; -Cardinal *num_args; +XawSimpleMenuInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - SimpleMenuWidget smw = (SimpleMenuWidget) new; + SimpleMenuWidget smw = (SimpleMenuWidget)cnew; + Dimension width, height; - XmuCallInitializers(XtWidgetToApplicationContext(new)); + XmuCallInitializers(XtWidgetToApplicationContext(cnew)); - if (smw->simple_menu.label_class == NULL) - smw->simple_menu.label_class = smeBSBObjectClass; + if (smw->simple_menu.label_class == NULL) + smw->simple_menu.label_class = smeBSBObjectClass; - smw->simple_menu.label = NULL; - smw->simple_menu.entry_set = NULL; - smw->simple_menu.recursive_set_values = FALSE; + smw->simple_menu.label = NULL; + smw->simple_menu.entry_set = NULL; + smw->simple_menu.recursive_set_values = False; +#ifndef OLDXAW + smw->simple_menu.sub_menu = NULL; + smw->simple_menu.state = 0; - if (smw->simple_menu.label_string != NULL) - CreateLabel(new); + XtAddCallback(cnew, XtNpopupCallback, PopupCB, NULL); +#endif - smw->simple_menu.menu_width = TRUE; + if (smw->simple_menu.label_string != NULL) + CreateLabel(cnew); - if (smw->core.width == 0) { - smw->simple_menu.menu_width = FALSE; - smw->core.width = GetMenuWidth(new, (Widget)NULL); - } + width = height = 0; + CalculateNewSize(cnew, &width, &height); - smw->simple_menu.menu_height = TRUE; + smw->simple_menu.menu_width = True; - if (smw->core.height == 0) { - smw->simple_menu.menu_height = FALSE; - smw->core.height = GetMenuHeight(new); - } + if (XtWidth(smw) == 0) { + smw->simple_menu.menu_width = False; + XtWidth(smw) = width; + } -/* - * Add a popup_callback routine for changing the cursor. - */ - - XtAddCallback(new, XtNpopupCallback, ChangeCursorOnGrab, (XtPointer)NULL); + smw->simple_menu.menu_height = True; + + if (XtHeight(smw) == 0) { + smw->simple_menu.menu_height = False; + XtHeight(smw) = height; + } + + /* + * Add a popup_callback routine for changing the cursor + */ + XtAddCallback(cnew, XtNpopupCallback, ChangeCursorOnGrab, NULL); } -/* Function Name: Redisplay - * Description: Redisplays the contents of the widget. - * Arguments: w - the simple menu widget. - * event - the X event that caused this redisplay. - * region - the region the needs to be repainted. - * Returns: none. +/* + * Function: + * XawSimpleMenuRedisplay + * + * Parameters: + * w - simple menu widget + * event - X event that caused this redisplay + * region - region the needs to be repainted + * + * Description: + * Redisplays the contents of the widget. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -Redisplay(w, event, region) -Widget w; -XEvent * event; -Region region; +XawSimpleMenuRedisplay(Widget w, XEvent *event, Region region) { - SimpleMenuWidget smw = (SimpleMenuWidget) w; - SmeObject * entry; - SmeObjectClass class; + SimpleMenuWidget smw = (SimpleMenuWidget)w; + SmeObject *entry; + SmeObjectClass cclass; if (region == NULL) XClearWindow(XtDisplay(w), XtWindow(w)); +#ifndef OLDXAW + if (smw->simple_menu.display_list) + XawRunDisplayList(w, smw->simple_menu.display_list, event, region); +#endif + /* - * Check and Paint each of the entries - including the label. + * Check and Paint each of the entries - including the label */ - ForAllChildren(smw, entry) { - if (!XtIsManaged ( (Widget) *entry)) continue; + if (!XtIsManaged((Widget)*entry)) + continue; if (region != NULL) - switch(XRectInRegion(region, (int) (*entry)->rectangle.x, - (int) (*entry)->rectangle.y, - (unsigned int) (*entry)->rectangle.width, - (unsigned int) (*entry)->rectangle.height)) { - case RectangleIn: - case RectanglePart: - break; - default: - continue; + switch(XRectInRegion(region, XtX(*entry),XtY(*entry), + XtWidth(*entry), XtHeight(*entry))) { + case RectangleIn: + case RectanglePart: + break; + default: + continue; } - class = (SmeObjectClass) (*entry)->object.widget_class; - if (class->rect_class.expose != NULL) - (class->rect_class.expose)( (Widget) *entry, NULL, NULL); + cclass = (SmeObjectClass)(*entry)->object.widget_class; + + if (cclass->rect_class.expose != NULL) + (cclass->rect_class.expose)((Widget)*entry, NULL, NULL); } } -/* Function Name: Realize - * Description: Realizes the widget. - * Arguments: w - the simple menu widget. - * mask - value mask for the window to create. - * attrs - attributes for the window to create. - * Returns: none +/* + * Function: + * XawSimpleMenuRealize + * + * Parameters: + * w - simple menu widget + * mask - value mask for the window to create + * attrs - attributes for the window to create + * + * Description: + * Realizes the widget. */ - static void -Realize(w, mask, attrs) -Widget w; -XtValueMask * mask; -XSetWindowAttributes * attrs; +XawSimpleMenuRealize(Widget w, XtValueMask *mask, XSetWindowAttributes *attrs) { - SimpleMenuWidget smw = (SimpleMenuWidget) w; + SimpleMenuWidget smw = (SimpleMenuWidget)w; +#ifndef OLDXAW + XawPixmap *pixmap; +#endif attrs->cursor = smw->simple_menu.cursor; *mask |= CWCursor; - if ((smw->simple_menu.backing_store == Always) || - (smw->simple_menu.backing_store == NotUseful) || - (smw->simple_menu.backing_store == WhenMapped) ) { + if (smw->simple_menu.backing_store == Always || + smw->simple_menu.backing_store == NotUseful || + smw->simple_menu.backing_store == WhenMapped) { *mask |= CWBackingStore; attrs->backing_store = smw->simple_menu.backing_store; } else *mask &= ~CWBackingStore; - (*superclass->core_class.realize) (w, mask, attrs); + (*Superclass->core_class.realize)(w, mask, attrs); + +#ifndef OLDXAW + if (w->core.background_pixmap > XtUnspecifiedPixmap) { + pixmap = XawPixmapFromXPixmap(w->core.background_pixmap, XtScreen(w), + w->core.colormap, w->core.depth); + if (pixmap && pixmap->mask) + XawReshapeWidget(w, pixmap); + } +#endif } -/* Function Name: Resize - * Description: Handle the menu being resized bigger. - * Arguments: w - the simple menu widget. - * Returns: none. +/* + * Function: + * XawSimpleMenuResize + * + * Parameters: + * w - simple menu widget + * + * Description: + * Handle the menu being resized. */ - static void -Resize(w) -Widget w; +XawSimpleMenuResize(Widget w) { - SimpleMenuWidget smw = (SimpleMenuWidget) w; - SmeObject * entry; + if (!XtIsRealized(w)) + return; - if ( !XtIsRealized(w) ) return; + Layout(w, NULL, NULL); - ForAllChildren(smw, entry) /* reset width of all entries. */ - if (XtIsManaged( (Widget) *entry)) - (*entry)->rectangle.width = smw->core.width; - - Redisplay(w, (XEvent *) NULL, (Region) NULL); + XawSimpleMenuRedisplay(w, NULL, NULL); } -/* Function Name: SetValues - * Description: Relayout the menu when one of the resources is changed. - * Arguments: current - current state of the widget. - * request - what was requested. - * new - what the widget will become. - * Returns: none +/* + * Function: + * XawSimpleMenuSetValues + * + * Parameters: + * current - current state of the widget + * request - what was requested + * cnew - what the widget will become + * + * Description: + * Relayout the menu when one of the resources is changed. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static Boolean -SetValues(current, request, new, args, num_args) -Widget current, request, new; -ArgList args; -Cardinal *num_args; +XawSimpleMenuSetValues(Widget current, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - SimpleMenuWidget smw_old = (SimpleMenuWidget) current; - SimpleMenuWidget smw_new = (SimpleMenuWidget) new; - Boolean ret_val = FALSE, layout = FALSE; - - if (!XtIsRealized(current)) return(FALSE); - + SimpleMenuWidget smw_old = (SimpleMenuWidget)current; + SimpleMenuWidget smw_new = (SimpleMenuWidget)cnew; + Boolean ret_val = False, layout = False; + + if (!XtIsRealized(current)) + return (False); + if (!smw_new->simple_menu.recursive_set_values) { - if (smw_new->core.width != smw_old->core.width) { - smw_new->simple_menu.menu_width = (smw_new->core.width != 0); - layout = TRUE; + if (XtWidth(smw_new) != XtWidth(smw_old)) { + smw_new->simple_menu.menu_width = XtWidth(smw_new) != 0; + layout = True; } - if (smw_new->core.height != smw_old->core.height) { - smw_new->simple_menu.menu_height = (smw_new->core.height != 0); - layout = TRUE; + if (XtHeight(smw_new) != XtHeight(smw_old)) { + smw_new->simple_menu.menu_height = XtHeight(smw_new) != 0; + layout = True; } } if (smw_old->simple_menu.cursor != smw_new->simple_menu.cursor) - XDefineCursor(XtDisplay(new), - XtWindow(new), smw_new->simple_menu.cursor); - - if (smw_old->simple_menu.label_string !=smw_new->simple_menu.label_string) - if (smw_new->simple_menu.label_string == NULL) /* Destroy. */ - XtDestroyWidget((Widget) smw_old->simple_menu.label); - else if (smw_old->simple_menu.label_string == NULL) /* Create. */ - CreateLabel(new); - else { /* Change. */ + XDefineCursor(XtDisplay(cnew), XtWindow(cnew), + smw_new->simple_menu.cursor); + + if (smw_old->simple_menu.label_string !=smw_new->simple_menu.label_string) { + if (smw_new->simple_menu.label_string == NULL) /* Destroy */ + XtDestroyWidget((Widget)smw_old->simple_menu.label); + else if (smw_old->simple_menu.label_string == NULL) /* Create */ + CreateLabel(cnew); + else { /* Change */ Arg arglist[1]; XtSetArg(arglist[0], XtNlabel, smw_new->simple_menu.label_string); - XtSetValues((Widget) smw_new->simple_menu.label, arglist, ONE); + XtSetValues((Widget)smw_new->simple_menu.label, arglist, ONE); } - + } + if (smw_old->simple_menu.label_class != smw_new->simple_menu.label_class) - XtAppWarning(XtWidgetToApplicationContext(new), + XtAppWarning(XtWidgetToApplicationContext(cnew), "No Dynamic class change of the SimpleMenu Label."); - if ((smw_old->simple_menu.top_margin != smw_new->simple_menu.top_margin) || - (smw_old->simple_menu.bottom_margin != - smw_new->simple_menu.bottom_margin) /* filler................. */ ) { - layout = TRUE; - ret_val = TRUE; + if (smw_old->simple_menu.top_margin != smw_new->simple_menu.top_margin + || smw_old->simple_menu.bottom_margin + != smw_new->simple_menu.bottom_margin) { + layout = True; + ret_val = True; } +#ifndef OLDXAW + if (smw_old->core.background_pixmap != smw_new->core.background_pixmap) { + XawPixmap *opix, *npix; + + opix = XawPixmapFromXPixmap(smw_old->core.background_pixmap, + XtScreen(smw_old), smw_old->core.colormap, + smw_old->core.depth); + npix = XawPixmapFromXPixmap(smw_new->core.background_pixmap, + XtScreen(smw_new), smw_new->core.colormap, + smw_new->core.depth); + if ((npix && npix->mask) || (opix && opix->mask)) + XawReshapeWidget(cnew, npix); + } +#endif + if (layout) - Layout(new, (Dimension *)NULL, (Dimension *)NULL); + Layout(cnew, NULL, NULL); - return(ret_val); + return (ret_val); } -/* Function Name: SetValuesHook - * Description: To handle a special case, this is passed the - * actual arguments. - * Arguments: w - the menu widget. - * arglist - the argument list passed to XtSetValues. - * num_args - the number of args. - * Returns: none - */ - /* - * If the user actually passed a width and height to the widget - * then this MUST be used, rather than our newly calculated width and - * height. + * Function: + * XawSimpleMenuSetValuesHook + * + * Parameters: + * w - menu widget + * arglist - argument list passed to XtSetValues + * num_args - number of args + * + * Description: + * To handle a special case, this is passed the actual arguments. */ - static Boolean -SetValuesHook(w, arglist, num_args) -Widget w; -ArgList arglist; -Cardinal *num_args; +XawSimpleMenuSetValuesHook(Widget w, ArgList arglist, Cardinal *num_args) { Cardinal i; Dimension width, height; - width = w->core.width; - height = w->core.height; + width = XtWidth(w); + height = XtHeight(w); - for ( i = 0 ; i < *num_args ; i++) { - if ( streq(arglist[i].name, XtNwidth) ) - width = (Dimension) arglist[i].value; - if ( streq(arglist[i].name, XtNheight) ) + for (i = 0 ; i < *num_args ; i++) { + if (streq(arglist[i].name, XtNwidth)) + width = (Dimension)arglist[i].value; + if (streq(arglist[i].name, XtNheight)) height = (Dimension) arglist[i].value; } - if ((width != w->core.width) || (height != w->core.height)) + if (width != XtWidth(w) || height != XtHeight(w)) MakeSetValuesRequest(w, width, height); - return(FALSE); + + return (False); } -/************************************************************ - * - * Geometry Management routines. +/* + * Geometry Management routines + */ +/* + * Function: + * XawSimpleMenuGeometryManager * - ************************************************************/ - -/* Function Name: GeometryManager - * Description: This is the SimpleMenu Widget's Geometry Manager. - * Arguments: w - the Menu Entry making the request. - * request - requested new geometry. + * Parameters: + * w - Menu Entry making the request + * request - requested new geometry * reply - the allowed geometry. - * Returns: XtGeometry{Yes, No, Almost}. + * + * Description: + * This is the SimpleMenu Widget's Geometry Manager. + * + * Returns: + * XtGeometry{Yes, No, Almost} */ - static XtGeometryResult -GeometryManager(w, request, reply) -Widget w; -XtWidgetGeometry * request, * reply; +XawSimpleMenuGeometryManager(Widget w, XtWidgetGeometry *request, + XtWidgetGeometry *reply) { - SimpleMenuWidget smw = (SimpleMenuWidget) XtParent(w); - SmeObject entry = (SmeObject) w; + SimpleMenuWidget smw = (SimpleMenuWidget)XtParent(w); + SmeObject entry = (SmeObject)w; XtGeometryMask mode = request->request_mode; XtGeometryResult answer; Dimension old_height, old_width; - if ( !(mode & CWWidth) && !(mode & CWHeight) ) - return(XtGeometryNo); + if (!(mode & CWWidth) && !(mode & CWHeight)) + return (XtGeometryNo); reply->width = request->width; reply->height = request->height; - old_width = entry->rectangle.width; - old_height = entry->rectangle.height; + old_width = XtWidth(entry); + old_height = XtHeight(entry); - Layout(w, &(reply->width), &(reply->height) ); + Layout(w, &reply->width, &reply->height); -/* - * Since we are an override shell and have no parent there is no one to - * ask to see if this geom change is okay, so I am just going to assume - * we can do whatever we want. If you subclass be very careful with this - * assumption, it could bite you. - * - * Chris D. Peterson - Sept. 1989. - */ - - if ( (reply->width == request->width) && - (reply->height == request->height) ) { - - if ( mode & XtCWQueryOnly ) { /* Actually perform the layout. */ - entry->rectangle.width = old_width; - entry->rectangle.height = old_height; - } - else { - Layout(( Widget) smw, (Dimension *)NULL, (Dimension *)NULL); + /* + * Since we are an override shell and have no parent there is no one to + * ask to see if this geom change is okay, so I am just going to assume + * we can do whatever we want. If you subclass be very careful with this + * assumption, it could bite you. + * + * Chris D. Peterson - Sept. 1989. + */ + if ((!(mode & CWWidth) || reply->width == request->width) + && (!(mode & CWHeight) || reply->height == request->height)) { + if (mode & XtCWQueryOnly) { /* Actually perform the layout */ + XtWidth(entry) = old_width; + XtHeight(entry) = old_height; } + else + Layout((Widget)smw, NULL, NULL); answer = XtGeometryDone; } else { - entry->rectangle.width = old_width; - entry->rectangle.height = old_height; + XtWidth(entry) = old_width; + XtHeight(entry) = old_height; - if ( ((reply->width == request->width) && !(mode & CWHeight)) || - ((reply->height == request->height) && !(mode & CWWidth)) || - ((reply->width == request->width) && - (reply->height == request->height)) ) + if ((reply->width == request->width && !(mode & CWHeight)) + || (reply->height == request->height && !(mode & CWWidth)) + || (reply->width == request->width + && reply->height == request->height)) answer = XtGeometryNo; else { answer = XtGeometryAlmost; @@ -568,326 +748,343 @@ XtWidgetGeometry * request, * reply; reply->request_mode |= CWHeight; } } - return(answer); + + return (answer); } -/* Function Name: ChangeManaged - * Description: called whenever a new child is managed. - * Arguments: w - the simple menu widget. - * Returns: none. +/* + * Function: + * XawSimpleMenuChangeManaged + * + * Parameters: + * w - simple menu widget + * + * Description: + * Called whenever a new child is managed. */ - static void -ChangeManaged(w) -Widget w; +XawSimpleMenuChangeManaged(Widget w) { - Layout(w, (Dimension *)NULL, (Dimension *)NULL); + Layout(w, NULL, NULL); } -/************************************************************ - * - * Global Action Routines. +/* + * Global Action Routines * * These actions routines will be added to the application's - * global action list. + * global action list + */ +/* + * Function: + * PositionMenuAction * - ************************************************************/ - -/* Function Name: PositionMenuAction - * Description: Positions the simple menu widget. - * Arguments: w - a widget (no the simple menu widget.) - * event - the event that caused this action. - * params, num_params - parameters passed to the routine. + * Parameters: + * w - a widget (no the simple menu widget) + * event - the event that caused this action + * params - parameters passed to the routine. * we expect the name of the menu here. - * Returns: none + * num_params - "" + * + * Description: + * Positions the simple menu widget. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -PositionMenuAction(w, event, params, num_params) -Widget w; -XEvent * event; -String * params; -Cardinal * num_params; +PositionMenuAction(Widget w, XEvent *event, + String *params, Cardinal *num_params) { - Widget menu; - XPoint loc; - char error_buf[BUFSIZ]; - char* ebp; - int len; - char* fmt = "Xaw SimpleMenuWidget: could not find menu named: \"%s\""; - - if (*num_params != 1) { - char error_buf[BUFSIZ]; - (void) sprintf(error_buf, "%s %s", - "Xaw - SimpleMenuWidget: position menu action expects only one", - "parameter which is the name of the menu."); - XtAppWarning(XtWidgetToApplicationContext(w), - "Xaw - SimpleMenuWidget: position menu action expects only one parameter which is the name of the menu."); - return; - } - - if ( (menu = FindMenu(w, params[0])) == NULL) { - if ((len = strlen (fmt) + strlen (params[0])) < sizeof error_buf) - ebp = error_buf; - else - ebp = XtMalloc (len + 1); - if (ebp == NULL) { - ebp = error_buf; - strcpy (ebp, "Xaw - SimpleMenuWidget: could not find menu"); - } else - (void) sprintf(ebp, fmt, params[0]); - XtAppWarning(XtWidgetToApplicationContext(w), ebp); - if (ebp != error_buf) XtFree (ebp); - return; - } + Widget menu; + XPoint loc; + + if (*num_params != 1) { + XtAppWarning(XtWidgetToApplicationContext(w), + "SimpleMenuWidget: position menu action expects " + "only one parameter which is the name of the menu."); + return; + } + + if ((menu = FindMenu(w, params[0])) == NULL) { + char error_buf[BUFSIZ]; + + (void)XmuSnprintf(error_buf, sizeof(error_buf), + "SimpleMenuWidget: could not find menu named %s.", + params[0]); + XtAppWarning(XtWidgetToApplicationContext(w), error_buf); + return; + } - switch (event->type) { - case ButtonPress: - case ButtonRelease: - loc.x = event->xbutton.x_root; - loc.y = event->xbutton.y_root; - PositionMenu(menu, &loc); - break; - case EnterNotify: - case LeaveNotify: - loc.x = event->xcrossing.x_root; - loc.y = event->xcrossing.y_root; - PositionMenu(menu, &loc); - break; - case MotionNotify: - loc.x = event->xmotion.x_root; - loc.y = event->xmotion.y_root; - PositionMenu(menu, &loc); - break; - default: - PositionMenu(menu, (XPoint *)NULL); - break; - } + switch (event->type) { + case ButtonPress: + case ButtonRelease: + loc.x = event->xbutton.x_root; + loc.y = event->xbutton.y_root; + PositionMenu(menu, &loc); + break; + case EnterNotify: + case LeaveNotify: + loc.x = event->xcrossing.x_root; + loc.y = event->xcrossing.y_root; + PositionMenu(menu, &loc); + break; + case MotionNotify: + loc.x = event->xmotion.x_root; + loc.y = event->xmotion.y_root; + PositionMenu(menu, &loc); + break; + default: + PositionMenu(menu, NULL); + break; + } } -/************************************************************ +/* + * Widget Action Routines + */ +/* + * Function: + * Unhighlight * - * Widget Action Routines. + * Parameters: + * w - simple menu widget + * event - event that caused this action + * params - not used + * num_params - "" * - ************************************************************/ - -/* Function Name: Unhighlight - * Description: Unhighlights current entry. - * Arguments: w - the simple menu widget. - * event - the event that caused this action. - * params, num_params - ** NOT USED ** - * Returns: none + * Description: + * Unhighlights current entry. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -Unhighlight(w, event, params, num_params) -Widget w; -XEvent * event; -String * params; -Cardinal * num_params; +Unhighlight(Widget w, XEvent *event, String *params, Cardinal *num_params) { - SimpleMenuWidget smw = (SimpleMenuWidget) w; + SimpleMenuWidget smw = (SimpleMenuWidget)w; SmeObject entry = smw->simple_menu.entry_set; - SmeObjectClass class; - if ( entry == NULL) return; + if (entry == NULL) + return; - smw->simple_menu.entry_set = NULL; - class = (SmeObjectClass) entry->object.widget_class; - (class->sme_class.unhighlight) ( (Widget) entry); +#ifndef OLDXAW + if (!smw->simple_menu.sub_menu) +#endif + { + SmeObjectClass cclass; + + smw->simple_menu.entry_set = NULL; + cclass = (SmeObjectClass)entry->object.widget_class; + (cclass->sme_class.unhighlight)((Widget)entry); + } } -/* Function Name: Highlight - * Description: Highlights current entry. - * Arguments: w - the simple menu widget. - * event - the event that caused this action. - * params, num_params - ** NOT USED ** - * Returns: none +/* + * Function: + * Highlight + * + * Parameters: + * w - simple menu widget + * event - event that caused this action + * params - not used + * num_params - "" + * + * Description: + * Highlights current entry. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -Highlight(w, event, params, num_params) -Widget w; -XEvent * event; -String * params; -Cardinal * num_params; +Highlight(Widget w, XEvent *event, String *params, Cardinal *num_params) { - SimpleMenuWidget smw = (SimpleMenuWidget) w; + SimpleMenuWidget smw = (SimpleMenuWidget)w; SmeObject entry; - SmeObjectClass class; - - if ( !XtIsSensitive(w) ) return; - + + if (!XtIsSensitive(w)) + return; + entry = GetEventEntry(w, event); - if (entry == smw->simple_menu.entry_set) return; + if (entry == smw->simple_menu.entry_set) + return; - Unhighlight(w, event, params, num_params); +#ifndef OLDXAW + if (!smw->simple_menu.sub_menu) +#endif + Unhighlight(w, event, params, num_params); - if (entry == NULL) return; + if (entry == NULL) + return; - if ( !XtIsSensitive( (Widget) entry)) { - smw->simple_menu.entry_set = NULL; + if (!XtIsSensitive((Widget)entry)) return; - } - smw->simple_menu.entry_set = entry; - class = (SmeObjectClass) entry->object.widget_class; +#ifndef OLDXAW + if (smw->simple_menu.sub_menu) + PopdownSubMenu(smw); +#endif + + Unhighlight(w, event, params, num_params); - (class->sme_class.highlight) ( (Widget) entry); +#ifndef OLDXAW + if (!(smw->simple_menu.state & SMW_UNMAPPING)) +#endif + { + SmeObjectClass cclass; + + smw->simple_menu.entry_set = entry; + cclass = (SmeObjectClass)entry->object.widget_class; + + (cclass->sme_class.highlight)((Widget)entry); + +#ifndef OLDXAW + if (XtIsSubclass((Widget)entry, smeBSBObjectClass)) + PopupSubMenu(smw); +#endif + } } -/* Function Name: Notify - * Description: Notify user of current entry. - * Arguments: w - the simple menu widget. - * event - the event that caused this action. - * params, num_params - ** NOT USED ** - * Returns: none +/* + * Function: + * Notify + * + * Parameters: + * w - simple menu widget + * event - event that caused this action + * params - not used + * num_params - "" + * + * Description: + * Notify user of current entry. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -Notify(w, event, params, num_params) -Widget w; -XEvent * event; -String * params; -Cardinal * num_params; +Notify(Widget w, XEvent *event, String *params, Cardinal *num_params) { - SimpleMenuWidget smw = (SimpleMenuWidget) w; - SmeObject entry = smw->simple_menu.entry_set; - SmeObjectClass class; - - if ( (entry == NULL) || !XtIsSensitive((Widget) entry ) ) return; - - class = (SmeObjectClass) entry->object.widget_class; - (class->sme_class.notify)( (Widget) entry ); + SmeObject entry; + SmeObjectClass cclass; + + /* may be a propagated event from a sub menu, need to check it */ + if (XtWindow(w) != event->xany.window) + return; + entry = GetEventEntry(w, event); + if (entry == NULL || !XtIsSensitive((Widget)entry)) + return; + + cclass = (SmeObjectClass) entry->object.widget_class; + (cclass->sme_class.notify)((Widget)entry); } -/************************************************************ +/* + * Public Functions + */ +/* + * Function: + * XawSimpleMenuAddGlobalActions * - * Public Functions. + * Arguments: + * app_con - appcontext * - ************************************************************/ - -/* Function Name: XawSimpleMenuAddGlobalActions - * Description: adds the global actions to the simple menu widget. - * Arguments: app_con - the appcontext. - * Returns: none. + * Description: + * Adds the global actions to the simple menu widget. */ - void -#if NeedFunctionPrototypes XawSimpleMenuAddGlobalActions(XtAppContext app_con) -#else -XawSimpleMenuAddGlobalActions(app_con) -XtAppContext app_con; -#endif { XtInitializeWidgetClass(simpleMenuWidgetClass); - XmuCallInitializers( app_con ); + XmuCallInitializers(app_con); } - -/* Function Name: XawSimpleMenuGetActiveEntry - * Description: Gets the currently active (set) entry. - * Arguments: w - the smw widget. - * Returns: the currently set entry or NULL if none is set. +/* + * Function: + * XawSimpleMenuGetActiveEntry + * + * Parameters: + * w - smw widget + * + * Description: + * Gets the currently active (set) entry. + * + * Returns: + * The currently set entry or NULL if none is set */ - Widget -#if NeedFunctionPrototypes XawSimpleMenuGetActiveEntry(Widget w) -#else -XawSimpleMenuGetActiveEntry(w) -Widget w; -#endif { - SimpleMenuWidget smw = (SimpleMenuWidget) w; + SimpleMenuWidget smw = (SimpleMenuWidget)w; - return( (Widget) smw->simple_menu.entry_set); + return ((Widget)smw->simple_menu.entry_set); } -/* Function Name: XawSimpleMenuClearActiveEntry - * Description: Unsets the currently active (set) entry. - * Arguments: w - the smw widget. - * Returns: none. +/* + * Function: + * XawSimpleMenuClearActiveEntry + * + * Parameters: + * w - smw widget + * + * Description: + * Unsets the currently active (set) entry. */ - void -#if NeedFunctionPrototypes XawSimpleMenuClearActiveEntry(Widget w) -#else -XawSimpleMenuClearActiveEntry(w) -Widget w; -#endif { - SimpleMenuWidget smw = (SimpleMenuWidget) w; + SimpleMenuWidget smw = (SimpleMenuWidget)w; smw->simple_menu.entry_set = NULL; } -/************************************************************ - * - * Private Functions. +/* + * Private Functions + */ +/* + * Function: + * CreateLabel * - ************************************************************/ - -/* Function Name: CreateLabel - * Description: Creates a the menu label. - * Arguments: w - the smw widget. - * Returns: none. + * Parameters: + * w - smw widget * + * Description: * Creates the label object and makes sure it is the first child in * in the list. */ - static void -CreateLabel(w) -Widget w; +CreateLabel(Widget w) { - SimpleMenuWidget smw = (SimpleMenuWidget) w; - Widget * child, * next_child; + SimpleMenuWidget smw = (SimpleMenuWidget)w; + Widget *child, *next_child; int i; Arg args[2]; - if ( (smw->simple_menu.label_string == NULL) || - (smw->simple_menu.label != NULL) ) { - char error_buf[BUFSIZ]; - - (void) sprintf(error_buf, "Xaw Simple Menu Widget: %s or %s, %s", - "label string is NULL", "label already exists", - "no label is being created."); - XtAppWarning(XtWidgetToApplicationContext(w), error_buf); + if (smw->simple_menu.label_string == NULL || + smw->simple_menu.label != NULL) { + XtAppWarning(XtWidgetToApplicationContext(w), + "Xaw Simple Menu Widget: label string is NULL or " + "label already exists, no label is being created."); return; } XtSetArg(args[0], XtNlabel, smw->simple_menu.label_string); XtSetArg(args[1], XtNjustify, XtJustifyCenter); smw->simple_menu.label = (SmeObject) - XtCreateManagedWidget("menuLabel", - smw->simple_menu.label_class, w, - args, TWO); + XtCreateManagedWidget("menuLabel", + smw->simple_menu.label_class, w, args, TWO); next_child = NULL; for (child = smw->composite.children + smw->composite.num_children, - i = smw->composite.num_children ; i > 0 ; i--, child--) { + i = smw->composite.num_children; i > 0; i--, child--) { if (next_child != NULL) *next_child = *child; next_child = child; } - *child = (Widget) smw->simple_menu.label; + *child = (Widget)smw->simple_menu.label; } -/* Function Name: Layout - * Description: lays the menu entries out all nice and neat. - * Arguments: w - See below (+++) - * width_ret, height_ret - The returned width and - * height values. - * Returns: none. +/* + * Function: + * Layout * + * Arguments: + * w - See below + * width_ret - returned width + * height_ret - returned height + * + * Note: * if width == NULL || height == NULL then it assumes the you do not care * about the return values, and just want a relayout. * @@ -895,148 +1092,260 @@ Widget w; * to be width and height that the child would get if it were layed out * at this time. * - * +++ "w" can be the simple menu widget or any of its object children. + * "w" can be the simple menu widget or any of its object children. */ - static void -Layout(w, width_ret, height_ret) -Widget w; -Dimension *width_ret, *height_ret; +Layout(Widget w, Dimension *width_ret, Dimension *height_ret) { - SmeObject current_entry, *entry; + SmeObject current_entry; SimpleMenuWidget smw; Dimension width, height; - Boolean do_layout = ((height_ret == NULL) || (width_ret == NULL)); Boolean allow_change_size; + Widget kid; + Cardinal i, count, n; + int width_kid, height_kid, tmp_w, tmp_h; + short vadd, hadd, x_ins, y_ins; + Dimension *widths; + height = 0; - if ( XtIsSubclass(w, simpleMenuWidgetClass) ) { - smw = (SimpleMenuWidget) w; + if (XtIsSubclass(w, simpleMenuWidgetClass)) { + smw = (SimpleMenuWidget)w; current_entry = NULL; } else { - smw = (SimpleMenuWidget) XtParent(w); - current_entry = (SmeObject) w; + smw = (SimpleMenuWidget)XtParent(w); + current_entry = (SmeObject)w; } - allow_change_size = (!XtIsRealized((Widget)smw) || - (smw->shell.allow_shell_resize)); + allow_change_size = (!XtIsRealized((Widget)smw) + || smw->shell.allow_shell_resize); - if ( smw->simple_menu.menu_height ) - height = smw->core.height; - else - if (do_layout) { - height = smw->simple_menu.top_margin; - ForAllChildren(smw, entry) { - if (!XtIsManaged( (Widget) *entry)) continue; - - if ( (smw->simple_menu.row_height != 0) && - (*entry != smw->simple_menu.label) ) - (*entry)->rectangle.height = smw->simple_menu.row_height; - - (*entry)->rectangle.y = height; - (*entry)->rectangle.x = 0; - height += (*entry)->rectangle.height; - } - height += smw->simple_menu.bottom_margin; + for (i = smw->simple_menu.label ? 1 : 0; + i < smw->composite.num_children; + i++) { + XtWidgetGeometry preferred; + + kid = smw->composite.children[i]; + if (!XtIsManaged(kid)) + continue; + if (smw->simple_menu.row_height != 0) + XtHeight(kid) = smw->simple_menu.row_height; + XtQueryGeometry(kid, NULL, &preferred); + if (preferred.request_mode & CWWidth) + XtWidth(kid) = preferred.width; + } + + if (smw->simple_menu.label + && XtIsManaged((Widget)smw->simple_menu.label)) { + XtWidgetGeometry preferred; + + kid = (Widget)smw->simple_menu.label; + XtQueryGeometry(kid, NULL, &preferred); + if (preferred.request_mode & CWWidth) + XtWidth(kid) = preferred.width; + if (preferred.request_mode & CWHeight) + XtHeight(kid) = preferred.height; + } + + /* reset */ + if (!smw->simple_menu.menu_width) + XtWidth(smw) = 0; + if (!smw->simple_menu.menu_height) + XtHeight(smw) = 0; + if (!XtWidth(smw) || !XtHeight(smw)) + MakeResizeRequest((Widget)smw); + + widths = (Dimension *)XtMalloc(sizeof(Dimension)); +#ifndef OLDXAW + hadd = smw->simple_menu.left_margin; +#else + hadd = 0; +#endif + vadd = smw->simple_menu.top_margin; + if (smw->simple_menu.label) + vadd += XtHeight(smw->simple_menu.label); + + count = 1; + width = tmp_w = tmp_h = n = 0; + height = vadd; + + for (i = smw->simple_menu.label ? 1 : 0; + i < smw->composite.num_children; + i++) { + kid = smw->composite.children[i]; + if (!XtIsManaged(kid)) + continue; + width_kid = XtWidth(kid); + height_kid = XtHeight(kid); + + if (n && (height + height_kid + smw->simple_menu.bottom_margin + > XtHeight(smw))) { + ++count; + widths = (Dimension *)XtRealloc((char *)widths, + sizeof(Dimension) * count); + widths[count - 1] = width_kid; + width += tmp_w; + tmp_w = width_kid; + height = height_kid + vadd; + } + else + height += height_kid; + if (height > tmp_h) + tmp_h = height; + if (width_kid > tmp_w) + widths[count - 1] = tmp_w = width_kid; + ++n; + } + + height = tmp_h + smw->simple_menu.bottom_margin; + width += tmp_w; + + if (smw->simple_menu.label && width < XtWidth(smw->simple_menu.label)) { + float inc; + + inc = (XtWidth(smw->simple_menu.label) - width) / (float)count; + width = XtWidth(smw->simple_menu.label); + for (n = 0; n < count; n++) + widths[n] += inc; + } + +#ifndef OLDXAW + width += hadd + smw->simple_menu.right_margin; +#endif + + x_ins = n = count = 0; + tmp_w = widths[0]; + tmp_h = vadd; + + for (i = smw->simple_menu.label ? 1 : 0; + i < smw->composite.num_children; + i++) { + kid = smw->composite.children[i]; + if (!XtIsManaged(kid)) + continue; + + height_kid = XtHeight(kid); + + if (n && (tmp_h + height_kid + smw->simple_menu.bottom_margin + > XtHeight(smw))) { + x_ins = tmp_w; + y_ins = vadd; + ++count; + tmp_w += widths[count]; + tmp_h = height_kid + vadd; } else { - if ((smw->simple_menu.row_height != 0) && - (current_entry != smw->simple_menu.label) ) - height = smw->simple_menu.row_height; + y_ins = tmp_h; + tmp_h += height_kid; } - - if (smw->simple_menu.menu_width) - width = smw->core.width; - else if ( allow_change_size ) - width = GetMenuWidth((Widget) smw, (Widget) current_entry); - else - width = smw->core.width; + ++n; + + XtX(kid) = x_ins + hadd; + XtY(kid) = y_ins; + XtWidth(kid) = widths[count]; + } - if (do_layout) { - ForAllChildren(smw, entry) - if (XtIsManaged( (Widget) *entry)) - (*entry)->rectangle.width = width; + XtFree((char *)widths); - if (allow_change_size) - MakeSetValuesRequest((Widget) smw, width, height); + if (allow_change_size) + MakeSetValuesRequest((Widget) smw, width, height); + + if (smw->simple_menu.label) { + XtX(smw->simple_menu.label) = 0; + XtY(smw->simple_menu.label) = smw->simple_menu.top_margin; + XtWidth(smw->simple_menu.label) = XtWidth(smw) +#ifndef OLDXAW + - (smw->simple_menu.left_margin + smw->simple_menu.right_margin) +#endif + ; } - else { - *width_ret = width; - if (height != 0) - *height_ret = height; + if (current_entry) { + if (width_ret) + *width_ret = XtWidth(current_entry); + if (height_ret) + *height_ret = XtHeight(current_entry); } } -/* Function Name: AddPositionAction - * Description: Adds the XawPositionSimpleMenu action to the global +/* + * Function: + * AddPositionAction + * + * Parameters: + * app_con - application context + * data - (not used) + * + * Description: + * Adds the XawPositionSimpleMenu action to the global * action list for this appcon. - * Arguments: app_con - the application context for this app. - * data - NOT USED. - * Returns: none. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -AddPositionAction(app_con, data) -XtAppContext app_con; -XPointer data; +AddPositionAction(XtAppContext app_con, XPointer data) { static XtActionsRec pos_action[] = { - { "XawPositionSimpleMenu", PositionMenuAction }, + {"XawPositionSimpleMenu", PositionMenuAction}, }; XtAppAddActions(app_con, pos_action, XtNumber(pos_action)); } -/* Function Name: FindMenu - * Description: Find the menu give a name and reference widget. - * Arguments: widget - reference widget. - * name - the menu widget's name. - * Returns: the menu widget or NULL. +/* + * Function: + * FindMenu + * + * Parameters: + * widget - reference widget + * name - menu widget's name + * + * Description: + * Find the menu give a name and reference widget + * + * Returns: + * The menu widget or NULL. */ - static Widget -FindMenu(widget, name) -Widget widget; -String name; +FindMenu(Widget widget, String name) { Widget w, menu; - for ( w = widget ; w != NULL ; w = XtParent(w) ) - if ( (menu = XtNameToWidget(w, name)) != NULL ) - return(menu); - return(NULL); + for (w = widget; w != NULL; w = XtParent(w)) + if ((menu = XtNameToWidget(w, name)) != NULL) + return (menu); + + return (NULL); } -/* Function Name: PositionMenu - * Description: Places the menu - * Arguments: w - the simple menu widget. - * location - a pointer the the position or NULL. - * Returns: none. +/* + * Function: + * PositionMenu + * + * Parameters: + * w - simple menu widget + * location - pointer the the position or NULL + * + * Description: + * Places the menu */ - static void -PositionMenu(w, location) -Widget w; -XPoint * location; +PositionMenu(Widget w, XPoint *location) { - SimpleMenuWidget smw = (SimpleMenuWidget) w; + SimpleMenuWidget smw = (SimpleMenuWidget)w; SmeObject entry; XPoint t_point; if (location == NULL) { - Window junk1, junk2; - int root_x, root_y, junkX, junkY; - unsigned int junkM; + Window temp1, temp2; + int root_x, root_y, tempX, tempY; + unsigned int tempM; location = &t_point; - if (XQueryPointer(XtDisplay(w), XtWindow(w), &junk1, &junk2, - &root_x, &root_y, &junkX, &junkY, &junkM) == FALSE) { - char error_buf[BUFSIZ]; - (void) sprintf(error_buf, "%s %s", "Xaw Simple Menu Widget:", - "Could not find location of mouse pointer"); - XtAppWarning(XtWidgetToApplicationContext(w), error_buf); + if (XQueryPointer(XtDisplay(w), XtWindow(w), &temp1, &temp2, + &root_x, &root_y, &tempX, &tempY, &tempM) == False) { + XtAppWarning(XtWidgetToApplicationContext(w), + "Xaw Simple Menu Widget: " + "Could not find location of mouse pointer"); return; } location->x = (short) root_x; @@ -1044,12 +1353,11 @@ XPoint * location; } /* - * The width will not be correct unless it is realized. + * The width will not be correct unless it is realized */ - XtRealizeWidget(w); - location->x -= (Position) w->core.width/2; + location->x -= XtWidth(w) >> 1; if (smw->simple_menu.popup_entry == NULL) entry = smw->simple_menu.label; @@ -1057,34 +1365,38 @@ XPoint * location; entry = smw->simple_menu.popup_entry; if (entry != NULL) - location->y -= entry->rectangle.y + entry->rectangle.height/2; + location->y -= XtY(entry) + (XtHeight(entry) >> 1); - MoveMenu(w, (Position) location->x, (Position) location->y); + MoveMenu(w, location->x, location->y); } -/* Function Name: MoveMenu - * Description: Actually moves the menu, may force it to - * to be fully visable if menu_on_screen is TRUE. - * Arguments: w - the simple menu widget. - * x, y - the current location of the widget. - * Returns: none +/* + * Function: + * MoveMenu + * + * Parameters: + * w - simple menu widget + * x - current location of the widget + * y - "" + * + * Description: + * Actually moves the menu, may force it to + * to be fully visable if menu_on_screen is True. */ - static void -MoveMenu(w, x, y) -Widget w; -Position x, y; +MoveMenu(Widget w, int x, int y) { Arg arglist[2]; Cardinal num_args = 0; - SimpleMenuWidget smw = (SimpleMenuWidget) w; + SimpleMenuWidget smw = (SimpleMenuWidget)w; if (smw->simple_menu.menu_on_screen) { - int width = w->core.width + 2 * w->core.border_width; - int height = w->core.height + 2 * w->core.border_width; + int width = XtWidth(w) + (XtBorderWidth(w) << 1); + int height = XtHeight(w) + (XtBorderWidth(w) << 1); if (x >= 0) { int scr_width = WidthOfScreen(XtScreen(w)); + if (x + width > scr_width) x = scr_width - width; } @@ -1093,6 +1405,7 @@ Position x, y; if (y >= 0) { int scr_height = HeightOfScreen(XtScreen(w)); + if (y + height > scr_height) y = scr_height - height; } @@ -1105,184 +1418,414 @@ Position x, y; XtSetValues(w, arglist, num_args); } -/* Function Name: ChangeCursorOnGrab - * Description: Changes the cursor on the active grab to the one +/* + * Function: + * ChangeCursorOnGrab + * + * Parameters: + * w - menu widget + * temp1 - not used + * temp2 - "" + * + * Description: + * Changes the cursor on the active grab to the one * specified in out resource list. - * Arguments: w - the widget. - * junk, garbage - ** NOT USED **. - * Returns: None. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -ChangeCursorOnGrab(w, junk, garbage) -Widget w; -XtPointer junk, garbage; +ChangeCursorOnGrab(Widget w, XtPointer temp1, XtPointer temp2) { - SimpleMenuWidget smw = (SimpleMenuWidget) w; + SimpleMenuWidget smw = (SimpleMenuWidget)w; /* * The event mask here is what is currently in the MIT implementation. * There really needs to be a way to get the value of the mask out * of the toolkit (CDP 5/26/89). */ - - XChangeActivePointerGrab(XtDisplay(w), ButtonPressMask|ButtonReleaseMask, + XChangeActivePointerGrab(XtDisplay(w), ButtonPressMask | ButtonReleaseMask, smw->simple_menu.cursor, XtLastTimestampProcessed(XtDisplay(w))); } -/* Function Name: MakeSetValuesRequest - * Description: Makes a (possibly recursive) call to SetValues, - * I take great pains to not go into an infinite loop. - * Arguments: w - the simple menu widget. - * width, height - the size of the ask for. - * Returns: none +/* + * Function: + * MakeSetValuesRequest + * + * Parameters: + * w - simple menu widget + * width - size requested + * height - "" */ - static void -MakeSetValuesRequest(w, width, height) -Widget w; -Dimension width, height; +MakeSetValuesRequest(Widget w, unsigned int width, unsigned int height) { - SimpleMenuWidget smw = (SimpleMenuWidget) w; + SimpleMenuWidget smw = (SimpleMenuWidget)w; Arg arglist[2]; - Cardinal num_args = (Cardinal) 0; + Cardinal num_args = 0; - if ( !smw->simple_menu.recursive_set_values ) { - if ( (smw->core.width != width) || (smw->core.height != height) ) { - smw->simple_menu.recursive_set_values = TRUE; + if (!smw->simple_menu.recursive_set_values) { + if (XtWidth(smw) != width || XtHeight(smw) != height) { + smw->simple_menu.recursive_set_values = True; XtSetArg(arglist[num_args], XtNwidth, width); num_args++; XtSetArg(arglist[num_args], XtNheight, height); num_args++; XtSetValues(w, arglist, num_args); } - else if (XtIsRealized( (Widget) smw)) - Redisplay((Widget) smw, (XEvent *) NULL, (Region) NULL); + else if (XtIsRealized((Widget)smw)) + XawSimpleMenuRedisplay((Widget)smw, NULL, NULL); } - smw->simple_menu.recursive_set_values = FALSE; + smw->simple_menu.recursive_set_values = False; } -/* Function Name: GetMenuWidth - * Description: Sets the length of the widest entry in pixels. - * Arguments: w - the simple menu widget. - * Returns: width of menu. - */ - -static Dimension -GetMenuWidth(w, w_ent) -Widget w, w_ent; +static SmeObject +DoGetEventEntry(Widget w, int x_loc, int y_loc) { - SmeObject cur_entry = (SmeObject) w_ent; - SimpleMenuWidget smw = (SimpleMenuWidget) w; - Dimension width, widest = (Dimension) 0; - SmeObject * entry; - - if ( smw->simple_menu.menu_width ) - return(smw->core.width); + SimpleMenuWidget smw = (SimpleMenuWidget)w; + SmeObject *entry; ForAllChildren(smw, entry) { - XtWidgetGeometry preferred; - - if (!XtIsManaged( (Widget) *entry)) continue; - - if (*entry != cur_entry) { - XtQueryGeometry((Widget) *entry, (XtWidgetGeometry *)NULL, &preferred); - - if (preferred.request_mode & CWWidth) - width = preferred.width; + if (!XtIsManaged((Widget)*entry)) + continue; + + if (x_loc > XtX(*entry) + && x_loc <= XtX(*entry) + XtWidth(*entry) + && y_loc > XtY(*entry) + && y_loc <= XtY(*entry) + XtHeight(*entry)) { + if (*entry == smw->simple_menu.label) + return (NULL); /* cannot select the label */ else - width = (*entry)->rectangle.width; + return (*entry); } - else - width = (*entry)->rectangle.width; - - if ( width > widest ) - widest = width; } - return(widest); + return (NULL); } -/* Function Name: GetMenuHeight - * Description: Sets the length of the widest entry in pixels. - * Arguments: w - the simple menu widget. - * Returns: width of menu. +/* + * Function: + * GetEventEntry + * + * Parameters: + * w - simple menu widget + * event - X event + * + * Description: + * Gets an entry given an event that has X and Y coords. + * + * Returns: + * The entry that this point is in */ - -static Dimension -GetMenuHeight(w) -Widget w; +static SmeObject +GetEventEntry(Widget w, XEvent *event) { - SimpleMenuWidget smw = (SimpleMenuWidget) w; - SmeObject * entry; - Dimension height; - - if (smw->simple_menu.menu_height) - return(smw->core.height); + int x_loc, y_loc, x_root; + SimpleMenuWidget smw = (SimpleMenuWidget)w; + SmeObject entry; + int warp, move; - height = smw->simple_menu.top_margin + smw->simple_menu.bottom_margin; + switch (event->type) { + case MotionNotify: + x_loc = event->xmotion.x; + y_loc = event->xmotion.y; + x_root = event->xmotion.x_root; + break; + case EnterNotify: + case LeaveNotify: + x_loc = event->xcrossing.x; + y_loc = event->xcrossing.y; + x_root = event->xcrossing.x_root; + break; + case ButtonPress: + case ButtonRelease: + x_loc = event->xbutton.x; + y_loc = event->xbutton.y; + x_root = event->xbutton.x_root; + break; + default: + XtAppError(XtWidgetToApplicationContext(w), + "Unknown event type in GetEventEntry()."); + return (NULL); + } - if (smw->simple_menu.row_height == 0) { - ForAllChildren(smw, entry) - if (XtIsManaged ((Widget) *entry)) - height += (*entry)->rectangle.height; - } else - height += smw->simple_menu.row_height * smw->composite.num_children; - - return(height); + if (x_loc < 0 || x_loc >= XtWidth(smw) || + y_loc < 0 || y_loc >= XtHeight(smw)) + return (NULL); + + /* Move the menu if it's outside the screen, does not check + * smw->simple_menu.menu_on_screen because menus is bigger than screen + */ + if (x_root == WidthOfScreen(XtScreen(w)) - 1 && + XtX(w) + XtWidth(w) + (XtBorderWidth(w)) > x_root) { + warp = -8; + if (smw->simple_menu.entry_set) { + entry = DoGetEventEntry(w, + XtX(smw->simple_menu.entry_set) + + XtWidth(smw->simple_menu.entry_set) + 1, + y_loc); + Unhighlight(w, event, NULL, NULL); + if (entry) { + warp = -(int)XtWidth(entry) >> 1; + move = x_loc - XtWidth(entry) - XtX(entry) + XtBorderWidth(w); + } + else { + warp = 0; + move = WidthOfScreen(XtScreen(w)) - + (XtX(w) + XtWidth(w) + (XtBorderWidth(w) << 1)); + } + } + else { + warp = 0; + move = WidthOfScreen(XtScreen(w)) - + (XtX(w) + XtWidth(w) + (XtBorderWidth(w) << 1)); + } + } + else if (x_root == 0 && XtX(w) < 0) { + warp = 8; + if (smw->simple_menu.entry_set) { + entry = DoGetEventEntry(w, XtX(smw->simple_menu.entry_set) - 1, + y_loc); + Unhighlight(w, event, NULL, NULL); + if (entry) { + warp = XtWidth(entry) >> 1; + move = x_loc - XtX(entry); + } + else + move = x_loc + XtBorderWidth(w); + } + else + move = x_loc + XtBorderWidth(w); + } + else + move = warp = 0; + + if (move) + XtMoveWidget(w, XtX(w) + move, XtY(w)); + if (warp) + XWarpPointer(XtDisplay(w), None, None, 0, 0, 0, 0, warp, 0); + + return (DoGetEventEntry(w, x_loc, y_loc)); } -/* Function Name: GetEventEntry - * Description: Gets an entry given an event that has X and Y coords. - * Arguments: w - the simple menu widget. - * event - the event. - * Returns: the entry that this point is in. - */ +static void +CalculateNewSize(Widget w, Dimension *width_return, Dimension *height_return) +{ + SimpleMenuWidget xaw = (SimpleMenuWidget)w; + Widget kid; + Cardinal i; + int width_kid, height_kid; + int width, height, tmp_w, tmp_h, max_dim; + short vadd, hadd; + int n, columns, test_h, num_children = 0; + Boolean try_layout = False; + +#ifndef OLDXAW + hadd = xaw->simple_menu.left_margin + xaw->simple_menu.right_margin; +#else + hadd = 0; +#endif + vadd = xaw->simple_menu.top_margin + xaw->simple_menu.bottom_margin; + if (xaw->simple_menu.label) + vadd += XtHeight(xaw->simple_menu.label); + + if (*height_return) + max_dim = *height_return; + else if (!XtHeight(w)) { + max_dim = HeightOfScreen(XtScreen(w)); + try_layout = True; + } + else + max_dim = XtHeight(w); + max_dim -= vadd; + + width = height = tmp_w = tmp_h = n = test_h = 0; + columns = 1; + for (i = xaw->simple_menu.label ? 1 : 0; + i < xaw->composite.num_children; + i++) { + kid = xaw->composite.children[i]; + if (!XtIsManaged(kid)) + continue; + ++num_children; + width_kid = XtWidth(kid); + height_kid = XtHeight(kid); + + if (try_layout) { + if (!test_h) + test_h = height_kid; + else if (test_h != height_kid) + try_layout = False; + } -static SmeObject -GetEventEntry(w, event) -Widget w; -XEvent * event; + if (n && (height + height_kid > max_dim)) { + ++columns; + width += tmp_w; + tmp_w = width_kid; + height = height_kid; + } + else + height += height_kid; + if (height > tmp_h) + tmp_h = height; + if (width_kid > tmp_w) + tmp_w = width_kid; + ++n; + } + + height = tmp_h + vadd; + width += tmp_w + hadd; + + if (xaw->simple_menu.label) + width = XawMax(width, XtWidth(xaw->simple_menu.label) + hadd); + + *width_return = width; + *height_return = height; + + if (try_layout && columns > 1 && num_children > 2) { + int space; + + height = test_h * (xaw->simple_menu.label ? + num_children - 1 : + num_children); + + max_dim -= max_dim % test_h; + space = max_dim - (height % max_dim); + if (space >= test_h * columns) { + height = max_dim - space / columns; + if (height % test_h) + height += test_h - (height % test_h); + *height_return = height + vadd; + CalculateNewSize(w, width_return, height_return); + } + } +} + +static void +MakeResizeRequest(Widget w) { - Position x_loc, y_loc; - SimpleMenuWidget smw = (SimpleMenuWidget) w; - SmeObject * entry; - - switch (event->type) { - case MotionNotify: - x_loc = event->xmotion.x; - y_loc = event->xmotion.y; - break; - case EnterNotify: - case LeaveNotify: - x_loc = event->xcrossing.x; - y_loc = event->xcrossing.y; - break; - case ButtonPress: - case ButtonRelease: - x_loc = event->xbutton.x; - y_loc = event->xbutton.y; - break; - default: - XtAppError(XtWidgetToApplicationContext(w), - "Unknown event type in GetEventEntry()."); + int tries; + Dimension width, height; + + width = XtWidth(w); + height = XtHeight(w); + + for (tries = 0; tries < 100; tries++) { + CalculateNewSize(w, &width, &height); + if (width == XtWidth(w) && height == XtHeight(w)) + break; + if (XtMakeResizeRequest(w, width, height, &width, &height) == + XtGeometryNo) break; } - - if ( (x_loc < 0) || (x_loc >= (int)smw->core.width) || (y_loc < 0) || - (y_loc >= (int)smw->core.height) ) - return(NULL); - - ForAllChildren(smw, entry) { - if (!XtIsManaged ((Widget) *entry)) continue; +} - if ( ((*entry)->rectangle.y < y_loc) && - ((*entry)->rectangle.y + (int) (*entry)->rectangle.height > y_loc) ) - if ( *entry == smw->simple_menu.label ) - return(NULL); /* cannot select the label. */ - else - return(*entry); +#ifndef OLDXAW +static void +Popdown(Widget w, XEvent *event, String *params, Cardinal *num_params) +{ + SimpleMenuWidget smw = (SimpleMenuWidget)w; + + while (XtParent(w) && + XtIsSubclass(XtParent(w), simpleMenuWidgetClass)) { + if (((SimpleMenuWidget)XtParent(w))->simple_menu.sub_menu == (Widget)w) { + w = XtParent(w); + smw = (SimpleMenuWidget)w; + smw->simple_menu.entry_set = NULL; + } + else + break; } - - return(NULL); + + smw->simple_menu.state |= SMW_UNMAPPING; + if (smw->simple_menu.sub_menu) + PopdownSubMenu(smw); + XtCallActionProc(w, "XtMenuPopdown", event, params, *num_params); +} + +static void +PopupSubMenu(SimpleMenuWidget smw) +{ + Arg args[2]; + Cardinal num_args; + Widget menu; + SmeBSBObject entry = (SmeBSBObject)smw->simple_menu.entry_set; + Position menu_x, menu_y; + Bool popleft; + + if (entry->sme_bsb.menu_name == NULL) + return; + + if ((menu = FindMenu((Widget)smw, entry->sme_bsb.menu_name)) == NULL) + return; + + smw->simple_menu.sub_menu = menu; + + if (!XtIsRealized(menu)) + XtRealizeWidget(menu); + + popleft = (smw->simple_menu.state & SMW_POPLEFT) != 0; + + if (popleft) + XtTranslateCoords((Widget)smw, -(int)XtWidth(menu), + XtY(entry) - XtBorderWidth(menu), &menu_x, &menu_y); + else + XtTranslateCoords((Widget)smw, XtWidth(smw), XtY(entry) + - XtBorderWidth(menu), &menu_x, &menu_y); + + if (!popleft && menu_x >= 0) { + int scr_width = WidthOfScreen(XtScreen(menu)); + + if (menu_x + XtWidth(menu) > scr_width) { + menu_x -= XtWidth(menu) + XtWidth(smw); + popleft = True; + } + } + else if (popleft && menu_x < 0) { + menu_x = 0; + popleft = False; + } + if (menu_y >= 0) { + int scr_height = HeightOfScreen(XtScreen(menu)); + + if (menu_y + XtHeight(menu) > scr_height) + menu_y = scr_height - XtHeight(menu) - XtBorderWidth(menu); + } + if (menu_y < 0) + menu_y = 0; + + num_args = 0; + XtSetArg(args[num_args], XtNx, menu_x); num_args++; + XtSetArg(args[num_args], XtNy, menu_y); num_args++; + XtSetValues(menu, args, num_args); + + if (popleft) + ((SimpleMenuWidget)menu)->simple_menu.state |= SMW_POPLEFT; + else + ((SimpleMenuWidget)menu)->simple_menu.state &= ~SMW_POPLEFT; + + XtPopup(menu, XtGrabNone); +} + +static void +PopdownSubMenu(SimpleMenuWidget smw) +{ + SimpleMenuWidget menu = (SimpleMenuWidget)smw->simple_menu.sub_menu; + + if (!menu) + return; + + menu->simple_menu.state |= SMW_UNMAPPING; + PopdownSubMenu(menu); + + XtPopdown((Widget)menu); + + smw->simple_menu.sub_menu = NULL; +} + +/*ARGSUSED*/ +static void +PopupCB(Widget w, XtPointer client_data, XtPointer call_data) +{ + SimpleMenuWidget smw = (SimpleMenuWidget)w; + + smw->simple_menu.state &= ~(SMW_UNMAPPING | SMW_POPLEFT); } +#endif /* OLDXAW */ @@ -23,10 +23,9 @@ Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/Sme.c,v 1.7 2001/12/14 19:54:43 dawes Exp $ */ /* - * Sme.c - Source code for the generic menu entry - * * Date: September 26, 1989 * * By: Chris D. Peterson @@ -37,101 +36,116 @@ in this Software without prior written authorization from The Open Group. #include <stdio.h> #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> - -#include <X11/Xaw/XawInit.h> -#include <X11/Xaw/SmeP.h> #include <X11/Xaw/Cardinals.h> +#include <X11/Xaw/SmeP.h> +#include <X11/Xaw/XawInit.h> +#include "Private.h" +/* + * Class Methods + */ +static void Highlight(Widget); +static void Notify(Widget); +static void Unhighlight(Widget); +static void XawSmeClassPartInitialize(WidgetClass); +static void XawSmeInitialize(Widget, Widget, ArgList, Cardinal*); +static XtGeometryResult XawSmeQueryGeometry(Widget, XtWidgetGeometry*, + XtWidgetGeometry*); + +/* + * Initialization + */ #define offset(field) XtOffsetOf(SmeRec, sme.field) static XtResource resources[] = { - {XtNcallback, XtCCallback, XtRCallback, sizeof(XtPointer), - offset(callbacks), XtRCallback, (XtPointer)NULL}, - {XtNinternational, XtCInternational, XtRBoolean, sizeof(Boolean), - offset(international), XtRImmediate, (XtPointer) FALSE}, + { + XtNcallback, + XtCCallback, + XtRCallback, + sizeof(XtPointer), + offset(callbacks), + XtRCallback, + NULL + }, + { + XtNinternational, + XtCInternational, + XtRBoolean, + sizeof(Boolean), + offset(international), + XtRImmediate, + (XtPointer)False + }, }; #undef offset -/* - * Semi Public function definitions. - */ - -static void Unhighlight(), Highlight(), Notify(), ClassPartInitialize(); -static void Initialize(); -static XtGeometryResult QueryGeometry(); - -#define SUPERCLASS (&rectObjClassRec) - +#define Superclass (&rectObjClassRec) SmeClassRec smeClassRec = { + /* rectangle */ { - /* superclass */ (WidgetClass) SUPERCLASS, - /* class_name */ "Sme", - /* size */ sizeof(SmeRec), - /* class_initialize */ XawInitializeWidgetSet, - /* class_part_initialize*/ ClassPartInitialize, - /* Class init'ed */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* realize */ NULL, - /* actions */ NULL, - /* num_actions */ ZERO, - /* resources */ resources, - /* resource_count */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ FALSE, - /* compress_exposure */ FALSE, - /* compress_enterleave*/ FALSE, - /* visible_interest */ FALSE, - /* destroy */ NULL, - /* resize */ NULL, - /* expose */ NULL, - /* set_values */ NULL, - /* set_values_hook */ NULL, - /* set_values_almost */ XtInheritSetValuesAlmost, - /* get_values_hook */ NULL, - /* accept_focus */ NULL, - /* intrinsics version */ XtVersion, - /* callback offsets */ NULL, - /* tm_table */ NULL, - /* query_geometry */ QueryGeometry, - /* display_accelerator*/ NULL, - /* extension */ NULL - },{ - /* Simple Menu Entry Fields */ - - /* highlight */ Highlight, - /* unhighlight */ Unhighlight, - /* notify */ Notify, - /* extension */ NULL + (WidgetClass)Superclass, /* superclass */ + "Sme", /* class_name */ + sizeof(SmeRec), /* widget_size */ + XawInitializeWidgetSet, /* class_initialize */ + XawSmeClassPartInitialize, /* class_part_initialize */ + False, /* class_initialized */ + XawSmeInitialize, /* initialize */ + NULL, /* initialize_hook */ + NULL, /* realize */ + NULL, /* actions */ + 0, /* num_actions */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + False, /* compress_motion */ + False, /* compress_exposure */ + False, /* compress_enterleave */ + False, /* visible_interest */ + NULL, /* destroy */ + NULL, /* resize */ + NULL, /* expose */ + NULL, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + NULL, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* intrinsics_version */ + NULL, /* callback offsets */ + NULL, /* tm_table */ + XawSmeQueryGeometry, /* query_geometry */ + NULL, /* display_accelerator */ + NULL, /* extension */ + }, + /* sme */ + { + Highlight, /* highlight */ + Unhighlight, /* unhighlight */ + Notify, /* notify */ + NULL, /* extension */ } }; -WidgetClass smeObjectClass = (WidgetClass) &smeClassRec; +WidgetClass smeObjectClass = (WidgetClass)&smeClassRec; -/************************************************************ +/* + * Implementation + */ +/* + * Function: + * XawSmeClassPartInitialize * - * Semi-Public Functions. + * Parameters: + * cclass - widget classs of this widget * - ************************************************************/ - -/* Function Name: ClassPartInitialize - * Description: handles inheritance of class functions. - * Arguments: class - the widget classs of this widget. - * Returns: none. + * Description: + * Handles inheritance of class functions. */ - static void -ClassPartInitialize(class) -WidgetClass class; +XawSmeClassPartInitialize(WidgetClass cclass) { SmeObjectClass m_ent, superC; - m_ent = (SmeObjectClass) class; - superC = (SmeObjectClass) m_ent->rect_class.superclass; - -/* - * We don't need to check for null super since we'll get to TextSink - * eventually. - */ + m_ent = (SmeObjectClass)cclass; + superC = (SmeObjectClass)m_ent->rect_class.superclass; if (m_ent->sme_class.highlight == XtInheritHighlight) m_ent->sme_class.highlight = superC->sme_class.highlight; @@ -143,101 +157,113 @@ WidgetClass class; m_ent->sme_class.notify = superC->sme_class.notify; } -/* Function Name: Initialize - * Description: Initializes the simple menu widget - * Arguments: request - the widget requested by the argument list. - * new - the new widget with both resource and non - * resource values. - * Returns: none. +/* + * Function: + * XawSmeInitialize + * + * Parameters: + * request - widget requested by the argument list + * cnew - new widget with both resource and non resource values * - * MENU ENTRIES CANNOT HAVE BORDERS. + * Description: + * Initializes the simple menu widget entry */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -Initialize(request, new, args, num_args) -Widget request, new; -ArgList args; -Cardinal *num_args; +XawSmeInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - SmeObject entry = (SmeObject) new; + SmeObject entry = (SmeObject)cnew; entry->rectangle.border_width = 0; } -/* Function Name: Highlight - * Description: The default highlight proceedure for menu entries. - * Arguments: w - the menu entry. - * Returns: none. +/* + * Function: + * Highlight + * + * Parameters: + * w - menu entry + * + * Description: + * Default highlight proceedure for menu entries. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -Highlight(w) -Widget w; +Highlight(Widget w) { -/* This space intentionally left blank. */ } -/* Function Name: Unhighlight - * Description: The default unhighlight proceedure for menu entries. - * Arguments: w - the menu entry. - * Returns: none. +/* + * Function: + * Unhighlight + * + * Parameters: + * w - menu entry + * + * Description: + * Default unhighlight proceedure for menu entries. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -Unhighlight(w) -Widget w; +Unhighlight(Widget w) { -/* This space intentionally left blank. */ } -/* Function Name: Notify - * Description: calls the callback proceedures for this entry. - * Arguments: w - the menu entry. - * Returns: none. +/* + * Function: + * Notify + * + * Parameters: + * w - menu entry + * + * Description: + * Calls the callback proceedures for this entry. */ - static void -Notify(w) -Widget w; +Notify(Widget w) { - XtCallCallbacks(w, XtNcallback, (XtPointer)NULL); + XtCallCallbacks(w, XtNcallback, NULL); } -/* Function Name: QueryGeometry. - * Description: Returns the preferred geometry for this widget. - * Arguments: w - the menu entry object. - * itended, return - the intended and return geometry info. - * Returns: A Geometry Result. +/* + * Function: + * QueryGeometry * - * See the Intrinsics manual for details on what this function is for. + * Parameeters: + * w - menu entry object + * itended - intended and return geometry info + * return_val - * - * I just return the height and a width of 1. + * Description: + * Returns the preferred geometry for this widget. + * + * Returns: + * Geometry Result + * + * Note: + * See the Intrinsics manual for details on what this function is for. */ - static XtGeometryResult -QueryGeometry(w, intended, return_val) -Widget w; -XtWidgetGeometry *intended, *return_val; +XawSmeQueryGeometry(Widget w, XtWidgetGeometry *intended, + XtWidgetGeometry *return_val) { - SmeObject entry = (SmeObject) w; + SmeObject entry = (SmeObject)w; Dimension width; XtGeometryResult ret_val = XtGeometryYes; XtGeometryMask mode = intended->request_mode; - width = 1; /* we can be really small. */ + width = 1; - if ( ((mode & CWWidth) && (intended->width != width)) || - !(mode & CWWidth) ) { + if (((mode & CWWidth) && intended->width != width) || !(mode & CWWidth)) { return_val->request_mode |= CWWidth; return_val->width = width; mode = return_val->request_mode; - if ( (mode & CWWidth) && (width == entry->rectangle.width) ) - return(XtGeometryNo); - return(XtGeometryAlmost); + if ((mode & CWWidth) && width == XtWidth(entry)) + return (XtGeometryNo); + return (XtGeometryAlmost); } - return(ret_val); + + return (ret_val); } diff --git a/src/SmeBSB.c b/src/SmeBSB.c index 92fb0a6..aac727d 100644 --- a/src/SmeBSB.c +++ b/src/SmeBSB.c @@ -24,6 +24,8 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/SmeBSB.c,v 1.12 2001/12/14 19:54:43 dawes Exp $ */ + /* * SmeBSB.c - Source code file for BSB Menu Entry object. * @@ -34,228 +36,308 @@ in this Software without prior written authorization from The Open Group. * kit@expo.lcs.mit.edu */ +#include <stdio.h> #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> #include <X11/Xos.h> - -/* needed for abs() */ -#ifdef X_NOT_STDC_ENV -extern int abs(); -#else -#include <stdlib.h> -#endif - #include <X11/Xmu/Drawing.h> - -#include <X11/Xaw/XawInit.h> +#include <X11/Xmu/SysUtil.h> +#include <X11/Xaw/Cardinals.h> #include <X11/Xaw/SimpleMenu.h> #include <X11/Xaw/SmeBSBP.h> -#include <X11/Xaw/Cardinals.h> - -#include <stdio.h> +#include <X11/Xaw/XawInit.h> +#include "Private.h" #define ONE_HUNDRED 100 -#define offset(field) XtOffsetOf(SmeBSBRec, sme_bsb.field) - -static XtResource resources[] = { - {XtNlabel, XtCLabel, XtRString, sizeof(String), - offset(label), XtRString, NULL}, - {XtNvertSpace, XtCVertSpace, XtRInt, sizeof(int), - offset(vert_space), XtRImmediate, (XtPointer) 25}, - {XtNleftBitmap, XtCLeftBitmap, XtRBitmap, sizeof(Pixmap), - offset(left_bitmap), XtRImmediate, (XtPointer)None}, - {XtNjustify, XtCJustify, XtRJustify, sizeof(XtJustify), - offset(justify), XtRImmediate, (XtPointer) XtJustifyLeft}, - {XtNrightBitmap, XtCRightBitmap, XtRBitmap, sizeof(Pixmap), - offset(right_bitmap), XtRImmediate, (XtPointer)None}, - {XtNleftMargin, XtCHorizontalMargins, XtRDimension, sizeof(Dimension), - offset(left_margin), XtRImmediate, (XtPointer) 4}, - {XtNrightMargin, XtCHorizontalMargins, XtRDimension, sizeof(Dimension), - offset(right_margin), XtRImmediate, (XtPointer) 4}, - {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), - offset(foreground), XtRString, XtDefaultForeground}, - {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *), - offset(font), XtRString, XtDefaultFont}, - {XtNfontSet, XtCFontSet, XtRFontSet, sizeof(XFontSet ), - offset(fontset),XtRString, XtDefaultFontSet}, -}; -#undef offset - /* - * Semi Public function definitions. + * Class Methods */ - -static void Redisplay(), Destroy(), Initialize(), FlipColors(); -static void ClassInitialize(); -static Boolean SetValues(); -static XtGeometryResult QueryGeometry(); +static void FlipColors(Widget); +static void XawSmeBSBClassInitialize(void); +static void XawSmeBSBInitialize(Widget, Widget, ArgList, Cardinal*); +static void XawSmeBSBDestroy(Widget); +static XtGeometryResult XawSmeBSBQueryGeometry(Widget, XtWidgetGeometry*, + XtWidgetGeometry*); +static void XawSmeBSBRedisplay(Widget, XEvent*, Region); +static Boolean XawSmeBSBSetValues(Widget, Widget, Widget, + ArgList, Cardinal*); /* - * Private Function Definitions. + * Prototypes */ +static void CreateGCs(Widget); +static void GetBitmapInfo(Widget, Bool); +static void GetDefaultSize(Widget, Dimension*, Dimension*); +static void DestroyGCs(Widget); +static void DrawBitmaps(Widget, GC); -static void GetDefaultSize(), DrawBitmaps(), GetBitmapInfo(); -static void CreateGCs(), DestroyGCs(); +/* + * Initialization + */ +#define offset(field) XtOffsetOf(SmeBSBRec, sme_bsb.field) +static XtResource resources[] = { + { + XtNlabel, + XtCLabel, + XtRString, + sizeof(String), + offset(label), + XtRString, + NULL + }, + { + XtNvertSpace, + XtCVertSpace, + XtRInt, + sizeof(int), + offset(vert_space), + XtRImmediate, + (XtPointer)25 + }, + { + XtNleftBitmap, + XtCLeftBitmap, + XtRBitmap, + sizeof(Pixmap), + offset(left_bitmap), + XtRImmediate, + (XtPointer)None + }, + { + XtNjustify, + XtCJustify, + XtRJustify, + sizeof(XtJustify), + offset(justify), + XtRImmediate, + (XtPointer)XtJustifyLeft + }, + { + XtNrightBitmap, + XtCRightBitmap, + XtRBitmap, + sizeof(Pixmap), + offset(right_bitmap), + XtRImmediate, + (XtPointer)None + }, + { + XtNleftMargin, + XtCHorizontalMargins, + XtRDimension, + sizeof(Dimension), + offset(left_margin), + XtRImmediate, + (XtPointer)4 + }, + { + XtNrightMargin, + XtCHorizontalMargins, + XtRDimension, + sizeof(Dimension), + offset(right_margin), + XtRImmediate, + (XtPointer)4 + }, + { + XtNforeground, + XtCForeground, + XtRPixel, + sizeof(Pixel), + offset(foreground), + XtRString, + XtDefaultForeground + }, + { + XtNfont, + XtCFont, + XtRFontStruct, + sizeof(XFontStruct*), + offset(font), + XtRString, + XtDefaultFont + }, + { + XtNfontSet, + XtCFontSet, + XtRFontSet, + sizeof(XFontSet), + offset(fontset), + XtRString, + XtDefaultFontSet + }, +#ifndef OLDXAW + { + XtNmenuName, + XtCMenuName, + XtRString, + sizeof(String), + offset(menu_name), + XtRImmediate, + (XtPointer)NULL + }, +#endif +}; +#undef offset #define superclass (&smeClassRec) SmeBSBClassRec smeBSBClassRec = { + /* rectangle */ + { + (WidgetClass)superclass, /* superclass */ + "SmeBSB", /* class_name */ + sizeof(SmeBSBRec), /* size */ + XawSmeBSBClassInitialize, /* class_init */ + NULL, /* class_part_initialize */ + False, /* class_inited */ + XawSmeBSBInitialize, /* initialize */ + NULL, /* initialize_hook */ + NULL, /* realize */ + NULL, /* actions */ + 0, /* num_actions */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + False, /* compress_motion */ + False, /* compress_exposure */ + False, /* compress_enterleave */ + False, /* visible_interest */ + XawSmeBSBDestroy, /* destroy */ + NULL, /* resize */ + XawSmeBSBRedisplay, /* expose */ + XawSmeBSBSetValues, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + NULL, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* intrinsics version */ + NULL, /* callback offsets */ + NULL, /* tm_table */ + XawSmeBSBQueryGeometry, /* query_geometry */ + NULL, /* display_accelerator */ + NULL, /* extension */ + }, + /* sme */ + { + FlipColors, /* highlight */ + FlipColors, /* unhighlight */ + XtInheritNotify, /* notify */ + NULL, /* extension */ + }, + /* sme_bsb */ { - /* superclass */ (WidgetClass) superclass, - /* class_name */ "SmeBSB", - /* size */ sizeof(SmeBSBRec), - /* class_initializer */ ClassInitialize, - /* class_part_initialize*/ NULL, - /* Class init'ed */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* realize */ NULL, - /* actions */ NULL, - /* num_actions */ ZERO, - /* resources */ resources, - /* resource_count */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ FALSE, - /* compress_exposure */ FALSE, - /* compress_enterleave*/ FALSE, - /* visible_interest */ FALSE, - /* destroy */ Destroy, - /* resize */ NULL, - /* expose */ Redisplay, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* set_values_almost */ XtInheritSetValuesAlmost, - /* get_values_hook */ NULL, - /* accept_focus */ NULL, - /* intrinsics version */ XtVersion, - /* callback offsets */ NULL, - /* tm_table */ NULL, - /* query_geometry */ QueryGeometry, - /* display_accelerator*/ NULL, - /* extension */ NULL - },{ - /* SimpleMenuClass Fields */ - /* highlight */ FlipColors, - /* unhighlight */ FlipColors, - /* notify */ XtInheritNotify, - /* extension */ NULL - }, { - /* BSBClass Fields */ - /* extension */ NULL - } + NULL, /* extension */ + }, }; +WidgetClass smeBSBObjectClass = (WidgetClass)&smeBSBClassRec; -WidgetClass smeBSBObjectClass = (WidgetClass) &smeBSBClassRec; - -/************************************************************ - * - * Semi-Public Functions. +/* + * Function: + * XawSmeBSBClassInitialize * - ************************************************************/ - -/* Function Name: ClassInitialize - * Description: Initializes the SmeBSBObject. - * Arguments: none. - * Returns: none. + * Description: + * Initializes the SmeBSBObject. */ - static void -ClassInitialize() +XawSmeBSBClassInitialize(void) { XawInitializeWidgetSet(); - XtAddConverter( XtRString, XtRJustify, XmuCvtStringToJustify, - (XtConvertArgList)NULL, (Cardinal)0 ); + XtAddConverter(XtRString, XtRJustify, XmuCvtStringToJustify, NULL, 0); + XtSetTypeConverter(XtRJustify, XtRString, XmuCvtJustifyToString, + NULL, 0, XtCacheNone, NULL); } -/* Function Name: Initialize - * Description: Initializes the simple menu widget - * Arguments: request - the widget requested by the argument list. - * new - the new widget with both resource and non - * resource values. - * Returns: none. +/* + * Function: + * XawSmeBSBInitialize + * + * Parameters: + * request - widget requested by the argument list + * cnew - new widget with both resource and non resource values + * + * Description: + * Initializes the simple menu widget entry. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -Initialize(request, new, args, num_args) -Widget request, new; -ArgList args; -Cardinal *num_args; +XawSmeBSBInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - SmeBSBObject entry = (SmeBSBObject) new; + SmeBSBObject entry = (SmeBSBObject)cnew; if (entry->sme_bsb.label == NULL) - entry->sme_bsb.label = XtName(new); + entry->sme_bsb.label = XtName(cnew); else - entry->sme_bsb.label = XtNewString( entry->sme_bsb.label ); + entry->sme_bsb.label = XtNewString(entry->sme_bsb.label); - GetDefaultSize(new, &(entry->rectangle.width), &(entry->rectangle.height)); - CreateGCs(new); + GetDefaultSize(cnew, &entry->rectangle.width, &entry->rectangle.height); + CreateGCs(cnew); entry->sme_bsb.left_bitmap_width = entry->sme_bsb.left_bitmap_height = 0; entry->sme_bsb.right_bitmap_width = entry->sme_bsb.right_bitmap_height = 0; - GetBitmapInfo(new, TRUE); /* Left Bitmap Info */ - GetBitmapInfo(new, FALSE); /* Right Bitmap Info */ + GetBitmapInfo(cnew, True); /* Left Bitmap Info */ + GetBitmapInfo(cnew, False); /* Right Bitmap Info */ } -/* Function Name: Destroy - * Description: Called at destroy time, cleans up. - * Arguments: w - the simple menu widget. - * Returns: none. +/* + * Function: + * XawSmeBSBDestroy + * + * Parameters: + * w - simple menu widget entry */ - static void -Destroy(w) -Widget w; +XawSmeBSBDestroy(Widget w) { - SmeBSBObject entry = (SmeBSBObject) w; + SmeBSBObject entry = (SmeBSBObject)w; DestroyGCs(w); if (entry->sme_bsb.label != XtName(w)) XtFree(entry->sme_bsb.label); } -/* Function Name: Redisplay - * Description: Redisplays the contents of the widget. - * Arguments: w - the simple menu widget. - * event - the X event that caused this redisplay. - * region - the region the needs to be repainted. - * Returns: none. +/* + * Function: + * XawSmeBSBRedisplay + * + * Parameters: + * w - simple menu widget entry + * event - X event that caused this redisplay + * region - region the needs to be repainted + * + * Description: + * Redisplays the contents of the widget. */ - /* ARGSUSED */ static void -Redisplay(w, event, region) -Widget w; -XEvent * event; -Region region; +XawSmeBSBRedisplay(Widget w, XEvent *event, Region region) { GC gc; - SmeBSBObject entry = (SmeBSBObject) w; + SmeBSBObject entry = (SmeBSBObject)w; int font_ascent, font_descent, y_loc; - int fontset_ascent, fontset_descent; XFontSetExtents *ext = XExtentsOfFontSet(entry->sme_bsb.fontset); - entry->sme_bsb.set_values_area_cleared = FALSE; - if ( entry->sme.international == True ) { - fontset_ascent = abs(ext->max_ink_extent.y); - fontset_descent = ext->max_ink_extent.height - fontset_ascent; + font_ascent = font_descent = fontset_ascent = fontset_descent = 0; + entry->sme_bsb.set_values_area_cleared = False; + + if (entry->sme.international == True) { + fontset_ascent = XawAbs(ext->max_ink_extent.y); + fontset_descent = ext->max_ink_extent.height - fontset_ascent; } - else { /*else, compute size from font like R5*/ - font_ascent = entry->sme_bsb.font->max_bounds.ascent; - font_descent = entry->sme_bsb.font->max_bounds.descent; + else { + font_ascent = entry->sme_bsb.font->max_bounds.ascent; + font_descent = entry->sme_bsb.font->max_bounds.descent; } - y_loc = entry->rectangle.y; + y_loc = XtY(entry); - - if (XtIsSensitive(w) && XtIsSensitive( XtParent(w) ) ) { - if ( w == XawSimpleMenuGetActiveEntry(XtParent(w)) ) { + if (XtIsSensitive(w) && XtIsSensitive(XtParent(w))) { + if (w == XawSimpleMenuGetActiveEntry(XtParent(w))) { XFillRectangle(XtDisplayOfObject(w), XtWindowOfObject(w), - entry->sme_bsb.norm_gc, 0, y_loc, - (unsigned int) entry->rectangle.width, - (unsigned int) entry->rectangle.height); + entry->sme_bsb.norm_gc, XtX(w), y_loc, + XtWidth(entry), XtHeight(entry)); gc = entry->sme_bsb.rev_gc; } else @@ -267,159 +349,169 @@ Region region; if (entry->sme_bsb.label != NULL) { int x_loc = entry->sme_bsb.left_margin; int len = strlen(entry->sme_bsb.label); - char * label = entry->sme_bsb.label; + char *label = entry->sme_bsb.label; + int width, t_width; switch(entry->sme_bsb.justify) { - int width, t_width; - - case XtJustifyCenter: - if ( entry->sme.international == True ) { - t_width = XmbTextEscapement(entry->sme_bsb.fontset,label,len); - width = entry->rectangle.width - (entry->sme_bsb.left_margin + + case XtJustifyCenter: + if (entry->sme.international == True) { + t_width = XmbTextEscapement(entry->sme_bsb.fontset,label, + len); + width = XtWidth(entry) - (entry->sme_bsb.left_margin + entry->sme_bsb.right_margin); - } - else { - t_width = XTextWidth(entry->sme_bsb.font, label, len); - width = entry->rectangle.width - (entry->sme_bsb.left_margin + + } + else { + t_width = XTextWidth(entry->sme_bsb.font, label, len); + width = XtWidth(entry) - (entry->sme_bsb.left_margin + entry->sme_bsb.right_margin); - } - x_loc += (width - t_width)/2; - break; - case XtJustifyRight: - if ( entry->sme.international == True ) { - t_width = XmbTextEscapement(entry->sme_bsb.fontset,label,len); - x_loc = entry->rectangle.width - ( entry->sme_bsb.right_margin - + t_width ); - } - else { - t_width = XTextWidth(entry->sme_bsb.font, label, len); - x_loc = entry->rectangle.width - ( entry->sme_bsb.right_margin - + t_width ); - } - break; - case XtJustifyLeft: - default: - break; + } + x_loc += (width - t_width) >> 1; + break; + case XtJustifyRight: + if (entry->sme.international == True) { + t_width = XmbTextEscapement(entry->sme_bsb.fontset,label, + len); + x_loc = XtWidth(entry) - (entry->sme_bsb.right_margin + + t_width); + } + else { + t_width = XTextWidth(entry->sme_bsb.font, label, len); + x_loc = XtWidth(entry) - (entry->sme_bsb.right_margin + + t_width); + } + break; + case XtJustifyLeft: + /*FALLTHROUGH*/ + default: + break; } - /* this will center the text in the gadget top-to-bottom */ - - if ( entry->sme.international==True ) { - y_loc += ((int)entry->rectangle.height - - (fontset_ascent + fontset_descent)) / 2 + fontset_ascent; - - XmbDrawString(XtDisplayOfObject(w), XtWindowOfObject(w), - entry->sme_bsb.fontset, gc, x_loc, y_loc, label, len); - } - else { - y_loc += ((int)entry->rectangle.height - - (font_ascent + font_descent)) / 2 + font_ascent; + if (entry->sme.international == True) { + y_loc += ((XtHeight(entry) - + (fontset_ascent + fontset_descent)) >> 1) + + fontset_ascent; + + XmbDrawString(XtDisplayOfObject(w), XtWindowOfObject(w), + entry->sme_bsb.fontset, gc, + XtX(w) + x_loc, y_loc, label, len); + } + else { + y_loc += ((XtHeight(entry) - + (font_ascent + font_descent)) >> 1) + font_ascent; - XDrawString(XtDisplayOfObject(w), XtWindowOfObject(w), gc, - x_loc, y_loc, label, len); - } + XDrawString(XtDisplayOfObject(w), XtWindowOfObject(w), gc, + XtX(w) + x_loc, y_loc, label, len); + } } DrawBitmaps(w, gc); } -/* Function Name: SetValues - * Description: Relayout the menu when one of the resources is changed. - * Arguments: current - current state of the widget. - * request - what was requested. - * new - what the widget will become. - * Returns: none +/* + * Function: + * XawSmeBSBSetValues + * + * Parameters: + * current - current state of the widget + * request - what was requested + * cnew - what the widget will become + * + * Description: + * Relayout the menu when one of the resources is changed. */ -/* ARGSUSED */ +/*ARGSUSED*/ static Boolean -SetValues(current, request, new, args, num_args) -Widget current, request, new; -ArgList args; -Cardinal *num_args; +XawSmeBSBSetValues(Widget current, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - SmeBSBObject entry = (SmeBSBObject) new; - SmeBSBObject old_entry = (SmeBSBObject) current; - Boolean ret_val = FALSE; + SmeBSBObject entry = (SmeBSBObject)cnew; + SmeBSBObject old_entry = (SmeBSBObject)current; + Boolean ret_val = False; if (old_entry->sme_bsb.label != entry->sme_bsb.label) { - if (old_entry->sme_bsb.label != XtName( new ) ) - XtFree( (char *) old_entry->sme_bsb.label ); + if (old_entry->sme_bsb.label != XtName(cnew)) + XtFree((char *)old_entry->sme_bsb.label); - if (entry->sme_bsb.label != XtName(new) ) - entry->sme_bsb.label = XtNewString( entry->sme_bsb.label ); + if (entry->sme_bsb.label != XtName(cnew)) + entry->sme_bsb.label = XtNewString(entry->sme_bsb.label); ret_val = True; } - if (entry->rectangle.sensitive != old_entry->rectangle.sensitive ) - ret_val = TRUE; + if (entry->rectangle.sensitive != old_entry->rectangle.sensitive) + ret_val = True; if (entry->sme_bsb.left_bitmap != old_entry->sme_bsb.left_bitmap) { - GetBitmapInfo(new, TRUE); - ret_val = TRUE; + GetBitmapInfo(cnew, True); + ret_val = True; } if (entry->sme_bsb.right_bitmap != old_entry->sme_bsb.right_bitmap) { - GetBitmapInfo(new, FALSE); - ret_val = TRUE; + GetBitmapInfo(cnew, False); + ret_val = True; } - if ( ( (old_entry->sme_bsb.font != entry->sme_bsb.font) && - (old_entry->sme.international == False ) ) || - (old_entry->sme_bsb.foreground != entry->sme_bsb.foreground) ) { + if ((old_entry->sme_bsb.font != entry->sme_bsb.font + && old_entry->sme.international == False) + || old_entry->sme_bsb.foreground != entry->sme_bsb.foreground) { DestroyGCs(current); - CreateGCs(new); - ret_val = TRUE; + CreateGCs(cnew); + ret_val = True; } - if ( ( old_entry->sme_bsb.fontset != entry->sme_bsb.fontset) && - (old_entry->sme.international == True ) ) - /* DONT changes the GCs, because the fontset is not in them. */ - ret_val = TRUE; + if (old_entry->sme_bsb.fontset != entry->sme_bsb.fontset && + old_entry->sme.international == True) + /* DONT changes the GCs, because the fontset is not in them */ + ret_val = True; if (ret_val) { - GetDefaultSize(new, - &(entry->rectangle.width), &(entry->rectangle.height)); - entry->sme_bsb.set_values_area_cleared = TRUE; + Dimension width, height; + + GetDefaultSize(cnew, &width, &height); + entry->sme_bsb.set_values_area_cleared = True; + XtMakeResizeRequest(cnew, width, height, NULL, NULL); } - return(ret_val); + + return (ret_val); } -/* Function Name: QueryGeometry. - * Description: Returns the preferred geometry for this widget. - * Arguments: w - the menu entry object. - * itended, return_val - the intended and return geometry info. - * Returns: A Geometry Result. +/* + * Function: + * XawSmeBSBQueryGeometry * - * See the Intrinsics manual for details on what this function is for. + * Parameters: + * w - menu entry object + * itended - intended and return geometry info + * return_val - "" * - * I just return the height and width of the label plus the margins. + * Returns: + * Geometry Result + * + * Description: + * Returns the preferred geometry for this widget. + * See the Intrinsics manual for details on what this function is for. */ - static XtGeometryResult -QueryGeometry(w, intended, return_val) -Widget w; -XtWidgetGeometry *intended, *return_val; +XawSmeBSBQueryGeometry(Widget w, XtWidgetGeometry *intended, + XtWidgetGeometry *return_val) { - SmeBSBObject entry = (SmeBSBObject) w; + SmeBSBObject entry = (SmeBSBObject)w; Dimension width, height; XtGeometryResult ret_val = XtGeometryYes; XtGeometryMask mode = intended->request_mode; - GetDefaultSize(w, &width, &height ); + GetDefaultSize(w, &width, &height); - if ( ((mode & CWWidth) && (intended->width != width)) || - !(mode & CWWidth) ) { + if (((mode & CWWidth) && intended->width != width) || !(mode & CWWidth)) { return_val->request_mode |= CWWidth; return_val->width = width; ret_val = XtGeometryAlmost; } - if ( ((mode & CWHeight) && (intended->height != height)) || - !(mode & CWHeight) ) { + if (((mode & CWHeight) && intended->height != height) || !(mode & CWHeight)) { return_val->request_mode |= CWHeight; return_val->height = height; ret_val = XtGeometryAlmost; @@ -427,286 +519,226 @@ XtWidgetGeometry *intended, *return_val; if (ret_val == XtGeometryAlmost) { mode = return_val->request_mode; - - if ( ((mode & CWWidth) && (width == entry->rectangle.width)) && - ((mode & CWHeight) && (height == entry->rectangle.height)) ) - return(XtGeometryNo); + if (((mode & CWWidth) && width == XtWidth(entry)) && + ((mode & CWHeight) && height == XtHeight(entry))) + return (XtGeometryNo); } - return(ret_val); + return (ret_val); } -/* Function Name: FlipColors - * Description: Invert the colors of the current entry. - * Arguments: w - the bsb menu entry widget. - * Returns: none. +/* + * Function: + * FlipColors + * + * Parameters: + * w - bsb menu entry widget + * + * Description: + * Invert the colors of the current entry. */ - static void -FlipColors(w) -Widget w; +FlipColors(Widget w) { - SmeBSBObject entry = (SmeBSBObject) w; + SmeBSBObject entry = (SmeBSBObject)w; - if (entry->sme_bsb.set_values_area_cleared) { + if (entry->sme_bsb.set_values_area_cleared) return; - } XFillRectangle(XtDisplayOfObject(w), XtWindowOfObject(w), entry->sme_bsb.invert_gc, - 0, (int) entry->rectangle.y, - (unsigned int) entry->rectangle.width, - (unsigned int) entry->rectangle.height); + XtX(w), XtY(entry), XtWidth(entry), XtHeight(entry)); } -/************************************************************ +/* + * Function: + * GetDefaultSize * - * Private Functions. + * Parameters: + * w - menu entry widget. + * width - default width (return) + * height - default height (return) * - ************************************************************/ - -/* Function Name: GetDefaultSize - * Description: Calculates the Default (preferred) size of - * this menu entry. - * Arguments: w - the menu entry widget. - * width, height - default sizes (RETURNED). - * Returns: none. + * Description: + * Calculates the Default (preferred) size of this menu entry. */ - static void -GetDefaultSize(w, width, height) -Widget w; -Dimension * width, * height; +GetDefaultSize(Widget w, Dimension *width, Dimension *height) { - SmeBSBObject entry = (SmeBSBObject) w; + SmeBSBObject entry = (SmeBSBObject)w; - if ( entry->sme.international == True ) { - XFontSetExtents *ext = XExtentsOfFontSet(entry->sme_bsb.fontset); - if (entry->sme_bsb.label == NULL) + if (entry->sme.international == True) { + XFontSetExtents *ext = XExtentsOfFontSet(entry->sme_bsb.fontset); + + if (entry->sme_bsb.label == NULL) *width = 0; - else - *width = XmbTextEscapement(entry->sme_bsb.fontset, entry->sme_bsb.label, - strlen(entry->sme_bsb.label)); - *width += entry->sme_bsb.left_margin + entry->sme_bsb.right_margin; - *height = ext->max_ink_extent.height; - *height = ((int)*height * ( ONE_HUNDRED + - entry->sme_bsb.vert_space )) / ONE_HUNDRED; + else + *width = XmbTextEscapement(entry->sme_bsb.fontset, + entry->sme_bsb.label, + strlen(entry->sme_bsb.label)); + *width += entry->sme_bsb.left_margin + entry->sme_bsb.right_margin; + *height = ext->max_ink_extent.height; + *height = ((int)*height * (ONE_HUNDRED + + entry->sme_bsb.vert_space)) / ONE_HUNDRED; } else { - if (entry->sme_bsb.label == NULL) + if (entry->sme_bsb.label == NULL) *width = 0; - else + else *width = XTextWidth(entry->sme_bsb.font, entry->sme_bsb.label, strlen(entry->sme_bsb.label)); - *width += entry->sme_bsb.left_margin + entry->sme_bsb.right_margin; + *width += entry->sme_bsb.left_margin + entry->sme_bsb.right_margin; - *height = (entry->sme_bsb.font->max_bounds.ascent + - entry->sme_bsb.font->max_bounds.descent); + *height = entry->sme_bsb.font->max_bounds.ascent + + entry->sme_bsb.font->max_bounds.descent; - *height = ((int)*height * ( ONE_HUNDRED + - entry->sme_bsb.vert_space )) / ONE_HUNDRED; + *height = ((int)*height * (ONE_HUNDRED + + entry->sme_bsb.vert_space)) / ONE_HUNDRED; } } -/* Function Name: DrawBitmaps - * Description: Draws left and right bitmaps. - * Arguments: w - the simple menu widget. - * gc - graphics context to use for drawing. - * Returns: none +/* + * Function: + * DrawBitmaps + * + * Parameters: + * w - simple menu widget entry + * gc - graphics context to use for drawing + * + * Description: + * Draws left and right bitmaps. */ - static void -DrawBitmaps(w, gc) -Widget w; -GC gc; +DrawBitmaps(Widget w, GC gc) { int x_loc, y_loc; - SmeBSBObject entry = (SmeBSBObject) w; + SmeBSBObject entry = (SmeBSBObject)w; - if ( (entry->sme_bsb.left_bitmap == None) && - (entry->sme_bsb.right_bitmap == None) ) return; - -/* - * Draw Left Bitmap. - */ - - if (entry->sme_bsb.left_bitmap != None) { - x_loc = (int)(entry->sme_bsb.left_margin - - entry->sme_bsb.left_bitmap_width) / 2; - - y_loc = entry->rectangle.y + - (int)(entry->rectangle.height - - entry->sme_bsb.left_bitmap_height) / 2; - - XCopyPlane(XtDisplayOfObject(w), entry->sme_bsb.left_bitmap, - XtWindowOfObject(w), gc, 0, 0, - entry->sme_bsb.left_bitmap_width, - entry->sme_bsb.left_bitmap_height, x_loc, y_loc, 1); - } - -/* - * Draw Right Bitmap. - */ - - - if (entry->sme_bsb.right_bitmap != None) { - x_loc = entry->rectangle.width - - (int)(entry->sme_bsb.right_margin + - entry->sme_bsb.right_bitmap_width) / 2; - - y_loc = entry->rectangle.y + - (int)(entry->rectangle.height - - entry->sme_bsb.right_bitmap_height) / 2; + if (entry->sme_bsb.left_bitmap == None && + entry->sme_bsb.right_bitmap == None) + return; + + /* + * Draw Left Bitmap + */ + if (entry->sme_bsb.left_bitmap != None) { + x_loc = ((entry->sme_bsb.left_margin - + entry->sme_bsb.left_bitmap_width) >> 1) + XtX(w); + + y_loc = XtY(entry) + ((XtHeight(entry) - + entry->sme_bsb.left_bitmap_height) >> 1); + + XCopyPlane(XtDisplayOfObject(w), entry->sme_bsb.left_bitmap, + XtWindowOfObject(w), gc, 0, 0, + entry->sme_bsb.left_bitmap_width, + entry->sme_bsb.left_bitmap_height, x_loc, y_loc, 1); + } - XCopyPlane(XtDisplayOfObject(w), entry->sme_bsb.right_bitmap, - XtWindowOfObject(w), gc, 0, 0, - entry->sme_bsb.right_bitmap_width, - entry->sme_bsb.right_bitmap_height, x_loc, y_loc, 1); - } + /* + * Draw Right Bitmap + */ + if (entry->sme_bsb.right_bitmap != None) { + x_loc = XtWidth(entry) - ((entry->sme_bsb.right_margin + + entry->sme_bsb.right_bitmap_width) >> 1) + + XtX(w); + y_loc = XtY(entry) + ((XtHeight(entry) - + entry->sme_bsb.right_bitmap_height) >> 1); + + XCopyPlane(XtDisplayOfObject(w), entry->sme_bsb.right_bitmap, + XtWindowOfObject(w), gc, 0, 0, + entry->sme_bsb.right_bitmap_width, + entry->sme_bsb.right_bitmap_height, x_loc, y_loc, 1); + } } -/* Function Name: GetBitmapInfo - * Description: Gets the bitmap information from either of the bitmaps. - * Arguments: w - the bsb menu entry widget. - * is_left - TRUE if we are testing left bitmap, - * FALSE if we are testing the right bitmap. - * Returns: none +/* + * Function: + * GetBitmapInfo + * + * Parameters: + * w - bsb menu entry object + * is_left - True: if we are testing left bitmap + * False: if we are testing the right bitmap + * + * Description: + * Gets the bitmap information from either of the bitmaps. */ - static void -GetBitmapInfo(w, is_left) -Widget w; -Boolean is_left; +GetBitmapInfo(Widget w, Bool is_left) { - SmeBSBObject entry = (SmeBSBObject) w; + SmeBSBObject entry = (SmeBSBObject)w; unsigned int depth, bw; Window root; int x, y; unsigned int width, height; - char buf[BUFSIZ]; - char* bufp; - int len; - char* fmt1 = "%s Could not get %s Bitmap geometry information for menu entry \"%s\""; - char* def1 = "%s Could not get Bitmap geometry information for menu entry"; - char* fmt2 = "%s %s Bitmap of entry \"%s\" is not one bit deep"; - char* def2 = "%s Bitmap of entry is not one bit deep"; - char* Left = "Left"; - char* Right = "Right"; - char* smeobj = "Xaw SmeBSB Object:"; if (is_left) { - if (entry->sme_bsb.left_bitmap != None) { - if (!XGetGeometry(XtDisplayOfObject(w), - entry->sme_bsb.left_bitmap, &root, - &x, &y, &width, &height, &bw, &depth)) { - if ((len = strlen (fmt1) + strlen (smeobj) + strlen (Left) + strlen (XtName (w))) < sizeof buf) - bufp = buf; - else - bufp = XtMalloc (len + 1); - if (bufp == NULL) { - bufp = buf; - (void) sprintf (bufp, def1, smeobj); - } else - (void) sprintf(bufp, fmt1, smeobj, Left, XtName(w)); - XtAppError(XtWidgetToApplicationContext(w), bufp); - if (bufp != buf) XtFree (bufp); - } - if (depth != 1) { - if ((len = strlen (fmt2) + strlen (smeobj) + strlen (Left) + strlen (XtName (w))) < sizeof buf) - bufp = buf; - else - bufp = XtMalloc (len + 1); - if (bufp == NULL) { - bufp = buf; - (void) sprintf (bufp, def2, smeobj); - } else - (void) sprintf(buf, fmt2, smeobj, Left, XtName(w)); - XtAppError(XtWidgetToApplicationContext(w), buf); - if (bufp != buf) XtFree (bufp); - } - entry->sme_bsb.left_bitmap_width = (Dimension) width; - entry->sme_bsb.left_bitmap_height = (Dimension) height; + if (entry->sme_bsb.left_bitmap != None && + XGetGeometry(XtDisplayOfObject(w), + entry->sme_bsb.left_bitmap, &root, + &x, &y, &width, &height, &bw, &depth)) { + entry->sme_bsb.left_bitmap_width = width; + entry->sme_bsb.left_bitmap_height = height; } } - else if (entry->sme_bsb.right_bitmap != None) { - if (!XGetGeometry(XtDisplayOfObject(w), + else if (entry->sme_bsb.right_bitmap != None && + XGetGeometry(XtDisplayOfObject(w), entry->sme_bsb.right_bitmap, &root, &x, &y, &width, &height, &bw, &depth)) { - if ((len = strlen (fmt1) + strlen (smeobj) + strlen (Right) + strlen (XtName (w))) < sizeof buf) - bufp = buf; - else - bufp = XtMalloc (len + 1); - if (bufp == NULL) { - bufp = buf; - (void) sprintf (bufp, def1, smeobj); - } else - (void) sprintf(bufp, fmt1, smeobj, Right, XtName(w)); - XtAppError(XtWidgetToApplicationContext(w), bufp); - if (bufp != buf) XtFree (bufp); - } - if (depth != 1) { - if ((len = strlen (fmt2) + strlen (smeobj) + strlen (Right) + strlen (XtName (w))) < sizeof buf) - bufp = buf; - else - bufp = XtMalloc (len + 1); - if (bufp == NULL) { - bufp = buf; - (void) sprintf (bufp, def2, smeobj); - } else - (void) sprintf(buf, fmt2, smeobj, Right, XtName(w)); - XtAppError(XtWidgetToApplicationContext(w), buf); - if (bufp != buf) XtFree (bufp); - } - entry->sme_bsb.right_bitmap_width = (Dimension) width; - entry->sme_bsb.right_bitmap_height = (Dimension) height; + entry->sme_bsb.right_bitmap_width = width; + entry->sme_bsb.right_bitmap_height = height; } -} +} -/* Function Name: CreateGCs - * Description: Creates all gcs for the simple menu widget. - * Arguments: w - the simple menu widget. - * Returns: none. +/* + * Function: + * CreateGCs + * + * Parameters: + * w - simple menu widget entry + * + * Description: + * Creates all gc's for the simple menu widget. */ - static void -CreateGCs(w) -Widget w; +CreateGCs(Widget w) { - SmeBSBObject entry = (SmeBSBObject) w; + SmeBSBObject entry = (SmeBSBObject)w; XGCValues values; XtGCMask mask, mask_i18n; values.foreground = XtParent(w)->core.background_pixel; values.background = entry->sme_bsb.foreground; values.font = entry->sme_bsb.font->fid; - values.graphics_exposures = FALSE; + values.graphics_exposures = False; mask = GCForeground | GCBackground | GCGraphicsExposures | GCFont; mask_i18n = GCForeground | GCBackground | GCGraphicsExposures; - if ( entry->sme.international == True ) - entry->sme_bsb.rev_gc = XtAllocateGC(w, 0, mask_i18n, &values, GCFont, 0 ); + if (entry->sme.international == True) + entry->sme_bsb.rev_gc = XtAllocateGC(w, 0, mask_i18n, &values, GCFont, 0); else - entry->sme_bsb.rev_gc = XtGetGC(w, mask, &values); + entry->sme_bsb.rev_gc = XtGetGC(w, mask, &values); values.foreground = entry->sme_bsb.foreground; values.background = XtParent(w)->core.background_pixel; - if ( entry->sme.international == True ) - entry->sme_bsb.norm_gc = XtAllocateGC(w, 0, mask_i18n, &values, GCFont, 0 ); + if (entry->sme.international == True) + entry->sme_bsb.norm_gc = XtAllocateGC(w, 0, mask_i18n, &values, GCFont, 0); else - entry->sme_bsb.norm_gc = XtGetGC(w, mask, &values); + entry->sme_bsb.norm_gc = XtGetGC(w, mask, &values); values.fill_style = FillTiled; values.tile = XmuCreateStippledPixmap(XtScreenOfObject(w), entry->sme_bsb.foreground, XtParent(w)->core.background_pixel, XtParent(w)->core.depth); - values.graphics_exposures = FALSE; + values.graphics_exposures = False; mask |= GCTile | GCFillStyle; mask_i18n |= GCTile | GCFillStyle; - if ( entry->sme.international == True ) - entry->sme_bsb.norm_gray_gc = XtAllocateGC(w, 0, mask_i18n, &values, GCFont, 0 ); + if (entry->sme.international == True) + entry->sme_bsb.norm_gray_gc = XtAllocateGC(w, 0, mask_i18n, &values, + GCFont, 0); else - entry->sme_bsb.norm_gray_gc = XtGetGC(w, mask, &values); + entry->sme_bsb.norm_gray_gc = XtGetGC(w, mask, &values); values.foreground ^= values.background; values.background = 0; @@ -715,36 +747,23 @@ Widget w; entry->sme_bsb.invert_gc = XtGetGC(w, mask, &values); } -/* Function Name: DestroyGCs - * Description: Removes all gcs for the simple menu widget. - * Arguments: w - the simple menu widget. - * Returns: none. +/* + * Function: + * DestroyGCs + * + * Parameters: + * w - simple menu widget entry + * + * Description: + * Removes all gc's for the simple menu widget. */ - static void -DestroyGCs(w) -Widget w; +DestroyGCs(Widget w) { - SmeBSBObject entry = (SmeBSBObject) w; + SmeBSBObject entry = (SmeBSBObject)w; XtReleaseGC(w, entry->sme_bsb.norm_gc); XtReleaseGC(w, entry->sme_bsb.norm_gray_gc); XtReleaseGC(w, entry->sme_bsb.rev_gc); XtReleaseGC(w, entry->sme_bsb.invert_gc); } - -#ifdef apollo - -/* - * The apollo compiler that we have optomizes out my code for - * FlipColors() since it is static. and no one executes it in this - * file. I am setting the function pointer into the class structure so - * that it can be called by my parent who will tell me to when to - * highlight and unhighlight. - */ - -void _XawSmeBSBApolloHack () -{ - FlipColors(); -} -#endif /* apollo */ diff --git a/src/SmeLine.c b/src/SmeLine.c index e5d1f25..68a995f 100644 --- a/src/SmeLine.c +++ b/src/SmeLine.c @@ -25,6 +25,7 @@ in this Software without prior written authorization from The Open Group. * * Author: Chris D. Peterson, MIT X Consortium */ +/* $XFree86: xc/lib/Xaw/SmeLine.c,v 1.8 2001/12/14 19:54:43 dawes Exp $ */ /* * Sme.c - Source code for the generic menu entry @@ -39,131 +40,152 @@ in this Software without prior written authorization from The Open Group. #include <stdio.h> #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> - -#include <X11/Xaw/XawInit.h> -#include <X11/Xaw/SmeLineP.h> #include <X11/Xaw/Cardinals.h> - -#define offset(field) XtOffsetOf(SmeLineRec, sme_line.field) -static XtResource resources[] = { - {XtNlineWidth, XtCLineWidth, XtRDimension, sizeof(Dimension), - offset(line_width), XtRImmediate, (XtPointer) 1}, - {XtNstipple, XtCStipple, XtRBitmap, sizeof(Pixmap), - offset(stipple), XtRImmediate, (XtPointer) XtUnspecifiedPixmap}, - {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), - offset(foreground), XtRString, XtDefaultForeground}, -}; -#undef offset +#include <X11/Xaw/SmeLineP.h> +#include <X11/Xaw/XawInit.h> +#include "Private.h" /* - * Function definitions. + * Class Methods */ +static void XawSmeLineDestroy(Widget); +static void XawSmeLineInitialize(Widget, Widget, ArgList, Cardinal*); +static void XawSmeLineRedisplay(Widget, XEvent*, Region); +static Boolean XawSmeLineSetValues(Widget, Widget, Widget, + ArgList, Cardinal*); -static void Redisplay(), Initialize(); -static void DestroyGC(), CreateGC(); -static Boolean SetValues(); -static XtGeometryResult QueryGeometry(); - +/* + * Prototypes + */ +static void CreateGC(Widget); +static void DestroyGC(Widget); -#define SUPERCLASS (&smeClassRec) +/* + * Initialization + */ +#define offset(field) XtOffsetOf(SmeLineRec, sme_line.field) +static XtResource resources[] = { + { + XtNlineWidth, + XtCLineWidth, + XtRDimension, + sizeof(Dimension), + offset(line_width), + XtRImmediate, + (XtPointer)1 + }, + { + XtNstipple, + XtCStipple, + XtRBitmap, + sizeof(Pixmap), + offset(stipple), + XtRImmediate, + (XtPointer)XtUnspecifiedPixmap + }, + { + XtNforeground, + XtCForeground, + XtRPixel, + sizeof(Pixel), + offset(foreground), + XtRString, + XtDefaultForeground + }, +}; +#undef offset +#define Superclass (&smeClassRec) SmeLineClassRec smeLineClassRec = { + /* rectangle */ + { + (WidgetClass)Superclass, /* superclass */ + "SmeLine", /* class_name */ + sizeof(SmeLineRec), /* widget_size */ + XawInitializeWidgetSet, /* class_initialize */ + NULL, /* class_part_initialize */ + False, /* class inited */ + XawSmeLineInitialize, /* initialize */ + NULL, /* initialize_hook */ + NULL, /* realize */ + NULL, /* actions */ + 0, /* num_actions */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + False, /* compress_motion */ + False, /* compress_exposure */ + False, /* compress_enterleave */ + False, /* visible_interest */ + XawSmeLineDestroy, /* destroy */ + NULL, /* resize */ + XawSmeLineRedisplay, /* expose */ + XawSmeLineSetValues, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + NULL, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* intrinsics version */ + NULL, /* callback offsets */ + NULL, /* tm_table */ + XtInheritQueryGeometry, /* query_geometry */ + NULL, /* display_accelerator */ + NULL, /* extension */ + }, + /* sme */ { - /* superclass */ (WidgetClass) SUPERCLASS, - /* class_name */ "SmeLine", - /* size */ sizeof(SmeLineRec), - /* class_initialize */ XawInitializeWidgetSet, - /* class_part_initialize*/ NULL, - /* Class init'ed */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* realize */ NULL, - /* actions */ NULL, - /* num_actions */ ZERO, - /* resources */ resources, - /* resource_count */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ FALSE, - /* compress_exposure */ FALSE, - /* compress_enterleave*/ FALSE, - /* visible_interest */ FALSE, - /* destroy */ DestroyGC, - /* resize */ NULL, - /* expose */ Redisplay, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* set_values_almost */ XtInheritSetValuesAlmost, - /* get_values_hook */ NULL, - /* accept_focus */ NULL, - /* intrinsics version */ XtVersion, - /* callback offsets */ NULL, - /* tm_table */ NULL, - /* query_geometry */ QueryGeometry, - /* display_accelerator*/ NULL, - /* extension */ NULL - },{ - /* Menu Entry Fields */ - - /* highlight */ XtInheritHighlight, - /* unhighlight */ XtInheritUnhighlight, - /* notify */ XtInheritNotify, - /* extension */ NULL - },{ - /* Line Menu Entry Fields */ - /* extension */ NULL + XtInheritHighlight, /* highlight */ + XtInheritUnhighlight, /* unhighlight */ + XtInheritNotify, /* notify */ + NULL, /* extension */ + }, + /* sme_line */ + { + NULL, /* extension */ } }; -WidgetClass smeLineObjectClass = (WidgetClass) &smeLineClassRec; - -/************************************************************ - * - * Semi-Public Functions. - * - ************************************************************/ +WidgetClass smeLineObjectClass = (WidgetClass)&smeLineClassRec; -/* Function Name: Initialize - * Description: Initializes the simple menu widget - * Arguments: request - the widget requested by the argument list. - * new - the new widget with both resource and non - * resource values. - * Returns: none. +/* + * Implementation */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -Initialize(request, new, args, num_args) -Widget request, new; -ArgList args; -Cardinal *num_args; +XawSmeLineInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - SmeLineObject entry = (SmeLineObject) new; + SmeLineObject entry = (SmeLineObject)cnew; - if (entry->rectangle.height == 0) - entry->rectangle.height = entry->sme_line.line_width; + if (XtHeight(entry) == 0) + XtHeight(entry) = entry->sme_line.line_width; - CreateGC(new); + CreateGC(cnew); } -/* Function Name: CreateGC - * Description: Creates the GC for the line entry widget. - * Arguments: w - the Line entry widget. - * Returns: none +/* + * Function: + * CreateGC + * + * Parameters: + * w - Line entry widget + * + * Description: + * Creates the GC for the line entry widget. * + * Note: * We can only share the GC if there is no stipple, because - * we need to change the stipple origin when drawing. + * we need to change the stipple origin when drawing */ - static void -CreateGC(w) -Widget w; +CreateGC(Widget w) { - SmeLineObject entry = (SmeLineObject) w; + SmeLineObject entry = (SmeLineObject)w; XGCValues values; - XtGCMask mask = GCForeground | GCGraphicsExposures | GCLineWidth ; + XtGCMask mask = GCForeground | GCGraphicsExposures | GCLineWidth; values.foreground = entry->sme_line.foreground; - values.graphics_exposures = FALSE; + values.graphics_exposures = False; values.line_width = entry->sme_line.line_width; if (entry->sme_line.stipple != XtUnspecifiedPixmap) { @@ -179,17 +201,16 @@ Widget w; entry->sme_line.gc = XtGetGC(w, mask, &values); } -/* Function Name: DestroyGC - * Description: Destroys the GC when we are done with it. - * Arguments: w - the Line entry widget. - * Returns: none - */ +static void +XawSmeLineDestroy(Widget w) +{ + DestroyGC(w); +} static void -DestroyGC(w) -Widget w; +DestroyGC(Widget w) { - SmeLineObject entry = (SmeLineObject) w; + SmeLineObject entry = (SmeLineObject)w; if (entry->sme_line.stipple != XtUnspecifiedPixmap) XFreeGC(XtDisplayOfObject(w), entry->sme_line.gc); @@ -197,92 +218,47 @@ Widget w; XtReleaseGC(w, entry->sme_line.gc); } -/* Function Name: Redisplay - * Description: Paints the Line - * Arguments: w - the menu entry. - * event, region - NOT USED. - * Returns: none - */ - /*ARGSUSED*/ static void -Redisplay(w, event, region) -Widget w; -XEvent * event; -Region region; +XawSmeLineRedisplay(Widget w, XEvent *event, Region region) { - SmeLineObject entry = (SmeLineObject) w; - int y = entry->rectangle.y + - (int)(entry->rectangle.height - entry->sme_line.line_width) / 2; + SmeLineObject entry = (SmeLineObject)w; + int y = XtY(w) + (((int)XtHeight(w) - entry->sme_line.line_width) >> 1); if (entry->sme_line.stipple != XtUnspecifiedPixmap) XSetTSOrigin(XtDisplayOfObject(w), entry->sme_line.gc, 0, y); XFillRectangle(XtDisplayOfObject(w), XtWindowOfObject(w), - entry->sme_line.gc, - 0, y, (unsigned int) entry->rectangle.width, - (unsigned int) entry->sme_line.line_width ); + entry->sme_line.gc, XtX(w), y, + XtWidth(w), entry->sme_line.line_width); } -/* Function Name: SetValues - * Description: Relayout the menu when one of the resources is changed. - * Arguments: current - current state of the widget. - * request - what was requested. - * new - what the widget will become. - * Returns: none +/* + * Function: + * XawSmeLineSetValues + * + * Parameters: + * current - current state of the widget + * request - what was requested + * cnew - what the widget will become + * + * Description: + * Relayout the menu when one of the resources is changed. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static Boolean -SetValues(current, request, new, args, num_args) -Widget current, request, new; -ArgList args; -Cardinal *num_args; +XawSmeLineSetValues(Widget current, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - SmeLineObject entry = (SmeLineObject) new; - SmeLineObject old_entry = (SmeLineObject) current; + SmeLineObject entry = (SmeLineObject)cnew; + SmeLineObject old_entry = (SmeLineObject)current; - if ( (entry->sme_line.line_width != old_entry->sme_line.line_width) && - (entry->sme_line.stipple != old_entry->sme_line.stipple) ) { + if (entry->sme_line.line_width != old_entry->sme_line.line_width && + entry->sme_line.stipple != old_entry->sme_line.stipple) { DestroyGC(current); - CreateGC(new); - return(TRUE); + CreateGC(cnew); + return (True); } - return(FALSE); -} - -/* Function Name: QueryGeometry. - * Description: Returns the preferred geometry for this widget. - * Arguments: w - the menu entry object. - * itended, return - the intended and return geometry info. - * Returns: A Geometry Result. - * - * See the Intrinsics manual for details on what this function is for. - * - * I just return the height and a width of 1. - */ - -static XtGeometryResult -QueryGeometry(w, intended, return_val) -Widget w; -XtWidgetGeometry *intended, *return_val; -{ - SmeObject entry = (SmeObject) w; - Dimension width; - XtGeometryResult ret_val = XtGeometryYes; - XtGeometryMask mode = intended->request_mode; - width = 1; /* we can be really small. */ - - if ( ((mode & CWWidth) && (intended->width != width)) || - !(mode & CWWidth) ) { - return_val->request_mode |= CWWidth; - return_val->width = width; - mode = return_val->request_mode; - - if ( (mode & CWWidth) && (width == entry->rectangle.width) ) - return(XtGeometryNo); - return(XtGeometryAlmost); - } - return(ret_val); + return (False); } diff --git a/src/StripChart.c b/src/StripChart.c index d2cbf62..dd2bba4 100644 --- a/src/StripChart.c +++ b/src/StripChart.c @@ -46,172 +46,245 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/StripChart.c,v 1.8 2001/12/14 19:54:44 dawes Exp $ */ #include <stdio.h> #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> -#include <X11/Xaw/XawInit.h> -#include <X11/Xaw/StripCharP.h> #include <X11/Xfuncs.h> +#include <X11/Xaw/StripCharP.h> +#include <X11/Xaw/XawInit.h> +#include "Private.h" #define MS_PER_SEC 1000 -/* Private Data */ +/* + * Class Methods + */ +static void XawStripChartInitialize(Widget, Widget, ArgList, Cardinal*); +static void XawStripChartDestroy(Widget); +static void XawStripChartRedisplay(Widget, XEvent*, Region); +static void XawStripChartResize(Widget); +static Boolean XawStripChartSetValues(Widget, Widget, Widget, + ArgList, Cardinal*); -#define offset(field) XtOffsetOf(StripChartRec, field) +/* + * Prototypes + */ +static void CreateGC(StripChartWidget, unsigned int); +static void DestroyGC(StripChartWidget, unsigned int); +static void draw_it(XtPointer, XtIntervalId*); +static void MoveChart(StripChartWidget, Bool); +static int repaint_window(StripChartWidget, int, int); +/* + * Initialization + */ +#define offset(field) XtOffsetOf(StripChartRec, field) static XtResource resources[] = { - {XtNwidth, XtCWidth, XtRDimension, sizeof(Dimension), - offset(core.width), XtRImmediate, (XtPointer) 120}, - {XtNheight, XtCHeight, XtRDimension, sizeof(Dimension), - offset(core.height), XtRImmediate, (XtPointer) 120}, - {XtNupdate, XtCInterval, XtRInt, sizeof(int), - offset(strip_chart.update), XtRImmediate, (XtPointer) 10}, - {XtNminScale, XtCScale, XtRInt, sizeof(int), - offset(strip_chart.min_scale), XtRImmediate, (XtPointer) 1}, - {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), - offset(strip_chart.fgpixel), XtRString, XtDefaultForeground}, - {XtNhighlight, XtCForeground, XtRPixel, sizeof(Pixel), - offset(strip_chart.hipixel), XtRString, XtDefaultForeground}, - {XtNgetValue, XtCCallback, XtRCallback, sizeof(XtPointer), - offset(strip_chart.get_value), XtRImmediate, (XtPointer) NULL}, - {XtNjumpScroll, XtCJumpScroll, XtRInt, sizeof(int), - offset(strip_chart.jump_val), XtRImmediate, (XtPointer) DEFAULT_JUMP}, + { + XtNwidth, + XtCWidth, + XtRDimension, + sizeof(Dimension), + offset(core.width), + XtRImmediate, + (XtPointer) + 120 + }, + { + XtNheight, + XtCHeight, + XtRDimension, + sizeof(Dimension), + offset(core.height), + XtRImmediate, + (XtPointer)120 + }, + { + XtNupdate, + XtCInterval, + XtRInt, + sizeof(int), + offset(strip_chart.update), + XtRImmediate, + (XtPointer)10 + }, + { + XtNminScale, + XtCScale, + XtRInt, + sizeof(int), + offset(strip_chart.min_scale), + XtRImmediate, + (XtPointer)1 + }, + { + XtNforeground, + XtCForeground, + XtRPixel, + sizeof(Pixel), + offset(strip_chart.fgpixel), + XtRString, + XtDefaultForeground + }, + { + XtNhighlight, + XtCForeground, + XtRPixel, + sizeof(Pixel), + offset(strip_chart.hipixel), + XtRString, + XtDefaultForeground + }, + { + XtNgetValue, + XtCCallback, + XtRCallback, + sizeof(XtPointer), + offset(strip_chart.get_value), + XtRImmediate, + NULL + }, + { + XtNjumpScroll, + XtCJumpScroll, + XtRInt, + sizeof(int), + offset(strip_chart.jump_val), + XtRImmediate, + (XtPointer)DEFAULT_JUMP + }, }; - #undef offset -static void Initialize(), Destroy(), Redisplay(), MoveChart(), SetPoints(); -static Boolean SetValues(); -static int repaint_window(); - StripChartClassRec stripChartClassRec = { - { /* core fields */ - /* superclass */ (WidgetClass) &simpleClassRec, - /* class_name */ "StripChart", - /* size */ sizeof(StripChartRec), - /* class_initialize */ XawInitializeWidgetSet, - /* class_part_initialize */ NULL, - /* class_inited */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* realize */ XtInheritRealize, - /* actions */ NULL, - /* num_actions */ 0, - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure */ XtExposeCompressMultiple | - XtExposeGraphicsExposeMerged, - /* compress_enterleave */ TRUE, - /* visible_interest */ FALSE, - /* destroy */ Destroy, - /* resize */ SetPoints, - /* expose */ Redisplay, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* set_values_almost */ NULL, - /* get_values_hook */ NULL, - /* accept_focus */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ NULL, - /* query_geometry */ XtInheritQueryGeometry, - /* display_accelerator */ XtInheritDisplayAccelerator, - /* extension */ NULL - }, - { /* Simple class fields */ - /* change_sensitive */ XtInheritChangeSensitive - } + /* core */ + { + (WidgetClass)&simpleClassRec, /* superclass */ + "StripChart", /* class_name */ + sizeof(StripChartRec), /* widget_size */ + XawInitializeWidgetSet, /* class_initialize */ + NULL, /* class_part_initialize */ + False, /* class_inited */ + XawStripChartInitialize, /* initialize */ + NULL, /* initialize_hook */ + XtInheritRealize, /* realize */ + NULL, /* actions */ + 0, /* num_actions */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + True, /* compress_motion */ + XtExposeCompressMultiple /* compress_exposure */ + | XtExposeGraphicsExposeMerged, + True, /* compress_enterleave */ + False, /* visible_interest */ + XawStripChartDestroy, /* destroy */ + XawStripChartResize, /* resize */ + XawStripChartRedisplay, /* expose */ + XawStripChartSetValues, /* set_values */ + NULL, /* set_values_hook */ + NULL, /* set_values_almost */ + NULL, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + NULL, /* tm_table */ + XtInheritQueryGeometry, /* query_geometry */ + XtInheritDisplayAccelerator, /* display_accelerator */ + NULL, /* extension */ + }, + /* simple */ + { + XtInheritChangeSensitive, /* change_sensitive */ + } }; -WidgetClass stripChartWidgetClass = (WidgetClass) &stripChartClassRec; +WidgetClass stripChartWidgetClass = (WidgetClass)&stripChartClassRec; -/**************************************************************** +/* + * Implementation + */ +/* + * Function: + * CreateGC * - * Private Procedures + * Parameters: + * w - strip chart widget + * which - GC's to create * - ****************************************************************/ - -static void draw_it(); - -/* Function Name: CreateGC - * Description: Creates the GC's - * Arguments: w - the strip chart widget. - * which - which GC's to create. - * Returns: none + * Description: + * Creates the GC's */ - static void -CreateGC(w, which) -StripChartWidget w; -unsigned int which; +CreateGC(StripChartWidget w, unsigned int which) { - XGCValues myXGCV; + XGCValues myXGCV; - if (which & FOREGROUND) { - myXGCV.foreground = w->strip_chart.fgpixel; - w->strip_chart.fgGC = XtGetGC((Widget) w, GCForeground, &myXGCV); - } + if (which & FOREGROUND) { + myXGCV.foreground = w->strip_chart.fgpixel; + w->strip_chart.fgGC = XtGetGC((Widget)w, GCForeground, &myXGCV); + } - if (which & HIGHLIGHT) { - myXGCV.foreground = w->strip_chart.hipixel; - w->strip_chart.hiGC = XtGetGC((Widget) w, GCForeground, &myXGCV); - } + if (which & HIGHLIGHT) { + myXGCV.foreground = w->strip_chart.hipixel; + w->strip_chart.hiGC = XtGetGC((Widget)w, GCForeground, &myXGCV); + } } -/* Function Name: DestroyGC - * Description: Destroys the GC's - * Arguments: w - the strip chart widget. - * which - which GC's to destroy. - * Returns: none +/* + * Function: + * DestroyGC + * + * Arguments: + * w - strip chart widget + * which - which GC's to destroy + * + * Description: + * Destroys the GC's */ - static void -DestroyGC(w, which) -StripChartWidget w; -unsigned int which; +DestroyGC(StripChartWidget w, unsigned int which) { - if (which & FOREGROUND) - XtReleaseGC((Widget) w, w->strip_chart.fgGC); + if (which & FOREGROUND) + XtReleaseGC((Widget)w, w->strip_chart.fgGC); - if (which & HIGHLIGHT) - XtReleaseGC((Widget) w, w->strip_chart.hiGC); + if (which & HIGHLIGHT) + XtReleaseGC((Widget)w, w->strip_chart.hiGC); } -/* ARGSUSED */ -static void Initialize (greq, gnew, args, num_args) - Widget greq, gnew; - ArgList args; - Cardinal *num_args; +/*ARGSUSED*/ +static void +XawStripChartInitialize(Widget greq, Widget gnew, + ArgList args, Cardinal *num_args) { StripChartWidget w = (StripChartWidget)gnew; if (w->strip_chart.update > 0) - w->strip_chart.interval_id = XtAppAddTimeOut( - XtWidgetToApplicationContext(gnew), - w->strip_chart.update * MS_PER_SEC, - draw_it, (XtPointer) gnew); - CreateGC(w, (unsigned int) ALL_GCS); + w->strip_chart.interval_id = + XtAppAddTimeOut(XtWidgetToApplicationContext(gnew), + w->strip_chart.update * MS_PER_SEC, + draw_it, (XtPointer)gnew); + CreateGC(w, ALL_GCS); w->strip_chart.scale = w->strip_chart.min_scale; w->strip_chart.interval = 0; w->strip_chart.max_value = 0.0; w->strip_chart.points = NULL; - SetPoints(w); + XawStripChartResize(gnew); } -static void Destroy (gw) - Widget gw; +static void +XawStripChartDestroy(Widget gw) { - StripChartWidget w = (StripChartWidget)gw; + StripChartWidget w = (StripChartWidget)gw; - if (w->strip_chart.update > 0) - XtRemoveTimeOut (w->strip_chart.interval_id); - if (w->strip_chart.points) - XtFree((char *) w->strip_chart.points); - DestroyGC(w, (unsigned int) ALL_GCS); + if (w->strip_chart.update > 0) + XtRemoveTimeOut(w->strip_chart.interval_id); + if (w->strip_chart.points) + XtFree((char *)w->strip_chart.points); + DestroyGC(w, ALL_GCS); } /* @@ -219,97 +292,88 @@ static void Destroy (gw) * events, but since this is not easily supported until R4 I am * going to hold off until then. */ - -/* ARGSUSED */ -static void Redisplay(w, event, region) - Widget w; - XEvent *event; - Region region; +/*ARGSUSED*/ +static void +XawStripChartRedisplay(Widget w, XEvent *event, Region region) { if (event->type == GraphicsExpose) - (void) repaint_window ((StripChartWidget)w, event->xgraphicsexpose.x, - event->xgraphicsexpose.width); + (void)repaint_window((StripChartWidget)w, event->xgraphicsexpose.x, + event->xgraphicsexpose.width); else - (void) repaint_window ((StripChartWidget)w, event->xexpose.x, - event->xexpose.width); + (void)repaint_window((StripChartWidget)w, event->xexpose.x, + event->xexpose.width); } -/* ARGSUSED */ +/*ARGSUSED*/ static void -draw_it(client_data, id) -XtPointer client_data; -XtIntervalId *id; /* unused */ +draw_it(XtPointer client_data, XtIntervalId *id) { - StripChartWidget w = (StripChartWidget)client_data; - double value; + StripChartWidget w = (StripChartWidget)client_data; + double value; - if (w->strip_chart.update > 0) - w->strip_chart.interval_id = - XtAppAddTimeOut(XtWidgetToApplicationContext( (Widget) w), - w->strip_chart.update * MS_PER_SEC,draw_it,client_data); + if (w->strip_chart.update > 0) + w->strip_chart.interval_id = + XtAppAddTimeOut(XtWidgetToApplicationContext((Widget)w), + w->strip_chart.update * MS_PER_SEC,draw_it, + client_data); - if (w->strip_chart.interval >= (int)w->core.width) - MoveChart( (StripChartWidget) w, TRUE); + if (w->strip_chart.interval >= XtWidth(w)) + MoveChart((StripChartWidget)w, True); - /* Get the value, stash the point and draw corresponding line. */ + /* Get the value, stash the point and draw corresponding line */ + if (w->strip_chart.get_value == NULL) + return; - if (w->strip_chart.get_value == NULL) - return; + XtCallCallbacks((Widget)w, XtNgetValue, (XtPointer)&value); - XtCallCallbacks( (Widget)w, XtNgetValue, (XtPointer)&value ); + /* + * Keep w->strip_chart.max_value up to date, and if this data + * point is off the graph, change the scale to make it fit + */ + if (value > w->strip_chart.max_value) { + w->strip_chart.max_value = value; + if (XtIsRealized((Widget)w) && + w->strip_chart.max_value > w->strip_chart.scale) { + XClearWindow(XtDisplay(w), XtWindow(w)); + w->strip_chart.interval = repaint_window(w, 0, XtWidth(w)); + } + } - /* - * Keep w->strip_chart.max_value up to date, and if this data - * point is off the graph, change the scale to make it fit. - */ - - if (value > w->strip_chart.max_value) { - w->strip_chart.max_value = value; - if (XtIsRealized((Widget)w) && - w->strip_chart.max_value > w->strip_chart.scale) { - XClearWindow( XtDisplay (w), XtWindow (w)); - w->strip_chart.interval = repaint_window(w, 0, (int) w->core.width); - } - } - - w->strip_chart.valuedata[w->strip_chart.interval] = value; - if (XtIsRealized((Widget)w)) { - int y = (int) (w->core.height - - (int)(w->core.height * value) / w->strip_chart.scale); - - XFillRectangle(XtDisplay(w), XtWindow(w), w->strip_chart.fgGC, - w->strip_chart.interval, y, - (unsigned int) 1, w->core.height - y); - /* - * Fill in the graph lines we just painted over. - */ - - if (w->strip_chart.points != NULL) { - w->strip_chart.points[0].x = w->strip_chart.interval; - XDrawPoints(XtDisplay(w), XtWindow(w), w->strip_chart.hiGC, - w->strip_chart.points, w->strip_chart.scale - 1, - CoordModePrevious); - } - - XFlush(XtDisplay(w)); /* Flush output buffers */ - } - w->strip_chart.interval++; /* Next point */ -} /* draw_it */ - -/* Blts data according to current size, then redraws the stripChart window. + w->strip_chart.valuedata[w->strip_chart.interval] = value; + if (XtIsRealized((Widget)w)) { + int y = (int)(XtHeight(w) - XtHeight(w) * value + / w->strip_chart.scale); + + XFillRectangle(XtDisplay(w), XtWindow(w), w->strip_chart.fgGC, + w->strip_chart.interval, y, + 1, XtHeight(w) - y); + + /* + * Fill in the graph lines we just painted over + */ + if (w->strip_chart.points != NULL) { + w->strip_chart.points[0].x = w->strip_chart.interval; + XDrawPoints(XtDisplay(w), XtWindow(w), w->strip_chart.hiGC, + w->strip_chart.points, w->strip_chart.scale - 1, + CoordModePrevious); + } + + XFlush(XtDisplay(w)); /* Flush output buffers */ + } + w->strip_chart.interval++; /* Next point */ +} + +/* Blts data according to current size, then redraws the stripChart window * Next represents the number of valid points in data. Returns the (possibly) * adjusted value of next. If next is 0, this routine draws an empty window * (scale - 1 lines for graph). If next is less than the current window width, * the returned value is identical to the initial value of next and data is * unchanged. Otherwise keeps half a window's worth of data. If data is * changed, then w->strip_chart.max_value is updated to reflect the - * largest data point. + * largest data point */ - static int -repaint_window(w, left, width) -StripChartWidget w; -int left, width; +repaint_window(StripChartWidget w, int left, int width) { int i, j; int next = w->strip_chart.interval; @@ -317,23 +381,22 @@ int left, width; int scalewidth = 0; /* Compute the minimum scale required to graph the data, but don't go - lower than min_scale. */ - if (w->strip_chart.interval != 0 || scale <= (int)w->strip_chart.max_value) - scale = ((int) (w->strip_chart.max_value)) + 1; - if (scale < w->strip_chart.min_scale) - scale = w->strip_chart.min_scale; + lower than min_scale */ + if (w->strip_chart.interval != 0 || scale <= w->strip_chart.max_value) + scale = w->strip_chart.max_value + 1; + if (scale < w->strip_chart.min_scale) + scale = w->strip_chart.min_scale; if (scale != w->strip_chart.scale) { - w->strip_chart.scale = scale; - left = 0; - width = next; - scalewidth = w->core.width; - - SetPoints(w); + w->strip_chart.scale = scale; + left = 0; + width = next; + scalewidth = XtWidth(w); - if (XtIsRealized ((Widget) w)) - XClearWindow (XtDisplay (w), XtWindow (w)); + XawStripChartResize((Widget)w); + if (XtIsRealized((Widget)w)) + XClearWindow(XtDisplay(w), XtWindow(w)); } if (XtIsRealized((Widget)w)) { @@ -341,174 +404,173 @@ int left, width; Window win = XtWindow(w); width += left - 1; - if (!scalewidth) scalewidth = width; + if (!scalewidth) + scalewidth = width; - if (next < ++width) width = next; + if (next < ++width) + width = next; - /* Draw data point lines. */ + /* Draw data point lines */ for (i = left; i < width; i++) { - int y = (int) (w->core.height - - (int)(w->core.height * w->strip_chart.valuedata[i]) / - w->strip_chart.scale); + int y = XtHeight(w) - (XtHeight(w) * w->strip_chart.valuedata[i]) + / w->strip_chart.scale; XFillRectangle(dpy, win, w->strip_chart.fgGC, - i, y, (unsigned int) 1, - (unsigned int) (w->core.height - y)); + i, y, 1, XtHeight(w) - y); } /* Draw graph reference lines */ for (i = 1; i < w->strip_chart.scale; i++) { - j = i * ((int)w->core.height / w->strip_chart.scale); + j = i * ((int)XtHeight(w) / w->strip_chart.scale); XDrawLine(dpy, win, w->strip_chart.hiGC, left, j, scalewidth, j); } } - return(next); + return (next); } -/* Function Name: MoveChart - * Description: moves the chart over when it would run off the end. - * Arguments: w - the load widget. - * blit - blit the bits? (TRUE/FALSE). - * Returns: none. +/* + * Function: + * MoveChart + * + * Parameters: + * w - chart widget + * blit - blit the bits? + * + * Description: + * Moves the chart over when it would run off the end. */ - static void -MoveChart(w, blit) -StripChartWidget w; -Boolean blit; +MoveChart(StripChartWidget w, Bool blit) { double old_max; int left, i, j; int next = w->strip_chart.interval; - if (!XtIsRealized((Widget) w)) return; + if (!XtIsRealized((Widget)w)) + return; - if (w->strip_chart.jump_val < 0) w->strip_chart.jump_val = DEFAULT_JUMP; + if (w->strip_chart.jump_val < 0) + w->strip_chart.jump_val = DEFAULT_JUMP; if (w->strip_chart.jump_val == DEFAULT_JUMP) - j = w->core.width >> 1; /* Half the window width. */ + j = XtWidth(w) >> 1; else { - j = w->core.width - w->strip_chart.jump_val; - if (j < 0) j = 0; + j = (int)XtWidth(w) - w->strip_chart.jump_val; + if (j < 0) + j = 0; } - (void) memmove((char *)(w->strip_chart.valuedata), - (char *)(w->strip_chart.valuedata + next - j), - j * sizeof(double)); + (void)memmove((char *)w->strip_chart.valuedata, + (char *)(w->strip_chart.valuedata + next - j), + j * sizeof(double)); next = w->strip_chart.interval = j; /* * Since we just lost some data, recompute the - * w->strip_chart.max_value. + * w->strip_chart.max_value */ - old_max = w->strip_chart.max_value; w->strip_chart.max_value = 0.0; for (i = 0; i < next; i++) { - if (w->strip_chart.valuedata[i] > w->strip_chart.max_value) - w->strip_chart.max_value = w->strip_chart.valuedata[i]; + if (w->strip_chart.valuedata[i] > w->strip_chart.max_value) + w->strip_chart.max_value = w->strip_chart.valuedata[i]; } - if (!blit) return; /* we are done... */ + if (!blit) + return; - if ( ((int) old_max) != ( (int) w->strip_chart.max_value) ) { - XClearWindow(XtDisplay(w), XtWindow(w)); - repaint_window(w, 0, (int) w->core.width); - return; + if (old_max != w->strip_chart.max_value) { + XClearWindow(XtDisplay(w), XtWindow(w)); + repaint_window(w, 0, XtWidth(w)); + return; } XCopyArea(XtDisplay((Widget)w), XtWindow((Widget)w), XtWindow((Widget)w), - w->strip_chart.hiGC, (int) w->core.width - j, 0, - (unsigned int) j, (unsigned int) w->core.height, - 0, 0); + w->strip_chart.hiGC, (int)XtWidth(w) - j, 0, j, XtHeight(w), 0, 0); XClearArea(XtDisplay((Widget)w), XtWindow((Widget)w), - (int) j, 0, - (unsigned int) w->core.width - j, (unsigned int)w->core.height, - FALSE); + j, 0, XtWidth(w) - j, XtHeight(w), False); /* Draw graph reference lines */ left = j; for (i = 1; i < w->strip_chart.scale; i++) { - j = i * ((int)w->core.height / w->strip_chart.scale); - XDrawLine(XtDisplay((Widget) w), XtWindow( (Widget) w), - w->strip_chart.hiGC, left, j, (int)w->core.width, j); + j = i * (XtHeight(w) / w->strip_chart.scale); + XDrawLine(XtDisplay((Widget)w), XtWindow((Widget)w), + w->strip_chart.hiGC, left, j, XtWidth(w), j); } - return; } -/* ARGSUSED */ -static Boolean SetValues (current, request, new, args, num_args) - Widget current, request, new; - ArgList args; - Cardinal *num_args; +/*ARGSUSED*/ +static Boolean +XawStripChartSetValues(Widget current, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { StripChartWidget old = (StripChartWidget)current; - StripChartWidget w = (StripChartWidget)new; - Boolean ret_val = FALSE; + StripChartWidget w = (StripChartWidget)cnew; + Bool ret_val = False; unsigned int new_gc = NO_GCS; if (w->strip_chart.update != old->strip_chart.update) { if (old->strip_chart.update > 0) - XtRemoveTimeOut (old->strip_chart.interval_id); + XtRemoveTimeOut(old->strip_chart.interval_id); if (w->strip_chart.update > 0) w->strip_chart.interval_id = - XtAppAddTimeOut(XtWidgetToApplicationContext(new), + XtAppAddTimeOut(XtWidgetToApplicationContext(cnew), w->strip_chart.update * MS_PER_SEC, draw_it, (XtPointer)w); } - if ( w->strip_chart.min_scale > (int) ((w->strip_chart.max_value) + 1) ) - ret_val = TRUE; + if (w->strip_chart.min_scale > w->strip_chart.max_value + 1) + ret_val = True; - if ( w->strip_chart.fgpixel != old->strip_chart.fgpixel ) { - new_gc |= FOREGROUND; - ret_val = True; + if (w->strip_chart.fgpixel != old->strip_chart.fgpixel) { + new_gc |= FOREGROUND; + ret_val = True; } - if ( w->strip_chart.hipixel != old->strip_chart.hipixel ) { - new_gc |= HIGHLIGHT; - ret_val = True; + if (w->strip_chart.hipixel != old->strip_chart.hipixel) { + new_gc |= HIGHLIGHT; + ret_val = True; } DestroyGC(old, new_gc); CreateGC(w, new_gc); - return( ret_val ); + return (ret_val); } -/* Function Name: SetPoints - * Description: Sets up the polypoint that will be used to draw in - * the graph lines. - * Arguments: w - the StripChart widget. - * Returns: none. +/* + * Function: + * XawStripChartResize + * + * Parameters: + * w - StripChart widget + * + * Description: + * Sets up the polypoint that will be used to draw in the graph lines. */ - -#define HEIGHT ( (unsigned int) w->core.height) - static void -SetPoints(widget) -Widget widget; +XawStripChartResize(Widget widget) { - StripChartWidget w = (StripChartWidget) widget; - XPoint * points; + StripChartWidget w = (StripChartWidget)widget; + XPoint *points; Cardinal size; int i; - if (w->strip_chart.scale <= 1) { /* no scale lines. */ - XtFree ((char *) w->strip_chart.points); + if (w->strip_chart.scale <= 1) { + XtFree((char *)w->strip_chart.points); w->strip_chart.points = NULL; return; } size = sizeof(XPoint) * (w->strip_chart.scale - 1); - points = (XPoint *) XtRealloc( (XtPointer) w->strip_chart.points, size); + points = (XPoint *)XtRealloc((XtPointer)w->strip_chart.points, size); w->strip_chart.points = points; /* Draw graph reference lines into clip mask */ for (i = 1; i < w->strip_chart.scale; i++) { points[i - 1].x = 0; - points[i - 1].y = HEIGHT / w->strip_chart.scale; + points[i - 1].y = XtHeight(w) / w->strip_chart.scale; } } @@ -47,608 +47,980 @@ SOFTWARE. ******************************************************************/ +/* + * Copyright (c) 1998 by The XFree86 Project, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Except as contained in this notice, the name of the XFree86 Project shall + * not be used in advertising or otherwise to promote the sale, use or other + * dealings in this Software without prior written authorization from the + * XFree86 Project. + */ + +/* $XFree86: xc/lib/Xaw/Text.c,v 3.52 2002/11/03 20:10:25 paulo Exp $ */ + +#include <stdio.h> #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> #include <X11/Shell.h> #include <X11/Xatom.h> +#include <X11/Xfuncs.h> #include <X11/Xutil.h> -#include "XawI18n.h" -#include <stdio.h> - -#include <X11/Xmu/Atoms.h> -#include <X11/Xmu/CharSet.h> -#include <X11/Xmu/Converters.h> -#include <X11/Xmu/StdSel.h> #include <X11/Xmu/Misc.h> - -#include <X11/Xaw/XawInit.h> +#include <X11/Xmu/SysUtil.h> +#include <X11/Xmu/Xmu.h> #include <X11/Xaw/Cardinals.h> -#include <X11/Xaw/Scrollbar.h> -#include <X11/Xaw/TextP.h> #include <X11/Xaw/MultiSinkP.h> +#include <X11/Xaw/TextP.h> +#include <X11/Xaw/TextSrcP.h> +#include <X11/Xaw/TextSinkP.h> +#include <X11/Xaw/Scrollbar.h> #include <X11/Xaw/XawImP.h> - -#include <X11/Xfuncs.h> -#include <ctype.h> /* for isprint() */ +#include <X11/Xaw/XawInit.h> +#include "Private.h" +#include "XawI18n.h" #ifndef MAX_LEN_CT -#define MAX_LEN_CT 6 /* for sequence: ESC $ ( A \xx \xx */ +#define MAX_LEN_CT 6 /* for sequence: ESC $ ( A \xx \xx */ #endif unsigned long FMT8BIT = 0L; unsigned long XawFmt8Bit = 0L; unsigned long XawFmtWide = 0L; -#define SinkClearToBG XawTextSinkClearToBackground +#define SinkClearToBG _XawTextSinkClearToBackground -#define SrcScan XawTextSourceScan -#define SrcRead XawTextSourceRead -#define SrcReplace XawTextSourceReplace -#define SrcSearch XawTextSourceSearch -#define SrcCvtSel XawTextSourceConvertSelection -#define SrcSetSelection XawTextSourceSetSelection +#define SrcScan XawTextSourceScan +#define SrcRead XawTextSourceRead +#define SrcReplace XawTextSourceReplace +#define SrcSearch XawTextSourceSearch +#define SrcCvtSel XawTextSourceConvertSelection +#define SrcSetSelection XawTextSourceSetSelection -#define BIGNUM ((Dimension)32023) -#define MULTI_CLICK_TIME 500L +#define MULTI_CLICK_TIME 500L + +#define SRC_CHANGE_NONE 0 +#define SRC_CHANGE_AFTER 1 +#define SRC_CHANGE_BEFORE 2 +#define SRC_CHANGE_OVERLAP 3 + +#define Superclass (&simpleClassRec) /* * Compute a the maximum length of a cut buffer that we can pass at any * time. The 64 allows for the overhead of the Change Property request. */ - #define MAX_CUT_LEN(dpy) (XMaxRequestSize(dpy) - 64) -#define IsValidLine(ctx, num) ( ((num) == 0) || \ - ((ctx)->text.lt.info[(num)].position != 0) ) +#define ClearWindow(ctx) \ + _XawTextNeedsUpdating((ctx), \ + (ctx)->text.lt.top, \ + (ctx)->text.lt.info[ctx->text.lt.lines].position) + +/* + * Class Methods + */ +static void XawTextClassInitialize(void); +static void XawTextInitialize(Widget, Widget, ArgList, Cardinal*); +static void XawTextRealize(Widget, XtValueMask*, XSetWindowAttributes*); +static void XawTextDestroy(Widget); +static void XawTextResize(Widget); +static void XawTextExpose(Widget, XEvent*, Region); +static Boolean XawTextSetValues(Widget, Widget, Widget, ArgList, Cardinal*); +static void XawTextGetValuesHook(Widget, ArgList, Cardinal*); +static Bool XawTextChangeSensitive(Widget); + +/* + * Prototypes + */ +static XawTextPosition _BuildLineTable(TextWidget, XawTextPosition, int); +static void _CreateCutBuffers(Display*); +static Boolean TextConvertSelection(Widget, Atom*, Atom*, Atom*, XtPointer*, + unsigned long*, int*); +static int CountLines(TextWidget, XawTextPosition, XawTextPosition); +static void CreateHScrollBar(TextWidget); +static void CreateVScrollBar(TextWidget); +static void CvtStringToScrollMode(XrmValuePtr, Cardinal*, + XrmValuePtr, XrmValuePtr); +static Boolean CvtScrollModeToString(Display*, XrmValue*, Cardinal*, + XrmValue*, XrmValue*, XtPointer*); +static void CvtStringToWrapMode(XrmValuePtr, Cardinal*, + XrmValuePtr, XrmValuePtr); +static Boolean CvtWrapModeToString(Display*, XrmValue*, Cardinal*, + XrmValue*, XrmValue*, XtPointer*); +static Boolean CvtStringToJustifyMode(Display*, XrmValue*, Cardinal*, + XrmValue*, XrmValue*, XtPointer*); +static Boolean CvtJustifyModeToString(Display*, XrmValue*, Cardinal*, + XrmValue*, XrmValue*, XtPointer*); +static void DestroyHScrollBar(TextWidget); +static void DestroyVScrollBar(TextWidget); +static void DisplayText(Widget, XawTextPosition, XawTextPosition); +static void OldDisplayText(Widget, XawTextPosition, XawTextPosition); +static void DisplayTextWindow(Widget); +static void DoCopyArea(TextWidget, int, int, unsigned int, unsigned int, + int, int); +static void DoSelection(TextWidget, XawTextPosition, Time, Bool); +static void ExtendSelection(TextWidget, XawTextPosition, Bool); +static XawTextPosition FindGoodPosition(TextWidget, XawTextPosition); +static void FlushUpdate(TextWidget); +static int GetCutBufferNumber(Atom); +static int GetMaxTextWidth(TextWidget); +static unsigned int GetWidestLine(TextWidget); +static void HScroll(Widget, XtPointer, XtPointer); +static void HJump(Widget, XtPointer, XtPointer); +static void InsertCursor(Widget, XawTextInsertState); +static Bool LineAndXYForPosition(TextWidget, XawTextPosition, int*, + int*, int*); +static int LineForPosition(TextWidget, XawTextPosition); +static void TextLoseSelection(Widget, Atom*); +static Bool MatchSelection(Atom, XawTextSelection*); +static void ModifySelection(TextWidget, XawTextPosition, XawTextPosition); +static XawTextPosition PositionForXY(TextWidget, int, int); +static void PositionHScrollBar(TextWidget); +static void PositionVScrollBar(TextWidget); +#ifndef OLDXAW +static int ResolveColumnNumber(TextWidget); +static int ResolveLineNumber(TextWidget); +#endif +static void _SetSelection(TextWidget, XawTextPosition, XawTextPosition, + Atom*, Cardinal); +static void TextSinkResize(Widget); +static void UpdateTextInRectangle(TextWidget, XRectangle*); +static void UpdateTextInLine(TextWidget, int, int, int); +static void VScroll(Widget, XtPointer, XtPointer); +static void VJump(Widget, XtPointer, XtPointer); + +/* + * External + */ +void _XawTextAlterSelection(TextWidget, + XawTextSelectionMode, XawTextSelectionAction, + String*, Cardinal*); +void _XawTextCheckResize(TextWidget); +void _XawTextClearAndCenterDisplay(TextWidget); +void _XawTextExecuteUpdate(TextWidget); +char *_XawTextGetText(TextWidget, XawTextPosition, XawTextPosition); +void _XawTextPrepareToUpdate(TextWidget); +int _XawTextReplace(TextWidget, XawTextPosition, XawTextPosition, + XawTextBlock*); +Atom *_XawTextSelectionList(TextWidget, String*, Cardinal); +void _XawTextSetScrollBars(TextWidget); +void _XawTextSetSelection(TextWidget, XawTextPosition, XawTextPosition, + String*, Cardinal); +void _XawTextVScroll(TextWidget, int); +void XawTextScroll(TextWidget, int, int); +void _XawTextSetSource(Widget, Widget, XawTextPosition, XawTextPosition); +#ifndef OLDXAW +void _XawTextSetLineAndColumnNumber(TextWidget, Bool); +#endif +void _XawTextSourceChanged(Widget, XawTextPosition, XawTextPosition, + XawTextBlock*, int); + +/* Not used by other modules, but were extern on previous versions + * of the library + */ +void _XawTextShowPosition(TextWidget); /* - * Defined in Text.c + * From TextAction.c */ -static void UnrealizeScrollbars(); -static void VScroll(), VJump(), HScroll(), HJump(), ClearWindow(); -static void DisplayTextWindow(), ModifySelection(), PushCopyQueue(); -static void UpdateTextInLine(), UpdateTextInRectangle(), PopCopyQueue(); -static void FlushUpdate(); -static Boolean LineAndXYForPosition(), TranslateExposeRegion(); -static XawTextPosition FindGoodPosition(), _BuildLineTable(); +extern void _XawTextZapSelection(TextWidget, XEvent*, Bool); -void _XawTextAlterSelection(), _XawTextExecuteUpdate(); -void _XawTextSetScrollBars(), _XawTextPrepareToUpdate(); +/* + * From TextSrc.c + */ +void _XawSourceAddText(Widget, Widget); +void _XawSourceRemoveText(Widget, Widget, Bool); +Bool _XawTextSourceNewLineAtEOF(Widget); + +/* + * From TextSink.c + */ +void _XawTextSinkClearToBackground(Widget, int, int, unsigned, unsigned); +void _XawTextSinkDisplayText(Widget, int, int, XawTextPosition, XawTextPosition, + Bool); /**************************************************************** * * Full class record constant * ****************************************************************/ +/* + * From TextTr.c + */ +extern char _XawDefaultTextTranslations[]; static XawTextSelectType defaultSelectTypes[] = { - XawselectPosition, XawselectWord, XawselectLine, XawselectParagraph, - XawselectAll, XawselectNull, + XawselectPosition, XawselectAlphaNumeric, XawselectWord, XawselectLine, + XawselectParagraph, XawselectAll, XawselectNull, }; static XPointer defaultSelectTypesPtr = (XPointer)defaultSelectTypes; -extern char *_XawDefaultTextTranslations1, *_XawDefaultTextTranslations2, - *_XawDefaultTextTranslations3, *_XawDefaultTextTranslations4; static Dimension defWidth = 100; static Dimension defHeight = DEFAULT_TEXT_HEIGHT; #define offset(field) XtOffsetOf(TextRec, field) static XtResource resources[] = { - {XtNwidth, XtCWidth, XtRDimension, sizeof(Dimension), - offset(core.width), XtRDimension, (XtPointer)&defWidth}, - {XtNcursor, XtCCursor, XtRCursor, sizeof(Cursor), - offset(simple.cursor), XtRString, "xterm"}, - {XtNheight, XtCHeight, XtRDimension, sizeof(Dimension), - offset(core.height), XtRDimension, (XtPointer)&defHeight}, - {XtNdisplayPosition, XtCTextPosition, XtRInt, sizeof(XawTextPosition), - offset(text.lt.top), XtRImmediate, (XtPointer)0}, - {XtNinsertPosition, XtCTextPosition, XtRInt, sizeof(XawTextPosition), - offset(text.insertPos), XtRImmediate,(XtPointer)0}, - {XtNleftMargin, XtCMargin, XtRPosition, sizeof (Position), - offset(text.r_margin.left), XtRImmediate, (XtPointer)2}, - {XtNrightMargin, XtCMargin, XtRPosition, sizeof (Position), - offset(text.r_margin.right), XtRImmediate, (XtPointer)4}, - {XtNtopMargin, XtCMargin, XtRPosition, sizeof (Position), - offset(text.r_margin.top), XtRImmediate, (XtPointer)2}, - {XtNbottomMargin, XtCMargin, XtRPosition, sizeof (Position), - offset(text.r_margin.bottom), XtRImmediate, (XtPointer)2}, - {XtNselectTypes, XtCSelectTypes, XtRPointer, - sizeof(XawTextSelectType*), offset(text.sarray), - XtRPointer, (XtPointer)&defaultSelectTypesPtr}, - {XtNtextSource, XtCTextSource, XtRWidget, sizeof (Widget), - offset(text.source), XtRImmediate, NULL}, - {XtNtextSink, XtCTextSink, XtRWidget, sizeof (Widget), - offset(text.sink), XtRImmediate, NULL}, - {XtNdisplayCaret, XtCOutput, XtRBoolean, sizeof(Boolean), - offset(text.display_caret), XtRImmediate, (XtPointer)True}, - {XtNscrollVertical, XtCScroll, XtRScrollMode, sizeof(XawTextScrollMode), - offset(text.scroll_vert), XtRImmediate, (XtPointer) XawtextScrollNever}, - {XtNscrollHorizontal, XtCScroll, XtRScrollMode, sizeof(XawTextScrollMode), - offset(text.scroll_horiz), XtRImmediate, (XtPointer) XawtextScrollNever}, - {XtNwrap, XtCWrap, XtRWrapMode, sizeof(XawTextWrapMode), - offset(text.wrap), XtRImmediate, (XtPointer) XawtextWrapNever}, - {XtNresize, XtCResize, XtRResizeMode, sizeof(XawTextResizeMode), - offset(text.resize), XtRImmediate, (XtPointer) XawtextResizeNever}, - {XtNautoFill, XtCAutoFill, XtRBoolean, sizeof(Boolean), - offset(text.auto_fill), XtRImmediate, (XtPointer) FALSE}, - {XtNunrealizeCallback, XtCCallback, XtRCallback, sizeof(XtPointer), - offset(text.unrealize_callbacks), XtRCallback, (XtPointer) NULL} + { + XtNwidth, + XtCWidth, + XtRDimension, + sizeof(Dimension), + offset(core.width), + XtRDimension, + (XtPointer)&defWidth + }, + { + XtNcursor, + XtCCursor, + XtRCursor, + sizeof(Cursor), + offset(simple.cursor), + XtRString, + "xterm" + }, + { + XtNheight, + XtCHeight, + XtRDimension, + sizeof(Dimension), + offset(core.height), + XtRDimension, + (XtPointer)&defHeight + }, + { + XtNdisplayPosition, + XtCTextPosition, + XtRInt, + sizeof(XawTextPosition), + offset(text.lt.top), + XtRImmediate, + (XtPointer)0 + }, + { + XtNinsertPosition, + XtCTextPosition, + XtRInt, + sizeof(XawTextPosition), + offset(text.insertPos), + XtRImmediate, + (XtPointer)0 + }, + { + XtNleftMargin, + XtCMargin, + XtRPosition, + sizeof(Position), + offset(text.r_margin.left), + XtRImmediate, + (XtPointer)2 + }, + { + XtNrightMargin, + XtCMargin, + XtRPosition, + sizeof(Position), + offset(text.r_margin.right), + XtRImmediate, + (XtPointer)4 + }, + { + XtNtopMargin, + XtCMargin, + XtRPosition, + sizeof(Position), + offset(text.r_margin.top), + XtRImmediate, + (XtPointer)2 + }, + { + XtNbottomMargin, + XtCMargin, + XtRPosition, + sizeof(Position), + offset(text.r_margin.bottom), + XtRImmediate, + (XtPointer)2 + }, + { + XtNselectTypes, + XtCSelectTypes, + XtRPointer, + sizeof(XawTextSelectType*), + offset(text.sarray), + XtRPointer, + (XtPointer)&defaultSelectTypesPtr + }, + { + XtNtextSource, + XtCTextSource, + XtRWidget, + sizeof(Widget), + offset(text.source), + XtRImmediate, + NULL + }, + { + XtNtextSink, + XtCTextSink, + XtRWidget, + sizeof(Widget), + offset(text.sink), + XtRImmediate, + NULL + }, + { + XtNdisplayCaret, + XtCOutput, + XtRBoolean, + sizeof(Boolean), + offset(text.display_caret), + XtRImmediate, + (XtPointer)True + }, + { + XtNscrollVertical, + XtCScroll, + XtRScrollMode, + sizeof(XawTextScrollMode), + offset(text.scroll_vert), + XtRImmediate, + (XtPointer)False + }, + { + XtNscrollHorizontal, + XtCScroll, + XtRScrollMode, + sizeof(XawTextScrollMode), + offset(text.scroll_horiz), + XtRImmediate, + (XtPointer)False + }, + { + XtNwrap, + XtCWrap, + XtRWrapMode, + sizeof(XawTextWrapMode), + offset(text.wrap), + XtRImmediate, + (XtPointer)XawtextWrapNever + }, + { + XtNautoFill, + XtCAutoFill, + XtRBoolean, + sizeof(Boolean), + offset(text.auto_fill), + XtRImmediate, + (XtPointer)False + }, +#ifndef OLDXAW + { + XtNpositionCallback, + XtCCallback, + XtRCallback, + sizeof(XtPointer), + offset(text.position_callbacks), + XtRCallback, + NULL + }, + { + XtNleftColumn, + XtCColumn, + XtRShort, + sizeof(short), + offset(text.left_column), + XtRImmediate, + (XtPointer)0 + }, + { + XtNrightColumn, + XtCColumn, + XtRShort, + sizeof(short), + offset(text.right_column), + XtRImmediate, + (XtPointer)0 + }, + { + XtNjustifyMode, + XtCJustifyMode, + XtRJustifyMode, + sizeof(XawTextJustifyMode), + offset(text.justify), + XtRImmediate, + (XtPointer)XawjustifyLeft + }, +#endif /* OLDXAW */ }; #undef offset -/* ARGSUSED */ -static void -CvtStringToScrollMode(args, num_args, fromVal, toVal) -XrmValuePtr args; /* unused */ -Cardinal *num_args; /* unused */ -XrmValuePtr fromVal; -XrmValuePtr toVal; -{ - static XawTextScrollMode scrollMode; - static XrmQuark QScrollNever, QScrollAlways, QScrollWhenNeeded; - XrmQuark q; - char lowerName[40]; - static Boolean inited = FALSE; - - if ( !inited ) { - QScrollNever = XrmPermStringToQuark(XtEtextScrollNever); - QScrollWhenNeeded = XrmPermStringToQuark(XtEtextScrollWhenNeeded); - QScrollAlways = XrmPermStringToQuark(XtEtextScrollAlways); - inited = TRUE; - } +#define done(address, type) \ + { toVal->size = sizeof(type); toVal->addr = (XPointer)address; } - if (strlen ((char*) fromVal->addr) < sizeof lowerName) { - XmuCopyISOLatin1Lowered (lowerName, (char *)fromVal->addr); - q = XrmStringToQuark(lowerName); +static XrmQuark QWrapNever, QWrapLine, QWrapWord; +#ifndef notdef +static XrmQuark QScrollNever, QScrollWhenNeeded, QScrollAlways; +#endif +static XrmQuark QJustifyLeft, QJustifyRight, QJustifyCenter, QJustifyFull; - if (q == QScrollNever) scrollMode = XawtextScrollNever; - else if (q == QScrollWhenNeeded) scrollMode = XawtextScrollWhenNeeded; - else if (q == QScrollAlways) scrollMode = XawtextScrollAlways; - else { - toVal->size = 0; - toVal->addr = NULL; - return; +/*ARGSUSED*/ +static void +CvtStringToScrollMode(XrmValuePtr args, Cardinal *num_args, + XrmValuePtr fromVal, XrmValuePtr toVal) +{ + static XawTextScrollMode scrollMode = XawtextScrollNever; + XrmQuark q; + char name[32]; + + XmuNCopyISOLatin1Lowered(name, (char *)fromVal->addr, sizeof(name)); + q = XrmStringToQuark(name); + + if (q == QScrollNever || q == QScrollWhenNeeded) + scrollMode = XawtextScrollNever; + else if (q == QScrollAlways) + scrollMode = XawtextScrollAlways; + else if (strcmp(name, "true") == 0 || strcmp(name, "1") == 0) + scrollMode = XawtextScrollAlways; + else if (strcmp(name, "false") == 0 || strcmp(name, "0") == 0) + scrollMode = XawtextScrollNever; + else + XtStringConversionWarning((char *)fromVal->addr, XtRScrollMode); + + done(&scrollMode, XawTextScrollMode); +} + +/*ARGSUSED*/ +static Boolean +CvtScrollModeToString(Display *dpy, XrmValue *args, Cardinal *num_args, + XrmValue *fromVal, XrmValue *toVal, XtPointer *data) +{ + static char *buffer; + Cardinal size; + + switch (*(XawTextScrollMode *)fromVal->addr) { + case XawtextScrollNever: + case XawtextScrollWhenNeeded: + buffer = XtEtextScrollNever; + break; + case XawtextScrollAlways: + buffer = XtEtextScrollAlways; + break; + default: + XawTypeToStringWarning(dpy, XtRScrollMode); + toVal->addr = NULL; + toVal->size = 0; + return (False); } - toVal->size = sizeof scrollMode; - toVal->addr = (XPointer) &scrollMode; - return; - } - toVal->size = 0; - toVal->addr = NULL; + size = strlen(buffer) + 1; + if (toVal->addr != NULL) { + if (toVal->size < size) { + toVal->size = size; + return (False); + } + strcpy((char *)toVal->addr, buffer); + } + else + toVal->addr = (XPointer)buffer; + toVal->size = sizeof(String); + + return (True); } -/* ARGSUSED */ -static void -CvtStringToWrapMode(args, num_args, fromVal, toVal) -XrmValuePtr args; /* unused */ -Cardinal *num_args; /* unused */ -XrmValuePtr fromVal; -XrmValuePtr toVal; -{ - static XawTextWrapMode wrapMode; - static XrmQuark QWrapNever, QWrapLine, QWrapWord; - XrmQuark q; - char lowerName[BUFSIZ]; - static Boolean inited = FALSE; - - if ( !inited ) { - QWrapNever = XrmPermStringToQuark(XtEtextWrapNever); - QWrapLine = XrmPermStringToQuark(XtEtextWrapLine); - QWrapWord = XrmPermStringToQuark(XtEtextWrapWord); - inited = TRUE; - } +/*ARGSUSED*/ +static void +CvtStringToWrapMode(XrmValuePtr args, Cardinal *num_args, + XrmValuePtr fromVal, XrmValuePtr toVal) +{ + static XawTextWrapMode wrapMode = XawtextWrapNever; + XrmQuark q; + char lowerName[6]; - if (strlen ((char*) fromVal->addr) < sizeof lowerName) { - XmuCopyISOLatin1Lowered (lowerName, (char *)fromVal->addr); + XmuNCopyISOLatin1Lowered(lowerName, (char *)fromVal->addr, + sizeof(lowerName)); q = XrmStringToQuark(lowerName); - if (q == QWrapNever) wrapMode = XawtextWrapNever; - else if (q == QWrapLine) wrapMode = XawtextWrapLine; - else if (q == QWrapWord) wrapMode = XawtextWrapWord; - else { - toVal->size = 0; - toVal->addr = NULL; - return; + if (q == QWrapNever) + wrapMode = XawtextWrapNever; + else if (q == QWrapLine) + wrapMode = XawtextWrapLine; + else if (q == QWrapWord) + wrapMode = XawtextWrapWord; + else + XtStringConversionWarning((char *)fromVal->addr, XtRWrapMode); + + done(&wrapMode, XawTextWrapMode); +} + +/*ARGSUSED*/ +static Boolean +CvtWrapModeToString(Display *dpy, XrmValue *args, Cardinal *num_args, + XrmValue *fromVal, XrmValue *toVal, XtPointer *data) +{ + static char *buffer; + Cardinal size; + + switch (*(XawTextWrapMode *)fromVal->addr) { + case XawtextWrapNever: + buffer = XtEtextWrapNever; + break; + case XawtextWrapLine: + buffer = XtEtextWrapLine; + break; + case XawtextWrapWord: + buffer = XtEtextWrapWord; + break; + default: + XawTypeToStringWarning(dpy, XtRWrapMode); + toVal->addr = NULL; + toVal->size = 0; + return (False); } - toVal->size = sizeof wrapMode; - toVal->addr = (XPointer) &wrapMode; - return; - } - toVal->size = 0; - toVal->addr = NULL; + size = strlen(buffer) + 1; + if (toVal->addr != NULL) { + if (toVal->size < size) { + toVal->size = size; + return (False); + } + strcpy((char *)toVal->addr, buffer); + } + else + toVal->addr = (XPointer)buffer; + toVal->size = sizeof(String); + + return (True); } -/* ARGSUSED */ -static void -CvtStringToResizeMode(args, num_args, fromVal, toVal) -XrmValuePtr args; /* unused */ -Cardinal *num_args; /* unused */ -XrmValuePtr fromVal; -XrmValuePtr toVal; -{ - static XawTextResizeMode resizeMode; - static XrmQuark QResizeNever, QResizeWidth, QResizeHeight, QResizeBoth; - XrmQuark q; - char lowerName[40]; - static Boolean inited = FALSE; - - if ( !inited ) { - QResizeNever = XrmPermStringToQuark(XtEtextResizeNever); - QResizeWidth = XrmPermStringToQuark(XtEtextResizeWidth); - QResizeHeight = XrmPermStringToQuark(XtEtextResizeHeight); - QResizeBoth = XrmPermStringToQuark(XtEtextResizeBoth); - inited = TRUE; - } +/*ARGSUSED*/ +static Boolean +CvtStringToJustifyMode(Display *dpy, XrmValue *args, Cardinal *num_args, + XrmValue *fromVal, XrmValue *toVal, XtPointer *data) +{ + XawTextJustifyMode justify; + XrmQuark q; + char lowerName[8]; - if (strlen ((char*) fromVal->addr) < sizeof lowerName) { - XmuCopyISOLatin1Lowered (lowerName, (char *)fromVal->addr); + XmuNCopyISOLatin1Lowered(lowerName, (char *)fromVal->addr, + sizeof(lowerName)); q = XrmStringToQuark(lowerName); - if (q == QResizeNever) resizeMode = XawtextResizeNever; - else if (q == QResizeWidth) resizeMode = XawtextResizeWidth; - else if (q == QResizeHeight) resizeMode = XawtextResizeHeight; - else if (q == QResizeBoth) resizeMode = XawtextResizeBoth; + if (q == QJustifyLeft) + justify = XawjustifyLeft; + else if (q == QJustifyRight) + justify = XawjustifyRight; + else if (q == QJustifyCenter) + justify = XawjustifyCenter; + else if(q == QJustifyFull) + justify = XawjustifyFull; else { - toVal->size = 0; - toVal->addr = NULL; - return; + XtStringConversionWarning((char *)fromVal->addr, XtRJustifyMode); + return (False); } - toVal->size = sizeof resizeMode; - toVal->addr = (XPointer) &resizeMode; - return; - } - toVal->size = 0; - toVal->addr = NULL; + + toVal->size = sizeof(XawTextJustifyMode); + *(XawTextJustifyMode *)(toVal->addr) = justify; + + return (True); } -static void -ClassInitialize() + +/*ARGSUSED*/ +static Boolean +CvtJustifyModeToString(Display *dpy, XrmValue *args, Cardinal *num_args, + XrmValue *fromVal, XrmValue *toVal, XtPointer *data) { - int len1 = strlen (_XawDefaultTextTranslations1); - int len2 = strlen (_XawDefaultTextTranslations2); - int len3 = strlen (_XawDefaultTextTranslations3); - int len4 = strlen (_XawDefaultTextTranslations4); - char *buf = XtMalloc ((unsigned)(len1 + len2 + len3 + len4 + 1)); - char *cp = buf; + static char *buffer; + Cardinal size; + + switch (*(XawTextJustifyMode *)fromVal->addr) { + case XawjustifyLeft: + buffer = XtEtextJustifyLeft; + break; + case XawjustifyRight: + buffer = XtEtextJustifyRight; + break; + case XawjustifyCenter: + buffer = XtEtextJustifyCenter; + break; + case XawjustifyFull: + buffer = XtEtextJustifyFull; + break; + default: + XawTypeToStringWarning(dpy, XtRJustifyMode); + toVal->addr = NULL; + toVal->size = 0; + return (False); + } + size = strlen(buffer) + 1; + if (toVal->addr != NULL) { + if (toVal->size < size) { + toVal->size = size; + return (False); + } + strcpy((char *)toVal->addr, buffer); + } + else + toVal->addr = (XPointer)buffer; + toVal->size = sizeof(String); - if (!XawFmt8Bit) - FMT8BIT = XawFmt8Bit = XrmPermStringToQuark("FMT8BIT"); - if (!XawFmtWide) - XawFmtWide = XrmPermStringToQuark("FMTWIDE"); + return (True); +} - XawInitializeWidgetSet(); +#undef done -/* - * Set the number of actions. - */ +static void +XawTextClassInitialize(void) +{ + if (!XawFmt8Bit) + FMT8BIT = XawFmt8Bit = XrmPermStringToQuark("FMT8BIT"); + if (!XawFmtWide) + XawFmtWide = XrmPermStringToQuark("FMTWIDE"); - textClassRec.core_class.num_actions = _XawTextActionsTableCount; + XawInitializeWidgetSet(); + + textClassRec.core_class.num_actions = _XawTextActionsTableCount; - (void) strcpy( cp, _XawDefaultTextTranslations1); cp += len1; - (void) strcpy( cp, _XawDefaultTextTranslations2); cp += len2; - (void) strcpy( cp, _XawDefaultTextTranslations3); cp += len3; - (void) strcpy( cp, _XawDefaultTextTranslations4); - textWidgetClass->core_class.tm_table = buf; - - XtAddConverter(XtRString, XtRScrollMode, CvtStringToScrollMode, - (XtConvertArgList)NULL, (Cardinal)0 ); - XtAddConverter(XtRString, XtRWrapMode, CvtStringToWrapMode, - (XtConvertArgList)NULL, (Cardinal)0 ); - XtAddConverter(XtRString, XtRResizeMode, CvtStringToResizeMode, - (XtConvertArgList)NULL, (Cardinal)0 ); -} - -/* Function Name: PositionHScrollBar. - * Description: Positions the Horizontal scrollbar. - * Arguments: ctx - the text widget. - * Returns: none - */ + QWrapNever = XrmPermStringToQuark(XtEtextWrapNever); + QWrapLine = XrmPermStringToQuark(XtEtextWrapLine); + QWrapWord = XrmPermStringToQuark(XtEtextWrapWord); + XtAddConverter(XtRString, XtRWrapMode, CvtStringToWrapMode, NULL, 0); + XtSetTypeConverter(XtRWrapMode, XtRString, CvtWrapModeToString, + NULL, 0, XtCacheNone, NULL); + QScrollNever = XrmPermStringToQuark(XtEtextScrollNever); + QScrollWhenNeeded = XrmPermStringToQuark(XtEtextScrollWhenNeeded); + QScrollAlways = XrmPermStringToQuark(XtEtextScrollAlways); + XtAddConverter(XtRString, XtRScrollMode, CvtStringToScrollMode, + NULL, 0); + XtSetTypeConverter(XtRScrollMode, XtRString, CvtScrollModeToString, + NULL, 0, XtCacheNone, NULL); + QJustifyLeft = XrmPermStringToQuark(XtEtextJustifyLeft); + QJustifyRight = XrmPermStringToQuark(XtEtextJustifyRight); + QJustifyCenter = XrmPermStringToQuark(XtEtextJustifyCenter); + QJustifyFull = XrmPermStringToQuark(XtEtextJustifyFull); + XtSetTypeConverter(XtRString, XtRJustifyMode, CvtStringToJustifyMode, + NULL, 0, XtCacheNone, NULL); + XtSetTypeConverter(XtRJustifyMode, XtRString, CvtJustifyModeToString, + NULL, 0, XtCacheNone, NULL); +} +/* + * Function: + * PositionHScrollBar + * + * Parameters: + * ctx - text widget + * + * Description: + * Positions the Horizontal scrollbar. + */ static void -PositionHScrollBar(ctx) -TextWidget ctx; +PositionHScrollBar(TextWidget ctx) { - Widget vbar = ctx->text.vbar, hbar = ctx->text.hbar; - Position top, left = 0; - - if (ctx->text.hbar == NULL) return; + Widget hbar = ctx->text.hbar, vbar = ctx->text.vbar; + Position x, y; + Dimension width, height; - if (vbar != NULL) - left += (Position) (vbar->core.width + vbar->core.border_width); + if (ctx->text.hbar == NULL) + return; - XtResizeWidget( hbar, ctx->core.width - left, hbar->core.height, - hbar->core.border_width ); + if (vbar != NULL) + x = XtWidth(vbar); + else + x = -XtBorderWidth(hbar); + y = XtHeight(ctx) - XtHeight(hbar) - XtBorderWidth(hbar); + if (vbar != NULL) { + width = XtWidth(ctx) - XtWidth(vbar) - XtBorderWidth(vbar); + if (width > XtWidth(ctx)) + width = XtWidth(ctx); + } + else + width = XtWidth(ctx); + height = XtHeight(hbar); - left -= (Position) hbar->core.border_width; - - top = ctx->core.height - ( hbar->core.height + hbar->core.border_width); - XtMoveWidget( hbar, left, top); + XtConfigureWidget(hbar, x, y, width, height, XtBorderWidth(hbar)); } -/* Function Name: PositionVScrollBar. - * Description: Positions the Vertical scrollbar. - * Arguments: ctx - the text widget. - * Returns: none. +/* + * Function: + * PositionVScrollBar + * + * Parameters: + * ctx - text widget + * + * Description: + * Positions the Vertical scrollbar. */ - static void -PositionVScrollBar(ctx) -TextWidget ctx; +PositionVScrollBar(TextWidget ctx) { - Widget vbar = ctx->text.vbar; - Dimension bw; + Widget vbar = ctx->text.vbar; + Position x, y; + Dimension width, height; - if (vbar == NULL) return; - bw = vbar->core.border_width; + if (vbar == NULL) + return; + + x = y = -XtBorderWidth(vbar); + height = XtHeight(ctx); + width = XtWidth(vbar); - XtResizeWidget( vbar, vbar->core.width, ctx->core.height, bw); - XtMoveWidget( vbar, -(Position)bw, -(Position)bw ); + XtConfigureWidget(vbar, x, y, width, height, XtBorderWidth(vbar)); } -static void -CreateVScrollBar(ctx) -TextWidget ctx; +static void +CreateVScrollBar(TextWidget ctx) { - Widget vbar; + Widget vbar; - if (ctx->text.vbar != NULL) return; + if (ctx->text.vbar != NULL) + return; - ctx->text.vbar = vbar = - XtCreateWidget("vScrollbar", scrollbarWidgetClass, (Widget)ctx, - (ArgList) NULL, ZERO); - XtAddCallback( vbar, XtNscrollProc, VScroll, (XtPointer)ctx ); - XtAddCallback( vbar, XtNjumpProc, VJump, (XtPointer)ctx ); - if (ctx->text.hbar == NULL) - XtAddCallback((Widget) ctx, XtNunrealizeCallback, UnrealizeScrollbars, - (XtPointer) NULL); + ctx->text.vbar = vbar = + XtCreateWidget("vScrollbar", scrollbarWidgetClass, (Widget)ctx, NULL, 0); + XtAddCallback(vbar, XtNscrollProc, VScroll, (XtPointer)ctx); + XtAddCallback(vbar, XtNjumpProc, VJump, (XtPointer)ctx); - ctx->text.r_margin.left += vbar->core.width + vbar->core.border_width; - ctx->text.margin.left = ctx->text.r_margin.left; + ctx->text.r_margin.left += XtWidth(vbar) + XtBorderWidth(vbar); + ctx->text.left_margin = ctx->text.margin.left = ctx->text.r_margin.left; - PositionVScrollBar(ctx); - PositionHScrollBar(ctx); /* May modify location of Horiz. Bar. */ + PositionVScrollBar(ctx); + PositionHScrollBar(ctx); + TextSinkResize(ctx->text.sink); - if (XtIsRealized((Widget)ctx)) { - XtRealizeWidget(vbar); - XtMapWidget(vbar); - } + if (XtIsRealized((Widget)ctx)) { + XtRealizeWidget(vbar); + XtMapWidget(vbar); + } + XtSetKeyboardFocus(vbar, (Widget)ctx); } -/* Function Name: DestroyVScrollBar - * Description: Removes a vertical ScrollBar. - * Arguments: ctx - the parent text widget. - * Returns: none. +/* + * Function: + * DestroyVScrollBar + * + * Parameters: + * ctx - parent text widget + * + * Description: + * Removes vertical ScrollBar. */ - static void -DestroyVScrollBar(ctx) -TextWidget ctx; +DestroyVScrollBar(TextWidget ctx) { - Widget vbar = ctx->text.vbar; + Widget vbar = ctx->text.vbar; - if (vbar == NULL) return; + if (vbar == NULL) + return; - ctx->text.r_margin.left -= vbar->core.width + vbar->core.border_width; - ctx->text.margin.left = ctx->text.r_margin.left; - if (ctx->text.hbar == NULL) - XtRemoveCallback((Widget) ctx, XtNunrealizeCallback, UnrealizeScrollbars, - (XtPointer) NULL); - XtDestroyWidget(vbar); - ctx->text.vbar = NULL; - PositionHScrollBar(ctx); -} - -static void -CreateHScrollBar(ctx) -TextWidget ctx; -{ - Arg args[1]; - Widget hbar; - - if (ctx->text.hbar != NULL) return; - - XtSetArg(args[0], XtNorientation, XtorientHorizontal); - ctx->text.hbar = hbar = - XtCreateWidget("hScrollbar", scrollbarWidgetClass, (Widget)ctx, args, ONE); - XtAddCallback( hbar, XtNscrollProc, HScroll, (XtPointer)ctx ); - XtAddCallback( hbar, XtNjumpProc, HJump, (XtPointer)ctx ); - if (ctx->text.vbar == NULL) - XtAddCallback((Widget) ctx, XtNunrealizeCallback, UnrealizeScrollbars, - (XtPointer) NULL); - - PositionHScrollBar(ctx); - if (XtIsRealized((Widget)ctx)) { - XtRealizeWidget(hbar); - XtMapWidget(hbar); - } -} + ctx->text.r_margin.left -= XtWidth(vbar) + XtBorderWidth(vbar); + ctx->text.left_margin = ctx->text.margin.left = ctx->text.r_margin.left; -/* Function Name: DestroyHScrollBar - * Description: Removes a horizontal ScrollBar. - * Arguments: ctx - the parent text widget. - * Returns: none. - */ + XtDestroyWidget(vbar); + ctx->text.vbar = NULL; + if (!ctx->core.being_destroyed) { + PositionHScrollBar(ctx); + TextSinkResize(ctx->text.sink); + } +} static void -DestroyHScrollBar(ctx) -TextWidget ctx; +CreateHScrollBar(TextWidget ctx) { - Widget hbar = ctx->text.hbar; + Arg args[1]; + Widget hbar; + int bottom; - if (hbar == NULL) return; + if (ctx->text.hbar != NULL) + return; -/* - ctx->text.r_margin.bottom -= hbar->core.height + hbar->core.border_width; - ctx->text.margin.bottom = ctx->text.r_margin.bottom; -*/ - if (ctx->text.vbar == NULL) - XtRemoveCallback((Widget) ctx, XtNunrealizeCallback, UnrealizeScrollbars, - (XtPointer) NULL); - XtDestroyWidget(hbar); - ctx->text.hbar = NULL; + XtSetArg(args[0], XtNorientation, XtorientHorizontal); + ctx->text.hbar = hbar = + XtCreateWidget("hScrollbar", scrollbarWidgetClass, (Widget)ctx, args, 1); + XtAddCallback(hbar, XtNscrollProc, HScroll, (XtPointer)ctx); + XtAddCallback(hbar, XtNjumpProc, HJump, (XtPointer)ctx); + + bottom = ctx->text.r_margin.bottom + XtHeight(hbar) + XtBorderWidth(hbar); + + ctx->text.margin.bottom = ctx->text.r_margin.bottom = bottom; + + PositionHScrollBar(ctx); + TextSinkResize(ctx->text.sink); + + if (XtIsRealized((Widget)ctx)) { + XtRealizeWidget(hbar); + XtMapWidget(hbar); + } + XtSetKeyboardFocus(hbar, (Widget)ctx); } -static void warn_msg (w, dir, desc) - Widget w; - char* dir; - char* desc; +/* + * Function: + * DestroyHScrollBar + * + * Parameters: + * ctx - parent text widget + * + * Description: + * Removes horizontal ScrollBar. + */ +static void +DestroyHScrollBar(TextWidget ctx) { - char* fmt = "Xaw Text Widget \"%s\": %s scrolling not allowed with %s.\n%s scrolling has been DEACTIVATED."; - char error_buf[BUFSIZ]; - char* errorp; - int len; + Widget hbar = ctx->text.hbar; + + if (hbar == NULL) + return; - if ((len = strlen (fmt) + strlen (w->core.name) + 2 * strlen (dir) + strlen (desc)) < sizeof error_buf) - errorp = error_buf; - else - errorp = XtMalloc (len + 1); + ctx->text.r_margin.bottom -= XtHeight(hbar) + XtBorderWidth(hbar); + ctx->text.margin.bottom = ctx->text.r_margin.bottom; - if (errorp == NULL) { - errorp = error_buf; - strcpy (errorp, "Scrolling has been DEACTIVATED"); - } else - (void) sprintf (errorp, fmt, w->core.name, dir, desc, dir); - XtAppWarning (XtWidgetToApplicationContext (w), errorp); + XtDestroyWidget(hbar); + ctx->text.hbar = NULL; + if (!ctx->core.being_destroyed) + TextSinkResize(ctx->text.sink); } -/* ARGSUSED */ -static void -Initialize(request, new, args, num_args) -Widget request, new; -ArgList args; /* unused */ -Cardinal *num_args; /* unused */ -{ - TextWidget ctx = (TextWidget) new; - char* Horizontal = "Horizontal"; - - ctx->text.lt.lines = 0; - ctx->text.lt.info = NULL; - (void) bzero((char *) &(ctx->text.origSel), sizeof(XawTextSelection)); - (void) bzero((char *) &(ctx->text.s), sizeof(XawTextSelection)); - ctx->text.s.type = XawselectPosition; - ctx->text.salt = NULL; - ctx->text.hbar = ctx->text.vbar = (Widget) NULL; - ctx->text.lasttime = 0; /* ||| correct? */ - ctx->text.time = 0; /* ||| correct? */ - ctx->text.showposition = TRUE; - ctx->text.lastPos = (ctx->text.source != NULL) ? GETLASTPOS : 0; - ctx->text.file_insert = NULL; - ctx->text.search = NULL; - ctx->text.updateFrom = (XawTextPosition *) XtMalloc((unsigned) ONE); - ctx->text.updateTo = (XawTextPosition *) XtMalloc((unsigned) ONE); - ctx->text.numranges = ctx->text.maxranges = 0; - ctx->text.gc = DefaultGCOfScreen(XtScreen(ctx)); - ctx->text.hasfocus = FALSE; - ctx->text.margin = ctx->text.r_margin; /* Strucure copy. */ - ctx->text.update_disabled = FALSE; - ctx->text.old_insert = -1; - ctx->text.mult = 1; - ctx->text.single_char = FALSE; - ctx->text.copy_area_offsets = NULL; - ctx->text.salt2 = NULL; - - if (ctx->core.height == DEFAULT_TEXT_HEIGHT) { - ctx->core.height = VMargins(ctx); - if (ctx->text.sink != NULL) - ctx->core.height += XawTextSinkMaxHeight(ctx->text.sink, 1); - } +/*ARGSUSED*/ +static void +XawTextInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) +{ + TextWidget ctx = (TextWidget)cnew; - if (ctx->text.scroll_vert != XawtextScrollNever) - if ( (ctx->text.resize == XawtextResizeHeight) || - (ctx->text.resize == XawtextResizeBoth) ) { - warn_msg (ctx, "Vertical", "height resize"); - ctx->text.scroll_vert = XawtextScrollNever; - } - else if (ctx->text.scroll_vert == XawtextScrollAlways) - CreateVScrollBar(ctx); + ctx->text.lt.lines = 0; + ctx->text.lt.info = (XawTextLineTableEntry *) + XtCalloc(1, sizeof(XawTextLineTableEntry)); +#ifndef OLDXAW + ctx->text.lt.base_line = 1; +#endif + (void)bzero(&ctx->text.origSel, sizeof(XawTextSelection)); + (void)bzero(&ctx->text.s, sizeof(XawTextSelection)); + ctx->text.s.type = XawselectPosition; + ctx->text.salt = NULL; + ctx->text.hbar = ctx->text.vbar = NULL; + ctx->text.lasttime = 0; + ctx->text.time = 0; + ctx->text.showposition = True; + ctx->text.lastPos = ctx->text.source != NULL ? + XawTextGetLastPosition(ctx) : 0; + ctx->text.file_insert = NULL; + ctx->text.search = NULL; + ctx->text.update = XmuNewScanline(0, 0, 0); + ctx->text.gc = DefaultGCOfScreen(XtScreen(ctx)); + ctx->text.hasfocus = False; + ctx->text.margin = ctx->text.r_margin; /* Strucure copy */ + ctx->text.left_margin = ctx->text.r_margin.left; + ctx->text.update_disabled = False; + ctx->text.clear_to_eol = True; + ctx->text.old_insert = -1; + ctx->text.mult = 1; + ctx->text.salt2 = NULL; + ctx->text.from_left = -1; + +#ifndef OLDXAW + ctx->text.numeric = False; + ctx->text.selection_state = False; + ctx->text.kill_ring = 0; + + ctx->text.line_number = -1; + ctx->text.column_number = -1; + ctx->text.source_changed = SRC_CHANGE_NONE; + + ctx->text.kill_ring_ptr = NULL; + ctx->text.overwrite = False; +#endif - if (ctx->text.scroll_horiz != XawtextScrollNever) - if (ctx->text.wrap != XawtextWrapNever) { - warn_msg (ctx, Horizontal, "wrapping active"); - ctx->text.scroll_horiz = XawtextScrollNever; + if (XtHeight(ctx) == DEFAULT_TEXT_HEIGHT) { + XtHeight(ctx) = VMargins(ctx); + if (ctx->text.sink != NULL) + XtHeight(ctx) += XawTextSinkMaxHeight(ctx->text.sink, 1); } - else if ( (ctx->text.resize == XawtextResizeWidth) || - (ctx->text.resize == XawtextResizeBoth) ) { - warn_msg (ctx, Horizontal, "width resize"); - ctx->text.scroll_horiz = XawtextScrollNever; - } - else if (ctx->text.scroll_horiz == XawtextScrollAlways) - CreateHScrollBar(ctx); + + if (ctx->text.scroll_vert == XawtextScrollAlways) + CreateVScrollBar(ctx); + if (ctx->text.scroll_horiz == XawtextScrollAlways) + CreateHScrollBar(ctx); + +#ifndef OLDXAW + if (ctx->text.left_column < 0) + ctx->text.left_column = 0; + if (ctx->text.right_column < 0) + ctx->text.right_column = 0; +#endif } -static void -Realize( w, valueMask, attributes ) -Widget w; -Mask *valueMask; -XSetWindowAttributes *attributes; +static void +XawTextRealize(Widget w, XtValueMask *mask, XSetWindowAttributes *attr) { - TextWidget ctx = (TextWidget)w; - void _XawTextCheckResize(); + TextWidget ctx = (TextWidget)w; - (*textClassRec.core_class.superclass->core_class.realize) - (w, valueMask, attributes); + (*textClassRec.core_class.superclass->core_class.realize)(w, mask, attr); - if (ctx->text.hbar != NULL) { /* Put up Hbar -- Must be first. */ - XtRealizeWidget(ctx->text.hbar); - XtMapWidget(ctx->text.hbar); - } + if (ctx->text.hbar != NULL) { + XtRealizeWidget(ctx->text.hbar); + XtMapWidget(ctx->text.hbar); + } - if (ctx->text.vbar != NULL) { /* Put up Vbar. */ - XtRealizeWidget(ctx->text.vbar); - XtMapWidget(ctx->text.vbar); - } + if (ctx->text.vbar != NULL) { + XtRealizeWidget(ctx->text.vbar); + XtMapWidget(ctx->text.vbar); + } - _XawTextBuildLineTable(ctx, ctx->text.lt.top, TRUE); - _XawTextSetScrollBars(ctx); - _XawTextCheckResize(ctx); -} + _XawTextBuildLineTable(ctx, ctx->text.lt.top, True); -/*ARGSUSED*/ -static void UnrealizeScrollbars(widget, client, call) -Widget widget; /* Text widget */ -XtPointer client; /* unused */ -XtPointer call; /* unused */ -{ - TextWidget ctx = (TextWidget) widget; - - if (ctx->text.hbar) - XtUnrealizeWidget(ctx->text.hbar); - if (ctx->text.vbar) - XtUnrealizeWidget(ctx->text.vbar); +#ifndef OLDXAW + _XawTextSetLineAndColumnNumber(ctx, True); +#endif } /* Utility routines for support of Text */ - static void -_CreateCutBuffers(d) -Display *d; +_CreateCutBuffers(Display *d) { - static struct _DisplayRec { - struct _DisplayRec *next; - Display *dpy; - } *dpy_list = NULL; - struct _DisplayRec *dpy_ptr; - - for (dpy_ptr = dpy_list; dpy_ptr != NULL; dpy_ptr = dpy_ptr->next) - if (dpy_ptr->dpy == d) return; + static struct _DisplayRec { + struct _DisplayRec *next; + Display *dpy; + } *dpy_list = NULL; + struct _DisplayRec *dpy_ptr; + + for (dpy_ptr = dpy_list; dpy_ptr != NULL; dpy_ptr = dpy_ptr->next) + if (dpy_ptr->dpy == d) + return; - dpy_ptr = XtNew(struct _DisplayRec); - dpy_ptr->next = dpy_list; - dpy_ptr->dpy = d; - dpy_list = dpy_ptr; + dpy_ptr = XtNew(struct _DisplayRec); + dpy_ptr->next = dpy_list; + dpy_ptr->dpy = d; + dpy_list = dpy_ptr; #define Create(buffer) \ - XChangeProperty(d, RootWindow(d, 0), buffer, XA_STRING, 8, \ - PropModeAppend, NULL, 0 ); - - Create( XA_CUT_BUFFER0 ); - Create( XA_CUT_BUFFER1 ); - Create( XA_CUT_BUFFER2 ); - Create( XA_CUT_BUFFER3 ); - Create( XA_CUT_BUFFER4 ); - Create( XA_CUT_BUFFER5 ); - Create( XA_CUT_BUFFER6 ); - Create( XA_CUT_BUFFER7 ); + XChangeProperty(d, RootWindow(d, 0), buffer, XA_STRING, 8, \ + PropModeAppend, NULL, 0); + + Create(XA_CUT_BUFFER0); + Create(XA_CUT_BUFFER1); + Create(XA_CUT_BUFFER2); + Create(XA_CUT_BUFFER3); + Create(XA_CUT_BUFFER4); + Create(XA_CUT_BUFFER5); + Create(XA_CUT_BUFFER6); + Create(XA_CUT_BUFFER7); #undef Create } @@ -658,72 +1030,53 @@ Display *d; * the value of ctx->insertPos and an implicit argument. In the event that * position is immediately preceded by an eol graphic, then the insert cursor * is displayed at the beginning of the next line. -*/ -static void -InsertCursor (w, state) -Widget w; -XawTextInsertState state; -{ - TextWidget ctx = (TextWidget)w; - Position x, y; - int line; - - if (ctx->text.lt.lines < 1) return; + */ +static void +InsertCursor(Widget w, XawTextInsertState state) +{ + TextWidget ctx = (TextWidget)w; + int x, y; + int line; - if ( LineAndXYForPosition(ctx, ctx->text.insertPos, &line, &x, &y) ) { - if (line < ctx->text.lt.lines) - y += (ctx->text.lt.info[line + 1].y - ctx->text.lt.info[line].y) + 1; - else - y += (ctx->text.lt.info[line].y - ctx->text.lt.info[line - 1].y) + 1; + if (ctx->text.lt.lines < 1) + return; - if (ctx->text.display_caret) - XawTextSinkInsertCursor(ctx->text.sink, x, y, state); - } - ctx->text.ev_x = x; - ctx->text.ev_y = y; + if (ctx->text.display_caret && + LineAndXYForPosition(ctx, ctx->text.insertPos, &line, &x, &y)) { + if (line < ctx->text.lt.lines) + y += (ctx->text.lt.info[line + 1].y - ctx->text.lt.info[line].y) + 1; + else + y += (ctx->text.lt.info[line].y - ctx->text.lt.info[line - 1].y) + 1; - /* Keep Input Method up to speed */ + XawTextSinkInsertCursor(ctx->text.sink, x, y, state); + } - if ( ctx->simple.international ) { - Arg list[1]; + /* Keep Input Method up to speed */ + if (ctx->simple.international) { + Arg list[1]; - XtSetArg (list[0], XtNinsertPosition, ctx->text.insertPos); - _XawImSetValues (w, list, 1); - } + XtSetArg(list[0], XtNinsertPosition, ctx->text.insertPos); + _XawImSetValues(w, list, 1); + } } /* * Procedure to register a span of text that is no longer valid on the display * It is used to avoid a number of small, and potentially overlapping, screen - * updates. + * updates. */ - void -_XawTextNeedsUpdating(ctx, left, right) -TextWidget ctx; -XawTextPosition left, right; -{ - int i; - if (left < right) { - for (i = 0; i < ctx->text.numranges; i++) { - if (left <= ctx->text.updateTo[i] && right >= ctx->text.updateFrom[i]) { - ctx->text.updateFrom[i] = Min(left, ctx->text.updateFrom[i]); - ctx->text.updateTo[i] = Max(right, ctx->text.updateTo[i]); +_XawTextNeedsUpdating(TextWidget ctx, + XawTextPosition left, XawTextPosition right) +{ + XmuSegment segment; + + if (left >= right) return; - } - } - ctx->text.numranges++; - if (ctx->text.numranges > ctx->text.maxranges) { - ctx->text.maxranges = ctx->text.numranges; - i = ctx->text.maxranges * sizeof(XawTextPosition); - ctx->text.updateFrom = (XawTextPosition *) - XtRealloc((char *)ctx->text.updateFrom, (unsigned) i); - ctx->text.updateTo = (XawTextPosition *) - XtRealloc((char *)ctx->text.updateTo, (unsigned) i); - } - ctx->text.updateFrom[ctx->text.numranges - 1] = left; - ctx->text.updateTo[ctx->text.numranges - 1] = right; - } + + segment.x1 = (int)left; + segment.x2 = (int)right; + (void)XmuScanlineOrSegment(ctx->text.update, &segment); } /* @@ -731,174 +1084,161 @@ XawTextPosition left, right; * we probably need to add a function to sources to provide this functionality. * [note: this is really a private procedure but is used in multiple modules]. */ - char * -_XawTextGetText(ctx, left, right) -TextWidget ctx; -XawTextPosition left, right; -{ - char *result, *tempResult; - XawTextBlock text; - int bytes; - - if (_XawTextFormat(ctx) == XawFmt8Bit) - bytes = sizeof(unsigned char); - else if (_XawTextFormat(ctx) == XawFmtWide) - bytes = sizeof(wchar_t); - else /* if there is another fomat, add here */ - bytes = 1; - - /* leave space for ZERO */ - tempResult=result=XtMalloc( (unsigned)(((Cardinal)(right-left))+ONE )* bytes); - while (left < right) { - left = SrcRead(ctx->text.source, left, &text, (int)(right - left)); - if (!text.length) - break; - memmove(tempResult, text.ptr, text.length * bytes); - tempResult += text.length * bytes; - } +_XawTextGetText(TextWidget ctx, XawTextPosition left, XawTextPosition right) +{ + char *result, *tempResult; + XawTextBlock text; + int bytes; + + if (XawTextFormat(ctx, XawFmt8Bit)) + bytes = sizeof(unsigned char); + else if (XawTextFormat(ctx, XawFmtWide)) + bytes = sizeof(wchar_t); + else /* if there is another fomat, add here */ + bytes = 1; + + /* leave space for ZERO */ + tempResult = result = XtMalloc((unsigned)(right - left + ONE) * bytes); + + while (left < right) { + left = SrcRead(ctx->text.source, left, &text, (int)(right - left)); + if (!text.length) + break; + memmove(tempResult, text.ptr, (unsigned)(text.length * bytes)); + tempResult += text.length * bytes; + } + + if (bytes == sizeof(wchar_t)) + *((wchar_t*)tempResult) = (wchar_t)0; + else + *tempResult = '\0'; - if (bytes == sizeof(wchar_t)) - *((wchar_t*)tempResult) = (wchar_t)0; - else - *tempResult = '\0'; - return(result); + return (result); } /* Like _XawTextGetText, but enforces ICCCM STRING type encoding. This -routine is currently used to put just the ASCII chars in the selection into a -cut buffer. */ - + * routine is currently used to put just the ASCII chars in the selection + * into a cut buffer. + */ char * -_XawTextGetSTRING(ctx, left, right) -TextWidget ctx; -XawTextPosition left, right; -{ - unsigned char *s; - unsigned char c; - long i, j, n; - wchar_t *ws, wc; - - /* allow ESC in accordance with ICCCM */ - if (_XawTextFormat(ctx) == XawFmtWide) { - MultiSinkObject sink = (MultiSinkObject) ctx->text.sink; - ws = (wchar_t *)_XawTextGetText(ctx, left, right); - n = wcslen(ws); - for (j = 0, i = 0; j < n; j++) { - wc = ws[j]; - if (XwcTextEscapement (sink->multi_sink.fontset, &wc, 1) || - (wc == _Xaw_atowc(XawTAB)) || (wc == _Xaw_atowc(XawLF)) || (wc == _Xaw_atowc(XawESC))) - ws[i++] = wc; - } - ws[i] = (wchar_t)0; - return (char *)ws; - } else { - s = (unsigned char *)_XawTextGetText(ctx, left, right); - /* only HT and NL control chars are allowed, strip out others */ - n = strlen((char *)s); - i = 0; - for (j = 0; j < n; j++) { - c = s[j]; - if (((c >= 0x20) && c <= 0x7f) || - (c >= 0xa0) || (c == XawTAB) || (c == XawLF) || (c == XawESC)) { - s[i] = c; - i++; +_XawTextGetSTRING(TextWidget ctx, XawTextPosition left, XawTextPosition right) +{ + unsigned char *s; + unsigned char c; + long i, j, n; + wchar_t *ws, wc; + + /* allow ESC in accordance with ICCCM */ + if (XawTextFormat(ctx, XawFmtWide)) { + MultiSinkObject sink = (MultiSinkObject)ctx->text.sink; + ws = (wchar_t *)_XawTextGetText(ctx, left, right); + n = wcslen(ws); + for (j = 0, i = 0; j < n; j++) { + wc = ws[j]; + if (XwcTextEscapement (sink->multi_sink.fontset, &wc, 1) + || (wc == _Xaw_atowc(XawTAB)) || (wc == _Xaw_atowc(XawLF)) + || (wc == _Xaw_atowc(XawESC))) + ws[i++] = wc; } - } - s[i] = 0; - return (char *)s; - } -#undef ESC + ws[i] = (wchar_t)0; + return ((char *)ws); + } + else { + s = (unsigned char *)_XawTextGetText(ctx, left, right); + /* only HT and NL control chars are allowed, strip out others */ + n = strlen((char *)s); + i = 0; + for (j = 0; j < n; j++) { + c = s[j]; + if (((c >= 0x20) && c <= 0x7f) + ||(c >= 0xa0) || (c == XawTAB) || (c == XawLF) + || (c == XawESC)) { + s[i] = c; + i++; + } + } + s[i] = 0; + return ((char *)s); + } } /* * This routine maps an x and y position in a window that is displaying text * into the corresponding position in the source. - * - * NOTE: it is illegal to call this routine unless there is a valid line table! */ - -/*** figure out what line it is on ***/ - static XawTextPosition -PositionForXY (ctx, x, y) -TextWidget ctx; -Position x,y; +PositionForXY(TextWidget ctx, int x, int y) { - int fromx, line, width, height; - XawTextPosition position; + int fromx, line, width, height; + XawTextPosition position; - if (ctx->text.lt.lines == 0) return 0; - - for (line = 0; line < ctx->text.lt.lines - 1; line++) { - if (y <= ctx->text.lt.info[line + 1].y) - break; - } - position = ctx->text.lt.info[line].position; - if (position >= ctx->text.lastPos) - return(ctx->text.lastPos); - fromx = (int) ctx->text.margin.left; - XawTextSinkFindPosition( ctx->text.sink, position, fromx, x - fromx, - FALSE, &position, &width, &height); - if (position > ctx->text.lastPos) return(ctx->text.lastPos); - if (position >= ctx->text.lt.info[line + 1].position) - position = SrcScan(ctx->text.source, ctx->text.lt.info[line + 1].position, - XawstPositions, XawsdLeft, 1, TRUE); - return(position); + if (ctx->text.lt.lines == 0) + return (0); + + for (line = 0; line < ctx->text.lt.lines - 1; line++) { + if (y <= ctx->text.lt.info[line + 1].y) + break; + } + position = ctx->text.lt.info[line].position; + if (position >= ctx->text.lastPos) + return (ctx->text.lastPos); + fromx = ctx->text.left_margin; + XawTextSinkFindPosition(ctx->text.sink, position, fromx, x - fromx, + False, &position, &width, &height); + + if (position > ctx->text.lastPos) + return (ctx->text.lastPos); + + if (position >= ctx->text.lt.info[line + 1].position) + position = SrcScan(ctx->text.source, ctx->text.lt.info[line + 1].position, + XawstPositions, XawsdLeft, 1, True); + + return (position); } /* * This routine maps a source position in to the corresponding line number * of the text that is displayed in the window. - * - * NOTE: It is illegal to call this routine unless there is a valid line table! */ - -static int -LineForPosition (ctx, position) -TextWidget ctx; -XawTextPosition position; +static int +LineForPosition(TextWidget ctx, XawTextPosition position) { - int line; - - for (line = 0; line < ctx->text.lt.lines; line++) - if (position < ctx->text.lt.info[line + 1].position) - break; - return(line); + int line; + + for (line = 0; line < ctx->text.lt.lines; line++) + if (position < ctx->text.lt.info[line + 1].position) + break; + + return (line); } /* * This routine maps a source position into the corresponding line number * and the x, y coordinates of the text that is displayed in the window. - * - * NOTE: It is illegal to call this routine unless there is a valid line table! */ +static Bool +LineAndXYForPosition(TextWidget ctx, XawTextPosition pos, + int *line, int *x, int *y) +{ + XawTextPosition linePos, endPos; + Boolean visible; + int realW, realH; + + *line = 0; + *x = ctx->text.left_margin; + *y = ctx->text.margin.top + 1; + if ((visible = IsPositionVisible(ctx, pos)) != False) { + *line = LineForPosition(ctx, pos); + *y = ctx->text.lt.info[*line].y; + linePos = ctx->text.lt.info[*line].position; + XawTextSinkFindDistance(ctx->text.sink, linePos, + *x, pos, &realW, &endPos, &realH); + *x += realW; + } -static Boolean -LineAndXYForPosition (ctx, pos, line, x, y) -TextWidget ctx; -XawTextPosition pos; -int *line; -Position *x, *y; -{ - XawTextPosition linePos, endPos; - Boolean visible; - int realW, realH; - - *line = 0; - *x = ctx->text.margin.left; - *y = ctx->text.margin.top; - if (visible = IsPositionVisible(ctx, pos)) { - *line = LineForPosition(ctx, pos); - *y = ctx->text.lt.info[*line].y; - *x = ctx->text.margin.left; - linePos = ctx->text.lt.info[*line].position; - XawTextSinkFindDistance( ctx->text.sink, linePos, - *x, pos, &realW, &endPos, &realH); - *x += realW; - } - return(visible); + return (visible); } /* @@ -908,199 +1248,234 @@ Position *x, *y; * linetable all the required metrics for displaying a given line (e.g. * x offset, y offset, line length, etc.). */ - -void -#if NeedFunctionPrototypes -_XawTextBuildLineTable ( - TextWidget ctx, - XawTextPosition position, - _XtBoolean force_rebuild) -#else -_XawTextBuildLineTable (ctx, position, force_rebuild) - TextWidget ctx; - XawTextPosition position; - Boolean force_rebuild; -#endif +void +_XawTextBuildLineTable(TextWidget ctx, XawTextPosition position, + _XtBoolean force_rebuild) { - Dimension height = 0; - int lines = 0; - Cardinal size; + Dimension height = 0; + int lines = 0; + Cardinal size; - if ((int)ctx->core.height > VMargins(ctx)) { - height = ctx->core.height - VMargins(ctx); - lines = XawTextSinkMaxLines(ctx->text.sink, height); - } - size = sizeof(XawTextLineTableEntry) * (lines + 1); + if ((int)XtHeight(ctx) > VMargins(ctx)) { + height = XtHeight(ctx) - VMargins(ctx); + lines = XawTextSinkMaxLines(ctx->text.sink, height); + } + size = sizeof(XawTextLineTableEntry) * (lines + 1); - if ( (lines != ctx->text.lt.lines) || (ctx->text.lt.info == NULL) ) { - ctx->text.lt.info = (XawTextLineTableEntry *) XtRealloc((char *) ctx->text. - lt.info, size); - ctx->text.lt.lines = lines; - force_rebuild = TRUE; - } + if (lines != ctx->text.lt.lines || ctx->text.lt.info == NULL) { + ctx->text.lt.info = (XawTextLineTableEntry *) + XtRealloc((char *)ctx->text.lt.info, size); + ctx->text.lt.lines = lines; + force_rebuild = True; + } - if ( force_rebuild || (position != ctx->text.lt.top) ) { - (void) bzero((char *) ctx->text.lt.info, size); - (void) _BuildLineTable(ctx, ctx->text.lt.top = position, zeroPosition, 0); - } + if (force_rebuild) { + (void)bzero((char *)ctx->text.lt.info, size); + /* force a text update in the first text line if it is visible */ + ctx->text.lt.info[0].position = (XawTextPosition)-1; + } + if (position != ctx->text.lt.info[0].position) { + (void)_BuildLineTable(ctx, position, 0); + ctx->text.clear_to_eol = True; + } } /* - * This assumes that the line table does not change size. + * We may need to resize the line table here, since there maybe lines with + * different fonts (that can be shorter or taller than the default one) */ - static XawTextPosition -_BuildLineTable(ctx, position, min_pos, line) -TextWidget ctx; -XawTextPosition position, min_pos; -int line; -{ - XawTextLineTableEntry * lt = ctx->text.lt.info + line; - XawTextPosition endPos; - Position y; - int count, width, realW, realH; - Widget src = ctx->text.source; - - if ( ((ctx->text.resize == XawtextResizeWidth) || - (ctx->text.resize == XawtextResizeBoth) ) || - (ctx->text.wrap == XawtextWrapNever) ) - width = BIGNUM; - else - width = Max(0, ((int)ctx->core.width - (int)HMargins(ctx))); - - y = ( (line == 0) ? ctx->text.margin.top : lt->y ); - - /* CONSTCOND */ - while ( TRUE ) { - lt->y = y; - lt->position = position; - - XawTextSinkFindPosition( ctx->text.sink, position, ctx->text.margin.left, - width, ctx->text.wrap == XawtextWrapWord, - &endPos, &realW, &realH); - lt->textWidth = realW; - y += realH; - - if (ctx->text.wrap == XawtextWrapNever) - endPos = SrcScan(src, position, XawstEOL, XawsdRight, 1, TRUE); - - if ( endPos == ctx->text.lastPos) { /* We have reached the end. */ - if(SrcScan(src, position, XawstEOL, XawsdRight, 1, FALSE) == endPos) - break; - } - - ++lt; - ++line; - if ( (line > ctx->text.lt.lines) || - ((lt->position == (position = endPos)) && (position > min_pos)) ) - return(position); - } +_BuildLineTable(TextWidget ctx, XawTextPosition position, int line) +{ + XawTextLineTableEntry *lt = ctx->text.lt.info + line; + XawTextPosition end, update_from = -1; + Position y; + int wwidth, width, height; +#ifndef OLDXAW + Widget src = ctx->text.source; +#endif + int max_y = (int)XtHeight(ctx) - (int)ctx->text.margin.bottom; -/* - * If we are at the end of the buffer put two special lines in the table. - * - * a) Both have position > text.lastPos and lt->textWidth = 0. - * b) The first has a real height, and the second has a height that - * is the rest of the screen. - * - * I could fill in the rest of the table with valid heights and a large - * lastPos, but this method keeps the number of fill regions down to a - * minimum. - * - * One valid entry is needed at the end of the table so that the cursor - * does not jump off the bottom of the window. - */ + if (ctx->text.wrap == XawtextWrapNever) + wwidth = 0x7fffffff; + else + wwidth = GetMaxTextWidth(ctx); - for ( count = 0; count < 2 ; count++) - if (line++ < ctx->text.lt.lines) { /* make sure not to run of the end. */ - (++lt)->y = (count == 0) ? y : ctx->core.height; - lt->textWidth = 0; - lt->position = ctx->text.lastPos + 100; + /* XXX y may change, due to font size changes. See later */ + y = line == 0 ? ctx->text.margin.top : lt->y; + +#ifndef OLDXAW + if (ctx->text.lt.base_line < 0) { + if (line == 0) + ctx->text.lt.top = position; } + else if (line == 0) { + XawTextPosition pos = ctx->text.lt.top; + int base_line = ctx->text.lt.base_line; + + if (position == 0) + base_line = 1; + else if (ctx->text.lt.base_line == 0 || + ctx->text.source_changed == SRC_CHANGE_OVERLAP) { + pos = 0; + base_line = 1; + + while (pos < position) { + pos = SrcScan(src, pos, XawstEOL, XawsdRight, 1, True); + if (pos <= position) { + ++base_line; + if (pos == ctx->text.lastPos) { + base_line -= !_XawTextSourceNewLineAtEOF(src); + break; + } + } + } + } + else if (ctx->text.wrap == XawtextWrapNever + && IsPositionVisible(ctx, position)) + base_line += LineForPosition(ctx, position); + else if (pos < position) { + while (pos < position) { + pos = SrcScan(src, pos, XawstEOL, XawsdRight, 1, True); + if (pos <= position) { + ++base_line; + if (pos == ctx->text.lastPos) { + base_line -= !_XawTextSourceNewLineAtEOF(src); + break; + } + } + } + } + else if (pos > position) { + while (pos > position) { + pos = SrcScan(src, pos, XawstEOL, XawsdLeft, 1, False); + if (--pos >= position) + --base_line; + } + } - if (line < ctx->text.lt.lines) /* Clear out rest of table. */ - (void) bzero( (char *) (lt + 1), - (ctx->text.lt.lines - line) * sizeof(XawTextLineTableEntry) ); + ctx->text.lt.top = position; + ctx->text.lt.base_line = base_line; + } +#else + if (line == 0) + ctx->text.lt.top = position; +#endif - ctx->text.lt.info[ctx->text.lt.lines].position = lt->position; + /* CONSTCOND */ + while (True) { + XawTextSinkFindPosition(ctx->text.sink, position, ctx->text.left_margin, + wwidth, ctx->text.wrap == XawtextWrapWord, + &end, &width, &height); + + if (lt->position != position) { + _XawTextNeedsUpdating(ctx, position, + end <= position ? position + 1 : end); + ctx->text.clear_to_eol = True; + lt->position = position; + } + if (lt->y != y) { + if (update_from < 0) + update_from = line == 0 ? + ctx->text.lt.info[0].position : + ctx->text.lt.info[line - 1].position; + lt->y = y; + ctx->text.clear_to_eol = True; + } + if (lt->textWidth != width) { + if (lt->textWidth > width) + ctx->text.clear_to_eol = True; + lt->textWidth = width; + } + y += height; + + if (end > ctx->text.lastPos) { + position = end; + ctx->text.clear_to_eol = True; + _XawTextNeedsUpdating(ctx, end, end + ctx->text.lt.lines - line); + while (line++ < ctx->text.lt.lines) { + if (line > 1 && y > max_y) { + ctx->text.lt.lines = line - 1; + break; + } + ++lt; + if (lt->y != y) { + if (update_from < 0) + update_from = line < 2 ? + ctx->text.lt.info[0].position : + ctx->text.lt.info[line - 2].position; + lt->y = y; + } + lt->position = ++position; + lt->textWidth = 0; + y += height; + } + if (update_from >= 0) + _XawTextNeedsUpdating(ctx, update_from, + ctx->text.lt.info[ctx->text.lt.lines].position); + _XawTextSetScrollBars(ctx); - return(endPos); -} + return (ctx->text.lastPos); + } -/* Function Name: GetWidestLine - * Description: Returns the width (in pixels) of the widest line that - * is currently visable. - * Arguments: ctx - the text widget. - * Returns: the width of the widest line. - * - * NOTE: This function requires a valid line table. - */ + if (line && y > max_y) + /* will return in the next loop */ + ctx->text.lt.lines = line; + + if (++line > ctx->text.lt.lines && y < max_y) { + /* grow the line table */ + ctx->text.lt.info = (XawTextLineTableEntry *) + XtRealloc((char *)ctx->text.lt.info, + sizeof(XawTextLineTableEntry) * (line + 1)); + lt = ctx->text.lt.info + line; + bzero(lt, sizeof(XawTextLineTableEntry)); + ++ctx->text.lt.lines; + } + else + ++lt; + if (position == end) + ++position; + else + position = end; -static Dimension -GetWidestLine(ctx) -TextWidget ctx; -{ - int i; - Dimension widest; - XawTextLineTablePtr lt = &(ctx->text.lt); + if (line > ctx->text.lt.lines) { + if (update_from >= 0) + _XawTextNeedsUpdating(ctx, update_from, + ctx->text.lt.info[ctx->text.lt.lines].position); + _XawTextSetScrollBars(ctx); - for (i = 0, widest = 1 ; i < lt->lines ; i++) - if (widest < lt->info[i].textWidth) - widest = lt->info[i].textWidth; - - return(widest); + return (position); + } + } + /*NOTREACHED*/ } -static void -CheckVBarScrolling(ctx) -TextWidget ctx; +/* + * Function: + * GetWidestLine + * + * Parameters: + * ctx - text widget + * + * Description: + * Returns the width (in pixels) of the widest line that + * is currently visable. + * + * Returns: + * The width of the widest line + */ +static unsigned int +GetWidestLine(TextWidget ctx) { - float first, last; - Boolean temp = (ctx->text.vbar == NULL); + int i; + unsigned int widest; + XawTextLineTablePtr lt = &(ctx->text.lt); - if (ctx->text.scroll_vert == XawtextScrollNever) return; + for (i = 0, widest = 0; i < lt->lines; i++) + if (widest < lt->info[i].textWidth) + widest = lt->info[i].textWidth; - if ( (ctx->text.lastPos > 0) && (ctx->text.lt.lines > 0)) { - first = ctx->text.lt.top; - first /= (float) ctx->text.lastPos; - last = ctx->text.lt.info[ctx->text.lt.lines].position; - if ( ctx->text.lt.info[ctx->text.lt.lines].position < ctx->text.lastPos ) - last /= (float) ctx->text.lastPos; - else - last = 1.0; - - if (ctx->text.scroll_vert == XawtextScrollWhenNeeded) { - int line; - XawTextPosition last_pos; - Position y = ctx->core.height - ctx->text.margin.bottom; - - if (ctx->text.hbar != NULL) - y -= (ctx->text.hbar->core.height + - 2 * ctx->text.hbar->core.border_width); - - last_pos = PositionForXY(ctx, (Position) ctx->core.width, y); - line = LineForPosition(ctx, last_pos); - - if ( (y < ctx->text.lt.info[line + 1].y) || ((last - first) < 1.0) ) - CreateVScrollBar(ctx); - else - DestroyVScrollBar(ctx); - } - - if (ctx->text.vbar != NULL) - XawScrollbarSetThumb(ctx->text.vbar, first, last - first); - - if ( (ctx->text.vbar == NULL) != temp) { - _XawTextNeedsUpdating(ctx, zeroPosition, ctx->text.lastPos); - if (ctx->text.vbar == NULL) - _XawTextBuildLineTable (ctx, zeroPosition, FALSE); - } - } - else if (ctx->text.vbar != NULL) - if (ctx->text.scroll_vert == XawtextScrollWhenNeeded) - DestroyVScrollBar(ctx); - else if (ctx->text.scroll_vert == XawtextScrollAlways) - XawScrollbarSetThumb(ctx->text.vbar, 0.0, 1.0); + return (widest); } /* @@ -1108,473 +1483,545 @@ TextWidget ctx; * correct metrics (position and shown fraction) for the text being currently * displayed in the window. */ +void +_XawTextSetScrollBars(TextWidget ctx) +{ + float first, last, denom, widest; -void -_XawTextSetScrollBars(ctx) -TextWidget ctx; + if (ctx->text.scroll_vert == XawtextScrollAlways) { + if (ctx->text.lastPos == 0) + first = 0.0; + else + first = ctx->text.lt.top / (float)ctx->text.lastPos; + + if (ctx->text.lt.info[ctx->text.lt.lines].position < ctx->text.lastPos) + last = ctx->text.lt.info[ctx->text.lt.lines].position / + (float)ctx->text.lastPos; + else + last = 1.0; + + XawScrollbarSetThumb(ctx->text.vbar, first, last - first); + } + + if (ctx->text.scroll_horiz == XawtextScrollAlways) { + denom = GetWidestLine(ctx); + if (denom <= 0) + denom = (int)XtWidth(ctx) - RHMargins(ctx); + if (denom <= 0) + denom = 1; + widest = ((int)XtWidth(ctx) - RHMargins(ctx)) / denom; + first = ctx->text.r_margin.left - ctx->text.left_margin; + first /= denom; + + XawScrollbarSetThumb(ctx->text.hbar, first, widest); + } +} + +static void +DoCopyArea(TextWidget ctx, int src_x, int src_y, + unsigned int width, unsigned int height, int dst_x, int dst_y) { - float first, last, widest; - Boolean temp = (ctx->text.hbar == NULL); - Boolean vtemp = (ctx->text.vbar == NULL); - - CheckVBarScrolling(ctx); - - if (ctx->text.scroll_horiz == XawtextScrollNever) return; - - if (ctx->text.vbar != NULL) - widest = (int)(ctx->core.width - ctx->text.vbar->core.width - - ctx->text.vbar->core.border_width); - else - widest = ctx->core.width; - widest /= (last = GetWidestLine(ctx)); - if (ctx->text.scroll_horiz == XawtextScrollWhenNeeded) - if (widest < 1.0) - CreateHScrollBar(ctx); - else - DestroyHScrollBar(ctx); + int x1, y1, x2, y2; - if ( (ctx->text.hbar == NULL) != temp ) { - _XawTextBuildLineTable (ctx, ctx->text.lt.top, TRUE); - CheckVBarScrolling(ctx); /* Recheck need for vbar, now that we added - or removed the hbar.*/ - } - - if (ctx->text.hbar != NULL) { - first = ctx->text.r_margin.left - ctx->text.margin.left; - first /= last; - XawScrollbarSetThumb(ctx->text.hbar, first, widest); - } + x1 = ctx->text.r_margin.left; + y1 = ctx->text.r_margin.top; + x2 = XtWidth(ctx) - ctx->text.r_margin.right; + y2 = XtHeight(ctx) - ctx->text.r_margin.bottom; - if (((ctx->text.hbar == NULL) && (ctx->text.margin.left != - ctx->text.r_margin.left)) || - (ctx->text.vbar == NULL) != vtemp) - { - ctx->text.margin.left = ctx->text.r_margin.left; - _XawTextNeedsUpdating(ctx, zeroPosition, ctx->text.lastPos); - FlushUpdate(ctx); - } + if (x1 >= x2 || y1 >= y2) + return; + + src_x = XawMax(x1, XawMin(src_x, x2)); + src_y = XawMax(y1, XawMin(src_y, y2)); + dst_x = XawMax(x1, XawMin(dst_x, x2)); + dst_y = XawMax(y1, XawMin(dst_y, y2)); + width = XawMax(0, XawMin(x2 - dst_x, (int)width)); + height = XawMax(0, XawMin(y2 - dst_y, (int)height)); + + XCopyArea(XtDisplay(ctx), XtWindow(ctx), XtWindow(ctx), ctx->text.gc, + src_x, src_y, width, height, dst_x, dst_y); } /* - * The routine will scroll the displayed text by lines. If the arg is - * positive, move up; otherwise, move down. [note: this is really a private - * procedure but is used in multiple modules]. + * Function: + * XawTextScroll + * + * Parameters: + * ctx - text widget + * vlines - number of lines to scroll vertically + * hpixels - number of pixels to scroll horizontally + * + * Description: + * Generic function for scrolling the text window. + * Allows vertical and horizontal scroll at the same time. */ - void -_XawTextVScroll(ctx, n) -TextWidget ctx; -int n; +XawTextScroll(TextWidget ctx, int vlines, int hpixels) { - XawTextPosition top, target; - int y; - Arg list[1]; - XawTextLineTable * lt = &(ctx->text.lt); + XawTextPosition top, tmp, update_from, update_to; + XawTextLineTable *lt; + Arg arglist[1]; + int y0, y1, y2, count, dim, wwidth, lines = ctx->text.lt.lines; + int vwidth, vheight; /* visible width and height */ + Bool scroll; + + vwidth = (int)XtWidth(ctx) - RHMargins(ctx); + vheight = (int)XtHeight(ctx) - RVMargins(ctx); + lt = &ctx->text.lt; + + if (!lt || vwidth <= 0 || vheight <= 0) + return; - if (abs(n) > ctx->text.lt.lines) - n = (n > 0) ? ctx->text.lt.lines : -ctx->text.lt.lines; + if ((scroll = ctx->core.background_pixmap == XtUnspecifiedPixmap) == True) { + dim = lt->info[1].y - lt->info[0].y; + for (count = 1; count < lt->lines - 1; count++) + if (lt->info[count + 1].y - lt->info[count].y != dim) { + scroll = False; + break; + } + } - if (n == 0) return; + wwidth = GetMaxTextWidth(ctx); - if (n > 0) { - if ( IsValidLine(ctx, n) ) - top = Min(lt->info[n].position, ctx->text.lastPos); - else - top = ctx->text.lastPos; + /* + * Do the horizontall scrolling + */ + if (hpixels < 0 && ctx->text.left_margin - hpixels > ctx->text.r_margin.left) + hpixels = ctx->text.left_margin - ctx->text.r_margin.left; + ctx->text.left_margin -= hpixels; - y = IsValidLine(ctx, n) ? lt->info[n].y : ctx->core.height; - _XawTextBuildLineTable(ctx, top, FALSE); - if (top >= ctx->text.lastPos) - DisplayTextWindow( (Widget) ctx); - else { - XCopyArea(XtDisplay(ctx), XtWindow(ctx), XtWindow(ctx), ctx->text.gc, - 0, y, (int)ctx->core.width, (int)ctx->core.height - y, - 0, ctx->text.margin.top); - - PushCopyQueue(ctx, 0, (int) -y); - SinkClearToBG(ctx->text.sink, - (Position) 0, - (Position) (ctx->text.margin.top + ctx->core.height - y), - (Dimension) ctx->core.width, (Dimension) ctx->core.height); - - if (n < lt->lines) n++; /* update descenders at bottom */ - _XawTextNeedsUpdating(ctx, lt->info[lt->lines - n].position, - ctx->text.lastPos); - _XawTextSetScrollBars(ctx); - } - } - else { - XawTextPosition updateTo; - unsigned int height, clear_height; - - n = -n; - target = lt->top; - top = SrcScan(ctx->text.source, target, XawstEOL, - XawsdLeft, n+1, FALSE); - - _XawTextBuildLineTable(ctx, top, FALSE); - y = IsValidLine(ctx, n) ? lt->info[n].y : ctx->core.height; - updateTo = IsValidLine(ctx, n) ? lt->info[n].position : ctx->text.lastPos; - if (IsValidLine(ctx, lt->lines - n)) - height = lt->info[lt->lines-n].y - ctx->text.margin.top; - else if (ctx->core.height - HMargins(ctx)) - height = ctx->core.height - HMargins(ctx); - else - height = 0; - if (y > (int) ctx->text.margin.top) - clear_height = y - ctx->text.margin.top; - else - clear_height = 0; - - if ( updateTo == target ) { - XCopyArea(XtDisplay(ctx), XtWindow(ctx), XtWindow(ctx), ctx->text.gc, - 0, ctx->text.margin.top, (int) ctx->core.width, height, 0, y); - PushCopyQueue(ctx, 0, (int) y); - SinkClearToBG(ctx->text.sink, (Position) 0, ctx->text.margin.top, - (Dimension) ctx->core.width, (Dimension) clear_height); - - _XawTextNeedsUpdating(ctx, lt->info[0].position, updateTo); - _XawTextSetScrollBars(ctx); - } - else if (lt->top != target) - DisplayTextWindow((Widget)ctx); - } - XtSetArg (list[0], XtNinsertPosition, ctx->text.lt.top+ctx->text.lt.lines); - _XawImSetValues ((Widget) ctx, list, 1); -} + update_from = lt->top; /* remember the old value */ + /* + * Checks the requested number of lines and calculates the top + * of the line table + */ + if (vlines < 0) { /* VScroll Up */ + if (IsPositionVisible(ctx, 0)) + vlines = 0; + else if (ctx->text.wrap != XawtextWrapNever) { + XawTextPosition end; + int n_lines = 0; + + count = -vlines; + end = lt->top; + while (n_lines < count) { + top = SrcScan(ctx->text.source, end, XawstEOL, + XawsdLeft, 2, False); + n_lines += CountLines(ctx, top, end); + end = top; + } -/*ARGSUSED*/ -static void -HScroll(w, closure, callData) -Widget w; -XtPointer closure; /* TextWidget */ -XtPointer callData; /* #pixels */ -{ - TextWidget ctx = (TextWidget) closure; - Widget tw = (Widget) ctx; - Position old_left, pixels = (Position)(int) callData; - XRectangle rect, t_rect; - - _XawTextPrepareToUpdate(ctx); + while (count++ < n_lines) { + tmp = top; + XawTextSinkFindPosition(ctx->text.sink, top, + ctx->text.left_margin, + wwidth,ctx->text.wrap == XawtextWrapWord, + &top, &dim, &dim); + if (tmp == top) + ++top; + } + } + else + top = SrcScan(ctx->text.source, lt->top, XawstEOL, + XawsdLeft, -vlines + 1, False); + if (-vlines >= ctx->text.lt.lines) + scroll = False; + } + else if (vlines > 0) { /* VScroll Down */ + if (LineForPosition(ctx, ctx->text.lastPos) == 0) + vlines = 0; + if (vlines < lt->lines) + top = XawMin(lt->info[vlines].position, ctx->text.lastPos); + else if (ctx->text.wrap == XawtextWrapNever) + top = SrcScan(ctx->text.source, + SrcScan(ctx->text.source, lt->top, + XawstEOL, XawsdRight, vlines, + True), + XawstEOL, XawsdLeft, 1, False); + else { + top = lt->top; + count = 0; + while (count++ < vlines) { + tmp = top; + XawTextSinkFindPosition(ctx->text.sink, top, + ctx->text.left_margin, + wwidth, ctx->text.wrap == XawtextWrapWord, + &top, &dim, &dim); + if (tmp == top) + ++top; + } + } + if (vlines >= ctx->text.lt.lines + || lt->info[vlines].position >= ctx->text.lastPos) + scroll = False; + } - old_left = ctx->text.margin.left; - ctx->text.margin.left -= pixels; - if (ctx->text.margin.left > ctx->text.r_margin.left) { - ctx->text.margin.left = ctx->text.r_margin.left; - pixels = old_left - ctx->text.margin.left; - } - - if (pixels > 0) { - rect.width = (unsigned short) pixels + ctx->text.margin.right; - rect.x = (short) ctx->core.width - (short) rect.width; - rect.y = (short) ctx->text.margin.top; - rect.height = (unsigned short) ctx->core.height - rect.y; - - XCopyArea(XtDisplay(tw), XtWindow(tw), XtWindow(tw), ctx->text.gc, - pixels, (int) rect.y, - (unsigned int) rect.x, (unsigned int) ctx->core.height, - 0, (int) rect.y); - - PushCopyQueue(ctx, (int) -pixels, 0); - } - else if (pixels < 0) { - rect.x = 0; + if (!vlines) { + if (hpixels) { + ClearWindow(ctx); + ctx->text.clear_to_eol = True; + } + _XawTextSetScrollBars(ctx); + return; + } - if (ctx->text.vbar != NULL) - rect.x += (short) (ctx->text.vbar->core.width + - ctx->text.vbar->core.border_width); + /* Flushes any pending updates. Normally, there may be a call to + * XawTextUnsetSelection not yet updated. + */ + if (!hpixels && scroll) { + ctx->text.clear_to_eol = True; + FlushUpdate(ctx); + } + + /* + * Rebuild the line table, doing the vertical scroll + */ + (void)_BuildLineTable(ctx, top, 0); + lt = &ctx->text.lt; + if (scroll) { + for (count = 0; count < lt->lines - 1; count++) + if (lt->info[count + 1].y - lt->info[count].y != dim) { + scroll = False; + break; + } + } - rect.width = (Position) - pixels; - rect.y = ctx->text.margin.top; - rect.height = ctx->core.height - rect.y; + XtSetArg(arglist[0], XtNinsertPosition, lt->top + lt->lines); + _XawImSetValues((Widget)ctx, arglist, 1); - XCopyArea(XtDisplay(tw), XtWindow(tw), XtWindow(tw), ctx->text.gc, - (int) rect.x, (int) rect.y, - (unsigned int) ctx->core.width - rect.width, - (unsigned int) rect.height, - (int) rect.x + rect.width, (int) rect.y); + if (hpixels || !scroll || lines != lt->lines) + return; - PushCopyQueue(ctx, (int) rect.width, 0); + /* _BuildLineTable updates everything if the top position changes. + * It is not required here. + */ + (void)XmuScanlineXor(ctx->text.update, ctx->text.update); + if (vlines < 0 && IsPositionVisible(ctx, 0)) + vlines = -LineForPosition(ctx, update_from); + + y0 = ctx->text.r_margin.top; + if (vlines < 0) { + update_from = lt->top; + update_to = lt->info[-vlines + 1].position - 1; + y1 = lt->info[lt->lines + vlines].y; + y2 = lt->info[-vlines].y; + DoCopyArea(ctx, ctx->text.r_margin.left, y0, vwidth, + y1 - y0, + ctx->text.r_margin.left, y2); + } + else { + update_from = lt->info[lt->lines - vlines].position; + update_to = lt->info[lt->lines].position; + y1 = lt->info[lt->lines - vlines].y; + y2 = lt->info[vlines].y; + DoCopyArea(ctx, ctx->text.r_margin.left, y2, + vwidth, lt->info[lt->lines].y - y2, + ctx->text.r_margin.left, y0); + } + _XawTextNeedsUpdating(ctx, update_from, update_to); + ctx->text.clear_to_eol = True; +} /* - * Redraw the line overflow marks. + * The routine will scroll the displayed text by lines. If the arg is + * positive, move up; otherwise, move down. [note: this is really a private + * procedure but is used in multiple modules]. */ +void +_XawTextVScroll(TextWidget ctx, int n) +{ + XawTextScroll(ctx, n, 0); +} - t_rect.x = ctx->core.width - ctx->text.margin.right; - t_rect.width = ctx->text.margin.right; - t_rect.y = rect.y; - t_rect.height = rect.height; - - SinkClearToBG(ctx->text.sink, (Position) t_rect.x, (Position) t_rect.y, - (Dimension) t_rect.width, (Dimension) t_rect.height); - - UpdateTextInRectangle(ctx, &t_rect); - } +/*ARGSUSED*/ +static void +HScroll(Widget w, XtPointer closure, XtPointer callData) +{ + TextWidget ctx = (TextWidget)closure; + long pixels = (long)callData; -/* - * Put in the text that just became visible. - */ + if (pixels > 0) { + long max; - if ( pixels != 0 ) { - SinkClearToBG(ctx->text.sink, (Position) rect.x, (Position) rect.y, - (Dimension) rect.width, (Dimension) rect.height); - - UpdateTextInRectangle(ctx, &rect); - } - _XawTextExecuteUpdate(ctx); - _XawTextSetScrollBars(ctx); + max = (int)GetWidestLine(ctx) + ctx->text.left_margin - + ctx->text.r_margin.left; + max = XawMax(0, max); + pixels = XawMin(pixels, max); + } + + if (pixels) { + _XawTextPrepareToUpdate(ctx); + XawTextScroll(ctx, 0, pixels); + _XawTextExecuteUpdate(ctx); + } } /*ARGSUSED*/ -static void -HJump(w, closure, callData) -Widget w; -XtPointer closure, callData; /* closure = TextWidget, callData = percent. */ +static void +HJump(Widget w, XtPointer closure, XtPointer callData) { - TextWidget ctx = (TextWidget) closure; - float * percent = (float *) callData; - Position new_left, old_left = ctx->text.margin.left; + TextWidget ctx = (TextWidget)closure; + float percent = *(float *)callData; + long pixels; - long move; /*difference of Positions can be bigger than Position; lint err */ + pixels = ctx->text.left_margin - + (ctx->text.r_margin.left - (int)(percent * GetWidestLine(ctx))); - new_left = ctx->text.r_margin.left; - new_left -= (Position) (*percent * GetWidestLine(ctx)); - move = old_left - new_left; + HScroll(w, (XtPointer)ctx, (XtPointer)pixels); +} - if (abs(move) < (int)ctx->core.width) { - HScroll(w, (XtPointer) ctx, (XtPointer) move); - return; - } - _XawTextPrepareToUpdate(ctx); - ctx->text.margin.left = new_left; - if (XtIsRealized((Widget) ctx)) DisplayTextWindow((Widget) ctx); - _XawTextExecuteUpdate(ctx); -} - -/* Function Name: UpdateTextInLine - * Description: Updates some text in a given line. - * Arguments: ctx - the text widget. - * line - the line number (in the line table) of this line. - * left, right - left and right pixel offsets of the - * area to update. - * Returns: none. +/* + * Function: + * UpdateTextInLine + * + * Parameters: + * ctx - text widget + * line - line to update + * x1 - left pixel + * x2 - right pixel + * + * Description: + * Updates the text in the given line and pixel interval */ - static void -UpdateTextInLine(ctx, line, left, right) -TextWidget ctx; -int line; -Position left, right; -{ - XawTextPosition pos1, pos2; - int width, height, local_left, local_width; - XawTextLineTableEntry * lt = ctx->text.lt.info + line; - - if ( ((int)(lt->textWidth + ctx->text.margin.left) < left) || - ( ctx->text.margin.left > right ) ) - return; /* no need to update. */ - - local_width = left - ctx->text.margin.left; - XawTextSinkFindPosition(ctx->text.sink, lt->position, - (int) ctx->text.margin.left, - local_width, FALSE, &pos1, &width, &height); - - if (right >= (Position) lt->textWidth - ctx->text.margin.left) - if ( (IsValidLine(ctx, line + 1)) && - (ctx->text.lt.info[line + 1].position <= ctx->text.lastPos) ) - pos2 = SrcScan( ctx->text.source, (lt + 1)->position, XawstPositions, - XawsdLeft, 1, TRUE); - else - pos2 = GETLASTPOS; - else { - XawTextPosition t_pos; - - local_left = ctx->text.margin.left + width; - local_width = right - local_left; - XawTextSinkFindPosition(ctx->text.sink, pos1, local_left, - local_width, FALSE, &pos2, &width, &height); - - t_pos = SrcScan( ctx->text.source, pos2, - XawstPositions, XawsdRight, 1, TRUE); - if (t_pos < (lt + 1)->position) - pos2 = t_pos; - } +UpdateTextInLine(TextWidget ctx, int line, int x1, int x2) +{ + XawTextLineTableEntry *lt = ctx->text.lt.info + line; + XawTextPosition left, right; + int from_x, width, height; + + if (lt->position >= ctx->text.lastPos + || ctx->text.left_margin > x2 + || (int)lt->textWidth + ctx->text.left_margin < x1) { + /* Mark line to be cleared */ + if (ctx->text.clear_to_eol) + _XawTextNeedsUpdating(ctx, lt->position, lt->position + 1); + return; + } + + from_x = ctx->text.left_margin; + XawTextSinkFindPosition(ctx->text.sink, lt->position, + from_x, x1 - from_x, + False, &left, &width, &height); + if (line == ctx->text.lt.lines) + right = -1; + else if (x2 >= lt->textWidth - from_x) + right = lt[1].position - 1; + else { + from_x += width; + XawTextSinkFindPosition(ctx->text.sink, left, + from_x, x2 - from_x, + False, &right, &width, &height); + } + + if ((right < 0) || (right + 1 <= lt[1].position)) + ++right; - _XawTextNeedsUpdating(ctx, pos1, pos2); + /* Mark text interval to be repainted */ + _XawTextNeedsUpdating(ctx, left, right); } /* * The routine will scroll the displayed text by pixels. If the calldata is * positive, move up; otherwise, move down. */ +/*ARGSUSED*/ +static void +VScroll(Widget w, XtPointer closure, XtPointer callData) +{ + TextWidget ctx = (TextWidget)closure; + long height, lines = (long)callData; + + height = XtHeight(ctx) - VMargins(ctx); + if (height < 1) + height = 1; + lines = (lines * ctx->text.lt.lines) / height; + _XawTextPrepareToUpdate(ctx); + XawTextScroll(ctx, lines, 0); + _XawTextExecuteUpdate(ctx); +} /*ARGSUSED*/ -static void -VScroll(w, closure, callData) -Widget w; -XtPointer closure; /* TextWidget */ -XtPointer callData; /* #pixels */ +static void +VJump(Widget w, XtPointer closure, XtPointer callData) { - TextWidget ctx = (TextWidget)closure; - int height, lines = (int) callData; + float percent = *(float *)callData; + TextWidget ctx = (TextWidget)closure; + XawTextPosition top, last, position, tmp; + XawTextLineTable *lt = &(ctx->text.lt); + int dim, vlines = 0, wwidth = GetMaxTextWidth(ctx); + Bool scroll = True; + + position = percent * ctx->text.lastPos; + top = lt->top; + + if (!lt->lines || (position >= lt->top && position < lt->info[1].position)) { + _XawTextSetScrollBars(ctx); + return; + } + +#ifndef OLDXAW + ctx->text.lt.base_line = -1; +#endif + + if (position > lt->top) { /* VScroll Up */ + if (position > lt->top && position < lt->info[lt->lines].position) + vlines = LineForPosition(ctx, position); + else { + scroll = False; + top = SrcScan(ctx->text.source, position, XawstEOL, + XawsdLeft, 1, False); + if (ctx->text.wrap != XawtextWrapNever) { + last = top; + while (last < position) { + tmp = last; + XawTextSinkFindPosition(ctx->text.sink, last, + ctx->text.left_margin, wwidth, + ctx->text.wrap == XawtextWrapWord, + &last, &dim, &dim); + if (last == tmp) + ++last; + if (last < position) + top = last; + } + } + } + } + else { /* VScroll Down */ + /* + * Calculates the number of lines + */ + while (top > position) { + last = top; + top = SrcScan(ctx->text.source, top, XawstEOL, + XawsdLeft, 2, False); + vlines -= CountLines(ctx, top, last); + if (-vlines >= ctx->text.lt.lines) { + scroll = False; + top = SrcScan(ctx->text.source, position, XawstEOL, + XawsdLeft, 1, False); + break; + } + } + /* + * Normalize + */ + if (ctx->text.wrap != XawtextWrapNever) { + last = top; + while (last < position) { + tmp = last; + XawTextSinkFindPosition(ctx->text.sink, last, + ctx->text.left_margin, + wwidth, + ctx->text.wrap == XawtextWrapWord, + &last, &dim, &dim); + if (last == tmp) + ++last; + if (last < position) + top = last; + ++vlines; + } + } + } - height = ctx->core.height - VMargins(ctx); - if (height < 1) - height = 1; - lines = (int) (lines * (int) ctx->text.lt.lines) / height; - _XawTextPrepareToUpdate(ctx); - _XawTextVScroll(ctx, lines); - _XawTextExecuteUpdate(ctx); + if (vlines || !scroll) { + _XawTextPrepareToUpdate(ctx); + if (scroll) + XawTextScroll(ctx, vlines, 0); + else + _BuildLineTable(ctx, top, 0); + _XawTextExecuteUpdate(ctx); + } } -/* - * The routine "thumbs" the displayed text. Thumbing means reposition the - * displayed view of the source to a new position determined by a fraction - * of the way from beginning to end. Ideally, this should be determined by - * the number of displayable lines in the source. This routine does it as a - * fraction of the first position and last position and then normalizes to - * the start of the line containing the position. - * - * BUG/deficiency: The normalize to line portion of this routine will - * cause thumbing to always position to the start of the source. - */ +static Bool +MatchSelection(Atom selection, XawTextSelection *s) +{ + Atom *match; + int count; -/*ARGSUSED*/ -static void -VJump(w, closure, callData) -Widget w; -XtPointer closure, callData; /* closuer = TextWidget, callData = percent. */ -{ - float * percent = (float *) callData; - TextWidget ctx = (TextWidget)closure; - XawTextPosition position, old_top, old_bot; - XawTextLineTable * lt = &(ctx->text.lt); - - _XawTextPrepareToUpdate(ctx); - old_top = lt->top; - if ( (lt->lines > 0) && (IsValidLine(ctx, lt->lines - 1)) ) - old_bot = lt->info[lt->lines - 1].position; - else - old_bot = ctx->text.lastPos; - - position = (long) (*percent * (float) ctx->text.lastPos); - position= SrcScan(ctx->text.source, position, XawstEOL, XawsdLeft, 1, FALSE); - if ( (position >= old_top) && (position <= old_bot) ) { - int line = 0; - for (;(line < lt->lines) && (position > lt->info[line].position) ; line++); - _XawTextVScroll(ctx, line); - } - else { - XawTextPosition new_bot; - _XawTextBuildLineTable(ctx, position, FALSE); - new_bot = IsValidLine(ctx, lt->lines-1) ? lt->info[lt->lines-1].position - : ctx->text.lastPos; - - if ((old_top >= lt->top) && (old_top <= new_bot)) { - int line = 0; - for (;(line < lt->lines) && (old_top > lt->info[line].position); line++); - _XawTextBuildLineTable(ctx, old_top, FALSE); - _XawTextVScroll(ctx, -line); - } - else - DisplayTextWindow( (Widget) ctx); - } - _XawTextExecuteUpdate(ctx); + for (count = 0, match = s->selections; count < s->atom_count; + match++, count++) + if (*match == selection) + return (True); + + return (False); } static Boolean -MatchSelection(selection, s) -Atom selection; -XawTextSelection *s; -{ - Atom *match; - int count; - - for (count = 0, match = s->selections; count < s->atom_count; match++, count++) - if (*match == selection) - return True; - return False; -} - -static Boolean -ConvertSelection(w, selection, target, type, value, length, format) -Widget w; -Atom *selection, *target, *type; -XtPointer *value; -unsigned long *length; -int *format; -{ - Display* d = XtDisplay(w); - TextWidget ctx = (TextWidget)w; - Widget src = ctx->text.source; - XawTextEditType edit_mode; - Arg args[1]; - - XawTextSelectionSalt *salt = NULL; - XawTextSelection *s; - - if (*target == XA_TARGETS(d)) { - Atom* targetP, * std_targets; - unsigned long std_length; - - if ( SrcCvtSel(src, selection, target, type, value, length, format) ) - return True; - - XmuConvertStandardSelection(w, ctx->text.time, selection, - target, type, (XPointer*)&std_targets, - &std_length, format); - - *value = XtMalloc((unsigned) sizeof(Atom)*(std_length + 7)); - targetP = *(Atom**)value; - *length = std_length + 6; - *targetP++ = XA_STRING; - *targetP++ = XA_TEXT(d); - *targetP++ = XA_COMPOUND_TEXT(d); - *targetP++ = XA_LENGTH(d); - *targetP++ = XA_LIST_LENGTH(d); - *targetP++ = XA_CHARACTER_POSITION(d); - - XtSetArg(args[0], XtNeditType,&edit_mode); - XtGetValues(src, args, ONE); - - if (edit_mode == XawtextEdit) { - *targetP++ = XA_DELETE(d); - (*length)++; - } - (void) memmove((char*)targetP, (char*)std_targets, sizeof(Atom)*std_length); - XtFree((char*)std_targets); - *type = XA_ATOM; - *format = 32; - return True; - } - - if ( SrcCvtSel(src, selection, target, type, value, length, format) ) - return True; +TextConvertSelection(Widget w, Atom *selection, Atom *target, Atom *type, + XtPointer *value, unsigned long *length, int *format) +{ + Display *d = XtDisplay(w); + TextWidget ctx = (TextWidget)w; + Widget src = ctx->text.source; + XawTextEditType edit_mode; + Arg args[1]; + XawTextSelectionSalt *salt = NULL; + XawTextSelection *s; + + if (*target == XA_TARGETS(d)) { + Atom *targetP, *std_targets; + unsigned long std_length; + + if (SrcCvtSel(src, selection, target, type, value, length, format)) + return (True); + + XtSetArg(args[0], XtNeditType, &edit_mode); + XtGetValues(src, args, ONE); + + XmuConvertStandardSelection(w, ctx->text.time, selection, + target, type, (XPointer*)&std_targets, + &std_length, format); + + *length = 7 + (edit_mode == XawtextEdit) + std_length; + *value = XtMalloc((unsigned)sizeof(Atom)*(*length)); + targetP = *(Atom**)value; + *targetP++ = XA_STRING; + *targetP++ = XA_TEXT(d); + *targetP++ = XA_UTF8_STRING(d); + *targetP++ = XA_COMPOUND_TEXT(d); + *targetP++ = XA_LENGTH(d); + *targetP++ = XA_LIST_LENGTH(d); + *targetP++ = XA_CHARACTER_POSITION(d); + if (edit_mode == XawtextEdit) { + *targetP++ = XA_DELETE(d); + } + (void)memmove((char*)targetP, (char*)std_targets, + sizeof(Atom) * std_length); + XtFree((char*)std_targets); + *type = XA_ATOM; + *format = 32; + return (True); + } - if (MatchSelection (*selection, &ctx->text.s)) - s = &ctx->text.s; - else - { - for (salt = ctx->text.salt; salt; salt = salt->next) - if (MatchSelection (*selection, &salt->s)) - break; - if (!salt) - return False; - s = &salt->s; - } - if (*target == XA_STRING || - *target == XA_TEXT(d) || - *target == XA_COMPOUND_TEXT(d)) { + if (SrcCvtSel(src, selection, target, type, value, length, format)) + return (True); + + if (MatchSelection(*selection, &ctx->text.s)) + s = &ctx->text.s; + else { + for (salt = ctx->text.salt; salt; salt = salt->next) + if (MatchSelection(*selection, &salt->s)) + break; + if (!salt) + return (False); + s = &salt->s; + } + if (*target == XA_STRING + || *target == XA_TEXT(d) + || *target == XA_UTF8_STRING(d) + || *target == XA_COMPOUND_TEXT(d)) { if (*target == XA_TEXT(d)) { - if (_XawTextFormat(ctx) == XawFmtWide) + if (XawTextFormat(ctx, XawFmtWide)) *type = XA_COMPOUND_TEXT(d); else *type = XA_STRING; - } else { - *type = *target; } + else + *type = *target; /* - * If salt is True, the salt->contents stores CT string, + * If salt is True, the salt->contents stores CT string, * its length is measured in bytes. * Refer to _XawTextSaltAwaySelection(). * @@ -1582,203 +2029,215 @@ int *format; */ if (!salt) { *value = _XawTextGetSTRING(ctx, s->left, s->right); - if (_XawTextFormat(ctx) == XawFmtWide) { + if (XawTextFormat(ctx, XawFmtWide)) { XTextProperty textprop; if (XwcTextListToTextProperty(d, (wchar_t **)value, 1, XCompoundTextStyle, &textprop) - < Success) { - XtFree(*value); - return False; + < Success) { + XtFree((char *)*value); + return (False); } - XtFree(*value); + XtFree((char *)*value); *value = (XtPointer)textprop.value; *length = textprop.nitems; - } else { - *length = strlen(*value); } - } else { + else + *length = strlen((char *)*value); + } + else { *value = XtMalloc((salt->length + 1) * sizeof(unsigned char)); - strcpy (*value, salt->contents); + strcpy ((char *)*value, salt->contents); *length = salt->length; } - if (_XawTextFormat(ctx) == XawFmtWide && *type == XA_STRING) { + /* Got *value,*length, now in COMPOUND_TEXT format. */ + if (XawTextFormat(ctx, XawFmtWide) && *type == XA_STRING) { XTextProperty textprop; wchar_t **wlist; int count; + textprop.encoding = XA_COMPOUND_TEXT(d); textprop.value = (unsigned char *)*value; textprop.nitems = strlen(*value); textprop.format = 8; - if (XwcTextPropertyToTextList(d, &textprop, (wchar_t ***)&wlist, &count) - < Success) { - XtFree(*value); - return False; + if (XwcTextPropertyToTextList(d, &textprop, &wlist, &count) + < Success + || count < 1) { + XtFree((char *)*value); + return (False); } - XtFree(*value); - if (XwcTextListToTextProperty( d, (wchar_t **)wlist, 1, - XStringStyle, &textprop) < Success) { - XwcFreeStringList( (wchar_t**) wlist ); - return False; + XtFree((char *)*value); + if (XwcTextListToTextProperty(d, wlist, 1, XStringStyle, &textprop) + < Success) { + XwcFreeStringList((wchar_t**) wlist); + return (False); } - *value = (XtPointer) textprop.value; + *value = (XtPointer)textprop.value; *length = textprop.nitems; - XwcFreeStringList( (wchar_t**) wlist ); + XwcFreeStringList(wlist); + } else if (*type == XA_UTF8_STRING(d)) { + XTextProperty textprop; + char **list; + int count; + + textprop.encoding = XA_COMPOUND_TEXT(d); + textprop.value = (unsigned char *)*value; + textprop.nitems = strlen(*value); + textprop.format = 8; + if (Xutf8TextPropertyToTextList(d, &textprop, &list, &count) + < Success + || count < 1) { + XtFree((char *)*value); + return (False); + } + XtFree((char *)*value); + *value = *list; + *length = strlen(*list); + XFree(list); } *format = 8; - return True; - } + return (True); + } - if ( (*target == XA_LIST_LENGTH(d)) || (*target == XA_LENGTH(d)) ) { - long * temp; - - temp = (long *) XtMalloc( (unsigned) sizeof(long) ); - if (*target == XA_LIST_LENGTH(d)) - *temp = 1L; - else /* *target == XA_LENGTH(d) */ - *temp = (long) (s->right - s->left); - - *value = (XPointer) temp; - *type = XA_INTEGER; - *length = 1L; - *format = 32; - return True; - } + if ((*target == XA_LIST_LENGTH(d)) || (*target == XA_LENGTH(d))) { + long * temp; - if (*target == XA_CHARACTER_POSITION(d)) { - long * temp; - - temp = (long *) XtMalloc( (unsigned)( 2 * sizeof(long) ) ); - temp[0] = (long) (s->left + 1); - temp[1] = s->right; - *value = (XPointer) temp; - *type = XA_SPAN(d); - *length = 2L; - *format = 32; - return True; - } + temp = (long *)XtMalloc((unsigned)sizeof(long)); + if (*target == XA_LIST_LENGTH(d)) + *temp = 1L; + else /* *target == XA_LENGTH(d) */ + *temp = (long) (s->right - s->left); - if (*target == XA_DELETE(d)) { - void _XawTextZapSelection(); /* From TextAction.c */ - - if (!salt) - _XawTextZapSelection( ctx, (XEvent *) NULL, TRUE); - *value = NULL; - *type = XA_NULL(d); - *length = 0; - *format = 32; - return True; - } + *value = (XPointer)temp; + *type = XA_INTEGER; + *length = 1L; + *format = 32; + return (True); + } - if (XmuConvertStandardSelection(w, ctx->text.time, selection, target, type, - (XPointer *)value, length, format)) - return True; - - /* else */ - return False; -} + if (*target == XA_CHARACTER_POSITION(d)) { + long * temp; + + temp = (long *)XtMalloc((unsigned)(2 * sizeof(long))); + temp[0] = (long)(s->left + 1); + temp[1] = s->right; + *value = (XPointer)temp; + *type = XA_SPAN(d); + *length = 2L; + *format = 32; + return (True); + } -/* Function Name: GetCutBuffferNumber - * Description: Returns the number of the cut buffer. - * Arguments: atom - the atom to check. - * Returns: the number of the cut buffer representing this atom or - * NOT_A_CUT_BUFFER. - */ + if (*target == XA_DELETE(d)) { + if (!salt) + _XawTextZapSelection(ctx, NULL, True); + *value = NULL; + *type = XA_NULL(d); + *length = 0; + *format = 32; + return (True); + } -#define NOT_A_CUT_BUFFER -1 + if (XmuConvertStandardSelection(w, ctx->text.time, selection, target, type, + (XPointer *)value, length, format)) + return (True); -static int -GetCutBufferNumber(atom) -Atom atom; -{ - if (atom == XA_CUT_BUFFER0) return(0); - if (atom == XA_CUT_BUFFER1) return(1); - if (atom == XA_CUT_BUFFER2) return(2); - if (atom == XA_CUT_BUFFER3) return(3); - if (atom == XA_CUT_BUFFER4) return(4); - if (atom == XA_CUT_BUFFER5) return(5); - if (atom == XA_CUT_BUFFER6) return(6); - if (atom == XA_CUT_BUFFER7) return(7); - return(NOT_A_CUT_BUFFER); -} - -static void -LoseSelection(w, selection) -Widget w; -Atom *selection; -{ - TextWidget ctx = (TextWidget) w; - Atom* atomP; - int i; - XawTextSelectionSalt *salt, *prevSalt, *nextSalt; - - _XawTextPrepareToUpdate(ctx); - - atomP = ctx->text.s.selections; - for (i = 0 ; i < ctx->text.s.atom_count; i++, atomP++) - if ( (*selection == *atomP) || - (GetCutBufferNumber(*atomP) != NOT_A_CUT_BUFFER) )/* is a cut buffer */ - *atomP = (Atom)0; - - while (ctx->text.s.atom_count && - ctx->text.s.selections[ctx->text.s.atom_count-1] == 0) - ctx->text.s.atom_count--; + /* else */ + return (False); +} /* - * Must walk the selection list in opposite order from UnsetSelection. + * Function: + * GetCutBuffferNumber + * + * Parameters: + * atom - atom to check + * + * Description: + * Returns the number of the cut buffer. + * + * Returns: + * The number of the cut buffer representing this atom or NOT_A_CUT_BUFFER */ +#define NOT_A_CUT_BUFFER -1 +static int +GetCutBufferNumber(Atom atom) +{ + if (atom == XA_CUT_BUFFER0) return (0); + if (atom == XA_CUT_BUFFER1) return (1); + if (atom == XA_CUT_BUFFER2) return (2); + if (atom == XA_CUT_BUFFER3) return (3); + if (atom == XA_CUT_BUFFER4) return (4); + if (atom == XA_CUT_BUFFER5) return (5); + if (atom == XA_CUT_BUFFER6) return (6); + if (atom == XA_CUT_BUFFER7) return (7); + return (NOT_A_CUT_BUFFER); +} - atomP = ctx->text.s.selections; - for (i = 0 ; i < ctx->text.s.atom_count; i++, atomP++) - if (*atomP == (Atom)0) { - *atomP = ctx->text.s.selections[--ctx->text.s.atom_count]; - while (ctx->text.s.atom_count && - ctx->text.s.selections[ctx->text.s.atom_count-1] == 0) +static void +TextLoseSelection(Widget w, Atom *selection) +{ + TextWidget ctx = (TextWidget)w; + Atom *atomP; + int i; + XawTextSelectionSalt*salt, *prevSalt, *nextSalt; + + atomP = ctx->text.s.selections; + for (i = 0 ; i < ctx->text.s.atom_count; i++, atomP++) + if ((*selection == *atomP) + || (GetCutBufferNumber(*atomP) != NOT_A_CUT_BUFFER)) + *atomP = (Atom)0; + + while (ctx->text.s.atom_count + && ctx->text.s.selections[ctx->text.s.atom_count - 1] == 0) ctx->text.s.atom_count--; - } - - if (ctx->text.s.atom_count == 0) - ModifySelection(ctx, ctx->text.insertPos, ctx->text.insertPos); - - if (ctx->text.old_insert >= 0) /* Update in progress. */ - _XawTextExecuteUpdate(ctx); + + /* + * Must walk the selection list in opposite order from UnsetSelection + */ + atomP = ctx->text.s.selections; + for (i = 0 ; i < ctx->text.s.atom_count; i++, atomP++) + if (*atomP == (Atom)0) { + *atomP = ctx->text.s.selections[--ctx->text.s.atom_count]; + while (ctx->text.s.atom_count + && ctx->text.s.selections[ctx->text.s.atom_count-1] == 0) + ctx->text.s.atom_count--; + } + + if (ctx->text.s.atom_count == 0) + ModifySelection(ctx, ctx->text.insertPos, ctx->text.insertPos); prevSalt = 0; - for (salt = ctx->text.salt; salt; salt = nextSalt) - { - atomP = salt->s.selections; + for (salt = ctx->text.salt; salt; salt = nextSalt) { + atomP = salt->s.selections; nextSalt = salt->next; - for (i = 0 ; i < salt->s.atom_count; i++, atomP++) + for (i = 0 ; i < salt->s.atom_count; i++, atomP++) if (*selection == *atomP) *atomP = (Atom)0; - - while (salt->s.atom_count && - salt->s.selections[salt->s.atom_count-1] == 0) - { + + while (salt->s.atom_count + && salt->s.selections[salt->s.atom_count-1] == 0) salt->s.atom_count--; - } - /* - * Must walk the selection list in opposite order from UnsetSelection. - */ - - atomP = salt->s.selections; - for (i = 0 ; i < salt->s.atom_count; i++, atomP++) - if (*atomP == (Atom)0) - { - *atomP = salt->s.selections[--salt->s.atom_count]; - while (salt->s.atom_count && - salt->s.selections[salt->s.atom_count-1] == 0) - salt->s.atom_count--; - } - if (salt->s.atom_count == 0) - { + /* + * Must walk the selection list in opposite order from UnsetSelection + */ + atomP = salt->s.selections; + for (i = 0 ; i < salt->s.atom_count; i++, atomP++) + if (*atomP == (Atom)0) { + *atomP = salt->s.selections[--salt->s.atom_count]; + while (salt->s.atom_count + && salt->s.selections[salt->s.atom_count-1] == 0) + salt->s.atom_count--; + } + + if (salt->s.atom_count == 0) { XtFree ((char *) salt->s.selections); XtFree (salt->contents); if (prevSalt) prevSalt->next = nextSalt; else ctx->text.salt = nextSalt; - XtFree ((char *) salt); + XtFree((char *)salt); } else prevSalt = salt; @@ -1786,38 +2245,34 @@ Atom *selection; } void -_XawTextSaltAwaySelection (ctx, selections, num_atoms) -TextWidget ctx; -Atom* selections; -int num_atoms; +_XawTextSaltAwaySelection(TextWidget ctx, Atom *selections, int num_atoms) { - XawTextSelectionSalt *salt; - int i, j; + XawTextSelectionSalt *salt; + int i, j; for (i = 0; i < num_atoms; i++) - LoseSelection ((Widget) ctx, selections + i); + TextLoseSelection((Widget)ctx, selections + i); if (num_atoms == 0) return; salt = (XawTextSelectionSalt *) - XtMalloc( (unsigned) sizeof(XawTextSelectionSalt) ); + XtMalloc((unsigned)sizeof(XawTextSelectionSalt)); if (!salt) return; - salt->s.selections = (Atom *) - XtMalloc( (unsigned) ( num_atoms * sizeof (Atom) ) ); - if (!salt->s.selections) - { - XtFree ((char *) salt); + salt->s.selections = (Atom *)XtMalloc((unsigned)(num_atoms * sizeof(Atom))); + if (!salt->s.selections) { + XtFree((char *)salt); return; } salt->s.left = ctx->text.s.left; salt->s.right = ctx->text.s.right; salt->s.type = ctx->text.s.type; salt->contents = _XawTextGetSTRING(ctx, ctx->text.s.left, ctx->text.s.right); - if (_XawTextFormat(ctx) == XawFmtWide) { + if (XawTextFormat(ctx, XawFmtWide)) { XTextProperty textprop; if (XwcTextListToTextProperty(XtDisplay((Widget)ctx), - (wchar_t**)(&(salt->contents)), 1, XCompoundTextStyle, - &textprop) < Success) { + (wchar_t**)(&(salt->contents)), 1, + XCompoundTextStyle, + &textprop) < Success) { XtFree(salt->contents); salt->length = 0; return; @@ -1825,307 +2280,544 @@ int num_atoms; XtFree(salt->contents); salt->contents = (char *)textprop.value; salt->length = textprop.nitems; - } else - salt->length = strlen (salt->contents); + } + else + salt->length = strlen (salt->contents); salt->next = ctx->text.salt; ctx->text.salt = salt; j = 0; - for (i = 0; i < num_atoms; i++) - { - if (GetCutBufferNumber (selections[i]) == NOT_A_CUT_BUFFER) - { + for (i = 0; i < num_atoms; i++) { + if (GetCutBufferNumber (selections[i]) == NOT_A_CUT_BUFFER) { salt->s.selections[j++] = selections[i]; - XtOwnSelection ((Widget) ctx, selections[i], ctx->text.time, - ConvertSelection, LoseSelection, (XtSelectionDoneProc)NULL); + XtOwnSelection((Widget)ctx, selections[i], ctx->text.time, + TextConvertSelection, TextLoseSelection, NULL); } } salt->s.atom_count = j; } -static void -_SetSelection(ctx, left, right, selections, count) -TextWidget ctx; -XawTextPosition left, right; -Atom *selections; -Cardinal count; +static void +_SetSelection(TextWidget ctx, XawTextPosition left, XawTextPosition right, + Atom *selections, Cardinal count) { - XawTextPosition pos; - - if (left < ctx->text.s.left) { - pos = Min(right, ctx->text.s.left); - _XawTextNeedsUpdating(ctx, left, pos); - } - if (left > ctx->text.s.left) { - pos = Min(left, ctx->text.s.right); - _XawTextNeedsUpdating(ctx, ctx->text.s.left, pos); - } - if (right < ctx->text.s.right) { - pos = Max(right, ctx->text.s.left); - _XawTextNeedsUpdating(ctx, pos, ctx->text.s.right); - } - if (right > ctx->text.s.right) { - pos = Max(left, ctx->text.s.right); - _XawTextNeedsUpdating(ctx, pos, right); - } - - ctx->text.s.left = left; - ctx->text.s.right = right; +#ifndef OLDXAW + Cardinal i; + XawTextPosition pos; + TextSrcObject src = (TextSrcObject)ctx->text.source; - SrcSetSelection(ctx->text.source, left, right, - (count == 0) ? None : selections[0]); + for (i = 0; i < src->textSrc.num_text; i++) { + TextWidget tw = (TextWidget)src->textSrc.text[i]; + Bool needs_updating = tw->text.old_insert < 0; + Bool showposition = tw->text.showposition; - if (left < right) { - Widget w = (Widget) ctx; - int buffer; - - while (count) { - Atom selection = selections[--count]; + if (needs_updating) { + tw->text.showposition = False; + _XawTextPrepareToUpdate(tw); + } +#else + TextWidget tw = ctx; + XawTextPosition pos; +#endif /* OLDXAW */ -/* - * If this is a cut buffer. - */ + if (left < tw->text.s.left) { + pos = Min(right, tw->text.s.left); + _XawTextNeedsUpdating(tw, left, pos); + } + if (left > tw->text.s.left) { + pos = Min(left, tw->text.s.right); + _XawTextNeedsUpdating(tw, tw->text.s.left, pos); + } + if (right < tw->text.s.right) { + pos = Max(right, tw->text.s.left); + _XawTextNeedsUpdating(tw, pos, tw->text.s.right); + } + if (right > tw->text.s.right) { + pos = Max(left, tw->text.s.right); + _XawTextNeedsUpdating(tw, pos, right); + } - if ((buffer = GetCutBufferNumber(selection)) != NOT_A_CUT_BUFFER) { - unsigned char *ptr, *tptr; - unsigned int amount, max_len = MAX_CUT_LEN(XtDisplay(w)); - unsigned long len; - - tptr= ptr= (unsigned char *) _XawTextGetSTRING(ctx, ctx->text.s.left, - ctx->text.s.right); - if (_XawTextFormat(ctx) == XawFmtWide) { - /* - * Only XA_STRING(Latin 1) is allowed in CUT_BUFFER, - * so we get it from wchar string, then free the wchar string. - */ - XTextProperty textprop; - if (XwcTextListToTextProperty(XtDisplay(w), (wchar_t**)&ptr, 1, - XStringStyle, &textprop) < Success) { - XtFree((char *)ptr); - return; - } - XtFree((char *)ptr); - tptr = ptr = textprop.value; - } - if (buffer == 0) { - _CreateCutBuffers(XtDisplay(w)); - XRotateBuffers(XtDisplay(w), 1); + tw->text.s.left = left; + tw->text.s.right = right; + +#ifndef OLDXAW + if (needs_updating) { + _XawTextExecuteUpdate(tw); + tw->text.showposition = showposition; } - amount = Min ( (len = strlen((char *)ptr)), max_len); - XChangeProperty(XtDisplay(w), RootWindow(XtDisplay(w), 0), selection, - XA_STRING, 8, PropModeReplace, ptr, amount); - - while (len > max_len) { - len -= max_len; - tptr += max_len; - amount = Min (len, max_len); - XChangeProperty(XtDisplay(w), RootWindow(XtDisplay(w), 0), - selection, XA_STRING, 8, PropModeAppend, - tptr, amount); + } +#endif /* OLDXAW */ + + SrcSetSelection(ctx->text.source, left, right, + (count == 0) ? None : selections[0]); + + if (left < right) { + Widget w = (Widget)ctx; + int buffer; + + while (count) { + Atom selection = selections[--count]; + + /* + * If this is a cut buffer + */ + if ((buffer = GetCutBufferNumber(selection)) != NOT_A_CUT_BUFFER) { + unsigned char *ptr, *tptr; + unsigned int amount, max_len = MAX_CUT_LEN(XtDisplay(w)); + unsigned long len; + + tptr= ptr= (unsigned char *)_XawTextGetSTRING(ctx, + ctx->text.s.left, + ctx->text.s.right); + if (XawTextFormat(ctx, XawFmtWide)) { + /* + * Only XA_STRING(Latin 1) is allowed in CUT_BUFFER, + * so we get it from wchar string, then free the wchar string + */ + XTextProperty textprop; + + if (XwcTextListToTextProperty(XtDisplay(w), (wchar_t**)&ptr, + 1, XStringStyle, &textprop) + < Success){ + XtFree((char *)ptr); + return; + } + XtFree((char *)ptr); + tptr = ptr = textprop.value; + } + if (buffer == 0) { + _CreateCutBuffers(XtDisplay(w)); + XRotateBuffers(XtDisplay(w), 1); + } + amount = Min ((len = strlen((char *)ptr)), max_len); + XChangeProperty(XtDisplay(w), RootWindow(XtDisplay(w), 0), + selection, XA_STRING, 8, PropModeReplace, + ptr, amount); + + while (len > max_len) { + len -= max_len; + tptr += max_len; + amount = Min (len, max_len); + XChangeProperty(XtDisplay(w), RootWindow(XtDisplay(w), 0), + selection, XA_STRING, 8, PropModeAppend, + tptr, amount); + } + XtFree ((char *)ptr); + } + else /* This is a real selection */ + XtOwnSelection(w, selection, ctx->text.time, TextConvertSelection, + TextLoseSelection, NULL); } - XtFree ((char *)ptr); - } - else /* This is a real selection */ - XtOwnSelection(w, selection, ctx->text.time, ConvertSelection, - LoseSelection, (XtSelectionDoneProc)NULL); } - } - else - XawTextUnsetSelection((Widget)ctx); + else + XawTextUnsetSelection((Widget)ctx); } -/* - * This internal routine deletes the text from pos1 to pos2 in a source and - * then inserts, at pos1, the text that was passed. As a side effect it - * "invalidates" that portion of the displayed text (if any). - * - * NOTE: It is illegal to call this routine unless there is a valid line table! - */ +#ifndef OLDXAW +void +_XawTextSetLineAndColumnNumber(TextWidget ctx, Bool force) +{ + int line_number, column_number; + + if (ctx->text.old_insert != ctx->text.insertPos && + ctx->text.lt.base_line < 0) { + ctx->text.lt.base_line = 0; + (void)_BuildLineTable(ctx, ctx->text.lt.top, 0); + } + + line_number = ResolveLineNumber(ctx); + column_number = ResolveColumnNumber(ctx); + + if (force || (ctx->text.column_number != column_number + || ctx->text.line_number != line_number)) { + XawTextPositionInfo info; -int -_XawTextReplace (ctx, pos1, pos2, text) -TextWidget ctx; -XawTextPosition pos1, pos2; -XawTextBlock *text; + ctx->text.line_number = info.line_number = line_number; + ctx->text.column_number = info.column_number = column_number; + info.insert_position = ctx->text.insertPos; + info.last_position = ctx->text.lastPos; + info.overwrite_mode = ctx->text.overwrite; + + XtCallCallbacks((Widget)ctx, XtNpositionCallback, (XtPointer)&info); + } +} + +static int +ResolveColumnNumber(TextWidget ctx) { - int i, line1, delta, error; - XawTextPosition updateFrom, updateTo; - Widget src = ctx->text.source; - XawTextEditType edit_mode; - Arg args[1]; - Boolean tmp = ctx->text.update_disabled; + Widget src = ctx->text.source; + short column_number = 0; + XawTextPosition position; + XawTextBlock block; + unsigned long format = _XawTextFormat(ctx); + TextSinkObject sink = (TextSinkObject)ctx->text.sink; + short *char_tabs = sink->text_sink.char_tabs; + int tab_count = sink->text_sink.tab_count; + int tab_index = 0, tab_column = 0, tab_base = 0; + + if (ctx->text.lt.base_line < 1) + return (ctx->text.column_number); + + position = SrcScan(src, ctx->text.insertPos, XawstEOL, XawsdLeft, 1, False); + XawTextSourceRead(src, position, &block, ctx->text.insertPos - position); + + for (; position < ctx->text.insertPos; position++) { + if (position - block.firstPos >= block.length) + XawTextSourceRead(src, position, &block, ctx->text.insertPos - position); + if ((format == XawFmt8Bit && block.ptr[position - block.firstPos] == '\t') || + (format == XawFmtWide && ((wchar_t*)block.ptr)[position - block.firstPos] == _Xaw_atowc(XawTAB))) { + while (tab_base + tab_column <= column_number) { + if (tab_count) { + for (; tab_index < tab_count; ++tab_index) + if (tab_base + char_tabs[tab_index] > column_number) { + tab_column = char_tabs[tab_index]; + break; + } + if (tab_index >= tab_count) { + tab_base += char_tabs[tab_count - 1]; + tab_column = tab_index = 0; + } + } + else + tab_column += DEFAULT_TAB_SIZE; + } + column_number = tab_base + tab_column; + } + else + ++column_number; + if (column_number >= 16384) { + column_number = 16383; + break; + } + } - ctx->text.update_disabled = True; /* No redisplay during replacement. */ + return (column_number); +} +#endif /* OLDXAW */ -/* - * The insertPos may not always be set to the right spot in XawtextAppend - */ +void +_XawTextSourceChanged(Widget w, XawTextPosition left, XawTextPosition right, + XawTextBlock *block, int lines) +{ + TextWidget ctx = (TextWidget)w; + Widget src = ctx->text.source; + XawTextPosition update_from, update_to, top; + Boolean update_disabled; + int delta, line, line_from; - XtSetArg(args[0], XtNeditType, &edit_mode); - XtGetValues(src, args, ONE); + if (left < ctx->text.old_insert) { + XawTextPosition old_insert = ctx->text.old_insert; - if ((pos1 == ctx->text.insertPos) && (edit_mode == XawtextAppend)) { - ctx->text.insertPos = ctx->text.lastPos; - pos2 = SrcScan(src, ctx->text.insertPos, XawstPositions, XawsdRight, - (int)(ctx->text.insertPos - pos1), (Boolean)TRUE); - pos1 = ctx->text.insertPos; - if ( (pos1 == pos2) && (text->length == 0) ) { - ctx->text.update_disabled = FALSE; /* rearm redisplay. */ - return( XawEditError ); + if (right < ctx->text.old_insert) + old_insert -= right - left; + else + old_insert = left; + + ctx->text.insertPos = old_insert + block->length; } - } +#ifndef OLDXAW + if (left <= ctx->text.lt.top) { + if (left + block->length - (right - left) < ctx->text.lt.top) { + ctx->text.source_changed = SRC_CHANGE_BEFORE; + ctx->text.lt.base_line += lines; + } + else + ctx->text.source_changed = SRC_CHANGE_OVERLAP; + } + else + ctx->text.source_changed = SRC_CHANGE_AFTER; +#endif - updateFrom = SrcScan(src, pos1, XawstWhiteSpace, XawsdLeft, 1, FALSE); - updateFrom = Max(updateFrom, ctx->text.lt.top); + update_from = left; + update_to = left + block->length; + update_to = SrcScan(src, update_to, XawstEOL, XawsdRight, 1, False); + delta = block->length - (right - left); + if (delta < 0) + ctx->text.clear_to_eol = True; + if (update_to == update_from) + ++update_to; + update_disabled = ctx->text.update_disabled; + ctx->text.update_disabled = True; + ctx->text.lastPos = XawTextGetLastPosition(ctx); + top = ctx->text.lt.info[0].position; - line1 = LineForPosition(ctx, updateFrom); - if ( (error = SrcReplace(src, pos1, pos2, text)) != 0) { - ctx->text.update_disabled = tmp; /* restore redisplay */ - return(error); - } + XawTextUnsetSelection((Widget)ctx); - XawTextUnsetSelection((Widget)ctx); + if (delta) { + int i; + XmuSegment *seg; + + for (seg = ctx->text.update->segment; seg; seg = seg->next) { + if (seg->x1 > (int)left) + break; + else if (seg->x2 > (int)left) { + seg->x2 += delta; + seg = seg->next; + break; + } + } + for (; seg; seg = seg->next) { + seg->x1 += delta; + seg->x2 += delta; + } + XmuOptimizeScanline(ctx->text.update); - ctx->text.lastPos = GETLASTPOS; - if (ctx->text.lt.top >= ctx->text.lastPos) { - _XawTextBuildLineTable(ctx, ctx->text.lastPos, FALSE); - ClearWindow( (Widget) ctx); - ctx->text.update_disabled = tmp; /* restore redisplay */ - return(0); /* Things are fine. */ - } + for (i = 0; i <= ctx->text.lt.lines; i++) + if (ctx->text.lt.info[i].position > left) + break; + for (; i <= ctx->text.lt.lines; i++) + ctx->text.lt.info[i].position += delta; + } - ctx->text.single_char = (text->length <= 1 && pos2 - pos1 <= 1); + if (top != ctx->text.lt.info[0].position) { + line_from = line = 0; + ctx->text.lt.top = top = SrcScan(src, ctx->text.lt.info[0].position, + XawstEOL, XawsdLeft, 1, False); + update_from = top; + } + else { + line_from = line = LineForPosition(ctx, update_from + delta); + top = ctx->text.lt.info[line].position; + } - delta = text->length - (pos2 - pos1); + if (line > 0 && ctx->text.wrap == XawtextWrapWord) { + --line; + top = ctx->text.lt.info[line].position; + } - if (delta < ctx->text.lastPos) { - for (pos2 += delta, i = 0; i < ctx->text.numranges; i++) { - if (ctx->text.updateFrom[i] > pos1) - ctx->text.updateFrom[i] += delta; - if (ctx->text.updateTo[i] >= pos1) - ctx->text.updateTo[i] += delta; + (void)_BuildLineTable(ctx, top, line); + + if (ctx->text.wrap == XawtextWrapWord) { + if (line_from != LineForPosition(ctx, update_from) + || line_from != LineForPosition(ctx, update_to)) { + ctx->text.clear_to_eol = True; + update_from = SrcScan(src, update_from, + XawstWhiteSpace, XawsdLeft, 1, True); + if (update_to >= ctx->text.lastPos) + /* this is not an error, it just tells _BuildLineTable to + * clear to the bottom of the window. The value of update_to + * should not be > ctx->text.lastPos. + */ + ++update_to; + } + } + else if (!ctx->text.clear_to_eol) { + if (LineForPosition(ctx, update_from) + != LineForPosition(ctx, update_to)) + ctx->text.clear_to_eol = True; } - } - - /* - * fixup all current line table entries to reflect edit. - * %%% it is not legal to do arithmetic on positions. - * using Scan would be more proper. - */ - if (delta != 0) { - XawTextLineTableEntry *lineP; - i = LineForPosition(ctx, pos1) + 1; - for (lineP = ctx->text.lt.info + i; i <= ctx->text.lt.lines; i++, lineP++) - lineP->position += delta; - } - - /* - * Now process the line table and fixup in case edits caused - * changes in line breaks. If we are breaking on word boundaries, - * this code checks for moving words to and from lines. - */ - - if (IsPositionVisible(ctx, updateFrom)) { - updateTo = _BuildLineTable(ctx, - ctx->text.lt.info[line1].position, pos1, line1); - _XawTextNeedsUpdating(ctx, updateFrom, updateTo); - } - ctx->text.update_disabled = tmp; /* restore redisplay */ - return(0); /* Things are fine. */ + _XawTextNeedsUpdating(ctx, update_from, update_to); + ctx->text.update_disabled = update_disabled; } /* - * This routine will display text between two arbitrary source positions. - * In the event that this span contains highlighted text for the selection, - * only that portion will be displayed highlighted. + * Function: + * _XawTextReplace + * + * Parameters: + * ctx - text widget + * left - left offset + * right - right offset + * block - text block * - * NOTE: it is illegal to call this routine unless there - * is a valid line table! + * Description: + * Replaces the text between left and right by the text in block. + * Does all the required calculations of offsets, and rebuild the + * the line table, from the insertion point (or previous line, if + * wrap mode is 'word'). + * + * Returns: + * XawEditDone - success + * any other value - error code */ +int +_XawTextReplace(TextWidget ctx, XawTextPosition left, XawTextPosition right, + XawTextBlock *block) +{ + Arg args[1]; + Widget src; + XawTextEditType edit_mode; + + if (left == right && block->length == 0) + return (XawEditDone); + + src = ctx->text.source; + XtSetArg(args[0], XtNeditType, &edit_mode); + XtGetValues(src, args, 1); + + if (edit_mode == XawtextAppend) { + if (block->length == 0) + return (XawEditError); + ctx->text.insertPos = ctx->text.lastPos; + } + +#ifndef OLDXAW + return (SrcReplace(src, left, right, block)); +#else + if (SrcReplace(src, left, right, block) == XawEditDone) { + _XawTextSourceChanged((Widget)ctx, left, right, block, 0); + + return (XawEditDone); + } -static void -DisplayText(w, pos1, pos2) -Widget w; -XawTextPosition pos1, pos2; + return (XawEditError); +#endif +} + +/* + * This routine will display text between two arbitrary source positions. + * In the event that this span contains highlighted text for the selection, + * only that portion will be displayed highlighted. + */ +static void +OldDisplayText(Widget w, XawTextPosition left, XawTextPosition right) { - TextWidget ctx = (TextWidget)w; - Position x, y; - int height, line, i, lastPos = ctx->text.lastPos; - XawTextPosition startPos, endPos; - Boolean clear_eol, done_painting; + static XmuSegment segment; + static XmuScanline next; + static XmuScanline scanline = {0, &segment, &next}; + static XmuArea area = {&scanline}; + + TextWidget ctx = (TextWidget)w; + int x, y, line; + XawTextPosition start, end, last, final; + XmuScanline *scan; + XmuSegment *seg; + XmuArea *clip = NULL; + Bool cleol = ctx->text.clear_to_eol; + Bool has_selection = ctx->text.s.right > ctx->text.s.left; + + left = left < ctx->text.lt.top ? ctx->text.lt.top : left; + + if (left > right || !LineAndXYForPosition(ctx, left, &line, &x, &y)) + return; - pos1 = (pos1 < ctx->text.lt.top) ? ctx->text.lt.top : pos1; - pos2 = FindGoodPosition(ctx, pos2); - if ( (pos1 >= pos2) || !LineAndXYForPosition(ctx, pos1, &line, &x, &y) ) - return; /* line not visible, or pos1 >= pos2. */ + last = XawTextGetLastPosition(ctx); + segment.x2 = (int)XtWidth(ctx) - ctx->text.r_margin.right; + + if (cleol) + clip = XmuCreateArea(); + + for (start = left; start < right && line < ctx->text.lt.lines; line++) { + if ((end = ctx->text.lt.info[line + 1].position) > right) + end = right; + + final = end; + if (end > last) + end = last; + + if (end > start) { + if (!has_selection + || (start >= ctx->text.s.right || end <= ctx->text.s.left)) + _XawTextSinkDisplayText(ctx->text.sink, x, y, start, end, False); + else if (start >= ctx->text.s.left && end <= ctx->text.s.right) + _XawTextSinkDisplayText(ctx->text.sink, x, y, start, end, True); + else { + OldDisplayText(w, start, ctx->text.s.left); + OldDisplayText(w, Max(start, ctx->text.s.left), + Min(end, ctx->text.s.right)); + OldDisplayText(w, ctx->text.s.right, end); + } + } - for ( startPos = pos1, i = line; IsValidLine(ctx, i) && - (i < ctx->text.lt.lines) ; i++) { + x = ctx->text.left_margin; + if (cleol) { + segment.x1 = ctx->text.lt.info[line].textWidth + x; + if (XmuValidSegment(&segment)) { + scanline.y = y; + next.y = ctx->text.lt.info[line + 1].y; + XmuAreaOr(clip, &area); + } + } - - if ( (endPos = ctx->text.lt.info[i + 1].position) > pos2 ) { - clear_eol = ((endPos = pos2) >= lastPos); - done_painting = (!clear_eol || ctx->text.single_char); + start = final; + y = ctx->text.lt.info[line + 1].y; } - else { - clear_eol = TRUE; - done_painting = FALSE; - } - - height = ctx->text.lt.info[i + 1].y - ctx->text.lt.info[i].y; - - if ( (endPos > startPos) ) { - if ( (x == (Position) ctx->text.margin.left) && (x > 0) ) - SinkClearToBG (ctx->text.sink, - (Position) 0, y, - (Dimension) ctx->text.margin.left, (Dimension)height); - - if ( (startPos >= ctx->text.s.right) || (endPos <= ctx->text.s.left) ) - XawTextSinkDisplayText(ctx->text.sink, x, y, startPos, endPos, FALSE); - else if ((startPos >= ctx->text.s.left) && (endPos <= ctx->text.s.right)) - XawTextSinkDisplayText(ctx->text.sink, x, y, startPos, endPos, TRUE); - else { - DisplayText(w, startPos, ctx->text.s.left); - DisplayText(w, Max(startPos, ctx->text.s.left), - Min(endPos, ctx->text.s.right)); - DisplayText(w, ctx->text.s.right, endPos); - } - } - startPos = endPos; - if (clear_eol) { - SinkClearToBG(ctx->text.sink, - (Position) (ctx->text.lt.info[i].textWidth + - ctx->text.margin.left), - (Position) y, w->core.width, (Dimension) height); - /* - * We only get here if single character is true, and we need - * to clear to the end of the screen. We know that since there - * was only one character deleted that this is the same - * as clearing an extra line, so we do this, and are done. - * - * This a performance hack, and a pretty gross one, but it works. - * - * Chris Peterson 11/13/89. - */ + if (cleol) { + for (scan = clip->scanline; scan && scan->next; scan = scan->next) + for (seg = scan->segment; seg; seg = seg->next) + SinkClearToBG(ctx->text.sink, + seg->x1, scan->y, + seg->x2 - seg->x1, scan->next->y - scan->y); + XmuDestroyArea(clip); + } +} + +/*ARGSUSED*/ +static void +DisplayText(Widget w, XawTextPosition left, XawTextPosition right) +{ +#ifndef OLDXAW + static XmuSegment segment; + static XmuScanline next; + static XmuScanline scanline = {0, &segment, &next}; + static XmuArea area = {&scanline}; + + TextWidget ctx = (TextWidget)w; + int y, line; + XawTextPosition from, to, lastPos; + Bool cleol = ctx->text.clear_to_eol; + Bool has_selection = ctx->text.s.right > ctx->text.s.left; + XawTextPaintList *paint_list; + + left = left < ctx->text.lt.top ? ctx->text.lt.top : left; + + if (left > right || !IsPositionVisible(ctx, left)) + return; - if (done_painting) { - y += height; - SinkClearToBG(ctx->text.sink, - (Position) ctx->text.margin.left, (Position) y, - w->core.width, (Dimension) height); + line = LineForPosition(ctx, left); + y = ctx->text.lt.info[line].y; + segment.x2 = (int)XtWidth(ctx) - ctx->text.r_margin.right; + lastPos = XawTextGetLastPosition(ctx); + + paint_list = ((TextSinkObject)ctx->text.sink)->text_sink.paint; + + for (from = left; from < right && line < ctx->text.lt.lines; line++) { + if ((to = ctx->text.lt.info[line + 1].position) > right) + to = right; + + if (to > lastPos) + to = lastPos; + + if (from < to) { + if (!has_selection + || (from >= ctx->text.s.right || to <= ctx->text.s.left)) + XawTextSinkPreparePaint(ctx->text.sink, y, line, from, to, False); + else if (from >= ctx->text.s.left && to <= ctx->text.s.right) + XawTextSinkPreparePaint(ctx->text.sink, y, line, from, to, True); + else { + XawTextSinkPreparePaint(ctx->text.sink, y, line, from, + ctx->text.s.left, False); + XawTextSinkPreparePaint(ctx->text.sink, y, line, + XawMax(from, ctx->text.s.left), + XawMin(to, ctx->text.s.right), True); + XawTextSinkPreparePaint(ctx->text.sink, y, line, + ctx->text.s.right, to, False); + } + } - break; /* set single_char to FALSE and return. */ + if (cleol) { + segment.x1 = ctx->text.lt.info[line].textWidth + ctx->text.left_margin; + if (XmuValidSegment(&segment)) { + scanline.y = y; + next.y = ctx->text.lt.info[line + 1].y; + XmuAreaOr(paint_list->clip, &area); + } } + y = ctx->text.lt.info[line + 1].y; + from = to; } - x = (Position) ctx->text.margin.left; - y = ctx->text.lt.info[i + 1].y; - if ( done_painting - || (y >= (int)(ctx->core.height - ctx->text.margin.bottom)) ) - break; - } - ctx->text.single_char = FALSE; + /* clear to the bottom of the window */ + if (cleol && line >= ctx->text.lt.lines) { + segment.x1 = ctx->text.left_margin; + if (XmuValidSegment(&segment)) { + scanline.y = y; + next.y = (int)XtHeight(ctx) - (int)ctx->text.margin.bottom; + XmuAreaOr(paint_list->clip, &area); + } + } +#endif } /* @@ -2137,115 +2829,115 @@ XawTextPosition pos1, pos2; * will allows clients to implements a wide class of draw through and * multi-click selection user interfaces.] */ +static void +DoSelection(TextWidget ctx, XawTextPosition pos, Time time, Bool motion) +{ + XawTextPosition newLeft, newRight; + XawTextSelectType newType, *sarray; + Widget src = ctx->text.source; -static void -DoSelection (ctx, pos, time, motion) -TextWidget ctx; -XawTextPosition pos; -Time time; -Boolean motion; -{ - XawTextPosition newLeft, newRight; - XawTextSelectType newType, *sarray; - Widget src = ctx->text.source; - - if (motion) - newType = ctx->text.s.type; - else { - if ( (abs((long) time - (long) ctx->text.lasttime) < MULTI_CLICK_TIME) && - ((pos >= ctx->text.s.left) && (pos <= ctx->text.s.right))) { - sarray = ctx->text.sarray; - for (;*sarray != XawselectNull && *sarray != ctx->text.s.type; sarray++); - - if (*sarray == XawselectNull) - newType = *(ctx->text.sarray); - else { - newType = *(sarray + 1); - if (newType == XawselectNull) - newType = *(ctx->text.sarray); - } - } - else /* single-click event */ - newType = *(ctx->text.sarray); - - ctx->text.lasttime = time; - } - switch (newType) { - case XawselectPosition: - newLeft = newRight = pos; - break; - case XawselectChar: - newLeft = pos; - newRight = SrcScan(src, pos, XawstPositions, XawsdRight, 1, FALSE); - break; - case XawselectWord: - case XawselectParagraph: - { - XawTextScanType stype; - - if (newType == XawselectWord) - stype = XawstWhiteSpace; - else - stype = XawstParagraph; - - /* - * Somewhat complicated, but basically I treat the space between - * two objects as another object. The object that I am currently - * in then becomes the end of the selection. - * - * Chris Peterson - 4/19/90. - */ - - newRight = SrcScan(ctx->text.source, pos, stype, XawsdRight, 1, FALSE); - newRight =SrcScan(ctx->text.source, newRight,stype,XawsdLeft,1, FALSE); - - if (pos != newRight) - newLeft = SrcScan(ctx->text.source, pos, stype, XawsdLeft, 1, FALSE); - else - newLeft = pos; - - newLeft =SrcScan(ctx->text.source, newLeft, stype, XawsdRight,1,FALSE); - - if (newLeft > newRight) { - XawTextPosition temp = newLeft; - newLeft = newRight; - newRight = temp; - } - } - break; - case XawselectLine: - newLeft = SrcScan(src, pos, XawstEOL, XawsdLeft, 1, FALSE); - newRight = SrcScan(src, pos, XawstEOL, XawsdRight, 1, FALSE); - break; - case XawselectAll: - newLeft = SrcScan(src, pos, XawstAll, XawsdLeft, 1, FALSE); - newRight = SrcScan(src, pos, XawstAll, XawsdRight, 1, FALSE); - break; - default: - XtAppWarning(XtWidgetToApplicationContext((Widget) ctx), - "Text Widget: empty selection array."); - return; - } + if (motion) + newType = ctx->text.s.type; + else { + if ((abs((long) time - (long) ctx->text.lasttime) < MULTI_CLICK_TIME) + && (pos >= ctx->text.s.left && pos <= ctx->text.s.right)) { + sarray = ctx->text.sarray; + for (; *sarray != XawselectNull && *sarray != ctx->text.s.type; + sarray++) + ; + if (*sarray == XawselectNull) + newType = *(ctx->text.sarray); + else { + newType = *(sarray + 1); + if (newType == XawselectNull) + newType = *(ctx->text.sarray); + } + } + else /* single-click event */ + newType = *(ctx->text.sarray); - if ( (newLeft != ctx->text.s.left) || (newRight != ctx->text.s.right) - || (newType != ctx->text.s.type)) { - ModifySelection(ctx, newLeft, newRight); - if (pos - ctx->text.s.left < ctx->text.s.right - pos) - ctx->text.insertPos = newLeft; - else - ctx->text.insertPos = newRight; - ctx->text.s.type = newType; - } - if (!motion) { /* setup so we can freely mix select extend calls*/ - ctx->text.origSel.type = ctx->text.s.type; - ctx->text.origSel.left = ctx->text.s.left; - ctx->text.origSel.right = ctx->text.s.right; + ctx->text.lasttime = time; + } + switch (newType) { + case XawselectPosition: + newLeft = newRight = pos; + break; + case XawselectChar: + newLeft = pos; + newRight = SrcScan(src, pos, XawstPositions, XawsdRight, 1, False); + break; + case XawselectWord: + case XawselectParagraph: + case XawselectAlphaNumeric: { + XawTextScanType stype; + + if (newType == XawselectWord) + stype = XawstWhiteSpace; + else if (newType == XawselectParagraph) + stype = XawstParagraph; + else + stype = XawstAlphaNumeric; + + /* + * Somewhat complicated, but basically I treat the space between + * two objects as another object. The object that I am currently + * in then becomes the end of the selection. + * + * Chris Peterson - 4/19/90. + */ + newRight = SrcScan(ctx->text.source, pos, stype, + XawsdRight, 1, False); + newRight = SrcScan(ctx->text.source, newRight, stype, + XawsdLeft, 1, False); + + if (pos != newRight) + newLeft = SrcScan(ctx->text.source, pos, stype, + XawsdLeft, 1, False); + else + newLeft = pos; - if (pos >= ctx->text.s.left + ((ctx->text.s.right - ctx->text.s.left) / 2)) - ctx->text.extendDir = XawsdRight; - else - ctx->text.extendDir = XawsdLeft; - } + newLeft =SrcScan(ctx->text.source, newLeft, stype, + XawsdRight, 1, False); + + if (newLeft > newRight) { + XawTextPosition temp = newLeft; + newLeft = newRight; + newRight = temp; + } + } break; + case XawselectLine: + newLeft = SrcScan(src, pos, XawstEOL, XawsdLeft, 1, False); + newRight = SrcScan(src, pos, XawstEOL, XawsdRight, 1, False); + break; + case XawselectAll: + newLeft = SrcScan(src, pos, XawstAll, XawsdLeft, 1, False); + newRight = SrcScan(src, pos, XawstAll, XawsdRight, 1, False); + break; + default: + XtAppWarning(XtWidgetToApplicationContext((Widget) ctx), + "Text Widget: empty selection array."); + return; + } + + if (newLeft != ctx->text.s.left || newRight != ctx->text.s.right + || newType != ctx->text.s.type) { + ModifySelection(ctx, newLeft, newRight); + if (pos - ctx->text.s.left < ctx->text.s.right - pos) + ctx->text.insertPos = newLeft; + else + ctx->text.insertPos = newRight; + ctx->text.s.type = newType; + } + if (!motion) { /* setup so we can freely mix select extend calls*/ + ctx->text.origSel.type = ctx->text.s.type; + ctx->text.origSel.left = ctx->text.s.left; + ctx->text.origSel.right = ctx->text.s.right; + + if (pos >= ctx->text.s.left + (ctx->text.s.right - ctx->text.s.left) / 2) + ctx->text.extendDir = XawsdRight; + else + ctx->text.extendDir = XawsdLeft; + } } /* @@ -2255,274 +2947,235 @@ Boolean motion; * cross through the "center" of the current selection (e.g. switch which * end you are extending!). */ - -static void -ExtendSelection (ctx, pos, motion) -TextWidget ctx; -XawTextPosition pos; -Boolean motion; +static void +ExtendSelection(TextWidget ctx, XawTextPosition pos, Bool motion) { - XawTextScanDirection dir; + XawTextScanDirection dir; + + if (!motion) { /* setup for extending selection */ + if (ctx->text.s.left == ctx->text.s.right) /* no current selection. */ + ctx->text.s.left = ctx->text.s.right = ctx->text.insertPos; + else { + ctx->text.origSel.left = ctx->text.s.left; + ctx->text.origSel.right = ctx->text.s.right; + } - if (!motion) { /* setup for extending selection */ - if (ctx->text.s.left == ctx->text.s.right) /* no current selection. */ - ctx->text.s.left = ctx->text.s.right = ctx->text.insertPos; - else { - ctx->text.origSel.left = ctx->text.s.left; - ctx->text.origSel.right = ctx->text.s.right; + ctx->text.origSel.type = ctx->text.s.type; + + if (pos >= ctx->text.s.left + (ctx->text.s.right - ctx->text.s.left) / 2) + ctx->text.extendDir = XawsdRight; + else + ctx->text.extendDir = XawsdLeft; + } + else /* check for change in extend direction */ + if ((ctx->text.extendDir == XawsdRight && + pos <= ctx->text.origSel.left) || + (ctx->text.extendDir == XawsdLeft && + pos >= ctx->text.origSel.right)) { + ctx->text.extendDir = (ctx->text.extendDir == XawsdRight) ? + XawsdLeft : XawsdRight; + ModifySelection(ctx, ctx->text.origSel.left, ctx->text.origSel.right); + } + + dir = ctx->text.extendDir; + switch (ctx->text.s.type) { + case XawselectWord: + case XawselectParagraph: + case XawselectAlphaNumeric: { + XawTextPosition left_pos, right_pos; + XawTextScanType stype; + + if (ctx->text.s.type == XawselectWord) + stype = XawstWhiteSpace; + else if (ctx->text.s.type == XawselectParagraph) + stype = XawstParagraph; + else + stype = XawstAlphaNumeric; + + /* + * Somewhat complicated, but basically I treat the space between + * two objects as another object. The object that I am currently + * in then becomes the end of the selection. + * + * Chris Peterson - 4/19/90. + */ + right_pos = SrcScan(ctx->text.source, pos, stype, + XawsdRight, 1, False); + right_pos =SrcScan(ctx->text.source, right_pos, stype, + XawsdLeft, 1, False); + + if (pos != right_pos) + left_pos = SrcScan(ctx->text.source, pos, stype, + XawsdLeft, 1, False); + else + left_pos = pos; + + left_pos =SrcScan(ctx->text.source, left_pos, stype, + XawsdRight, 1, False); + + if (dir == XawsdLeft) + pos = Min(left_pos, right_pos); + else /* dir == XawsdRight */ + pos = Max(left_pos, right_pos); + } break; + case XawselectLine: + pos = SrcScan(ctx->text.source, pos, XawstEOL, + dir, 1, dir == XawsdRight); + break; + case XawselectAll: + pos = ctx->text.insertPos; + /*FALLTHROUGH*/ + case XawselectPosition: + default: + break; } - - ctx->text.origSel.type = ctx->text.s.type; - if (pos >= ctx->text.s.left + ((ctx->text.s.right - ctx->text.s.left) / 2)) - ctx->text.extendDir = XawsdRight; + if (dir == XawsdRight) + ModifySelection(ctx, ctx->text.s.left, pos); else - ctx->text.extendDir = XawsdLeft; - } - else /* check for change in extend direction */ - if ((ctx->text.extendDir == XawsdRight && pos <= ctx->text.origSel.left) || - (ctx->text.extendDir == XawsdLeft && pos >= ctx->text.origSel.right)) { - ctx->text.extendDir = (ctx->text.extendDir == XawsdRight) ? - XawsdLeft : XawsdRight; - ModifySelection(ctx, ctx->text.origSel.left, ctx->text.origSel.right); - } - - dir = ctx->text.extendDir; - switch (ctx->text.s.type) { - case XawselectWord: - case XawselectParagraph: - { - XawTextPosition left_pos, right_pos; - XawTextScanType stype; - - if (ctx->text.s.type == XawselectWord) - stype = XawstWhiteSpace; - else - stype = XawstParagraph; - - /* - * Somewhat complicated, but basically I treat the space between - * two objects as another object. The object that I am currently - * in then becomes the end of the selection. - * - * Chris Peterson - 4/19/90. - */ - - right_pos = SrcScan(ctx->text.source, pos, stype, XawsdRight, 1, FALSE); - right_pos =SrcScan(ctx->text.source, right_pos,stype,XawsdLeft,1, FALSE); - - if (pos != right_pos) - left_pos = SrcScan(ctx->text.source, pos, stype, XawsdLeft, 1, FALSE); - else - left_pos = pos; - - left_pos =SrcScan(ctx->text.source, left_pos, stype, XawsdRight,1,FALSE); - - if (dir == XawsdLeft) - pos = Min(left_pos, right_pos); - else /* dir == XawsdRight */ - pos = Max(left_pos, right_pos); - } - break; - case XawselectLine: - pos = SrcScan(ctx->text.source, pos, XawstEOL, dir, 1, dir == XawsdRight); - break; - case XawselectAll: - pos = ctx->text.insertPos; - case XawselectPosition: /* fall through. */ - default: - break; - } - - if (dir == XawsdRight) - ModifySelection(ctx, ctx->text.s.left, pos); - else - ModifySelection(ctx, pos, ctx->text.s.right); + ModifySelection(ctx, pos, ctx->text.s.right); - ctx->text.insertPos = pos; + ctx->text.insertPos = pos; } /* - * Clear the window to background color. + * Function: + * _XawTextClearAndCenterDisplay + * + * Parameters: + * ctx - text widget + * + * Description: + * Redraws the display with the cursor in insert point + * centered vertically. */ - -static void -ClearWindow (w) -Widget w; +void +_XawTextClearAndCenterDisplay(TextWidget ctx) { - TextWidget ctx = (TextWidget) w; + int left_margin = ctx->text.left_margin; + Bool visible = IsPositionVisible(ctx, ctx->text.insertPos); - if (XtIsRealized(w)) - SinkClearToBG(ctx->text.sink, - (Position) 0, (Position) 0, - w->core.width, w->core.height); + _XawTextShowPosition(ctx); + + if (XtIsRealized((Widget)ctx) && visible && + left_margin == ctx->text.left_margin) { + int insert_line = LineForPosition(ctx, ctx->text.insertPos); + int scroll_by = insert_line - (ctx->text.lt.lines >> 1); + Boolean clear_to_eol = ctx->text.clear_to_eol; + + XawTextScroll(ctx, scroll_by, 0); + SinkClearToBG(ctx->text.sink, 0, 0, XtWidth(ctx), XtHeight(ctx)); + ClearWindow(ctx); + clear_to_eol = ctx->text.clear_to_eol; + ctx->text.clear_to_eol = False; + FlushUpdate(ctx); + ctx->text.clear_to_eol = clear_to_eol; + } } -/* Function Name: _XawTextClearAndCenterDisplay - * Description: Redraws the display with the cursor in insert point - * centered vertically. - * Arguments: ctx - the text widget. - * Returns: none. +/* + * Internal redisplay entire window + * Legal to call only if widget is realized */ - -void -_XawTextClearAndCenterDisplay(ctx) -TextWidget ctx; +static void +DisplayTextWindow(Widget w) { - int insert_line = LineForPosition(ctx, ctx->text.insertPos); - int scroll_by = insert_line - ctx->text.lt.lines/2; + TextWidget ctx = (TextWidget)w; - _XawTextVScroll(ctx, scroll_by); - DisplayTextWindow( (Widget) ctx); + _XawTextBuildLineTable(ctx, ctx->text.lt.top, False); + ClearWindow(ctx); } - -/* - * Internal redisplay entire window. - * Legal to call only if widget is realized. - */ static void -DisplayTextWindow (w) -Widget w; +TextSinkResize(Widget w) { - TextWidget ctx = (TextWidget) w; - ClearWindow(w); - _XawTextBuildLineTable(ctx, ctx->text.lt.top, FALSE); - _XawTextNeedsUpdating(ctx, zeroPosition, ctx->text.lastPos); - _XawTextSetScrollBars(ctx); + if (w && XtClass(w)->core_class.resize) + XtClass(w)->core_class.resize(w); } -/* - * This routine checks to see if the window should be resized (grown or - * shrunk) when text to be painted overflows to the right or - * the bottom of the window. It is used by the keyboard input routine. - */ - +/* ARGSUSED */ void -_XawTextCheckResize(ctx) -TextWidget ctx; -{ - Widget w = (Widget) ctx; - int line = 0, old_height; - XtWidgetGeometry rbox, return_geom; - - if ( (ctx->text.resize == XawtextResizeWidth) || - (ctx->text.resize == XawtextResizeBoth) ) { - XawTextLineTableEntry *lt; - rbox.width = 0; - for (lt = ctx->text.lt.info; - IsValidLine(ctx, line) && (line < ctx->text.lt.lines); - line++, lt++) { - if ((int)(lt->textWidth + ctx->text.margin.left) > (int)rbox.width) - rbox.width = lt->textWidth + ctx->text.margin.left; - } - - rbox.width += ctx->text.margin.right; - if (rbox.width > ctx->core.width) { /* Only get wider. */ - rbox.request_mode = CWWidth; - if (XtMakeGeometryRequest(w, &rbox, &return_geom) == XtGeometryAlmost) - (void) XtMakeGeometryRequest(w, &return_geom, (XtWidgetGeometry*) NULL); - } - } - - if ( !((ctx->text.resize == XawtextResizeHeight) || - (ctx->text.resize == XawtextResizeBoth)) ) - return; - - if (IsPositionVisible(ctx, ctx->text.lastPos)) - line = LineForPosition(ctx, ctx->text.lastPos); - else - line = ctx->text.lt.lines; - - if ( (line + 1) == ctx->text.lt.lines ) return; - - old_height = ctx->core.height; - rbox.request_mode = CWHeight; - rbox.height = XawTextSinkMaxHeight(ctx->text.sink, line + 1) + VMargins(ctx); - - if ((int)rbox.height < old_height) return; /* It will only get taller. */ - - if (XtMakeGeometryRequest(w, &rbox, &return_geom) == XtGeometryAlmost) - if (XtMakeGeometryRequest(w, &return_geom, (XtWidgetGeometry*)NULL) != XtGeometryYes) - return; - - _XawTextBuildLineTable(ctx, ctx->text.lt.top, TRUE); +_XawTextCheckResize(TextWidget ctx) +{ + return; } /* * Converts (params, num_params) to a list of atoms & caches the * list in the TextWidget instance. */ - -Atom* -_XawTextSelectionList(ctx, list, nelems) -TextWidget ctx; -String *list; -Cardinal nelems; +Atom * +_XawTextSelectionList(TextWidget ctx, String *list, Cardinal nelems) { - Atom * sel = ctx->text.s.selections; - Display *dpy = XtDisplay((Widget) ctx); - int n; + Atom *sel = ctx->text.s.selections; + Display *dpy = XtDisplay((Widget)ctx); + int n; + + if (nelems > (Cardinal)ctx->text.s.array_size) { + sel = (Atom *)XtRealloc((char *)sel, sizeof(Atom) * nelems); + ctx->text.s.array_size = nelems; + ctx->text.s.selections = sel; + } + for (n = nelems; --n >= 0; sel++, list++) + *sel = XInternAtom(dpy, *list, False); + ctx->text.s.atom_count = nelems; - if (nelems > ctx->text.s.array_size) { - sel = (Atom *) XtRealloc((char *) sel, sizeof(Atom) * nelems); - ctx->text.s.array_size = nelems; - ctx->text.s.selections = sel; - } - for (n=nelems; --n >= 0; sel++, list++) - *sel = XInternAtom(dpy, *list, False); - ctx->text.s.atom_count = nelems; - return ctx->text.s.selections; -} - -/* Function Name: SetSelection - * Description: Sets the current selection. - * Arguments: ctx - the text widget. - * defaultSel - the default selection. - * l, r - the left and right ends of the selection. - * list, nelems - the selection list (as strings). - * Returns: none. + return (ctx->text.s.selections); +} + +/* + * Function: + * SetSelection * - * NOTE: if (ctx->text.s.left >= ctx->text.s.right) then the selection - * is unset. + * Parameters: + * ctx - text widget + * defaultSel - default selection + * l - left and right ends of the selection + * r - "" + * list - the selection list (as strings). + * nelems - "" + * + * Description: + * Sets the current selection. + * + * Note: + * if (ctx->text.s.left >= ctx->text.s.right) then the selection is unset */ - void -_XawTextSetSelection(ctx, l, r, list, nelems) -TextWidget ctx; -XawTextPosition l, r; -String *list; -Cardinal nelems; +_XawTextSetSelection(TextWidget ctx, XawTextPosition l, XawTextPosition r, + String *list, Cardinal nelems) { - if (nelems == 1 && !strcmp (list[0], "none")) - return; - if (nelems == 0) { - String defaultSel = "PRIMARY"; - list = &defaultSel; - nelems = 1; - } - _SetSelection(ctx, l, r, _XawTextSelectionList(ctx, list, nelems), nelems); + if (nelems == 1 && !strcmp (list[0], "none")) + return; + if (nelems == 0) { + String defaultSel = "PRIMARY"; + list = &defaultSel; + nelems = 1; + } + _SetSelection(ctx, l, r, _XawTextSelectionList(ctx, list, nelems), nelems); } - -/* Function Name: ModifySelection - * Description: Modifies the current selection. - * Arguments: ctx - the text widget. - * left, right - the left and right ends of the selection. - * Returns: none. +/* + * Function: + * ModifySelection * - * NOTE: if (ctx->text.s.left >= ctx->text.s.right) then the selection - * is unset. + * Parameters: + * ctx - text widget + * left - left and right ends of the selection + * right - "" + * + * Description: + * Modifies the current selection. + * + * Note: + * if (ctx->text.s.left >= ctx->text.s.right) then the selection is unset */ - static void -ModifySelection(ctx, left, right) -TextWidget ctx; -XawTextPosition left, right; +ModifySelection(TextWidget ctx, XawTextPosition left, XawTextPosition right) { - if (left == right) - ctx->text.insertPos = left; - _SetSelection( ctx, left, right, (Atom*) NULL, ZERO ); + if (left == right) + ctx->text.insertPos = left; + _SetSelection(ctx, left, right, NULL, 0); } /* @@ -2530,76 +3183,63 @@ XawTextPosition left, right; * to be able to specify all the more popular forms of draw-through and * multi-click selection user interfaces from the outside. */ - -void -_XawTextAlterSelection (ctx, mode, action, params, num_params) -TextWidget ctx; -XawTextSelectionMode mode; /* {XawsmTextSelect, XawsmTextExtend} */ -XawTextSelectionAction action; /* {XawactionStart, - XawactionAdjust, XawactionEnd} */ -String *params; -Cardinal *num_params; +void +_XawTextAlterSelection(TextWidget ctx, XawTextSelectionMode mode, + XawTextSelectionAction action, String *params, + Cardinal *num_params) { - XawTextPosition position; - Boolean flag; - -/* - * This flag is used by TextPop.c:DoReplace() to determine if the selection - * is okay to use, or if it has been modified. - */ - - if (ctx->text.search != NULL) - ctx->text.search->selection_changed = TRUE; + XawTextPosition position; + Boolean flag; - position = PositionForXY (ctx, (int) ctx->text.ev_x, (int) ctx->text.ev_y); + /* + * This flag is used by TextPop.c:DoReplace() to determine if the selection + * is okay to use, or if it has been modified. + */ + if (ctx->text.search != NULL) + ctx->text.search->selection_changed = True; - flag = (action != XawactionStart); - if (mode == XawsmTextSelect) - DoSelection (ctx, position, ctx->text.time, flag); - else /* mode == XawsmTextExtend */ - ExtendSelection (ctx, position, flag); + position = PositionForXY(ctx, (int) ctx->text.ev_x, (int) ctx->text.ev_y); - if (action == XawactionEnd) - _XawTextSetSelection(ctx, ctx->text.s.left, ctx->text.s.right, - params, *num_params); -} + flag = (action != XawactionStart); + if (mode == XawsmTextSelect) + DoSelection(ctx, position, ctx->text.time, flag); + else /* mode == XawsmTextExtend */ + ExtendSelection (ctx, position, flag); -/* Function Name: RectanglesOverlap - * Description: Returns TRUE if two rectangles overlap. - * Arguments: rect1, rect2 - the two rectangles to check. - * Returns: TRUE iff these rectangles overlap. - */ - -static Boolean -RectanglesOverlap(rect1, rect2) -XRectangle *rect1, *rect2; -{ - return ( (rect1->x < rect2->x + (short) rect2->width) && - (rect2->x < rect1->x + (short) rect1->width) && - (rect1->y < rect2->y + (short) rect2->height) && - (rect2->y < rect1->y + (short) rect1->height) ); + if (action == XawactionEnd) + _XawTextSetSelection(ctx, ctx->text.s.left, ctx->text.s.right, + params, *num_params); } -/* Function Name: UpdateTextInRectangle. - * Description: Updates the text in a rectangle. - * Arguments: ctx - the text widget. - * rect - the rectangle to update. - * Returns: none. +/* + * Function: + * UpdateTextInRectangle + * + * Parameters: + * ctx - the text widget + * rect - rectangle + * + * Description: + * Updates the text in the given rectangle */ - static void -UpdateTextInRectangle(ctx, rect) -TextWidget ctx; -XRectangle * rect; +UpdateTextInRectangle(TextWidget ctx, XRectangle *rect) { - XawTextLineTableEntry *info = ctx->text.lt.info; - int line, x = rect->x, y = rect->y; - int right = rect->width + x, bottom = rect->height + y; + XawTextLineTable *lt; + int line, y1, y2, x2; - for (line = 0;( (line < ctx->text.lt.lines) && - IsValidLine(ctx, line) && (info->y < bottom)); line++, info++) - if ( (info + 1)->y >= y ) - UpdateTextInLine(ctx, line, x, right); + y1 = rect->y; + y2 = y1 + rect->height; + x2 = rect->x + rect->width; + + for (line = 0, lt = &ctx->text.lt; line < lt->lines; line++) + if (lt->info[line + 1].y > y1) + break; + for (; line <= lt->lines; line++) { + if (lt->info[line].y > y2) + break; + UpdateTextInLine(ctx, line, rect->x, x2); + } } /* @@ -2607,18 +3247,14 @@ XRectangle * rect; * is to the best job at minimal re-paint of the text, displayed in the * window, that it can. */ - /* ARGSUSED */ static void -ProcessExposeRegion(w, event, region) -Widget w; -XEvent *event; -Region region; /* Unused. */ -{ - TextWidget ctx = (TextWidget) w; - XRectangle expose, cursor; - Boolean need_to_draw; - +XawTextExpose(Widget w, XEvent *event, Region region) +{ + TextWidget ctx = (TextWidget)w; + Boolean clear_to_eol; + XRectangle expose; + if (event->type == Expose) { expose.x = event->xexpose.x; expose.y = event->xexpose.y; @@ -2630,44 +3266,42 @@ Region region; /* Unused. */ expose.y = event->xgraphicsexpose.y; expose.width = event->xgraphicsexpose.width; expose.height = event->xgraphicsexpose.height; - } - else { /* No Expose */ - PopCopyQueue(ctx); - return; /* no more processing necessary. */ } + else + return; - need_to_draw = TranslateExposeRegion(ctx, &expose); - if ((event->type == GraphicsExpose) && (event->xgraphicsexpose.count == 0)) - PopCopyQueue(ctx); + _XawTextPrepareToUpdate(ctx); - if (!need_to_draw) - return; /* don't draw if we don't need to. */ + if (Superclass->core_class.expose) + (*Superclass->core_class.expose)(w, event, region); + + clear_to_eol = ctx->text.clear_to_eol; + ctx->text.clear_to_eol = False; - _XawTextPrepareToUpdate(ctx); UpdateTextInRectangle(ctx, &expose); - XawTextSinkGetCursorBounds(ctx->text.sink, &cursor); - if (RectanglesOverlap(&cursor, &expose)) { - SinkClearToBG(ctx->text.sink, (Position) cursor.x, (Position) cursor.y, - (Dimension) cursor.width, (Dimension) cursor.height); - UpdateTextInRectangle(ctx, &cursor); - } + XawTextSinkGetCursorBounds(ctx->text.sink, &expose); + UpdateTextInRectangle(ctx, &expose); + SinkClearToBG(ctx->text.sink, expose.x, expose.y, + expose.width, expose.height); _XawTextExecuteUpdate(ctx); + ctx->text.clear_to_eol = clear_to_eol; } /* * This routine does all setup required to syncronize batched screen updates */ - void -_XawTextPrepareToUpdate(ctx) -TextWidget ctx; -{ - if (ctx->text.old_insert < 0) { - InsertCursor((Widget)ctx, XawisOff); - ctx->text.numranges = 0; - ctx->text.showposition = FALSE; - ctx->text.old_insert = ctx->text.insertPos; - } +_XawTextPrepareToUpdate(TextWidget ctx) +{ + if (ctx->text.old_insert < 0) { + InsertCursor((Widget)ctx, XawisOff); + ctx->text.showposition = False; + ctx->text.old_insert = ctx->text.insertPos; + ctx->text.clear_to_eol = False; +#ifndef OLDXAW + ctx->text.source_changed = SRC_CHANGE_NONE; +#endif + } } /* @@ -2675,476 +3309,518 @@ TextWidget ctx; * processes all the outstanding update requests and merges update * ranges where possible. */ - -static -void FlushUpdate(ctx) -TextWidget ctx; +static void +FlushUpdate(TextWidget ctx) { - int i, w; - XawTextPosition updateFrom, updateTo; - if (!XtIsRealized((Widget)ctx)) { - ctx->text.numranges = 0; - return; - } - while (ctx->text.numranges > 0) { - updateFrom = ctx->text.updateFrom[0]; - w = 0; - for (i = 1 ; i < ctx->text.numranges ; i++) { - if (ctx->text.updateFrom[i] < updateFrom) { - updateFrom = ctx->text.updateFrom[i]; - w = i; - } - } - updateTo = ctx->text.updateTo[w]; - ctx->text.numranges--; - ctx->text.updateFrom[w] = ctx->text.updateFrom[ctx->text.numranges]; - ctx->text.updateTo[w] = ctx->text.updateTo[ctx->text.numranges]; - for (i = ctx->text.numranges - 1 ; i >= 0 ; i--) { - while (ctx->text.updateFrom[i] <= updateTo && i < ctx->text.numranges) { - updateTo = ctx->text.updateTo[i]; - ctx->text.numranges--; - ctx->text.updateFrom[i] = ctx->text.updateFrom[ctx->text.numranges]; - ctx->text.updateTo[i] = ctx->text.updateTo[ctx->text.numranges]; - } - } - DisplayText((Widget)ctx, updateFrom, updateTo); - } + XmuSegment *seg; + void (*display_text)(Widget, XawTextPosition, XawTextPosition); + + if (XtIsRealized((Widget)ctx)) { + ctx->text.s.right = XawMin(ctx->text.s.right, ctx->text.lastPos); + ctx->text.s.left = XawMin(ctx->text.s.left, ctx->text.s.right); + +#ifndef OLDXAW + if (XawTextSinkBeginPaint(ctx->text.sink) == False) +#endif + display_text = OldDisplayText; +#ifndef OLDXAW + else + display_text = DisplayText; +#endif + for (seg = ctx->text.update->segment; seg; seg = seg->next) + (*display_text)((Widget)ctx, + (XawTextPosition)seg->x1, + (XawTextPosition)seg->x2); +#ifndef OLDXAW + if (display_text != OldDisplayText) { + XawTextSinkDoPaint(ctx->text.sink); + XawTextSinkEndPaint(ctx->text.sink); + } +#endif + } + (void)XmuScanlineXor(ctx->text.update, ctx->text.update); } -/* - * This is a private utility routine used by _XawTextExecuteUpdate. This - * routine worries about edits causing new data or the insertion point becoming - * invisible (off the screen, or under the horiz. scrollbar). Currently - * it always makes it visible by scrolling. It probably needs - * generalization to allow more options. - */ +static int +CountLines(TextWidget ctx, XawTextPosition left, XawTextPosition right) +{ + if (ctx->text.wrap == XawtextWrapNever || left >= right) + return (1); + else { + XawTextPosition tmp; + int dim, lines = 0, wwidth = GetMaxTextWidth(ctx); + + while (left < right) { + tmp = left; + XawTextSinkFindPosition(ctx->text.sink, left, + ctx->text.left_margin, + wwidth, ctx->text.wrap == XawtextWrapWord, + &left, &dim, &dim); + ++lines; + if (tmp == left) + ++left; + } -void -_XawTextShowPosition(ctx) -TextWidget ctx; + return (lines); + } + /*NOTREACHED*/ +} + +static int +GetMaxTextWidth(TextWidget ctx) { - int x, y, lines, number; - Boolean no_scroll; - XawTextPosition max_pos, top, first; + XRectangle cursor; + int width; - if ( (!XtIsRealized((Widget)ctx)) || (ctx->text.lt.lines <= 0) ) - return; + XawTextSinkGetCursorBounds(ctx->text.sink, &cursor); + width = (int)XtWidth(ctx) - RHMargins(ctx) - cursor.width; + + return (XawMax(0, width)); +} /* - * Find out the bottom the visable window, and make sure that the - * cursor does not go past the end of this space. + * Function: + * _XawTextShowPosition * - * This makes sure that the cursor does not go past the end of the - * visable window. + * Parameters: + * ctx - the text widget to show the position + * + * Description: + * Makes sure the text cursor visible, scrolling the text window + * if required. */ +void +_XawTextShowPosition(TextWidget ctx) +{ + /* + * Variable scroll is used to avoid scanning large files to calculate + * line offsets + */ + int hpixels, vlines; + XawTextPosition first, last, top, tmp; + Bool visible, scroll; - x = ctx->core.width; - y = ctx->core.height - ctx->text.margin.bottom; - if (ctx->text.hbar != NULL) - y -= ctx->text.hbar->core.height + 2 * ctx->text.hbar->core.border_width; - - max_pos = PositionForXY (ctx, x, y); - lines = LineForPosition(ctx, max_pos) + 1; /* number of visable lines. */ - - if ( (ctx->text.insertPos >= ctx->text.lt.top) && - (ctx->text.insertPos < max_pos)) - return; + if (!XtIsRealized((Widget)ctx)) + return; - first = ctx->text.lt.top; - no_scroll = FALSE; - - if (ctx->text.insertPos < first) { /* We need to scroll down. */ - top = SrcScan(ctx->text.source, ctx->text.insertPos, - XawstEOL, XawsdLeft, 1, FALSE); - - /* count the number of lines we have to scroll */ - - number = 0; - while (first > top) { - first = SrcScan(ctx->text.source, first, - XawstEOL, XawsdLeft, 1, TRUE); - - if ( - number > lines ) - break; - - number--; - } - - if (first <= top) { /* If we found the proper number - of lines. */ - - /* Back up to just before the last CR. */ - - first = SrcScan(ctx->text.source, first, - XawstPositions, XawsdRight, 1, TRUE); - - /* Check to make sure the cursor is visable. */ - - if (first <= top) - number++; - - lines = number; - } - else - no_scroll = TRUE; - } - else { /* We need to Scroll up */ - top = SrcScan(ctx->text.source, ctx->text.insertPos, - XawstEOL, XawsdLeft, lines, FALSE); - - if (top < max_pos) - lines = LineForPosition(ctx, top); - else - no_scroll = TRUE; - } + /* + * Checks if a horizontal scroll is required + */ + if (ctx->text.wrap == XawtextWrapNever) { + int x, vwidth, distance, dim; + XRectangle rect; + + vwidth = (int)XtWidth(ctx) - RHMargins(ctx); + last = SrcScan(ctx->text.source, ctx->text.insertPos, + XawstEOL, XawsdLeft, 1, False); + XawTextSinkFindDistance(ctx->text.sink, last, + ctx->text.left_margin, + ctx->text.insertPos, + &distance, &first, &dim); + XawTextSinkGetCursorBounds(ctx->text.sink, &rect); + x = ctx->text.left_margin - ctx->text.r_margin.left; + + if (x + distance + rect.width > vwidth) + hpixels = x + distance + rect.width - vwidth + (vwidth >> 2); + else if (x + distance < 0) + hpixels = x + distance - (vwidth >> 2); + else + hpixels = 0; + } + else + hpixels = 0; - if (no_scroll) { - _XawTextBuildLineTable(ctx, top, FALSE); - DisplayTextWindow((Widget)ctx); - } - else - _XawTextVScroll(ctx, lines); + visible = IsPositionVisible(ctx, ctx->text.insertPos); + + /* + * If the cursor is already visible + */ + if (!hpixels && visible) + return; + + scroll = ctx->core.background_pixmap == XtUnspecifiedPixmap && !hpixels; + vlines = 0; + first = ctx->text.lt.top; + + /* + * Needs to scroll the text window + */ + if (visible) + top = ctx->text.lt.top; + else { + top = SrcScan(ctx->text.source, ctx->text.insertPos, + XawstEOL, XawsdLeft, 1, False); + + /* + * Finds the nearest left position from ctx->text.insertPos + */ + if (ctx->text.wrap != XawtextWrapNever) { + int dim, vwidth = GetMaxTextWidth(ctx); + + last = top; + /*CONSTCOND*/ + while (1) { + tmp = last; + XawTextSinkFindPosition(ctx->text.sink, last, + ctx->text.left_margin, vwidth, + ctx->text.wrap == XawtextWrapWord, + &last, &dim, &dim); + if (last == tmp) + ++last; + if (last <= ctx->text.insertPos) + top = last; + else + break; + } + } + } + + if (scroll) { + if (ctx->text.insertPos < first) { /* Scroll Down */ + while (first > top) { + last = first; + first = SrcScan(ctx->text.source, first, + XawstEOL, XawsdLeft, 2, False); + vlines -= CountLines(ctx, first, last); + if (-vlines >= ctx->text.lt.lines) { + scroll = False; + break; + } + } + } + else if (!visible) { /* Scroll Up */ + while (first < top) { + last = first; + first = SrcScan(ctx->text.source, first, + XawstEOL, XawsdRight, 1, True); + vlines += CountLines(ctx, last, first); + if (vlines > ctx->text.lt.lines) { + scroll = False; + break; + } + } + } + else + scroll = False; + } + + /* + * If a portion of the text that will be scrolled is visible + */ + if (scroll) + XawTextScroll(ctx, vlines ? vlines - (ctx->text.lt.lines >> 1) : 0, 0); + /* + * Else redraw the entire text window + */ + else { + ctx->text.left_margin -= hpixels; + if (ctx->text.left_margin > ctx->text.r_margin.left) + ctx->text.left_margin = ctx->text.margin.left = + ctx->text.r_margin.left; + + if (!visible) { + vlines = ctx->text.lt.lines >> 1; + if (vlines) + top = SrcScan(ctx->text.source, ctx->text.insertPos, + XawstEOL, XawsdLeft, vlines + 1, False); + + if (ctx->text.wrap != XawtextWrapNever) { + int dim; + int n_lines = CountLines(ctx, top, ctx->text.insertPos); + int vwidth = GetMaxTextWidth(ctx); + + while (n_lines-- > vlines) { + tmp = top; + XawTextSinkFindPosition(ctx->text.sink, top, + ctx->text.left_margin, + vwidth, + ctx->text.wrap == XawtextWrapWord, + &top, &dim, &dim); + if (tmp == top) + ++top; + } + } + _XawTextBuildLineTable(ctx, top, True); + } + else + ClearWindow(ctx); + } + ctx->text.clear_to_eol = True; +} + +#ifndef OLDXAW +static int +ResolveLineNumber(TextWidget ctx) +{ + int line_number = ctx->text.lt.base_line; + XawTextPosition position = ctx->text.lt.top; + + if (ctx->text.lt.base_line < 1) + return (ctx->text.line_number); + + if (ctx->text.wrap == XawtextWrapNever + && IsPositionVisible(ctx, ctx->text.insertPos)) + line_number += LineForPosition(ctx, ctx->text.insertPos); + else if (position < ctx->text.insertPos) { + while (position < ctx->text.insertPos) { + position = SrcScan(ctx->text.source, position, + XawstEOL, XawsdRight, 1, True); + if (position <= ctx->text.insertPos) { + ++line_number; + if (position == ctx->text.lastPos) { + line_number -= !_XawTextSourceNewLineAtEOF(ctx->text.source); + break; + } + } + } + } + else if (position > ctx->text.insertPos) { + while (position > ctx->text.insertPos) { + position = SrcScan(ctx->text.source, position, + XawstEOL, XawsdLeft, 1, False); + if (--position >= ctx->text.insertPos) + --line_number; + } + } - _XawTextSetScrollBars(ctx); + return (line_number); } +#endif /* * This routine causes all batched screen updates to be performed */ - void -_XawTextExecuteUpdate(ctx) -TextWidget ctx; +_XawTextExecuteUpdate(TextWidget ctx) { - if ( ctx->text.update_disabled || (ctx->text.old_insert < 0) ) - return; + if (ctx->text.update_disabled || ctx->text.old_insert < 0) + return; - if((ctx->text.old_insert != ctx->text.insertPos) || (ctx->text.showposition)) - _XawTextShowPosition(ctx); - FlushUpdate(ctx); - InsertCursor((Widget)ctx, XawisOn); - ctx->text.old_insert = -1; -} + if(ctx->text.old_insert != ctx->text.insertPos || ctx->text.showposition) + _XawTextShowPosition(ctx); + FlushUpdate(ctx); + InsertCursor((Widget)ctx, XawisOn); + ctx->text.old_insert = -1; +#ifndef OLDXAW + _XawTextSetLineAndColumnNumber(ctx, False); +#endif +} -static void -TextDestroy(w) -Widget w; +static void +XawTextDestroy(Widget w) { - TextWidget ctx = (TextWidget)w; + TextWidget ctx = (TextWidget)w; - DestroyHScrollBar(ctx); - DestroyVScrollBar(ctx); + DestroyHScrollBar(ctx); + DestroyVScrollBar(ctx); - XtFree((char *)ctx->text.s.selections); - XtFree((char *)ctx->text.lt.info); - XtFree((char *)ctx->text.search); - XtFree((char *)ctx->text.updateFrom); - XtFree((char *)ctx->text.updateTo); + XtFree((char *)ctx->text.s.selections); + XtFree((char *)ctx->text.lt.info); + XtFree((char *)ctx->text.search); + XmuDestroyScanline(ctx->text.update); } /* * by the time we are managed (and get this far) we had better * have both a source and a sink */ - static void -Resize(w) -Widget w; +XawTextResize(Widget w) { - TextWidget ctx = (TextWidget) w; + TextWidget ctx = (TextWidget)w; - PositionVScrollBar(ctx); - PositionHScrollBar(ctx); + PositionVScrollBar(ctx); + PositionHScrollBar(ctx); + TextSinkResize(ctx->text.sink); - _XawTextBuildLineTable(ctx, ctx->text.lt.top, TRUE); - _XawTextSetScrollBars(ctx); + ctx->text.showposition = True; + _XawTextBuildLineTable(ctx, ctx->text.lt.top, True); } /* * This routine allow the application program to Set attributes. */ - /*ARGSUSED*/ -static Boolean -SetValues(current, request, new, args, num_args) -Widget current, request, new; -ArgList args; -Cardinal *num_args; -{ - TextWidget oldtw = (TextWidget) current; - TextWidget newtw = (TextWidget) new; - Boolean redisplay = FALSE; - Boolean display_caret = newtw->text.display_caret; - - - newtw->text.display_caret = oldtw->text.display_caret; - _XawTextPrepareToUpdate(newtw); - newtw->text.display_caret = display_caret; - - if (oldtw->text.r_margin.left != newtw->text.r_margin.left) { - newtw->text.margin.left = newtw->text.r_margin.left; - if (newtw->text.vbar != NULL) - newtw->text.margin.left += newtw->text.vbar->core.width + - newtw->text.vbar->core.border_width; - redisplay = TRUE; - } - - if (oldtw->text.scroll_vert != newtw->text.scroll_vert) { - if (newtw->text.scroll_vert == XawtextScrollNever) - DestroyVScrollBar(newtw); - else if (newtw->text.scroll_vert == XawtextScrollAlways) - CreateVScrollBar(newtw); - redisplay = TRUE; - } +static Boolean +XawTextSetValues(Widget current, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) +{ + TextWidget oldtw = (TextWidget)current; + TextWidget newtw = (TextWidget)cnew; + Boolean redisplay = False; + Boolean display_caret = newtw->text.display_caret; +#ifndef OLDXAW + Boolean show_lc = False; +#endif - if (oldtw->text.r_margin.bottom != newtw->text.r_margin.bottom) { - newtw->text.margin.bottom = newtw->text.r_margin.bottom; - if (newtw->text.hbar != NULL) - newtw->text.margin.bottom += newtw->text.hbar->core.height + - newtw->text.hbar->core.border_width; - redisplay = TRUE; - } - - if (oldtw->text.scroll_horiz != newtw->text.scroll_horiz) { - if (newtw->text.scroll_horiz == XawtextScrollNever) - DestroyHScrollBar(newtw); - else if (newtw->text.scroll_horiz == XawtextScrollAlways) - CreateHScrollBar(newtw); - redisplay = TRUE; - } + newtw->text.display_caret = oldtw->text.display_caret; + _XawTextPrepareToUpdate(newtw); + newtw->text.display_caret = display_caret; - if ( oldtw->text.source != newtw->text.source ) - XawTextSetSource( (Widget) newtw, newtw->text.source, newtw->text.lt.top); + if (oldtw->text.r_margin.left != newtw->text.r_margin.left) { + newtw->text.left_margin = newtw->text.margin.left = + newtw->text.r_margin.left; + if (newtw->text.vbar != NULL) { + newtw->text.left_margin += XtWidth(newtw->text.vbar) + + XtBorderWidth(newtw->text.vbar); + } + redisplay = True; + } - newtw->text.redisplay_needed = False; - XtSetValues( (Widget)newtw->text.source, args, *num_args ); - XtSetValues( (Widget)newtw->text.sink, args, *num_args ); + if (oldtw->text.scroll_vert != newtw->text.scroll_vert) { + if (newtw->text.scroll_vert == XawtextScrollAlways) + CreateVScrollBar(newtw); + else + DestroyVScrollBar(newtw); - if ( oldtw->text.wrap != newtw->text.wrap || - oldtw->text.lt.top != newtw->text.lt.top || - oldtw->text.r_margin.right != newtw->text.r_margin.right || - oldtw->text.r_margin.top != newtw->text.r_margin.top || - oldtw->text.sink != newtw->text.sink || - newtw->text.redisplay_needed ) - { - _XawTextBuildLineTable(newtw, newtw->text.lt.top, TRUE); - redisplay = TRUE; - } + redisplay = True; + } - if (oldtw->text.insertPos != newtw->text.insertPos) { - newtw->text.showposition = TRUE; - redisplay = TRUE; - } + if (oldtw->text.r_margin.bottom != newtw->text.r_margin.bottom) { + newtw->text.margin.bottom = newtw->text.r_margin.bottom; + if (newtw->text.hbar != NULL) + newtw->text.margin.bottom += newtw->text.hbar->core.height + + newtw->text.hbar->core.border_width; + redisplay = True; + } - _XawTextExecuteUpdate(newtw); - if (redisplay) - _XawTextSetScrollBars(newtw); + if (oldtw->text.scroll_horiz != newtw->text.scroll_horiz) { + if (newtw->text.scroll_horiz == XawtextScrollAlways) + CreateHScrollBar(newtw); + else + DestroyHScrollBar(newtw); + + redisplay = True; + } + + if (oldtw->text.source != newtw->text.source) { +#ifndef OLDXAW + show_lc = True; + _XawSourceRemoveText(oldtw->text.source, cnew, + oldtw->text.source && + XtParent(oldtw->text.source) == cnew); + _XawSourceAddText(newtw->text.source, cnew); +#endif + _XawTextSetSource((Widget)newtw, newtw->text.source, newtw->text.lt.top, + newtw->text.insertPos); + } + + newtw->text.redisplay_needed = False; + XtSetValues((Widget)newtw->text.source, args, *num_args); + XtSetValues((Widget)newtw->text.sink, args, *num_args); + + if (oldtw->text.wrap != newtw->text.wrap + || oldtw->text.lt.top != newtw->text.lt.top + || oldtw->text.insertPos != newtw->text.insertPos + || oldtw->text.r_margin.right != newtw->text.r_margin.right + || oldtw->text.r_margin.top != newtw->text.r_margin.top + || oldtw->text.sink != newtw->text.sink + || newtw->text.redisplay_needed) { + if (oldtw->text.wrap != newtw->text.wrap) { + newtw->text.left_margin = newtw->text.margin.left = + newtw->text.r_margin.left; + if (oldtw->text.lt.top == newtw->text.lt.top) + newtw->text.lt.top = SrcScan(newtw->text.source, 0, XawstEOL, + XawsdLeft, 1, False); + } + newtw->text.showposition = True; +#ifndef OLDXAW + show_lc = True; + newtw->text.source_changed = SRC_CHANGE_OVERLAP; +#endif + _XawTextBuildLineTable(newtw, newtw->text.lt.top, True); + redisplay = True; + } + +#ifndef OLDXAW + if (newtw->text.left_column < 0) + newtw->text.left_column = 0; + if (newtw->text.right_column < 0) + newtw->text.right_column = 0; +#endif - return redisplay; + _XawTextExecuteUpdate(newtw); + +#ifndef OLDXAW + if (show_lc) + _XawTextSetLineAndColumnNumber(newtw, True); +#endif + + if (redisplay) + _XawTextSetScrollBars(newtw); + + return (redisplay); } /* invoked by the Simple widget's SetValues */ -static Boolean ChangeSensitive(w) - Widget w; /* the new widget */ +static Bool +XawTextChangeSensitive(Widget w) { Arg args[1]; - TextWidget tw = (TextWidget) w; + TextWidget tw = (TextWidget)w; (*(&simpleClassRec)->simple_class.change_sensitive)(w); - XtSetArg(args[0], XtNancestorSensitive, - (tw->core.ancestor_sensitive && tw->core.sensitive)); + XtSetArg(args[0], XtNancestorSensitive, + (tw->core.ancestor_sensitive && tw->core.sensitive)); if (tw->text.vbar) XtSetValues(tw->text.vbar, args, ONE); if (tw->text.hbar) XtSetValues(tw->text.hbar, args, ONE); - return False; + return (False); } -/* Function Name: GetValuesHook - * Description: This is a get values hook routine that gets the - * values in the text source and sink. - * Arguments: w - the Text Widget. - * args - the argument list. - * num_args - the number of args. - * Returns: none. - */ - -static void -GetValuesHook(w, args, num_args) -Widget w; -ArgList args; -Cardinal * num_args; -{ - XtGetValues( ((TextWidget) w)->text.source, args, *num_args ); - XtGetValues( ((TextWidget) w)->text.sink, args, *num_args ); -} - -/* Function Name: FindGoodPosition - * Description: Returns a valid position given any postition - * Arguments: pos - any position. - * Returns: a position between (0 and lastPos); - */ - -static XawTextPosition -FindGoodPosition(ctx, pos) -TextWidget ctx; -XawTextPosition pos; -{ - if (pos < 0) return(0); - return ( ((pos > ctx->text.lastPos) ? ctx->text.lastPos : pos) ); -} - -/************************************************************ - * - * Routines for handling the copy area expose queue. +/* + * Function: + * XawTextGetValuesHook * - ************************************************************/ - -/* Function Name: PushCopyQueue - * Description: Pushes a value onto the copy queue. - * Arguments: ctx - the text widget. - * h, v - amount of offset in the horiz and vert directions. - * Returns: none - */ - -static void -PushCopyQueue(ctx, h, v) -TextWidget ctx; -int h, v; -{ - struct text_move * offsets = XtNew(struct text_move); - - offsets->h = h; - offsets->v = v; - offsets->next = NULL; - - if (ctx->text.copy_area_offsets == NULL) - ctx->text.copy_area_offsets = offsets; - else { - struct text_move * end = ctx->text.copy_area_offsets; - for ( ; end->next != NULL; end = end->next) {} - end->next = offsets; - } -} - -/* Function Name: PopCopyQueue - * Description: Pops the top value off of the copy queue. - * Arguments: ctx - the text widget. - * Returns: none. + * Parameters: + * w - Text Widget + * args - argument list + * num_args - number of args + * + * Description: + * This is a get values hook routine that gets the + * values in the text source and sink. */ - static void -PopCopyQueue(ctx) -TextWidget ctx; +XawTextGetValuesHook(Widget w, ArgList args, Cardinal *num_args) { - struct text_move * offsets = ctx->text.copy_area_offsets; - - if (offsets == NULL) - (void) printf( "Xaw Text widget %s: empty copy queue\n", - XtName( (Widget) ctx ) ); - else { - ctx->text.copy_area_offsets = offsets->next; - XtFree((char *) offsets); /* free what you allocate. */ - } + XtGetValues(((TextWidget)w)->text.source, args, *num_args); + XtGetValues(((TextWidget)w)->text.sink, args, *num_args); } -/* Function Name: TranslateExposeRegion - * Description: Translates the expose that came into - * the cordinates that now exist in the Text widget. - * Arguments: ctx - the text widget. - * expose - a Rectangle, who's region currently - * contains the expose event location. - * this region will be returned containing - * the new rectangle. - * Returns: True if there is drawing that needs to be done. +/* + * Function: + * FindGoodPosition + * + * Parameters: + * pos - any position + * + * Description: + * Returns a valid position given any postition. + * + * Returns: + * A position between (0 and lastPos) */ - -static Boolean -TranslateExposeRegion(ctx, expose) -TextWidget ctx; -XRectangle * expose; +static XawTextPosition +FindGoodPosition(TextWidget ctx, XawTextPosition pos) { - struct text_move * offsets = ctx->text.copy_area_offsets; - int value; - int x, y, width, height; - - /* - * Skip over the first one, this has already been taken into account. - */ - - if (!offsets || !(offsets = offsets->next)) - return(TRUE); - - x = expose->x; - y = expose->y; - width = expose->width; - height = expose->height; - - while (offsets) { - x += offsets->h; - y += offsets->v; - offsets = offsets->next; - } - - /* - * remove that area of the region that is now outside the window. - */ - - if (y < 0) { - height += y; - y = 0; - } - - value = y + height - ctx->core.height; - if (value > 0) - height -= value; - - if (height <= 0) - return(FALSE); /* no need to draw outside the window. */ - - /* - * and now in the horiz direction... - */ - - if (x < 0) { - width += x; - x = 0; - } - - value = x + width - ctx->core.width; - if (value > 0) - width -= value; - - if (width <= 0) - return(FALSE); /* no need to draw outside the window. */ - - expose->x = x; - expose->y = y; - expose->width = width; - expose->height = height; - return(TRUE); + if (pos < 0) + return (0); + return (((pos > ctx->text.lastPos) ? ctx->text.lastPos : pos)); } -/* Li wrote this so the IM can find a given text position's screen position. */ - +/* Li wrote this so the IM can find a given text position's screen position */ void -#if NeedFunctionPrototypes -_XawTextPosToXY( - Widget w, - XawTextPosition pos, - Position* x, - Position* y ) -#else -_XawTextPosToXY( w, pos, x, y ) - Widget w; - XawTextPosition pos; - Position *x, *y; -#endif +_XawTextPosToXY(Widget w, XawTextPosition pos, Position *x, Position *y) { - int line; - LineAndXYForPosition( (TextWidget)w, pos, &line, x, y ); + int line, ix, iy; + + LineAndXYForPosition((TextWidget)w, pos, &line, &ix, &iy); + *x = ix; + *y = iy; } /******************************************************************* @@ -3156,67 +3832,74 @@ internal one. The major value of this set is that they have actual application clients and therefore the functionality provided is required for any future version of Text. ********************************************************************/ - void -#if NeedFunctionPrototypes -XawTextDisplay (Widget w) -#else -XawTextDisplay (w) -Widget w; -#endif +XawTextDisplay(Widget w) { - if (!XtIsRealized(w)) return; - - _XawTextPrepareToUpdate( (TextWidget) w); - DisplayTextWindow(w); - _XawTextExecuteUpdate( (TextWidget) w); + TextWidget ctx = (TextWidget)w; + + if (!XtIsRealized(w)) + return; + + _XawTextPrepareToUpdate(ctx); + ctx->text.clear_to_eol = True; + DisplayTextWindow(w); + _XawTextExecuteUpdate(ctx); } void -#if NeedFunctionPrototypes XawTextSetSelectionArray(Widget w, XawTextSelectType *sarray) -#else -XawTextSetSelectionArray(w, sarray) -Widget w; -XawTextSelectType *sarray; -#endif { - ((TextWidget)w)->text.sarray = sarray; + ((TextWidget)w)->text.sarray = sarray; } void -#if NeedFunctionPrototypes XawTextGetSelectionPos(Widget w, XawTextPosition *left, XawTextPosition *right) -#else -XawTextGetSelectionPos(w, left, right) -Widget w; -XawTextPosition* left,* right; -#endif { - *left = ((TextWidget) w)->text.s.left; - *right = ((TextWidget) w)->text.s.right; + *left = ((TextWidget)w)->text.s.left; + *right = ((TextWidget)w)->text.s.right; } +void +_XawTextSetSource(Widget w, Widget source, + XawTextPosition top, XawTextPosition startPos) +{ + TextWidget ctx = (TextWidget)w; +#ifndef OLDXAW + Bool resolve = False; +#endif -void -#if NeedFunctionPrototypes -XawTextSetSource(Widget w, Widget source, XawTextPosition startPos) -#else -XawTextSetSource(w, source, startPos) -Widget w, source; -XawTextPosition startPos; +#ifndef OLDXAW + if (source != ctx->text.source) + _XawSourceRemoveText(ctx->text.source, w, ctx->text.source && + XtParent(ctx->text.source) == w); + _XawSourceAddText(source, w); + + if (source != ctx->text.source || ctx->text.insertPos != startPos) + resolve = True; + + ctx->text.source_changed = SRC_CHANGE_OVERLAP; #endif -{ - TextWidget ctx = (TextWidget) w; + ctx->text.source = source; + ctx->text.s.left = ctx->text.s.right = 0; + ctx->text.lastPos = GETLASTPOS; + top = FindGoodPosition(ctx, top); + startPos = FindGoodPosition(ctx, startPos); + ctx->text.insertPos = ctx->text.old_insert = startPos; + _XawTextPrepareToUpdate(ctx); - ctx->text.source = source; - ctx->text.lt.top = startPos; - ctx->text.s.left = ctx->text.s.right = 0; - ctx->text.insertPos = startPos; - ctx->text.lastPos = GETLASTPOS; - - _XawTextBuildLineTable(ctx, ctx->text.lt.top, TRUE); - XawTextDisplay(w); + _XawTextBuildLineTable(ctx, top, True); + + _XawTextExecuteUpdate(ctx); +#ifndef OLDXAW + if (resolve) + _XawTextSetLineAndColumnNumber(ctx, True); +#endif +} + +void +XawTextSetSource(Widget w, Widget source, XawTextPosition top) +{ + _XawTextSetSource(w, source, top, top); } /* @@ -3225,293 +3908,250 @@ XawTextPosition startPos; * "invalidates" that portion of the displayed text (if any), so that things * will be repainted properly. */ - -int -#if NeedFunctionPrototypes +int XawTextReplace(Widget w, XawTextPosition startPos, XawTextPosition endPos, - XawTextBlock *text) + XawTextBlock *text) +{ + TextWidget ctx = (TextWidget)w; + int result; +#ifndef OLDXAW + Cardinal i; + TextSrcObject src = (TextSrcObject)ctx->text.source; + + for (i = 0; i < src->textSrc.num_text; i++) + _XawTextPrepareToUpdate((TextWidget)src->textSrc.text[i]); #else -XawTextReplace(w, startPos, endPos, text) -Widget w; -XawTextPosition startPos, endPos; -XawTextBlock *text; + _XawTextPrepareToUpdate(ctx); #endif -{ - TextWidget ctx = (TextWidget) w; - int result; - _XawTextPrepareToUpdate(ctx); - endPos = FindGoodPosition(ctx, endPos); - startPos = FindGoodPosition(ctx, startPos); - if ((result = _XawTextReplace(ctx, startPos, endPos, text)) == XawEditDone) { - int delta = text->length - (endPos - startPos); - if (ctx->text.insertPos >= (endPos + delta)) { - XawTextScanDirection sd = (delta < 0) ? XawsdLeft : XawsdRight; - ctx->text.insertPos = SrcScan(ctx->text.source, ctx->text.insertPos, - XawstPositions, sd, abs(delta), TRUE); - } - } + endPos = FindGoodPosition(ctx, endPos); + startPos = FindGoodPosition(ctx, startPos); + result = _XawTextReplace(ctx, startPos, endPos, text); - _XawTextCheckResize(ctx); - _XawTextExecuteUpdate(ctx); - _XawTextSetScrollBars(ctx); - - return result; +#ifndef OLDXAW + for (i = 0; i < src->textSrc.num_text; i++) + _XawTextExecuteUpdate((TextWidget)src->textSrc.text[i]); +#else + _XawTextExecuteUpdate(ctx); +#endif + + return (result); } XawTextPosition -#if NeedFunctionPrototypes XawTextTopPosition(Widget w) -#else -XawTextTopPosition(w) -Widget w; -#endif { - return( ((TextWidget) w)->text.lt.top ); + return (((TextWidget)w)->text.lt.top); } -void -#if NeedFunctionPrototypes +XawTextPosition +XawTextLastPosition(Widget w) +{ + return (((TextWidget)w)->text.lastPos); +} + +void XawTextSetInsertionPoint(Widget w, XawTextPosition position) -#else -XawTextSetInsertionPoint(w, position) -Widget w; -XawTextPosition position; -#endif { - TextWidget ctx = (TextWidget) w; + TextWidget ctx = (TextWidget)w; - _XawTextPrepareToUpdate(ctx); - ctx->text.insertPos = FindGoodPosition(ctx, position); - ctx->text.showposition = TRUE; + _XawTextPrepareToUpdate(ctx); + ctx->text.insertPos = FindGoodPosition(ctx, position); + ctx->text.showposition = True; + ctx->text.from_left = -1; - _XawTextExecuteUpdate(ctx); + _XawTextExecuteUpdate(ctx); +#ifndef OLDXAW + _XawTextSetLineAndColumnNumber(ctx, False); +#endif } XawTextPosition -#if NeedFunctionPrototypes XawTextGetInsertionPoint(Widget w) -#else -XawTextGetInsertionPoint(w) -Widget w; -#endif { - return( ((TextWidget) w)->text.insertPos); + return (((TextWidget)w)->text.insertPos); } /* - * NOTE: Must walk the selection list in opposite order from LoseSelection. + * Note: Must walk the selection list in opposite order from TextLoseSelection */ - -void -#if NeedFunctionPrototypes +void XawTextUnsetSelection(Widget w) -#else -XawTextUnsetSelection(w) -Widget w; -#endif { - TextWidget ctx = (TextWidget)w; - - while (ctx->text.s.atom_count != 0) { - Atom sel = ctx->text.s.selections[ctx->text.s.atom_count - 1]; - if ( sel != (Atom) 0 ) { -/* - * As selections are lost the atom_count will decrement. - */ - if (GetCutBufferNumber(sel) == NOT_A_CUT_BUFFER) - XtDisownSelection(w, sel, ctx->text.time); - LoseSelection(w, &sel); /* In case this is a cut buffer, or - XtDisownSelection failed to call us. */ + TextWidget ctx = (TextWidget)w; + + while (ctx->text.s.atom_count != 0) { + Atom sel = ctx->text.s.selections[ctx->text.s.atom_count - 1]; + + if (sel != (Atom) 0) { + /* + * As selections are lost the atom_count will decrement + */ + if (GetCutBufferNumber(sel) == NOT_A_CUT_BUFFER) + XtDisownSelection(w, sel, ctx->text.time); + TextLoseSelection(w, &sel); /* In case this is a cut buffer, or + XtDisownSelection failed to call us */ + } } - } } void -#if NeedFunctionPrototypes -XawTextSetSelection (Widget w, XawTextPosition left, XawTextPosition right) -#else -XawTextSetSelection (w, left, right) -Widget w; -XawTextPosition left, right; -#endif +XawTextSetSelection(Widget w, XawTextPosition left, XawTextPosition right) { - TextWidget ctx = (TextWidget) w; - - _XawTextPrepareToUpdate(ctx); - _XawTextSetSelection(ctx, FindGoodPosition(ctx, left), - FindGoodPosition(ctx, right), (String*)NULL, ZERO); - _XawTextExecuteUpdate(ctx); + TextWidget ctx = (TextWidget)w; + + _XawTextPrepareToUpdate(ctx); + _XawTextSetSelection(ctx, FindGoodPosition(ctx, left), + FindGoodPosition(ctx, right), NULL, 0); + _XawTextExecuteUpdate(ctx); } -void -#if NeedFunctionPrototypes +void XawTextInvalidate(Widget w, XawTextPosition from, XawTextPosition to) -#else -XawTextInvalidate(w, from, to) -Widget w; -XawTextPosition from,to; -#endif { - TextWidget ctx = (TextWidget) w; + TextWidget ctx = (TextWidget)w; - from = FindGoodPosition(ctx, from); - to = FindGoodPosition(ctx, to); - ctx->text.lastPos = GETLASTPOS; - _XawTextPrepareToUpdate(ctx); - _XawTextNeedsUpdating(ctx, from, to); - _XawTextBuildLineTable(ctx, ctx->text.lt.top, TRUE); - _XawTextExecuteUpdate(ctx); + from = FindGoodPosition(ctx, from); + to = FindGoodPosition(ctx, to); + ctx->text.lastPos = GETLASTPOS; + _XawTextPrepareToUpdate(ctx); + _XawTextNeedsUpdating(ctx, from, to); + _XawTextExecuteUpdate(ctx); } /*ARGSUSED*/ void -#if NeedFunctionPrototypes XawTextDisableRedisplay(Widget w) -#else -XawTextDisableRedisplay(w) -Widget w; -#endif { - ((TextWidget) w)->text.update_disabled = True; - _XawTextPrepareToUpdate( (TextWidget) w); + ((TextWidget)w)->text.update_disabled = True; + _XawTextPrepareToUpdate((TextWidget)w); } void -#if NeedFunctionPrototypes XawTextEnableRedisplay(Widget w) -#else -XawTextEnableRedisplay(w) -Widget w; -#endif { - TextWidget ctx = (TextWidget)w; - XawTextPosition lastPos; + TextWidget ctx = (TextWidget)w; + XawTextPosition lastPos; - if (!ctx->text.update_disabled) return; + if (!ctx->text.update_disabled) + return; - ctx->text.update_disabled = False; - lastPos = ctx->text.lastPos = GETLASTPOS; - ctx->text.lt.top = FindGoodPosition(ctx, ctx->text.lt.top); - ctx->text.insertPos = FindGoodPosition(ctx, ctx->text.insertPos); - if ( (ctx->text.s.left > lastPos) || (ctx->text.s.right > lastPos) ) - ctx->text.s.left = ctx->text.s.right = 0; - - _XawTextBuildLineTable(ctx, ctx->text.lt.top, TRUE); - if (XtIsRealized(w)) - DisplayTextWindow(w); - _XawTextExecuteUpdate(ctx); + ctx->text.update_disabled = False; + lastPos = ctx->text.lastPos = GETLASTPOS; + ctx->text.lt.top = FindGoodPosition(ctx, ctx->text.lt.top); + ctx->text.insertPos = FindGoodPosition(ctx, ctx->text.insertPos); + + if (ctx->text.s.left > lastPos || ctx->text.s.right > lastPos) + ctx->text.s.left = ctx->text.s.right = 0; + + _XawTextExecuteUpdate(ctx); } Widget -#if NeedFunctionPrototypes XawTextGetSource(Widget w) -#else -XawTextGetSource(w) -Widget w; -#endif { - return ((TextWidget)w)->text.source; + return (((TextWidget)w)->text.source); +} + +Widget +XawTextGetSink(Widget w) +{ + return (((TextWidget)w)->text.sink); } void -#if NeedFunctionPrototypes -XawTextDisplayCaret (Widget w, +XawTextDisplayCaret(Widget w, #if NeedWidePrototypes - /* Boolean */ int display_caret) -#else - Boolean display_caret) -#endif + int display_caret #else -XawTextDisplayCaret (w, display_caret) -Widget w; -Boolean display_caret; + Boolean display_caret #endif +) { - TextWidget ctx = (TextWidget) w; + TextWidget ctx = (TextWidget)w; - if (ctx->text.display_caret == display_caret) return; + if (XtIsRealized(w)) { + _XawTextPrepareToUpdate(ctx); + ctx->text.display_caret = display_caret; + _XawTextExecuteUpdate(ctx); + } + else + ctx->text.display_caret = display_caret; +} - if (XtIsRealized(w)) { - _XawTextPrepareToUpdate(ctx); - ctx->text.display_caret = display_caret; - _XawTextExecuteUpdate(ctx); - } - else - ctx->text.display_caret = display_caret; -} - -/* Function Name: XawTextSearch(w, dir, text). - * Description: searches for the given text block. - * Arguments: w - The text widget. - * dir - The direction to search. - * text - The text block containing info about the string - * to search for. - * Returns: The position of the text found, or XawTextSearchError on - * an error. +/* + * Function: + * XawTextSearch + * + * Parameters: + * w - text widget + * dir - direction to search + * text - text block containing info about the string to search for + * + * Description: + * Searches for the given text block. + * + * Returns: + * The position of the text found, or XawTextSearchError on an error */ - XawTextPosition -#if NeedFunctionPrototypes XawTextSearch(Widget w, #if NeedWidePrototypes - /* XawTextScanDirection */ int dir, -#else - XawTextScanDirection dir, -#endif - XawTextBlock *text) + int dir, #else -XawTextSearch(w, dir, text) -Widget w; -XawTextScanDirection dir; -XawTextBlock * text; + XawTextScanDirection dir, #endif + XawTextBlock *text) { - TextWidget ctx = (TextWidget) w; + TextWidget ctx = (TextWidget)w; - return(SrcSearch(ctx->text.source, ctx->text.insertPos, dir, text)); + return (SrcSearch(ctx->text.source, ctx->text.insertPos, dir, text)); } - + TextClassRec textClassRec = { - { /* core fields */ - /* superclass */ (WidgetClass) &simpleClassRec, - /* class_name */ "Text", - /* widget_size */ sizeof(TextRec), - /* class_initialize */ ClassInitialize, - /* class_part_init */ NULL, - /* class_inited */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* realize */ Realize, - /* actions */ _XawTextActionsTable, - /* num_actions */ 0, /* Set in ClassInitialize. */ - /* resources */ resources, - /* num_ resource */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure*/ XtExposeGraphicsExpose | XtExposeNoExpose, - /* compress_enterleave*/ TRUE, - /* visible_interest */ FALSE, - /* destroy */ TextDestroy, - /* resize */ Resize, - /* expose */ ProcessExposeRegion, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* set_values_almost*/ XtInheritSetValuesAlmost, - /* get_values_hook */ GetValuesHook, - /* accept_focus */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ NULL, /* set in ClassInitialize */ - /* query_geometry */ XtInheritQueryGeometry, - /* display_accelerator*/ XtInheritDisplayAccelerator, - /* extension */ NULL + /* core */ + { + (WidgetClass)&simpleClassRec, /* superclass */ + "Text", /* class_name */ + sizeof(TextRec), /* widget_size */ + XawTextClassInitialize, /* class_initialize */ + NULL, /* class_part_init */ + False, /* class_inited */ + XawTextInitialize, /* initialize */ + NULL, /* initialize_hook */ + XawTextRealize, /* realize */ + _XawTextActionsTable, /* actions */ + 0, /* num_actions */ + resources, /* resources */ + XtNumber(resources), /* num_resource */ + NULLQUARK, /* xrm_class */ + True, /* compress_motion */ + XtExposeGraphicsExpose | /* compress_exposure */ + XtExposeNoExpose, + True, /* compress_enterleave */ + False, /* visible_interest */ + XawTextDestroy, /* destroy */ + XawTextResize, /* resize */ + XawTextExpose, /* expose */ + XawTextSetValues, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + XawTextGetValuesHook, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + _XawDefaultTextTranslations, /* tm_table */ + XtInheritQueryGeometry, /* query_geometry */ + XtInheritDisplayAccelerator, /* display_accelerator */ + NULL, /* extension */ }, - { /* Simple fields */ - /* change_sensitive */ ChangeSensitive + /* simple */ + { + XawTextChangeSensitive, /* change_sensitive */ }, - { /* text fields */ - /* empty */ 0 + /* text */ + { + NULL, /* extension */ } }; diff --git a/src/TextAction.c b/src/TextAction.c index a6a8c17..2fd34de 100644 --- a/src/TextAction.c +++ b/src/TextAction.c @@ -25,282 +25,481 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/TextAction.c,v 3.46 2002/03/20 05:06:23 paulo Exp $ */ + +#include <stdio.h> +#include <stdlib.h> +#include <X11/Xos.h> /* for select() and struct timeval */ +#include <ctype.h> #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> -#include <X11/Xutil.h> #include <X11/Xatom.h> +#include <X11/Xfuncs.h> +#include <X11/Xutil.h> +#include <X11/Xmu/Atoms.h> #include <X11/Xmu/Misc.h> -#include <X11/Xmu/StdSel.h> /* for XmuConvertStandardSelection */ -#include <X11/Xmu/Atoms.h> /* for XA_COMPOUND_TEXT */ -#include <X11/Xaw/TextP.h> +#include <X11/Xmu/StdSel.h> +#include <X11/Xmu/SysUtil.h> +#include <X11/Xaw/MultiSinkP.h> #include <X11/Xaw/MultiSrcP.h> +#include <X11/Xaw/TextP.h> +#include <X11/Xaw/TextSrcP.h> #include <X11/Xaw/XawImP.h> -#include <X11/Xfuncs.h> +#include "Private.h" #include "XawI18n.h" -#include <stdio.h> -#include <ctype.h> -#define SrcScan XawTextSourceScan -#define FindDist XawTextSinkFindDistance -#define FindPos XawTextSinkFindPosition +#define SrcScan XawTextSourceScan +#define FindDist XawTextSinkFindDistance +#define FindPos XawTextSinkFindPosition +#define MULT(w) (w->text.mult == 0 ? 4 : \ + w->text.mult == 32767 ? -4 : w->text.mult) + +#define KILL_RING_APPEND 2 +#define KILL_RING_BEGIN 3 +#define KILL_RING_YANK 100 +#define KILL_RING_YANK_DONE 98 + +#define XawTextActionMaxHexChars 100 + +/* + * Prototypes + */ +static void _DeleteOrKill(TextWidget, XawTextPosition, XawTextPosition, Bool); +static void _SelectionReceived(Widget, XtPointer, Atom*, Atom*, XtPointer, + unsigned long*, int*); +static void _LoseSelection(Widget, Atom*, char**, int*); +static void AutoFill(TextWidget); +static Boolean ConvertSelection(Widget, Atom*, Atom*, Atom*, XtPointer*, + unsigned long*, int*); +static void DeleteOrKill(TextWidget, XEvent*, XawTextScanDirection, + XawTextScanType, Bool, Bool); +static void EndAction(TextWidget); +#ifndef OLDXAW +static Bool BlankLine(Widget, XawTextPosition, int*); +static int DoFormatText(TextWidget, XawTextPosition, Bool, int, + XawTextBlock*, XawTextPosition*, int, Bool); +static int FormatText(TextWidget, XawTextPosition, Bool, + XawTextPosition*, int); +static Bool GetBlockBoundaries(TextWidget, XawTextPosition*, XawTextPosition*); +#endif +static int FormRegion(TextWidget, XawTextPosition, XawTextPosition, + XawTextPosition*, int); +static void GetSelection(Widget, Time, String*, Cardinal); +static char *IfHexConvertHexElseReturnParam(char*, int*); +static void InsertNewCRs(TextWidget, XawTextPosition, XawTextPosition, + XawTextPosition*, int); +static int InsertNewLineAndBackupInternal(TextWidget); +static int LocalInsertNewLine(TextWidget, XEvent*); +static void LoseSelection(Widget, Atom*); +static void ParameterError(Widget, String); +static Bool MatchSelection(Atom, XawTextSelection*); +static void ModifySelection(TextWidget, XEvent*, XawTextSelectionMode, + XawTextSelectionAction, String*, Cardinal*); +static void Move(TextWidget, XEvent*, XawTextScanDirection, XawTextScanType, + Bool); +static void NotePosition(TextWidget, XEvent*); +static void StartAction(TextWidget, XEvent*); +static XawTextPosition StripOutOldCRs(TextWidget, XawTextPosition, + XawTextPosition, XawTextPosition*, int); +#ifndef OLDXAW +static Bool StripSpaces(TextWidget, XawTextPosition, XawTextPosition, + XawTextPosition*, int, XawTextBlock*); +static Bool Tabify(TextWidget, XawTextPosition, XawTextPosition, + XawTextPosition*, int, XawTextBlock*); +static Bool Untabify(TextWidget, XawTextPosition, XawTextPosition, + XawTextPosition*, int, XawTextBlock*); +#endif -#define XawTextActionMaxHexChars 100 +/* + * Actions + */ +static void CapitalizeWord(Widget, XEvent*, String*, Cardinal*); +static void DisplayCaret(Widget, XEvent*, String*, Cardinal*); +static void Delete(Widget, XEvent*, String*, Cardinal*); +static void DeleteBackwardChar(Widget, XEvent*, String*, Cardinal*); +static void DeleteBackwardWord(Widget, XEvent*, String*, Cardinal*); +static void DeleteCurrentSelection(Widget, XEvent*, String*, Cardinal*); +static void DeleteForwardChar(Widget, XEvent*, String*, Cardinal*); +static void DeleteForwardWord(Widget, XEvent*, String*, Cardinal*); +static void DowncaseWord(Widget, XEvent*, String*, Cardinal*); +static void ExtendAdjust(Widget, XEvent*, String*, Cardinal*); +static void ExtendEnd(Widget, XEvent*, String*, Cardinal*); +static void ExtendStart(Widget, XEvent*, String*, Cardinal*); +static void FormParagraph(Widget, XEvent*, String*, Cardinal*); +#ifndef OLDXAW +static void Indent(Widget, XEvent*, String*, Cardinal*); +#endif +static void InsertChar(Widget, XEvent*, String*, Cardinal*); +static void InsertNewLine(Widget, XEvent*, String*, Cardinal*); +static void InsertNewLineAndBackup(Widget, XEvent*, String*, Cardinal*); +static void InsertNewLineAndIndent(Widget, XEvent*, String*, Cardinal*); +static void InsertSelection(Widget, XEvent*, String*, Cardinal*); +static void InsertString(Widget, XEvent*, String*, Cardinal*); +#ifndef OLDXAW +static void KeyboardReset(Widget, XEvent*, String*, Cardinal*); +#endif +static void KillBackwardWord(Widget, XEvent*, String*, Cardinal*); +static void KillCurrentSelection(Widget, XEvent*, String*, Cardinal*); +static void KillForwardWord(Widget, XEvent*, String*, Cardinal*); +#ifndef OLDXAW +static void KillRingYank(Widget, XEvent*, String*, Cardinal*); +#endif +static void KillToEndOfLine(Widget, XEvent*, String*, Cardinal*); +static void KillToEndOfParagraph(Widget, XEvent*, String*, Cardinal*); +static void MoveBackwardChar(Widget, XEvent*, String*, Cardinal*); +static void MoveBackwardWord(Widget, XEvent*, String*, Cardinal*); +static void MoveBackwardParagraph(Widget, XEvent*, String*, Cardinal*); +static void MoveBeginningOfFile(Widget, XEvent*, String*, Cardinal*); +static void MoveEndOfFile(Widget, XEvent*, String*, Cardinal*); +static void MoveForwardChar(Widget, XEvent*, String*, Cardinal*); +static void MoveForwardWord(Widget, XEvent*, String*, Cardinal*); +static void MoveForwardParagraph(Widget, XEvent*, String*, Cardinal*); +static void MoveNextLine(Widget, XEvent*, String*, Cardinal*); +static void MoveNextPage(Widget, XEvent*, String*, Cardinal*); +static void MovePage(TextWidget, XEvent*, XawTextScanDirection); +static void MovePreviousLine(Widget, XEvent*, String*, Cardinal*); +static void MovePreviousPage(Widget, XEvent*, String*, Cardinal*); +static void MoveLine(TextWidget, XEvent*, XawTextScanDirection); +static void MoveToLineEnd(Widget, XEvent*, String*, Cardinal*); +static void MoveToLineStart(Widget, XEvent*, String*, Cardinal*); +static void Multiply(Widget, XEvent*, String*, Cardinal*); +static void NoOp(Widget, XEvent*, String*, Cardinal*); +#ifndef OLDXAW +static void Numeric(Widget, XEvent*, String*, Cardinal*); +#endif +static void Reconnect(Widget, XEvent*, String*, Cardinal*); +static void RedrawDisplay(Widget, XEvent*, String*, Cardinal*); +static void Scroll(TextWidget, XEvent*, XawTextScanDirection); +static void ScrollOneLineDown(Widget, XEvent*, String*, Cardinal*); +static void ScrollOneLineUp(Widget, XEvent*, String*, Cardinal*); +static void SelectAdjust(Widget, XEvent*, String*, Cardinal*); +static void SelectAll(Widget, XEvent*, String*, Cardinal*); +static void SelectEnd(Widget, XEvent*, String*, Cardinal*); +static void SelectSave(Widget, XEvent*, String*, Cardinal*); +static void SelectStart(Widget, XEvent*, String*, Cardinal*); +static void SelectWord(Widget, XEvent*, String*, Cardinal*); +static void SetKeyboardFocus(Widget, XEvent*, String*, Cardinal*); +static void TextEnterWindow(Widget, XEvent*, String*, Cardinal*); +static void TextFocusIn(Widget, XEvent*, String*, Cardinal*); +static void TextFocusOut(Widget, XEvent*, String*, Cardinal*); +static void TextLeaveWindow(Widget, XEvent*, String*, Cardinal*); +static void TransposeCharacters(Widget, XEvent*, String*, Cardinal*); +#ifndef OLDXAW +static void ToggleOverwrite(Widget, XEvent*, String*, Cardinal*); +static void Undo(Widget, XEvent*, String*, Cardinal*); +#endif +static void UpcaseWord(Widget, XEvent*, String*, Cardinal*); +static void DestroyFocusCallback(Widget, XtPointer, XtPointer); /* - * These are defined in TextPop.c + * External */ +void _XawTextZapSelection(TextWidget, XEvent*, Bool); -void _XawTextInsertFileAction(), _XawTextInsertFile(), _XawTextSearch(); -void _XawTextSearch(), _XawTextDoSearchAction(), _XawTextDoReplaceAction(); -void _XawTextSetField(), _XawTextPopdownSearchAction(); +/* + * Defined in TextPop.c + */ +void _XawTextInsertFileAction(Widget, XEvent*, String*, Cardinal*); +void _XawTextInsertFile(Widget, XEvent*, String*, Cardinal*); +void _XawTextSearch(Widget, XEvent*, String*, Cardinal*); +void _XawTextDoSearchAction(Widget, XEvent*, String*, Cardinal*); +void _XawTextDoReplaceAction(Widget, XEvent*, String*, Cardinal*); +void _XawTextSetField(Widget, XEvent*, String*, Cardinal*); +void _XawTextPopdownSearchAction(Widget, XEvent*, String*, Cardinal*); /* * These are defined in Text.c */ +void _XawTextAlterSelection(TextWidget, XawTextSelectionMode, + XawTextSelectionAction, String*, Cardinal*); +void _XawTextClearAndCenterDisplay(TextWidget); +void _XawTextExecuteUpdate(TextWidget); +char *_XawTextGetText(TextWidget, XawTextPosition, XawTextPosition); +void _XawTextPrepareToUpdate(TextWidget); +int _XawTextReplace(TextWidget, XawTextPosition, XawTextPosition, + XawTextBlock*); +Atom *_XawTextSelectionList(TextWidget, String*, Cardinal); +void _XawTextSetSelection(TextWidget, XawTextPosition, XawTextPosition, + String*, Cardinal); +void _XawTextVScroll(TextWidget, int); +void XawTextScroll(TextWidget, int, int); +void _XawTextSetLineAndColumnNumber(TextWidget, Bool); + +#ifndef OLDXAW +/* + * Defined in TextSrc.c + */ +Bool _XawTextSrcUndo(TextSrcObject, XawTextPosition*); +Bool _XawTextSrcToggleUndo(TextSrcObject); +void _XawSourceSetUndoErase(TextSrcObject, int); +void _XawSourceSetUndoMerge(TextSrcObject, Bool); +#endif /* OLDXAW */ -char * _XawTextGetText(); -void _XawTextAlterSelection(), _XawTextVScroll(); -void _XawTextSetSelection(), _XawTextCheckResize(), _XawTextExecuteUpdate(); -void _XawTextSetScrollBars(), _XawTextClearAndCenterDisplay(); -Atom * _XawTextSelectionList(); -void _XawTextPrepareToUpdate(); -int _XawTextReplace(); +/* + * Initialization + */ +#ifndef OLDXAW +#define MAX_KILL_RINGS 1024 +XawTextKillRing *xaw_text_kill_ring; +static XawTextKillRing kill_ring_prev, kill_ring_null = { &kill_ring_prev, }; +static unsigned num_kill_rings; +#endif -static void ParameterError(w, param) - Widget w; - String param; +/* + * Implementation + */ +static void +ParameterError(Widget w, String param) { String params[2]; Cardinal num_params = 2; params[0] = XtName(w); params[1] = param; - - XtAppWarningMsg( XtWidgetToApplicationContext(w), - "parameterError", "textAction", "XawError", - "Widget: %s Parameter: %s", - params, &num_params); - XBell( XtDisplay( w ), 50 ); + + XtAppWarningMsg(XtWidgetToApplicationContext(w), + "parameterError", "textAction", "XawError", + "Widget: %s Parameter: %s", + params, &num_params); + XBell(XtDisplay(w), 50); } static void -StartAction(ctx, event) -TextWidget ctx; -XEvent *event; +StartAction(TextWidget ctx, XEvent *event) +{ +#ifndef OLDXAW + Cardinal i; + TextSrcObject src = (TextSrcObject)ctx->text.source; + + for (i = 0; i < src->textSrc.num_text; i++) + _XawTextPrepareToUpdate((TextWidget)src->textSrc.text[i]); + _XawSourceSetUndoMerge(src, False); +#else + _XawTextPrepareToUpdate(ctx); +#endif + + if (event != NULL) { + switch (event->type) { + case ButtonPress: + case ButtonRelease: + ctx->text.time = event->xbutton.time; + break; + case KeyPress: + case KeyRelease: + ctx->text.time = event->xkey.time; + break; + case MotionNotify: + ctx->text.time = event->xmotion.time; + break; + case EnterNotify: + case LeaveNotify: + ctx->text.time = event->xcrossing.time; + } + } +} + +static void +NotePosition(TextWidget ctx, XEvent *event) { - _XawTextPrepareToUpdate(ctx); - if (event != NULL) { switch (event->type) { - case ButtonPress: - case ButtonRelease: - ctx->text.time = event->xbutton.time; - break; - case KeyPress: - case KeyRelease: - ctx->text.time = event->xkey.time; - break; - case MotionNotify: - ctx->text.time = event->xmotion.time; - break; - case EnterNotify: - case LeaveNotify: - ctx->text.time = event->xcrossing.time; - } - } -} - -static void -NotePosition(ctx, event) -TextWidget ctx; -XEvent* event; -{ - switch (event->type) { - case ButtonPress: - case ButtonRelease: - ctx->text.ev_x = event->xbutton.x; - ctx->text.ev_y = event->xbutton.y; - break; - case KeyPress: - case KeyRelease: - { - XRectangle cursor; - XawTextSinkGetCursorBounds(ctx->text.sink, &cursor); - ctx->text.ev_x = cursor.x + cursor.width / 2;; - ctx->text.ev_y = cursor.y + cursor.height / 2;; - } - break; - case MotionNotify: - ctx->text.ev_x = event->xmotion.x; - ctx->text.ev_y = event->xmotion.y; - break; - case EnterNotify: - case LeaveNotify: - ctx->text.ev_x = event->xcrossing.x; - ctx->text.ev_y = event->xcrossing.y; - } -} - -static void -EndAction(ctx) -TextWidget ctx; -{ - _XawTextCheckResize(ctx); - _XawTextExecuteUpdate(ctx); - ctx->text.mult = 1; + case ButtonPress: + case ButtonRelease: + ctx->text.ev_x = event->xbutton.x; + ctx->text.ev_y = event->xbutton.y; + break; + case KeyPress: + case KeyRelease: { + XRectangle cursor; + XawTextSinkGetCursorBounds(ctx->text.sink, &cursor); + ctx->text.ev_x = cursor.x + cursor.width / 2; + ctx->text.ev_y = cursor.y + cursor.height / 2; + } break; + case MotionNotify: + ctx->text.ev_x = event->xmotion.x; + ctx->text.ev_y = event->xmotion.y; + break; + case EnterNotify: + case LeaveNotify: + ctx->text.ev_x = event->xcrossing.x; + ctx->text.ev_y = event->xcrossing.y; + } } +static void +EndAction(TextWidget ctx) +{ +#ifndef OLDXAW + Cardinal i; + TextSrcObject src = (TextSrcObject)ctx->text.source; + + for (i = 0; i < src->textSrc.num_text; i++) + _XawTextExecuteUpdate((TextWidget)src->textSrc.text[i]); + + ctx->text.mult = 1; + ctx->text.numeric = False; + if (ctx->text.kill_ring) { + if (--ctx->text.kill_ring == KILL_RING_YANK_DONE) { + if (ctx->text.kill_ring_ptr) { + --ctx->text.kill_ring_ptr->refcount; + ctx->text.kill_ring_ptr = NULL; + } + } + } +#else + ctx->text.mult = 1; + _XawTextExecuteUpdate(ctx); +#endif /* OLDXAW */ +} struct _SelectionList { String* params; Cardinal count; Time time; - Boolean CT_asked; /* flag if asked XA_COMPOUND_TEXT */ - Atom selection; /* selection atom when asking XA_COMPOUND_TEXT */ + int asked; /* which selection currently has been asked for: + 0 = UTF8_STRING, 1 = COMPOUND_TEXT, 2 = STRING */ + Atom selection; /* selection atom (normally XA_PRIMARY) */ }; -static int ProbablyMB(s) - char* s; +/*ARGSUSED*/ +static void +_SelectionReceived(Widget w, XtPointer client_data, Atom *selection, + Atom *type, XtPointer value, unsigned long *length, + int *format) { - int escapes = 0; - int has_hi_bit = False; + Display *d = XtDisplay(w); + TextWidget ctx = (TextWidget)w; + XawTextBlock text; + + if (*type == 0 /*XT_CONVERT_FAIL*/ || *length == 0) { + struct _SelectionList* list = (struct _SelectionList*)client_data; + + if (list != NULL) { + if (list->asked == 0) { + /* If we just asked for XA_UTF8_STRING and got no response, + we'll ask again, this time for XA_COMPOUND_TEXT. */ + list->asked++; + XtGetSelectionValue(w, list->selection, XA_COMPOUND_TEXT(d), + _SelectionReceived, + (XtPointer)list, list->time); + } else if (list->asked == 1) { + /* If we just asked for XA_COMPOUND_TEXT and got no response, + we'll ask again, this time for XA_STRING. */ + list->asked++; + XtGetSelectionValue(w, list->selection, XA_STRING, + _SelectionReceived, + (XtPointer)list, list->time); + } else { + /* We tried all possible text targets in this param. + Recurse on the tail of the params list. */ + GetSelection(w, list->time, list->params, list->count); + XtFree(client_data); + } + } + return; + } - /* if it has more than one ESC char, I assume it is COMPOUND_TEXT. - If it has at least one hi bit set character, I pretend it is multibyte. */ + StartAction(ctx, NULL); + if (XawTextFormat(ctx, XawFmtWide)) { + XTextProperty textprop; + wchar_t **wlist; + int count; + + textprop.encoding = *type; + textprop.value = (unsigned char *)value; + textprop.nitems = strlen(value); + textprop.format = 8; + + if (XwcTextPropertyToTextList(d, &textprop, &wlist, &count) + != Success + || count < 1) { + XwcFreeStringList(wlist); + + /* Notify the user on strerr and in the insertion :) */ + fprintf(stderr, "Xaw Text Widget: An attempt was made to insert " + "an illegal selection.\n"); + + textprop.value = (unsigned char *)" >> ILLEGAL SELECTION << "; + textprop.nitems = strlen((char *) textprop.value); + if (XwcTextPropertyToTextList(d, &textprop, &wlist, &count) + != Success + || count < 1) + return; + } + + XFree(value); + value = (XPointer)wlist[0]; + + *length = wcslen(wlist[0]); + XtFree((XtPointer)wlist); + text.format = XawFmtWide; + } else { + XTextProperty textprop; + char **list; + int count; + + textprop.encoding = *type; + textprop.value = (unsigned char *)value; + textprop.nitems = strlen(value); + textprop.format = 8; + + if (XmbTextPropertyToTextList(d, &textprop, &list, &count) + != Success + || count < 1) { + XFreeStringList(list); + + /* Notify the user on strerr and in the insertion :) */ + fprintf(stderr, "Xaw Text Widget: An attempt was made to insert " + "an illegal selection.\n"); + + textprop.value = (unsigned char *)" >> ILLEGAL SELECTION << "; + textprop.nitems = strlen((char *) textprop.value); + if (XmbTextPropertyToTextList(d, &textprop, &list, &count) + != Success + || count < 1) + return; + } - while ( (*s) != (wchar_t)0 ) { - if ( *s & 128 ) - has_hi_bit = True; - if ( *s++ == '\033' ) - escapes++; - if ( escapes >= 2 ) - return( 0 ); + XFree(value); + value = (XPointer)list[0]; + + *length = strlen(list[0]); + XtFree((XtPointer)list); + text.format = XawFmt8Bit; + } + text.ptr = (char*)value; + text.firstPos = 0; + text.length = *length; + if (_XawTextReplace(ctx, ctx->text.insertPos, ctx->text.insertPos, &text)) { + XBell(XtDisplay(ctx), 0); + EndAction(ctx); + return; } - return( has_hi_bit ); + + ctx->text.from_left = -1; + ctx->text.insertPos = SrcScan(ctx->text.source, ctx->text.old_insert, + XawstPositions, XawsdRight, text.length, True); + + EndAction(ctx); + XtFree(client_data); + XFree(value); /* the selection value should be freed with XFree */ } -static void GetSelection(); -/* ARGSUSED */ -static void -_SelectionReceived(w, client_data, selection, type, value, length, format) -Widget w; -XtPointer client_data; -Atom *selection, *type; -XtPointer value; -unsigned long *length; -int* format; -{ - TextWidget ctx = (TextWidget)w; - XawTextBlock text; - - if (*type == 0 /*XT_CONVERT_FAIL*/ || *length == 0) { - struct _SelectionList* list = (struct _SelectionList*)client_data; - if (list != NULL) { - if (list->CT_asked) { - - /* If we just asked for a XA_COMPOUND_TEXT and got a null - response, we'll ask again, this time for an XA_STRING. */ - - list->CT_asked = False; - XtGetSelectionValue(w, list->selection, XA_STRING, _SelectionReceived, - (XtPointer)list, list->time); - } else { - GetSelection(w, list->time, list->params, list->count); - XtFree(client_data); - } - } - return; - } - - /* Many programs, especially old terminal emulators, give us multibyte text -but tell us it is COMPOUND_TEXT :( The following routine checks to see if the -string is a legal multibyte string in our locale using a spooky heuristic :O -and if it is we can only assume the sending client is using the same locale as -we are, and convert it. I also warn the user that the other client is evil. */ - - StartAction( ctx, (XEvent*) NULL ); - if (_XawTextFormat(ctx) == XawFmtWide) { - XTextProperty textprop; - Display *d = XtDisplay((Widget)ctx); - wchar_t **wlist; - int count; - int try_CT = 1; - - /* IS THE SELECTION IN MULTIBYTE FORMAT? */ - - if ( ProbablyMB( (char *) value ) ) { - char * list[1]; - list[0] = (char *) value; - if ( XmbTextListToTextProperty( d, (char**) list, 1, - XCompoundTextStyle, &textprop ) == Success ) - try_CT = 0; - } - - /* OR IN COMPOUND TEXT FORMAT? */ - - if ( try_CT ) { - textprop.encoding = XA_COMPOUND_TEXT(d); - textprop.value = (unsigned char *)value; - textprop.nitems = strlen(value); - textprop.format = 8; - } - - if ( XwcTextPropertyToTextList( d, &textprop, (wchar_t***) &wlist, &count ) - != Success) { - XwcFreeStringList( (wchar_t**) wlist ); - - /* Notify the user on strerr and in the insertion :) */ - textprop.value = (unsigned char *) " >> ILLEGAL SELECTION << "; - count = 1; - fprintf( stderr, "Xaw Text Widget: An attempt was made to insert an illegal selection.\n" ); - - if ( XwcTextPropertyToTextList( d, &textprop, (wchar_t***) &wlist, &count ) - != Success) return; - } - - XFree(value); - value = (XPointer)wlist[0]; - - *length = wcslen(wlist[0]); - XtFree((XtPointer)wlist); - text.format = XawFmtWide; - } else - text.format = XawFmt8Bit; - text.ptr = (char*)value; - text.firstPos = 0; - text.length = *length; - if (_XawTextReplace(ctx, ctx->text.insertPos, ctx->text.insertPos, &text)) { - XBell(XtDisplay(ctx), 0); - return; - } - ctx->text.insertPos = SrcScan(ctx->text.source, ctx->text.insertPos, - XawstPositions, XawsdRight, text.length, TRUE); - - _XawTextSetScrollBars(ctx); - EndAction(ctx); - XtFree(client_data); - XFree(value); /* the selection value should be freed with XFree */ -} - -static void -GetSelection(w, time, params, num_params) -Widget w; -Time time; -String* params; /* selections in precedence order */ -Cardinal num_params; +static void +GetSelection(Widget w, Time timev, String *params, Cardinal num_params) { Atom selection; int buffer; selection = XInternAtom(XtDisplay(w), *params, False); switch (selection) { - case XA_CUT_BUFFER0: buffer = 0; break; - case XA_CUT_BUFFER1: buffer = 1; break; - case XA_CUT_BUFFER2: buffer = 2; break; - case XA_CUT_BUFFER3: buffer = 3; break; - case XA_CUT_BUFFER4: buffer = 4; break; - case XA_CUT_BUFFER5: buffer = 5; break; - case XA_CUT_BUFFER6: buffer = 6; break; - case XA_CUT_BUFFER7: buffer = 7; break; - default: buffer = -1; + case XA_CUT_BUFFER0: buffer = 0; break; + case XA_CUT_BUFFER1: buffer = 1; break; + case XA_CUT_BUFFER2: buffer = 2; break; + case XA_CUT_BUFFER3: buffer = 3; break; + case XA_CUT_BUFFER4: buffer = 4; break; + case XA_CUT_BUFFER5: buffer = 5; break; + case XA_CUT_BUFFER6: buffer = 6; break; + case XA_CUT_BUFFER7: buffer = 7; break; + default: buffer = -1; } if (buffer >= 0) { int nbytes; @@ -308,1277 +507,2715 @@ Cardinal num_params; int fmt8 = 8; Atom type = XA_STRING; char *line = XFetchBuffer(XtDisplay(w), &nbytes, buffer); - if (length = nbytes) - _SelectionReceived(w, (XtPointer) NULL, &selection, &type, (XPointer)line, - &length, &fmt8); + + if ((length = nbytes) != 0L) + _SelectionReceived(w, NULL, &selection, &type, line, &length, &fmt8); else if (num_params > 1) - GetSelection(w, time, params+1, num_params-1); - } else { + GetSelection(w, timev, params+1, num_params-1); + } + else { struct _SelectionList* list; + if (--num_params) { list = XtNew(struct _SelectionList); list->params = params + 1; list->count = num_params; - list->time = time; - list->CT_asked = True; + list->time = timev; + list->asked = 0; list->selection = selection; - } else list = NULL; - XtGetSelectionValue(w, selection, XA_COMPOUND_TEXT(XtDisplay(w)), - _SelectionReceived, (XtPointer)list, time); + } + else + list = NULL; + XtGetSelectionValue(w, selection, XA_UTF8_STRING(XtDisplay(w)), + _SelectionReceived, (XtPointer)list, timev); } } -static void -InsertSelection(w, event, params, num_params) -Widget w; -XEvent* event; -String* params; /* precedence list of selections to try */ -Cardinal* num_params; +static void +InsertSelection(Widget w, XEvent *event, String *params, Cardinal *num_params) { - StartAction((TextWidget)w, event); /* Get Time. */ - GetSelection(w, ((TextWidget)w)->text.time, params, *num_params); - EndAction((TextWidget)w); + StartAction((TextWidget)w, event); /* Get Time. */ + GetSelection(w, ((TextWidget)w)->text.time, params, *num_params); + EndAction((TextWidget)w); } -/************************************************************ - * - * Routines for Moving Around. - * - ************************************************************/ - +/* + * Routines for Moving Around + */ static void -Move(ctx, event, dir, type, include) -TextWidget ctx; -XEvent* event; -XawTextScanDirection dir; -XawTextScanType type; -Boolean include; +Move(TextWidget ctx, XEvent *event, XawTextScanDirection dir, + XawTextScanType type, Bool include) { - StartAction(ctx, event); - ctx->text.insertPos = SrcScan(ctx->text.source, ctx->text.insertPos, - type, dir, ctx->text.mult, include); - EndAction(ctx); + XawTextPosition insertPos; + short mult = MULT(ctx); + + if (mult < 0) { + mult = -mult; + dir = dir == XawsdLeft ? XawsdRight : XawsdLeft; + } + + insertPos = SrcScan(ctx->text.source, ctx->text.insertPos, + type, dir, mult, include); + + StartAction(ctx, event); + + if (ctx->text.s.left != ctx->text.s.right) + XawTextUnsetSelection((Widget)ctx); + +#ifndef OLDXAW + ctx->text.numeric = False; +#endif + ctx->text.mult = 1; + ctx->text.showposition = True; + ctx->text.from_left = -1; + ctx->text.insertPos = insertPos; + EndAction(ctx); } /*ARGSUSED*/ -static void -MoveForwardChar(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +MoveForwardChar(Widget w, XEvent *event, String *p, Cardinal *n) { - Move((TextWidget) w, event, XawsdRight, XawstPositions, TRUE); + Move((TextWidget)w, event, XawsdRight, XawstPositions, True); } /*ARGSUSED*/ -static void -MoveBackwardChar(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +MoveBackwardChar(Widget w, XEvent *event, String *p, Cardinal *n) { - Move((TextWidget) w, event, XawsdLeft, XawstPositions, TRUE); + Move((TextWidget)w, event, XawsdLeft, XawstPositions, True); } -/*ARGSUSED*/ -static void -MoveForwardWord(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +MoveForwardWord(Widget w, XEvent *event, String *p, Cardinal *n) { - Move((TextWidget) w, event, XawsdRight, XawstWhiteSpace, FALSE); + if (*n && (p[0][0] == 'A' || p[0][0] == 'a')) + Move((TextWidget)w, event, XawsdRight, XawstAlphaNumeric, False); + else + Move((TextWidget)w, event, XawsdRight, XawstWhiteSpace, False); } -/*ARGSUSED*/ -static void -MoveBackwardWord(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +MoveBackwardWord(Widget w, XEvent *event, String *p, Cardinal *n) { - Move((TextWidget) w, event, XawsdLeft, XawstWhiteSpace, FALSE); + if (*n && (p[0][0] == 'A' || p[0][0] == 'a')) + Move((TextWidget)w, event, XawsdLeft, XawstAlphaNumeric, False); + else + Move((TextWidget)w, event, XawsdLeft, XawstWhiteSpace, False); } -/*ARGSUSED*/ -static void MoveForwardParagraph(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +MoveForwardParagraph(Widget w, XEvent *event, String *p, Cardinal *n) { - Move((TextWidget) w, event, XawsdRight, XawstParagraph, FALSE); + TextWidget ctx = (TextWidget)w; + XawTextPosition position = ctx->text.insertPos; + short mult = MULT(ctx); + + if (mult < 0) { + ctx->text.mult = -mult; + MoveBackwardParagraph(w, event, p, n); + return; + } + + while (mult--) { + position = SrcScan(ctx->text.source, position, + XawstEOL, XawsdRight, 1, False) - 1; + + while (position == SrcScan(ctx->text.source, position, + XawstEOL, XawsdRight, 1, False)) + if (++position > ctx->text.lastPos) { + mult = 0; + break; + } + + position = SrcScan(ctx->text.source, position, + XawstParagraph, XawsdRight, 1, True); + if (position != ctx->text.lastPos) + position = SrcScan(ctx->text.source, position - 1, + XawstEOL, XawsdLeft, 1, False); + else + break; + } + + if (position != ctx->text.insertPos) { + XawTextUnsetSelection(w); + StartAction(ctx, event); + ctx->text.showposition = True; + ctx->text.from_left = -1; + ctx->text.insertPos = position; + EndAction(ctx); + } + else + ctx->text.mult = 1; } /*ARGSUSED*/ -static void MoveBackwardParagraph(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +MoveBackwardParagraph(Widget w, XEvent *event, String *p, Cardinal *n) { - Move((TextWidget) w, event, XawsdLeft, XawstParagraph, FALSE); + TextWidget ctx = (TextWidget)w; + XawTextPosition position = ctx->text.insertPos; + short mult = MULT(ctx); + + if (mult < 0) { + ctx->text.mult = -mult; + MoveForwardParagraph(w, event, p, n); + return; + } + + while (mult--) { + position = SrcScan(ctx->text.source, position, + XawstEOL, XawsdLeft, 1, False) + 1; + + while (position == SrcScan(ctx->text.source, position, + XawstEOL, XawsdLeft, 1, False)) + if (--position < 0) { + mult = 0; + break; + } + + position = SrcScan(ctx->text.source, position, + XawstParagraph, XawsdLeft, 1, True); + if (position > 0 && position < ctx->text.lastPos) + ++position; + else + break; + } + + if (position != ctx->text.insertPos) { + XawTextUnsetSelection(w); + StartAction(ctx, event); + ctx->text.showposition = True; + ctx->text.from_left = -1; + ctx->text.insertPos = position; + EndAction(ctx); + } + else + ctx->text.mult = 1; } /*ARGSUSED*/ -static void -MoveToLineEnd(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +MoveToLineEnd(Widget w, XEvent *event, String *p, Cardinal *n) { - Move((TextWidget) w, event, XawsdRight, XawstEOL, FALSE); + Move((TextWidget)w, event, XawsdRight, XawstEOL, False); } /*ARGSUSED*/ -static void -MoveToLineStart(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +MoveToLineStart(Widget w, XEvent *event, String *p, Cardinal *n) { - Move((TextWidget) w, event, XawsdLeft, XawstEOL, FALSE); + Move((TextWidget)w, event, XawsdLeft, XawstEOL, False); } - static void -MoveLine(ctx, event, dir) -TextWidget ctx; -XEvent* event; -XawTextScanDirection dir; +MoveLine(TextWidget ctx, XEvent *event, XawTextScanDirection dir) { - XawTextPosition new, next_line, junk; - int from_left, garbage; + XawTextPosition cnew, next_line, ltemp; + int itemp, from_left; + short mult = MULT(ctx); - StartAction(ctx, event); + StartAction(ctx, event); - if (dir == XawsdLeft) - ctx->text.mult++; + XawTextUnsetSelection((Widget)ctx); - new = SrcScan(ctx->text.source, ctx->text.insertPos, - XawstEOL, XawsdLeft, 1, FALSE); + if (dir == XawsdLeft) + mult = mult == 0 ? 5 : mult + 1; - FindDist(ctx->text.sink, new, ctx->text.margin.left, ctx->text.insertPos, - &from_left, &junk, &garbage); + cnew = SrcScan(ctx->text.source, ctx->text.insertPos, + XawstEOL, XawsdLeft, 1, False); - new = SrcScan(ctx->text.source, ctx->text.insertPos, XawstEOL, dir, - ctx->text.mult, (dir == XawsdRight)); + if (ctx->text.from_left < 0) + FindDist(ctx->text.sink, cnew, ctx->text.left_margin, ctx->text.insertPos, + &ctx->text.from_left, <emp, &itemp); - next_line = SrcScan(ctx->text.source, new, XawstEOL, XawsdRight, 1, FALSE); + cnew = SrcScan(ctx->text.source, ctx->text.insertPos, XawstEOL, dir, + mult, (dir == XawsdRight)); - FindPos(ctx->text.sink, new, ctx->text.margin.left, from_left, FALSE, - &(ctx->text.insertPos), &garbage, &garbage); - - if (ctx->text.insertPos > next_line) - ctx->text.insertPos = next_line; + next_line = SrcScan(ctx->text.source, cnew, XawstEOL, XawsdRight, 1, False); + + FindPos(ctx->text.sink, cnew, ctx->text.left_margin, ctx->text.from_left, + False, &ctx->text.insertPos, &from_left, &itemp); + + if (from_left < ctx->text.from_left) { + XawTextBlock block; + + XawTextSourceRead(ctx->text.source, ctx->text.insertPos, &block, 1); + if (block.length) { + if (XawTextFormat(ctx, XawFmtWide)) { + if (*(wchar_t *)block.ptr == _Xaw_atowc(XawTAB)) + ++ctx->text.insertPos; + } + else if (block.ptr[0] == XawTAB) + ++ctx->text.insertPos; + } + } - EndAction(ctx); + if (ctx->text.insertPos > next_line) + ctx->text.insertPos = next_line; + + EndAction(ctx); } -/*ARGSUSED*/ -static void -MoveNextLine(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +MoveNextLine(Widget w, XEvent *event, String *p, Cardinal *n) { - MoveLine( (TextWidget) w, event, XawsdRight); + TextWidget ctx = (TextWidget)w; + short mult = MULT(ctx); + + if (mult < 0) { + ctx->text.mult = -mult; + MovePreviousLine(w, event, p, n); + return; + } + + if (ctx->text.insertPos < ctx->text.lastPos) + MoveLine(ctx, event, XawsdRight); + else + ctx->text.mult = 1; } -/*ARGSUSED*/ -static void -MovePreviousLine(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +MovePreviousLine(Widget w, XEvent *event, String *p, Cardinal *n) { - MoveLine( (TextWidget) w, event, XawsdLeft); + TextWidget ctx = (TextWidget)w; + short mult = MULT(ctx); + + if (mult < 0) { + ctx->text.mult = -mult; + MoveNextLine(w, event, p, n); + return; + } + + if (ctx->text.lt.top != 0 || (ctx->text.lt.lines > 1 && + ctx->text.insertPos >= ctx->text.lt.info[1].position)) + MoveLine(ctx, event, XawsdLeft); + else + ctx->text.mult = 1; } /*ARGSUSED*/ static void -MoveBeginningOfFile(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +MoveBeginningOfFile(Widget w, XEvent *event, String *p, Cardinal *n) { - Move((TextWidget) w, event, XawsdLeft, XawstAll, TRUE); + Move((TextWidget)w, event, XawsdLeft, XawstAll, True); } /*ARGSUSED*/ -static void -MoveEndOfFile(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +MoveEndOfFile(Widget w, XEvent *event, String *p, Cardinal *n) { - Move((TextWidget) w, event, XawsdRight, XawstAll, TRUE); + Move((TextWidget)w, event, XawsdRight, XawstAll, True); } -static void -Scroll(ctx, event, dir) -TextWidget ctx; -XEvent* event; -XawTextScanDirection dir; +static void +Scroll(TextWidget ctx, XEvent *event, XawTextScanDirection dir) { - StartAction(ctx, event); + short mult = MULT(ctx); + + if (mult < 0) { + mult = -mult; + dir = dir == XawsdLeft ? XawsdRight : XawsdLeft; + } + + if (ctx->text.lt.lines > 1 + && (dir == XawsdRight + || ctx->text.lastPos >= ctx->text.lt.info[1].position)) { + StartAction(ctx, event); - if (dir == XawsdLeft) - _XawTextVScroll(ctx, ctx->text.mult); - else - _XawTextVScroll(ctx, -ctx->text.mult); + if (dir == XawsdLeft) + _XawTextVScroll(ctx, mult); + else + _XawTextVScroll(ctx, -mult); - EndAction(ctx); + EndAction(ctx); + } + else { + ctx->text.mult = 1; +#ifndef OLDXAW + ctx->text.numeric = False; +#endif + } } /*ARGSUSED*/ -static void -ScrollOneLineUp(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +ScrollOneLineUp(Widget w, XEvent *event, String *p, Cardinal *n) { - Scroll( (TextWidget) w, event, XawsdLeft); + Scroll((TextWidget)w, event, XawsdLeft); } /*ARGSUSED*/ -static void -ScrollOneLineDown(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +ScrollOneLineDown(Widget w, XEvent *event, String *p, Cardinal *n) { - Scroll( (TextWidget) w, event, XawsdRight); + Scroll((TextWidget)w, event, XawsdRight); } -static void -MovePage(ctx, event, dir) -TextWidget ctx; -XEvent* event; -XawTextScanDirection dir; +static void +MovePage(TextWidget ctx, XEvent *event, XawTextScanDirection dir) { - int scroll_val = Max(1, ctx->text.lt.lines - 2); + int scroll_val = 0; + XawTextPosition old_pos; + + ctx->text.from_left = -1; + switch (dir) { + case XawsdLeft: + if (ctx->text.lt.top != 0) + scroll_val = -Max(1, ctx->text.lt.lines - 1); + break; + case XawsdRight: + if (!IsPositionVisible(ctx, Max(0, ctx->text.lastPos))) + scroll_val = Max(1, ctx->text.lt.lines - 1); + break; + } - if (dir == XawsdLeft) - scroll_val = -scroll_val; + if (scroll_val) + XawTextScroll(ctx, scroll_val, + ctx->text.left_margin - ctx->text.r_margin.left); - StartAction(ctx, event); - _XawTextVScroll(ctx, scroll_val); - ctx->text.insertPos = ctx->text.lt.top; - EndAction(ctx); + old_pos = ctx->text.insertPos; + switch (dir) { + case XawsdRight: + if (IsPositionVisible(ctx, Max(0, ctx->text.lastPos))) + ctx->text.insertPos = Max(0, ctx->text.lastPos); + else + ctx->text.insertPos = ctx->text.lt.top; + if (ctx->text.insertPos < old_pos) + ctx->text.insertPos = SrcScan(ctx->text.source, old_pos, + XawstEOL, XawsdLeft, 1, False); + break; + case XawsdLeft: + if (IsPositionVisible(ctx, 0)) + ctx->text.insertPos = 0; + else if (ctx->text.lt.lines) + ctx->text.insertPos = + ctx->text.lt.info[ctx->text.lt.lines - 1].position; + else + ctx->text.insertPos = ctx->text.lt.top; + if (ctx->text.insertPos > old_pos) + ctx->text.insertPos = SrcScan(ctx->text.source, old_pos, + XawstEOL, XawsdLeft, 1, False); + break; + } } -/*ARGSUSED*/ -static void -MoveNextPage(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +MoveNextPage(Widget w, XEvent *event, String *p, Cardinal *n) { - MovePage((TextWidget) w, event, XawsdRight); + TextWidget ctx = (TextWidget)w; + short mult = MULT(ctx); + + if (mult < 0) { + ctx->text.mult = -mult; + MovePreviousPage(w, event, p, n); + return; + } + + if (ctx->text.insertPos < ctx->text.lastPos) { + XawTextUnsetSelection(w); + StartAction(ctx, event); + ctx->text.clear_to_eol = True; + while (mult-- && ctx->text.insertPos < ctx->text.lastPos) + MovePage(ctx, event, XawsdRight); + EndAction(ctx); + } + else + ctx->text.mult = 1; } /*ARGSUSED*/ -static void -MovePreviousPage(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +MovePreviousPage(Widget w, XEvent *event, String *p, Cardinal *n) { - MovePage((TextWidget) w, event, XawsdLeft); -} + TextWidget ctx = (TextWidget)w; + short mult = MULT(ctx); -/************************************************************ - * - * Delete Routines. - * - ************************************************************/ + if (mult < 0) { + ctx->text.mult = -mult; + MoveNextPage(w, event, p, n); + return; + } -static Boolean -MatchSelection(selection, s) - Atom selection; - XawTextSelection* s; + if (ctx->text.insertPos > 0) { + XawTextUnsetSelection(w); + StartAction(ctx, event); + ctx->text.clear_to_eol = True; + while (mult-- && ctx->text.insertPos > 0) + MovePage(ctx, event, XawsdLeft); + EndAction(ctx); + } + else + ctx->text.mult = 1; +} + +/* + * Delete Routines + */ +static Bool +MatchSelection(Atom selection, XawTextSelection *s) { - Atom *match; - int count; + Atom *match; + int count; - for (count = 0, match = s->selections; count < s->atom_count; match++, count++) + for (count = 0, match = s->selections; count < s->atom_count; + match++, count++) if (*match == selection) - return True; - return False; + return (True); + + return (False); } #define SrcCvtSel XawTextSourceConvertSelection -static Boolean -ConvertSelection(w, selection, target, type, value, length, format) - Widget w; - Atom *selection, *target, *type; - XtPointer* value; - unsigned long* length; - int* format; -{ - Display* d = XtDisplay(w); - TextWidget ctx = (TextWidget)w; - Widget src = ctx->text.source; - XawTextEditType edit_mode; - Arg args[1]; - XawTextSelectionSalt *salt = NULL; - XawTextSelection *s; - - if (*target == XA_TARGETS(d)) { - Atom* targetP, * std_targets; - unsigned long std_length; - - if ( SrcCvtSel(src, selection, target, type, value, length, format) ) - return True; - - XmuConvertStandardSelection(w, ctx->text.time, selection, - target, type, (XPointer*)&std_targets, - &std_length, format); - - *value = XtMalloc((unsigned) sizeof(Atom)*(std_length + 7)); - targetP = *(Atom**)value; - - *length = std_length + 6; - *targetP++ = XA_STRING; - *targetP++ = XA_TEXT(d); - *targetP++ = XA_COMPOUND_TEXT(d); - *targetP++ = XA_LENGTH(d); - *targetP++ = XA_LIST_LENGTH(d); - *targetP++ = XA_CHARACTER_POSITION(d); - - XtSetArg(args[0], XtNeditType,&edit_mode); - XtGetValues(src, args, 1); - - if (edit_mode == XawtextEdit) { - *targetP++ = XA_DELETE(d); - (*length)++; - } - memcpy((char*)targetP, (char*)std_targets, sizeof(Atom)*std_length); - XtFree((char*)std_targets); - *type = XA_ATOM; - *format = 32; - return True; - } - - if ( SrcCvtSel(src, selection, target, type, value, length, format) ) - return True; - - for (salt = ctx->text.salt2; salt; salt = salt->next) - if (MatchSelection (*selection, &salt->s)) - break; - if (!salt) - return False; - s = &salt->s; - if (*target == XA_STRING || - *target == XA_TEXT(d) || - *target == XA_COMPOUND_TEXT(d)) { +static Boolean +ConvertSelection(Widget w, Atom *selection, Atom *target, Atom *type, + XtPointer *value, unsigned long *length, int *format) +{ + Display *d = XtDisplay(w); + TextWidget ctx = (TextWidget)w; + Widget src = ctx->text.source; + XawTextEditType edit_mode; + Arg args[1]; + XawTextSelectionSalt *salt = NULL; + XawTextSelection *s; + + if (*target == XA_TARGETS(d)) { + Atom *targetP, *std_targets; + unsigned long std_length; + + if (SrcCvtSel(src, selection, target, type, value, length, format)) + return (True); + + XtSetArg(args[0], XtNeditType,&edit_mode); + XtGetValues(src, args, 1); + + XmuConvertStandardSelection(w, ctx->text.time, selection, + target, type, (XPointer *)&std_targets, + &std_length, format); + + *length = 7 + (edit_mode == XawtextEdit) + std_length; + *value = XtMalloc((unsigned)sizeof(Atom)*(*length)); + targetP = *(Atom**)value; + *targetP++ = XA_STRING; + *targetP++ = XA_TEXT(d); + *targetP++ = XA_UTF8_STRING(d); + *targetP++ = XA_COMPOUND_TEXT(d); + *targetP++ = XA_LENGTH(d); + *targetP++ = XA_LIST_LENGTH(d); + *targetP++ = XA_CHARACTER_POSITION(d); + if (edit_mode == XawtextEdit) { + *targetP++ = XA_DELETE(d); + } + memcpy((char*)targetP, (char*)std_targets, sizeof(Atom)*std_length); + XtFree((char*)std_targets); + *type = XA_ATOM; + *format = 32; + return (True); + } + + if (SrcCvtSel(src, selection, target, type, value, length, format)) + return (True); + + for (salt = ctx->text.salt2; salt; salt = salt->next) + if (MatchSelection (*selection, &salt->s)) + break; + if (!salt) + return (False); + s = &salt->s; + if (*target == XA_STRING + || *target == XA_TEXT(d) + || *target == XA_UTF8_STRING(d) + || *target == XA_COMPOUND_TEXT(d)) { if (*target == XA_TEXT(d)) { - if (_XawTextFormat(ctx) == XawFmtWide) + if (XawTextFormat(ctx, XawFmtWide)) *type = XA_COMPOUND_TEXT(d); else *type = XA_STRING; - } else { - *type = *target; } - /* - * If salt is True, the salt->contents stores CT string, + else + *type = *target; + + /* + * If salt is True, the salt->contents stores CT string, * its length is measured in bytes. - * Refer to _XawTextSaltAwaySelection(). + * Refer to _XawTextSaltAwaySelection() * * by Li Yuhong, Mar. 20, 1991. */ if (!salt) { *value = (char *)_XawTextGetSTRING(ctx, s->left, s->right); - if (_XawTextFormat(ctx) == XawFmtWide) { + if (XawTextFormat(ctx, XawFmtWide)) { XTextProperty textprop; if (XwcTextListToTextProperty(d, (wchar_t**)value, 1, XCompoundTextStyle, &textprop) - < Success) { + < Success) { XtFree(*value); - return False; + return (False); } XtFree(*value); *value = (XtPointer)textprop.value; *length = textprop.nitems; - } else { - *length = strlen(*value); } - } else { + else + *length = strlen(*value); + } + else { *value = XtMalloc((salt->length + 1) * sizeof(unsigned char)); strcpy (*value, salt->contents); *length = salt->length; } - if (_XawTextFormat(ctx) == XawFmtWide && *type == XA_STRING) { + /* Got *value,*length, now in COMPOUND_TEXT format. */ + if (XawTextFormat(ctx, XawFmtWide) && *type == XA_STRING) { XTextProperty textprop; - wchar_t** wlist; + wchar_t **wlist; int count; + textprop.encoding = XA_COMPOUND_TEXT(d); textprop.value = (unsigned char *)*value; textprop.nitems = strlen(*value); textprop.format = 8; - if (XwcTextPropertyToTextList(d, &textprop, (wchar_t***)&wlist, &count) - < Success) { + if (XwcTextPropertyToTextList(d, &textprop, &wlist, &count) + < Success + || count < 1) { XtFree(*value); - return False; + return (False); } XtFree(*value); - if (XwcTextListToTextProperty(d, (wchar_t**)wlist, 1, - XStringStyle, &textprop) < Success) { - XwcFreeStringList( (wchar_t**) wlist ); - return False; + if (XwcTextListToTextProperty(d, wlist, 1, XStringStyle, &textprop) + < Success) { + XwcFreeStringList((wchar_t**)wlist); + return (False); } *value = (XtPointer)textprop.value; *length = textprop.nitems; - XwcFreeStringList( (wchar_t**) wlist ); + XwcFreeStringList((wchar_t**) wlist); + } else if (*type == XA_UTF8_STRING(d)) { + XTextProperty textprop; + char **list; + int count; + + textprop.encoding = XA_COMPOUND_TEXT(d); + textprop.value = (unsigned char *)*value; + textprop.nitems = strlen(*value); + textprop.format = 8; + if (Xutf8TextPropertyToTextList(d, &textprop, &list, &count) + < Success + || count < 1) { + XtFree(*value); + return (False); + } + XtFree(*value); + *value = *list; + *length = strlen(*list); + XFree(list); } *format = 8; - return True; - } - - if ( (*target == XA_LIST_LENGTH(d)) || (*target == XA_LENGTH(d)) ) { - long * temp; - - temp = (long *) XtMalloc(sizeof(long)); - if (*target == XA_LIST_LENGTH(d)) - *temp = 1L; - else /* *target == XA_LENGTH(d) */ - *temp = (long) (s->right - s->left); - - *value = (XPointer) temp; - *type = XA_INTEGER; - *length = 1L; - *format = 32; - return True; - } - - if (*target == XA_CHARACTER_POSITION(d)) { - long * temp; - - temp = (long *) XtMalloc(2 * sizeof(long)); - temp[0] = (long) (s->left + 1); - temp[1] = s->right; - *value = (XPointer) temp; - *type = XA_SPAN(d); - *length = 2L; - *format = 32; - return True; - } - - if (*target == XA_DELETE(d)) { - void _XawTextZapSelection(); /* From TextAction.c */ - - if (!salt) - _XawTextZapSelection( ctx, (XEvent *) NULL, TRUE); - *value = NULL; - *type = XA_NULL(d); - *length = 0; - *format = 32; - return True; - } - - if (XmuConvertStandardSelection(w, ctx->text.time, selection, target, type, - (XPointer *)value, length, format)) - return True; + return (True); + } + + if (*target == XA_LIST_LENGTH(d) || *target == XA_LENGTH(d)) { + long *temp; + + temp = (long *)XtMalloc(sizeof(long)); + if (*target == XA_LIST_LENGTH(d)) + *temp = 1L; + else /* *target == XA_LENGTH(d) */ + *temp = (long)(s->right - s->left); + + *value = (XPointer)temp; + *type = XA_INTEGER; + *length = 1L; + *format = 32; + return (True); + } + + if (*target == XA_CHARACTER_POSITION(d)) { + long *temp; + + temp = (long *) XtMalloc(2 * sizeof(long)); + temp[0] = (long)(s->left + 1); + temp[1] = s->right; + *value = (XPointer)temp; + *type = XA_SPAN(d); + *length = 2L; + *format = 32; + return (True); + } + + if (*target == XA_DELETE(d)) { + if (!salt) + _XawTextZapSelection(ctx, NULL, True); + *value = NULL; + *type = XA_NULL(d); + *length = 0; + *format = 32; + return (True); + } + + if (XmuConvertStandardSelection(w, ctx->text.time, selection, target, type, + (XPointer *)value, length, format)) + return (True); - /* else */ - return False; + return (False); +} + +static void +LoseSelection(Widget w, Atom *selection) +{ + _LoseSelection(w, selection, NULL, NULL); } -static void -LoseSelection(w, selection) - Widget w; - Atom* selection; +static void +_LoseSelection(Widget w, Atom *selection, char **contents, int *length) { - TextWidget ctx = (TextWidget) w; - Atom* atomP; - int i; - XawTextSelectionSalt *salt, *prevSalt, *nextSalt; + TextWidget ctx = (TextWidget)w; + Atom *atomP; + int i; + XawTextSelectionSalt *salt, *prevSalt, *nextSalt; prevSalt = 0; - for (salt = ctx->text.salt2; salt; salt = nextSalt) - { - atomP = salt->s.selections; + for (salt = ctx->text.salt2; salt; salt = nextSalt) { + atomP = salt->s.selections; nextSalt = salt->next; - for (i = 0 ; i < salt->s.atom_count; i++, atomP++) + for (i = 0 ; i < salt->s.atom_count; i++, atomP++) if (*selection == *atomP) *atomP = (Atom)0; - - while (salt->s.atom_count && - salt->s.selections[salt->s.atom_count-1] == 0) - { + + while (salt->s.atom_count + && salt->s.selections[salt->s.atom_count-1] == 0) salt->s.atom_count--; - } - - /* - * Must walk the selection list in opposite order from UnsetSelection. - */ - - atomP = salt->s.selections; - for (i = 0 ; i < salt->s.atom_count; i++, atomP++) - if (*atomP == (Atom)0) - { - *atomP = salt->s.selections[--salt->s.atom_count]; - while (salt->s.atom_count && - salt->s.selections[salt->s.atom_count-1] == 0) - salt->s.atom_count--; - } - if (salt->s.atom_count == 0) - { - XtFree ((char *) salt->s.selections); - - /* WARNING: the next line frees memory not allocated in Xaw. */ - /* Could be a serious bug. Someone look into it. */ - XtFree (salt->contents); + + /* + * Must walk the selection list in opposite order from UnsetSelection. + */ + atomP = salt->s.selections; + for (i = 0 ; i < salt->s.atom_count; i++, atomP++) + if (*atomP == (Atom)0) { + *atomP = salt->s.selections[--salt->s.atom_count]; + + while (salt->s.atom_count + && salt->s.selections[salt->s.atom_count-1] == 0) + salt->s.atom_count--; + } + if (salt->s.atom_count == 0) { +#ifndef OLDXAW + if (contents == NULL) { + XawTextKillRing *kill_ring = XtNew(XawTextKillRing); + + kill_ring->next = xaw_text_kill_ring; + kill_ring->contents = salt->contents; + kill_ring->length = salt->length; + kill_ring->format = XawFmt8Bit; + xaw_text_kill_ring = kill_ring; + kill_ring_prev.next = xaw_text_kill_ring; + + if (++num_kill_rings > MAX_KILL_RINGS) { + XawTextKillRing *tail = NULL; + + while (kill_ring->next) { + tail = kill_ring; + kill_ring = kill_ring->next; + } + if (kill_ring->refcount == 0) { + --num_kill_rings; + tail->next = NULL; + XtFree(kill_ring->contents); + XtFree((char*)kill_ring); + } + } + } + else { + *contents = salt->contents; + *length = salt->length; + } +#endif if (prevSalt) prevSalt->next = nextSalt; else ctx->text.salt2 = nextSalt; - XtFree ((char *) salt); + + XtFree((char *)salt->s.selections); + XtFree((char *)salt); } else prevSalt = salt; } } -static void -_DeleteOrKill(ctx, from, to, kill) -TextWidget ctx; -XawTextPosition from, to; -Boolean kill; +static void +_DeleteOrKill(TextWidget ctx, XawTextPosition from, XawTextPosition to, + Bool kill) { - XawTextBlock text; - - if (kill && from < to) { - XawTextSelectionSalt *salt; - Atom selection = XInternAtom(XtDisplay(ctx), "SECONDARY", False); + XawTextBlock text; - LoseSelection ((Widget) ctx, &selection); - salt = (XawTextSelectionSalt *) XtMalloc (sizeof (XawTextSelectionSalt)); - if (!salt) - return; - salt->s.selections = (Atom *) XtMalloc (sizeof (Atom)); - if (!salt->s.selections) - { - XtFree ((char *) salt); - return; +#ifndef OLDXAW + if (ctx->text.kill_ring_ptr) { + --ctx->text.kill_ring_ptr->refcount; + ctx->text.kill_ring_ptr = NULL; } - salt->s.left = from; - salt->s.right = to; - salt->contents = (char *)_XawTextGetSTRING(ctx, from, to); - if (_XawTextFormat(ctx) == XawFmtWide) { - XTextProperty textprop; - if (XwcTextListToTextProperty(XtDisplay((Widget)ctx), - (wchar_t**)(&(salt->contents)), 1, XCompoundTextStyle, - &textprop) < Success) { - XtFree(salt->contents); - salt->length = 0; - return; +#endif + if (kill && from < to) { +#ifndef OLDXAW + Bool append = False; + char *ring = NULL; + XawTextPosition old_from = from; +#endif + char *string; + int size = 0, length; + XawTextSelectionSalt *salt; + Atom selection = XInternAtom(XtDisplay(ctx), "SECONDARY", False); + +#ifndef OLDXAW + if (ctx->text.kill_ring == KILL_RING_APPEND) { + old_from = ctx->text.salt2->s.left; + append = True; } - XtFree(salt->contents); - salt->contents = (char *)textprop.value; - salt->length = textprop.nitems; - } else - salt->length = strlen (salt->contents); - salt->next = ctx->text.salt2; - ctx->text.salt2 = salt; - salt->s.selections[0] = selection; - XtOwnSelection ((Widget) ctx, selection, ctx->text.time, - ConvertSelection, LoseSelection, NULL); - salt->s.atom_count = 1; -/* - XStoreBuffer(XtDisplay(ctx), ptr, strlen(ptr), 1); - XtFree(ptr); -*/ - } - text.length = 0; - text.firstPos = 0; + else + ctx->text.kill_ring = KILL_RING_BEGIN; + + if (append) + _LoseSelection((Widget)ctx, &selection, &ring, &size); + else +#endif + LoseSelection((Widget)ctx, &selection); - text.format = _XawTextFormat(ctx); - text.ptr = ""; /* These two lines needed to make legal TextBlock */ + salt = (XawTextSelectionSalt*)XtMalloc(sizeof(XawTextSelectionSalt)); + salt->s.selections = (Atom *)XtMalloc(sizeof(Atom)); + salt->s.left = from; + salt->s.right = to; - if (_XawTextReplace(ctx, from, to, &text)) { - XBell(XtDisplay(ctx), 50); - return; - } - ctx->text.insertPos = from; - ctx->text.showposition = TRUE; + string = (char *)_XawTextGetSTRING(ctx, from, to); + + if (XawTextFormat(ctx, XawFmtWide)) { + XTextProperty textprop; + + if (XwcTextListToTextProperty(XtDisplay((Widget)ctx), + (wchar_t**)(&string), + 1, XCompoundTextStyle, + &textprop) < Success) { + XtFree(string); + XtFree((char*)salt->s.selections); + XtFree((char*)salt); + return; + } + XtFree(string); + string = (char *)textprop.value; + length = textprop.nitems; + } + else + length = strlen(string); + + salt->length = length + size; + +#ifndef OLDXAW + if (!append) + salt->contents = string; + else { + salt->contents = XtMalloc(length + size + 1); + if (from >= old_from) { + strncpy(salt->contents, ring, size); + salt->contents[size] = '\0'; + strncat(salt->contents, string, length); + } + else { + strncpy(salt->contents, string, length); + salt->contents[length] = '\0'; + strncat(salt->contents, ring, size); + } + salt->contents[length + size] = '\0'; + XtFree(ring); + XtFree(string); + } + + kill_ring_prev.contents = salt->contents; + kill_ring_prev.length = salt->length; + kill_ring_prev.format = XawFmt8Bit; +#else + salt->contents = string; +#endif + + salt->next = ctx->text.salt2; + ctx->text.salt2 = salt; + +#ifndef OLDXAW + if (append) + ctx->text.kill_ring = KILL_RING_BEGIN; +#endif + + salt->s.selections[0] = selection; + + XtOwnSelection((Widget)ctx, selection, ctx->text.time, + ConvertSelection, LoseSelection, NULL); + salt->s.atom_count = 1; + } + text.length = 0; + text.firstPos = 0; + + text.format = _XawTextFormat(ctx); + text.ptr = ""; + + if (_XawTextReplace(ctx, from, to, &text)) { + XBell(XtDisplay(ctx), 50); + return; + } + ctx->text.from_left = -1; + ctx->text.insertPos = from; + ctx->text.showposition = TRUE; } static void -DeleteOrKill(ctx, event, dir, type, include, kill) -TextWidget ctx; -XEvent* event; -XawTextScanDirection dir; -XawTextScanType type; -Boolean include, kill; +DeleteOrKill(TextWidget ctx, XEvent *event, XawTextScanDirection dir, + XawTextScanType type, Bool include, Bool kill) { - XawTextPosition from, to; - - StartAction(ctx, event); - to = SrcScan(ctx->text.source, ctx->text.insertPos, - type, dir, ctx->text.mult, include); + XawTextPosition from, to; + short mult = MULT(ctx); -/* - * If no movement actually happened, then bump the count and try again. - * This causes the character position at the very beginning and end of - * a boundary to act correctly. - */ + if (mult < 0) { + mult = -mult; + dir = dir == XawsdLeft ? XawsdRight : XawsdLeft; + } - if (to == ctx->text.insertPos) - to = SrcScan(ctx->text.source, ctx->text.insertPos, - type, dir, ctx->text.mult + 1, include); + StartAction(ctx, event); +#ifndef OLDXAW + if (mult == 1) + _XawSourceSetUndoMerge((TextSrcObject)ctx->text.source, True); +#endif + to = SrcScan(ctx->text.source, ctx->text.insertPos, + type, dir, mult, include); + + /* + * If no movement actually happened, then bump the count and try again. + * This causes the character position at the very beginning and end of + * a boundary to act correctly + */ + if (to == ctx->text.insertPos) + to = SrcScan(ctx->text.source, ctx->text.insertPos, + type, dir, mult + 1, include); + + if (dir == XawsdLeft) { + from = to; + to = ctx->text.insertPos; + } + else + from = ctx->text.insertPos; - if (dir == XawsdLeft) { - from = to; - to = ctx->text.insertPos; - } - else - from = ctx->text.insertPos; + _DeleteOrKill(ctx, from, to, kill); + EndAction(ctx); +} - _DeleteOrKill(ctx, from, to, kill); - _XawTextSetScrollBars(ctx); - EndAction(ctx); +static void +Delete(Widget w, XEvent *event, String *p, Cardinal *n) +{ + TextWidget ctx = (TextWidget)w; + + if (ctx->text.s.left != ctx->text.s.right) + DeleteCurrentSelection(w, event, p, n); + else + DeleteBackwardChar(w, event, p, n); } -/*ARGSUSED*/ -static void -DeleteForwardChar(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +DeleteChar(Widget w, XEvent *event, XawTextScanDirection dir) { - DeleteOrKill((TextWidget) w, event, XawsdRight, XawstPositions, TRUE, FALSE); + TextWidget ctx = (TextWidget)w; + short mul = MULT(ctx); + + if (mul < 0) { + ctx->text.mult = mul = -mul; + dir = dir == XawsdLeft ? XawsdRight : XawsdLeft; + } + DeleteOrKill(ctx, event, dir, XawstPositions, True, False); +#ifndef OLDXAW + if (mul == 1) + _XawSourceSetUndoErase((TextSrcObject)ctx->text.source, + dir == XawsdLeft ? -1 : 1); +#endif } /*ARGSUSED*/ static void -DeleteBackwardChar(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +DeleteForwardChar(Widget w, XEvent *event, String *p, Cardinal *n) { - DeleteOrKill((TextWidget) w, event, XawsdLeft, XawstPositions, TRUE, FALSE); + DeleteChar(w, event, XawsdRight); } /*ARGSUSED*/ -static void -DeleteForwardWord(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +DeleteBackwardChar(Widget w, XEvent *event, String *p, Cardinal *n) +{ + DeleteChar(w, event, XawsdLeft); +} + +static void +DeleteForwardWord(Widget w, XEvent *event, String *params, Cardinal *num_params) +{ + XawTextScanType type; + + if (*num_params && (*params[0] == 'A' || *params[0] == 'a')) + type = XawstAlphaNumeric; + else + type = XawstWhiteSpace; + + DeleteOrKill((TextWidget)w, event, XawsdRight, type, False, False); +} + +static void +DeleteBackwardWord(Widget w, XEvent *event, String *params, Cardinal *num_params) { - DeleteOrKill((TextWidget) w, event, - XawsdRight, XawstWhiteSpace, FALSE, FALSE); + XawTextScanType type; + + if (*num_params && (*params[0] == 'A' || *params[0] == 'a')) + type = XawstAlphaNumeric; + else + type = XawstWhiteSpace; + + DeleteOrKill((TextWidget)w, event, XawsdLeft, type, False, False); +} + +static void +KillForwardWord(Widget w, XEvent *event, String *params, Cardinal *num_params) +{ + XawTextScanType type; + + if (*num_params && (*params[0] == 'A' || *params[0] == 'a')) + type = XawstAlphaNumeric; + else + type = XawstWhiteSpace; + + DeleteOrKill((TextWidget)w, event, XawsdRight, type, False, True); +} + +static void +KillBackwardWord(Widget w, XEvent *event, String *params, Cardinal *num_params) +{ + XawTextScanType type; + + if (*num_params && (*params[0] == 'A' || *params[0] == 'a')) + type = XawstAlphaNumeric; + else + type = XawstWhiteSpace; + + DeleteOrKill((TextWidget) w, event, XawsdLeft, type, False, True); } /*ARGSUSED*/ -static void -DeleteBackwardWord(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +KillToEndOfLine(Widget w, XEvent *event, String *p, Cardinal *n) { - DeleteOrKill((TextWidget) w, event, - XawsdLeft, XawstWhiteSpace, FALSE, FALSE); + TextWidget ctx = (TextWidget)w; + XawTextPosition end_of_line; + XawTextScanDirection dir = XawsdRight; + short mult = MULT(ctx); + + if (mult < 0) { + dir = XawsdLeft; + mult = -mult; + } + + StartAction(ctx, event); + end_of_line = SrcScan(ctx->text.source, ctx->text.insertPos, XawstEOL, + dir, mult, False); + if (end_of_line == ctx->text.insertPos) + end_of_line = SrcScan(ctx->text.source, ctx->text.insertPos, XawstEOL, + dir, mult, True); + + if (dir == XawsdRight) + _DeleteOrKill(ctx, ctx->text.insertPos, end_of_line, True); + else + _DeleteOrKill(ctx, end_of_line, ctx->text.insertPos, True); + EndAction(ctx); } /*ARGSUSED*/ -static void -KillForwardWord(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +KillToEndOfParagraph(Widget w, XEvent *event, String *p, Cardinal *n) +{ + DeleteOrKill((TextWidget)w, event, XawsdRight, XawstParagraph, False, True); +} + +void +_XawTextZapSelection(TextWidget ctx, XEvent *event, Bool kill) { - DeleteOrKill((TextWidget) w, event, - XawsdRight, XawstWhiteSpace, FALSE, TRUE); + StartAction(ctx, event); + _DeleteOrKill(ctx, ctx->text.s.left, ctx->text.s.right, kill); + EndAction(ctx); } /*ARGSUSED*/ -static void -KillBackwardWord(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +KillCurrentSelection(Widget w, XEvent *event, String *p, Cardinal *n) { - DeleteOrKill((TextWidget) w, event, - XawsdLeft, XawstWhiteSpace, FALSE, TRUE); + _XawTextZapSelection((TextWidget) w, event, True); } +#ifndef OLDXAW /*ARGSUSED*/ static void -KillToEndOfLine(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +KillRingYank(Widget w, XEvent *event, String *params, Cardinal *num_params) { - TextWidget ctx = (TextWidget) w; - XawTextPosition end_of_line; + TextWidget ctx = (TextWidget)w; + XawTextPosition insertPos = ctx->text.insertPos; + Bool first_yank = False; - StartAction(ctx, event); - end_of_line = SrcScan(ctx->text.source, ctx->text.insertPos, XawstEOL, - XawsdRight, ctx->text.mult, FALSE); - if (end_of_line == ctx->text.insertPos) - end_of_line = SrcScan(ctx->text.source, ctx->text.insertPos, XawstEOL, - XawsdRight, ctx->text.mult, TRUE); + if (ctx->text.s.left != ctx->text.s.right) + XawTextUnsetSelection((Widget)ctx); - _DeleteOrKill(ctx, ctx->text.insertPos, end_of_line, TRUE); - _XawTextSetScrollBars(ctx); - EndAction(ctx); + StartAction(ctx, event); + + if (ctx->text.kill_ring_ptr == NULL) { + ctx->text.kill_ring_ptr = &kill_ring_prev; + ++ctx->text.kill_ring_ptr->refcount; + ctx->text.s.left = ctx->text.s.right = insertPos; + first_yank = True; + } + if (ctx->text.kill_ring_ptr) { + int mul = MULT(ctx); + XawTextBlock text; + + if (!first_yank) { + if (mul < 0) + mul = 1; + --ctx->text.kill_ring_ptr->refcount; + while (mul--) { + if ((ctx->text.kill_ring_ptr = ctx->text.kill_ring_ptr->next) == NULL) + ctx->text.kill_ring_ptr = &kill_ring_null; + } + ++ctx->text.kill_ring_ptr->refcount; + } + text.firstPos = 0; + text.length = ctx->text.kill_ring_ptr->length; + text.ptr = ctx->text.kill_ring_ptr->contents; + text.format = ctx->text.kill_ring_ptr->format; + + if (_XawTextReplace(ctx, ctx->text.s.left, insertPos, &text) == XawEditDone) { + ctx->text.kill_ring = KILL_RING_YANK; + ctx->text.insertPos = ctx->text.s.left + text.length; + } + } + else + XBell(XtDisplay(w), 0); + + EndAction(ctx); } +#endif /* OLDXAW */ /*ARGSUSED*/ -static void -KillToEndOfParagraph(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +DeleteCurrentSelection(Widget w, XEvent *event, String *p, Cardinal *n) +{ + _XawTextZapSelection((TextWidget)w, event, False); +} + +#ifndef OLDXAW +#define CHECK_SAVE() \ + if (save && !save->ptr) \ + save->ptr = _XawTextGetText(ctx, save->firstPos, \ + save->firstPos + save->length) +static Bool +StripSpaces(TextWidget ctx, XawTextPosition left, XawTextPosition right, + XawTextPosition *pos, int num_pos, XawTextBlock *save) +{ + Bool done, space; + int i, cpos, count = 0; + XawTextBlock block, text; + XawTextPosition ipos, position = left, tmp = left; + + text.firstPos = 0; + text.format = XawFmt8Bit; + text.ptr = " "; + text.length = 1; + + position = XawTextSourceRead(ctx->text.source, position, + &block, right - left); + done = False; + space = False; + /* convert tabs and returns to spaces */ + while (!done) { + if (XawTextFormat(ctx, XawFmt8Bit)) { + for (i = 0; i < block.length; i++) + if (block.ptr[i] == '\t' || block.ptr[i] == '\n') { + space = True; + break; + } + } + else { + wchar_t *wptr = (wchar_t*)block.ptr; + for (i = 0; i < block.length; i++) + if (wptr[i] == _Xaw_atowc('\t') || wptr[i] == _Xaw_atowc('\n')) { + space = True; + break; + } + } + if (space) { + CHECK_SAVE(); + if (_XawTextReplace(ctx, tmp + i, tmp + i + 1, &text)) + return (False); + space = False; + } + tmp += i; + position = XawTextSourceRead(ctx->text.source, tmp, + &block, right - tmp); + if (block.length == 0 || tmp == position || tmp >= right) + done = True; + } + + text.ptr = ""; + text.length = 0; + position = tmp = left; + position = XawTextSourceRead(ctx->text.source, position, + &block, right - left); + ipos = ctx->text.insertPos; + done = False; + while (!done) { + if (XawTextFormat(ctx, XawFmt8Bit)) { + for (i = 0; i < block.length; i++) + if (block.ptr[i] == ' ') + ++count; + else if (count == 1) + count = 0; + else if (count) + break; + } + else { + wchar_t *wptr = (wchar_t*)block.ptr; + for (i = 0; i < block.length; i++) + if (wptr[i] == _Xaw_atowc(' ')) + ++count; + else if (count == 1) + count = 0; + else if (count) + break; + } + if (--count > 0) { + CHECK_SAVE(); + if (_XawTextReplace(ctx, tmp + i - count, tmp + i, &text)) + return (False); + right -= count; + if (num_pos) { + for (cpos = 0; cpos < num_pos; cpos++) { + if (tmp + i - count < pos[cpos]) { + if (tmp + i < pos[cpos]) + pos[cpos] -= count; + else + pos[cpos] = tmp + i - count; + } + } + } + else { + if (tmp + i - count < ipos) { + if (tmp + i < ipos) + ipos -= count; + else + ipos = tmp + i - count; + } + } + tmp += i - count; + } + else + tmp += i + 1; + count = 0; + position = XawTextSourceRead(ctx->text.source, tmp, + &block, right - tmp); + if (block.length == 0 || tmp == position || tmp >= right) + done = True; + } + if (!num_pos) + ctx->text.insertPos = ipos; + + return (True); +} + +static Bool +Tabify(TextWidget ctx, XawTextPosition left, XawTextPosition right, + XawTextPosition *pos, int num_pos, XawTextBlock *save) { - DeleteOrKill((TextWidget) w, event, XawsdRight, XawstParagraph, FALSE, TRUE); + Bool done, zero; + int i, cpos, count = 0, column = 0, offset = 0; + XawTextBlock text, block; + XawTextPosition ipos, position = left, tmp = left; + TextSinkObject sink = (TextSinkObject)ctx->text.sink; + short *char_tabs = sink->text_sink.char_tabs; + int tab_count = sink->text_sink.tab_count; + int tab_index = 0, tab_column = 0, TAB_SIZE = DEFAULT_TAB_SIZE; + + text.firstPos = 0; + text.ptr = "\t"; + text.format = XawFmt8Bit; + text.length = 1; + + position = XawTextSourceRead(ctx->text.source, position, + &block, right - left); + ipos = ctx->text.insertPos; + done = zero = False; + if (tab_count) + TAB_SIZE = *char_tabs; + while (!done) { + if (XawTextFormat(ctx, XawFmt8Bit)) { + for (i = 0; i < block.length; i++) { + ++offset; + ++column; + if (tab_count) { + if (column > tab_column + char_tabs[tab_index]) { + TAB_SIZE = tab_index < tab_count - 1 ? char_tabs[tab_index + 1] - char_tabs[tab_index] : *char_tabs; + if (++tab_index >= tab_count) { + tab_column += char_tabs[tab_count - 1]; + tab_index = 0; + } + } + } + if (block.ptr[i] == ' ') { + if (++count > TAB_SIZE) + count %= TAB_SIZE; + if ((tab_count && column == tab_column + char_tabs[tab_index]) || + (!tab_count && column % TAB_SIZE == 0)) { + if (count % (TAB_SIZE + 1) > 1) + break; + else + count = 0; + } + } + else { + if (block.ptr[i] == '\n') { + zero = True; + break; + } + count = 0; + } + } + } + else { + wchar_t *wptr = (wchar_t*)block.ptr; + for (i = 0; i < block.length; i++) { + ++offset; + ++column; + if (tab_count) { + if (column > tab_column + char_tabs[tab_index]) { + TAB_SIZE = tab_index < tab_count - 1 ? char_tabs[tab_index + 1] - char_tabs[tab_index] : *char_tabs; + if (++tab_index >= tab_count) { + tab_column += char_tabs[tab_count - 1]; + tab_index = 0; + } + } + } + if (wptr[i] == _Xaw_atowc(' ')) { + if (++count > TAB_SIZE) + count %= TAB_SIZE; + if ((tab_count && column == tab_column + char_tabs[tab_index]) || + (!tab_count && column % TAB_SIZE == 0)) { + if (count % (TAB_SIZE + 1) > 1) + break; + else + count = 0; + } + } + else { + if (wptr[i] == _Xaw_atowc('\n')) { + zero = True; + break; + } + count = 0; + } + } + } + count %= TAB_SIZE + 1; + if (!zero && count > 1 && i < block.length) { + CHECK_SAVE(); + if (_XawTextReplace(ctx, tmp + i - count + 1, tmp + i + 1, &text)) + return (False); + right -= count - 1; + offset -= count - 1; + if (num_pos) { + for (cpos = 0; cpos < num_pos; cpos++) { + if (tmp + i - count + 1 < pos[cpos]) { + if (tmp + i + 1 < pos[cpos]) + pos[cpos] -= count; + else + pos[cpos] = tmp + i - count + 1; + ++pos[cpos]; + } + } + } + else { + if (tmp + i - count + 1 < ipos) { + if (tmp + i + 1 < ipos) + ipos -= count; + else + ipos = tmp + i - count + 1; + ++ipos; + } + } + } + if (count) + --count; + if (zero) { + count = column = 0; + zero = False; + if (tab_count) { + tab_column = tab_index = 0; + TAB_SIZE = *char_tabs; + } + } + else if (i < block.length) + count = 0; + tmp = left + offset; + position = XawTextSourceRead(ctx->text.source, tmp, + &block, right - tmp); + if (tmp == position || tmp >= right) + done = True; + } + if (!num_pos) + ctx->text.insertPos = ipos; + + return (True); } -void -_XawTextZapSelection(ctx, event, kill) -TextWidget ctx; -XEvent* event; -Boolean kill; +static Bool +Untabify(TextWidget ctx, XawTextPosition left, XawTextPosition right, + XawTextPosition *pos, int num_pos, XawTextBlock *save) { - StartAction(ctx, event); - _DeleteOrKill(ctx, ctx->text.s.left, ctx->text.s.right, kill); - _XawTextSetScrollBars(ctx); - EndAction(ctx); + Bool done, zero; + int i, cpos, count = 0, diff = 0; + XawTextBlock block, text; + XawTextPosition ipos, position = left, tmp = left; + TextSinkObject sink = (TextSinkObject)ctx->text.sink; + short *char_tabs = sink->text_sink.char_tabs; + int tab_count = sink->text_sink.tab_count; + int tab_index = 0, tab_column = 0, tab_base = 0; + static char *tabs = " "; + + text.firstPos = 0; + text.format = XawFmt8Bit; + text.ptr = tabs; + + position = XawTextSourceRead(ctx->text.source, position, + &block, right - left); + ipos = ctx->text.insertPos; + done = False; + zero = False; + while (!done) { + if (XawTextFormat(ctx, XawFmt8Bit)) + for (i = 0; i < block.length; i++) { + if (block.ptr[i] != '\t') { + ++count; + if (block.ptr[i] == '\n') { + zero = True; + break; + } + } + else + break; + } + else { + wchar_t *wptr = (wchar_t*)block.ptr; + for (i = 0; i < block.length; i++) + if (wptr[i] != _Xaw_atowc('\t')) { + ++count; + if (wptr[i] != _Xaw_atowc('\n')) { + zero = True; + break; + } + } + else + break; + } + if (!zero && i < block.length) { + if (tab_count) { + while (tab_base + tab_column <= count) { + for (; tab_index < tab_count; ++tab_index) + if (tab_base + char_tabs[tab_index] > count) { + tab_column = char_tabs[tab_index]; + break; + } + if (tab_index >= tab_count) { + tab_base += char_tabs[tab_count - 1]; + tab_column = tab_index = 0; + } + } + text.length = (tab_base + tab_column) - count; + if (text.length > 8) { + int j; + + text.ptr = XtMalloc(text.length); + for (j = 0; j < text.length; j++) + text.ptr[j] = ' '; + } + else + text.ptr = tabs; + } + else + text.length = DEFAULT_TAB_SIZE - (count % DEFAULT_TAB_SIZE); + CHECK_SAVE(); + if (_XawTextReplace(ctx, tmp + i, tmp + i + 1, &text)) { + if (tab_count && text.length > 8) + XtFree(text.ptr); + return (False); + } + if (tab_count && text.length > 8) + XtFree(text.ptr); + count += text.length; + right += text.length - 1; + if (num_pos) { + for (cpos = 0; cpos < num_pos; cpos++) { + if (tmp + i < pos[cpos]) { + if (tmp + i + 1 < pos[cpos]) + --pos[cpos]; + else + pos[cpos] = tmp + i; + pos[cpos] += text.length; + } + } + } + else { + if (tmp + i < ipos) { + if (tmp + i + 1 < ipos) + --ipos; + else + ipos = tmp + i; + ipos += text.length; + } + } + } + tmp = left + count + diff; + if (zero) { + diff += count; + count = 0; + zero = False; + if (tab_count) + tab_base = tab_column = tab_index = 0; + } + position = XawTextSourceRead(ctx->text.source, tmp, + &block, right - tmp); + if (tmp == position || tmp >= right) + done = True; + } + if (!num_pos) + ctx->text.insertPos = ipos; + + return (True); } +static int +FormatText(TextWidget ctx, XawTextPosition left, Bool force, + XawTextPosition *pos, int num_pos) +{ + char *ptr = NULL; + Bool freepos = False, undo, paragraph = pos != NULL; + int i, result; + XawTextBlock block, *text; + XawTextPosition end = ctx->text.lastPos, buf[32]; + TextSrcObject src = (TextSrcObject)ctx->text.source; + XawTextPosition right = SrcScan(ctx->text.source, left, XawstEOL, + XawsdRight, 1, False); + + undo = src->textSrc.enable_undo && src->textSrc.undo_state == False; + if (undo) { + if (!pos) { + num_pos = src->textSrc.num_text; + pos = XawStackAlloc(sizeof(XawTextPosition) * num_pos, buf); + for (i = 0; i < num_pos; i++) + pos[i] = ((TextWidget)src->textSrc.text[i])->text.insertPos; + freepos = True; + } + else + freepos = False; + src->textSrc.undo_state = True; + block.ptr = NULL; + block.firstPos = left; + block.length = right - left; + text = █ + } + else + text = NULL; + + result = DoFormatText(ctx, left, force, 1, text, pos, num_pos, paragraph); + if (undo && result == XawEditDone && block.ptr) { + char *lbuf, *rbuf; + unsigned llen, rlen, size; + + ptr = lbuf = block.ptr; + llen = block.length; + rlen = llen + (ctx->text.lastPos - end); + + block.firstPos = 0; + block.format = _XawTextFormat(ctx); + + rbuf = _XawTextGetText(ctx, left, left + rlen); + + size = XawTextFormat(ctx, XawFmtWide) ? sizeof(wchar_t) : sizeof(char); + if (llen != rlen || memcmp(lbuf, rbuf, llen * size)) { + block.ptr = lbuf; + block.length = llen; + _XawTextReplace(ctx, left, left + rlen, &block); + + src->textSrc.undo_state = False; + block.ptr = rbuf; + block.length = rlen; + _XawTextReplace(ctx, left, left + llen, &block); + } + else + src->textSrc.undo_state = False; + XtFree(rbuf); + } + if (undo) { + src->textSrc.undo_state = False; + if (freepos) { + for (i = 0; i < num_pos; i++) { + TextWidget tw = (TextWidget)src->textSrc.text[i]; + tw->text.insertPos = XawMin(XawMax(0, pos[i]), tw->text.lastPos); + } + XawStackFree(pos, buf); + } + if (ptr) + XtFree(ptr); + } + + return (result); +} + +static int +DoFormatText(TextWidget ctx, XawTextPosition left, Bool force, int level, + XawTextBlock *save, XawTextPosition *pos, int num_pos, + Bool paragraph) +{ + XawTextPosition right = SrcScan(ctx->text.source, left, XawstEOL, + XawsdRight, 1, False); + XawTextPosition position, tmp, ipos; + XawTextBlock block, text; + char buf[128]; + wchar_t *wptr; + int i, count, cpos; + Bool done, force2 = force, recurse = False; + + position = XawTextSourceRead(ctx->text.source, left, &block, right - left); + if (block.length == 0 || left >= right || + (level == 1 && ((XawTextFormat(ctx, XawFmt8Bit) && + block.ptr[0] != ' ' && + block.ptr[0] != '\t' && + !isalnum(*(unsigned char*)block.ptr)) || + (XawTextFormat(ctx, XawFmtWide) && + _Xaw_atowc(XawSP) != *(wchar_t*)block.ptr && + _Xaw_atowc(XawTAB) != *(wchar_t*)block.ptr && + !iswalnum(*(wchar_t*)block.ptr))))) + return (XawEditDone); + + if (level == 1 && !paragraph) { + tmp = ctx->text.lastPos; + if (Untabify(ctx, left, right, pos, num_pos, save) == False) + return (XawEditError); + right += ctx->text.lastPos - tmp; + position = XawTextSourceRead(ctx->text.source, left, &block, + right - left); + } + + text.firstPos = 0; + text.format = XawFmt8Bit; + + ipos = ctx->text.insertPos; + count = 0; + done = False; + while (!done) { + if (XawTextFormat(ctx, XawFmt8Bit)) { + for (i = 0; i < block.length; i++) + if (block.ptr[i] == ' ') + ++count; + else { + done = True; + break; + } + } + else { + wptr = (wchar_t*)block.ptr; + for (i = 0; i < block.length; i++) + if (wptr[i] == _Xaw_atowc(' ')) + ++count; + else { + done = True; + break; + } + } + tmp = position; + position = XawTextSourceRead(ctx->text.source, position, + &block, right - position); + if (tmp == position) + done = True; + } + position = left + count; + if (count < ctx->text.left_column) { + int bytes = ctx->text.left_column - count; + + text.ptr = XawStackAlloc(bytes, buf); + text.length = bytes; + for (i = 0; i < bytes; i++) + text.ptr[i] = ' '; + CHECK_SAVE(); + if (_XawTextReplace(ctx, left, left, &text)) { + XawStackFree(text.ptr, buf); + return (XawEditError); + } + XawStackFree(text.ptr, buf); + right += bytes; + if (num_pos) { + for (cpos = 0; cpos < num_pos; cpos++) + if (pos[cpos] >= left) + pos[cpos] += bytes; + } + if (ipos >= left) + ipos += bytes; + count += bytes; + } + + done = False; + if (!paragraph && level == 1 + && ipos <= right && ipos - left > ctx->text.right_column) { + XawTextPosition len = ctx->text.lastPos; + int skip = ctx->text.justify == XawjustifyRight + || ctx->text.justify == XawjustifyCenter ? + ctx->text.left_column : count; + + if (pos) + for (i = 0; i < num_pos; i++) + if (pos[i] == ipos) + break; + + StripSpaces(ctx, left + skip, right, pos, num_pos, save); + right += ctx->text.lastPos - len; + if (pos && i < num_pos) + ipos = pos[i]; + else + ipos = ctx->text.insertPos; + done = ipos - left > ctx->text.right_column; + count = skip + (count == skip + 1); + } + if ((paragraph || done) && right - left > ctx->text.right_column) { + position = tmp = right; + XawTextSourceRead(ctx->text.source, position - 1, &block, 1); + if (block.length && + ((XawTextFormat(ctx, XawFmt8Bit) && + block.ptr[0] == ' ') || + (XawTextFormat(ctx, XawFmtWide) && + _Xaw_atowc(XawSP) == *(wchar_t*)block.ptr))) + --position; + while (position - left > ctx->text.right_column) { + tmp = position; + position = SrcScan(ctx->text.source, position, + XawstWhiteSpace, XawsdLeft, 1, True); + } + if (position <= left + ctx->text.left_column) + position = tmp; + if (position > left && position - left > ctx->text.left_column + && position != right) { + text.ptr = "\n"; + text.length = 1; + CHECK_SAVE(); + if (_XawTextReplace(ctx, position, position + 1, &text)) + return (XawEditError); + right = position; + recurse = True; + force = True; + } + } + + if (force) { + if (ctx->text.justify == XawjustifyCenter) + count = ctx->text.right_column - (count - ctx->text.left_column); + else + count = ctx->text.right_column; + if (count > right - left) + count -= right - left; + else + count = 0; + } + else + count = 0; + if (count > 0) { + switch (ctx->text.justify) { + case XawjustifyLeft: + break; + case XawjustifyRight: + case XawjustifyCenter: + if (ctx->text.justify == XawjustifyCenter) { + int alnum = 0; + + if (!(count & 1)) { + XawTextSourceRead(ctx->text.source, right, &block, 1); + if ((XawTextFormat(ctx, XawFmt8Bit) + && isalnum(*(unsigned char*)block.ptr)) || + (XawTextFormat(ctx, XawFmtWide) + && iswalnum(*(wchar_t*)block.ptr))) + alnum = 1; + } + count = (count + alnum) >> 1; + } + text.ptr = XawStackAlloc(count, buf); + text.length = count; + for (i = 0; i < count; i++) + text.ptr[i] = ' '; + CHECK_SAVE(); + if (_XawTextReplace(ctx, left, left, &text)) { + XawStackFree(text.ptr, buf); + return (XawEditError); + } + XawStackFree(text.ptr, buf); + position += count; + right += count; + if (num_pos) { + for (cpos = 0; cpos < num_pos; cpos++) + if (pos[cpos] > left) + pos[cpos] += count; + } + else if (ipos > left) + ipos += count; + break; + case XawjustifyFull: + i = 0; + tmp = left; + /*CONSTCOND*/ + while (True) { + tmp = SrcScan(ctx->text.source, tmp, XawstWhiteSpace, + XawsdRight, 1, True); + if (tmp < right) + ++i; + else + break; + } + if (i) { + double inc, ii; + int bytes, steps; + + bytes = count; + inc = ii = (count + .5) / (double)i; + + steps = count; + text.ptr = XawStackAlloc(steps, buf); + for (i = 0; i < steps; i++) + text.ptr[i] = ' '; + tmp = left; + CHECK_SAVE(); + while (bytes) { + steps = 1; + while (inc + ii < 1) { + ++steps; + inc += ii; + } + tmp = SrcScan(ctx->text.source, tmp, XawstWhiteSpace, + XawsdRight, steps, True); + if (bytes > inc) + text.length = (int)inc; + else + text.length = bytes; + bytes -= text.length; + if (_XawTextReplace(ctx, tmp, tmp, &text)) { + XawStackFree(buf, text.ptr); + return (XawEditError); + } + if (num_pos) { + for (cpos = 0; cpos < num_pos; cpos++) + if (tmp <= pos[cpos]) + pos[cpos] += text.length; + } + else if (tmp <= ipos) + ipos += text.length; + inc -= (int)inc; + inc += ii; + } + position += count; + right += count; + XawStackFree(buf, text.ptr); + } + break; + } + } + + if (!num_pos) + ctx->text.insertPos = XawMin(ipos, ctx->text.lastPos); + + return (recurse ? DoFormatText(ctx, position + 1, + ctx->text.justify != XawjustifyFull + && (force2 || paragraph), + ++level, save, pos, num_pos, paragraph) + : XawEditDone); +} +#undef CHECK_SAVE + /*ARGSUSED*/ -static void -KillCurrentSelection(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +Indent(Widget w, XEvent *event, String *params, Cardinal *num_params) { - _XawTextZapSelection( (TextWidget) w, event, TRUE); + TextWidget ctx = (TextWidget)w; + TextSrcObject src = (TextSrcObject)ctx->text.source; + XawTextPosition from, to, tmp, end = 0, *pos, *posbuf[32]; + char buf[32]; + XawTextBlock text; + int i, spaces = MULT(ctx); + char *lbuf = NULL, *rbuf; + unsigned llen = 0, rlen, size; + Bool undo = src->textSrc.enable_undo && src->textSrc.undo_state == False; + Bool format = ctx->text.auto_fill + && ctx->text.left_column < ctx->text.right_column; + + text.firstPos = 0; + text.format = XawFmt8Bit; + text.ptr = ""; + + StartAction(ctx, event); + + pos = XawStackAlloc(sizeof(XawTextPosition) * src->textSrc.num_text, posbuf); + for (i = 0; i < src->textSrc.num_text; i++) + pos[i] = ((TextWidget)src->textSrc.text[i])->text.insertPos; + + if (!GetBlockBoundaries(ctx, &from, &to)) { + EndAction(ctx); + XawStackFree(pos, posbuf); + return; + } + + if (undo) { + llen = to - from; + end = ctx->text.lastPos; + lbuf = _XawTextGetText(ctx, from, to); + src->textSrc.undo_state = True; + } + + tmp = ctx->text.lastPos; + if (!Untabify(ctx, from, to, pos, src->textSrc.num_text, NULL)) { + XBell(XtDisplay(ctx), 0); + EndAction(ctx); + XawStackFree(pos, posbuf); + if (undo) { + src->textSrc.undo_state = True; + XtFree(lbuf); + } + return; + } + to += ctx->text.lastPos - tmp; + + tmp = from; + + if (spaces > 0) { + text.ptr = XawStackAlloc(spaces, buf); + for (i = 0; i < spaces; i++) + text.ptr[i] = ' '; + + text.length = spaces; + while (tmp < to) { + _XawTextReplace(ctx, tmp, tmp, &text); + + for (i = 0; i < src->textSrc.num_text; i++) + if (tmp < pos[i]) + pos[i] += spaces; + + to += spaces; + tmp = SrcScan(ctx->text.source, tmp, XawstEOL, XawsdRight, 1, True); + } + XawStackFree(text.ptr, buf); + } + else { + int min = 32767; + + text.length = 0; + tmp = from; + + /* find the amount of spaces to cut */ + while (tmp < to) { + (void)BlankLine(w, tmp, &i); + if (i < min) + min = i; + tmp = SrcScan(ctx->text.source, tmp, XawstEOL, XawsdRight, 1, True); + } + spaces = XawMin(-spaces, min); + + /* cut the spaces */ + tmp = from; + while (tmp < to) { + _XawTextReplace(ctx, tmp, tmp + spaces, &text); + + for (i = 0; i < src->textSrc.num_text; i++) + if (tmp < pos[i]) { + if (tmp + spaces < pos[i]) + pos[i] -= spaces; + else + pos[i] = tmp; + } + + to -= spaces; + tmp = SrcScan(ctx->text.source, tmp, XawstEOL, XawsdRight, 1, True); + } + } + + if (!format) + Tabify(ctx, from, to, pos, src->textSrc.num_text, NULL); + + if (undo) { + rlen = llen + (ctx->text.lastPos - end); + rbuf = _XawTextGetText(ctx, from, from + rlen); + + text.format = _XawTextFormat(ctx); + size = XawTextFormat(ctx, XawFmtWide) ? sizeof(wchar_t) : sizeof(char); + if (llen != rlen || memcmp(lbuf, rbuf, llen * size)) { + text.ptr = lbuf; + text.length = llen; + _XawTextReplace(ctx, from, from + rlen, &text); + + src->textSrc.undo_state = False; + text.ptr = rbuf; + text.length = rlen; + _XawTextReplace(ctx, from, from + llen, &text); + } + else + src->textSrc.undo_state = False; + XtFree(lbuf); + XtFree(rbuf); + } + + for (i = 0; i < src->textSrc.num_text; i++) { + TextWidget tw = (TextWidget)src->textSrc.text[i]; + + tw->text.insertPos = XawMin(XawMax(0, pos[i]), tw->text.lastPos); + } + XawStackFree(pos, posbuf); + ctx->text.showposition = True; + + EndAction(ctx); } /*ARGSUSED*/ -static void -DeleteCurrentSelection(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +ToggleOverwrite(Widget w, XEvent *event, String *params, Cardinal *num_params) { - _XawTextZapSelection( (TextWidget) w, event, FALSE); + TextWidget ctx = (TextWidget)w; + + ctx->text.overwrite = !ctx->text.overwrite; + + /* call information callback */ + _XawTextSetLineAndColumnNumber(ctx, True); } +#endif /* OLDXAW */ -/************************************************************ - * - * Insertion Routines. - * - ************************************************************/ - -static int -InsertNewLineAndBackupInternal(ctx) -TextWidget ctx; -{ - int count, error = XawEditDone; - XawTextBlock text; - - text.format = _XawTextFormat(ctx); - text.length = ctx->text.mult; - text.firstPos = 0; - - if ( text.format == XawFmtWide ) { - wchar_t* wptr; - text.ptr = XtMalloc(sizeof(wchar_t) * ctx->text.mult); - wptr = (wchar_t *)text.ptr; - for (count = 0; count < ctx->text.mult; count++ ) - wptr[count] = _Xaw_atowc(XawLF); - } - else { - text.ptr = XtMalloc(sizeof(char) * ctx->text.mult); - for (count = 0; count < ctx->text.mult; count++ ) - text.ptr[count] = XawLF; - } - - if (_XawTextReplace(ctx, ctx->text.insertPos, ctx->text.insertPos, &text)) { - XBell( XtDisplay(ctx), 50); - error = XawEditError; - } - else - ctx->text.showposition = TRUE; +/* + * Insertion Routines + */ +static int +InsertNewLineAndBackupInternal(TextWidget ctx) +{ + int count, error = XawEditDone, mult = MULT(ctx); + XawTextPosition position; + XawTextBlock text; + char buf[32]; + + if (mult < 0) { + ctx->text.mult = 1; + return (XawEditError); + } + + text.format = _XawTextFormat(ctx); + text.length = mult; + text.firstPos = 0; + + if (text.format == XawFmtWide) { + wchar_t *wptr; + + text.ptr = XawStackAlloc(sizeof(wchar_t) * mult, buf); + wptr = (wchar_t *)text.ptr; + for (count = 0; count < mult; count++) + wptr[count] = _Xaw_atowc(XawLF); + } + else { + text.ptr = XawStackAlloc(sizeof(char) * mult, buf); + for (count = 0; count < mult; count++) + text.ptr[count] = XawLF; + } + + position = SrcScan(ctx->text.source, ctx->text.insertPos, + XawstEOL, XawsdLeft, 1, False); + if (_XawTextReplace(ctx, ctx->text.insertPos, ctx->text.insertPos, &text)) { + XBell( XtDisplay(ctx), 50); + error = XawEditError; + } + else { + ctx->text.showposition = TRUE; + ctx->text.insertPos += text.length; + } + + XawStackFree(text.ptr, buf); + +#ifndef OLDXAW + if (ctx->text.auto_fill && error == XawEditDone) + (void)FormatText(ctx, position, ctx->text.justify != XawjustifyFull, + NULL, 0); +#endif - XtFree( text.ptr ); - return( error ); + return (error); } /*ARGSUSED*/ -static void -InsertNewLineAndBackup(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +static void +InsertNewLineAndBackup(Widget w, XEvent *event, String *p, Cardinal *n) { - StartAction( (TextWidget) w, event ); - (void) InsertNewLineAndBackupInternal( (TextWidget) w ); - _XawTextSetScrollBars( (TextWidget) w); - EndAction( (TextWidget) w ); + TextWidget ctx = (TextWidget)w; + XawTextPosition insertPos = ctx->text.insertPos; + + StartAction((TextWidget)w, event); + (void)InsertNewLineAndBackupInternal(ctx); + ctx->text.insertPos = SrcScan(ctx->text.source, insertPos, XawstEOL, + XawsdRight, 1, False); + EndAction((TextWidget)w); } static int -LocalInsertNewLine(ctx, event) - TextWidget ctx; - XEvent* event; +LocalInsertNewLine(TextWidget ctx, XEvent *event) { - StartAction(ctx, event); - if (InsertNewLineAndBackupInternal(ctx) == XawEditError) - return(XawEditError); - ctx->text.insertPos = SrcScan(ctx->text.source, ctx->text.insertPos, - XawstPositions, XawsdRight, ctx->text.mult, TRUE); - _XawTextSetScrollBars(ctx); - EndAction(ctx); - return(XawEditDone); + int error; + + StartAction(ctx, event); + error = InsertNewLineAndBackupInternal(ctx); + ctx->text.from_left = -1; + EndAction(ctx); + + return (error); } /*ARGSUSED*/ static void -InsertNewLine(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +InsertNewLine(Widget w, XEvent *event, String *p, Cardinal *n) { - (void) LocalInsertNewLine( (TextWidget) w, event); + (void)LocalInsertNewLine((TextWidget)w, event); } /*ARGSUSED*/ -static void -InsertNewLineAndIndent(w, event, p, n) -Widget w; -XEvent *event; -String *p; -Cardinal *n; -{ - XawTextBlock text; - XawTextPosition pos1; - int length; - TextWidget ctx = (TextWidget) w; - String line_to_ip; - - StartAction(ctx, event); - pos1 = SrcScan(ctx->text.source, ctx->text.insertPos, - XawstEOL, XawsdLeft, 1, FALSE); - - line_to_ip = _XawTextGetText(ctx, pos1, ctx->text.insertPos); - - text.format = _XawTextFormat(ctx); - text.firstPos = 0; - - if ( text.format == XawFmtWide ) { - wchar_t* ptr; - text.ptr = XtMalloc( ( 2 + wcslen((wchar_t*)line_to_ip) ) * sizeof(wchar_t) ); - - ptr = (wchar_t*)text.ptr; - ptr[0] = _Xaw_atowc( XawLF ); - wcscpy( (wchar_t*) ++ptr, (wchar_t*) line_to_ip ); - - length = wcslen((wchar_t*)text.ptr); - while ( length && ( iswspace(*ptr) || ( *ptr == _Xaw_atowc(XawTAB) ) ) ) - ptr++, length--; - *ptr = (wchar_t)0; - text.length = wcslen((wchar_t*)text.ptr); - - } else { - char *ptr; - length = strlen(line_to_ip); - text.ptr = XtMalloc( ( 2 + length ) * sizeof( char ) ); - ptr = text.ptr; - ptr[0] = XawLF; - strcpy( ++ptr, line_to_ip ); - - length++; - while ( length && ( isspace(*ptr) || ( *ptr == XawTAB ) ) ) - ptr++, length--; - *ptr = '\0'; - text.length = strlen(text.ptr); - } - XtFree( line_to_ip ); - - if (_XawTextReplace(ctx,ctx->text.insertPos, ctx->text.insertPos, &text)) { - XBell(XtDisplay(ctx), 50); +static void +InsertNewLineAndIndent(Widget w, XEvent *event, String *p, Cardinal *n) +{ + XawTextBlock text; + XawTextPosition pos1; + int length; + TextWidget ctx = (TextWidget)w; + String line_to_ip; + + StartAction(ctx, event); + pos1 = SrcScan(ctx->text.source, ctx->text.insertPos, + XawstEOL, XawsdLeft, 1, False); + + line_to_ip = _XawTextGetText(ctx, pos1, ctx->text.insertPos); + + text.format = _XawTextFormat(ctx); + text.firstPos = 0; + + if (text.format == XawFmtWide) { + wchar_t *ptr; + + text.ptr = XtMalloc((2 + wcslen((wchar_t*)line_to_ip)) + * sizeof(wchar_t)); + ptr = (wchar_t*)text.ptr; + ptr[0] = _Xaw_atowc(XawLF); + wcscpy((wchar_t*)++ptr, (wchar_t*)line_to_ip); + + length = wcslen((wchar_t*)text.ptr); + while (length && (iswspace(*ptr) || *ptr == _Xaw_atowc(XawTAB))) + ptr++, length--; + *ptr = (wchar_t)0; + text.length = wcslen((wchar_t*)text.ptr); + } + else { + char *ptr; + + length = strlen(line_to_ip); + text.ptr = XtMalloc((2 + length) * sizeof(char)); + ptr = text.ptr; + ptr[0] = XawLF; + strcpy(++ptr, line_to_ip); + + length++; + while (length && (isspace(*ptr) || (*ptr == XawTAB))) + ptr++, length--; + *ptr = '\0'; + text.length = strlen(text.ptr); + } + XtFree(line_to_ip); + + if (_XawTextReplace(ctx,ctx->text.insertPos, ctx->text.insertPos, &text)) { + XBell(XtDisplay(ctx), 50); + XtFree(text.ptr); + EndAction(ctx); + return; + } + XtFree(text.ptr); + ctx->text.from_left = -1; + ctx->text.insertPos = SrcScan(ctx->text.source, ctx->text.old_insert, + XawstPositions, XawsdRight, text.length, True); EndAction(ctx); - return; - } - XtFree(text.ptr); - ctx->text.insertPos = SrcScan(ctx->text.source, ctx->text.insertPos, - XawstPositions, XawsdRight, text.length, TRUE); - _XawTextSetScrollBars(ctx); - EndAction(ctx); } -/************************************************************ - * - * Selection Routines. - * - *************************************************************/ - -static void -SelectWord(w, event, params, num_params) -Widget w; -XEvent* event; -String* params; -Cardinal* num_params; +/* + * Selection Routines + */ +static void +SelectWord(Widget w, XEvent *event, String *params, Cardinal *num_params) { - TextWidget ctx = (TextWidget) w; - XawTextPosition l, r; - - StartAction(ctx, event); - l = SrcScan(ctx->text.source, ctx->text.insertPos, - XawstWhiteSpace, XawsdLeft, 1, FALSE); - r = SrcScan(ctx->text.source, l, XawstWhiteSpace, XawsdRight, 1, FALSE); - _XawTextSetSelection(ctx, l, r, params, *num_params); - EndAction(ctx); + TextWidget ctx = (TextWidget)w; + XawTextPosition l, r; + + StartAction(ctx, event); + l = SrcScan(ctx->text.source, ctx->text.insertPos, + XawstWhiteSpace, XawsdLeft, 1, False); + r = SrcScan(ctx->text.source, l, XawstWhiteSpace, XawsdRight, 1, False); + _XawTextSetSelection(ctx, l, r, params, *num_params); + EndAction(ctx); } -static void -SelectAll(w, event, params, num_params) -Widget w; -XEvent* event; -String* params; -Cardinal* num_params; +static void +SelectAll(Widget w, XEvent *event, String *params, Cardinal *num_params) { - TextWidget ctx = (TextWidget) w; + TextWidget ctx = (TextWidget)w; - StartAction(ctx, event); - _XawTextSetSelection(ctx,zeroPosition,ctx->text.lastPos,params,*num_params); - EndAction(ctx); + StartAction(ctx, event); + _XawTextSetSelection(ctx,zeroPosition,ctx->text.lastPos,params,*num_params); + EndAction(ctx); } static void -ModifySelection(ctx, event, mode, action, params, num_params) -TextWidget ctx; -XEvent* event; -XawTextSelectionMode mode; -XawTextSelectionAction action; -String* params; /* unused */ -Cardinal* num_params; /* unused */ +ModifySelection(TextWidget ctx, XEvent *event, + XawTextSelectionMode mode, + XawTextSelectionAction action, + String *params, Cardinal *num_params) { - StartAction(ctx, event); - NotePosition(ctx, event); - _XawTextAlterSelection(ctx, mode, action, params, num_params); - EndAction(ctx); +#ifndef OLDXAW + int old_y = ctx->text.ev_y; +#endif + + StartAction(ctx, event); + NotePosition(ctx, event); + +#ifndef OLDXAW + if (event->type == MotionNotify) { + if (ctx->text.ev_y <= ctx->text.margin.top) { + if (old_y >= ctx->text.ev_y) + XawTextScroll(ctx, -1, 0); + } + else if (ctx->text.ev_y >= XtHeight(ctx) - ctx->text.margin.bottom) { + if (old_y <= ctx->text.ev_y + && !IsPositionVisible(ctx, ctx->text.lastPos)) + XawTextScroll(ctx, 1, 0); + } + } +#endif + ctx->text.from_left = -1; + _XawTextAlterSelection(ctx, mode, action, params, num_params); + + EndAction(ctx); } - -/* ARGSUSED */ -static void -SelectStart(w, event, params, num_params) -Widget w; -XEvent* event; -String* params; /* unused */ -Cardinal* num_params; /* unused */ + +static void +SelectStart(Widget w, XEvent *event, String *params, Cardinal *num_params) { - ModifySelection((TextWidget) w, event, - XawsmTextSelect, XawactionStart, params, num_params); + TextWidget ctx = (TextWidget)w; + +#ifndef OLDXAW + if (!ctx->text.selection_state) { + ctx->text.selection_state = True; +#endif + ModifySelection(ctx, event, + XawsmTextSelect, XawactionStart, params, num_params); +#ifndef OLDXAW + } +#endif } -/* ARGSUSED */ -static void -SelectAdjust(w, event, params, num_params) -Widget w; -XEvent* event; -String* params; /* unused */ -Cardinal* num_params; /* unused */ +static void +SelectAdjust(Widget w, XEvent *event, String *params, Cardinal *num_params) { - ModifySelection((TextWidget) w, event, - XawsmTextSelect, XawactionAdjust, params, num_params); + TextWidget ctx = (TextWidget)w; + +#ifndef OLDXAW + if (ctx->text.selection_state) +#endif + ModifySelection(ctx, event, + XawsmTextSelect, XawactionAdjust, params, num_params); } -static void -SelectEnd(w, event, params, num_params) -Widget w; -XEvent* event; -String* params; -Cardinal* num_params; +static void +SelectEnd(Widget w, XEvent *event, String *params, Cardinal *num_params) { - ModifySelection((TextWidget) w, event, - XawsmTextSelect, XawactionEnd, params, num_params); + TextWidget ctx = (TextWidget)w; + +#ifndef OLDXAW + if (ctx->text.selection_state) { + ctx->text.selection_state = False; +#endif + ModifySelection(ctx, event, + XawsmTextSelect, XawactionEnd, params, num_params); +#ifndef OLDXAW + } +#endif } -/* ARGSUSED */ -static void -ExtendStart(w, event, params, num_params) -Widget w; -XEvent* event; -String* params; /* unused */ -Cardinal* num_params; /* unused */ +static void +ExtendStart(Widget w, XEvent *event, String *params, Cardinal *num_params) { - ModifySelection((TextWidget) w, event, - XawsmTextExtend, XawactionStart, params, num_params); + TextWidget ctx = (TextWidget)w; + +#ifndef OLDXAW + if (!ctx->text.selection_state) { + ctx->text.selection_state = True; +#endif + ModifySelection(ctx, event, + XawsmTextExtend, XawactionStart, params, num_params); +#ifndef OLDXAW + } +#endif } -/* ARGSUSED */ -static void -ExtendAdjust(w, event, params, num_params) -Widget w; -XEvent* event; -String* params; /* unused */ -Cardinal* num_params; /* unused */ +static void +ExtendAdjust(Widget w, XEvent *event, String *params, Cardinal *num_params) { - ModifySelection((TextWidget) w, event, - XawsmTextExtend, XawactionAdjust, params, num_params); + TextWidget ctx = (TextWidget)w; + +#ifndef OLDXAW + if (ctx->text.selection_state) +#endif + ModifySelection(ctx, event, + XawsmTextExtend, XawactionAdjust, params, num_params); } -static void -ExtendEnd(w, event, params, num_params) -Widget w; -XEvent* event; -String* params; -Cardinal* num_params; +static void +ExtendEnd(Widget w, XEvent *event, String *params, Cardinal *num_params) { - ModifySelection((TextWidget) w, event, - XawsmTextExtend, XawactionEnd, params, num_params); + TextWidget ctx = (TextWidget)w; + +#ifndef OLDXAW + if (ctx->text.selection_state) { + ctx->text.selection_state = False; +#endif + ModifySelection(ctx, event, + XawsmTextExtend, XawactionEnd, params, num_params); +#ifndef OLDXAW + } +#endif } static void -SelectSave(w, event, params, num_params) -Widget w; -XEvent* event; -String* params; -Cardinal* num_params; +SelectSave(Widget w, XEvent *event, String *params, Cardinal *num_params) { - int num_atoms; - Atom* sel; - Display* dpy = XtDisplay(w); - Atom selections[256]; + int num_atoms; + Atom *sel; + Display *dpy = XtDisplay(w); + Atom selections[256]; - StartAction( (TextWidget) w, event ); + StartAction((TextWidget)w, event); num_atoms = *num_params; if (num_atoms > 256) num_atoms = 256; for (sel=selections; --num_atoms >= 0; sel++, params++) *sel = XInternAtom(dpy, *params, False); num_atoms = *num_params; - _XawTextSaltAwaySelection( (TextWidget) w, selections, num_atoms ); - EndAction( (TextWidget) w ); + _XawTextSaltAwaySelection((TextWidget)w, selections, num_atoms); + EndAction((TextWidget)w); } -/************************************************************ - * - * Misc. Routines. - * - ************************************************************/ +/* + * Misc. Routines + */ +/*ARGSUSED*/ +static void +SetKeyboardFocus(Widget w, XEvent *event, String *params, Cardinal *num_params) +{ + Widget shell, parent; + + shell = parent = w; + while (parent) { + if (XtIsShell(shell = parent)) + break; + parent = XtParent(parent); + } + XtSetKeyboardFocus(shell, w); +} + +/*ARGSUSED*/ +static void +RedrawDisplay(Widget w, XEvent *event, String *p, Cardinal *n) +{ + StartAction((TextWidget)w, event); + _XawTextClearAndCenterDisplay((TextWidget)w); + EndAction((TextWidget)w); +} -/* ARGSUSED */ -static void -RedrawDisplay(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +/* This is kind of a hack, but, only one text widget can have focus at + * a time on one display. There is a problem in the implementation of the + * text widget, the scrollbars can not be adressed via editres, since they + * are not children of a subclass of composite. + * The focus variable is required to make sure only one text window will + * show a block cursor at one time. + */ +struct _focus { Display *display; Widget widget; }; +static struct _focus *focus; +static Cardinal num_focus; + +/*ARGSUSED*/ +static void +DestroyFocusCallback(Widget w, XtPointer user_data, XtPointer call_data) { - StartAction( (TextWidget) w, event); - _XawTextClearAndCenterDisplay((TextWidget) w); - EndAction( (TextWidget) w); + struct _focus *f = (struct _focus*)(user_data); + + if (f->widget == w) + f->widget = NULL; } /*ARGSUSED*/ static void -TextFocusIn (w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +TextFocusIn(Widget w, XEvent *event, String *p, Cardinal *n) { - TextWidget ctx = (TextWidget) w; + TextWidget ctx = (TextWidget)w; + Bool display_caret = ctx->text.display_caret; + int i; + + if (event->xfocus.detail == NotifyPointer) + return; - /* Let the input method know focus has arrived. */ - _XawImSetFocusValues (w, NULL, 0); - if ( event->xfocus.detail == NotifyPointer ) return; + if (event->xfocus.send_event) { + Window root, child; + int rootx, rooty, x, y; + unsigned int mask; - ctx->text.hasfocus = TRUE; + if (ctx->text.hasfocus) + return; + + if (XQueryPointer(XtDisplay(w), XtWindow(w), &root, &child, + &rootx, &rooty, &x, &y, &mask)) { + if (child) + return; + } + } + + /* Let the input method know focus has arrived. */ + _XawImSetFocusValues(w, NULL, 0); + + if (display_caret) + StartAction(ctx, event); + ctx->text.hasfocus = TRUE; + if (display_caret) + EndAction(ctx); + + for (i = 0; i < num_focus; i++) + if (focus[i].display == XtDisplay(w)) + break; + if (i >= num_focus) { + focus = (struct _focus*) + XtRealloc((XtPointer)focus, sizeof(struct _focus) * (num_focus + 1)); + i = num_focus; + focus[i].widget = NULL; + focus[i].display = XtDisplay(w); + num_focus++; + } + if (focus[i].widget != w) { + Widget old = focus[i].widget; + + focus[i].widget = w; + if (old != NULL) { + TextFocusOut(old, event, p, n); + /* TextFocusOut may set it to NULL */ + focus[i].widget = w; + } + XtAddCallback(w, XtNdestroyCallback, + DestroyFocusCallback, (XtPointer)&focus[i]); + } } /*ARGSUSED*/ static void -TextFocusOut(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; +TextFocusOut(Widget w, XEvent *event, String *p, Cardinal *n) { - TextWidget ctx = (TextWidget) w; + TextWidget ctx = (TextWidget)w; + Bool display_caret = ctx->text.display_caret; + Widget shell; + Window window; + int i, revert; + + shell = w; + while (shell) { + if (XtIsShell(shell)) + break; + shell = XtParent(shell); + } + + for (i = 0; i < num_focus; i++) + if (focus[i].display == XtDisplay(w)) + break; + XGetInputFocus(XtDisplay(w), &window, &revert); + if ((XtWindow(shell) == window && + (i < num_focus && focus[i].widget == w)) + || event->xfocus.detail == NotifyPointer) + return; + + if (i < num_focus && focus[i].widget) { + XtRemoveCallback(focus[i].widget, XtNdestroyCallback, + DestroyFocusCallback, (XtPointer)&focus[i]); + focus[i].widget = NULL; + } + + /* Let the input method know focus has left.*/ + _XawImUnsetFocus(w); - /* Let the input method know focus has left.*/ - _XawImUnsetFocus(w); - if ( event->xfocus.detail == NotifyPointer ) return; - ctx->text.hasfocus = FALSE; + if (display_caret) + StartAction(ctx, event); + ctx->text.hasfocus = FALSE; + if (display_caret) + EndAction(ctx); } /*ARGSUSED*/ static void -TextEnterWindow( w, event, params, num_params ) - Widget w; - XEvent* event; - String* params; - Cardinal* num_params; +TextEnterWindow(Widget w, XEvent *event, String *params, Cardinal *num_params) { - TextWidget ctx = (TextWidget) w; + TextWidget ctx = (TextWidget)w; - if ((event->xcrossing.detail != NotifyInferior) && event->xcrossing.focus && - !ctx->text.hasfocus) { + if ((event->xcrossing.detail != NotifyInferior) && event->xcrossing.focus + && !ctx->text.hasfocus) _XawImSetFocusValues(w, NULL, 0); - } } /*ARGSUSED*/ static void -TextLeaveWindow( w, event, params, num_params ) - Widget w; - XEvent* event; - String* params; - Cardinal* num_params; +TextLeaveWindow(Widget w, XEvent *event, String *params, Cardinal *num_params) { - TextWidget ctx = (TextWidget) w; + TextWidget ctx = (TextWidget)w; - if ((event->xcrossing.detail != NotifyInferior) && event->xcrossing.focus && - !ctx->text.hasfocus) { + if ((event->xcrossing.detail != NotifyInferior) && event->xcrossing.focus + && !ctx->text.hasfocus) _XawImUnsetFocus(w); - } } -static XComposeStatus compose_status = {NULL, 0}; - -/* Function Name: AutoFill - * Description: Breaks the line at the previous word boundry when - * called inside InsertChar. +/* + * Function: + * AutoFill * Arguments: ctx - The text widget. - * Returns: none + * + * Description: + * Breaks the line at the previous word boundry when + * called inside InsertChar. */ - static void -AutoFill(ctx) -TextWidget ctx; +AutoFill(TextWidget ctx) { - int width, height, x, line_num, max_width; - XawTextPosition ret_pos; - XawTextBlock text; + int width, height, x, line_num, max_width; + XawTextPosition ret_pos; + XawTextBlock text; + XRectangle cursor; + wchar_t wc_buf[2]; + + for (line_num = 0; line_num < ctx->text.lt.lines ; line_num++) + if (ctx->text.lt.info[line_num].position >= ctx->text.insertPos) + break; + if (line_num) + line_num--; /* backup a line. */ + + XawTextSinkGetCursorBounds(ctx->text.sink, &cursor); + max_width = Max(0, (int)XtWidth(ctx) - RHMargins(ctx) - cursor.width); + + x = ctx->text.r_margin.left; + XawTextSinkFindPosition(ctx->text.sink, ctx->text.lt.info[line_num].position, + x, max_width, True, &ret_pos, + &width, &height); + + if (ret_pos <= ctx->text.lt.info[line_num].position + || ret_pos >= ctx->text.insertPos || ret_pos < 1) + return; - if ( !((ctx->text.auto_fill) && (ctx->text.mult == 1)) ) - return; + XawTextSourceRead(ctx->text.source, ret_pos - 1, &text, 1); - for ( line_num = 0; line_num < ctx->text.lt.lines ; line_num++) - if ( ctx->text.lt.info[line_num].position >= ctx->text.insertPos ) - break; - line_num--; /* backup a line. */ + if (XawTextFormat(ctx, XawFmtWide)) { + wc_buf[0] = *(wchar_t *)text.ptr; + if (wc_buf[0] != _Xaw_atowc(XawSP) && wc_buf[0] != _Xaw_atowc(XawTAB)) + /* Only eats white spaces */ + return; - max_width = Max(0, (int)(ctx->core.width - HMargins(ctx))); + text.format = XawFmtWide; + text.ptr = (char *)wc_buf; + wc_buf[0] = _Xaw_atowc(XawLF); + wc_buf[1] = 0; + } + else { + if (text.ptr[0] != XawSP && text.ptr[0] != XawTAB) + /* Only eats white spaces */ + return; - x = ctx->text.margin.left; - XawTextSinkFindPosition( ctx->text.sink,ctx->text.lt.info[line_num].position, - x, max_width, TRUE, &ret_pos, &width, &height); - - if ( ret_pos >= ctx->text.insertPos ) - return; - - text.format = XawFmt8Bit; - if (_XawTextFormat(ctx) == XawFmtWide) { - text.format = XawFmtWide; - text.ptr = (char *)XtMalloc(sizeof(wchar_t) * 2); - ((wchar_t*)text.ptr)[0] = _Xaw_atowc(XawLF); - ((wchar_t*)text.ptr)[1] = 0; - } else - text.ptr = "\n"; - text.length = 1; - text.firstPos = 0; + text.format = XawFmt8Bit; + text.ptr = "\n"; + } + text.length = 1; + text.firstPos = 0; - if (_XawTextReplace(ctx, ret_pos - 1, ret_pos, &text)) - XBell(XtDisplay((Widget) ctx), 0); /* Unable to edit, complain. */ + if (_XawTextReplace(ctx, ret_pos - 1, ret_pos, &text)) + XBell(XtDisplay((Widget)ctx), 0); + + if (++ctx->text.insertPos > ctx->text.lastPos) + ctx->text.insertPos = ctx->text.lastPos; } /*ARGSUSED*/ static void -InsertChar(w, event, p, n) -Widget w; -XEvent* event; -String* p; -Cardinal* n; -{ - TextWidget ctx = (TextWidget) w; - char *ptr, strbuf[BUFSIZ]; - int count, error; - KeySym keysym; - XawTextBlock text; - - if (XtIsSubclass (ctx->text.source, (WidgetClass) multiSrcObjectClass)) - text.length = _XawImWcLookupString (w, &event->xkey, - (wchar_t*) strbuf, BUFSIZ, &keysym, (Status*) &compose_status); - else - text.length = XLookupString ((XKeyEvent*)event, strbuf, BUFSIZ, &keysym, &compose_status); - - if (text.length == 0) - return; - - text.format = _XawTextFormat( ctx ); - if ( text.format == XawFmtWide ) { - text.ptr = ptr = XtMalloc(sizeof(wchar_t) * text.length * ctx->text.mult ); - for (count = 0; count < ctx->text.mult; count++ ) { - memcpy((char*) ptr, (char *)strbuf, sizeof(wchar_t) * text.length ); - ptr += sizeof(wchar_t) * text.length; - } - - } else { /* == XawFmt8Bit */ - text.ptr = ptr = XtMalloc( sizeof(char) * text.length * ctx->text.mult ); - for ( count = 0; count < ctx->text.mult; count++ ) { - strncpy( ptr, strbuf, text.length ); - ptr += text.length; - } - } - - text.length = text.length * ctx->text.mult; - text.firstPos = 0; - - StartAction(ctx, event); - - error = _XawTextReplace(ctx, ctx->text.insertPos,ctx->text.insertPos, &text); +InsertChar(Widget w, XEvent *event, String *p, Cardinal *n) +{ + TextWidget ctx = (TextWidget)w; + char *ptr, strbuf[128], ptrbuf[512]; + int count, error, mult = MULT(ctx); + KeySym keysym; + XawTextBlock text; +#ifndef OLDXAW + Bool format = False; +#endif + XawTextPosition from, to; + + if (XtIsSubclass (ctx->text.source, (WidgetClass) multiSrcObjectClass)) + text.length = _XawImWcLookupString(w, &event->xkey, (wchar_t*)strbuf, + sizeof(strbuf), &keysym); + else + text.length = _XawLookupString(w, (XKeyEvent*)event, strbuf, + sizeof(strbuf), &keysym); + + if (text.length == 0) + return; - if (error == XawEditDone) { - ctx->text.insertPos = SrcScan(ctx->text.source, ctx->text.insertPos, - XawstPositions, XawsdRight, text.length, TRUE); - AutoFill(ctx); - } - else - XBell(XtDisplay(ctx), 50); + if (mult < 0) { + ctx->text.mult = 1; + return; + } - XtFree(text.ptr); - _XawTextSetScrollBars(ctx); - EndAction(ctx); -} + text.format = _XawTextFormat(ctx); + if (text.format == XawFmtWide) { + text.ptr = ptr = XawStackAlloc(sizeof(wchar_t) * text.length + * mult, ptrbuf); + for (count = 0; count < mult; count++) { + memcpy((char*)ptr, (char *)strbuf, sizeof(wchar_t) * text.length); + ptr += sizeof(wchar_t) * text.length; + } +#ifndef OLDXAW + if (mult == 1) + format = ctx->text.left_column < ctx->text.right_column; +#endif + } + else { /* == XawFmt8Bit */ + text.ptr = ptr = XawStackAlloc(text.length * mult, ptrbuf); + for (count = 0; count < mult; count++) { + strncpy(ptr, strbuf, text.length); + ptr += text.length; + } +#ifndef OLDXAW + if (mult == 1) + format = ctx->text.left_column < ctx->text.right_column; +#endif + } + text.length = text.length * mult; + text.firstPos = 0; + + StartAction(ctx, event); +#ifndef OLDXAW + if (mult == 1) + _XawSourceSetUndoMerge((TextSrcObject)ctx->text.source, True); +#endif + + from = ctx->text.insertPos; +#ifndef OLDXAW + if (ctx->text.overwrite) { + XawTextPosition tmp; + + to = from + mult; + tmp = SrcScan(ctx->text.source, from, XawstEOL, XawsdRight, 1, False); + if (to > tmp) + to = tmp; + } + else +#endif + to = from; + + error = _XawTextReplace(ctx, from , to, &text); + + if (error == XawEditDone) { + ctx->text.from_left = -1; + ctx->text.insertPos = SrcScan(ctx->text.source, ctx->text.old_insert, + XawstPositions, XawsdRight, + text.length, True); + if (ctx->text.auto_fill) { +#ifndef OLDXAW + if (format) + (void)FormatText(ctx, SrcScan(ctx->text.source, + ctx->text.insertPos, XawstEOL, + XawsdLeft, 1, False), False, + NULL, 0); + else +#endif + AutoFill(ctx); + } + } + else + XBell(XtDisplay(ctx), 50); + + XawStackFree(text.ptr, ptrbuf); + EndAction(ctx); + + if (error == XawEditDone && text.format == XawFmt8Bit && text.length == 1 + && (text.ptr[0] == ')' || text.ptr[0] == ']' || text.ptr[0] == '}') + && ctx->text.display_caret) { + static struct timeval tmval = {0, 500000}; + fd_set fds; + Widget source = ctx->text.source; + XawTextPosition insertPos = ctx->text.insertPos, pos, tmp, last; + char left, right = text.ptr[0]; + int level = 0; + XtAppContext app_context = XtWidgetToApplicationContext(w); + + left = right == ')' ? '(' : right == ']' ? '[' : '{'; + + last = insertPos - 1; + do { + text.ptr[0] = left; + pos = XawTextSourceSearch(source, last, XawsdLeft, &text); + if (pos == XawTextSearchError || !IsPositionVisible(ctx, pos)) + return; + text.ptr[0] = right; + tmp = pos; + do { + tmp = XawTextSourceSearch(source, tmp, XawsdRight, &text); + if (tmp == XawTextSearchError) + return; + if (tmp <= last) + ++level; + } while (++tmp <= last); + --level; + last = pos; + } while (level); + + StartAction(ctx, NULL); +#ifndef OLDXAW + _XawSourceSetUndoMerge((TextSrcObject)ctx->text.source, True); +#endif + ctx->text.insertPos = pos; + EndAction(ctx); + + XSync(XtDisplay(w), False); + while (XtAppPending(app_context) & XtIMXEvent) { + XEvent ev; + if (! XtAppPeekEvent(app_context, &ev)) + break; + if (ev.type == KeyPress || ev.type == ButtonPress) + break; + XtAppProcessEvent(app_context, XtIMXEvent); + } + FD_ZERO(&fds); + FD_SET(ConnectionNumber(XtDisplay(w)), &fds); + (void)select(FD_SETSIZE, &fds, NULL, NULL, &tmval); + if (tmval.tv_usec != 500000) + usleep(40000); + + StartAction(ctx, NULL); +#ifndef OLDXAW + _XawSourceSetUndoMerge((TextSrcObject)ctx->text.source, True); +#endif + ctx->text.insertPos = insertPos; + EndAction(ctx); + } +} /* IfHexConvertHexElseReturnParam() - called by InsertString * @@ -1590,78 +3227,70 @@ Cardinal* n; * * WHEN: the passed param is a legal hex string * RETURNS: a pointer to that converted, null terminated hex string; - * len_return holds the character count of conversion result + * len_return holds the character count of conversion result * * WHEN: the passed param is not a legal hex string: * RETURNS: the parameter passed; - * len_return holds the char count of param. + * len_return holds the char count of param. * * NOTE: In neither case will there be strings to free. */ - -static char* -IfHexConvertHexElseReturnParam(param, len_return) - char* param; - int* len_return; +static char * +IfHexConvertHexElseReturnParam(char *param, int *len_return) { - char *p; /* steps through param char by char */ - char c; /* holds the character pointed to by p */ - - int ind; /* steps through hexval buffer char by char */ - static char hexval[ XawTextActionMaxHexChars ]; - Boolean first_digit; - - /* reject if it doesn't begin with 0x and at least one more character. */ - - if ( ( param[0] != '0' ) || ( param[1] != 'x' ) || ( param[2] == '\0' ) ) { - *len_return = strlen( param ); - return( param ); - } - - /* Skip the 0x; go character by character shifting and adding. */ - - first_digit = True; - ind = 0; - hexval[ ind ] = '\0'; - - for ( p = param+2; ( c = *p ); p++ ) { - hexval[ ind ] *= 16; - if (c >= '0' && c <= '9') - hexval[ ind ] += c - '0'; - else if (c >= 'a' && c <= 'f') - hexval[ ind ] += c - 'a' + 10; - else if (c >= 'A' && c <= 'F') - hexval[ ind ] += c - 'A' + 10; - else break; - - /* If we didn't break in preceding line, it was a good hex char. */ - - if ( first_digit ) - first_digit = False; - else { - first_digit = True; - if ( ++ind < XawTextActionMaxHexChars ) - hexval[ ind ] = '\0'; - else { - *len_return = strlen( param ); - return( param ); - } - } - } + char *p; /* steps through param char by char */ + char c; /* holds the character pointed to by p */ + int ind; /* steps through hexval buffer char by char */ + static char hexval[XawTextActionMaxHexChars]; + Boolean first_digit; + + /* reject if it doesn't begin with 0x and at least one more character. */ + if ((param[0] != '0') || (param[1] != 'x') || (param[2] == '\0')) { + *len_return = strlen(param); + return(param); + } - /* We quit the above loop becasue we hit a non hex. If that char is \0... */ + /* Skip the 0x; go character by character shifting and adding. */ + first_digit = True; + ind = 0; + hexval[ind] = '\0'; + + for (p = param+2; (c = *p) != '\0'; p++) { + hexval[ind] *= 16; + if (c >= '0' && c <= '9') + hexval[ind] += c - '0'; + else if (c >= 'a' && c <= 'f') + hexval[ind] += c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + hexval[ind] += c - 'A' + 10; + else + break; + + /* If we didn't break in preceding line, it was a good hex char. */ + if (first_digit) + first_digit = False; + else { + first_digit = True; + if (++ind < XawTextActionMaxHexChars) + hexval[ind] = '\0'; + else { + *len_return = strlen(param); + return(param); + } + } + } - if ( ( c == '\0' ) && first_digit ) { - *len_return = strlen( hexval ); - return( hexval ); /* ...it was a legal hex string, so return it.*/ - } + /* We quit the above loop becasue we hit a non hex. If that char is \0... */ + if ((c == '\0') && first_digit) { + *len_return = strlen(hexval); + return (hexval); /* ...it was a legal hex string, so return it */ + } - /* Else, there were non-hex chars or odd digit count, so... */ + /* Else, there were non-hex chars or odd digit count, so... */ - *len_return = strlen( param ); - return( param ); /* ...return the verbatim string. */ + *len_return = strlen(param); + return (param); /* ...return the verbatim string. */ } - /* InsertString() - action * * Mostly rewritten for R6 i18n. @@ -1671,589 +3300,1122 @@ IfHexConvertHexElseReturnParam(param, len_return) * * The exception is that parameters composed of the two * characters 0x, followed only by an even number of - * hexadecimal digits will be converted to characters. */ - + * hexadecimal digits will be converted to characters */ /*ARGSUSED*/ -static void -InsertString(w, event, params, num_params) -Widget w; -XEvent* event; -String* params; -Cardinal* num_params; +static void +InsertString(Widget w, XEvent *event, String *params, Cardinal *num_params) { - TextWidget ctx = (TextWidget) w; - XtAppContext app_con = XtWidgetToApplicationContext(w); - XawTextBlock text; - int i; - - text.firstPos = 0; - text.format = _XawTextFormat( ctx ); - - StartAction(ctx, event); - for ( i = *num_params; i; i--, params++ ) { /* DO FOR EACH PARAMETER */ - - text.ptr = IfHexConvertHexElseReturnParam( *params, &text.length ); - - if ( text.length == 0 ) continue; - - if ( _XawTextFormat( ctx ) == XawFmtWide ) { /* convert to WC */ - - int temp_len; - text.ptr = (char*) _XawTextMBToWC( XtDisplay(w), text.ptr, - &text.length ); - - if ( text.ptr == NULL ) { /* conversion error */ - XtAppWarningMsg( app_con, - "insertString", "textAction", "XawError", - "insert-string()'s parameter contents not legal in this locale.", - NULL, NULL ); - ParameterError( w, *params ); - continue; - } - - /* Double check that the new input is legal: try to convert to MB. */ - - temp_len = text.length; /* _XawTextWCToMB's 3rd arg is in_out */ - if ( _XawTextWCToMB( XtDisplay(w), (wchar_t*)text.ptr, &temp_len ) == NULL ) { - XtAppWarningMsg( app_con, - "insertString", "textAction", "XawError", - "insert-string()'s parameter contents not legal in this locale.", - NULL, NULL ); - ParameterError( w, *params ); - continue; - } - } /* convert to WC */ + TextWidget ctx = (TextWidget)w; + XtAppContext app_con = XtWidgetToApplicationContext(w); + XawTextBlock text; + int i; + + text.firstPos = 0; + text.format = _XawTextFormat(ctx); + + StartAction(ctx, event); + for (i = *num_params; i; i--, params++) { /* DO FOR EACH PARAMETER */ + text.ptr = IfHexConvertHexElseReturnParam(*params, &text.length); + + if (text.length == 0) + continue; + + if (XawTextFormat(ctx, XawFmtWide)) { /* convert to WC */ + int temp_len; + + text.ptr = (char*)_XawTextMBToWC(XtDisplay(w), text.ptr, + &text.length); + + if (text.ptr == NULL) { /* conversion error */ + XtAppWarningMsg(app_con, + "insertString", "textAction", "XawError", + "insert-string()'s parameter contents " + "not legal in this locale.", + NULL, NULL); + ParameterError(w, *params); + continue; + } + + /* Double check that the new input is legal: try to convert to MB. */ + + temp_len = text.length; /* _XawTextWCToMB's 3rd arg is in_out */ + if (_XawTextWCToMB(XtDisplay(w), (wchar_t*)text.ptr, &temp_len) + == NULL) { + XtAppWarningMsg( app_con, + "insertString", "textAction", "XawError", + "insert-string()'s parameter contents " + "not legal in this locale.", + NULL, NULL); + ParameterError(w, *params); + continue; + } + } /* convert to WC */ - if ( _XawTextReplace( ctx, ctx->text.insertPos, - ctx->text.insertPos, &text ) ) { - XBell( XtDisplay( ctx ), 50 ); - EndAction( ctx ); - return; - } + if (_XawTextReplace(ctx, ctx->text.insertPos, + ctx->text.insertPos, &text)) { + XBell(XtDisplay(ctx), 50); + EndAction(ctx); + return; + } - /* Advance insertPos to the end of the string we just inserted. */ - ctx->text.insertPos = SrcScan( ctx->text.source, ctx->text.insertPos, - XawstPositions, XawsdRight, text.length, TRUE ); + ctx->text.from_left = -1; + /* Advance insertPos to the end of the string we just inserted. */ + ctx->text.insertPos = SrcScan(ctx->text.source, ctx->text.old_insert, + XawstPositions, XawsdRight, text.length, + True); - } /* DO FOR EACH PARAMETER */ + } /* DO FOR EACH PARAMETER */ - EndAction( ctx ); + EndAction(ctx); } - /* DisplayCaret() - action - * + * * The parameter list should contain one boolean value. If the * argument is true, the cursor will be displayed. If false, not. * * The exception is that EnterNotify and LeaveNotify events may * have a second argument, "always". If they do not, the cursor * is only affected if the focus member of the event is true. */ +static void +DisplayCaret(Widget w, XEvent *event, String *params, Cardinal *num_params) +{ + TextWidget ctx = (TextWidget)w; + Bool display_caret = True; + + if ((event->type == EnterNotify || event->type == LeaveNotify) + && ((*num_params >= 2) && (strcmp(params[1], "always") == 0)) + && (!event->xcrossing.focus)) + return; -static void -DisplayCaret(w, event, params, num_params) -Widget w; -XEvent* event; /* CrossingNotify special-cased */ -String* params; /* Off, False, No, On, True, Yes, etc. */ -Cardinal* num_params; /* 0, 1 or 2 */ + if (*num_params > 0) { /* default arg is "True" */ + XrmValue from, to; + from.size = strlen(from.addr = params[0]); + XtConvert(w, XtRString, &from, XtRBoolean, &to); + + if (to.addr != NULL) + display_caret = *(Boolean*)to.addr; + if (ctx->text.display_caret == display_caret) + return; + } + StartAction(ctx, event); + ctx->text.display_caret = display_caret; + EndAction(ctx); +} + +#ifndef OLDXAW +static void +Numeric(Widget w, XEvent *event, String *params, Cardinal *num_params) { - TextWidget ctx = (TextWidget)w; - Boolean display_caret = True; + TextWidget ctx = (TextWidget)w; - if ( ( event->type == EnterNotify || event->type == LeaveNotify ) && - ( ( *num_params >= 2 ) && ( strcmp( params[1], "always" ) == 0 ) ) && - ( !event->xcrossing.focus ) ) - return; + if (ctx->text.numeric) { + long mult = ctx->text.mult; - if (*num_params > 0) { /* default arg is "True" */ - XrmValue from, to; - from.size = strlen(from.addr = params[0]); - XtConvert( w, XtRString, &from, XtRBoolean, &to ); + if (*num_params != 1 || strlen(params[0]) != 1 + || (!isdigit(params[0][0]) + && (params[0][0] != '-' || mult != 0))) { + char err_buf[256]; - if ( to.addr != NULL ) - display_caret = *(Boolean*)to.addr; - if ( ctx->text.display_caret == display_caret ) - return; - } - StartAction(ctx, event); - ctx->text.display_caret = display_caret; - EndAction(ctx); + if (event && (event->type == KeyPress || event->type == KeyRelease) + && params[0][0] == '-') { + InsertChar(w, event, params, num_params); + return; + } + XmuSnprintf(err_buf, sizeof(err_buf), + "numeric: Invalid argument%s'%s'", + *num_params ? ", " : "", *num_params ? params[0] : ""); + XtAppWarning(XtWidgetToApplicationContext(w), err_buf); + ctx->text.numeric = False; + ctx->text.mult = 1; + return; + } + if (params[0][0] == '-') { + ctx->text.mult = 32767; + return; + } + else if (mult == 32767) { + mult = ctx->text.mult = - (params[0][0] - '0'); + return; + } + else { + mult = mult * 10 + (params[0][0] - '0') * (mult < 0 ? -1 : 1); + ctx->text.mult = ctx->text.mult * 10 + (params[0][0] - '0') * + (mult < 0 ? -1 : 1); + } + if (mult != ctx->text.mult || mult >= 32767) { /* checks for overflow */ + XBell(XtDisplay(w), 0); + ctx->text.mult = 1; + ctx->text.numeric = False; + return; + } + } + else + InsertChar(w, event, params, num_params); } +/*ARGSUSED*/ +static void +KeyboardReset(Widget w, XEvent *event, String *params, Cardinal *num_params) +{ + TextWidget ctx = (TextWidget)w; + + ctx->text.numeric = False; + ctx->text.mult = 1; + + (void)_XawTextSrcToggleUndo((TextSrcObject)ctx->text.source); + + if (ctx->text.kill_ring_ptr) { + --ctx->text.kill_ring_ptr->refcount; + ctx->text.kill_ring_ptr = NULL; + } + ctx->text.kill_ring = 0; + + XBell(XtDisplay(w), 0); +} +#endif /* OLDXAW */ /* Multiply() - action - * + * * The parameter list may contain either a number or the string 'Reset'. - * + * * A number will multiply the current multiplication factor by that number. * Many of the text widget actions will will perform n actions, where n is * the multiplication factor. * * The string reset will reset the mutiplication factor to 1. */ - -/* ARGSUSED */ -static void -Multiply(w, event, params, num_params) -Widget w; -XEvent* event; -String* params; -Cardinal* num_params; +/*ARGSUSED*/ +static void +Multiply(Widget w, XEvent *event, String *params, Cardinal *num_params) { - TextWidget ctx = (TextWidget) w; - int mult; + TextWidget ctx = (TextWidget)w; + int mult; - if (*num_params != 1) { - XtAppError( XtWidgetToApplicationContext( w ), - "Xaw Text Widget: multiply() takes exactly one argument."); - XBell( XtDisplay( w ), 0 ); - return; - } + if (*num_params != 1) { + XtAppError(XtWidgetToApplicationContext(w), + "Xaw Text Widget: multiply() takes exactly one argument."); + XBell(XtDisplay(w), 0); + return; + } - if ( ( params[0][0] == 'r' ) || ( params[0][0] == 'R' ) ) { - XBell( XtDisplay( w ), 0 ); - ctx->text.mult = 1; - return; - } + if ((params[0][0] == 'r') || (params[0][0] == 'R')) { + XBell(XtDisplay(w), 0); +#ifndef OLDXAW + ctx->text.numeric = False; +#endif + ctx->text.mult = 1; + return; + } - if ( ( mult = atoi( params[0] ) ) == 0 ) { - char buf[ BUFSIZ ]; - sprintf(buf, "%s %s", "Xaw Text Widget: multiply() argument", - "must be a number greater than zero, or 'Reset'." ); - XtAppError( XtWidgetToApplicationContext( w ), buf ); - XBell( XtDisplay( w ), 50 ); - return; - } +#ifndef OLDXAW + if (params[0][0] == 's' || params[0][0] == 'S') { + ctx->text.numeric = True; + ctx->text.mult = 0; + return; + } + else +#endif + if ((mult = atoi(params[0])) == 0) { + char buf[BUFSIZ]; + + XmuSnprintf(buf, sizeof(buf), + "%s %s", "Xaw Text Widget: multiply() argument", + "must be a number greater than zero, or 'Reset'."); + XtAppError(XtWidgetToApplicationContext(w), buf); + XBell(XtDisplay(w), 50); + return; + } - ctx->text.mult *= mult; + ctx->text.mult *= mult; } - /* StripOutOldCRs() - called from FormRegion * * removes CRs in widget ctx, from from to to. * * RETURNS: the new ending location (we may add some characters), * or XawReplaceError if the widget can't be written to. */ - static XawTextPosition -StripOutOldCRs(ctx, from, to) -TextWidget ctx; -XawTextPosition from, to; +StripOutOldCRs(TextWidget ctx, XawTextPosition from, XawTextPosition to, + XawTextPosition *pos, int num_pos) { - XawTextPosition startPos, endPos, eop_begin, eop_end, temp; - Widget src = ctx->text.source; - XawTextBlock text; - char *buf; - static wchar_t wc_two_spaces[ 3 ]; - - /* Initialize our TextBlock with two spaces. */ - - text.firstPos = 0; - text.format = _XawTextFormat(ctx); - if ( text.format == XawFmt8Bit ) + XawTextPosition startPos, endPos, eop_begin, eop_end, temp; + Widget src = ctx->text.source; + XawTextBlock text; + char *buf; + static wchar_t wc_two_spaces[3]; + int idx; + + /* Initialize our TextBlock with two spaces. */ + text.firstPos = 0; + text.format = _XawTextFormat(ctx); + if (text.format == XawFmt8Bit) text.ptr= " "; - else { - wc_two_spaces[0] = _Xaw_atowc(XawSP); - wc_two_spaces[1] = _Xaw_atowc(XawSP); - wc_two_spaces[2] = 0; - text.ptr = (char*) wc_two_spaces; - } - - /* Strip out CR's. */ - - eop_begin = eop_end = startPos = endPos = from; - /* CONSTCOND */ - while (TRUE) { - endPos=SrcScan(src, startPos, XawstEOL, XawsdRight, 1, FALSE); - - temp = SrcScan(src, endPos, XawstWhiteSpace, XawsdLeft, 1, FALSE); - temp = SrcScan(src, temp, XawstWhiteSpace, XawsdRight,1, FALSE); - - if (temp > startPos) - endPos = temp; - - if (endPos >= to) - break; - - if (endPos >= eop_begin) { - startPos = eop_end; - eop_begin=SrcScan(src, startPos, XawstParagraph, XawsdRight, 1,FALSE); - eop_end = SrcScan(src, startPos, XawstParagraph, XawsdRight, 1, TRUE); - } else { - XawTextPosition periodPos, next_word; - int i, len; - - periodPos= SrcScan(src, endPos, XawstPositions, XawsdLeft, 1, TRUE); - next_word = SrcScan(src, endPos, XawstWhiteSpace, XawsdRight, 1, FALSE); - - len = next_word - periodPos; - - text.length = 1; - buf = _XawTextGetText(ctx, periodPos, next_word); - if (text.format == XawFmtWide) { - if ( (periodPos < endPos) && (((wchar_t*)buf)[0] == _Xaw_atowc('.'))) - text.length++; - } else - if ( (periodPos < endPos) && (buf[0] == '.') ) - text.length++; /* Put in two spaces. */ - - /* - * Remove all extra spaces. - */ - - for (i = 1 ; i < len; i++) - if (text.format == XawFmtWide) { - if ( !iswspace(((wchar_t*)buf)[i]) || ((periodPos + i) >= to) ) { - break; - } - } else - if ( !isspace(buf[i]) || ((periodPos + i) >= to) ) { - break; - } + wc_two_spaces[0] = _Xaw_atowc(XawSP); + wc_two_spaces[1] = _Xaw_atowc(XawSP); + wc_two_spaces[2] = 0; + text.ptr = (char*)wc_two_spaces; + } + + /* Strip out CR's. */ + eop_begin = eop_end = startPos = endPos = from; + + /* CONSTCOND */ + while (TRUE) { + endPos=SrcScan(src, startPos, XawstEOL, XawsdRight, 1, False); + + temp = SrcScan(src, endPos, XawstWhiteSpace, XawsdLeft, 1, False); + temp = SrcScan(src, temp, XawstWhiteSpace, XawsdRight,1, False); + + if (temp > startPos) + endPos = temp; + + if (endPos >= to) + break; + + if (endPos >= eop_begin) { + startPos = eop_end; + eop_begin=SrcScan(src, startPos, XawstParagraph, + XawsdRight, 1,False); + eop_end = SrcScan(src, startPos, XawstParagraph, + XawsdRight, 1, True); + } + else { + XawTextPosition periodPos, next_word; + int i, len; + + periodPos = SrcScan(src, endPos, XawstPositions, + XawsdLeft, 1, True); + next_word = SrcScan(src, endPos, XawstWhiteSpace, + XawsdRight, 1, False); + + len = next_word - periodPos; + + text.length = 1; + buf = _XawTextGetText(ctx, periodPos, next_word); + if (text.format == XawFmtWide) { + if (periodPos < endPos && ((wchar_t*)buf)[0] == _Xaw_atowc('.')) + text.length++; + } + else + if (periodPos < endPos && buf[0] == '.') + text.length++; /* Put in two spaces. */ + + /* + * Remove all extra spaces. + */ + for (i = 1 ; i < len; i++) + if (text.format == XawFmtWide) { + if (!iswspace(((wchar_t*)buf)[i]) || ((periodPos + i) >= to)) + break; + } + else if (!isspace(buf[i]) || (periodPos + i) >= to) + break; - XtFree(buf); + XtFree(buf); + + to -= (i - text.length - 1); + startPos = SrcScan(src, periodPos, XawstPositions, + XawsdRight, i, True); + if (_XawTextReplace(ctx, endPos, startPos, &text) != XawEditDone) + return (XawReplaceError); + + for (idx = 0; idx < num_pos; idx++) { + if (endPos < pos[idx]) { + if (startPos < pos[idx]) + pos[idx] -= startPos - endPos; + else + pos[idx] = endPos; + pos[idx] += text.length; + } + } - to -= (i - text.length - 1); - startPos = SrcScan(src, periodPos, XawstPositions, XawsdRight, i, TRUE); - if (_XawTextReplace(ctx, endPos, startPos, &text) != XawEditDone) - return XawReplaceError; - startPos -= i - text.length; + startPos -= i - text.length; + } } - } - return(to); -} + return (to); +} /* InsertNewCRs() - called from FormRegion * * inserts new CRs for FormRegion, thus for FormParagraph action */ - static void -InsertNewCRs(ctx, from, to) -TextWidget ctx; -XawTextPosition from, to; -{ - XawTextPosition startPos, endPos, space, eol; - XawTextBlock text; - int i, width, height, len; - char * buf; - static wchar_t wide_CR[ 2 ]; - - text.firstPos = 0; - text.length = 1; - text.format = _XawTextFormat( ctx ); - - if ( text.format == XawFmt8Bit ) - text.ptr = "\n"; - else { - wide_CR[0] = _Xaw_atowc(XawLF); - wide_CR[1] = 0; - text.ptr = (char*) wide_CR; - } - - startPos = from; - /* CONSTCOND */ - while (TRUE) { - XawTextSinkFindPosition( ctx->text.sink, startPos, - (int) ctx->text.margin.left, - (int) (ctx->core.width - HMargins(ctx)), - TRUE, &eol, &width, &height); - if (eol >= to) - break; - - eol = SrcScan(ctx->text.source, eol, XawstPositions, XawsdLeft, 1, TRUE); - space= SrcScan(ctx->text.source, eol, XawstWhiteSpace,XawsdRight,1, TRUE); - - startPos = endPos = eol; - if (eol == space) - return; - - len = (int) (space - eol); - buf = _XawTextGetText(ctx, eol, space); - for ( i = 0 ; i < len ; i++) - if (text.format == XawFmtWide) { - if (!iswspace(((wchar_t*)buf)[i])) - break; - } else - if (!isspace(buf[i])) - break; - - to -= (i - 1); - endPos = SrcScan(ctx->text.source, endPos, - XawstPositions, XawsdRight, i, TRUE); - XtFree(buf); - - if (_XawTextReplace(ctx, startPos, endPos, &text)) - return; - - startPos = SrcScan(ctx->text.source, startPos, - XawstPositions, XawsdRight, 1, TRUE); - } -} +InsertNewCRs(TextWidget ctx, XawTextPosition from, XawTextPosition to, + XawTextPosition *pos, int num_pos) +{ + XawTextPosition startPos, endPos, space, eol; + XawTextBlock text; + int i, width, height, len, wwidth, idx; + char *buf; + static wchar_t wide_CR[2]; + + text.firstPos = 0; + text.length = 1; + text.format = _XawTextFormat(ctx); + + if (text.format == XawFmt8Bit) + text.ptr = "\n"; + else { + wide_CR[0] = _Xaw_atowc(XawLF); + wide_CR[1] = 0; + text.ptr = (char*)wide_CR; + } + + startPos = from; + wwidth = (int)XtWidth(ctx) - (int)HMargins(ctx); + if (ctx->text.wrap != XawtextWrapNever) { + XRectangle cursor; + + XawTextSinkGetCursorBounds(ctx->text.sink, &cursor); + wwidth -= (int)cursor.width; + } + wwidth = XawMax(0, wwidth); + + /* CONSTCOND */ + while (TRUE) { + XawTextSinkFindPosition(ctx->text.sink, startPos, + (int)ctx->text.r_margin.left, wwidth, + True, &eol, &width, &height); + if (eol == startPos) + ++eol; + if (eol >= to) + break; + + eol = SrcScan(ctx->text.source, eol, XawstPositions, + XawsdLeft, 1, True); + space = SrcScan(ctx->text.source, eol, XawstWhiteSpace, + XawsdRight,1, True); + + startPos = endPos = eol; + if (eol == space) + return; + + len = (int)(space - eol); + buf = _XawTextGetText(ctx, eol, space); + for (i = 0 ; i < len ; i++) + if (text.format == XawFmtWide) { + if (!iswspace(((wchar_t*)buf)[i])) + break; + } + else if (!isspace(buf[i])) + break; + + to -= (i - 1); + endPos = SrcScan(ctx->text.source, endPos, + XawstPositions, XawsdRight, i, True); + XtFree(buf); + + if (_XawTextReplace(ctx, startPos, endPos, &text)) + return; + + for (idx = 0; idx < num_pos; idx++) { + if (startPos < pos[idx]) { + if (endPos < pos[idx]) + pos[idx] -= endPos - startPos; + else + pos[idx] = startPos; + pos[idx] += text.length; + } + } + + startPos = SrcScan(ctx->text.source, startPos, + XawstPositions, XawsdRight, 1, True); + } +} /* FormRegion() - called by FormParagraph - * + * * oversees the work of paragraph-forming a region * - * RETURNS: XawEditDone if successful, or XawReplaceError. */ - + * Return: + * XawEditDone if successful, or XawReplaceError + */ static int -FormRegion(ctx, from, to) -TextWidget ctx; -XawTextPosition from, to; +FormRegion(TextWidget ctx, XawTextPosition from, XawTextPosition to, + XawTextPosition *pos, int num_pos) { - if ( from >= to ) return XawEditDone; +#ifndef OLDXAW + Bool format = ctx->text.auto_fill + && ctx->text.left_column < ctx->text.right_column; +#endif + + if (from >= to) + return (XawEditDone); + +#ifndef OLDXAW + if (format) { + XawTextPosition len = ctx->text.lastPos; + int inc = 0; + + if (ctx->text.justify == XawjustifyLeft || + ctx->text.justify == XawjustifyFull) { + Untabify(ctx, from, to, pos, num_pos, NULL); + to += ctx->text.lastPos - len; + len = ctx->text.insertPos; + (void)BlankLine((Widget)ctx, from, &inc); + if (from + inc >= to) + return (XawEditDone); + } + if (!StripSpaces(ctx, from + inc, to, pos, num_pos, NULL)) + return (XawReplaceError); + to += ctx->text.lastPos - len; - if ( ( to = StripOutOldCRs( ctx, from, to ) ) == XawReplaceError ) - return XawReplaceError; + FormatText(ctx, from, ctx->text.justify != XawjustifyFull, pos, num_pos); + } + else { +#endif + if ((to = StripOutOldCRs(ctx, from, to, pos, num_pos)) == XawReplaceError) + return (XawReplaceError); + InsertNewCRs(ctx, from, to, pos, num_pos); +#ifndef OLDXAW + } +#endif + ctx->text.from_left = -1; + + return (XawEditDone); +} - /* insure that the insertion point is within legal bounds */ - if ( ctx->text.insertPos > SrcScan( ctx->text.source, 0, - XawstAll, XawsdRight, 1, TRUE ) ) - ctx->text.insertPos = to; +#ifndef OLDXAW +static Bool +BlankLine(Widget w, XawTextPosition pos, int *blanks_return) +{ + int i, blanks = 0; + XawTextBlock block; + Widget src = XawTextGetSource(w); + XawTextPosition l = SrcScan(src, pos, XawstEOL, XawsdLeft, 1, False); + XawTextPosition r = SrcScan(src, pos, XawstEOL, XawsdRight, 1, False); + + while (l < r) { + l = XawTextSourceRead(src, l, &block, r - l); + if (block.length == 0) { + if (blanks_return) + *blanks_return = blanks; + return (True); + } + if (XawTextFormat((TextWidget)w, XawFmt8Bit)) { + for (i = 0; i < block.length; i++, blanks++) + if (block.ptr[i] != ' ' && + block.ptr[i] != '\t') { + if (blanks_return) + *blanks_return = blanks; + return (block.ptr[i] == '\n'); + } + } + else if (XawTextFormat((TextWidget)w, XawFmtWide)) { + for (i = 0; i < block.length; i++, blanks++) + if (_Xaw_atowc(XawSP) != ((wchar_t*)block.ptr)[i] && + _Xaw_atowc(XawTAB) != ((wchar_t*)block.ptr)[i]) { + if (blanks_return) + *blanks_return = blanks; + return (_Xaw_atowc(XawLF) == ((wchar_t*)block.ptr)[i]); + } + } + } - InsertNewCRs(ctx, from, to); - _XawTextBuildLineTable(ctx, ctx->text.lt.top, TRUE); - return XawEditDone; + return (True); } +static Bool +GetBlockBoundaries(TextWidget ctx, + XawTextPosition *from_return, XawTextPosition *to_return) +{ + XawTextPosition from, to; + + if (ctx->text.auto_fill && ctx->text.left_column < ctx->text.right_column) { + if (ctx->text.s.left != ctx->text.s.right) { + from = SrcScan(ctx->text.source, + XawMin(ctx->text.s.left, ctx->text.s.right), + XawstEOL, XawsdLeft, 1, False); + to = SrcScan(ctx->text.source, + XawMax(ctx->text.s.right, ctx->text.s.right), + XawstEOL, XawsdRight, 1, False); + } + else { + XawTextBlock block; + XawTextPosition tmp; + Bool first; + + from = to = ctx->text.insertPos; + + /* find from position */ + first = True; + while (1) { + tmp = from; + from = SrcScan(ctx->text.source, from, XawstEOL, XawsdLeft, + 1 + !first, False); + XawTextSourceRead(ctx->text.source, from, &block, 1); + if (block.length == 0 || + (XawTextFormat(ctx, XawFmt8Bit) && + block.ptr[0] != ' ' && + block.ptr[0] != '\t' && + !isalnum(*(unsigned char*)block.ptr)) || + (XawTextFormat(ctx, XawFmtWide) && + _Xaw_atowc(XawSP) != *(wchar_t*)block.ptr && + _Xaw_atowc(XawTAB) != *(wchar_t*)block.ptr && + !iswalnum(*(wchar_t*)block.ptr)) || + BlankLine((Widget)ctx, from, NULL)) { + from = tmp; + break; + } + if (from == tmp && !first) + break; + first = False; + } + if (first) + return (False); + + /* find to position */ + first = True; + while (1) { + tmp = to; + to = SrcScan(ctx->text.source, to, XawstEOL, XawsdRight, + 1 + !first, False); + XawTextSourceRead(ctx->text.source, to + (to < ctx->text.lastPos), + &block, 1); + if (block.length == 0 || + (XawTextFormat(ctx, XawFmt8Bit) && + block.ptr[0] != ' ' && + block.ptr[0] != '\t' && + !isalnum(*(unsigned char*)block.ptr)) || + (XawTextFormat(ctx, XawFmtWide) && + _Xaw_atowc(XawSP) != *(wchar_t*)block.ptr && + _Xaw_atowc(XawTAB) != *(wchar_t*)block.ptr && + !iswalnum(*(wchar_t*)block.ptr)) || + BlankLine((Widget)ctx, to, NULL)) + break; + if (to == tmp && !first) + break; + first = False; + } + } + } + else { + from = SrcScan(ctx->text.source, ctx->text.insertPos, XawstEOL, + XawsdLeft, 1, False); + if (BlankLine((Widget)ctx, from, NULL)) + return (False); + from = SrcScan(ctx->text.source, from, XawstParagraph, + XawsdLeft, 1, False); + if (BlankLine((Widget)ctx, from, NULL)) + from = SrcScan(ctx->text.source, from, XawstEOL, + XawsdRight, 1, True); + to = SrcScan(ctx->text.source, from, XawstParagraph, + XawsdRight, 1, False); + } + + if (from < to) { + *from_return = from; + *to_return = to; + return (True); + } + + return (False); +} +#endif /* OLDXAW */ /* FormParagraph() - action * * removes and reinserts CRs to maximize line length without clipping */ - -/* ARGSUSED */ -static void -FormParagraph(w, event, params, num_params) -Widget w; -XEvent* event; -String* params; -Cardinal* num_params; +/*ARGSUSED*/ +static void +FormParagraph(Widget w, XEvent *event, String *params, Cardinal *num_params) { - TextWidget ctx = (TextWidget) w; - XawTextPosition from, to; + TextWidget ctx = (TextWidget)w; + XawTextPosition from, to, buf[32], *pos; +#ifndef OLDXAW + XawTextPosition endPos = 0; + char *lbuf = NULL, *rbuf; + TextSrcObject src = (TextSrcObject)ctx->text.source; + Cardinal i; + Bool undo = src->textSrc.enable_undo && src->textSrc.undo_state == False; +#endif + + StartAction(ctx, event); + +#ifndef OLDXAW + pos = XawStackAlloc(sizeof(XawTextPosition) * src->textSrc.num_text, buf); + for (i = 0; i < src->textSrc.num_text; i++) + pos[i] = ((TextWidget)src->textSrc.text[i])->text.old_insert; +#else + pos = buf; + *pos = ctx->text.old_insert; +#endif + +#ifndef OLDXAW + if (!GetBlockBoundaries(ctx, &from, &to)) { + EndAction(ctx); + XawStackFree(pos, buf); + return; + } - StartAction(ctx, event); + if (undo) { + src->textSrc.undo_state = True; + lbuf = _XawTextGetText(ctx, from, to); + endPos = ctx->text.lastPos; + } - from = SrcScan( ctx->text.source, ctx->text.insertPos, - XawstParagraph, XawsdLeft, 1, FALSE ); - to = SrcScan( ctx->text.source, from, - XawstParagraph, XawsdRight, 1, FALSE ); + if (FormRegion(ctx, from, to, pos, src->textSrc.num_text) == XawReplaceError) { +#else + from = SrcScan(ctx->text.source, ctx->text.insertPos, + XawstParagraph, XawsdLeft, 1, False); + to = SrcScan(ctx->text.source, from, + XawstParagraph, XawsdRight, 1, False); - if ( FormRegion( ctx, from, to ) == XawReplaceError ) - XBell( XtDisplay( w ), 0 ); - _XawTextSetScrollBars( ctx ); - EndAction( ctx ); -} + if (FormRegion(ctx, from, to, pos, 1) == XawReplaceError) { +#endif + XawStackFree(pos, buf); + XBell(XtDisplay(w), 0); +#ifndef OLDXAW + if (undo) { + src->textSrc.undo_state = False; + XtFree(lbuf); + } +#endif + } +#ifndef OLDXAW + else if (undo) { + /* makes the form-paragraph only one undo/redo step */ + unsigned llen, rlen, size; + XawTextBlock block; + + llen = to - from; + rlen = llen + (ctx->text.lastPos - endPos); + + block.firstPos = 0; + block.format = _XawTextFormat(ctx); + + rbuf = _XawTextGetText(ctx, from, from + rlen); + + size = XawTextFormat(ctx, XawFmtWide) ? sizeof(wchar_t) : sizeof(char); + if (llen != rlen || memcmp(lbuf, rbuf, llen * size)) { + block.ptr = lbuf; + block.length = llen; + _XawTextReplace(ctx, from, from + rlen, &block); + + src->textSrc.undo_state = False; + block.ptr = rbuf; + block.length = rlen; + _XawTextReplace(ctx, from, from + llen, &block); + } + else + src->textSrc.undo_state = False; + XtFree(lbuf); + XtFree(rbuf); + } + + for (i = 0; i < src->textSrc.num_text; i++) { + TextWidget tw = (TextWidget)src->textSrc.text[i]; + tw->text.old_insert = tw->text.insertPos = pos[i]; + _XawTextBuildLineTable(tw, SrcScan((Widget)src, tw->text.lt.top, XawstEOL, + XawsdLeft, 1, False), False); + tw->text.clear_to_eol = True; + } +#else + ctx->text.old_insert = ctx->text.insertPos = *pos; + _XawTextBuildLineTable(ctx, SrcScan(ctx->text.source, ctx->text.lt.top, + XawstEOL, XawsdLeft, 1, False), False); + ctx->text.clear_to_eol = True; +#endif + XawStackFree(pos, buf); + ctx->text.showposition = True; + + EndAction(ctx); +} /* TransposeCharacters() - action * * Swaps the character to the left of the mark - * with the character to the right of the mark. */ - -/* ARGSUSED */ -static void -TransposeCharacters(w, event, params, num_params) -Widget w; -XEvent* event; -String* params; -Cardinal* num_params; -{ - TextWidget ctx = (TextWidget) w; - XawTextPosition start, end; - XawTextBlock text; - char* buf; - int i; - - StartAction(ctx, event); - - /* Get bounds. */ - - start = SrcScan( ctx->text.source, ctx->text.insertPos, XawstPositions, - XawsdLeft, 1, TRUE ); - end = SrcScan( ctx->text.source, ctx->text.insertPos, XawstPositions, - XawsdRight, ctx->text.mult, TRUE ); - - /* Make sure we aren't at the very beginning or end of the buffer. */ - - if ( ( start == ctx->text.insertPos ) || ( end == ctx->text.insertPos ) ) { - XBell( XtDisplay( w ), 0 ); /* complain. */ - EndAction( ctx ); - return; - } - - ctx->text.insertPos = end; - - text.firstPos = 0; - text.format = _XawTextFormat(ctx); - - /* Retrieve text and swap the characters. */ - - if ( text.format == XawFmtWide) { - wchar_t wc; - wchar_t* wbuf; - - wbuf = (wchar_t*) _XawTextGetText(ctx, start, end); - text.length = wcslen( wbuf ); - wc = wbuf[ 0 ]; - for ( i = 1; i < text.length; i++ ) - wbuf[ i-1 ] = wbuf[ i ]; - wbuf[ i-1 ] = wc; - buf = (char*) wbuf; /* so that it gets assigned and freed */ - - } else { /* thus text.format == XawFmt8Bit */ - char c; - buf = _XawTextGetText( ctx, start, end ); - text.length = strlen( buf ); - c = buf[ 0 ]; - for ( i = 1; i < text.length; i++ ) - buf[ i-1 ] = buf[ i ]; - buf[ i-1 ] = c; - } - - text.ptr = buf; - - /* Store new text in source. */ - - if (_XawTextReplace (ctx, start, end, &text)) /* Unable to edit, complain. */ - XBell(XtDisplay(w), 0); - XtFree((char *) buf); - EndAction(ctx); + * with the character to the right of the mark */ +/*ARGSUSED*/ +static void +TransposeCharacters(Widget w, XEvent *event, + String *params, Cardinal *num_params) +{ + TextWidget ctx = (TextWidget)w; + XawTextPosition start, end; + XawTextBlock text; + char *buf; + int i, mult = MULT(ctx); + + if (mult < 0) { + ctx->text.mult = 1; + return; + } + + StartAction(ctx, event); + + /* Get bounds. */ + + start = SrcScan(ctx->text.source, ctx->text.insertPos, XawstPositions, + XawsdLeft, 1, True); + end = SrcScan(ctx->text.source, ctx->text.insertPos, XawstPositions, + XawsdRight, mult, True); + + /* Make sure we aren't at the very beginning or end of the buffer. */ + + if (start == ctx->text.insertPos || end == ctx->text.insertPos) { + XBell(XtDisplay(w), 0); /* complain. */ + EndAction(ctx); + return; + } + + ctx->text.from_left = -1; + ctx->text.insertPos = end; + + text.firstPos = 0; + text.format = _XawTextFormat(ctx); + + /* Retrieve text and swap the characters. */ + if (text.format == XawFmtWide) { + wchar_t wc; + wchar_t *wbuf; + + wbuf = (wchar_t*)_XawTextGetText(ctx, start, end); + text.length = wcslen(wbuf); + wc = wbuf[0]; + for (i = 1; i < text.length; i++) + wbuf[i - 1] = wbuf[i]; + wbuf[i - 1] = wc; + buf = (char*)wbuf; /* so that it gets assigned and freed */ + } + else { /* thus text.format == XawFmt8Bit */ + char c; + + buf = _XawTextGetText(ctx, start, end); + text.length = strlen(buf); + c = buf[0]; + for (i = 1; i < text.length; i++) + buf[i - 1] = buf[i]; + buf[i - 1] = c; + } + + text.ptr = buf; + + /* Store new text in source. */ + + if (_XawTextReplace (ctx, start, end, &text)) + XBell(XtDisplay(w), 0); + XtFree((char *)buf); + EndAction(ctx); } +#ifndef OLDXAW +/*ARGSUSED*/ +static void +Undo(Widget w, XEvent *event, String *params, Cardinal *num_params) +{ + TextWidget ctx = (TextWidget)w; + int mul = MULT(ctx); + Bool toggle = False; + + if (mul < 0) { + toggle = True; + _XawTextSrcToggleUndo((TextSrcObject)ctx->text.source); + ctx->text.mult = mul = -mul; + } + + StartAction(ctx, event); + for (; mul; --mul) + if (!_XawTextSrcUndo((TextSrcObject)ctx->text.source, &ctx->text.insertPos)) + break; + ctx->text.showposition = True; + + if (toggle) + _XawTextSrcToggleUndo((TextSrcObject)ctx->text.source); + EndAction(ctx); +} +#endif /* NoOp() - action * This action performs no action, and allows the user or * application programmer to unbind a translation. * * Note: If the parameter list contains the string "RingBell" then - * this action will ring the bell. + * this action will ring the bell. */ - /*ARGSUSED*/ static void -NoOp(w, event, params, num_params) -Widget w; -XEvent* event; -String* params; -Cardinal* num_params; +NoOp(Widget w, XEvent *event, String *params, Cardinal *num_params) { if (*num_params != 1) return; switch(params[0][0]) { - case 'R': - case 'r': - XBell(XtDisplay(w), 0); - default: /* Fall Through */ - break; + case 'R': + case 'r': + XBell(XtDisplay(w), 0); + /*FALLTROUGH*/ + default: + break; } } - + /* Reconnect() - action * This reconnects to the input method. The user will typically call * this action if/when connection has been severed, or when the app - * was started up before an IM was started up. + * was started up before an IM was started up */ +/*ARGSUSED*/ +static void +Reconnect(Widget w, XEvent *event, String *params, Cardinal *num_params) +{ + _XawImReconnect(w); +} + +#define CAPITALIZE 1 +#define DOWNCASE 2 +#define UPCASE 3 + +#ifdef NO_LIBC_I18N +static int +ToLower(int ch) +{ + char buf[2]; + + *buf = ch; + XmuNCopyISOLatin1Lowered(buf, buf, sizeof(buf)); + + return (*buf); +} + +static int +ToUpper(int ch) +{ + char buf[2]; + + *buf = ch; + XmuNCopyISOLatin1Uppered(buf, buf, sizeof(buf)); + + return (*buf); +} + +static int +IsAlnum(int ch) +{ + return ((ch >= '0' && ch <= '9') || ToUpper(ch) != ch || ToLower(ch) != ch); +} + +static int +IsLower(int ch) +{ + char upbuf[2]; + char lobuf[2]; + + *upbuf = *lobuf = ch; + XmuNCopyISOLatin1Lowered(lobuf, lobuf, sizeof(lobuf)); + XmuNCopyISOLatin1Uppered(upbuf, upbuf, sizeof(upbuf)); + + return (*lobuf != *upbuf && ch == *lobuf); +} + +static int +IsUpper(int ch) +{ + char upbuf[2]; + char lobuf[2]; + + *upbuf = *lobuf = ch; + XmuNCopyISOLatin1Lowered(lobuf, lobuf, sizeof(lobuf)); + XmuNCopyISOLatin1Uppered(upbuf, upbuf, sizeof(upbuf)); + + return (*lobuf != *upbuf && ch == *upbuf); +} +#else +#define ToLower tolower +#define ToUpper toupper +#define IsAlnum isalnum +#define IsLower islower +#define IsUpper isupper +#endif + +static void +CaseProc(Widget w, XEvent *event, int cmd) +{ + TextWidget ctx = (TextWidget)w; + short mul = MULT(ctx); + XawTextPosition left, right; + XawTextBlock block; + Bool changed = False; + unsigned char ch, mb[sizeof(wchar_t)]; + int i, count; + + if (mul > 0) + right = SrcScan(ctx->text.source, left = ctx->text.insertPos, + XawstAlphaNumeric, XawsdRight, mul, False); + else + left = SrcScan(ctx->text.source, right = ctx->text.insertPos, + XawstAlphaNumeric, XawsdLeft, 1 + -mul, False); + block.firstPos = 0; + block.format = _XawTextFormat(ctx); + block.length = right - left; + block.ptr = _XawTextGetText(ctx, left, right); + + count = 0; + if (block.format == XawFmt8Bit) + for (i = 0; i < block.length; i++) { + if (!IsAlnum(*mb = (unsigned char)block.ptr[i])) + count = 0; + else if (++count == 1 || cmd != CAPITALIZE) { + ch = cmd == DOWNCASE ? ToLower(*mb) : ToUpper(*mb); + if (ch != *mb) { + changed = True; + block.ptr[i] = ch; + } + } + else if (cmd == CAPITALIZE) { + if ((ch = ToLower(*mb)) != *mb) { + changed = True; + block.ptr[i] = ch; + } + } + } + else + for (i = 0; i < block.length; i++) { + wctomb((char*)mb, ((wchar_t*)block.ptr)[i]); + if (!IsAlnum(*mb)) + count = 0; + else if (++count == 1 || cmd != CAPITALIZE) { + ch = cmd == DOWNCASE ? ToLower(*mb) : ToUpper(*mb); + if (ch != *mb) { + changed = True; + ((wchar_t*)block.ptr)[i] = _Xaw_atowc(ch); + } + } + else if (cmd == CAPITALIZE) { + if ((ch = ToLower(*mb)) != *mb) { + changed = True; + ((wchar_t*)block.ptr)[i] = _Xaw_atowc(ch); + } + } + } + + StartAction(ctx, event); + if (changed && _XawTextReplace(ctx, left, right, &block) != XawEditDone) + XBell(XtDisplay(ctx), 0); + ctx->text.insertPos = right; + EndAction(ctx); + + XtFree(block.ptr); +} /*ARGSUSED*/ static void -Reconnect( w, event, params, num_params ) - Widget w; - XEvent* event; - String* params; - Cardinal* num_params; +CapitalizeWord(Widget w, XEvent *event, String *params, Cardinal *num_params) { - _XawImReconnect( w ); + CaseProc(w, event, CAPITALIZE); } - -XtActionsRec _XawTextActionsTable[] = { +/*ARGSUSED*/ +static void +DowncaseWord(Widget w, XEvent *event, String *params, Cardinal *num_params) +{ + CaseProc(w, event, DOWNCASE); +} -/* motion bindings */ - - {"forward-character", MoveForwardChar}, - {"backward-character", MoveBackwardChar}, - {"forward-word", MoveForwardWord}, - {"backward-word", MoveBackwardWord}, - {"forward-paragraph", MoveForwardParagraph}, - {"backward-paragraph", MoveBackwardParagraph}, - {"beginning-of-line", MoveToLineStart}, - {"end-of-line", MoveToLineEnd}, - {"next-line", MoveNextLine}, - {"previous-line", MovePreviousLine}, - {"next-page", MoveNextPage}, - {"previous-page", MovePreviousPage}, - {"beginning-of-file", MoveBeginningOfFile}, - {"end-of-file", MoveEndOfFile}, - {"scroll-one-line-up", ScrollOneLineUp}, - {"scroll-one-line-down", ScrollOneLineDown}, - -/* delete bindings */ - - {"delete-next-character", DeleteForwardChar}, - {"delete-previous-character", DeleteBackwardChar}, - {"delete-next-word", DeleteForwardWord}, - {"delete-previous-word", DeleteBackwardWord}, - {"delete-selection", DeleteCurrentSelection}, - -/* kill bindings */ - - {"kill-word", KillForwardWord}, - {"backward-kill-word", KillBackwardWord}, - {"kill-selection", KillCurrentSelection}, - {"kill-to-end-of-line", KillToEndOfLine}, - {"kill-to-end-of-paragraph", KillToEndOfParagraph}, - -/* new line stuff */ - - {"newline-and-indent", InsertNewLineAndIndent}, - {"newline-and-backup", InsertNewLineAndBackup}, - {"newline", InsertNewLine}, - -/* Selection stuff */ - - {"select-word", SelectWord}, - {"select-all", SelectAll}, - {"select-start", SelectStart}, - {"select-adjust", SelectAdjust}, - {"select-end", SelectEnd}, +/*ARGSUSED*/ +static void +UpcaseWord(Widget w, XEvent *event, String *params, Cardinal *num_params) +{ + CaseProc(w, event, UPCASE); +} +#undef CAPITALIZE +#undef DOWNCASE +#undef UPCASE + +XtActionsRec _XawTextActionsTable[] = { + /* motion */ + {"forward-character", MoveForwardChar}, + {"backward-character", MoveBackwardChar}, + {"forward-word", MoveForwardWord}, + {"backward-word", MoveBackwardWord}, + {"forward-paragraph", MoveForwardParagraph}, + {"backward-paragraph", MoveBackwardParagraph}, + {"beginning-of-line", MoveToLineStart}, + {"end-of-line", MoveToLineEnd}, + {"next-line", MoveNextLine}, + {"previous-line", MovePreviousLine}, + {"next-page", MoveNextPage}, + {"previous-page", MovePreviousPage}, + {"beginning-of-file", MoveBeginningOfFile}, + {"end-of-file", MoveEndOfFile}, + {"scroll-one-line-up", ScrollOneLineUp}, + {"scroll-one-line-down", ScrollOneLineDown}, + + /* delete */ + {"delete-next-character", DeleteForwardChar}, + {"delete-previous-character", DeleteBackwardChar}, + {"delete-next-word", DeleteForwardWord}, + {"delete-previous-word", DeleteBackwardWord}, + {"delete-selection", DeleteCurrentSelection}, + {"delete", Delete}, + + /* kill */ + {"kill-word", KillForwardWord}, + {"backward-kill-word", KillBackwardWord}, + {"kill-selection", KillCurrentSelection}, + {"kill-to-end-of-line", KillToEndOfLine}, + {"kill-to-end-of-paragraph", KillToEndOfParagraph}, + + /* new line */ + {"newline-and-indent", InsertNewLineAndIndent}, + {"newline-and-backup", InsertNewLineAndBackup}, + {"newline", InsertNewLine}, + + /* selection */ + {"select-word", SelectWord}, + {"select-all", SelectAll}, + {"select-start", SelectStart}, + {"select-adjust", SelectAdjust}, + {"select-end", SelectEnd}, {"select-save", SelectSave}, - {"extend-start", ExtendStart}, - {"extend-adjust", ExtendAdjust}, + {"extend-start", ExtendStart}, + {"extend-adjust", ExtendAdjust}, {"extend-end", ExtendEnd}, {"insert-selection", InsertSelection}, -/* Miscellaneous */ - - {"redraw-display", RedrawDisplay}, - {"insert-file", _XawTextInsertFile}, - {"search", _XawTextSearch}, - {"insert-char", InsertChar}, + /* miscellaneous */ + {"redraw-display", RedrawDisplay}, + {"insert-file", _XawTextInsertFile}, + {"search", _XawTextSearch}, + {"insert-char", InsertChar}, {"insert-string", InsertString}, - {"focus-in", TextFocusIn}, - {"focus-out", TextFocusOut}, - {"enter-window", TextEnterWindow}, - {"leave-window", TextLeaveWindow}, + {"focus-in", TextFocusIn}, + {"focus-out", TextFocusOut}, + {"enter-window", TextEnterWindow}, + {"leave-window", TextLeaveWindow}, {"display-caret", DisplayCaret}, - {"multiply", Multiply}, - {"form-paragraph", FormParagraph}, - {"transpose-characters", TransposeCharacters}, - {"no-op", NoOp}, - -/* Action to bind special translations for text Dialogs. */ - - {"InsertFileAction", _XawTextInsertFileAction}, - {"DoSearchAction", _XawTextDoSearchAction}, - {"DoReplaceAction", _XawTextDoReplaceAction}, - {"SetField", _XawTextSetField}, - {"PopdownSearchAction", _XawTextPopdownSearchAction}, - -/* Reconnect to Input Method */ - {"reconnect-im", Reconnect} /* Li Yuhong, Omron KK, 1991 */ + {"multiply", Multiply}, + {"form-paragraph", FormParagraph}, + {"transpose-characters", TransposeCharacters}, + {"set-keyboard-focus", SetKeyboardFocus}, +#ifndef OLDXAW + {"numeric", Numeric}, + {"undo", Undo}, + {"keyboard-reset", KeyboardReset}, + {"kill-ring-yank", KillRingYank}, + {"toggle-overwrite", ToggleOverwrite}, + {"indent", Indent}, +#endif + {"no-op", NoOp}, + + /* case transformations */ + {"capitalize-word", CapitalizeWord}, + {"downcase-word", DowncaseWord}, + {"upcase-word", UpcaseWord}, + + /* action to bind translations for text dialogs */ + {"InsertFileAction", _XawTextInsertFileAction}, + {"DoSearchAction", _XawTextDoSearchAction}, + {"DoReplaceAction", _XawTextDoReplaceAction}, + {"SetField", _XawTextSetField}, + {"PopdownSearchAction", _XawTextPopdownSearchAction}, + + /* reconnect to Input Method */ + {"reconnect-im", Reconnect} /* Li Yuhong, Omron KK, 1991 */ }; Cardinal _XawTextActionsTableCount = XtNumber(_XawTextActionsTable); diff --git a/src/TextPop.c b/src/TextPop.c index 694be4c..df877c4 100644 --- a/src/TextPop.c +++ b/src/TextPop.c @@ -26,8 +26,9 @@ in this Software without prior written authorization from The Open Group. */ -/************************************************************ - * +/* $XFree86: xc/lib/Xaw/TextPop.c,v 1.20 2001/12/14 19:54:44 dawes Exp $ */ + +/* * This file is broken up into three sections one dealing with * each of the three popups created here: * @@ -44,28 +45,23 @@ in this Software without prior written authorization from The Open Group. * void _XawTextDoSearchAction(w, event, params, num_params); * void _XawTextDoReplaceAction(w, event, params, num_params); * void _XawTextInsertFile(w, event, params, num_params); - * - *************************************************************/ + */ +#include <stdio.h> +#include <errno.h> #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> #include <X11/Shell.h> - +#include <X11/Xos.h> +#include <X11/Xmu/CharSet.h> +#include <X11/Xmu/SysUtil.h> #include <X11/Xaw/TextP.h> #include <X11/Xaw/AsciiText.h> #include <X11/Xaw/Cardinals.h> #include <X11/Xaw/Command.h> #include <X11/Xaw/Form.h> #include <X11/Xaw/Toggle.h> -#include <X11/Xmu/CharSet.h> #include "XawI18n.h" -#include <stdio.h> -#include <X11/Xos.h> /* for O_RDONLY */ -#include <errno.h> - -#ifdef X_NOT_STDC_ENV -extern int errno; -#endif static char* INSERT_FILE = "Enter Filename:"; static char* SEARCH_LABEL_1 = "Use <Tab> to change fields."; @@ -78,1316 +74,1413 @@ static char* TEXT_NAME = "text"; #define R_OFFSET 1 -static void CenterWidgetOnPoint(), PopdownSearch(), DoInsert(), _SetField(); -static void InitializeSearchWidget(), SetResource(), SetSearchLabels(); -static void DoReplaceOne(), DoReplaceAll(); -static Widget CreateDialog(), GetShell(); -static void SetWMProtocolTranslations(); -static Boolean DoSearch(), SetResourceByName(), Replace(); -static String GetString(); +typedef void (*AddFunc)(Widget, char*, Widget); + +/* + * Prototypes + */ +static void _SetField(Widget, Widget); +static void AddSearchChildren(Widget, char*, Widget); +static void AddInsertFileChildren(Widget, char*, Widget); +static void CenterWidgetOnPoint(Widget, XEvent*); +static Widget CreateDialog(Widget, String, String, AddFunc); +static void DoInsert(Widget, XtPointer, XtPointer); +static void DoReplaceAll(Widget, XtPointer, XtPointer); +static void DoReplaceOne(Widget, XtPointer, XtPointer); +static Bool DoSearch(struct SearchAndReplace*); +static Widget GetShell(Widget); +static String GetString(Widget); +static String GetStringRaw(Widget); +static void InitializeSearchWidget(struct SearchAndReplace*, + XawTextScanDirection, Bool); +static Bool InParams(String, String*, unsigned int); +static Bool InsertFileNamed(Widget, char*); +static void PopdownFileInsert(Widget, XtPointer, XtPointer); +static void PopdownSearch(Widget, XtPointer, XtPointer); +static Bool Replace(struct SearchAndReplace*, Bool, Bool); +static void SearchButton(Widget, XtPointer, XtPointer); +static void SetResource(Widget, char*, XtArgVal); +static Bool SetResourceByName(Widget, char*, char*, XtArgVal); +static void SetSearchLabels(struct SearchAndReplace*, String, String, Bool); +static void SetWMProtocolTranslations(Widget); + +/* + * Actions + */ +static void WMProtocols(Widget, XEvent*, String*, Cardinal*); -static String GetStringRaw(); +/* + * External Actions + */ +void _XawTextDoReplaceAction(Widget, XEvent*, String*, Cardinal*); +void _XawTextDoSearchAction(Widget, XEvent*, String*, Cardinal*); +void _XawTextInsertFile(Widget, XEvent*, String*, Cardinal*); +void _XawTextInsertFileAction(Widget, XEvent*, String*, Cardinal*); +void _XawTextPopdownSearchAction(Widget, XEvent*, String*, Cardinal*); +void _XawTextSearch(Widget, XEvent*, String*, Cardinal*); +void _XawTextSetField(Widget, XEvent*, String*, Cardinal*); -static void AddInsertFileChildren(); -static Boolean InsertFileNamed(); -static void AddSearchChildren(); +/* + * From Text.c + */ +char *_XawTextGetText(TextWidget, XawTextPosition, XawTextPosition); +void _XawTextShowPosition(TextWidget); +/* + * Initialization + */ static char radio_trans_string[] = - "<Btn1Down>,<Btn1Up>: set() notify()"; +"<Btn1Down>,<Btn1Up>:" "set() notify()\n" +; static char search_text_trans[] = - "~Shift<Key>Return: DoSearchAction(Popdown) \n\ - Shift<Key>Return: DoSearchAction() SetField(Replace) \n\ - Ctrl<Key>q,<Key>Tab: insert-char() \n\ - Ctrl<Key>c: PopdownSearchAction() \n\ - <Btn1Down>: select-start() SetField(Search) \n\ - <Key>Tab: DoSearchAction() SetField(Replace)"; +"~s<Key>Return:" "DoSearchAction(Popdown)\n" +"s<Key>Return:" "DoSearchAction() SetField(Replace)\n" +"c<Key>c:" "PopdownSearchAction()\n" +"<Btn1Down>:" "select-start() SetField(Search)\n" +"<Key>Tab:" "DoSearchAction() SetField(Replace)\n" +; static char rep_text_trans[] = - "~Shift<Key>Return: DoReplaceAction(Popdown) \n\ - Shift<Key>Return: SetField(Search) \n\ - Ctrl<Key>q,<Key>Tab: insert-char() \n\ - Ctrl<Key>c: PopdownSearchAction() \n\ - <Btn1Down>: select-start() DoSearchAction() SetField(Replace)\n\ - <Key>Tab: SetField(Search)"; - -/************************************************************ - * - * This section of the file contains all the functions that - * the file insert dialog box uses. - * - ************************************************************/ +"~s<Key>Return:" "DoReplaceAction(Popdown)\n" +"s<Key>Return:" "SetField(Search)\n" +"c<Key>c:" "PopdownSearchAction()\n" +"<Btn1Down>:" "select-start() DoSearchAction() SetField(Replace)\n" +"<Key>Tab:" "SetField(Search)\n" +; -/* Function Name: _XawTextInsertFileAction - * Description: Action routine that can be bound to dialog box's - * Text Widget that will insert a file into the main - * Text Widget. - * Arguments: (Standard Action Routine args) - * Returns: none. +/* + * Implementation + */ +/* + * This section of the file contains all the functions that + * the file insert dialog box uses */ -/* ARGSUSED */ +/* + * Function: + * _XawTextInsertFileAction + * + * Description: + * Action routine that can be bound to dialog box's Text Widget + * that will insert a file into the main Text Widget. + */ +/*ARGSUSED*/ void -_XawTextInsertFileAction(w, event, params, num_params) -Widget w; -XEvent *event; -String * params; -Cardinal * num_params; +_XawTextInsertFileAction(Widget w, XEvent *event, + String *params, Cardinal *num_params) { - DoInsert(w, (XtPointer) XtParent(XtParent(XtParent(w))), (XtPointer)NULL); + DoInsert(w, (XtPointer)XtParent(XtParent(XtParent(w))), NULL); } -/* Function Name: _XawTextInsertFile - * Description: Action routine that can be bound to the text widget - * it will popup the insert file dialog box. - * Arguments: w - the text widget. - * event - X Event (used to get x and y location). - * params, num_params - the parameter list. - * Returns: none. +/* + * Function: + * _XawTextInsertFile + * + * Parameters: + * w - text widget + * event - X Event (used to get x and y location) + * params - parameter list + * num_params - "" * - * NOTE: + * Description: + * Action routine that can be bound to the text widget + * it will popup the insert file dialog box. * - * The parameter list may contain one entry. + * Note: + * The parameter list may contain one entry * - * Entry: This entry is optional and contains the value of the default - * file to insert. + * Entry: + * This entry is optional and contains the value of the default + * file to insert */ - void -_XawTextInsertFile(w, event, params, num_params) -Widget w; -XEvent *event; -String * params; -Cardinal * num_params; +_XawTextInsertFile(Widget w, XEvent *event, + String *params, Cardinal *num_params) { - TextWidget ctx = (TextWidget)w; - char * ptr; - XawTextEditType edit_mode; - Arg args[1]; + TextWidget ctx = (TextWidget)w; + char *ptr; + XawTextEditType edit_mode; + Arg args[1]; - XtSetArg(args[0], XtNeditType,&edit_mode); - XtGetValues(ctx->text.source, args, ONE); + XtSetArg(args[0], XtNeditType, &edit_mode); + XtGetValues(ctx->text.source, args, 1); - if (edit_mode != XawtextEdit) { - XBell(XtDisplay(w), 0); - return; - } + if (edit_mode != XawtextEdit) { + XBell(XtDisplay(w), 0); + return; + } - if (*num_params == 0) - ptr = ""; - else - ptr = params[0]; + if (*num_params == 0) + ptr = ""; + else + ptr = params[0]; - if (!ctx->text.file_insert) { - ctx->text.file_insert = CreateDialog(w, ptr, "insertFile", - AddInsertFileChildren); - XtRealizeWidget(ctx->text.file_insert); - SetWMProtocolTranslations(ctx->text.file_insert); - } - - CenterWidgetOnPoint(ctx->text.file_insert, event); - XtPopup(ctx->text.file_insert, XtGrabNone); + if (!ctx->text.file_insert) { + ctx->text.file_insert = CreateDialog(w, ptr, "insertFile", + AddInsertFileChildren); + XtRealizeWidget(ctx->text.file_insert); + SetWMProtocolTranslations(ctx->text.file_insert); + } + + CenterWidgetOnPoint(ctx->text.file_insert, event); + XtPopup(ctx->text.file_insert, XtGrabNone); } -/* Function Name: PopdownFileInsert - * Description: Pops down the file insert button. - * Arguments: w - the widget that caused this action. - * closure - a pointer to the main text widget that - * popped up this dialog. - * call_data - *** NOT USED ***. - * Returns: none. +/* + * Function: + * PopdownFileInsert + * + * Parameters: + * w - widget that caused this action + * closure - pointer to the main text widget that popped up this dialog + * call_data - (not used) + * + * Description: + * Pops down the file insert button */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -PopdownFileInsert(w, closure, call_data) -Widget w; /* The Dialog Button Pressed. */ -XtPointer closure; /* Text Widget. */ -XtPointer call_data; /* unused */ +PopdownFileInsert(Widget w, XtPointer closure, XtPointer call_data) { - TextWidget ctx = (TextWidget) closure; + TextWidget ctx = (TextWidget)closure; - XtPopdown( ctx->text.file_insert ); - (void) SetResourceByName( ctx->text.file_insert, LABEL_NAME, - XtNlabel, (XtArgVal) INSERT_FILE); + XtPopdown(ctx->text.file_insert); + (void)SetResourceByName(ctx->text.file_insert, LABEL_NAME, + XtNlabel, (XtArgVal)INSERT_FILE); } -/* Function Name: DoInsert - * Description: Actually insert the file named in the text widget - * of the file dialog. - * Arguments: w - the widget that activated this callback. - * closure - a pointer to the text widget to insert the - * file into. - * Returns: none. +/* + * Function: + * DoInsert + * + * Parameters: + * w - widget that activated this callback + * closure - pointer to the text widget to insert the file into + * + * Description: + * Actually insert the file named in the text widget of the file dialog */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -DoInsert(w, closure, call_data) -Widget w; /* The Dialog Button Pressed. */ -XtPointer closure; /* Text Widget */ -XtPointer call_data; /* unused */ +DoInsert(Widget w, XtPointer closure, XtPointer call_data) { - TextWidget ctx = (TextWidget) closure; - char buf[BUFSIZ], msg[BUFSIZ]; - Widget temp_widget; - - (void) sprintf(buf, "%s.%s", FORM_NAME, TEXT_NAME); - if ( (temp_widget = XtNameToWidget(ctx->text.file_insert, buf)) == NULL ) { - (void) strcpy(msg, - "*** Error: Could not get text widget from file insert popup"); - } - else - if (InsertFileNamed( (Widget) ctx, GetString( temp_widget ))) { - PopdownFileInsert(w, closure, call_data); - return; + TextWidget ctx = (TextWidget)closure; + char buf[BUFSIZ], msg[BUFSIZ]; + Widget temp_widget; + + (void)XmuSnprintf(buf, sizeof(buf), "%s.%s", FORM_NAME, TEXT_NAME); + if ((temp_widget = XtNameToWidget(ctx->text.file_insert, buf)) == NULL) { + (void)strcpy(msg, + "Error: Could not get text widget from file insert popup"); + } + else if (InsertFileNamed((Widget)ctx, GetString(temp_widget))) { + PopdownFileInsert(w, closure, call_data); + return; } else - (void) sprintf( msg, "*** Error: %s ***", strerror(errno)); + (void)XmuSnprintf(msg, sizeof(msg), "Error: %s", strerror(errno)); - (void)SetResourceByName(ctx->text.file_insert, - LABEL_NAME, XtNlabel, (XtArgVal) msg); - XBell(XtDisplay(w), 0); + (void)SetResourceByName(ctx->text.file_insert, + LABEL_NAME, XtNlabel, (XtArgVal)msg); + XBell(XtDisplay(w), 0); } -/* Function Name: InsertFileNamed - * Description: Inserts a file into the text widget. - * Arguments: tw - The text widget to insert this file into. - * str - name of the file to insert. - * Returns: TRUE if the insert was sucessful, FALSE otherwise. +/* + * Function: + * InsertFileNamed + * + * Parameters: + * tw - text widget to insert this file into + * str - name of the file to insert + * + * Description: + * Inserts a file into the text widget. + * + * Returns: + * True if the insert was sucessful, False otherwise. */ +static Bool +InsertFileNamed(Widget tw, char *str) +{ + FILE *file; + XawTextBlock text; + XawTextPosition pos; + if (str == NULL || strlen(str) == 0 || (file = fopen(str, "r")) == NULL) + return (False); -static Boolean -InsertFileNamed(tw, str) -Widget tw; -char *str; -{ - FILE *file; - XawTextBlock text; - XawTextPosition pos; - - if ( (str == NULL) || (strlen(str) == 0) || - ((file = fopen(str, "r")) == NULL)) - return(FALSE); - - pos = XawTextGetInsertionPoint(tw); - - fseek(file, 0L, 2); - - - text.firstPos = 0; - text.length = (ftell(file))/sizeof(unsigned char); - text.ptr = XtMalloc((text.length + 1) * sizeof(unsigned char)); - text.format = XawFmt8Bit; - - fseek(file, 0L, 0); - if (fread(text.ptr, sizeof(unsigned char), text.length, file) != text.length) - XtErrorMsg("readError", "insertFileNamed", "XawError", - "fread returned error.", NULL, NULL); - - /* DELETE if (text.format == XawFmtWide) { - wchar_t* _XawTextMBToWC(); - wchar_t* wstr; - wstr = _XawTextMBToWC(XtDisplay(tw), text.ptr, &(text.length)); - wstr[text.length] = NULL; - XtFree(text.ptr); - text.ptr = (char *)wstr; - } else { - (text.ptr)[text.length] = '\0'; - }*/ - - if (XawTextReplace(tw, pos, pos, &text) != XawEditDone) { - XtFree(text.ptr); - fclose(file); - return(FALSE); - } - pos += text.length; - XtFree(text.ptr); - fclose(file); - XawTextSetInsertionPoint(tw, pos); - return(TRUE); -} + pos = XawTextGetInsertionPoint(tw); + fseek(file, 0L, 2); -/* Function Name: AddInsertFileChildren - * Description: Adds all children to the InsertFile dialog widget. - * Arguments: form - the form widget for the insert dialog widget. - * ptr - a pointer to the initial string for the Text Widget. - * tw - the main text widget. - * Returns: none - */ + text.firstPos = 0; + text.length = ftell(file); + text.ptr = XtMalloc(text.length + 1); + text.format = XawFmt8Bit; + + fseek(file, 0L, 0); + if (fread(text.ptr, 1, text.length, file) != text.length) + XtErrorMsg("readError", "insertFileNamed", "XawError", + "fread returned error", NULL, NULL); + if (XawTextReplace(tw, pos, pos, &text) != XawEditDone) { + XtFree(text.ptr); + fclose(file); + return (False); + } + pos += text.length; + XtFree(text.ptr); + fclose(file); + XawTextSetInsertionPoint(tw, pos); + _XawTextShowPosition((TextWidget)tw); + + return (True); +} + +/* + * Function: + * AddInsertFileChildren + * + * Parameters: + * form - form widget for the insert dialog widget + * ptr - pointer to the initial string for the Text Widget + * tw - main text widget + * + * Description: + * Adds all children to the InsertFile dialog widget. + */ static void -AddInsertFileChildren(form, ptr, tw) -Widget form, tw; -char * ptr; +AddInsertFileChildren(Widget form, char *ptr, Widget tw) { - Arg args[10]; - Cardinal num_args; - Widget label, text, cancel, insert; - XtTranslations trans; - - num_args = 0; - XtSetArg(args[num_args], XtNlabel, INSERT_FILE);num_args++; - XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; - XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; - XtSetArg(args[num_args], XtNresizable, TRUE ); num_args++; - XtSetArg(args[num_args], XtNborderWidth, 0 ); num_args++; - label = XtCreateManagedWidget (LABEL_NAME, labelWidgetClass, form, - args, num_args); - - num_args = 0; - XtSetArg(args[num_args], XtNfromVert, label); num_args++; - XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; - XtSetArg(args[num_args], XtNright, XtChainRight); num_args++; - XtSetArg(args[num_args], XtNeditType, XawtextEdit); num_args++; - XtSetArg(args[num_args], XtNresizable, TRUE); num_args++; - XtSetArg(args[num_args], XtNresize, XawtextResizeWidth); num_args++; - XtSetArg(args[num_args], XtNstring, ptr); num_args++; - text = XtCreateManagedWidget(TEXT_NAME, asciiTextWidgetClass, form, - args, num_args); - - num_args = 0; - XtSetArg(args[num_args], XtNlabel, "Insert File"); num_args++; - XtSetArg(args[num_args], XtNfromVert, text); num_args++; - XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; - XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; - insert = XtCreateManagedWidget("insert", commandWidgetClass, form, - args, num_args); + Arg args[10]; + Cardinal num_args; + Widget label, text, cancel, insert; + XtTranslations trans; - num_args = 0; - XtSetArg(args[num_args], XtNlabel, "Cancel"); num_args++; - XtSetArg(args[num_args], XtNfromVert, text); num_args++; - XtSetArg(args[num_args], XtNfromHoriz, insert); num_args++; - XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; - XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; - cancel = XtCreateManagedWidget(DISMISS_NAME, commandWidgetClass, form, + num_args = 0; + XtSetArg(args[num_args], XtNlabel, INSERT_FILE); num_args++; + XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNresizable, True); num_args++; + XtSetArg(args[num_args], XtNborderWidth, 0); num_args++; + label = XtCreateManagedWidget(LABEL_NAME, labelWidgetClass, form, + args, num_args); + + num_args = 0; + XtSetArg(args[num_args], XtNfromVert, label); num_args++; + XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNright, XtChainRight); num_args++; + XtSetArg(args[num_args], XtNeditType, XawtextEdit); num_args++; + XtSetArg(args[num_args], XtNresizable, True); num_args++; + XtSetArg(args[num_args], XtNstring, ptr); num_args++; + text = XtCreateManagedWidget(TEXT_NAME, asciiTextWidgetClass, form, args, num_args); - XtAddCallback(cancel, XtNcallback, PopdownFileInsert, (XtPointer) tw); - XtAddCallback(insert, XtNcallback, DoInsert, (XtPointer) tw); + num_args = 0; + XtSetArg(args[num_args], XtNlabel, "Insert File"); num_args++; + XtSetArg(args[num_args], XtNfromVert, text); num_args++; + XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; + insert = XtCreateManagedWidget("insert", commandWidgetClass, form, + args, num_args); - XtSetKeyboardFocus(form, text); + num_args = 0; + XtSetArg(args[num_args], XtNlabel, "Cancel"); num_args++; + XtSetArg(args[num_args], XtNfromVert, text); num_args++; + XtSetArg(args[num_args], XtNfromHoriz, insert); num_args++; + XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; + cancel = XtCreateManagedWidget(DISMISS_NAME, commandWidgetClass, form, + args, num_args); -/* - * Bind <CR> to insert file. - */ + XtAddCallback(cancel, XtNcallback, PopdownFileInsert, (XtPointer)tw); + XtAddCallback(insert, XtNcallback, DoInsert, (XtPointer)tw); - trans = XtParseTranslationTable("<Key>Return: InsertFileAction()"); - XtOverrideTranslations(text, trans); + XtSetKeyboardFocus(form, text); + /* + * Bind <CR> to insert file + */ + trans = XtParseTranslationTable("<Key>Return:InsertFileAction()"); + XtOverrideTranslations(text, trans); } -/************************************************************ - * +/* * This section of the file contains all the functions that - * the search dialog box uses. + * the search dialog box uses + */ +/* + * Function: + * _XawTextDoSearchAction * - ************************************************************/ - -/* Function Name: _XawTextDoSearchAction - * Description: Action routine that can be bound to dialog box's - * Text Widget that will search for a string in the main - * Text Widget. - * Arguments: (Standard Action Routine args) - * Returns: none. + * Description: + * Action routine that can be bound to dialog box's Text Widget that + * will search for a string in the main Text Widget. * * Note: - * * If the search was sucessful and the argument popdown is passed to * this action routine then the widget will automatically popdown the - * search widget. + * search widget */ - -/* ARGSUSED */ +/*ARGSUSED*/ void -_XawTextDoSearchAction(w, event, params, num_params) -Widget w; -XEvent *event; -String * params; -Cardinal * num_params; +_XawTextDoSearchAction(Widget w, XEvent *event, + String *params, Cardinal *num_params) { - TextWidget tw = (TextWidget) XtParent(XtParent(XtParent(w))); - Boolean popdown = FALSE; + TextWidget tw = (TextWidget)XtParent(XtParent(XtParent(w))); + Bool popdown = False; - if ( (*num_params == 1) && - ((params[0][0] == 'p') || (params[0][0] == 'P')) ) - popdown = TRUE; + if (*num_params == 1 && (params[0][0] == 'p' || params[0][0] == 'P')) + popdown = True; - if (DoSearch(tw->text.search) && popdown) - PopdownSearch(w, (XtPointer) tw->text.search, (XtPointer)NULL); + if (DoSearch(tw->text.search) && popdown) + PopdownSearch(w, (XtPointer)tw->text.search, NULL); } -/* Function Name: _XawTextPopdownSearchAction - * Description: Action routine that can be bound to dialog box's - * Text Widget that will popdown the search widget. - * Arguments: (Standard Action Routine args) - * Returns: none. +/* + * Function: + * _XawTextPopdownSearchAction + * + * Description: + * Action routine that can be bound to dialog box's Text Widget that + * will popdown the search widget. */ - -/* ARGSUSED */ +/*ARGSUSED*/ void -_XawTextPopdownSearchAction(w, event, params, num_params) -Widget w; -XEvent *event; -String * params; -Cardinal * num_params; +_XawTextPopdownSearchAction(Widget w, XEvent *event, + String *params, Cardinal *num_params) { - TextWidget tw = (TextWidget) XtParent(XtParent(XtParent(w))); + TextWidget tw = (TextWidget)XtParent(XtParent(XtParent(w))); - PopdownSearch(w, (XtPointer) tw->text.search, (XtPointer)NULL); + PopdownSearch(w, (XtPointer)tw->text.search, NULL); } -/* Function Name: PopdownSeach - * Description: Pops down the search widget and resets it. - * Arguments: w - *** NOT USED ***. - * closure - a pointer to the search structure. - * call_data - *** NOT USED ***. - * Returns: none +/* + * Function: + * PopdownSearch + * + * Parameters: + * w - (not used) + * closure - pointer to the search structure + * call_data - (not used) + * + * Description: + * Pops down the search widget and resets it */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -PopdownSearch(w, closure, call_data) -Widget w; -XtPointer closure; -XtPointer call_data; +PopdownSearch(Widget w, XtPointer closure, XtPointer call_data) { - struct SearchAndReplace * search = (struct SearchAndReplace *) closure; + struct SearchAndReplace *search = (struct SearchAndReplace *)closure; - XtPopdown( search->search_popup ); - SetSearchLabels(search, SEARCH_LABEL_1, SEARCH_LABEL_2, FALSE); + XtPopdown(search->search_popup); + SetSearchLabels(search, SEARCH_LABEL_1, SEARCH_LABEL_2, False); } -/* Function Name: SearchButton - * Description: Performs a search when the button is clicked. - * Arguments: w - *** NOT USED **. - * closure - a pointer to the search info. - * call_data - *** NOT USED ***. - * Returns: +/* + * Function: + * SearchButton + * + * Arguments: + * w - (not used) + * closure - pointer to the search info + * call_data - (not used) + * + * Description: + * Performs a search when the button is clicked. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -SearchButton(w, closure, call_data) -Widget w; -XtPointer closure; -XtPointer call_data; +SearchButton(Widget w, XtPointer closure, XtPointer call_data) { - (void) DoSearch( (struct SearchAndReplace *) closure ); + (void)DoSearch((struct SearchAndReplace *)closure); } -/* Function Name: _XawTextSearch - * Description: Action routine that can be bound to the text widget - * it will popup the search dialog box. - * Arguments: w - the text widget. - * event - X Event (used to get x and y location). - * params, num_params - the parameter list. - * Returns: none. +/* + * Function: + * _XawTextSearch * - * NOTE: + * Parameters: + * w - text widget + * event - X Event (used to get x and y location) + * params - parameter list + * num_params - "" * - * The parameter list contains one or two entries that may be the following. + * Description: + * Action routine that can be bound to the text widget + * it will popup the search dialog box. + * + * Note: + * The parameter list contains one or two entries that may be + * the following. * - * First Entry: The first entry is the direction to search by default. - * This arguement must be specified and may have a value of - * "left" or "right". + * First Entry: + * The first entry is the direction to search by default. + * This arguement must be specified and may have a value of + * "left" or "right". * - * Second Entry: This entry is optional and contains the value of the default - * string to search for. + * Second Entry: + * This entry is optional and contains the value of the default + * string to search for. */ -#define SEARCH_HEADER ("Text Widget - Search():") - +#define SEARCH_HEADER "Text Widget - Search():" void -_XawTextSearch(w, event, params, num_params) -Widget w; -XEvent *event; -String * params; -Cardinal * num_params; +_XawTextSearch(Widget w, XEvent *event, String *params, Cardinal *num_params) { - TextWidget ctx = (TextWidget)w; - XawTextScanDirection dir; - char * ptr, buf[BUFSIZ]; - XawTextEditType edit_mode; - Arg args[1]; - -#ifdef notdef - if (ctx->text.source->Search == NULL) { - XBell(XtDisplay(w), 0); - return; - } -#endif + TextWidget ctx = (TextWidget)w; + XawTextScanDirection dir; + char *ptr, buf[BUFSIZ]; + XawTextEditType edit_mode; + Arg args[1]; + wchar_t wcs[1]; + + if (*num_params < 1 || *num_params > 2) { + (void)XmuSnprintf(buf, sizeof(buf), "%s %s\n%s", SEARCH_HEADER, + "This action must have only", + "one or two parameters"); + XtAppWarning(XtWidgetToApplicationContext(w), buf); + return; + } - if ( (*num_params < 1) || (*num_params > 2) ) { - (void) sprintf(buf, "%s %s\n%s", SEARCH_HEADER, - "This action must have only", - "one or two parameters"); - XtAppWarning(XtWidgetToApplicationContext(w), buf); - return; - } - - if (*num_params == 2 ) - ptr = params[1]; - else - if (_XawTextFormat(ctx) == XawFmtWide) { - /*This just does the equivalent of ptr = ""L, a waste because params[1] isnt W aligned.*/ - ptr = (char *)XtMalloc(sizeof(wchar_t)); - *((wchar_t*)ptr) = (wchar_t)0; - } else - ptr = ""; - - switch(params[0][0]) { - case 'b': /* Left. */ - case 'B': - dir = XawsdLeft; - break; - case 'f': /* Right. */ - case 'F': - dir = XawsdRight; - break; - default: - (void) sprintf(buf, "%s %s\n%s", SEARCH_HEADER, - "The first parameter must be", - "Either 'backward' or 'forward'"); - XtAppWarning(XtWidgetToApplicationContext(w), buf); - return; - } - - if (ctx->text.search== NULL) { - ctx->text.search = XtNew(struct SearchAndReplace); - ctx->text.search->search_popup = CreateDialog(w, ptr, "search", - AddSearchChildren); - XtRealizeWidget(ctx->text.search->search_popup); - SetWMProtocolTranslations(ctx->text.search->search_popup); - } - else if (*num_params > 1) { - XtVaSetValues(ctx->text.search->search_text, XtNstring, ptr, NULL); - } - - XtSetArg(args[0], XtNeditType,&edit_mode); - XtGetValues(ctx->text.source, args, ONE); - - InitializeSearchWidget(ctx->text.search, dir, (edit_mode == XawtextEdit)); - - CenterWidgetOnPoint(ctx->text.search->search_popup, event); - XtPopup(ctx->text.search->search_popup, XtGrabNone); + if (*num_params == 2) + ptr = params[1]; + else if (XawTextFormat(ctx, XawFmtWide)) { + /* This just does the equivalent of + ptr = ""L, a waste because params[1] isnt W aligned */ + ptr = (char *)wcs; + wcs[0] = 0; + } + else + ptr = ""; + + switch(params[0][0]) { + case 'b': /* Left */ + case 'B': + dir = XawsdLeft; + break; + case 'f': /* Right */ + case 'F': + dir = XawsdRight; + break; + default: + (void)XmuSnprintf(buf, sizeof(buf), "%s %s\n%s", SEARCH_HEADER, + "The first parameter must be", + "Either 'backward' or 'forward'"); + XtAppWarning(XtWidgetToApplicationContext(w), buf); + return; + } + + if (ctx->text.search== NULL) { + ctx->text.search = XtNew(struct SearchAndReplace); + ctx->text.search->search_popup = CreateDialog(w, ptr, "search", + AddSearchChildren); + XtRealizeWidget(ctx->text.search->search_popup); + SetWMProtocolTranslations(ctx->text.search->search_popup); + } + else if (*num_params > 1) + XtVaSetValues(ctx->text.search->search_text, XtNstring, ptr, NULL); + + XtSetArg(args[0], XtNeditType,&edit_mode); + XtGetValues(ctx->text.source, args, 1); + + InitializeSearchWidget(ctx->text.search, dir, (edit_mode == XawtextEdit)); + + CenterWidgetOnPoint(ctx->text.search->search_popup, event); + XtPopup(ctx->text.search->search_popup, XtGrabNone); } -/* Function Name: InitializeSearchWidget - * Description: This function initializes the search widget and - * is called each time the search widget is poped up. - * Arguments: search - the search widget structure. - * dir - direction to search. - * replace_active - state of the sensitivity for the - * replace button. - * Returns: none. +/* + * Function: + * InitializeSearchWidget + * + * Parameters: + * search - search widget structure + * dir - direction to search + * replace_active - state of the sensitivity for the replace button + * + * Description: + * This function initializes the search widget and + * is called each time the search widget is poped up. */ - static void -InitializeSearchWidget(search, dir, replace_active) -struct SearchAndReplace * search; -XawTextScanDirection dir; -Boolean replace_active; +InitializeSearchWidget(struct SearchAndReplace *search, + XawTextScanDirection dir, Bool replace_active) { - SetResource(search->rep_one, XtNsensitive, (XtArgVal) replace_active); - SetResource(search->rep_all, XtNsensitive, (XtArgVal) replace_active); - SetResource(search->rep_label, XtNsensitive, (XtArgVal) replace_active); - SetResource(search->rep_text, XtNsensitive, (XtArgVal) replace_active); - - switch (dir) { - case XawsdLeft: - SetResource(search->left_toggle, XtNstate, (XtArgVal) TRUE); - break; - case XawsdRight: - SetResource(search->right_toggle, XtNstate, (XtArgVal) TRUE); - break; - default: - break; - } + SetResource(search->rep_one, XtNsensitive, (XtArgVal)replace_active); + SetResource(search->rep_all, XtNsensitive, (XtArgVal)replace_active); + SetResource(search->rep_label, XtNsensitive, (XtArgVal)replace_active); + SetResource(search->rep_text, XtNsensitive, (XtArgVal)replace_active); + + switch (dir) { + case XawsdLeft: + SetResource(search->left_toggle, XtNstate, (XtArgVal)True); + break; + case XawsdRight: + SetResource(search->right_toggle, XtNstate, (XtArgVal)True); + break; + } } -/* Function Name: AddSearchChildren - * Description: Adds all children to the Search Dialog Widget. - * Arguments: form - the form widget for the search widget. - * ptr - a pointer to the initial string for the Text Widget. - * tw - the main text widget. - * Returns: none. +/* + * Function: + * AddSearchChildren + * + * Parameters: + * form - form widget for the search widget + * ptr - pointer to the initial string for the Text Widget + * tw - main text widget + * + * Description: + * Adds all children to the Search Dialog Widget. */ - static void -AddSearchChildren(form, ptr, tw) -Widget form, tw; -char * ptr; +AddSearchChildren(Widget form, char *ptr, Widget tw) { - Arg args[10]; - Cardinal num_args; - Widget cancel, search_button, s_label, s_text, r_text; - XtTranslations trans; - struct SearchAndReplace * search = ((TextWidget) tw)->text.search; - - num_args = 0; - XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; - XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; - XtSetArg(args[num_args], XtNresizable, TRUE ); num_args++; - XtSetArg(args[num_args], XtNborderWidth, 0 ); num_args++; - search->label1 = XtCreateManagedWidget("label1", labelWidgetClass, form, - args, num_args); - - num_args = 0; - XtSetArg(args[num_args], XtNfromVert, search->label1); num_args++; - XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; - XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; - XtSetArg(args[num_args], XtNresizable, TRUE ); num_args++; - XtSetArg(args[num_args], XtNborderWidth, 0 ); num_args++; - search->label2 = XtCreateManagedWidget("label2", labelWidgetClass, form, - args, num_args); + Arg args[10]; + Cardinal num_args; + Widget cancel, search_button, s_label, s_text, r_text; + XtTranslations trans; + struct SearchAndReplace *search = ((TextWidget)tw)->text.search; + + num_args = 0; + XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNresizable, True); num_args++; + XtSetArg(args[num_args], XtNborderWidth, 0); num_args++; + search->label1 = XtCreateManagedWidget("label1", labelWidgetClass, form, + args, num_args); + + num_args = 0; + XtSetArg(args[num_args], XtNfromVert, search->label1); num_args++; + XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNresizable, True); num_args++; + XtSetArg(args[num_args], XtNborderWidth, 0); num_args++; + search->label2 = XtCreateManagedWidget("label2", labelWidgetClass, form, + args, num_args); -/* - * We need to add R_OFFSET to the radio_data, because the value zero (0) - * has special meaning. - */ + /* + * We need to add R_OFFSET to the radio_data, because the value zero (0) + * has special meaning + */ + num_args = 0; + XtSetArg(args[num_args], XtNlabel, "Backward"); num_args++; + XtSetArg(args[num_args], XtNfromVert, search->label2); num_args++; + XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNradioData, (XPointer)XawsdLeft + R_OFFSET); + num_args++; + search->left_toggle = XtCreateManagedWidget("backwards", toggleWidgetClass, + form, args, num_args); - num_args = 0; - XtSetArg(args[num_args], XtNlabel, "Backward"); num_args++; - XtSetArg(args[num_args], XtNfromVert, search->label2); num_args++; - XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; - XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; - XtSetArg(args[num_args], XtNradioData, (XPointer) XawsdLeft + R_OFFSET); - num_args++; - search->left_toggle = XtCreateManagedWidget("backwards", toggleWidgetClass, - form, args, num_args); + num_args = 0; + XtSetArg(args[num_args], XtNlabel, "Forward"); num_args++; + XtSetArg(args[num_args], XtNfromVert, search->label2); num_args++; + XtSetArg(args[num_args], XtNfromHoriz, search->left_toggle); num_args++; + XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNradioGroup, search->left_toggle); num_args++; + XtSetArg(args[num_args], XtNradioData, (XPointer)XawsdRight + R_OFFSET); + num_args++; + search->right_toggle = XtCreateManagedWidget("forwards", toggleWidgetClass, + form, args, num_args); + + { + XtTranslations radio_translations; + + radio_translations = XtParseTranslationTable(radio_trans_string); + XtOverrideTranslations(search->left_toggle, radio_translations); + XtOverrideTranslations(search->right_toggle, radio_translations); + } - num_args = 0; - XtSetArg(args[num_args], XtNlabel, "Forward"); num_args++; - XtSetArg(args[num_args], XtNfromVert, search->label2); num_args++; - XtSetArg(args[num_args], XtNfromHoriz, search->left_toggle); num_args++; - XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; - XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; - XtSetArg(args[num_args], XtNradioGroup, search->left_toggle); num_args++; - XtSetArg(args[num_args], XtNradioData, (XPointer) XawsdRight + R_OFFSET); - num_args++; - search->right_toggle = XtCreateManagedWidget("forwards", toggleWidgetClass, - form, args, num_args); - - { - XtTranslations radio_translations; - - radio_translations = XtParseTranslationTable(radio_trans_string); - XtOverrideTranslations(search->left_toggle, radio_translations); - XtOverrideTranslations(search->right_toggle, radio_translations); - } - - num_args = 0; - XtSetArg(args[num_args], XtNfromVert, search->left_toggle); num_args++; - XtSetArg(args[num_args], XtNlabel, "Search for: ");num_args++; - XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; - XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; - XtSetArg(args[num_args], XtNborderWidth, 0 ); num_args++; - s_label = XtCreateManagedWidget("searchLabel", labelWidgetClass, form, - args, num_args); +#ifndef OLDXAW + if (XawTextFormat((TextWidget)tw, XawFmt8Bit)) { + num_args = 0; + XtSetArg(args[num_args], XtNlabel, "Case Sensitive"); num_args++; + XtSetArg(args[num_args], XtNfromVert, search->label2); num_args++; + XtSetArg(args[num_args], XtNfromHoriz, search->right_toggle); num_args++; + XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNstate, True); num_args++; + search->case_sensitive = XtCreateManagedWidget("case", toggleWidgetClass, + form, args, num_args); + } + else + search->case_sensitive = NULL; +#endif - num_args = 0; - XtSetArg(args[num_args], XtNfromVert, search->left_toggle); num_args++; - XtSetArg(args[num_args], XtNfromHoriz, s_label); num_args++; - XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; - XtSetArg(args[num_args], XtNright, XtChainRight); num_args++; - XtSetArg(args[num_args], XtNeditType, XawtextEdit); num_args++; - XtSetArg(args[num_args], XtNresizable, TRUE); num_args++; - XtSetArg(args[num_args], XtNresize, XawtextResizeWidth); num_args++; - XtSetArg(args[num_args], XtNstring, ptr); num_args++; - s_text = XtCreateManagedWidget("searchText", asciiTextWidgetClass, form, - args, num_args); - search->search_text = s_text; - - num_args = 0; - XtSetArg(args[num_args], XtNfromVert, s_text); num_args++; - XtSetArg(args[num_args], XtNlabel, "Replace with:");num_args++; - XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; - XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; - XtSetArg(args[num_args], XtNborderWidth, 0 ); num_args++; - search->rep_label = XtCreateManagedWidget("replaceLabel", labelWidgetClass, - form, args, num_args); + num_args = 0; + XtSetArg(args[num_args], XtNfromVert, search->left_toggle); num_args++; + XtSetArg(args[num_args], XtNlabel, "Search for: "); num_args++; + XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNborderWidth, 0 ); num_args++; + s_label = XtCreateManagedWidget("searchLabel", labelWidgetClass, form, + args, num_args); - num_args = 0; - XtSetArg(args[num_args], XtNfromHoriz, s_label); num_args++; - XtSetArg(args[num_args], XtNfromVert, s_text); num_args++; - XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; - XtSetArg(args[num_args], XtNright, XtChainRight); num_args++; - XtSetArg(args[num_args], XtNeditType, XawtextEdit); num_args++; - XtSetArg(args[num_args], XtNresizable, TRUE); num_args++; - XtSetArg(args[num_args], XtNresize, XawtextResizeWidth); num_args++; - XtSetArg(args[num_args], XtNstring, ""); num_args++; - r_text = XtCreateManagedWidget("replaceText", asciiTextWidgetClass, - form, args, num_args); - search->rep_text = r_text; - - num_args = 0; - XtSetArg(args[num_args], XtNlabel, "Search"); num_args++; - XtSetArg(args[num_args], XtNfromVert, r_text); num_args++; - XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; - XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; - search_button = XtCreateManagedWidget("search", commandWidgetClass, form, - args, num_args); - - num_args = 0; - XtSetArg(args[num_args], XtNlabel, "Replace"); num_args++; - XtSetArg(args[num_args], XtNfromVert, r_text); num_args++; - XtSetArg(args[num_args], XtNfromHoriz, search_button); num_args++; - XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; - XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; - search->rep_one = XtCreateManagedWidget("replaceOne", commandWidgetClass, - form, args, num_args); - - num_args = 0; - XtSetArg(args[num_args], XtNlabel, "Replace All"); num_args++; - XtSetArg(args[num_args], XtNfromVert, r_text); num_args++; - XtSetArg(args[num_args], XtNfromHoriz, search->rep_one); num_args++; - XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; - XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; - search->rep_all = XtCreateManagedWidget("replaceAll", commandWidgetClass, - form, args, num_args); - - num_args = 0; - XtSetArg(args[num_args], XtNlabel, "Cancel"); num_args++; - XtSetArg(args[num_args], XtNfromVert, r_text); num_args++; - XtSetArg(args[num_args], XtNfromHoriz, search->rep_all); num_args++; - XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; - XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; - cancel = XtCreateManagedWidget(DISMISS_NAME, commandWidgetClass, form, - args, num_args); + num_args = 0; + XtSetArg(args[num_args], XtNfromVert, search->left_toggle); num_args++; + XtSetArg(args[num_args], XtNfromHoriz, s_label); num_args++; + XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNright, XtChainRight); num_args++; + XtSetArg(args[num_args], XtNeditType, XawtextEdit); num_args++; + XtSetArg(args[num_args], XtNresizable, True); num_args++; + XtSetArg(args[num_args], XtNstring, ptr); num_args++; + s_text = XtCreateManagedWidget("searchText", asciiTextWidgetClass, form, + args, num_args); + search->search_text = s_text; - XtAddCallback(search_button, XtNcallback, SearchButton, (XtPointer) search); - XtAddCallback(search->rep_one, XtNcallback, DoReplaceOne, (XtPointer) search); - XtAddCallback(search->rep_all, XtNcallback, DoReplaceAll, (XtPointer) search); - XtAddCallback(cancel, XtNcallback, PopdownSearch, (XtPointer) search); + num_args = 0; + XtSetArg(args[num_args], XtNfromVert, s_text); num_args++; + XtSetArg(args[num_args], XtNlabel, "Replace with:"); num_args++; + XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNborderWidth, 0); num_args++; + search->rep_label = XtCreateManagedWidget("replaceLabel", labelWidgetClass, + form, args, num_args); -/* - * Initialize the text entry fields. - */ + num_args = 0; + XtSetArg(args[num_args], XtNfromHoriz, s_label); num_args++; + XtSetArg(args[num_args], XtNfromVert, s_text); num_args++; + XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNright, XtChainRight); num_args++; + XtSetArg(args[num_args], XtNeditType, XawtextEdit); num_args++; + XtSetArg(args[num_args], XtNresizable, True); num_args++; + XtSetArg(args[num_args], XtNstring, ""); num_args++; + r_text = XtCreateManagedWidget("replaceText", asciiTextWidgetClass, + form, args, num_args); + search->rep_text = r_text; + + num_args = 0; + XtSetArg(args[num_args], XtNlabel, "Search"); num_args++; + XtSetArg(args[num_args], XtNfromVert, r_text); num_args++; + XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; + search_button = XtCreateManagedWidget("search", commandWidgetClass, form, + args, num_args); - { - Pixel color; num_args = 0; - XtSetArg(args[num_args], XtNbackground, &color); num_args++; - XtGetValues(search->rep_text, args, num_args); + XtSetArg(args[num_args], XtNlabel, "Replace"); num_args++; + XtSetArg(args[num_args], XtNfromVert, r_text); num_args++; + XtSetArg(args[num_args], XtNfromHoriz, search_button); num_args++; + XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; + search->rep_one = XtCreateManagedWidget("replaceOne", commandWidgetClass, + form, args, num_args); + num_args = 0; - XtSetArg(args[num_args], XtNborderColor, color); num_args++; - XtSetValues(search->rep_text, args, num_args); - XtSetKeyboardFocus(form, search->search_text); - } + XtSetArg(args[num_args], XtNlabel, "Replace All"); num_args++; + XtSetArg(args[num_args], XtNfromVert, r_text); num_args++; + XtSetArg(args[num_args], XtNfromHoriz, search->rep_one); num_args++; + XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; + search->rep_all = XtCreateManagedWidget("replaceAll", commandWidgetClass, + form, args, num_args); - SetSearchLabels(search, SEARCH_LABEL_1, SEARCH_LABEL_2, FALSE); + num_args = 0; + XtSetArg(args[num_args], XtNlabel, "Cancel"); num_args++; + XtSetArg(args[num_args], XtNfromVert, r_text); num_args++; + XtSetArg(args[num_args], XtNfromHoriz, search->rep_all); num_args++; + XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++; + XtSetArg(args[num_args], XtNright, XtChainLeft); num_args++; + cancel = XtCreateManagedWidget(DISMISS_NAME, commandWidgetClass, form, + args, num_args); + + XtAddCallback(search_button, XtNcallback, SearchButton, (XtPointer)search); + XtAddCallback(search->rep_one, XtNcallback, DoReplaceOne, (XtPointer)search); + XtAddCallback(search->rep_all, XtNcallback, DoReplaceAll, (XtPointer)search); + XtAddCallback(cancel, XtNcallback, PopdownSearch, (XtPointer)search); + + /* + * Initialize the text entry fields + */ + { + Pixel color; + + num_args = 0; + XtSetArg(args[num_args], XtNbackground, &color); num_args++; + XtGetValues(search->rep_text, args, num_args); + num_args = 0; + XtSetArg(args[num_args], XtNborderColor, color); num_args++; + XtSetValues(search->rep_text, args, num_args); + XtSetKeyboardFocus(form, search->search_text); + } -/* - * Bind Extra translations. - */ + SetSearchLabels(search, SEARCH_LABEL_1, SEARCH_LABEL_2, False); - trans = XtParseTranslationTable(search_text_trans); - XtOverrideTranslations(search->search_text, trans); + /* + * Bind Extra translations + */ + trans = XtParseTranslationTable(search_text_trans); + XtOverrideTranslations(search->search_text, trans); - trans = XtParseTranslationTable(rep_text_trans); - XtOverrideTranslations(search->rep_text, trans); + trans = XtParseTranslationTable(rep_text_trans); + XtOverrideTranslations(search->rep_text, trans); } -/* Function Name: DoSearch - * Description: Performs a search. - * Arguments: search - the serach structure. - * Returns: TRUE if sucessful. +/* + * Function: + * DoSearch + * + * Parameters: + * search - search structure + * + * Description: + * Performs a search + * + * Returns: + * True if sucessful */ - -/* ARGSUSED */ -static Boolean -DoSearch(search) -struct SearchAndReplace * search; +/*ARGSUSED*/ +static Bool +DoSearch(struct SearchAndReplace *search) { - Widget tw = XtParent(search->search_popup); - XawTextPosition pos; - XawTextScanDirection dir; - XawTextBlock text; - - TextWidget ctx = (TextWidget)tw; - - text.ptr = GetStringRaw(search->search_text); - if ((text.format = _XawTextFormat(ctx)) == XawFmtWide) - text.length = wcslen((wchar_t*)text.ptr); - else - text.length = strlen(text.ptr); - text.firstPos = 0; - - dir = (XawTextScanDirection)(int) ((XPointer)XawToggleGetCurrent(search->left_toggle) - - R_OFFSET); + char msg[37]; + Widget tw = XtParent(search->search_popup); + XawTextPosition pos; + XawTextScanDirection dir; + XawTextBlock text; + TextWidget ctx = (TextWidget)tw; + + text.firstPos = 0; + text.ptr = GetStringRaw(search->search_text); + if ((text.format = _XawTextFormat(ctx)) == XawFmtWide) + text.length = wcslen((wchar_t*)text.ptr); + else { + text.length = strlen(text.ptr); + +#ifndef OLDXAW + if (search->case_sensitive) { + /* text.firstPos isn't useful here, so I'll use it as an + * options flag. + */ + Arg args[1]; + Boolean case_sensitive; + + XtSetArg(args[0], XtNstate, &case_sensitive); + XtGetValues(search->case_sensitive, args, 1); + text.firstPos = !case_sensitive; + } +#endif /* OLDXAW */ + } - pos = XawTextSearch( tw, dir, &text); + dir = (XawTextScanDirection) + ((XPointer)XawToggleGetCurrent(search->left_toggle) - R_OFFSET); + pos = XawTextSearch(tw, dir, &text); /* The Raw string in find.ptr may be WC I can't use here, so I re - call - GetString to get a tame version. */ - - if (pos == XawTextSearchError) { - char msgbuf[BUFSIZ]; - char* msg; - char* fmt = "Could not find string \"%s\""; - int len = strlen (fmt) + strlen (GetString (search->search_text)); - - if (len < sizeof msgbuf) msg = msgbuf; - else msg = XtMalloc (len + 1); - if (msg == NULL) { - msg = msgbuf; - strcpy (msg, "Could not find string."); - } else - (void) sprintf (msg, fmt, GetString (search->search_text)); - XawTextUnsetSelection(tw); - SetSearchLabels(search, msg, "", TRUE); - if (msg != msgbuf) XtFree (msg); - return FALSE; - } - if (dir == XawsdRight) - XawTextSetInsertionPoint( tw, pos + text.length); - else - XawTextSetInsertionPoint( tw, pos); - - XawTextSetSelection( tw, pos, pos + text.length); - search->selection_changed = FALSE; /* selection is good. */ - return TRUE; + GetString to get a tame version */ + + if (pos == XawTextSearchError) { + char *ptr; + int len; + + ptr = GetString(search->search_text); + len = strlen(ptr); + (void)XmuSnprintf(msg, sizeof(msg), "%s", ptr); + + ptr = strchr(msg, '\n'); + if (ptr != NULL || sizeof(msg) - 1 < len) { + if (ptr != NULL) + len = ptr - msg + 4; + else + len = strlen(msg); + + if (len < 4) + strcpy(msg, "..."); + else + strcpy(msg + len - 4, "..."); + } + XawTextUnsetSelection(tw); + SetSearchLabels(search, "Could not find string", msg, True); + + return (False); + } + XawTextDisableRedisplay(tw); + XawTextSetSelection(tw, pos, pos + text.length); + search->selection_changed = False; /* selection is good */ + + if (dir == XawsdRight) + XawTextSetInsertionPoint(tw, pos + text.length); + else + XawTextSetInsertionPoint(tw, pos); + _XawTextShowPosition(ctx); + XawTextEnableRedisplay(tw); + + return (True); } -/************************************************************ - * +/* * This section of the file contains all the functions that - * the replace dialog box uses. + * the replace dialog box uses + */ +/* + * Function: + * _XawTextDoReplaceAction * - ************************************************************/ - -/* Function Name: _XawTextDoReplaceAction - * Description: Action routine that can be bound to dialog box's - * Text Widget that will replace a string in the main - * Text Widget. - * Arguments: (Standard Action Routine args) - * Returns: none. + * Description: + * Action routine that can be bound to dialog box's + * Text Widget that will replace a string in the main Text Widget. */ - -/* ARGSUSED */ +/*ARGSUSED*/ void -_XawTextDoReplaceAction(w, event, params, num_params) -Widget w; -XEvent *event; -String * params; -Cardinal * num_params; +_XawTextDoReplaceAction(Widget w, XEvent *event, + String *params, Cardinal *num_params) { - TextWidget ctx = (TextWidget) XtParent(XtParent(XtParent(w))); - Boolean popdown = FALSE; + TextWidget ctx = (TextWidget)XtParent(XtParent(XtParent(w))); + Bool popdown = False; - if ( (*num_params == 1) && - ((params[0][0] == 'p') || (params[0][0] == 'P')) ) - popdown = TRUE; + if (*num_params == 1 && (params[0][0] == 'p' || params[0][0] == 'P')) + popdown = True; - if (Replace( ctx->text.search, TRUE, popdown) && popdown) - PopdownSearch(w, (XtPointer) ctx->text.search, (XtPointer)NULL); + if (Replace( ctx->text.search, True, popdown) && popdown) + PopdownSearch(w, (XtPointer)ctx->text.search, NULL); } -/* Function Name: DoReplaceOne - * Description: Replaces the first instance of the string - * in the search dialog's text widget - * with the one in the replace dialog's text widget. - * Arguments: w - *** Not Used ***. - * closure - a pointer to the search structure. - * call_data - *** Not Used ***. - * Returns: none. +/* + * Function: + * DoReplaceOne + * + * Arguments: + * w - *** Not Used *** + * closure - a pointer to the search structure + * call_data - *** Not Used *** + * + * Description: + * Replaces the first instance of the string in the search + * dialog's text widget with the one in the replace dialog's text widget. */ - -/* ARGSUSED */ -static void -DoReplaceOne(w, closure, call_data) -Widget w; /* The Button Pressed. */ -XtPointer closure; /* Text Widget. */ -XtPointer call_data; /* unused */ +/*ARGSUSED*/ +static void +DoReplaceOne(Widget w, XtPointer closure, XtPointer call_data) { - Replace( (struct SearchAndReplace *) closure, TRUE, FALSE); + Replace((struct SearchAndReplace *)closure, True, False); } -/* Function Name: DoReplaceOne - * Description: Replaces every instance of the string - * in the search dialog's text widget - * with the one in the replace dialog's text widget. - * Arguments: w - *** Not Used ***. - * closure - a pointer to the search structure. - * call_data - *** Not Used ***. - * Returns: none. +/* + * Function: + * DoReplaceAll + * + * Parameters: + * w - (not used) + * closure - pointer to the search structure + * call_data - (not used) + * + * Description: + * Replaces every instance of the string in the search dialog's + * text widget with the one in the replace dialog's text widget. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -DoReplaceAll(w, closure, call_data) -Widget w; /* The Button Pressed. */ -XtPointer closure; /* Text Widget. */ -XtPointer call_data; /* unused */ +DoReplaceAll(Widget w, XtPointer closure, XtPointer call_data) { - Replace( (struct SearchAndReplace *) closure, FALSE, FALSE); + Replace((struct SearchAndReplace *)closure, False, False); } -/* Function Name: Replace - * Description: This is the function that does the real work of - * replacing strings in the main text widget. - * Arguments: tw - the Text Widget to replce the string in. - * once_only - If TRUE then only replace the first one found. - * other replace all of them. - * show_current - If true then leave the selection on the - * string that was just replaced, otherwise - * move it onto the next one. - * Returns: none. +/* + * Function: + * Replace + * + * Parameters: + * tw - Text Widget to replce the string in + * once_only - if True then only replace the first one found, + * else replace all of them + * show_current - if true then leave the selection on the + * string that was just replaced, otherwise + * move it onto the next one + * + * Description: + * This is the function that does the real work of + * replacing strings in the main text widget. */ - -static Boolean -Replace(search, once_only, show_current) -struct SearchAndReplace * search; -Boolean once_only, show_current; +static Bool +Replace(struct SearchAndReplace *search, Bool once_only, Bool show_current) { - XawTextPosition pos, new_pos, end_pos; - XawTextScanDirection dir; - XawTextBlock find, replace; - Widget tw = XtParent(search->search_popup); - int count = 0; - - TextWidget ctx = (TextWidget)tw; - - find.ptr = GetStringRaw( search->search_text); - if ((find.format = _XawTextFormat(ctx)) == XawFmtWide) - find.length = wcslen((wchar_t*)find.ptr); - else - find.length = strlen(find.ptr); - find.firstPos = 0; - - replace.ptr = GetStringRaw(search->rep_text); - replace.firstPos = 0; - if ((replace.format = _XawTextFormat(ctx)) == XawFmtWide) - replace.length = wcslen((wchar_t*)replace.ptr); - else - replace.length = strlen(replace.ptr); + XawTextPosition pos, new_pos, end_pos, ipos; + XawTextScanDirection dir; + XawTextBlock find, replace; + Widget tw = XtParent(search->search_popup); + int count = 0; + TextWidget ctx = (TextWidget)tw; + Bool redisplay; + + find.ptr = GetStringRaw(search->search_text); + if ((find.format = _XawTextFormat(ctx)) == XawFmtWide) + find.length = (XawTextPosition)wcslen((wchar_t*)find.ptr); + else + find.length = (XawTextPosition)strlen(find.ptr); + find.firstPos = 0; + + replace.ptr = GetStringRaw(search->rep_text); + replace.firstPos = 0; + if ((replace.format = _XawTextFormat(ctx)) == XawFmtWide) + replace.length = wcslen((wchar_t*)replace.ptr); + else + replace.length = strlen(replace.ptr); - dir = (XawTextScanDirection)(int) ((XPointer)XawToggleGetCurrent(search->left_toggle) - - R_OFFSET); - /* CONSTCOND */ - while (TRUE) { - if (count != 0) { - new_pos = XawTextSearch( tw, dir, &find); - - if ( (new_pos == XawTextSearchError) ) { - if (count == 0) { - char msgbuf[BUFSIZ]; - char* msg; - int len; - char* fmt = "*** Error: Could not find string \"%s\" ***"; - - len = strlen (fmt) + strlen (GetString (search->search_text)); - if (len < sizeof msgbuf) msg = msgbuf; - else msg = XtMalloc (len + 1); - if (msg == NULL) { - msg = msgbuf; - strcpy (msg, "*** Error: Could not find string. ***"); - } else - (void) sprintf (msg, fmt, GetString (search->search_text)); - SetSearchLabels(search, msg, "", TRUE); - if (msg != msgbuf) XtFree (msg); - return FALSE; + dir = (XawTextScanDirection) + XawToggleGetCurrent(search->left_toggle) - R_OFFSET; + + redisplay = !once_only || (once_only && !show_current); + ipos = XawTextGetInsertionPoint(tw); + if (redisplay) + XawTextDisableRedisplay(tw); + /*CONSTCOND*/ + while (True) { + if (count != 0) { + new_pos = XawTextSearch(tw, dir, &find); + + if (new_pos == XawTextSearchError) { + if (count == 0) { + char msg[37]; + char *ptr; + int len; + + ptr = GetString(search->search_text); + len = strlen(ptr); + (void)XmuSnprintf(msg, sizeof(msg), "%s", ptr); + ptr = strchr(msg, '\n'); + if (ptr != NULL || sizeof(msg) - 1 < len) { + if (ptr != NULL) + len = ptr - msg + 4; + else + len = strlen(msg); + + if (len < 4) + strcpy(msg, "..."); + else + strcpy(msg + len - 4, "..."); + } + SetSearchLabels(search, "Could not find string", msg, True); + + if (redisplay) { + XawTextSetInsertionPoint(tw, ipos); + _XawTextShowPosition(ctx); + XawTextEnableRedisplay(tw); + } + + return (False); + } + else + break; + } + pos = new_pos; + end_pos = pos + find.length; } + else { + XawTextGetSelectionPos(tw, &pos, &end_pos); + + if (search->selection_changed) { + SetSearchLabels(search, "Selection modified, aborting.", + "", True); + if (redisplay) { + XawTextSetInsertionPoint(tw, ipos); + XawTextEnableRedisplay(tw); + } + + return (False); + } + if (pos == end_pos) { + if (redisplay) { + XawTextSetInsertionPoint(tw, ipos); + XawTextEnableRedisplay(tw); + } + + return (False); + } + } + + if (XawTextReplace(tw, pos, end_pos, &replace) != XawEditDone) { + SetSearchLabels(search, "Error while replacing.", "", True); + if (redisplay) { + XawTextSetInsertionPoint(tw, ipos); + XawTextEnableRedisplay(tw); + } + + return (False); + } + + if (dir == XawsdRight) + ipos = pos + replace.length; else - break; - } - pos = new_pos; - end_pos = pos + find.length; - } - else { - XawTextGetSelectionPos(tw, &pos, &end_pos); - - if (search->selection_changed) { - SetSearchLabels(search, "Selection has been modified, aborting.", - "", TRUE); - return(FALSE); - } - if (pos == end_pos) - return(FALSE); - } + ipos = pos; - if (XawTextReplace(tw, pos, end_pos, &replace) != XawEditDone) { - char msgbuf[BUFSIZ]; - char* msg; - int len; - char* fmt = "'%s' with '%s'. ***"; - - len = strlen (fmt) + strlen (find.ptr) + strlen (replace.ptr); - if (len < sizeof msgbuf) msg = msgbuf; - else msg = XtMalloc (len + 1); - if (msg == NULL) { - msg = msgbuf; - strcpy (msg, "long strings"); - } else - (void) sprintf( msg, fmt, find.ptr, replace.ptr); - SetSearchLabels(search, "*** Error while replacing", msg, TRUE); - if (msg != msgbuf) XtFree (msg); - return FALSE; - } + if (once_only) { + if (show_current) + break; + else { + DoSearch(search); + XawTextEnableRedisplay(tw); - if (dir == XawsdRight) - XawTextSetInsertionPoint( tw, pos + replace.length); + return (True); + } + } + else + ctx->text.insertPos = ipos; + count++; + } + + if (replace.length == 0) + XawTextUnsetSelection(tw); else - XawTextSetInsertionPoint( tw, pos); - - if (once_only) - if (show_current) - break; - else { - DoSearch(search); - return(TRUE); - } - count++; - } - - if (replace.length == 0) - XawTextUnsetSelection(tw); - else - XawTextSetSelection( tw, pos, pos + replace.length); - - return TRUE; + XawTextSetSelection(tw, pos, pos + replace.length); + + XawTextSetInsertionPoint(tw, ipos); + _XawTextShowPosition(ctx); + XawTextEnableRedisplay(tw); + + return (True); } -/* Function Name: SetSearchLabels - * Description: Sets both the search labels, and also rings the bell - * Arguments: search - the search structure. - * msg1, msg2 - message to put in each search label. - * bell - if TRUE then ring bell. - * Returns: none. +/* + * Function: + * SetSearchLabels + * + * Parameters: + * search - search structure + * msg1 - message to put in each search label + * msg2 - "" + * bell - if True then ring bell + * + * Description: + * Sets both the search labels, and also rings the bell. */ - static void -SetSearchLabels(search, msg1, msg2, bell) -struct SearchAndReplace * search; -String msg1, msg2; -Boolean bell; +SetSearchLabels(struct SearchAndReplace *search, String msg1, String msg2, + Bool bell) { - (void) SetResource( search->label1, XtNlabel, (XtArgVal) msg1); - (void) SetResource( search->label2, XtNlabel, (XtArgVal) msg2); - if (bell) - XBell(XtDisplay(search->search_popup), 0); + (void)SetResource(search->label1, XtNlabel, (XtArgVal)msg1); + (void)SetResource(search->label2, XtNlabel, (XtArgVal)msg2); + if (bell) + XBell(XtDisplay(search->search_popup), 0); } -/************************************************************ - * +/* * This section of the file contains utility routines used by - * other functions in this file. + * other functions in this file + */ +/* + * Function: + * _XawTextSetField * - ************************************************************/ - - -/* Function Name: _XawTextSetField - * Description: Action routine that can be bound to dialog box's - * Text Widget that will send input to the field specified. - * Arguments: (Standard Action Routine args) - * Returns: none. + * Description: + * Action routine that can be bound to dialog box's + * Text Widget that will send input to the field specified. */ - -/* ARGSUSED */ +/*ARGSUSED*/ void -_XawTextSetField(w, event, params, num_params) -Widget w; -XEvent *event; -String * params; -Cardinal * num_params; +_XawTextSetField(Widget w, XEvent *event, String *params, Cardinal *num_params) { - struct SearchAndReplace * search; - Widget new, old; - - search = ((TextWidget) XtParent(XtParent(XtParent(w))))->text.search; - - if (*num_params != 1) { - SetSearchLabels(search, "*** Error: SetField Action must have", - "exactly one argument. ***", TRUE); - return; - } - switch (params[0][0]) { - case 's': - case 'S': - new = search->search_text; - old = search->rep_text; - break; - case 'r': - case 'R': - old = search->search_text; - new = search->rep_text; - break; - default: - SetSearchLabels(search, "*** Error: SetField Action's first Argument must", - "be either 'Search' or 'Replace'. ***", TRUE); - return; - } - _SetField(new, old); + struct SearchAndReplace *search; + Widget cnew, old; + + search = ((TextWidget)XtParent(XtParent(XtParent(w))))->text.search; + + if (*num_params != 1) { + SetSearchLabels(search, "Error: SetField Action must have", + "exactly one argument", True); + return; + } + switch (params[0][0]) { + case 's': + case 'S': + cnew = search->search_text; + old = search->rep_text; + break; + case 'r': + case 'R': + old = search->search_text; + cnew = search->rep_text; + break; + default: + SetSearchLabels(search, + "Error: SetField Action's first Argument must", + "be either 'Search' or 'Replace'", True); + return; + } + _SetField(cnew, old); } -/* Function Name: SetField - * Description: Sets the current text field. - * Arguments: new, old - new and old text fields. - * Returns: none +/* + * Function: + * _SetField + * + * Parameters: + * cnew - new and old text fields + * old - "" + * + * Description: + * Sets the current text field. */ - static void -_SetField(new, old) -Widget new, old; +_SetField(Widget cnew, Widget old) { - Arg args[2]; - Pixel new_border, old_border, old_bg; + Arg args[2]; + Pixel new_border, old_border, old_bg; - if (!XtIsSensitive(new)) { - XBell(XtDisplay(old), 0); /* Don't set field to an inactive Widget. */ - return; - } + if (!XtIsSensitive(cnew)) { + XBell(XtDisplay(old), 0); /* Don't set field to an inactive Widget */ + return; + } - XtSetKeyboardFocus(XtParent(new), new); + XtSetKeyboardFocus(XtParent(cnew), cnew); - XtSetArg(args[0], XtNborderColor, &old_border); - XtSetArg(args[1], XtNbackground, &old_bg); - XtGetValues(new, args, TWO); + XtSetArg(args[0], XtNborderColor, &old_border); + XtSetArg(args[1], XtNbackground, &old_bg); + XtGetValues(cnew, args, 2); - XtSetArg(args[0], XtNborderColor, &new_border); - XtGetValues(old, args, ONE); + XtSetArg(args[0], XtNborderColor, &new_border); + XtGetValues(old, args, 1); - if (old_border != old_bg) /* Colors are already correct, return. */ - return; + if (old_border != old_bg) /* Colors are already correct, return */ + return; - SetResource(old, XtNborderColor, (XtArgVal) old_border); - SetResource(new, XtNborderColor, (XtArgVal) new_border); + SetResource(old, XtNborderColor, (XtArgVal)old_border); + SetResource(cnew, XtNborderColor, (XtArgVal)new_border); } -/* Function Name: SetResourceByName - * Description: Sets a resource in any of the dialog children given - * name of the child and the shell widget of the dialog. - * Arguments: shell - shell widget of the popup. - * name - name of the child. - * res_name - name of the resource. - * value - the value of the resource. - * Returns: TRUE if sucessful. +/* + * Function: + * SetResourceByName + * + * Parameters: + * shell - shell widget of the popup + * name - name of the child + * res_name - name of the resource + * value - value of the resource + * + * Description: + * Sets a resource in any of the dialog children given + * name of the child and the shell widget of the dialog. + * + * Returns: + * True if sucessful */ - -static Boolean -SetResourceByName(shell, name, res_name, value) -Widget shell; -char * name, * res_name; -XtArgVal value; +static Bool +SetResourceByName(Widget shell, char *name, char *res_name, XtArgVal value) { - Widget temp_widget; - char buf[BUFSIZ]; - char* bufp; - int len = strlen (FORM_NAME) + strlen (name) + 1; - Boolean ret = FALSE; - - if (len < sizeof buf) bufp = buf; - else bufp = XtMalloc (len + 1); + Widget temp_widget; + char buf[BUFSIZ]; - if (bufp == NULL) return FALSE; + (void)XmuSnprintf(buf, sizeof(buf), "%s.%s", FORM_NAME, name); - (void) sprintf(bufp, "%s.%s", FORM_NAME, name); - - if ( (temp_widget = XtNameToWidget(shell, bufp)) != NULL) { - SetResource(temp_widget, res_name, value); - ret = TRUE; - } - if (bufp != buf) XtFree (bufp); - return ret; + if ((temp_widget = XtNameToWidget(shell, buf)) != NULL) { + SetResource(temp_widget, res_name, value); + return (True); + } + return (False); } -/* Function Name: SetResource - * Description: Sets a resource in a widget - * Arguments: w - the widget. - * res_name - name of the resource. - * value - the value of the resource. - * Returns: none. +/* + * Function: + * SetResource + * + * Parameters: + * w - widget + * res_name - name of the resource + * value - value of the resource + * + * Description: + * Sets a resource in a widget */ - static void -SetResource(w, res_name, value) -Widget w; -char * res_name; -XtArgVal value; +SetResource(Widget w, char *res_name, XtArgVal value) { - Arg args[1]; + Arg args[1]; - XtSetArg(args[0], res_name, value); - XtSetValues( w, args, ONE ); + XtSetArg(args[0], res_name, value); + XtSetValues( w, args, 1); } -/* Function Name: GetString{Raw} - * Description: Gets the value for the string in the popup. - * Arguments: text - the text widget whose string we will get. +/* + * Function: + * GetString{Raw} + * + * Parameters: + * text - text widget whose string we will get * - * GetString returns the string as a MB. - * GetStringRaw returns the exact buffer contents suitable for a search. + * Description: + * Gets the value for the string in the popup. * + * Returns: + * GetString: the string as a MB + * GetStringRaw: the exact buffer contents suitable for a search */ - static String -GetString(text) -Widget text; +GetString(Widget text) { - String string; - Arg args[1]; + String string; + Arg args[1]; - XtSetArg( args[0], XtNstring, &string ); - XtGetValues( text, args, ONE ); - return(string); + XtSetArg(args[0], XtNstring, &string); + XtGetValues(text, args, 1); + + return (string); } static String -GetStringRaw(tw) -Widget tw; +GetStringRaw(Widget tw) { - TextWidget ctx = (TextWidget)tw; - XawTextPosition last; - char *_XawTextGetText(); + TextWidget ctx = (TextWidget)tw; + XawTextPosition last; - last = XawTextSourceScan(ctx->text.source, 0, XawstAll, XawsdRight, - ctx->text.mult, TRUE); - return (_XawTextGetText(ctx, 0, last)); + last = XawTextSourceScan(ctx->text.source, 0, XawstAll, XawsdRight, + ctx->text.mult, True); + return (_XawTextGetText(ctx, 0, last)); } -/* Function Name: CenterWidgetOnPoint. - * Description: Centers a shell widget on a point relative to - * the root window. - * Arguments: w - the shell widget. - * event - event containing the location of the point - * Returns: none. +/* + * Function: + * CenterWidgetOnPoint + * + * Parameters: + * w - shell widget + * event - event containing the location of the point * - * NOTE: The widget is not allowed to go off the screen. + * Description: + * Centers a shell widget on a point relative to the root window. + * + * Note: + * The widget is not allowed to go off the screen */ - static void -CenterWidgetOnPoint(w, event) -Widget w; -XEvent *event; +CenterWidgetOnPoint(Widget w, XEvent *event) { - Arg args[3]; - Cardinal num_args; - Dimension width, height, b_width; - Position x, y, max_x, max_y; + Arg args[3]; + Cardinal num_args; + Dimension width, height, b_width; + Position x, y, max_x, max_y; - if (event != NULL) { - switch (event->type) { - case ButtonPress: - case ButtonRelease: - x = event->xbutton.x_root; - y = event->xbutton.y_root; - break; - case KeyPress: - case KeyRelease: - x = event->xkey.x_root; - y = event->xkey.y_root; - break; - default: - return; + if (event != NULL) { + switch (event->type) { + case ButtonPress: + case ButtonRelease: + x = event->xbutton.x_root; + y = event->xbutton.y_root; + break; + case KeyPress: + case KeyRelease: + x = event->xkey.x_root; + y = event->xkey.y_root; + break; + default: + return; + } } - } - - num_args = 0; - XtSetArg(args[num_args], XtNwidth, &width); num_args++; - XtSetArg(args[num_args], XtNheight, &height); num_args++; - XtSetArg(args[num_args], XtNborderWidth, &b_width); num_args++; - XtGetValues(w, args, num_args); - - width += 2 * b_width; - height += 2 * b_width; - - x -= ( (Position) width/2 ); - if (x < 0) x = 0; - if ( x > (max_x = (Position) (XtScreen(w)->width - width)) ) x = max_x; - - y -= ( (Position) height/2 ); - if (y < 0) y = 0; - if ( y > (max_y = (Position) (XtScreen(w)->height - height)) ) y = max_y; + else + return; + + num_args = 0; + XtSetArg(args[num_args], XtNwidth, &width); num_args++; + XtSetArg(args[num_args], XtNheight, &height); num_args++; + XtSetArg(args[num_args], XtNborderWidth, &b_width); num_args++; + XtGetValues(w, args, num_args); + + width += b_width << 1; + height += b_width << 1; + + x -= (Position)(width >> 1); + if (x < 0) + x = 0; + if (x > (max_x = (Position)(XtScreen(w)->width - width))) + x = max_x; + + y -= (Position)(height >> 1); + if (y < 0) + y = 0; + if (y > (max_y = (Position)(XtScreen(w)->height - height))) + y = max_y; - num_args = 0; - XtSetArg(args[num_args], XtNx, x); num_args++; - XtSetArg(args[num_args], XtNy, y); num_args++; - XtSetValues(w, args, num_args); + num_args = 0; + XtSetArg(args[num_args], XtNx, x); num_args++; + XtSetArg(args[num_args], XtNy, y); num_args++; + XtSetValues(w, args, num_args); } -/* Function Name: CreateDialog - * Description: Actually creates a dialog. - * Arguments: parent - the parent of the dialog - the main text widget. - * ptr - initial_string for the dialog. - * name - name of the dialog. - * func - function to create the children of the dialog. - * Returns: the popup shell of the dialog. - * - * NOTE: +/* + * Function: + * CreateDialog * - * The function argument is passed the following arguements. + * Parameters: + * parent - parent of the dialog - the main text widget + * ptr - initial_string for the dialog + * name - name of the dialog + * func - function to create the children of the dialog * - * form - the from widget that is the dialog. - * ptr - the initial string for the dialog's text widget. - * parent - the parent of the dialog - the main text widget. + * Returns: + * Popup shell of the dialog + * + * Note: + * The function argument is passed the following arguments: + * form - from widget that is the dialog + * ptr - initial string for the dialog's text widget + * parent - parent of the dialog - the main text widget */ - static Widget -CreateDialog(parent, ptr, name, func) -Widget parent; -String ptr, name; -void (*func)(); +CreateDialog(Widget parent, String ptr, String name, AddFunc func) { - Widget popup, form; - Arg args[5]; - Cardinal num_args; - - num_args = 0; - XtSetArg(args[num_args], XtNiconName, name); num_args++; - XtSetArg(args[num_args], XtNgeometry, NULL); num_args++; - XtSetArg(args[num_args], XtNallowShellResize, TRUE); num_args++; - XtSetArg(args[num_args], XtNtransientFor, GetShell(parent)); num_args++; - popup = XtCreatePopupShell(name, transientShellWidgetClass, - parent, args, num_args); - - form = XtCreateManagedWidget(FORM_NAME, formWidgetClass, popup, - (ArgList)NULL, ZERO); - XtManageChild (form); + Widget popup, form; + Arg args[5]; + Cardinal num_args; - (*func) (form, ptr, parent); - return(popup); + num_args = 0; + XtSetArg(args[num_args], XtNiconName, name); num_args++; + XtSetArg(args[num_args], XtNgeometry, NULL); num_args++; + XtSetArg(args[num_args], XtNallowShellResize, True); num_args++; + XtSetArg(args[num_args], XtNtransientFor, GetShell(parent));num_args++; + popup = XtCreatePopupShell(name, transientShellWidgetClass, + parent, args, num_args); + + form = XtCreateManagedWidget(FORM_NAME, formWidgetClass, popup, NULL, 0); + XtManageChild (form); + + (*func)(form, ptr, parent); + + return (popup); } - /* Function Name: GetShell - * Description: Walks up the widget hierarchy to find the - * nearest shell widget. - * Arguments: w - the widget whose parent shell should be returned. - * Returns: The shell widget among the ancestors of w that is the - * fewest levels up in the widget hierarchy. - */ - +/* + * Function + * GetShell + * nearest shell widget. + * + * Parameters: + * w - widget whose parent shell should be returned + * + * Returns: + * The shell widget among the ancestors of w that is the + * fewest levels up in the widget hierarchy. + * + * Description: + * Walks up the widget hierarchy to find the topmost shell widget. + */ static Widget -GetShell(w) -Widget w; +GetShell(Widget w) { - while ((w != NULL) && !XtIsShell(w)) + while (w != NULL && !XtIsShell(w)) w = XtParent(w); return (w); } -static Boolean InParams(str, p, n) - String str; - String *p; - Cardinal n; +static Bool +InParams(String str, String *p, unsigned int n) { - int i; - for (i=0; i < n; p++, i++) - if (! XmuCompareISOLatin1(*p, str)) return True; - return False; + unsigned int i; + + for (i = 0; i < n; p++, i++) + if (!XmuCompareISOLatin1(*p, str)) + return (True); + return (False); } static char *WM_DELETE_WINDOW = "WM_DELETE_WINDOW"; -static void WMProtocols(w, event, params, num_params) - Widget w; /* popup shell */ - XEvent *event; - String *params; - Cardinal *num_params; +static void +WMProtocols(Widget w, XEvent *event, String *params, Cardinal *num_params) { Atom wm_delete_window; Atom wm_protocols; @@ -1395,54 +1488,57 @@ static void WMProtocols(w, event, params, num_params) wm_delete_window = XInternAtom(XtDisplay(w), WM_DELETE_WINDOW, True); wm_protocols = XInternAtom(XtDisplay(w), "WM_PROTOCOLS", True); - /* Respond to a recognized WM protocol request iff + /* Respond to a recognized WM protocol request if * event type is ClientMessage and no parameters are passed, or * event type is ClientMessage and event data is matched to parameters, or - * event type isn't ClientMessage and parameters make a request. + * event type isn't ClientMessage and parameters make a request */ #define DO_DELETE_WINDOW InParams(WM_DELETE_WINDOW, params, *num_params) - if ((event->type == ClientMessage && - event->xclient.message_type == wm_protocols && - event->xclient.data.l[0] == wm_delete_window && - (*num_params == 0 || DO_DELETE_WINDOW)) - || - (event->type != ClientMessage && DO_DELETE_WINDOW)) { - + if ((event->type == ClientMessage + && event->xclient.message_type == wm_protocols + && event->xclient.data.l[0] == wm_delete_window + && (*num_params == 0 || DO_DELETE_WINDOW)) + || (event->type != ClientMessage && DO_DELETE_WINDOW)) { #undef DO_DELETE_WINDOW - Widget cancel; char descendant[DISMISS_NAME_LEN + 2]; - (void) sprintf(descendant, "*%s", DISMISS_NAME); + + (void)XmuSnprintf(descendant, sizeof(descendant), "*%s", DISMISS_NAME); cancel = XtNameToWidget(w, descendant); - if (cancel) XtCallCallbacks(cancel, XtNcallback, (XtPointer)NULL); + if (cancel) + XtCallCallbacks(cancel, XtNcallback, NULL); } } -static void SetWMProtocolTranslations(w) - Widget w; /* realized popup shell */ +static void +SetWMProtocolTranslations(Widget w) { - int i; + static XtTranslations compiled_table; + static XtAppContext *app_context_list; + static Cardinal list_size; + + unsigned int i; XtAppContext app_context; Atom wm_delete_window; - static XtTranslations compiled_table; /* initially 0 */ - static XtAppContext *app_context_list; /* initially 0 */ - static Cardinal list_size; /* initially 0 */ app_context = XtWidgetToApplicationContext(w); /* parse translation table once */ - if (! compiled_table) compiled_table = XtParseTranslationTable - ("<Message>WM_PROTOCOLS: XawWMProtocols()\n"); + if (!compiled_table) + compiled_table = + XtParseTranslationTable("<Message>WM_PROTOCOLS:XawWMProtocols()\n"); /* add actions once per application context */ - for (i=0; i < list_size && app_context_list[i] != app_context; i++) ; + for (i = 0; i < list_size && app_context_list[i] != app_context; i++) + ; if (i == list_size) { XtActionsRec actions[1]; + actions[0].string = "XawWMProtocols"; actions[0].proc = WMProtocols; list_size++; - app_context_list = (XtAppContext *) XtRealloc + app_context_list = (XtAppContext *)XtRealloc ((char *)app_context_list, list_size * sizeof(XtAppContext)); XtAppAddActions(app_context, actions, 1); app_context_list[i] = app_context; @@ -1451,5 +1547,5 @@ static void SetWMProtocolTranslations(w) /* establish communication between the window manager and each shell */ XtAugmentTranslations(w, compiled_table); wm_delete_window = XInternAtom(XtDisplay(w), WM_DELETE_WINDOW, False); - (void) XSetWMProtocols(XtDisplay(w), XtWindow(w), &wm_delete_window, 1); + (void)XSetWMProtocols(XtDisplay(w), XtWindow(w), &wm_delete_window, 1); } diff --git a/src/TextSink.c b/src/TextSink.c index 1a37716..45a584a 100644 --- a/src/TextSink.c +++ b/src/TextSink.c @@ -24,6 +24,7 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/TextSink.c,v 1.21 2002/06/03 21:39:24 paulo Exp $ */ /* * Author: Chris Peterson, MIT X Consortium. @@ -37,742 +38,1789 @@ in this Software without prior written authorization from The Open Group. */ #include <stdio.h> +#include <stdlib.h> #include <ctype.h> #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> -#include <X11/Xaw/XawInit.h> -#include <X11/Xaw/TextSinkP.h> #include <X11/Xaw/TextP.h> +#include <X11/Xaw/TextSinkP.h> +#include <X11/Xaw/XawInit.h> +#include "Private.h" -/**************************************************************** - * - * Full class record constant - * - ****************************************************************/ - -static void ClassPartInitialize(), Initialize(), Destroy(); -static Boolean SetValues(); +/* + * Prototypes + */ +static void XawTextSinkClassPartInitialize(WidgetClass); +static void XawTextSinkInitialize(Widget, Widget, ArgList, Cardinal*); +static void XawTextSinkDestroy(Widget); +static Boolean XawTextSinkSetValues(Widget, Widget, Widget, + ArgList, Cardinal*); + +static int MaxLines(Widget, unsigned int); +static int MaxHeight(Widget, int); +static void DisplayText(Widget, int, int, XawTextPosition, XawTextPosition, + Bool); +static void InsertCursor(Widget, int, int, XawTextInsertState); +static void ClearToBackground(Widget, int, int, unsigned int, unsigned int); +static void FindPosition(Widget, XawTextPosition, int, int, Bool, + XawTextPosition*, int*, int*); +static void FindDistance(Widget, XawTextPosition, int, XawTextPosition, int*, + XawTextPosition*, int*); +static void Resolve(Widget, XawTextPosition, int, int, XawTextPosition*); +static void SetTabs(Widget, int, short*); +static void GetCursorBounds(Widget, XRectangle*); + +#ifndef OLDXAW +static Boolean CvtStringToPropertyList(Display*, XrmValue*, Cardinal*, + XrmValue*, XrmValue*, XtPointer*); +static Boolean CvtPropertyListToString(Display*, XrmValue*, Cardinal*, + XrmValue*, XrmValue*, XtPointer*); +static Bool BeginPaint(Widget); +static Bool EndPaint(Widget); +static void SetXlfdDefaults(Display*, XawTextProperty*); +#endif -static int MaxHeight(), MaxLines(); -static void DisplayText(), InsertCursor(), ClearToBackground(), FindPosition(); -static void FindDistance(), Resolve(), SetTabs(), GetCursorBounds(); +/* + * External + */ +void _XawTextSinkClearToBackground(Widget, int, int, unsigned, unsigned); +void _XawTextSinkDisplayText(Widget, int, int, XawTextPosition, XawTextPosition, + Bool); +/* + * Initialization + */ #define offset(field) XtOffsetOf(TextSinkRec, text_sink.field) static XtResource resources[] = { - {XtNforeground, XtCForeground, XtRPixel, sizeof (Pixel), - offset(foreground), XtRString, XtDefaultForeground}, - {XtNbackground, XtCBackground, XtRPixel, sizeof (Pixel), - offset(background), XtRString, XtDefaultBackground}, + { + XtNforeground, + XtCForeground, + XtRPixel, + sizeof(Pixel), + offset(foreground), + XtRString, + XtDefaultForeground + }, + { + XtNbackground, + XtCBackground, + XtRPixel, + sizeof(Pixel), + offset(background), + XtRString, + XtDefaultBackground + }, +#ifndef OLDXAW + { + XtNcursorColor, + XtCColor, + XtRPixel, + sizeof(Pixel), + offset(cursor_color), + XtRString, + XtDefaultForeground + }, + { + XawNtextProperties, + XawCTextProperties, + XawRTextProperties, + sizeof(XawTextPropertyList*), + offset(properties), + XtRImmediate, + NULL + }, +#endif }; #undef offset -#define SuperClass (&objectClassRec) +#ifndef OLDXAW +static TextSinkExtRec extension_rec = { + NULL, /* next_extension */ + NULLQUARK, /* record_type */ + 1, /* version */ + sizeof(TextSinkExtRec), /* record_size */ + BeginPaint, + NULL, + NULL, + EndPaint +}; + +static XrmQuark Qdefault; +#endif + +#define Superclass (&objectClassRec) TextSinkClassRec textSinkClassRec = { + /* object */ { -/* core_class fields */ - /* superclass */ (WidgetClass) SuperClass, - /* class_name */ "TextSink", - /* widget_size */ sizeof(TextSinkRec), - /* class_initialize */ XawInitializeWidgetSet, - /* class_part_initialize */ ClassPartInitialize, - /* class_inited */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* obj1 */ NULL, - /* obj2 */ NULL, - /* obj3 */ 0, - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* obj4 */ FALSE, - /* obj5 */ FALSE, - /* obj6 */ FALSE, - /* obj7 */ FALSE, - /* destroy */ Destroy, - /* obj8 */ NULL, - /* obj9 */ NULL, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* obj10 */ NULL, - /* get_values_hook */ NULL, - /* obj11 */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* obj12 */ NULL, - /* obj13 */ NULL, - /* obj14 */ NULL, - /* extension */ NULL + (WidgetClass)Superclass, /* superclass */ + "TextSink", /* class_name */ + sizeof(TextSinkRec), /* widget_size */ + XawInitializeWidgetSet, /* class_initialize */ + XawTextSinkClassPartInitialize, /* class_part_initialize */ + False, /* class_inited */ + XawTextSinkInitialize, /* initialize */ + NULL, /* initialize_hook */ + NULL, /* obj1 */ + NULL, /* obj2 */ + 0, /* obj3 */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + False, /* obj4 */ + False, /* obj5 */ + False, /* obj6 */ + False, /* obj7 */ + XawTextSinkDestroy, /* destroy */ + NULL, /* obj8 */ + NULL, /* obj9 */ + XawTextSinkSetValues, /* set_values */ + NULL, /* set_values_hook */ + NULL, /* obj10 */ + NULL, /* get_values_hook */ + NULL, /* obj11 */ + XtVersion, /* version */ + NULL, /* callback_private */ + NULL, /* obj12 */ + NULL, /* obj13 */ + NULL, /* obj14 */ + NULL, /* extension */ }, -/* textSink_class fields */ + /* text_sink */ { - /* DisplayText */ DisplayText, - /* InsertCursor */ InsertCursor, - /* ClearToBackground */ ClearToBackground, - /* FindPosition */ FindPosition, - /* FindDistance */ FindDistance, - /* Resolve */ Resolve, - /* MaxLines */ MaxLines, - /* MaxHeight */ MaxHeight, - /* SetTabs */ SetTabs, - /* GetCursorBounds */ GetCursorBounds, - } + DisplayText, /* DisplayText */ + InsertCursor, /* InsertCursor */ + ClearToBackground, /* ClearToBackground */ + FindPosition, /* FindPosition */ + FindDistance, /* FindDistance */ + Resolve, /* Resolve */ + MaxLines, /* MaxLines */ + MaxHeight, /* MaxHeight */ + SetTabs, /* SetTabs */ + GetCursorBounds, /* GetCursorBounds */ + }, }; WidgetClass textSinkObjectClass = (WidgetClass)&textSinkClassRec; +/* + * Implementation + */ static void -ClassPartInitialize(wc) -WidgetClass wc; +XawTextSinkClassPartInitialize(WidgetClass wc) { - TextSinkObjectClass t_src, superC; - - t_src = (TextSinkObjectClass) wc; - superC = (TextSinkObjectClass) t_src->object_class.superclass; - -/* - * We don't need to check for null super since we'll get to TextSink - * eventually. - */ - - if (t_src->text_sink_class.DisplayText == XtInheritDisplayText) - t_src->text_sink_class.DisplayText = superC->text_sink_class.DisplayText; - - if (t_src->text_sink_class.InsertCursor == XtInheritInsertCursor) - t_src->text_sink_class.InsertCursor = - superC->text_sink_class.InsertCursor; - - if (t_src->text_sink_class.ClearToBackground== XtInheritClearToBackground) - t_src->text_sink_class.ClearToBackground = - superC->text_sink_class.ClearToBackground; - - if (t_src->text_sink_class.FindPosition == XtInheritFindPosition) - t_src->text_sink_class.FindPosition = - superC->text_sink_class.FindPosition; - - if (t_src->text_sink_class.FindDistance == XtInheritFindDistance) - t_src->text_sink_class.FindDistance = - superC->text_sink_class.FindDistance; - - if (t_src->text_sink_class.Resolve == XtInheritResolve) - t_src->text_sink_class.Resolve = superC->text_sink_class.Resolve; + TextSinkObjectClass t_src, superC; +#ifndef OLDXAW + static XtConvertArgRec CvtArgs[] = { + {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.self), + sizeof(Widget)}, + }; +#endif - if (t_src->text_sink_class.MaxLines == XtInheritMaxLines) - t_src->text_sink_class.MaxLines = superC->text_sink_class.MaxLines; + t_src = (TextSinkObjectClass) wc; + superC = (TextSinkObjectClass) t_src->object_class.superclass; - if (t_src->text_sink_class.MaxHeight == XtInheritMaxHeight) - t_src->text_sink_class.MaxHeight = superC->text_sink_class.MaxHeight; +#ifndef OLDXAW + extension_rec.record_type = XrmPermStringToQuark("TextSink"); + extension_rec.next_extension = (XtPointer)t_src->text_sink_class.extension; + t_src->text_sink_class.extension = &extension_rec; - if (t_src->text_sink_class.SetTabs == XtInheritSetTabs) - t_src->text_sink_class.SetTabs = superC->text_sink_class.SetTabs; + Qdefault = XrmPermStringToQuark("default"); +#endif - if (t_src->text_sink_class.GetCursorBounds == XtInheritGetCursorBounds) - t_src->text_sink_class.GetCursorBounds = - superC->text_sink_class.GetCursorBounds; + /* + * We don't need to check for null super since we'll get to TextSink + * eventually. + */ + if (t_src->text_sink_class.DisplayText == XtInheritDisplayText) + t_src->text_sink_class.DisplayText = + superC->text_sink_class.DisplayText; + + if (t_src->text_sink_class.InsertCursor == XtInheritInsertCursor) + t_src->text_sink_class.InsertCursor = + superC->text_sink_class.InsertCursor; + + if (t_src->text_sink_class.ClearToBackground== XtInheritClearToBackground) + t_src->text_sink_class.ClearToBackground = + superC->text_sink_class.ClearToBackground; + + if (t_src->text_sink_class.FindPosition == XtInheritFindPosition) + t_src->text_sink_class.FindPosition = + superC->text_sink_class.FindPosition; + + if (t_src->text_sink_class.FindDistance == XtInheritFindDistance) + t_src->text_sink_class.FindDistance = + superC->text_sink_class.FindDistance; + + if (t_src->text_sink_class.Resolve == XtInheritResolve) + t_src->text_sink_class.Resolve = + superC->text_sink_class.Resolve; + + if (t_src->text_sink_class.MaxLines == XtInheritMaxLines) + t_src->text_sink_class.MaxLines = + superC->text_sink_class.MaxLines; + + if (t_src->text_sink_class.MaxHeight == XtInheritMaxHeight) + t_src->text_sink_class.MaxHeight = + superC->text_sink_class.MaxHeight; + + if (t_src->text_sink_class.SetTabs == XtInheritSetTabs) + t_src->text_sink_class.SetTabs = + superC->text_sink_class.SetTabs; + + if (t_src->text_sink_class.GetCursorBounds == XtInheritGetCursorBounds) + t_src->text_sink_class.GetCursorBounds = + superC->text_sink_class.GetCursorBounds; + +#ifndef OLDXAW + XtSetTypeConverter(XtRString, XawRTextProperties, CvtStringToPropertyList, + &CvtArgs[0], XtNumber(CvtArgs), XtCacheNone, NULL); + XtSetTypeConverter(XawRTextProperties, XtRString, CvtPropertyListToString, + NULL, 0, XtCacheNone, NULL); +#endif } -/* Function Name: Initialize - * Description: Initializes the TextSink Object. - * Arguments: request, new - the requested and new values for the object - * instance. - * Returns: none. +/* + * Function: + * XawTextSinkInitialize + * + * Parameters: + * request - requested and new values for the object instance + * cnew - "" * + * Description: + * Initializes the TextSink Object. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -Initialize(request, new, args, num_args) -Widget request, new; -ArgList args; -Cardinal *num_args; +XawTextSinkInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - TextSinkObject sink = (TextSinkObject) new; + TextSinkObject sink = (TextSinkObject)cnew; - sink->text_sink.tab_count = 0; /* Initialize the tab stops. */ - sink->text_sink.tabs = NULL; - sink->text_sink.char_tabs = NULL; + sink->text_sink.tab_count = 0; /* Initialize the tab stops. */ + sink->text_sink.tabs = NULL; + sink->text_sink.char_tabs = NULL; +#ifndef OLDXAW + sink->text_sink.paint = NULL; +#endif } -/* Function Name: Destroy - * Description: This function cleans up when the object is - * destroyed. - * Arguments: w - the TextSink Object. - * Returns: none. +/* + * Function: + * XawTextSinkDestroy + * + * Parameters: + * w - TextSink Object + * + * Description: + * This function cleans up when the object is destroyed. */ - static void -Destroy(w) -Widget w; +XawTextSinkDestroy(Widget w) { - TextSinkObject sink = (TextSinkObject) w; + TextSinkObject sink = (TextSinkObject) w; - XtFree((char *) sink->text_sink.tabs); - XtFree((char *) sink->text_sink.char_tabs); + XtFree((char *)sink->text_sink.tabs); + XtFree((char *)sink->text_sink.char_tabs); } -/* Function Name: SetValues - * Description: Sets the values for the TextSink - * Arguments: current - current state of the object. - * request - what was requested. - * new - what the object will become. - * Returns: True if redisplay is needed. +/* + * Function: + * XawTextSinkSetValues + * + * Parameters: + * current - current state of the object + * request - what was requested + * cnew - what the object will become + * + * Description: + * Sets the values for the TextSink. + * + * Returns: + * True if redisplay is needed */ - -/* ARGSUSED */ +/*ARGSUSED*/ static Boolean -SetValues(current, request, new, args, num_args) -Widget current, request, new; -ArgList args; -Cardinal *num_args; +XawTextSinkSetValues(Widget current, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - TextSinkObject w = (TextSinkObject) new; - TextSinkObject old_w = (TextSinkObject) current; + TextSinkObject w = (TextSinkObject)cnew; + TextSinkObject old_w = (TextSinkObject)current; - if (w->text_sink.foreground != old_w->text_sink.foreground) - ((TextWidget)XtParent(new))->text.redisplay_needed = True; + if (w->text_sink.foreground != old_w->text_sink.foreground) + ((TextWidget)XtParent(cnew))->text.redisplay_needed = True; - return FALSE; + return (False); } -/************************************************************ +/* + * Function: + * DisplayText * - * Class specific methods. + * Parameters: + * w - TextSink Object + * x - location to start drawing text + * y - "" + * pos1 - location of starting and ending points in the text buffer + * pos2 - "" + * highlight - hightlight this text? * - ************************************************************/ + * Description: + * Stub function that in subclasses will display text. + */ +/*ARGSUSED*/ +static void +DisplayText(Widget w, int x, int y, + XawTextPosition pos1, XawTextPosition pos2, Bool highlight) +{ + return; +} -/* Function Name: DisplayText - * Description: Stub function that in subclasses will display text. - * Arguments: w - the TextSink Object. - * x, y - location to start drawing text. - * pos1, pos2 - location of starting and ending points - * in the text buffer. - * highlight - hightlight this text? - * Returns: none. +/* + * Function: + * InsertCursor + * + * Parameters: + * w - TextSink Object + * x - location for the cursor + * y - "" + * state - whether to turn the cursor on, or off * - * This function doesn't actually display anything, it is only a place - * holder. + * Description: + * Places the InsertCursor. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -DisplayText(w, x, y, pos1, pos2, highlight) -Widget w; -Position x, y; -Boolean highlight; -XawTextPosition pos1, pos2; +InsertCursor(Widget w, int x, int y, XawTextInsertState state) { - return; + return; } -/* Function Name: InsertCursor - * Description: Places the InsertCursor. - * Arguments: w - the TextSink Object. - * x, y - location for the cursor. - * staye - whether to turn the cursor on, or off. - * Returns: none. +/* + * Function: + * ClearToBackground * - * This function doesn't actually display anything, it is only a place - * holder. + * Parameters: + * w - TextSink Object + * x - location of area to clear + * y - "" + * width - size of area to clear + * height - "" + * + * Description: + * Clears a region of the sink to the background color. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -InsertCursor(w, x, y, state) -Widget w; -Position x, y; -XawTextInsertState state; +ClearToBackground(Widget w, int x, int y, + unsigned int width, unsigned int height) { - return; + /* + * Don't clear in height or width are zero + * XClearArea() has special semantic for these values + */ + TextWidget xaw = (TextWidget)XtParent(w); + Position x1, y1, x2, y2; + + x1 = XawMax(x, xaw->text.r_margin.left); + y1 = XawMax(y, xaw->text.r_margin.top); + x2 = XawMin(x + (int)width, (int)XtWidth(xaw) - xaw->text.r_margin.right); + y2 = XawMin(y + (int)height, (int)XtHeight(xaw) - xaw->text.r_margin.bottom); + + x = x1; + y = y1; + width = XawMax(0, x2 - x1); + height = XawMax(0, y2 - y1); + + if (height != 0 && width != 0) + XClearArea(XtDisplayOfObject(w), XtWindowOfObject(w), + x, y, width, height, False); } -/* Function Name: ClearToBackground - * Description: Clears a region of the sink to the background color. - * Arguments: w - the TextSink Object. - * x, y - location of area to clear. - * width, height - size of area to clear - * Returns: void. +/* + * Function: + * FindPosition * + * Parameters: + * w - TextSink Object + * fromPos - reference position + * fromX - reference location + * width - width of section to paint text + * stopAtWordBreak - returned position is a word break? + * resPos - position found (return) + * resWidth - Width actually used (return) + * resHeight - Height actually used (return) + * + * Description: + * Finds a position in the text. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -ClearToBackground (w, x, y, width, height) -Widget w; -Position x, y; -Dimension width, height; -{ -/* - * Don't clear in height or width are zero. - * XClearArea() has special semantic for these values. - */ +FindPosition(Widget w, XawTextPosition fromPos, int fromx, int width, + Bool stopAtWordBreak, XawTextPosition *resPos, + int *resWidth, int *resHeight) +{ + *resPos = fromPos; + *resHeight = *resWidth = 0; +} - if ( (height == 0) || (width == 0) ) return; - XClearArea(XtDisplayOfObject(w), XtWindowOfObject(w), - x, y, width, height, False); -} - -/* Function Name: FindPosition - * Description: Finds a position in the text. - * Arguments: w - the TextSink Object. - * fromPos - reference position. - * fromX - reference location. - * width, - width of section to paint text. - * stopAtWordBreak - returned position is a word break? - * resPos - Position to return. *** RETURNED *** - * resWidth - Width actually used. *** RETURNED *** - * resHeight - Height actually used. *** RETURNED *** - * Returns: none (see above). +/* + * Function: + * FindDistance + * + * Parameters: + * w - TextSink Object + * fromPos - starting Position + * fromX - x location of starting Position + * toPos - end Position + * resWidth - Distance between fromPos and toPos + * resPos - Acutal toPos used + * resHeight - Height required by this text + * + * Description: + * Find the Pixel Distance between two text Positions. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -FindPosition(w, fromPos, fromx, width, stopAtWordBreak, - resPos, resWidth, resHeight) -Widget w; -XawTextPosition fromPos; -int fromx, width; -Boolean stopAtWordBreak; -XawTextPosition *resPos; -int *resWidth, *resHeight; -{ - *resPos = fromPos; - *resHeight = *resWidth = 0; -} - -/* Function Name: FindDistance - * Description: Find the Pixel Distance between two text Positions. - * Arguments: w - the TextSink Object. - * fromPos - starting Position. - * fromX - x location of starting Position. - * toPos - end Position. - * resWidth - Distance between fromPos and toPos. - * resPos - Acutal toPos used. - * resHeight - Height required by this text. - * Returns: none. - */ +FindDistance(Widget w, XawTextPosition fromPos, int fromx, + XawTextPosition toPos, int *resWidth, + XawTextPosition *resPos, int *resHeight) +{ + *resWidth = *resHeight = 0; + *resPos = fromPos; +} -/* ARGSUSED */ -static void -FindDistance (w, fromPos, fromx, toPos, resWidth, resPos, resHeight) -Widget w; -XawTextPosition fromPos; -int fromx; -XawTextPosition toPos; -int *resWidth; -XawTextPosition *resPos; -int *resHeight; -{ - *resWidth = *resHeight = 0; - *resPos = fromPos; -} - -/* Function Name: Resolve - * Description: Resloves a location to a position. - * Arguments: w - the TextSink Object. - * pos - a reference Position. - * fromx - a reference Location. - * width - width to move. - * resPos - the resulting position. - * Returns: none +/* + * Function: + * Resolve + * + * Parameters: + * w - TextSink Object + * pos - reference Position + * fromx - reference Location + * width - width to move + * resPos - resulting position + * + * Description: + * Resloves a location to a position. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -Resolve (w, pos, fromx, width, resPos) -Widget w; -XawTextPosition pos; -int fromx, width; -XawTextPosition *resPos; +Resolve(Widget w, XawTextPosition pos, int fromx, int width, + XawTextPosition *resPos) { - *resPos = pos; + *resPos = pos; } -/* Function Name: MaxLines - * Description: Finds the Maximum number of lines that will fit in - * a given height. - * Arguments: w - the TextSink Object. - * height - height to fit lines into. - * Returns: the number of lines that will fit. +/* + * Function: + * MaxLines + * + * Parameters: + * w - TextSink Object + * height - height to fit lines into + * + * Description: + * Finds the Maximum number of lines that will fit in a given height. + * + * Returns: + * Number of lines that will fit */ - -/* ARGSUSED */ +/*ARGSUSED*/ static int -MaxLines(w, height) -Widget w; -Dimension height; -{ - /* - * The fontset has gone down to descent Sink Widget, so - * the functions such MaxLines, SetTabs... are bound to the descent. - * - * by Li Yuhong, Jan. 15, 1991 - */ - return 0; -} - -/* Function Name: MaxHeight - * Description: Finds the Minium height that will contain a given number - * lines. - * Arguments: w - the TextSink Object. - * lines - the number of lines. - * Returns: the height. - */ +MaxLines(Widget w, unsigned int height) +{ + /* + * The fontset has gone down to descent Sink Widget, so + * the functions such MaxLines, SetTabs... are bound to the descent. + * + * by Li Yuhong, Jan. 15, 1991 + */ + return (0); +} -/* ARGSUSED */ +/* + * Function: + * MaxHeight + * + * Parameters: + * w - TextSink Object + * lines - number of lines + * + * Description: + * Finds the Minium height that will contain a given number lines. + * + * Returns: + * the height + */ +/*ARGSUSED*/ static int -MaxHeight(w, lines) -Widget w; -int lines; +MaxHeight(Widget w, int lines) { - return 0; + return (0); } -/* Function Name: SetTabs - * Description: Sets the Tab stops. - * Arguments: w - the TextSink Object. - * tab_count - the number of tabs in the list. - * tabs - the text positions of the tabs. - * Returns: none +/* + * Function: + * SetTabs + * + * Parameters: + * w - TextSink Object + * tab_count - the number of tabs in the list + * tabs - text positions of the tabs + * Description: + * Sets the Tab stops. */ - /*ARGSUSED*/ static void -SetTabs(w, tab_count, tabs) -Widget w; -int tab_count; -short *tabs; +SetTabs(Widget w, int tab_count, short *tabs) { - return; + return; } -/* Function Name: GetCursorBounds - * Description: Finds the bounding box for the insert curor (caret). - * Arguments: w - the TextSinkObject. - * rect - an X rectance containing the cursor bounds. - * Returns: none (fills in rect). +/* + * Function: + * GetCursorBounds + * + * Parameters: + * w - TextSinkObject. + * rect - X rectangle containing the cursor bounds + * + * Description: + * Finds the bounding box for the insert cursor (caret) */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -GetCursorBounds(w, rect) -Widget w; -XRectangle * rect; +GetCursorBounds(Widget w, XRectangle *rect) { - rect->x = rect->y = rect->width = rect->height = 0; + rect->x = rect->y = rect->width = rect->height = 0; } -/************************************************************ - * - * Public Functions. - * - ************************************************************/ - -/* Function Name: XawTextSinkDisplayText - * Description: Stub function that in subclasses will display text. - * Arguments: w - the TextSink Object. - * x, y - location to start drawing text. - * pos1, pos2 - location of starting and ending points - * in the text buffer. - * highlight - hightlight this text? - * Returns: none. +/* + * Public Functions + */ +/* + * Function: + * XawTextSinkDisplayText * - * This function doesn't actually display anything, it is only a place - * holder. + * Parameters: + * w - TextSink Object + * x - location to start drawing text + * y - "" + * pos1 - location of starting and ending points in the text buffer + * pos2 - "" + * highlight - hightlight this text? */ - -/* ARGSUSED */ +/*ARGSUSED*/ void -#if NeedFunctionPrototypes XawTextSinkDisplayText(Widget w, #if NeedWidePrototypes - /* Position */ int x, /* Position */ int y, + int x, int y, #else Position x, Position y, #endif XawTextPosition pos1, XawTextPosition pos2, #if NeedWidePrototypes - /* Boolean */ int highlight) -#else - Boolean highlight) -#endif + int highlight #else -XawTextSinkDisplayText(w, x, y, pos1, pos2, highlight) -Widget w; -Position x, y; -Boolean highlight; -XawTextPosition pos1, pos2; + Boolean highlight #endif +) +{ + _XawTextSinkDisplayText(w, x, y, pos1, pos2, highlight); +} + +void +_XawTextSinkDisplayText(Widget w, int x, int y, + XawTextPosition pos1, XawTextPosition pos2, + Bool highlight) { - TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class; + TextSinkObjectClass cclass = (TextSinkObjectClass)w->core.widget_class; - (*class->text_sink_class.DisplayText)(w, x, y, pos1, pos2, highlight); + (*cclass->text_sink_class.DisplayText)(w, x, y, pos1, pos2, highlight); } -/* Function Name: XawTextSinkInsertCursor - * Description: Places the InsertCursor. - * Arguments: w - the TextSink Object. - * x, y - location for the cursor. - * staye - whether to turn the cursor on, or off. - * Returns: none. +/* + * Function: + * XawTextSinkInsertCursor + * + * Parameters: + * w - TextSink Object + * x - location for the cursor + * y - "" + * state - whether to turn the cursor on, or off * - * This function doesn't actually display anything, it is only a place - * holder. + * Description: + * Places the InsertCursor. */ - -/* ARGSUSED */ +/*ARGSUSED*/ void -#if NeedFunctionPrototypes -XawTextSinkInsertCursor(Widget w, #if NeedWidePrototypes - int x, int y, int state) +XawTextSinkInsertCursor(Widget w, int x, int y, int state) #else - Position x, Position y, XawTextInsertState state) -#endif -#else -XawTextSinkInsertCursor(w, x, y, state) -Widget w; -Position x, y; -XawTextInsertState state; +XawTextSinkInsertCursor(Widget w, Position x, Position y, XawTextInsertState state) #endif { - TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class; - - (*class->text_sink_class.InsertCursor)(w, x, y, state); -} + TextSinkObjectClass cclass = (TextSinkObjectClass)w->core.widget_class; + (*cclass->text_sink_class.InsertCursor)(w, x, y, state); +} -/* Function Name: XawTextSinkClearToBackground - * Description: Clears a region of the sink to the background color. - * Arguments: w - the TextSink Object. - * x, y - location of area to clear. - * width, height - size of area to clear - * Returns: void. +/* + * Function: + * XawTextSinkClearToBackground + * + * Parameters: + * w - TextSink Object + * x - location of area to clear + * y - "" + * width - size of area to clear + * height - "" * - * This function doesn't actually display anything, it is only a place - * holder. + * Description: + * Clears a region of the sink to the background color. */ - -/* ARGSUSED */ +/*ARGSUSED*/ void -#if NeedFunctionPrototypes -XawTextSinkClearToBackground (Widget w, +XawTextSinkClearToBackground(Widget w, #if NeedWidePrototypes - int x, int y, int width, int height) + int x, int y, + unsigned int width, unsigned int height #else - Position x, Position y, - Dimension width, Dimension height) -#endif -#else -XawTextSinkClearToBackground (w, x, y, width, height) -Widget w; -Position x, y; -Dimension width, height; + Position x, Position y, + Dimension width, Dimension height #endif +) { - TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class; + _XawTextSinkClearToBackground(w, x, y, width, height); +} - (*class->text_sink_class.ClearToBackground)(w, x, y, width, height); +void +_XawTextSinkClearToBackground(Widget w, + int x, int y, + unsigned int width, unsigned int height) +{ + TextSinkObjectClass cclass = (TextSinkObjectClass)w->core.widget_class; + + (*cclass->text_sink_class.ClearToBackground)(w, x, y, width, height); } -/* Function Name: XawTextSinkFindPosition - * Description: Finds a position in the text. - * Arguments: w - the TextSink Object. - * fromPos - reference position. - * fromX - reference location. - * width, - width of section to paint text. - * stopAtWordBreak - returned position is a word break? - * resPos - Position to return. *** RETURNED *** - * resWidth - Width actually used. *** RETURNED *** - * resHeight - Height actually used. *** RETURNED *** - * Returns: none (see above). +/* + * Function: + * XawTextSinkFindPosition + * + * Parameters: + * w - TextSink Object + * fromPos - reference position + * fromX - reference location + * width - width of section to paint text + * stopAtWordBreak - returned position is a word break? + * resPos - position found (return) + * resWidth - Width actually used (return) + * resHeight - Height actually used (return) + * + * Description: + * Finds a position in the text. */ - -/* ARGSUSED */ +/*ARGSUSED*/ void -#if NeedFunctionPrototypes -XawTextSinkFindPosition(Widget w, XawTextPosition fromPos, int fromx, - int width, +XawTextSinkFindPosition(Widget w, XawTextPosition fromPos, int fromx, int width, #if NeedWidePrototypes - /* Boolean */ int stopAtWordBreak, + int stopAtWordBreak, #else Boolean stopAtWordBreak, #endif XawTextPosition *resPos, int *resWidth, int *resHeight) -#else -XawTextSinkFindPosition(w, fromPos, fromx, width, stopAtWordBreak, - resPos, resWidth, resHeight) -Widget w; -XawTextPosition fromPos; -int fromx, width; -Boolean stopAtWordBreak; -XawTextPosition *resPos; -int *resWidth, *resHeight; -#endif { - TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class; + TextSinkObjectClass cclass = (TextSinkObjectClass)w->core.widget_class; - (*class->text_sink_class.FindPosition)(w, fromPos, fromx, width, - stopAtWordBreak, - resPos, resWidth, resHeight); + (*cclass->text_sink_class.FindPosition)(w, fromPos, fromx, width, + stopAtWordBreak, + resPos, resWidth, resHeight); } -/* Function Name: XawTextSinkFindDistance - * Description: Find the Pixel Distance between two text Positions. - * Arguments: w - the TextSink Object. - * fromPos - starting Position. - * fromX - x location of starting Position. - * toPos - end Position. - * resWidth - Distance between fromPos and toPos. - * resPos - Acutal toPos used. - * resHeight - Height required by this text. - * Returns: none. +/* + * Function: + * XawTextSinkFindDistance + * + * Parameters: + * w - TextSink Object + * fromPos - starting Position + * fromX - x location of starting Position + * toPos - end Position + * resWidth - Distance between fromPos and toPos + * resPos - Acutal toPos used + * resHeight - Height required by this text + * + * Description: + * Find the Pixel Distance between two text Positions. */ - -/* ARGSUSED */ +/*ARGSUSED*/ void -#if NeedFunctionPrototypes -XawTextSinkFindDistance (Widget w, XawTextPosition fromPos, int fromx, - XawTextPosition toPos, int *resWidth, - XawTextPosition *resPos, int *resHeight) -#else -XawTextSinkFindDistance (w, fromPos, fromx, toPos, resWidth, resPos, resHeight) -Widget w; -XawTextPosition fromPos, toPos, *resPos; -int fromx, *resWidth, *resHeight; -#endif +XawTextSinkFindDistance(Widget w, XawTextPosition fromPos, int fromx, + XawTextPosition toPos, int *resWidth, + XawTextPosition *resPos, int *resHeight) { - TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class; + TextSinkObjectClass cclass = (TextSinkObjectClass)w->core.widget_class; - (*class->text_sink_class.FindDistance)(w, fromPos, fromx, toPos, - resWidth, resPos, resHeight); + (*cclass->text_sink_class.FindDistance)(w, fromPos, fromx, toPos, + resWidth, resPos, resHeight); } -/* Function Name: XawTextSinkResolve - * Description: Resloves a location to a position. - * Arguments: w - the TextSink Object. - * pos - a reference Position. - * fromx - a reference Location. - * width - width to move. - * resPos - the resulting position. - * Returns: none +/* + * Function: + * XawTextSinkResolve + * + * Parameters: + * w - TextSink Object + * pos - reference Position + * fromx - reference Location + * width - width to move + * resPos - resulting position + * + * Description: + * Resloves a location to a position. */ - -/* ARGSUSED */ +/*ARGSUSED*/ void -#if NeedFunctionPrototypes XawTextSinkResolve(Widget w, XawTextPosition pos, int fromx, int width, XawTextPosition *resPos) -#else -XawTextSinkResolve(w, pos, fromx, width, resPos) -Widget w; -XawTextPosition pos; -int fromx, width; -XawTextPosition *resPos; -#endif { - TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class; + TextSinkObjectClass cclass = (TextSinkObjectClass) w->core.widget_class; - (*class->text_sink_class.Resolve)(w, pos, fromx, width, resPos); + (*cclass->text_sink_class.Resolve)(w, pos, fromx, width, resPos); } -/* Function Name: XawTextSinkMaxLines - * Description: Finds the Maximum number of lines that will fit in - * a given height. - * Arguments: w - the TextSink Object. - * height - height to fit lines into. - * Returns: the number of lines that will fit. +/* + * Function: + * XawTextSinkMaxLines + * + * Parameters: + * w - TextSink Object + * height - height to fit lines into + * + * Description: + * Finds the Maximum number of lines that will fit in a given height. + * + * Returns: + * Number of lines that will fit */ - -/* ARGSUSED */ +/*ARGSUSED*/ int -#if NeedFunctionPrototypes -XawTextSinkMaxLines(Widget w, #if NeedWidePrototypes - /* Dimension */ int height) -#else - Dimension height) -#endif +XawTextSinkMaxLines(Widget w, unsigned int height) #else -XawTextSinkMaxLines(w, height) -Widget w; -Dimension height; +XawTextSinkMaxLines(Widget w, Dimension height) #endif { - TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class; + TextSinkObjectClass cclass = (TextSinkObjectClass)w->core.widget_class; - return((*class->text_sink_class.MaxLines)(w, height)); + return((*cclass->text_sink_class.MaxLines)(w, height)); } -/* Function Name: XawTextSinkMaxHeight - * Description: Finds the Minimum height that will contain a given number - * lines. - * Arguments: w - the TextSink Object. - * lines - the number of lines. - * Returns: the height. +/* + * Function: + * XawTextSinkMaxHeight + * + * Parameters: + * w - TextSink Object + * lines - number of lines + * + * Description: + * Finds the Minium height that will contain a given number lines. + * + * Returns: + * the height */ - -/* ARGSUSED */ +/*ARGSUSED*/ int -#if NeedFunctionPrototypes XawTextSinkMaxHeight(Widget w, int lines) -#else -XawTextSinkMaxHeight(w, lines) -Widget w; -int lines; -#endif { - TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class; + TextSinkObjectClass cclass = (TextSinkObjectClass)w->core.widget_class; - return((*class->text_sink_class.MaxHeight)(w, lines)); + return((*cclass->text_sink_class.MaxHeight)(w, lines)); } -/* Function Name: XawTextSinkSetTabs - * Description: Sets the Tab stops. - * Arguments: w - the TextSink Object. - * tab_count - the number of tabs in the list. - * tabs - the text positions of the tabs. - * Returns: none +/* + * Function: + * XawTextSinkSetTabs + * + * Parameters: + * w - TextSink Object + * tab_count - the number of tabs in the list + * tabs - text positions of the tabs + * Description: + * Sets the Tab stops. */ - void -#if NeedFunctionPrototypes XawTextSinkSetTabs(Widget w, int tab_count, int *tabs) -#else -XawTextSinkSetTabs(w, tab_count, tabs) -Widget w; -int tab_count, *tabs; +{ + if (tab_count > 0) { + TextSinkObjectClass cclass = (TextSinkObjectClass)w->core.widget_class; + short *char_tabs = (short*)XtMalloc((unsigned)tab_count * sizeof(short)); + short *tab, len = 0; + int i; + + for (i = tab_count, tab = char_tabs; i; i--) { + if ((short)*tabs > len) + *tab++ = (len = (short)*tabs++); + else { + tabs++; + --tab_count; + } + } + + if (tab_count > 0) + (*cclass->text_sink_class.SetTabs)(w, tab_count, char_tabs); + XtFree((char *)char_tabs); + } +} + +/* + * Function: + * XawTextSinkGetCursorBounds + * + * Parameters: + * w - TextSinkObject + * rect - X rectance containing the cursor bounds + * + * Description: + * Finds the bounding box for the insert cursor (caret). + */ +/*ARGSUSED*/ +void +XawTextSinkGetCursorBounds(Widget w, XRectangle *rect) +{ + TextSinkObjectClass cclass = (TextSinkObjectClass)w->core.widget_class; + + (*cclass->text_sink_class.GetCursorBounds)(w, rect); +} + +#ifndef OLDXAW +Bool +XawTextSinkBeginPaint(Widget w) +{ + TextSinkObjectClass cclass = (TextSinkObjectClass)w->core.widget_class; + + if (cclass->text_sink_class.extension->BeginPaint == NULL || + cclass->text_sink_class.extension->PreparePaint == NULL || + cclass->text_sink_class.extension->DoPaint == NULL || + cclass->text_sink_class.extension->EndPaint == NULL) + return (False); + + return ((*cclass->text_sink_class.extension->BeginPaint)(w)); +} + +static Bool +BeginPaint(Widget w) +{ + TextSinkObject sink = (TextSinkObject)w; + + if (sink->text_sink.paint != NULL) + return (False); + + sink->text_sink.paint = XtNew(XawTextPaintList); + sink->text_sink.paint->clip = XmuCreateArea(); + sink->text_sink.paint->hightabs = NULL; + sink->text_sink.paint->paint = NULL; + sink->text_sink.paint->bearings = NULL; + + return (True); +} + +void +XawTextSinkPreparePaint(Widget w, int y, int line, XawTextPosition from, + XawTextPosition to, Bool highlight) +{ + TextSinkObjectClass cclass = (TextSinkObjectClass)w->core.widget_class; + + (*cclass->text_sink_class.extension->PreparePaint) + (w, y, line, from, to, highlight); +} + +#if 0 +/*ARGSUSED*/ +static void +PreparePaint(Widget w, int y, int line, XawTextPosition from, XawTextPosition to, + Bool highlight) +{ +} #endif + +void +XawTextSinkDoPaint(Widget w) +{ + TextSinkObjectClass cclass = (TextSinkObjectClass)w->core.widget_class; + + (*cclass->text_sink_class.extension->DoPaint)(w); +} + +#if 0 +/*ARGSUSED*/ +static void +DoPaint(Widget w) +{ +} +#endif + +Bool +XawTextSinkEndPaint(Widget w) +{ + TextSinkObjectClass cclass = (TextSinkObjectClass)w->core.widget_class; + + return ((*cclass->text_sink_class.extension->EndPaint)(w)); +} + +static Bool +EndPaint(Widget w) +{ + TextSinkObject sink = (TextSinkObject)w; + XawTextPaintStruct *paint, *next; + + if (sink->text_sink.paint == NULL) + return (False); + + XmuDestroyArea(sink->text_sink.paint->clip); + if (sink->text_sink.paint->hightabs) + XmuDestroyArea(sink->text_sink.paint->hightabs); + paint = sink->text_sink.paint->paint; + while (paint) { + next = paint->next; + if (paint->text) + XtFree((XtPointer)paint->text); + if (paint->backtabs) + XmuDestroyArea(paint->backtabs); + XtFree((XtPointer)paint); + paint = next; + } + + paint = sink->text_sink.paint->bearings; + while (paint) { + next = paint->next; + if (paint->text) + XtFree((XtPointer)paint->text); + XtFree((XtPointer)paint); + paint = next; + } + + XtFree((XtPointer)sink->text_sink.paint); + sink->text_sink.paint = NULL; + return (True); +} + +static XawTextPropertyList **prop_lists; +static Cardinal num_prop_lists; + +static int +bcmp_qident(_Xconst void *left, _Xconst void *right) +{ + return ((long)left - (*(XawTextProperty**)right)->identifier); +} + +static int +qcmp_qident(_Xconst void *left, _Xconst void *right) +{ + return ((*(XawTextProperty**)left)->identifier - + (*(XawTextProperty**)right)->identifier); +} + +static void +SetXlfdDefaults(Display *display, XawTextProperty *property) +{ + Atom atom = XInternAtom(display, "FONT", True); + unsigned long value; + char *str; + + if (XGetFontProperty(property->font, atom, &value)) { + char *xlfd = XGetAtomName(display, value); + + if (xlfd) { + char *sep = xlfd + 1; + char *name = sep; + + property->xlfd = XrmStringToQuark(xlfd); + + sep = strchr(sep, '-'); *sep++ = '\0'; + property->foundry = XrmStringToQuark(name); + name = sep; + + sep = strchr(sep, '-'); *sep++ = '\0'; + property->family = XrmStringToQuark(name); + name = sep; + + sep = strchr(sep, '-'); *sep++ = '\0'; + property->weight = XrmStringToQuark(name); + name = sep; + + sep = strchr(sep, '-'); *sep++ = '\0'; + property->slant = XrmStringToQuark(name); + name = sep; + + sep = strchr(sep, '-'); *sep++ = '\0'; + property->setwidth = XrmStringToQuark(name); + name = sep; + + sep = strchr(sep, '-'); *sep++ = '\0'; + property->addstyle = XrmStringToQuark(name); + name = sep; + + sep = strchr(sep, '-'); *sep++ = '\0'; + property->pixel_size = XrmStringToQuark(name); + name = sep; + + sep = strchr(sep, '-'); *sep++ = '\0'; + property->point_size = XrmStringToQuark(name); + name = sep; + + sep = strchr(sep, '-'); *sep++ = '\0'; + property->res_x = XrmStringToQuark(name); + name = sep; + + sep = strchr(sep, '-'); *sep++ = '\0'; + property->res_y = XrmStringToQuark(name); + name = sep; + + sep = strchr(sep, '-'); *sep++ = '\0'; + property->spacing = XrmStringToQuark(name); + name = sep; + + sep = strchr(sep, '-'); *sep++ = '\0'; + property->avgwidth = XrmStringToQuark(name); + name = sep; + + sep = strchr(sep, '-'); *sep++ = '\0'; + property->registry = XrmStringToQuark(name); + name = sep; + + property->encoding = XrmStringToQuark(name); + + XFree(xlfd); + } + } + + atom = XInternAtom(display, "UNDERLINE_THICKNESS", True); + if (XGetFontProperty(property->font, atom, &value) && + (str = XGetAtomName(display, value)) != NULL) { + property->underline_thickness = atoi(str); + XFree(str); + } + else { + /* XLFD says: + * CapStemWidth = average width of the stems of capitals + * if (UNDERLINE_THICKNESS undefined) then + * UNDERLINE_THICKNESS = CapStemWidth + * + * How do I know the value of CapStemWidth?? + */ + if (property->pixel_size != NULLQUARK) { + property->underline_thickness = + atoi(XrmQuarkToString(property->pixel_size)) / 10; + property->underline_thickness = + XawMax(1, property->underline_thickness); + } + else + property->underline_thickness = 1; + } + + atom = XInternAtom(display, "UNDERLINE_POSITION", True); + if (XGetFontProperty(property->font, atom, &value) && + (str = XGetAtomName(display, value)) != NULL) { + property->underline_position = atoi(str); + XFree(str); + } + else + /* XLFD says: + * if (UNDERLINE_POSITION undefined) then + * UNDERLINE_POSITION = ROUND((maximum_descent) / 2) + */ + property->underline_position = + property->font->max_bounds.descent >> 1; + + /* I am assuming xlfd does not consider that lines are + * centered in the path */ + property->underline_position += property->underline_thickness >> 1; + +} + +static void +DestroyTextPropertyList(XawTextPropertyList *list) { - if (tab_count > 0) { - TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class; - short *char_tabs = (short*)XtMalloc( (unsigned)tab_count*sizeof(short) ); - short *tab; int i; - for (i = tab_count, tab = char_tabs; i; i--) *tab++ = (short)*tabs++; + for (i = 0; i < list->num_properties; i++) { + if (list->properties[i]->font) + XFreeFont(DisplayOfScreen(list->screen), list->properties[i]->font); + XtFree((char*)list->properties[i]); + } + if (list->properties) + XtFree((char*)list->properties); + XtFree((char*)list); +} - (*class->text_sink_class.SetTabs)(w, tab_count, char_tabs); - XtFree((char *)char_tabs); - } +static XawTextProperty * +_XawTextSinkGetProperty(XawTextPropertyList *list, XrmQuark property) +{ + if (property != NULLQUARK && list && list->properties) { + XawTextProperty **ptr = (XawTextProperty**) + bsearch((void*)(long)property, + list->properties, list->num_properties, + sizeof(XawTextProperty*), bcmp_qident); + + if (ptr) + return (*ptr); + } + + return (NULL); +} + +XawTextProperty * +XawTextSinkGetProperty(Widget w, XrmQuark property) +{ + TextSinkObject sink = (TextSinkObject)w; + XawTextPropertyList *list = sink->text_sink.properties; + + return (_XawTextSinkGetProperty(list, property)); +} + +XawTextProperty * +XawTextSinkCopyProperty(Widget w, XrmQuark property) +{ + XawTextProperty *cur, *ret; + + if ((cur = XawTextSinkGetProperty(w, property)) == NULL) + cur = XawTextSinkGetProperty(w, Qdefault); + ret = (XawTextProperty*)XtCalloc(1, sizeof(XawTextProperty)); + if (cur) + memcpy(ret, cur, sizeof(XawTextProperty)); + ret->identifier = NULLQUARK; + ret->mask &= ~XAW_TPROP_FONT; + + return (ret); +} + +static XawTextProperty * +_XawTextSinkAddProperty(XawTextPropertyList *list, XawTextProperty *property, + Bool replace) +{ + XawTextProperty *result; + XColor color; + char identifier[1024]; + char foreground[16]; + char background[16]; + char *foundry, *family, *weight, *slant, *setwidth, *addstyle, *pixel_size, + *point_size, *res_x, *res_y, *spacing, *avgwidth, *registry, *encoding; + char *xlfd; + static char *asterisk = "*", *null = ""; + XrmQuark quark; + + if (list == NULL || property == NULL) + return (NULL); + + if (property->mask & XAW_TPROP_FOREGROUND) { + color.pixel = property->foreground; + XQueryColor(DisplayOfScreen(list->screen), list->colormap, &color); + XmuSnprintf(foreground, sizeof(foreground), "%04x%04x%04x", + color.red, color.green, color.blue); + } + else + strcpy(foreground, asterisk); + if (property->mask & XAW_TPROP_BACKGROUND) { + color.pixel = property->background; + XQueryColor(DisplayOfScreen(list->screen), list->colormap, &color); + XmuSnprintf(background, sizeof(background), "%04x%04x%04x", + color.red, color.green, color.blue); + } + else + strcpy(background, asterisk); + + if (property->xlfd_mask & XAW_TPROP_FOUNDRY) + foundry = XrmQuarkToString(property->foundry); + else + foundry = asterisk; + + /* use default, or what was requested */ + if (property->family != NULLQUARK) + family = XrmQuarkToString(property->family); + else + family = asterisk; + if (property->weight != NULLQUARK) + weight = XrmQuarkToString(property->weight); + else + weight = asterisk; + if (property->slant != NULLQUARK) { + slant = XrmQuarkToString(property->slant); + if (toupper(*slant) != 'R') + slant = asterisk; /* X defaults to italics, so, don't + care in resolving between `I' and `O' */ + } + else + slant = asterisk; + + if (property->xlfd_mask & XAW_TPROP_SETWIDTH) + setwidth = XrmQuarkToString(property->setwidth); + else + setwidth = asterisk; + if (property->xlfd_mask & XAW_TPROP_ADDSTYLE) + addstyle = XrmQuarkToString(property->addstyle); + else + addstyle = null; + + /* use default, or what was requested */ + if (!(property->mask & XAW_TPROP_POINTSIZE) && + property->pixel_size != NULLQUARK) + pixel_size = XrmQuarkToString(property->pixel_size); + else + pixel_size = asterisk; + + if (property->xlfd_mask & XAW_TPROP_POINTSIZE) + point_size = XrmQuarkToString(property->point_size); + else + point_size = asterisk; + if (property->xlfd_mask & XAW_TPROP_RESX) + res_x = XrmQuarkToString(property->res_x); + else + res_x = asterisk; + if (property->xlfd_mask & XAW_TPROP_RESY) + res_y = XrmQuarkToString(property->res_y); + else + res_y = asterisk; + if (property->xlfd_mask & XAW_TPROP_SPACING) + spacing = XrmQuarkToString(property->spacing); + else + spacing = asterisk; + if (property->xlfd_mask & XAW_TPROP_AVGWIDTH) + avgwidth = XrmQuarkToString(property->avgwidth); + else + avgwidth = asterisk; + + /* use default, or what that was requested */ + if (property->registry != NULLQUARK) + registry = XrmQuarkToString(property->registry); + else + registry = asterisk; + if (property->encoding != NULLQUARK) + encoding = XrmQuarkToString(property->encoding); + else + encoding = asterisk; + + if (replace) { + result = XtNew(XawTextProperty); + memcpy(result, property, sizeof(XawTextProperty)); + } + else + result = property; + + /* XXX should do the best to load a suitable font here */ + if (!(result->mask & XAW_TPROP_FONT)) { + XmuSnprintf(identifier, sizeof(identifier), + "-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s", + foundry, family, weight, slant, setwidth, addstyle, pixel_size, + point_size, res_x, res_y, spacing, avgwidth, registry, encoding); + if ((result->font = XLoadQueryFont(DisplayOfScreen(list->screen), + identifier)) != NULL) { + result->mask |= XAW_TPROP_FONT; + SetXlfdDefaults(DisplayOfScreen(list->screen), result); + } + else + result->mask &= ~XAW_TPROP_FONT; + } + + if (result->font) + xlfd = XrmQuarkToString(result->xlfd); + else + xlfd = null; + + XmuSnprintf(identifier, sizeof(identifier), "%08x%08x%s%s%d%d%d%d%s", + property->mask, property->xlfd_mask, + foreground, background, + (result->mask & XAW_TPROP_UNDERLINE) != 0, + (result->mask & XAW_TPROP_OVERSTRIKE) != 0, + (result->mask & XAW_TPROP_SUBSCRIPT) != 0, + (result->mask & XAW_TPROP_SUPERSCRIPT) != 0, + xlfd); + + quark = XrmStringToQuark(identifier); + if (result->identifier == NULLQUARK) + result->identifier = quark; + result->code = quark; + + if ((property = _XawTextSinkGetProperty(list, result->identifier)) != NULL) { + if (result->font) + XFreeFont(DisplayOfScreen(list->screen), result->font); + if (replace) + XtFree((XtPointer)result); + + return (property); + } + + list->properties = (XawTextProperty**) + XtRealloc((XtPointer)list->properties, sizeof(XawTextProperty*) * + (list->num_properties + 1)); + list->properties[list->num_properties++] = result; + qsort((void*)list->properties, list->num_properties, + sizeof(XawTextProperty*), qcmp_qident); + + return (result); +} + +XawTextProperty * +XawTextSinkAddProperty(Widget w, XawTextProperty *property) +{ + TextSinkObject sink = (TextSinkObject)w; + XawTextPropertyList *list = sink->text_sink.properties; + + return (_XawTextSinkAddProperty(list, property, True)); } - -/* Function Name: XawTextSinkGetCursorBounds - * Description: Finds the bounding box for the insert curor (caret). - * Arguments: w - the TextSinkObject. - * rect - an X rectance containing the cursor bounds. - * Returns: none (fills in rect). + +XawTextProperty * +XawTextSinkCombineProperty(Widget w, + XawTextProperty *property, XawTextProperty *combine, + Bool override) +{ + if (property == NULL || combine == NULL) + return (property); + + if ((override || !(property->mask & XAW_TPROP_FOREGROUND)) && + (combine->mask & XAW_TPROP_FOREGROUND)) { + property->mask |= XAW_TPROP_FOREGROUND; + property->foreground = combine->foreground; + } + if ((override || !(property->mask & XAW_TPROP_BACKGROUND)) && + (combine->mask & XAW_TPROP_BACKGROUND)) { + property->mask |= XAW_TPROP_BACKGROUND; + property->background = combine->background; + } + if ((override || !(property->mask & XAW_TPROP_FPIXMAP)) && + (combine->mask & XAW_TPROP_FPIXMAP)) { + property->mask |= XAW_TPROP_FPIXMAP; + property->foreground_pixmap = combine->foreground_pixmap; + } + if ((override || !(property->mask & XAW_TPROP_BPIXMAP)) && + (combine->mask & XAW_TPROP_BPIXMAP)) { + property->mask |= XAW_TPROP_BPIXMAP; + property->background_pixmap = combine->background_pixmap; + } + if (combine->mask & XAW_TPROP_UNDERLINE) + property->mask |= XAW_TPROP_UNDERLINE; + if (combine->mask & XAW_TPROP_OVERSTRIKE) + property->mask |= XAW_TPROP_OVERSTRIKE; + if ((override || !(property->mask & XAW_TPROP_SUPERSCRIPT)) && + (combine->mask & XAW_TPROP_SUBSCRIPT)) + property->mask |= XAW_TPROP_SUBSCRIPT; + if ((property->mask & XAW_TPROP_SUBSCRIPT) && + (combine->mask & XAW_TPROP_SUPERSCRIPT)) + property->mask |= XAW_TPROP_SUPERSCRIPT; + if ((override || !(property->xlfd_mask & XAW_TPROP_FOUNDRY)) && + (combine->xlfd_mask & XAW_TPROP_FOUNDRY)) { + property->xlfd_mask |= XAW_TPROP_FOUNDRY; + property->foundry = combine->foundry; + } + if ((override || !(property->xlfd_mask & XAW_TPROP_FAMILY)) && + (combine->xlfd_mask & XAW_TPROP_FAMILY)) { + property->xlfd_mask |= XAW_TPROP_FAMILY; + property->family = combine->family; + } + if ((override || !(property->xlfd_mask & XAW_TPROP_WEIGHT)) && + (combine->xlfd_mask & XAW_TPROP_WEIGHT)) { + property->xlfd_mask |= XAW_TPROP_WEIGHT; + property->weight = combine->weight; + } + if ((override || !(property->xlfd_mask & XAW_TPROP_SLANT)) && + (combine->xlfd_mask & XAW_TPROP_SLANT)) { + property->xlfd_mask |= XAW_TPROP_SLANT; + property->slant = combine->slant; + } + if ((override || !(property->xlfd_mask & XAW_TPROP_SETWIDTH)) && + (combine->xlfd_mask & XAW_TPROP_SETWIDTH)) { + property->xlfd_mask |= XAW_TPROP_SETWIDTH; + property->setwidth = combine->setwidth; + } + if ((override || !(property->xlfd_mask & XAW_TPROP_ADDSTYLE)) && + (combine->xlfd_mask & XAW_TPROP_ADDSTYLE)) { + property->xlfd_mask |= XAW_TPROP_ADDSTYLE; + property->addstyle = combine->addstyle; + } + if ((override || !(property->xlfd_mask & XAW_TPROP_PIXELSIZE)) && + (combine->xlfd_mask & XAW_TPROP_PIXELSIZE)) { + property->xlfd_mask |= XAW_TPROP_PIXELSIZE; + property->pixel_size = combine->pixel_size; + } + if ((override || !(property->xlfd_mask & XAW_TPROP_POINTSIZE)) && + (combine->xlfd_mask & XAW_TPROP_POINTSIZE)) { + property->xlfd_mask |= XAW_TPROP_POINTSIZE; + property->point_size = combine->point_size; + } + if ((override || !(property->xlfd_mask & XAW_TPROP_RESX)) && + (combine->xlfd_mask & XAW_TPROP_RESX)) { + property->xlfd_mask |= XAW_TPROP_RESX; + property->res_x = combine->res_x; + } + if ((override || !(property->xlfd_mask & XAW_TPROP_RESY)) && + (combine->xlfd_mask & XAW_TPROP_RESY)) { + property->xlfd_mask |= XAW_TPROP_RESY; + property->res_y = combine->res_y; + } + if ((override || !(property->xlfd_mask & XAW_TPROP_SPACING)) && + (combine->xlfd_mask & XAW_TPROP_SPACING)) { + property->xlfd_mask |= XAW_TPROP_SPACING; + property->spacing = combine->spacing; + } + if ((override || !(property->xlfd_mask & XAW_TPROP_AVGWIDTH)) && + (combine->xlfd_mask & XAW_TPROP_AVGWIDTH)) { + property->xlfd_mask |= XAW_TPROP_AVGWIDTH; + property->avgwidth = combine->avgwidth; + } + if ((override || !(property->xlfd_mask & XAW_TPROP_REGISTRY)) && + (combine->xlfd_mask & XAW_TPROP_REGISTRY)) { + property->xlfd_mask |= XAW_TPROP_REGISTRY; + property->registry = combine->registry; + } + if ((override || !(property->xlfd_mask & XAW_TPROP_ENCODING)) && + (combine->xlfd_mask & XAW_TPROP_ENCODING)) { + property->xlfd_mask |= XAW_TPROP_ENCODING; + property->encoding = combine->encoding; + } + + return (property); +} + +/* + * The default property must be defined first, if the code is willing to + * combine properties. */ +XawTextPropertyList * +XawTextSinkConvertPropertyList(String name, String spec, Screen *screen, + Colormap colormap, int depth) +{ + XrmQuark qname = XrmStringToQuark(name); + XawTextPropertyList **ptr = NULL; + XawTextPropertyList *propl, *prev = NULL; + XawTextProperty *def_prop = NULL; + String str, tok, tmp; + char buffer[BUFSIZ]; + + if (prop_lists) ptr = (XawTextPropertyList**) + bsearch((void*)(long)qname, prop_lists, num_prop_lists, + sizeof(XawTextPropertyList*), bcmp_qident); + if (ptr) { + propl = *ptr; + while (propl) { + prev = propl; + if (propl->screen == screen && + propl->colormap == colormap && + propl->depth == depth) + return (propl); + propl = propl->next; + } + } + + propl = XtNew(XawTextPropertyList); + propl->identifier = qname; + propl->screen = screen; + propl->colormap = colormap; + propl->depth = depth; + propl->next = NULL; + + if (prev) + prev->next = propl; + + propl->properties = NULL; + propl->num_properties = 0; + + str = XtNewString(spec); + for (tok = str; tok; tok = tmp) { + XawTextProperty *prop; + XawParams *params; + XrmQuark ident; + XawArgVal *argval; + XColor color, exact; + + if (def_prop == NULL && propl->num_properties) + def_prop = _XawTextSinkGetProperty(propl, Qdefault); + tmp = strchr(tok, ','); + if (tmp) { + *tmp = '\0'; + if (*++tmp == '\0') + tmp = NULL; + } + params = XawParseParamsString(tok); + ident = XrmStringToQuark(params->name); + if (ident == NULLQUARK) { + XmuSnprintf(buffer, sizeof(buffer), + "Bad text property name \"%s\".", params->name); + XtAppWarning(XtDisplayToApplicationContext + (DisplayOfScreen(screen)), buffer); + DestroyTextPropertyList(propl); + if (prev) + prev->next = NULL; + XawFreeParamsStruct(params); + return (NULL); + } + else if (_XawTextSinkGetProperty(propl, ident) != NULL) { + XawFreeParamsStruct(params); + continue; + } + + prop = (XawTextProperty*)XtCalloc(1, sizeof(XawTextProperty)); + prop->identifier = ident; + + if ((argval = XawFindArgVal(params, "font")) != NULL && + argval->value) { + + if ((prop->font = XLoadQueryFont(DisplayOfScreen(screen), + argval->value)) == NULL) { + XmuSnprintf(buffer, sizeof(buffer), + "Cannot load font \"%s\".", argval->value); + XtAppWarning(XtDisplayToApplicationContext + (DisplayOfScreen(screen)), buffer); + DestroyTextPropertyList(propl); + if (prev) + prev->next = NULL; + XawFreeParamsStruct(params); + return (NULL); + } + prop->mask |= XAW_TPROP_FONT; + SetXlfdDefaults(DisplayOfScreen(screen), prop); + } + /* fontset processing here */ + + if ((argval = XawFindArgVal(params, "foreground")) != NULL && + argval->value) { + if (!XAllocNamedColor(DisplayOfScreen(screen), colormap, + argval->value, &color, &exact)) { + XmuSnprintf(buffer, sizeof(buffer), + "Cannot allocate color \"%s\".", argval->value); + XtAppWarning(XtDisplayToApplicationContext + (DisplayOfScreen(screen)), buffer); + DestroyTextPropertyList(propl); + if (prev) + prev->next = NULL; + XawFreeParamsStruct(params); + return (NULL); + } + prop->foreground = color.pixel; + prop->mask |= XAW_TPROP_FOREGROUND; + } + if ((argval = XawFindArgVal(params, "background")) != NULL && + argval->value) { + if (!XAllocNamedColor(DisplayOfScreen(screen), colormap, + argval->value, &color, &exact)) { + XmuSnprintf(buffer, sizeof(buffer), + "Cannot allocate color \"%s\".", argval->value); + XtAppWarning(XtDisplayToApplicationContext + (DisplayOfScreen(screen)), buffer); + DestroyTextPropertyList(propl); + if (prev) + prev->next = NULL; + XawFreeParamsStruct(params); + return (NULL); + } + prop->background = color.pixel; + prop->mask |= XAW_TPROP_BACKGROUND; + } + /* foreground_pixmap and background_pixmap processing here */ + + if (XawFindArgVal(params, "underline")) + prop->mask |= XAW_TPROP_UNDERLINE; + if (XawFindArgVal(params, "overstrike")) + prop->mask |= XAW_TPROP_OVERSTRIKE; + + if (XawFindArgVal(params, "subscript")) + prop->mask |= XAW_TPROP_SUBSCRIPT; + else if (XawFindArgVal(params, "superscript")) + prop->mask |= XAW_TPROP_SUPERSCRIPT; + + /* xlfd */ + if ((argval = XawFindArgVal(params, "foundry")) != NULL && + argval->value) { + prop->xlfd_mask |= XAW_TPROP_FOUNDRY; + prop->foundry = XrmStringToQuark(argval->value); + } + if ((argval = XawFindArgVal(params, "family")) != NULL && + argval->value) { + prop->xlfd_mask |= XAW_TPROP_FAMILY; + prop->family = XrmStringToQuark(argval->value); + } + if ((argval = XawFindArgVal(params, "weight")) != NULL && + argval->value) { + prop->xlfd_mask |= XAW_TPROP_WEIGHT; + prop->weight = XrmStringToQuark(argval->value); + } + if ((argval = XawFindArgVal(params, "slant")) != NULL && + argval->value) { + prop->xlfd_mask |= XAW_TPROP_SLANT; + prop->slant = XrmStringToQuark(argval->value); + } + if ((argval = XawFindArgVal(params, "setwidth")) != NULL && + argval->value) { + prop->xlfd_mask |= XAW_TPROP_SETWIDTH; + prop->setwidth = XrmStringToQuark(argval->value); + } + if ((argval = XawFindArgVal(params, "addstyle")) != NULL && + argval->value) { + prop->xlfd_mask |= XAW_TPROP_ADDSTYLE; + prop->addstyle = XrmStringToQuark(argval->value); + } + if ((argval = XawFindArgVal(params, "pixelsize")) != NULL && + argval->value) { + prop->xlfd_mask |= XAW_TPROP_PIXELSIZE; + prop->pixel_size = XrmStringToQuark(argval->value); + } + if ((argval = XawFindArgVal(params, "pointsize")) != NULL && + argval->value) { + prop->xlfd_mask |= XAW_TPROP_POINTSIZE; + prop->point_size = XrmStringToQuark(argval->value); + } + if ((argval = XawFindArgVal(params, "resx")) != NULL && + argval->value) { + prop->xlfd_mask |= XAW_TPROP_RESX; + prop->res_x = XrmStringToQuark(argval->value); + } + if ((argval = XawFindArgVal(params, "resy")) != NULL && + argval->value) { + prop->xlfd_mask |= XAW_TPROP_RESY; + prop->res_y = XrmStringToQuark(argval->value); + } + if ((argval = XawFindArgVal(params, "spacing")) != NULL && + argval->value) { + prop->xlfd_mask |= XAW_TPROP_SPACING; + prop->spacing = XrmStringToQuark(argval->value); + } + if ((argval = XawFindArgVal(params, "avgwidth")) != NULL && + argval->value) { + prop->xlfd_mask |= XAW_TPROP_AVGWIDTH; + prop->avgwidth = XrmStringToQuark(argval->value); + } + if ((argval = XawFindArgVal(params, "registry")) != NULL && + argval->value) { + prop->xlfd_mask |= XAW_TPROP_REGISTRY; + prop->registry = XrmStringToQuark(argval->value); + } + if ((argval = XawFindArgVal(params, "encoding")) != NULL && + argval->value) { + prop->xlfd_mask |= XAW_TPROP_ENCODING; + prop->encoding = XrmStringToQuark(argval->value); + } + + if (def_prop) + (void)XawTextSinkCombineProperty(NULL, prop, def_prop, False); + (void)_XawTextSinkAddProperty(propl, prop, False); + + XawFreeParamsStruct(params); + } + + prop_lists = (XawTextPropertyList**) + XtRealloc((XtPointer)prop_lists, sizeof(XawTextPropertyList*) * + (num_prop_lists + 1)); + prop_lists[num_prop_lists++] = propl; + qsort((void*)prop_lists, num_prop_lists, sizeof(XawTextPropertyList*), + qcmp_qident); + + XtFree(str); + + return (propl); +} -/* ARGSUSED */ -void -#if NeedFunctionPrototypes -XawTextSinkGetCursorBounds(Widget w, XRectangle *rect) -#else -XawTextSinkGetCursorBounds(w, rect) -Widget w; -XRectangle * rect; -#endif +/*ARGSUSED*/ +static Boolean +CvtStringToPropertyList(Display *dpy, XrmValue *args, Cardinal *num_args, + XrmValue *fromVal, XrmValue *toVal, + XtPointer *converter_data) { - TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class; + XawTextPropertyList *propl = NULL; + String name; + Widget w; + + if (*num_args != 1) { + XtAppWarningMsg(XtDisplayToApplicationContext(dpy), + "wrongParameters", "cvtStringToTextProperties", + "ToolkitError", + "String to textProperties conversion needs widget argument", + NULL, NULL); + return (False); + } + + w = *(Widget*)args[0].addr; + while (w && !XtIsWidget(w)) + w = XtParent(w); + + name = (String)(fromVal[0].addr); + + if (w) { + XawTextPropertyList **ptr = NULL; + if (prop_lists) ptr = (XawTextPropertyList**) + bsearch((void*)(long)XrmStringToQuark(name), + prop_lists, num_prop_lists, + sizeof(XawTextPropertyList*), bcmp_qident); + + if (ptr) { + Screen *screen = w->core.screen; + Colormap colormap = w->core.colormap; + int depth = w->core.depth; + + propl = *ptr; + while (propl) { + if (propl->screen == screen && + propl->colormap == colormap && + propl->depth == depth) + break; + propl = propl->next; + } + } + } + + if (!propl) { + XtDisplayStringConversionWarning(dpy, (String)fromVal->addr, + XawRTextProperties); + toVal->addr = NULL; + toVal->size = sizeof(XawTextPropertyList*); + return (False); + } + + if (toVal->addr != NULL) { + if (toVal->size < sizeof(XawTextPropertyList*)) { + toVal->size = sizeof(XawTextPropertyList*); + return (False); + } + *(XawTextPropertyList**)(toVal->addr) = propl; + } + else { + static XawTextPropertyList *static_val; + + static_val = propl; + toVal->addr = (XPointer)&static_val; + } + toVal->size = sizeof(XawTextProperty*); + + return (True); +} - (*class->text_sink_class.GetCursorBounds)(w, rect); +/*ARGSUSED*/ +static Boolean +CvtPropertyListToString(Display *dpy, XrmValue *args, Cardinal *num_args, + XrmValue *fromVal, XrmValue *toVal, + XtPointer *converter_data) +{ + static char *buffer; + Cardinal size; + XawTextPropertyList *propl; + + propl = *(XawTextPropertyList**)fromVal[0].addr; + + buffer = XrmQuarkToString(propl->identifier); + size = strlen(buffer) + 1; + + if (toVal->addr != NULL) { + if (toVal->size < size) { + toVal->size = size; + return (False); + } + strcpy((char *)toVal->addr, buffer); + } + else + toVal->addr = buffer; + toVal->size = size; + + return (True); } +#endif diff --git a/src/TextSrc.c b/src/TextSrc.c index d36040f..cc004ed 100644 --- a/src/TextSrc.c +++ b/src/TextSrc.c @@ -25,449 +25,1393 @@ in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/TextSrc.c,v 1.34 2002/09/22 07:09:05 paulo Exp $ */ + /* * Author: Chris Peterson, MIT X Consortium. * Much code taken from X11R3 String and Disk Sources. */ -/* - * TextSrc.c - TextSrc object. (For use with the text widget). - * - */ - +#include <stdio.h> +#include <ctype.h> #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> +#include <X11/Xfuncs.h> #include <X11/Xutil.h> -#include <X11/Xaw/XawInit.h> -#include <X11/Xaw/TextSrcP.h> #include <X11/Xmu/Atoms.h> #include <X11/Xmu/CharSet.h> +#include <X11/Xaw/TextSrcP.h> +#include <X11/Xaw/XawInit.h> #include "XawI18n.h" -#include <stdio.h> -#include <ctype.h> +#include "Private.h" -/**************************************************************** - * - * Full class record constant - * - ****************************************************************/ +#ifndef OLDXAW +#define UNDO_DEPTH 16384 -/* Private Data */ +#define ANCHORS_DIST 4096 /* default distance between anchors */ +/* + * Types + */ +typedef struct { + XawTextPosition position; + char *buffer; + unsigned length; + unsigned refcount; + unsigned long format; +} XawTextUndoBuffer; + +typedef struct _XawTextUndoList XawTextUndoList; +struct _XawTextUndoList { + XawTextUndoBuffer *left, *right; + XawTextUndoList *undo, *redo; +}; + +struct _XawTextUndo { + XawTextUndoBuffer **undo; + unsigned num_undo; + XawTextUndoList *list, *pointer, *end_mark, *head; + unsigned num_list; + XawTextScanDirection dir; + XawTextUndoBuffer *l_save, *r_save; + XawTextUndoList *u_save; + XawTextUndoBuffer *l_no_change, *r_no_change; + int merge; + int erase; /* there are two types of erases */ +}; +#endif /* OLDXAW */ + +/* + * Class Methods + */ +static Boolean ConvertSelection(Widget, Atom*, Atom*, Atom*, XtPointer*, + unsigned long*, int*); +static XawTextPosition Read(Widget, XawTextPosition, XawTextBlock*, int); +static int Replace(Widget, XawTextPosition, XawTextPosition, XawTextBlock*); +static XawTextPosition Scan(Widget, XawTextPosition, XawTextScanType, + XawTextScanDirection, int, Bool); +static XawTextPosition Search(Widget, XawTextPosition, XawTextScanDirection, + XawTextBlock*); +static void SetSelection(Widget, XawTextPosition, XawTextPosition, Atom); +static void XawTextSrcClassInitialize(void); +static void XawTextSrcClassPartInitialize(WidgetClass); +static void XawTextSrcInitialize(Widget, Widget, ArgList, Cardinal*); +static void XawTextSrcDestroy(Widget); +static Boolean XawTextSrcSetValues(Widget, Widget, Widget, ArgList, Cardinal*); +/* + * Prototypes + */ +static void CvtStringToEditMode(XrmValuePtr, Cardinal*, + XrmValuePtr, XrmValuePtr); +static Boolean CvtEditModeToString(Display*, XrmValuePtr, Cardinal*, + XrmValuePtr, XrmValuePtr, XtPointer*); +#ifndef OLDXAW +static void FreeUndoBuffer(XawTextUndo*); +static void UndoGC(XawTextUndo*); +static void TellSourceChanged(TextSrcObject, XawTextPosition, XawTextPosition, + XawTextBlock*, int); +Bool _XawTextSrcUndo(TextSrcObject, XawTextPosition*); +Bool _XawTextSrcToggleUndo(TextSrcObject); +XawTextAnchor *_XawTextSourceFindAnchor(Widget, XawTextPosition); + +/* + * External + */ +void _XawSourceAddText(Widget, Widget); +void _XawSourceRemoveText(Widget, Widget, Bool); +Bool _XawTextSourceNewLineAtEOF(Widget); +void _XawSourceSetUndoErase(TextSrcObject, int); +void _XawSourceSetUndoMerge(TextSrcObject, Bool); +#endif /* OLDXAW */ + +/* + * Defined in Text.c + */ +char *_XawTextGetText(TextWidget, XawTextPosition, XawTextPosition); +void _XawTextSourceChanged(Widget, XawTextPosition, XawTextPosition, + XawTextBlock*, int); + +/* + * Initialization + */ #define offset(field) XtOffsetOf(TextSrcRec, textSrc.field) static XtResource resources[] = { - {XtNeditType, XtCEditType, XtREditMode, sizeof(XawTextEditType), - offset(edit_mode), XtRString, "read"}, + { + XtNeditType, + XtCEditType, + XtREditMode, + sizeof(XawTextEditType), + offset(edit_mode), + XtRString, + "read" + }, +#ifndef OLDXAW + { + XtNcallback, + XtCCallback, + XtRCallback, + sizeof(XtPointer), + offset(callback), + XtRCallback, + NULL + }, + { + XtNsourceChanged, + XtCChanged, + XtRBoolean, + sizeof(Boolean), + offset(changed), + XtRImmediate, + (XtPointer)False + }, + { + XtNenableUndo, + XtCUndo, + XtRBoolean, + sizeof(Boolean), + offset(enable_undo), + XtRImmediate, + (XtPointer)False + }, + { + XtNpropertyCallback, + XtCCallback, + XtRCallback, + sizeof(XtPointer), + offset(property_callback), + XtRCallback, + NULL + }, +#endif /* OLDXAW */ }; +#undef offset -static void ClassInitialize(), ClassPartInitialize(), SetSelection(); -static void CvtStringToEditMode(); -static Boolean ConvertSelection(); -static XawTextPosition Search(), Scan(), Read(); -static int Replace(); - -#define SuperClass (&objectClassRec) +#define Superclass (&objectClassRec) TextSrcClassRec textSrcClassRec = { + /* object */ { -/* core_class fields */ - /* superclass */ (WidgetClass) SuperClass, - /* class_name */ "TextSrc", - /* widget_size */ sizeof(TextSrcRec), - /* class_initialize */ ClassInitialize, - /* class_part_initialize */ ClassPartInitialize, - /* class_inited */ FALSE, - /* initialize */ NULL, - /* initialize_hook */ NULL, - /* realize */ NULL, - /* actions */ NULL, - /* num_actions */ 0, - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ FALSE, - /* compress_exposure */ FALSE, - /* compress_enterleave */ FALSE, - /* visible_interest */ FALSE, - /* destroy */ NULL, - /* resize */ NULL, - /* expose */ NULL, - /* set_values */ NULL, - /* set_values_hook */ NULL, - /* set_values_almost */ NULL, - /* get_values_hook */ NULL, - /* accept_focus */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ NULL, - /* query_geometry */ NULL, - /* display_accelerator */ NULL, - /* extension */ NULL, + (WidgetClass)Superclass, /* superclass */ + "TextSrc", /* class_name */ + sizeof(TextSrcRec), /* widget_size */ + XawTextSrcClassInitialize, /* class_initialize */ + XawTextSrcClassPartInitialize, /* class_part_initialize */ + False, /* class_inited */ + XawTextSrcInitialize, /* initialize */ + NULL, /* initialize_hook */ + NULL, /* realize */ + NULL, /* actions */ + 0, /* num_actions */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + False, /* compress_motion */ + False, /* compress_exposure */ + False, /* compress_enterleave */ + False, /* visible_interest */ + XawTextSrcDestroy, /* destroy */ + NULL, /* resize */ + NULL, /* expose */ + XawTextSrcSetValues, /* set_values */ + NULL, /* set_values_hook */ + NULL, /* set_values_almost */ + NULL, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + NULL, /* tm_table */ + NULL, /* query_geometry */ + NULL, /* display_accelerator */ + NULL, /* extension */ }, -/* textSrc_class fields */ + /* text_src */ { - /* Read */ Read, - /* Replace */ Replace, - /* Scan */ Scan, - /* Search */ Search, - /* SetSelection */ SetSelection, - /* ConvertSelection */ ConvertSelection - } + Read, /* Read */ + Replace, /* Replace */ + Scan, /* Scan */ + Search, /* Search */ + SetSelection, /* SetSelection */ + ConvertSelection, /* ConvertSelection */ + }, }; WidgetClass textSrcObjectClass = (WidgetClass)&textSrcClassRec; +static XrmQuark QRead, QAppend, QEdit; +#ifndef OLDXAW +static char *SrcNL = "\n"; +static wchar_t SrcWNL[2]; +#endif + +/* + * Implementation + */ static void -ClassInitialize () +XawTextSrcClassInitialize(void) { - XawInitializeWidgetSet (); + XawInitializeWidgetSet(); + +#ifndef OLDXAW + SrcWNL[0] = _Xaw_atowc(XawLF); + SrcWNL[1] = 0; +#endif + QRead = XrmPermStringToQuark(XtEtextRead); + QAppend = XrmPermStringToQuark(XtEtextAppend); + QEdit = XrmPermStringToQuark(XtEtextEdit); XtAddConverter(XtRString, XtREditMode, CvtStringToEditMode, NULL, 0); + XtSetTypeConverter(XtREditMode, XtRString, CvtEditModeToString, NULL, 0, + XtCacheNone, NULL); } - static void -ClassPartInitialize(wc) -WidgetClass wc; +XawTextSrcClassPartInitialize(WidgetClass wc) { - TextSrcObjectClass t_src, superC; + TextSrcObjectClass t_src, superC; - t_src = (TextSrcObjectClass) wc; - superC = (TextSrcObjectClass) t_src->object_class.superclass; + t_src = (TextSrcObjectClass)wc; + superC = (TextSrcObjectClass)t_src->object_class.superclass; -/* - * We don't need to check for null super since we'll get to TextSrc - * eventually. - */ + /* + * We don't need to check for null super since we'll get to TextSrc + * eventually + */ if (t_src->textSrc_class.Read == XtInheritRead) - t_src->textSrc_class.Read = superC->textSrc_class.Read; + t_src->textSrc_class.Read = superC->textSrc_class.Read; if (t_src->textSrc_class.Replace == XtInheritReplace) - t_src->textSrc_class.Replace = superC->textSrc_class.Replace; + t_src->textSrc_class.Replace = superC->textSrc_class.Replace; if (t_src->textSrc_class.Scan == XtInheritScan) - t_src->textSrc_class.Scan = superC->textSrc_class.Scan; + t_src->textSrc_class.Scan = superC->textSrc_class.Scan; if (t_src->textSrc_class.Search == XtInheritSearch) - t_src->textSrc_class.Search = superC->textSrc_class.Search; + t_src->textSrc_class.Search = superC->textSrc_class.Search; if (t_src->textSrc_class.SetSelection == XtInheritSetSelection) - t_src->textSrc_class.SetSelection = superC->textSrc_class.SetSelection; + t_src->textSrc_class.SetSelection = superC->textSrc_class.SetSelection; if (t_src->textSrc_class.ConvertSelection == XtInheritConvertSelection) - t_src->textSrc_class.ConvertSelection = - superC->textSrc_class.ConvertSelection; + t_src->textSrc_class.ConvertSelection = + superC->textSrc_class.ConvertSelection; +} + +/*ARGSUSED*/ +static void +XawTextSrcInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) +{ +#ifndef OLDXAW + TextSrcObject src = (TextSrcObject)cnew; + + if (src->textSrc.enable_undo) { + src->textSrc.undo = (XawTextUndo*)XtCalloc(1, sizeof(XawTextUndo)); + src->textSrc.undo->dir = XawsdLeft; + } + else + src->textSrc.undo = NULL; + src->textSrc.undo_state = False; + if (XtIsSubclass(XtParent(cnew), textWidgetClass)) { + src->textSrc.text = (WidgetList)XtMalloc(sizeof(Widget*)); + src->textSrc.text[0] = XtParent(cnew); + src->textSrc.num_text = 1; + } + else { + src->textSrc.text = NULL; + src->textSrc.num_text = 0; + } + + src->textSrc.anchors = NULL; + src->textSrc.num_anchors = 0; + (void)XawTextSourceAddAnchor(cnew, 0); +#endif /* OLDXAW */ } -/************************************************************ +static void +XawTextSrcDestroy(Widget w) +{ +#ifndef OLDXAW + TextSrcObject src = (TextSrcObject)w; + + if (src->textSrc.enable_undo) { + FreeUndoBuffer(src->textSrc.undo); + XtFree((char*)src->textSrc.undo); + } + XtFree((char*)src->textSrc.text); + + if (src->textSrc.num_anchors) { + XawTextEntity *entity, *enext; + int i; + + for (i = 0; i < src->textSrc.num_anchors; i++) { + entity = src->textSrc.anchors[i]->entities; + while (entity) { + enext = entity->next; + XtFree((XtPointer)entity); + entity = enext; + } + XtFree((XtPointer)src->textSrc.anchors[i]); + } + XtFree((XtPointer)src->textSrc.anchors); + } +#endif /* OLDXAW */ +} + +/*ARGSUSED*/ +static Boolean +XawTextSrcSetValues(Widget current, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) +{ +#ifndef OLDXAW + TextSrcObject oldtw = (TextSrcObject)current; + TextSrcObject newtw = (TextSrcObject)cnew; + + if (oldtw->textSrc.enable_undo != newtw->textSrc.enable_undo) { + if (newtw->textSrc.enable_undo) { + newtw->textSrc.undo = (XawTextUndo*) + XtCalloc(1, sizeof(XawTextUndo)); + newtw->textSrc.undo->dir = XawsdLeft; + } + else { + FreeUndoBuffer(newtw->textSrc.undo); + XtFree((char*)newtw->textSrc.undo); + newtw->textSrc.undo = NULL; + } + } + if (oldtw->textSrc.changed != newtw->textSrc.changed) { + if (newtw->textSrc.enable_undo) { + if (newtw->textSrc.undo->list) { + newtw->textSrc.undo->l_no_change = + newtw->textSrc.undo->list->left; + newtw->textSrc.undo->r_no_change = + newtw->textSrc.undo->list->right; + } + else + newtw->textSrc.undo->l_no_change = + newtw->textSrc.undo->r_no_change = NULL; + } + } +#endif /* OLDXAW */ + return (False); +} + +/* + * Function: + * Read + * + * Parameters: + * w - TextSrc Object + * pos - position of the text to retreive + * text - text block that will contain returned text + * length - maximum number of characters to read * - * Class specific methods. + * Description: + * This function reads the source. * - ************************************************************/ - -/* Function Name: Read - * Description: This function reads the source. - * Arguments: w - the TextSrc Object. - * pos - position of the text to retreive. - * RETURNED text - text block that will contain returned text. - * length - maximum number of characters to read. - * Returns: The number of characters read into the buffer. + * Returns: + * The character position following the retrieved text. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static XawTextPosition -Read(w, pos, text, length) -Widget w; -XawTextPosition pos; -XawTextBlock *text; -int length; +Read(Widget w, XawTextPosition pos, XawTextBlock *text, int length) { - XtAppError(XtWidgetToApplicationContext(w), - "TextSrc Object: No read function is defined."); - - return( (XawTextPosition) 0 ); /* for gcc -Wall and lint */ + return ((XawTextPosition)0); } -/* Function Name: Replace. - * Description: Replaces a block of text with new text. - * Arguments: src - the Text Source Object. - * startPos, endPos - ends of text that will be removed. - * text - new text to be inserted into buffer at startPos. - * Returns: XawEditError. +/* + * Function: + * Replace + * + * Parameters: + * src - Text Source Object + * startPos - ends of text that will be removed + * endPos - "" + * text - new text to be inserted into buffer at startPos + * + * Description: + * Replaces a block of text with new text. */ - /*ARGSUSED*/ static int -Replace (w, startPos, endPos, text) -Widget w; -XawTextPosition startPos, endPos; -XawTextBlock *text; -{ - return(XawEditError); -} - -/* Function Name: Scan - * Description: Scans the text source for the number and type - * of item specified. - * Arguments: w - the TextSrc Object. - * position - the position to start scanning. - * type - type of thing to scan for. - * dir - direction to scan. - * count - which occurance if this thing to search for. - * include - whether or not to include the character found in - * the position that is returned. - * Returns: EXITS WITH AN ERROR MESSAGE. - * - */ +Replace(Widget w, XawTextPosition startPos, XawTextPosition endPos, + XawTextBlock *text) +{ + return (XawEditError); +} -/* ARGSUSED */ -static -XawTextPosition -Scan (w, position, type, dir, count, include) -Widget w; -XawTextPosition position; -XawTextScanType type; -XawTextScanDirection dir; -int count; -Boolean include; -{ - XtAppError(XtWidgetToApplicationContext(w), - "TextSrc Object: No SCAN function is defined."); - - return( (XawTextPosition) 0 ); /* for gcc -Wall and lint */ -} - -/* Function Name: Search - * Description: Searchs the text source for the text block passed - * Arguments: w - the TextSource Object. - * position - the position to start scanning. - * dir - direction to scan. - * text - the text block to search for. - * Returns: XawTextSearchError. +/* + * Function: + * Scan + * + * Parameters: + * w - TextSrc Object + * position - position to start scanning + * type - type of thing to scan for + * dir - direction to scan + * count - which occurance if this thing to search for + * include - whether or not to include the character found in + * the position that is returned + * + * Description: + * Scans the text source for the number and type of item specified. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static XawTextPosition -Search(w, position, dir, text) -Widget w; -XawTextPosition position; -XawTextScanDirection dir; -XawTextBlock * text; -{ - return(XawTextSearchError); -} - -/* Function Name: ConvertSelection - * Description: Dummy selection converter. - * Arguments: w - the TextSrc object. - * selection - the current selection atom. - * target - the current target atom. - * type - the type to conver the selection to. - * RETURNED value, length - the return value that has been converted. - * RETURNED format - the format of the returned value. - * Returns: TRUE if the selection has been converted. +Scan(Widget w, XawTextPosition position, XawTextScanType type, + XawTextScanDirection dir, int count, Bool include) +{ + return ((XawTextPosition)0); +} + +/* + * Function: + * Search * + * Parameters: + * w - TextSource Object + * position - position to start searching + * dir - direction to search + * text - the text block to search for + * + * Description: + * Searchs the text source for the text block passed */ +/*ARGSUSED*/ +static XawTextPosition +Search(Widget w, XawTextPosition position, XawTextScanDirection dir, + XawTextBlock *text) +{ + return (XawTextSearchError); +} -/* ARGSUSED */ +/*ARGSUSED*/ static Boolean -ConvertSelection(w, selection, target, type, value, length, format) -Widget w; -Atom * selection, * target, * type; -XtPointer * value; -unsigned long * length; -int * format; -{ - return(FALSE); -} - -/* Function Name: SetSelection - * Description: allows special setting of the selection. - * Arguments: w - the TextSrc object. - * left, right - bounds of the selection. - * selection - the selection atom. - * Returns: none - */ +ConvertSelection(Widget w, Atom *selection, Atom *target, Atom *type, + XtPointer *value, unsigned long *length, int *format) +{ + return (False); +} -/* ARGSUSED */ +/*ARGSUSED*/ static void -SetSelection(w, left, right, selection) -Widget w; -XawTextPosition left, right; -Atom selection; +SetSelection(Widget w, XawTextPosition left, XawTextPosition right, + Atom selection) { - /* This space intentionally left blank. */ } - -/* ARGSUSED */ +/*ARGSUSED*/ static void -CvtStringToEditMode(args, num_args, fromVal, toVal) -XrmValuePtr args; /* unused */ -Cardinal *num_args; /* unused */ -XrmValuePtr fromVal; -XrmValuePtr toVal; -{ - static XawTextEditType editType; - static XrmQuark QRead, QAppend, QEdit; - XrmQuark q; - char lowerName[40]; - static Boolean inited = FALSE; - - if ( !inited ) { - QRead = XrmPermStringToQuark(XtEtextRead); - QAppend = XrmPermStringToQuark(XtEtextAppend); - QEdit = XrmPermStringToQuark(XtEtextEdit); - inited = TRUE; - } +CvtStringToEditMode(XrmValuePtr args, Cardinal *num_args, + XrmValuePtr fromVal, XrmValuePtr toVal) +{ + static XawTextEditType editType; + XrmQuark q; + char name[7]; + + XmuNCopyISOLatin1Lowered(name, (char *)fromVal->addr, sizeof(name)); + q = XrmStringToQuark(name); + + if (q == QRead) + editType = XawtextRead; + else if (q == QAppend) + editType = XawtextAppend; + else if (q == QEdit) + editType = XawtextEdit; + else { + toVal->size = 0; + toVal->addr = NULL; + XtStringConversionWarning((char *)fromVal->addr, XtREditMode); + } + toVal->size = sizeof(XawTextEditType); + toVal->addr = (XPointer)&editType; +} - if (strlen ((char*) fromVal->addr) < sizeof lowerName) { - XmuCopyISOLatin1Lowered (lowerName, (char *)fromVal->addr); - q = XrmStringToQuark(lowerName); +/*ARGSUSED*/ +static Boolean +CvtEditModeToString(Display *dpy, XrmValuePtr args, Cardinal *num_args, + XrmValuePtr fromVal, XrmValuePtr toVal, + XtPointer *data) +{ + static String buffer; + Cardinal size; + + switch (*(XawTextEditType *)fromVal->addr) { + case XawtextAppend: + case XawtextRead: + buffer = XtEtextRead; + break; + buffer = XtEtextAppend; + break; + case XawtextEdit: + buffer = XtEtextEdit; + break; + default: + XawTypeToStringWarning(dpy, XtREditMode); + toVal->addr = NULL; + toVal->size = 0; + return (False); + } - if (q == QRead) editType = XawtextRead; - else if (q == QAppend) editType = XawtextAppend; - else if (q == QEdit) editType = XawtextEdit; - else { - toVal->size = 0; - toVal->addr = NULL; - return; + size = strlen(buffer) + 1; + if (toVal->addr != NULL) { + if (toVal->size < size) { + toVal->size = size; + return (False); + } + strcpy((char *)toVal->addr, buffer); } - toVal->size = sizeof editType; - toVal->addr = (XPointer) &editType; - return; - } - toVal->size = 0; - toVal->addr = NULL; + else + toVal->addr = (XPointer)buffer; + toVal->size = sizeof(String); + + return (True); } +#ifndef OLDXAW +Bool +_XawTextSourceNewLineAtEOF(Widget w) +{ + TextSrcObject src = (TextSrcObject)w; + XawTextBlock text; + + text.firstPos = 0; + if ((text.format = src->textSrc.text_format) == XawFmt8Bit) + text.ptr = SrcNL; + else + text.ptr = (char*)SrcWNL; + text.length = 1; + + return (XawTextSourceSearch(w, XawTextSourceScan(w, 0, XawstAll, + XawsdRight, 1, True) - 1, + XawsdRight, &text) != XawTextSearchError); +} +void +_XawSourceAddText(Widget source, Widget text) +{ + TextSrcObject src = (TextSrcObject)source; + Bool found = False; + Cardinal i; + + for (i = 0; i < src->textSrc.num_text; i++) + if (src->textSrc.text[i] == text) { + found = True; + break; + } + + if (!found) { + src->textSrc.text = (WidgetList) + XtRealloc((char*)src->textSrc.text, + sizeof(Widget) * (src->textSrc.num_text + 1)); + src->textSrc.text[src->textSrc.num_text++] = text; + } +} -/************************************************************ +void +_XawSourceRemoveText(Widget source, Widget text, Bool destroy) +{ + TextSrcObject src = (TextSrcObject)source; + Bool found = False; + Cardinal i; + + if (src == NULL) + return; + + for (i = 0; i < src->textSrc.num_text; i++) + if (src->textSrc.text[i] == text) { + found = True; + break; + } + + if (found) { + if (--src->textSrc.num_text == 0) { + if (destroy) { + XtDestroyWidget(source); + return; + } + else { + XtFree((char*)src->textSrc.text); + src->textSrc.text = NULL; /* for realloc "magic" */ + } + } + else if (i < src->textSrc.num_text) + memmove(&src->textSrc.text[i], &src->textSrc.text[i + 1], + sizeof(Widget) * (src->textSrc.num_text - i)); + } +} +#endif /* OLDXAW */ + +/* + * Function: + * XawTextSourceRead + * + * Parameters: + * w - TextSrc Object + * pos - position of the text to retrieve + * text - text block that will contain returned text (return) + * length - maximum number of characters to read * - * Public Functions. + * Description: + * This function reads the source. * - ************************************************************/ - -/* Function Name: XawTextSourceRead - * Description: This function reads the source. - * Arguments: w - the TextSrc Object. - * pos - position of the text to retreive. - * RETURNED text - text block that will contain returned text. - * length - maximum number of characters to read. - * Returns: The number of characters read into the buffer. + * Returns: + * The number of characters read into the buffer */ - XawTextPosition -#if NeedFunctionPrototypes XawTextSourceRead(Widget w, XawTextPosition pos, XawTextBlock *text, int length) -#else -XawTextSourceRead(w, pos, text, length) -Widget w; -XawTextPosition pos; -XawTextBlock *text; -int length; -#endif { - TextSrcObjectClass class = (TextSrcObjectClass) w->core.widget_class; + TextSrcObjectClass cclass = (TextSrcObjectClass)w->core.widget_class; + + return ((*cclass->textSrc_class.Read)(w, pos, text, length)); +} - if ( !XtIsSubclass( w, textSrcObjectClass ) ) - XtErrorMsg("bad argument", "textSource", "XawError", - "XawTextSourceRead's 1st parameter must be subclass of asciiSrc.", - NULL, NULL); +#ifndef OLDXAW +static void +TellSourceChanged(TextSrcObject src, XawTextPosition left, + XawTextPosition right, XawTextBlock *block, int lines) +{ + Cardinal i; - return((*class->textSrc_class.Read)(w, pos, text, length)); + for (i = 0; i < src->textSrc.num_text; i++) + _XawTextSourceChanged(src->textSrc.text[i], left, right, block, lines); +} + +/* + * This function is required because there is no way to diferentiate + * if the first erase was generated by a backward-kill-char and the + * second by a forward-kill-char (or vice-versa) from XawTextSourceReplace. + * It is only possible to diferentiate after the second character is + * killed, but then, it is too late. + */ +void +_XawSourceSetUndoErase(TextSrcObject src, int value) +{ + if (src && src->textSrc.enable_undo) + src->textSrc.undo->erase = value; } -/* Function Name: XawTextSourceReplace. - * Description: Replaces a block of text with new text. - * Arguments: src - the Text Source Object. - * startPos, endPos - ends of text that will be removed. - * text - new text to be inserted into buffer at startPos. - * Returns: XawEditError or XawEditDone. +/* + * To diferentiate insert-char's separeted by cursor movements. */ +void +_XawSourceSetUndoMerge(TextSrcObject src, Bool state) +{ + if (src && src->textSrc.enable_undo) + src->textSrc.undo->merge += state ? 1 : -1; +} +#endif /* OLDXAW */ +/* + * Public Functions + */ +/* + * Function: + * XawTextSourceReplace + * + * Parameters: + * src - Text Source Object + * startPos - ends of text that will be removed + * endPos - "" + * text - new text to be inserted into buffer at startPos + * + * Description: + * Replaces a block of text with new text. + * + * Returns: + * XawEditError or XawEditDone. + */ /*ARGSUSED*/ int -#if NeedFunctionPrototypes -XawTextSourceReplace (Widget w, XawTextPosition startPos, - XawTextPosition endPos, XawTextBlock *text) +XawTextSourceReplace(Widget w, XawTextPosition left, + XawTextPosition right, XawTextBlock *block) +{ + TextSrcObjectClass cclass = (TextSrcObjectClass)w->core.widget_class; +#ifndef OLDXAW + TextSrcObject src = (TextSrcObject)w; + XawTextUndoBuffer *l_state, *r_state; + XawTextUndoList *undo; + Bool enable_undo; + XawTextPosition start, end; + int i, error, lines = 0; + + if (src->textSrc.edit_mode == XawtextRead) + return (XawEditError); + + enable_undo = src->textSrc.enable_undo && src->textSrc.undo_state == False; + if (enable_undo) { + unsigned size, total; + + if (src->textSrc.undo->l_save) { + l_state = src->textSrc.undo->l_save; + src->textSrc.undo->l_save = NULL; + } + else + l_state = XtNew(XawTextUndoBuffer); + l_state->refcount = 1; + l_state->position = left; + if (left < right) { + Widget ctx = NULL; + + for (i = 0; i < src->textSrc.num_text; i++) + if (XtIsSubclass(src->textSrc.text[i], textWidgetClass)) { + ctx = src->textSrc.text[i]; + break; + } + l_state->buffer = _XawTextGetText((TextWidget)ctx, left, right); + l_state->length = right - left; + } + else { + l_state->length = 0; + l_state->buffer = NULL; + } + l_state->format = src->textSrc.text_format; + if (l_state->length == 1) { + if (l_state->format == XawFmtWide && + *(wchar_t*)l_state->buffer == *SrcWNL) { + XtFree(l_state->buffer); + l_state->buffer = (char*)SrcWNL; + } + else if (*l_state->buffer == '\n') { + XtFree(l_state->buffer); + l_state->buffer = SrcNL; + } + } + + if (src->textSrc.undo->r_save) { + r_state = src->textSrc.undo->r_save; + src->textSrc.undo->r_save = NULL; + } + else + r_state = XtNew(XawTextUndoBuffer); + r_state->refcount = 1; + r_state->position = left; + r_state->format = block->format; + size = block->format == XawFmtWide ? sizeof(wchar_t) : sizeof(char); + total = size * block->length; + r_state->length = block->length; + r_state->buffer = NULL; + if (total == size) { + if (r_state->format == XawFmtWide && + *(wchar_t*)block->ptr == *SrcWNL) + r_state->buffer = (char*)SrcWNL; + else if (*block->ptr == '\n') + r_state->buffer = SrcNL; + } + if (total && !r_state->buffer) { + r_state->buffer = XtMalloc(total); + memcpy(r_state->buffer, block->ptr, total); + } + + if (src->textSrc.undo->u_save) { + undo = src->textSrc.undo->u_save; + src->textSrc.undo->u_save = NULL; + } + else + undo = XtNew(XawTextUndoList); + undo->left = l_state; + undo->right = r_state; + undo->undo = src->textSrc.undo->list; + undo->redo = NULL; + } + else { + undo = NULL; + l_state = r_state = NULL; + } + +#define LARGE_VALUE 262144 /* 256 K */ + /* optimization, to avoid long delays recalculating the line number + * when editing huge files + */ + if (left > LARGE_VALUE) { + start = XawTextSourceScan(w, left, XawstEOL, XawsdLeft, 2, False); + for (i = 0; i < src->textSrc.num_text; i++) { + TextWidget tw = (TextWidget)src->textSrc.text[i]; + + if (left <= tw->text.lt.top && + left + block->length - (right - left) > tw->text.lt.top) + _XawTextBuildLineTable(tw, start, False); + } + } +#undef LARGE_VALUE + + start = left; + end = right; + while (start < end) { + start = XawTextSourceScan(w, start, XawstEOL, XawsdRight, 1, True); + if (start <= end) { + --lines; + if (start == XawTextSourceScan(w, 0, XawstAll, XawsdRight, 1, True)) { + lines += !_XawTextSourceNewLineAtEOF(w); + break; + } + } + } #else -XawTextSourceReplace (w, startPos, endPos, text) -Widget w; -XawTextPosition startPos, endPos; -XawTextBlock *text; -#endif + int error; +#endif /* OLDXAW */ + + error = (*cclass->textSrc_class.Replace)(w, left, right, block); + +#ifndef OLDXAW + if (error != XawEditDone) { + if (enable_undo) { + if (l_state->buffer) { + if (l_state->buffer != SrcNL && l_state->buffer != (char*)SrcWNL) + XtFree(l_state->buffer); + l_state->buffer = NULL; + } + src->textSrc.undo->l_save = l_state; + if (r_state->buffer) { + if (r_state->buffer != SrcNL && r_state->buffer != (char*)SrcWNL) + XtFree(r_state->buffer); + r_state->buffer = NULL; + } + src->textSrc.undo->r_save = r_state; + + src->textSrc.undo->u_save = undo; + } + } + else if (enable_undo) { + XawTextUndoList *list = src->textSrc.undo->list; + XawTextUndoBuffer *unl, *lnl; + int erase = undo->right->length == 0 && undo->left->length == 1 && list + && list->right->length == 0; + + if (erase) { + erase = list->left->position - 1 == undo->left->position ? -1 : + list->left->position == undo->left->position ? 1 : 0; + if (src->textSrc.undo->erase && erase != src->textSrc.undo->erase) + erase = 0; + else + src->textSrc.undo->erase = erase; + } + + if (erase) { + unl = l_state; + lnl = list->left; + } + else { + unl = r_state; + lnl = list ? list->right : NULL; + } + + /* Try to merge the undo buffers */ + if (src->textSrc.undo->merge > 0 && ((erase || + (list && ((list->left->length == 0 && undo->left->length == 0) || + (list->left->length == list->right->length && + undo->left->length == 1)) && + undo->right->length == 1 && + list->right->position + list->right->length + == undo->right->position)) + && src->textSrc.undo->pointer == list + && unl->format == list->right->format + && ((unl->format == XawFmt8Bit && unl->buffer[0] != XawLF) || + (unl->format == XawFmtWide && + *(wchar_t*)(unl->buffer) != _Xaw_atowc(XawLF))) + && ((lnl->format == XawFmt8Bit && lnl->buffer[0] != XawLF) || + (lnl->format == XawFmtWide && + *(wchar_t*)(lnl->buffer) != _Xaw_atowc(XawLF))))) { + unsigned size = lnl->format == XawFmtWide ? + sizeof(wchar_t) : sizeof(char); + + if (!erase) { + list->right->buffer = XtRealloc(list->right->buffer, + (list->right->length + 1) * size); + memcpy(list->right->buffer + list->right->length * size, + undo->right->buffer, size); + ++list->right->length; + XtFree(r_state->buffer); + } + else if (erase < 0) { + --list->left->position; + --list->right->position; + } + + src->textSrc.undo->l_save = l_state; + src->textSrc.undo->r_save = r_state; + src->textSrc.undo->u_save = undo; + + if (list->left->length) { + list->left->buffer = XtRealloc(list->left->buffer, + (list->left->length + 1) * size); + if (erase >= 0) + memcpy(list->left->buffer + list->left->length * size, + undo->left->buffer, size); + else { + /* use memmove, since strings overlap */ + memmove(list->left->buffer + size, list->left->buffer, + list->left->length * size); + memcpy(list->left->buffer, undo->left->buffer, size); + } + ++list->left->length; + if (l_state->buffer != SrcNL && l_state->buffer != (char*)SrcWNL) + XtFree(l_state->buffer); + } + + if (src->textSrc.undo->num_list >= UNDO_DEPTH) + UndoGC(src->textSrc.undo); + } + else { + src->textSrc.undo->undo = (XawTextUndoBuffer**) + XtRealloc((char*)src->textSrc.undo->undo, + (2 + src->textSrc.undo->num_undo) + * sizeof(XawTextUndoBuffer)); + src->textSrc.undo->undo[src->textSrc.undo->num_undo++] = l_state; + src->textSrc.undo->undo[src->textSrc.undo->num_undo++] = r_state; + + if (src->textSrc.undo->list) + src->textSrc.undo->list->redo = undo; + else + src->textSrc.undo->head = undo; + + src->textSrc.undo->merge = l_state->length <= 1 && + r_state->length <= 1; + + src->textSrc.undo->list = src->textSrc.undo->pointer = + src->textSrc.undo->end_mark = undo; + + if (++src->textSrc.undo->num_list >= UNDO_DEPTH) + UndoGC(src->textSrc.undo); + } + src->textSrc.undo->dir = XawsdLeft; + if (!src->textSrc.changed) { + src->textSrc.undo->l_no_change = src->textSrc.undo->list->right; + src->textSrc.undo->r_no_change = src->textSrc.undo->list->left; + src->textSrc.changed = True; + } + } + else if (!src->textSrc.enable_undo) + src->textSrc.changed = True; + + if (error == XawEditDone) { + XawTextPropertyInfo info; + XawTextAnchor *anchor; + + /* find anchor and index */ + /* XXX index (i) could be returned by XawTextSourceFindAnchor + * or similar function, to speed up */ + if ((anchor = XawTextSourceFindAnchor(w, left))) { + XawTextEntity *eprev, *entity, *enext; + XawTextPosition offset = 0, diff = block->length - (right - left); + + for (i = 0; i < src->textSrc.num_anchors; i++) + if (src->textSrc.anchors[i] == anchor) + break; + if (anchor->cache && anchor->position + anchor->cache->offset + + anchor->cache->length <= left) + eprev = entity = anchor->cache; + else + eprev = entity = anchor->entities; + while (entity) { + offset = anchor->position + entity->offset; + + if (offset > left) + break; + if (offset + entity->length > left) + break; + + eprev = entity; + entity = entity->next; + } + + /* try to do the right thing here (and most likely correct), but + * other code needs to check what was done */ + + /* adjust entity length */ + if (entity && offset <= left) { + if (offset + entity->length < right) + entity->length = left - offset + block->length; + else + entity->length += diff; + + if (entity->length == 0) { + enext = entity->next; + eprev->next = enext; + anchor->cache = NULL; + XtFree((XtPointer)entity); + if (entity == anchor->entities) { + if ((anchor->entities = enext) == NULL) { + eprev = NULL; + anchor = XawTextSourceRemoveAnchor(w, anchor); + entity = anchor ? anchor->entities : NULL; + } + else + eprev = entity = enext; + } + else + entity = enext; + } + else { + eprev = entity; + entity = entity->next; + } + } + + while (anchor) { + while (entity) { + offset = anchor->position + entity->offset + entity->length; + + if (offset > right) { + entity->length = XawMin(entity->length, offset - right); + goto exit_anchor_loop; + } + + enext = entity->next; + if (eprev) + eprev->next = enext; + XtFree((XtPointer)entity); + anchor->cache = NULL; + if (entity == anchor->entities) { + eprev = NULL; + if ((anchor->entities = enext) == NULL) { + if (i == 0) + ++i; + else if (i < --src->textSrc.num_anchors) { + memmove(&src->textSrc.anchors[i], + &src->textSrc.anchors[i + 1], + (src->textSrc.num_anchors - i) * + sizeof(XawTextAnchor*)); + XtFree((XtPointer)anchor); + } + if (i >= src->textSrc.num_anchors) { + anchor = NULL; + entity = NULL; + break; + } + anchor = src->textSrc.anchors[i]; + entity = anchor->entities; + continue; + } + } + entity = enext; + } + if (i + 1 < src->textSrc.num_anchors) { + anchor = src->textSrc.anchors[++i]; + entity = anchor->entities; + eprev = NULL; + } + else + break; + eprev = NULL; + } + +exit_anchor_loop: + if (anchor) { + XawTextAnchor *aprev; + + if (anchor->position >= XawMax(right, left + block->length)) + anchor->position += diff; + else if (anchor->position > left && + (aprev = XawTextSourcePrevAnchor(w, anchor))) { + XawTextPosition tmp = anchor->position - aprev->position; + + if (diff) { + while (entity) { + entity->offset += diff; + entity = entity->next; + } + } + entity = anchor->entities; + while (entity) { + entity->offset += tmp; + entity = entity->next; + } + if ((entity = aprev->entities) == NULL) + aprev->entities = anchor->entities; + else { + while (entity->next) + entity = entity->next; + entity->next = anchor->entities; + } + anchor->entities = NULL; + (void)XawTextSourceRemoveAnchor(w, anchor); + --i; + } + else if (diff) { + while (entity) { + entity->offset += diff; + entity = entity->next; + } + } + } + + if (diff) { + for (++i; i < src->textSrc.num_anchors; i++) + src->textSrc.anchors[i]->position += diff; + } + } + + start = left; + end = start + block->length; + while (start < end) { + start = XawTextSourceScan(w, start, XawstEOL, XawsdRight, 1, True); + if (start <= end) { + ++lines; + if (start == XawTextSourceScan(w, 0, XawstAll, XawsdRight, 1, True)) { + lines -= !_XawTextSourceNewLineAtEOF(w); + break; + } + } + } + + info.left = left; + info.right = right; + info.block = block; + XtCallCallbacks(w, XtNpropertyCallback, &info); + + TellSourceChanged(src, left, right, block, lines); + /* Call callbacks, we have changed the buffer */ + XtCallCallbacks(w, XtNcallback, + (XtPointer)((long)src->textSrc.changed)); + } + +#endif /* OLDXAW */ + return (error); +} + +#ifndef OLDXAW +Bool +_XawTextSrcUndo(TextSrcObject src, XawTextPosition *insert_pos) { - TextSrcObjectClass class = (TextSrcObjectClass) w->core.widget_class; + static wchar_t wnull = 0; + XawTextBlock block; + XawTextUndoList *list, *nlist; + XawTextUndoBuffer *l_state, *r_state; + Boolean changed = src->textSrc.changed; - if ( !XtIsSubclass( w, textSrcObjectClass ) ) - XtErrorMsg("bad argument", "textSource", "XawError", - "XawTextSourceReplace's 1st parameter must be subclass of asciiSrc.", - NULL, NULL); + if (!src->textSrc.enable_undo || !src->textSrc.undo->num_undo) + return (False); + + list = src->textSrc.undo->pointer; + + if (src->textSrc.undo->dir == XawsdLeft) { + l_state = list->right; + r_state = list->left; + } + else { + l_state = list->left; + r_state = list->right; + } - return((*class->textSrc_class.Replace)(w, startPos, endPos, text)); + if (src->textSrc.undo->l_no_change == l_state + && src->textSrc.undo->r_no_change == r_state) + src->textSrc.changed = False; + else + src->textSrc.changed = True; + + block.firstPos = 0; + block.length = r_state->length; + block.ptr = r_state->buffer ? r_state->buffer : (char*)&wnull; + block.format = r_state->format; + + src->textSrc.undo_state = True; + if (XawTextSourceReplace((Widget)src, l_state->position, l_state->position + + l_state->length, &block) != XawEditDone) { + src->textSrc.undo_state = False; + src->textSrc.changed = changed; + return (False); + } + src->textSrc.undo_state = False; + + ++l_state->refcount; + ++r_state->refcount; + nlist = XtNew(XawTextUndoList); + nlist->left = l_state; + nlist->right = r_state; + nlist->undo = src->textSrc.undo->list; + nlist->redo = NULL; + + if (list == src->textSrc.undo->list) + src->textSrc.undo->end_mark = nlist; + + if (src->textSrc.undo->dir == XawsdLeft) { + if (list->undo == NULL) + src->textSrc.undo->dir = XawsdRight; + else + list = list->undo; + } + else { + if (list->redo == NULL || list->redo == src->textSrc.undo->end_mark) + src->textSrc.undo->dir = XawsdLeft; + else + list = list->redo; + } + *insert_pos = r_state->position + r_state->length; + src->textSrc.undo->pointer = list; + src->textSrc.undo->list->redo = nlist; + src->textSrc.undo->list = nlist; + src->textSrc.undo->merge = src->textSrc.undo->erase = 0; + + if (++src->textSrc.undo->num_list >= UNDO_DEPTH) + UndoGC(src->textSrc.undo); + + return (True); } -/* Function Name: XawTextSourceScan - * Description: Scans the text source for the number and type - * of item specified. - * Arguments: w - the TextSrc Object. - * position - the position to start scanning. - * type - type of thing to scan for. - * dir - direction to scan. - * count - which occurance if this thing to search for. - * include - whether or not to include the character found in - * the position that is returned. - * Returns: The position of the text. +Bool +_XawTextSrcToggleUndo(TextSrcObject src) +{ + if (!src->textSrc.enable_undo || !src->textSrc.undo->num_undo) + return (False); + + if (src->textSrc.undo->pointer != src->textSrc.undo->list) { + if (src->textSrc.undo->dir == XawsdLeft) { + if (src->textSrc.undo->pointer->redo + && (src->textSrc.undo->pointer->redo + != src->textSrc.undo->end_mark)) { + src->textSrc.undo->pointer = src->textSrc.undo->pointer->redo; + src->textSrc.undo->dir = XawsdRight; + } + } + else { + if (src->textSrc.undo->pointer->undo + && (src->textSrc.undo->pointer != src->textSrc.undo->head)) { + src->textSrc.undo->pointer = src->textSrc.undo->pointer->undo; + src->textSrc.undo->dir = XawsdLeft; + } + } + } + + return (True); +} + +static void +FreeUndoBuffer(XawTextUndo *undo) +{ + unsigned i; + XawTextUndoList *head, *del; + + for (i = 0; i < undo->num_undo; i++) { + if (undo->undo[i]->buffer && undo->undo[i]->buffer != SrcNL && + undo->undo[i]->buffer != (char*)SrcWNL) + XtFree(undo->undo[i]->buffer); + XtFree((char*)undo->undo[i]); + } + XtFree((char*)undo->undo); + head = undo->head; + + del = head; + while (head) { + head = head->redo; + XtFree((char*)del); + del = head; + } + + if (undo->l_save) { + XtFree((char*)undo->l_save); + undo->l_save = NULL; + } + if (undo->r_save) { + XtFree((char*)undo->r_save); + undo->r_save = NULL; + } + if (undo->u_save) { + XtFree((char*)undo->u_save); + undo->u_save = NULL; + } + + undo->list = undo->pointer = undo->head = undo->end_mark = NULL; + undo->l_no_change = undo->r_no_change = NULL; + undo->undo = NULL; + undo->dir = XawsdLeft; + undo->num_undo = undo->num_list = undo->erase = undo->merge = 0; +} + +static void +UndoGC(XawTextUndo *undo) +{ + unsigned i; + XawTextUndoList *head = undo->head, *redo = head->redo; + + if (head == undo->pointer || head == undo->end_mark + || undo->l_no_change == NULL + || head->left == undo->l_no_change || head->right == undo->l_no_change) + return; + + undo->head = redo; + redo->undo = NULL; + + --head->left->refcount; + if (--head->right->refcount == 0) { + for (i = 0; i < undo->num_undo; i+= 2) + if (head->left == undo->undo[i] || head->left == undo->undo[i+1]) { + if (head->left == undo->undo[i+1]) { + XawTextUndoBuffer *tmp = redo->left; + + redo->left = redo->right; + redo->right = tmp; + } + if (head->left->buffer && head->left->buffer != SrcNL && + head->left->buffer != (char*)SrcWNL) + XtFree(head->left->buffer); + XtFree((char*)head->left); + if (head->right->buffer && head->right->buffer != SrcNL && + head->right->buffer != (char*)SrcWNL) + XtFree(head->right->buffer); + XtFree((char*)head->right); + + undo->num_undo -= 2; + memmove(&undo->undo[i], &undo->undo[i + 2], + (undo->num_undo - i) * sizeof(XawTextUndoBuffer*)); + break; + } + } + XtFree((char*)head); + --undo->num_list; +} +#endif /* OLDXAW */ + +/* + * Function: + * XawTextSourceScan + * + * Parameters: + * w - TextSrc Object + * position - position to start scanning + * type - type of thing to scan for + * dir - direction to scan + * count - which occurance if this thing to search for + * include - whether or not to include the character found in + * the position that is returned. * + * Description: + * Scans the text source for the number and type of item specified. + * + * Returns: + * The position of the text */ - XawTextPosition -#if NeedFunctionPrototypes XawTextSourceScan(Widget w, XawTextPosition position, #if NeedWidePrototypes - int type, int dir, + int type, int dir, int count, int include #else XawTextScanType type, XawTextScanDirection dir, + int count, Boolean include #endif - int count, -#if NeedWidePrototypes - int include) -#else - Boolean include) -#endif -#else -XawTextSourceScan(w, position, type, dir, count, include) -Widget w; -XawTextPosition position; -XawTextScanType type; -XawTextScanDirection dir; -int count; -Boolean include; -#endif +) { - TextSrcObjectClass class = (TextSrcObjectClass) w->core.widget_class; - - if ( !XtIsSubclass( w, textSrcObjectClass ) ) - XtErrorMsg("bad argument", "textSource", "XawError", - "XawTextSourceScan's 1st parameter must be subclass of asciiSrc.", - NULL, NULL); + TextSrcObjectClass cclass = (TextSrcObjectClass)w->core.widget_class; - return((*class->textSrc_class.Scan)(w, position, type, dir, count, include)); + return ((*cclass->textSrc_class.Scan) + (w, position, type, dir, count, include)); } -/* Function Name: XawTextSourceSearch - * Description: Searchs the text source for the text block passed - * Arguments: w - the TextSource Object. - * position - the position to start scanning. - * dir - direction to scan. - * text - the text block to search for. - * Returns: The position of the text we are searching for or - * XawTextSearchError. +/* + * Function: + * XawTextSourceSearch + * + * Parameters: + * w - TextSource Object + * position - position to start scanning + * dir - direction to scan + * text - the text block to search for. + * + * Returns: + * The position of the text we are searching for or XawTextSearchError. + * + * Description: + * Searchs the text source for the text block passed */ - XawTextPosition -#if NeedFunctionPrototypes XawTextSourceSearch(Widget w, XawTextPosition position, #if NeedWidePrototypes int dir, @@ -475,204 +1419,560 @@ XawTextSourceSearch(Widget w, XawTextPosition position, XawTextScanDirection dir, #endif XawTextBlock *text) -#else -XawTextSourceSearch(w, position, dir, text) -Widget w; -XawTextPosition position; -XawTextScanDirection dir; -XawTextBlock * text; -#endif { - TextSrcObjectClass class = (TextSrcObjectClass) w->core.widget_class; - - if ( !XtIsSubclass( w, textSrcObjectClass ) ) - XtErrorMsg("bad argument", "textSource", "XawError", - "XawTextSourceSearch's 1st parameter must be subclass of asciiSrc.", - NULL, NULL); + TextSrcObjectClass cclass = (TextSrcObjectClass)w->core.widget_class; - return((*class->textSrc_class.Search)(w, position, dir, text)); + return ((*cclass->textSrc_class.Search)(w, position, dir, text)); } -/* Function Name: XawTextSourceConvertSelection - * Description: Dummy selection converter. - * Arguments: w - the TextSrc object. - * selection - the current selection atom. - * target - the current target atom. - * type - the type to conver the selection to. - * RETURNED value, length - the return value that has been converted. - * RETURNED format - the format of the returned value. - * Returns: TRUE if the selection has been converted. +/* + * Function: + * XawTextSourceConvertSelection * + * Parameters: + * w - TextSrc object + * selection - current selection atom + * target - current target atom + * type - type to conver the selection to + * value - return value that has been converted + * length - "" + * format - format of the returned value + * + * Returns: + * True if the selection has been converted */ - Boolean -#if NeedFunctionPrototypes XawTextSourceConvertSelection(Widget w, Atom *selection, Atom *target, Atom *type, XtPointer *value, unsigned long *length, int *format) -#else -XawTextSourceConvertSelection(w, selection, - target, type, value, length, format) -Widget w; -Atom * selection, * target, * type; -XtPointer * value; -unsigned long * length; -int * format; -#endif { - TextSrcObjectClass class = (TextSrcObjectClass) w->core.widget_class; - - if ( !XtIsSubclass( w, textSrcObjectClass ) ) - XtErrorMsg("bad argument", "textSource", "XawError", - "XawTextSourceConvertSelectionXawTextSourceConvertSelection's 1st parameter must be subclass of asciiSrc.", - NULL, NULL); + TextSrcObjectClass cclass = (TextSrcObjectClass)w->core.widget_class; - return((*class->textSrc_class.ConvertSelection)(w, selection, target, type, - value, length, format)); + return((*cclass->textSrc_class.ConvertSelection) + (w, selection, target, type, value, length, format)); } -/* Function Name: XawTextSourceSetSelection - * Description: allows special setting of the selection. - * Arguments: w - the TextSrc object. - * left, right - bounds of the selection. - * selection - the selection atom. - * Returns: none +/* + * Function: + * XawTextSourceSetSelection + * + * Parameters: + * w - TextSrc object + * left - bounds of the selection + * rigth - "" + * selection - selection atom + * + * Description: + * Allows special setting of the selection. */ - void -#if NeedFunctionPrototypes XawTextSourceSetSelection(Widget w, XawTextPosition left, XawTextPosition right, Atom selection) -#else -XawTextSourceSetSelection(w, left, right, selection) -Widget w; -XawTextPosition left, right; -Atom selection; -#endif { - TextSrcObjectClass class = (TextSrcObjectClass) w->core.widget_class; + TextSrcObjectClass cclass = (TextSrcObjectClass)w->core.widget_class; - if ( !XtIsSubclass( w, textSrcObjectClass ) ) - XtErrorMsg("bad argument", "textSource", "XawError", - "'s 1st parameter must be subclass of asciiSrc.", - NULL, NULL); - - (*class->textSrc_class.SetSelection)(w, left, right, selection); + (*cclass->textSrc_class.SetSelection)(w, left, right, selection); } -/******************************************************************** - * - * External Functions for Multi Text. - * - ********************************************************************/ - +/* + * External Functions for Multi Text + */ /* * TextFormat(): - * returns the format of text: FMT8BIT or FMTWIDE. - * + * returns the format of text: FMT8BIT or FMTWIDE */ XrmQuark -#if NeedFunctionPrototypes _XawTextFormat(TextWidget tw) -#else -_XawTextFormat(tw) - TextWidget tw; -#endif { - return (((TextSrcObject)(tw->text.source))->textSrc.text_format); + return (((TextSrcObject)(tw->text.source))->textSrc.text_format); } - /* _XawTextWCToMB(): - * convert the wchar string to external encoding. - * The caller is responsible for freeing both the source and ret string. + * Convert the wchar string to external encoding + * The caller is responsible for freeing both the source and ret string * - * wstr - source wchar string. + * wstr - source wchar string * len_in_out - lengh of string. - * As In, length of source wchar string, measured in wchar. - * As Out, length of returned string. + * As In, length of source wchar string, measured in wchar + * As Out, length of returned string */ - - char * -_XawTextWCToMB( d, wstr, len_in_out ) - Display* d; - wchar_t* wstr; - int* len_in_out; - +_XawTextWCToMB(Display *d, wchar_t *wstr, int *len_in_out) { XTextProperty textprop; + if (XwcTextListToTextProperty(d, (wchar_t**)&wstr, 1, - XTextStyle, &textprop) < Success) { - XtWarningMsg("convertError", "textSource", "XawError", - "Non-character code(s) in buffer.", NULL, NULL); - *len_in_out = 0; - return( NULL ); + XTextStyle, &textprop) < Success) { + XtWarningMsg("convertError", "textSource", "XawError", + "Non-character code(s) in buffer.", NULL, NULL); + *len_in_out = 0; + return (NULL); } *len_in_out = textprop.nitems; - return((char *)textprop.value); -} + return ((char *)textprop.value); +} /* _XawTextMBToWC(): - * convert the string to internal processing codeset WC. + * Convert the string to internal processing codeset WC. * The caller is responsible for freeing both the source and ret string. * - * str - source string. - * len_in_out - lengh of string. - * As In, it is length of source string. - * As Out, it is length of returned string, measured in wchar. + * str - source string + * len_in_out - lengh of string + * As In, it is length of source string + * As Out, it is length of returned string, measured in wchar */ - -wchar_t* _XawTextMBToWC( d, str, len_in_out ) -Display *d; -char *str; -int *len_in_out; +wchar_t * +_XawTextMBToWC(Display *d, char *str, int *len_in_out) { - if (*len_in_out == 0) { - return(NULL); - } else { XTextProperty textprop; char *buf; wchar_t **wlist, *wstr; int count; + + if (*len_in_out == 0) + return (NULL); + buf = XtMalloc(*len_in_out + 1); - if (!buf) { - XtErrorMsg("convertError", "multiSourceCreate", "XawError", - "No Memory", NULL, NULL); - *len_in_out = 0; - return (NULL); /* The above function doesn't really return. */ - } + strncpy(buf, str, *len_in_out); *(buf + *len_in_out) = '\0'; - if (XmbTextListToTextProperty(d, &buf, 1, XTextStyle, &textprop) - != Success) { + if (XmbTextListToTextProperty(d, &buf, 1, XTextStyle, &textprop) != Success) { XtWarningMsg("convertError", "textSource", "XawError", - "No Memory, or Locale not supported.", NULL, NULL); + "No Memory, or Locale not supported.", NULL, NULL); XtFree(buf); *len_in_out = 0; return (NULL); } + XtFree(buf); if (XwcTextPropertyToTextList(d, &textprop, - (wchar_t***)&wlist, &count) != Success) { + (wchar_t***)&wlist, &count) != Success) { XtWarningMsg("convertError", "multiSourceCreate", "XawError", - "Non-character code(s) in source.", NULL, NULL); + "Non-character code(s) in source.", NULL, NULL); *len_in_out = 0; return (NULL); } - wstr = (wchar_t *) XtMalloc((wcslen(wlist[0]) + 1) * sizeof(wchar_t)); - if (wstr == (wchar_t *) NULL) { - XwcFreeStringList(wlist); - XtErrorMsg("convertError", "multiSourceCreate", "XawError", - "No Memory", NULL, NULL); - *len_in_out = 0; - return (NULL); /* The above function doesn't really return. */ - } - wcscpy(wstr, wlist[0]); + wstr = wlist[0]; *len_in_out = wcslen(wstr); - XwcFreeStringList(wlist); - return(wstr); - } + XtFree((XtPointer)wlist); + + return (wstr); +} + +#ifndef OLDXAW +static int +qcmp_anchors(_Xconst void *left, _Xconst void *right) +{ + return ((*(XawTextAnchor**)left)->position - + (*(XawTextAnchor**)right)->position); } +XawTextAnchor * +XawTextSourceAddAnchor(Widget w, XawTextPosition position) +{ + TextSrcObject src = (TextSrcObject)w; + XawTextAnchor *anchor, *panchor; + + if ((panchor = XawTextSourceFindAnchor(w, position)) != NULL) { + XawTextEntity *pentity, *entity; + + if (position - panchor->position < ANCHORS_DIST) + return (panchor); + + if (panchor->cache && panchor->position + panchor->cache->offset + + panchor->cache->length < position) + pentity = entity = panchor->cache; + else + pentity = entity = panchor->entities; + + while (entity && panchor->position + entity->offset + + entity->length < position) { + pentity = entity; + entity = entity->next; + } + if (entity) { + XawTextPosition diff; + + if (panchor->position + entity->offset < position) + position = panchor->position + entity->offset; + + if (position == panchor->position) + return (panchor); + + anchor = XtNew(XawTextAnchor); + diff = position - panchor->position; + + panchor->cache = NULL; + anchor->entities = entity; + if (pentity != entity) + pentity->next = NULL; + else + panchor->entities = NULL; + while (entity) { + entity->offset -= diff; + entity = entity->next; + } + } + else { + anchor = XtNew(XawTextAnchor); + anchor->entities = NULL; + } + } + else { + anchor = XtNew(XawTextAnchor); + anchor->entities = NULL; + } + + anchor->position = position; + anchor->cache = NULL; + + src->textSrc.anchors = (XawTextAnchor**) + XtRealloc((XtPointer)src->textSrc.anchors, sizeof(XawTextAnchor*) * + (src->textSrc.num_anchors + 1)); + src->textSrc.anchors[src->textSrc.num_anchors++] = anchor; + qsort((void*)src->textSrc.anchors, src->textSrc.num_anchors, + sizeof(XawTextAnchor*), qcmp_anchors); + + return (anchor); +} + +XawTextAnchor * +XawTextSourceFindAnchor(Widget w, XawTextPosition position) +{ + TextSrcObject src = (TextSrcObject)w; + int i = 0, left, right, nmemb = src->textSrc.num_anchors; + XawTextAnchor *anchor, **anchors = src->textSrc.anchors; + + left = 0; + right = nmemb - 1; + while (left <= right) { + anchor = anchors[i = (left + right) >> 1]; + if (anchor->position == position) + return (anchor); + else if (position < anchor->position) + right = i - 1; + else + left = i + 1; + } + + if (nmemb) + return (right < 0 ? anchors[0] : anchors[right]); + + return (NULL); +} + +Bool +XawTextSourceAnchorAndEntity(Widget w, XawTextPosition position, + XawTextAnchor **anchor_return, + XawTextEntity **entity_return) +{ + XawTextAnchor *anchor = XawTextSourceFindAnchor(w, position); + XawTextEntity *pentity, *entity; + XawTextPosition offset; + Bool next_anchor = True, retval = False; + + if (anchor->cache && anchor->position + anchor->cache->offset + + anchor->cache->length <= position) + pentity = entity = anchor->cache; + else + pentity = entity = anchor->entities; + while (entity) { + offset = anchor->position + entity->offset; + + if (offset > position) { + retval = next_anchor = False; + break; + } + if (offset + entity->length > position) { + retval = True; + next_anchor = False; + break; + } + pentity = entity; + entity = entity->next; + } + + if (next_anchor) { + *anchor_return = anchor = XawTextSourceNextAnchor(w, anchor); + *entity_return = anchor ? anchor->entities : NULL; + } + else { + *anchor_return = anchor; + *entity_return = retval ? entity : pentity; + } + + if (*anchor_return) + (*anchor_return)->cache = *entity_return; + + return (retval); +} + +XawTextAnchor * +XawTextSourceNextAnchor(Widget w, XawTextAnchor *anchor) +{ + int i; + TextSrcObject src = (TextSrcObject)w; + + for (i = 0; i < src->textSrc.num_anchors - 1; i++) + if (src->textSrc.anchors[i] == anchor) + return (src->textSrc.anchors[i + 1]); + + return (NULL); +} + +XawTextAnchor * +XawTextSourcePrevAnchor(Widget w, XawTextAnchor *anchor) +{ + int i; + TextSrcObject src = (TextSrcObject)w; + + for (i = src->textSrc.num_anchors - 1; i > 0; i--) + if (src->textSrc.anchors[i] == anchor) + return (src->textSrc.anchors[i - 1]); + + return (NULL); +} + +XawTextAnchor * +XawTextSourceRemoveAnchor(Widget w, XawTextAnchor *anchor) +{ + int i; + TextSrcObject src = (TextSrcObject)w; + + for (i = 0; i < src->textSrc.num_anchors; i++) + if (src->textSrc.anchors[i] == anchor) + break; + + if (i == 0) + return (src->textSrc.num_anchors > 1 ? src->textSrc.anchors[1] : NULL); + + if (i < src->textSrc.num_anchors) { + XtFree((XtPointer)anchor); + if (i < --src->textSrc.num_anchors) { + memmove(&src->textSrc.anchors[i], + &src->textSrc.anchors[i + 1], + (src->textSrc.num_anchors - i) * + sizeof(XawTextAnchor*)); + + return (src->textSrc.anchors[i]); + } + } + + return (NULL); +} + +XawTextEntity * +XawTextSourceAddEntity(Widget w, int type, int flags, XtPointer data, + XawTextPosition position, Cardinal length, + XrmQuark property) +{ + XawTextAnchor *next, *anchor = _XawTextSourceFindAnchor(w, position); + XawTextEntity *entity, *eprev; + + /* There is no support for zero length entities for now */ + if (length == 0) + return (NULL); + + if (anchor->cache && anchor->position + anchor->cache->offset + + anchor->cache->length <= position) + eprev = entity = anchor->cache; + else + eprev = entity = anchor->entities; + + while (entity && anchor->position + entity->offset + entity->length <= + position) { + eprev = entity; + entity = entity->next; + } + if (entity && anchor->position + entity->offset < position + length) { + fprintf(stderr, "Cannot (yet) add more than one entity to same region.\n"); + return (NULL); + } + + next = XawTextSourceFindAnchor(w, position + length); + if (next && next != anchor) { + if ((entity = next->entities) != NULL) { + if (next->position + entity->offset < position + length) { + fprintf(stderr, "Cannot (yet) add more than one entity to same region.\n"); + return (NULL); + } + } + if (position + length > next->position) { + XawTextPosition diff = position + length - next->position; + + next->position += diff; + entity = next->entities; + while (entity) { + entity->offset -= diff; + entity = entity->next; + } + entity = anchor->entities; + while (entity && entity->offset < 0) + entity = entity->next; + if (entity && entity->offset < 0) { + if (eprev) + eprev->next = next->entities; + else + anchor->entities = next->entities; + if ((next->entities = entity->next) == NULL) + (void)XawTextSourceRemoveAnchor(w, next); + entity->next = NULL; + + return (XawTextSourceAddEntity(w, type, flags, data, position, + length, property)); + } + } + } + + /* Automatically join sequential entities if possible */ + if (eprev && + anchor->position + eprev->offset + eprev->length == position && + eprev->property == property && eprev->type == type && + eprev->flags == flags && eprev->data == data) { + eprev->length += length; + return (eprev); + } + + entity = XtNew(XawTextEntity); + entity->type = type; + entity->flags = flags; + entity->data = data; + entity->offset = position - anchor->position; + entity->length = length; + entity->property = property; + + if (eprev == NULL) { + anchor->entities = entity; + entity->next = NULL; + anchor->cache = NULL; + } + else if (eprev->offset > entity->offset) { + anchor->cache = NULL; + anchor->entities = entity; + entity->next = eprev; + } + else { + anchor->cache = eprev; + entity->next = eprev->next; + eprev->next = entity; + } + + return (entity); +} + +void +XawTextSourceClearEntities(Widget w, XawTextPosition left, XawTextPosition right) +{ + XawTextAnchor *anchor = XawTextSourceFindAnchor(w, left); + XawTextEntity *entity, *eprev, *enext; + XawTextPosition offset; + int length; + + while (anchor && anchor->entities == NULL) + anchor = XawTextSourceRemoveAnchor(w, anchor); + + if (anchor == NULL || left >= right) + return; + + if (anchor->cache && anchor->position + anchor->cache->offset + + anchor->cache->length < left) + eprev = entity = anchor->cache; + else + eprev = entity = anchor->entities; + + /* find first entity before left position */ + while (anchor->position + entity->offset + entity->length < left) { + eprev = entity; + if ((entity = entity->next) == NULL) { + if ((anchor = XawTextSourceNextAnchor(w, anchor)) == NULL) + return; + if ((eprev = entity = anchor->entities) == NULL) { + fprintf(stderr, "Bad anchor found!\n"); + return; + } + } + } + + offset = anchor->position + entity->offset; + if (offset <= left) { + length = XawMin(entity->length, left - offset); + + if (length <= 0) { + enext = entity->next; + eprev->next = enext; + XtFree((XtPointer)entity); + anchor->cache = NULL; + if (entity == anchor->entities) { + eprev = NULL; + if ((anchor->entities = enext) == NULL) { + if ((anchor = XawTextSourceRemoveAnchor(w, anchor)) == NULL) + return; + entity = anchor->entities; + } + else + entity = enext; + } + else + entity = enext; + } + else { + entity->length = length; + eprev = entity; + entity = entity->next; + } + } + + /* clean everything until right position is reached */ + while (anchor) { + while (entity) { + offset = anchor->position + entity->offset + entity->length; + + if (offset > right) { + anchor->cache = NULL; + entity->offset = XawMax(entity->offset, right - anchor->position); + entity->length = XawMin(entity->length, offset - right); + return; + } + + enext = entity->next; + if (eprev) + eprev->next = enext; + XtFree((XtPointer)entity); + if (entity == anchor->entities) { + eprev = anchor->cache = NULL; + if ((anchor->entities = enext) == NULL) { + if ((anchor = XawTextSourceRemoveAnchor(w, anchor)) == NULL) + return; + entity = anchor->entities; + continue; + } + } + entity = enext; + } + if (anchor) + anchor->cache = NULL; + if ((anchor = XawTextSourceNextAnchor(w, anchor)) != NULL) + entity = anchor->entities; + eprev = NULL; + } +} + +/* checks the anchors up to position, and create an appropriate anchor + * at position, if required. + */ +XawTextAnchor * +_XawTextSourceFindAnchor(Widget w, XawTextPosition position) +{ + XawTextAnchor *anchor; + + anchor = XawTextSourceFindAnchor(w, position); + + position -= position % ANCHORS_DIST; + + if (position - anchor->position >= ANCHORS_DIST) + return (XawTextSourceAddAnchor(w, position)); + + return (anchor); +} +#endif diff --git a/src/TextTr.c b/src/TextTr.c index 333853d..16f717c 100644 --- a/src/TextTr.c +++ b/src/TextTr.c @@ -25,6 +25,7 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/TextTr.c,v 3.16 2001/12/14 19:54:45 dawes Exp $ */ /* INTERNATIONALIZATION: @@ -42,88 +43,117 @@ The Japanese user typically hits their Kanji key when they want to do input. This merely makes sure the input is connected. */ -char *_XawDefaultTextTranslations1 = -"\ -Ctrl<Key>A: beginning-of-line() \n\ -Ctrl<Key>B: backward-character() \n\ -Ctrl<Key>C: insert-selection(CUT_BUFFER0) \n\ -Ctrl<Key>D: delete-next-character() \n\ -Ctrl<Key>E: end-of-line() \n\ -Ctrl<Key>F: forward-character() \n\ -Ctrl<Key>G: multiply(Reset) \n\ -Ctrl<Key>H: delete-previous-character() \n\ -Ctrl<Key>J: newline-and-indent() \n\ -Ctrl<Key>K: kill-to-end-of-line() \n\ -Ctrl<Key>L: redraw-display() \n\ -Ctrl<Key>M: newline() \n\ -Ctrl<Key>N: next-line() \n\ -Ctrl<Key>O: newline-and-backup() \n\ -Ctrl<Key>P: previous-line() \n\ -Ctrl<Key>R: search(backward) \n\ -Ctrl<Key>S: search(forward) \n\ -Ctrl<Key>T: transpose-characters() \n\ -Ctrl<Key>U: multiply(4) \n\ -Ctrl<Key>V: next-page() \n\ -Ctrl<Key>W: kill-selection() \n\ -Ctrl<Key>Y: insert-selection(SECONDARY) \n\ -Ctrl<Key>Z: scroll-one-line-up() \n\ -", *_XawDefaultTextTranslations2 = "\ -Meta<Key>B: backward-word() \n\ -Meta<Key>F: forward-word() \n\ -Meta<Key>I: insert-file() \n\ -Meta<Key>K: kill-to-end-of-paragraph() \n\ -Meta<Key>Q: form-paragraph() \n\ -Meta<Key>V: previous-page() \n\ -Meta<Key>Y: insert-selection(PRIMARY, CUT_BUFFER0) \n\ -Meta<Key>Z: scroll-one-line-down() \n\ -:Meta<Key>d: delete-next-word() \n\ -:Meta<Key>D: kill-word() \n\ -:Meta<Key>h: delete-previous-word() \n\ -:Meta<Key>H: backward-kill-word() \n\ -:Meta<Key>\\<: beginning-of-file() \n\ -:Meta<Key>\\>: end-of-file() \n\ -:Meta<Key>]: forward-paragraph() \n\ -:Meta<Key>[: backward-paragraph() \n\ -~Shift Meta<Key>Delete: delete-previous-word() \n\ - Shift Meta<Key>Delete: backward-kill-word() \n\ -~Shift Meta<Key>BackSpace: delete-previous-word() \n\ - Shift Meta<Key>BackSpace: backward-kill-word() \n\ -", *_XawDefaultTextTranslations3 = "\ -<Key>Home: beginning-of-file() \n\ -:<Key>KP_Home: beginning-of-file() \n\ -<Key>End: end-of-file() \n\ -:<Key>KP_End: end-of-file() \n\ -<Key>Next: next-page() \n\ -:<Key>KP_Next: next-page() \n\ -<Key>Prior: previous-page() \n\ -:<Key>KP_Prior: previous-page() \n\ -<Key>Right: forward-character() \n\ -:<Key>KP_Right: forward-character() \n\ -<Key>Left: backward-character() \n\ -:<Key>KP_Left: backward-character() \n\ -<Key>Down: next-line() \n\ -:<Key>KP_Down: next-line() \n\ -<Key>Up: previous-line() \n\ -:<Key>KP_Up: previous-line() \n\ -<Key>Delete: delete-previous-character() \n\ -:<Key>KP_Delete: delete-previous-character() \n\ -<Key>BackSpace: delete-previous-character() \n\ -<Key>Linefeed: newline-and-indent() \n\ -<Key>Return: newline() \n\ -:<Key>KP_Enter: newline() \n\ -Ctrl<Key>backslash: reconnect-im() \n\ -<Key>Kanji: reconnect-im()\n\ -<Key>: insert-char() \n\ -", *_XawDefaultTextTranslations4 = "\ -<EnterWindow>: enter-window() \n\ -<LeaveWindow>: leave-window() \n\ -<FocusIn>: focus-in() \n\ -<FocusOut>: focus-out() \n\ -<Btn1Down>: select-start() \n\ -<Btn1Motion>: extend-adjust() \n\ -<Btn1Up>: extend-end(PRIMARY, CUT_BUFFER0) \n\ -<Btn2Down>: insert-selection(PRIMARY, CUT_BUFFER0) \n\ -<Btn3Down>: extend-start() \n\ -<Btn3Motion>: extend-adjust() \n\ -<Btn3Up>: extend-end(PRIMARY, CUT_BUFFER0) \ -"; +char _XawDefaultTextTranslations[] = +"c<Key>A:" "beginning-of-line()\n" +"c<Key>B:" "backward-character()\n" +"c<Key>C:" "insert-selection(CUT_BUFFER0)\n" +"c<Key>D:" "delete-next-character()\n" +"c<Key>E:" "end-of-line()\n" +"c<Key>F:" "forward-character()\n" +#ifndef OLDXAW +"c<Key>G:" "keyboard-reset()\n" +#else +"c<Key>G:" "multiply(Reset)\n" +#endif +"c<Key>H:" "delete-previous-character()\n" +"c<Key>J:" "newline-and-indent()\n" +"c<Key>K:" "kill-to-end-of-line()\n" +"c<Key>L:" "redraw-display()\n" +"c<Key>M:" "newline()\n" +"c<Key>N:" "next-line()\n" +"c<Key>O:" "newline-and-backup()\n" +"c<Key>P:" "previous-line()\n" +"c<Key>R:" "search(backward)\n" +"c<Key>S:" "search(forward)\n" +"c<Key>T:" "transpose-characters()\n" +#ifndef OLDXAW +"c<Key>U:" "multiply(Start)\n" +#else +"c<Key>U:" "multiply(4)\n" +#endif +"c<Key>V:" "next-page()\n" +"c<Key>W:" "kill-selection()\n" +"c<Key>Y:" "insert-selection(SECONDARY)\n" +"c<Key>Z:" "scroll-one-line-up()\n" +"m<Key>B:" "backward-word()\n" +"m<Key>C:" "capitalize-word()\n" +"m<Key>F:" "forward-word()\n" +"m<Key>I:" "insert-file()\n" +"m<Key>K:" "kill-to-end-of-paragraph()\n" +"m<Key>L:" "downcase-word()\n" +"m<Key>Q:" "form-paragraph()\n" +"m<Key>U:" "upcase-word()\n" +"m<Key>V:" "previous-page()\n" +#ifndef OLDXAW +"m<Key>Y:" "kill-ring-yank()\n" +#endif +"m<Key>Z:" "scroll-one-line-down()\n" +"~s m<Key>d:" "kill-word(alnum)\n" +"s m<Key>d:" "delete-next-word(alnum)\n" +"~s m<Key>h:" "backward-kill-word(alnum)\n" +"s m<Key>h:" "delete-previous-word(alnum)\n" +":m<Key>\\<:" "beginning-of-file()\n" +":m<Key>\\>:" "end-of-file()\n" +":m<Key>]:" "forward-paragraph()\n" +":m<Key>[:" "backward-paragraph()\n" +"~s m<Key>Delete:" "backward-kill-word(alnum)\n" +"s m<Key>Delete:" "delete-previous-word(alnum)\n" +"~s m<Key>BackSpace:" "backward-kill-word(alnum)\n" +"s m<Key>BackSpace:" "delete-previous-word(alnum)\n" +"c<Key>Left:" "backward-word(alnum)\n" +"c<Key>Right:" "forward-word(alnum)\n" +"c<Key>Up:" "backward-paragraph()\n" +"c<Key>Down:" "forward-paragraph()\n" +"<Key>Home:" "beginning-of-file()\n" +":<Key>KP_Home:" "beginning-of-file()\n" +"<Key>End:" "end-of-file()\n" +":<Key>KP_End:" "end-of-file()\n" +"<Key>Next:" "next-page()\n" +":<Key>KP_Next:" "next-page()\n" +"<Key>Prior:" "previous-page()\n" +":<Key>KP_Prior:" "previous-page()\n" +"<Key>Right:" "forward-character()\n" +":<Key>KP_Right:" "forward-character()\n" +"<Key>Left:" "backward-character()\n" +":<Key>KP_Left:" "backward-character()\n" +"<Key>Down:" "next-line()\n" +":<Key>KP_Down:" "next-line()\n" +"<Key>Up:" "previous-line()\n" +":<Key>KP_Up:" "previous-line()\n" +"<Key>Delete:" "delete()\n" +":<Key>KP_Delete:" "delete()\n" +"<Key>BackSpace:" "delete-previous-character()\n" +"<Key>Linefeed:" "newline-and-indent()\n" +"<Key>Return:" "newline()\n" +":<Key>KP_Enter:" "newline()\n" +"c<Key>backslash:" "reconnect-im()\n" +"<Key>Kanji:" "reconnect-im()\n" +#ifndef OLDXAW +":<Key>0:" "numeric(0)\n" +":<Key>1:" "numeric(1)\n" +":<Key>2:" "numeric(2)\n" +":<Key>3:" "numeric(3)\n" +":<Key>4:" "numeric(4)\n" +":<Key>5:" "numeric(5)\n" +":<Key>6:" "numeric(6)\n" +":<Key>7:" "numeric(7)\n" +":<Key>8:" "numeric(8)\n" +":<Key>9:" "numeric(9)\n" +":<Key>-:" "numeric(-)\n" +":c<Key>_:" "undo()\n" +#endif +"s <Key>Insert:" "insert-selection(PRIMARY, CUT_BUFFER0)\n" +"<Ctrl>Q,<Key>:" "insert-char()\n" +"<Key>:" "insert-char()\n" +"<Enter>:" "enter-window()\n" +"<Leave>:" "leave-window()\n" +"<FocusIn>:" "focus-in()\n" +"<FocusOut>:" "focus-out()\n" +"<Btn1Down>:" "select-start()\n" +"<Btn1Motion>:" "extend-adjust()\n" +"<Btn1Up>:" "extend-end(PRIMARY, CUT_BUFFER0)\n" +"<Btn2Down>:" "insert-selection(PRIMARY, CUT_BUFFER0)\n" +"<Btn3Down>:" "extend-start()\n" +"<Btn3Motion>:" "extend-adjust()\n" +"<Btn3Up>:" "extend-end(PRIMARY, CUT_BUFFER0)\n" +; diff --git a/src/Toggle.c b/src/Toggle.c index 988d9e1..06b2254 100644 --- a/src/Toggle.c +++ b/src/Toggle.c @@ -25,10 +25,9 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/Toggle.c,v 1.9 2001/12/14 19:54:45 dawes Exp $ */ /* - * Toggle.c - Toggle button widget - * * Author: Chris D. Peterson * MIT X Consortium * kit@expo.lcs.mit.edu @@ -38,74 +37,100 @@ in this Software without prior written authorization from The Open Group. */ #include <stdio.h> - #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> -#include <X11/Xaw/XawInit.h> #include <X11/Xmu/Converters.h> #include <X11/Xmu/Misc.h> +#include <X11/Xmu/SysUtil.h> #include <X11/Xaw/ToggleP.h> +#include <X11/Xaw/XawInit.h> -/**************************************************************** - * - * Full class record constant - * - ****************************************************************/ +/* + * Class Methods + */ +static void XawToggleClassInitialize(void); +static void XawToggleInitialize(Widget, Widget, ArgList, Cardinal*); +static Boolean XawToggleSetValues(Widget, Widget, Widget, ArgList, Cardinal*); -/* Private Data */ +/* + * Prototypes + */ +static void AddToRadioGroup(RadioGroup*, Widget); +static void CreateRadioGroup(Widget, Widget); +static RadioGroup *GetRadioGroup(Widget); +static void RemoveFromRadioGroup(Widget); +static void TurnOffRadioSiblings(Widget); +static void XawToggleDestroy(Widget, XtPointer, XtPointer); /* - * The order of toggle and notify are important, as the state has - * to be set when we call the notify proc. + * Actions */ +static void Notify(Widget, XEvent*, String*, Cardinal*); +static void Toggle(Widget, XEvent*, String*, Cardinal*); +static void ToggleSet(Widget, XEvent*, String*, Cardinal*); +/* + * Initialization + */ +/* + * The order of toggle and notify are important, as the state has + * to be set when we call the notify proc + */ static char defaultTranslations[] = - "<EnterWindow>: highlight(Always) \n\ - <LeaveWindow>: unhighlight() \n\ - <Btn1Down>,<Btn1Up>: toggle() notify()"; +"<Enter>:" "highlight(Always)\n" +"<Leave>:" "unhighlight()\n" +"<Btn1Down>,<Btn1Up>:" "toggle() notify()\n" +; #define offset(field) XtOffsetOf(ToggleRec, field) - static XtResource resources[] = { - {XtNstate, XtCState, XtRBoolean, sizeof(Boolean), - offset(command.set), XtRString, "off"}, - {XtNradioGroup, XtCWidget, XtRWidget, sizeof(Widget), - offset(toggle.widget), XtRWidget, (XtPointer) NULL }, - {XtNradioData, XtCRadioData, XtRPointer, sizeof(XtPointer), - offset(toggle.radio_data), XtRPointer, (XtPointer) NULL }, + { + XtNstate, + XtCState, + XtRBoolean, + sizeof(Boolean), + offset(command.set), + XtRString, + "off" + }, + { + XtNradioGroup, + XtCWidget, + XtRWidget, + sizeof(Widget), + offset(toggle.widget), + XtRWidget, + NULL + }, + { + XtNradioData, + XtCRadioData, + XtRPointer, + sizeof(XtPointer), + offset(toggle.radio_data), + XtRPointer, + NULL + }, }; - #undef offset - -static void Toggle(), Initialize(), Notify(), ToggleSet(); -static void ToggleDestroy(), ClassInit(); -static Boolean SetValues(); - -/* Functions for handling the Radio Group. */ - -static RadioGroup * GetRadioGroup(); -static void CreateRadioGroup(), AddToRadioGroup(), TurnOffRadioSiblings(); -static void RemoveFromRadioGroup(); - -static XtActionsRec actionsList[] = -{ - {"toggle", Toggle}, - {"notify", Notify}, - {"set", ToggleSet}, +static XtActionsRec actionsList[] = { + {"toggle", Toggle}, + {"notify", Notify}, + {"set", ToggleSet}, }; -#define SuperClass ((CommandWidgetClass)&commandClassRec) - +#define Superclass ((CommandWidgetClass)&commandClassRec) ToggleClassRec toggleClassRec = { + /* core */ { - (WidgetClass) SuperClass, /* superclass */ + (WidgetClass)Superclass, /* superclass */ "Toggle", /* class_name */ sizeof(ToggleRec), /* size */ - ClassInit, /* class_initialize */ + XawToggleClassInitialize, /* class_initialize */ NULL, /* class_part_initialize */ - FALSE, /* class_inited */ - Initialize, /* initialize */ + False, /* class_inited */ + XawToggleInitialize, /* initialize */ NULL, /* initialize_hook */ XtInheritRealize, /* realize */ actionsList, /* actions */ @@ -113,14 +138,14 @@ ToggleClassRec toggleClassRec = { resources, /* resources */ XtNumber(resources), /* resource_count */ NULLQUARK, /* xrm_class */ - FALSE, /* compress_motion */ - TRUE, /* compress_exposure */ - TRUE, /* compress_enterleave */ - FALSE, /* visible_interest */ - NULL, /* destroy */ + False, /* compress_motion */ + True, /* compress_exposure */ + True, /* compress_enterleave */ + False, /* visible_interest */ + NULL, /* destroy */ XtInheritResize, /* resize */ XtInheritExpose, /* expose */ - SetValues, /* set_values */ + XawToggleSetValues, /* set_values */ NULL, /* set_values_hook */ XtInheritSetValuesAlmost, /* set_values_almost */ NULL, /* get_values_hook */ @@ -130,486 +155,475 @@ ToggleClassRec toggleClassRec = { defaultTranslations, /* tm_table */ XtInheritQueryGeometry, /* query_geometry */ XtInheritDisplayAccelerator, /* display_accelerator */ - NULL /* extension */ - }, /* CoreClass fields initialization */ + NULL, /* extension */ + }, + /* simple */ { - XtInheritChangeSensitive /* change_sensitive */ - }, /* SimpleClass fields initialization */ + XtInheritChangeSensitive, /* change_sensitive */ + }, + /* label */ { - 0 /* field not used */ - }, /* LabelClass fields initialization */ + NULL, /* extension */ + }, + /* command */ { - 0 /* field not used */ - }, /* CommandClass fields initialization */ + NULL, /* extension */ + }, + /* toggle */ { - NULL, /* Set Procedure. */ - NULL, /* Unset Procedure. */ - NULL /* extension. */ - } /* ToggleClass fields initialization */ + NULL, /* Set */ + NULL, /* Unset */ + NULL, /* extension */ + } }; - /* for public consumption */ -WidgetClass toggleWidgetClass = (WidgetClass) &toggleClassRec; - -/**************************************************************** - * - * Private Procedures - * - ****************************************************************/ +WidgetClass toggleWidgetClass = (WidgetClass)&toggleClassRec; +/* + * Impelementation + */ static void -ClassInit() +XawToggleClassInitialize(void) { - XtActionList actions; - Cardinal num_actions; - Cardinal i; - ToggleWidgetClass class = (ToggleWidgetClass) toggleWidgetClass; - static XtConvertArgRec parentCvtArgs[] = { - {XtBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.parent), - sizeof(Widget)} - }; - - XawInitializeWidgetSet(); - XtSetTypeConverter(XtRString, XtRWidget, XmuNewCvtStringToWidget, - parentCvtArgs, XtNumber(parentCvtArgs), XtCacheNone, - (XtDestructor)NULL); -/* - * Find the set and unset actions in the command widget's action table. - */ - - XtGetActionList(commandWidgetClass, &actions, &num_actions); - - for (i = 0 ; i < num_actions ; i++) { - if (streq(actions[i].string, "set")) - class->toggle_class.Set = actions[i].proc; - if (streq(actions[i].string, "unset")) - class->toggle_class.Unset = actions[i].proc; - - if ( (class->toggle_class.Set != NULL) && - (class->toggle_class.Unset != NULL) ) { - XtFree((char *) actions); - return; + XtActionList actions; + Cardinal num_actions; + Cardinal i; + ToggleWidgetClass cclass = (ToggleWidgetClass)toggleWidgetClass; + static XtConvertArgRec parentCvtArgs[] = { + {XtBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.parent), + sizeof(Widget)} + }; + + XawInitializeWidgetSet(); + XtSetTypeConverter(XtRString, XtRWidget, XmuNewCvtStringToWidget, + parentCvtArgs, XtNumber(parentCvtArgs), + XtCacheNone, NULL); + XtSetTypeConverter(XtRWidget, XtRString, XmuCvtWidgetToString, + NULL, 0, XtCacheNone, NULL); + + /* + * Find the set and unset actions in the command widget's action table + */ + XtGetActionList(commandWidgetClass, &actions, &num_actions); + + for (i = 0 ; i < num_actions ; i++) { + if (streq(actions[i].string, "set")) + cclass->toggle_class.Set = actions[i].proc; + if (streq(actions[i].string, "unset")) + cclass->toggle_class.Unset = actions[i].proc; + + if (cclass->toggle_class.Set != NULL && + cclass->toggle_class.Unset != NULL) { + XtFree((char *)actions); + return; + } } - } -/* We should never get here. */ - XtError("Aborting, due to errors resolving bindings in the Toggle widget."); + /* We should never get here */ + XtError("Aborting, due to errors resolving bindings in the Toggle widget."); } /*ARGSUSED*/ -static void Initialize(request, new, args, num_args) - Widget request, new; - ArgList args; - Cardinal *num_args; +static void +XawToggleInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - ToggleWidget tw = (ToggleWidget) new; - ToggleWidget tw_req = (ToggleWidget) request; + ToggleWidget tw = (ToggleWidget)cnew; + ToggleWidget tw_req = (ToggleWidget)request; tw->toggle.radio_group = NULL; if (tw->toggle.radio_data == NULL) - tw->toggle.radio_data = (XtPointer) new->core.name; + tw->toggle.radio_data = (XtPointer)cnew->core.name; if (tw->toggle.widget != NULL) { - if ( GetRadioGroup(tw->toggle.widget) == NULL) - CreateRadioGroup(new, tw->toggle.widget); - else - AddToRadioGroup( GetRadioGroup(tw->toggle.widget), new); - } - XtAddCallback(new, XtNdestroyCallback, ToggleDestroy, (XtPointer)NULL); - -/* - * Command widget assumes that the widget is unset, so we only - * have to handle the case where it needs to be set. - * - * If this widget is in a radio group then it may cause another - * widget to be unset, thus calling the notify proceedure. - * - * I want to set the toggle if the user set the state to "On" in - * the resource group, reguardless of what my ancestors did. - */ - + if (GetRadioGroup(tw->toggle.widget) == NULL) + CreateRadioGroup(cnew, tw->toggle.widget); + else + AddToRadioGroup(GetRadioGroup(tw->toggle.widget), cnew); + } + XtAddCallback(cnew, XtNdestroyCallback, XawToggleDestroy, NULL); + + /* + * Command widget assumes that the widget is unset, so we only + * have to handle the case where it needs to be set + * + * If this widget is in a radio group then it may cause another + * widget to be unset, thus calling the notify proceedure + * + * I want to set the toggle if the user set the state to "On" in + * the resource group, reguardless of what my ancestors did + */ if (tw_req->command.set) - ToggleSet(new, (XEvent *)NULL, (String *)NULL, (Cardinal *)0); + ToggleSet(cnew, NULL, NULL, NULL); } -/************************************************************ - * - * Action Procedures - * - ************************************************************/ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -ToggleSet(w,event,params,num_params) -Widget w; -XEvent *event; -String *params; /* unused */ -Cardinal *num_params; /* unused */ +ToggleSet(Widget w, XEvent *event, String *params, Cardinal *num_params) { - ToggleWidgetClass class = (ToggleWidgetClass) w->core.widget_class; + ToggleWidgetClass cclass = (ToggleWidgetClass)w->core.widget_class; TurnOffRadioSiblings(w); - class->toggle_class.Set(w, event, NULL, 0); + cclass->toggle_class.Set(w, event, NULL, NULL); } -/* ARGSUSED */ static void -Toggle(w,event,params,num_params) -Widget w; -XEvent *event; -String *params; /* unused */ -Cardinal *num_params; /* unused */ +Toggle(Widget w, XEvent *event, String *params, Cardinal *num_params) { - ToggleWidget tw = (ToggleWidget)w; - ToggleWidgetClass class = (ToggleWidgetClass) w->core.widget_class; + ToggleWidget tw = (ToggleWidget)w; + ToggleWidgetClass cclass = (ToggleWidgetClass)w->core.widget_class; - if (tw->command.set) - class->toggle_class.Unset(w, event, NULL, 0); - else - ToggleSet(w, event, params, num_params); + if (tw->command.set) + cclass->toggle_class.Unset(w, event, NULL, NULL); + else + ToggleSet(w, event, params, num_params); } -/* ARGSUSED */ -static void Notify(w,event,params,num_params) -Widget w; -XEvent *event; -String *params; /* unused */ -Cardinal *num_params; /* unused */ +/*ARGSUSED*/ +static void +Notify(Widget w, XEvent *event, String *params, Cardinal *num_params) { - ToggleWidget tw = (ToggleWidget) w; - long antilint = tw->command.set; + ToggleWidget tw = (ToggleWidget)w; + long antilint = tw->command.set; - XtCallCallbacks( w, XtNcallback, (XtPointer) antilint ); + XtCallCallbacks(w, XtNcallback, (XtPointer)antilint); } -/************************************************************ - * - * Set specified arguments into widget - * - ***********************************************************/ - -/* ARGSUSED */ +/*ARGSUSED*/ static Boolean -SetValues (current, request, new, args, num_args) -Widget current, request, new; -ArgList args; -Cardinal *num_args; +XawToggleSetValues(Widget current, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - ToggleWidget oldtw = (ToggleWidget) current; - ToggleWidget tw = (ToggleWidget) new; - ToggleWidget rtw = (ToggleWidget) request; + ToggleWidget oldtw = (ToggleWidget)current; + ToggleWidget tw = (ToggleWidget)cnew; + ToggleWidget rtw = (ToggleWidget)request; if (oldtw->toggle.widget != tw->toggle.widget) - XawToggleChangeRadioGroup(new, tw->toggle.widget); + XawToggleChangeRadioGroup(cnew, tw->toggle.widget); if (!tw->core.sensitive && oldtw->core.sensitive && rtw->command.set) tw->command.set = True; if (oldtw->command.set != tw->command.set) { tw->command.set = oldtw->command.set; - Toggle(new, (XEvent *)NULL, (String *)NULL, (Cardinal *)0); + Toggle(cnew, NULL, NULL, NULL); } - return(FALSE); + + return (False); } -/* Function Name: ToggleDestroy - * Description: Destroy Callback for toggle widget. - * Arguments: w - the toggle widget that is being destroyed. - * junk, grabage - not used. - * Returns: none. +/* + * Function: + * XawToggleDestroy + * + * Parameters: + * w - toggle widget that is being destroyed + * temp1 - not used + * temp2 - "" + * + * Description: + * Destroy Callback for toggle widget. */ - -/* ARGSUSED */ +/*ARGSUSED*/ static void -ToggleDestroy(w, junk, garbage) -Widget w; -XtPointer junk, garbage; +XawToggleDestroy(Widget w, XtPointer temp1, XtPointer temp2) { - RemoveFromRadioGroup(w); + RemoveFromRadioGroup(w); } -/************************************************************ +/* + * Function: + * GetRadioGroup * - * Below are all the private procedures that handle - * radio toggle buttons. + * Parameters: + * w - toggle widget who's radio group we are getting * - ************************************************************/ - -/* Function Name: GetRadioGroup - * Description: Gets the radio group associated with a give toggle - * widget. - * Arguments: w - the toggle widget who's radio group we are getting. - * Returns: the radio group associated with this toggle group. + * Description: + * Gets the radio group associated with a give toggle widget. + * + * Returns: + * The radio group associated with this toggle group */ - static RadioGroup * -GetRadioGroup(w) -Widget w; +GetRadioGroup(Widget w) { - ToggleWidget tw = (ToggleWidget) w; + ToggleWidget tw = (ToggleWidget)w; + + if (tw == NULL) + return (NULL); - if (tw == NULL) return(NULL); - return( tw->toggle.radio_group ); + return (tw->toggle.radio_group); } -/* Function Name: CreateRadioGroup - * Description: Creates a radio group. give two widgets. - * Arguments: w1, w2 - the toggle widgets to add to the radio group. - * Returns: none. +/* + * Function: + * CreateRadioGroup + * + * Parameters: + * w1 - toggle widgets to add to the radio group + * w2 - "" + * + * Description: + * Creates a radio group. give two widgets. * - * NOTE: A pointer to the group is added to each widget's radio_group - * field. + * Note: + * A pointer to the group is added to each widget's radio_group field. */ - static void -CreateRadioGroup(w1, w2) -Widget w1, w2; +CreateRadioGroup(Widget w1, Widget w2) { - char error_buf[BUFSIZ]; - ToggleWidget tw1 = (ToggleWidget) w1; - ToggleWidget tw2 = (ToggleWidget) w2; - - if ( (tw1->toggle.radio_group != NULL) || (tw2->toggle.radio_group != NULL) ) { - (void) sprintf(error_buf, "%s %s", "Toggle Widget Error - Attempting", - "to create a new toggle group, when one already exists."); - XtWarning(error_buf); - } + ToggleWidget tw1 = (ToggleWidget)w1; + ToggleWidget tw2 = (ToggleWidget) w2; - AddToRadioGroup( (RadioGroup *)NULL, w1 ); - AddToRadioGroup( GetRadioGroup(w1), w2 ); + if (tw1->toggle.radio_group != NULL || tw2->toggle.radio_group != NULL) + XtAppWarning(XtWidgetToApplicationContext(w1), + "Toggle Widget Error - Attempting to create a " + "new toggle group, when one already exists."); + + AddToRadioGroup(NULL, w1); + AddToRadioGroup(GetRadioGroup(w1), w2); } -/* Function Name: AddToRadioGroup - * Description: Adds a toggle to the radio group. - * Arguments: group - any element of the radio group the we are adding to. - * w - the new toggle widget to add to the group. - * Returns: none. +/* + * Function: + * AddToRadioGroup + * + * Parameters: + * group - element of the radio group the we are adding to + * w - new toggle widget to add to the group + * + * Description: + * Adds a toggle to the radio group. */ - static void -AddToRadioGroup(group, w) -RadioGroup * group; -Widget w; +AddToRadioGroup(RadioGroup *group, Widget w) { - ToggleWidget tw = (ToggleWidget) w; - RadioGroup * local; - - local = (RadioGroup *) XtMalloc( sizeof(RadioGroup) ); - local->widget = w; - tw->toggle.radio_group = local; - - if (group == NULL) { /* Creating new group. */ - group = local; - group->next = NULL; - group->prev = NULL; - return; - } - local->prev = group; /* Adding to previous group. */ - if ((local->next = group->next) != NULL) - local->next->prev = local; - group->next = local; + ToggleWidget tw = (ToggleWidget)w; + RadioGroup *local; + + local = (RadioGroup *)XtMalloc(sizeof(RadioGroup)); + local->widget = w; + tw->toggle.radio_group = local; + + if (group == NULL) { /* Creating new group */ + group = local; + group->next = NULL; + group->prev = NULL; + return; + } + local->prev = group; /* Adding to previous group */ + if ((local->next = group->next) != NULL) + local->next->prev = local; + group->next = local; } -/* Function Name: TurnOffRadioSiblings - * Description: Deactivates all radio siblings. - * Arguments: widget - a toggle widget. - * Returns: none. +/* + * Function: + * TurnOffRadioSiblings + * + * Parameters: + * widget - toggle widget + * + * Description: + * Deactivates all radio siblings. */ - static void -TurnOffRadioSiblings(w) -Widget w; +TurnOffRadioSiblings(Widget w) { - RadioGroup * group; - ToggleWidgetClass class = (ToggleWidgetClass) w->core.widget_class; + RadioGroup *group; + ToggleWidgetClass cclass = (ToggleWidgetClass)w->core.widget_class; - if ( (group = GetRadioGroup(w)) == NULL) /* Punt if there is no group */ - return; + if ((group = GetRadioGroup(w)) == NULL) /* Punt if there is no group */ + return; - /* Go to the top of the group. */ + /* Go to the top of the group */ + for (; group->prev != NULL ; group = group->prev) + ; - for ( ; group->prev != NULL ; group = group->prev ); + while (group != NULL) { + ToggleWidget local_tog = (ToggleWidget)group->widget; - while ( group != NULL ) { - ToggleWidget local_tog = (ToggleWidget) group->widget; - if ( local_tog->command.set ) { - class->toggle_class.Unset(group->widget, NULL, NULL, 0); - Notify( group->widget, (XEvent *)NULL, (String *)NULL, (Cardinal *)0); + if (local_tog->command.set) { + cclass->toggle_class.Unset(group->widget, NULL, NULL, NULL); + Notify(group->widget, NULL, NULL, NULL); + } + group = group->next; } - group = group->next; - } } -/* Function Name: RemoveFromRadioGroup - * Description: Removes a toggle from a RadioGroup. - * Arguments: w - the toggle widget to remove. - * Returns: none. +/* + * Function: + * RemoveFromRadioGroup + * + * Parameters: + * w - toggle widget to remove + * + * Description: + * Removes a toggle from a RadioGroup. */ - static void -RemoveFromRadioGroup(w) -Widget w; +RemoveFromRadioGroup(Widget w) { - RadioGroup * group = GetRadioGroup(w); - if (group != NULL) { - if (group->prev != NULL) - (group->prev)->next = group->next; - if (group->next != NULL) - (group->next)->prev = group->prev; - XtFree((char *) group); - } + RadioGroup *group = GetRadioGroup(w); + if (group != NULL) { + if (group->prev != NULL) + (group->prev)->next = group->next; + if (group->next != NULL) + (group->next)->prev = group->prev; + XtFree((char *)group); + } } -/************************************************************ +/* + * Function: + * XawToggleChangeRadioGroup * - * Public Routines + * Parameters: + * w - toggle widget to change groups + * radio_group - any widget in the new group * - ************************************************************/ - -/* Function Name: XawToggleChangeRadioGroup - * Description: Allows a toggle widget to change radio groups. - * Arguments: w - The toggle widget to change groups. - * radio_group - any widget in the new group. - * Returns: none. + * Description: + * Allows a toggle widget to change radio groups. */ - void -#if NeedFunctionPrototypes XawToggleChangeRadioGroup(Widget w, Widget radio_group) -#else -XawToggleChangeRadioGroup(w, radio_group) -Widget w, radio_group; -#endif { - ToggleWidget tw = (ToggleWidget) w; - RadioGroup * group; + ToggleWidget tw = (ToggleWidget)w; + RadioGroup *group; - RemoveFromRadioGroup(w); + RemoveFromRadioGroup(w); -/* - * If the toggle that we are about to add is set then we will - * unset all toggles in the new radio group. - */ + /* + * If the toggle that we are about to add is set then we will + * unset all toggles in the new radio group + */ - if ( tw->command.set && radio_group != NULL ) - XawToggleUnsetCurrent(radio_group); + if (tw->command.set && radio_group != NULL) + XawToggleUnsetCurrent(radio_group); - if (radio_group != NULL) - if ((group = GetRadioGroup(radio_group)) == NULL) - CreateRadioGroup(w, radio_group); - else AddToRadioGroup(group, w); + if (radio_group != NULL) { + if ((group = GetRadioGroup(radio_group)) == NULL) + CreateRadioGroup(w, radio_group); + else + AddToRadioGroup(group, w); + } } -/* Function Name: XawToggleGetCurrent - * Description: Returns the RadioData associated with the toggle - * widget that is currently active in a toggle group. - * Arguments: w - any toggle widget in the toggle group. - * Returns: The XtNradioData associated with the toggle widget. +/* + * Function: + * XawToggleGetCurrent + * + * Parameters: + * w - any toggle widget in the toggle group + * + * Description: + * Returns the RadioData associated with the toggle + * widget that is currently active in a toggle group. + * + * Returns: + * The XtNradioData associated with the toggle widget */ - XtPointer -#if NeedFunctionPrototypes XawToggleGetCurrent(Widget w) -#else -XawToggleGetCurrent(w) -Widget w; -#endif { - RadioGroup * group; + RadioGroup *group; - if ( (group = GetRadioGroup(w)) == NULL) return(NULL); - for ( ; group->prev != NULL ; group = group->prev); + if ((group = GetRadioGroup(w)) == NULL) + return (NULL); - while ( group != NULL ) { - ToggleWidget local_tog = (ToggleWidget) group->widget; - if ( local_tog->command.set ) - return( local_tog->toggle.radio_data ); - group = group->next; - } - return(NULL); + for (; group->prev != NULL ; group = group->prev) + ; + + while (group != NULL) { + ToggleWidget local_tog = (ToggleWidget)group->widget; + + if (local_tog->command.set) + return (local_tog->toggle.radio_data); + group = group->next; + } + + return (NULL); } -/* Function Name: XawToggleSetCurrent - * Description: Sets the Toggle widget associated with the - * radio_data specified. - * Arguments: radio_group - any toggle widget in the toggle group. - * radio_data - radio data of the toggle widget to set. - * Returns: none. +/* + * Function: + * XawToggleSetCurrent + * + * Parameters: + * radio_group - any toggle widget in the toggle group + * radio_data - radio data of the toggle widget to set + * + * Description: + * Sets the Toggle widget associated with the radio_data specified. */ - void -#if NeedFunctionPrototypes XawToggleSetCurrent(Widget radio_group, XtPointer radio_data) -#else -XawToggleSetCurrent(radio_group, radio_data) -Widget radio_group; -XtPointer radio_data; -#endif { - RadioGroup * group; - ToggleWidget local_tog; - -/* Special case of no radio group. */ - - if ( (group = GetRadioGroup(radio_group)) == NULL) { - local_tog = (ToggleWidget) radio_group; - if ( (local_tog->toggle.radio_data == radio_data) ) - if (!local_tog->command.set) { - ToggleSet((Widget) local_tog, (XEvent *)NULL, (String *)NULL, (Cardinal *)0); - Notify((Widget) local_tog, (XEvent *)NULL, (String *)NULL, (Cardinal *)0); - } - return; - } + RadioGroup *group; + ToggleWidget local_tog; -/* - * find top of radio_roup - */ + /* Special case of no radio group */ - for ( ; group->prev != NULL ; group = group->prev); + if ((group = GetRadioGroup(radio_group)) == NULL) { + local_tog = (ToggleWidget)radio_group; -/* - * search for matching radio data. - */ + if (local_tog->toggle.radio_data == radio_data && + !local_tog->command.set) { + ToggleSet(radio_group, NULL, NULL, NULL); + Notify(radio_group, NULL, NULL, NULL); + } + return; + } - while ( group != NULL ) { - local_tog = (ToggleWidget) group->widget; - if ( (local_tog->toggle.radio_data == radio_data) ) { - if (!local_tog->command.set) { /* if not already set. */ - ToggleSet((Widget) local_tog, (XEvent *)NULL, (String *)NULL, (Cardinal *)0); - Notify((Widget) local_tog, (XEvent *)NULL, (String *)NULL, (Cardinal *)0); - } - return; /* found it, done */ + /* + * find top of radio_roup + */ + for (; group->prev != NULL ; group = group->prev) + ; + + /* + * search for matching radio data + */ + while (group != NULL) { + local_tog = (ToggleWidget)group->widget; + + if (local_tog->toggle.radio_data == radio_data) { + if (!local_tog->command.set) { /* if not already set */ + ToggleSet(group->widget, NULL, NULL, NULL); + Notify(group->widget, NULL, NULL, NULL); + } + return; /* found it, done */ + } + group = group->next; } - group = group->next; - } } - -/* Function Name: XawToggleUnsetCurrent - * Description: Unsets all Toggles in the radio_group specified. - * Arguments: radio_group - any toggle widget in the toggle group. - * Returns: none. - */ +/* + * Function: + * XawToggleUnsetCurrent + * + * Parameters: + * radio_group - any toggle widget in the toggle group + * + * Description: + * Unsets all Toggles in the radio_group specified. + */ void -#if NeedFunctionPrototypes XawToggleUnsetCurrent(Widget radio_group) -#else -XawToggleUnsetCurrent(radio_group) -Widget radio_group; -#endif { - ToggleWidgetClass class; - ToggleWidget local_tog = (ToggleWidget) radio_group; + ToggleWidgetClass cclass; + ToggleWidget local_tog = (ToggleWidget)radio_group; - /* Special Case no radio group. */ + /* Special Case no radio group */ - if (local_tog->command.set) { - class = (ToggleWidgetClass) local_tog->core.widget_class; - class->toggle_class.Unset(radio_group, NULL, NULL, 0); - Notify(radio_group, (XEvent *)NULL, (String *)NULL, (Cardinal *)0); - } - if ( GetRadioGroup(radio_group) == NULL) return; - TurnOffRadioSiblings(radio_group); -} + if (local_tog->command.set) { + cclass = (ToggleWidgetClass)local_tog->core.widget_class; + cclass->toggle_class.Unset(radio_group, NULL, NULL, NULL); + Notify(radio_group, NULL, NULL, NULL); + } + if (GetRadioGroup(radio_group) == NULL) + return; + TurnOffRadioSiblings(radio_group); +} @@ -48,35 +48,53 @@ in this Software without prior written authorization from The Open Group. * additional blank space to make the structure of the graph easier to see * as well as to support vertical trees. */ +/* $XFree86: xc/lib/Xaw/Tree.c,v 1.10 2001/12/14 19:54:45 dawes Exp $ */ #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> #include <X11/Xaw/XawInit.h> #include <X11/Xaw/Cardinals.h> #include <X11/Xaw/TreeP.h> +#include "Private.h" #define IsHorizontal(tw) ((tw)->tree.gravity == WestGravity || \ (tw)->tree.gravity == EastGravity) +/* + * Class Methods + */ +static void XawTreeChangeManaged(Widget); +static void XawTreeClassInitialize(void); +static void XawTreeConstraintDestroy(Widget); +static void XawTreeConstraintInitialize(Widget, Widget, ArgList, Cardinal*); +static Boolean XawTreeConstraintSetValues(Widget, Widget, Widget, + ArgList, Cardinal*); +static void XawTreeDestroy(Widget); +static XtGeometryResult XawTreeGeometryManager(Widget, XtWidgetGeometry*, + XtWidgetGeometry*); +static void XawTreeInitialize(Widget, Widget, ArgList, Cardinal*); +static XtGeometryResult XawTreeQueryGeometry(Widget, XtWidgetGeometry*, + XtWidgetGeometry*); +static void XawTreeRedisplay(Widget, XEvent*, Region); +static Boolean XawTreeSetValues(Widget, Widget, Widget, ArgList, Cardinal*); - /* widget class method */ -static void ClassInitialize(); -static void Initialize(); -static void ConstraintInitialize(); -static void ConstraintDestroy(); -static Boolean ConstraintSetValues(); -static void Destroy(); -static Boolean SetValues(); -static XtGeometryResult GeometryManager(); -static void ChangeManaged(); -static void Redisplay(); -static XtGeometryResult QueryGeometry(); - - /* utility routines */ -static void insert_node(); -static void delete_node(); -static void layout_tree(); +/* + * Prototypes + */ +static void arrange_subtree(TreeWidget, Widget, int, int, int); +static void check_gravity(TreeWidget, XtGravity); +static void compute_bounding_box_subtree(TreeWidget, Widget, int); +static void delete_node(Widget, Widget); +static GC get_tree_gc(TreeWidget); +static void initialize_dimensions(Dimension**, int*, int); +static void insert_node(Widget, Widget); +static void layout_tree(TreeWidget, Bool); +static void set_positions(TreeWidget, Widget, int); +static void set_tree_size(TreeWidget, Bool, unsigned int, unsigned int); +/* + * Initialization + */ /* * resources of the tree itself @@ -97,6 +115,11 @@ static XtResource resources[] = { { XtNgravity, XtCGravity, XtRGravity, sizeof (XtGravity), XtOffsetOf(TreeRec, tree.gravity), XtRImmediate, (XtPointer) WestGravity }, +#ifndef OLDXAW + { XawNdisplayList, XawCDisplayList, XawRDisplayList, sizeof(XawDisplayList*), + XtOffsetOf(TreeRec, tree.display_list), XtRImmediate, + NULL }, +#endif }; @@ -117,10 +140,10 @@ TreeClassRec treeClassRec = { (WidgetClass) &constraintClassRec, /* superclass */ "Tree", /* class_name */ sizeof(TreeRec), /* widget_size */ - ClassInitialize, /* class_init */ + XawTreeClassInitialize, /* class_init */ NULL, /* class_part_init */ FALSE, /* class_inited */ - Initialize, /* initialize */ + XawTreeInitialize, /* initialize */ NULL, /* initialize_hook */ XtInheritRealize, /* realize */ NULL, /* actions */ @@ -132,10 +155,10 @@ TreeClassRec treeClassRec = { TRUE, /* compress_exposure */ TRUE, /* compress_enterleave*/ TRUE, /* visible_interest */ - Destroy, /* destroy */ + XawTreeDestroy, /* destroy */ NULL, /* resize */ - Redisplay, /* expose */ - SetValues, /* set_values */ + XawTreeRedisplay, /* expose */ + XawTreeSetValues, /* set_values */ NULL, /* set_values_hook */ XtInheritSetValuesAlmost, /* set_values_almost */ NULL, /* get_values_hook */ @@ -143,14 +166,14 @@ TreeClassRec treeClassRec = { XtVersion, /* version */ NULL, /* callback_private */ NULL, /* tm_table */ - QueryGeometry, /* query_geometry */ + XawTreeQueryGeometry, /* query_geometry */ NULL, /* display_accelerator*/ NULL, /* extension */ }, { /* composite_class fields */ - GeometryManager, /* geometry_manager */ - ChangeManaged, /* change_managed */ + XawTreeGeometryManager, /* geometry_manager */ + XawTreeChangeManaged, /* change_managed */ XtInheritInsertChild, /* insert_child */ XtInheritDeleteChild, /* delete_child */ NULL, /* extension */ @@ -160,9 +183,9 @@ TreeClassRec treeClassRec = { treeConstraintResources, /* subresources */ XtNumber(treeConstraintResources), /* subresource_count */ sizeof(TreeConstraintsRec), /* constraint_size */ - ConstraintInitialize, /* initialize */ - ConstraintDestroy, /* destroy */ - ConstraintSetValues, /* set_values */ + XawTreeConstraintInitialize, /* initialize */ + XawTreeConstraintDestroy, /* destroy */ + XawTreeConstraintSetValues, /* set_values */ NULL, /* extension */ }, { @@ -180,10 +203,8 @@ WidgetClass treeWidgetClass = (WidgetClass) &treeClassRec; * * *****************************************************************************/ -static void initialize_dimensions (listp, sizep, n) - Dimension **listp; - int *sizep; - int n; +static void +initialize_dimensions(Dimension **listp, int *sizep, int n) { int i; Dimension *l; @@ -207,8 +228,8 @@ static void initialize_dimensions (listp, sizep, n) return; } -static GC get_tree_gc (w) - TreeWidget w; +static GC +get_tree_gc(TreeWidget w) { XtGCMask valuemask = GCBackground | GCForeground; XGCValues values; @@ -223,8 +244,8 @@ static GC get_tree_gc (w) return XtGetGC ((Widget) w, valuemask, &values); } -static void insert_node (parent, node) - Widget parent, node; +static void +insert_node(Widget parent, Widget node) { TreeConstraints pc; TreeConstraints nc = TREE_CONSTRAINT(node); @@ -257,8 +278,8 @@ static void insert_node (parent, node) pc->tree.n_children++; } -static void delete_node (parent, node) - Widget parent, node; +static void +delete_node(Widget parent, Widget node) { TreeConstraints pc; int pos, i; @@ -293,9 +314,8 @@ static void delete_node (parent, node) pc->tree.children[pc->tree.n_children]=0; } -static void check_gravity (tw, grav) - TreeWidget tw; - XtGravity grav; +static void +check_gravity(TreeWidget tw, XtGravity grav) { switch (tw->tree.gravity) { case WestGravity: case NorthGravity: case EastGravity: case SouthGravity: @@ -313,80 +333,80 @@ static void check_gravity (tw, grav) * * *****************************************************************************/ -static void ClassInitialize () +static void +XawTreeClassInitialize(void) { XawInitializeWidgetSet(); - XtAddConverter (XtRString, XtRGravity, XmuCvtStringToGravity, - (XtConvertArgList) NULL, (Cardinal) 0); + XtAddConverter(XtRString, XtRGravity, XmuCvtStringToGravity, NULL, 0); + XtSetTypeConverter(XtRGravity, XtRString, XmuCvtGravityToString, + NULL, 0, XtCacheNone, NULL); } /*ARGSUSED*/ -static void Initialize (grequest, gnew, args, num_args) - Widget grequest, gnew; - ArgList args; - Cardinal *num_args; +static void +XawTreeInitialize(Widget grequest, Widget gnew, + ArgList args, Cardinal *num_args) { - TreeWidget request = (TreeWidget) grequest, new = (TreeWidget) gnew; + TreeWidget request = (TreeWidget) grequest, cnew = (TreeWidget) gnew; Arg arglist[2]; /* * Make sure the widget's width and height are * greater than zero. */ - if (request->core.width <= 0) new->core.width = 5; - if (request->core.height <= 0) new->core.height = 5; + if (request->core.width <= 0) cnew->core.width = 5; + if (request->core.height <= 0) cnew->core.height = 5; /* * Set the padding according to the orientation */ if (request->tree.hpad == 0 && request->tree.vpad == 0) { if (IsHorizontal (request)) { - new->tree.hpad = TREE_HORIZONTAL_DEFAULT_SPACING; - new->tree.vpad = TREE_VERTICAL_DEFAULT_SPACING; + cnew->tree.hpad = TREE_HORIZONTAL_DEFAULT_SPACING; + cnew->tree.vpad = TREE_VERTICAL_DEFAULT_SPACING; } else { - new->tree.hpad = TREE_VERTICAL_DEFAULT_SPACING; - new->tree.vpad = TREE_HORIZONTAL_DEFAULT_SPACING; + cnew->tree.hpad = TREE_VERTICAL_DEFAULT_SPACING; + cnew->tree.vpad = TREE_HORIZONTAL_DEFAULT_SPACING; } } /* * Create a graphics context for the connecting lines. */ - new->tree.gc = get_tree_gc (new); + cnew->tree.gc = get_tree_gc (cnew); /* * Create the hidden root widget. */ - new->tree.tree_root = (Widget) NULL; + cnew->tree.tree_root = (Widget) NULL; XtSetArg(arglist[0], XtNwidth, 1); XtSetArg(arglist[1], XtNheight, 1); - new->tree.tree_root = XtCreateWidget ("root", widgetClass, gnew, + cnew->tree.tree_root = XtCreateWidget ("root", widgetClass, gnew, arglist,TWO); /* * Allocate the array used to hold the widest values per depth */ - new->tree.largest = NULL; - new->tree.n_largest = 0; - initialize_dimensions (&new->tree.largest, &new->tree.n_largest, + cnew->tree.largest = NULL; + cnew->tree.n_largest = 0; + initialize_dimensions (&cnew->tree.largest, &cnew->tree.n_largest, TREE_INITIAL_DEPTH); /* * make sure that our gravity is one of the acceptable values */ - check_gravity (new, WestGravity); + check_gravity (cnew, WestGravity); } /* ARGSUSED */ -static void ConstraintInitialize (request, new, args, num_args) - Widget request, new; - ArgList args; - Cardinal *num_args; +static void +XawTreeConstraintInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - TreeConstraints tc = TREE_CONSTRAINT(new); - TreeWidget tw = (TreeWidget) new->core.parent; + TreeConstraints tc = TREE_CONSTRAINT(cnew); + TreeWidget tw = (TreeWidget) cnew->core.parent; /* * Initialize the widget to have no sub-nodes. @@ -405,30 +425,29 @@ static void ConstraintInitialize (request, new, args, num_args) * the tree_root widget. */ if (tc->tree.parent) - insert_node (tc->tree.parent, new); + insert_node (tc->tree.parent, cnew); else if (tw->tree.tree_root) - insert_node (tw->tree.tree_root, new); + insert_node (tw->tree.tree_root, cnew); } /* ARGSUSED */ -static Boolean SetValues (gcurrent, grequest, gnew, args, num_args) - Widget gcurrent, grequest, gnew; - ArgList args; - Cardinal *num_args; +static Boolean +XawTreeSetValues(Widget gcurrent, Widget grequest, Widget gnew, + ArgList args, Cardinal *num_args) { - TreeWidget current = (TreeWidget) gcurrent, new = (TreeWidget) gnew; + TreeWidget current = (TreeWidget) gcurrent, cnew = (TreeWidget) gnew; Boolean redraw = FALSE; /* * If the foreground color has changed, redo the GC's * and indicate a redraw. */ - if (new->tree.foreground != current->tree.foreground || - new->core.background_pixel != current->core.background_pixel || - new->tree.line_width != current->tree.line_width) { - XtReleaseGC (gnew, new->tree.gc); - new->tree.gc = get_tree_gc (new); + if (cnew->tree.foreground != current->tree.foreground || + cnew->core.background_pixel != current->core.background_pixel || + cnew->tree.line_width != current->tree.line_width) { + XtReleaseGC (gnew, cnew->tree.gc); + cnew->tree.gc = get_tree_gc (cnew); redraw = TRUE; } @@ -437,22 +456,22 @@ static Boolean SetValues (gcurrent, grequest, gnew, args, num_args) * tree layout. layout_tree() does a redraw, so we don't * need SetValues to do another one. */ - if (new->tree.gravity != current->tree.gravity) { - check_gravity (new, current->tree.gravity); + if (cnew->tree.gravity != current->tree.gravity) { + check_gravity (cnew, current->tree.gravity); } - if (IsHorizontal(new) != IsHorizontal(current)) { - if (new->tree.vpad == current->tree.vpad && - new->tree.hpad == current->tree.hpad) { - new->tree.vpad = current->tree.hpad; - new->tree.hpad = current->tree.vpad; + if (IsHorizontal(cnew) != IsHorizontal(current)) { + if (cnew->tree.vpad == current->tree.vpad && + cnew->tree.hpad == current->tree.hpad) { + cnew->tree.vpad = current->tree.hpad; + cnew->tree.hpad = current->tree.vpad; } } - if (new->tree.vpad != current->tree.vpad || - new->tree.hpad != current->tree.hpad || - new->tree.gravity != current->tree.gravity) { - layout_tree (new, TRUE); + if (cnew->tree.vpad != current->tree.vpad || + cnew->tree.hpad != current->tree.hpad || + cnew->tree.gravity != current->tree.gravity) { + layout_tree (cnew, TRUE); redraw = FALSE; } return redraw; @@ -460,14 +479,13 @@ static Boolean SetValues (gcurrent, grequest, gnew, args, num_args) /* ARGSUSED */ -static Boolean ConstraintSetValues (current, request, new, args, num_args) - Widget current, request, new; - ArgList args; - Cardinal *num_args; +static Boolean +XawTreeConstraintSetValues(Widget current, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - TreeConstraints newc = TREE_CONSTRAINT(new); + TreeConstraints newc = TREE_CONSTRAINT(cnew); TreeConstraints curc = TREE_CONSTRAINT(current); - TreeWidget tw = (TreeWidget) new->core.parent; + TreeWidget tw = (TreeWidget) cnew->core.parent; /* * If the parent field has changed, remove the widget @@ -476,9 +494,9 @@ static Boolean ConstraintSetValues (current, request, new, args, num_args) */ if (curc->tree.parent != newc->tree.parent){ if (curc->tree.parent) - delete_node (curc->tree.parent, new); + delete_node (curc->tree.parent, cnew); if (newc->tree.parent) - insert_node(newc->tree.parent, new); + insert_node(newc->tree.parent, cnew); /* * If the Tree widget has been realized, @@ -491,8 +509,8 @@ static Boolean ConstraintSetValues (current, request, new, args, num_args) } -static void ConstraintDestroy (w) - Widget w; +static void +XawTreeConstraintDestroy(Widget w) { TreeConstraints tc = TREE_CONSTRAINT(w); TreeWidget tw = (TreeWidget) XtParent(w); @@ -518,10 +536,9 @@ static void ConstraintDestroy (w) } /* ARGSUSED */ -static XtGeometryResult GeometryManager (w, request, reply) - Widget w; - XtWidgetGeometry *request; - XtWidgetGeometry *reply; +static XtGeometryResult +XawTreeGeometryManager(Widget w, XtWidgetGeometry *request, + XtWidgetGeometry *reply) { TreeWidget tw = (TreeWidget) w->core.parent; @@ -548,15 +565,15 @@ static XtGeometryResult GeometryManager (w, request, reply) return (XtGeometryYes); } -static void ChangeManaged (gw) - Widget gw; +static void +XawTreeChangeManaged(Widget gw) { layout_tree ((TreeWidget) gw, FALSE); } -static void Destroy (gw) - Widget gw; +static void +XawTreeDestroy(Widget gw) { TreeWidget w = (TreeWidget) gw; @@ -566,18 +583,22 @@ static void Destroy (gw) /* ARGSUSED */ -static void Redisplay (gw, event, region) - Widget gw; - XEvent *event; - Region region; +static void +XawTreeRedisplay(Widget gw, XEvent *event, Region region) { TreeWidget tw = (TreeWidget) gw; +#ifndef OLDXAW + if (tw->tree.display_list) + XawRunDisplayList(gw, tw->tree.display_list, event, region); +#endif + /* * If the Tree widget is visible, visit each managed child. */ if (tw->core.visible) { - int i, j; + Cardinal i; + int j; Display *dpy = XtDisplay (tw); Window w = XtWindow (tw); @@ -663,9 +684,9 @@ static void Redisplay (gw, event, region) } } -static XtGeometryResult QueryGeometry (w, intended, preferred) - Widget w; - XtWidgetGeometry *intended, *preferred; +static XtGeometryResult +XawTreeQueryGeometry(Widget w, XtWidgetGeometry *intended, + XtWidgetGeometry *preferred) { TreeWidget tw = (TreeWidget) w; @@ -697,10 +718,8 @@ static XtGeometryResult QueryGeometry (w, intended, preferred) * * *****************************************************************************/ -static void compute_bounding_box_subtree (tree, w, depth) - TreeWidget tree; - Widget w; - int depth; +static void +compute_bounding_box_subtree(TreeWidget tree, Widget w, int depth) { TreeConstraints tc = TREE_CONSTRAINT(w); /* info attached to all kids */ int i; @@ -770,10 +789,8 @@ static void compute_bounding_box_subtree (tree, w, depth) } -static void set_positions (tw, w, level) - TreeWidget tw; - Widget w; - int level; +static void +set_positions(TreeWidget tw, Widget w, int level) { int i; @@ -811,11 +828,8 @@ static void set_positions (tw, w, level) } -static void arrange_subtree (tree, w, depth, x, y) - TreeWidget tree; - Widget w; - int depth; - Position x, y; +static void +arrange_subtree(TreeWidget tree, Widget w, int depth, int x, int y) { TreeConstraints tc = TREE_CONSTRAINT(w); /* info attached to all kids */ TreeConstraints firstcc, lastcc; @@ -918,10 +932,9 @@ static void arrange_subtree (tree, w, depth, x, y) } } -static void set_tree_size (tw, insetvalues, width, height) - TreeWidget tw; - Boolean insetvalues; - Dimension width, height; +static void +set_tree_size(TreeWidget tw, Bool insetvalues, + unsigned int width, unsigned int height) { if (insetvalues) { tw->core.width = width; @@ -942,9 +955,8 @@ static void set_tree_size (tw, insetvalues, width, height) return; } -static void layout_tree (tw, insetvalues) - TreeWidget tw; - Boolean insetvalues; +static void +layout_tree(TreeWidget tw, Bool insetvalues) { int i; Dimension *dp; @@ -995,12 +1007,7 @@ static void layout_tree (tw, insetvalues) *****************************************************************************/ void -#if NeedFunctionPrototypes -XawTreeForceLayout (Widget tree) -#else -XawTreeForceLayout (tree) - Widget tree; -#endif +XawTreeForceLayout(Widget tree) { layout_tree ((TreeWidget) tree, FALSE); } diff --git a/src/Vendor.c b/src/Vendor.c index 17cd17b..b2fbd33 100644 --- a/src/Vendor.c +++ b/src/Vendor.c @@ -46,6 +46,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/Vendor.c,v 1.9 2002/05/31 18:45:44 dawes Exp $ */ /* * This is a copy of Xt/Vendor.c with an additional ClassInitialize @@ -71,6 +72,32 @@ SOFTWARE. #include <X11/Xaw/VendorEP.h> #include <X11/Xaw/XawImP.h> +/* + * Class Methods + */ +static void XawVendorShellChangeManaged(Widget); +static Boolean XawCvtCompoundTextToString(Display*, XrmValuePtr, Cardinal*, + XrmValue*, XrmValue*, XtPointer*); +static void XawVendorShellClassInitialize(void); +static XtGeometryResult XawVendorShellGeometryManager(Widget, + XtWidgetGeometry*, + XtWidgetGeometry*); +static void XawVendorShellExtClassInitialize(void); +static void XawVendorShellExtDestroy(Widget); +static void XawVendorShellExtInitialize(Widget, Widget, ArgList, Cardinal*); +void XawVendorShellExtResize(Widget); +static Boolean XawVendorShellExtSetValues(Widget, Widget, Widget, + ArgList, Cardinal*); +static void XawVendorShellClassPartInit(WidgetClass); +static void XawVendorShellInitialize(Widget, Widget, ArgList, Cardinal*); +static void XawVendorShellRealize(Widget, Mask*, XSetWindowAttributes*); +static Boolean XawVendorShellSetValues(Widget, Widget, Widget, + ArgList, Cardinal*); + +/* + * External + */ +void XawVendorStructureNotifyHandler(Widget, XtPointer, XEvent*, Boolean*); static XtResource resources[] = { {XtNinput, XtCInput, XtRBool, sizeof(Bool), @@ -84,13 +111,28 @@ static XtResource resources[] = { * ***************************************************************************/ -static void XawVendorShellClassInitialize(); -static void XawVendorShellClassPartInit(); -static void XawVendorShellInitialize(); -static Boolean XawVendorShellSetValues(); -static void Realize(), ChangeManaged(); -static XtGeometryResult GeometryManager(); -void XawVendorShellExtResize(); +#ifdef __UNIXOS2__ +/* to fix the EditRes problem because of wrong linker semantics */ +extern WidgetClass vendorShellWidgetClass; /* from Xt/Vendor.c */ +extern VendorShellClassRec _XawVendorShellClassRec; +extern void _XawFixupVendorShell(); +unsigned long _DLL_InitTerm(unsigned long mod,unsigned long flag) +{ + switch (flag) { + case 0: /*called on init*/ + _CRT_init(); + vendorShellWidgetClass = (WidgetClass)(&_XawVendorShellClassRec); + _XawFixupVendorShell(); + return 1; + case 1: /*called on exit*/ + return 1; + default: + return 0; + } +} +#define vendorShellClassRec _XawVendorShellClassRec + +#endif static CompositeClassExtensionRec vendorCompositeExt = { /* next_extension */ NULL, @@ -112,7 +154,7 @@ externaldef(vendorshellclassrec) VendorShellClassRec vendorShellClassRec = { /* Class init'ed ? */ FALSE, /* initialize */ XawVendorShellInitialize, /* initialize_hook */ NULL, - /* realize */ Realize, + /* realize */ XawVendorShellRealize, /* actions */ NULL, /* num_actions */ 0, /* resources */ resources, @@ -137,8 +179,8 @@ externaldef(vendorshellclassrec) VendorShellClassRec vendorShellClassRec = { /* display_accelerator*/ NULL, /* extension */ NULL },{ - /* geometry_manager */ GeometryManager, - /* change_managed */ ChangeManaged, + /* geometry_manager */ XawVendorShellGeometryManager, + /* change_managed */ XawVendorShellChangeManaged, /* insert_child */ XtInheritInsertChild, /* delete_child */ XtInheritDeleteChild, /* extension */ (XtPointer) &vendorCompositeExt @@ -151,9 +193,10 @@ externaldef(vendorshellclassrec) VendorShellClassRec vendorShellClassRec = { } }; +#ifndef __UNIXOS2__ externaldef(vendorshellwidgetclass) WidgetClass vendorShellWidgetClass = (WidgetClass) (&vendorShellClassRec); - +#endif /*************************************************************************** * @@ -176,11 +219,6 @@ static XtResource ext_resources[] = { XtRImmediate, (XtPointer)FALSE} }; -static void XawVendorShellExtClassInitialize(); -static void XawVendorShellExtInitialize(); -static void XawVendorShellExtDestroy(); -static Boolean XawVendorShellExtSetValues(); - externaldef(vendorshellextclassrec) XawVendorShellExtClassRec xawvendorShellExtClassRec = { { @@ -227,13 +265,9 @@ externaldef(xawvendorshellwidgetclass) WidgetClass /*ARGSUSED*/ static Boolean -XawCvtCompoundTextToString(dpy, args, num_args, fromVal, toVal, cvt_data) -Display *dpy; -XrmValuePtr args; -Cardinal *num_args; -XrmValue *fromVal; -XrmValue *toVal; -XtPointer *cvt_data; +XawCvtCompoundTextToString(Display *dpy, XrmValuePtr args, Cardinal *num_args, + XrmValue *fromVal, XrmValue *toVal, + XtPointer *cvt_data) { XTextProperty prop; char **list; @@ -261,7 +295,8 @@ XtPointer *cvt_data; return True; } -static void XawVendorShellClassInitialize() +static void +XawVendorShellClassInitialize(void) { static XtConvertArgRec screenConvertArg[] = { {XtWidgetBaseOffset, (XtPointer) XtOffsetOf(WidgetRec, core.screen), @@ -278,14 +313,14 @@ static void XawVendorShellClassInitialize() NULL, 0, XtCacheNone, NULL); } -static void XawVendorShellClassPartInit(class) - WidgetClass class; +static void +XawVendorShellClassPartInit(WidgetClass cclass) { CompositeClassExtension ext; - VendorShellWidgetClass vsclass = (VendorShellWidgetClass) class; + VendorShellWidgetClass vsclass = (VendorShellWidgetClass)cclass; if ((ext = (CompositeClassExtension) - XtGetClassExtension (class, + XtGetClassExtension (cclass, XtOffsetOf(CompositeClassRec, composite_class.extension), NULLQUARK, 1L, (Cardinal) 0)) == NULL) { @@ -302,7 +337,7 @@ static void XawVendorShellClassPartInit(class) } } -#ifdef __osf__ +#if defined(__osf__) || defined(__UNIXOS2__) /* stupid OSF/1 shared libraries have the wrong semantics */ /* symbols do not get resolved external to the shared library */ void _XawFixupVendorShell() @@ -315,28 +350,26 @@ void _XawFixupVendorShell() #endif /* ARGSUSED */ -static void XawVendorShellInitialize(req, new, args, num_args) - Widget req, new; - ArgList args; - Cardinal *num_args; +static void +XawVendorShellInitialize(Widget req, Widget cnew, + ArgList args, Cardinal *num_args) { - XtAddEventHandler(new, (EventMask) 0, TRUE, _XEditResCheckMessages, NULL); - XtAddEventHandler(new, (EventMask) 0, TRUE, XmuRegisterExternalAgent, NULL); + XtAddEventHandler(cnew, (EventMask) 0, TRUE, _XEditResCheckMessages, NULL); + XtAddEventHandler(cnew, (EventMask) 0, TRUE, XmuRegisterExternalAgent, NULL); XtCreateWidget("shellext", xawvendorShellExtWidgetClass, - new, args, *num_args); + cnew, args, *num_args); } /* ARGSUSED */ -static Boolean XawVendorShellSetValues(old, ref, new) - Widget old, ref, new; +static Boolean +XawVendorShellSetValues(Widget old, Widget ref, Widget cnew, + ArgList args, Cardinal *num_args) { return FALSE; } -static void Realize(wid, vmask, attr) - Widget wid; - Mask *vmask; - XSetWindowAttributes *attr; +static void +XawVendorShellRealize(Widget wid, Mask *vmask, XSetWindowAttributes *attr) { WidgetClass super = wmShellWidgetClass; @@ -347,37 +380,40 @@ static void Realize(wid, vmask, attr) } -static void XawVendorShellExtClassInitialize() +static void +XawVendorShellExtClassInitialize(void) { } /* ARGSUSED */ -static void XawVendorShellExtInitialize(req, new) - Widget req, new; +static void +XawVendorShellExtInitialize(Widget req, Widget cnew, + ArgList args, Cardinal *num_args) { - _XawImInitialize(new->core.parent, new); + _XawImInitialize(cnew->core.parent, cnew); } /* ARGSUSED */ -static void XawVendorShellExtDestroy( w ) - Widget w; +static void +XawVendorShellExtDestroy(Widget w) { _XawImDestroy( w->core.parent, w ); } /* ARGSUSED */ -static Boolean XawVendorShellExtSetValues(old, ref, new) - Widget old, ref, new; +static Boolean +XawVendorShellExtSetValues(Widget old, Widget ref, Widget cnew, + ArgList args, Cardinal *num_args) { return FALSE; } -void XawVendorShellExtResize( w ) - Widget w; +void +XawVendorShellExtResize(Widget w) { ShellWidget sw = (ShellWidget) w; Widget childwid; - int i; + Cardinal i; int core_height; _XawImResizeVendorShell( w ); @@ -392,10 +428,17 @@ void XawVendorShellExtResize( w ) } /*ARGSUSED*/ -static XtGeometryResult GeometryManager( wid, request, reply ) - Widget wid; - XtWidgetGeometry *request; - XtWidgetGeometry *reply; +void +XawVendorStructureNotifyHandler(Widget w, XtPointer closure, XEvent *event, + Boolean *continue_to_dispatch) +{ + XawVendorShellExtResize(w); +} + +/*ARGSUSED*/ +static XtGeometryResult +XawVendorShellGeometryManager(Widget wid, XtWidgetGeometry *request, + XtWidgetGeometry *reply) { ShellWidget shell = (ShellWidget)(wid->core.parent); XtWidgetGeometry my_request; @@ -442,8 +485,8 @@ static XtGeometryResult GeometryManager( wid, request, reply ) } else return XtGeometryNo; } -static void ChangeManaged(wid) - Widget wid; +static void +XawVendorShellChangeManaged(Widget wid) { ShellWidget w = (ShellWidget) wid; Widget* childP; diff --git a/src/Viewport.c b/src/Viewport.c index 02182e0..eafc00c 100644 --- a/src/Viewport.c +++ b/src/Viewport.c @@ -46,141 +46,223 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/Viewport.c,v 1.11 2001/12/14 19:54:45 dawes Exp $ */ #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> - -#include <X11/Xaw/XawInit.h> #include <X11/Xmu/Misc.h> #include <X11/Xaw/Scrollbar.h> #include <X11/Xaw/ViewportP.h> +#include <X11/Xaw/XawInit.h> +#include "Private.h" -static void ScrollUpDownProc(), ThumbProc(); -static Boolean GetGeometry(); +/* + * Class Methods + */ +static Boolean Layout(FormWidget, unsigned int, unsigned int, Bool); +static void XawViewportChangeManaged(Widget); +static void XawViewportInitialize(Widget, Widget, ArgList, Cardinal*); +static void +XawViewportConstraintInitialize(Widget, Widget, ArgList, Cardinal*); +static XtGeometryResult XawViewportGeometryManager(Widget, XtWidgetGeometry*, + XtWidgetGeometry*); +static XtGeometryResult XawViewportQueryGeometry(Widget, + XtWidgetGeometry*, + XtWidgetGeometry*); +static void XawViewportRealize(Widget, XtValueMask*, XSetWindowAttributes*); +static void XawViewportResize(Widget); +static Boolean XawViewportSetValues(Widget, Widget, Widget, + ArgList, Cardinal*); -static void ComputeWithForceBars(); +/* + * Prototypes + */ +static void ComputeLayout(Widget, Bool, Bool); +static void ComputeWithForceBars(Widget, Bool, XtWidgetGeometry*, + int*, int*); +static Widget CreateScrollbar(ViewportWidget, Bool); +static XtGeometryResult GeometryRequestPlusScrollbar(ViewportWidget, Bool, + XtWidgetGeometry*, + XtWidgetGeometry*); +static Bool GetGeometry(Widget, unsigned int, unsigned int); +static void MoveChild(ViewportWidget, int, int); +static XtGeometryResult QueryGeometry(ViewportWidget, XtWidgetGeometry*, + XtWidgetGeometry*); +static void RedrawThumbs(ViewportWidget); +static void ScrollUpDownProc(Widget, XtPointer, XtPointer); +static void SendReport(ViewportWidget, unsigned int); +static void SetBar(Widget, int, unsigned int, unsigned int); +static XtGeometryResult TestSmaller(ViewportWidget, XtWidgetGeometry*, + XtWidgetGeometry*); +static void ThumbProc(Widget, XtPointer, XtPointer); +/* + * Initialization + */ #define offset(field) XtOffsetOf(ViewportRec, viewport.field) static XtResource resources[] = { - {XtNforceBars, XtCBoolean, XtRBoolean, sizeof(Boolean), - offset(forcebars), XtRImmediate, (XtPointer)False}, - {XtNallowHoriz, XtCBoolean, XtRBoolean, sizeof(Boolean), - offset(allowhoriz), XtRImmediate, (XtPointer)False}, - {XtNallowVert, XtCBoolean, XtRBoolean, sizeof(Boolean), - offset(allowvert), XtRImmediate, (XtPointer)False}, - {XtNuseBottom, XtCBoolean, XtRBoolean, sizeof(Boolean), - offset(usebottom), XtRImmediate, (XtPointer)False}, - {XtNuseRight, XtCBoolean, XtRBoolean, sizeof(Boolean), - offset(useright), XtRImmediate, (XtPointer)False}, - {XtNreportCallback, XtCReportCallback, XtRCallback, sizeof(XtPointer), - offset(report_callbacks), XtRImmediate, (XtPointer) NULL}, + { + XtNforceBars, + XtCBoolean, + XtRBoolean, + sizeof(Boolean), + offset(forcebars), + XtRImmediate, + (XtPointer)False + }, + { + XtNallowHoriz, + XtCBoolean, + XtRBoolean, + sizeof(Boolean), + offset(allowhoriz), + XtRImmediate, + (XtPointer)False + }, + { + XtNallowVert, + XtCBoolean, + XtRBoolean, + sizeof(Boolean), + offset(allowvert), + XtRImmediate, + (XtPointer)False + }, + { + XtNuseBottom, + XtCBoolean, + XtRBoolean, + sizeof(Boolean), + offset(usebottom), + XtRImmediate, + (XtPointer)False + }, + { + XtNuseRight, + XtCBoolean, + XtRBoolean, + sizeof(Boolean), + offset(useright), + XtRImmediate, + (XtPointer)False + }, + { + XtNreportCallback, + XtCReportCallback, + XtRCallback, + sizeof(XtPointer), + offset(report_callbacks), + XtRImmediate, + NULL + }, }; #undef offset -static void Initialize(), ConstraintInitialize(), - Realize(), Resize(), ChangeManaged(); -static Boolean SetValues(), Layout(); -static XtGeometryResult GeometryManager(), PreferredGeometry(); - -#define superclass (&formClassRec) +#define Superclass (&formClassRec) ViewportClassRec viewportClassRec = { - { /* core_class fields */ - /* superclass */ (WidgetClass) superclass, - /* class_name */ "Viewport", - /* widget_size */ sizeof(ViewportRec), - /* class_initialize */ XawInitializeWidgetSet, - /* class_part_init */ NULL, - /* class_inited */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* realize */ Realize, - /* actions */ NULL, - /* num_actions */ 0, - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure */ TRUE, - /* compress_enterleave*/ TRUE, - /* visible_interest */ FALSE, - /* destroy */ NULL, - /* resize */ Resize, - /* expose */ XtInheritExpose, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* set_values_almost */ XtInheritSetValuesAlmost, - /* get_values_hook */ NULL, - /* accept_focus */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ NULL, - /* query_geometry */ PreferredGeometry, - /* display_accelerator*/ XtInheritDisplayAccelerator, - /* extension */ NULL + /* core */ + { + (WidgetClass)Superclass, /* superclass */ + "Viewport", /* class_name */ + sizeof(ViewportRec), /* widget_size */ + XawInitializeWidgetSet, /* class_initialize */ + NULL, /* class_part_init */ + False, /* class_inited */ + XawViewportInitialize, /* initialize */ + NULL, /* initialize_hook */ + XawViewportRealize, /* realize */ + NULL, /* actions */ + 0, /* num_actions */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + True, /* compress_motion */ + True, /* compress_exposure */ + True, /* compress_enterleave */ + False, /* visible_interest */ + NULL, /* destroy */ + XawViewportResize, /* resize */ + XtInheritExpose, /* expose */ + XawViewportSetValues, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + NULL, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + NULL, /* tm_table */ + XawViewportQueryGeometry, /* query_geometry */ + XtInheritDisplayAccelerator, /* display_accelerator */ + NULL, /* extension */ }, - { /* composite_class fields */ - /* geometry_manager */ GeometryManager, - /* change_managed */ ChangeManaged, - /* insert_child */ XtInheritInsertChild, - /* delete_child */ XtInheritDeleteChild, - /* extension */ NULL + /* composite */ + { + XawViewportGeometryManager, /* geometry_manager */ + XawViewportChangeManaged, /* change_managed */ + XtInheritInsertChild, /* insert_child */ + XtInheritDeleteChild, /* delete_child */ + NULL, /* extension */ }, - { /* constraint_class fields */ - /* subresourses */ NULL, - /* subresource_count */ 0, - /* constraint_size */ sizeof(ViewportConstraintsRec), - /* initialize */ ConstraintInitialize, - /* destroy */ NULL, - /* set_values */ NULL, - /* extension */ NULL + /* constraint */ + { + NULL, /* subresourses */ + 0, /* subresource_count */ + sizeof(ViewportConstraintsRec), /* constraint_size */ + XawViewportConstraintInitialize, /* initialize */ + NULL, /* destroy */ + NULL, /* set_values */ + NULL, /* extension */ }, - { /* form_class fields */ - /* layout */ Layout + /* form */ + { + Layout, /* layout */ + }, + /* viewport */ + { + NULL, /* extension */ }, - { /* viewport_class fields */ - /* empty */ 0 - } }; - WidgetClass viewportWidgetClass = (WidgetClass)&viewportClassRec; -static Widget CreateScrollbar(w, horizontal) - ViewportWidget w; - Boolean horizontal; +/* + * Implementation + */ +static Widget +CreateScrollbar(ViewportWidget w, Bool horizontal) { + static Arg barArgs[] = { + {XtNorientation, 0}, + {XtNlength, 0}, + {XtNleft, 0}, + {XtNright, 0}, + {XtNtop, 0}, + {XtNbottom, 0}, + {XtNmappedWhenManaged, False}, + }; Widget clip = w->viewport.clip; ViewportConstraints constraints = (ViewportConstraints)clip->core.constraints; - static Arg barArgs[] = { - {XtNorientation, (XtArgVal) 0}, - {XtNlength, (XtArgVal) 0}, - {XtNleft, (XtArgVal) 0}, - {XtNright, (XtArgVal) 0}, - {XtNtop, (XtArgVal) 0}, - {XtNbottom, (XtArgVal) 0}, - {XtNmappedWhenManaged, (XtArgVal) False}, - }; Widget bar; XtSetArg(barArgs[0], XtNorientation, - horizontal ? XtorientHorizontal : XtorientVertical ); + horizontal ? XtorientHorizontal : XtorientVertical); XtSetArg(barArgs[1], XtNlength, - horizontal ? clip->core.width : clip->core.height); + horizontal ? XtWidth(clip) : XtHeight(clip)); XtSetArg(barArgs[2], XtNleft, - (!horizontal && w->viewport.useright) ? XtChainRight : XtChainLeft); + !horizontal && w->viewport.useright ? XtChainRight : XtChainLeft); XtSetArg(barArgs[3], XtNright, - (!horizontal && !w->viewport.useright) ? XtChainLeft : XtChainRight); + !horizontal && !w->viewport.useright ? XtChainLeft : XtChainRight); XtSetArg(barArgs[4], XtNtop, - (horizontal && w->viewport.usebottom) ? XtChainBottom: XtChainTop); + horizontal && w->viewport.usebottom ? XtChainBottom: XtChainTop); XtSetArg(barArgs[5], XtNbottom, - (horizontal && !w->viewport.usebottom) ? XtChainTop: XtChainBottom); + horizontal && !w->viewport.usebottom ? XtChainTop: XtChainBottom); - bar = XtCreateWidget((horizontal ? "horizontal" : "vertical"), - scrollbarWidgetClass, (Widget)w, - barArgs, XtNumber(barArgs) ); - XtAddCallback( bar, XtNscrollProc, ScrollUpDownProc, (XtPointer)w ); - XtAddCallback( bar, XtNjumpProc, ThumbProc, (XtPointer)w ); + bar = XtCreateWidget(horizontal ? "horizontal" : "vertical", + scrollbarWidgetClass, (Widget)w, + barArgs, XtNumber(barArgs)); + XtAddCallback(bar, XtNscrollProc, ScrollUpDownProc, (XtPointer)w); + XtAddCallback(bar, XtNjumpProc, ThumbProc, (XtPointer)w); if (horizontal) { w->viewport.horiz_bar = bar; @@ -191,77 +273,68 @@ static Widget CreateScrollbar(w, horizontal) constraints->form.horiz_base = bar; } - XtManageChild( bar ); + XtManageChild(bar); - return bar; + return (bar); } -/* ARGSUSED */ -static void Initialize(request, new, args, num_args) - Widget request, new; - ArgList args; - Cardinal *num_args; +/*ARGSUSED*/ +static void +XawViewportInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - ViewportWidget w = (ViewportWidget)new; + ViewportWidget w = (ViewportWidget)cnew; static Arg clip_args[8]; Cardinal arg_cnt; Widget h_bar, v_bar; Dimension clip_height, clip_width; - w->form.default_spacing = 0; /* Reset the default spacing to 0 pixels. */ + w->form.default_spacing = 0; /* Reset the default spacing to 0 pixels */ + /* + * Initialize all widget pointers to NULL + */ + w->viewport.child = NULL; + w->viewport.horiz_bar = w->viewport.vert_bar = NULL; -/* - * Initialize all widget pointers to NULL. - */ - - w->viewport.child = (Widget) NULL; - w->viewport.horiz_bar = w->viewport.vert_bar = (Widget)NULL; - -/* - * Create Clip Widget. - */ - + /* + * Create Clip Widget + */ arg_cnt = 0; - XtSetArg(clip_args[arg_cnt], XtNbackgroundPixmap, None); arg_cnt++; - XtSetArg(clip_args[arg_cnt], XtNborderWidth, 0); arg_cnt++; - XtSetArg(clip_args[arg_cnt], XtNleft, XtChainLeft); arg_cnt++; - XtSetArg(clip_args[arg_cnt], XtNright, XtChainRight); arg_cnt++; - XtSetArg(clip_args[arg_cnt], XtNtop, XtChainTop); arg_cnt++; - XtSetArg(clip_args[arg_cnt], XtNbottom, XtChainBottom); arg_cnt++; - XtSetArg(clip_args[arg_cnt], XtNwidth, w->core.width); arg_cnt++; - XtSetArg(clip_args[arg_cnt], XtNheight, w->core.height); arg_cnt++; - - w->viewport.clip = XtCreateManagedWidget("clip", widgetClass, new, + XtSetArg(clip_args[arg_cnt], XtNbackgroundPixmap, None); arg_cnt++; + XtSetArg(clip_args[arg_cnt], XtNborderWidth, 0); arg_cnt++; + XtSetArg(clip_args[arg_cnt], XtNleft, XtChainLeft); arg_cnt++; + XtSetArg(clip_args[arg_cnt], XtNright, XtChainRight); arg_cnt++; + XtSetArg(clip_args[arg_cnt], XtNtop, XtChainTop); arg_cnt++; + XtSetArg(clip_args[arg_cnt], XtNbottom, XtChainBottom); arg_cnt++; + XtSetArg(clip_args[arg_cnt], XtNwidth, XtWidth(w)); arg_cnt++; + XtSetArg(clip_args[arg_cnt], XtNheight, XtHeight(w)); arg_cnt++; + + w->viewport.clip = XtCreateManagedWidget("clip", widgetClass, cnew, clip_args, arg_cnt); if (!w->viewport.forcebars) - return; /* If we are not forcing the bars then we are done. */ + return; /* If we are not forcing the bars then we are done */ if (w->viewport.allowhoriz) - (void) CreateScrollbar(w, True); + (void)CreateScrollbar(w, True); if (w->viewport.allowvert) - (void) CreateScrollbar(w, False); + (void)CreateScrollbar(w, False); h_bar = w->viewport.horiz_bar; v_bar = w->viewport.vert_bar; -/* - * Set the clip widget to the correct height. - */ + /* + * Set the clip widget to the correct height + */ + clip_width = XtWidth(w); + clip_height = XtHeight(w); - clip_width = w->core.width; - clip_height = w->core.height; + if (h_bar != NULL && XtWidth(w) > XtWidth(h_bar) + XtBorderWidth(h_bar)) + clip_width -= XtWidth(h_bar) + XtBorderWidth(h_bar); - if ( (h_bar != NULL) && - ((int)w->core.width > - (int)(h_bar->core.width + h_bar->core.border_width)) ) - clip_width -= h_bar->core.width + h_bar->core.border_width; - - if ( (v_bar != NULL) && - ((int)w->core.height > - (int)(v_bar->core.height + v_bar->core.border_width)) ) - clip_height -= v_bar->core.height + v_bar->core.border_width; + if (v_bar != NULL && XtHeight(w) > XtHeight(v_bar) + XtBorderWidth(v_bar)) + clip_height -= XtHeight(v_bar) + XtBorderWidth(v_bar); arg_cnt = 0; XtSetArg(clip_args[arg_cnt], XtNwidth, clip_width); arg_cnt++; @@ -269,19 +342,17 @@ static void Initialize(request, new, args, num_args) XtSetValues(w->viewport.clip, clip_args, arg_cnt); } -/* ARGSUSED */ -static void ConstraintInitialize(request, new, args, num_args) - Widget request, new; - ArgList args; - Cardinal *num_args; +/*ARGSUSED*/ +static void +XawViewportConstraintInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - ((ViewportConstraints)new->core.constraints)->viewport.reparented = False; + ((ViewportConstraints)cnew->core.constraints)->viewport.reparented = False; } -static void Realize(widget, value_mask, attributes) - Widget widget; - XtValueMask *value_mask; - XSetWindowAttributes *attributes; +static void +XawViewportRealize(Widget widget, XtValueMask *value_mask, + XSetWindowAttributes *attributes) { ViewportWidget w = (ViewportWidget)widget; Widget child = w->viewport.child; @@ -289,57 +360,53 @@ static void Realize(widget, value_mask, attributes) *value_mask |= CWBitGravity; attributes->bit_gravity = NorthWestGravity; - (*superclass->core_class.realize)(widget, value_mask, attributes); + (*Superclass->core_class.realize)(widget, value_mask, attributes); (*w->core.widget_class->core_class.resize)(widget); /* turn on bars */ - if (child != (Widget)NULL) { - XtMoveWidget( child, (Position)0, (Position)0 ); - XtRealizeWidget( clip ); - XtRealizeWidget( child ); - XReparentWindow( XtDisplay(w), XtWindow(child), XtWindow(clip), - (Position)0, (Position)0 ); - XtMapWidget( child ); + if (child != NULL) { + XtMoveWidget(child, 0, 0); + XtRealizeWidget(clip); + XtRealizeWidget(child); + XReparentWindow(XtDisplay(w), XtWindow(child), XtWindow(clip), 0, 0); + XtMapWidget(child); } } -/* ARGSUSED */ -static Boolean SetValues(current, request, new, args, num_args) - Widget current, request, new; - ArgList args; - Cardinal *num_args; +/*ARGSUSED*/ +static Boolean +XawViewportSetValues(Widget current, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - ViewportWidget w = (ViewportWidget)new; + ViewportWidget w = (ViewportWidget)cnew; ViewportWidget cw = (ViewportWidget)current; - if ( (w->viewport.forcebars != cw->viewport.forcebars) || - (w->viewport.allowvert != cw->viewport.allowvert) || - (w->viewport.allowhoriz != cw->viewport.allowhoriz) || - (w->viewport.useright != cw->viewport.useright) || - (w->viewport.usebottom != cw->viewport.usebottom) ) - { - (*w->core.widget_class->core_class.resize)(new); /* Recompute layout.*/ - } + if (w->viewport.forcebars != cw->viewport.forcebars + || w->viewport.allowvert != cw->viewport.allowvert + || w->viewport.allowhoriz != cw->viewport.allowhoriz + || w->viewport.useright != cw->viewport.useright + || w->viewport.usebottom != cw->viewport.usebottom) + (*w->core.widget_class->core_class.resize)(cnew); /* Recompute layout */ - return False; + return (False); } - -static void ChangeManaged(widget) - Widget widget; +static void +XawViewportChangeManaged(Widget widget) { ViewportWidget w = (ViewportWidget)widget; int num_children = w->composite.num_children; Widget child, *childP; int i; - child = (Widget)NULL; - for (childP=w->composite.children, i=0; i < num_children; childP++, i++) { + child = NULL; + for (childP = w->composite.children, + i = 0; i < num_children; + childP++, i++) { if (XtIsManaged(*childP) && *childP != w->viewport.clip && *childP != w->viewport.horiz_bar - && *childP != w->viewport.vert_bar) - { + && *childP != w->viewport.vert_bar) { child = *childP; break; } @@ -347,81 +414,63 @@ static void ChangeManaged(widget) if (child != w->viewport.child) { w->viewport.child = child; - if (child != (Widget)NULL) { - XtResizeWidget( child, child->core.width, - child->core.height, (Dimension)0 ); + if (child != NULL) { + XtResizeWidget(child, XtWidth(child), XtHeight(child), 0); if (XtIsRealized(widget)) { ViewportConstraints constraints = (ViewportConstraints)child->core.constraints; if (!XtIsRealized(child)) { Window window = XtWindow(w); - XtMoveWidget( child, (Position)0, (Position)0 ); -#ifdef notdef - /* this is dirty, but it saves the following code: */ - XtRealizeWidget( child ); - XReparentWindow( XtDisplay(w), XtWindow(child), - XtWindow(w->viewport.clip), - (Position)0, (Position)0 ); - if (child->core.mapped_when_managed) - XtMapWidget( child ); -#else + + XtMoveWidget(child, 0, 0); w->core.window = XtWindow(w->viewport.clip); - XtRealizeWidget( child ); + XtRealizeWidget(child); w->core.window = window; -#endif /* notdef */ constraints->viewport.reparented = True; } else if (!constraints->viewport.reparented) { - XReparentWindow( XtDisplay(w), XtWindow(child), - XtWindow(w->viewport.clip), - (Position)0, (Position)0 ); + XReparentWindow(XtDisplay(w), XtWindow(child), + XtWindow(w->viewport.clip), 0, 0); constraints->viewport.reparented = True; if (child->core.mapped_when_managed) - XtMapWidget( child ); + XtMapWidget(child); } } - GetGeometry( widget, child->core.width, child->core.height ); + GetGeometry(widget, XtWidth(child), XtHeight(child)); (*((ViewportWidgetClass)w->core.widget_class)->form_class.layout) - ( (FormWidget)w, w->core.width, w->core.height ); - /* %%% do we need to hide this child from Form? */ + ((FormWidget)w, XtWidth(w), XtHeight(w), True /* True? */); } } #ifdef notdef - (*superclass->composite_class.change_managed)( widget ); + (*Superclass->composite_class.change_managed)(widget); #endif } - -static void SetBar(w, top, length, total) - Widget w; - Position top; - Dimension length, total; +static void +SetBar(Widget w, int top, unsigned int length, unsigned int total) { - XawScrollbarSetThumb(w, (float)top/(float)total, - (float)length/(float)total); + XawScrollbarSetThumb(w, (float)top / (float)total, + (float)length / (float)total); } -static void RedrawThumbs(w) - ViewportWidget w; +static void +RedrawThumbs(ViewportWidget w) { Widget child = w->viewport.child; Widget clip = w->viewport.clip; - if (w->viewport.horiz_bar != (Widget)NULL) - SetBar( w->viewport.horiz_bar, -(child->core.x), - clip->core.width, child->core.width ); + if (w->viewport.horiz_bar != NULL) + SetBar(w->viewport.horiz_bar, -(int)XtX(child), + XtWidth(clip), XtWidth(child)); - if (w->viewport.vert_bar != (Widget)NULL) - SetBar( w->viewport.vert_bar, -(child->core.y), - clip->core.height, child->core.height ); + if (w->viewport.vert_bar != NULL) + SetBar(w->viewport.vert_bar, -(int)XtY(child), + XtHeight(clip), XtHeight(child)); } - - -static void SendReport (w, changed) - ViewportWidget w; - unsigned int changed; +static void +SendReport(ViewportWidget w, unsigned int changed) { XawPannerReport rep; @@ -430,72 +479,70 @@ static void SendReport (w, changed) Widget clip = w->viewport.clip; rep.changed = changed; - rep.slider_x = -child->core.x; /* child is canvas */ - rep.slider_y = -child->core.y; /* clip is slider */ - rep.slider_width = clip->core.width; - rep.slider_height = clip->core.height; - rep.canvas_width = child->core.width; - rep.canvas_height = child->core.height; - XtCallCallbackList ((Widget) w, w->viewport.report_callbacks, - (XtPointer) &rep); + rep.slider_x = -XtX(child); /* child is canvas */ + rep.slider_y = -XtY(child); /* clip is slider */ + rep.slider_width = XtWidth(clip); + rep.slider_height = XtHeight(clip); + rep.canvas_width = XtWidth(child); + rep.canvas_height = XtHeight(child); + XtCallCallbackList((Widget)w, w->viewport.report_callbacks, + (XtPointer)&rep); } } - -static void MoveChild(w, x, y) - ViewportWidget w; - Position x, y; +static void +MoveChild(ViewportWidget w, int x, int y) { Widget child = w->viewport.child; Widget clip = w->viewport.clip; /* make sure we never move past right/bottom borders */ - if (-x + (int)clip->core.width > (int)child->core.width) - x = -(child->core.width - clip->core.width); + if (-x + (int)XtWidth(clip) > XtWidth(child)) + x = -(int)(XtWidth(child) - XtWidth(clip)); - if (-y + (int)clip->core.height > (int)child->core.height) - y = -(child->core.height - clip->core.height); + if (-y + (int)XtHeight(clip) > XtHeight(child)) + y = -(int)(XtHeight(child) - XtHeight(clip)); /* make sure we never move past left/top borders */ - if (x >= 0) x = 0; - if (y >= 0) y = 0; + if (x >= 0) + x = 0; + if (y >= 0) + y = 0; XtMoveWidget(child, x, y); - SendReport (w, (XawPRSliderX | XawPRSliderY)); + SendReport(w, (XawPRSliderX | XawPRSliderY)); RedrawThumbs(w); } - -static void ComputeLayout(widget, query, destroy_scrollbars) - Widget widget; /* Viewport */ - Boolean query; /* query child's preferred geom? */ - Boolean destroy_scrollbars; /* destroy un-needed scrollbars? */ +static void +ComputeLayout(Widget widget, Bool query, Bool destroy_scrollbars) { ViewportWidget w = (ViewportWidget)widget; Widget child = w->viewport.child; Widget clip = w->viewport.clip; - ViewportConstraints constraints - = (ViewportConstraints)clip->core.constraints; - Boolean needshoriz, needsvert; + ViewportConstraints constraints = + (ViewportConstraints)clip->core.constraints; + Bool needshoriz, needsvert; int clip_width, clip_height; XtWidgetGeometry intended; - if (child == (Widget) NULL) return; + if (child == NULL) + return; - clip_width = w->core.width; - clip_height = w->core.height; + clip_width = XtWidth(w); + clip_height = XtHeight(w); intended.request_mode = CWBorderWidth; intended.border_width = 0; if (w->viewport.forcebars) { - needsvert = w->viewport.allowvert; - needshoriz = w->viewport.allowhoriz; - ComputeWithForceBars(widget, query, &intended, + needsvert = w->viewport.allowvert; + needshoriz = w->viewport.allowhoriz; + ComputeWithForceBars(widget, query, &intended, &clip_width, &clip_height); } else { - Dimension prev_width, prev_height; + Dimension prev_width, prev_height; XtGeometryMask prev_mode; XtWidgetGeometry preferred; @@ -504,36 +551,34 @@ static void ComputeLayout(widget, query, destroy_scrollbars) /* * intended.{width,height} caches the eventual child dimensions, * but we don't set the mode bits until after we decide that the - * child's preferences are not acceptable. + * child's preferences are not acceptable */ - if (!w->viewport.allowhoriz) intended.request_mode |= CWWidth; - if ((int)child->core.width < clip_width) + if (XtWidth(child) < clip_width) intended.width = clip_width; else - intended.width = child->core.width; + intended.width = XtWidth(child); - if ((int)child->core.height < clip_height) + if (XtHeight(child) < clip_height) intended.height = clip_height; else - intended.height = child->core.height; + intended.height = XtHeight(child); if (!w->viewport.allowvert) intended.request_mode |= CWHeight; if (!query) { - preferred.width = child->core.width; - preferred.height = child->core.height; + preferred.width = XtWidth(child); + preferred.height = XtHeight(child); } do { /* while intended != prev */ - if (query) { - (void) XtQueryGeometry( child, &intended, &preferred ); - if ( !(preferred.request_mode & CWWidth) ) + (void)XtQueryGeometry(child, &intended, &preferred); + if (!(preferred.request_mode & CWWidth)) preferred.width = intended.width; - if ( !(preferred.request_mode & CWHeight) ) + if (!(preferred.request_mode & CWHeight)) preferred.height = intended.height; } prev_width = intended.width; @@ -542,44 +587,44 @@ static void ComputeLayout(widget, query, destroy_scrollbars) /* * note that having once decided to turn on either bar * we'll not change our mind until we're next resized, - * thus avoiding potential oscillations. + * thus avoiding potential oscillations */ -#define CheckHoriz() \ - if ( w->viewport.allowhoriz && \ - (int)preferred.width > clip_width) { \ - if (!needshoriz) { \ - Widget bar; \ - needshoriz = True; \ - if ((bar = w->viewport.horiz_bar) == (Widget)NULL) \ - bar = CreateScrollbar(w, True); \ - clip_height -= bar->core.height + \ - bar->core.border_width; \ - if (clip_height < 1) clip_height = 1; \ - } \ - intended.width = preferred.width; \ +#define CheckHoriz() \ + if (w->viewport.allowhoriz && \ + preferred.width > clip_width) { \ + if (!needshoriz) { \ + Widget bar; \ + \ + needshoriz = True; \ + if ((bar = w->viewport.horiz_bar) == NULL) \ + bar = CreateScrollbar(w, True); \ + clip_height -= XtHeight(bar) + XtBorderWidth(bar); \ + if (clip_height < 1) \ + clip_height = 1; \ + } \ + intended.width = preferred.width; \ } -/*enddef*/ + CheckHoriz(); - if (w->viewport.allowvert && (int)preferred.height > clip_height) { - if (!needsvert) { + if (w->viewport.allowvert && preferred.height > clip_height) { + if (!needsvert) { Widget bar; needsvert = True; - if ((bar = w->viewport.vert_bar) == (Widget)NULL) - bar = CreateScrollbar(w, False); - clip_width -= bar->core.width + bar->core.border_width; - if (clip_width < 1) clip_width = 1; + if ((bar = w->viewport.vert_bar) == NULL) + bar = CreateScrollbar(w, False); + clip_width -= XtWidth(bar) + XtBorderWidth(bar); + if (clip_width < 1) + clip_width = 1; CheckHoriz(); } intended.height = preferred.height; } - if ( !w->viewport.allowhoriz || - (int)preferred.width < clip_width) { - intended.width = clip_width; + if (!w->viewport.allowhoriz || preferred.width < clip_width) { + intended.width = clip_width; intended.request_mode |= CWWidth; } - if ( !w->viewport.allowvert || - (int)preferred.height < clip_height) { - intended.height = clip_height; + if (!w->viewport.allowvert || preferred.height < clip_height) { + intended.height = clip_height; intended.request_mode |= CWHeight; } } while (intended.request_mode != prev_mode @@ -590,152 +635,150 @@ static void ComputeLayout(widget, query, destroy_scrollbars) } if (XtIsRealized(clip)) - XRaiseWindow( XtDisplay(clip), XtWindow(clip) ); - - XtMoveWidget( clip, - (Position) (needsvert ? (w->viewport.useright ? 0 : - w->viewport.vert_bar->core.width + - w->viewport.vert_bar->core.border_width) : 0), - (Position) (needshoriz ? (w->viewport.usebottom ? 0 : - w->viewport.horiz_bar->core.height + - w->viewport.horiz_bar->core.border_width) : 0)); - XtResizeWidget( clip, (Dimension)clip_width, - (Dimension)clip_height, (Dimension)0 ); + XRaiseWindow(XtDisplay(clip), XtWindow(clip)); + + XtMoveWidget(clip, + needsvert ? w->viewport.useright ? 0 : + XtWidth(w->viewport.vert_bar) + + XtBorderWidth(w->viewport.vert_bar) : 0, + needshoriz ? w->viewport.usebottom ? 0 : + XtHeight(w->viewport.horiz_bar) + + XtBorderWidth(w->viewport.horiz_bar) : 0); + XtResizeWidget(clip, clip_width, clip_height, 0); - if (w->viewport.horiz_bar != (Widget)NULL) { + if (w->viewport.horiz_bar != NULL) { Widget bar = w->viewport.horiz_bar; + if (!needshoriz) { - constraints->form.vert_base = (Widget)NULL; + constraints->form.vert_base = NULL; if (destroy_scrollbars) { - XtDestroyWidget( bar ); - w->viewport.horiz_bar = (Widget)NULL; + XtDestroyWidget(bar); + w->viewport.horiz_bar = NULL; } } else { - int bw = bar->core.border_width; - XtResizeWidget( bar, (Dimension) clip_width, bar->core.height, (Dimension) bw ); - XtMoveWidget( bar, - (Position)((needsvert && !w->viewport.useright) - ? w->viewport.vert_bar->core.width - : -bw), - (Position)(w->viewport.usebottom - ? w->core.height - bar->core.height - bw - : -bw) ); - XtSetMappedWhenManaged( bar, True ); + int bw = XtBorderWidth(bar); + + XtResizeWidget(bar, clip_width, XtHeight(bar), bw); + XtMoveWidget(bar, + needsvert && !w->viewport.useright + ? XtWidth(w->viewport.vert_bar) : -bw, + w->viewport.usebottom + ? XtHeight(w) - XtHeight(bar) - bw : -bw); + XtSetMappedWhenManaged(bar, True); } } - if (w->viewport.vert_bar != (Widget)NULL) { + if (w->viewport.vert_bar != NULL) { Widget bar = w->viewport.vert_bar; - if (!needsvert) { - constraints->form.horiz_base = (Widget)NULL; + + if (!needsvert) { + constraints->form.horiz_base = NULL; if (destroy_scrollbars) { - XtDestroyWidget( bar ); - w->viewport.vert_bar = (Widget)NULL; + XtDestroyWidget(bar); + w->viewport.vert_bar = NULL; } } else { int bw = bar->core.border_width; - XtResizeWidget( bar, bar->core.width, (Dimension)clip_height, (Dimension)bw ); - XtMoveWidget( bar, - (Position)(w->viewport.useright - ? w->core.width - bar->core.width - bw - : -bw), - (Position)((needshoriz && !w->viewport.usebottom) - ? w->viewport.horiz_bar->core.height - : -bw) ); - XtSetMappedWhenManaged( bar, True ); + + XtResizeWidget(bar, XtWidth(bar), clip_height, bw); + XtMoveWidget(bar, + w->viewport.useright + ? XtWidth(w) - XtWidth(bar) - bw : -bw, + needshoriz && !w->viewport.usebottom + ? XtHeight(w->viewport.horiz_bar) : -bw); + XtSetMappedWhenManaged(bar, True); } } - if (child != (Widget)NULL) { - XtResizeWidget( child, (Dimension)intended.width, - (Dimension)intended.height, (Dimension)0 ); - MoveChild(w, - needshoriz ? child->core.x : 0, - needsvert ? child->core.y : 0); + if (child != NULL) { + XtResizeWidget(child, intended.width, intended.height, 0); + MoveChild(w, needshoriz ? XtX(child) : 0, needsvert ? XtY(child) : 0); } SendReport (w, XawPRAll); } -/* Function Name: ComputeWithForceBars - * Description: Computes the layout give forcebars is set. - * Arguments: widget - the viewport widget. - * query - whether or not to query the child. - * intended - the cache of the childs height is - * stored here ( USED AND RETURNED ). - * clip_width, clip_height - size of clip window. - * (USED AND RETURNED ). - * Returns: none. +/* + * Function: + * ComputeWithForceBars + * + * Parameters: + * widget - viewport widget + * query - whether or not to query the child + * intended - cache of the childs height is stored here + * (used and returned) + * clip_width - size of clip window (used and returned) + * clip_height - "" + * + * Description: + * Computes the layout give forcebars is set. */ - static void -ComputeWithForceBars(widget, query, intended, clip_width, clip_height) -Widget widget; -Boolean query; -XtWidgetGeometry * intended; -int *clip_width, *clip_height; +ComputeWithForceBars(Widget widget, Bool query, XtWidgetGeometry *intended, + int *clip_width, int *clip_height) { ViewportWidget w = (ViewportWidget)widget; Widget child = w->viewport.child; XtWidgetGeometry preferred; -/* - * If forcebars then needs = allows = has. - * Thus if needsvert is set it MUST have a scrollbar. - */ - + /* + * If forcebars then needs = allows = has + * Thus if needsvert is set it MUST have a scrollbar + */ if (w->viewport.allowvert) { if (w->viewport.vert_bar == NULL) w->viewport.vert_bar = CreateScrollbar(w, False); - *clip_width -= w->viewport.vert_bar->core.width + - w->viewport.vert_bar->core.border_width; + *clip_width -= XtWidth(w->viewport.vert_bar) + + XtBorderWidth(w->viewport.vert_bar); } if (w->viewport.allowhoriz) { if (w->viewport.horiz_bar == NULL) w->viewport.horiz_bar = CreateScrollbar(w, True); - *clip_height -= w->viewport.horiz_bar->core.height + - w->viewport.horiz_bar->core.border_width; + *clip_height -= XtHeight(w->viewport.horiz_bar) + + XtBorderWidth(w->viewport.horiz_bar); } - AssignMax( *clip_width, 1 ); - AssignMax( *clip_height, 1 ); + AssignMax(*clip_width, 1); + AssignMax(*clip_height, 1); if (!w->viewport.allowvert) { - intended->height = *clip_height; - intended->request_mode = CWHeight; + intended->height = *clip_height; + intended->request_mode = CWHeight; } if (!w->viewport.allowhoriz) { - intended->width = *clip_width; - intended->request_mode = CWWidth; + intended->width = *clip_width; + intended->request_mode = CWWidth; } - if ( query ) { - if ( (w->viewport.allowvert || w->viewport.allowhoriz) ) { - XtQueryGeometry( child, intended, &preferred ); + if (query) { + if (w->viewport.allowvert || w->viewport.allowhoriz) { + XtQueryGeometry(child, intended, &preferred); - if ( !(intended->request_mode & CWWidth) ) - if ( preferred.request_mode & CWWidth ) + if (!(intended->request_mode & CWWidth)) { + if (preferred.request_mode & CWWidth) intended->width = preferred.width; else - intended->width = child->core.width; + intended->width = XtWidth(child); + } - if ( !(intended->request_mode & CWHeight) ) - if ( preferred.request_mode & CWHeight ) + if (!(intended->request_mode & CWHeight)) { + if (preferred.request_mode & CWHeight) intended->height = preferred.height; else - intended->height = child->core.height; + intended->height = XtHeight(child); + } } } else { - if (w->viewport.allowvert) - intended->height = child->core.height; + if (w->viewport.allowvert) + intended->height = XtHeight(child); if (w->viewport.allowhoriz) - intended->width = child->core.width; + intended->width = XtWidth(child); } if (*clip_width > (int)intended->width) @@ -744,210 +787,192 @@ int *clip_width, *clip_height; intended->height = *clip_height; } -static void Resize(widget) - Widget widget; +static void +XawViewportResize(Widget widget) { - ComputeLayout( widget, /*query=*/True, /*destroy=*/True ); + ComputeLayout(widget, True, True); } - -/* ARGSUSED */ -static Boolean Layout(w, width, height) - FormWidget w; - Dimension width, height; +/*ARGSUSED*/ +static Boolean +Layout(FormWidget w, unsigned int width, unsigned int height, Bool force) { - ComputeLayout( (Widget)w, /*query=*/True, /*destroy=*/True ); - w->form.preferred_width = w->core.width; - w->form.preferred_height = w->core.height; - return False; -} + ComputeLayout((Widget)w, True, True); + w->form.preferred_width = XtWidth(w); + w->form.preferred_height = XtHeight(w); + return (False); +} -static void ScrollUpDownProc(widget, closure, call_data) - Widget widget; - XtPointer closure; - XtPointer call_data; +static void +ScrollUpDownProc(Widget widget, XtPointer closure, XtPointer call_data) { ViewportWidget w = (ViewportWidget)closure; Widget child = w->viewport.child; - int pix = (int)call_data; - Position x, y; + int pix = (long)call_data; + int x, y; - if (child == NULL) return; /* no child to scroll. */ + if (child == NULL) + return; - x = child->core.x - ((widget == w->viewport.horiz_bar) ? pix : 0); - y = child->core.y - ((widget == w->viewport.vert_bar) ? pix : 0); + x = XtX(child) - (widget == w->viewport.horiz_bar ? pix : 0); + y = XtY(child) - (widget == w->viewport.vert_bar ? pix : 0); MoveChild(w, x, y); } - -/* ARGSUSED */ -static void ThumbProc(widget, closure, call_data) - Widget widget; - XtPointer closure; - XtPointer call_data; +/*ARGSUSED*/ +static void +ThumbProc(Widget widget, XtPointer closure, XtPointer call_data) { ViewportWidget w = (ViewportWidget)closure; Widget child = w->viewport.child; - float *percent = (float *) call_data; - Position x, y; + float percent = *(float *)call_data; + int x, y; - if (child == NULL) return; /* no child to scroll. */ + if (child == NULL) + return; if (widget == w->viewport.horiz_bar) -#ifdef macII /* bug in the macII A/UX 1.0 cc */ - x = (int)(-*percent * child->core.width); -#else /* else not macII */ - x = -(int)(*percent * child->core.width); -#endif /* macII */ + x = -percent * XtWidth(child); else - x = child->core.x; + x = XtX(child); if (widget == w->viewport.vert_bar) -#ifdef macII /* bug in the macII A/UX 1.0 cc */ - y = (int)(-*percent * child->core.height); -#else /* else not macII */ - y = -(int)(*percent * child->core.height); -#endif /* macII */ + y = -percent * XtHeight(child); else - y = child->core.y; + y = XtY(child); MoveChild(w, x, y); } static XtGeometryResult -TestSmaller(w, request, reply_return) - ViewportWidget w; XtWidgetGeometry *request, *reply_return; +TestSmaller(ViewportWidget w, XtWidgetGeometry *request, + XtWidgetGeometry *reply_return) { - if (request->width < w->core.width || request->height < w->core.height) - return XtMakeGeometryRequest((Widget)w, request, reply_return); - else - return XtGeometryYes; + if (request->width < XtWidth(w) || request->height < XtHeight(w)) + return (XtMakeGeometryRequest((Widget)w, request, reply_return)); + + return (XtGeometryYes); } static XtGeometryResult -GeometryRequestPlusScrollbar(w, horizontal, request, reply_return) - Boolean horizontal; - ViewportWidget w; - XtWidgetGeometry *request, *reply_return; +GeometryRequestPlusScrollbar(ViewportWidget w, Bool horizontal, + XtWidgetGeometry *request, + XtWidgetGeometry *reply_return) { - Widget sb; - XtWidgetGeometry plusScrollbars; - plusScrollbars = *request; - if ((sb = w->viewport.horiz_bar) == (Widget)NULL) - sb = CreateScrollbar( w, horizontal); - request->width += sb->core.width; - request->height += sb->core.height; - XtDestroyWidget(sb); - return XtMakeGeometryRequest((Widget) w, &plusScrollbars, reply_return); - } - -#define WidthChange() (request->width != w->core.width) -#define HeightChange() (request->height != w->core.height) + Widget sb; + XtWidgetGeometry plusScrollbars; + + plusScrollbars = *request; + if ((sb = w->viewport.horiz_bar) == NULL) + sb = CreateScrollbar(w, horizontal); + request->width += XtWidth(sb); + request->height += XtHeight(sb); + XtDestroyWidget(sb); + return (XtMakeGeometryRequest((Widget)w, &plusScrollbars, reply_return)); +} +#define WidthChange() (request->width != XtWidth(w)) +#define HeightChange() (request->height != XtHeight(w)) static XtGeometryResult -QueryGeometry(w, request, reply_return) - ViewportWidget w; XtWidgetGeometry *request, *reply_return; +QueryGeometry(ViewportWidget w, XtWidgetGeometry *request, + XtWidgetGeometry *reply_return) { - if (w->viewport.allowhoriz && w->viewport.allowvert) - return TestSmaller(w, request, reply_return); - - else if (w->viewport.allowhoriz && !w->viewport.allowvert) { - if (WidthChange() && !HeightChange()) - return TestSmaller(w, request, reply_return); - else if (!WidthChange() && HeightChange()) - return XtMakeGeometryRequest((Widget) w, request, reply_return); - else if (WidthChange() && HeightChange()) /* hard part */ - return GeometryRequestPlusScrollbar(w, True, request, reply_return); - else /* !WidthChange() && !HeightChange() */ - return XtGeometryYes; - } - else if (!w->viewport.allowhoriz && w->viewport.allowvert) { - if (!WidthChange() && HeightChange()) - return TestSmaller(w, request, reply_return); - else if (WidthChange() && !HeightChange()) - return XtMakeGeometryRequest((Widget)w, request, reply_return); - else if (WidthChange() && HeightChange()) /* hard part */ - return GeometryRequestPlusScrollbar(w, False, request, reply_return); - else /* !WidthChange() && !HeightChange() */ - return XtGeometryYes; - } - else /* (!w->viewport.allowhoriz && !w->viewport.allowvert) */ - return XtMakeGeometryRequest((Widget) w, request, reply_return); + if (w->viewport.allowhoriz && w->viewport.allowvert) + return (TestSmaller(w, request, reply_return)); + + else if (w->viewport.allowhoriz && !w->viewport.allowvert) { + if (WidthChange() && !HeightChange()) + return (TestSmaller(w, request, reply_return)); + else if (!WidthChange() && HeightChange()) + return (XtMakeGeometryRequest((Widget)w, request, reply_return)); + else if (WidthChange() && HeightChange()) + return (GeometryRequestPlusScrollbar(w, True, request, reply_return)); + else /* !WidthChange() && !HeightChange() */ + return (XtGeometryYes); + } + else if (!w->viewport.allowhoriz && w->viewport.allowvert) { + if (!WidthChange() && HeightChange()) + return (TestSmaller(w, request, reply_return)); + else if (WidthChange() && !HeightChange()) + return (XtMakeGeometryRequest((Widget)w, request, reply_return)); + else if (WidthChange() && HeightChange()) + return (GeometryRequestPlusScrollbar(w, False, request, reply_return)); + else /* !WidthChange() && !HeightChange() */ + return (XtGeometryYes); + } + else /* (!w->viewport.allowhoriz && !w->viewport.allowvert) */ + return (XtMakeGeometryRequest((Widget)w, request, reply_return)); } - #undef WidthChange #undef HeightChange -static XtGeometryResult GeometryManager(child, request, reply) - Widget child; - XtWidgetGeometry *request, *reply; +static XtGeometryResult +XawViewportGeometryManager(Widget child, XtWidgetGeometry *request, + XtWidgetGeometry *reply) { ViewportWidget w = (ViewportWidget)child->core.parent; - Boolean rWidth = (Boolean)(request->request_mode & CWWidth); - Boolean rHeight = (Boolean)(request->request_mode & CWHeight); + Bool rWidth = (request->request_mode & CWWidth) != 0; + Bool rHeight = (request->request_mode & CWHeight) != 0; XtWidgetGeometry allowed; XtGeometryResult result; - Boolean reconfigured; - Boolean child_changed_size; - Dimension height_remaining; + Bool reconfigured; + Bool child_changed_size; + unsigned int height_remaining; if (request->request_mode & XtCWQueryOnly) - return QueryGeometry(w, request, reply); + return (QueryGeometry(w, request, reply)); if (child != w->viewport.child - || request->request_mode & ~(CWWidth | CWHeight - | CWBorderWidth) + || request->request_mode & ~(CWWidth | CWHeight | CWBorderWidth) || ((request->request_mode & CWBorderWidth) && request->border_width > 0)) - return XtGeometryNo; + return (XtGeometryNo); allowed = *request; - reconfigured = GetGeometry( (Widget)w, - (rWidth ? request->width : w->core.width), - (rHeight ? request->height : w->core.height) - ); + reconfigured = GetGeometry((Widget)w, + rWidth ? request->width : XtWidth(w), + rHeight ? request->height : XtHeight(w)); - child_changed_size = ((rWidth && child->core.width != request->width) || - (rHeight && child->core.height != request->height)); + child_changed_size = (rWidth && XtWidth(child) != request->width) || + (rHeight && XtHeight(child) != request->height); - height_remaining = w->core.height; - if (rWidth && w->core.width != request->width) { - if (w->viewport.allowhoriz && request->width > w->core.width) { + height_remaining = XtHeight(w); + if (rWidth && XtWidth(w) != request->width) { + if (w->viewport.allowhoriz && request->width > XtWidth(w)) { /* horizontal scrollbar will be needed so possibly reduce height */ Widget bar; - if ((bar = w->viewport.horiz_bar) == (Widget)NULL) - bar = CreateScrollbar( w, True ); - height_remaining -= bar->core.height + bar->core.border_width; + + if ((bar = w->viewport.horiz_bar) == NULL) + bar = CreateScrollbar(w, True); + height_remaining -= XtHeight(bar) + XtBorderWidth(bar); reconfigured = True; } - else { - allowed.width = w->core.width; - } + else + allowed.width = XtWidth(w); } if (rHeight && height_remaining != request->height) { if (w->viewport.allowvert && request->height > height_remaining) { /* vertical scrollbar will be needed, so possibly reduce width */ - if (!w->viewport.allowhoriz || request->width < w->core.width) { + if (!w->viewport.allowhoriz || request->width < XtWidth(w)) { Widget bar; - if ((bar = w->viewport.vert_bar) == (Widget)NULL) - bar = CreateScrollbar( w, False ); + + if ((bar = w->viewport.vert_bar) == NULL) + bar = CreateScrollbar(w, False); if (!rWidth) { - allowed.width = w->core.width; + allowed.width = XtWidth(w); allowed.request_mode |= CWWidth; } - if ( (int)allowed.width > - (int)(bar->core.width + bar->core.border_width) ) - allowed.width -= bar->core.width + bar->core.border_width; + if (allowed.width > XtWidth(bar) + XtBorderWidth(bar)) + allowed.width -= XtWidth(bar) + XtBorderWidth(bar); else allowed.width = 1; reconfigured = True; } } - else { + else allowed.height = height_remaining; - } } if (allowed.width != request->width || allowed.height != request->height) { @@ -955,129 +980,120 @@ static XtGeometryResult GeometryManager(child, request, reply) result = XtGeometryAlmost; } else { - if (rWidth) child->core.width = request->width; - if (rHeight) child->core.height = request->height; + if (rWidth) + XtWidth(child) = request->width; + if (rHeight) + XtHeight(child) = request->height; result = XtGeometryYes; } if (reconfigured || child_changed_size) - ComputeLayout( (Widget)w, - /*query=*/ False, - /*destroy=*/ (result == XtGeometryYes) ? True : False ); - - return result; - } + ComputeLayout((Widget)w, False, result == XtGeometryYes); + return (result); +} -static Boolean GetGeometry(w, width, height) - Widget w; - Dimension width, height; +static Bool +GetGeometry(Widget w, unsigned int width, unsigned int height) { XtWidgetGeometry geometry, return_geom; XtGeometryResult result; - if (width == w->core.width && height == w->core.height) - return False; + if (width == XtWidth(w) && height == XtHeight(w)) + return (False); geometry.request_mode = CWWidth | CWHeight; geometry.width = width; geometry.height = height; if (XtIsRealized(w)) { - if (((ViewportWidget)w)->viewport.allowhoriz && width > w->core.width) - geometry.width = w->core.width; - if (((ViewportWidget)w)->viewport.allowvert && height > w->core.height) - geometry.height = w->core.height; - } else { + if (((ViewportWidget)w)->viewport.allowhoriz && width > XtWidth(w)) + geometry.width = XtWidth(w); + if (((ViewportWidget)w)->viewport.allowvert && height > XtHeight(w)) + geometry.height = XtHeight(w); + } + else { /* This is the Realize call; we'll inherit a w&h iff none currently */ - if (w->core.width != 0) { - if (w->core.height != 0) return False; - geometry.width = w->core.width; + if (XtWidth(w) != 0) { + if (XtHeight(w) != 0) + return (False); + geometry.width = XtWidth(w); } - if (w->core.height != 0) geometry.height = w->core.height; + if (XtHeight(w) != 0) + geometry.height = XtHeight(w); } result = XtMakeGeometryRequest(w, &geometry, &return_geom); if (result == XtGeometryAlmost) - result = XtMakeGeometryRequest(w, &return_geom, (XtWidgetGeometry *)NULL); + result = XtMakeGeometryRequest(w, &return_geom, NULL); return (result == XtGeometryYes); } -static XtGeometryResult PreferredGeometry(w, constraints, reply) - Widget w; - XtWidgetGeometry *constraints, *reply; +static XtGeometryResult +XawViewportQueryGeometry(Widget w, XtWidgetGeometry *constraints, + XtWidgetGeometry *reply) { if (((ViewportWidget)w)->viewport.child != NULL) - return XtQueryGeometry( ((ViewportWidget)w)->viewport.child, - constraints, reply ); - else - return XtGeometryYes; -} + return (XtQueryGeometry(((ViewportWidget)w)->viewport.child, + constraints, reply)); + return (XtGeometryYes); +} void -#if NeedFunctionPrototypes -XawViewportSetLocation (Widget gw, +XawViewportSetLocation +( + Widget gw, #if NeedWidePrototypes - double xoff, double yoff) -#else - float xoff, float yoff) -#endif + double xoff, double yoff #else -XawViewportSetLocation (gw, xoff, yoff) - Widget gw; - float xoff,yoff; + float xoff, float yoff #endif + ) { - ViewportWidget w = (ViewportWidget) gw; + ViewportWidget w = (ViewportWidget)gw; Widget child = w->viewport.child; - Position x, y; + int x, y; if (xoff > 1.0) /* scroll to right */ - x = child->core.width; + x = XtWidth(child); else if (xoff < 0.0) /* if the offset is < 0.0 nothing */ - x = child->core.x; + x = XtX(child); else - x = (Position) (((float) child->core.width) * xoff); + x = (float)XtWidth(child) * xoff; if (yoff > 1.0) - y = child->core.height; + y = XtHeight(child); else if (yoff < 0.0) - y = child->core.y; + y = XtY(child); else - y = (Position) (((float) child->core.height) * yoff); + y = (float)XtHeight(child) * yoff; MoveChild (w, -x, -y); } void -#if NeedFunctionPrototypes -XawViewportSetCoordinates (Widget gw, +XawViewportSetCoordinates(Widget gw, #if NeedWidePrototypes - int x, int y) + int x, int y #else - Position x, Position y) -#endif -#else -XawViewportSetCoordinates (gw, x, y) - Widget gw; - Position x, y; + Position x, Position y #endif +) { - ViewportWidget w = (ViewportWidget) gw; + ViewportWidget w = (ViewportWidget)gw; Widget child = w->viewport.child; - if (x > (int)child->core.width) - x = child->core.width; + if (x > XtWidth(child)) + x = XtWidth(child); else if (x < 0) - x = child->core.x; + x = XtX(child); - if (y > (int)child->core.height) - y = child->core.height; + if (y > XtHeight(child)) + y = XtHeight(child); else if (y < 0) - y = child->core.y; + y = XtY(child); MoveChild (w, -x, -y); } - diff --git a/src/XawI18n.c b/src/XawI18n.c index b774aec..5d600ad 100644 --- a/src/XawI18n.c +++ b/src/XawI18n.c @@ -53,16 +53,16 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/XawI18n.c,v 1.8 2001/12/14 19:54:46 dawes Exp $ */ #include <X11/IntrinsicP.h> #include "XawI18n.h" -#if NeedFunctionPrototypes -wchar_t _Xaw_atowc( - unsigned char c) +wchar_t +#if NeedWidePrototypes +_Xaw_atowc(int c) #else -wchar_t _Xaw_atowc(c) - unsigned char c; +_Xaw_atowc(unsigned char c) #endif { wchar_t wc; @@ -72,16 +72,30 @@ wchar_t _Xaw_atowc(c) str[1] = '\0'; mbtowc(&wc, str, 1); - return wc; + + return (wc); } #ifdef NCR -int _Xaw_iswspace(wchar_t w) +int +_Xaw_iswspace(wchar_t w) { int ret = 0; wchar_t s = _Xaw_atowc(' '); + if (s == w) ret = 1; - return ret; + + return (ret); } #endif + +int +_Xaw_iswalnum(wchar_t ch) +{ + unsigned char mb[sizeof(wchar_t)]; + + wctomb((char*)mb, ch); + + return (isalnum(*mb)); +} diff --git a/src/XawI18n.h b/src/XawI18n.h index 4432553..fa06859 100644 --- a/src/XawI18n.h +++ b/src/XawI18n.h @@ -25,13 +25,16 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. ********************************************************/ +/* $XFree86: xc/lib/Xaw/XawI18n.h,v 3.14 2001/12/14 19:54:46 dawes Exp $ */ #ifdef HAS_WCTYPE_H #include <wctype.h> +#ifndef NO_WIDEC_H #include <widec.h> #define wcslen(c) wslen(c) -#define wcscpy(d,s) wscpy(d,s) -#define wcsncpy(d,s,l) wsncpy(d,s,l) +#define wcscpy(d, s) wscpy(d, s) +#define wcsncpy(d, s, l) wsncpy(d, s, l) +#endif #endif #ifdef HAS_WCHAR_H @@ -44,7 +47,10 @@ in this Software without prior written authorization from The Open Group. #ifdef NCR #define iswspace(c) _Xaw_iswspace(c) -extern int _Xaw_iswspace(wchar_t); +int _Xaw_iswspace +( + wchar_t c + ); #endif #ifdef sony @@ -54,20 +60,50 @@ extern int _Xaw_iswspace(wchar_t); #endif #endif +#ifdef QNX4 +#define toascii( c ) ((unsigned)(c) & 0x007f) +#endif + +#include <stdlib.h> + #ifdef USE_XWCHAR_STRING +int _Xwcslen +( + wchar_t *wstr + ); + #define wcslen(c) _Xwcslen(c) + +wchar_t *_Xwcscpy +( + wchar_t *wstr1, + wchar_t *wstr2 + ); + #define wcscpy(d,s) _Xwcscpy(d,s) -#define wcsncpy(d,s,l) _Xwcsncpy(d,s,l) + +wchar_t *_Xwcsncpy +( + wchar_t *wstr1, + wchar_t *wstr2, + int len + ); + +#define wcsncpy(d, s, l) _Xwcsncpy(d, s, l) + #ifdef USE_XMBTOWC -#define mbtowc(wc,s,l) _Xmbtowc(wc,s,l) +#define mbtowc(wc, s, l) _Xmbtowc(wc, s, l) #endif #endif -extern wchar_t _Xaw_atowc ( -#if NeedFunctionPrototypes - unsigned char c +wchar_t _Xaw_atowc +( +#if NeedWidePrototypes + int c +#else + unsigned char c #endif -); + ); #ifndef HAS_ISW_FUNCS #include <ctype.h> @@ -75,3 +111,11 @@ extern wchar_t _Xaw_atowc ( #define iswspace(c) (isascii(c) && isspace(toascii(c))) #endif #endif + +#ifndef iswalnum +#define iswalnum(c) _Xaw_iswalnum(c) +int _Xaw_iswalnum +( + wchar_t c + ); +#endif diff --git a/src/XawIm.c b/src/XawIm.c index e4b4bac..49a4115 100644 --- a/src/XawIm.c +++ b/src/XawIm.c @@ -52,6 +52,7 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/Xaw/XawIm.c,v 1.14 2001/12/14 19:54:46 dawes Exp $ */ #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> @@ -66,13 +67,7 @@ in this Software without prior written authorization from The Open Group. #include "XawI18n.h" #include <ctype.h> -#if NeedVarargsPrototypes -# include <stdarg.h> -# define Va_start(a,b) va_start(a,b) -#else -# include <varargs.h> -# define Va_start(a,b) va_start(a) -#endif +#include <stdarg.h> #define maxAscentOfFontSet(fontset) \ ( - (XExtentsOfFontSet((fontset)))->max_logical_extent.y) @@ -91,18 +86,70 @@ in this Software without prior written authorization from The Open Group. * *****************************************************/ -static XawIcTableList CurrentSharedIcTable( -#if NeedFunctionPrototypes - XawVendorShellExtPart* /* ve */ -#endif -); +/* + * Prototypes + */ +static void AllCreateIC(XawVendorShellExtPart*); +static void CloseIM(XawVendorShellExtPart*); +static void CompileResourceList(XtResourceList, unsigned int); +static void ConfigureCB(Widget, XtPointer, XEvent*, Boolean*); +static void CreateIC(Widget, XawVendorShellExtPart*); +static XawIcTableList CreateIcTable(Widget, XawVendorShellExtPart*); +static XawIcTableList CurrentSharedIcTable(XawVendorShellExtPart*); +static void Destroy(Widget, XawVendorShellExtPart*); +static void DestroyAllIM(XawVendorShellExtPart*); +static void DestroyIC(Widget, XawVendorShellExtPart*); +static void FreeAllDataOfVendorShell(XawVendorShellExtPart*, + VendorShellWidget); +static XawVendorShellExtPart *GetExtPart(VendorShellWidget); +static XawIcTableList GetIcTable(Widget, XawVendorShellExtPart*); +static XawIcTableList GetIcTableShared(Widget, XawVendorShellExtPart*); +static XIMStyle GetInputStyleOfIC(XawVendorShellExtPart*); +static Bool Initialize(VendorShellWidget, XawVendorShellExtPart*); +static Bool IsCreatedIC(Widget, XawVendorShellExtPart*); +static Bool IsRegistered(Widget, XawVendorShellExtPart*); +static Bool IsSharedIC(XawVendorShellExtPart*); +static Bool NoRegistered(XawVendorShellExtPart*); +static void OpenIM(XawVendorShellExtPart*); +static void Reconnect(XawVendorShellExtPart*); +static void Register(Widget, XawVendorShellExtPart*); +static Bool RegisterToVendorShell(Widget, XawVendorShellExtPart*); +static void ResizeVendorShell(VendorShellWidget, XawVendorShellExtPart*); +static Bool ResizeVendorShell_Core(VendorShellWidget, XawVendorShellExtPart*, + XawIcTableList); +static VendorShellWidget SearchVendorShell(Widget); +static Widget SetErrCnxt(Widget, XIM); +static XawVendorShellExtPart *SetExtPart(VendorShellWidget, + XawVendorShellExtWidget); +static void SetFocus(Widget, XawVendorShellExtPart*); +static void SetFocusValues(Widget, ArgList, Cardinal, Bool); +static void SetICFocus(Widget, XawVendorShellExtPart*); +static void SetICValues(Widget, XawVendorShellExtPart*, Bool); +static void SetICValuesShared(Widget, XawVendorShellExtPart*, XawIcTableList, + Bool); +static void SetValues(Widget, XawVendorShellExtPart*, ArgList, Cardinal); +static unsigned int SetVendorShellHeight(XawVendorShellExtPart*, + unsigned int); +static void SharedICChangeFocusWindow(Widget, XawVendorShellExtPart*, + XawIcTableList); +static void SizeNegotiation(XawIcTableList, unsigned int, unsigned int); +static void Unregister(Widget, XawVendorShellExtPart*); +static void UnregisterFromVendorShell(Widget, XawVendorShellExtPart*); +static void UnsetFocus(Widget); +static void UnsetICFocus(Widget, XawVendorShellExtPart*); +static void VendorShellDestroyed(Widget, XtPointer, XtPointer); -static void DestroyIC( -#if NeedFunctionPrototypes - Widget /* w */, - XawVendorShellExtPart* /* ve */ -#endif -); +/* + * From Vendor.c + */ +void XawVendorShellExtResize(Widget); +void XawVendorStructureNotifyHandler(Widget, XtPointer, XEvent*, Boolean*); + + +/* + * From Xt/Resources.c + */ +void _XtCopyFromArg(XtArgVal src, char*, unsigned int); static XtResource resources[] = { @@ -130,12 +177,6 @@ static XtResource resources[] = #undef Offset -static void SetVaArg( arg, value ) - XPointer *arg, value; -{ - *arg = value; -} - static VendorShellWidget SearchVendorShell( w ) Widget w; { @@ -146,9 +187,8 @@ static VendorShellWidget SearchVendorShell( w ) static XContext extContext = (XContext)NULL; -static XawVendorShellExtPart *SetExtPart( w, vew ) - VendorShellWidget w; - XawVendorShellExtWidget vew; +static XawVendorShellExtPart * +SetExtPart(VendorShellWidget w, XawVendorShellExtWidget vew) { contextDataRec *contextData; @@ -163,8 +203,8 @@ static XawVendorShellExtPart *SetExtPart( w, vew ) return(&(vew->vendor_ext)); } -static XawVendorShellExtPart *GetExtPart( w ) - VendorShellWidget w; +static XawVendorShellExtPart * +GetExtPart(VendorShellWidget w) { contextDataRec *contextData; XawVendorShellExtWidget vew; @@ -177,15 +217,14 @@ static XawVendorShellExtPart *GetExtPart( w ) return(&(vew->vendor_ext)); } -static Boolean IsSharedIC( ve ) - XawVendorShellExtPart * ve; +static Bool +IsSharedIC(XawVendorShellExtPart * ve) { return( ve->ic.shared_ic ); } -static XawIcTableList GetIcTableShared( w, ve ) - Widget w; - XawVendorShellExtPart * ve; +static XawIcTableList +GetIcTableShared(Widget w, XawVendorShellExtPart *ve) { XawIcTableList p; @@ -201,9 +240,8 @@ static XawIcTableList GetIcTableShared( w, ve ) return(NULL); } -static XawIcTableList GetIcTable( w, ve ) - Widget w; - XawVendorShellExtPart * ve; +static XawIcTableList +GetIcTable(Widget w, XawVendorShellExtPart *ve) { XawIcTableList p; @@ -215,18 +253,17 @@ static XawIcTableList GetIcTable( w, ve ) return(NULL); } -static XIMStyle GetInputStyleOfIC( ve ) - XawVendorShellExtPart * ve; +static XIMStyle +GetInputStyleOfIC(XawVendorShellExtPart *ve) { if (!ve) return((XIMStyle)0); return(ve->ic.input_style); } -static void ConfigureCB( w, closure, event ) - Widget w; - XtPointer closure; - XEvent * event; +/*ARGSUSED*/ +static void +ConfigureCB(Widget w, XtPointer closure, XEvent *event, Boolean *unused) { XawIcTableList p; XawVendorShellExtPart *ve; @@ -239,7 +276,7 @@ static void ConfigureCB( w, closure, event ) if ((vw = SearchVendorShell(w)) == NULL) return; - if (ve = GetExtPart(vw)) { + if ((ve = GetExtPart(vw)) != NULL) { if (IsSharedIC(ve)) return; if ((ve->im.xim == NULL) || ((p = GetIcTableShared(w, ve)) == NULL) || @@ -262,9 +299,7 @@ static void ConfigureCB( w, closure, event ) static XContext errContext = (XContext)NULL; -static Widget SetErrCnxt( w, xim ) - Widget w; - XIM xim; +static Widget SetErrCnxt(Widget w, XIM xim) { contextErrDataRec *contextErrData; @@ -280,8 +315,9 @@ static Widget SetErrCnxt( w, xim ) return(contextErrData->widget); } -static Widget GetErrCnxt( error_im ) - XIM error_im; +#if 0 +static Widget +GetErrCnxt(XIM error_im) { contextErrDataRec *contextErrData; @@ -291,17 +327,17 @@ static Widget GetErrCnxt( error_im ) } return(contextErrData->widget); } +#endif -static void CloseIM( ve ) - XawVendorShellExtPart * ve; +static void +CloseIM(XawVendorShellExtPart *ve) { if (ve->im.xim) XCloseIM(ve->im.xim); } -static Dimension SetVendorShellHeight( ve, height ) - XawVendorShellExtPart* ve; - Dimension height; +static unsigned int +SetVendorShellHeight(XawVendorShellExtPart* ve, unsigned int height) { Arg args[2]; Cardinal i = 0; @@ -315,8 +351,8 @@ static Dimension SetVendorShellHeight( ve, height ) return(ve->im.area_height); } -static void DestroyAllIM( ve ) - XawVendorShellExtPart * ve; +static void +DestroyAllIM(XawVendorShellExtPart *ve) { XawIcTableList p; contextErrDataRec *contextErrData; @@ -342,12 +378,12 @@ static void DestroyAllIM( ve ) /* * Close Input Method */ - CloseIM(ve); if (!XFindContext(XDisplayOfIM(ve->im.xim), (Window)ve->im.xim, errContext, (XPointer*)&contextErrData)) { if (contextErrData) XtFree((char *)contextErrData); } XDeleteContext(XDisplayOfIM(ve->im.xim), (Window)ve->im.xim, errContext); + CloseIM(ve); ve->im.xim = NULL; /* @@ -360,9 +396,8 @@ static void DestroyAllIM( ve ) return; } -static void FreeAllDataOfVendorShell(ve, vw) - XawVendorShellExtPart * ve; - VendorShellWidget vw; +static void +FreeAllDataOfVendorShell(XawVendorShellExtPart *ve, VendorShellWidget vw) { XawIcTableList p, next; contextErrDataRec *contextErrData; @@ -381,9 +416,8 @@ static void FreeAllDataOfVendorShell(ve, vw) } } -static void VendorShellDestroyed( w, cl_data, ca_data ) - Widget w; - XtPointer cl_data, ca_data; +static void +VendorShellDestroyed(Widget w, XtPointer cl_data, XtPointer ca_data) { XawVendorShellExtPart *ve; @@ -393,8 +427,9 @@ static void VendorShellDestroyed( w, cl_data, ca_data ) return; } -static int IOErrorHandler( error_im ) - XIM error_im; +#if 0 +static int +IOErrorHandler(XIM error_im) { VendorShellWidget vw; XawVendorShellExtPart * ve; @@ -405,13 +440,14 @@ static int IOErrorHandler( error_im ) DestroyAllIM(ve); return(0); } +#endif /* * Attempt to open an input method */ -static void OpenIM(ve) - XawVendorShellExtPart * ve; +static void +OpenIM(XawVendorShellExtPart *ve) { int i; char *p, *s, *ns, *end, *pbuf, buf[32]; @@ -427,7 +463,7 @@ static void OpenIM(ve) xim = XOpenIM(XtDisplay(ve->parent), NULL, NULL, NULL); } else { /* no fragment can be longer than the whole string */ - int len = strlen (ve->im.input_method) + 5; + Cardinal len = strlen (ve->im.input_method) + 5; if (len < sizeof buf) pbuf = buf; else pbuf = XtMalloc (len); @@ -440,12 +476,15 @@ static void OpenIM(ve) if (!*s) break; if ((ns = end = strchr(s, ',')) == NULL) end = s + strlen(s); - /* strip any trailing blanks */ - while (isspace(*end)) end--; - - strcpy (pbuf, "@im="); - strncat (pbuf, s, end - s); - pbuf[end - s + 4] = '\0'; + /* If there is a spurious comma end can be the same as s */ + if (end > s) { + /* strip any trailing blanks */ + while (isspace(*(end - 1))) end--; + + strcpy (pbuf, "@im="); + strncat (pbuf, s, end - s); + pbuf[end - s + 4] = '\0'; + } if ((p = XSetLocaleModifiers(pbuf)) != NULL && *p && (xim = XOpenIM(XtDisplay(ve->parent), NULL, NULL, NULL)) != NULL) @@ -478,19 +517,11 @@ static void OpenIM(ve) while (*s && isspace(*s)) s++; if (!*s) break; if ((ns = end = strchr(s, ',')) == NULL) - ns = end = s + strlen(s); - while ((end > s) && isspace(end[-1])) end--; - - /* - * If input was degenerate, e.g. "PreeditType: , Root" - * Skip over the comma - * Don't bother checking current preedit type - */ - - if (end <= s) { - s = ns + 1; - continue; - } + end = s + strlen(s); + else + ns++; + if (end > s) + while (isspace(*(end - 1))) end--; if (!strncmp(s, "OverTheSpot", end - s)) { input_style = (XIMPreeditPosition | XIMStatusArea); @@ -508,7 +539,7 @@ static void OpenIM(ve) break; } - s = ns + 1; + s = ns; } XFree(xim_styles); @@ -519,10 +550,9 @@ static void OpenIM(ve) } } -static Boolean ResizeVendorShell_Core(vw, ve, p) - VendorShellWidget vw; - XawVendorShellExtPart * ve; - XawIcTableList p; +static Bool +ResizeVendorShell_Core(VendorShellWidget vw, XawVendorShellExtPart *ve, + XawIcTableList p) { XVaNestedList pe_attr, st_attr; XRectangle pe_area, st_area; @@ -570,9 +600,8 @@ static Boolean ResizeVendorShell_Core(vw, ve, p) return(TRUE); } -static void ResizeVendorShell(vw, ve) - VendorShellWidget vw; - XawVendorShellExtPart * ve; +static void +ResizeVendorShell(VendorShellWidget vw, XawVendorShellExtPart *ve) { XawIcTableList p; @@ -588,9 +617,8 @@ static void ResizeVendorShell(vw, ve) } } -static XawIcTableList CreateIcTable( w, ve ) - Widget w; - XawVendorShellExtPart * ve; +static XawIcTableList +CreateIcTable(Widget w, XawVendorShellExtPart *ve) { XawIcTableList table; @@ -609,9 +637,8 @@ static XawIcTableList CreateIcTable( w, ve ) return(table); } -static Boolean RegisterToVendorShell( w, ve ) - Widget w; - XawVendorShellExtPart * ve; +static Bool +RegisterToVendorShell(Widget w, XawVendorShellExtPart *ve) { XawIcTableList table; @@ -621,13 +648,12 @@ static Boolean RegisterToVendorShell( w, ve ) return(TRUE); } -static void UnregisterFromVendorShell(w, ve) - Widget w; - XawVendorShellExtPart * ve; +static void +UnregisterFromVendorShell(Widget w, XawVendorShellExtPart *ve) { XawIcTableList *prev, p; - for (prev = &ve->ic.ic_table; p = *prev; prev = &p->next) { + for (prev = &ve->ic.ic_table; (p = *prev) != NULL; prev = &p->next) { if (p->widget == w) { *prev = p->next; XtFree((char *)p); @@ -637,11 +663,9 @@ static void UnregisterFromVendorShell(w, ve) return; } -static void SetICValuesShared(w, ve, p, check) - Widget w; - XawVendorShellExtPart * ve; - XawIcTableList p; - Boolean check; +static void +SetICValuesShared(Widget w, XawVendorShellExtPart *ve, + XawIcTableList p, Bool check) { XawIcTableList pp; @@ -674,9 +698,8 @@ static void SetICValuesShared(w, ve, p, check) } } -static Boolean IsCreatedIC(w, ve) - Widget w; - XawVendorShellExtPart * ve; +static Bool +IsCreatedIC(Widget w, XawVendorShellExtPart *ve) { XawIcTableList p; @@ -686,9 +709,8 @@ static Boolean IsCreatedIC(w, ve) return(TRUE); } -static void SizeNegotiation(p, width, height) - XawIcTableList p; - Dimension width, height; +static void +SizeNegotiation(XawIcTableList p, unsigned int width, unsigned int height) { XRectangle pe_area, st_area; XVaNestedList pe_attr = NULL, st_attr = NULL; @@ -698,15 +720,15 @@ static void SizeNegotiation(p, width, height) if (p->input_style & XIMPreeditArea) { pe_attr = XVaCreateNestedList(0, XNAreaNeeded, &pe_area_needed, NULL); - SetVaArg( &ic_a[ic_cnt], (XPointer) XNPreeditAttributes); ic_cnt++; - SetVaArg( &ic_a[ic_cnt], (XPointer) pe_attr); ic_cnt++; + ic_a[ic_cnt] = (XPointer) XNPreeditAttributes; ic_cnt++; + ic_a[ic_cnt] = (XPointer) pe_attr; ic_cnt++; } if (p->input_style & XIMStatusArea) { st_attr = XVaCreateNestedList(0, XNAreaNeeded, &st_area_needed, NULL); - SetVaArg( &ic_a[ic_cnt], (XPointer) XNStatusAttributes); ic_cnt++; - SetVaArg( &ic_a[ic_cnt], (XPointer) st_attr); ic_cnt++; + ic_a[ic_cnt] = (XPointer) XNStatusAttributes; ic_cnt++; + ic_a[ic_cnt] = (XPointer) st_attr; ic_cnt++; } - SetVaArg( &ic_a[ic_cnt], (XPointer) NULL); + ic_a[ic_cnt] = (XPointer) NULL; if (ic_cnt > 0) { XGetICValues(p->xic, ic_a[0], ic_a[1], ic_a[2], ic_a[3], ic_a[4]); @@ -730,8 +752,8 @@ static void SizeNegotiation(p, width, height) XFree(st_area_needed); st_attr = XVaCreateNestedList(0, XNArea, &st_area, NULL); - SetVaArg( &ic_a[ic_cnt], (XPointer) XNStatusAttributes); ic_cnt++; - SetVaArg( &ic_a[ic_cnt], (XPointer) st_attr); ic_cnt++; + ic_a[ic_cnt] = (XPointer) XNStatusAttributes; ic_cnt++; + ic_a[ic_cnt] = (XPointer) st_attr; ic_cnt++; } if (p->input_style & XIMPreeditArea) { if (p->input_style & XIMStatusArea) { @@ -745,10 +767,10 @@ static void SizeNegotiation(p, width, height) XFree(pe_area_needed); pe_area.y = height - pe_area.height; pe_attr = XVaCreateNestedList(0, XNArea, &pe_area, NULL); - SetVaArg( &ic_a[ic_cnt], (XPointer) XNPreeditAttributes); ic_cnt++; - SetVaArg( &ic_a[ic_cnt], (XPointer) pe_attr); ic_cnt++; + ic_a[ic_cnt] = (XPointer) XNPreeditAttributes; ic_cnt++; + ic_a[ic_cnt] = (XPointer) pe_attr; ic_cnt++; } - SetVaArg( &ic_a[ic_cnt], (XPointer) NULL); + ic_a[ic_cnt] = (XPointer) NULL; XSetICValues(p->xic, ic_a[0], ic_a[1], ic_a[2], ic_a[3], ic_a[4]); if (pe_attr) XFree(pe_attr); if (st_attr) XFree(st_attr); @@ -759,9 +781,8 @@ static void SizeNegotiation(p, width, height) } } -static void CreateIC( w, ve ) - Widget w; - XawVendorShellExtPart* ve; +static void +CreateIC(Widget w, XawVendorShellExtPart *ve) { XawIcTableList p; XPoint position; @@ -783,37 +804,37 @@ static void CreateIC( w, ve ) if (p->input_style & (XIMPreeditArea|XIMPreeditPosition|XIMStatusArea)) { if (p->flg & CIFontSet) { - SetVaArg( &pe_a[pe_cnt], (XPointer) XNFontSet); pe_cnt++; - SetVaArg( &pe_a[pe_cnt], (XPointer) p->font_set); pe_cnt++; - SetVaArg( &st_a[st_cnt], (XPointer) XNFontSet); st_cnt++; - SetVaArg( &st_a[st_cnt], (XPointer) p->font_set); st_cnt++; + pe_a[pe_cnt] = (XPointer) XNFontSet; pe_cnt++; + pe_a[pe_cnt] = (XPointer) p->font_set; pe_cnt++; + st_a[st_cnt] = (XPointer) XNFontSet; st_cnt++; + st_a[st_cnt] = (XPointer) p->font_set; st_cnt++; height = maxAscentOfFontSet(p->font_set) + maxDescentOfFontSet(p->font_set); height = SetVendorShellHeight(ve, height); } if (p->flg & CIFg) { - SetVaArg( &pe_a[pe_cnt], (XPointer) XNForeground); pe_cnt++; - SetVaArg( &pe_a[pe_cnt], (XPointer) p->foreground); pe_cnt++; - SetVaArg( &st_a[st_cnt], (XPointer) XNForeground); st_cnt++; - SetVaArg( &st_a[st_cnt], (XPointer) p->foreground); st_cnt++; + pe_a[pe_cnt] = (XPointer) XNForeground; pe_cnt++; + pe_a[pe_cnt] = (XPointer) p->foreground; pe_cnt++; + st_a[st_cnt] = (XPointer) XNForeground; st_cnt++; + st_a[st_cnt] = (XPointer) p->foreground; st_cnt++; } if (p->flg & CIBg) { - SetVaArg( &pe_a[pe_cnt], (XPointer) XNBackground); pe_cnt++; - SetVaArg( &pe_a[pe_cnt], (XPointer) p->background); pe_cnt++; - SetVaArg( &st_a[st_cnt], (XPointer) XNBackground); st_cnt++; - SetVaArg( &st_a[st_cnt], (XPointer) p->background); st_cnt++; + pe_a[pe_cnt] = (XPointer) XNBackground; pe_cnt++; + pe_a[pe_cnt] = (XPointer) p->background; pe_cnt++; + st_a[st_cnt] = (XPointer) XNBackground; st_cnt++; + st_a[st_cnt] = (XPointer) p->background; st_cnt++; } if (p->flg & CIBgPixmap) { - SetVaArg( &pe_a[pe_cnt], (XPointer) XNBackgroundPixmap); pe_cnt++; - SetVaArg( &pe_a[pe_cnt], (XPointer) p->bg_pixmap); pe_cnt++; - SetVaArg( &st_a[st_cnt], (XPointer) XNBackgroundPixmap); st_cnt++; - SetVaArg( &st_a[st_cnt], (XPointer) p->bg_pixmap); st_cnt++; + pe_a[pe_cnt] = (XPointer) XNBackgroundPixmap; pe_cnt++; + pe_a[pe_cnt] = (XPointer) p->bg_pixmap; pe_cnt++; + st_a[st_cnt] = (XPointer) XNBackgroundPixmap; st_cnt++; + st_a[st_cnt] = (XPointer) p->bg_pixmap; st_cnt++; } if (p->flg & CILineS) { - SetVaArg( &pe_a[pe_cnt], (XPointer) XNLineSpace); pe_cnt++; - SetVaArg( &pe_a[pe_cnt], (XPointer) p->line_spacing); pe_cnt++; - SetVaArg( &st_a[st_cnt], (XPointer) XNLineSpace); st_cnt++; - SetVaArg( &st_a[st_cnt], (XPointer) p->line_spacing); st_cnt++; + pe_a[pe_cnt] = (XPointer) XNLineSpace; pe_cnt++; + pe_a[pe_cnt] = (XPointer) p->line_spacing; pe_cnt++; + st_a[st_cnt] = (XPointer) XNLineSpace; st_cnt++; + st_a[st_cnt] = (XPointer) p->line_spacing; st_cnt++; } } if (p->input_style & XIMPreeditArea) { @@ -821,8 +842,8 @@ static void CreateIC( w, ve ) pe_area.y = ve->parent->core.height - height; pe_area.width = ve->parent->core.width; pe_area.height = height; - SetVaArg( &pe_a[pe_cnt], (XPointer) XNArea); pe_cnt++; - SetVaArg( &pe_a[pe_cnt], (XPointer) &pe_area); pe_cnt++; + pe_a[pe_cnt] = (XPointer) XNArea; pe_cnt++; + pe_a[pe_cnt] = (XPointer) &pe_area; pe_cnt++; } if (p->input_style & XIMPreeditPosition) { pe_area.x = 0; @@ -834,54 +855,54 @@ static void CreateIC( w, ve ) pe_area.y += margin->top; pe_area.width -= (margin->left + margin->right - 1); pe_area.height -= (margin->top + margin->bottom - 1); - SetVaArg( &pe_a[pe_cnt], (XPointer) XNArea); pe_cnt++; - SetVaArg( &pe_a[pe_cnt], (XPointer) &pe_area); pe_cnt++; + pe_a[pe_cnt] = (XPointer) XNArea; pe_cnt++; + pe_a[pe_cnt] = (XPointer) &pe_area; pe_cnt++; if (p->flg & CICursorP) { _XawMultiSinkPosToXY(w, p->cursor_position, &position.x, &position.y); } else { position.x = position.y = 0; } - SetVaArg( &pe_a[pe_cnt], (XPointer) XNSpotLocation); pe_cnt++; - SetVaArg( &pe_a[pe_cnt], (XPointer) &position); pe_cnt++; + pe_a[pe_cnt] = (XPointer) XNSpotLocation; pe_cnt++; + pe_a[pe_cnt] = (XPointer) &position; pe_cnt++; } if (p->input_style & XIMStatusArea) { st_area.x = 0; st_area.y = ve->parent->core.height - height; st_area.width = ve->parent->core.width; st_area.height = height; - SetVaArg( &st_a[st_cnt], (XPointer) XNArea); st_cnt++; - SetVaArg( &st_a[st_cnt], (XPointer) &st_area); st_cnt++; + st_a[st_cnt] = (XPointer) XNArea; st_cnt++; + st_a[st_cnt] = (XPointer) &st_area; st_cnt++; } - SetVaArg( &ic_a[ic_cnt], (XPointer) XNInputStyle); ic_cnt++; - SetVaArg( &ic_a[ic_cnt], (XPointer) p->input_style); ic_cnt++; - SetVaArg( &ic_a[ic_cnt], (XPointer) XNClientWindow); ic_cnt++; - SetVaArg( &ic_a[ic_cnt], (XPointer) XtWindow(ve->parent)); ic_cnt++; - SetVaArg( &ic_a[ic_cnt], (XPointer) XNFocusWindow); ic_cnt++; - SetVaArg( &ic_a[ic_cnt], (XPointer) XtWindow(w)); ic_cnt++; + ic_a[ic_cnt] = (XPointer) XNInputStyle; ic_cnt++; + ic_a[ic_cnt] = (XPointer) p->input_style; ic_cnt++; + ic_a[ic_cnt] = (XPointer) XNClientWindow; ic_cnt++; + ic_a[ic_cnt] = (XPointer) XtWindow(ve->parent); ic_cnt++; + ic_a[ic_cnt] = (XPointer) XNFocusWindow; ic_cnt++; + ic_a[ic_cnt] = (XPointer) XtWindow(w); ic_cnt++; if (pe_cnt > 0) { - SetVaArg( &pe_a[pe_cnt], (XPointer) NULL); + pe_a[pe_cnt] = (XPointer) NULL; pe_attr = XVaCreateNestedList(0, pe_a[0], pe_a[1], pe_a[2], pe_a[3], pe_a[4], pe_a[5], pe_a[6], pe_a[7], pe_a[8], pe_a[9], pe_a[10], pe_a[11], pe_a[12], pe_a[13], pe_a[14], pe_a[15], pe_a[16], pe_a[17], pe_a[18], pe_a[19]); - SetVaArg( &ic_a[ic_cnt], (XPointer) XNPreeditAttributes); ic_cnt++; - SetVaArg( &ic_a[ic_cnt], (XPointer) pe_attr); ic_cnt++; + ic_a[ic_cnt] = (XPointer) XNPreeditAttributes; ic_cnt++; + ic_a[ic_cnt] = (XPointer) pe_attr; ic_cnt++; } if (st_cnt > 0) { - SetVaArg( &st_a[st_cnt], (XPointer) NULL); + st_a[st_cnt] = (XPointer) NULL; st_attr = XVaCreateNestedList(0, st_a[0], st_a[1], st_a[2], st_a[3], st_a[4], st_a[5], st_a[6], st_a[7], st_a[8], st_a[9], st_a[10], st_a[11], st_a[12], st_a[13], st_a[14], st_a[15], st_a[16], st_a[17], st_a[18], st_a[19]); - SetVaArg( &ic_a[ic_cnt], (XPointer) XNStatusAttributes); ic_cnt++; - SetVaArg( &ic_a[ic_cnt], (XPointer) st_attr); ic_cnt++; + ic_a[ic_cnt] = (XPointer) XNStatusAttributes; ic_cnt++; + ic_a[ic_cnt] = (XPointer) st_attr; ic_cnt++; } - SetVaArg( &ic_a[ic_cnt], (XPointer) NULL); + ic_a[ic_cnt] = (XPointer) NULL; p->xic = XCreateIC(ve->im.xim, ic_a[0], ic_a[1], ic_a[2], ic_a[3], ic_a[4], ic_a[5], ic_a[6], ic_a[7], ic_a[8], ic_a[9], @@ -907,10 +928,8 @@ static void CreateIC( w, ve ) } } -static void SetICValues( w, ve, focus ) - Widget w; - XawVendorShellExtPart *ve; - Boolean focus; +static void +SetICValues(Widget w, XawVendorShellExtPart *ve, Bool focus) { XawIcTableList p; XPoint position; @@ -942,44 +961,44 @@ static void SetICValues( w, ve, focus ) if (p->input_style & (XIMPreeditArea|XIMPreeditPosition|XIMStatusArea)) { if (p->flg & CIFontSet) { - SetVaArg( &pe_a[pe_cnt], (XPointer) XNFontSet); pe_cnt++; - SetVaArg( &pe_a[pe_cnt], (XPointer) p->font_set); pe_cnt++; - SetVaArg( &st_a[st_cnt], (XPointer) XNFontSet); st_cnt++; - SetVaArg( &st_a[st_cnt], (XPointer) p->font_set); st_cnt++; + pe_a[pe_cnt] = (XPointer) XNFontSet; pe_cnt++; + pe_a[pe_cnt] = (XPointer) p->font_set; pe_cnt++; + st_a[st_cnt] = (XPointer) XNFontSet; st_cnt++; + st_a[st_cnt] = (XPointer) p->font_set; st_cnt++; height = maxAscentOfFontSet(p->font_set) + maxDescentOfFontSet(p->font_set); height = SetVendorShellHeight(ve, height); } if (p->flg & CIFg) { - SetVaArg( &pe_a[pe_cnt], (XPointer) XNForeground); pe_cnt++; - SetVaArg( &pe_a[pe_cnt], (XPointer) p->foreground); pe_cnt++; - SetVaArg( &st_a[st_cnt], (XPointer) XNForeground); st_cnt++; - SetVaArg( &st_a[st_cnt], (XPointer) p->foreground); st_cnt++; + pe_a[pe_cnt] = (XPointer) XNForeground; pe_cnt++; + pe_a[pe_cnt] = (XPointer) p->foreground; pe_cnt++; + st_a[st_cnt] = (XPointer) XNForeground; st_cnt++; + st_a[st_cnt] = (XPointer) p->foreground; st_cnt++; } if (p->flg & CIBg) { - SetVaArg( &pe_a[pe_cnt], (XPointer) XNBackground); pe_cnt++; - SetVaArg( &pe_a[pe_cnt], (XPointer) p->background); pe_cnt++; - SetVaArg( &st_a[st_cnt], (XPointer) XNBackground); st_cnt++; - SetVaArg( &st_a[st_cnt], (XPointer) p->background); st_cnt++; + pe_a[pe_cnt] = (XPointer) XNBackground; pe_cnt++; + pe_a[pe_cnt] = (XPointer) p->background; pe_cnt++; + st_a[st_cnt] = (XPointer) XNBackground; st_cnt++; + st_a[st_cnt] = (XPointer) p->background; st_cnt++; } if (p->flg & CIBgPixmap) { - SetVaArg( &pe_a[pe_cnt], (XPointer) XNBackgroundPixmap); pe_cnt++; - SetVaArg( &pe_a[pe_cnt], (XPointer) p->bg_pixmap); pe_cnt++; - SetVaArg( &st_a[st_cnt], (XPointer) XNBackgroundPixmap); st_cnt++; - SetVaArg( &st_a[st_cnt], (XPointer) p->bg_pixmap); st_cnt++; + pe_a[pe_cnt] = (XPointer) XNBackgroundPixmap; pe_cnt++; + pe_a[pe_cnt] = (XPointer) p->bg_pixmap; pe_cnt++; + st_a[st_cnt] = (XPointer) XNBackgroundPixmap; st_cnt++; + st_a[st_cnt] = (XPointer) p->bg_pixmap; st_cnt++; } if (p->flg & CILineS) { - SetVaArg( &pe_a[pe_cnt], (XPointer) XNLineSpace); pe_cnt++; - SetVaArg( &pe_a[pe_cnt], (XPointer) p->line_spacing); pe_cnt++; - SetVaArg( &st_a[st_cnt], (XPointer) XNLineSpace); st_cnt++; - SetVaArg( &st_a[st_cnt], (XPointer) p->line_spacing); st_cnt++; + pe_a[pe_cnt] = (XPointer) XNLineSpace; pe_cnt++; + pe_a[pe_cnt] = (XPointer) p->line_spacing; pe_cnt++; + st_a[st_cnt] = (XPointer) XNLineSpace; st_cnt++; + st_a[st_cnt] = (XPointer) p->line_spacing; st_cnt++; } } if (p->input_style & XIMPreeditPosition) { if (p->flg & CICursorP) { _XawMultiSinkPosToXY(w, p->cursor_position, &position.x, &position.y); - SetVaArg( &pe_a[pe_cnt], (XPointer) XNSpotLocation); pe_cnt++; - SetVaArg( &pe_a[pe_cnt], (XPointer) &position); pe_cnt++; + pe_a[pe_cnt] = (XPointer) XNSpotLocation; pe_cnt++; + pe_a[pe_cnt] = (XPointer) &position; pe_cnt++; } } if (IsSharedIC(ve)) { @@ -993,37 +1012,37 @@ static void SetICValues( w, ve, focus ) pe_area.y += margin->top; pe_area.width -= (margin->left + margin->right - 1); pe_area.height -= (margin->top + margin->bottom - 1); - SetVaArg( &pe_a[pe_cnt], (XPointer) XNArea); pe_cnt++; - SetVaArg( &pe_a[pe_cnt], (XPointer) &pe_area); pe_cnt++; + pe_a[pe_cnt] = (XPointer) XNArea; pe_cnt++; + pe_a[pe_cnt] = (XPointer) &pe_area; pe_cnt++; } } if (pe_cnt > 0) { - SetVaArg( &pe_a[pe_cnt], (XPointer) NULL); + pe_a[pe_cnt] = (XPointer) NULL; pe_attr = XVaCreateNestedList(0, pe_a[0], pe_a[1], pe_a[2], pe_a[3], pe_a[4], pe_a[5], pe_a[6], pe_a[7], pe_a[8], pe_a[9], pe_a[10], pe_a[11], pe_a[12], pe_a[13], pe_a[14], pe_a[15], pe_a[16], pe_a[17], pe_a[18], pe_a[19]); - SetVaArg( &ic_a[ic_cnt], (XPointer) XNPreeditAttributes); ic_cnt++; - SetVaArg( &ic_a[ic_cnt], (XPointer) pe_attr); ic_cnt++; + ic_a[ic_cnt] = (XPointer) XNPreeditAttributes; ic_cnt++; + ic_a[ic_cnt] = (XPointer) pe_attr; ic_cnt++; } if (st_cnt > 0) { - SetVaArg( &st_a[st_cnt], (XPointer) NULL); + st_a[st_cnt] = (XPointer) NULL; st_attr = XVaCreateNestedList(0, st_a[0], st_a[1], st_a[2], st_a[3], st_a[4], st_a[5], st_a[6], st_a[7], st_a[8], st_a[9], st_a[10], st_a[11], st_a[12], st_a[13], st_a[14], st_a[15], st_a[16], st_a[17], st_a[18], st_a[19]); - SetVaArg( &ic_a[ic_cnt], (XPointer) XNStatusAttributes); ic_cnt++; - SetVaArg( &ic_a[ic_cnt], (XPointer) st_attr); ic_cnt++; + ic_a[ic_cnt] = (XPointer) XNStatusAttributes; ic_cnt++; + ic_a[ic_cnt] = (XPointer) st_attr; ic_cnt++; } if (focus == TRUE) { - SetVaArg( &ic_a[ic_cnt], (XPointer) XNFocusWindow); ic_cnt++; - SetVaArg( &ic_a[ic_cnt], (XPointer) XtWindow(w)); ic_cnt++; + ic_a[ic_cnt] = (XPointer) XNFocusWindow; ic_cnt++; + ic_a[ic_cnt] = (XPointer) XtWindow(w); ic_cnt++; } if (ic_cnt > 0) { - SetVaArg( &ic_a[ic_cnt], (XPointer) NULL); + ic_a[ic_cnt] = (XPointer) NULL; XSetICValues(p->xic, ic_a[0], ic_a[1], ic_a[2], ic_a[3], ic_a[4], ic_a[5], ic_a[6], ic_a[7], ic_a[8], ic_a[9], ic_a[10], ic_a[11], ic_a[12], ic_a[13], ic_a[14], ic_a[15], @@ -1038,10 +1057,9 @@ static void SetICValues( w, ve, focus ) p->flg &= ~(CIFontSet | CIFg | CIBg | CIBgPixmap | CICursorP | CILineS); } -static void SharedICChangeFocusWindow(w, ve, p) - Widget w; - XawVendorShellExtPart *ve; - XawIcTableList p; +static void +SharedICChangeFocusWindow(Widget w, XawVendorShellExtPart *ve, + XawIcTableList p) { XawIcTableList pp; @@ -1054,15 +1072,14 @@ static void SharedICChangeFocusWindow(w, ve, p) SetICValues(w, ve, TRUE); } -static XawIcTableList CurrentSharedIcTable( ve ) - XawVendorShellExtPart * ve; +static XawIcTableList +CurrentSharedIcTable(XawVendorShellExtPart *ve) { return(ve->ic.current_ic_table); } -static void SetICFocus(w, ve) - Widget w; - XawVendorShellExtPart * ve; +static void +SetICFocus(Widget w, XawVendorShellExtPart *ve) { XawIcTableList p, pp; @@ -1082,9 +1099,8 @@ static void SetICFocus(w, ve) p->flg &= ~CIICFocus; } -static void UnsetICFocus(w, ve) - Widget w; - XawVendorShellExtPart * ve; +static void +UnsetICFocus(Widget w, XawVendorShellExtPart *ve) { XawIcTableList p, pp; @@ -1103,17 +1119,15 @@ static void UnsetICFocus(w, ve) } } -static void SetValues( w, ve, args, num_args ) - Widget w; - XawVendorShellExtPart * ve; - ArgList args; - Cardinal num_args; +static void +SetValues(Widget w, XawVendorShellExtPart *ve, + ArgList args, Cardinal num_args) { ArgList arg; XrmName argName; XrmResourceList xrmres; - int i; + Cardinal i; XawIcTablePart *p, save_tbl; if ((p = GetIcTable(w, ve)) == NULL) return; @@ -1153,9 +1167,8 @@ static void SetValues( w, ve, args, num_args ) p->prev_flg |= p->flg; } -static void SetFocus( w, ve ) - Widget w; - XawVendorShellExtPart *ve; +static void +SetFocus(Widget w, XawVendorShellExtPart *ve) { XawIcTableList p; if ((p = GetIcTableShared(w, ve)) == NULL) return; @@ -1166,9 +1179,8 @@ static void SetFocus( w, ve ) p->prev_flg |= p->flg; } -static void DestroyIC(w, ve) - Widget w; - XawVendorShellExtPart *ve; +static void +DestroyIC(Widget w, XawVendorShellExtPart *ve) { XawIcTableList p; @@ -1189,17 +1201,14 @@ static void DestroyIC(w, ve) } } -static void SetFocusValues( inwidg, args, num_args, focus ) - Widget inwidg; - ArgList args; - Cardinal num_args; - Boolean focus; +static void +SetFocusValues(Widget inwidg, ArgList args, Cardinal num_args, Bool focus) { XawVendorShellExtPart *ve; VendorShellWidget vw; if ((vw = SearchVendorShell(inwidg)) == NULL) return; - if (ve = GetExtPart(vw)) { + if ((ve = GetExtPart(vw)) != NULL) { if (num_args > 0) SetValues(inwidg, ve, args, num_args); if (focus) SetFocus(inwidg, ve); if (XtIsRealized((Widget)vw) && ve->im.xim) { @@ -1214,15 +1223,15 @@ static void SetFocusValues( inwidg, args, num_args, focus ) } } -static void UnsetFocus( inwidg ) - Widget inwidg; +static void +UnsetFocus(Widget inwidg) { XawVendorShellExtPart *ve; VendorShellWidget vw; XawIcTableList p; if ((vw = SearchVendorShell(inwidg)) == NULL) return; - if (ve = GetExtPart(vw)) { + if ((ve = GetExtPart(vw)) != NULL) { if ((p = GetIcTableShared(inwidg, ve)) == NULL) return; if (p->flg & CIICFocus) { p->flg &= ~CIICFocus; @@ -1234,9 +1243,8 @@ static void UnsetFocus( inwidg ) } } -static Boolean IsRegistered( w, ve ) - Widget w; - XawVendorShellExtPart* ve; +static Bool +IsRegistered(Widget w, XawVendorShellExtPart* ve) { XawIcTableList p; @@ -1247,9 +1255,8 @@ static Boolean IsRegistered( w, ve ) return(FALSE); } -static void Register(inwidg, ve) - Widget inwidg; - XawVendorShellExtPart* ve; +static void +Register(Widget inwidg, XawVendorShellExtPart* ve) { if (ve->im.xim == NULL) { @@ -1269,16 +1276,15 @@ static void Register(inwidg, ve) } } -static Boolean NoRegistered(ve) - XawVendorShellExtPart* ve; +static Bool +NoRegistered(XawVendorShellExtPart* ve) { if (ve->ic.ic_table == NULL) return(TRUE); return(FALSE); } -static void Unregister(inwidg, ve) - Widget inwidg; - XawVendorShellExtPart* ve; +static void +Unregister(Widget inwidg, XawVendorShellExtPart *ve) { if (!IsRegistered(inwidg, ve)) return; @@ -1297,8 +1303,8 @@ static void Unregister(inwidg, ve) } } -static void AllCreateIC( ve ) - XawVendorShellExtPart* ve; +static void +AllCreateIC(XawVendorShellExtPart *ve) { XawIcTableList p; @@ -1320,8 +1326,8 @@ static void AllCreateIC( ve ) } -static void Reconnect(ve) - XawVendorShellExtPart* ve; +static void +Reconnect(XawVendorShellExtPart *ve) { XawIcTableList p; @@ -1345,9 +1351,8 @@ static void Reconnect(ve) } -static void CompileResourceList( res, num_res ) - XtResourceList res; - unsigned int num_res; +static void +CompileResourceList(XtResourceList res, unsigned int num_res) { unsigned int count; @@ -1362,9 +1367,8 @@ static void CompileResourceList( res, num_res ) #undef xrmres } -static Boolean Initialize( vw, ve ) - VendorShellWidget vw; - XawVendorShellExtPart* ve; +static Bool +Initialize(VendorShellWidget vw, XawVendorShellExtPart *ve) { if (!XtIsVendorShell((Widget)vw)) return(FALSE); ve->parent = (Widget)vw; @@ -1390,9 +1394,8 @@ static Boolean Initialize( vw, ve ) * It is called by _XawImDestroy, which is called by Vendor.c's * VendorExt's Destroy method. Sheeran, Omron KK, 93/08/05 */ -static void Destroy( w, ve ) - Widget w; - XawVendorShellExtPart* ve; +static void +Destroy(Widget w, XawVendorShellExtPart *ve) { contextDataRec *contextData; contextErrDataRec *contextErrData; @@ -1420,13 +1423,7 @@ static void Destroy( w, ve ) ********************************************/ void -#if NeedFunctionPrototypes -_XawImResizeVendorShell( - Widget w ) -#else -_XawImResizeVendorShell( w ) - Widget w; -#endif +_XawImResizeVendorShell(Widget w) { XawVendorShellExtPart *ve; @@ -1437,57 +1434,37 @@ _XawImResizeVendorShell( w ) Dimension -#if NeedFunctionPrototypes -_XawImGetShellHeight( - Widget w ) -#else -_XawImGetShellHeight( w ) - Widget w; -#endif +_XawImGetShellHeight(Widget w) { XawVendorShellExtPart *ve; if (!XtIsVendorShell( w ) ) return( w->core.height ); - if ( ve = GetExtPart( (VendorShellWidget) w ) ) { + if ( (ve = GetExtPart( (VendorShellWidget) w )) != NULL ) { return( w->core.height - ve->im.area_height ); } return( w->core.height ); } void -#if NeedFunctionPrototypes -_XawImRealize( - Widget w ) -#else -_XawImRealize( w ) - Widget w; -#endif +_XawImRealize(Widget w) { XawVendorShellExtPart *ve; - extern void XawVendorShellExtResize(); if ( !XtIsRealized( w ) || !XtIsVendorShell( w ) ) return; - if ( ve = GetExtPart( (VendorShellWidget) w ) ) { + if ( (ve = GetExtPart( (VendorShellWidget) w )) != NULL ) { XtAddEventHandler( w, (EventMask)StructureNotifyMask, FALSE, - XawVendorShellExtResize, (XtPointer)NULL ); + XawVendorStructureNotifyHandler, (XtPointer)NULL ); AllCreateIC(ve); } } void -#if NeedFunctionPrototypes -_XawImInitialize( - Widget w, - Widget ext ) -#else -_XawImInitialize( w, ext ) - Widget w, ext; -#endif +_XawImInitialize(Widget w, Widget ext) { XawVendorShellExtPart *ve; if ( !XtIsVendorShell( w ) ) return; - if ( ve = SetExtPart( (VendorShellWidget) w, (XawVendorShellExtWidget)ext ) ) { + if ( (ve = SetExtPart( (VendorShellWidget) w, (XawVendorShellExtWidget)ext )) != NULL ) { if ( Initialize( (VendorShellWidget) w, ve ) == FALSE ) return; XtAddCallback( w, XtNdestroyCallback, VendorShellDestroyed, (XtPointer) NULL ); @@ -1495,122 +1472,63 @@ _XawImInitialize( w, ext ) } void -#if NeedFunctionPrototypes -_XawImReconnect( - Widget inwidg ) -#else -_XawImReconnect( inwidg ) - Widget inwidg; -#endif +_XawImReconnect(Widget inwidg) { XawVendorShellExtPart *ve; VendorShellWidget vw; if ((vw = SearchVendorShell(inwidg)) == NULL) return; - if (ve = GetExtPart(vw)) { + if ((ve = GetExtPart(vw)) != NULL) { Reconnect(ve); } } void -#if NeedFunctionPrototypes -_XawImRegister( - Widget inwidg) -#else -_XawImRegister(inwidg) - Widget inwidg; -#endif +_XawImRegister(Widget inwidg) { XawVendorShellExtPart *ve; VendorShellWidget vw; if ((vw = SearchVendorShell(inwidg)) == NULL) return; - if (ve = GetExtPart(vw)) { + if ((ve = GetExtPart(vw)) != NULL) { Register(inwidg, ve); } } void -#if NeedFunctionPrototypes -_XawImUnregister( - Widget inwidg) -#else -_XawImUnregister(inwidg) - Widget inwidg; -#endif +_XawImUnregister(Widget inwidg) { XawVendorShellExtPart *ve; VendorShellWidget vw; if ((vw = SearchVendorShell(inwidg)) == NULL) return; - if (ve = GetExtPart(vw)) { + if ((ve = GetExtPart(vw)) != NULL) { Unregister(inwidg, ve); } } void -#if NeedFunctionPrototypes -_XawImSetValues( - Widget inwidg, - ArgList args, - Cardinal num_args ) -#else -_XawImSetValues( inwidg, args, num_args ) - Widget inwidg; - ArgList args; - Cardinal num_args; -#endif +_XawImSetValues(Widget inwidg, ArgList args, Cardinal num_args) { SetFocusValues( inwidg, args, num_args, FALSE ); } void -#if NeedFunctionPrototypes -_XawImSetFocusValues( - Widget inwidg, - ArgList args, - Cardinal num_args) -#else -_XawImSetFocusValues(inwidg, args, num_args) - Widget inwidg; - ArgList args; - Cardinal num_args; -#endif +_XawImSetFocusValues(Widget inwidg, ArgList args, Cardinal num_args) { SetFocusValues(inwidg, args, num_args, TRUE); } void -#if NeedFunctionPrototypes -_XawImUnsetFocus( - Widget inwidg) -#else -_XawImUnsetFocus(inwidg) - Widget inwidg; -#endif +_XawImUnsetFocus(Widget inwidg) { UnsetFocus(inwidg); } int -#if NeedFunctionPrototypes -_XawImWcLookupString( - Widget inwidg, - XKeyPressedEvent *event, - wchar_t* buffer_return, - int bytes_buffer, - KeySym *keysym_return, - Status *status_return) -#else -_XawImWcLookupString( inwidg, event, buffer_return, bytes_buffer, - keysym_return, status_return) - Widget inwidg; - XKeyPressedEvent* event; - wchar_t* buffer_return; - int bytes_buffer; - KeySym* keysym_return; - Status* status_return; -#endif +_XawImWcLookupString(Widget inwidg, XKeyPressedEvent *event, + wchar_t* buffer_return, int bytes_buffer, + KeySym *keysym_return) { XawVendorShellExtPart* ve; VendorShellWidget vw; @@ -1621,11 +1539,11 @@ _XawImWcLookupString( inwidg, event, buffer_return, bytes_buffer, if ((vw = SearchVendorShell(inwidg)) && (ve = GetExtPart(vw)) && ve->im.xim && (p = GetIcTableShared(inwidg, ve)) && p->xic) { - return(XwcLookupString(p->xic, event, buffer_return, bytes_buffer, - keysym_return, status_return)); + return(XwcLookupString(p->xic, event, buffer_return, bytes_buffer/sizeof(wchar_t), + keysym_return, NULL)); } - ret = XLookupString( event, tmp_buf, 64, keysym_return, - (XComposeStatus*) status_return ); + ret = XLookupString( event, tmp_buf, sizeof(tmp_buf), keysym_return, + NULL ); for ( i = 0, tmp_p = tmp_buf, buf_p = buffer_return; i < ret; i++ ) { *buf_p++ = _Xaw_atowc(*tmp_p++); } @@ -1633,13 +1551,24 @@ _XawImWcLookupString( inwidg, event, buffer_return, bytes_buffer, } int -#if NeedFunctionPrototypes -_XawImGetImAreaHeight( - Widget w) -#else -_XawImGetImAreaHeight( w ) - Widget w; -#endif +_XawLookupString(Widget w, XKeyEvent *event, char *buffer_return, int buffer_size, + KeySym *keysym_return) +{ + XawVendorShellExtPart *ve; + VendorShellWidget vw; + XawIcTableList p; + + if ((vw = SearchVendorShell(w)) && (ve = GetExtPart(vw)) + && ve->im.xim && (p = GetIcTableShared(w, ve)) && p->xic) + return (XmbLookupString(p->xic, event, buffer_return, buffer_size, + keysym_return, NULL)); + + return (XLookupString(event, buffer_return, buffer_size, + keysym_return, NULL)); +} + +int +_XawImGetImAreaHeight(Widget w) { XawVendorShellExtPart *ve; VendorShellWidget vw; @@ -1651,20 +1580,13 @@ _XawImGetImAreaHeight( w ) } void -#if NeedFunctionPrototypes -_XawImCallVendorShellExtResize( - Widget w) -#else -_XawImCallVendorShellExtResize( w ) - Widget w; -#endif +_XawImCallVendorShellExtResize(Widget w) { XawVendorShellExtPart *ve; VendorShellWidget vw; - extern void XawVendorShellExtResize(); if ((vw = SearchVendorShell(w)) && (ve = GetExtPart(vw))) { - XawVendorShellExtResize(vw); + XawVendorShellExtResize((Widget)vw); } } @@ -1675,19 +1597,11 @@ _XawImCallVendorShellExtResize( w ) * core Destroy method. Sheeran, Omron KK 93/08/05 */ void -#if NeedFunctionPrototypes -_XawImDestroy( - Widget w, - Widget ext ) -#else -_XawImDestroy( w, ext ) - Widget w; - Widget ext; -#endif +_XawImDestroy(Widget w, Widget ext) { XawVendorShellExtPart *ve; if ( !XtIsVendorShell( w ) ) return; - if ( ve = GetExtPart( (VendorShellWidget) w ) ) + if ( (ve = GetExtPart( (VendorShellWidget) w )) != NULL ) Destroy( w, ve ); } diff --git a/src/XawInit.c b/src/XawInit.c index f30f49f..211f014 100644 --- a/src/XawInit.c +++ b/src/XawInit.c @@ -32,17 +32,24 @@ in this Software without prior written authorization from The Open Group. * call this routine from their ClassInitialize procs (this routine may be * used as the class init proc). */ +/* $XFree86: xc/lib/Xaw/XawInit.c,v 1.10 2001/12/14 19:54:46 dawes Exp $ */ #include <X11/Intrinsic.h> #include <X11/Vendor.h> #include <X11/Xaw/XawInit.h> +#include "Private.h" -void XawInitializeWidgetSet () +void +XawInitializeWidgetSet(void) { - static int firsttime = 1; + static Boolean firsttime = True; if (firsttime) { - firsttime = 0; - XtInitializeWidgetClass (vendorShellWidgetClass); + firsttime = False; +#ifndef OLDXAW + XawPixmapsInitialize(); + XawInitializeDefaultConverters(); +#endif + XtInitializeWidgetClass(vendorShellWidgetClass); } } |