~canonical-dx-team/ubuntu/maverick/gtk+2.0/menuproxy

« back to all changes in this revision

Viewing changes to gdk/directfb/gdkcolor-directfb.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-05-04 12:24:25 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20070504122425-0m8midgzrp40y8w2
Tags: 2.10.12-1ubuntu1
* Sync with Debian
* New upstream version:
  Fixed bugs:
  - 379414 file chooser warnings when changing path in the entry
  - 418585 GtkFileChooserDefault sizing code is not DPI independent
  - 419568 Crash in search if start with special letter
  - 435062 build dies with icon cache validation
  - 379399 Segfault to call gtk_print_operation_run twice.
  - 387889 cups backend has problems when there are too many printers
  - 418531 invalid read to gtkicontheme.c gtk_icon_theme_lookup_icon...
  - 423916 crash in color scheme code
  - 424042 Segmentation fault while quickly pressing Alt+arrows
  - 415260 Protect against negative indices when setting values in G...
  - 419171 XGetVisualInfo() may not set nxvisuals
  - 128852 Gdk cursors don't look good on win32
  - 344657 Ctrl-H doesn't toggle "Show Hidden Files" setting
  - 345345 PrintOperation::paginate is not emitted for class handler
  - 347567 GtkPrintOperation::end-print is not emitted if it's cance...
  - 369112 gtk_ui_manager_add_ui should accept unnamed separator
  - 392015 Selected menu item invisible on Windows Vista
  - 399253 MS-Windows Theme Bottom Tab placement rendering glitches
  - 399425 gtk_input_dialog_fill_axes() adds child to gtkscrolledwin...
  - 403251 [patch] little memory leak in GtkPrintJob
  - 403267 [patch] memory leak in GtkPageSetupUnixDialog
  - 403470 MS-Windows Theme tab placement other than on top leaks a ...
  - 404506 Windows system fonts that have multi-byte font names cann...
  - 405089 Incorrect window placement for GtkEventBox private window
  - 405515 Minor leak in gtkfilesystemmodel.c
  - 405539 gdk_pixbuf_save() for PNG saver can return FALSE without ...
  - 415681 gdk_window_clear_area includes an extra line and column o...
  - 418219 GtkRecentChooser should apply filter before sorting and c...
  - 418403 Scroll to printer after selecting it from settings
  - 421985 _gtk_print_operation_platform_backend_launch_preview
  - 421990 gtk_print_job_get_surface
  - 421993 gtk_print_operation_init
  - 423064 Conditional jump or move depends on uninitialised value(s...
  - 423722 Fix printing header in gtk-demo
  - 424168 gtk_print_operation_run on async preview
  - 425655 Don't install gtk+-unix-print-2.0.pc on non-UNIX platforms
  - 425786 GDK segfaults if XineramaQueryScreens fails
  - 428665 Lpr Backend gets stuck in infinite loop during gtk_enumer...
  - 429902 GtkPrintOperation leaks cairo contextes
  - 431997 First delay of GdkPixbufAnimationIter is wrong
  - 433242 Inconsistent scroll arrow position calculations
  - 433972 Placing gtk.Expander inside a gtk.TextView() changes gtk....
  - 434261 _gtk_toolbar_elide_underscores incorrectly handles some s...
  - 383354 ctrl-L should make 'Location' entry disappear
  - 418673 gtk_recent_manager_add_item
  - 429732 gtk_accel_group_finalize accesses invalid memory
  - 435028 WM_CLIENT_LEADER is wrong on the leader_window
  - 431067 Background of the header window is not updated
  - 338843 add recent files support inside the ui manager
  - 148535 add drop shadow to menus, tooltips, etc. under Windows XP
* debian/control.in:
  - Conflicts on ubuntulooks (<= 0.9.11-1)
* debian/patches/15_default-fallback-icon-theme.patch:
  - patch from Debian, fallback on gnome icon theme

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
23
 */
 
24
 
 
25
/*
 
26
 * GTK+ DirectFB backend
 
27
 * Copyright (C) 2001-2002  convergence integrated media GmbH
 
28
 * Copyright (C) 2002       convergence GmbH
 
29
 * Written by Denis Oliver Kropp <dok@convergence.de> and
 
30
 *            Sven Neumann <sven@convergence.de>
 
31
 */
 
32
 
 
33
#include "config.h"
 
34
#include "gdk.h"
 
35
 
 
36
 
 
37
#include <stdio.h>
 
38
#include <stdlib.h>
 
39
#include <string.h>
 
40
 
 
41
#include "gdkdirectfb.h"
 
42
#include "gdkprivate-directfb.h"
 
43
 
 
44
#include "gdkinternals.h"
 
45
 
 
46
#include "gdkcolor.h"
 
47
#include "gdkalias.h"
 
48
 
 
49
 
 
50
typedef struct {
 
51
  GdkColorInfo     *info;
 
52
  IDirectFBPalette *palette;
 
53
} GdkColormapPrivateDirectFB;
 
54
 
 
55
 
 
56
static void  gdk_colormap_init          (GdkColormap      *colormap);
 
57
static void  gdk_colormap_class_init    (GdkColormapClass *klass);
 
58
static void  gdk_colormap_finalize      (GObject          *object);
 
59
 
 
60
static gint  gdk_colormap_alloc_pseudocolors (GdkColormap *colormap,
 
61
                                              GdkColor    *colors,
 
62
                                              gint         ncolors,
 
63
                                              gboolean     writeable,
 
64
                                              gboolean     best_match,
 
65
                                              gboolean    *success);
 
66
static void  gdk_directfb_allocate_color_key (GdkColormap *colormap);
 
67
 
 
68
 
 
69
static GObjectClass *parent_class = NULL;
 
70
 
 
71
 
 
72
GType
 
73
gdk_colormap_get_type (void)
 
74
{
 
75
  static GType object_type = 0;
 
76
 
 
77
  if (!object_type) {
 
78
    static const GTypeInfo object_info =
 
79
      {
 
80
        sizeof (GdkColormapClass),
 
81
        (GBaseInitFunc) NULL,
 
82
        (GBaseFinalizeFunc) NULL,
 
83
        (GClassInitFunc) gdk_colormap_class_init,
 
84
        NULL,           /* class_finalize */
 
85
        NULL,           /* class_data */
 
86
        sizeof (GdkColormap),
 
87
        0,              /* n_preallocs */
 
88
        (GInstanceInitFunc) gdk_colormap_init,
 
89
      };
 
90
 
 
91
    object_type = g_type_register_static (G_TYPE_OBJECT,
 
92
                                          "GdkColormap",
 
93
                                          &object_info, 0);
 
94
  }
 
95
 
 
96
  return object_type;
 
97
}
 
98
 
 
99
static void
 
100
gdk_colormap_init (GdkColormap *colormap)
 
101
{
 
102
  colormap->size           = 0;
 
103
  colormap->colors         = NULL;
 
104
  colormap->windowing_data = NULL;
 
105
}
 
106
 
 
107
static void
 
108
gdk_colormap_class_init (GdkColormapClass *klass)
 
109
{
 
110
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
111
 
 
112
  parent_class = g_type_class_peek_parent (klass);
 
113
 
 
114
  object_class->finalize = gdk_colormap_finalize;
 
115
}
 
116
 
 
117
static void
 
118
gdk_colormap_finalize (GObject *object)
 
119
{
 
120
  GdkColormap                *colormap = GDK_COLORMAP (object);
 
121
  GdkColormapPrivateDirectFB *private  = colormap->windowing_data;
 
122
 
 
123
  g_free (colormap->colors);
 
124
  colormap->colors = NULL;
 
125
 
 
126
  if (private)
 
127
    {
 
128
      g_free (private->info);
 
129
 
 
130
      if (private->palette)
 
131
        private->palette->Release (private->palette);
 
132
 
 
133
      g_free (private);
 
134
      colormap->windowing_data = NULL;
 
135
    }
 
136
 
 
137
  G_OBJECT_CLASS (parent_class)->finalize (object);
 
138
}
 
139
 
 
140
GdkColormap*
 
141
gdk_colormap_new (GdkVisual *visual,
 
142
                  gboolean   private_cmap)
 
143
{
 
144
  GdkColormap *colormap;
 
145
  gint         i;
 
146
 
 
147
  g_return_val_if_fail (visual != NULL, NULL);
 
148
 
 
149
  colormap = g_object_new (gdk_colormap_get_type (), NULL);
 
150
  colormap->visual = visual;
 
151
  colormap->size   = visual->colormap_size;
 
152
 
 
153
  switch (visual->type)
 
154
    {
 
155
    case GDK_VISUAL_PSEUDO_COLOR:
 
156
      {
 
157
        GdkColormapPrivateDirectFB *private;
 
158
        DFBPaletteDescription       dsc;
 
159
 
 
160
        colormap->colors = g_new0 (GdkColor, colormap->size);
 
161
 
 
162
        private = g_new0 (GdkColormapPrivateDirectFB, 1);
 
163
        private->info = g_new0 (GdkColorInfo, colormap->size);
 
164
 
 
165
        if (visual == gdk_visual_get_system())
 
166
          {
 
167
            /* save the first (transparent) palette entry */
 
168
            private->info[0].ref_count++;
 
169
          }
 
170
 
 
171
        dsc.flags = DPDESC_SIZE;
 
172
        dsc.size  = colormap->size;
 
173
        _gdk_display->directfb->CreatePalette (
 
174
                _gdk_display->directfb, &dsc, &private->palette);
 
175
 
 
176
        colormap->windowing_data = private;
 
177
 
 
178
        gdk_directfb_allocate_color_key (colormap);
 
179
      }
 
180
      break;
 
181
 
 
182
    case GDK_VISUAL_STATIC_COLOR:
 
183
      colormap->colors = g_new0 (GdkColor, colormap->size);
 
184
      for (i = 0; i < colormap->size; i++)
 
185
        {
 
186
          GdkColor *color = colormap->colors + i;
 
187
 
 
188
          color->pixel = i;
 
189
          color->red   = (i & 0xE0) <<  8 | (i & 0xE0);
 
190
          color->green = (i & 0x1C) << 11 | (i & 0x1C) << 3;
 
191
          color->blue  = (i & 0x03) << 14 | (i & 0x03) << 6;
 
192
        }
 
193
      break;
 
194
 
 
195
    default:
 
196
      break;
 
197
    }
 
198
 
 
199
  return colormap;
 
200
}
 
201
 
 
202
GdkScreen*
 
203
gdk_colormap_get_screen (GdkColormap *cmap)
 
204
{
 
205
  return _gdk_screen;
 
206
}
 
207
 
 
208
GdkColormap*
 
209
gdk_screen_get_system_colormap (GdkScreen *screen)
 
210
{
 
211
  static GdkColormap *colormap = NULL;
 
212
 
 
213
  if (!colormap)
 
214
    {
 
215
      GdkVisual *visual = gdk_visual_get_system();
 
216
 
 
217
      /* special case PSEUDO_COLOR to use the system palette */
 
218
      if (visual->type == GDK_VISUAL_PSEUDO_COLOR)
 
219
        {
 
220
          GdkColormapPrivateDirectFB *private;
 
221
          IDirectFBSurface           *surface;
 
222
 
 
223
          colormap = g_object_new (gdk_colormap_get_type (), NULL);
 
224
 
 
225
          colormap->visual = visual;
 
226
          colormap->size   = visual->colormap_size;
 
227
          colormap->colors = g_new0 (GdkColor, colormap->size);
 
228
 
 
229
          private = g_new0 (GdkColormapPrivateDirectFB, 1);
 
230
          private->info = g_new0 (GdkColorInfo, colormap->size);
 
231
        
 
232
          surface=GDK_WINDOW_IMPL_DIRECTFB (
 
233
                                GDK_WINDOW_OBJECT (_gdk_parent_root)->impl)->drawable.surface;
 
234
          surface->GetPalette (surface, &private->palette);
 
235
 
 
236
          colormap->windowing_data = private;
 
237
 
 
238
          /* save the first (transparent) palette entry */
 
239
          private->info[0].ref_count++;
 
240
 
 
241
          gdk_directfb_allocate_color_key (colormap);
 
242
        }
 
243
      else
 
244
        {
 
245
          colormap = gdk_colormap_new (visual, FALSE);
 
246
        }
 
247
    }
 
248
 
 
249
  return colormap;
 
250
}
 
251
 
 
252
gint
 
253
gdk_colormap_get_system_size (void)
 
254
{
 
255
  GdkVisual *visual;
 
256
 
 
257
  visual = gdk_visual_get_system ();
 
258
 
 
259
  return visual->colormap_size;
 
260
}
 
261
 
 
262
void
 
263
gdk_colormap_change (GdkColormap *colormap,
 
264
                     gint         ncolors)
 
265
{
 
266
  g_message ("gdk_colormap_change() is deprecated and unimplemented");
 
267
}
 
268
 
 
269
gboolean
 
270
gdk_colors_alloc (GdkColormap   *colormap,
 
271
                  gboolean       contiguous,
 
272
                  gulong        *planes,
 
273
                  gint           nplanes,
 
274
                  gulong        *pixels,
 
275
                  gint           npixels)
 
276
{
 
277
  /* g_message ("gdk_colors_alloc() is deprecated and unimplemented"); */
 
278
 
 
279
  return TRUE;  /* return TRUE here to make GdkRGB happy */
 
280
}
 
281
 
 
282
void
 
283
gdk_colors_free (GdkColormap *colormap,
 
284
                 gulong      *in_pixels,
 
285
                 gint         in_npixels,
 
286
                 gulong       planes)
 
287
{
 
288
  /* g_message ("gdk_colors_free() is deprecated and unimplemented"); */
 
289
}
 
290
 
 
291
void
 
292
gdk_colormap_free_colors (GdkColormap *colormap,
 
293
                          GdkColor    *colors,
 
294
                          gint         ncolors)
 
295
{
 
296
  GdkColormapPrivateDirectFB *private;
 
297
  gint                        i;
 
298
 
 
299
  g_return_if_fail (GDK_IS_COLORMAP (colormap));
 
300
  g_return_if_fail (colors != NULL);
 
301
 
 
302
  private = colormap->windowing_data;
 
303
  if (!private)
 
304
    return;
 
305
 
 
306
  for (i = 0; i < ncolors; i++)
 
307
    {
 
308
      gint  index = colors[i].pixel;
 
309
 
 
310
      if (index < 0 || index >= colormap->size)
 
311
        continue;
 
312
 
 
313
      if (private->info[index].ref_count)
 
314
        private->info[index].ref_count--;
 
315
    }
 
316
}
 
317
 
 
318
gint
 
319
gdk_colormap_alloc_colors (GdkColormap *colormap,
 
320
                           GdkColor    *colors,
 
321
                           gint         ncolors,
 
322
                           gboolean     writeable,
 
323
                           gboolean     best_match,
 
324
                           gboolean    *success)
 
325
{
 
326
  GdkVisual *visual;
 
327
  gint       i;
 
328
 
 
329
  g_return_val_if_fail (GDK_IS_COLORMAP (colormap), 0);
 
330
  g_return_val_if_fail (colors != NULL, 0);
 
331
  g_return_val_if_fail (success != NULL, 0);
 
332
 
 
333
  switch (colormap->visual->type)
 
334
    {
 
335
    case GDK_VISUAL_TRUE_COLOR:
 
336
      visual = colormap->visual;
 
337
 
 
338
      for (i = 0; i < ncolors; i++)
 
339
        {
 
340
          colors[i].pixel =
 
341
            (((colors[i].red
 
342
               >> (16 - visual->red_prec))   << visual->red_shift)   +
 
343
             ((colors[i].green
 
344
               >> (16 - visual->green_prec)) << visual->green_shift) +
 
345
             ((colors[i].blue
 
346
               >> (16 - visual->blue_prec))  << visual->blue_shift));
 
347
 
 
348
          success[i] = TRUE;
 
349
        }
 
350
      break;
 
351
 
 
352
    case GDK_VISUAL_PSEUDO_COLOR:
 
353
      return gdk_colormap_alloc_pseudocolors (colormap,
 
354
                                              colors, ncolors,
 
355
                                              writeable, best_match,
 
356
                                              success);
 
357
      break;
 
358
 
 
359
    case GDK_VISUAL_STATIC_COLOR:
 
360
      for (i = 0; i < ncolors; i++)
 
361
        {
 
362
          colors[i].pixel = (((colors[i].red   & 0xE000) >> 8)  |
 
363
                             ((colors[i].green & 0xE000) >> 11) |
 
364
                             ((colors[i].blue  & 0xC000) >> 14));
 
365
          success[i] = TRUE;
 
366
        }
 
367
      break;
 
368
 
 
369
    default:
 
370
      for (i = 0; i < ncolors; i++)
 
371
        success[i] = FALSE;
 
372
      break;
 
373
    }
 
374
 
 
375
  return 0;
 
376
}
 
377
 
 
378
gboolean
 
379
gdk_color_change (GdkColormap *colormap,
 
380
                  GdkColor    *color)
 
381
{
 
382
  GdkColormapPrivateDirectFB *private;
 
383
  IDirectFBPalette           *palette;
 
384
 
 
385
  g_return_val_if_fail (GDK_IS_COLORMAP (colormap), FALSE);
 
386
  g_return_val_if_fail (color != NULL, FALSE);
 
387
 
 
388
  private = colormap->windowing_data;
 
389
  if (!private)
 
390
    return FALSE;
 
391
 
 
392
  palette = private->palette;
 
393
  if (!palette)
 
394
    return FALSE;
 
395
 
 
396
  if (color->pixel < 0 || color->pixel >= colormap->size)
 
397
    return FALSE;
 
398
 
 
399
  if (private->info[color->pixel].flags & GDK_COLOR_WRITEABLE)
 
400
    {
 
401
      DFBColor  entry = { 0xFF,
 
402
                          color->red   >> 8,
 
403
                          color->green >> 8,
 
404
                          color->blue  >> 8 };
 
405
 
 
406
      if (palette->SetEntries (palette, &entry, 1, color->pixel) != DFB_OK)
 
407
        return FALSE;
 
408
 
 
409
      colormap->colors[color->pixel] = *color;
 
410
      return TRUE;
 
411
    }
 
412
 
 
413
  return FALSE;
 
414
}
 
415
 
 
416
void
 
417
gdk_colormap_query_color (GdkColormap *colormap,
 
418
                          gulong       pixel,
 
419
                          GdkColor    *result)
 
420
{
 
421
  GdkVisual *visual;
 
422
 
 
423
  g_return_if_fail (GDK_IS_COLORMAP (colormap));
 
424
 
 
425
  visual = gdk_colormap_get_visual (colormap);
 
426
 
 
427
  switch (visual->type)
 
428
    {
 
429
    case GDK_VISUAL_TRUE_COLOR:
 
430
      result->red = 65535. *
 
431
        (gdouble)((pixel & visual->red_mask) >> visual->red_shift) /
 
432
        ((1 << visual->red_prec) - 1);
 
433
 
 
434
      result->green = 65535. *
 
435
        (gdouble)((pixel & visual->green_mask) >> visual->green_shift) /
 
436
        ((1 << visual->green_prec) - 1);
 
437
 
 
438
      result->blue = 65535. *
 
439
        (gdouble)((pixel & visual->blue_mask) >> visual->blue_shift) /
 
440
        ((1 << visual->blue_prec) - 1);
 
441
      break;
 
442
 
 
443
    case GDK_VISUAL_STATIC_COLOR:
 
444
    case GDK_VISUAL_PSEUDO_COLOR:
 
445
      if (pixel >= 0 && pixel < colormap->size)
 
446
        {
 
447
          result->red   = colormap->colors[pixel].red;
 
448
          result->green = colormap->colors[pixel].green;
 
449
          result->blue  = colormap->colors[pixel].blue;
 
450
        }
 
451
      else
 
452
        g_warning ("gdk_colormap_query_color: pixel outside colormap");
 
453
      break;
 
454
 
 
455
    case GDK_VISUAL_DIRECT_COLOR:
 
456
    case GDK_VISUAL_GRAYSCALE:
 
457
    case GDK_VISUAL_STATIC_GRAY:
 
458
      /* unsupported */
 
459
      g_assert_not_reached ();
 
460
      break;
 
461
    }
 
462
}
 
463
 
 
464
IDirectFBPalette *
 
465
gdk_directfb_colormap_get_palette (GdkColormap *colormap)
 
466
{
 
467
  GdkColormapPrivateDirectFB *private;
 
468
 
 
469
  g_return_val_if_fail (GDK_IS_COLORMAP (colormap), NULL);
 
470
 
 
471
  private = colormap->windowing_data;
 
472
 
 
473
  if (private && private->palette)
 
474
    return private->palette;
 
475
  else
 
476
    return NULL;
 
477
}
 
478
 
 
479
static gint
 
480
gdk_colormap_alloc_pseudocolors (GdkColormap *colormap,
 
481
                                 GdkColor    *colors,
 
482
                                 gint         ncolors,
 
483
                                 gboolean     writeable,
 
484
                                 gboolean     best_match,
 
485
                                 gboolean    *success)
 
486
{
 
487
  GdkColormapPrivateDirectFB *private = colormap->windowing_data;
 
488
  IDirectFBPalette           *palette;
 
489
  gint                        i, j;
 
490
  gint                        remaining = ncolors;
 
491
 
 
492
  palette = private->palette;
 
493
 
 
494
  for (i = 0; i < ncolors; i++)
 
495
    {
 
496
      guint     index;
 
497
      DFBColor  lookup = { 0xFF,
 
498
                           colors[i].red   >> 8,
 
499
                           colors[i].green >> 8,
 
500
                           colors[i].blue  >> 8 };
 
501
 
 
502
      success[i] = FALSE;
 
503
 
 
504
      if (writeable)
 
505
        {
 
506
          /* look for an empty slot and allocate a new color */
 
507
          for (j = 0; j < colormap->size; j++)
 
508
            if (private->info[j].ref_count == 0)
 
509
              {
 
510
                index = j;
 
511
 
 
512
                palette->SetEntries (palette, &lookup, 1, index);
 
513
 
 
514
                private->info[index].flags = GDK_COLOR_WRITEABLE;
 
515
 
 
516
                colors[i].pixel = index;
 
517
                colormap->colors[index] = colors[i];
 
518
 
 
519
                goto allocated;
 
520
              }
 
521
        }
 
522
      else
 
523
        {
 
524
          palette->FindBestMatch (palette,
 
525
                                  lookup.r, lookup.g, lookup.b, lookup.a,
 
526
                                  &index);
 
527
 
 
528
          if (index < 0 || index > colormap->size)
 
529
            continue;
 
530
 
 
531
          /* check if we have an exact (non-writeable) match */
 
532
          if (private->info[index].ref_count &&
 
533
              !(private->info[index].flags & GDK_COLOR_WRITEABLE))
 
534
            {
 
535
              DFBColor  entry;
 
536
 
 
537
              palette->GetEntries (palette, &entry, 1, index);
 
538
 
 
539
              if (entry.a == 0xFF &&
 
540
                  entry.r == lookup.r && entry.g == lookup.g && entry.b == lookup.b)
 
541
                {
 
542
                  colors[i].pixel = index;
 
543
 
 
544
                  goto allocated;
 
545
                }
 
546
            }
 
547
 
 
548
          /* look for an empty slot and allocate a new color */
 
549
          for (j = 0; j < colormap->size; j++)
 
550
            if (private->info[j].ref_count == 0)
 
551
              {
 
552
                index = j;
 
553
 
 
554
                palette->SetEntries (palette, &lookup, 1, index);
 
555
                private->info[index].flags = 0;
 
556
 
 
557
                colors[i].pixel = index;
 
558
                colormap->colors[index] = colors[i];
 
559
 
 
560
                goto allocated;
 
561
              }
 
562
 
 
563
          /* if that failed, use the best match */
 
564
          if (best_match &&
 
565
              !(private->info[index].flags & GDK_COLOR_WRITEABLE))
 
566
            {
 
567
#if 0
 
568
               g_print ("best match for (%d %d %d)  ",
 
569
                       colormap->colors[index].red,
 
570
                       colormap->colors[index].green,
 
571
                       colormap->colors[index].blue);
 
572
#endif
 
573
 
 
574
              colors[i].pixel = index;
 
575
 
 
576
              goto allocated;
 
577
            }
 
578
        }
 
579
 
 
580
      /* if we got here, all attempts failed */
 
581
      continue;
 
582
 
 
583
    allocated:
 
584
      private->info[index].ref_count++;
 
585
 
 
586
#if 0
 
587
      g_print ("cmap %p: allocated (%d %d %d) %d [%d]\n", colormap,
 
588
                colors[i].red, colors[i].green, colors[i].blue, colors[i].pixel,
 
589
                private->info[index].ref_count);
 
590
#endif
 
591
 
 
592
      success[i] = TRUE;
 
593
      remaining--;
 
594
    }
 
595
 
 
596
  return remaining;
 
597
}
 
598
 
 
599
/* dirty hack for color_keying */
 
600
static void
 
601
gdk_directfb_allocate_color_key (GdkColormap *colormap)
 
602
{
 
603
  GdkColormapPrivateDirectFB *private = colormap->windowing_data;
 
604
  IDirectFBPalette           *palette = private->palette;
 
605
 
 
606
  if (!gdk_directfb_enable_color_keying)
 
607
    return;
 
608
 
 
609
  palette->SetEntries (palette, &gdk_directfb_bg_color, 1, 255);
 
610
 
 
611
  colormap->colors[255].pixel = 255;
 
612
  colormap->colors[255].red   = ((gdk_directfb_bg_color_key.r << 8)
 
613
                                 | gdk_directfb_bg_color_key.r);
 
614
  colormap->colors[255].green = ((gdk_directfb_bg_color_key.g << 8)
 
615
                                 | gdk_directfb_bg_color_key.g);
 
616
  colormap->colors[255].blue  = ((gdk_directfb_bg_color_key.b << 8)
 
617
                                 | gdk_directfb_bg_color_key.b);
 
618
 
 
619
  private->info[255].ref_count++;
 
620
}
 
621
 
 
622
#define __GDK_COLOR_X11_C__
 
623
#include "gdkaliasdef.c"