AxWin3 - Heaps of bugfixes to RichText renderer
[tpg/acess2.git] / Usermode / Applications / axwin3_src / libaxwin3.so_src / r_richtext.c
1 /*
2  * AxWin3 Interface Library
3  * - By John Hodge (thePowersGang)
4  *
5  * r_richtext.c
6  * - Formatted Text window type
7  */
8 #include <axwin3/axwin.h>
9 #include <axwin3/richtext.h>
10 #include "include/internal.h"
11 #include <richtext_messages.h>
12 #include <string.h>
13 //#include <alloca.h>
14
15 // === TYPES ===
16 typedef struct sRichText_Window
17 {
18         tAxWin3_RichText_KeyHandler     KeyCallback;
19         tAxWin3_RichText_MouseHandler   MouseCallback;
20         tAxWin3_RichText_LineHandler    LineHandler;
21 } tRichText_Window;
22
23 // === CODE ===
24 int AxWin3_RichText_MessageHandler(tHWND Window, int MessageID, int Size, void *Data)
25 {
26         return 0;
27 }
28
29 static void _SendAttrib(tHWND Window, int Attr, uint32_t Value)
30 {
31         struct sRichTextMsg_SetAttr     msg;
32         msg.Attr = Attr;
33         msg.Value = Value;
34         AxWin3_SendMessage(Window, Window, MSG_RICHTEXT_SETATTR, sizeof(msg), &msg);
35 }
36
37 tHWND AxWin3_RichText_CreateWindow(tHWND Parent, int Flags)
38 {
39         tHWND ret = AxWin3_CreateWindow(Parent, "RichText", Flags, sizeof(tRichText_Window), AxWin3_RichText_MessageHandler);
40 //      tRichText_Window *info = AxWin3_int_GetDataPtr(ret);
41         return ret;
42 }
43
44 void AxWin3_RichText_SetKeyHandler(tHWND Window, tAxWin3_RichText_KeyHandler Handler)
45 {
46         tRichText_Window        *info = AxWin3_int_GetDataPtr(Window);
47         info->KeyCallback = Handler;
48 }
49
50 void AxWin3_RichText_SetMouseHandler(tHWND Window, tAxWin3_RichText_MouseHandler Handler)
51 {
52         tRichText_Window        *info = AxWin3_int_GetDataPtr(Window);
53         info->MouseCallback = Handler;
54 }
55
56 void AxWin3_RichText_EnableScroll(tHWND Window, int bEnable)
57 {
58         _SendAttrib(Window, _ATTR_SCROLL, bEnable);
59 }
60 void AxWin3_RichText_SetLineCount(tHWND Window, int Lines)
61 {
62         _SendAttrib(Window, _ATTR_LINECOUNT, Lines);
63 }
64 void AxWin3_RichText_SetColCount(tHWND Window, int Cols)
65 {
66         _SendAttrib(Window, _ATTR_COLCOUNT, Cols);
67 }
68 void AxWin3_RichText_SetBackground(tHWND Window, uint32_t ARGB_Colour)
69 {
70         _SendAttrib(Window, _ATTR_DEFBG, ARGB_Colour);
71 }
72 void AxWin3_RichText_SetDefaultColour(tHWND Window, uint32_t ARGB_Colour)
73 {
74         _SendAttrib(Window, _ATTR_DEFFG, ARGB_Colour);
75 }
76 void AxWin3_RichText_SetFont(tHWND Window, const char *FontName, int PointSize)
77 {
78         // TODO: Send message
79 }
80 void AxWin3_RichText_SetCursorType(tHWND Window, int Type)
81 {
82         _SendAttrib(Window, _ATTR_CURSOR, Type);
83 }
84 void AxWin3_RichText_SetCursorBlink(tHWND Window, int bBlink)
85 {
86         _SendAttrib(Window, _ATTR_CURSORBLINK, bBlink);
87 }
88 void AxWin3_RichText_SetCursorPos(tHWND Window, int Row, int Column)
89 {
90         if(Row < 0 || Row > 0xFFFFF || Column > 0xFFF || Column < 0)
91                 return ;
92         _SendAttrib(Window, _ATTR_CURSORPOS, ((Row & 0xFFFFF) << 12) | (Column & 0xFFF));
93 }
94
95 void AxWin3_RichText_SendLine(tHWND Window, int Line, const char *Text)
96 {
97         // TODO: Local sanity check on `Line`?
98         struct sRichTextMsg_SendLine    *msg;
99         size_t  len = sizeof(*msg) + strlen(Text) + 1;
100         char    buffer[len];
101         msg = (void*)buffer;
102         msg->Line = Line;
103         strcpy(msg->LineData, Text);
104         AxWin3_SendMessage(Window, Window, MSG_RICHTEXT_SENDLINE, len, msg);
105 }
106

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