1 /*---------------------------------------------------------------------------- 2 -- 3 -- Module: xtmEditPref 4 -- 5 -- Project: Xdiary 6 -- System: xtm - X Desktop Calendar 7 -- Subsystem: <> 8 -- Function block: <> 9 -- 10 -- Description: 11 -- Edit the preferences for an XDiary entry. 12 -- 13 -- Filename: xtmEditPref.c 14 -- 15 -- Authors: Roger Larsson, Ulrika Bornetun 16 -- Creation date: 1992-10-10 17 -- 18 -- 19 -- (C) Copyright Ulrika Bornetun, Roger Larsson (1995) 20 -- All rights reserved 21 -- 22 -- Permission to use, copy, modify, and distribute this software and its 23 -- documentation for any purpose and without fee is hereby granted, 24 -- provided that the above copyright notice appear in all copies. Ulrika 25 -- Bornetun and Roger Larsson make no representations about the usability 26 -- of this software for any purpose. It is provided "as is" without express 27 -- or implied warranty. 28 ----------------------------------------------------------------------------*/ 29 30 /* SCCS module identifier. */ 31 static char SCCSID[] = "@(#) Module: xtmEditPref.c, Version: 1.1, Date: 95/02/18 15:52:16"; 32 33 34 /*---------------------------------------------------------------------------- 35 -- Include files 36 ----------------------------------------------------------------------------*/ 37 38 #include <string.h> 39 #include <stdlib.h> 40 #include <stdio.h> 41 42 #include <X11/Intrinsic.h> 43 #include <X11/Shell.h> 44 45 #include <Xm/Protocols.h> 46 47 #include <Xm/Xm.h> 48 #include <Xm/Form.h> 49 #include <Xm/Frame.h> 50 #include <Xm/RowColumn.h> 51 #include <Xm/Text.h> 52 #include <Xm/ToggleB.h> 53 54 #include "System.h" 55 #include "Message.h" 56 #include "TimDate.h" 57 58 #include "msgXdiary.h" 59 #include "xtmGlobal.h" 60 #include "xtmFields.h" 61 #include "xtmFormat.h" 62 #include "xtmHelp.h" 63 #include "xtmTools.h" 64 #include "xitColorSel.h" 65 #include "xitError.h" 66 #include "xitTools.h" 67 #include "xitTune.h" 68 #include "xtmEditPref.h" 69 70 71 /*---------------------------------------------------------------------------- 72 -- Macro definitions 73 ----------------------------------------------------------------------------*/ 74 75 /* Local widgets in the preference window. */ 76 #define colorBgCs dataLocalW[ 0 ] 77 #define colorEntryRc dataLocalW[ 1 ] 78 #define colorFgCs dataLocalW[ 2 ] 79 #define colorFr dataLocalW[ 3 ] 80 #define colorLa dataLocalW[ 4 ] 81 #define colorRc dataLocalW[ 5 ] 82 #define defColorPb dataLocalW[ 6 ] 83 #define flagsFr dataLocalW[ 7 ] 84 #define flagsRc dataLocalW[ 8 ] 85 #define hideFr dataLocalW[ 9 ] 86 #define hideLa dataLocalW[ 10 ] 87 #define hideRc dataLocalW[ 11 ] 88 #define hideWhatRc dataLocalW[ 12 ] 89 #define lineAlarmLa dataLocalW[ 13 ] 90 #define lineAlarmTx dataLocalW[ 14 ] 91 #define lineEntryLa dataLocalW[ 15 ] 92 #define lineEntryRc dataLocalW[ 16 ] 93 #define lineEntryTx dataLocalW[ 17 ] 94 #define linesFr dataLocalW[ 18 ] 95 #define linesLa dataLocalW[ 19 ] 96 #define linesRc dataLocalW[ 20 ] 97 #define sampleLa dataLocalW[ 21 ] 98 99 100 /*---------------------------------------------------------------------------- 101 -- Type declarations 102 ----------------------------------------------------------------------------*/ 103 104 /* Record describing one instance of the preference window. */ 105 typedef struct { 106 107 /* Preference window. */ 108 Widget prefW; 109 110 /* Application wide data. */ 111 XTM_GL_BASE_DATA_REF appl_data_ref; 112 113 /* Callback and user data to inform our creator of specific actions. */ 114 XTM_EP_ACTION_CB actionCB; 115 void *user_data; 116 117 } PREF_REC, *PREF_REC_REF; 118 119 120 /*---------------------------------------------------------------------------- 121 -- Global definitions 122 ----------------------------------------------------------------------------*/ 123 124 /* Name of module. */ 125 static char *module_name = "xtmEditPref"; 126 127 /* IDs for the help windows. */ 128 static char *pref_window_id = "EntryPref"; 129 130 131 /*---------------------------------------------------------------------------- 132 -- Function prototypes 133 ----------------------------------------------------------------------------*/ 134 135 static void 136 cancelCB( Widget widget, 137 PREF_REC_REF pref_ref, 138 XtPointer call_data ); 139 140 static Widget 141 createPrefWindow( Widget parent, 142 PREF_REC_REF pref_ref ); 143 144 static void 145 defaultColorCB( Widget widget, 146 PREF_REC_REF pref_ref, 147 XtPointer call_data ); 148 149 static void 150 destroyCB( Widget widget, 151 PREF_REC_REF pref_ref, 152 XtPointer call_data ); 153 154 static Boolean 155 fetchPrefValues( PREF_REC_REF pref_ref, 156 XTM_EP_GET_PREF_DATA *values_ref ); 157 158 static void 159 helpCB( Widget widget, 160 PREF_REC_REF pref_ref, 161 XtPointer call_data ); 162 163 static void 164 newColorCB( Widget widget, 165 PREF_REC_REF pref_ref, 166 xitColorSelectCallbackStruct *call_data ); 167 168 static void 169 okCB( Widget widget, 170 PREF_REC_REF pref_ref, 171 XtPointer call_data ); 172 173 static void 174 setPrefValues( PREF_REC_REF pref_ref, 175 XTM_EP_SET_PREF_DATA *values_ref ); 176 177 178 179 /*---------------------------------------------------------------------------- 180 -- Functions 181 ----------------------------------------------------------------------------*/ 182 183 XTM_EP_HANDLE xtmEpInitialize(XTM_GL_BASE_DATA_REF appl_data_ref,Widget parent,XTM_EP_ACTION_CB actionCB,void * user_data)184 xtmEpInitialize( XTM_GL_BASE_DATA_REF appl_data_ref, 185 Widget parent, 186 XTM_EP_ACTION_CB actionCB, 187 void *user_data ) 188 { 189 190 /* Variables. */ 191 PREF_REC_REF pref_ref; 192 193 194 /* Code. */ 195 196 /* Create and initialize our private data. */ 197 pref_ref = SysNew( PREF_REC ); 198 if( pref_ref == NULL ) 199 return( NULL ); 200 201 pref_ref -> appl_data_ref = appl_data_ref; 202 pref_ref -> actionCB = actionCB; 203 pref_ref -> user_data = user_data; 204 pref_ref -> prefW = NULL; 205 206 207 /* Create the base window. */ 208 pref_ref -> prefW = createPrefWindow( parent, pref_ref ); 209 if( pref_ref -> prefW == NULL ) { 210 SysFree( pref_ref ); 211 212 return( NULL ); 213 } 214 215 216 return( (XTM_EP_HANDLE) pref_ref ); 217 218 } /* xtmEpInitialize */ 219 220 221 /*----------------------------------------------------------------------*/ 222 223 void xtmEpDestroy(XTM_EP_HANDLE pref_handle)224 xtmEpDestroy( XTM_EP_HANDLE pref_handle ) 225 { 226 227 /* Variables. */ 228 PREF_REC_REF pref_ref; 229 230 231 /* Code. */ 232 233 if( pref_handle == NULL ) 234 return; 235 236 /* Our private data. */ 237 pref_ref = (PREF_REC_REF) pref_handle; 238 239 /* Get rid of all windows. */ 240 if( pref_ref -> prefW != NULL ) 241 XtDestroyWidget( pref_ref -> prefW ); 242 243 244 return; 245 246 } /* xtmEpDestroy */ 247 248 249 /*----------------------------------------------------------------------*/ 250 251 void xtmEpEditPreferences(XTM_EP_HANDLE pref_handle,XTM_EP_SET_PREF_DATA * values_ref)252 xtmEpEditPreferences( XTM_EP_HANDLE pref_handle, 253 XTM_EP_SET_PREF_DATA *values_ref ) 254 { 255 256 /* Variables. */ 257 PREF_REC_REF pref_ref; 258 259 260 /* Code. */ 261 262 /* Our private data. */ 263 pref_ref = (PREF_REC_REF) pref_handle; 264 265 266 /* Make sure the window is visible. */ 267 XtManageChild( pref_ref -> prefW ); 268 269 270 /* Set the window data. */ 271 setPrefValues( pref_ref, values_ref ); 272 273 274 return; 275 276 } /* xtmEaEditPreferences */ 277 278 279 /*----------------------------------------------------------------------*/ 280 281 static Widget createPrefWindow(Widget parent,PREF_REC_REF pref_ref)282 createPrefWindow( Widget parent, 283 PREF_REC_REF pref_ref ) 284 { 285 286 /* Variables. */ 287 Arg args[ 10 ]; 288 Cardinal n; 289 Widget dataLocalW[ 22 ]; 290 Widget hideTb[ 6 ]; 291 Widget prefFd; 292 Widget flagsTb[ 4 ]; 293 Widget workFo; 294 XTM_GL_BASE_DATA_REF appl_data_ref; 295 XTM_GL_CUSTOM_DATA_REF custom_data_ref; 296 297 298 static XIT_TEXT_STRUCT text_buffer[] = { 299 { "LineEntryTx", NULL, 1, True }, 300 { "LineAlarmTx", NULL, 1, True }, 301 }; 302 303 static XIT_ACTION_AREA_ITEM action_buttons[] = { 304 { "", okCB, NULL }, 305 { "", cancelCB, NULL }, 306 { "", helpCB, NULL }, 307 }; 308 309 static XIT_PUSH_STRUCT doit_buttons_def[] = { 310 { "DefColorPb", "", "", True, NULL }, 311 }; 312 313 314 /* Code. */ 315 316 appl_data_ref = pref_ref -> appl_data_ref; 317 custom_data_ref = appl_data_ref -> custom_data; 318 319 320 action_buttons[ 0 ].label = msgGetText( MXDI_OK_BUTTON ); 321 action_buttons[ 0 ].data = pref_ref; 322 action_buttons[ 1 ].label = msgGetText( MXDI_CANCEL_BUTTON ); 323 action_buttons[ 1 ].data = pref_ref; 324 action_buttons[ 2 ].label = msgGetText( MXDI_HELP_BUTTON ); 325 action_buttons[ 2 ].data = pref_ref; 326 327 doit_buttons_def[ 0 ].title = msgGetText( MXDI_DEFAULT_COLORS_LABEL ); 328 329 330 /* Create a form dialog with buttons. */ 331 prefFd = xitCreateFormDialog( parent, "PrefFd", 332 1, 0, 333 action_buttons, 334 XtNumber( action_buttons ) ); 335 336 XtAddCallback( prefFd, XmNdestroyCallback, 337 (XtCallbackProc) destroyCB, (XtPointer) pref_ref ); 338 339 /* We want to know when this window is closed. */ 340 { 341 Atom wm_delete_window; 342 343 wm_delete_window = XmInternAtom( XtDisplay( prefFd ), 344 "WM_DELETE_WINDOW", False ); 345 346 XmAddWMProtocols( XtParent( prefFd ), &wm_delete_window, 1 ); 347 XmAddWMProtocolCallback( XtParent( prefFd ), wm_delete_window, 348 (XtCallbackProc) cancelCB, (XtPointer) pref_ref ); 349 } /* block */ 350 351 n = 0; 352 XtSetArg( args[ n ], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL ); n++; 353 XtSetValues( prefFd, args, n ); 354 355 n = 0; 356 XtSetArg( args[ n ], XmNtitle, msgGetText( MXDI_PREF_TITLE ) ); n++; 357 XtSetValues( XtParent( prefFd ), args, n ); 358 359 360 /* Container for the contents of the window. */ 361 workFo = XtNameToWidget( prefFd, "PrefFdFo" ); 362 363 364 /* Form for the lines to show. */ 365 linesFr = XmCreateFrame( workFo, "LinesFr", args, 0 ); 366 367 n = 0; 368 XtSetArg( args[ n ], XmNorientation, XmVERTICAL ); n++; 369 linesRc = XmCreateRowColumn( linesFr, "LinesRc", args, n ); 370 371 linesLa = xitCreateLabel( linesRc, "LinesLa", 372 msgGetText( MXDI_LINE_LABEL ), -1 ); 373 374 n = 0; 375 XtSetArg( args[ n ], XmNorientation, XmHORIZONTAL ); n++; 376 lineEntryRc = XmCreateRowColumn( linesRc, "LineEntryRc", args, n ); 377 378 lineEntryLa = xitCreateLabel( 379 lineEntryRc, "LineEntryLa", 380 msgGetText( MXDI_LINE_ENTRY_LABEL ), -1 ); 381 382 lineEntryTx = xitCreateTextCols( lineEntryRc, &text_buffer[ 0 ], 5 ); 383 384 lineAlarmLa = xitCreateLabel( 385 lineEntryRc, "LineAlarmLa", 386 msgGetText( MXDI_LINE_ALARM_LABEL ), -1 ); 387 388 lineAlarmTx = xitCreateTextCols( lineEntryRc, &text_buffer[ 1 ], 5 ); 389 390 n = 0; 391 XtSetArg( args[ n ], XmNmaxLength, 3 ); n++; 392 XtSetValues( lineEntryTx, args, n ); 393 XtSetValues( lineAlarmTx, args, n ); 394 395 396 /* Form for the foreground and background colors. */ 397 colorFr = XmCreateFrame( workFo, "ColorFr", args, 0 ); 398 399 n = 0; 400 XtSetArg( args[ n ], XmNorientation, XmVERTICAL ); n++; 401 XtSetArg( args[ n ], XmNadjustLast, False ); n++; 402 colorRc = XmCreateRowColumn( colorFr, "ColorRc", args, n ); 403 404 colorLa = xitCreateLabel( colorRc, "ColorLa", 405 msgGetText( MXDI_ENTRY_COLOR_LABEL ), -1 ); 406 407 n = 0; 408 XtSetArg( args[ n ], XmNorientation, XmHORIZONTAL ); n++; 409 XtSetArg( args[ n ], XmNspacing, 10 ); n++; 410 colorEntryRc = XmCreateRowColumn( colorRc, "ColorEntryRc", args, n ); 411 412 colorFgCs = xtmFlCreateColorField( colorEntryRc, "ColorFgCs", 413 5, 414 custom_data_ref -> color_fg_list, 415 (XtCallbackProc) newColorCB, 416 (void *) pref_ref ); 417 418 colorBgCs = xtmFlCreateColorField( colorEntryRc, "ColorBgCs", 419 5, 420 custom_data_ref -> color_bg_list, 421 (XtCallbackProc) newColorCB, 422 (void *) pref_ref ); 423 424 sampleLa = xitCreateLabelWidget( colorRc, "SampleLa", 425 msgGetText( MXDI_COLOR_SAMPLE_LABEL ), 426 -1 ); 427 428 defColorPb = xitCreatePushButton( colorRc, &doit_buttons_def[ 0 ] ); 429 430 n = 0; 431 XtSetArg( args[ n ], XmNalignment, XmALIGNMENT_CENTER ); n++; 432 XtSetValues( defColorPb, args, n ); 433 434 XtAddCallback( defColorPb, XmNactivateCallback, 435 (XtCallbackProc) defaultColorCB, (XtPointer) pref_ref ); 436 437 438 /* Where the entry should be hidden. */ 439 hideFr = XmCreateFrame( workFo, "HideFr", args, 0 ); 440 hideRc = XmCreateRowColumn( hideFr, "HideRc", args, 0 ); 441 442 hideLa = xitCreateLabel( hideRc, "HideLa", 443 msgGetText( MXDI_HIDE_IN_LABEL ), -1 ); 444 445 n = 0; 446 XtSetArg( args[ n ], XmNnumColumns, 2 ); n++; 447 XtSetArg( args[ n ], XmNpacking, XmPACK_COLUMN ); n++; 448 hideWhatRc = XmCreateRowColumn( hideRc, "HideWhatRc", args, n ); 449 450 hideTb[ 0 ] = xitCreateToggleButton( 451 hideWhatRc, "Hide1Tb", 452 msgGetText( MXDI_HIDE_IN_CAL_LABEL ), False ); 453 454 hideTb[ 1 ] = xitCreateToggleButton( 455 hideWhatRc, "Hide2Tb", 456 msgGetText( MXDI_HIDE_IN_DAY_VIEW_LABEL ), False ); 457 458 hideTb[ 2 ] = xitCreateToggleButton( 459 hideWhatRc, "Hide3Tb", 460 msgGetText( MXDI_HIDE_IN_SUMMARY_LABEL ), False ); 461 462 hideTb[ 3 ] = xitCreateToggleButton( 463 hideWhatRc, "Hide4Tb", 464 msgGetText( MXDI_HIDE_IN_PRINT_LABEL ), False ); 465 466 hideTb[ 4 ] = xitCreateToggleButton( 467 hideWhatRc, "Hide5Tb", 468 msgGetText( MXDI_HIDE_IN_ALARM_LABEL ), False ); 469 470 hideTb[ 5 ] = xitCreateToggleButton( 471 hideWhatRc, "Hide6Tb", 472 msgGetText( MXDI_HIDE_IN_DUMP_LABEL ), False ); 473 474 475 /* Various flags for the entry. */ 476 flagsFr = XmCreateFrame( workFo, "FlagsFr", args, 0 ); 477 flagsRc = XmCreateRowColumn( flagsFr, "FlagsRc", args, 0 ); 478 479 flagsTb[ 0 ] = xitCreateToggleButton( 480 flagsRc, "Flags1Tb", 481 msgGetText( MXDI_PROT_NOT_OWNER_CHANGE_LABEL ), False ); 482 483 flagsTb[ 1 ] = xitCreateToggleButton( 484 flagsRc, "Flags2Tb", 485 msgGetText( MXDI_PROT_NOT_OWNER_DELETE_LABEL ), False ); 486 487 flagsTb[ 2 ] = xitCreateToggleButton( 488 flagsRc, "Flags3Tb", 489 msgGetText( MXDI_KEEP_ENTRY_IN_FG_LABEL ), False ); 490 491 flagsTb[ 3 ] = xitCreateToggleButton( 492 flagsRc, "Flags4Tb", 493 msgGetText( MXDI_KEEP_ENTRY_IN_BG_LABEL ), False ); 494 495 496 /* Put the elements together. */ 497 xitAttachWidget( linesFr, 498 XmATTACH_FORM, NULL, XmATTACH_FORM, NULL, 499 XmATTACH_NONE, NULL, XmATTACH_NONE, NULL ); 500 xitAttachWidget( colorFr, 501 XmATTACH_WIDGET, linesFr, XmATTACH_FORM, NULL, 502 XmATTACH_NONE, NULL, XmATTACH_NONE, NULL ); 503 xitAttachWidget( hideFr, 504 XmATTACH_WIDGET, colorFr, XmATTACH_FORM, NULL, 505 XmATTACH_NONE, NULL, XmATTACH_NONE, NULL ); 506 xitAttachWidget( flagsFr, 507 XmATTACH_WIDGET, hideFr, XmATTACH_FORM, NULL, 508 XmATTACH_NONE, NULL, XmATTACH_NONE, NULL ); 509 510 n = 0; 511 XtSetArg( args[ n ], XmNtopOffset, 5 ); n++; 512 XtSetArg( args[ n ], XmNleftOffset, 5 ); n++; 513 XtSetArg( args[ n ], XmNrightOffset, 5 ); n++; 514 XtSetArg( args[ n ], XmNbottomOffset, 5 ); n++; 515 XtSetValues( linesFr, args, n ); 516 XtSetValues( hideFr, args, n ); 517 XtSetValues( flagsFr, args, n ); 518 XtSetValues( colorFr, args, n ); 519 520 521 /* Manage the widgets. */ 522 xitManageChildren( hideTb, XtNumber( hideTb ) ); 523 xitManageChildren( flagsTb, XtNumber( flagsTb ) ); 524 525 xitManageChildren( dataLocalW, XtNumber( dataLocalW ) ); 526 527 528 /* Set the initial sizes. */ 529 xitSetSizeFormDialog( prefFd, False ); 530 531 532 return( prefFd ); 533 534 } /* createPrefWindow */ 535 536 537 /*----------------------------------------------------------------------*/ 538 539 static Boolean fetchPrefValues(PREF_REC_REF pref_ref,XTM_EP_GET_PREF_DATA * values_ref)540 fetchPrefValues( PREF_REC_REF pref_ref, 541 XTM_EP_GET_PREF_DATA *values_ref ) 542 { 543 544 /* Variables. */ 545 Boolean ok; 546 int color_index; 547 int index; 548 char buffer[ 100 ]; 549 char *char_ref; 550 Widget baseW; 551 Widget mainW; 552 Widget tempW; 553 554 555 /* Code. */ 556 557 /* We need a waindow. */ 558 if( pref_ref -> prefW == NULL ) 559 return( False ); 560 561 562 /* Preference window. */ 563 mainW = XtNameToWidget( pref_ref -> prefW, "PrefFdFo" ); 564 565 566 /* Default values. */ 567 values_ref -> alarm_lines = 0; 568 values_ref -> day_list_lines = 0; 569 values_ref -> flags = 0; 570 values_ref -> bg_color_index = 0; 571 values_ref -> fg_color_index = 0; 572 573 574 /* Lines to show. */ 575 sprintf( buffer, "LinesFr.LinesRc.LineEntryRc" ); 576 baseW = XtNameToWidget( mainW, buffer ); 577 578 tempW = XtNameToWidget( baseW, "LineEntryTx" ); 579 580 char_ref = xitStringGetText( tempW ); 581 index = atoi( char_ref ); 582 SysFree( char_ref ); 583 584 if( index > 0 ) 585 values_ref -> day_list_lines = index; 586 587 tempW = XtNameToWidget( baseW, "LineAlarmTx" ); 588 589 char_ref = xitStringGetText( tempW ); 590 index = atoi( char_ref ); 591 SysFree( char_ref ); 592 593 if( index > 0 ) 594 values_ref -> alarm_lines = index; 595 596 597 /* Hide in? */ 598 sprintf( buffer, "HideFr.HideRc.HideWhatRc" ); 599 baseW = XtNameToWidget( mainW, buffer ); 600 601 tempW = XtNameToWidget( baseW, "Hide1Tb" ); 602 if( XmToggleButtonGetState( tempW ) ) 603 flagSet( values_ref -> flags, XTM_DB_FLAG_HIDE_IN_CALENDAR ); 604 605 tempW = XtNameToWidget( baseW, "Hide2Tb" ); 606 if( XmToggleButtonGetState( tempW ) ) 607 flagSet( values_ref -> flags, XTM_DB_FLAG_HIDE_IN_DAY_VIEW ); 608 609 tempW = XtNameToWidget( baseW, "Hide3Tb" ); 610 if( XmToggleButtonGetState( tempW ) ) 611 flagSet( values_ref -> flags, XTM_DB_FLAG_HIDE_IN_SUMMARY ); 612 613 tempW = XtNameToWidget( baseW, "Hide4Tb" ); 614 if( XmToggleButtonGetState( tempW ) ) 615 flagSet( values_ref -> flags, XTM_DB_FLAG_HIDE_IN_PRINT ); 616 617 tempW = XtNameToWidget( baseW, "Hide5Tb" ); 618 if( XmToggleButtonGetState( tempW ) ) 619 flagSet( values_ref -> flags, XTM_DB_FLAG_HIDE_IN_ALARM ); 620 621 tempW = XtNameToWidget( baseW, "Hide6Tb" ); 622 if( XmToggleButtonGetState( tempW ) ) 623 flagSet( values_ref -> flags, XTM_DB_FLAG_HIDE_IN_DUMP ); 624 625 626 /* Flags for the entry? */ 627 sprintf( buffer, "FlagsFr.FlagsRc" ); 628 baseW = XtNameToWidget( mainW, buffer ); 629 630 tempW = XtNameToWidget( baseW, "Flags1Tb" ); 631 if( XmToggleButtonGetState( tempW ) ) 632 flagSet( values_ref -> flags, XTM_DB_FLAG_ONLY_OWNER_CHANGE ); 633 634 tempW = XtNameToWidget( baseW, "Flags2Tb" ); 635 if( XmToggleButtonGetState( tempW ) ) 636 flagSet( values_ref -> flags, XTM_DB_FLAG_ONLY_OWNER_DELETE ); 637 638 tempW = XtNameToWidget( baseW, "Flags3Tb" ); 639 if( XmToggleButtonGetState( tempW ) ) 640 flagSet( values_ref -> flags, XTM_DB_FLAG_KEEP_IN_FG ); 641 642 tempW = XtNameToWidget( baseW, "Flags4Tb" ); 643 if( XmToggleButtonGetState( tempW ) ) 644 flagSet( values_ref -> flags, XTM_DB_FLAG_KEEP_IN_BG ); 645 646 647 /* Foreground and background color. */ 648 sprintf( buffer, "ColorFr.ColorRc.ColorEntryRc" ); 649 baseW = XtNameToWidget( mainW, buffer ); 650 651 tempW = XtNameToWidget( baseW, "ColorBgCs" ); 652 ok = xitColorSelectGetIndex( tempW, &color_index ); 653 654 if( ok ) 655 values_ref -> bg_color_index = color_index; 656 657 tempW = XtNameToWidget( baseW, "ColorFgCs" ); 658 ok = xitColorSelectGetIndex( tempW, &color_index ); 659 660 if( ok ) 661 values_ref -> fg_color_index = color_index; 662 663 664 return( True ); 665 666 } /* fetchPrefValues */ 667 668 669 /*----------------------------------------------------------------------*/ 670 671 static void setPrefValues(PREF_REC_REF pref_ref,XTM_EP_SET_PREF_DATA * values_ref)672 setPrefValues( PREF_REC_REF pref_ref, 673 XTM_EP_SET_PREF_DATA *values_ref ) 674 { 675 676 /* Variables. */ 677 int color_index; 678 char buffer[ 80 ]; 679 Widget baseW; 680 Widget mainW; 681 Widget tempW; 682 XTM_GL_BASE_DATA_REF appl_data_ref; 683 XTM_GL_CUSTOM_DATA_REF custom_data_ref; 684 685 686 /* Code. */ 687 688 appl_data_ref = pref_ref -> appl_data_ref; 689 custom_data_ref = appl_data_ref -> custom_data; 690 691 /* We need a waindow. */ 692 if( pref_ref -> prefW == NULL ) 693 return; 694 695 696 mainW = XtNameToWidget( pref_ref -> prefW, "PrefFdFo" ); 697 698 699 /* Lines to show. */ 700 sprintf( buffer, "LinesFr.LinesRc.LineEntryRc" ); 701 baseW = XtNameToWidget( mainW, buffer ); 702 703 tempW = XtNameToWidget( baseW, "LineEntryTx" ); 704 705 sprintf( buffer, "%d ", values_ref -> day_list_lines ); 706 XmTextSetString( tempW, buffer ); 707 708 tempW = XtNameToWidget( baseW, "LineAlarmTx" ); 709 710 sprintf( buffer, "%d ", values_ref -> alarm_lines ); 711 XmTextSetString( tempW, buffer ); 712 713 714 /* Hide the entry in? */ 715 sprintf( buffer, "HideFr.HideRc.HideWhatRc" ); 716 baseW = XtNameToWidget( mainW, buffer ); 717 718 tempW = XtNameToWidget( baseW, "Hide1Tb" ); 719 720 if( values_ref -> entry_type == XTM_DB_TYPE_APPOINTMENT || 721 values_ref -> entry_type == XTM_DB_TYPE_NOTE ) { 722 XmToggleButtonSetState( tempW, False, False ); 723 XtSetSensitive( tempW, False ); 724 725 } else { 726 if( flagIsSet( values_ref -> flags, XTM_DB_FLAG_HIDE_IN_CALENDAR ) ) 727 XmToggleButtonSetState( tempW, True, False ); 728 else 729 XmToggleButtonSetState( tempW, False, False ); 730 XtSetSensitive( tempW, True ); 731 } 732 733 tempW = XtNameToWidget( baseW, "Hide2Tb" ); 734 if( flagIsSet( values_ref -> flags, XTM_DB_FLAG_HIDE_IN_DAY_VIEW ) ) 735 XmToggleButtonSetState( tempW, True, False ); 736 else 737 XmToggleButtonSetState( tempW, False, False ); 738 739 tempW = XtNameToWidget( baseW, "Hide3Tb" ); 740 if( flagIsSet( values_ref -> flags, XTM_DB_FLAG_HIDE_IN_SUMMARY ) ) 741 XmToggleButtonSetState( tempW, True, False ); 742 else 743 XmToggleButtonSetState( tempW, False, False ); 744 745 tempW = XtNameToWidget( baseW, "Hide4Tb" ); 746 if( flagIsSet( values_ref -> flags, XTM_DB_FLAG_HIDE_IN_PRINT ) ) 747 XmToggleButtonSetState( tempW, True, False ); 748 else 749 XmToggleButtonSetState( tempW, False, False ); 750 751 tempW = XtNameToWidget( baseW, "Hide5Tb" ); 752 if( flagIsSet( values_ref -> flags, XTM_DB_FLAG_HIDE_IN_ALARM ) ) 753 XmToggleButtonSetState( tempW, True, False ); 754 else 755 XmToggleButtonSetState( tempW, False, False ); 756 757 tempW = XtNameToWidget( baseW, "Hide6Tb" ); 758 if( flagIsSet( values_ref -> flags, XTM_DB_FLAG_HIDE_IN_DUMP ) ) 759 XmToggleButtonSetState( tempW, True, False ); 760 else 761 XmToggleButtonSetState( tempW, False, False ); 762 763 764 /* Flags for the entry? */ 765 sprintf( buffer, "FlagsFr.FlagsRc" ); 766 baseW = XtNameToWidget( mainW, buffer ); 767 768 tempW = XtNameToWidget( baseW, "Flags1Tb" ); 769 if( flagIsSet( values_ref -> flags, XTM_DB_FLAG_ONLY_OWNER_CHANGE ) ) 770 XmToggleButtonSetState( tempW, True, False ); 771 else 772 XmToggleButtonSetState( tempW, False, False ); 773 774 tempW = XtNameToWidget( baseW, "Flags2Tb" ); 775 if( flagIsSet( values_ref -> flags, XTM_DB_FLAG_ONLY_OWNER_DELETE ) ) 776 XmToggleButtonSetState( tempW, True, False ); 777 else 778 XmToggleButtonSetState( tempW, False, False ); 779 780 tempW = XtNameToWidget( baseW, "Flags3Tb" ); 781 if( flagIsSet( values_ref -> flags, XTM_DB_FLAG_KEEP_IN_FG ) ) 782 XmToggleButtonSetState( tempW, True, False ); 783 else 784 XmToggleButtonSetState( tempW, False, False ); 785 786 tempW = XtNameToWidget( baseW, "Flags4Tb" ); 787 if( flagIsSet( values_ref -> flags, XTM_DB_FLAG_KEEP_IN_BG ) ) 788 XmToggleButtonSetState( tempW, True, False ); 789 else 790 XmToggleButtonSetState( tempW, False, False ); 791 792 793 /* Foreground and background color. */ 794 sprintf( buffer, "ColorFr.ColorRc.ColorEntryRc" ); 795 baseW = XtNameToWidget( mainW, buffer ); 796 797 color_index = values_ref -> bg_color_index; 798 if( color_index < 0 || 799 color_index >= custom_data_ref -> colorsDB_bg.no_colors ) 800 color_index = 0; 801 802 tempW = XtNameToWidget( baseW, "ColorBgCs" ); 803 xitColorSelectSetIndex( tempW, color_index, False ); 804 805 color_index = values_ref -> fg_color_index; 806 if( color_index < 0 || 807 color_index >= custom_data_ref -> colorsDB_fg.no_colors ) 808 color_index = 0; 809 810 tempW = XtNameToWidget( baseW, "ColorFgCs" ); 811 xitColorSelectSetIndex( tempW, color_index, True ); 812 813 814 return; 815 816 } /* setPrefValues */ 817 818 819 /*----------------------------------------------------------------------*/ 820 821 static void cancelCB(Widget widget,PREF_REC_REF pref_ref,XtPointer call_data)822 cancelCB( Widget widget, 823 PREF_REC_REF pref_ref, 824 XtPointer call_data ) 825 { 826 827 /* Code. */ 828 829 /* Do we have a user action callback registered? */ 830 if( pref_ref -> actionCB != NULL ) 831 (* pref_ref -> actionCB)( XTM_EP_REASON_CANCEL, 832 pref_ref -> user_data, NULL ); 833 834 XtUnmanageChild( pref_ref -> prefW ); 835 836 837 return; 838 839 } /* cancelCB */ 840 841 842 /*----------------------------------------------------------------------*/ 843 844 static void defaultColorCB(Widget widget,PREF_REC_REF pref_ref,XtPointer call_data)845 defaultColorCB( Widget widget, 846 PREF_REC_REF pref_ref, 847 XtPointer call_data ) 848 { 849 850 /* Variables. */ 851 Widget baseW; 852 Widget mainW; 853 Widget tempW; 854 855 856 /* Code. */ 857 858 mainW = XtNameToWidget( pref_ref -> prefW, "PrefFdFo" ); 859 860 /* Set the new colors. */ 861 baseW = XtNameToWidget( mainW, "ColorFr.ColorRc.ColorEntryRc" ); 862 863 tempW = XtNameToWidget( baseW, "ColorBgCs" ); 864 xitColorSelectSetIndex( tempW, 0, False ); 865 866 tempW = XtNameToWidget( baseW, "ColorFgCs" ); 867 xitColorSelectSetIndex( tempW, 0, True ); 868 869 870 return; 871 872 } /* defaultColorCB */ 873 874 875 /*----------------------------------------------------------------------*/ 876 877 static void destroyCB(Widget widget,PREF_REC_REF pref_ref,XtPointer call_data)878 destroyCB( Widget widget, 879 PREF_REC_REF pref_ref, 880 XtPointer call_data ) 881 { 882 883 /* Code. */ 884 885 /* Do we have a user action callback registered? */ 886 if( pref_ref -> actionCB != NULL ) 887 (* pref_ref -> actionCB)( XTM_EP_REASON_DESTROY, 888 pref_ref -> user_data, NULL ); 889 890 SysFree( pref_ref ); 891 892 893 return; 894 895 } /* destroyCB */ 896 897 898 /*----------------------------------------------------------------------*/ 899 900 static void helpCB(Widget widget,PREF_REC_REF pref_ref,XtPointer call_data)901 helpCB( Widget widget, 902 PREF_REC_REF pref_ref, 903 XtPointer call_data ) 904 { 905 906 /* Code. */ 907 908 xtmHlDisplayHelp( pref_ref -> appl_data_ref -> info_handle, 909 XTM_HL_WINDOW_INDEX, 910 pref_window_id, "" ); 911 912 913 return; 914 915 } /* helpCB */ 916 917 918 /*----------------------------------------------------------------------*/ 919 920 static void newColorCB(Widget widget,PREF_REC_REF pref_ref,xitColorSelectCallbackStruct * call_data)921 newColorCB( Widget widget, 922 PREF_REC_REF pref_ref, 923 xitColorSelectCallbackStruct *call_data ) 924 { 925 926 /* Variables. */ 927 Boolean ok; 928 Arg args[ 10 ]; 929 Cardinal n; 930 Pixel bg; 931 Pixel fg; 932 Widget baseW; 933 Widget mainW; 934 Widget tempW; 935 936 937 /* Code. */ 938 939 mainW = XtNameToWidget( pref_ref -> prefW, "PrefFdFo" ); 940 941 942 /* Fetch the selected background and foreground. */ 943 baseW = XtNameToWidget( mainW, "ColorFr.ColorRc.ColorEntryRc" ); 944 945 tempW = XtNameToWidget( baseW, "ColorBgCs" ); 946 ok = xitColorSelectGetPixel( tempW, &bg ); 947 948 tempW = XtNameToWidget( baseW, "ColorFgCs" ); 949 ok = xitColorSelectGetPixel( tempW, &fg ); 950 951 952 /* Set the color sample. */ 953 baseW = XtNameToWidget( mainW, "ColorFr.ColorRc" ); 954 tempW = XtNameToWidget( baseW, "SampleLa" ); 955 956 n = 0; 957 XtSetArg( args[ n ], XmNbackground, bg ); n++; 958 XtSetArg( args[ n ], XmNforeground, fg ); n++; 959 XtSetValues( tempW, args, n ); 960 961 962 return; 963 964 } /* newColorCB */ 965 966 967 /*----------------------------------------------------------------------*/ 968 969 static void okCB(Widget widget,PREF_REC_REF pref_ref,XtPointer call_data)970 okCB( Widget widget, 971 PREF_REC_REF pref_ref, 972 XtPointer call_data ) 973 { 974 975 /* Variables. */ 976 Boolean ok; 977 XTM_EP_GET_PREF_DATA values; 978 979 980 /* Code. */ 981 982 ok = fetchPrefValues( pref_ref, &values ); 983 if( ! ok ) 984 return; 985 986 /* Do we have a user action callback registered? */ 987 if( pref_ref -> actionCB != NULL ) 988 (* pref_ref -> actionCB)( XTM_EP_REASON_OK, 989 pref_ref -> user_data, 990 &values ); 991 992 XtUnmanageChild( pref_ref -> prefW ); 993 994 995 return; 996 997 } /* okCB */ 998