summaryrefslogtreecommitdiff
path: root/extras
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-05-20 09:38:00 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-05-20 09:38:00 +0000
commit593ee71c3bbb694c8e607fe36f5452cd97ad362d (patch)
tree08d177373bfe399ae80047bb79f23b131807973c /extras
parentf8fdc2ce2938cf387ded4169ef538cd03654aa89 (diff)
downloadfpGUI-593ee71c3bbb694c8e607fe36f5452cd97ad362d.tar.xz
* Updated the tiOPF support code which the latest 0-based indexing changes.
Diffstat (limited to 'extras')
-rw-r--r--extras/tiopf/gui/tiCompositeMediators.pas64
-rw-r--r--extras/tiopf/gui/tiGenericEditMediators.pas37
-rw-r--r--extras/tiopf/gui/tiGenericListMediators.pas77
3 files changed, 79 insertions, 99 deletions
diff --git a/extras/tiopf/gui/tiCompositeMediators.pas b/extras/tiopf/gui/tiCompositeMediators.pas
index cd8d3547..6d0602e8 100644
--- a/extras/tiopf/gui/tiCompositeMediators.pas
+++ b/extras/tiopf/gui/tiCompositeMediators.pas
@@ -12,10 +12,10 @@ interface
uses
Classes
,SysUtils
- ,tiObject
- ,gui_listview { TfpgListView }
,Contnrs { TObjectList }
+ ,gui_listview { TfpgListView }
,gui_grid { TfpgStringGrid }
+ ,tiObject
;
@@ -219,21 +219,19 @@ procedure TStringGridRowMediator.BeforeDestruction;
begin
FModel.DetachObserver(self);
FModel := nil;
-
inherited BeforeDestruction;
end;
procedure TStringGridRowMediator.Update(ASubject: TtiObject);
var
- i : Integer;
- lField : string;
- lFieldName : string;
+ i: Integer;
+ lField: string;
+ lFieldName: string;
begin
Assert(FModel = ASubject);
-
- for i := 1 to tiNumToken(FDisplayNames, cFieldDelimiter) do
+ for i := 0 to tiNumToken(FDisplayNames, cFieldDelimiter)-1 do
begin
- lField := tiToken(FDisplayNames, cFieldDelimiter, i);
+ lField := tiToken(FDisplayNames, cFieldDelimiter, i+1);
lFieldName := tiFieldName(lField);
FView.Cells[i, FRowIndex] := FModel.PropValue[lFieldName];
@@ -303,7 +301,7 @@ procedure TCompositeListViewMediator.SetSelectedObject(const AValue: TtiObject);
var
i: integer;
begin
- for i := 0 to FView.Items.Count - 1 do
+ for i := 0 to FView.Items.Count-1 do
begin
if TtiObject(FView.Items.Item[i].UserData) = AValue then
begin
@@ -329,7 +327,7 @@ end;
procedure TCompositeListViewMediator.SetShowDeleted(const AValue: Boolean);
begin
if FShowDeleted = AValue then
- exit; //==>
+ Exit; //==>
BeginUpdate;
try
@@ -351,7 +349,7 @@ begin
li := TfpgLVItem.Create(FView.Items);
li.UserData := AData;
FView.Items.Add(li);
- m := TListViewListItemMediator.CreateCustom(AData, li, FDisplayNames, FIsObserving);
+ m := TListViewListItemMediator.CreateCustom(AData, li, FDisplayNames, FIsObserving);
FMediatorList.Add(m);
end;
@@ -377,7 +375,7 @@ end;
procedure TCompositeListViewMediator.SetupGUIandObject;
begin
- { Setup TListView defaults }
+ { Setup TfpgListView defaults }
FView.Columns.Clear;
FView.Items.Clear;
// FView.ViewStyle := vsReport;
@@ -442,7 +440,7 @@ begin
SetupGUIandObject;
- { TODO: This must be improved. If no ADisplayNames value maybe default to a
+ { TODO: This must be improved. If no ADisplayNames value, maybe default to a
single column listview using the Caption property }
if (ADisplayNames <> '') and (tiNumToken(ADisplayNames, cFieldDelimiter) > 0) then
begin
@@ -496,7 +494,7 @@ begin
FSelectedObject.ObserverList.Assign(FObserversInTransit);
{ Set the Observers Subject property to the selected object }
- for i := 0 to FSelectedObject.ObserverList.Count - 1 do
+ for i := 0 to FSelectedObject.ObserverList.Count-1 do
begin
TMediatorView(FSelectedObject.ObserverList.Items[i]).Subject :=
FSelectedObject;
@@ -511,24 +509,24 @@ end;
function TCompositeStringGridMediator.GetSelectedObjected: TtiObject;
begin
- if FView.FocusRow = 0 then
+ if FView.FocusRow = -1 then
// if FView.Selection.Top = 0 then
Result := nil
else
// Result := TtiObject(FView.Objects[1, FView.Selection.Top]);
- Result := TtiObject(FView.Objects[1, FView.FocusRow]);
+ Result := TtiObject(FView.Objects[0, FView.FocusRow]);
end;
procedure TCompositeStringGridMediator.SetSelectedObject(const AValue: TtiObject);
var
- i : integer;
+ i: integer;
begin
- for i := 1 to FView.RowCount - 1 do
+ for i := 0 to FView.RowCount-1 do
begin
- if TtiObject(FView.Objects[1, i]) = AValue then
+ if TtiObject(FView.Objects[0, i]) = AValue then
begin
FView.FocusRow := i;
- Exit; //==>
+ Break; //==>
end;
end;
end;
@@ -559,14 +557,14 @@ var
lFieldName: string;
lMediatorView: TStringGridRowMediator;
begin
- FView.Objects[1, pRowIdx + 1] := AData;
+ FView.Objects[0, pRowIdx] := AData;
for i := 1 to tiNumToken(FDisplayNames, cFieldDelimiter) do
begin
lField := tiToken(FDisplayNames, cFieldDelimiter, i);
lFieldName := tiFieldName(lField);
- FView.Cells[i, pRowIdx + 1] := AData.PropValue[lFieldName];
+ FView.Cells[i-1, pRowIdx] := AData.PropValue[lFieldName];
- lMediatorView := TStringGridRowMediator.CreateCustom(AData, FView, FDisplayNames, pRowIdx + 1, FIsObserving);
+ lMediatorView := TStringGridRowMediator.CreateCustom(AData, FView, FDisplayNames, pRowIdx, FIsObserving);
FMediatorList.Add(lMediatorView);
end;
end;
@@ -577,10 +575,10 @@ var
lField: string;
lColumnTotalWidth: integer;
begin
- lColumnTotalWidth:= 0;
- for i := 1 to tiNumToken(FDisplayNames, cFieldDelimiter) do
+ lColumnTotalWidth := 0;
+ for i := 0 to tiNumToken(FDisplayNames, cFieldDelimiter)-1 do
begin
- lField := tiToken(FDisplayNames, cFieldDelimiter, i);
+ lField := tiToken(FDisplayNames, cFieldDelimiter, i+1);
FView.ColumnWidth[i] := tiFieldWidth(lField);
FView.ColumnTitle[i] := tiFieldCaption(lField);
@@ -590,12 +588,10 @@ begin
else
lColumnTotalWidth := lColumnTotalWidth + FView.ColumnWidth[i] + 20;
end;
- for i := 0 to FModel.Count - 1 do
+ for i := 0 to FModel.Count-1 do
begin
if not FModel.Items[i].Deleted or FShowDeleted then
- begin
DoCreateItemMediator(FModel.Items[i], i);
- end;
end;
end;
@@ -611,22 +607,16 @@ procedure TCompositeStringGridMediator.RebuildStringGrid;
var
i: integer;
begin
- writeln('RebuildStringGrid');
{ This rebuilds the whole list. Not very efficient. }
View.BeginUpdate;
try
FMediatorList.Clear;
- for i := View.ColumnCount to 1 do
+ for i := View.ColumnCount-1 downto 0 do
View.DeleteColumn(i);
CreateSubMediators;
finally
View.EndUpdate;
end;
-
-// { Do nothing. Can be implement as you see fit. A simple example is given
-// in the Demos/GenericMediatingViews/Composite_ListView_Mediator }
-// raise EtiOPFProgrammerException.Create('You are trying to call ' + Classname
-// + '.RebuildStringGrid, which must be overridden in the concrete class.');
end;
function TCompositeStringGridMediator.DataAndPropertyValid(const AData: TtiObject): Boolean;
diff --git a/extras/tiopf/gui/tiGenericEditMediators.pas b/extras/tiopf/gui/tiGenericEditMediators.pas
index 6de77905..6ddb345b 100644
--- a/extras/tiopf/gui/tiGenericEditMediators.pas
+++ b/extras/tiopf/gui/tiGenericEditMediators.pas
@@ -3,6 +3,7 @@
Revision history:
2005-08-17: First release by Graeme Geldenhuys (graemeg@gmail.com)
2007-08-24: Ported the code to the fpGUI toolkit. [Graeme]
+ 2008-05-20: Updates due to fpGUI components now being 0-based. [Graeme]
Purpose:
Abstract mediating view and Mediator Factory. This allows you to use
@@ -219,7 +220,7 @@ type
FMediatingViewClass: TMediatingViewClass;
FName: string;
public
- constructor CreateExt( pName: String; pMediatingClass: TMediatingViewClass );
+ constructor CreateExt(pName: String; pMediatingClass: TMediatingViewClass);
property Name: string read FName write FName;
property MediatingViewClass: TMediatingViewClass read FMediatingViewClass write FMediatingViewClass;
end;
@@ -241,9 +242,6 @@ type
{ Factory class to register and create your mediating views }
-
- { TMediatorFactory }
-
TMediatorFactory = class(TObject)
private
MappingList: TStringList;
@@ -268,10 +266,9 @@ uses
SysUtils
,TypInfo
,tiExcept
-// ,Dialogs { MessageDlg }
- ,gui_dialogs // for ShowMessage
- ,tiGUIConstants // for error color
- ,gfxbase // for predefined colors
+ ,gui_dialogs // for TfpgMessageDialog
+ ,tiGUIConstants // for error color
+ ,gfxbase // for predefined colors
;
var
@@ -465,7 +462,7 @@ begin
{ Get the name formatting correct }
lName := Format(cName, [UpperCase(pSubject.ClassName), UpperCase(pFieldName), UpperCase(pComponentClass.ClassName)]);
{ Does the Type exist in the list? }
- i := MappingList.IndexOf( lName );
+ i := MappingList.IndexOf(lName);
if i <> -1 then
Result := TMediatorViewMapping(MappingList.Objects[i]).MediatingViewClass
else
@@ -477,8 +474,8 @@ function TMediatorFactory.GetMediatorClass(pSubject: TtiObject; pComponentClass:
begin
Result := FindMediatorClass(pSubject, pComponentClass, pFieldName);
if not Assigned(Result) then
- raise Exception.Create('No mediator registered for:' + #13#10 +
- ' Component: ' + pComponentClass.ClassName + #13#10 +
+ raise Exception.Create('No mediator registered for:' + LineEnding +
+ ' Component: ' + pComponentClass.ClassName + LineEnding +
' FieldName: ' + pSubject.ClassName + '.' + pFieldName);
end;
@@ -498,9 +495,8 @@ begin
begin { If yes, notify the user }
{ We cannot raise an exception as this will be called in the Initialization
section of a unit. FPC's exception handling may not have been loaded yet! }
-// MessageDlg('Registering a duplicate Mediator View Type <' + FieldName + '> with ' + ClassName,
-// mtInformation, [mbOK], 0);
- ShowMessage('Registering a duplicate Mediator View Type <' + FieldName + '> with ' + ClassName);
+ TfpgMessageDialog.Information('',
+ 'Registering a duplicate Mediator View Type <' + FieldName + '> with ' + ClassName);
end
else
begin { If no, then add it to the list }
@@ -681,9 +677,8 @@ end;
procedure TMediatorComboBoxView.ObjectToGui;
begin
- // NOTE: FocusItem is 1 based!!
EditControl.FocusItem :=
- EditControl.Items.IndexOf(Subject.PropValue[FieldName]) +1;
+ EditControl.Items.IndexOf(Subject.PropValue[FieldName]);
end;
@@ -739,9 +734,7 @@ procedure TMediatorDynamicComboBoxView.SetList(const AValue: TtiObjectList);
begin
if FList = AValue then
Exit; //==>
-
FList := AValue;
-
InternalListRefresh;
end;
@@ -838,10 +831,10 @@ var
begin
if not DataAndPropertyValid then
Exit; //==>
- if EditControl.FocusItem < 1 then
+ if EditControl.FocusItem < 0 then
Exit; //==>
- lValue := TtiObject(FList.Items[EditControl.FocusItem-1]);
+ lValue := TtiObject(FList.Items[EditControl.FocusItem]);
lPropType := typinfo.PropType(Subject, FieldName);
if lPropType = tkClass then
@@ -859,7 +852,7 @@ begin
SetOnChangeActive(false);
// Set the index only (We're assuming the item is present in the list)
- EditControl.FocusItem := 0;
+ EditControl.FocusItem := -1;
if FSubject = nil then
Exit; //==>
@@ -875,7 +868,7 @@ begin
for i := 0 to FList.Count - 1 do
if FList.Items[i] = lValue then
begin
- EditControl.FocusItem := i+1; // Control is 1-based
+ EditControl.FocusItem := i;
Break; //==>
end;
diff --git a/extras/tiopf/gui/tiGenericListMediators.pas b/extras/tiopf/gui/tiGenericListMediators.pas
index 4f15b9d1..faa8de95 100644
--- a/extras/tiopf/gui/tiGenericListMediators.pas
+++ b/extras/tiopf/gui/tiGenericListMediators.pas
@@ -4,6 +4,8 @@ Revision history:
2005-09-01: First release by Graeme Geldenhuys (graemeg@gmail.com)
2007-08-27: Ported the code to the fpGUI toolkit. [Graeme]
+ 2008-05-20: Updates due to fpGUI components now being 0-based. [Graeme]
+
Purpose:
Abstract mediating views for GUI list controls. This allows you to use
@@ -42,10 +44,9 @@ type
Selected Object. }
TUpdateMode = (umSelectedObject, umObjectList);
- { Abstract class that observes a list object }
-
- { TListMediator }
+ { Abstract class that observes a list object }
+
TListMediator = class(TtiObject)
private
FObjectList: TtiObjectList;
@@ -71,7 +72,6 @@ type
constructor CreateCustom(pObjectList: TtiObjectList; pView: TfpgWidget); virtual;
destructor Destroy; override;
procedure Update(pSubject: TtiObject); override;
-
{ Called from GUI to trigger events }
procedure HandleDeleteItem; virtual;
procedure HandleListChanged; virtual;
@@ -79,7 +79,7 @@ type
procedure MenuItemAddClick(Sender: TObject); virtual;
procedure MenuItemEditClick(Sender: TObject); virtual;
procedure MenuItemDeleteClick(Sender: TObject); virtual;
-
+ //
property SelectedObject: TtiObject read FSelectedObject write SetSelectedObject;
property ShowDeleted: Boolean read FShowDeleted write SetShowDeleted;
property Model: TtiObjectList read GetModel write SetModel;
@@ -149,16 +149,16 @@ begin
if Value = nil then
begin
- View.FocusItem := 0;
- exit; //==>
+ View.FocusItem := -1;
+ Exit; //==>
end;
- for i := 0 to Pred(Model.Count) do
+ for i := 0 to Model.Count-1 do
begin
if Value.OID.AsString = Model.Items[i].OID.AsString then
begin
- View.FocusItem := i+1; // fpGUI is 1-based
- exit; //==>
+ View.FocusItem := i;
+ Break; //==>
end;
end;
end;
@@ -172,7 +172,7 @@ procedure TListBoxMediator.HandleSelectionChanged;
var
i: integer;
begin
- if View.FocusItem = 0 then
+ if View.FocusItem = -1 then
FSelectedObject := nil
else
begin
@@ -183,7 +183,7 @@ begin
FObserversInTransit.Assign(FSelectedObject.ObserverList);
// Assign Newly selected item to SelectedObject Obj.
- FSelectedObject := TtiObject(View.Items.Objects[View.FocusItem-1]);
+ FSelectedObject := TtiObject(View.Items.Objects[View.FocusItem]);
{ If an object was selected, copy the old item's observer List
to the new item's observer List. }
@@ -191,7 +191,7 @@ begin
FSelectedObject.ObserverList.Assign(FObserversInTransit);
{ set the observers's Subject property to the selected object }
- for i := 0 to FSelectedObject.ObserverList.Count - 1 do
+ for i := 0 to FSelectedObject.ObserverList.Count-1 do
begin
TMediatorView(FSelectedObject.ObserverList.Items[i]).Subject :=
FSelectedObject;
@@ -209,18 +209,18 @@ var
ptr: TNotifyEvent;
selected: integer;
begin
- selected := 0;
- if (Model.CountNotDeleted) >= View.FocusItem then
+ selected := -1;
+ if (Model.CountNotDeleted) >= View.FocusItem+1 then
begin
selected := View.FocusItem;
end;
ptr := View.OnChange;
View.OnChange := nil;
- View.Items.BeginUpdate;
+ View.BeginUpdate;
try
View.Items.Clear;
- for i := 0 to Pred(Model.Count) do
+ for i := 0 to Model.Count-1 do
begin
if (not Model.Items[i].Deleted) or
(ShowDeleted and Model.Items[i].Deleted) then
@@ -230,13 +230,13 @@ begin
end;
if Model.CountNotDeleted > 0 then
begin
- if selected = 0 then
- selected := 1;
+ if selected = -1 then
+ selected := 0;
View.FocusItem := selected;
end;
finally
- View.Items.EndUpdate;
- view.Update;
+ View.EndUpdate;
+ View.Update;
View.OnChange := ptr;
HandleSelectionChanged;
end;
@@ -245,10 +245,8 @@ end;
procedure TListBoxMediator.RestoreBookmark;
begin
- if OldPos > View.Items.Count then
- NewPos := View.Items.Count
- else if OldPos = 0 then
- NewPos := 0
+ if OldPos > View.Items.Count-1 then
+ NewPos := View.Items.Count-1
else
NewPos := OldPos;
View.FocusItem := NewPos;
@@ -268,18 +266,17 @@ var
i: integer;
begin
inherited SetSelectedObject(Value);
-
if Value = nil then
begin
- View.FocusItem := 0;
- exit; //==>
+ View.FocusItem := -1;
+ Exit; //==>
end;
-
- for i := 0 to Pred(Model.Count) do
+
+ for i := 0 to Model.Count-1 do
begin
if Value = Model.Items[i] then
begin
- View.FocusItem := i+1; // fpGUI is 1-based
+ View.FocusItem := i;
exit; //==>
end;
end;
@@ -295,19 +292,19 @@ procedure TComboBoxMediator.HandleSelectionChanged;
var
i: integer;
begin
- if View.FocusItem = 0 then
+ if View.FocusItem = -1 then
SelectedObject := nil
else
begin
if Assigned(SelectedObject) then
FObserversInTransit.Assign(SelectedObject.ObserverList);
- SelectedObject := TtiObject(View.Items.Objects[View.FocusItem-1]);
+ SelectedObject := TtiObject(View.Items.Objects[View.FocusItem]);
if FObserversInTransit.Count > 0 then
SelectedObject.ObserverList.Assign(FObserversInTransit);
- for i := 0 to SelectedObject.ObserverList.Count - 1 do
+ for i := 0 to SelectedObject.ObserverList.Count-1 do
begin
TMediatorView(SelectedObject.ObserverList.Items[i]).Subject :=
SelectedObject;
@@ -324,8 +321,8 @@ var
ptr: TNotifyEvent;
selected: integer;
begin
- selected := 0;
- if (Model.CountNotDeleted-1) >= View.FocusItem then
+ selected := -1;
+ if Model.CountNotDeleted >= View.FocusItem+1 then
selected := View.FocusItem;
ptr := View.OnChange;
@@ -333,7 +330,7 @@ begin
View.Items.BeginUpdate;
try
View.Items.Clear;
- for i := 0 to Pred(Model.Count) do
+ for i := 0 to Model.Count-1 do
begin
if (not Model.Items[i].Deleted) or
(ShowDeleted and Model.Items[i].Deleted) then
@@ -343,13 +340,13 @@ begin
end;
if Model.CountNotDeleted > 0 then
begin
- if selected = 0 then
- selected := 1;
+ if selected = -1 then
+ selected := 0;
View.FocusItem := selected;
end;
finally
View.Items.EndUpdate;
- View.FocusItem := 1;
+ View.FocusItem := 0;
View.OnChange := ptr;
HandleSelectionChanged;
end;