1 /*
2 * PROJECT: ReactOS Compatibility Layer Shell Extension
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: CEditCompatModes implementation
5 * COPYRIGHT: Copyright 2015-2019 Mark Jansen (mark.jansen@reactos.org)
6 */
7
8 #include "precomp.h"
9 #include <windowsx.h>
10
11
12 class CEditCompatModes : public CDialogImpl<CEditCompatModes>
13 {
14 private:
15 CLayerUIPropPage* m_pPage;
16 HWND m_hListAdd;
17 HWND m_hListActive;
18
GetListText(HWND ListBox,int Cur)19 CStringW GetListText(HWND ListBox, int Cur)
20 {
21 CStringW Str;
22 int Length = ListBox_GetTextLen(ListBox, Cur);
23 LPWSTR Buffer = Str.GetBuffer(Length + 1);
24 ListBox_GetText(ListBox, Cur, Buffer);
25 Str.ReleaseBuffer(Length);
26 return Str;
27 }
28
29 public:
CEditCompatModes(CLayerUIPropPage * page)30 CEditCompatModes(CLayerUIPropPage* page)
31 : m_pPage(page)
32 {
33 m_pPage->AddRef();
34 }
35
~CEditCompatModes()36 ~CEditCompatModes()
37 {
38 m_pPage->Release();
39 }
40
OnInitDialog(UINT nMsg,WPARAM wParam,LPARAM lParam,BOOL & bHandled)41 LRESULT OnInitDialog(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
42 {
43 CenterWindow(GetParent());
44
45 m_hListActive = GetDlgItem(IDC_COMPATIBILITYMODE);
46 m_hListAdd = GetDlgItem(IDC_NEWCOMPATIBILITYMODE);
47
48 CComObject<CLayerStringList> pList;
49
50 while (TRUE)
51 {
52 CComHeapPtr<OLECHAR> str;
53 HRESULT hr = pList.Next(1, &str, NULL);
54 if (hr != S_OK)
55 break;
56 ListBox_AddString(m_hListAdd, str);
57 }
58
59 for (int n = 0; n < m_pPage->m_CustomLayers.GetSize(); ++n)
60 {
61 const WCHAR* Str = m_pPage->m_CustomLayers[n].GetString();
62 int Index = ListBox_FindStringExact(m_hListActive, -1, Str);
63 if (Index == LB_ERR)
64 Index = ListBox_AddString(m_hListActive, Str);
65 }
66
67 OnListboxUpdated(0, 0, 0, bHandled);
68 return 0;
69 }
70
OnButton(WORD wNotifyCode,WORD wID,HWND hWndCtl,BOOL & bHandled)71 LRESULT OnButton(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
72 {
73 if (wID == IDOK)
74 {
75 int Count = ListBox_GetCount(m_hListActive);
76 m_pPage->m_CustomLayers.RemoveAll();
77 for (int Cur = 0; Cur < Count; ++Cur)
78 {
79 CString Str = GetListText(m_hListActive, Cur);
80 m_pPage->m_CustomLayers.Add(Str);
81 }
82 }
83 EndDialog(wID);
84 return 0;
85 }
86
OnAdd(WORD wNotifyCode,WORD wID,HWND hWndCtl,BOOL & bHandled)87 LRESULT OnAdd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
88 {
89 int Sel = ListBox_GetCurSel(m_hListAdd);
90 CStringW Str = GetListText(m_hListAdd, Sel);
91
92 int Index = ListBox_FindStringExact(m_hListActive, -1, Str);
93 if (Index == LB_ERR)
94 Index = ListBox_AddString(m_hListActive, Str);
95
96 ::SetFocus(m_hListAdd);
97 return 0;
98 }
99
OnRemove(WORD wNotifyCode,WORD wID,HWND hWndCtl,BOOL & bHandled)100 LRESULT OnRemove(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
101 {
102 int Sel = ListBox_GetCurSel(m_hListActive);
103 CStringW Str = GetListText(m_hListActive, Sel);
104
105 ListBox_DeleteString(m_hListActive, Sel);
106 int Index = ListBox_FindStringExact(m_hListAdd, -1, Str);
107 if (Index != LB_ERR)
108 Index = ListBox_SetCurSel(m_hListAdd, Index);
109 OnListboxUpdated(wNotifyCode, wID, hWndCtl, bHandled);
110 return 0;
111 }
112
OnRemoveAll(WORD wNotifyCode,WORD wID,HWND hWndCtl,BOOL & bHandled)113 LRESULT OnRemoveAll(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
114 {
115 ListBox_ResetContent(m_hListActive);
116 OnListboxUpdated(wNotifyCode, wID, hWndCtl, bHandled);
117 return 0;
118 }
119
OnListboxUpdated(WORD wNotifyCode,WORD wID,HWND hWndCtl,BOOL & bHandled)120 LRESULT OnListboxUpdated(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
121 {
122 if (m_hListAdd == hWndCtl)
123 ListBox_SetCurSel(m_hListActive, -1);
124 else if (m_hListActive == hWndCtl)
125 ListBox_SetCurSel(m_hListAdd, -1);
126
127 ::EnableWindow(GetDlgItem(IDC_ADD), ListBox_GetCurSel(m_hListAdd) >= 0);
128 ::EnableWindow(GetDlgItem(IDC_REMOVE), ListBox_GetCurSel(m_hListActive) >= 0);
129 ::EnableWindow(GetDlgItem(IDC_REMOVEALL), ListBox_GetCount(m_hListActive) > 0);
130 bHandled = TRUE;
131 return 0;
132 }
133
134 public:
135 enum { IDD = IDD_EDITCOMPATIBILITYMODES };
136
137 BEGIN_MSG_MAP(CEditCompatModes)
138 MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
139 COMMAND_ID_HANDLER(IDC_ADD, OnAdd)
140 COMMAND_ID_HANDLER(IDC_REMOVE, OnRemove)
141 COMMAND_ID_HANDLER(IDC_REMOVEALL, OnRemoveAll)
142
143 COMMAND_ID_HANDLER(IDOK, OnButton)
144 COMMAND_ID_HANDLER(IDCANCEL, OnButton)
145 COMMAND_ID_HANDLER(IDC_COMPATIBILITYMODE, OnListboxUpdated)
146 COMMAND_ID_HANDLER(IDC_NEWCOMPATIBILITYMODE, OnListboxUpdated)
147 END_MSG_MAP()
148 };
149
150
ShowEditCompatModes(HWND hWnd,CLayerUIPropPage * page)151 BOOL ShowEditCompatModes(HWND hWnd, CLayerUIPropPage* page)
152 {
153 CEditCompatModes modes(page);
154 INT_PTR Result = modes.DoModal(hWnd);
155 return Result == IDOK;
156 }
157
158
159