/**** ファイル名 : cccheck.h ****/
#ifndef CCCHECKH #define CCCHECKH //--------------------------------------------------------------------- #include <Be.h> #include <string.h> //--------------------------------------------------------------------- const uint32 ccBCType[7]={B_UNICODE_CONVERSION,B_UNICODE_CONVERSION, B_JIS_CONVERSION,B_SJIS_CONVERSION, B_EUC_CONVERSION,B_SJIS_CONVERSION, B_UNICODE_CONVERSION}; enum CCODETYPE {ccBINARY,ccASCII,ccJIS,ccSJIS,ccEUC,ccSJISorEUC,ccOther}; enum CRETURNCODE {rcLF,rcCRLF}; void CheckCharCodeType(const unsigned char *sce,enum CCODETYPE &code, enum CRETURNCODE &ret,const long checklen=1024); //--------------------------------------------------------------------- #endif
/**** ファイル名 : MainWindow.cpp ****/
//--------------------------------------------------------------------- void BEditorWindow::OpenFile(BEntry *entry) { if(entry->Exists()) { BFile fil; off_t size; BString str; unsigned char *buf; try { fil.SetTo(entry,B_READ_ONLY | B_FAIL_IF_EXISTS); fil.GetSize(&size); buf=(unsigned char *)malloc(size); fil.ReadAt(0,buf,size); CheckCharCodeType(buf,fcode,fret); if(ccBCType[fcode]!=B_UNICODE_CONVERSION) { int32 buflen,buf2len,state=0; str.SetTo('\0',size*2); char *buf2=str.LockBuffer(size*2); buflen=size; buf2len=size*2; convert_to_utf8(ccBCType[fcode],(char *)buf, &buflen,buf2,&buf2len,&state); str.UnlockBuffer(); } else str.SetTo((char *)buf); if(fret==rcCRLF) str.ReplaceAll("\r\n","\n"); mainview->memo->SetText(str.String()); free(buf); fil.Unset(); SetFileName(entry); } catch(...) { BAlert *altmsg = new BAlert("Error", "File read failed!!","OK", NULL,NULL,B_WIDTH_AS_USUAL, B_WARNING_ALERT); altmsg->Go(); } } } //---------------------------------------------------------------------
/**** ファイル名 : MainWindow.cpp ****/
//--------------------------------------------------------------------- void BEditorWindow::SaveFile(BEntry *entry) { BFile fil; off_t wsize; off_t tsize; BString str; try { fil.SetTo(entry,B_READ_WRITE | B_CREATE_FILE); str.SetTo(mainview->memo->Text()); if(fret==rcCRLF) str.ReplaceAll("\n","\r\n"); if(ccBCType[fcode]==B_UNICODE_CONVERSION) { tsize=str.Length(); wsize=fil.WriteAt(0,str.String(),tsize); } else { int32 buflen,buf2len,state=0; buf2len=str.Length(); buflen=buf2len*2; char *buf=(char *)malloc(buflen); convert_from_utf8(ccBCType[fcode],str.String(), &buf2len,buf,&buflen,&state); tsize=buflen; wsize=fil.WriteAt(0,buf,tsize); free(buf); } if(tsize==wsize) { SetFileName(entry); if(save_to_quit) PostMessage(new BMessage(B_QUIT_REQUESTED)); } } catch(...) { BAlert *altmsg = new BAlert("Error", "File write failed!!","OK", NULL,NULL,B_WIDTH_AS_USUAL, B_WARNING_ALERT); altmsg->Go(); } } //---------------------------------------------------------------------
BMenu *filemenu=new BMenu("File");
filemenu->AddItem(new BMenuItem("Open...",new BMessage(MSG_OPEN)));
filemenu->ItemAt(0)->SetTarget(be_app);
filemenu->AddItem(new BMenuItem("New Text",new BMessage(MSG_ADDEDITOR)));
filemenu->ItemAt(1)->SetTarget(be_app);
filemenu->AddItem(new BMenuItem("Save",new BMessage(MSG_SAVE)));
filemenu->ItemAt(2)->Message()->AddBool("to_quit",false);
filemenu->AddItem(new BMenuItem("Save As...",new BMessage(MSG_SAVEAS)));
filemenu->ItemAt(3)->Message()->AddBool("to_quit",false);
savemenu=new BMenu("Character Code");
savemenu->AddItem(new BMenuItem("UTF8",new BMessage(MSG_CCODECHANGE)));
savemenu->ItemAt(0)->Message()->AddInt32("code",ccASCII);
savemenu->AddItem(new BMenuItem("SJIS",new BMessage(MSG_CCODECHANGE)));
savemenu->ItemAt(1)->Message()->AddInt32("code",ccSJIS);
savemenu->AddItem(new BMenuItem("JIS",new BMessage(MSG_CCODECHANGE)));
savemenu->ItemAt(2)->Message()->AddInt32("code",ccJIS);
savemenu->AddItem(new BMenuItem("EUC",new BMessage(MSG_CCODECHANGE)));
savemenu->ItemAt(3)->Message()->AddInt32("code",ccEUC);
savemenu->AddSeparatorItem();
savemenu->AddItem(new BMenuItem("LF",new BMessage(MSG_CRETCHANGE)));
savemenu->ItemAt(5)->Message()->AddInt32("ret",rcLF);
savemenu->AddItem(new BMenuItem("CR/LF",new BMessage(MSG_CRETCHANGE)));
savemenu->ItemAt(6)->Message()->AddInt32("ret",rcCRLF);
filemenu->AddItem(savemenu);
filemenu->AddSeparatorItem();
filemenu->AddItem(new BMenuItem("Close",new BMessage(B_QUIT_REQUESTED)));
filemenu->AddSeparatorItem();
filemenu->AddItem(new BMenuItem("Quit",new BMessage(MSG_QUIT)));
filemenu->ItemAt(8)->SetTarget(be_app);
mainmenu->AddItem(filemenu);
/**** ファイル名 : MainWindow.cpp ****/
//-------------------------------------------------------------------- void BEditorWindow::SetCCodeToMenu(void) { const int MenuIdxCode[7]={0,0,2,1,3,1,0}; //Menu Index const int MenuIdxRet[2]={5,6}; //Menu Index for(int i=0;i<mainview->savemenu->CountItems();i++) mainview->savemenu->ItemAt(i)->SetMarked(false); mainview->savemenu->ItemAt(MenuIdxCode[fcode])->SetMarked(true); mainview->savemenu->ItemAt(MenuIdxRet[fret])->SetMarked(true); } //--------------------------------------------------------------------
case MSG_CCODECHANGE:
{
int32 i;
msg->FindInt32("code",&i);
fcode=(enum CCODETYPE)i;
SetCCodeToMenu();
}
break;
case MSG_CRETCHANGE:
{
int32 i;
msg->FindInt32("ret",&i);
fret=(enum CRETURNCODE)i;
SetCCodeToMenu();
}
break;
| 圧縮ファイル R5 Intel環境で確認 |
BTinyEditor20000628.zip |
| ソースファイル | BTinyEditor.cpp |
| BTinyEditor.h | |
| BFindWindow.cpp | |
| BFindWindow.h | |
| BMemoView.cpp | |
| BMemoView.h | |
| cccheck.cpp | |
| cccheck.h | |
| main.cpp | |
| MainWindow.cpp | |
| MainWindow.h |