OSDN Git Service

カラムソートのカラム位置に対する依存性を改善(不完全)。
[gikonavigoeson/gikonavi.git] / Sort.pas
1 unit Sort;
2
3 interface
4 uses
5         Windows, Messages, SysUtils, Classes, Controls, Forms,
6         BoardGroup,DateUtils,
7         Setting;
8
9         function CategorySortProc(Item1, Item2: Pointer): integer;
10         function BoardSortProc(List: TStringList; Item1, Item2: Integer): integer;
11         function ThreadItemSortProc(List: TStringList; Item1, Item2: Integer): integer;
12         function CompareBool(Item1, Item2: Boolean): integer;
13         function CompareInt(Item1, Item2: Integer): Integer;
14         function CompareDate(Item1, Item2: TDateTime): Integer;
15
16 var
17         SortOrder: Boolean;
18         SortIndex: Integer;
19         SortNoFlag: Boolean;
20         SortNonAcquiredCountFlag: Boolean;
21
22 implementation
23
24 function CategorySortProc(Item1, Item2: Pointer): integer;
25 var
26         CategoryItem1: TCategory;
27         CategoryItem2: TCategory;
28 begin
29         CategoryItem1 := TCategory(Item1);
30         CategoryItem2 := TCategory(Item2);
31
32         case TGikoBBSColumnID( SortIndex ) of
33         gbbscTitle:
34                 if SortNoFlag then
35                         Result := CompareInt(CategoryItem1.No, CategoryItem2.No)
36                 else
37                         Result := AnsiCompareText(CategoryItem1.Title, CategoryItem2.Title);
38         end;
39
40         if not SortOrder then
41                 Result := Result * -1;
42 end;
43
44 function BoardSortProc(List: TStringList; Item1, Item2: Integer): integer;
45 var
46         BoardItem1: TBoard;
47         BoardItem2: TBoard;
48 begin
49         BoardItem1 := TBoard(List.Objects[Item1]);
50         BoardItem2 := TBoard(List.Objects[Item2]);
51         case TGikoCategoryColumnID( SortIndex ) of
52         gccTitle:
53                 if SortNoFlag then
54                         Result := CompareInt(BoardItem1.No, BoardItem2.No)
55                 else
56                         Result := AnsiCompareText(BoardItem1.Title, BoardItem2.Title);
57
58         gccRoundName:
59                 Result := CompareInt(BoardItem1.Count, BoardItem2.Count);
60
61         gccLastModified:
62                 Result := CompareDate(BoardItem1.RoundDate, BoardItem2.RoundDate);
63         end;
64
65         if not SortOrder then
66                 Result := Result * -1;
67 end;
68
69 function ThreadItemSortProc(List: TStringList; Item1, Item2: Integer): integer;
70 var
71         ThreadItem1: TThreadItem;
72         ThreadItem2: TThreadItem;
73 begin
74         ThreadItem1 := TThreadItem(List.Objects[ Item1 ]);
75         ThreadItem2 := TThreadItem(List.Objects[ Item2 ]);
76         case TGikoBoardColumnID( SortIndex ) of
77                 gbcTitle:
78                         begin
79                                 if SortNoFlag then
80                                         Result := CompareInt(ThreadItem1.No, ThreadItem2.No)
81                                 else
82                                         Result := AnsiCompareText(ThreadItem1.Title, ThreadItem2.Title)
83                         end;
84
85                 gbcAllCount:                    Result := CompareInt(ThreadItem1.AllResCount, ThreadItem2.AllResCount);
86                 gbcLocalCount:          Result := CompareInt(ThreadItem1.Count, ThreadItem2.Count);
87                 gbcNonAcqCount:
88                         begin
89                                 if ThreadItem1.IsLogFile and ThreadItem2.IsLogFile then
90                                         Result := CompareInt(ThreadItem1.AllResCount - ThreadItem1.Count, ThreadItem2.AllResCount - ThreadItem2.Count)
91                                 else if ThreadItem1.IsLogFile then
92                                         Result := 1
93                                 else if ThreadItem2.IsLogFile then
94                                         Result := -1
95                                 else
96                                         Result := 0;
97                         end;
98
99                 gbcNewCount:                    Result := CompareInt(ThreadItem1.NewResCount, ThreadItem2.NewResCount);
100                 gbcUnReadCount:         Result := 0;
101                 gbcRoundName:           Result := AnsiCompareText(ThreadItem1.RoundName, ThreadItem2.RoundName);
102                 gbcLastModified:        Result := CompareDateTime(ThreadItem1.RoundDate, ThreadItem2.RoundDate);
103                 gbcCreated:                             Result := CompareDateTime(ThreadItem1.CreateDate, ThreadItem2.CreateDate);
104         else
105                 Result := 0;
106         end;
107
108 {       if SortIndex = 0 then
109                 if SortNoFlag then
110                         Result := CompareInt(ThreadItem1.No, ThreadItem2.No)
111                 else
112                         Result := CompareText(ThreadItem1.Title, ThreadItem2.Title)
113         else if SortIndex = 1 then
114                 Result := CompareInt(ThreadItem1.Count, ThreadItem2.Count)
115         else if SortIndex = 2 then
116 //              Result := CompareInt(ThreadItem1.RoundNo, ThreadItem2.RoundNo)
117                 Result := CompareText(ThreadItem1.RoundName, ThreadItem2.RoundName)
118         else
119                 Result := CompareDate(ThreadItem1.LastModified, ThreadItem2.LastModified);
120 }
121         if not SortOrder then
122                 Result := Result * -1;
123
124         // \83\\81[\83g\95]\89¿\82ª\93¯\82\8fê\8d\87\82Í\81A\91æ1\83J\83\89\83\80\82Ì\8f¸\8f\87\82É\83\\81[\83g
125         if Result = 0 then begin
126                 if SortNoFlag then
127                         Result := CompareInt(ThreadItem1.No, ThreadItem2.No)
128                 else
129                         Result := AnsiCompareText(ThreadItem1.Title, ThreadItem2.Title)
130         end;
131 end;
132
133 function CompareBool(Item1, Item2: Boolean): Integer;
134 begin
135         if (Item1 = True) and (Item2 = False) then
136                 Result := 1
137         else if (Item2 = False) and (Item2 = True) then
138                 Result := -1
139         else
140                 Result := 0;
141 end;
142
143 function CompareInt(Item1, Item2: Integer): Integer;
144 begin
145         if Item1 > Item2 then
146                 Result := 1
147         else if Item1 < Item2 then
148                 Result := -1
149         else
150                 Result := 0;
151 end;
152
153 function CompareDate(Item1, Item2: TDateTime): Integer;
154 begin
155         if Item1 > Item2 then
156                 Result := 1
157         else if Item1 < Item2 then
158                 Result := -1
159         else
160                 Result := 0;
161 end;
162
163 end.