LCOV - code coverage report
Current view: top level - desktop/unx/source - splashx.c (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 314 0.0 %
Date: 2014-11-03 Functions: 0 17 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      37             : typedef struct {
      38             :     unsigned char b, g, r;
      39             : } color_t;
      40             : 
      41             : struct 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             : 
      86           0 : static int splash_load_bmp( struct splash* splash, const char *filename )
      87             : {
      88             :     FILE *file;
      89             : 
      90           0 :     if ( !(file = fopen( filename, "r" ) ) )
      91           0 :         return 0;
      92             : 
      93           0 :     splash->png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING, 0, 0, 0 );
      94           0 :     splash->info_ptr = png_create_info_struct(splash->png_ptr);
      95           0 :     png_init_io( splash->png_ptr, file );
      96             : 
      97           0 :     if( setjmp( png_jmpbuf( splash->png_ptr ) ) )
      98             :     {
      99           0 :         png_destroy_read_struct( &(splash->png_ptr), &(splash->info_ptr), NULL );
     100           0 :         fclose( file );
     101           0 :         return 0;
     102             :     }
     103             : 
     104           0 :     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           0 :     splash->bitmap_rows = png_get_rows( splash->png_ptr, splash->info_ptr );
     109           0 :     splash->width = png_get_image_width( splash->png_ptr, splash->info_ptr );
     110           0 :     splash->height = png_get_image_height( splash->png_ptr, splash->info_ptr );
     111             : 
     112           0 :     fclose( file );
     113           0 :     return 1;
     114             : }
     115             : 
     116           0 : static void setup_color( int val[3], color_t *col )
     117             : {
     118           0 :     if ( val[0] < 0 || val[1] < 0 || val[2] < 0 )
     119           0 :         return;
     120             : 
     121             : #define CONVERT_COLOR( from,to ) if ( from < 0 ) to = 0; else if ( from > 255 ) to = 255; else to = from;
     122           0 :     CONVERT_COLOR( val[0], col->r );
     123           0 :     CONVERT_COLOR( val[1], col->g );
     124           0 :     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 */
     130           0 : static void get_bootstrap_value( int *array, int size, rtlBootstrapHandle handle, const char *name )
     131             : {
     132           0 :     rtl_uString *pKey = NULL, *pValue = NULL;
     133             : 
     134             :     /* get the value from the ini file */
     135           0 :     rtl_uString_newFromAscii( &pKey, name );
     136           0 :     rtl_bootstrap_get_from_handle( handle, pKey, &pValue, NULL );
     137             : 
     138             :     /* the value is several numbers delimited by ',' - parse it */
     139           0 :     if ( rtl_uString_getLength( pValue ) > 0 )
     140             :     {
     141           0 :         rtl_uString *pToken = NULL;
     142           0 :         int i = 0;
     143           0 :         sal_Int32 nIndex = 0;
     144           0 :         for ( ; ( nIndex >= 0 ) && ( i < size ); ++i )
     145             :         {
     146           0 :             nIndex = rtl_uString_getToken( &pToken, pValue, 0, ',', nIndex );
     147           0 :             array[i] = rtl_ustr_toInt32( rtl_uString_getStr( pToken ), 10 );
     148             :         }
     149             : 
     150           0 :         rtl_uString_release( pToken );
     151             :     }
     152             : 
     153             :     /* cleanup */
     154           0 :     rtl_uString_release( pKey );
     155           0 :     rtl_uString_release( pValue );
     156           0 : }
     157             : 
     158             : // setup
     159           0 : static void splash_setup( struct splash* splash, int barc[3], int framec[3], int posx, int posy, int w, int h )
     160             : {
     161           0 :     if ( splash->width <= 500 )
     162             :     {
     163           0 :         splash->barwidth  = splash->width - ( 2 * PROGRESS_XOFFSET );
     164           0 :         splash->barheight = 6;
     165           0 :         splash->tlx = PROGRESS_XOFFSET;
     166           0 :         splash->tly = splash->height - PROGRESS_YOFFSET;
     167             : 
     168           0 :         splash->barcol.r = 0;
     169           0 :         splash->barcol.g = 0;
     170           0 :         splash->barcol.b = 128;
     171             :     }
     172             : 
     173           0 :     if ( posx >= 0 )
     174           0 :         splash->tlx = posx;
     175           0 :     if ( posy >= 0 )
     176           0 :         splash->tly = posy;
     177           0 :     if ( w >= 0 )
     178           0 :         splash->barwidth = w;
     179           0 :     if ( h >= 0 )
     180           0 :         splash->barheight = h;
     181             : 
     182           0 :     setup_color( barc, &(splash->barcol) );
     183           0 :     setup_color( framec, &(splash->framecol) );
     184           0 : }
     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)
     190           0 : static inline int HIGHEST_BIT( unsigned long x )
     191             : {
     192           0 :     int i = 0;
     193           0 :     for ( ; x; ++i )
     194           0 :         x >>= 1;
     195             : 
     196           0 :     return i;
     197             : }
     198             : 
     199             : // Number of bits set to 1
     200           0 : static inline int BITS( unsigned long x )
     201             : {
     202           0 :     int i = 0;
     203           0 :     for ( ; x; x >>= 1 )
     204           0 :         if ( x & 1UL )
     205           0 :             ++i;
     206             : 
     207           0 :     return i;
     208             : }
     209             : 
     210             : // Set 'bitmap' as the background of our 'win' window
     211           0 : static void create_pixmap(struct splash* splash)
     212             : {
     213             :     Pixmap pixmap;
     214             :     GC pixmap_gc;
     215           0 :     unsigned long value_mask = 0;
     216             :     XGCValues values;
     217             : 
     218           0 :     if ( !splash->bitmap_rows )
     219             :     {
     220           0 :         return;
     221             :     }
     222           0 :     pixmap = XCreatePixmap( splash->display, splash->win, splash->width, splash->height, splash->depth );
     223             : 
     224           0 :     pixmap_gc = XCreateGC( splash->display, pixmap, value_mask, &values );
     225             : 
     226           0 :     if ( splash->visual->class == TrueColor )
     227             :     {
     228           0 :         unsigned long red_mask   = splash->visual->red_mask;
     229           0 :         unsigned long green_mask = splash->visual->green_mask;
     230           0 :         unsigned long blue_mask  = splash->visual->blue_mask;
     231             : 
     232           0 :         unsigned long red_delta_mask   = ( 1UL << ( 8 - BITS( red_mask ) ) ) - 1;
     233           0 :         unsigned long green_delta_mask = ( 1UL << ( 8 - BITS( green_mask ) ) ) - 1;
     234           0 :         unsigned long blue_delta_mask  = ( 1UL << ( 8 - BITS( blue_mask ) ) ) - 1;
     235             : 
     236           0 :         int red_shift   = HIGHEST_BIT( red_mask ) - 8;
     237           0 :         int green_shift = HIGHEST_BIT( green_mask ) - 8;
     238           0 :         int blue_shift  = HIGHEST_BIT( blue_mask ) - 8;
     239             : 
     240           0 :         XImage* image = XCreateImage( splash->display, splash->visual, splash->depth, ZPixmap,
     241           0 :                                       0, NULL, splash->width, splash->height, 32, 0 );
     242             : 
     243           0 :         int bytes_per_line = image->bytes_per_line;
     244           0 :         int bpp = image->bits_per_pixel;
     245           0 :         int byte_order = image->byte_order;
     246             : #if defined( _LITTLE_ENDIAN )
     247           0 :         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           0 :         char *data = malloc( splash->height * bytes_per_line );
     261           0 :         char *out = data;
     262           0 :         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           0 :         if ( bpp == 32 )
     301             :         {
     302           0 :             if ( machine_byte_order == byte_order )
     303           0 :                 COPY_IN_OUT( 4, *( (uint32_t *)out ) = (uint32_t)pixel; out += 4; )
     304             :             else
     305           0 :                 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           0 :         else if ( bpp == 24 )
     313             :         {
     314           0 :             if ( machine_byte_order == byte_order && byte_order == LSBFirst )
     315           0 :                 COPY_IN_OUT( 3, *( (color_t *)out ) = *( (color_t *)( &pixel ) ); out += 3; )
     316           0 :             else if ( machine_byte_order == byte_order && byte_order == MSBFirst )
     317           0 :                 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           0 :                 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           0 :         else if ( bpp == 16 )
     330             :         {
     331           0 :             if ( machine_byte_order == byte_order )
     332           0 :                 COPY_IN_OUT( 2, *( (uint16_t *)out ) = (uint16_t)pixel; out += 2; )
     333             :             else
     334           0 :                 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           0 :         else if ( bpp == 8 )
     340             :         {
     341           0 :             COPY_IN_OUT( 1, *( (uint8_t *)out ) = (uint8_t)pixel; ++out; )
     342             :         }
     343             :         else
     344             :         {
     345           0 :             fprintf( stderr, "Unsupported depth: %d bits per pixel.\n", bpp );
     346           0 :             XFreeGC( splash->display, pixmap_gc );
     347           0 :             XFreePixmap( splash->display, pixmap );
     348           0 :             XDestroyImage( image );
     349           0 :             return;
     350             :         }
     351             : 
     352             : #undef COPY_IN_OUT
     353             : 
     354           0 :         XPutImage( splash->display, pixmap, pixmap_gc, image, 0, 0, 0, 0, splash->width, splash->height );
     355           0 :         XDestroyImage( image );
     356             :     }
     357             : 
     358           0 :     XSetWindowBackgroundPixmap( splash->display, splash->win, pixmap );
     359             : 
     360           0 :     XFreeGC( splash->display, pixmap_gc );
     361           0 :     XFreePixmap( splash->display, pixmap );
     362             : }
     363             : 
     364             : // The old method of hiding the window decorations
     365           0 : static void suppress_decorations_motif(struct splash* splash)
     366             : {
     367             :     struct
     368             :     {
     369             :         unsigned long flags, functions, decorations;
     370             :         long input_mode;
     371             :     } mwmhints;
     372             : 
     373           0 :     Atom a = XInternAtom( splash->display, "_MOTIF_WM_HINTS", False );
     374             : 
     375           0 :     mwmhints.flags = 15; // functions, decorations, input_mode, status
     376           0 :     mwmhints.functions = 2; // ?
     377           0 :     mwmhints.decorations = 0;
     378           0 :     mwmhints.input_mode = 0;
     379             : 
     380           0 :     XChangeProperty( splash->display, splash->win, a, a, 32,
     381             :                      PropModeReplace, (unsigned char*)&mwmhints, 5 );
     382           0 : }
     383             : 
     384             : // This is a splash, set it as such.
     385             : // If it fails, just hide the decorations...
     386           0 : static void suppress_decorations(struct splash* splash)
     387             : {
     388           0 :     Atom atom_type = XInternAtom( splash->display, "_NET_WM_WINDOW_TYPE", True );
     389           0 :     Atom atom_splash = XInternAtom( splash->display, "_NET_WM_WINDOW_TYPE_SPLASH", True );
     390             : 
     391           0 :     if ( atom_type != None && atom_splash != None )
     392           0 :         XChangeProperty( splash->display, splash->win, atom_type, XA_ATOM, 32,
     393             :                          PropModeReplace, (unsigned char*)&atom_splash, 1 );
     394             :     //else
     395           0 :     suppress_decorations_motif(splash); // FIXME: Unconditional until Metacity/compiz's SPLASH handling is fixed
     396           0 : }
     397             : 
     398             : /**
     399             :  * Create the window for the splash screen
     400             :  *
     401             :  * @return Success: 1; Failure: 0
     402             :  */
     403           0 : static int splash_create_window( struct splash* splash, int argc, char** argv )
     404             : {
     405           0 :     char *display_name = NULL;
     406             :     int i;
     407             :     Window root_win;
     408           0 :     int display_width = 0;
     409           0 :     int display_height = 0;
     410           0 :     int display_x_pos = 0;
     411           0 :     int display_y_pos = 0;
     412           0 :     unsigned long value_mask = 0;
     413             :     XGCValues values;
     414           0 :     const char* name = "LibreOffice";
     415           0 :     const char* icon = "icon"; // FIXME
     416             :     XSizeHints size_hints;
     417             : #ifdef USE_XINERAMA
     418           0 :     int n_xinerama_screens = 1;
     419           0 :     XineramaScreenInfo* p_screens = NULL;
     420             : #endif
     421             : 
     422           0 :     for ( i = 0; i < argc; i++ )
     423             :     {
     424           0 :         if ( !strcmp( argv[i], "-display" )  || !strcmp( argv[i], "--display" ) )
     425             :         {
     426           0 :             display_name = ( i + 1 < argc )? argv[i+1]: NULL;
     427             :         }
     428             :     }
     429             : 
     430           0 :     if ( !display_name )
     431             :     {
     432           0 :         display_name = getenv( "DISPLAY" );
     433             :     }
     434             :     // init display
     435           0 :     splash->display = XOpenDisplay( display_name );
     436           0 :     if ( !splash->display )
     437             :     {
     438           0 :         fprintf( stderr, "Failed to open display\n" );
     439           0 :         return 0;
     440             :     }
     441             : 
     442             :     // create the window
     443           0 :     splash->screen = DefaultScreen( splash->display );
     444           0 :     splash->depth = DefaultDepth( splash->display, splash->screen );
     445           0 :     splash->color_map = DefaultColormap( splash->display, splash->screen );
     446           0 :     splash->visual = DefaultVisual( splash->display, splash->screen );
     447             : 
     448           0 :     root_win = RootWindow( splash->display, splash->screen );
     449           0 :     display_width = DisplayWidth( splash->display, splash->screen );
     450           0 :     display_height = DisplayHeight( splash->display, splash->screen );
     451             : 
     452             : #ifdef USE_XINERAMA
     453           0 :     p_screens = XineramaQueryScreens( splash->display, &n_xinerama_screens );
     454           0 :     if( p_screens )
     455             :     {
     456           0 :         for( i=0; i < n_xinerama_screens; i++ )
     457             :         {
     458           0 :             if ( p_screens[i].screen_number == splash->screen )
     459             :             {
     460           0 :                 display_width = p_screens[i].width;
     461           0 :                 display_height = p_screens[i].height;
     462           0 :                 display_x_pos = p_screens[i].x_org;
     463           0 :                 display_y_pos = p_screens[i].y_org;
     464           0 :                 break;
     465             :             }
     466             :         }
     467           0 :         XFree( p_screens );
     468             :     }
     469             : #endif
     470             : 
     471           0 :     splash->win = XCreateSimpleWindow( splash->display, root_win,
     472           0 :             (display_x_pos + (display_width - splash->width)/2),
     473           0 :             (display_y_pos + (display_height - splash->height)/2),
     474           0 :             splash->width, splash->height, 0,
     475           0 :             BlackPixel( splash->display, splash->screen ), BlackPixel( splash->display, splash->screen ) );
     476             : 
     477           0 :     XSetWindowColormap( splash->display, splash->win, splash->color_map );
     478             : 
     479             :     // setup colors
     480             : #define FILL_COLOR( xcol,col ) xcol.red = 256*col.r; xcol.green = 256*col.g; xcol.blue = 256*col.b;
     481           0 :     FILL_COLOR( splash->barcolor, splash->barcol );
     482           0 :     FILL_COLOR( splash->framecolor, splash->framecol );
     483             : #undef FILL_COLOR
     484             : 
     485           0 :     XAllocColor( splash->display, splash->color_map, &(splash->barcolor) );
     486           0 :     XAllocColor( splash->display, splash->color_map, &(splash->framecolor) );
     487             : 
     488             :     // not resizable, no decorations, etc.
     489           0 :     splash->gc = XCreateGC( splash->display, splash->win, value_mask, &values );
     490             : 
     491           0 :     size_hints.flags = PPosition | PSize | PMinSize | PMaxSize;
     492           0 :     size_hints.min_width = splash->width;
     493           0 :     size_hints.max_width = splash->width;
     494           0 :     size_hints.min_height = splash->height;
     495           0 :     size_hints.max_height = splash->height;
     496             : 
     497           0 :     XSetStandardProperties( splash->display, splash->win, name, icon, None,
     498             :             0, 0, &size_hints );
     499             : 
     500             :     // the actual work
     501           0 :     suppress_decorations(splash);
     502           0 :     create_pixmap(splash);
     503             : 
     504             :     // show it
     505           0 :     XSelectInput( splash->display, splash->win, 0 );
     506           0 :     XMapWindow( splash->display, splash->win );
     507             : 
     508           0 :     return 1;
     509             : }
     510             : 
     511             : // Re-draw & process the events
     512             : // Just throwing them away - we do not need anything more...
     513           0 : static void process_events(struct splash* splash)
     514             : {
     515             :     XEvent xev;
     516             :     int num_events;
     517             : 
     518           0 :     XFlush( splash->display );
     519           0 :     num_events = XPending( splash->display );
     520           0 :     while ( num_events > 0 )
     521             :     {
     522           0 :         num_events--;
     523           0 :         XNextEvent( splash->display, &xev );
     524             :     }
     525           0 : }
     526             : 
     527             : 
     528           0 : static rtl_String* ustr_to_str( rtl_uString* pStr )
     529             : {
     530           0 :     rtl_String *pOut = NULL;
     531             : 
     532           0 :     rtl_uString2String( &pOut, rtl_uString_getStr( pStr ),
     533           0 :                         rtl_uString_getLength( pStr ), osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS );
     534             : 
     535           0 :     return pOut;
     536             : }
     537             : 
     538             : #define IMG_SUFFIX           ".png"
     539             : 
     540           0 : static void splash_load_image( struct splash* splash, rtl_uString* pUAppPath )
     541             : {
     542             :     /* FIXME-BCP47: if we wanted to support language tags here that would get
     543             :      * complicated, this is C-source not C++ so LanguageTag can't be used. For
     544             :      * now the splash screen will have to get along with language-territory. */
     545             : 
     546             :     char *pBuffer, *pSuffix, *pLocale;
     547             :     int nLocSize;
     548           0 :     rtl_Locale *pLoc = NULL;
     549             :     rtl_String *pLang, *pCountry, *pAppPath;
     550             : 
     551           0 :     osl_getProcessLocale (&pLoc);
     552           0 :     pLang = ustr_to_str (pLoc->Language);
     553           0 :     pCountry = ustr_to_str (pLoc->Country);
     554             : 
     555           0 :     nLocSize = strlen (pLang->buffer) + strlen (pCountry->buffer) + 3;
     556           0 :     pLocale = malloc (nLocSize);
     557           0 :     pLocale[0] = '-';
     558           0 :     strcpy (pLocale + 1, pLang->buffer);
     559           0 :     strcat (pLocale, "_");
     560           0 :     strcat (pLocale, pCountry->buffer);
     561             : 
     562           0 :     rtl_string_release( pCountry );
     563           0 :     rtl_string_release( pLang );
     564             : 
     565           0 :     pAppPath = ustr_to_str (pUAppPath);
     566           0 :     pBuffer = malloc (pAppPath->length + nLocSize + 256);
     567           0 :     strcpy (pBuffer, pAppPath->buffer);
     568           0 :     pSuffix = pBuffer + pAppPath->length;
     569           0 :     rtl_string_release( pAppPath );
     570             : 
     571           0 :     strcpy (pSuffix, "intro");
     572           0 :     strcat (pSuffix, pLocale);
     573           0 :     strcat (pSuffix, IMG_SUFFIX);
     574           0 :     if ( splash_load_bmp( splash, pBuffer ) )
     575           0 :         goto cleanup;
     576             : 
     577           0 :     strcpy (pSuffix, "intro" IMG_SUFFIX);
     578           0 :     if ( splash_load_bmp( splash, pBuffer ) )
     579           0 :         goto cleanup;
     580             : 
     581           0 :     fprintf (stderr, "Failed to find intro image\n");
     582             : 
     583             :  cleanup:
     584           0 :     free (pLocale);
     585           0 :     free (pBuffer);
     586           0 : }
     587             : 
     588             : /* Load the colors and size of the splash. */
     589           0 : static void splash_load_defaults( struct splash* splash, rtl_uString* pAppPath, sal_Bool* bNoDefaults )
     590             : {
     591           0 :     rtl_uString *pSettings = NULL, *pTmp = NULL;
     592             :     rtlBootstrapHandle handle;
     593           0 :     int logo[1] =  { -1 },
     594           0 :         bar[3] =   { -1, -1, -1 },
     595           0 :         frame[3] = { -1, -1, -1 },
     596           0 :         pos[2] =   { -1, -1 },
     597           0 :         size[2] =  { -1, -1 };
     598             : 
     599             :     /* costruct the sofficerc file location */
     600           0 :     rtl_uString_newFromAscii( &pSettings, "file://" );
     601           0 :     rtl_uString_newConcat( &pSettings, pSettings, pAppPath );
     602           0 :     rtl_uString_newConcat( &pSettings, pSettings, pTmp );
     603           0 :     rtl_uString_newFromAscii( &pTmp, SAL_CONFIGFILE( "soffice" ) );
     604           0 :     rtl_uString_newConcat( &pSettings, pSettings, pTmp );
     605             : 
     606             :     /* use it as the bootstrap file */
     607           0 :     handle = rtl_bootstrap_args_open( pSettings );
     608             : 
     609             :     /* get the values */
     610           0 :     get_bootstrap_value( logo,  1, handle, "Logo" );
     611           0 :     get_bootstrap_value( bar,   3, handle, "ProgressBarColor" );
     612           0 :     get_bootstrap_value( frame, 3, handle, "ProgressFrameColor" );
     613           0 :     get_bootstrap_value( pos,   2, handle, "ProgressPosition" );
     614           0 :     get_bootstrap_value( size,  2, handle, "ProgressSize" );
     615             : 
     616           0 :     if ( logo[0] == 0 )
     617             :     {
     618           0 :         *bNoDefaults = sal_True;
     619             :     }
     620             : 
     621           0 :     splash_setup( splash, bar, frame, pos[0], pos[1], size[0], size[1] );
     622             : 
     623             :     /* cleanup */
     624           0 :     rtl_bootstrap_args_close( handle );
     625           0 :     rtl_uString_release( pSettings );
     626           0 :     rtl_uString_release( pTmp );
     627           0 : }
     628             : 
     629             : 
     630             : // Draw the progress
     631           0 : void splash_draw_progress( struct splash* splash, int progress )
     632             : {
     633           0 :     int length = 0;
     634             : 
     635           0 :     if (!splash)
     636             :     {
     637           0 :         return;
     638             :     }
     639             :     // sanity
     640           0 :     if ( progress < 0 )
     641             :     {
     642           0 :         progress = 0;
     643             :     }
     644           0 :     if ( progress > 100 )
     645             :     {
     646           0 :         progress = 100;
     647             :     }
     648             :     // draw progress...
     649           0 :     length = ( progress * splash->barwidth / 100 ) - ( 2 * splash->barspace );
     650           0 :     if ( length < 0 )
     651             :     {
     652           0 :         length = 0;
     653             :     }
     654             :     // border
     655           0 :     XSetForeground( splash->display, splash->gc, splash->framecolor.pixel );
     656           0 :     XDrawRectangle( splash->display, splash->win, splash->gc, splash->tlx, splash->tly,
     657           0 :             splash->barwidth, splash->barheight );
     658             : 
     659             :     // progress bar
     660           0 :     XSetForeground( splash->display, splash->gc, splash->barcolor.pixel );
     661           0 :     XFillRectangle( splash->display, splash->win, splash->gc,
     662           0 :             splash->tlx + splash->barspace, splash->tly + splash->barspace,
     663           0 :             length + 1, splash->barheight - 2 * splash->barspace + 1 );
     664             : 
     665             :     // pending events
     666           0 :     process_events(splash);
     667             : }
     668             : 
     669           0 : void splash_destroy(struct splash* splash)
     670             : {
     671           0 :     if(splash)
     672             :     {
     673           0 :         if(splash->display)
     674             :         {
     675           0 :             if(splash->gc)
     676             :             {
     677           0 :                 XFreeGC(splash->display, splash->gc);
     678           0 :                 splash->gc = NULL;
     679             :             }
     680             : 
     681           0 :             XCloseDisplay( splash->display );
     682           0 :             splash->display = NULL;
     683           0 :             png_destroy_read_struct( &(splash->png_ptr), &(splash->info_ptr), NULL );
     684             :         }
     685           0 :         free(splash);
     686             :     }
     687           0 : }
     688             : 
     689           0 : struct splash* splash_create(rtl_uString* pAppPath, int argc, char** argv)
     690             : {
     691             :     struct splash* splash;
     692           0 :     sal_Bool bNoDefaults = sal_False;
     693             : 
     694           0 :     splash = calloc(1, sizeof(struct splash));
     695           0 :     if(splash)
     696             :     {
     697           0 :         splash->width = WINDOW_WIDTH;
     698           0 :         splash->height = WINDOW_HEIGHT;
     699             : 
     700           0 :         splash->tlx = 212;
     701           0 :         splash->tly = 216;
     702           0 :         splash->barwidth = 263;
     703           0 :         splash->barheight = 8;
     704           0 :         splash->barspace = PROGRESS_BARSPACE;
     705           0 :         splash->barcol.b = 18;
     706           0 :         splash->barcol.g = 202;
     707           0 :         splash->barcol.r = 157;
     708           0 :         splash->framecol.b = 0xD3;
     709           0 :         splash->framecol.g = 0xD3;
     710           0 :         splash->framecol.r = 0xD3;
     711             : 
     712           0 :         splash_load_image( splash, pAppPath );
     713           0 :         splash_load_defaults( splash, pAppPath, &bNoDefaults );
     714             : 
     715           0 :         if (!bNoDefaults && splash_create_window( splash, argc, argv ) )
     716             :         {
     717           0 :             splash_draw_progress( splash, 0 );
     718             :         }
     719             :         else
     720             :         {
     721           0 :             splash_destroy(splash);
     722           0 :             splash = NULL;
     723             :         }
     724             :     }
     725           0 :     return splash;
     726             : }
     727             : 
     728             : #else /* not ENABLE_QUICKSTART_LIBPNG */
     729             : 
     730             : #include <rtl/ustrbuf.h>
     731             : 
     732             : struct splash
     733             : {
     734             : };
     735             : 
     736             : /* Stubs that will never be called in this case */
     737             : void splash_draw_progress( struct splash* splash, int progress )
     738             : {
     739             :     (void)splash; (void)progress;
     740             : }
     741             : 
     742             : void splash_destroy(struct splash* splash)
     743             : {
     744             :     (void)splash;
     745             : }
     746             : 
     747             : struct splash* splash_create(rtl_uString* pAppPath, int argc, char** argv)
     748             : {
     749             :     (void)pAppPath; (void)argc; (void)argv;
     750             :     return NULL;
     751             : }
     752             : 
     753             : 
     754             : #endif // ENABLE_QUICKSTART_LIBPNG
     755             : 
     756             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10