Mercurial > dwindows
comparison win/dw.c @ 1887:09860ba329a4
Divided thread initialization and deinitialization into separate
exported functions so they can be accessed from language bindings.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 09 Sep 2013 19:18:36 +0000 |
parents | f7d408a47752 |
children | cb5f9aa9aebb |
comparison
equal
deleted
inserted
replaced
1886:f7d408a47752 | 1887:09860ba329a4 |
---|---|
3759 } | 3759 } |
3760 return windowtype; | 3760 return windowtype; |
3761 } | 3761 } |
3762 #endif | 3762 #endif |
3763 | 3763 |
3764 /* Initialize thread local values to the defaults */ | |
3765 void _init_thread(void) | |
3766 { | |
3767 COLORREF foreground = RGB(128,128,128); | |
3768 COLORREF background = DW_RGB_TRANSPARENT; | |
3769 #ifdef GDIPLUS | |
3770 ARGB gpfore = MAKEARGB(255, 128, 128, 128); | |
3771 GpBrush *brush; | |
3772 GpPen *pen; | |
3773 | |
3774 GdipCreatePen1(gpfore, 1.0, UnitPixel, &pen); | |
3775 TlsSetValue(_gpPen, (LPVOID)pen); | |
3776 GdipCreateSolidFill(gpfore, &brush); | |
3777 TlsSetValue(_gpBrush, brush); | |
3778 #endif | |
3779 TlsSetValue(_foreground, DW_UINT_TO_POINTER(foreground)); | |
3780 TlsSetValue(_background, DW_UINT_TO_POINTER(background)); | |
3781 TlsSetValue(_hPen, CreatePen(PS_SOLID, 1, foreground)); | |
3782 TlsSetValue(_hBrush, CreateSolidBrush(foreground)); | |
3783 } | |
3784 | |
3785 /* | 3764 /* |
3786 * Initializes the Dynamic Windows engine. | 3765 * Initializes the Dynamic Windows engine. |
3787 * Parameters: | 3766 * Parameters: |
3788 * newthread: True if this is the only thread. | 3767 * newthread: True if this is the only thread. |
3789 * False if there is already a message loop running. | 3768 * False if there is already a message loop running. |
3976 si.SuppressBackgroundThread = FALSE; | 3955 si.SuppressBackgroundThread = FALSE; |
3977 si.SuppressExternalCodecs = FALSE; | 3956 si.SuppressExternalCodecs = FALSE; |
3978 GdiplusStartup(&gdiplusToken, &si, NULL); | 3957 GdiplusStartup(&gdiplusToken, &si, NULL); |
3979 #endif | 3958 #endif |
3980 | 3959 |
3981 /* GDI+ Needs to be initialized before calling _init_thread(); */ | 3960 /* GDI+ Needs to be initialized before calling _dw_init_thread(); */ |
3982 _init_thread(); | 3961 _dw_init_thread(); |
3983 | 3962 |
3984 if((huxtheme = LoadLibrary(TEXT("uxtheme")))) | 3963 if((huxtheme = LoadLibrary(TEXT("uxtheme")))) |
3985 _SetWindowTheme = (HRESULT (WINAPI *)(HWND, LPCWSTR, LPCWSTR ))GetProcAddress(huxtheme, "SetWindowTheme"); | 3964 _SetWindowTheme = (HRESULT (WINAPI *)(HWND, LPCWSTR, LPCWSTR ))GetProcAddress(huxtheme, "SetWindowTheme"); |
3986 #ifdef AEROGLASS | 3965 #ifdef AEROGLASS |
3987 /* Attempt to load the Desktop Window Manager and Theme library */ | 3966 /* Attempt to load the Desktop Window Manager and Theme library */ |
11383 UnmapViewOfFile(ptr); | 11362 UnmapViewOfFile(ptr); |
11384 CloseHandle(handle); | 11363 CloseHandle(handle); |
11385 return 0; | 11364 return 0; |
11386 } | 11365 } |
11387 | 11366 |
11388 /* | 11367 /* |
11389 * Encapsulate thread creation on Win32. | 11368 * Generally an internal function called from a newly created |
11390 */ | 11369 * thread to setup the Dynamic Windows environment for the thread. |
11391 void _dwthreadstart(void *data) | 11370 * However it is exported so language bindings can call it when |
11392 { | 11371 * they create threads that require access to Dynamic Windows. |
11393 void (* threadfunc)(void *) = NULL; | 11372 */ |
11394 void **tmp = (void **)data; | 11373 void API _dw_init_thread(void) |
11374 { | |
11375 COLORREF foreground = RGB(128,128,128); | |
11376 COLORREF background = DW_RGB_TRANSPARENT; | |
11377 #ifdef GDIPLUS | |
11378 ARGB gpfore = MAKEARGB(255, 128, 128, 128); | |
11379 GpBrush *brush; | |
11380 GpPen *pen; | |
11381 | |
11382 GdipCreatePen1(gpfore, 1.0, UnitPixel, &pen); | |
11383 TlsSetValue(_gpPen, (LPVOID)pen); | |
11384 GdipCreateSolidFill(gpfore, &brush); | |
11385 TlsSetValue(_gpBrush, brush); | |
11386 #endif | |
11387 TlsSetValue(_foreground, DW_UINT_TO_POINTER(foreground)); | |
11388 TlsSetValue(_background, DW_UINT_TO_POINTER(background)); | |
11389 TlsSetValue(_hPen, CreatePen(PS_SOLID, 1, foreground)); | |
11390 TlsSetValue(_hBrush, CreateSolidBrush(foreground)); | |
11391 } | |
11392 | |
11393 /* | |
11394 * Generally an internal function called from a terminating | |
11395 * thread to cleanup the Dynamic Windows environment for the thread. | |
11396 * However it is exported so language bindings can call it when | |
11397 * they exit threads that require access to Dynamic Windows. | |
11398 */ | |
11399 void API _dw_deinit_thread(void) | |
11400 { | |
11395 HPEN hPen; | 11401 HPEN hPen; |
11396 HBRUSH hBrush; | 11402 HBRUSH hBrush; |
11397 #ifdef GDIPLUS | 11403 #ifdef GDIPLUS |
11398 GpBrush *brush; | 11404 GpBrush *brush; |
11399 GpPen *pen; | 11405 GpPen *pen; |
11400 #endif | 11406 #endif |
11401 | 11407 |
11402 _init_thread(); | |
11403 | |
11404 threadfunc = (void (*)(void *))tmp[0]; | |
11405 threadfunc(tmp[1]); | |
11406 | |
11407 free(tmp); | |
11408 if((hPen = TlsGetValue(_hPen))) | 11408 if((hPen = TlsGetValue(_hPen))) |
11409 DeleteObject(hPen); | 11409 DeleteObject(hPen); |
11410 if((hBrush = TlsGetValue(_hBrush))) | 11410 if((hBrush = TlsGetValue(_hBrush))) |
11411 DeleteObject(hBrush); | 11411 DeleteObject(hBrush); |
11412 #ifdef GDIPLUS | 11412 #ifdef GDIPLUS |
11413 if((brush = TlsGetValue(_gpBrush))) | 11413 if((brush = TlsGetValue(_gpBrush))) |
11414 GdipDeleteBrush(brush); | 11414 GdipDeleteBrush(brush); |
11415 if((pen = TlsGetValue(_gpPen))) | 11415 if((pen = TlsGetValue(_gpPen))) |
11416 GdipDeletePen(pen); | 11416 GdipDeletePen(pen); |
11417 #endif | 11417 #endif |
11418 } | |
11419 | |
11420 /* | |
11421 * Encapsulate thread creation on Win32. | |
11422 */ | |
11423 void _dwthreadstart(void *data) | |
11424 { | |
11425 void (* threadfunc)(void *) = NULL; | |
11426 void **tmp = (void **)data; | |
11427 | |
11428 _dw_init_thread(); | |
11429 | |
11430 threadfunc = (void (*)(void *))tmp[0]; | |
11431 threadfunc(tmp[1]); | |
11432 | |
11433 free(tmp); | |
11434 _dw_deinit_thread(); | |
11418 } | 11435 } |
11419 | 11436 |
11420 /* | 11437 /* |
11421 * Creates a new thread with a starting point of func. | 11438 * Creates a new thread with a starting point of func. |
11422 * Parameters: | 11439 * Parameters: |