2
0

I18nMain.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $TOG: I18nMain.c /main/4 1997/08/11 12:31:36 samborn $ */
  24. /*
  25. * (c) Copyright 1996 Digital Equipment Corporation.
  26. * (c) Copyright 1996 Hewlett-Packard Company.
  27. * (c) Copyright 1996 International Business Machines Corp.
  28. * (c) Copyright 1996 Sun Microsystems, Inc.
  29. * (c) Copyright 1996 Novell, Inc.
  30. * (c) Copyright 1996 FUJITSU LIMITED.
  31. * (c) Copyright 1996 Hitachi.
  32. */
  33. /************************************<+>*************************************
  34. ****************************************************************************
  35. **
  36. ** File: I18nMain.c
  37. **
  38. ** Description: Controls the Dtstyle I18N customization dialog
  39. **
  40. **
  41. ****************************************************************************
  42. ************************************<+>*************************************/
  43. /*+++++++++++++++++++++++++++++++++++++++*/
  44. /* include files */
  45. /*+++++++++++++++++++++++++++++++++++++++*/
  46. #include <X11/Xlib.h>
  47. #include <errno.h>
  48. #include <Xm/MwmUtil.h>
  49. #include <Xm/XmP.h>
  50. #include <Xm/Xm.h>
  51. #include <Xm/Form.h>
  52. #include <Xm/LabelG.h>
  53. #include <Xm/PushBG.h>
  54. #include <Xm/RowColumn.h>
  55. #include <Xm/ToggleBG.h>
  56. #include <Xm/SeparatoG.h>
  57. #include <Xm/VendorSEP.h>
  58. #include <Xm/MessageB.h>
  59. #include <Dt/DialogBox.h>
  60. #include <Dt/Icon.h>
  61. #include <Dt/TitleBox.h>
  62. #include <Dt/UserMsg.h>
  63. #include <Dt/Message.h>
  64. #include <Dt/HourGlass.h>
  65. #include <Dt/Wsm.h>
  66. #include "Help.h"
  67. #include "Main.h"
  68. #include "SaveRestore.h"
  69. #include "Protocol.h"
  70. #include <ctype.h>
  71. /*+++++++++++++++++++++++++++++++++++++++*/
  72. /* include extern functions */
  73. /*+++++++++++++++++++++++++++++++++++++++*/
  74. #include "I18nMain.h"
  75. #include "I18nEnv.h"
  76. /*+++++++++++++++++++++++++++++++++++++++*/
  77. /* Local #defines */
  78. /*+++++++++++++++++++++++++++++++++++++++*/
  79. #define MSG_IMMEDIATE ((char *)GETMESSAGE(19, 20, "The new XmNpreeditType value will take effect\nas applications are restarted."))
  80. #define MSG_LATER ((char *)GETMESSAGE(19, 21, "Your selection will take effect\n at your next session."))
  81. /*+++++++++++++++++++++++++++++++++++++++*/
  82. /* Internal Functions */
  83. /*+++++++++++++++++++++++++++++++++++++++*/
  84. static int InitI18nValues(Widget shell);
  85. static void SetImServerHosts(I18nEnv *env);
  86. static void SetImsToggleList(I18nEnv *env);
  87. static void SetImsMode(I18nEnv *env);
  88. static void SetPreeditType(I18nEnv *env, XmStringTable preeditTable,
  89. int preeditTableNum);
  90. static Widget BuildI18nDlg(Widget shell);
  91. static void FormLayoutCB(Widget w, XtPointer client_data, XtPointer call_data);
  92. static void MapCB(Widget w, XtPointer client_data, XtPointer call_data);
  93. static void SystemDefaultCB(Widget w, XtPointer client_data,
  94. XtPointer call_data);
  95. static void ServerHostCB(Widget w, XtPointer client_data, XtPointer call_data);
  96. static void UpdateImList(I18nEnv *env, char *hostname);
  97. static void TextFocusCB(Widget w, XtPointer client_data, XtPointer call_data);
  98. static void TextLosingFocusCB(Widget w, XtPointer client_data,
  99. XtPointer call_data);
  100. static void ButtonCB(Widget w, XtPointer client_data, XtPointer call_data);
  101. static int SaveSelectedValues(I18nEnv *env);
  102. static void SetFileSelValues(I18nEnv *env);
  103. static void ResetLastSavedValues(I18nEnv *env);
  104. static void OkWarnCB(Widget w, XtPointer client_data, XtPointer call_data);
  105. static void CancelWarnCB(Widget w, XtPointer client_data, XtPointer call_data);
  106. static void ListItemSelectCB(Widget w, XtPointer client_data,
  107. XtPointer call_data);
  108. static void MoveUpCB(Widget w, XtPointer client_data, XtPointer call_data);
  109. static void MoveDownCB(Widget w, XtPointer client_data, XtPointer call_data);
  110. static XmStringTable CopyST (XmStringTable st, int nst);
  111. static void FreeST (XmStringTable st, int nst);
  112. /*+++++++++++++++++++++++++++++++++++++++*/
  113. /* Internal Variables */
  114. /*+++++++++++++++++++++++++++++++++++++++*/
  115. typedef struct {
  116. Widget pictLabel;
  117. Widget systemDefault;
  118. Widget inputMethodTB;
  119. Widget serverHostLabel;
  120. Widget serverHostCB;
  121. Widget inputMethodLabel;
  122. Widget inputMethodRC;
  123. Widget imStartModeTB;
  124. Widget imStartModeRC;
  125. Widget askAtLoginTG;
  126. Widget resumeCurrentImTG;
  127. Widget preeditTypeTB;
  128. Widget preeditTypeList;
  129. int preeditTypeListLastPos;
  130. Boolean preeditHasChanged;
  131. XmStringTable preeditSavedVal;
  132. int preeditSavedNum;
  133. Widget buttonMoveUp;
  134. Widget buttonMoveDown;
  135. Widget warnDialog;
  136. Widget defaultButton;
  137. } I18n, *I18nPtr;
  138. static I18n i18n;
  139. static saveRestore save = {FALSE, 0, };
  140. static char i18nRes[150]="";
  141. static char *defaultPreedit[] =
  142. { "OnTheSpot",
  143. "OverTheSpot",
  144. "OffTheSpot",
  145. "Root"
  146. };
  147. #define NUM_PREEDIT 4
  148. /*+++++++++++++++++++++++++++++++++++++++*/
  149. /* popup_i18nBB */
  150. /*+++++++++++++++++++++++++++++++++++++++*/
  151. void
  152. popup_i18nBB(
  153. Widget shell )
  154. {
  155. int ret = NoError;
  156. if (style.i18nDialog == NULL) {
  157. _DtTurnOnHourGlass(shell);
  158. BuildI18nDlg(shell);
  159. ret = InitI18nValues(shell);
  160. XtManageChild(style.i18nDialog);
  161. if (ret != NoError)
  162. _DtI18nErrorDialog(ret) ;
  163. _DtTurnOffHourGlass(shell);
  164. }
  165. else
  166. {
  167. XtManageChild(style.i18nDialog);
  168. raiseWindow(XtWindow(XtParent(style.i18nDialog)));
  169. }
  170. }
  171. /*+++++++++++++++++++++++++++++++++++++++*/
  172. /* InitI18nValues */
  173. /*+++++++++++++++++++++++++++++++++++++++*/
  174. static int
  175. InitI18nValues(Widget shell)
  176. {
  177. I18nEnv *env;
  178. int ret = NoError;
  179. int num_preedit = 0;
  180. XmString *str = style.xrdb.preeditType;
  181. /* Initialize */
  182. env = &i18n_env;
  183. env->shell = shell;
  184. /* Get all the needed values from the environment. */
  185. if ((ret = _DtI18nGetEnvValues(env)) == NoError) {
  186. /* Update the display with the values */
  187. SetImServerHosts(env);
  188. SetImsMode(env);
  189. }
  190. /* Get the preeditType resource value */
  191. while (str[num_preedit]) num_preedit++;
  192. SetPreeditType(env, style.xrdb.preeditType, num_preedit);
  193. i18n.preeditHasChanged = False;
  194. /* Save the initial value in case of a reset. */
  195. i18n.preeditSavedVal = style.xrdb.preeditType;
  196. i18n.preeditSavedNum = num_preedit;
  197. return ret ;
  198. }
  199. static void
  200. SetImServerHosts(I18nEnv *env)
  201. {
  202. Cardinal num_hosts = 0 ;
  203. /* Set the TextField of the ComboBox with the value found in
  204. the IMS selection file */
  205. XtVaSetValues(XtNameToWidget(i18n.serverHostCB,"Text"),
  206. XmNvalue, env->file_sel->hostname, NULL);
  207. /* update ComboBox with list of server hostnames found in
  208. "imServerHosts" resource */
  209. if (style.xrdb.imServerHosts)
  210. while (style.xrdb.imServerHosts[num_hosts]) num_hosts ++ ;
  211. /* TBD: need to add file_sel->hostname if not null
  212. or localhost, if not already present */
  213. XtVaSetValues(i18n.serverHostCB,
  214. XmNitemCount, num_hosts,
  215. XmNitems, style.xrdb.imServerHosts, NULL);
  216. }
  217. static void
  218. SetImsToggleList(I18nEnv *env)
  219. {
  220. Cardinal n,i;
  221. XmString string;
  222. Widget *im_tog = NULL;
  223. Arg args[5];
  224. Boolean found = FALSE;
  225. Cardinal default_index = 0;
  226. /* create new toggles */
  227. if (env->ims_sel->ims_list_size > 0)
  228. im_tog = (Widget*)XtMalloc(sizeof(Widget)
  229. * env->ims_sel->ims_list_size);
  230. for (i=0; i< env->ims_sel->ims_list_size; i++) {
  231. string = XmStringCreateLocalized(env->ims_sel->ims_list[i].im_label);
  232. n = 0;
  233. XtSetArg(args[n], XmNlabelString, string); n++;
  234. XtSetArg(args[n], XmNsensitive,
  235. !(env->ims_sel->ims_list[i].inactive)); n++;
  236. XtSetArg(args[n], XmNuserData,
  237. env->ims_sel->ims_list[i].im_name); n++;
  238. /* Need to default to the file_sel->im_name, if in the list */
  239. if (strcmp(env->file_sel->im_name,
  240. env->ims_sel->ims_list[i].im_name) == 0) {
  241. found = TRUE;
  242. XtSetArg(args[n], XmNset, True); n++;
  243. }
  244. if (env->ims_sel->ims_list[i].im_default) {
  245. default_index = i;
  246. }
  247. im_tog[i] = XmCreateToggleButtonGadget(i18n.inputMethodRC,
  248. "IM", args, n);
  249. XmStringFree(string);
  250. }
  251. if (env->ims_sel->ims_list_size > 0)
  252. XtManageChildren(im_tog, env->ims_sel->ims_list_size);
  253. /* If we provided toggle buttons, but the file_sel->im_name was not
  254. found, default it to the default from the locale file. */
  255. if (im_tog && !found) {
  256. n = 0;
  257. XtSetArg(args[n], XmNset, True); n++;
  258. XtSetValues(im_tog[default_index], args, n);
  259. }
  260. if (im_tog)
  261. XtFree((char *) im_tog);
  262. _DtTurnOffHourGlass(i18n.inputMethodTB);
  263. }
  264. static void
  265. SetImsMode(I18nEnv *env)
  266. {
  267. /* only called once at startup, or when resetting the saved values */
  268. if (env->file_sel->start_mode == 0)
  269. XmToggleButtonGadgetSetState(i18n.askAtLoginTG, True, True);
  270. else
  271. XmToggleButtonGadgetSetState(i18n.resumeCurrentImTG, True, True);
  272. }
  273. static void
  274. SetPreeditType(
  275. I18nEnv *env,
  276. XmStringTable preeditTable,
  277. int preeditTableNum)
  278. {
  279. XmStringTable loc_preeditTable ;
  280. loc_preeditTable = CopyST(preeditTable, preeditTableNum);
  281. /* initialize List with preeditType values */
  282. XtVaSetValues(i18n.preeditTypeList,
  283. XmNvisibleItemCount, preeditTableNum,
  284. XmNitemCount, preeditTableNum,
  285. XmNitems, loc_preeditTable,
  286. XmNselectedItemCount, 1,
  287. XmNselectedItems, loc_preeditTable, NULL);
  288. /* set the last item position - This is the number of items in the list. */
  289. i18n.preeditTypeListLastPos = preeditTableNum;
  290. /* If more than one item in the list, set the Button MoveDown sentivity to
  291. True. */
  292. if (preeditTableNum > 1)
  293. XtVaSetValues(i18n.buttonMoveDown, XmNsensitive, True, NULL);
  294. XtVaSetValues(i18n.buttonMoveUp, XmNsensitive, False, NULL);
  295. }
  296. /*+++++++++++++++++++++++++++++++++++++++*/
  297. /* build__i18nDlg */
  298. /*+++++++++++++++++++++++++++++++++++++++*/
  299. static Widget
  300. BuildI18nDlg(
  301. Widget shell )
  302. {
  303. int i, n;
  304. Arg args[MAX_ARGS];
  305. XmString button_string[NUM_LABELS];
  306. XmString string;
  307. Widget form;
  308. Widget inputMethodForm;
  309. Widget imStartModeForm;
  310. Widget preeditTypeForm;
  311. int count = 0;
  312. Widget widgetList1[6];
  313. /* get i18n resource values */
  314. /* Set up DialogBoxDialog button labels */
  315. button_string[0] = CMPSTR((String) _DtOkString);
  316. button_string[1] = CMPSTR((String) _DtCancelString);
  317. button_string[2] = CMPSTR((String) _DtHelpString);
  318. /* Create toplevel DialogBox */
  319. /* Initialize the i18n structure */
  320. i18n.pictLabel = NULL;
  321. i18n.systemDefault = NULL;
  322. i18n.inputMethodTB = NULL;
  323. i18n.serverHostLabel = NULL;
  324. i18n.serverHostCB = NULL;
  325. i18n.inputMethodLabel = NULL;
  326. i18n.inputMethodRC = NULL;
  327. i18n.imStartModeTB = NULL;
  328. i18n.imStartModeRC = NULL;
  329. i18n.askAtLoginTG = NULL;
  330. i18n.resumeCurrentImTG = NULL;
  331. i18n.preeditTypeTB = NULL;
  332. i18n.preeditTypeList = NULL;
  333. i18n.buttonMoveUp = NULL;
  334. i18n.buttonMoveDown = NULL;
  335. i18n.warnDialog = NULL;
  336. /* saveRestore
  337. * Note that save.poscnt has been initialized elsewhere.
  338. * save.posArgs may contain information from restoreBeep().*/
  339. XtSetArg(save.posArgs[save.poscnt], XmNbuttonCount, NUM_LABELS);
  340. save.poscnt++;
  341. XtSetArg(save.posArgs[save.poscnt], XmNbuttonLabelStrings, button_string);
  342. save.poscnt++;
  343. XtSetArg(save.posArgs[save.poscnt], XmNdefaultPosition, False);
  344. save.poscnt++;
  345. style.i18nDialog =
  346. __DtCreateDialogBoxDialog(shell, "i18nDialog", save.posArgs,
  347. save.poscnt);
  348. XtAddCallback(style.i18nDialog, XmNhelpCallback,
  349. (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_I18N_DIALOG);
  350. XmStringFree(button_string[0]);
  351. XmStringFree(button_string[1]);
  352. XmStringFree(button_string[2]);
  353. widgetList1[0] = _DtDialogBoxGetButton(style.i18nDialog,2);
  354. n=0;
  355. XtSetArg(args[n], XmNautoUnmanage, False); n++;
  356. XtSetArg(args[n], XmNcancelButton, widgetList1[0]); n++;
  357. XtSetValues (style.i18nDialog, args, n);
  358. n=0;
  359. XtSetArg(args[n], XmNtitle,
  360. ((char *)GETMESSAGE(19, 1, "Style Manager - Internationalization")));
  361. n++;
  362. XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
  363. XtSetArg(args[n], XmNmwmFunctions, DIALOG_MWM_FUNC); n++;
  364. XtSetValues (XtParent(style.i18nDialog), args, n);
  365. n = 0;
  366. XtSetArg(args[n], XmNallowOverlap, False); n++;
  367. XtSetArg(args[n], XmNchildType, XmWORK_AREA); n++;
  368. form = XmCreateForm(style.i18nDialog, "i18nForm", args, n);
  369. n = 0;
  370. XtSetArg(args[n], XmNfillMode, XmFILL_SELF); n++;
  371. XtSetArg(args[n], XmNbehavior, XmICON_LABEL); n++;
  372. XtSetArg(args[n], XmNpixmapForeground, style.secBSCol); n++;
  373. XtSetArg(args[n], XmNpixmapBackground, style.secTSCol); n++;
  374. XtSetArg(args[n], XmNstring, NULL); n++;
  375. XtSetArg(args[n], XmNshadowThickness, 0); n++;
  376. XtSetArg(args[n], XmNimageName, I18N_ICON); n++;
  377. XtSetArg(args[n], XmNtraversalOn, False); n++;
  378. widgetList1[count++] = i18n.pictLabel =
  379. _DtCreateIcon(form, "i18npictLabel", args, n);
  380. n = 0;
  381. XtSetArg(args[n], XmNmarginHeight, LB_MARGIN_HEIGHT); n++;
  382. XtSetArg(args[n], XmNmarginWidth, LB_MARGIN_WIDTH); n++;
  383. string = CMPSTR(((char *)GETMESSAGE(19, 2, "Default")));
  384. XtSetArg(args[n], XmNlabelString, string); n++;
  385. widgetList1[count++] = i18n.systemDefault =
  386. XmCreatePushButtonGadget(form, "systemDefault", args, n);
  387. XmStringFree(string);
  388. n = 0;
  389. string = CMPSTR((char *)GETMESSAGE(19, 3, "Input Method"));
  390. XtSetArg(args[n], XmNtitleString, string); n++;
  391. widgetList1[count++] = i18n.inputMethodTB =
  392. _DtCreateTitleBox(form, "inputMethodTB", args, n);
  393. XmStringFree(string);
  394. n = 0;
  395. XtSetArg(args[n], XmNallowOverlap, False); n++;
  396. XtSetArg(args[n], XmNchildType, XmWORK_AREA); n++;
  397. inputMethodForm =
  398. XmCreateForm(i18n.inputMethodTB, "inputMethodForm", args, n);
  399. n = 0;
  400. string = CMPSTR((char *)GETMESSAGE(19, 4, "Input Method Start Mode"));
  401. XtSetArg(args[n], XmNtitleString, string); n++;
  402. widgetList1[count++] = i18n.imStartModeTB =
  403. _DtCreateTitleBox(form, "imStartModeTB", args, n);
  404. XmStringFree(string);
  405. n = 0;
  406. XtSetArg(args[n], XmNallowOverlap, False); n++;
  407. XtSetArg(args[n], XmNchildType, XmWORK_AREA); n++;
  408. imStartModeForm =
  409. XmCreateForm(i18n.imStartModeTB, "imStartModeForm", args, n);
  410. n = 0;
  411. string = CMPSTR((char *)GETMESSAGE(19, 5, "Preedit Type"));
  412. XtSetArg(args[n], XmNtitleString, string); n++;
  413. widgetList1[count++] = i18n.preeditTypeTB =
  414. _DtCreateTitleBox(form, "preeditTypeTB", args, n);
  415. XmStringFree(string);
  416. n = 0;
  417. XtSetArg(args[n], XmNallowOverlap, False); n++;
  418. XtSetArg(args[n], XmNchildType, XmWORK_AREA); n++;
  419. preeditTypeForm =
  420. XmCreateForm(i18n.preeditTypeTB, "preeditTypeForm", args, n);
  421. /* Create widgets inside the inputMethodForm */
  422. n = 0;
  423. string = CMPSTR((char *)GETMESSAGE(19, 6, "Server Host :"));
  424. XtSetArg(args[n], XmNlabelString, string); n++;
  425. i18n.serverHostLabel =
  426. XmCreateLabelGadget(inputMethodForm, "serverHostLabel", args, n);
  427. n = 0;
  428. XtSetArg(args[n], XmNcomboBoxType, XmDROP_DOWN_COMBO_BOX); n++;
  429. i18n.serverHostCB =
  430. (Widget) (intptr_t) XmCreateComboBox(inputMethodForm, "serverHostCB", args, n);
  431. XtAddCallback(XtNameToWidget(i18n.serverHostCB, "Text"),
  432. XmNactivateCallback, ServerHostCB, NULL);
  433. XtAddCallback(XtNameToWidget(i18n.serverHostCB, "Text"),
  434. XmNfocusCallback, TextFocusCB, NULL);
  435. XtAddCallback(XtNameToWidget(i18n.serverHostCB, "Text"),
  436. XmNlosingFocusCallback, TextLosingFocusCB, NULL);
  437. n = 0;
  438. string = CMPSTR((char *)GETMESSAGE(19, 7, "Input Method"));
  439. XtSetArg(args[n], XmNlabelString, string); n++;
  440. i18n.inputMethodLabel =
  441. XmCreateLabelGadget(inputMethodForm, "inputMethodLabel", args, n);
  442. n = 0;
  443. XtSetArg(args[n], XmNmarginWidth, LB_MARGIN_WIDTH); n++;
  444. XtSetArg(args[n], XmNmarginHeight, LB_MARGIN_HEIGHT); n++;
  445. i18n.inputMethodRC =
  446. XmCreateRadioBox(inputMethodForm, "inputMethodRC", args, n);
  447. /* Create widgets inside the imStartModeForm */
  448. n = 0;
  449. XtSetArg(args[n], XmNmarginWidth, 0); n++;
  450. XtSetArg(args[n], XmNmarginHeight, 0); n++;
  451. i18n.imStartModeRC =
  452. XmCreateRadioBox(imStartModeForm, "imStartModeRC", args, n);
  453. n = 0;
  454. string = CMPSTR((char *)GETMESSAGE(19, 8, "Ask at login"));
  455. XtSetArg(args[n], XmNlabelString, string); n++;
  456. i18n.askAtLoginTG =
  457. XmCreateToggleButtonGadget(i18n.imStartModeRC, "askAtLoginTG",
  458. args, n);
  459. XmStringFree(string);
  460. n = 0;
  461. string = CMPSTR((char *)GETMESSAGE(19, 9, "Resume Current Input Method"));
  462. XtSetArg(args[n], XmNlabelString, string); n++;
  463. i18n.resumeCurrentImTG =
  464. XmCreateToggleButtonGadget(i18n.imStartModeRC, "resumeCurrentImTG",
  465. args, n);
  466. XmStringFree(string);
  467. /* Create widgets inside the preeditTypeForm */
  468. n = 0;
  469. XtSetArg(args[n], XmNselectionPolicy, XmBROWSE_SELECT); n++;
  470. i18n.preeditTypeList =
  471. (Widget) (intptr_t) XmCreateList(preeditTypeForm, "preeditTypeList", args, n);
  472. n = 0;
  473. string = CMPSTR((char *)GETMESSAGE(19, 10, "Move Up"));
  474. XtSetArg(args[n], XmNlabelString, string); n++;
  475. XtSetArg(args[n], XmNsensitive, False); n++;
  476. i18n.buttonMoveUp =
  477. XmCreatePushButtonGadget(preeditTypeForm, "buttonMoveUp", args, n);
  478. XmStringFree(string);
  479. n = 0;
  480. string = CMPSTR((char *)GETMESSAGE(19, 11, "Move Down"));
  481. XtSetArg(args[n], XmNlabelString, string); n++;
  482. XtSetArg(args[n], XmNsensitive, False); n++;
  483. i18n.buttonMoveDown =
  484. XmCreatePushButtonGadget(preeditTypeForm, "buttonMoveDown", args, n);
  485. XmStringFree(string);
  486. XtAddCallback(style.i18nDialog, XmNmapCallback, FormLayoutCB, NULL);
  487. XtAddCallback(style.i18nDialog, XmNmapCallback, MapCB, shell);
  488. XtAddCallback(style.i18nDialog, XmNcallback, ButtonCB, NULL);
  489. XtAddCallback(i18n.systemDefault, XmNactivateCallback,
  490. SystemDefaultCB, NULL);
  491. XtAddCallback(i18n.preeditTypeList, XmNbrowseSelectionCallback,
  492. ListItemSelectCB, NULL);
  493. XtAddCallback(i18n.buttonMoveUp, XmNactivateCallback,
  494. MoveUpCB, NULL);
  495. XtAddCallback(i18n.buttonMoveDown, XmNactivateCallback,
  496. MoveDownCB, NULL);
  497. XtManageChild(form);
  498. XtManageChildren(widgetList1,count);
  499. XtManageChild(inputMethodForm);
  500. XtManageChild(imStartModeForm);
  501. XtManageChild(preeditTypeForm);
  502. XtManageChild(i18n.serverHostLabel);
  503. XtManageChild(i18n.serverHostCB);
  504. XtManageChild(i18n.inputMethodLabel);
  505. XtManageChild(i18n.inputMethodRC);
  506. XtManageChild(i18n.imStartModeRC);
  507. XtManageChild(i18n.askAtLoginTG);
  508. XtManageChild(i18n.resumeCurrentImTG);
  509. XtManageChild(i18n.preeditTypeList);
  510. XtManageChild(i18n.buttonMoveUp);
  511. XtManageChild(i18n.buttonMoveDown);
  512. return(style.i18nDialog);
  513. }
  514. /*+++++++++++++++++++++++++++++++++++++++*/
  515. /* FormLayoutCB */
  516. /*+++++++++++++++++++++++++++++++++++++++*/
  517. static void
  518. FormLayoutCB(
  519. Widget w,
  520. XtPointer client_data,
  521. XtPointer call_data )
  522. {
  523. int n;
  524. Arg args[MAX_ARGS];
  525. /* Picture Label */
  526. n=0;
  527. XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  528. XtSetArg(args[n], XmNtopOffset, style.verticalSpacing); n++;
  529. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  530. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  531. XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
  532. XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
  533. XtSetValues (i18n.pictLabel, args, n);
  534. /* system Default */
  535. n=0;
  536. XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  537. XtSetArg(args[n], XmNtopOffset, style.verticalSpacing); n++;
  538. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  539. XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
  540. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  541. XtSetArg(args[n], XmNrightOffset, style.horizontalSpacing); n++;
  542. XtSetValues (i18n.systemDefault, args, n);
  543. /* Input Method TitleBox */
  544. n=0;
  545. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  546. XtSetArg(args[n], XmNtopWidget, i18n.pictLabel); n++;
  547. XtSetArg(args[n], XmNtopOffset, style.horizontalSpacing); n++;
  548. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  549. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  550. XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
  551. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  552. XtSetArg(args[n], XmNrightOffset, style.horizontalSpacing); n++;
  553. XtSetValues (i18n.inputMethodTB, args, n);
  554. /* Input Method widgets */
  555. n = 0;
  556. XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  557. XtSetArg(args[n], XmNtopOffset, 2*style.verticalSpacing); n++;
  558. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  559. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  560. XtSetArg(args[n], XmNleftOffset, 0); n++;
  561. XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
  562. XtSetValues (i18n.serverHostLabel, args, n);
  563. n = 0;
  564. XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  565. XtSetArg(args[n], XmNtopOffset, style.verticalSpacing); n++;
  566. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  567. XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  568. XtSetArg(args[n], XmNleftWidget, i18n.serverHostLabel); n++;
  569. XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
  570. XtSetValues (i18n.serverHostCB, args, n);
  571. n = 0;
  572. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  573. XtSetArg(args[n], XmNtopWidget, i18n.serverHostCB); n++;
  574. XtSetArg(args[n], XmNtopOffset, style.verticalSpacing); n++;
  575. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  576. XtSetArg(args[n], XmNleftOffset, 0); n++;
  577. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  578. XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
  579. XtSetValues (i18n.inputMethodLabel, args, n);
  580. n = 0;
  581. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  582. XtSetArg(args[n], XmNtopWidget, i18n.inputMethodLabel); n++;
  583. XtSetArg(args[n], XmNtopOffset, style.verticalSpacing); n++;
  584. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  585. XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
  586. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  587. XtSetArg(args[n], XmNbottomOffset, style.verticalSpacing); n++;
  588. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  589. XtSetArg(args[n], XmNrightOffset, style.horizontalSpacing); n++;
  590. XtSetValues (i18n.inputMethodRC, args, n);
  591. /* Input Method Start Mode TitleBox */
  592. n=0;
  593. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  594. XtSetArg(args[n], XmNtopWidget, i18n.inputMethodTB); n++;
  595. XtSetArg(args[n], XmNtopOffset, style.verticalSpacing); n++;
  596. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  597. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  598. XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
  599. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  600. XtSetArg(args[n], XmNrightOffset, style.horizontalSpacing); n++;
  601. XtSetValues (i18n.imStartModeTB, args, n);
  602. /* IM Start Mode RC */
  603. n=0;
  604. XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  605. XtSetArg(args[n], XmNtopOffset, style.verticalSpacing); n++;
  606. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  607. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  608. XtSetArg(args[n], XmNleftOffset, 0); n++;
  609. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  610. XtSetArg(args[n], XmNrightOffset, 0); n++;
  611. XtSetValues (i18n.imStartModeRC, args, n);
  612. /* Preedit Type TitleBox */
  613. n=0;
  614. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  615. XtSetArg(args[n], XmNtopWidget, i18n.imStartModeTB); n++;
  616. XtSetArg(args[n], XmNtopOffset, style.verticalSpacing); n++;
  617. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  618. XtSetArg(args[n], XmNbottomOffset, style.verticalSpacing); n++;
  619. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  620. XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
  621. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  622. XtSetArg(args[n], XmNrightOffset, style.horizontalSpacing); n++;
  623. XtSetValues (i18n.preeditTypeTB, args, n);
  624. /* Preedit Type widgets */
  625. n = 0;
  626. XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  627. XtSetArg(args[n], XmNtopOffset, style.verticalSpacing); n++;
  628. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  629. XtSetArg(args[n], XmNbottomOffset, style.verticalSpacing); n++;
  630. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  631. XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
  632. XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
  633. XtSetValues (i18n.preeditTypeList, args, n);
  634. n = 0;
  635. XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  636. XtSetArg(args[n], XmNtopOffset, 2*style.verticalSpacing); n++;
  637. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  638. XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  639. XtSetArg(args[n], XmNleftWidget, i18n.preeditTypeList); n++;
  640. XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
  641. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  642. XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
  643. XtSetValues (i18n.buttonMoveUp, args, n);
  644. n = 0;
  645. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  646. XtSetArg(args[n], XmNtopWidget, i18n.buttonMoveUp); n++;
  647. XtSetArg(args[n], XmNtopOffset, style.verticalSpacing); n++;
  648. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  649. XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  650. XtSetArg(args[n], XmNleftWidget, i18n.preeditTypeList); n++;
  651. XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
  652. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  653. XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
  654. XtSetValues (i18n.buttonMoveDown, args, n);
  655. XtRemoveCallback(style.i18nDialog, XmNmapCallback, FormLayoutCB, NULL);
  656. }
  657. /*+++++++++++++++++++++++++++++++++++++++*/
  658. /* MapCB */
  659. /*+++++++++++++++++++++++++++++++++++++++*/
  660. static void
  661. MapCB(
  662. Widget w,
  663. XtPointer client_data,
  664. XtPointer call_data )
  665. {
  666. static int first_time = 1;
  667. int n;
  668. Arg args[MAX_ARGS];
  669. DtWsmRemoveWorkspaceFunctions(style.display, XtWindow(XtParent(w)));
  670. if (!save.restoreFlag)
  671. putDialog ((Widget)client_data, w);
  672. XtRemoveCallback(style.i18nDialog, XmNmapCallback, MapCB, NULL);
  673. }
  674. /*+++++++++++++++++++++++++++++++++++++++*/
  675. /* ServerHostCB - get the new hostname, */
  676. /* query its list of im and update the */
  677. /* radio box. */
  678. /*+++++++++++++++++++++++++++++++++++++++*/
  679. static void
  680. ServerHostCB(
  681. Widget w,
  682. XtPointer client_data,
  683. XtPointer call_data )
  684. {
  685. char *hostname;
  686. _DtTurnOnHourGlass(i18n.inputMethodTB);
  687. /* Get the current hostname in the TextField of the ComboBox,
  688. as string */
  689. XtVaGetValues(XtNameToWidget(i18n.serverHostCB,"Text"),
  690. XmNvalue, &hostname, NULL);
  691. /* Update the display and query for new IM on this host. */
  692. UpdateImList(&i18n_env, hostname);
  693. }
  694. static void
  695. UpdateImList(
  696. I18nEnv *env,
  697. char *hostname)
  698. {
  699. Cardinal i;
  700. XtArgVal n;
  701. Widget *im_tog = NULL;
  702. int ret = NoError;
  703. /* Clean first the existing list */
  704. /* destroy toggle in radio box is any */
  705. XtVaGetValues(i18n.inputMethodRC, XmNchildren, &im_tog,
  706. XmNnumChildren, &n, NULL);
  707. if (n) {
  708. XtUnmanageChildren(im_tog, n);
  709. for (i=0; i<n; i++) XtDestroyWidget(im_tog[i]);
  710. im_tog = NULL;
  711. }
  712. /* Empty what we used to have here */
  713. if (env->ims_sel->ims_list_size) {
  714. XtFree((char *) env->ims_sel->ims_list);
  715. env->ims_sel->ims_list = NULL;
  716. env->ims_sel->ims_list_size = 0 ;
  717. }
  718. /* then update the env struct with new ims name and status */
  719. ret = _DtI18nGetImList(env, hostname);
  720. if (ret != NoError) {
  721. _DtTurnOffHourGlass(i18n.inputMethodTB);
  722. _DtI18nErrorDialog(ret);
  723. }
  724. }
  725. /*+++++++++++++++++++++++++++++++++++++++*/
  726. /* SystemDefaultCB */
  727. /*+++++++++++++++++++++++++++++++++++++++*/
  728. static void
  729. SystemDefaultCB(
  730. Widget w,
  731. XtPointer client_data,
  732. XtPointer call_data )
  733. {
  734. static XmStringTable preeditTable = NULL ;
  735. Cardinal i;
  736. I18nEnv *env;
  737. env = &i18n_env;
  738. /* Set the Server Host to local, that is use the NULL string */
  739. XtVaSetValues(XtNameToWidget(i18n.serverHostCB,"Text"),
  740. XmNvalue, "local", NULL);
  741. UpdateImList(env, "local");
  742. /* Set the Input Method Start Mode to Ask at login */
  743. XmToggleButtonGadgetSetState(i18n.askAtLoginTG, True, True);
  744. if (!preeditTable) {
  745. /* Set the preeditType list to the default in Motif */
  746. preeditTable = (XmStringTable) XtMalloc(NUM_PREEDIT *
  747. sizeof( XmString ));
  748. for ( i = 0; i < NUM_PREEDIT; i ++ )
  749. preeditTable[i] = XmStringCreate(defaultPreedit[i],
  750. "ISO8859-1");
  751. }
  752. SetPreeditType(env, preeditTable, NUM_PREEDIT);
  753. /* Mark that the preeditType list has changed. */
  754. i18n.preeditHasChanged = True;
  755. return;
  756. }
  757. /*+++++++++++++++++++++++++++++++++++++++*/
  758. /* TextFocusCB - disable the default */
  759. /* button in the dialog, so that return */
  760. /* in the TextField doesn't activate it. */
  761. /*+++++++++++++++++++++++++++++++++++++++*/
  762. static void
  763. TextFocusCB(
  764. Widget w,
  765. XtPointer client_data,
  766. XtPointer call_data )
  767. {
  768. XtVaGetValues(style.i18nDialog, XmNdefaultButton, &i18n.defaultButton,
  769. NULL);
  770. XtVaSetValues(style.i18nDialog, XmNdefaultButton, NULL, NULL);
  771. return;
  772. }
  773. /*+++++++++++++++++++++++++++++++++++++++*/
  774. /* TextLosingFocusCB - enable the */
  775. /* default button, so that return key in */
  776. /* the dialog activate it. */
  777. /*+++++++++++++++++++++++++++++++++++++++*/
  778. static void
  779. TextLosingFocusCB(
  780. Widget w,
  781. XtPointer client_data,
  782. XtPointer call_data )
  783. {
  784. XtVaSetValues(style.i18nDialog, XmNdefaultButton, i18n.defaultButton,
  785. NULL);
  786. return;
  787. }
  788. /*+++++++++++++++++++++++++++++++++++++++*/
  789. /* ButtonCB */
  790. /* callback for PushButtons in DialogBox */
  791. /*+++++++++++++++++++++++++++++++++++++++*/
  792. static void
  793. ButtonCB(
  794. Widget w,
  795. XtPointer client_data,
  796. XtPointer call_data )
  797. {
  798. int n;
  799. int ret = NoError;
  800. I18nEnv *env;
  801. DtDialogBoxCallbackStruct *cb = (DtDialogBoxCallbackStruct *) call_data;
  802. env = &i18n_env;
  803. switch (cb->button_position)
  804. {
  805. case OK_BUTTON:
  806. ret = SaveSelectedValues(env);
  807. XtUnmanageChild (w);
  808. break;
  809. case CANCEL_BUTTON:
  810. XtUnmanageChild(w);
  811. /* reset the i18n values from last saved values */
  812. ResetLastSavedValues(env);
  813. if (i18n.preeditHasChanged) {
  814. /* Reset the preeditType value from the saved one. */
  815. SetPreeditType(env, i18n.preeditSavedVal, i18n.preeditSavedNum);
  816. i18n.preeditHasChanged = False;
  817. }
  818. break;
  819. case HELP_BUTTON:
  820. XtCallCallbacks(style.i18nDialog, XmNhelpCallback, (XtPointer)NULL);
  821. break;
  822. default:
  823. break;
  824. }
  825. }
  826. static int
  827. SaveSelectedValues(
  828. I18nEnv *env)
  829. {
  830. int ret = NoError;
  831. char *preeditStr = NULL, *tmpStr;
  832. int i;
  833. XtArgVal num_preedit = 0;
  834. XmStringTable list_preedit;
  835. static char preeditTypeRes[1024];
  836. /* Get the values from the UI and update the FileSel structure */
  837. SetFileSelValues(env);
  838. /* Write these values in the IMS Selection File */
  839. ret = _DtI18nWriteImSelectionFile(env);
  840. /* Save the preeditType resource value if needed */
  841. if (i18n.preeditHasChanged) {
  842. if (style.xrdb.writeXrdbImmediate)
  843. InfoDialog(MSG_IMMEDIATE, style.shell, False);
  844. else
  845. InfoDialog(MSG_LATER, style.shell, False);
  846. /* generate a string from the list to set the resource */
  847. XtVaGetValues(i18n.preeditTypeList,
  848. XmNitemCount, &num_preedit,
  849. XmNitems, &list_preedit, NULL);
  850. /* Save this value in case of a Cancel */
  851. if (i18n.preeditSavedVal) {
  852. FreeST(i18n.preeditSavedVal, i18n.preeditSavedNum);
  853. }
  854. i18n.preeditSavedVal = CopyST(list_preedit, num_preedit);
  855. i18n.preeditSavedNum = num_preedit;
  856. for (i = 0; i < num_preedit; i++) {
  857. /* get the text of the XmString */
  858. tmpStr = XmStringUnparse(list_preedit[i], NULL, XmCHARSET_TEXT,
  859. XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
  860. /* realloc mallocs the first time */
  861. preeditStr = XtRealloc(preeditStr,
  862. strlen(preeditStr) + strlen(tmpStr) + 2);
  863. /* insert the comma before the second, third. etc */
  864. if (i != 0) {
  865. strcat(preeditStr, ",");
  866. strcat(preeditStr, tmpStr);
  867. }
  868. else
  869. strcpy(preeditStr, tmpStr);
  870. XtFree(tmpStr);
  871. }
  872. /* if writeXrdbImmediate true write to Xrdb else send to
  873. session mgr */
  874. sprintf(preeditTypeRes, "*preeditType: %s\n", preeditStr);
  875. XtFree(preeditStr);
  876. if(style.xrdb.writeXrdbImmediate)
  877. _DtAddToResource(style.display, preeditTypeRes);
  878. SmNewPreeditSettings(preeditTypeRes);
  879. /* Reset the state of the list. */
  880. i18n.preeditHasChanged = False;
  881. }
  882. return (ret);
  883. }
  884. static void
  885. SetFileSelValues(
  886. I18nEnv *env
  887. )
  888. {
  889. char *hostname;
  890. Cardinal i;
  891. XtArgVal n;
  892. Widget *im_tog;
  893. /* The hostname value is stored in the ImsSel structure. */
  894. env->file_sel->hostname = XtNewString(env->ims_sel->host_name);
  895. /* Get the selected IM from the selected Toggle button */
  896. XtVaGetValues(i18n.inputMethodRC, XmNchildren, &im_tog,
  897. XmNnumChildren, &n, NULL);
  898. if (n) {
  899. for (i=0; i<n; i++) {
  900. if (XmToggleButtonGadgetGetState(im_tog[i]) == TRUE) {
  901. XtVaGetValues(im_tog[i], XmNuserData,
  902. &(env->file_sel->im_name),
  903. NULL);
  904. break;
  905. }
  906. }
  907. }
  908. else
  909. env->file_sel->im_name = NULL;
  910. /* Get the start mode from the askAtLoginTG state */
  911. if (XmToggleButtonGadgetGetState(i18n.askAtLoginTG) == TRUE)
  912. env->file_sel->start_mode = 0;
  913. else
  914. env->file_sel->start_mode = 1;
  915. }
  916. static void
  917. ResetLastSavedValues(
  918. I18nEnv *env
  919. )
  920. {
  921. if (env->file_sel->start_mode == -1) return;
  922. /* Reset the TextField of the ComboBox to the last saved hostname. */
  923. XtVaSetValues(XtNameToWidget(i18n.serverHostCB,"Text"),
  924. XmNvalue, env->file_sel->hostname, NULL);
  925. UpdateImList(env, env->file_sel->hostname);
  926. /* Reset the saved start mode */
  927. SetImsMode(env);
  928. }
  929. /************************************************************************
  930. * restoreI18n()
  931. * restore any state information saved with savei18n.
  932. * This is called from restoreSession with the application
  933. * shell and the special xrm database retrieved for restore.
  934. ************************************************************************/
  935. void
  936. restoreI18n(
  937. Widget shell,
  938. XrmDatabase db )
  939. {
  940. XrmName xrm_name[5];
  941. XrmRepresentation rep_type;
  942. XrmValue value;
  943. xrm_name [0] = XrmStringToQuark ("i18nDlg");
  944. xrm_name [2] = 0;
  945. /* get x position */
  946. xrm_name [1] = XrmStringToQuark ("x");
  947. if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
  948. XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr));
  949. save.poscnt++;
  950. save.restoreFlag = True;
  951. }
  952. /* get y position */
  953. xrm_name [1] = XrmStringToQuark ("y");
  954. if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
  955. XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr)); save.poscnt++;
  956. }
  957. xrm_name [1] = XrmStringToQuark ("ismapped");
  958. XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
  959. /* Are we supposed to be mapped? */
  960. if (strcmp(value.addr, "True") == 0)
  961. popup_i18nBB(shell);
  962. }
  963. /************************************************************************
  964. * saveI18n()
  965. *
  966. * This routine will write out to the passed file descriptor any state
  967. * information this dialog needs. It is called from saveSessionCB with the
  968. * file already opened.
  969. * All information is saved in xrm format. There is no restriction
  970. * on what can be saved. It doesn't have to be defined or be part of any
  971. * widget or Xt definition. Just name and save it here and recover it in
  972. * restoreBackdrop. The suggested minimum is whether you are mapped, and your
  973. * location.
  974. ************************************************************************/
  975. void
  976. saveI18n(
  977. int fd )
  978. {
  979. Position x,y;
  980. Dimension width, height;
  981. char *bufr = style.tmpBigStr; /* size=[1024], make bigger if needed */
  982. XmVendorShellExtObject vendorExt;
  983. XmWidgetExtData extData;
  984. if (style.i18nDialog != NULL)
  985. {
  986. if (XtIsManaged(style.i18nDialog))
  987. sprintf(bufr, "*i18nDlg.ismapped: True\n");
  988. else
  989. sprintf(bufr, "*i18nDlg.ismapped: False\n");
  990. /* Get and write out the geometry info for our Window */
  991. x = XtX(XtParent(style.i18nDialog));
  992. y = XtY(XtParent(style.i18nDialog));
  993. /* Modify x & y to take into account window mgr frames
  994. * This is pretty bogus, but I don't know a better way to do it.
  995. */
  996. extData = _XmGetWidgetExtData(style.shell, XmSHELL_EXTENSION);
  997. vendorExt = (XmVendorShellExtObject)extData->widget;
  998. x -= vendorExt->vendor.xOffset;
  999. y -= vendorExt->vendor.yOffset;
  1000. width = XtWidth(style.i18nDialog);
  1001. height = XtHeight(style.i18nDialog);
  1002. sprintf(bufr, "%s*i18nDlg.x: %d\n", bufr, x);
  1003. sprintf(bufr, "%s*i18nDlg.y: %d\n", bufr, y);
  1004. sprintf(bufr, "%s*i18nDlg.width: %d\n", bufr, width);
  1005. sprintf(bufr, "%s*i18nDlg.height: %d\n", bufr, height);
  1006. if(-1 == write (fd, bufr, strlen(bufr))) {
  1007. perror(strerror(errno));
  1008. }
  1009. }
  1010. }
  1011. /*+++++++++++++++++++++++++++++++++++++++*/
  1012. /* cancelWarnCB - callback for the */
  1013. /* cancel button of the warnDialog */
  1014. /*+++++++++++++++++++++++++++++++++++++++*/
  1015. static void
  1016. CancelWarnCB(
  1017. Widget w,
  1018. XtPointer client_data,
  1019. XtPointer call_data )
  1020. {
  1021. return;
  1022. }
  1023. /*+++++++++++++++++++++++++++++++++++++++*/
  1024. /* okWarnCB - callback for the */
  1025. /* OK button of the warnDialog */
  1026. /*+++++++++++++++++++++++++++++++++++++++*/
  1027. static void
  1028. OkWarnCB(
  1029. Widget w,
  1030. XtPointer client_data,
  1031. XtPointer call_data )
  1032. {
  1033. return;
  1034. }
  1035. /*+++++++++++++++++++++++++++++++++++++++*/
  1036. /* _DtI18nSetSensitiveImTB - set the */
  1037. /* sensitivity of the TitleBox. This is */
  1038. /* used when changing host, while getting*/
  1039. /* information. */
  1040. /* Also recreate the toggle list. */
  1041. /*+++++++++++++++++++++++++++++++++++++++*/
  1042. void
  1043. _DtI18nSetSensitiveImTB(
  1044. I18nEnv * env,
  1045. Boolean sensitivity )
  1046. {
  1047. static Boolean first_time = True;
  1048. XtSetSensitive(i18n.inputMethodRC, sensitivity);
  1049. if (sensitivity) {
  1050. SetImsToggleList(env);
  1051. /* Save the initial values in case of a Cancel */
  1052. if (first_time) {
  1053. SetFileSelValues(env);
  1054. first_time = False;
  1055. }
  1056. }
  1057. }
  1058. void
  1059. _DtI18nErrorDialog(
  1060. int err
  1061. )
  1062. {
  1063. char *err_str;
  1064. switch(err) {
  1065. case ErrNoHome:
  1066. err_str = GETMESSAGE(19, 30,
  1067. "The environment variable HOME is not defined.");
  1068. break;
  1069. case ErrNoLocale:
  1070. err_str = GETMESSAGE(19, 31,
  1071. "The environment variable LANG is not defined.");
  1072. break;
  1073. case ErrNoCDELocale:
  1074. err_str = GETMESSAGE(19, 32,
  1075. "This locale is not supported by the desktop.");
  1076. break;
  1077. /* File I/O */
  1078. case ErrFileCreate:
  1079. err_str = GETMESSAGE(19, 33,
  1080. "Cannot create the user Input Method Selection file");
  1081. break;
  1082. /* Selection */
  1083. case ErrNoSelectionFile:
  1084. err_str = GETMESSAGE(19, 34,
  1085. "Cannot find the user Input Method Selection file.");
  1086. break;
  1087. case ErrSaveSelection:
  1088. err_str = GETMESSAGE(19, 35,
  1089. "Cannot save the user Input Method Selection file.");
  1090. break;
  1091. /* Remote */
  1092. case ErrUnknownHost:
  1093. err_str = GETMESSAGE(19, 36, "Unknown host");
  1094. break;
  1095. case ErrNoDtimsstart:
  1096. err_str = GETMESSAGE(19, 37,
  1097. "dtimsstart was not found.\nPerhaps the desktop environment\nis not properly installed.");
  1098. break;
  1099. case ErrRemoteFailed:
  1100. err_str = GETMESSAGE(19, 38, "Remote execution failed on\n the selected host.");
  1101. /* Pipe */
  1102. case ErrNoPopen:
  1103. err_str = GETMESSAGE(19, 39, "Cannot initialize remote execution");
  1104. break;
  1105. case ErrTimeOut:
  1106. err_str = GETMESSAGE(19, 40, "Getting the Input Method on the \nselected host is taking too long");
  1107. break;
  1108. default:
  1109. err_str = GETMESSAGE(19, 41, "Unknown error");
  1110. break;
  1111. }
  1112. ErrDialog(err_str, style.i18nDialog);
  1113. }
  1114. /*+++++++++++++++++++++++++++++++++++++++*/
  1115. /* ListItemSelectCB - callback for the */
  1116. /* selection on an item in the preedit */
  1117. /* Type List. */
  1118. /*+++++++++++++++++++++++++++++++++++++++*/
  1119. static void
  1120. ListItemSelectCB(
  1121. Widget w,
  1122. XtPointer client_data,
  1123. XtPointer call_data )
  1124. {
  1125. XmListCallbackStruct *listCBS = (XmListCallbackStruct *) call_data;
  1126. /* Set the sensitivity of the MoveUp and MoveDown buttons depending
  1127. on the selected item position. MoveUp is insensitive is the first
  1128. item in the list is selected; MoveDown is insensitive if the last
  1129. item in the list is selected */
  1130. if (listCBS->item_position == 1)
  1131. XtSetSensitive(i18n.buttonMoveUp, False);
  1132. else
  1133. XtSetSensitive(i18n.buttonMoveUp, True);
  1134. if (listCBS->item_position == i18n.preeditTypeListLastPos)
  1135. XtSetSensitive(i18n.buttonMoveDown, False);
  1136. else
  1137. XtSetSensitive(i18n.buttonMoveDown, True);
  1138. return;
  1139. }
  1140. /*+++++++++++++++++++++++++++++++++++++++*/
  1141. /* MoveUpCB - callback for the */
  1142. /* MoveUp button */
  1143. /*+++++++++++++++++++++++++++++++++++++++*/
  1144. static void
  1145. MoveUpCB(
  1146. Widget w,
  1147. XtPointer client_data,
  1148. XtPointer call_data )
  1149. {
  1150. int *position_list;
  1151. int position_count;
  1152. if (XmListGetSelectedPos(i18n.preeditTypeList, &position_list,
  1153. &position_count)) {
  1154. /* there should be only one selected per our selection
  1155. policy set on the list, but consider the first selected one
  1156. in any case */
  1157. /* this should always be the case as the MoveUp button should be
  1158. insensitive when the first item is selected, but check anyway */
  1159. if (position_list[0] > 1) {
  1160. XmStringTable list_items;
  1161. XmString items[2];
  1162. int sel_pos = position_list[0];
  1163. int sel_index = sel_pos - 1;
  1164. XtVaGetValues(i18n.preeditTypeList, XmNitems, &list_items, NULL);
  1165. /* makes an array of two XmStrings by reversing the selected
  1166. one and the item preceding it */
  1167. items[0] = list_items[sel_index];
  1168. items[1] = list_items[sel_index - 1];
  1169. /* this call preserves selected state */
  1170. XmListReplaceItemsPos(i18n.preeditTypeList,
  1171. items, 2,
  1172. sel_pos - 1);
  1173. if (sel_pos == 2) {
  1174. /* it's now 1, so set the MoveUp button insensitive */
  1175. XtSetSensitive(i18n.buttonMoveUp, False);
  1176. }
  1177. if (sel_pos == i18n.preeditTypeListLastPos) {
  1178. /* it's not anymore the last one, so set the MoveDown
  1179. button sensitive */
  1180. XtSetSensitive(i18n.buttonMoveDown, True);
  1181. }
  1182. /* preeditType has changed */
  1183. i18n.preeditHasChanged = True;
  1184. }
  1185. }
  1186. }
  1187. /*+++++++++++++++++++++++++++++++++++++++*/
  1188. /* MoveDownCB - callback for the */
  1189. /* MoveDown button */
  1190. /*+++++++++++++++++++++++++++++++++++++++*/
  1191. static void
  1192. MoveDownCB(
  1193. Widget w,
  1194. XtPointer client_data,
  1195. XtPointer call_data )
  1196. {
  1197. int *position_list;
  1198. int position_count;
  1199. if (XmListGetSelectedPos(i18n.preeditTypeList, &position_list,
  1200. &position_count)) {
  1201. /* there should be only one selected per our selection
  1202. policy set on the list, but consider the first selected one
  1203. in any case */
  1204. /* this should always be the case as the Move Down button should be
  1205. insensitive when the first item is selected, but check anyway */
  1206. if (position_list[0] != i18n.preeditTypeListLastPos) {
  1207. XmStringTable list_items;
  1208. XmString items[2];
  1209. int sel_pos = position_list[0];
  1210. int sel_index = sel_pos - 1;
  1211. XtVaGetValues(i18n.preeditTypeList, XmNitems, &list_items, NULL);
  1212. /* makes an array of two XmStrings by reversing the selected
  1213. one and the item succeeding it */
  1214. items[0] = list_items[sel_index + 1];
  1215. items[1] = list_items[sel_index];
  1216. /* this call preserves selected state */
  1217. XmListReplaceItemsPos(i18n.preeditTypeList,
  1218. items, 2,
  1219. sel_pos);
  1220. if (sel_pos == (i18n.preeditTypeListLastPos - 1)) {
  1221. /* it's now the last one, so set the MoveDown button
  1222. insensitive */
  1223. XtSetSensitive(i18n.buttonMoveDown, False);
  1224. }
  1225. if (sel_pos == 1) {
  1226. /* it's not anymore the first one, so set the MoveUp
  1227. button sensitive */
  1228. XtSetSensitive(i18n.buttonMoveUp, True);
  1229. }
  1230. /* preeditType has changed */
  1231. i18n.preeditHasChanged = True;
  1232. }
  1233. }
  1234. }
  1235. static XmStringTable
  1236. CopyST (XmStringTable st, int nst)
  1237. {
  1238. XmStringTable lst = (XmStringTable) XtMalloc(sizeof(XmString) * nst);
  1239. int i ;
  1240. for (i=0; i < nst ; i++) {
  1241. lst[i] = XmStringCopy(st[i]);
  1242. }
  1243. return lst ;
  1244. }
  1245. static void
  1246. FreeST (XmStringTable st, int nst)
  1247. {
  1248. int i;
  1249. for (i=0; i < nst ; i++) {
  1250. XmStringFree(st[i]);
  1251. }
  1252. XtFree((char*)st);
  1253. }