Consolidate the Win32 init and cleanup code in to one place so

it's easier to keep track of it.


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10312 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Pierre Ossman 2014-09-15 09:35:05 +00:00
parent 53888cf064
commit 61e1b18f7b
4 changed files with 43 additions and 58 deletions

View File

@ -101,6 +101,8 @@ extern FL_EXPORT void fl_save_dc( HWND w, HDC dc);
inline Window fl_xid(const Fl_Window* w) { Fl_X *temp = Fl_X::i(w); return temp ? temp->xid : 0; }
extern FL_EXPORT void fl_open_display();
#else
FL_EXPORT Window fl_xid_(const Fl_Window* w);
#define fl_xid(w) fl_xid_(w)

View File

@ -590,45 +590,6 @@ int Fl::run() {
return 0;
}
#ifdef WIN32
// Function to initialize COM/OLE for usage. This must be done only once.
// We define a flag to register whether we called it:
static char oleInitialized = 0;
// This calls the Windows function OleInitialize() exactly once.
void fl_OleInitialize() {
if (!oleInitialized) {
OleInitialize(0L);
oleInitialized = 1;
}
}
// This calls the Windows function OleUninitialize() only, if
// OleInitialize has been called before.
void fl_OleUninitialize() {
if (oleInitialized) {
OleUninitialize();
oleInitialized = 0;
}
}
class Fl_Win32_At_Exit {
public:
Fl_Win32_At_Exit() { }
~Fl_Win32_At_Exit() {
fl_free_fonts(); // do some WIN32 cleanup
fl_cleanup_pens();
fl_OleUninitialize();
fl_brush_action(1);
fl_cleanup_dc_list();
}
};
static Fl_Win32_At_Exit win32_at_exit;
#endif
/**
Waits until "something happens" and then returns. Call this
repeatedly to "run" your program. You can also check what happened

View File

@ -34,14 +34,13 @@ LPCWSTR utf8towchar(const char *in); //MG
char *wchartoutf8(LPCWSTR in); //MG
#include <FL/Fl_Native_File_Chooser.H>
#include <FL/x.H>
#define LCURLY_CHR '{'
#define RCURLY_CHR '}'
#define LBRACKET_CHR '['
#define RBRACKET_CHR ']'
void fl_OleInitialize(); // in Fl.cxx (Windows only)
// STATIC: PRINT WINDOWS 'DOUBLE NULL' STRING (DEBUG)
#ifdef DEBUG
static void dnullprint(char *wp) {
@ -465,7 +464,7 @@ int CALLBACK Fl_Native_File_Chooser::Dir_CB(HWND win, UINT msg, LPARAM param, LP
// SHOW DIRECTORY BROWSER
int Fl_Native_File_Chooser::showdir() {
// initialize OLE only once
fl_OleInitialize(); // init needed by BIF_USENEWUI
fl_open_display(); // init needed by BIF_USENEWUI
ClearBINF();
clear_pathnames();
// PARENT WINDOW

View File

@ -125,21 +125,15 @@ typedef BOOL (WINAPI* flTypeImmSetCompositionWindow)(HIMC, LPCOMPOSITIONFORM);
static flTypeImmSetCompositionWindow flImmSetCompositionWindow = 0;
typedef BOOL (WINAPI* flTypeImmReleaseContext)(HWND, HIMC);
static flTypeImmReleaseContext flImmReleaseContext = 0;
typedef BOOL (WINAPI* flTypeImmIsIME)(HKL);
static flTypeImmIsIME flImmIsIME = 0;
static HMODULE get_imm_module() {
if (!s_imm_module) {
s_imm_module = LoadLibrary("IMM32.DLL");
if (!s_imm_module)
Fl::fatal("FLTK Lib Error: IMM32.DLL file not found!\n\n"
"Please check your input method manager library accessibility.");
flImmGetContext = (flTypeImmGetContext)GetProcAddress(s_imm_module, "ImmGetContext");
flImmSetCompositionWindow = (flTypeImmSetCompositionWindow)GetProcAddress(s_imm_module, "ImmSetCompositionWindow");
flImmReleaseContext = (flTypeImmReleaseContext)GetProcAddress(s_imm_module, "ImmReleaseContext");
flImmIsIME = (flTypeImmIsIME)GetProcAddress(s_imm_module, "ImmIsIME");
}
return s_imm_module;
static void get_imm_module() {
s_imm_module = LoadLibrary("IMM32.DLL");
if (!s_imm_module)
Fl::fatal("FLTK Lib Error: IMM32.DLL file not found!\n\n"
"Please check your input method manager library accessibility.");
flImmGetContext = (flTypeImmGetContext)GetProcAddress(s_imm_module, "ImmGetContext");
flImmSetCompositionWindow = (flTypeImmSetCompositionWindow)GetProcAddress(s_imm_module, "ImmSetCompositionWindow");
flImmReleaseContext = (flTypeImmReleaseContext)GetProcAddress(s_imm_module, "ImmReleaseContext");
}
// USE_TRACK_MOUSE - define NO_TRACK_MOUSE if you don't have
@ -257,7 +251,9 @@ void fl_set_spot(int font, int size, int X, int Y, int W, int H, Fl_Window *win)
Fl_Window* tw = win;
while (tw->parent()) tw = tw->window(); // find top level window
get_imm_module();
if (!tw->shown())
return;
HIMC himc = flImmGetContext(fl_xid(tw));
if (himc) {
@ -438,6 +434,32 @@ int fl_ready() {
return get_wsock_mod() ? s_wsock_select(0,&fdt[0],&fdt[1],&fdt[2],&t) : 0;
}
void fl_open_display() {
static char beenHereDoneThat = 0;
if (beenHereDoneThat)
return;
beenHereDoneThat = 1;
OleInitialize(0L);
get_imm_module();
}
class Fl_Win32_At_Exit {
public:
Fl_Win32_At_Exit() { }
~Fl_Win32_At_Exit() {
fl_free_fonts(); // do some WIN32 cleanup
fl_cleanup_pens();
OleUninitialize();
fl_brush_action(1);
fl_cleanup_dc_list();
}
};
static Fl_Win32_At_Exit win32_at_exit;
////////////////////////////////////////////////////////////////
int Fl::x()
@ -1649,6 +1671,8 @@ int fl_disable_transient_for; // secret method of removing TRANSIENT_FOR
Fl_X* Fl_X::make(Fl_Window* w) {
Fl_Group::current(0); // get rid of very common user bug: forgot end()
fl_open_display();
// if the window is a subwindow and our parent is not mapped yet, we
// mark this window visible, so that mapping the parent at a later
// point in time will call this function again to finally map the subwindow.
@ -1852,7 +1876,6 @@ Fl_X* Fl_X::make(Fl_Window* w) {
(Fl::grab() || (styleEx & WS_EX_TOOLWINDOW)) ? SW_SHOWNOACTIVATE : SW_SHOWNORMAL);
// Register all windows for potential drag'n'drop operations
fl_OleInitialize();
RegisterDragDrop(x->xid, flIDropTarget);
return x;