Browse Source

+ TTimedDialog and TimedMessageBox added

Tomas Hajny 20 years ago
parent
commit
b1e82ff529
6 changed files with 352 additions and 28 deletions
  1. 1 1
      fv/Makefile
  2. 1 1
      fv/Makefile.fpc
  3. 5 1
      fv/buildfv.pas
  4. 44 21
      fv/msgbox.pas
  5. 38 4
      fv/test/testapp.pas
  6. 263 0
      fv/timeddlg.pas

+ 1 - 1
fv/Makefile

@@ -222,7 +222,7 @@ PACKAGESDIR:=$(wildcard $(FPCDIR) $(FPCDIR)/packages/base $(FPCDIR)/packages/ext
 override PACKAGE_NAME=fv
 override PACKAGE_VERSION=1.9.4
 override TARGET_UNITS+=buildfv
-override TARGET_IMPLICITUNITS+=app colortxt dialogs drivers editors fvcommon fvconsts gadgets histlist inplong memory menus msgbox resource statuses stddlg tabs time validate views sysmsg asciitab
+override TARGET_IMPLICITUNITS+=app colortxt dialogs drivers editors fvcommon fvconsts gadgets histlist inplong memory menus msgbox resource statuses stddlg tabs time validate views sysmsg asciitab timeddlg
 override TARGET_EXAMPLEDIRS+=test
 override INSTALL_BUILDUNIT=buildfv
 override INSTALL_FPCPACKAGE=y

+ 1 - 1
fv/Makefile.fpc

@@ -11,7 +11,7 @@ units=buildfv
 implicitunits=app colortxt dialogs drivers editors \
               fvcommon fvconsts gadgets histlist inplong memory \
               menus msgbox resource statuses stddlg tabs time validate \
-              views sysmsg asciitab
+              views sysmsg asciitab timeddlg
 exampledirs=test
 
 [libs]

+ 5 - 1
fv/buildfv.pas

@@ -27,6 +27,7 @@ uses
   inplong,
   editors,
   gadgets,
+  timeddlg,
   time;
 
 implementation
@@ -34,7 +35,10 @@ implementation
 end.
 {
   $Log$
-  Revision 1.8  2004-11-06 17:08:48  peter
+  Revision 1.9  2004-12-19 20:25:11  hajny
+    + TTimedDialog and TimedMessageBox added
+
+  Revision 1.8  2004/11/06 17:08:48  peter
     * drawing of tview merged from old fv code
 
 }

+ 44 - 21
fv/msgbox.pas

@@ -76,7 +76,7 @@ UNIT MsgBox;
 {$V-} { Turn off strict VAR strings }
 {====================================================================}
 
-USES Objects;                                         { Standard GFV unit }
+USES objects, dialogs;                                 { Standard GFV units }
 
 {***************************************************************************}
 {                              PUBLIC CONSTANTS                             }
@@ -107,6 +107,10 @@ CONST
    mfOKCancel     = mfOKButton + mfCancelButton;
                                                       { Standard OK, Cancel dialog }
 
+var
+  MsgBoxTitles: array[0..3] of string[40];
+
+
 {***************************************************************************}
 {                            INTERFACE ROUTINES                             }
 {***************************************************************************}
@@ -134,6 +138,13 @@ to occupy.
 FUNCTION MessageBoxRect (Var R: TRect; Const Msg: String; Params: Pointer;
   AOptions: Word): Word;
 
+{-MessageBoxRectDlg--------------------------------------------------
+MessageBoxRecDlg allows the specification of a TRect for the message box
+to occupy plus the dialog window (to allow different dialog window types).
+---------------------------------------------------------------------}
+FUNCTION MessageBoxRectDlg (Dlg: PDialog; Var R: TRect; Const Msg: String;
+  Params: Pointer; AOptions: Word): Word;
+
 {-InputBox-----------------------------------------------------------
 InputBox displays a simple dialog that allows user to type in a string
 30Sep99 LdB
@@ -152,7 +163,7 @@ FUNCTION InputBoxRect (Var Bounds: TRect; Const Title, ALabel: String;
                                 IMPLEMENTATION
 {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
 
-USES Drivers, Views, App, Dialogs, Resource;           { Standard GFV units }
+USES Drivers, Views, App, Resource;                    { Standard GFV units }
 
 {***************************************************************************}
 {                            INTERFACE ROUTINES                             }
@@ -163,7 +174,6 @@ const
     (cmYes, cmNo, cmOK, cmCancel);
 var
   ButtonName: array[0..3] of string[40];
-  Titles: array[0..3] of string[40];
 
 {---------------------------------------------------------------------------}
 {  MessageBox -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB        }
@@ -181,18 +191,12 @@ BEGIN
      AOptions);                                       { Create message box }
 END;
 
-{---------------------------------------------------------------------------}
-{  MessageBoxRect -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB    }
-{---------------------------------------------------------------------------}
-FUNCTION MessageBoxRect(Var R: TRect; Const Msg: String; Params: Pointer;
-  AOptions: Word): Word;
-VAR I, X, ButtonCount: Integer; S: String; Dialog: PDialog; Control: PView;
+FUNCTION MessageBoxRectDlg (Dlg: PDialog; Var R: TRect; Const Msg: String;
+  Params: Pointer; AOptions: Word): Word;
+VAR I, X, ButtonCount: Integer; S: String; Control: PView;
     ButtonList: Array[0..4] Of PView;
 BEGIN
-   Dialog := New(PDialog, Init(R, Titles[AOptions
-     AND $3]));                                       { Create dialog }
-   With Dialog^ Do Begin
-     R.Assign(3, 2, Size.X - 2, Size.Y - 3);          { Assign screen area }
+   With Dlg^ Do Begin
      FormatStr(S, Msg, Params^);                      { Format the message }
      Control := New(PStaticText, Init(R, S));         { Create static text }
      Insert(Control);                                 { Insert the text }
@@ -218,9 +222,25 @@ BEGIN
      SelectNext(False);                               { Select first button }
    End;
    If (AOptions AND mfInsertInApp = 0) Then
-     MessageBoxRect := DeskTop^.ExecView(Dialog) Else { Execute dialog }
-     MessageBoxRect := Application^.ExecView(Dialog); { Execute dialog }
-   Dispose(Dialog, Done);                             { Dispose of dialog }
+     MessageBoxRectDlg := DeskTop^.ExecView(Dlg) Else { Execute dialog }
+     MessageBoxRectDlg := Application^.ExecView(Dlg); { Execute dialog }
+end;
+
+
+{---------------------------------------------------------------------------}
+{  MessageBoxRect -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB    }
+{---------------------------------------------------------------------------}
+FUNCTION MessageBoxRect(Var R: TRect; Const Msg: String; Params: Pointer;
+  AOptions: Word): Word;
+var
+  Dialog: PDialog;
+BEGIN
+  Dialog := New (PDialog, Init (R, MsgBoxTitles [AOptions
+    AND $3]));                                       { Create dialog }
+  with Dialog^ do
+    R.Assign(3, 2, Size.X - 2, Size.Y - 3);          { Assign area for text }
+  MessageBoxRect := MessageBoxRectDlg (Dialog, R, Msg, Params, AOptions);
+  Dispose (Dialog, Done);                            { Dispose of dialog }
 END;
 
 {---------------------------------------------------------------------------}
@@ -277,10 +297,10 @@ begin
   ButtonName[1] := Labels^.Get(slNo);
   ButtonName[2] := Labels^.Get(slOk);
   ButtonName[3] := Labels^.Get(slCancel);
-  Titles[0] := Strings^.Get(sWarning);
-  Titles[1] := Strings^.Get(sError);
-  Titles[2] := Strings^.Get(sInformation);
-  Titles[3] := Strings^.Get(sConfirm);
+  MsgBoxTitles[0] := Strings^.Get(sWarning);
+  MsgBoxTitles[1] := Strings^.Get(sError);
+  MsgBoxTitles[2] := Strings^.Get(sInformation);
+  MsgBoxTitles[3] := Strings^.Get(sConfirm);
 end;
 
 procedure DoneMsgBox;
@@ -291,7 +311,10 @@ END.
 
 {
  $Log$
- Revision 1.6  2004-11-06 17:08:48  peter
+ Revision 1.7  2004-12-19 20:25:11  hajny
+   + TTimedDialog and TimedMessageBox added
+
+ Revision 1.6  2004/11/06 17:08:48  peter
    * drawing of tview merged from old fv code
 
 }

+ 38 - 4
fv/test/testapp.pas

@@ -1,7 +1,11 @@
 { $Id$ }
 PROGRAM TestApp;
 
-{&PMTYPE PM}                                          { FULL GUI MODE }
+{ $UNDEF OS2PM}
+
+{$IFDEF OS2PM}
+ {&PMTYPE PM}                                          { FULL GUI MODE }
+{$ENDIF OS2PM}
 
 { ******************************* REMARK ****************************** }
 {  This is a basic test program to test the app framework. In use will  }
@@ -34,7 +38,9 @@ PROGRAM TestApp;
 
 {$I Platform.inc}
   USES
+{$IFDEF OS2PM}
      {$IFDEF OS_OS2} Os2Def, os2PmApi,  {$ENDIF}
+{$ENDIF OS2PM}
      Objects, Drivers, Views, Menus, Dialogs, App,             { Standard GFV units }
      FVConsts,
      {$ifdef TEST}
@@ -43,13 +49,14 @@ PROGRAM TestApp;
      {$ifdef DEBUG}
      Gfvgraph,
      {$endif DEBUG}
-     Gadgets;
+     Gadgets, TimedDlg, MsgBox;
 
 
 CONST cmAppToolbar = 1000;
       cmWindow1    = 1001;
       cmWindow2    = 1002;
       cmWindow3    = 1003;
+      cmTimedBox   = 1004;
       cmAscii      = 1010;
       cmCloseWindow1    = 1101;
       cmCloseWindow2    = 1102;
@@ -75,6 +82,7 @@ TYPE
       PROCEDURE Window1;
       PROCEDURE Window2;
       PROCEDURE Window3;
+      PROCEDURE TimedBox;
       PROCEDURE AsciiWindow;
       PROCEDURE CloseWindow(var P : PGroup);
     End;
@@ -145,6 +153,7 @@ BEGIN
        cmWindow1 : Window1;
        cmWindow2 : Window2;
        cmWindow3 : Window3;
+       cmTimedBox: TimedBox;
        cmAscii   : AsciiWindow;
        cmCloseWindow1 : CloseWindow(P1);
        cmCloseWindow2 : CloseWindow(P2);
@@ -173,10 +182,11 @@ BEGIN
       NewItem('Window 1','',kbNoKey,cmWindow1,hcNoContext,
       NewItem('Window 2','',kbNoKey,cmWindow2,hcNoContext,
       NewItem('Window 3','',kbNoKey,cmWindow3,hcNoContext,
+      NewItem('Timed Box','',kbNoKey,cmTimedBox,hcNoContext,
       NewItem('Close Window 1','',kbNoKey,cmCloseWindow1,hcNoContext,
       NewItem('Close Window 2','',kbNoKey,cmCloseWindow2,hcNoContext,
       NewItem('Close Window 3','',kbNoKey,cmCloseWindow3,hcNoContext,
-      Nil)))))))),
+      Nil))))))))),
     NewSubMenu('~W~indow', 0, NewMenu(
       StdWindowMenuItems(Nil)), Nil)))))));            { Standard window  menu }
 END;
@@ -245,6 +255,23 @@ begin
 end;
 
 
+PROCEDURE TTvDemo.TimedBox;
+var
+  X: longint;
+  S: string;
+begin
+  X := TimedMessageBox ('Everything OK?', nil, mfConfirmation or mfOKCancel, 10);
+  case X of
+   cmCancel: MessageBox ('cmCancel', nil, mfOKButton);
+   cmOK: MessageBox ('cmOK', nil, mfOKButton);
+  else
+   begin
+    Str (X, S);
+    MessageBox (S, nil, mfOKButton);
+   end;
+  end;
+end;
+
 PROCEDURE TTvDemo.CloseWindow(var P : PGroup);
 BEGIN
   If Assigned(P) then
@@ -325,7 +352,9 @@ END;
 {                             MAIN PROGRAM START                            }
 {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
 VAR I: Integer; R: TRect; P: PGroup; MyApp: TTvDemo;
+{$IFDEF OS2PM}
     {$IFDEF OS_OS2} Message: QMSg; Event: TEvent; {$ENDIF}
+{$ENDIF OS2PM}
 BEGIN
    (*SystemPalette := CreateRGBPalette(256);            { Create palette }
    For I := 0 To 15 Do Begin
@@ -337,6 +366,7 @@ BEGIN
 
 
    MyApp.Run;                                         { Run the app }
+{$IFDEF OS2PM}
    {$IFDEF OS_OS2}
    while (MyApp.EndState = 0)
    AND WinGetMsg(Anchor, Message, 0, 0, 0) Do Begin
@@ -346,6 +376,7 @@ BEGIN
          Then MyApp.handleEvent(Event);
    End;
    {$ENDIF}
+{$ENDIF OS2PM}
    MyApp.Done;                                        { Dispose of app }
 
    {DisposeRGBPalette(SystemPalette);}
@@ -354,7 +385,10 @@ END.
 
 {
  $Log$
- Revision 1.3  2004-03-22 15:50:31  peter
+ Revision 1.4  2004-12-19 20:26:36  hajny
+   + TTimedDialog and TimedMessageBox added
+
+ Revision 1.3  2004/03/22 15:50:31  peter
    * compile fixes
 
  Revision 1.2  2002/09/07 15:06:38  peter

+ 263 - 0
fv/timeddlg.pas

@@ -0,0 +1,263 @@
+{
+   $Id$
+
+   Timed dialogs for Free Vision
+
+   Copyright (c) 2004 by Free Pascal core team
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public
+   License as published by the Free Software Foundation; either
+   version 2 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this library; if not, write to the Free
+   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************}
+UNIT timeddlg;
+
+{<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
+                                  INTERFACE
+{<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
+
+{====Include file to sort compiler platform out =====================}
+{$I Platform.inc}
+{====================================================================}
+
+{==== Compiler directives ===========================================}
+
+{$IFNDEF PPC_FPC}{ FPC doesn't support these switches }
+  {$F-} { Near calls are okay }
+  {$A+} { Word Align Data }
+  {$B-} { Allow short circuit boolean evaluations }
+  {$O+} { This unit may be overlaid }
+  {$G+} { 286 Code optimization - if you're on an 8088 get a real computer }
+  {$P-} { Normal string variables }
+  {$N-} { No 80x87 code generation }
+  {$E+} { Emulation is on }
+{$ENDIF}
+
+{$X+} { Extended syntax is ok }
+{$R-} { Disable range checking }
+{$S-} { Disable Stack Checking }
+{$I-} { Disable IO Checking }
+{$Q-} { Disable Overflow Checking }
+{$V-} { Turn off strict VAR strings }
+{====================================================================}
+
+USES objects, dialogs, fvconsts, drivers, views; { Standard GFV unit }
+
+type
+  TTimedDialog = object (TDialog)
+    Secs: longint;
+    constructor Init (var Bounds: TRect; ATitle: TTitleStr; ASecs: word);
+    constructor Load (var S: TStream);
+    procedure   GetEvent (var Event: TEvent); virtual;
+    procedure   Store (var S: TStream); virtual;
+  private
+    Secs0: longint;
+    Secs2: longint;
+    DayWrap: boolean;
+  end;
+  PTimedDialog = ^TTimedDialog;
+
+(* Must be always included in TTimeDialog! *)
+  TTimedDialogText = object (TStaticText)
+    constructor Init (var Bounds: TRect);
+    procedure   GetText (var S: string); virtual;
+  end;
+  PTimedDialogText = ^TTimedDialogText;
+
+const
+  RTimedDialog: TStreamRec = (
+    ObjType: idTimedDialog;
+{$IFDEF BP_VMTLink}                              { BP style VMT link }
+    VmtLink: Ofs (TypeOf (TTimedDialog)^);
+{$ELSE}                                          { Alt style VMT link }
+    VmtLink: TypeOf (TTimedDialog);
+{$ENDIF BP_VMTLink}
+    Load:    @TTimedDialog.Load;
+    Store:   @TTimedDialog.Store
+  );
+
+  RTimedDialogText: TStreamRec = (
+    ObjType: idTimedDialogText;
+{$IFDEF BP_VMTLink}                              { BP style VMT link }
+    VmtLink: Ofs (TypeOf (TTimedDialogText)^);
+{$ELSE}                                          { Alt style VMT link }
+    VmtLink: TypeOf (TTimedDialogText);
+{$ENDIF BP_VMTLink}
+    Load:    @TTimedDialogText.Load;
+    Store:   @TTimedDialogText.Store
+  );
+
+procedure RegisterTimedDialog;
+
+FUNCTION TimedMessageBox (Const Msg: String; Params: Pointer;
+  AOptions: Word; ASecs: Word): Word;
+
+{-TimedMessageBoxRect------------------------------------------------
+TimedMessageBoxRect allows the specification of a TRect for the message box
+to occupy.
+---------------------------------------------------------------------}
+FUNCTION TimedMessageBoxRect (Var R: TRect; Const Msg: String; Params: Pointer;
+  AOptions: Word; ASecs: Word): Word;
+
+
+{<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
+                                IMPLEMENTATION
+{<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
+
+USES
+  dos,
+  app, resource, msgbox;   { Standard GFV units }
+
+
+{***************************************************************************}
+{                            INTERFACE ROUTINES                             }
+{***************************************************************************}
+
+constructor TTimedDialogText.Init (var Bounds: TRect);
+begin
+  inherited Init (Bounds, '');
+end;
+
+
+procedure TTimedDialogText.GetText (var S: string);
+begin
+  if Owner <> nil
+(* and (TypeOf (Owner^) = TypeOf (TTimedDialog)) *)
+                  then
+   begin
+    Str (PTimedDialog (Owner)^.Secs, S);
+    S := #3 + S;
+   end
+  else
+   S := '';
+end;
+
+
+
+constructor TTimedDialog.Init (var Bounds: TRect; ATitle: TTitleStr;
+  ASecs: word);
+var
+  H, M, S, S100: word;
+begin
+  inherited Init (Bounds, ATitle);
+  GetTime (H, M, S, S100);
+  Secs0 := H * 3600 + M * 60 + S;
+  Secs2 := Secs0 + ASecs;
+  Secs := ASecs;
+  DayWrap := Secs2 > 24 * 3600;
+end;
+
+
+procedure TTimedDialog.GetEvent (var Event: TEvent);
+var
+  H, M, S, S100: word;
+  Secs1: longint;
+begin
+  inherited GetEvent (Event);
+  GetTime (H, M, S, S100);
+  Secs1 := H * 3600 + M * 60 + S;
+  if DayWrap then Inc (Secs1, 24 * 3600);
+  if Secs2 - Secs1 <> Secs then
+   begin
+    Secs := Secs2 - Secs1;
+    if Secs < 0 then
+     Secs := 0;
+(* If remaining seconds are displayed in one of included views, update them. *)
+    Redraw;
+   end;
+  with Event do
+   if (Secs = 0) and (What = evNothing) then
+    begin
+     What := evCommand;
+     Command := cmCancel;
+    end;
+end;
+
+
+constructor TTimedDialog.Load (var S: TStream);
+begin
+  inherited Load (S);
+  S.Read (Secs, SizeOf (Secs));
+  S.Read (Secs0, SizeOf (Secs0));
+  S.Read (Secs2, SizeOf (Secs2));
+  S.Read (DayWrap, SizeOf (DayWrap));
+end;
+
+
+procedure TTimedDialog.Store (var S: TStream);
+begin
+  inherited Store (S);
+  S.Write (Secs, SizeOf (Secs));
+  S.Write (Secs0, SizeOf (Secs0));
+  S.Write (Secs2, SizeOf (Secs2));
+  S.Write (DayWrap, SizeOf (DayWrap));
+end;
+
+
+
+function TimedMessageBox (const Msg: string; Params: pointer;
+  AOptions: word; ASecs: word): word;
+var
+  R: TRect;
+begin
+  R.Assign(0, 0, 40, 10);                            { Assign area }
+  if (AOptions AND mfInsertInApp = 0) then           { Non app insert }
+   R.Move((Desktop^.Size.X - R.B.X) div 2,
+      (Desktop^.Size.Y - R.B.Y) div 2)               { Calculate position }
+  else
+   R.Move((Application^.Size.X - R.B.X) div 2,
+      (Application^.Size.Y - R.B.Y) div 2);          { Calculate position }
+  TimedMessageBox := TimedMessageBoxRect (R, Msg, Params,
+    AOptions, ASecs);                                { Create message box }
+end;
+
+
+function TimedMessageBoxRect (var R: TRect; const Msg: string; Params: pointer;
+  AOptions: word; ASecs: word): word;
+var
+  Dlg: PTimedDialog;
+  TimedText: PTimedDialogText;
+begin
+  Dlg := New (PTimedDialog, Init (R, MsgBoxTitles [AOptions
+    and $3], ASecs));                                { Create dialog }
+  with Dlg^ do
+   begin
+    R.Assign (3, Size.Y - 5, Size.X - 2, Size.Y - 4);
+    New (TimedText, Init (R));
+    Insert (TimedText);
+    R.Assign (3, 2, Size.X - 2, Size.Y - 5);         { Assign area for text }
+   end;
+  TimedMessageBoxRect := MessageBoxRectDlg (Dlg, R, Msg, Params, AOptions);
+  Dispose (Dlg, Done);                               { Dispose of dialog }
+end;
+
+
+
+procedure RegisterTimedDialog;
+begin
+  RegisterType (RTimedDialog);
+  RegisterType (RTimedDialogText);
+end;
+
+
+begin
+  RegisterTimedDialog;
+end.
+
+{
+ $Log$
+ Revision 1.1  2004-12-19 20:25:11  hajny
+   + TTimedDialog and TimedMessageBox added
+
+
+}