1 /* Copyright (C) 1992-1998 The Geometry Center
2  * Copyright (C) 1998-2000 Stuart Levy, Tamara Munzner, Mark Phillips
3  *
4  * This file is part of Geomview.
5  *
6  * Geomview is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published
8  * by the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * Geomview is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with Geomview; see the file COPYING.  If not, write
18  * to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
19  * USA, or visit http://www.gnu.org.
20  */
21 
22 #if HAVE_CONFIG_H
23 # include "config.h"
24 #endif
25 
26 #if 0
27 static char copyright[] = "Copyright (C) 1992-1998 The Geometry Center\n\
28 Copyright (C) 1998-2000 Stuart Levy, Tamara Munzner, Mark Phillips";
29 #endif
30 
31 #include "mibload.h"
32 #include "mibwidgets.h"
33 
34 extern Display	*dpy;
35 extern GC	 mib_gc;
36 
37 /* Code for TextBox */
38 /*****************************************************************************/
39 
mib_create_TextBox(mib_Widget * parent,char * name,char * contents,int posx,int posy,int width,int height,int mib_fill)40 mib_Widget *mib_create_TextBox(mib_Widget *parent, char *name, char *contents,
41 	int posx, int posy, int width, int height,
42 	int mib_fill)
43 {
44   mib_Widget *temp;
45   mib_TextBox *myres;
46   Arg     args[20];
47   int     n;
48 
49   /* create the new widget and add it to the tree */
50 
51   temp = mib_new_mib_Widget();
52   if (mib_fill == WDEFAULT)
53     mib_add_backward(temp, parent);
54   else
55     mib_add_mib_Widget(temp, parent);
56   myres = (mib_TextBox *)malloc(sizeof(mib_TextBox));
57 
58   /* initialize public resources */
59 
60   if (mib_fill == WDEFAULT)
61   {
62     temp->name = (char *)malloc(strlen(name)+1);
63     strcpy(temp->name,name);
64   }
65   temp->mib_class = (char *)malloc(8);
66   sprintf(temp->mib_class,"TextBox");
67   temp->mib_class_num = MIB_TEXTBOX;
68   temp->width = width;
69   temp->height = height;
70   temp->topOffset = posy;
71   temp->leftOffset = posx;
72   temp->bottomOffset = 0;
73   temp->rightOffset = 0;
74   temp->topAttachment = 1;
75   temp->leftAttachment = 1;
76   temp->bottomAttachment = 0;
77   temp->rightAttachment = 0;
78 
79   temp->mib_allowresize = 1;
80 
81   /* initialize private resources */
82 
83   temp->myres = (void *)myres;
84   myres->init_contents = NULL;
85 
86   if (mib_fill == WDEFAULT)
87   {
88     if (contents != NULL)
89     {
90       myres->init_contents = (char *)malloc(strlen(contents)+1);
91       strcpy(myres->init_contents, contents);
92     }
93   }
94 
95   /* create Xt widget */
96 
97   n = 0;
98 
99   if (mib_fill == WDEFAULT)
100   {
101     XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
102     XtSetArg (args[n], XmNleftOffset, posx);n++;
103     XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
104     XtSetArg (args[n], XmNtopOffset, posy);n++;
105     XtSetArg (args[n], XmNwidth, width); n++;
106     XtSetArg (args[n], XmNheight, height); n++;
107   }
108 
109   XtSetArg (args[n], XmNrubberPositioning, False); n++;
110   XtSetArg (args[n], XmNhighlightThickness, 0); n++;
111 
112   temp->me = XtCreateManagedWidget(name, xmTextFieldWidgetClass,
113                 temp->parent->me, args, n);
114 
115   if (mib_fill == WEDIT || mib_fill == WDEFAULT)
116   {
117     mib_apply_eventhandlers(temp->me, temp);
118     XmTextFieldSetString(temp->me, "Text Field");
119 
120   }
121 
122   return temp;
123 }
124 
mib_delete_TextBox(mib_Widget * this)125 void mib_delete_TextBox(mib_Widget *this)
126 {
127   mib_TextBox *temp = (mib_TextBox *)this->myres;
128 
129   if (temp->init_contents != NULL)
130     free(temp->init_contents);
131 }
132 
mib_save_TextBox(mib_Widget * this,FILE * fout)133 void mib_save_TextBox(mib_Widget *this, FILE *fout)
134 {
135 }
136 
mib_load_TextBox(mib_Widget * this,mib_Buffer * fin)137 int mib_load_TextBox(mib_Widget *this, mib_Buffer *fin)
138 {
139   char          res[MI_MAXSTRLEN];
140   char          val[MI_MAXSTRLEN];
141 
142   if (!mib_read_line(fin, res, val))
143     return 0;
144 
145   if (!strcmp(res,"EndWidget."))
146     return 0;
147 
148   return 1;
149 }
150