/*
* ReplaceDialog.cpp
* Copyright (c) 2009 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// Sample program to use ReplaceDialog class of SOL++2000.
// 2000.02.18
#include <sol\ApplicationView.h>
#include <sol\ScrolledText.h>
#include <sol\ReplaceDialog.h>
#include <sol\FileDialog.h>
#include "Resource.h"
#include <sol\Stdio.h>
namespace SOL {
/**
* This is a simple sample for ReplaceDialog of Windows Common dialogs.
* This shows only how to use ReplaceDialog class in SOL9, but does not
* implement actions to find and replace strings.
*/
class TextEditor :public ApplicationView {
private:
UINT findMsg;
ScrolledText text;
FileDialog fileDialog;
ReplaceDialog replaceDialog;
private:
long search(Event& event)
{
Args ar;
TCHAR* find = null;
TCHAR* replace = null;
ulong flags;
ar.set(XmNflags, (void*)&flags);
ar.set(XmNfindString, (TCHAR**)&find);
ar.set(XmNreplaceString, (TCHAR**)&replace);
replaceDialog.getValues(ar);
if (flags & FR_DIALOGTERM) { // Cancel button
showMessageDialog(_T("TextEditor"), _T("Closing"));
return 0L;
}
if (flags & FR_FINDNEXT) { // find next
showMessageDialog(_T("TextEditor"), _T("Find next"));
}
if (flags & FR_REPLACE) { // replace and find next
showMessageDialog(_T("TextEditor"), _T("Replace and find next"));
}
if (flags & FR_REPLACEALL) { // replace all
showMessageDialog(_T("TextEditor"), _T("Replace all"));
}
showMessageDialog(_T("TextEditor:findString"), (TCHAR*)find);
showMessageDialog(_T("TextEditor:replaceString"), (TCHAR*)replace);
return 0L;
}
private:
void replace(Action& action)
{
if(!replaceDialog.isWindow()) {
// Popup the replaceDialog
replaceDialog.replace(_T(""), _T(""));
}
}
public:
/**
* Constructor
*/
TextEditor(Application& applet, const TCHAR* name, Args& args)
:ApplicationView(applet, name, args)
{
Args ar;
ar.set(XmNnoHideSel, True);
text.create(this, NULL, ar);
add(text);
findMsg = RegisterWindowMessage(FINDMSGSTRING);
ar.reset();
replaceDialog.create(this, NULL, ar);
ar.reset();
fileDialog.create(this, NULL, ar);
addCallback(XmNmenuCallback, ID_OPEN, this,
(Callback)&TextEditor::open, NULL);
addCallback(XmNmenuCallback, ID_SAVE, this,
(Callback)&TextEditor::save, NULL);
addCallback(XmNmenuCallback, ID_REPLACE, this,
(Callback)&TextEditor::replace, NULL);
addCallback(XmNmenuCallback, ID_EXIT, this,
(Callback)&TextEditor::exit, NULL);
addEventHandler(findMsg, this,
(Handler)&TextEditor::search, NULL);
restorePlacement();
}
private:
void open(Action& action)
{
if(fileDialog.open()) {
TCHAR* name = fileDialog.getFileName();
if (text.load(name)) {
TCHAR caption[MAX_PATH];
_stprintf_s(caption, SizeOf(caption), _T("Opened:%s"), name);
setText(caption);
}
}
}
private:
void save(Action& action)
{
if(fileDialog.save()) {
TCHAR* name = fileDialog.getFileName();
if (text.save(name)) {
TCHAR caption[MAX_PATH];
_stprintf_s(caption, SizeOf(caption), _T("Saved:%s"), name);
setText(caption);
}
}
}
};
}
// Sample Main
void Main(int argc, TCHAR** argv)
{
const String appClass = "TextEditor";
try {
Application applet(appClass, argc, argv);
Args args;
TextEditor editor(applet, appClass, args);
editor.realize();
applet.run();
} catch (...) {
}
}
|