diff options
author | Graeme Geldenhuys <graemeg@users.sourceforge.net> | 2007-03-07 14:48:56 +0000 |
---|---|---|
committer | Graeme Geldenhuys <graemeg@users.sourceforge.net> | 2007-03-07 14:48:56 +0000 |
commit | e6714f4d892945103ef0e0339f101f958b40baf4 (patch) | |
tree | 6ddefc7525e6d11a51e5636da9e700cb71091411 | |
parent | 7e5581b378b48ff731f2d3ea078ff8978f25e8aa (diff) | |
download | fpGUI-e6714f4d892945103ef0e0339f101f958b40baf4.tar.xz |
* Added a new unit to manage command line parameters.
* TFCustomApplication now checks for parameters before entering the event loop. -? will show the help without running the application.
* -display parameter is now supported for X11 systems.
-rw-r--r-- | gfx/commandlineparams.pas | 438 | ||||
-rw-r--r-- | gfx/gdi/gfx_gdi.pas | 4 | ||||
-rw-r--r-- | gfx/gfxbase.pas | 235 | ||||
-rw-r--r-- | gfx/x11/fpgfxpackage.lpk | 6 | ||||
-rw-r--r-- | gfx/x11/fpgfxpackage.pas | 3 | ||||
-rw-r--r-- | gfx/x11/gfx_x11.pas | 20 |
6 files changed, 587 insertions, 119 deletions
diff --git a/gfx/commandlineparams.pas b/gfx/commandlineparams.pas new file mode 100644 index 00000000..ec13f3a7 --- /dev/null +++ b/gfx/commandlineparams.pas @@ -0,0 +1,438 @@ +{ + fpGUI - Free Pascal GUI Library + + CommandLineParams - Unit to handle command line processing + + Copyright (C) 2007 See the file AUTHORS.txt, included in this + distribution, for details of the copyright. + + See the file COPYING.modifiedLGPL, included in this distribution, + for details about redistributing fpGUI. + + 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. +} + +unit CommandLineParams; + +{$IFDEF Debug} + {$ASSERTIONS On} +{$ENDIF} + +{$ifdef fpc} + {$mode objfpc}{$H+} +{$endif} + +interface +uses + Classes + ; + +const + ctiCommandLineParamPrefix = '-'; + +type + + TGfxCommandLineParams = class(TObject) + private + FsParams: string; + FslParams: TStringList; + procedure ReadParams; + function WordExtract(const AInput: string; const APos: integer; const ADelims: string): string; + function WordCount(const AStrToProcess: string; ADelims: string): integer; + function WordPosition(const AN: integer; const AStr: string; ADelims: string): integer; + function ExtractChar(const AValue: string; const APos: integer): char; + function CharInStr(const AChr: char; const AStr: string): boolean; + function StripLeadingDelims(const AStrToProcess: string; ADelims: string): string; + function StripTrailingDelims(const AStrToProcess: string; ADelims: string): string; + function NumToken(const AValue, AToken: string): integer; + function Token(const AValue, AToken: string; const APos: integer): string; + function StrTran(AValue, ADel, AIns: string): string; + public + constructor Create; + destructor Destroy; override; + function IsParam(const AParam: string): boolean; overload; + function IsParam(const AParams: array of string): boolean; overload; + function GetParam(const AParam: string): string; + property Params: TStringList read FslParams; + property AsString: string read FsParams; + end; + + +// Singleton +function gCommandLineParams: TGfxCommandLineParams; + + +implementation +uses + SysUtils + ; + +var + uCommandLineParams: TGfxCommandLineParams; + +// Singleton +function gCommandLineParams: TGfxCommandLineParams; +begin + if uCommandLineParams = nil then + uCommandLineParams := TGfxCommandLineParams.Create; + result := uCommandLineParams; +end; + +{ TGfxCommandLineParams } + +constructor TGfxCommandLineParams.Create; +begin + inherited; + FslParams := TStringList.Create; + ReadParams; +end; + +destructor TGfxCommandLineParams.destroy; +begin + FslParams.Free; + inherited; +end; + +function TGfxCommandLineParams.GetParam(const AParam: string): string; +begin + result := FslParams.Values[ upperCase(AParam)]; +end; + +function TGfxCommandLineParams.IsParam(const AParam: string): boolean; +var + i: integer; +begin + result := false; + for i := 0 to FslParams.Count - 1 do begin + if FslParams.Names[i] = upperCase(AParam) then begin + result := true; + break; //==> + end; + end; +end; + +function TGfxCommandLineParams.IsParam(const AParams: array of string): boolean; +var + i: integer; +begin + result := false; + for i := Low(AParams) to High(AParams) do + if IsParam(AParams[i]) then + begin + result := true; + Exit; //==> + end; +end; + +procedure TGfxCommandLineParams.ReadParams; +var + i: integer; + j: integer; + lsNameValue: string; + lsValue: string; + lsName: string; +const + cDelim = ' '; +begin + FsParams := ''; + j := ParamCount; + for i := 1 to j do begin + if FsParams <> '' then FsParams := FsParams + cDelim; + FsParams := FsParams + ParamStr(i); + end ; + + j := WordCount(FsParams, ctiCommandLineParamPrefix); + for i := 1 to j do begin + lsNameValue := WordExtract(FsParams, i, ctiCommandLineParamPrefix); + lsName := Token(lsNameValue, cDelim, 1); + lsValue := copy(lsNameValue, length(lsName) + 1, + length(FsParams) - length(lsValue)); + + lsValue := Trim(lsValue); + lsName := StrTran(lsName, ctiCommandLineParamPrefix, ''); + lsName := upperCase(lsName); + + FslParams.Add(lsName + '=' + lsValue); + end; +end; + +function TGfxCommandLineParams.StrTran(AValue, ADel, AIns: string): string; +var + i: integer; + sToChange: string; +begin + result := ''; + sToChange := AValue; + i := pos(ADel, sToChange); + while i <> 0 do + begin + result := result + copy(sToChange, 1, i-1) + AIns; + delete(sToChange, 1, i+length(ADel)-1); + i := pos(ADel, sToChange); + end; + result := result + sToChange; +end; + +function TGfxCommandLineParams.NumToken(const AValue, AToken: string): integer; +var + i, iCount: integer; + lsValue: string; +begin + result := 0; + if AValue = '' then + Exit; //==> + + iCount := 0; + lsValue := AValue; + i := pos(AToken, lsValue); + while i <> 0 do + begin + delete(lsValue, i, length(AToken)); + inc(iCount); + i := pos(AToken, lsValue); + end; + result := iCount + 1; +end; + +function TGfxCommandLineParams.Token(const AValue, AToken: string; + const APos: integer): string; +var + i, iCount, iNumToken: integer; + lsValue: string; +begin + result := ''; + + iNumToken := NumToken(AValue, AToken); + if APos = 1 then + begin + if pos(AToken, AValue) = 0 then + result := AValue + else + result := copy(AValue, 1, pos(AToken, AValue)-1); + end + else if (iNumToken < APos-1) or (APos<1) then + begin + result := ''; + end + else + begin + { Remove leading blocks } + iCount := 1; + lsValue := AValue; + i := pos(AToken, lsValue); + while (i<>0) and (iCount<APos) do + begin + delete(lsValue, 1, i + length(AToken) - 1); + inc(iCount); + i := pos(AToken, lsValue); + end; + + if (i=0) and (iCount=APos) then + result := lsValue + else if (i=0) and (iCount<>APos) then + result := '' + else + result := copy(lsValue, 1, i-1); + end; +end; + +function TGfxCommandLineParams.WordExtract(const AInput: string; + const APos: integer; const ADelims: string): string; +var + iStart: integer; + i: integer; + iLen: integer; +begin + result := ''; + + // Find the starting pos of the Nth word + iStart := WordPosition(APos, AInput, ADelims); + + if iStart <> 0 then + begin + i := iStart; + iLen := length(AInput); + // Build up result until we come to our next wordDelim + // while (i <= iLen) and not(S[i] in ADelims) do begin + while (i <= iLen) and not(CharInStr(ExtractChar(AInput, i), ADelims)) do + begin + result := result + ExtractChar(AInput, i); + inc(i); + end; + end; +end; + +function TGfxCommandLineParams.WordPosition(const AN: integer; + const AStr: string; ADelims: string): integer; +var + lCount: integer; + lI: Word; + lSLen: integer; +begin + lCount := 0; + lI := 1; + Result := 0; + lSLen := length(AStr); + + while (lI <= lSLen) and (lCount <> AN) do + begin + while (lI <= lSLen) and (CharInStr(ExtractChar(AStr, lI), ADelims)) do + begin + Inc(lI); + end; + + // if we're not beyond end of S, we're at the start of a word + if lI <= lSLen then + begin + Inc(lCount); + end; + + // if not finished, find the end of the current word + if lCount <> AN then + begin + while (lI <= lSLen) and not(CharInStr(ExtractChar(AStr, lI), ADelims)) do + begin + Inc(lI); + end; + end + else + begin + Result := lI; + end; + end; +end; + +function TGfxCommandLineParams.ExtractChar(const AValue: string; + const APos: integer): char; +var + lResult: string; +begin + if APos > length(AValue) then + begin + result := ' '; + exit; + end; + lResult := copy(AValue, APos, 1); + result := lResult[1]; +end; + +function TGfxCommandLineParams.StripLeadingDelims(const AStrToProcess: string; + ADelims: string): string; +var + i: integer; + lCharCurrent: char; +begin + result := AStrToProcess; + // Loop through each char in the string + for i := 1 to length(AStrToProcess) do + begin + // Extract the current character + lCharCurrent := ExtractChar(AStrToProcess, i); + + // Is this character a NON word delim?, then we have found the body of the string. + if not CharInStr(lCharCurrent, ADelims) then + begin + result := copy(AStrToProcess, i, + length(AStrToProcess) - i + 1); + exit; //==> + // The current char is a word delim, but we are at the end of the string - + // so no words + end + else + begin + if i = length(AStrToProcess) then + begin + result := ''; + end; + end; + end; +end; + +// Strip any trailing ADelims +function TGfxCommandLineParams.StripTrailingDelims(const AStrToProcess: string; + ADelims: string): string; +var + i: integer; + lCharCurrent: char; +begin + result := AStrToProcess; + // Loop through each char in the string + for i := length(AStrToProcess) downto 1 do + begin + // Extract the current character + lCharCurrent := ExtractChar(AStrToProcess, i); + + // Is this character a NON word delim?, then we have found the body of the string. + if not CharInStr(lCharCurrent, ADelims) then + begin + result := copy(AStrToProcess, 1, i); + exit; //==> + // The current char is a word delim, but we are at the beginning of the string - + // so no words + end + else + begin + if i = length(AStrToProcess) then + begin + result := ''; + end; + end; + end; +end; + +// Given a set of word delimiters, return number of words in S +function TGfxCommandLineParams.WordCount(const AStrToProcess: string; + ADelims: string): integer; +var + i: integer; + lCharLast: char; + lCharCurrent: char; + lStrToProcess: string; +begin + // Strip any leading ADelims + lStrToProcess := StripLeadingDelims(AStrToProcess, ADelims); + lStrToProcess := StripTrailingDelims(lStrToProcess, ADelims); + + // If lStrToProcess is empty, then there are no words + if lStrToProcess = '' then + begin + result := 0; + Exit; //==> + end; + + // lStrToProcess is not empty, therefore there must be at least one word + // Every wordDelim we find equals another word: + // 0 word delim := 1 word + // 1 word delim := 2 words... + result := 1; + + // lCharLast is used to check for more than 1 wordDelim together + lCharLast := #0; + + for i := 1 to length(lStrToProcess) do + begin + lCharCurrent := ExtractChar(lStrToProcess, i); + if CharInStr(lCharCurrent, ADelims) and not(CharInStr(lCharLast, ADelims)) then + begin + inc(result); + end; + lCharLast := lCharCurrent; + end; +end; + +// Is AChr in the string AStr ? +function TGfxCommandLineParams.CharInStr(const AChr: char; const AStr: string): boolean; +begin + result := pos(AChr, AStr) <> 0; +end; + + +initialization + +finalization + uCommandLineParams.Free; + +end. + diff --git a/gfx/gdi/gfx_gdi.pas b/gfx/gdi/gfx_gdi.pas index 16c17d48..763fe8e3 100644 --- a/gfx/gdi/gfx_gdi.pas +++ b/gfx/gdi/gfx_gdi.pas @@ -161,8 +161,6 @@ type { TGDIApplication } TGDIApplication = class(TFCustomApplication) - private - DoBreakRun: Boolean; public { default methods } constructor Create; override; @@ -1062,7 +1060,7 @@ procedure TGDIApplication.Run; var Msg: TMsg; begin - DoBreakRun := False; + inherited Run; while Windows.GetMessage(@Msg, 0, 0, 0) and (not (QuitWhenLastWindowCloses and (Forms.Count = 0))) and diff --git a/gfx/gfxbase.pas b/gfx/gfxbase.pas index 3a1994a9..7ca51cb0 100644 --- a/gfx/gfxbase.pas +++ b/gfx/gfxbase.pas @@ -424,8 +424,9 @@ type private FOnIdle: TNotifyEvent; FQuitWhenLastWindowCloses: Boolean; - FDisplayName: String; protected + FDisplayName: String; + DoBreakRun: Boolean; FTitle: String; procedure SetTitle(const ATitle: String); public @@ -436,7 +437,7 @@ type procedure AddWindow(AWindow: TFCustomWindow); virtual; procedure RemoveWindow(AWindow: TFCustomWindow); virtual; procedure Initialize(ADisplayName: String = ''); virtual; abstract; - procedure Run; virtual; abstract; + procedure Run; virtual; procedure Quit; virtual; abstract; { Properties } property OnIdle: TNotifyEvent read FOnIdle write FOnIdle; @@ -589,8 +590,9 @@ function KeycodeToText(Key: Word; ShiftState: TShiftState): String; implementation -//uses -// GFXInterface; { Just to get FPC to compile the TGfxCanvas descendants } +uses + CommandLineParams + ; { Exceptions } @@ -1220,112 +1222,112 @@ begin end; case Key of - keyNul: s := 'Null'; - keyBackSpace: s := 'Backspace'; - keyTab: s := 'Tab'; - keyLinefeed: s := 'Linefeed'; - keyReturn: s := 'Enter'; - keyEscape: s := 'Esc'; - Ord(' '): s := 'Space'; - keyDelete: s := 'Del'; - keyVoid: s := 'Void'; - keyBreak: s := 'Break'; - keyScrollForw: s := 'ScrollForw'; - keyScrollBack: s := 'ScrollBack'; - keyBoot: s := 'Boot'; - keyCompose: s := 'Compose'; - keySAK: s := 'SAK'; - keyUndo: s := 'Undo'; - keyRedo: s := 'Redo'; - keyMenu: s := 'Menu'; - keyCancel: s := 'Cancel'; - keyPrintScreen: s := 'PrtScr'; - keyExecute: s := 'Exec'; - keyFind: s := 'Find'; - keyBegin: s := 'Begin'; - keyClear: s := 'Clear'; - keyInsert: s := 'Ins'; - keySelect: s := 'Select'; - keyMacro: s := 'Macro'; - keyHelp: s := 'Help'; - keyDo: s := 'Do'; - keyPause: s := 'Pause'; - keySysRq: s := 'SysRq'; - keyModeSwitch: s := 'ModeSw'; - keyUp: s := 'Up'; - keyDown: s := 'Down'; - keyLeft: s := 'Left'; - keyRight: s := 'Right'; - keyPrior: s := 'PgUp'; - keyNext: s := 'PgDown'; - keyHome: s := 'Home'; - keyEnd: s := 'End'; - keyF0..keyF64: s := 'F' + IntToStr(Key - keyF0); - keyP0..keyP9: s := 'KP' + Chr(Key - keyP0 + Ord('0')); - keyPA..keyPF: s := 'KP' + Chr(Key - keyPA + Ord('A')); + keyNul: s := 'Null'; + keyBackSpace: s := 'Backspace'; + keyTab: s := 'Tab'; + keyLinefeed: s := 'Linefeed'; + keyReturn: s := 'Enter'; + keyEscape: s := 'Esc'; + Ord(' '): s := 'Space'; + keyDelete: s := 'Del'; + keyVoid: s := 'Void'; + keyBreak: s := 'Break'; + keyScrollForw: s := 'ScrollForw'; + keyScrollBack: s := 'ScrollBack'; + keyBoot: s := 'Boot'; + keyCompose: s := 'Compose'; + keySAK: s := 'SAK'; + keyUndo: s := 'Undo'; + keyRedo: s := 'Redo'; + keyMenu: s := 'Menu'; + keyCancel: s := 'Cancel'; + keyPrintScreen: s := 'PrtScr'; + keyExecute: s := 'Exec'; + keyFind: s := 'Find'; + keyBegin: s := 'Begin'; + keyClear: s := 'Clear'; + keyInsert: s := 'Ins'; + keySelect: s := 'Select'; + keyMacro: s := 'Macro'; + keyHelp: s := 'Help'; + keyDo: s := 'Do'; + keyPause: s := 'Pause'; + keySysRq: s := 'SysRq'; + keyModeSwitch: s := 'ModeSw'; + keyUp: s := 'Up'; + keyDown: s := 'Down'; + keyLeft: s := 'Left'; + keyRight: s := 'Right'; + keyPrior: s := 'PgUp'; + keyNext: s := 'PgDown'; + keyHome: s := 'Home'; + keyEnd: s := 'End'; + keyF0..keyF64: s := 'F' + IntToStr(Key - keyF0); + keyP0..keyP9: s := 'KP' + Chr(Key - keyP0 + Ord('0')); + keyPA..keyPF: s := 'KP' + Chr(Key - keyPA + Ord('A')); keyPPlus, keyPMinus, keyPSlash, keyPStar, keyPEqual, keyPSeparator, keyPDecimal, keyPParenLeft, keyPParenRight, keyPSpace, keyPEnter, - keyPTab: s := 'KP' + GetASCIIText; - keyPPlusMinus: s := 'KPPlusMinus'; - keyPBegin: s := 'KPBegin'; - keyPF1..keyPF9: s := 'KPF' + IntToStr(Key - keyPF1); - keyShiftL: s := 'ShiftL'; - keyShiftR: s := 'ShiftR'; - keyCtrlL: s := 'CtrlL'; - keyCtrlR: s := 'CtrlR'; - keyAltL: s := 'AltL'; - keyAltR: s := 'AltR'; - keyMetaL: s := 'MetaL'; - keyMetaR: s := 'MetaR'; - keySuperL: s := 'SuperL'; - keySuperR: s := 'SuperR'; - keyHyperL: s := 'HyperL'; - keyHyperR: s := 'HyperR'; - keyAltGr: s := 'AltGr'; - keyCaps: s := 'Caps'; - keyNum: s := 'Num'; - keyScroll: s := 'Scroll'; - keyShiftLock: s := 'ShiftLock'; - keyCtrlLock: s := 'CtrlLock'; - keyAltLock: s := 'AltLock'; - keyMetaLock: s := 'MetaLock'; - keySuperLock: s := 'SuperLock'; - keyHyperLock: s := 'HyperLock'; - keyAltGrLock: s := 'AltGrLock'; - keyCapsLock: s := 'CapsLock'; - keyNumLock: s := 'NumLock'; - keyScrollLock: s := 'ScrollLock'; - keyDeadRing: s := 'DeadRing'; - keyDeadCaron: s := 'DeadCaron'; - keyDeadOgonek: s := 'DeadOgonek'; - keyDeadIota: s := 'DeadIota'; - keyDeadDoubleAcute: s := 'DeadDoubleAcute'; - keyDeadBreve: s := 'DeadBreve'; - keyDeadAboveDot: s := 'DeadAboveDot'; - keyDeadBelowDot: s := 'DeadBelowDot'; - keyDeadVoicedSound: s := 'DeadVoicedSound'; + keyPTab: s := 'KP' + GetASCIIText; + keyPPlusMinus: s := 'KPPlusMinus'; + keyPBegin: s := 'KPBegin'; + keyPF1..keyPF9: s := 'KPF' + IntToStr(Key - keyPF1); + keyShiftL: s := 'ShiftL'; + keyShiftR: s := 'ShiftR'; + keyCtrlL: s := 'CtrlL'; + keyCtrlR: s := 'CtrlR'; + keyAltL: s := 'AltL'; + keyAltR: s := 'AltR'; + keyMetaL: s := 'MetaL'; + keyMetaR: s := 'MetaR'; + keySuperL: s := 'SuperL'; + keySuperR: s := 'SuperR'; + keyHyperL: s := 'HyperL'; + keyHyperR: s := 'HyperR'; + keyAltGr: s := 'AltGr'; + keyCaps: s := 'Caps'; + keyNum: s := 'Num'; + keyScroll: s := 'Scroll'; + keyShiftLock: s := 'ShiftLock'; + keyCtrlLock: s := 'CtrlLock'; + keyAltLock: s := 'AltLock'; + keyMetaLock: s := 'MetaLock'; + keySuperLock: s := 'SuperLock'; + keyHyperLock: s := 'HyperLock'; + keyAltGrLock: s := 'AltGrLock'; + keyCapsLock: s := 'CapsLock'; + keyNumLock: s := 'NumLock'; + keyScrollLock: s := 'ScrollLock'; + keyDeadRing: s := 'DeadRing'; + keyDeadCaron: s := 'DeadCaron'; + keyDeadOgonek: s := 'DeadOgonek'; + keyDeadIota: s := 'DeadIota'; + keyDeadDoubleAcute: s := 'DeadDoubleAcute'; + keyDeadBreve: s := 'DeadBreve'; + keyDeadAboveDot: s := 'DeadAboveDot'; + keyDeadBelowDot: s := 'DeadBelowDot'; + keyDeadVoicedSound: s := 'DeadVoicedSound'; keyDeadSemiVoicedSound: s := 'DeadSemiVoicedSound'; - keyDeadAcute: s := 'DeadAcute'; - keyDeadCedilla: s := 'DeadCedilla'; - keyDeadCircumflex: s := 'DeadCircumflex'; - keyDeadDiaeresis: s := 'DeadDiaeresis'; - keyDeadGrave: s := 'DeadGrave'; - keyDeadTilde: s := 'DeadTilde'; - keyDeadMacron: s := 'DeadMacron'; - - keyEcuSign: s := 'Ecu'; - keyColonSign: s := 'Colon'; - keyCruzeiroSign: s := 'Cruzeiro'; - keyFFrancSign: s := 'FFranc'; - keyLiraSign: s := 'Lira'; - keyMillSign: s := 'Mill'; - keyNairaSign: s := 'Naira'; - keyPesetaSign: s := 'Peseta'; - keyRupeeSign: s := 'Rupee'; - keyWonSign: s := 'Won'; + keyDeadAcute: s := 'DeadAcute'; + keyDeadCedilla: s := 'DeadCedilla'; + keyDeadCircumflex: s := 'DeadCircumflex'; + keyDeadDiaeresis: s := 'DeadDiaeresis'; + keyDeadGrave: s := 'DeadGrave'; + keyDeadTilde: s := 'DeadTilde'; + keyDeadMacron: s := 'DeadMacron'; + + keyEcuSign: s := 'Ecu'; + keyColonSign: s := 'Colon'; + keyCruzeiroSign: s := 'Cruzeiro'; + keyFFrancSign: s := 'FFranc'; + keyLiraSign: s := 'Lira'; + keyMillSign: s := 'Mill'; + keyNairaSign: s := 'Naira'; + keyPesetaSign: s := 'Peseta'; + keyRupeeSign: s := 'Rupee'; + keyWonSign: s := 'Won'; keyNewSheqelSign: s := 'NewShequel'; - keyDongSign: s := 'Dong'; - keyEuroSign: s := 'Euro'; + keyDongSign: s := 'Dong'; + keyEuroSign: s := 'Euro'; else s := '#' + IntToHex(Key, 4); end; @@ -1342,7 +1344,10 @@ end; constructor TFCustomApplication.Create; begin inherited Create(nil); - FDisplayName := ''; + if gCommandLineParams.IsParam('display') then + FDisplayName := gCommandLineParams.GetParam('display') + else + FDisplayName := ''; Forms := TList.Create; FQuitWhenLastWindowCloses := True; end; @@ -1364,6 +1369,22 @@ begin Forms.Remove(AWindow); end; +procedure TFCustomApplication.Run; +begin + DoBreakRun := False; + + if gCommandLineParams.IsParam('?') then + begin + writeln(' The following parameters are supported by fpGUI applications.'); + writeln(' '); + writeln(' -? Shows this help'); + writeln(' -display fpGUI/X11 only: sets the display to use'); + writeln(' -style Overrides the default (autodetected) GUI style'); + writeln(' '); + DoBreakRun := True; + end; +end; + {procedure TFCustomApplication.CreateForm(AForm: TCustomForm); var form: PForm; diff --git a/gfx/x11/fpgfxpackage.lpk b/gfx/x11/fpgfxpackage.lpk index 773211b0..12033342 100644 --- a/gfx/x11/fpgfxpackage.lpk +++ b/gfx/x11/fpgfxpackage.lpk @@ -21,7 +21,7 @@ <License Value="Modified LGPL "/> <Version Minor="3"/> - <Files Count="8"> + <Files Count="9"> <Item1> <Filename Value="../gfxbase.pas"/> <UnitName Value="GfxBase"/> @@ -54,6 +54,10 @@ <Filename Value="../gelimage.pas"/> <UnitName Value="GELImage"/> </Item8> + <Item9> + <Filename Value="../commandlineparams.pas"/> + <UnitName Value="CommandLineParams"/> + </Item9> </Files> <RequiredPkgs Count="1"> <Item1> diff --git a/gfx/x11/fpgfxpackage.pas b/gfx/x11/fpgfxpackage.pas index a089c522..84c4bda2 100644 --- a/gfx/x11/fpgfxpackage.pas +++ b/gfx/x11/fpgfxpackage.pas @@ -7,7 +7,8 @@ unit fpgfxpackage; interface uses - GfxBase, GFX_X11, gfxinterface, schar16, unitkeys, fpgfx, GELDirty, GELImage; + GfxBase, GFX_X11, gfxinterface, schar16, unitkeys, fpgfx, GELDirty, GELImage, + CommandLineParams; implementation diff --git a/gfx/x11/gfx_x11.pas b/gfx/x11/gfx_x11.pas index 06b41c9c..1f217621 100644 --- a/gfx/x11/gfx_x11.pas +++ b/gfx/x11/gfx_x11.pas @@ -210,9 +210,7 @@ type TX11Application = class(TFCustomApplication) private - DoBreakRun: Boolean; FDirtyList: TDirtyList; - FDisplayName: String; FDefaultFont: TX11FontResourceImpl; FEventFilter: TX11EventFilter; Handle: PDisplay; @@ -1031,8 +1029,8 @@ var WindowEntry: TFCustomWindow; Event: TFEvent; begin - DoBreakRun := False; - + inherited Run; + while (not (QuitWhenLastWindowCloses and (Forms.Count = 0))) and (DoBreakRun = False) do begin @@ -1243,8 +1241,14 @@ end; procedure TX11Application.Initialize(ADisplayName: String = ''); begin - if Length(ADisplayName) = 0 then FDisplayName := XDisplayName(nil) - else FDisplayName := ADisplayName; + if Length(ADisplayName) = 0 then + begin + // Maybe it was passed as a -display parameter. Lets check first! + if FDisplayName = '' then + FDisplayName := XDisplayName(nil) + end + else + FDisplayName := ADisplayName; Handle := XOpenDisplay(PChar(DisplayName)); @@ -1262,7 +1266,9 @@ begin if not Assigned(FDefaultFont) then begin - {$IFNDEF XftSupport} FDefaultFont.FontData := XLoadQueryFont(Handle, 'fixed'); {$ENDIF} + {$IFNDEF XftSupport} + FDefaultFont.FontData := XLoadQueryFont(Handle, 'fixed'); + {$ENDIF} if not Assigned(FDefaultFont) then raise EX11Error.Create(SNoDefaultFont); end; |