[TextEditor-mcc] Re: How can take not marked blocks (useful for sintax highlight)

  • From: "Gianfranco \"ShInKurO\" Gignina" <sh1nkur0@xxxxxxxxx>
  • To: texteditor_mcc@xxxxxxxxxxxxx
  • Date: Wed, 04 Mar 2009 09:40:33 +0100

Il 26-Feb-2009, Gianfranco "ShInKurO" Gignina scrisse:

> Hi,
>
> is there any way to insert some coordinates (for example startx,
> starty, stopx, stopy) and retrieve than block of text without mark it?
>
> I would want implement sintax highlight on NoWinED, but without to
> retrieve a block without to mark it the only way could be to get
> content of texteditor, to read last word, and if should be coloured,
> mark it on texteditor and coloured it... I find this few good...
>
> Suggestions?

Nevermind, I've just implemented it into TE sources:

basically I've addd some attributes to struct MUIP_TextEditor_ExportBlock
which are considered only if flag is MUIF_TextEditor_ExportBlock_TakeBlock,
so in this case you can take a block without to select it, only specifing
coordinates.

I've even added MUIM_TextEditor_SetBlock, which is useful to change a block
of text without to select it, always specifing coordinates. For now are
supported changing of colour block and style of block...

Here diff file...


I want work to \t character, but even if I've a working and good version of
a function to use instead of plain Text() in any case all cursor movements
trash spaces drawn with this function, so I would want informations about
how could change functions which draw cursor and refresh a line, I've jst
tried to modify SetCursor() etc... but without any good result...



-- 
Bye, 
Gianfranco "ShInKurO" Gignina

http://shinkuro.amiga.it
Index: trunk/mcc/HandleInput.c
===================================================================
--- trunk/mcc/HandleInput.c     (revision 496)
+++ trunk/mcc/HandleInput.c     (working copy)
@@ -238,7 +238,7 @@
 
             if(visible > 0)
             {
-                       struct IntuiWheelData *iwd = (struct IntuiWheelData 
*)imsg->IAddress;
+              struct IntuiWheelData *iwd = (struct IntuiWheelData 
*)imsg->IAddress;
 
               // we scroll about 1/6 of the displayed text by default
               LONG delta = (visible + 3) / 6;
@@ -249,9 +249,9 @@
 
               D(DBF_INPUT, "WheelX: %ld WheelY: %ld", iwd->WheelX, 
iwd->WheelY);
 
-                       if(iwd->WheelY < 0 || iwd->WheelX < 0)
+              if(iwd->WheelY < 0 || iwd->WheelX < 0)
                 DoMethod(data->slider, MUIM_Prop_Decrease, delta * 
abs(MIN(iwd->WheelX, iwd->WheelY)));
-                   else if(iwd->WheelY > 0 || iwd->WheelX > 0)
+              else if(iwd->WheelY > 0 || iwd->WheelX > 0)
                 DoMethod(data->slider, MUIM_Prop_Increase, delta * 
abs(MAX(iwd->WheelX, iwd->WheelY)));
             }
 
Index: trunk/mcc/private.h
===================================================================
--- trunk/mcc/private.h (revision 496)
+++ trunk/mcc/private.h (working copy)
@@ -126,9 +126,9 @@
 #endif
 
 // some own usefull MUI-style macros to check mouse positions in objects
-#define _between(a,x,b)                                        ((x)>=(a) && 
(x)<=(b))
-#define _isinobject(o,x,y)                             
(_between(_mleft(o),(x),_mright (o)) && _between(_mtop(o) ,(y),_mbottom(o)))
-#define _isinwholeobject(o,x,y)        (_between(_left(o),(x),_right (o)) && 
_between(_top(o) ,(y),_bottom(o)))
+#define _between(a,x,b)           ((x)>=(a) && (x)<=(b))
+#define _isinobject(o,x,y)        (_between(_mleft(o),(x),_mright (o)) && 
_between(_mtop(o) ,(y),_mbottom(o)))
+#define _isinwholeobject(o,x,y)   (_between(_left(o),(x),_right (o)) && 
_between(_top(o) ,(y),_bottom(o)))
 
 // own common macros
 #define Enabled(data)   ((data)->blockinfo.enabled && \
@@ -193,7 +193,7 @@
   struct line_node *next;     // Pointer to next line
   struct line_node *previous; // Pointer to previous line
 
-       struct LineNode line;
+  struct LineNode line;
 
   UWORD visual;               // How many lines are this line wrapped over
   UWORD flags;                // Different flags...
@@ -479,6 +479,8 @@
 void *ExportText(struct MUIP_TextEditor_ExportText *msg, struct InstData 
*data);
 void *ExportBlock(struct MUIP_TextEditor_ExportBlock *msg, struct InstData 
*data);
 
+ULONG OM_SetBlock(struct MUIP_TextEditor_SetBlock *msg, struct InstData *data);
+
 struct  line_node *loadtext (void);
 unsigned short  *CheckStyles      (char *);
 
Index: trunk/mcc/ImportText.c
===================================================================
--- trunk/mcc/ImportText.c      (revision 496)
+++ trunk/mcc/ImportText.c      (working copy)
@@ -32,84 +32,85 @@
 ***********************************************************************/
 struct line_node *ImportText(char *contents, struct InstData *data, struct 
Hook *importHook, LONG wraplength)
 {
-       struct line_node *first_line, *line;
-       struct ImportMessage im;
+  struct line_node *first_line, *line;
+  struct ImportMessage im;
 
-       ENTER();
+  ENTER();
 
-       im.Data = contents;
-       im.ImportWrap = wraplength;
-       im.PoolHandle = data->mypool;
+  im.Data = contents;
+  im.ImportWrap = wraplength;
+  im.PoolHandle = data->mypool;
 
-       line = AllocLine(data);
-       if(!line)
-       {
-               RETURN(NULL);
-               return NULL;
-       }
+  line = AllocLine(data);
+  if(!line)
+  {
+    RETURN(NULL);
+    return NULL;
+  }
 
-       memset(line,0,sizeof(*line));
-       first_line = line;
+  memset(line,0,sizeof(*line));
+  first_line = line;
 
-       while (1)
-       {
-               struct line_node *new_line;
+  while (1)
+  {
+    struct line_node *new_line;
 
-               im.linenode = &line->line;
+    im.linenode = &line->line;
 
-               /* invoke the hook, it will return NULL in case it is finished 
or
-                * an error occured */
-               im.Data = (char*)CallHookPkt(importHook, NULL, &im);
+    /* invoke the hook, it will return NULL in case it is finished or
+     * an error occured */
+    im.Data = (char*)CallHookPkt(importHook, NULL, &im);
 
-               if (!im.Data)
-               {
-                       if (!line->line.Contents)
-                       {
-                               /* Free the line node if it didn't contain any 
contents */
-                               if (line->previous)
-                               {
-                                       line->previous->next = NULL;
+    if (!im.Data)
+    {
+      if (!line->line.Contents)
+      {
+        /* Free the line node if it didn't contain any contents */
+        if (line->previous)
+        {
+          line->previous->next = NULL;
 
-                                       FreeLine(line, data);
-                               }
-                               else
-                               {
-                                       char *ctext;
+          FreeLine(line, data);
+        }
+        else
+        {
+          char *ctext;
 
-                                       // if the line has nor predecessor it 
was obviously the first line
-                                       // so we prepare a "fake" line_node to 
let the textEditor clear our
-                                       // text
-                                       if((ctext = MyAllocPooled(data->mypool, 
2)))
-                                       {
-                                               ctext[0] = '\n';
-                                               ctext[1] = '\0';
-                                               line->line.Contents = ctext;
-                                               line->line.Length        = 1;
-                                       } else
-                                       {
-                                               FreeLine(first_line, data);
-                                               first_line = NULL;
-                                       }
-                               }
-                       }
-                       break;
-               }
+          // if the line has nor predecessor it was obviously the first line
+          // so we prepare a "fake" line_node to let the textEditor clear our
+          // text
+          if((ctext = MyAllocPooled(data->mypool, 2)))
+          {
+            ctext[0] = '\n';
+            ctext[1] = '\0';
+            line->line.Contents = ctext;
+            line->line.Length  = 1;
+          } else
+          {
+            FreeLine(first_line, data);
+            first_line = NULL;
+          }
+        }
+      }
+      break;
+    }
 
-               if(!(new_line = AllocLine(data)))
-                       break;
+    if(!(new_line = AllocLine(data)))
+      break;
 
-               memset(new_line,0,sizeof(*new_line));
+    memset(new_line,0,sizeof(*new_line));
 
-               // Inherit the flow from the previous line, but only if
-               // the clearFlow variable is not set
-               if(line->line.clearFlow == FALSE)
-                       new_line->line.Flow = line->line.Flow;
+    // Inherit the flow from the previous line, but only if
+    // the clearFlow variable is not set
+    if(line->line.clearFlow == FALSE)
+      new_line->line.Flow = line->line.Flow;
 
-               new_line->previous = line;
-               line->next = new_line;
-               line = new_line;
-       }
+    new_line->previous = line;
+    line->next = new_line;
+    line = new_line;
 
-       RETURN(first_line);
-       return first_line;
+  }
+
+  RETURN(first_line);
+  return first_line;
 }
Index: trunk/mcc/Dispatcher.c
===================================================================
--- trunk/mcc/Dispatcher.c      (revision 496)
+++ trunk/mcc/Dispatcher.c      (working copy)
@@ -318,15 +318,15 @@
 ULONG AskMinMax(struct IClass *cl, Object *obj, struct MUIP_AskMinMax *msg)
 {
   struct InstData *data = INST_DATA(cl, obj);
-       struct MUI_MinMax *mi;
+  struct MUI_MinMax *mi;
   ULONG fontheight;
 
   ENTER();
 
-       // call the supermethod first
-       DoSuperMethodA(cl, obj, (Msg)msg);
+  // call the supermethod first
+  DoSuperMethodA(cl, obj, (Msg)msg);
 
-       mi = ((struct MUIP_AskMinMax *)msg)->MinMaxInfo;
+  mi = ((struct MUIP_AskMinMax *)msg)->MinMaxInfo;
 
   if(data->Columns)
   {
@@ -573,6 +573,7 @@
       case MUIM_TextEditor_ToggleCursor:
       case MUIM_TextEditor_MarkText:
       case MUIM_TextEditor_ClearText:
+      case MUIM_TextEditor_SetBlock:
       case MUIM_HandleEvent:
       case MUIM_GoInactive:
       case MUIM_GoActive:
@@ -717,7 +718,7 @@
       struct MUIP_TextEditor_InsertText *ins_msg = (struct 
MUIP_TextEditor_InsertText *)msg;
       struct marking block;
 
-         switch(ins_msg->pos)
+      switch(ins_msg->pos)
       {
         case MUIV_TextEditor_InsertText_Top:
         {
@@ -741,7 +742,7 @@
     }
     break;
 
-    case MUIM_TextEditor_ExportBlock: result = (ULONG)ExportBlock((struct 
MUIP_TextEditor_ExportBlock *)msg, data); RETURN(result); return(result); break;
+    case MUIM_TextEditor_ExportBlock:      result = (ULONG)ExportBlock((struct 
MUIP_TextEditor_ExportBlock *)msg, data); RETURN(result); return(result); break;
     case MUIM_TextEditor_ExportText:  result = (ULONG)ExportText((struct 
MUIP_TextEditor_ExportText *)msg, data); RETURN(result); return(result); break;
     case MUIM_TextEditor_ARexxCmd:    result = HandleARexx(data, ((struct 
MUIP_TextEditor_ARexxCmd *)msg)->command); break;
     case MUIM_TextEditor_MarkText:    result = OM_MarkText((struct 
MUIP_TextEditor_MarkText *)msg, data); break;
@@ -749,6 +750,7 @@
     case MUIM_TextEditor_Search:      result = OM_Search((struct 
MUIP_TextEditor_Search *)msg, data); break;
     case MUIM_TextEditor_Replace:     result = OM_Replace(obj, (struct 
MUIP_TextEditor_Replace *)msg, data); break;
     case MUIM_TextEditor_QueryKeyAction: result = OM_QueryKeyAction(cl, obj, 
(struct MUIP_TextEditor_QueryKeyAction *)msg); break;
+    case MUIM_TextEditor_SetBlock:      result = OM_SetBlock((struct 
MUIP_TextEditor_SetBlock *)msg, data); RETURN(result); return(result); break;
 
     case MUIM_Export:
     {
Index: trunk/mcc/ImportHook.c
===================================================================
--- trunk/mcc/ImportHook.c      (revision 496)
+++ trunk/mcc/ImportHook.c      (working copy)
@@ -493,7 +493,7 @@
 
         lastWasSeparator = TRUE;
 
-        continue;       
+        continue;
       }
       else if(c == '/')
       {
Index: trunk/mcc/Makefile
===================================================================
--- trunk/mcc/Makefile  (revision 496)
+++ trunk/mcc/Makefile  (working copy)
@@ -230,6 +230,7 @@
           $(OBJDIR)/EditorStuff.o \
           $(OBJDIR)/ExportHook.o \
           $(OBJDIR)/ExportBlock.o \
+          $(OBJDIR)/SetBlock.o \
           $(OBJDIR)/ExportText.o \
           $(OBJDIR)/GetSetAttrs.o \
           $(OBJDIR)/HandleARexx.o \
@@ -260,6 +261,7 @@
           $(OBJDIR)/EditorStuff.o \
           $(OBJDIR)/ExportHook.o \
           $(OBJDIR)/ExportBlock.o \
+          $(OBJDIR)/SetBlock.o \
           $(OBJDIR)/ExportText.o \
           $(OBJDIR)/GetSetAttrs.o \
           $(OBJDIR)/HandleARexx.o \
Index: trunk/mcc/Navigation.c
===================================================================
--- trunk/mcc/Navigation.c      (revision 496)
+++ trunk/mcc/Navigation.c      (working copy)
@@ -20,6 +20,7 @@
 
 ***************************************************************************/
 
+#include <string.h>
 #include <clib/alib_protos.h>
 #include <proto/graphics.h>
 #include <proto/intuition.h>
@@ -63,10 +64,9 @@
   {
     struct TextExtent tExtend;
     LONG offset = data->pixel_x-FlowSpace(line->line.Flow, text, data);
-
     if(offset < 1)
       offset = 1;
-
+    
     res = TextFit(&data->tmprp, text, lineCharsWidth, &tExtend, NULL, 1, 
offset, data->font->tf_YSize);
 
     // in case of a hard-wrapped line we have to deal with
@@ -96,7 +96,7 @@
   ENTER();
 
   pos = TextLength(&data->tmprp, data->actualline->line.Contents+bytes, x);
-
+  
   if(*(data->actualline->line.Contents+data->CPos_X) == '\n')
     pos += TextLength(&data->tmprp, " ", 1)/2;
   else
Index: trunk/mcc/BlockOperators.c
===================================================================
--- trunk/mcc/BlockOperators.c  (revision 496)
+++ trunk/mcc/BlockOperators.c  (working copy)
@@ -78,7 +78,7 @@
   data->actualline = startline;
 
   // clear the export message
-       memset(&emsg, 0, sizeof(struct ExportMessage));
+  memset(&emsg, 0, sizeof(struct ExportMessage));
 
   // fill it afterwards
   emsg.UserData = NULL;
Index: trunk/mcc/ExportBlock.c
===================================================================
--- trunk/mcc/ExportBlock.c     (revision 496)
+++ trunk/mcc/ExportBlock.c     (working copy)
@@ -31,12 +31,12 @@
   struct line_node *node;
   struct Hook *exportHook = data->ExportHook;
   ULONG wraplen = data->ExportWrap;
-       struct ExportMessage emsg;
+    struct ExportMessage emsg;
   struct marking newblock;
   ULONG flags = msg->flags;
-       void *user_data = NULL;
+    void *user_data = NULL;
 
-       ENTER();
+    ENTER();
 
   // get information about marked text
   if(data->blockinfo.enabled)
@@ -49,15 +49,32 @@
     newblock.stopx     = data->CPos_X;
   }
 
+  if(flags & MUIF_TextEditor_ExportBlock_TakeBlock)
+  {
+
+    if (msg->starty <= (ULONG)data->totallines)
+        newblock.startline = LineNode(msg->starty+1, data);
+
+    if (msg->startx <= (newblock.startline)->line.Length)
+        newblock.startx = msg->startx;
+
+    if (msg->stopx <= (newblock.startline)->line.Length)
+        newblock.stopx = msg->stopx;
+
+    if (msg->starty <= (ULONG)data->totallines)
+        newblock.stopline = LineNode(msg->stopy+1, data);
+  }
+
   node = newblock.startline;
 
+
   // clear the export message
-       memset(&emsg, 0, sizeof(struct ExportMessage));
+    memset(&emsg, 0, sizeof(struct ExportMessage));
 
   // now we export all selected/marked lines with
   // the currently active export hook
-       while(node)
-       {
+  while(node)
+  {
     struct line_node *next_node = node->next;
 
     emsg.UserData = user_data;
@@ -90,6 +107,7 @@
       else
         emsg.SkipBack = 0;
     }
+    
 
     // call the ExportHook and exit immediately if it returns NULL
     if((user_data = (void*)CallHookPkt(exportHook, NULL, &emsg)) == NULL)
@@ -103,6 +121,6 @@
     node = next_node;
   }
 
-       RETURN(user_data);
-       return user_data;
+    RETURN(user_data);
+    return user_data;
 }
Index: trunk/include/mui/TextEditor_mcc.h
===================================================================
--- trunk/include/mui/TextEditor_mcc.h  (revision 496)
+++ trunk/include/mui/TextEditor_mcc.h  (working copy)
@@ -102,11 +102,12 @@
 #define MUIM_TextEditor_Search                (TextEditor_Dummy + 0x2b)
 #define MUIM_TextEditor_MarkText              (TextEditor_Dummy + 0x2c)
 #define MUIM_TextEditor_QueryKeyAction        (TextEditor_Dummy + 0x2d)
+#define MUIM_TextEditor_SetBlock              (TextEditor_Dummy + 0x2e)
 
 struct MUIP_TextEditor_ARexxCmd          { ULONG MethodID; STRPTR command; };
 struct MUIP_TextEditor_BlockInfo         { ULONG MethodID; ULONG *startx; 
ULONG *starty; ULONG *stopx; ULONG *stopy; };
 struct MUIP_TextEditor_ClearText         { ULONG MethodID; };
-struct MUIP_TextEditor_ExportBlock       { ULONG MethodID; ULONG flags; };
+struct MUIP_TextEditor_ExportBlock       { ULONG MethodID; ULONG flags; ULONG 
startx; ULONG starty; ULONG stopx; ULONG stopy;};
 struct MUIP_TextEditor_ExportText        { ULONG MethodID; };
 struct MUIP_TextEditor_HandleError       { ULONG MethodID; ULONG errorcode; }; 
/* See below for error codes */
 struct MUIP_TextEditor_InsertText        { ULONG MethodID; STRPTR text; LONG 
pos; }; /* See below for positions */
@@ -114,6 +115,7 @@
 struct MUIP_TextEditor_Search            { ULONG MethodID; STRPTR 
SearchString; ULONG Flags; };
 struct MUIP_TextEditor_MarkText          { ULONG MethodID; ULONG start_crsr_x; 
ULONG start_crsr_y; ULONG stop_crsr_x; ULONG stop_crsr_y; };
 struct MUIP_TextEditor_QueryKeyAction    { ULONG MethodID; ULONG keyAction; };
+struct MUIP_TextEditor_SetBlock          { ULONG MethodID; ULONG startx; ULONG 
starty; ULONG stopx; ULONG stopy; ULONG operation; ULONG flag;};
 
 #define MUIV_TextEditor_ExportHook_Plain       0x00000000
 #define MUIV_TextEditor_ExportHook_EMail       0x00000001
@@ -151,7 +153,14 @@
 
 /* Flags for MUIM_TextEditor_ExportBlock */
 #define MUIF_TextEditor_ExportBlock_FullLines  (1 << 0)
+#define MUIF_TextEditor_ExportBlock_TakeBlock  (1 << 1)
 
+/* Flags for MUIM_TextEditor_SetBlock */
+#define MUIF_TextEditor_SetBlock_Color           (1 << 0)
+#define MUIF_TextEditor_SetBlock_StyleBold       (1 << 1)
+#define MUIF_TextEditor_SetBlock_StyleItalic     (1 << 2)
+#define MUIF_TextEditor_SetBlock_StyleUnderline  (1 << 3)
+
 /* Error codes given as argument to MUIM_TextEditor_HandleError */
 #define Error_ClipboardIsEmpty         0x01
 #define Error_ClipboardIsNotFTXT       0x02

Other related posts: