Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FarUtils.h « Far « UI « 7zip « CPP - github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a4887c9a8246da47dd288f7fa0a62900187a42d5 (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
// FarUtils.h

#ifndef __FARUTILS_H
#define __FARUTILS_H

#include "FarPlugin.h"
#include "Windows/Registry.h"

namespace NFar {

namespace NFileOperationReturnCode
{
  enum EEnum
  {
    kInterruptedByUser = -1,
    kError = 0,
    kSuccess = 1
  };
}

namespace NEditorReturnCode
{
  enum EEnum
  {
    kOpenError = 0,
    kFileWasChanged = 1,
    kFileWasNotChanged = 2,
    kInterruptedByUser = 3
  };
}

struct CInitDialogItem
{
  DialogItemTypes Type;
  int X1,Y1,X2,Y2;
  bool Focus;
  bool Selected;
  unsigned int Flags; //FarDialogItemFlags Flags;
  bool DefaultButton;
  int DataMessageId;
  const char *DataString;
  const char *HistoryName;
  // void InitToFarDialogItem(struct FarDialogItem &anItemDest);
};

class CStartupInfo
{
  PluginStartupInfo m_Data;
  CSysString m_RegistryPath;

  CSysString GetFullKeyName(const CSysString &keyName) const;
  LONG CreateRegKey(HKEY parentKey,
    const CSysString &keyName, NWindows::NRegistry::CKey &destKey) const;
  LONG OpenRegKey(HKEY parentKey,
    const CSysString &keyName, NWindows::NRegistry::CKey &destKey) const;

public:
  void Init(const PluginStartupInfo &pluginStartupInfo,
      const CSysString &pluginNameForRegestry);
  const char *GetMsgString(int messageId);
  int ShowMessage(unsigned int flags, const char *helpTopic,
      const char **items, int numItems, int numButtons);
  int ShowMessage(const char *message);
  int ShowMessageLines(const char *message);
  int ShowMessage(int messageId);

  int ShowDialog(int X1, int Y1, int X2, int Y2,
      const char *helpTopic, struct FarDialogItem *items, int numItems);
  int ShowDialog(int sizeX, int sizeY,
      const char *helpTopic, struct FarDialogItem *items, int numItems);

  void InitDialogItems(const CInitDialogItem *srcItems,
      FarDialogItem *destItems, int numItems);
  
  HANDLE SaveScreen(int X1, int Y1, int X2, int Y2);
  HANDLE SaveScreen();
  void RestoreScreen(HANDLE handle);

  void SetRegKeyValue(HKEY parentKey, const CSysString &keyName,
      const LPCTSTR valueName, LPCTSTR value) const;
  void SetRegKeyValue(HKEY hRoot, const CSysString &keyName,
      const LPCTSTR valueName, UINT32 value) const;
  void SetRegKeyValue(HKEY hRoot, const CSysString &keyName,
      const LPCTSTR valueName, bool value) const;

  CSysString QueryRegKeyValue(HKEY parentKey, const CSysString &keyName,
      LPCTSTR valueName, const CSysString &valueDefault) const;

  UINT32 QueryRegKeyValue(HKEY parentKey, const CSysString &keyName,
      LPCTSTR valueName, UINT32 valueDefault) const;

  bool QueryRegKeyValue(HKEY parentKey, const CSysString &keyName,
      LPCTSTR valueName, bool valueDefault) const;

  bool Control(HANDLE plugin, int command, void *param);
  bool ControlRequestActivePanel(int command, void *param);
  bool ControlGetActivePanelInfo(PanelInfo &panelInfo);
  bool ControlSetSelection(const PanelInfo &panelInfo);
  bool ControlGetActivePanelCurrentItemInfo(PluginPanelItem &pluginPanelItem);
  bool ControlGetActivePanelSelectedOrCurrentItems(
      CObjectVector<PluginPanelItem> &pluginPanelItems);

  bool ControlClearPanelSelection();

  int Menu(
      int x,
      int y,
      int maxHeight,
      unsigned int flags,
      const char *title,
      const char *aBottom,
      const char *helpTopic,
      int *breakKeys,
      int *breakCode,
      FarMenuItem *items,
      int numItems);
  int Menu(
      unsigned int flags,
      const char *title,
      const char *helpTopic,
      FarMenuItem *items,
      int numItems);

  int Menu(
      unsigned int flags,
      const char *title,
      const char *helpTopic,
      const CSysStringVector &items,
      int selectedItem);

  int Editor(const char *fileName, const char *title,
      int X1, int Y1, int X2, int Y2, DWORD flags, int startLine, int startChar)
      { return m_Data.Editor((char *)fileName, (char *)title, X1, Y1, X2, Y2,
        flags, startLine, startChar); }
  int Editor(const char *fileName)
      { return Editor(fileName, NULL, 0, 0, -1, -1, 0, -1, -1); }

  int Viewer(const char *fileName, const char *title,
      int X1, int Y1, int X2, int Y2, DWORD flags)
      { return m_Data.Viewer((char *)fileName, (char *)title, X1, Y1, X2, Y2, flags); }
  int Viewer(const char *fileName)
      { return Viewer(fileName, NULL, 0, 0, -1, -1, VF_NONMODAL); }

};

class CScreenRestorer
{
  bool m_Saved;
  HANDLE m_HANDLE;
public:
  CScreenRestorer(): m_Saved(false){};
  ~CScreenRestorer();
  void Save();
  void Restore();
};


extern CStartupInfo g_StartupInfo;

void PrintErrorMessage(const char *message, int code);
void PrintErrorMessage(const char *message, const char *text);
void PrintErrorMessage(const char *message, const wchar_t *text);

#define  MY_TRY_BEGIN   try\
  {

#define  MY_TRY_END1(x)     }\
  catch(int n) { PrintErrorMessage(x, n);  return; }\
  catch(const CSysString &s) { PrintErrorMessage(x, s); return; }\
  catch(const char *s) { PrintErrorMessage(x, s); return; }\
  catch(...) { g_StartupInfo.ShowMessage(x);  return; }

#define  MY_TRY_END2(x, y)     }\
  catch(int n) { PrintErrorMessage(x, n); return y; }\
  catch(const AString &s) { PrintErrorMessage(x, s); return y; }\
  catch(const char *s) { PrintErrorMessage(x, s); return y; }\
  catch(const UString &s) { PrintErrorMessage(x, s); return y; }\
  catch(const wchar_t *s) { PrintErrorMessage(x, s); return y; }\
  catch(...) { g_StartupInfo.ShowMessage(x); return y; }

bool WasEscPressed();
void ShowErrorMessage(DWORD errorCode);
void ShowLastErrorMessage();

}

#endif