mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-02 11:01:20 +02:00
fixed crash on SetShowInTaskBar for non application forms
git-svn-id: trunk@8086 -
This commit is contained in:
parent
205ee1a4fd
commit
5bf19dd85b
3
.gitattributes
vendored
3
.gitattributes
vendored
@ -827,6 +827,9 @@ ide/cleandirdlg.lfm svneol=native#text/plain
|
||||
ide/cleandirdlg.lrs svneol=native#text/pascal
|
||||
ide/cleandirdlg.pas svneol=native#text/pascal
|
||||
ide/clipboardhistory.pas svneol=native#text/pascal
|
||||
ide/codecontextform.lfm svneol=native#text/plain
|
||||
ide/codecontextform.lrs svneol=native#text/plain
|
||||
ide/codecontextform.pas svneol=native#text/plain
|
||||
ide/codeexplopts.lfm svneol=native#text/plain
|
||||
ide/codeexplopts.lrs svneol=native#text/pascal
|
||||
ide/codeexplopts.pas svneol=native#text/pascal
|
||||
|
12
ide/codecontextform.lfm
Normal file
12
ide/codecontextform.lfm
Normal file
@ -0,0 +1,12 @@
|
||||
object CodeContextFrm: TCodeContextFrm
|
||||
Caption = 'CodeContextFrm'
|
||||
ClientHeight = 300
|
||||
ClientWidth = 400
|
||||
PixelsPerInch = 112
|
||||
HorzScrollBar.Page = 399
|
||||
VertScrollBar.Page = 299
|
||||
Left = 290
|
||||
Height = 300
|
||||
Top = 163
|
||||
Width = 400
|
||||
end
|
8
ide/codecontextform.lrs
Normal file
8
ide/codecontextform.lrs
Normal file
@ -0,0 +1,8 @@
|
||||
{ This is an automatically generated lazarus resource file }
|
||||
|
||||
LazarusResources.Add('TCodeContextFrm','FORMDATA',[
|
||||
'TPF0'#15'TCodeContextFrm'#14'CodeContextFrm'#7'Caption'#6#14'CodeContextFrm'
|
||||
+#12'ClientHeight'#3','#1#11'ClientWidth'#3#144#1#13'PixelsPerInch'#2'p'#18'H'
|
||||
+'orzScrollBar.Page'#3#143#1#18'VertScrollBar.Page'#3'+'#1#4'Left'#3'"'#1#6'H'
|
||||
+'eight'#3','#1#3'Top'#3#163#0#5'Width'#3#144#1#0#0
|
||||
]);
|
69
ide/codecontextform.pas
Normal file
69
ide/codecontextform.pas
Normal file
@ -0,0 +1,69 @@
|
||||
{
|
||||
/***************************************************************************
|
||||
CodeContextForm.pas
|
||||
-------------------
|
||||
|
||||
***************************************************************************/
|
||||
|
||||
***************************************************************************
|
||||
* *
|
||||
* This source is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This code 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 *
|
||||
* General Public License for more details. *
|
||||
* *
|
||||
* A copy of the GNU General Public License is available on the World *
|
||||
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
|
||||
* obtain it by writing to the Free Software Foundation, *
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
* *
|
||||
***************************************************************************
|
||||
|
||||
Author: Mattias Gaertner
|
||||
|
||||
Abstract:
|
||||
The popup tooltip window for the source editor.
|
||||
}
|
||||
unit CodeContextForm;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
|
||||
CodeCache, CodeToolManager, SynEdit;
|
||||
|
||||
type
|
||||
TCodeContextFrm = class(TForm)
|
||||
private
|
||||
public
|
||||
end;
|
||||
|
||||
var
|
||||
CodeContextFrm: TCodeContextFrm = nil;
|
||||
|
||||
function ShowCodeContext(Code: TCodeBuffer; Editor: TSynEdit): boolean;
|
||||
|
||||
implementation
|
||||
|
||||
function ShowCodeContext(Code: TCodeBuffer; Editor: TSynEdit): boolean;
|
||||
var
|
||||
LogCaretXY: TPoint;
|
||||
begin
|
||||
Result:=false;
|
||||
LogCaretXY:=Editor.LogicalCaretXY;
|
||||
if not CodeToolBoss.FindCodeContext(Code,LogCaretXY,CodeContext) then
|
||||
exit;
|
||||
end;
|
||||
|
||||
initialization
|
||||
{$I codecontextform.lrs}
|
||||
|
||||
end.
|
||||
|
@ -46,6 +46,8 @@ function ExecuteCodeTemplate(SrcEdit: TSourceEditorInterface;
|
||||
const TemplateName, TemplateValue, TemplateComment,
|
||||
EndOfTokenChr: string;
|
||||
IndentToTokenStart: boolean): boolean;
|
||||
function SubstituteCodeMacros(SrcEdit: TSourceEditorInterface;
|
||||
var Pattern: string): boolean;
|
||||
|
||||
implementation
|
||||
|
||||
@ -63,11 +65,29 @@ var
|
||||
IndentLen: Integer;
|
||||
i: Integer;
|
||||
j: LongInt;
|
||||
Pattern: String;
|
||||
begin
|
||||
Result:=false;
|
||||
//debugln('ExecuteCodeTemplate ',dbgsName(SrcEdit),' ',dbgsName(SrcEdit.EditorControl));
|
||||
AEditor:=SrcEdit.EditorControl as TCustomSynEdit;
|
||||
|
||||
Pattern:=TemplateValue;
|
||||
if copy(Pattern,1,length(CodeTemplateMakroMagic))=CodeTemplateMakroMagic
|
||||
then begin
|
||||
// macros enabled
|
||||
|
||||
// remove first line (i.e. macro enabled flag)
|
||||
Pattern:=TemplateValue;
|
||||
i:=length(CodeTemplateMakroMagic);
|
||||
while (i<=length(Pattern)) and (not (Pattern[i] in [#10,#13])) do inc(i);
|
||||
if (i<length(Pattern)) and (Pattern[i+1] in [#10,#13])
|
||||
and (Pattern[i+1]<>Pattern[i]) then
|
||||
inc(i);
|
||||
Pattern:=copy(Pattern,i+1,length(Pattern));
|
||||
|
||||
if not SubstituteCodeMacros(SrcEdit,Pattern) then exit;
|
||||
end;
|
||||
|
||||
AEditor.BeginUpdate;
|
||||
try
|
||||
// get caret position in text
|
||||
@ -103,10 +123,10 @@ begin
|
||||
NewCaretPos := False;
|
||||
Temp := TStringList.Create;
|
||||
try
|
||||
Temp.Text := TemplateValue;
|
||||
Temp.Text := Pattern;
|
||||
|
||||
// add empty line at end if wanted
|
||||
s:=TemplateValue;
|
||||
s:=Pattern;
|
||||
if (s<>'') and (s[length(s)] in [#10,#13]) then
|
||||
Temp.Add('');
|
||||
|
||||
@ -159,6 +179,107 @@ begin
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
function SubstituteCodeMacros(SrcEdit: TSourceEditorInterface;
|
||||
var Pattern: string): boolean;
|
||||
var
|
||||
p: Integer;
|
||||
len: Integer;
|
||||
MacroStartPos: LongInt;
|
||||
MacroParamStartPos: LongInt;
|
||||
Level: Integer;
|
||||
MacroParamEndPos: LongInt;
|
||||
MacroEndPos: LongInt;
|
||||
|
||||
function SubstituteCodeMacro: boolean;
|
||||
var
|
||||
MacroName: String;
|
||||
Macro: TIDECodeMacro;
|
||||
NewValue: String;
|
||||
//Parameter: String;
|
||||
begin
|
||||
Result:=false;
|
||||
MacroName:=copy(Pattern,MacroStartPos+1,MacroParamStartPos-MacroStartPos-2);
|
||||
Macro:=IDECodeMacros.FindByName(MacroName);
|
||||
if Macro<>nil then begin
|
||||
// macro found
|
||||
//Parameter:=copy(Pattern,MacroParamStartPos,
|
||||
// MacroParamEndPos-MacroParamStartPos);
|
||||
// substitute macros in Parameter
|
||||
|
||||
// TODO
|
||||
|
||||
if Macro.Interactive then begin
|
||||
// collect interactive macro
|
||||
|
||||
// TODO
|
||||
|
||||
end else begin
|
||||
// normal macro -> substitute
|
||||
// TODO
|
||||
|
||||
end;
|
||||
end else begin
|
||||
// macro unknown
|
||||
NewValue:='UnknownMacro('+MacroName+')';
|
||||
end;
|
||||
Pattern:=copy(Pattern,1,MacroStartPos)+NewValue
|
||||
+copy(Pattern,MacroEndPos,len);
|
||||
len:=length(Pattern);
|
||||
p:=MacroStartPos+length(NewValue);
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
begin
|
||||
// replace as many macros as possible
|
||||
p:=1;
|
||||
len:=length(Pattern);
|
||||
while p<len do begin
|
||||
if Pattern[p]<>'$' then begin
|
||||
inc(p);
|
||||
end else begin
|
||||
// could be a macro start
|
||||
MacroStartPos:=p;
|
||||
inc(p);
|
||||
if Pattern[p+1]='$' then begin
|
||||
// $$ is a simple $ character
|
||||
System.Delete(Pattern,p,1);
|
||||
len:=length(Pattern);
|
||||
end else if Pattern[p+1] in ['a'..'z','A'..'Z'] then begin
|
||||
// read macro name
|
||||
while (p<len) and (Pattern[p] in ['a'..'z','A'..'Z','0'..'9','_']) do
|
||||
inc(p);
|
||||
if (p>len) or (p-MacroStartPos=1) or (Pattern[p]<>'(') then begin
|
||||
// missing name or missing round bracket open
|
||||
end else begin
|
||||
// round bracket open found
|
||||
inc(p);
|
||||
MacroParamStartPos:=p;
|
||||
Level:=1;
|
||||
while (p<=len) and (Level>0) do begin
|
||||
case Pattern[p] of
|
||||
'(': inc(Level);
|
||||
')': dec(Level);
|
||||
end;
|
||||
inc(p);
|
||||
end;
|
||||
if Level=0 then begin
|
||||
// macro parameter end found
|
||||
MacroParamEndPos:=p;
|
||||
inc(p);
|
||||
MacroEndPos:=p;
|
||||
if not SubstituteCodeMacro then exit(false);
|
||||
end else begin
|
||||
// macro parameter end not found
|
||||
end;
|
||||
end;
|
||||
end else begin
|
||||
// a normal $ character
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
initialization
|
||||
{$I codemacroprompt.lrs}
|
||||
|
||||
|
@ -103,8 +103,6 @@ type
|
||||
property Items[Index: integer]: TIDECodeMacro read GetItems; default;
|
||||
function Count: integer; override;
|
||||
function Add(Macro: TIDECodeMacro): integer; override;
|
||||
function IndexOf(Macro: TIDECodeMacro): Integer; override;
|
||||
function IndexByName(const AName: string): Integer; override;
|
||||
function FindByName(const AName: string): TIDECodeMacro; override;
|
||||
function CreateUniqueName(const AName: string): string; override;
|
||||
end;
|
||||
@ -547,7 +545,7 @@ var
|
||||
|
||||
procedure AddLine(const s: string);
|
||||
begin
|
||||
if (LineCount=0) and (s='$(EnableMakros)') then
|
||||
if (LineCount=0) and (s=CodeTemplateMakroMagic) then
|
||||
EnableMakros:=true
|
||||
else
|
||||
TemplateSynEdit.Lines.Add(s);
|
||||
@ -610,7 +608,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
if UseMakrosCheckBox.Checked then
|
||||
NewValue:='$(EnableMakros)'+LineEnding+NewValue;
|
||||
NewValue:=CodeTemplateMakroMagic+LineEnding+NewValue;
|
||||
SynAutoComplete.CompletionValues[i]:=NewValue;
|
||||
end;
|
||||
|
||||
@ -653,35 +651,25 @@ begin
|
||||
Result:=FItems.Add(Macro);
|
||||
end;
|
||||
|
||||
function TLazCodeMacros.IndexOf(Macro: TIDECodeMacro): Integer;
|
||||
begin
|
||||
Result:=FItems.IndexOf(Macro);
|
||||
end;
|
||||
|
||||
function TLazCodeMacros.IndexByName(const AName: string): Integer;
|
||||
begin
|
||||
Result:=Count-1;
|
||||
while (Result>=0) and (CompareText(Items[Result].Name,AName)<>0) do
|
||||
dec(Result);
|
||||
end;
|
||||
|
||||
function TLazCodeMacros.FindByName(const AName: string): TIDECodeMacro;
|
||||
var
|
||||
i: LongInt;
|
||||
begin
|
||||
i:=IndexByName(AName);
|
||||
if i>=0 then
|
||||
Result:=Items[i]
|
||||
else
|
||||
Result:=nil;
|
||||
i:=Count-1;
|
||||
while (i>=0) do begin
|
||||
Result:=Items[i];
|
||||
if (CompareText(Result.Name,AName)<>0) then exit;
|
||||
dec(i);
|
||||
end;
|
||||
Result:=nil;
|
||||
end;
|
||||
|
||||
function TLazCodeMacros.CreateUniqueName(const AName: string): string;
|
||||
begin
|
||||
Result:=AName;
|
||||
if IndexByName(Result)<0 then exit;
|
||||
if FindByName(Result)=nil then exit;
|
||||
Result:=CreateFirstIdentifier(Result);
|
||||
while IndexByName(Result)>=0 do
|
||||
while FindByName(Result)<>nil do
|
||||
Result:=CreateNextIdentifier(Result);
|
||||
end;
|
||||
|
||||
|
@ -102,8 +102,6 @@ type
|
||||
property Items[Index: integer]: TIDECodeMacro read GetItems; default;
|
||||
function Count: integer; virtual; abstract;
|
||||
function Add(Macro: TIDECodeMacro): integer; virtual; abstract;
|
||||
function IndexOf(Macro: TIDECodeMacro): Integer; virtual; abstract;
|
||||
function IndexByName(const AName: string): Integer; virtual; abstract;
|
||||
function FindByName(const AName: string): TIDECodeMacro; virtual; abstract;
|
||||
function CreateUniqueName(const AName: string): string; virtual; abstract;
|
||||
end;
|
||||
@ -111,6 +109,9 @@ type
|
||||
var
|
||||
IDECodeMacros: TIDECodeMacros = nil; // set by the IDE
|
||||
|
||||
const
|
||||
CodeTemplateMakroMagic = '$(EnableMakros)';
|
||||
|
||||
|
||||
function RegisterCodeMacro(const Name: string;
|
||||
const ShortDescription, LongDescription: string;
|
||||
|
@ -239,6 +239,10 @@ begin
|
||||
|
||||
if TheWinControl is TCustomPage then
|
||||
UpdateNotebookPageTab(nil,TheWinControl);
|
||||
|
||||
if TheWinControl is TCustomForm then
|
||||
SetFormShowInTaskbar(TCustomForm(TheWinControl),
|
||||
TCustomForm(TheWinControl).ShowInTaskbar);
|
||||
end;
|
||||
|
||||
end;
|
||||
|
@ -4688,9 +4688,6 @@ begin
|
||||
if ASetupProps then
|
||||
{ TODO: call this in CreateHandle when converted: SetProperties(ALCLObject) };
|
||||
|
||||
if ALCLObject is TCustomForm then
|
||||
TGtkWSCustomForm.SetShowInTaskbar(ALCLObject as TCustomForm, (ALCLObject as TCustomForm).ShowInTaskbar);
|
||||
|
||||
if AGTKObject <> nil then begin
|
||||
{$IFNDEF NoStyle}
|
||||
if (ALCLObject is TCustomForm) and (TCustomForm(ALCLObject).Parent=nil) then
|
||||
|
@ -912,6 +912,43 @@ begin
|
||||
GTKAPIWidget_HideCaret(PGTKAPIWidget(MainWidget),CaretWasVisible);
|
||||
end;
|
||||
|
||||
procedure SetFormShowInTaskbar(AForm: TCustomForm;
|
||||
const AValue: TShowInTaskbar);
|
||||
var
|
||||
Enable: boolean;
|
||||
Widget: PGtkWidget;
|
||||
begin
|
||||
if (AForm.Parent<>nil) or not (AForm.HandleAllocated) then exit;
|
||||
Widget:=PGtkWidget(AForm.Handle);
|
||||
if Widget^.Window=nil then begin
|
||||
// widget not yet realized
|
||||
exit;
|
||||
end;
|
||||
|
||||
Enable := AValue <> stNever;
|
||||
if (AValue = stDefault)
|
||||
and (Application<>nil) and (Application.MainForm <> nil)
|
||||
and (Application.MainForm <> AForm) then
|
||||
Enable := false;
|
||||
|
||||
//debugln('SetGtkWindowShowInTaskbar ',DbgSName(AForm),' ',dbgs(Enable));
|
||||
SetGtkWindowShowInTaskbar(PGtkWindow(Widget),Enable);
|
||||
end;
|
||||
|
||||
procedure SetGtkWindowShowInTaskbar(AGtkWindow: PGtkWindow; Value: boolean);
|
||||
begin
|
||||
{$IFDEF GTK1}
|
||||
if PgtkWidget(AGtkWindow)^.Window=nil then begin
|
||||
// widget not yet realized
|
||||
exit;
|
||||
end;
|
||||
GDK_WINDOW_SHOW_IN_TASKBAR(PGdkWindowPrivate(PGtkWidget(AGtkWindow)^.Window),
|
||||
Value);
|
||||
{$ELSE}
|
||||
gtk_window_set_skip_taskbar_hint(AGtkWindow, not Value);
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
procedure SetComboBoxText(ComboWidget: PGtkCombo; const NewText: string);
|
||||
|
||||
|
@ -322,6 +322,9 @@ function GetRCStyleDebugReport(AStyle: PGtkRcStyle): string;
|
||||
function WidgetFlagsToString(Widget: PGtkWidget): string;
|
||||
function GdkColorToStr(Color: PGDKColor): string;
|
||||
function GetWidgetStyleReport(Widget: PGtkWidget): string;
|
||||
procedure BeginGDKErrorTrap;
|
||||
procedure EndGDKErrorTrap;
|
||||
|
||||
|
||||
// gtk resources
|
||||
procedure Set_RC_Name(Sender: TObject; AWidget: PGtkWidget);
|
||||
@ -379,6 +382,11 @@ Procedure FixedPutControl(Parent, Child: PGTKWidget; Left, Top: Longint);
|
||||
// caret
|
||||
procedure HideCaretOfWidgetGroup(ChildWidget: PGtkWidget;
|
||||
var MainWidget: PGtkWidget; var CaretWasVisible: boolean);
|
||||
|
||||
// forms
|
||||
procedure SetFormShowInTaskbar(AForm: TCustomForm;
|
||||
const AValue: TShowInTaskbar);
|
||||
procedure SetGtkWindowShowInTaskbar(AGtkWindow: PGtkWindow; Value: boolean);
|
||||
|
||||
// combobox
|
||||
procedure SetComboBoxText(ComboWidget: PGtkCombo; NewText: PChar);
|
||||
@ -752,10 +760,6 @@ function gtk_widget_get_ythickness(Style: PGTKStyle): gint; overload;
|
||||
function gtk_widget_get_xthickness(Style: PGTKWidget): gint; overload;
|
||||
function gtk_widget_get_ythickness(Style: PGTKWidget): gint; overload;
|
||||
|
||||
// debugging
|
||||
procedure BeginGDKErrorTrap;
|
||||
procedure EndGDKErrorTrap;
|
||||
|
||||
{$Ifdef GTK1}
|
||||
type
|
||||
PGtkOldEditable = PGtkEditable;
|
||||
|
@ -211,26 +211,8 @@ end;
|
||||
|
||||
procedure TGtkWSCustomForm.SetShowInTaskbar(const AForm: TCustomForm;
|
||||
const AValue: TShowInTaskbar);
|
||||
var
|
||||
{$IFDEF GTK1}
|
||||
AWindow: PGdkWindowPrivate;
|
||||
{$ENDIF}
|
||||
enable: boolean;
|
||||
begin
|
||||
if (AForm.Parent<>nil) or not (AForm.HandleAllocated) then exit;
|
||||
|
||||
enable := AValue <> stNever;
|
||||
if (Application.MainForm <> nil) and (Application.MainForm <> AForm)
|
||||
and (AValue = stDefault) then
|
||||
enable := false;
|
||||
|
||||
{$IFDEF GTK1}
|
||||
AWindow := PGdkWindowPrivate(PGtkWidget(AForm.Handle)^.window);
|
||||
GDK_WINDOW_SHOW_IN_TASKBAR(AWindow, enable);
|
||||
{$ELSE}
|
||||
DebugLn('TGtkWSCustomForm.SetShowInTaskbar ',dbgsName(AForm),' ',dbgs(enable));
|
||||
gtk_window_set_skip_taskbar_hint(PGtkWindow(AForm.Handle), not enable);
|
||||
{$ENDIF}
|
||||
SetFormShowInTaskbar(AForm,AValue);
|
||||
end;
|
||||
|
||||
procedure TGtkWSCustomForm.ShowModal(const ACustomForm: TCustomForm);
|
||||
|
Loading…
Reference in New Issue
Block a user