1. -- 
  2. -- Copyright (c) 2012 Kevin Wellwood 
  3. -- All rights reserved. 
  4. -- 
  5. -- This source code is distributed under the Modified BSD License. For terms and 
  6. -- conditions, see license.txt. 
  7. -- 
  8.  
  9. package Widgets.Containers.Panels.Dialogs is 
  10.  
  11.     -- A Dialog is an abstract container widget for modal dialogs. All of the 
  12.     -- dialog's controls are added as children and a title can be set using the 
  13.     -- inherited operations from Panel. The Dialog class extends the Panel's 
  14.     -- functionality by adding Hide and Show procedures to hide and show the 
  15.     -- dialog as a modal widget in the window. If the dialog has a title bar, it 
  16.     -- can also be dragged with the mouse. Events to pause and resume gameplay 
  17.     -- will be queued when the dialog is shown and hidden, respectively, because 
  18.     -- it is modal. 
  19.     type Dialog is abstract new Panel and 
  20.                                 Key_Listener and 
  21.                                 Visibility_Listener with private; 
  22.     type A_Dialog is access all Dialog'Class; 
  23.  
  24.     -- Hides the dialog. It remains a child of the window. 
  25.     procedure Hide( this : access Dialog ); 
  26.  
  27.     -- Shows the modal dialog in the window. The dialog must have been added 
  28.     -- to the window before this is called. 
  29.     procedure Show( this : access Dialog ); 
  30.  
  31. private 
  32.  
  33.     type Dialog is abstract new Panel and 
  34.                                 Key_Listener and 
  35.                                 Visibility_Listener with 
  36.         record 
  37.             dragStartX, 
  38.             dragStartY : Integer := -1; 
  39.         end record; 
  40.  
  41.     procedure Construct( this  : access Dialog; 
  42.                          view  : not null access Game_Views.Game_View'Class; 
  43.                          id    : String; 
  44.                          title : String; 
  45.                          icon  : String ); 
  46.     pragma Precondition( id'Length > 0 ); 
  47.  
  48.     procedure Delete( this : in out Dialog ); 
  49.  
  50.     -- Traps key actions, preventing them from being propagated to the dialog's 
  51.     -- window. 
  52.     procedure Handle_Action( this    : access Dialog; 
  53.                              action  : A_Key_Action; 
  54.                              handled : out Boolean ); 
  55.  
  56.     -- Handles visibility actions by dispatching to the On_Dialog_Show and 
  57.     -- On_Dialog_Hide procedures implemented by a concrete subclass. 
  58.     procedure Handle_Action( this   : access Dialog; 
  59.                              action : A_Visibility_Action ); 
  60.  
  61.     -- This is called when the dialog is hidden or closed. Override this 
  62.     -- procedure to implement its behavior. 
  63.     procedure On_Dialog_Hide( this : access Dialog ) is null; 
  64.  
  65.     -- This is called when the dialog is shown or opened. Override this 
  66.     -- procedure to implement its behavior. 
  67.     procedure On_Dialog_Show( this : access Dialog ) is null; 
  68.  
  69.     -- Moves the dialog around its parent if its being dragged. 
  70.     procedure On_Mouse_Move( this : access Dialog; 
  71.                              evt  : not null A_Mouse_Event ); 
  72.  
  73.     -- Detects if the dialog should be dragged when the left mouse is pressed. 
  74.     procedure On_Mouse_Press( this : access Dialog; 
  75.                               evt  : not null A_Mouse_Button_Event ); 
  76.  
  77. end Widgets.Containers.Panels.Dialogs;