749N/A * Copyright 1991 by OMRON Corporation 749N/A * Permission to use, copy, modify, distribute, and sell this software and its 749N/A * documentation for any purpose is hereby granted without fee, provided that 749N/A * the above copyright notice appear in all copies and that both that 749N/A * copyright notice and this permission notice appear in supporting 749N/A * documentation, and that the name OMRON not be used in 749N/A * advertising or publicity pertaining to distribution of the software without 749N/A * specific, written prior permission. OMRON makes no representations 749N/A * about the suitability of this software for any purpose. It is provided 749N/A * "as is" without express or implied warranty. 749N/A * OMRON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 749N/A * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 749N/A * EVENT SHALL OMRON BE LIABLE FOR ANY SPECIAL, INDIRECT OR 749N/A * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 749N/A * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 749N/A * TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 749N/A * PERFORMANCE OF THIS SOFTWARE. 749N/A * Authors: Chris Peterson MIT X Consortium 749N/A * Li Yuhong OMRON Corporation 749N/A * Frank Sheeran OMRON Corporation 749N/A * Much code taken from X11R3 String and Disk Sources. 749N/ACopyright (c) 1991, 1994 X Consortium 749N/APermission is hereby granted, free of charge, to any person obtaining a copy 749N/Aof this software and associated documentation files (the "Software"), to deal 749N/Ain the Software without restriction, including without limitation the rights 749N/Ato use, copy, modify, merge, publish, distribute, sublicense, and/or sell 749N/Acopies of the Software, and to permit persons to whom the Software is 749N/Afurnished to do so, subject to the following conditions: 749N/AThe above copyright notice and this permission notice shall be included in 749N/Aall copies or substantial portions of the Software. 749N/ATHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 749N/AIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 749N/AFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 749N/AX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 749N/AAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 749N/ACONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 749N/AExcept as contained in this notice, the name of the X Consortium shall not be 749N/Aused in advertising or otherwise to promote the sale, use or other dealings 749N/Ain this Software without prior written authorization from the X Consortium. 749N/A/**************************************************************** 749N/A * Full class record constant 749N/A ****************************************************************/ 749N/A {
/* object_class fields */ 749N/A /* class_name */ "MultiSrc",
749N/A {
/* textSrc_class fields */ 749N/A {
/* multiSrc_class fields */ 749N/A /* Keep the compiler happy */ '\0' 749N/A/************************************************************ 749N/A * Semi-Public Interfaces. 749N/A ************************************************************/ 749N/A/* Function Name: ClassInitialize 749N/A * Description: Class Initialize routine, called only once. 749N/A/* Function Name: Initialize 749N/A * Description: Initializes the simple menu widget 749N/A * Arguments: request - the widget requested by the argument list. 749N/A * new - the new widget with both resource and non 749N/A * Set correct flags (override resources) depending upon widget class. 749N/A/* Function Name: ReadText 749N/A * Description: This function reads the source. 749N/A * Arguments: w - the MultiSource widget. 749N/A * pos - position of the text to retreive. 749N/A * RETURNED text - text block that will contain returned text. 749N/A * length - maximum number of characters to read. 749N/A * Returns: The number of characters read into the buffer. 749N/A/* Function Name: ReplaceText. 749N/A * Description: Replaces a block of text with new text. 749N/A * Arguments: w - the MultiSource widget. 749N/A * startPos, endPos - ends of text that will be removed. 749N/A * text - new text to be inserted into buffer at startPos. 749N/A * Returns: XawEditError or XawEditDone. 749N/A /* STEP 1: The user handed me a text block called `u_text' that may be 749N/A * in either FMTWIDE or FMT8BIT (ie MB.) Later code needs the block 749N/A * `text' to hold FMTWIDE. So, this copies `u_text' to `text', and if 749N/A * `u_text' was MB, I knock it up to WIDE. */ 749N/A /* text.format is unneeded */ 749N/A /* WARNING! u_text->firstPos and length are in units of CHAR, not CHARACTERS! */ 749N/A /* I assert the following assignment is not needed - since Step 4 749N/A depends on length, it has no need of a terminating NULL. I think 749N/A the ASCII-version has the same needless NULL. */ 749N/A /*((wchar_t*)text.ptr)[ text.length ] = NULL;*/ 749N/A /* STEP 2: some initialization... */ 749N/A /* STEP 3: remove the empty pieces... */ 749N/A /* If empty and not the only piece then remove it. */ 749N/A else {
/* We are fully in one piece. */ 749N/A /*((TextWidget)src->object.parent)->text.lastPos = src->multi_src.length;*/ 749N/A /* STEP 4: insert the new stuff */ 749N/A * The string is used in place, then the string 749N/A * is not allowed to grow. 749N/A /*((TextWidget)src->object.parent)->text.lastPos = src->multi_src.length;*/ 749N/A /* In other words, text is not the u_text that the user handed me but 749N/A one I made myself. I only care, because I need to free the string. */ 749N/A * Description: Scans the text source for the number and type 749N/A * Arguments: w - the MultiSource widget. 749N/A * position - the position to start scanning. 749N/A * type - type of thing to scan for. 749N/A * dir - direction to scan. 749N/A * count - which occurance if this thing to search for. 749N/A * include - whether or not to include the character found in 749N/A * the position that is returned. 749N/A * Returns: the position of the item found. 749N/A * Note: While there are only 'n' characters in the file there are n+1 749N/A * possible cursor positions (one before the first character and 749N/A * one after the last character. 749N/A /* STEP 1: basic sanity checks */ 749N/A else {
/* XawstParagraph */ 749N/A/* case XawstAll: ---- handled in special code above */ 749N/A/* Function Name: Search 749N/A * Description: Searchs the text source for the text block passed 749N/A * Arguments: w - the MultiSource Widget. 749N/A * position - the position to start scanning. 749N/A * dir - direction to scan. 749N/A * text - the text block to search for. 749N/A * Returns: the position of the item found. 749N/A /* STEP 1: First, a brief sanity check. */ 749N/A /* STEP 2: Ensure I have a local wide string.. */ 749N/A /* Since this widget stores 32bit chars, I check here to see if 749N/A I'm being passed a string claiming to be 8bit chars (ie, MB text.) 749N/A If that is the case, naturally I convert to 32bit format. */ 749N/A /*if the block was FMT8BIT, length will convert to REAL wchar count below */ 749N/A /* The following converts wtarget_len from byte len to wchar count */ 749N/A /* OK, I can now assert that wtarget holds wide characters, wtarget_len 749N/A holds an accurate count of those characters, and that firstPos has been 749N/A effectively factored out of the following computations. */ 749N/A/* Function Name: SetValues 749N/A * Description: Sets the values for the MultiSource. 749N/A * Arguments: current - current state of the widget. 749N/A * request - what was requested. 749N/A * new - what the widget will become. 749N/A * Returns: True if redisplay is needed. 749N/A "MultiSrc: The XtNuseStringInPlace resources may not be changed.");
749N/A /* Load pieces does this logic for us, but it shouldn't. Its messy.*/ 749N/A /* If the buffer holds bad chars, don't touch it... */ 749N/A "convertError",
"multiSource",
"XawError",
749N/A "convertError",
"multiSource",
"XawError",
749N/A/* Function Name: GetValuesHook 749N/A * Description: This is a get values hook routine that sets the 749N/A * values specific to the multi source. 749N/A * Arguments: w - the MultiSource Widget. 749N/A * args - the argument list. 749N/A * num_args - the number of args. 749N/A/* Function Name: Destroy 749N/A * Description: Destroys an multi source (frees all data) 749N/A * Arguments: src - the Multi source Widget to free. 749N/A/************************************************************ 749N/A ************************************************************/ 749N/A/* Function Name: XawMultiSourceFreeString 749N/A * Description: Frees the string returned by a get values call 749N/A * on the string when the source is of type string. 749N/A * Arguments: w - the MultiSrc widget. 749N/A * The public interface is XawAsciiSourceFreeString! 749N/A/*if (src->multi_src.allocated_string&& src->multi_src.type != XawAsciiFile) {*/ 749N/A /* ASSERT: src->multi_src.allocated_string -> we MUST free .string! */ 749N/A/* Function Name: _XawMultiSave 749N/A * Description: Saves all the pieces into a file or string as required. 749N/A * Arguments: w - the multiSrc Widget. 749N/A * Returns: TRUE if the save was successful. 749N/A * The public interface is XawAsciiSave(w)! 749N/A * If using the string in place then there is no need to play games 749N/A * to get the internal info into a readable string. 749N/A /* If the buffer holds bad chars, don't touch it... */ 749N/A "convertError",
"multiSource",
"XawError",
749N/A /* THIS FUNCTIONALITY IS UNDOCUMENTED, probably UNNEEDED? The manual 749N/A says this routine's only function is to save files to disk. -Sheeran */ 749N/A /* If the buffer holds bad chars, don't touch it... */ 749N/A "convertError",
"multiSource",
"XawError",
749N/A /* assert: mb_string holds good characters so the buffer is fine */ 749N/A/* Function Name: XawMultiSaveAsFile 749N/A * Description: Save the current buffer as a file. 749N/A * Arguments: w - the MultiSrc widget. 749N/A * name - name of the file to save this file into. 749N/A * Returns: True if the save was sucessful. 749N/A * The public interface is XawAsciiSaveAsFile! 749N/A /* otherwise there was a conversion error. So print widget name too. */ 749N/A "convertError",
"multiSource",
"XawError",
749N/A/************************************************************ 749N/A ************************************************************/ 749N/A/* Function Name: WriteToFile 749N/A * Description: Write the string specified to the begining of the file 749N/A * Arguments: string - string to write. 749N/A * name - the name of the file 749N/A * Returns: returns TRUE if sucessful, FALSE otherwise. 749N/A/* Function Name: StorePiecesInString 749N/A * Description: store the pieces in memory into a char string. 749N/A * Arguments: src - the multiSrc to gather data from 749N/A * Returns: char *mb_string. Caller must free. 749N/A * or 0: conversion error. Caller must panic! 749N/A /* I believe the char_count + 1 and the NULL termination are unneeded! FS*/ 749N/A /* This will refill all pieces to capacity. */ 749N/A /* Lastly, convert it to a MB format and send it back. */ 749N/A /* NOTE THAT mb_string MAY BE ZERO IF THE CONVERSION FAILED. */ 749N/A/* Function Name: InitStringOrFile. 749N/A * Description: Initializes the string or file. 749N/A * Arguments: src - the MultiSource. 749N/A * Returns: none - May exit though. 749N/A /* Wasteful, throwing away the WC string, but need side effect! */ 749N/A /* In case the length resource is incorrectly set */ 749N/A /*((TextWidget)src->object.parent)->text.lastPos = src->multi_src.length;*/ 749N/A * type is XawAsciiFile. 749N/A "Creating a read only disk widget and no file specified.",
749N/A "Bad editMode for multi source; must be Read, Append or Edit.",
749N/A /* Allocate new memory for the temp filename, because it is held in 749N/A * a stack memory buffer. We must verify that all routines that set 749N/A * .string first check .allocated_string and free it - plumbing Sheeran. 749N/A "openError",
"multiSourceCreate",
"XawWarning",
749N/A/* LoadPieces: This routine takes either the MB contents of open file `file' or the 749N/Athem in Pieces in WC format. 749N/ACAUTION: You must have src->multi_src.length set to file length bytes 749N/Athe length of the parameter string if string is non-NULL. */ 749N/A * This is tricky - the _XawTextMBtoWC converter uses its 3rd arg 749N/A * in as MB length, out as WC length. We want local_length to be 749N/A * ASSERT: IF our caller passed a non-null string, THEN 749N/A * src->multi_src.length is currently string's * byte count, 749N/A * AND string is in a MB format. 749N/A * here, we are not changing the contents, just reloading, 749N/A * so don't change len... 749N/A "readError",
"multiSource",
"XawError",
749N/A "<<< FILE CONTENTS NOT REPRESENTABLE IN THIS LOCALE >>>";
749N/A "readLocaleError",
"multiSource",
"XawError",
749N/A "%s: The file `%s' contains characters not representable in this locale.",
749N/A }
else {
/*ASSERT that since following while loop looks at local_length 749N/A this isn't needed. Sheeran, Omron KK, 1993/07/15 749N/A temp_mb_holder[src->multi_src.length] = '\0';*/ 749N/A/* Function Name: AllocNewPiece 749N/A * Description: Allocates a new piece of memory. 749N/A * Arguments: src - The MultiSrc Widget. 749N/A * prev - the piece just before this one, or NULL. 749N/A * Returns: the allocated piece. 749N/A/* Function Name: FreeAllPieces 749N/A * Description: Frees all the pieces 749N/A * Arguments: src - The MultiSrc Widget. 749N/A printf(
"Xaw MultiSrc Object: possible memory leak in FreeAllPieces().\n");
749N/A/* Function Name: RemovePiece 749N/A * Description: Removes a piece from the list. 749N/A * piece - the piece to remove. 749N/A/* Function Name: FindPiece 749N/A * Description: Finds the piece containing the position indicated. 749N/A * Arguments: src - The MultiSrc Widget. 749N/A * position - the position that we are searching for. 749N/A * RETURNED first - the position of the first character in this piece. 749N/A * Returns: piece - the piece that contains this position. 749N/A return(
old_piece);
/* if we run off the end the return the last piece */ 749N/A/* Function Name: BreakPiece 749N/A * Description: Breaks a full piece into two new pieces. 749N/A * Arguments: src - The MultiSrc Widget. 749N/A * piece - the piece to break. 749N/A/* Convert string "XawAsciiString" and "XawAsciiFile" to quarks. */