forked from crom83/cromfarplugs
/
FARstuffs.cpp
182 lines (159 loc) · 5.88 KB
/
FARstuffs.cpp
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
#include "stdafx.h"
#include "FARstuffs.h"
const farStr* LOC(int MsgId)
{
return fInfo.GetMsg(&MainGuid, MsgId);
}
int ShowMessage(const farStr* msg, int buttons, const farStr* help, bool Warning /*= false*/)
{
return static_cast<int>(fInfo.Message(&MainGuid, &MsgGuid, (Warning ? FMSG_WARNING : 0) | FMSG_ALLINONE, help, reinterpret_cast<const farStr * const *>(msg), 0, buttons));
}
void ShowMessageWait(const farStr* const* msg, int msgsize)
{
fInfo.Message(&MainGuid, &MsgWaitGuid, FMSG_LEFTALIGN, nullptr, msg, msgsize, 0);
}
int ShowDialog(int width, int height, const farStr* help, FarDialogItem* items, int count, HANDLE& hDlg, FARWINDOWPROC dlgProc)
{
hDlg = static_cast<int*>(fInfo.DialogInit(&MainGuid, &DialogGuid, -1, -1, width, height, help, items, count, 0, 0, dlgProc, nullptr));
return static_cast<int>(fInfo.DialogRun(hDlg));
}
int ShowMenu(const farStr* title, const farStr* bottom, const farStr* help, const FarKey *breakKeys, intptr_t * breakCode, const FarMenuItem* items, int count)
{
return static_cast<int>(fInfo.Menu(&MainGuid, &MenuGuid, -1, -1, 0, FMENU_WRAPMODE | FMENU_AUTOHIGHLIGHT | FMENU_CHANGECONSOLETITLE, title, bottom, help, breakKeys, breakCode, items, count));
}
int GetChecked(const HANDLE& hDlg, int item)
{
return static_cast<int>(fInfo.SendDlgMessage(hDlg, DM_GETCHECK, item, nullptr));
}
CString GetPanelPath(bool another /*= false*/)
{
CString ret;
int Size = static_cast<int>(fInfo.PanelControl(another ? PANEL_PASSIVE : PANEL_ACTIVE, FCTL_GETPANELDIRECTORY, 0, nullptr));
FarPanelDirectory* dirInfo = static_cast<FarPanelDirectory*>(my_malloc(Size));
dirInfo->StructSize = sizeof(FarPanelDirectory);
fInfo.PanelControl(another ? PANEL_PASSIVE : PANEL_ACTIVE, FCTL_GETPANELDIRECTORY, Size, dirInfo);
ret = dirInfo->Name;
my_free(dirInfo);
return ret;
}
FarDialogItem* GetFarDialogItem(const HANDLE& hDlg, DWORD item)
{
if (hDlg)
{
struct FarGetDialogItem DialogItem = {sizeof(FarGetDialogItem)};
DialogItem.Item = static_cast<FarDialogItem *>(my_malloc(DialogItem.Size = fInfo.SendDlgMessage(hDlg, DM_GETDLGITEM, item, nullptr)));
if (DialogItem.Item)
{
fInfo.SendDlgMessage(hDlg, DM_GETDLGITEM, item, &DialogItem);
return DialogItem.Item;
}
}
return nullptr;
}
int GetItemSelected(const HANDLE& hDlg, DWORD item)
{
auto DialogItem = GetFarDialogItem(hDlg, item);
if (!DialogItem) return FALSE;
auto s = static_cast<int>(DialogItem->Selected);
my_free(DialogItem);
return s;
}
bool SetItemSelected(const HANDLE& hDlg, DWORD item, int selected)
{
if (!hDlg) return false;
auto DialogItem = GetFarDialogItem(hDlg, item);
if (!DialogItem) return false;
DialogItem->Selected = selected;
fInfo.SendDlgMessage(hDlg, DM_SETDLGITEM, item, static_cast<void *>(DialogItem));
my_free(DialogItem);
return true;
}
CString GetItemData(const HANDLE& hDlg, DWORD item)
{
auto DialogItem = GetFarDialogItem(hDlg, item);
if (!DialogItem) return _F("");
CString str = DialogItem->Data;
my_free(DialogItem);
return str;
}
bool SetItemData(const HANDLE& hDlg, DWORD item, const CString& data)
{
if (!hDlg) return false;
auto DialogItem = GetFarDialogItem(hDlg, item);
if (!DialogItem) return false;
DialogItem->Data = _C(data);
fInfo.SendDlgMessage(hDlg, DM_SETDLGITEM, item, static_cast<void *>(DialogItem));
my_free(DialogItem);
return true;
}
void InitDialogItems(struct InitDialogItem* Init, struct FarDialogItem* Item, int ItemsNumber)
{
auto PItem = Item;
auto PInit = Init;
for (auto i = 0; i < ItemsNumber; i++, PItem++, PInit++)
{
memset(static_cast<void *>(PItem), 0, sizeof(*PItem));
PItem->Type = static_cast<FARDIALOGITEMTYPES>(PInit->Type);
PItem->X1 = PInit->X1;
PItem->Y1 = PInit->Y1;
PItem->X2 = PInit->X2;
PItem->Y2 = PInit->Y2;
PItem->Flags = PInit->Flags;
if (PInit->DefaultButton)
PItem->Flags |= DIF_DEFAULTBUTTON;
PItem->MaxLength = 0;
if (PItem->Type == DI_FIXEDIT)
PItem->Mask = reinterpret_cast<const farStr *>(PInit->Selected);
else
PItem->History = reinterpret_cast<const farStr *>(PInit->Selected);
PItem->Data = PInit->Data;
}
}
CString GetFileName(bool another, bool selected, int i)
{
int size = static_cast<int>(fInfo.PanelControl(another ? PANEL_PASSIVE : PANEL_ACTIVE, selected ? FCTL_GETSELECTEDPANELITEM : FCTL_GETPANELITEM, i, nullptr));
if (size > 0)
{
struct FarGetPluginPanelItem item;
item.StructSize = sizeof(item);
item.Size = size;
item.Item = static_cast<PluginPanelItem *>(my_malloc(size));
fInfo.PanelControl(another ? PANEL_PASSIVE : PANEL_ACTIVE, selected ? FCTL_GETSELECTEDPANELITEM : FCTL_GETPANELITEM, i, &item);
CString ret = item.Item->FileName;
my_free(item.Item);
return ret;
}
return _T("");
}
DWORD GetFileAttributes(bool another, bool selected, int i)
{
intptr_t size = fInfo.PanelControl(another ? PANEL_PASSIVE : PANEL_ACTIVE, selected ? FCTL_GETSELECTEDPANELITEM : FCTL_GETPANELITEM, i, nullptr);
if (size > 0)
{
struct FarGetPluginPanelItem item;
item.StructSize = sizeof(item);
item.Size = size;
item.Item = static_cast<PluginPanelItem *>(my_malloc(size));
fInfo.PanelControl(another ? PANEL_PASSIVE : PANEL_ACTIVE, selected ? FCTL_GETSELECTEDPANELITEM : FCTL_GETPANELITEM, i, nullptr);
auto ret = static_cast<DWORD>(item.Item->FileAttributes);
my_free(item.Item);
return ret;
}
return 0;
}
CString GetCurrentFileName(bool another)
{
intptr_t size = fInfo.PanelControl(another ? PANEL_PASSIVE : PANEL_ACTIVE, FCTL_GETCURRENTPANELITEM, 0, nullptr);
if (size > 0)
{
struct FarGetPluginPanelItem item;
item.StructSize = sizeof(item);
item.Size = size;
item.Item = static_cast<PluginPanelItem *>(my_malloc(size));
fInfo.PanelControl(another ? PANEL_PASSIVE : PANEL_ACTIVE, FCTL_GETCURRENTPANELITEM, 0, &item);
CString ret = item.Item->FileName;
my_free(item.Item);
return ret;
}
return _T("");
}