with Claw.Fonts;
package Claw.Dialog is
    --
    -- CLAW - Class Library for Ada and Windows.
    --
    -- This package contains the abstract dialog class.
    --
    -- Copyright 1996, 1997  R.R. Software, Inc.
    -- P.O. Box 1512, Madison WI  53701
    -- All rights reserved.
    --

    pragma Elaborate_Body; -- Insure that the body is elaborated before anyone
	                   -- can call CLAW.

    -- Dialog class

    type Root_Dialog_Type is abstract new CLAW.Root_Window_Type with private;

    -- Predefined ID numbers.
    ID_OK	: constant Identifier_Type := 1;
    ID_Cancel	: constant Identifier_Type := 2;
    ID_Abort	: constant Identifier_Type := 3;
    ID_Help	: constant Identifier_Type := 16#40E#;

    package Styles is
        type Dialog_Style_Type is private;

        --  Dialog Box Styles (note, these can be combined with most
        --		       Windows styles)

        Normal            : constant Dialog_Style_Type; -- No special style.

	Force_Foreground  : constant Dialog_Style_Type;
	    -- The dialog box will be forced into the foreground.
	Modal_Frame	  : constant Dialog_Style_Type;
	    -- The dialog box will have a modal-dialog frame.
	No_Idle_Message	  : constant Dialog_Style_Type;
	    -- Windows will not send an idle message to the owner window.
	    -- Note: Claw does not use the Idle message.
	System_Modal      : constant Dialog_Style_Type;
	    -- Create a system modal dialog box. This forces the dialog to always
	    -- be the topmost dialog. It does NOT effect other applications.
	Use_3D_Look	  : constant Dialog_Style_Type;
	    -- The dialog box will have a 3-D look.  This flag is only effective
	    -- when running on versions of Windows previous to 4.0. [Newer
	    -- versions automatically use a 3-D look.  (But it is
	    -- not supported in older development systems).

	Use_Fixed_System_Font : constant Dialog_Style_Type;
	    -- The dialog box will use the fixed system font.  >= Win 4.0 only.
	Center_in_Workspace : constant Dialog_Style_Type;
	    -- The dialog box will be centered in the workspace.  >= Win 4.0 only.
	Center_Mouse	  : constant Dialog_Style_Type;
	    -- The mouse cursor will be centered in the dialog box.  >= Win 4.0 only.
	Control_Dialog	  : constant Dialog_Style_Type;
	    -- Create a dialog box that will work well as a control in a larger
	    -- dialog box.  This alters the keyboard interface.  >= Win 4.0 only.
	Context_Help	  : constant Dialog_Style_Type;
	    -- Include a context help button in the title of the dialog box.  >= Win 4.0 only.

	Standard_Modal      : constant Dialog_Style_Type;
	    -- A modal-framed dialog, caption, system menu, popup window.
	Standard_Modeless   : constant Dialog_Style_Type;
	    -- A modeless-framed dialog, caption, system menu, popup window.



        function DWORD_of (s : in Dialog_Style_Type) return CLAW.DWORD;
	    -- Low-level access to styles.

        function "+"(Left, Right : Dialog_Style_Type) return Dialog_Style_Type;
	    -- Combines two styles into a single styles value.

        function "+"(Left : Claw.Styles.Window_Style_Type; Right : Dialog_Style_Type)
	        return Dialog_Style_Type;
	    -- Combines two styles into a single styles value.

        function "+"(Left : Dialog_Style_Type; Right : Claw.Styles.Window_Style_Type)
	        return Dialog_Style_Type;
	    -- Combines two styles into a single styles value.

        function ">="(Left, Right : Dialog_Style_Type) return Boolean;
        function ">="(Left : Dialog_Style_Type; Right : Claw.Styles.Window_Style_Type)
	        return Boolean;
	    -- Read  A >= B   as   A includes B.
	    -- That is, each set style in B is also in A.

        function Dialog_Style_of (S : in DWord) return Dialog_Style_Type;
	    -- Create a style from a DWord for low-level use.
    private
	type Dialog_Style_Type is new Claw.DWord;
        Normal            : constant Dialog_Style_Type := 16#0000#;
	Absolute_Alignment: constant Dialog_Style_Type := 16#0001#;
	    -- The coordinates of the dialog box are screen coordinates; otherwise
	    -- they are client coordinates.  For Claw use only.
	System_Modal      : constant Dialog_Style_Type := 16#0002#;
	Local_Storage_for_Edit : constant Dialog_Style_Type := 16#0020#;
	    -- Use local storage for edit controls.  Obsolete (local and global
	    -- memory is the same in Win32).
	Set_Font	  : constant Dialog_Style_Type := 16#0040#;
	    -- Causes Windows to call WM_SETFONT on all of the controls with
	    -- the appropriate font.  Not supported by Claw (the application
	    -- can do this if desired, by calling Set_Font on the appropriate
	    -- controls).  (Note that this doesn't change the font of the
	    -- dialog box itself, the only potentially useful case).
	Modal_Frame	  : constant Dialog_Style_Type := 16#0080#;
	No_Idle_Message	  : constant Dialog_Style_Type := 16#0100#;
	Force_Foreground  : constant Dialog_Style_Type := 16#0200#;
	Use_3D_Look	  : constant Dialog_Style_Type := 16#0004#;
	Use_Fixed_System_Font : constant Dialog_Style_Type := 16#0008#;
	No_Fail_Creation  : constant Dialog_Style_Type := 16#0010#;
	    -- Create the dialog box even if errors occur.  Only in Windows 95.
	    -- Not supported in Claw, since the only kind of template that can
	    -- use these flags are dynamic (and empty).  Those cannot fail.
	Control_Dialog	  : constant Dialog_Style_Type := 16#0400#;
	Center_in_Workspace : constant Dialog_Style_Type := 16#0800#;
	Center_Mouse	  : constant Dialog_Style_Type := 16#1000#;
	Context_Help	  : constant Dialog_Style_Type := 16#2000#;

	use type Claw.Styles.Window_Style_Type;

	Standard_Modal      : constant Dialog_Style_Type :=
	    Modal_Frame or Dialog_Style_Type(Claw.Styles.DWord_of(Claw.Styles.Caption +
		Claw.Styles.System_Menu + Claw.Styles.Popup));
	    -- A modal-framed dialog, caption, system menu, popup window.
	Standard_Modeless   : constant Dialog_Style_Type :=
	    Dialog_Style_Type(Claw.Styles.DWord_of(Claw.Styles.Border +
		Claw.Styles.Caption + Claw.Styles.System_Menu + Claw.Styles.Popup));
	    -- A modeless-framed dialog, caption, system menu, popup window.

    end Styles;


    -- Operations:

    function Get_Autoposition (Dialog : in Root_Dialog_Type) return Boolean;
	-- Returns the autoposition value for Dialog.

    procedure Get_Default_Button (Dialog : in Root_Dialog_Type;
				  Has_Default_Button : out Boolean;
				  Default_Button_Identifier : out Claw.Identifier_Type);
	-- Returns whether a Dialog has a default push button, and if so,
	-- its identifier.
        -- Raises:
        --      Not_Valid_Error if Dialog is not open.

    procedure Set_Default_Button (Dialog : in Root_Dialog_Type;
				  Default_Button_Identifier : in Claw.Identifier_Type);
	-- Set the default push button for Dialog.
	-- Note: The calling program must use Claw.Push_Button.Modify to
	-- change the Default property for the buttons involved.
        -- Raises:
        --      Not_Valid_Error if Dialog is not open.

    -- Note:
    -- Dialog units are based on the system font (or the dialog box font);
    -- using them means that the dialog box will adjust in size depending
    -- of the properties of the font in use.  (To successfully use them
    -- requires that all controls in a dialog box use the same font, or are
    -- automatically sized by Claw).  Dialog and control creation routines
    -- optionally take values in dialog box units.
    -- Window operations, on the other hand, require positions and sizes in
    -- pixels.  The following conversion routines are provided in order that
    -- all operations can use dialog units, if necessary.

    function Dialog_Units_to_Pixels (Dialog : in Root_Dialog_Type'Class;
				     Rect   : in Rectangle_Type) return Rectangle_Type;
	-- Convert Rect (in system-independent dialog units) into Pixels.
	-- Raises:
	--	Not_Valid_Error if Dialog isn't valid.
	--	Windows_Error if Windows returns an error.

    function Dialog_Units_to_Pixels (Dialog : in Root_Dialog_Type'Class;
				     Size   : in Size_Type) return Size_Type;
	-- Convert Size (in system-independent dialog units) into Pixels.
	-- Raises:
	--	Not_Valid_Error if Dialog isn't valid.
	--	Windows_Error if Windows returns an error.

    function Dialog_Units_to_Pixels (Dialog : in Root_Dialog_Type'Class;
				     Point  : in Point_Type) return Point_Type;
	-- Convert Point (in system-independent dialog units) into Pixels.
	-- Raises:
	--	Not_Valid_Error if Dialog isn't valid.
	--	Windows_Error if Windows returns an error.


    -- Will inherit Get_Parent, Show, Update, Destroy, Initialize, Adjust, Finalize.

    -- Action routines:

    -- Inherits When_Close, When_Child_Control, When_Other_Message.

    procedure When_OK (Dialog : in out Root_Dialog_Type) is abstract;
	-- This procedure is called whenever the OK button (if any) is pushed.
	-- The OK button has Id number ID_OK.

    procedure When_Cancel (Dialog : in out Root_Dialog_Type) is abstract;
	-- This procedure is called whenever the Cancel button (if any) is pushed.
	-- The Cancel button has Id number ID_Cancel.

    procedure When_Help (Dialog : in out Root_Dialog_Type) is abstract;
	-- This procedure is called whenever the Help button (if any) is pushed.
	-- The Help button has Id number ID_Help.

    procedure When_Initialize (Dialog : in out Root_Dialog_Type;
			       Windows_Set_Focus : in out Boolean) is abstract;
	-- This procedure is called when the dialog box is initialized.
	-- If this routine sets the input focus to a specific control, it
	-- should set Windows_Set_Focus to False; otherwise, it should set
	-- Windows_Set_Focus to True (Windows will then set the focus to
	-- an appropriate control).
	-- The routine can be used to set up edit and listbox controls in
	-- the dialog box.

    -- Low-level access:

    -- Inherits Get_Handle.

private
    type Root_Dialog_Type is abstract new CLAW.Root_Window_Type with record
	Autoposition : Boolean := FALSE;
	    -- This flag should only be set at creation-time, and only has
	    -- an effect at that time.
	Dialog_Base_X : Claw.Int;
	Dialog_Base_Y : Claw.Int;
	Dialog_Base_Set : Boolean := False;
	    -- These values should only be set at creation-time.
	Has_Default_Font : Boolean := False;
	Default_Font : Any_Tool_Access_Type := null;
	    -- These values should only be set at creation-time.
    end record;

    function Convert_Size (Dialog : in Root_Dialog_Type;
			   Original_Size : in Size_Type;
			   In_Dialog_Units : in Boolean) return Size_Type;
	-- Convert Size from Dialog units to Pixels, if needed.
	-- Raises:
	--	Not_Valid_Error if Dialog does not have a valid (Windows) window.

    function Convert_Position (Dialog : in Root_Dialog_Type;
			       Original_Position : in Point_Type;
			       In_Dialog_Units : in Boolean) return Point_Type;
	-- Convert Size from Dialog units to Pixels, if needed.
	-- Raises:
	--	Not_Valid_Error if Dialog does not have a valid (Windows) window.

    function Has_Default_Font (Dialog : in Root_Dialog_Type) return Boolean;
	-- Returns True if Dialog has a default font; returns False otherwise.
	-- (We'll use the system font if this is False).
	-- Raises:
	--	Not_Valid_Error if Dialog does not have a valid (Windows) window.

    function Default_Font (Dialog : in Root_Dialog_Type) return Any_Tool_Access_Type;
	-- Returns an access to the default font object for Dialog.
	-- Raises:
	--	Not_Valid_Error if Dialog does not have a valid (Windows) window.
	--	Not_Found_Error if Has_Default_Font would return False.

    procedure Set_Default_Dialog_Units (Dialog : in out Root_Dialog_Type'Class);
	-- Set the dialog units to the default value.
	-- This routine should only be called during creation of a dialog.

    procedure Set_Dialog_Units (Dialog : in out Root_Dialog_Type'Class;
				Font : in Claw.Fonts.Font_Type'Class);
	-- Set the dialog units based on Font.
	-- This routine should only be called during creation of a dialog.

    procedure Get_Dialog_Units (Dialog : in Root_Dialog_Type'Class;
				Base_Unit_X : out Claw.Int;
				Base_Unit_Y : out Claw.Int);
	-- Get the dialog units for Dialog.
	-- A dialog unit is related to pixels by the following formulas:
	--	Pixel_X := (Dialog_Unit_X * Base_Unit_X) / 4;
	--	Pixel_Y := (Dialog_Unit_Y * Base_Unit_Y) / 8;
	--	Dialog_Unit_X := (Pixel_X * 4) / Base_Unit_X);
	--	Dialog_Unit_Y := (Pixel_Y * 4) / Base_Unit_Y);
	-- Note: Usually, it is easier to use one of the Dialog_Units_to_Pixels
	-- routines.

end Claw.Dialog;