~ubuntu-branches/ubuntu/precise/p7zip/precise-updates

« back to all changes in this revision

Viewing changes to CPP/7zip/UI/FileManager/FM.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mohammed Adnène Trojette
  • Date: 2009-02-14 20:12:27 UTC
  • mfrom: (1.1.11 upstream) (2.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090214201227-go63qxm9ozfdma60
Tags: 4.65~dfsg.1-1
* New upstream release.
* Remove wx2.8 Build-Depends added by mistakes (7zG is not yet
  intended to be built).
* Use dh_clean without -k.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// FM.cpp
 
2
 
 
3
#include "StdAfx.h"
 
4
 
 
5
#include "resource.h"
 
6
#include "Panel.h"
 
7
 
 
8
extern "C" 
 
9
 
10
  #include "../../../../C/Alloc.h"
 
11
}
 
12
 
 
13
#include "Common/Defs.h"
 
14
#include "Common/StringConvert.h"
 
15
// #include "Common/CommandLineParser.h"
 
16
 
 
17
// FIXME #include "Windows/Control/Toolbar.h"
 
18
#include "Windows/Error.h"
 
19
#include "Windows/COM.h"
 
20
#include "Windows/DLL.h"
 
21
// FIXME #include "Windows/Security.h"
 
22
// FIXME #include "Windows/MemoryLock.h"
 
23
 
 
24
#include "ViewSettings.h"
 
25
#include "../GUI/ExtractRes.h"
 
26
 
 
27
#include "App.h"
 
28
#include "StringUtils.h"
 
29
 
 
30
#include "MyLoadMenu.h"
 
31
#include "LangUtils.h"
 
32
#include "FormatUtils.h"
 
33
#include "RegistryUtils.h"
 
34
 
 
35
using namespace NWindows;
 
36
using namespace NFile;
 
37
using namespace NFind;
 
38
// using namespace NCommandLineParser;
 
39
 
 
40
#define MAX_LOADSTRING 100
 
41
 
 
42
#define MENU_HEIGHT 26
 
43
 
 
44
#ifndef _UNICODE
 
45
bool g_IsNT = false;
 
46
#endif
 
47
HINSTANCE g_hInstance;
 
48
HWND g_HWND;
 
49
bool g_OpenArchive = false;
 
50
static UString g_MainPath;
 
51
 
 
52
const int kNumDefaultPanels = 1;
 
53
 
 
54
const int kSplitterWidth = 4;
 
55
int kSplitterRateMax = 1 << 16;
 
56
 
 
57
// bool OnMenuCommand(HWND hWnd, int id);
 
58
 
 
59
static void local_WM_CREATE(HWND hWnd);
 
60
 
 
61
#ifdef _WIN32
 
62
static UString GetProgramPath()
 
63
{
 
64
  UString s;
 
65
  NDLL::MyGetModuleFileName(g_hInstance, s);
 
66
  return s;
 
67
}
 
68
 
 
69
UString GetProgramFolderPrefix()
 
70
{
 
71
  UString path = GetProgramPath();
 
72
  int pos = path.ReverseFind(WCHAR_PATH_SEPARATOR);
 
73
  return path.Left(pos + 1);
 
74
}
 
75
 
 
76
 
 
77
class CSplitterPos
 
78
{
 
79
  int _ratio; // 10000 is max
 
80
  int _pos;
 
81
  int _fullWidth;
 
82
  void SetRatioFromPos(HWND hWnd)
 
83
    { _ratio = (_pos + kSplitterWidth / 2) * kSplitterRateMax / 
 
84
        MyMax(GetWidth(hWnd), 1); }
 
85
public:
 
86
  int GetPos() const
 
87
    { return _pos; }
 
88
  int GetWidth(HWND hWnd) const
 
89
  {
 
90
    RECT rect;
 
91
    ::GetClientRect(hWnd, &rect);
 
92
    return rect.right;
 
93
  }
 
94
  void SetRatio(HWND hWnd, int aRatio)
 
95
  { 
 
96
    _ratio = aRatio; 
 
97
    SetPosFromRatio(hWnd);
 
98
  }
 
99
  void SetPosPure(HWND hWnd, int pos)
 
100
  {
 
101
    int posMax = GetWidth(hWnd) - kSplitterWidth;
 
102
    if (pos > posMax)
 
103
      pos = posMax;
 
104
    if (pos < 0)
 
105
      pos = 0;
 
106
    _pos = pos;
 
107
  }
 
108
  void SetPos(HWND hWnd, int pos)
 
109
  {
 
110
    _fullWidth = GetWidth(hWnd);
 
111
    SetPosPure(hWnd, pos);
 
112
    SetRatioFromPos(hWnd);
 
113
  }
 
114
  void SetPosFromRatio(HWND hWnd)
 
115
  { 
 
116
    int fullWidth = GetWidth(hWnd);
 
117
    if (_fullWidth != fullWidth)
 
118
    {
 
119
      _fullWidth = fullWidth;
 
120
      SetPosPure(hWnd, GetWidth(hWnd) * _ratio / kSplitterRateMax - kSplitterWidth / 2); 
 
121
    }
 
122
  }
 
123
};
 
124
#endif
 
125
 
 
126
bool g_CanChangeSplitter = false;
 
127
UINT32 g_SplitterPos = 0;
 
128
// FIXME CSplitterPos g_Splitter;
 
129
bool g_PanelsInfoDefined = false;
 
130
 
 
131
int g_StartCaptureMousePos;
 
132
int g_StartCaptureSplitterPos;
 
133
 
 
134
CApp g_App;
 
135
 
 
136
void MoveSubWindows(HWND hWnd);
 
137
void OnSize(HWND hWnd);
 
138
 
 
139
// FIXME LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
 
140
 
 
141
const wchar_t *kWindowClass = L"FM";
 
142
 
 
143
#ifndef _UNICODE
 
144
static bool IsItWindowsNT()
 
145
{
 
146
  OSVERSIONINFO versionInfo;
 
147
  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
 
148
  if (!::GetVersionEx(&versionInfo)) 
 
149
    return false;
 
150
  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);
 
151
}
 
152
#endif
 
153
 
 
154
//  FUNCTION: InitInstance(HANDLE, int)
 
155
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
 
156
{
 
157
  CWindow wnd;
 
158
 
 
159
  g_hInstance = hInstance;
 
160
 
 
161
  ReloadLangSmart();
 
162
 
 
163
  // LoadString(hInstance, IDS_CLASS, windowClass, MAX_LOADSTRING);
 
164
 
 
165
  // LoadString(hInstance, IDS_APP_TITLE, title, MAX_LOADSTRING);
 
166
  UString title = LangString(IDS_APP_TITLE, 0x03000000);
 
167
 
 
168
  /*
 
169
  //If it is already running, then focus on the window
 
170
  hWnd = FindWindow(windowClass, title);
 
171
  if (hWnd) 
 
172
  {
 
173
    SetForegroundWindow ((HWND) (((DWORD)hWnd) | 0x01));    
 
174
    return 0;
 
175
  } 
 
176
  */
 
177
 
 
178
#ifdef _WIN32
 
179
  WNDCLASSW wc;
 
180
 
 
181
  // wc.style = CS_HREDRAW | CS_VREDRAW;
 
182
  wc.style = 0;
 
183
  wc.lpfnWndProc = (WNDPROC) WndProc;
 
184
  wc.cbClsExtra = 0;
 
185
  wc.cbWndExtra = 0;
 
186
  wc.hInstance = hInstance;
 
187
  wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_FAM));
 
188
 
 
189
  // wc.hCursor = LoadCursor (NULL, IDC_ARROW);
 
190
  wc.hCursor = ::LoadCursor(0, IDC_SIZEWE);
 
191
  // wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
 
192
  wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
 
193
 
 
194
  wc.lpszMenuName = MAKEINTRESOURCEW(IDM_MENU);
 
195
  wc.lpszClassName = kWindowClass;
 
196
 
 
197
  MyRegisterClass(&wc);
 
198
 
 
199
  // RECT rect;
 
200
  // GetClientRect(hWnd, &rect);
 
201
 
 
202
  DWORD style = WS_OVERLAPPEDWINDOW;
 
203
  // DWORD style = 0;
 
204
  
 
205
  RECT rect;
 
206
  bool maximized = false;
 
207
  int x , y, xSize, ySize;
 
208
  x = y = xSize = ySize = CW_USEDEFAULT;
 
209
  bool windowPosIsRead = ReadWindowSize(rect, maximized);
 
210
 
 
211
  if (windowPosIsRead)
 
212
  {
 
213
    // x = rect.left;
 
214
    // y = rect.top;
 
215
    xSize = rect.right - rect.left;
 
216
    ySize = rect.bottom - rect.top;
 
217
  }
 
218
#endif
 
219
 
 
220
  UINT32 numPanels, currentPanel;
 
221
  g_PanelsInfoDefined = ReadPanelsInfo(numPanels, currentPanel, g_SplitterPos);
 
222
  if (g_PanelsInfoDefined)
 
223
  {
 
224
    if (numPanels < 1 || numPanels > 2)
 
225
      numPanels = kNumDefaultPanels;
 
226
    if (currentPanel >= 2)
 
227
      currentPanel = 0;
 
228
  }
 
229
  else
 
230
  {
 
231
    numPanels = kNumDefaultPanels;
 
232
    currentPanel = 0;
 
233
  }
 
234
  g_App.NumPanels = numPanels;
 
235
  g_App.LastFocusedPanel = currentPanel;
 
236
 
 
237
#ifdef _WIN32 // FIXME
 
238
  if (!wnd.Create(kWindowClass, title, style,
 
239
    x, y, xSize, ySize, NULL, NULL, hInstance, NULL))
 
240
    return FALSE;
 
241
  g_HWND = (HWND)wnd;
 
242
#else
 
243
  {
 
244
    extern HWND myCreateAndShowMainWindow(LPCTSTR title,void (*fct)(HWND));
 
245
     g_HWND = myCreateAndShowMainWindow(title,local_WM_CREATE);
 
246
  }
 
247
#endif
 
248
 
 
249
#ifdef _WIN32
 
250
  WINDOWPLACEMENT placement;
 
251
  placement.length = sizeof(placement);
 
252
  if (wnd.GetPlacement(&placement))
 
253
  {
 
254
    if (nCmdShow == SW_SHOWNORMAL || nCmdShow == SW_SHOW || 
 
255
        nCmdShow == SW_SHOWDEFAULT)
 
256
    {
 
257
      if (maximized)
 
258
        placement.showCmd = SW_SHOWMAXIMIZED;
 
259
      else
 
260
        placement.showCmd = SW_SHOWNORMAL;
 
261
    }
 
262
    else
 
263
      placement.showCmd = nCmdShow;
 
264
    if (windowPosIsRead)
 
265
      placement.rcNormalPosition = rect;
 
266
    wnd.SetPlacement(&placement);
 
267
    // window.Show(nCmdShow);
 
268
  }
 
269
  else
 
270
    wnd.Show(nCmdShow);
 
271
#endif
 
272
  return TRUE;
 
273
}
 
274
 
 
275
/*
 
276
static void GetCommands(const UString &aCommandLine, UString &aCommands)
 
277
{
 
278
  UString aProgramName;
 
279
  aCommands.Empty();
 
280
  bool aQuoteMode = false;
 
281
  for (int i = 0; i < aCommandLine.Length(); i++)
 
282
  {
 
283
    wchar_t aChar = aCommandLine[i];
 
284
    if (aChar == L'\"')
 
285
      aQuoteMode = !aQuoteMode;
 
286
    else if (aChar == L' ' && !aQuoteMode)
 
287
    {
 
288
      if (!aQuoteMode)
 
289
      {
 
290
        i++;
 
291
        break;
 
292
      }
 
293
    }
 
294
    else 
 
295
      aProgramName += aChar;
 
296
  }
 
297
  aCommands = aCommandLine.Mid(i);
 
298
}
 
299
*/
 
300
 
 
301
#ifdef _WIN32
 
302
DWORD GetDllVersion(LPCTSTR lpszDllName)
 
303
{
 
304
  HINSTANCE hinstDll;
 
305
  DWORD dwVersion = 0;
 
306
  hinstDll = LoadLibrary(lpszDllName);
 
307
  if(hinstDll)
 
308
  {
 
309
    DLLGETVERSIONPROC pDllGetVersion;
 
310
    pDllGetVersion = (DLLGETVERSIONPROC) GetProcAddress(hinstDll, "DllGetVersion");
 
311
    
 
312
    /*Because some DLLs might not implement this function, you
 
313
    must test for it explicitly. Depending on the particular 
 
314
    DLL, the lack of a DllGetVersion function can be a useful
 
315
    indicator of the version.
 
316
    */
 
317
    if(pDllGetVersion)
 
318
    {
 
319
      DLLVERSIONINFO dvi;
 
320
      HRESULT hr;
 
321
      
 
322
      ZeroMemory(&dvi, sizeof(dvi));
 
323
      dvi.cbSize = sizeof(dvi);
 
324
      
 
325
      hr = (*pDllGetVersion)(&dvi);
 
326
      
 
327
      if(SUCCEEDED(hr))
 
328
      {
 
329
        dwVersion = MAKELONG(dvi.dwMinorVersion, dvi.dwMajorVersion);
 
330
      }
 
331
    }
 
332
    FreeLibrary(hinstDll);
 
333
  }
 
334
  return dwVersion;
 
335
}
 
336
 
 
337
DWORD g_ComCtl32Version;
 
338
#endif
 
339
 
 
340
/*
 
341
#ifndef _WIN64
 
342
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
 
343
 
 
344
static bool IsWow64()
 
345
{
 
346
  LPFN_ISWOW64PROCESS  fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(
 
347
      GetModuleHandle("kernel32"), "IsWow64Process");
 
348
  if (fnIsWow64Process == NULL)
 
349
    return false;
 
350
  BOOL isWow;
 
351
  if (!fnIsWow64Process(GetCurrentProcess(),&isWow))
 
352
    return false;
 
353
  return isWow != FALSE;
 
354
}
 
355
#endif
 
356
*/
 
357
 
 
358
#ifdef _WIN32
 
359
bool IsLargePageSupported()
 
360
{
 
361
  #ifdef _WIN64
 
362
  return true;
 
363
  #else
 
364
  OSVERSIONINFO versionInfo;
 
365
  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
 
366
  if (!::GetVersionEx(&versionInfo)) 
 
367
    return false;
 
368
  if (versionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || versionInfo.dwMajorVersion < 5)
 
369
    return false;
 
370
  if (versionInfo.dwMajorVersion > 5)
 
371
    return true;
 
372
  if (versionInfo.dwMinorVersion < 1)
 
373
    return false;
 
374
  if (versionInfo.dwMinorVersion > 1)
 
375
    return true;
 
376
  // return IsWow64();
 
377
  return false;
 
378
  #endif
 
379
}
 
380
 
 
381
static void SetMemoryLock()
 
382
{
 
383
  if (!IsLargePageSupported())
 
384
    return;
 
385
  // if (ReadLockMemoryAdd())
 
386
    NSecurity::AddLockMemoryPrivilege();
 
387
 
 
388
  if (ReadLockMemoryEnable())
 
389
    NSecurity::EnableLockMemoryPrivilege();
 
390
}
 
391
#endif
 
392
 
 
393
/*
 
394
static const int kNumSwitches = 1;
 
395
 
 
396
namespace NKey {
 
397
enum Enum
 
398
{
 
399
  kOpenArachive = 0,
 
400
};
 
401
 
 
402
}
 
403
 
 
404
static const CSwitchForm kSwitchForms[kNumSwitches] = 
 
405
  {
 
406
    { L"SOA",  NSwitchType::kSimple, false },
 
407
  };
 
408
*/
 
409
 
 
410
// int APIENTRY WinMain2(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */, LPSTR /* lpCmdLine */, int /* nCmdShow */);
 
411
 
 
412
#ifdef _WIN32
 
413
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */, LPSTR /* lpCmdLine */, int nCmdShow)
 
414
{
 
415
  #ifndef _UNICODE
 
416
  g_IsNT = IsItWindowsNT();
 
417
  #endif
 
418
 
 
419
  #ifdef _WIN32
 
420
  SetLargePageSize();
 
421
  #endif
 
422
 
 
423
  InitCommonControls();
 
424
 
 
425
  g_ComCtl32Version = ::GetDllVersion(TEXT("comctl32.dll"));
 
426
 
 
427
  // OleInitialize is required for drag and drop.
 
428
  OleInitialize(NULL); 
 
429
  // Maybe needs CoInitializeEx also ?
 
430
  // NCOM::CComInitializer comInitializer;
 
431
 
 
432
  UString programString, commandsString;
 
433
  // MessageBoxW(0, GetCommandLineW(), L"", 0);
 
434
  SplitStringToTwoStrings(GetCommandLineW(), programString, commandsString);
 
435
 
 
436
  commandsString.Trim();
 
437
  UString paramString, tailString;
 
438
  SplitStringToTwoStrings(commandsString, paramString, tailString);
 
439
  paramString.Trim();
 
440
 
 
441
  if (!paramString.IsEmpty())
 
442
  {
 
443
    g_MainPath = paramString;
 
444
    // return WinMain2(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
 
445
 
 
446
    // MessageBoxW(0, paramString, L"", 0);
 
447
  }
 
448
  /*
 
449
  UStringVector commandStrings;
 
450
  NCommandLineParser::SplitCommandLine(GetCommandLineW(), commandStrings);
 
451
  NCommandLineParser::CParser parser(kNumSwitches);
 
452
  try 
 
453
  { 
 
454
    parser.ParseStrings(kSwitchForms, commandStrings); 
 
455
    const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;
 
456
    if(nonSwitchStrings.Size() > 1)  
 
457
    {
 
458
      g_MainPath = nonSwitchStrings[1];
 
459
      // g_OpenArchive = parser[NKey::kOpenArachive].ThereIs;
 
460
      CFileInfoW fileInfo;
 
461
      if (FindFile(g_MainPath, fileInfo))
 
462
      {
 
463
        if (!fileInfo.IsDir())
 
464
          g_OpenArchive = true;
 
465
      }
 
466
    }
 
467
  }
 
468
  catch(...) { }
 
469
  */
 
470
 
 
471
 
 
472
  SetMemoryLock();
 
473
 
 
474
  MSG msg;
 
475
  if (!InitInstance (hInstance, nCmdShow)) 
 
476
    return FALSE;
 
477
 
 
478
  MyLoadMenu(g_HWND);
 
479
 
 
480
  #ifndef _UNICODE
 
481
  if (g_IsNT)
 
482
  {
 
483
    HACCEL hAccels = LoadAcceleratorsW(hInstance, MAKEINTRESOURCEW(IDR_ACCELERATOR1));
 
484
    while (GetMessageW(&msg, NULL, 0, 0)) 
 
485
    {
 
486
      if (TranslateAcceleratorW(g_HWND, hAccels, &msg) == 0) 
 
487
      {
 
488
        TranslateMessage(&msg);
 
489
        DispatchMessageW(&msg);
 
490
      }
 
491
    }
 
492
  }
 
493
  else
 
494
  #endif
 
495
  {
 
496
    HACCEL hAccels = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR1));
 
497
    while (GetMessage(&msg, NULL, 0, 0)) 
 
498
    {
 
499
      if (TranslateAccelerator(g_HWND, hAccels, &msg) == 0) 
 
500
      {
 
501
        // if (g_Hwnd != NULL || !IsDialogMessage(g_Hwnd, &msg))
 
502
        // if (!IsDialogMessage(g_Hwnd, &msg))
 
503
        TranslateMessage(&msg);
 
504
        DispatchMessage(&msg);
 
505
      }
 
506
    }
 
507
  }
 
508
 
 
509
  g_HWND = 0;
 
510
  OleUninitialize();
 
511
  return (int)msg.wParam;
 
512
}
 
513
 
 
514
static void SaveWindowInfo(HWND aWnd)
 
515
{
 
516
  /*
 
517
  RECT rect;
 
518
  if (!::GetWindowRect(aWnd, &rect))
 
519
    return;
 
520
  */
 
521
  WINDOWPLACEMENT placement;
 
522
  placement.length = sizeof(placement);
 
523
  if (!::GetWindowPlacement(aWnd, &placement))
 
524
    return;
 
525
  SaveWindowSize(placement.rcNormalPosition, 
 
526
      BOOLToBool(::IsZoomed(aWnd)));
 
527
  SavePanelsInfo(g_App.NumPanels, g_App.LastFocusedPanel, 
 
528
      g_Splitter.GetPos());
 
529
}
 
530
#else
 
531
int Main1(int argc,TCHAR **argv)
 
532
{
 
533
  if (argc >= 2)
 
534
  {
 
535
    g_MainPath = argv[1];
 
536
  }
 
537
 
 
538
  if (!InitInstance (0, 0)) 
 
539
    return FALSE;
 
540
 
 
541
  MyLoadMenu(g_HWND);
 
542
 
 
543
  // FIXME : install Accelerators ?
 
544
 
 
545
  return 0;
 
546
}
 
547
 
 
548
#endif
 
549
 
 
550
void ExecuteCommand(UINT commandID)
 
551
{
 
552
  printf("FM - ExecuteCommand(%d)\n",commandID);
 
553
  switch (commandID)
 
554
  {
 
555
    case kAddCommand:
 
556
      g_App.AddToArchive();
 
557
      break;
 
558
    case kExtractCommand:
 
559
      g_App.ExtractArchives();
 
560
      break;
 
561
    case kTestCommand:
 
562
      g_App.TestArchives();
 
563
      break;
 
564
  }
 
565
}
 
566
 
 
567
#ifdef _WIN32
 
568
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 
569
{
 
570
  int wmId, wmEvent;
 
571
  switch (message) 
 
572
  {
 
573
    case WM_COMMAND:
 
574
      wmId    = LOWORD(wParam); 
 
575
      wmEvent = HIWORD(wParam); 
 
576
      if ((HWND) lParam != NULL && wmEvent != 0)
 
577
        break;
 
578
      if (wmId >= kToolbarStartID)
 
579
      {
 
580
        ExecuteCommand(wmId);
 
581
        return 0;
 
582
      }
 
583
      if (OnMenuCommand(hWnd, wmId))
 
584
        return 0;
 
585
      break;
 
586
    case WM_INITMENUPOPUP:
 
587
      OnMenuActivating(hWnd, HMENU(wParam), LOWORD(lParam));
 
588
      break;
 
589
 
 
590
    /*
 
591
    It doesn't help
 
592
    case WM_EXITMENULOOP:
 
593
      {
 
594
        OnMenuUnActivating(hWnd);
 
595
        break;
 
596
      }
 
597
    case WM_UNINITMENUPOPUP:
 
598
      OnMenuUnActivating(hWnd, HMENU(wParam), lParam);
 
599
      break;
 
600
    */
 
601
 
 
602
    case WM_CREATE:
 
603
    {
 
604
 
 
605
      /*
 
606
      INITCOMMONCONTROLSEX icex;
 
607
      icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
 
608
      icex.dwICC  = ICC_BAR_CLASSES;
 
609
      InitCommonControlsEx(&icex);
 
610
      
 
611
      // Toolbar buttons used to create the first 4 buttons.
 
612
      TBBUTTON tbb [ ] = 
 
613
      {
 
614
        // {0, 0, TBSTATE_ENABLED, BTNS_SEP, 0L, 0},
 
615
        // {VIEW_PARENTFOLDER, kParentFolderID, TBSTATE_ENABLED, BTNS_BUTTON, 0L, 0},
 
616
          // {0, 0, TBSTATE_ENABLED, BTNS_SEP, 0L, 0},
 
617
        {VIEW_NEWFOLDER, ID_FILE_CREATEFOLDER, TBSTATE_ENABLED, BTNS_BUTTON, 0L, 0},
 
618
      };
 
619
      
 
620
      int baseID = 100;
 
621
      NWindows::NControl::CToolBar aToolBar;
 
622
      aToolBar.Attach(::CreateToolbarEx (hWnd, 
 
623
        WS_CHILD | WS_BORDER | WS_VISIBLE | TBSTYLE_TOOLTIPS, //  | TBSTYLE_FLAT 
 
624
        baseID + 2, 11, 
 
625
        (HINSTANCE)HINST_COMMCTRL, IDB_VIEW_SMALL_COLOR, 
 
626
        (LPCTBBUTTON)&tbb, sizeof(tbb) / sizeof(tbb[0]), 
 
627
        0, 0, 100, 30, sizeof (TBBUTTON)));
 
628
      */
 
629
      // HCURSOR cursor = ::LoadCursor(0, IDC_SIZEWE);
 
630
      // ::SetCursor(cursor);
 
631
 
 
632
      if (g_PanelsInfoDefined)
 
633
        g_Splitter.SetPos(hWnd, g_SplitterPos);
 
634
      else
 
635
      {
 
636
        g_Splitter.SetRatio(hWnd, kSplitterRateMax / 2);
 
637
        g_SplitterPos = g_Splitter.GetPos();
 
638
      }
 
639
 
 
640
      RECT rect;
 
641
      ::GetClientRect(hWnd, &rect);
 
642
      int xSize = rect.right;
 
643
      int xSizes[2];
 
644
      xSizes[0] = g_Splitter.GetPos();
 
645
      xSizes[1] = xSize - kSplitterWidth - xSizes[0];
 
646
      if (xSizes[1] < 0)
 
647
        xSizes[1] = 0;
 
648
 
 
649
      g_App.CreateDragTarget();
 
650
      bool archiveIsOpened;
 
651
      bool encrypted;
 
652
      bool needOpenFile = false;
 
653
      if (!g_MainPath.IsEmpty() /* && g_OpenArchive */)
 
654
      {
 
655
        NFile::NFind::CFileInfoW fileInfo;
 
656
        if (NFile::NFind::FindFile(g_MainPath, fileInfo))
 
657
          if (!fileInfo.IsDir())
 
658
            needOpenFile = true;
 
659
      }
 
660
      g_App.Create(hWnd, g_MainPath, xSizes, archiveIsOpened, encrypted);
 
661
 
 
662
      if (needOpenFile && !archiveIsOpened)
 
663
      {
 
664
        UString message;
 
665
        if (encrypted)
 
666
          message = MyFormatNew(IDS_CANT_OPEN_ENCRYPTED_ARCHIVE, 0x0200060A, g_MainPath);
 
667
        else
 
668
          message = MyFormatNew(IDS_CANT_OPEN_ARCHIVE, 0x02000609, g_MainPath);
 
669
        MessageBoxW(0, message, L"7-zip", MB_ICONERROR);
 
670
        return -1;
 
671
      }
 
672
      // g_SplitterPos = 0;
 
673
 
 
674
      // ::DragAcceptFiles(hWnd, TRUE);
 
675
      RegisterDragDrop(hWnd, g_App._dropTarget);
 
676
 
 
677
      break;
 
678
    }
 
679
    case WM_DESTROY:
 
680
    {
 
681
      // ::DragAcceptFiles(hWnd, FALSE);  
 
682
      RevokeDragDrop(hWnd);
 
683
      g_App._dropTarget.Release();
 
684
 
 
685
      g_App.Save();
 
686
      g_App.Release();
 
687
      SaveWindowInfo(hWnd);
 
688
      PostQuitMessage(0);
 
689
      break;
 
690
    }
 
691
    /*
 
692
    case WM_MOVE:
 
693
    {
 
694
      break;
 
695
    }
 
696
    */
 
697
    case WM_LBUTTONDOWN:
 
698
      g_StartCaptureMousePos = LOWORD(lParam);
 
699
      g_StartCaptureSplitterPos = g_Splitter.GetPos();
 
700
      ::SetCapture(hWnd);
 
701
      break;
 
702
    case WM_LBUTTONUP:
 
703
    {
 
704
      ::ReleaseCapture();
 
705
      break;
 
706
    }
 
707
    case WM_MOUSEMOVE: 
 
708
    {
 
709
      if ((wParam & MK_LBUTTON) != 0 && ::GetCapture() == hWnd)
 
710
      {
 
711
        g_Splitter.SetPos(hWnd, g_StartCaptureSplitterPos + 
 
712
            (short)LOWORD(lParam) - g_StartCaptureMousePos);
 
713
        MoveSubWindows(hWnd);
 
714
      }
 
715
      break;
 
716
    }
 
717
 
 
718
    case WM_SIZE:
 
719
    {
 
720
      if (g_CanChangeSplitter)
 
721
        g_Splitter.SetPosFromRatio(hWnd);
 
722
      else
 
723
      {
 
724
        g_Splitter.SetPos(hWnd, g_SplitterPos );
 
725
        g_CanChangeSplitter = true;
 
726
      }
 
727
 
 
728
      OnSize(hWnd);
 
729
      /*
 
730
      int xSize = LOWORD(lParam);
 
731
      int ySize = HIWORD(lParam);
 
732
      // int xSplitter = 2;
 
733
      int xWidth = g_SplitPos;
 
734
      // int xSplitPos = xWidth;
 
735
      g_Panel[0]._listView.MoveWindow(0, 0, xWidth, ySize);
 
736
      g_Panel[1]._listView.MoveWindow(xSize - xWidth, 0, xWidth, ySize);
 
737
      */
 
738
      return 0;
 
739
      break;
 
740
    }
 
741
    case WM_SETFOCUS:
 
742
      // g_App.SetFocus(g_App.LastFocusedPanel);
 
743
      g_App.SetFocusToLastItem();
 
744
      break;
 
745
    /*
 
746
    case WM_ACTIVATE:
 
747
    {
 
748
      int fActive = LOWORD(wParam); 
 
749
      switch (fActive)
 
750
      {
 
751
        case WA_INACTIVE:
 
752
        {
 
753
          // g_FocusIndex = g_App.LastFocusedPanel;
 
754
          // g_App.LastFocusedPanel = g_App.GetFocusedPanelIndex();
 
755
          // return 0;
 
756
        }
 
757
      }
 
758
      break;
 
759
    }
 
760
    */
 
761
    /*
 
762
    case kLangWasChangedMessage:
 
763
      MyLoadMenu(g_HWND);
 
764
      return 0;
 
765
    */
 
766
      
 
767
    /*
 
768
    case WM_SETTINGCHANGE:
 
769
      break;
 
770
    */
 
771
    case WM_NOTIFY:
 
772
    {
 
773
      g_App.OnNotify((int)wParam, (LPNMHDR)lParam);
 
774
      break;
 
775
    }
 
776
    /*
 
777
    case WM_DROPFILES:
 
778
    {
 
779
      g_App.GetFocusedPanel().CompressDropFiles((HDROP)wParam);
 
780
      return 0 ;
 
781
    }
 
782
    */
 
783
   }
 
784
   #ifndef _UNICODE
 
785
   if (g_IsNT)
 
786
     return DefWindowProcW(hWnd, message, wParam, lParam);
 
787
   else
 
788
   #endif
 
789
     return DefWindowProc(hWnd, message, wParam, lParam);
 
790
 
 
791
}
 
792
 
 
793
void OnSize(HWND hWnd)
 
794
{
 
795
  /*
 
796
  if (g_App._rebar)
 
797
  {
 
798
    RECT rect;
 
799
    ::GetClientRect(hWnd, &rect);
 
800
    int xSize = rect.right;
 
801
    int ySize = rect.bottom;
 
802
    // rect.bottom = 0;
 
803
    // g_App._rebar.SizeToRect(&rect);
 
804
    // g_App._rebar.Move(0, 0, xSize, ySize);
 
805
  }
 
806
  */
 
807
  MoveSubWindows(hWnd);
 
808
}
 
809
 
 
810
int Window_GetRealHeight(NWindows::CWindow &w)
 
811
{
 
812
  RECT rect;
 
813
  WINDOWPLACEMENT placement;
 
814
  w.GetWindowRect(&rect);
 
815
  int res = rect.bottom - rect.top;
 
816
  if (w.GetPlacement(&placement))
 
817
    res += placement.rcNormalPosition.top;
 
818
  return res;
 
819
}
 
820
#else // _WIN32
 
821
static void local_WM_CREATE(HWND hWnd)
 
822
    {
 
823
            printf("**local_WM_CREATE**\n");
 
824
#if 0
 
825
      if (g_PanelsInfoDefined)
 
826
        g_Splitter.SetPos(hWnd, g_SplitterPos);
 
827
      else
 
828
      {
 
829
        g_Splitter.SetRatio(hWnd, kSplitterRateMax / 2);
 
830
        g_SplitterPos = g_Splitter.GetPos();
 
831
      }
 
832
 
 
833
      RECT rect;
 
834
      ::GetClientRect(hWnd, &rect);
 
835
      int xSize = rect.right;
 
836
      int xSizes[2];
 
837
      xSizes[0] = g_Splitter.GetPos();
 
838
      xSizes[1] = xSize - kSplitterWidth - xSizes[0];
 
839
      if (xSizes[1] < 0)
 
840
        xSizes[1] = 0;
 
841
 
 
842
      g_App.CreateDragTarget();
 
843
#else
 
844
      int xSizes[2] = { 0,0 };
 
845
#endif
 
846
      bool archiveIsOpened;
 
847
      bool encrypted;
 
848
      bool needOpenFile = false;
 
849
      if (!g_MainPath.IsEmpty() /* && g_OpenArchive */)
 
850
      {
 
851
        NFile::NFind::CFileInfoW fileInfo;
 
852
        if (NFile::NFind::FindFile(g_MainPath, fileInfo))
 
853
          if (!fileInfo.IsDir())
 
854
            needOpenFile = true;
 
855
      }
 
856
      g_App.Create(hWnd, g_MainPath, xSizes, archiveIsOpened, encrypted);
 
857
 
 
858
      if (needOpenFile && !archiveIsOpened)
 
859
      {
 
860
        UString message;
 
861
        if (encrypted)
 
862
          message = MyFormatNew(IDS_CANT_OPEN_ENCRYPTED_ARCHIVE, 0x0200060A, g_MainPath);
 
863
        else
 
864
          message = MyFormatNew(IDS_CANT_OPEN_ARCHIVE, 0x02000609, g_MainPath);
 
865
        MessageBoxW(0, message, L"7-zip", MB_ICONERROR);
 
866
        return ;// -1;
 
867
      }
 
868
      // g_SplitterPos = 0;
 
869
 
 
870
      // FIXME RegisterDragDrop(hWnd, g_App._dropTarget);
 
871
 
 
872
}
 
873
 
 
874
void main_WM_DESTROY()
 
875
{
 
876
      // RevokeDragDrop(hWnd);
 
877
      // g_App._dropTarget.Release();
 
878
printf("main_WM_DESTROY\n");
 
879
      g_App.Save();
 
880
      g_App.Release();
 
881
      // SaveWindowInfo(hWnd);
 
882
      // PostQuitMessage(0);
 
883
}
 
884
#endif
 
885
 
 
886
void MoveSubWindows(HWND hWnd)
 
887
{
 
888
#ifdef _WIN32
 
889
  RECT rect;
 
890
  ::GetClientRect(hWnd, &rect);
 
891
  int xSize = rect.right;
 
892
  int headerSize = 0;
 
893
  if (g_App._rebar)
 
894
    headerSize = Window_GetRealHeight(g_App._rebar);
 
895
  int ySize = MyMax((int)(rect.bottom - headerSize), 0);
 
896
 
 
897
  if (g_App.NumPanels > 1)
 
898
  {
 
899
    g_App.Panels[0].Move(0, headerSize, g_Splitter.GetPos(), ySize);
 
900
    int xWidth1 = g_Splitter.GetPos() + kSplitterWidth;
 
901
    g_App.Panels[1].Move(xWidth1, headerSize, xSize - xWidth1, ySize);
 
902
  }
 
903
  else
 
904
  {
 
905
    /*
 
906
    int otherPanel = 1 - g_App.LastFocusedPanel;
 
907
    if (g_App.PanelsCreated[otherPanel])
 
908
      g_App.Panels[otherPanel].Move(0, headerSize, 0, ySize);
 
909
    */
 
910
    g_App.Panels[g_App.LastFocusedPanel].Move(0, headerSize, xSize, ySize);
 
911
  }
 
912
#endif
 
913
}
 
914