From f7afd44bda63d8eb9a9bc62683fbfc73b6b232b7 Mon Sep 17 00:00:00 2001 From: Phil Greenway Date: Mon, 23 Sep 2002 23:01:55 +0000 Subject: [PATCH] Initial Check in. Coded by Mattias Sundblad. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1135 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/stylededit/ColorMenuItem.cpp | 19 + src/apps/stylededit/ColorMenuItem.h | 14 + src/apps/stylededit/Constants.h | 75 ++ src/apps/stylededit/FindWindow.cpp | 156 ++++ src/apps/stylededit/FindWindow.h | 32 + src/apps/stylededit/ReplaceWindow.cpp | 198 +++++ src/apps/stylededit/ReplaceWindow.h | 31 + src/apps/stylededit/StyledEditApp.cpp | 91 +++ src/apps/stylededit/StyledEditApp.h | 32 + src/apps/stylededit/StyledEditView.cpp | 93 +++ src/apps/stylededit/StyledEditView.h | 34 + src/apps/stylededit/StyledEditWindow.cpp | 952 +++++++++++++++++++++++ src/apps/stylededit/StyledEditWindow.h | 100 +++ 13 files changed, 1827 insertions(+) create mode 100644 src/apps/stylededit/ColorMenuItem.cpp create mode 100644 src/apps/stylededit/ColorMenuItem.h create mode 100644 src/apps/stylededit/Constants.h create mode 100644 src/apps/stylededit/FindWindow.cpp create mode 100644 src/apps/stylededit/FindWindow.h create mode 100644 src/apps/stylededit/ReplaceWindow.cpp create mode 100644 src/apps/stylededit/ReplaceWindow.h create mode 100644 src/apps/stylededit/StyledEditApp.cpp create mode 100644 src/apps/stylededit/StyledEditApp.h create mode 100644 src/apps/stylededit/StyledEditView.cpp create mode 100644 src/apps/stylededit/StyledEditView.h create mode 100644 src/apps/stylededit/StyledEditWindow.cpp create mode 100644 src/apps/stylededit/StyledEditWindow.h diff --git a/src/apps/stylededit/ColorMenuItem.cpp b/src/apps/stylededit/ColorMenuItem.cpp new file mode 100644 index 0000000000..beb61bedc7 --- /dev/null +++ b/src/apps/stylededit/ColorMenuItem.cpp @@ -0,0 +1,19 @@ +#ifndef _MENU_ITEM_H +#include +#endif + +#ifndef COLOR_MENU_ITEM_H +#include "ColorMenuItem.h" +#endif + +ColorMenuItem::ColorMenuItem(const char *label, rgb_color color,BMessage *message) + :BMenuItem(label, message,0,0){ + fItemColor= color; +} + +void ColorMenuItem::DrawContent(){ + + BMenu *menu= Menu(); + menu->SetHighColor(fItemColor); + BMenuItem::DrawContent(); +} diff --git a/src/apps/stylededit/ColorMenuItem.h b/src/apps/stylededit/ColorMenuItem.h new file mode 100644 index 0000000000..f1851d9893 --- /dev/null +++ b/src/apps/stylededit/ColorMenuItem.h @@ -0,0 +1,14 @@ +#ifndef COLOR_MENU_ITEM_H +#define COLOR_MENU_ITEM_H + +class ColorMenuItem: public BMenuItem { + public: + ColorMenuItem(const char *label, rgb_color color, BMessage *message); + protected: + virtual void DrawContent(); + private: + rgb_color fItemColor; + +}; +#endif + diff --git a/src/apps/stylededit/Constants.h b/src/apps/stylededit/Constants.h new file mode 100644 index 0000000000..46ffbcbcf8 --- /dev/null +++ b/src/apps/stylededit/Constants.h @@ -0,0 +1,75 @@ +/*StyledEdit: constants*/ +#ifndef CONSTANTS_H +#define CONSTANTS_H + +#ifndef _GRAPHICS_DEFS_H +#include +#endif + +#ifndef _SUPPORT_DEFS_H +#include +#endif + +#define APP_SIGNATURE "application/x-vnd.obos-stylededit" + +const float MENU_BAR_HEIGHT= 19.0; +const float TEXT_INSET= 3.0; + +/*Messages for window registry with application*/ +const uint32 WINDOW_REGISTRY_ADD= 'WRad'; +const uint32 WINDOW_REGISTRY_SUB='WRsb'; +const uint32 WINDOW_REGISTRY_ADDED='WRdd'; +/*Messages for menu commands +file menu*/ +const uint32 MENU_NEW ='MFnw'; +const uint32 MENU_OPEN ='MFop'; +const uint32 MENU_SAVE ='MSav'; +const uint32 MENU_SAVEAS ='MEsa'; +const uint32 MENU_REVERT ='MFre'; +const uint32 MENU_CLOSE ='MFcl'; +const uint32 MENU_PAGESETUP ='MFps'; +const uint32 MENU_PRINT ='MFpr'; +const uint32 MENU_QUIT ='MFqu'; +//edit menu +const uint32 MENU_CLEAR ='MEcl'; +const uint32 MENU_FIND ='MEfi'; +const uint32 MENU_FIND_AGAIN ='MEfa'; +const uint32 MENU_FIND_SELECTION ='MEfs'; +const uint32 MENU_REPLACE ='MEre'; +const uint32 MENU_REPLACE_SAME ='MErs'; + +const uint32 MSG_SEARCH ='msea'; +const uint32 MSG_REPLACE ='msre'; +const uint32 MSG_REPLACE_ALL ='mrea'; +//"Font"-menu +const uint32 FONT_SIZE ='FMsi'; +const uint32 FONT_STYLE ='FSch'; +const uint32 FONT_COLOR ='Fcol'; + +//fontcolors +//red, green, blue, alphachannel +const rgb_color BLACK = {0, 0, 0, 255}; +const rgb_color RED = {255, 0, 0, 255}; +const rgb_color GREEN = {0, 255, 0, 255}; +const rgb_color BLUE = {0, 0, 255, 255}; +const rgb_color CYAN = {0, 255, 255, 255}; +const rgb_color MAGENTA = {255, 0, 255, 255}; +const rgb_color YELLOW = {255, 255, 0, 255}; + +//"Document"-menu +const uint32 ALIGN_LEFT ='ALle'; +const uint32 ALIGN_CENTER ='ALce'; +const uint32 ALIGN_RIGHT ='ALri'; +const uint32 WRAP_LINES ='MDwr'; + +//enables "edit" menuitems +const uint32 ENABLE_ITEMS ='ENit'; +const uint32 DISABLE_ITEMS ='DIit'; +const uint32 CHANGE_WINDOW ='CHwi'; +const uint32 TEXT_CHANGED ='TEch'; + + +#endif + + + diff --git a/src/apps/stylededit/FindWindow.cpp b/src/apps/stylededit/FindWindow.cpp new file mode 100644 index 0000000000..482a1a5604 --- /dev/null +++ b/src/apps/stylededit/FindWindow.cpp @@ -0,0 +1,156 @@ +#ifndef _BUTTON_H +#include +#endif + +#ifndef _CHECK_BOX_H +#include +#endif + +#ifndef _STRING_H +#include +#endif + +#ifndef _TEXT_CONTROL_H +#include +#endif + +#ifndef _WINDOW_H +#include +#endif + +#ifndef CONSTANTS_H +#include "Constants.h" +#endif + +#ifndef FIND_WINDOW_H +#include "FindWindow.h" +#endif + + + +// FindWindow::FindWindow() +FindWindow::FindWindow(BRect frame, BHandler *_handler, BString *searchString, bool *caseState, bool *wrapState, bool *backState) + : BWindow(frame," ", B_MODAL_WINDOW, + B_NOT_RESIZABLE,B_CURRENT_WORKSPACE) { + + AddChild(fFindView=new BView(Bounds(),"",B_FOLLOW_ALL_SIDES,B_WILL_DRAW)); + fFindView->SetViewColor(216,216,216); + + fFindView->AddChild(fSearchString= new BTextControl(BRect(14,12,277,30), "", "Find:", NULL, NULL, + B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); + fSearchString->SetDivider(27); + fFindView->AddChild(fCaseSensBox= new BCheckBox(BRect(44,36,162,52),"","Case-sensitive", NULL, + B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); + fFindView->AddChild(fWrapBox= new BCheckBox(BRect(44,58,190,73),"","Wrap-around search", NULL, + B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); + fFindView->AddChild(fBackSearchBox= new BCheckBox(BRect(44,79,179,95),"","Search backwards", NULL, + B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); + + fFindView->AddChild(fCancelButton= new BButton(BRect(131,108,191,128),"","Cancel",new BMessage(B_QUIT_REQUESTED), + B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); + fFindView->AddChild(fSearchButton= new BButton(BRect(210,107,277,127),"","Find",new BMessage(MSG_SEARCH), + B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); + + fSearchButton->MakeDefault(true); + fHandler=_handler; + + const char *text= searchString->String(); + + fSearchString->SetText(text); + + if(*caseState== true) + fCaseSensBox->SetValue(B_CONTROL_ON); + else + fCaseSensBox->SetValue(B_CONTROL_OFF); + + if(*wrapState== true) + fWrapBox->SetValue(B_CONTROL_ON); + else + fWrapBox->SetValue(B_CONTROL_OFF); + + if(*backState== true) + fBackSearchBox->SetValue(B_CONTROL_ON); + else + fBackSearchBox->SetValue(B_CONTROL_OFF); + + Show(); +} + +void FindWindow::MessageReceived(BMessage *msg){ + switch(msg->what){ + case B_QUIT_REQUESTED: + QuitRequested(); + break; + case MSG_SEARCH: + ExtractToMsg(new BMessage(MSG_SEARCH)); + break; + default: + BWindow::MessageReceived(msg); + break; + } +} + +void FindWindow::DispatchMessage(BMessage *message, BHandler *handler) + +{ + int8 key; + + if ( message->what == B_KEY_DOWN ) { + status_t result; + result= message->FindInt8("byte", 0, &key); + + if (result== B_OK){ + if (key== B_ESCAPE){ + message-> MakeEmpty(); + message-> what= B_QUIT_REQUESTED; + } + } + } + BWindow::DispatchMessage(message,handler); +} + +void FindWindow::ExtractToMsg(BMessage *message){ + + int32 caseBoxState; + int32 wrapBoxState; + int32 backBoxState; + + caseBoxState= fCaseSensBox-> Value(); + wrapBoxState= fWrapBox-> Value(); + backBoxState= fBackSearchBox-> Value(); + + bool caseSens; + bool wrapIt; + bool backSearch; + + if(caseBoxState== B_CONTROL_ON) + caseSens=true; + else + caseSens= false; + + if(wrapBoxState== B_CONTROL_ON) + wrapIt= true; + else + wrapIt= false; + + if(backBoxState== B_CONTROL_ON) + backSearch= true; + else + backSearch= false; + + //Add the string + message->AddString("findtext",fSearchString->Text()); + + //Add searchparameters from checkboxes + message->AddBool("casesens", caseSens); + message->AddBool("wrap", wrapIt); + message->AddBool("backsearch", backSearch); + + fHandler->Looper()->PostMessage(message,fHandler); + delete(message); + PostMessage(B_QUIT_REQUESTED); +} + + + + diff --git a/src/apps/stylededit/FindWindow.h b/src/apps/stylededit/FindWindow.h new file mode 100644 index 0000000000..c2bc6c5fd4 --- /dev/null +++ b/src/apps/stylededit/FindWindow.h @@ -0,0 +1,32 @@ +#ifndef FIND_WINDOW_H +#define FIND_WINDOW_H + +class FindWindow : public BWindow { + public: + FindWindow(BRect frame, BHandler* handler, BString *searchString, bool *caseState, bool *wrapState, bool *backState); + + virtual void MessageReceived(BMessage* message); + virtual void DispatchMessage(BMessage* message, BHandler* handler); + + + private: + void ExtractToMsg(BMessage *message); + + BView *fFindView; + BTextControl *fSearchString; + BCheckBox *fCaseSensBox; + BCheckBox *fWrapBox; + BCheckBox *fBackSearchBox; + BButton *fCancelButton; + BButton *fSearchButton; + + BHandler *fHandler; + +}; +#endif + + + + + + diff --git a/src/apps/stylededit/ReplaceWindow.cpp b/src/apps/stylededit/ReplaceWindow.cpp new file mode 100644 index 0000000000..6c61b0ed35 --- /dev/null +++ b/src/apps/stylededit/ReplaceWindow.cpp @@ -0,0 +1,198 @@ +#ifndef _BUTTON_H +#include +#endif + +#ifndef _CHECK_BOX_H +#include +#endif + +#ifndef _STRING_H +#include +#endif + +#ifndef _TEXT_CONTROL_H +#include +#endif + +#ifndef _WINDOW_H +#include +#endif + +#ifndef CONSTANTS_H +#include "Constants.h" +#endif + +#ifndef REPLACE_WINDOW_H +#include "ReplaceWindow.h" +#endif + +ReplaceWindow::ReplaceWindow(BRect frame, BHandler *_handler, BString *searchString, BString *replaceString, bool *caseState, bool *wrapState, bool *backState) + : BWindow(frame, "", B_MODAL_WINDOW, B_NOT_RESIZABLE,B_CURRENT_WORKSPACE) + { + + fReplaceView=new BView(Bounds(),"",B_FOLLOW_ALL_SIDES,B_WILL_DRAW); + fReplaceView->SetViewColor(216,216,216); + fReplaceView->AddChild (fSearchString= new BTextControl(BRect(5,10,290,50), "", "Find:",NULL, NULL, + B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); + fSearchString->SetDivider(65); + fReplaceView->AddChild(fReplaceString=new BTextControl(BRect(5,35,290,50), "", "Replace with:",NULL, + NULL,B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); + fReplaceString->SetDivider(65); + + fReplaceView->AddChild(fCaseSensBox=new BCheckBox(BRect(72,60,162,52),"","Case-sensitive", NULL, + B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); + fReplaceView->AddChild(fWrapBox=new BCheckBox(BRect(72,80,195,70),"","Wrap-around search", NULL, + B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); + fReplaceView->AddChild(fBackSearchBox=new BCheckBox(BRect(72,100,179,95),"","Search backwards", NULL, + B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); + fReplaceView->AddChild(fAllWindowsBox=new BCheckBox(BRect(72,120,195,95),"","Replace in all windows", + new BMessage(CHANGE_WINDOW) ,B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); + fUichange=false; + + //vertical separator at 110 in StyledEdit + fReplaceView->AddChild(fReplaceAllButton=new BButton(BRect(10,150,98,166),"","Replace All",new BMessage(MSG_REPLACE_ALL), + B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); + fReplaceView->AddChild(fCancelButton=new BButton(BRect(141,150,211,166),"","Cancel",new BMessage(B_QUIT_REQUESTED), + B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); + fReplaceView->AddChild(fReplaceButton=new BButton(BRect(221,150,291,166),"","Replace",new BMessage(MSG_REPLACE), + B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); + fReplaceButton->MakeDefault(true); + + AddChild(fReplaceView); + fHandler=_handler; + + const char *searchtext= searchString->String(); + const char *replacetext= replaceString->String(); + + fSearchString->SetText(searchtext); + fReplaceString->SetText(replacetext); + + if(*caseState== true) + fCaseSensBox->SetValue(B_CONTROL_ON); + else + fCaseSensBox->SetValue(B_CONTROL_OFF); + + if(*wrapState== true) + fWrapBox->SetValue(B_CONTROL_ON); + else + fWrapBox->SetValue(B_CONTROL_OFF); + + if(*backState== true) + fBackSearchBox->SetValue(B_CONTROL_ON); + else + fBackSearchBox->SetValue(B_CONTROL_OFF); + + Show(); +} + +void ReplaceWindow::MessageReceived(BMessage *msg){ + switch(msg->what){ + case B_QUIT_REQUESTED: + QuitRequested(); + break; + case MSG_REPLACE: + ExtractToMsg(new BMessage(MSG_REPLACE)); + break; + case CHANGE_WINDOW: + ChangeUi(); + break; + case MSG_REPLACE_ALL: + ExtractToMsg(new BMessage(MSG_REPLACE_ALL)); + break; + default: + BWindow::MessageReceived(msg); + break; + } +} + +void ReplaceWindow::ChangeUi(){ + + if(!fUichange){ + fReplaceAllButton->MakeDefault(true); + fReplaceButton->SetEnabled(false); + fWrapBox->SetValue(B_CONTROL_ON); + fWrapBox->SetEnabled(false); + fBackSearchBox->SetEnabled(false); + fUichange=true; + } + else{ + fReplaceButton->MakeDefault(true); + fReplaceButton->SetEnabled(true); + fReplaceAllButton->SetEnabled(true); + fWrapBox->SetValue(B_CONTROL_OFF); + fWrapBox->SetEnabled(true); + fBackSearchBox->SetEnabled(true); + fUichange=false; + } + +}/***ReplaceWindow::ChangeUi()***/ + +void ReplaceWindow::DispatchMessage(BMessage *message, BHandler *fHandler){ + int8 key; + if ( message->what == B_KEY_DOWN ) { + status_t result; + result= message-> FindInt8("byte", 0, &key); + + if (result== B_OK) { + if(key== B_ESCAPE){ + message-> MakeEmpty(); + message-> what= B_QUIT_REQUESTED; + } + } + } + BWindow::DispatchMessage(message,fHandler); +} + +void ReplaceWindow::ExtractToMsg(BMessage *message ){ + + int32 caseBoxState; + int32 wrapBoxState; + int32 backBoxState; + int32 allWinBoxState; + + caseBoxState= fCaseSensBox-> Value(); + wrapBoxState= fWrapBox-> Value(); + backBoxState= fBackSearchBox-> Value(); + allWinBoxState= fAllWindowsBox-> Value(); + + bool caseSens; + bool wrapIt; + bool backSearch; + bool allWindows; + + if(caseBoxState== B_CONTROL_ON) + caseSens= true; + else + caseSens= false; + + if(wrapBoxState== B_CONTROL_ON) + wrapIt= true; + else + wrapIt= false; + + if(backBoxState== B_CONTROL_ON) + backSearch= true; + else + backSearch= false; + + if(allWinBoxState== B_CONTROL_ON) + allWindows= true; + else + allWindows= false; + + message->AddString("FindText",fSearchString->Text()); + message->AddString("ReplaceText",fReplaceString->Text()); + message->AddBool("casesens", caseSens); + message->AddBool("wrap", wrapIt); + message->AddBool("backsearch", backSearch); + message->AddBool("allwindows", allWindows); + + fHandler->Looper()->PostMessage(message,fHandler); + delete(message); + PostMessage(B_QUIT_REQUESTED); +} + + + + + diff --git a/src/apps/stylededit/ReplaceWindow.h b/src/apps/stylededit/ReplaceWindow.h new file mode 100644 index 0000000000..986cd3286d --- /dev/null +++ b/src/apps/stylededit/ReplaceWindow.h @@ -0,0 +1,31 @@ +#ifndef REPLACE_WINDOW_H +#define REPLACE_WINDOW_H + +class ReplaceWindow : public BWindow { + public: + ReplaceWindow(BRect frame, BHandler *_handler,BString *searchString, + BString *replaceString, bool *caseState, bool *wrapState, bool *backState); + + virtual void MessageReceived(BMessage* message); + virtual void DispatchMessage(BMessage* message, BHandler *handler); + + + private: + void ExtractToMsg(BMessage *message); + void ChangeUi(); + BView *fReplaceView; + BTextControl *fSearchString; + BTextControl *fReplaceString; + BCheckBox *fCaseSensBox; + BCheckBox *fWrapBox; + BCheckBox *fBackSearchBox; + BCheckBox *fAllWindowsBox; + BButton *fReplaceButton; + BButton *fReplaceAllButton; + BButton *fCancelButton; + BHandler *fHandler; + bool fUichange; +}; + +#endif + diff --git a/src/apps/stylededit/StyledEditApp.cpp b/src/apps/stylededit/StyledEditApp.cpp new file mode 100644 index 0000000000..221831a32d --- /dev/null +++ b/src/apps/stylededit/StyledEditApp.cpp @@ -0,0 +1,91 @@ + +#ifndef CONSTANTS_H +#include "Constants.h" +#endif + +#ifndef STYLED_EDIT_APP +#include "StyledEditApp.h" +#endif + + +BRect windowRect(50,50,599,399); + +StyledEditApp::StyledEditApp() + : BApplication(APP_SIGNATURE) + { + + new StyledEditWindow(windowRect); + fOpenPanel= new BFilePanel; + + fWindowCount= 0; + fNext_Untitled_Window= 1; + } /***StyledEditApp::StyledEditApp()***/ + + +void StyledEditApp::MessageReceived(BMessage *message){ + switch(message->what){ + case MENU_OPEN: + fOpenPanel->Show(); // + break; + case WINDOW_REGISTRY_ADD: + { + bool need_id= false; + BMessage reply(WINDOW_REGISTRY_ADDED); + + if(message->FindBool("need_id", &need_id)== B_OK) + { + if(need_id) + { + reply.AddInt32("new_window_number", fNext_Untitled_Window); + fNext_Untitled_Window++; + } + fWindowCount++; + } + reply.AddRect("rect",windowRect); + windowRect.OffsetBy(20,20); + message->SendReply(&reply); + break; + } + case WINDOW_REGISTRY_SUB: + fWindowCount--; + if (!fWindowCount) + { + Quit(); + } + break; + default: + BApplication::MessageReceived(message); + break; + } +} + +void StyledEditApp::RefsReceived(BMessage *message){ + + int32 refNum; + entry_ref ref; + status_t err; + + refNum=0; + do{ + if((err= message->FindRef("refs", refNum, &ref)) != B_OK) + return; + new StyledEditWindow(windowRect, &ref); + refNum++; + } while(1); +} /***StyledEditApp::RefsReceived();***/ + +int32 StyledEditApp::NumberOfWindows(){ + + return fWindowCount; + +}/***StyledEditApp::NumberOfWindows()***/ + +int main(){ + StyledEditApp StyledEdit; + StyledEdit.Run(); + return 0; + } + + + + \ No newline at end of file diff --git a/src/apps/stylededit/StyledEditApp.h b/src/apps/stylededit/StyledEditApp.h new file mode 100644 index 0000000000..d7d2fda0cf --- /dev/null +++ b/src/apps/stylededit/StyledEditApp.h @@ -0,0 +1,32 @@ +/**StyledEdit: Application class*/ +#ifndef STYLED_EDIT_APP +#define STYLED_EDIT_APP + +#ifndef _APPLICATION_H +#include +#endif + +#ifndef STYLED_EDIT_WINDOW_H +#include "StyledEditWindow.h" +#endif + +class StyledEditApp: public BApplication{ + public: + StyledEditApp(); + virtual void MessageReceived(BMessage *message); + virtual void RefsReceived(BMessage *message); + int32 NumberOfWindows(); + + + private: + BFilePanel *fOpenPanel; + int32 fWindowCount; + int32 fNext_Untitled_Window; + +}; +#endif + + + + + diff --git a/src/apps/stylededit/StyledEditView.cpp b/src/apps/stylededit/StyledEditView.cpp new file mode 100644 index 0000000000..1fe2db9282 --- /dev/null +++ b/src/apps/stylededit/StyledEditView.cpp @@ -0,0 +1,93 @@ +#ifndef STYLED_EDIT_VIEW_H +#include "StyledEditView.h" +#endif + +#ifndef _MESSAGE_H +#include +#endif + +#ifndef CONSTANTS_H +#include "Constants.h" +#endif + +#ifndef _MESSENGER_H +#include +#endif + +#ifndef _RECT_H +#include +#endif + + + +StyledEditView::StyledEditView(BRect viewFrame, BRect textBounds, BHandler *handler) : BTextView(viewFrame, "textview", + textBounds, B_FOLLOW_ALL, B_FRAME_EVENTS|B_WILL_DRAW){ + fHandler= handler; + fMessenger= new BMessenger(handler); + }/***StyledEditView()***/ + + StyledEditView::~StyledEditView(){ + + }/***~StyledEditView***/ + +void StyledEditView::FrameResized(float width, float height){ + BTextView::FrameResized(width, height); + + if(DoesWordWrap()){ + BRect textRect; + textRect= Bounds(); + textRect.OffsetTo(B_ORIGIN); + textRect.InsetBy(TEXT_INSET,TEXT_INSET); + SetTextRect(textRect); + } +} + +void StyledEditView::Select(int32 start, int32 finish){ + + if(start==finish) + fChangeMessage= new BMessage(DISABLE_ITEMS); + else + fChangeMessage= new BMessage(ENABLE_ITEMS); + + fMessenger->SendMessage(fChangeMessage); + + BTextView::Select(start, finish); +} + +void StyledEditView::InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs){ + + fMessenger-> SendMessage(new BMessage(TEXT_CHANGED)); + + BTextView::InsertText(text, length, offset, runs); + +}/****StyledEditView::InsertText()***/ + +void StyledEditView::DeleteText(int32 start, int32 finish){ + + fMessenger-> SendMessage(new BMessage(TEXT_CHANGED)); + + BTextView::DeleteText(start, finish); + +}/***StyledEditView::DeleteText***/ + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/apps/stylededit/StyledEditView.h b/src/apps/stylededit/StyledEditView.h new file mode 100644 index 0000000000..8093af0f84 --- /dev/null +++ b/src/apps/stylededit/StyledEditView.h @@ -0,0 +1,34 @@ +#ifndef STYLED_EDIT_VIEW_H +#define STYLED_EDIT_VIEW_H + +#ifndef _TEXTVIEW_H +#include +#endif + +class StyledEditView : public BTextView { + public: + StyledEditView(BRect viewframe, BRect textframe, BHandler *handler); + ~StyledEditView(); + + virtual void Select(int32 start, int32 finish); + virtual void FrameResized(float width, float height); + protected: + virtual void InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs); + virtual void DeleteText(int32 start, int32 finish); + + private: + BHandler *fHandler; + BMessage *fChangeMessage; + BMessenger *fMessenger; +}; +#endif + + + + + + + + + + diff --git a/src/apps/stylededit/StyledEditWindow.cpp b/src/apps/stylededit/StyledEditWindow.cpp new file mode 100644 index 0000000000..78ab7eee02 --- /dev/null +++ b/src/apps/stylededit/StyledEditWindow.cpp @@ -0,0 +1,952 @@ +// Be-defined headers + +#ifndef _ALERT_H +#include +#endif + +#ifndef _CLIPBOARD_H +#include +#endif + +#ifndef _FILE_H +#include +#endif + +#ifndef _MENU_H +#include +#endif + +#ifndef _MENU_ITEM_H +#include +#endif + +#ifndef _PRINTSESSION_H +#include +#endif + +#ifndef _SCROLL_VIEW_H +#include +#endif + +#ifndef _STDLIB_H +#include +#endif + +#ifndef _STRING_H +#include +#endif + +#ifndef _TRANSLATION_UTILS_H +#include +#endif + +#ifndef _WINDOW_H +#include +#endif + +//****** Application defined header files************/. +#ifndef CONSTANTS_H +#include "Constants.h" +#endif + +#ifndef COLOR_MENU_ITEM_H +#include "ColorMenuItem.h" +#endif + +#ifndef FIND_WINDOW_H +#include "FindWindow.h" +#endif + +#ifndef REPLACE_WINDOW_H +#include "ReplaceWindow.h" +#endif + +#ifndef STYLED_EDIT_APP +#include "StyledEditApp.h" +#endif + +#ifndef STYLED_EDIT_VIEW_H +#include "StyledEditView.h" +#endif + +#ifndef STYLED_EDIT_WINDOW_H +#include "StyledEditWindow.h" +#endif + +StyledEditWindow::StyledEditWindow(BRect frame) + : BWindow(frame,"untitled",B_DOCUMENT_WINDOW,0){ + InitWindow(); + Show(); + }/***StyledEditWindow()***/ + +StyledEditWindow::StyledEditWindow(BRect frame, entry_ref *ref) + : BWindow(frame,"untitled",B_DOCUMENT_WINDOW,0) + { + InitWindow(); + OpenFile(ref); + Show(); + } /***StyledEditWindow()***/ + +StyledEditWindow::~StyledEditWindow(){ + Unregister(); + + if(fSaveMessage) + delete fSaveMessage; + if(fPrintSettings) + delete fPrintSettings; + + delete fSavePanel; +}/***~StyledEditWindow()***/ + +void StyledEditWindow::InitWindow(){ + + fPrintSettings= NULL; + fSaveMessage= NULL; + fEnableItems= false; + fFirstEdit= true; + fUnDoneFlag= false; + fTextSaved= true; //initial state, no text changed. + + //search- state + fReplaceString= ""; + fStringToFind=""; + fCaseSens= false; + fWrapAround= false; + fBackSearch= false; + + //add menubar + BRect menuBarRect; + + menuBarRect= Bounds(); + fMenuBar= new BMenuBar(menuBarRect,"menubar"); + + AddChild(fMenuBar); + + //add textview and scrollview + BRect viewFrame; + BRect textBounds; + + viewFrame= Bounds(); + + viewFrame.top = MENU_BAR_HEIGHT+1; + viewFrame.right -= B_V_SCROLL_BAR_WIDTH; + viewFrame.bottom -= B_H_SCROLL_BAR_HEIGHT; + + + textBounds= viewFrame; + textBounds.OffsetTo(B_ORIGIN); + textBounds.InsetBy(TEXT_INSET, TEXT_INSET); + + + fTextView= new StyledEditView(viewFrame, textBounds, this); + fTextView-> SetDoesUndo(true); + fTextView-> SetStylable(true); + fTextView-> MakeFocus(true); + + fScrollView= new BScrollView("scrollview", fTextView, B_FOLLOW_ALL, 0, true, true, B_NO_BORDER); + AddChild(fScrollView); + + + + //Add "File"-menu: + BMenu *menu; + BMenu *subMenu; + BMenuItem *menuItem; + + menu= new BMenu("File"); + fMenuBar-> AddItem(menu); + + menu-> AddItem(menuItem= new BMenuItem("New", new BMessage(MENU_NEW), 'N')); + menu-> AddItem(menuItem= new BMenuItem("Open..", new BMessage(MENU_OPEN))); + menuItem->SetTarget(be_app); + menu-> AddSeparatorItem(); + + menu-> AddItem(fSaveItem= new BMenuItem("Save", new BMessage(MENU_SAVE), 'S')); + fSaveItem-> SetEnabled(false); + menu-> AddItem(menuItem= new BMenuItem("Save as", new BMessage(MENU_SAVEAS))); + menuItem-> SetEnabled(true); + + menu-> AddItem(menuItem= new BMenuItem("Revert to Saved", new BMessage(MENU_REVERT))); + menuItem-> SetEnabled(true); + menu-> AddItem(menuItem= new BMenuItem("Close", new BMessage(MENU_CLOSE), 'W')); + + menu-> AddSeparatorItem(); + menu-> AddItem(menuItem= new BMenuItem("Page Setup" B_UTF8_ELLIPSIS, new BMessage(MENU_PAGESETUP))); + menu-> AddItem(menuItem= new BMenuItem("Print" B_UTF8_ELLIPSIS, new BMessage(MENU_PRINT), 'P')); + + menu-> AddSeparatorItem(); + menu-> AddItem(menuItem= new BMenuItem("Quit", new BMessage(MENU_QUIT), 'Q')); + + //Add the "Edit"-menu: + menu= new BMenu("Edit"); + fMenuBar-> AddItem(menu); + + menu-> AddItem(fUndoItem= new BMenuItem("Can't Undo", new BMessage(B_UNDO), 'Z')); + fUndoItem-> SetEnabled(false); + fUndoItem-> SetTarget(fTextView); + + menu-> AddSeparatorItem(); + menu-> AddItem(fCutItem= new BMenuItem("Cut", new BMessage(B_CUT), 'X')); + fCutItem->SetEnabled(false); + fCutItem-> SetTarget(fTextView); + + menu-> AddItem(fCopyItem= new BMenuItem("Copy", new BMessage(B_COPY), 'C')); + fCopyItem-> SetEnabled(false); + fCopyItem-> SetTarget(fTextView); + + menu-> AddItem(menuItem= new BMenuItem("Paste", new BMessage(B_PASTE), 'V')); + menuItem-> SetTarget(fTextView); + menu-> AddItem(fClearItem= new BMenuItem("Clear", new BMessage(MENU_CLEAR))); + fClearItem-> SetEnabled(false); + fClearItem-> SetTarget(fTextView); + + + menu-> AddSeparatorItem(); + menu-> AddItem(menuItem=new BMenuItem("Select All", new BMessage(B_SELECT_ALL), 'A')); + menuItem-> SetTarget(fTextView); + + menu-> AddSeparatorItem(); + menu-> AddItem(menuItem= new BMenuItem("Find", new BMessage(MENU_FIND),'F')); + menu-> AddItem(menuItem= new BMenuItem("Find Again",new BMessage(MENU_FIND_AGAIN),'G')); + menu-> AddItem(menuItem= new BMenuItem("Find Selection", new BMessage(MENU_FIND_SELECTION),'H')); + menu-> AddItem(menuItem= new BMenuItem("Replace", new BMessage(MENU_REPLACE),'R')); + menu-> AddItem(menuItem= new BMenuItem("Replace Same", new BMessage(MENU_REPLACE_SAME),'T')); + + //Add the "Font"-menu: + BMessage *fontMessage; + menu= new BMenu("Font"); + fMenuBar-> AddItem(menu); + + //"Size"-subMenu + subMenu=new BMenu("Size"); + subMenu-> SetRadioMode(true); + menu-> AddItem(subMenu); + + subMenu-> AddItem(menuItem= new BMenuItem("9", fontMessage= new BMessage(FONT_SIZE))); + fontMessage-> AddFloat("size", 9.0); + + subMenu-> AddItem(menuItem= new BMenuItem("10", fontMessage= new BMessage(FONT_SIZE))); + fontMessage-> AddFloat("size",10.0); + menuItem-> SetMarked(true); + + subMenu-> AddItem(menuItem= new BMenuItem("12", fontMessage= new BMessage(FONT_SIZE))); + fontMessage-> AddFloat("size",12.0); + subMenu-> AddItem(menuItem= new BMenuItem("14", fontMessage= new BMessage(FONT_SIZE))); + fontMessage-> AddFloat("size",14.0); + subMenu-> AddItem(menuItem= new BMenuItem("18", fontMessage= new BMessage(FONT_SIZE))); + fontMessage-> AddFloat("size",18.0); + + subMenu-> AddItem(menuItem= new BMenuItem("24", fontMessage= new BMessage(FONT_SIZE))); + fontMessage-> AddFloat("size",24.0); + subMenu-> AddItem(menuItem= new BMenuItem("36", fontMessage= new BMessage(FONT_SIZE))); + fontMessage-> AddFloat("size",36.0); + subMenu-> AddItem(menuItem= new BMenuItem("48", fontMessage= new BMessage(FONT_SIZE))); + fontMessage-> AddFloat("size",48.0); + subMenu-> AddItem(menuItem= new BMenuItem("72", fontMessage= new BMessage(FONT_SIZE))); + fontMessage-> AddFloat("size",72.0); + + //"Color"-subMenu + subMenu= new BMenu("Color"); + subMenu->SetRadioMode(true); + menu-> AddItem(subMenu); + + ColorMenuItem *ColorItem; + + subMenu-> AddItem(menuItem= new BMenuItem("Black", fontMessage= new BMessage(FONT_COLOR))); + fontMessage-> AddPointer("colour",&BLACK); + menuItem-> SetMarked(true); + subMenu-> AddItem(ColorItem= new ColorMenuItem("Red", RED, fontMessage= new BMessage(FONT_COLOR))); + fontMessage-> AddPointer("colour", &RED); + subMenu-> AddItem(ColorItem= new ColorMenuItem("Green", GREEN, fontMessage= new BMessage(FONT_COLOR))); + fontMessage-> AddPointer("colour", &GREEN); + subMenu-> AddItem(ColorItem= new ColorMenuItem("Blue", BLUE, fontMessage= new BMessage(FONT_COLOR))); + fontMessage-> AddPointer("colour", &BLUE); + subMenu-> AddItem(ColorItem= new ColorMenuItem("Cyan", CYAN, fontMessage= new BMessage(FONT_COLOR))); + fontMessage-> AddPointer("colour",&CYAN); + subMenu-> AddItem(ColorItem= new ColorMenuItem("Magenta", MAGENTA, fontMessage= new BMessage(FONT_COLOR))); + fontMessage-> AddPointer("colour", &MAGENTA); + subMenu-> AddItem(ColorItem= new ColorMenuItem("Yellow", YELLOW, fontMessage= new BMessage(FONT_COLOR))); + fontMessage-> AddPointer("colour", &YELLOW); + menu->AddSeparatorItem(); + + //Available fonts + + int32 numFamilies = count_font_families(); + for ( int32 i = 0; i < numFamilies; i++ ) { + font_family localfamily; + if ( get_font_family ( i, &localfamily ) == B_OK ) { + subMenu=new BMenu(localfamily); + subMenu-> SetRadioMode(true); + menu->AddItem(subMenu); + menu->SetRadioMode(true); + int32 numStyles=count_font_styles(localfamily); + for(int32 j = 0;j AddItem(menuItem= new BMenuItem(style, fontMessage= new BMessage(FONT_STYLE))); + fontMessage-> AddString("FontFamily", localfamily); + fontMessage-> AddString("FontStyle", style); + } + } + } + } + + //Add the "Document"-menu: + menu= new BMenu("Document"); + fMenuBar-> AddItem(menu); + + //"Align"-subMenu: + subMenu= new BMenu("Align"); + subMenu-> SetRadioMode(true); + subMenu-> AddItem(menuItem= new BMenuItem("Left", new BMessage(ALIGN_LEFT))); + menuItem-> SetMarked(true); + + subMenu-> AddItem(menuItem= new BMenuItem("Center", new BMessage(ALIGN_CENTER))); + subMenu-> AddItem(menuItem= new BMenuItem("Right", new BMessage(ALIGN_RIGHT))); + menu-> AddItem(subMenu); + menu-> AddItem(fWrapItem= new BMenuItem("Wrap Lines", new BMessage(WRAP_LINES))); + fWrapItem-> SetMarked(true); + /***************************MENUS ADDED***********************/ + + + fSavePanel= new BFilePanel(B_SAVE_PANEL, new BMessenger(this), NULL, B_FILE_NODE, false); + Register(true); + Minimize(true); + } /***StyledEditWindow::Initwindow()***/ + + void StyledEditWindow::MessageReceived(BMessage *message){ + switch(message->what){ + case WINDOW_REGISTRY_ADDED: + { + + BRect rect; + if (message->FindInt32("new_window_number", &fWindow_Id) == B_OK) + { + if (!fSaveMessage) + { + BString unTitled; + unTitled.SetTo("Untitled "); + unTitled << fWindow_Id; + const char *title= unTitled.String(); + SetTitle(title); + } + } + if (message->FindRect("rect", &rect) == B_OK) + { + MoveTo(rect.LeftTop()); + ResizeTo(rect.Width(), rect.Height()); + } + Minimize(false); + } + break; +/************file menu:***************/ + case MENU_NEW: + { + BRect newViewFrame; + newViewFrame= Frame(); + new StyledEditWindow(newViewFrame); + } + break; + case MENU_SAVE: + { + if(!fSaveMessage) + fSavePanel->Show(); + else + Save(fSaveMessage); + } + break; + case MENU_SAVEAS: + fSavePanel->Show(); + break; + case B_SAVE_REQUESTED: + Save(message); + break; + case MENU_REVERT: + RevertToSaved(); + break; + case MENU_CLOSE:{ + if(this->QuitRequested()) + Quit(); + } + break; + case MENU_PAGESETUP: + PageSetup(fTextView->Window()->Title()); + break; + case MENU_PRINT: + Print(fTextView->Window()->Title()); + break; + case MENU_QUIT: + be_app->PostMessage(B_QUIT_REQUESTED); + break; +/*********commands from the "Edit"-menu:**************/ + case B_UNDO: + fTextView->Undo(be_clipboard); + break; + case B_CUT: + fTextView->Cut(be_clipboard); + break; + case B_COPY: + fTextView->Copy(be_clipboard); + break; + case B_PASTE: + fTextView->Paste(be_clipboard); + break; + case MENU_CLEAR: + fTextView->Clear(); + break; + case MENU_FIND: + { + BRect findWindowFrame(100,100,400,235); + FindWindow *find; + find= new FindWindow(findWindowFrame, this, &fStringToFind, &fCaseSens, + &fWrapAround, &fBackSearch); + } + break; + case MSG_SEARCH: + { + message->FindString("findtext", &fStringToFind); + message->FindBool("casesens", &fCaseSens); + message->FindBool("wrap", &fWrapAround); + message->FindBool("backsearch", &fBackSearch); + + Search(fStringToFind, fCaseSens, fWrapAround, fBackSearch); + } + break; + case MENU_FIND_AGAIN: + Search(fStringToFind, fCaseSens, fWrapAround, fBackSearch); + break; + case MENU_FIND_SELECTION: + FindSelection(); + break; + case MENU_REPLACE: + { + BRect replaceWindowFrame(100,100,400,284); + ReplaceWindow *replace; + replace= new ReplaceWindow(replaceWindowFrame, this, &fStringToFind, &fReplaceString, &fCaseSens, + &fWrapAround, &fBackSearch); + } + break; + case MSG_REPLACE: + { + BString findIt; + BString replaceWith; + bool caseSens, wrap, backSearch; + + message->FindBool("casesens", &caseSens); + message->FindBool("wrap", &wrap); + message->FindBool("backsearch", &backSearch); + + + message->FindString("FindText",&findIt); + message->FindString("ReplaceText",&replaceWith); + fStringToFind= findIt; + fReplaceString= replaceWith; + fCaseSens= caseSens; + fWrapAround= wrap; + fBackSearch= backSearch; + + Replace(findIt, replaceWith, caseSens, wrap, backSearch); + } + break; + case MSG_REPLACE_ALL: + { + BString findIt; + BString replaceWith; + bool caseSens, allWindows; + + message->FindBool("casesens", &caseSens); + message->FindString("FindText",&findIt); + message->FindString("ReplaceText",&replaceWith); + message->FindBool("allwindows", &allWindows); + + fStringToFind= findIt; + fReplaceString= replaceWith; + fCaseSens= caseSens; + + + if(allWindows) + SearchAllWindows(findIt, replaceWith, caseSens); + else + ReplaceAll(findIt, replaceWith,caseSens); + + } + break; + /*********"Font"-menu*****************/ + case FONT_SIZE: + { + float fontSize; + message->FindFloat("size",&fontSize); + SetFontSize(fontSize); + } + break; + case FONT_STYLE: + { + const char *fontFamily,*fontStyle; + message-> FindString("FontFamily",&fontFamily); + message-> FindString("FontStyle",&fontStyle); + SetFontStyle(fontFamily, fontStyle); + } + break; + case FONT_COLOR: + { + void *v; + rgb_color *color; + + message-> FindPointer("colour",&v); + color= (rgb_color *) v; + SetFontColor(color); + } + break; + /*********"Document"-menu*************/ + case ALIGN_LEFT: + fTextView->SetAlignment(B_ALIGN_LEFT); + break; + case ALIGN_CENTER: + fTextView->SetAlignment(B_ALIGN_CENTER); + break; + case ALIGN_RIGHT: + fTextView->SetAlignment(B_ALIGN_RIGHT); + break; + case WRAP_LINES: + if(fTextView->DoesWordWrap()){ + fTextView->SetWordWrap(false); + fWrapItem->SetMarked(false); + } + else{ + fTextView->SetWordWrap(true); + fWrapItem->SetMarked(true); + } + break; + case ENABLE_ITEMS: + { + fCutItem->SetEnabled(true); + fCopyItem->SetEnabled(true); + fClearItem->SetEnabled(true); + } + break; + case DISABLE_ITEMS: + { + fCutItem->SetEnabled(false); + fCopyItem->SetEnabled(false); + fClearItem->SetEnabled(false); + } + break; + case TEXT_CHANGED: + { + fSaveItem-> SetEnabled(true); + fTextSaved= false; + + if(fFirstEdit){ + fUndoItem-> SetLabel("Undo Typing"); + fUndoItem-> SetEnabled(true); + } + + if (fUnDoneFlag){ + fUndoItem->SetLabel("Redo Typing"); + fUnDoneFlag= false; + } + else{ + fUndoItem->SetLabel("Undo Typing"); + fUnDoneFlag= true; + } + + } + break; + default: + BWindow::MessageReceived(message); + break; + } + }/***StyledEditWindow::MessageReceived() ***/ + + +void StyledEditWindow::Register(bool need_id) { + BMessenger messenger(APP_SIGNATURE); + BMessage message(WINDOW_REGISTRY_ADD); + + message.AddBool("need_id", need_id); + messenger.SendMessage(&message, this); +}/***Register()***/ + + +void StyledEditWindow::Unregister(void){ + BMessenger messenger(APP_SIGNATURE); + messenger.SendMessage(new BMessage(WINDOW_REGISTRY_SUB)); +}/***Unregister()***/ + + +bool StyledEditWindow::QuitRequested(){ + + int32 buttonIndex= 0; + + if(!fTextSaved){ + BAlert *saveAlert; + BString alertText; + alertText.SetTo("Save changes to the document "); + alertText<< Title(); + alertText<<"? "; + saveAlert= new BAlert("savealert",alertText.String(), "Cancel", "Don't save","Save", + B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT); + saveAlert-> SetShortcut(0, B_ESCAPE); + buttonIndex= saveAlert-> Go(); + + + if(buttonIndex==0) //"cancel": dont save, dont close the window + return false; + else if(buttonIndex==1) // "don't save": just close the window + return true; + else if(!fSaveMessage){ //save as + DispatchMessage(new BMessage(MENU_SAVEAS), this); + return false; + } + else{ + DispatchMessage(new BMessage(B_SAVE_REQUESTED), this); + return true; + } + } + else + return true; + +}/***QuitRequested()***/ + +status_t StyledEditWindow::Save(BMessage *message){ + entry_ref ref; + const char *name; + status_t err; + + if(!message){ + message=fSaveMessage; + if(!message) + return B_ERROR; + } + + err= message->FindRef("directory", &ref); + if(err!= B_OK) + return err; + + err=message->FindString("name", &name); + if (err!= B_OK) + return err; + + BDirectory dir(&ref); + err= dir.InitCheck(); + if(err!= B_OK) + return err; + + BFile file(&dir, name, B_READ_WRITE | B_CREATE_FILE); + + err= file.InitCheck(); + if(err!= B_OK) + return err; + + err= BTranslationUtils::WriteStyledEditFile(fTextView, &file); + + if(err>= 0) + { + SetTitle(name); + fSaveItem->SetEnabled(true); + if(fSaveMessage!= message) + { + delete fSaveMessage; + fSaveMessage= new BMessage(*message); + } + } + + fSaveItem-> SetEnabled(false); + fTextSaved= true; + return err; +} /***Save()***/ + +void StyledEditWindow::OpenFile(entry_ref *ref){ + + BFile file; + status_t fileinit; + + fileinit= file.SetTo(ref, B_READ_ONLY); + + if(fileinit== B_OK){ + status_t result; + result= BTranslationUtils::GetStyledText(&file, fTextView, NULL); //he he he :) + + if(result==B_OK){ + fSaveMessage= new BMessage(B_SAVE_REQUESTED); + if(fSaveMessage){ + BEntry entry(ref, true); + BEntry parent; + entry_ref parentRef; + char name[B_FILE_NAME_LENGTH]; + + entry.GetParent(&parent); + entry.GetName(name); + parent.GetRef(&parentRef); + fSaveMessage->AddRef("directory",&parentRef); + fSaveMessage->AddString("name", name); + SetTitle(name); + } + } + } +}/*** StyledEditWindow::OpenFile() ***/ + +void StyledEditWindow::RevertToSaved(){ + //translationutils here as well + entry_ref ref; + const char *name; + + fSaveMessage->FindRef("directory", &ref); + fSaveMessage->FindString("name", &name); + + BDirectory dir(&ref); + + BFile file(&dir, name, B_READ_ONLY | B_CREATE_FILE); + fTextView->SetText(""); //clear the textview... + BTranslationUtils::GetStyledText(&file, fTextView, NULL); //and fill it from the file +}/***StyledEditWindow::RevertToSaved()***/ + +status_t StyledEditWindow::PageSetup(const char *documentname){ + + status_t result= B_ERROR; + + BPrintJob printJob(documentname); + + if (fPrintSettings!= NULL) + printJob.SetSettings(fPrintSettings); + //else + //; ///?? + + result= printJob.ConfigPage(); + + if (result== B_NO_ERROR){ + delete fPrintSettings; + fPrintSettings= printJob.Settings(); + } + + return result; +}/***StyledEditWindow::PageSetup()***/ + +void StyledEditWindow::Print(const char *documentname){ + + BPrintJob printJob(documentname); + + if (fPrintSettings== NULL){ + status_t pageSetup; + pageSetup= PageSetup(fTextView->Window()->Title()); + + if (pageSetup!= B_NO_ERROR) + return; + } + else + printJob.SetSettings(fPrintSettings); + + status_t configCheck; + configCheck= printJob.ConfigJob(); + if (configCheck== B_NO_ERROR){ + int32 currentPage= 1; + int32 firstPage; + int32 lastPage; + int32 pagesInDocument; + BRect pageRect; + BRect currentPageRect; + + pageRect= printJob.PrintableRect(); + currentPageRect= pageRect; + //not sure about this.... + BRect docRect; + docRect= fTextView->TextRect(); + pagesInDocument= (int32)(docRect.Height()+ (pageRect.Height()-1) / pageRect.Height()); + + firstPage= printJob.FirstPage(); + lastPage= printJob.LastPage(); + + if(lastPage> pagesInDocument) + lastPage= pagesInDocument; + + printJob.BeginJob(); + + for(currentPage= firstPage;currentPage<= lastPage;currentPage++){ + currentPageRect.OffsetTo(0, currentPage* pageRect.Height()); + printJob.DrawView(fTextView, currentPageRect, BPoint(0.0, 0.0)); + printJob.SpoolPage(); + } + printJob.CommitJob(); + } +}/***StyledEditWindow::Print()***/ + +bool StyledEditWindow::Search(BString string, bool casesens, bool wrap, bool backsearch){ + + int32 start; + int32 finish; + int32 strlen; + + start= B_ERROR; + + strlen= string.Length(); + if (strlen== 0) + return false; + + BString viewText; + viewText.SetTo(fTextView->Text()); + int32 textStart, textFinish; + fTextView->GetSelection(&textStart, &textFinish); + //case insensitive, non wrap seems to be default in SE... + if(casesens== true) + start= viewText.FindFirst(string, textFinish); + else if(wrap== true) + start= viewText.IFindFirst(string); + else if(backsearch== true) + start= viewText.IFindLast(string, textStart); + else + start= viewText.IFindFirst(string, textFinish); //i.e this one... + + + if(start!= B_ERROR){ + finish= start+ strlen; + fTextView->Select(start, finish); + fTextView->ScrollToSelection(); + return true; + } else + return false; + +}/***StyledEditWindow::Search***/ + +void StyledEditWindow::FindSelection(){ + + int32 selectionStart, selectionFinish; + fTextView->GetSelection(&selectionStart,&selectionFinish); + + int32 selectionLength; + selectionLength= selectionFinish- selectionStart; + + BString viewText; + viewText= fTextView->Text(); + + viewText.CopyInto(fStringToFind, selectionStart, selectionLength); + Search(fStringToFind, false, false, false); + +}/***StyledEditWindow::FindSelection()***/ + +void StyledEditWindow::Replace(BString findthis, BString replaceWith, bool casesens, bool wrap, bool backsearch){ + + int32 start; + int32 replaceLength; + int32 findLength; + + start= B_ERROR; + + findLength= findthis.Length(); + replaceLength= replaceWith.Length(); + + BString viewText; + viewText.SetTo(fTextView->Text()); + + int32 textStart, textFinish; + fTextView->GetSelection(&textStart, &textFinish); + + if(casesens== true) + start= viewText.FindFirst(findthis, textFinish); + else if(wrap== true) + start= viewText.IFindFirst(findthis); + else if(backsearch== true) + start= viewText.IFindLast(findthis, textStart); + else + start= viewText.IFindFirst(findthis, textFinish); + + if (start!= B_ERROR) { + fTextView->Delete(start, start+ findLength); + fTextView->Insert(start, replaceWith.String(), replaceLength); + fTextView->Select(start, start+ replaceLength); + } + +}/***StyledEditWindow::Replace()***/ + +void StyledEditWindow::ReplaceAll(BString findIt, BString replaceWith, bool caseSens){ + + while(Search(findIt, caseSens, true, false)) + Replace(findIt, replaceWith, caseSens, true, false); + +}/***StyledEditWindow::ReplaceAll()***/ + +void StyledEditWindow::SearchAllWindows(BString find, BString replace, bool casesens){ + + int32 numWindows; + numWindows= be_app->CountWindows(); + + BMessage *message; + message= new BMessage(MSG_REPLACE_ALL); + message->AddString("FindText",find); + message->AddString("ReplaceText",replace); + message->AddBool("casesens", casesens); + + BMessenger *messenger; + + while(numWindows>=0){ + StyledEditWindow *win= dynamic_cast(be_app->WindowAt(numWindows)); + messenger= new BMessenger(win); + messenger->SendMessage(message); + + numWindows--; + } + +}/***StyledEditWindow::SearchAllWindows***/ + + +void StyledEditWindow::SetFontSize(float fontSize){ + + uint32 sameProperties; + BFont font; + + fTextView->GetFontAndColor(&font,&sameProperties); + font.SetSize(fontSize); + fTextView->SetFontAndColor(&font,B_FONT_SIZE); +}/***StyledEditWindow::SetFontSize()***/ + +void StyledEditWindow::SetFontColor(rgb_color *color){ + uint32 sameProperties; + BFont font; + + fTextView-> GetFontAndColor(&font,&sameProperties,NULL,NULL); + fTextView-> SetFontAndColor(&font, B_FONT_ALL,color); + +}/***StyledEditWindow::SetFontColor()***/ + +void StyledEditWindow::SetFontStyle(const char *fontFamily, const char *fontStyle){ + BFont font; + uint32 sameProperties; + + fTextView->GetFontAndColor(&font,&sameProperties); + font.SetFamilyAndStyle(fontFamily,fontStyle); + fTextView->SetFontAndColor(&font); + + BMenuItem *superItem; + superItem= fMenuBar->FindItem(fontFamily); + superItem-> SetMarked(true); + +}/***StyledEditWindow::SetFontStyle()***/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/apps/stylededit/StyledEditWindow.h b/src/apps/stylededit/StyledEditWindow.h new file mode 100644 index 0000000000..7e39012cb8 --- /dev/null +++ b/src/apps/stylededit/StyledEditWindow.h @@ -0,0 +1,100 @@ + +#ifndef STYLED_EDIT_WINDOW_H +#define STYLED_EDIT_WINDOW_H + +#ifndef _FILE_PANEL_H +#include +#endif + +#ifndef _MENUBAR_H +#include +#endif + +#ifndef _MESSAGE_H +#include +#endif + +#ifndef _RECT_H +#include +#endif + +#ifndef _STRING_H +#include +#endif + +#ifndef _TEXTVIEW_H +#include +#endif + +#ifndef _WINDOW_H +#include +#endif + +#ifndef STYLED_EDIT_VIEW_H +#include "StyledEditView.h" +#endif + + +class StyledEditWindow: public BWindow{ + public: + StyledEditWindow(BRect frame); + StyledEditWindow(BRect frame, entry_ref *ref); + ~StyledEditWindow(); + + + virtual bool QuitRequested(); + virtual void MessageReceived(BMessage *message); + + status_t Save(BMessage *message); + void OpenFile(entry_ref *ref); + status_t PageSetup(const char *documentname); + void Print(const char *documentname); + void SearchAllWindows(BString find, BString replace, bool casesens); + + private: + void InitWindow(); + void Register(bool need_id); + void Unregister(void); + bool Search(BString searchfor, bool casesens, bool wrap, bool backsearch); + void FindSelection(); + void Replace(BString findthis, BString replacewith, bool casesens, bool wrap, bool backsearch); + void ReplaceAll(BString find, BString replace, bool casesens); + void SetFontSize(float fontSize); + void SetFontColor(rgb_color *color); + void SetFontStyle(const char *fontFamily, const char *fontStyle); + void RevertToSaved(); + + + BMenuBar *fMenuBar; + BMessage *fPrintSettings; + BMessage *fSaveMessage; + BMenuItem *fSaveItem; + BMenuItem *fUndoItem; + BMenuItem *fCutItem; + BMenuItem *fCopyItem; + BMenuItem *fClearItem; + BMenuItem *fWrapItem; + BString fStringToFind; + BString fReplaceString; + bool fEnableItems; + bool fFirstEdit; + bool fTextSaved; + bool fUnDoneFlag; + bool fCaseSens; + bool fWrapAround; + bool fBackSearch; + StyledEditView *fTextView; + BScrollView *fScrollView; + BFilePanel *fSavePanel; + int32 fWindow_Id; + +}; +#endif + + + + + + + + \ No newline at end of file