From 7b04d530a61166f3de27912f6921e8cc886416b1 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Tue, 12 Jun 2018 09:22:39 +0000 Subject: [PATCH] tvplanit: Fix contact editor form size in Linux. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6488 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../tvplanit/source/vpcontacteditdlg.lfm | 129 +++++++++--------- .../tvplanit/source/vpcontacteditdlg.pas | 101 ++++++++++---- .../tvplanit/source/vpcontactgridpainter.pas | 15 +- components/tvplanit/source/vpdlg.pas | 17 ++- 4 files changed, 153 insertions(+), 109 deletions(-) diff --git a/components/tvplanit/source/vpcontacteditdlg.lfm b/components/tvplanit/source/vpcontacteditdlg.lfm index 71569fa0b..4324d86c9 100644 --- a/components/tvplanit/source/vpcontacteditdlg.lfm +++ b/components/tvplanit/source/vpcontacteditdlg.lfm @@ -1,7 +1,7 @@ object ContactEditForm: TContactEditForm - Left = 479 + Left = 397 Height = 610 - Top = 165 + Top = 158 Width = 506 HorzScrollBar.Page = 432 VertScrollBar.Page = 320 @@ -9,20 +9,19 @@ object ContactEditForm: TContactEditForm Caption = 'ContactEdit' ClientHeight = 610 ClientWidth = 506 - Constraints.MinWidth = 480 OnCreate = FormCreate OnKeyDown = FormKeyDown OnShow = FormShow Position = poScreenCenter - LCLVersion = '1.6.4.0' + LCLVersion = '1.9.0.0' object PageControl: TPageControl Left = 0 Height = 577 Top = 0 Width = 506 - ActivePage = tabBaseData + ActivePage = tabAddresses Align = alClient - TabIndex = 0 + TabIndex = 1 TabOrder = 0 OnChange = PageControlChange object tabBaseData: TTabSheet @@ -54,7 +53,7 @@ object ContactEditForm: TContactEditForm Height = 23 Top = 8 Width = 384 - Anchors = [akTop, akRight] + Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 8 BorderSpacing.Right = 8 MaxLength = 100 @@ -194,19 +193,19 @@ object ContactEditForm: TContactEditForm ClientWidth = 498 ImageIndex = 1 object gbWorkAddress: TGroupBox - Left = 8 + Left = 24 Height = 298 Top = 8 - Width = 482 + Width = 466 Align = alTop AutoSize = True - BorderSpacing.Left = 8 + BorderSpacing.Left = 24 BorderSpacing.Top = 8 BorderSpacing.Right = 8 BorderSpacing.Bottom = 8 Caption = 'gbWorkAddress' ClientHeight = 278 - ClientWidth = 478 + ClientWidth = 462 Font.Style = [fsBold] ParentFont = False TabOrder = 0 @@ -214,11 +213,11 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Control = gbWorkAddress AnchorSideRight.Control = gbWorkAddress AnchorSideRight.Side = asrBottom - Left = 132 + Left = 128 Height = 23 Top = 0 - Width = 338 - Anchors = [akTop, akRight] + Width = 326 + Anchors = [akTop, akLeft, akRight] BorderSpacing.Right = 8 MaxLength = 50 OnChange = ItemChanged @@ -229,7 +228,7 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Control = edCompany AnchorSideTop.Side = asrCenter AnchorSideRight.Control = edCompany - Left = 59 + Left = 55 Height = 15 Top = 4 Width = 65 @@ -246,7 +245,7 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Control = edDepartment AnchorSideTop.Side = asrCenter AnchorSideRight.Control = edCompany - Left = 48 + Left = 44 Height = 15 Top = 31 Width = 76 @@ -265,10 +264,10 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = edCompany AnchorSideRight.Side = asrBottom - Left = 132 + Left = 128 Height = 23 Top = 27 - Width = 338 + Width = 326 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 4 MaxLength = 50 @@ -280,7 +279,7 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Control = edPosition AnchorSideTop.Side = asrCenter AnchorSideRight.Control = edCompany - Left = 68 + Left = 64 Height = 15 Top = 58 Width = 56 @@ -299,10 +298,10 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = edCompany AnchorSideRight.Side = asrBottom - Left = 132 + Left = 128 Height = 23 Top = 54 - Width = 338 + Width = 326 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 4 MaxLength = 50 @@ -314,7 +313,7 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Control = edAddressW AnchorSideTop.Side = asrCenter AnchorSideRight.Control = edCompany - Left = 69 + Left = 65 Height = 15 Top = 85 Width = 55 @@ -333,10 +332,10 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = edCompany AnchorSideRight.Side = asrBottom - Left = 132 + Left = 128 Height = 23 Top = 81 - Width = 338 + Width = 326 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 4 MaxLength = 100 @@ -348,7 +347,7 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Control = edCityW AnchorSideTop.Side = asrCenter AnchorSideRight.Control = edCompany - Left = 90 + Left = 86 Height = 15 Top = 112 Width = 34 @@ -367,10 +366,10 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = edCompany AnchorSideRight.Side = asrBottom - Left = 132 + Left = 128 Height = 23 Top = 108 - Width = 338 + Width = 326 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 4 MaxLength = 50 @@ -382,7 +381,7 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Control = edStateW AnchorSideTop.Side = asrCenter AnchorSideRight.Control = edCompany - Left = 85 + Left = 81 Height = 15 Top = 139 Width = 39 @@ -401,10 +400,10 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = edCompany AnchorSideRight.Side = asrBottom - Left = 132 + Left = 128 Height = 23 Top = 135 - Width = 338 + Width = 326 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 4 MaxLength = 25 @@ -416,14 +415,14 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Control = cbStateW AnchorSideTop.Side = asrCenter AnchorSideRight.Control = edCompany - Left = 49 + Left = 41 Height = 15 Top = 166 Width = 79 Alignment = taRightJustify Anchors = [akTop, akRight] BorderSpacing.Left = 8 - BorderSpacing.Right = 4 + BorderSpacing.Right = 8 Caption = 'lblStateCombo' FocusControl = cbStateW ParentColor = False @@ -436,10 +435,10 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = edCompany AnchorSideRight.Side = asrBottom - Left = 132 + Left = 128 Height = 23 Top = 162 - Width = 338 + Width = 326 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 4 ItemHeight = 15 @@ -452,7 +451,7 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Control = edZipCodeW AnchorSideTop.Side = asrCenter AnchorSideRight.Control = edCompany - Left = 66 + Left = 62 Height = 15 Top = 193 Width = 58 @@ -470,7 +469,7 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Control = cbStateW AnchorSideTop.Side = asrBottom AnchorSideRight.Side = asrBottom - Left = 132 + Left = 128 Height = 23 Top = 189 Width = 120 @@ -485,7 +484,7 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Control = cbCountryW AnchorSideTop.Side = asrCenter AnchorSideRight.Control = edCompany - Left = 28 + Left = 24 Height = 15 Top = 220 Width = 96 @@ -505,10 +504,10 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = edCompany AnchorSideRight.Side = asrBottom - Left = 132 + Left = 128 Height = 23 Top = 216 - Width = 338 + Width = 326 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 4 BorderSpacing.Bottom = 8 @@ -523,7 +522,7 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Control = edCountryW AnchorSideTop.Side = asrCenter AnchorSideRight.Control = edCompany - Left = 68 + Left = 64 Height = 15 Top = 251 Width = 56 @@ -542,10 +541,10 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = edCompany AnchorSideRight.Side = asrBottom - Left = 132 + Left = 128 Height = 23 Top = 247 - Width = 338 + Width = 326 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 4 BorderSpacing.Bottom = 8 @@ -574,7 +573,7 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Control = edAddressH AnchorSideTop.Side = asrCenter AnchorSideRight.Control = edAddressH - Left = 69 + Left = 65 Height = 15 Top = 4 Width = 55 @@ -591,11 +590,11 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Control = gbHomeAddress AnchorSideRight.Control = gbHomeAddress AnchorSideRight.Side = asrBottom - Left = 132 + Left = 128 Height = 23 Top = 0 - Width = 338 - Anchors = [akTop, akRight] + Width = 342 + Anchors = [akTop, akLeft, akRight] BorderSpacing.Right = 8 MaxLength = 100 OnChange = ItemChanged @@ -606,7 +605,7 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Control = edCityH AnchorSideTop.Side = asrCenter AnchorSideRight.Control = edCityH - Left = 90 + Left = 86 Height = 15 Top = 31 Width = 34 @@ -625,10 +624,10 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = edAddressH AnchorSideRight.Side = asrBottom - Left = 132 + Left = 128 Height = 23 Top = 27 - Width = 338 + Width = 342 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 4 MaxLength = 50 @@ -640,7 +639,7 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Control = edStateH AnchorSideTop.Side = asrCenter AnchorSideRight.Control = edStateH - Left = 85 + Left = 81 Height = 15 Top = 58 Width = 39 @@ -659,10 +658,10 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = edAddressH AnchorSideRight.Side = asrBottom - Left = 132 + Left = 128 Height = 23 Top = 54 - Width = 338 + Width = 342 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 4 MaxLength = 25 @@ -674,7 +673,7 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Control = cbStateH AnchorSideTop.Side = asrCenter AnchorSideRight.Control = cbStateH - Left = 49 + Left = 45 Height = 15 Top = 85 Width = 79 @@ -694,10 +693,10 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = edAddressH AnchorSideRight.Side = asrBottom - Left = 132 + Left = 128 Height = 23 Top = 81 - Width = 338 + Width = 342 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 4 ItemHeight = 15 @@ -710,7 +709,7 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Control = edZipCodeH AnchorSideTop.Side = asrCenter AnchorSideRight.Control = edZipCodeH - Left = 66 + Left = 62 Height = 15 Top = 112 Width = 58 @@ -728,7 +727,7 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Control = cbStateH AnchorSideTop.Side = asrBottom AnchorSideRight.Side = asrBottom - Left = 132 + Left = 128 Height = 23 Top = 108 Width = 120 @@ -743,7 +742,7 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Control = cbCountryH AnchorSideTop.Side = asrCenter AnchorSideRight.Control = cbCountryH - Left = 28 + Left = 24 Height = 15 Top = 139 Width = 96 @@ -763,10 +762,10 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = edAddressH AnchorSideRight.Side = asrBottom - Left = 132 + Left = 128 Height = 23 Top = 135 - Width = 338 + Width = 342 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 4 BorderSpacing.Bottom = 8 @@ -781,7 +780,7 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Control = edCountryH AnchorSideTop.Side = asrCenter AnchorSideRight.Control = edCountryH - Left = 68 + Left = 64 Height = 15 Top = 170 Width = 56 @@ -800,10 +799,10 @@ object ContactEditForm: TContactEditForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = edAddressH AnchorSideRight.Side = asrBottom - Left = 132 + Left = 128 Height = 23 Top = 166 - Width = 338 + Width = 342 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 4 BorderSpacing.Bottom = 8 @@ -814,7 +813,7 @@ object ContactEditForm: TContactEditForm end object tabContact: TTabSheet Caption = 'tabContact' - ClientHeight = 545 + ClientHeight = 549 ClientWidth = 498 ImageIndex = 1 object gbPhone: TGroupBox @@ -1233,7 +1232,7 @@ object ContactEditForm: TContactEditForm end object tabCustom: TTabSheet Caption = 'tabCustom' - ClientHeight = 545 + ClientHeight = 549 ClientWidth = 498 ImageIndex = 3 object lblCustom1: TLabel diff --git a/components/tvplanit/source/vpcontacteditdlg.pas b/components/tvplanit/source/vpcontacteditdlg.pas index 16d3f7e63..d513b3023 100644 --- a/components/tvplanit/source/vpcontacteditdlg.pas +++ b/components/tvplanit/source/vpcontacteditdlg.pas @@ -166,6 +166,7 @@ type ceContact: TVpContact; ceResource: TVpResource; public + constructor Create(AOwner: TComponent); override; function AddNewContact: Boolean; function Execute(Contact: TVpContact): Boolean; reintroduce; published @@ -256,7 +257,8 @@ end; procedure TContactEditForm.OKBtnClick(Sender: TObject); begin if (edLastName.Text = '') and (edFirstName.Text = '') then begin - raise EVpContactEditError.Create(RSNameIsRequired); + MessageDlg(RSNameIsRequired, mtError, [mbOK], 0); +// raise EVpContactEditError.Create(RSNameIsRequired); exit; end; ReturnCode := rtCommit; @@ -350,11 +352,12 @@ begin edFirstName.Text := Contact.FirstName; edTitle.Text := Contact.Title; if contact.Birthdate = 0.0 then - edBirthdate.Clear else + edBirthdate.Clear + else edBirthdate.Date := Contact.Birthdate; cbCategory.Items.Clear; - for ct := Low (TVpCategoryType) to High (TVpCategoryType) do + for ct := Low(TVpCategoryType) to High(TVpCategoryType) do cbCategory.Items.Add(CategoryLabel(ct)); cbCategory.ItemIndex := Contact.Category; @@ -505,19 +508,22 @@ var Labels: TLabelArray; Comboboxes: TComboboxArray; largestLabelWidth: Integer; - i: Integer; + comboArrowWidth: Integer; + i, w: Integer; OldFont: TFont; + hlabeldist: Integer = 8; // min distance from label to edge of owner hdist: Integer = 4; // Horizontal distance between label and edit/combo vDist: Integer = 4; // Vertical distance between edits hBorder: Integer = 8; // Horizontal distance between container border and label vBorder: Integer = 8; // Vertical distance between container border and 1st control - comboArrowWidth: Integer; + P: TPoint; begin {----------------------------------------------------------------------------} { Preparations } {----------------------------------------------------------------------------} hdist := ScaleX(hdist, DesignTimeDPI); vdist := ScaleY(vdist, DesignTimeDPI); + hlabeldist := ScaleX(hlabeldist, DesignTimeDPI); hBorder := ScaleX(hBorder, DesignTimeDPI); vBorder := ScaleY(vBorder, DesignTimeDPI); edBirthdate.ButtonWidth := edBirthdate.Height; @@ -540,6 +546,17 @@ begin {----------------------------------------------------------------------------} { Page "Base data" } {----------------------------------------------------------------------------} + SetLength(labels, 5); + labels[0] := lblLastName; + labels[1] := lblFirstName; + labels[2] := lblTitle; + labels[3] := lblCategory; + labels[4] := lblBirthdate; + largestLabelWidth := 0; + for i:=0 to High(labels) do + largestLabelWidth := Max(largestLabelWidth, GetLabelWidth(labels[i])); + edLastName.Left := largestLabelWidth + hlabelDist; + edBirthdate.Width := edTitle.Width; cbCategory.Width := edTitle.Width; {$IFDEF NEW_ICONS} @@ -583,6 +600,25 @@ begin Comboboxes[i].Width := largestLabelWidth; end; + {----------------------------------------------------------------------------} + { Page "Adresses" } + {----------------------------------------------------------------------------} + SetLength(labels, 8); + labels[0] := lblCompany; + labels[1] := lblDepartment; + labels[2] := lblPosition; + labels[3] := lblAddressW; + labels[4] := lblCityW; + labels[5] := lblZipCodeW; + labels[6] := lblStateW; + labels[7] := lblCountryW; + largestLabelWidth := 0; + for i:=0 to High(labels) do + largestLabelWidth := Max(largestLabelWidth, GetLabelWidth(labels[i])); + + edCompany.Left := largestlabelWidth + hlabeldist; + edAddressH.Left := edCompany.Left; + {----------------------------------------------------------------------------} { Page "User-defined" } {----------------------------------------------------------------------------} @@ -596,12 +632,15 @@ begin for i := Low(Labels) to High(Labels) do largestLabelWidth := Max(largestLabelWidth, GetLabelWidth(Labels[i])); - edCustom1.Left := hBorder + largestLabelWidth + hDist; + edCustom1.Left := hBorder + largestLabelWidth + hLabelDist; {----------------------------------------------------------------------------} { Form size } {----------------------------------------------------------------------------} - Autosize := true; + P := Point(0, gbHomeAddress.Height + gbHomeAddress.BorderSpacing.Bottom); + P := gbHomeAddress.ClientToScreen(P); + P := ScreenToClient(P); + Height := P.Y + pnlBottom.Height; end; procedure TContactEditForm.DisplayCurrentCountry(AddressType: TVpAddressType); @@ -781,6 +820,33 @@ end; { TVpContactEditDialog } +constructor TVpContactEditDialog.Create(AOwner: TComponent); +begin + inherited; + FOptions := FOptions + [doSizeable]; +end; + +function TVpContactEditDialog.AddNewContact: Boolean; +begin + result := false; + if DataStore <> nil then begin + if DataStore.Resource = nil then + Exit; + ceContact := DataStore.Resource.Contacts.AddContact( + DataStore.GetNextID(ContactsTableName)); + if ceContact <> nil then begin + Result := Execute(ceContact); + if not Result then + (* + if Result then + DataStore.PostContacts + else + *) + ceContact.Free; + end; + end; +end; + function TVpContactEditDialog.Execute(Contact: TVpContact): Boolean; var EditForm: TContactEditForm; @@ -812,27 +878,6 @@ begin end; end; -function TVpContactEditDialog.AddNewContact: Boolean; -begin - result := false; - if DataStore <> nil then begin - if DataStore.Resource = nil then - Exit; - ceContact := DataStore.Resource.Contacts.AddContact( - DataStore.GetNextID(ContactsTableName)); - if ceContact <> nil then begin - Result := Execute(ceContact); - if not Result then - (* - if Result then - DataStore.PostContacts - else - *) - ceContact.Free; - end; - end; -end; - end. diff --git a/components/tvplanit/source/vpcontactgridpainter.pas b/components/tvplanit/source/vpcontactgridpainter.pas index 6d3aeb605..d27dee24b 100644 --- a/components/tvplanit/source/vpcontactgridpainter.pas +++ b/components/tvplanit/source/vpcontactgridpainter.pas @@ -241,13 +241,6 @@ var baseTextHeight: Integer; maxTextWidth: Integer; begin - contactCount := FContactGrid.DataStore.Resource.Contacts.Count; - oldCol1RecCount := TVpContactGridOpener(FContactGrid).cgCol1RecCount; - TVpContactGridOpener(FContactGrid).FVisibleContacts := 0; - TVpContactGridOpener(FContactGrid).cgCol1RecCount := 0; - TextXOffset := 0; - TextYOffset := 0; - { if the component is sufficiently small then no sense in painting it } if (FContactGrid.Height < 20) then exit; @@ -258,6 +251,14 @@ begin then Exit; + { Some initializations } + contactCount := FContactGrid.DataStore.Resource.Contacts.Count; + oldCol1RecCount := TVpContactGridOpener(FContactGrid).cgCol1RecCount; + TVpContactGridOpener(FContactGrid).FVisibleContacts := 0; + TVpContactGridOpener(FContactGrid).cgCol1RecCount := 0; + TextXOffset := 0; + TextYOffset := 0; + { create a temporary bitmap for painting the items } TmpBmp := TBitmap.Create; try diff --git a/components/tvplanit/source/vpdlg.pas b/components/tvplanit/source/vpdlg.pas index 5462e3ba5..b73e9b356 100644 --- a/components/tvplanit/source/vpdlg.pas +++ b/components/tvplanit/source/vpdlg.pas @@ -74,18 +74,17 @@ type function GetVersion: String; procedure SetVersion(const Value: string); - procedure SetControlLink (const v : TVpControlLink); + procedure SetControlLink (const v: TVpControlLink); procedure SetDataStore(Value: TVpCustomDataStore); - procedure DoFormPlacement(Form : TForm); - procedure SetFormCaption(Form : TForm; const Title, SubTitle : string); - property Options : TVpDialogOptions read FOptions write FOptions; - property Placement : TVpDialogPlacement read FPlacement write FPlacement; + procedure DoFormPlacement(Form: TForm); + procedure SetFormCaption(Form: TForm; const Title, SubTitle: string); + property Options: TVpDialogOptions read FOptions write FOptions; + property Placement: TVpDialogPlacement read FPlacement write FPlacement; public - constructor Create(AOwner : TComponent); override; + constructor Create(AOwner: TComponent); override; destructor Destroy; override; - function Execute : Boolean; virtual; - property ControlLink : TVpControlLink - read FControlLink write SetControlLink; + function Execute: Boolean; virtual; + property ControlLink: TVpControlLink read FControlLink write SetControlLink; published property DataStore: TVpCustomDataStore read FDataStore write SetDataStore; property Version: string read GetVersion write SetVersion;