Changeset 2866


Ignore:
Timestamp:
Nov 15, 2022, 3:29:56 AM (2 years ago)
Author:
bsmith
Message:

GTK2/3/4: Add return values to dw_window_set_bitmap(_from_data).
Also similar to the other platforms, no longer install XPMs to gtk/.
GTK4 is currently untested, if it doesn't work, may be a follow-up.
Also fix a GCC fortify warning with strncpy().

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/Makefile.in

    r2773 r2866  
    108108        $(INSTALL) -d $(prefix)/bin; \
    109109        $(INSTALL) -d $(prefix)/share/applications; \
    110         $(INSTALL) -d $(prefix)/share/dwtest/gtk; \
     110        $(INSTALL) -d $(prefix)/share/dwtest; \
    111111        $(INSTALL) dwtest $(prefix)/bin; \
    112112        $(INSTALL) org.dbsoft.dwindows.dwtest.desktop $(prefix)/share/applications/; \
    113         $(INSTALL) image/test.png $(prefix)/share/dwtest/; \
    114         $(INSTALL) gtk/file.xpm $(prefix)/share/dwtest/gtk; \
    115         $(INSTALL) gtk/folder.xpm $(prefix)/share/dwtest/gtk
     113        $(INSTALL) image/test.png $(prefix)/share/dwtest; \
     114        $(INSTALL) gtk/file.xpm $(prefix)/share/dwtest; \
     115        $(INSTALL) gtk/folder.xpm $(prefix)/share/dwtest
    116116
    117117installdwcompat: $(SYSCONF_LINK_TARGET2)
     
    141141        rm -f $(prefix)/share/man/man1/dwindows-config.1.gz
    142142        rm -f $(prefix)/share/dwtest/test.png
    143         rm -f $(prefix)/share/dwtest/gtk/file.xpm
    144         rm -f $(prefix)/share/dwtest/gtk/folder.xpm
     143        rm -f $(prefix)/share/dwtest/file.xpm
     144        rm -f $(prefix)/share/dwtest/folder.xpm
    145145
    146146deb: dist
  • TabularUnified trunk/dwtest.c

    r2863 r2866  
    22512251        foldericon = dw_icon_load_from_file(pathbuff);
    22522252        if(foldericon)
    2253             strncpy(foldericonpath, pathbuff, 1024);
     2253            strncpy(foldericonpath, pathbuff, 1025);
    22542254        strncpy(&pathbuff[pos], "file", 1024-pos);
    22552255        fileicon = dw_icon_load_from_file(pathbuff);
    22562256        if(fileicon)
    2257             strncpy(fileiconpath, pathbuff, 1024);
     2257            strncpy(fileiconpath, pathbuff, 1025);
    22582258    }
    22592259
  • TabularUnified trunk/gtk/dw.c

    r2762 r2866  
    46104610   {
    46114611      dw_window_set_bitmap(bitmap, id, NULL);
    4612       gtk_container_add (GTK_CONTAINER(tmp), bitmap);
     4612      gtk_container_add(GTK_CONTAINER(tmp), bitmap);
    46134613      gtk_object_set_data(GTK_OBJECT(tmp), "_dw_bitmap", bitmap);
    46144614   }
     
    46414641   /* Now on to the image stuff */
    46424642   bitmap = dw_bitmap_new(id);
    4643    if ( bitmap )
    4644    {
    4645       dw_window_set_bitmap( bitmap, 0, filename );
     4643   if(bitmap)
     4644   {
     4645      dw_window_set_bitmap(bitmap, 0, filename);
    46464646      gtk_container_add (GTK_CONTAINER(tmp), bitmap);
    46474647      gtk_object_set_data(GTK_OBJECT(tmp), "_dw_bitmap", bitmap);
     
    46754675   bitmap = dw_bitmap_new(id);
    46764676
    4677    if ( bitmap )
     4677   if(bitmap)
    46784678   {
    46794679      dw_window_set_bitmap_from_data(bitmap, 0, data, len);
    4680       gtk_container_add (GTK_CONTAINER(tmp), bitmap);
     4680      gtk_container_add(GTK_CONTAINER(tmp), bitmap);
    46814681      gtk_object_set_data(GTK_OBJECT(tmp), "_dw_bitmap", bitmap);
    46824682   }
     
    49104910 *                 Windows and a pixmap on Unix, pass
    49114911 *                 NULL if you use the id param)
    4912  */
    4913 void dw_window_set_bitmap(HWND handle, unsigned long id, const char *filename)
     4912 * Returns:
     4913 *        DW_ERROR_NONE on success.
     4914 *        DW_ERROR_UNKNOWN if the parameters were invalid.
     4915 *        DW_ERROR_GENERAL if the bitmap was unable to be loaded.
     4916 */
     4917int dw_window_set_bitmap(HWND handle, unsigned long id, const char *filename)
    49144918{
    49154919#if GTK_MAJOR_VERSION > 1
     
    49194923   GdkPixmap *tmp = NULL;
    49204924#endif
    4921    int found_ext = 0;
    4922    int i;
    4923    int _dw_locked_by_me = FALSE;
     4925   int i, found_ext = 0;
     4926   int _dw_locked_by_me = FALSE;
     4927   int retval = DW_ERROR_UNKNOWN;
    49244928
    49254929   if(!id && !filename)
    4926       return;
     4930      return retval;
    49274931
    49284932   DW_MUTEX_LOCK;
     
    49404944#endif
    49414945
    4942       if (!file)
     4946      if(!file)
    49434947      {
    49444948         DW_MUTEX_UNLOCK;
    4945          return;
     4949         return DW_ERROR_GENERAL;
    49464950      }
    49474951
     
    49494953
    49504954      /* check if we can read from this file (it exists and read permission) */
    4951       if ( access(file, 04 ) != 0 )
     4955      if(access(file, 04 ) != 0)
    49524956      {
    49534957         /* Try with various extentions */
    4954          for ( i = 0; i < NUM_EXTS; i++ )
     4958         for(i = 0; i < NUM_EXTS; i++)
    49554959         {
    4956             strcpy( file, filename );
    4957             strcat( file, _dw_image_exts[i] );
    4958             if ( access( file, 04 ) == 0 )
     4960            strcpy(file, filename);
     4961            strcat(file, _dw_image_exts[i]);
     4962            if(access( file, 04 ) == 0)
    49594963            {
    49604964               found_ext = 1;
     
    49624966            }
    49634967         }
    4964          if ( found_ext == 0 )
     4968         if(found_ext == 0)
    49654969         {
    49664970            DW_MUTEX_UNLOCK;
    4967             return;
     4971            return DW_ERROR_GENERAL;
    49684972         }
    49694973      }
    49704974#if GTK_MAJOR_VERSION > 1
    4971       pixbuf = gdk_pixbuf_new_from_file(file, NULL );
     4975      pixbuf = gdk_pixbuf_new_from_file(file, NULL);
    49724976#elif defined(USE_IMLIB)
    49734977      image = gdk_imlib_load_image(file);
     
    49824986
    49834987#if GTK_MAJOR_VERSION > 1
    4984    if (pixbuf)
     4988   if(pixbuf)
    49854989#else
    4986    if (tmp)
    4987 #endif
    4988    {
    4989       if ( GTK_IS_BUTTON(handle) )
     4990   if(tmp)
     4991#endif
     4992   {
     4993      if(GTK_IS_BUTTON(handle))
    49904994      {
    49914995#if GTK_MAJOR_VERSION > 1
    4992          GtkWidget *pixmap = (GtkWidget *)gtk_object_get_data( GTK_OBJECT(handle), "_dw_bitmap" );
     4996         GtkWidget *pixmap = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "_dw_bitmap");
    49934997         if(pixmap)
    49944998         {
    49954999            gtk_image_set_from_pixbuf(GTK_IMAGE(pixmap), pixbuf);
     5000            retval = DW_ERROR_NONE;
    49965001         }
    49975002#else
    49985003         GtkWidget *pixmap = GTK_BUTTON(handle)->child;
    49995004         gtk_pixmap_set(GTK_PIXMAP(pixmap), tmp, bitmap);
    5000 #endif
    5001       }
    5002       else
    5003       {
     5005         retval = DW_ERROR_NONE;
     5006#endif
     5007      }
    50045008#if GTK_MAJOR_VERSION > 1
     5009      else if(GTK_IS_IMAGE(handle))
     5010      {
    50055011         gtk_image_set_from_pixbuf(GTK_IMAGE(handle), pixbuf);
    50065012#else
     5013      else if(GTK_IS_PIXMAP(handle))
     5014      {
    50075015         gtk_pixmap_set(GTK_PIXMAP(handle), tmp, bitmap);
    50085016#endif
     5017         retval = DW_ERROR_NONE;
    50095018      }
    50105019   }
     
    50145023#endif
    50155024   DW_MUTEX_UNLOCK;
     5025   return retval;
    50165026}
    50175027
     
    50265036 *                 NULL if you use the id param)
    50275037 *       len: length of data
    5028  */
    5029 void dw_window_set_bitmap_from_data(HWND handle, unsigned long id, const char *data, int len)
     5038 * Returns:
     5039 *        DW_ERROR_NONE on success.
     5040 *        DW_ERROR_UNKNOWN if the parameters were invalid.
     5041 *        DW_ERROR_GENERAL if the bitmap was unable to be loaded.
     5042 */
     5043int dw_window_set_bitmap_from_data(HWND handle, unsigned long id, const char *data, int len)
    50305044{
    50315045#if GTK_MAJOR_VERSION > 1
     
    50365050#endif
    50375051   int _dw_locked_by_me = FALSE;
     5052        int retval = DW_ERROR_UNKNOWN;
    50385053
    50395054   if(!id && !data)
    5040       return;
     5055      return retval;
    50415056
    50425057   DW_MUTEX_LOCK;
     
    50625077      {
    50635078         DW_MUTEX_UNLOCK;
    5064          return;
     5079         return DW_ERROR_GENERAL;
    50655080      }
    50665081#if GTK_MAJOR_VERSION > 1
     
    50785093      unlink(template);
    50795094   }
    5080    else if (id)
     5095   else if(id)
    50815096#if GTK_MAJOR_VERSION > 1
    50825097      pixbuf = _dw_find_pixbuf((HICN)id);
     
    50865101
    50875102#if GTK_MAJOR_VERSION > 1
    5088    if (pixbuf)
     5103   if(pixbuf)
    50895104#else
    5090    if (tmp)
    5091 #endif
    5092    {
    5093       if ( GTK_IS_BUTTON(handle) )
     5105   if(tmp)
     5106#endif
     5107   {
     5108      if(GTK_IS_BUTTON(handle))
    50945109      {
    50955110#if GTK_MAJOR_VERSION > 1
     
    50985113         {
    50995114            gtk_image_set_from_pixbuf(GTK_IMAGE(pixmap), pixbuf);
     5115            retval = DW_ERROR_NONE;
    51005116         }
    51015117#else
    51025118         GtkWidget *pixmap = GTK_BUTTON(handle)->child;
    51035119         gtk_pixmap_set(GTK_PIXMAP(pixmap), tmp, bitmap);
    5104 #endif
    5105       }
    5106       else
    5107       {
     5120         retval = DW_ERROR_NONE;
     5121#endif
     5122      }
    51085123#if GTK_MAJOR_VERSION > 1
     5124      else if(GTK_IS_IMAGE(handle))
     5125      {
    51095126         gtk_image_set_from_pixbuf(GTK_IMAGE(handle), pixbuf);
    51105127#else
     5128      else if(GTK_IS_PIXMAP(handle))
     5129      {
    51115130         gtk_pixmap_set(GTK_PIXMAP(handle), tmp, bitmap);
    51125131#endif
     5132                        retval = DW_ERROR_NONE;
    51135133      }
    51145134   }
     
    51185138#endif
    51195139   DW_MUTEX_UNLOCK;
     5140   return retval;
    51205141}
    51215142
  • TabularUnified trunk/gtk3/dw.c

    r2762 r2866  
    42634263   if(bitmap)
    42644264   {
    4265       dw_window_set_bitmap( bitmap, 0, filename );
    4266       gtk_container_add (GTK_CONTAINER(tmp), bitmap);
     4265      dw_window_set_bitmap(bitmap, 0, filename);
     4266      gtk_container_add(GTK_CONTAINER(tmp), bitmap);
    42674267      g_object_set_data(G_OBJECT(tmp), "_dw_bitmap", bitmap);
    42684268   }
     
    42994299   {
    43004300      dw_window_set_bitmap_from_data(bitmap, 0, data, len);
    4301       gtk_container_add (GTK_CONTAINER(tmp), bitmap);
     4301      gtk_container_add(GTK_CONTAINER(tmp), bitmap);
    43024302      g_object_set_data(G_OBJECT(tmp), "_dw_bitmap", bitmap);
    43034303   }
     
    45504550 *                 Windows and a pixmap on Unix, pass
    45514551 *                 NULL if you use the id param)
    4552  */
    4553 void dw_window_set_bitmap(HWND handle, unsigned long id, const char *filename)
     4552 * Returns:
     4553 *        DW_ERROR_NONE on success.
     4554 *        DW_ERROR_UNKNOWN if the parameters were invalid.
     4555 *        DW_ERROR_GENERAL if the bitmap was unable to be loaded.
     4556 */
     4557int dw_window_set_bitmap(HWND handle, unsigned long id, const char *filename)
    45544558{
    45554559   GdkPixbuf *tmp = NULL;
    4556    int found_ext = 0;
    4557    int i;
    4558    int _dw_locked_by_me = FALSE;
     4560   int i, found_ext = 0;
     4561   int _dw_locked_by_me = FALSE;
     4562   int retval = DW_ERROR_UNKNOWN;
    45594563
    45604564   if(!id && !filename)
    4561       return;
     4565      return retval;
    45624566
    45634567   DW_MUTEX_LOCK;
     
    45684572      char *file = alloca(strlen(filename) + 6);
    45694573
    4570       if (!file)
     4574      if(!file)
    45714575      {
    45724576         DW_MUTEX_UNLOCK;
    4573          return;
     4577         return DW_ERROR_GENERAL;
    45744578      }
    45754579
     
    45774581
    45784582      /* check if we can read from this file (it exists and read permission) */
    4579       if ( access(file, 04 ) != 0 )
     4583      if(access(file, 04) != 0)
    45804584      {
    45814585         /* Try with various extentions */
    4582          for ( i = 0; i < NUM_EXTS; i++ )
     4586         for(i = 0; i < NUM_EXTS; i++)
    45834587         {
    4584             strcpy( file, filename );
    4585             strcat( file, _dw_image_exts[i] );
    4586             if ( access( file, 04 ) == 0 )
     4588            strcpy(file, filename);
     4589            strcat(file, _dw_image_exts[i]);
     4590            if(access( file, 04 ) == 0)
    45874591            {
    45884592               found_ext = 1;
     
    45904594            }
    45914595         }
    4592          if ( found_ext == 0 )
     4596         if(found_ext == 0)
    45934597         {
    45944598            DW_MUTEX_UNLOCK;
    4595             return;
     4599            return DW_ERROR_GENERAL;
    45964600         }
    45974601      }
    4598       tmp = gdk_pixbuf_new_from_file(file, NULL );
    4599    }
    4600 
    4601    if (tmp)
    4602    {
    4603       if ( GTK_IS_BUTTON(handle) )
    4604       {
    4605          GtkWidget *pixmap = (GtkWidget *)g_object_get_data( G_OBJECT(handle), "_dw_bitmap" );
     4602      tmp = gdk_pixbuf_new_from_file(file, NULL);
     4603   }
     4604
     4605   if(tmp)
     4606   {
     4607      if(GTK_IS_BUTTON(handle))
     4608      {
     4609         GtkWidget *pixmap = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_bitmap");
    46064610         if(pixmap)
    46074611         {
    46084612            gtk_image_set_from_pixbuf(GTK_IMAGE(pixmap), tmp);
     4613                 retval = DW_ERROR_NONE;
    46094614         }
    46104615      }
    4611       else
     4616      else if(GTK_IS_IMAGE(handle))
    46124617      {
    46134618         gtk_image_set_from_pixbuf(GTK_IMAGE(handle), tmp);
    4614       }
    4615    }
    4616    DW_MUTEX_UNLOCK;
     4619         retval = DW_ERROR_NONE;
     4620      }
     4621   }
     4622   DW_MUTEX_UNLOCK;
     4623   return retval;
    46174624}
    46184625
     
    46274634 *                 NULL if you use the id param)
    46284635 *       len: length of data
    4629  */
    4630 void dw_window_set_bitmap_from_data(HWND handle, unsigned long id, const char *data, int len)
     4636 * Returns:
     4637 *        DW_ERROR_NONE on success.
     4638 *        DW_ERROR_UNKNOWN if the parameters were invalid.
     4639 *        DW_ERROR_GENERAL if the bitmap was unable to be loaded.
     4640 */
     4641int dw_window_set_bitmap_from_data(HWND handle, unsigned long id, const char *data, int len)
    46314642{
    46324643   GdkPixbuf *tmp = NULL;
    46334644   int _dw_locked_by_me = FALSE;
     4645   int retval = DW_ERROR_UNKNOWN;
    46344646
    46354647   if(!id && !data)
    4636       return;
     4648      return retval;
    46374649
    46384650   DW_MUTEX_LOCK;
     
    46554667      {
    46564668         DW_MUTEX_UNLOCK;
    4657          return;
     4669         return DW_ERROR_GENERAL;
    46584670      }
    46594671
     
    46724684
    46734685         if(pixmap)
     4686         {
    46744687            gtk_image_set_from_pixbuf(GTK_IMAGE(pixmap), tmp);
    4675       }
    4676       else
     4688            retval = DW_ERROR_NONE;
     4689         }
     4690      }
     4691      else if(GTK_IS_IMAGE(handle))
     4692      {
    46774693         gtk_image_set_from_pixbuf(GTK_IMAGE(handle), tmp);
    4678    }
    4679    DW_MUTEX_UNLOCK;
     4694         retval = DW_ERROR_NONE;
     4695      }
     4696   }
     4697   DW_MUTEX_UNLOCK;
     4698   return retval;
    46804699}
    46814700
  • TabularUnified trunk/gtk4/dw.c

    r2770 r2866  
    39263926 *                 Windows and a pixmap on Unix, pass
    39273927 *                 NULL if you use the id param)
    3928  */
    3929 DW_FUNCTION_DEFINITION(dw_window_set_bitmap, void, HWND handle, unsigned long id, const char *filename)
     3928 * Returns:
     3929 *        DW_ERROR_NONE on success.
     3930 *        DW_ERROR_UNKNOWN if the parameters were invalid.
     3931 *        DW_ERROR_GENERAL if the bitmap was unable to be loaded.
     3932 */
     3933DW_FUNCTION_DEFINITION(dw_window_set_bitmap, int, HWND handle, unsigned long id, const char *filename)
    39303934DW_FUNCTION_ADD_PARAM3(handle, id, filename)
    3931 DW_FUNCTION_NO_RETURN(dw_window_set_bitmap)
     3935DW_FUNCTION_RETURN(dw_window_set_bitmap, int)
    39323936DW_FUNCTION_RESTORE_PARAM3(handle, HWND, id, ULONG, filename, const char *)
    39333937{
    39343938   GdkPixbuf *tmp = NULL;
     3939   int retval = DW_ERROR_UNKNOWN;
    39353940
    39363941   if(id)
     
    39673972         GtkWidget *pixmap = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_bitmap");
    39683973         if(pixmap)
     3974         {
    39693975            gtk_picture_set_pixbuf(GTK_PICTURE(pixmap), tmp);
     3976            retval = DW_ERROR_NONE;
     3977         }
    39703978      }
    39713979      else if(GTK_IS_PICTURE(handle))
     3980      {
    39723981         gtk_picture_set_pixbuf(GTK_PICTURE(handle), tmp);
    3973    }
    3974    DW_FUNCTION_RETURN_NOTHING;
     3982         retval = DW_ERROR_NONE;
     3983      }
     3984   }
     3985   else
     3986        retval = DW_ERROR_GENERAL;
     3987   DW_FUNCTION_RETURN_THIS(retval);
    39753988}
    39763989
     
    39853998 *                 NULL if you use the id param)
    39863999 *       len: length of data
    3987  */
    3988 DW_FUNCTION_DEFINITION(dw_window_set_bitmap_from_data, void, HWND handle, unsigned long id, const char *data, int len)
     4000 * Returns:
     4001 *        DW_ERROR_NONE on success.
     4002 *        DW_ERROR_UNKNOWN if the parameters were invalid.
     4003 *        DW_ERROR_GENERAL if the bitmap was unable to be loaded.
     4004 */
     4005DW_FUNCTION_DEFINITION(dw_window_set_bitmap_from_data, int, HWND handle, unsigned long id, const char *data, int len)
    39894006DW_FUNCTION_ADD_PARAM4(handle, id, data, len)
    3990 DW_FUNCTION_NO_RETURN(dw_window_set_bitmap_from_data)
     4007DW_FUNCTION_RETURN(dw_window_set_bitmap_from_data, int)
    39914008DW_FUNCTION_RESTORE_PARAM4(handle, HWND, id, ULONG, data, const char *, len, int)
    39924009{
    39934010   GdkPixbuf *tmp = NULL;
     4011   int retval = DW_ERROR_UNKNOWN;
    39944012
    39954013   if(data)
     
    40154033      }
    40164034   }
    4017    else if (id)
     4035   else if(id)
    40184036      tmp = _dw_find_pixbuf((HICN)id, NULL, NULL);
    40194037
     
    40254043
    40264044         if(pixmap)
     4045         {
    40274046            gtk_picture_set_pixbuf(GTK_PICTURE(pixmap), tmp);
     4047            retval = DW_ERROR_NONE;
     4048         }
    40284049      }
    40294050      else if(GTK_IS_PICTURE(handle))
     4051      {
    40304052         gtk_picture_set_pixbuf(GTK_PICTURE(handle), tmp);
    4031    }
    4032    DW_FUNCTION_RETURN_NOTHING;
     4053         retval = DW_ERROR_NONE;
     4054      }
     4055   }
     4056   else
     4057        retval = DW_ERROR_GENERAL;
     4058   DW_FUNCTION_RETURN_THIS(retval);
    40334059}
    40344060
Note: See TracChangeset for help on using the changeset viewer.