dialogDevice.icl 48.9 KB
Newer Older
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1 2 3 4 5 6 7
implementation module dialogDevice;

import StdClass; // RWS
import StdBool, StdChar, StdInt, StdString, StdReal;
import xkernel,xtypes, deltaIOSystem, xdialog;
import ioState, dialogDef;

8 9
from xwindow import get_mouse_state;
from xwindow import popdown;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
from windowDevice import EventToMouse,Draw_in_window;
from picture import NewXPicture;
import misc, commonDef;


     

XModalCommandDialog		:== 0;
XModelessCommandDialog	:== 1;

XGroupRows		:== 0;
XGroupColumns	:== 1;

XMarkOn			:== 0;
XMarkOff			:== 1;

XCControl		:== 0;
XCIcon			:== 1;


PictureNormal pic :== [SetPenNormal, SetPenColour BlackColour, 
                      SetBackColour WhiteColour, EraseRectangle pic];
PictureNormalF :== [SetPenNormal, SetPenColour BlackColour,
                   SetBackColour WhiteColour];

DummyDialHandle :== DialHandle Modeless (0,0) [] DummyDialogDef;
DummyDialogDef  :== CommandDialog 0 "" [] 0 [];


    

DialogFunctions ::    DeviceFunctions s;
DialogFunctions
   = (ShowDialog,OpenDialogDevice,DialogIO,CloseDialogDevice, HideDialog);


/* Closing the entire dialog device.
*/
CloseDialogDevice :: !(IOState s) -> IOState s;
CloseDialogDevice io
   =  UEvaluate_2 (IOStateRemoveDevice io` DialogDevice)
                  (Close_dialogs dialogs);
      where {
      (dialogs, io`)=: IOStateGetDevice io DialogDevice;
      };

Close_dialogs :: !(DeviceSystemState s) -> DeviceSystemState s;
Close_dialogs (DialogSystemState dialogs) 
   #!
		strict1=strict1;
		=
		DialogSystemState strict1;
	where {
	strict1=(Close_dialogs` dialogs);
		
	};

Close_dialogs` :: ![DialogHandle s io] -> [DialogHandle s io];
Close_dialogs`  [dialog : dialogs]
   =  Evaluate_2 (Close_dialogs` dialogs) (Close_dialog dialog);
Close_dialogs` dialogs =  dialogs;

Close_dialog :: !(DialogHandle s io) -> Widget;
73
Close_dialog (DialHandle m (id, w) handle def) =  destroy_dialog w;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102


HideDialog :: !(IOState s) -> IOState s;
HideDialog io_state
   =  IOStateSetDevice io_state` dialog`;
      where {
      dialog`            =: HideDialog` dialog;
      (dialog, io_state`)=: IOStateGetDevice io_state DialogDevice;
      };

HideDialog` :: !(DeviceSystemState s) -> DeviceSystemState s;
HideDialog` (DialogSystemState dialogs)
   #!
		strict1=strict1;
		=
		DialogSystemState strict1;
	where {
	strict1=(HideDialog`` dialogs);
		
	};

HideDialog`` :: ![DialogHandle s (IOState s)] -> [DialogHandle s (IOState s)];
HideDialog`` [DialHandle m (id,w) items def : dialogs]
   #!
		strict1=strict1;
		strict2=strict2;
		=
		[DialHandle m (id,strict1) items def : strict2];
	where {
103
	strict1=popdown_dialog w;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
		strict2=HideDialog`` dialogs;
		
	};
HideDialog`` dialogs =  dialogs;


ShowDialog :: !(IOState s) -> IOState s;
ShowDialog io_state
   =  IOStateSetDevice io_state` dialog`;
      where {
      dialog`            =: ShowDialog` dialog;
      (dialog, io_state`)=: IOStateGetDevice io_state DialogDevice;
      };

ShowDialog` :: !(DeviceSystemState s) -> DeviceSystemState s;
ShowDialog` (DialogSystemState dialogs)
   #!
		strict1=strict1;
		=
		DialogSystemState strict1;
	where {
	strict1=(ShowDialog`` dialogs);
		
	};

ShowDialog`` :: ![DialogHandle s (IOState s)] -> [DialogHandle s (IOState s)];
ShowDialog`` [h=:DialHandle Modal w items (CommandDialog id t a di items`) : dialogs]
   #!
		strict1=strict1;
		strict2=strict2;
		=
		[strict1 : strict2];
	where {
	strict1=PopupModalDialog h;
		strict2=ShowDialog`` dialogs;
		
	};
ShowDialog`` [dialog : dialogs]
   #!
		strict1=strict1;
		strict2=strict2;
		=
		[strict1 : strict2];
	where {
	strict1=PopupModelessDialog dialog;
		strict2=ShowDialog`` dialogs;
		
	};
ShowDialog`` dialogs =  dialogs;


/* Opening the dialog device at start up.
*/
OpenDialogDevice :: !(DeviceSystem s (IOState s)) !(IOState s) -> IOState s;
OpenDialogDevice (DialogSystem dialog_defs) io_state
   #!
		strict1=strict1;
		=
		IOStateSetDevice io_state (DialogSystemState strict1);
	where {
	strict1=(Open_dialogs dialog_defs);
		
	};

Open_dialogs :: ![DialogDef s (IOState s)] -> DialogHandles s (IOState s);
Open_dialogs [dialog=:CommandDialog id t a di items : dialogs]
   #!
		strict1=strict1;
		strict2=strict2;
		=
		[strict1 : strict2];
	where {
	strict1=Open_dialog Modeless dialog;
		strict2=Open_dialogs dialogs;
		
	};
Open_dialogs [dialog=:PropertyDialog id t a f1 f2 items : dialogs]
   #!
		strict1=strict1;
		strict2=strict2;
		=
		[strict1 : strict2];
	where {
		strict1=Open_dialog Modeless dialog;
		strict2=Open_dialogs dialogs;
	};
Open_dialogs [dialog=:AboutDialog appname pic=:((x0,y0),(x1,y1)) dfs help : dialogs]
	| x0==x1 && y0==y1
192
		#! r=set_toplevelname appname;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
		= Open_dialogs (Evaluate_2 (RemoveAbouts dialogs) r);
		#!
			strict1=Open_about dialog;
			strict2=Open_dialogs (RemoveAbouts dialogs);
		  =
			[strict1 : strict2];
Open_dialogs [dialog : dialogs] 
   =  Open_dialogs dialogs;
Open_dialogs dialogs =  [];

RemoveAbouts :: ![DialogDef s (IOState s)] -> [DialogDef s (IOState s)];
RemoveAbouts [AboutDialog appname pic dfs help : dialogs]
   =  RemoveAbouts dialogs;
RemoveAbouts [dialog : dialogs]
   #!
		strict1=strict1;
		=
		[dialog : strict1];
	where {
		strict1=RemoveAbouts dialogs;
	};
RemoveAbouts dialogs =  dialogs;

Open_about :: !(DialogDef s (IOState s)) -> DialogHandle s (IOState s);
Open_about def=:(AboutDialog appname ((x0,y0),(x1,y1)) dfs NoHelp)
   #!
		about=about;
		=
		Evaluate_2 (DialHandle Modal (-1, about) [] def)
222
                 (set_toplevelname appname);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
223
      where {
224
      about=: create_about_dialog x0 y0 x1 y1 0 "";
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
225 226 227 228 229 230 231
      };
Open_about def=:(AboutDialog appname ((x0,y0),(x1,y1)) dfs
                  (AboutHelp title f))
   #!
		about=about;
		=
		Evaluate_2 (DialHandle Modal (-1, about) [] def)
232
                 (set_toplevelname appname);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
233
      where {
234
      about=: create_about_dialog x0 y0 x1 y1 1 title;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
      };

Open_dialog :: !DialogMode !(DialogDef s (IOState s)) -> DialogHandle s (IOState s);
Open_dialog Modal def=:(CommandDialog id title att ditem items)
   #!
		strict1=strict1;
		=
		PopupModalDialog (strict1);
	where {
	strict1=OpenNormalDialog Modal def;
		
	};
Open_dialog modeless def=:(CommandDialog id title att ditem items)
   #!
		strict1=strict1;
		=
		PopupModelessDialog (strict1);
	where {
	strict1=OpenNormalDialog Modeless def;
		
	};
Open_dialog mode def=:(PropertyDialog id title att f1 f2 items)
   #!
		strict1=strict1;
		=
		PopupModelessDialog (strict1);
	where {
	strict1=OpenNormalDialog Modeless def;
		
	};

PopupModalDialog :: !(DialogHandle s (IOState s)) -> DialogHandle s (IOState s);
PopupModalDialog (DialHandle m (id,w) items def)
   #!
		strict1=strict1;
		=
		DialHandle Modal (id, strict1) items def;
	where {
273
	strict1=popup_modaldialog w;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
274 275 276 277 278 279 280 281 282 283 284
		
	};

PopupModelessDialog :: !(DialogHandle s (IOState s))
   -> DialogHandle s (IOState s);
PopupModelessDialog (DialHandle m (id,w) items def)
   #!
		strict1=strict1;
		=
		DialHandle Modeless (id, strict1) items def;
	where {
285
	strict1=popup_modelessdialog w;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
286 287 288 289 290 291 292 293
		
	};

OpenNormalDialog :: !DialogMode !(DialogDef s (IOState s)) -> DialogHandle s (IOState s);
OpenNormalDialog mode def=:(CommandDialog id title att ditem items)
   #!
		strict3=GetDialogSize att;
   #  (width,height)= strict3;
294
   #!  command= create_commanddial title width height (GetDialogMode mode);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
295 296 297 298
		strict2=(AddDialogItems command items);

      items` = PositionItems command att items strict2;
      defitem= GetCommandDefaultItem ditem items`;
299
      strict1=set_command_default command defitem;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
300 301 302 303 304 305
		=
		DialHandle mode (id, strict1) items` def;
OpenNormalDialog mode def=:(PropertyDialog id title att f1 f2 items)
   #!
		strict2=GetDialogSize att;
   #  (width,height)= strict2;
306
   #! property= create_propertydial title width height;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
      strict1=(AddDialogItems property items);
      items`  = PositionItems property att items strict1;
		=
		DialHandle mode (id, property) items` def;

GetDialogMode :: DialogMode -> Int; 
GetDialogMode Modal =  XModalCommandDialog;
GetDialogMode x     =  XModelessCommandDialog;

GetDialogSize :: ![DialogAttribute] -> (!Int, !Int);
GetDialogSize [DialogSize w h : rest] =  (ConvertMeasureX w,ConvertMeasureY h);
GetDialogSize [att : rest] =  GetDialogSize rest;
GetDialogSize atts =  (0,0);

ConvertMeasureX :: Measure -> Int;
ConvertMeasureX (Pixel n) =  n;
323 324
ConvertMeasureX (MM    n) =  mm_to_pixel_hor n;
ConvertMeasureX (Inch  n) =  mm_to_pixel_hor (n * 25.4);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
325 326 327
  
ConvertMeasureY :: Measure -> Int;
ConvertMeasureY (Pixel n) =  n;
328 329
ConvertMeasureY (MM    n) =  mm_to_pixel_ver n;
ConvertMeasureY (Inch  n) =  mm_to_pixel_ver(n * 25.4);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
330 331 332 333 334


AddDialogItems :: !Widget ![DialogItem s io] -> [XDItemHandle];
AddDialogItems dialog [DialogButton id layout title state f : items]
   #!
335
      item= add_dialog_button dialog 0 0 0 0 title;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
336 337 338 339 340 341 342 343 344 345 346
      strict1=SetDialogItemAbility item state;
		strict2=AddDialogItems dialog items;
		=
		[(id, strict1) : strict2];
AddDialogItems dialog [StaticText id layout text : items]
   #!
		strict1=strict1;
		strict2=strict2;
		=
		[(id, strict1) : strict2];
	where {
347
	strict1=add_static_text dialog 0 0 0 0 text;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
348 349 350 351 352 353 354 355 356 357
		strict2=AddDialogItems dialog items;
		
	};
AddDialogItems dialog [DynamicText id itempos width text : items]
   #!
		strict1=strict1;
		strict2=strict2;
		=
		[(id, strict1) : strict2];
	where {
358
	strict1=add_static_text dialog 0 0 (ConvertMeasureX width) 0 text;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
359 360 361 362 363 364 365 366 367 368
		strict2=AddDialogItems dialog items;
		
	};
AddDialogItems dialog [EditText id layout width lines text : items]
   #!
		strict1=strict1;
		strict2=strict2;
		=
		[(id, strict1) : strict2];
	where {
369
		strict1=add_edit_text dialog 0 0 (ConvertMeasureX width) 0 lines text;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
370 371 372 373 374 375
		strict2=AddDialogItems dialog items;
		
	};
AddDialogItems dialog [DialogPopUp id layout state rid radios : items]
   #  rid`    = CheckDefaultRadioId rid radios; 
   #!
376
      popup   = add_dialog_popup dialog 0 0 0 0;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
377
      popup`=SetDialogItemAbility popup state;
378
      radios` = AddDialogRadioItems (get_popup_ex popup`) dialog rid` radios;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
379 380 381 382 383 384 385 386 387 388 389
      radios``= CorrectPopupSize radios` popup`;
		strict2=(AddDialogItems dialog items);
		strict1=Concat radios`` strict2;
		=
		[(id, popup`) :
        strict1];
AddDialogItems dialog [RadioButtons id layout roc rid radios : items]
   #  rid`     = CheckDefaultRadioId rid radios; 
   #!	strict3=ConvertROC roc;
   #
      (roc`, n)= strict3;
390
   #! group    = add_dialog_exclusives dialog 0 0 0 0 roc` n;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
391 392 393 394 395 396 397 398 399
   #! radios`  = AddDialogRadioItems group dialog rid` radios;
      strict2=(AddDialogItems dialog items);
		strict1=Concat radios` strict2;
		=
		[(id, group) : strict1];
AddDialogItems dialog [CheckBoxes id layout roc checks : items]
   #!	strict3=ConvertROC roc;
   #  (roc`, n)= strict3;
   #!
400
      group    = add_dialog_nonexclusives dialog 0 0 0 0 roc` n;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
401 402 403 404 405 406 407 408 409 410 411 412 413
      checks`  = AddDialogCheckItems group dialog checks;
      strict2=(AddDialogItems dialog items);
		strict1=Concat checks` strict2;
		=
		[(id, group) : strict1];
AddDialogItems dialog [Control id layout ((x0,y0),(x1,y1)) state cstate
                                  look feel f : items]
   #!
		strict1=strict1;
		control=control;
		=
		[(id, control) : strict1];
      where {
414
      control=: add_dialog_control dialog 0 0 width height x0 y0 XCControl;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
415 416 417 418 419 420 421 422 423 424 425 426
      width  =: x1 - x0;
      height =: y1 - y0;
      strict1=AddDialogItems dialog items;
		};
AddDialogItems dialog [DialogIconButton id pos ((x0,y0),(x1,y1)) look state f
                         : items]
   #!
		strict1=strict1;
		control=control;
		=
		[(id, control) : strict1];
      where {
427
      control=: add_dialog_control dialog 0 0 width height x0 y0 XCIcon;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
      width  =: x1 - x0;
      height =: y1 - y0;
      strict1=AddDialogItems dialog items;
		};
AddDialogItems dialog [] =  [];

ConvertROC :: !RowsOrColumns -> (!Int, !Int);
ConvertROC (Rows r)    =  (XGroupRows, r);
ConvertROC (Columns c) =  (XGroupColumns, c);

ConvertMark :: !MarkState -> Int;
ConvertMark Mark   =  XMarkOn;
ConvertMark NoMark =  XMarkOff;

SetDialogItemAbility :: !Widget !SelectState -> Widget;
443 444
SetDialogItemAbility w Able =  enable_dialog_item w;
SetDialogItemAbility w Unable =  disable_dialog_item w;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
445 446 447

CorrectPopupSize :: ![XDItemHandle] !Widget -> [XDItemHandle];
CorrectPopupSize radios popup 
448
   =  Evaluate_2 radios (correct_popup_size popup);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464

CheckDefaultRadioId :: !Id ![RadioItemDef s io] -> Id;
CheckDefaultRadioId rid radios=:[RadioItem id t s f : rest`]
   =  CheckDefaultRadioId` rid id radios;
CheckDefaultRadioId rid [] =  rid;

CheckDefaultRadioId` :: !Id !Id ![RadioItemDef s io] -> Id;
CheckDefaultRadioId` rid first [RadioItem id t s f : radios]
   | id == rid =  rid;
   =  CheckDefaultRadioId` rid first radios;
CheckDefaultRadioId` rid first [] =  first;

AddDialogRadioItems :: !Widget !Widget !Id ![RadioItemDef s io]
   -> [XDItemHandle];
AddDialogRadioItems group dialog rid [RadioItem id title state f : radios]
   | id == rid #!
465
      radio1=  add_dialog_radiob group dialog title XMarkOn;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
466 467 468 469 470
		strict1=SetDialogItemAbility radio1 state;
	#!	radios`=radios`;
		=
		[(id, strict1) : radios`];
   #!
471
      radio2=  add_dialog_radiob group dialog title XMarkOff;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
      strict3=SetDialogItemAbility radio2 state;
	#!	radios`=radios`;
		=
		[(id, strict3) : radios`];
      where {
      radios`=: AddDialogRadioItems group dialog rid radios;
		};
AddDialogRadioItems g d rid [] =  [];

AddDialogCheckItems :: !Widget !Widget ![CheckBoxDef s io]
   -> [XDItemHandle];
AddDialogCheckItems group dialog [CheckBox id title state mark f : radios]
   #!
		strict1=strict1;
		check=check;
		checks=checks;
		=
		[(id, strict1) : checks];
      where {
491
      check=:  add_dialog_checkb group dialog title (ConvertMark mark);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
492 493 494 495 496 497 498 499 500 501 502
      checks=: AddDialogCheckItems group dialog radios;
      strict1=SetDialogItemAbility check state;
		};
AddDialogCheckItems g d [] =  [];

DoModalDialog	:: !*s !(IOState *s) -> (!*s, !IOState *s);
DoModalDialog s io
	| not active || dev <> XDialogDevice =  (s,io`);
	| not the_one =  DoModalDialog s  io`;
	=  DoModalDialog s` io``;
		where {
503
		(s`,io``)                  =: DialogIO` [dialog] (get_dialog_event e) s io`;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
		(active,the_one,dialog,io`)=: GetActiveModalDialogHandle w io;
		(w,dev,e)                  =: GetNextEvent;
		};

GetActiveModalDialogHandle	:: !Int !(IOState s)
	-> (!Bool, !Bool, !DialogHandle s (IOState s), !IOState s);
GetActiveModalDialogHandle widget io =  (active,the_one,handle,io`);
		where {
		(active,the_one,handle)=: GetActiveModalFromDevice widget device;
		(device,io`)           =: IOStateGetDevice io DialogDevice;
		};

GetActiveModalFromDevice	:: !Int !(DeviceSystemState s)
	                         -> (!Bool, !Bool, !DialogHandle s (IOState s));
GetActiveModalFromDevice widget (DialogSystemState dialogs)
	=  GetActiveModalDialog False widget dialogs;

GetActiveModalDialog	:: !Bool !Int ![DialogHandle s (IOState s)]
	                         -> (!Bool, !Bool, !DialogHandle s (IOState s));
GetActiveModalDialog modal widget [active=:DialHandle Modal (i,w) b d : rest]
	| w == widget =  (True,True,active);
	=  GetActiveModalDialog True widget rest;
GetActiveModalDialog modal widget [active : rest]
	=  GetActiveModalDialog modal widget rest;
GetActiveModalDialog modal widget [] =  (modal, False, DummyDialHandle);

DialogIO :: !Event !*s !(IOState *s) -> (!Bool, !*s, !IOState *s);
DialogIO (w, XDialogDevice, e) s io_state
   #!
533
      strict2=get_dialog_event e;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
      strict3=GetDialogHandle io_state w;
   #  (dialog,io``)= strict3;
   #! strict1=DialogIO` dialog (strict2) s io``;
   #  (s`, io`)= strict1;
		=
		(True, s`, io`);
DialogIO no_dialog_event s io_state =  (False, s, io_state);

DialogIO` :: ![DialogHandle *s (IOState *s)] !DialogEvent !*s !(IOState *s)
   -> (!*s, !IOState *s);
DialogIO` [dialog] event s io
   =  DialogIO`` (ReconstructDialogHandle dialog) event s io;
DialogIO` [] event s io =  (s, io);

DialogIO`` :: !(DialogHandle *s (IOState *s)) !DialogEvent !*s !(IOState *s)
   -> (!*s, !IOState *s);
DialogIO`` (DialHandle m (id,w) items def) (XDialogButton, item) s io
   =  f (DDef2DInfo def) s io;
      where {
      f=: GetButtonFunction (GetDialogItemId item items) def;
      };
DialogIO`` (DialHandle m (id,w) items def) (XDialogClosed, item) s io
   #!
		strict1=strict1;
		=
559
		UEvaluate_2 (s,strict1) (destroy_dialog w);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606
	where {
	strict1=RemoveDialogHandle w io;
		
	};
DialogIO`` h=:(DialHandle m (id,w) items def) (XDialogRadioButton, item) s io
   #!
		dstate=dstate;
		=
		(s, ChangeDialogHandle id (DState2DHandle dstate) io);
      where {
      dstate=: f (DDef2DInfo def) (DHandle2DState h);
      f=: GetDialogRadioFunction (GetDialogItemId item items) def;
      };
DialogIO`` h=:(DialHandle m (id,w) items def) (XDialogCheckButton, item) s io
   #!
		dstate=dstate;
		=
		(s, ChangeDialogHandle id (DState2DHandle dstate) io);
      where {
      dstate=: f (DDef2DInfo def) (DHandle2DState h);
      f=: GetDialogCheckFunction (GetDialogItemId item items) def;
      };
DialogIO`` (DialHandle m (id,w) items def) (XDialogRedraw, item) s io
   #!
		drawfs=drawfs;
		=
		(s, DrawInControl item (Concat (PictureNormal pic) drawfs) io);
      where {
      drawfs=: f state cs;
      (state,f,cs,pic)=: GetDialogControlLook (GetDialogItemId item items) def;
      }; 
DialogIO`` (DialHandle m (id,w) items def) (XDialogIRedraw, item) s io
   #!
		drawfs=drawfs;
		=
		(s, DrawInControl item (Concat (PictureNormal pic) drawfs) io);
      where {
      drawfs=: f able;
      (able,f,pic)=: GetDialogIconLook (GetDialogItemId item items) def;
      };
DialogIO`` handle=:(DialHandle m (id,w) items def) (XDialogMouse, item) s io
   #!
	      cid= GetDialogItemId item items;
   #  (able,f,cs)= GetDialogControlFeel cid def;
   | able
		#!	cs=cs;
	      cid= GetDialogItemId item items;
607
	      mouse=EventToMouse (get_mouse_state item);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
		#  (cs`, drawfs)= f mouse cs;
		#! drawfs=drawfs;
		   cs`=cs`;
		#  f2= GetDialogControlFunction cid def;
	   #!
	      io`= DrawInControl item (Concat PictureNormalF drawfs) io;
	      handle`= ChangeControlState handle cid cs`;
	      strict5=DHandle2DState handle`;
	      dstate= f2 (DDef2DInfo def) (strict5);
		  strict2=DState2DHandle dstate;
		  strict1=ChangeDialogHandle id (strict2) io`;
		=
		(s, strict1);
		=
		(s, io);
DialogIO`` handle=:(DialHandle m (id,w) items def) (XDialogIMouse, item) s io
   =  HandleIconSelection items def item mouse s io;
      where {
626
      mouse=: EventToMouse (get_mouse_state item);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685
      };
DialogIO`` (DialHandle m (id,w) items def) (XDialogApply, item) s io
   =  f (DDef2DInfo def) s io;
      where {
      f=: GetDialogApplyFunction def;
      };
DialogIO`` (DialHandle m (id,w) items def) (XDialogReset, item) s io
   =  f (DDef2DInfo def) s io;
      where {
      f=: GetDialogResetFunction def;
      };
DialogIO`` dialog (XDialogActivate, item) s io
   #!
		strict1=strict1;
		=
		(s, strict1);
	where {
	strict1=MakeActiveDialog dialog io;
		
	};
DialogIO`` (DialHandle m (id,w) items (AboutDialog appname pic dfs help))
              (XAboutRedraw, item) s io
   =  (s, DrawInControl w (Concat (PictureNormal pic) dfs) io);
DialogIO`` (DialHandle m (id,w) items def=:(AboutDialog a p d (AboutHelp h f)))
              (XAboutHelp, item) s io
   =  f s io;

HandleIconSelection :: ![XDItemHandle] !(DialogDef *s (IOState *s)) !Widget
      !MouseState !*s !(IOState *s)
	-> (!*s, !IOState *s);
HandleIconSelection items def w (x,ButtonDown,m) state io
   | able =  (state, DrawInControl w [InvertRectangle pic] io);
   =  (state, io);
      where {
      (able,f,pic)=: GetDialogIconFunction (GetDialogItemId w items) def;
      };
HandleIconSelection items def w (x,ButtonUp,m) state io
   | able #!
		io`=io`;
		=
		f (DDef2DInfo def) state io`;
   #!
		io`=io`;
		=
		(state,io); 
      where {
      io`=: DrawInControl w [InvertRectangle pic] io;
      (able,f,pic)=: GetDialogIconFunction (GetDialogItemId w items) def;
      };
HandleIconSelection items def w mouse state io
   =  (state, io);

DrawInControl :: !Widget ![DrawFunction] !(IOState s) -> IOState s;
DrawInControl control dfs io
   #!
		strict1=strict1;
		=
		UEvaluate_2 io (Draw_in_window (1,strict1) (0,0) dfs);
	where {
686
	strict1=NewXPicture (dialog_item_to_object control);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910
		
	};

// IsModalDialog !(DialogDef s (IOState s)) -> BOOL;
// IsModalDialog (CommandDialog id t Modal a di i) -> TRUE;
// IsModalDialog def -> FALSE;

GetDialogItemId :: !Widget ![XDItemHandle] -> Id;
GetDialogItemId w [(id, w`) : items]
   | w == w` =  id;
   =  GetDialogItemId w items;
GetDialogItemId w [] =  0;

GetButtonFunction :: !Id !(DialogDef s (IOState s))
   -> ButtonFunction s (IOState s);
GetButtonFunction id (CommandDialog did t a di items)
   =  GetButtonFunction` id items;
GetButtonFunction id (PropertyDialog i t a f1 f2 items)
   =  GetButtonFunction` id items;

GetButtonFunction` :: !Id ![DialogItem s (IOState s)]
   -> ButtonFunction s (IOState s);
GetButtonFunction` id [DialogButton id2 l t s f : items]
   | id == id2 =  f;
   =  GetButtonFunction` id items;
GetButtonFunction` id [item : items]
   =  GetButtonFunction` id items;

GetDialogRadioFunction :: !Id !(DialogDef s (IOState s))
   -> DialogFunction s (IOState s);
GetDialogRadioFunction id (CommandDialog did t a di items)
   =  GetDialogRadioFunction` id items;
GetDialogRadioFunction id (PropertyDialog i t a f1 f2 items)
   =  GetDialogRadioFunction` id items;

GetDialogRadioFunction` :: !Id ![DialogItem s (IOState s)]
   -> DialogFunction s (IOState s);
GetDialogRadioFunction` id [RadioButtons id2 l roc did radios : items]
   | found =  f;
   =  GetDialogRadioFunction` id items;
      where {
      (f, found)=: GetDialogRadioFunction`` id radios;
      };
GetDialogRadioFunction` id [DialogPopUp id2 l able did radios : items]
   | found =  f;
   =  GetDialogRadioFunction` id items;
      where {
      (f, found)=: GetDialogRadioFunction`` id radios;
      };
GetDialogRadioFunction` id [item : items]
   =  GetDialogRadioFunction` id items;

GetDialogRadioFunction`` :: !Id ![RadioItemDef s (IOState s)]
   -> (!DialogFunction s (IOState s), !Bool);
GetDialogRadioFunction`` id [RadioItem id2 t s f : radios]
   | id == id2 =  (f, True);
   =  GetDialogRadioFunction`` id radios;
GetDialogRadioFunction`` id radios =  (EmptyDialogFunc, False);

GetDialogCheckFunction :: !Id !(DialogDef s (IOState s))
   -> DialogFunction s (IOState s);
GetDialogCheckFunction id (CommandDialog did t a di items)
   =  GetDialogCheckFunction` id items;
GetDialogCheckFunction id (PropertyDialog i t a f1 f2 items)
   =  GetDialogCheckFunction` id items;

GetDialogCheckFunction` :: !Id ![DialogItem s (IOState s)]
   -> DialogFunction s (IOState s);
GetDialogCheckFunction` id [CheckBoxes id2 l roc checks : items]
   | found =  f;
   =  GetDialogCheckFunction` id items;
      where {
      (f, found)=: GetDialogCheckFunction`` id checks;
      };
GetDialogCheckFunction` id [item : items]
   =  GetDialogCheckFunction` id items;

GetDialogCheckFunction`` :: !Id ![CheckBoxDef s (IOState s)]
   -> (!DialogFunction s (IOState s), !Bool);
GetDialogCheckFunction`` id [CheckBox id2 t s m f : checks]
   | id == id2 =  (f, True);
   =  GetDialogCheckFunction`` id checks;
GetDialogCheckFunction`` id checks =  (EmptyDialogFunc, False);

GetDialogControlFunction :: !Id !(DialogDef s (IOState s))
   -> DialogFunction s (IOState s);
GetDialogControlFunction id (CommandDialog did t a di items)
   =  GetDialogControlFunction` id items;
GetDialogControlFunction id (PropertyDialog i t a f1 f2 items)
   =  GetDialogControlFunction` id items; 

GetDialogControlFunction` :: !Id ![DialogItem s (IOState s)]
   -> DialogFunction s (IOState s);
GetDialogControlFunction` id [Control id` pos pic sel cs look feel f : items]
   | id == id` =  f;
   =  GetDialogControlFunction` id items;
GetDialogControlFunction` id [item : items]
   =  GetDialogControlFunction` id items;

EmptyDialogFunc :: !DialogInfo (DialogState s (IOState s))
   -> DialogState s (IOState s);
EmptyDialogFunc def ds =  ds;

GetDialogApplyFunction :: !(DialogDef s (IOState s))
   -> ButtonFunction s (IOState s);
GetDialogApplyFunction (PropertyDialog i t a f f1 is) =  f;

GetDialogResetFunction :: !(DialogDef s (IOState s))
   -> ButtonFunction s (IOState s);
GetDialogResetFunction (PropertyDialog i t a f1 f is) =  f;

GetDialogControlLook ::  !Id !(DialogDef s (IOState s))
   -> (!SelectState,!ControlLook, !ControlState, !PictureDomain);
GetDialogControlLook id (CommandDialog did t a di items)
   =  GetDialogControlLook` id items;
GetDialogControlLook id (PropertyDialog i t a f1 f2 items)
   =  GetDialogControlLook` id items;

GetDialogControlLook` :: !Id ![DialogItem s (IOState s)]
   -> (!SelectState,!ControlLook, !ControlState, !PictureDomain);
GetDialogControlLook` id [Control id2 l pic s cs look feel f : items]
   | id == id2 =  (s,look,cs,pic);
   =  GetDialogControlLook` id items;
GetDialogControlLook` id [item : items]
   =  GetDialogControlLook` id items;

GetDialogControlFeel ::  !Id !(DialogDef s (IOState s))
   -> (!Bool,!ControlFeel, !ControlState);
GetDialogControlFeel id (CommandDialog did t a di items)
   =  GetDialogControlFeel` id items;
GetDialogControlFeel id (PropertyDialog i t a f1 f2 items)
   =  GetDialogControlFeel` id items;

GetDialogControlFeel` :: !Id ![DialogItem s (IOState s)]
   -> (!Bool,!ControlFeel, !ControlState);
GetDialogControlFeel` id [Control id2 pic l Able cs look feel f : items]
   | id == id2 =  (True,feel, cs);
   =  GetDialogControlFeel` id items;
GetDialogControlFeel` id [item : items]
   =  GetDialogControlFeel` id items;
GetDialogControlFeel` id items
   =  (False,EmptyControlFeel, IntCS 0);

GetDialogIconLook :: !Id !(DialogDef s (IOState s))
   -> (!SelectState,!IconLook, !PictureDomain);
GetDialogIconLook id (CommandDialog did t a di items)
   =  GetDialogIconLook` id items;
GetDialogIconLook id (PropertyDialog i t a f1 f2 items)
   =  GetDialogIconLook` id items;

GetDialogIconLook` :: !Id ![DialogItem s (IOState s)]
   -> (!SelectState,!IconLook, !PictureDomain);
GetDialogIconLook` id [DialogIconButton id2 pos pic look able f : items]
   | id == id2 =  (able,look,pic);
   =  GetDialogIconLook` id items;
GetDialogIconLook` id [item:items] =  GetDialogIconLook` id items; 

GetDialogIconFunction :: !Id !(DialogDef s (IOState s))
   -> (!Bool,!ButtonFunction s (IOState s),!PictureDomain);
GetDialogIconFunction id (CommandDialog did t a di items)
   =  GetDialogIconFunction` id items;
GetDialogIconFunction id (PropertyDialog i t a f1 f2 items)
   =  GetDialogIconFunction` id items;

GetDialogIconFunction` :: !Id ![DialogItem s (IOState s)]
   -> (!Bool, !ButtonFunction s (IOState s), !PictureDomain);
GetDialogIconFunction` id [DialogIconButton id2 pos pic look able f : items]
   | id == id2 =  (Enabled able,f,pic);
   =  GetDialogIconFunction` id items;
GetDialogIconFunction` id [item:items] =  GetDialogIconFunction` id items; 

GetCommandDefaultItem :: !Id ![XDItemHandle] -> Widget;
GetCommandDefaultItem id [(id2,w)] =  w;
GetCommandDefaultItem id [(id2,w) : items]
   | id == id2 =  w;
   =  GetCommandDefaultItem id items;

EmptyControlFeel :: MouseState ControlState -> (ControlState,[DrawFunction]);
EmptyControlFeel m cs =  (cs,[]);

ReconstructDialogHandle :: !(DialogHandle s (IOState s))
   -> DialogHandle s (IOState s);
ReconstructDialogHandle (DialHandle m h items def)
   #!
		strict1=strict1;
		=
		DialHandle m h items (strict1);
	where {
	strict1=ReconstructDialog def items;
		
	};

ReconstructDialog :: !(DialogDef s (IOState s)) ![XDItemHandle]
   -> DialogDef s (IOState s);
ReconstructDialog (CommandDialog id t a d items) handles
   #!
		strict1=strict1;
		=
		CommandDialog id t a d (strict1);
	where {
	strict1=ReconstructDialog` items handles;
		
	};
ReconstructDialog (PropertyDialog id t a f1 f2 items) handles
   #!
		strict1=strict1;
		=
		PropertyDialog id t a f1 f2 (strict1);
	where {
	strict1=ReconstructDialog` items handles;
		
	};
ReconstructDialog def=:(AboutDialog appname pic dfs help) handles
   =  def;

ReconstructDialog` :: ![DialogItem s (IOState s)] ![XDItemHandle]
   -> [DialogItem s (IOState s)];
ReconstructDialog` [EditText id l w nl text : items] handles
   #!
		strict1=strict1;
		text`=text`;
		=
		[EditText id l w nl text` : strict1];
      where {
911
      text`=: get_edit_text (GetDialogWidget id handles);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955
      strict1=ReconstructDialog` items handles;
		};
ReconstructDialog` [RadioButtons id l roc did radios : items] handles
   #!
      strict1=ReconstructDialog` items handles;
		strict2=ReconstructRadioButtons radios handles;
   #  (did`, radios`)= strict2;
		=
		[RadioButtons id l roc did` radios` :
                  strict1];
ReconstructDialog` [DialogPopUp id l able did radios : items] handles
   #!
		strict1=strict1;
		=
		[DialogPopUp id l able did` radios` :
                  strict1];
      where {
      (did`, radios`)=: ReconstructRadioButtons radios handles;
      strict1=ReconstructDialog` items handles;
		};
ReconstructDialog` [CheckBoxes id l roc checks : items ] handles
   #!
		strict1=strict1;
		checks`=checks`;
		=
		[CheckBoxes id l roc checks` : strict1];
      where {
      checks`=: ReconstructCheckBoxes checks handles;
      strict1=ReconstructDialog` items handles;
		};
ReconstructDialog` [item : items] [handle : handles]
   #!
		strict1=strict1;
		=
		[item : strict1];
	where {
	strict1=ReconstructDialog` items handles;
		
	};
ReconstructDialog` items handles =  items;

ReconstructRadioButtons :: ![RadioItemDef s (IOState s)] ![XDItemHandle]
   -> (!Id, ![RadioItemDef s (IOState s)]);
ReconstructRadioButtons [radio=:RadioItem id t state f : radios] handles
956
   | IsMark (get_mark (GetDialogWidget id handles)) =  (id, [radio : radios]);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
957 958 959 960 961 962 963 964 965 966 967 968 969 970
   #!
      strict2=ReconstructRadioButtons radios handles;
   #  (id`, radios`)= strict2;
   #!
		radios`=radios`;
		strict2=strict2;
		=
		(id`, [radio : radios`]);
ReconstructRadioButtons radios handles =  (0,radios);

ReconstructCheckBoxes :: ![CheckBoxDef s (IOState s)] ![XDItemHandle]
   -> [CheckBoxDef s (IOState s)];
ReconstructCheckBoxes [CheckBox id t state mark f : checks] handles
   #!
971
      xmark= get_mark (GetDialogWidget id handles);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100
   | IsMark xmark #!
		checks`=checks`;
		=
		 [CheckBox id t state Mark f : checks`];
   #!
		checks`=checks`;
		=
		[CheckBox id t state NoMark f : checks`];
      where {
      checks`=: ReconstructCheckBoxes checks handles;
      };
ReconstructCheckBoxes checks handles =  checks;

ChangeControlState :: !(DialogHandle s (IOState s)) !Id !ControlState
   -> DialogHandle s (IOState s);
ChangeControlState (DialHandle m (id, w) items def) cid cs
   #!
		def`=def`;
		=
		DialHandle m (id, w) items def`;
      where {
      def`=: ChangeControlState` def cid cs;
      };

ChangeControlState` :: !(DialogDef s (IOState s)) !Id !ControlState
   -> DialogDef s (IOState s);
ChangeControlState` (CommandDialog did t a di items) cid cs
   #!
		strict1=strict1;
		=
		CommandDialog did t a di (strict1);
	where {
	strict1=ChangeControlState`` items cid cs;
		
	};
ChangeControlState` (PropertyDialog i t a f1 f2 items) cid cs
   #!
		strict1=strict1;
		=
		PropertyDialog i t a f1 f2 (strict1);
	where {
	strict1=ChangeControlState`` items cid cs;
		
	};

ChangeControlState`` :: ![DialogItem s (IOState s)] !Id !ControlState
   -> [DialogItem s (IOState s)];
ChangeControlState`` [item=:Control id l p s cs look feel f: items] cid cs`
   | id == cid =  [Control id l p s cs` look feel f: items];
   #!
		strict1=strict1;
		=
		[item : strict1];
	where {
	strict1=ChangeControlState`` items cid cs`;
		
	};
ChangeControlState`` [item :items] cid cs 
   #!
		strict1=strict1;
		=
		[item : strict1];
	where {
	strict1=ChangeControlState`` items cid cs;
		
	};
ChangeControlState`` items cid cs =  items;

IsMark :: !Int -> Bool;
IsMark XMarkOn  =  True;
IsMark XMarkOff =  False;

GetDialogWidget :: !Id ![XDItemHandle] -> Widget;
GetDialogWidget id [(id2,w): handles]
   | id == id2 =  w;
   =  GetDialogWidget id handles;

GetDialogHandle :: !(IOState s) !Widget 
   -> (![DialogHandle s (IOState s)], !IOState s);
GetDialogHandle io w
   =  (dialog, io`);
      where {
      dialog       =: GetDialogHandle` device w;
      (device, io`)=: IOStateGetDevice io DialogDevice;
      };

GetDialogHandle` :: !(DeviceSystemState s) !Widget
   -> [DialogHandle s (IOState s)];
GetDialogHandle` (DialogSystemState dialogs) w
   =  GetDialogHandle`` dialogs w;

GetDialogHandle`` :: !(DialogHandles s (IOState s)) !Widget
   -> [DialogHandle s (IOState s)];
GetDialogHandle`` [handle=: DialHandle m (id, w`) b d : dialogs] w
   | w == w` =  [handle];
   =  GetDialogHandle`` dialogs w;
GetDialogHandle`` dialogs w =  dialogs;

GetDialogHandleFromId :: !(IOState s) !Id
   -> (![DialogHandle s (IOState s)], !IOState s);
GetDialogHandleFromId io id
   =  (dialog, io`);
      where {
      dialog       =: GetDialogHandleFromId` device id;
      (device, io`)=: IOStateGetDevice io DialogDevice;
      };

GetDialogHandleFromId` :: !(DeviceSystemState s) !Id
   -> [DialogHandle s (IOState s)];
GetDialogHandleFromId` (DialogSystemState dialogs) id
   =  GetDialogHandleFromId`` dialogs id;

GetDialogHandleFromId`` :: !(DialogHandles s (IOState s)) !Id
   -> [DialogHandle s (IOState s)];
GetDialogHandleFromId`` [handle=: DialHandle m (id`, w) b d : dialogs] id
   | id == id` =  [handle];
   =  GetDialogHandleFromId`` dialogs id;
GetDialogHandleFromId`` dialogs id =  dialogs;

DialogNotOpen :: !(DialogDef s (IOState s)) !(DialogHandles s (IOState s))
   -> Bool;
DialogNotOpen (CommandDialog id t a did items) dialogs
   =  DialogNotOpen` (GetDialogHandleFromId`` dialogs id);
DialogNotOpen (PropertyDialog id t a f1 f2 items) dialogs
   =  DialogNotOpen` (GetDialogHandleFromId`` dialogs id);

DialogNotOpen` :: ![DialogHandle s (IOState s)] -> Bool;
DialogNotOpen` [] =  True;
DialogNotOpen` [DialHandle m (id,w) items def : rest]
1101
   =  Evaluate_2 False (activate_dialog w);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245

MakeActiveDialog :: !(DialogHandle s (IOState s)) !(IOState s) -> IOState s;
MakeActiveDialog dialog io_state
   =  IOStateSetDevice io_state` device`;
      where {
      device`            =: MakeActiveDialog` dialog device;
      (device, io_state`)=: IOStateGetDevice io_state DialogDevice;
      };

MakeActiveDialog` :: !(DialogHandle s (IOState s)) !(DeviceSystemState s)
   -> DeviceSystemState s;
MakeActiveDialog` dialog=: (DialHandle m (id,w) items def)
                     (DialogSystemState dialogs)
   #!
		strict1=strict1;
		=
		DialogSystemState [dialog : strict1];
	where {
	strict1=RemoveDialogHandle`` w dialogs;
		
	};

RemoveDialogHandle :: !Widget !(IOState s) -> IOState s;
RemoveDialogHandle w io_state
   =  IOStateSetDevice io_state` device`;
      where {
      device`            =: RemoveDialogHandle` w device;
      (device, io_state`)=: IOStateGetDevice io_state DialogDevice;
      };

RemoveDialogHandle` :: !Widget !(DeviceSystemState s) -> DeviceSystemState s;
RemoveDialogHandle` w (DialogSystemState dialogs)
   #!
		strict1=strict1;
		=
		DialogSystemState strict1;
	where {
	strict1=(RemoveDialogHandle`` w dialogs);
		
	};

RemoveDialogHandle`` :: !Widget !(DialogHandles s (IOState s))
   -> DialogHandles s (IOState s);
RemoveDialogHandle`` w [handle=: DialHandle m (id, w`) b d : dialogs]
   | w == w` =  dialogs;
   #!
		strict1=strict1;
		=
		[handle : strict1];
	where {
	strict1=RemoveDialogHandle`` w dialogs;
		
	};
RemoveDialogHandle`` w dialogs =  dialogs;

ChangeDialogHandle :: !Id !(DialogHandle s (IOState s)) !(IOState s) -> IOState s;
ChangeDialogHandle id handle io_state
   =  IOStateSetDevice io_state` dialog`;
      where {
      dialog`           =: ChangeDialogHandle` id handle dialog;
      (dialog,io_state`)=: IOStateGetDevice io_state DialogDevice;
      };

ChangeDialogHandle` :: !Id !(DialogHandle s (IOState s)) !(DeviceSystemState s)
   -> DeviceSystemState s;
ChangeDialogHandle` id handle (DialogSystemState dialogs)
   #!
		strict1=strict1;
		=
		DialogSystemState strict1;
	where {
	strict1=(ChangeDialogHandle`` id handle dialogs);
		
	};

ChangeDialogHandle`` :: !Id !(DialogHandle s (IOState s)) 
      ![DialogHandle s (IOState s)] 
   -> [DialogHandle s (IOState s)];
ChangeDialogHandle`` id handle [handle`=: DialHandle m (id`, w) i d : dialogs]
   | id == id` =  [handle : dialogs];
   #!
		strict1=strict1;
		=
		[handle`: strict1];
	where {
	strict1=ChangeDialogHandle`` id handle dialogs;
		
	}; 
ChangeDialoghandle`` id handle dialogs =  dialogs;


/* Functions used for parsing and installing the layout hints.
*/

    

:: Rect :== (!Int,!Int,!Int,!Int);
:: ItemLayout :== (!XDItemHandle, !Rect, !ItemPos, ![(!XDItemHandle, !Rect)]);


     

VerticalSep    :== 10;
HorizontalSep  :== 6;

RefOk          :== 1;
RefFalse       :== 2;
RefCenter      :== 3;
RefRight       :== 4;


    

PositionItems :: !Widget ![DialogAttribute] ![DialogItem s io] ![XDItemHandle]
   -> [XDItemHandle];
PositionItems dialog att items handles
   =  Evaluate_2 handles (RepositionCItems dialog margins itemlayouts``);
      where {
      (marginx,marginy)=: margins;
      itemlayouts``=: RepositionItems itemlayouts`;
      (height,itemlayouts`) =: LayoutPass2 margins spaces 0 [] itemlayouts;
      margins      =: GetDialogMargins att;
      spaces       =: GetDialogItemSpaces att;
      itemlayouts  =: MakeItemLayouts items handles;
      };


GetDialogMargins :: ![DialogAttribute] -> (!Int,!Int);
GetDialogMargins [DialogMargin x y : rest]
   =  (ConvertMeasureX x, ConvertMeasureY y);
GetDialogMargins [att : rest] =  GetDialogMargins rest;
GetDialogMargins atts =  (HorizontalSep, VerticalSep);

GetDialogItemSpaces :: ![DialogAttribute] -> (!Int,!Int);
GetDialogItemSpaces [ItemSpace x y : rest]
   =  (ConvertMeasureX x, ConvertMeasureY y);
GetDialogItemSpaces [att : rest] =  GetDialogItemSpaces rest;
GetDialogItemSpaces atts =  (HorizontalSep, VerticalSep);

MakeItemLayouts :: ![DialogItem s io] ![XDItemHandle] -> [ItemLayout];
MakeItemLayouts [DialogButton id pos t s f : items] handles
   #!
		strict1=strict1;
		=
1246
		[(handle, get_current_rect w, pos, []) : strict1];
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1247 1248 1249 1250 1251 1252 1253 1254 1255
      where {
      (handle, handles`)=: GetXDItemHandle id handles;
      (id`,w)=: handle;
      strict1=MakeItemLayouts items handles`;
		};
MakeItemLayouts [DialogIconButton id pos p l s f : items] handles
   #!
		strict1=strict1;
		=
1256
		[(handle, get_current_rect w, pos, []) : strict1];
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1257 1258 1259 1260 1261 1262 1263 1264 1265
      where {
      (handle, handles`)=: GetXDItemHandle id handles;
      (id`,w)=: handle;
      strict1=MakeItemLayouts items handles`;
		};
MakeItemLayouts [StaticText id pos s : items] handles
   #!
		strict1=strict1;
		=
1266
		[(handle, get_current_rect w, pos, []) : strict1];
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1267 1268 1269 1270 1271 1272 1273 1274 1275
      where {
      (handle, handles`)=: GetXDItemHandle id handles;
      (id`,w)=: handle;
      strict1=MakeItemLayouts items handles`;
		};
MakeItemLayouts [DynamicText id pos width s : items] handles
   #!
		strict1=strict1;
		=
1276
		[(handle, get_current_rect w, pos, []) : strict1];
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1277 1278 1279 1280 1281 1282 1283 1284 1285
      where {
      (handle, handles`)=: GetXDItemHandle id handles;
      (id`,w)=: handle;
      strict1=MakeItemLayouts items handles`;
		};
MakeItemLayouts [EditText id pos wi n s : items] handles
   #!
		strict1=strict1;
		=
1286
		[(handle, get_current_rect w, pos, []) : strict1]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1287 1288 1289 1290 1291 1292 1293 1294 1295
      where {
      (handle, handles`)=: GetXDItemHandle id handles;
      (id`,w)=: handle;
      strict1=MakeItemLayouts items handles`;
		};
MakeItemLayouts [DialogPopUp id pos able did radios : items] handles
   #!
		strict1=strict1;
		=
1296
		[(handle, get_current_rect w, pos, []) :
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306
       strict1];
      where {
      (handle, handles`)=: GetXDItemHandle id handles;
      (id`,w)=: handle;
      strict1=MakeItemLayouts items handles`;
		};
MakeItemLayouts [RadioButtons id pos roc did radios : items] handles
   #!
		strict1=strict1;
		=
1307
		[(handle, get_current_rect w, pos, []) : strict1];
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1308 1309 1310 1311 1312 1313 1314 1315 1316
      where {
      (handle, handles`)=: GetXDItemHandle id handles;
      (id`,w)=: handle;
      strict1=MakeItemLayouts items handles`;
		};
MakeItemLayouts [CheckBoxes id pos roc checks : items] handles
   #!
		strict1=strict1;
		=
1317
		[(handle, get_current_rect w, pos, []) : strict1];
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1318 1319 1320 1321 1322 1323 1324 1325 1326
      where {
      (handle, handles`)=: GetXDItemHandle id handles;
      (id`,w)=: handle;
      strict1=MakeItemLayouts items handles`;
		};
MakeItemLayouts [Control id pos p s cs lo fe f : items] handles
   #!
		strict1=strict1;
		=
1327
		[(handle, get_current_rect w, pos, []) : strict1];
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354
      where {
      (handle, handles`)=: GetXDItemHandle id handles;
      (id`,w)=: handle;
      strict1=MakeItemLayouts items handles`;
		};
MakeItemLayouts [] handles =  [];

GetXDItemHandle :: !Id ![XDItemHandle] -> (!XDItemHandle, ![XDItemHandle]);
GetXDItemHandle id [handle=:(id`,w) : handles]
   | id == id` =  (handle, handles)
   =  (handle`, [handle : handles`])
      where {
      (handle`, handles`)=: GetXDItemHandle id handles;
      };


// Halbe: RepositionItems moet ook items in list 'l' verplaatsen,
//        daarom RepositionCList toegevoegd.

RepositionItems :: ![ItemLayout] -> [ItemLayout];
RepositionItems [item=:((id,widget),(x,y,w,h),pos,l) : items]
   #!
		strict1=strict1;
		strict2=strict2;
		=
		[strict1  : strict2];
      where {
1355
      change=: RepositionCList l (repos_widget widget x y w h);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1356 1357 1358 1359 1360 1361 1362
      strict1=Evaluate_2 item change;
		strict2=RepositionItems items;
		};
RepositionItems items =  items;

RepositionCList :: ![(XDItemHandle,Rect)] !Int -> Int;
RepositionCList [((id,widget),(x,y,w,h)) : rest] c
1363
   =  RepositionCList rest (repos_widget widget x y w h);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536
RepositionCList [] c =  c;

LayoutPass2 :: !(!Int,!Int) !(!Int,!Int) !Int ![ItemLayout] ![ItemLayout]
   -> (!Int, [ItemLayout]);
LayoutPass2 margins spaces cline citems [item=: ((handle, (x,y,w,h), ItemBox x` y` w` h`, [])) : items]=  LayoutPass2 margins spaces cline` 
                  [(handle,(x`,y`,w`,h`),Left,[]) : citems] items;
      where {
      cline`=: NewCurrentLine y` h` cline;
      };
LayoutPass2 margins spaces cline citems [item=: ((handle, (x,y,w,h), XY x` y`, [])) : items]=  LayoutPass2 margins spaces cline`
                  [(handle,(x``,y``,w,h),Left,[]) : citems] items;
      where {
      cline`=: NewCurrentLine y`` h cline;
      x``   =: ConvertMeasureX x`;
      y``   =: ConvertMeasureY y`;
      };
LayoutPass2 margins=: ((marginx,marginy)) spaces=:(spacex,spacey) cline citems [item=: ((handle, (x,y,w,h), Left, [])) : items]=  LayoutPass2 margins spaces (h + y`)
                  [(handle,(marginx,y`,w,h), Left, []) : citems] items;
      where {
      y`=: if (cline == 0) (marginy + cline) (spacey + cline);
      };
LayoutPass2 margins spaces=:(spacex,spacey) cline citems [item=: ((handle, rect=:(x,y,w,h), Below ref, [])) : items]| valid == RefOk =  LayoutPass2 margins spaces cline` 
                  [(handle,(x`,y``,w,h),Left,[]) : citems]
                  items;
   | valid == RefCenter =  LayoutPass2 margins spaces cline`
                  [(handle,(0,y``,w,h),Center,[]) : citems]
                  items;
   | valid == RefRight =  LayoutPass2 margins spaces cline`
                  [(handle,(0,y``,w,h),Right,[]) : citems]
                  items;
   =  LayoutPass2 margins spaces cline citems
                  [(handle, rect, Left, []) : items];
      where {
      (valid, x`, y`, w`, h`)=: GetRefRect citems ref;
      y``=: y` + (spacey + h`);
      cline`=: NewCurrentLine y`` h cline;
      };
LayoutPass2 margins spaces cline citems [item=: ((handle, rect=:(x,y,w,h), YOffset ref yoffset, [])) : items]| valid == RefOk =  LayoutPass2 margins spaces cline`
                  [(handle,(x`,y``,w,h),Left,[]) : citems]
                  items;
   | valid == RefCenter =  LayoutPass2 margins spaces cline` 
                  [(handle,(0,y``,w,h),Center,[]) : citems]
                  items;
   | valid == RefRight =  LayoutPass2 margins spaces cline` 
                  [(handle,(0,y``,w,h),Right,[]) : citems]
                  items;
   =  LayoutPass2 margins spaces cline citems 
                  [(handle, rect, Left, []) : items];
      where {
      (valid, x`, y`, w`, h`)=: GetRefRect citems ref;
      y``=:  y` + h`  +  ConvertMeasureY yoffset ;
      cline`=: NewCurrentLine y`` h cline;
      }; 
LayoutPass2 margins spaces=:(spacex,spacey) cline citems [item=: ((handle, rect=:(x,y,w,h), RightTo ref, [])) : items]| valid == RefOk =  LayoutPass2 margins spaces cline`
                  [(handle,(x``,y`,w,h),Left,[]) : citems]
                  items;
   | (valid == RefCenter) || (valid == RefRight) =  LayoutPass2 margins spaces cline`                           // Halbe: was cline
                  (CenteredRef citems ref handle (x``,y`,w,h))
                  items;
   =  LayoutPass2 margins spaces cline citems
                  [(handle, rect, Left, []) : items];
      where {
      (valid, x`, y`, w`, h`)=: GetRefRect citems ref;
      x``=: x` + (spacex + w`);
      cline`=: NewCurrentLine y` h cline;
      };
LayoutPass2 margins spaces cline citems [item=: ((handle, rect=:(x,y,w,h), XOffset ref xoffset, [])) : items]| valid == RefOk =  LayoutPass2 margins spaces cline` 
                  [(handle,(x``,y`,w,h),Left,[]) : citems]
                  items;
   | (valid == RefCenter) || (valid == RefRight) =  LayoutPass2 margins spaces cline`                           // Halbe: was cline
                  (CenteredRef citems ref handle (x``,y`,w,h))
                  items;
   =  LayoutPass2 margins spaces cline citems 
                  [(handle, rect, Left, []) : items];
      where {
      (valid, x`, y`, w`, h`)=: GetRefRect citems ref;
      x``=:  x` + w`  +  ConvertMeasureX xoffset ;
      cline`=: NewCurrentLine y` h cline;
      };
LayoutPass2 margins spaces=:(spacex,spacey) cline citems [item=: ((handle, rect=:(x,y,w,h), Center, [])) : items]=  LayoutPass2 margins spaces (h + y`) 
                  [(handle,(0,y`,w,h),Center,[]) : citems] items;
      where {
      y`=: cline + spacey;
      };
LayoutPass2 margins spaces=:(spacex,spacey) cline citems [item=: ((handle, rect=:(x,y,w,h), Right, [])) : items]=  LayoutPass2 margins spaces (h + y`)
                  [(handle,(0,y`,w,h),Right,[]) : citems] items;
      where {
      y`=: cline + spacey;
      };
LayoutPass2 (marginx,marginy) spaces cline citems []
   =  (cline + marginy,citems);

GetRefRect :: ![ItemLayout] !Id -> (!Int, !Int, !Int, !Int, !Int);
GetRefRect [((id,widget), (x,y,w,h), Center, l) : items] id`
   | id == id` =  (RefCenter,x,y,w,h);
   | refinlist =  (RefCenter,x`,y`,w`,h`);
   =  GetRefRect items id`;
      where {
      (refinlist, x`, y`, w`, h`)=: GetCenteredRefRect l id`;
      };
GetRefRect [((id,widget), (x,y,w,h), Right, l) : items] id`
   | id == id` =  (RefRight,x,y,w,h);
   | refinlist =  (RefRight,x`,y`,w`,h`);
   =  GetRefRect items id`;
      where {
      (refinlist, x`, y`, w`, h`)=: GetCenteredRefRect l id`;
      };
GetRefRect [((id,widget), (x,y,w,h), pos, l) : items] id`
   | id == id` =  (RefOk,x,y,w,h);
   =  GetRefRect items id`;
GetRefRect [] id` =  (RefFalse,0,0,0,0);

GetCenteredRefRect :: ![(!XDItemHandle, !Rect)] !Id
   -> (!Bool,!Int,!Int,!Int,!Int);
GetCenteredRefRect [((id,widget), (x,y,w,h)) : items] id`
   | id == id` =  (True,x,y,w,h);
   =  GetCenteredRefRect items id`;
GetCenteredRefRect items id =  (False,0,0,0,0);

CenteredRef :: ![ItemLayout] !Id !XDItemHandle !Rect -> [ItemLayout];
CenteredRef [item=:(h=:(id,w),r,Center,l) : citems] ref handle rect
   | ref == id || RefInList ref l =  [(h,r,Center,[(handle,rect) : l]) : citems];
   #!
		strict1=strict1;
		=
		[item : strict1];
	where {
	strict1=CenteredRef citems ref handle rect;
		
	};
CenteredRef [item=:(h=:(id,w),r,Right,l) : citems] ref handle rect
   | ref == id || RefInList ref l =  [(h,r,Right,[(handle,rect) : l]) : citems];
   #!
		strict1=strict1;
		=
		[item : strict1];
	where {
	strict1=CenteredRef citems ref handle rect;
		
	};
CenteredRef [item : citems] ref handle rect 
   #!
		strict1=strict1;
		=
		[item : strict1];
	where {
	strict1=CenteredRef citems ref handle rect;
		
	};

RefInList :: !Id ![(!XDItemHandle, !Rect)] -> Bool;
RefInList id [((id`,w),rect) : items] 
   | id == id` =  True;
   =  RefInList id items;
RefInList id items =  False;

NewCurrentLine :: !Int !Int !Int -> Int;
NewCurrentLine y h cline 
   | newcline > cline =  newcline;
   =  cline;
      where {
      newcline=: y + h;
      };

RepositionCItems :: !Widget !(!Int,!Int) ![ItemLayout] -> [Widget];
RepositionCItems dialog m=:(mx,my) [(handle,rect,Center,l) : items]
   =  Concat (CenterItems mx [(handle,rect):l])
             (RepositionCItems dialog m items);
RepositionCItems dialog m=:(mx,my) [(handle,rect,Right,l) : items]
   =  Concat (RightItems mx [(handle,rect):l])
             (RepositionCItems dialog m items);
RepositionCItems dialog m [item : items] =  RepositionCItems dialog m items;
RepositionCItems dialog (mx,my) []
1537
   =  Evaluate_2 [] (set_dialog_margins dialog mx my);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1538 1539 1540 1541 1542 1543

CenterItems :: !Int ![(!XDItemHandle, !Rect)] -> [Widget];
CenterItems mx l=:[item=: ((id,w),rect) : items]
   =  CenterItems` base l;
      where {
      base=: ( dialogwidth - groupwidth  - (mx + mx)) / 2;
1544
      dialogwidth=: get_father_width w;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1545 1546 1547 1548 1549 1550 1551 1552
      groupwidth=: GetTotalWidth mx l;
      };

RightItems :: !Int ![(!XDItemHandle, !Rect)] -> [Widget];
RightItems mx l=:[item=: ((id,w),rect) : items]
   =  CenterItems` base l;
      where {
      base=:  dialogwidth - groupwidth  - (mx + mx);
1553
      dialogwidth=: get_father_width w;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573
      groupwidth=: GetTotalWidth mx l;
      };

GetTotalWidth :: !Int ![(!XDItemHandle, !Rect)] -> Int;
GetTotalWidth width [(handle, (x,y,w,h)) : items]
   | width` > width =  GetTotalWidth width` items;
   =  GetTotalWidth width items;
      where {
      width`=: x + w;
      };
GetTotalWidth width items =  width;

CenterItems` :: !Int ![(!XDItemHandle, !Rect)] -> [Widget];
CenterItems` base [((id,widget),(x,y,w,h)) : items] 
   #!
		strict1=strict1;
		strict2=strict2;
		=
		[strict1 : strict2];
	where {
1574
	strict1=repos_widget widget (x + base) y w h;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1575 1576 1577 1578 1579
		strict2=CenterItems` base items;
		
	};
CenterItems` base items =  [];