1706f2543Smrg/* 2706f2543Smrg *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved. 3706f2543Smrg * 4706f2543Smrg *Permission is hereby granted, free of charge, to any person obtaining 5706f2543Smrg * a copy of this software and associated documentation files (the 6706f2543Smrg *"Software"), to deal in the Software without restriction, including 7706f2543Smrg *without limitation the rights to use, copy, modify, merge, publish, 8706f2543Smrg *distribute, sublicense, and/or sell copies of the Software, and to 9706f2543Smrg *permit persons to whom the Software is furnished to do so, subject to 10706f2543Smrg *the following conditions: 11706f2543Smrg * 12706f2543Smrg *The above copyright notice and this permission notice shall be 13706f2543Smrg *included in all copies or substantial portions of the Software. 14706f2543Smrg * 15706f2543Smrg *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16706f2543Smrg *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17706f2543Smrg *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18706f2543Smrg *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR 19706f2543Smrg *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 20706f2543Smrg *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21706f2543Smrg *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22706f2543Smrg * 23706f2543Smrg *Except as contained in this notice, the name of Harold L Hunt II 24706f2543Smrg *shall not be used in advertising or otherwise to promote the sale, use 25706f2543Smrg *or other dealings in this Software without prior written authorization 26706f2543Smrg *from Harold L Hunt II. 27706f2543Smrg * 28706f2543Smrg * Authors: Harold L Hunt II 29706f2543Smrg */ 30706f2543Smrg 31706f2543Smrg#ifdef HAVE_XWIN_CONFIG_H 32706f2543Smrg#include <xwin-config.h> 33706f2543Smrg#endif 34706f2543Smrg#include "dixstruct.h" 35706f2543Smrg#include "winclipboard.h" 36706f2543Smrg 37706f2543Smrg 38706f2543Smrg/* 39706f2543Smrg * Local typedefs 40706f2543Smrg */ 41706f2543Smrg 42706f2543Smrgtypedef int (*winDispatchProcPtr) (ClientPtr); 43706f2543Smrg 44706f2543Smrgint winProcSetSelectionOwner(ClientPtr /* client */); 45706f2543Smrg 46706f2543Smrg 47706f2543Smrg/* 48706f2543Smrg * References to external symbols 49706f2543Smrg */ 50706f2543Smrg 51706f2543Smrgextern pthread_t g_ptClipboardProc; 52706f2543Smrgextern winDispatchProcPtr winProcSetSelectionOwnerOrig; 53706f2543Smrgextern Bool g_fClipboard; 54706f2543Smrgextern HWND g_hwndClipboard; 55706f2543Smrg 56706f2543Smrg 57706f2543Smrg/* 58706f2543Smrg * Intialize the Clipboard module 59706f2543Smrg */ 60706f2543Smrg 61706f2543SmrgBool 62706f2543SmrgwinInitClipboard (void) 63706f2543Smrg{ 64706f2543Smrg ErrorF ("winInitClipboard ()\n"); 65706f2543Smrg 66706f2543Smrg /* Wrap some internal server functions */ 67706f2543Smrg if (ProcVector[X_SetSelectionOwner] != winProcSetSelectionOwner) 68706f2543Smrg { 69706f2543Smrg winProcSetSelectionOwnerOrig = ProcVector[X_SetSelectionOwner]; 70706f2543Smrg ProcVector[X_SetSelectionOwner] = winProcSetSelectionOwner; 71706f2543Smrg } 72706f2543Smrg 73706f2543Smrg /* Spawn a thread for the Clipboard module */ 74706f2543Smrg if (pthread_create (&g_ptClipboardProc, 75706f2543Smrg NULL, 76706f2543Smrg winClipboardProc, 77706f2543Smrg NULL)) 78706f2543Smrg { 79706f2543Smrg /* Bail if thread creation failed */ 80706f2543Smrg ErrorF ("winInitClipboard - pthread_create failed.\n"); 81706f2543Smrg return FALSE; 82706f2543Smrg } 83706f2543Smrg 84706f2543Smrg return TRUE; 85706f2543Smrg} 86706f2543Smrg 87706f2543Smrg 88706f2543Smrg/* 89706f2543Smrg * Create the Windows window that we use to recieve Windows messages 90706f2543Smrg */ 91706f2543Smrg 92706f2543SmrgHWND 93706f2543SmrgwinClipboardCreateMessagingWindow (void) 94706f2543Smrg{ 95706f2543Smrg WNDCLASSEX wc; 96706f2543Smrg HWND hwnd; 97706f2543Smrg 98706f2543Smrg /* Setup our window class */ 99706f2543Smrg wc.cbSize=sizeof(WNDCLASSEX); 100706f2543Smrg wc.style = CS_HREDRAW | CS_VREDRAW; 101706f2543Smrg wc.lpfnWndProc = winClipboardWindowProc; 102706f2543Smrg wc.cbClsExtra = 0; 103706f2543Smrg wc.cbWndExtra = 0; 104706f2543Smrg wc.hInstance = GetModuleHandle (NULL); 105706f2543Smrg wc.hIcon = 0; 106706f2543Smrg wc.hCursor = 0; 107706f2543Smrg wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); 108706f2543Smrg wc.lpszMenuName = NULL; 109706f2543Smrg wc.lpszClassName = WIN_CLIPBOARD_WINDOW_CLASS; 110706f2543Smrg wc.hIconSm = 0; 111706f2543Smrg RegisterClassEx (&wc); 112706f2543Smrg 113706f2543Smrg /* Create the window */ 114706f2543Smrg hwnd = CreateWindowExA (0, /* Extended styles */ 115706f2543Smrg WIN_CLIPBOARD_WINDOW_CLASS,/* Class name */ 116706f2543Smrg WIN_CLIPBOARD_WINDOW_TITLE,/* Window name */ 117706f2543Smrg WS_OVERLAPPED, /* Not visible anyway */ 118706f2543Smrg CW_USEDEFAULT, /* Horizontal position */ 119706f2543Smrg CW_USEDEFAULT, /* Vertical position */ 120706f2543Smrg CW_USEDEFAULT, /* Right edge */ 121706f2543Smrg CW_USEDEFAULT, /* Bottom edge */ 122706f2543Smrg (HWND) NULL, /* No parent or owner window */ 123706f2543Smrg (HMENU) NULL, /* No menu */ 124706f2543Smrg GetModuleHandle (NULL),/* Instance handle */ 125706f2543Smrg NULL); /* Creation data */ 126706f2543Smrg assert (hwnd != NULL); 127706f2543Smrg 128706f2543Smrg /* I'm not sure, but we may need to call this to start message processing */ 129706f2543Smrg ShowWindow (hwnd, SW_HIDE); 130706f2543Smrg 131706f2543Smrg /* Similarly, we may need a call to this even though we don't paint */ 132706f2543Smrg UpdateWindow (hwnd); 133706f2543Smrg 134706f2543Smrg return hwnd; 135706f2543Smrg} 136706f2543Smrg 137706f2543Smrgvoid 138706f2543SmrgwinFixClipboardChain (void) 139706f2543Smrg{ 140706f2543Smrg if (g_fClipboard 141706f2543Smrg && g_hwndClipboard) 142706f2543Smrg { 143706f2543Smrg PostMessage (g_hwndClipboard, WM_WM_REINIT, 0, 0); 144706f2543Smrg } 145706f2543Smrg} 146