diff --git a/src/filesel.c b/src/filesel.c index 5493984f..e2747eed 100644 --- a/src/filesel.c +++ b/src/filesel.c @@ -25,10 +25,6 @@ along with Grafx2; if not, see */ -#if defined(USE_SDL) || defined(USE_SDL2) -#include -#endif - #if defined(__amigaos4__) || defined(__AROS__) || defined(__MORPHOS__) || defined(__amigaos__) #include #include @@ -95,21 +91,11 @@ byte Native_filesel(byte load) #if WIN32 OPENFILENAME ofn; char szFileName[MAX_PATH] = ""; - HWND hwnd; -#if defined(USE_SDL) || defined(USE_SDL2) - SDL_SysWMinfo wminfo; - - SDL_VERSION(&wminfo.version); - SDL_GetWMInfo(&wminfo); - hwnd = wminfo.window; -#else - hwnd = GetActiveWindow(); -#endif ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); - ofn.hwndOwner = hwnd; + ofn.hwndOwner = GFX2_Get_Window_Handle(); ofn.lpstrFilter = TEXT("Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"); #ifdef UNICODE #else diff --git a/src/init.c b/src/init.c index 99322abe..061ee510 100644 --- a/src/init.c +++ b/src/init.c @@ -52,9 +52,6 @@ #if defined(WIN32) #include // GetLogicalDrives(), GetDriveType(), DRIVE_* #endif -#if !defined(__GP2X__) && defined(USE_SDL) - #include -#endif #if defined (__MINT__) #include #endif @@ -85,6 +82,7 @@ #include "mountlist.h" // read_file_system_list #include "operatio.h" #include "palette.h" +#include "screen.h" #if defined(USE_SDL) || defined(USE_SDL2) #include "sdlscreen.h" #endif @@ -3112,9 +3110,6 @@ void Define_icon(void) LPVOID lpResIcon32; HGLOBAL hMem; WORD nID; -#if defined(USE_SDL) || defined(USE_SDL2) - SDL_SysWMinfo info; -#endif hInstance = (HINSTANCE)GetModuleHandle(NULL); if (hInstance==NULL) @@ -3136,11 +3131,6 @@ void Define_icon(void) if (lpResIconDir==NULL) break; -#if defined(USE_SDL) || defined(USE_SDL2) - SDL_VERSION(&info.version); - SDL_GetWMInfo(&info); -#endif - // // 16x16 // @@ -3175,7 +3165,7 @@ void Define_icon(void) // Set it #if defined(USE_SDL) || defined(USE_SDL2) - SetClassLongPtr(info.window, GCL_HICONSM, (LONG_PTR)hicon); + SetClassLongPtr(GFX2_Get_Window_Handle(), GCL_HICONSM, (LONG_PTR)hicon); #else // TODO #endif @@ -3215,7 +3205,7 @@ void Define_icon(void) // Set it #if defined(USE_SDL) || defined(USE_SDL2) - SetClassLongPtr(info.window, GCL_HICON, (LONG_PTR)hicon); + SetClassLongPtr(GFX2_Get_Window_Handle(), GCL_HICON, (LONG_PTR)hicon); #else // TODO #endif diff --git a/src/main.c b/src/main.c index 845f7be4..d2fdd2aa 100644 --- a/src/main.c +++ b/src/main.c @@ -45,11 +45,18 @@ #if defined(USE_SDL) || defined(USE_SDL2) #include #include - -// There is no WM on the GP2X... -#if !defined(__GP2X__) && !defined(__WIZ__) && !defined(__CAANOO__) && !defined(GCWZERO) - #include #endif + +#if defined(WIN32) + #include + #include +#elif defined (__MINT__) + #include +#elif defined(__macosx__) + #import + #import +#elif defined(__FreeBSD__) + #include #endif #include "const.h" @@ -80,18 +87,6 @@ #include "win32screen.h" #endif -#if defined(WIN32) - #include - #include -#elif defined (__MINT__) - #include -#elif defined(__macosx__) - #import - #import -#elif defined(__FreeBSD__) - #include -#endif - #if defined (WIN32) && (defined(USE_SDL) || defined(USE_SDL2)) // On Windows, SDL_putenv is not present in any compilable header. @@ -859,11 +854,8 @@ int Init_program(int argc,char * argv[]) { //RECT r; #if defined(USE_SDL) || defined(USE_SDL2) - static SDL_SysWMinfo pInfo; - SDL_VERSION(&pInfo.version); - SDL_GetWMInfo(&pInfo); - //GetWindowRect(pInfo.window, &r); - SetWindowPos(pInfo.window, 0, Config.Window_pos_x, Config.Window_pos_y, 0, 0, SWP_NOSIZE); + //GetWindowRect(window, &r); + SetWindowPos(GFX2_Get_Window_Handle(), 0, Config.Window_pos_x, Config.Window_pos_y, 0, 0, SWP_NOSIZE); #endif } } @@ -1071,10 +1063,7 @@ void Program_shutdown(void) #if defined(USE_SDL) || defined(USE_SDL2) { RECT r; - static SDL_SysWMinfo pInfo; - - SDL_GetWMInfo(&pInfo); - GetWindowRect(pInfo.window, &r); + GetWindowRect(GFX2_Get_Window_Handle(), &r); Config.Window_pos_x = r.left; Config.Window_pos_y = r.top; diff --git a/src/readline.c b/src/readline.c index fedad71f..65740ab6 100644 --- a/src/readline.c +++ b/src/readline.c @@ -47,9 +47,6 @@ #ifdef WIN32 #include -#if defined(USE_SDL) -#include -#endif #elif defined __HAIKU__ #include "haiku.h" @@ -307,18 +304,7 @@ static char* getClipboard(word * * unicode) { #ifdef WIN32 char* dst = NULL; -#if defined(USE_SDL) || defined(USE_SDL2) - SDL_SysWMinfo info; - - SDL_VERSION(&info.version); - - if ( SDL_GetWMInfo(&info) ) - { - if (OpenClipboard(info.window) ) -#else - { - if (OpenClipboard(GetActiveWindow())) -#endif + if (OpenClipboard(GFX2_Get_Window_Handle())) { HANDLE hMem; if ( IsClipboardFormatAvailable(CF_TEXT) ) @@ -346,7 +332,6 @@ static char* getClipboard(word * * unicode) } CloseClipboard(); } - } return dst; #elif defined(__AROS__) diff --git a/src/screen.h b/src/screen.h index cfee6ca6..eecbde90 100644 --- a/src/screen.h +++ b/src/screen.h @@ -29,6 +29,9 @@ #ifndef SCREEN_H_INCLUDED #define SCREEN_H_INCLUDED +#ifdef WIN32 +#include // for HWND +#endif #include "struct.h" #include "global.h" @@ -63,4 +66,8 @@ void Allow_drag_and_drop(int flag); void GFX2_UpdateScreen(void); #endif +#if defined(WIN32) +HWND GFX2_Get_Window_Handle(void); +#endif + #endif // SCREEN_H_INCLUDED diff --git a/src/sdlscreen.c b/src/sdlscreen.c index 209f40c1..008ba863 100644 --- a/src/sdlscreen.c +++ b/src/sdlscreen.c @@ -502,18 +502,23 @@ void Clear_border(byte color) } } +#ifdef WIN32 +HWND GFX2_Get_Window_Handle(void) +{ + SDL_SysWMinfo wminfo; + + SDL_VERSION(&wminfo.version); + SDL_GetWMInfo(&wminfo); + return wminfo.window; +} +#endif + /// Activates or desactivates file drag-dropping in program window. void Allow_drag_and_drop(int flag) { // Inform Windows that we accept drag-n-drop events or not #ifdef __WIN32__ - SDL_SysWMinfo wminfo; - HWND hwnd; - - SDL_VERSION(&wminfo.version); - SDL_GetWMInfo(&wminfo); - hwnd = wminfo.window; - DragAcceptFiles(hwnd,flag?TRUE:FALSE); + DragAcceptFiles(GFX2_Get_Window_Handle(), flag?TRUE:FALSE); SDL_EventState (SDL_SYSWMEVENT,flag?SDL_ENABLE:SDL_DISABLE ); #else (void)flag; // unused diff --git a/src/win32screen.c b/src/win32screen.c index eb36e529..81cb9127 100644 --- a/src/win32screen.c +++ b/src/win32screen.c @@ -44,6 +44,11 @@ static int Windows_DIB_height = 0; static HWND Win32_hwnd = NULL; static int Win32_Is_Fullscreen = 0; +HWND GFX2_Get_Window_Handle() +{ + return Win32_hwnd; +} + static void Win32_Repaint(HWND hwnd) { PAINTSTRUCT ps; @@ -421,4 +426,5 @@ volatile int Allow_colorcycling = 0; /// Activates or desactivates file drag-dropping in program window. void Allow_drag_and_drop(int flag) { + DragAcceptFiles(GFX2_Get_Window_Handle(), flag?TRUE:FALSE); }