Fixes AV in gtk2 TTrayIcon.InternalUpdate and adds a better handle mechanism to it

git-svn-id: trunk@16261 -
This commit is contained in:
sekelsenmat 2008-08-27 01:13:29 +00:00
parent a5edfe5a9b
commit 09225df31f

View File

@ -22,6 +22,13 @@
{ TGtk2WSCustomTrayIcon } { TGtk2WSCustomTrayIcon }
type
TGtk2WSTrayIconHandle = record
AImage: PGtkWidget;
end;
PGtk2WSTrayIconHandle = ^TGtk2WSTrayIconHandle;
const const
SYSTEM_TRAY_REQUEST_DOCK = 0; SYSTEM_TRAY_REQUEST_DOCK = 0;
SYSTEM_TRAY_BEGIN_MESSAGE = 1; SYSTEM_TRAY_BEGIN_MESSAGE = 1;
@ -287,6 +294,8 @@ end;
* *
*******************************************************************} *******************************************************************}
class function TGtk2WSCustomTrayIcon.Hide(const ATrayIcon: TCustomTrayIcon): Boolean; class function TGtk2WSCustomTrayIcon.Hide(const ATrayIcon: TCustomTrayIcon): Boolean;
var
TrayHandle: PGtk2WSTrayIconHandle absolute ATrayIcon.Handle;
begin begin
Result := False; Result := False;
@ -298,7 +307,11 @@ begin
Tips := nil; Tips := nil;
ATrayIcon.Handle := PtrInt(0); { Free and nil the handle }
FreeMem(TrayHandle);
TrayHandle := nil;
Result := True; Result := True;
end; end;
@ -315,10 +328,12 @@ end;
*******************************************************************} *******************************************************************}
class function TGtk2WSCustomTrayIcon.Show(const ATrayIcon: TCustomTrayIcon): Boolean; class function TGtk2WSCustomTrayIcon.Show(const ATrayIcon: TCustomTrayIcon): Boolean;
var var
AImage: PGtkWidget; TrayHandle: PGtk2WSTrayIconHandle absolute ATrayIcon.Handle;
begin begin
Result := False; Result := False;
ATrayIcon.Handle := PtrInt(GetMem(SizeOf(TGtk2WSTrayIconHandle)));
{******************************************************************* {*******************************************************************
* Creates the GtkPlug * Creates the GtkPlug
*******************************************************************} *******************************************************************}
@ -353,11 +368,11 @@ begin
* Draws the icon * Draws the icon
*******************************************************************} *******************************************************************}
AImage := gtk_image_new_from_pixbuf(PGdkPixbuf(ATrayIcon.Icon.Handle)); TrayHandle^.AImage := gtk_image_new_from_pixbuf(PGdkPixbuf(ATrayIcon.Icon.Handle));
gtk_widget_show(AImage); gtk_widget_show(TrayHandle^.AImage);
gtk_container_add(GTK_CONTAINER(GtkForm), AImage); gtk_container_add(GTK_CONTAINER(GtkForm), TrayHandle^.AImage);
{******************************************************************* {*******************************************************************
* Now shows the GtkPlug * Now shows the GtkPlug
@ -365,13 +380,6 @@ begin
gtk_widget_show(GtkForm); gtk_widget_show(GtkForm);
{*******************************************************************
* We don't use the GtkPlug for anything, but we reuse the image
* to update it in InternalUpdate, so we save the image
* as the handle
*******************************************************************}
ATrayIcon.Handle := PtrInt(AImage);
Result := True; Result := True;
end; end;
@ -388,28 +396,16 @@ end;
*******************************************************************} *******************************************************************}
class procedure TGtk2WSCustomTrayIcon.InternalUpdate(const ATrayIcon: TCustomTrayIcon); class procedure TGtk2WSCustomTrayIcon.InternalUpdate(const ATrayIcon: TCustomTrayIcon);
var var
AImage: PGtkWidget; TrayHandle: PGtk2WSTrayIconHandle absolute ATrayIcon.Handle;
AMask: PGdkBitmap;
GDIObject: PgdiObject;
begin begin
// Updates the tooltips // Updates the tooltips
if Assigned(Tips) then gtk_tooltips_set_tip(GTK_TOOLTIPS(Tips), GtkForm, PChar(ATrayIcon.Hint), ''); if Assigned(Tips) then gtk_tooltips_set_tip(GTK_TOOLTIPS(Tips), GtkForm, PChar(ATrayIcon.Hint), '');
// Updates the icon // Updates the icon
AImage := PGtkWidget(ATrayIcon.Handle); if (TrayHandle <> nil) and (TrayHandle^.AImage <> nil) then
if AImage <> nil then
begin begin
GDIObject := PgdiObject(ATrayIcon.Icon.Handle); gtk_image_set_from_pixbuf(GTK_IMAGE(TrayHandle^.AImage), PGdkPixbuf(ATrayIcon.Icon.Handle));
AMask := CreateGdkMaskBitmap(
GDIObject^.GDIPixmapObject.Mask,
GDIObject^.GDIBitmapObject);
gtk_image_set_from_pixmap(GTK_IMAGE(AImage),GDIObject^.GDIPixmapObject.Image, AMask);
g_object_unref(AMask);
end; end;
end; end;