1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
// Feel free to use this code in your own applications.
// The Author does not guarantee anything about this code.
// Author : Yves Maurer
// FormattedTextDraw.h : Declaration of the CFormattedTextDraw
#ifndef __FORMATTEDTEXTDRAW_H_
#define __FORMATTEDTEXTDRAW_H_
#ifndef LY_PER_INCH
#define LY_PER_INCH 1440
#define HOST_BORDER 0
#endif
/////////////////////////////////////////////////////////////////////////////
// CFormattedTextDraw
class CFormattedTextDraw : public ITextHost, public MZeroedObject
{
HWND m_hwndParent;
RECT m_rcClient; // Client Rect
RECT m_rcViewInset; // view rect inset
SIZEL m_sizelExtent; // Extent array
int nPixelsPerInchX; // Pixels per logical inch along width
int nPixelsPerInchY; // Pixels per logical inch along height
CHARFORMAT2W m_CF;
PARAFORMAT2 m_PF;
uint32_t m_dwPropertyBits; // Property bits
bool m_bNative = false; // Doesn't generate RTF itself, uses external plain RTF
ITextServices *m_spTextServices;
ITextDocument *m_spTextDocument;
public:
CFormattedTextDraw();
~CFormattedTextDraw();
HRESULT get_NaturalSize(HDC hdcDraw, long *Width, long *pVal);
HRESULT Draw(HDC hdcDraw, RECT *prc);
HRESULT putRTFText(char *newVal);
HRESULT putTextA(char *newVal);
HRESULT putTextW(wchar_t *newVal);
__forceinline ITextServices *getTextService() { return m_spTextServices; };
__forceinline ITextDocument *getTextDocument() { return m_spTextDocument; };
__forceinline bool isNative() const { return m_bNative; }
__forceinline void setParentWnd(HWND hwnd, RECT rect) { m_hwndParent = hwnd; m_rcClient = rect; }
__forceinline HWND getParentWnd() { return m_hwndParent; }
// IUnknown
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, void __RPC_FAR *__RPC_FAR *ppvObject) override
{ *ppvObject = nullptr;
return S_FALSE;
}
ULONG STDMETHODCALLTYPE AddRef(void) override
{ return 0;
}
ULONG STDMETHODCALLTYPE Release(void) override
{ return 0;
}
// ITextHost
HDC TxGetDC() override;
INT TxReleaseDC(HDC hdc) override;
BOOL TxShowScrollBar(INT fnBar, BOOL fShow) override;
BOOL TxEnableScrollBar(INT fuSBFlags, INT fuArrowflags) override;
BOOL TxSetScrollRange(INT fnBar, LONG nMinPos, INT nMaxPos, BOOL fRedraw) override;
BOOL TxSetScrollPos(INT fnBar, INT nPos, BOOL fRedraw) override;
void TxInvalidateRect(LPCRECT prc, BOOL fMode) override;
void TxViewChange(BOOL fUpdate) override;
BOOL TxCreateCaret(HBITMAP hbmp, INT xWidth, INT yHeight) override;
BOOL TxShowCaret(BOOL fShow) override;
BOOL TxSetCaretPos(INT x, INT y) override;
BOOL TxSetTimer(UINT idTimer, UINT uTimeout) override;
void TxKillTimer(UINT idTimer) override;
void TxScrollWindowEx(INT dx, INT dy, LPCRECT lprcScroll, LPCRECT lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate, UINT fuScroll) override;
void TxSetCapture(BOOL fCapture) override;
void TxSetFocus() override;
void TxSetCursor(HCURSOR hcur, BOOL fText) override;
BOOL TxScreenToClient(LPPOINT lppt) override;
BOOL TxClientToScreen(LPPOINT lppt) override;
HRESULT TxActivate(LONG * plOldState) override;
HRESULT TxDeactivate(LONG lNewState) override;
HRESULT TxGetClientRect(LPRECT prc) override;
HRESULT TxGetViewInset(LPRECT prc) override;
HRESULT TxGetCharFormat(const CHARFORMATW **ppCF) override;
HRESULT TxGetParaFormat(const PARAFORMAT **ppPF) override;
COLORREF TxGetSysColor(int nIndex) override;
HRESULT TxGetBackStyle(TXTBACKSTYLE *pstyle) override;
HRESULT TxGetMaxLength(DWORD *plength) override;
HRESULT TxGetScrollBars(DWORD *pdwScrollBar) override;
HRESULT TxGetPasswordChar(wchar_t *pch) override;
HRESULT TxGetAcceleratorPos(LONG *pcp) override;
HRESULT TxGetExtent(LPSIZEL lpExtent) override;
HRESULT OnTxCharFormatChange(const CHARFORMATW * pcf) override;
HRESULT OnTxParaFormatChange(const PARAFORMAT * ppf) override;
HRESULT TxGetPropertyBits(DWORD dwMask, DWORD *pdwBits) override;
HRESULT TxNotify(DWORD iNotify, void *pv) override;
HIMC TxImmGetContext() override;
void TxImmReleaseContext(HIMC himc) override;
HRESULT TxGetSelectionBarWidth(LONG *lSelBarWidth) override;
// Custom functions
HRESULT CharFormatFromHFONT(CHARFORMAT2W* pCF, HFONT hFont);
HRESULT InitDefaultCharFormat();
HRESULT InitDefaultParaFormat();
};
struct TextObject
{
uint32_t options = 0;
MCONTACT hContact = INVALID_CONTACT_ID;
const char *szProto = nullptr;
CFormattedTextDraw *ftd = nullptr;
TextObject() {}
~TextObject()
{
delete ftd;
}
};
void bbCodeParse(CFormattedTextDraw *ts);
struct TextControlData
{
HANDLE htu;
wchar_t *text;
TextObject *mtext;
COLORREF clBack = -1;
bool m_bInsideDraw = false;
};
#endif //__FORMATTEDTEXTDRAW_H_
|