Usermode/AxWin4 - Clean up logging
[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         switch(MessageID)
30         {
31         case WNDMSG_KEYFIRE:
32                 if(Size < sizeof(*keyaction))   return -1;
33                 info->KeyCallback(Window, 2, keyaction->KeySym, keyaction->UCS32);
34                 return 1;
35         case WNDMSG_KEYDOWN:
36                 if(Size < sizeof(*keyaction))   return -1;
37                 info->KeyCallback(Window, 1, keyaction->KeySym, keyaction->UCS32);
38                 return 1;
39         case WNDMSG_KEYUP:
40                 if(Size < sizeof(*keyaction))   return -1;
41                 info->KeyCallback(Window, 0, keyaction->KeySym, 0);
42                 return 1;
43         }
44         return 0;
45 }
46
47 static void _SendAttrib(tHWND Window, int Attr, uint32_t Value)
48 {
49         struct sRichTextIPC_SetAttr     msg;
50         msg.Attr = Attr;
51         msg.Value = Value;
52         AxWin3_SendIPC(Window, IPC_RICHTEXT_SETATTR, sizeof(msg), &msg);
53 }
54
55 tHWND AxWin3_RichText_CreateWindow(tHWND Parent, int Flags)
56 {
57         tHWND ret = AxWin3_CreateWindow(Parent, "RichText", Flags,
58                 sizeof(tRichText_Window), AxWin3_RichText_MessageHandler);
59 //      tRichText_Window *info = AxWin3_int_GetDataPtr(ret);
60         return ret;
61 }
62
63 void AxWin3_RichText_SetKeyHandler(tHWND Window, tAxWin3_RichText_KeyHandler Handler)
64 {
65         tRichText_Window        *info = AxWin3_int_GetDataPtr(Window);
66         info->KeyCallback = Handler;
67 }
68
69 void AxWin3_RichText_SetMouseHandler(tHWND Window, tAxWin3_RichText_MouseHandler Handler)
70 {
71         tRichText_Window        *info = AxWin3_int_GetDataPtr(Window);
72         info->MouseCallback = Handler;
73 }
74
75 void AxWin3_RichText_EnableScroll(tHWND Window, int bEnable)
76 {
77         _SendAttrib(Window, _ATTR_SCROLL, bEnable);
78 }
79 void AxWin3_RichText_SetLineCount(tHWND Window, int Lines)
80 {
81         _SendAttrib(Window, _ATTR_LINECOUNT, Lines);
82 }
83 void AxWin3_RichText_SetColCount(tHWND Window, int Cols)
84 {
85         _SendAttrib(Window, _ATTR_COLCOUNT, Cols);
86 }
87 void AxWin3_RichText_SetBackground(tHWND Window, uint32_t ARGB_Colour)
88 {
89         _SendAttrib(Window, _ATTR_DEFBG, ARGB_Colour);
90 }
91 void AxWin3_RichText_SetDefaultColour(tHWND Window, uint32_t ARGB_Colour)
92 {
93         _SendAttrib(Window, _ATTR_DEFFG, ARGB_Colour);
94 }
95 void AxWin3_RichText_SetFont(tHWND Window, const char *FontName, int PointSize)
96 {
97         // TODO: Send message
98 }
99 void AxWin3_RichText_SetCursorType(tHWND Window, int Type)
100 {
101         _SendAttrib(Window, _ATTR_CURSOR, Type);
102 }
103 void AxWin3_RichText_SetCursorBlink(tHWND Window, int bBlink)
104 {
105         _SendAttrib(Window, _ATTR_CURSORBLINK, bBlink);
106 }
107 void AxWin3_RichText_SetCursorPos(tHWND Window, int Row, int Column)
108 {
109         if(Row < 0 || Row > 0xFFFFF || Column > 0xFFF || Column < 0)
110                 return ;
111         _SendAttrib(Window, _ATTR_CURSORPOS, ((Row & 0xFFFFF) << 12) | (Column & 0xFFF));
112 }
113
114 void AxWin3_RichText_ScrollRange(tHWND Window, int FirstRow, int RangeCount, int DownCount)
115 {
116         if( FirstRow < 0 )
117                 return ;
118         if( RangeCount < -2 || RangeCount == 0 )
119                 return ;
120         if( RangeCount > 0 && DownCount > RangeCount )
121                 return ;
122
123         struct sRichTextIPC_ScrollRange msg;
124         msg.First = FirstRow;
125         msg.Range = RangeCount;
126         msg.Count = DownCount;
127         AxWin3_SendIPC(Window, IPC_RICHTEXT_SCROLLRANGE, sizeof(msg), &msg);
128 }
129
130 void AxWin3_RichText_SendLine(tHWND Window, int Line, const char *Text)
131 {
132         // TODO: Local sanity check on `Line`?
133         struct sRichTextIPC_WriteLine   *msg;
134         size_t  len = sizeof(*msg) + strlen(Text) + 1;
135         char    buffer[len];
136         msg = (void*)buffer;
137         msg->Line = Line;
138         strcpy(msg->LineData, Text);
139         AxWin3_SendIPC(Window, IPC_RICHTEXT_WRITELINE, len, msg);
140 }
141

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