Don't let applications add Connection header to request.
[wine] / windows / dce.c
1 /*
2  * USER DCE functions
3  *
4  * Copyright 1993 Alexandre Julliard
5  *           1996,1997 Alex Korobka
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  *
22  * Note: Visible regions of CS_OWNDC/CS_CLASSDC window DCs
23  * have to be updated dynamically.
24  *
25  * Internal DCX flags:
26  *
27  * DCX_DCEEMPTY    - dce is uninitialized
28  * DCX_DCEBUSY     - dce is in use
29  * DCX_DCEDIRTY    - ReleaseDC() should wipe instead of caching
30  * DCX_KEEPCLIPRGN - ReleaseDC() should not delete the clipping region
31  * DCX_WINDOWPAINT - BeginPaint() is in effect
32  */
33
34 #include <assert.h>
35 #include "dce.h"
36 #include "win.h"
37 #include "user.h"
38 #include "wine/debug.h"
39 #include "windef.h"
40 #include "wingdi.h"
41 #include "wownt32.h"
42 #include "wine/winbase16.h"
43 #include "wine/winuser16.h"
44
45 WINE_DEFAULT_DEBUG_CHANNEL(dc);
46
47 static DCE *firstDCE;
48 static HDC16 defaultDCstate;
49
50 static void DCE_DeleteClipRgn( DCE* );
51 static INT DCE_ReleaseDC( DCE* );
52
53
54 /***********************************************************************
55  *           DCE_DumpCache
56  */
57 static void DCE_DumpCache(void)
58 {
59     DCE *dce;
60
61     USER_Lock();
62     dce = firstDCE;
63
64     DPRINTF("DCE:\n");
65     while( dce )
66     {
67         DPRINTF("\t[0x%08x] hWnd %p, dcx %08x, %s %s\n",
68              (unsigned)dce, dce->hwndCurrent, (unsigned)dce->DCXflags,
69              (dce->DCXflags & DCX_CACHE) ? "Cache" : "Owned",
70              (dce->DCXflags & DCX_DCEBUSY) ? "InUse" : "" );
71         dce = dce->next;
72     }
73
74     USER_Unlock();
75 }
76
77 /***********************************************************************
78  *           DCE_AllocDCE
79  *
80  * Allocate a new DCE.
81  */
82 DCE *DCE_AllocDCE( HWND hWnd, DCE_TYPE type )
83 {
84     static const WCHAR szDisplayW[] = { 'D','I','S','P','L','A','Y','\0' };
85     DCE * dce;
86
87     TRACE("(%p,%d)\n", hWnd, type);
88
89     if (!(dce = HeapAlloc( GetProcessHeap(), 0, sizeof(DCE) ))) return NULL;
90     if (!(dce->hDC = CreateDCW( szDisplayW, NULL, NULL, NULL )))
91     {
92         HeapFree( GetProcessHeap(), 0, dce );
93         return 0;
94     }
95     if (!defaultDCstate) defaultDCstate = GetDCState16( HDC_16(dce->hDC) );
96
97     /* store DCE handle in DC hook data field */
98
99     SetDCHook( dce->hDC, DCHook16, (DWORD)dce );
100
101     dce->hwndCurrent = WIN_GetFullHandle( hWnd );
102     dce->hClipRgn    = 0;
103
104     if( type != DCE_CACHE_DC ) /* owned or class DC */
105     {
106         dce->DCXflags = DCX_DCEBUSY;
107         if( hWnd )
108         {
109             LONG style = GetWindowLongW( hWnd, GWL_STYLE );
110             if (style & WS_CLIPCHILDREN) dce->DCXflags |= DCX_CLIPCHILDREN;
111             if (style & WS_CLIPSIBLINGS) dce->DCXflags |= DCX_CLIPSIBLINGS;
112         }
113         SetHookFlags16( HDC_16(dce->hDC), DCHF_INVALIDATEVISRGN );
114     }
115     else dce->DCXflags = DCX_CACHE | DCX_DCEEMPTY;
116
117     USER_Lock();
118     dce->next = firstDCE;
119     firstDCE = dce;
120     USER_Unlock();
121     return dce;
122 }
123
124
125 /***********************************************************************
126  *           DCE_FreeDCE
127  */
128 DCE* DCE_FreeDCE( DCE *dce )
129 {
130     DCE **ppDCE, *ret;
131
132     if (!dce) return NULL;
133
134     USER_Lock();
135
136     ppDCE = &firstDCE;
137
138     while (*ppDCE && (*ppDCE != dce)) ppDCE = &(*ppDCE)->next;
139     if (*ppDCE == dce) *ppDCE = dce->next;
140     ret = *ppDCE;
141     USER_Unlock();
142
143     SetDCHook(dce->hDC, NULL, 0L);
144
145     DeleteDC( dce->hDC );
146     if( dce->hClipRgn && !(dce->DCXflags & DCX_KEEPCLIPRGN) )
147         DeleteObject(dce->hClipRgn);
148     HeapFree( GetProcessHeap(), 0, dce );
149
150     return ret;
151 }
152
153 /***********************************************************************
154  *           DCE_FreeWindowDCE
155  *
156  * Remove owned DCE and reset unreleased cache DCEs.
157  */
158 void DCE_FreeWindowDCE( HWND hwnd )
159 {
160     DCE *pDCE;
161     WND *pWnd = WIN_GetPtr( hwnd );
162
163     pDCE = firstDCE;
164     while( pDCE )
165     {
166         if( pDCE->hwndCurrent == hwnd )
167         {
168             if( pDCE == pWnd->dce ) /* owned or Class DCE*/
169             {
170                 if (pWnd->clsStyle & CS_OWNDC)  /* owned DCE*/
171                 {
172                     pDCE = DCE_FreeDCE( pDCE );
173                     pWnd->dce = NULL;
174                     continue;
175                 }
176                 else if( pDCE->DCXflags & (DCX_INTERSECTRGN | DCX_EXCLUDERGN) ) /* Class DCE*/
177                 {
178                     if (USER_Driver.pReleaseDC)
179                         USER_Driver.pReleaseDC( pDCE->hwndCurrent, pDCE->hDC );
180                     DCE_DeleteClipRgn( pDCE );
181                     pDCE->hwndCurrent = 0;
182                 }
183             }
184             else
185             {
186                 if( pDCE->DCXflags & DCX_DCEBUSY ) /* shared cache DCE */
187                 {
188                     /* FIXME: AFAICS we are doing the right thing here so
189                      * this should be a WARN. But this is best left as an ERR
190                      * because the 'application error' is likely to come from
191                      * another part of Wine (i.e. it's our fault after all).
192                      * We should change this to WARN when Wine is more stable
193                      * (for 1.0?).
194                      */
195                     ERR("[%p] GetDC() without ReleaseDC()!\n",hwnd);
196                     DCE_ReleaseDC( pDCE );
197                 }
198
199                 if (pDCE->hwndCurrent && USER_Driver.pReleaseDC)
200                     USER_Driver.pReleaseDC( pDCE->hwndCurrent, pDCE->hDC );
201                 pDCE->DCXflags &= DCX_CACHE;
202                 pDCE->DCXflags |= DCX_DCEEMPTY;
203                 pDCE->hwndCurrent = 0;
204             }
205         }
206         pDCE = pDCE->next;
207     }
208     WIN_ReleasePtr( pWnd );
209 }
210
211
212 /***********************************************************************
213  *   DCE_DeleteClipRgn
214  */
215 static void DCE_DeleteClipRgn( DCE* dce )
216 {
217     dce->DCXflags &= ~(DCX_EXCLUDERGN | DCX_INTERSECTRGN | DCX_WINDOWPAINT);
218
219     if( dce->DCXflags & DCX_KEEPCLIPRGN )
220         dce->DCXflags &= ~DCX_KEEPCLIPRGN;
221     else
222         if( dce->hClipRgn > (HRGN)1 )
223             DeleteObject( dce->hClipRgn );
224
225     dce->hClipRgn = 0;
226
227     /* make it dirty so that the vis rgn gets recomputed next time */
228     dce->DCXflags |= DCX_DCEDIRTY;
229     SetHookFlags16( HDC_16(dce->hDC), DCHF_INVALIDATEVISRGN );
230 }
231
232
233 /***********************************************************************
234  *   DCE_ReleaseDC
235  */
236 static INT DCE_ReleaseDC( DCE* dce )
237 {
238     if ((dce->DCXflags & (DCX_DCEEMPTY | DCX_DCEBUSY)) != DCX_DCEBUSY) return 0;
239
240     /* restore previous visible region */
241
242     if ((dce->DCXflags & (DCX_INTERSECTRGN | DCX_EXCLUDERGN)) &&
243         (dce->DCXflags & (DCX_CACHE | DCX_WINDOWPAINT)) )
244         DCE_DeleteClipRgn( dce );
245
246     if (dce->DCXflags & DCX_CACHE)
247     {
248         /* make the DC clean so that SetDCState doesn't try to update the vis rgn */
249         SetHookFlags16( HDC_16(dce->hDC), DCHF_VALIDATEVISRGN );
250         SetDCState16( HDC_16(dce->hDC), defaultDCstate );
251         dce->DCXflags &= ~DCX_DCEBUSY;
252         if (dce->DCXflags & DCX_DCEDIRTY)
253         {
254             /* don't keep around invalidated entries
255              * because SetDCState() disables hVisRgn updates
256              * by removing dirty bit. */
257             if (dce->hwndCurrent && USER_Driver.pReleaseDC)
258                 USER_Driver.pReleaseDC( dce->hwndCurrent, dce->hDC );
259             dce->hwndCurrent = 0;
260             dce->DCXflags &= DCX_CACHE;
261             dce->DCXflags |= DCX_DCEEMPTY;
262         }
263     }
264     return 1;
265 }
266
267
268 /***********************************************************************
269  *   DCE_InvalidateDCE
270  *
271  * It is called from SetWindowPos() and EVENT_MapNotify - we have to
272  * mark as dirty all busy DCEs for windows that have pWnd->parent as
273  * an ancestor and whose client rect intersects with specified update
274  * rectangle. In addition, pWnd->parent DCEs may need to be updated if
275  * DCX_CLIPCHILDREN flag is set.  */
276 BOOL DCE_InvalidateDCE(HWND hwnd, const RECT* pRectUpdate)
277 {
278     HWND hwndScope = GetAncestor( hwnd, GA_PARENT );
279     BOOL bRet = FALSE;
280
281     if( hwndScope )
282     {
283         DCE *dce;
284
285         TRACE("scope hwnd = %p, (%ld,%ld - %ld,%ld)\n",
286               hwndScope, pRectUpdate->left,pRectUpdate->top,
287               pRectUpdate->right,pRectUpdate->bottom);
288         if(TRACE_ON(dc))
289           DCE_DumpCache();
290
291         /* walk all DCEs and fixup non-empty entries */
292
293         for (dce = firstDCE; (dce); dce = dce->next)
294         {
295             if (dce->DCXflags & DCX_DCEEMPTY) continue;
296             if ((dce->hwndCurrent == hwndScope) && !(dce->DCXflags & DCX_CLIPCHILDREN))
297                 continue;  /* child window positions don't bother us */
298
299             /* check if DCE window is within the z-order scope */
300
301             if (hwndScope == dce->hwndCurrent || IsChild( hwndScope, dce->hwndCurrent ))
302             {
303                 if (hwnd != dce->hwndCurrent)
304                 {
305                     /* check if the window rectangle intersects this DCE window */
306                     RECT rect;
307                     GetWindowRect( dce->hwndCurrent, &rect );
308                     MapWindowPoints( 0, hwndScope, (POINT *)&rect, 2 );
309                     if (!IntersectRect( &rect, &rect, pRectUpdate )) continue;
310
311                 }
312                 if( !(dce->DCXflags & DCX_DCEBUSY) )
313                 {
314                     /* Don't bother with visible regions of unused DCEs */
315
316                     TRACE("\tpurged %p dce [%p]\n", dce, dce->hwndCurrent);
317                     if (dce->hwndCurrent && USER_Driver.pReleaseDC)
318                         USER_Driver.pReleaseDC( dce->hwndCurrent, dce->hDC );
319                     dce->hwndCurrent = 0;
320                     dce->DCXflags &= DCX_CACHE;
321                     dce->DCXflags |= DCX_DCEEMPTY;
322                 }
323                 else
324                 {
325                     /* Set dirty bits in the hDC and DCE structs */
326
327                     TRACE("\tfixed up %p dce [%p]\n", dce, dce->hwndCurrent);
328                     dce->DCXflags |= DCX_DCEDIRTY;
329                     SetHookFlags16( HDC_16(dce->hDC), DCHF_INVALIDATEVISRGN );
330                     bRet = TRUE;
331                 }
332             }
333         } /* dce list */
334     }
335     return bRet;
336 }
337
338
339 /***********************************************************************
340  *           DCE_ExcludeRgn
341  *
342  *  Translate given region from the wnd client to the DC coordinates
343  *  and add it to the clipping region.
344  */
345 INT DCE_ExcludeRgn( HDC hDC, HWND hwnd, HRGN hRgn )
346 {
347   POINT  pt = {0, 0};
348   DCE     *dce = firstDCE;
349
350   while (dce && (dce->hDC != hDC)) dce = dce->next;
351   if (!dce) return ERROR;
352
353   MapWindowPoints( hwnd, dce->hwndCurrent, &pt, 1);
354   if( dce->DCXflags & DCX_WINDOW )
355   {
356       WND *wnd = WIN_FindWndPtr(dce->hwndCurrent);
357       pt.x += wnd->rectClient.left - wnd->rectWindow.left;
358       pt.y += wnd->rectClient.top - wnd->rectWindow.top;
359       WIN_ReleaseWndPtr(wnd);
360   }
361   OffsetRgn(hRgn, pt.x, pt.y);
362
363   return ExtSelectClipRgn( hDC, hRgn, RGN_DIFF );
364 }
365
366
367 /***********************************************************************
368  *              GetDCEx (USER32.@)
369  *
370  * Unimplemented flags: DCX_LOCKWINDOWUPDATE
371  *
372  * FIXME: Full support for hrgnClip == 1 (alias for entire window).
373  */
374 HDC WINAPI GetDCEx( HWND hwnd, HRGN hrgnClip, DWORD flags )
375 {
376     HDC         hdc = 0;
377     DCE *       dce;
378     WND *       wndPtr;
379     DWORD       dcxFlags = 0;
380     BOOL        bUpdateVisRgn = TRUE;
381     BOOL        bUpdateClipOrigin = FALSE;
382     HWND parent, full;
383
384     TRACE("hwnd %p, hrgnClip %p, flags %08lx\n", hwnd, hrgnClip, flags);
385
386     if (flags & (DCX_LOCKWINDOWUPDATE)) {
387        FIXME("not yet supported - see source\n");
388        /* See the comment in LockWindowUpdate for more explanation. This flag is not implemented
389         * by that patch, but we need LockWindowUpdate implemented correctly before this can be done.
390         */
391     }
392
393     if (!hwnd) hwnd = GetDesktopWindow();
394     if (!(full = WIN_IsCurrentProcess( hwnd )))
395     {
396         FIXME( "not supported yet on other process window %p\n", hwnd );
397         return 0;
398     }
399     hwnd = full;
400     if (!(wndPtr = WIN_GetPtr( hwnd ))) return 0;
401
402     /* fixup flags */
403
404     if (flags & (DCX_WINDOW | DCX_PARENTCLIP)) flags |= DCX_CACHE;
405
406     if (flags & DCX_USESTYLE)
407     {
408         flags &= ~( DCX_CLIPCHILDREN | DCX_CLIPSIBLINGS | DCX_PARENTCLIP);
409
410         if( wndPtr->dwStyle & WS_CLIPSIBLINGS )
411             flags |= DCX_CLIPSIBLINGS;
412
413         if ( !(flags & DCX_WINDOW) )
414         {
415             if (wndPtr->clsStyle & CS_PARENTDC) flags |= DCX_PARENTCLIP;
416
417             if (wndPtr->dwStyle & WS_CLIPCHILDREN &&
418                      !(wndPtr->dwStyle & WS_MINIMIZE) ) flags |= DCX_CLIPCHILDREN;
419             if (!wndPtr->dce) flags |= DCX_CACHE;
420         }
421     }
422
423     if (flags & DCX_WINDOW) flags &= ~DCX_CLIPCHILDREN;
424
425     parent = GetAncestor( hwnd, GA_PARENT );
426     if (!parent || (parent == GetDesktopWindow()))
427         flags = (flags & ~DCX_PARENTCLIP) | DCX_CLIPSIBLINGS;
428
429     /* it seems parent clip is ignored when clipping siblings or children */
430     if (flags & (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN)) flags &= ~DCX_PARENTCLIP;
431
432     if( flags & DCX_PARENTCLIP )
433     {
434         LONG parent_style = GetWindowLongW( parent, GWL_STYLE );
435         if( (wndPtr->dwStyle & WS_VISIBLE) && (parent_style & WS_VISIBLE) )
436         {
437             flags &= ~DCX_CLIPCHILDREN;
438             if (parent_style & WS_CLIPSIBLINGS) flags |= DCX_CLIPSIBLINGS;
439         }
440     }
441
442     /* find a suitable DCE */
443
444     dcxFlags = flags & (DCX_PARENTCLIP | DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN |
445                         DCX_CACHE | DCX_WINDOW);
446
447     if (flags & DCX_CACHE)
448     {
449         DCE*    dceEmpty;
450         DCE*    dceUnused;
451
452         dceEmpty = dceUnused = NULL;
453
454         /* Strategy: First, we attempt to find a non-empty but unused DCE with
455          * compatible flags. Next, we look for an empty entry. If the cache is
456          * full we have to purge one of the unused entries.
457          */
458
459         for (dce = firstDCE; (dce); dce = dce->next)
460         {
461             if ((dce->DCXflags & (DCX_CACHE | DCX_DCEBUSY)) == DCX_CACHE )
462             {
463                 dceUnused = dce;
464
465                 if (dce->DCXflags & DCX_DCEEMPTY)
466                     dceEmpty = dce;
467                 else
468                 if ((dce->hwndCurrent == hwnd) &&
469                    ((dce->DCXflags & (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN |
470                                       DCX_CACHE | DCX_WINDOW | DCX_PARENTCLIP)) == dcxFlags))
471                 {
472                     TRACE("\tfound valid %p dce [%p], flags %08lx\n",
473                           dce, hwnd, dcxFlags );
474                     bUpdateVisRgn = FALSE;
475                     bUpdateClipOrigin = TRUE;
476                     break;
477                 }
478             }
479         }
480
481         if (!dce) dce = (dceEmpty) ? dceEmpty : dceUnused;
482
483         /* if there's no dce empty or unused, allocate a new one */
484         if (!dce)
485         {
486             dce = DCE_AllocDCE( 0, DCE_CACHE_DC );
487         }
488     }
489     else
490     {
491         dce = wndPtr->dce;
492         if (dce && dce->hwndCurrent == hwnd)
493         {
494             TRACE("\tskipping hVisRgn update\n");
495             bUpdateVisRgn = FALSE; /* updated automatically, via DCHook() */
496         }
497     }
498     if (!dce)
499     {
500         hdc = 0;
501         goto END;
502     }
503
504     if (!(flags & (DCX_INTERSECTRGN | DCX_EXCLUDERGN))) hrgnClip = 0;
505
506     if (((flags ^ dce->DCXflags) & (DCX_INTERSECTRGN | DCX_EXCLUDERGN)) &&
507         (dce->hClipRgn != hrgnClip))
508     {
509         /* if the extra clip region has changed, get rid of the old one */
510         DCE_DeleteClipRgn( dce );
511     }
512
513     dce->hwndCurrent = hwnd;
514     dce->hClipRgn = hrgnClip;
515     dce->DCXflags = flags & (DCX_PARENTCLIP | DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN |
516                              DCX_CACHE | DCX_WINDOW | DCX_WINDOWPAINT |
517                              DCX_KEEPCLIPRGN | DCX_INTERSECTRGN | DCX_EXCLUDERGN);
518     dce->DCXflags |= DCX_DCEBUSY;
519     dce->DCXflags &= ~DCX_DCEDIRTY;
520     hdc = dce->hDC;
521
522     if (bUpdateVisRgn) SetHookFlags16( HDC_16(hdc), DCHF_INVALIDATEVISRGN ); /* force update */
523
524     if (!USER_Driver.pGetDC( hwnd, hdc, hrgnClip, flags )) hdc = 0;
525
526     TRACE("(%p,%p,0x%lx): returning %p\n", hwnd, hrgnClip, flags, hdc);
527 END:
528     WIN_ReleasePtr(wndPtr);
529     return hdc;
530 }
531
532
533 /***********************************************************************
534  *              GetDC (USER32.@)
535  *
536  * Get a device context.
537  *
538  * RETURNS
539  *      Success: Handle to the device context
540  *      Failure: NULL.
541  */
542 HDC WINAPI GetDC(
543              HWND hwnd /* [in] handle of window - may be NULL */
544 ) {
545     if (!hwnd)
546         return GetDCEx( 0, 0, DCX_CACHE | DCX_WINDOW );
547     return GetDCEx( hwnd, 0, DCX_USESTYLE );
548 }
549
550
551 /***********************************************************************
552  *              GetWindowDC (USER32.@)
553  */
554 HDC WINAPI GetWindowDC( HWND hwnd )
555 {
556     return GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
557 }
558
559
560 /***********************************************************************
561  *              ReleaseDC (USER32.@)
562  *
563  * Release a device context.
564  *
565  * RETURNS
566  *      Success: Non-zero. Resources used by hdc are released.
567  *      Failure: 0.
568  */
569 INT WINAPI ReleaseDC(
570              HWND hwnd, /* [in] Handle of window - ignored */
571              HDC hdc   /* [in] Handle of device context */
572 ) {
573     DCE * dce;
574     INT nRet = 0;
575
576     USER_Lock();
577     dce = firstDCE;
578
579     TRACE("%p %p\n", hwnd, hdc );
580
581     while (dce && (dce->hDC != hdc)) dce = dce->next;
582
583     if ( dce )
584         if ( dce->DCXflags & DCX_DCEBUSY )
585             nRet = DCE_ReleaseDC( dce );
586
587     USER_Unlock();
588
589     return nRet;
590 }
591
592 /***********************************************************************
593  *              DCHook (USER.362)
594  *
595  * See "Undoc. Windows" for hints (DC, SetDCHook, SetHookFlags)..
596  */
597 BOOL16 WINAPI DCHook16( HDC16 hDC, WORD code, DWORD data, LPARAM lParam )
598 {
599     BOOL retv = TRUE;
600     DCE *dce = (DCE *)data;
601
602     TRACE("hDC = %04x, %i\n", hDC, code);
603
604     if (!dce) return 0;
605     assert( HDC_16(dce->hDC) == hDC );
606
607     /* Grab the windows lock before doing anything else  */
608     USER_Lock();
609
610     switch( code )
611     {
612       case DCHC_INVALIDVISRGN:
613            /* GDI code calls this when it detects that the
614             * DC is dirty (usually after SetHookFlags()). This
615             * means that we have to recompute the visible region.
616             */
617            if( dce->DCXflags & DCX_DCEBUSY )
618            {
619                /* Dirty bit has been cleared by caller, set it again so that
620                 * pGetDC recomputes the visible region. */
621                SetHookFlags16( hDC, DCHF_INVALIDATEVISRGN );
622                USER_Driver.pGetDC( dce->hwndCurrent, dce->hDC, dce->hClipRgn, dce->DCXflags );
623            }
624            else /* non-fatal but shouldn't happen */
625              WARN("DC is not in use!\n");
626            break;
627
628       case DCHC_DELETEDC:
629            /*
630             * Windows will not let you delete a DC that is busy
631             * (between GetDC and ReleaseDC)
632             */
633
634            if ( dce->DCXflags & DCX_DCEBUSY )
635            {
636                WARN("Application trying to delete a busy DC\n");
637                retv = FALSE;
638            }
639            else DCE_FreeDCE( dce );
640            break;
641
642       default:
643            FIXME("unknown code\n");
644     }
645
646   USER_Unlock();  /* Release the wnd lock */
647   return retv;
648 }
649
650
651 /**********************************************************************
652  *              WindowFromDC (USER32.@)
653  */
654 HWND WINAPI WindowFromDC( HDC hDC )
655 {
656     DCE *dce;
657     HWND hwnd;
658
659     USER_Lock();
660     dce = firstDCE;
661
662     while (dce && (dce->hDC != hDC)) dce = dce->next;
663
664     hwnd = dce ? dce->hwndCurrent : 0;
665     USER_Unlock();
666
667     return hwnd;
668 }
669
670
671 /***********************************************************************
672  *              LockWindowUpdate (USER32.@)
673  */
674 BOOL WINAPI LockWindowUpdate( HWND hwnd )
675 {
676     static HWND lockedWnd;
677
678     /* This function is fully implemented by the following patch:
679      *
680      * http://www.winehq.org/hypermail/wine-patches/2004/01/0142.html
681      *
682      * but in order to work properly, it needs the ability to invalidate
683      * DCEs in other processes when the lock window is changed, which
684      * isn't possible yet.
685      * -mike
686      */
687
688     FIXME("(%p), partial stub!\n",hwnd);
689
690     USER_Lock();
691     if (lockedWnd)
692     {
693         if (!hwnd)
694         {
695             /* Unlock lockedWnd */
696             /* FIXME: Do something */
697         }
698         else
699         {
700             /* Attempted to lock a second window */
701             /* Return FALSE and do nothing */
702             USER_Unlock();
703             return FALSE;
704         }
705     }
706     lockedWnd = hwnd;
707     USER_Unlock();
708     return TRUE;
709 }