1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10#ifdef ENABLE_QUICKSTART_LIBPNG
11
12#include <X11/Xlib.h>
13#include <X11/Xatom.h>
14#include <X11/Xutil.h>
15
16#ifdef USE_XINERAMA
17#include <X11/extensions/Xinerama.h>
18#endif
19
20#include "osl/endian.h"
21#include <fcntl.h>
22#include <stdint.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <unistd.h>
27
28#include <png.h>
29
30#include <osl/process.h>
31#include <osl/thread.h>
32#include <rtl/bootstrap.h>
33#include <rtl/ustrbuf.h>
34
35#include "splashx.h"
36
37typedef struct {
38 unsigned char b, g, r;
39} color_t;
40
41struct splash
42{
43 Display* display;
44 int screen;
45 int depth;
46 Visual* visual;
47
48 int width;
49 int height;
50
51 Colormap color_map;
52 Window win;
53 GC gc;
54
55// Progress bar values
56// taken from desktop/source/splash/splash.cxx
57 int tlx;
58 int tly;
59 int barwidth;
60 int barheight;
61 int barspace;
62 color_t barcol;
63 color_t framecol;
64
65 XColor barcolor;
66 XColor framecolor;
67
68 unsigned char** bitmap_rows;
69 png_structp png_ptr;
70 png_infop info_ptr;
71
72};
73
74#define WINDOW_WIDTH 440
75#define WINDOW_HEIGHT 299
76
77#define PROGRESS_XOFFSET 12
78#define PROGRESS_YOFFSET 18
79#define PROGRESS_BARSPACE 2
80
81/* libpng-1.2.41 */
82#ifndef PNG_TRANSFORM_GRAY_TO_RGB
83# define PNG_TRANSFORM_GRAY_TO_RGB 0x2000
84#endif
85
86static int splash_load_bmp( struct splash* splash, const char *filename )
87{
88 FILE *file;
89
90 if ( !(file = fopen( filename, "r" ) ) )
91 return 0;
92
93 splash->png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING, 0, 0, 0 );
94 splash->info_ptr = png_create_info_struct(splash->png_ptr);
95 png_init_io( splash->png_ptr, file );
96
97 if( setjmp( png_jmpbuf( splash->png_ptr ) ) )
98 {
99 png_destroy_read_struct( &(splash->png_ptr), &(splash->info_ptr), NULL );
100 fclose( file );
101 return 0;
102 }
103
104 png_read_png( splash->png_ptr, splash->info_ptr,
105 PNG_TRANSFORM_EXPAND | PNG_TRANSFORM_STRIP_ALPHA |
106 PNG_TRANSFORM_GRAY_TO_RGB | PNG_TRANSFORM_BGR, NULL);
107
108 splash->bitmap_rows = png_get_rows( splash->png_ptr, splash->info_ptr );
109 splash->width = png_get_image_width( splash->png_ptr, splash->info_ptr );
110 splash->height = png_get_image_height( splash->png_ptr, splash->info_ptr );
111
112 fclose( file );
113 return 1;
114}
115
116static void setup_color( int val[3], color_t *col )
117{
118 if ( val[0] < 0 || val[1] < 0 || val[2] < 0 )
119 return;
120
121#define CONVERT_COLOR( from,to ) if ( from < 0 ) to = 0; else if ( from > 255 ) to = 255; else to = from;
122 CONVERT_COLOR( val[0], col->r );
123 CONVERT_COLOR( val[1], col->g );
124 CONVERT_COLOR( val[2], col->b );
125#undef CONVERT_COLOR
126}
127
128/* Fill 'array' with values of the key 'name'.
129 Its value is a comma delimited list of integers */
130static void get_bootstrap_value( int *array, int size, rtlBootstrapHandle handle, const char *name )
131{
132 rtl_uString *pKey = NULL, *pValue = NULL;
133
134 /* get the value from the ini file */
135 rtl_uString_newFromAscii( &pKey, name );
136 rtl_bootstrap_get_from_handle( handle, pKey, &pValue, NULL );
137
138 /* the value is several numbers delimited by ',' - parse it */
139 if ( rtl_uString_getLength( pValue ) > 0 )
140 {
141 rtl_uString *pToken = NULL;
142 int i = 0;
143 sal_Int32 nIndex = 0;
144 for ( ; ( nIndex >= 0 ) && ( i < size ); ++i )
145 {
146 nIndex = rtl_uString_getToken( &pToken, pValue, 0, ',', nIndex );
147 array[i] = rtl_ustr_toInt32( rtl_uString_getStr( pToken ), 10 );
148 }
149
150 rtl_uString_release( pToken );
151 }
152
153 /* cleanup */
154 rtl_uString_release( pKey );
155 rtl_uString_release( pValue );
156}
157
158// setup
159static void splash_setup( struct splash* splash, int barc[3], int framec[3], int posx, int posy, int w, int h )
160{
161 if ( splash->width <= 500 )
162 {
163 splash->barwidth = splash->width - ( 2 * PROGRESS_XOFFSET );
164 splash->barheight = 6;
165 splash->tlx = PROGRESS_XOFFSET;
166 splash->tly = splash->height - PROGRESS_YOFFSET;
167
168 splash->barcol.r = 0;
169 splash->barcol.g = 0;
170 splash->barcol.b = 128;
171 }
172
173 if ( posx >= 0 )
174 splash->tlx = posx;
175 if ( posy >= 0 )
176 splash->tly = posy;
177 if ( w >= 0 )
178 splash->barwidth = w;
179 if ( h >= 0 )
180 splash->barheight = h;
181
182 setup_color( barc, &(splash->barcol) );
183 setup_color( framec, &(splash->framecol) );
184}
185
186// Universal shift: bits >= 0 - left, otherwise right
187#define SHIFT( x, bits ) ( ( (bits) >= 0 )? ( (x) << (bits) ): ( (x) >> -(bits) ) )
188
189// Position of the highest bit (more or less integer log2)
190static inline int HIGHEST_BIT( unsigned long x )
191{
192 int i = 0;
193 for ( ; x; ++i )
194 x >>= 1;
195
196 return i;
197}
198
199// Number of bits set to 1
200static inline int BITS( unsigned long x )
201{
202 int i = 0;
203 for ( ; x; x >>= 1 )
204 if ( x & 1UL )
205 ++i;
206
207 return i;
208}
209
210// Set 'bitmap' as the background of our 'win' window
211static void create_pixmap(struct splash* splash)
212{
213 Pixmap pixmap;
214 GC pixmap_gc;
215 unsigned long value_mask = 0;
216 XGCValues values;
217
218 if ( !splash->bitmap_rows )
219 {
220 return;
221 }
222 pixmap = XCreatePixmap( splash->display, splash->win, splash->width, splash->height, splash->depth );
223
224 pixmap_gc = XCreateGC( splash->display, pixmap, value_mask, &values );
225
226 if ( splash->visual->class == TrueColor )
227 {
228 unsigned long red_mask = splash->visual->red_mask;
229 unsigned long green_mask = splash->visual->green_mask;
230 unsigned long blue_mask = splash->visual->blue_mask;
231
232 unsigned long red_delta_mask = ( 1UL << ( 8 - BITS( red_mask ) ) ) - 1;
233 unsigned long green_delta_mask = ( 1UL << ( 8 - BITS( green_mask ) ) ) - 1;
234 unsigned long blue_delta_mask = ( 1UL << ( 8 - BITS( blue_mask ) ) ) - 1;
235
236 int red_shift = HIGHEST_BIT( red_mask ) - 8;
237 int green_shift = HIGHEST_BIT( green_mask ) - 8;
238 int blue_shift = HIGHEST_BIT( blue_mask ) - 8;
239
240 XImage* image = XCreateImage( splash->display, splash->visual, splash->depth, ZPixmap,
241 0, NULL, splash->width, splash->height, 32, 0 );
242
243 int bytes_per_line = image->bytes_per_line;
244 int bpp = image->bits_per_pixel;
245 int byte_order = image->byte_order;
246#if defined( _LITTLE_ENDIAN )
247 int machine_byte_order = LSBFirst;
248#elif defined( _BIG_ENDIAN )
249 int machine_byte_order = MSBFirst;
250#else
251 {
252 fprintf( stderr, "Unsupported machine endianity.\n" );
253 XFreeGC( splash->display, pixmap_gc );
254 XFreePixmap( splash->display, pixmap );
255 XDestroyImage( image );
256 return;
257 }
258#endif
259
260 char *data = malloc( splash->height * bytes_per_line );
261 char *out = data;
262 image->data = data;
263
264 // The following dithers & converts the color_t color to one
265 // acceptable for the visual
266#define COPY_IN_OUT( pix_size, code ) \
267 { \
268 int x, y; \
269 for ( y = 0; y < splash->height; ++y ) \
270 { \
271 unsigned long red_delta = 0, green_delta = 0, blue_delta = 0; \
272 color_t *in = (color_t *)(splash->bitmap_rows[y]); \
273 out = data + y * bytes_per_line; \
274 for ( x = 0; x < splash->width; ++x, ++in ) \
275 { \
276 unsigned long red = in->r + red_delta; \
277 unsigned long green = in->g + green_delta; \
278 unsigned long blue = in->b + blue_delta; \
279 unsigned long pixel = 0; \
280 uint32_t tmp = 0; \
281 (void) tmp; \
282 red_delta = red & red_delta_mask; \
283 green_delta = green & green_delta_mask; \
284 blue_delta = blue & blue_delta_mask; \
285 if ( red > 255 ) \
286 red = 255; \
287 if ( green > 255 ) \
288 green = 255; \
289 if ( blue > 255 ) \
290 blue = 255; \
291 pixel = \
292 ( SHIFT( red, red_shift ) & red_mask ) | \
293 ( SHIFT( green, green_shift ) & green_mask ) | \
294 ( SHIFT( blue, blue_shift ) & blue_mask ); \
295 code \
296 } \
297 } \
298 }
299
300 if ( bpp == 32 )
301 {
302 if ( machine_byte_order == byte_order )
303 COPY_IN_OUT( 4, *( (uint32_t *)out ) = (uint32_t)pixel; out += 4; )
304 else
305 COPY_IN_OUT( 4, tmp = pixel;
306 *( (uint8_t *)out ) = *( (uint8_t *)(&tmp) + 3 );
307 *( (uint8_t *)out + 1 ) = *( (uint8_t *)(&tmp) + 2 );
308 *( (uint8_t *)out + 2 ) = *( (uint8_t *)(&tmp) + 1 );
309 *( (uint8_t *)out + 3 ) = *( (uint8_t *)(&tmp) );
310 out += 4; )
311 }
312 else if ( bpp == 24 )
313 {
314 if ( machine_byte_order == byte_order && byte_order == LSBFirst )
315 COPY_IN_OUT( 3, *( (color_t *)out ) = *( (color_t *)( &pixel ) ); out += 3; )
316 else if ( machine_byte_order == byte_order && byte_order == MSBFirst )
317 COPY_IN_OUT( 3, tmp = pixel;
318 *( (uint8_t *)out ) = *( (uint8_t *)(&tmp) + 1 );
319 *( (uint8_t *)out + 1 ) = *( (uint8_t *)(&tmp) + 2 );
320 *( (uint8_t *)out + 2 ) = *( (uint8_t *)(&tmp) + 3 );
321 out += 3; )
322 else
323 COPY_IN_OUT( 3, tmp = pixel;
324 *( (uint8_t *)out ) = *( (uint8_t *)(&tmp) + 3 );
325 *( (uint8_t *)out + 1 ) = *( (uint8_t *)(&tmp) + 2 );
326 *( (uint8_t *)out + 2 ) = *( (uint8_t *)(&tmp) + 1 );
327 out += 3; )
328 }
329 else if ( bpp == 16 )
330 {
331 if ( machine_byte_order == byte_order )
332 COPY_IN_OUT( 2, *( (uint16_t *)out ) = (uint16_t)pixel; out += 2; )
333 else
334 COPY_IN_OUT( 2, tmp = pixel;
335 *( (uint8_t *)out ) = *( (uint8_t *)(&tmp) + 1 );
336 *( (uint8_t *)out + 1 ) = *( (uint8_t *)(&tmp) );
337 out += 2; );
338 }
339 else if ( bpp == 8 )
340 {
341 COPY_IN_OUT( 1, *( (uint8_t *)out ) = (uint8_t)pixel; ++out; )
342 }
343 else
344 {
345 fprintf( stderr, "Unsupported depth: %d bits per pixel.\n", bpp );
346 XFreeGC( splash->display, pixmap_gc );
347 XFreePixmap( splash->display, pixmap );
348 XDestroyImage( image );
349 return;
350 }
351
352#undef COPY_IN_OUT
353
354 XPutImage( splash->display, pixmap, pixmap_gc, image, 0, 0, 0, 0, splash->width, splash->height );
355 XDestroyImage( image );
356 }
357 else //if ( depth == 1 || visual->class == DirectColor )
358 {
359 // FIXME Something like the following, but faster ;-) - XDrawPoint is not
360 // a good idea...
361 int x, y;
362 for ( y = 0; y < splash->height; ++y )
363 {
364 color_t* color = (color_t *)&(splash->bitmap_rows[y]);
365
366 int delta = 0;
367 for ( x = 0; x < splash->width; ++x, ++color )
368 {
369 int rnd = (int)( ( (long)( random() - RAND_MAX/2 ) * 32000 )/RAND_MAX );
370 int luminance = delta + rnd + 299 * (int)color->r + 587 * (int)color->g + 114 * (int)color->b;
371
372 if ( luminance < 128000 )
373 {
374 XSetForeground( splash->display, pixmap_gc, BlackPixel( splash->display, splash->screen ) );
375 delta = luminance;
376 }
377 else
378 {
379 XSetForeground( splash->display, pixmap_gc, WhitePixel( splash->display, splash->screen ) );
380 delta = luminance - 255000;
381 }
382
383 XDrawPoint( splash->display, pixmap, pixmap_gc, x, y );
384 }
385 }
386 }
387
388 XSetWindowBackgroundPixmap( splash->display, splash->win, pixmap );
389
390 XFreeGC( splash->display, pixmap_gc );
391 XFreePixmap( splash->display, pixmap );
392}
393
394// The old method of hiding the window decorations
395static void suppress_decorations_motif(struct splash* splash)
396{
397 struct
398 {
399 unsigned long flags, functions, decorations;
400 long input_mode;
401 } mwmhints;
402
403 Atom a = XInternAtom( splash->display, "_MOTIF_WM_HINTS", False );
404
405 mwmhints.flags = 15; // functions, decorations, input_mode, status
406 mwmhints.functions = 2; // ?
407 mwmhints.decorations = 0;
408 mwmhints.input_mode = 0;
409
410 XChangeProperty( splash->display, splash->win, a, a, 32,
411 PropModeReplace, (unsigned char*)&mwmhints, 5 );
412}
413
414// This is a splash, set it as such.
415// If it fails, just hide the decorations...
416static void suppress_decorations(struct splash* splash)
417{
418 Atom atom_type = XInternAtom( splash->display, "_NET_WM_WINDOW_TYPE", True );
419 Atom atom_splash = XInternAtom( splash->display, "_NET_WM_WINDOW_TYPE_SPLASH", True );
420
421 if ( atom_type != None && atom_splash != None )
422 XChangeProperty( splash->display, splash->win, atom_type, XA_ATOM, 32,
423 PropModeReplace, (unsigned char*)&atom_splash, 1 );
424 //else
425 suppress_decorations_motif(splash); // FIXME: Unconditional until Metacity/compiz's SPLASH handling is fixed
426}
427
428/**
429 * Create the window for the splash screen
430 *
431 * @return Success: 1; Failure: 0
432 */
433static int splash_create_window( struct splash* splash, int argc, char** argv )
434{
435 char *display_name = NULL;
436 int i;
437 Window root_win;
438 int display_width = 0;
439 int display_height = 0;
440 int display_x_pos = 0;
441 int display_y_pos = 0;
442 unsigned long value_mask = 0;
443 XGCValues values;
444 const char* name = "LibreOffice";
445 const char* icon = "icon"; // FIXME
446 XSizeHints size_hints;
447#ifdef USE_XINERAMA
448 int n_xinerama_screens = 1;
449 XineramaScreenInfo* p_screens = NULL;
450#endif
451
452 for ( i = 0; i < argc; i++ )
453 {
454 if ( !strcmp( argv[i], "-display" ) || !strcmp( argv[i], "--display" ) )
455 {
456 display_name = ( i + 1 < argc )? argv[i+1]: NULL;
457 }
458 }
459
460 if ( !display_name )
461 {
462 display_name = getenv( "DISPLAY" );
463 }
464 // init display
465 splash->display = XOpenDisplay( display_name );
466 if ( !splash->display )
467 {
468 fprintf( stderr, "Failed to open display\n" );
469 return 0;
470 }
471
472 // create the window
473 splash->screen = DefaultScreen( splash->display );
474 splash->depth = DefaultDepth( splash->display, splash->screen );
475 splash->color_map = DefaultColormap( splash->display, splash->screen );
476 splash->visual = DefaultVisual( splash->display, splash->screen );
477
478 root_win = RootWindow( splash->display, splash->screen );
479 display_width = DisplayWidth( splash->display, splash->screen );
480 display_height = DisplayHeight( splash->display, splash->screen );
481
482#ifdef USE_XINERAMA
483 p_screens = XineramaQueryScreens( splash->display, &n_xinerama_screens );
484 if( p_screens )
485 {
486 for( i=0; i < n_xinerama_screens; i++ )
487 {
488 if ( p_screens[i].screen_number == splash->screen )
489 {
490 display_width = p_screens[i].width;
491 display_height = p_screens[i].height;
492 display_x_pos = p_screens[i].x_org;
493 display_y_pos = p_screens[i].y_org;
494 break;
495 }
496 }
497 XFree( p_screens );
498 }
499#endif
500
501 splash->win = XCreateSimpleWindow( splash->display, root_win,
502 (display_x_pos + (display_width - splash->width)/2),
503 (display_y_pos + (display_height - splash->height)/2),
504 splash->width, splash->height, 0,
505 BlackPixel( splash->display, splash->screen ), BlackPixel( splash->display, splash->screen ) );
506
507 XSetWindowColormap( splash->display, splash->win, splash->color_map );
508
509 // setup colors
510#define FILL_COLOR( xcol,col ) xcol.red = 256*col.r; xcol.green = 256*col.g; xcol.blue = 256*col.b;
511 FILL_COLOR( splash->barcolor, splash->barcol );
512 FILL_COLOR( splash->framecolor, splash->framecol );
513#undef FILL_COLOR
514
515 XAllocColor( splash->display, splash->color_map, &(splash->barcolor) );
516 XAllocColor( splash->display, splash->color_map, &(splash->framecolor) );
517
518 // not resizable, no decorations, etc.
519 splash->gc = XCreateGC( splash->display, splash->win, value_mask, &values );
520
521 size_hints.flags = PPosition | PSize | PMinSize | PMaxSize;
522 size_hints.min_width = splash->width;
523 size_hints.max_width = splash->width;
524 size_hints.min_height = splash->height;
525 size_hints.max_height = splash->height;
526
527 XSetStandardProperties( splash->display, splash->win, name, icon, None,
528 0, 0, &size_hints );
529
530 // the actual work
531 suppress_decorations(splash);
532 create_pixmap(splash);
533
534 // show it
535 XSelectInput( splash->display, splash->win, 0 );
536 XMapWindow( splash->display, splash->win );
537
538 return 1;
539}
540
541// Re-draw & process the events
542// Just throwing them away - we do not need anything more...
543static void process_events(struct splash* splash)
544{
545 XEvent xev;
546 int num_events;
547
548 XFlush( splash->display );
549 num_events = XPending( splash->display );
550 while ( num_events > 0 )
551 {
552 num_events--;
553 XNextEvent( splash->display, &xev );
554 }
555}
556
557
558static rtl_String* ustr_to_str( rtl_uString* pStr )
559{
560 rtl_String *pOut = NULL;
561
562 rtl_uString2String( &pOut, rtl_uString_getStr( pStr ),
563 rtl_uString_getLength( pStr ), osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS );
564
565 return pOut;
566}
567
568#define IMG_SUFFIX ".png"
569
570static void splash_load_image( struct splash* splash, rtl_uString* pUAppPath )
571{
572 /* FIXME-BCP47: if we wanted to support language tags here that would get
573 * complicated, this is C-source not C++ so LanguageTag can't be used. For
574 * now the splash screen will have to get along with language-territory. */
575
576 char *pBuffer, *pSuffix, *pLocale;
577 int nLocSize;
578 rtl_Locale *pLoc = NULL;
579 rtl_String *pLang, *pCountry, *pAppPath;
580
581 osl_getProcessLocale (&pLoc);
582 pLang = ustr_to_str (pLoc->Language);
583 pCountry = ustr_to_str (pLoc->Country);
584
585 nLocSize = strlen (pLang->buffer) + strlen (pCountry->buffer) + 8;
586 pLocale = malloc (nLocSize);
587 pLocale[0] = '-';
588 strcpy (pLocale + 1, pLang->buffer);
589 strcat (pLocale, "_");
590 strcat (pLocale, pCountry->buffer);
591
592 rtl_string_release( pCountry );
593 rtl_string_release( pLang );
594
595 pAppPath = ustr_to_str (pUAppPath);
596 pBuffer = malloc (pAppPath->length + nLocSize + 256);
597 strcpy (pBuffer, pAppPath->buffer);
598 pSuffix = pBuffer + pAppPath->length;
599 rtl_string_release( pAppPath );
600
601 strcpy (pSuffix, "intro");
602 strcat (pSuffix, pLocale);
603 strcat (pSuffix, IMG_SUFFIX);
604 if ( splash_load_bmp( splash, pBuffer ) )
605 goto cleanup;
606
607 strcpy (pSuffix, "intro" IMG_SUFFIX);
608 if ( splash_load_bmp( splash, pBuffer ) )
609 goto cleanup;
610
611 fprintf (stderr, "Failed to find intro image\n");
612
613 cleanup:
614 free (pLocale);
615 free (pBuffer);
616}
617
618/* Load the colors and size of the splash. */
619static void splash_load_defaults( struct splash* splash, rtl_uString* pAppPath, sal_Bool* bNoDefaults )
620{
621 rtl_uString *pSettings = NULL, *pTmp = NULL;
622 rtlBootstrapHandle handle;
623 int [1] = { -1 },
624 bar[3] = { -1, -1, -1 },
625 frame[3] = { -1, -1, -1 },
626 pos[2] = { -1, -1 },
627 size[2] = { -1, -1 };
628
629 /* costruct the sofficerc file location */
630 rtl_uString_newFromAscii( &pSettings, "file://" );
631 rtl_uString_newConcat( &pSettings, pSettings, pAppPath );
632 rtl_uString_newConcat( &pSettings, pSettings, pTmp );
633 rtl_uString_newFromAscii( &pTmp, SAL_CONFIGFILE( "soffice" ) );
634 rtl_uString_newConcat( &pSettings, pSettings, pTmp );
635
636 /* use it as the bootstrap file */
637 handle = rtl_bootstrap_args_open( pSettings );
638
639 /* get the values */
640 get_bootstrap_value( logo, 1, handle, "Logo" );
641 get_bootstrap_value( bar, 3, handle, "ProgressBarColor" );
642 get_bootstrap_value( frame, 3, handle, "ProgressFrameColor" );
643 get_bootstrap_value( pos, 2, handle, "ProgressPosition" );
644 get_bootstrap_value( size, 2, handle, "ProgressSize" );
645
646 if ( logo[0] == 0 )
647 {
648 *bNoDefaults = sal_True;
649 }
650
651 splash_setup( splash, bar, frame, pos[0], pos[1], size[0], size[1] );
652
653 /* cleanup */
654 rtl_bootstrap_args_close( handle );
655 rtl_uString_release( pSettings );
656 rtl_uString_release( pTmp );
657}
658
659
660// Draw the progress
661void splash_draw_progress( struct splash* splash, int progress )
662{
663 int length = 0;
664
665 if (!splash)
666 {
667 return;
668 }
669 // sanity
670 if ( progress < 0 )
671 {
672 progress = 0;
673 }
674 if ( progress > 100 )
675 {
676 progress = 100;
677 }
678 // draw progress...
679 length = ( progress * splash->barwidth / 100 ) - ( 2 * splash->barspace );
680 if ( length < 0 )
681 {
682 length = 0;
683 }
684 // border
685 XSetForeground( splash->display, splash->gc, splash->framecolor.pixel );
686 XDrawRectangle( splash->display, splash->win, splash->gc, splash->tlx, splash->tly,
687 splash->barwidth, splash->barheight );
688
689 // progress bar
690 XSetForeground( splash->display, splash->gc, splash->barcolor.pixel );
691 XFillRectangle( splash->display, splash->win, splash->gc,
692 splash->tlx + splash->barspace, splash->tly + splash->barspace,
693 length + 1, splash->barheight - 2 * splash->barspace + 1 );
694
695 // pending events
696 process_events(splash);
697}
698
699void splash_destroy(struct splash* splash)
700{
701 if(splash)
702 {
703 if(splash->display)
704 {
705 if(splash->gc)
706 {
707 XFreeGC(splash->display, splash->gc);
708 splash->gc = NULL;
709 }
710
711 XCloseDisplay( splash->display );
712 splash->display = NULL;
713 png_destroy_read_struct( &(splash->png_ptr), &(splash->info_ptr), NULL );
714 }
715 free(splash);
716 }
717}
718
719struct splash* splash_create(rtl_uString* pAppPath, int argc, char** argv)
720{
721 struct splash* splash;
722 sal_Bool bNoDefaults = sal_False;
723
724 splash = calloc(1, sizeof(struct splash));
725 if(splash)
726 {
727 splash->width = WINDOW_WIDTH;
728 splash->height = WINDOW_HEIGHT;
729
730 splash->tlx = 212;
731 splash->tly = 216;
732 splash->barwidth = 263;
733 splash->barheight = 8;
734 splash->barspace = PROGRESS_BARSPACE;
735 splash->barcol.b = 18;
736 splash->barcol.g = 202;
737 splash->barcol.r = 157;
738 splash->framecol.b = 0xD3;
739 splash->framecol.g = 0xD3;
740 splash->framecol.r = 0xD3;
741
742 splash_load_image( splash, pAppPath );
743 splash_load_defaults( splash, pAppPath, &bNoDefaults );
744
745 if (!bNoDefaults && splash_create_window( splash, argc, argv ) )
746 {
747 splash_draw_progress( splash, 0 );
748 }
749 else
750 {
751 splash_destroy(splash);
752 splash = NULL;
753 }
754 }
755 return splash;
756}
757
758#else /* not ENABLE_QUICKSTART_LIBPNG */
759
760#include <rtl/ustrbuf.h>
761
762struct splash
763{
764};
765
766/* Stubs that will never be called in this case */
767void splash_draw_progress( struct splash* splash, int progress )
768{
769 (void)splash; (void)progress;
770}
771
772void splash_destroy(struct splash* splash)
773{
774 (void)splash;
775}
776
777struct splash* splash_create(rtl_uString* pAppPath, int argc, char** argv)
778{
779 (void)pAppPath; (void)argc; (void)argv;
780 return NULL;
781}
782
783
784#endif // ENABLE_QUICKSTART_LIBPNG
785
786/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
787