[sword-cvs] swordreader/src/gui TextControl.cpp,NONE,1.1 TextControl.h,NONE,1.1 VerseTextControl.cpp,NONE,1.1 VerseTextControl.h,NONE,1.1

sword@www.crosswire.org sword@www.crosswire.org
Sat, 17 Apr 2004 11:52:55 -0700


Update of /cvs/core/swordreader/src/gui
In directory www:/tmp/cvs-serv10350

Added Files:
	TextControl.cpp TextControl.h VerseTextControl.cpp 
	VerseTextControl.h 
Log Message:
Searching works now

--- NEW FILE: TextControl.cpp ---
#include "ApplicationInterface.h"
#include "TextControl.h"

#include <swordce.h>

//#define NOHTML

#ifndef NOHTML

// The sophisticated graphical representation, using an HTML component

#include <htmlctrl.h>

//#define debugfile

#ifdef debugfile
	#include <stdio.h>
	FILE* file;
	#define addHtml(window,text) SendMessage(window, DTM_ADDTEXTW, FALSE, (LPARAM)text);fwprintf(file,text);
#else
	#define addHtml(window,text) SendMessage(window, DTM_ADDTEXTW, FALSE, (LPARAM)text)
#endif

#define setZoom(window,zoom) SendMessage(window, DTM_ZOOMLEVEL, 0, zoom);
#define clearHtml(window) SendMessage(window, DTM_CLEAR, 0, 0);
#define endHtml(window) SendMessage(window, DTM_ENDOFSOURCE, 0, 0);
#define controlToVerse(window,versenr) SendMessage(window, DTM_ANCHORW, FALSE, (LPARAM)(toUString(versenr).c_str()))

TextControl::TextControl(int x, int y, int width, int height){
	VERIFY(InitHTMLControl(g_hInst));
	htmlControl = CreateWindowEx(WS_EX_NOACTIVATE, WC_HTML, NULL, 
		WS_CHILD | HS_CLEARTYPE | HS_NOSCRIPTING | 
		HS_NOIMAGES | HS_NOACTIVEX | HS_NOSOUNDS ,
		x, y, width, height, 
		g_hWnd,	NULL, g_hInst, NULL);
	setZoom(htmlControl, 1);}

TextControl::~TextControl(){
}

void TextControl::show() {
	ShowWindow(htmlControl,SW_SHOW);
}

void TextControl::hide() {
	ShowWindow(htmlControl,SW_HIDE);
}

void TextControl::paint() {
}

void TextControl::clearText() {
	clearHtml(htmlControl);
}

void TextControl::addText(UString text) {
	addHtml(htmlControl,text.c_str());
}

void TextControl::endOfText() {
	endHtml(htmlControl);
}

#else //ifndef NOHTML

// A simpeler graphical representation not using the HTML component

TextControl::TextControl(int x, int y, int width, int height){
	area.left=x; area.top=y; area.right=x+width; area.bottom=y+height;
}

TextControl::~TextControl(){
}

void TextControl::show() {
}

void TextControl::hide() {
}

void TextControl::paint() {
	RECT textArea=area;
	textArea.top+=drawVerseText(&textArea,buffer);
	clearRect(&textArea);
}

void TextControl::clearText() {
	buffer=L"";
}

void TextControl::addText(UString text) {
	buffer+=noMarkup(text);
}

void TextControl::endOfText() {
	refreshScreen();
}

#endif
--- NEW FILE: TextControl.h ---
#ifndef TEXTCONTROL_H
#define TEXTCONTROL_H

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <map>

class TextControl {
public:
	TextControl(int x, int y, int width, int height);
	virtual ~TextControl();

	void show();
	void hide();
	virtual void paint();

	virtual void clearText();
	void addText(UString text);
	void endOfText();
protected:
	HWND htmlControl;					// in case of HTML
	UString buffer;
	RECT area;
};

#endif

--- NEW FILE: VerseTextControl.cpp ---
#include "ApplicationInterface.h"
#include "VerseTextControl.h"

#include <swordce.h>

//#define NOHTML

#ifndef NOHTML

VerseTextControl::VerseTextControl(int x, int y, int width, int height) 
		: TextControl(x,y,width,height) {}

void VerseTextControl::addAnchoredText(UString text, int anchor) {
	//TODO
	addText(text);
}

void VerseTextControl::gotoAnchor(int anchor) {
	//TODO
}

void VerseTextControl::paint() {}

void VerseTextControl::clearText() {
	TextControl::clearText();
}

#else //ifndef NOHTML

VerseTextControl::VerseTextControl(int x, int y, int width, int height) 
		: TextControl(x,y,width,height) {
	currentAnchor=-1;
}

void VerseTextControl::paint() {
	AnchorIterator current=anchorPositions.find(currentAnchor);
	if (current==(AnchorIterator)anchorPositions.end()) {
		current=anchorPositions.begin();
		// no or invalid anchor, start at the first anchor
	}
	RECT textArea=area;
	int start, end;
	if (current==(AnchorIterator)anchorPositions.end()) start=0; 
	else start=current->second;
	while (textArea.top<textArea.bottom) {
		if (current==(AnchorIterator)anchorPositions.end()) 
			end=buffer.length(); 
		else {
			current++; 
			end=current->second;
		}
		if (end<=start) break; // no more text left
		textArea.top+=drawVerseText(&textArea,buffer.substr(start, end-start));
		start=end;
	}
	clearRect(&textArea);
}

void VerseTextControl::clearText() {
	TextControl::clearText();
	currentAnchor=-1;
	anchorPositions.clear();
}


void VerseTextControl::addAnchoredText(UString text, int anchor) {
	anchorPositions[anchor]=buffer.length();
	addText(text);
}

void VerseTextControl::gotoAnchor(int anchor) {
	currentAnchor=anchor;
}

#endif
--- NEW FILE: VerseTextControl.h ---
#ifndef VERSETEXTCONTROL_H
#define VERSETEXTCONTROL_H

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "TextControl.h"

class VerseTextControl: public TextControl {
public:
	VerseTextControl(int x, int y, int width, int height);
	void addAnchoredText(UString text, int anchor); 
	// we are able to scroll back to this point using the anchor
	void gotoAnchor(int anchor);

	virtual void paint();
	virtual void clearText();
protected:
	std::map<int,int> anchorPositions;	// in case of plain text
	typedef std::map<int,int>::const_iterator AnchorIterator;
	int currentAnchor;
};

#endif