summaryrefslogtreecommitdiff
path: root/plugins/Actman30/iac_storage.pas
blob: aaa7351452b451542062eba1fe64b406b50a29a4 (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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
unit iac_storage;

interface

implementation

uses
  windows, messages,
  common, wrapper,
  mirutils,m_api,dbsettings,
  global,iac_global;

{$include i_cnst_storage.inc}
{$resource iac_storage.res}

const
  opt_number = 'number';
const
  ioNumber = 'number';
  ioOper   = 'oper';
  ioCopy   = 'copy';
const
  ACF_COPYFROM = $00000001;
type
  tStorageAction = class(tBaseAction)
    Number:integer;

    constructor Create(uid:dword);
    destructor Destroy; override;
//    function  Clone:tBaseAction; override;
    function  DoAction(var WorkData:tWorkData):LRESULT; override;
    procedure Save(node:pointer;fmt:integer); override;
    procedure Load(node:pointer;fmt:integer); override;
  end;

//----- Support functions -----

//----- Object realization -----

constructor tStorageAction.Create(uid:dword);
begin
  inherited Create(uid);

  Number:=0;
end;

destructor tStorageAction.Destroy;
begin

  inherited Destroy;
end;
{
function tStorageAction.Clone:tBaseAction;
begin
  result:=.Create(0);
  Duplicate(result);

end;
}
function tStorageAction.DoAction(var WorkData:tWorkData):LRESULT;
var
  num:integer;
  st,dt:pByte;
  sv,dv:^uint_ptr;
begin
  result:=0;

  if Number in [0..9] then
  begin
    // copy to slot
    if (flags and ACF_COPYFROM)=0 then
    begin
      num:=Number;
      st:=@WorkData.ResultType;
      dt:=@WorkData.Storage[Number].rtype;
      sv:=@WorkData.LastResult;
      dv:=@WorkData.Storage[Number].value;
    end
    // copy from slot
    else
    begin
      num:=-1;
      dt:=@WorkData.ResultType;
      st:=@WorkData.Storage[Number].rtype;
      dv:=@WorkData.LastResult;
      sv:=@WorkData.Storage[Number].value;
    end;

    ClearResult(WorkData,num);
    dt^:=st^;

    if WorkData.ResultType=rtInt then // Number
      dv^:=sv^

    else if WorkData.ResultType=rtWide then // Unicode
      StrDupW(pWideChar(dv^),pWideChar(sv^))
    
    else if WorkData.ResultType<>rtUnkn then // Ansi and UTF8
      StrDup(pAnsiChar(dv^),pAnsiChar(sv^));
  end;

{
  // copy to slot
  if (flags and ACF_COPYFROM)=0 then
  begin
    if Number in [0..9] then
    begin
      ClearResult(WorkData,Number);
      WorkData.Storage[Number].rtype:=WorkData.ResultType;

      if WorkData.ResultType=rtInt then // Number
        WorkData.Storage[Number].value:=WorkData.LastResult

      else if WorkData.ResultType=rtWide then // Unicode
        StrDupW(pWideChar(WorkData.Storage[Number].value),pWideChar(WorkData.LastResult))
      
      else if WorkData.ResultType<>rtUnkn then // Ansi and UTF8
        StrDup(pAnsiChar(WorkData.Storage[Number].value),pAnsiChar(WorkData.LastResult));

    end;
  end
  // copy from slot
  else
  begin
    if Number in [0..9] then
    begin
      ClearResult(WorkData);
      WorkData.ResultType:=WorkData.Storage[Number].rtype;

      if WorkData.ResultType=rtInt then // Number
        WorkData.LastResult:=WorkData.Storage[Number].value

      else if WorkData.ResultType=rtWide then // Unicode
        StrDupW(pWideChar(WorkData.LastResult),pWideChar(WorkData.Storage[Number].value))
      
      else if WorkData.ResultType<>rtUnkn then // Ansi and UTF8
        StrDup(pAnsiChar(WorkData.LastResult),pAnsiChar(WorkData.Storage[Number].value));

    end;
  end;
}
end;

procedure tStorageAction.Load(node:pointer;fmt:integer);
var
  section: array [0..127] of AnsiChar;
  pc:pAnsiChar;
begin
  inherited Load(node,fmt);
  case fmt of
    0: begin
      pc:=StrCopyE(section,pAnsiChar(node));
      StrCopy(pc,opt_number); Number:=DBReadByte(0,DBBranch,section,0);
    end;

    1: begin
      with xmlparser do
      begin
        if lstrcmpiw(getAttrValue(HXML(node),ioOper),ioCopy)=1 then
           flags:=flags or ACF_COPYFROM;
        Number:=StrToInt(getAttrValue(HXML(node),ioNumber));
      end;
    end;
  end;
end;

procedure tStorageAction.Save(node:pointer;fmt:integer);
var
  section: array [0..127] of AnsiChar;
  pc:pAnsiChar;
begin
  inherited Save(node,fmt);
  case fmt of
    0: begin
      pc:=StrCopyE(section,pAnsiChar(node));
      StrCopy(pc,opt_number); DBWriteByte(0,DBBranch,section,Number);
    end;
{
    1: begin
    end;
}
  end;
end;

//----- Dialog realization -----

procedure FillStorageCombo(wnd:HWND);
var
  i:integer;
  buf:array [0..31] of AnsiChar;
  p:pAnsiChar;
begin
  SendMessage(wnd,CB_RESETCONTENT,0,0);

  p:=StrCopyE(buf,'Slot #')-1;
  for i:=0 to 9 do
  begin
    p^:=AnsiChar(ORD('0')+i);
    InsertString(wnd,i,buf);
  end;

  SendMessage(wnd,CB_SETCURSEL,0,0);
end;

procedure ClearFields(Dialog:HWND);
begin
  CheckDlgButton(Dialog,IDC_FLAG_TO  ,BST_UNCHECKED);
  CheckDlgButton(Dialog,IDC_FLAG_FROM,BST_UNCHECKED);
end;

function DlgProc(Dialog:HWnd;hMessage:UINT;wParam:WPARAM;lParam:LPARAM):lresult; stdcall;
begin
  result:=0;

  case hMessage of
    WM_INITDIALOG: begin
      TranslateDialogDefault(Dialog);

      FillStorageCombo(GetDlgItem(Dialog,IDC_STORAGELIST));
    end;

    WM_ACT_SETVALUE: begin
      ClearFields(Dialog);
      with tStorageAction(lParam) do
      begin
        if (flags and ACF_COPYFROM)=0 then
          CheckDlgButton(Dialog,IDC_FLAG_TO  ,BST_CHECKED)
        else
          CheckDlgButton(Dialog,IDC_FLAG_FROM,BST_CHECKED);

        CB_SelectData(GetDlgItem(Dialog,IDC_STORAGELIST),Number);
      end;
    end;

    WM_ACT_RESET: begin
      ClearFields(Dialog);
      CheckDlgButton(Dialog,IDC_FLAG_TO,BST_CHECKED);
      CB_SelectData(GetDlgItem(Dialog,IDC_STORAGELIST),0);
    end;

    WM_ACT_SAVE: begin
      with tStorageAction(lParam) do
      begin
        if IsDlgButtonChecked(Dialog,IDC_FLAG_FROM)<>BST_UNCHECKED then
          flags:=flags or ACF_COPYFROM;

        Number:=CB_GetData(GetDlgItem(Dialog,IDC_STORAGELIST));
      end;
    end;
{
    WM_COMMAND: begin
      case wParam shr 16 of
      end;
    end;
}
    WM_HELP: begin
      result:=1;
    end;

  end;
end;

//----- Export/interface functions -----

var
  vc:tActModule;

function CreateAction:tBaseAction;
begin
  result:=tStorageAction.Create(vc.Hash);
end;

function CreateDialog(parent:HWND):HWND;
begin
  result:=CreateDialogW(hInstance,'IDD_ACTSTORAGE',parent,@DlgProc);
end;

procedure Init;
begin
  vc.Next    :=ModuleLink;

  vc.Name    :='Storage';
  vc.Dialog  :=@CreateDialog;
  vc.Create  :=@CreateAction;
  vc.Icon    :='IDI_STORAGE';

  ModuleLink :=@vc;
end;

begin
  Init;
end.