campo-sirio/xvaga/oswin32.cpp
guy b3b79ff0d8 Patch level : 1.32
Files correlati     : Tutti
Ricompilazione Demo : [ ]
Commento            :
Hello 32 bits world!


git-svn-id: svn://10.65.10.50/trunk@10098 c028cbd2-c16b-5b4b-a496-9718f37d4682
2002-02-28 14:26:23 +00:00

178 lines
4.1 KiB
C++
Executable File

#include "wxinc.h"
#include "oswin32.h"
#define WIN32_LEAN_AND_MEAN
#define WIN32_EXTRA_LEAN
#define STRICT
#include <windows.h>
#include <winspool.h>
bool OsWin32_CheckPrinterInfo(const void* data)
{
bool ok = data != NULL;
if (ok)
{
LPDEVMODE pdm = (LPDEVMODE)data;
const int s = pdm->dmSize + pdm->dmDriverExtra;
ok = s > 0;
}
return ok;
}
void* OsWin32_ConvertFromNativePrinterInfo(void* hGlobal)
{
void* data = new char[1024]; memset(data, 0, 1024);
void* ptr = ::GlobalLock(hGlobal);
PDEVMODE dm = (PDEVMODE)ptr;
const int size = dm->dmSize+dm->dmDriverExtra;
memcpy(data, ptr, size);
::GlobalUnlock(hGlobal);
return data;
}
void* OsWin32_ConvertToNativePrinterInfo(void* data)
{
HGLOBAL hGlobal = ::GlobalAlloc(GHND, 1024);
void* ptr = ::GlobalLock(hGlobal);
memcpy(ptr, data, 1024);
::GlobalUnlock(hGlobal);
return hGlobal;
}
#include <math.h>
struct XvtData
{
char** families;
long* sizes;
short* scalable;
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;
*d->scalable = (plf->lfPitchAndFamily & VARIABLE_PITCH) != 0;
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;
}
int OsWin32_GetDefaultPrinterInfo(void* data, int max_size)
{
char name[80];
if (GetProfileString ("windows", "device", ",,,", name, sizeof(name)) == 0)
return 0;
char* comma = strchr(name, ',');
if (comma) *comma = '\0';
LPDEVMODE pdm = (LPDEVMODE)data;
HANDLE hPrinter;
if (::OpenPrinter(name, &hPrinter, NULL) == 0)
return 0;
::DocumentProperties(0, hPrinter, name, pdm, NULL, DM_OUT_BUFFER);
::ClosePrinter(hPrinter);
const int size = pdm->dmSize + pdm->dmDriverExtra;
return size;
}
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);
}
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)
{
::StretchBlt((HDC)hDst, xd, yd, wd, hd, (HDC)hSrc, xs, ys, ws, hs, SRCCOPY);
}
void OsWin32_UpdateWindow(unsigned int handle)
{
HWND hwnd = (HWND)handle;
::UpdateWindow(hwnd);
}