home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue30 / system / LibExp / LibTestForm.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1998-01-11  |  8.1 KB  |  282 lines

  1. unit LibTestForm;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   DsgnIntf, LibIntf, StdCtrls, ExtCtrls, Tabs, Menus;
  8.  
  9. type
  10.   TLibExTest = class(TForm)
  11.     TabSet1: TTabSet;
  12.     Notebook1: TNotebook;
  13.     GroupBox1: TGroupBox;
  14.     Label1: TLabel;
  15.     BaseReg: TEdit;
  16.     GroupBox2: TGroupBox;
  17.     Label6: TLabel;
  18.     Label3: TLabel;
  19.     DisplayGrid: TCheckBox;
  20.     SnapToGrid: TCheckBox;
  21.     ShowComponentCaptions: TCheckBox;
  22.     GridSizeX: TEdit;
  23.     GridSizeY: TEdit;
  24.     GroupBox5: TGroupBox;
  25.     ComboBox1: TComboBox;
  26.     Image2: TImage;
  27.     cbLockState: TCheckBox;
  28.     Label5: TLabel;
  29.     PathAndBaseName: TLabel;
  30.     Label7: TLabel;
  31.     AppHandle: TLabel;
  32.     Label8: TLabel;
  33.     IDETime: TLabel;
  34.     Label9: TLabel;
  35.     WinSize: TLabel;
  36.     Label4: TLabel;
  37.     Image1: TImage;
  38.     GroupBox4: TGroupBox;
  39.     Label2: TLabel;
  40.     HelpClassName: TEdit;
  41.     ClassHelpOK: TButton;
  42.     GroupBox3: TGroupBox;
  43.     ComboBox2: TComboBox;
  44.     Label10: TLabel;
  45.     Button1: TButton;
  46.     GroupBox6: TGroupBox;
  47.     SelectionType: TLabel;
  48.     SelectionName: TLabel;
  49.     FirstSelectionType: TLabel;
  50.     SelectedList: TListBox;
  51.     SetLockState: TCheckBox;
  52.     SelectAll: TButton;
  53.     DeleteAll: TButton;
  54.     PropertyList: TListBox;
  55.     EventList: TListBox;
  56.     Label11: TLabel;
  57.     Label12: TLabel;
  58.     Button2: TButton;
  59.     procedure FormCreate(Sender: TObject);
  60.     procedure HelpClassNameChange(Sender: TObject);
  61.     procedure ClassHelpOKClick(Sender: TObject);
  62.     procedure FormPaint(Sender: TObject);
  63.     procedure TabSet1Change(Sender: TObject; NewTab: Integer;
  64.       var AllowChange: Boolean);
  65.     procedure ComboBox1Change(Sender: TObject);
  66.     procedure Button1Click(Sender: TObject);
  67.     procedure SetLockStateClick(Sender: TObject);
  68.     procedure SelectAllClick(Sender: TObject);
  69.     procedure DeleteAllClick(Sender: TObject);
  70.     procedure Button2Click(Sender: TObject);
  71.   private
  72.     { Private declarations }
  73.     procedure GetPropertiesProc (Prop: TIProperty);
  74.     procedure GetEventsProc (Prop: TIProperty);
  75.   public
  76.     { Public declarations }
  77.   end;
  78.  
  79. implementation
  80.  
  81. {$R *.DFM}
  82.  
  83. procedure TLibExTest.FormCreate(Sender: TObject);
  84. begin
  85.     TabSet1.Tabs := NoteBook1.Pages;
  86.     ComboBox1.ItemIndex := 0;
  87.     ComboBox2.ItemIndex := 0;
  88.     ComboBox1Change (Self);
  89. end;
  90.  
  91. procedure TLibExTest.HelpClassNameChange(Sender: TObject);
  92. begin
  93.     ClassHelpOK.Enabled := HelpClassName.Text <> '';
  94. end;
  95.  
  96. procedure TLibExTest.ClassHelpOKClick(Sender: TObject);
  97. begin
  98.     DelphiIDE.ShowClassHelp (HelpClassName.Text);
  99. end;
  100.  
  101. procedure TLibExTest.FormPaint(Sender: TObject);
  102. var
  103.     Item: TIPaletteItem;
  104. begin
  105.     with DelphiIDE do
  106.         if GetToolSelected then begin
  107.             Label4.Visible := True;
  108.             Image1.Visible := True;
  109.             Item := GetCurCompClass;
  110.             try
  111.                 Item.Paint (Image1.Canvas, 0, 0);
  112.             finally
  113.                 Item.Free;
  114.             end;
  115.         end
  116.         else begin
  117.             Label4.Visible := False;
  118.             Image1.Visible := False;
  119.         end;
  120. end;
  121.  
  122. procedure TLibExTest.TabSet1Change (Sender: TObject; NewTab: Integer;
  123.                                     var AllowChange: Boolean);
  124. var
  125.     r: TRect;
  126.     Idx: Integer;
  127.     Opts: TDesignerOptions;
  128.     Selection: TComponentList;
  129. begin
  130.     NoteBook1.PageIndex := NewTab;
  131.     { Case out on the active page name }
  132.     if NoteBook1.Pages [NewTab] = 'Miscellaneous' then with DelphiIDE do begin
  133.         BaseReg.Text := GetBaseRegKey;
  134.         cbLockState.Checked := LockState;
  135.         PathAndBaseName.Caption := GetPathAndBaseExeName;
  136.         AppHandle.Caption := '$' + IntToHex (GetAppHandle, 8);
  137.         IDETime.Caption := '$' + IntToHex (GetCurTime, 8);
  138.         r := GetMainWindowSize;
  139.         WinSize.Caption := Format ('(%d,%d)-(%d,%d)', [r.Left, r.Top, r.Right, r.Bottom]);
  140.     end;
  141.  
  142.     if NoteBook1.Pages [NewTab] = 'Selections' then with CompLib do begin
  143.         if GetSelectionName <> '' then
  144.             SelectionName.Caption := 'Name of selected component - ' + GetSelectionName
  145.         else SelectionName.Caption := '--No component selected--';
  146.  
  147.         if GetSelectionType <> '' then
  148.             SelectionType.Caption := 'Type of selected component - ' + GetSelectionType
  149.         else SelectionType.Caption := '--No component selected--';
  150.  
  151.         if GetFirstSelectionType <> '' then
  152.             FirstSelectionType.Caption := 'Type of first selected - ' + GetFirstSelectionType
  153.         else FirstSelectionType.Caption := '--No component selected--';
  154.  
  155.         Selection := TComponentList.Create;
  156.         try
  157.             { Delphi 3 Bug - only call GetSelection if there is a selection }
  158.             if GetFirstSelectionType <> '' then GetSelection (Selection);
  159.  
  160.             SelectedList.Clear;
  161.             if Selection.Count = 0 then SelectedList.Items.Add ('---no selection---') else
  162.                 for Idx := 0 to Selection.Count - 1 do
  163.                     with Selection [Idx] as TControl do
  164.                         SelectedList.Items.Add (Format ('%s (%s)', [Name, ClassName]));
  165.  
  166.         finally
  167.             Selection.Free;
  168.         end;
  169.  
  170.         Self.SetLockState.Checked := DelphiIDE.LockState;
  171.     end;
  172.  
  173.     if NoteBook1.Pages [NewTab] = 'More Selection Info' then with CompLib do begin
  174.         PropertyList.Clear;
  175.         EventList.Clear;
  176.         GetProperties (pkProperties, GetPropertiesProc);
  177.         GetProperties (pkEvents, GetEventsProc);
  178.     end;
  179.  
  180.     if NoteBook1.Pages [NewTab] = 'Form Designer' then with DelphiIDE do begin
  181.         GetDesignerOptions (Opts);
  182.         DisplayGrid.Checked := Opts.DisplayGrid;
  183.         SnapToGrid.Checked := Opts.SnapToGrid;
  184.         ShowComponentCaptions.Checked := Opts.ShowComponentCaptions;
  185.         GridSizeX.Text := IntToStr (Opts.GridSizeX);
  186.         GridSizeY.Text := IntToStr (Opts.GridSizeY);
  187.     end;
  188. end;
  189.  
  190. procedure TLibExTest.ComboBox1Change(Sender: TObject);
  191. var
  192.     Item: TIPaletteItem;
  193.     Cls: TComponentClass;
  194. begin
  195.     with DelphiIDE do begin
  196.         case ComboBox1.ItemIndex of
  197.             0:      Cls := TMainMenu;
  198.             1:      Cls := TPopupMenu;
  199.             2:      Cls := TLabel;
  200.             3:      Cls := TEdit;
  201.             4:      Cls := TMemo;
  202.             5:      Cls := TButton;
  203.             6:      Cls := TCheckBox;
  204.             7:      Cls := TRadioButton;
  205.             8:      Cls := TListBox;
  206.             9:      Cls := TComboBox;
  207.             10:     Cls := TScrollBar;
  208.             11:     Cls := TGroupBox;
  209.             12:     Cls := TRadioGroup;
  210.             13:     Cls := TPanel;
  211.             else    Cls := Nil;
  212.         end;
  213.  
  214.         if Cls = Nil then Image2.Visible := False else begin
  215.             Item := GetPaletteItem (Cls);
  216.             try
  217.                 Item.Paint (Image2.Canvas, 0, 0);
  218.             finally
  219.                 Item.Free;
  220.             end;
  221.             Image2.Visible := True;
  222.             Image2.Invalidate;
  223.         end;
  224.     end;
  225. end;
  226.  
  227. procedure TLibExTest.Button1Click (Sender: TObject);
  228. begin
  229.     { This will do nothing if there's no active form }
  230.     DelphiIDE.ExecDesignDialog (TDesignDialog (ComboBox2.ItemIndex));
  231. end;
  232.  
  233. { @@@@ }
  234.  
  235. procedure TLibExTest.GetPropertiesProc (Prop: TIProperty);
  236. begin
  237.     PropertyList.Items.Add (Prop.GetName);
  238.     Prop.Free;
  239. end;
  240.  
  241. procedure TLibExTest.GetEventsProc (Prop: TIProperty);
  242. begin
  243.     EventList.Items.Add (Prop.GetName);
  244.     Prop.Free;
  245. end;
  246.  
  247. procedure TLibExTest.SetLockStateClick (Sender: TObject);
  248. begin
  249.     CompLib.SetLockState (SetLockState.Checked);
  250. end;
  251.  
  252. procedure TLibExTest.SelectAllClick (Sender: TObject);
  253. begin
  254.     CompLib.EditAction (eaSelectAll);
  255. end;
  256.  
  257. procedure TLibExTest.DeleteAllClick(Sender: TObject);
  258. begin
  259.     CompLib.EditAction (eaSelectAll);
  260.     CompLib.EditAction (eaCut);
  261. end;
  262.  
  263. procedure TLibExTest.Button2Click(Sender: TObject);
  264. var
  265.     Form: TIForm;
  266.     module: TIModule;
  267. begin
  268.     Form := CompLib.GetActiveForm;
  269.     if Form <> Nil then begin
  270.         module := Form.GetModule;
  271.         if module <> Nil then Module.SwapSourceFormView;        
  272.     end;     
  273. end;
  274.  
  275. end.
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.