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)
12 class CEditCompatModes
: public CDialogImpl
<CEditCompatModes
>
15 CLayerUIPropPage
* m_pPage
;
19 CStringW
GetListText(HWND ListBox
, int Cur
)
22 int Length
= ListBox_GetTextLen(ListBox
, Cur
);
23 LPWSTR Buffer
= Str
.GetBuffer(Length
+ 1);
24 ListBox_GetText(ListBox
, Cur
, Buffer
);
25 Str
.ReleaseBuffer(Length
);
30 CEditCompatModes(CLayerUIPropPage
* page
)
41 LRESULT
OnInitDialog(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
43 CenterWindow(GetParent());
45 m_hListActive
= GetDlgItem(IDC_COMPATIBILITYMODE
);
46 m_hListAdd
= GetDlgItem(IDC_NEWCOMPATIBILITYMODE
);
48 CComObject
<CLayerStringList
> pList
;
52 CComHeapPtr
<OLECHAR
> str
;
53 HRESULT hr
= pList
.Next(1, &str
, NULL
);
56 ListBox_AddString(m_hListAdd
, str
);
59 for (int n
= 0; n
< m_pPage
->m_CustomLayers
.GetSize(); ++n
)
61 const WCHAR
* Str
= m_pPage
->m_CustomLayers
[n
].GetString();
62 int Index
= ListBox_FindStringExact(m_hListActive
, -1, Str
);
64 Index
= ListBox_AddString(m_hListActive
, Str
);
67 OnListboxUpdated(0, 0, 0, bHandled
);
71 LRESULT
OnButton(WORD wNotifyCode
, WORD wID
, HWND hWndCtl
, BOOL
& bHandled
)
75 int Count
= ListBox_GetCount(m_hListActive
);
76 m_pPage
->m_CustomLayers
.RemoveAll();
77 for (int Cur
= 0; Cur
< Count
; ++Cur
)
79 CString Str
= GetListText(m_hListActive
, Cur
);
80 m_pPage
->m_CustomLayers
.Add(Str
);
87 LRESULT
OnAdd(WORD wNotifyCode
, WORD wID
, HWND hWndCtl
, BOOL
& bHandled
)
89 int Sel
= ListBox_GetCurSel(m_hListAdd
);
90 CStringW Str
= GetListText(m_hListAdd
, Sel
);
92 int Index
= ListBox_FindStringExact(m_hListActive
, -1, Str
);
94 Index
= ListBox_AddString(m_hListActive
, Str
);
96 ::SetFocus(m_hListAdd
);
100 LRESULT
OnRemove(WORD wNotifyCode
, WORD wID
, HWND hWndCtl
, BOOL
& bHandled
)
102 int Sel
= ListBox_GetCurSel(m_hListActive
);
103 CStringW Str
= GetListText(m_hListActive
, Sel
);
105 ListBox_DeleteString(m_hListActive
, Sel
);
106 int Index
= ListBox_FindStringExact(m_hListAdd
, -1, Str
);
108 Index
= ListBox_SetCurSel(m_hListAdd
, Index
);
109 OnListboxUpdated(wNotifyCode
, wID
, hWndCtl
, bHandled
);
113 LRESULT
OnRemoveAll(WORD wNotifyCode
, WORD wID
, HWND hWndCtl
, BOOL
& bHandled
)
115 ListBox_ResetContent(m_hListActive
);
116 OnListboxUpdated(wNotifyCode
, wID
, hWndCtl
, bHandled
);
120 LRESULT
OnListboxUpdated(WORD wNotifyCode
, WORD wID
, HWND hWndCtl
, BOOL
& bHandled
)
122 if (m_hListAdd
== hWndCtl
)
123 ListBox_SetCurSel(m_hListActive
, -1);
124 else if (m_hListActive
== hWndCtl
)
125 ListBox_SetCurSel(m_hListAdd
, -1);
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);
135 enum { IDD
= IDD_EDITCOMPATIBILITYMODES
};
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
)
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
)
151 BOOL
ShowEditCompatModes(HWND hWnd
, CLayerUIPropPage
* page
)
153 CEditCompatModes
modes(page
);
154 INT_PTR Result
= modes
.DoModal(hWnd
);
155 return Result
== IDOK
;