home *** CD-ROM | disk | FTP | other *** search
- unit WABD_FormSecEditor;
-
- interface
-
- {$I kbmWABD.inc}
-
- {$IFDEF VER100}
- {$ASSERTIONS ON}
- {$ENDIF}
-
- uses
- {$ifdef LEVEL6}
- DesignIntf,
- {$else}
- DsgnIntf,
- {$endif}
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- WABD_Objects, ExtCtrls, Buttons, StdCtrls, ShellAPI;
-
- type
- TInvisWin = class(TPanel)
- protected
- FSel : boolean;
- procedure SetSel(b: boolean);
- procedure WndProc(var Message: TMessage); override;
- procedure CreateParams(var Params: TCreateParams); override;
- procedure PaintSquares(var ps: TPaintStruct);
- public
- Buddy : TControl;
- property Selected: boolean read FSel write SetSel;
- end;
-
- TFormSectionEditor = class(TForm)
- ToolPanel: TPanel;
- AnchorSpeed: TSpeedButton;
- ImageSpeed: TSpeedButton;
- LabelSpeed: TSpeedButton;
- MemoSpeed: TSpeedButton;
- ButtonSpeed: TSpeedButton;
- EditSpeed: TSpeedButton;
- ComboSpeed: TSpeedButton;
- RadioSpeed: TSpeedButton;
- ListSpeed: TSpeedButton;
- CheckSpeed: TSpeedButton;
- HTMLEmbedSpeed: TSpeedButton;
- PreviewBut: TButton;
- GridBut: TSpeedButton;
- ScrollBox1: TScrollBox;
- SelectSpeed: TSpeedButton;
- LiveImageSpeed: TSpeedButton;
- pStatus: TPanel;
- HTMLFileEmbedSpeed: TSpeedButton;
- UploadFileSpeed: TSpeedButton;
- procedure PanelMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure PanelMouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- procedure PanelMouseUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure FormCreate(Sender: TObject);
- procedure SecButSpeedClick(Sender: TObject);
- procedure GridButClick(Sender: TObject);
- procedure FormKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- procedure PreviewButClick(Sender: TObject);
- procedure ScrollBox1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure PanelDblClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- {$ifdef LEVEL6}
- MyDesigner : IDesigner;
- {$else}
- {$ifdef LEVEL5}
- MyDesigner : IFormDesigner;
- {$else}
- {$ifdef LEVEL4}
- MyDesigner : IFormDesigner;
- {$else}
- {$ifdef LEVEL3}
- MyDesigner : TFormDesigner; // Delphi 3, C++ Builder 3
- {$endif}
- {$endif}
- {$endif}
- {$endif}
-
- FS : TWABD_FormSection;
- DownX : integer;
- DownY : integer;
- Moving : boolean;
- Sizing : boolean;
- DetectChanges : boolean;
- OldSel : TInvisWin;
- ViewPanel : TPaintPanel;
- LastTag : integer;
- LookFor : TWABD_SectionObject;
- procedure Init;
- function GetObj(Tag: integer): TWABD_SectionObject;
- procedure ReflectedNotify(Sender: TObject; AComponent: TComponent; Operation: TOperation);
- procedure ChildChanged(Sender: TObject);
- procedure SetPanel(p: TInvisWin; Active: boolean);
- procedure SetSpecialProperties(c: TControl);
- procedure SetAllProperties(c: TWinControl);
- end;
-
- var
- FormSectionEditor: TFormSectionEditor;
-
- implementation
-
- uses WABD_FormEditor, TypInfo;
-
- {$R *.DFM}
-
- function GetRegion(Obj: TWABD_SectionObject; X, Y: integer): integer;
- const
- BORDER = 5;
- var
- px, py : integer;
- begin
- px := 1;
- if X < BORDER then px := 0;
- if X > Obj.Width-BORDER then px := 2;
-
- py := 1;
- if Y < BORDER then py := 0;
- if Y > Obj.Height-BORDER then py := 2;
-
- Result := py * 3 + px + 1;
- end;
-
- function GetRegCursor(Reg: integer): TCursor;
- begin
- Result := crDefault;
- case Reg of
- 1, 9 : Result := crSizeNWSE;
- 3, 7 : Result := crSizeNESW;
- 2, 8 : Result := crSizeNS;
- 4, 6 : Result := crSizeWE;
- 5 : Result := crDefault;
- end;
- end;
-
- function TFormSectionEditor.GetObj(Tag: integer): TWABD_SectionObject;
- begin
- if (Tag-1 < 0) or (Tag-1 >= FS.ChildCount) then begin
- Result := nil;
- exit;
- end;
-
- Result := fs.Children[Tag-1] as TWABD_SectionObject;
- Assert(Result<>nil, 'Result = nil');
- end;
-
- procedure TFormSectionEditor.SetPanel(p: TInvisWin; Active: boolean);
- begin
- if Active then begin
- p.Color := clActiveCaption;
- p.Font.Color := clCaptionText;
- if OldSel<>nil then SetPanel(OldSel, False);
- OldSel := p;
- (p as TInvisWin).Selected := True;
- end else begin
- p.Color := clInactiveCaption;
- p.Font.Color := clInactiveCaptionText;
- (p as TInvisWin).Selected := False;
- end;
- end;
-
- procedure TFormSectionEditor.Init;
- var
- i : integer;
- c : TControl;
- Child : TWABD_Object;
- begin
- if not DetectChanges then exit;
-
- OldSel := nil;
- Caption := 'WABD Form Section Editor - ' + fs.Name;
-
- // Remove the old ones first
- for i := ScrollBox1.ControlCount-1 downto 0 do begin
- c := ScrollBox1.Controls[i];
- c.Free;
- end;
-
- FS.OnChange := ChildChanged;
- for i := 0 to FS.ChildCount-1 do begin
- Child := FS.Children[i] as TWABD_SectionObject;
- Child.OnChange := ChildChanged;
- end;
-
- c := FS.Object_To_Control(ScrollBox1);
- c.Width := 1024;
- c.Height := 1024;
- ViewPanel := c as TPaintPanel;
- ViewPanel.DesignMode := GridBut.Down;
- ViewPanel.OnMouseDown := ScrollBox1MouseDown;
-
- SetAllProperties(ViewPanel);
- end;
-
- procedure TFormSectionEditor.SetSpecialProperties(c: TControl);
- var
- iw : TInvisWin;
- Sel : boolean;
- begin
- if (c is TPaintPanel) then begin
- (c as TPaintPanel).DrawPic := False;
- exit;
- end;
-
- Sel := GetObj(c.Tag) = LookFor;
-
- iw := TInvisWin.Create(Self);
- iw.Parent := c.Parent;
- iw.Buddy := c;
- iw.Left := c.Left;
- iw.Top := c.Top;
- iw.Width := c.Width;
- iw.Height := c.Height;
- iw.OnMouseDown := PanelMouseDown;
- iw.OnMouseMove := PanelMouseMove;
- iw.OnMouseUp := PanelMouseUp;
- iw.OnDblClick := PanelDblClick;
- SetPanel(iw, Sel);
- end;
-
- procedure TFormSectionEditor.SetAllProperties(c: TWinControl);
- var
- i : integer;
- Child : TControl;
- begin
- SetSpecialProperties(c);
- for i := 0 to c.ControlCount-1 do begin
- Child := c.Controls[i];
- if (Child is TWinControl) then begin
- SetAllProperties(Child as TWinControl);
- end else begin
- SetSpecialProperties(Child);
- end;
- end;
- end;
-
- procedure TFormSectionEditor.PanelMouseDown(Sender: TObject;
- Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- var
- s : TWABD_SectionObject;
- p : TInvisWin;
- x1,y1:integer;
- begin
- DownX := X;
- DownY := Y;
-
- // Get component pointed at.
- p := Sender as TInvisWin;
- s := GetObj(p.Buddy.Tag);
- Assert(s<>nil, 's = nil');
- MyDesigner.SelectComponent(s);
-
- // Check if sizing or moving.
- x1 := p.Left + (X-DownX);
- y1 := p.Top + (Y-DownY);
-
- // Check if moved at all. If not, just exit.
- if (X>=p.Width-5) or (Y>=p.Height-5) then
- Sizing:=true
- else
- Moving:=true;
- //ShowMessage(Format('X,Y=%d,%d, p.Left,p.Top=%d,%d pWidth,p.Height=%d,%d',[X,Y,p.Left,p.Top,p.Width,p.Height]));
-
- // Show selection.
- SetPanel(p, True);
- p.Buddy.BringToFront;
- p.BringToFront;
- OldSel := p;
- end;
-
- procedure TFormSectionEditor.PanelMouseMove(Sender: TObject;
- Shift: TShiftState; X, Y: Integer);
- var
- p : TInvisWin;
- s : TWABD_SectionObject;
- x1,y1: integer;
- w, h : integer;
- begin
- if not (Moving or Sizing) then exit;
-
- // Calculate placement/size.
- p := Sender as TInvisWin;
- x1 := (X-DownX);
- y1 := (Y-DownY);
- if GridBut.Down then begin
- x1 := (x1 div FS.GridX) * FS.GridX;
- y1 := (y1 div FS.GridY) * FS.GridY;
- end;
-
- // If moving.
- if Moving then
- begin
- // Check if moved at all. If not, just exit.
- x1:=x1+p.Left;
- y1:=y1+p.Top;
- if (x1=p.Left) and (y1=p.Top) then exit;
-
- w:=p.Width;
- h:=p.Height;
- end
- else
- // Sizing.
- begin
- // If not change of size.
- if (p.Width=X) and (p.Height=Y) then exit;
-
- x1:=p.Left;
- y1:=p.Top;
- w:=X;
- h:=Y;
- end;
-
- // OK, moved or sized, update component.
- p.SetBounds(x1, y1, w, h);
- p.Buddy.SetBounds(x1, y1, w, h);
- p.Invalidate;
- p.Buddy.Invalidate;
- s := GetObj(p.Buddy.Tag);
- DetectChanges := False;
- s.LeftPos := p.Left;
- s.TopPos := p.Top;
- s.Width := p.Width;
- s.Height := p.Height;
- p.Buddy.Refresh;
- DetectChanges := True;
- MyDesigner.Modified;
- end;
-
- procedure TFormSectionEditor.PanelMouseUp(Sender: TObject;
- Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- var
- p : TInvisWin;
- w,h:integer;
- s : TWABD_SectionObject;
- begin
- // Check if to resize to grid.
- if Sizing and GridBut.Down then
- begin
- p := Sender as TInvisWin;
- w := (p.Buddy.Width div FS.GridX) * FS.GridX;
- h := (p.Buddy.Height div FS.GridY) * FS.GridY;
- if w<=0 then w:=FS.GridX;
- if h<=0 then h:=FS.GridY;
- s := GetObj(p.Buddy.Tag);
- p.SetBounds(p.Left, p.Top, w, h);
- p.Buddy.SetBounds(p.Left, p.Top, w, h);
- s.Width := p.Width;
- s.Height := p.Height;
- p.Invalidate;
- p.Buddy.Invalidate;
- end;
- Sizing := False;
- Moving := False;
- end;
-
- procedure TFormSectionEditor.FormCreate(Sender: TObject);
- begin
- Moving := False;
- DetectChanges := True;
- OldSel := nil;
- ViewPanel := nil;
- LastTag := -1;
- end;
-
- procedure TFormSectionEditor.ReflectedNotify(Sender: TObject; AComponent: TComponent; Operation: TOperation);
- begin
- if (AComponent = FS) and (Operation = opRemove) then begin
- FS := nil;
- Visible := False;
- end;
-
- if AComponent is TWABD_SectionObject then
- if (AComponent as TWABD_SectionObject).Parent = FS then Init;
- end;
-
- procedure TFormSectionEditor.ChildChanged(Sender: TObject);
- begin
- if not DetectChanges then exit;
-
- if (Sender is TWABD_SectionObject) then
- if (Sender as TWABD_SectionObject).Parent = FS then Init;
-
- if Sender = FS then Init;
- end;
-
- procedure TFormSectionEditor.SecButSpeedClick(Sender: TObject);
- begin
- // (Owner as TWABDFormEditor).AddSectionLevel((Sender as TControl).Tag);
- LastTag := (Sender as TControl).Tag;
- end;
-
-
- procedure TFormSectionEditor.GridButClick(Sender: TObject);
- begin
- ViewPanel.DesignMode := GridBut.Down;
- ViewPanel.Invalidate;
- end;
-
- procedure TFormSectionEditor.FormKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- var
- c : TWABD_Object;
- begin
- if (OldSel<>nil) and (Key = 46) then begin
- c := GetObj(OldSel.Buddy.Tag);
- // if c<>nil then ShowMessage(Format('Name, Class = %s, %s', [c.name, c.ClassName]));
- c.Free;
- MyDesigner.SelectComponent(nil);
- end;
- end;
-
- procedure TFormSectionEditor.PreviewButClick(Sender: TObject);
- var
- f : string;
- h : string;
- fstm : TFileStream;
- rc : integer;
- begin
- f := 'LocalTemp.htm';
- h := '<HTML><BODY>' + FS.Object_To_HTML + '</BODY></HTML>';
- fstm := TFileStream.Create(f, fmCreate or fmOpenWrite or fmShareDenyWrite);
- fstm.Write(h[1], Length(h));
- fstm.Free;
-
- rc := ShellExecute(Handle, 'open', PChar(f), nil, nil, SW_SHOWNORMAL);
- if (rc <= 32) then ShowMessage('Unable to execute: ' + f + #13#10 + 'Browser not installed?');
- end;
-
-
-
- procedure TInvisWin.WndProc(var Message: TMessage);
- var
- ps : TPaintStruct;
- begin
- case Message.Msg of
- WM_ERASEBKGND: Message.Result := 1;
- WM_PAINT: begin
- BeginPaint(Handle, ps);
- if FSel then PaintSquares(ps);
- EndPaint(Handle, ps);
- Message.Result := 1;
- end;
- else
- inherited WndProc(Message);
- end;
- end;
-
- procedure TInvisWin.PaintSquares(var ps: TPaintStruct);
- var
- c : TCanvas;
- i : integer;
- mx, my : integer;
- x, y : integer;
- R : TRect;
- begin
- c := TCanvas.Create;
- c.Handle := ps.hdc;
-
- c.Brush.Color := clBlack;
- mx := Width div 2;
- my := Height div 2;
-
- for i := 0 to 7 do begin
- x := 0;
- y := 0;
- case i of
- 0, 1, 2 : y := 0;
- 3, 4 : y := my - 2;
- 5, 6, 7 : y := Height - 5;
- end;
- case i of
- 0, 3, 5 : x := 0;
- 1, 6 : x := mx - 2;
- 2, 4, 7 : x := Width - 5;
- end;
- R := Rect(x, y, x+5, y+5);
- c.FillRect(R);
- end;
-
- c.Free;
- end;
-
- procedure TInvisWin.SetSel(b: boolean);
- begin
- FSel := b;
- Invalidate;
- if Buddy<>nil then Buddy.Invalidate;
- end;
-
- procedure TInvisWin.CreateParams(var Params: TCreateParams);
- begin
- inherited;
- Params.ExStyle := Params.ExStyle or WS_EX_TRANSPARENT;
- end;
-
- procedure TFormSectionEditor.ScrollBox1MouseDown(Sender: TObject;
- Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- var
- wo : TWABD_SectionObject;
- begin
- // Check if to select formsection.
- if LastTag = -1 then
- begin
- MyDesigner.SelectComponent(FS);
- if OldSel<>nil then SetPanel(OldSel, False);
- OldSel := nil;
- exit;
- end;
-
- // Else add a component.
- DetectChanges := False;
- wo := (Owner as TWABDFormEditor).AddSectionLevel(LastTag);
- SelectSpeed.Down := True;
- LastTag := -1;
-
- if GridBut.Down then begin
- X := (X div FS.GridX) * FS.GridX;
- Y := (Y div FS.GridY) * FS.GridY;
- end;
-
- wo.LeftPos := X;
- wo.TopPos := Y;
- LookFor := wo;
- DetectChanges := True;
- Init;
- end;
-
- procedure TFormSectionEditor.PanelDblClick(Sender: TObject);
- var
- p : TInvisWin;
- s : TWABD_Object;
- nm : TMethod;
- MethName : string;
- wb : TWABD_Button;
- wi : TWABD_Base_Image;
- wt : TWABD_Table;
- begin
- p := Sender as TInvisWin;
- s := GetObj(p.Buddy.Tag);
- Assert(s<>nil, 's = nil');
-
- if s is TWABD_Button then begin
- wb := s as TWABD_Button;
- if Assigned(wb.OnUserClick) then begin
- nm := TMethod(wb.OnUserClick);
- MethName := MyDesigner.GetMethodName(nm);
- end else begin
- MethName := s.Name+'UserClick';
- nm := MyDesigner.CreateMethod(MethName, GetTypeData(TypeInfo(TNotifyEvent)));
- wb.OnUserClick := TNotifyEvent(nm);
- end;
- MyDesigner.ShowMethod(MethName);
- end;
-
- if s is TWABD_Base_Image then begin
- wi := s as TWABD_Base_Image;
- if Assigned(wi.OnMouseDown) then begin
- nm := TMethod(wi.OnMouseDown);
- MethName := MyDesigner.GetMethodName(nm);
- ShowMessage('MethName = ' + MethName);
- end else begin
- MethName := s.Name+'MouseDown';
- nm := MyDesigner.CreateMethod(MethName, GetTypeData(TypeInfo(TWABD_MouseDown)));
- wi.OnMouseDown := TWABD_MouseDown(nm);
- end;
- MyDesigner.ShowMethod(MethName);
- end;
-
- if s is TWABD_Table then begin
- wt := s as TWABD_Table;
- if Assigned(wt.OnUserClick) then begin
- nm := TMethod(wt.OnUserClick);
- MethName := MyDesigner.GetMethodName(nm);
- end else begin
- MethName := s.Name+'UserClick';
- nm := MyDesigner.CreateMethod(MethName, GetTypeData(TypeInfo(TWABDTableClick)));
- wt.OnUserClick := TWABDTableClick(nm);
- end;
- MyDesigner.ShowMethod(MethName);
- end;
- end;
-
-
- end.
-