2 * AxWin3 Interface Library
3 * - By John Hodge (thePowersGang)
6 * - Formatted Text window type
8 #include <axwin3/axwin.h>
9 #include <axwin3/richtext.h>
10 #include "include/internal.h"
11 #include <richtext_messages.h>
13 #include <wm_messages.h>
17 typedef struct sRichText_Window
19 tAxWin3_RichText_KeyHandler KeyCallback;
20 tAxWin3_RichText_MouseHandler MouseCallback;
21 tAxWin3_RichText_LineHandler LineHandler;
25 int AxWin3_RichText_MessageHandler(tHWND Window, int MessageID, int Size, void *Data)
27 tRichText_Window *info = AxWin3_int_GetDataPtr(Window);
28 struct sWndMsg_KeyAction *keyaction = Data;
32 if(Size < sizeof(*keyaction)) return -1;
33 info->KeyCallback(Window, 2, keyaction->KeySym, keyaction->UCS32);
36 if(Size < sizeof(*keyaction)) return -1;
37 info->KeyCallback(Window, 1, keyaction->KeySym, keyaction->UCS32);
40 if(Size < sizeof(*keyaction)) return -1;
41 info->KeyCallback(Window, 0, keyaction->KeySym, 0);
47 static void _SendAttrib(tHWND Window, int Attr, uint32_t Value)
49 struct sRichTextIPC_SetAttr msg;
52 AxWin3_SendIPC(Window, IPC_RICHTEXT_SETATTR, sizeof(msg), &msg);
55 tHWND AxWin3_RichText_CreateWindow(tHWND Parent, int Flags)
57 tHWND ret = AxWin3_CreateWindow(Parent, "RichText", Flags, sizeof(tRichText_Window), AxWin3_RichText_MessageHandler);
58 // tRichText_Window *info = AxWin3_int_GetDataPtr(ret);
62 void AxWin3_RichText_SetKeyHandler(tHWND Window, tAxWin3_RichText_KeyHandler Handler)
64 tRichText_Window *info = AxWin3_int_GetDataPtr(Window);
65 info->KeyCallback = Handler;
68 void AxWin3_RichText_SetMouseHandler(tHWND Window, tAxWin3_RichText_MouseHandler Handler)
70 tRichText_Window *info = AxWin3_int_GetDataPtr(Window);
71 info->MouseCallback = Handler;
74 void AxWin3_RichText_EnableScroll(tHWND Window, int bEnable)
76 _SendAttrib(Window, _ATTR_SCROLL, bEnable);
78 void AxWin3_RichText_SetLineCount(tHWND Window, int Lines)
80 _SendAttrib(Window, _ATTR_LINECOUNT, Lines);
82 void AxWin3_RichText_SetColCount(tHWND Window, int Cols)
84 _SendAttrib(Window, _ATTR_COLCOUNT, Cols);
86 void AxWin3_RichText_SetBackground(tHWND Window, uint32_t ARGB_Colour)
88 _SendAttrib(Window, _ATTR_DEFBG, ARGB_Colour);
90 void AxWin3_RichText_SetDefaultColour(tHWND Window, uint32_t ARGB_Colour)
92 _SendAttrib(Window, _ATTR_DEFFG, ARGB_Colour);
94 void AxWin3_RichText_SetFont(tHWND Window, const char *FontName, int PointSize)
98 void AxWin3_RichText_SetCursorType(tHWND Window, int Type)
100 _SendAttrib(Window, _ATTR_CURSOR, Type);
102 void AxWin3_RichText_SetCursorBlink(tHWND Window, int bBlink)
104 _SendAttrib(Window, _ATTR_CURSORBLINK, bBlink);
106 void AxWin3_RichText_SetCursorPos(tHWND Window, int Row, int Column)
108 if(Row < 0 || Row > 0xFFFFF || Column > 0xFFF || Column < 0)
110 _SendAttrib(Window, _ATTR_CURSORPOS, ((Row & 0xFFFFF) << 12) | (Column & 0xFFF));
113 void AxWin3_RichText_SendLine(tHWND Window, int Line, const char *Text)
115 // TODO: Local sanity check on `Line`?
116 struct sRichTextIPC_WriteLine *msg;
117 size_t len = sizeof(*msg) + strlen(Text) + 1;
121 strcpy(msg->LineData, Text);
122 AxWin3_SendIPC(Window, IPC_RICHTEXT_WRITELINE, len, msg);