1/* 2 *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved. 3 * 4 *Permission is hereby granted, free of charge, to any person obtaining 5 * a copy of this software and associated documentation files (the 6 *"Software"), to deal in the Software without restriction, including 7 *without limitation the rights to use, copy, modify, merge, publish, 8 *distribute, sublicense, and/or sell copies of the Software, and to 9 *permit persons to whom the Software is furnished to do so, subject to 10 *the following conditions: 11 * 12 *The above copyright notice and this permission notice shall be 13 *included in all copies or substantial portions of the Software. 14 * 15 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR 19 *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 20 *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 * 23 *Except as contained in this notice, the name of Harold L Hunt II 24 *shall not be used in advertising or otherwise to promote the sale, use 25 *or other dealings in this Software without prior written authorization 26 *from Harold L Hunt II. 27 * 28 * Authors: Harold L Hunt II 29 */ 30 31#ifdef HAVE_XWIN_CONFIG_H 32#include <xwin-config.h> 33#endif 34#include "dixstruct.h" 35#include "winclipboard.h" 36 37 38/* 39 * Local typedefs 40 */ 41 42typedef int (*winDispatchProcPtr) (ClientPtr); 43 44int winProcSetSelectionOwner(ClientPtr /* client */); 45 46 47/* 48 * References to external symbols 49 */ 50 51extern pthread_t g_ptClipboardProc; 52extern winDispatchProcPtr winProcSetSelectionOwnerOrig; 53extern Bool g_fClipboard; 54extern HWND g_hwndClipboard; 55 56 57/* 58 * Intialize the Clipboard module 59 */ 60 61Bool 62winInitClipboard (void) 63{ 64 ErrorF ("winInitClipboard ()\n"); 65 66 /* Wrap some internal server functions */ 67 if (ProcVector[X_SetSelectionOwner] != winProcSetSelectionOwner) 68 { 69 winProcSetSelectionOwnerOrig = ProcVector[X_SetSelectionOwner]; 70 ProcVector[X_SetSelectionOwner] = winProcSetSelectionOwner; 71 } 72 73 /* Spawn a thread for the Clipboard module */ 74 if (pthread_create (&g_ptClipboardProc, 75 NULL, 76 winClipboardProc, 77 NULL)) 78 { 79 /* Bail if thread creation failed */ 80 ErrorF ("winInitClipboard - pthread_create failed.\n"); 81 return FALSE; 82 } 83 84 return TRUE; 85} 86 87 88/* 89 * Create the Windows window that we use to recieve Windows messages 90 */ 91 92HWND 93winClipboardCreateMessagingWindow (void) 94{ 95 WNDCLASSEX wc; 96 HWND hwnd; 97 98 /* Setup our window class */ 99 wc.cbSize=sizeof(WNDCLASSEX); 100 wc.style = CS_HREDRAW | CS_VREDRAW; 101 wc.lpfnWndProc = winClipboardWindowProc; 102 wc.cbClsExtra = 0; 103 wc.cbWndExtra = 0; 104 wc.hInstance = GetModuleHandle (NULL); 105 wc.hIcon = 0; 106 wc.hCursor = 0; 107 wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); 108 wc.lpszMenuName = NULL; 109 wc.lpszClassName = WIN_CLIPBOARD_WINDOW_CLASS; 110 wc.hIconSm = 0; 111 RegisterClassEx (&wc); 112 113 /* Create the window */ 114 hwnd = CreateWindowExA (0, /* Extended styles */ 115 WIN_CLIPBOARD_WINDOW_CLASS,/* Class name */ 116 WIN_CLIPBOARD_WINDOW_TITLE,/* Window name */ 117 WS_OVERLAPPED, /* Not visible anyway */ 118 CW_USEDEFAULT, /* Horizontal position */ 119 CW_USEDEFAULT, /* Vertical position */ 120 CW_USEDEFAULT, /* Right edge */ 121 CW_USEDEFAULT, /* Bottom edge */ 122 (HWND) NULL, /* No parent or owner window */ 123 (HMENU) NULL, /* No menu */ 124 GetModuleHandle (NULL),/* Instance handle */ 125 NULL); /* Creation data */ 126 assert (hwnd != NULL); 127 128 /* I'm not sure, but we may need to call this to start message processing */ 129 ShowWindow (hwnd, SW_HIDE); 130 131 /* Similarly, we may need a call to this even though we don't paint */ 132 UpdateWindow (hwnd); 133 134 return hwnd; 135} 136 137void 138winFixClipboardChain (void) 139{ 140 if (g_fClipboard 141 && g_hwndClipboard) 142 { 143 PostMessage (g_hwndClipboard, WM_WM_REINIT, 0, 0); 144 } 145} 146