Skip to content

Commit

Permalink
Changed the dialog to use IFileDialog instead of SHBrowseForFolder
Browse files Browse the repository at this point in the history
Added bushbuttons for (file/folder) dialog opening where they missed
  • Loading branch information
lawrinn committed Mar 4, 2016
1 parent d47f21d commit 9e8bca5
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 64 deletions.
143 changes: 92 additions & 51 deletions dsn/odbc_dsn.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <tchar.h>
#include <windowsx.h>
#include <winuser.h>
#include <shlobj.h>
#include <shobjidl.h>
#include "resource.h"
#include <ma_odbc.h>
#include <ma_odbc_setup.h>
Expand All @@ -45,6 +45,7 @@ char DSNStr[2048];
HWND hwndTab[7], hwndMain;
const int *EffectiveDisabledPages= NULL,
*EffectiveDisabledControls= NULL;
BOOL OpenCurSelection= TRUE;

const int DisabledPages[MAODBC_PROMPT_REQUIRED + 1][LASTPAGE + 1]= {
{ 0, 0, 0, 0, 0, 0},
Expand Down Expand Up @@ -451,51 +452,75 @@ void MADB_WIN_TestDsn(my_bool ShowSuccess)
}


static int CALLBACK SelectFolderCallbackProc(HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
INT_PTR SelectPath(HWND ParentWnd, int BoundEditId, const wchar_t *Caption, BOOL FolderPath, BOOL OpenCurrentSelection)
{

if(uMsg == BFFM_INITIALIZED)
if (SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE)))
{
SendMessage(hWnd, BFFM_SETSELECTION, TRUE, lpData);
//SendMessage(hWnd, BFFM_SETEXPANDED, TRUE, lpData) ;
}

return 0;
}
IFileDialog *PathDialog;

if (SUCCEEDED(CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
&IID_IFileOpenDialog, (void**)&PathDialog)))
{
HWND BoundEditWnd= GetDlgItem(ParentWnd, BoundEditId);
DWORD DialogOptions;
TCHAR Path[MAX_PATH];
IShellItem *SelectedItem;
int Length;
LPWSTR wPath;

if (FolderPath && SUCCEEDED(PathDialog->lpVtbl->GetOptions(PathDialog, &DialogOptions)))
{
PathDialog->lpVtbl->SetOptions(PathDialog, DialogOptions | FOS_PICKFOLDERS);
}

INT_PTR SelectFolder(HWND ParentWnd, int BoundEditId, const TCHAR *Caption)
{
TCHAR Path[MAX_PATH];
HWND BoundEditWnd= GetDlgItem(ParentWnd, BoundEditId);
BROWSEINFO bi;
LPITEMIDLIST pidl;

Edit_GetText(BoundEditWnd, Path, sizeof(Path));
Edit_GetText(BoundEditWnd, Path, sizeof(Path));
Length= MultiByteToWideChar(GetACP(), 0, Path, -1, NULL, 0);

bi.hwndOwner= ParentWnd;
bi.lpszTitle= Caption;
bi.ulFlags= BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
bi.lpfn= SelectFolderCallbackProc;
bi.lParam= (LPARAM)Path;
wPath= (SQLWCHAR *)malloc(Length * sizeof(SQLWCHAR));
if (wPath == NULL)
{
return FALSE;
}

pidl= SHBrowseForFolder(&bi);
MultiByteToWideChar(GetACP(), 0, Path, -1, wPath, Length);

if (pidl != 0)
{
IMalloc *imalloc= NULL;
SHCreateItemFromParsingName(wPath, NULL, &IID_IShellItem, (void**)&SelectedItem);
if (OpenCurrentSelection)
{
PathDialog->lpVtbl->SetFolder(PathDialog, SelectedItem);
}
else
{
PathDialog->lpVtbl->SetDefaultFolder(PathDialog, SelectedItem);
}
SelectedItem->lpVtbl->Release(SelectedItem);

SHGetPathFromIDList(pidl, Path);
free(wPath);

Edit_SetText(BoundEditWnd, Path);
PathDialog->lpVtbl->SetTitle(PathDialog, Caption);

if (SUCCEEDED(SHGetMalloc(&imalloc)))
{
imalloc->lpVtbl->Free(imalloc, pidl);
imalloc->lpVtbl->Release(imalloc);
if (SUCCEEDED(PathDialog->lpVtbl->Show(PathDialog, ParentWnd)))
{
if (SUCCEEDED(PathDialog->lpVtbl->GetResult(PathDialog, &SelectedItem)))
{
LPWSTR SelectedValue;
if (SUCCEEDED(SelectedItem->lpVtbl->GetDisplayName(SelectedItem, SIGDN_FILESYSPATH, &SelectedValue)))
{
BOOL Error;

/* TODO: I guess conversions from/to utf8 has to be done when syncing edits with DSN */
WideCharToMultiByte(GetACP(), 0, SelectedValue, -1, Path, sizeof(Path), NULL, &Error);
Edit_SetText(BoundEditWnd, Path);
CoTaskMemFree(SelectedValue);

return TRUE;
}
SelectedItem->lpVtbl->Release(SelectedItem);
}
}
PathDialog->lpVtbl->Release(PathDialog);
}

return TRUE;
CoUninitialize();
}

return FALSE;
Expand All @@ -504,7 +529,9 @@ INT_PTR SelectFolder(HWND ParentWnd, int BoundEditId, const TCHAR *Caption)

INT_PTR CALLBACK DialogDSNProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
BOOL res;

switch(uMsg)
{
case WM_CTLCOLORDLG:
if (!hbrBg)
Expand Down Expand Up @@ -545,23 +572,37 @@ INT_PTR CALLBACK DialogDSNProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
}
return TRUE;
case pbPlugindirBrowse:
return SelectFolder(hDlg, txtPluginDir, _T("Select Plugins Directory"));
return SelectPath(hDlg, txtPluginDir, L"Select Plugins Directory", /* Folder*/ TRUE, TRUE);
case pbCaPathBrowse:
return SelectFolder(hDlg, txtSslCaPath, _T("Select CA Path"));
case rbTCP:
case rbPipe:
if (HIWORD(wParam) == BN_CLICKED)
{
SendMessage(GetDlgItem(hwndTab[CurrentPage], lblServerName), WM_SETTEXT, 0,
(LOWORD(wParam) == rbTCP) ? (LPARAM)"Server name:" : (LPARAM)"Named pipe:");
ShowWindow(GetDlgItem(hwndTab[CurrentPage], lblPort),
(LOWORD(wParam) == rbTCP) ? SW_SHOW : SW_HIDE);
ShowWindow(GetDlgItem(hwndTab[CurrentPage], txtPort),
(LOWORD(wParam) == rbTCP) ? SW_SHOW : SW_HIDE);
}
return TRUE;
res= SelectPath(hDlg, txtSslCaPath, L"Select CA Path", TRUE, OpenCurSelection);
OpenCurSelection= OpenCurSelection && !res;
return res;
case pbKeyBrowse:
res= SelectPath(hDlg, txtSslKey, L"Select Client Private Key File", /* File */ FALSE,OpenCurSelection);
OpenCurSelection= OpenCurSelection && !res;
return res;
case pbCertBrowse:
res= SelectPath(hDlg, txtSslCert, L"Select Public Key Certificate File", FALSE,OpenCurSelection);
OpenCurSelection= OpenCurSelection && !res;
return res;
case pbCaCertBrowse:
res= SelectPath(hDlg, txtSslCertAuth, L"Select Certificate Authority Certificate File", FALSE,OpenCurSelection);
OpenCurSelection= OpenCurSelection && !res;
return res;
case rbTCP:
case rbPipe:
if (HIWORD(wParam) == BN_CLICKED)
{
SendMessage(GetDlgItem(hwndTab[CurrentPage], lblServerName), WM_SETTEXT, 0,
(LOWORD(wParam) == rbTCP) ? (LPARAM)"Server name:" : (LPARAM)"Named pipe:");
ShowWindow(GetDlgItem(hwndTab[CurrentPage], lblPort),
(LOWORD(wParam) == rbTCP) ? SW_SHOW : SW_HIDE);
ShowWindow(GetDlgItem(hwndTab[CurrentPage], txtPort),
(LOWORD(wParam) == rbTCP) ? SW_SHOW : SW_HIDE);
}
return TRUE;

}
}
break;
}
return FALSE;
Expand Down
3 changes: 3 additions & 0 deletions dsn/odbc_dsn.rc
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,15 @@ BEGIN

LTEXT "Key",IDC_STATIC,15,25,56,8,0,WS_EX_TRANSPARENT
EDITTEXT txtSslKey,84,25,110,10,ES_AUTOHSCROLL
PUSHBUTTON "Browse",pbKeyBrowse,195,23,30,14

LTEXT "Certificate",IDC_STATIC,15,39,56,8,0,WS_EX_TRANSPARENT
EDITTEXT txtSslCert,84,39,110,10,ES_AUTOHSCROLL
PUSHBUTTON "Browse",pbCertBrowse,195,37,30,14

LTEXT "Certificate Authority",IDC_STATIC,15,53,68,8,0,WS_EX_TRANSPARENT
EDITTEXT txtSslCertAuth,84,53,110,10,ES_AUTOHSCROLL
PUSHBUTTON "Browse",pbCaCertBrowse,195,51,30,14

LTEXT "CA Path",IDC_STATIC,15,67,56,8,0,WS_EX_TRANSPARENT
EDITTEXT txtSslCaPath,84,67,110,10,ES_AUTOHSCROLL
Expand Down
Binary file modified dsn/resource.h
Binary file not shown.
6 changes: 3 additions & 3 deletions ma_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,9 @@ int MADB_ConvertAnsi2Unicode(int CodePage, char *AnsiString, int AnsiLength,
int *LengthIndicator, MADB_Error *Error)
{
SQLINTEGER RequiredLength;
SQLWCHAR *Tmp= UnicodeString;
char IsNull= 0;
int rc= 0;
SQLWCHAR *Tmp= UnicodeString;
char IsNull= 0;
int rc= 0;

if (LengthIndicator)
*LengthIndicator= 0;
Expand Down
9 changes: 7 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ SET (ODBC_TESTS
"curext" "relative" "unicode" "cursor" "dyn_cursor"
"error" "param" "result1" "result2" "multistatement")

IF (BUILD_INTERACTIVE_TESTS OR USE_INTERACTIVE_TESTS)
# Interactive makes sense on WIN32 only atm
IF (WIN32 AND (BUILD_INTERACTIVE_TESTS OR USE_INTERACTIVE_TESTS))
SET (ODBC_TESTS ${ODBC_TESTS} "interactive")
ENDIF()

FOREACH (ODBC_TEST ${ODBC_TESTS})
ADD_EXECUTABLE(${ODBC_TEST} ${ODBC_TEST}.c tap.h)
IF (${ODBC_TEST} STREQUAL "interactive")
ADD_EXECUTABLE(${ODBC_TEST} ${ODBC_TEST}.c tap.h)
ELSE()
ADD_EXECUTABLE(${ODBC_TEST} ${ODBC_TEST}.c tap.h)
ENDIF()
IF (DIRECT_LINK_TESTS)
TARGET_LINK_LIBRARIES(${ODBC_TEST} maodbc ${MARIADB_LIB} ${PLATFORM_DEPENDENCIES})
ELSE()
Expand Down
18 changes: 11 additions & 7 deletions test/interactive.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,18 @@ int main(int argc, char **argv)
int tests= sizeof(my_tests)/sizeof(MA_ODBC_TESTS) - 1;
DWORD dwProcID= GetCurrentProcessId();

hWnd = GetTopWindow(GetDesktopWindow());
while(hWnd)
hWnd= GetConsoleWindow();
if (hWnd == NULL)
{
DWORD dwWndProcID = 0;
GetWindowThreadProcessId(hWnd, &dwWndProcID);
if(dwWndProcID == dwProcID)
break;
hWnd = GetNextWindow(hWnd, GW_HWNDNEXT);
hWnd= GetTopWindow(GetDesktopWindow());
while(hWnd)
{
DWORD dwWndProcID = 0;
GetWindowThreadProcessId(hWnd, &dwWndProcID);
if(dwWndProcID == dwProcID)
break;
hWnd = GetNextWindow(hWnd, GW_HWNDNEXT);
}
}

get_options(argc, argv);
Expand Down
2 changes: 1 addition & 1 deletion test/tap.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ SQLHANDLE DoConnect(SQLHANDLE *Connection,

if(!SQL_SUCCEEDED(SQLDriverConnect(*Connection, NULL, (SQLCHAR *)DSNString, SQL_NTS, (SQLCHAR *)DSNOut, 1024, &Length, SQL_DRIVER_NOPROMPT)))
{
diag("Connection failed");
odbc_print_error(SQL_HANDLE_DBC, *Connection);
return NULL;
}

Expand Down

0 comments on commit 9e8bca5

Please sign in to comment.