]> Pileus Git - ~andy/gtk/blob - gdk/linux-fb/gdkpixmap-fb.c
Don't mangle sequences of consecutive \n or \r.
[~andy/gtk] / gdk / linux-fb / gdkpixmap-fb.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GTK+ Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26
27 #include "config.h"
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <string.h>
31 /* Needed for SEEK_END in SunOS */
32 #include <unistd.h>
33
34 #include "gdkpixmap.h"
35 #include "gdkfb.h"
36 #include "gdkprivate-fb.h"
37
38 typedef struct
39 {
40   gchar *color_string;
41   GdkColor color;
42   gint transparent;
43 } _GdkPixmapColor;
44
45 typedef struct
46 {
47   guint ncolors;
48   GdkColormap *colormap;
49   gulong pixels[1];
50 } _GdkPixmapInfo;
51
52 static gpointer parent_class = NULL;
53
54 static void
55 gdk_pixmap_impl_fb_init (GdkPixmapFBData *impl)
56 {
57   GdkDrawableFBData *private = (GdkDrawableFBData *)impl;
58
59   private->window_type = GDK_DRAWABLE_PIXMAP;
60   private->colormap = gdk_colormap_ref (gdk_colormap_get_system());
61   private->mem = NULL;
62   private->width = 1;
63   private->height = 1;
64 }
65
66 static void
67 gdk_pixmap_impl_fb_finalize (GObject *object)
68 {
69   g_free (GDK_DRAWABLE_FBDATA (object)->mem);
70
71   G_OBJECT_CLASS (parent_class)->finalize (object);
72 }
73
74 static void
75 gdk_pixmap_impl_fb_class_init (GdkPixmapFBClass *klass)
76 {
77   GObjectClass *object_class = G_OBJECT_CLASS (klass);
78   /*  GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass); */
79   
80   parent_class = g_type_class_peek_parent (klass);
81
82   object_class->finalize = gdk_pixmap_impl_fb_finalize;
83 }
84
85 GType
86 _gdk_pixmap_impl_get_type (void)
87 {
88   static GType object_type = 0;
89
90   if (!object_type)
91     {
92       static const GTypeInfo object_info =
93       {
94         sizeof (GdkPixmapFBClass),
95         (GBaseInitFunc) NULL,
96         (GBaseFinalizeFunc) NULL,
97         (GClassInitFunc) gdk_pixmap_impl_fb_class_init,
98         NULL,           /* class_finalize */
99         NULL,           /* class_data */
100         sizeof (GdkPixmapFBData),
101         0,              /* n_preallocs */
102         (GInstanceInitFunc) gdk_pixmap_impl_fb_init
103       };
104       
105       object_type = g_type_register_static (gdk_drawable_impl_fb_get_type(),
106                                             "GdkPixmapFB",
107                                             &object_info,
108                                             0);
109     }
110   
111   return object_type;
112 }
113
114 GdkPixmap*
115 gdk_pixmap_new (GdkWindow *window,
116                 gint       width,
117                 gint       height,
118                 gint       depth)
119 {
120   GdkPixmap *pixmap;
121   GdkDrawableFBData *private;
122
123   g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
124   g_return_val_if_fail ((window != NULL) || (depth != -1), NULL);
125   g_return_val_if_fail ((width != 0) && (height != 0), NULL);
126   
127   if (!window)
128     window = _gdk_parent_root;
129
130   if (depth == -1)
131     depth = gdk_drawable_get_visual (window)->depth;
132
133   pixmap = (GdkPixmap *)g_object_new (gdk_pixmap_get_type (), NULL);
134   private = GDK_DRAWABLE_IMPL_FBDATA (pixmap);
135   private->rowstride = (width * depth + 7) / 8; /* Round up to nearest whole byte */
136   private->mem = g_malloc (private->rowstride * height);
137   private->abs_x = 0;
138   private->abs_y = 0;
139   private->llim_x = 0;
140   private->llim_y = 0;
141   private->lim_x = width;
142   private->lim_y = height;
143   private->width = width;
144   private->height = height;
145   private->depth = ((GdkPixmapObject *)pixmap)->depth = depth;
146
147   return pixmap;
148 }
149
150 GdkPixmap *
151 gdk_bitmap_create_from_data (GdkWindow   *window,
152                              const gchar *data,
153                              gint         width,
154                              gint         height)
155 {
156   GdkPixmap *pixmap;
157
158   g_return_val_if_fail (data != NULL, NULL);
159   g_return_val_if_fail ((width != 0) && (height != 0), NULL);
160   g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
161
162   if (!window)
163     window = _gdk_parent_root;
164
165   pixmap = gdk_pixmap_new (window, width, height, 1);
166
167   memcpy (GDK_DRAWABLE_IMPL_FBDATA (pixmap)->mem, data, ((width + 7) / 8) * height);
168
169   return pixmap;
170 }
171
172 GdkPixmap*
173 gdk_pixmap_create_from_data (GdkWindow   *window,
174                              const gchar *data,
175                              gint         width,
176                              gint         height,
177                              gint         depth,
178                              GdkColor    *fg,
179                              GdkColor    *bg)
180 {
181   GdkPixmap *pixmap;
182
183   g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
184   g_return_val_if_fail (data != NULL, NULL);
185   g_return_val_if_fail (fg != NULL, NULL);
186   g_return_val_if_fail (bg != NULL, NULL);
187   g_return_val_if_fail ((window != NULL) || (depth != -1), NULL);
188   g_return_val_if_fail ((width != 0) && (height != 0), NULL);
189
190   if (!window)
191     window = _gdk_parent_root;
192
193   if (depth == -1)
194     depth = gdk_drawable_get_visual (window)->depth;
195
196   pixmap = gdk_pixmap_new (window, width, height, depth);
197
198   memcpy (GDK_DRAWABLE_IMPL_FBDATA (pixmap)->mem, data, height * GDK_DRAWABLE_IMPL_FBDATA (pixmap)->rowstride);
199
200   return pixmap;
201 }
202
203 GdkPixmap*
204 gdk_pixmap_foreign_new (GdkNativeWindow anid)
205 {
206   return (GdkPixmap*) gdk_drawable_ref (anid);
207 }
208
209 GdkPixmap*
210 gdk_pixmap_lookup (GdkNativeWindow anid)
211 {
212   return (GdkPixmap*) (anid);
213 }
214