2002-02-28 14:26:23 +00:00
|
|
|
#include "wxinc.h"
|
|
|
|
|
|
|
|
#include "oswin32.h"
|
|
|
|
|
2002-10-24 10:47:49 +00:00
|
|
|
#include "xvt_menu.h"
|
|
|
|
#include "xvt_help.h"
|
|
|
|
|
2002-02-28 14:26:23 +00:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#define WIN32_EXTRA_LEAN
|
|
|
|
#define STRICT
|
|
|
|
#include <windows.h>
|
|
|
|
#include <winspool.h>
|
2002-10-24 10:47:49 +00:00
|
|
|
#include <shellapi.h>
|
2002-02-28 14:26:23 +00:00
|
|
|
|
2002-07-03 14:53:33 +00:00
|
|
|
bool OsWin32_CheckPrinterInfo(const void* data, unsigned int size)
|
2002-02-28 14:26:23 +00:00
|
|
|
{
|
|
|
|
bool ok = data != NULL;
|
|
|
|
if (ok)
|
|
|
|
{
|
|
|
|
LPDEVMODE pdm = (LPDEVMODE)data;
|
2002-07-03 14:53:33 +00:00
|
|
|
const unsigned int s = pdm->dmSize + pdm->dmDriverExtra;
|
|
|
|
ok = s > 0 && s == size;
|
2002-02-28 14:26:23 +00:00
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2002-07-03 14:53:33 +00:00
|
|
|
void* OsWin32_ConvertFromNativePrinterInfo(void* hGlobal, unsigned int& nDataSize)
|
2002-02-28 14:26:23 +00:00
|
|
|
{
|
|
|
|
void* ptr = ::GlobalLock(hGlobal);
|
|
|
|
PDEVMODE dm = (PDEVMODE)ptr;
|
2002-07-03 14:53:33 +00:00
|
|
|
nDataSize = dm->dmSize+dm->dmDriverExtra;
|
|
|
|
void* buff = new char[nDataSize];
|
|
|
|
memcpy(buff, ptr, nDataSize);
|
2002-02-28 14:26:23 +00:00
|
|
|
::GlobalUnlock(hGlobal);
|
2002-07-03 14:53:33 +00:00
|
|
|
return buff;
|
2002-02-28 14:26:23 +00:00
|
|
|
}
|
|
|
|
|
2002-07-03 14:53:33 +00:00
|
|
|
void* OsWin32_ConvertToNativePrinterInfo(void* data, unsigned int nDataSize)
|
2002-02-28 14:26:23 +00:00
|
|
|
{
|
2002-07-03 14:53:33 +00:00
|
|
|
HGLOBAL hGlobal = ::GlobalAlloc(GHND, nDataSize);
|
2002-02-28 14:26:23 +00:00
|
|
|
void* ptr = ::GlobalLock(hGlobal);
|
2002-07-03 14:53:33 +00:00
|
|
|
memcpy(ptr, data, nDataSize);
|
2002-02-28 14:26:23 +00:00
|
|
|
::GlobalUnlock(hGlobal);
|
|
|
|
return hGlobal;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct XvtData
|
|
|
|
{
|
|
|
|
char** families;
|
|
|
|
long* sizes;
|
2002-07-03 14:53:33 +00:00
|
|
|
short* scalable;
|
2002-02-28 14:26:23 +00:00
|
|
|
long max_count;
|
|
|
|
long cur_count;
|
|
|
|
|
|
|
|
XvtData() { memset(this, 0, sizeof(XvtData)); }
|
|
|
|
};
|
|
|
|
|
|
|
|
int CALLBACK FamilyEnumerator(
|
|
|
|
const LOGFONT *plf, // pointer to logical-font data
|
|
|
|
const TEXTMETRIC *lpntme, // pointer to physical-font data
|
|
|
|
unsigned long FontType, // type of font
|
|
|
|
LPARAM lParam // application-defined data
|
|
|
|
)
|
|
|
|
{
|
|
|
|
XvtData* d = (XvtData*)lParam;
|
|
|
|
d->families[d->cur_count++] = strdup(plf->lfFaceName);
|
|
|
|
return d->cur_count < d->max_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CALLBACK SizeEnumerator(
|
|
|
|
const LOGFONT *plf, // pointer to logical-font data
|
|
|
|
const TEXTMETRIC *lpntme, // pointer to physical-font data
|
|
|
|
unsigned long FontType, // type of font
|
|
|
|
LPARAM lParam // application-defined data
|
|
|
|
)
|
|
|
|
{
|
|
|
|
XvtData* d = (XvtData*)lParam;
|
|
|
|
long& i = d->cur_count;
|
|
|
|
const int size = (plf->lfHeight+5) / 10;
|
|
|
|
if (i == 0 || size > d->sizes[i-1])
|
|
|
|
{
|
|
|
|
d->sizes[i] = size;
|
2002-07-03 14:53:33 +00:00
|
|
|
if (lpntme->tmPitchAndFamily & TMPF_TRUETYPE)
|
|
|
|
*d->scalable = TRUE;
|
2002-02-28 14:26:23 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return i < d->max_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
int FamilySorter(const void* p1,const void* p2)
|
|
|
|
{
|
|
|
|
const char* s1 = *(const char**)p1;
|
|
|
|
const char* s2 = *(const char**)p2;
|
|
|
|
return strcmp(s1, s2);
|
|
|
|
}
|
|
|
|
|
|
|
|
int OsWin32_EnumerateFamilies(unsigned int hDC, char** families, int max_count)
|
|
|
|
{
|
|
|
|
XvtData data;
|
|
|
|
data.families = families;
|
|
|
|
data.max_count = max_count;
|
|
|
|
LOGFONT lf; memset(&lf, 0, sizeof(lf));
|
|
|
|
::EnumFontFamiliesEx((HDC)hDC, &lf, FamilyEnumerator, (LPARAM)&data, 0);
|
|
|
|
qsort(families, data.cur_count, sizeof(char*), FamilySorter);
|
|
|
|
return data.cur_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
int OsWin32_EnumerateSizes(unsigned int hDC, const char* name, long* sizes, short* scalable, int max_count)
|
|
|
|
{
|
|
|
|
XvtData data;
|
|
|
|
data.sizes = sizes;
|
|
|
|
data.scalable = scalable;
|
|
|
|
data.max_count = max_count;
|
|
|
|
LOGFONT lf; memset(&lf, 0, sizeof(lf));
|
|
|
|
strcpy(lf.lfFaceName, name);
|
|
|
|
::EnumFontFamiliesEx((HDC)hDC, &lf, SizeEnumerator, (LPARAM)&data, 0);
|
|
|
|
|
|
|
|
return data.cur_count;
|
|
|
|
}
|
|
|
|
|
2002-07-03 14:53:33 +00:00
|
|
|
void* OsWin32_GetPrinterInfo(int& size, const char* printer)
|
2002-02-28 14:26:23 +00:00
|
|
|
{
|
2002-07-03 14:53:33 +00:00
|
|
|
char name[256];
|
|
|
|
|
|
|
|
size = 0;
|
|
|
|
if (printer == NULL || *printer == '\0')
|
|
|
|
{
|
|
|
|
if (::GetProfileString("windows", "device", ",,,", name, sizeof(name)) == 0)
|
|
|
|
return NULL;
|
|
|
|
char* comma = strchr(name, ',');
|
|
|
|
if (comma) *comma = '\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
strcpy(name, printer);
|
2002-02-28 14:26:23 +00:00
|
|
|
|
2003-02-05 14:26:24 +00:00
|
|
|
LPDEVMODE pdm = NULL;
|
2002-02-28 14:26:23 +00:00
|
|
|
HANDLE hPrinter;
|
2003-02-05 14:26:24 +00:00
|
|
|
if (::OpenPrinter(name, &hPrinter, NULL) != 0)
|
|
|
|
{
|
|
|
|
size = ::DocumentProperties(0, hPrinter, name, NULL, NULL, 0); // Determina dimensione DEVMODE
|
|
|
|
if (size > 0)
|
|
|
|
{
|
|
|
|
pdm = (LPDEVMODE) new char[size]; // Alloca un DEVMODE sufficientemente capiente
|
|
|
|
::DocumentProperties(0, hPrinter, name, pdm, NULL, DM_OUT_BUFFER); // Legge DEVMODE
|
|
|
|
}
|
|
|
|
else
|
|
|
|
size = 0;
|
|
|
|
::ClosePrinter(hPrinter);
|
|
|
|
}
|
2002-07-03 14:53:33 +00:00
|
|
|
return pdm;
|
2002-02-28 14:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OsWin32_SetCaptionStyle(unsigned int handle, bool set)
|
|
|
|
{
|
|
|
|
HWND hwnd = (HWND)handle;
|
|
|
|
DWORD s = ::GetWindowLong(hwnd, GWL_STYLE);
|
|
|
|
if (set)
|
|
|
|
s |= WS_CAPTION;
|
|
|
|
else
|
|
|
|
s &= ~WS_CAPTION;
|
|
|
|
#if !wxCHECK_VERSION(2,3,2)
|
|
|
|
s |= WS_CLIPSIBLINGS;
|
|
|
|
#endif
|
|
|
|
::SetWindowLong(hwnd, GWL_STYLE, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OsWin32_SetClippingRect(unsigned int hDC, int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
HDC hdc = (HDC)hDC;
|
|
|
|
if (w > 0 && h > 0)
|
|
|
|
{
|
|
|
|
HRGN hrgn = ::CreateRectRgn(x, y, x+w, y+h);
|
|
|
|
::SelectClipRgn(hdc, hrgn);
|
|
|
|
::DeleteObject(hrgn);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
::SelectClipRgn(hdc, NULL);
|
|
|
|
}
|
|
|
|
|
2002-07-03 14:53:33 +00:00
|
|
|
void OsWin32_UpdateWindow(unsigned int handle)
|
|
|
|
{
|
|
|
|
HWND hwnd = (HWND)handle;
|
|
|
|
::UpdateWindow(hwnd);
|
|
|
|
}
|
|
|
|
|
2002-02-28 14:26:23 +00:00
|
|
|
void OsWin32_StretchBlt(unsigned int hDst, int xd, int yd, int wd, int hd,
|
|
|
|
unsigned int hSrc, int xs, int ys, int ws, int hs)
|
|
|
|
{
|
2002-07-03 14:53:33 +00:00
|
|
|
const int nColors = ::GetDeviceCaps((HDC)hDst, NUMCOLORS);
|
|
|
|
::SetStretchBltMode((HDC)hDst, nColors == 2 ? STRETCH_HALFTONE : STRETCH_DELETESCANS);
|
2002-02-28 14:26:23 +00:00
|
|
|
::StretchBlt((HDC)hDst, xd, yd, wd, hd, (HDC)hSrc, xs, ys, ws, hs, SRCCOPY);
|
|
|
|
}
|
|
|
|
|
2002-07-03 14:53:33 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Drawing bitmaps
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void OsWin32_DrawBitmap(unsigned int hBitmap, unsigned int hDC,
|
|
|
|
int xd, int yd, int wd, int hd,
|
|
|
|
int xs, int ys, int ws, int hs)
|
2002-02-28 14:26:23 +00:00
|
|
|
{
|
2002-07-03 14:53:33 +00:00
|
|
|
const int nTechno = ::GetDeviceCaps((HDC)hDC, TECHNOLOGY);
|
|
|
|
if (nTechno == DT_RASPRINTER) // Sto stampando!
|
|
|
|
{
|
|
|
|
BITMAPINFO bi; memset(&bi, 0, sizeof(bi));
|
|
|
|
BITMAPINFOHEADER& bih = bi.bmiHeader;
|
|
|
|
bih.biSize = sizeof(bih);
|
|
|
|
HDC hMemDC = ::CreateCompatibleDC(NULL);
|
|
|
|
GetDIBits(hMemDC, (HBITMAP)hBitmap, 0, 0, NULL, &bi, DIB_RGB_COLORS);
|
|
|
|
if (bih.biSizeImage > 0)
|
|
|
|
{
|
|
|
|
LPBYTE bits = new BYTE[bih.biSizeImage];
|
|
|
|
::GetDIBits(hMemDC, (HBITMAP)hBitmap, 0, bih.biHeight,
|
|
|
|
bits, &bi, DIB_RGB_COLORS);
|
|
|
|
::StretchDIBits((HDC)hDC, xd, yd, wd, hd, xs, ys, ws, hs,
|
|
|
|
bits, &bi, DIB_RGB_COLORS, SRCCOPY);
|
|
|
|
delete bits;
|
|
|
|
}
|
|
|
|
::DeleteDC(hMemDC);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HDC hMemDC = ::CreateCompatibleDC((HDC)hDC);
|
|
|
|
HGDIOBJ hOldBitmap = ::SelectObject(hMemDC, (HBITMAP)hBitmap);
|
|
|
|
::SetStretchBltMode((HDC)hDC, STRETCH_DELETESCANS);
|
|
|
|
::StretchBlt((HDC)hDC, xd, yd, wd, hd, hMemDC, xs, ys, ws, hs, SRCCOPY);
|
|
|
|
::SelectObject(hMemDC, hOldBitmap);
|
|
|
|
::DeleteDC(hMemDC);
|
|
|
|
}
|
2002-02-28 14:26:23 +00:00
|
|
|
}
|
|
|
|
|
2003-02-25 15:22:52 +00:00
|
|
|
void OsWin32_DrawDottedRect(unsigned int hDC, int left, int top, int right, int bottom)
|
|
|
|
{
|
|
|
|
LOGBRUSH lBrush; lBrush.lbHatch = 0; lBrush.lbStyle = BS_SOLID;
|
|
|
|
lBrush.lbColor = ::GetTextColor((HDC)hDC);
|
|
|
|
HPEN hPen = ::ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lBrush, 0, NULL);
|
|
|
|
HGDIOBJ hOldPen = ::SelectObject((HDC)hDC, hPen);
|
|
|
|
HGDIOBJ hBrush = ::GetStockObject(HOLLOW_BRUSH);
|
|
|
|
HGDIOBJ hOldBrush = ::SelectObject((HDC)hDC, hBrush);
|
|
|
|
::Rectangle((HDC)hDC, left, top, right, bottom);
|
|
|
|
::SelectObject((HDC)hDC, hOldBrush);
|
|
|
|
::SelectObject((HDC)hDC, hOldPen);
|
|
|
|
::DeleteObject(hPen);
|
|
|
|
}
|
|
|
|
|
2002-09-13 14:56:23 +00:00
|
|
|
void OsWin32_Beep(int severity)
|
|
|
|
{
|
|
|
|
switch (severity)
|
|
|
|
{
|
2003-02-25 15:22:52 +00:00
|
|
|
case 0: ::MessageBeep(MB_OK); break;
|
|
|
|
case 1: ::MessageBeep(MB_ICONEXCLAMATION); break;
|
|
|
|
default: ::MessageBeep(MB_ICONSTOP); break;
|
2002-09-13 14:56:23 +00:00
|
|
|
}
|
|
|
|
}
|
2002-10-24 10:47:49 +00:00
|
|
|
|
|
|
|
int OsWin32_Help(unsigned int handle, const char* hlp, unsigned int cmd, const char* topic)
|
|
|
|
{
|
|
|
|
HWND hwnd = (HWND)handle;
|
|
|
|
|
|
|
|
switch(cmd)
|
|
|
|
{
|
|
|
|
case M_HELP_CONTENTS:
|
|
|
|
::WinHelp(hwnd, hlp, HELP_CONTENTS, 0);
|
|
|
|
break;
|
|
|
|
case M_HELP_SEARCH:
|
|
|
|
::WinHelp(hwnd, hlp, HELP_PARTIALKEY, (DWORD)"");
|
|
|
|
break;
|
|
|
|
case M_HELP_HELPONHELP:
|
|
|
|
::WinHelp(hwnd, hlp, HELP_HELPONHELP, 0);
|
|
|
|
break;
|
|
|
|
case M_HELP_ONCONTEXT:
|
|
|
|
if (topic != NULL)
|
|
|
|
{
|
|
|
|
struct MULTIGUY
|
|
|
|
{
|
|
|
|
DWORD mkSize;
|
|
|
|
TCHAR mkKeylist;
|
|
|
|
TCHAR mkKeyphrase[16];
|
|
|
|
} mk;
|
|
|
|
|
|
|
|
mk.mkSize = sizeof(MULTIGUY);
|
|
|
|
mk.mkKeylist = 'M';
|
|
|
|
strncpy(mk.mkKeyphrase, topic, sizeof(mk.mkKeyphrase));
|
|
|
|
::WinHelp(hwnd, hlp, HELP_MULTIKEY, (DWORD)&mk);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
::WinHelp(hwnd, hlp, HELP_QUIT, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-04-01 07:34:53 +00:00
|
|
|
|
|
|
|
bool OsWin32_TestNetworkVersion()
|
|
|
|
{
|
|
|
|
// Win95 only!
|
|
|
|
char* VREDIRNAME = "vredir.vxd";
|
|
|
|
DWORD handle;
|
|
|
|
|
|
|
|
DWORD dwSize = ::GetFileVersionInfoSize(VREDIRNAME,&handle);
|
|
|
|
if (dwSize)
|
|
|
|
{
|
|
|
|
BYTE infoBuffer[512];
|
|
|
|
GetFileVersionInfo(VREDIRNAME,handle,dwSize,infoBuffer);
|
|
|
|
long *language;
|
|
|
|
void * lpBuffer;
|
|
|
|
UINT Size;
|
|
|
|
if (VerQueryValue(infoBuffer, "\\VarFileInfo\\Translation", (void **)&language, &Size) && Size!=0)
|
|
|
|
{
|
|
|
|
char szName[128];
|
|
|
|
sprintf(szName, "\\StringFileInfo\\%04x%04x\\FileVersion",LOWORD(*language), HIWORD(*language));
|
|
|
|
if (VerQueryValue(infoBuffer, szName, &lpBuffer, &Size) && Size!=0)
|
|
|
|
{
|
|
|
|
const char* s = (const char *)lpBuffer;
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
s = strchr(s, '.')+1;
|
|
|
|
int subver=atoi(s);
|
|
|
|
if (subver >= 1111 && subver <= 1115)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|