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
This commit is contained in:
parent
a4b6e788fc
commit
46555d8f43
@ -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 <src!apps!stylededit>CharacterSet.cpp += [ FDirName $(OBOS_TOP) src kits support ] ;
|
||||
SEARCH on <src!apps!stylededit>CharacterSetRoster.cpp += [ FDirName $(OBOS_TOP) src kits support ] ;
|
||||
SEARCH on <src!apps!stylededit>character_sets.cpp += [ FDirName $(OBOS_TOP) src kits support ] ;
|
||||
|
||||
LinkSharedOSLibs StyledEdit : be translation tracker textencoding ;
|
||||
|
@ -2,11 +2,14 @@
|
||||
#include <Autolock.h>
|
||||
#include <Path.h>
|
||||
#include <MenuItem.h>
|
||||
#include "CharacterSet.h"
|
||||
#include <CharacterSet.h>
|
||||
#include <CharacterSetRoster.h>
|
||||
#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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,11 +5,14 @@
|
||||
#include <TranslationUtils.h>
|
||||
#include <Node.h>
|
||||
#include <stdio.h>
|
||||
#include <CharacterSet.h>
|
||||
#include <CharacterSetRoster.h>
|
||||
#include <UTF8.h>
|
||||
|
||||
#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();
|
||||
|
@ -15,9 +15,10 @@
|
||||
#include <TextControl.h>
|
||||
#include <TranslationUtils.h>
|
||||
#include <Window.h>
|
||||
#include <CharacterSet.h>
|
||||
#include <CharacterSetRoster.h>
|
||||
|
||||
//****** 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user