Changeset 66


Ignore:
Timestamp:
Oct 10, 2024, 11:05:35 PM (6 weeks ago)
Author:
chronos
Message:
  • Added: Api calls to show windows.
Location:
branches/Independent
Files:
8 added
2 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • branches/Independent

    • Property svn:ignore
      •  

        old new  
        33Independent.lps
        44Independent.res
         5heaptrclog.trc
  • branches/Independent/Api.pas

    r65 r66  
    77
    88type
     9  THandle = NativeInt;
     10
     11  { THandles }
     12
     13  THandles = class(TList<THandle>)
     14    NewHandle: THandle;
     15    function AddNew: THandle;
     16  end;
     17
    918  { TApi }
    1019
     
    1322    procedure RunApp(Name: string); virtual; abstract;
    1423    procedure Sleep(Time: TDateTime); virtual; abstract;
     24    function CreateWindow: THandle; virtual; abstract;
     25    procedure SetWindowName(Handle: THandle; Name: string); virtual; abstract;
     26    procedure SetWindowRect(Handle: THandle; Rect: TRect); virtual; abstract;
     27    procedure SetWindowVisible(Handle: THandle; Visible: Boolean); virtual; abstract;
    1528  end;
    1629
     
    3851
    3952implementation
     53
     54{ THandles }
     55
     56function THandles.AddNew: THandle;
     57begin
     58  Result := NewHandle;
     59  Inc(NewHandle);
     60  Add(Result);
     61end;
    4062
    4163{ TApp }
  • branches/Independent/Apps.pas

    r65 r66  
    3030
    3131procedure TAppTest.Run(Context: TAppContext);
     32var
     33  Handle: THandle;
    3234begin
    3335  with Context.Api do begin
     
    3537    Sleep(OneSecond);
    3638    RunApp('Code');
     39    Handle := CreateWindow;
     40    SetWindowName(Handle, 'New window');
     41    SetWindowRect(Handle, Bounds(100, 100, 400, 200));
     42    SetWindowVisible(Handle, True);
     43
     44    Handle := CreateWindow;
     45    SetWindowName(Handle, 'Second window');
     46    SetWindowRect(Handle, Bounds(350, 150, 500, 300));
     47    SetWindowVisible(Handle, True);
    3748  end;
    3849end;
  • branches/Independent/Independent.lpi

    r65 r66  
    2424          <SearchPaths>
    2525            <IncludeFiles Value="$(ProjOutDir)"/>
     26            <OtherUnitFiles Value="Forms"/>
    2627            <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)-$(BuildMode)"/>
    2728          </SearchPaths>
     
    7374      </Unit>
    7475      <Unit>
    75         <Filename Value="FormMain.pas"/>
     76        <Filename Value="Forms/FormMain.pas"/>
    7677        <IsPartOfProject Value="True"/>
    7778        <ComponentName Value="FormName"/>
     
    99100        <IsPartOfProject Value="True"/>
    100101      </Unit>
     102      <Unit>
     103        <Filename Value="Forms/FormConsole.pas"/>
     104        <IsPartOfProject Value="True"/>
     105        <ComponentName Value="FormConsole"/>
     106        <ResourceBaseClass Value="Form"/>
     107      </Unit>
     108      <Unit>
     109        <Filename Value="Forms/FormScreen.pas"/>
     110        <IsPartOfProject Value="True"/>
     111        <ComponentName Value="FormScreen"/>
     112        <ResourceBaseClass Value="Form"/>
     113      </Unit>
    101114    </Units>
    102115  </ProjectOptions>
     
    108121    <SearchPaths>
    109122      <IncludeFiles Value="$(ProjOutDir)"/>
     123      <OtherUnitFiles Value="Forms"/>
    110124      <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)-$(BuildMode)"/>
    111125    </SearchPaths>
     
    131145      <Debugging>
    132146        <DebugInfoType Value="dsDwarf3"/>
     147        <UseHeaptrc Value="True"/>
    133148      </Debugging>
    134149      <Options>
  • branches/Independent/Independent.lpr

    r65 r66  
    11program Independent;
    2 
    3 {$mode objfpc}{$H+}
    42
    53uses
    64  {$IFDEF UNIX}
    7   cthreads,
     5  cthreads, clocale,
    86  {$ENDIF}
    97  {$IFDEF HASAMIGA}
     
    119  {$ENDIF}
    1210  Interfaces, // this includes the LCL widgetset
    13   Forms, FormMain, Os, Apps, Api, Console, FileSystem
     11  Forms, FormMain, FormScreen, SysUtils
    1412  { you can add units after this };
    1513
    1614{$R *.res}
    1715
     16{$if declared(UseHeapTrace)}
     17const
     18  HeapTraceLog = 'heaptrclog.trc';
     19{$ENDIF}
     20
    1821begin
     22  {$if declared(UseHeapTrace)}
     23  // Heap trace
     24  DeleteFile(ExtractFilePath(ParamStr(0)) + HeapTraceLog);
     25  SetHeapTraceOutput(ExtractFilePath(ParamStr(0)) + HeapTraceLog);
     26  {$ENDIF}
     27
    1928  RequireDerivedFormResource:=True;
    2029  Application.Scaled:=True;
  • branches/Independent/Os.pas

    r65 r66  
    5353    procedure RunApp(Name: string); override;
    5454    procedure Sleep(Time: TDateTime); override;
     55    function CreateWindow: THandle; override;
     56    procedure SetWindowName(Handle: THandle; Name: string); override;
     57    procedure SetWindowRect(Handle: THandle; Rect: TRect); override;
     58    procedure SetWindowVisible(Handle: THandle; Visible: Boolean); override;
     59  end;
     60
     61  { TWindow }
     62
     63  TWindow = class
     64    Handle: THandle;
     65    Name: string;
     66    Visible: Boolean;
     67    Rect: TRect;
     68  end;
     69
     70  { TWindows }
     71
     72  TWindows = class(TObjectList<TWindow>)
     73    function AddNew: TWindow;
     74    function SearchByHandle(Handle: THandle): TWindow;
    5575  end;
    5676
     
    5878
    5979  TSystem = class
     80  private
     81    FOnDraw: TNotifyEvent;
     82    procedure Redraw;
     83  public
    6084    Console: TConsole;
    6185    FileSystem: TFileSystem;
    6286    Apps: TApps;
    6387    RunningApps: TRunningApps;
     88    Windows: TWindows;
     89    Handles: THandles;
    6490    procedure RunApp(Name: string);
    6591    procedure Start;
    6692    constructor Create;
    6793    destructor Destroy; override;
     94    property OnDraw: TNotifyEvent read FOnDraw write FOnDraw;
    6895  end;
    6996
     
    153180end;
    154181
     182function TSystemApi.CreateWindow: THandle;
     183var
     184  Window: TWindow;
     185begin
     186  Window := System.Windows.AddNew;
     187  Window.Handle := System.Handles.AddNew;
     188  Result := Window.Handle;
     189end;
     190
     191procedure TSystemApi.SetWindowName(Handle: THandle; Name: string);
     192var
     193  Window: TWindow;
     194begin
     195  Window := System.Windows.SearchByHandle(Handle);
     196  if Assigned(Window) then begin
     197    Window.Name := Name;
     198    System.Redraw;
     199  end;
     200end;
     201
     202procedure TSystemApi.SetWindowRect(Handle: THandle; Rect: TRect);
     203var
     204  Window: TWindow;
     205begin
     206  Window := System.Windows.SearchByHandle(Handle);
     207  if Assigned(Window) then begin
     208    Window.Rect := Rect;
     209    System.Redraw;
     210  end;
     211end;
     212
     213procedure TSystemApi.SetWindowVisible(Handle: THandle; Visible: Boolean);
     214var
     215  Window: TWindow;
     216begin
     217  Window := System.Windows.SearchByHandle(Handle);
     218  if Assigned(Window) then begin
     219    Window.Visible := Visible;
     220    System.Redraw;
     221  end;
     222end;
     223
     224{ TWindows }
     225
     226function TWindows.AddNew: TWindow;
     227begin
     228  Result := TWindow.Create;
     229  Add(Result);
     230end;
     231
     232function TWindows.SearchByHandle(Handle: THandle): TWindow;
     233var
     234  I: Integer;
     235begin
     236  I := 0;
     237  while (I < Count) and (Items[I].Handle <> Handle) do Inc(I);
     238  if I < Count then Result := Items[I]
     239    else Result := nil;
     240end;
     241
    155242{ TSystem }
     243
     244procedure TSystem.Redraw;
     245begin
     246  if Assigned(FOnDraw) then FOnDraw(Self);
     247end;
    156248
    157249procedure TSystem.RunApp(Name: string);
     
    182274constructor TSystem.Create;
    183275begin
     276  Handles := THandles.Create;
     277  Windows := TWindows.Create;
    184278  Console := TConsole.Create;
    185279  FileSystem := TFileSystem.Create;
     
    194288  FreeAndNil(Console);
    195289  FreeAndNil(FileSystem);
     290  FreeAndNil(Windows);
     291  FreeAndNil(Handles);
    196292  inherited;
    197293end;
Note: See TracChangeset for help on using the changeset viewer.