1 static const char CVSID
[] = "$Id: preferences.c,v 1.97 2003/05/28 08:26:02 edg Exp $";
2 /*******************************************************************************
4 * preferences.c -- Nirvana Editor preferences processing *
6 * Copyright (C) 1999 Mark Edel *
8 * This is free software; you can redistribute it and/or modify it under the *
9 * terms of the GNU General Public License as published by the Free Software *
10 * Foundation; either version 2 of the License, or (at your option) any later *
13 * This software is distributed in the hope that it will be useful, but WITHOUT *
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
18 * You should have received a copy of the GNU General Public License along with *
19 * software; if not, write to the Free Software Foundation, Inc., 59 Temple *
20 * Place, Suite 330, Boston, MA 02111-1307 USA *
22 * Nirvana Text Editor *
25 * Written by Mark Edel *
27 *******************************************************************************/
30 #include "../config.h"
33 #include "preferences.h"
40 #include "highlight.h"
41 #include "highlightData.h"
43 #include "regularExp.h"
44 #include "smartIndent.h"
45 #include "windowTitle.h"
48 #include "../util/prefFile.h"
49 #include "../util/misc.h"
50 #include "../util/DialogF.h"
51 #include "../util/managedList.h"
52 #include "../util/fontsel.h"
53 #include "../util/fileUtils.h"
54 #include "../util/utils.h"
61 #include "../util/VMSparam.h"
64 #include <sys/param.h>
66 #include "../util/clearcase.h"
70 #include <Xm/SelectioB.h>
73 #include <Xm/SeparatoG.h>
74 #include <Xm/LabelG.h>
76 #include <Xm/PushBG.h>
78 #include <Xm/ToggleBG.h>
79 #include <Xm/ToggleB.h>
80 #include <Xm/RowColumn.h>
81 #include <Xm/CascadeBG.h>
89 #define PREF_FILE_VERSION "5.4"
91 /* New styles added in 5.2 for auto-upgrade */
92 #define ADD_5_2_STYLES " Pointer:#660000:Bold\nRegex:#009944:Bold\nWarning:brown2:Italic"
94 /* maximum number of word delimiters allowed (256 allows whole character set) */
95 #define MAX_WORD_DELIMITERS 256
97 /* maximum number of file extensions allowed in a language mode */
98 #define MAX_FILE_EXTENSIONS 20
100 /* Return values for checkFontStatus */
101 enum fontStatus
{GOOD_FONT
, BAD_PRIMARY
, BAD_FONT
, BAD_SIZE
, BAD_SPACING
};
103 /* enumerated type preference strings
104 ** The order of the elements in this array must be exactly the same
105 ** as the order of the corresponding integers of the enum SearchType
106 ** defined in search.h (!!)
108 static char *SearchMethodStrings
[] = {
109 "Literal", "CaseSense", "RegExp",
110 "LiteralWord", "CaseSenseWord", "RegExpNoCase",
115 /* enumerated default scope for replace dialog if a selection exists when
116 ** the dialog is popped up.
118 static char *ReplaceDefScopeStrings
[] = {
119 "Window", "Selection", "Smart", NULL
123 #define N_WRAP_STYLES 3
124 static char *AutoWrapTypes
[N_WRAP_STYLES
+3] = {"None", "Newline", "Continuous",
125 "True", "False", NULL
};
126 #define N_INDENT_STYLES 3
127 static char *AutoIndentTypes
[N_INDENT_STYLES
+3] = {"None", "Auto",
128 "Smart", "True", "False", NULL
};
129 #define N_VIRTKEY_OVERRIDE_MODES 3
130 static char *VirtKeyOverrideModes
[N_VIRTKEY_OVERRIDE_MODES
+1] = { "Never",
131 "Auto", "Always", NULL
};
133 #define N_SHOW_MATCHING_STYLES 3
134 /* For backward compatibility, "False" and "True" are still accepted.
135 They are internally converted to "Off" and "Delimiter" respectively.
136 NOTE: N_SHOW_MATCHING_STYLES must correspond to the number of
137 _real_ matching styles, not counting False & True.
138 False and True should also be the last ones in the list. */
139 static char *ShowMatchingTypes
[] = {"Off", "Delimiter", "Range",
140 "False", "True", NULL
};
142 /* suplement wrap and indent styles w/ a value meaning "use default" for
143 the override fields in the language modes dialog */
144 #define DEFAULT_WRAP -1
145 #define DEFAULT_INDENT -1
146 #define DEFAULT_TAB_DIST -1
147 #define DEFAULT_EM_TAB_DIST -1
149 /* list of available language modes and language specific preferences */
150 static int NLanguageModes
= 0;
155 char *recognitionExpr
;
163 static languageModeRec
*LanguageModes
[MAX_LANGUAGE_MODES
];
165 /* Language mode dialog information */
176 Widget defaultIndentW
;
184 languageModeRec
**languageModeList
;
186 } LMDialog
= {NULL
,NULL
,NULL
,NULL
,NULL
,NULL
,NULL
,NULL
,NULL
,NULL
,
187 NULL
,NULL
,NULL
,NULL
,NULL
,NULL
,NULL
,NULL
,0};
189 /* Font dialog information */
199 Widget boldItalicErrW
;
204 /* Color dialog information */
226 /* Repository for simple preferences settings */
227 static struct prefData
{
228 int wrapStyle
; /* what kind of wrapping to do */
229 int wrapMargin
; /* 0=wrap at window width, other=wrap margin */
230 int autoIndent
; /* style for auto-indent */
231 int autoSave
; /* whether automatic backup feature is on */
232 int saveOldVersion
; /* whether to preserve a copy of last version */
233 int searchDlogs
; /* whether to show explanatory search dialogs */
234 int searchWrapBeep
; /* 1=beep when search restarts at begin/end */
235 int keepSearchDlogs
; /* whether to retain find and replace dialogs */
236 int searchWraps
; /* whether to attempt search again if reach bof or eof */
237 int statsLine
; /* whether to show the statistics line */
238 int iSearchLine
; /* whether to show the incremental search line*/
239 int lineNums
; /* whether to show line numbers */
240 int pathInWindowsMenu
; /* whether to show path in windows menu */
241 int warnFileMods
; /* warn user if files externally modified */
242 int warnRealFileMods
; /* only warn if file contents modified */
243 int warnExit
; /* whether to warn on exit */
244 int searchMethod
; /* initial search method as a text string */
246 int replaceDefScope
; /* default replace scope if selection exists */
248 int textRows
; /* initial window height in characters */
249 int textCols
; /* initial window width in characters */
250 int tabDist
; /* number of characters between tab stops */
251 int emTabDist
; /* non-zero tab dist. if emulated tabs are on */
252 int insertTabs
; /* whether to use tabs for padding */
253 int showMatchingStyle
; /* how to flash matching parenthesis */
254 int matchSyntaxBased
; /* use syntax info to match parenthesis */
255 int highlightSyntax
; /* whether to highlight syntax by default */
256 int smartTags
; /* look for tag in current window first */
257 int alwaysCheckRelativeTagsSpecs
; /* for every new opened file of session */
258 int stickyCaseSenseBtn
; /* whether Case Word Btn is sticky to Regex Btn */
259 int prefFileRead
; /* detects whether a .nedit existed */
260 int backlightChars
; /* whether to apply character "backlighting" */
261 char *backlightCharTypes
; /* the backlighting color definitions */
263 int shortMenus
; /* short menu mode */
265 char fontString
[MAX_FONT_LEN
]; /* names of fonts for text widget */
266 char boldFontString
[MAX_FONT_LEN
];
267 char italicFontString
[MAX_FONT_LEN
];
268 char boldItalicFontString
[MAX_FONT_LEN
];
269 XmFontList fontList
; /* XmFontLists corresp. to above named fonts */
270 XFontStruct
*boldFontStruct
;
271 XFontStruct
*italicFontStruct
;
272 XFontStruct
*boldItalicFontStruct
;
273 int repositionDialogs
; /* w. to reposition dialogs under the pointer */
274 int sortOpenPrevMenu
; /* whether to sort the "Open Previous" menu */
275 int appendLF
; /* Whether to append LF at the end of each file */
276 int mapDelete
; /* whether to map delete to backspace */
277 int stdOpenDialog
; /* w. to retain redundant text field in Open */
278 char tagFile
[MAXPATHLEN
]; /* name of tags file to look for at startup */
279 int maxPrevOpenFiles
; /* limit to size of Open Previous menu */
280 int typingHidesPointer
; /* hide mouse pointer when typing */
281 char delimiters
[MAX_WORD_DELIMITERS
]; /* punctuation characters */
282 char shell
[MAXPATHLEN
]; /* shell to use for executing commands */
283 char geometry
[MAX_GEOM_STRING_LEN
]; /* per-application geometry string,
284 only for the clueless */
285 char serverName
[MAXPATHLEN
];/* server name for multiple servers per disp. */
286 char bgMenuBtn
[MAX_ACCEL_LEN
]; /* X event description for triggering
287 posting of background menu */
288 char fileVersion
[6]; /* Version of nedit which wrote the .nedit
289 file we're reading */
290 int findReplaceUsesSelection
; /* whether the find replace dialog is automatically
291 loaded with the primary selection */
292 int virtKeyOverride
; /* Override Motif default virtual key bindings
293 never, if invalid, or always */
294 char titleFormat
[MAX_TITLE_FORMAT_LEN
];
295 char helpFontNames
[NUM_HELP_FONTS
][MAX_FONT_LEN
];/* fonts for help system */
296 char helpLinkColor
[MAX_COLOR_LEN
]; /* Color for hyperlinks in the help system */
297 char colorNames
[NUM_COLORS
][MAX_COLOR_LEN
];
298 int undoModifiesSelection
;
301 /* Temporary storage for preferences strings which are discarded after being
311 char *smartIndentCommon
;
314 /* preference descriptions for SavePreferences and RestorePreferences. */
315 static PrefDescripRec PrefDescrip
[] = {
316 {"fileVersion", "FileVersion" , PREF_STRING
, "", PrefData
.fileVersion
,
317 (void *)sizeof(PrefData
.fileVersion
), True
},
320 {"shellCommands", "ShellCommands", PREF_ALLOC_STRING
, "spell:Alt+B:s:EX:\n\
321 cat>spellTmp; xterm -e ispell -x spellTmp; cat spellTmp; rm spellTmp\n\
322 wc::w:ED:\nwc | awk '{print $1 \" lines, \" $2 \" words, \" $3 \" characters\"}'\n\
323 sort::o:EX:\nsort\nnumber lines::n:AW:\nnl -ba\nmake:Alt+Z:m:W:\nmake\n\
324 expand::p:EX:\nexpand\nunexpand::u:EX:\nunexpand\n",
325 &TempStringPrefs
.shellCmds
, NULL
, True
},
327 {"shellCommands", "ShellCommands", PREF_ALLOC_STRING
, "spell:Alt+B:s:EX:\n\
328 cat>spellTmp; xterm -e ispell -x spellTmp; cat spellTmp; rm spellTmp\n\
329 wc::w:ED:\nwc | awk '{print $2 \" lines, \" $1 \" words, \" $3 \" characters\"}'\n\
330 sort::o:EX:\nsort\nnumber lines::n:AW:\npr -tn\nmake:Alt+Z:m:W:\nmake\n\
331 expand::p:EX:\nexpand\nunexpand::u:EX:\nunexpand\n",
332 &TempStringPrefs
.shellCmds
, NULL
, True
},
334 {"shellCommands", "ShellCommands", PREF_ALLOC_STRING
, "spell:Alt+B:s:ED:\n\
335 (cat;echo \"\") | spell\nwc::w:ED:\nwc | awk '{print $1 \" lines, \" $2 \" words, \" $3 \" characters\"}'\n\
336 \nsort::o:EX:\nsort\nnumber lines::n:AW:\nnl -ba\nmake:Alt+Z:m:W:\nmake\n\
337 expand::p:EX:\nexpand\nunexpand::u:EX:\nunexpand\n",
338 &TempStringPrefs
.shellCmds
, NULL
, True
},
339 #endif /* linux, __FreeBSD__ */
341 {"macroCommands", "MacroCommands", PREF_ALLOC_STRING
,
342 "Complete Word:Alt+D::: {\n\
343 # Tuning parameters\n\
344 ScanDistance = 200\n\
346 # Search back to a word boundary to find the word to complete\n\
347 startScan = max(0, $cursor - ScanDistance)\n\
348 endScan = min($text_length, $cursor + ScanDistance)\n\
349 scanString = get_range(startScan, endScan)\n\
350 keyEnd = $cursor-startScan\n\
351 keyStart = search_string(scanString, \"<\", keyEnd, \"backward\", \"regex\")\n\
352 if (keyStart == -1)\n\
354 keyString = \"<\" substring(scanString, keyStart, keyEnd)\n\
356 # search both forward and backward from the cursor position. Note that\n\
357 # using a regex search can lead to incorrect results if any of the special\n\
358 # regex characters is encountered, which is not considered a delimiter\n\
359 backwardSearchResult = search_string(scanString, keyString, keyStart-1, \\\n\
360 \"backward\", \"regex\")\n\
361 forwardSearchResult = search_string(scanString, keyString, keyEnd, \"regex\")\n\
362 if (backwardSearchResult == -1 && forwardSearchResult == -1) {\n\
367 # if only one direction matched, use that, otherwise use the nearest\n\
368 if (backwardSearchResult == -1)\n\
369 matchStart = forwardSearchResult\n\
370 else if (forwardSearchResult == -1)\n\
371 matchStart = backwardSearchResult\n\
373 if (keyStart - backwardSearchResult <= forwardSearchResult - keyEnd)\n\
374 matchStart = backwardSearchResult\n\
376 matchStart = forwardSearchResult\n\
379 # find the complete word\n\
380 matchEnd = search_string(scanString, \">\", matchStart, \"regex\")\n\
381 completedWord = substring(scanString, matchStart, matchEnd)\n\
383 # replace it in the window\n\
384 replace_range(startScan + keyStart, $cursor, completedWord)\n\
386 Fill Sel. w/Char:::R: {\n\
387 if ($selection_start == -1) {\n\
392 # Ask the user what character to fill with\n\
393 fillChar = string_dialog(\"Fill selection with what character?\", \"OK\", \"Cancel\")\n\
394 if ($string_dialog_button == 2 || $string_dialog_button == 0)\n\
397 # Count the number of lines in the selection\n\
399 for (i=$selection_start; i<$selection_end; i++)\n\
400 if (get_character(i) == \"\\n\")\n\
403 # Create the fill text\n\
404 rectangular = $selection_left != -1\n\
407 if (rectangular) {\n\
408 for (i=0; i<$selection_right-$selection_left; i++)\n\
409 line = line fillChar\n\
410 for (i=0; i<nLines; i++)\n\
411 fillText = fillText line \"\\n\"\n\
412 fillText = fillText line\n\
414 if (nLines == 0) {\n\
415 for (i=$selection_start; i<$selection_end; i++)\n\
416 fillText = fillText fillChar\n\
419 for (i=$selection_start-1; i>=0 && get_character(i)!=\"\\n\"; i--)\n\
421 for (i=0; i<$wrap_margin-startIndent; i++)\n\
422 fillText = fillText fillChar\n\
423 fillText = fillText \"\\n\"\n\
424 for (i=0; i<$wrap_margin; i++)\n\
425 line = line fillChar\n\
426 for (i=0; i<nLines-1; i++)\n\
427 fillText = fillText line \"\\n\"\n\
428 for (i=$selection_end-1; i>=$selection_start && get_character(i)!=\"\\n\"; \\\n\
430 fillText = fillText fillChar\n\
434 # Replace the selection with the fill text\n\
435 replace_selection(fillText)\n\
437 Quote Mail Reply:::: {\n\
438 if ($selection_start == -1)\n\
439 replace_all(\"^.*$\", \"\\\\> &\", \"regex\")\n\
441 replace_in_selection(\"^.*$\", \"\\\\> &\", \"regex\")\n\
443 Unquote Mail Reply:::: {\n\
444 if ($selection_start == -1)\n\
445 replace_all(\"(^\\\\> )(.*)$\", \"\\\\2\", \"regex\")\n\
447 replace_in_selection(\"(^\\\\> )(.*)$\", \"\\\\2\", \"regex\")\n\
449 Comments>/* Comment */@C@C++@Java@CSS@JavaScript@Lex:::R: {\n\
450 selStart = $selection_start\n\
451 selEnd = $selection_end\n\
452 replace_range(selStart, selEnd, \"/* \" get_selection() \" */\")\n\
453 select(selStart, selEnd + 6)\n\
455 Comments>/* Uncomment */@C@C++@Java@CSS@JavaScript@Lex:::R: {\n\
456 sel = get_selection()\n\
457 selStart = $selection_start\n\
458 selEnd = $selection_end\n\
459 commentStart = search_string(sel, \"/*\", 0)\n\
460 if (substring(sel, commentStart + 2, commentStart + 3) == \" \")\n\
461 keepStart = commentStart + 3\n\
463 keepStart = commentStart + 2\n\
464 keepEnd = search_string(sel, \"*/\", length(sel), \"backward\")\n\
465 commentEnd = keepEnd + 2\n\
466 if (substring(sel, keepEnd - 1, keepEnd == \" \"))\n\
467 keepEnd = keepEnd - 1\n\
468 replace_range(selStart + commentStart, selStart + commentEnd, \\\n\
469 substring(sel, keepStart, keepEnd))\n\
470 select(selStart, selEnd - (keepStart-commentStart) - \\\n\
471 (commentEnd - keepEnd))\n\
473 Comments>// Comment@C@C++@Java@JavaScript:::R: {\n\
474 replace_in_selection(\"^.*$\", \"// &\", \"regex\")\n\
476 Comments>// Uncomment@C@C++@Java@JavaScript:::R: {\n\
477 replace_in_selection(\"(^[ \\\\t]*// ?)(.*)$\", \"\\\\2\", \"regex\")\n\
479 Comments># Comment@Perl@Sh Ksh Bash@NEdit Macro@Makefile@Awk@Csh@Python@Tcl:::R: {\n\
480 replace_in_selection(\"^.*$\", \"#&\", \"regex\")\n\
482 Comments># Uncomment@Perl@Sh Ksh Bash@NEdit Macro@Makefile@Awk@Csh@Python@Tcl:::R: {\n\
483 replace_in_selection(\"(^[ \\\\t]*#)(.*)$\", \"\\\\2\", \"regex\")\n\
485 Comments>-- Comment@SQL:::R: {\n\
486 replace_in_selection(\"^.*$\", \"--&\", \"regex\")\n\
488 Comments>-- Uncomment@SQL:::R: {\n\
489 replace_in_selection(\"(^[ \\\\t]*--)(.*)$\", \"\\\\2\", \"regex\")\n\
491 Comments>! Comment@X Resources:::R: {\n\
492 replace_in_selection(\"^.*$\", \"!&\", \"regex\")\n\
494 Comments>! Uncomment@X Resources:::R: {\n\
495 replace_in_selection(\"(^[ \\\\t]*!)(.*)$\", \"\\\\2\", \"regex\")\n\
497 Comments>Bar Comment@C:::R: {\n\
498 if ($selection_left != -1) {\n\
499 dialog(\"Selection must not be rectangular\")\n\
502 start = $selection_start\n\
503 end = $selection_end-1\n\
504 origText = get_range($selection_start, $selection_end-1)\n\
505 newText = \"/*\\n\" replace_in_string(get_range(start, end), \\\n\
506 \"^\", \" * \", \"regex\") \"\\n */\\n\"\n\
507 replace_selection(newText)\n\
508 select(start, start + length(newText))\n\
510 Comments>Bar Uncomment@C:::R: {\n\
511 selStart = $selection_start\n\
512 selEnd = $selection_end\n\
513 newText = get_range(selStart+3, selEnd-4)\n\
514 newText = replace_in_string(newText, \"^ \\\\* \", \"\", \"regex\")\n\
515 replace_range(selStart, selEnd, newText)\n\
516 select(selStart, selStart + length(newText))\n\
518 Make C Prototypes@C@C++:::: {\n\
519 if ($selection_start == -1) {\n\
521 end = $text_length\n\
523 start = $selection_start\n\
524 end = $selection_end\n\
526 string = get_range(start, end)\n\
530 staticPrototypes = \"\"\n\
532 headerStart = search_string(string, \\\n\
533 \"^[a-zA-Z]([^;#\\\"'{}=><!/]|\\n)*\\\\)[ \\t]*\\n?[ \\t]*\\\\{\", \\\n\
534 searchPos, \"regex\")\n\
535 if (headerStart == -1)\n\
537 headerEnd = search_string(string, \")\", $search_end,\"backward\") + 1\n\
538 prototype = substring(string, headerStart, headerEnd) \";\\n\"\n\
539 if (substring(string, headerStart, headerStart+6) == \"static\")\n\
540 staticPrototypes = staticPrototypes prototype\n\
542 prototypes = prototypes prototype\n\
543 searchPos = headerEnd\n\
547 dialog(\"No function declarations found\")\n\
551 focus_window(\"last\")\n\
552 replace_range(0, 0, prototypes staticPrototypes)\n\
553 }", &TempStringPrefs
.macroCmds
, NULL
, True
},
554 {"bgMenuCommands", "BGMenuCommands", PREF_ALLOC_STRING
,
555 "Undo:::: {\nundo()\n}\n\
556 Redo:::: {\nredo()\n}\n\
557 Cut:::R: {\ncut_clipboard()\n}\n\
558 Copy:::R: {\ncopy_clipboard()\n}\n\
559 Paste:::: {\npaste_clipboard()\n}", &TempStringPrefs
.bgMenuCmds
,
562 /* The VAX compiler can't compile Java-Script's definition in highlightData.c */
563 {"highlightPatterns", "HighlightPatterns", PREF_ALLOC_STRING
,
576 NEdit Macro:Default\n\
579 PostScript:Default\n\
584 Sh Ksh Bash:Default\n\
589 X Resources:Default\n\
591 &TempStringPrefs
.highlight
, NULL
, True
},
592 {"languageModes", "LanguageModes", PREF_ALLOC_STRING
,
594 {"highlightPatterns", "HighlightPatterns", PREF_ALLOC_STRING
,
603 JavaScript:Default\n\
608 NEdit Macro:Default\n\
611 PostScript:Default\n\
616 Sh Ksh Bash:Default\n\
621 X Resources:Default\n\
623 &TempStringPrefs
.highlight
, NULL
, True
},
624 {"languageModes", "LanguageModes", PREF_ALLOC_STRING
,
627 "Ada:.ADA .AD .ADS .ADB .A:::::::\n\
629 C++:.CC .HH .C .H .I .CXX .HXX .CPP::::::\".,/\\`'!|@#%^&*()-=+{}[]\"\":;<>?~\":\n\
630 C:.C .H::::::\".,/\\`'!|@#%^&*()-=+{}[]\"\":;<>?~\":\n\
631 CSS:CSS::Auto:None:::\".,/\\`'!|@#%^&*()=+{}[]\"\":;<>?~\":\n\
632 Csh:.csh .cshrc .login .logout:\"^[ \\t]*#[ \\t]*![ \\t]*/bin/csh\"::::::\n\
633 Fortran:.F .F77 .FOR:::::::\n\
635 LaTeX:.TEX .STY .CLS .DTX .INS:::::::\n\
637 Makefile:MAKEFILE:::None:8:8::\n\
638 Matlab:.m .oct .sci:::::::\n\
639 NEdit Macro:.NM .NEDITMACRO:::::::\n\
640 Pascal:.PAS .P .INT:::::::\n\
641 Perl:.PL .PM .P5:\"^[ \\t]*#[ \\t]*!.*perl\":Auto:None:::\".,/\\\\`'!$@#%^&*()-=+{}[]\"\":;<>?~|\":\n\
642 PostScript:.ps .PS .eps .EPS .epsf .epsi:\"^%!\":::::\"/%(){}[]<>\":\n\
643 Python:.PY:\"^#!.*python\":Auto:None:::\"!\"\"#$%&'()*+,-./:;<=>?@[\\\\]^`{|}~\":\n\
644 Regex:.reg .regex:\"\\(\\?[:#=!iInN].+\\)\":None:Continuous::::\n\
645 SGML HTML:.sgml .sgm .html .htm:\"\\<[Hh][Tt][Mm][Ll]\\>\"::::::\n\
647 Sh Ksh Bash:.sh .bash .ksh .profile .bashrc .bash_logout .bash_login .bash_profile:\"^[ \\t]*#[ \\t]*![ \\t]*/.*bin/(sh|ksh|bash)\"::::::\n\
648 Tcl:.TCL::Smart:None::::\n\
649 VHDL:.VHD .VHDL .VDL:::::::\n\
651 XML:.xml .xsl .dtd:\"\\<(?i\\?xml|!doctype)\"::None:::\"<>/=\"\"'()+*?|\":\n\
652 X Resources:.XRESOURCES .XDEFAULTS .NEDIT:\"^[!#].*([Aa]pp|[Xx]).*[Dd]efaults\"::::::\n\
653 Yacc:.Y::::::\".,/\\`'!|@#%^&*()-=+{}[]\"\":;<>?~\":",
655 "Ada:.ada .ad .ads .adb .a:::::::\n\
657 C++:.cc .hh .C .H .i .cxx .hxx .cpp::::::\".,/\\`'!|@#%^&*()-=+{}[]\"\":;<>?~\":\n\
658 C:.c .h::::::\".,/\\`'!|@#%^&*()-=+{}[]\"\":;<>?~\":\n\
659 CSS:css::Auto:None:::\".,/\\`'!|@#%^&*()=+{}[]\"\":;<>?~\":\n\
660 Csh:.csh .cshrc .login .logout:\"^[ \\t]*#[ \\t]*![ \\t]*/bin/csh\"::::::\n\
661 Fortran:.f .f77 .for:::::::\n\
663 JavaScript:.js:::::::\n\
664 LaTeX:.tex .sty .cls .dtx .ins:::::::\n\
666 Makefile:Makefile makefile .gmk:::None:8:8::\n\
667 Matlab:.m .oct .sci:::::::\n\
668 NEdit Macro:.nm .neditmacro:::::::\n\
669 Pascal:.pas .p .int:::::::\n\
670 Perl:.pl .pm .p5 .PL:\"^[ \\t]*#[ \\t]*!.*perl\":Auto:None:::\".,/\\\\`'!$@#%^&*()-=+{}[]\"\":;<>?~|\":\n\
671 PostScript:.ps .eps .epsf .epsi:\"^%!\":::::\"/%(){}[]<>\":\n\
672 Python:.py:\"^#!.*python\":Auto:None:::\"!\"\"#$%&'()*+,-./:;<=>?@[\\\\]^`{|}~\":\n\
673 Regex:.reg .regex:\"\\(\\?[:#=!iInN].+\\)\":None:Continuous::::\n\
674 SGML HTML:.sgml .sgm .html .htm:\"\\<[Hh][Tt][Mm][Ll]\\>\"::::::\n\
676 Sh Ksh Bash:.sh .bash .ksh .profile .bashrc .bash_logout .bash_login .bash_profile:\"^[ \\t]*#[ \\t]*![ \\t]*/.*bin/(sh|ksh|bash)\"::::::\n\
677 Tcl:.tcl .tk .itcl .itk::Smart:None::::\n\
678 VHDL:.vhd .vhdl .vdl:::::::\n\
680 XML:.xml .xsl .dtd:\"\\<(?i\\?xml|!doctype)\"::None:::\"<>/=\"\"'()+*?|\":\n\
681 X Resources:.Xresources .Xdefaults .nedit:\"^[!#].*([Aa]pp|[Xx]).*[Dd]efaults\"::::::\n\
682 Yacc:.y::::::\".,/\\`'!|@#%^&*()-=+{}[]\"\":;<>?~\":",
684 &TempStringPrefs
.language
, NULL
, True
},
685 {"styles", "Styles", PREF_ALLOC_STRING
, "Plain:black:Plain\n\
686 Comment:gray20:Italic\n\
687 Keyword:black:Bold\n\
688 Storage Type:brown:Bold\n\
689 Storage Type1:saddle brown:Bold\n\
690 String:darkGreen:Plain\n\
691 String1:SeaGreen:Plain\n\
692 String2:darkGreen:Bold\n\
693 Preprocessor:RoyalBlue4:Plain\n\
694 Preprocessor1:blue:Plain\n\
695 Character Const:darkGreen:Plain\n\
696 Numeric Const:darkGreen:Plain\n\
697 Identifier:brown:Plain\n\
698 Identifier1:RoyalBlue4:Plain\n\
699 Identifier2:SteelBlue:Plain\n\
700 Subroutine:brown:Plain\n\
701 Subroutine1:chocolate:Plain\n\
702 Ada Attributes:plum:Bold\n\
705 Text Comment:SteelBlue4:Italic\n\
706 Text Key:VioletRed4:Bold\n\
707 Text Key1:VioletRed4:Plain\n\
708 Text Arg:RoyalBlue4:Bold\n\
709 Text Arg1:SteelBlue4:Bold\n\
710 Text Arg2:RoyalBlue4:Plain\n\
711 Text Escape:gray30:Bold\n\
712 LaTeX Math:darkGreen:Plain\n"
714 &TempStringPrefs
.styles
, NULL
, True
},
715 {"smartIndentInit", "SmartIndentInit", PREF_ALLOC_STRING
,
719 Matlab:Default", &TempStringPrefs
.smartIndent
, NULL
, True
},
720 {"smartIndentInitCommon", "SmartIndentInitCommon", PREF_ALLOC_STRING
,
721 "Default", &TempStringPrefs
.smartIndentCommon
, NULL
, True
},
722 {"autoWrap", "AutoWrap", PREF_ENUM
, "Newline",
723 &PrefData
.wrapStyle
, AutoWrapTypes
, True
},
724 {"wrapMargin", "WrapMargin", PREF_INT
, "0",
725 &PrefData
.wrapMargin
, NULL
, True
},
726 {"autoIndent", "AutoIndent", PREF_ENUM
, "Auto",
727 &PrefData
.autoIndent
, AutoIndentTypes
, True
},
728 {"autoSave", "AutoSave", PREF_BOOLEAN
, "True",
729 &PrefData
.autoSave
, NULL
, True
},
730 {"saveOldVersion", "SaveOldVersion", PREF_BOOLEAN
, "False",
731 &PrefData
.saveOldVersion
, NULL
, True
},
732 {"showMatching", "ShowMatching", PREF_ENUM
, "Delimiter",
733 &PrefData
.showMatchingStyle
, ShowMatchingTypes
, True
},
734 {"matchSyntaxBased", "MatchSyntaxBased", PREF_BOOLEAN
, "True",
735 &PrefData
.matchSyntaxBased
, NULL
, True
},
736 {"highlightSyntax", "HighlightSyntax", PREF_BOOLEAN
, "True",
737 &PrefData
.highlightSyntax
, NULL
, True
},
738 {"backlightChars", "BacklightChars", PREF_BOOLEAN
, "False",
739 &PrefData
.backlightChars
, NULL
, True
},
740 {"backlightCharTypes", "BacklightCharTypes", PREF_ALLOC_STRING
,
741 "0-8,10-31,127:red;9:#dedede;32-126,160-255:#f0f0f0;128-159:orange",
743 &PrefData
.backlightCharTypes
, NULL
, False
},
744 {"searchDialogs", "SearchDialogs", PREF_BOOLEAN
, "False",
745 &PrefData
.searchDlogs
, NULL
, True
},
746 {"beepOnSearchWrap", "BeepOnSearchWrap", PREF_BOOLEAN
, "False",
747 &PrefData
.searchWrapBeep
, NULL
, True
},
748 {"retainSearchDialogs", "RetainSearchDialogs", PREF_BOOLEAN
, "False",
749 &PrefData
.keepSearchDlogs
, NULL
, True
},
750 {"searchWraps", "SearchWraps", PREF_BOOLEAN
, "True",
751 &PrefData
.searchWraps
, NULL
, True
},
752 {"stickyCaseSenseButton", "StickyCaseSenseButton", PREF_BOOLEAN
, "True",
753 &PrefData
.stickyCaseSenseBtn
, NULL
, True
},
754 #if XmVersion < 1002 /* Flashing is annoying in 1.1 versions */
755 {"repositionDialogs", "RepositionDialogs", PREF_BOOLEAN
, "False",
756 &PrefData
.repositionDialogs
, NULL
, True
},
758 {"repositionDialogs", "RepositionDialogs", PREF_BOOLEAN
, "True",
759 &PrefData
.repositionDialogs
, NULL
, True
},
761 {"appendLF", "AppendLF", PREF_BOOLEAN
, "True",
762 &PrefData
.appendLF
, NULL
, True
},
763 {"sortOpenPrevMenu", "SortOpenPrevMenu", PREF_BOOLEAN
, "True",
764 &PrefData
.sortOpenPrevMenu
, NULL
, True
},
765 {"statisticsLine", "StatisticsLine", PREF_BOOLEAN
, "False",
766 &PrefData
.statsLine
, NULL
, True
},
767 {"iSearchLine", "ISearchLine", PREF_BOOLEAN
, "False",
768 &PrefData
.iSearchLine
, NULL
, True
},
769 {"lineNumbers", "LineNumbers", PREF_BOOLEAN
, "False",
770 &PrefData
.lineNums
, NULL
, True
},
771 {"pathInWindowsMenu", "PathInWindowsMenu", PREF_BOOLEAN
, "True",
772 &PrefData
.pathInWindowsMenu
, NULL
, True
},
773 {"warnFileMods", "WarnFileMods", PREF_BOOLEAN
, "True",
774 &PrefData
.warnFileMods
, NULL
, True
},
775 {"warnRealFileMods", "WarnRealFileMods", PREF_BOOLEAN
, "True",
776 &PrefData
.warnRealFileMods
, NULL
, True
},
777 {"warnExit", "WarnExit", PREF_BOOLEAN
, "True",
778 &PrefData
.warnExit
, NULL
, True
},
779 {"searchMethod", "SearchMethod", PREF_ENUM
, "Literal",
780 &PrefData
.searchMethod
, SearchMethodStrings
, True
},
782 {"replaceDefaultScope", "ReplaceDefaultAllScope", PREF_ENUM
, "Smart",
783 &PrefData
.replaceDefScope
, ReplaceDefScopeStrings
, True
},
785 {"textRows", "TextRows", PREF_INT
, "24",
786 &PrefData
.textRows
, NULL
, True
},
787 {"textCols", "TextCols", PREF_INT
, "80",
788 &PrefData
.textCols
, NULL
, True
},
789 {"tabDistance", "TabDistance", PREF_INT
, "8",
790 &PrefData
.tabDist
, NULL
, True
},
791 {"emulateTabs", "EmulateTabs", PREF_INT
, "0",
792 &PrefData
.emTabDist
, NULL
, True
},
793 {"insertTabs", "InsertTabs", PREF_BOOLEAN
, "True",
794 &PrefData
.insertTabs
, NULL
, True
},
795 {"textFont", "TextFont", PREF_STRING
,
796 "-*-courier-medium-r-normal--*-120-*-*-*-iso8859-1",
797 PrefData
.fontString
, (void *)sizeof(PrefData
.fontString
), True
},
798 {"boldHighlightFont", "BoldHighlightFont", PREF_STRING
,
799 "-*-courier-bold-r-normal--*-120-*-*-*-iso8859-1",
800 PrefData
.boldFontString
, (void *)sizeof(PrefData
.boldFontString
), True
},
801 {"italicHighlightFont", "ItalicHighlightFont", PREF_STRING
,
802 "-*-courier-medium-o-normal--*-120-*-*-*-iso8859-1",
803 PrefData
.italicFontString
,
804 (void *)sizeof(PrefData
.italicFontString
), True
},
805 {"boldItalicHighlightFont", "BoldItalicHighlightFont", PREF_STRING
,
806 "-*-courier-bold-o-normal--*-120-*-*-*-iso8859-1",
807 PrefData
.boldItalicFontString
,
808 (void *)sizeof(PrefData
.boldItalicFontString
), True
},
809 {"helpFont", "helpFont", PREF_STRING
,
810 "-*-helvetica-medium-r-normal--*-120-*-*-*-iso8859-1",
811 PrefData
.helpFontNames
[HELP_FONT
],
812 (void *)sizeof(PrefData
.helpFontNames
[HELP_FONT
]), False
},
813 {"boldHelpFont", "BoldHelpFont", PREF_STRING
,
814 "-*-helvetica-bold-r-normal--*-120-*-*-*-iso8859-1",
815 PrefData
.helpFontNames
[BOLD_HELP_FONT
],
816 (void *)sizeof(PrefData
.helpFontNames
[BOLD_HELP_FONT
]), False
},
817 {"italicHelpFont", "ItalicHelpFont", PREF_STRING
,
818 "-*-helvetica-medium-o-normal--*-120-*-*-*-iso8859-1",
819 PrefData
.helpFontNames
[ITALIC_HELP_FONT
],
820 (void *)sizeof(PrefData
.helpFontNames
[ITALIC_HELP_FONT
]), False
},
821 {"boldItalicHelpFont", "BoldItalicHelpFont", PREF_STRING
,
822 "-*-helvetica-bold-o-normal--*-120-*-*-*-iso8859-1",
823 PrefData
.helpFontNames
[BOLD_ITALIC_HELP_FONT
],
824 (void *)sizeof(PrefData
.helpFontNames
[BOLD_ITALIC_HELP_FONT
]), False
},
825 {"fixedHelpFont", "fixedHelpFont", PREF_STRING
,
826 "-*-courier-medium-r-normal--*-120-*-*-*-iso8859-1",
827 PrefData
.helpFontNames
[FIXED_HELP_FONT
],
828 (void *)sizeof(PrefData
.helpFontNames
[FIXED_HELP_FONT
]), False
},
829 {"boldFixedHelpFont", "BoldFixedHelpFont", PREF_STRING
,
830 "-*-courier-bold-r-normal--*-120-*-*-*-iso8859-1",
831 PrefData
.helpFontNames
[BOLD_FIXED_HELP_FONT
],
832 (void *)sizeof(PrefData
.helpFontNames
[BOLD_FIXED_HELP_FONT
]), False
},
833 {"italicFixedHelpFont", "ItalicFixedHelpFont", PREF_STRING
,
834 "-*-courier-medium-o-normal--*-120-*-*-*-iso8859-1",
835 PrefData
.helpFontNames
[ITALIC_FIXED_HELP_FONT
],
836 (void *)sizeof(PrefData
.helpFontNames
[ITALIC_FIXED_HELP_FONT
]), False
},
837 {"boldItalicFixedHelpFont", "BoldItalicFixedHelpFont", PREF_STRING
,
838 "-*-courier-bold-o-normal--*-120-*-*-*-iso8859-1",
839 PrefData
.helpFontNames
[BOLD_ITALIC_FIXED_HELP_FONT
],
840 (void *)sizeof(PrefData
.helpFontNames
[BOLD_ITALIC_FIXED_HELP_FONT
]), False
},
841 {"helpLinkFont", "helpLinkFont", PREF_STRING
,
842 "-*-helvetica-medium-r-normal--*-120-*-*-*-iso8859-1",
843 PrefData
.helpFontNames
[HELP_LINK_FONT
],
844 (void *)sizeof(PrefData
.helpFontNames
[HELP_LINK_FONT
]), False
},
845 {"h1HelpFont", "H1HelpFont", PREF_STRING
,
846 "-*-helvetica-bold-r-normal--*-140-*-*-*-iso8859-1",
847 PrefData
.helpFontNames
[H1_HELP_FONT
],
848 (void *)sizeof(PrefData
.helpFontNames
[H1_HELP_FONT
]), False
},
849 {"h2HelpFont", "H2HelpFont", PREF_STRING
,
850 "-*-helvetica-bold-o-normal--*-120-*-*-*-iso8859-1",
851 PrefData
.helpFontNames
[H2_HELP_FONT
],
852 (void *)sizeof(PrefData
.helpFontNames
[H2_HELP_FONT
]), False
},
853 {"h3HelpFont", "H3HelpFont", PREF_STRING
,
854 "-*-courier-bold-r-normal--*-120-*-*-*-iso8859-1",
855 PrefData
.helpFontNames
[H3_HELP_FONT
],
856 (void *)sizeof(PrefData
.helpFontNames
[H3_HELP_FONT
]), False
},
857 {"helpLinkColor", "helpLinkColor", PREF_STRING
, "#009900",
858 PrefData
.helpLinkColor
,
859 (void *)sizeof(PrefData
.helpLinkColor
), False
},
861 {"textFgColor", "textFgColor", PREF_STRING
, NEDIT_DEFAULT_FG
,
862 PrefData
.colorNames
[TEXT_FG_COLOR
],
863 (void *)sizeof(PrefData
.colorNames
[TEXT_FG_COLOR
]), True
},
864 {"textBgColor", "textBgColor", PREF_STRING
, NEDIT_DEFAULT_TEXT_BG
,
865 PrefData
.colorNames
[TEXT_BG_COLOR
],
866 (void *)sizeof(PrefData
.colorNames
[TEXT_BG_COLOR
]), True
},
867 {"selectFgColor", "selectFgColor", PREF_STRING
, NEDIT_DEFAULT_SEL_FG
,
868 PrefData
.colorNames
[SELECT_FG_COLOR
],
869 (void *)sizeof(PrefData
.colorNames
[SELECT_FG_COLOR
]), True
},
870 {"selectBgColor", "selectBgColor", PREF_STRING
, NEDIT_DEFAULT_SEL_BG
,
871 PrefData
.colorNames
[SELECT_BG_COLOR
],
872 (void *)sizeof(PrefData
.colorNames
[SELECT_BG_COLOR
]), True
},
873 {"hiliteFgColor", "hiliteFgColor", PREF_STRING
, NEDIT_DEFAULT_HI_FG
,
874 PrefData
.colorNames
[HILITE_FG_COLOR
],
875 (void *)sizeof(PrefData
.colorNames
[HILITE_FG_COLOR
]), True
},
876 {"hiliteBgColor", "hiliteBgColor", PREF_STRING
, NEDIT_DEFAULT_HI_BG
,
877 PrefData
.colorNames
[HILITE_BG_COLOR
],
878 (void *)sizeof(PrefData
.colorNames
[HILITE_BG_COLOR
]), True
},
879 {"lineNoFgColor", "lineNoFgColor", PREF_STRING
, NEDIT_DEFAULT_LINENO_FG
,
880 PrefData
.colorNames
[LINENO_FG_COLOR
],
881 (void *)sizeof(PrefData
.colorNames
[LINENO_FG_COLOR
]), True
},
882 {"cursorFgColor", "cursorFgColor", PREF_STRING
, NEDIT_DEFAULT_CURSOR_FG
,
883 PrefData
.colorNames
[CURSOR_FG_COLOR
],
884 (void *)sizeof(PrefData
.colorNames
[CURSOR_FG_COLOR
]), True
},
886 {"shell", "Shell", PREF_STRING
,
887 #if defined(__MVS__) || defined(__EMX__)
892 PrefData
.shell
, (void *)sizeof(PrefData
.shell
), False
},
893 {"geometry", "Geometry", PREF_STRING
, "",
894 PrefData
.geometry
, (void *)sizeof(PrefData
.geometry
), False
},
895 {"remapDeleteKey", "RemapDeleteKey", PREF_BOOLEAN
, "False",
896 &PrefData
.mapDelete
, NULL
, False
},
897 {"stdOpenDialog", "StdOpenDialog", PREF_BOOLEAN
, "False",
898 &PrefData
.stdOpenDialog
, NULL
, False
},
899 {"tagFile", "TagFile", PREF_STRING
,
900 "", PrefData
.tagFile
, (void *)sizeof(PrefData
.tagFile
), False
},
901 {"wordDelimiters", "WordDelimiters", PREF_STRING
,
902 ".,/\\`'!|@#%^&*()-=+{}[]\":;<>?",
903 PrefData
.delimiters
, (void *)sizeof(PrefData
.delimiters
), False
},
904 {"serverName", "serverName", PREF_STRING
, "", PrefData
.serverName
,
905 (void *)sizeof(PrefData
.serverName
), False
},
906 {"maxPrevOpenFiles", "MaxPrevOpenFiles", PREF_INT
, "30",
907 &PrefData
.maxPrevOpenFiles
, NULL
, False
},
908 {"bgMenuButton", "BGMenuButton" , PREF_STRING
,
909 "~Shift~Ctrl~Meta~Alt<Btn3Down>", PrefData
.bgMenuBtn
,
910 (void *)sizeof(PrefData
.bgMenuBtn
), False
},
911 {"smartTags", "SmartTags", PREF_BOOLEAN
, "True",
912 &PrefData
.smartTags
, NULL
, True
},
913 {"typingHidesPointer", "TypingHidesPointer", PREF_BOOLEAN
, "False",
914 &PrefData
.typingHidesPointer
, NULL
, False
},
915 {"alwaysCheckRelativeTagsSpecs", "AlwaysCheckRelativeTagsSpecs",
916 PREF_BOOLEAN
, "True", &PrefData
.alwaysCheckRelativeTagsSpecs
, NULL
, False
},
917 {"prefFileRead", "PrefFileRead", PREF_BOOLEAN
, "False",
918 &PrefData
.prefFileRead
, NULL
, True
},
920 {"shortMenus", "ShortMenus", PREF_BOOLEAN
, "False", &PrefData
.shortMenus
,
923 {"findReplaceUsesSelection", "FindReplaceUsesSelection", PREF_BOOLEAN
, "False",
924 &PrefData
.findReplaceUsesSelection
, NULL
, False
},
925 {"overrideDefaultVirtualKeyBindings", "OverrideDefaultVirtualKeyBindings",
926 PREF_ENUM
, "Auto", &PrefData
.virtKeyOverride
, VirtKeyOverrideModes
, False
},
927 {"titleFormat", "TitleFormat", PREF_STRING
, "{%c} [%s] %f (%S) - %d",
928 PrefData
.titleFormat
, (void *)sizeof(PrefData
.titleFormat
), True
},
929 {"undoModifiesSelection", "UndoModifiesSelection", PREF_BOOLEAN
,
930 "True", &PrefData
.undoModifiesSelection
, NULL
, True
},
933 static XrmOptionDescRec OpTable
[] = {
934 {"-wrap", ".autoWrap", XrmoptionNoArg
, (caddr_t
)"Continuous"},
935 {"-nowrap", ".autoWrap", XrmoptionNoArg
, (caddr_t
)"None"},
936 {"-autowrap", ".autoWrap", XrmoptionNoArg
, (caddr_t
)"Newline"},
937 {"-noautowrap", ".autoWrap", XrmoptionNoArg
, (caddr_t
)"None"},
938 {"-autoindent", ".autoIndent", XrmoptionNoArg
, (caddr_t
)"Auto"},
939 {"-noautoindent", ".autoIndent", XrmoptionNoArg
, (caddr_t
)"False"},
940 {"-autosave", ".autoSave", XrmoptionNoArg
, (caddr_t
)"True"},
941 {"-noautosave", ".autoSave", XrmoptionNoArg
, (caddr_t
)"False"},
942 {"-rows", ".textRows", XrmoptionSepArg
, (caddr_t
)NULL
},
943 {"-columns", ".textCols", XrmoptionSepArg
, (caddr_t
)NULL
},
944 {"-tabs", ".tabDistance", XrmoptionSepArg
, (caddr_t
)NULL
},
945 {"-font", ".textFont", XrmoptionSepArg
, (caddr_t
)NULL
},
946 {"-fn", ".textFont", XrmoptionSepArg
, (caddr_t
)NULL
},
947 {"-svrname", ".serverName", XrmoptionSepArg
, (caddr_t
)NULL
},
950 static const char HeaderText
[] = "\
951 ! Preferences file for NEdit\n\
953 ! This file is overwritten by the \"Save Defaults...\" command in NEdit \n\
954 ! and serves only the interactively settable options presented in the NEdit\n\
955 ! \"Preferences\" menu. To modify other options, such as key bindings, use \n\
956 ! the .Xdefaults file in your home directory (or the X resource \n\
957 ! specification method appropriate to your system). The contents of this \n\
958 ! file can be moved into an X resource file, but since resources in this file\n\
959 ! override their corresponding X resources, either this file should be \n\
960 ! deleted or individual resource lines in the file should be deleted for the\n\
961 ! moved lines to take effect.\n";
963 /* Module-global variable set when any preference changes (for asking the
964 user about re-saving on exit) */
965 static int PrefsHaveChanged
= False
;
967 /* Module-global variable set when user uses -import to load additional
968 preferences on top of the defaults. Contains name of file loaded */
969 static char *ImportedFile
= NULL
;
971 /* Module-global variables to support Initial Window Size... dialog */
972 static int DoneWithSizeDialog
;
973 static Widget RowText
, ColText
;
975 /* Module-global variables for Tabs dialog */
976 static int DoneWithTabsDialog
;
977 static WindowInfo
*TabsDialogForWindow
;
978 static Widget TabDistText
, EmTabText
, EmTabToggle
, UseTabsToggle
, EmTabLabel
;
980 /* Module-global variables for Wrap Margin dialog */
981 static int DoneWithWrapDialog
;
982 static WindowInfo
*WrapDialogForWindow
;
983 static Widget WrapText
, WrapTextLabel
, WrapWindowToggle
;
985 static void translatePrefFormats(int convertOld
, int fileVer
);
986 static void setIntPref(int *prefDataField
, int newValue
);
987 static void setStringPref(char *prefDataField
, const char *newValue
);
988 static void sizeOKCB(Widget w
, XtPointer clientData
, XtPointer callData
);
989 static void setStringAllocPref(char **pprefDataField
, char *newValue
);
990 static void sizeCancelCB(Widget w
, XtPointer clientData
, XtPointer callData
);
991 static void tabsOKCB(Widget w
, XtPointer clientData
, XtPointer callData
);
992 static void tabsCancelCB(Widget w
, XtPointer clientData
, XtPointer callData
);
993 static void tabsHelpCB(Widget w
, XtPointer clientData
, XtPointer callData
);
994 static void emTabsCB(Widget w
, XtPointer clientData
, XtPointer callData
);
995 static void wrapOKCB(Widget w
, XtPointer clientData
, XtPointer callData
);
996 static void wrapCancelCB(Widget w
, XtPointer clientData
, XtPointer callData
);
997 static void wrapWindowCB(Widget w
, XtPointer clientData
, XtPointer callData
);
998 static void reapplyLanguageMode(WindowInfo
*window
, int mode
,int forceDefaults
);
1001 static void fillFromPrimaryCB(Widget w
, XtPointer clientData
,
1002 XtPointer callData
);
1003 static int checkFontStatus(fontDialog
*fd
, Widget fontTextFieldW
);
1004 static int showFontStatus(fontDialog
*fd
, Widget fontTextFieldW
,
1005 Widget errorLabelW
);
1006 static void primaryModifiedCB(Widget w
, XtPointer clientData
,
1007 XtPointer callData
);
1008 static void italicModifiedCB(Widget w
, XtPointer clientData
,
1009 XtPointer callData
);
1010 static void boldModifiedCB(Widget w
, XtPointer clientData
, XtPointer callData
);
1011 static void boldItalicModifiedCB(Widget w
, XtPointer clientData
,
1012 XtPointer callData
);
1013 static void primaryBrowseCB(Widget w
, XtPointer clientData
, XtPointer callData
);
1014 static void italicBrowseCB(Widget w
, XtPointer clientData
, XtPointer callData
);
1015 static void boldBrowseCB(Widget w
, XtPointer clientData
, XtPointer callData
);
1016 static void boldItalicBrowseCB(Widget w
, XtPointer clientData
,
1017 XtPointer callData
);
1018 static void browseFont(Widget parent
, Widget fontTextW
, fontDialog
*fd
);
1019 static void fontDestroyCB(Widget w
, XtPointer clientData
, XtPointer callData
);
1020 static void fontOkCB(Widget w
, XtPointer clientData
, XtPointer callData
);
1021 static void fontApplyCB(Widget w
, XtPointer clientData
, XtPointer callData
);
1022 static void fontDismissCB(Widget w
, XtPointer clientData
, XtPointer callData
);
1023 static void updateFonts(fontDialog
*fd
);
1025 static Boolean
checkColorStatus(colorDialog
*cd
, Widget colorFieldW
);
1026 static int verifyAllColors (colorDialog
*cd
);
1027 static void showColorStatus (colorDialog
*cd
, Widget colorFieldW
,
1028 Widget errorLabelW
);
1029 static void updateColors(colorDialog
*cd
);
1030 static void colorDestroyCB(Widget w
, XtPointer clientData
, XtPointer callData
);
1031 static void colorOkCB (Widget w
, XtPointer clientData
, XtPointer callData
);
1032 static void colorApplyCB (Widget w
, XtPointer clientData
, XtPointer callData
);
1033 static void colorDismissCB(Widget w
, XtPointer clientData
, XtPointer callData
);
1034 static void textFgModifiedCB (Widget w
, XtPointer clientData
,
1035 XtPointer callData
);
1036 static void textBgModifiedCB (Widget w
, XtPointer clientData
,
1037 XtPointer callData
);
1038 static void selectFgModifiedCB(Widget w
, XtPointer clientData
,
1039 XtPointer callData
);
1040 static void selectBgModifiedCB(Widget w
, XtPointer clientData
,
1041 XtPointer callData
);
1042 static void hiliteFgModifiedCB(Widget w
, XtPointer clientData
,
1043 XtPointer callData
);
1044 static void hiliteBgModifiedCB(Widget w
, XtPointer clientData
,
1045 XtPointer callData
);
1046 static void lineNoFgModifiedCB(Widget w
, XtPointer clientData
,
1047 XtPointer callData
);
1048 static void cursorFgModifiedCB(Widget w
, XtPointer clientData
,
1049 XtPointer callData
);
1051 static int matchLanguageMode(WindowInfo
*window
);
1052 static int loadLanguageModesString(char *inString
, int fileVer
);
1053 static char *writeLanguageModesString(void);
1054 static char *createExtString(char **extensions
, int nExtensions
);
1055 static char **readExtensionList(char **inPtr
, int *nExtensions
);
1056 static void updateLanguageModeSubmenu(WindowInfo
*window
);
1057 static void setLangModeCB(Widget w
, XtPointer clientData
, XtPointer callData
);
1058 static int modeError(languageModeRec
*lm
, const char *stringStart
,
1059 const char *stoppedAt
, const char *message
);
1060 static void lmDestroyCB(Widget w
, XtPointer clientData
, XtPointer callData
);
1061 static void lmOkCB(Widget w
, XtPointer clientData
, XtPointer callData
);
1062 static void lmApplyCB(Widget w
, XtPointer clientData
, XtPointer callData
);
1063 static void lmDismissCB(Widget w
, XtPointer clientData
, XtPointer callData
);
1064 static int lmDeleteConfirmCB(int itemIndex
, void *cbArg
);
1065 static int updateLMList(void);
1066 static languageModeRec
*copyLanguageModeRec(languageModeRec
*lm
);
1067 static void *lmGetDisplayedCB(void *oldItem
, int explicitRequest
, int *abort
,
1069 static void lmSetDisplayedCB(void *item
, void *cbArg
);
1070 static languageModeRec
*readLMDialogFields(int silent
);
1071 static void lmFreeItemCB(void *item
);
1072 static void freeLanguageModeRec(languageModeRec
*lm
);
1073 static int lmDialogEmpty(void);
1074 static void updatePatternsTo5dot1(void);
1075 static void updatePatternsTo5dot2(void);
1076 static void updatePatternsTo5dot3(void);
1077 static void updatePatternsTo5dot4(void);
1078 static void updateShellCmdsTo5dot3(void);
1079 static void updateShellCmdsTo5dot4(void);
1080 static void migrateColorResources(XrmDatabase prefDB
, XrmDatabase appDB
);
1081 static void spliceString(char **intoString
, const char *insertString
, const char *atExpr
);
1082 static int regexFind(const char *inString
, const char *expr
);
1083 static int regexReplace(char **inString
, const char *expr
,
1084 const char *replaceWith
);
1087 static int shortPrefToDefault(Widget parent
, const char *settingName
, int *setDefault
);
1090 XrmDatabase
CreateNEditPrefDB(int *argcInOut
, char **argvInOut
)
1092 return CreatePreferencesDatabase(GetRCFileName(NEDIT_RC
), APP_NAME
,
1093 OpTable
, XtNumber(OpTable
), (unsigned int *)argcInOut
, argvInOut
);
1096 void RestoreNEditPrefs(XrmDatabase prefDB
, XrmDatabase appDB
)
1098 int requiresConversion
;
1099 int major
; /* The integral part of version number */
1100 int minor
; /* fractional part of version number */
1101 int fileVer
= 0; /* Both combined into an integer */
1104 /* Load preferences */
1105 RestorePreferences(prefDB
, appDB
, APP_NAME
,
1106 APP_CLASS
, PrefDescrip
, XtNumber(PrefDescrip
));
1108 /* If the preferences file was written by an older version of NEdit,
1109 warn the user that it will be converted. */
1110 requiresConversion
= PrefData
.prefFileRead
&&
1111 PrefData
.fileVersion
[0] == '\0';
1112 if (requiresConversion
) {
1113 updatePatternsTo5dot1();
1116 if (PrefData
.prefFileRead
) {
1117 if (PrefData
.fileVersion
[0] == '\0') {
1118 fileVer
= 0; /* Pre-5.1 */
1121 /* Note: do not change the format of this. Older executables
1122 need to read this field for forward compatability. */
1123 nparsed
= sscanf(PrefData
.fileVersion
, "%d.%d", &major
, &minor
);
1125 /* Use OSF-style numbering scheme */
1126 fileVer
= major
* 1000 + minor
;
1131 if (PrefData
.prefFileRead
&& fileVer
< 5002) {
1132 updatePatternsTo5dot2();
1135 if (PrefData
.prefFileRead
&& fileVer
< 5003) {
1136 updateShellCmdsTo5dot3();
1137 updatePatternsTo5dot3();
1140 /* Note that we don't care about unreleased file versions. Anyone
1141 who is running a CVS or alpha version of NEdit is resposnbile
1142 for managing the preferences file themselves. Otherwise, it
1143 gets impossible to track the number of "in-between" file formats.
1144 We only do auto-upgrading for a real release. */
1146 if (PrefData
.prefFileRead
&& (fileVer
< 5004)) {
1147 /* There are some implict conversions done later - show this
1148 message even if there's no explicit call to upgrade. */
1149 fprintf(stderr
, "NEdit: Converting .nedit file to 5.4 version.\n"
1150 " To keep, use Preferences -> Save Defaults\n");
1152 /* XXX: When 5.4 is released we should move the following lines into
1153 the above if stmt. It's here now for developers who have been using CVS
1154 versions and want their colors and patterns migrated. */
1155 migrateColorResources(prefDB
, appDB
);
1156 updateShellCmdsTo5dot4();
1157 updatePatternsTo5dot4();
1159 /* Do further parsing on resource types which RestorePreferences does
1160 not understand and reads as strings, to put them in the final form
1161 in which nedit stores and uses. If the preferences file was
1162 written by an older version of NEdit, update regular expressions in
1163 highlight patterns to quote braces and use & instead of \0 */
1164 translatePrefFormats(requiresConversion
, fileVer
);
1168 ** Many of of NEdit's preferences are much more complicated than just simple
1169 ** integers or strings. These are read as strings, but must be parsed and
1170 ** translated into something meaningful. This routine does the translation,
1171 ** and, in most cases, frees the original string, which is no longer useful.
1173 ** The argument convertOld attempts a conversion from pre 5.1 format .nedit
1174 ** files (which means patterns and macros may contain regular expressions
1175 ** which are of the older syntax where braces were not quoted, and \0 was a
1176 ** legal substitution character). Macros, so far can not be automatically
1177 ** converted, unfortunately.
1179 static void translatePrefFormats(int convertOld
, int fileVer
)
1183 /* Parse the strings which represent types which are not decoded by
1184 the standard resource manager routines */
1186 if (TempStringPrefs
.shellCmds
!= NULL
) {
1187 LoadShellCmdsString(TempStringPrefs
.shellCmds
);
1188 XtFree(TempStringPrefs
.shellCmds
);
1189 TempStringPrefs
.shellCmds
= NULL
;
1192 if (TempStringPrefs
.macroCmds
!= NULL
) {
1193 LoadMacroCmdsString(TempStringPrefs
.macroCmds
);
1194 XtFree(TempStringPrefs
.macroCmds
);
1195 TempStringPrefs
.macroCmds
= NULL
;
1197 if (TempStringPrefs
.bgMenuCmds
!= NULL
) {
1198 LoadBGMenuCmdsString(TempStringPrefs
.bgMenuCmds
);
1199 XtFree(TempStringPrefs
.bgMenuCmds
);
1200 TempStringPrefs
.bgMenuCmds
= NULL
;
1202 if (TempStringPrefs
.highlight
!= NULL
) {
1203 LoadHighlightString(TempStringPrefs
.highlight
, convertOld
);
1204 XtFree(TempStringPrefs
.highlight
);
1205 TempStringPrefs
.highlight
= NULL
;
1207 if (TempStringPrefs
.styles
!= NULL
) {
1208 LoadStylesString(TempStringPrefs
.styles
);
1209 XtFree(TempStringPrefs
.styles
);
1210 TempStringPrefs
.styles
= NULL
;
1212 if (TempStringPrefs
.language
!= NULL
) {
1213 loadLanguageModesString(TempStringPrefs
.language
, fileVer
);
1214 XtFree(TempStringPrefs
.language
);
1215 TempStringPrefs
.language
= NULL
;
1217 if (TempStringPrefs
.smartIndent
!= NULL
) {
1218 LoadSmartIndentString(TempStringPrefs
.smartIndent
);
1219 XtFree(TempStringPrefs
.smartIndent
);
1220 TempStringPrefs
.smartIndent
= NULL
;
1222 if (TempStringPrefs
.smartIndentCommon
!= NULL
) {
1223 LoadSmartIndentCommonString(TempStringPrefs
.smartIndentCommon
);
1224 XtFree(TempStringPrefs
.smartIndentCommon
);
1225 TempStringPrefs
.smartIndentCommon
= NULL
;
1228 /* translate the font names into fontLists suitable for the text widget */
1229 font
= XLoadQueryFont(TheDisplay
, PrefData
.fontString
);
1230 PrefData
.fontList
= font
==NULL
? NULL
:
1231 XmFontListCreate(font
, XmSTRING_DEFAULT_CHARSET
);
1232 PrefData
.boldFontStruct
= XLoadQueryFont(TheDisplay
,
1233 PrefData
.boldFontString
);
1234 PrefData
.italicFontStruct
= XLoadQueryFont(TheDisplay
,
1235 PrefData
.italicFontString
);
1236 PrefData
.boldItalicFontStruct
= XLoadQueryFont(TheDisplay
,
1237 PrefData
.boldItalicFontString
);
1239 /* For compatability with older (4.0.3 and before) versions, the autoWrap
1240 and autoIndent resources can accept values of True and False. Translate
1241 them into acceptable wrap and indent styles */
1242 if (PrefData
.wrapStyle
== 3) PrefData
.wrapStyle
= NEWLINE_WRAP
;
1243 if (PrefData
.wrapStyle
== 4) PrefData
.wrapStyle
= NO_WRAP
;
1244 if (PrefData
.autoIndent
== 3) PrefData
.autoIndent
= AUTO_INDENT
;
1245 if (PrefData
.autoIndent
== 4) PrefData
.autoIndent
= NO_AUTO_INDENT
;
1248 void SaveNEditPrefs(Widget parent
, int quietly
)
1250 const char* prefFileName
= GetRCFileName(NEDIT_RC
);
1251 if (prefFileName
== NULL
)
1253 /* GetRCFileName() might return NULL if an error occurs during
1254 creation of the preference file directory. */
1255 DialogF(DF_WARN
, parent
, 1, "Error saving Preferences",
1256 "Unable to save preferences: Cannot determine filename.",
1262 if (DialogF(DF_INF
, parent
, 2, "Save imported Settings",
1263 ImportedFile
== NULL
?
1264 "Default preferences will be saved in the file:\n"
1266 "NEdit automatically loads this file\n"
1267 "each time it is started." :
1268 "Default preferences will be saved in the file:\n"
1270 "SAVING WILL INCORPORATE SETTINGS\n"
1271 "FROM FILE: %s", "OK", "Cancel",
1272 prefFileName
, ImportedFile
) == 2)
1276 TempStringPrefs
.shellCmds
= WriteShellCmdsString();
1278 TempStringPrefs
.macroCmds
= WriteMacroCmdsString();
1279 TempStringPrefs
.bgMenuCmds
= WriteBGMenuCmdsString();
1280 TempStringPrefs
.highlight
= WriteHighlightString();
1281 TempStringPrefs
.language
= writeLanguageModesString();
1282 TempStringPrefs
.styles
= WriteStylesString();
1283 TempStringPrefs
.smartIndent
= WriteSmartIndentString();
1284 TempStringPrefs
.smartIndentCommon
= WriteSmartIndentCommonString();
1285 strcpy(PrefData
.fileVersion
, PREF_FILE_VERSION
);
1286 if (!SavePreferences(XtDisplay(parent
), prefFileName
, HeaderText
,
1287 PrefDescrip
, XtNumber(PrefDescrip
)))
1289 DialogF(DF_WARN
, parent
, 1, "Save Preferences",
1290 "Unable to save preferences in %s", "Dismiss", prefFileName
);
1294 XtFree(TempStringPrefs
.shellCmds
);
1296 XtFree(TempStringPrefs
.macroCmds
);
1297 XtFree(TempStringPrefs
.bgMenuCmds
);
1298 XtFree(TempStringPrefs
.highlight
);
1299 XtFree(TempStringPrefs
.language
);
1300 XtFree(TempStringPrefs
.styles
);
1301 XtFree(TempStringPrefs
.smartIndent
);
1302 XtFree(TempStringPrefs
.smartIndentCommon
);
1304 PrefsHaveChanged
= False
;
1308 ** Load an additional preferences file on top of the existing preferences
1309 ** derived from defaults, the .nedit file, and X resources.
1311 void ImportPrefFile(const char *filename
, int convertOld
)
1316 fileString
= ReadAnyTextFile(filename
);
1317 if (fileString
!= NULL
){
1318 db
= XrmGetStringDatabase(fileString
);
1320 OverlayPreferences(db
, APP_NAME
, APP_CLASS
, PrefDescrip
,
1321 XtNumber(PrefDescrip
));
1322 translatePrefFormats(convertOld
, -1);
1323 ImportedFile
= XtNewString(filename
);
1326 fprintf(stderr
, "Could not read additional preferences file: ");
1327 fprintf(stderr
, filename
);
1328 fprintf(stderr
, "\n");
1332 void SetPrefWrap(int state
)
1334 setIntPref(&PrefData
.wrapStyle
, state
);
1337 int GetPrefWrap(int langMode
)
1339 if (langMode
== PLAIN_LANGUAGE_MODE
||
1340 LanguageModes
[langMode
]->wrapStyle
== DEFAULT_WRAP
)
1341 return PrefData
.wrapStyle
;
1342 return LanguageModes
[langMode
]->wrapStyle
;
1345 void SetPrefWrapMargin(int margin
)
1347 setIntPref(&PrefData
.wrapMargin
, margin
);
1350 int GetPrefWrapMargin(void)
1352 return PrefData
.wrapMargin
;
1355 void SetPrefSearch(int searchType
)
1357 setIntPref(&PrefData
.searchMethod
, searchType
);
1360 int GetPrefSearch(void)
1362 return PrefData
.searchMethod
;
1365 #ifdef REPLACE_SCOPE
1366 void SetPrefReplaceDefScope(int scope
)
1368 setIntPref(&PrefData
.replaceDefScope
, scope
);
1371 int GetPrefReplaceDefScope(void)
1373 return PrefData
.replaceDefScope
;
1377 void SetPrefAutoIndent(int state
)
1379 setIntPref(&PrefData
.autoIndent
, state
);
1382 int GetPrefAutoIndent(int langMode
)
1384 if (langMode
== PLAIN_LANGUAGE_MODE
||
1385 LanguageModes
[langMode
]->indentStyle
== DEFAULT_INDENT
)
1386 return PrefData
.autoIndent
;
1387 return LanguageModes
[langMode
]->indentStyle
;
1390 void SetPrefAutoSave(int state
)
1392 setIntPref(&PrefData
.autoSave
, state
);
1395 int GetPrefAutoSave(void)
1397 return PrefData
.autoSave
;
1400 void SetPrefSaveOldVersion(int state
)
1402 setIntPref(&PrefData
.saveOldVersion
, state
);
1405 int GetPrefSaveOldVersion(void)
1407 return PrefData
.saveOldVersion
;
1410 void SetPrefSearchDlogs(int state
)
1412 setIntPref(&PrefData
.searchDlogs
, state
);
1415 int GetPrefSearchDlogs(void)
1417 return PrefData
.searchDlogs
;
1420 void SetPrefBeepOnSearchWrap(int state
)
1422 setIntPref(&PrefData
.searchWrapBeep
, state
);
1425 int GetPrefBeepOnSearchWrap(void)
1427 return PrefData
.searchWrapBeep
;
1430 void SetPrefKeepSearchDlogs(int state
)
1432 setIntPref(&PrefData
.keepSearchDlogs
, state
);
1435 int GetPrefKeepSearchDlogs(void)
1437 return PrefData
.keepSearchDlogs
;
1440 void SetPrefSearchWraps(int state
)
1442 setIntPref(&PrefData
.searchWraps
, state
);
1445 int GetPrefStickyCaseSenseBtn(void)
1447 return PrefData
.stickyCaseSenseBtn
;
1450 void SetPrefStickyCaseSenseBtn(int state
)
1452 setIntPref(&PrefData
.stickyCaseSenseBtn
, state
);
1455 int GetPrefSearchWraps(void)
1457 return PrefData
.searchWraps
;
1460 void SetPrefStatsLine(int state
)
1462 setIntPref(&PrefData
.statsLine
, state
);
1465 int GetPrefStatsLine(void)
1467 return PrefData
.statsLine
;
1470 void SetPrefISearchLine(int state
)
1472 setIntPref(&PrefData
.iSearchLine
, state
);
1475 int GetPrefISearchLine(void)
1477 return PrefData
.iSearchLine
;
1480 void SetPrefLineNums(int state
)
1482 setIntPref(&PrefData
.lineNums
, state
);
1485 int GetPrefLineNums(void)
1487 return PrefData
.lineNums
;
1490 void SetPrefShowPathInWindowsMenu(int state
)
1492 setIntPref(&PrefData
.pathInWindowsMenu
, state
);
1495 int GetPrefShowPathInWindowsMenu(void)
1497 return PrefData
.pathInWindowsMenu
;
1500 void SetPrefWarnFileMods(int state
)
1502 setIntPref(&PrefData
.warnFileMods
, state
);
1505 int GetPrefWarnFileMods(void)
1507 return PrefData
.warnFileMods
;
1510 void SetPrefWarnRealFileMods(int state
)
1512 setIntPref(&PrefData
.warnRealFileMods
, state
);
1515 int GetPrefWarnRealFileMods(void)
1517 return PrefData
.warnRealFileMods
;
1520 void SetPrefWarnExit(int state
)
1522 setIntPref(&PrefData
.warnExit
, state
);
1525 int GetPrefWarnExit(void)
1527 return PrefData
.warnExit
;
1530 void SetPrefv(int state
)
1532 setIntPref(&PrefData
.findReplaceUsesSelection
, state
);
1535 int GetPrefFindReplaceUsesSelection(void)
1537 return PrefData
.findReplaceUsesSelection
;
1540 void SetPrefMapDelete(int state
)
1542 setIntPref(&PrefData
.mapDelete
, state
);
1545 int GetPrefMapDelete(void)
1547 return PrefData
.mapDelete
;
1550 void SetPrefStdOpenDialog(int state
)
1552 setIntPref(&PrefData
.stdOpenDialog
, state
);
1555 int GetPrefStdOpenDialog(void)
1557 return PrefData
.stdOpenDialog
;
1560 void SetPrefRows(int nRows
)
1562 setIntPref(&PrefData
.textRows
, nRows
);
1565 int GetPrefRows(void)
1567 return PrefData
.textRows
;
1570 void SetPrefCols(int nCols
)
1572 setIntPref(&PrefData
.textCols
, nCols
);
1575 int GetPrefCols(void)
1577 return PrefData
.textCols
;
1580 void SetPrefTabDist(int tabDist
)
1582 setIntPref(&PrefData
.tabDist
, tabDist
);
1585 int GetPrefTabDist(int langMode
)
1588 if (langMode
== PLAIN_LANGUAGE_MODE
||
1589 LanguageModes
[langMode
]->tabDist
== DEFAULT_TAB_DIST
) {
1590 tabDist
= PrefData
.tabDist
;
1592 tabDist
= LanguageModes
[langMode
]->tabDist
;
1594 /* Make sure that the tab distance is in range (garbage may have
1595 been entered via the command line or the X resources, causing
1596 errors later on, like division by zero). */
1597 if (tabDist
<= 0) return 1;
1598 if (tabDist
> MAX_EXP_CHAR_LEN
) return MAX_EXP_CHAR_LEN
;
1602 void SetPrefEmTabDist(int tabDist
)
1604 setIntPref(&PrefData
.emTabDist
, tabDist
);
1607 int GetPrefEmTabDist(int langMode
)
1609 if (langMode
== PLAIN_LANGUAGE_MODE
||
1610 LanguageModes
[langMode
]->emTabDist
== DEFAULT_EM_TAB_DIST
)
1611 return PrefData
.emTabDist
;
1612 return LanguageModes
[langMode
]->emTabDist
;
1615 void SetPrefInsertTabs(int state
)
1617 setIntPref(&PrefData
.insertTabs
, state
);
1620 int GetPrefInsertTabs(void)
1622 return PrefData
.insertTabs
;
1625 void SetPrefShowMatching(int state
)
1627 setIntPref(&PrefData
.showMatchingStyle
, state
);
1630 int GetPrefShowMatching(void)
1633 * For backwards compatibility with pre-5.2 versions, the boolean
1634 * False/True matching behavior is converted to NO_FLASH/FLASH_DELIMIT.
1636 if (PrefData
.showMatchingStyle
>= N_SHOW_MATCHING_STYLES
)
1637 PrefData
.showMatchingStyle
-= N_SHOW_MATCHING_STYLES
;
1638 return PrefData
.showMatchingStyle
;
1641 void SetPrefMatchSyntaxBased(int state
)
1643 setIntPref(&PrefData
.matchSyntaxBased
, state
);
1646 int GetPrefMatchSyntaxBased(void)
1648 return PrefData
.matchSyntaxBased
;
1651 void SetPrefHighlightSyntax(int state
)
1653 setIntPref(&PrefData
.highlightSyntax
, state
);
1656 int GetPrefHighlightSyntax(void)
1658 return PrefData
.highlightSyntax
;
1661 void SetPrefBacklightChars(int state
)
1663 setIntPref(&PrefData
.backlightChars
, state
);
1666 int GetPrefBacklightChars(void)
1668 return PrefData
.backlightChars
;
1671 void SetPrefBacklightCharTypes(char *types
)
1673 setStringAllocPref(&PrefData
.backlightCharTypes
, types
);
1676 char *GetPrefBacklightCharTypes(void)
1678 return PrefData
.backlightCharTypes
;
1681 void SetPrefRepositionDialogs(int state
)
1683 setIntPref(&PrefData
.repositionDialogs
, state
);
1686 int GetPrefRepositionDialogs(void)
1688 return PrefData
.repositionDialogs
;
1691 void SetPrefAppendLF(int state
)
1693 setIntPref(&PrefData
.appendLF
, state
);
1696 int GetPrefAppendLF(void)
1698 return PrefData
.appendLF
;
1701 void SetPrefSortOpenPrevMenu(int state
)
1703 setIntPref(&PrefData
.sortOpenPrevMenu
, state
);
1706 int GetPrefSortOpenPrevMenu(void)
1708 return PrefData
.sortOpenPrevMenu
;
1711 void SetPrefTagFile(const char *tagFileName
)
1713 setStringPref(PrefData
.tagFile
, tagFileName
);
1716 char *GetPrefTagFile(void)
1718 return PrefData
.tagFile
;
1721 void SetPrefSmartTags(int state
)
1723 setIntPref(&PrefData
.smartTags
, state
);
1726 int GetPrefSmartTags(void)
1728 return PrefData
.smartTags
;
1731 int GetPrefAlwaysCheckRelTagsSpecs(void)
1733 return PrefData
.alwaysCheckRelativeTagsSpecs
;
1736 char *GetPrefDelimiters(void)
1738 return PrefData
.delimiters
;
1741 char *GetPrefColorName(int index
)
1743 return PrefData
.colorNames
[index
];
1746 void SetPrefColorName(int index
, const char *name
)
1748 setStringPref(PrefData
.colorNames
[index
], name
);
1752 ** Set the font preferences using the font name (the fontList is generated
1753 ** in this call). Note that this leaks memory and server resources each
1754 ** time the default font is re-set. See note on SetFontByName in window.c
1755 ** for more information.
1757 void SetPrefFont(char *fontName
)
1761 setStringPref(PrefData
.fontString
, fontName
);
1762 font
= XLoadQueryFont(TheDisplay
, fontName
);
1763 PrefData
.fontList
= font
==NULL
? NULL
:
1764 XmFontListCreate(font
, XmSTRING_DEFAULT_CHARSET
);
1767 void SetPrefBoldFont(char *fontName
)
1769 setStringPref(PrefData
.boldFontString
, fontName
);
1770 PrefData
.boldFontStruct
= XLoadQueryFont(TheDisplay
, fontName
);
1773 void SetPrefItalicFont(char *fontName
)
1775 setStringPref(PrefData
.italicFontString
, fontName
);
1776 PrefData
.italicFontStruct
= XLoadQueryFont(TheDisplay
, fontName
);
1778 void SetPrefBoldItalicFont(char *fontName
)
1780 setStringPref(PrefData
.boldItalicFontString
, fontName
);
1781 PrefData
.boldItalicFontStruct
= XLoadQueryFont(TheDisplay
, fontName
);
1784 char *GetPrefFontName(void)
1786 return PrefData
.fontString
;
1789 char *GetPrefBoldFontName(void)
1791 return PrefData
.boldFontString
;
1794 char *GetPrefItalicFontName(void)
1796 return PrefData
.italicFontString
;
1799 char *GetPrefBoldItalicFontName(void)
1801 return PrefData
.boldItalicFontString
;
1804 XmFontList
GetPrefFontList(void)
1806 return PrefData
.fontList
;
1809 XFontStruct
*GetPrefBoldFont(void)
1811 return PrefData
.boldFontStruct
;
1814 XFontStruct
*GetPrefItalicFont(void)
1816 return PrefData
.italicFontStruct
;
1819 XFontStruct
*GetPrefBoldItalicFont(void)
1821 return PrefData
.boldItalicFontStruct
;
1824 char *GetPrefHelpFontName(int index
)
1826 return PrefData
.helpFontNames
[index
];
1829 char *GetPrefHelpLinkColor(void)
1831 return PrefData
.helpLinkColor
;
1834 void SetPrefShell(const char *shell
)
1836 setStringPref(PrefData
.shell
, shell
);
1839 char *GetPrefShell(void)
1841 return PrefData
.shell
;
1844 void SetPrefGeometry(const char *geometry
)
1846 setStringPref(PrefData
.geometry
, geometry
);
1849 char *GetPrefGeometry(void)
1851 return PrefData
.geometry
;
1854 char *GetPrefServerName(void)
1856 return PrefData
.serverName
;
1859 char *GetPrefBGMenuBtn(void)
1861 return PrefData
.bgMenuBtn
;
1864 int GetPrefMaxPrevOpenFiles(void)
1866 return PrefData
.maxPrevOpenFiles
;
1869 int GetPrefTypingHidesPointer(void)
1871 return(PrefData
.typingHidesPointer
);
1875 void SetPrefShortMenus(int state
)
1877 setIntPref(&PrefData
.shortMenus
, state
);
1880 int GetPrefShortMenus(void)
1882 return PrefData
.shortMenus
;
1886 void SetPrefTitleFormat(const char* format
)
1888 const WindowInfo
* window
;
1890 setStringPref(PrefData
.titleFormat
, format
);
1892 /* update all windows */
1893 for (window
=WindowList
; window
!=NULL
; window
=window
->next
) {
1894 UpdateWindowTitle(window
);
1897 const char* GetPrefTitleFormat(void)
1899 return PrefData
.titleFormat
;
1902 void SetPrefUndoModifiesSelection(Boolean value
)
1904 setIntPref(&PrefData
.undoModifiesSelection
, value
);
1907 Boolean
GetPrefUndoModifiesSelection(void)
1909 return (Boolean
)PrefData
.undoModifiesSelection
;
1912 int GetPrefOverrideVirtKeyBindings(void)
1914 return PrefData
.virtKeyOverride
;
1918 ** If preferences don't get saved, ask the user on exit whether to save
1920 void MarkPrefsChanged(void)
1922 PrefsHaveChanged
= True
;
1926 ** Check if preferences have changed, and if so, ask the user if he wants
1927 ** to re-save. Returns False if user requests cancelation of Exit (or whatever
1928 ** operation triggered this call to be made).
1930 int CheckPrefsChangesSaved(Widget dialogParent
)
1934 if (!PrefsHaveChanged
)
1937 resp
= DialogF(DF_WARN
, dialogParent
, 3, "Default Preferences",
1938 ImportedFile
== NULL
?
1939 "Default Preferences have changed.\n"
1940 "Save changes to NEdit preference file?" :
1941 "Default Preferences have changed. SAVING \n"
1942 "CHANGES WILL INCORPORATE ADDITIONAL\nSETTINGS FROM FILE: %s",
1943 "Save", "Don't Save", "Cancel", ImportedFile
);
1949 SaveNEditPrefs(dialogParent
, True
);
1954 ** set *prefDataField to newValue, but first check if they're different
1955 ** and update PrefsHaveChanged if a preference setting has now changed.
1957 static void setIntPref(int *prefDataField
, int newValue
)
1959 if (newValue
!= *prefDataField
)
1960 PrefsHaveChanged
= True
;
1961 *prefDataField
= newValue
;
1964 static void setStringPref(char *prefDataField
, const char *newValue
)
1966 if (strcmp(prefDataField
, newValue
))
1967 PrefsHaveChanged
= True
;
1968 strcpy(prefDataField
, newValue
);
1971 static void setStringAllocPref(char **pprefDataField
, char *newValue
)
1975 /* treat empty strings as nulls */
1976 if (newValue
&& *newValue
== '\0')
1978 if (*pprefDataField
&& **pprefDataField
== '\0')
1979 *pprefDataField
= NULL
; /* assume statically alloc'ed "" */
1982 if (!*pprefDataField
&& !newValue
)
1984 else if (!*pprefDataField
&& newValue
)
1985 PrefsHaveChanged
= True
;
1986 else if (*pprefDataField
&& !newValue
)
1987 PrefsHaveChanged
= True
;
1988 else if (strcmp(*pprefDataField
, newValue
))
1989 PrefsHaveChanged
= True
;
1991 /* get rid of old preference */
1992 if (*pprefDataField
)
1993 XtFree(*pprefDataField
);
1995 /* store new preference */
1997 p_newField
= XtMalloc(strlen(newValue
) + 1);
1998 strcpy(p_newField
, newValue
);
2000 *pprefDataField
= newValue
;
2004 ** Set the language mode for the window, update the menu and trigger language
2005 ** mode specific actions (turn on/off highlighting). If forceNewDefaults is
2006 ** true, re-establish default settings for language-specific preferences
2007 ** regardless of whether they were previously set by the user.
2009 void SetLanguageMode(WindowInfo
*window
, int mode
, int forceNewDefaults
)
2017 /* Do mode-specific actions */
2018 reapplyLanguageMode(window
, mode
, forceNewDefaults
);
2020 /* Select the correct language mode in the sub-menu */
2021 XtVaGetValues(window
->langModeCascade
, XmNsubMenuId
, &menu
, NULL
);
2022 XtVaGetValues(menu
, XmNchildren
, &items
, XmNnumChildren
, &nItems
, NULL
);
2023 for (n
=0; n
<(int)nItems
; n
++) {
2024 XtVaGetValues(items
[n
], XmNuserData
, &userData
, NULL
);
2025 XmToggleButtonSetState(items
[n
], (int)userData
== mode
, False
);
2030 ** Lookup a language mode by name, returning the index of the language
2031 ** mode or PLAIN_LANGUAGE_MODE if the name is not found
2033 int FindLanguageMode(const char *languageName
)
2037 /* Compare each language mode to the one we were presented */
2038 for (i
=0; i
<NLanguageModes
; i
++)
2039 if (!strcmp(languageName
, LanguageModes
[i
]->name
))
2042 return PLAIN_LANGUAGE_MODE
;
2047 ** Apply language mode matching criteria and set window->languageMode to
2048 ** the appropriate mode for the current file, trigger language mode
2049 ** specific actions (turn on/off highlighting), and update the language
2050 ** mode menu item. If forceNewDefaults is true, re-establish default
2051 ** settings for language-specific preferences regardless of whether
2052 ** they were previously set by the user.
2054 void DetermineLanguageMode(WindowInfo
*window
, int forceNewDefaults
)
2056 SetLanguageMode(window
, matchLanguageMode(window
), forceNewDefaults
);
2060 ** Return the name of the current language mode set in "window", or NULL
2061 ** if the current mode is "Plain".
2063 char *LanguageModeName(int mode
)
2065 if (mode
== PLAIN_LANGUAGE_MODE
)
2068 return LanguageModes
[mode
]->name
;
2072 ** Get the set of word delimiters for the language mode set in the current
2073 ** window. Returns NULL when no language mode is set (it would be easy to
2074 ** return the default delimiter set when the current language mode is "Plain",
2075 ** or the mode doesn't have its own delimiters, but this is usually used
2076 ** to supply delimiters for RE searching, and ExecRE can skip compiling a
2077 ** delimiter table when delimiters is NULL).
2079 char *GetWindowDelimiters(WindowInfo
*window
)
2081 if (window
->languageMode
== PLAIN_LANGUAGE_MODE
)
2084 return LanguageModes
[window
->languageMode
]->delimiters
;
2088 ** Put up a dialog for selecting a custom initial window size
2090 void RowColumnPrefDialog(Widget parent
)
2092 Widget form
, selBox
, topLabel
;
2096 XtSetArg(selBoxArgs
[0], XmNdialogStyle
, XmDIALOG_FULL_APPLICATION_MODAL
);
2097 XtSetArg(selBoxArgs
[1], XmNautoUnmanage
, False
);
2098 selBox
= CreatePromptDialog(parent
, "customSize", selBoxArgs
, 2);
2099 XtAddCallback(selBox
, XmNokCallback
, (XtCallbackProc
)sizeOKCB
, NULL
);
2100 XtAddCallback(selBox
, XmNcancelCallback
, (XtCallbackProc
)sizeCancelCB
,NULL
);
2101 XtUnmanageChild(XmSelectionBoxGetChild(selBox
, XmDIALOG_TEXT
));
2102 XtUnmanageChild(XmSelectionBoxGetChild(selBox
, XmDIALOG_SELECTION_LABEL
));
2103 XtUnmanageChild(XmSelectionBoxGetChild(selBox
, XmDIALOG_HELP_BUTTON
));
2104 XtVaSetValues(XtParent(selBox
), XmNtitle
, "Initial Window Size", NULL
);
2106 form
= XtVaCreateManagedWidget("form", xmFormWidgetClass
, selBox
, NULL
);
2108 topLabel
= XtVaCreateManagedWidget("topLabel", xmLabelGadgetClass
, form
,
2109 XmNlabelString
, s1
=MKSTRING(
2110 "Enter desired size in rows\nand columns of characters:"), NULL
);
2113 RowText
= XtVaCreateManagedWidget("rows", xmTextWidgetClass
, form
,
2115 XmNtopAttachment
, XmATTACH_WIDGET
,
2116 XmNleftAttachment
, XmATTACH_POSITION
,
2117 XmNrightAttachment
, XmATTACH_POSITION
,
2118 XmNtopWidget
, topLabel
,
2120 XmNrightPosition
, 45, NULL
);
2121 RemapDeleteKey(RowText
);
2123 XtVaCreateManagedWidget("xLabel", xmLabelGadgetClass
, form
,
2124 XmNlabelString
, s1
=MKSTRING("x"),
2125 XmNtopAttachment
, XmATTACH_WIDGET
,
2126 XmNleftAttachment
, XmATTACH_POSITION
,
2127 XmNrightAttachment
, XmATTACH_POSITION
,
2128 XmNbottomAttachment
, XmATTACH_OPPOSITE_WIDGET
,
2129 XmNtopWidget
, topLabel
,
2130 XmNbottomWidget
, RowText
,
2131 XmNleftPosition
, 45,
2132 XmNrightPosition
, 55, NULL
);
2135 ColText
= XtVaCreateManagedWidget("cols", xmTextWidgetClass
, form
,
2137 XmNtopAttachment
, XmATTACH_WIDGET
,
2138 XmNleftAttachment
, XmATTACH_POSITION
,
2139 XmNrightAttachment
, XmATTACH_POSITION
,
2140 XmNtopWidget
, topLabel
,
2141 XmNleftPosition
, 55,
2142 XmNrightPosition
, 95, NULL
);
2143 RemapDeleteKey(ColText
);
2145 /* put up dialog and wait for user to press ok or cancel */
2146 DoneWithSizeDialog
= False
;
2147 ManageDialogCenteredOnPointer(selBox
);
2148 while (!DoneWithSizeDialog
)
2151 XtAppNextEvent(XtWidgetToApplicationContext(parent
), &event
);
2152 ServerDispatchEvent(&event
);
2155 XtDestroyWidget(selBox
);
2158 static void sizeOKCB(Widget w
, XtPointer clientData
, XtPointer callData
)
2160 int rowValue
, colValue
, stat
;
2162 /* get the values that the user entered and make sure they're ok */
2163 stat
= GetIntTextWarn(RowText
, &rowValue
, "number of rows", True
);
2164 if (stat
!= TEXT_READ_OK
)
2166 stat
= GetIntTextWarn(ColText
, &colValue
, "number of columns", True
);
2167 if (stat
!= TEXT_READ_OK
)
2170 /* set the corresponding preferences and dismiss the dialog */
2171 SetPrefRows(rowValue
);
2172 SetPrefCols(colValue
);
2173 DoneWithSizeDialog
= True
;
2176 static void sizeCancelCB(Widget w
, XtPointer clientData
, XtPointer callData
)
2178 DoneWithSizeDialog
= True
;
2182 ** Present the user a dialog for setting tab related preferences, either as
2183 ** defaults, or for a specific window (pass "forWindow" as NULL to set default
2184 ** preference, or a window to set preferences for the specific window.
2186 void TabsPrefDialog(Widget parent
, WindowInfo
*forWindow
)
2188 Widget form
, selBox
;
2191 int emulate
, emTabDist
, useTabs
, tabDist
;
2193 XtSetArg(selBoxArgs
[0], XmNdialogStyle
, XmDIALOG_FULL_APPLICATION_MODAL
);
2194 XtSetArg(selBoxArgs
[1], XmNautoUnmanage
, False
);
2195 selBox
= CreatePromptDialog(parent
, "customSize", selBoxArgs
, 2);
2196 XtAddCallback(selBox
, XmNokCallback
, (XtCallbackProc
)tabsOKCB
, NULL
);
2197 XtAddCallback(selBox
, XmNcancelCallback
, (XtCallbackProc
)tabsCancelCB
,NULL
);
2198 XtAddCallback(selBox
, XmNhelpCallback
, (XtCallbackProc
)tabsHelpCB
,NULL
);
2199 XtUnmanageChild(XmSelectionBoxGetChild(selBox
, XmDIALOG_TEXT
));
2200 XtUnmanageChild(XmSelectionBoxGetChild(selBox
, XmDIALOG_SELECTION_LABEL
));
2201 XtVaSetValues(XtParent(selBox
), XmNtitle
, "Tabs", NULL
);
2203 form
= XtVaCreateManagedWidget("form", xmFormWidgetClass
, selBox
, NULL
);
2205 TabDistText
= XtVaCreateManagedWidget("tabDistText", xmTextWidgetClass
,
2206 form
, XmNcolumns
, 7,
2207 XmNtopAttachment
, XmATTACH_FORM
,
2208 XmNrightAttachment
, XmATTACH_FORM
, NULL
);
2209 RemapDeleteKey(TabDistText
);
2210 XtVaCreateManagedWidget("tabDistLabel", xmLabelGadgetClass
, form
,
2211 XmNlabelString
, s1
=XmStringCreateSimple(
2212 "Tab spacing (for hardware tab characters)"),
2214 XmNuserData
, TabDistText
,
2215 XmNtopAttachment
, XmATTACH_FORM
,
2216 XmNleftAttachment
, XmATTACH_FORM
,
2217 XmNrightAttachment
, XmATTACH_WIDGET
,
2218 XmNrightWidget
, TabDistText
,
2219 XmNbottomAttachment
, XmATTACH_OPPOSITE_WIDGET
,
2220 XmNbottomWidget
, TabDistText
, NULL
);
2223 EmTabText
= XtVaCreateManagedWidget("emTabText", xmTextWidgetClass
, form
,
2225 XmNtopAttachment
, XmATTACH_WIDGET
,
2226 XmNtopWidget
, TabDistText
,
2227 XmNrightAttachment
, XmATTACH_OPPOSITE_WIDGET
,
2228 XmNrightWidget
, TabDistText
, NULL
);
2229 RemapDeleteKey(EmTabText
);
2230 EmTabLabel
= XtVaCreateManagedWidget("emTabLabel", xmLabelGadgetClass
, form
,
2231 XmNlabelString
, s1
=XmStringCreateSimple("Emulated tab spacing"),
2233 XmNuserData
, EmTabText
,
2234 XmNtopAttachment
, XmATTACH_WIDGET
,
2235 XmNtopWidget
, TabDistText
,
2236 XmNrightAttachment
, XmATTACH_WIDGET
,
2237 XmNrightWidget
, EmTabText
,
2238 XmNbottomAttachment
, XmATTACH_OPPOSITE_WIDGET
,
2239 XmNbottomWidget
, EmTabText
, NULL
);
2241 EmTabToggle
= XtVaCreateManagedWidget("emTabToggle",
2242 xmToggleButtonWidgetClass
, form
, XmNlabelString
,
2243 s1
=XmStringCreateSimple("Emulate tabs"),
2245 XmNtopAttachment
, XmATTACH_WIDGET
,
2246 XmNtopWidget
, TabDistText
,
2247 XmNleftAttachment
, XmATTACH_FORM
,
2248 XmNbottomAttachment
, XmATTACH_OPPOSITE_WIDGET
,
2249 XmNbottomWidget
, EmTabText
, NULL
);
2251 XtAddCallback(EmTabToggle
, XmNvalueChangedCallback
, emTabsCB
, NULL
);
2252 UseTabsToggle
= XtVaCreateManagedWidget("useTabsToggle",
2253 xmToggleButtonWidgetClass
, form
,
2254 XmNlabelString
, s1
=XmStringCreateSimple(
2255 "Use tab characters in padding and emulated tabs"),
2257 XmNtopAttachment
, XmATTACH_WIDGET
,
2258 XmNtopWidget
, EmTabText
,
2260 XmNleftAttachment
, XmATTACH_FORM
, NULL
);
2263 /* Set default values */
2264 if (forWindow
== NULL
) {
2265 emTabDist
= GetPrefEmTabDist(PLAIN_LANGUAGE_MODE
);
2266 useTabs
= GetPrefInsertTabs();
2267 tabDist
= GetPrefTabDist(PLAIN_LANGUAGE_MODE
);
2269 XtVaGetValues(forWindow
->textArea
, textNemulateTabs
, &emTabDist
, NULL
);
2270 useTabs
= forWindow
->buffer
->useTabs
;
2271 tabDist
= BufGetTabDistance(forWindow
->buffer
);
2273 emulate
= emTabDist
!= 0;
2274 SetIntText(TabDistText
, tabDist
);
2275 XmToggleButtonSetState(EmTabToggle
, emulate
, True
);
2277 SetIntText(EmTabText
, emTabDist
);
2278 XmToggleButtonSetState(UseTabsToggle
, useTabs
, False
);
2279 XtSetSensitive(EmTabText
, emulate
);
2280 XtSetSensitive(EmTabLabel
, emulate
);
2282 /* Handle mnemonic selection of buttons and focus to dialog */
2283 AddDialogMnemonicHandler(form
, FALSE
);
2285 /* Set the widget to get focus */
2286 #if XmVersion >= 1002
2287 XtVaSetValues(form
, XmNinitialFocus
, TabDistText
, NULL
);
2290 /* put up dialog and wait for user to press ok or cancel */
2291 TabsDialogForWindow
= forWindow
;
2292 DoneWithTabsDialog
= False
;
2293 ManageDialogCenteredOnPointer(selBox
);
2294 while (!DoneWithTabsDialog
)
2297 XtAppNextEvent(XtWidgetToApplicationContext(parent
), &event
);
2298 ServerDispatchEvent(&event
);
2301 XtDestroyWidget(selBox
);
2304 static void tabsOKCB(Widget w
, XtPointer clientData
, XtPointer callData
)
2306 int emulate
, useTabs
, stat
, tabDist
, emTabDist
;
2307 WindowInfo
*window
= TabsDialogForWindow
;
2309 /* get the values that the user entered and make sure they're ok */
2310 emulate
= XmToggleButtonGetState(EmTabToggle
);
2311 useTabs
= XmToggleButtonGetState(UseTabsToggle
);
2312 stat
= GetIntTextWarn(TabDistText
, &tabDist
, "tab spacing", True
);
2313 if (stat
!= TEXT_READ_OK
)
2316 if (tabDist
<= 0 || tabDist
> MAX_EXP_CHAR_LEN
)
2318 DialogF(DF_WARN
, TabDistText
, 1, "Tab Spacing",
2319 "Tab spacing out of range", "Dismiss");
2324 stat
= GetIntTextWarn(EmTabText
, &emTabDist
, "emulated tab spacing",True
);
2325 if (stat
!= TEXT_READ_OK
)
2328 if (emTabDist
<= 0 || tabDist
>= 1000)
2330 DialogF(DF_WARN
, EmTabText
, 1, "Tab Spacing",
2331 "Emulated tab spacing out of range", "Dismiss");
2338 /* Ask the user about saving as a default preference */
2339 if (TabsDialogForWindow
!= NULL
) {
2341 if (!shortPrefToDefault(window
->shell
, "Tab Settings", &setDefault
)) {
2342 DoneWithTabsDialog
= True
;
2346 SetPrefTabDist(tabDist
);
2347 SetPrefEmTabDist(emTabDist
);
2348 SetPrefInsertTabs(useTabs
);
2349 SaveNEditPrefs(window
->shell
, GetPrefShortMenus());
2354 /* Set the value in either the requested window or default preferences */
2355 if (TabsDialogForWindow
== NULL
) {
2356 SetPrefTabDist(tabDist
);
2357 SetPrefEmTabDist(emTabDist
);
2358 SetPrefInsertTabs(useTabs
);
2364 sprintf(numStr
, "%d", tabDist
);
2365 XtCallActionProc(window
->textArea
, "set_tab_dist", NULL
, params
, 1);
2367 sprintf(numStr
, "%d", emTabDist
);
2368 XtCallActionProc(window
->textArea
, "set_em_tab_dist", NULL
, params
, 1);
2370 sprintf(numStr
, "%d", useTabs
);
2371 XtCallActionProc(window
->textArea
, "set_use_tabs", NULL
, params
, 1);
2373 setTabDist(window, tabDist);
2374 setEmTabDist(window, emTabDist);
2375 window->buffer->useTabs = useTabs;
2378 DoneWithTabsDialog
= True
;
2381 static void tabsCancelCB(Widget w
, XtPointer clientData
, XtPointer callData
)
2383 DoneWithTabsDialog
= True
;
2386 static void tabsHelpCB(Widget w
, XtPointer clientData
, XtPointer callData
)
2388 Help(HELP_TABS_DIALOG
);
2391 static void emTabsCB(Widget w
, XtPointer clientData
, XtPointer callData
)
2393 int state
= XmToggleButtonGetState(w
);
2395 XtSetSensitive(EmTabLabel
, state
);
2396 XtSetSensitive(EmTabText
, state
);
2400 ** Present the user a dialog for setting wrap margin.
2402 void WrapMarginDialog(Widget parent
, WindowInfo
*forWindow
)
2404 Widget form
, selBox
;
2409 XtSetArg(selBoxArgs
[0], XmNdialogStyle
, XmDIALOG_FULL_APPLICATION_MODAL
);
2410 XtSetArg(selBoxArgs
[1], XmNautoUnmanage
, False
);
2411 selBox
= CreatePromptDialog(parent
, "wrapMargin", selBoxArgs
, 2);
2412 XtAddCallback(selBox
, XmNokCallback
, (XtCallbackProc
)wrapOKCB
, NULL
);
2413 XtAddCallback(selBox
, XmNcancelCallback
, (XtCallbackProc
)wrapCancelCB
,NULL
);
2414 XtUnmanageChild(XmSelectionBoxGetChild(selBox
, XmDIALOG_TEXT
));
2415 XtUnmanageChild(XmSelectionBoxGetChild(selBox
, XmDIALOG_SELECTION_LABEL
));
2416 XtUnmanageChild(XmSelectionBoxGetChild(selBox
, XmDIALOG_HELP_BUTTON
));
2417 XtVaSetValues(XtParent(selBox
), XmNtitle
, "Wrap Margin", NULL
);
2419 form
= XtVaCreateManagedWidget("form", xmFormWidgetClass
, selBox
, NULL
);
2421 WrapWindowToggle
= XtVaCreateManagedWidget("wrapWindowToggle",
2422 xmToggleButtonWidgetClass
, form
, XmNlabelString
,
2423 s1
=XmStringCreateSimple("Wrap and Fill at width of window"),
2425 XmNtopAttachment
, XmATTACH_FORM
,
2426 XmNleftAttachment
, XmATTACH_FORM
, NULL
);
2428 XtAddCallback(WrapWindowToggle
, XmNvalueChangedCallback
, wrapWindowCB
,NULL
);
2429 WrapText
= XtVaCreateManagedWidget("wrapText", xmTextWidgetClass
, form
,
2431 XmNtopAttachment
, XmATTACH_WIDGET
,
2432 XmNtopWidget
, WrapWindowToggle
,
2433 XmNrightAttachment
, XmATTACH_FORM
, NULL
);
2434 RemapDeleteKey(WrapText
);
2435 WrapTextLabel
= XtVaCreateManagedWidget("wrapMarginLabel",
2436 xmLabelGadgetClass
, form
,
2437 XmNlabelString
, s1
=XmStringCreateSimple(
2438 "Margin for Wrap and Fill"),
2440 XmNuserData
, WrapText
,
2441 XmNtopAttachment
, XmATTACH_WIDGET
,
2442 XmNtopWidget
, WrapWindowToggle
,
2443 XmNleftAttachment
, XmATTACH_FORM
,
2444 XmNrightAttachment
, XmATTACH_WIDGET
,
2445 XmNrightWidget
, WrapText
,
2446 XmNbottomAttachment
, XmATTACH_OPPOSITE_WIDGET
,
2447 XmNbottomWidget
, WrapText
, NULL
);
2450 /* Set default value */
2451 if (forWindow
== NULL
)
2452 margin
= GetPrefWrapMargin();
2454 XtVaGetValues(forWindow
->textArea
, textNwrapMargin
, &margin
, NULL
);
2455 XmToggleButtonSetState(WrapWindowToggle
, margin
==0, True
);
2457 SetIntText(WrapText
, margin
);
2458 XtSetSensitive(WrapText
, margin
!=0);
2459 XtSetSensitive(WrapTextLabel
, margin
!=0);
2461 /* Handle mnemonic selection of buttons and focus to dialog */
2462 AddDialogMnemonicHandler(form
, FALSE
);
2464 /* put up dialog and wait for user to press ok or cancel */
2465 WrapDialogForWindow
= forWindow
;
2466 DoneWithWrapDialog
= False
;
2467 ManageDialogCenteredOnPointer(selBox
);
2468 while (!DoneWithWrapDialog
)
2471 XtAppNextEvent(XtWidgetToApplicationContext(parent
), &event
);
2472 ServerDispatchEvent(&event
);
2475 XtDestroyWidget(selBox
);
2478 static void wrapOKCB(Widget w
, XtPointer clientData
, XtPointer callData
)
2480 int wrapAtWindow
, margin
, stat
;
2481 WindowInfo
*window
= WrapDialogForWindow
;
2483 /* get the values that the user entered and make sure they're ok */
2484 wrapAtWindow
= XmToggleButtonGetState(WrapWindowToggle
);
2488 stat
= GetIntTextWarn(WrapText
, &margin
, "wrap Margin", True
);
2489 if (stat
!= TEXT_READ_OK
)
2492 if (margin
<= 0 || margin
>= 1000)
2494 DialogF(DF_WARN
, WrapText
, 1, "Wrap Margin",
2495 "Wrap margin out of range", "Dismiss");
2502 /* Ask the user about saving as a default preference */
2503 if (WrapDialogForWindow
!= NULL
) {
2505 if (!shortPrefToDefault(window
->shell
, "Wrap Margin Settings",
2507 DoneWithWrapDialog
= True
;
2511 SetPrefWrapMargin(margin
);
2512 SaveNEditPrefs(window
->shell
, GetPrefShortMenus());
2517 /* Set the value in either the requested window or default preferences */
2518 if (WrapDialogForWindow
== NULL
)
2519 SetPrefWrapMargin(margin
);
2523 sprintf(marginStr
, "%d", margin
);
2524 params
[0] = marginStr
;
2525 XtCallActionProc(window
->textArea
, "set_wrap_margin", NULL
, params
, 1);
2527 DoneWithWrapDialog
= True
;
2530 static void wrapCancelCB(Widget w
, XtPointer clientData
, XtPointer callData
)
2532 DoneWithWrapDialog
= True
;
2535 static void wrapWindowCB(Widget w
, XtPointer clientData
, XtPointer callData
)
2537 int wrapAtWindow
= XmToggleButtonGetState(w
);
2539 XtSetSensitive(WrapTextLabel
, !wrapAtWindow
);
2540 XtSetSensitive(WrapText
, !wrapAtWindow
);
2544 ** Present a dialog for editing language mode information
2546 void EditLanguageModes()
2548 #define LIST_RIGHT 40
2549 #define LEFT_MARGIN_POS 1
2550 #define RIGHT_MARGIN_POS 99
2552 Widget form
, nameLbl
, topLbl
, extLbl
, recogLbl
, delimitLbl
, defTipsLbl
;
2553 Widget okBtn
, applyBtn
, dismissBtn
;
2554 Widget overrideFrame
, overrideForm
, delimitForm
;
2555 Widget tabForm
, tabLbl
, indentBox
, wrapBox
;
2560 /* if the dialog is already displayed, just pop it to the top and return */
2561 if (LMDialog
.shell
!= NULL
) {
2562 RaiseShellWindow(LMDialog
.shell
);
2566 LMDialog
.languageModeList
= (languageModeRec
**)XtMalloc(
2567 sizeof(languageModeRec
*) * MAX_LANGUAGE_MODES
);
2568 for (i
=0; i
<NLanguageModes
; i
++)
2569 LMDialog
.languageModeList
[i
] = copyLanguageModeRec(LanguageModes
[i
]);
2570 LMDialog
.nLanguageModes
= NLanguageModes
;
2572 /* Create a form widget in an application shell */
2574 XtSetArg(args
[ac
], XmNdeleteResponse
, XmDO_NOTHING
); ac
++;
2575 XtSetArg(args
[ac
], XmNiconName
, "NEdit Language Modes"); ac
++;
2576 XtSetArg(args
[ac
], XmNtitle
, "Language Modes"); ac
++;
2577 LMDialog
.shell
= CreateShellWithBestVis(APP_NAME
, APP_CLASS
,
2578 applicationShellWidgetClass
, TheDisplay
, args
, ac
);
2579 AddSmallIcon(LMDialog
.shell
);
2580 form
= XtVaCreateManagedWidget("editLanguageModes", xmFormWidgetClass
,
2581 LMDialog
.shell
, XmNautoUnmanage
, False
,
2582 XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2583 XtAddCallback(form
, XmNdestroyCallback
, lmDestroyCB
, NULL
);
2584 AddMotifCloseCallback(LMDialog
.shell
, lmDismissCB
, NULL
);
2586 topLbl
= XtVaCreateManagedWidget("topLabel", xmLabelGadgetClass
, form
,
2587 XmNlabelString
, s1
=MKSTRING(
2588 "To modify the properties of an existing language mode, select the name from\n\
2589 the list on the left. To add a new language, select \"New\" from the list."),
2591 XmNtopAttachment
, XmATTACH_POSITION
,
2593 XmNleftAttachment
, XmATTACH_POSITION
,
2594 XmNleftPosition
, LEFT_MARGIN_POS
,
2595 XmNrightAttachment
, XmATTACH_POSITION
,
2596 XmNrightPosition
, RIGHT_MARGIN_POS
, NULL
);
2599 nameLbl
= XtVaCreateManagedWidget("nameLbl", xmLabelGadgetClass
, form
,
2600 XmNlabelString
, s1
=XmStringCreateSimple("Name"),
2602 XmNalignment
, XmALIGNMENT_BEGINNING
,
2603 XmNleftAttachment
, XmATTACH_POSITION
,
2604 XmNleftPosition
, LIST_RIGHT
,
2605 XmNtopAttachment
, XmATTACH_WIDGET
,
2606 XmNtopOffset
, H_MARGIN
,
2607 XmNtopWidget
, topLbl
, NULL
);
2610 LMDialog
.nameW
= XtVaCreateManagedWidget("name", xmTextWidgetClass
, form
,
2612 XmNleftAttachment
, XmATTACH_POSITION
,
2613 XmNleftPosition
, LIST_RIGHT
,
2614 XmNtopAttachment
, XmATTACH_WIDGET
,
2615 XmNtopWidget
, nameLbl
,
2616 XmNrightAttachment
, XmATTACH_POSITION
,
2617 XmNrightPosition
, (RIGHT_MARGIN_POS
+ LIST_RIGHT
)/2, NULL
);
2618 RemapDeleteKey(LMDialog
.nameW
);
2619 XtVaSetValues(nameLbl
, XmNuserData
, LMDialog
.nameW
, NULL
);
2621 extLbl
= XtVaCreateManagedWidget("extLbl", xmLabelGadgetClass
, form
,
2623 s1
=XmStringCreateSimple("File extensions (separate w/ space)"),
2625 XmNalignment
, XmALIGNMENT_BEGINNING
,
2626 XmNleftAttachment
, XmATTACH_POSITION
,
2627 XmNleftPosition
, LIST_RIGHT
,
2628 XmNtopAttachment
, XmATTACH_WIDGET
,
2629 XmNtopOffset
, H_MARGIN
,
2630 XmNtopWidget
, LMDialog
.nameW
, NULL
);
2633 LMDialog
.extW
= XtVaCreateManagedWidget("ext", xmTextWidgetClass
, form
,
2634 XmNleftAttachment
, XmATTACH_POSITION
,
2635 XmNleftPosition
, LIST_RIGHT
,
2636 XmNtopAttachment
, XmATTACH_WIDGET
,
2637 XmNtopWidget
, extLbl
,
2638 XmNrightAttachment
, XmATTACH_POSITION
,
2639 XmNrightPosition
, RIGHT_MARGIN_POS
, NULL
);
2640 RemapDeleteKey(LMDialog
.extW
);
2641 XtVaSetValues(extLbl
, XmNuserData
, LMDialog
.extW
, NULL
);
2643 recogLbl
= XtVaCreateManagedWidget("recogLbl", xmLabelGadgetClass
, form
,
2644 XmNlabelString
, s1
=MKSTRING(
2645 "Recognition regular expression (applied to first 200\n\
2646 characters of file to determine type from content)"),
2647 XmNalignment
, XmALIGNMENT_BEGINNING
,
2649 XmNleftAttachment
, XmATTACH_POSITION
,
2650 XmNleftPosition
, LIST_RIGHT
,
2651 XmNtopAttachment
, XmATTACH_WIDGET
,
2652 XmNtopOffset
, H_MARGIN
,
2653 XmNtopWidget
, LMDialog
.extW
, NULL
);
2656 LMDialog
.recogW
= XtVaCreateManagedWidget("recog", xmTextWidgetClass
, form
,
2657 XmNleftAttachment
, XmATTACH_POSITION
,
2658 XmNleftPosition
, LIST_RIGHT
,
2659 XmNtopAttachment
, XmATTACH_WIDGET
,
2660 XmNtopWidget
, recogLbl
,
2661 XmNrightAttachment
, XmATTACH_POSITION
,
2662 XmNrightPosition
, RIGHT_MARGIN_POS
, NULL
);
2663 RemapDeleteKey(LMDialog
.recogW
);
2664 XtVaSetValues(recogLbl
, XmNuserData
, LMDialog
.recogW
, NULL
);
2666 defTipsLbl
= XtVaCreateManagedWidget("defTipsLbl", xmLabelGadgetClass
, form
,
2667 XmNlabelString
, s1
=MKSTRING(
2668 "Default calltips file(s) (separate w/colons)"),
2669 XmNalignment
, XmALIGNMENT_BEGINNING
,
2671 XmNleftAttachment
, XmATTACH_POSITION
,
2672 XmNleftPosition
, LIST_RIGHT
,
2673 XmNtopAttachment
, XmATTACH_WIDGET
,
2674 XmNtopOffset
, H_MARGIN
,
2675 XmNtopWidget
, LMDialog
.recogW
, NULL
);
2678 LMDialog
.defTipsW
= XtVaCreateManagedWidget("defTips", xmTextWidgetClass
,
2680 XmNleftAttachment
, XmATTACH_POSITION
,
2681 XmNleftPosition
, LIST_RIGHT
,
2682 XmNtopAttachment
, XmATTACH_WIDGET
,
2683 XmNtopWidget
, defTipsLbl
,
2684 XmNrightAttachment
, XmATTACH_POSITION
,
2685 XmNrightPosition
, RIGHT_MARGIN_POS
, NULL
);
2686 RemapDeleteKey(LMDialog
.defTipsW
);
2687 XtVaSetValues(defTipsLbl
, XmNuserData
, LMDialog
.defTipsW
, NULL
);
2689 okBtn
= XtVaCreateManagedWidget("ok", xmPushButtonWidgetClass
, form
,
2690 XmNlabelString
, s1
=XmStringCreateSimple("OK"),
2691 XmNleftAttachment
, XmATTACH_POSITION
,
2692 XmNleftPosition
, 10,
2693 XmNrightAttachment
, XmATTACH_POSITION
,
2694 XmNrightPosition
, 30,
2695 XmNbottomAttachment
, XmATTACH_POSITION
,
2696 XmNbottomPosition
, 99, NULL
);
2697 XtAddCallback(okBtn
, XmNactivateCallback
, lmOkCB
, NULL
);
2700 applyBtn
= XtVaCreateManagedWidget("apply", xmPushButtonWidgetClass
, form
,
2701 XmNlabelString
, s1
=XmStringCreateSimple("Apply"),
2703 XmNleftAttachment
, XmATTACH_POSITION
,
2704 XmNleftPosition
, 40,
2705 XmNrightAttachment
, XmATTACH_POSITION
,
2706 XmNrightPosition
, 60,
2707 XmNbottomAttachment
, XmATTACH_POSITION
,
2708 XmNbottomPosition
, 99, NULL
);
2709 XtAddCallback(applyBtn
, XmNactivateCallback
, lmApplyCB
, NULL
);
2712 dismissBtn
= XtVaCreateManagedWidget("dismiss",xmPushButtonWidgetClass
,form
,
2713 XmNlabelString
, s1
=XmStringCreateSimple("Dismiss"),
2714 XmNleftAttachment
, XmATTACH_POSITION
,
2715 XmNleftPosition
, 70,
2716 XmNrightAttachment
, XmATTACH_POSITION
,
2717 XmNrightPosition
, 90,
2718 XmNbottomAttachment
, XmATTACH_POSITION
,
2719 XmNbottomPosition
, 99, NULL
);
2720 XtAddCallback(dismissBtn
, XmNactivateCallback
, lmDismissCB
, NULL
);
2723 overrideFrame
= XtVaCreateManagedWidget("overrideFrame",
2724 xmFrameWidgetClass
, form
,
2725 XmNleftAttachment
, XmATTACH_POSITION
,
2726 XmNleftPosition
, LEFT_MARGIN_POS
,
2727 XmNrightAttachment
, XmATTACH_POSITION
,
2728 XmNrightPosition
, RIGHT_MARGIN_POS
,
2729 XmNbottomAttachment
, XmATTACH_WIDGET
,
2730 XmNbottomWidget
, dismissBtn
,
2731 XmNbottomOffset
, H_MARGIN
, NULL
);
2732 overrideForm
= XtVaCreateManagedWidget("overrideForm", xmFormWidgetClass
,
2733 overrideFrame
, NULL
);
2734 XtVaCreateManagedWidget("overrideLbl", xmLabelGadgetClass
, overrideFrame
,
2735 XmNlabelString
, s1
=XmStringCreateSimple("Override Defaults"),
2736 XmNchildType
, XmFRAME_TITLE_CHILD
,
2737 XmNchildHorizontalAlignment
, XmALIGNMENT_CENTER
, NULL
);
2740 delimitForm
= XtVaCreateManagedWidget("delimitForm", xmFormWidgetClass
,
2742 XmNleftAttachment
, XmATTACH_POSITION
,
2743 XmNleftPosition
, LEFT_MARGIN_POS
,
2744 XmNtopAttachment
, XmATTACH_FORM
,
2745 XmNtopOffset
, H_MARGIN
,
2746 XmNrightAttachment
, XmATTACH_POSITION
,
2747 XmNrightPosition
, RIGHT_MARGIN_POS
, NULL
);
2748 delimitLbl
= XtVaCreateManagedWidget("delimitLbl", xmLabelGadgetClass
,
2750 XmNlabelString
, s1
=XmStringCreateSimple("Word delimiters"),
2752 XmNleftAttachment
, XmATTACH_FORM
,
2753 XmNtopAttachment
, XmATTACH_FORM
,
2754 XmNbottomAttachment
, XmATTACH_FORM
, NULL
);
2756 LMDialog
.delimitW
= XtVaCreateManagedWidget("delimit", xmTextWidgetClass
,
2758 XmNtopAttachment
, XmATTACH_FORM
,
2759 XmNleftAttachment
, XmATTACH_WIDGET
,
2760 XmNleftWidget
, delimitLbl
,
2761 XmNrightAttachment
, XmATTACH_FORM
,
2762 XmNbottomAttachment
, XmATTACH_FORM
, NULL
);
2763 RemapDeleteKey(LMDialog
.delimitW
);
2764 XtVaSetValues(delimitLbl
, XmNuserData
, LMDialog
.delimitW
, NULL
);
2766 tabForm
= XtVaCreateManagedWidget("tabForm", xmFormWidgetClass
,
2768 XmNleftAttachment
, XmATTACH_POSITION
,
2769 XmNleftPosition
, LEFT_MARGIN_POS
,
2770 XmNtopAttachment
, XmATTACH_WIDGET
,
2771 XmNtopWidget
, delimitForm
,
2772 XmNtopOffset
, H_MARGIN
,
2773 XmNrightAttachment
, XmATTACH_POSITION
,
2774 XmNrightPosition
, RIGHT_MARGIN_POS
, NULL
);
2775 tabLbl
= XtVaCreateManagedWidget("tabLbl", xmLabelGadgetClass
, tabForm
,
2776 XmNlabelString
, s1
=XmStringCreateSimple(
2777 "Alternative hardware tab spacing"),
2779 XmNleftAttachment
, XmATTACH_FORM
,
2780 XmNtopAttachment
, XmATTACH_FORM
,
2781 XmNbottomAttachment
, XmATTACH_FORM
, NULL
);
2783 LMDialog
.tabW
= XtVaCreateManagedWidget("delimit", xmTextWidgetClass
,
2786 XmNtopAttachment
, XmATTACH_FORM
,
2787 XmNleftAttachment
, XmATTACH_WIDGET
,
2788 XmNleftWidget
, tabLbl
,
2789 XmNbottomAttachment
, XmATTACH_FORM
, NULL
);
2790 RemapDeleteKey(LMDialog
.tabW
);
2791 XtVaSetValues(tabLbl
, XmNuserData
, LMDialog
.tabW
, NULL
);
2792 LMDialog
.emTabW
= XtVaCreateManagedWidget("delimit", xmTextWidgetClass
,
2795 XmNtopAttachment
, XmATTACH_FORM
,
2796 XmNrightAttachment
, XmATTACH_FORM
,
2797 XmNbottomAttachment
, XmATTACH_FORM
, NULL
);
2798 RemapDeleteKey(LMDialog
.emTabW
);
2799 XtVaCreateManagedWidget("emTabLbl", xmLabelGadgetClass
, tabForm
,
2801 s1
=XmStringCreateSimple("Alternative emulated tab spacing"),
2802 XmNalignment
, XmALIGNMENT_END
,
2804 XmNuserData
, LMDialog
.emTabW
,
2805 XmNleftAttachment
, XmATTACH_WIDGET
,
2806 XmNleftWidget
, LMDialog
.tabW
,
2807 XmNrightAttachment
, XmATTACH_WIDGET
,
2808 XmNrightWidget
, LMDialog
.emTabW
,
2809 XmNtopAttachment
, XmATTACH_FORM
,
2810 XmNbottomAttachment
, XmATTACH_FORM
, NULL
);
2813 indentBox
= XtVaCreateManagedWidget("indentBox", xmRowColumnWidgetClass
,
2815 XmNorientation
, XmHORIZONTAL
,
2816 XmNpacking
, XmPACK_TIGHT
,
2817 XmNradioBehavior
, True
,
2818 XmNleftAttachment
, XmATTACH_POSITION
,
2819 XmNleftPosition
, LEFT_MARGIN_POS
,
2820 XmNtopAttachment
, XmATTACH_WIDGET
,
2821 XmNtopWidget
, tabForm
,
2822 XmNtopOffset
, H_MARGIN
, NULL
);
2823 LMDialog
.defaultIndentW
= XtVaCreateManagedWidget("defaultIndent",
2824 xmToggleButtonWidgetClass
, indentBox
,
2827 XmNlabelString
, s1
=XmStringCreateSimple("Default indent style"),
2828 XmNmnemonic
, 'D', NULL
);
2830 LMDialog
.noIndentW
= XtVaCreateManagedWidget("noIndent",
2831 xmToggleButtonWidgetClass
, indentBox
,
2833 XmNlabelString
, s1
=XmStringCreateSimple("No automatic indent"),
2834 XmNmnemonic
, 'N', NULL
);
2836 LMDialog
.autoIndentW
= XtVaCreateManagedWidget("autoIndent",
2837 xmToggleButtonWidgetClass
, indentBox
,
2839 XmNlabelString
, s1
=XmStringCreateSimple("Auto-indent"),
2840 XmNmnemonic
, 'A', NULL
);
2842 LMDialog
.smartIndentW
= XtVaCreateManagedWidget("smartIndent",
2843 xmToggleButtonWidgetClass
, indentBox
,
2845 XmNlabelString
, s1
=XmStringCreateSimple("Smart-indent"),
2846 XmNmnemonic
, 'S', NULL
);
2849 wrapBox
= XtVaCreateManagedWidget("wrapBox", xmRowColumnWidgetClass
,
2851 XmNorientation
, XmHORIZONTAL
,
2852 XmNpacking
, XmPACK_TIGHT
,
2853 XmNradioBehavior
, True
,
2854 XmNleftAttachment
, XmATTACH_POSITION
,
2855 XmNleftPosition
, LEFT_MARGIN_POS
,
2856 XmNtopAttachment
, XmATTACH_WIDGET
,
2857 XmNtopWidget
, indentBox
,
2858 XmNtopOffset
, H_MARGIN
,
2859 XmNbottomAttachment
, XmATTACH_FORM
,
2860 XmNbottomOffset
, H_MARGIN
, NULL
);
2861 LMDialog
.defaultWrapW
= XtVaCreateManagedWidget("defaultWrap",
2862 xmToggleButtonWidgetClass
, wrapBox
,
2865 XmNlabelString
, s1
=XmStringCreateSimple("Default wrap style"),
2866 XmNmnemonic
, 'D', NULL
);
2868 LMDialog
.noWrapW
= XtVaCreateManagedWidget("noWrap",
2869 xmToggleButtonWidgetClass
, wrapBox
,
2871 XmNlabelString
, s1
=XmStringCreateSimple("No wrapping"),
2872 XmNmnemonic
, 'N', NULL
);
2874 LMDialog
.newlineWrapW
= XtVaCreateManagedWidget("newlineWrap",
2875 xmToggleButtonWidgetClass
, wrapBox
,
2877 XmNlabelString
, s1
=XmStringCreateSimple("Auto newline wrap"),
2878 XmNmnemonic
, 'A', NULL
);
2880 LMDialog
.contWrapW
= XtVaCreateManagedWidget("contWrap",
2881 xmToggleButtonWidgetClass
, wrapBox
,
2883 XmNlabelString
, s1
=XmStringCreateSimple("Continuous wrap"),
2884 XmNmnemonic
, 'C', NULL
);
2887 XtVaCreateManagedWidget("stretchForm", xmFormWidgetClass
, form
,
2888 XmNtopAttachment
, XmATTACH_WIDGET
,
2889 XmNtopWidget
, LMDialog
.defTipsW
,
2890 XmNleftAttachment
, XmATTACH_POSITION
,
2891 XmNleftPosition
, LIST_RIGHT
,
2892 XmNrightAttachment
, XmATTACH_POSITION
,
2893 XmNrightPosition
, RIGHT_MARGIN_POS
,
2894 XmNbottomAttachment
, XmATTACH_WIDGET
,
2895 XmNbottomWidget
, overrideFrame
,
2896 XmNbottomOffset
, H_MARGIN
*2, NULL
);
2899 XtSetArg(args
[ac
], XmNtopAttachment
, XmATTACH_WIDGET
); ac
++;
2900 XtSetArg(args
[ac
], XmNtopOffset
, H_MARGIN
); ac
++;
2901 XtSetArg(args
[ac
], XmNtopWidget
, topLbl
); ac
++;
2902 XtSetArg(args
[ac
], XmNleftAttachment
, XmATTACH_POSITION
); ac
++;
2903 XtSetArg(args
[ac
], XmNleftPosition
, LEFT_MARGIN_POS
); ac
++;
2904 XtSetArg(args
[ac
], XmNrightAttachment
, XmATTACH_POSITION
); ac
++;
2905 XtSetArg(args
[ac
], XmNrightPosition
, LIST_RIGHT
-1); ac
++;
2906 XtSetArg(args
[ac
], XmNbottomAttachment
, XmATTACH_WIDGET
); ac
++;
2907 XtSetArg(args
[ac
], XmNbottomWidget
, overrideFrame
); ac
++;
2908 XtSetArg(args
[ac
], XmNbottomOffset
, H_MARGIN
*2); ac
++;
2909 LMDialog
.managedListW
= CreateManagedList(form
, "list", args
, ac
,
2910 (void **)LMDialog
.languageModeList
, &LMDialog
.nLanguageModes
,
2911 MAX_LANGUAGE_MODES
, 15, lmGetDisplayedCB
, NULL
, lmSetDisplayedCB
,
2912 NULL
, lmFreeItemCB
);
2913 AddDeleteConfirmCB(LMDialog
.managedListW
, lmDeleteConfirmCB
, NULL
);
2914 XtVaSetValues(topLbl
, XmNuserData
, LMDialog
.managedListW
, NULL
);
2916 /* Set initial default button */
2917 XtVaSetValues(form
, XmNdefaultButton
, okBtn
, NULL
);
2918 XtVaSetValues(form
, XmNcancelButton
, dismissBtn
, NULL
);
2920 /* Handle mnemonic selection of buttons and focus to dialog */
2921 AddDialogMnemonicHandler(form
, FALSE
);
2923 /* Realize all of the widgets in the new dialog */
2924 RealizeWithoutForcingPosition(LMDialog
.shell
);
2927 static void lmDestroyCB(Widget w
, XtPointer clientData
, XtPointer callData
)
2931 for (i
=0; i
<LMDialog
.nLanguageModes
; i
++)
2932 freeLanguageModeRec(LMDialog
.languageModeList
[i
]);
2933 XtFree((char *)LMDialog
.languageModeList
);
2936 static void lmOkCB(Widget w
, XtPointer clientData
, XtPointer callData
)
2938 if (!updateLMList())
2941 /* pop down and destroy the dialog */
2942 XtDestroyWidget(LMDialog
.shell
);
2943 LMDialog
.shell
= NULL
;
2946 static void lmApplyCB(Widget w
, XtPointer clientData
, XtPointer callData
)
2951 static void lmDismissCB(Widget w
, XtPointer clientData
, XtPointer callData
)
2953 /* pop down and destroy the dialog */
2954 XtDestroyWidget(LMDialog
.shell
);
2955 LMDialog
.shell
= NULL
;
2958 static int lmDeleteConfirmCB(int itemIndex
, void *cbArg
)
2962 /* Allow duplicate names to be deleted regardless of dependencies */
2963 for (i
=0; i
<LMDialog
.nLanguageModes
; i
++)
2964 if (i
!= itemIndex
&& !strcmp(LMDialog
.languageModeList
[i
]->name
,
2965 LMDialog
.languageModeList
[itemIndex
]->name
))
2968 /* don't allow deletion if data will be lost */
2969 if (LMHasHighlightPatterns(LMDialog
.languageModeList
[itemIndex
]->name
))
2971 DialogF(DF_WARN
, LMDialog
.shell
, 1, "Patterns exist",
2972 "This language mode has syntax highlighting\n"
2973 "patterns defined. Please delete the patterns\n"
2974 "first, in Preferences -> Default Settings ->\n"
2975 "Syntax Highlighting, before proceeding here.", "Dismiss");
2979 /* don't allow deletion if data will be lost */
2980 if (LMHasSmartIndentMacros(LMDialog
.languageModeList
[itemIndex
]->name
))
2982 DialogF(DF_WARN
, LMDialog
.shell
, 1, "Smart Indent Macros exist",
2983 "This language mode has smart indent macros\n"
2984 "defined. Please delete the macros first,\n"
2985 "in Preferences -> Default Settings ->\n"
2986 "Auto Indent -> Program Smart Indent,\n"
2987 "before proceeding here.", "Dismiss");
2995 ** Apply the changes that the user has made in the language modes dialog to the
2996 ** stored language mode information for this NEdit session (the data array
2999 static int updateLMList(void)
3002 char *oldModeName
, *newDelimiters
;
3005 /* Get the current contents of the dialog fields */
3006 if (!UpdateManagedList(LMDialog
.managedListW
, True
))
3009 /* Fix up language mode indices in all open windows (which may change
3010 if the currently selected mode is deleted or has changed position),
3011 and update word delimiters */
3012 for (window
=WindowList
; window
!=NULL
; window
=window
->next
) {
3013 if (window
->languageMode
!= PLAIN_LANGUAGE_MODE
) {
3014 oldModeName
= LanguageModes
[window
->languageMode
]->name
;
3015 window
->languageMode
= PLAIN_LANGUAGE_MODE
;
3016 for (i
=0; i
<LMDialog
.nLanguageModes
; i
++) {
3017 if (!strcmp(oldModeName
, LMDialog
.languageModeList
[i
]->name
)) {
3018 newDelimiters
= LMDialog
.languageModeList
[i
]->delimiters
;
3019 if (newDelimiters
== NULL
)
3020 newDelimiters
= GetPrefDelimiters();
3021 XtVaSetValues(window
->textArea
, textNwordDelimiters
,
3022 newDelimiters
, NULL
);
3023 for (j
=0; j
<window
->nPanes
; j
++)
3024 XtVaSetValues(window
->textPanes
[j
],
3025 textNwordDelimiters
, newDelimiters
, NULL
);
3026 window
->languageMode
= i
;
3033 /* If there were any name changes, re-name dependent highlight patterns
3034 and smart-indent macros and fix up the weird rename-format names */
3035 for (i
=0; i
<LMDialog
.nLanguageModes
; i
++) {
3036 if (strchr(LMDialog
.languageModeList
[i
]->name
, ':') != NULL
) {
3037 char *newName
= strrchr(LMDialog
.languageModeList
[i
]->name
, ':')+1;
3038 *strchr(LMDialog
.languageModeList
[i
]->name
, ':') = '\0';
3039 RenameHighlightPattern(LMDialog
.languageModeList
[i
]->name
, newName
);
3040 RenameSmartIndentMacros(LMDialog
.languageModeList
[i
]->name
, newName
);
3041 memmove(LMDialog
.languageModeList
[i
]->name
, newName
,
3042 strlen(newName
) + 1);
3043 ChangeManagedListData(LMDialog
.managedListW
);
3047 /* Unload any default calltips file that is no longer a default. */
3048 for (i
=0; i
<NLanguageModes
; i
++) {
3049 if (!LanguageModes
[i
]->defTipsFile
)
3051 for (j
=0; j
<LMDialog
.nLanguageModes
; j
++) {
3052 if (!LMDialog
.languageModeList
[j
]->defTipsFile
)
3054 if (!strcmp(LanguageModes
[i
]->defTipsFile
,
3055 LMDialog
.languageModeList
[j
]->defTipsFile
))
3058 if ( j
==LMDialog
.nLanguageModes
)
3059 DeleteTagsFile(LanguageModes
[i
]->defTipsFile
, TIP
);
3062 /* Replace the old language mode list with the new one from the dialog */
3063 for (i
=0; i
<NLanguageModes
; i
++)
3064 freeLanguageModeRec(LanguageModes
[i
]);
3065 for (i
=0; i
<LMDialog
.nLanguageModes
; i
++)
3066 LanguageModes
[i
] = copyLanguageModeRec(LMDialog
.languageModeList
[i
]);
3067 NLanguageModes
= LMDialog
.nLanguageModes
;
3069 /* Update the menus in the window menu bars and load any needed
3071 for (window
=WindowList
; window
!=NULL
; window
=window
->next
) {
3072 updateLanguageModeSubmenu(window
);
3073 if (window
->languageMode
!= PLAIN_LANGUAGE_MODE
&&
3074 LanguageModes
[window
->languageMode
]->defTipsFile
!= NULL
)
3075 AddTagsFile(LanguageModes
[window
->languageMode
]->defTipsFile
, TIP
);
3078 /* If a syntax highlighting dialog is up, update its menu */
3079 UpdateLanguageModeMenu();
3080 /* The same for the smart indent macro dialog */
3081 UpdateLangModeMenuSmartIndent();
3082 /* Note that preferences have been changed */
3088 static void *lmGetDisplayedCB(void *oldItem
, int explicitRequest
, int *abort
,
3091 languageModeRec
*lm
, *oldLM
= (languageModeRec
*)oldItem
;
3093 int i
, nCopies
, oldLen
;
3095 /* If the dialog is currently displaying the "new" entry and the
3096 fields are empty, that's just fine */
3097 if (oldItem
== NULL
&& lmDialogEmpty())
3100 /* Read the data the user has entered in the dialog fields */
3101 lm
= readLMDialogFields(True
);
3103 /* If there was a name change of a non-duplicate language mode, modify the
3104 name to the weird format of: ":old name:new name". This signals that a
3105 name change is necessary in lm dependent data such as highlight
3106 patterns. Duplicate language modes may be re-named at will, since no
3107 data will be lost due to the name change. */
3108 if (lm
!= NULL
&& oldLM
!= NULL
&& strcmp(oldLM
->name
, lm
->name
)) {
3110 for (i
=0; i
<LMDialog
.nLanguageModes
; i
++)
3111 if (!strcmp(oldLM
->name
, LMDialog
.languageModeList
[i
]->name
))
3114 oldLen
= strchr(oldLM
->name
, ':') == NULL
? strlen(oldLM
->name
) :
3115 strchr(oldLM
->name
, ':') - oldLM
->name
;
3116 tempName
= XtMalloc(oldLen
+ strlen(lm
->name
) + 2);
3117 strncpy(tempName
, oldLM
->name
, oldLen
);
3118 sprintf(&tempName
[oldLen
], ":%s", lm
->name
);
3120 lm
->name
= tempName
;
3124 /* If there are no problems reading the data, just return it */
3128 /* If there are problems, and the user didn't ask for the fields to be
3129 read, give more warning */
3130 if (!explicitRequest
)
3132 if (DialogF(DF_WARN
, LMDialog
.shell
, 2, "Discard Language Mode",
3133 "Discard incomplete entry\nfor current language mode?", "Keep",
3136 return oldItem
== NULL
3138 : (void *)copyLanguageModeRec((languageModeRec
*)oldItem
);
3142 /* Do readLMDialogFields again without "silent" mode to display warning */
3143 lm
= readLMDialogFields(False
);
3148 static void lmSetDisplayedCB(void *item
, void *cbArg
)
3150 languageModeRec
*lm
= (languageModeRec
*)item
;
3154 XmTextSetString(LMDialog
.nameW
, "");
3155 XmTextSetString(LMDialog
.extW
, "");
3156 XmTextSetString(LMDialog
.recogW
, "");
3157 XmTextSetString(LMDialog
.defTipsW
, "");
3158 XmTextSetString(LMDialog
.delimitW
, "");
3159 XmTextSetString(LMDialog
.tabW
, "");
3160 XmTextSetString(LMDialog
.emTabW
, "");
3161 XmToggleButtonSetState(LMDialog
.defaultIndentW
, True
, True
);
3162 XmToggleButtonSetState(LMDialog
.defaultWrapW
, True
, True
);
3164 XmTextSetString(LMDialog
.nameW
, strchr(lm
->name
, ':') == NULL
?
3165 lm
->name
: strchr(lm
->name
, ':')+1);
3166 extStr
= createExtString(lm
->extensions
, lm
->nExtensions
);
3167 XmTextSetString(LMDialog
.extW
, extStr
);
3169 XmTextSetString(LMDialog
.recogW
, lm
->recognitionExpr
);
3170 XmTextSetString(LMDialog
.defTipsW
, lm
->defTipsFile
);
3171 XmTextSetString(LMDialog
.delimitW
, lm
->delimiters
);
3172 if (lm
->tabDist
== DEFAULT_TAB_DIST
)
3173 XmTextSetString(LMDialog
.tabW
, "");
3175 SetIntText(LMDialog
.tabW
, lm
->tabDist
);
3176 if (lm
->emTabDist
== DEFAULT_EM_TAB_DIST
)
3177 XmTextSetString(LMDialog
.emTabW
, "");
3179 SetIntText(LMDialog
.emTabW
, lm
->emTabDist
);
3180 XmToggleButtonSetState(LMDialog
.defaultIndentW
,
3181 lm
->indentStyle
== DEFAULT_INDENT
, False
);
3182 XmToggleButtonSetState(LMDialog
.noIndentW
,
3183 lm
->indentStyle
== NO_AUTO_INDENT
, False
);
3184 XmToggleButtonSetState(LMDialog
.autoIndentW
,
3185 lm
->indentStyle
== AUTO_INDENT
, False
);
3186 XmToggleButtonSetState(LMDialog
.smartIndentW
,
3187 lm
->indentStyle
== SMART_INDENT
, False
);
3188 XmToggleButtonSetState(LMDialog
.defaultWrapW
,
3189 lm
->wrapStyle
== DEFAULT_WRAP
, False
);
3190 XmToggleButtonSetState(LMDialog
.noWrapW
,
3191 lm
->wrapStyle
== NO_WRAP
, False
);
3192 XmToggleButtonSetState(LMDialog
.newlineWrapW
,
3193 lm
->wrapStyle
== NEWLINE_WRAP
, False
);
3194 XmToggleButtonSetState(LMDialog
.contWrapW
,
3195 lm
->wrapStyle
== CONTINUOUS_WRAP
, False
);
3199 static void lmFreeItemCB(void *item
)
3201 freeLanguageModeRec((languageModeRec
*)item
);
3204 static void freeLanguageModeRec(languageModeRec
*lm
)
3209 if (lm
->recognitionExpr
!= NULL
)
3210 XtFree(lm
->recognitionExpr
);
3211 if (lm
->defTipsFile
!= NULL
)
3212 XtFree(lm
->defTipsFile
);
3213 if (lm
->delimiters
!= NULL
)
3214 XtFree(lm
->delimiters
);
3215 for (i
=0; i
<lm
->nExtensions
; i
++)
3216 XtFree(lm
->extensions
[i
]);
3217 if (lm
->nExtensions
!= 0)
3218 XtFree((char *)lm
->extensions
);
3223 ** Copy a languageModeRec data structure and all of the allocated data it contains
3225 static languageModeRec
*copyLanguageModeRec(languageModeRec
*lm
)
3227 languageModeRec
*newLM
;
3230 newLM
= (languageModeRec
*)XtMalloc(sizeof(languageModeRec
));
3231 newLM
->name
= XtMalloc(strlen(lm
->name
)+1);
3232 strcpy(newLM
->name
, lm
->name
);
3233 newLM
->nExtensions
= lm
->nExtensions
;
3234 newLM
->extensions
= (char **)XtMalloc(sizeof(char *) * lm
->nExtensions
);
3235 for (i
=0; i
<lm
->nExtensions
; i
++) {
3236 newLM
->extensions
[i
] = XtMalloc(strlen(lm
->extensions
[i
]) + 1);
3237 strcpy(newLM
->extensions
[i
], lm
->extensions
[i
]);
3239 if (lm
->recognitionExpr
== NULL
)
3240 newLM
->recognitionExpr
= NULL
;
3242 newLM
->recognitionExpr
= XtMalloc(strlen(lm
->recognitionExpr
)+1);
3243 strcpy(newLM
->recognitionExpr
, lm
->recognitionExpr
);
3245 if (lm
->defTipsFile
== NULL
)
3246 newLM
->defTipsFile
= NULL
;
3248 newLM
->defTipsFile
= XtMalloc(strlen(lm
->defTipsFile
)+1);
3249 strcpy(newLM
->defTipsFile
, lm
->defTipsFile
);
3251 if (lm
->delimiters
== NULL
)
3252 newLM
->delimiters
= NULL
;
3254 newLM
->delimiters
= XtMalloc(strlen(lm
->delimiters
)+1);
3255 strcpy(newLM
->delimiters
, lm
->delimiters
);
3257 newLM
->wrapStyle
= lm
->wrapStyle
;
3258 newLM
->indentStyle
= lm
->indentStyle
;
3259 newLM
->tabDist
= lm
->tabDist
;
3260 newLM
->emTabDist
= lm
->emTabDist
;
3265 ** Read the fields in the language modes dialog and create a languageModeRec data
3266 ** structure reflecting the current state of the selected language mode in the dialog.
3267 ** If any of the information is incorrect or missing, display a warning dialog and
3268 ** return NULL. Passing "silent" as True, suppresses the warning dialogs.
3270 static languageModeRec
*readLMDialogFields(int silent
)
3272 languageModeRec
*lm
;
3274 char *compileMsg
, *extStr
, *extPtr
;
3276 /* Allocate a language mode structure to return, set unread fields to
3277 empty so everything can be freed on errors by freeLanguageModeRec */
3278 lm
= (languageModeRec
*)XtMalloc(sizeof(languageModeRec
));
3279 lm
->nExtensions
= 0;
3280 lm
->recognitionExpr
= NULL
;
3281 lm
->defTipsFile
= NULL
;
3282 lm
->delimiters
= NULL
;
3284 /* read the name field */
3285 lm
->name
= ReadSymbolicFieldTextWidget(LMDialog
.nameW
,
3286 "language mode name", silent
);
3287 if (lm
->name
== NULL
) {
3292 if (*lm
->name
== '\0')
3296 DialogF(DF_WARN
, LMDialog
.shell
, 1, "Language Mode Name",
3297 "Please specify a name\nfor the language mode", "Dismiss");
3298 XmProcessTraversal(LMDialog
.nameW
, XmTRAVERSE_CURRENT
);
3300 freeLanguageModeRec(lm
);
3304 /* read the extension list field */
3305 extStr
= extPtr
= XmTextGetString(LMDialog
.extW
);
3306 lm
->extensions
= readExtensionList(&extPtr
, &lm
->nExtensions
);
3309 /* read recognition expression */
3310 lm
->recognitionExpr
= XmTextGetString(LMDialog
.recogW
);
3311 if (*lm
->recognitionExpr
== '\0') {
3312 XtFree(lm
->recognitionExpr
);
3313 lm
->recognitionExpr
= NULL
;
3316 compiledRE
= CompileRE(lm
->recognitionExpr
, &compileMsg
, REDFLT_STANDARD
);
3318 if (compiledRE
== NULL
)
3322 DialogF(DF_WARN
, LMDialog
.shell
, 1, "Regex",
3323 "Recognition expression:\n%s", "Dismiss", compileMsg
);
3324 XmProcessTraversal(LMDialog
.recogW
, XmTRAVERSE_CURRENT
);
3326 XtFree((char *)compiledRE
);
3327 freeLanguageModeRec(lm
);
3331 XtFree((char *)compiledRE
);
3334 /* Read the default calltips file for the language mode */
3335 lm
->defTipsFile
= XmTextGetString(LMDialog
.defTipsW
);
3336 if (*lm
->defTipsFile
== '\0') {
3338 XtFree(lm
->defTipsFile
);
3339 lm
->defTipsFile
= NULL
;
3341 /* Ensure that AddTagsFile will work */
3342 if (AddTagsFile(lm
->defTipsFile
, TIP
) == FALSE
) {
3345 DialogF(DF_WARN
, LMDialog
.shell
, 1, "Error reading Calltips",
3346 "Can't read default calltips file(s):\n \"%s\"\n",
3347 "Dismiss", lm
->defTipsFile
);
3348 XmProcessTraversal(LMDialog
.recogW
, XmTRAVERSE_CURRENT
);
3350 freeLanguageModeRec(lm
);
3353 if (DeleteTagsFile(lm
->defTipsFile
, TIP
) == FALSE
)
3354 fprintf(stderr
, "nedit: Internal error: Trouble deleting "
3355 "calltips file(s):\n \"%s\"\n", lm
->defTipsFile
);
3358 /* read tab spacing field */
3359 if (TextWidgetIsBlank(LMDialog
.tabW
))
3360 lm
->tabDist
= DEFAULT_TAB_DIST
;
3362 if (GetIntTextWarn(LMDialog
.tabW
, &lm
->tabDist
, "tab spacing", False
)
3364 freeLanguageModeRec(lm
);
3368 if (lm
->tabDist
<= 0 || lm
->tabDist
> 100)
3372 DialogF(DF_WARN
, LMDialog
.shell
, 1, "Invalid Tab Spacing",
3373 "Invalid tab spacing: %d", "Dismiss", lm
->tabDist
);
3374 XmProcessTraversal(LMDialog
.tabW
, XmTRAVERSE_CURRENT
);
3376 freeLanguageModeRec(lm
);
3381 /* read emulated tab field */
3382 if (TextWidgetIsBlank(LMDialog
.emTabW
))
3384 lm
->emTabDist
= DEFAULT_EM_TAB_DIST
;
3387 if (GetIntTextWarn(LMDialog
.emTabW
, &lm
->emTabDist
,
3388 "emulated tab spacing", False
) != TEXT_READ_OK
)
3390 freeLanguageModeRec(lm
);
3394 if (lm
->emTabDist
< 0 || lm
->emTabDist
> 100)
3398 DialogF(DF_WARN
, LMDialog
.shell
, 1, "Invalid Tab Spacing",
3399 "Invalid emulated tab spacing: %d", "Dismiss",
3401 XmProcessTraversal(LMDialog
.emTabW
, XmTRAVERSE_CURRENT
);
3403 freeLanguageModeRec(lm
);
3408 /* read delimiters string */
3409 lm
->delimiters
= XmTextGetString(LMDialog
.delimitW
);
3410 if (*lm
->delimiters
== '\0') {
3411 XtFree(lm
->delimiters
);
3412 lm
->delimiters
= NULL
;
3415 /* read indent style */
3416 if (XmToggleButtonGetState(LMDialog
.noIndentW
))
3417 lm
->indentStyle
= NO_AUTO_INDENT
;
3418 else if (XmToggleButtonGetState(LMDialog
.autoIndentW
))
3419 lm
->indentStyle
= AUTO_INDENT
;
3420 else if (XmToggleButtonGetState(LMDialog
.smartIndentW
))
3421 lm
->indentStyle
= SMART_INDENT
;
3423 lm
->indentStyle
= DEFAULT_INDENT
;
3425 /* read wrap style */
3426 if (XmToggleButtonGetState(LMDialog
.noWrapW
))
3427 lm
->wrapStyle
= NO_WRAP
;
3428 else if (XmToggleButtonGetState(LMDialog
.newlineWrapW
))
3429 lm
->wrapStyle
= NEWLINE_WRAP
;
3430 else if (XmToggleButtonGetState(LMDialog
.contWrapW
))
3431 lm
->wrapStyle
= CONTINUOUS_WRAP
;
3433 lm
->wrapStyle
= DEFAULT_WRAP
;
3439 ** Return True if the language mode dialog fields are blank (unchanged from the "New"
3440 ** language mode state).
3442 static int lmDialogEmpty(void)
3444 return TextWidgetIsBlank(LMDialog
.nameW
) &&
3445 TextWidgetIsBlank(LMDialog
.extW
) &&
3446 TextWidgetIsBlank(LMDialog
.recogW
) &&
3447 TextWidgetIsBlank(LMDialog
.delimitW
) &&
3448 TextWidgetIsBlank(LMDialog
.tabW
) &&
3449 TextWidgetIsBlank(LMDialog
.emTabW
) &&
3450 XmToggleButtonGetState(LMDialog
.defaultIndentW
) &&
3451 XmToggleButtonGetState(LMDialog
.defaultWrapW
);
3455 ** Present a dialog for changing fonts (primary, and for highlighting).
3457 void ChooseFonts(WindowInfo
*window
, int forWindow
)
3459 #define MARGIN_SPACING 10
3460 #define BTN_TEXT_OFFSET 3
3461 Widget form
, primaryLbl
, primaryBtn
, italicLbl
, italicBtn
;
3462 Widget boldLbl
, boldBtn
, boldItalicLbl
, boldItalicBtn
;
3463 Widget primaryFrame
, primaryForm
, highlightFrame
, highlightForm
;
3464 Widget okBtn
, applyBtn
, dismissBtn
;
3470 /* if the dialog is already displayed, just pop it to the top and return */
3471 if (window
->fontDialog
!= NULL
) {
3472 RaiseShellWindow(((fontDialog
*)window
->fontDialog
)->shell
);
3476 /* Create a structure for keeping track of dialog state */
3477 fd
= (fontDialog
*)XtMalloc(sizeof(fontDialog
));
3478 fd
->window
= window
;
3479 fd
->forWindow
= forWindow
;
3480 window
->fontDialog
= (void*)fd
;
3482 /* Create a form widget in a dialog shell */
3484 XtSetArg(args
[ac
], XmNautoUnmanage
, False
); ac
++;
3485 XtSetArg(args
[ac
], XmNresizePolicy
, XmRESIZE_NONE
); ac
++;
3486 form
= CreateFormDialog(window
->shell
, "choose Fonts", args
, ac
);
3487 XtVaSetValues(form
, XmNshadowThickness
, 0, NULL
);
3488 fd
->shell
= XtParent(form
);
3489 XtVaSetValues(fd
->shell
, XmNtitle
, "Text Fonts", NULL
);
3490 AddMotifCloseCallback(XtParent(form
), fontDismissCB
, fd
);
3491 XtAddCallback(form
, XmNdestroyCallback
, fontDestroyCB
, fd
);
3493 primaryFrame
= XtVaCreateManagedWidget("primaryFrame", xmFrameWidgetClass
,
3494 form
, XmNmarginHeight
, 3,
3495 XmNtopAttachment
, XmATTACH_POSITION
,
3497 XmNleftAttachment
, XmATTACH_POSITION
,
3499 XmNrightAttachment
, XmATTACH_POSITION
,
3500 XmNrightPosition
, 99, NULL
);
3501 primaryForm
= XtVaCreateManagedWidget("primaryForm", xmFormWidgetClass
,
3502 primaryFrame
, NULL
);
3503 primaryLbl
= XtVaCreateManagedWidget("primaryFont", xmLabelGadgetClass
,
3505 XmNlabelString
, s1
=XmStringCreateSimple("Primary Font"),
3507 XmNchildType
, XmFRAME_TITLE_CHILD
,
3508 XmNchildHorizontalAlignment
, XmALIGNMENT_CENTER
, NULL
);
3511 primaryBtn
= XtVaCreateManagedWidget("primaryBtn",
3512 xmPushButtonWidgetClass
, primaryForm
,
3513 XmNlabelString
, s1
=XmStringCreateSimple("Browse..."),
3515 XmNtopAttachment
, XmATTACH_POSITION
,
3517 XmNtopOffset
, BTN_TEXT_OFFSET
,
3518 XmNleftAttachment
, XmATTACH_POSITION
,
3519 XmNleftPosition
, 1, NULL
);
3521 XtAddCallback(primaryBtn
, XmNactivateCallback
, primaryBrowseCB
, fd
);
3523 fd
->primaryW
= XtVaCreateManagedWidget("primary", xmTextWidgetClass
,
3526 XmNmaxLength
, MAX_FONT_LEN
,
3527 XmNleftAttachment
, XmATTACH_WIDGET
,
3528 XmNleftWidget
, primaryBtn
,
3529 XmNtopAttachment
, XmATTACH_POSITION
,
3531 XmNrightAttachment
, XmATTACH_POSITION
,
3532 XmNrightPosition
, 99, NULL
);
3533 RemapDeleteKey(fd
->primaryW
);
3534 XtAddCallback(fd
->primaryW
, XmNvalueChangedCallback
,
3535 primaryModifiedCB
, fd
);
3536 XtVaSetValues(primaryLbl
, XmNuserData
, fd
->primaryW
, NULL
);
3538 highlightFrame
= XtVaCreateManagedWidget("highlightFrame",
3539 xmFrameWidgetClass
, form
,
3541 XmNnavigationType
, XmTAB_GROUP
,
3542 XmNtopAttachment
, XmATTACH_WIDGET
,
3543 XmNtopWidget
, primaryFrame
,
3545 XmNleftAttachment
, XmATTACH_POSITION
,
3547 XmNrightAttachment
, XmATTACH_POSITION
,
3548 XmNrightPosition
, 99, NULL
);
3549 highlightForm
= XtVaCreateManagedWidget("highlightForm", xmFormWidgetClass
,
3550 highlightFrame
, NULL
);
3551 XtVaCreateManagedWidget("highlightFonts", xmLabelGadgetClass
,
3554 s1
=XmStringCreateSimple("Fonts for Syntax Highlighting"),
3555 XmNchildType
, XmFRAME_TITLE_CHILD
,
3556 XmNchildHorizontalAlignment
, XmALIGNMENT_CENTER
, NULL
);
3559 fd
->fillW
= XtVaCreateManagedWidget("fillBtn",
3560 xmPushButtonWidgetClass
, highlightForm
,
3562 s1
=XmStringCreateSimple("Fill Highlight Fonts from Primary"),
3564 XmNtopAttachment
, XmATTACH_POSITION
,
3566 XmNtopOffset
, BTN_TEXT_OFFSET
,
3567 XmNleftAttachment
, XmATTACH_POSITION
,
3568 XmNleftPosition
, 1, NULL
);
3570 XtAddCallback(fd
->fillW
, XmNactivateCallback
, fillFromPrimaryCB
, fd
);
3572 italicLbl
= XtVaCreateManagedWidget("italicLbl", xmLabelGadgetClass
,
3574 XmNlabelString
, s1
=XmStringCreateSimple("Italic Font"),
3576 XmNalignment
, XmALIGNMENT_BEGINNING
,
3577 XmNtopAttachment
, XmATTACH_WIDGET
,
3578 XmNtopWidget
, fd
->fillW
,
3579 XmNtopOffset
, MARGIN_SPACING
,
3580 XmNleftAttachment
, XmATTACH_POSITION
,
3581 XmNleftPosition
, 1, NULL
);
3584 fd
->italicErrW
= XtVaCreateManagedWidget("italicErrLbl",
3585 xmLabelGadgetClass
, highlightForm
,
3586 XmNlabelString
, s1
=XmStringCreateSimple(
3587 "(vvv spacing is inconsistent with primary font vvv)"),
3588 XmNalignment
, XmALIGNMENT_END
,
3589 XmNtopAttachment
, XmATTACH_WIDGET
,
3590 XmNtopWidget
, fd
->fillW
,
3591 XmNtopOffset
, MARGIN_SPACING
,
3592 XmNleftAttachment
, XmATTACH_WIDGET
,
3593 XmNleftWidget
, italicLbl
,
3594 XmNrightAttachment
, XmATTACH_POSITION
,
3595 XmNrightPosition
, 99, NULL
);
3598 italicBtn
= XtVaCreateManagedWidget("italicBtn",
3599 xmPushButtonWidgetClass
, highlightForm
,
3600 XmNlabelString
, s1
=XmStringCreateSimple("Browse..."),
3602 XmNtopAttachment
, XmATTACH_WIDGET
,
3603 XmNtopWidget
, italicLbl
,
3604 XmNtopOffset
, BTN_TEXT_OFFSET
,
3605 XmNleftAttachment
, XmATTACH_POSITION
,
3606 XmNleftPosition
, 1, NULL
);
3608 XtAddCallback(italicBtn
, XmNactivateCallback
, italicBrowseCB
, fd
);
3610 fd
->italicW
= XtVaCreateManagedWidget("italic", xmTextWidgetClass
,
3612 XmNmaxLength
, MAX_FONT_LEN
,
3613 XmNleftAttachment
, XmATTACH_WIDGET
,
3614 XmNleftWidget
, italicBtn
,
3615 XmNtopAttachment
, XmATTACH_WIDGET
,
3616 XmNtopWidget
, italicLbl
,
3617 XmNrightAttachment
, XmATTACH_POSITION
,
3618 XmNrightPosition
, 99, NULL
);
3619 RemapDeleteKey(fd
->italicW
);
3620 XtAddCallback(fd
->italicW
, XmNvalueChangedCallback
,
3621 italicModifiedCB
, fd
);
3622 XtVaSetValues(italicLbl
, XmNuserData
, fd
->italicW
, NULL
);
3624 boldLbl
= XtVaCreateManagedWidget("boldLbl", xmLabelGadgetClass
,
3626 XmNlabelString
, s1
=XmStringCreateSimple("Bold Font"),
3628 XmNalignment
, XmALIGNMENT_BEGINNING
,
3629 XmNtopAttachment
, XmATTACH_WIDGET
,
3630 XmNtopWidget
, italicBtn
,
3631 XmNtopOffset
, MARGIN_SPACING
,
3632 XmNleftAttachment
, XmATTACH_POSITION
,
3633 XmNleftPosition
, 1, NULL
);
3636 fd
->boldErrW
= XtVaCreateManagedWidget("boldErrLbl",
3637 xmLabelGadgetClass
, highlightForm
,
3638 XmNlabelString
, s1
=XmStringCreateSimple(""),
3639 XmNalignment
, XmALIGNMENT_END
,
3640 XmNtopAttachment
, XmATTACH_WIDGET
,
3641 XmNtopWidget
, italicBtn
,
3642 XmNtopOffset
, MARGIN_SPACING
,
3643 XmNleftAttachment
, XmATTACH_WIDGET
,
3644 XmNleftWidget
, boldLbl
,
3645 XmNrightAttachment
, XmATTACH_POSITION
,
3646 XmNrightPosition
, 99, NULL
);
3649 boldBtn
= XtVaCreateManagedWidget("boldBtn",
3650 xmPushButtonWidgetClass
, highlightForm
,
3651 XmNlabelString
, s1
=XmStringCreateSimple("Browse..."),
3653 XmNtopAttachment
, XmATTACH_WIDGET
,
3654 XmNtopWidget
, boldLbl
,
3655 XmNtopOffset
, BTN_TEXT_OFFSET
,
3656 XmNleftAttachment
, XmATTACH_POSITION
,
3657 XmNleftPosition
, 1, NULL
);
3659 XtAddCallback(boldBtn
, XmNactivateCallback
, boldBrowseCB
, fd
);
3661 fd
->boldW
= XtVaCreateManagedWidget("bold", xmTextWidgetClass
,
3663 XmNmaxLength
, MAX_FONT_LEN
,
3664 XmNleftAttachment
, XmATTACH_WIDGET
,
3665 XmNleftWidget
, boldBtn
,
3666 XmNtopAttachment
, XmATTACH_WIDGET
,
3667 XmNtopWidget
, boldLbl
,
3668 XmNrightAttachment
, XmATTACH_POSITION
,
3669 XmNrightPosition
, 99, NULL
);
3670 RemapDeleteKey(fd
->boldW
);
3671 XtAddCallback(fd
->boldW
, XmNvalueChangedCallback
,
3672 boldModifiedCB
, fd
);
3673 XtVaSetValues(boldLbl
, XmNuserData
, fd
->boldW
, NULL
);
3675 boldItalicLbl
= XtVaCreateManagedWidget("boldItalicLbl", xmLabelGadgetClass
,
3677 XmNlabelString
, s1
=XmStringCreateSimple("Bold Italic Font"),
3679 XmNalignment
, XmALIGNMENT_BEGINNING
,
3680 XmNtopAttachment
, XmATTACH_WIDGET
,
3681 XmNtopWidget
, boldBtn
,
3682 XmNtopOffset
, MARGIN_SPACING
,
3683 XmNleftAttachment
, XmATTACH_POSITION
,
3684 XmNleftPosition
, 1, NULL
);
3687 fd
->boldItalicErrW
= XtVaCreateManagedWidget("boldItalicErrLbl",
3688 xmLabelGadgetClass
, highlightForm
,
3689 XmNlabelString
, s1
=XmStringCreateSimple(""),
3690 XmNalignment
, XmALIGNMENT_END
,
3691 XmNtopAttachment
, XmATTACH_WIDGET
,
3692 XmNtopWidget
, boldBtn
,
3693 XmNtopOffset
, MARGIN_SPACING
,
3694 XmNleftAttachment
, XmATTACH_WIDGET
,
3695 XmNleftWidget
, boldItalicLbl
,
3696 XmNrightAttachment
, XmATTACH_POSITION
,
3697 XmNrightPosition
, 99, NULL
);
3700 boldItalicBtn
= XtVaCreateManagedWidget("boldItalicBtn",
3701 xmPushButtonWidgetClass
, highlightForm
,
3702 XmNlabelString
, s1
=XmStringCreateSimple("Browse..."),
3704 XmNtopAttachment
, XmATTACH_WIDGET
,
3705 XmNtopWidget
, boldItalicLbl
,
3706 XmNtopOffset
, BTN_TEXT_OFFSET
,
3707 XmNleftAttachment
, XmATTACH_POSITION
,
3708 XmNleftPosition
, 1, NULL
);
3710 XtAddCallback(boldItalicBtn
, XmNactivateCallback
, boldItalicBrowseCB
, fd
);
3712 fd
->boldItalicW
= XtVaCreateManagedWidget("boldItalic",
3713 xmTextWidgetClass
, highlightForm
,
3714 XmNmaxLength
, MAX_FONT_LEN
,
3715 XmNleftAttachment
, XmATTACH_WIDGET
,
3716 XmNleftWidget
, boldItalicBtn
,
3717 XmNtopAttachment
, XmATTACH_WIDGET
,
3718 XmNtopWidget
, boldItalicLbl
,
3719 XmNrightAttachment
, XmATTACH_POSITION
,
3720 XmNrightPosition
, 99, NULL
);
3721 RemapDeleteKey(fd
->boldItalicW
);
3722 XtAddCallback(fd
->boldItalicW
, XmNvalueChangedCallback
,
3723 boldItalicModifiedCB
, fd
);
3724 XtVaSetValues(boldItalicLbl
, XmNuserData
, fd
->boldItalicW
, NULL
);
3726 okBtn
= XtVaCreateManagedWidget("ok", xmPushButtonWidgetClass
, form
,
3727 XmNlabelString
, s1
=XmStringCreateSimple("OK"),
3728 XmNtopAttachment
, XmATTACH_WIDGET
,
3729 XmNtopWidget
, highlightFrame
,
3730 XmNtopOffset
, MARGIN_SPACING
,
3731 XmNleftAttachment
, XmATTACH_POSITION
,
3732 XmNleftPosition
, forWindow
? 13 : 26,
3733 XmNrightAttachment
, XmATTACH_POSITION
,
3734 XmNrightPosition
, forWindow
? 27 : 40, NULL
);
3735 XtAddCallback(okBtn
, XmNactivateCallback
, fontOkCB
, fd
);
3739 applyBtn
= XtVaCreateManagedWidget("apply",xmPushButtonWidgetClass
,form
,
3740 XmNlabelString
, s1
=XmStringCreateSimple("Apply"),
3742 XmNtopAttachment
, XmATTACH_WIDGET
,
3743 XmNtopWidget
, highlightFrame
,
3744 XmNtopOffset
, MARGIN_SPACING
,
3745 XmNleftAttachment
, XmATTACH_POSITION
,
3746 XmNleftPosition
, 43,
3747 XmNrightAttachment
, XmATTACH_POSITION
,
3748 XmNrightPosition
, 57, NULL
);
3749 XtAddCallback(applyBtn
, XmNactivateCallback
, fontApplyCB
, fd
);
3753 dismissBtn
= XtVaCreateManagedWidget("dismiss",xmPushButtonWidgetClass
,form
,
3754 XmNlabelString
, s1
=XmStringCreateSimple("Dismiss"),
3755 XmNtopAttachment
, XmATTACH_WIDGET
,
3756 XmNtopWidget
, highlightFrame
,
3757 XmNtopOffset
, MARGIN_SPACING
,
3758 XmNleftAttachment
, XmATTACH_POSITION
,
3759 XmNleftPosition
, forWindow
? 73 : 59,
3760 XmNrightAttachment
, XmATTACH_POSITION
,
3761 XmNrightPosition
, forWindow
? 87 : 73, NULL
);
3762 XtAddCallback(dismissBtn
, XmNactivateCallback
, fontDismissCB
, fd
);
3765 /* Set initial default button */
3766 XtVaSetValues(form
, XmNdefaultButton
, okBtn
, NULL
);
3767 XtVaSetValues(form
, XmNcancelButton
, dismissBtn
, NULL
);
3769 /* Set initial values */
3771 XmTextSetString(fd
->primaryW
, window
->fontName
);
3772 XmTextSetString(fd
->boldW
, window
->boldFontName
);
3773 XmTextSetString(fd
->italicW
, window
->italicFontName
);
3774 XmTextSetString(fd
->boldItalicW
, window
->boldItalicFontName
);
3776 XmTextSetString(fd
->primaryW
, GetPrefFontName());
3777 XmTextSetString(fd
->boldW
, GetPrefBoldFontName());
3778 XmTextSetString(fd
->italicW
, GetPrefItalicFontName());
3779 XmTextSetString(fd
->boldItalicW
, GetPrefBoldItalicFontName());
3782 /* Handle mnemonic selection of buttons and focus to dialog */
3783 AddDialogMnemonicHandler(form
, FALSE
);
3786 ManageDialogCenteredOnPointer(form
);
3789 static void fillFromPrimaryCB(Widget w
, XtPointer clientData
,
3792 fontDialog
*fd
= (fontDialog
*)clientData
;
3793 char *primaryName
, *errMsg
;
3794 char modifiedFontName
[MAX_FONT_LEN
];
3795 char *searchString
= "(-[^-]*-[^-]*)-([^-]*)-([^-]*)-(.*)";
3796 char *italicReplaceString
= "\\1-\\2-o-\\4";
3797 char *boldReplaceString
= "\\1-bold-\\3-\\4";
3798 char *boldItalicReplaceString
= "\\1-bold-o-\\4";
3801 /* Match the primary font agains RE pattern for font names. If it
3802 doesn't match, we can't generate highlight font names, so return */
3803 compiledRE
= CompileRE(searchString
, &errMsg
, REDFLT_STANDARD
);
3804 primaryName
= XmTextGetString(fd
->primaryW
);
3805 if (!ExecRE(compiledRE
, NULL
, primaryName
, NULL
, False
, '\0', '\0', NULL
, NULL
)) {
3806 XBell(XtDisplay(fd
->shell
), 0);
3808 XtFree(primaryName
);
3812 /* Make up names for new fonts based on RE replace patterns */
3813 SubstituteRE(compiledRE
, italicReplaceString
, modifiedFontName
,
3815 XmTextSetString(fd
->italicW
, modifiedFontName
);
3816 SubstituteRE(compiledRE
, boldReplaceString
, modifiedFontName
,
3818 XmTextSetString(fd
->boldW
, modifiedFontName
);
3819 SubstituteRE(compiledRE
, boldItalicReplaceString
, modifiedFontName
,
3821 XmTextSetString(fd
->boldItalicW
, modifiedFontName
);
3822 XtFree(primaryName
);
3826 static void primaryModifiedCB(Widget w
, XtPointer clientData
,
3829 fontDialog
*fd
= (fontDialog
*)clientData
;
3831 showFontStatus(fd
, fd
->italicW
, fd
->italicErrW
);
3832 showFontStatus(fd
, fd
->boldW
, fd
->boldErrW
);
3833 showFontStatus(fd
, fd
->boldItalicW
, fd
->boldItalicErrW
);
3835 static void italicModifiedCB(Widget w
, XtPointer clientData
, XtPointer callData
)
3837 fontDialog
*fd
= (fontDialog
*)clientData
;
3839 showFontStatus(fd
, fd
->italicW
, fd
->italicErrW
);
3841 static void boldModifiedCB(Widget w
, XtPointer clientData
, XtPointer callData
)
3843 fontDialog
*fd
= (fontDialog
*)clientData
;
3845 showFontStatus(fd
, fd
->boldW
, fd
->boldErrW
);
3847 static void boldItalicModifiedCB(Widget w
, XtPointer clientData
,
3850 fontDialog
*fd
= (fontDialog
*)clientData
;
3852 showFontStatus(fd
, fd
->boldItalicW
, fd
->boldItalicErrW
);
3855 static void primaryBrowseCB(Widget w
, XtPointer clientData
, XtPointer callData
)
3857 fontDialog
*fd
= (fontDialog
*)clientData
;
3859 browseFont(fd
->shell
, fd
->primaryW
, fd
);
3861 static void italicBrowseCB(Widget w
, XtPointer clientData
, XtPointer callData
)
3863 fontDialog
*fd
= (fontDialog
*)clientData
;
3865 browseFont(fd
->shell
, fd
->italicW
, fd
);
3867 static void boldBrowseCB(Widget w
, XtPointer clientData
, XtPointer callData
)
3869 fontDialog
*fd
= (fontDialog
*)clientData
;
3871 browseFont(fd
->shell
, fd
->boldW
, fd
);
3873 static void boldItalicBrowseCB(Widget w
, XtPointer clientData
,
3876 fontDialog
*fd
= (fontDialog
*)clientData
;
3878 browseFont(fd
->shell
, fd
->boldItalicW
, fd
);
3881 static void fontDestroyCB(Widget w
, XtPointer clientData
, XtPointer callData
)
3883 fontDialog
*fd
= (fontDialog
*)clientData
;
3885 fd
->window
->fontDialog
= NULL
;
3889 static void fontOkCB(Widget w
, XtPointer clientData
, XtPointer callData
)
3891 fontDialog
*fd
= (fontDialog
*)clientData
;
3895 /* pop down and destroy the dialog */
3896 XtDestroyWidget(fd
->shell
);
3899 static void fontApplyCB(Widget w
, XtPointer clientData
, XtPointer callData
)
3901 fontDialog
*fd
= (fontDialog
*)clientData
;
3906 static void fontDismissCB(Widget w
, XtPointer clientData
, XtPointer callData
)
3908 fontDialog
*fd
= (fontDialog
*)clientData
;
3910 /* pop down and destroy the dialog */
3911 XtDestroyWidget(fd
->shell
);
3915 ** Check over a font name in a text field to make sure it agrees with the
3916 ** primary font in height and spacing.
3918 static int checkFontStatus(fontDialog
*fd
, Widget fontTextFieldW
)
3920 char *primaryName
, *testName
;
3921 XFontStruct
*primaryFont
, *testFont
;
3922 Display
*display
= XtDisplay(fontTextFieldW
);
3923 int primaryWidth
, primaryHeight
, testWidth
, testHeight
;
3925 /* Get width and height of the font to check. Note the test for empty
3926 name: X11R6 clients freak out X11R5 servers if they ask them to load
3927 an empty font name, and kill the whole application! */
3928 testName
= XmTextGetString(fontTextFieldW
);
3929 if (testName
[0] == '\0') {
3933 testFont
= XLoadQueryFont(display
, testName
);
3934 if (testFont
== NULL
) {
3939 testWidth
= testFont
->min_bounds
.width
;
3940 testHeight
= testFont
->ascent
+ testFont
->descent
;
3941 XFreeFont(display
, testFont
);
3943 /* Get width and height of the primary font */
3944 primaryName
= XmTextGetString(fd
->primaryW
);
3945 if (primaryName
[0] == '\0') {
3946 XtFree(primaryName
);
3949 primaryFont
= XLoadQueryFont(display
, primaryName
);
3950 if (primaryFont
== NULL
) {
3951 XtFree(primaryName
);
3954 XtFree(primaryName
);
3955 primaryWidth
= primaryFont
->min_bounds
.width
;
3956 primaryHeight
= primaryFont
->ascent
+ primaryFont
->descent
;
3957 XFreeFont(display
, primaryFont
);
3959 /* Compare font information */
3960 if (testWidth
!= primaryWidth
)
3962 if (testHeight
!= primaryHeight
)
3968 ** Update the error label for a font text field to reflect its validity and degree
3969 ** of agreement with the currently selected primary font
3971 static int showFontStatus(fontDialog
*fd
, Widget fontTextFieldW
,
3978 status
= checkFontStatus(fd
, fontTextFieldW
);
3979 if (status
== BAD_PRIMARY
)
3980 msg
= "(font below may not match primary font)";
3981 else if (status
== BAD_FONT
)
3982 msg
= "(xxx font below is invalid xxx)";
3983 else if (status
== BAD_SIZE
)
3984 msg
= "(height of font below does not match primary)";
3985 else if (status
== BAD_SPACING
)
3986 msg
= "(spacing of font below does not match primary)";
3990 XtVaSetValues(errorLabelW
, XmNlabelString
, s
=XmStringCreateSimple(msg
),
3997 ** Put up a font selector panel to set the font name in the text widget "fontTextW"
3999 static void browseFont(Widget parent
, Widget fontTextW
, fontDialog
*fd
)
4001 char *origFontName
, *newFontName
;
4002 Pixel fgPixel
, bgPixel
;
4005 origFontName
= XmTextGetString(fontTextW
);
4007 /* Get the values from the defaults */
4008 fgPixel
= AllocColor(parent
, GetPrefColorName(TEXT_FG_COLOR
),
4009 &dummy
, &dummy
, &dummy
);
4010 bgPixel
= AllocColor(parent
, GetPrefColorName(TEXT_BG_COLOR
),
4011 &dummy
, &dummy
, &dummy
);
4013 newFontName
= FontSel(parent
, PREF_FIXED
, origFontName
, fgPixel
, bgPixel
);
4014 XtFree(origFontName
);
4015 if (newFontName
== NULL
)
4017 XmTextSetString(fontTextW
, newFontName
);
4018 XtFree(newFontName
);
4022 ** Accept the changes in the dialog and set the fonts regardless of errors
4024 static void updateFonts(fontDialog
*fd
)
4026 char *fontName
, *italicName
, *boldName
, *boldItalicName
;
4028 fontName
= XmTextGetString(fd
->primaryW
);
4029 italicName
= XmTextGetString(fd
->italicW
);
4030 boldName
= XmTextGetString(fd
->boldW
);
4031 boldItalicName
= XmTextGetString(fd
->boldItalicW
);
4033 if (fd
->forWindow
) {
4035 params
[0] = fontName
;
4036 params
[1] = italicName
;
4037 params
[2] = boldName
;
4038 params
[3] = boldItalicName
;
4039 XtCallActionProc(fd
->window
->textArea
, "set_fonts", NULL
, params
, 4);
4041 SetFonts(fd->window, fontName, italicName, boldName, boldItalicName);
4045 SetPrefFont(fontName
);
4046 SetPrefItalicFont(italicName
);
4047 SetPrefBoldFont(boldName
);
4048 SetPrefBoldItalicFont(boldItalicName
);
4053 XtFree(boldItalicName
);
4057 ** Change the language mode to the one indexed by "mode", reseting word
4058 ** delimiters, syntax highlighting and other mode specific parameters
4060 static void reapplyLanguageMode(WindowInfo
*window
, int mode
, int forceDefaults
)
4063 int i
, wrapMode
, indentStyle
, tabDist
, emTabDist
, highlight
, oldEmTabDist
;
4064 int wrapModeIsDef
, tabDistIsDef
, emTabDistIsDef
, indentStyleIsDef
;
4065 int highlightIsDef
, haveHighlightPatterns
, haveSmartIndentMacros
;
4066 int oldMode
= window
->languageMode
;
4069 /* If the mode is the same, and changes aren't being forced (as might
4070 happen with Save As...), don't mess with already correct settings */
4071 if (window
->languageMode
== mode
&& !forceDefaults
)
4074 /* Change the mode name stored in the window */
4075 window
->languageMode
= mode
;
4077 /* Unload oldMode's default calltips file if there are no more windows
4078 in that mode and the mode has a default file */
4079 if (oldMode
!= PLAIN_LANGUAGE_MODE
&& LanguageModes
[oldMode
]->defTipsFile
) {
4080 for (wi
= WindowList
; wi
; wi
= wi
->next
)
4081 if (wi
->languageMode
== oldMode
) break;
4082 if (!wi
) DeleteTagsFile( LanguageModes
[oldMode
]->defTipsFile
, TIP
);
4085 /* Make sure we didn't accidentally delete a default calltips file that
4086 also belongs another language mode (also load the tips file for the
4088 for (wi
= WindowList
; wi
; wi
= wi
->next
) {
4089 i
= wi
->languageMode
;
4090 if (i
!= PLAIN_LANGUAGE_MODE
&& LanguageModes
[i
]->defTipsFile
)
4091 if (AddTagsFile( LanguageModes
[i
]->defTipsFile
, TIP
) == FALSE
)
4092 fprintf( stderr
, "Error loading default calltips file:\n"
4093 " \"%s\"\n", LanguageModes
[i
]->defTipsFile
);
4096 /* Set delimiters for all text widgets */
4097 if (mode
== PLAIN_LANGUAGE_MODE
|| LanguageModes
[mode
]->delimiters
== NULL
)
4098 delimiters
= GetPrefDelimiters();
4100 delimiters
= LanguageModes
[mode
]->delimiters
;
4101 XtVaSetValues(window
->textArea
, textNwordDelimiters
, delimiters
, NULL
);
4102 for (i
=0; i
<window
->nPanes
; i
++)
4103 XtVaSetValues(window
->textPanes
[i
], textNautoIndent
, delimiters
, NULL
);
4105 /* Decide on desired values for language-specific parameters. If a
4106 parameter was set to its default value, set it to the new default,
4107 otherwise, leave it alone */
4108 wrapModeIsDef
= window
->wrapMode
== GetPrefWrap(oldMode
);
4109 tabDistIsDef
= BufGetTabDistance(window
->buffer
) == GetPrefTabDist(oldMode
);
4110 XtVaGetValues(window
->textArea
, textNemulateTabs
, &oldEmTabDist
, NULL
);
4111 emTabDistIsDef
= oldEmTabDist
== GetPrefEmTabDist(oldMode
);
4112 indentStyleIsDef
= window
->indentStyle
== GetPrefAutoIndent(oldMode
) ||
4113 (GetPrefAutoIndent(oldMode
) == SMART_INDENT
&&
4114 window
->indentStyle
== AUTO_INDENT
&&
4115 !SmartIndentMacrosAvailable(LanguageModeName(oldMode
)));
4116 highlightIsDef
= window
->highlightSyntax
== GetPrefHighlightSyntax()
4117 || (GetPrefHighlightSyntax() &&
4118 FindPatternSet(LanguageModeName(oldMode
)) == NULL
);
4119 wrapMode
= wrapModeIsDef
|| forceDefaults
?
4120 GetPrefWrap(mode
) : window
->wrapMode
;
4121 tabDist
= tabDistIsDef
|| forceDefaults
?
4122 GetPrefTabDist(mode
) : BufGetTabDistance(window
->buffer
);
4123 emTabDist
= emTabDistIsDef
|| forceDefaults
?
4124 GetPrefEmTabDist(mode
) : oldEmTabDist
;
4125 indentStyle
= indentStyleIsDef
|| forceDefaults
?
4126 GetPrefAutoIndent(mode
) : window
->indentStyle
;
4127 highlight
= highlightIsDef
|| forceDefaults
?
4128 GetPrefHighlightSyntax() : window
->highlightSyntax
;
4130 /* Dim/undim smart-indent and highlighting menu items depending on
4131 whether patterns/macros are available */
4132 haveHighlightPatterns
= FindPatternSet(LanguageModeName(mode
)) != NULL
;
4133 haveSmartIndentMacros
= SmartIndentMacrosAvailable(LanguageModeName(mode
));
4134 XtSetSensitive(window
->highlightItem
, haveHighlightPatterns
);
4135 XtSetSensitive(window
->smartIndentItem
, haveSmartIndentMacros
);
4137 /* Turn off requested options which are not available */
4138 highlight
= haveHighlightPatterns
&& highlight
;
4139 if (indentStyle
== SMART_INDENT
&& !haveSmartIndentMacros
)
4140 indentStyle
= AUTO_INDENT
;
4142 /* Change highlighting */
4143 window
->highlightSyntax
= highlight
;
4144 XmToggleButtonSetState(window
->highlightItem
, highlight
, False
);
4145 StopHighlighting(window
);
4147 StartHighlighting(window
, False
);
4149 /* Force a change of smart indent macros (SetAutoIndent will re-start) */
4150 if (window
->indentStyle
== SMART_INDENT
) {
4151 EndSmartIndent(window
);
4152 window
->indentStyle
= AUTO_INDENT
;
4155 /* set requested wrap, indent, and tabs */
4156 SetAutoWrap(window
, wrapMode
);
4157 SetAutoIndent(window
, indentStyle
);
4158 SetTabDist(window
, tabDist
);
4159 SetEmTabDist(window
, emTabDist
);
4161 /* Add/remove language specific menu items */
4163 UpdateShellMenu(window
);
4165 UpdateMacroMenu(window
);
4166 UpdateBGMenu(window
);
4170 ** Find and return the name of the appropriate languange mode for
4171 ** the file in "window". Returns a pointer to a string, which will
4172 ** remain valid until a change is made to the language modes list.
4174 static int matchLanguageMode(WindowInfo
*window
)
4176 char *ext
, *first200
;
4177 int i
, j
, fileNameLen
, extLen
, beginPos
, endPos
, start
;
4178 const char *versionExtendedPath
;
4180 /*... look for an explicit mode statement first */
4182 /* Do a regular expression search on for recognition pattern */
4183 first200
= BufGetRange(window
->buffer
, 0, 200);
4184 for (i
=0; i
<NLanguageModes
; i
++) {
4185 if (LanguageModes
[i
]->recognitionExpr
!= NULL
) {
4186 if (SearchString(first200
, LanguageModes
[i
]->recognitionExpr
,
4187 SEARCH_FORWARD
, SEARCH_REGEX
, False
, 0, &beginPos
,
4188 &endPos
, NULL
, NULL
, NULL
))
4197 /* Look at file extension ("@@/" starts a ClearCase version extended path,
4198 which gets appended after the file extension, and therefore must be
4199 stripped off to recognize the extension to make ClearCase users happy) */
4200 fileNameLen
= strlen(window
->filename
);
4202 if (strchr(window
->filename
, ';') != NULL
)
4203 fileNameLen
= strchr(window
->filename
, ';') - window
->filename
;
4205 if ((versionExtendedPath
= GetClearCaseVersionExtendedPath(window
->filename
)) != NULL
)
4206 fileNameLen
= versionExtendedPath
- window
->filename
;
4208 for (i
=0; i
<NLanguageModes
; i
++) {
4209 for (j
=0; j
<LanguageModes
[i
]->nExtensions
; j
++) {
4210 ext
= LanguageModes
[i
]->extensions
[j
];
4211 extLen
= strlen(ext
);
4212 start
= fileNameLen
- extLen
;
4213 #if defined(__VMS) && (__VMS_VER >= 70200000)
4214 /* VMS v7.2 has case-preserving filenames */
4215 if (start
>= 0 && !strncasecmp(&window
->filename
[start
], ext
, extLen
))
4218 if (start
>= 0 && !strncmp(&window
->filename
[start
], ext
, extLen
))
4224 /* no appropriate mode was found */
4225 return PLAIN_LANGUAGE_MODE
;
4228 static int loadLanguageModesString(char *inString
, int fileVer
)
4230 char *errMsg
, *styleName
, *inPtr
= inString
;
4231 languageModeRec
*lm
;
4236 /* skip over blank space */
4237 inPtr
+= strspn(inPtr
, " \t\n");
4239 /* Allocate a language mode structure to return, set unread fields to
4240 empty so everything can be freed on errors by freeLanguageModeRec */
4241 lm
= (languageModeRec
*)XtMalloc(sizeof(languageModeRec
));
4242 lm
->nExtensions
= 0;
4243 lm
->recognitionExpr
= NULL
;
4244 lm
->defTipsFile
= NULL
;
4245 lm
->delimiters
= NULL
;
4247 /* read language mode name */
4248 lm
->name
= ReadSymbolicField(&inPtr
);
4249 if (lm
->name
== NULL
) {
4251 return modeError(NULL
,inString
,inPtr
,"language mode name required");
4253 if (!SkipDelimiter(&inPtr
, &errMsg
))
4254 return modeError(lm
, inString
, inPtr
, errMsg
);
4256 /* read list of extensions */
4257 lm
->extensions
= readExtensionList(&inPtr
,
4259 if (!SkipDelimiter(&inPtr
, &errMsg
))
4260 return modeError(lm
, inString
, inPtr
, errMsg
);
4262 /* read the recognition regular expression */
4263 if (*inPtr
== '\n' || *inPtr
== '\0' || *inPtr
== ':')
4264 lm
->recognitionExpr
= NULL
;
4265 else if (!ReadQuotedString(&inPtr
, &errMsg
, &lm
->recognitionExpr
))
4266 return modeError(lm
, inString
,inPtr
, errMsg
);
4267 if (!SkipDelimiter(&inPtr
, &errMsg
))
4268 return modeError(lm
, inString
, inPtr
, errMsg
);
4270 /* read the indent style */
4271 styleName
= ReadSymbolicField(&inPtr
);
4272 if (styleName
== NULL
)
4273 lm
->indentStyle
= DEFAULT_INDENT
;
4275 for (i
=0; i
<N_INDENT_STYLES
; i
++) {
4276 if (!strcmp(styleName
, AutoIndentTypes
[i
])) {
4277 lm
->indentStyle
= i
;
4282 if (i
== N_INDENT_STYLES
)
4283 return modeError(lm
,inString
,inPtr
,"unrecognized indent style");
4285 if (!SkipDelimiter(&inPtr
, &errMsg
))
4286 return modeError(lm
, inString
, inPtr
, errMsg
);
4288 /* read the wrap style */
4289 styleName
= ReadSymbolicField(&inPtr
);
4290 if (styleName
== NULL
)
4291 lm
->wrapStyle
= DEFAULT_WRAP
;
4293 for (i
=0; i
<N_WRAP_STYLES
; i
++) {
4294 if (!strcmp(styleName
, AutoWrapTypes
[i
])) {
4300 if (i
== N_WRAP_STYLES
)
4301 return modeError(lm
, inString
, inPtr
,"unrecognized wrap style");
4303 if (!SkipDelimiter(&inPtr
, &errMsg
))
4304 return modeError(lm
, inString
, inPtr
, errMsg
);
4306 /* read the tab distance */
4307 if (*inPtr
== '\n' || *inPtr
== '\0' || *inPtr
== ':')
4308 lm
->tabDist
= DEFAULT_TAB_DIST
;
4309 else if (!ReadNumericField(&inPtr
, &lm
->tabDist
))
4310 return modeError(lm
, inString
, inPtr
, "bad tab spacing");
4311 if (!SkipDelimiter(&inPtr
, &errMsg
))
4312 return modeError(lm
, inString
, inPtr
, errMsg
);
4314 /* read emulated tab distance */
4315 if (*inPtr
== '\n' || *inPtr
== '\0' || *inPtr
== ':')
4316 lm
->emTabDist
= DEFAULT_EM_TAB_DIST
;
4317 else if (!ReadNumericField(&inPtr
, &lm
->emTabDist
))
4318 return modeError(lm
, inString
, inPtr
, "bad emulated tab spacing");
4319 if (!SkipDelimiter(&inPtr
, &errMsg
))
4320 return modeError(lm
, inString
, inPtr
, errMsg
);
4322 /* read the delimiters string */
4323 if (*inPtr
== '\n' || *inPtr
== '\0' || *inPtr
== ':')
4324 lm
->delimiters
= NULL
;
4325 else if (!ReadQuotedString(&inPtr
, &errMsg
, &lm
->delimiters
))
4326 return modeError(lm
, inString
, inPtr
, errMsg
);
4328 /* After 5.3 all language modes need a default tips file field */
4329 if (!SkipDelimiter(&inPtr
, &errMsg
))
4331 return modeError(lm
, inString
, inPtr
, errMsg
);
4333 /* read the default tips file */
4334 if (*inPtr
== '\n' || *inPtr
== '\0')
4335 lm
->defTipsFile
= NULL
;
4336 else if (!ReadQuotedString(&inPtr
, &errMsg
, &lm
->defTipsFile
))
4337 return modeError(lm
, inString
, inPtr
, errMsg
);
4339 /* pattern set was read correctly, add/replace it in the list */
4340 for (i
=0; i
<NLanguageModes
; i
++) {
4341 if (!strcmp(LanguageModes
[i
]->name
, lm
->name
)) {
4342 freeLanguageModeRec(LanguageModes
[i
]);
4343 LanguageModes
[i
] = lm
;
4347 if (i
== NLanguageModes
) {
4348 LanguageModes
[NLanguageModes
++] = lm
;
4349 if (NLanguageModes
> MAX_LANGUAGE_MODES
)
4350 return modeError(NULL
, inString
, inPtr
,
4351 "maximum allowable number of language modes exceeded");
4354 /* if the string ends here, we're done */
4355 inPtr
+= strspn(inPtr
, " \t\n");
4361 static char *writeLanguageModesString(void)
4364 char *outStr
, *escapedStr
, *str
, numBuf
[25];
4367 outBuf
= BufCreate();
4368 for (i
=0; i
<NLanguageModes
; i
++) {
4369 BufInsert(outBuf
, outBuf
->length
, "\t");
4370 BufInsert(outBuf
, outBuf
->length
, LanguageModes
[i
]->name
);
4371 BufInsert(outBuf
, outBuf
->length
, ":");
4372 BufInsert(outBuf
, outBuf
->length
, str
= createExtString(
4373 LanguageModes
[i
]->extensions
, LanguageModes
[i
]->nExtensions
));
4375 BufInsert(outBuf
, outBuf
->length
, ":");
4376 if (LanguageModes
[i
]->recognitionExpr
!= NULL
) {
4377 BufInsert(outBuf
, outBuf
->length
,
4378 str
=MakeQuotedString(LanguageModes
[i
]->recognitionExpr
));
4381 BufInsert(outBuf
, outBuf
->length
, ":");
4382 if (LanguageModes
[i
]->indentStyle
!= DEFAULT_INDENT
)
4383 BufInsert(outBuf
, outBuf
->length
,
4384 AutoIndentTypes
[LanguageModes
[i
]->indentStyle
]);
4385 BufInsert(outBuf
, outBuf
->length
, ":");
4386 if (LanguageModes
[i
]->wrapStyle
!= DEFAULT_WRAP
)
4387 BufInsert(outBuf
, outBuf
->length
,
4388 AutoWrapTypes
[LanguageModes
[i
]->wrapStyle
]);
4389 BufInsert(outBuf
, outBuf
->length
, ":");
4390 if (LanguageModes
[i
]->tabDist
!= DEFAULT_TAB_DIST
) {
4391 sprintf(numBuf
, "%d", LanguageModes
[i
]->tabDist
);
4392 BufInsert(outBuf
, outBuf
->length
, numBuf
);
4394 BufInsert(outBuf
, outBuf
->length
, ":");
4395 if (LanguageModes
[i
]->emTabDist
!= DEFAULT_EM_TAB_DIST
) {
4396 sprintf(numBuf
, "%d", LanguageModes
[i
]->emTabDist
);
4397 BufInsert(outBuf
, outBuf
->length
, numBuf
);
4399 BufInsert(outBuf
, outBuf
->length
, ":");
4400 if (LanguageModes
[i
]->delimiters
!= NULL
) {
4401 BufInsert(outBuf
, outBuf
->length
,
4402 str
=MakeQuotedString(LanguageModes
[i
]->delimiters
));
4405 BufInsert(outBuf
, outBuf
->length
, ":");
4406 if (LanguageModes
[i
]->defTipsFile
!= NULL
) {
4407 BufInsert(outBuf
, outBuf
->length
,
4408 str
=MakeQuotedString(LanguageModes
[i
]->defTipsFile
));
4412 BufInsert(outBuf
, outBuf
->length
, "\n");
4415 /* Get the output, and lop off the trailing newline */
4416 outStr
= BufGetRange(outBuf
, 0, outBuf
->length
- 1);
4418 escapedStr
= EscapeSensitiveChars(outStr
);
4423 static char *createExtString(char **extensions
, int nExtensions
)
4426 char *outStr
, *outPtr
;
4428 for (e
=0; e
<nExtensions
; e
++)
4429 length
+= strlen(extensions
[e
]) + 1;
4430 outStr
= outPtr
= XtMalloc(length
);
4431 for (e
=0; e
<nExtensions
; e
++) {
4432 strcpy(outPtr
, extensions
[e
]);
4433 outPtr
+= strlen(extensions
[e
]);
4436 if (nExtensions
== 0)
4443 static char **readExtensionList(char **inPtr
, int *nExtensions
)
4445 char *extensionList
[MAX_FILE_EXTENSIONS
];
4446 char **retList
, *strStart
;
4449 /* skip over blank space */
4450 *inPtr
+= strspn(*inPtr
, " \t");
4452 for (i
=0; i
<MAX_FILE_EXTENSIONS
&& **inPtr
!=':' && **inPtr
!='\0'; i
++) {
4453 *inPtr
+= strspn(*inPtr
, " \t");
4455 while (**inPtr
!=' ' && **inPtr
!='\t' && **inPtr
!=':' && **inPtr
!='\0')
4457 len
= *inPtr
- strStart
;
4458 extensionList
[i
] = XtMalloc(len
+ 1);
4459 strncpy(extensionList
[i
], strStart
, len
);
4460 extensionList
[i
][len
] = '\0';
4465 retList
= (char **)XtMalloc(sizeof(char *) * i
);
4466 memcpy(retList
, extensionList
, sizeof(char *) * i
);
4470 int ReadNumericField(char **inPtr
, int *value
)
4474 /* skip over blank space */
4475 *inPtr
+= strspn(*inPtr
, " \t");
4477 if (sscanf(*inPtr
, "%d%n", value
, &charsRead
) != 1)
4479 *inPtr
+= charsRead
;
4484 ** Parse a symbolic field, skipping initial and trailing whitespace,
4485 ** stops on first invalid character or end of string. Valid characters
4486 ** are letters, numbers, _, -, +, $, #, and internal whitespace. Internal
4487 ** whitespace is compressed to single space characters.
4489 char *ReadSymbolicField(char **inPtr
)
4491 char *outStr
, *outPtr
, *strStart
, *strPtr
;
4494 /* skip over initial blank space */
4495 *inPtr
+= strspn(*inPtr
, " \t");
4497 /* Find the first invalid character or end of string to know how
4498 much memory to allocate for the returned string */
4500 while (isalnum((unsigned char)**inPtr
) || **inPtr
=='_' || **inPtr
=='-' ||
4501 **inPtr
=='+' || **inPtr
=='$' || **inPtr
=='#' || **inPtr
==' ' ||
4504 len
= *inPtr
- strStart
;
4507 outStr
= outPtr
= XtMalloc(len
+ 1);
4509 /* Copy the string, compressing internal whitespace to a single space */
4511 while (strPtr
- strStart
< len
) {
4512 if (*strPtr
== ' ' || *strPtr
== '\t') {
4513 strPtr
+= strspn(strPtr
, " \t");
4516 *outPtr
++ = *strPtr
++;
4519 /* If there's space on the end, take it back off */
4520 if (outPtr
> outStr
&& *(outPtr
-1) == ' ')
4522 if (outPtr
== outStr
) {
4531 ** parse an individual quoted string. Anything between
4532 ** double quotes is acceptable, quote characters can be escaped by "".
4533 ** Returns allocated string "string" containing
4534 ** argument minus quotes. If not successful, returns False with
4535 ** (statically allocated) message in "errMsg".
4537 int ReadQuotedString(char **inPtr
, char **errMsg
, char **string
)
4541 /* skip over blank space */
4542 *inPtr
+= strspn(*inPtr
, " \t");
4544 /* look for initial quote */
4545 if (**inPtr
!= '\"') {
4546 *errMsg
= "expecting quoted string";
4551 /* calculate max length and allocate returned string */
4552 for (c
= *inPtr
; ; c
++) {
4554 *errMsg
= "string not terminated";
4556 } else if (*c
== '\"') {
4564 /* copy string up to end quote, transforming escaped quotes into quotes */
4565 *string
= XtMalloc(c
- *inPtr
+ 1);
4568 if (**inPtr
== '\"') {
4569 if (*(*inPtr
+1) == '\"')
4574 *outPtr
++ = *(*inPtr
)++;
4578 /* skip end quote */
4584 ** Replace characters which the X resource file reader considers control
4585 ** characters, such that a string will read back as it appears in "string".
4586 ** (So far, newline characters are replaced with with \n\<newline> and
4587 ** backslashes with \\. This has not been tested exhaustively, and
4588 ** probably should be. It would certainly be more asthetic if other
4589 ** control characters were replaced as well).
4591 ** Returns an allocated string which must be freed by the caller with XtFree.
4593 char *EscapeSensitiveChars(const char *string
)
4596 char *outStr
, *outPtr
;
4599 /* calculate length and allocate returned string */
4600 for (c
=string
; *c
!='\0'; c
++) {
4603 else if (*c
== '\n')
4607 outStr
= XtMalloc(length
+ 1);
4610 /* add backslashes */
4611 for (c
=string
; *c
!='\0'; c
++) {
4614 else if (*c
== '\n') {
4626 ** Adds double quotes around a string and escape existing double quote
4627 ** characters with two double quotes. Enables the string to be read back
4628 ** by ReadQuotedString.
4630 char *MakeQuotedString(const char *string
)
4633 char *outStr
, *outPtr
;
4636 /* calculate length and allocate returned string */
4637 for (c
=string
; *c
!='\0'; c
++) {
4642 outStr
= XtMalloc(length
+ 3);
4645 /* add starting quote */
4648 /* copy string, escaping quotes with "" */
4649 for (c
=string
; *c
!='\0'; c
++) {
4655 /* add ending quote */
4658 /* terminate string and return */
4664 ** Read a dialog text field containing a symbolic name (language mode names,
4665 ** style names, highlight pattern names, colors, and fonts), clean the
4666 ** entered text of leading and trailing whitespace, compress all
4667 ** internal whitespace to one space character, and check it over for
4668 ** colons, which interfere with the preferences file reader/writer syntax.
4669 ** Returns NULL on error, and puts up a dialog if silent is False. Returns
4670 ** an empty string if the text field is blank.
4672 char *ReadSymbolicFieldTextWidget(Widget textW
, const char *fieldName
, int silent
)
4674 char *string
, *stringPtr
, *parsedString
;
4676 /* read from the text widget */
4677 string
= stringPtr
= XmTextGetString(textW
);
4679 /* parse it with the same routine used to read symbolic fields from
4680 files. If the string is not read entirely, there are invalid
4681 characters, so warn the user if not in silent mode. */
4682 parsedString
= ReadSymbolicField(&stringPtr
);
4683 if (*stringPtr
!= '\0')
4687 *(stringPtr
+ 1) = '\0';
4688 DialogF(DF_WARN
, textW
, 1, "Invalid Character",
4689 "Invalid character \"%s\" in %s", "Dismiss", stringPtr
,
4691 XmProcessTraversal(textW
, XmTRAVERSE_CURRENT
);
4694 if (parsedString
!= NULL
)
4695 XtFree(parsedString
);
4699 if (parsedString
== NULL
) {
4700 parsedString
= XtMalloc(1);
4701 *parsedString
= '\0';
4703 return parsedString
;
4707 ** Create a pulldown menu pane with the names of the current language modes.
4708 ** XmNuserData for each item contains the language mode name.
4710 Widget
CreateLanguageModeMenu(Widget parent
, XtCallbackProc cbProc
, void *cbArg
)
4716 menu
= CreatePulldownMenu(parent
, "languageModes", NULL
, 0);
4717 for (i
=0; i
<NLanguageModes
; i
++) {
4718 btn
= XtVaCreateManagedWidget("languageMode", xmPushButtonGadgetClass
,
4720 XmNlabelString
, s1
=XmStringCreateSimple(LanguageModes
[i
]->name
),
4722 XmNuserData
, (void *)LanguageModes
[i
]->name
, NULL
);
4724 XtAddCallback(btn
, XmNactivateCallback
, cbProc
, cbArg
);
4730 ** Set the language mode menu in option menu "optMenu" to
4731 ** show a particular language mode
4733 void SetLangModeMenu(Widget optMenu
, const char *modeName
)
4738 Widget pulldown
, selectedItem
;
4741 XtVaGetValues(optMenu
, XmNsubMenuId
, &pulldown
, NULL
);
4742 XtVaGetValues(pulldown
, XmNchildren
, &items
, XmNnumChildren
, &nItems
, NULL
);
4745 selectedItem
= items
[0];
4746 for (i
=0; i
<(int)nItems
; i
++) {
4747 XtVaGetValues(items
[i
], XmNuserData
, &itemName
, NULL
);
4748 if (!strcmp(itemName
, modeName
)) {
4749 selectedItem
= items
[i
];
4753 XtVaSetValues(optMenu
, XmNmenuHistory
, selectedItem
,NULL
);
4757 ** Create a submenu for chosing language mode for the current window.
4759 Widget
CreateLanguageModeSubMenu(WindowInfo
*window
, Widget parent
, char *name
,
4760 char *label
, char mnemonic
)
4762 XmString s1
=XmStringCreateSimple(label
);
4764 window
->langModeCascade
= XtVaCreateManagedWidget(name
,
4765 xmCascadeButtonGadgetClass
, parent
, XmNlabelString
,
4766 s1
, XmNmnemonic
, mnemonic
,
4767 XmNsubMenuId
, NULL
, NULL
);
4769 updateLanguageModeSubmenu(window
);
4770 return window
->langModeCascade
;
4774 ** Re-build the language mode sub-menu using the current data stored
4775 ** in the master list: LanguageModes.
4777 static void updateLanguageModeSubmenu(WindowInfo
*window
)
4782 Arg args
[1] = {{XmNradioBehavior
, (XtArgVal
)True
}};
4784 /* Destroy and re-create the menu pane */
4785 XtVaGetValues(window
->langModeCascade
, XmNsubMenuId
, &menu
, NULL
);
4787 XtDestroyWidget(menu
);
4788 menu
= CreatePulldownMenu(XtParent(window
->langModeCascade
),
4789 "languageModes", args
, 1);
4790 btn
= XtVaCreateManagedWidget("languageMode",
4791 xmToggleButtonGadgetClass
, menu
,
4792 XmNlabelString
, s1
=XmStringCreateSimple("Plain"),
4793 XmNuserData
, (void *)PLAIN_LANGUAGE_MODE
,
4794 XmNset
, window
->languageMode
==PLAIN_LANGUAGE_MODE
, NULL
);
4796 XtAddCallback(btn
, XmNvalueChangedCallback
, setLangModeCB
, window
);
4797 for (i
=0; i
<NLanguageModes
; i
++) {
4798 btn
= XtVaCreateManagedWidget("languageMode",
4799 xmToggleButtonGadgetClass
, menu
,
4800 XmNlabelString
, s1
=XmStringCreateSimple(LanguageModes
[i
]->name
),
4802 XmNuserData
, (void *)i
,
4803 XmNset
, window
->languageMode
==i
, NULL
);
4805 XtAddCallback(btn
, XmNvalueChangedCallback
, setLangModeCB
, window
);
4807 XtVaSetValues(window
->langModeCascade
, XmNsubMenuId
, menu
, NULL
);
4810 static void setLangModeCB(Widget w
, XtPointer clientData
, XtPointer callData
)
4812 WindowInfo
*window
= (WindowInfo
*)clientData
;
4816 if (!XmToggleButtonGetState(w
))
4819 /* get name of language mode stored in userData field of menu item */
4820 XtVaGetValues(w
, XmNuserData
, &mode
, NULL
);
4822 /* If the mode didn't change, do nothing */
4823 if (window
->languageMode
== (int)mode
)
4826 /* redo syntax highlighting word delimiters, etc. */
4828 reapplyLanguageMode(window, (int)mode, False);
4830 params
[0] = (((int)mode
) == PLAIN_LANGUAGE_MODE
) ? "" : LanguageModes
[(int)mode
]->name
;
4831 XtCallActionProc(window
->textArea
, "set_language_mode", NULL
, params
, 1);
4835 ** Skip a delimiter and it's surrounding whitespace
4837 int SkipDelimiter(char **inPtr
, char **errMsg
)
4839 *inPtr
+= strspn(*inPtr
, " \t");
4840 if (**inPtr
!= ':') {
4841 *errMsg
= "syntax error";
4845 *inPtr
+= strspn(*inPtr
, " \t");
4850 ** Skip an optional separator and its surrounding whitespace
4851 ** return true if delimiter found
4853 int SkipOptSeparator(char separator
, char **inPtr
, char **errMsg
)
4855 *inPtr
+= strspn(*inPtr
, " \t");
4856 if (**inPtr
!= separator
) {
4860 *inPtr
+= strspn(*inPtr
, " \t");
4865 ** Short-hand error processing for language mode parsing errors, frees
4866 ** lm (if non-null), prints a formatted message explaining where the
4867 ** error is, and returns False;
4869 static int modeError(languageModeRec
*lm
, const char *stringStart
,
4870 const char *stoppedAt
, const char *message
)
4873 freeLanguageModeRec(lm
);
4874 return ParseError(NULL
, stringStart
, stoppedAt
,
4875 "language mode specification", message
);
4879 ** Report parsing errors in resource strings or macros, formatted nicely so
4880 ** the user can tell where things became botched. Errors can be sent either
4881 ** to stderr, or displayed in a dialog. For stderr, pass toDialog as NULL.
4882 ** For a dialog, pass the dialog parent in toDialog.
4884 int ParseError(Widget toDialog
, const char *stringStart
, const char *stoppedAt
,
4885 const char *errorIn
, const char *message
)
4887 int len
, nNonWhite
= 0;
4891 for (c
=stoppedAt
; c
>=stringStart
; c
--) {
4892 if (c
== stringStart
)
4894 else if (*c
== '\n' && nNonWhite
>= 5)
4896 else if (*c
!= ' ' && *c
!= '\t')
4899 len
= stoppedAt
- c
+ (*stoppedAt
== '\0' ? 0 : 1);
4900 errorLine
= XtMalloc(len
+4);
4901 strncpy(errorLine
, c
, len
);
4902 errorLine
[len
++] = '<';
4903 errorLine
[len
++] = '=';
4904 errorLine
[len
++] = '=';
4905 errorLine
[len
] = '\0';
4906 if (toDialog
== NULL
)
4908 fprintf(stderr
, "NEdit: %s in %s:\n%s\n", message
, errorIn
, errorLine
);
4911 DialogF(DF_WARN
, toDialog
, 1, "Parse Error", "%s in %s:\n%s", "Dismiss",
4912 message
, errorIn
, errorLine
);
4919 ** Compare two strings which may be NULL
4921 int AllocatedStringsDiffer(const char *s1
, const char *s2
)
4923 if (s1
== NULL
&& s2
== NULL
)
4925 if (s1
== NULL
|| s2
== NULL
)
4927 return strcmp(s1
, s2
);
4930 static void updatePatternsTo5dot1(void)
4932 const char *htmlDefaultExpr
= "^[ \t]*HTML[ \t]*:[ \t]*Default[ \t]*$";
4933 const char *vhdlAnchorExpr
= "^[ \t]*VHDL:";
4935 /* Add new patterns if there aren't already existing patterns with
4936 the same name. If possible, insert before VHDL in language mode
4937 list. If not, just add to end */
4938 if (!regexFind(TempStringPrefs
.highlight
, "^[ \t]*PostScript:"))
4939 spliceString(&TempStringPrefs
.highlight
, "PostScript:Default",
4941 if (!regexFind(TempStringPrefs
.language
, "^[ \t]*PostScript:"))
4942 spliceString(&TempStringPrefs
.language
,
4943 "PostScript:.ps .PS .eps .EPS .epsf .epsi::::::",
4945 if (!regexFind(TempStringPrefs
.highlight
, "^[ \t]*Lex:"))
4946 spliceString(&TempStringPrefs
.highlight
, "Lex:Default",
4948 if (!regexFind(TempStringPrefs
.language
, "^[ \t]*Lex:"))
4949 spliceString(&TempStringPrefs
.language
, "Lex:.lex::::::",
4951 if (!regexFind(TempStringPrefs
.highlight
, "^[ \t]*SQL:"))
4952 spliceString(&TempStringPrefs
.highlight
, "SQL:Default",
4954 if (!regexFind(TempStringPrefs
.language
, "^[ \t]*SQL:"))
4955 spliceString(&TempStringPrefs
.language
, "SQL:.sql::::::",
4957 if (!regexFind(TempStringPrefs
.highlight
, "^[ \t]*Matlab:"))
4958 spliceString(&TempStringPrefs
.highlight
, "Matlab:Default",
4960 if (!regexFind(TempStringPrefs
.language
, "^[ \t]*Matlab:"))
4961 spliceString(&TempStringPrefs
.language
, "Matlab:..m .oct .sci::::::",
4963 if (!regexFind(TempStringPrefs
.smartIndent
, "^[ \t]*Matlab:"))
4964 spliceString(&TempStringPrefs
.smartIndent
, "Matlab:Default", NULL
);
4965 if (!regexFind(TempStringPrefs
.styles
, "^[ \t]*Label:"))
4966 spliceString(&TempStringPrefs
.styles
, "Label:red:Italic",
4968 if (!regexFind(TempStringPrefs
.styles
, "^[ \t]*Storage Type1:"))
4969 spliceString(&TempStringPrefs
.styles
, "Storage Type1:saddle brown:Bold",
4972 /* Replace html pattern with sgml html pattern, as long as there
4973 isn't an existing html pattern which will be overwritten */
4974 if (regexFind(TempStringPrefs
.highlight
, htmlDefaultExpr
)) {
4975 regexReplace(&TempStringPrefs
.highlight
, htmlDefaultExpr
,
4976 "SGML HTML:Default");
4977 if (!regexReplace(&TempStringPrefs
.language
, "^[ \t]*HTML:.*$",
4978 "SGML HTML:.sgml .sgm .html .htm:\"\\<(?ihtml)\\>\":::::\n")) {
4979 spliceString(&TempStringPrefs
.language
,
4980 "SGML HTML:.sgml .sgm .html .htm:\"\\<(?ihtml)\\>\":::::\n",
4986 static void updatePatternsTo5dot2(void)
4989 const char *cppLm5dot1
=
4990 "^[ \t]*C\\+\\+:\\.CC \\.HH \\.I::::::\"\\.,/\\\\`'!\\|@#%\\^&\\*\\(\\)-=\\+\\{\\}\\[\\]\"\":;\\<\\>\\?~\"";
4991 const char *perlLm5dot1
=
4992 "^[ \t]*Perl:\\.PL \\.PM \\.P5:\"\\^\\[ \\\\t\\]\\*#\\[ \\\\t\\]\\*!\\.\\*perl\":::::";
4993 const char *psLm5dot1
=
4994 "^[ \t]*PostScript:\\.ps \\.PS \\.eps \\.EPS \\.epsf \\.epsi:\"\\^%!\":::::\"/%\\(\\)\\{\\}\\[\\]\\<\\>\"";
4995 const char *tclLm5dot1
= "^[ \t]*Tcl:\\.TCL::::::";
4997 const char *cppLm5dot2
=
4998 "C++:.CC .HH .C .H .I .CXX .HXX .CPP::::::\".,/\\`'!|@#%^&*()-=+{}[]\"\":;<>?~\"";
4999 const char *perlLm5dot2
=
5000 "Perl:.PL .PM .P5:\"^[ \\t]*#[ \\t]*!.*perl\":Auto:None:::\".,/\\\\`'!$@#%^&*()-=+{}[]\"\":;<>?~|\"";
5001 const char *psLm5dot2
=
5002 "PostScript:.ps .PS .eps .EPS .epsf .epsi:\"^%!\":::::\"/%(){}[]<>\"";
5003 const char *tclLm5dot2
=
5004 "Tcl:.TCL::Smart:None:::";
5006 const char *cppLm5dot1
=
5007 "^[ \t]*C\\+\\+:\\.cc \\.hh \\.C \\.H \\.i \\.cxx \\.hxx::::::\"\\.,/\\\\`'!\\|@#%\\^&\\*\\(\\)-=\\+\\{\\}\\[\\]\"\":;\\<\\>\\?~\"";
5008 const char *perlLm5dot1
=
5009 "^[ \t]*Perl:\\.pl \\.pm \\.p5:\"\\^\\[ \\\\t\\]\\*#\\[ \\\\t\\]\\*!\\.\\*perl\":::::";
5010 const char *psLm5dot1
=
5011 "^[ \t]*PostScript:\\.ps \\.PS \\.eps \\.EPS \\.epsf \\.epsi:\"\\^%!\":::::\"/%\\(\\)\\{\\}\\[\\]\\<\\>\"";
5012 const char *shLm5dot1
=
5013 "^[ \t]*Sh Ksh Bash:\\.sh \\.bash \\.ksh \\.profile:\"\\^\\[ \\\\t\\]\\*#\\[ \\\\t\\]\\*!\\[ \\\\t\\]\\*/bin/\\(sh\\|ksh\\|bash\\)\":::::";
5014 const char *tclLm5dot1
= "^[ \t]*Tcl:\\.tcl::::::";
5016 const char *cppLm5dot2
=
5017 "C++:.cc .hh .C .H .i .cxx .hxx .cpp::::::\".,/\\`'!|@#%^&*()-=+{}[]\"\":;<>?~\"";
5018 const char *perlLm5dot2
=
5019 "Perl:.pl .pm .p5 .PL:\"^[ \\t]*#[ \\t]*!.*perl\":Auto:None:::\".,/\\\\`'!$@#%^&*()-=+{}[]\"\":;<>?~|\"";
5020 const char *psLm5dot2
=
5021 "PostScript:.ps .eps .epsf .epsi:\"^%!\":::::\"/%(){}[]<>\"";
5022 const char *shLm5dot2
=
5023 "Sh Ksh Bash:.sh .bash .ksh .profile .bashrc .bash_logout .bash_login .bash_profile:\"^[ \\t]*#[ \\t]*![ \\t]*/.*bin/(sh|ksh|bash)\":::::";
5024 const char *tclLm5dot2
=
5025 "Tcl:.tcl .tk .itcl .itk::Smart:None:::";
5028 const char *cssLm5dot2
=
5029 "CSS:css::Auto:None:::\".,/\\`'!|@#%^&*()=+{}[]\"\":;<>?~\"";
5030 const char *reLm5dot2
=
5031 "Regex:.reg .regex:\"\\(\\?[:#=!iInN].+\\)\":None:Continuous:::";
5032 const char *xmlLm5dot2
=
5033 "XML:.xml .xsl .dtd:\"\\<(?i\\?xml|!doctype)\"::None:::\"<>/=\"\"'()+*?|\"";
5035 const char *cssHl5dot2
= "CSS:Default";
5036 const char *reHl5dot2
= "Regex:Default";
5037 const char *xmlHl5dot2
= "XML:Default";
5039 const char *ptrStyle
= "Pointer:#660000:Bold";
5040 const char *reStyle
= "Regex:#009944:Bold";
5041 const char *wrnStyle
= "Warning:brown2:Italic";
5043 /* First upgrade modified language modes, only if the user hasn't
5044 altered the default 5.1 definitions. */
5045 if (regexFind(TempStringPrefs
.language
, cppLm5dot1
))
5046 regexReplace(&TempStringPrefs
.language
, cppLm5dot1
, cppLm5dot2
);
5047 if (regexFind(TempStringPrefs
.language
, perlLm5dot1
))
5048 regexReplace(&TempStringPrefs
.language
, perlLm5dot1
, perlLm5dot2
);
5049 if (regexFind(TempStringPrefs
.language
, psLm5dot1
))
5050 regexReplace(&TempStringPrefs
.language
, psLm5dot1
, psLm5dot2
);
5052 if (regexFind(TempStringPrefs
.language
, shLm5dot1
))
5053 regexReplace(&TempStringPrefs
.language
, shLm5dot1
, shLm5dot2
);
5055 if (regexFind(TempStringPrefs
.language
, tclLm5dot1
))
5056 regexReplace(&TempStringPrefs
.language
, tclLm5dot1
, tclLm5dot2
);
5058 /* Then append the new modes (trying to keep them in alphabetical order
5059 makes no sense, since 5.1 didn't use alphabetical order). */
5060 if (!regexFind(TempStringPrefs
.language
, "^[ \t]*CSS:"))
5061 spliceString(&TempStringPrefs
.language
, cssLm5dot2
, NULL
);
5062 if (!regexFind(TempStringPrefs
.language
, "^[ \t]*Regex:"))
5063 spliceString(&TempStringPrefs
.language
, reLm5dot2
, NULL
);
5064 if (!regexFind(TempStringPrefs
.language
, "^[ \t]*XML:"))
5065 spliceString(&TempStringPrefs
.language
, xmlLm5dot2
, NULL
);
5067 /* Enable default highlighting patterns for these modes, unless already
5069 if (!regexFind(TempStringPrefs
.highlight
, "^[ \t]*CSS:"))
5070 spliceString(&TempStringPrefs
.highlight
, cssHl5dot2
, NULL
);
5071 if (!regexFind(TempStringPrefs
.highlight
, "^[ \t]*Regex:"))
5072 spliceString(&TempStringPrefs
.highlight
, reHl5dot2
, NULL
);
5073 if (!regexFind(TempStringPrefs
.highlight
, "^[ \t]*XML:"))
5074 spliceString(&TempStringPrefs
.highlight
, xmlHl5dot2
, NULL
);
5076 /* Finally, append the new highlight styles */
5078 if (!regexFind(TempStringPrefs
.styles
, "^[ \t]*Warning:"))
5079 spliceString(&TempStringPrefs
.styles
, wrnStyle
, NULL
);
5080 if (!regexFind(TempStringPrefs
.styles
, "^[ \t]*Regex:"))
5081 spliceString(&TempStringPrefs
.styles
, reStyle
, "^[ \t]*Warning:");
5082 if (!regexFind(TempStringPrefs
.styles
, "^[ \t]*Pointer:"))
5083 spliceString(&TempStringPrefs
.styles
, ptrStyle
, "^[ \t]*Regex:");
5086 static void updatePatternsTo5dot3(void)
5088 /* This is a bogus function on non-VMS */
5090 const char *psLm5dot2
=
5091 "^[ \t]*PostScript:\\.ps \\.PS \\.eps \\.EPS \\.epsf \\.epsi:\"\\^%!\":::::\"/%\\(\\)\\{\\}\\[\\]\\<\\>\"";
5093 const char *psLm5dot3
=
5094 "PostScript:.ps .PS .eps .EPS .epsf .EPSF .epsi .EPSI:\"^%!\":::::\"/%(){}[]<>\"";
5096 /* Upgrade modified language modes, only if the user hasn't
5097 altered the default 5.2 definitions. */
5098 if (regexFind(TempStringPrefs
.language
, psLm5dot2
))
5099 regexReplace(&TempStringPrefs
.language
, psLm5dot2
, psLm5dot3
);
5103 static void updatePatternsTo5dot4(void)
5106 const char *pyLm5dot3
=
5107 "Python:\\.PY:\"\\^#!\\.\\*python\":Auto:None::::?\n";
5108 const char *xrLm5dot3
=
5109 "X Resources:\\.XRESOURCES \\.XDEFAULTS \\.NEDIT:\"\\^\\[!#\\]\\.\\*\\(\\[Aa\\]pp\\|\\[Xx\\]\\)\\.\\*\\[Dd\\]efaults\"::::::?\n";
5111 const char *pyLm5dot4
=
5112 "Python:.PY:\"^#!.*python\":Auto:None:::\"!\"\"#$%&'()*+,-./:;<=>?@[\\\\]^`{|}~\":\n";
5113 const char *xrLm5dot4
=
5114 "X Resources:.XRESOURCES .XDEFAULTS .NEDIT NEDIT.RC:\"^[!#].*([Aa]pp|[Xx]).*[Dd]efaults\"::::::\n";
5116 const char *pyLm5dot3
=
5117 "Python:\\.py:\"\\^#!\\.\\*python\":Auto:None::::?\n";
5118 const char *xrLm5dot3
=
5119 "X Resources:\\.Xresources \\.Xdefaults \\.nedit:\"\\^\\[!#\\]\\.\\*\\(\\[Aa\\]pp\\|\\[Xx\\]\\)\\.\\*\\[Dd\\]efaults\"::::::?\n";
5121 const char *pyLm5dot4
=
5122 "Python:.py:\"^#!.*python\":Auto:None:::\"!\"\"#$%&'()*+,-./:;<=>?@[\\\\]^`{|}~\":\n";
5123 const char *xrLm5dot4
=
5124 "X Resources:.Xresources .Xdefaults .nedit nedit.rc:\"^[!#].*([Aa]pp|[Xx]).*[Dd]efaults\"::::::\n";
5127 /* Upgrade modified language modes, only if the user hasn't
5128 altered the default 5.3 definitions. */
5129 if (regexFind(TempStringPrefs
.language
, pyLm5dot3
))
5130 regexReplace(&TempStringPrefs
.language
, pyLm5dot3
, pyLm5dot4
);
5131 if (regexFind(TempStringPrefs
.language
, xrLm5dot3
))
5132 regexReplace(&TempStringPrefs
.language
, xrLm5dot3
, xrLm5dot4
);
5134 /* Add new styles */
5135 if (!regexFind(TempStringPrefs
.styles
, "^[ \t]*Identifier2:"))
5136 spliceString(&TempStringPrefs
.styles
, "Identifier2:SteelBlue:Plain",
5137 "^[ \t]*Subroutine:");
5141 * We migrate a color from the X resources to the prefs if:
5142 * 1. The prefs entry is equal to the default entry
5143 * 2. The X resource is not equal to the default entry
5145 static void migrateColor(XrmDatabase prefDB
, XrmDatabase appDB
,
5146 char *class, char *name
, int color_index
, char *default_val
)
5148 char *type
, *valueString
;
5151 /* If this color has been customized in the color dialog then use
5153 if ( strcmp(default_val
, PrefData
.colorNames
[color_index
]) )
5156 /* Retrieve the value of the resource from the DB */
5157 if (XrmGetResource(prefDB
, name
, class, &type
, &rsrcValue
)) {
5158 if (strcmp(type
, XmRString
)) {
5159 fprintf(stderr
,"Internal Error: Unexpected resource type, %s\n",
5163 valueString
= rsrcValue
.addr
;
5164 } else if (XrmGetResource(appDB
, name
, class, &type
, &rsrcValue
)) {
5165 if (strcmp(type
, XmRString
)) {
5166 fprintf(stderr
,"Internal Error: Unexpected resource type, %s\n",
5170 valueString
= rsrcValue
.addr
;
5172 /* No resources set */
5175 /* An X resource is set. If it's non-default, update the prefs. */
5176 if ( strcmp(valueString
, default_val
) ) {
5177 strncpy(PrefData
.colorNames
[color_index
], valueString
,
5183 * In 5.4 we moved color preferences from X resources to a color dialog,
5184 * meaning they're in the normal prefs system. Users who have customized
5185 * their colors with X resources would probably prefer not to have to redo
5186 * the customization in the dialog, so we migrate them to the prefs for them.
5188 static void migrateColorResources(XrmDatabase prefDB
, XrmDatabase appDB
)
5190 migrateColor(prefDB
, appDB
, APP_CLASS
".Text.Foreground",
5191 APP_NAME
".text.foreground", TEXT_FG_COLOR
,
5193 migrateColor(prefDB
, appDB
, APP_CLASS
".Text.Background",
5194 APP_NAME
".text.background", TEXT_BG_COLOR
,
5195 NEDIT_DEFAULT_TEXT_BG
);
5196 migrateColor(prefDB
, appDB
, APP_CLASS
".Text.SelectForeground",
5197 APP_NAME
".text.selectForeground", SELECT_FG_COLOR
,
5198 NEDIT_DEFAULT_SEL_FG
);
5199 migrateColor(prefDB
, appDB
, APP_CLASS
".Text.SelectBackground",
5200 APP_NAME
".text.selectBackground", SELECT_BG_COLOR
,
5201 NEDIT_DEFAULT_SEL_BG
);
5202 migrateColor(prefDB
, appDB
, APP_CLASS
".Text.HighlightForeground",
5203 APP_NAME
".text.highlightForeground", HILITE_FG_COLOR
,
5204 NEDIT_DEFAULT_HI_FG
);
5205 migrateColor(prefDB
, appDB
, APP_CLASS
".Text.HighlightBackground",
5206 APP_NAME
".text.highlightBackground", HILITE_BG_COLOR
,
5207 NEDIT_DEFAULT_HI_BG
);
5208 migrateColor(prefDB
, appDB
, APP_CLASS
".Text.LineNumForeground",
5209 APP_NAME
".text.lineNumForeground", LINENO_FG_COLOR
,
5210 NEDIT_DEFAULT_LINENO_FG
);
5211 migrateColor(prefDB
, appDB
, APP_CLASS
".Text.CursorForeground",
5212 APP_NAME
".text.cursorForeground", CURSOR_FG_COLOR
,
5213 NEDIT_DEFAULT_CURSOR_FG
);
5217 ** Inserts a string into intoString, reallocating it with XtMalloc. If
5218 ** regular expression atExpr is found, inserts the string before atExpr
5219 ** followed by a newline. If atExpr is not found, inserts insertString
5220 ** at the end, PRECEDED by a newline.
5222 static void spliceString(char **intoString
, const char *insertString
, const char *atExpr
)
5224 int beginPos
, endPos
;
5225 int intoLen
= strlen(*intoString
);
5226 int insertLen
= strlen(insertString
);
5227 char *newString
= XtMalloc(intoLen
+ insertLen
+ 2);
5229 if (atExpr
!= NULL
&& SearchString(*intoString
, atExpr
,
5230 SEARCH_FORWARD
, SEARCH_REGEX
, False
, 0, &beginPos
, &endPos
,
5231 NULL
, NULL
, NULL
)) {
5232 strncpy(newString
, *intoString
, beginPos
);
5233 strncpy(&newString
[beginPos
], insertString
, insertLen
);
5234 newString
[beginPos
+insertLen
] = '\n';
5235 strncpy(&newString
[beginPos
+insertLen
+1],
5236 &((*intoString
)[beginPos
]), intoLen
- beginPos
);
5238 strncpy(newString
, *intoString
, intoLen
);
5239 newString
[intoLen
] = '\n';
5240 strncpy(&newString
[intoLen
+1], insertString
, insertLen
);
5242 newString
[intoLen
+ insertLen
+ 1] = '\0';
5243 XtFree(*intoString
);
5244 *intoString
= newString
;
5248 ** Simplified regular expression search routine which just returns true
5249 ** or false depending on whether inString matches expr
5251 static int regexFind(const char *inString
, const char *expr
)
5253 int beginPos
, endPos
;
5254 return SearchString(inString
, expr
, SEARCH_FORWARD
, SEARCH_REGEX
, False
,
5255 0, &beginPos
, &endPos
, NULL
, NULL
, NULL
);
5259 ** Simplified regular expression replacement routine which replaces the
5260 ** first occurence of expr in inString with replaceWith, reallocating
5261 ** inString with XtMalloc. If expr is not found, does nothing and
5264 static int regexReplace(char **inString
, const char *expr
, const char *replaceWith
)
5266 int beginPos
, endPos
, newLen
;
5268 int replaceLen
= strlen(replaceWith
);
5269 int inLen
= strlen(*inString
);
5271 if (!SearchString(*inString
, expr
, SEARCH_FORWARD
, SEARCH_REGEX
, False
,
5272 0, &beginPos
, &endPos
, NULL
, NULL
, NULL
))
5274 newLen
= inLen
+ replaceLen
- (endPos
-beginPos
);
5275 newString
= XtMalloc(newLen
+ 1);
5276 strncpy(newString
, *inString
, beginPos
);
5277 strncpy(&newString
[beginPos
], replaceWith
, replaceLen
);
5278 strncpy(&newString
[beginPos
+replaceLen
],
5279 &((*inString
)[endPos
]), inLen
- endPos
);
5280 newString
[newLen
] = '\0';
5282 *inString
= newString
;
5289 ** Replace all '#' characters in shell commands by '##' to keep commands
5290 ** containing those working. '#' is a line number placeholder in 5.3 and
5291 ** had no special meaning before.
5293 static void updateShellCmdsTo5dot3(void)
5295 char *cOld
, *cNew
, *pCol
, *pNL
;
5299 if(!TempStringPrefs
.shellCmds
)
5302 /* Count number of '#'. If there are '#' characters in the non-command
5303 ** part of the definition we count too much and later allocate too much
5304 ** memory for the new string, but this doesn't hurt.
5306 for(cOld
=TempStringPrefs
.shellCmds
, nHash
=0; *cOld
; cOld
++)
5310 /* No '#' -> no conversion necessary. */
5314 newString
=XtMalloc(strlen(TempStringPrefs
.shellCmds
) + 1 + nHash
);
5316 cOld
= TempStringPrefs
.shellCmds
;
5322 /* Copy all characters from TempStringPrefs.shellCmds into newString
5323 ** and duplicate '#' in command parts. A simple check for really beeing
5324 ** inside a command part (starting with '\n', between the the two last
5325 ** '\n' a colon ':' must have been found) is preformed.
5328 /* actually every 2nd line is a command. We additionally
5329 ** check if there is a colon ':' in the previous line.
5332 if((pCol
> pNL
) && !isCmd
)
5339 if(!isCmd
&& *cOld
==':')
5342 /* Duplicate hashes if we're in a command part */
5343 if(isCmd
&& *cOld
=='#')
5346 /* Copy every character */
5351 /* Terminate new preferences string */
5354 /* free the old memory */
5355 XtFree(TempStringPrefs
.shellCmds
);
5357 /* exchange the string */
5358 TempStringPrefs
.shellCmds
= newString
;
5364 static void updateShellCmdsTo5dot3(void) {
5365 /* No shell commands in VMS ! */
5371 static void updateShellCmdsTo5dot4(void)
5373 #ifndef VMS /* No shell commands on VMS */
5376 const char* wc5dot3
=
5377 "^(\\s*)set wc=`wc`; echo \\$wc\\[1\\] \"words,\" \\$wc\\[2\\] \"lines,\" \\$wc\\[3\\] \"characters\"\\n";
5378 const char* wc5dot4
=
5379 "wc | awk '{print $2 \" lines, \" $1 \" words, \" $3 \" characters\"}'\n";
5381 const char* wc5dot3
=
5382 "^(\\s*)set wc=`wc`; echo \\$wc\\[1\\] \"lines,\" \\$wc\\[2\\] \"words,\" \\$wc\\[3\\] \"characters\"\\n";
5383 const char* wc5dot4
=
5384 "wc | awk '{print $1 \" lines, \" $2 \" words, \" $3 \" characters\"}'\n";
5385 #endif /* __FreeBSD__ */
5387 if (regexFind(TempStringPrefs
.shellCmds
, wc5dot3
))
5388 regexReplace(&TempStringPrefs
.shellCmds
, wc5dot3
, wc5dot4
);
5397 ** Present the user a dialog for specifying whether or not a short
5398 ** menu mode preference should be applied toward the default setting.
5399 ** Return False (function value) if operation was canceled, return True
5400 ** in setDefault if requested to reset the default value.
5402 static int shortPrefToDefault(Widget parent
, const char *settingName
, int *setDefault
)
5406 if (!GetPrefShortMenus()) {
5407 *setDefault
= False
;
5411 sprintf(msg
, "%s\nSave as default for future windows as well?", settingName
);
5412 switch (DialogF (DF_QUES
, parent
, 3, "Save Default", msg
, "Yes", "No",
5419 *setDefault
= False
;
5421 case 3: /* cancel */
5424 return False
; /* not reached */
5428 /* Unload the default calltips file for this window unless somebody else
5430 void UnloadLanguageModeTipsFile(WindowInfo
*window
) {
5434 mode
= window
->languageMode
;
5435 if (mode
!= PLAIN_LANGUAGE_MODE
&& LanguageModes
[mode
]->defTipsFile
) {
5436 for (wi
= WindowList
; wi
; wi
= wi
->next
)
5437 if (wi
->languageMode
== mode
&& wi
!= window
)
5439 if (!wi
) /* If we got to end of WindowList... */
5440 DeleteTagsFile( LanguageModes
[mode
]->defTipsFile
, TIP
);
5443 /* Make sure we didn't accidentally delete a default calltips file that
5444 also belongs to another language mode */
5445 for (wi
= WindowList
; wi
; wi
= wi
->next
) {
5448 mode
= wi
->languageMode
;
5449 if (mode
!= PLAIN_LANGUAGE_MODE
&& LanguageModes
[mode
]->defTipsFile
)
5450 if (AddTagsFile( LanguageModes
[mode
]->defTipsFile
, TIP
) == FALSE
)
5451 fprintf( stderr
, "Error loading default calltips file:\n"
5452 " \"%s\"\n", LanguageModes
[mode
]->defTipsFile
);
5456 /******************************************************************************
5457 * The Color selection dialog
5458 ******************************************************************************/
5461 There are 8 colors: And 8 indices:
5462 textFg TEXT_FG_COLOR
5463 textBg TEXT_BG_COLOR
5464 selectFg SELECT_FG_COLOR
5465 selectBg SELECT_BG_COLOR
5466 hiliteFg HILITE_FG_COLOR
5467 hiliteBg HILITE_BG_COLOR
5468 lineNoFg LINENO_FG_COLOR
5469 cursorFg CURSOR_FG_COLOR
5472 #define MARGIN_SPACING 10
5475 * Callbacks for field modifications
5477 static void textFgModifiedCB(Widget w
, XtPointer clientData
,
5480 colorDialog
*cd
= (colorDialog
*)clientData
;
5481 showColorStatus(cd
, cd
->textFgW
, cd
->textFgErrW
);
5484 static void textBgModifiedCB(Widget w
, XtPointer clientData
,
5487 colorDialog
*cd
= (colorDialog
*)clientData
;
5488 showColorStatus(cd
, cd
->textBgW
, cd
->textBgErrW
);
5491 static void selectFgModifiedCB(Widget w
, XtPointer clientData
,
5494 colorDialog
*cd
= (colorDialog
*)clientData
;
5495 showColorStatus(cd
, cd
->selectFgW
, cd
->selectFgErrW
);
5498 static void selectBgModifiedCB(Widget w
, XtPointer clientData
,
5501 colorDialog
*cd
= (colorDialog
*)clientData
;
5502 showColorStatus(cd
, cd
->selectBgW
, cd
->selectBgErrW
);
5505 static void hiliteFgModifiedCB(Widget w
, XtPointer clientData
,
5508 colorDialog
*cd
= (colorDialog
*)clientData
;
5509 showColorStatus(cd
, cd
->hiliteFgW
, cd
->hiliteFgErrW
);
5512 static void hiliteBgModifiedCB(Widget w
, XtPointer clientData
,
5515 colorDialog
*cd
= (colorDialog
*)clientData
;
5516 showColorStatus(cd
, cd
->hiliteBgW
, cd
->hiliteBgErrW
);
5519 static void lineNoFgModifiedCB(Widget w
, XtPointer clientData
,
5522 colorDialog
*cd
= (colorDialog
*)clientData
;
5523 showColorStatus(cd
, cd
->lineNoFgW
, cd
->lineNoFgErrW
);
5526 static void cursorFgModifiedCB(Widget w
, XtPointer clientData
,
5529 colorDialog
*cd
= (colorDialog
*)clientData
;
5530 showColorStatus(cd
, cd
->cursorFgW
, cd
->cursorFgErrW
);
5535 * Helper functions for validating colors
5537 static int verifyAllColors(colorDialog
*cd
) {
5538 /* Maybe just check for empty strings in error widgets instead? */
5539 return (checkColorStatus(cd
, cd
->textFgW
) &&
5540 checkColorStatus(cd
, cd
->textBgW
) &&
5541 checkColorStatus(cd
, cd
->selectFgW
) &&
5542 checkColorStatus(cd
, cd
->selectBgW
) &&
5543 checkColorStatus(cd
, cd
->hiliteFgW
) &&
5544 checkColorStatus(cd
, cd
->hiliteBgW
) &&
5545 checkColorStatus(cd
, cd
->lineNoFgW
) &&
5546 checkColorStatus(cd
, cd
->cursorFgW
) );
5549 /* Returns True if the color is valid, False if it's not */
5550 static Boolean
checkColorStatus(colorDialog
*cd
, Widget colorFieldW
)
5555 Display
*display
= XtDisplay(cd
->shell
);
5556 char *text
= XmTextGetString(colorFieldW
);
5557 XtVaGetValues(cd
->shell
, XtNcolormap
, &cMap
, NULL
);
5558 status
= XParseColor(display
, cMap
, text
, &colorDef
);
5560 return (status
!= 0);
5563 /* Show or hide errorLabelW depending on whether or not colorFieldW
5564 contains a valid color name. */
5565 static void showColorStatus(colorDialog
*cd
, Widget colorFieldW
,
5568 /* Should set the OK/Apply button sensitivity here, instead
5569 of leaving is sensitive and then complaining if an error. */
5570 XtSetMappedWhenManaged( errorLabelW
, !checkColorStatus(cd
, colorFieldW
) );
5573 /* Update the colors in the window or in the preferences */
5574 static void updateColors(colorDialog
*cd
)
5578 char *textFg
= XmTextGetString(cd
->textFgW
),
5579 *textBg
= XmTextGetString(cd
->textBgW
),
5580 *selectFg
= XmTextGetString(cd
->selectFgW
),
5581 *selectBg
= XmTextGetString(cd
->selectBgW
),
5582 *hiliteFg
= XmTextGetString(cd
->hiliteFgW
),
5583 *hiliteBg
= XmTextGetString(cd
->hiliteBgW
),
5584 *lineNoFg
= XmTextGetString(cd
->lineNoFgW
),
5585 *cursorFg
= XmTextGetString(cd
->cursorFgW
);
5587 for (window
= WindowList
; window
!= NULL
; window
= window
->next
)
5589 SetColors(window
, textFg
, textBg
, selectFg
, selectBg
, hiliteFg
,
5590 hiliteBg
, lineNoFg
, cursorFg
);
5593 SetPrefColorName(TEXT_FG_COLOR
, textFg
);
5594 SetPrefColorName(TEXT_BG_COLOR
, textBg
);
5595 SetPrefColorName(SELECT_FG_COLOR
, selectFg
);
5596 SetPrefColorName(SELECT_BG_COLOR
, selectBg
);
5597 SetPrefColorName(HILITE_FG_COLOR
, hiliteFg
);
5598 SetPrefColorName(HILITE_BG_COLOR
, hiliteBg
);
5599 SetPrefColorName(LINENO_FG_COLOR
, lineNoFg
);
5600 SetPrefColorName(CURSOR_FG_COLOR
, cursorFg
);
5614 * Dialog button callbacks
5617 static void colorDestroyCB(Widget w
, XtPointer clientData
, XtPointer callData
)
5619 colorDialog
*cd
= (colorDialog
*)clientData
;
5621 cd
->window
->colorDialog
= NULL
;
5625 static void colorOkCB(Widget w
, XtPointer clientData
, XtPointer callData
)
5627 colorDialog
*cd
= (colorDialog
*)clientData
;
5629 if(!verifyAllColors(cd
))
5631 DialogF(DF_ERR
, w
, 1, "Invalid Colors",
5632 "All colors must be valid to proceed.", "Dismiss");
5637 /* pop down and destroy the dialog */
5638 XtDestroyWidget(cd
->shell
);
5641 static void colorApplyCB(Widget w
, XtPointer clientData
, XtPointer callData
)
5643 colorDialog
*cd
= (colorDialog
*)clientData
;
5645 if(!verifyAllColors(cd
))
5647 DialogF(DF_ERR
, w
, 1, "Invalid Colors",
5648 "All colors must be valid to be applied.", "Dismiss");
5654 static void colorDismissCB(Widget w
, XtPointer clientData
, XtPointer callData
)
5656 colorDialog
*cd
= (colorDialog
*)clientData
;
5658 /* pop down and destroy the dialog */
5659 XtDestroyWidget(cd
->shell
);
5663 /* Add a label, error label, and text entry label with a validation
5665 static Widget
addColorGroup( Widget parent
, const char *name
, char mnemonic
,
5666 char *label
, Widget
*fieldW
, Widget
*errW
, Widget topWidget
,
5667 int leftPos
, int rightPos
, XtCallbackProc modCallback
,
5673 int nameLen
= strlen(name
);
5675 /* The label widget */
5676 longerName
= XtMalloc(nameLen
+7);
5677 strcpy(longerName
, name
);
5678 strcat(longerName
, "Lbl");
5679 lblW
= XtVaCreateManagedWidget(longerName
,
5680 xmLabelGadgetClass
, parent
,
5681 XmNlabelString
, s1
=XmStringCreateSimple( label
),
5682 XmNmnemonic
, mnemonic
,
5683 XmNtopAttachment
, XmATTACH_WIDGET
,
5684 XmNtopWidget
, topWidget
,
5685 XmNtopOffset
, MARGIN_SPACING
,
5686 XmNleftAttachment
, XmATTACH_POSITION
,
5687 XmNleftPosition
, leftPos
, NULL
);
5690 /* The error label widget */
5691 strcpy(&(longerName
[nameLen
]), "ErrLbl");
5692 *errW
= XtVaCreateManagedWidget(longerName
,
5693 xmLabelWidgetClass
, parent
,
5694 XmNlabelString
, s1
=XmStringCreateSimple("(Invalid!)"),
5695 XmNalignment
, XmALIGNMENT_END
,
5696 XmNtopAttachment
, XmATTACH_WIDGET
,
5697 XmNtopWidget
, topWidget
,
5698 XmNtopOffset
, MARGIN_SPACING
,
5699 XmNleftAttachment
, XmATTACH_WIDGET
,
5700 XmNleftWidget
, lblW
,
5701 XmNrightAttachment
, XmATTACH_POSITION
,
5702 XmNrightPosition
, rightPos
, NULL
);
5705 /* The text field entry widget */
5706 *fieldW
= XtVaCreateManagedWidget(name
, xmTextWidgetClass
,
5708 XmNcolumns
, MAX_COLOR_LEN
-1,
5709 XmNmaxLength
, MAX_COLOR_LEN
-1,
5710 XmNleftAttachment
, XmATTACH_POSITION
,
5711 XmNleftPosition
, leftPos
,
5712 XmNrightAttachment
, XmATTACH_POSITION
,
5713 XmNrightPosition
, rightPos
,
5714 XmNtopAttachment
, XmATTACH_WIDGET
,
5715 XmNtopWidget
, lblW
, NULL
);
5716 RemapDeleteKey(*fieldW
);
5717 XtAddCallback(*fieldW
, XmNvalueChangedCallback
,
5719 XtVaSetValues(lblW
, XmNuserData
, *fieldW
, NULL
);
5727 * Code for the dialog itself
5729 void ChooseColors(WindowInfo
*window
, int forWindow
)
5731 Widget form
, tmpW
, topW
, infoLbl
;
5732 Widget okBtn
, applyBtn
, dismissBtn
, fillBtn
;
5738 /* if the dialog is already displayed, just pop it to the top and return */
5739 if (window
->colorDialog
!= NULL
) {
5740 RaiseShellWindow(((colorDialog
*)window
->colorDialog
)->shell
);
5744 /* Create a structure for keeping track of dialog state */
5745 cd
= XtNew(colorDialog
);
5746 window
->colorDialog
= (void*)cd
;
5748 /* Create a form widget in a dialog shell */
5750 XtSetArg(args
[ac
], XmNautoUnmanage
, False
); ac
++;
5751 XtSetArg(args
[ac
], XmNresizePolicy
, XmRESIZE_NONE
); ac
++;
5752 form
= CreateFormDialog(window
->shell
, "choose colors", args
, ac
);
5753 XtVaSetValues(form
, XmNshadowThickness
, 0, NULL
);
5754 cd
->shell
= XtParent(form
);
5755 cd
->window
= window
;
5756 XtVaSetValues(cd
->shell
, XmNtitle
, "Colors", NULL
);
5757 AddMotifCloseCallback(XtParent(form
), colorDismissCB
, cd
);
5758 XtAddCallback(form
, XmNdestroyCallback
, colorDestroyCB
, cd
);
5760 /* Information label */
5761 infoLbl
= XtVaCreateManagedWidget("infoLbl",
5762 xmLabelGadgetClass
, form
,
5763 XmNtopAttachment
, XmATTACH_POSITION
,
5765 XmNleftAttachment
, XmATTACH_POSITION
,
5767 XmNrightAttachment
, XmATTACH_POSITION
,
5768 XmNrightPosition
, 99,
5769 XmNalignment
, XmALIGNMENT_CENTER
,
5770 XmNlabelString
, s1
= XmStringCreateLtoR(
5771 "Colors can be entered as names (e.g. red, blue) or "
5772 "as RGB triples\nin the format #RRGGBB, where each digit "
5773 "is in the range 0-f.", XmFONTLIST_DEFAULT_TAG
),
5779 /* The left column (foregrounds) of color entry groups */
5780 tmpW
= addColorGroup( form
, "textFg", 'P', "Plain Text Foreground",
5781 &(cd
->textFgW
), &(cd
->textFgErrW
), topW
, 1, 49,
5782 textFgModifiedCB
, cd
);
5783 tmpW
= addColorGroup( form
, "selectFg", 'S', "Selection Foreground",
5784 &(cd
->selectFgW
), &(cd
->selectFgErrW
), tmpW
, 1, 49,
5785 selectFgModifiedCB
, cd
);
5786 tmpW
= addColorGroup( form
, "hiliteFg", 'M', "Matching (..) Foreground",
5787 &(cd
->hiliteFgW
), &(cd
->hiliteFgErrW
), tmpW
, 1, 49,
5788 hiliteFgModifiedCB
, cd
);
5789 tmpW
= addColorGroup( form
, "lineNoFg", 'L', "Line Numbers",
5790 &(cd
->lineNoFgW
), &(cd
->lineNoFgErrW
), tmpW
, 1, 49,
5791 lineNoFgModifiedCB
, cd
);
5793 /* The right column (backgrounds) */
5794 tmpW
= addColorGroup( form
, "textBg", 'T', "Text Area Background",
5795 &(cd
->textBgW
), &(cd
->textBgErrW
), topW
, 51, 99,
5796 textBgModifiedCB
, cd
);
5797 tmpW
= addColorGroup( form
, "selectBg", 'B', "Selection Background",
5798 &(cd
->selectBgW
), &(cd
->selectBgErrW
), tmpW
, 51, 99,
5799 selectBgModifiedCB
, cd
);
5800 tmpW
= addColorGroup( form
, "hiliteBg", 'h', "Matching (..) Background",
5801 &(cd
->hiliteBgW
), &(cd
->hiliteBgErrW
), tmpW
, 51, 99,
5802 hiliteBgModifiedCB
, cd
);
5803 tmpW
= addColorGroup( form
, "cursorFg", 'C', "Cursor Color",
5804 &(cd
->cursorFgW
), &(cd
->cursorFgErrW
), tmpW
, 51, 99,
5805 cursorFgModifiedCB
, cd
);
5807 tmpW
= XtVaCreateManagedWidget("infoLbl",
5808 xmLabelGadgetClass
, form
,
5809 XmNtopAttachment
, XmATTACH_WIDGET
,
5811 XmNtopOffset
, MARGIN_SPACING
,
5812 XmNleftAttachment
, XmATTACH_POSITION
,
5814 XmNrightAttachment
, XmATTACH_POSITION
,
5815 XmNrightPosition
, 99,
5816 XmNalignment
, XmALIGNMENT_CENTER
,
5817 XmNlabelString
, s1
= XmStringCreateLtoR(
5818 "NOTE: Foreground colors only apply when syntax highlighting "
5819 "is DISABLED.\n", XmFONTLIST_DEFAULT_TAG
),
5823 /* The OK, Apply, and Cancel buttons */
5824 okBtn
= XtVaCreateManagedWidget("ok", xmPushButtonWidgetClass
, form
,
5825 XmNlabelString
, s1
=XmStringCreateSimple("OK"),
5826 XmNtopAttachment
, XmATTACH_WIDGET
,
5828 /* XmNtopOffset, MARGIN_SPACING, */
5829 XmNleftAttachment
, XmATTACH_POSITION
,
5830 XmNleftPosition
, 10,
5831 XmNrightAttachment
, XmATTACH_POSITION
,
5832 XmNrightPosition
, 30,
5833 XmNbottomAttachment
, XmATTACH_POSITION
,
5834 XmNbottomPosition
, 99, NULL
);
5835 XtAddCallback(okBtn
, XmNactivateCallback
, colorOkCB
, cd
);
5838 applyBtn
= XtVaCreateManagedWidget(
5839 "apply", xmPushButtonWidgetClass
, form
,
5840 XmNlabelString
, s1
=XmStringCreateSimple("Apply"),
5841 XmNtopAttachment
, XmATTACH_WIDGET
,
5843 /* XmNtopOffset, MARGIN_SPACING, */
5845 XmNleftAttachment
, XmATTACH_POSITION
,
5846 XmNleftPosition
, 40,
5847 XmNrightAttachment
, XmATTACH_POSITION
,
5848 XmNrightPosition
, 60,
5849 XmNbottomAttachment
, XmATTACH_POSITION
,
5850 XmNbottomPosition
, 99, NULL
);
5851 XtAddCallback(applyBtn
, XmNactivateCallback
, colorApplyCB
, cd
);
5854 dismissBtn
= XtVaCreateManagedWidget(
5855 "dismiss", xmPushButtonWidgetClass
, form
,
5856 XmNlabelString
, s1
=XmStringCreateSimple("Dismiss"),
5857 XmNtopAttachment
, XmATTACH_WIDGET
,
5859 /* XmNtopOffset, MARGIN_SPACING, */
5860 XmNleftAttachment
, XmATTACH_POSITION
,
5861 XmNleftPosition
, 70,
5862 XmNrightAttachment
, XmATTACH_POSITION
,
5863 XmNrightPosition
, 90,
5864 XmNbottomAttachment
, XmATTACH_POSITION
,
5865 XmNbottomPosition
, 99, NULL
);
5866 XtAddCallback(dismissBtn
, XmNactivateCallback
, colorDismissCB
, cd
);
5869 /* Set initial default button */
5870 XtVaSetValues(form
, XmNdefaultButton
, okBtn
, NULL
);
5871 XtVaSetValues(form
, XmNcancelButton
, dismissBtn
, NULL
);
5873 /* Set initial values */
5874 XmTextSetString(cd
->textFgW
, GetPrefColorName(TEXT_FG_COLOR
));
5875 XmTextSetString(cd
->textBgW
, GetPrefColorName(TEXT_BG_COLOR
));
5876 XmTextSetString(cd
->selectFgW
, GetPrefColorName(SELECT_FG_COLOR
));
5877 XmTextSetString(cd
->selectBgW
, GetPrefColorName(SELECT_BG_COLOR
));
5878 XmTextSetString(cd
->hiliteFgW
, GetPrefColorName(HILITE_FG_COLOR
));
5879 XmTextSetString(cd
->hiliteBgW
, GetPrefColorName(HILITE_BG_COLOR
));
5880 XmTextSetString(cd
->lineNoFgW
, GetPrefColorName(LINENO_FG_COLOR
));
5881 XmTextSetString(cd
->cursorFgW
, GetPrefColorName(CURSOR_FG_COLOR
));
5883 /* Handle mnemonic selection of buttons and focus to dialog */
5884 AddDialogMnemonicHandler(form
, FALSE
);
5887 ManageDialogCenteredOnPointer(form
);