From 3d203b58185f8d703d638fe762167291f3dc055c Mon Sep 17 00:00:00 2001 From: graemeg Date: Mon, 19 May 2008 15:13:26 +0000 Subject: * Merged my private graemeg branch changes (r752:r781) into trunk. These changes are required to change all componens from 1-based indexing to 0-based indexing. --- examples/apps/uidesigner/newformdesigner.pas | 50 +++++++--------------- examples/apps/uidesigner/uidesigner.lpr | 2 +- examples/apps/uidesigner/vfddesigner.pas | 43 ++++++++----------- examples/apps/uidesigner/vfdeditors.pas | 28 +++++++++---- examples/apps/uidesigner/vfdfile.pas | 41 +++++++++--------- examples/apps/uidesigner/vfdformparser.pas | 40 ++++++++---------- examples/apps/uidesigner/vfdforms.pas | 49 ++++++++-------------- examples/apps/uidesigner/vfdmain.pas | 52 +++++++++-------------- examples/apps/uidesigner/vfdpropeditgrid.pas | 46 ++++++++++---------- examples/apps/uidesigner/vfdprops.pas | 63 ++++++++++++++++------------ examples/apps/uidesigner/vfdresizer.pas | 17 ++++---- examples/apps/uidesigner/vfdutils.pas | 4 +- examples/apps/uidesigner/vfdwidgetclass.pas | 4 +- examples/apps/uidesigner/vfdwidgets.pas | 6 ++- 14 files changed, 204 insertions(+), 241 deletions(-) (limited to 'examples/apps') diff --git a/examples/apps/uidesigner/newformdesigner.pas b/examples/apps/uidesigner/newformdesigner.pas index 175e4fa6..8a96997c 100644 --- a/examples/apps/uidesigner/newformdesigner.pas +++ b/examples/apps/uidesigner/newformdesigner.pas @@ -1,7 +1,7 @@ { - fpGUI - Free Pascal GUI Library + fpGUI - Free Pascal GUI Toolkit - Copyright (C) 2006 - 2007 See the file AUTHORS.txt, included in this + Copyright (C) 2006 - 2008 See the file AUTHORS.txt, included in this distribution, for details of the copyright. See the file COPYING.modifiedLGPL, included in this distribution, @@ -75,7 +75,6 @@ TfrmMain = class(TfpgForm) previewmenu: TfpgPopupMenu; {@VFD_HEAD_END: frmMain} mru: TfpgMRU; - constructor Create(AOwner: TComponent); override; destructor Destroy; override; function GetSelectedWidget: TVFDWidgetClass; @@ -89,11 +88,11 @@ TfrmMain = class(TfpgForm) TPropertyList = class(TObject) private FList: TList; + function GetCount: integer; public Widget: TfpgWidget; constructor Create; destructor Destroy; override; - function GetCount: integer; procedure Clear; property Count: integer read GetCount; procedure AddItem(aProp: TVFDWidgetProperty); @@ -346,7 +345,7 @@ procedure TfrmMain.AfterCreate; SetPosition(116, 60, 200, 22); Items.Add('-'); FontDesc := '#List'; - FocusItem := 1; + FocusItem := 0; end; filemenu := TfpgPopupMenu.Create(self); @@ -415,7 +414,7 @@ procedure TfrmMain.AfterCreate; x := 0; - for n := 1 to VFDWidgetCount do + for n := 0 to VFDWidgetCount-1 do begin wgc := VFDWidget(n); btn := TwgPaletteButton.Create(wgpalette); @@ -457,12 +456,10 @@ procedure TfrmMain.OnPaletteClick(Sender: TObject); if TwgPaletteButton(Sender).Down then begin s := TwgPaletteButton(Sender).VFDWidget.WidgetClass.ClassName; - i := chlPalette.Items.IndexOf(s); - if i >= 0 then - chlPalette.FocusItem := i + 1; - end - else - chlPalette.FocusItem := 1; + chlPalette.FocusItem := chlPalette.Items.IndexOf(s); + end; + if chlPalette.FocusItem = -1 then + chlPalette.FocusItem := 0; end; { TfrmProperties } @@ -665,20 +662,11 @@ destructor TfrmProperties.Destroy; procedure TPropertyList.AddItem(aProp: TVFDWidgetProperty); begin - { - result := TPropertyLine.Create; - result.name := aPropName; - result.propclass := apropclass; - result.value := aPropName; -} FList.Add(aProp); end; procedure TPropertyList.Clear; - //var - // n : integer; begin - //for n:=0 to FList.Count-1 do TObject(FList[n]).Free; FList.Clear; end; @@ -702,17 +690,17 @@ function TPropertyList.GetCount: integer; function TPropertyList.GetItem(index: integer): TVFDWidgetProperty; begin - if (index < 1) or (index > Count) then + if (index < 0) or (index > Count-1) then Result := nil else - Result := TVFDWidgetProperty(FList[index - 1]); + Result := TVFDWidgetProperty(FList[index]); end; { TwgPropertyList } constructor TwgPropertyList.Create(AOwner: TComponent); begin - inherited; + inherited Create(AOwner); NameWidth := 80; editor := nil; OnChange := @OnRowChange; @@ -741,10 +729,9 @@ procedure TwgPropertyList.DrawItem(num: integer; rect: TfpgRect; flags: integer) prop: TVFDWidgetProperty; r: TfpgRect; begin - //inherited; prop := Props.GetItem(num); if prop = nil then - Exit; + Exit; //==> x := rect.left; y := rect.top; @@ -782,9 +769,7 @@ function TwgPropertyList.RowHeight: integer; procedure TwgPropertyList.OnUpdateProperty(Sender: TObject); begin -// writeln('updating property...'); editor.StoreValue(props.Widget); -// props.Widget.UpdateWindowPosition; end; procedure TwgPropertyList.HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); @@ -887,8 +872,8 @@ destructor TfrmMain.Destroy; function TfrmMain.GetSelectedWidget: TVFDWidgetClass; begin - if chlPalette.FocusItem > 1 then - Result := TVFDWidgetClass(chlPalette.Items.Objects[chlPalette.FocusItem - 1]) + if chlPalette.FocusItem > 0 then + Result := TVFDWidgetClass(chlPalette.Items.Objects[chlPalette.FocusItem]) else Result := nil; end; @@ -899,7 +884,7 @@ procedure TfrmMain.SetSelectedWidget(wgc: TVFDWidgetClass); begin if wgc = nil then begin - chlPalette.FocusItem := 1; + chlPalette.FocusItem := 0; for n := 0 to wgpalette.ComponentCount - 1 do if wgpalette.Components[n] is TwgPaletteButton then TwgPaletteButton(wgpalette.Components[n]).Down := False; @@ -943,10 +928,7 @@ procedure TwgPropertyList.AllocateEditor; procedure TwgPalette.HandlePaint; begin -// inherited HandlePaint; - Canvas.BeginDraw; Canvas.Clear(clWindowBackground); - Canvas.EndDraw; end; diff --git a/examples/apps/uidesigner/uidesigner.lpr b/examples/apps/uidesigner/uidesigner.lpr index 4b4c371f..96aef118 100644 --- a/examples/apps/uidesigner/uidesigner.lpr +++ b/examples/apps/uidesigner/uidesigner.lpr @@ -12,7 +12,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Description: - The starting unit for the uiDesigner project. + The starting unit for the UI Designer project. } program uidesigner; diff --git a/examples/apps/uidesigner/vfddesigner.pas b/examples/apps/uidesigner/vfddesigner.pas index 6eb79b9b..17e1bedc 100644 --- a/examples/apps/uidesigner/vfddesigner.pas +++ b/examples/apps/uidesigner/vfddesigner.pas @@ -1,7 +1,7 @@ { - fpGUI - Free Pascal GUI Library + fpGUI - Free Pascal GUI Toolkit - Copyright (C) 2006 - 2007 See the file AUTHORS.txt, included in this + Copyright (C) 2006 - 2008 See the file AUTHORS.txt, included in this distribution, for details of the copyright. See the file COPYING.modifiedLGPL, included in this distribution, @@ -49,7 +49,7 @@ interface TOtherWidget = class(TfpgWidget) protected FFont: TfpgFont; - procedure HandlePaint; override; + procedure HandlePaint; override; public wgClassName: string; constructor Create(AOwner: TComponent); override; @@ -61,7 +61,7 @@ TFormDesigner = class; TDesignedForm = class(TfpgForm) public - procedure AfterCreate; override; + procedure AfterCreate; override; end; @@ -145,9 +145,6 @@ implementation uses vfdmain, TypInfo; -type - // used to get to SetDesigning() in Form Designer - TComponentFriendClass = class(TComponent); { TWidgetDesigner } @@ -439,13 +436,13 @@ constructor TFormDesigner.Create; FWidgets := TList.Create; FWasDrag := False; - OneClickMove := True; //false; + OneClickMove := True; - FForm := TDesignedForm.Create(nil); - FForm.FormDesigner := self; - FForm.Name := maindsgn.NewFormName; - FForm.WindowTitle := FForm.Name; - FFormOther := ''; + FForm := TDesignedForm.Create(nil); + FForm.FormDesigner := self; + FForm.Name := maindsgn.NewFormName; + FForm.WindowTitle := FForm.Name; + FFormOther := ''; end; destructor TFormDesigner.Destroy; @@ -543,7 +540,7 @@ procedure TFormDesigner.SelectNextWidget(fw: boolean); n, dir: integer; cd, scd: TWidgetDesigner; begin - if FWidgets.Count < 1 then + if FWidgets.Count = 0 then Exit; if fw then @@ -894,7 +891,7 @@ procedure TFormDesigner.PutControlByName(x, y: integer; cname: string); procedure TFormDesigner.OnPaletteChange(Sender: TObject); begin - if PaletteForm.clist.FocusItem > 1 then + if PaletteForm.clist.FocusItem > 0 then FForm.MouseCursor := mcCross else FForm.MouseCursor := mcDefault; @@ -936,18 +933,18 @@ procedure TFormDesigner.UpdatePropWin; wgc := scd.FVFDClass; n := frmProperties.lstProps.FocusItem; - if (n > 0) and (PropList.GetItem(n) <> nil) then + if (n >= 0) and (PropList.GetItem(n) <> nil) then lastpropname := PropList.GetItem(n).Name else lastpropname := ''; - i := 0; + i := -1; if PropList.Widget <> wg then begin frmProperties.lstProps.ReleaseEditor; PropList.Clear; - for n := 1 to wgc.PropertyCount do + for n := 0 to wgc.PropertyCount-1 do begin PropList.AddItem(wgc.GetProperty(n)); if UpperCase(wgc.GetProperty(n).Name) = UpperCase(lastPropName) then @@ -955,7 +952,7 @@ procedure TFormDesigner.UpdatePropWin; end; PropList.Widget := wg; frmProperties.lstProps.Update; - if i > 0 then + if i > -1 then frmProperties.lstProps.FocusItem := i; end; @@ -1475,7 +1472,7 @@ function TFormDesigner.GetWidgetSourceImpl(wd: TWidgetDesigner; ident: string): s := s + ident + 'Anchors := ' + ts + LineEnding; end; - for n := 1 to wgc.PropertyCount do + for n := 0 to wgc.PropertyCount-1 do s := s + wgc.GetProperty(n).GetPropertySource(wg, ident); { @@ -1642,7 +1639,6 @@ procedure TDesignedForm.AfterCreate; WindowPosition := wpUser; WindowTitle := 'New Form'; SetPosition(300, 150, 300, 250); -// TComponentFriendClass(self).SetDesigning(True); end; @@ -1652,9 +1648,6 @@ procedure TOtherWidget.HandlePaint; var s: string; begin - Canvas.BeginDraw; - inherited HandlePaint; - Canvas.Clear(FBackgroundColor); Canvas.SetFont(FFont); Canvas.SetColor(clWidgetFrame); @@ -1662,8 +1655,6 @@ procedure TOtherWidget.HandlePaint; Canvas.SetTextColor(clText1); s := Name + ': ' + wgClassName; Canvas.DrawString(2, 2, s); - - Canvas.EndDraw; end; constructor TOtherWidget.Create(AOwner: TComponent); diff --git a/examples/apps/uidesigner/vfdeditors.pas b/examples/apps/uidesigner/vfdeditors.pas index 50a47b37..c5ba41e1 100644 --- a/examples/apps/uidesigner/vfdeditors.pas +++ b/examples/apps/uidesigner/vfdeditors.pas @@ -1,7 +1,7 @@ { - fpGUI - Free Pascal GUI Library + fpGUI - Free Pascal GUI Toolkit - Copyright (C) 2006 - 2007 See the file AUTHORS.txt, included in this + Copyright (C) 2006 - 2008 See the file AUTHORS.txt, included in this distribution, for details of the copyright. See the file COPYING.modifiedLGPL, included in this distribution, @@ -31,14 +31,18 @@ interface vfdforms; type + TItemEditorForm = class(TVFDDialog) + private + procedure btnClearClicked(Sender: TObject); + procedure OnButtonClick(Sender: TObject); public l1: TfpgLabel; edItems: TfpgMemo; - btnOK, + btnOK: TfpgButton; btnCancel: TfpgButton; + btnClear: TfpgButton; procedure AfterCreate; override; - procedure OnButtonClick(Sender: TObject); end; @@ -61,13 +65,23 @@ procedure TItemEditorForm.AfterCreate; with edItems do begin SetPosition(8, 24, 344, 168); - Anchors := [anLeft, anTop, anRight, anBottom]; + Anchors := AllAnchors; end; - btnOK := CreateButton(self, 8, 200, 105, 'OK', @OnButtonClick); + btnClear := CreateButton(self, 8, 200, 80, 'Clear', @btnClearClicked); + btnClear.Anchors := [anLeft, anBottom]; + + btnOK := CreateButton(self, btnClear.Right + 4, 200, 80, 'OK', @OnButtonClick); btnOK.Anchors := [anLeft, anBottom]; - btnCancel := CreateButton(self, 244, 200, 105, 'Cancel', @OnButtonClick); + + btnCancel := CreateButton(self, Width-84, 200, 80, 'Cancel', @OnButtonClick); btnCancel.Anchors := [anRight, anBottom]; + +end; + +procedure TItemEditorForm.btnClearClicked(Sender: TObject); +begin + edItems.Lines.Clear; end; procedure TItemEditorForm.OnButtonClick(Sender: TObject); diff --git a/examples/apps/uidesigner/vfdfile.pas b/examples/apps/uidesigner/vfdfile.pas index 15e23d75..16910883 100644 --- a/examples/apps/uidesigner/vfdfile.pas +++ b/examples/apps/uidesigner/vfdfile.pas @@ -1,5 +1,5 @@ { - fpGUI - Free Pascal GUI Library + fpGUI - Free Pascal GUI Toolkit Copyright (C) 2006 - 2008 See the file AUTHORS.txt, included in this distribution, for details of the copyright. @@ -46,20 +46,21 @@ TVFDFile = class NewFormsDecl: string; NewFormsImpl: string; constructor Create; - destructor Destroy; override; - function LoadFile(fname: string): boolean; - procedure AddBlock(aposition: integer; ablockid, aformname, ablockdata: string); - function BlockCount: integer; - function Block(index: integer): TVFDFileBlock; - procedure FreeBlocks; - function GetBlocks: integer; // parse file - function MergeBlocks: string; // store file - procedure AddNewFormDecl(formname, formheadblock: string); - procedure AddNewFormImpl(formname, formbody: string); - function FindFormBlock(blockid, formname: string): TVFDFileBlock; - procedure SetFormData(formname, headblock, bodyblock: string); - procedure NewFileSkeleton(unitname: string); + destructor Destroy; override; + function LoadFile(fname: string): boolean; + procedure AddBlock(aposition: integer; ablockid, aformname, ablockdata: string); + function BlockCount: integer; + function Block(index: integer): TVFDFileBlock; + procedure FreeBlocks; + function GetBlocks: integer; // parse file + function MergeBlocks: string; // store file + procedure AddNewFormDecl(formname, formheadblock: string); + procedure AddNewFormImpl(formname, formbody: string); + function FindFormBlock(blockid, formname: string): TVFDFileBlock; + procedure SetFormData(formname, headblock, bodyblock: string); + procedure NewFileSkeleton(unitname: string); end; + implementation @@ -109,9 +110,9 @@ procedure TVFDFile.AddNewFormImpl(formname, formbody: string); function TVFDFile.Block(index: integer): TVFDFileBlock; begin Result := nil; - if (index < 1) or (index > FBlocks.Count) then + if (index < 0) or (index > FBlocks.Count-1) then Exit; - Result := TVFDFileBlock(FBlocks[index - 1]); + Result := TVFDFileBlock(FBlocks[index]); end; function TVFDFile.BlockCount: integer; @@ -141,7 +142,7 @@ function TVFDFile.FindFormBlock(blockid, formname: string): TVFDFileBlock; fb: TVFDFileBlock; begin Result := nil; - for n := 1 to BlockCount do + for n := 0 to BlockCount-1 do begin fb := Block(n); if (fb.BlockID = blockid) and (UpperCase(fb.FormName) = UpperCase(formname)) then @@ -156,7 +157,7 @@ procedure TVFDFile.FreeBlocks; var n: integer; begin - for n := 0 to FBlocks.Count - 1 do + for n := 0 to FBlocks.Count-1 do TVFDFileBlock(FBlocks[n]).Free; FBlocks.Clear; NewFormsDecl := ''; @@ -338,10 +339,8 @@ function TVFDFile.MergeBlocks: string; end; if not newsaved and (NewFormsImpl <> '') then - rs := rs + NewFormsImpl// do not loose new form data. - ; + rs := rs + NewFormsImpl; // do not loose new form data. - //writeln(rs); Result := rs; end; diff --git a/examples/apps/uidesigner/vfdformparser.pas b/examples/apps/uidesigner/vfdformparser.pas index 1acaed31..a3d7c966 100644 --- a/examples/apps/uidesigner/vfdformparser.pas +++ b/examples/apps/uidesigner/vfdformparser.pas @@ -1,7 +1,7 @@ { - fpGUI - Free Pascal GUI Library + fpGUI - Free Pascal GUI Toolkit - Copyright (C) 2006 - 2007 See the file AUTHORS.txt, included in this + Copyright (C) 2006 - 2008 See the file AUTHORS.txt, included in this distribution, for details of the copyright. See the file COPYING.modifiedLGPL, included in this distribution, @@ -41,7 +41,7 @@ TVFDFormParser = class(TObject) line: string; lineindex: integer; public - procedure nextline; + procedure NextLine; public constructor Create(const FormName, FormHead, FormBody: string); destructor Destroy; override; @@ -52,15 +52,17 @@ TVFDFormParser = class(TObject) end; -function GetIdentifier(var s: string): string; -function GetStringValue(var s: string): string; +function GetIdentifier(var s: string): string; +function GetStringValue(var s: string): string; procedure SkipSpaces(var s: string); -function CheckSymbol(var s: string; const sym: string): boolean; -function GetIntValue(var s: string): integer; -function GetBoolValue(var s: string): boolean; +function CheckSymbol(var s: string; const sym: string): boolean; +function GetIntValue(var s: string): integer; +function GetBoolValue(var s: string): boolean; + implementation + { TVFDFormParser } constructor TVFDFormParser.Create(const FormName, FormHead, FormBody: string); @@ -69,7 +71,7 @@ constructor TVFDFormParser.Create(const FormName, FormHead, FormBody: string); ffd := nil; BodyLines := TStringList.Create; BodyLines.Text := FormBody; - lineindex := 0; + lineindex := -1; end; destructor TVFDFormParser.Destroy; @@ -78,13 +80,13 @@ destructor TVFDFormParser.Destroy; inherited; end; -procedure TVFDFormParser.nextline; +procedure TVFDFormParser.NextLine; begin repeat Inc(lineindex); - eob := (lineindex > BodyLines.Count); + eob := (lineindex > BodyLines.Count-1); if not eob then - line := trim(bodylines.Strings[lineindex - 1]) + line := trim(bodylines.Strings[lineindex]) else line := ''; until eob or (line <> ''); @@ -94,16 +96,12 @@ function TVFDFormParser.ParseForm: TFormDesigner; begin ffd := TFormDesigner.Create; ffd.Form.Name := fformname; - // parsing line by line // the unknown lines will be "other properties" - lineindex := 0; - nextline; - + lineindex := -1; + NextLine; ParseFormProperties; - ParseFormWidgets; - Result := ffd; end; @@ -250,10 +248,8 @@ procedure TVFDFormParser.ParseFormProperties; while not eob and (pos('.CREATE(', UpperCase(line)) = 0) do begin lok := ReadWGProperty(line, ffd.Form, VFDFormWidget); - if not lok then ffd.FormOther := ffd.FormOther + line + LineEnding; - NextLine; end; end; @@ -307,7 +303,7 @@ procedure TVFDFormParser.ParseFormWidgets; wg := nil; wgc := nil; - for n := 1 to VFDWidgetCount do + for n := 0 to VFDWidgetCount-1 do begin wgc := VFDWidget(n); if wgclassuc = UpperCase(wgc.WidgetClass.ClassName) then @@ -532,7 +528,7 @@ function TVFDFormParser.ReadWGProperty(propline: string; wg: TfpgWidget; wgc: TV if not lok then if wgc <> nil then - for n := 1 to wgc.PropertyCount do + for n := 0 to wgc.PropertyCount-1 do begin lok := wgc.GetProperty(n).ParseSourceLine(wg, line); if lok then diff --git a/examples/apps/uidesigner/vfdforms.pas b/examples/apps/uidesigner/vfdforms.pas index 508b64bf..8c19104a 100644 --- a/examples/apps/uidesigner/vfdforms.pas +++ b/examples/apps/uidesigner/vfdforms.pas @@ -1,5 +1,5 @@ { - fpGUI - Free Pascal GUI Library + fpGUI - Free Pascal GUI Toolkit Copyright (C) 2006 - 2008 See the file AUTHORS.txt, included in this distribution, for details of the copyright. @@ -161,18 +161,7 @@ procedure TPaletteForm.AfterCreate; clist.Top := 22; clist.Height := Height - clist.top - 2; clist.Anchors := [anLeft, anRight, anTop, anBottom]; - clist.Items.Add('-'); -{ - clist.Items.Add('Label'); - clist.Items.Add('Edit'); - clist.Items.Add('Button'); - clist.Items.Add('CheckBox'); - clist.Items.Add('ComboBox'); - clist.Items.Add('Memo'); - clist.Items.Add('ListBox'); - clist.Items.Add('[OTHER]'); -} clist.OnChange := @(maindsgn.OnPaletteChange); end; @@ -360,8 +349,8 @@ procedure TWidgetOrderForm.AfterCreate; procedure TWidgetOrderForm.OnButtonClick(Sender: TObject); var - i, - n, + i: integer; + n: integer; myilev: integer; function IdentLevel(astr: string): integer; @@ -388,16 +377,16 @@ procedure TWidgetOrderForm.OnButtonClick(Sender: TObject); begin // up / down i := list.FocusItem; - if i < 1 then + if i < 0 then Exit; - myilev := IdentLevel(list.Items[i - 1]); + myilev := IdentLevel(list.Items[i]); if Sender = btnUP then begin - if (i > 1) and (IdentLevel(list.Items[i - 2]) = myilev) then + if (i > 0) and (IdentLevel(list.Items[i - 1]) = myilev) then begin - list.Items.Move(i - 1, i - 2); + list.Items.Move(i, i - 1); n := i; while (n < list.Items.Count) and (IdentLevel(list.Items[n]) > myilev) do @@ -410,24 +399,21 @@ procedure TWidgetOrderForm.OnButtonClick(Sender: TObject); end; end else if Sender = btnDOWN then - if (i < list.Items.Count) then + if (i < list.Items.Count-1) then begin - //list.Items.Move(i-1,i); - n := i; while (n < list.Items.Count) and (IdentLevel(list.Items[n]) > myilev) do - Inc(n)//list.Items.Move(n,n-1); - ; + Inc(n); - if (i = n) and (i < list.Items.Count - 1) and (IdentLevel(list.Items[i + 1]) > myilev) then + if (i = n) and (i < list.Items.Count-1) and (IdentLevel(list.Items[i]) > myilev) then Exit; - if (n > list.Items.Count - 1) then - Exit; + if (n > list.Items.Count-1) then + Exit; //==> while (n >= i) do begin - list.Items.Move(n, n - 1); + list.Items.Move(n, n + 1); Dec(n); end; @@ -444,16 +430,15 @@ procedure TVFDDialog.HandleKeyPress(var keycode: word; var shiftstate: TShiftSta begin ModalResult := 2; consumed := True; - end - else - inherited HandleKeyPress(keycode, shiftstate, consumed); + end; + inherited HandleKeyPress(keycode, shiftstate, consumed); end; procedure TfrmVFDSetup.LoadSettings; begin - chlGrid.FocusItem := gINI.ReadInteger('Options', 'GridResolution', 2); + chlGrid.FocusItem := gINI.ReadInteger('Options', 'GridResolution', 2); tbMRUFileCount.Position := gINI.ReadInteger('Options', 'MRUFileCount', 4); - cbFullPath.Checked := gINI.ReadBool('Options', 'ShowFullPath', True); + cbFullPath.Checked := gINI.ReadBool('Options', 'ShowFullPath', True); end; procedure TfrmVFDSetup.SaveSettings; diff --git a/examples/apps/uidesigner/vfdmain.pas b/examples/apps/uidesigner/vfdmain.pas index 53145c6d..d0e81778 100644 --- a/examples/apps/uidesigner/vfdmain.pas +++ b/examples/apps/uidesigner/vfdmain.pas @@ -1,5 +1,5 @@ { - fpGUI - Free Pascal GUI Library + fpGUI - Free Pascal GUI Toolkit Copyright (C) 2006 - 2008 See the file AUTHORS.txt, included in this distribution, for details of the copyright. @@ -38,8 +38,8 @@ interface TMainDesigner = class(TObject) private - procedure SetEditedFileName(const Value: string); - procedure LoadGridResolution; + procedure SetEditedFileName(const Value: string); + procedure LoadGridResolution; protected FDesigners: TList; FFile: TVFDFile; @@ -137,23 +137,21 @@ procedure TMainDesigner.OnLoadFile(Sender: TObject); TFormDesigner(FDesigners[n]).Free; end; FDesigners.Clear; - + if not fpgFileExists(fname) then begin ShowMessage('File does not exists.', 'Error loading form'); Exit; end; - Writeln('loading file...'); - FFile.LoadFile(fname); FFile.GetBlocks; - for n := 1 to FFile.BlockCount do + for n := 0 to FFile.BlockCount-1 do begin bl := FFile.Block(n); if bl.BlockID = 'VFD_HEAD_BEGIN' then - for m := n + 1 to FFile.BlockCount do + for m := n + 1 to FFile.BlockCount-1 do begin bl2 := FFile.Block(m); if (bl2.BlockID = 'VFD_BODY_BEGIN') and (bl2.FormName = bl.FormName) then @@ -213,7 +211,7 @@ procedure TMainDesigner.OnSaveFile(Sender: TObject); FFile.NewFileSkeleton(uname); end; - for n := 1 to DesignerCount do + for n := 0 to DesignerCount-1 do begin fd := Designer(n); FFile.SetFormData(fd.Form.Name, fd.GetFormSourceDecl, fd.GetFormSourceImpl); @@ -229,11 +227,11 @@ procedure TMainDesigner.OnSaveFile(Sender: TObject); finally CloseFile(ff); end; - // frmMain.WindowTitle := 'fpGUI Designer v' + program_version + ' - ' + fname; - // everything is done by SetEditedFileName (EditedFileName := ...) frmMain.mru.AddItem(fname); except - Writeln('Form save I/O failure.'); + on E: Exception do + raise Exception.Create('Form save I/O failure in TMainDesigner.OnSaveFile.' + #13 + + E.Message); end; end; @@ -277,7 +275,6 @@ procedure TMainDesigner.OnNewForm(Sender: TObject); fd: TFormDesigner; nfrm: TNewFormForm; begin - Writeln('new form'); nfrm := TNewFormForm.Create(nil); if nfrm.ShowModal = 1 then if nfrm.edName.Text <> '' then @@ -292,8 +289,6 @@ procedure TMainDesigner.OnNewForm(Sender: TObject); end; procedure TMainDesigner.CreateWindows; - //var - // fd : TFormDesigner; begin frmMain := TfrmMain.Create(nil); frmMain.WindowTitle := 'fpGUI Designer v' + program_version; @@ -301,12 +296,6 @@ procedure TMainDesigner.CreateWindows; frmProperties := TfrmProperties.Create(nil); frmProperties.Show; - - // fd := TFormDesigner.Create; - // fd.Form.Name := 'frmNewForm'; - // fd.Form.WindowTitle := u8('frmNewForm'); - // FDesigners.Add(fd); - // fd.Show; end; constructor TMainDesigner.Create; @@ -338,7 +327,6 @@ destructor TMainDesigner.Destroy; procedure TMainDesigner.SelectForm(aform: TFormDesigner); begin - //Writeln('selected...'); if (SelectedForm <> nil) and (SelectedForm <> aform) then SelectedForm.DeSelectAll; SelectedForm := aform; @@ -347,9 +335,9 @@ procedure TMainDesigner.SelectForm(aform: TFormDesigner); function TMainDesigner.Designer(index: integer): TFormDesigner; begin Result := nil; - if (index < 1) or (index > FDesigners.Count) then + if (index < 0) or (index > FDesigners.Count-1) then Exit; - Result := TFormDesigner(FDesigners[index - 1]); + Result := TFormDesigner(FDesigners[index]); end; function TMainDesigner.DesignerCount: integer; @@ -366,14 +354,14 @@ function TMainDesigner.NewFormName: string; repeat Inc(i); s := 'Form' + IntToStr(i); - n := 1; - while (n <= DesignerCount) do + n := 0; + while (n < DesignerCount) do begin if Designer(n).Form.Name = s then Break; Inc(n); end; - until n > DesignerCount; + until n > DesignerCount-1; Result := s; end; @@ -382,8 +370,6 @@ procedure TMainDesigner.CreateParseForm(const FormName, FormHead, FormBody: stri fd: TFormDesigner; fp: TVFDFormParser; begin - Writeln('CreateParseForm: ', FormName); - fp := TVFDFormParser.Create(FormName, FormHead, FormBody); fd := fp.ParseForm; fp.Free; @@ -446,10 +432,10 @@ procedure TMainDesigner.SetEditedFileName(const Value: string); procedure TMainDesigner.LoadGridResolution; begin - case gINI.ReadInteger('Options', 'GridResolution', 2) of - 1: GridResolution := 2; - 2: GridResolution := 4; - 3: GridResolution := 8; + case gINI.ReadInteger('Options', 'GridResolution', 1) of + 0: GridResolution := 2; + 1: GridResolution := 4; + 2: GridResolution := 8; end; end; diff --git a/examples/apps/uidesigner/vfdpropeditgrid.pas b/examples/apps/uidesigner/vfdpropeditgrid.pas index 97ebb0e6..d31f7f5b 100644 --- a/examples/apps/uidesigner/vfdpropeditgrid.pas +++ b/examples/apps/uidesigner/vfdpropeditgrid.pas @@ -1,7 +1,7 @@ { - fpGUI - Free Pascal GUI Library + fpGUI - Free Pascal GUI Toolkit - Copyright (C) 2006 - 2007 See the file AUTHORS.txt, included in this + Copyright (C) 2006 - 2008 See the file AUTHORS.txt, included in this distribution, for details of the copyright. See the file COPYING.modifiedLGPL, included in this distribution, @@ -56,8 +56,8 @@ TPropertyDBColumns = class(TVFDWidgetProperty) TColumnsGrid = class(TfpgCustomGrid) protected - function GetRowCount: Longword; override; - procedure DrawCell(ARow, ACol: Longword; ARect: TfpgRect; AFlags: TfpgGridDrawState); override; + function GetRowCount: Integer; override; + procedure DrawCell(ARow, ACol: Integer; ARect: TfpgRect; AFlags: TfpgGridDrawState); override; public dbgrid: TfpgStringGrid; constructor Create(AOwner: TComponent); override; @@ -66,7 +66,7 @@ TColumnsGrid = class(TfpgCustomGrid) TColumnEditForm = class(TfpgForm) private - procedure GridRowChange(Sender: TObject; row: Longword); + procedure GridRowChange(Sender: TObject; row: Integer); procedure EditChange(Sender: TObject); procedure NewButtonClick(Sender: TObject); procedure DeleteButtonClick(Sender: TObject); @@ -284,12 +284,12 @@ procedure TColumnEditForm.AfterCreate; {@VFD_BODY_END: ColumnEditForm} end; -procedure TColumnEditForm.GridRowChange(Sender: TObject; row: Longword); +procedure TColumnEditForm.GridRowChange(Sender: TObject; row: Integer); var i: integer; c: TfpgStringColumn; begin - c := dbgrid.Columns[row{ - 1}]; + c := dbgrid.Columns[row]; if c = nil then Exit; @@ -298,11 +298,11 @@ procedure TColumnEditForm.GridRowChange(Sender: TObject; row: Longword); edCOLWIDTH.Text := IntToStr(c.Width); case c.Alignment of taRightJustify: - i := 2; + i := 1; taCenter: - i := 3 + i := 2 else - i := 1; + i := 0; end; chlALIGN.FocusItem := i; end; @@ -311,15 +311,15 @@ procedure TColumnEditForm.SaveColumn(row: integer); var c: TfpgStringColumn; begin - c := dbgrid.Columns[row{ - 1}]; + c := dbgrid.Columns[row]; if c = nil then Exit; c.Title := edTITLE.Text; c.Width := StrToIntDef(edCOLWIDTH.Text, 30); case chlALIGN.FocusItem of - 2: c.Alignment := taRightJustify; - 3: c.Alignment := taCenter; + 1: c.Alignment := taRightJustify; + 2: c.Alignment := taCenter; else c.Alignment := taLeftJustify; end; @@ -330,7 +330,7 @@ procedure TColumnEditForm.SaveColumn(row: integer); procedure TColumnEditForm.EditChange(Sender: TObject); begin - if grid.FocusRow < 1 then + if grid.FocusRow < 0 then Exit; SaveColumn(grid.FocusRow); @@ -359,14 +359,14 @@ procedure TColumnEditForm.UpDownButtonClick(Sender: TObject); begin if Sender = btnUP then begin - if grid.FocusRow > 1 then + if grid.FocusRow > 0 then begin dbgrid.MoveColumn(grid.FocusRow - 1, grid.FocusRow - 2); grid.FocusRow := grid.FocusRow - 1; grid.Update; end; end - else if grid.FocusRow < grid.RowCount then + else if grid.FocusRow < grid.RowCount-1 then begin dbgrid.MoveColumn(grid.FocusRow - 1, grid.FocusRow); grid.FocusRow := grid.FocusRow + 1; @@ -377,7 +377,7 @@ procedure TColumnEditForm.UpDownButtonClick(Sender: TObject); { TColumnsGrid } -function TColumnsGrid.GetRowCount: Longword; +function TColumnsGrid.GetRowCount: Integer; begin try // Yes, it must be ColumnCount and *not* RowCount! @@ -387,7 +387,7 @@ function TColumnsGrid.GetRowCount: Longword; end; end; -procedure TColumnsGrid.DrawCell(ARow, ACol: Longword; ARect: TfpgRect; AFlags: TfpgGridDrawState); +procedure TColumnsGrid.DrawCell(ARow, ACol: Integer; ARect: TfpgRect; AFlags: TfpgGridDrawState); var s: string; x: integer; @@ -404,10 +404,10 @@ procedure TColumnsGrid.DrawCell(ARow, ACol: Longword; ARect: TfpgRect; AFlags: T x := ARect.Left + 1; case ACol of - 1: s := IntToStr(ARow); - 2: s := c.Title; - 3: s := IntToStr(c.Width); - 4: case c.Alignment of + 0: s := IntToStr(ARow); + 1: s := c.Title; + 2: s := IntToStr(c.Width); + 3: case c.Alignment of taRightJustify: s := 'Right'; taCenter: @@ -506,7 +506,7 @@ function TPropertyDBColumns.GetPropertySource(wg: TfpgWidget; const ident: strin Result := ''; with TfpgStringGrid(wg) do begin - for f := 1 to ColumnCount do + for f := 0 to ColumnCount-1 do begin c := Columns[f]; case c.Alignment of diff --git a/examples/apps/uidesigner/vfdprops.pas b/examples/apps/uidesigner/vfdprops.pas index fa2c8cd7..7e033d24 100644 --- a/examples/apps/uidesigner/vfdprops.pas +++ b/examples/apps/uidesigner/vfdprops.pas @@ -1,7 +1,7 @@ { - fpGUI - Free Pascal GUI Library + fpGUI - Free Pascal GUI Toolkit - Copyright (C) 2006 - 2007 See the file AUTHORS.txt, included in this + Copyright (C) 2006 - 2008 See the file AUTHORS.txt, included in this distribution, for details of the copyright. See the file COPYING.modifiedLGPL, included in this distribution, @@ -62,10 +62,10 @@ TPropertyEnum = class(TVFDWidgetProperty) TPropertyStringList = class(TVFDWidgetProperty) public - function ParseSourceLine(wg: TfpgWidget; const line: string): boolean; override; - function GetPropertySource(wg: TfpgWidget; const ident: string): string; override; - function GetValueText(wg: TfpgWidget): string; override; - function CreateEditor(AOwner: TComponent): TVFDPropertyEditor; override; + function ParseSourceLine(wg: TfpgWidget; const line: string): boolean; override; + function GetPropertySource(wg: TfpgWidget; const ident: string): string; override; + function GetValueText(wg: TfpgWidget): string; override; + function CreateEditor(AOwner: TComponent): TVFDPropertyEditor; override; procedure OnExternalEdit(wg: TfpgWidget); override; end; @@ -79,10 +79,8 @@ TPropertyBoolean = class(TVFDWidgetProperty) end; - { TPropertyFontDesc } - TPropertyFontDesc = class(TPropertyString) - function CreateEditor(AOwner: TComponent): TVFDPropertyEditor; override; + function CreateEditor(AOwner: TComponent): TVFDPropertyEditor; override; procedure OnExternalEdit(wg: TfpgWidget); override; end; @@ -151,19 +149,19 @@ implementation fpgfx, gui_dialogs; + procedure EditStringList(sl: TStringList); var - frmie: TItemEditorForm; + frm: TItemEditorForm; begin - frmie := TItemEditorForm.Create(nil); - //GfxGetAbsolutePosition(PropertyForm.btnEdit.WinHandle, PropertyForm.btnEdit.width, 0, ax,ay); - //frmie.Left := ax; - //frmie.Top := ay; - - frmie.edItems.Lines.Assign(sl); - if frmie.ShowModal = 1 then - sl.Assign(frmie.edItems.Lines); - frmie.Free; + frm := TItemEditorForm.Create(nil); + try + frm.edItems.Lines.Assign(sl); + if frm.ShowModal = 1 then + sl.Assign(frm.edItems.Lines); + finally + frm.Free; + end; end; procedure GetEnumPropValueList(wg: TObject; const APropName: string; sl: TStringList); @@ -377,11 +375,18 @@ function TPropertyStringList.GetPropertySource(wg: TfpgWidget; const ident: stri f: integer; begin sl := TStringList(GetObjectProp(wg, Name, TStrings)); + if not Assigned(sl) then + raise Exception.Create('Failed to find TStrings type property.'); Result := ''; - for f := 0 to sl.Count - 1 do - Result := Result + ident + Name + '.Add(' + QuotedStr(sl.Strings[f]) + ');' + LineEnding; + //if sl.Text <> '' then + //begin + //writeln('Text = <', sl.Text, '>'); + //writeln('StringList.Count = ', sl.Count); + for f := 0 to sl.Count - 1 do + Result := Result + ident + Name + '.Add(' + QuotedStr(sl.Strings[f]) + ');' + LineEnding; + //end; end; function TPropertyStringList.GetValueText(wg: TfpgWidget): string; @@ -389,6 +394,8 @@ function TPropertyStringList.GetValueText(wg: TfpgWidget): string; sl: TStringList; begin sl := TStringList(GetObjectProp(wg, Name, TStrings)); + if not Assigned(sl) then + raise Exception.Create('Failed to find TStrings type property.'); Result := '[' + IntToStr(sl.Count) + ' lines]'; end; @@ -397,6 +404,8 @@ procedure TPropertyStringList.OnExternalEdit(wg: TfpgWidget); sl: TStringList; begin sl := TStringList(GetObjectProp(wg, Name, TStrings)); + if not Assigned(sl) then + raise Exception.Create('Failed to find TStrings type property.'); EditStringList(sl); end; @@ -424,6 +433,8 @@ function TPropertyStringList.ParseSourceLine(wg: TfpgWidget; const line: string) if Result then begin sl := TStringList(GetObjectProp(wg, Name, TStrings)); + if not Assigned(sl) then + raise Exception.Create('Failed to find TStrings type property.'); sl.Add(sval); end; end; @@ -498,12 +509,10 @@ procedure TExternalPropertyEditor.HandlePaint; // Exit; if widget = nil then Exit; - Canvas.BeginDraw; Canvas.Clear(clBoxColor); Canvas.GetWinRect(r); Canvas.SetTextColor(clText1); prop.DrawValue(Widget, Canvas, r, 0); - Canvas.EndDraw; end; procedure TExternalPropertyEditor.CreateLayout; @@ -616,12 +625,12 @@ procedure TChoicePropertyEditor.LoadValue(wg: TfpgWidget); sv := GetEnumProp(wg, prop.Name); sl := TStringList.Create; GetEnumPropValueList(wg, prop.Name, sl); - fi := 1; + fi := 0; for i := 0 to sl.Count - 1 do begin chl.Items.Add(sl.Strings[i]); if UpperCase(sv) = UpperCase(sl.Strings[i]) then - fi := i + 1; + fi := i; end; chl.FocusItem := fi; sl.Free; @@ -642,9 +651,9 @@ procedure TBooleanPropertyEditor.LoadValue(wg: TfpgWidget); chl.Items.Add('True'); chl.Items.Add('False'); if b = 1 then - chl.FocusItem := 1 + chl.FocusItem := 0 else - chl.FocusItem := 2; + chl.FocusItem := 1; end; procedure TBooleanPropertyEditor.StoreValue(wg: TfpgWidget); diff --git a/examples/apps/uidesigner/vfdresizer.pas b/examples/apps/uidesigner/vfdresizer.pas index 137fdbd4..9944e3b6 100644 --- a/examples/apps/uidesigner/vfdresizer.pas +++ b/examples/apps/uidesigner/vfdresizer.pas @@ -1,7 +1,7 @@ { - fpGUI - Free Pascal GUI Library + fpGUI - Free Pascal GUI Toolkit - Copyright (C) 2006 - 2007 See the file AUTHORS.txt, included in this + Copyright (C) 2006 - 2008 See the file AUTHORS.txt, included in this distribution, for details of the copyright. See the file COPYING.modifiedLGPL, included in this distribution, @@ -31,10 +31,10 @@ interface TwgResizer = class(TfpgWidget) protected wgdesigner: TObject; - procedure HandlePaint; override; - procedure HandleLMouseDown(x, y: integer; shiftstate: TShiftState); override; - procedure HandleLMouseUp(x, y: integer; shiftstate: TShiftState); override; - procedure HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); override; + procedure HandlePaint; override; + procedure HandleLMouseDown(x, y: integer; shiftstate: TShiftState); override; + procedure HandleLMouseUp(x, y: integer; shiftstate: TShiftState); override; + procedure HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); override; public direction: integer; FDragging: boolean; @@ -43,9 +43,11 @@ TwgResizer = class(TfpgWidget) constructor Create(ACompDesigner: TObject; adirection: integer); reintroduce; procedure Show; end; + implementation + uses vfddesigner, vfdmain; @@ -54,10 +56,7 @@ implementation procedure TwgResizer.HandlePaint; begin - Canvas.BeginDraw; - inherited HandlePaint; Canvas.Clear(FBackgroundColor); - Canvas.EndDraw; end; procedure TwgResizer.HandleLMouseDown(x, y: integer; shiftstate: TShiftState); diff --git a/examples/apps/uidesigner/vfdutils.pas b/examples/apps/uidesigner/vfdutils.pas index fe60c933..90b99841 100644 --- a/examples/apps/uidesigner/vfdutils.pas +++ b/examples/apps/uidesigner/vfdutils.pas @@ -1,7 +1,7 @@ { - fpGUI - Free Pascal GUI Library + fpGUI - Free Pascal GUI Toolkit - Copyright (C) 2006 - 2007 See the file AUTHORS.txt, included in this + Copyright (C) 2006 - 2008 See the file AUTHORS.txt, included in this distribution, for details of the copyright. See the file COPYING.modifiedLGPL, included in this distribution, diff --git a/examples/apps/uidesigner/vfdwidgetclass.pas b/examples/apps/uidesigner/vfdwidgetclass.pas index 19308b35..9729691f 100644 --- a/examples/apps/uidesigner/vfdwidgetclass.pas +++ b/examples/apps/uidesigner/vfdwidgetclass.pas @@ -1,5 +1,5 @@ { - fpGUI - Free Pascal GUI Library + fpGUI - Free Pascal GUI Toolkit Copyright (C) 2006 - 2008 See the file AUTHORS.txt, included in this distribution, for details of the copyright. @@ -133,7 +133,7 @@ destructor TVFDWidgetClass.Destroy; function TVFDWidgetClass.GetProperty(ind: integer): TVFDWidgetProperty; begin - Result := TVFDWidgetProperty(FProps[ind - 1]); + Result := TVFDWidgetProperty(FProps[ind]); end; function TVFDWidgetClass.PropertyCount: integer; diff --git a/examples/apps/uidesigner/vfdwidgets.pas b/examples/apps/uidesigner/vfdwidgets.pas index 73088160..71cacc1d 100644 --- a/examples/apps/uidesigner/vfdwidgets.pas +++ b/examples/apps/uidesigner/vfdwidgets.pas @@ -1,5 +1,5 @@ { - fpGUI - Free Pascal GUI Library + fpGUI - Free Pascal GUI Toolkit Copyright (C) 2006 - 2008 See the file AUTHORS.txt, included in this distribution, for details of the copyright. @@ -79,7 +79,7 @@ function VFDWidgetCount: integer; function VFDWidget(ind: integer): TVFDWidgetClass; begin - Result := TVFDWidgetClass(FVFDWidgets[ind - 1]); + Result := TVFDWidgetClass(FVFDWidgets[ind]); end; procedure RegisterVFDWidget(awc: TVFDWidgetClass); @@ -352,6 +352,7 @@ procedure RegisterWidgets; wc.AddProperty('Min', TPropertyInteger, ''); wc.AddProperty('Max', TPropertyInteger, ''); wc.AddProperty('Position', TPropertyInteger, ''); + wc.AddProperty('ShowCaption', TPropertyBoolean, ''); wc.WidgetIconName := 'vfd.progressbar'; RegisterVFDWidget(wc); @@ -362,6 +363,7 @@ procedure RegisterWidgets; wc.AddProperty('Min', TPropertyInteger, ''); wc.AddProperty('Orientation', TPropertyEnum, ''); wc.AddProperty('Position', TPropertyInteger, ''); + wc.AddProperty('ShowPosition', TPropertyBoolean, ''); wc.AddProperty('TabOrder', TPropertyInteger, 'The tab order'); wc.WidgetIconName := 'vfd.trackbar'; RegisterVFDWidget(wc); -- cgit v1.2.3-54-g00ecf