1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
(*
GTK-Kylix Library: GTKClasses - Non-visual objects
Version 0.6.4 (last updated 2003-04-03)
Copyright (C) 2003 Tomas Bzatek <tbzatek@users.sourceforge.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307 USA.
*)
unit GTKClasses;
interface
uses gtk2, gdk2, glib2, Classes, SysUtils;
type
TGDKColor = record
pixel: Cardinal;
red, green, blue: Word;
end;
(****************************************** TGLIST ******************************************************************************)
TGList = class(TComponent)
private
FNotify: TNotifyEvent;
public
FList: PGList;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Append(Data: Pointer); overload;
procedure Append(Data: string); overload;
procedure Delete(Index: integer);
function Count: integer;
published
property Notify: TNotifyEvent read FNotify write FNotify;
end;
(****************************************** TGTKTIMER ***************************************************************************)
TGTKTimer = class(TComponent)
private
FOnTimer: TNotifyEvent;
FHandlerID: guint;
FEnabled: boolean;
FInterval: Cardinal;
procedure SetEnabled(Value: boolean);
procedure SetInterval(Value: Cardinal);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Start;
procedure Stop;
published
property OnTimer: TNotifyEvent read FOnTimer write FOnTimer;
property Enabled: boolean read FEnabled write SetEnabled default False;
property Interval: Cardinal read FInterval write SetInterval;
end;
(********************************************************************************************************************************)
(********************************************************************************************************************************)
implementation
uses GTKUtils;
(********************************************************************************************************************************)
(********************************************************************************************************************************)
constructor TGList.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FList := nil;
FNotify := nil;
end;
destructor TGList.Destroy;
begin
g_list_free(FList);
inherited Destroy;
end;
procedure TGList.Append(Data: Pointer);
begin
FList := g_list_append(FList, Data);
if Assigned(FNotify) then FNotify(Self);
end;
procedure TGList.Append(Data: string);
begin
Append(Pointer(StringToPgchar(Data)));
end;
procedure TGList.Delete(Index: integer);
var El: PGSList;
begin
El := g_list_nth_data(FList, Index);
if El <> nil then FList := g_list_remove(FList, El);
end;
function TGList.Count: integer;
begin
Result := 0;
if FList <> nil then Result := g_list_length(FList);
end;
(********************************************************************************************************************************)
(********************************************************************************************************************************)
constructor TGTKTimer.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FOnTimer := nil;
FEnabled := False;
FInterval := 0;
FHandlerID := 0;
end;
destructor TGTKTimer.Destroy;
begin
SetEnableD(False);
inherited Destroy;
end;
procedure TGTKTimer.SetEnabled(Value: boolean);
begin
if Value <> FEnabled then begin
FEnabled := Value;
if Value then Start
else Stop;
end;
end;
procedure TGTKTimer.SetInterval(Value: Cardinal);
begin
if FInterval <> Value then begin
FInterval := Value;
Stop;
Start;
end;
end;
function TGTKTimer_Timeout(data: gpointer): gboolean; cdecl;
begin
if Assigned(TGTKTimer(data).FOnTimer) then TGTKTimer(data).FOnTimer(TGTKTimer(data));
Result := True;
end;
procedure TGTKTimer.Start;
begin
if FHandlerID > 0 then Stop;
if FEnabled then FHandlerID := gtk_timeout_add(FInterval, TGTKTimer_Timeout, Self);
end;
procedure TGTKTimer.Stop;
begin
if FHandlerID > 0 then gtk_timeout_remove(FHandlerID);
FHandlerID := 0;
end;
(********************************************************************************************************************************)
(********************************************************************************************************************************)
end.
|