ADD: GTK3 support

This commit is contained in:
Alexander Koblov 2025-03-28 23:16:54 +03:00
commit 4b17c073d1
3 changed files with 81 additions and 209 deletions

View file

@ -1,34 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="9"/>
<Version Value="12"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
<LRSInOutputDirectory Value="False"/>
<CompatibilityMode Value="True"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
</General>
<VersionInfo>
<Language Value=""/>
<CharSet Value=""/>
<StringTable ProductVersion=""/>
</VersionInfo>
<MacroValues Count="1">
<Macro1 Name="LCLWidgetType" Value="gtk3"/>
</MacroValues>
<BuildModes Count="1">
<Item1 Name="default" Default="True"/>
<SharedMatrixOptions Count="2">
<Item1 ID="968855537398" Modes="default" Type="IDEMacro" MacroName="LCLWidgetType" Value="gtk3"/>
<Item2 ID="879531914067" Type="IDEMacro" MacroName="LCLWidgetType" Value="gtk2"/>
</SharedMatrixOptions>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<IgnoreBinaries Value="False"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T &apos;Lazarus Run Output&apos; -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
<FormatVersion Value="2"/>
<Modes Count="1">
<Mode0 Name="default">
<local>
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T &apos;Lazarus Run Output&apos; -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
</Mode0>
</Modes>
</RunParams>
<RequiredPackages Count="1">
<Item1>
<PackageName Value="LCL"/>
</Item1>
</RequiredPackages>
<Units Count="1">
<Unit0>
<Filename Value="simplewlx.lpr"/>
@ -44,21 +62,22 @@
</Target>
<SearchPaths>
<IncludeFiles Value="../../../../sdk"/>
<OtherUnitFiles Value="../../../../sdk"/>
<UnitOutputDirectory Value="../lib"/>
</SearchPaths>
<Conditionals Value="if (TargetCPU &lt;> 'arm') then
<Conditionals Value="if (TargetCPU &lt;> &apos;arm&apos;) then
begin
CustomOptions += '-fPIC';
CustomOptions += &apos;-fPIC&apos;;
end;
if (TargetOS = 'darwin') then
if (TargetOS = &apos;darwin&apos;) then
begin
LinkerOptions += ' -no_order_inits';
LinkerOptions += &apos; -no_order_inits&apos;;
end;
if (TargetOS = 'linux') then
if (TargetOS = &apos;linux&apos;) then
begin
LinkerOptions += ' -z relro --as-needed';
LinkerOptions += &apos; -z relro --as-needed&apos;;
end;"/>
<Parsing>
<SyntaxOptions>

View file

@ -3,126 +3,64 @@ library SimpleWlx;
{$mode objfpc}{$H+}
{$include calling.inc}
{$DEFINE GTK2}
uses
Classes,
sysutils,
{$IFDEF GTK}
gtk,gdk,glib,
{$ENDIF}
{$IFDEF GTK2}
gtk2,gdk2,glib2,
{$ENDIF}
WLXPlugin;
var List:TStringList;
SysUtils,
{$IF DEFINED(LCLGTK2)}
gtk2, gdk2, glib2,
{$ELSEIF DEFINED(LCLGTK3)}
LazGtk3,
{$ENDIF}
WlxPlugin;
//Custom class contains info for plugin windows
type
{ TPlugInfo }
TPlugInfo = class
private
fControls:TStringList;
public
fFileToLoad:string;
fShowFlags:integer;
//etc
constructor Create;
destructor Destroy; override;
function AddControl(AItem:PGtkWidget):integer;
end;
{ TPlugInfo }
constructor TPlugInfo.Create;
begin
fControls:=TStringlist.Create;
end;
destructor TPlugInfo.Destroy;
begin
while fControls.Count>0 do
begin
gtk_widget_destroy(PGtkWidget(fControls.Objects[0]));
fControls.Delete(0);
end;
inherited Destroy;
end;
function TPlugInfo.AddControl(AItem: PGtkWidget): integer;
begin
fControls.AddObject(inttostr(Integer(AItem)),TObject(AItem));
end;
function ListLoad(ParentWin:thandle;FileToLoad:pchar;ShowFlags:integer):thandle; dcpcall;
function ListLoad(ParentWin: HWND; FileToLoad: PAnsiChar; ShowFlags: Integer): HWND; dcpcall;
var
GFix, GButton1, Gbutton2: PGtkWidget;
GButton1, Gbutton2: PGtkWidget;
GFix: PGtkWidget absolute Result;
AParent: PGtkWidget absolute ParentWin;
begin
// gFix:=gtk_fixed_new;
gFix:=gtk_vbox_new(true,5);
gtk_container_add(GTK_CONTAINER(PGtkWidget(ParentWin)),gFix);
gtk_widget_show(gFix);
{$IFDEF LCLGTK2}
// gFix:= gtk_fixed_new;
gFix:= gtk_vbox_new(True, 5);
{$ELSE}
gFix:= gtk_layout_new(nil, nil);
{$ENDIF}
gtk_container_add(PGtkContainer(AParent), gFix);
gtk_widget_show(gFix);
GButton1:=gtk_button_new_with_label('Yehoo1');
gtk_container_add(GTK_CONTAINER(GFix),GButton1);
gtk_widget_set_usize(GButton1,10,10);
// gtk_widget_set_uposition(GButton1,30,10);
gtk_widget_show(GButton1);
GButton1:= gtk_button_new_with_label('Yehoo1');
gtk_container_add(PGtkContainer(GFix), GButton1);
{$IFDEF LCLGTK2}
gtk_widget_set_usize(GButton1, 90, 48);
// gtk_widget_set_uposition(GButton1, 30, 10);
{$ELSE}
GButton1^.set_size_request(90, 48);
PGtkLayout(GFix)^.move(GButton1, 30, 10);
{$ENDIF}
gtk_widget_show(GButton1);
Gbutton2:=gtk_button_new_with_label('Yehoo2');
gtk_container_add(GTK_CONTAINER(GFix),Gbutton2 );
gtk_widget_set_usize(GButton2,20,20);
// gtk_widget_set_uposition(GButton2,50,50);
gtk_widget_show(Gbutton2);
//Create list if none
if not assigned(List) then
List:=TStringList.Create;
//add to list new plugin window and it's info
List.AddObject(IntToStr(integer(GFix)),TPlugInfo.Create);
with TPlugInfo(List.Objects[List.Count-1]) do
begin
fFileToLoad:=FileToLoad;
fShowFlags:=ShowFlags;
AddControl(GFix);
end;
Result:= thandle(GFix);
Gbutton2:= gtk_button_new_with_label('Yehoo2');
gtk_container_add(PGtkContainer(GFix), Gbutton2);
{$IFDEF LCLGTK2}
gtk_widget_set_usize(GButton2, 90, 64);
// gtk_widget_set_uposition(GButton2, 50, 74);
{$ELSE}
GButton2^.set_size_request(90, 64);
PGtkLayout(GFix)^.move(GButton2, 50, 74);
{$ENDIF}
gtk_widget_show(Gbutton2);
end;
procedure ListCloseWindow(ListWin:thandle); dcpcall;
var Index:integer; s:string;
procedure ListCloseWindow(ListWin: HWND); dcpcall;
var
AWidget: PGtkWidget absolute ListWin;
begin
if assigned(List) then
begin
writeln('ListCloseWindow quit, List Item count: '+inttostr(List.Count));
s:=IntToStr(ListWin);
Index:=List.IndexOf(s);
if Index>-1 then
begin
TPlugInfo(List.Objects[index]).Free;
List.Delete(Index);
writeln('List item n: '+inttostr(Index)+' Deleted');
end;
//Free list if it has zero items
If List.Count=0 then FreeAndNil(List);
end;
gtk_widget_destroy(AWidget);
end;
exports
ListLoad,
ListCloseWindow;
ListLoad,
ListCloseWindow;
begin
end.

View file

@ -1,85 +0,0 @@
// Lister API definitions.
// This unit is written by Christian Ghisler, it's from Total Commander
// Lister API Guide, which can be found at http://ghisler.com.
// Version: 1.8.
unit WLXPlugin;
interface
{$IFDEF MSWINDOWS}
uses
Windows;{$ENDIF}
const
lc_copy=1;
lc_newparams=2;
lc_selectall=3;
lc_setpercent=4;
lcp_wraptext=1;
lcp_fittowindow=2;
lcp_ansi=4;
lcp_ascii=8;
lcp_variable=12;
lcp_forceshow=16;
lcp_fitlargeronly=32;
lcp_center=64;
lcs_findfirst=1;
lcs_matchcase=2;
lcs_wholewords=4;
lcs_backwards=8;
itm_percent=$FFFE;
itm_fontstyle=$FFFD;
itm_wrap=$FFFC;
itm_fit=$FFFB;
itm_next=$FFFA;
itm_center=$FFF9;
LISTPLUGIN_OK=0;
LISTPLUGIN_ERROR=1;
const MAX_PATH=32000;
type
tListDefaultParamStruct=record
size,
PluginInterfaceVersionLow,
PluginInterfaceVersionHi:longint;
DefaultIniName:array[0..MAX_PATH-1] of char;
end;
pListDefaultParamStruct=^tListDefaultParamStruct;
type tdateformat=record
wYear,wMonth,wDay:word;
end;
pdateformat=^tdateformat;
type ttimeformat=record
wHour,wMinute,wSecond:word;
end;
ptimeformat=^ttimeformat;
type HBITMAP = type LongWord;
{ Function prototypes: Functions need to be defined exactly like this!}
{
function ListLoad(ParentWin:thandle;FileToLoad:pchar;ShowFlags:integer):thandle; stdcall;
function ListLoadNext(ParentWin,PluginWin:thandle;FileToLoad:pchar;ShowFlags:integer):integer; stdcall;
procedure ListCloseWindow(ListWin:thandle); stdcall;
procedure ListGetDetectString(DetectString:pchar;maxlen:integer); stdcall;
function ListSearchText(ListWin:thandle;SearchString:pchar;
SearchParameter:integer):integer; stdcall;
function ListSearchDialog(ListWin:thandle;FindNext:integer):integer; stdcall;
function ListSendCommand(ListWin:thandle;Command,Parameter:integer):integer; stdcall;
function ListPrint(ListWin:thandle;FileToPrint,DefPrinter:pchar;
PrintFlags:integer;var Margins:trect):integer; stdcall;
function ListNotificationReceived(ListWin:thandle;Message,wParam,lParam:integer):integer; stdcall;
procedure ListSetDefaultParams(dps:pListDefaultParamStruct); stdcall;
function ListGetPreviewBitmap(FileToLoad:pchar;width,height:integer;
contentbuf:pchar;contentbuflen:integer):hbitmap; stdcall;
}
implementation
end.