Added another GetStyledText() function to force a specific encoding.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19847 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,39 +1,11 @@
|
||||
/*****************************************************************************/
|
||||
// File: TranslationUtils.h
|
||||
// Class: BTranslationUtils
|
||||
// Reimplemented by: Michael Wilber, Translation Kit Team
|
||||
// Reimplementation: 2002-04
|
||||
//
|
||||
// Description: Utility functions for the Translation Kit
|
||||
//
|
||||
//
|
||||
// Copyright (c) 2002 OpenBeOS Project
|
||||
//
|
||||
// Original Version: Copyright 1998, Be Incorporated, All Rights Reserved.
|
||||
// Copyright 1995-1997, Jon Watte
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
/*****************************************************************************/
|
||||
|
||||
#if !defined(_TRANSLATION_UTILS_H)
|
||||
/*
|
||||
* Copyright 2002-2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _TRANSLATION_UTILS_H
|
||||
#define _TRANSLATION_UTILS_H
|
||||
|
||||
|
||||
#include <TranslationDefs.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
@@ -42,10 +14,9 @@ class BTranslatorRoster;
|
||||
class BPositionIO;
|
||||
class BMenu;
|
||||
|
||||
// This class is a little different from many other classes.
|
||||
// You don't create an instance of it; you just call its various
|
||||
// static member functions for utility-like operations.
|
||||
|
||||
class BTranslationUtils {
|
||||
private:
|
||||
BTranslationUtils();
|
||||
~BTranslationUtils();
|
||||
BTranslationUtils(const BTranslationUtils &);
|
||||
@@ -66,8 +37,10 @@ class BTranslationUtils {
|
||||
BTranslatorRoster *roster = NULL);
|
||||
|
||||
// text functions
|
||||
static status_t GetStyledText(BPositionIO *fromStream, BTextView *intoView,
|
||||
static status_t GetStyledText(BPositionIO* fromStream, BTextView* intoView,
|
||||
BTranslatorRoster *roster = NULL);
|
||||
static status_t GetStyledText(BPositionIO* fromStream, BTextView* intoView,
|
||||
const char* encoding, BTranslatorRoster* roster = NULL);
|
||||
static status_t PutStyledText(BTextView *fromView, BPositionIO *intoStream,
|
||||
BTranslatorRoster *roster = NULL);
|
||||
static status_t WriteStyledEditFile(BTextView *fromView, BFile *intoFile);
|
||||
@@ -84,9 +57,9 @@ class BTranslationUtils {
|
||||
B_TRANSLATION_MENU = 'BTMN'
|
||||
};
|
||||
static status_t AddTranslationItems(BMenu *intoMenu, uint32 fromType,
|
||||
const BMessage *model = NULL, // default B_TRANSLATION_MENU
|
||||
const char *translatorIdName = NULL, // default "be:translator"
|
||||
const char *translatorTypeName = NULL, // default "be:type"
|
||||
const BMessage *model = NULL, // default B_TRANSLATION_MENU
|
||||
const char *translatorIdName = NULL, // default "be:translator"
|
||||
const char *translatorTypeName = NULL, // default "be:type"
|
||||
BTranslatorRoster *roster = NULL);
|
||||
};
|
||||
|
||||
|
||||
@@ -312,19 +312,20 @@ BTranslationUtils::GetBitmap(BPositionIO *stream, BTranslatorRoster *roster)
|
||||
defined in
|
||||
/boot/develop/headers/be/translation/TranslatorFormats.h
|
||||
|
||||
\param fromStream the stream with the styled text
|
||||
\param source the stream with the styled text
|
||||
\param intoView the view where the test will be inserted
|
||||
roster, BTranslatorRoster used to do the translation
|
||||
\param the encoding to use, defaults to UTF-8
|
||||
|
||||
\return B_BAD_VALUE, if fromStream or intoView is NULL
|
||||
\return B_ERROR, if any other error occurred
|
||||
\return B_OK, if successful
|
||||
*/
|
||||
status_t
|
||||
BTranslationUtils::GetStyledText(BPositionIO *fromStream, BTextView *intoView,
|
||||
BTranslatorRoster *roster)
|
||||
BTranslationUtils::GetStyledText(BPositionIO* source, BTextView* intoView,
|
||||
const char* encoding, BTranslatorRoster* roster)
|
||||
{
|
||||
if (fromStream == NULL || intoView == NULL)
|
||||
if (source == NULL || intoView == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
// Use default Translator if none is specified
|
||||
@@ -334,10 +335,14 @@ BTranslationUtils::GetStyledText(BPositionIO *fromStream, BTextView *intoView,
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
BMessage config;
|
||||
if (encoding != NULL && encoding[0])
|
||||
config.AddString("be:encoding", encoding);
|
||||
|
||||
// Translate the file from whatever format it is to B_STYLED_TEXT_FORMAT
|
||||
// we understand
|
||||
BMallocIO mallocIO;
|
||||
if (roster->Translate(fromStream, NULL, NULL, &mallocIO,
|
||||
if (roster->Translate(source, NULL, &config, &mallocIO,
|
||||
B_STYLED_TEXT_FORMAT) < B_OK)
|
||||
return B_BAD_TYPE;
|
||||
|
||||
@@ -429,6 +434,14 @@ BTranslationUtils::GetStyledText(BPositionIO *fromStream, BTextView *intoView,
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BTranslationUtils::GetStyledText(BPositionIO* source, BTextView* intoView,
|
||||
BTranslatorRoster* roster)
|
||||
{
|
||||
return GetStyledText(source, intoView, NULL, roster);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
This function takes styled text data from fromView and writes it to
|
||||
intoStream. The plain text data and styled text data are combined
|
||||
|
||||
Reference in New Issue
Block a user