OSDN Git Service

This commit was manufactured by cvs2svn to create branch 'Bb62'.
[gikonavigoeson/gikonavi.git] / ToolBarUtil.pas
1 unit ToolBarUtil;
2
3 interface
4
5 uses
6         Windows, Messages, SysUtils, Classes, Controls,
7         StdCtrls, ExtCtrls, ComCtrls, ActnList;
8
9 const
10         //\95W\8f\80\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
11         DEF_STANDARD: array[0..11]      of string = ('RoundAction',
12                                                                                                                                                                         '',
13                                                                                                                                                                         'ArrangeAction',
14                                                                                                                                                                         '',
15                                                                                                                                                                         'StopAction',
16                                                                                                                                                                         'LoginAction',
17                                                                                                                                                                         '',
18                                                                                                                                                                         'CabinetBBSAction',
19                                                                                                                                                                         'CabinetHistoryAction',
20                                                                                                                                                                         'CabinetFavoriteAction',
21                                                                                                                                                                         'MuteAction',
22                                                                                     'BeLogInOutAction');
23         //\83\8a\83X\83g\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
24         DEF_LIST:       array[0..18] of string = ('ListNumberVisibleAction',
25                                                                                                                                                                         'IconStyle',
26                                                                                                                                                                         'UpFolderAction',
27                                                                                                                                                                         '',
28                                                                                                                                                                         'AllItemAction',
29                                                                                                                                                                         'LogItemAction',
30                                                                                                                                                                         'NewItemAction',
31                                                                                                                                                                         'LiveItemAction',
32                                                                                                                                                                         'ArchiveItemAction',
33                                                                                                                                                                         'SelectItemAction',
34                                                                                                                                                                         '',
35                                                                                                                                                                         'ThreadEditorAction',
36                                                                                                                                                                         '',
37                                                                                                                                                                         'BoardIEAction',
38                                                                                                                                                                         '',
39                                                                                                                                                                         'SelectListReloadAction',
40                                                                                                                                                                         'SelectThreadReloadAction',
41                                                                                                                                                                         '',
42                                                                                                                                                                         'SelectReservAction');
43         //\83u\83\89\83E\83U\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
44         DEF_BROWSER:  array[0..16] of string = ('BrowserMaxAction',
45                                                                                                                                                                         'BrowserMinAction',
46                                                                                                                                                                         '',
47                                                                                                                                                                         'ScrollTopAction',
48                                                                                                                                                                         'ScrollLastAction',
49                                                                                                                                                                         'ScrollNewAction',
50                                                                                                                                                                         'ScrollKokoAction',
51                                                                                                                                                                         '',
52                                                                                                                                                                         'SelectResAction',
53                                                                                                                                                                         'ResRangeAction',
54                                                                                                                                                                         '',
55                                                                                                                                                                         'EditorAction',
56                                                                                                                                                                         '',
57                                                                                                                                                                         'IEAction',
58                                                                                                                                                                         '',
59                                                                                                                                                                         'ItemReloadAction',
60                                                                                                                                                                         'UpBoardAction'
61                                                                                                                                                                         );
62
63
64         /// \83{\83^\83\93\83X\83^\83C\83\8b\82ª"tbsCheck"\83{\83^\83\93\82Ì\83A\83N\83V\83\87\83\93
65         CHECK_STYLE:   array[0..37] of string = ('CabinetVisibleAction',
66                                                                                     'MuteAction',
67                                                                                                                                                                         'ArrangeAction',
68                                                                                                                                                                         'AllItemAction',
69                                                                                                                                                                         'LogItemAction',
70                                                                                                                                                                         'NewItemAction',
71                                                                                                                                                                         'LiveItemAction',
72                                                                                                                                                                         'ArchiveItemAction',
73                                                                                                                                                                         'SelectItemAction',
74
75                                                                                                                                                                         'StdToolBarVisibleAction',
76                                                                                                                                                                         'AddressBarVisibleAction',
77                                                                                                                                                                         'LinkBarVisibleAction',
78                                                                                                                                                                         'ListToolBarVisibleAction',
79                                                                                                                                                                         'ListNameBarVisibleAction',
80                                                                                                                                                                         'BrowserToolBarVisibleAction',
81                                                                                                                                                                         'BrowserNameBarVisibleAction',
82                                                                                                                                                                         'MsgBarVisibleAction',
83                                                                                                                                                                         'StatusBarVisibleAction',
84                                                                                                                                                                         'CabinetHistoryAction',
85                                           'CabinetFavoriteAction',
86                                                                                                                                                                         'LargeIconAction',
87                                                                                                                                                                         'SmallIconAction',
88                                                                                                                                                                         'ListIconAction',
89                                                                                                                                                                         'DetailIconAction',
90                                                                                                                                                                         'BrowserTabVisibleAction',
91                                                                                                                                                                         'BrowserTabTopAction',
92                                                                                                                                                                         'BrowserTabBottomAction',
93                                                                                                                                                                         'BrowserTabTabStyleAction',
94                                                                                                                                                                         'BrowserTabButtonStyleAction',
95                                                                                                                                                                         'BrowserTabFlatStyleAction',
96                                                                                                                                                                         'LoginAction',
97                                                                                                                                                                         'ListNumberVisibleAction',
98                                                                                                                                                                         'AllResAction',
99                                                                                                                                                                         'SelectResAction',
100                                                                                                                                                                         'OnlyAHundredResAction',
101                                                                                                                                                                         'OnlyKokoResAction',
102                                                                                                                                                                         'OnlyNewResAction',
103                                                                                     'BeLogInOutAction'
104                                                                                                                                                                         );
105
106         /// \83{\83^\83\93\82Ì\83X\83^\83C\83\8b\82ª"tbsDropDown"\83{\83^\83\93\82Ì\83A\83N\83V\83\87\83\93
107         /// Giko.pas : SetToolBarPopup \82à\8fC\90³\82·\82é\8e\96
108         DROPDOWN_STYLE: array[0..4] of string = ('IconStyle',
109                                                                                                                                                                          'IEAction',
110                                                                                                                                                                          'CabinetBBSAction',
111                                                                                                                                                                          'ResRangeAction',
112                                                                                                                                                                          'ThreadRangeAction');
113
114         INI_FILENAME: string = 'ToolBar.ini';
115
116         //\8bæ\90Ø\82è\95\8e\9a
117         SEPARATOR_TEXT = '- \8bæ\90Ø\82è -';
118
119         function IsCheckStyle(Action: TCustomAction): Boolean;
120         function IsDropDownStyle(Action: TCustomAction): Boolean;
121         procedure SetButtonStyle(Action: TCustomAction; Button: TToolButton);
122         function GetActionItem(ActionList: TActionList; ActionName: string): TCustomAction;
123         procedure ReadToolBarSetting(ActionList: TActionList; ToolBar: TToolBar);
124         procedure SaveToolBarSetting(ToolBar: TToolBar);
125         procedure MakeDefaultINIFile();
126
127 implementation
128
129 uses
130         IniFiles,       GikoSystem, MojuUtils;
131
132 function ConvertToolButton( setting : string ) : string;
133 begin
134
135         // \8b\8c [\8dÅ\90V100\83\8c\83X\82Ì\82Ý\95\\8e¦] \82ð [\83\8c\83X\82Ì\95\\8e¦\94Í\88Í\82ð\90Ý\92è] \82É\92u\8a·
136         if setting = 'OnlyAHundredRes' then
137                 Result := 'ResRangeAction'
138         else
139                 Result := setting;
140
141 end;
142
143 procedure ReadToolBarSetting(ActionList: TActionList; ToolBar: TToolBar);
144 var
145         FileName: string;
146         ini: TMemIniFile;
147         i: Integer;
148         s: string;
149         Action: TCustomAction;
150         ToolButton: TToolButton;
151 begin
152         FileName := GikoSys.GetConfigDir + INI_FILENAME;
153         if FileExists(FileName) then begin
154                 for i := ToolBar.ButtonCount - 1 downto 0 do begin
155                         ToolBar.Buttons[i].HostDockSite := nil;
156                 end;
157                 ini := TMemIniFile.Create(FileName);
158                 try
159                         i := 0;
160                         while True do begin
161                                 s := ini.ReadString(ToolBar.Name, 'Button' + IntToStr(i), '');
162                                 s := ConvertToolButton( s );
163                                 if s = '-' then begin
164                                         ToolButton := TToolButton.Create(ToolBar);
165                                         ToolButton.Style := tbsSeparator;
166                                         ToolButton.Width := 8;
167                                         ToolButton.Left := 10000;
168                                         ToolBar.InsertControl(ToolButton);
169                                 end else if s <> '' then begin
170                                         Action := GetActionItem(ActionList, s);
171                                         if Action <> nil then begin
172                                                 ToolButton := TToolButton.Create(ToolBar);
173                                                 ToolButton.Action := Action;
174                                                 if ToolButton.ImageIndex = -1 then
175                                                         ToolButton.ImageIndex := 51;
176
177                                                 ToolButton.Left := 10000;
178                                                 SetButtonStyle(Action, ToolButton);
179                                                 ToolBar.InsertControl(ToolButton);
180                                         end;
181                                 end else
182                                         Break;
183                                 inc(i);
184                         end;
185                 finally
186                         ini.Free;
187                 end;
188         end;
189 end;
190
191 procedure SaveToolBarSetting(ToolBar: TToolBar);
192 var
193         ini: TMemIniFile;
194         i, j: Integer;
195         Action: TBasicAction;
196 begin
197         ini := TMemIniFile.Create(GikoSys.GetConfigDir + INI_FILENAME);
198         j := 0;
199         try
200                 ini.EraseSection(ToolBar.Name);
201                 for i := 0 to ToolBar.ButtonCount - 1 do begin
202                         if ToolBar.Buttons[i].Style = tbsSeparator then begin
203                 //SelectComboBox\97p\82Ì\83_\83~\81[\82Í\95Û\91\82µ\82È\82¢
204                                 if not (ToolBar.Buttons[i].Name = 'SelectComboBoxDummy') then begin
205                                         ini.WriteString(ToolBar.Name, 'Button' + IntToStr(j), '-');
206                                         Inc( j );
207                                 end;
208                         end else begin
209                                 Action := ToolBar.Buttons[i].Action;
210                                 if Action <> nil then
211                                                                 begin
212                                         ini.WriteString(ToolBar.Name, 'Button' + IntToStr(j), Action.Name);
213                                         Inc( j );
214                                 end;
215                         end;
216                 end;
217                 ini.UpdateFile;
218         finally
219                 ini.Free;
220         end;
221 end;
222
223 //ActionName\82ÌAction\82ð\95Ô\82µ\82Ü\82·
224 function GetActionItem(ActionList: TActionList; ActionName: string): TCustomAction;
225 var
226         i: Integer;
227 begin
228         for i := 0 to ActionList.ActionCount - 1 do begin
229                 if ActionList.Actions[i].Name = ActionName then begin
230                         Result := TCustomAction(ActionList.Actions[i]);
231                         Exit;
232                 end;
233         end;
234         Result := nil;
235 end;
236
237 //\83c\81[\83\8b\83{\83^\83\93\82Ì\83X\83^\83C\83\8b\90Ý\92è\82Æ\83|\83b\83v\83A\83b\83v\90Ý\92è
238 procedure SetButtonStyle(Action: TCustomAction; Button: TToolButton);
239 begin
240         if IsCheckStyle(Action) then
241                 Button.Style := tbsCheck
242         else if IsDropDownStyle(Action) then
243                 Button.Style := tbsDropDown
244         else
245                 Button.Style := tbsButton;
246 end;
247
248 //Action\82ª\83`\83F\83b\83N\83X\83^\83C\83\8b\82Ì\83A\83N\83V\83\87\83\93\82©\82Ç\82¤\82©\82ð\95Ô\82µ\82Ü\82·
249 function IsCheckStyle(Action: TCustomAction): Boolean;
250 var
251         i: Integer;
252 begin
253         for i := 0 to Length(CHECK_STYLE) - 1 do begin
254                 if Action.Name = CHECK_STYLE[i] then begin
255                         Result := True;
256                         Exit;
257                 end;
258         end;
259         Result := False;
260 end;
261
262 //Action\82ª\83h\83\8d\83b\83v\83_\83E\83\93\83X\83^\83C\83\8b\82Ì\83A\83N\83V\83\87\83\93\82©\82Ç\82¤\82©\82ð\95Ô\82µ\82Ü\82·
263 function IsDropDownStyle(Action: TCustomAction): Boolean;
264 var
265         i: Integer;
266 begin
267         for i := 0 to Length(DROPDOWN_STYLE) - 1 do begin
268                 if Action.Name = DROPDOWN_STYLE[i] then begin
269                         Result := True;
270                         Exit;
271                 end;
272         end;
273         Result := False;
274 end;
275
276 procedure MakeDefaultINIFile();
277 var
278         ini: TMemIniFile;
279     i: Integer;
280 begin
281         //\95W\8f\80\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
282         //DEF_STANDARD:
283         //\83\8a\83X\83g\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
284         //DEF_LIST:
285         //\83u\83\89\83E\83U\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
286         //DEF_BROWSER:
287     if not FileExists(GikoSys.GetConfigDir + INI_FILENAME) then begin
288             ini := TMemIniFile.Create(GikoSys.GetConfigDir + INI_FILENAME);
289         try
290             for i := 0 to Length(DEF_STANDARD) - 1 do begin
291                 if DEF_STANDARD[i] <> '' then
292                         ini.WriteString('StdToolBar', 'Button' + IntToStr(i), DEF_STANDARD[i])
293                 else
294                         ini.WriteString('StdToolBar', 'Button' + IntToStr(i), '-');
295             end;
296             for i := 0 to Length(DEF_LIST) - 1 do begin
297                 if DEF_LIST[i] <> '' then
298                         ini.WriteString('ListToolBar', 'Button' + IntToStr(i), DEF_LIST[i])
299                 else
300                         ini.WriteString('ListToolBar', 'Button' + IntToStr(i), '-');
301             end;
302             for i := 0 to Length(DEF_BROWSER) - 1 do begin
303                 if DEF_BROWSER[i] <> '' then
304                         ini.WriteString('BrowserToolBar', 'Button' + IntToStr(i), DEF_BROWSER[i])
305                 else
306                         ini.WriteString('BrowserToolBar', 'Button' + IntToStr(i), '-');
307             end;
308
309         finally
310                 ini.UpdateFile;
311             ini.Free;
312         end;
313     end;
314
315 end;
316
317 end.