1 /*
2  *  "GEDKeeper", the personal genealogical database editor.
3  *  Copyright (C) 2009-2017 by Sergey V. Zhdanovskih.
4  *
5  *  This file is part of "GEDKeeper".
6  *
7  *  This program is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 using System;
22 using BSLib.Design.MVP;
23 using BSLib.Design.MVP.Controls;
24 using GDModel;
25 using GKCore.Interfaces;
26 using GKCore.Operations;
27 using GKCore.Types;
28 
29 namespace GKCore.Lists
30 {
ModifyEventHandler(object sender, ModifyEventArgs eArgs)31     public delegate void ModifyEventHandler(object sender, ModifyEventArgs eArgs);
ItemValidatingEventHandler(object sender, ItemValidatingEventArgs e)32     public delegate void ItemValidatingEventHandler(object sender, ItemValidatingEventArgs e);
33 
34     /// <summary>
35     ///
36     /// </summary>
37     public class ModifyEventArgs : EventArgs
38     {
39         public RecordAction Action { get; private set; }
40         public object ItemData { get; set; }
41         public bool IsChanged { get; set; }
42 
ModifyEventArgs(RecordAction action, object itemData)43         public ModifyEventArgs(RecordAction action, object itemData)
44         {
45             Action = action;
46             ItemData = itemData;
47             IsChanged = false;
48         }
49     }
50 
51     public class ItemValidatingEventArgs : EventArgs
52     {
53         private bool fIsAvailable;
54         private object fItem;
55 
56         public bool IsAvailable
57         {
58             get { return fIsAvailable; }
59             set { fIsAvailable = value; }
60         }
61 
62         public object Item
63         {
64             get { return fItem; }
65             set { fItem = value; }
66         }
67 
ItemValidatingEventArgs()68         public ItemValidatingEventArgs() : this(null)
69         {
70         }
71 
ItemValidatingEventArgs(object item)72         public ItemValidatingEventArgs(object item)
73         {
74             fItem = item;
75         }
76     }
77 
78 
79     public enum SheetButton
80     {
81         lbAdd,
82         lbEdit,
83         lbDelete,
84         lbJump,
85         lbMoveUp,
86         lbMoveDown
87     }
88 
89 
90     public interface ISheetList : IBaseControl
91     {
92         ListModel ListModel { get; set; }
93         bool ReadOnly { get; set; }
94 
AddColumn(string caption, int width, bool autoSize)95         void AddColumn(string caption, int width, bool autoSize);
AddItem(object rowData, params object[] columnValues)96         IListItem AddItem(object rowData, params object[] columnValues);
BeginUpdate()97         void BeginUpdate();
EndUpdate()98         void EndUpdate();
ClearColumns()99         void ClearColumns();
ClearItems()100         void ClearItems();
ResizeColumn(int columnIndex)101         void ResizeColumn(int columnIndex);
UpdateSheet()102         void UpdateSheet();
103     }
104 
105     /// <summary>
106     ///
107     /// </summary>
108     public abstract class ListModel : ListSource
109     {
110         protected ISheetList fSheetList;
111         protected readonly IBaseWindow fBaseWin;
112         protected readonly ChangeTracker fUndoman;
113         protected GDMObject fDataOwner;
114 
115 
116         public GDMObject DataOwner
117         {
118             get {
119                 return fDataOwner;
120             }
121             set {
122                 fDataOwner = value;
123                 UpdateContents();
124             }
125         }
126 
127         public ISheetList SheetList
128         {
129             get {
130                 return fSheetList;
131             }
132             set {
133                 if (fSheetList != value) {
134                     fSheetList = value;
135                 }
136             }
137         }
138 
ListModel(IBaseWindow baseWin, ChangeTracker undoman)139         protected ListModel(IBaseWindow baseWin, ChangeTracker undoman) :
140             base(baseWin.Context, new ListColumns())
141         {
142             fBaseWin = baseWin;
143             fUndoman = undoman;
144         }
145 
UpdateColumns(IListViewEx listView)146         public override void UpdateColumns(IListViewEx listView)
147         {
148             if (listView == null) return;
149 
150             ColumnsMap_Clear();
151 
152             int num = fListColumns.Count;
153             for (int i = 0; i < num; i++) {
154                 ListColumn cs = fListColumns.OrderedColumns[i];
155 
156                 AddColumn(listView, LangMan.LS(cs.ColName), cs.CurWidth, false, cs.Id, 0);
157             }
158 
159             ColumnsHaveBeenChanged = false;
160         }
161 
Modify(object sender, ModifyEventArgs eArgs)162         public abstract void Modify(object sender, ModifyEventArgs eArgs);
163     }
164 }
165