dtinfo: remove register keyword
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Graphics / PixmapGraphic.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*
24  * $XConsortium: PixmapGraphic.C /main/8 1996/10/04 11:07:06 drk $
25  *
26  * Copyright (c) 1992 HaL Computer Systems, Inc.  All rights reserved.
27  * UNPUBLISHED -- rights reserved under the Copyright Laws of the United
28  * States. Use of a copyright notice is precautionary only and does not
29  * imply publication or disclosure.
30  * 
31  * This software contains confidential information and trade secrets of HaL
32  * Computer Systems, Inc.  Use, disclosure, or reproduction is prohibited
33  * without the prior express written permission of HaL Computer Systems, Inc.
34  * 
35  *                         RESTRICTED RIGHTS LEGEND
36  * Use, duplication, or disclosure by the Government is subject to
37  * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
38  * Technical Data and Computer Software clause at DFARS 252.227-7013.
39  *                        HaL Computer Systems, Inc.
40  *                  1315 Dell Avenue, Campbell, CA  95008
41  * 
42  */
43
44 #define C_TOC_Element
45 #define L_Basic
46
47 #define C_WindowSystem
48 #define L_Other
49
50 #define C_PixmapGraphic
51 #define L_Graphics
52 #define C_GraphicsMgr
53 #define L_Managers
54
55 // for GraphicsHandler 
56 #define C_NodeWindowAgent
57 #define C_GraphicAgent
58 #define L_Agents
59
60 #include "Prelude.h"
61
62 // /////////////////////////////////////////////////////////////////////////
63 // for tml
64 // /////////////////////////////////////////////////////////////////////////
65
66 Drawable
67 PixmapFromGraphic (void *gr)
68 {
69   return ((Graphic*) gr)->graphic()->pixmap();
70 }
71
72 // /////////////////////////////////////////////////////////////////////////
73 // regular constructor
74 // /////////////////////////////////////////////////////////////////////////
75
76
77 PixmapGraphic::PixmapGraphic(Pixmap pixmap, Dimension width, Dimension height,
78                              PixmapFlag flag)
79 : f_pixmap (pixmap),
80   f_width (width),
81   f_height (height),
82   f_flag (flag),
83   f_agent(0),
84   f_colormap(0),
85   f_num_colors(0),
86   f_colors(NULL),
87   f_tiff_context(NULL)
88 {
89 }
90
91 // /////////////////////////////////////////////////////////////////////////
92 // copy constructor
93 // /////////////////////////////////////////////////////////////////////////
94
95 PixmapGraphic::PixmapGraphic(const PixmapGraphic *pg)
96 : f_pixmap(pg->f_pixmap),
97   f_width(pg->f_width),
98   f_height(pg->f_height),
99   f_flag(pg->f_flag),
100   f_agent(pg->f_agent)
101 {
102   // do not want these to be copied
103   abort();
104
105 }
106
107 // /////////////////////////////////////////////////////////////////
108 // class destructor
109 // /////////////////////////////////////////////////////////////////
110
111 PixmapGraphic::~PixmapGraphic()
112 {
113   if (f_pixmap && (f_flag == NORMAL))
114   {
115     XFreePixmap (window_system().display(), f_pixmap);
116     if (f_colors)
117     {
118       XFreeColors (window_system().display(), f_colormap,
119                    f_colors, f_num_colors, 0 );
120       XFree (f_colors);
121 #ifdef DEBUG
122       printf( "pixmap %lx and its colors freed in PixmapGraphic %p\n",
123                f_pixmap, this );
124 #endif
125     }
126     if (f_tiff_context)
127     {
128 #ifdef DEBUG
129       printf( "pixmap %lx and TIFF context %p freed in PixmapGraphic %p\n",
130                f_pixmap, f_tiff_context, this );
131 #endif
132       _DtGrDestroyContext(f_tiff_context);
133       delete f_tiff_context ;   // free the struct memory we own
134     }
135   }
136   assert(!f_agent);
137 }
138
139 // hold colormap info allocated for the f_pixmap we are maintaining
140 void
141 PixmapGraphic::set_colormap( Colormap cm,
142                              int      num,
143                              Pixel   *pixels,
144                              _DtGrContext *tc )
145 {
146   f_colormap = cm;              // the containing colormap
147   f_num_colors = num;           // num colors allocated
148   f_colors = pixels;            // colors allocated
149
150   f_tiff_context = tc;          // tiff only, in lieu of above values
151 }
152
153 void
154 PixmapGraphic::register_handler(GraphicsHandler *graphics_handler)
155 {
156   UAS_Sender<DetachGraphic>::request(graphics_handler);
157   UAS_Sender<ReAttachGraphic>::request(graphics_handler);
158
159   if (f_agent != NULL)
160     graphics_handler->UAS_Sender<DisplayGraphic>::request(f_agent);
161
162 }