Browse Source

* Major restructuring and simplifications

sg 25 years ago
parent
commit
83856ede6a
1 changed files with 49 additions and 73 deletions
  1. 49 73
      fcl/shedit/gtkdemo.pp

+ 49 - 73
fcl/shedit/gtkdemo.pp

@@ -1,22 +1,15 @@
 {
 {
-  $Id$
+    $Id$
 
 
-  GTK (demo) implementation for shedit
-  Copyright (C) 1999  Sebastian Guenther ([email protected])
+    GTK (demo) implementation for shedit
+    Copyright (C) 1999  Sebastian Guenther ([email protected])
 
 
-  This program 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.
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
 
 
-  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.  See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with this program; if not, write to the Free Software
-  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+    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.
 }
 }
 
 
 {$MODE objfpc}
 {$MODE objfpc}
@@ -28,73 +21,52 @@ uses
   Doc_text, shedit, sh_pas, sh_xml,
   Doc_text, shedit, sh_pas, sh_xml,
   GDK, GTK, GtkSHEdit;
   GDK, GTK, GtkSHEdit;
 
 
-type
-  TGtkSHTextEdit = class(TGtkSHEdit)
-  public
-    constructor Create(ADoc: TTextDoc);
-  end;
-
-  TGtkSHPasEdit = class(TGtkSHEdit)
-  public
-    constructor Create(ADoc: TTextDoc);
-  end;
 
 
-  TGtkSHXMLEdit = class(TGtkSHEdit)
-  public
-    constructor Create(ADoc: TTextDoc);
-  end;
-
-constructor TGtkSHTextEdit.Create(ADoc: TTextDoc);
-var
-  e: TSHTextEdit;
+function CreateTextEditWidget(ADoc: TTextDoc): TGtkSHWidget;
 begin
 begin
-  inherited Create;
-  e := TSHTextEdit.Create(ADoc, Self);
-  SetEdit(e);
+  Result := TGtkSHWidget.Create(ADoc, TSHTextEdit);
 end;
 end;
 
 
-constructor TGtkSHPasEdit.Create(ADoc: TTextDoc);
+function CreatePasEditWidget(ADoc: TTextDoc): TGtkSHWidget;
 var
 var
   e: TSHPasEdit;
   e: TSHPasEdit;
 begin
 begin
-  inherited Create;
-  e := TSHPasEdit.Create(ADoc, Self);
-  SetEdit(e);
-
-  e.shSymbol     := AddSHStyle('Symbol',        colBrown,       colDefault, fsNormal);
-  e.shKeyword    := AddSHStyle('Keyword',       colBlack,       colDefault, fsBold);
-  e.shComment    := AddSHStyle('Comment',       colDarkCyan,    colDefault, fsItalics);
-  e.shDirective  := AddSHStyle('Directive',     colRed,         colDefault, fsItalics);
-  e.shNumbers    := AddSHStyle('Numbers',       colDarkMagenta, colDefault, fsNormal);
-  e.shCharacters := AddSHStyle('Characters',    colDarkBlue,    colDefault, fsNormal);
-  e.shStrings    := AddSHStyle('Strings',       colBlue,        colDefault, fsNormal);
-  e.shAssembler  := AddSHStyle('Assembler',     colDarkGreen,   colDefault, fsNormal);
+  Result := TGtkSHWidget.Create(ADoc, TSHPasEdit);
+  e := Result.Edit as TSHPasEdit;
+
+  e.shSymbol     := Result.AddSHStyle('Symbol',        colBrown,       colDefault, fsNormal);
+  e.shKeyword    := Result.AddSHStyle('Keyword',       colBlack,       colDefault, fsBold);
+  e.shComment    := Result.AddSHStyle('Comment',       colDarkCyan,    colDefault, fsItalics);
+  e.shDirective  := Result.AddSHStyle('Directive',     colRed,         colDefault, fsItalics);
+  e.shNumbers    := Result.AddSHStyle('Numbers',       colDarkMagenta, colDefault, fsNormal);
+  e.shCharacters := Result.AddSHStyle('Characters',    colDarkBlue,    colDefault, fsNormal);
+  e.shStrings    := Result.AddSHStyle('Strings',       colBlue,        colDefault, fsNormal);
+  e.shAssembler  := Result.AddSHStyle('Assembler',     colDarkGreen,   colDefault, fsNormal);
 end;
 end;
 
 
-constructor TGtkSHXMLEdit.Create(ADoc: TTextDoc);
+function CreateXMLEditWidget(ADoc: TTextDoc): TGtkSHWidget;
 var
 var
   e: TSHXMLEdit;
   e: TSHXMLEdit;
 begin
 begin
-  inherited Create;
-  e := TSHXMLEdit.Create(ADoc, Self);
-  SetEdit(e);
-
-  e.shTag        := AddSHStyle('Tag',           colBlack,       colDefault, fsBold);
-  e.shTagName    := AddSHStyle('Tag Name',      colBlack,       colDefault, fsBold);
-  e.shDefTagName := AddSHStyle('Definition Tag Name', colDarkGreen, colDefault, fsBold);
-  e.shArgName    := AddSHStyle('Argument Name', colBrown,       colDefault, fsNormal);
-  e.shString     := AddSHStyle('String',        colBlue,        colDefault, fsNormal);
-  e.shReference  := AddSHStyle('Reference',     colDarkMagenta, colDefault, fsNormal);
-  e.shInvalid    := AddSHStyle('Invalid',       colRed,         colDefault, fsNormal);
-  e.shComment    := AddSHStyle('Comment',       colDarkCyan,    colDefault, fsItalics);
-  e.shCDATA      := AddSHStyle('CDATA',         colDarkGreen,   colDefault, fsNormal);
+  Result := TGtkSHWidget.Create(ADoc, TSHXMLEdit);
+  e := Result.Edit as TSHXMLEdit;
+
+  e.shTag        := Result.AddSHStyle('Tag',           colBlack,       colDefault, fsBold);
+  e.shTagName    := Result.AddSHStyle('Tag Name',      colBlack,       colDefault, fsBold);
+  e.shDefTagName := Result.AddSHStyle('Definition Tag Name', colDarkGreen, colDefault, fsBold);
+  e.shArgName    := Result.AddSHStyle('Argument Name', colBrown,       colDefault, fsNormal);
+  e.shString     := Result.AddSHStyle('String',        colBlue,        colDefault, fsNormal);
+  e.shReference  := Result.AddSHStyle('Reference',     colDarkMagenta, colDefault, fsNormal);
+  e.shInvalid    := Result.AddSHStyle('Invalid',       colRed,         colDefault, fsNormal);
+  e.shComment    := Result.AddSHStyle('Comment',       colDarkCyan,    colDefault, fsItalics);
+  e.shCDATA      := Result.AddSHStyle('CDATA',         colDarkGreen,   colDefault, fsNormal);
 end;
 end;
 
 
 
 
 var
 var
   MainWindow, Notebook: PGtkWidget;
   MainWindow, Notebook: PGtkWidget;
-  Pages: array[0..2] of TGtkSHEdit;
-  PasDoc, XMLDoc: TTextDoc;
+  Pages: array[0..2] of TGtkSHWidget;
+  PasDoc, XMLDoc, TxtDoc: TTextDoc;
 
 
 procedure OnMainWindowDestroyed; cdecl;
 procedure OnMainWindowDestroyed; cdecl;
 begin
 begin
@@ -112,15 +84,14 @@ begin
   gtk_signal_connect(PGtkObject(MainWindow), 'destroy', GTK_SIGNAL_FUNC(@OnMainWindowDestroyed), nil);
   gtk_signal_connect(PGtkObject(MainWindow), 'destroy', GTK_SIGNAL_FUNC(@OnMainWindowDestroyed), nil);
 
 
   // Set up documents
   // Set up documents
-  PasDoc := TTextDoc.Create;
-  PasDoc.LoadFromFile('gtkdemo.pp');
-  XMLDoc := TTextDoc.Create;
-  XMLDoc.LoadFromFile('gtkdemo.pp');
+  PasDoc := TTextDoc.Create; PasDoc.LoadFromFile('gtkdemo.pp');
+  XMLDoc := TTextDoc.Create; XMLDoc.LoadFromFile('simple.xml');
+  TxtDoc := TTextDoc.Create; TxtDoc.LoadFromFile('README');
 
 
   // Create notebook pages (editor widgets)
   // Create notebook pages (editor widgets)
-  Pages[0] := TGtkSHPasEdit.Create(PasDoc);
-  Pages[1] := TGtkSHXMLEdit.Create(XMLDoc);
-  Pages[2] := TGtkSHTextEdit.Create(PasDoc);
+  Pages[0] := CreatePasEditWidget (PasDoc);
+  Pages[1] := CreateXMLEditWidget (XMLDoc);
+  Pages[2] := CreateTextEditWidget(TxtDoc);
 
 
   // Create notebook
   // Create notebook
   Notebook := gtk_notebook_new;
   Notebook := gtk_notebook_new;
@@ -133,9 +104,14 @@ begin
   Pages[0].SetFocus;
   Pages[0].SetFocus;
   gtk_main;
   gtk_main;
 end.
 end.
+
+
 {
 {
   $Log$
   $Log$
-  Revision 1.6  1999-12-22 22:28:08  peter
+  Revision 1.7  1999-12-30 21:03:25  sg
+  * Major restructuring and simplifications
+
+  Revision 1.6  1999/12/22 22:28:08  peter
     * updates for cursor setting
     * updates for cursor setting
     * button press event works
     * button press event works