diff --git a/.gitattributes b/.gitattributes index 7c2fe3e983..175bbeadf3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1643,6 +1643,16 @@ examples/toolbar.lpi svneol=native#text/plain examples/toolbar.pp svneol=native#text/pascal examples/trackbar.lpi svneol=native#text/plain examples/trackbar.pp svneol=native#text/pascal +examples/trayicon/createbundle.sh -text +examples/trayicon/frmtest.dfm -text +examples/trayicon/frmtest.lfm -text +examples/trayicon/frmtest.lrs -text +examples/trayicon/frmtest.pas -text +examples/trayicon/icon.ico -text +examples/trayicon/magnifier.res -text +examples/trayicon/wndtray.dpr -text +examples/trayicon/wndtray.lpi -text +examples/trayicon/wndtray.lps -text examples/treeview/README.txt svneol=native#text/plain examples/treeview/TV_Add_Remove.dpr svneol=native#text/pascal examples/treeview/TV_Add_Remove.res svneol=native#unset diff --git a/examples/trayicon/createbundle.sh b/examples/trayicon/createbundle.sh new file mode 100644 index 0000000000..bd4594084a --- /dev/null +++ b/examples/trayicon/createbundle.sh @@ -0,0 +1,54 @@ +#!/bin/sh +# Force Bourne shell in case tcsh is default. +# + +appname=Wndtray +appfolder=$appname.app +macosfolder=$appfolder/Contents/MacOS +plistfile=$appfolder/Contents/Info.plist +appfile=wndtray +# +if ! [ -e $appfile ] +then + echo "$appfile does not exist" +elif [ -e $appfolder ] +then + echo "$appfolder already exists" +else + echo "Creating $appfolder..." + mkdir $appfolder + mkdir $appfolder/Contents + mkdir $appfolder/Contents/MacOS + mkdir $appfolder/Contents/Resources +# +# Instead of copying executable into .app folder after each compile, +# simply create a symbolic link to executable. + ln -s ../../../$appname $macosfolder/$appname +# Copy the resource files to the correct place + cp icon.ico $appfolder/Contents/Resources +# +# Create PkgInfo file. + echo "APPL????" >$appfolder/Contents/PkgInfo +# +# Create information property list file (Info.plist). + echo '' >$plistfile + echo '' >>$plistfile + echo '' >>$plistfile + echo '' >>$plistfile + echo ' CFBundleDevelopmentRegion' >>$plistfile + echo ' English' >>$plistfile + echo ' CFBundleExecutable' >>$plistfile + echo ' '$appname'' >>$plistfile + echo ' CFBundleInfoDictionaryVersion' >>$plistfile + echo ' 6.0' >>$plistfile + echo ' CFBundlePackageType' >>$plistfile + echo ' APPL' >>$plistfile + echo ' CFBundleSignature' >>$plistfile + echo ' ????' >>$plistfile + echo ' CFBundleVersion' >>$plistfile + echo ' 1.0' >>$plistfile + echo ' CSResourcesFileMapped' >>$plistfile + echo ' ' >>$plistfile + echo '' >>$plistfile + echo '' >>$plistfile +fi diff --git a/examples/trayicon/frmtest.dfm b/examples/trayicon/frmtest.dfm new file mode 100644 index 0000000000..4a40c77bdd --- /dev/null +++ b/examples/trayicon/frmtest.dfm @@ -0,0 +1,33 @@ +object Form1: TForm1 + Caption = 'Form1' + ClientHeight = 300 + ClientWidth = 400 + OnCreate = FormCreate + PixelsPerInch = 96 + Left = 290 + Height = 300 + Top = 175 + Width = 400 + object Button1: TButton + Caption = 'Show' + OnClick = Button1Click + TabOrder = 0 + Left = 75 + Height = 25 + Top = 56 + Width = 75 + end + object Button2: TButton + Caption = 'Hide' + OnClick = Button2Click + TabOrder = 1 + Left = 75 + Height = 25 + Top = 95 + Width = 75 + end + object SystrayIcon: TTrayIcon + left = 221 + top = 145 + end +end diff --git a/examples/trayicon/frmtest.lfm b/examples/trayicon/frmtest.lfm new file mode 100644 index 0000000000..41a3523c84 --- /dev/null +++ b/examples/trayicon/frmtest.lfm @@ -0,0 +1,60 @@ +object Form1: TForm1 + Left = 290 + Height = 300 + Top = 175 + Width = 400 + HorzScrollBar.Page = 399 + VertScrollBar.Page = 299 + ActiveControl = Button1 + Caption = 'Form1' + ClientHeight = 300 + ClientWidth = 400 + OnCreate = FormCreate + object Button1: TButton + Left = 56 + Height = 33 + Top = 56 + Width = 94 + BorderSpacing.InnerBorder = 4 + Caption = 'Show' + OnClick = Button1Click + TabOrder = 0 + end + object Button2: TButton + Left = 56 + Height = 33 + Top = 112 + Width = 94 + BorderSpacing.InnerBorder = 4 + Caption = 'Hide' + OnClick = Button2Click + TabOrder = 1 + end + object Button3: TButton + Left = 224 + Height = 33 + Top = 56 + Width = 94 + BorderSpacing.InnerBorder = 4 + Caption = 'Paint Test' + OnClick = Button3Click + TabOrder = 2 + end + object PopupMenu: TPopupMenu + left = 180 + top = 260 + object MenuItem1: TMenuItem + Caption = 'New Item1' + end + object MenuItem3: TMenuItem + Caption = 'New Item3' + end + object MenuItem2: TMenuItem + Caption = 'New Item2' + end + end + object SystrayIcon: TTrayIcon + left = 221 + top = 145 + end +end diff --git a/examples/trayicon/frmtest.lrs b/examples/trayicon/frmtest.lrs new file mode 100644 index 0000000000..225e22bfe4 --- /dev/null +++ b/examples/trayicon/frmtest.lrs @@ -0,0 +1,19 @@ +{ This is an automatically generated lazarus resource file } + +LazarusResources.Add('TForm1','FORMDATA',[ + 'TPF0'#6'TForm1'#5'Form1'#4'Left'#3'"'#1#6'Height'#3','#1#3'Top'#3#175#0#5'Wi' + +'dth'#3#144#1#18'HorzScrollBar.Page'#3#143#1#18'VertScrollBar.Page'#3'+'#1#13 + +'ActiveControl'#7#7'Button1'#7'Caption'#6#5'Form1'#12'ClientHeight'#3','#1#11 + +'ClientWidth'#3#144#1#8'OnCreate'#7#10'FormCreate'#0#7'TButton'#7'Button1'#4 + +'Left'#2'8'#6'Height'#2'!'#3'Top'#2'8'#5'Width'#2'^'#25'BorderSpacing.InnerB' + +'order'#2#4#7'Caption'#6#4'Show'#7'OnClick'#7#12'Button1Click'#8'TabOrder'#2 + +#0#0#0#7'TButton'#7'Button2'#4'Left'#2'8'#6'Height'#2'!'#3'Top'#2'p'#5'Width' + +#2'^'#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#4'Hide'#7'OnClick'#7#12 + +'Button2Click'#8'TabOrder'#2#1#0#0#7'TButton'#7'Button3'#4'Left'#3#224#0#6'H' + +'eight'#2'!'#3'Top'#2'8'#5'Width'#2'^'#25'BorderSpacing.InnerBorder'#2#4#7'C' + +'aption'#6#10'Paint Test'#7'OnClick'#7#12'Button3Click'#8'TabOrder'#2#2#0#0 + +#10'TPopupMenu'#9'PopupMenu'#4'left'#3#180#0#3'top'#3#4#1#0#9'TMenuItem'#9'M' + +'enuItem1'#7'Caption'#6#9'New Item1'#0#0#9'TMenuItem'#9'MenuItem3'#7'Caption' + +#6#9'New Item3'#0#0#9'TMenuItem'#9'MenuItem2'#7'Caption'#6#9'New Item2'#0#0#0 + +#9'TTrayIcon'#11'SystrayIcon'#4'left'#3#221#0#3'top'#3#145#0#0#0#0 +]); diff --git a/examples/trayicon/frmtest.pas b/examples/trayicon/frmtest.pas new file mode 100644 index 0000000000..179fc0f1cb --- /dev/null +++ b/examples/trayicon/frmtest.pas @@ -0,0 +1,173 @@ +{ + frmtest.dpr + + ***************************************************************************** + * * + * This demonstration program is public domain, which means no copyright, * + * but also no warranty! * + * * + * This program 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. * + * * + ***************************************************************************** + + Author: Felipe Monteiro de Carvalho +} +unit frmtest; + +{$ifdef fpc} + {$mode delphi}{$H+} +{$endif} + +interface + +uses + Classes, SysUtils, +{$ifdef fpc} + LResources, +{$endif} + Forms, Controls, Graphics, Dialogs, Buttons, StdCtrls, Menus, + ExtCtrls; + +type + + { TForm1 } + + TForm1 = class(TForm) + Button1: TButton; + Button2: TButton; + Button3: TButton; + MenuItem1: TMenuItem; + MenuItem2: TMenuItem; + MenuItem3: TMenuItem; + PopupMenu: TPopupMenu; + SystrayIcon: TTrayIcon; + procedure Button1Click(Sender: TObject); + procedure Button2Click(Sender: TObject); + procedure Button3Click(Sender: TObject); + procedure FormCreate(Sender: TObject); + procedure HandleClick(Sender: TObject); + private + { private declarations } + procedure DoPaint(Sender: TObject); + public + { public declarations } + end; + +var + Form1: TForm1; + +{$ifndef fpc} + {$R frmtest.dfm} +{$endif} + +implementation + +{$ifdef Windows} +uses Windows; +{$endif} +{$IFDEF Darwin} +uses FPCMacOSAll; +{$ENDIF} + +{ TForm1 } + +procedure TForm1.Button1Click(Sender: TObject); +begin + SystrayIcon.Visible := True; +end; + +procedure TForm1.Button2Click(Sender: TObject); +begin + SystrayIcon.Visible := False; +end; + +procedure TForm1.Button3Click(Sender: TObject); +var + MyImage, SecondImage: TIcon; +begin + MyImage := TIcon.Create; + SecondImage := TIcon.Create; + + MyImage.LoadFromFile('icon.ico'); + SecondImage.Height := 22; + SecondImage.Width := 22; + {$IFDEF FPC} + SecondImage.Canvas.Draw(0, 0, MyImage); + {$ENDIF} + Canvas.Draw(0, 0, SecondImage); + + SecondImage.Free; + MyImage.Free; +end; + +procedure TForm1.FormCreate(Sender: TObject); +const + IDI_ICON1 = 101; + IDI_ICON2 = 115; + BundleResourceFolder = '/Contents/Resources/'; +var +{$IFDEF Darwin} + pathRef: CFURLRef; + pathCFStr: CFStringRef; + pathStr: shortstring; +{$ENDIF} + pathMedia: string; +begin + pathMedia := ''; + + // Under Mac OS X we need to get the location of the bundle +{$IFDEF Darwin} + pathRef := CFBundleCopyBundleURL(CFBundleGetMainBundle()); + pathCFStr := CFURLCopyFileSystemPath(pathRef, kCFURLPOSIXPathStyle); + CFStringGetPascalString(pathCFStr, @pathStr, 255, CFStringGetSystemEncoding()); + CFRelease(pathRef); + CFRelease(pathCFStr); + + pathMedia := pathStr + BundleResourceFolder; +{$ENDIF} + +{$ifdef Windows} + SystrayIcon.Icon.Handle := LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); + +// Loading from a file should also work +// SystrayIcon.Icon.LoadFromFile('icon.ico'); +{$else} + SystrayIcon.Icon.LoadFromFile(pathMedia + 'icon.ico'); +{$endif} + + SystrayIcon.Hint := 'my tool tip'; + + SystrayIcon.OnClick := HandleClick; + +// SystrayIcon.OnPaint := DoPaint; + + SystrayIcon.PopUpMenu := PopupMenu; +end; + +procedure TForm1.HandleClick(Sender: TObject); +begin + Application.MessageBox('Text', 'Caption', 0); +end; + +procedure TForm1.DoPaint(Sender: TObject); +var + MyImage: TIcon; +begin + MyImage := TIcon.Create; + MyImage.LoadFromFile('icon.ico'); + {$IFDEF FPC} + SystrayIcon.Canvas.Draw(0, 0, MyImage); + {$ENDIF} + MyImage.Free; + WriteLn('Paint'); +end; + +initialization +{$ifdef fpc} + {$I frmtest.lrs} +{$endif} + +end. + diff --git a/examples/trayicon/icon.ico b/examples/trayicon/icon.ico new file mode 100644 index 0000000000..3fe34ad084 Binary files /dev/null and b/examples/trayicon/icon.ico differ diff --git a/examples/trayicon/magnifier.res b/examples/trayicon/magnifier.res new file mode 100644 index 0000000000..7e9cbe1834 Binary files /dev/null and b/examples/trayicon/magnifier.res differ diff --git a/examples/trayicon/wndtray.dpr b/examples/trayicon/wndtray.dpr new file mode 100644 index 0000000000..ed6c36d189 --- /dev/null +++ b/examples/trayicon/wndtray.dpr @@ -0,0 +1,41 @@ +{ + wndtray.dpr + + ***************************************************************************** + * * + * This demonstration program is public domain, witch means no copyright, * + * but also no warranty! * + * * + * This program 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. * + * * + ***************************************************************************** + + Author: Felipe Monteiro de Carvalho +} +program wndtray; + +{$ifdef fpc} + {$mode objfpc}{$H+} +{$endif} + +uses +{$ifdef fpc} + Interfaces, +{$endif} + Forms, + frmtest in 'frmtest.pas'; + +{ add your units here } + +{$ifdef Windows} + {$R magnifier.res} +{$endif} + +begin + Application.Initialize; + Application.CreateForm(TForm1, Form1); + Application.Run; +end. + diff --git a/examples/trayicon/wndtray.lpi b/examples/trayicon/wndtray.lpi new file mode 100644 index 0000000000..413c08a18a --- /dev/null +++ b/examples/trayicon/wndtray.lpi @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/trayicon/wndtray.lps b/examples/trayicon/wndtray.lps new file mode 100644 index 0000000000..2f22376808 --- /dev/null +++ b/examples/trayicon/wndtray.lps @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +