1
2 /* editarea.c - part of asedit program */
3 /*
4 * Copyright 1991 - 1994, Andrzej Stochniol, London, UK
5 *
6 * ASEDIT text editor, both binary and source (hereafter, Software) is
7 * copyrighted by Andrzej Stochniol (hereafter, AS) and ownership remains
8 * with AS.
9 *
10 * AS grants you (hereafter, Licensee) a license to use the Software
11 * for academic, research and internal business purposes only, without a
12 * fee. Licensee may distribute the binary and source code (if released)
13 * to third parties provided that the copyright notice and this statement
14 * appears on all copies and that no charge is associated with such copies.
15 *
16 * Licensee may make derivative works. However, if Licensee distributes
17 * any derivative work based on or derived from the Software, then
18 * Licensee will:
19 * (1) notify AS regarding its distribution of the derivative work, and
20 * (2) clearly notify users that such derivative work is a modified version
21 * and not the original ASEDIT distributed by AS.
22 *
23 * Any Licensee wishing to make commercial use of the Software should
24 * contact AS to negotiate an appropriate license for such commercial use.
25 * Commercial use includes:
26 * (1) integration of all or part of the source code into a product for sale
27 * or license by or on behalf of Licensee to third parties, or
28 * (2) distribution of the binary code or source code to third parties that
29 * need it to utilize a commercial product sold or licensed by or on
30 * behalf of Licensee.
31 *
32 * A. STOCHNIOL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS
33 * SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR
34 * IMPLIED WARRANTY. IN NO EVENT SHALL A. STOCHNIOL BE LIABLE FOR ANY
35 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
36 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
37 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
38 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
39 *
40 * By using or copying this Software, Licensee agrees to abide by the
41 * copyright law and all other applicable laws, and the terms of this
42 * license.
43 * AS shall have the right to terminate this license immediately by
44 * written notice upon Licensee's breach of, or non-compliance with, any
45 * of its terms. Licensee may be held legally responsible for any
46 * copyright infringement that is caused or encouraged by Licensee's
47 * failure to abide by the terms of this license.
48 *
49 *
50 * Andrzej Stochniol (A.Stochniol@ic.ac.uk)
51 * 30 Hatch Road
52 * London SW16 4PN
53 * UK
54 */
55
56
57 #include <stdio.h>
58 #include <string.h>
59
60 #include <Xm/Text.h>
61 #include <Xm/Form.h>
62 #include <Xm/Frame.h>
63 #include <Xm/RowColumn.h>
64 #include <Xm/Label.h>
65 #include <Xm/PanedW.h>
66
67 #include <Xm/XmP.h> /* needed for declaration of _XmSelectColorDefault (prcatically needed only since Motif 1.2x) */
68
69 #include "asedit.h"
70
71 /***************************** CreateScrolledText **************************
72 **
73 ** Create Scrolled Text widget and set the colour of recessed windows.
74 */
75 #ifdef _NO_PROTO
CreateScrolledText(parent,wrap_on)76 static Widget CreateScrolledText (parent, wrap_on)
77 Widget parent;
78 Boolean wrap_on;
79 #else /* ! _NO_PROTO */
80
81 static Widget CreateScrolledText (Widget parent, Boolean wrap_on)
82 #endif
83 {
84 Arg al[10]; /* arg list */
85 register int ac; /* arg count */
86 Pixel foreground; /* used for a proper set up of mono screens */
87 Widget text;
88
89 /* create scrolled text widget */
90 ac = 0;
91 XtSetArg (al[ac], XmNresizeWidth, False); ac++;
92 XtSetArg (al[ac], XmNresizeHeight, False); ac++;
93 XtSetArg (al[ac], XmNscrollVertical, True); ac++;
94 XtSetArg (al[ac], XmNscrollHorizontal, !wrap_on); ac++;
95 XtSetArg (al[ac], XmNwordWrap, wrap_on); ac++;
96 XtSetArg (al[ac], XmNeditMode, XmMULTI_LINE_EDIT); ac++;
97
98 text = XmCreateScrolledText (parent, "edit_text", al, ac);
99
100 /* add value changed callback - we do not use that now
101 XtAddCallback (text, XmNvalueChangedCallback,
102 (XtCallbackProc)TextCB, (XtPointer)NULL);
103 (if ever start usign that again look out for mk_asdat !! ***/
104
105 /* add the focus callback to recognize which one of two text widgets
106 is currently being used to edit the text*/
107 XtAddCallback (text, XmNfocusCallback,
108 (XtCallbackProc)TextCB, mk_asdat(0) );
109
110 /* add gain/losePrimary callbacks (used to set sensitivities
111 in the edit and tools menus) */
112 XtAddCallback (text, XmNlosePrimaryCallback,
113 (XtCallbackProc)TextCB, mk_asdat(0) );
114 XtAddCallback (text, XmNgainPrimaryCallback,
115 (XtCallbackProc)TextCB, mk_asdat(0) );
116
117 /* add modify verify callback (may be used to check changes) */
118 XtAddCallback (text, XmNmodifyVerifyCallback,
119 (XtCallbackProc)TextCB, mk_asdat(0) );
120 /* add motion callback */
121 XtAddCallback (text, XmNmotionVerifyCallback,
122 (XtCallbackProc)TextCB, mk_asdat(0) );
123 /* add the help callback - TEMP we use XTEXT_HELP as a call data */
124 XtAddCallback (text, XmNhelpCallback,
125 (XtCallbackProc)HelpCB, mk_asdat(HTEXT_HELP) );
126
127 /* get the standard colours of the scrolled background */
128 ac = 0;
129 XtSetArg(al[ac], XmNbackground, &text_edit_background); ac++;
130 XtSetArg(al[ac], XmNforeground, &foreground); ac++;
131 XtGetValues(text, al, ac);
132
133 if(lstr.useOldColorSetup)
134 {
135 text_read_only_background = text_edit_background;
136
137 /* Set colours of recessed widgets (text & scrollbars)
138 We are doing that only for screens supporting more than 16
139 colours (theoritically it should be done if the colour
140 display is available, but practically if we have less than 16
141 colours all of them probably have been already used up
142 and the nearest available colour which will be assigned
143 maybe inappropriate )*/
144
145 if (DefaultDepthOfScreen(XDefaultScreenOfDisplay(display)) > 4)
146 {
147 Widget scrolled_window;
148 Widget hsbar, vsbar; /* ScrollBars */
149 XrmValue pixel_data;
150
151 scrolled_window = XtParent(text);
152 ac = 0;
153 if(!wrap_on)
154 XtSetArg (al[ac], XmNhorizontalScrollBar, &hsbar); ac++;
155 XtSetArg (al[ac], XmNverticalScrollBar, &vsbar); ac++;
156 XtGetValues (scrolled_window, al, ac); /* get scroll bars .. */
157
158 /* get a colour to be used for editable text widgets and remember it */
159 _XmSelectColorDefault (scrolled_window, 0 , &pixel_data);
160 text_edit_background = *((Pixel *) pixel_data.addr);
161
162 /* now check if the text_edit_background is not by chance identical
163 with the foreground (it happens on mono screens or for a black/white
164 setup); if so do not apply it, but use the standard background.
165 */
166 if(text_edit_background == foreground)
167 text_edit_background = text_read_only_background;
168
169 XtSetArg (al[0], XmNbackground, text_edit_background);
170
171 /* XtSetValues (text, al, 1); - do not set it now; if the text
172 is editable this colour will be assigned when a file is read in */
173 if(!wrap_on)
174 XtSetValues (hsbar, al, 1);
175 XtSetValues (vsbar, al, 1);
176 }
177 } /* useOldColorSetup */
178 else
179 {
180 /* all colours are set via resources; we've already stored the current
181 text widget background as the text_edit_background;
182 as the text_read_only_background use the value from
183 the user resources: lstr.readOnlyBackground (we don't
184 use it directly to use alternatively the Old color setup)
185 */
186 text_read_only_background = lstr.readOnlyBackground;
187 }
188
189 return(text);
190
191 } /* CreateScrolledText */
192
193
194 /***************************** CreateEditWorkArea *************************
195 create work area form. Inside the form there will be pane widget (with two
196 scrolled text widget) and status line (bottom_row)
197 The status line and one of the text widget might be unmanaged using
198 Options menu.
199 */
200 #ifdef _NO_PROTO
CreateEditWorkArea(win,parent)201 Widget CreateEditWorkArea(win, parent)
202 aseditWindowStruct *win;
203 Widget parent;
204 #else /* ! _NO_PROTO */
205
206 Widget CreateEditWorkArea(aseditWindowStruct *win, Widget parent)
207 #endif
208 {
209
210 Widget form_work; /* form for the work area */
211 Widget form_frame_bottom; /* to envelope frame_bottom; needed for
212 proper management when frame_bottom is unmanaged/managed */
213 Widget row_column; /* RowColumn */
214 Widget pane; /* Pane */
215 Widget wline, wcolumn;
216
217 Arg al[10]; /* arg list */
218 register int ac; /* arg count */
219 Dimension height;
220
221
222
223 /* Create a form widget for the work area */
224 ac = 0;
225
226 form_work = XtCreateWidget("form_work", xmFormWidgetClass,
227 parent, al, ac);
228 /* Create paned window. */
229
230 ac = 0;
231 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
232 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
233 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
234 /* bottom attachement will be set when the bottom_row widget is available ... */
235
236 pane = XtCreateWidget ("pane", xmPanedWindowWidgetClass,
237 form_work, al, ac);
238
239 /* Create Text (1) inside a pane */
240 /** wrap_in_AS_COM_only: win->edit_text1 = CreateScrolledText (pane, False); **/
241 win->edit_text1 = CreateScrolledText (pane, lstr.defaultWrap);
242 XtManageChild (win->edit_text1);
243
244 # if (XmVersion == 1000)
245 XmAddTabGroup(win->edit_text1);
246 # endif
247
248 XtSetSensitive(win->edit_text1, False);
249
250 /* set initial value for edit_text .... */
251 win->edit_text = win->edit_text1;
252
253 /* get the default font list ... */
254 ac=0;
255 XtSetArg(al[ac], XmNfontList, &default_fontlist); ac++;
256 XtGetValues(win->edit_text1, al, ac);
257
258
259
260
261 XtManageChild(pane);
262
263
264 /* create a frame for the bottom row of edit informations ... */
265
266 ac = 0;
267 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
268 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
269 XtSetArg(al[ac], XmNbottomAttachment,XmATTACH_FORM); ac++;
270
271 form_frame_bottom = XmCreateForm(form_work, "form_frame_bottom", al, ac);
272
273 ac = 0;
274 /* since ver. 1.27 shadowType $ shadowThickness are set in the
275 application resource file (to support SGI schemes idea)
276 XtSetArg (al[ac], XmNshadowThickness, 2); ac++;
277 XtSetArg (al[ac], XmNshadowType, XmSHADOW_IN); ac++;
278 */
279
280 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
281 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
282 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
283 XtSetArg(al[ac], XmNbottomAttachment,XmATTACH_FORM); ac++;
284
285 win->frame_bottom = XmCreateFrame (form_frame_bottom, "frame_bottom_row", al, ac);
286
287
288 /* create an XmRowColumn widget containing 5 XmLabelwidgets */
289 ac = 0;
290 XtSetArg (al[ac], XmNadjustLast, False); ac++; /* to stop stretching
291 of the last widget */
292
293 XtSetArg(al[ac], XmNorientation, XmHORIZONTAL); ac++;
294 XtSetArg(al[ac], XmNnumColumns, 1); ac++; /* for horizontal design it is == 1 row */
295
296 row_column = XmCreateRowColumn (win->frame_bottom, "bottom_row", al, ac);
297
298 ac = 0;
299 win->changes_status = XmCreateLabel (row_column, " ", al, ac); /* 1 space */
300 XtManageChild (win->changes_status);
301
302 ac = 0;
303 wline = XmCreateLabel (row_column, "line", al, ac);
304 XtManageChild (wline);
305
306 ac = 0;
307 win->line_number = XmCreateLabel (row_column, "1 ", al, ac); /* space
308 reserved for numbers as big as: "99999"
309 plus a leading and trailing space */
310
311 XtManageChild (win->line_number);
312
313 ac = 0;
314 wcolumn = XmCreateLabel (row_column, "column", al, ac);
315 XtManageChild (wcolumn);
316
317 ac = 0;
318 win->column_number = XmCreateLabel (row_column, "1 ", al, ac); /* space
319 reserved for numbers as big as: "9999"
320 plus a leading and trailing space */
321 XtManageChild (win->column_number);
322
323 XtManageChild (row_column);
324
325
326 /* now manage the bottom frame ... */
327 XtManageChild (win->frame_bottom);
328
329
330 XtManageChild (form_frame_bottom);
331
332
333 /* now we can set the attachement for the pane widget */
334 ac = 0;
335 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++;
336 XtSetArg(al[ac], XmNbottomWidget, form_frame_bottom); ac++;
337 XtSetValues(pane, al, ac);
338
339 XtManageChild(form_work); /* now manage the manager widget */
340
341 return(form_work);
342
343
344 } /* CreateEditWorkArea */
345