Commit a0b2f6b76f3fa1d795cf98d3ba295cf9c56c0769

Authored by Alain Prouté
1 parent 93be4d65

*** empty log message ***

anubis_dev/library/widgets4/host_window.anubis
... ... @@ -245,7 +245,8 @@ define List(Rectangle)
245 245 WidgetAnswer a,
246 246 Var(Maybe(Var(One))) mouse_capture_ticket_v,
247 247 Var(Maybe(Var(One))) keyboard_capture_ticket_v,
248   - Var(WidgetEventCompression) compress_v
  248 + Var(WidgetEventCompression) compress_v,
  249 + Var(Maybe(WidgetEvent)) secondary_event_v
249 250 ) =
250 251 if a is
251 252 {
... ... @@ -257,6 +258,8 @@ define List(Rectangle)
257 258 compress_v <- cm;
258 259 if a is abs_area(l) then l,
259 260 want_to_capture_keyboard(v,a) then keyboard_capture_ticket_v <- success(v);
  261 + secondary_event_v <-
  262 + success(keyboard_recaptured((Var(One) t) |-> v = t));
260 263 if a is abs_area(l) then l,
261 264 }.
262 265  
... ... @@ -275,9 +278,14 @@ define (HostWindow,HostWindowEvent(One)) -&gt; List(Rectangle)
275 278 Var(Maybe(Var(One))) keyboard_capture_ticket_v,
276 279 Var(WidgetEventCompression) compress_v,
277 280 Var(Int32) pmx_v,
278   - Var(Int32) pmy_v
279   - ) =
280   - with store_v = var((List(Rectangle))[]),
  281 + Var(Int32) pmy_v,
  282 + Var(Maybe(WidgetEvent)) secondary_event
  283 + ) =
  284 + //
  285 + // We store all rectangles in the next variable, and only the 'tick' event
  286 + // returns a non empty list of rectangles.
  287 + //
  288 + with store_v = var((List(Rectangle))[]),
281 289 (HostWindow win, HostWindowEvent(One) we) |->
282 290 if we is
283 291 {
... ... @@ -298,7 +306,7 @@ define (HostWindow,HostWindowEvent(One)) -&gt; List(Rectangle)
298 306 mouse_gone),
299 307 mouse_capture_ticket_v,
300 308 keyboard_capture_ticket_v,
301   - compress_v),
  309 + compress_v,secondary_event),
302 310 store_v <- *store_v + result;
303 311 [],
304 312  
... ... @@ -320,7 +328,7 @@ define (HostWindow,HostWindowEvent(One)) -&gt; List(Rectangle)
320 328 else failure)),
321 329 mouse_capture_ticket_v,
322 330 keyboard_capture_ticket_v,
323   - compress_v),
  331 + compress_v,secondary_event),
324 332 store_v <- *store_v + result;
325 333 []
326 334 },
... ... @@ -341,7 +349,7 @@ define (HostWindow,HostWindowEvent(One)) -&gt; List(Rectangle)
341 349 mouse_move(ks,x,y)),
342 350 mouse_capture_ticket_v,
343 351 keyboard_capture_ticket_v,
344   - compress_v),
  352 + compress_v,secondary_event),
345 353 pmx_v <- x;
346 354 pmy_v <- y;
347 355 store_v <- *store_v + result;
... ... @@ -360,7 +368,7 @@ define (HostWindow,HostWindowEvent(One)) -&gt; List(Rectangle)
360 368 else failure)),
361 369 mouse_capture_ticket_v,
362 370 keyboard_capture_ticket_v,
363   - compress_v),
  371 + compress_v,secondary_event),
364 372 pmx_v <- x;
365 373 pmy_v <- y;
366 374 store_v <- *store_v + result;
... ... @@ -373,12 +381,13 @@ define (HostWindow,HostWindowEvent(One)) -&gt; List(Rectangle)
373 381 then unique
374 382 else mouse_capture_ticket_v <- failure
375 383 );
376   - with result = translate(win,
377   - transmit(event_tool_box(0,0,*pmx_v,*pmy_v))(root_widget,0,0,
378   - mouse_click(ks,mc,x,y)),
379   - mouse_capture_ticket_v,
380   - keyboard_capture_ticket_v,
381   - compress_v),
  384 + with result =
  385 + translate(win,
  386 + transmit(event_tool_box(0,0,*pmx_v,*pmy_v))(root_widget,0,0,
  387 + mouse_click(ks,mc,x,y)),
  388 + mouse_capture_ticket_v,
  389 + keyboard_capture_ticket_v,
  390 + compress_v,secondary_event),
382 391 pmx_v <- x;
383 392 pmy_v <- y;
384 393 store_v <- *store_v + result;
... ... @@ -395,7 +404,7 @@ define (HostWindow,HostWindowEvent(One)) -&gt; List(Rectangle)
395 404 mouse_wheel(ks,d,x,y)),
396 405 mouse_capture_ticket_v,
397 406 keyboard_capture_ticket_v,
398   - compress_v),
  407 + compress_v,secondary_event),
399 408 pmx_v <- x;
400 409 pmy_v <- y;
401 410 store_v <- *store_v + result;
... ... @@ -410,7 +419,18 @@ define (HostWindow,HostWindowEvent(One)) -&gt; List(Rectangle)
410 419 changed(l)),
411 420 mouse_capture_ticket_v,
412 421 keyboard_capture_ticket_v,
413   - compress_v),
  422 + compress_v,secondary_event) +
  423 + if *secondary_event is
  424 + {
  425 + failure then [],
  426 + success(e) then
  427 + secondary_event <- failure;
  428 + translate(win,
  429 + transmit(event_tool_box(0,0,*pmx_v,*pmy_v))(root_widget,0,0,e),
  430 + mouse_capture_ticket_v,
  431 + keyboard_capture_ticket_v,
  432 + compress_v,secondary_event)
  433 + },
414 434 store_v <- [];
415 435 last,
416 436  
... ... @@ -511,19 +531,21 @@ define List(HostWindowEvent(One))
511 531 //print(n+" ---> "+length(result)+"\n");
512 532 result.
513 533  
514   -
515 534  
516   - *** [] Opening the host window.
517 535  
518 536  
519 537  
  538 +
  539 +
  540 + *** [] Opening the host window.
  541 +
520 542 public define Bool
521 543 open_host_window
522 544 (
523   - WidgetHostWindowState -> Widget root, // content of host window
524   - Int32 x,
525   - Int32 y,
526   - String title
  545 + WidgetHostWindowState -> Widget root, // content of host window
  546 + Int32 x, // coordinates of window on screen
  547 + Int32 y,
  548 + String title // title of window
527 549 ) =
528 550 with the_window_state =
529 551 host_window_state(var((Int32)0), // size is updated below
... ... @@ -543,7 +565,8 @@ public define Bool
543 565 registration(f) then f(mvtb),
544 566 regs);
545 567  
546   - with buffer = to_host_image(create_rgba_image(800,800, //root_w>>1,root_h>>1,
  568 + with buffer = to_host_image(create_rgba_image(800,800,
  569 + //root_w>>1,root_h>>1,
547 570 rgba(0,0,0,0)),1),
548 571  
549 572 with mouse_capture_ticket_v = var((Maybe(Var(One)))failure),
... ... @@ -553,6 +576,8 @@ public define Bool
553 576 with pmx_v = var((Int32)0),
554 577 pmy_v = var((Int32)0),
555 578  
  579 + with secondary_event = var((Maybe(WidgetEvent))failure),
  580 +
556 581 if open_host_window(rect(x,y,x+root_w,y+root_h),
557 582 title,
558 583 managed,
... ... @@ -566,7 +591,8 @@ public define Bool
566 591 keyboard_capture_ticket_v,
567 592 compress_v,
568 593 pmx_v,
569   - pmy_v),
  594 + pmy_v,
  595 + secondary_event),
570 596 (List(HostWindowEvent(One)) l) |->
571 597 if *compress_v is
572 598 {
... ... @@ -581,6 +607,9 @@ public define Bool
581 607 }.
582 608  
583 609  
  610 +
  611 + The variants:
  612 +
584 613 public define Bool
585 614 open_host_window
586 615 (
... ...
anubis_dev/library/widgets4/text_input.anubis
... ... @@ -404,6 +404,12 @@ define (WidgetEventToolBox,WidgetEvent) -&gt; WidgetAnswer
404 404 }
405 405 }
406 406 },
  407 +
  408 + keyboard_recaptured(f) then
  409 + if f(ticket)
  410 + then ignored
  411 + else focused_v <- false;
  412 + handled(area(etb)([rect(0,0,width,height)])),
407 413  
408 414 changed(l) then
409 415 if member(l,var_id(content_v))
... ... @@ -452,63 +458,3 @@ public define Widget
452 458 ).
453 459  
454 460  
455   -
456   -
457   -read host_window.anubis
458   -read table.anubis
459   -
460   -
461   -define Bool
462   - no_capital
463   - (
464   - List(Int8) l
465   - ) =
466   - if l is
467   - {
468   - [ ] then true,
469   - [h . t]
470   - then if h /= to_lower(h)
471   - then false
472   - else no_capital(t)
473   - }.
474   -
475   -global define One
476   - text_input_test
477   - (
478   - List(String) args
479   - ) =
480   - if load_system_font("helvetica_medium_r_10") is
481   - {
482   - failure then print("Cannot load font.\n"),
483   - success(font) then
484   - with content_v = var((String)"gabuzomeu"),
485   - forget(open_host_window( table(borders(rgb(255,255,0),
486   - rgb(128,128,128),
487   - 2,2),4,4,
488   - [[cell(
489   - text_input(content_v,
490   - (String s) |-> no_capital(explode(s)),
491   - font,
492   - rgb(0,0,0),
493   - rgb(230,0,0),
494   - rgb(0,0,255),
495   - rgb(255,255,255),
496   - 200))
497   - ],
498   - [cell(
499   - text_input(content_v,
500   - (String s) |-> no_capital(explode(s)),
501   - font,
502   - rgb(0,0,0),
503   - rgb(230,0,0),
504   - rgb(0,0,255),
505   - rgb(255,255,255),
506   - 200))
507   - ]]),
508   -
509   -
510   - "Text Input Test"))
511   -
512   - }.
513   -
514   -
515 461 \ No newline at end of file
... ...
anubis_dev/library/widgets4/widget.anubis
... ... @@ -429,6 +429,7 @@ public type WidgetEvent:
429 429 // Events generated when the keyboard is captured:
430 430 //
431 431 key_down ((Var(One)) -> Maybe((KeyboardState,KeyboardKey))),
  432 + keyboard_recaptured ((Var(One)) -> Bool),
432 433 //
433 434 // Events generated when a state variable is reassigned:
434 435 //
... ... @@ -514,14 +515,19 @@ public type WidgetEvent:
514 515 childs.
515 516  
516 517  
517   - *** (4.1.4) 'key_down'.
  518 + *** (4.1.4) 'key_down' and 'keyboard_recaptured'.
518 519  
519 520 This event works like 'captured_mouse_move' and 'captured_mouse_liberated' events. You
520 521 must apply the function to your ticket in order to know if you are concerned by the
521 522 event. If it is the case you get the keyboard state and the character which has been
522 523 entered.
523 524  
524   - If your widget is not concerned by this event it must transmit it to all of its childs.
  525 + The event 'keyboard_recaptured(f)' means that the keyboard has just been
  526 + recaptured. Your widget must apply 'f' to its own ticket. If the result is 'true' your
  527 + widget still has the keyboard. If it is 'false', your widget loosed the keyboard.
  528 +
  529 + If your widget is not concerned by one of these event it must transmit it to all of its
  530 + childs.
525 531  
526 532  
527 533  
... ... @@ -1122,6 +1128,7 @@ public define (Widget child, Int32 x, Int32 y, WidgetEvent) -&gt; WidgetAnswer
1122 1128 captured_mouse_move(f) then event_handler(cetb,e),
1123 1129 captured_mouse_liberated(f) then event_handler(cetb,e),
1124 1130 key_down(f) then event_handler(cetb,e),
  1131 + keyboard_recaptured(f) then event_handler(cetb,e),
1125 1132 changed(l) then event_handler(cetb,e)
1126 1133 }.
1127 1134  
... ...