From 46555d8f436bd50ad3a657c87c8db6b6b3a3fd99 Mon Sep 17 00:00:00 2001 From: shatty Date: Sat, 26 Jul 2003 22:56:30 +0000 Subject: [PATCH] changed to use new BCharacterSet and BCharacterSetRoster from support kit. because libtextencoding.so is not finished yet it uses those sources directly instead of the library. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4092 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/stylededit/Jamfile | 12 ++- src/apps/stylededit/StyledEditApp.cpp | 37 ++++----- src/apps/stylededit/StyledEditView.cpp | 98 +++++++++++------------- src/apps/stylededit/StyledEditWindow.cpp | 38 ++++----- 4 files changed, 95 insertions(+), 90 deletions(-) diff --git a/src/apps/stylededit/Jamfile b/src/apps/stylededit/Jamfile index fbc4e23438..f3befcd9ef 100644 --- a/src/apps/stylededit/Jamfile +++ b/src/apps/stylededit/Jamfile @@ -1,18 +1,26 @@ SubDir OBOS_TOP src apps stylededit ; +UsePrivateHeaders support ; + AddResources StyledEdit : StyledEdit.rdef StyledEdit.icons.rdef StyledEdit.version.rdef ; App StyledEdit : - CharacterSet.cpp ColorMenuItem.cpp FindWindow.cpp ReplaceWindow.cpp StyledEditApp.cpp StyledEditView.cpp StyledEditWindow.cpp + # OBOS textencodings + CharacterSet.cpp + CharacterSetRoster.cpp + character_sets.cpp ; -LinkSharedOSLibs StyledEdit : be translation tracker textencoding ; +SEARCH on CharacterSet.cpp += [ FDirName $(OBOS_TOP) src kits support ] ; +SEARCH on CharacterSetRoster.cpp += [ FDirName $(OBOS_TOP) src kits support ] ; +SEARCH on character_sets.cpp += [ FDirName $(OBOS_TOP) src kits support ] ; +LinkSharedOSLibs StyledEdit : be translation tracker textencoding ; diff --git a/src/apps/stylededit/StyledEditApp.cpp b/src/apps/stylededit/StyledEditApp.cpp index 1e1d3c6129..61d20d9eec 100644 --- a/src/apps/stylededit/StyledEditApp.cpp +++ b/src/apps/stylededit/StyledEditApp.cpp @@ -2,11 +2,14 @@ #include #include #include -#include "CharacterSet.h" +#include +#include #include "Constants.h" #include "StyledEditApp.h" #include "StyledEditWindow.h" +using namespace BPrivate; + BRect windowRect(7,26,507,426); StyledEditApp * styled_edit_app; @@ -24,23 +27,21 @@ StyledEditApp::StyledEditApp() fOpenPanelEncodingMenu->SetRadioMode(true); status_t status = B_OK; - CharacterSetRoster * roster = CharacterSetRoster::Roster(&status); - if (status == B_OK) { - for (int index = 0; (index < roster->GetCharacterSetCount()) ; index++) { - const CharacterSet * cs = roster->GetCharacterSet(index); - BString name(cs->GetPrintName()); - const char * mime = cs->GetMIMEName(); - if (mime) { - name.Append(" ("); - name.Append(mime); - name.Append(")"); - } - BMenuItem * item = new BMenuItem(name.String(),new BMessage(OPEN_AS_ENCODING)); - item->SetTarget(this); - fOpenPanelEncodingMenu->AddItem(item); - if (index == fOpenAsEncoding) { - item->SetMarked(true); - } + BCharacterSetRoster roster; + BCharacterSet charset; + while (roster.GetNextCharacterSet(&charset) == B_NO_ERROR) { + BString name(charset.GetPrintName()); + const char * mime = charset.GetMIMEName(); + if (mime) { + name.Append(" ("); + name.Append(mime); + name.Append(")"); + } + BMenuItem * item = new BMenuItem(name.String(),new BMessage(OPEN_AS_ENCODING)); + item->SetTarget(this); + fOpenPanelEncodingMenu->AddItem(item); + if (charset.GetFontID() == fOpenAsEncoding) { + item->SetMarked(true); } } diff --git a/src/apps/stylededit/StyledEditView.cpp b/src/apps/stylededit/StyledEditView.cpp index 41c1c31e9e..4755ce0d5b 100644 --- a/src/apps/stylededit/StyledEditView.cpp +++ b/src/apps/stylededit/StyledEditView.cpp @@ -5,11 +5,14 @@ #include #include #include +#include +#include +#include #include "StyledEditView.h" #include "Constants.h" -#include "CharacterSet.h" -#include "UTF8.h" + +using namespace BPrivate; StyledEditView::StyledEditView(BRect viewFrame, BRect textBounds, BHandler *handler) : BTextView(viewFrame, "textview", textBounds, @@ -74,15 +77,10 @@ StyledEditView::GetStyledText(BPositionIO * stream) int32 encoding; bytesRead = node->ReadAttr("be:encoding",0,0,&encoding,sizeof(encoding)); if (bytesRead > 0) { - CharacterSetRoster * roster = CharacterSetRoster::Roster(&result); - if (result != B_OK) { - fSuppressChanges = false; - return result; - } if (encoding == 65535) { fEncoding = 0; } else { - const CharacterSet * cs = roster->FindCharacterSetByConversionID(encoding); + const BCharacterSet * cs = BCharacterSetRoster::GetCharacterSetByConversionID(encoding); if (cs != 0) { fEncoding = cs->GetFontID(); } @@ -114,31 +112,28 @@ StyledEditView::GetStyledText(BPositionIO * stream) if (fEncoding != 0) { int32 length = stream->Seek(0,SEEK_END); text_run_array * run_array = RunArray(0,length); - CharacterSetRoster * roster = CharacterSetRoster::Roster(&result); - if (result == B_OK) { - uint32 id = roster->FindCharacterSetByFontID(fEncoding)->GetConversionID(); - SetText(""); - char inBuffer[256]; - off_t location = 0; - int32 textOffset = 0; - int32 state = 0; - int32 bytesRead; - while ((bytesRead = stream->ReadAt(location,inBuffer,256)) > 0) { - char * inPtr = inBuffer; - char textBuffer[256]; - int32 textLength = 256; - int32 bytes = bytesRead; - while (textLength > 0) { - convert_to_utf8(id,inPtr,&bytes,textBuffer,&textLength,&state); - InsertText(textBuffer,textLength,textOffset); - textOffset += textLength; - inPtr += bytes; - location += bytes; - bytesRead -= bytes; - bytes = bytesRead; - if (textLength > 0) { - textLength = 256; - } + uint32 id = BCharacterSetRoster::GetCharacterSetByFontID(fEncoding)->GetConversionID(); + SetText(""); + char inBuffer[256]; + off_t location = 0; + int32 textOffset = 0; + int32 state = 0; + int32 bytesRead; + while ((bytesRead = stream->ReadAt(location,inBuffer,256)) > 0) { + char * inPtr = inBuffer; + char textBuffer[256]; + int32 textLength = 256; + int32 bytes = bytesRead; + while (textLength > 0) { + convert_to_utf8(id,inPtr,&bytes,textBuffer,&textLength,&state); + InsertText(textBuffer,textLength,textOffset); + textOffset += textLength; + inPtr += bytes; + location += bytes; + bytesRead -= bytes; + bytes = bytesRead; + if (textLength > 0) { + textLength = 256; } } } @@ -168,27 +163,26 @@ StyledEditView::WriteStyledEditFile(BFile * file) if (result != B_OK) { return result; } - CharacterSetRoster * roster = CharacterSetRoster::Roster(&result); - if (result != B_OK) { - return result; - } - uint32 id = roster->FindCharacterSetByFontID(fEncoding)->GetConversionID(); - const char * outText = Text(); - int32 sourceLength = TextLength(); - int32 state = 0; - char buffer[256]; - while (sourceLength > 0) { - int32 length = sourceLength; - int32 written = 256; - result = convert_from_utf8(id,outText,&length,buffer,&written,&state); - if (result != B_OK) { - return result; + const BCharacterSet * cs = BCharacterSetRoster::GetCharacterSetByFontID(fEncoding); + if (cs != 0) { + uint32 id = cs->GetConversionID(); + const char * outText = Text(); + int32 sourceLength = TextLength(); + int32 state = 0; + char buffer[256]; + while (sourceLength > 0) { + int32 length = sourceLength; + int32 written = 256; + result = convert_from_utf8(id,outText,&length,buffer,&written,&state); + if (result != B_OK) { + return result; + } + file->Write(buffer,written); + sourceLength -= length; + outText += length; } - file->Write(buffer,written); - sourceLength -= length; - outText += length; + file->WriteAttr("be:encoding",B_INT32_TYPE,0,&id,sizeof(id)); } - file->WriteAttr("be:encoding",B_INT32_TYPE,0,&id,sizeof(id)); } alignment align = Alignment(); diff --git a/src/apps/stylededit/StyledEditWindow.cpp b/src/apps/stylededit/StyledEditWindow.cpp index 132baf9763..663e948817 100644 --- a/src/apps/stylededit/StyledEditWindow.cpp +++ b/src/apps/stylededit/StyledEditWindow.cpp @@ -15,9 +15,10 @@ #include #include #include +#include +#include //****** Application defined header files************/. -#include "CharacterSet.h" #include "Constants.h" #include "ColorMenuItem.h" #include "FindWindow.h" @@ -26,6 +27,8 @@ #include "StyledEditView.h" #include "StyledEditWindow.h" +using namespace BPrivate; + StyledEditWindow::StyledEditWindow(BRect frame, int32 id, uint32 encoding) : BWindow(frame,"untitled",B_DOCUMENT_WINDOW,0) { @@ -866,23 +869,22 @@ StyledEditWindow::SaveAs() fSavePanelEncodingMenu->SetRadioMode(true); status_t status = B_OK; - CharacterSetRoster * roster = CharacterSetRoster::Roster(&status); - if (status == B_OK) { - for (int index = 0; (index < roster->GetCharacterSetCount()) ; index++) { - const CharacterSet * cs = roster->GetCharacterSet(index); - BString name(cs->GetPrintName()); - const char * mime = cs->GetMIMEName(); - if (mime) { - name.Append(" ("); - name.Append(mime); - name.Append(")"); - } - BMenuItem * item = new BMenuItem(name.String(),new BMessage(SAVE_AS_ENCODING)); - item->SetTarget(this); - fSavePanelEncodingMenu->AddItem(item); - if (index == fTextView->GetEncoding()) { - item->SetMarked(true); - } + BCharacterSetRoster roster; + BCharacterSet charset; + int index = 0; + while (roster.GetNextCharacterSet(&charset) == B_NO_ERROR) { + BString name(charset.GetPrintName()); + const char * mime = charset.GetMIMEName(); + if (mime) { + name.Append(" ("); + name.Append(mime); + name.Append(")"); + } + BMenuItem * item = new BMenuItem(name.String(),new BMessage(SAVE_AS_ENCODING)); + item->SetTarget(this); + fSavePanelEncodingMenu->AddItem(item); + if (charset.GetFontID() == fTextView->GetEncoding()) { + item->SetMarked(true); } } }