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 ;
|
SubDir OBOS_TOP src apps stylededit ;
|
||||||
|
|
||||||
|
UsePrivateHeaders support ;
|
||||||
|
|
||||||
AddResources StyledEdit :
|
AddResources StyledEdit :
|
||||||
StyledEdit.rdef StyledEdit.icons.rdef StyledEdit.version.rdef
|
StyledEdit.rdef StyledEdit.icons.rdef StyledEdit.version.rdef
|
||||||
;
|
;
|
||||||
|
|
||||||
App StyledEdit :
|
App StyledEdit :
|
||||||
CharacterSet.cpp
|
|
||||||
ColorMenuItem.cpp
|
ColorMenuItem.cpp
|
||||||
FindWindow.cpp
|
FindWindow.cpp
|
||||||
ReplaceWindow.cpp
|
ReplaceWindow.cpp
|
||||||
StyledEditApp.cpp
|
StyledEditApp.cpp
|
||||||
StyledEditView.cpp
|
StyledEditView.cpp
|
||||||
StyledEditWindow.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 <Autolock.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <MenuItem.h>
|
#include <MenuItem.h>
|
||||||
#include "CharacterSet.h"
|
#include <CharacterSet.h>
|
||||||
|
#include <CharacterSetRoster.h>
|
||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
#include "StyledEditApp.h"
|
#include "StyledEditApp.h"
|
||||||
#include "StyledEditWindow.h"
|
#include "StyledEditWindow.h"
|
||||||
|
|
||||||
|
using namespace BPrivate;
|
||||||
|
|
||||||
BRect windowRect(7,26,507,426);
|
BRect windowRect(7,26,507,426);
|
||||||
|
|
||||||
StyledEditApp * styled_edit_app;
|
StyledEditApp * styled_edit_app;
|
||||||
@ -24,23 +27,21 @@ StyledEditApp::StyledEditApp()
|
|||||||
fOpenPanelEncodingMenu->SetRadioMode(true);
|
fOpenPanelEncodingMenu->SetRadioMode(true);
|
||||||
|
|
||||||
status_t status = B_OK;
|
status_t status = B_OK;
|
||||||
CharacterSetRoster * roster = CharacterSetRoster::Roster(&status);
|
BCharacterSetRoster roster;
|
||||||
if (status == B_OK) {
|
BCharacterSet charset;
|
||||||
for (int index = 0; (index < roster->GetCharacterSetCount()) ; index++) {
|
while (roster.GetNextCharacterSet(&charset) == B_NO_ERROR) {
|
||||||
const CharacterSet * cs = roster->GetCharacterSet(index);
|
BString name(charset.GetPrintName());
|
||||||
BString name(cs->GetPrintName());
|
const char * mime = charset.GetMIMEName();
|
||||||
const char * mime = cs->GetMIMEName();
|
if (mime) {
|
||||||
if (mime) {
|
name.Append(" (");
|
||||||
name.Append(" (");
|
name.Append(mime);
|
||||||
name.Append(mime);
|
name.Append(")");
|
||||||
name.Append(")");
|
}
|
||||||
}
|
BMenuItem * item = new BMenuItem(name.String(),new BMessage(OPEN_AS_ENCODING));
|
||||||
BMenuItem * item = new BMenuItem(name.String(),new BMessage(OPEN_AS_ENCODING));
|
item->SetTarget(this);
|
||||||
item->SetTarget(this);
|
fOpenPanelEncodingMenu->AddItem(item);
|
||||||
fOpenPanelEncodingMenu->AddItem(item);
|
if (charset.GetFontID() == fOpenAsEncoding) {
|
||||||
if (index == fOpenAsEncoding) {
|
item->SetMarked(true);
|
||||||
item->SetMarked(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,11 +5,14 @@
|
|||||||
#include <TranslationUtils.h>
|
#include <TranslationUtils.h>
|
||||||
#include <Node.h>
|
#include <Node.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <CharacterSet.h>
|
||||||
|
#include <CharacterSetRoster.h>
|
||||||
|
#include <UTF8.h>
|
||||||
|
|
||||||
#include "StyledEditView.h"
|
#include "StyledEditView.h"
|
||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
#include "CharacterSet.h"
|
|
||||||
#include "UTF8.h"
|
using namespace BPrivate;
|
||||||
|
|
||||||
StyledEditView::StyledEditView(BRect viewFrame, BRect textBounds, BHandler *handler)
|
StyledEditView::StyledEditView(BRect viewFrame, BRect textBounds, BHandler *handler)
|
||||||
: BTextView(viewFrame, "textview", textBounds,
|
: BTextView(viewFrame, "textview", textBounds,
|
||||||
@ -74,15 +77,10 @@ StyledEditView::GetStyledText(BPositionIO * stream)
|
|||||||
int32 encoding;
|
int32 encoding;
|
||||||
bytesRead = node->ReadAttr("be:encoding",0,0,&encoding,sizeof(encoding));
|
bytesRead = node->ReadAttr("be:encoding",0,0,&encoding,sizeof(encoding));
|
||||||
if (bytesRead > 0) {
|
if (bytesRead > 0) {
|
||||||
CharacterSetRoster * roster = CharacterSetRoster::Roster(&result);
|
|
||||||
if (result != B_OK) {
|
|
||||||
fSuppressChanges = false;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
if (encoding == 65535) {
|
if (encoding == 65535) {
|
||||||
fEncoding = 0;
|
fEncoding = 0;
|
||||||
} else {
|
} else {
|
||||||
const CharacterSet * cs = roster->FindCharacterSetByConversionID(encoding);
|
const BCharacterSet * cs = BCharacterSetRoster::GetCharacterSetByConversionID(encoding);
|
||||||
if (cs != 0) {
|
if (cs != 0) {
|
||||||
fEncoding = cs->GetFontID();
|
fEncoding = cs->GetFontID();
|
||||||
}
|
}
|
||||||
@ -114,31 +112,28 @@ StyledEditView::GetStyledText(BPositionIO * stream)
|
|||||||
if (fEncoding != 0) {
|
if (fEncoding != 0) {
|
||||||
int32 length = stream->Seek(0,SEEK_END);
|
int32 length = stream->Seek(0,SEEK_END);
|
||||||
text_run_array * run_array = RunArray(0,length);
|
text_run_array * run_array = RunArray(0,length);
|
||||||
CharacterSetRoster * roster = CharacterSetRoster::Roster(&result);
|
uint32 id = BCharacterSetRoster::GetCharacterSetByFontID(fEncoding)->GetConversionID();
|
||||||
if (result == B_OK) {
|
SetText("");
|
||||||
uint32 id = roster->FindCharacterSetByFontID(fEncoding)->GetConversionID();
|
char inBuffer[256];
|
||||||
SetText("");
|
off_t location = 0;
|
||||||
char inBuffer[256];
|
int32 textOffset = 0;
|
||||||
off_t location = 0;
|
int32 state = 0;
|
||||||
int32 textOffset = 0;
|
int32 bytesRead;
|
||||||
int32 state = 0;
|
while ((bytesRead = stream->ReadAt(location,inBuffer,256)) > 0) {
|
||||||
int32 bytesRead;
|
char * inPtr = inBuffer;
|
||||||
while ((bytesRead = stream->ReadAt(location,inBuffer,256)) > 0) {
|
char textBuffer[256];
|
||||||
char * inPtr = inBuffer;
|
int32 textLength = 256;
|
||||||
char textBuffer[256];
|
int32 bytes = bytesRead;
|
||||||
int32 textLength = 256;
|
while (textLength > 0) {
|
||||||
int32 bytes = bytesRead;
|
convert_to_utf8(id,inPtr,&bytes,textBuffer,&textLength,&state);
|
||||||
while (textLength > 0) {
|
InsertText(textBuffer,textLength,textOffset);
|
||||||
convert_to_utf8(id,inPtr,&bytes,textBuffer,&textLength,&state);
|
textOffset += textLength;
|
||||||
InsertText(textBuffer,textLength,textOffset);
|
inPtr += bytes;
|
||||||
textOffset += textLength;
|
location += bytes;
|
||||||
inPtr += bytes;
|
bytesRead -= bytes;
|
||||||
location += bytes;
|
bytes = bytesRead;
|
||||||
bytesRead -= bytes;
|
if (textLength > 0) {
|
||||||
bytes = bytesRead;
|
textLength = 256;
|
||||||
if (textLength > 0) {
|
|
||||||
textLength = 256;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -168,27 +163,26 @@ StyledEditView::WriteStyledEditFile(BFile * file)
|
|||||||
if (result != B_OK) {
|
if (result != B_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
CharacterSetRoster * roster = CharacterSetRoster::Roster(&result);
|
const BCharacterSet * cs = BCharacterSetRoster::GetCharacterSetByFontID(fEncoding);
|
||||||
if (result != B_OK) {
|
if (cs != 0) {
|
||||||
return result;
|
uint32 id = cs->GetConversionID();
|
||||||
}
|
const char * outText = Text();
|
||||||
uint32 id = roster->FindCharacterSetByFontID(fEncoding)->GetConversionID();
|
int32 sourceLength = TextLength();
|
||||||
const char * outText = Text();
|
int32 state = 0;
|
||||||
int32 sourceLength = TextLength();
|
char buffer[256];
|
||||||
int32 state = 0;
|
while (sourceLength > 0) {
|
||||||
char buffer[256];
|
int32 length = sourceLength;
|
||||||
while (sourceLength > 0) {
|
int32 written = 256;
|
||||||
int32 length = sourceLength;
|
result = convert_from_utf8(id,outText,&length,buffer,&written,&state);
|
||||||
int32 written = 256;
|
if (result != B_OK) {
|
||||||
result = convert_from_utf8(id,outText,&length,buffer,&written,&state);
|
return result;
|
||||||
if (result != B_OK) {
|
}
|
||||||
return result;
|
file->Write(buffer,written);
|
||||||
|
sourceLength -= length;
|
||||||
|
outText += length;
|
||||||
}
|
}
|
||||||
file->Write(buffer,written);
|
file->WriteAttr("be:encoding",B_INT32_TYPE,0,&id,sizeof(id));
|
||||||
sourceLength -= length;
|
|
||||||
outText += length;
|
|
||||||
}
|
}
|
||||||
file->WriteAttr("be:encoding",B_INT32_TYPE,0,&id,sizeof(id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
alignment align = Alignment();
|
alignment align = Alignment();
|
||||||
|
@ -15,9 +15,10 @@
|
|||||||
#include <TextControl.h>
|
#include <TextControl.h>
|
||||||
#include <TranslationUtils.h>
|
#include <TranslationUtils.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
#include <CharacterSet.h>
|
||||||
|
#include <CharacterSetRoster.h>
|
||||||
|
|
||||||
//****** Application defined header files************/.
|
//****** Application defined header files************/.
|
||||||
#include "CharacterSet.h"
|
|
||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
#include "ColorMenuItem.h"
|
#include "ColorMenuItem.h"
|
||||||
#include "FindWindow.h"
|
#include "FindWindow.h"
|
||||||
@ -26,6 +27,8 @@
|
|||||||
#include "StyledEditView.h"
|
#include "StyledEditView.h"
|
||||||
#include "StyledEditWindow.h"
|
#include "StyledEditWindow.h"
|
||||||
|
|
||||||
|
using namespace BPrivate;
|
||||||
|
|
||||||
StyledEditWindow::StyledEditWindow(BRect frame, int32 id, uint32 encoding)
|
StyledEditWindow::StyledEditWindow(BRect frame, int32 id, uint32 encoding)
|
||||||
: BWindow(frame,"untitled",B_DOCUMENT_WINDOW,0)
|
: BWindow(frame,"untitled",B_DOCUMENT_WINDOW,0)
|
||||||
{
|
{
|
||||||
@ -866,23 +869,22 @@ StyledEditWindow::SaveAs()
|
|||||||
fSavePanelEncodingMenu->SetRadioMode(true);
|
fSavePanelEncodingMenu->SetRadioMode(true);
|
||||||
|
|
||||||
status_t status = B_OK;
|
status_t status = B_OK;
|
||||||
CharacterSetRoster * roster = CharacterSetRoster::Roster(&status);
|
BCharacterSetRoster roster;
|
||||||
if (status == B_OK) {
|
BCharacterSet charset;
|
||||||
for (int index = 0; (index < roster->GetCharacterSetCount()) ; index++) {
|
int index = 0;
|
||||||
const CharacterSet * cs = roster->GetCharacterSet(index);
|
while (roster.GetNextCharacterSet(&charset) == B_NO_ERROR) {
|
||||||
BString name(cs->GetPrintName());
|
BString name(charset.GetPrintName());
|
||||||
const char * mime = cs->GetMIMEName();
|
const char * mime = charset.GetMIMEName();
|
||||||
if (mime) {
|
if (mime) {
|
||||||
name.Append(" (");
|
name.Append(" (");
|
||||||
name.Append(mime);
|
name.Append(mime);
|
||||||
name.Append(")");
|
name.Append(")");
|
||||||
}
|
}
|
||||||
BMenuItem * item = new BMenuItem(name.String(),new BMessage(SAVE_AS_ENCODING));
|
BMenuItem * item = new BMenuItem(name.String(),new BMessage(SAVE_AS_ENCODING));
|
||||||
item->SetTarget(this);
|
item->SetTarget(this);
|
||||||
fSavePanelEncodingMenu->AddItem(item);
|
fSavePanelEncodingMenu->AddItem(item);
|
||||||
if (index == fTextView->GetEncoding()) {
|
if (charset.GetFontID() == fTextView->GetEncoding()) {
|
||||||
item->SetMarked(true);
|
item->SetMarked(true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user