Usermode/AxWin3 - resources and bugfixes
[tpg/acess2.git] / Usermode / Applications / axwin3_src / WM / renderers / richtext.c
index 28be1ae..8f69c9c 100644 (file)
@@ -43,6 +43,7 @@ typedef struct sRichText_Window
 // === PROTOTYPES ===
  int   Renderer_RichText_Init(void);
 tWindow        *Renderer_RichText_Create(int Flags);
+void   Renderer_RichText_Destroy(tWindow *Window);
 void   Renderer_RichText_Redraw(tWindow *Window);
  int   Renderer_RichText_HandleIPC_SetAttr(tWindow *Window, size_t Len, const void *Data);
  int   Renderer_RichText_HandleIPC_WriteLine(tWindow *Window, size_t Len, const void *Data);
@@ -52,6 +53,7 @@ void  Renderer_RichText_Redraw(tWindow *Window);
 tWMRenderer    gRenderer_RichText = {
        .Name = "RichText",
        .CreateWindow   = Renderer_RichText_Create,
+       .DestroyWindow  = Renderer_RichText_Destroy,
        .Redraw         = Renderer_RichText_Redraw,
        .HandleMessage  = Renderer_RichText_HandleMessage,
        .nIPCHandlers = N_IPC_RICHTEXT,
@@ -83,6 +85,23 @@ tWindow *Renderer_RichText_Create(int Flags)
        return ret;
 }
 
+void Renderer_RichText_Destroy(tWindow *Window)
+{
+       tRichText_Window        *info = Window->RendererInfo;
+
+       // TODO: Is locking needed? WM_Destroy should have taken us off the render tree
+       while( info->FirstLine )
+       {
+               tRichText_Line *line = info->FirstLine;
+               info->FirstLine = line->Next;
+
+               free(line);
+       }
+
+       if( info->Font )
+               _SysDebug("RichText_Destroy - TODO: Free font");
+}
+
 static inline int Renderer_RichText_RenderText_Act(tWindow *Window, tRichText_Window *info, int X, int Row, const char *Text, int Bytes, tColour FG, tColour BG, int Flags)
 {
         int    rwidth;
@@ -224,6 +243,27 @@ void Renderer_RichText_Redraw(tWindow *Window)
                Window->W, (info->DispLines-i)*info->LineHeight,
                info->DefaultBG
                );
+
+       // HACK!
+       info->DispCols = Window->W / 8; 
+
+       // TODO: Text cursor
+       _SysDebug("Cursor at %i,%i", info->CursorCol, info->CursorRow);
+       _SysDebug(" Range [%i+%i],[%i+%i]", info->FirstVisRow, info->DispLines, info->FirstVisCol, info->DispCols);
+       if( info->CursorRow >= info->FirstVisRow && info->CursorRow < info->FirstVisRow + info->DispLines )
+       {
+               if( info->CursorCol >= info->FirstVisCol && info->CursorCol < info->FirstVisCol + info->DispCols )
+               {
+                       // TODO: Kill hardcoded 8 with cached text distance
+                       WM_Render_FillRect(Window,
+                               (info->CursorCol - info->FirstVisCol) * 8,
+                               (info->CursorRow - info->FirstVisRow) * info->LineHeight,
+                               1,
+                               info->LineHeight,
+                               info->DefaultFG
+                               );
+               }
+       }
 }
 
 int Renderer_RichText_HandleIPC_SetAttr(tWindow *Window, size_t Len, const void *Data)
@@ -241,6 +281,10 @@ int Renderer_RichText_HandleIPC_SetAttr(tWindow *Window, size_t Len, const void
        case _ATTR_DEFFG:
                info->DefaultFG = msg->Value;
                break;
+       case _ATTR_CURSORPOS:
+               info->CursorRow = msg->Value >> 12;
+               info->CursorCol = msg->Value & 0xFFF;
+               break;
        case _ATTR_SCROLL:
                // TODO: Set scroll flag
                break;
@@ -298,7 +342,9 @@ int Renderer_RichText_HandleIPC_WriteLine(tWindow *Window, size_t Len, const voi
        }
        line->ByteLength = Len - sizeof(*msg);
        memcpy(line->Data, msg->LineData, Len - sizeof(*msg));
-       
+
+       WM_Invalidate( Window );
+
        return  0;
 }
 
@@ -312,6 +358,10 @@ int Renderer_RichText_HandleMessage(tWindow *Target, int Msg, int Len, const voi
                if(Len < sizeof(*msg))  return -1;
                info->DispLines = msg->H / info->LineHeight;
                return 1; }
+       case WNDMSG_KEYDOWN:
+       case WNDMSG_KEYUP:
+       case WNDMSG_KEYFIRE:
+               return 1;
        }
        return 0;
 }

UCC git Repository :: git.ucc.asn.au