Imported Upstream version 9.20
[platform/upstream/7zip.git] / CPP / 7zip / UI / FileManager / SplitDialog.cpp
1 // SplitDialog.cpp\r
2 \r
3 #include "StdAfx.h"\r
4 \r
5 #include "Windows/FileName.h"\r
6 \r
7 #ifdef LANG\r
8 #include "LangUtils.h"\r
9 #endif\r
10 \r
11 #include "BrowseDialog.h"\r
12 #include "CopyDialogRes.h"\r
13 #include "SplitDialog.h"\r
14 #include "SplitUtils.h"\r
15 #include "resourceGui.h"\r
16 \r
17 using namespace NWindows;\r
18 \r
19 #ifdef LANG\r
20 static CIDLangPair kIDLangPairs[] =\r
21 {\r
22   { IDC_STATIC_SPLIT_PATH, 0x03020501 },\r
23   { IDC_STATIC_SPLIT_VOLUME, 0x02000D40 },\r
24 };\r
25 #endif\r
26 \r
27 \r
28 bool CSplitDialog::OnInit()\r
29 {\r
30   #ifdef LANG\r
31   LangSetWindowText(HWND(*this), 0x03020500);\r
32   LangSetDlgItemsText(HWND(*this), kIDLangPairs, sizeof(kIDLangPairs) / sizeof(kIDLangPairs[0]));\r
33   #endif\r
34   _pathCombo.Attach(GetItem(IDC_COMBO_SPLIT_PATH));\r
35   _volumeCombo.Attach(GetItem(IDC_COMBO_SPLIT_VOLUME));\r
36   \r
37   if (!FilePath.IsEmpty())\r
38   {\r
39     UString title;\r
40     GetText(title);\r
41     title += L' ';\r
42     title += FilePath;\r
43     SetText(title);\r
44   }\r
45   _pathCombo.SetText(Path);\r
46   AddVolumeItems(_volumeCombo);\r
47   _volumeCombo.SetCurSel(0);\r
48   NormalizeSize();\r
49   return CModalDialog::OnInit();\r
50 }\r
51 \r
52 bool CSplitDialog::OnSize(WPARAM /* wParam */, int xSize, int ySize)\r
53 {\r
54   int mx, my;\r
55   GetMargins(8, mx, my);\r
56   int bx1, bx2, by;\r
57   GetItemSizes(IDCANCEL, bx1, by);\r
58   GetItemSizes(IDOK, bx2, by);\r
59   int yPos = ySize - my - by;\r
60   int xPos = xSize - mx - bx1;\r
61 \r
62   InvalidateRect(NULL);\r
63 \r
64   {\r
65     RECT rect;\r
66     GetClientRectOfItem(IDC_BUTTON_SPLIT_PATH, rect);\r
67     int bx = rect.right - rect.left;\r
68     MoveItem(IDC_BUTTON_SPLIT_PATH, xSize - mx - bx, rect.top, bx, rect.bottom - rect.top);\r
69     ChangeSubWindowSizeX(_pathCombo, xSize - mx - mx - bx - mx);\r
70   }\r
71 \r
72   MoveItem(IDCANCEL, xPos, yPos, bx1, by);\r
73   MoveItem(IDOK, xPos - mx - bx2, yPos, bx2, by);\r
74 \r
75   return false;\r
76 }\r
77 \r
78 bool CSplitDialog::OnButtonClicked(int buttonID, HWND buttonHWND)\r
79 {\r
80   switch(buttonID)\r
81   {\r
82     case IDC_BUTTON_SPLIT_PATH:\r
83       OnButtonSetPath();\r
84       return true;\r
85   }\r
86   return CModalDialog::OnButtonClicked(buttonID, buttonHWND);\r
87 }\r
88 \r
89 void CSplitDialog::OnButtonSetPath()\r
90 {\r
91   UString currentPath;\r
92   _pathCombo.GetText(currentPath);\r
93   // UString title = L"Specify a location for output folder";\r
94   UString title = LangStringSpec(IDS_SET_FOLDER, 0x03020209);\r
95 \r
96   UString resultPath;\r
97   if (!MyBrowseForFolder(HWND(*this), title, currentPath, resultPath))\r
98     return;\r
99   NFile::NName::NormalizeDirPathPrefix(resultPath);\r
100   _pathCombo.SetCurSel(-1);\r
101   _pathCombo.SetText(resultPath);\r
102 }\r
103 \r
104 void CSplitDialog::OnOK()\r
105 {\r
106   _pathCombo.GetText(Path);\r
107   UString volumeString;\r
108   _volumeCombo.GetText(volumeString);\r
109   volumeString.Trim();\r
110   if (!ParseVolumeSizes(volumeString, VolumeSizes) || VolumeSizes.Size() == 0)\r
111   {\r
112     ::MessageBoxW(*this, LangString(IDS_INCORRECT_VOLUME_SIZE, 0x02000D41), L"7-Zip", 0);\r
113     return;\r
114   }\r
115   CModalDialog::OnOK();\r
116 }\r