Usermode/axwin3 - Added WNDMSG_FIRE handler to richtext lib
[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 <wm_messages.h>
14 //#include <alloca.h>
15
16 // === TYPES ===
17 typedef struct sRichText_Window
18 {
19         tAxWin3_RichText_KeyHandler     KeyCallback;
20         tAxWin3_RichText_MouseHandler   MouseCallback;
21         tAxWin3_RichText_LineHandler    LineHandler;
22 } tRichText_Window;
23
24 // === CODE ===
25 int AxWin3_RichText_MessageHandler(tHWND Window, int MessageID, int Size, void *Data)
26 {
27         tRichText_Window        *info = AxWin3_int_GetDataPtr(Window);
28         struct sWndMsg_KeyAction        *keyaction = Data;
29         _SysDebug("MessageID = %i", MessageID);
30         switch(MessageID)
31         {
32         case WNDMSG_KEYFIRE:
33                 if(Size < sizeof(*keyaction))   return -1;
34                 info->KeyCallback(Window, 2, keyaction->KeySym, keyaction->UCS32);
35                 return 1;
36         }
37         return 0;
38 }
39
40 static void _SendAttrib(tHWND Window, int Attr, uint32_t Value)
41 {
42         struct sRichTextIPC_SetAttr     msg;
43         msg.Attr = Attr;
44         msg.Value = Value;
45         AxWin3_SendIPC(Window, IPC_RICHTEXT_SETATTR, sizeof(msg), &msg);
46 }
47
48 tHWND AxWin3_RichText_CreateWindow(tHWND Parent, int Flags)
49 {
50         tHWND ret = AxWin3_CreateWindow(Parent, "RichText", Flags, sizeof(tRichText_Window), AxWin3_RichText_MessageHandler);
51 //      tRichText_Window *info = AxWin3_int_GetDataPtr(ret);
52         return ret;
53 }
54
55 void AxWin3_RichText_SetKeyHandler(tHWND Window, tAxWin3_RichText_KeyHandler Handler)
56 {
57         tRichText_Window        *info = AxWin3_int_GetDataPtr(Window);
58         info->KeyCallback = Handler;
59 }
60
61 void AxWin3_RichText_SetMouseHandler(tHWND Window, tAxWin3_RichText_MouseHandler Handler)
62 {
63         tRichText_Window        *info = AxWin3_int_GetDataPtr(Window);
64         info->MouseCallback = Handler;
65 }
66
67 void AxWin3_RichText_EnableScroll(tHWND Window, int bEnable)
68 {
69         _SendAttrib(Window, _ATTR_SCROLL, bEnable);
70 }
71 void AxWin3_RichText_SetLineCount(tHWND Window, int Lines)
72 {
73         _SendAttrib(Window, _ATTR_LINECOUNT, Lines);
74 }
75 void AxWin3_RichText_SetColCount(tHWND Window, int Cols)
76 {
77         _SendAttrib(Window, _ATTR_COLCOUNT, Cols);
78 }
79 void AxWin3_RichText_SetBackground(tHWND Window, uint32_t ARGB_Colour)
80 {
81         _SendAttrib(Window, _ATTR_DEFBG, ARGB_Colour);
82 }
83 void AxWin3_RichText_SetDefaultColour(tHWND Window, uint32_t ARGB_Colour)
84 {
85         _SendAttrib(Window, _ATTR_DEFFG, ARGB_Colour);
86 }
87 void AxWin3_RichText_SetFont(tHWND Window, const char *FontName, int PointSize)
88 {
89         // TODO: Send message
90 }
91 void AxWin3_RichText_SetCursorType(tHWND Window, int Type)
92 {
93         _SendAttrib(Window, _ATTR_CURSOR, Type);
94 }
95 void AxWin3_RichText_SetCursorBlink(tHWND Window, int bBlink)
96 {
97         _SendAttrib(Window, _ATTR_CURSORBLINK, bBlink);
98 }
99 void AxWin3_RichText_SetCursorPos(tHWND Window, int Row, int Column)
100 {
101         if(Row < 0 || Row > 0xFFFFF || Column > 0xFFF || Column < 0)
102                 return ;
103         _SendAttrib(Window, _ATTR_CURSORPOS, ((Row & 0xFFFFF) << 12) | (Column & 0xFFF));
104 }
105
106 void AxWin3_RichText_SendLine(tHWND Window, int Line, const char *Text)
107 {
108         // TODO: Local sanity check on `Line`?
109         struct sRichTextIPC_WriteLine   *msg;
110         size_t  len = sizeof(*msg) + strlen(Text) + 1;
111         char    buffer[len];
112         msg = (void*)buffer;
113         msg->Line = Line;
114         strcpy(msg->LineData, Text);
115         AxWin3_SendIPC(Window, IPC_RICHTEXT_WRITELINE, len, msg);
116 }
117

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