Changeset View
Changeset View
Standalone View
Standalone View
w32/main.c
Context not available. | |||||
#include <config.h> | #include <config.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#if WINVER < 0x0403 | #include <unistd.h> | ||||
# define WINVER 0x0403 /* Required for SendInput. */ | |||||
#endif | |||||
#include <windows.h> | #include <windows.h> | ||||
#ifdef HAVE_W32CE_SYSTEM | #ifdef HAVE_W32CE_SYSTEM | ||||
# include <winioctl.h> | # include <winioctl.h> | ||||
Context not available. | |||||
#define PGMNAME "pinentry-w32" | #define PGMNAME "pinentry-w32" | ||||
#ifndef LSFW_LOCK | |||||
# define LSFW_LOCK 1 | |||||
# define LSFW_UNLOCK 2 | |||||
#endif | |||||
#ifndef debugfp | #ifndef debugfp | ||||
#define debugfp stderr | #define debugfp stderr | ||||
#endif | #endif | ||||
/* This function pointer gets initialized in main. */ | |||||
#ifndef HAVE_W32CE_SYSTEM | |||||
static BOOL WINAPI (*lock_set_foreground_window)(UINT); | |||||
#endif | |||||
static int w32_cmd_handler (pinentry_t pe); | static int w32_cmd_handler (pinentry_t pe); | ||||
static void ok_button_clicked (HWND dlg, pinentry_t pe); | static void ok_button_clicked (HWND dlg, pinentry_t pe); | ||||
Context not available. | |||||
static void | |||||
move_mouse_and_click (HWND hwnd) | |||||
{ | |||||
#ifndef HAVE_W32CE_SYSTEM | |||||
RECT rect; | |||||
HDC hdc; | |||||
int wscreen, hscreen, x, y, normx, normy; | |||||
INPUT inp[3]; | |||||
int idx; | |||||
hdc = GetDC (hwnd); | |||||
wscreen = GetDeviceCaps (hdc, HORZRES); | |||||
hscreen = GetDeviceCaps (hdc, VERTRES); | |||||
ReleaseDC (hwnd, hdc); | |||||
if (wscreen < 10 || hscreen < 10) | |||||
return; | |||||
GetWindowRect (hwnd, &rect); | |||||
x = rect.left; | |||||
y = rect.bottom; | |||||
normx = x * (65535 / wscreen); | |||||
if (normx < 0 || normx > 65535) | |||||
return; | |||||
normy = y * (65535 / hscreen); | |||||
if (normy < 0 || normy > 65535) | |||||
return; | |||||
for (idx=0; idx < 3; idx++) | |||||
memset (&inp[idx], 0, sizeof inp[idx]); | |||||
idx=0; | |||||
inp[idx].type = INPUT_MOUSE; | |||||
inp[idx].mi.dx = normx; | |||||
inp[idx].mi.dy = normy; | |||||
inp[idx].mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE; | |||||
idx++; | |||||
inp[idx].type = INPUT_MOUSE; | |||||
inp[idx].mi.dwFlags = MOUSEEVENTF_LEFTDOWN; | |||||
idx++; | |||||
inp[idx].type = INPUT_MOUSE; | |||||
inp[idx].mi.dwFlags = MOUSEEVENTF_LEFTUP; | |||||
idx++; | |||||
if ( (SendInput (idx, inp, sizeof (INPUT)) != idx) && debugfp) | |||||
fprintf (debugfp, "SendInput failed: %s\n", w32_strerror (-1)); | |||||
#endif | |||||
} | |||||
/* Resize the button so that STRING fits into it. */ | /* Resize the button so that STRING fits into it. */ | ||||
static void | static void | ||||
resize_button (HWND hwnd, const char *string) | resize_button (HWND hwnd, const char *string) | ||||
Context not available. | |||||
if (!hwnd) | if (!hwnd) | ||||
return; | return; | ||||
(void)string; | |||||
/* FIXME: Need to figure out how to convert dialog coorddnates to | /* FIXME: Need to figure out how to convert dialog coorddnates to | ||||
screen coordinates and how buttons should be placed. */ | screen coordinates and how buttons should be placed. */ | ||||
/* SetWindowPos (hbutton, NULL, */ | /* SetWindowPos (hbutton, NULL, */ | ||||
Context not available. | |||||
/* Dialog processing loop. */ | /* Dialog processing loop. */ | ||||
static BOOL CALLBACK | static INT_PTR CALLBACK | ||||
dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) | dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) | ||||
{ | { | ||||
static pinentry_t pe; | static pinentry_t pe; | ||||
Context not available. | |||||
center_window (dlg, HWND_TOP); | center_window (dlg, HWND_TOP); | ||||
/* Unfortunately we can't use SetForegroundWindow because there | |||||
is no easy eay to have all the calling processes do an | |||||
AllowSetForegroundWindow. What we do instead is to bad hack | |||||
by simulating a click to the Window. */ | |||||
/* if (SetForegroundWindow (dlg) && lock_set_foreground_window) */ | |||||
/* { */ | |||||
/* lock_set_foreground_window (LSFW_LOCK); */ | |||||
/* } */ | |||||
/* show_window_hierarchy (GetDesktopWindow (), 0); */ | /* show_window_hierarchy (GetDesktopWindow (), 0); */ | ||||
ShowWindow (dlg, SW_SHOW); | |||||
move_mouse_and_click ( GetDlgItem (dlg, IDC_PINENT_PROMPT) ); | |||||
raise_sip (dlg); | raise_sip (dlg); | ||||
break; | break; | ||||
Context not available. | |||||
static int | static int | ||||
w32_cmd_handler (pinentry_t pe) | w32_cmd_handler (pinentry_t pe) | ||||
{ | { | ||||
/* HWND lastwindow = GetForegroundWindow (); */ | |||||
confirm_mode = !pe->pin; | confirm_mode = !pe->pin; | ||||
passphrase_ok = confirm_yes = 0; | passphrase_ok = confirm_yes = 0; | ||||
Context not available. | |||||
dialog_handle = NULL; | dialog_handle = NULL; | ||||
DialogBoxParam (GetModuleHandle (NULL), MAKEINTRESOURCE (IDD_PINENT), | DialogBoxParam (GetModuleHandle (NULL), MAKEINTRESOURCE (IDD_PINENT), | ||||
GetDesktopWindow (), dlg_proc, (LPARAM)pe); | GetDesktopWindow (), dlg_proc, (LPARAM)pe); | ||||
if (dialog_handle) | if (!dialog_handle) | ||||
{ | |||||
/* if (lock_set_foreground_window) */ | |||||
/* lock_set_foreground_window (LSFW_UNLOCK); */ | |||||
/* if (lastwindow) */ | |||||
/* SetForegroundWindow (lastwindow); */ | |||||
} | |||||
else | |||||
return -1; | return -1; | ||||
if (confirm_mode) | if (confirm_mode) | ||||
Context not available. | |||||
int | int | ||||
main (int argc, char **argv) | main (int argc, char **argv) | ||||
{ | { | ||||
#ifndef HAVE_W32CE_SYSTEM | |||||
void *handle; | |||||
#endif | |||||
w32_infd = STDIN_FILENO; | w32_infd = STDIN_FILENO; | ||||
w32_outfd = STDOUT_FILENO; | w32_outfd = STDOUT_FILENO; | ||||
Context not available. | |||||
/* if (!debugfp) */ | /* if (!debugfp) */ | ||||
/* debugfp = stderr; */ | /* debugfp = stderr; */ | ||||
/* We need to load a function because that one is only available | |||||
since W2000 but not in older NTs. */ | |||||
#ifndef HAVE_W32CE_SYSTEM | |||||
handle = LoadLibrary ("user32.dll"); | |||||
if (handle) | |||||
{ | |||||
void *foo; | |||||
foo = GetProcAddress (handle, "LockSetForegroundWindow"); | |||||
if (foo) | |||||
lock_set_foreground_window = foo; | |||||
else | |||||
CloseHandle (handle); | |||||
} | |||||
#endif | |||||
if (pinentry_loop2 (w32_infd, w32_outfd)) | if (pinentry_loop2 (w32_infd, w32_outfd)) | ||||
return 1; | return 1; | ||||
Context not available. |