summaryrefslogtreecommitdiff
path: root/plugins/Folders/src/dlg_handlers.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-08-07 12:10:19 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-08-07 12:10:19 +0000
commit52a0c6e6efb7014b87552097c13ceea6175ce377 (patch)
treedc4d3e62d27d6538672c9e80166ed945cf659a2f /plugins/Folders/src/dlg_handlers.cpp
parent97ecd2b560357a1c7756d7b93d0b820f63071080 (diff)
folders -> TCHAR
git-svn-id: http://svn.miranda-ng.org/main/trunk@1389 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Folders/src/dlg_handlers.cpp')
-rw-r--r--plugins/Folders/src/dlg_handlers.cpp439
1 files changed, 158 insertions, 281 deletions
diff --git a/plugins/Folders/src/dlg_handlers.cpp b/plugins/Folders/src/dlg_handlers.cpp
index 4d507ce31c..88f6f4ad63 100644
--- a/plugins/Folders/src/dlg_handlers.cpp
+++ b/plugins/Folders/src/dlg_handlers.cpp
@@ -6,179 +6,121 @@ static int bInitializing = 0;
int GetCurrentItemSelection(HWND hWnd)
{
- return SendDlgItemMessageW(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_GETCURSEL, 0, 0);
+ return SendDlgItemMessage(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_GETCURSEL, 0, 0);
}
int GetCurrentSectionSelection(HWND hWnd)
{
- return SendDlgItemMessageW(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_GETCURSEL, 0, 0);
+ return SendDlgItemMessage(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_GETCURSEL, 0, 0);
}
PFolderItem GetSelectedItem(HWND hWnd)
{
- WCHAR section[MAX_FOLDER_SIZE];
- WCHAR item[MAX_FOLDER_SIZE];
+ char section[MAX_FOLDER_SIZE], item[MAX_FOLDER_SIZE];
GetCurrentItemText(hWnd, item, MAX_FOLDER_SIZE);
GetCurrentSectionText(hWnd, section, MAX_FOLDER_SIZE);
return lstRegisteredFolders.GetTranslated(section, item);
}
-int GetCurrentItemText(HWND hWnd, WCHAR *buffer, int count)
+int GetCurrentItemText(HWND hWnd, char *buffer, int count)
{
int index = GetCurrentItemSelection(hWnd);
- if (index != LB_ERR)
- {
- SendDlgItemMessageW(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_GETTEXT, index, (LPARAM) buffer);
- return 1;
- }
- else{
- buffer[0] = L'\0';
- return 0;
- }
+ if (index != LB_ERR) {
+ SendDlgItemMessageA(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_GETTEXT, index, (LPARAM) buffer);
+ return 1;
+ }
+
+ buffer[0] = L'\0';
+ return 0;
}
-int GetCurrentSectionText(HWND hWnd, WCHAR *buffer, int count)
+int GetCurrentSectionText(HWND hWnd, char *buffer, int count)
{
int index = GetCurrentSectionSelection(hWnd);
- if (index != LB_ERR)
- {
- SendDlgItemMessageW(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_GETTEXT, index, (LPARAM) buffer);
- return 1;
- }
- else{
- buffer[0] = L'0';
- return 0;
- }
-}
+ if (index != LB_ERR) {
+ SendDlgItemMessageA(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_GETTEXT, index, (LPARAM) buffer);
+ return 1;
+ }
-//void GetEditText(HWND hWnd, char *buffer, int size)
-//{
-// GetWindowText(GetDlgItem(hWnd, IDC_FOLDER_EDIT), buffer, size);
-// StrTrim(buffer, "\\\t \n");
-//}
+ buffer[0] = L'0';
+ return 0;
+}
-void GetEditTextW(HWND hWnd, wchar_t *buffer, int size)
+static void GetEditText(HWND hWnd, TCHAR *buffer, int size)
{
- GetWindowTextW(GetDlgItem(hWnd, IDC_FOLDER_EDIT), buffer, size);
+ GetWindowText( GetDlgItem(hWnd, IDC_FOLDER_EDIT), buffer, size);
}
-//void SetEditText(HWND hWnd, const char *buffer)
-//{
-// bInitializing = 1;
-// SetWindowText(GetDlgItem(hWnd, IDC_FOLDER_EDIT), buffer);
-// bInitializing = 0;
-//// SendDlgItemMessage(hWnd, IDC_FOLDER_EDIT, WM_SETTEXT, 0, (LPARAM) buffer);
-//}
-
-void SetEditTextW(HWND hWnd, const wchar_t *buffer)
+void SetEditText(HWND hWnd, const TCHAR *buffer)
{
bInitializing = 1;
- SetWindowTextW(GetDlgItem(hWnd, IDC_FOLDER_EDIT), buffer);
+ SetWindowText(GetDlgItem(hWnd, IDC_FOLDER_EDIT), buffer);
bInitializing = 0;
}
int ContainsSection(HWND hWnd, const WCHAR *section)
{
- int index = SendDlgItemMessageW(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_FINDSTRINGEXACT, -1, (LPARAM) section);
+ int index = SendDlgItemMessage(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_FINDSTRINGEXACT, -1, (LPARAM) section);
return (index != LB_ERR);
}
void LoadRegisteredFolderSections(HWND hWnd)
{
- for (int i = 0; i < lstRegisteredFolders.Count(); i++)
- {
- PFolderItem tmp = lstRegisteredFolders.Get(i + 1);
- WCHAR *translated = mir_a2u(Translate(tmp->GetSection()));
- if (!ContainsSection(hWnd, translated))
- {
- SendDlgItemMessageW(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_ADDSTRING, 0, (LPARAM) translated);
- }
- mir_free(translated);
- }
+ for (int i = 0; i < lstRegisteredFolders.Count(); i++) {
+ PFolderItem tmp = lstRegisteredFolders.Get(i + 1);
+ TCHAR *translated = mir_a2t( tmp->GetSection());
+ if (!ContainsSection(hWnd, translated))
+ SendDlgItemMessage(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_ADDSTRING, 0, (LPARAM)TranslateTS(translated));
+
+ mir_free(translated);
+ }
}
void LoadRegisteredFolderItems(HWND hWnd)
{
- WCHAR buffer[MAX_FOLDER_SIZE];
+ char buffer[MAX_FOLDER_SIZE];
GetCurrentSectionText(hWnd, buffer, MAX_FOLDER_SIZE);
- SendDlgItemMessageW(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_RESETCONTENT, 0, 0);
- for (int i = 0; i < lstRegisteredFolders.Count(); i++)
- {
- PFolderItem item = lstRegisteredFolders.Get(i + 1);
- WCHAR *wide = mir_a2u(Translate(item->GetSection()));
- if (wcscmp(buffer, wide) == 0)
- {
- mir_free(wide);
- wide = mir_a2u(Translate(item->GetName()));
- SendDlgItemMessageW(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_ADDSTRING, 0, (LPARAM) wide);
- }
- mir_free(wide);
+ SendDlgItemMessage(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_RESETCONTENT, 0, 0);
+ for (int i = 0; i < lstRegisteredFolders.Count(); i++) {
+ PFolderItem item = lstRegisteredFolders.Get(i + 1);
+ if ( !strcmp(buffer, item->GetSection()) == 0) {
+ mir_ptr<TCHAR> wide( mir_a2t( item->GetName()));
+ SendDlgItemMessage(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_ADDSTRING, 0, (LPARAM)TranslateTS(wide));
}
- SendDlgItemMessageW(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_SETCURSEL, 0, 0); //select the first item
+ }
+ SendDlgItemMessage(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_SETCURSEL, 0, 0); //select the first item
PostMessage(hWnd, WM_COMMAND, MAKEWPARAM(IDC_FOLDERS_ITEMS_LIST, LBN_SELCHANGE), 0); //tell the dialog to refresh the preview
}
void LoadItem(HWND hWnd, PFolderItem item)
{
- if (item)
- {
- if (item->IsUnicode())
- {
- SetEditTextW(hWnd, item->GetFormatW());
- }
- else{
- WCHAR *buffer = mir_a2u(item->GetFormat());
- SetEditTextW(hWnd, buffer);
- mir_free(buffer);
- }
- RefreshPreview(hWnd);
- }
+ if (item) {
+ SetEditText(hWnd, item->GetFormat());
+ RefreshPreview(hWnd);
+ }
}
void SaveItem(HWND hWnd, PFolderItem item, int bEnableApply)
{
- if (item)
- {
- if (item->IsUnicode())
- {
- wchar_t buffer[MAX_FOLDER_SIZE];
- GetEditTextW(hWnd, buffer, MAX_FOLDER_SIZE);
- item->SetFormatW(buffer);
- }
- else{
- WCHAR buffer[MAX_FOLDER_SIZE];
- char ansi[MAX_FOLDER_SIZE];
- GetEditTextW(hWnd, buffer, MAX_FOLDER_SIZE);
- WideCharToMultiByte(CallService(MS_LANGPACK_GETCODEPAGE, 0, 0), 0, buffer, -1, ansi, MAX_FOLDER_SIZE, NULL, NULL);
- item->SetFormat(ansi);
- }
- if (bEnableApply)
- {
- SendMessage(GetParent(hWnd), PSM_CHANGED, 0, 0);
- }
- }
+ if (!item)
+ return;
+
+ TCHAR buffer[MAX_FOLDER_SIZE];
+ GetEditText(hWnd, buffer, SIZEOF(buffer));
+ item->SetFormat(buffer);
+
+ if (bEnableApply)
+ SendMessage(GetParent(hWnd), PSM_CHANGED, 0, 0);
}
int ChangesNotSaved(HWND hWnd, PFolderItem item)
{
int res = 0;
- if (item)
- {
- if (item->IsUnicode())
- {
- wchar_t buffer[MAX_FOLDER_SIZE];
- GetEditTextW(hWnd, buffer, MAX_FOLDER_SIZE);
- res = (wcscmp(item->GetFormatW(), buffer) != 0);
- }
- else{
- WCHAR buffer[MAX_FOLDER_SIZE];
- GetEditTextW(hWnd, buffer, MAX_FOLDER_SIZE);
- char *ansi = mir_u2a(buffer);
-
- res = (strcmp(item->GetFormat(), ansi) != 0);
- mir_free(ansi);
- }
- }
+ if (item) {
+ TCHAR buffer[MAX_FOLDER_SIZE];
+ GetEditText(hWnd, buffer, MAX_FOLDER_SIZE);
+ res = _tcscmp(item->GetFormat(), buffer) != 0;
+ }
return res;
}
@@ -186,22 +128,16 @@ int ChangesNotSaved(HWND hWnd, PFolderItem item)
void CheckForChanges(HWND hWnd, int bNeedConfirmation = 1)
{
if (ChangesNotSaved(hWnd, lastItem))
- {
- if ((!bNeedConfirmation) || MessageBoxW(hWnd, TranslateW(L"Some changes weren't saved. Apply the changes now ?"), TranslateW(L"Changes not saved"), MB_YESNO | MB_ICONINFORMATION) == IDYES)
- {
- SaveItem(hWnd, lastItem);
- }
- }
+ if ((!bNeedConfirmation) || MessageBox(hWnd, TranslateT("Some changes weren't saved. Apply the changes now ?"), TranslateT("Changes not saved"), MB_YESNO | MB_ICONINFORMATION) == IDYES)
+ SaveItem(hWnd, lastItem);
}
void RefreshPreview(HWND hWnd)
{
- wchar_t tmp[MAX_FOLDER_SIZE];
- wchar_t res[MAX_FOLDER_SIZE];
- GetEditTextW(hWnd, tmp, MAX_FOLDER_SIZE);
- ExpandPathW(res, tmp, MAX_FOLDER_SIZE);
- SetWindowTextW(GetDlgItem(hWnd, IDC_PREVIEW_EDIT), res);
- //SendDlgItemMessage(hWnd, IDC_PREVIEW_EDIT, WM_SETTEXT, 0, (LPARAM) res);
+ TCHAR tmp[MAX_FOLDER_SIZE], res[MAX_FOLDER_SIZE];
+ GetEditText(hWnd, tmp, MAX_FOLDER_SIZE);
+ ExpandPath(res, tmp, MAX_FOLDER_SIZE);
+ SetWindowText(GetDlgItem(hWnd, IDC_PREVIEW_EDIT), res);
}
@@ -210,148 +146,97 @@ void RefreshPreview(HWND hWnd)
INT_PTR CALLBACK DlgProcOpts(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch (msg)
- {
- case WM_INITDIALOG:
- {
- bInitializing = 1;
- lastItem = NULL;
- TranslateDialogDefault(hWnd);
- LoadRegisteredFolderSections(hWnd);
- bInitializing = 0;
+ switch (msg) {
+ case WM_INITDIALOG:
+ bInitializing = 1;
+ lastItem = NULL;
+ TranslateDialogDefault(hWnd);
+ LoadRegisteredFolderSections(hWnd);
+ bInitializing = 0;
+ break;
+
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDC_FOLDER_EDIT:
+ switch (HIWORD(wParam)) {
+ case EN_CHANGE:
+ RefreshPreview(hWnd);
+ if (!bInitializing)
+ SendMessage(GetParent(hWnd), PSM_CHANGED, 0, 0); //show the apply button.
+ }
+ break;
- break;
- }
+ case IDC_REFRESH_BUTTON:
+ RefreshPreview(hWnd);
+ break;
- case WM_COMMAND:
- {
- switch (LOWORD(wParam))
- {
- case IDC_FOLDER_EDIT:
- {
- switch (HIWORD(wParam))
- {
- case EN_CHANGE:
- {
- RefreshPreview(hWnd);
- if (!bInitializing)
- {
- SendMessage(GetParent(hWnd), PSM_CHANGED, 0, 0); //show the apply button.
- }
-
- break;
- }
- }
-
- break;
- }
-
- case IDC_REFRESH_BUTTON:
- {
- RefreshPreview(hWnd);
-
- break;
- }
-
- case IDC_HELP_BUTTON:
- {
- HWND helpDlg = CreateDialogW(hInstance, MAKEINTRESOURCEW(IDD_VARIABLES_HELP), hWnd, DlgProcVariables);
- ShowWindow(helpDlg, SW_SHOW);
-
- break;
- }
-
- case IDC_FOLDERS_SECTIONS_LIST:
- {
- switch (HIWORD(wParam))
- {
- case LBN_SELCHANGE:
- {
- CheckForChanges(hWnd);
- LoadRegisteredFolderItems(hWnd);
- lastItem = NULL;
- SetEditTextW(hWnd, L"");
- RefreshPreview(hWnd);
-
- break;
- }
- }
-
- break;
- }
-
- case IDC_FOLDERS_ITEMS_LIST:
- {
- switch (HIWORD(wParam))
- {
- case LBN_SELCHANGE:
- {
- PFolderItem item = GetSelectedItem(hWnd);
- if (item != NULL)
- {
- CheckForChanges(hWnd);
- LoadItem(hWnd, item);
- }
- lastItem = item;
-
- break;
- }
- }
-
- break;
- }
- }
+ case IDC_HELP_BUTTON:
+ {
+ HWND helpDlg = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_VARIABLES_HELP), hWnd, DlgProcVariables);
+ ShowWindow(helpDlg, SW_SHOW);
+ }
+ break;
+
+ case IDC_FOLDERS_SECTIONS_LIST:
+ switch (HIWORD(wParam)) {
+ case LBN_SELCHANGE:
+ CheckForChanges(hWnd);
+ LoadRegisteredFolderItems(hWnd);
+ lastItem = NULL;
+ SetEditText(hWnd, L"");
+ RefreshPreview(hWnd);
+ break;
+ }
- break;
- }
+ break;
- case WM_NOTIFY:
+ case IDC_FOLDERS_ITEMS_LIST:
+ switch (HIWORD(wParam)) {
+ case LBN_SELCHANGE:
{
-// Log("WM_NOTIFY %d %d", wParam, lParam);
- switch(((LPNMHDR)lParam)->idFrom)
+ PFolderItem item = GetSelectedItem(hWnd);
+ if (item != NULL)
{
- case 0:
- switch (((LPNMHDR)lParam)->code)
- {
- case PSN_APPLY:
- {
- PFolderItem item = GetSelectedItem(hWnd);
- if (item)
- {
- SaveItem(hWnd, item, FALSE);
- LoadItem(hWnd, item);
- }
-
- lstRegisteredFolders.Save();
- CallPathChangedEvents();
-
- break;
- }
- }
-
- break;
+ CheckForChanges(hWnd);
+ LoadItem(hWnd, item);
}
+ lastItem = item;
+
+ break;
}
+ }
- break;
+ break;
+ }
+
+ break;
- default:
+ case WM_NOTIFY:
+ switch(((LPNMHDR)lParam)->idFrom) {
+ case 0:
+ switch (((LPNMHDR)lParam)->code) {
+ case PSN_APPLY:
{
+ PFolderItem item = GetSelectedItem(hWnd);
+ if (item) {
+ SaveItem(hWnd, item, FALSE);
+ LoadItem(hWnd, item);
+ }
+
+ lstRegisteredFolders.Save();
+ CallPathChangedEvents();
break;
}
+ }
}
+ break;
+ }
return 0;
}
-INT_PTR CALLBACK DlgProcVariables(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- switch (msg)
- {
- case WM_INITDIALOG:
- {
- SetDlgItemText(hWnd, IDC_HELP_RICHEDIT, _T("\
+static TCHAR tszMessage[] = _T("\
Don\'t forget to click on Apply to save the changes. If you don\'t then the changes won\'t\r\n\
be saved to the database, they will only be valid for this session.\r\n\r\n\
Variable string\t\tWhat it expands to:\r\n\
@@ -376,36 +261,28 @@ profile is \'default.dat\' and miranda\'s path is \'c:\\program files\\miranda i
%profile_path%\\%current_profile%\twill expand to \'c:\\program files\\miranda im\\profiles\\default\\'\r\n\
%miranda_path%\\plugins\\config\twill expand to \'c:\\program files\\miranda im\\plugins\\config\\'\r\n\
\' %miranda_path%\\\\\\\\ \'\t\twill expand to \'c:\\program files\\miranda im\\'\r\n\
-notice that the spaces at the beginning and the end of the string are trimmed, as well as the last \\\
-"));
-
- TranslateDialogDefault(hWnd);
-
- break;
- }
-
- case WM_CLOSE:
- {
- DestroyWindow(hWnd);
+notice that the spaces at the beginning and the end of the string are trimmed, as well as the last");
- break;
- }
-
- case WM_COMMAND:
- {
- switch (LOWORD(wParam))
- {
- case IDCLOSE:
- {
- DestroyWindow(hWnd);
-
- break;
- }
- }
-
- break;
- }
+INT_PTR CALLBACK DlgProcVariables(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch (msg) {
+ case WM_INITDIALOG:
+ SetDlgItemText(hWnd, IDC_HELP_RICHEDIT, tszMessage);
+ TranslateDialogDefault(hWnd);
+ break;
+
+ case WM_CLOSE:
+ DestroyWindow(hWnd);
+ break;
+
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDCLOSE:
+ DestroyWindow(hWnd);
+ break;
}
+ break;
+ }
return 0;
-} \ No newline at end of file
+}