[TextEditor-mcc] Re: Cursor Y position chained with vertical scroll?

  • From: "Gianfranco \"ShInKurO\" Gignina" <sh1nkur0@xxxxxxxxx>
  • To: texteditor_mcc@xxxxxxxxxxxxx
  • Date: Sat, 04 Jul 2009 13:31:00 +0200

Il 30-Giu-2009, Gianfranco "ShInKurO" Gignina scrisse:

> Il 24-Giu-2009, Gianfranco "ShInKurO" Gignina scrisse:
>
>> What do you think? 
>
> After to have tried many solution the only praticable way is to add a
> new attribute which if setted to TRUE does this work. 
> My problem is that my current implementation has problems when a line
> is very long and it's automatically wrapped, in this case the visual y
> is at the end of the line, while I would cursor to be positioned at the
> first visible line into TE obj... but I haven't understand how I can
> calculate value which correspond to first visible line...
>
> help please :)

I've better incapsulated code so it doesn't give any problems if it is not
activated. 
For now it works for scroll down, I can implement it for scoll up, but my
problem is always to understand what is the first dispayed line, in fact
visualy is only the first coordinate given by scroller, which isn't the
first visualized line in case of wrapped line. A line wrapped is lucky
known by an its attribute "visual", which tell us how many visualized lines
correspond to a line.

I don't understand how I can know if :

- a line is currently visualized (in this way I could navigate through lines
until I find first hide line and then to know what is the first visualized
line)

- what is the first visualized line;

Please help me :)

-- 
Bye, 
Gianfranco "ShInKurO" Gignina

http://shinkuro.amiga.it
Index: mcc/private.h
===================================================================
--- mcc/private.h       (revision 521)
+++ mcc/private.h       (working copy)
@@ -291,6 +291,7 @@
   LONG    totallines;         // Total number of lines
   LONG    maxlines;         // max visual lines in gadget
   ULONG   flags;
+  BOOL    cursorFollowsSlider; //cursor follows slider movements?
 
   UWORD   cursor_shown;       // Width of stored cursor
   Object  *object;          // Pointer to the object itself
@@ -312,6 +313,8 @@
   BOOL    shown;
   BOOL    update;
 
+  LONG    diffLine; //how many visualized lines are contained into actualLine?
+
   struct  IFFHandle *iff;
 
   ULONG   StartSecs, StartMicros;
Index: mcc/Navigation.c
===================================================================
--- mcc/Navigation.c    (revision 521)
+++ mcc/Navigation.c    (working copy)
@@ -49,7 +49,7 @@
   return(flowspace);
 }
 
-static ULONG CursorOffset(struct InstData *data)
+ULONG CursorOffset(struct InstData *data)
 {
   struct line_node *line = data->actualline;
   STRPTR text = line->line.Contents+data->CPos_X;
Index: mcc/GetSetAttrs.c
===================================================================
--- mcc/GetSetAttrs.c   (revision 521)
+++ mcc/GetSetAttrs.c   (working copy)
@@ -284,6 +284,10 @@
           crsr_y = ti_Data;
         break;
 
+      case MUIA_TextEditor_CursorFollowsSlider:
+        data->cursorFollowsSlider = ti_Data;
+      break;
+
       case MUIA_TextEditor_Prop_Release:
         data->smooth_wait = ti_Data;
       break;
@@ -297,7 +301,7 @@
           struct   Hook  *oldhook;
           void    *cliphandle;
 
-          diff = data->visual_y - ((ti_Data/data->height)+1);
+          diff = data->visual_y - ((ti_Data/data->height)+1);  //why is this 
calculated? it's not used...
 
           data->visual_y = (ti_Data/data->height)+1;
           smooth = ti_Data - lastpixel;
@@ -335,6 +339,40 @@
             }
 
             DumpText(data->visual_y+line_nr, line_nr, data->maxlines+1, FALSE, 
data);
+
+            if (data->cursorFollowsSlider)
+            {
+//D(DBF_STARTUP, "1, line_nr=%ld, visual_y=%ld, diffLine=%ld",line_nr, 
data->visual_y, data->diffLine);
+              SetCursor(data->CPos_X, data->actualline, FALSE, data);
+
+              if (data->diffLine<=1)
+                data->actualline = LineNode(data->visual_y-1, data);
+
+              if (data->diffLine<=1)
+                data->diffLine = data->actualline->visual;
+
+//D(DBF_STARTUP, "1-2 diffLine=%ld", data->diffLine);
+
+              if (data->diffLine <= 1)
+                data->diffLine = 0;
+
+
+              if (data->diffLine>0)
+              {
+                struct pos_info pos;
+
+                OffsetToLines(data->CPos_X, data->actualline, &pos, data);
+                data->CPos_X  = pos.extra;
+                data->CPos_X += CursorOffset(data);
+              }
+              else
+                GoDown(data);
+
+              SetCursor(data->CPos_X, data->actualline, TRUE, data);
+
+
+              data->diffLine--;
+            }
           }
           else
           {
Index: include/mui/TextEditor_mcc.h
===================================================================
--- include/mui/TextEditor_mcc.h        (revision 521)
+++ include/mui/TextEditor_mcc.h        (working copy)
@@ -100,6 +100,7 @@
 #define MUIA_TextEditor_UndoLevels            (TextEditor_Dummy + 0x38)
 #define MUIA_TextEditor_WrapMode              (TextEditor_Dummy + 0x39)
 #define MUIA_TextEditor_ActiveObjectOnClick   (TextEditor_Dummy + 0x3a)
+#define MUIA_TextEditor_CursorFollowsSlider   (TextEditor_Dummy + 0x3b)
 
 #define MUIM_TextEditor_AddKeyBindings        (TextEditor_Dummy + 0x22)
 #define MUIM_TextEditor_ARexxCmd              (TextEditor_Dummy + 0x23)
Index: doc/MCC_TextEditor.doc
===================================================================
--- doc/MCC_TextEditor.doc      (revision 521)
+++ doc/MCC_TextEditor.doc      (working copy)
@@ -32,6 +32,7 @@
 TextEditor.mcc/MUIA_TextEditor_Rows
 TextEditor.mcc/MUIA_TextEditor_Separator
 TextEditor.mcc/MUIA_TextEditor_Slider
+TextEditor.mcc/MUIA_TextEditor_CursorFollowsSlider
 TextEditor.mcc/MUIA_TextEditor_StyleBold
 TextEditor.mcc/MUIA_TextEditor_StyleItalic
 TextEditor.mcc/MUIA_TextEditor_StyleUnderline
@@ -827,6 +828,25 @@
         MUIA_TextEditor_Prop_DeltaFactor, MUIA_TextEditor_Prop_Entries
         MUIA_TextEditor_Prop_First, MUIA_TextEditor_Prop_Visible
 
+TextEditor.mcc/MUIA_TextEditor_CursorFollowsSlider
+
+    NAME
+        MUIA_TextEditor_CursorFollowsSlider -- [IS.], BOOL (v15.29)
+
+    FUNCTION
+        When value of this tag is TRUE cursor will follow slider movements 
+        instead to stay in its current position. Useful when there are
+        many TextEditor objects into a group setted with MUIA_Group_PageMode.
+        In this case when user will return into a TextEditor object this will
+        be in the same scrolled position user had left it before to select
+        another TextEditor into that group.
+        Default is FALSE.
+
+    EXAMPLE
+
+    SEE ALSO
+        
+
 TextEditor.mcc/MUIA_TextEditor_StyleBold
 
     NAME

Other related posts: