| 1 |
/* |
| 2 |
|
| 3 |
Copyright 1989, 1998 The Open Group |
| 4 |
|
| 5 |
Permission to use, copy, modify, distribute, and sell this software and its |
| 6 |
documentation for any purpose is hereby granted without fee, provided that |
| 7 |
the above copyright notice appear in all copies and that both that |
| 8 |
copyright notice and this permission notice appear in supporting |
| 9 |
documentation. |
| 10 |
|
| 11 |
The above copyright notice and this permission notice shall be included in |
| 12 |
all copies or substantial portions of the Software. |
| 13 |
|
| 14 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 |
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 18 |
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 19 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 20 |
|
| 21 |
Except as contained in this notice, the name of The Open Group shall not be |
| 22 |
used in advertising or otherwise to promote the sale, use or other dealings |
| 23 |
in this Software without prior written authorization from The Open Group. |
| 24 |
|
| 25 |
*/ |
| 26 |
|
| 27 |
/* |
| 28 |
* Author: Jim Fulton, MIT X Consortium |
| 29 |
*/ |
| 30 |
|
| 31 |
#ifdef HAVE_CONFIG_H |
| 32 |
#include <config.h> |
| 33 |
#endif |
| 34 |
#include <stdio.h> |
| 35 |
#include <X11/Xlib.h> |
| 36 |
#include <X11/Xos.h> |
| 37 |
#include <X11/Xmu/CvtCache.h> |
| 38 |
#include <stdlib.h> |
| 39 |
|
| 40 |
/* |
| 41 |
* Prototypes |
| 42 |
*/ |
| 43 |
static int _CloseDisplay(XmuDisplayQueue*, XmuDisplayQueueEntry*); |
| 44 |
static int _FreeCCDQ(XmuDisplayQueue*); |
| 45 |
static void _InitializeCvtCache(XmuCvtCache*); |
| 46 |
|
| 47 |
/* |
| 48 |
* Initialization |
| 49 |
*/ |
| 50 |
static XmuDisplayQueue *dq = NULL; |
| 51 |
|
| 52 |
|
| 53 |
/* |
| 54 |
* internal utility callbacks |
| 55 |
*/ |
| 56 |
|
| 57 |
static int |
| 58 |
_FreeCCDQ(XmuDisplayQueue *q) |
| 59 |
{ |
| 60 |
XmuDQDestroy (dq, False); |
| 61 |
dq = NULL; |
| 62 |
return (0); |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
static int |
| 67 |
_CloseDisplay(XmuDisplayQueue *q, XmuDisplayQueueEntry *e) |
| 68 |
{ |
| 69 |
XmuCvtCache *c; |
| 70 |
|
| 71 |
if (e && (c = (XmuCvtCache *)(e->data))) { |
| 72 |
_XmuStringToBitmapFreeCache (c); |
| 73 |
/* insert calls to free any cached memory */ |
| 74 |
|
| 75 |
} |
| 76 |
return 0; |
| 77 |
} |
| 78 |
|
| 79 |
static void |
| 80 |
_InitializeCvtCache(register XmuCvtCache *c) |
| 81 |
{ |
| 82 |
_XmuStringToBitmapInitCache (c); |
| 83 |
/* insert calls to init any cached memory */ |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
/* |
| 88 |
* XmuCCLookupDisplay - return the cache entry for the indicated display; |
| 89 |
* initialize the cache if necessary |
| 90 |
*/ |
| 91 |
XmuCvtCache * |
| 92 |
_XmuCCLookupDisplay(Display *dpy) |
| 93 |
{ |
| 94 |
XmuDisplayQueueEntry *e; |
| 95 |
|
| 96 |
/* |
| 97 |
* If no displays have been added before this, create the display queue. |
| 98 |
*/ |
| 99 |
if (!dq) { |
| 100 |
dq = XmuDQCreate (_CloseDisplay, _FreeCCDQ, NULL); |
| 101 |
if (!dq) return NULL; |
| 102 |
} |
| 103 |
|
| 104 |
/* |
| 105 |
* See if the display is already there |
| 106 |
*/ |
| 107 |
e = XmuDQLookupDisplay (dq, dpy); /* see if it's there */ |
| 108 |
if (!e) { /* else create it */ |
| 109 |
XmuCvtCache *c = (XmuCvtCache *) malloc (sizeof (XmuCvtCache)); |
| 110 |
if (!c) return NULL; |
| 111 |
|
| 112 |
/* |
| 113 |
* Add the display to the queue |
| 114 |
*/ |
| 115 |
e = XmuDQAddDisplay (dq, dpy, (XPointer) c); |
| 116 |
if (!e) { |
| 117 |
free ((char *) c); |
| 118 |
return NULL; |
| 119 |
} |
| 120 |
|
| 121 |
/* |
| 122 |
* initialize fields in cache |
| 123 |
*/ |
| 124 |
_InitializeCvtCache (c); |
| 125 |
} |
| 126 |
|
| 127 |
/* |
| 128 |
* got it |
| 129 |
*/ |
| 130 |
return (XmuCvtCache *)(e->data); |
| 131 |
} |
| 132 |
|
| 133 |
|