Initial
This commit is contained in:
157
proto/source/RICHEDIT.HPP
Normal file
157
proto/source/RICHEDIT.HPP
Normal file
@@ -0,0 +1,157 @@
|
||||
#ifndef _PROTO_RICHEDIT_HPP_
|
||||
#define _PROTO_RICHEDIT_HPP_
|
||||
#ifndef _COMMON_CONTROL_HPP_
|
||||
#include <common/control.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_RICHEDIT_HPP_
|
||||
#include <common/richedit.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_FONT_HPP_
|
||||
#include <common/font.hpp>
|
||||
#endif
|
||||
#ifndef _PROTO_CHARFORMAT_HPP_
|
||||
#include <proto/charform.hpp>
|
||||
#endif
|
||||
|
||||
class RichEditControl : public Control
|
||||
{
|
||||
public:
|
||||
RichEditControl(void);
|
||||
RichEditControl(HWND hControlWnd,BOOL destroyWindow=TRUE);
|
||||
virtual ~RichEditControl();
|
||||
BOOL setTextColor(RGBColor textColor);
|
||||
BOOL setBkGndColor(RGBColor bkGndColor);
|
||||
BOOL wantReturn(BOOL wantReturn);
|
||||
BOOL setFont(const Font &someFont);
|
||||
BOOL setCharFormat(const String faceName,int charHeight);
|
||||
BOOL limitText(WORD cchMax);
|
||||
BOOL createControl(Window &parentWnd,const Rect &initRect,UINT controlID);
|
||||
private:
|
||||
void loadLibrary(void);
|
||||
void freeLibrary(void);
|
||||
void getLogPixelsy(void);
|
||||
int mLogPixelsy;
|
||||
HINSTANCE mhLibInst;
|
||||
};
|
||||
|
||||
inline
|
||||
RichEditControl::RichEditControl(void)
|
||||
: mhLibInst(0)
|
||||
{
|
||||
loadLibrary();
|
||||
getLogPixelsy();
|
||||
}
|
||||
|
||||
inline
|
||||
RichEditControl::RichEditControl(HWND hControlWnd,BOOL destroyWindow)
|
||||
: Control(hControlWnd,destroyWindow), mhLibInst(0)
|
||||
{
|
||||
loadLibrary();
|
||||
getLogPixelsy();
|
||||
}
|
||||
|
||||
inline
|
||||
RichEditControl::~RichEditControl()
|
||||
{
|
||||
freeLibrary();
|
||||
}
|
||||
|
||||
inline
|
||||
BOOL RichEditControl::createControl(Window &parentWnd,const Rect &initRect,UINT controlID)
|
||||
{
|
||||
Control::createControl(WS_EX_CLIENTEDGE,"RICHEDIT","",WS_VISIBLE|ES_MULTILINE|ES_SUNKEN|ES_SAVESEL|ES_AUTOHSCROLL|ES_AUTOVSCROLL|WS_VSCROLL,initRect,parentWnd,controlID);
|
||||
return isValid();
|
||||
}
|
||||
|
||||
inline
|
||||
void RichEditControl::loadLibrary(void)
|
||||
{
|
||||
freeLibrary();
|
||||
mhLibInst=::LoadLibrary("RICHED32.DLL");
|
||||
}
|
||||
|
||||
inline
|
||||
void RichEditControl::freeLibrary(void)
|
||||
{
|
||||
if(!mhLibInst)return;
|
||||
::FreeLibrary(mhLibInst);
|
||||
}
|
||||
|
||||
inline
|
||||
BOOL RichEditControl::setTextColor(RGBColor textColor)
|
||||
{
|
||||
if(!isValid())return FALSE;
|
||||
CharFormat charFormat;
|
||||
sendMessage(EM_GETCHARFORMAT,0,(LPARAM)(LPSTR)&((CHARFORMAT&)charFormat));
|
||||
charFormat.mask(CharFormat::MaskColor);
|
||||
charFormat.effects(0);
|
||||
charFormat.textColor(textColor);
|
||||
sendMessage(EM_SETCHARFORMAT,SCF_ALL,(LPARAM)(LPSTR)&((CHARFORMAT&)charFormat));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#include <common/purehdc.hpp>
|
||||
inline
|
||||
BOOL RichEditControl::setFont(const Font &someFont)
|
||||
{
|
||||
if(!isValid())return FALSE;
|
||||
CharFormat charFormat;
|
||||
sendMessage(EM_GETCHARFORMAT,0,(LPARAM)(LPSTR)&((CHARFORMAT&)charFormat));
|
||||
charFormat.mask(CharFormat::MaskCharSet|CharFormat::MaskFace|CharFormat::MaskSize);
|
||||
charFormat.effects(0);
|
||||
charFormat.charSet(someFont.charSet());
|
||||
charFormat.yHeight(-(((int)someFont.sizeFont()*mLogPixelsy)/72));
|
||||
// charFormat.yHeight(-((50*mLogPixelsy)/72));
|
||||
// charFormat.yHeight(200);
|
||||
charFormat.pitchAndFamily(someFont.pitchAndFamily());
|
||||
charFormat.faceName(someFont.fontStyle());
|
||||
sendMessage(EM_SETCHARFORMAT,SCF_ALL,(LPARAM)(LPSTR)&((CHARFORMAT&)charFormat));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
inline
|
||||
BOOL RichEditControl::setCharFormat(const String faceName,int charHeight)
|
||||
{
|
||||
if(!isValid())return FALSE;
|
||||
CharFormat charFormat;
|
||||
charFormat.mask(CharFormat::MaskCharSet|CharFormat::MaskFace|CharFormat::MaskSize);
|
||||
charFormat.effects(0);
|
||||
charFormat.charSet(0);
|
||||
charFormat.yHeight(charHeight);
|
||||
charFormat.faceName(faceName);
|
||||
sendMessage(EM_SETCHARFORMAT,SCF_ALL,(LPARAM)(LPSTR)&((CHARFORMAT&)charFormat));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
inline
|
||||
BOOL RichEditControl::setBkGndColor(RGBColor bkGndColor)
|
||||
{
|
||||
if(!isValid())return FALSE;
|
||||
sendMessage(EM_SETBKGNDCOLOR,0,(COLORREF)bkGndColor);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
inline
|
||||
BOOL RichEditControl::limitText(WORD cchMax)
|
||||
{
|
||||
if(!isValid())return FALSE;
|
||||
sendMessage(EM_LIMITTEXT,(WPARAM)cchMax,0L);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
inline
|
||||
BOOL RichEditControl::wantReturn(BOOL wantReturn)
|
||||
{
|
||||
if(!isValid())return FALSE;
|
||||
sendMessage(EM_SETOPTIONS,ECOOP_OR,ECO_WANTRETURN);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
inline
|
||||
void RichEditControl::getLogPixelsy(void)
|
||||
{
|
||||
PureDevice screenDevice;
|
||||
screenDevice.screenDevice();
|
||||
mLogPixelsy=::GetDeviceCaps(screenDevice,LOGPIXELSY);
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user