Browse Source

* changes so redrawing and walking with the cursor finally works
correct

peter 26 years ago
parent
commit
6c4b0b264b
3 changed files with 88 additions and 72 deletions
  1. 6 1
      fcl/shedit/gtkdemo.pp
  2. 19 27
      fcl/shedit/gtkshedit.pp
  3. 63 44
      fcl/shedit/keys.inc

+ 6 - 1
fcl/shedit/gtkdemo.pp

@@ -130,11 +130,16 @@ begin
   gtk_container_add(PGtkContainer(MainWindow), Notebook);
   gtk_widget_show(Notebook);
   gtk_widget_show(MainWindow);
+  Pages[0].SetFocus;
   gtk_main;
 end.
 {
   $Log$
-  Revision 1.4  1999-11-15 21:47:36  peter
+  Revision 1.5  1999-12-08 01:03:15  peter
+    * changes so redrawing and walking with the cursor finally works
+      correct
+
+  Revision 1.4  1999/11/15 21:47:36  peter
     * first working keypress things
 
   Revision 1.3  1999/11/14 21:32:55  peter

+ 19 - 27
fcl/shedit/gtkshedit.pp

@@ -130,14 +130,14 @@ procedure TGtkSHEdit_Expose(GtkWidget: PGtkWidget; event: PGdkEventExpose; edit:
 var
   x1, y1, x2, y2: Integer;
 begin
-  x1 := event^.area.x div edit.CharW;
+  x1:=event^.area.x;
   if x1>0 then
-   dec(x1);
+   dec(x1,edit.LeftIndent);
+  x2:=x1+event^.area.width - 1;
+  x1:=x1 div edit.CharW;
+  x2:=(x2+edit.CharW-1) div edit.CharW;
   y1 := event^.area.y div edit.CharH;
-  if y1>0 then
-   dec(y1);
-  x2 := (event^.area.x + event^.area.width - 1) div edit.CharW+1;
-  y2 := (event^.area.y + event^.area.height - 1) div edit.CharH+1;
+  y2 := (event^.area.y + event^.area.height - 1) div edit.CharH;
   WriteLn(Format('Expose(%d/%d - %d/%d) for %s', [x1, y1, x2, y2, edit.ClassName]));
 
   edit.GdkWnd := edit.PaintBox^.window;
@@ -254,15 +254,15 @@ begin
 
   PGtkObject(PaintBox)^.flags := PGtkObject(PaintBox)^.flags or GTK_CAN_FOCUS;
 
-  gtk_signal_connect_after(PGtkObject(PaintBox), 'expose-event',
+  gtk_signal_connect(PGtkObject(PaintBox), 'expose-event',
     GTK_SIGNAL_FUNC(@TGtkSHEdit_Expose), self);
   gtk_signal_connect_after(PGtkObject(PaintBox), 'key-press-event',
     GTK_SIGNAL_FUNC(@TGtkSHEdit_KeyPressed), self);
-  gtk_signal_connect(PGtkObject(PaintBox), 'button-press-event',
+  gtk_signal_connect_after(PGtkObject(PaintBox), 'button-press-event',
     GTK_SIGNAL_FUNC(@TGtkSHEdit_KeyPressed), self);
-  gtk_signal_connect(PGtkObject(PaintBox), 'focus-in-event',
+  gtk_signal_connect_after(PGtkObject(PaintBox), 'focus-in-event',
     GTK_SIGNAL_FUNC(@TGtkSHEdit_FocusInEvent), self);
-  gtk_signal_connect(PGtkObject(PaintBox), 'focus-out-event',
+  gtk_signal_connect_after(PGtkObject(PaintBox), 'focus-out-event',
     GTK_SIGNAL_FUNC(@TGtkSHEdit_FocusOutEvent), self);
   gtk_widget_show(Widget);
 end;
@@ -348,11 +348,11 @@ var
 
   procedure doerase;
   begin
-    if rx2>rx1 then
+    if rx2>x1 then
      begin
        SetGCColor(CurColor);
        gdk_draw_rectangle(PGdkDrawable(GdkWnd), GC, 1,
-                          x1 * CharW + LeftIndent, y * CharH, (rx2 - rx1 + 1) * CharW, CharH);
+                          rx1 * CharW + LeftIndent, y * CharH, (rx2 - rx1 + 1) * CharW, CharH);
        rx1:=rx2;
      end;
   end;
@@ -363,7 +363,7 @@ var
   NewColor: LongWord;
   hs : pchar;
 begin
-  {WriteLn(Format('DrawTextLine(%d) for %s ', [y, ClassName]));}
+  // WriteLn(Format('DrawTextLine(%d) for %s ', [y, ClassName]));
 
   // Erase the (potentially multi-coloured) background
 
@@ -447,9 +447,6 @@ begin
         end;
     end;
   until false;
-{ Also draw the cursor }
-{  if y=edit.CursorY then
-   DrawCursor; }
 end;
 
 
@@ -462,19 +459,10 @@ end;
 procedure TGtkSHEdit.ShowCursor(x, y: Integer);
 var
   r : TGdkRectangle;
-  px,py : integer;
 begin
   writeln('Showcursor ',x,',',y);
-  px := x * CharW + LeftIndent;
-  py := y * CharH;
   SetGCColor(colBlack);
-  gdk_draw_rectangle(PGdkDrawable(GdkWnd), GC, 1, px, py, 2, CharH);
-
-{  r.x:=x * CharW;
-  r.y:=y * CharH;
-  r.Width:=CharW;
-  r.Height:=CharH;
-  gtk_widget_draw(PGtkWidget(PaintBox), @r); }
+  gdk_draw_rectangle(PGdkDrawable(GdkWnd), GC, 1, x*CharW + LeftIndent, y*CharH, 2, CharH);
 end;
 
 
@@ -519,7 +507,11 @@ end;
 end.
 {
   $Log$
-  Revision 1.3  1999-12-08 00:42:54  sg
+  Revision 1.4  1999-12-08 01:03:15  peter
+    * changes so redrawing and walking with the cursor finally works
+      correct
+
+  Revision 1.3  1999/12/08 00:42:54  sg
   * The cursor should be displayed correctly now
 
   Revision 1.2  1999/12/06 21:27:27  peter

+ 63 - 44
fcl/shedit/keys.inc

@@ -53,93 +53,108 @@ begin
 end;
 
 procedure TSHTextEdit.CursorUp;
-var
-  l1, l2: Integer;
 begin
   if FCursorY = 0 then
     FCursorX := 0
-  else begin
-    l1 := FDoc.LineLen[FCursorY];
+  else
     Dec(FCursorY);
-    l2 := FDoc.LineLen[FCursorY];
-    if FCursorX > l2 then
-      FCursorX := l2;
-  end;
+  if FCursorY<Renderer.VertPos then
+   Renderer.VertPos := Renderer.VertPos - 1;
 end;
 
+
 procedure TSHTextEdit.CursorDown;
-var
-  l1, l2: Integer;
 begin
-  if FCursorY < FDoc.LineCount - 1 then begin
-    l1 := FDoc.LineLen[FCursorY];
-    Inc(FCursorY);
-    l2 := FDoc.LineLen[FCursorY];
-    if FCursorX > l2 then
-      FCursorX := l2;
-  end else
-    FCursorX := FDoc.LineLen[FCursorY];
+  if FCursorY < FDoc.LineCount - 1 then
+   Inc(FCursorY)
+  else
+   FCursorX := FDoc.LineLen[FCursorY];
+  if FCursorY>Renderer.VertPos+Renderer.PageHeight then
+   Renderer.VertPos := Renderer.VertPos + 1;
 end;
 
+
 procedure TSHTextEdit.CursorLeft;
 begin
   if FCursorX > 0 then
     Dec(FCursorX)
-  else if FCursorY > 0 then begin
-    Dec(FCursorY);
-    FCursorX := FDoc.LineLen[FCursorY];
-  end;
-
+  else
+    if FCursorY > 0 then
+      begin
+        Dec(FCursorY);
+        FCursorX := FDoc.LineLen[FCursorY];
+        if FCursorY<Renderer.VertPos then
+         Renderer.VertPos := Renderer.VertPos - 1;
+      end;
 end;
 
+
 procedure TSHTextEdit.CursorRight;
 begin
   Inc(FCursorX);
   if FCursorX > FDoc.LineLen[FCursorY] then
-    if FCursorY < FDoc.LineCount - 1 then begin
-      Inc(FCursorY);
-      FCursorX := 0;
-    end else
-      FCursorX := FDoc.LineLen[FCursorY];
+    if FCursorY < FDoc.LineCount - 1 then
+     begin
+       Inc(FCursorY);
+       FCursorX := 0;
+       if FCursorY>Renderer.VertPos+Renderer.PageHeight then
+        Renderer.VertPos := Renderer.VertPos + 1;
+     end
+    else
+     FCursorX := FDoc.LineLen[FCursorY];
 end;
 
+
 procedure TSHTextEdit.CursorHome;
 begin
   FCursorX := 0;
 end;
 
+
 procedure TSHTextEdit.CursorEnd;
 begin
   FCursorX := FDoc.LineLen[FCursorY];
 end;
 
+
 procedure TSHTextEdit.CursorPageUp;
 begin
   if FCursorY = 0 then
     FCursorX := 0
-  else begin
-    Dec(FCursorY, Renderer.PageHeight);
-    if FCursorY < 0 then FCursorY := 0;
-    if FCursorX > FDoc.LineLen[FCursorY] then
-      FCursorX := FDoc.LineLen[FCursorY];
-  end;
-  Renderer.VertPos := Renderer.VertPos - Renderer.PageHeight;
+  else
+    begin
+      Dec(FCursorY, Renderer.PageHeight);
+      if FCursorY < 0 then
+       begin
+         FCursorY := 0;
+         Renderer.VertPos := 0;
+       end
+      else
+       Renderer.VertPos := Renderer.VertPos - Renderer.PageHeight;
+    end;
 end;
 
+
 procedure TSHTextEdit.CursorPageDown;
 begin
   if FCursorY = FDoc.LineCount - 1 then
     FCursorX := FDoc.LineLen[FCursorY]
-  else begin
-    Inc(FCursorY, Renderer.PageHeight);
-    if FCursorY >= FDoc.LineCount then
-      FCursorY := FDoc.LineCount - 1;
-    if FCursorX > FDoc.LineLen[FCursorY] then
-      FCursorX := FDoc.LineLen[FCursorY];
-  end;
-  Renderer.VertPos := Renderer.VertPos + Renderer.PageHeight;
+  else
+    begin
+      Inc(FCursorY, Renderer.PageHeight);
+      if FCursorY >= FDoc.LineCount then
+       begin
+         FCursorY := FDoc.LineCount - Renderer.PageHeight;
+         if FCursorY < 0 then
+          FCursorY:=0;
+         Renderer.VertPos := FCursorY;
+       end
+      else
+       Renderer.VertPos := Renderer.VertPos + Renderer.PageHeight;
+    end;
 end;
 
+
 procedure TSHTextEdit.EditDelLeft;
 var
   s: String;
@@ -569,7 +584,11 @@ end;
 
 {
   $Log$
-  Revision 1.2  1999-11-15 21:47:36  peter
+  Revision 1.3  1999-12-08 01:03:15  peter
+    * changes so redrawing and walking with the cursor finally works
+      correct
+
+  Revision 1.2  1999/11/15 21:47:36  peter
     * first working keypress things
 
   Revision 1.1  1999/10/29 15:59:04  peter