1 /* -*- mode: C; mode: fold; -*- */
2 /* Copyright (c) 1992, 1998, 2000, 2002, 2003, 2004, 2005, 2006 John E. Davis
3  * This file is part of JED editor library source.
4  *
5  * You may distribute this file under the terms the GNU General Public
6  * License.  See the file COPYING for more information.
7  */
8 
9 #define _BUILD_GTK_JED
10 
11 #include "config.h"
12 #include "jed-feat.h"
13 
14 #define USE_NEW_META_CODE	1
15 #define HAS_IBM_NUMLOCK_CODE	0
16 #define SKIP_LOCALE_CODE	0
17 #ifndef HAVE_SETLOCALE
18 # define X_LOCALE		1
19 #endif
20 
21 #define XJED_USE_COMPOUND_TEXT	0
22 #ifndef XJED_HAS_XRENDERFONT
23 # define XJED_HAS_XRENDERFONT	0
24 #endif
25 
26 /*{{{ Include Files */
27 
28 #ifndef VMS
29 # include <X11/Xlib.h>
30 # include <X11/Xutil.h>
31 /* #include <X11/Xos.h> */
32 # include <X11/Xatom.h>
33 # include <X11/keysym.h>
34 # include <X11/cursorfont.h>
35 # include <X11/Intrinsic.h>
36 # if XJED_HAS_XRENDERFONT
37 #  include <X11/Xft/Xft.h>
38 # endif
39 # if !SKIP_LOCALE_CODE
40 #  if XtSpecificationRelease >= 6
41 #   define XJED_USE_R6IM
42 #   include <X11/Xlocale.h>
43 #  endif
44 # endif
45 #else
46 # include <decw$include/Xlib.h>
47 # include <decw$include/Xutil.h>
48 /* #include <decw$include/Xos.h> */
49 # include <decw$include/Xatom.h>
50 # include <decw$include/keysym.h>
51 # include <decw$include/cursorfont.h>
52 #endif
53 
54 #include <stdio.h>
55 #include <string.h>
56 #include <ctype.h>
57 #include <signal.h>
58 #include <sys/time.h>
59 #include <time.h>
60 
61 #include <gtk/gtk.h>
62 #include <gdk/gdkx.h>
63 #include <gdk/gdkkeysyms.h>
64 
65 #include <slang.h>
66 
67 #include "jdmacros.h"
68 
69 #include "buffer.h"
70 #include "display.h"
71 #include "sysdep.h"
72 #include "screen.h"
73 #include "keymap.h"
74 #include "hooks.h"
75 #include "ins.h"
76 #include "ledit.h"
77 #include "misc.h"
78 #include "cmds.h"
79 #include "sig.h"
80 #include "file.h"
81 #include "vterm.h"
82 #include "colors.h"
83 #include "window.h"
84 #include "menu.h"
85 
86 #include "gtkjed.h"
87 
88 /* Fixes some X headers... */
89 #ifndef Button6Mask
90 # define Button6Mask (Button5Mask<<1)
91 #endif
92 
93 /*}}}*/
94 
95 /* X_HAVE_UTF8_STRING is defined in X11.h */
96 #if (SLANG_VERSION >= 20000) && defined(X_HAVE_UTF8_STRING)
97 # define USE_XUTF8_CODE		1
98 #else
99 # define USE_XUTF8_CODE		0
100 #endif
101 
102 /*{{{ Static Global Variables */
103 
104 typedef struct /*{{{*/
105 {
106    GdkGC     *gc;
107    GdkColor  *fg, *bg;
108    char      *fgName;
109    char      *bgName;
110    int        dirty;
111 }
112 /*}}}*/
113 GCGtkInfoType;
114 
115 typedef struct StructGtkSubWinType
116 {
117    struct StructGtkSubWinType *next;
118 
119    Window_Type         *jedWin;
120    GtkWidget           *boxWin;
121    GtkWidget           *edWin;
122    GtkWidget           *stWin;
123    GtkWidget           *sbWin;
124 
125    gint                edX;
126    gint                edY;
127    gint                edWidth;
128    gint                edHeight;
129 
130    GtkAdjustment       *sbAdj;
131 
132    int                  numLineSav;
133    int                  curLineSav;
134    int                  winHeightSav;
135 
136    int                  ppY;
137    int                  ppX;
138    int                  ppHeight;   /* proposed height */
139    int                  ppWidth;    /* proposed width  */
140 }
141 GtkSubWinType;
142 
143 typedef struct
144 {
145 
146    Display     *XDisplay;
147 
148    /*********************************************************************/
149    /****** Stolen from original JXWindow_Type, don't get me wrong, but **/
150    /****** this data is still very useful.                ***************/
151    /*********************************************************************/
152 
153    /* int          height, width; */
154    int          border;			        /* inside border */
155    int          o_border;		        /* outside border */
156 
157    int          current_gc_num;
158 
159    int          vis_curs_row, vis_curs_col;     /* position of VISIBLE cursor */
160 
161    int          cursor_showing;		        /* true if widow has cursor showing */
162    int          focus;			        /* true if window has focus */
163    int          window_mapped;		        /* true if window is mapped */
164 
165    /* Window tty parameters */
166 
167    int insert_mode;		                /* true if inserting */
168    int scroll_r1,  scroll_r2;	                /* scrolling region */
169    int cursor_row, cursor_col;	                /* row column of cursor (0, 0) origin */
170 
171    int visible;			                /* from visibilitynotify */
172 
173    /*********************************************************************/
174 
175    GdkDisplay      *display;
176    GdkScreen       *screen;
177    GdkColormap     *colormap;
178    int              height;   /* Height of Window in Pixel                     */
179    int              width;    /* Width of Window in Pixel                      */
180 
181    int              edHeight; /* Total height of all editor windows in lines   */
182    int              edWidth;  /* Total width  of all editor windows in rows    */
183    int              hCheck;
184 
185    int              numWin;   /* Number of windows, not including the Minibuffer  */
186    GtkSubWinType   *subWins;
187    int              gutSize;  /* size of handle between subWins                */
188    GtkSubWinType ***widgetWinXRef;
189    GtkSubWinType   *miniWinSW;
190    int              inGridHeight;
191    int              inGridHeightPixel;
192    int              inGridWidthPixel;
193 
194    int              maxEdHeight;  /* Max number of Lines of all editor windows in total */
195                                   /* Needed only for preallocating memory        */
196    int              maxEdWidth;   /* Max rows per line, needed for preallocation */
197 #if 0
198    int             *maxWinLine;   /* maximal window segments for each line     */
199    int             *actWinLine;   /* actual number of windows for each line    */
200    int            **lineWinXRef;  /* All lines and window segment definition   */
201 #endif
202    /************************************************************************
203    |------------------------------------------------------------------------
204    |appW: GTK_WINDOW_TOPLEVEL
205    | |----------------------------------------------------------------------
206    | | appWGrid: vbox
207    | | |--------------------------------------------------------------------
208    | | |appWMenuBar: menu_bar
209    | | | |------------------------------------------------------------------
210    | | | |<<< the editor menu >>>
211    | | | |------------------------------------------------------------------
212    | | |--------------------------------------------------------------------
213    | | |appWTBGrid: vbox, toolbar area
214    | | | |------------------------------------------------------------------
215    | | | | First TB (created dynamically)
216    | | | |------------------------------------------------------------------
217    | | | | Next TB (created dynamically)
218    | | | |------------------------------------------------------------------
219    | | | | ...
220    | | | |------------------------------------------------------------------
221    | | | | N-th TB (created dynamically)
222    | | | |------------------------------------------------------------------
223    | | |--------------------------------------------------------------------
224    | | |appWEdGrid: vbox
225    | | | |------------------------------------------------------------------
226    | | | | appWASCWin <<< currently not used, will be draw area >>>
227    | | | |------------------------------------------------------------------
228    | | | | appWTopEdWin: paned Widget or box
229    | | | |
230    | | | | <<< editor windows, dynamically created >>>
231    | | | |
232    | | | | ****************************************************
233    | | | | * Editor area widgets, implemented as vertical box
234    | | | | * containing:
235    | | | | * - horizontal box containing
236    | | | | *    - draw area
237    | | | | *    - scrollbar
238    | | | | * - draw area to display status line for buffer
239    | | | | * dynamically. All editor area widgets are hierarchically
240    | | | | * stacked together with paned widget. If there is only one editor
241    | | | | * area widget no paned widget is used/created.
242    | | | | * |-----------------------------------------------------
243    | | | | * | vertical box
244    | | | | * | |---------------------------------------------------
245    | | | | * | | horizontal box
246    | | | | * | | |------------------------------------------------|
247    | | | | * | | | draw area (X: scrollbar)                     | |
248    | | | | * | | |                                              | |
249    | | | | * | | |                                              |X|
250    | | | | * | | |                                              |X|
251    | | | | * | | |                                              |X|
252    | | | | * | | |                                              | |
253    | | | | * | | |                                              | |
254    | | | | * | | |------------------------------------------------|
255    | | | | * | |---------------------------------------------------
256    | | | | * | | draw area to display buffer status line
257    | | | | * | |---------------------------------------------------
258    | | | | * |-----------------------------------------------------
259    | | | | ****************************************************
260    | | | |------------------------------------------------------------------
261    | | | | appWMiniW (widget for miniWin)
262    | | | |------------------------------------------------------------------
263    | | |--------------------------------------------------------------------
264    | | |appWSB: statusbar
265    | | |--------------------------------------------------------------------
266    | |----------------------------------------------------------------------
267    |------------------------------------------------------------------------
268    ************************************************************************/
269 
270    /*****************************************************
271    * Main container widgets
272    *****************************************************/
273 
274    GtkWidget       *appW;                 /* GTK_WINDOW_TOPLEVEL  */
275    GtkWidget       *appWGrid;             /* vbox                 */
276 
277    /*****************************************************
278    * Default menu widgets, contain no functionality
279    *****************************************************/
280 
281    GtkWidget       *appWMenuBar;          /* menu_bar       */
282    GtkWidget       *appWMenu;
283    GtkWidget       *appWMenuItem;
284    GtkWidget       *appWMenuItemOpen;
285    GtkWidget       *appWMenuItemSave;
286    GtkWidget       *appWMenuItemClose;
287 
288    /* GHashTable      *menuArray; */ /* Used to access menu items by path. The path is used as index */
289                                 /*  into a hash table, that contains pointer to menu items.     */
290 
291    /***************************************************
292    * Toolbar widget container, toolbars are created
293    * dynamically.
294    ***************************************************/
295 
296    GtkWidget       *appWTbGrid;           /* vbox           */
297 
298    /***************************************************
299    * Editor area widgets, implemented as vertical box
300    * containing:
301    * - horizontal box containing
302    *    - draw area
303    *    - scrollbar
304    * - draw area to display status line for buffer
305    * dynamically. All editor area widgets are hierarchically
306    * stacked together with paned widget. For only one editor
307    * area widget no paned widget is used.
308    ***************************************************/
309 
310    GtkWidget       *appWEdGrid;     /* Contains drawing Area for Menu and appWInGrid                */
311    GtkWidget       *appWASCMenu;    /* Draw area containing the ASCII-based menu <<< currently      */
312 				    /*      not implemented >>>                                     */
313    GtkWidget       *appWInGrid;     /* Contains Toplevel paned widget and miniWidget for minibuffer */
314                                     /*      following the description above, to be removed in near  */
315 				    /*      future                                                  */
316    GtkWidget       *appWTopEdWin;   /* Toplevel EditorWindow (draw area / paned widget)             */
317    GtkWidget       *appWMiniW;      /* miniWidget, Widget to display the minibuffer                 */
318 
319    /*****************************************************
320    * Status bar widget, currently not used.
321    *****************************************************/
322 
323    GtkWidget       *appWSB;         /* Statusbar widget                                             */
324 
325    /**************************************************
326    * Text drawing/rendering objects
327    **************************************************/
328 
329    PangoContext          *fontContext;
330    PangoFontDescription  *fontDescription;
331    PangoFontMetrics      *fontMetrics;
332    char                  *fontName;
333    int                    fontAscent;
334    int                    fontDescent;
335    int                    fontHeight;
336    int                    fontWidth;
337 
338    GCGtkInfoType         *textGC;
339    GCGtkInfoType         *currentGC;
340 }
341 JGtkWinType;
342 
343 /* extern JGtkWinType  JGtkWinBuf; */
344 extern JGtkWinType *JGtkWin;
345 
346 /* #define XJED_MAP 0 */
347 
348 #define MAX_EDHEIGHT  500; /* default for height of edit windows */
349 #define MAX_EDWIDTH   500; /* default for width of edit windows  */
350 
351 void jedGtkUpdateEdSize( int, int );
352 void updateWidgetWinXRef( GtkSubWinType *, int, int, int, int );
353 
354 /* static int checkFlushXDisplay(void); */
355 /* static int checkFlushXDisplayST( int, const char * ); */
356 
357 static int JX_Screen_Cols;
358 static int JX_Screen_Rows;
359 static int JX_Term_Cannot_Scroll =  0;
360 static int JX_Term_Cannot_Insert =  0;
361 static int JX_Use_Ansi_Colors =     1;
362 static int JX_Ignore_Beep =         3;
363 static int JX_Blink_Mode =          1;
364 static int JX_MultiClick_Time =     500;   /* milliseconds */
365 
366 static int JX_MetaMask = Mod1Mask;
367 
368 #ifdef XJED_USE_R6IM
369 static char            *R6IM_Input_Method =  NULL;
370 /* static XIMStyle         R6IM_Input_Style =   0; */
371 static char            *R6IM_Preedit_Type =  "Root";
372 /* static XIC              R6IM_Xic; */
373 /* static void             i18init(void); */
374 /* static XPoint           R6IM_Spot; */
375 /* static XVaNestedList    R6IM_Preedit_Attr; */
376 /* static void             move_input_position (void); */
377 /* static void             set_geometry (XEvent *, XIMStyle, char *); */
378 #endif
379 
380 static int              updateGtkWin = 1;  /* used during splitWin / showAll to prevent drawing!!! */
381                                /* see also gtkDraw-function */
382 
383 static int              doColorSetup = 1;
384 static int              doCLS = 1;
385 
386 static gboolean         sbChangeValue( GtkRange *, GtkScrollType,
387 				       gdouble, gpointer );
388 
389 void                    printGtkSubWin( GtkSubWinType * );
390 
391 void                    printSubWins(void);
392 
393 static void             toggle_cursor( int );
394 
395 /* static char            *The_Xserver_Vendor; */
396 
397 /* static int Current_Color; */
398 static int              X_Alt_Char =     27;
399 static KeySym           X_Last_Keysym;
400 static int              X_Warp_Pending = 0;
401 
402 static gdouble          actSBVal;
403 
404 #define FC_CMD_KEY_SEQ "\033[FC"
405 
406 static gpointer         actParaData;
407 static void          ( *actFunToCall )( gpointer );
408 
409 static void       modWidgetWinXRef( GtkSubWinType ***, GtkSubWinType *, int, int, int, int );
410 static void       printWidgetStruct(void);
411 
412 /******************** Jed internal Event Queue *******************/
413 
414 typedef enum
415 {
416    JXGtkAnyID            = 1,
417    JXGtkGdkEventID       = 2,
418    JXKeyFeedID           = 3
419 }
420 JXGtkEventID;
421 
422 typedef struct
423 {
424    JXGtkEventID     type;
425 }
426 JXGtkAnyEvent;
427 
428 typedef struct
429 {
430    JXGtkEventID     type;
431    GdkEvent         gdkEvent;
432    GtkWidget       *w;
433    gpointer        *data;
434 }
435 JXGtkGdkEvent;
436 
437 typedef struct
438 {
439    JXGtkEventID     type;
440    char            *keys;
441 }
442 JXKeyFeedEvent;
443 
444 typedef union
445 {
446    JXGtkEventID           type;
447    JXGtkAnyEvent          any;
448    JXGtkGdkEvent          gdkEvent;
449    JXKeyFeedEvent         keyFeed;
450 }
451 JXGtkEventType;
452 
453 /************************************************************************/
454 
455 static int              Performing_Update;
456 static int              Check_Buffers_Pending;
457 static int              No_XEvents;		       /* if true, do nothing */
458 
459 typedef struct /*{{{*/
460 {
461    char *name;
462    char *name1;
463    int type;
464    char *value;
465    char **dflt;
466 }
467 
468 /*}}}*/
469 XWindow_Arg_Type;
470 
471 #define XJED_CLASS	           "XTerm"
472 static char    *This_App_Name =    "xjed";
473 static char    *This_App_Title =   "XJed";
474 
475 /* #define Default_Geometry "80x24+0-0" */
476 #define Default_Geometry           "80x24"
477 static char    *This_Geometry =    NULL;
478 static char    *This_Font_Name =   "fixed";
479 
480 #if XJED_HAS_XRENDERFONT
481 static char    *This_Face_Size =   "                           ";
482 #endif
483 
484 static char    *This_Border_Width_Name =    "0";
485 static char    *This_Internal_Border_Name = "0";
486 static char    *This_MFG =                  "green";
487 static char    *This_MBG =                  "white";
488 static char    *Iconic =                    NULL;
489 
490 /* static Atom     Xjed_Prop; */
491 /* static Atom     Compound_Text_Atom; */
492 /* static Atom     UTF8_String_Atom; */
493 
494 /* static XEvent   Current_Event; */
495 static char    *jgtkSelectionData = NULL;
496 static char    *jgtkClipboardData = NULL;
497 /* static int      receive_selection (XEvent *); */
498 /* static int      send_selection (XEvent *); */
499 
500 static GCGtkInfoType DefaultGtkGCInfo[JMAX_COLORS] = /*{{{*/
501 {
502 /*******************************************************************************
503  * GC: X11-gc
504  * foreground (unsigned long)
505  * background (unsigned long)
506  * foreground color name
507  * background color name
508  * flag if dirty
509 *******************************************************************************/
510    { NULL, NULL, NULL, "black",   "white",   0 },    /* NORMAL */
511    { NULL, NULL, NULL, "green",   "red",     0 },    /* CURSOR */
512    { NULL, NULL, NULL, "default", "skyblue", 0 },    /* STATUS */
513    { NULL, NULL, NULL, "default", "magenta", 0 },    /* REGION */
514    { NULL, NULL, NULL, "default", "skyblue", 0 },    /* MENU */
515    { NULL, NULL, NULL, "default", "default", 0 },    /* operator */
516    { NULL, NULL, NULL, "green",   "default", 0 },    /* numbers */
517    { NULL, NULL, NULL, "blue",    "default", 0 },    /* strings */
518    { NULL, NULL, NULL, "default", "gray",    0 },    /* comments */
519    { NULL, NULL, NULL, "default", "default", 0 },    /* delimeters */
520    { NULL, NULL, NULL, "magenta", "default", 0 },    /* preprocess */
521    { NULL, NULL, NULL, "blue",    "default", 0 },    /* message */
522    { NULL, NULL, NULL, "red",     "default", 0 },    /* error */
523    { NULL, NULL, NULL, "magenta", "default", 0 },    /* dollar */
524    { NULL, NULL, NULL, "red",     "default", 0 },    /* keyword */
525    { NULL, NULL, NULL, "green",   "default", 0 },    /* keyword1 */
526    { NULL, NULL, NULL, "red",     "default", 0 },    /* keyword2 */
527    { NULL, NULL, NULL, "green",   "magenta", 0 }     /* ... fold mark */
528 };
529 
530 /* cheat a little, use VOID_TYPE for boolean arguments */
531 static XWindow_Arg_Type jGtkArgList[] = /*{{{*/
532 {
533    /* These MUST be in this order!!! */
534 #define XARG_DISPLAY	0
535    {"Display",		"d", 	STRING_TYPE,	NULL,	NULL},
536 #define JGTK_ARG_NAME	1
537    {"Name",		NULL,	STRING_TYPE,	NULL,	&This_App_Name},
538 #define XARG_GEOMETRY	2
539    {"Geometry",		NULL, 	STRING_TYPE,	NULL,	&This_Geometry},
540 
541 #define XARG_START	2
542      /* Note: it's good to look for
543       * `font', `background', `foreground'
544       * instead of
545       * `Font', `background', `foreground'
546       * so that XTerm names can be used
547       * (resource vs. class names)
548       *
549       * also, change order of names a little?
550       */
551    {"font",		"fn",	 STRING_TYPE,	NULL,	&This_Font_Name},
552    {"fgMouse",	"mfg", 	 STRING_TYPE,	NULL,	&This_MFG},
553    {"bgMouse",	"mbg", 	 STRING_TYPE,	NULL,	&This_MBG},
554    {"background",	"bg", 	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JNORMAL_COLOR].bgName},
555    {"foreground",	"fg",	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JNORMAL_COLOR].fgName},
556    {"fgStatus",	"sfg", 	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JSTATUS_COLOR].fgName},
557    {"bgStatus",	"sbg", 	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JSTATUS_COLOR].bgName},
558    {"fgRegion",	"rfg", 	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JREGION_COLOR].fgName},
559    {"bgRegion",	"rbg", 	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JREGION_COLOR].bgName},
560    {"fgCursor",	"cfg", 	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JCURSOR_COLOR].fgName},
561    {"bgCursor",	"cbg", 	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JCURSOR_COLOR].bgName},
562    {"fgCursorOvr",	"cofg",  STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JCURSOROVR_COLOR].fgName},
563    {"bgCursorOvr",	"cobg",  STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JCURSOROVR_COLOR].bgName},
564    {"fgMenu",		"fgm", 	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JMENU_COLOR].fgName},
565    {"bgMenu",		"bgm", 	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JMENU_COLOR].bgName},
566    {"fgOperator",	"fgop",	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JOP_COLOR].fgName},
567    {"bgOperator",	"bgop",	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JOP_COLOR].bgName},
568    {"fgNumber",	"fgnm",	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JNUM_COLOR].fgName},
569    {"bgNumber",	"bgnm",	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JNUM_COLOR].bgName},
570    {"fgString",	"fgst",	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JSTR_COLOR].fgName},
571    {"bgString",	"bgst",	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JSTR_COLOR].bgName},
572    {"fgComments",	"fgco",	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JCOM_COLOR].fgName},
573    {"bgComments",	"bgco",	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JCOM_COLOR].bgName},
574    {"fgKeyword",	"fgkw",	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JKEY_COLOR].fgName},
575    {"bgKeyword",	"bgkw",	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JKEY_COLOR].bgName},
576    {"fgKeyword1",	"fgkw1", STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JKEY_COLOR + 1].fgName},
577    {"bgKeyword1",	"bgkw1", STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JKEY_COLOR + 1].bgName},
578    {"fgKeyword2",	"fgkw2", STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JKEY_COLOR + 2].fgName},
579    {"bgKeyword2",	"bgkw2", STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JKEY_COLOR + 2].bgName},
580    {"fgDelimiter",	"fgde",	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JDELIM_COLOR].fgName},
581    {"bgDelimiter",	"bgde",	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JDELIM_COLOR].bgName},
582    {"fgPreprocess",	"fgpr",	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JPREPROC_COLOR].fgName},
583    {"bgPreprocess",	"bgpr",	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JPREPROC_COLOR].bgName},
584    {"bgMessage",	"bgms",	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JMESSAGE_COLOR].bgName},
585    {"fgMessage",	"fgms",	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JMESSAGE_COLOR].fgName},
586    {"bgError",	"bger",	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JERROR_COLOR].bgName},
587    {"fgError",	"fger",	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JERROR_COLOR].fgName},
588    {"fgDots",		"fgdt",	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JDOTS_COLOR].bgName},
589    {"bgDots",		"bgdt",	 STRING_TYPE,	NULL,	&DefaultGtkGCInfo[JDOTS_COLOR].bgName},
590    {"BorderWidth",	"bw", 	 STRING_TYPE,	NULL,	&This_Border_Width_Name},
591    {"title",		NULL,	 STRING_TYPE,	NULL,	&This_App_Title},
592    {"BorderColor",	"bd", 	 STRING_TYPE,	NULL,	NULL},
593    {"Iconic",		"ic",	 VOID_TYPE,	NULL,	&Iconic},
594    {"xrm",		NULL,	 STRING_TYPE,	NULL,	NULL},
595    {"internalBorder", "ib",	 STRING_TYPE,	NULL,	&This_Internal_Border_Name},
596 #ifdef XJED_USE_R6IM
597    {"inputMethod",      "im",   STRING_TYPE,    NULL,   &R6IM_Input_Method},
598    {"inputStyle",       "is",   STRING_TYPE,    NULL,   &R6IM_Preedit_Type},
599 #endif
600 #if XJED_HAS_XRENDERFONT
601    {"facesize",	"fs",	STRING_TYPE,	NULL,	&This_Face_Size},
602 #endif
603    {NULL,		NULL,	0,		NULL,	NULL}
604 };
605 
606 /*}}}*/
607 
608 /*}}}*/
609 
610 static JGtkWinType    JGtkWinBuf;
611 JGtkWinType   *JGtkWin = &JGtkWinBuf;
612 
613 /* static int            gtkButtonEvent = 0; */
614 
615 static gboolean       eventCallback( GtkWidget *,
616 	                             GdkEvent  *,
617 	                             gpointer  * );
618 static void           jGtkCoverExposedArea( int, int,
619 					    int, int,
620 					    int );
621 
622 static int            gtkInsertSelection( void );
623 static void           gtkSelectionReceive( GtkWidget *,
624 				           GtkSelectionData *,
625 				           gpointer );
626 static void           jGtkSendSelection( GtkWidget *,
627 					 GtkSelectionData *,
628 					 guint,
629 					 guint,
630 					 gpointer );
631 
632 static void           jGtkSetFGBGColor( GtkWidget *, int );
633 
634 typedef struct
635 {
636    GList         *jXGtkEvList;
637    int            jXGtkNumEv;
638 }
639 FilterEventData;
640 
641 static FilterEventData *thisEventBuffer;
642 
643 typedef struct jGtkScrollInfoStruct
644 {
645    int        set;     /* flagging scrollInfo active (with valid infos) or not */
646    int        tl;      /* Target line */
647    GtkRange  *rangeW;  /* rangeWidget */
648    int        sLSBeg;     /* singleLineSteps (sLS) outstanding */
649                 /* Scrolling is done by first doing a view single line steps. */
650 		/* If target is not reached, jump to target (maybe in a view bigger */
651                 /* steps, not only one big step). */
652    int        sLSEnd;  /* singleLineSteps at End of scrolling. */
653    int        jF;      /* jumpFlag, if set to one means, no single line steps any more */
654                        /* to perform act scroll event, just jump to target (this should be done, */
655                        /* if the next scroll */
656 		       /* event arrives before act scroll event is completed. */
657    int        cnt;     /* intermediate solution for slow down scrolling!!! */
658    struct timeval   tv;
659 }
660 JGtkScrollInfo;
661 
662 #define JGTK_SCROLL_SLOW_DOWN 20
663 
664 static JGtkScrollInfo   jGtkSIPrim =
665 {
666    0,
667    1,
668    NULL,
669    0,
670    0,
671    0,
672    JGTK_SCROLL_SLOW_DOWN,
673  { 0,
674       0
675  }
676 };
677 
678            /* Primary scrollInfo (means scrollInfo for act scroll event) */
679 static JGtkScrollInfo   jGtkSISec  =
680 {
681    0,
682    1,
683    NULL,
684    0,
685    0,
686    0,
687    JGTK_SCROLL_SLOW_DOWN,
688  { 0,
689       0
690  }
691 };
692            /* Secondary scrollInfo is queued if next scroll event arrives before */
693 	   /* actual scroll event is completed. In further scrollEvent will */
694 	   /* discard secondary scrollInfo and reset it. */
695 
696 /************************************/
697 
698 /************************************
699 * JXGtkPending
700 *
701 * group: event
702 *
703 *
704 * debug print:
705 *
706 *
707 ************************************/
708 
709 static  gboolean
jGtkPending(void)710 jGtkPending(void)
711 {
712    while ( gtk_events_pending() )
713      {
714 	gtk_main_iteration_do( False );
715      }
716 
717    return( thisEventBuffer->jXGtkNumEv );
718 }
719 
720 /************************************
721 * JXGtkPeekEvent
722 *
723 * group: event
724 *
725 *
726 * debug print:
727 *
728 *
729 ************************************/
730 
731 #if 0
732 static int
733 JXGtkPeekEvent( JXGtkEventType *ev )
734 {
735    FilterEventData *cbData = thisEventBuffer;
736 
737    while ( !( thisEventBuffer->jXGtkNumEv ) )
738      {
739 	if ( gtk_events_pending() )
740 	  {
741 	     gtk_main_iteration();
742 	  }
743      }
744 
745    if ( thisEventBuffer->jXGtkNumEv )
746      {
747 	memcpy( ev, ( JXGtkEventType * ) thisEventBuffer->jXGtkEvList->data, sizeof( JXGtkEventType ) );
748 	return( TRUE );
749      }
750    else
751      {
752 	return( FALSE );
753      }
754 }
755 #endif
756 
757 /*******************************
758 * JXGtkNextEvent
759 *
760 * group: event
761 *
762 *
763 * debug print:
764 *
765 ********************************/
766 
767 static int
JXGtkNextEvent(JXGtkEventType * ev)768 JXGtkNextEvent( JXGtkEventType *ev )
769 {
770    FilterEventData *cbData = thisEventBuffer;
771 
772    while ( !( thisEventBuffer->jXGtkNumEv ) )
773      {
774 	if ( gtk_events_pending() )
775 	  {
776 	     gtk_main_iteration();
777 	  }
778      }
779 
780    if ( thisEventBuffer->jXGtkNumEv )
781      {
782 	memcpy( ev, ( JXGtkEventType * ) thisEventBuffer->jXGtkEvList->data, sizeof( JXGtkEventType ) );
783 	SLfree( ( char * ) thisEventBuffer->jXGtkEvList->data );
784 	thisEventBuffer->jXGtkEvList =
785 	  g_list_remove( thisEventBuffer->jXGtkEvList,
786 			 thisEventBuffer->jXGtkEvList->data );
787 	thisEventBuffer->jXGtkNumEv -= 1;
788 	if ( thisEventBuffer->jXGtkNumEv < 0 )
789 	  thisEventBuffer->jXGtkNumEv = 0;
790 	return( TRUE );
791      }
792    else
793      {
794 	return( FALSE );
795      }
796 }
797 
798 /************************************
799 * JXGtkCheckMaskEvent( Display *display, long mask, JXGtkEventType *ev )
800 *
801 * group: event
802 *
803 *
804 * debug print:
805 *
806 ***********************************/
807 
808 static Bool
JXGtkCheckMaskEvent(long mask,JXGtkEventType * ev)809 JXGtkCheckMaskEvent( long mask, JXGtkEventType *ev )
810 {
811    FilterEventData *cbData = thisEventBuffer;
812    guint  sizeOfBuffer;
813    GList *actEle;
814 
815    while ( gtk_events_pending() )
816      {
817 	gtk_main_iteration();
818      }
819 
820    if ( thisEventBuffer->jXGtkNumEv )
821      {
822 	actEle = thisEventBuffer->jXGtkEvList;
823 
824 	sizeOfBuffer = g_list_length( actEle );
825 
826 	while ( sizeOfBuffer-- )
827 	  {
828 	     if ( mask && ( ( JXGtkEventType * ) actEle->data )->gdkEvent.gdkEvent.type )
829 	       {
830 		  memcpy( ev, ( JXGtkEventType * ) actEle->data, sizeof( JXGtkEventType ) );
831 		  SLfree( ( char * ) actEle->data );
832 		  thisEventBuffer->jXGtkEvList =
833 		    g_list_remove( thisEventBuffer->jXGtkEvList,
834 				   actEle->data );
835 		  thisEventBuffer->jXGtkNumEv -= 1;
836 		  if ( thisEventBuffer->jXGtkNumEv < 0 )
837 		    thisEventBuffer->jXGtkNumEv = 0;
838 		  return( TRUE );
839 	       }
840 	     actEle = actEle->next;
841 	  }
842 	return( False );
843      }
844    else
845      {
846 	return( False );
847      }
848 }
849 
850 /************************************
851 * addGdkEvent
852 *
853 * group: event
854 *
855 *
856 * debug print:
857 *
858 *
859 ************************************/
860 
861 static void
addGdkEvent(GdkEvent * ev,GtkWidget * w,gpointer * data)862 addGdkEvent( GdkEvent *ev, GtkWidget *w, gpointer *data )
863 {
864    FilterEventData *eB = thisEventBuffer;
865    JXGtkEventType *newEv = ( JXGtkEventType * ) SLmalloc( sizeof( JXGtkEventType ) );
866 
867    newEv->type = JXGtkGdkEventID;
868    newEv->any.type = JXGtkGdkEventID;
869    newEv->gdkEvent.type = JXGtkGdkEventID;
870    memcpy( &( newEv->gdkEvent.gdkEvent ), ev, sizeof( GdkEvent ) );
871    newEv->gdkEvent.w = w;
872    newEv->gdkEvent.data = data;
873    eB->jXGtkEvList = g_list_append( eB->jXGtkEvList, newEv );
874    ( eB->jXGtkNumEv ) += 1;
875    /* printf( "File: %s, Line: %d; Num JXGtkEvents: %d\n", __FILE__, __LINE__, eB->jXGtkNumEv ); */
876 }
877 
878 /*************************/
879 
880 /************************************
881 * createGtkMiniWin
882 *
883 * group: win
884 *
885 *
886 * debug print: "void (%d)\n", 1
887 *
888 *
889 ************************************/
890 
891 static GtkWidget *
createGtkMiniWin(void)892 createGtkMiniWin(void)
893 {
894 
895    GdkColor white = { 0, 0xffff, 0xffff, 0xffff };
896    GtkWidget *w = gtk_drawing_area_new();   /* Edit window */
897 
898    gtk_widget_modify_bg(  w, GTK_STATE_NORMAL, &white );
899 
900    GTK_WIDGET_SET_FLAGS(  w, GTK_CAN_FOCUS );
901 
902    gtk_widget_add_events( w, GDK_KEY_PRESS_MASK );
903    g_signal_connect( G_OBJECT( w ),
904 		     "key_press_event",
905 		     G_CALLBACK( eventCallback ),
906 		     NULL );
907 
908    gtk_widget_add_events( w, GDK_BUTTON_PRESS_MASK );
909    g_signal_connect( G_OBJECT( w ),
910 		     "button_press_event",
911 		     G_CALLBACK( eventCallback ),
912 		     NULL );
913 
914    gtk_widget_add_events( w, GDK_BUTTON_RELEASE_MASK );
915    g_signal_connect( G_OBJECT( w ),
916 		     "button_release_event",
917 		     G_CALLBACK( eventCallback ),
918 		     NULL );
919 
920    g_signal_connect( G_OBJECT( w ),
921 		     "expose_event",
922 		     G_CALLBACK( eventCallback ),
923 		     NULL );
924 
925    gtk_widget_add_events( w, GDK_BUTTON_MOTION_MASK );
926    g_signal_connect( G_OBJECT( w ),
927 		     "motion_notify_event",
928 		     G_CALLBACK( eventCallback ),
929 		     NULL );
930 
931    gtk_widget_add_events( w, GDK_FOCUS_CHANGE_MASK );
932    g_signal_connect( G_OBJECT( w ),
933 		     "focus-out-event",
934 		     G_CALLBACK( eventCallback ),
935 		     NULL );
936    g_signal_connect( G_OBJECT( w ),
937 		     "focus-in-event",
938 		     G_CALLBACK( eventCallback ),
939 		     NULL );
940 
941    g_signal_connect( G_OBJECT( w ),
942 		     "selection_received",
943 		     G_CALLBACK( gtkSelectionReceive ),
944 		     NULL );
945 
946    g_signal_connect( G_OBJECT( w ),
947 		     "selection_get",
948 		     G_CALLBACK( jGtkSendSelection), NULL );
949 
950    gtk_selection_add_target( w,
951 			     GDK_SELECTION_PRIMARY,
952 			     GDK_SELECTION_TYPE_STRING,
953 			     1 );
954 
955    return( w );
956 }
957 
958 /************************************
959 * createGtkWinTmpl
960 *
961 * group: win
962 *
963 *
964 * debug print: "ce: %d, jw(GtkSubWinType): %x\n", ce, jw
965 *
966 *
967 ************************************/
968 
969 static GtkSubWinType *
createGtkWinTmpl(GtkSubWinType * jw)970 createGtkWinTmpl( GtkSubWinType *jw )
971 {
972    JGtkWinType *win = JGtkWin;
973    /* EdWinWidgetType edWidgets; */
974    GdkColor white = { 0, 0xffff, 0xffff, 0xffff };
975    GtkWidget *w = gtk_drawing_area_new();   /* Edit window */
976    GtkWidget *ws = gtk_drawing_area_new();  /* Window statusbar */
977    GtkWidget *sb = gtk_vscrollbar_new( NULL );
978    GtkWidget *eb = gtk_hbox_new( False, 0 );
979    GtkWidget *wb = gtk_vbox_new( False, 0 );
980    GtkAdjustment *sbAdj = gtk_range_get_adjustment( GTK_RANGE( sb ) );
981 
982    gtk_widget_set_size_request( ws, -1, win->fontHeight );
983 
984    gtk_widget_modify_bg(  w, GTK_STATE_NORMAL, &white );
985    gtk_widget_modify_bg( ws, GTK_STATE_NORMAL, &white );
986 
987    GTK_WIDGET_SET_FLAGS(  w, GTK_CAN_FOCUS );
988    GTK_WIDGET_SET_FLAGS( ws, GTK_CAN_FOCUS );
989 
990    gtk_widget_add_events( w, GDK_KEY_PRESS_MASK );
991    g_signal_connect( G_OBJECT( w ),
992 		     "key_press_event",
993 		     G_CALLBACK( eventCallback ),
994 		     jw );
995 
996    gtk_widget_add_events( w, GDK_BUTTON_PRESS_MASK );
997    g_signal_connect( G_OBJECT( w ),
998 		     "button_press_event",
999 		     G_CALLBACK( eventCallback ),
1000 		     w );
1001 
1002    gtk_widget_add_events( ws, GDK_BUTTON_PRESS_MASK );
1003    g_signal_connect( G_OBJECT( ws ),
1004 		     "button_press_event",
1005 		     G_CALLBACK( eventCallback ),
1006 		     ws );
1007 
1008    gtk_widget_add_events( w, GDK_BUTTON_RELEASE_MASK );
1009    g_signal_connect( G_OBJECT( w ),
1010 		     "button_release_event",
1011 		     G_CALLBACK( eventCallback ),
1012 		     w );
1013 
1014    gtk_widget_add_events( ws, GDK_BUTTON_RELEASE_MASK );
1015    g_signal_connect( G_OBJECT( ws ),
1016 		     "button_release_event",
1017 		     G_CALLBACK( eventCallback ),
1018 		     ws );
1019 
1020    gtk_widget_add_events( w, GDK_EXPOSURE_MASK );
1021    g_signal_connect( G_OBJECT( w ),
1022 		     "expose_event",
1023 		     G_CALLBACK( eventCallback ),
1024 		     jw );
1025 
1026    gtk_widget_add_events( ws, GDK_EXPOSURE_MASK );
1027    g_signal_connect( G_OBJECT( ws ),
1028 		     "expose_event",
1029 		     G_CALLBACK( eventCallback ),
1030 		     jw );
1031 
1032    gtk_widget_add_events( w, GDK_BUTTON_MOTION_MASK );
1033    g_signal_connect( G_OBJECT( w ),
1034 		     "motion_notify_event",
1035 		     G_CALLBACK( eventCallback ),
1036 		     jw );
1037 
1038    gtk_widget_add_events( w, GDK_FOCUS_CHANGE_MASK );
1039    g_signal_connect( G_OBJECT( w ),
1040 		     "focus-out-event",
1041 		     G_CALLBACK( eventCallback ),
1042 		     jw );
1043    g_signal_connect( G_OBJECT( w ),
1044 		     "focus-in-event",
1045 		     G_CALLBACK( eventCallback ),
1046 		     jw );
1047 
1048    g_signal_connect( G_OBJECT( w ),
1049 		     "configure_event",
1050 		     G_CALLBACK( eventCallback ),
1051 		     jw );
1052 
1053    g_signal_connect( G_OBJECT( w ),
1054 		     "selection_received",
1055 		     G_CALLBACK( gtkSelectionReceive ),
1056 		     jw );
1057 
1058    g_signal_connect( G_OBJECT( w ),
1059 		     "selection_get",
1060 		     G_CALLBACK( jGtkSendSelection), jw );
1061 
1062    gtk_selection_add_target( w,
1063 			     GDK_SELECTION_PRIMARY,
1064 			     GDK_SELECTION_TYPE_STRING,
1065 			     1 );
1066 
1067    g_signal_connect( G_OBJECT( sb ), "change-value",
1068 		     G_CALLBACK( sbChangeValue ),
1069 		     NULL );
1070 
1071    /* Set initial dummy values */
1072    sbAdj->lower = 0;
1073    sbAdj->upper = 100;
1074    sbAdj->value = 30;
1075    sbAdj->step_increment = 1;
1076    sbAdj->page_increment = 10;
1077    sbAdj->page_size = 5;
1078 
1079    g_signal_emit_by_name( G_OBJECT( sbAdj ), "changed" );
1080 
1081    gtk_box_pack_start( GTK_BOX( eb ), w, True, True, 0 );
1082    gtk_box_pack_start( GTK_BOX( eb ), sb, False, False, 0 );
1083 
1084    gtk_box_pack_start( GTK_BOX( wb ),  eb,  True,  True, 0 );
1085    gtk_box_pack_start( GTK_BOX( wb ), ws, False, True, 0 );
1086 
1087    jw->edWin = w;
1088    jw->stWin = ws;
1089    jw->sbWin = sb;
1090 
1091    return( jw );
1092 }
1093 
1094 /************************************
1095 * printWidgetWinXRef
1096 *
1097 * group: win, debug
1098 *
1099 *
1100 * debug print: "(void)", 1
1101 *
1102 *
1103 ************************************/
1104 
1105 #if 0
1106 static void
1107 printWidgetWinXRef(void)
1108 {
1109    int i, i1;
1110    JGtkWinType *win = JGtkWin;
1111 
1112    printf( "Ed Height: %d, Width: %d\n", win->edHeight, win->edWidth );
1113    printf( " Jed_Num_Screen_Cols: %d, Jed_Num_Screen_Rows: %d, Top_Window_SY: %d\n",
1114 	   Jed_Num_Screen_Cols, Jed_Num_Screen_Rows, Top_Window_SY );
1115 
1116    for ( i = 0; i < win->edHeight; ++i )
1117      {
1118 	printf( "%3d:", i );
1119 	for ( i1 = 0; i1 < win->edWidth; ++i1 )
1120 	  {
1121 	     if ( win->widgetWinXRef[i][i1] )
1122 	       {
1123 		  if ( i != win->widgetWinXRef[i][i1]->jedWin->sy +
1124 		       win->widgetWinXRef[i][i1]->jedWin->rows )
1125 		    {
1126 	       /* printf( "(%6x-E-%6x)", win->widgetWinXRef[i][i1]->jedWin, win->widgetWinXRef[i][i1]->edWin ); */
1127 		       printf( "E%p-%p ", (void*)win->widgetWinXRef[i][i1]->jedWin, (void*)win->widgetWinXRef[i][i1]->edWin );
1128 		    }
1129 		  else
1130 		    {
1131 	       /* printf( "(%6x-S-%6x)", win->widgetWinXRef[i][i1]->jedWin, win->widgetWinXRef[i][i1]->stWin ); */
1132 		       printf( "S%p-%p ", (void*)win->widgetWinXRef[i][i1]->jedWin, (void*)win->widgetWinXRef[i][i1]->stWin );
1133 		    }
1134 	       }
1135 	     else
1136 	       {
1137 	    /* printf( "(%6x-S-%6x)", NULL, NULL ); */
1138 		  printf( "S%p-%p ", NULL, NULL );
1139 	       }
1140 	  }
1141 	printf( "\n" );
1142      }
1143 }
1144 #endif
1145 
1146 /************************************
1147 * printWidgetWinXRefXY
1148 *
1149 * group: win, debug
1150 *
1151 *
1152 * debug print: "x: %d, y: %d\n", x, y
1153 *
1154 *
1155 ************************************/
1156 
1157 #if 0
1158 static void
1159 printWidgetWinXRefXY( int x, int y )
1160 {
1161    int i, i1;
1162    JGtkWinType *win = JGtkWin;
1163 
1164    printf( "Ed Height: %d, Width: %d\n", win->edHeight, win->edWidth );
1165    printf( " Jed_Num_Screen_Cols: %d, Jed_Num_Screen_Rows: %d, Top_Window_SY: %d\n",
1166 	   Jed_Num_Screen_Cols, Jed_Num_Screen_Rows, Top_Window_SY );
1167 
1168    for ( i = 0; i <= y; ++i )
1169      {
1170 	printf( "height[%8d]: ", i );
1171 	for ( i1 = 0; i1 <= x; ++i1 )
1172 	  {
1173 	     if ( win->widgetWinXRef[i][i1] )
1174 	       {
1175 		  if ( i != win->widgetWinXRef[i][i1]->jedWin->sy +
1176 		       win->widgetWinXRef[i][i1]->jedWin->rows )
1177 		    {
1178 		       printf( "(%p-E-%p)", (void*)win->widgetWinXRef[i][i1]->jedWin, (void*)win->widgetWinXRef[i][i1]->edWin );
1179 		    }
1180 		  else
1181 		    {
1182 		       printf( "(%p-S-%p)",(void*) win->widgetWinXRef[i][i1]->jedWin, (void*)win->widgetWinXRef[i][i1]->stWin );
1183 		    }
1184 	       }
1185 	     else
1186 	       {
1187 		  printf( "(%p-S-%p)", NULL, NULL );
1188 	       }
1189 	  }
1190 	printf( "\n" );
1191      }
1192 }
1193 #endif
1194 
1195 static void
printWidgetStruct(void)1196 printWidgetStruct(void)
1197 {
1198    JGtkWinType *win = JGtkWin;
1199    GtkSubWinType *sw = win->subWins;
1200    GtkWidget *w, *pw;
1201 
1202    do
1203      {
1204 	printGtkSubWin( sw );
1205 	printf( "Parents: \n" );
1206 	pw = sw->stWin;
1207 	do
1208 	  {
1209 	     pw = gtk_widget_get_parent( pw );
1210 	     printf( " %p(w: %d, h: %d", (void*)pw, pw->allocation.width, pw->allocation.height );
1211 	     if ( pw != gtk_widget_get_parent( sw->stWin ) )
1212 	       printf( ", paned-pos: %d), ", gtk_paned_get_position( GTK_PANED( pw ) ) );
1213 	     else
1214 	       printf( ", box), " );
1215 	  }
1216 	while( pw != win->appWTopEdWin );
1217 	printf( "\n" );
1218 	w = sw->edWin;
1219 	printf( "EdWidget: %p: x: %d, y: %d, width: %d, height: %d\n", (void*)w,
1220 		w->allocation.x, w->allocation.y,
1221 		w->allocation.width, w->allocation.height );
1222 	w = sw->stWin;
1223 	printf( "StWidget: %p: x: %d, y: %d, width: %d, height: %d\n", (void*)w,
1224 		w->allocation.x, w->allocation.y,
1225 		w->allocation.width, w->allocation.height );
1226 	printf( "=========================================\n" );
1227 	sw = sw->next;
1228      }
1229    while ( sw != win->subWins );
1230 }
1231 
1232 void printGtkSubWin( GtkSubWinType * );
1233 
1234 /************************************
1235 * printSubWinSizes
1236 *
1237 * group: win, debug
1238 *
1239 *
1240 * debug print: "(void)"
1241 *
1242 *
1243 ************************************/
1244 
1245 #if 0
1246 static void
1247 printSubWinSizes(void)
1248 {
1249    int sumHeight;
1250    JGtkWinType *win = JGtkWin;
1251    GtkSubWinType *sw = win->subWins;
1252 
1253    printf( "Font height: %d, width: %d\n", win->fontHeight, win->fontWidth );
1254 
1255    if ( win->appWInGrid )
1256      {
1257 	printf( "appWInGrid(%p): %5d W, %5d H\n", (void*)win->appWInGrid,
1258 		win->appWInGrid->allocation.width,
1259 		win->appWInGrid->allocation.height );
1260      }
1261 
1262    /* printf( "Font height: %d, width: %d\n", win->fontHeight, win->fontWidth ); */
1263 
1264    /* sumHeight = win->fontHeight; */
1265    sumHeight = 0;
1266    if ( sw )
1267      do
1268      {
1269 	/* printGtkSubWinSize( sw ); */
1270 	printf( "SW: %p, edWin(%p): %5d W, %5d H, stWin(%p): %5d W, %5d H\n",
1271 		(void*)sw,
1272 		(void*)sw->edWin, sw->edWin->allocation.width, sw->edWin->allocation.height,
1273 		(void*)sw->stWin, sw->stWin->allocation.width, sw->stWin->allocation.height );
1274 	sumHeight += sw->edWin->allocation.height +
1275 	  sw->stWin->allocation.height;
1276 	sw = sw->next;
1277      }
1278    while ( sw != win->subWins );
1279    printf( "Sum widget height in pixel: %d\n", sumHeight );
1280 }
1281 #endif
1282 
1283 /************************************
1284 * printSubWins
1285 *
1286 * group: win, debug
1287 *
1288 *
1289 * debug print: "(void)"
1290 *
1291 *
1292 ************************************/
1293 
1294 void
printSubWins()1295 printSubWins()
1296 {
1297    int sumHeight;
1298    JGtkWinType *win = JGtkWin;
1299    GtkSubWinType *sw = win->subWins;
1300 
1301    printf( " Jed_Num_Screen_Cols: %d, Jed_Num_Screen_Rows: %d, Top_Window_SY: %d\n",
1302 	   Jed_Num_Screen_Cols, Jed_Num_Screen_Rows, Top_Window_SY );
1303 
1304    if ( win->appWInGrid )
1305      {
1306 	printf( "Win->appWInGrid: Height: %d, Width: %d\n",
1307 		win->appWInGrid->allocation.height,
1308 		win->appWInGrid->allocation.width );
1309      }
1310 
1311    printf( "Font height: %d, width: %d\n", win->fontHeight, win->fontWidth );
1312 
1313    sumHeight = win->fontHeight;
1314 
1315    if ( sw )
1316      do
1317      {
1318 	printGtkSubWin( sw );
1319 	sumHeight += sw->edWin->allocation.height +
1320 	  sw->stWin->allocation.height;
1321 	printf( "Sum widget height in pixel: %d\n", sumHeight );
1322 	sw = sw->next;
1323      }
1324    while ( sw != win->subWins );
1325 }
1326 
1327 /************************************
1328 * printJedWin
1329 *
1330 * group: win, debug
1331 *
1332 *
1333 * debug print: "w(Window_Type): %p\n", w
1334 *
1335 *
1336 ************************************/
1337 
1338 static void
printJedWin(Window_Type * w)1339 printJedWin( Window_Type *w )
1340 {
1341    printf( "Jed-Win: %p\n", (void*)w );
1342    printf( "    next: %p\n", (void*)w->next );
1343    printf( "    sx: %d, sy: %d\n", w->sx,
1344 	   w->sy );
1345    printf( "    rows: %d, width: %d\n", w->rows,
1346 	   w->width );
1347    printf( "    hscroll_column: %d\n", w->hscroll_column );
1348    printf( "    buffer: %p\n", (void*)w->buffer );
1349    printf( "    trashed: %d\n", w->trashed );
1350    printf( "    flags: %d\n", w->flags );
1351 }
1352 
1353 /************************************
1354 * printGtkSubWin
1355 *
1356 * group: win, debug
1357 *
1358 *
1359 * debug print: "sw(GtkSubWinType): %p\n", sw
1360 *
1361 *
1362 ************************************/
1363 
1364 void
printGtkSubWin(GtkSubWinType * sw)1365 printGtkSubWin( GtkSubWinType *sw )
1366 {
1367    printf( "GtkSubWinType: %p\n", (void*)sw );
1368    printJedWin( sw->jedWin );
1369    printf( "  Next: %p\n", (void*)sw->next );
1370    printf( "  EdWidget: %p\n", (void*)sw->edWin );
1371    printf( "    Win:    %p\n", (void*)sw->edWin->window );
1372    printf( "      Height: %d\n", sw->edWin->allocation.height );
1373    printf( "      Width:  %d\n", sw->edWin->allocation.width );
1374    printf( "  StWidget: %p\n", (void*)sw->stWin );
1375    printf( "    Win:    %p\n", (void*)sw->stWin->window );
1376    printf( "      Height: %d\n", sw->stWin->allocation.height );
1377    printf( "      Width:  %d\n", sw->stWin->allocation.width );
1378    printf( "  SbWidget: %p\n", (void*)sw->sbWin );
1379    printf( "  SbAdj:    %p\n", (void*)sw->sbAdj );
1380    printf( "  ppY: %d, ppX: %d\n", sw->ppY, sw->ppX );
1381    printf( "  ppHeight: %d, ppWidth: %d\n", sw->ppHeight, sw->ppWidth );
1382 }
1383 
1384 /************************************
1385 * modLineWidgetWinXRef
1386 *
1387 * debug print: "dArr(GtkSubWinType ***): %p, sArr(GtkSubWinType ***): %p, x: %d, y: %d, w: %d, source: %d", dArr, sArr, x, y, w, source
1388 *
1389 ************************************/
1390 
1391 static void
modLineWidgetWinXRef(GtkSubWinType *** dArr,GtkSubWinType *** sArr,int x,int y,int w,int source)1392 modLineWidgetWinXRef( GtkSubWinType ***dArr, GtkSubWinType ***sArr, int x, int y, int w, int source )
1393 {
1394    int i;
1395    for ( i = 0; i < w; ++i )
1396      dArr[y][x + i] = sArr[source][x + i];
1397 
1398    /* printWidgetWinXRef(); */
1399    /* printSubWins(); */
1400 }
1401 
1402 /************************************
1403 * updEdWidgetWinXRef
1404 *
1405 * group: win
1406 *
1407 * debug print: "WV: %p, y: %d, x: %d\n", wv, y, x
1408 *
1409 ************************************/
1410 
1411 void
jgtk_updEdWidgetWinXRef(Window_Type * wv,int y,int h)1412 jgtk_updEdWidgetWinXRef( Window_Type *wv, int y, int h )
1413 {
1414    int m;
1415    /* GtkWidget *w = ( GtkWidget * ) wv->window; */
1416    JGtkWinType *win = JGtkWin;
1417    GtkSubWinType *sw = win->subWins;
1418 
1419    do
1420      {
1421 	if ( sw->jedWin == wv )
1422 	  {
1423 	     break;
1424 	  }
1425 	sw = sw->next;
1426      }
1427    while ( sw != win->subWins );
1428 
1429    modWidgetWinXRef( win->widgetWinXRef, sw, 0, y, win->edWidth, h );
1430 
1431    /***********
1432    printWidgetWinXRef();
1433    printSubWins();
1434    *************/
1435 }
1436 
1437 /************************************
1438 * modWidgetWinXRef
1439 *
1440 * group: debug
1441 *
1442 * debug print: "a(GtkSubWinType ***): %p, val: %p, x: %d, y: %d, w: %d, h: %d\n", a, val, x, y, w, h
1443 *
1444 ************************************/
1445 
1446 static void
modWidgetWinXRef(GtkSubWinType *** a,GtkSubWinType * val,int x,int y,int w,int h)1447 modWidgetWinXRef( GtkSubWinType ***a, GtkSubWinType *val, int x, int y, int w, int h )
1448 {
1449    int i, i1;
1450 
1451    for ( i = 0; i < h; ++i )
1452      for ( i1 = 0; i1 < w; ++i1 )
1453        {
1454 	  a[y + i][x + i1] = val;
1455        }
1456 
1457    /* printWidgetWinXRef(); */
1458    /* printSubWins(); */
1459 }
1460 
1461 /************************************
1462 * adjustSubWinPanes
1463 *
1464 * debug print:
1465 *
1466 ************************************/
1467 
1468 static void
adjustSubWinPanes(void)1469 adjustSubWinPanes(void)
1470 {
1471    /* int i = 0; */
1472    int gutPos, accumHeight;
1473    JGtkWinType *win = JGtkWin;
1474    GtkSubWinType *sw = win->subWins, *savSW, *oldSW;
1475    GtkWidget *parBox, *parPane, *actPane;
1476 
1477    oldSW = sw;
1478    sw = sw->next;
1479 
1480    if ( gtk_widget_get_parent( sw->stWin ) != win->appWTopEdWin )
1481      {
1482 	parBox = gtk_widget_get_parent( sw->stWin );
1483 
1484       /* Dbp2( "SW: %p, ParBox: %p\n", sw, parBox ); */
1485 
1486 	actPane = gtk_widget_get_parent( parBox );
1487 
1488 	gutPos = ( oldSW->jedWin->rows + 1 ) * win->fontHeight;
1489 
1490 	accumHeight = gutPos + win->gutSize;
1491 
1492 	gtk_paned_set_position( GTK_PANED( gtk_widget_get_parent( parBox ) ), gutPos );
1493 
1494 	savSW = sw;
1495 
1496 	oldSW = sw;
1497 	sw = sw->next;
1498 
1499 	if ( sw != win->subWins )
1500 	  do
1501 	  {
1502 	     parBox = gtk_widget_get_parent( sw->stWin );
1503 
1504 	     parPane = gtk_widget_get_parent( parBox );
1505 
1506 	     gutPos = accumHeight + ( oldSW->jedWin->rows + 1 ) * win->fontHeight;
1507 
1508 	     gtk_paned_set_position( GTK_PANED( parPane ), gutPos );
1509 
1510 	     accumHeight = gutPos + win->gutSize;
1511 
1512 	     savSW = sw;
1513 
1514 	     parBox = gtk_widget_get_parent( sw->next->stWin );
1515 	     oldSW = sw;
1516 	     sw = sw->next;
1517 	  }
1518 	while ( sw != win->subWins );
1519      }
1520 }
1521 
1522 /************************************
1523 * jGtkCheckEdSize
1524 *
1525 *   Resizes widgetWinXRef if necessary to height, width
1526 *
1527 * group: win
1528 *
1529 * debug print: "Height: %d, Width: %d\n", height, width
1530 *
1531 ************************************/
1532 
1533 void
jGtkCheckEdSize(int height,int width)1534 jGtkCheckEdSize( int height, int width )
1535 {
1536    int n, m;
1537    int cpyOld;
1538    JGtkWinType *win = JGtkWin;
1539    int newHeight = height > win->maxEdHeight ? height : win->maxEdHeight;
1540    int newWidth  = width  > win->maxEdWidth  ? width  : win->maxEdWidth;
1541    GtkSubWinType ***newEdLines;
1542    GtkSubWinType **tmpLine;
1543 
1544    /* printSubWins(); */
1545 
1546    if ( ! ( height && width && win->edWidth && win->edHeight ) ) return;
1547 
1548    if ( width > win->maxEdWidth )
1549      {
1550       /* Dbp1( "Window width (%d) bigger maxEdWidth!!!\n", width ); */
1551 	if ( height > win->maxEdHeight )
1552 	  {
1553 	 /* Dbp1( "Creating new edbuffer\n", 1 ); */
1554 	     newEdLines = ( GtkSubWinType *** ) SLmalloc( sizeof( GtkSubWinType ** ) * width );
1555 	  }
1556 	else
1557 	  {
1558 	     newEdLines = win->widgetWinXRef;
1559 	  }
1560 
1561       /* if height smaller than win->edHeight backup copy lines of last window */
1562       /* below win->edHeight border. Should the lower border be part of different */
1563       /* window, function calling this function will do one_window-call!!! */
1564 
1565 	if ( height < win->edHeight )
1566 	  {
1567 	     for ( m = 0; m < win->edWidth; ++m )
1568 	       {
1569 		  win->widgetWinXRef[height - 1][m] = win->widgetWinXRef[win->edWidth - 1][m];
1570 	       }
1571 
1572 	     win->edHeight = height;
1573 	  }
1574 
1575       /* if height smaller than win->maxEdHeight simply create some new buffer lines */
1576       /* without copying anything. */
1577 
1578 	for ( n = newHeight - 1; n > height; --n )
1579 	  {
1580 	     tmpLine = ( GtkSubWinType ** ) SLmalloc( sizeof( GtkSubWinType * ) * width );
1581 	     SLfree( ( char * ) win->widgetWinXRef[n] );
1582 	     win->widgetWinXRef[n] = tmpLine;
1583 	  }
1584 
1585 	for ( n = height - 1; n >= 0; --n )
1586 	  {
1587 	     tmpLine = ( GtkSubWinType ** ) SLmalloc( sizeof( GtkSubWinType * ) * width );
1588 
1589 	     cpyOld = n;
1590 
1591 	     if ( n == height - 1 ) cpyOld = win->edHeight - 1;
1592 	     else if ( win->edHeight > 1 && win->edHeight - 2 <= n && n <= height - 2 ) cpyOld = win->edHeight - 2;
1593 	     else cpyOld = n;
1594 
1595 	     for ( m = 0; m < width; ++m )
1596 	       {
1597 		  tmpLine[m] = m < win->edWidth ? win->widgetWinXRef[cpyOld][m] : win->widgetWinXRef[cpyOld][win->edWidth - 1];
1598 	       }
1599 
1600 	     if ( n < win->maxEdHeight ) SLfree( ( char * ) win->widgetWinXRef[n] );
1601 	     newEdLines[n] = tmpLine;
1602 	  }
1603 
1604 	SLfree( ( char * ) win->widgetWinXRef );
1605 
1606 	win->widgetWinXRef = newEdLines;
1607      }
1608    else if ( height > win->maxEdHeight )
1609      {
1610       /* Dbp1( "Window height (%d) greater maxEdHeight\n", height ); */
1611 	newEdLines = ( GtkSubWinType *** ) SLmalloc( sizeof( GtkSubWinType ** ) * newHeight );
1612 
1613 	for ( n = height - 1; n >= 0; --n )
1614 	  {
1615 	     if ( n >= win->maxEdHeight )
1616 	       tmpLine = ( GtkSubWinType ** ) SLmalloc( sizeof( GtkSubWinType * ) * newWidth );
1617 	     else
1618 	       tmpLine = win->widgetWinXRef[n];
1619 
1620 	     if ( n == height - 1 ) cpyOld = win->edHeight - 1;
1621 	     else if ( win->edHeight > 1 && win->edHeight - 2 <= n && n <= height - 2 ) cpyOld = win->edHeight - 2;
1622 	     else cpyOld = n;
1623 
1624 	     if ( win->edWidth )
1625 	       for ( m = 0; m < width; ++m )
1626 		 {
1627 		    tmpLine[m] = m < win->edWidth ? win->widgetWinXRef[cpyOld][m] : win->widgetWinXRef[cpyOld][win->edWidth - 1];
1628 		 }
1629 
1630 	 /* if ( n < win->maxEdHeight ) SLfree( win->widgetWinXRef[n] ); */
1631 	     newEdLines[n] = tmpLine;
1632 	  }
1633 
1634 	SLfree( ( char * ) win->widgetWinXRef );
1635 
1636 	win->widgetWinXRef = newEdLines;
1637      }
1638 
1639    win->maxEdWidth = newWidth;
1640    win->maxEdHeight = newHeight;
1641 
1642    win->edWidth = width;
1643    win->edHeight = height;
1644 
1645    /* Dbp( "Win->edWidth: %d\n", win->edWidth ); */
1646    /* Dbp( "Win->edHeight: %d\n", win->edHeight ); */
1647    /* printWidgetWinXRef(); */
1648 }
1649 
1650 /************************************
1651 * jGtkWidenEd
1652 *
1653 * debug print:
1654 *
1655 ************************************/
1656 
1657 void
jGtkWidenEd(int height,int newW,int oldW)1658 jGtkWidenEd( int height, int newW, int oldW )
1659 {
1660    int i, i1, n = oldW - 1;
1661    GtkSubWinType ***img = JGtkWin->widgetWinXRef;
1662 
1663    for ( i = 0; i < height; ++i )
1664      for ( i1 = oldW; i1 < newW; ++i1 )
1665        {
1666 	  img[i][i1] = img[i][n];
1667        }
1668 }
1669 
1670 /************************************
1671 * updateWidgetWinXRef
1672 *
1673 *  Overwrites widgetWinXRef with sw for new sy, sx, nHeight, nWidth
1674 *  sets subWinParameter sx, sy, width, height accordingly
1675 *
1676 * group: win
1677 *
1678 * debug print: "sw: %p, sy: %d, sx: %d, nHeight: %d, nWidth: %d\n", sw, sy, sx, nHeight, nWidth
1679 *
1680 ************************************/
1681 
1682 void
updateWidgetWinXRef(GtkSubWinType * sw,int sy,int sx,int nHeight,int nWidth)1683 updateWidgetWinXRef( GtkSubWinType *sw, int sy, int sx, int nHeight, int nWidth )
1684 {
1685    int i, i1;
1686    int minY, maxY;
1687    JGtkWinType *win = JGtkWin;
1688 
1689    /*********
1690    Dbp1( "--%d-------------------------------------------------\n", 1 );
1691    printWidgetWinXRef();
1692    printSubWins();
1693    Dbp1( "--%d-------------------------------------------------\n", 1 );
1694    *********/
1695 
1696    /* printGtkSubWin( sw ); */
1697 
1698    if ( sy > sw->jedWin->sy + sw->jedWin->rows || sy + nHeight < sw->jedWin->sy ||
1699 	sx > sw->jedWin->sx + sw->jedWin->width || sx + nWidth  < sw->jedWin->sx )
1700      {
1701       /* Dbp( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n", 1 ); */
1702 
1703 	for ( i = sy; i < sy + nHeight; ++i )
1704 	  {
1705 	 /* Dbp( "i: %d\n", i ); */
1706 	     for ( i1 = sx; i1 < sx + nWidth; ++i1 )
1707 	       {
1708 	    /* Dbp( "i1: %d\n", i1 ); */
1709 		  win->widgetWinXRef[i][i1] = sw;
1710 	       }
1711 	  }
1712      }
1713    else
1714      {
1715 	for ( i = sy; i < sw->jedWin->sy; ++i )
1716 	  {
1717 	 /* Dbp( "i: %d\n", i ); */
1718 	     for ( i1 = sx; i1 < sx + nWidth; ++i1 )
1719 	       {
1720 	    /* Dbp( "i1: %d\n", i1 ); */
1721 		  win->widgetWinXRef[i][i1] = sw;
1722 	       }
1723 	  }
1724 
1725 	minY = sy < sw->jedWin->sy ? sw->jedWin->sy : sy;
1726 	maxY = sy + nHeight < sw->jedWin->sy + sw->jedWin->rows + 1 ? sy + nHeight : sw->jedWin->sy + sw->jedWin->rows + 1;
1727 
1728       /* Dbp( "Min Y: %d\n", minY ); */
1729       /* Dbp( "Max Y: %d\n", maxY ); */
1730 
1731 	for ( i = minY; i < maxY; ++i )
1732 	  {
1733 	 /* Dbp( "i: %d\n", i ); */
1734 	     for ( i1 = sx; i1 < sw->jedWin->sx; ++i1 )
1735 	       {
1736 	    /* Dbp( "i1: %d\n", i1 ); */
1737 		  win->widgetWinXRef[i][i1] = sw;
1738 	       }
1739 
1740 	     for ( i1 = sw->jedWin->sx + sw->jedWin->width; i1 < sx + nWidth; ++i1 )
1741 	       {
1742 	    /* Dbp( "i1: %d\n", i1 ); */
1743 		  win->widgetWinXRef[i][i1] = sw;
1744 	       }
1745 	  }
1746 
1747 	for ( i = sw->jedWin->sy + sw->jedWin->rows + 1; i < sy + nHeight; ++i )
1748 	  {
1749 	 /* Dbp( "i: %d\n", i ); */
1750 	     for ( i1 = sx; i1 < sx + nWidth; ++i1 )
1751 	       {
1752 	    /* Dbp( "i1: %d\n", i1 ); */
1753 		  win->widgetWinXRef[i][i1] = sw;
1754 	       }
1755 	  }
1756      }
1757    sw->jedWin->sy = sy;
1758    sw->jedWin->sx = sx;
1759    sw->jedWin->rows = nHeight - 1;
1760    sw->jedWin->width = nWidth;
1761 
1762    /**********
1763    Dbp1( "==%d==========================================\n", 2 );
1764    printWidgetWinXRef();
1765    printSubWins();
1766    Dbp1( "==%d==========================================\n", 2 );
1767    *******/
1768 
1769    /* printGtkSubWin( sw ); */
1770 }
1771 
1772 void
jgtk_updMiniWinWidgetWinXRef(int n)1773 jgtk_updMiniWinWidgetWinXRef( int n )
1774 {
1775    int i = Jed_Num_Screen_Cols - 1;
1776    JGtkWinType *win = JGtkWin;
1777 
1778    for ( ; i >= 0; --i )
1779      {
1780 	win->widgetWinXRef[n][i] = win->miniWinSW;
1781      }
1782 }
1783 
1784 /************************************
1785 * splitEdWin
1786 *
1787 * group: win
1788 *
1789 *
1790 * debug print: "Widget (wv): %p, sy: %d, sx: %d, height: %d, scroll: %d, width: %d\n", wv, sy, sx, height, scroll, width
1791 *
1792 ************************************/
1793 
1794 void
jgtk_splitEdWin(Window_Type * wv,Window_Type * newJedW,int sy,int sx,int height,int scroll,int width)1795 jgtk_splitEdWin( Window_Type *wv, Window_Type *newJedW, int sy, int sx, int height, int scroll, int width )
1796 {
1797    int n, m;
1798    int isFirstPane = 1;
1799    JGtkWinType *win = JGtkWin;
1800    GtkWidget *wEd = win->widgetWinXRef[sy][sx]->edWin;
1801    GtkWidget *wSt = win->widgetWinXRef[sy + height][sx]->stWin;
1802    GtkWidget *curEdBox = gtk_widget_get_parent( gtk_widget_get_parent( wEd ) );
1803    GtkWidget *parW = gtk_widget_get_parent( curEdBox );
1804    GtkWidget *newPaned = gtk_vpaned_new();
1805    GtkSubWinType *sw, *newSW = createGtkWinTmpl( ( GtkSubWinType * ) SLmalloc( sizeof( GtkSubWinType ) ) );
1806    /* EdWinWidgetType newW = createGtkWinTmpl( newSW ); */
1807    GtkWidget *edBox = gtk_widget_get_parent( gtk_widget_get_parent( newSW->edWin ) );
1808 
1809    newSW->edX =
1810      newSW->edY =
1811      newSW->edHeight =
1812      newSW->edWidth = 0;
1813 
1814    /************
1815    printWidgetWinXRef();
1816    printSubWins();
1817    ********/
1818 
1819    g_signal_connect( G_OBJECT( newPaned ),
1820 		     "button_press_event",
1821 		     G_CALLBACK( eventCallback ),
1822 		     NULL );
1823 
1824    g_signal_connect( G_OBJECT( newPaned ),
1825 		     "button_release_event",
1826 		     G_CALLBACK( eventCallback ),
1827 		     NULL );
1828 
1829    /* Dbp2( "win->gutSize: %d, win->numWin: %d\n", win->gutSize, win->numWin ); */
1830    if ( !win->gutSize && win->subWins != win->subWins->next )
1831      {
1832 	GtkWidget *topPaned = win->appWTopEdWin;
1833 	win->gutSize =
1834 	  topPaned->allocation.height -
1835 	  gtk_paned_get_child1( GTK_PANED( topPaned ) )->allocation.height -
1836 	  gtk_paned_get_child2( GTK_PANED( topPaned ) )->allocation.height;
1837       /* Dbp1( "Guttersize: %d\n", win->gutSize ); */
1838      }
1839 
1840    /* printWidgetStruct(); */
1841 
1842    updateGtkWin = 0;
1843 
1844    /*********************************************
1845    * Currently, as of gtk+ version 2.12.0 there is
1846    * no function to return the gutter size. So
1847    * we have to compute them ourself.
1848    *********************************************/
1849 
1850    if ( curEdBox != win->appWTopEdWin )
1851      {
1852 	isFirstPane = ( curEdBox == gtk_paned_get_child1( GTK_PANED( parW ) ) );
1853      }
1854 
1855    /*********
1856    gtk_paned_add1( GTK_PANED( newPaned ), curEdBox );
1857 
1858    g_object_unref( curEdBox );
1859    ***********/
1860 
1861    gtk_paned_add2( GTK_PANED( newPaned ), edBox );
1862 
1863    if ( isFirstPane ) /* also true for curEdBox == win->appWTopEdWin */
1864      {
1865 	g_object_ref( curEdBox );
1866 	gtk_container_remove( GTK_CONTAINER( parW ), curEdBox );
1867 	gtk_paned_add1( GTK_PANED( newPaned ), curEdBox );
1868 	g_object_unref( curEdBox );
1869 	if ( curEdBox == win->appWTopEdWin )
1870 	  {
1871 	     gtk_box_pack_start( GTK_BOX( win->appWInGrid ), newPaned, True, True, 0 );
1872 	     win->appWTopEdWin = newPaned;
1873 	 /* Dbp4( "Splitting top window: old: %p, newBox: %p, new.ed: %p, new.status: %p\n", curEdBox, edBox, newW.ed, newW.st ); */
1874 	  }
1875 	else
1876 	  {
1877 	     gtk_paned_add1( GTK_PANED( parW ), newPaned );
1878          /* Dbp2( "Splitting first pane: old: %p, new: %p\n", curEdBox, edBox ); */
1879 	  }
1880      }
1881    else
1882      {
1883 	GtkWidget *gParW = gtk_widget_get_parent( parW );
1884 
1885       /* Db; */
1886 
1887 	if ( parW != win->appWTopEdWin )
1888 	  {
1889 	     isFirstPane = ( parW == gtk_paned_get_child1( GTK_PANED( gParW ) ) );
1890 	  }
1891 
1892       /* Db; */
1893 
1894 	g_object_ref( parW );
1895 	gtk_container_remove( GTK_CONTAINER( gParW ), parW );
1896 	gtk_paned_add1( GTK_PANED( newPaned ), parW );
1897 	g_object_unref( parW );
1898 
1899       /* Db; */
1900 
1901 	if ( parW == win->appWTopEdWin )
1902 	  {
1903 	     gtk_box_pack_start( GTK_BOX( win->appWInGrid ), newPaned, True, True, 0 );
1904 	     win->appWTopEdWin = newPaned;
1905 	  }
1906 	else
1907 	  {
1908 	     gtk_paned_add1( GTK_PANED( gParW ), newPaned );
1909 	  }
1910      }
1911 
1912    /*******
1913    Db;
1914 
1915    printWidgetStruct();
1916    **********/
1917 
1918    sw = win->subWins;
1919 
1920    do
1921      {
1922 	if ( sw->jedWin == wv )
1923 	  {
1924 	     break;
1925 	  }
1926 	sw = sw->next;
1927      }
1928    while ( sw != win->subWins );
1929 
1930    newSW->jedWin = newJedW;
1931    /* newSW->edWin = newW.ed; */
1932    /* newSW->stWin = newW.st; */
1933    /* newSW->sbWin = newW.sb; */
1934 
1935    newSW->sbAdj = gtk_range_get_adjustment( GTK_RANGE( newSW->sbWin ) );
1936    newSW->numLineSav =
1937      newSW->curLineSav =
1938      newSW->winHeightSav = 0;
1939 
1940    newSW->ppHeight = 0;
1941    newSW->next = sw->next;
1942    sw->next = newSW;
1943 
1944    win->numWin++;
1945 
1946    /************
1947    gtk_widget_show_all( win->appWTopEdWin );
1948 
1949    if ( gtk_events_pending() )
1950      {
1951       gtk_main_iteration();
1952       }
1953    *****************/
1954 
1955    /********/
1956    /* Db; */
1957 
1958    /* printWidgetStruct(); */
1959    /**************/
1960 
1961    modWidgetWinXRef( win->widgetWinXRef, newSW, sx, sy, width, height + 1 );
1962 
1963    /*****
1964    printf( "vvvvvv111111111111111111111111111111111111111111111111111111vvvvvv\n" );
1965    printWidgetWinXRef();
1966    printSubWins();
1967    printf( "^^^^^^111111111111111111111111111111111111111111111111111111^^^^^^\n" );
1968    ******/
1969    /* Db; */
1970 
1971    adjustSubWinPanes();
1972 
1973    /* gtk_widget_show_all( parW ); */
1974 
1975    /* gtk_widget_show_all( newPaned ); */
1976 
1977    gtk_widget_grab_focus( newSW->edWin );
1978 
1979    /*********
1980    Db;
1981 
1982    printWidgetStruct();
1983    ************/
1984    /*******/
1985    /* printf( "vvvvvv2222222222222222222222222222222222222222222222222222222vvvvvv\n" ); */
1986    /* updateInGridHeight(); */
1987    /* printf( "^^^^^^2222222222222222222222222222222222222222222222222222222^^^^^^\n" ); */
1988    /*****/
1989 
1990    /***********
1991    Db;
1992    printWidgetStruct();
1993    **********/
1994 
1995    /* adjustSubWinPanes(); */
1996    updateGtkWin = 1;
1997    gtk_widget_show_all( win->appWTopEdWin );
1998 
1999    jGtkSetFGBGColor( newSW->edWin, JNORMAL_COLOR );
2000    jGtkSetFGBGColor( newSW->stWin, JNORMAL_COLOR );
2001 }
2002 
2003 /************************************
2004 * updOWEdWin
2005 *
2006 * group: win
2007 *
2008 * debug print: "WV: %p, nsy: %d, nsx: %d, nheight: %d, nwidth: %d\n", wv, nsy, nsx, nheight, nwidth
2009 *
2010 ************************************/
2011 
2012 void
jgtk_updOWEdWin(Window_Type * wv,int nsy,int nsx,int nheight,int nwidth)2013 jgtk_updOWEdWin( Window_Type *wv, int nsy, int nsx, int nheight, int nwidth )
2014 {
2015    int n, m;
2016    JGtkWinType *win = JGtkWin;
2017    GtkSubWinType *winList = win->subWins;
2018    GtkWidget *actEdWin = win->widgetWinXRef[wv->sy][wv->sx]->edWin;
2019    GtkWidget *ow = gtk_widget_get_parent( gtk_widget_get_parent( actEdWin ) );
2020    GtkWidget *parOW = gtk_widget_get_parent( ow );
2021    /* GtkWidget *childOW = gtk_paned_get_child2( GTK_PANED( ow ) ); */
2022    GtkSubWinType *sw, *owSW, *delSW;
2023 
2024    /* printf( "updOWEdWin: ow: %p\n", ow ); */
2025 
2026    /* if ( childOW ) gtk_widget_destroy( childOW ); */
2027 
2028    /* Updating list of subWins ************/
2029 
2030    sw = win->subWins;
2031 
2032    do
2033      {
2034 	if ( sw->jedWin == wv )
2035 	  {
2036 	     owSW = sw;
2037 	     sw = sw->next;
2038 	  }
2039 	else
2040 	  {
2041 	     delSW = sw;
2042 	     sw = sw->next;
2043 	     SLfree( ( char * ) delSW );
2044 	  }
2045      }
2046    while ( sw != win->subWins );
2047 
2048    owSW->ppHeight = 0;
2049    owSW->next = owSW;
2050    win->subWins = owSW;
2051    win->numWin = 1;
2052 
2053    /* Updating widgetWinXRef **************/
2054 
2055    modWidgetWinXRef( win->widgetWinXRef, owSW, nsx, nsy, nwidth, nheight );
2056 
2057    /**************
2058    for ( m = 0; m <= nheight; ++m )
2059      for ( n = 0; n < nwidth; ++n )
2060        win->widgetWinXRef[nsy + m][nsx + n] = owSW;
2061    ***************/
2062 
2063    if ( ow != win->appWTopEdWin )
2064      {
2065       /* printf( "Removing one window from pane: %p\n", parOW ); */
2066 	updateGtkWin = 0;
2067 	g_object_ref( ow );
2068 	gtk_container_remove( GTK_CONTAINER( parOW ), ow );
2069 	gtk_widget_destroy( win->appWTopEdWin );
2070 	win->appWTopEdWin = ow;
2071 	gtk_box_pack_start( GTK_BOX( win->appWInGrid ), ow, True, True, 0 );
2072 	g_object_unref( ow );
2073 	gtk_widget_show_all( win->appWTopEdWin );
2074 	gtk_widget_grab_focus( actEdWin );
2075 	updateGtkWin = 1;
2076      }
2077 
2078    /**********
2079    printf( "(updOWEdWin): -----vvv---------------\n" );
2080    printWidgetWinXRef();
2081    printf( "(updOWEdWin): -----^^^---------------\n" );
2082    ********/
2083 
2084 }
2085 
2086 /************************************
2087 * createTopEdWin
2088 *
2089 * group: win
2090 *
2091 *
2092 * debug print: "w: %p, sy: %d, sx: %d, height: %d, scroll: %d, width: %d\n", w, sy, sx, height, scroll, width
2093 *
2094 ************************************/
2095 
2096 void
jgtk_createTopEdWin(Window_Type * w,int sy,int sx,int height,int scroll,int width)2097 jgtk_createTopEdWin( Window_Type *w, int sy, int sx, int height, int scroll, int width )
2098 {
2099    int n, m;
2100    JGtkWinType *win = JGtkWin;
2101    GtkSubWinType *newSW = createGtkWinTmpl( ( GtkSubWinType * ) SLmalloc( sizeof( GtkSubWinType ) ) );
2102 
2103    newSW->next = newSW;
2104    newSW->jedWin = w;
2105 
2106    newSW->sbAdj = gtk_range_get_adjustment( GTK_RANGE( newSW->sbWin ) );
2107    newSW->numLineSav =
2108      newSW->curLineSav =
2109      newSW->winHeightSav = 0;
2110 
2111    newSW->ppHeight = 0;
2112    win->subWins = newSW;
2113 
2114    jGtkCheckEdSize( win->edHeight + sy + height + 1, sx + width );
2115 
2116    if ( win->appWMiniW )
2117      {
2118 	modLineWidgetWinXRef( win->widgetWinXRef, win->widgetWinXRef, 0, win->edHeight + sy + height, sx + width, 0 );
2119      }
2120 
2121    if ( win->appWTopEdWin )
2122      {
2123 	gtk_widget_destroy( win->appWTopEdWin );
2124      }
2125 
2126    win->appWTopEdWin = gtk_widget_get_parent( gtk_widget_get_parent( newSW->edWin ) );
2127 
2128    gtk_box_pack_start( GTK_BOX( win->appWInGrid ), win->appWTopEdWin, True, True, 0 );
2129 
2130    /* printf( "createTopEdWin: newDrawArea: %p\n", win->appWTopEdWin ); */
2131 
2132    modWidgetWinXRef( win->widgetWinXRef, newSW, sx, sy, width, height + 1 );
2133 #if 0
2134    for ( m = 0; m <= height; ++m )
2135      for ( n = 0; n < width; ++n )
2136        {
2137 	/* printf( "Height: %d, width: %d, n: %d, sy: %d, sx: %d\n", height, width, n, sy, sx ); */
2138 	/* printf( "win->widgetWinXRef: %p\n", win->widgetWinXRef ); */
2139 	  win->widgetWinXRef[sy + m][sx + n] = newSW;
2140        }
2141 #endif
2142    /* Db; */
2143    /* printWidgetWinXRef(); */
2144 
2145    gtk_widget_show_all( win->appWTopEdWin );
2146 
2147    gtk_widget_grab_focus( newSW->edWin );
2148 
2149    jGtkSetFGBGColor( newSW->edWin, JNORMAL_COLOR );
2150    jGtkSetFGBGColor( newSW->stWin, JNORMAL_COLOR );
2151 
2152    /* Db; */
2153    /* printWidgetWinXRef(); */
2154 }
2155 
2156 /************************************
2157 * delEdWin
2158 *
2159 * group: win
2160 *
2161 *
2162 * debug print: "WV: %p, SubW: %p, sy: %d, sx: %d, height: %d, width: %d, lastLine: %d\n", wv, subW, sy, sx, height, width, lastLine
2163 *
2164 ************************************/
2165 
2166 void
jgtk_delEdWin(Window_Type * wv,Window_Type * subW,int sy,int sx,int height,int width,int lastLine)2167 jgtk_delEdWin( Window_Type *wv, Window_Type *subW, int sy, int sx, int height, int width, int lastLine )
2168 {
2169    int m, n;
2170    int isFirstPane;
2171    JGtkWinType *win = JGtkWin;
2172    /* GtkWidget *w = ( GtkWidget * ) wv->window; */
2173    GtkWidget *wBox = gtk_widget_get_parent( gtk_widget_get_parent( win->widgetWinXRef[wv->sy][wv->sx]->edWin ) );
2174    GtkWidget *parW = gtk_widget_get_parent( wBox );
2175    GtkWidget *gParW; /* Grandparent */
2176    GtkWidget *remW;
2177    GtkSubWinType *subWSW = win->widgetWinXRef[subW->sy][subW->sx];
2178    GtkSubWinType *wvSW = win->widgetWinXRef[wv->sy][wv->sx];
2179    GtkSubWinType *sw;
2180 
2181    if ( wBox == win->appWTopEdWin )
2182      {
2183 	return;
2184      }
2185 
2186    if ( subW->sy == wv->sy )
2187      {
2188 	subWSW = win->widgetWinXRef[subW->sy + subW->rows - 1][subW->sx];
2189      }
2190 
2191    if ( subWSW->next == wvSW )
2192      {
2193 	subWSW->next = wvSW->next;
2194      }
2195    else
2196      {
2197 	sw = win->subWins;
2198 
2199 	do
2200 	  {
2201 	     if ( sw->next == wvSW ) break;
2202 	     sw = sw->next;
2203 	  }
2204 	while ( sw != win->subWins );
2205 
2206 	sw->next = subWSW;
2207      }
2208 
2209    SLfree( ( char * ) wvSW );
2210 
2211    if ( wvSW == win->subWins )
2212      {
2213 	win->subWins = subWSW;
2214      }
2215 
2216    --win->numWin;
2217 
2218    modWidgetWinXRef( win->widgetWinXRef, subWSW, sx, sy, width, height );
2219 
2220    /***************
2221    for ( n = 0; n < height; ++n )
2222      for ( m = 0; m < width; ++m )
2223        {
2224         win->widgetWinXRef[sy + n][sx + m] = subWSW;
2225 	}
2226    ****************/
2227 
2228    if ( wv->sy == subW->sy )
2229      {
2230 	modWidgetWinXRef( win->widgetWinXRef, subWSW, wv->sx, wv->sy + wv->rows, width, 1 );
2231       /****************
2232       for ( m = 0; m < width; ++m )
2233 	{
2234 	 win->widgetWinXRef[wv->sy + wv->rows][wv->sx + m] = subWSW;
2235 	 }
2236       ******************/
2237      }
2238    else
2239      {
2240 	modWidgetWinXRef( win->widgetWinXRef, subWSW, wv->sx, subW->sy + subW->rows, width, 1 );
2241 #if 0
2242 	for ( m = 0; m < width; ++m )
2243 	  {
2244 	 /* win->widgetWinXRef[wv->sy - 1][wv->sx + m].jedWin = subW; */
2245 	     win->widgetWinXRef[subW->sy + subW->rows][wv->sx + m] = subWSW;
2246 	  }
2247 #endif
2248      }
2249 
2250    updateGtkWin = 0;
2251 
2252    if ( wBox == gtk_paned_get_child1( GTK_PANED( parW ) ) )
2253      {
2254 	remW = gtk_paned_get_child2( GTK_PANED( parW ) );
2255      }
2256    else
2257      {
2258 	remW = gtk_paned_get_child1( GTK_PANED( parW ) );
2259      }
2260 
2261    g_object_ref( remW );
2262    gtk_container_remove( GTK_CONTAINER( parW ), remW );
2263 
2264    if ( parW == win->appWTopEdWin )
2265      {
2266 	gtk_widget_destroy( parW );
2267 	win->appWTopEdWin = remW;
2268 	gtk_box_pack_start( GTK_BOX( win->appWInGrid ), remW, True, True, 0 );
2269 	g_object_unref( remW );
2270      }
2271    else
2272      {
2273 	gParW = gtk_widget_get_parent( parW );
2274 	isFirstPane = ( parW == gtk_paned_get_child1( GTK_PANED( gParW ) ) );
2275 	gtk_widget_destroy( parW );
2276 	if ( isFirstPane )
2277 	  {
2278 	     gtk_paned_add1( GTK_PANED( gParW ), remW );
2279 	  }
2280 	else
2281 	  {
2282 	     gtk_paned_add2( GTK_PANED( gParW ), remW );
2283 	  }
2284      }
2285 
2286    gtk_widget_show_all( remW );
2287 
2288    gtk_widget_grab_focus( subWSW->edWin );
2289 
2290    updateGtkWin = 1;
2291 
2292    /******************
2293    printWidgetWinXRef();
2294    ****************/
2295 
2296 }
2297 
2298 /************************************
2299 * createEditorMiniWin
2300 *
2301 * group: win
2302 *
2303 *
2304 * debug print: "mw(Window_Type): %p\n", mw
2305 *
2306 *
2307 ************************************/
2308 
2309 int
jgtk_createEditorMiniWin(Window_Type * mw)2310 jgtk_createEditorMiniWin( Window_Type *mw )
2311 {
2312    int i;
2313    JGtkWinType *win = JGtkWin;
2314    GtkWidget *newMiniWin = createGtkMiniWin();
2315 
2316    jGtkCheckEdSize( 1, mw->width );
2317 
2318    if ( win->appWMiniW )
2319      {
2320 	gtk_widget_destroy( win->appWMiniW );
2321      }
2322 
2323    win->appWMiniW = newMiniWin;
2324 
2325    gtk_widget_set_size_request( win->appWMiniW, -1, win->fontHeight );
2326 
2327    gtk_box_pack_start( GTK_BOX( win->appWEdGrid ), newMiniWin, False, False, 0 );
2328 
2329    win->edWidth = mw->width;
2330    win->edHeight = 1;
2331 
2332    gtk_widget_show_all( newMiniWin );
2333 
2334    gtk_widget_grab_focus( newMiniWin );
2335 
2336    win->miniWinSW = ( GtkSubWinType * ) SLmalloc( sizeof( GtkSubWinType ) );
2337 
2338    win->miniWinSW->jedWin = mw;
2339    win->miniWinSW->next = NULL;
2340    win->miniWinSW->edWin = newMiniWin;
2341    win->miniWinSW->stWin = newMiniWin;
2342    win->miniWinSW->ppHeight = 0;
2343 
2344    modWidgetWinXRef( win->widgetWinXRef, win->miniWinSW, 0, win->edHeight - 1, win->edWidth, 1 );
2345 
2346    for ( i = 0; i < JMAX_COLORS; ++i )
2347      {
2348 	DefaultGtkGCInfo[i].gc = gdk_gc_new( win->appWMiniW->window );
2349      }
2350 
2351    /* Db; */
2352    /* printf( "################################################################\n" ); */
2353    /*printWidgetWinXRef(); */
2354    /* printGtkSubWin( sw ); */
2355    /* printf( "################################################################\n" ); */
2356 
2357    /* Return( newMiniWin ); */
2358 
2359    return 0;
2360 }
2361 
2362 /************************************
2363 * jGtkWinDestroy
2364 *
2365 * group: app
2366 *
2367 *
2368 * debug print:
2369 *
2370 *
2371 ************************************/
2372 
2373 static void
jGtkWinDestroy(GtkWidget * widget,gpointer data)2374 jGtkWinDestroy( GtkWidget *widget,
2375 		gpointer data )
2376 {
2377    exit( 0 );
2378 }
2379 
2380 /************************************
2381 * jGtkSetWinSizes
2382 *
2383 * debug print:
2384 *
2385 ************************************/
2386 
jGtkSetWinSizes(void)2387 void jGtkSetWinSizes(void)
2388 {
2389    JGtkWinType   *win = JGtkWin;
2390    GtkSubWinType *sw = win->subWins;
2391 
2392    adjustSubWinPanes();
2393 
2394    return;
2395 
2396    do
2397      {
2398       /* Dbp1( "Height: %d\n", ( sw->jedWin->rows + 1 ) * win->fontHeight); */
2399 	gtk_widget_set_size_request( sw->edWin, -1, sw->jedWin->rows * win->fontHeight );
2400 	sw = sw->next;
2401      }
2402    while ( sw != win->subWins );
2403 
2404 }
2405 
2406 /************************************
2407 * updateHeightOfSubWinStatusWins
2408 *
2409 * debug print:
2410 *
2411 ************************************/
2412 
2413 static void
updateHeightOfSubWinStatusWins(void)2414 updateHeightOfSubWinStatusWins(void)
2415 {
2416 
2417    JGtkWinType *win = JGtkWin;
2418    GtkSubWinType *sw = win->subWins;
2419 
2420    if ( sw )
2421      do
2422      {
2423 	gtk_widget_set_size_request( sw->stWin, -1, win->fontHeight );
2424 	sw = sw->next;
2425      }
2426    while ( sw != win->subWins );
2427 
2428    if ( win->miniWinSW )
2429      {
2430 	gtk_widget_set_size_request( win->miniWinSW->edWin, -1, win->fontHeight );
2431      }
2432 }
2433 
2434 /************************************
2435 * loadFont
2436 *
2437 * debug print: "FontName: |%s|\n", fontName
2438 *
2439 ************************************/
2440 
2441 static void
loadFont(char * fontName)2442 loadFont( char *fontName )
2443 {
2444    JGtkWinType *win = JGtkWin;
2445 
2446    SLfree( win->fontName );
2447    win->fontName = SLmalloc( strlen( fontName ) + 1 );
2448    strcpy( win->fontName, fontName );
2449 
2450    win->fontDescription = pango_font_description_from_string( win->fontName );
2451    win->fontMetrics = pango_context_get_metrics( win->fontContext,
2452 						 win->fontDescription,
2453 						 NULL );
2454    win->fontAscent = pango_font_metrics_get_ascent( win->fontMetrics ) / PANGO_SCALE;
2455    win->fontDescent = pango_font_metrics_get_descent( win->fontMetrics ) / PANGO_SCALE;
2456 
2457    /* printf( "Scale: %d; Ascent: %d, Descent: %d\n", PANGO_SCALE, win->fontAscent, win->fontDescent ); */
2458 
2459    win->fontHeight = win->fontAscent + win->fontDescent;
2460 
2461    win->fontWidth = pango_font_metrics_get_approximate_char_width( win->fontMetrics ) / PANGO_SCALE;
2462    /* printf( "Scale: %d; charWidth: %d\n", PANGO_SCALE, win->fontWidth ); */
2463 
2464    updateHeightOfSubWinStatusWins();
2465 
2466    jed_init_display();
2467    jed_redraw_screen( 1 );
2468 }
2469 
2470 static void
jGtkMenuCreateDef(JGtkWinType * win)2471 jGtkMenuCreateDef( JGtkWinType *win )
2472 {
2473 
2474    jgtk_initToolbarArray();
2475 
2476    jgtk_initMenubarStruct();
2477 
2478    if ( !win->appWMenuBar )
2479      {
2480       /* Dbp1( "win->appWMenuBar: %p\n", win->appWMenuBar ); */
2481 	win->appWMenuBar = gtk_menu_bar_new();
2482 
2483       /* Db; */
2484 
2485 	win->appWMenu = gtk_menu_new();
2486 
2487 	win->appWMenuItemOpen = gtk_menu_item_new_with_label( "Open" );
2488 	win->appWMenuItemSave = gtk_menu_item_new_with_label( "Save" );
2489 	win->appWMenuItemClose = gtk_menu_item_new_with_label( "Close" );
2490 
2491 	gtk_widget_show( win->appWMenuItemOpen );
2492 	gtk_widget_show( win->appWMenuItemSave );
2493 	gtk_widget_show( win->appWMenuItemClose );
2494 
2495 	gtk_menu_shell_append( GTK_MENU_SHELL( win->appWMenu ), win->appWMenuItemOpen );
2496 	gtk_menu_shell_append( GTK_MENU_SHELL( win->appWMenu ), win->appWMenuItemSave );
2497 	gtk_menu_shell_append( GTK_MENU_SHELL( win->appWMenu ), win->appWMenuItemClose );
2498 
2499 	win->appWMenuItem = gtk_menu_item_new_with_label( "File" );
2500 
2501 	gtk_menu_item_set_submenu( GTK_MENU_ITEM( win->appWMenuItem ), win->appWMenu );
2502 
2503 	gtk_menu_bar_append( GTK_MENU_BAR( win->appWMenuBar ), win->appWMenuItem );
2504      }
2505 
2506    gtk_widget_show_all( win->appWMenuBar );
2507 }
2508 
2509 /************************************
2510 * createGtkMainWindow
2511 *
2512 * group: win
2513 *
2514 *
2515 * debug print: "(void)"
2516 *
2517 *
2518 ************************************/
2519 
2520 static void
createGtkMainWindow(void)2521 createGtkMainWindow(void)
2522 {
2523    GtkWidget *tmpFrame;
2524    JGtkWinType  *win = JGtkWin;
2525    GdkColor white = { 0, 0xffff, 0xffff, 0xffff };
2526    /********
2527    GParamSpec *param = g_param_spec_int( "testval",
2528 					 "testing",
2529 					 "test test test",
2530 					 -10, 1000, 0,
2531 					 G_PARAM_READABLE );
2532    GValue val;
2533    ******/
2534 
2535    win->appW = gtk_window_new( GTK_WINDOW_TOPLEVEL );
2536 
2537    /*********
2538    gtk_widget_class_install_style_property( GTK_WIDGET_CLASS( G_OBJECT_GET_CLASS( win->appW ) ),
2539 					    param );
2540 
2541    gtk_rc_parse( "/root/.gtkjed" );
2542 
2543    g_value_init( &val, G_PARAM_SPEC_VALUE_TYPE( param ) );
2544 
2545    gtk_widget_style_get_property( win->appW, "testval", &val );
2546 
2547    Dbp1( "Value: %d\n", g_value_get_int( &val ) );
2548    ***********/
2549 
2550    gtk_window_set_default_size( GTK_WINDOW( win->appW ), 100, 300 );
2551 
2552    g_signal_connect( G_OBJECT( win->appW ),
2553 		     "destroy",
2554 		     G_CALLBACK( jGtkWinDestroy ),
2555 		     NULL );
2556 
2557    win->appWGrid = gtk_vbox_new( False, 0 );
2558 
2559    win->appWMenuBar = NULL;
2560 
2561    jGtkMenuCreateDef( win );
2562 
2563    gtk_box_pack_start( GTK_BOX( win->appWGrid ), win->appWMenuBar, False, False, 0 );
2564 
2565    win->appWTbGrid = gtk_vbox_new( False, 0 );
2566    gtk_box_pack_start( GTK_BOX( win->appWGrid ), win->appWTbGrid, False, False, 0 );
2567 
2568    win->appWEdGrid = gtk_vbox_new( False, 0 );
2569    gtk_box_pack_start( GTK_BOX( win->appWGrid ), win->appWEdGrid, True, True, 0 );
2570 
2571    g_signal_connect( G_OBJECT( win->appWEdGrid ),
2572 		     "configure_event",
2573 		     G_CALLBACK( eventCallback ), NULL );
2574 
2575    win->widgetWinXRef = NULL;
2576 
2577    win->appWInGrid = gtk_vbox_new( False, 0 );
2578    gtk_box_pack_start( GTK_BOX( win->appWEdGrid ), win->appWInGrid, True, True, 0 );
2579 
2580    win->appWASCMenu =
2581      win->appWTopEdWin =
2582      win->appWMiniW = NULL;
2583 
2584    win->appWSB = gtk_statusbar_new();
2585    gtk_widget_add_events( win->appWSB, GDK_KEY_PRESS_MASK );
2586    gtk_box_pack_start( GTK_BOX( win->appWGrid ), win->appWSB, False, True, 0 );
2587 
2588    gtk_container_add( GTK_CONTAINER( win->appW ), win->appWGrid );
2589 
2590    win->fontContext = gtk_widget_create_pango_context( win->appWSB );
2591    win->fontDescription = pango_font_description_from_string( win->fontName );
2592    win->fontMetrics = pango_context_get_metrics( win->fontContext,
2593 						 win->fontDescription,
2594 						 NULL );
2595    win->fontAscent = pango_font_metrics_get_ascent( win->fontMetrics ) / PANGO_SCALE;
2596    win->fontDescent = pango_font_metrics_get_descent( win->fontMetrics ) / PANGO_SCALE;
2597 
2598    win->fontHeight = win->fontAscent + win->fontDescent;
2599 
2600    win->fontWidth = pango_font_metrics_get_approximate_char_width( win->fontMetrics ) / PANGO_SCALE;
2601 
2602    gtk_widget_show_all( win->appW );
2603 }
2604 
2605 /************************************
2606 * getEdWinFromJedWin
2607 *
2608 * group: win
2609 *
2610 *
2611 * debug print: "Window_Type: %p\n", jWin
2612 *
2613 *
2614 ************************************/
2615 
2616 static GtkWidget *
getEdWinFromJedWin(Window_Type * jWin)2617 getEdWinFromJedWin( Window_Type *jWin )
2618 {
2619    GtkSubWinType *edWin = JGtkWin->subWins;
2620 
2621    do
2622      {
2623 	if ( edWin->jedWin == jWin ) return( edWin->edWin );
2624 	edWin = edWin->next;
2625      }
2626    while ( edWin != JGtkWin->subWins );
2627 
2628    return( NULL );
2629 }
2630 
2631 /************************************
2632 * getGtkSubWinFromRange
2633 *
2634 * group: scroll
2635 *
2636 *
2637 * debug print: "Range: %p\n", r
2638 *
2639 ************************************/
2640 
2641 static GtkSubWinType *
getGtkSubWinFromRange(GtkRange * r)2642 getGtkSubWinFromRange( GtkRange *r )
2643 {
2644    GtkSubWinType *sb = JGtkWin->subWins;
2645 
2646    do
2647      {
2648 	if ( sb->sbWin == ( GtkWidget * ) r ) return( sb );
2649 	sb = sb->next;
2650      }
2651    while ( sb != JGtkWin->subWins );
2652 
2653    return( JGtkWin->subWins );
2654 }
2655 
2656 /* Shamelessly stolen from emacsmsc.sl */
2657 
2658 /************************************
2659 * jGtkScrollUpN
2660 *
2661 * group: scroll
2662 *
2663 *
2664 * debug print:
2665 *
2666 *
2667 ************************************/
2668 
2669 static void
jGtkScrollUpN(int n)2670 jGtkScrollUpN( int n )
2671 {
2672    int i = window_line();
2673    if ( jed_up( n ) ) recenter( &i ) ;
2674    bol();
2675    /* Return( 1 ); */
2676 }
2677 
2678 /************************************
2679 * jGtkScrollDownN
2680 *
2681 * group: scroll
2682 *
2683 *
2684 * debug print:
2685 *
2686 *
2687 ************************************/
2688 
2689 static int
jGtkScrollDownN(int n)2690 jGtkScrollDownN( int n )
2691 {
2692    int i = window_line();
2693    if ( jed_down( n ) ) recenter( &i );
2694    bol();
2695    return 0;
2696 }
2697 
2698 /************************************
2699 * jGtkScrollUp
2700 *
2701 * group: scroll
2702 *
2703 *
2704 * debug print:
2705 *
2706 *
2707 ************************************/
2708 
2709 static void
jGtkScrollUp(void)2710 jGtkScrollUp( void )
2711 {
2712    int i = window_line();
2713    if ( jed_up( 1 ) ) recenter( &i );
2714    bol();
2715    /* Return( 1 ); */
2716 }
2717 
2718 /************************************
2719 * jGtkScrollDown
2720 *
2721 * group: scroll
2722 *
2723 *
2724 * debug print:
2725 *
2726 *
2727 ************************************/
2728 
2729 static int
jGtkScrollDown(void)2730 jGtkScrollDown( void )
2731 {
2732    int i = window_line();
2733    if ( jed_down( 1 ) ) recenter( &i );
2734    bol();
2735    return 0;
2736 }
2737 
2738 /************************************
2739 * jGtkDiffTime
2740 *
2741 * group: scroll
2742 *
2743 *
2744 * debug print:
2745 *
2746 *
2747 ************************************/
2748 
2749 static long
jGtkDiffTime(struct timeval * st)2750 jGtkDiffTime( struct timeval *st )
2751 {
2752    struct timeval ct;
2753    long diff;
2754 
2755    gettimeofday( &ct, NULL );
2756 
2757    /*******
2758    printf( "ct.tv_sec: %ld, ct.tv_usec: %ld, st->tv_sec: %ld, st->tv_usec: %ld\n",
2759 	      ct.tv_sec, ct.tv_usec,
2760 	      st->tv_sec, st->tv_usec );
2761    ***************/
2762 
2763    diff = ( 1000000 * ( ct.tv_sec - st->tv_sec ) + ( long ) ct.tv_usec - ( long ) st->tv_usec ) / 1000;
2764    /* Dbp1( "Diff: %d\n", diff ); */
2765    return( diff );
2766 }
2767 
2768 static void fcSBGotoLine( gpointer );
2769 
2770 /************************************
2771 * jGtkGotoLine
2772 *
2773 * group: scroll
2774 *
2775 *
2776 * debug print:
2777 *
2778 *
2779 ************************************/
2780 
2781 static void
jGtkGotoLine(void)2782 jGtkGotoLine(void)
2783 {
2784    if ( jGtkSIPrim.set  )
2785      { /* The delay ( curr: 30 ) should sometime be configurable from Jed/slang */
2786 
2787 	if ( jGtkDiffTime( &jGtkSIPrim.tv ) > 30 )
2788 	  {
2789 	     gettimeofday( &jGtkSIPrim.tv, NULL );
2790 
2791 	 /* Dbp1( "jGtkSIPrim.tl: %d\n", jGtkSIPrim.tl ); */
2792 
2793 	     if ( LineNum < (unsigned int) jGtkSIPrim.tl )
2794 	       {
2795 		  if ( jGtkSIPrim.sLSBeg > 0 )
2796 		    {
2797 		       jGtkScrollDown();
2798 		       jGtkSIPrim.sLSBeg--;
2799 	       /* Dbp( "jGtkSIPrim.sLS: %d\n", jGtkSIPrim.sLS ); */
2800 		    }
2801 		  else
2802 		    {
2803 		       int jumpLines = jGtkSIPrim.tl - LineNum - jGtkSIPrim.sLSEnd;
2804 		       if ( jumpLines > 0 )
2805 			 {
2806 			    jGtkScrollDownN( jumpLines );
2807 			    jGtkSIPrim.sLSBeg = jGtkSIPrim.sLSEnd;
2808 			 }
2809 		       else
2810 			 {
2811 			    jGtkSIPrim.sLSBeg = jGtkSIPrim.tl - LineNum;
2812 			 }
2813 		    }
2814 	       }
2815 	     else
2816 	       {
2817 		  if ( LineNum > (unsigned int) jGtkSIPrim.tl )
2818 		    {
2819 		       if ( jGtkSIPrim.sLSBeg > 0 )
2820 			 {
2821 			    jGtkScrollUp();
2822 			    jGtkSIPrim.sLSBeg--;
2823 		  /* Dbp( "jGtkSIPrim.sLS: %d\n", jGtkSIPrim.sLS ); */
2824 			 }
2825 		       else
2826 			 {
2827 			    int jumpLines = LineNum - jGtkSIPrim.tl - jGtkSIPrim.sLSEnd;
2828 
2829 			    if ( jumpLines > 0 )
2830 			      {
2831 				 jGtkScrollUpN( jumpLines );
2832 				 jGtkSIPrim.sLSBeg = jGtkSIPrim.sLSEnd;
2833 			      }
2834 			    else
2835 			      {
2836 				 jGtkSIPrim.sLSBeg = LineNum - jGtkSIPrim.tl;
2837 			      }
2838 			 }
2839 		    }
2840 	       }
2841 	  }
2842 
2843 	if ( LineNum == (unsigned int) jGtkSIPrim.tl )
2844 	  {
2845 	     if ( jGtkSISec.set )
2846 	       {
2847 		  jGtkSIPrim = jGtkSISec;
2848 		  gettimeofday( &jGtkSIPrim.tv, NULL );
2849 		  jGtkSISec.set = 0;
2850 	       }
2851 	     else
2852 	       {
2853 		  jGtkSIPrim.set = 0;
2854 	       }
2855 	  }
2856 
2857 	if ( (unsigned int) jGtkSIPrim.tl != LineNum && jGtkSIPrim.set )
2858 	  {
2859 	     jgtk_createKeyEvents( SLang_process_keystring( FC_CMD_KEY_SEQ ) );
2860 	     actParaData = ( gpointer ) NULL;
2861 	     actFunToCall = fcSBGotoLine;
2862 	  }
2863 
2864      }
2865 }
2866 
2867 /************************************
2868 * fcSBGotoLine
2869 *
2870 * group: scroll
2871 *
2872 *
2873 * debug print: "data: %p\n", data
2874 *
2875 *
2876 ************************************/
2877 
2878 static void
fcSBGotoLine(gpointer data)2879 fcSBGotoLine( gpointer data )
2880 {
2881    /* GtkRange *sbRange = ( GtkRange * ) data; */
2882    GtkRange *sbRange = ( GtkRange * ) jGtkSIPrim.rangeW;
2883    int actLine = ( int ) actSBVal;
2884    GtkSubWinType *subWin = getGtkSubWinFromRange( sbRange );
2885    Window_Type *actWin = JWindow;
2886 
2887    if ( subWin->jedWin != JWindow )
2888      {
2889 	do
2890 	  {
2891 	     other_window();
2892 	  }
2893 	while ( JWindow != subWin->jedWin && JWindow != actWin );
2894      }
2895 
2896    /* goto_line( &actLine ); */
2897    jGtkGotoLine();
2898 
2899    if ( JWindow != actWin )
2900      {
2901 	do
2902 	  {
2903 	     other_window();
2904 	  }
2905 	while ( JWindow != actWin );
2906      }
2907 
2908    update( NULL, 1, 0, 0 );
2909 }
2910 
2911 /************************************
2912 * jGtkFillScrollInfoStruct
2913 *
2914 * group: scroll
2915 *
2916 *
2917 * debug print:
2918 *
2919 *
2920 ************************************/
2921 
2922 static void
jGtkFillScrollInfoStruct(JGtkScrollInfo * si,GtkRange * w,gdouble val)2923 jGtkFillScrollInfoStruct( JGtkScrollInfo *si, GtkRange *w, gdouble val )
2924 {
2925    /* struct timezone tz; */
2926    GtkSubWinType *sw = getGtkSubWinFromRange( w );
2927 
2928    si->set = 1;
2929    si->tl = val; /* - sw->jedWin->rows * val / Max_LineNum; */
2930    si->tl = si->tl < 1 ? 1 : ( si->tl > (int)Max_LineNum ? (int)Max_LineNum : si->tl );
2931    /* Dbp1( "si->tl: %d\n", si->tl ); */
2932    si->rangeW = w;
2933    /* The value of 10 should sometime be configurable form Jed/slang */
2934    si->sLSBeg =
2935      si->sLSEnd = sw->jedWin->rows > 10 ? 10 : sw->jedWin->rows;
2936    si->jF = 0;
2937    si->cnt = JGTK_SCROLL_SLOW_DOWN;
2938    gettimeofday( &si->tv, NULL );
2939 }
2940 
2941 /************************************
2942 * jGtkFillScrollInfo
2943 *
2944 * group: scroll
2945 *
2946 *
2947 * debug print:
2948 *
2949 *
2950 ************************************/
2951 
2952 static void
jGtkFillScrollInfo(GtkRange * w,gdouble val)2953 jGtkFillScrollInfo( GtkRange *w, gdouble val )
2954 {
2955    if ( jGtkSIPrim.set )
2956      {
2957 	jGtkSIPrim.jF = 1;
2958 	jGtkFillScrollInfoStruct( &jGtkSISec, w, val );
2959      }
2960    else
2961      {
2962 	jGtkFillScrollInfoStruct( &jGtkSIPrim, w, val );
2963      }
2964 }
2965 
2966 /************************************
2967 * sbChangeValue
2968 *
2969 * group: scroll
2970 *
2971 *
2972 * debug print: "GtkRange: %p, GtkStrollType: %d, val: %f, ud(gpointer): %p\n", w, st, val, ud
2973 *
2974 *
2975 ************************************/
2976 
2977 static gboolean
sbChangeValue(GtkRange * w,GtkScrollType st,gdouble val,gpointer ud)2978 sbChangeValue( GtkRange *w, GtkScrollType st, gdouble val, gpointer ud )
2979 {
2980    /* Dbp1( "Value: %f\n", ( float ) val ); */
2981 
2982    actSBVal = val;
2983 
2984    val = val < 1 ? 1 : ( val > gtk_range_get_adjustment( w )->upper ? gtk_range_get_adjustment( w )->upper + 1 : val + 1 );
2985 
2986    jgtk_createKeyEvents( SLang_process_keystring( FC_CMD_KEY_SEQ ) );
2987    /* Dbp1( "val: %f\n", val ); */
2988    jGtkFillScrollInfo( w, val );
2989    actParaData = ( gpointer ) w;
2990    actFunToCall = fcSBGotoLine;
2991    return( True );
2992 }
2993 
2994 #if 0
2995 static int
2996 checkIfSizeChanged( GdkEventConfigure *ev )
2997 {
2998    JGtkWinType *win = JGtkWin;
2999    GtkSubWinType *sw = win->subWins;
3000 
3001    do
3002      {
3003 	if ( sw->edWin->window == ev->window )
3004 	  {
3005 	 /********
3006 	 if ( ev->x      == sw->edX &&
3007 	      ev->y      == sw->edY &&
3008 	      ev->width  == sw->edWidth &&
3009 	      ev->height == sw->edHeight )
3010 	 *******/
3011 	 /*******/
3012 	     if ( sw->edWin->allocation.x      == sw->edX &&
3013 		  sw->edWin->allocation.y      == sw->edY &&
3014 		  sw->edWin->allocation.width  == sw->edWidth &&
3015 		  sw->edWin->allocation.height == sw->edHeight )
3016 	 /*********/
3017 	       {
3018 		  return( False );
3019 	       }
3020 	     else
3021 	       {
3022 	    /*******/
3023 		  sw->edX    = sw->edWin->allocation.x;
3024 		  sw->edY    = sw->edWin->allocation.y;
3025 		  sw->edWidth  = sw->edWin->allocation.width;
3026 		  sw->edHeight = sw->edWin->allocation.height;
3027 	    /************/
3028 
3029 	    /********
3030 	    sw->edX    = ev->x;
3031 	    sw->edY    = ev->y;
3032 	    sw->edWidth  = ev->width;
3033 	    sw->edHeight = ev->height;
3034             ********/
3035 
3036 		  return( True );
3037 	       }
3038 	  }
3039 	sw = sw->next;
3040      }
3041    while ( sw != win->subWins );
3042 
3043    return( True );
3044 }
3045 #endif
3046 
3047 /************************************
3048 * eventCallback
3049 *
3050 * group: event
3051 *
3052 *
3053 * debug print:
3054 *
3055 *
3056 ************************************/
3057 
3058 static gboolean
eventCallback(GtkWidget * w,GdkEvent * ev,gpointer * data)3059 eventCallback( GtkWidget *w,
3060 	       GdkEvent  *ev,
3061 	       gpointer  *data )
3062 {
3063    static int dragPaned;
3064    static GtkSubWinType *paneWin1, *paneWin2;
3065    Window_Type *jWin;
3066    int tmpInt;
3067    GtkSubWinType *actWin = ( GtkSubWinType * ) data;
3068    JGtkWinType *win = JGtkWin;
3069    int block_expose = 0;
3070    static int doNoEvents;
3071    /* printf( "EventCallback: %s, %d\n", __FILE__, __LINE__ ); */
3072    /* printf( "  Length of queue: %d\n", thisEventBuffer->numGtkEv ); */
3073 
3074    /* printf( "Window: %p\n", win ); */
3075    /* printf( "Windows: %p\n", win->subWins ); */
3076 
3077    if ( doNoEvents ) return( False );
3078 
3079    switch ( ev->type )
3080      {
3081       case GDK_EXPOSE:
3082 	/* printf( "Gdk Expose EventCallback: %s, %d\n", __FILE__, __LINE__ ); */
3083 	/* printf( "    Expose event\n" ); */
3084 	if ( actWin )
3085 	  {
3086 	     if ( block_expose == 0 )
3087 	       {
3088 		  if ( w == actWin->edWin )
3089 		    {
3090 		       jGtkCoverExposedArea( ev->expose.area.x + actWin->jedWin->sx * win->fontWidth,
3091 					     ev->expose.area.y + actWin->jedWin->sy * win->fontHeight,
3092 					     ev->expose.area.width,
3093 					     ev->expose.area.height,
3094 					     ev->expose.count );
3095 		    }
3096 		  else
3097 		    {
3098 		       jGtkCoverExposedArea( ev->expose.area.x + actWin->jedWin->sx * win->fontWidth,
3099 					     ev->expose.area.y + ( actWin->jedWin->sy +
3100 								   actWin->jedWin->rows ) * win->fontHeight,
3101 					     ev->expose.area.width,
3102 					     ev->expose.area.height,
3103 					     ev->expose.count );
3104 		    }
3105 	       }
3106 	     else
3107 	       {
3108 		  if ( ev->expose.count == 0 )
3109 		    {
3110 		       jed_redraw_screen( 1 );
3111 		       block_expose = 0;
3112 		    }
3113 	       }
3114 	  }
3115 	break;
3116       case GDK_FOCUS_CHANGE:
3117 	/* printf( "Focus change: %s, %d\n", __FILE__, __LINE__ ); */
3118 	toggle_cursor( ev->focus_change.in );
3119 	break;
3120       case GDK_CONFIGURE:
3121         /* if ( !updateGtkWin ) Return; */
3122 	/*****************/
3123         /* printf( "Gdk Configure: %s, %d: data: %p, widget: %p\n", __FILE__, __LINE__, data, w ); */
3124         /* printf( "File: %s, Line: %d: Width: %d, Height: %d\n", __FILE__, __LINE__, JGtkWin->width, JGtkWin->height ); */
3125 
3126         /* printSubWins(); */
3127 	/*************
3128 	printf( "vvvvvv~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~vvvvvv\n" );
3129 	printSubWinSizes();
3130 	printf( "^^^^^^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^\n" );
3131         ************/
3132         /* printf( "File: %s, Line: %d: Width: %d, Height: %d\n", __FILE__, __LINE__, JGtkWin->width, JGtkWin->height ); */
3133 
3134         /* Dbp3( "Configure-Event: Widget: %p, Event: %p, data: %p\n", w, ev, data ); */
3135 
3136         if (
3137 	    /**********
3138 	    ( win->appWInGrid->allocation.height != win->inGridHeightPixel ||
3139 	       win->appWInGrid->allocation.width  != win->inGridWidthPixel ) &&
3140 	     *********/
3141 	    win->subWins && actWin )
3142 	  {
3143 	     int sy, sx, i;
3144 	     int hCheck;
3145 	     int newWidth, newHeight;
3146 	     GtkSubWinType *sw;
3147 
3148 	   /* if ( !checkIfSizeChanged( ( GdkEventConfigure * ) ev ) ) break; */
3149 
3150 	   /*******/
3151 	   /* Dbp2( "w: %p, actWin: %p\n", w, actWin ); */
3152 
3153 	   /******
3154 	   printf( "1: vvvvvv---------------------------------------vvvvvv\n" );
3155 	   printWidgetWinXRef();
3156 	   printSubWins();
3157 	   printf( "1: ^^^^^^---------------------------------------^^^^^^\n" );
3158 	   **********/
3159 	   /**********/
3160 
3161 	     if ( !dragPaned )
3162 	       {
3163 		  sw = win->subWins;
3164 
3165 		  hCheck =
3166 		    sy = win->subWins->jedWin->sy;
3167 		  sx = 0;
3168 
3169 	      /* printSubWins(); */
3170 
3171 		  do
3172 		    {
3173 		       newHeight = sw->edWin->allocation.height / win->fontHeight + 1;
3174 		       hCheck += newHeight;
3175 		       if ( newHeight < 3 ) newHeight = 3;
3176 		 /* Dbp4( "sy: %d, newHeight: %d, sw->edWin->allocation.height: %d, win->fontHeight: %d\n", sy, newHeight, sw->edWin->allocation.height, win->fontHeight ); */
3177 		 /* newWidth = sw->edWin->allocation.width / win->fontWidth + 1; */
3178 		       newWidth = win->appWInGrid->allocation.width / win->fontWidth;
3179 		       if ( !newWidth ) newWidth = 1;
3180 		 /* Db; */ updateWidgetWinXRef( sw, sy, sx, newHeight, newWidth );
3181 		 /* touch_window( sw->jedWin ); */
3182 		       sy = sy + sw->jedWin->rows + 1;
3183 		 /* printf( "SW: %p, height: %d, sum height: %d, hCheck: %d\n", sw, newHeight, sy, hCheck ); */
3184 		       sw = sw->next;
3185 		 /* Dbp( "  --> sy: %d\n", sy ); */
3186 		    }
3187 		  while ( sw != win->subWins );
3188 
3189 	      /*************************
3190 	       * Update Minibuffer!!!
3191 	       *************************/
3192 
3193 	      /* newWidth = win->miniWinSW->edWin->allocation.width / win->fontWidth + 1; */
3194 
3195 	      /********/
3196 	      /* Dbp( "Miniwin: sy: %d\n", sy ); */
3197 	      /* Dbp( "MiniWin: win->miniWinSW: %p\n", win->miniWinSW ); */
3198 	      /* printGtkSubWin( win->miniWinSW ); */
3199 	      /************/
3200 		  if ( win->miniWinSW )
3201 		    {
3202 		       modWidgetWinXRef( win->widgetWinXRef, win->miniWinSW, 0, sy, newWidth, 1 );
3203 		 /***************
3204 		  for ( i = 0; i < newWidth; ++i )
3205 		    {
3206 		     win->widgetWinXRef[sy][win->miniWinSW->jedWin->sx + i] = win->miniWinSW;
3207 		     }
3208 		  **************/
3209 		       sy++;
3210 		       hCheck++;
3211 		    }
3212 
3213 	   /**********
3214 	   printf( "1.5: ---------------------------------------\n" );
3215 	   printWidgetWinXRefXY( win->miniWinSW->jedWin->sx + newWidth, sy );
3216 	   printSubWins();
3217 	   printf( "1.5: ---------------------------------------\n" );
3218 	   ***************/
3219 
3220 		  win->hCheck = hCheck;
3221 		  win->inGridHeight = sy;
3222 	   /* Dbp( "WinGridHeight: %d\n", win->inGridHeight ); */
3223 
3224 	   /* Db; */
3225 	   /* printf( "win->hCheck: %d, win->inGridHeight: %d\n", win->hCheck, win->inGridHeight ); */
3226 
3227 	   /* Dbp2( "win->edWidth: %d, win->edHeight: %d\n", win->edWidth, win->edHeight ); */
3228 	   /* Dbp2( "newWidth:     %d, sy:            %d\n", newWidth, sy ); */
3229 
3230 		  win->edWidth = newWidth;
3231 		  win->edHeight = sy;
3232 
3233 	      /* Dbp4( "win->hCheck: %d, win->inGridHeight: %d, win->edWidth: %d, win->edHeight: %d\n", win->hCheck, win->inGridHeight, win->edWidth, win->edHeight ); */
3234 
3235 	   /***********/
3236 		  JGtkWin->width = win->appWInGrid->allocation.width;
3237 		  JGtkWin->height = sy * win->fontHeight;
3238            /************/
3239 
3240 		  win->edWidth = newWidth;
3241 		  win->edHeight = sy;
3242 
3243 		  win->inGridHeightPixel = win->appWInGrid->allocation.height;
3244 		  win->inGridWidthPixel = win->appWInGrid->allocation.width;
3245 
3246 #if 0
3247 		  printf( "1.5: ---------------------------------------\n" );
3248 	   /* printWidgetWinXRefXY( win->miniWinSW->jedWin->sx + newWidth, sy - 1 ); */
3249 		  printWidgetWinXRef();
3250 		  printSubWins();
3251 		  printf( "1.5: ---------------------------------------\n" );
3252 #endif
3253 
3254 	   /**************/
3255 		  doColorSetup = 0;
3256 		  doCLS = 0;
3257 		  jed_init_display();
3258 		  jed_redraw_screen( 1 );
3259 		  doCLS = 1;
3260 		  doColorSetup = 1;
3261 	   /************/
3262            /*********
3263 	   printf( "2: vvvvvv---------------------------------------vvvvvv\n" );
3264 	   printWidgetWinXRef();
3265 	   printSubWins();
3266 	   printf( "2: ^^^^^^---------------------------------------^^^^^^\n" );
3267 	   ********/
3268 	       }
3269 	     else
3270 	       {
3271 		  if ( w == paneWin1->edWin ||
3272 		       w == paneWin2->edWin )
3273 		    {
3274 		       GtkSubWinType *subW;
3275 		       int resizeEdFlag = 0;
3276 		       int _sy, _newHeight, newHeightP1, newHeightP2, _newWidth;
3277 		       int sumHeight = paneWin1->jedWin->rows + 1 +
3278 			 paneWin2->jedWin->rows + 1;
3279 
3280 		       _newHeight = paneWin1->edWin->allocation.height / win->fontHeight + 1;
3281 		       if ( _newHeight < 3 || paneWin1->jedWin->rows <= 3 )
3282 			 {
3283 			    if ( _newHeight < 3 ) _newHeight = 3;
3284 			    resizeEdFlag = 1;
3285 			 }
3286 
3287 		       _newWidth = paneWin1->edWin->allocation.width / win->fontWidth;
3288 		       updateWidgetWinXRef( paneWin1, paneWin1->jedWin->sy, 0, _newHeight, _newWidth );
3289 
3290 		       newHeightP1 = _newHeight;
3291 
3292 		       _sy = paneWin1->jedWin->sy + paneWin1->jedWin->rows + 1;
3293 
3294 		 /***************
3295 		 if ( resizeEdFlag )
3296 		   {
3297 		    _newHeight = paneWin2->edWin->allocation.height / win->fontHeight + 1;
3298 		    }
3299 		 else
3300 		   _newHeight = sumHeight - _newHeight;
3301                  ***************/
3302 
3303 		       newHeightP2 =  paneWin2->edWin->allocation.height / win->fontHeight + 1;
3304 
3305 		 /* Dbp2( "Allocation.height: %d, newHeightP2: %d\n", paneWin2->edWin->allocation.height, newHeightP2 ); */
3306 
3307 		       if ( newHeightP2 != sumHeight - _newHeight )
3308 			 {
3309 			    resizeEdFlag = 1;
3310 			 }
3311 
3312 		       _newHeight = newHeightP2;
3313 
3314 		 /*********
3315                  if ( newHeightP2 > sumHeight - _newHeight )
3316 		   {
3317 		    _newHeight = newHeightP2;
3318 		    resizeEdFlag = 1;
3319 		    }
3320 		 else
3321 		   {
3322 		    _newHeight = sumHeight - _newHeight;
3323 		    }
3324 		 **********/
3325 
3326 		    /****************
3327 		    if ( newHeightP2 < 3 )
3328 		      {
3329 		       _newHeight = 3;
3330 		       resizeEdFlag = 1;
3331 		       }
3332 		    else
3333 		      {
3334 		       _newHeight = newHeightP2;
3335 		       }
3336 		    ****************/
3337 
3338 		       if ( _newHeight < 3 || paneWin2->jedWin->rows <= 3 )
3339 			 {
3340 			    if ( _newHeight < 3 ) _newHeight = 3;
3341 			    resizeEdFlag = 1;
3342 			 }
3343 
3344 		       updateWidgetWinXRef( paneWin2, _sy, 0, _newHeight, _newWidth );
3345 
3346 		       newHeightP2 = _newHeight;
3347 
3348 		 /* Dbp5( "ResizeEdFlag: %d, SumHeight old: %d, SumHeight new: %d, newHeightP1: %d, newHeightP2: %d\n", resizeEdFlag, sumHeight, newHeightP1 + newHeightP2, newHeightP1, newHeightP2 ); */
3349 
3350 		       if ( newHeightP1 + newHeightP2 == sumHeight )
3351 			 resizeEdFlag = 0;
3352 
3353 		       if ( resizeEdFlag )
3354 			 {
3355 		    /*******
3356 		    subW = JGtkWin->subWins;
3357 		    _sy = subW->jedWin->sy;
3358 		    **********/
3359 
3360 			    subW = paneWin2->next;
3361 			    _sy = paneWin2->jedWin->sy + paneWin2->jedWin->rows + 1;
3362 
3363 			    if ( subW != JGtkWin->subWins )
3364 			      do
3365 			      {
3366 				 _newHeight = subW->edWin->allocation.height / win->fontHeight + 1;
3367 				 if ( _newHeight < 3 ) _newHeight = 3;
3368 				 _newWidth = win->appWInGrid->allocation.width / win->fontWidth;
3369 				 if ( !_newWidth ) _newWidth = 1;
3370 				 updateWidgetWinXRef( subW, _sy, 0, _newHeight, _newWidth );
3371 				 _sy = _sy + _newHeight;
3372 				 subW = subW->next;
3373 			      }
3374 			    while ( subW != JGtkWin->subWins );
3375 
3376 			    if ( win->miniWinSW )
3377 			      {
3378 				 modWidgetWinXRef( win->widgetWinXRef, win->miniWinSW, 0, _sy, _newWidth, 1 );
3379 				 _sy++;
3380 			      }
3381 
3382 			    win->inGridHeight = _sy;
3383 			    win->edHeight = _sy;
3384 
3385 			    JGtkWin->height = _sy * win->fontHeight;
3386 
3387 			    win->edHeight = _sy;
3388 
3389 			    win->inGridHeightPixel = win->appWInGrid->allocation.height;
3390 
3391  		    /* Dbp1( "===========================================================================================%d\n", 1 ); */
3392  		    /* Dbp1( "===========================================================================================%d\n", 1 ); */
3393  		    /* Dbp1( "===========================================================================================%d\n", 1 ); */
3394 
3395 			    doNoEvents = 1;
3396 			    doColorSetup = 0;
3397 			    doCLS = 0;
3398 			    jed_init_display();
3399 			    update( NULL, 1, 0, 0 );
3400 		    /* jed_redraw_screen( 1 ); */
3401 			    doCLS = 1;
3402 			    doColorSetup = 1;
3403 			    doNoEvents = 0;
3404  		    /* Dbp1( "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^%d\n", 1 ); */
3405  		    /* Dbp1( "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^%d\n", 1 ); */
3406  		    /* Dbp1( "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^%d\n", 1 ); */
3407 			 }
3408 		       else
3409 			 {
3410 		    /**********
3411 		    jWin = JWindow;
3412 		    do
3413 		      {
3414 		       touch_window_hard( JWindow, 0 );
3415 		       JWindow = JWindow->next;
3416 		       }
3417 		    while ( jWin != JWindow );
3418 		    **************/
3419 			    touch_window_hard( paneWin1->jedWin, 1 );
3420 			    touch_window_hard( paneWin2->jedWin, 1 );
3421 		    /* touch_screen(); */
3422 		    /* jed_redraw_screen( 1 ); */
3423 			    update( NULL, 1, 0, 0 );
3424 			 }
3425 		    }
3426 	       }
3427 	  }
3428 
3429       /***********
3430       printf( "99: vvvvvv~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~vvvvvv\n" );
3431       printWidgetWinXRef();
3432       printSubWins();
3433       printf( "99: ^^^^^^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^\n" );
3434       ********/
3435 	if ( JGtkWin->appWMiniW )
3436 	  gtk_widget_grab_focus( JGtkWin->appWMiniW );
3437 	break;
3438       case GDK_KEY_PRESS:
3439         /* printf( "File: %s Line: %d GDK_KEY_PRESS event!!!\n", __FILE__, __LINE__ ); */
3440 	/* printf( "KeyCode: \n" ); */
3441         addGdkEvent( ev, w, data );
3442 	break;
3443       case GDK_BUTTON_PRESS:
3444 	/* printf( "File: %s Line: %d Button press\n", __FILE__, __LINE__ ); */
3445 	if ( GTK_IS_PANED( w ) )
3446 	  {
3447 	     GtkWidget *ch1 = gtk_paned_get_child1( GTK_PANED( w ) );
3448 	     GList *childList;
3449 	     GtkWidget *stWidget;
3450 	     GtkSubWinType *sw = JGtkWin->subWins;
3451 	   /* GtkWidget *ch2; */
3452 
3453 	   /* Dbp1( "Paned: %p Button press!!\n", w ); */
3454 
3455 	     if ( GTK_IS_PANED( ch1 ) )
3456 	       {
3457 		  ch1 = gtk_paned_get_child2( GTK_PANED( ch1 ) );
3458 	       }
3459 
3460 	     if ( GTK_IS_BOX( ch1 ) )
3461 	       {
3462 		  childList = gtk_container_get_children( GTK_CONTAINER( ch1 ) );
3463 		  stWidget = ( GtkWidget * ) childList->next->data;
3464 		  g_list_free( childList );
3465 
3466 		  while ( sw->stWin != stWidget &&
3467 			  sw->next != JGtkWin->subWins )
3468 		    {
3469 		       sw = sw->next;
3470 		    }
3471 
3472 		  if ( sw->stWin == stWidget )
3473 		    {
3474 		       paneWin1 = sw;
3475 		       paneWin2 = paneWin1->next;
3476 		       dragPaned = 1;
3477 		 /* Dbp2( "Found paneWin1: %p, paneWin2: %p\n", paneWin1, paneWin2 ); */
3478 		       return( False );
3479 		    }
3480 	       }
3481 
3482 	   /* Dbp1( "Widget structure does not match: %p\n", ch1 ); */
3483 
3484 	     paneWin1 = paneWin2 = NULL;
3485 	     dragPaned = 0;
3486 	     return( False );
3487 	  }
3488         else
3489 	  addGdkEvent( ev, w, data );
3490 	break;
3491       case GDK_BUTTON_RELEASE:
3492 	/* printf( "File: %s Line: %d Button release\n", __FILE__, __LINE__ ); */
3493 	if ( GTK_IS_PANED( w ) )
3494 	  {
3495 	   /* Dbp1( "Paned: %p Button release!!\n", w ); */
3496 	     dragPaned = 0;
3497 	     paneWin1 = paneWin2 = NULL;
3498 	     return( False );
3499 	  }
3500         else
3501           addGdkEvent( ev, w, data );
3502 	break;
3503       case GDK_MOTION_NOTIFY:
3504         /* printf( "File: %s Line: %d Motion event\n", __FILE__, __LINE__ ); */
3505         /* printf( "File: %s Line: %d x: %f, y: %f\n", __FILE__, __LINE__, ev->motion.x, ev->motion.y ); */
3506         addGdkEvent( ev, w, data );
3507 	break;
3508       default:
3509         /* thisEventBuffer->gtkEvList = g_list_append( thisEventBuffer->gtkEvList, gdk_event_copy( ev ) ); */
3510         /* ( thisEventBuffer->numGtkEv )++; */
3511         /* printf( "  Length of queue: %d\n", thisEventBuffer->numGtkEv ); */
3512 	break;
3513      }
3514 
3515    return( True );
3516 }
3517 
3518 #if SLANG_VERSION >= 20000
3519 
3520 /************************************
3521 * bytes_to_wchars
3522 *
3523 * group:
3524 *
3525 *
3526 * debug print:
3527 *
3528 *
3529 ************************************/
3530 
3531 static SLwchar_Type *
bytes_to_wchars(unsigned char * s,unsigned int nchars)3532 bytes_to_wchars (unsigned char *s, unsigned int nchars )
3533 {
3534    unsigned int i;
3535 
3536    SLwchar_Type *w = (SLwchar_Type *)SLmalloc(nchars*sizeof(SLwchar_Type));
3537    if (w == NULL)
3538      return NULL;
3539 
3540    for (i = 0; i < nchars; i++)
3541      w[i] = s[i];
3542 
3543    return w;
3544 }
3545 
3546 /************************************
3547 * utf8nt_to_wchars
3548 *
3549 * group:
3550 *
3551 *
3552 * debug print:
3553 *
3554 *
3555 ************************************/
3556 
3557 static SLwchar_Type *
utf8nt_to_wchars(unsigned char * s,unsigned int len,unsigned int * ncharsp)3558 utf8nt_to_wchars(unsigned char *s, unsigned int len, unsigned int *ncharsp)
3559 {
3560    SLwchar_Type *w;
3561    unsigned int i, nchars;
3562    unsigned char *smax;
3563 
3564    nchars = SLutf8_strlen(s, 0);
3565    if (NULL == (w = (SLwchar_Type *)SLmalloc(nchars*sizeof(SLwchar_Type))))
3566      {
3567 	*ncharsp = 0;
3568 	return NULL;
3569      }
3570 
3571    smax = s + len;
3572    for (i = 0; i < nchars; i++)
3573      {
3574 	unsigned int n;
3575 	if ( SLutf8_decode(s, smax, &w[i], &n ) == NULL )
3576 	  w[i] = '?';
3577 	s += n;
3578      }
3579 
3580    *ncharsp = nchars;
3581    return w;
3582 }
3583 
3584 # define SLSMGCHAR_EQUAL(o, n) \
3585    (((o)->nchars == (n)->nchars) \
3586        && ((o)->color == (n)->color) \
3587        && (0 == memcmp((o)->wchars, (n)->wchars, (n)->nchars * sizeof(SLwchar_Type))))
3588 
3589 # define SLSMGCHAR_SET_CHAR(sc, _char) \
3590    do { (sc).nchars = 1; (sc).wchars[0] = (_char); } while (0)
3591 # define SLSMGCHAR_SET_COLOR(sc, _color) \
3592    (sc).color = (_color)
3593 # define SLSMG_COUNT_CHARS(sc) ((sc).nchars)
3594 
3595 #else
3596 /* SLang1 versions */
3597 # define SLSMGCHAR_EQUAL(o, n) ((o) == (n))
3598 
3599 # ifdef SLSMG_HLINE_CHAR_UNICODE
3600 /* Grrr.... hack for the slang1-utf8 version hacked by RedHat and SuSE... */
3601 #  define SLSMGCHAR_SET_CHAR(sc, _char) (sc) = ((sc) & 0xFF000000) + (_char)
3602 #  define SLSMGCHAR_SET_COLOR(sc, _color) (sc) = ((sc) & 0xFF) + ((_color)<<24)
3603 # else
3604 #  define SLSMGCHAR_SET_CHAR(sc, _char) (sc) = ((sc) & 0xFF00) + (_char)
3605 #  define SLSMGCHAR_SET_COLOR(sc, _color) (sc) = ((sc) & 0xFF) + ((_color)<<8)
3606 # endif
3607 # define SLSMG_COUNT_CHARS(sc) (1)
3608 /* These exist in SLang 2 include, but not on SLang 1. Define here to allow
3609  * using the same code
3610  */
3611 # define SLSMG_COLOR_MASK 0xFF
3612 # define SLwchar_Type char
3613 
3614 #endif				       /* SLANG_VERSION >= 20000 */
3615 
3616 /************************************
3617 * gtkXDrawString
3618 *
3619 * group:
3620 *
3621 *
3622 * debug print: "drawW: %p, gcNum: %d, text: %p, x: %d, y: %d\n", drawW, gcNum, text, x, y
3623 *
3624 ************************************/
3625 
3626 static void
jGtkDrawString(GtkWidget * drawW,int gcNum,char * text,int x,int y)3627 jGtkDrawString( GtkWidget *drawW, int gcNum, char *text, int x, int y )
3628 {
3629    JGtkWinType *win = JGtkWin;
3630    GdkColor *fg = DefaultGtkGCInfo[gcNum].fg;
3631    GdkColor *bg = DefaultGtkGCInfo[gcNum].bg;
3632    PangoRenderer *renderer;
3633    PangoLayout   *layout;
3634 
3635    if ( !drawW->window )
3636      {
3637       /* Dbp1( "Widget (%p) Window: NULL, should not occur!!!\n", drawW ); */
3638 	return;
3639      }
3640 
3641    renderer = gdk_pango_renderer_get_default( win->screen );
3642    gdk_pango_renderer_set_drawable( GDK_PANGO_RENDERER( renderer ), drawW->window );
3643    gdk_pango_renderer_set_gc( GDK_PANGO_RENDERER( renderer ), drawW->style->black_gc );
3644    layout = pango_layout_new( win->fontContext );
3645 
3646    pango_layout_set_text( layout, text, -1 );
3647    pango_layout_set_font_description( layout, win->fontDescription );
3648    gdk_pango_renderer_set_override_color( GDK_PANGO_RENDERER( renderer ),
3649 					  PANGO_RENDER_PART_FOREGROUND, fg );
3650    gdk_pango_renderer_set_override_color( GDK_PANGO_RENDERER( renderer ),
3651 					  PANGO_RENDER_PART_BACKGROUND, bg );
3652    pango_layout_context_changed( layout );
3653    pango_renderer_draw_layout( renderer, layout, x * PANGO_SCALE, y * PANGO_SCALE );
3654 
3655    /* free the objects we created */
3656    g_object_unref ( layout );
3657 }
3658 
3659 /* This function does the low-level drawing.
3660  * It can draw the new text, but setting 'overimpose' to 1 it draws the string
3661  * over the existing text (used for unicode combining characters).
3662  * It can use Xft (if configured), or plain X functions.
3663  */
3664 
3665 /************************************
3666 * gtkXDraw
3667 *
3668 * group:
3669 *
3670 *
3671 * debug print: "gcNum: %d, row: %d, col: %d, w: %p, nChars: %d, overimpose: %d\n", gcNum, row, col, w, nchars, overimpose
3672 *
3673 ************************************/
3674 
3675 static int
jGtkDraw(int gcNum,int row,int col,SLwchar_Type * w,int nchars,int overimpose)3676 jGtkDraw( int gcNum, int row, int col, SLwchar_Type *w, int nchars, int overimpose )
3677 {
3678    char *tmpText = "A";
3679    char *text, *buf, *sav;
3680    int bufLen = 8*nchars + 1;
3681    int i;
3682    JGtkWinType *win = JGtkWin;
3683    int x = col * win->fontWidth;
3684    int y = row * win->fontHeight;
3685 
3686    if ( row == 0 ) return( 1 );
3687 
3688    if ( !updateGtkWin ) return( 1 );
3689 
3690    buf =
3691      sav =
3692      text = SLmalloc( bufLen + 1 );
3693 
3694    for ( i = 0; i < nchars; ++i )
3695      {
3696 	if ( sav && bufLen > 0 )
3697 	  {
3698 	     buf = sav;
3699 	     sav = ( char * ) SLutf8_encode( w[i], ( unsigned char * ) buf, bufLen );
3700 	     bufLen -= sav - buf;
3701 	  }
3702      }
3703 
3704    if ( !sav ) return( 0 );
3705 
3706    *sav = '\0';
3707 
3708    if ( row > 0 && col >= 0 && row < Jed_Num_Screen_Rows && col < Jed_Num_Screen_Cols )
3709      {  /* row > 0 needed because routines for ascii-menu not implemented!!!! */
3710 
3711       /* printf( "win->widgetWinXRef[%d][%d]\n", row, col ); */
3712       /* printf( "win->widgetWinXRef[%d][%d]: %p\n", row, col, win->widgetWinXRef[row][col] ); */
3713 
3714 	if ( win->widgetWinXRef[row][col] )
3715 	  {
3716 	     Window_Type *jedWin = win->widgetWinXRef[row][col]->jedWin;
3717 
3718 	     if ( row == jedWin->sy + jedWin->rows )
3719 	       {
3720             /* printf( "win->widgetWinXRef[%d][%d]: StWin: %p\n", row, col, win->widgetWinXRef[row][col]->stWin ); */
3721 		  jGtkDrawString( win->widgetWinXRef[row][col]->stWin, gcNum, text, x, 0 );
3722 	       }
3723 	     else
3724 	       {
3725             /* printf( "win->widgetWinXRef[%d][%d]: EdWin: %p\n", row, col, win->widgetWinXRef[row][col]->edWin ); */
3726 		  jGtkDrawString( win->widgetWinXRef[row][col]->edWin, gcNum, text, x, y - jedWin->sy*win->fontHeight );
3727 	       }
3728 	  }
3729      }
3730    SLfree( text );
3731    return 1;
3732    /* printf( "End drawing\n" ); */
3733 }
3734 
3735 /* Get 'n' characters from SLSMG screen, at position ('row', 'col'). */
3736 /************************************
3737 * smg_read_at
3738 *
3739 * group:
3740 *
3741 *
3742 * debug print:
3743 *
3744 *
3745 ************************************/
3746 
3747 static unsigned int
smg_read_at(int row,int col,SLsmg_Char_Type * s,unsigned int n)3748 smg_read_at( int row, int col, SLsmg_Char_Type *s, unsigned int n)
3749 {
3750    int saverow, savecol;
3751    unsigned int rc;
3752 
3753    saverow = SLsmg_get_row ();
3754    savecol = SLsmg_get_column ();
3755    SLsmg_gotorc(row, col);
3756    rc = SLsmg_read_raw (s, n);
3757    SLsmg_gotorc (saverow, savecol);
3758    return rc;
3759 }
3760 
3761 /* Write to screen a single SLsmg_Char, handling combining characters
3762  * (X doesn't seem to handle these...) to position (row, col).
3763  * This function doesn't touch the cursor position.
3764  */
3765 /************************************
3766 * JX_write_smgchar
3767 *
3768 * group:
3769 *
3770 *
3771 * debug print:
3772 *
3773 *
3774 ************************************/
3775 
3776 static void
JX_write_smgchar(int row,int col,SLsmg_Char_Type * s)3777 JX_write_smgchar( int row, int col, SLsmg_Char_Type *s )
3778 {
3779    int color = SLSMG_EXTRACT_COLOR(*s) & SLSMG_COLOR_MASK;
3780 
3781    if ((color >= JMAX_COLORS) || (color < 0))
3782      color = 0;
3783 
3784 #if SLANG_VERSION >= 20000
3785    if (s->nchars > 0)
3786      {
3787 	(void) jGtkDraw( color, row, col, s->wchars, 1, 0 );
3788      }
3789 
3790    if (Jed_UTF8_Mode)
3791      {
3792 	unsigned int i;
3793 
3794 	for (i = 1; i < s->nchars; i++)
3795 	  (void) jGtkDraw( color, row, col, &s->wchars[i], 1, 1 );
3796      }
3797 #else
3798      {
3799 	SLwchar_Type ch = SLSMG_EXTRACT_CHAR(*s);
3800 	(void) jGtkDraw( color, row, col, &ch, 1, 0 );
3801      }
3802 #endif
3803 
3804 }
3805 
3806 /* Write to screen a row of SLsmg_Chars, handling combining characters
3807  * (X doesn't seem to handle these...) to position (row, col).
3808  * This function doesn't touch the cursor position.
3809  */
3810 
3811 /************************************
3812 * JX_write_smgchars
3813 *
3814 * group:
3815 *
3816 *
3817 * debug print:
3818 *
3819 *
3820 ************************************/
3821 
3822 static void
JX_write_smgchars(int row,int col,SLsmg_Char_Type * s,SLsmg_Char_Type * smax)3823 JX_write_smgchars( int row, int col, SLsmg_Char_Type *s, SLsmg_Char_Type *smax )
3824 {
3825    SLwchar_Type *b, *bend, buf[512];
3826    int oldcolor, color;
3827    SLsmg_Char_Type *s0;
3828    int is_dual_font;
3829 
3830    b = buf;
3831    bend = buf + 510;
3832 
3833    oldcolor = (SLSMG_EXTRACT_COLOR(*s) & SLSMG_COLOR_MASK);
3834    if ((oldcolor < 0) || (oldcolor >= JMAX_COLORS))
3835      oldcolor = 0;
3836 
3837    is_dual_font = 0;
3838 
3839    s0 = s;
3840    while (s < smax)
3841      {
3842 	color = (SLSMG_EXTRACT_COLOR(*s) & SLSMG_COLOR_MASK);
3843 	if ((color < 0) || (color >= JMAX_COLORS))
3844 	  color = 0;
3845 
3846 	if ( oldcolor != color		   /* Color changed. */
3847 	     || (b >= bend)		   /* Space finished */
3848 	     || SLSMG_COUNT_CHARS(*s) > 1)  /* a combining character */
3849 	  {
3850 	     (void) jGtkDraw( oldcolor, row, col, buf, b-buf, 0 );
3851 	     col += (int)(s-s0);
3852 	     s0 = s;
3853 	     b = buf;
3854 	     oldcolor = color;
3855 	  }
3856 #if SLANG_VERSION >= 20000
3857 	if ( s->nchars > 1 )
3858 	  {
3859 	 /* this cell has combining characters */
3860 	     JX_write_smgchar(row, col, s);
3861 	     col++;
3862 	     s0 = s + 1;
3863 	  }
3864 	else if ( s->nchars == 0 )
3865 	  {
3866 	 /* SLsmg thinks this is a double width character, but the font has no such characters */
3867 	     if ( is_dual_font == 0 )
3868 	       *b++ = ' ';
3869 	  }
3870 	else
3871 #endif
3872 	  *b++ = SLSMG_EXTRACT_CHAR(*s);
3873 	s++;
3874      }
3875    if ( b != buf )
3876      (void) jGtkDraw( color, row, col, buf, b-buf, 0 );
3877 }
3878 
3879 /************************************
3880 * hide_cursor
3881 *
3882 * group:
3883 *
3884 *
3885 * debug print:
3886 *
3887 *
3888 ************************************/
3889 
3890 static void
hide_cursor(void)3891 hide_cursor( void )
3892 {
3893    SLsmg_Char_Type sc;
3894 
3895    if ( No_XEvents ||
3896         ( JGtkWin->cursor_showing == 0 ) )
3897      return;
3898 
3899    JGtkWin->cursor_showing = 0;
3900    if ( 0 == smg_read_at( JGtkWin->vis_curs_row,
3901 			  JGtkWin->vis_curs_col, &sc, 1 ) )
3902      {
3903 	SLSMGCHAR_SET_CHAR(sc, ' ');
3904 	SLSMGCHAR_SET_COLOR(sc, JNORMAL_COLOR);
3905 	sc.nchars = 1;
3906      }
3907 
3908    JX_write_smgchar( JGtkWin->vis_curs_row, JGtkWin->vis_curs_col, &sc);
3909 }
3910 /*}}}*/
3911 
3912 /************************************
3913 * updateScrollbar
3914 *
3915 * group:
3916 *
3917 *
3918 * debug print:
3919 *
3920 *
3921 ************************************/
3922 
3923 void
updateScrollbar(Window_Type * jw)3924 updateScrollbar( Window_Type *jw )
3925 {
3926    int subWinNotFound = 1;
3927    GtkSubWinType *subWin = JGtkWin->subWins;
3928 
3929    /* printSubWins(); */
3930 
3931    do
3932      {
3933 	if ( subWin->jedWin == jw )
3934 	  {
3935 	     subWinNotFound = 0;
3936 	  }
3937 	else
3938 	  {
3939 	     subWin = subWin->next;
3940 	  }
3941      }
3942    while ( subWinNotFound && subWin != JGtkWin->subWins );
3943 
3944    if ( subWinNotFound ) return;
3945 
3946    if ( subWin->numLineSav != subWin->jedWin->buffer->max_linenum  ||
3947 	subWin->curLineSav != subWin->jedWin->buffer->linenum  ||
3948 	subWin->winHeightSav != subWin->jedWin->rows )
3949      {
3950 	subWin->sbAdj->upper = subWin->jedWin->buffer->max_linenum - 1 > 0 ? subWin->jedWin->buffer->max_linenum - 1 : 0;
3951 	subWin->sbAdj->value = subWin->jedWin->buffer->linenum - 1 > 0 ? subWin->jedWin->buffer->linenum - 1 : 0;
3952 	subWin->sbAdj->page_size = subWin->jedWin->rows;
3953 
3954 	subWin->numLineSav = subWin->jedWin->buffer->max_linenum;
3955 	subWin->curLineSav = subWin->jedWin->buffer->linenum;
3956 	subWin->winHeightSav = subWin->jedWin->rows;
3957 
3958       /* Dbp1( "Adjustment:   -->  %p\n", subWin->sbAdj ); */
3959 	g_signal_emit_by_name( G_OBJECT( subWin->sbAdj ), "changed" );
3960      }
3961 }
3962 
3963 /************************************
3964 * gtkCopyRect
3965 *
3966 * group:
3967 *
3968 *
3969 * debug print: "x1: %d, y1: %d, x2: %d, y2: %d, x3: %d, y3: %d\n", x1, y1, x2, y2, x3, y3
3970 *
3971 ************************************/
3972 
3973 static void
gtkCopyRect(int x1,int y1,int x2,int y2,int x3,int y3)3974 gtkCopyRect( int x1, int y1, int x2, int y2, int x3, int y3 )
3975 {
3976    int w, h;
3977    Window_Type *jedWin1 = JGtkWin->widgetWinXRef[y1][x1]->jedWin;
3978    Window_Type *jedWin3 = JGtkWin->widgetWinXRef[y3][x3]->jedWin;
3979    GtkWidget *win1 = JGtkWin->widgetWinXRef[y1][x1]->edWin;
3980    GtkWidget *win3 = JGtkWin->widgetWinXRef[y3][x3]->edWin;
3981 
3982    if ( win1 != win3 ) return;
3983 
3984    w = (x2 - x1) * JGtkWin->fontWidth;
3985    h = (y2 - y1) * JGtkWin->fontHeight;
3986 
3987    if ((w <= 0) || (h <= 0)) return;
3988 
3989    x3 = x3 * JGtkWin->fontWidth;
3990    x1 = x1 * JGtkWin->fontWidth;
3991    y3 = y3 * JGtkWin->fontHeight;
3992    y1 = y1 * JGtkWin->fontHeight;
3993    hide_cursor ();
3994 
3995    if ( win1 == win3 )
3996      {
3997 	gdk_gc_set_exposures( win1->style->white_gc, 1 );
3998 	gdk_draw_drawable( win1->window, win1->style->white_gc, win3->window,
3999 			   x1, y1 - jedWin1->sy * JGtkWin->fontHeight,
4000 			   x3, y3 - jedWin3->sy * JGtkWin->fontHeight, w, h );
4001      }
4002    else
4003      {
4004 	printf( "file: %s, Line: %d: GtkCopyRect: widgets differ!!!\n", __FILE__, __LINE__ );
4005      }
4006 }
4007 
4008 /*}}}*/
4009 
4010 /************************************
4011 * gtkBlankRect
4012 *
4013 * group:
4014 *
4015 *
4016 * debug print: "x1: %d, y1: %d, x2: %d, y2: %d \n", x1, y1, x2, y2
4017 *
4018 ************************************/
4019 
4020 static void
gtkBlankRect(int x1,int y1,int x2,int y2)4021 gtkBlankRect (int x1,  int y1, int x2, int y2 ) /*{{{*/
4022 {
4023    int w, h;
4024    Window_Type *jedWin1 = NULL;
4025    Window_Type *jedWin2 = NULL;
4026    GtkWidget *win1 = NULL;
4027    GtkWidget *win2 = NULL;
4028 
4029    /* Dbp4( "JedWin1: %p, JedWin2: %p, Win1: %p, Win2: %p\n", jedWin1, jedWin2, win1, win2 ); */
4030 
4031    jedWin1 = JGtkWin->widgetWinXRef[y1][x1]->jedWin;
4032 
4033    /* Dbp4( "JedWin1: %p, JedWin2: %p, Win1: %p, Win2: %p\n", jedWin1, jedWin2, win1, win2 ); */
4034 
4035    win1 = JGtkWin->widgetWinXRef[y1][x1]->edWin;
4036 
4037    /* Dbp4( "JedWin1: %p, JedWin2: %p, Win1: %p, Win2: %p\n", jedWin1, jedWin2, win1, win2 ); */
4038 
4039    if (No_XEvents || (JGtkWin->window_mapped == 0)) return;
4040 
4041    w = (x2 - x1) * JGtkWin->fontWidth;
4042    h = (y2 - y1) * JGtkWin->fontHeight;
4043 
4044    if ((w <= 0) || (h <= 0)) return;
4045 
4046    x1 = x1 * JGtkWin->fontWidth;
4047    y1 = y1 * JGtkWin->fontHeight;
4048    hide_cursor ();
4049 
4050    gdk_gc_set_foreground( DefaultGtkGCInfo[JNORMAL_COLOR].gc, DefaultGtkGCInfo[JNORMAL_COLOR].bg );
4051 
4052    /*  gdk_draw_rectangle( win1->window, win1->style->white_gc, 1, */
4053    gdk_draw_rectangle( win1->window, DefaultGtkGCInfo[JNORMAL_COLOR].gc, 1,
4054 		       x1, y1 - jedWin1->sy * JGtkWin->fontHeight,
4055 		       w, h );
4056 
4057    gdk_gc_set_foreground( DefaultGtkGCInfo[JNORMAL_COLOR].gc, DefaultGtkGCInfo[JNORMAL_COLOR].fg );
4058 }
4059 
4060 /*}}}*/
4061 
4062 /************************************
4063 * copy_rect
4064 *
4065 * group:
4066 *
4067 *
4068 * debug print:
4069 *
4070 *
4071 ************************************/
4072 
4073 static void
copy_rect(int x1,int y1,int x2,int y2,int x3,int y3)4074 copy_rect(int x1, int y1, int x2, int y2, int x3, int y3)  /*{{{*/
4075 {
4076    int w, h;
4077 
4078    gtkCopyRect( x1, y1, x2, y2, x3, y3 );
4079 }
4080 
4081 /*}}}*/
4082 
4083 /************************************
4084 * blank_rect
4085 *
4086 * group:
4087 *
4088 *
4089 * debug print:
4090 *
4091 *
4092 ************************************/
4093 
4094 static void
blank_rect(int x1,int y1,int x2,int y2)4095 blank_rect (int x1,  int y1, int x2, int y2 ) /*{{{*/
4096 {
4097    int w, h;
4098 
4099    gtkBlankRect( x1, y1, x2, y2 );
4100 }
4101 
4102 /*}}}*/
4103 
4104 /************************************
4105 * JX_set_scroll_region
4106 *
4107 * group: interface
4108 *
4109 *
4110 * debug print: "r1: %d, r2: %d\n", r1, r2
4111 *
4112 *
4113 ************************************/
4114 
4115 static void
JX_set_scroll_region(int r1,int r2)4116 JX_set_scroll_region(int r1, int r2)
4117 {
4118    JGtkWin->scroll_r1 = r1;
4119    JGtkWin->scroll_r2 = r2;
4120    /* vterm_set_scroll_region (r1, r2); */
4121 }
4122 
4123 /************************************
4124 * jGtkSetFocus
4125 *
4126 * debug print: "(void) dummy: %d\n", 1
4127 *
4128 ************************************/
4129 
jGtkSetFocus(void)4130 void jGtkSetFocus(void)
4131 {
4132    JGtkWin->focus = 1;
4133 }
4134 
4135 /************************************
4136 * JX_reset_scroll_region
4137 *
4138 * group:  interface
4139 *
4140 *
4141 * debug print:
4142 *
4143 *
4144 ************************************/
4145 
4146 static void
JX_reset_scroll_region(void)4147 JX_reset_scroll_region (void ) /*{{{*/
4148 {
4149    JX_set_scroll_region (0, JX_Screen_Rows - 1);
4150 }
4151 
4152 /*}}}*/
4153 
4154 /************************************
4155 * show_cursor
4156 *
4157 * group:
4158 *
4159 *
4160 * debug print:
4161 *
4162 *
4163 ************************************/
4164 
4165 static void
show_cursor(void)4166 show_cursor( void ) /*{{{*/
4167 {
4168    SLsmg_Char_Type sc;
4169    int row, col, b;
4170    int color;
4171    GC gc;
4172    XGCValues gcv;
4173 
4174    /* Db; */
4175 
4176    if ( No_XEvents )
4177      return;
4178 
4179    /* Db; */
4180 
4181    if ( JGtkWin->cursor_showing ) hide_cursor ();
4182 
4183    /* Db; */
4184 
4185    JGtkWin->cursor_showing = 1;
4186    row = JGtkWin->vis_curs_row = JGtkWin->cursor_row;
4187    col = JGtkWin->vis_curs_col = JGtkWin->cursor_col;
4188    b = JGtkWin->border;
4189 
4190    /* Dbp2( ">>>>>>>>>> row: %d, col: %d\n", row, col ); */
4191    /* Db; */
4192 
4193    if ( ( CBuf != NULL ) && ( CBuf->flags & OVERWRITE_MODE ) )
4194      color = JCURSOROVR_COLOR;
4195    else
4196      color = JCURSOR_COLOR;
4197 
4198    /* Db; */
4199 
4200    if ( JGtkWin->focus )
4201      {
4202       /* Db; */
4203 	if ( smg_read_at(row, col, &sc, 1) == 0 )
4204 	  SLSMGCHAR_SET_CHAR( sc, ' ' );
4205 	SLSMGCHAR_SET_COLOR( sc, color );
4206 	JX_write_smgchar( row, col, &sc );
4207      }
4208    else
4209      {
4210       /* Draw rectangle !!!!!!!! */
4211 	GtkWidget *w;
4212 	Window_Type *jedWin;
4213 
4214       /* Dbp3( "WidgetWinXRef: %p, Row: %d, Col: %d\n", JGtkWin->widgetWinXRef, row, col ); */
4215 
4216 	if ( row > 0 && col >= 0 )
4217 	  {
4218 	 /* Dbp3( "WidgetWinXRef: %p, Row: %d, Col: %d\n", JGtkWin->widgetWinXRef, row, col ); */
4219 
4220 	     w = JGtkWin->widgetWinXRef[row][col]->edWin;
4221 	     jedWin = JGtkWin->widgetWinXRef[row][col]->jedWin;
4222 
4223 	 /* Dbp4( "Color: %d Default gc: %p, Default fg col: %p Default bg col: %p\n", */
4224 	 /*       color, DefaultGtkGCInfo[color].gc, DefaultGtkGCInfo[color].fg, DefaultGtkGCInfo[color].bg ); */
4225 
4226 	     gdk_gc_set_foreground( DefaultGtkGCInfo[color].gc, DefaultGtkGCInfo[color].bg );
4227 	     gdk_gc_set_background( DefaultGtkGCInfo[color].gc, DefaultGtkGCInfo[color].fg );
4228 
4229 	     if ( w && w->window )
4230 	       gdk_draw_rectangle( w->window,
4231 				   DefaultGtkGCInfo[color].gc,
4232 				   0,
4233 				   (col - jedWin->sx)*JGtkWin->fontWidth,
4234 				   (row - jedWin->sy)*JGtkWin->fontHeight,
4235 				   JGtkWin->fontWidth - 1,
4236 				   JGtkWin->fontHeight - 1 );
4237 
4238 	     gdk_gc_set_foreground( DefaultGtkGCInfo[color].gc, DefaultGtkGCInfo[color].fg );
4239 	     gdk_gc_set_background( DefaultGtkGCInfo[color].gc, DefaultGtkGCInfo[color].bg );
4240 	  }
4241      }
4242 
4243 }
4244 
4245 /*}}}*/
4246 
4247 /************************************
4248 * toggle_cursor
4249 *
4250 * group:
4251 *
4252 *
4253 * debug print:
4254 *
4255 *
4256 ************************************/
4257 
4258 static void
toggle_cursor(int on)4259 toggle_cursor (int on ) /*{{{*/
4260 {
4261    /* Dbp1( ">>> %d <<<#####################################################################\n", on ); */
4262    if (on)
4263      {
4264 	if ( JGtkWin->focus) return;
4265 	JGtkWin->focus = 1;
4266      }
4267    else
4268      {
4269 	if ( JGtkWin->focus == 0) return;
4270 	JGtkWin->focus = 0;
4271      }
4272 
4273    show_cursor ();
4274 }
4275 
4276 /*}}}*/
4277 
4278 /* This routine assumes that cursor is in the correct location.  The
4279  * cursor is placed at the end of the string.  Even if we are unable to
4280  * write the string, make sure that the cursor is moved as if we did
4281  * the write. The main reason for this is that our X cursor must track
4282  * the vterm cursor so that the display gets updated properly.
4283  * Otherwise, smart_puts will call forward_cursor and then write to the
4284  * virtual display, and get that wrong because forward_cursor assumes
4285  * that the XWin cursor is correct.
4286  */
4287 
4288 /************************************
4289 * JX_write_string
4290 *
4291 * group:
4292 *
4293 *
4294 * debug print:
4295 *
4296 *
4297 ************************************/
4298 
4299 static void
JX_write_string(char * s)4300 JX_write_string (char *s ) /*{{{*/
4301 {
4302    unsigned int nchars;
4303    SLwchar_Type *w;
4304    unsigned int nbytes = strlen(s);
4305 
4306    /* printf( "File: %s, Line: %d: JX_write_string\n", __FILE__, __LINE__ ); */
4307 
4308 #if SLANG_VERSION >= 20000
4309 
4310    if (Jed_UTF8_Mode)
4311      w = utf8nt_to_wchars((unsigned char *)s, nbytes, &nchars);
4312    else
4313      {
4314 	w = bytes_to_wchars((unsigned char *)s, nbytes);
4315 	nchars = nbytes;
4316      }
4317    if ( w == NULL )
4318      goto write_done;
4319 
4320 #else
4321    nchars = nbytes;
4322    w = s;
4323 #endif
4324 
4325    if ((No_XEvents == 0) && JGtkWin->window_mapped)
4326      {
4327 	hide_cursor ();
4328 	(void) jGtkDraw( JGtkWin->current_gc_num, JGtkWin->cursor_row, JGtkWin->cursor_col, w, nchars, 0);
4329      }
4330 #if SLANG_VERSION >= 20000
4331    SLfree((char *)w);
4332 write_done:
4333 #endif
4334 
4335    JGtkWin->cursor_col += nchars;
4336    if ( JGtkWin->cursor_col >= JX_Screen_Cols)
4337      JGtkWin->cursor_col = JX_Screen_Cols - 1;
4338    if (!Performing_Update)
4339      show_cursor();
4340 }
4341 
4342 /************************************
4343 * JX_goto_rc
4344 *
4345 * group: interface
4346 *
4347 *
4348 * debug print: "r: %d, c: %d\n", r, c
4349 *
4350 *
4351 ************************************/
4352 
4353 static void
JX_goto_rc(int r,int c)4354 JX_goto_rc(int r, int c)  /*{{{*/
4355 {
4356    /* Dbp2( ">>>>>>>>>>>>>>>> r: %d, c: %d\n", r, c ); */
4357 
4358    if ( JGtkWin == NULL) return;
4359    if ( JGtkWin->cursor_showing) hide_cursor ();
4360    if (r >= JX_Screen_Rows) r = JX_Screen_Rows - 1;
4361    if (c >= JX_Screen_Cols) c = JX_Screen_Cols - 1;
4362 
4363    JGtkWin->cursor_row = r + JGtkWin->scroll_r1;
4364    JGtkWin->cursor_col = c;
4365 
4366    /* Dbp1( "JGtkWin->scroll_r1: %d\n", JGtkWin->scroll_r1 ); */
4367    /* Dbp2( "JGtkWin->cursor_row: %d, JGtkWin->cursor_col: %d\n", JGtkWin->cursor_row, JGtkWin->cursor_col ); */
4368 
4369    if (Performing_Update) return;
4370    show_cursor ();
4371 }
4372 
4373 /*}}}*/
4374 
4375 /* Must respect scrolling region */
4376 /************************************
4377 * JX_delete_nlines
4378 *
4379 * group: interface
4380 *
4381 *
4382 * debug print: "n: %d\n", n
4383 *
4384 *
4385 ************************************/
4386 
4387 static void
JX_delete_nlines(int n)4388 JX_delete_nlines(int n)  /*{{{*/
4389 {
4390    int r1, r2;
4391    JGtkWinType *win = JGtkWin;
4392 
4393    r1 = JGtkWin->cursor_row;
4394    r2 = JGtkWin->scroll_r2;
4395 
4396    /* Dbp2( "JGtkWin->cursor_row: %d, JGtkWin->scroll_r2: %d\n", JGtkWin->cursor_row, JGtkWin->scroll_r2 ); */
4397 
4398    if (r1 <= r2 - n) copy_rect(0, r1 + n, JX_Screen_Cols, r2 + 1,
4399 			       0, r1);
4400 
4401    jGtkCoverExposedArea( 0, (r2 - n)*win->fontHeight,
4402 			 JX_Screen_Cols*win->fontWidth, win->fontHeight,
4403 			 1 );
4404 
4405    r2++;
4406    blank_rect(0, r2 - n, JX_Screen_Cols, r2);
4407 }
4408 
4409 /*}}}*/
4410 
4411 /************************************
4412 * JX_reverse_index
4413 *
4414 * group: interface
4415 *
4416 *
4417 * debug print: "n: %d\n", n
4418 *
4419 *
4420 ************************************/
4421 
4422 static void
JX_reverse_index(int n)4423 JX_reverse_index( int n )  /*{{{*/
4424 {
4425    int r1, r2;
4426 
4427    /* vterm_reverse_index (n); */
4428 
4429    if (No_XEvents || ( JGtkWin->window_mapped == 0))
4430      return;
4431 
4432    r1 = JGtkWin->scroll_r1;
4433    r2 = JGtkWin->scroll_r2;
4434 
4435    if (r2 >= r1 + n) copy_rect(0, r1, JX_Screen_Cols, r2 - n + 1,
4436 			       0, r1 + n);
4437 
4438    blank_rect(0, r1, JX_Screen_Cols, r1 + n);
4439 }
4440 
4441 /*}}}*/
4442 
4443 /************************************
4444 * JX_beep
4445 *
4446 * group:
4447 *
4448 *
4449 * debug print:
4450 *
4451 *
4452 ************************************/
4453 
4454 static void
JX_beep(void)4455 JX_beep(void)  /*{{{*/
4456 {
4457 
4458    if ( No_XEvents ) return;
4459 
4460    flush_input();
4461 
4462    if ( JGtkWin->appWMiniW &&
4463 	JGtkWin->appWMiniW->window )
4464      {
4465 	if ( JX_Ignore_Beep & 0x1 )
4466 	  {
4467 #if 0				       /* not defined in my version of gtk */
4468 	     gdk_window_beep( JGtkWin->appWMiniW->window );
4469 #endif
4470 	  }
4471 
4472 	if ( JX_Ignore_Beep & 0x2 )
4473 	  {
4474 	     struct timeval bgTime;
4475 	     GdkColor colorWhite = { 0, 0xffff, 0xffff, 0xffff },
4476 	     colorBlack = { 0, 0x0, 0x0, 0x0 };
4477 	     GdkGC *gc = gdk_gc_new( JGtkWin->appWMiniW->window );
4478 	     GtkSubWinType *sw = JGtkWin->subWins;
4479 
4480 	     gdk_gc_set_rgb_fg_color( gc, &colorWhite );
4481 	     gdk_gc_set_rgb_bg_color( gc, &colorBlack );
4482 
4483 	     gdk_gc_set_function( gc, GDK_INVERT );
4484 
4485 	     do
4486 	       {
4487 		  if ( sw->edWin && sw->edWin->window )
4488 		    {
4489 		       gdk_draw_rectangle( sw->edWin->window,
4490 					   gc, TRUE,
4491 					   0, 0,
4492 					   sw->edWin->allocation.width,
4493 					   sw->edWin->allocation.height );
4494 		    }
4495 		  if ( sw->stWin && sw->stWin->window )
4496 		    {
4497 		       gdk_draw_rectangle( sw->stWin->window,
4498 					   gc, TRUE,
4499 					   0, 0,
4500 					   sw->stWin->allocation.width,
4501 					   sw->stWin->allocation.height );
4502 		    }
4503 		  sw = sw->next;
4504 	       }
4505 	     while ( sw != JGtkWin->subWins );
4506 
4507 	     gdk_display_flush( JGtkWin->display );
4508 
4509 	     gettimeofday( &bgTime, NULL );
4510 
4511 	 /* Wait 100 ms */
4512 	     while ( jGtkDiffTime( &bgTime ) < 100 )
4513 	       {
4514 		  ;
4515 	       }
4516 
4517 	     do
4518 	       {
4519 		  if ( sw->edWin && sw->edWin->window )
4520 		    {
4521 		       gdk_draw_rectangle( sw->edWin->window,
4522 					   gc, TRUE,
4523 					   0, 0,
4524 					   sw->edWin->allocation.width,
4525 					   sw->edWin->allocation.height );
4526 		    }
4527 		  if ( sw->stWin && sw->stWin->window )
4528 		    {
4529 		       gdk_draw_rectangle( sw->stWin->window,
4530 					   gc, TRUE,
4531 					   0, 0,
4532 					   sw->stWin->allocation.width,
4533 					   sw->stWin->allocation.height );
4534 		    }
4535 		  sw = sw->next;
4536 	       }
4537 	     while ( sw != JGtkWin->subWins );
4538 
4539 	     gdk_display_flush( JGtkWin->display );
4540 
4541 	     gdk_gc_unref( gc );
4542 	  }
4543      }
4544 
4545 }
4546 
4547 /*}}}*/
4548 
4549 /************************************
4550 * JX_del_eol
4551 *
4552 * group: interface
4553 *
4554 *
4555 * debug print: "(void %d)", 0
4556 *
4557 *
4558 ************************************/
4559 
4560 static void
JX_del_eol(void)4561 JX_del_eol(void)  /*{{{*/
4562 {
4563    blank_rect( JGtkWin->cursor_col, JGtkWin->cursor_row, JX_Screen_Cols, JGtkWin->cursor_row + 1);
4564 }
4565 
4566 /*}}}*/
4567 
4568 /************************************
4569 * JX_reverse_video
4570 *
4571 * group:
4572 *
4573 *
4574 * debug print:
4575 *
4576 *
4577 ************************************/
4578 
4579 static void
JX_reverse_video(int color)4580 JX_reverse_video(int color)  /*{{{*/
4581 {
4582    if ((color < 0) || (color >= JMAX_COLORS))
4583      return;
4584 }
4585 
4586 /*}}}*/
4587 
4588 /************************************
4589 * JX_normal_video
4590 *
4591 * group: interface
4592 *
4593 *
4594 * debug print:
4595 *
4596 *
4597 ************************************/
4598 
4599 static void
JX_normal_video(void)4600 JX_normal_video(void)  /*{{{*/
4601 {
4602    JX_reverse_video (JNORMAL_COLOR);
4603 }
4604 
4605 /*}}}*/
4606 
4607 /************************************
4608 * JX_smart_puts
4609 *
4610 * group: interface
4611 *
4612 *
4613 * debug print:
4614 *
4615 *
4616 ************************************/
4617 
4618 static void
JX_smart_puts(SLsmg_Char_Type * neww,SLsmg_Char_Type * oldd,int len,int row)4619 JX_smart_puts(SLsmg_Char_Type *neww, SLsmg_Char_Type *oldd, int len, int row)
4620 {
4621    int col;
4622 
4623    /* Skip equal chars at the beginning */
4624    col = 0;
4625    while ((col < len) && SLSMGCHAR_EQUAL(&neww[col], &oldd[col]))
4626      col++;
4627 
4628    if (col < len)
4629      {
4630 	hide_cursor();
4631 	JX_write_smgchars(row, col, neww+col, neww+len);
4632 	JX_goto_rc (row, len);
4633      }
4634 }
4635 
4636 /*}}}*/
4637 
4638 /************************************
4639 * jGtkCoverExposedArea
4640 *
4641 * group:
4642 *
4643 *
4644 * debug print:
4645 *
4646 *
4647 ************************************/
4648 
4649 static void
jGtkCoverExposedArea(int x,int y,int width,int height,int count)4650 jGtkCoverExposedArea( int x, int y, int width, int height, int count)   /*{{{*/
4651 {
4652    JGtkWinType *win = JGtkWin;
4653    SLsmg_Char_Type *s;
4654    int row, max_col, max_row, col;
4655    int width_chars, len;
4656 
4657    Performing_Update++;
4658    /* VTerm_Suspend_Update++; */
4659    hide_cursor ();
4660    col = x / win->fontWidth;
4661    row = y / win->fontHeight;
4662 
4663    width_chars = 2 + width / win->fontWidth;
4664    max_col = col + width_chars;
4665    max_row = 2 + row + height / win->fontHeight;
4666    if (max_col > JX_Screen_Cols) max_col = JX_Screen_Cols;
4667    if (max_row > JX_Screen_Rows) max_row = JX_Screen_Rows;
4668 
4669    if (NULL != (s = (SLsmg_Char_Type *)SLmalloc(width_chars*sizeof(SLsmg_Char_Type))))
4670      {
4671 	while (row < max_row)
4672 	  {
4673 	     len = smg_read_at(row, col, s, width_chars);
4674 	     JX_write_smgchars(row, col, s, s + len);
4675 	     row++;
4676 	  }
4677 	SLfree ((char *)s);
4678      }
4679    Performing_Update--;
4680    if (count == 0) show_cursor ();
4681 }
4682 
4683 #include "xkeys.c"
4684 
4685 /* Return 1 if event is listed in the switch or zero otherwise.  The switch
4686  * events are considered harmless--- that is, processing them does not really
4687  * interfere with internal JED state (redisplay, etc...).  More bluntly,
4688  * harmless means that the events can be processesed while checking for
4689  * pending input.
4690  */
4691 static int Debug_gtkjed = 0;
4692 
4693 /*}}}*/
4694 
4695 /************************************
4696 * jGtkFillJMouse
4697 *
4698 * group:
4699 *
4700 *
4701 * debug print:
4702 *
4703 *
4704 ************************************/
4705 
4706 static void
jGtkFillJMouse(JMouse_Type * jmouse,unsigned char type,int x,int y,unsigned long t,unsigned int button,unsigned int state)4707 jGtkFillJMouse( JMouse_Type *jmouse, /*{{{*/
4708 		unsigned char type, int x, int y, unsigned long t,
4709 		unsigned int button, unsigned int state )
4710 {
4711    unsigned char s;
4712 #if JED_HAS_MULTICLICK
4713    static unsigned long last_press_time;
4714    static unsigned int clicks;
4715    static unsigned int last_button;
4716 
4717    /* printf( "In fill_jmouse\n" ); */
4718 
4719    if (type == JMOUSE_DOWN)
4720      {
4721 	/* printf( "File: %s Line: %d\n", __FILE__, __LINE__ ); */
4722 	if ((last_button == button)
4723 	    && (last_press_time + JX_MultiClick_Time > t))
4724 	  {
4725 	   /* printf( "File: %s Line: %d\n", __FILE__, __LINE__ ); */
4726 	     clicks++;
4727 	     if (clicks == 2)
4728 	       type = JMOUSE_DOUBLE_CLICK;
4729 	     else
4730 	       type = JMOUSE_TRIPLE_CLICK;
4731 	  }
4732 	else
4733 	  {
4734 	   /* printf( "File: %s Line: %d\n", __FILE__, __LINE__ ); */
4735 	     clicks = 1;
4736 	     last_button = button;
4737 	  }
4738 	last_press_time = t;
4739      }
4740    else if ((clicks > 1) && (last_button == button))
4741      {
4742 	/* printf( "File: %s Line: %d\n", __FILE__, __LINE__ ); */
4743 	/* Last was a multi-click.  Ignore this event. */
4744 	type = JMOUSE_IGNORE_EVENT;
4745      }
4746 #endif
4747    jmouse->type = type;
4748    jmouse->x = 1 + x / JGtkWin->fontWidth;
4749 
4750    /* if ( y < XWin->border ) jmouse->y = 0; */
4751    if ( y < JGtkWin->border ) jmouse->y = 0;
4752    else jmouse->y = 1 + y / JGtkWin->fontHeight;
4753 
4754    /* Dbp2( "Mouse y: %d jmouse->y: %d\n", y, jmouse->y ); */
4755 
4756    if (button == Button1) jmouse->button = JMOUSE_BUTTON_1;
4757    else if (button == Button2) jmouse->button = JMOUSE_BUTTON_2;
4758    else if (button == Button3) jmouse->button = JMOUSE_BUTTON_3;
4759    else if (button == Button4) jmouse->button = JMOUSE_BUTTON_4;
4760    else if (button == Button5) jmouse->button = JMOUSE_BUTTON_5;
4761    else jmouse->button = JMOUSE_BUTTON_6;
4762 
4763    s = 0;
4764    if (state & Button1Mask) s |= JMOUSE_BUTTON_1;
4765    if (state & Button2Mask) s |= JMOUSE_BUTTON_2;
4766    if (state & Button3Mask) s |= JMOUSE_BUTTON_3;
4767    if (state & Button4Mask) s |= JMOUSE_BUTTON_4;
4768    if (state & Button5Mask) s |= JMOUSE_BUTTON_5;
4769    if (state & Button6Mask) s |= JMOUSE_BUTTON_5;
4770    if (state & ShiftMask) s |= JMOUSE_SHIFT;
4771    if (state & ControlMask) s |= JMOUSE_CTRL;
4772 
4773    jmouse->state = s;
4774    /* printf( "File: %s Line: %d\n", __FILE__, __LINE__ ); */
4775 
4776 }
4777 
4778 /*}}}*/
4779 
4780 /************************************
4781 * getJGtkSubWin
4782 *
4783 * group:
4784 *
4785 *
4786 * debug print:
4787 *
4788 *
4789 ************************************/
4790 
4791 static GtkSubWinType *
getJGtkSubWin(GtkWidget * w)4792 getJGtkSubWin( GtkWidget *w )
4793 {
4794    GtkSubWinType *tmpW = JGtkWin->subWins;
4795 
4796    do
4797      {
4798 	if ( tmpW->edWin == w ||
4799 	     tmpW->stWin == w )
4800 	  {
4801 	     return( tmpW );
4802 	  }
4803 	tmpW = tmpW->next;
4804      }
4805    while ( tmpW != JGtkWin->subWins );
4806 
4807    return( NULL );
4808 }
4809 
4810 /************************************
4811 * translateCoord
4812 *
4813 * group:
4814 *
4815 *
4816 * debug print: "FontHeight: %d, Widget: %p, x: %d, y: %d\n", JGtkWin->fontHeight, w, x, y
4817 *
4818 ************************************/
4819 
4820 static void
translateCoord(GtkWidget * w,int x,int y,int * newX,int * newY)4821 translateCoord( GtkWidget *w, int x, int y, int *newX, int *newY )
4822 {
4823    /* GtkSubWinType *tmpWin = JGtkWin->subWins; */
4824    GtkSubWinType *actSubWin = getJGtkSubWin( w );
4825    int actSubWinSy;
4826 
4827    /* Dbp1( "ActSubWin: %p\n", actSubWin ); */
4828 
4829    /* printSubWins(); */
4830 
4831    *newX = x;
4832 
4833    if ( actSubWin )
4834      {
4835 	if ( actSubWin->edWin == w )
4836 	  {  /* edit windows */
4837 	     *newY = actSubWin->jedWin->sy  * JGtkWin->fontHeight + y;
4838 	  }
4839 	else
4840 	  {  /* status windows */
4841 	     *newY = ( actSubWin->jedWin->sy  + actSubWin->jedWin->rows ) *
4842 	       JGtkWin->fontHeight + y;
4843 	  }
4844      }
4845    else
4846      { /* minibuffer window */
4847 	*newY = ( Jed_Num_Screen_Rows - 1 ) * JGtkWin->fontHeight + y;
4848      }
4849 }
4850 
4851 /*************************/
4852 
4853 #define MOUSE_DRAG_THRESHOLD 3
4854 
4855 /* if force is true, wait for an event.  If force is false, only
4856  *  process events that exist.  This will Return either when there
4857  *  are no more events or a key/mouse event is processed Returning
4858  *  1 in the process */
4859 /************************************
4860 * X_process_events
4861 *
4862 * group:
4863 *
4864 *
4865 * debug print:
4866 *
4867 *
4868 ************************************/
4869 
4870 static int
X_process_events(int force,char * buf,unsigned int buflen,int * n_chars)4871 X_process_events( int force, char *buf,
4872 		  unsigned int buflen,
4873 		  int *n_chars )  /*{{{*/
4874 {
4875    char *savBuf;
4876    int xGtkPend, jXGtkPend;
4877    XEvent report;
4878    JXGtkEventType jXEv;
4879    JMouse_Type jmouse;
4880    int ch1;
4881    int block_expose = 0;
4882    char *bufp;
4883    KeySym ks = 0;
4884    int esc = 27;
4885 
4886    Window root, child;
4887    int posx, posy, rootx, rooty;
4888    unsigned int keys_buttons;
4889    int last_x, last_y;
4890    static int last_event, last_motion_down_button;
4891    static unsigned int motion_state;
4892 #if MOUSE_DRAG_THRESHOLD
4893    static int button_press_x, button_press_y;
4894 #endif
4895    int width, height;
4896 
4897    /* printf( "File: %s Line: %d X_process_events\n", __FILE__, __LINE__ ); */
4898 
4899    /* while ( force || XGtkPending( This_XDisplay ) || jGtkPending( This_XDisplay ) ) */
4900    /* while ( force || jGtkPending( This_XDisplay ) ) */
4901    while ( force || jGtkPending() )
4902      {
4903 	/* printf( "File: %s Line: %d\n", __FILE__, __LINE__ ); */
4904 
4905      /* if ( jGtkPending( This_XDisplay ) ) */
4906 	if ( jGtkPending() )
4907 	  {
4908         /* JXGtkNextEvent( This_XDisplay, &jXEv ); */
4909 	     JXGtkNextEvent( &jXEv );
4910 
4911 	     switch ( jXEv.type )
4912 	       {
4913 		case JXGtkGdkEventID:
4914 		  switch ( jXEv.gdkEvent.gdkEvent.type )
4915 		    {
4916 		     case GDK_KEY_PRESS:
4917 	          /* printf( "File: %s, Line: %d: JXEvent, KeyPress\n", __FILE__, __LINE__ ); */
4918 		       bufp = buf;
4919 
4920 		       *n_chars = 0;
4921 
4922 		       if ( jXEv.gdkEvent.gdkEvent.key.keyval <= 0xFF )
4923 			 {
4924 	             /* printf( "File: %s, Line: %d: buf: %p, bufp %p\n", __FILE__, __LINE__, buf, bufp ); */
4925 
4926 			    bufp = SLutf8_encode( gdk_keyval_to_unicode( jXEv.gdkEvent.gdkEvent.key.keyval ),
4927 						  buf,
4928 						  buflen );
4929 	             /* printf( "File: %s, Line: %d: buf: %p, bufp %p\n", __FILE__, __LINE__, buf, bufp ); */
4930 
4931 			    if ( bufp )
4932 			      {
4933 	                /* printf( "File: %s, Line: %d: buf: %p, bufp %p\n", __FILE__, __LINE__, buf, bufp ); */
4934 				 *n_chars = bufp - buf;
4935 				 if ( *n_chars == 1 && ( jXEv.gdkEvent.gdkEvent.key.state & GDK_CONTROL_MASK ) )
4936 				   {
4937 	                   /* printf( "File: %s, Line: %d: buf: %p, bufp %p\n", __FILE__, __LINE__, buf, bufp ); */
4938 				      if ( *buf >= 'a' && *buf <= 'z' ) *buf = *buf - 0x60;
4939 				      if ( *buf >= 'A' && *buf <= 'Z' ) *buf = *buf - 0x40;
4940 				   }
4941 			      }
4942 			    else *n_chars = 0;
4943 			 }
4944 		       else
4945 			 {
4946 		     /*   I do not know why!!! */
4947 			    *buf = 1;
4948 			 }
4949 
4950 		       bufp = ( char * ) map_keysym_to_keyseq( jXEv.gdkEvent.gdkEvent.key.keyval, jXEv.gdkEvent.gdkEvent.key.state &
4951 							       ( ShiftMask | ControlMask ) );
4952 	          /* printf( "File: %s, Line: %d: bufp: %p\n", __FILE__, __LINE__, bufp ); */
4953 
4954 		       if (bufp != NULL)
4955 			 {
4956 			    *n_chars = (unsigned char) *bufp++;
4957 #if USE_NEW_META_CODE
4958 			    if ( jXEv.gdkEvent.gdkEvent.key.state & JX_MetaMask)
4959 			      {
4960 				 buf[0] = X_Alt_Char;
4961 				 SLMEMCPY (buf + 1, bufp, *n_chars);
4962 				 *n_chars += 1;
4963 			      }
4964 			    else
4965 #endif
4966 			      SLMEMCPY(buf, bufp, *n_chars);
4967 			 }
4968 		       else if (*n_chars == 1)
4969 			 {
4970 			    if ( bufp == NULL )
4971 			      bufp = buf;
4972 
4973 			    if ( jXEv.gdkEvent.gdkEvent.key.state & JX_MetaMask )
4974 			      {
4975 				 ch1 = *bufp;
4976 				 if ( X_Alt_Char <= 0 ) *buf |= 0x80;
4977 				 else
4978 				   {
4979 				      *bufp++ = (unsigned char) X_Alt_Char;
4980 				      *bufp = (unsigned char) ch1;
4981 				      *n_chars = 2;
4982 				   }
4983 			      }
4984 			    else if ( jXEv.gdkEvent.gdkEvent.key.state & ControlMask )
4985 			      {
4986 				 if (*buf == ' ') *buf = 0;
4987 				 else if (*buf == '-') *buf = 0x1F;
4988 			      }
4989 			 }
4990 
4991 		       if ( *n_chars == 0 ) break;
4992 		       return 1;
4993 		       break;
4994 		     case GDK_MOTION_NOTIFY:
4995 	          /* printf( "File: %s Line: %d GDK_MOTION_NOTIFY\n", __FILE__, __LINE__ ); */
4996 
4997 	          /* Make sure we get the last event of this type */
4998 		       while ( JXGtkCheckMaskEvent( GDK_MOTION_NOTIFY, &jXEv ) )
4999 			 ;
5000 	          /* printf( "File: %s Line: %d GDK_MOTION_NOTIFY\n", __FILE__, __LINE__ ); */
5001 
5002 		       if ( jXEv.gdkEvent.w )
5003 			 {
5004 			    translateCoord( jXEv.gdkEvent.w,
5005 					    jXEv.gdkEvent.gdkEvent.button.x,
5006 					    jXEv.gdkEvent.gdkEvent.button.y,
5007 					    &posx, &posy );
5008 			 }
5009 
5010 		       keys_buttons = jXEv.gdkEvent.gdkEvent.motion.state;
5011 
5012 	          /* This will ensure that modifier keys are not pressed while
5013 	          we are in motion. */
5014 	          /* printf( "File: %s Line: %d GDK_MOTION_NOTIFY\n", __FILE__, __LINE__ ); */
5015 
5016 		       if ( ( last_event == GDK_MOTION_NOTIFY )
5017 			    && ( motion_state != keys_buttons ) )
5018 			 break;
5019 	          /* printf( "File: %s Line: %d GDK_MOTION_NOTIFY\n", __FILE__, __LINE__ ); */
5020 
5021 		       motion_state = keys_buttons;
5022 
5023 		       memset( ( char * ) &jmouse, 0, sizeof( jmouse ) );
5024 		       last_x = jmouse.x;
5025 		       last_y = jmouse.y;
5026 	          /* printf( "File: %s Line: %d GDK_MOTION_NOTIFY\n", __FILE__, __LINE__ ); */
5027 
5028 		       jGtkFillJMouse( &jmouse, JMOUSE_DRAG,
5029 				       posx, posy, jXEv.gdkEvent.gdkEvent.motion.time,
5030 				       last_motion_down_button, keys_buttons );
5031 	          /* printf( "File: %s Line: %d GDK_MOTION_NOTIFY\n", __FILE__, __LINE__ ); */
5032 
5033  		  /* Dbp3( " Button_press_x: %d, posx: %d: Diff abs: %d\n", button_press_x, posx, abs( button_press_x - posx ) ); */
5034  		  /* Dbp3( " Button_press_y: %d, posy: %d: Diff abs: %d\n", button_press_y, posy, abs( button_press_y - posy ) ); */
5035 
5036 #if MOUSE_DRAG_THRESHOLD
5037 		       if ( ( abs(button_press_x - posx ) <= MOUSE_DRAG_THRESHOLD )
5038 			    && ( abs( button_press_y - posy ) <= MOUSE_DRAG_THRESHOLD ) )
5039 			 {
5040 		     /* Db; */
5041 			    break;
5042 			 }
5043 #endif
5044 	          /* printf( "File: %s Line: %d\n", __FILE__, __LINE__ ); */
5045 		       if ((last_x == jmouse.x) && (last_y == jmouse.y)) break;
5046 	          /* printf( "File: %s Line: %d\n", __FILE__, __LINE__ ); */
5047 		       if (-1 == (ch1 = jed_mouse_add_event (&jmouse)))
5048 			 break;		       /* queue full */
5049 
5050 	           /* return ESC ^@ */
5051 	          /* printf( "File: %s Line: %d\n", __FILE__, __LINE__ ); */
5052 		       *buf++ = esc; *buf++ = 0; *buf++ = ch1;
5053 	          /* printf( "File: %s Line: %d\n", __FILE__, __LINE__ ); */
5054 		       *n_chars = 3;
5055 
5056 	          /* printf( "File: %s Line: %d\n", __FILE__, __LINE__ ); */
5057 		       last_event = MotionNotify;
5058 	          /* printf( "File: %s Line: %d\n", __FILE__, __LINE__ ); */
5059 		       return 1;
5060 
5061 		     case GDK_BUTTON_PRESS:
5062 		  /* gtkButtonEvent = 1; */
5063 	          /* Prohibit dragging more than one button at a time. */
5064 	          /* printf( "File: %s Line: %d\n", __FILE__, __LINE__ ); */
5065 		       if ( last_event == GDK_MOTION_NOTIFY ) break;
5066 	            /* drop */
5067 
5068 		     case GDK_BUTTON_RELEASE:
5069 		  /* gtkButtonEvent = 1; */
5070 	          /* printf( "File: %s Line: %d\n", __FILE__, __LINE__ ); */
5071 		       if ( ( last_event == GDK_MOTION_NOTIFY ) &&
5072 			    ( jXEv.gdkEvent.gdkEvent.button.button != (unsigned int) last_motion_down_button))
5073 			 break;
5074 
5075 	     	  /* printf( "File: %s Line: %d Button press\n", __FILE__, __LINE__ ); */
5076 		       last_event = 0;
5077 	          /* printf( "File: %s Line: %d Button press\n", __FILE__, __LINE__ ); */
5078 
5079 		       if ( jXEv.gdkEvent.w )
5080 			 {
5081 			    translateCoord( jXEv.gdkEvent.w,
5082 					    jXEv.gdkEvent.gdkEvent.button.x,
5083 					    jXEv.gdkEvent.gdkEvent.button.y,
5084 					    &rootx, &rooty );
5085 		     /* Dbp2( "Posx: %d, Posy: %d\n", rootx, rooty ); */
5086 
5087 			    jGtkFillJMouse (&jmouse,
5088 					    ((jXEv.gdkEvent.gdkEvent.type == GDK_BUTTON_RELEASE ) ? JMOUSE_UP : JMOUSE_DOWN ),
5089 					    rootx, rooty, jXEv.gdkEvent.gdkEvent.button.time,
5090 					    jXEv.gdkEvent.gdkEvent.button.button, jXEv.gdkEvent.gdkEvent.button.state);
5091 	     	  /* printf( "File: %s Line: %d\n", __FILE__, __LINE__ ); */
5092 			 }
5093 		       else
5094 			 {
5095 			    jGtkFillJMouse (&jmouse,
5096 					    ((jXEv.gdkEvent.gdkEvent.type == GDK_BUTTON_RELEASE ) ? JMOUSE_UP : JMOUSE_DOWN ),
5097 					    jXEv.gdkEvent.gdkEvent.button.x, jXEv.gdkEvent.gdkEvent.button.y, jXEv.gdkEvent.gdkEvent.button.time,
5098 					    jXEv.gdkEvent.gdkEvent.button.button, jXEv.gdkEvent.gdkEvent.button.state);
5099 
5100 			 }
5101 
5102 #if MOUSE_DRAG_THRESHOLD
5103 		       if ( jXEv.gdkEvent.gdkEvent.type == GDK_BUTTON_PRESS )
5104 			 {
5105 			    button_press_x = rootx;
5106 			    button_press_y = rooty;
5107 			 }
5108 		       else
5109 			 {
5110 			    button_press_x = 0;
5111 			    button_press_y = 0;
5112 			 }
5113 	          /* printf( "File: %s Line: %d Button press\n", __FILE__, __LINE__ ); */
5114 
5115 #endif
5116 
5117 		       if ( -1 == (ch1 = jed_mouse_add_event (&jmouse)))
5118 			 break;		       /* queue full */
5119 
5120 		       if ( ( jXEv.gdkEvent.gdkEvent.type == GDK_BUTTON_PRESS ) &&
5121 			    ( 0 == ( jXEv.gdkEvent.gdkEvent.button.state &
5122 				     ( GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK |
5123 				       GDK_BUTTON4_MASK | GDK_BUTTON5_MASK ) ) ) )
5124 			 last_motion_down_button = jXEv.gdkEvent.gdkEvent.button.button;
5125 
5126 		       savBuf = buf;
5127 
5128 	          /* ESC ^@ is a  mouse prefix */
5129 		       *buf++ = esc; *buf++ = 0; *buf++ = ch1;
5130 		       *n_chars = 3;
5131 	          /* printf( "File: %s Line: %d Button press (%2x|%2x|%2x)\n", __FILE__, __LINE__, savBuf[0], savBuf[1], savBuf[2] ); */
5132 
5133 		       return 1;
5134 		     default:
5135 		       printf( "Unknown GdkEvent: %s, %d.\n", __FILE__, __LINE__ );
5136 		       break;
5137 		    }
5138 		  break;
5139 		case JXKeyFeedID:
5140 	     /* Dbp3( "Key Feed Event: keys: |%p|: %d, %p\n", jXEv.keyFeed.keys, *( jXEv.keyFeed.keys ), *( jXEv.keyFeed.keys + 1 ) ); */
5141 		  strncpy( buf, ( jXEv.keyFeed.keys ) + 1, ( *( jXEv.keyFeed.keys ) ) - 1 );
5142 		  *n_chars = ( *( jXEv.keyFeed.keys ) ) - 1;
5143 		  SLfree( jXEv.keyFeed.keys );
5144 	     /* Dbp1( "n_chars: %d\n", *n_chars ); */
5145 		  return 1;
5146 		  break;
5147 		default:
5148 		  printf( "Unknown JXGtkEvent: %s, %d!!!\n", __FILE__, __LINE__ );
5149 		  break;
5150 	       }
5151 	  }
5152 
5153      }
5154 
5155    return 0;
5156 }
5157 
5158 /*}}}*/
5159 
5160 /************************************
5161 * X_read_key
5162 *
5163 * group: interface
5164 *
5165 *
5166 * debug print:
5167 *
5168 *
5169 ************************************/
5170 
5171 static int
X_read_key(void)5172 X_read_key( void )  /*{{{*/
5173 {
5174    int nread;
5175    char buf[64];
5176 
5177    /* printf( "File: %s Line: %d X_read_key before\n", __FILE__, __LINE__ ); */
5178    (void) X_process_events (1, buf, sizeof (buf), &nread);
5179    /* printf( "File: %s Line: %d X_read_key after, nread: %d\n", __FILE__, __LINE__, nread ); */
5180    if (nread > 1) ungetkey_string(buf + 1, nread - 1);
5181    /* Dbp2( "Nread: %d, *buf: %d\n", nread, *buf ); */
5182    if ( *buf == (char) Jed_Abort_Char )
5183      {
5184 	if ( Ignore_User_Abort == 0 )
5185 	  SLang_set_error (USER_BREAK);
5186 	SLKeyBoard_Quit = 1;
5187       /* Dbp2( "SLang_get_error: %d, USER_BREAK: %d\n", SLang_get_error(), USER_BREAK ); */
5188      }
5189    return (int) *buf;
5190 }
5191 
5192 /*}}}*/
5193 
5194 /************************************
5195 * X_input_pending
5196 *
5197 * called by sys_input_pending
5198 *
5199 * group: interface
5200 *
5201 *
5202 * debug print:
5203 *
5204 *
5205 ************************************/
5206 
5207 static int
X_input_pending(void)5208 X_input_pending( void )  /*{{{*/
5209 {
5210    XEvent ev;
5211    int n;
5212 
5213    while ( gtk_events_pending() )
5214      {
5215 	gtk_main_iteration_do( False );
5216      }
5217 
5218    if ( jGtkPending() )
5219      {
5220 	return( 1 );
5221      }
5222 
5223    return 0;
5224 }
5225 
5226 /*}}}*/
5227 
5228 /************************************
5229 * createKeyEvents
5230 *
5231 * group:
5232 *
5233 *
5234 * debug print:
5235 *
5236 *
5237 ************************************/
5238 
jgtk_createKeyEvents(char * keyStr)5239 int jgtk_createKeyEvents( char *keyStr )
5240 {
5241    FilterEventData *eB = thisEventBuffer;
5242    JXGtkEventType *newEv = ( JXGtkEventType * ) SLmalloc( sizeof( JXGtkEventType ) );
5243 
5244    /* Dbp3( "String: |%p|-|%p|-|%p|\n", keyStr[0], keyStr[1], keyStr[2] ); */
5245 
5246    newEv->type = JXKeyFeedID;
5247    newEv->any.type = JXKeyFeedID;
5248    newEv->keyFeed.type = JXKeyFeedID;
5249    /* newEv->keyFeed.keys = keyStr; */
5250    newEv->keyFeed.keys = SLmalloc( sizeof( ( *keyStr ) + 1 ) );
5251    strncpy( newEv->keyFeed.keys, keyStr, *keyStr );
5252    newEv->keyFeed.keys[(unsigned char) *keyStr] = '\0';
5253    eB->jXGtkEvList = g_list_append( eB->jXGtkEvList, newEv );
5254    ( eB->jXGtkNumEv ) += 1;
5255 
5256    return 0;
5257 }
5258 
5259 /************************************
5260 * JX_get_display_size
5261 *
5262 * group:
5263 *
5264 *
5265 * debug print:
5266 *
5267 *
5268 ************************************/
5269 
5270 static void
JX_get_display_size(int * rows,int * cols)5271 JX_get_display_size( int *rows, int *cols )  /*{{{*/
5272 {
5273    int sy, sx, i;
5274    int newHeight, newWidth;
5275    int hCheck;
5276    GtkSubWinType *sw;
5277    JGtkWinType *win = JGtkWin;
5278 
5279    if ( win->subWins )
5280      {
5281 	sw = win->subWins;
5282 
5283 	hCheck =
5284 	  sy = win->subWins->jedWin->sy;
5285 	sx = 0;
5286 
5287       /********
5288       printWidgetWinXRef();
5289       printSubWins();
5290       *******/
5291 
5292 	do
5293 	  {
5294 	     newHeight = sw->edWin->allocation.height / win->fontHeight + 1;
5295 	     hCheck += newHeight;
5296 	     if ( newHeight < 3 ) newHeight = 3;
5297 	     newWidth = win->appWInGrid->allocation.width / win->fontWidth;
5298 	     sy = sy + sw->jedWin->rows + 1;
5299 	     sw = sw->next;
5300 	  }
5301 	while ( sw != win->subWins );
5302 
5303 	if ( win->miniWinSW )
5304 	  {
5305 	     sy++;
5306 	     hCheck++;
5307 	  }
5308 
5309 	win->hCheck = hCheck;
5310 	win->inGridHeight = sy;
5311 
5312       /* printf( "win->hCheck: %d, win->inGridHeight: %d\n", hCheck, win->inGridHeight ); */
5313 
5314 	win->edWidth = newWidth;
5315 	win->edHeight = sy;
5316 
5317 	JX_Screen_Cols = win->edWidth;
5318 	JX_Screen_Rows = win->edHeight;
5319      }
5320    else
5321      {
5322 	JX_Screen_Cols = JGtkWin->width / JGtkWin->fontWidth;
5323 	JX_Screen_Rows = JGtkWin->height / JGtkWin->fontHeight;
5324      }
5325 
5326    Jed_Num_Screen_Cols = JX_Screen_Cols;
5327    Jed_Num_Screen_Rows = JX_Screen_Rows;
5328 
5329    *cols = JX_Screen_Cols;
5330    *rows = JX_Screen_Rows;
5331 
5332    /* Dbp2( "Jed_Num_Screen_Cols: %d, Jed_Num_Screen_Rows: %d\n", Jed_Num_Screen_Cols, Jed_Num_Screen_Rows ); */
5333 }
5334 /*}}}*/
5335 
5336 /************************************
5337 * JX_set_term_vtxxx
5338 *
5339 * group:
5340 *
5341 *
5342 * debug print:
5343 *
5344 *
5345 ************************************/
5346 
JX_set_term_vtxxx(int * n)5347 static void  JX_set_term_vtxxx (int *n ) /*{{{*/
5348 {
5349    (void) n;
5350 }
5351 
5352 /*}}}*/
5353 
5354 /************************************
5355 * JX_narrow_width
5356 *
5357 * group:
5358 *
5359 *
5360 * debug print:
5361 *
5362 *
5363 ************************************/
5364 
JX_narrow_width(void)5365 static void  JX_narrow_width (void ) /*{{{*/
5366 {
5367 }
5368 
5369 /*}}}*/
5370 
5371 /************************************
5372 * JX_wide_width
5373 *
5374 * group:
5375 *
5376 *
5377 * debug print:
5378 *
5379 *
5380 ************************************/
5381 
JX_wide_width(void)5382 static void   JX_wide_width (void ) /*{{{*/
5383 {
5384 }
5385 
5386 /*}}}*/
5387 
5388 /************************************
5389 * JX_enable_cursor_keys
5390 *
5391 * group:
5392 *
5393 *
5394 * debug print:
5395 *
5396 *
5397 ************************************/
5398 
5399 /* ???????????????????? */
5400 
JX_enable_cursor_keys(void)5401 static void  JX_enable_cursor_keys(void)  /*{{{*/
5402 {
5403 }
5404 
5405 /*}}}*/
5406 
5407 static void
jGtkSetFGBGColor(GtkWidget * w,int c)5408 jGtkSetFGBGColor( GtkWidget *w, int c )
5409 {
5410    /* colorChangeFlag = 1; */
5411    gtk_widget_modify_fg( w, GTK_STATE_NORMAL,      DefaultGtkGCInfo[c].fg );
5412    gtk_widget_modify_fg( w, GTK_STATE_ACTIVE,      DefaultGtkGCInfo[c].fg );
5413    gtk_widget_modify_fg( w, GTK_STATE_PRELIGHT,    DefaultGtkGCInfo[c].fg );
5414    gtk_widget_modify_fg( w, GTK_STATE_SELECTED,    DefaultGtkGCInfo[c].fg );
5415    gtk_widget_modify_fg( w, GTK_STATE_INSENSITIVE, DefaultGtkGCInfo[c].fg );
5416 
5417    gtk_widget_modify_bg( w, GTK_STATE_NORMAL,      DefaultGtkGCInfo[c].bg );
5418    gtk_widget_modify_bg( w, GTK_STATE_ACTIVE,      DefaultGtkGCInfo[c].bg );
5419    gtk_widget_modify_bg( w, GTK_STATE_PRELIGHT,    DefaultGtkGCInfo[c].bg );
5420    gtk_widget_modify_bg( w, GTK_STATE_SELECTED,    DefaultGtkGCInfo[c].bg );
5421    gtk_widget_modify_bg( w, GTK_STATE_INSENSITIVE, DefaultGtkGCInfo[c].bg );
5422    /* colorChangeFlag = 0; */
5423 }
5424 
5425 /************************************
5426 * JX_cls
5427 *
5428 * group: interface
5429 *
5430 *
5431 * debug print: "\n"
5432 *
5433 ************************************/
5434 
5435 static void
JX_cls(void)5436 JX_cls( void )  /*{{{*/
5437 {
5438    GtkSubWinType *sw = JGtkWin->subWins;
5439    GtkSubWinType *swBeg = sw;
5440 
5441    if ( !sw ) return;
5442 
5443    if (No_XEvents) return;
5444 
5445    if ( !doCLS ) return;
5446 
5447    if ( JGtkWin->window_mapped == 0) return;
5448 
5449    do
5450      {
5451       /* gdk_draw_rectangle( sw->edWin, sw->edWin->style->white_gc, 1, 0, 0, xxx, yyy ); */
5452       /* gdk_draw_rectangle( sw->stWin, sw->stWin->style->white_gc, 1, 0, 0, xxx, yyy ); */
5453 	if ( sw->edWin->window )
5454 	  {
5455 	     if ( doColorSetup )
5456 	       jGtkSetFGBGColor( sw->edWin, JNORMAL_COLOR );
5457 	     gdk_window_clear( sw->edWin->window );
5458 	  }
5459 	else
5460 	  {
5461 	 /* Dbp1( "EdWin NULL should not occur!!!\n", 1 ); */
5462 	 /********
5463 	 printWidgetWinXRef();
5464 	 printSubWins();
5465 	 ******/
5466 	  }
5467 
5468 	if ( sw->stWin->window )
5469 	  {
5470 	     if ( doColorSetup )
5471 	       jGtkSetFGBGColor( sw->stWin, JNORMAL_COLOR );
5472 	     gdk_window_clear( sw->stWin->window );
5473 	  }
5474 	else
5475 	  {
5476 	 /* Dbp1( "StWin NULL should not occur!!!\n", 1 ); */
5477 	 /*******
5478 	 printWidgetWinXRef();
5479 	 printSubWins();
5480 	 ******/
5481 	  }
5482 	sw = sw->next;
5483      }
5484    while ( sw != swBeg );
5485 
5486    /********
5487    gdk_draw_rectangle( JGtkWin->appWDrawArea->window, JGtkWin->appWDrawArea->style->white_gc, 1,
5488     		       0, 0, JGtkWin->width, JGtkWin->height );
5489    *******/
5490 }
5491 
5492 /*}}}*/
5493 
5494 /* This routine is called from S-Lang inner interpreter.  It serves
5495    as a poor mans version of an interrupt 9 handler */
5496 /************************************
5497 * xjed_check_kbd
5498 *
5499 * group: interface
5500 *
5501 *
5502 * debug print:
5503 *
5504 *
5505 ************************************/
5506 
5507 static void
xjed_check_kbd(void)5508 xjed_check_kbd( void )  /*{{{*/
5509 {
5510    char buf[64];
5511    int n;
5512    register char *b, *bmax;
5513 
5514    if (Batch || No_XEvents) return;
5515 
5516    while ( jGtkPending() )
5517      {
5518       /* printf( "File: %s Line: %d xjed_check_kbd before\n", __FILE__, __LINE__ ); */
5519 
5520 	if (X_process_events (0, buf, sizeof (buf), &n) == 0) continue;
5521 
5522       /* printf( "File: %s Line: %d xjed_check_kbd after\n", __FILE__, __LINE__ ); */
5523 
5524 	b = buf; bmax = b + n;
5525 	while (b < bmax)
5526 	  {
5527 	     if ( *b == (char) Jed_Abort_Char )
5528 	       {
5529 		  if ( Ignore_User_Abort == 0 )
5530 		    SLang_set_error (USER_BREAK);
5531 		  if ( b != buf ) buffer_keystring (buf, (int) (b - buf));
5532 		  SLKeyBoard_Quit = 1;
5533 	    /* Dbp2( "SLang_get_error: %d, USER_BREAK: %d\n", SLang_get_error(), USER_BREAK ); */
5534 		  break;
5535 	       }
5536 	     b++;
5537 	  }
5538 	if (!SLKeyBoard_Quit) buffer_keystring (buf, n);
5539      }
5540 }
5541 
5542 /*}}}*/
5543 
5544 /************************************
5545 * xjed_suspend
5546 *
5547 * group: interface
5548 *
5549 *
5550 * debug print:
5551 *
5552 *
5553 ************************************/
5554 
5555 static void
xjed_suspend(void)5556 xjed_suspend( void )  /*{{{*/
5557 {
5558    if ( No_XEvents ) return;
5559    /* if ( XWin->focus ) */
5560    if ( JGtkWin->focus )
5561      {
5562      }
5563    else
5564      {
5565       /* The window doesn't have focus which means that this was most
5566        * likely called by pressing Ctrl-Z from another window.
5567        */
5568 	fprintf (stderr, "jed stopping\n");
5569 #ifdef SIGSTOP
5570 	kill (0, SIGSTOP);
5571 #endif
5572       /* sys_suspend (); */
5573      }
5574 }
5575 
5576 /*}}}*/
5577 
5578 /************************************
5579 * set_window_name
5580 *
5581 * debug print: "Name: |%s|\n", s
5582 *
5583 ************************************/
5584 
5585 static void
set_window_name(char * s)5586 set_window_name( char *s ) /*{{{*/
5587 {
5588    if ( Batch ) return;
5589    if ( JGtkWin->appW )
5590      gtk_window_set_title( GTK_WINDOW( JGtkWin->appW ), s );
5591    /* XStoreName (This_XDisplay, XWin->w, s); */
5592 }
5593 
5594 /************************************
5595 * set_icon_name
5596 *
5597 * debug print: "Icon file name: |%s|\n", s
5598 *
5599 ************************************/
5600 
5601 static void
set_icon_name(char * s)5602 set_icon_name( char *s ) /*{{{*/
5603 {
5604    if ( Batch ) return;
5605    if ( JGtkWin->appW )
5606      gtk_window_set_default_icon_from_file( s, NULL );
5607 
5608    /* XSetIconName(This_XDisplay, XWin->w, s); */
5609 }
5610 
5611 /************************************
5612 * setupGtkColor
5613 *
5614 * group:
5615 *
5616 *
5617 * debug print:
5618 *
5619 *
5620 ************************************/
5621 
5622 static char *
setupGtkColor(char * colName,GdkColor ** oldColP,char * defColName,GdkColor * defCol)5623 setupGtkColor( char *colName, GdkColor **oldColP, char *defColName, GdkColor *defCol )
5624 {
5625    char *newName;
5626 
5627    if ( *oldColP )
5628      {
5629 	SLfree( ( char * ) *oldColP );
5630      }
5631    *oldColP = ( GdkColor * ) SLmalloc( sizeof( GdkColor ) );
5632 
5633    if ( colName )
5634      {
5635 	if ( strcmp( colName, "default" ) )
5636 	  {
5637 	     if ( !strncmp( colName, "bright", 6 ) )
5638 	       {
5639 		  colName += 6;
5640 	       }
5641 
5642 	     if ( gdk_color_parse( colName, *oldColP ) )
5643 	       {
5644 		  newName = SLmalloc( strlen( colName ) + 1 );
5645 		  strcpy( newName, colName );
5646 		  gdk_colormap_alloc_color( JGtkWin->colormap,
5647 					    *oldColP,
5648 					    1, 1 );
5649 	       }
5650 	     else
5651 	       {
5652 		  newName = SLmalloc( strlen( defColName ) + 1 );
5653 		  strcpy( newName, defColName );
5654 		  memcpy( *oldColP, defCol, sizeof( GdkColor ) );
5655 	       }
5656 	  }
5657 	else
5658 	  {
5659 	     newName = SLmalloc( strlen( defColName ) + 1 );
5660 	     strcpy( newName, defColName );
5661 	     memcpy( *oldColP, defCol, sizeof( GdkColor ) );
5662 	  }
5663      }
5664    else
5665      {
5666 	newName = SLmalloc( strlen( defColName ) + 1 );
5667 	strcpy( newName, defColName );
5668 	memcpy( *oldColP, defCol, sizeof( GdkColor ) );
5669      }
5670 
5671    return( newName );
5672 }
5673 
5674 /************************************
5675 * setupAndParseGtkColors
5676 *
5677 * group:
5678 *
5679 *
5680 * debug print:
5681 *
5682 *
5683 ************************************/
5684 
5685 static int
setupAndParseGtkColors(void)5686 setupAndParseGtkColors(void)
5687 {
5688    int i;
5689    char *savName;
5690    GdkColor *fgCol, *bgCol;
5691    GCGtkInfoType   *savGtkGCInfo;
5692 
5693    savGtkGCInfo = DefaultGtkGCInfo;
5694 
5695    JGtkWin->textGC = DefaultGtkGCInfo;
5696 
5697    fgCol = ( GdkColor * ) SLmalloc( sizeof( GdkColor ) );
5698    bgCol = ( GdkColor * ) SLmalloc( sizeof( GdkColor ) );
5699 
5700    fgCol->pixel = 0; fgCol->red = 0x0;    fgCol->green = 0x0;    fgCol->blue = 0x0;
5701    bgCol->pixel = 0; bgCol->red = 0xffff; bgCol->green = 0xffff; bgCol->blue = 0xffff;
5702 
5703    JGtkWin->textGC->fg = fgCol;
5704    JGtkWin->textGC->bg = bgCol;
5705 
5706    savName = JGtkWin->textGC->fgName;
5707    JGtkWin->textGC->fgName = SLmalloc( strlen( savName ) + 1 );
5708    strcpy( JGtkWin->textGC->fgName, savName );
5709 
5710    savName = JGtkWin->textGC->bgName;
5711    JGtkWin->textGC->bgName = SLmalloc( strlen( savName ) + 1 );
5712    strcpy( JGtkWin->textGC->bgName, savName );
5713 
5714    for ( i = 1; i < JMAX_COLORS; ++i )
5715      {
5716       /* printf( "file: %s line: %d: i: %d\n", __FILE__, __LINE__, i ); */
5717       /* printf( "FG: %s, BG: %s\n", DefaultGtkGCInfo[i].fgName, DefaultGtkGCInfo[i].bgName ); */
5718 
5719 	DefaultGtkGCInfo[i].fgName = setupGtkColor( DefaultGtkGCInfo[i].fgName,
5720 						    &DefaultGtkGCInfo[i].fg,
5721 						    JGtkWin->textGC->fgName,
5722 						    JGtkWin->textGC->fg );
5723 
5724 	DefaultGtkGCInfo[i].bgName = setupGtkColor( DefaultGtkGCInfo[i].bgName,
5725 						    &DefaultGtkGCInfo[i].bg,
5726 						    JGtkWin->textGC->bgName,
5727 						    JGtkWin->textGC->bg );
5728      }
5729    return( 0 );
5730 }
5731 
5732 /* #if 0 */
5733 
5734 /************************************
5735 * setup_and_parse_colors
5736 *
5737 * group:
5738 *
5739 *
5740 * debug print:
5741 *
5742 *
5743 ************************************/
5744 #if 0
5745 static int
5746 setup_and_parse_colors (void ) /*{{{*/
5747 {
5748    unsigned long fg, bg, tmp;
5749    char *fg_name, *bg_name;
5750    int i;
5751 
5752    setupAndParseGtkColors();
5753 
5754    return 0;
5755 }
5756 
5757 /*}}}*/
5758 #endif
5759 
5760 /* #endif */
5761 
5762 /* ??????????????? */
5763 
5764 /************************************
5765 * set_mouse_color
5766 *
5767 * group:
5768 *
5769 *
5770 * debug print:
5771 *
5772 *
5773 ************************************/
5774 
5775 static void
set_mouse_color(char * fgc,char * bgc)5776 set_mouse_color( char *fgc, char *bgc ) /*{{{*/
5777 {
5778    XColor xfg, xbg;
5779 
5780 }
5781 
5782 /************************************
5783 * create_XWindow
5784 *
5785 * group:
5786 *
5787 *
5788 * debug print:
5789 *
5790 *
5791 ************************************/
5792 
5793 static void
create_XWindow(void)5794 create_XWindow(void)  /*{{{*/
5795 {
5796    int i;
5797    int bdr, x, y, flags;
5798    unsigned int width, height;
5799    XSizeHints sizehint;
5800    XClassHint xcls;
5801    XWMHints wmhint;
5802    long key_event_type;
5803    FilterEventData *tmpData;
5804    GdkDisplay *tmpDisp;
5805 
5806    thisEventBuffer =
5807      tmpData = ( FilterEventData * ) SLmalloc( sizeof( FilterEventData ) );
5808 
5809    /* tmpData->win =          win; */
5810    /* tmpData->evList =       NULL; */
5811    /* tmpData->numEv =        0; */
5812    tmpData->jXGtkEvList =  NULL;
5813    tmpData->jXGtkNumEv  =  0;
5814 
5815    tmpDisp = gdk_display_get_default();
5816 
5817    JGtkWin->height = /* win->height = */ 200;
5818    JGtkWin->width  = /* win->width = */  200;
5819 
5820    createGtkMainWindow();
5821 
5822    JGtkWin->numWin = 0;
5823    JGtkWin->gutSize = 0;
5824    JGtkWin->hCheck = 0;
5825    JGtkWin->inGridHeight = 0;
5826    JGtkWin->inGridHeightPixel = 0;
5827    JGtkWin->inGridWidthPixel = 0;
5828    JGtkWin->subWins = NULL;
5829    JGtkWin->miniWinSW = NULL;
5830 
5831    JGtkWin->maxEdHeight = MAX_EDHEIGHT;
5832    JGtkWin->maxEdWidth  = MAX_EDWIDTH;
5833 
5834    JGtkWin->widgetWinXRef = ( GtkSubWinType *** ) SLmalloc( sizeof( GtkSubWinType ** ) * JGtkWin->maxEdHeight );
5835 
5836    /* printf( "JGtkWin->maxEdHeight: %d\n", JGtkWin->maxEdHeight ); */
5837 
5838    for ( ; JGtkWin->maxEdHeight; --JGtkWin->maxEdHeight )
5839      {
5840 	JGtkWin->widgetWinXRef[JGtkWin->maxEdHeight - 1] = ( GtkSubWinType ** )
5841 	  SLmalloc( sizeof( GtkSubWinType * ) * JGtkWin->maxEdWidth );
5842 #if 0
5843 	for ( i = 0; i < JGtkWin->maxEdWidth; ++i )
5844 	  {
5845 	 /* printf( "JGtkWin->maxEdHeigth: %d, i: %d\n", JGtkWin->maxEdHeight, i ); */
5846 	 /* printf( "JGtkWin->widgetWinXRef: %p\n", JGtkWin->widgetWinXRef ); */
5847 	     JGtkWin->widgetWinXRef[JGtkWin->maxEdHeight - 1][i] = NULL;
5848 	  }
5849 #endif
5850      }
5851 
5852    modWidgetWinXRef( JGtkWin->widgetWinXRef, NULL, 0, 0, JGtkWin->maxEdWidth, JGtkWin->maxEdHeight );
5853 
5854    JGtkWin->maxEdHeight = MAX_EDHEIGHT;
5855 #if 0
5856    Return( ( Window ) 5 /* DUMMY */ );
5857 #endif
5858 }
5859 
5860 /*}}}*/
5861 
jGtkAttachMenubar(GtkWidget * mb)5862 void jGtkAttachMenubar( GtkWidget *mb )
5863 {
5864    if ( mb == JGtkWin->appWMenuBar ) return;
5865 
5866    gtk_box_pack_start( GTK_BOX( JGtkWin->appWGrid ), mb, False, False, 0 );
5867    gtk_box_reorder_child( GTK_BOX( JGtkWin->appWGrid ), mb, 1 );
5868    if ( JGtkWin->appWMenuBar )
5869      gtk_container_remove( GTK_CONTAINER( JGtkWin->appWGrid ), JGtkWin->appWMenuBar );
5870    JGtkWin->appWMenuBar = mb;
5871    gtk_widget_show_all( mb );
5872 }
5873 
5874 /************************************
5875 * jGtkAddToolbar
5876 *
5877 * debug print: "tb: %p, where: %d\n", tb, where
5878 *
5879 ************************************/
5880 
jGtkAddToolbar(GtkWidget * tb,int where)5881 void jGtkAddToolbar( GtkWidget *tb, int where )
5882 {
5883    int n;
5884 
5885    if ( !GTK_IS_CONTAINER( JGtkWin->appWTbGrid ) )
5886      {
5887       /* Dbp1( "Internal error: appWTbGrid: %p not a container!!\n", JGtkWin->appWTbGrid ); */
5888      }
5889 
5890    if ( where != -1 )
5891      {
5892 	n = g_list_length( gtk_container_get_children( GTK_CONTAINER( JGtkWin->appWTbGrid ) ) );
5893 
5894 	if ( where > n ) where = n;
5895      }
5896 
5897    /* Dbp1( "Where: %d\n", where ); */
5898 
5899    gtk_box_pack_start( GTK_BOX( JGtkWin->appWTbGrid ), tb, False, False, 0 );
5900 
5901    gtk_box_reorder_child( GTK_BOX( JGtkWin->appWTbGrid ), tb, where );
5902    gtk_widget_show_all( tb );
5903 }
5904 
5905 /************************************
5906 * x_err_handler
5907 *
5908 * group:
5909 *
5910 *
5911 * debug print:
5912 *
5913 *
5914 ************************************/
5915 #if 0
5916 static int
5917 x_err_handler (Display *d, XErrorEvent *ev ) /*{{{*/
5918 {
5919    char errmsg[256];
5920 
5921    return 1;
5922 }
5923 
5924 /*}}}*/
5925 #endif
5926 /************************************
5927 * x_ioerr_handler
5928 *
5929 * group:
5930 *
5931 *
5932 * debug print:
5933 *
5934 *
5935 ************************************/
5936 #if 0
5937 static int
5938 x_ioerr_handler (Display *d ) /*{{{*/
5939 {
5940    No_XEvents = 1;
5941    exit_error("XWindows IO error", 0);
5942    return d == NULL;  /* just use d to avoid a warning */
5943 }
5944 
5945 /*}}}*/
5946 #endif
5947 
5948 /************************************
5949 * open_Xdisplay
5950 *
5951 * group:
5952 *
5953 *
5954 * debug print:
5955 *
5956 *
5957 ************************************/
5958 
5959 static int
open_Xdisplay(void)5960 open_Xdisplay (void ) /*{{{*/
5961 {
5962    char dname [256];
5963    char *n;
5964    int numArg = 0;
5965 
5966    memset( (char *) JGtkWin, 0, sizeof( JGtkWinType ));
5967 
5968    /* gtk_init( &numArg, NULL ); */
5969 
5970    JGtkWin->display = gdk_display_get_default();
5971 
5972    JGtkWin->screen = gdk_display_get_default_screen( JGtkWin->display );
5973    JGtkWin->colormap = gdk_screen_get_default_colormap( JGtkWin->screen );
5974 
5975 #define FONT "monospace 6"
5976 
5977    JGtkWin->fontName = SLmalloc( strlen( FONT ) + 1 );
5978    strcpy( JGtkWin->fontName, FONT );
5979 
5980    JGtkWin->XDisplay = gdk_x11_display_get_xdisplay( JGtkWin->display );
5981 
5982    return 1;
5983 }
5984 
5985 #ifdef SIXTEEN_BIT_SYSTEM
5986 # define VFILE_BUF_SIZE 1024
5987 #else
5988 # define VFILE_BUF_SIZE 4096
5989 #endif
5990 
5991 static char *
getLibFile(char * file)5992 getLibFile( char *file ) /*{{{*/
5993 {
5994    static char retFile[JED_MAX_PATH_LEN];
5995    char libfsl[JED_MAX_PATH_LEN], libfslc[JED_MAX_PATH_LEN];
5996    char *lib, *tmpLib, *type, *libf;
5997    unsigned int n;
5998 
5999    /* Dbp1( "file: |%s|\n", file ); */
6000 
6001    libf = file;
6002    /* lib = Jed_Library; */
6003    lib = NULL;
6004 
6005    if ( ( 0 == strncmp( file, "./", 2 ) ) ||
6006 #ifdef IBMPC_SYSTEM
6007 	( 0 == strncmp( file, ".\\", 2 ) ) ||
6008 	( 0 == strncmp( file, "..\\", 3 ) ) ||
6009 #endif
6010         ( 0 == strncmp( file, "../", 3 ) ) )
6011      {
6012 	if ( NULL == ( lib = jed_get_cwd() ) )
6013 	  lib = "";
6014      }
6015    else if ( SLpath_is_absolute_path( file ) )
6016      lib = "";
6017    /**************
6018    else if ( ( lib == NULL ) || ( *lib == 0 ) )
6019      exit_error( "JED_ROOT environment variable needs set.", 0 );
6020    ***************/
6021    else
6022      {
6023 	tmpLib = SLpath_get_load_path ();      /* SLstring */
6024 	if ((tmpLib == NULL) || (*tmpLib == 0))
6025 	  exit_error("The JED_ROOT environment variable needs set.", 0);
6026 	else
6027 	  {
6028 	     lib = ( char * ) SLmalloc( strlen( tmpLib ) + 1 );
6029 	     strcpy( lib, tmpLib );
6030 	  }
6031      }
6032 
6033    /* Dbp1( "Lib: |%s|\n", lib ); */
6034 
6035    n = 0;
6036    while ( 0 == SLextract_list_element (lib, n, ',', libfsl, sizeof( libfsl ) ) )
6037      {
6038 	n++;
6039 
6040 	fixup_dir(libfsl);
6041 	safe_strcat (libfsl, file, sizeof (libfsl));
6042 	safe_strcpy (libfsl, jed_standardize_filename_static(libfsl), sizeof (libfsl));
6043 
6044 	libf = libfsl;
6045 
6046 	if ( ( 1 == file_status( libf ) ) )
6047 	  break;
6048 
6049 	libf = NULL;
6050      }
6051 
6052    if ( libf )
6053      {
6054 	safe_strcpy( retFile, libf, sizeof( retFile ) );
6055 
6056 	return( retFile );
6057      }
6058    else
6059      {
6060 	return( NULL );
6061      }
6062 }
6063 
6064 /*}}}*/
6065 
6066 #define JGTK_NUM_KEYFILES 2
6067 
6068 #define JGTK_KEYFILE_BASE_NAME   "gtkjed.ini"
6069 #define JGTK_KEYFILE_HOME_NAME   "~/." JGTK_KEYFILE_BASE_NAME
6070 
6071 static GKeyFile **
getKeyFiles(void)6072 getKeyFiles(void)
6073 {
6074    int i = 0;
6075    char *fn;
6076    char *expFn;
6077    GKeyFile **kf = ( GKeyFile ** ) SLmalloc( sizeof( GKeyFile * ) * ( JGTK_NUM_KEYFILES + 1 ) );
6078 
6079    kf[i] = g_key_file_new();
6080 
6081    fn = getLibFile( JGTK_KEYFILE_BASE_NAME );
6082 
6083    /* Dbp1( "NewTest: |%s|\n", fn ? fn : "(NULL)" ); */
6084 
6085    if ( fn )
6086      {
6087 	if ( g_key_file_load_from_file( kf[i], fn, G_KEY_FILE_KEEP_TRANSLATIONS |
6088 					G_KEY_FILE_KEEP_COMMENTS,
6089 					NULL ) )
6090 	  {
6091 	     i++;
6092 	     kf[i] = g_key_file_new();
6093 	  }
6094      }
6095 
6096    fn = jed_expand_filename( SLmake_string( JGTK_KEYFILE_HOME_NAME ) );
6097 
6098    /* Dbp1( "Begin: %s!!\n", fn ); */
6099 
6100    if ( g_key_file_load_from_file( kf[i], fn,
6101 				   G_KEY_FILE_KEEP_TRANSLATIONS |
6102 				   G_KEY_FILE_KEEP_COMMENTS, NULL ) )
6103      {
6104 	i++;
6105      }
6106    else
6107      {
6108 	g_key_file_free( kf[i] );
6109      }
6110 
6111    /* Dbp1( "NewTest01: %d\n", i ); */
6112 
6113    kf[i] = NULL;
6114    return( kf );
6115 }
6116 
6117 static void
getGtkDefaults(void)6118 getGtkDefaults(void)
6119 {
6120    XWindow_Arg_Type *jGtkArgs = jGtkArgList + XARG_START;
6121    GKeyFile **kfs = getKeyFiles();
6122    GKeyFile **tmpKfs;
6123 
6124    if ( *kfs )
6125      {
6126 	while ( jGtkArgs->name != NULL )
6127 	  {
6128 	     if ( jGtkArgs->dflt == NULL )
6129 	       {
6130 		  jGtkArgs++;
6131 		  continue;
6132 	       }
6133 
6134 	     if ( jGtkArgs->type != VOID_TYPE  &&
6135 		  jGtkArgs->value == NULL )
6136 	       {
6137 		  static char *classNames[] =
6138 		    {
6139 		       "UGtkjed", "UGtkJed", "ugtkjed", NULL
6140 		    };
6141 		  char *p, *cn;
6142 		  char **cnp;
6143 
6144 		  p = NULL;
6145 		  if ( Jed_UTF8_Mode )
6146 		    {
6147 		       cnp = classNames;
6148 		       while( NULL != ( cn = *cnp++ ) )
6149 			 {
6150 			    tmpKfs = kfs;
6151 			    while ( *tmpKfs )
6152 			      {
6153 				 p = g_key_file_get_string( *tmpKfs, cn, jGtkArgs->name, NULL );
6154 				 if ( p ) break;
6155 				 tmpKfs++;
6156 			      }
6157 			    if ( p != NULL )
6158 			      break;
6159 			 }
6160 		    }
6161 
6162 		  if ( p == NULL )
6163 		    {
6164 		       cnp = classNames;
6165 		       while ( NULL != ( cn = *cnp++ ) )
6166 			 {
6167 			    cn++; /* Skip leading U */
6168 			    tmpKfs = kfs;
6169 			    while ( *tmpKfs )
6170 			      {
6171 				 p = g_key_file_get_string( *tmpKfs, cn, jGtkArgs->name, NULL );
6172 				 if ( p ) break;
6173 				 tmpKfs++;
6174 			      }
6175 			    if ( p != NULL )
6176 			      break;
6177 			 }
6178 		    }
6179 
6180 		  if ( p == NULL )
6181 		    {
6182 		       tmpKfs = kfs;
6183 		       while ( *tmpKfs )
6184 			 {
6185 			    p = g_key_file_get_string( *tmpKfs, "UXTerm", jGtkArgs->name, NULL );
6186 			    if ( p ) break;
6187 			    tmpKfs++;
6188 			 }
6189 		       if ( p == NULL )
6190 			 {
6191 			    tmpKfs = kfs;
6192 			    while ( *tmpKfs )
6193 			      {
6194 				 p = g_key_file_get_string( *tmpKfs, "XTerm", jGtkArgs->name, NULL );
6195 				 if ( p ) break;
6196 				 tmpKfs++;
6197 			      }
6198 			 }
6199 		    }
6200 
6201 		  if ( p != NULL )
6202 		    jGtkArgs->value = p;
6203 	       }
6204 
6205 	     if ( jGtkArgs->value != NULL )
6206 	       *jGtkArgs->dflt = jGtkArgs->value;
6207 
6208 	 /* Dbp2( "Arg: |%s|: Value: |%s|\n", jGtkArgs->name, jGtkArgs->value ? jGtkArgs->value : "(NULL)" ); */
6209 
6210 	     jGtkArgs++;
6211 	  }
6212      }
6213 }
6214 
6215 /* returns socket descriptor */
6216 /************************************
6217 * init_Xdisplay
6218 *
6219 * group: interface
6220 *
6221 *
6222 * debug print:
6223 *
6224 *
6225 ************************************/
6226 
6227 static int
init_Xdisplay(void)6228 init_Xdisplay (void ) /*{{{*/
6229 {
6230 #ifdef XJED_USE_R6IM
6231    setlocale(LC_ALL, "");
6232 #endif
6233 
6234    if (jGtkArgList[JGTK_ARG_NAME].value != NULL)
6235      {
6236 	This_App_Name = jGtkArgList[JGTK_ARG_NAME].value;
6237      }
6238 
6239    /* Db; */
6240 
6241    getGtkDefaults();
6242 
6243    JGtkWin->border = atoi(This_Internal_Border_Name);
6244    if ( JGtkWin->border < 0)
6245      JGtkWin->border = 0;
6246 
6247 #if XJED_HAS_XRENDERFONT
6248 # if 0
6249    /* if a parameter to -fs was supplied, we assume the user wants XFT */
6250    if (strlen(This_Face_Size))
6251      {
6252 	if ( ( JGtkWin->face_size = atof( This_Face_Size ) ) <= 0 )
6253 	  JGtkWin->face_size = 0;
6254      }
6255    else
6256      /* there was no -fs, so we don't do anything */
6257      JGtkWin->face_size = 0;
6258 
6259     /* make sure that XWin->xftdraw is null in any case */
6260    JGtkWin->xftdraw = NULL;
6261 # endif
6262 #endif
6263 
6264    if ( -1 == setupAndParseGtkColors() )		       /* This allocs and parses colors */
6265      exit (1);
6266 
6267    create_XWindow();
6268 
6269    JGtkWin->window_mapped = 1;
6270 
6271    return ConnectionNumber( JGtkWin->XDisplay );
6272 }
6273 
6274 /*}}}*/
6275 
6276 /************************************
6277 * reset_Xdisplay
6278 *
6279 * group: interface
6280 *
6281 *
6282 * debug print:
6283 *
6284 *
6285 ************************************/
6286 
6287 static void
reset_Xdisplay(void)6288 reset_Xdisplay (void ) /*{{{*/
6289 {
6290 }
6291 
6292 /*}}}*/
6293 
6294 #define UPCSE(x)  (((x) <= 'z') && ((x) >= 'a') ? (x) - 32 : (x))
6295 /************************************
6296 * myXstrcmp
6297 *
6298 * group:
6299 *
6300 *
6301 * debug print:
6302 *
6303 *
6304 ************************************/
6305 
6306 static int
myXstrcmp(char * a,char * b)6307 myXstrcmp(char *a, char *b)  /*{{{*/
6308 {
6309    register char cha, chb;
6310    /* do simple comparison */
6311 
6312    cha = *a++;  chb = *b++;
6313    if ((cha != chb) && (UPCSE(cha) != UPCSE(chb))) return 0;
6314    while ((cha = *a++), (chb = *b++), (cha && chb) != 0)
6315      {
6316 	if (cha != chb) return 0;
6317      }
6318 
6319    return (cha == chb);
6320 }
6321 
6322 /*}}}*/
6323 
6324 #define STREQS(a, b) myXstrcmp(a, b)
6325 /************************************
6326 * X_eval_command_line
6327 *
6328 * group:
6329 *
6330 *
6331 * debug print:
6332 *
6333 *
6334 ************************************/
6335 
6336 static int
X_eval_command_line(int argc,char ** argv)6337 X_eval_command_line (int argc, char **argv ) /*{{{*/
6338 {
6339    char *arg;
6340    int i;
6341    int cpyArgc = argc;
6342    char **cpyArgv = ( char ** ) SLmalloc ( (1+argc) * sizeof( char * ) );
6343    int n;
6344    XWindow_Arg_Type *opt;
6345 
6346    if (cpyArgv == NULL)
6347      return -1;
6348 
6349    /******************************
6350    * Create a copy of argv because gtk_init might modify if
6351    ******************************/
6352 
6353    for ( i = 0; i < argc; ++i )
6354      {
6355 	cpyArgv[i] = SLmalloc( 1+strlen( argv[i] ) );
6356 	if (cpyArgv[i] == NULL)
6357 	  return -1;
6358 
6359 	strcpy( cpyArgv[i], argv[i] );
6360      }
6361    cpyArgv[argc] = NULL;
6362 
6363    gtk_init( &cpyArgc, &cpyArgv );
6364 
6365    /****************************
6366    * Overide original argv, because I don't know
6367    * what gtk did to the original cpyArgv/argv
6368    * array (might it be freed?).
6369    ****************************/
6370 
6371    n = argc - cpyArgc;
6372 
6373    argv[0] = cpyArgv[0]; /* program name */
6374 
6375    for ( i = 1; i < cpyArgc; ++i )
6376      { /*****************************
6377 	* Recreate the format jed likes to process
6378 	* argc and argv (this means unprocessed arguments
6379 	* are left at the end of argv).
6380 	******************************/
6381 	argv[i + n] = cpyArgv[i];
6382      }
6383 
6384    for ( i = n + 1; i < argc; ++i )
6385      {
6386 	arg = argv[i];
6387 	if (*arg != '-') break;
6388 	if ( 0 == strcmp( "--debug-xjed", arg ) ||
6389 	     0 == strcmp( "--debug-gtkjed", arg ) )
6390 	  {
6391 	     Debug_gtkjed = 1;
6392 	     continue;
6393 	  }
6394 
6395 	arg++;
6396 	opt = jGtkArgList;
6397 	while ( opt->name != NULL )
6398 	  {
6399 	     if ( STREQS(opt->name, arg )
6400 		  || (( opt->name1 != NULL) && STREQS(opt->name1, arg ))) break;
6401 	     opt++;
6402 	  }
6403 
6404 	if ( opt->name == NULL ) break;
6405 
6406 	if ( opt->type == VOID_TYPE ) opt->value = "on";
6407 	else if ( i + 1 < argc )
6408 	  {
6409 	     i++;
6410 	     opt->value = argv[i];
6411 	  }
6412 	else break;
6413      }
6414 
6415    /*******************
6416    if ( argc > 1 )
6417      {
6418       Return( argc - 1 );
6419       }
6420    else
6421      {
6422       Return( argc );
6423       }
6424    ******************/
6425    return( i );
6426 }
6427 
6428 /*}}}*/
6429 
6430 /************************************
6431 * set_border_color
6432 *
6433 * group:
6434 *
6435 *
6436 * debug print:
6437 *
6438 *
6439 ************************************/
6440 
6441 static void
set_border_color(char * fgc,char * bgc)6442 set_border_color (char *fgc, char *bgc ) /*{{{*/
6443 {
6444    XColor xfg;
6445    unsigned int bdr = atoi(bgc);
6446 
6447 }
6448 
6449 /*}}}*/
6450 
6451 /************************************
6452 * JX_set_mono
6453 *
6454 * group:
6455 *
6456 *
6457 * debug print:
6458 *
6459 *
6460 ************************************/
6461 
6462 static JX_SETXXX_RETURN_TYPE
JX_set_mono(int obj_unused,char * unused,SLtt_Char_Type c_unused)6463 JX_set_mono (int obj_unused, char *unused, SLtt_Char_Type c_unused )
6464 {
6465    (void) obj_unused;
6466    (void) unused;
6467    (void) c_unused;
6468    return JX_SETXXX_RETURN_VAL;
6469 }
6470 
6471 /************************************
6472 * jGtkSetColor
6473 *
6474 * group:
6475 *
6476 *
6477 * debug print:
6478 *
6479 *
6480 ************************************/
6481 
6482 static JX_SETXXX_RETURN_TYPE
jGtkSetColor(int i,char * what,char * fg,char * bg)6483 jGtkSetColor (int i, char *what, char *fg, char *bg )
6484 {
6485    char *savName;
6486    GdkColor *fgCol, *bgCol;
6487    GdkColor *savCol;
6488 
6489    /* printf( "JGtk_set_color: File: %s line: %d: i: %d FG: %s, BG: %s\n", __FILE__, __LINE__, i, fg, bg ); */
6490 
6491    if ( JGtkWin->appW == NULL)
6492      return JX_SETXXX_RETURN_VAL;
6493 
6494    if (!Term_Supports_Color)
6495      return JX_SETXXX_RETURN_VAL;
6496 
6497 #if SLANG_VERSION >= 10306
6498    SLsmg_touch_screen ();
6499 #endif
6500 
6501    if (i == -1)
6502      {
6503 	if ( !strcmp("mouse", what) )
6504 	  {
6505 	     set_mouse_color (fg, bg);
6506 	  }
6507 	else if (!strcmp("border", what))
6508 	  {
6509 	     set_border_color (fg, bg);
6510 	  }
6511 	return JX_SETXXX_RETURN_VAL;
6512      }
6513 
6514    savName = DefaultGtkGCInfo[i].fgName;
6515    DefaultGtkGCInfo[i].fgName = setupGtkColor( fg,
6516 					       &( DefaultGtkGCInfo[i].fg ),
6517 					       JGtkWin->textGC->fgName,
6518 					       JGtkWin->textGC->fg );
6519    SLfree( savName );
6520 
6521    savName = DefaultGtkGCInfo[i].bgName;
6522    DefaultGtkGCInfo[i].bgName = setupGtkColor( bg,
6523 					       &( DefaultGtkGCInfo[i].bg ),
6524 					       JGtkWin->textGC->bgName,
6525 					       JGtkWin->textGC->bg );
6526    SLfree( savName );
6527 
6528    return JX_SETXXX_RETURN_VAL;
6529 }
6530 
6531 /*}}}*/
6532 
6533 /************************************
6534 * JX_set_color
6535 *
6536 * group:
6537 *
6538 *
6539 * debug print:
6540 *
6541 *
6542 ************************************/
6543 
6544 static JX_SETXXX_RETURN_TYPE
JX_set_color(int i,char * what,char * fg,char * bg)6545 JX_set_color (int i, char *what, char *fg, char *bg )
6546 {
6547 
6548    jGtkSetColor( i, what, fg, bg );
6549 
6550    return JX_SETXXX_RETURN_VAL;
6551 }
6552 
6553 /*}}}*/
6554 
6555 /************************************
6556 * x_warp_pointer
6557 *
6558 * group:
6559 *
6560 *
6561 * debug print:
6562 *
6563 *
6564 ************************************/
6565 
6566 static void
x_warp_pointer(void)6567 x_warp_pointer (void ) /*{{{*/
6568 {
6569    /* int x, y; */
6570    /* GtkWidget *w = getEdWinFromJedWin( JWindow ); */
6571    X_Warp_Pending = 1;
6572 
6573 #if 0
6574    if ( w )
6575      {
6576 	X_Warp_Pending = 1;
6577 
6578 	gdk_window_get_origin( w->window, &x, &y );
6579 
6580 	Dbp3( "Windows: %p, x: %d, y: %d\n", w->window, x, y );
6581 
6582 	x = JGtkWin->fontWidth*( JGtkWin->vis_curs_col + 0.5 ) + x;
6583 	y = JGtkWin->fontHeight*( JGtkWin->vis_curs_row - 0.5 ) + y;
6584 
6585 	Dbp3( "Windows: %p, x: %d, y: %d\n", w->window, x, y );
6586 
6587 	gdk_display_warp_pointer( gdk_drawable_get_display( ( GdkDrawable * ) w->window ),
6588 				  gdk_drawable_get_screen( ( GdkDrawable * ) w->window ),
6589 				  x, y );
6590      }
6591 #endif
6592 
6593 }
6594 
6595 /*}}}*/
6596 
6597 static void
jgtk_clear_clipboard(GtkClipboard * clb,gpointer data)6598 jgtk_clear_clipboard( GtkClipboard *clb,
6599 		      gpointer data )
6600 {
6601 }
6602 
6603 static void
jgtk_provide_clipboard(GtkClipboard * clb,GtkSelectionData * data,guint info,gpointer userData)6604 jgtk_provide_clipboard( GtkClipboard *clb,
6605 			GtkSelectionData *data,
6606 			guint info,
6607 			gpointer userData )
6608 {
6609    /* gtk_clipboard_set_text( clb, jgtkClipboardData, strlen( jgtkClipboardData ) ); */
6610    /* Dbp3( "ClipboardData: %p: len: %d, data: |%s|\n", jgtkClipboardData, strlen( jgtkClipboardData ), jgtkClipboardData ); */
6611    gtk_selection_data_set( data, gdk_atom_intern( "STRING", FALSE ), 8, jgtkClipboardData, strlen( jgtkClipboardData ) );
6612 }
6613 
6614 static void
jgtk_receive_clipboard_targets(GtkClipboard * clb,GdkAtom * atoms,gint n,gpointer data)6615 jgtk_receive_clipboard_targets( GtkClipboard *clb,
6616 				GdkAtom *atoms,
6617 				gint n,
6618 				gpointer data )
6619 {
6620    int i;
6621 
6622    /* Dbp2( "Clipboard can be provided with %d target types by atoms: %p\n", n, atoms ); */
6623 
6624    for ( i = 0; i < n; ++i )
6625      {
6626       /* Dbp2( "Target(%3d): |%s|\n", atoms + i, gdk_atom_name( atoms[i] ) ); */
6627      }
6628 
6629 }
6630 
6631 static void
jgtk_receive_clipboard(GtkClipboard * clb,const gchar * text,gpointer data)6632 jgtk_receive_clipboard( GtkClipboard *clb,
6633 			const gchar *text,
6634 			gpointer data )
6635 {
6636    /* Dbp1( "Text: |%s|\n", text ); */
6637    jed_insert_nbytes( text, strlen( text ) );
6638    update( NULL, 1, 0, 0 );
6639 }
6640 
6641 static int
jgtk_insert_clipboard(void)6642 jgtk_insert_clipboard(void)
6643 {
6644 
6645    gtk_clipboard_request_text( gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ),
6646 			       jgtk_receive_clipboard,
6647 			       NULL );
6648 
6649 #if 0
6650    gtk_clipboard_request_targets( gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ),
6651 				  jgtk_receive_clipboard_targets,
6652 				  NULL );
6653 #endif
6654    return( 0 );
6655 }
6656 
6657 static void
jgtk_region_2_clipboard(void)6658 jgtk_region_2_clipboard(void)
6659 {
6660    int nbytes;
6661    GdkAtom textAtom = gdk_atom_intern( "STRING", FALSE );
6662    static GtkTargetEntry tt
6663      =
6664      {
6665 	"STRING",
6666 	GTK_TARGET_SAME_WIDGET
6667 #if 0
6668 	| GTK_TARGET_OTHER_APP | GTK_TARGET_OTHER_WIDGET
6669 #endif
6670 	| GTK_TARGET_SAME_APP,
6671 	8
6672      };
6673 
6674    /*************
6675    gtk_clipboard_set_with_data( GtkClipboard *clb,
6676 				const GtkTargetEntry *targets,
6677 				guint n_targets,
6678 				GtkClipboardGetFunc gf: jgtk_provide_clipboard,
6679 				GtkClipboardClearFunc cf,
6680 				gpointer userData );
6681    **************/
6682    if ( jgtkClipboardData )
6683      {
6684 	SLfree( jgtkClipboardData );
6685      }
6686 
6687    jgtkClipboardData = make_buffer_substring( &nbytes );
6688 
6689    gtk_clipboard_set_with_data( gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ),
6690 				&tt,
6691 				1,
6692 				jgtk_provide_clipboard,
6693 				jgtk_clear_clipboard,
6694 				NULL );
6695 }
6696 
6697 /************************************
6698 * x_insert_selection
6699 *
6700 * group:
6701 *
6702 *
6703 * debug print:
6704 *
6705 *
6706 ************************************/
6707 
6708 static int
x_insert_selection(void)6709 x_insert_selection( void )
6710 {
6711    /* if ( gtkButtonEvent ) */
6712    /*  { */
6713    return( gtkInsertSelection() );
6714    /*    } */
6715    /* Return 0; */
6716 }
6717 
6718 /************************************
6719 * gtkInsertSelection
6720 *
6721 * group:
6722 *
6723 *
6724 * debug print:
6725 *
6726 *
6727 ************************************/
6728 
6729 static int
gtkInsertSelection(void)6730 gtkInsertSelection( void )
6731 {
6732    GdkAtom textAtom = gdk_atom_intern( "STRING", FALSE );
6733 
6734    /* printf( "File %s, Line %d: Insert gtk Selection!!!\n", __FILE__, __LINE__ ); */
6735 
6736    /***********
6737    gtk_selection_convert( JGtkWin->appWDrawArea, GDK_SELECTION_PRIMARY, textAtom,
6738 			  GDK_CURRENT_TIME );
6739    ********************/
6740 
6741    if ( JGtkWin->appWMiniW )
6742      {
6743 	gtk_selection_convert( JGtkWin->appWMiniW, GDK_SELECTION_PRIMARY, textAtom,
6744 			       GDK_CURRENT_TIME );
6745      }
6746 
6747    return( 0 );
6748 }
6749 
6750 /************************************
6751 * gtkSelectionReceive
6752 *
6753 * group:
6754 *
6755 *
6756 * debug print:
6757 *
6758 *
6759 ************************************/
6760 
6761 static void
gtkSelectionReceive(GtkWidget * w,GtkSelectionData * selData,gpointer usrData)6762 gtkSelectionReceive( GtkWidget *w,
6763 		     GtkSelectionData *selData,
6764 		     gpointer usrData )
6765 {
6766    GdkAtom textAtom = gdk_atom_intern( "STRING", FALSE );
6767    char *txt;
6768 
6769    if ( selData->length < 0 )
6770      {
6771       /* printf( "File %s, Line %d: Selection retrieval failed!!!\n", __FILE__, __LINE__ ); */
6772 	return;
6773      }
6774 
6775    if ( selData->type != textAtom )
6776      {
6777       /* printf( "File %s, Line %d: Selection was not return as STRING!!!\n", __FILE__, __LINE__ ); */
6778 	return;
6779      }
6780 
6781    txt = ( char * ) selData->data;
6782 
6783    jed_insert_nbytes( txt, selData->length );
6784 
6785    /* printf( "File %s, Line %d: Selectiontext returned:\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n%s<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n", __FILE__, __LINE__, txt ); */
6786 }
6787 
6788 /************************************
6789 * gtkRegionToSelection
6790 *
6791 * group:
6792 *
6793 *
6794 * debug print:
6795 *
6796 *
6797 ************************************/
6798 
6799 static void
gtkRegionToSelection(void)6800 gtkRegionToSelection( void )
6801 {
6802    int nbytes;
6803 
6804    /* printf( "File %s, Line %d: gtkRegionToSelection!!!\n", __FILE__, __LINE__ ); */
6805 
6806    if ( jgtkSelectionData != NULL )
6807      {
6808 	SLfree( jgtkSelectionData );
6809      }
6810    jgtkSelectionData = make_buffer_substring( &nbytes );
6811 
6812    if ( jgtkSelectionData == NULL ) return;
6813 
6814    if ( JGtkWin->appWMiniW )
6815      {
6816 	gtk_selection_owner_set( JGtkWin->appWMiniW,
6817 				 GDK_SELECTION_PRIMARY,
6818 				 GDK_CURRENT_TIME );
6819      }
6820 
6821    /*************
6822    gtk_selection_owner_set( JGtkWin->appWDrawArea,
6823 			    GDK_SELECTION_PRIMARY,
6824 			    GDK_CURRENT_TIME );
6825    *******/
6826 }
6827 
6828 /************************************
6829 * jGtkSendSelection
6830 *
6831 * group:
6832 *
6833 *
6834 * debug print:
6835 *
6836 *
6837 ************************************/
6838 
6839 static void
jGtkSendSelection(GtkWidget * w,GtkSelectionData * selData,guint info,guint time_stamp,gpointer usrData)6840 jGtkSendSelection( GtkWidget *w,
6841 		   GtkSelectionData *selData,
6842 		   guint             info,
6843 		   guint             time_stamp,
6844 		   gpointer          usrData )
6845 {
6846    /* printf( "File %s, Line %d: jGtkSendSelection!!!\n", __FILE__, __LINE__ ); */
6847 
6848    gtk_selection_data_set( selData, GDK_SELECTION_TYPE_STRING,
6849 			   8, jgtkSelectionData, strlen( jgtkSelectionData ) );
6850 }
6851 
6852 #if 0
6853 typedef struct
6854 Selection_Data_Type
6855 {
6856    unsigned int len;
6857    struct Selection_Data_Type *next;
6858    unsigned char bytes[1];
6859 }
6860 Selection_Data_Type;
6861 #endif
6862 
6863 /************************************
6864 * x_region_2_selection
6865 *
6866 * group:
6867 *
6868 *
6869 * debug print:
6870 *
6871 *
6872 ************************************/
6873 
6874 static void
x_region_2_selection(void)6875 x_region_2_selection (void )
6876 {
6877    int nbytes;
6878 
6879    /* if ( gtkButtonEvent ) */
6880    /*  { */
6881    gtkRegionToSelection();
6882    /*   } */
6883 }
6884 
6885 /************************************
6886 * x_server_vendor
6887 *
6888 * group:
6889 *
6890 *
6891 * debug print:
6892 *
6893 *
6894 ************************************/
6895 
6896 static char *
x_server_vendor(void)6897 x_server_vendor (void )
6898 {
6899    return( "" );
6900 }
6901 
6902 /************************************
6903 * jgtk_server_vendor
6904 *
6905 * group:
6906 *
6907 *
6908 * debug print:
6909 *
6910 *
6911 ************************************/
6912 
6913 static void
jgtk_server_vendor(void)6914 jgtk_server_vendor (void )
6915 {
6916 }
6917 
6918 #if SLANG_VERSION < 10404
6919 /************************************
6920 * get_termcap_string
6921 *
6922 * group:
6923 *
6924 *
6925 * debug print:
6926 *
6927 *
6928 ************************************/
6929 
6930 static char *
get_termcap_string(char * cap)6931 get_termcap_string  (char *cap)
6932 {
6933    return "";
6934 }
6935 #endif
6936 
6937 /************************************
6938 * x_set_meta_keys
6939 *
6940 * group:
6941 *
6942 *
6943 * debug print:
6944 *
6945 *
6946 ************************************/
6947 
x_set_meta_keys(int * maskp)6948 static void x_set_meta_keys(int *maskp )
6949 {
6950    int mask = *maskp;
6951 
6952    JX_MetaMask = 0;
6953    if (mask & (1<<0)) JX_MetaMask |= Mod1Mask;
6954    if (mask & (1<<1)) JX_MetaMask |= Mod2Mask;
6955    if (mask & (1<<2)) JX_MetaMask |= Mod3Mask;
6956    if (mask & (1<<3)) JX_MetaMask |= Mod4Mask;
6957    if (mask & (1<<4)) JX_MetaMask |= Mod5Mask;
6958 }
6959 
6960 static SLang_Intrin_Fun_Type sl_x_table[] = /*{{{*/
6961 {
6962 
6963    MAKE_INTRINSIC_S(    "x_set_window_name", set_window_name, VOID_TYPE),
6964    MAKE_INTRINSIC_S( "jgtk_set_window_name", set_window_name, VOID_TYPE),
6965    MAKE_INTRINSIC_S(    "x_set_icon_name", set_icon_name, VOID_TYPE),
6966    MAKE_INTRINSIC_S( "jgtk_set_icon_name", set_icon_name, VOID_TYPE),
6967 
6968    MAKE_INTRINSIC(   "x_warp_pointer", x_warp_pointer, VOID_TYPE, 0),
6969    MAKE_INTRINSIC("jgtk_warp_pointer", x_warp_pointer, VOID_TYPE, 0),
6970 
6971 #if 0
6972    /* Maybe some day */
6973    MAKE_INTRINSIC_S(  "jgtk_insert_clipboard_by_name",         jgtk_insert_clipboard_by_name, INT_TYPE, 0 ),
6974    MAKE_INTRINSIC_S(  "jgtk_get_clipboard_by_name",            jgtk_get_clipboard_by_name, STRING_TYPE ),
6975    MAKE_INTRINSIC_SS( "jgtk_set_clipboard_by_name",            jgtk_set_clipboard_by_name, VOID_TYPE ),
6976    MAKE_INTRINSIC_S(  "jgtk_copy_region_to_clipboard_by_name", jgtk_region_2_clipboard_by_name, VOID_TYPE, 0 ),
6977 #endif
6978 
6979    /* Cutbuffer no longer supported. */
6980    /* (see also: http://www.freedesktop.org/Standards/clipboards-spec) */
6981    /* Instead of cutbuffer gtk clipboard is used. */
6982    MAKE_INTRINSIC(   "x_insert_cutbuffer", jgtk_insert_clipboard, INT_TYPE, 0),
6983    MAKE_INTRINSIC("jgtk_insert_clipboard", jgtk_insert_clipboard, INT_TYPE, 0),
6984    /* Prototype: Integer x_insert_cutbuffer ();
6985     * Inserts cutbuffer into the current buffer and returns the number
6986     * of characters inserted.
6987     */
6988    MAKE_INTRINSIC("x_copy_region_to_cutbuffer", jgtk_region_2_clipboard, VOID_TYPE, 0),
6989    MAKE_INTRINSIC("jgtk_copy_region_to_clipboard", jgtk_region_2_clipboard, VOID_TYPE, 0),
6990    /*Prototype: Void x_copy_region_to_cutbuffer();
6991     */
6992 
6993    MAKE_INTRINSIC(    "x_insert_selection", x_insert_selection, SLANG_INT_TYPE, 0),
6994    MAKE_INTRINSIC( "jgtk_insert_selection", x_insert_selection, SLANG_INT_TYPE, 0),
6995    /* Prototype: Integer x_insert_selection ();
6996     * This function only requests selection data from the selection owner.
6997     * If Xjed received EVENT, Xjed inserts selection data into the current buffer.
6998     * And returns the number of characters inserted.
6999     */
7000    MAKE_INTRINSIC(    "x_copy_region_to_selection", x_region_2_selection, VOID_TYPE, 0),
7001    MAKE_INTRINSIC( "jgtk_copy_region_to_selection", x_region_2_selection, VOID_TYPE, 0),
7002    /*Prototype: Void x_copy_region_to_selection();
7003     */
7004    MAKE_INTRINSIC_IIS(    "x_set_keysym", x_set_keysym, VOID_TYPE),
7005    MAKE_INTRINSIC_IIS( "jgtk_set_keysym", x_set_keysym, VOID_TYPE),
7006   /*Prototype: Void x_set_keysym (Integer keysym, Integer shift, String str);
7007    *
7008    * This function may be used to assocate a string 'str' with a key
7009    * 'keysym' modified by mask @shift@. Pressing the key associated with
7010    * @keysym@ will then generate the keysequence given by @str@. The
7011    * function keys are mapped to integers in the range @0xFF00@ to @0xFFFF@.
7012    * On most systems, the keys that these mappings refer to are located in
7013    * the file @/usr/include/X11/keysymdef.h@. For example, on my system, the
7014    * keysyms for the function keys @XK_F1@ to @XK_F35@ fall in the range
7015    * @0xFFBE@ to @0xFFE0@. So to make the @F1@ key correspond to the string
7016    * given by the two characters @Ctrl-X@ @Ctrl-C@, simply use:
7017    * @ x_set_keysym (0xFFBE, 0, "^X^C");
7018    * The @shift@ argument is an integer with the following meanings:
7019    * @ 0   : unmodified key
7020    * @ '$'  : shifted
7021    * @ '^'  : control
7022    * Any other value for shift will default to 0 (unshifted).
7023    */
7024    MAKE_INTRINSIC_I(    "x_set_meta_keys", x_set_meta_keys, SLANG_VOID_TYPE),
7025    MAKE_INTRINSIC_I( "jgtk_set_meta_keys", x_set_meta_keys, SLANG_VOID_TYPE),
7026 
7027    MAKE_INTRINSIC( "x_server_vendor", x_server_vendor, STRING_TYPE, 0),
7028    /* Prototype: String x_server_vendor ();
7029     * This function returns the empty string for the X server.
7030     * Only provided for compatibily reasons.
7031     */
7032    MAKE_INTRINSIC( "jgtk_server_vendor", jgtk_server_vendor, VOID_TYPE, 0),
7033    /* Prototype: String x_server_vendor ();
7034     * Do nothing. Provided to identify gtkjed.
7035     */
7036 
7037    MAKE_INTRINSIC( "jgtk_print_widget_struct", printWidgetStruct, VOID_TYPE, 0 ),
7038 
7039 #if 0
7040    MAKE_INTRINSIC( "scrollDown", jGtkScrollDown, SLANG_VOID_TYPE, 0 ),
7041    /* Prototype: int jGtkScrollDown( void );
7042     * Scrolls down one line. Cursor remains in the same line relative to
7043     * the window.
7044     */
7045 
7046    MAKE_INTRINSIC( "scrollUp", jGtkScrollUp, SLANG_INT_TYPE, 0 ),
7047    /* Prototype: int jGtkScrollUp( void );
7048     * Scrolls up one line. Cursor remains in the same line relative to
7049     * the window.
7050     */
7051 #endif
7052 
7053    MAKE_INTRINSIC_S("jgtk_load_font", loadFont, VOID_TYPE ),
7054 
7055 #if SLANG_VERSION < 10404
7056    MAKE_INTRINSIC_S("get_termcap_string", get_termcap_string, STRING_TYPE),
7057 #endif
7058    MAKE_INTRINSIC(NULL,NULL,0,0)
7059 };
7060 
7061 /*}}}*/
7062 
7063 static SLang_Intrin_Var_Type X_Variable_Table [] =
7064 {
7065    MAKE_VARIABLE("ALT_CHAR", &X_Alt_Char, INT_TYPE, 0),
7066    MAKE_VARIABLE("X_LAST_KEYSYM", &X_Last_Keysym, INT_TYPE, 0),
7067    MAKE_VARIABLE(NULL,NULL,0,0)
7068 };
7069 
7070 /************************************
7071 * X_init_slang
7072 *
7073 * group:
7074 *
7075 *
7076 * debug print:
7077 *
7078 *
7079 ************************************/
7080 
X_init_slang(void)7081 static int  X_init_slang (void ) /*{{{*/
7082 {
7083    /* cfXDVarAsk = 1; */
7084    if ((-1 == SLadd_intrin_fun_table (sl_x_table, "XWINDOWS"))
7085        || (-1 == SLadd_intrin_var_table (X_Variable_Table, NULL)))
7086      return -1;
7087    return 0;
7088 }
7089 
7090 /*}}}*/
7091 
7092 /************************************
7093 * X_update_open
7094 *
7095 * group: interface
7096 *
7097 *
7098 * debug print:
7099 *
7100 *
7101 ************************************/
7102 
7103 static void
X_update_open(void)7104 X_update_open (void ) /*{{{*/
7105 {
7106    hide_cursor ();
7107    if (Check_Buffers_Pending)
7108      {
7109 	check_buffers();
7110 	Check_Buffers_Pending = 0;
7111      }
7112    Performing_Update = 1;
7113 }
7114 
7115 /*}}}*/
7116 
7117 /************************************
7118 * X_update_close
7119 *
7120 * group: interface
7121 *
7122 *
7123 * debug print:
7124 *
7125 *
7126 ************************************/
7127 
7128 static void
X_update_close(void)7129 X_update_close (void ) /*{{{*/
7130 {
7131 
7132    Performing_Update = 0;
7133    show_cursor ();
7134 
7135    if ( X_Warp_Pending )
7136      {
7137 	int x, y;
7138 	GtkWidget *w = getEdWinFromJedWin( JWindow );
7139 
7140 	if ( w )
7141 	  {
7142 	     gdk_window_get_origin( w->window, &x, &y );
7143 
7144 	 /* Dbp3( "Windows: %p, x: %d, y: %d\n", w->window, x, y ); */
7145 
7146 	     x = JGtkWin->fontWidth*( JGtkWin->vis_curs_col + 0.5 ) + x;
7147 	     y = JGtkWin->fontHeight*( JGtkWin->vis_curs_row - 0.5 ) + y;
7148 
7149 	 /* Dbp3( "Windows: %p, x: %d, y: %d\n", w->window, x, y ); */
7150 
7151 	     gdk_display_warp_pointer( gdk_drawable_get_display( ( GdkDrawable * ) w->window ),
7152 				       gdk_drawable_get_screen( ( GdkDrawable * ) w->window ),
7153 				       x, y );
7154 	  }
7155 
7156 	X_Warp_Pending = 0;
7157      }
7158 }
7159 
7160 /*}}}*/
7161 
7162 /************************************
7163 * funCallCB
7164 *
7165 * group:
7166 *
7167 *
7168 * debug print:
7169 *
7170 *
7171 ************************************/
7172 
7173 static int
funCallCB(void)7174 funCallCB(void)
7175 {
7176    ( *actFunToCall )( actParaData );
7177    return 0;
7178 }
7179 
7180 /************************************
7181 * x_define_xkeys
7182 *
7183 * group: interface
7184 *
7185 *
7186 * debug print:
7187 *
7188 *
7189 ************************************/
7190 
7191 static void
x_define_xkeys(SLKeyMap_List_Type * map)7192 x_define_xkeys (SLKeyMap_List_Type *map ) /*{{{*/
7193 {
7194    SLkm_define_key ("\033[^D", (FVOID_STAR) jed_scroll_right_cmd, map);
7195    SLkm_define_key ("\033[d", (FVOID_STAR) jed_scroll_right_cmd, map);
7196    SLkm_define_key ("\033[^C", (FVOID_STAR) jed_scroll_left_cmd, map);
7197    SLkm_define_key ("\033[c", (FVOID_STAR) jed_scroll_left_cmd, map);
7198    SLkm_define_key ("\033[a", (FVOID_STAR) bob, map);
7199    SLkm_define_key ("\033[^A", (FVOID_STAR) bob, map);
7200    SLkm_define_key ("\033[b", (FVOID_STAR) eob, map);
7201    SLkm_define_key ("\033[^B", (FVOID_STAR) eob, map);
7202    SLkm_define_key ("\033[1~", (FVOID_STAR) bol, map);   /* home */
7203    SLkm_define_key ("\033[4~", (FVOID_STAR) eol, map);   /* end */
7204 
7205    SLkm_define_key( FC_CMD_KEY_SEQ, (FVOID_STAR) funCallCB, Global_Map );
7206 }
7207 
7208 /*}}}*/
7209 
7210 /************************************
7211 * JX_reset_video
7212 *
7213 * group: interface
7214 *
7215 *
7216 * debug print:
7217 *
7218 *
7219 ************************************/
7220 
JX_reset_video(void)7221 static int  JX_reset_video (void ) /*{{{*/
7222 {
7223    JX_reset_scroll_region ();
7224    JX_goto_rc (0, 0);
7225    JX_normal_video ();
7226    /* Return vterm_reset_display (); */
7227    return 0;
7228 }
7229 
7230 /*}}}*/
7231 
7232 /************************************
7233 * JX_init_video
7234 *
7235 * group: interface
7236 *
7237 *
7238 * debug print:
7239 *
7240 *
7241 ************************************/
7242 
JX_init_video(void)7243 static int  JX_init_video (void ) /*{{{*/
7244 {
7245    JX_reset_video ();
7246    if ((JX_Screen_Rows == 0) || (JX_Screen_Cols == 0))
7247      {
7248 	JX_Screen_Cols = 80;
7249 	JX_Screen_Rows = 24;
7250      }
7251 
7252    /* Return vterm_init_display (JX_Screen_Rows, JX_Screen_Cols); */
7253    return 0;
7254 }
7255 
7256 /*}}}*/
7257 
7258 /************************************
7259 * flush_output
7260 *
7261 * group:
7262 *
7263 *
7264 * debug print:
7265 *
7266 *
7267 ************************************/
7268 
flush_output(void)7269 void  flush_output (void ) /*{{{*/
7270 {
7271    if ( JGtkWin->XDisplay == NULL)
7272      fflush (stdout);
7273    else
7274      SLtt_flush_output ();
7275 }
7276 
7277 /*}}}*/
7278 
7279 /* a hook to parse some command line args. */
7280 int (*X_Argc_Argv_Hook)(int, char **) = X_eval_command_line;
7281 
7282 /************************************
7283 * JX_flush_output
7284 *
7285 * group: interface
7286 *
7287 *
7288 * debug print:
7289 *
7290 *
7291 ************************************/
7292 
7293 static int
JX_flush_output(void)7294 JX_flush_output (void )
7295 {
7296    return 0;
7297 }
7298 
7299 static int JX_Zero = 0;
7300 
7301 /************************************
7302 * get_screen_size
7303 *
7304 * group:
7305 *
7306 *
7307 * debug print:
7308 *
7309 *
7310 ************************************/
7311 
7312 static void
get_screen_size(int * r,int * c)7313 get_screen_size (int *r, int *c )
7314 {
7315    SLtt_get_screen_size ();
7316    *r = SLtt_Screen_Rows;
7317    *c = SLtt_Screen_Cols;
7318 }
7319 
7320 /* the links to functions and variables here */
7321 void (*tt_beep)(void);
7322 void (*tt_write_string)(char *);
7323 
7324 JX_SETXXX_RETURN_TYPE (*tt_set_color)(int, char *, char *, char *);
7325 JX_SETXXX_RETURN_TYPE (*tt_set_color_esc)(int, char *);
7326 JX_SETXXX_RETURN_TYPE (*tt_set_mono) (int, char *, SLtt_Char_Type);
7327 
7328 void (*tt_wide_width)(void);
7329 void (*tt_narrow_width)(void);
7330 void (*tt_enable_cursor_keys)(void);
7331 void (*tt_set_term_vtxxx)(int *);
7332 void (*tt_get_screen_size)(int *, int *);
7333 
7334 int *tt_Ignore_Beep;
7335 int *tt_Use_Ansi_Colors;
7336 int *tt_Term_Cannot_Scroll;
7337 int *tt_Term_Cannot_Insert;
7338 int *tt_Blink_Mode;
7339 
7340 /* int *tt_Baud_Rate; */
7341 
7342 /************************************
7343 * set_xtt_hooks
7344 *
7345 * group:
7346 *
7347 *
7348 * debug print:
7349 *
7350 *
7351 ************************************/
7352 
7353 static void
set_xtt_hooks(void)7354 set_xtt_hooks( void )
7355 {
7356    tt_beep =             JX_beep;
7357    tt_write_string =     JX_write_string;
7358    tt_get_screen_size =  JX_get_display_size;
7359    tt_set_color =        JX_set_color;
7360    tt_set_mono =         JX_set_mono;
7361 
7362    tt_wide_width =          JX_wide_width;
7363    tt_narrow_width =        JX_narrow_width;
7364    tt_enable_cursor_keys =  JX_enable_cursor_keys;
7365    tt_set_term_vtxxx =      JX_set_term_vtxxx;
7366 
7367    tt_Ignore_Beep =         &JX_Ignore_Beep;
7368    tt_Use_Ansi_Colors =     &JX_Use_Ansi_Colors;
7369    tt_Term_Cannot_Scroll =  &JX_Term_Cannot_Scroll;
7370    tt_Term_Cannot_Insert =  &JX_Term_Cannot_Insert;
7371    tt_Blink_Mode =          &JX_Blink_Mode;
7372 }
7373 
7374 /************************************
7375 * JX_get_terminfo
7376 *
7377 * group:
7378 *
7379 *
7380 * debug print:
7381 *
7382 *
7383 ************************************/
7384 
7385 static void
JX_get_terminfo(void)7386 JX_get_terminfo( void ) /*{{{*/
7387 {
7388    SLsmg_Term_Type tt;
7389 
7390    if ((Batch) || !open_Xdisplay())
7391      {
7392       /* This function should match the corresponding function in display.c.
7393        * I should "include" it to guarantee the correspondence.
7394        */
7395 	tt_beep                 = SLtt_beep;
7396 	tt_write_string         = SLtt_write_string;
7397 	tt_get_screen_size      = get_screen_size;
7398 	tt_set_color            = SLtt_set_color;
7399 	tt_set_mono             = SLtt_set_mono;
7400 #if SLANG_VERSION < 20000
7401 	tt_set_color_esc        = SLtt_set_color_esc;
7402 #endif
7403 	tt_wide_width           = SLtt_wide_width;
7404 	tt_narrow_width         = SLtt_narrow_width;
7405 	tt_enable_cursor_keys   = SLtt_enable_cursor_keys;
7406 	tt_set_term_vtxxx       = SLtt_set_term_vtxxx;
7407 	tt_Ignore_Beep          = &SLtt_Ignore_Beep;
7408 	tt_Use_Ansi_Colors      = &SLtt_Use_Ansi_Colors;
7409 	tt_Term_Cannot_Scroll   = &SLtt_Term_Cannot_Scroll;
7410 	tt_Term_Cannot_Insert   = &SLtt_Term_Cannot_Insert;
7411 	tt_Blink_Mode           = &SLtt_Blink_Mode;
7412       /*     tt_Baud_Rate            = &SLtt_Baud_Rate; */
7413 
7414 	if (Batch == 0) SLtt_get_terminfo ();
7415 	return;
7416      }
7417 
7418    set_xtt_hooks ();
7419 
7420    if (-1 == init_xkeys ())
7421      {
7422      }
7423 
7424    JX_Screen_Cols = 80;
7425    JX_Screen_Rows = 24;
7426 
7427    (void) jed_add_init_slang_hook (X_init_slang);
7428 
7429    /* init hooks */
7430    X_Read_Hook =           X_read_key;
7431    X_Input_Pending_Hook =  X_input_pending;
7432    X_Update_Open_Hook =    X_update_open;
7433    X_Update_Close_Hook =   X_update_close;
7434    X_Suspend_Hook =        xjed_suspend;
7435    X_Init_Term_Hook =      init_Xdisplay;
7436    X_Reset_Term_Hook =     reset_Xdisplay;
7437    X_Define_Keys_Hook =    x_define_xkeys;
7438    SLang_Interrupt =       xjed_check_kbd;
7439 
7440    /* Set this so that main will not try to read from stdin.  It is quite
7441     * likely that this is started from a menu or something.
7442     */
7443    Stdin_Is_TTY = -1;
7444    /* We do not need this since we do not have to worry about incoming
7445     * eight bit escape sequences. tt_goto_rc
7446     */
7447    DEC_8Bit_Hack = 0;
7448 
7449    memset ((char *) &tt, 0, sizeof (SLsmg_Term_Type));
7450 
7451    tt.tt_normal_video =         JX_normal_video;
7452    tt.tt_set_scroll_region =    JX_set_scroll_region;
7453    tt.tt_goto_rc =              JX_goto_rc;
7454    tt.tt_reverse_index =        JX_reverse_index;
7455    tt.tt_reset_scroll_region =  JX_reset_scroll_region;
7456    tt.tt_delete_nlines =        JX_delete_nlines;
7457    tt.tt_cls =           JX_cls;
7458    tt.tt_del_eol =       JX_del_eol;
7459    tt.tt_smart_puts =    JX_smart_puts;
7460    tt.tt_flush_output =  JX_flush_output;
7461    tt.tt_reset_video =   JX_reset_video;
7462    tt.tt_init_video =    JX_init_video;
7463 
7464    tt.tt_screen_rows =   &JX_Screen_Rows;
7465    tt.tt_screen_cols =   &JX_Screen_Cols;
7466    tt.tt_term_cannot_scroll = &JX_Term_Cannot_Scroll;
7467    tt.tt_has_alt_charset =    &JX_Zero;
7468 
7469 #if SLANG_VERSION >= 20000
7470    tt.unicode_ok = &Jed_UTF8_Mode;
7471 #endif
7472 
7473    SLsmg_set_terminal_info (&tt);
7474    Jed_Handle_SIGTSTP = 0;
7475    if ( 1 )  return;
7476 }
7477 
7478 /*}}}*/
7479 
7480 void (*tt_get_terminfo)(void) = JX_get_terminfo;
7481 
7482 /* Unused but required. */
7483 #ifdef USE_GPM_MOUSE
7484 int (*X_Open_Mouse_Hook)(void);
7485 void (*X_Close_Mouse_Hook)(void);
7486 #endif
7487 
7488