// $Revision: 1.7 $ // Copyright (C) 1995 Taligent, Inc. All rights reserved. #ifndef TaligentSamples_LIBWWWINTERFACE #include "LibWWWInterface.h" #endif #ifndef Taligent_RUNTIME #include #endif #ifndef Taligent_UNICODEGENERAL #include #endif #ifndef Taligent_TRANSCODING #include #endif #ifndef Taligent_LINELAYOUTSTYLES #include #endif #ifndef Taligent_FONTSTYLES #include #endif #ifndef Taligent_SCRAPITEMON #include #endif extern "C" { #include #include #include #include } // these three globals must be declared by the devleoper to get libwww to // link extern char* HTAppName = "TALIGENT WEBRUNNER SAMPLE"; extern char* HTAppVersion = "Beta 1.0"; HTStyle kNormalStyle = {0,"Normal","",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; HTStyle kH1Style = {0,"Heading1","",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; HTStyle kH2Style = {0,"Heading2","",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; HTStyle kH3Style = {0,"Heading3","",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; HTStyle kListStyle = {0,"List","",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; HTStyle kItalicStyle = {0,"Italic","",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; GCoordinate kH1Size = 32; GCoordinate kH2Size = 24; GCoordinate kH3Size = 16; HTStyleSheet* CreateStyleSheet() { HTStyleSheet* sheet = HTStyleSheetNew(); sheet = HTStyleSheetAddStyle(sheet, &kNormalStyle); sheet = HTStyleSheetAddStyle(sheet, &kH1Style); sheet = HTStyleSheetAddStyle(sheet, &kH2Style); sheet = HTStyleSheetAddStyle(sheet, &kH3Style); sheet = HTStyleSheetAddStyle(sheet, &kListStyle); sheet = HTStyleSheetAddStyle(sheet, &kItalicStyle); return sheet; } extern HTStyleSheet* styleSheet = CreateStyleSheet(); void _HTStream_free(HTStream* inStream) { delete inStream; } void _HTStream_abort(HTStream* inStream, HTError e) { } void _HTStream_put_character(HTStream* inStream, char character) { if (inStream->GetTaligentStreamAlias() != 0) { inStream->GetTaligentStreamAlias()->Write(character); } } void _HTStream_put_string(HTStream* inStream, const char* string) { if (inStream->GetTaligentStreamAlias() != 0) { inStream->GetTaligentStreamAlias()->Write(string, ::strlen(string)); } } void _HTStream_put_block(HTStream* inStream, const char* string, int length) { if (inStream->GetTaligentStreamAlias() != 0) { inStream->GetTaligentStreamAlias()->Write(string, length); } } _HTStream::_HTStream(TStream* taligentStreamAlias, THypertextScrapItem* taligentTextAlias, TMIMEForeignDataType* mimeDataTypeAlias) : fStreamAlias(taligentStreamAlias), fTextAlias(taligentTextAlias), fMIMEDataTypeAlias(mimeDataTypeAlias) { fLibWWWClass = new HTStreamClass; fLibWWWClass->name = (char*)"Taligent_HTStream"; fLibWWWClass->free = _HTStream_free; fLibWWWClass->abort = _HTStream_abort; fLibWWWClass->put_character = _HTStream_put_character; fLibWWWClass->put_string = _HTStream_put_string; fLibWWWClass->put_block = _HTStream_put_block; } _HTStream::~_HTStream() { delete fLibWWWClass; } TStream* _HTStream::GetTaligentStreamAlias() const { return fStreamAlias; } THypertextScrapItem* _HTStream::GetHypertextAlias() const { return fTextAlias; } TMIMEForeignDataType* _HTStream::GetMIMETypeAlias() const { return fMIMEDataTypeAlias; } HTStream* NonHTMLStream(HTRequest* request, void* param, HTFormat input_format, HTFormat output_format, HTStream* output_stream) { if (output_stream != 0) { TMIMEForeignDataType* typeAlias = output_stream->GetMIMETypeAlias(); if (typeAlias != 0) { *typeAlias = input_format->name; } } return output_stream; } void AddTaligentConversions(HTList* conversionList) { HTSetConversion(conversionList, "www/mime", "*/*", HTMIMEConvert, 1.0, 0.0, 0.0); HTSetConversion(conversionList, "text/html", "text/plain", HTMLToPlain, 0.5, 0.0, 0.0); HTSetConversion(conversionList, "text/html", "www/present", HTMLPresent, 1.0, 0.0, 0.0); HTSetConversion(conversionList, "*/*", "www/present", NonHTMLStream, 0.3, 0.0, 0.0); } _HText::_HText(THypertextScrapItem* taligentHypertextAlias, HTParentAnchor* anchor) : fHypertextAlias(taligentHypertextAlias), fCurrentAnchorBeginning(-1), fParentAnchor(anchor) { } _HText::~_HText() { } void _HText::EndAppend() { if (fHypertextAlias != 0) { ApplyCurrentText(); if (fParentAnchor != 0) { if (fParentAnchor->title != 0) { fHypertextAlias->SetTitle(TStandardText(fParentAnchor->title)); } else { fHypertextAlias->SetTitle( TStandardText(fParentAnchor->address)); } } } } void _HText::ApplyCurrentText() { fCurrentText.AddStyles(fCurrentStyles); if (fHypertextAlias != 0) { fHypertextAlias->Append(fCurrentText); fCurrentStyles.RemoveAll(); fCurrentText.Delete(); } } void _HText::AppendToCurrent(const TText& text) { fCurrentText.Insert(text); } void _HText::AppendToCurrent(char character) { switch (character) { case TASCII::kLineFeed: case TASCII::kCarriageReturn: AppendLineBreakToCurrent(); break; default: static const TASCIITranscoder transcoder; transcoder.AppendToText(&character, 1, fCurrentText); } } void _HText::AppendLineBreakToCurrent() { static const TASCIITranscoder transcoder; unsigned char lineBreak = TASCII::kCarriageReturn; transcoder.AppendToText(&lineBreak, 1, fCurrentText); } void _HText::AddStyleToCurrentText(const TStyle& style) { fCurrentStyles.Add(style); } void _HText::AppendImage(const TURL& imageURL) { TDequeOf acceptableTypes( new TOperatorComparator, NIL); const TTypeDescription graphicScrapType(StaticTypeInfo(TScrapItemOn)); acceptableTypes.Add(&graphicScrapType); TDeleterFor item = imageURL.Follow(acceptableTypes); if (item != NIL) { TScrapItemOn* graphicScrapItem = 0; DynamicCastTo(graphicScrapItem, item.GetObject()); if (graphicScrapItem != 0) { MGraphic* graphic = graphicScrapItem->OrphanObject(); TMGraphicObjectStyle graphicStyle; graphicStyle.AdoptMGraphic(graphic, TMGraphicObjectStyle::fNullPoint); TStandardText imageText("#"); imageText.AddStyles(graphicStyle); // adjacent graphic styles are optimized into the same graphic, // so we separate them with a space. imageText.Insert(" "); AppendToCurrent(imageText); } } } void _HText::BeginAnchor(const TURL& destination) { fCurrentAnchorDestination = destination; fCurrentAnchorBeginning = fCurrentText.GetLength() + fHypertextAlias->GetText()->GetLength(); } void _HText::EndAnchor() { if (fCurrentAnchorBeginning >= 0) { TStyleSet currentStyles = fCurrentStyles; ApplyCurrentText(); fCurrentStyles = currentStyles; TTextOffset endOffset = (long)fHypertextAlias->GetText()->GetLength(); TTextRange linkRange(fCurrentAnchorBeginning, endOffset); fHypertextAlias->AddLinkRange(linkRange, fCurrentAnchorDestination); fCurrentAnchorBeginning = -1; } } HText* HText_new(HTParentAnchor* anchor) { return new _HText(NIL, NIL); } HText* HText_new2(HTParentAnchor* anchor, HTStream* output_stream) { THypertextScrapItem* item = output_stream->GetHypertextAlias(); return new _HText(item, anchor); } HText* HText_new3(HTParentAnchor* anchor, HTStream* output_stream, HTStructured* structure) { return new _HText(output_stream->GetHypertextAlias(), NIL); } void HText_free(HText* me) { delete me; } void HText_beginAppend(HText* text) { } void HText_endAppend(HText* text) { text->EndAppend(); } void HText_setStyle(HText* text, HTStyle* style) { if (style != 0) { text->ApplyCurrentText(); if (style == &kH1Style) { text->AddStyleToCurrentText(TFontPointSizeStyle(kH1Size)); } else if (style == &kH2Style) { text->AddStyleToCurrentText(TFontPointSizeStyle(kH2Size)); } else if (style == &kH3Style) { text->AddStyleToCurrentText(TFontPointSizeStyle(kH3Size)); } else if (style == &kListStyle) { // nothing special implemented } else if (style == &kItalicStyle) { text->AddStyleToCurrentText(TFontSlantAngleStyle()); } } } void HText_appendCharacter(HText* text, char ch) { text->AppendToCurrent(TStandardText(UniChar((unsigned char)ch))); } void HText_appendText(HText* text, CONST char* str) { static const TASCIITranscoder transcoder; TStandardText commonPointText; transcoder.AppendToText(str, ::strlen(str), commonPointText); text->AppendToCurrent(commonPointText); } void HText_appendParagraph(HText* text) { text->AppendLineBreakToCurrent(); text->AppendLineBreakToCurrent(); } void HText_appendLineBreak(HText* text) { text->AppendLineBreakToCurrent(); } void HText_appendHorizontalRule(HText* text) { } void HText_beginAnchor(HText* text, HTChildAnchor* anc) { if (anc->mainLink.dest) { if (anc->mainLink.dest->parent->address) { TStandardText linkString(anc->mainLink.dest->parent->address); text->BeginAnchor(TURL(linkString)); } } } void HText_endAnchor(HText* text) { text->EndAnchor(); } void HText_appendImage( HText* text, HTChildAnchor* anc, CONST char* alternative_text, CONST char* alignment, BOOL isMap) { if (anc != 0 && anc->mainLink.dest != 0 && anc->mainLink.dest->parent != 0) { const char* urlString = anc->mainLink.dest->parent->address; if (urlString != 0) { TURL imageURL(urlString); text->AppendImage(imageURL); } } } void HText_dump(HText* text) { } HTParentAnchor* HText_nodeAnchor(HText* text) { return NULL; } BOOL HText_select(HText* text) { return 0; } BOOL HText_selectAnchor(HText* text, HTChildAnchor* anchor) { return 0; } void HText_applyStyle(HText* text, HTStyle* style) { } void HText_updateStyle(HText* text, HTStyle* style) { } HTStyle* HText_selectionStyle(HText* text, HTStyleSheet* sheet) { return NULL; } void HText_replaceSel(HText* text, CONST char* aString, HTStyle* aStyle) { } void HTextApplyToSimilar(HText* text, HTStyle* style) { } void HTextSelectUnstyled(HText* text, HTStyleSheet* sheet) { } void HText_unlinkSelection(HText* text) { } HTAnchor* HText_referenceSelected(HText* text) { return NULL; } HTAnchor* HText_linkSelTo(HText* text, HTAnchor* anchor) { return NULL; }