soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SRichEdit.cpp
1#include "souistd.h"
2#include "control/SRichEdit.h"
3#include "SApp.h"
4#include "helper/SMenu.h"
5#include "helper/SplitString.h"
6#include "helper/SAutoBuf.h"
7#include <gdialpha.h>
8#include <helper/STimer.h>
9
10#ifndef LY_PER_INCH
11#define LY_PER_INCH 1440
12#endif
13
14#ifndef HIMETRIC_PER_INCH
15#define HIMETRIC_PER_INCH 2540
16#endif
17
18#define USE_MSFTEDIT
19
20SNSBEGIN
21//////////////////////////////////////////////////////////////////////////
22// STextServiceHelper
23/**
24 * @class STextServiceHelper
25 * @brief
26 *
27 * Describe
28 */
29class STextServiceHelper *s_textServiceHelper = NULL;
30
32 friend class SRichEdit;
33
34 public:
35 static STextServiceHelper *instance()
36 {
37 SASSERT(s_textServiceHelper);
38 return s_textServiceHelper;
39 }
40
41 public:
42 /**
43 * STextServiceHelper::CreateTextServices
44 * @brief
45 * @param IUnknown *punkOuter
46 * @param ITextHost *pITextHost
47 * @param IUnknown **ppUnk
48 * @return 返回HRESULT
49 *
50 * Describe
51 */
52 HRESULT CreateTextServices(IUnknown *punkOuter, ITextHost *pITextHost, IUnknown **ppUnk);
53
54 protected:
55 /**
56 * STextServiceHelper::STextServiceHelper
57 * @brief 构造函数
58 *
59 * Describe 构造函数
60 */
62 /**
63 * STextServiceHelper::~STextServiceHelper
64 * @brief 析构函数
65 *
66 * Describe 析构函数
67 */
69
70 HINSTANCE m_rich20; /**< richedit module */
71 PCreateTextServices m_funCreateTextServices; /**< 回调函数 */
72};
73
75{
76#ifdef _WIN32
77 m_rich20 = LoadLibrary(_T("Msftedit.dll"));
78#else
79 m_rich20 = LoadLibrary(_T("libmsftedit.so"));
80#endif
81 if (m_rich20)
82 m_funCreateTextServices = (PCreateTextServices)GetProcAddress(m_rich20, "CreateTextServices");
83 else
84 {
85#ifndef _WIN32
86 const char *err = dlerror();
87 printf("load so failed, err=%s\n", err);
88#endif
89 }
90}
91
98
99HRESULT STextServiceHelper::CreateTextServices(IUnknown *punkOuter, ITextHost *pITextHost, IUnknown **ppUnk)
100{
102 return E_NOTIMPL;
103 return m_funCreateTextServices(punkOuter, pITextHost, ppUnk);
104}
105
106void SRichEdit::InitTextService()
107{
108 SASSERT(s_textServiceHelper == NULL);
109 s_textServiceHelper = new STextServiceHelper;
110}
111
112void SRichEdit::UninitTextService()
113{
114 SASSERT(s_textServiceHelper);
115 delete s_textServiceHelper;
116 s_textServiceHelper = NULL;
117}
118
119//////////////////////////////////////////////////////////////////////////
120//
121class SRicheditDropTarget : public IDropTarget {
122 public:
123 SRicheditDropTarget(ITextServices *pTxtSvr)
124 : nRef(1)
125 , pserv(pTxtSvr)
126 {
127 SASSERT(pserv);
128 pserv->AddRef();
129 }
130
131 ~SRicheditDropTarget()
132 {
133 SASSERT(pserv);
134 pserv->Release();
135 }
136
137 // IUnkown
138 virtual HRESULT STDMETHODCALLTYPE QueryInterface(
139 /* [in] */ REFIID riid,
140 /* [iid_is][out] */ void **ppvObject)
141 {
142 HRESULT hr = E_NOINTERFACE;
143 if (riid == __uuidof(IUnknown))
144 *ppvObject = (IUnknown *)this, hr = S_OK;
145 else if (riid == __uuidof(IDropTarget))
146 *ppvObject = (IDropTarget *)this, hr = S_OK;
147 if (SUCCEEDED(hr))
148 AddRef();
149 return hr;
150 }
151
152 virtual ULONG STDMETHODCALLTYPE AddRef(void)
153 {
154 return ++nRef;
155 }
156
157 virtual ULONG STDMETHODCALLTYPE Release(void)
158 {
159 ULONG uRet = --nRef;
160 if (uRet == 0)
161 delete this;
162 return uRet;
163 }
164
165 // IDropTarget
166 virtual HRESULT STDMETHODCALLTYPE DragEnter(
167 /* [unique][in] */ IDataObject *pDataObj,
168 /* [in] */ DWORD grfKeyState,
169 /* [in] */ POINTL pt,
170 /* [out][in] */ DWORD *pdwEffect)
171 {
172 HRESULT hr = S_FALSE;
173 IDropTarget *pDropTarget = NULL;
174 hr = pserv->TxGetDropTarget(&pDropTarget);
175 if (SUCCEEDED(hr))
176 {
177 hr = pDropTarget->DragEnter(pDataObj, grfKeyState, pt, pdwEffect);
178 *pdwEffect = DROPEFFECT_COPY;
179 pDropTarget->Release();
180 }
181 return hr;
182 }
183
184 virtual HRESULT STDMETHODCALLTYPE DragOver(
185 /* [in] */ DWORD grfKeyState,
186 /* [in] */ POINTL pt,
187 /* [out][in] */ DWORD *pdwEffect)
188 {
189 HRESULT hr = S_FALSE;
190 IDropTarget *pDropTarget = NULL;
191 hr = pserv->TxGetDropTarget(&pDropTarget);
192 if (SUCCEEDED(hr))
193 {
194 hr = pDropTarget->DragOver(grfKeyState, pt, pdwEffect);
195 *pdwEffect = DROPEFFECT_COPY;
196 pDropTarget->Release();
197 }
198 return hr;
199 }
200
201 virtual HRESULT STDMETHODCALLTYPE DragLeave(void)
202 {
203 HRESULT hr = S_FALSE;
204 IDropTarget *pDropTarget = NULL;
205 hr = pserv->TxGetDropTarget(&pDropTarget);
206 if (SUCCEEDED(hr))
207 {
208 hr = pDropTarget->DragLeave();
209 pDropTarget->Release();
210 }
211 return hr;
212 }
213
214 virtual HRESULT STDMETHODCALLTYPE Drop(
215 /* [unique][in] */ IDataObject *pDataObj,
216 /* [in] */ DWORD grfKeyState,
217 /* [in] */ POINTL pt,
218 /* [out][in] */ DWORD *pdwEffect)
219 {
220 if (*pdwEffect == DROPEFFECT_NONE)
221 return S_FALSE;
222 HRESULT hr = S_FALSE;
223 IDropTarget *pDropTarget = NULL;
224 hr = pserv->TxGetDropTarget(&pDropTarget);
225 if (SUCCEEDED(hr))
226 {
227 hr = pDropTarget->Drop(pDataObj, grfKeyState, pt, pdwEffect);
228 pDropTarget->Release();
229 }
230 return hr;
231 }
232
233 protected:
234 ITextServices *pserv; // pointer to Text Services object
235 LONG nRef;
236};
237
238const LONG cInitTextMax = (32 * 1024) - 1;
239#define FValidCF(_pcf) ((_pcf)->cbSize == sizeof(CHARFORMAT2W))
240#define FValidPF(_ppf) ((_ppf)->cbSize == sizeof(PARAFORMAT2))
241#define TIMER_INVALIDATE 6
242
243EXTERN_C const IID IID_ITextServices = // 8d33f740-cf58-11ce-a89d-00aa006cadc5
244 { 0x8d33f740, 0xcf58, 0x11ce, { 0xa8, 0x9d, 0x00, 0xaa, 0x00, 0x6c, 0xad, 0xc5 } };
245
246EXTERN_C const IID IID_ITextHost = /* c5bdd8d0-d26e-11ce-a89e-00aa006cadc5 */
247 { 0xc5bdd8d0, 0xd26e, 0x11ce, { 0xa8, 0x9e, 0x00, 0xaa, 0x00, 0x6c, 0xad, 0xc5 } };
248
249// Convert Device Pixels to Himetric
250LONG DtoHimetric(LONG d, LONG dPerInch)
251{
252 return (LONG)MulDiv(d, HIMETRIC_PER_INCH, dPerInch);
253}
254
255// Convert Himetric Device pixels
256LONG HimetrictoD(LONG lHimetric, LONG dPerInch)
257{
258 return (LONG)MulDiv(lHimetric, dPerInch, HIMETRIC_PER_INCH);
259}
260
261/**
262 * @class STextHost
263 * @brief
264 *
265 * Describe
266 */
267class STextHost : public ITextHost {
268 friend class SRichEdit;
269
270 public:
271 /**
272 * STextHost::STextHost
273 * @brief 构造函数
274 *
275 * Describe 构造函数
276 */
277 STextHost(void);
278 /**
279 * STextHost::~STextHost
280 * @brief 析构函数
281 *
282 * Describe 析构函数
283 */
284 ~STextHost(void);
285 /**
286 * STextHost::Init
287 * @brief 初始化函数
288 * @param SRichEdit* pRichEdit -- SRichEdit对象
289 *
290 * Describe 初始化函数
291 */
292 BOOL Init(SRichEdit *pRichEdit);
293 /**
294 * STextHost::GetTextService
295 * @brief
296 *
297 * Describe
298 */
299 ITextServices *GetTextService()
300 {
301 return pserv;
302 }
303
304 protected:
305 STDMETHOD_(HRESULT, QueryInterface)(THIS_ REFGUID riid, void **ppvObject) OVERRIDE;
306 STDMETHOD_(ULONG, AddRef)(THIS) OVERRIDE;
307 STDMETHOD_(ULONG, Release)(THIS) OVERRIDE;
308
309 /**
310 * STextHost::TxGetDC
311 * @brief Get the DC for the host
312 * @return 返回HDC
313 *
314 * Describe Get the DC for the host
315 */
316 virtual HDC TxGetDC();
317
318 /**
319 * STextHost::TxReleaseDC
320 * @brief Release the DC gotten from the host
321 * @return 返回INT
322 *
323 * Describe Release the DC gotten from the host
324 */
325 virtual INT TxReleaseDC(HDC hdc);
326
327 /**
328 * STextHost::TxShowScrollBar
329 * @brief Show the scroll bar
330 * @param INT fnBar --
331 * @param BOOL fShow --
332 * @return 返回BOOL
333 *
334 * Describe Show the scroll bar
335 */
336 virtual BOOL TxShowScrollBar(INT fnBar, BOOL fShow);
337
338 /**
339 * STextHost::TxEnableScrollBar
340 * @brief Enable the scroll bar
341 * @param INT fuSBFlags --
342 * @param INT fuArrowflags --
343 * @return 返回BOOL
344 *
345 * Describe Enable the scroll bar
346 */
347 virtual BOOL TxEnableScrollBar(INT fuSBFlags, INT fuArrowflags);
348
349 /**
350 * STextHost::TxEnableScrollBar
351 * @brief Set the scroll range
352 * @param INT fnBar --
353 * @param LONG nMinPos --
354 * @param INT nMaxPos --
355 * @param BOOL fRedraw --
356 * @return 返回BOOL
357 *
358 * Describe Set the scroll range
359 */
360 virtual BOOL TxSetScrollRange(INT fnBar, LONG nMinPos, INT nMaxPos, BOOL fRedraw);
361
362 /**
363 * STextHost::TxSetScrollPos
364 * @brief Set the scroll position
365 * @param INT fnBar --
366 * @param INT nPos --
367 * @param BOOL fRedraw --
368 * @return 返回BOOL
369 *
370 * Describe Set the scroll position
371 */
372 virtual BOOL TxSetScrollPos(INT fnBar, INT nPos, BOOL fRedraw);
373
374 /**
375 * STextHost::TxInvalidateRect
376 * @brief InvalidateRect
377 * @param LPCRECT prc --
378 * @param BOOL fMode --
379 *
380 * Describe Set the scroll position
381 */
382 virtual void TxInvalidateRect(LPCRECT prc, BOOL fMode);
383
384 /**
385 * STextHost::TxViewChange
386 * @brief Send a WM_PAINT to the window
387 * @param BOOL fUpdate --
388 *
389 * Describe Send a WM_PAINT to the window
390 */
391 virtual void TxViewChange(BOOL fUpdate);
392
393 /**
394 * STextHost::TxCreateCaret
395 * @brief Create the caret
396 * @param HBITMAP hbmp -- caret bitmap
397 * @param INT xWidth -- caret width
398 * @param INT yHeight -- caret height
399 * @return 返回BOOL
400 *
401 * Describe Create the caret
402 */
403 virtual BOOL TxCreateCaret(HBITMAP hbmp, INT xWidth, INT yHeight);
404
405 /**
406 * STextHost::TxShowCaret
407 * @brief Show the caret
408 * @param BOOL fShow -- true to show the caret
409 * @return 返回BOOL
410 *
411 * Describe Show the caret
412 */
413 virtual BOOL TxShowCaret(BOOL fShow);
414
415 /**
416 * STextHost::TxSetCaretPos
417 * @brief Set the caret position
418 * @param INT x -- caret position:x
419 * @param INT y -- caret position:y
420 * @return 返回BOOL
421 *
422 * Describe Set the caret position
423 */
424 virtual BOOL TxSetCaretPos(INT x, INT y);
425
426 /**
427 * STextHost::TxSetTimer
428 * @brief Create a timer with the specified timeout
429 * @param UINT idTimer -- timer ID
430 * @param UINT uTimeout -- time interval
431 * @return 返回BOOL
432 *
433 * Describe Create a timer with the specified timeout
434 */
435 virtual BOOL TxSetTimer(UINT idTimer, UINT uTimeout);
436
437 /**
438 * STextHost::TxSetTimer
439 * @brief Destroy a timer
440 * @param UINT idTimer -- timer id
441 * @return 返回BOOL
442 *
443 * Describe Destroy a timer
444 */
445 virtual void TxKillTimer(UINT idTimer);
446
447 /**
448 * STextHost::TxScrollWindowEx
449 * @brief Scroll the content of the specified window's client area
450 * @param INT dx --
451 * @param INT dy --
452 * @param LPCRECT lprcScroll --
453 * @param LPCRECT lprcClip --
454 * @param HRGN hrgnUpdate --
455 * @param LPRECT lprcUpdate --
456 * @param UINT fuScroll --
457 *
458 * Describe Scroll the content of the specified window's client area
459 */
460 virtual void TxScrollWindowEx(INT dx, INT dy, LPCRECT lprcScroll, LPCRECT lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate, UINT fuScroll);
461
462 /**
463 * STextHost::TxSetCapture
464 * @brief Get mouse capture
465 * @param BOOL fCapture --
466 *
467 * Describe Get mouse capture
468 */
469 virtual void TxSetCapture(BOOL fCapture);
470
471 /**
472 * STextHost::TxSetFocus
473 * @brief Set the focus to the text window
474 *
475 * Describe Set the focus to the text window
476 */
477 virtual void TxSetFocus();
478
479 /**
480 * STextHost::TxSetCursor
481 * @brief Establish a new cursor shape
482 * @param HCURSOR hcur --
483 * @param BOOL fText --
484 *
485 * Describe Establish a new cursor shape
486 */
487 virtual void TxSetCursor(HCURSOR hcur, BOOL fText);
488
489 /**
490 * STextHost::TxScreenToClient
491 * @brief Converts screen coordinates of a specified point to the client coordinates
492 * @param LPPOINT lppt --
493 * @return 返回BOOL
494 *
495 * Describe Converts screen coordinates of a specified point to the client coordinates
496 */
497 virtual BOOL TxScreenToClient(LPPOINT lppt);
498
499 /**
500 * STextHost::TxClientToScreen
501 * @brief Converts the client coordinates of a specified point to screen coordinates
502 * @param LPPOINT lppt --
503 * @return 返回BOOL
504 *
505 * Describe Converts the client coordinates of a specified point to screen coordinates
506 */
507 virtual BOOL TxClientToScreen(LPPOINT lppt);
508
509 /**
510 * STextHost::TxActivate
511 * @brief Request host to activate text services
512 * @param LONG * plOldState --
513 * @return 返回HRESULT
514 *
515 * Describe Request host to activate text services
516 */
517 virtual HRESULT TxActivate(LONG *plOldState);
518
519 /**
520 * STextHost::TxDeactivate
521 * @brief Request host to deactivate text services
522 * @param LONG lNewState --
523 * @return 返回HRESULT
524 *
525 * Describe Request host to deactivate text services
526 */
527 virtual HRESULT TxDeactivate(LONG lNewState);
528
529 /**
530 * STextHost::TxGetClientRect
531 * @brief Retrieves the coordinates of a window's client area
532 * @param LPRECT prc --
533 * @return 返回HRESULT
534 *
535 * Describe Retrieves the coordinates of a window's client area
536 */
537 virtual HRESULT TxGetClientRect(LPRECT prc);
538
539 /**
540 * STextHost::TxGetViewInset
541 * @brief Get the view rectangle relative to the inset
542 * @param LPRECT prc --
543 * @return 返回HRESULT
544 *
545 * Describe Get the view rectangle relative to the inset
546 */
547 virtual HRESULT TxGetViewInset(LPRECT prc);
548
549 /**
550 * STextHost::TxGetCharFormat
551 * @brief Get the default character format for the text
552 * @param const CHARFORMATW **ppCF --
553 * @return 返回HRESULT
554 *
555 * Describe Get the default character format for the text
556 */
557 virtual HRESULT TxGetCharFormat(const CHARFORMATW **ppCF);
558
559 /**
560 * STextHost::TxGetParaFormat
561 * @brief Get the default paragraph format for the text
562 * @param const PARAFORMAT **ppPF --
563 * @return 返回HRESULT
564 *
565 * Describe Get the default character format for the text
566 */
567 virtual HRESULT TxGetParaFormat(const PARAFORMAT **ppPF);
568
569 /**
570 * STextHost::TxGetSysColor
571 * @brief Get the background color for the window
572 * @param int nIndex --
573 * @return 返回COLORREF
574 *
575 * Describe Get the background color for the window
576 */
577 virtual COLORREF TxGetSysColor(int nIndex);
578
579 /**
580 * STextHost::TxGetBackStyle
581 * @brief Get the background (either opaque or transparent)
582 * @param TXTBACKSTYLE *pstyle --
583 * @return 返回HRESULT
584 *
585 * Describe Get the background (either opaque or transparent)
586 */
587 virtual HRESULT TxGetBackStyle(TXTBACKSTYLE *pstyle);
588
589 /**
590 * STextHost::TxGetMaxLength
591 * @brief Get the maximum length for the text
592 * @param DWORD *plength --
593 * @return 返回HRESULT
594 *
595 * Describe Get the maximum length for the text
596 */
597 virtual HRESULT TxGetMaxLength(DWORD *plength);
598
599 /**
600 * STextHost::TxGetScrollBars
601 * @brief Get the bits representing requested scroll bars for the window
602 * @param DWORD *pdwScrollBar --
603 * @return 返回HRESULT
604 *
605 * Describe Get the bits representing requested scroll bars for the window
606 */
607 virtual HRESULT TxGetScrollBars(DWORD *pdwScrollBar);
608
609 /**
610 * STextHost::TxGetPasswordChar
611 * @brief Get the character to display for password input
612 * @param TCHAR *pch --
613 * @return 返回HRESULT
614 *
615 * Describe Get the character to display for password input
616 */
617 virtual HRESULT TxGetPasswordChar(TCHAR *pch);
618
619 /**
620 * STextHost::TxGetAcceleratorPos
621 * @brief Get the accelerator character
622 * @param LONG *pcp --
623 * @return 返回HRESULT
624 *
625 * Describe Get the accelerator character
626 */
627 virtual HRESULT TxGetAcceleratorPos(LONG *pcp);
628
629 /**
630 * STextHost::TxGetExtent
631 * @brief Get the native size
632 * @param LPSIZEL lpExtent --
633 * @return 返回HRESULT
634 *
635 * Describe Get the native size
636 */
637 virtual HRESULT TxGetExtent(LPSIZEL lpExtent);
638
639 /**
640 * STextHost::OnTxCharFormatChange
641 * @brief Notify host that default character format has changed
642 * @param const CHARFORMATW * pcf --
643 * @return 返回HRESULT
644 *
645 * Describe Notify host that default character format has changed
646 */
647 virtual HRESULT OnTxCharFormatChange(const CHARFORMATW *pcf);
648
649 /**
650 * STextHost::OnTxParaFormatChange
651 * @brief Notify host that default paragraph format has changed
652 * @param const PARAFORMAT * ppf --
653 * @return 返回HRESULT
654 *
655 * Describe Notify host that default paragraph format has changed
656 */
657 virtual HRESULT OnTxParaFormatChange(const PARAFORMAT *ppf);
658
659 /**
660 * STextHost::TxGetPropertyBits
661 * @brief Bulk access to bit properties
662 * @param DWORD dwMask --
663 * @param DWORD *pdwBits --
664 * @return 返回HRESULT
665 *
666 * Describe Bulk access to bit properties
667 */
668 virtual HRESULT TxGetPropertyBits(DWORD dwMask, DWORD *pdwBits);
669
670 /**
671 * STextHost::TxNotify
672 * @brief Notify host of events
673 * @param DWORD iNotify --
674 * @param void *pv --
675 * @return 返回HRESULT
676 *
677 * Describe Bulk access to bit properties
678 */
679 virtual HRESULT TxNotify(DWORD iNotify, void *pv);
680
681 // Far East Methods for getting the Input Context
682 //#ifdef WIN95_IME
683 /**
684 * STextHost::TxImmGetContext
685 * @brief
686 * @return 返回HIMC
687 *
688 * Describe
689 */
690 virtual HIMC TxImmGetContext();
691 /**
692 * STextHost::TxImmReleaseContext
693 * @brief
694 * @param HIMC himc --
695 *
696 * Describe
697 */
698 virtual void TxImmReleaseContext(HIMC himc);
699 //#endif
700
701 /**
702 * STextHost::TxGetSelectionBarWidth
703 * @brief Returns HIMETRIC size of the control bar
704 * @param LONG *plSelBarWidth --
705 *
706 * Describe Returns HIMETRIC size of the control bar
707 */
708 virtual HRESULT TxGetSelectionBarWidth(LONG *plSelBarWidth);
709
710 protected:
711 BOOL m_fUiActive; /**< Whether control is inplace active */
712
713 ULONG cRefs; /**< Reference Count */
714 ITextServices *pserv; /**< pointer to Text Services object */
715 SRichEdit *m_pRichEdit; /**< swindow for text host */
716 POINT m_ptCaret;
717};
718
720 : m_pRichEdit(NULL)
721 , cRefs(0)
722 , m_fUiActive(FALSE)
723 , pserv(NULL)
724{
725}
726
728{
729 if (pserv)
730 pserv->Release();
731}
732
733//////////////////////////////////////////////////////////////////////////
734// IUnknown
735HRESULT STextHost::QueryInterface(REFIID riid, void **ppvObject)
736{
737 HRESULT hr = E_NOINTERFACE;
738 *ppvObject = NULL;
739
740 if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_ITextHost))
741 {
742 AddRef();
743 *ppvObject = (ITextHost *)this;
744 hr = S_OK;
745 }
746
747 return hr;
748}
749
750ULONG STextHost::AddRef(void)
751{
752 return ++cRefs;
753}
754
755ULONG STextHost::Release(void)
756{
757 ULONG c_Refs = --cRefs;
758
759 if (c_Refs == 0)
760 {
761 delete this;
762 }
763
764 return c_Refs;
765}
766
767//////////////////////////////////////////////////////////////////////////
768// ITextHost
769HRESULT STextHost::TxGetViewInset(LPRECT prc)
770{
771 *prc = m_pRichEdit->m_rcInset;
772 return S_OK;
773}
774
775HRESULT STextHost::TxGetCharFormat(const CHARFORMATW **ppCF)
776{
777 *ppCF = &m_pRichEdit->m_cfDef;
778 return S_OK;
779}
780
781HRESULT STextHost::TxGetParaFormat(const PARAFORMAT **ppPF)
782{
783 *ppPF = &m_pRichEdit->m_pfDef;
784 return S_OK;
785}
786
787HRESULT STextHost::TxGetClientRect(LPRECT prc)
788{
789 m_pRichEdit->GetClientRect(prc);
790 return S_OK;
791}
792
793HRESULT STextHost::TxDeactivate(LONG lNewState)
794{
795 m_fUiActive = FALSE;
796 return S_OK;
797}
798
799HRESULT STextHost::TxActivate(LONG *plOldState)
800{
801 *plOldState = m_fUiActive;
802 m_fUiActive = TRUE;
803 return S_OK;
804}
805
807{
808 RECT rc = { 0 };
809 m_pRichEdit->GetContainer()->FrameToHost(&rc);
810 lppt->x += rc.left;
811 lppt->y += rc.top;
812 return ::ClientToScreen(m_pRichEdit->GetContainer()->GetHostHwnd(), lppt);
813}
814
816{
817 RECT rc = { 0 };
818 m_pRichEdit->GetContainer()->FrameToHost(&rc);
819 lppt->x -= rc.left;
820 lppt->y -= rc.top;
821 return ::ScreenToClient(m_pRichEdit->GetContainer()->GetHostHwnd(), lppt);
822}
823
824void STextHost::TxSetCursor(HCURSOR hcur, BOOL fText)
825{
826 ::SetCursor(hcur);
827}
828
830{
831 m_pRichEdit->SetFocus();
832}
833
834void STextHost::TxSetCapture(BOOL fCapture)
835{
836 if (fCapture)
837 m_pRichEdit->SetCapture();
838 else
839 m_pRichEdit->ReleaseCapture();
840}
841
842void STextHost::TxScrollWindowEx(INT dx, INT dy, LPCRECT lprcScroll, LPCRECT lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate, UINT fuScroll)
843{
844 m_pRichEdit->Invalidate();
845}
846
847void STextHost::TxKillTimer(UINT idTimer)
848{
849 m_pRichEdit->OnTxKillTimer(idTimer);
850}
851
852BOOL STextHost::TxSetTimer(UINT idTimer, UINT uTimeout)
853{
854 return m_pRichEdit->OnTxSetTimer(idTimer, uTimeout);
855}
856
857BOOL STextHost::TxSetCaretPos(INT x, INT y)
858{
859 m_ptCaret.x = x, m_ptCaret.y = y;
860 m_pRichEdit->SetCaretPos(x, y);
861 return TRUE;
862}
863
865{
866 if (fShow && !m_fUiActive)
867 return FALSE;
868 m_pRichEdit->ShowCaret(fShow);
869 return TRUE;
870}
871
872BOOL STextHost::TxCreateCaret(HBITMAP hbmp, INT xWidth, INT yHeight)
873{
874 return m_pRichEdit->CreateCaret(hbmp, xWidth, yHeight);
875}
876
878{
879 return ::GetDC(NULL);
880}
881
883{
884 return ::ReleaseDC(NULL, hdc);
885}
886
887BOOL STextHost::TxShowScrollBar(INT fnBar, BOOL fShow)
888{
889 int wBar = 0;
890 switch (fnBar)
891 {
892 case SB_BOTH:
893 wBar = SSB_BOTH;
894 break;
895 case SB_VERT:
896 wBar = SSB_VERT;
897 break;
898 case SB_HORZ:
899 wBar = SSB_HORZ;
900 break;
901 }
902 return m_pRichEdit->ShowScrollBar(wBar, fShow);
903}
904
905BOOL STextHost::TxEnableScrollBar(INT fuSBFlags, INT fuArrowflags)
906{
907 int wBar = 0;
908 switch (fuSBFlags)
909 {
910 case SB_BOTH:
911 wBar = SSB_BOTH;
912 break;
913 case SB_VERT:
914 wBar = SSB_VERT;
915 break;
916 case SB_HORZ:
917 wBar = SSB_HORZ;
918 break;
919 }
920 return m_pRichEdit->EnableScrollBar(wBar, fuArrowflags == ESB_ENABLE_BOTH);
921}
922
923BOOL STextHost::TxSetScrollRange(INT fnBar, LONG nMinPos, INT nMaxPos, BOOL fRedraw)
924{
925 return m_pRichEdit->SetScrollRange(fnBar != SB_HORZ, nMinPos, nMaxPos, fRedraw);
926}
927
928BOOL SRichEdit::OnTxSetScrollPos(INT fnBar, INT nPos, BOOL fRedraw)
929{
931 return TRUE;
932 BOOL bVertical = fnBar != SB_HORZ;
933 SCROLLINFO *psi = bVertical ? (&m_siVer) : (&m_siHoz);
934
935 if (psi->nPos != nPos)
936 {
937 psi->nPos = nPos;
938 CRect rcSb = GetScrollBarRect(!!bVertical);
939 InvalidateRect(rcSb);
940 }
941 if (fRedraw)
942 {
943 Invalidate();
944 }
945 return TRUE;
946}
947
948BOOL STextHost::TxSetScrollPos(INT fnBar, INT nPos, BOOL fRedraw)
949{
950 return m_pRichEdit->OnTxSetScrollPos(fnBar, nPos, fRedraw);
951}
952
953void STextHost::TxInvalidateRect(LPCRECT prc, BOOL fMode)
954{
955 if (prc)
956 {
957 m_pRichEdit->InvalidateRect(prc);
958 }
959 else
960 {
961 m_pRichEdit->Invalidate();
962 }
963}
964
965void STextHost::TxViewChange(BOOL fUpdate)
966{
967 if (fUpdate)
968 {
969 m_pRichEdit->InvalidateRect(NULL);
970 }
971}
972
973COLORREF STextHost::TxGetSysColor(int nIndex)
974{
975 return ::GetSysColor(nIndex);
976}
977
978HRESULT STextHost::TxGetBackStyle(TXTBACKSTYLE *pstyle)
979{
980 *pstyle = TXTBACK_TRANSPARENT;
981 return S_OK;
982}
983
984HRESULT STextHost::TxGetMaxLength(DWORD *plength)
985{
986 *plength = m_pRichEdit->m_cchTextMost;
987 return S_OK;
988}
989
990HRESULT STextHost::TxGetScrollBars(DWORD *pdwScrollBar)
991{
992 *pdwScrollBar = m_pRichEdit->m_dwStyle & (WS_VSCROLL | WS_HSCROLL | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_DISABLENOSCROLL);
993
994 return S_OK;
995}
996
998{
999 *pch = m_pRichEdit->m_chPasswordChar;
1000 return S_OK;
1001}
1002
1004{
1005 *pcp = m_pRichEdit->m_lAccelPos;
1006 return S_OK;
1007}
1008
1009HRESULT STextHost::TxGetExtent(LPSIZEL lpExtent)
1010{
1011 *lpExtent = m_pRichEdit->m_sizelExtent;
1012 return S_OK;
1013}
1014
1015HRESULT STextHost::OnTxCharFormatChange(const CHARFORMATW *pcf)
1016{
1017 return S_OK;
1018}
1019
1020HRESULT STextHost::OnTxParaFormatChange(const PARAFORMAT *ppf)
1021{
1022 return S_OK;
1023}
1024
1025HRESULT STextHost::TxGetPropertyBits(DWORD dwMask, DWORD *pdwBits)
1026{
1027 DWORD dwProperties = 0;
1028
1029 if (m_pRichEdit->m_fRich)
1030 {
1031 dwProperties = TXTBIT_RICHTEXT;
1032 }
1033
1034 if (m_pRichEdit->m_dwStyle & ES_MULTILINE)
1035 {
1036 dwProperties |= TXTBIT_MULTILINE;
1037 }
1038
1039 if (m_pRichEdit->m_dwStyle & ES_READONLY)
1040 {
1041 dwProperties |= TXTBIT_READONLY;
1042 }
1043
1044 if (m_pRichEdit->m_dwStyle & ES_PASSWORD)
1045 {
1046 dwProperties |= TXTBIT_USEPASSWORD;
1047 }
1048
1049 if (!(m_pRichEdit->m_dwStyle & ES_NOHIDESEL))
1050 {
1051 dwProperties |= TXTBIT_HIDESELECTION;
1052 }
1053
1054 if (m_pRichEdit->m_fEnableAutoWordSel)
1055 {
1056 dwProperties |= TXTBIT_AUTOWORDSEL;
1057 }
1058
1059 if (m_pRichEdit->m_fVertical)
1060 {
1061 dwProperties |= TXTBIT_VERTICAL;
1062 }
1063
1064 if (m_pRichEdit->m_fWordWrap)
1065 {
1066 dwProperties |= TXTBIT_WORDWRAP;
1067 }
1068
1069 if (m_pRichEdit->m_fAllowBeep)
1070 {
1071 dwProperties |= TXTBIT_ALLOWBEEP;
1072 }
1073
1074 if (m_pRichEdit->m_fSaveSelection)
1075 {
1076 dwProperties |= TXTBIT_SAVESELECTION;
1077 }
1078
1079 *pdwBits = dwProperties & dwMask;
1080 return NOERROR;
1081}
1082
1083HRESULT STextHost::TxNotify(DWORD iNotify, void *pv)
1084{
1085 return m_pRichEdit->OnTxNotify(iNotify, pv);
1086}
1087
1089{
1090 return ImmGetContext(m_pRichEdit->GetContainer()->GetHostHwnd());
1091}
1092
1094{
1095 ImmReleaseContext(m_pRichEdit->GetContainer()->GetHostHwnd(), himc);
1096}
1097
1098HRESULT STextHost::TxGetSelectionBarWidth(LONG *plSelBarWidth)
1099{
1100 *plSelBarWidth = 0;
1101 return S_OK;
1102}
1103
1104BOOL STextHost::Init(SRichEdit *pRichEdit)
1105{
1106 IUnknown *pUnk;
1107 HRESULT hr;
1108
1109 m_pRichEdit = pRichEdit;
1110
1111 // Create Text Services component
1112 if (FAILED(STextServiceHelper::instance()->CreateTextServices(NULL, this, &pUnk)))
1113 return FALSE;
1114
1115 hr = pUnk->QueryInterface(IID_ITextServices, (void **)&pserv);
1116
1117 pUnk->Release();
1118
1119 return SUCCEEDED(hr);
1120}
1121
1122//////////////////////////////////////////////////////////////////////////
1123// dui interface
1124
1126 : m_pTxtHost(NULL)
1127 , m_fTransparent(0)
1128 , m_fRich(1)
1129 , m_fSaveSelection(TRUE)
1130 , m_fVertical(FALSE)
1131 , m_fWordWrap(FALSE)
1132 , m_fAllowBeep(FALSE)
1133 , m_fEnableAutoWordSel(TRUE)
1134 , m_fWantTab(FALSE)
1135 , m_fSingleLineVCenter(TRUE)
1136 , m_fScrollPending(FALSE)
1137 , m_fEnableDragDrop(FALSE)
1138 , m_fAutoSel(FALSE)
1139 , m_fNotifyChange(FALSE)
1140 , m_fDisableCaret(FALSE)
1141 , m_cchTextMost(cInitTextMax)
1142 , m_chPasswordChar(_T('*'))
1143 , m_lAccelPos(-1)
1144 , m_dwStyle(ES_LEFT | ES_AUTOHSCROLL)
1145 , m_byDbcsLeadByte(0)
1146{
1147 m_pNcSkin = GETBUILTINSKIN(SKIN_SYS_BORDER);
1148
1149 m_bFocusable = TRUE;
1150 m_bClipClient = TRUE;
1151 m_sizelExtent.cx = m_sizelExtent.cy = 0;
1152 m_evtSet.addEvent(EVENTID(EventRENotify));
1153 m_evtSet.addEvent(EVENTID(EventREMenu));
1154 m_evtSet.addEvent(EVENTID(EventKeyDown));
1155}
1156
1158{
1159 if (0 != __baseCls::OnCreate(NULL))
1160 return 1;
1161
1164
1165 m_pTxtHost = new STextHost;
1166 m_pTxtHost->AddRef();
1167 if (!m_pTxtHost->Init(this))
1168 {
1169 m_pTxtHost->Release();
1170 m_pTxtHost = NULL;
1171 return 1;
1172 }
1173
1174 if (!m_fTransparent && m_style.m_crBg == CR_INVALID && !m_pBgSkin)
1175 m_style.m_crBg = RGB(0xff, 0xff, 0xff);
1176 // inplace activate
1177 m_pTxtHost->GetTextService()->OnTxInPlaceActivate(NULL);
1178 //默认没有焦点
1179 m_pTxtHost->m_fUiActive = FALSE;
1180 m_pTxtHost->GetTextService()->OnTxUIDeactivate();
1181 m_pTxtHost->GetTextService()->TxSendMessage(WM_KILLFOCUS, 0, 0, 0);
1182
1183 // set IME
1184 DWORD dw = (DWORD)SSendMessage(EM_GETLANGOPTIONS);
1185 dw |= IMF_AUTOKEYBOARD | IMF_DUALFONT | IMF_UIFONTS;
1186 dw &= ~IMF_AUTOFONT;
1187 SSendMessage(EM_SETLANGOPTIONS, 0, dw);
1188
1189 if (m_fNotifyChange)
1190 { // receive enm_change event
1191 SSendMessage(EM_SETEVENTMASK, 0, ENM_CHANGE);
1192 }
1193
1194 if (m_strRtfSrc.IsEmpty())
1196 else
1197 SetAttribute(L"rtf", m_strRtfSrc, FALSE);
1198 // register droptarget
1199 OnEnableDragDrop(!(m_dwStyle & ES_READONLY) & m_fEnableDragDrop);
1200 return 0;
1201}
1202
1204{
1205 KillFocus();
1206 OnEnableDragDrop(FALSE);
1207
1208 if (m_pTxtHost)
1209 {
1210 m_pTxtHost->GetTextService()->OnTxInPlaceDeactivate();
1211 m_pTxtHost->Release();
1212 m_pTxtHost = NULL;
1213 }
1214 m_mapTimer.RemoveAll();
1215 __baseCls::OnDestroy();
1216}
1217
1219{
1220 CRect rcClient;
1221 GetClientRect(&rcClient);
1222 pRT->PushClipRect(&rcClient, RGN_AND);
1223
1224 float fMtx[9];
1225 pRT->GetTransform(fMtx);
1226 SMatrix mtx(fMtx);
1227
1229 if (!mtx.isIdentity() || !pRT->IsOffscreen())
1230 {
1231 GETRENDERFACTORY->CreateRenderTarget(&rt, rcClient.Width(), rcClient.Height());
1232 rt->BeginDraw();
1233 rt->SetViewportOrg(-rcClient.TopLeft());
1234 if (!SUCCEEDED(rt->BitBlt(&rcClient, pRT, rcClient.left, rcClient.top)))
1235 {
1236 //从ID2D1HwndRenderTarget复制背景会失败,重新生成背景
1237 rt->ClearRect(&rcClient, RGBA(255, 255, 255, 255));
1238 SSendMessage(WM_ERASEBKGND, (WPARAM)(IRenderTarget *)rt);
1239 }
1240 }
1241 else
1242 {
1243 rt = pRT;
1244 }
1245 HDC hdc = rt->GetDC(0);
1246 if (hdc)
1247 {
1248 int nOldMode = ::SetGraphicsMode(hdc, GM_COMPATIBLE); // richedit需要将GraphicMode强制设置为GM_COMPATIBLE
1249
1250#ifdef _WIN32
1251 ALPHAINFO ai;
1252 CGdiAlpha::AlphaBackup(hdc, &rcClient, ai);
1253#endif //_WIN32
1254 LONG lPos = 0;
1255 m_pTxtHost->GetTextService()->TxGetVScroll(NULL, NULL, &lPos, NULL, NULL);
1256 RECTL rcL = { rcClient.left, rcClient.top, rcClient.right, rcClient.bottom };
1257 m_pTxtHost->GetTextService()->TxDraw(DVASPECT_CONTENT, // Draw Aspect
1258 0, // Lindex
1259 NULL, // Info for drawing optimazation
1260 NULL, // target device information
1261 hdc, // Draw device HDC
1262 NULL, // Target device HDC
1263 &rcL, // Bounding client rectangle
1264 NULL, // Clipping rectangle for metafiles
1265 &rcClient, // Update rectangle
1266 NULL, // Call back function
1267 0, // Call back parameter
1268 TXTVIEW_ACTIVE);
1269#ifdef _WIN32
1270 CGdiAlpha::AlphaRestore(ai);
1271#endif //_WIN32
1272 ::SetGraphicsMode(hdc, nOldMode);
1273 }
1274 rt->ReleaseDC(hdc, &rcClient);
1275 if (rt != pRT)
1276 {
1277 rt->EndDraw();
1278 pRT->AlphaBlend(&rcClient, rt, &rcClient, 255);
1279 rt = NULL;
1280 }
1281 pRT->PopClip();
1282}
1283
1284void SRichEdit::OnSetFocus(SWND wndOld)
1285{
1286 __baseCls::OnSetFocus(wndOld);
1287
1288 if (m_pTxtHost && IsVisible(TRUE) && !IsDisabled(TRUE))
1289 {
1290 m_pTxtHost->m_fUiActive = TRUE;
1291 m_pTxtHost->GetTextService()->OnTxUIActivate();
1292 m_pTxtHost->GetTextService()->TxSendMessage(WM_SETFOCUS, 0, 0, 0);
1293 if (m_fAutoSel)
1294 SetSel((DWORD)MAKELONG(0, -1), TRUE);
1295 }
1296
1297 if (ES_PASSWORD & m_dwStyle || ES_NUMBER & m_dwStyle)
1298 {
1299 GetContainer()->EnableIME(FALSE);
1300 }
1301}
1302
1303void SRichEdit::OnKillFocus(SWND wndFocus)
1304{
1305 if (ES_PASSWORD & m_dwStyle || ES_NUMBER & m_dwStyle)
1306 {
1307 GetContainer()->EnableIME(TRUE);
1308 }
1309
1310 __baseCls::OnKillFocus(wndFocus);
1311 if (m_pTxtHost)
1312 {
1313 m_pTxtHost->m_fUiActive = FALSE;
1314 m_pTxtHost->GetTextService()->OnTxUIDeactivate();
1315 m_pTxtHost->GetTextService()->TxSendMessage(WM_KILLFOCUS, 0, 0, 0);
1316 m_pTxtHost->TxShowCaret(FALSE);
1317 }
1318 //防止正在编辑时隐藏了cursor
1320}
1321
1322void SRichEdit::OnTimer(char idEvent)
1323{
1324 if (idEvent == TIMER_INVALIDATE)
1325 {
1326 Invalidate();
1327 KillTimer(idEvent);
1328 }
1329 else
1330 {
1331 __baseCls::OnTimer(idEvent);
1332 }
1333}
1334
1336{
1337 UINT uRet = SC_WANTCHARS | SC_WANTARROWS;
1338 if (m_fWantTab)
1339 uRet |= SC_WANTTAB;
1340 if (m_dwStyle & ES_WANTRETURN)
1341 uRet |= SC_WANTRETURN;
1342 return uRet;
1343}
1344
1345BOOL SRichEdit::OnScroll(BOOL bVertical, UINT uCode, int nPos)
1346{
1347 if (m_fScrollPending)
1348 return FALSE;
1349 LRESULT lresult = -1;
1350 m_fScrollPending = TRUE;
1351 SPanel::OnScroll(bVertical, uCode, nPos);
1352
1353#ifdef USE_MSFTEDIT
1354 LONG lPos = 0;
1355 if (uCode == SB_THUMBPOSITION)
1356 {
1357 POINT scrollPos;
1358
1359 m_pTxtHost->GetTextService()->TxSendMessage(EM_GETSCROLLPOS, 0, reinterpret_cast<LPARAM>(&scrollPos), NULL);
1360 if (bVertical)
1361 {
1362 scrollPos.y = nPos;
1363 }
1364 else
1365 {
1366 scrollPos.x = nPos;
1367 }
1368
1369 m_pTxtHost->GetTextService()->TxSendMessage(EM_SETSCROLLPOS, 0, reinterpret_cast<LPARAM>(&scrollPos), NULL);
1370 m_pTxtHost->GetTextService()->TxSendMessage(EM_GETSCROLLPOS, 0, reinterpret_cast<LPARAM>(&scrollPos), NULL);
1371
1372 if (bVertical)
1373 {
1374 lPos = scrollPos.y;
1375 }
1376 else
1377 {
1378 lPos = scrollPos.x;
1379 }
1380
1381 if (lPos != GetScrollPos(bVertical))
1382 SetScrollPos(bVertical, lPos, TRUE);
1383 }
1384 else
1385 {
1386 m_pTxtHost->GetTextService()->TxSendMessage(bVertical ? WM_VSCROLL : WM_HSCROLL, MAKEWPARAM(uCode, nPos), 0, &lresult);
1387 if (bVertical)
1388 {
1389 m_pTxtHost->GetTextService()->TxGetVScroll(NULL, NULL, &lPos, NULL, NULL);
1390 }
1391 else
1392 {
1393 m_pTxtHost->GetTextService()->TxGetHScroll(NULL, NULL, &lPos, NULL, NULL);
1394 }
1395
1396 if (lPos != GetScrollPos(bVertical))
1397 SetScrollPos(bVertical, lPos, TRUE);
1398 }
1399#else
1400 m_pTxtHost->GetTextService()->TxSendMessage(bVertical ? WM_VSCROLL : WM_HSCROLL, MAKEWPARAM(uCode, nPos), 0, &lresult);
1401 LONG lPos = 0;
1402 if (bVertical)
1403 {
1404 m_pTxtHost->GetTextService()->TxGetVScroll(NULL, NULL, &lPos, NULL, NULL);
1405 }
1406 else
1407 {
1408 m_pTxtHost->GetTextService()->TxGetHScroll(NULL, NULL, &lPos, NULL, NULL);
1409 }
1410 if (lPos != GetScrollPos(bVertical))
1411 SetScrollPos(bVertical, lPos, TRUE);
1412#endif
1413
1414 m_fScrollPending = FALSE;
1415 if (uCode == SB_THUMBTRACK)
1416 ScrollUpdate();
1417 return lresult == 0;
1418}
1419
1420BOOL SRichEdit::OnSetCursor(const CPoint &pt)
1421{
1422 CRect rcClient;
1423 GetClientRect(&rcClient);
1424 if (!rcClient.PtInRect(pt))
1425 return FALSE;
1426
1427 HDC hdc = GetDC(GetContainer()->GetHostHwnd());
1428 m_pTxtHost->GetTextService()->OnTxSetCursor(DVASPECT_CONTENT, -1, NULL, NULL, hdc, NULL, &rcClient, pt.x, pt.y);
1429 ReleaseDC(GetContainer()->GetHostHwnd(), hdc);
1430 return TRUE;
1431}
1432
1433BOOL SRichEdit::SwndProc(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult)
1434{
1435 BOOL bRet = __baseCls::SwndProc(uMsg, wParam, lParam, lResult);
1436 if (bRet)
1437 return TRUE;
1438 if (m_pTxtHost && m_pTxtHost->GetTextService())
1439 {
1440 if (uMsg == EM_GETRECT)
1441 {
1442 SetMsgHandled(TRUE);
1443 GetClientRect((LPRECT)lParam);
1444 return TRUE;
1445 }
1446 if (m_pTxtHost->GetTextService()->TxSendMessage(uMsg, wParam, lParam, lResult) == S_OK)
1447 {
1448 SetMsgHandled(TRUE);
1449 return TRUE;
1450 }
1451 }
1452 return bRet;
1453}
1454
1455HRESULT SRichEdit::InitDefaultCharFormat(CHARFORMAT2W *pcf, IFontS *pFont)
1456{
1458 GETRENDERFACTORY->CreateRenderTarget(&pRT, 0, 0);
1459 SASSERT(pRT);
1460 BeforePaintEx(pRT);
1461
1462 SAutoRefPtr<IFontS> oldFont;
1463 if (pFont == NULL)
1464 pFont = (IFontS *)pRT->GetCurrentObject(OT_FONT);
1465 SIZE szTxt;
1466 pRT->MeasureText(_T("A"), 1, &szTxt);
1467 m_nFontHeight = szTxt.cy;
1468
1469 memset(pcf, 0, sizeof(CHARFORMAT2W));
1470 pcf->cbSize = sizeof(CHARFORMAT2W);
1471 pcf->dwMask = CFM_SIZE | CFM_OFFSET | CFM_FACE | CFM_CHARSET | CFM_COLOR | CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE;
1472
1473#ifdef _WIN32
1474 pcf->crTextColor = pRT->GetTextColor() & 0x00ffffff;
1475#else
1476 pcf->crTextColor = pRT->GetTextColor();
1477#endif //_WIN32
1478 HDC hdc = GetDC(NULL);
1479 LONG yPixPerInch = GetDeviceCaps(hdc, LOGPIXELSY);
1480 ReleaseDC(NULL, hdc);
1481 const LOGFONT *plf = pFont->LogFont();
1482 pcf->yHeight = abs(MulDiv(pFont->TextSize(), LY_PER_INCH, yPixPerInch));
1483 if (SLayoutSize::defUnit != SLayoutSize::px && IsRichScale())
1484 {
1485 // rich scale 的情况下,edit内部已经对文字进行了放大,不再放大默认字体。
1486 pcf->yHeight /= (GetScale() / 100);
1487 }
1488 pcf->yOffset = 0;
1489 pcf->dwEffects = 0;
1490 if (pFont->IsBold())
1491 pcf->dwEffects |= CFE_BOLD;
1492 if (pFont->IsItalic())
1493 pcf->dwEffects |= CFE_ITALIC;
1494 if (pFont->IsUnderline())
1495 pcf->dwEffects |= CFE_UNDERLINE;
1496 pcf->bCharSet = plf->lfCharSet;
1497 pcf->bPitchAndFamily = plf->lfPitchAndFamily;
1498#ifdef _UNICODE
1499 wcscpy(pcf->szFaceName, plf->lfFaceName);
1500#else
1501 // need to thunk pcf->szFaceName to a standard char string.in this case it's easy because our
1502 // thunk is also our copy
1503 MultiByteToWideChar(CP_ACP, 0, plf->lfFaceName, LF_FACESIZE, pcf->szFaceName, LF_FACESIZE);
1504#endif
1505
1506 return S_OK;
1507}
1508
1509HRESULT SRichEdit::InitDefaultParaFormat(PARAFORMAT2 *ppf)
1510{
1511 memset(ppf, 0, sizeof(PARAFORMAT2));
1512 ppf->cbSize = sizeof(PARAFORMAT2);
1513 ppf->dwMask = PFM_ALL;
1514 ppf->cTabCount = 1;
1515 ppf->rgxTabs[0] = lDefaultTab;
1516
1517 if (m_dwStyle & ES_CENTER)
1518 ppf->wAlignment = PFA_CENTER;
1519 else if (m_dwStyle & ES_RIGHT)
1520 ppf->wAlignment = PFA_RIGHT;
1521 else
1522 ppf->wAlignment = PFA_LEFT;
1523
1524 return S_OK;
1525}
1526
1527HRESULT SRichEdit::OnTxNotify(DWORD iNotify, LPVOID pv)
1528{
1529 EventRENotify evt(this);
1530 evt.iNotify = iNotify;
1531 evt.pv = pv;
1532 evt.hr = S_OK;
1533 FireEvent(evt);
1534 return evt.hr;
1535}
1536//////////////////////////////////////////////////////////////////////////
1537// richedit interfaces
1539{
1540 return m_fWordWrap;
1541}
1542
1543void SRichEdit::SetWordWrap(BOOL fWordWrap)
1544{
1545 m_fWordWrap = fWordWrap;
1546 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(TXTBIT_WORDWRAP, fWordWrap ? TXTBIT_WORDWRAP : 0);
1547}
1548
1550{
1551 return (m_dwStyle & ES_READONLY) != 0;
1552}
1553
1554BOOL SRichEdit::SetReadOnly(BOOL bReadOnly)
1555{
1556 return 0 != SSendMessage(EM_SETREADONLY, bReadOnly);
1557}
1558
1560{
1561 return m_cchTextMost;
1562}
1563
1565{
1566 return 0 != SSendMessage(EM_EXLIMITTEXT, nLength);
1567}
1568
1570{
1571 return m_pfDef.wAlignment;
1572}
1573
1574void SRichEdit::SetDefaultAlign(WORD wNewAlign)
1575{
1576 m_pfDef.wAlignment = wNewAlign;
1577
1578 // Notify control of property change
1579 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(TXTBIT_PARAFORMATCHANGE, 0);
1580}
1581
1583{
1584 return m_fRich;
1585}
1586
1588{
1589 m_fRich = fRich;
1590
1591 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(TXTBIT_RICHTEXT, fRich ? TXTBIT_RICHTEXT : 0);
1592}
1593
1595{
1596 return m_pfDef.dxOffset;
1597}
1598
1600{
1601 m_pfDef.dxOffset = lNewIndent;
1602
1603 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(TXTBIT_PARAFORMATCHANGE, 0);
1604}
1605
1606BOOL SRichEdit::SetSaveSelection(BOOL fSaveSelection)
1607{
1608 BOOL fResult = fSaveSelection;
1609
1610 m_fSaveSelection = fSaveSelection;
1611
1612 // notify text services of property change
1613 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(TXTBIT_SAVESELECTION, m_fSaveSelection ? TXTBIT_SAVESELECTION : 0);
1614
1615 return fResult;
1616}
1617
1618void SRichEdit::OnLButtonDown(UINT nFlags, CPoint point)
1619{
1620 SetCapture();
1621 if (!IsFocused())
1622 {
1623 SetFocus();
1624 if (!m_fAutoSel)
1625 m_pTxtHost->GetTextService()->TxSendMessage(GetCurMsg()->uMsg, GetCurMsg()->wParam, GetCurMsg()->lParam, NULL);
1626 }
1627 else
1628 {
1629 m_pTxtHost->GetTextService()->TxSendMessage(GetCurMsg()->uMsg, GetCurMsg()->wParam, GetCurMsg()->lParam, NULL);
1630 }
1631}
1632
1633void SRichEdit::OnLButtonUp(UINT nFlags, CPoint point)
1634{
1635 m_pTxtHost->GetTextService()->TxSendMessage(GetCurMsg()->uMsg, GetCurMsg()->wParam, GetCurMsg()->lParam, NULL);
1637}
1638
1639LRESULT SRichEdit::OnButtonClick(UINT uMsg, WPARAM wParam, LPARAM lParam)
1640{
1641 m_pTxtHost->GetTextService()->TxSendMessage(uMsg, wParam, lParam, NULL);
1642 return 0;
1643}
1644
1645void SRichEdit::OnRButtonDown(UINT nFlags, CPoint point)
1646{
1647 if (FireCtxMenu(point))
1648 return; //用户自己响应右键
1649 SetFocus();
1650 //弹出默认编辑窗菜单
1652 if (xmlMenu)
1653 {
1654 SMenu menu;
1655 if (menu.LoadMenu2(&xmlMenu))
1656 {
1657 CRect rcCantainer;
1658 GetContainer()->GetContainerRect(&rcCantainer);
1659 point.Offset(rcCantainer.TopLeft());
1660 HWND hHost = GetContainer()->GetHostHwnd();
1661 ::ClientToScreen(hHost, &point);
1662 BOOL canPaste = (BOOL)SSendMessage(EM_CANPASTE, 0);
1663 DWORD dwStart = 0, dwEnd = 0;
1664 SSendMessage(EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
1665 BOOL hasSel = dwStart < dwEnd;
1666 UINT uLen = (UINT)SSendMessage(WM_GETTEXTLENGTH, 0, 0);
1667 BOOL bReadOnly = m_dwStyle & ES_READONLY;
1668 EnableMenuItem(menu.m_hMenu, MENU_CUT, MF_BYCOMMAND | ((hasSel && (!bReadOnly)) ? 0 : MF_GRAYED));
1669 EnableMenuItem(menu.m_hMenu, MENU_COPY, MF_BYCOMMAND | (hasSel ? 0 : MF_GRAYED));
1670 EnableMenuItem(menu.m_hMenu, MENU_PASTE, MF_BYCOMMAND | ((canPaste && (!bReadOnly)) ? 0 : MF_GRAYED));
1671 EnableMenuItem(menu.m_hMenu, MENU_DEL, MF_BYCOMMAND | ((hasSel && (!bReadOnly)) ? 0 : MF_GRAYED));
1672 EnableMenuItem(menu.m_hMenu, MENU_SELALL, MF_BYCOMMAND | ((uLen > 0) ? 0 : MF_GRAYED));
1673
1674 UINT uCmd = menu.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN, point.x, point.y, hHost, NULL, GetScale());
1675
1676 EventREMenu evt(this);
1677 evt.uCmd = uCmd;
1678 FireEvent(evt);
1679 if (evt.handled)
1680 return;
1681
1682 switch (uCmd)
1683 {
1684 case MENU_CUT:
1685 SSendMessage(WM_CUT);
1686 break;
1687 case MENU_COPY:
1688 SSendMessage(WM_COPY);
1689 break;
1690 case MENU_PASTE:
1691 SSendMessage(WM_PASTE);
1692 break;
1693 case MENU_DEL:
1694 SSendMessage(EM_REPLACESEL, 0, (LPARAM) _T(""));
1695 break;
1696 case MENU_SELALL:
1697 SSendMessage(EM_SETSEL, 0, -1);
1698 break;
1699 default:
1700 break;
1701 }
1702 }
1703 }
1704}
1705
1706void SRichEdit::OnMouseMove(UINT nFlags, CPoint point)
1707{
1708 m_pTxtHost->GetTextService()->TxSendMessage(GetCurMsg()->uMsg, GetCurMsg()->wParam, GetCurMsg()->lParam, NULL);
1709}
1710
1711void SRichEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
1712{
1713 EventKeyDown evt(this);
1714 evt.bCancel = FALSE;
1715 evt.nChar = nChar;
1716 evt.nFlags = nFlags;
1717 FireEvent(evt);
1718 if (evt.bCancel)
1719 {
1720 SetMsgHandled(FALSE);
1721 return;
1722 }
1723
1724 if (nChar == VK_RETURN && !(m_dwStyle & ES_WANTRETURN) && !(GetKeyState(VK_CONTROL) & 0x8000))
1725 {
1726 SetMsgHandled(FALSE);
1727 return;
1728 }
1729 m_pTxtHost->GetTextService()->TxSendMessage(GetCurMsg()->uMsg, GetCurMsg()->wParam, GetCurMsg()->lParam, NULL);
1730}
1731
1732#define CTRL(_ch) (_ch - 'A' + 1)
1733
1734void SRichEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
1735{
1736 SWNDMSG msg = *GetCurMsg();
1737 switch (nChar)
1738 {
1739 // Ctrl-Return generates Ctrl-J (LF), treat it as an ordinary return
1740 case CTRL('J'):
1741 case VK_RETURN:
1742 if (!(GetKeyState(VK_CONTROL) & 0x8000) && !(m_dwStyle & ES_WANTRETURN))
1743 return;
1744 break;
1745
1746 case VK_TAB:
1747 if (!m_fWantTab && !(GetKeyState(VK_CONTROL) & 0x8000))
1748 return;
1749 break;
1750 default:
1751 if (m_dwStyle & ES_NUMBER && !isdigit(nChar) && nChar != '-' && nChar != '.' && nChar != ',')
1752 return;
1753 if ((m_dwStyle & ES_UPPERCASE) && nChar >= 'a' && nChar <= 'z')
1754 {
1755 nChar -= 0x20;
1756 msg.wParam = nChar;
1757 break;
1758 }
1759 if ((m_dwStyle & ES_LOWERCASE) && nChar >= 'A' && nChar <= 'Z')
1760 {
1761 nChar += 0x20;
1762 msg.wParam = nChar;
1763 break;
1764 }
1765#ifndef _UNICODE
1766 // todo:hjx
1767 if (m_byDbcsLeadByte == 0)
1768 {
1769 if (IsDBCSLeadByte(nChar))
1770 {
1771 m_byDbcsLeadByte = nChar;
1772 return;
1773 }
1774 }
1775 else
1776 {
1777 nChar = MAKEWORD(nChar, m_byDbcsLeadByte);
1778 m_pTxtHost->GetTextService()->TxSendMessage(WM_IME_CHAR, nChar, 0, NULL);
1779 m_byDbcsLeadByte = 0;
1780 return;
1781 }
1782#endif //_UNICODE
1783 break;
1784 }
1785 m_pTxtHost->GetTextService()->TxSendMessage(msg.uMsg, msg.wParam, msg.lParam, NULL);
1786}
1787
1788LRESULT SRichEdit::OnNcCalcSize(BOOL bCalcValidRects, LPARAM lParam)
1789{
1790 __baseCls::OnNcCalcSize(bCalcValidRects, lParam);
1791
1792 CRect rcInsetPixel = GetStyle().GetPadding();
1793
1794 if (!IsRichScale())
1795 {
1796 rcInsetPixel.top = rcInsetPixel.bottom = (m_rcClient.Height() - m_nFontHeight) / 2;
1797 }
1798
1799 m_siHoz.nPage = m_rcClient.Width() - rcInsetPixel.left - rcInsetPixel.right;
1800 m_siVer.nPage = m_rcClient.Height() - rcInsetPixel.top - rcInsetPixel.bottom;
1801
1802 if (m_pTxtHost)
1803 {
1804 HDC hdc = GetDC(GetContainer()->GetHostHwnd());
1805 LONG xPerInch = ::GetDeviceCaps(hdc, LOGPIXELSX);
1806 LONG yPerInch = ::GetDeviceCaps(hdc, LOGPIXELSY);
1807 ReleaseDC(GetContainer()->GetHostHwnd(), hdc);
1808
1809 m_sizelExtent.cx = DtoHimetric(m_rcClient.Width(), xPerInch);
1810 m_sizelExtent.cy = DtoHimetric(m_rcClient.Height(), yPerInch);
1811
1812 m_rcInset.left = DtoHimetric(rcInsetPixel.left, xPerInch);
1813 m_rcInset.right = DtoHimetric(rcInsetPixel.right, xPerInch);
1814 m_rcInset.top = DtoHimetric(rcInsetPixel.top, yPerInch);
1815 m_rcInset.bottom = DtoHimetric(rcInsetPixel.bottom, yPerInch);
1816
1817 //窗口有焦点时,需要更新光标位置:先使edit失活用来关闭光标,再激活edit来显示光标。
1818 //此处不应该直接用setfocus和killfocus,因为这两个消息可能会被外面响应。导致逻辑错误
1819 BOOL bFocus = IsFocused();
1820 if (bFocus)
1821 {
1822 m_pTxtHost->m_fUiActive = FALSE;
1823 m_pTxtHost->GetTextService()->OnTxUIDeactivate();
1824 m_pTxtHost->GetTextService()->TxSendMessage(WM_KILLFOCUS, 0, 0, NULL);
1825 m_pTxtHost->TxShowCaret(FALSE);
1826 }
1827 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(TXTBIT_EXTENTCHANGE | TXTBIT_CLIENTRECTCHANGE, TXTBIT_EXTENTCHANGE | TXTBIT_CLIENTRECTCHANGE);
1828 if (bFocus)
1829 {
1830 m_pTxtHost->m_fUiActive = TRUE;
1831 m_pTxtHost->GetTextService()->OnTxUIActivate();
1832 m_pTxtHost->GetTextService()->TxSendMessage(WM_SETFOCUS, 0, 0, NULL);
1833 }
1834 }
1835 return 0;
1836}
1837
1838LRESULT SRichEdit::OnSetReadOnly(UINT uMsg, WPARAM wParam, LPARAM lParam)
1839{
1840 return SUCCEEDED(SetAttribute(L"readonly", wParam ? L"1" : L"0"));
1841}
1842
1843LRESULT SRichEdit::OnSetLimitText(UINT uMsg, WPARAM wParam, LPARAM lParam)
1844{
1845 if (wParam == 0)
1846 m_cchTextMost = cInitTextMax;
1847 else
1848 m_cchTextMost = (DWORD)wParam;
1849 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(TXTBIT_MAXLENGTHCHANGE, TXTBIT_MAXLENGTHCHANGE);
1850 return 1;
1851}
1852
1853LRESULT SRichEdit::OnSetCharFormat(UINT uMsg, WPARAM wParam, LPARAM lParam)
1854{
1855 if (wParam == SCF_DEFAULT && !FValidCF((CHARFORMAT2W *)lParam))
1856 { //设置默认字体只支持CHARFORMAT2W
1857 SSLOGI() << "set default char format failed! only CHARFORMAT2W can be set for default char format";
1858 return 0;
1859 }
1860
1861 m_pTxtHost->GetTextService()->TxSendMessage(uMsg, wParam, lParam, NULL);
1862 if (wParam == SCF_DEFAULT)
1863 {
1864 m_cfDef = *(CHARFORMAT2W *)lParam;
1865 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(TXTBIT_CHARFORMATCHANGE, TXTBIT_CHARFORMATCHANGE);
1866 }
1867 return 1;
1868}
1869
1870LRESULT SRichEdit::OnSetParaFormat(UINT uMsg, WPARAM wparam, LPARAM lparam)
1871{
1872 if (!FValidPF((PARAFORMAT *)lparam))
1873 {
1874 return 0;
1875 }
1876
1877 // check to see if we're setting the default.
1878 // either SCF_DEFAULT will be specified *or* there is no
1879 // no text in the document (richedit1.0 behaviour).
1880 if (!(wparam & SCF_DEFAULT))
1881 {
1882 HRESULT hr = m_pTxtHost->GetTextService()->TxSendMessage(WM_GETTEXTLENGTH, 0, 0, 0);
1883
1884 if (hr == 0)
1885 {
1886 wparam |= SCF_DEFAULT;
1887 }
1888 }
1889
1890 if (wparam & SCF_DEFAULT)
1891 {
1892 m_pfDef = *(PARAFORMAT2 *)lparam;
1893 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(TXTBIT_PARAFORMATCHANGE, TXTBIT_PARAFORMATCHANGE);
1894 }
1895 else
1896 {
1897 m_pTxtHost->GetTextService()->TxSendMessage(uMsg, wparam, lparam,
1898 NULL); // Change selection format
1899 }
1900 return 1;
1901}
1902
1903LRESULT SRichEdit::OnSetText(UINT uMsg, WPARAM wparam, LPARAM lparam)
1904{
1905 // For RichEdit 1.0, the max text length would be reset by a settext so
1906 // we follow pattern here as well.
1907
1908 HRESULT hr = m_pTxtHost->GetTextService()->TxSendMessage(uMsg, wparam, lparam, 0);
1909
1910 if (FAILED(hr))
1911 return 0;
1912 // Update succeeded.
1913 ULONG cNewText = (ULONG)(lparam ? _tcslen((LPCTSTR)lparam) : 0);
1914
1915 // If the new text is greater than the max set the max to the new
1916 // text length.
1917 if (cNewText > m_cchTextMost)
1918 {
1919 m_cchTextMost = cNewText;
1920 }
1921 return 1;
1922}
1923
1924void SRichEdit::OnSetFont(IFontS *pFont, BOOL bRedraw)
1925{
1926 if (SUCCEEDED(InitDefaultCharFormat(&m_cfDef, pFont)))
1927 {
1928 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(TXTBIT_CHARFORMATCHANGE, TXTBIT_CHARFORMATCHANGE);
1929 }
1930}
1931
1932void SRichEdit::SetWindowText(LPCTSTR lpszText)
1933{
1934#ifdef _UNICODE
1935 SSendMessage(WM_SETTEXT, 0, (LPARAM)lpszText);
1936#else
1937 SStringW str = S_CT2W(lpszText);
1938 SSendMessage(WM_SETTEXT, 0, (LPARAM)(LPCWSTR)str);
1939#endif
1940 if (IsRichScale())
1941 {
1942 // setwindowtext会导致zoom丢失,需要重新设置。
1943 SSendMessage(EM_SETZOOM, GetScale(), 100);
1944 }
1945 Invalidate();
1946}
1947
1948int SRichEdit::GetWindowText(THIS_ TCHAR *pBuf, int nBufLen, BOOL bRawText)
1949{
1950 if (!pBuf)
1951 {
1952 return GetWindowTextLength();
1953 }
1954 SStringT str = GetWindowText(bRawText);
1955 if (nBufLen < str.GetLength())
1956 return 0;
1957 else if (nBufLen == str.GetLength())
1958 _tcsncpy(pBuf, str.c_str(), str.GetLength());
1959 else // if(nBufLen > str.GetLength())
1960 _tcscpy(pBuf, str.c_str()); // auto append null char
1961 return str.GetLength();
1962}
1963
1964SStringT SRichEdit::GetWindowText(BOOL bRawText)
1965{
1966 (bRawText);
1967 SStringW strRet;
1968 int nLen = GetWindowTextLength();
1969 wchar_t *pBuf = strRet.GetBufferSetLength(nLen);
1970 SSendMessage(WM_GETTEXT, (WPARAM)nLen + 1, (LPARAM)pBuf);
1971 strRet.ReleaseBuffer();
1972 return S_CW2T(strRet);
1973}
1974
1976{
1977 LRESULT lResult = 0;
1978 if (m_pTxtHost)
1979 {
1980 m_pTxtHost->GetTextService()->TxSendMessage(WM_GETTEXTLENGTH, 0, 0, &lResult);
1981 }
1982 return (int)lResult;
1983}
1984
1985void SRichEdit::ReplaceSel(LPCTSTR pszText, BOOL bCanUndo)
1986{
1987#ifdef _UNICODE
1988 SSendMessage(EM_REPLACESEL, (WPARAM)bCanUndo, (LPARAM)pszText);
1989#else
1990 SStringW str = S_CT2W(pszText);
1991 SSendMessage(EM_REPLACESEL, (WPARAM)bCanUndo, (LPARAM)str.c_str());
1992#endif
1993}
1994
1995void SRichEdit::SetSel(DWORD dwSelection, BOOL bNoScroll)
1996{
1997 SSendMessage(EM_SETSEL, LOWORD(dwSelection), HIWORD(dwSelection));
1998 if (!bNoScroll)
1999 SSendMessage(EM_SCROLLCARET, 0, 0L);
2000}
2001
2002void SRichEdit::SetSel(long nStartChar, long nEndChar, BOOL bNoScroll)
2003{
2004 SSendMessage(EM_SETSEL, nStartChar, nEndChar);
2005 if (!bNoScroll)
2006 SSendMessage(EM_SCROLLCARET, 0, 0L);
2007}
2008
2009HRESULT SRichEdit::OnAttrTextColor(const SStringW &strValue, BOOL bLoading)
2010{
2011 m_style.SetTextColor(0, GETCOLOR(strValue));
2012 if (!bLoading)
2013 {
2014 SetDefaultTextColor(m_style.GetTextColor(0));
2015 }
2016 return S_OK;
2017}
2018
2019DWORD CALLBACK EditStreamInCallback_FILE(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
2020{
2021 FILE *f = (FILE *)dwCookie;
2022 LONG nReaded = (LONG)fread(pbBuff, 1, cb, f);
2023 if (pcb)
2024 *pcb = nReaded;
2025 return 0;
2026}
2027
2028DWORD CALLBACK EditStreamOutCallback_FILE(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
2029{
2030 FILE *f = (FILE *)dwCookie;
2031 LONG nWrited = (LONG)fwrite(pbBuff, 1, cb, f);
2032 if (pcb)
2033 *pcb = nWrited;
2034 return 0;
2035}
2036
2037struct MemBlock
2038{
2039 LPBYTE pBuf;
2040 LONG nRemains;
2041};
2042
2043DWORD CALLBACK EditStreamInCallback_MemBlock(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
2044{
2045 MemBlock *pmb = (MemBlock *)dwCookie;
2046 if (pmb->nRemains >= cb)
2047 {
2048 memcpy(pbBuff, pmb->pBuf, cb);
2049 pmb->pBuf += cb;
2050 pmb->nRemains -= cb;
2051 if (pcb)
2052 *pcb = cb;
2053 return 0;
2054 }
2055 else
2056 {
2057 memcpy(pbBuff, pmb->pBuf, pmb->nRemains);
2058 pmb->pBuf += pmb->nRemains;
2059 if (pcb)
2060 *pcb = pmb->nRemains;
2061 pmb->nRemains = 0;
2062 return 0;
2063 }
2064}
2065
2066HRESULT SRichEdit::OnAttrRTF(const SStringW &strValue, BOOL bLoading)
2067{
2068 if (bLoading)
2069 {
2070 m_strRtfSrc = strValue; //将数据保存到控件初始化完成再写入控件
2071 return S_FALSE;
2072 }
2073 else
2074 {
2075 SStringTList lstSrc;
2076 int nSegs = ParseResID(S_CW2T(strValue), lstSrc);
2077 LPCTSTR pszType = NULL;
2078 LPCTSTR pszName = NULL;
2079 if (lstSrc.GetCount() == 2)
2080 {
2081 pszType = lstSrc[0];
2082 pszName = lstSrc[1];
2083 }
2084 else
2085 {
2086 pszName = lstSrc[0];
2087 }
2088 size_t dwSize = GETRESPROVIDER->GetRawBufferSize(pszType, pszName);
2089 if (dwSize)
2090 {
2091 EDITSTREAM es;
2092 MemBlock mb = { NULL, 0 };
2093 SAutoBuf mybuf;
2094 mb.pBuf = (LPBYTE)mybuf.Allocate(dwSize);
2095 mb.nRemains = (DWORD)dwSize;
2096 GETRESPROVIDER->GetRawBuffer(pszType, pszName, mybuf, dwSize);
2097 es.dwCookie = (DWORD_PTR)&mb;
2098 es.pfnCallback = EditStreamInCallback_MemBlock;
2099 SSendMessage(EM_STREAMIN, SF_RTF, (LPARAM)&es);
2100 }
2101 return S_FALSE;
2102 }
2103}
2104
2106{
2107 COLORREF crOld = m_cfDef.crTextColor;
2108#ifdef _WIN32
2109 m_cfDef.crTextColor = cr & 0x00ffffff;
2110#else
2111 m_cfDef.crTextColor = cr;
2112#endif //_WIN32
2113 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(TXTBIT_CHARFORMATCHANGE, TXTBIT_CHARFORMATCHANGE);
2114 return crOld;
2115}
2116
2118{
2119 if (bEnable)
2120 {
2121 SRicheditDropTarget *pDropTarget = new SRicheditDropTarget(m_pTxtHost->GetTextService());
2122 GetContainer()->RegisterDragDrop(m_swnd, pDropTarget);
2123 pDropTarget->Release();
2124 }
2125 else
2126 {
2128 }
2129}
2130
2131HRESULT SRichEdit::OnAttrAlign(const SStringW &strValue, BOOL bLoading)
2132{
2133 if (!strValue.CompareNoCase(L"center"))
2134 m_dwStyle |= ES_CENTER;
2135 else if (!strValue.CompareNoCase(L"right"))
2136 m_dwStyle |= ES_RIGHT;
2137 else
2138 m_dwStyle |= ES_LEFT;
2139 if (!bLoading)
2140 {
2141 if (m_dwStyle & ES_CENTER)
2142 m_pfDef.wAlignment = PFA_CENTER;
2143 else if (m_dwStyle & ES_RIGHT)
2144 m_pfDef.wAlignment = PFA_RIGHT;
2145 else
2146 m_pfDef.wAlignment = PFA_LEFT;
2147 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(TXTBIT_PARAFORMATCHANGE, 0);
2148 }
2149 return bLoading ? S_FALSE : S_OK;
2150}
2151
2152HRESULT SRichEdit::OnAttrNotifyChange(const SStringW &strValue, BOOL bLoading)
2153{
2154 m_fNotifyChange = STRINGASBOOL(strValue);
2155 if (!bLoading)
2156 {
2157 LPARAM lEvtMask = SSendMessage(EM_GETEVENTMASK);
2158 if (m_fNotifyChange)
2159 lEvtMask |= ENM_CHANGE;
2160 else
2161 lEvtMask &= ~ENM_CHANGE;
2162 SSendMessage(EM_SETEVENTMASK, 0, lEvtMask);
2163 }
2164 return S_FALSE;
2165}
2166
2167DWORD SRichEdit::SaveRtf(LPCTSTR pszFileName)
2168{
2169 FILE *f = _tfopen(pszFileName, _T("wb"));
2170 if (!f)
2171 return 0;
2172 EDITSTREAM es;
2173 es.dwCookie = (DWORD_PTR)f;
2174 es.pfnCallback = EditStreamOutCallback_FILE;
2175 DWORD dwRet = (DWORD)SSendMessage(EM_STREAMOUT, SF_RTF, (LPARAM)&es);
2176 fclose(f);
2177 return dwRet;
2178}
2179
2180DWORD SRichEdit::LoadRtf(LPCTSTR pszFileName)
2181{
2182 FILE *f = _tfopen(pszFileName, _T("rb"));
2183 if (!f)
2184 return FALSE;
2185 EDITSTREAM es;
2186 es.dwCookie = (DWORD_PTR)f;
2187 es.pfnCallback = EditStreamInCallback_FILE;
2188 DWORD dwRet = (DWORD)SSendMessage(EM_STREAMIN, SF_RTF, (LPARAM)&es);
2189 fclose(f);
2190 return dwRet;
2191}
2192
2194{
2195 __baseCls::OnScaleChanged(nScale);
2196 if (IsRichScale())
2197 {
2198 SSendMessage(EM_SETZOOM, nScale, 100);
2199 }
2200 else
2201 { //单行居中的放大,做特殊处理
2202 OnSetFont(NULL, FALSE);
2203 }
2204}
2205
2207{
2208 __baseCls::OnRebuildFont();
2209 OnSetFont(NULL, FALSE); //更新默认字体
2210}
2211
2212void SRichEdit::OnEnable(BOOL bEnable, UINT nStatus)
2213{
2214 __baseCls::OnEnable(bEnable, nStatus);
2215 COLORREF cr;
2216 if (bEnable)
2217 {
2218 cr = m_style.GetTextColor(0);
2219 if (CR_INVALID == cr)
2220 cr = 0;
2221 }
2222 else
2223 {
2224 cr = m_style.GetTextColor(3);
2225 }
2226
2227 if (CR_INVALID != cr)
2229}
2230
2231BOOL SRichEdit::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
2232{
2233 if (!(m_dwStyle & ES_MULTILINE))
2234 {
2235 return SWindow::OnMouseWheel(nFlags, zDelta, pt);
2236 }
2237 else
2238 {
2239 PSWNDMSG p = GetCurMsg();
2240 LRESULT lResult = 0;
2241 return m_pTxtHost->GetTextService()->TxSendMessage(p->uMsg, p->wParam, p->lParam, &lResult) == S_OK;
2242 }
2243}
2244
2245BOOL SRichEdit::CreateCaret(HBITMAP pBmp, int nWid, int nHeight)
2246{
2247 if (m_fDisableCaret)
2248 return FALSE;
2249 return SWindow::CreateCaret(pBmp, nWid, nHeight);
2250}
2251
2252HRESULT SRichEdit::OnAttrReStyle(const SStringW &strValue, DWORD dwStyle, DWORD txtBit, BOOL bLoading)
2253{
2254 BOOL bValue = STRINGASBOOL(strValue);
2255 DWORD dwBit = 0;
2256 if (!bValue)
2257 m_dwStyle &= ~dwStyle;
2258 else
2259 m_dwStyle |= dwStyle, dwBit = txtBit;
2260 if (!bLoading && txtBit != 0)
2261 {
2262 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(txtBit, dwBit);
2263 }
2264 return bLoading ? S_FALSE : S_OK;
2265}
2266
2267HRESULT SRichEdit::OnAttrReStyle2(const SStringW &strValue, DWORD dwStyle, DWORD txtBit, BOOL bLoading)
2268{
2269 BOOL bValue = STRINGASBOOL(strValue);
2270 if (!bValue)
2271 m_dwStyle &= ~dwStyle;
2272 else
2273 m_dwStyle |= dwStyle;
2274 if (!bLoading && txtBit != 0)
2275 {
2276 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(txtBit, txtBit);
2277 }
2278 return bLoading ? S_FALSE : S_OK;
2279}
2280
2281HRESULT SRichEdit::OnAttrPasswordChar(const SStringW &strValue, BOOL bLoading)
2282{
2283 SStringT strValueT = S_CW2T(strValue);
2284 m_chPasswordChar = strValueT[0];
2285 return bLoading ? S_FALSE : S_OK;
2286}
2287
2288HRESULT SRichEdit::OnAttrEnableDragdrop(const SStringW &strValue, BOOL bLoading)
2289{
2290 m_fEnableDragDrop = STRINGASBOOL(strValue);
2291 if (!bLoading)
2292 {
2293 OnEnableDragDrop(!(m_dwStyle & ES_READONLY) & m_fEnableDragDrop);
2294 }
2295 return S_FALSE;
2296}
2297
2298LRESULT SRichEdit::OnGetRect(UINT uMsg, WPARAM wp, LPARAM lp)
2299{
2300 GetClientRect((LPRECT)lp);
2301 return TRUE;
2302}
2303
2304BOOL SRichEdit::OnTxSetTimer(UINT idTimer, UINT uTimeout)
2305{
2306 SMap<UINT, SAutoRefPtr<ITimer>>::CPair *p = m_mapTimer.Lookup(idTimer);
2307 if (p)
2308 {
2309 p->m_value->KillTimer();
2310 p->m_value->StartTimer(uTimeout, TRUE, idTimer);
2311 return TRUE;
2312 }
2314 STimer *timer = new STimer(&slot);
2315 timer->StartTimer(uTimeout, TRUE, idTimer);
2316 m_mapTimer[idTimer] = timer;
2317 timer->Release();
2318
2319 return TRUE;
2320}
2321
2323{
2324 m_mapTimer.RemoveKey(idTimer);
2325}
2326
2327BOOL SRichEdit::OnTimeout(IEvtArgs *e)
2328{
2329 EventTimer *e2 = sobj_cast<EventTimer>(e);
2330 m_pTxtHost->GetTextService()->TxSendMessage(WM_TIMER, e2->uData, 0, NULL);
2331 return TRUE;
2332}
2333
2335{
2336 return m_fRich || !m_fSingleLineVCenter || (m_dwStyle & ES_MULTILINE);
2337}
2338
2339SNSEND
Header file for the SAutoBuf class, a smart buffer management class.
通过类成员函数回调的槽函数类模板
Definition SEventSlot.h:168
SXmlNode GetEditCtxMenuTemplate() const
Get the edit context menu template XML node.
Definition SApp.cpp:823
A smart buffer management class that automatically handles memory allocation and deallocation.
Definition SAutoBuf.h:18
char * Allocate(size_t nElements)
Allocates a buffer of the specified size. If a buffer is already allocated, it will be freed first.
Definition SAutoBuf.cpp:40
Smart pointer class for managing COM-style reference-counted objects.
The SMatrix class holds a 3x3 matrix for transforming coordinates. SMatrix does not have a constructo...
Definition SMatrix.h:22
BOOL isIdentity() SCONST OVERRIDE
Checks if the matrix is the identity matrix.
Definition SMatrix.cpp:1777
菜单类
Definition SMenu.h:399
BOOL LoadMenu2(IXmlNode *xmlMenu) OVERRIDE
加载菜单资源(XML)
Definition SMenu.cpp:309
UINT TrackPopupMenu(UINT uFlags, int x, int y, HWND hWnd, LPCRECT prcRect=NULL, int nScale=100) OVERRIDE
跟踪弹出菜单
Definition SMenu.cpp:416
virtual CRect GetClientRect() const
Gets the client rectangle.
Definition SPanel.cpp:368
virtual BOOL OnScroll(BOOL bVertical, UINT uCode, int nPos)
Handles scroll events.
Definition SPanel.cpp:517
CRect GetScrollBarRect(BOOL bVert) SCONST OVERRIDE
Gets the rectangle of a scrollbar.
Definition SPanel.cpp:11
void ScrollUpdate()
Updates the scrollbar.
Definition SPanel.cpp:579
LONG m_lAccelPos
Definition SRichEdit.h:668
UINT m_fSingleLineVCenter
Definition SRichEdit.h:682
HRESULT OnAttrTextColor(const SStringW &strValue, BOOL bLoading)
Set text color attribute.
UINT m_fSaveSelection
Definition SRichEdit.h:677
BOOL SetSaveSelection(BOOL fSaveSelection) OVERRIDE
Set the save selection flag.
SStringW m_strRtfSrc
Definition SRichEdit.h:690
UINT m_fDisableCaret
Definition SRichEdit.h:688
LRESULT OnSetParaFormat(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handle set paragraph format message.
SRichEdit()
Constructor.
void SetWordWrap(BOOL fWordWrap) OVERRIDE
Set the word wrap setting.
void SetWindowText(LPCTSTR lpszText) OVERRIDE
Set the window text.
BOOL OnTxSetScrollPos(INT fnBar, INT nPos, BOOL fRedraw)
Handle set scroll position message.
void SetDefaultAlign(WORD wNewAlign) OVERRIDE
Set the default text alignment.
BOOL SwndProc(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult) OVERRIDE
Process window messages.
UINT m_fScrollPending
Definition SRichEdit.h:684
UINT m_fEnableAutoWordSel
Definition SRichEdit.h:674
HRESULT OnAttrReStyle2(const SStringW &strValue, DWORD dwStyle, DWORD txtBit, BOOL bLoading)
Handle the restyle attribute (variant)
UINT m_fEnableDragDrop
Definition SRichEdit.h:685
PARAFORMAT2 m_pfDef
Definition SRichEdit.h:665
void OnRButtonDown(UINT nFlags, CPoint point)
Handle right button down message.
void OnTxKillTimer(UINT idTimer)
Handle kill timer message.
void OnTimer(char idEvent)
Handle timer message.
UINT m_fTransparent
Definition SRichEdit.h:678
LRESULT OnButtonClick(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handle button click message.
UINT m_fNotifyChange
Definition SRichEdit.h:687
void SetDefaultLeftIndent(LONG lNewIndent) OVERRIDE
Set the default left indent.
UINT m_fRich
Definition SRichEdit.h:676
int m_nFontHeight
Definition SRichEdit.h:671
LRESULT OnNcCalcSize(BOOL bCalcValidRects, LPARAM lParam)
Handle non-client calculate size message.
HRESULT OnAttrNotifyChange(const SStringW &strValue, BOOL bLoading)
Handle the notify change attribute.
UINT m_fAutoSel
Definition SRichEdit.h:686
void OnDestroy()
Handle destruction of the control.
virtual void OnScaleChanged(int nScale)
Handle scale change message.
DWORD m_cchTextMost
Definition SRichEdit.h:666
LRESULT OnSetCharFormat(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handle set character format message.
SIZEL m_sizelExtent
Definition SRichEdit.h:669
BOOL SetLimitText(int nLength) OVERRIDE
Set the maximum text length.
virtual HRESULT SetAttribute(const SNS::SStringW &amp;amp;amp;amp;strAttribName, const SNS::SStringW &amp;amp;amp;amp;strValue, BOOL bLoading=FALSE)
Begin the attribute map for the SRichEdit class.
Definition SRichEdit.h:631
virtual HRESULT OnTxNotify(DWORD iNotify, LPVOID pv)
Handle text notification.
virtual UINT WINAPI OnGetDlgCode() const
Get dialog code.
BYTE m_byDbcsLeadByte
Definition SRichEdit.h:689
BOOL OnTimeout(IEvtArgs *e)
Handle timer timeout message.
HRESULT InitDefaultCharFormat(CHARFORMAT2W *pcf, IFontS *pFont=NULL)
Initialize default character format.
virtual void OnRebuildFont()
Handle rebuild font message.
void OnSetFont(IFontS *font, BOOL bRedraw)
Handle set font message.
void OnLButtonUp(UINT nFlags, CPoint point)
Handle left button up message.
LONG GetDefaultLeftIndent() SCONST OVERRIDE
Get the default left indent.
TCHAR m_chPasswordChar
Definition SRichEdit.h:667
HRESULT InitDefaultParaFormat(PARAFORMAT2 *ppf)
Initialize default paragraph format.
DWORD SaveRtf(LPCTSTR pszFileName) OVERRIDE
Save content to an RTF file.
BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
Handle mouse wheel message.
UINT m_fAllowBeep
Definition SRichEdit.h:680
UINT m_fVertical
Definition SRichEdit.h:679
void ReplaceSel(LPCTSTR pszText, BOOL bCanUndo=TRUE) OVERRIDE
Replace the selected text.
BOOL OnTxSetTimer(UINT idTimer, UINT uTimeout)
Handle set timer message.
int OnCreate(LPVOID lpCreateStruct)
Handle creation of the control.
LRESULT OnSetLimitText(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handle set limit text message.
void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
Handle character message.
CHARFORMAT2W m_cfDef
Definition SRichEdit.h:664
LRESULT OnSetText(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handle set text message.
COLORREF SetDefaultTextColor(COLORREF cr) OVERRIDE
Set the default text color.
void OnLButtonDown(UINT nFlags, CPoint point)
Handle left button down message.
void OnSetFocus(SWND wndOld)
Handle set focus message.
BOOL GetReadOnly() SCONST OVERRIDE
Check if the control is read-only.
virtual BOOL OnSetCursor(const CPoint &pt)
Handle set cursor message.
BOOL IsRichScale() const
Check if rich text scaling is enabled.
HRESULT OnAttrReStyle(const SStringW &strValue, DWORD dwStyle, DWORD txtBit, BOOL bLoading)
Handle the restyle attribute.
void OnEnableDragDrop(BOOL bEnable)
Enable or disable drag-and-drop.
STextHost * m_pTxtHost
Definition SRichEdit.h:691
virtual BOOL OnScroll(BOOL bVertical, UINT uCode, int nPos)
Handle scroll message.
void SetRichTextFlag(BOOL fRich) OVERRIDE
Set the rich text flag.
void SetSel(long nStartChar, long nEndChar, BOOL bNoScroll) OVERRIDE
Set the selection range.
BOOL SetReadOnly(BOOL bReadOnly) OVERRIDE
Set the read-only state.
WORD GetDefaultAlign() SCONST OVERRIDE
Get the default text alignment.
BOOL GetRichTextFlag() SCONST OVERRIDE
Get the rich text flag.
int GetWindowTextLength() const
Get the length of the window text.
CRect m_rcInset
Definition SRichEdit.h:670
void OnEnable(BOOL bEnable, UINT nStatus)
Handle enable message.
LONG GetLimitText() SCONST OVERRIDE
Get the maximum text length.
BOOL GetWordWrap() SCONST OVERRIDE
Get the word wrap setting.
void OnPaint(IRenderTarget *pRT)
Handle paint message.
HRESULT OnAttrEnableDragdrop(const SStringW &strValue, BOOL bLoading)
Handle the enable dragdrop attribute.
DWORD LoadRtf(LPCTSTR pszFileName) OVERRIDE
Load content from an RTF file.
LRESULT OnGetRect(UINT uMsg, WPARAM wp, LPARAM lp)
Handle get rectangle message.
UINT m_fWantTab
Definition SRichEdit.h:681
HRESULT OnAttrRTF(const SStringW &strValue, BOOL bLoading)
Set RTF attribute.
void OnKillFocus(SWND wndFocus)
Handle kill focus message.
BOOL CreateCaret(HBITMAP pBmp, int nWid, int nHeight) OVERRIDE
Create a caret.
HRESULT OnAttrAlign(const SStringW &strValue, BOOL bLoading)
Set alignment attribute.
UINT m_fWordWrap
Definition SRichEdit.h:675
SMap< UINT, SAutoRefPtr< ITimer > > m_mapTimer
Definition SRichEdit.h:692
void OnMouseMove(UINT nFlags, CPoint point)
Handle mouse move message.
HRESULT OnAttrPasswordChar(const SStringW &strValue, BOOL bLoading)
Handle the password character attribute.
int GetWindowText(TCHAR *pBuf, int nBufLen, BOOL bRawText) OVERRIDE
Get the window text.
void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
Handle key down message.
LRESULT OnSetReadOnly(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handle set read-only message.
static SApplication * getSingletonPtr(void)
Definition SSingleton.h:73
A class representing an ASCII string.
Definition sstringw.h:96
int CompareNoCase(const wchar_t *psz) SCONST
Compares the string with another string, ignoring case.
Definition sstringw.cpp:929
void ReleaseBuffer(int nNewLength=-1)
Releases the buffer and sets the new length of the string.
Definition sstringw.cpp:426
const wchar_t * c_str() SCONST
Retrieves a C-style string representation of the string.
wchar_t * GetBufferSetLength(int nNewLength)
Retrieves a modifiable buffer for the string and sets the new length.
Definition sstringw.cpp:414
STextHost(void)
构造函数
ITextServices * pserv
virtual void TxImmReleaseContext(HIMC himc)
virtual HRESULT TxGetAcceleratorPos(LONG *pcp)
Get the accelerator character.
virtual void TxSetFocus()
Set the focus to the text window.
SRichEdit * m_pRichEdit
virtual HRESULT TxGetViewInset(LPRECT prc)
Get the view rectangle relative to the inset.
virtual HDC TxGetDC()
Get the DC for the host.
virtual HRESULT TxActivate(LONG *plOldState)
Request host to activate text services.
virtual HRESULT OnTxCharFormatChange(const CHARFORMATW *pcf)
Notify host that default character format has changed.
virtual HRESULT OnTxParaFormatChange(const PARAFORMAT *ppf)
Notify host that default paragraph format has changed.
virtual void TxScrollWindowEx(INT dx, INT dy, LPCRECT lprcScroll, LPCRECT lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate, UINT fuScroll)
Scroll the content of the specified window's client area.
virtual void TxKillTimer(UINT idTimer)
Destroy a timer.
virtual COLORREF TxGetSysColor(int nIndex)
Get the background color for the window.
virtual BOOL TxScreenToClient(LPPOINT lppt)
Converts screen coordinates of a specified point to the client coordinates.
virtual HRESULT TxGetClientRect(LPRECT prc)
Retrieves the coordinates of a window's client area.
virtual BOOL TxCreateCaret(HBITMAP hbmp, INT xWidth, INT yHeight)
Create the caret.
virtual HRESULT TxGetPropertyBits(DWORD dwMask, DWORD *pdwBits)
Bulk access to bit properties.
virtual void TxViewChange(BOOL fUpdate)
Send a WM_PAINT to the window.
virtual BOOL TxSetCaretPos(INT x, INT y)
Set the caret position.
virtual HRESULT TxGetCharFormat(const CHARFORMATW **ppCF)
Get the default character format for the text.
virtual BOOL TxClientToScreen(LPPOINT lppt)
Converts the client coordinates of a specified point to screen coordinates.
virtual BOOL TxSetScrollRange(INT fnBar, LONG nMinPos, INT nMaxPos, BOOL fRedraw)
Set the scroll range.
virtual void TxSetCapture(BOOL fCapture)
Get mouse capture.
virtual BOOL TxSetTimer(UINT idTimer, UINT uTimeout)
Create a timer with the specified timeout.
virtual BOOL TxEnableScrollBar(INT fuSBFlags, INT fuArrowflags)
Enable the scroll bar.
BOOL m_fUiActive
virtual BOOL TxShowScrollBar(INT fnBar, BOOL fShow)
Show the scroll bar.
virtual void TxInvalidateRect(LPCRECT prc, BOOL fMode)
InvalidateRect.
virtual HRESULT TxDeactivate(LONG lNewState)
Request host to deactivate text services.
virtual BOOL TxShowCaret(BOOL fShow)
Show the caret.
~STextHost(void)
析构函数
BOOL Init(SRichEdit *pRichEdit)
初始化函数
virtual INT TxReleaseDC(HDC hdc)
Release the DC gotten from the host.
virtual void TxSetCursor(HCURSOR hcur, BOOL fText)
Establish a new cursor shape.
virtual HRESULT TxGetParaFormat(const PARAFORMAT **ppPF)
Get the default paragraph format for the text.
virtual HIMC TxImmGetContext()
virtual HRESULT TxNotify(DWORD iNotify, void *pv)
Notify host of events.
virtual HRESULT TxGetBackStyle(TXTBACKSTYLE *pstyle)
Get the background (either opaque or transparent)
ITextServices * GetTextService()
Describe.
virtual HRESULT TxGetScrollBars(DWORD *pdwScrollBar)
Get the bits representing requested scroll bars for the window.
virtual BOOL TxSetScrollPos(INT fnBar, INT nPos, BOOL fRedraw)
Set the scroll position.
virtual HRESULT TxGetMaxLength(DWORD *plength)
Get the maximum length for the text.
virtual HRESULT TxGetExtent(LPSIZEL lpExtent)
Get the native size.
virtual HRESULT TxGetPasswordChar(TCHAR *pch)
Get the character to display for password input.
ULONG cRefs
virtual HRESULT TxGetSelectionBarWidth(LONG *plSelBarWidth)
Returns HIMETRIC size of the control bar.
STextServiceHelper()
构造函数
Definition SRichEdit.cpp:74
HRESULT CreateTextServices(IUnknown *punkOuter, ITextHost *pITextHost, IUnknown **ppUnk)
Definition SRichEdit.cpp:99
PCreateTextServices m_funCreateTextServices
Definition SRichEdit.cpp:71
~STextServiceHelper()
析构函数
Definition SRichEdit.cpp:92
定时器类
Definition STimer.h:13
BOOL StartTimer(int nElapse, BOOL bRepeat, LPARAM uData=0) OVERRIDE
启动定时器
Definition STimer.cpp:17
BOOL FireEvent(IEvtArgs *evt) OVERRIDE
Fires an event.
Definition Swnd.cpp:1540
SAutoRefPtr< ISkinObj > m_pNcSkin
Definition SWnd.h:2623
SwndStyle m_style
Definition SWnd.h:2596
int GetWindowText(TCHAR *pBuf, int nBufLen, BOOL bRawText) OVERRIDE
Retrieves the window text.
Definition Swnd.cpp:263
int GetScale() SCONST OVERRIDE
Retrieves the scale factor of the window.
Definition Swnd.cpp:3266
BOOL IsVisible(BOOL bCheckParent=FALSE) SCONST OVERRIDE
Checks if the window is visible.
Definition Swnd.cpp:646
ISwndContainer * GetContainer() OVERRIDE
Retrieves the container associated with this window.
Definition Swnd.cpp:679
BOOL IsFocused() SCONST OVERRIDE
Checks if the window has focus.
Definition Swnd.cpp:2639
PSWNDMSG GetCurMsg(void) const
Retrieves the current message being processed.
Definition SWnd.h:1190
BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
Handles the mouse wheel event.
Definition Swnd.cpp:2159
LRESULT SSendMessage(UINT uMsg, WPARAM wParam=0, LPARAM lParam=0, BOOL *pbMsgHandled=NULL) OVERRIDE
Sends a message to the window.
Definition Swnd.cpp:364
void InvalidateRect(LPCRECT lprect) OVERRIDE
Invalidates a specific rectangle area of the window.
Definition Swnd.cpp:1444
BOOL m_bFocusable
Definition SWnd.h:2609
SWND SetCapture() OVERRIDE
Sets the window to capture the mouse.
Definition Swnd.cpp:2484
void SetFocus() OVERRIDE
Sets the focus to the window.
Definition Swnd.cpp:2620
BOOL IsDisabled(BOOL bCheckParent=FALSE) SCONST OVERRIDE
Checks if the window is disabled.
Definition Swnd.cpp:638
void KillFocus() OVERRIDE
Kills the focus from the window.
Definition Swnd.cpp:2629
BOOL KillTimer(char id) OVERRIDE
Kills a timer for the window.
Definition Swnd.cpp:483
SAutoRefPtr< ISkinObj > m_pBgSkin
Definition SWnd.h:2622
BOOL FireCtxMenu(POINT pt) OVERRIDE
Fires a context menu event.
Definition Swnd.cpp:2719
void Invalidate() OVERRIDE
Invalidates the entire window.
Definition Swnd.cpp:1437
BOOL CreateCaret(HBITMAP pBmp, int nWid, int nHeight) OVERRIDE
Creates a caret.
Definition Swnd.cpp:3038
void SetMsgHandled(BOOL bHandled)
Sets the message handled flag.
Definition Swnd.cpp:212
SEventSet m_evtSet
Definition SWnd.h:2581
const SwndStyle & GetStyle() const
Retrieves the style of the window.
Definition Swnd.cpp:716
HWND GetHostHwnd() OVERRIDE
Retrieves the host window handle.
Definition Swnd.cpp:3616
SWND m_swnd
Member variables representing various properties of the window.
Definition SWnd.h:2577
void BeforePaintEx(IRenderTarget *pRT)
Prepares the drawing environment for the current window's RenderTarget, starting from the top-level w...
Definition Swnd.cpp:1767
BOOL m_bClipClient
Definition SWnd.h:2607
BOOL ReleaseCapture() OVERRIDE
Releases the mouse capture from the window.
Definition Swnd.cpp:2491
Class representing an XML node.
Definition SXml.h:352
CRect GetPadding() const
Retrieves the padding rectangle.
long Release() override
Decrements the reference count and deletes the object if the count reaches zero.
Font object interface.
Definition SRender-i.h:650
BOOL IsBold() SCONST PURE
Checks if the font is bold.
int TextSize() SCONST PURE
Retrieves the text size of the font.
BOOL IsItalic() SCONST PURE
Checks if the font is italic.
BOOL IsUnderline() SCONST PURE
Checks if the font has an underline.
const LOGFONT * LogFont() SCONST PURE
Retrieves the LOGFONT structure of the font.
Interface for rendering target objects.
Definition SRender-i.h:1440
HRESULT AlphaBlend(LPCRECT pRcDest, IRenderTarget *pRTSrc, LPCRECT pRcSrc, BYTE byAlpha) PURE
Performs an alpha-blended transfer from one render target to another.
HRESULT GetTransform(float matrix[9]) SCONST PURE
Retrieves the current coordinate transformation matrix.
BOOL IsOffscreen() SCONST PURE
Check if the render target is offscreen.
HRESULT PushClipRect(LPCRECT pRect, UINT mode=RGN_AND) PURE
Push a rectangular clip region.
HRESULT PopClip() PURE
Pop the last clip region from the stack.
BOOL RegisterDragDrop(SWND swnd, IDropTarget *pDropTarget) PURE
Registers an IDropTarget with a Swnd.
HWND GetHostHwnd() PURE
Retrieves the handle to the host window.
void GetContainerRect(RECT *ret) SCONST PURE
Retrieves the container's display rectangle.
void OnUpdateCursor() PURE
Updates the cursor.
void EnableIME(BOOL bEnable) PURE
Enables or disables the input method editor (IME).
BOOL UnregisterDragDrop(SWND swnd) PURE
Unregisters an IDropTarget from a Swnd.
Structure representing a window message.
Definition SWnd.h:88
UINT uMsg
Definition SWnd.h:89
WPARAM wParam
Definition SWnd.h:90
LPARAM lParam
Definition SWnd.h:91