/*
* RichTextViewer.h
* Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
#include <sol\PopupView.h>
#include <sol\FileDialog.h>
#include <sol\ScrolledRichText.h>
#include <sol\Font.h>
#include <sol\FontDialog.h>
#include <sol\ClientDC.h>
#include <sol\FileStream.h>
#include <sol/MessageFont.h>
#include "resource.h"
namespace SOL {
class RichTextViewer :public PopupView {
private:
ScrolledRichText text;
MessageFont font;
public:
RichTextViewer()
:PopupView()
{
}
public:
RichTextViewer(View* parent, const TCHAR* name, Args& args)
:PopupView(parent, name, args)
{
Args ar;
ar.set(XmNexStyle, (ulong)WS_EX_ACCEPTFILES);
text.create(this, NULL, ar);
add(text);
text.setEventMask(ENM_DROPFILES);
text.addCallback(XmNdropFilesCallback, this,
(Callback)&RichTextViewer::dropped, NULL);
font.create(9);
text.setFont(font);
resize();
}
public:
Boolean create(View* parent, const TCHAR* name, Args& args)
{
Boolean rc = PopupView::create(parent, name, args.set(XmNstyle, WS_THICKFRAME));
Args ar;
ar.set(XmNexStyle, (ulong)WS_EX_ACCEPTFILES);
text.create(this, NULL, ar);
//add(text);
text.setEventMask(ENM_DROPFILES);
text.addCallback(XmNdropFilesCallback, this,
(Callback)&RichTextViewer::dropped, NULL);
addEventHandler(WM_SIZE, this,
(Handler)&RichTextViewer::size, NULL);
font.create(9);
text.setFont(font);
resize();
return rc;
}
private:
long size(Event& event)
{
int w, h;
event.getSize(w, h);
text.reshape(0, 0, w, h);
return 0;
}
public:
void setCaption(TCHAR* filename)
{
if(filename) {
TCHAR text[MAX_PATH];
_stprintf_s(text, SizeOf(text), _T("%s - RichTextEditor"), filename);
setText(text);
}
}
public:
void openRTF(TCHAR* filename)
{
if (filename) {
text.streamIn(filename, SF_RTF);
setCaption(filename);
}
}
public:
void openText(TCHAR* filename)
{
if (filename) {
text.streamIn(filename, SF_TEXT);
setCaption(filename);
}
}
public:
void dropped(Action& action)
{
Event& event = action.getEvent();
ENDROPFILES* endrop = (ENDROPFILES*)event.getLParam();
HDROP hdrop = (HDROP)endrop->hDrop;
TCHAR filename[_MAX_PATH];
::DragQueryFile(hdrop, 0, filename, sizeof(filename));
text.streamIn(filename, SF_TEXT|SFF_SELECTION);
}
public:
void clear(Action& action)
{
text.clear();
}
};
}
|