first start encodings menu up for save as

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3852 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
shatty 2003-07-05 00:51:07 +00:00
parent a162af3b0e
commit e6903129a7
5 changed files with 302 additions and 13 deletions

View File

@ -1,2 +1,257 @@
#include "CharacterSet.h"
#include "UTF8.h"
#include <strings.h>
CharacterSet::CharacterSet()
{
id = 0;
MIBenum = 0;
strcpy(print_name,"");
strcpy(iana_name,"");
mime_name = "";
aliases = NULL;
aliases_count = 0;
}
CharacterSetRoster::CharacterSetRoster()
{
// this information should be loaded from a file
character_sets_count = 10;
character_sets = new (CharacterSet*)[character_sets_count];
CharacterSet * cs;
{
cs = new CharacterSet();
cs->id = B_ISO1_CONVERSION; // a.k.a. 0
cs->MIBenum = 4;
strcpy(cs->print_name,"Latin 1");
strcpy(cs->iana_name,"ISO_8859-1:1987");
cs->aliases_count = 8;
cs->aliases = new (char*)[cs->aliases_count];
cs->aliases[0] = "iso-ir-100";
cs->aliases[1] = "ISO_8859-1";
cs->aliases[2] = cs->mime_name = "ISO-8859-1";
cs->aliases[3] = "latin1";
cs->aliases[4] = "11";
cs->aliases[5] = "IBM819";
cs->aliases[6] = "CP819";
cs->aliases[7] = "csISOLatin1";
character_sets[cs->id] = cs;
}
{
cs = new CharacterSet();
cs->id = B_ISO2_CONVERSION;
cs->MIBenum = 5;
strcpy(cs->print_name,"Latin 2");
strcpy(cs->iana_name,"ISO_8859-2:1987");
cs->aliases_count = 6;
cs->aliases = new (char*)[cs->aliases_count];
cs->aliases[0] = "iso-ir-101";
cs->aliases[1] = "ISO_8859-2";
cs->aliases[2] = cs->mime_name = "ISO-8859-2";
cs->aliases[3] = "latin2";
cs->aliases[4] = "12";
cs->aliases[5] = "csISOLatin2";
character_sets[cs->id] = cs;
}
{
cs = new CharacterSet();
cs->id = B_ISO3_CONVERSION;
cs->MIBenum = 6;
strcpy(cs->print_name,"Latin 3");
strcpy(cs->iana_name,"ISO_8859-3:1988");
cs->mime_name = cs->print_name;
cs->aliases_count = 6;
cs->aliases = new (char*)[cs->aliases_count];
cs->aliases[0] = "iso-ir-109";
cs->aliases[1] = "ISO_8859-3";
cs->aliases[2] = cs->mime_name = "ISO-8859-3";
cs->aliases[3] = "latin3";
cs->aliases[4] = "13";
cs->aliases[5] = "csISOLatin3";
character_sets[cs->id] = cs;
}
{
cs = new CharacterSet();
cs->id = B_ISO4_CONVERSION;
cs->MIBenum = 7;
strcpy(cs->print_name,"Latin 4");
strcpy(cs->iana_name,"ISO_8859-4:1988");
cs->aliases_count = 6;
cs->aliases = new (char*)[cs->aliases_count];
cs->aliases[0] = "iso-ir-110";
cs->aliases[1] = "ISO_8859-4";
cs->aliases[2] = cs->mime_name = "ISO-8859-4";
cs->aliases[3] = "latin4";
cs->aliases[4] = "14";
cs->aliases[5] = "csISOLatin4";
character_sets[cs->id] = cs;
}
{
cs = new CharacterSet();
cs->id = B_ISO5_CONVERSION;
cs->MIBenum = 8;
strcpy(cs->print_name,"Cyrillic");
strcpy(cs->iana_name,"ISO_8859-5:1988");
cs->aliases_count = 5;
cs->aliases = new (char*)[cs->aliases_count];
cs->aliases[0] = "iso-ir-144";
cs->aliases[1] = "ISO_8859-5";
cs->aliases[2] = cs->mime_name = "ISO-8859-5";
cs->aliases[3] = "cyrillic";
cs->aliases[4] = "csISOLatinCyrillic";
character_sets[cs->id] = cs;
}
{
cs = new CharacterSet();
cs->id = B_ISO6_CONVERSION;
cs->MIBenum = 9;
strcpy(cs->print_name,"Arabic");
strcpy(cs->iana_name,"ISO_8859-6:1987");
cs->aliases_count = 7;
cs->aliases = new (char*)[cs->aliases_count];
cs->aliases[0] = "iso-ir-127";
cs->aliases[1] = "ISO_8859-6";
cs->aliases[2] = cs->mime_name = "ISO-8859-6";
cs->aliases[5] = "ECMA-114";
cs->aliases[5] = "ASMO-708";
cs->aliases[5] = "arabic";
cs->aliases[6] = "csISOLatinArabic";
character_sets[cs->id] = cs;
}
{
cs = new CharacterSet();
cs->id = B_ISO7_CONVERSION;
cs->MIBenum = 10;
strcpy(cs->print_name,"Greek");
strcpy(cs->iana_name,"ISO_8859-7:1987");
cs->aliases_count = 8;
cs->aliases = new (char*)[cs->aliases_count];
cs->aliases[0] = "iso-ir-126";
cs->aliases[1] = "ISO_8859-7";
cs->aliases[2] = cs->mime_name = "ISO-8859-7";
cs->aliases[5] = "ELOT_928";
cs->aliases[5] = "ECMA-118";
cs->aliases[5] = "greek";
cs->aliases[6] = "greek8";
cs->aliases[7] = "csISOLatinGreek";
character_sets[cs->id] = cs;
}
{
cs = new CharacterSet();
cs->id = B_ISO8_CONVERSION;
cs->MIBenum = 11;
strcpy(cs->print_name,"Hebrew");
strcpy(cs->iana_name,"ISO_8859-8:1988");
cs->aliases_count = 5;
cs->aliases = new (char*)[cs->aliases_count];
cs->aliases[0] = "iso-ir-138";
cs->aliases[1] = "ISO_8859-8";
cs->aliases[2] = cs->mime_name = "ISO-8859-8";
cs->aliases[3] = "hebrew";
cs->aliases[4] = "csISOLatinHebrew";
character_sets[cs->id] = cs;
}
{
cs = new CharacterSet();
cs->id = B_ISO9_CONVERSION;
cs->MIBenum = 12;
strcpy(cs->print_name,"Latin 5");
strcpy(cs->iana_name,"ISO_8859-9:1989");
cs->aliases_count = 6;
cs->aliases = new (char*)[cs->aliases_count];
cs->aliases[0] = "iso-ir-148";
cs->aliases[1] = "ISO_8859-9";
cs->aliases[2] = cs->mime_name = "ISO-8859-9";
cs->aliases[3] = "latin5";
cs->aliases[4] = "15";
cs->aliases[5] = "csISOLatin5";
character_sets[cs->id] = cs;
}
{
cs = new CharacterSet();
cs->id = B_ISO10_CONVERSION;
cs->MIBenum = 12;
strcpy(cs->print_name,"Latin 6");
strcpy(cs->iana_name,"ISO_8859-10");
cs->mime_name = cs->iana_name;
cs->aliases_count = 5;
cs->aliases = new (char*)[cs->aliases_count];
cs->aliases[0] = "iso-ir-157";
cs->aliases[1] = "16";
cs->aliases[2] = "ISO-8859-10:1992";
cs->aliases[3] = "csISOLatin6";
cs->aliases[4] = "latin6";
character_sets[cs->id] = cs;
}
}
CharacterSetRoster * theRoster = NULL;
CharacterSetRoster *
CharacterSetRoster::Roster(status_t * outError)
{
// TODO: add synchronization protection
if (theRoster == NULL) {
theRoster = new CharacterSetRoster();
}
if (outError != NULL) {
*outError = (theRoster == NULL ? B_NO_MEMORY : B_OK);
}
return theRoster;
}
CharacterSetRoster *
CharacterSetRoster::CurrentRoster()
{
return theRoster;
}
const CharacterSet *
CharacterSetRoster::FindCharacterSetByFontID(uint32 id)
{
return character_sets[id - 1];
}
const CharacterSet *
CharacterSetRoster::FindCharacterSetByConversionID(uint32 id)
{
return character_sets[id];
}
const CharacterSet *
CharacterSetRoster::FindCharacterSetByMIBenum(uint32 MIBenum)
{
for (int id = 0 ; (id < character_sets_count) ; id++) {
if (character_sets[id]->MIBenum == MIBenum) {
return character_sets[id];
}
}
return 0;
}
const CharacterSet *
CharacterSetRoster::FindCharacterSetByPrintName(char * name)
{
for (int id = 0 ; (id < character_sets_count) ; id++) {
if (strcmp(character_sets[id]->print_name,name) == 0) {
return character_sets[id];
}
}
return 0;
}
const CharacterSet *
CharacterSetRoster::FindCharacterSetByName(char * name)
{
for (int id = 0 ; (id < character_sets_count) ; id++) {
if (strcmp(character_sets[id]->iana_name,name) == 0) {
return character_sets[id];
}
for (int alias = 0 ; (alias < character_sets[id]->aliases_count) ; alias++) {
if (strcmp(character_sets[id]->aliases[alias],name) == 0) {
return character_sets[id];
}
}
}
return 0;
}

View File

@ -1,6 +1,8 @@
#ifndef CHARACTER_SET_H
#define CHARACTER_SET_H
#include <SupportDefs.h>
/*! CharacterSet holds a variety of useful information about
each character set. This information has been derived from the
IANA standards organization. Since IANA provides several names
@ -9,32 +11,32 @@
@see http://www.iana.org/assignments/character-sets
*/
class CharacterSetRoster;
class CharacterSet {
public:
CharacterSet();
//! returns an id suitable for use in BFont::SetEncoding
uint32 GetFontID() { return id + 1; }
uint32 GetFontID() const { return id + 1; }
//! returns an id suitable for use in convert_to_utf8/convert_from_utf8
uint32 GetConversionID() { return id; }
uint32 GetConversionID() const { return id; }
//! returns an id for use in MIBs to identify coded character sets
uint32 GetMIBenum() { return MIBenum; }
uint32 GetMIBenum() const { return MIBenum; }
//! returns the standard IANA name for this character set
const char * GetName() { return iana_name; }
const char * GetName() const { return iana_name; }
//! returns a user interface friendly name for this character set
const char * GetPrintName() { return print_name; }
const char * GetPrintName() const { return print_name; }
//! returns the preferred MIME name for this character set
//! or null if none exists
const char * GetMIMEName() { return mime_name; }
const char * GetMIMEName() const { return mime_name; }
//! returns an array of aliases for this character set
//! or null if none exist
const char ** GetAliases(int32 & out_size) {
const char * const * GetAliases(int32 & out_size) const {
out_size = aliases_count;
return aliases;
}
@ -48,6 +50,9 @@ private:
char **aliases; //! aliases for this character set
uint32 aliases_count; //! how many aliases are available
uint32 padding[16];
private:
CharacterSet();
friend class CharacterSetRoster;
};
/*! the CharacterSetRoster is used to obtain a CharacterSet object
@ -55,13 +60,20 @@ private:
*/
class CharacterSetRoster {
private:
CharacterSetRoster();
public:
static CharacterSetRoster * Roster(status_t * outError = NULL);
static CharacterSetRoster * CurrentRoster(void);
const CharacterSet * FindCharacterSetByFontID(uint32 id);
const CharacterSet * FindCharacterSetByConversionID(uint32 id);
const CharacterSet * FindCharacterSetByMIBenum(uint32 MIBenum);
const CharacterSet * FindCharacterSetByPrintName(char * name);
const CharacterSet * FindCharacterSetByName(char * name);
uint32 GetCharacterSetCount() const { return character_sets_count; }
private:
CharacterSet * character_sets;
CharacterSet ** character_sets;
uint32 character_sets_count;
};
#endif CHARACTER_SET_H

View File

@ -59,4 +59,6 @@ const uint32 DISABLE_ITEMS ='DIit';
const uint32 CHANGE_WINDOW ='CHwi';
const uint32 TEXT_CHANGED ='TEch';
const uint32 SAVE_AS_ENCODING ='SAen';
#endif // CONSTANTS_H

View File

@ -4,12 +4,15 @@ AddResources StyledEdit :
StyledEdit.rdef StyledEdit.icons.rdef StyledEdit.version.rdef
;
App StyledEdit : ColorMenuItem.cpp
App StyledEdit :
CharacterSet.cpp
ColorMenuItem.cpp
FindWindow.cpp
ReplaceWindow.cpp
StyledEditApp.cpp
StyledEditView.cpp
StyledEditWindow.cpp ;
StyledEditWindow.cpp
;
LinkSharedOSLibs StyledEdit : be translation tracker ;

View File

@ -17,6 +17,7 @@
#include <Window.h>
//****** Application defined header files************/.
#include "CharacterSet.h"
#include "Constants.h"
#include "ColorMenuItem.h"
#include "FindWindow.h"
@ -852,9 +853,25 @@ StyledEditWindow::SaveAs()
fSavePanelEncodingMenu= new BMenu("Encoding");
menuBar->AddItem(fSavePanelEncodingMenu);
fSavePanelEncodingMenu->SetRadioMode(true);
status_t status = B_OK;
CharacterSetRoster * roster = CharacterSetRoster::Roster(&status);
if (status == B_OK) {
for (int id = 0; (id < roster->GetCharacterSetCount()) ; id++) {
const CharacterSet * cs = roster->FindCharacterSetByConversionID(id);
BString name(cs->GetPrintName());
name.Append(" (");
name.Append(cs->GetMIMEName());
name.Append(")");
BMenuItem * item = new BMenuItem(name.String(),new BMessage(SAVE_AS_ENCODING));
item->SetTarget(this);
fSavePanelEncodingMenu->AddItem(item);
}
}
}
// it's own scope allows the lock to be released before Show()
// its own scope allows the lock to be released before Show()
{
// TODO: add encodings
BAutolock lock(fSavePanel->Window());