summaryrefslogtreecommitdiff
path: root/plugins/HistoryPlusPlus/hpp_opt_dialog.pas
blob: f203f59a6a107ad773d65e10b6a32af5010d9166 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
(*
    History++ plugin for Miranda IM: the free IM client for Microsoft* Windows*

    Copyright (C) 2006-2009 theMIROn, 2003-2006 Art Fedorov.
    History+ parts (C) 2001 Christian Kastner

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*)

unit hpp_opt_dialog;

interface

uses
  Windows;

const
  IDD_OPT_HISTORYPP = 207; // dialog id

function OptDialogProc(hwndDlg: HWND; uMsg: UInt; wParam: WPARAM; lParam: LPARAM): lresult; stdcall;

var
  hDlg: HWND = 0;

implementation

uses
  Messages, CommCtrl,
  m_api,
  hpp_global, hpp_options, hpp_services, hpp_database
  {$IFNDEF NO_EXTERNALGRID}, hpp_external{$ENDIF},
  HistoryForm, GlobalSearch;

const
  ID_APPEARANCE_GROUP  = 100; // "Appearance options" group
  IDC_SHOWEVENTICONS   = 101; // "Show event icons" checkbox
  IDC_RTLDEFAULT       = 102; // "RTL by default" checkbox
  IDC_OPENDETAILS      = 103; // "Open event details by Enter" checkbox
  IDC_SHOWEVENTSCOUNT  = 104; // "Show events count in menu" checkbox
  IDC_SHOWAVATARS      = 105; // "Show avatars" checkbox

  ID_FORMATTING_GROUP  = 200; // "Text formatting options" group
  IDC_BBCODE           = 201; // "Enable BBCodes" checkbox
  IDC_SMILEY           = 202; // "Enable SmileyAdd support" checkbox
  IDC_RAWRTF           = 204; // "Enable raw RTF support" checkbox
  IDC_AVATARSHISTORY   = 205; // "Display chanage avatars" checkbox

  ID_MESSAGELOG_GROUP  = 300; // "Message log options" group
  IDC_GROUPLOGITEMS    = 302; // "Group messages" checkbox
  IDC_DISABLEBORDER    = 303; // "Disable border" checkbox
  IDC_DISABLESCROLL    = 304; // "Disable scrollbar" checkbox

  ID_HISTORYVIEW_GROUP = 500;// "History view options" group
  IDC_RECENTONTOP      = 501; // "Recent events on top" checkbox
  IDC_GROUPHISTITEMS   = 502; // "Group messages" checkbox

  ID_NEEDOPTIONS_LINK  = 250; // "Visit Wiki page for more options" hyperlink

  ID_NEED_RESTART      = 999; // "Please restart Miranda IM..."

const
  URL_NEEDOPTIONS = 'https://miranda-ng.org/p/HistoryPP#Hidden_settings';

{
function GetText(idCtrl: Integer): AnsiString;
var
  dlg_text: array[0..1023] of AnsiChar;
begin
  ZeroMemory(@dlg_text,SizeOf(dlg_text));
  GetDlgItemText(hDlg,idCtrl,@dlg_text,1023);
  Result := dlg_text;
end;

procedure SetText(idCtrl: Integer; Text: AnsiString);
begin
  SetDlgItemText(hDlg,idCtrl,@Text[1]);
end;
}
procedure SetChecked(idCtrl: Integer; Checked: Boolean);
begin
  if Checked then
    SendDlgItemMessage(hDlg,idCtrl,BM_SETCHECK,BST_CHECKED,0)
  else
    SendDlgItemMessage(hDlg,idCtrl,BM_SETCHECK,BST_UNCHECKED,0);
end;

function GetChecked(idCtrl: Integer): Boolean;
begin
  Result := (SendDlgItemMessage(hDlg,idCtrl,BM_GETCHECK,0,0) = BST_CHECKED);
end;

function AreOptionsChanged: Boolean;
begin
  Result := True;

  if GetChecked(IDC_SHOWEVENTICONS) <> GridOptions.ShowIcons then exit;
  if GetChecked(IDC_RTLDEFAULT) <> GridOptions.RTLEnabled then exit;
  if GetChecked(IDC_OPENDETAILS) <> GridOptions.OpenDetailsMode then exit;
  if GetChecked(IDC_SHOWEVENTSCOUNT) <> ShowHistoryCount then exit;
  //if GetChecked(IDC_SHOWAVATARS) <> GridOptions.ShowAvatars then exit;

  if GetChecked(IDC_BBCODE) <> GridOptions.BBCodesEnabled then exit;
  if SmileyAddEnabled then
    if GetChecked(IDC_SMILEY) <> GridOptions.SmileysEnabled then exit;
  if GetChecked(IDC_RAWRTF) <> GridOptions.RawRTFEnabled then exit;
  if GetChecked(IDC_AVATARSHISTORY) <> GridOptions.AvatarsHistoryEnabled then exit;

  if GetChecked(IDC_RECENTONTOP) <> GetDBBool(hppDBName,'SortOrder',false) then exit;
  if GetChecked(IDC_GROUPHISTITEMS) <> GetDBBool(hppDBName,'GroupHistoryItems',false) then exit;

  {$IFNDEF NO_EXTERNALGRID}
  if GetChecked(IDC_GROUPLOGITEMS) <> GetDBBool(hppDBName,'GroupLogItems',false) then exit;
  if GetChecked(IDC_DISABLEBORDER) <> GetDBBool(hppDBName,'NoLogBorder',false) then exit;
  if GetChecked(IDC_DISABLESCROLL) <> GetDBBool(hppDBName,'NoLogScrollBar',false) then exit;
  {$ENDIF}

  Result := False;
end;

procedure SaveChangedOptions;
var
  ShowRestart: Boolean;
  Checked: Boolean;
  i: Integer;
begin
  ShowRestart := False;
  GridOptions.StartChange;
  try
    GridOptions.ShowIcons := GetChecked(IDC_SHOWEVENTICONS);
    GridOptions.RTLEnabled := GetChecked(IDC_RTLDEFAULT);
    GridOptions.OpenDetailsMode := GetChecked(IDC_OPENDETAILS);

    ShowHistoryCount := GetChecked(IDC_SHOWEVENTSCOUNT);
    if ShowHistoryCount <> GetDBBool(hppDBName,'ShowHistoryCount',false) then
      WriteDBBool(hppDBName,'ShowHistoryCount',ShowHistoryCount);

    //GridOptions.ShowAvatars := GetChecked(IDC_SHOWAVATARS);

    GridOptions.BBCodesEnabled        := GetChecked(IDC_BBCODE);
    GridOptions.RawRTFEnabled         := GetChecked(IDC_RAWRTF);
    GridOptions.AvatarsHistoryEnabled := GetChecked(IDC_AVATARSHISTORY);

    if SmileyAddEnabled  then GridOptions.SmileysEnabled    := GetChecked(IDC_SMILEY);

    SaveGridOptions;
  finally
    GridOptions.EndChange;
  end;

  Checked := GetChecked(IDC_RECENTONTOP);
  if Checked <> GetDBBool(hppDBName,'SortOrder',false) then
  begin
    WriteDBBool(hppDBName,'SortOrder',Checked);
    for i := 0 to HstWindowList.Count - 1 do
    begin
      THistoryFrm(HstWindowList[i]).SetRecentEventsPosition(Checked);
    end;
    if Assigned(fmGlobalSearch) then
      fmGlobalSearch.SetRecentEventsPosition(Checked);
  end;

  Checked := GetChecked(IDC_GROUPHISTITEMS);
  if Checked <> GetDBBool(hppDBName,'GroupHistoryItems',false) then
  begin
    WriteDBBool(hppDBName,'GroupHistoryItems',Checked);
    for i := 0 to HstWindowList.Count - 1 do
      THistoryFrm(HstWindowList[i]).hg.GroupLinked := Checked;
  end;

  {$IFNDEF NO_EXTERNALGRID}
  Checked := GetChecked(IDC_GROUPLOGITEMS);
  if Checked <> GetDBBool(hppDBName,'GroupLogItems',false) then
  begin
    WriteDBBool(hppDBName,'GroupLogItems',Checked);
    ExternalGrids.GroupLinked := Checked;
  end;

  Checked := GetChecked(IDC_DISABLEBORDER);
  if Checked <> GetDBBool(hppDBName,'NoLogBorder',false) then
    WriteDBBool(hppDBName,'NoLogBorder',Checked);
  //ShowRestart := ShowRestart or (Checked <> DisableLogBorder);

  Checked := GetChecked(IDC_DISABLESCROLL);
  if Checked <> GetDBBool(hppDBName,'NoLogScrollBar',false) then
    WriteDBBool(hppDBName,'NoLogScrollBar',Checked);
  //ShowRestart := ShowRestart or (Checked <> DisableLogScrollbar);
  {$ENDIF}

  if ShowRestart then
    ShowWindow(GetDlgItem(hDlg,ID_NEED_RESTART),SW_SHOW)
  else
    ShowWindow(GetDlgItem(hDlg,ID_NEED_RESTART),SW_HIDE);
end;

function OptDialogProc(hwndDlg: HWND; uMsg: UInt; wParam: WPARAM; lParam: LPARAM): lresult; stdcall;
begin
  Result := 0;
  case uMsg of
    WM_DESTROY: hDlg := 0;

    WM_INITDIALOG: begin
      hDlg := hwndDlg;
      SetChecked(IDC_SHOWEVENTICONS,GridOptions.ShowIcons);
      SetChecked(IDC_RTLDEFAULT,GridOptions.RTLEnabled);
      SetChecked(IDC_OPENDETAILS,GridOptions.OpenDetailsMode);
      SetChecked(IDC_SHOWEVENTSCOUNT,ShowHistoryCount);
      //SetChecked(IDC_SHOWAVATARS,GridOptions.ShowAvatars);

      SetChecked(IDC_BBCODE,GridOptions.BBCodesEnabled);
      EnableWindow(GetDlgItem(hDlg,IDC_SMILEY),SmileyAddEnabled);
      if SmileyAddEnabled then
        SetChecked(IDC_SMILEY,GridOptions.SmileysEnabled);
      SetChecked(IDC_RAWRTF,GridOptions.RawRTFEnabled);
      SetChecked(IDC_AVATARSHISTORY,GridOptions.AvatarsHistoryEnabled);

      SetChecked(IDC_RECENTONTOP,GetDBBool(hppDBName,'SortOrder',false));
      SetChecked(IDC_GROUPHISTITEMS,GetDBBool(hppDBName,'GroupHistoryItems',false));

      SetChecked(IDC_GROUPLOGITEMS,GetDBBool(hppDBName,'GroupLogItems',false));
      SetChecked(IDC_DISABLEBORDER,GetDBBool(hppDBName,'NoLogBorder',false));
      SetChecked(IDC_DISABLESCROLL,GetDBBool(hppDBName,'NoLogScrollBar',false));

      TranslateDialogDefault(hwndDlg);
    end;

    WM_NOTIFY: begin
      if PNMHDR(lParam)^.code = PSN_APPLY then
      begin
        Result := 1;
        // apply changes here
        SaveChangedOptions;
      end;
    end;

    WM_COMMAND: begin
      case LoWord(wParam) of
        ID_NEEDOPTIONS_LINK: begin
          Utils_OpenUrl(URL_NEEDOPTIONS);
          Result := 1;
        end;
      else
        if AreOptionsChanged then
        begin
          Result := 1;
          SendMessage(GetParent(hDlg),PSM_CHANGED,hDlg,0);
        end;
      end;
    end;

  end;
end;

end.