diff --git a/src/apps/stylededit/ColorMenuItem.cpp b/src/apps/stylededit/ColorMenuItem.cpp index 1cf1e62472..3dac37dcfe 100644 --- a/src/apps/stylededit/ColorMenuItem.cpp +++ b/src/apps/stylededit/ColorMenuItem.cpp @@ -1,21 +1,30 @@ -#ifndef _MENU_ITEM_H -#include -#endif +/* + * Copyright 2002-2006, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Mattias Sundblad + * Andrew Bachmann + */ + -#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; + +ColorMenuItem::ColorMenuItem(const char *label, rgb_color color, BMessage *message) + : BMenuItem(label, message, 0, 0) +{ + fItemColor = color; } -void ColorMenuItem::DrawContent(){ - - BMenu *menu= Menu(); - rgb_color menuColor = menu->HighColor(); - menu->SetHighColor(fItemColor); - BMenuItem::DrawContent(); - menu->SetHighColor(menuColor); + +void +ColorMenuItem::DrawContent() +{ + BMenu *menu = Menu(); + rgb_color menuColor = menu->HighColor(); + + menu->SetHighColor(fItemColor); + BMenuItem::DrawContent(); + menu->SetHighColor(menuColor); } diff --git a/src/apps/stylededit/ColorMenuItem.h b/src/apps/stylededit/ColorMenuItem.h index f1851d9893..9a2a0cbd29 100644 --- a/src/apps/stylededit/ColorMenuItem.h +++ b/src/apps/stylededit/ColorMenuItem.h @@ -1,14 +1,28 @@ +/* + * Copyright 2002-2006, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Mattias Sundblad + * Andrew Bachmann + */ #ifndef COLOR_MENU_ITEM_H #define COLOR_MENU_ITEM_H + +#include + + class ColorMenuItem: public BMenuItem { public: ColorMenuItem(const char *label, rgb_color color, BMessage *message); - protected: - virtual void DrawContent(); - private: - rgb_color fItemColor; - -}; -#endif + + protected: + virtual void DrawContent(); + + private: + rgb_color fItemColor; +}; + +#endif // COLOR_MENU_ITEM_H diff --git a/src/apps/stylededit/Constants.h b/src/apps/stylededit/Constants.h index df67c5e950..d4c6a32373 100644 --- a/src/apps/stylededit/Constants.h +++ b/src/apps/stylededit/Constants.h @@ -1,44 +1,55 @@ -/*StyledEdit: constants*/ +/* + * Copyright 2002-2006, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Mattias Sundblad + * Andrew Bachmann + */ #ifndef CONSTANTS_H #define CONSTANTS_H + #include #include + #define APP_SIGNATURE "application/x-vnd.obos.styled-edit" const float TEXT_INSET = 3.0; -/*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'; +// Messages for menu commands -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_FAMILY ='FFch'; -const uint32 FONT_STYLE ='FSch'; -const uint32 FONT_COLOR ='Fcol'; +// 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'; -//fontcolors -//red, green, blue, alphachannel +// 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_FAMILY = 'FFch'; +const uint32 FONT_STYLE = 'FSch'; +const uint32 FONT_COLOR = 'Fcol'; + +// fontcolors const rgb_color BLACK = {0, 0, 0, 255}; const rgb_color RED = {255, 0, 0, 255}; const rgb_color GREEN = {0, 255, 0, 255}; @@ -47,21 +58,21 @@ 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'; +// "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'; +// enables "edit" menuitems +const uint32 ENABLE_ITEMS = 'ENit'; +const uint32 DISABLE_ITEMS = 'DIit'; +const uint32 CHANGE_WINDOW = 'CHwi'; +const uint32 TEXT_CHANGED = 'TEch'; // file panel constants -const uint32 OPEN_AS_ENCODING ='FPoe'; -const uint32 SAVE_AS_ENCODING ='FPse'; -const uint32 SAVE_THEN_QUIT ='FPsq'; +const uint32 OPEN_AS_ENCODING = 'FPoe'; +const uint32 SAVE_AS_ENCODING = 'FPse'; +const uint32 SAVE_THEN_QUIT = 'FPsq'; -#endif // CONSTANTS_H +#endif // CONSTANTS_H diff --git a/src/apps/stylededit/FindWindow.cpp b/src/apps/stylededit/FindWindow.cpp index 0c9e7790fd..56b7c21c8f 100644 --- a/src/apps/stylededit/FindWindow.cpp +++ b/src/apps/stylededit/FindWindow.cpp @@ -1,147 +1,127 @@ +/* + * Copyright 2002-2006, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Mattias Sundblad + * Andrew Bachmann + */ + + +#include "Constants.h" +#include "FindWindow.h" + #include #include #include #include -#include -#include -#include "Constants.h" -#include "FindWindow.h" -// FindWindow::FindWindow() FindWindow::FindWindow(BRect frame, BHandler *_handler, BString *searchString, bool *caseState, bool *wrapState, bool *backState) : BWindow(frame, "FindWindow", B_MODAL_WINDOW, B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS, B_CURRENT_WORKSPACE) { - fFindView = new BBox(Bounds(), "FindView", B_FOLLOW_ALL, B_WILL_DRAW, B_PLAIN_BORDER); + fFindView = new BView(Bounds(), "FindView", B_FOLLOW_ALL, B_WILL_DRAW); fFindView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); AddChild(fFindView); font_height height; fFindView->GetFontHeight(&height); - float lineHeight = height.ascent+height.descent+height.leading; - - float findWidth = fFindView->StringWidth("Find:")+6; - - float searchBottom = 12 + 2 + lineHeight + 2 + 1; - float buttonTop = frame.Height()-19-lineHeight; - float wrapBoxTop = (buttonTop+searchBottom-lineHeight)/2; - float wrapBoxBottom = (buttonTop+searchBottom+lineHeight)/2; - float caseBoxTop = (searchBottom+wrapBoxTop-lineHeight)/2; - float caseBoxBottom = (searchBottom+wrapBoxTop+lineHeight)/2; - float backBoxTop = (buttonTop+wrapBoxBottom-lineHeight)/2; - float backBoxBottom = (buttonTop+wrapBoxBottom+lineHeight)/2; - - fFindView->AddChild(fSearchString= new BTextControl(BRect(14,12,frame.Width()-10,searchBottom), "", "Find:", NULL, NULL)); - fSearchString->SetDivider(findWidth); + float lineHeight = height.ascent+height.descent + height.leading; - fFindView->AddChild(fCaseSensBox= new BCheckBox(BRect(16+findWidth,caseBoxTop,frame.Width()-12,caseBoxBottom),"","Case-sensitive", NULL)); - fFindView->AddChild(fWrapBox= new BCheckBox(BRect(16+findWidth,wrapBoxTop,frame.Width()-12,wrapBoxBottom),"","Wrap-around search", NULL)); - fFindView->AddChild(fBackSearchBox= new BCheckBox(BRect(16+findWidth,backBoxTop,frame.Width()-12,backBoxBottom),"","Search backwards", NULL)); - - fFindView->AddChild(fCancelButton= new BButton(BRect(142,buttonTop,212,frame.Height()-7),"","Cancel",new BMessage(B_QUIT_REQUESTED))); - fFindView->AddChild(fSearchButton= new BButton(BRect(221,buttonTop,291,frame.Height()-7),"","Find",new BMessage(MSG_SEARCH))); + float findWidth = fFindView->StringWidth("Find:") + 6; + + float searchBottom = 12 + 2 + lineHeight + 2 + 1; + float buttonTop = frame.Height() - 19 - lineHeight; + float wrapBoxTop = (buttonTop + searchBottom - lineHeight) / 2; + float wrapBoxBottom = (buttonTop + searchBottom + lineHeight) / 2; + float caseBoxTop = (searchBottom + wrapBoxTop - lineHeight) / 2; + float caseBoxBottom = (searchBottom + wrapBoxTop + lineHeight) / 2; + float backBoxTop = (buttonTop + wrapBoxBottom - lineHeight) / 2; + float backBoxBottom = (buttonTop + wrapBoxBottom + lineHeight) / 2; + + fFindView->AddChild(fSearchString = new BTextControl(BRect(14, 12, + frame.Width() - 10, searchBottom), "", "Find:", NULL, NULL)); + fSearchString->SetDivider(findWidth); + + fFindView->AddChild(fCaseSensBox = new BCheckBox(BRect(16 + findWidth, caseBoxTop, + frame.Width() - 12, caseBoxBottom), "", "Case-sensitive", NULL)); + fFindView->AddChild(fWrapBox = new BCheckBox(BRect(16 + findWidth, wrapBoxTop, + frame.Width() - 12, wrapBoxBottom), "", "Wrap-around search", NULL)); + fFindView->AddChild(fBackSearchBox = new BCheckBox(BRect(16 + findWidth, + backBoxTop, frame.Width() - 12, backBoxBottom), "", "Search backwards", NULL)); + fFindView->AddChild(fCancelButton = new BButton(BRect(142, buttonTop, 212, + frame.Height() - 7), "", "Cancel", new BMessage(B_QUIT_REQUESTED))); + fFindView->AddChild(fSearchButton = new BButton(BRect(221, buttonTop, 291, + frame.Height() - 7), "", "Find", new BMessage(MSG_SEARCH))); + fSearchButton->MakeDefault(true); - fHandler=_handler; - - const char *text= searchString->String(); - + fHandler = _handler; + + const char *text = searchString->String(); + fSearchString->SetText(text); - fSearchString-> MakeFocus(true); //021021 - - 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(); + fSearchString->MakeFocus(true); + + fCaseSensBox->SetValue(*caseState ? B_CONTROL_ON : B_CONTROL_OFF); + fWrapBox->SetValue(*wrapState ? B_CONTROL_ON : B_CONTROL_OFF); + fBackSearchBox->SetValue(*backState ? B_CONTROL_ON : B_CONTROL_OFF); } -void FindWindow::MessageReceived(BMessage *msg){ - switch(msg->what){ + +void +FindWindow::MessageReceived(BMessage *msg) +{ + switch (msg->what) { case B_QUIT_REQUESTED: Quit(); - break; + break; case MSG_SEARCH: - ExtractToMsg(new BMessage(MSG_SEARCH)); - break; - default: - BWindow::MessageReceived(msg); - break; - } -} - -void FindWindow::DispatchMessage(BMessage *message, BHandler *handler) + _SendMessage(); + 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; + if (message->what == B_KEY_DOWN) { + int8 key; + if (message->FindInt8("byte", 0, &key) == B_OK) { + if (key == B_ESCAPE) { + message->MakeEmpty(); + message->what = B_QUIT_REQUESTED; } } } - BWindow::DispatchMessage(message,handler); + + 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); +void +FindWindow::_SendMessage() +{ + BMessage message(MSG_SEARCH); + + // Add the string + message.AddString("findtext", fSearchString->Text()); + + // Add searchparameters from checkboxes + message.AddBool("casesens", fCaseSensBox->Value() == B_CONTROL_ON); + message.AddBool("wrap", fWrapBox->Value() == B_CONTROL_ON); + message.AddBool("backsearch", fBackSearchBox->Value() == B_CONTROL_ON); + + fHandler->Looper()->PostMessage(&message, fHandler); + PostMessage(B_QUIT_REQUESTED); } diff --git a/src/apps/stylededit/FindWindow.h b/src/apps/stylededit/FindWindow.h index c592ace371..e8cb570b1c 100644 --- a/src/apps/stylededit/FindWindow.h +++ b/src/apps/stylededit/FindWindow.h @@ -1,28 +1,46 @@ +/* + * Copyright 2002-2006, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Mattias Sundblad + * Andrew Bachmann + */ #ifndef FIND_WINDOW_H #define FIND_WINDOW_H + +#include + +class BButton; +class BCheckBox; +class BTextControl; +class BView; + + 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); - + 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; - + void _SendMessage(); + + BView *fFindView; + BTextControl *fSearchString; + BCheckBox *fCaseSensBox; + BCheckBox *fWrapBox; + BCheckBox *fBackSearchBox; + BButton *fCancelButton; + BButton *fSearchButton; + + BHandler *fHandler; }; -#endif + +#endif // FIND_WINDOW_H diff --git a/src/apps/stylededit/ReplaceWindow.cpp b/src/apps/stylededit/ReplaceWindow.cpp index 434fce74f0..e65dea8937 100644 --- a/src/apps/stylededit/ReplaceWindow.cpp +++ b/src/apps/stylededit/ReplaceWindow.cpp @@ -1,13 +1,22 @@ -#include +/* + * Copyright 2002-2006, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Mattias Sundblad + * Andrew Bachmann + */ + + +#include "Constants.h" +#include "ReplaceWindow.h" + #include #include #include #include #include -#include "Constants.h" -#include "ReplaceWindow.h" - ReplaceWindow::ReplaceWindow(BRect frame, BHandler *_handler, BString *searchString, BString *replaceString, bool *caseState, bool *wrapState, bool *backState) @@ -15,177 +24,140 @@ ReplaceWindow::ReplaceWindow(BRect frame, BHandler *_handler, BString *searchStr B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS, B_CURRENT_WORKSPACE) { - fReplaceView = new BBox(Bounds(), "ReplaceView", B_FOLLOW_ALL, B_WILL_DRAW, B_PLAIN_BORDER); + fReplaceView = new BView(Bounds(), "ReplaceView", B_FOLLOW_ALL, B_WILL_DRAW); fReplaceView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); AddChild(fReplaceView); - char *findLabel = "Find:"; + char* findLabel = "Find:"; float findWidth = fReplaceView->StringWidth(findLabel); - fReplaceView->AddChild(fSearchString= new BTextControl(BRect(5,10,290,50), "", findLabel,NULL, NULL, - B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); + fReplaceView->AddChild(fSearchString = new BTextControl(BRect(5, 10, 290, 50), "", + findLabel, NULL, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE)); - char * replaceWithLabel = "Replace with:"; + char* replaceWithLabel = "Replace with:"; float replaceWithWidth = fReplaceView->StringWidth(replaceWithLabel); - fReplaceView->AddChild(fReplaceString=new BTextControl(BRect(5,35,290,50), "", replaceWithLabel,NULL, - NULL,B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); + fReplaceView->AddChild(fReplaceString = new BTextControl(BRect(5, 35, 290, 50), "", + replaceWithLabel, NULL, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, + B_WILL_DRAW | B_NAVIGABLE)); float maxWidth = (replaceWithWidth > findWidth ? replaceWithWidth : findWidth) + 1; fSearchString->SetDivider(maxWidth); fReplaceString->SetDivider(maxWidth); - - fReplaceView->AddChild(fCaseSensBox=new BCheckBox(BRect(maxWidth+8,60,290,52),"","Case-sensitive", NULL, - B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); - fReplaceView->AddChild(fWrapBox=new BCheckBox(BRect(maxWidth+8,80,290,70),"","Wrap-around search", NULL, - B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); - fReplaceView->AddChild(fBackSearchBox=new BCheckBox(BRect(maxWidth+8,100,290,95),"","Search backwards", NULL, - B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); - fReplaceView->AddChild(fAllWindowsBox=new BCheckBox(BRect(maxWidth+8,120,290,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)); + + fReplaceView->AddChild(fCaseSensBox = new BCheckBox(BRect(maxWidth + 8, 60, 290, 52), + "", "Case-sensitive", NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE)); + fReplaceView->AddChild(fWrapBox = new BCheckBox(BRect(maxWidth + 8, 80, 290, 70), + "", "Wrap-around search", NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, + B_WILL_DRAW | B_NAVIGABLE)); + fReplaceView->AddChild(fBackSearchBox = new BCheckBox(BRect(maxWidth + 8, 100, 290, 95), + "", "Search backwards", NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, + B_WILL_DRAW | B_NAVIGABLE)); + fReplaceView->AddChild(fAllWindowsBox = new BCheckBox(BRect(maxWidth + 8, 120, 290, 95), + "", "Replace in all windows", new BMessage(CHANGE_WINDOW), + B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE)); + fUIchange = false; + + 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); - - fHandler= _handler; - - const char *searchtext= searchString->String(); - const char *replacetext= replaceString->String(); - + + fHandler = _handler; + + const char *searchtext = searchString->String(); + const char *replacetext = replaceString->String(); + fSearchString->SetText(searchtext); fReplaceString->SetText(replacetext); - fSearchString-> MakeFocus(true); //021021 - - 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(); + fSearchString->MakeFocus(true); + + fCaseSensBox->SetValue(*caseState ? B_CONTROL_ON : B_CONTROL_OFF); + fWrapBox->SetValue(*wrapState ? B_CONTROL_ON : B_CONTROL_OFF); + fBackSearchBox->SetValue(*backState ? B_CONTROL_ON : B_CONTROL_OFF); } -void ReplaceWindow::MessageReceived(BMessage *msg){ - switch(msg->what){ - case B_QUIT_REQUESTED: - Quit(); - break; + +void +ReplaceWindow::MessageReceived(BMessage *msg) +{ + switch (msg->what){ case MSG_REPLACE: - ExtractToMsg(new BMessage(MSG_REPLACE)); - break; + _SendMessage(MSG_REPLACE); + break; case CHANGE_WINDOW: - ChangeUi(); - break; + _ChangeUI(); + break; case MSG_REPLACE_ALL: - ExtractToMsg(new BMessage(MSG_REPLACE_ALL)); - break; - default: - BWindow::MessageReceived(msg); - break; + _SendMessage(MSG_REPLACE_ALL); + break; + + default: + BWindow::MessageReceived(msg); + break; } } -void ReplaceWindow::ChangeUi(){ - - if(!fUichange){ + +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{ + 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; + fUIchange = false; + } +} + + +void +ReplaceWindow::DispatchMessage(BMessage *message, BHandler *handler) +{ + if (message->what == B_KEY_DOWN) { + int8 key; + if (message->FindInt8("byte", 0, &key) == B_OK) { + if (key == B_ESCAPE) { + message->MakeEmpty(); + message->what = B_QUIT_REQUESTED; } } } - BWindow::DispatchMessage(message,fHandler); + + BWindow::DispatchMessage(message, handler); } -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); + +void +ReplaceWindow::_SendMessage(uint32 what) +{ + BMessage message(what); + + // Add the strings + message.AddString("FindText", fSearchString->Text()); + message.AddString("ReplaceText", fReplaceString->Text()); + + // Add searchparameters from checkboxes + message.AddBool("casesens", fCaseSensBox->Value() == B_CONTROL_ON); + message.AddBool("wrap", fWrapBox->Value() == B_CONTROL_ON); + message.AddBool("backsearch", fBackSearchBox->Value() == B_CONTROL_ON); + message.AddBool("allwindows", fAllWindowsBox->Value() == B_CONTROL_ON); + + fHandler->Looper()->PostMessage(&message, fHandler); + PostMessage(B_QUIT_REQUESTED); } - - - - diff --git a/src/apps/stylededit/ReplaceWindow.h b/src/apps/stylededit/ReplaceWindow.h index e4e7933023..81ca132b88 100644 --- a/src/apps/stylededit/ReplaceWindow.h +++ b/src/apps/stylededit/ReplaceWindow.h @@ -1,6 +1,15 @@ +/* + * Copyright 2002-2006, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Mattias Sundblad + * Andrew Bachmann + */ #ifndef REPLACE_WINDOW_H #define REPLACE_WINDOW_H + #include #include #include @@ -11,31 +20,31 @@ #include #include + 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); - - + 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; + void _SendMessage(uint32 what); + 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 - +#endif // REPLACE_WINDOW_H diff --git a/src/apps/stylededit/StyledEditApp.cpp b/src/apps/stylededit/StyledEditApp.cpp index a3d86d14e8..f2c730008c 100644 --- a/src/apps/stylededit/StyledEditApp.cpp +++ b/src/apps/stylededit/StyledEditApp.cpp @@ -1,3 +1,12 @@ +/* + * Copyright 2002-2006, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Mattias Sundblad + * Andrew Bachmann + */ + #include #include @@ -14,47 +23,56 @@ using namespace BPrivate; -BRect windowRect(7-15,26-15,507,426); +StyledEditApp * styled_edit_app; +BRect gWindowRect(7-15, 26-15, 507, 426); -void cascade() { + +void +cascade() +{ BScreen screen(NULL); BRect screenBorder = screen.Frame(); - float left = windowRect.left + 15; - if (left + windowRect.Width() > screenBorder.right) { + float left = gWindowRect.left + 15; + if (left + gWindowRect.Width() > screenBorder.right) left = 7; - } - float top = windowRect.top + 15; - if (top + windowRect.Height() > screenBorder.bottom) { + + float top = gWindowRect.top + 15; + if (top + gWindowRect.Height() > screenBorder.bottom) top = 26; - } - windowRect.OffsetTo(BPoint(left,top)); + + gWindowRect.OffsetTo(BPoint(left,top)); } -void uncascade() { + +void +uncascade() +{ BScreen screen(NULL); BRect screenBorder = screen.Frame(); - float left = windowRect.left - 15; + + float left = gWindowRect.left - 15; if (left < 7) { - left = screenBorder.right - windowRect.Width() - 7; + left = screenBorder.right - gWindowRect.Width() - 7; left = left - ((int)left % 15) + 7; } - float top = windowRect.top - 15; + + float top = gWindowRect.top - 15; if (top < 26) { - top = screenBorder.bottom - windowRect.Height() - 26; + top = screenBorder.bottom - gWindowRect.Height() - 26; top = top - ((int)left % 15) + 26; } - windowRect.OffsetTo(BPoint(left,top)); + + gWindowRect.OffsetTo(BPoint(left,top)); } -StyledEditApp * styled_edit_app; StyledEditApp::StyledEditApp() : BApplication(APP_SIGNATURE) { fOpenPanel= new BFilePanel(); BMenuBar * menuBar = - dynamic_cast(fOpenPanel->Window()->FindView("MenuBar")); - + dynamic_cast(fOpenPanel->Window()->FindView("MenuBar")); + fOpenAsEncoding = 0; fOpenPanelEncodingMenu= new BMenu("Encoding"); menuBar->AddItem(fOpenPanelEncodingMenu); @@ -64,92 +82,96 @@ StyledEditApp::StyledEditApp() BCharacterSet charset; while (roster.GetNextCharacterSet(&charset) == B_NO_ERROR) { BString name(charset.GetPrintName()); - const char * mime = charset.GetMIMEName(); + 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)); + BMenuItem* item = new BMenuItem(name.String(), new BMessage(OPEN_AS_ENCODING)); item->SetTarget(this); fOpenPanelEncodingMenu->AddItem(item); - if (charset.GetFontID() == fOpenAsEncoding) { + if (charset.GetFontID() == fOpenAsEncoding) item->SetMarked(true); - } } - - fWindowCount= 0; - fNext_Untitled_Window= 1; - styled_edit_app = this; -} /***StyledEditApp::StyledEditApp()***/ -void StyledEditApp::DispatchMessage(BMessage *msg, BHandler *handler) + fWindowCount = 0; + fNextUntitledWindow = 1; + + styled_edit_app = this; +} + + +void +StyledEditApp::DispatchMessage(BMessage *msg, BHandler *handler) { - if ( msg->what == B_ARGV_RECEIVED ) { + if (msg->what == B_ARGV_RECEIVED) { int32 argc; - if (msg->FindInt32("argc",&argc) != B_OK) { - argc=0; - } - const char ** argv = new const char*[argc]; - for (int arg = 0; (arg < argc) ; arg++) { - if (msg->FindString("argv",arg,&argv[arg]) != B_OK) { + if (msg->FindInt32("argc", &argc) != B_OK) + argc = 0; + + const char** argv = new const char*[argc]; + for (int arg = 0; arg < argc; arg++) { + if (msg->FindString("argv", arg, &argv[arg]) != B_OK) { argv[arg] = ""; } } - const char * cwd; - if (msg->FindString("cwd",&cwd) != B_OK) { + const char* cwd; + if (msg->FindString("cwd", &cwd) != B_OK) cwd = ""; - } + ArgvReceived(argc, argv, cwd); - } else { - BApplication::DispatchMessage(msg,handler); - } + } else + BApplication::DispatchMessage(msg, handler); } void StyledEditApp::MessageReceived(BMessage *message) { - switch(message->what) { + switch (message->what) { case MENU_NEW: OpenDocument(); - break; + break; case MENU_OPEN: - fOpenPanel->Show(); // - break; + fOpenPanel->Show(); + break; case B_SILENT_RELAUNCH: OpenDocument(); - break; + break; case OPEN_AS_ENCODING: - void * ptr; - if (message->FindPointer("source",&ptr) == B_OK) { - if (fOpenPanelEncodingMenu != 0) { - fOpenAsEncoding = (uint32)fOpenPanelEncodingMenu->IndexOf((BMenuItem*)ptr); - } + void* ptr; + if (message->FindPointer("source", &ptr) == B_OK + && fOpenPanelEncodingMenu != 0) { + fOpenAsEncoding = (uint32)fOpenPanelEncodingMenu->IndexOf((BMenuItem*)ptr); } - break; + break; + default: BApplication::MessageReceived(message); - break; + break; } } + void StyledEditApp::OpenDocument() { cascade(); - new StyledEditWindow(windowRect,fNext_Untitled_Window++,fOpenAsEncoding); + new StyledEditWindow(gWindowRect, fNextUntitledWindow++, fOpenAsEncoding); fWindowCount++; } + void -StyledEditApp::OpenDocument(entry_ref * ref) +StyledEditApp::OpenDocument(entry_ref* ref) { cascade(); - new StyledEditWindow(windowRect,ref,fOpenAsEncoding); + new StyledEditWindow(gWindowRect, ref, fOpenAsEncoding); fWindowCount++; } + void StyledEditApp::CloseDocument() { @@ -161,75 +183,71 @@ StyledEditApp::CloseDocument() } } + void StyledEditApp::RefsReceived(BMessage *message) { - int32 refNum; - entry_ref ref; - status_t err; - - refNum = 0; - do { - err = message->FindRef("refs", refNum, &ref); - if (err != B_OK) - return; + int32 index = 0; + entry_ref ref; + + while (message->FindRef("refs", index++, &ref) == B_OK) { OpenDocument(&ref); - refNum++; - } while (true); -} /***StyledEditApp::RefsReceived();***/ + } +} + void -StyledEditApp::ArgvReceived(int32 argc, const char *argv[], const char * cwd) +StyledEditApp::ArgvReceived(int32 argc, const char* argv[], const char* cwd) { for (int i = 1 ; (i < argc) ; i++) { BPath path; - if (argv[i][0] == '/') { + if (argv[i][0] == '/') path.SetTo(argv[i]); - } else { - path.SetTo(cwd,argv[i]); - } + else + path.SetTo(cwd, argv[i]); + if (path.InitCheck() != B_OK) { - printf("path.InitCheck failed: \""); - if (argv[i][0] == '/') { - printf("%s",argv[i]); - } else { - printf("%s/%s",cwd,argv[i]); - } - printf("\".\n"); + fprintf(stderr, "Setting path failed: \""); + if (argv[i][0] == '/') + fprintf(stderr, "%s\".\n", argv[i]); + else + fprintf(stderr, "%s/%s\".\n", cwd, argv[i]); continue; } - + entry_ref ref; if (get_ref_for_path(path.Path(), &ref) != B_OK) { - printf("get_ref_for_path failed: \""); - printf("%s",path.Path()); - printf("\".\n"); + fprintf(stderr, "Entry not found: \"%s\".\n", path.Path()); continue; } OpenDocument(&ref); } } + void StyledEditApp::ReadyToRun() { - if (fWindowCount == 0) { + if (fWindowCount == 0) OpenDocument(); - } } + int32 StyledEditApp::NumberOfWindows() { - return fWindowCount; -}/***StyledEditApp::NumberOfWindows()***/ +} + + +// #pragma mark - + int -main() +main(int argc, char** argv) { - StyledEditApp styledEdit; + StyledEditApp styledEdit; styledEdit.Run(); return 0; } diff --git a/src/apps/stylededit/StyledEditApp.h b/src/apps/stylededit/StyledEditApp.h index ccff525d59..27c27449af 100644 --- a/src/apps/stylededit/StyledEditApp.h +++ b/src/apps/stylededit/StyledEditApp.h @@ -1,39 +1,46 @@ -/**StyledEdit: Application class*/ +/* + * Copyright 2002-2006, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Mattias Sundblad + * Andrew Bachmann + */ #ifndef STYLED_EDIT_APP #define STYLED_EDIT_APP + #include #include #include + class StyledEditWindow; -class StyledEditApp - : public BApplication -{ -public: - StyledEditApp(); - virtual void MessageReceived(BMessage *message); - void ArgvReceived(int32 argc, const char *argv[], const char * cwd); - virtual void RefsReceived(BMessage *message); - virtual void ReadyToRun(); +class StyledEditApp : public BApplication { + public: + StyledEditApp(); + virtual void MessageReceived(BMessage *message); + void ArgvReceived(int32 argc, const char *argv[], const char * cwd); + virtual void RefsReceived(BMessage *message); + virtual void ReadyToRun(); - virtual void DispatchMessage(BMessage *an_event, BHandler *handler); + virtual void DispatchMessage(BMessage *an_event, BHandler *handler); - int32 NumberOfWindows(); - void OpenDocument(); - void OpenDocument(entry_ref * ref); - void CloseDocument(); - -private: - BFilePanel *fOpenPanel; - BMenu *fOpenPanelEncodingMenu; - uint32 fOpenAsEncoding; - int32 fWindowCount; - int32 fNext_Untitled_Window; + int32 NumberOfWindows(); + void OpenDocument(); + void OpenDocument(entry_ref * ref); + void CloseDocument(); + + private: + BFilePanel* fOpenPanel; + BMenu* fOpenPanelEncodingMenu; + uint32 fOpenAsEncoding; + int32 fWindowCount; + int32 fNextUntitledWindow; }; -extern StyledEditApp * styled_edit_app; +extern StyledEditApp* styled_edit_app; -#endif // STYLED_EDIT_APP +#endif // STYLED_EDIT_APP diff --git a/src/apps/stylededit/StyledEditView.cpp b/src/apps/stylededit/StyledEditView.cpp index 02fa5434aa..6a4b45cdaa 100644 --- a/src/apps/stylededit/StyledEditView.cpp +++ b/src/apps/stylededit/StyledEditView.cpp @@ -1,3 +1,16 @@ +/* + * Copyright 2002-2006, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Mattias Sundblad + * Andrew Bachmann + */ + + +#include "Constants.h" +#include "StyledEditView.h" + #include #include #include @@ -10,38 +23,39 @@ #include #include -#include "StyledEditView.h" -#include "Constants.h" - using namespace BPrivate; + StyledEditView::StyledEditView(BRect viewFrame, BRect textBounds, BHandler *handler) : BTextView(viewFrame, "textview", textBounds, - B_FOLLOW_ALL, B_FRAME_EVENTS|B_WILL_DRAW) + B_FOLLOW_ALL, B_FRAME_EVENTS|B_WILL_DRAW) { - fHandler= handler; - fMessenger= new BMessenger(handler); + fHandler = handler; + fMessenger = new BMessenger(handler); fSuppressChanges = false; fEncoding = 0; } + StyledEditView::~StyledEditView() { delete fMessenger; } - + + 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); + textRect.InsetBy(TEXT_INSET, TEXT_INSET); SetTextRect(textRect); } + /* // I tried to do some sort of intelligent resize thing but it just doesn't work // so we revert to the R5 stylededit yucky practice of setting the text rect to // some crazy large number when word wrap is turned off :-( @@ -60,126 +74,129 @@ StyledEditView::FrameResized(float width, float height) */ } + status_t -StyledEditView::GetStyledText(BPositionIO * stream) +StyledEditView::GetStyledText(BPositionIO* stream) { - status_t result = B_OK; - fSuppressChanges = true; - result = BTranslationUtils::GetStyledText(stream, this, NULL); + status_t result = BTranslationUtils::GetStyledText(stream, this, NULL); fSuppressChanges = false; - if (result != B_OK) { - return result; - } - BNode * node = dynamic_cast(stream); - if (node != 0) { + if (result != B_OK) + return result; + + BNode* node = dynamic_cast(stream); + if (node != NULL) { ssize_t bytesRead; // decode encoding int32 encoding; - bytesRead = node->ReadAttr("be:encoding",0,0,&encoding,sizeof(encoding)); - if (bytesRead > 0) { + bytesRead = node->ReadAttr("be:encoding", 0, 0, &encoding, sizeof(encoding)); + if (bytesRead == (ssize_t)sizeof(encoding)) { if (encoding == 65535) { fEncoding = 0; } else { - const BCharacterSet * cs = BCharacterSetRoster::GetCharacterSetByConversionID(encoding); - if (cs != 0) { - fEncoding = cs->GetFontID(); - } + const BCharacterSet* characterSet + = BCharacterSetRoster::GetCharacterSetByConversionID(encoding); + if (characterSet != 0) + fEncoding = characterSet->GetFontID(); } } - + // restore alignment alignment align; - bytesRead = node->ReadAttr("alignment",0,0,&align,sizeof(align)); - if (bytesRead > 0) { + bytesRead = node->ReadAttr("alignment", 0, 0, &align, sizeof(align)); + if (bytesRead == (ssize_t)sizeof(align)) SetAlignment(align); - } + // restore wrapping bool wrap; - bytesRead = node->ReadAttr("wrap",0,0,&wrap,sizeof(wrap)); - if (bytesRead > 0) { + bytesRead = node->ReadAttr("wrap", 0, 0, &wrap, sizeof(wrap)); + if (bytesRead == (ssize_t)sizeof(wrap)) { SetWordWrap(wrap); if (wrap == false) { BRect textRect; textRect = Bounds(); textRect.OffsetTo(B_ORIGIN); - textRect.InsetBy(TEXT_INSET,TEXT_INSET); + textRect.InsetBy(TEXT_INSET, TEXT_INSET); // the width comes from stylededit R5. TODO: find a better way - textRect.SetRightBottom(BPoint(1500.0,textRect.RightBottom().y)); + textRect.SetRightBottom(BPoint(1500.0, textRect.RightBottom().y)); SetTextRect(textRect); } } } + if (fEncoding != 0) { - int32 length = stream->Seek(0,SEEK_END); + int32 length = stream->Seek(0, SEEK_END); // Here we save the run_array before it gets overwritten... - text_run_array * run_array = RunArray(0,length); + text_run_array* runArray = RunArray(0, length); uint32 id = BCharacterSetRoster::GetCharacterSetByFontID(fEncoding)->GetConversionID(); + fSuppressChanges = true; SetText(""); fSuppressChanges = false; + char inBuffer[32768]; off_t location = 0; int32 textOffset = 0; int32 state = 0; int32 bytesRead; - while ((bytesRead = stream->ReadAt(location,inBuffer,32768)) > 0) { - char * inPtr = inBuffer; + while ((bytesRead = stream->ReadAt(location, inBuffer, sizeof(inBuffer))) > 0) { + char* inPtr = inBuffer; char textBuffer[32768]; - int32 textLength = 32768; + int32 textLength = sizeof(textBuffer); int32 bytes = bytesRead; - while ((textLength > 0) && (bytes > 0)) { - result = convert_to_utf8(id,inPtr,&bytes,textBuffer,&textLength,&state); - if (result != B_OK) { + while (textLength > 0 && bytes > 0) { + result = convert_to_utf8(id, inPtr, &bytes, textBuffer, &textLength, &state); + if (result != B_OK) return result; - } + fSuppressChanges = true; - InsertText(textBuffer,textLength,textOffset); + InsertText(textBuffer, textLength, textOffset); fSuppressChanges = false; textOffset += textLength; inPtr += bytes; location += bytes; bytesRead -= bytes; bytes = bytesRead; - if (textLength > 0) { - textLength = 32768; - } + if (textLength > 0) + textLength = sizeof(textBuffer); } } // ... and here we restore it - SetRunArray(0,length,run_array); - free(run_array); + SetRunArray(0, length, runArray); + free(runArray); } + return result; } + status_t -StyledEditView::WriteStyledEditFile(BFile * file) +StyledEditView::WriteStyledEditFile(BFile* file) { status_t result = B_OK; ssize_t bytes = 0; - result = BTranslationUtils::WriteStyledEditFile(this,file); - if (result != B_OK) { + result = BTranslationUtils::WriteStyledEditFile(this, file); + if (result != B_OK) return result; - } + if (fEncoding == 0) { int32 encoding = 65535; - bytes = file->WriteAttr("be:encoding",B_INT32_TYPE,0,&encoding,sizeof(encoding)); + bytes = file->WriteAttr("be:encoding", B_INT32_TYPE, 0, &encoding, sizeof(encoding)); if (bytes < 0) return bytes; } else { result = file->SetSize(0); - if (result != B_OK) { + if (result != B_OK) return result; - } + bytes = file->Seek(0, SEEK_SET); - if (bytes != 0) { + if (bytes != 0) return bytes; - } - const BCharacterSet * cs = BCharacterSetRoster::GetCharacterSetByFontID(fEncoding); + + const BCharacterSet* cs = BCharacterSetRoster::GetCharacterSetByFontID(fEncoding); if (cs != 0) { uint32 id = cs->GetConversionID(); const char * outText = Text(); @@ -199,23 +216,26 @@ StyledEditView::WriteStyledEditFile(BFile * file) sourceLength -= length; outText += length; } - bytes = file->WriteAttr("be:encoding",B_INT32_TYPE,0,&id,sizeof(id)); + bytes = file->WriteAttr("be:encoding", B_INT32_TYPE, 0, &id, sizeof(id)); if (bytes < 0) return bytes; } - } + } alignment align = Alignment(); - bytes = file->WriteAttr("alignment",B_INT32_TYPE,0,&align,sizeof(align)); + bytes = file->WriteAttr("alignment", B_INT32_TYPE, 0, &align, sizeof(align)); if (bytes < 0) return bytes; + bool wrap = DoesWordWrap(); - bytes = file->WriteAttr("wrap",B_BOOL_TYPE,0,&wrap,sizeof(wrap)); + bytes = file->WriteAttr("wrap", B_BOOL_TYPE, 0, &wrap, sizeof(wrap)); if (bytes < 0) return bytes; + return result; } + void StyledEditView::Reset() { @@ -224,47 +244,48 @@ StyledEditView::Reset() fSuppressChanges = false; } + void StyledEditView::Select(int32 start, int32 finish) { - if(start==finish) - fChangeMessage= new BMessage(DISABLE_ITEMS); - else - fChangeMessage= new BMessage(ENABLE_ITEMS); - + fChangeMessage = new BMessage(start == finish ? DISABLE_ITEMS : ENABLE_ITEMS); fMessenger->SendMessage(fChangeMessage); - + BTextView::Select(start, finish); } + void StyledEditView::SetEncoding(uint32 encoding) { fEncoding = encoding; } + uint32 StyledEditView::GetEncoding() const { return fEncoding; } + void -StyledEditView::InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs) +StyledEditView::InsertText(const char *text, int32 length, int32 offset, + const text_run_array *runs) { if (!fSuppressChanges) - fMessenger-> SendMessage(new BMessage(TEXT_CHANGED)); - - BTextView::InsertText(text, length, offset, runs); - -}/****StyledEditView::InsertText()***/ + fMessenger->SendMessage(new BMessage(TEXT_CHANGED)); + + BTextView::InsertText(text, length, offset, runs); +} + void StyledEditView::DeleteText(int32 start, int32 finish) { if (!fSuppressChanges) fMessenger-> SendMessage(new BMessage(TEXT_CHANGED)); - - BTextView::DeleteText(start, finish); -}/***StyledEditView::DeleteText***/ + BTextView::DeleteText(start, finish); +} + diff --git a/src/apps/stylededit/StyledEditView.h b/src/apps/stylededit/StyledEditView.h index a3985b5b3d..0a2fac9646 100644 --- a/src/apps/stylededit/StyledEditView.h +++ b/src/apps/stylededit/StyledEditView.h @@ -1,34 +1,45 @@ +/* + * Copyright 2002-2006, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Mattias Sundblad + * Andrew Bachmann + */ #ifndef STYLED_EDIT_VIEW_H #define STYLED_EDIT_VIEW_H + #include #include #include -class StyledEditView : public BTextView { -public: - StyledEditView(BRect viewframe, BRect textframe, BHandler *handler); - virtual ~StyledEditView(); - virtual void Select(int32 start, int32 finish); - virtual void FrameResized(float width, float height); +class StyledEditView : public BTextView { + public: + StyledEditView(BRect viewframe, BRect textframe, BHandler *handler); + virtual ~StyledEditView(); + + virtual void Select(int32 start, int32 finish); + virtual void FrameResized(float width, float height); - virtual void Reset(); - virtual status_t GetStyledText(BPositionIO * stream); - virtual status_t WriteStyledEditFile(BFile * file); + virtual void Reset(); + virtual status_t GetStyledText(BPositionIO * stream); + virtual status_t WriteStyledEditFile(BFile * file); - virtual void SetEncoding(uint32 encoding); - virtual uint32 GetEncoding() const; -protected: - virtual void InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs = NULL); - virtual void DeleteText(int32 start, int32 finish); + virtual void SetEncoding(uint32 encoding); + virtual uint32 GetEncoding() const; + + protected: + virtual void InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs = NULL); + virtual void DeleteText(int32 start, int32 finish); -private: - BHandler *fHandler; - BMessage *fChangeMessage; - BMessenger *fMessenger; - bool fSuppressChanges; - uint32 fEncoding; + private: + BHandler *fHandler; + BMessage *fChangeMessage; + BMessenger *fMessenger; + bool fSuppressChanges; + uint32 fEncoding; }; -#endif // STYLED_EDIT_VIEW_H +#endif // STYLED_EDIT_VIEW_H diff --git a/src/apps/stylededit/StyledEditWindow.cpp b/src/apps/stylededit/StyledEditWindow.cpp index abe92748b1..1f8fc70156 100644 --- a/src/apps/stylededit/StyledEditWindow.cpp +++ b/src/apps/stylededit/StyledEditWindow.cpp @@ -1,4 +1,20 @@ -// Be-defined headers +/* + * Copyright 2002-2006, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Mattias Sundblad + * Andrew Bachmann + */ + + +#include "Constants.h" +#include "ColorMenuItem.h" +#include "FindWindow.h" +#include "ReplaceWindow.h" +#include "StyledEditApp.h" +#include "StyledEditView.h" +#include "StyledEditWindow.h" #include #include @@ -15,20 +31,14 @@ #include #include #include + #include #include -//****** Application defined header files************/. -#include "Constants.h" -#include "ColorMenuItem.h" -#include "FindWindow.h" -#include "ReplaceWindow.h" -#include "StyledEditApp.h" -#include "StyledEditView.h" -#include "StyledEditWindow.h" using namespace BPrivate; + StyledEditWindow::StyledEditWindow(BRect frame, int32 id, uint32 encoding) : BWindow(frame,"untitled",B_DOCUMENT_WINDOW,0) { @@ -37,9 +47,11 @@ StyledEditWindow::StyledEditWindow(BRect frame, int32 id, uint32 encoding) unTitled.SetTo("Untitled "); unTitled << id; SetTitle(unTitled.String()); - fSaveItem->SetEnabled(true); // allow saving empty files + fSaveItem->SetEnabled(true); + // allow saving empty files Show(); -} /***StyledEditWindow()***/ +} + StyledEditWindow::StyledEditWindow(BRect frame, entry_ref *ref, uint32 encoding) : BWindow(frame,"untitled",B_DOCUMENT_WINDOW,0) @@ -47,465 +59,453 @@ StyledEditWindow::StyledEditWindow(BRect frame, entry_ref *ref, uint32 encoding) InitWindow(encoding); OpenFile(ref); Show(); -} /***StyledEditWindow()***/ - +} + + StyledEditWindow::~StyledEditWindow() { delete fSaveMessage; delete fPrintSettings; delete fSavePanel; -} /***~StyledEditWindow()***/ - +} + + void StyledEditWindow::InitWindow(uint32 encoding) { - fPrintSettings= NULL; - fSaveMessage= NULL; - + fPrintSettings = NULL; + fSaveMessage = NULL; + // undo modes fUndoFlag = false; fCanUndo = false; fRedoFlag = false; fCanRedo = false; - + // clean modes fUndoCleans = false; fRedoCleans = false; fClean = true; - - //search- state - fReplaceString= ""; - fStringToFind=""; - fCaseSens= false; - fWrapAround= false; - fBackSearch= false; - - //add menubar - fMenuBar = new BMenuBar(BRect(0,0,0,0),"menubar"); - + + // search- state + fReplaceString = ""; + fStringToFind = ""; + fCaseSens = false; + fWrapAround = false; + fBackSearch = false; + + // add menubar + fMenuBar = new BMenuBar(BRect(0, 0, 0, 0), "menubar"); AddChild(fMenuBar); - //add textview and scrollview - BRect viewFrame; - BRect textBounds; - - viewFrame= Bounds(); - - viewFrame.top = fMenuBar->Bounds().Height()+1; //021021 + // add textview and scrollview + + BRect viewFrame = Bounds(); + viewFrame.top = fMenuBar->Bounds().Height() + 1; viewFrame.right -= B_V_SCROLL_BAR_WIDTH; - viewFrame.left = 0; //021021 + viewFrame.left = 0; viewFrame.bottom -= B_H_SCROLL_BAR_HEIGHT; - - textBounds= viewFrame; + BRect 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->SetEncoding(encoding); - - fScrollView= new BScrollView("scrollview", fTextView, B_FOLLOW_ALL, 0, true, true, B_PLAIN_BORDER); + + fScrollView = new BScrollView("scrollview", fTextView, B_FOLLOW_ALL, 0, + true, true, B_PLAIN_BORDER); AddChild(fScrollView); fTextView->MakeFocus(true); - - - //Add "File"-menu: - BMenu *menu; - BMenu *subMenu; - BMenuItem *menuItem; - - menu= new BMenu("File"); + + // Add "File"-menu: + + BMenu* menu = new BMenu("File"); fMenuBar->AddItem(menu); - - menu->AddItem(menuItem= new BMenuItem("New", new BMessage(MENU_NEW), 'N')); + + BMenuItem* menuItem; + menu->AddItem(menuItem = new BMenuItem("New", new BMessage(MENU_NEW), 'N')); menuItem->SetTarget(be_app); - menu->AddItem(menuItem= new BMenuItem(fRecentMenu= new BMenu("Open..."), new BMessage(MENU_OPEN))); - menuItem->SetShortcut('O',0); + menu->AddItem(menuItem = new BMenuItem(fRecentMenu = new BMenu("Open..."), + new BMessage(MENU_OPEN))); + menuItem->SetShortcut('O', 0); menuItem->SetTarget(be_app); - menu->AddSeparatorItem(); - - menu->AddItem(fSaveItem= new BMenuItem("Save", new BMessage(MENU_SAVE), 'S')); + 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))); + menu->AddItem(menuItem = new BMenuItem("Save As...", new BMessage(MENU_SAVEAS))); menuItem->SetShortcut('S',B_SHIFT_KEY); - menuItem->SetEnabled(true); - - menu->AddItem(fRevertItem= new BMenuItem("Revert to Saved...", new BMessage(MENU_REVERT))); - fRevertItem->SetEnabled(false); - menu->AddItem(menuItem= new BMenuItem("Close", new BMessage(MENU_CLOSE), 'W')); - + menuItem->SetEnabled(true); + + menu->AddItem(fRevertItem = new BMenuItem("Revert to Saved...", + new BMessage(MENU_REVERT))); + fRevertItem->SetEnabled(false); + menu->AddItem(menuItem = new BMenuItem("Close", new BMessage(MENU_CLOSE), 'W')); + menu->AddSeparatorItem(); - menu->AddItem(menuItem= new BMenuItem("Page Setup...", new BMessage(MENU_PAGESETUP))); - menu->AddItem(menuItem= new BMenuItem("Print...", new BMessage(MENU_PRINT), 'P')); - + menu->AddItem(menuItem = new BMenuItem("Page Setup...", new BMessage(MENU_PAGESETUP))); + menu->AddItem(menuItem = new BMenuItem("Print...", 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"); + 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')); + + menu->AddItem(fUndoItem = new BMenuItem("Can't Undo", new BMessage(B_UNDO), 'Z')); fUndoItem->SetEnabled(false); - + menu->AddSeparatorItem(); - menu->AddItem(fCutItem= new BMenuItem("Cut", new BMessage(B_CUT), 'X')); + 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')); + 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')); + menu->AddItem(menuItem = new BMenuItem("Paste", new BMessage(B_PASTE), 'V')); menuItem->SetTarget(fTextView); - menu->AddItem(fClearItem= new BMenuItem("Clear", new BMessage(MENU_CLEAR))); + 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')); + 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...", new BMessage(MENU_FIND),'F')); menu->AddItem(fFindAgainItem= new BMenuItem("Find Again",new BMessage(MENU_FIND_AGAIN),'G')); fFindAgainItem->SetEnabled(false); - - 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(fReplaceSameItem= new BMenuItem("Replace Same", new BMessage(MENU_REPLACE_SAME),'T')); + + 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(fReplaceSameItem = new BMenuItem("Replace Same", new BMessage(MENU_REPLACE_SAME),'T')); fReplaceSameItem->SetEnabled(false); - - //Add the "Font"-menu: - BMessage *fontMessage; + + // Add the "Font"-menu: fFontMenu = new BMenu("Font"); fMenuBar->AddItem(fFontMenu); - + //"Size"-subMenu - fFontSizeMenu=new BMenu("Size"); + fFontSizeMenu = new BMenu("Size"); fFontSizeMenu->SetRadioMode(true); fFontMenu->AddItem(fFontSizeMenu); + + const int32 fontSizes[] = {9, 10, 11, 12, 14, 18, 24, 36, 48, 72}; + for (uint32 i = 0; i < sizeof(fontSizes) / sizeof(fontSizes[0]); i++) { + BMessage* fontMessage = new BMessage(FONT_SIZE); + fontMessage->AddFloat("size", fontSizes[i]); + + char label[64]; + snprintf(label, sizeof(label), "%ld", fontSizes[i]); + fFontSizeMenu->AddItem(menuItem = new BMenuItem(label, fontMessage)); + + if (fontSizes[i] == (int32)be_plain_font->Size()) + menuItem->SetMarked(true); + } - fFontSizeMenu->AddItem(menuItem= new BMenuItem("9", fontMessage= new BMessage(FONT_SIZE))); - fontMessage->AddFloat("size", 9.0); - - fFontSizeMenu->AddItem(menuItem= new BMenuItem("10", fontMessage= new BMessage(FONT_SIZE))); - fontMessage->AddFloat("size",10.0); - menuItem->SetMarked(true); - fFontSizeMenu->AddItem(menuItem= new BMenuItem("11", fontMessage= new BMessage(FONT_SIZE))); - fontMessage->AddFloat("size",11.0); - fFontSizeMenu->AddItem(menuItem= new BMenuItem("12", fontMessage= new BMessage(FONT_SIZE))); - fontMessage->AddFloat("size",12.0); - fFontSizeMenu->AddItem(menuItem= new BMenuItem("14", fontMessage= new BMessage(FONT_SIZE))); - fontMessage->AddFloat("size",14.0); - fFontSizeMenu->AddItem(menuItem= new BMenuItem("18", fontMessage= new BMessage(FONT_SIZE))); - fontMessage->AddFloat("size",18.0); - - fFontSizeMenu->AddItem(menuItem= new BMenuItem("24", fontMessage= new BMessage(FONT_SIZE))); - fontMessage->AddFloat("size",24.0); - fFontSizeMenu->AddItem(menuItem= new BMenuItem("36", fontMessage= new BMessage(FONT_SIZE))); - fontMessage->AddFloat("size",36.0); - fFontSizeMenu->AddItem(menuItem= new BMenuItem("48", fontMessage= new BMessage(FONT_SIZE))); - fontMessage->AddFloat("size",48.0); - fFontSizeMenu->AddItem(menuItem= new BMenuItem("72", fontMessage= new BMessage(FONT_SIZE))); - fontMessage->AddFloat("size",72.0); - - //"Color"-subMenu - fFontColorMenu= new BMenu("Color"); + // "Color"-subMenu + fFontColorMenu = new BMenu("Color"); fFontColorMenu->SetRadioMode(true); fFontMenu->AddItem(fFontColorMenu); - fFontColorMenu->AddItem(fBlackItem= new BMenuItem("Black", new BMessage(FONT_COLOR))); + fFontColorMenu->AddItem(fBlackItem = new BMenuItem("Black", new BMessage(FONT_COLOR))); fBlackItem->SetMarked(true); - fFontColorMenu->AddItem(fRedItem= new ColorMenuItem("Red", RED, new BMessage(FONT_COLOR))); - fFontColorMenu->AddItem(fGreenItem= new ColorMenuItem("Green", GREEN, new BMessage(FONT_COLOR))); - fFontColorMenu->AddItem(fBlueItem= new ColorMenuItem("Blue", BLUE, new BMessage(FONT_COLOR))); - fFontColorMenu->AddItem(fCyanItem= new ColorMenuItem("Cyan", CYAN, new BMessage(FONT_COLOR))); - fFontColorMenu->AddItem(fMagentaItem= new ColorMenuItem("Magenta", MAGENTA, new BMessage(FONT_COLOR))); - fFontColorMenu->AddItem(fYellowItem= new ColorMenuItem("Yellow", YELLOW, new BMessage(FONT_COLOR))); + fFontColorMenu->AddItem(fRedItem = new ColorMenuItem("Red", RED, new BMessage(FONT_COLOR))); + fFontColorMenu->AddItem(fGreenItem = new ColorMenuItem("Green", GREEN, new BMessage(FONT_COLOR))); + fFontColorMenu->AddItem(fBlueItem = new ColorMenuItem("Blue", BLUE, new BMessage(FONT_COLOR))); + fFontColorMenu->AddItem(fCyanItem = new ColorMenuItem("Cyan", CYAN, new BMessage(FONT_COLOR))); + fFontColorMenu->AddItem(fMagentaItem = new ColorMenuItem("Magenta", MAGENTA, new BMessage(FONT_COLOR))); + fFontColorMenu->AddItem(fYellowItem = new ColorMenuItem("Yellow", YELLOW, new BMessage(FONT_COLOR))); fFontMenu->AddSeparatorItem(); - //Available fonts - font_family plain_family; - font_style plain_style; - be_plain_font->GetFamilyAndStyle(&plain_family,&plain_style); + // Available fonts, mark "be_plain_font" item + + font_family plainFamily; + font_style plainStyle; + be_plain_font->GetFamilyAndStyle(&plainFamily, &plainStyle); fCurrentFontItem = 0; + BMenu* subMenu; 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); + for (int32 i = 0; i < numFamilies; i++) { + font_family family; + if (get_font_family(i, &family) == B_OK) { + subMenu = new BMenu(family); subMenu->SetRadioMode(true); fFontMenu->AddItem(menuItem = new BMenuItem(subMenu, new BMessage(FONT_FAMILY))); - if (!strcmp(plain_family,localfamily)) { + + if (!strcmp(plainFamily, family)) { menuItem->SetMarked(true); fCurrentFontItem = menuItem; } - int32 numStyles=count_font_styles(localfamily); - for(int32 j = 0;jAddItem(menuItem = new BMenuItem(style, new BMessage(FONT_STYLE))); - if (!strcmp(plain_style,style)) { + if (get_font_style(family, j, &style, &flags) == B_OK) { + subMenu->AddItem(menuItem = new BMenuItem(style, + new BMessage(FONT_STYLE))); + + if (!strcmp(plainStyle, style)) menuItem->SetMarked(true); - } } } } - } - - //Add the "Document"-menu: - menu= new BMenu("Document"); + } + + // Add the "Document"-menu: + menu = new BMenu("Document"); fMenuBar->AddItem(menu); - - //"Align"-subMenu: - subMenu= new BMenu("Align"); + + // "Align"-subMenu: + subMenu = new BMenu("Align"); subMenu->SetRadioMode(true); subMenu->AddItem(fAlignLeft = new BMenuItem("Left", new BMessage(ALIGN_LEFT))); menuItem->SetMarked(true); - + subMenu->AddItem(fAlignCenter = new BMenuItem("Center", new BMessage(ALIGN_CENTER))); subMenu->AddItem(fAlignRight = 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 = 0; // build lazily - fSavePanelEncodingMenu = 0; // build lazily -} /***StyledEditWindow::Initwindow()***/ + + fSavePanel = NULL; + fSavePanelEncodingMenu = NULL; + // build lazily +} + void StyledEditWindow::MessageReceived(BMessage *message) { - if(message->WasDropped()) { + if (message->WasDropped()) { entry_ref ref; - if(message->FindRef("refs",0,&ref)==B_OK) { - message->what=B_REFS_RECEIVED; + if (message->FindRef("refs", 0, &ref)==B_OK) { + message->what = B_REFS_RECEIVED; be_app->PostMessage(message); } } - - switch(message->what){ -/************file menu:***************/ - case MENU_SAVE: { - if(!fSaveMessage) + + switch (message->what) { + // File menu + case MENU_SAVE: + if (!fSaveMessage) SaveAs(); else Save(fSaveMessage); - } - break; + break; + case MENU_SAVEAS: SaveAs(); - break; + break; + case B_SAVE_REQUESTED: Save(message); - break; + break; + case SAVE_THEN_QUIT: - if (Save(message) == B_OK) { - BAutolock lock(this); + if (Save(message) == B_OK) Quit(); - } - break; + break; + case MENU_REVERT: RevertToSaved(); - break; - case MENU_CLOSE: { - if(this->QuitRequested()) { - BAutolock lock(this); + break; + + case MENU_CLOSE: + if (QuitRequested()) Quit(); - } - } - break; + break; + case MENU_PAGESETUP: PageSetup(fTextView->Window()->Title()); - break; + break; case MENU_PRINT: Print(fTextView->Window()->Title()); - break; + break; case MENU_QUIT: be_app->PostMessage(B_QUIT_REQUESTED); - break; -/*********commands from the "Edit"-menu:**************/ + break; + + // Edit menu + case B_UNDO: ASSERT(fCanUndo || fCanRedo); ASSERT(!(fCanUndo && fCanRedo)); - if (fCanUndo) { + if (fCanUndo) fUndoFlag = true; - } - if (fCanRedo) { + if (fCanRedo) fRedoFlag = true; - } + fTextView->Undo(be_clipboard); - break; + break; case B_CUT: fTextView->Cut(be_clipboard); - break; + break; case B_COPY: fTextView->Copy(be_clipboard); - break; + break; case B_PASTE: fTextView->Paste(be_clipboard); - break; + break; case MENU_CLEAR: fTextView->Clear(); - break; + break; case MENU_FIND: - { - BRect findWindowFrame(100,100,400,235); - FindWindow *find; - find= new FindWindow(findWindowFrame, this, &fStringToFind, &fCaseSens, - &fWrapAround, &fBackSearch); - } - break; + { + BRect findWindowFrame(100, 100, 400, 235); + BWindow* window = new FindWindow(findWindowFrame, this, + &fStringToFind, &fCaseSens, &fWrapAround, &fBackSearch); + window->Show(); + break; + } case MSG_SEARCH: - { message->FindString("findtext", &fStringToFind); fFindAgainItem->SetEnabled(true); 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; + break; case MENU_FIND_SELECTION: FindSelection(); - break; + break; case MENU_REPLACE: - { - BRect replaceWindowFrame(100,100,400,284); - ReplaceWindow *replace; - replace= new ReplaceWindow(replaceWindowFrame, this, &fStringToFind, &fReplaceString, &fCaseSens, - &fWrapAround, &fBackSearch); - } - break; + { + BRect replaceWindowFrame(100, 100, 400, 284); + BWindow* window = new ReplaceWindow(replaceWindowFrame, this, + &fStringToFind, &fReplaceString, &fCaseSens, &fWrapAround, &fBackSearch); + window->Show(); + 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; + + message->FindString("FindText", &findIt); + message->FindString("ReplaceText", &replaceWith); + fStringToFind = findIt; fFindAgainItem->SetEnabled(true); - fReplaceString= replaceWith; + fReplaceString = replaceWith; fReplaceSameItem->SetEnabled(true); - fCaseSens= caseSens; - fWrapAround= wrap; - fBackSearch= backSearch; - + fCaseSens = caseSens; + fWrapAround = wrap; + fBackSearch = backSearch; + Replace(findIt, replaceWith, caseSens, wrap, backSearch); + break; } - break; case MENU_REPLACE_SAME: - { Replace(fStringToFind,fReplaceString,fCaseSens,fWrapAround,fBackSearch); - } - break; + 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; + + fStringToFind = findIt; fFindAgainItem->SetEnabled(true); - fReplaceString= replaceWith; + fReplaceString = replaceWith; fReplaceSameItem->SetEnabled(true); - fCaseSens= caseSens; - - - if(allWindows) + fCaseSens = caseSens; + + if (allWindows) SearchAllWindows(findIt, replaceWith, caseSens); else ReplaceAll(findIt, replaceWith,caseSens); - - } - break; -/*********"Font"-menu*****************/ + break; + } + + // Font menu + case FONT_SIZE: { float fontSize; - message->FindFloat("size",&fontSize); - SetFontSize(fontSize); + if (message->FindFloat("size", &fontSize) == B_OK) + SetFontSize(fontSize); + break; } - break; case FONT_FAMILY: - { - const char * fontFamily = 0, * fontStyle = 0; - void * ptr; - if (message->FindPointer("source",&ptr) == B_OK) { + { + const char* fontFamily = NULL; + const char* fontStyle = NULL; + void* ptr; + if (message->FindPointer("source", &ptr) == B_OK) { fCurrentFontItem = static_cast(ptr); fontFamily = fCurrentFontItem->Label(); } SetFontStyle(fontFamily, fontStyle); - } - break; + break; + } case FONT_STYLE: - { - const char * fontFamily = 0, * fontStyle = 0; - void * ptr; - if (message->FindPointer("source",&ptr) == B_OK) { - BMenuItem * item = static_cast(ptr); + { + const char* fontFamily = NULL; + const char* fontStyle = NULL; + void* ptr; + if (message->FindPointer("source", &ptr) == B_OK) { + BMenuItem* item = static_cast(ptr); fontStyle = item->Label(); - BMenu * menu = item->Menu(); - if (menu != 0) { + BMenu* menu = item->Menu(); + if (menu != NULL) { fCurrentFontItem = menu->Superitem(); - if (fCurrentFontItem != 0) { + if (fCurrentFontItem != NULL) fontFamily = fCurrentFontItem->Label(); - } } } SetFontStyle(fontFamily, fontStyle); - } - break; + break; + } case FONT_COLOR: { - void * ptr; - if (message->FindPointer("source",&ptr) == B_OK) { - if (ptr == fBlackItem) { + void* ptr; + if (message->FindPointer("source", &ptr) == B_OK) { + if (ptr == fBlackItem) SetFontColor(&BLACK); - } else if (ptr == fRedItem) { + else if (ptr == fRedItem) SetFontColor(&RED); - } else if (ptr == fGreenItem) { + else if (ptr == fGreenItem) SetFontColor(&GREEN); - } else if (ptr == fBlueItem) { + else if (ptr == fBlueItem) SetFontColor(&BLUE); - } else if (ptr == fCyanItem) { + else if (ptr == fCyanItem) SetFontColor(&CYAN); - } else if (ptr == fMagentaItem) { + else if (ptr == fMagentaItem) SetFontColor(&MAGENTA); - } else if (ptr == fYellowItem) { + else if (ptr == fYellowItem) SetFontColor(&YELLOW); - } } + break; } - break; -/*********"Document"-menu*************/ + + // Document menu + case ALIGN_LEFT: fTextView->SetAlignment(B_ALIGN_LEFT); fClean = false; @@ -517,7 +517,7 @@ StyledEditWindow::MessageReceived(BMessage *message) fUndoItem->SetEnabled(false); fCanUndo = false; fCanRedo = false; - break; + break; case ALIGN_CENTER: fTextView->SetAlignment(B_ALIGN_CENTER); fClean = false; @@ -529,7 +529,7 @@ StyledEditWindow::MessageReceived(BMessage *message) fUndoItem->SetEnabled(false); fCanUndo = false; fCanRedo = false; - break; + break; case ALIGN_RIGHT: fTextView->SetAlignment(B_ALIGN_RIGHT); fClean = false; @@ -541,7 +541,7 @@ StyledEditWindow::MessageReceived(BMessage *message) fUndoItem->SetEnabled(false); fCanUndo = false; fCanRedo = false; - break; + break; case WRAP_LINES: if (fTextView->DoesWordWrap()) { fTextView->SetWordWrap(false); @@ -571,20 +571,18 @@ StyledEditWindow::MessageReceived(BMessage *message) fUndoItem->SetEnabled(false); fCanUndo = false; fCanRedo = false; - break; - case ENABLE_ITEMS: { + break; + case ENABLE_ITEMS: fCutItem->SetEnabled(true); fCopyItem->SetEnabled(true); fClearItem->SetEnabled(true); - } - break; - case DISABLE_ITEMS: { + break; + case DISABLE_ITEMS: fCutItem->SetEnabled(false); fCopyItem->SetEnabled(false); fClearItem->SetEnabled(false); - } - break; - case TEXT_CHANGED: { + break; + case TEXT_CHANGED: if (fUndoFlag) { if (fUndoCleans) { // we cleaned! @@ -629,76 +627,76 @@ StyledEditWindow::MessageReceived(BMessage *message) } else { fRevertItem->SetEnabled(fSaveMessage != NULL); fSaveItem->SetEnabled(true); - } - // clear flags - } - break; -/*********"Document"-menu*************/ - case SAVE_AS_ENCODING: - void * ptr; - if (message->FindPointer("source",&ptr) == B_OK) { - if (fSavePanelEncodingMenu != 0) { - fTextView->SetEncoding((uint32)fSavePanelEncodingMenu->IndexOf((BMenuItem*)ptr)); - } } - break; + break; + + case SAVE_AS_ENCODING: + void* ptr; + if (message->FindPointer("source", &ptr) == B_OK + && fSavePanelEncodingMenu != NULL) { + fTextView->SetEncoding((uint32)fSavePanelEncodingMenu->IndexOf((BMenuItem*)ptr)); + } + break; + default: - BWindow::MessageReceived(message); - break; + BWindow::MessageReceived(message); + break; } -}/***StyledEditWindow::MessageReceived() ***/ +} + void StyledEditWindow::MenusBeginning() { // set up the recent documents menu BMessage documents; - be_roster->GetRecentDocuments(&documents,9,NULL,APP_SIGNATURE); - + be_roster->GetRecentDocuments(&documents, 9, NULL, APP_SIGNATURE); + // delete old items.. // shatty: it would be preferable to keep the old // menu around instead of continuously thrashing // the menu, but unfortunately there does not // seem to be a straightforward way to update it // going backwards may simplify memory management - for (int i = fRecentMenu->CountItems()-1 ; (i >= 0) ; i--) { + for (int i = fRecentMenu->CountItems(); i-- > 0;) { delete fRecentMenu->RemoveItem(i); } + // add new items int count = 0; entry_ref ref; - while (documents.FindRef("refs",count++,&ref) == B_OK) { - if ((ref.device != -1) && (ref.directory != -1)) { + while (documents.FindRef("refs", count++, &ref) == B_OK) { + if (ref.device != -1 && ref.directory != -1) { // sanity check passed - BMessage * openRecent = new BMessage(B_REFS_RECEIVED); - openRecent->AddRef("refs",&ref); - BMenuItem * item = new BMenuItem(ref.name,openRecent); + BMessage* openRecent = new BMessage(B_REFS_RECEIVED); + openRecent->AddRef("refs", &ref); + BMenuItem* item = new BMenuItem(ref.name, openRecent); item->SetTarget(be_app); fRecentMenu->AddItem(item); } } - - // update the font menu be/interface/GraphicsDefs.h + + // update the font menu // unselect the old values - if (fCurrentFontItem != 0) { + if (fCurrentFontItem != NULL) fCurrentFontItem->SetMarked(false); - } - BMenuItem * oldColorItem = fFontColorMenu->FindMarked(); - if (oldColorItem != 0) { + + BMenuItem* oldColorItem = fFontColorMenu->FindMarked(); + if (oldColorItem != NULL) oldColorItem->SetMarked(false); - } - BMenuItem * oldSizeItem = fFontSizeMenu->FindMarked(); - if (oldSizeItem != 0) { + + BMenuItem* oldSizeItem = fFontSizeMenu->FindMarked(); + if (oldSizeItem != NULL) oldSizeItem->SetMarked(false); - } + // find the current font, color, size BFont font; uint32 sameProperties; rgb_color color = BLACK; bool sameColor; - fTextView->GetFontAndColor(&font,&sameProperties,&color,&sameColor); - - if (sameColor && (color.alpha == 255)) { + fTextView->GetFontAndColor(&font, &sameProperties, &color, &sameColor); + + if (sameColor && color.alpha == 255) { // select the current color if (color.red == 0) { if (color.green == 0) { @@ -728,158 +726,159 @@ StyledEditWindow::MenusBeginning() } } } - + if (sameProperties & B_FONT_SIZE) { if ((int)font.Size() == font.Size()) { // select the current font size char fontSizeStr[16]; - snprintf(fontSizeStr,15,"%i",(int)font.Size()); - BMenuItem * item = fFontSizeMenu->FindItem(fontSizeStr); - if (item != 0) { + snprintf(fontSizeStr, 15, "%i", (int)font.Size()); + BMenuItem* item = fFontSizeMenu->FindItem(fontSizeStr); + if (item != NULL) item->SetMarked(true); - } } } - + if (sameProperties & B_FONT_FAMILY_AND_STYLE) { font_family family; font_style style; - font.GetFamilyAndStyle(&family,&style); + font.GetFamilyAndStyle(&family, &style); fCurrentFontItem = fFontMenu->FindItem(family); - if (fCurrentFontItem != 0) { + if (fCurrentFontItem != NULL) { fCurrentFontItem->SetMarked(true); - BMenu * menu = fCurrentFontItem->Submenu(); - if (menu != 0) { - BMenuItem * item = menu->FindItem(style); - if (item != 0) { + BMenu* menu = fCurrentFontItem->Submenu(); + if (menu != NULL) { + BMenuItem* item = menu->FindItem(style); + if (item != NULL) item->SetMarked(true); - } } } } - + switch (fTextView->Alignment()) { - case B_ALIGN_LEFT: - fAlignLeft->SetMarked(true); - break; - case B_ALIGN_CENTER: - fAlignCenter->SetMarked(true); - break; - case B_ALIGN_RIGHT: - fAlignRight->SetMarked(true); - break; - default: - // I am so confused. - break; + case B_ALIGN_LEFT: + default: + fAlignLeft->SetMarked(true); + break; + case B_ALIGN_CENTER: + fAlignCenter->SetMarked(true); + break; + case B_ALIGN_RIGHT: + fAlignRight->SetMarked(true); + break; } } + void StyledEditWindow::Quit() { styled_edit_app->CloseDocument(); BWindow::Quit(); } - + + bool StyledEditWindow::QuitRequested() { - int32 buttonIndex= 0; - - if (fClean) return true; + int32 buttonIndex = 0; + + if (fClean) + return true; 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", + 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); - saveAlert->SetShortcut(1,'d'); - saveAlert->SetShortcut(2,'s'); - buttonIndex= saveAlert->Go(); + saveAlert->SetShortcut(1, 'd'); + saveAlert->SetShortcut(2, 's'); + buttonIndex = saveAlert->Go(); - if (buttonIndex==0) { //"cancel": dont save, dont close the window + if (buttonIndex == 0) { + // "cancel": dont save, dont close the window return false; - } else if(buttonIndex==1) { // "don't save": just close the window + } else if (buttonIndex == 1) { + // "don't save": just close the window return true; - } else if(!fSaveMessage) { //save as - BMessage * message = new BMessage(SAVE_THEN_QUIT); + } else if (!fSaveMessage) { + // save as + BMessage* message = new BMessage(SAVE_THEN_QUIT); SaveAs(message); return false; - } else { - return (Save() == B_OK); } - -}/***QuitRequested()***/ - + + return Save() == B_OK; +} + + status_t StyledEditWindow::Save(BMessage *message) { status_t err = B_OK; - - if(!message){ - message=fSaveMessage; - if(!message) + + if (!message){ + message = fSaveMessage; + if (!message) return B_ERROR; } - - entry_ref dirref; - err= message->FindRef("directory", &dirref); - if(err!= B_OK) - return err; - - const char *name; - err=message->FindString("name", &name); + + entry_ref dirRef; + err = message->FindRef("directory", &dirRef); if (err!= B_OK) return err; - - BDirectory dir(&dirref); - err= dir.InitCheck(); - if(err!= B_OK) + + const char* name; + err = message->FindString("name", &name); + if (err!= B_OK) return err; - + + BDirectory dir(&dirRef); + err = dir.InitCheck(); + if (err != B_OK) + return err; + BEntry entry(&dir, name); - err= entry.InitCheck(); - if(err!= B_OK) + err = entry.InitCheck(); + if (err != B_OK) return err; - + BFile file(&entry, B_READ_WRITE | B_CREATE_FILE); - err= file.InitCheck(); - if(err!= B_OK) + err = file.InitCheck(); + if (err != B_OK) return err; - + err = fTextView->WriteStyledEditFile(&file); - if(err != B_OK) { + if (err != B_OK) { BAlert *saveFailedAlert; BString alertText; - if (err == B_TRANSLATION_ERROR_BASE) { + if (err == B_TRANSLATION_ERROR_BASE) alertText.SetTo("Translation error saving \""); - } else { + else alertText.SetTo("Unknown error saving \""); - } - alertText<< name; - alertText<<"\"."; - saveFailedAlert= new BAlert("saveFailedAlert",alertText.String(), "Bummer", 0, 0, - B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_STOP_ALERT); + + alertText << name; + alertText << "\"."; + saveFailedAlert = new BAlert("saveFailedAlert", alertText.String(), "Bummer", + 0, 0, B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_STOP_ALERT); saveFailedAlert->SetShortcut(0, B_ESCAPE); saveFailedAlert->Go(); return err; } SetTitle(name); - if(fSaveMessage!= message) - { + + if (fSaveMessage != message) { delete fSaveMessage; - fSaveMessage= new BMessage(*message); + fSaveMessage = new BMessage(*message); } entry_ref ref; - if (entry.GetRef(&ref) == B_OK) { - be_roster->AddToRecentDocuments(&ref,APP_SIGNATURE); - } - + if (entry.GetRef(&ref) == B_OK) + be_roster->AddToRecentDocuments(&ref, APP_SIGNATURE); + // clear clean modes fSaveItem->SetEnabled(false); fRevertItem->SetEnabled(false); @@ -887,24 +886,26 @@ StyledEditWindow::Save(BMessage *message) fRedoCleans = false; fClean = true; return err; -} /***Save()***/ +} + status_t StyledEditWindow::SaveAs(BMessage *message) { - if (fSavePanel == 0) { - entry_ref * directory = 0; - if (fSaveMessage != 0) { - entry_ref dirref; - if (fSaveMessage->FindRef("directory", &dirref)) { - directory = new entry_ref(dirref); - } + if (fSavePanel == NULL) { + entry_ref* directory = NULL; + if (fSaveMessage != NULL) { + entry_ref dirRef; + if (fSaveMessage->FindRef("directory", &dirRef)) + directory = new entry_ref(dirRef); } - fSavePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this), directory, B_FILE_NODE, false); - - BMenuBar * menuBar = - dynamic_cast(fSavePanel->Window()->FindView("MenuBar")); - + + fSavePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this), + directory, B_FILE_NODE, false); + + BMenuBar* menuBar = dynamic_cast( + fSavePanel->Window()->FindView("MenuBar")); + fSavePanelEncodingMenu= new BMenu("Encoding"); menuBar->AddItem(fSavePanelEncodingMenu); fSavePanelEncodingMenu->SetRadioMode(true); @@ -913,99 +914,99 @@ StyledEditWindow::SaveAs(BMessage *message) BCharacterSet charset; while (roster.GetNextCharacterSet(&charset) == B_NO_ERROR) { BString name(charset.GetPrintName()); - const char * mime = charset.GetMIMEName(); + 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)); + BMenuItem * item = new BMenuItem(name.String(), new BMessage(SAVE_AS_ENCODING)); item->SetTarget(this); fSavePanelEncodingMenu->AddItem(item); - if (charset.GetFontID() == fTextView->GetEncoding()) { + if (charset.GetFontID() == fTextView->GetEncoding()) item->SetMarked(true); - } } } - + fSavePanel->SetSaveText(Title()); - if (message != 0) { + if (message != NULL) fSavePanel->SetMessage(message); - } + fSavePanel->Show(); return B_OK; } -void -StyledEditWindow::OpenFile(entry_ref *ref) + +status_t +StyledEditWindow::_LoadFile(entry_ref* ref) { BFile file; - status_t fileinit; - - fileinit = file.SetTo(ref, B_READ_ONLY); - - if (fileinit == B_OK){ - status_t result; - result = fTextView->GetStyledText(&file); //he he he :) + status_t status = file.SetTo(ref, B_READ_ONLY); + if (status == B_OK) + status = fTextView->GetStyledText(&file); - if (result != B_OK) { - BEntry entry(ref, true); - char name[B_FILE_NAME_LENGTH]; - entry.GetName(name); - BAlert *loadFailedAlert; - BString alertText; - if (result == B_TRANSLATION_ERROR_BASE) { - alertText.SetTo("Translation error loading \""); - } else { - alertText.SetTo("Unknown error loading \""); - } - alertText<< name; - alertText<<"\"."; - loadFailedAlert= new BAlert("loadFailedAlert",alertText.String(), "Bummer", 0, 0, - B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_STOP_ALERT); - loadFailedAlert->Go(); - return; - } + if (status != B_OK) { + BEntry entry(ref, true); + char name[B_FILE_NAME_LENGTH]; + if (entry.GetName(name) != B_OK) + strcpy(name, "???"); - // update alignment - switch (fTextView->Alignment()) { - case B_ALIGN_LEFT: - fAlignLeft->SetMarked(true); - break; - case B_ALIGN_CENTER: - fAlignCenter->SetMarked(true); - break; - case B_ALIGN_RIGHT: - fAlignRight->SetMarked(true); - break; - default: - // weird - break; - } - - // update word wrapping - fWrapItem->SetMarked(fTextView->DoesWordWrap()); - } else { - fSaveItem->SetEnabled(true); // allow saving new files + char text[B_PATH_NAME_LENGTH + 100]; + snprintf(text, sizeof(text), "Error loading \"%s\":\n\t%s", name, + strerror(status)); + + BAlert* alert = new BAlert("StyledEdit Load Failed", text, + "Bummer", 0, 0, B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_STOP_ALERT); + alert->Go(); + return status; } - be_roster->AddToRecentDocuments(ref,APP_SIGNATURE); + // update alignment + switch (fTextView->Alignment()) { + case B_ALIGN_LEFT: + default: + fAlignLeft->SetMarked(true); + break; + case B_ALIGN_CENTER: + fAlignCenter->SetMarked(true); + break; + case B_ALIGN_RIGHT: + fAlignRight->SetMarked(true); + break; + } + + // update word wrapping + fWrapItem->SetMarked(fTextView->DoesWordWrap()); + return B_OK; +} + + +void +StyledEditWindow::OpenFile(entry_ref* ref) +{ + if (_LoadFile(ref) != B_OK) { + fSaveItem->SetEnabled(true); + // allow saving new files + } + + be_roster->AddToRecentDocuments(ref, APP_SIGNATURE); fSaveMessage = new BMessage(B_SAVE_REQUESTED); - if(fSaveMessage){ + 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->AddRef("directory", &parentRef); fSaveMessage->AddString("name", name); SetTitle(name); } - fTextView->Select(0,0); -}/*** StyledEditWindow::OpenFile() ***/ + fTextView->Select(0, 0); +} + void StyledEditWindow::RevertToSaved() @@ -1015,79 +1016,48 @@ StyledEditWindow::RevertToSaved() fSaveMessage->FindRef("directory", &ref); fSaveMessage->FindString("name", &name); - - BDirectory dir(&ref); - BFile file(&dir, name, B_READ_ONLY); - status_t result; - result = file.InitCheck(); - if (result != B_OK) { + BDirectory dir(&ref); + status_t status = dir.InitCheck(); + BEntry entry; + if (status == B_OK) + status = entry.SetTo(&dir, name); + if (status == B_OK) + status = entry.GetRef(&ref); + if (status != B_OK || !entry.Exists()) { BAlert *vanishedAlert; BString alertText; alertText.SetTo("Cannot revert, file not found: \""); - alertText<< name; - alertText<<"\"."; - vanishedAlert = new BAlert("vanishedAlert",alertText.String(), "Bummer", 0, 0, + alertText << name; + alertText << "\"."; + vanishedAlert = new BAlert("vanishedAlert", alertText.String(), "Bummer", 0, 0, B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_STOP_ALERT); vanishedAlert->SetShortcut(0, B_ESCAPE); vanishedAlert->Go(); return; - } - - int32 buttonIndex= 0; - BAlert *revertAlert; + } + + int32 buttonIndex = 0; + BAlert* revertAlert; BString alertText; alertText.SetTo("Revert to the last version of \""); - alertText<< Title(); - alertText<<"\"? "; - revertAlert= new BAlert("revertAlert",alertText.String(), "Cancel", "OK", 0, + alertText << Title(); + alertText << "\"? "; + revertAlert= new BAlert("revertAlert", alertText.String(), "Cancel", "OK", 0, B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT); revertAlert->SetShortcut(0, B_ESCAPE); revertAlert->SetShortcut(1, 'o'); - buttonIndex= revertAlert->Go(); - - if (buttonIndex!=1) { // some sort of cancel, don't revert - return; - } - - fTextView->Reset(); //clear the textview... - result = fTextView->GetStyledText(&file); //he he he :) + buttonIndex = revertAlert->Go(); - if (result != B_OK) { - BAlert *loadFailedAlert; - BString alertText; - if (result == B_TRANSLATION_ERROR_BASE) { - alertText.SetTo("Translation error loading \""); - } else { - alertText.SetTo("Unknown error loading \""); - } - alertText<< name; - alertText<<"\"."; - loadFailedAlert= new BAlert("loadFailedAlert",alertText.String(), "Bummer", 0, 0, - B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_STOP_ALERT); - loadFailedAlert->SetShortcut(0, B_ESCAPE); - loadFailedAlert->Go(); + if (buttonIndex != 1) { + // some sort of cancel, don't revert return; } - // update alignment - switch (fTextView->Alignment()) { - case B_ALIGN_LEFT: - fAlignLeft->SetMarked(true); - break; - case B_ALIGN_CENTER: - fAlignCenter->SetMarked(true); - break; - case B_ALIGN_RIGHT: - fAlignRight->SetMarked(true); - break; - default: - // weird - break; - } + fTextView->Reset(); - // update word wrapping - fWrapItem->SetMarked(fTextView->DoesWordWrap()); + if (_LoadFile(&ref) != B_OK) + return; // clear undo modes fUndoItem->SetLabel("Can't Undo"); @@ -1096,218 +1066,215 @@ StyledEditWindow::RevertToSaved() fCanUndo = false; fRedoFlag = false; fCanRedo = false; + // clear clean modes fSaveItem->SetEnabled(false); fRevertItem->SetEnabled(false); fUndoCleans = false; fRedoCleans = false; fClean = true; -}/***StyledEditWindow::RevertToSaved()***/ - +} + + status_t -StyledEditWindow::PageSetup(const char *documentname) +StyledEditWindow::PageSetup(const char* documentName) { - status_t result = B_OK; - - BPrintJob printJob(documentname); - - if (fPrintSettings != NULL) { + BPrintJob printJob(documentName); + + if (fPrintSettings != NULL) printJob.SetSettings(new BMessage(*fPrintSettings)); - } - - result = printJob.ConfigPage(); - - if (result == B_NO_ERROR) { + + status_t result = printJob.ConfigPage(); + if (result == B_OK) { delete fPrintSettings; fPrintSettings = printJob.Settings(); - } + } return result; -}/***StyledEditWindow::PageSetup()***/ - +} + + void -StyledEditWindow::Print(const char *documentname) +StyledEditWindow::Print(const char* documentName) { - status_t result = B_OK; - + status_t result; + if (fPrintSettings == NULL) { - result = PageSetup(documentname); - if (result != B_OK) { + result = PageSetup(documentName); + if (result != B_OK) return; - } } - - BPrintJob printJob(documentname); + + BPrintJob printJob(documentName); printJob.SetSettings(new BMessage(*fPrintSettings)); result = printJob.ConfigJob(); - if (result != B_OK) { + if (result != B_OK) return; - } + // information from printJob - BRect printable_rect = printJob.PrintableRect(); + BRect printableRect = printJob.PrintableRect(); int32 firstPage = printJob.FirstPage(); int32 lastPage = printJob.LastPage(); - + // lines eventually to be used to compute pages to print int32 firstLine = 0; int32 lastLine = fTextView->CountLines(); - + // values to be computed int32 pagesInDocument = 1; int32 linesInDocument = fTextView->CountLines(); - + int32 currentLine = 0; while (currentLine < linesInDocument) { float currentHeight = 0; - while ((currentHeight < printable_rect.Height()) && (currentLine < linesInDocument)) { + while (currentHeight < printableRect.Height() && currentLine < linesInDocument) { currentHeight += fTextView->LineHeight(currentLine); - if (currentHeight < printable_rect.Height()) { + if (currentHeight < printableRect.Height()) currentLine++; - } } - if (pagesInDocument == lastPage) { + if (pagesInDocument == lastPage) lastLine = currentLine; - } - if (currentHeight >= printable_rect.Height()) { + + if (currentHeight >= printableRect.Height()) { pagesInDocument++; - if (pagesInDocument == firstPage) { + if (pagesInDocument == firstPage) firstLine = currentLine; - } } } - + if (lastPage > pagesInDocument - 1) { lastPage = pagesInDocument - 1; lastLine = currentLine - 1; } - + printJob.BeginJob(); int32 printLine = firstLine; while (printLine < lastLine) { float currentHeight = 0; int32 firstLineOnPage = printLine; - while ((currentHeight < printable_rect.Height()) && (printLine < lastLine)) { + while (currentHeight < printableRect.Height() && printLine < lastLine) { currentHeight += fTextView->LineHeight(printLine); - if (currentHeight < printable_rect.Height()) { + if (currentHeight < printableRect.Height()) printLine++; - } } + float top = 0; - if (firstLineOnPage != 0) { - top = fTextView->TextHeight(0,firstLineOnPage-1); - } - float bottom = fTextView->TextHeight(0,printLine-1); - BRect textRect(0.0,top+TEXT_INSET,printable_rect.Width(),bottom+TEXT_INSET); - printJob.DrawView(fTextView,textRect,BPoint(0.0,0.0)); + if (firstLineOnPage != 0) + top = fTextView->TextHeight(0, firstLineOnPage - 1); + + float bottom = fTextView->TextHeight(0, printLine - 1); + BRect textRect(0.0, top + TEXT_INSET, printableRect.Width(), bottom + TEXT_INSET); + printJob.DrawView(fTextView, textRect, BPoint(0.0,0.0)); printJob.SpoolPage(); } + printJob.CommitJob(); -}/***StyledEditWindow::Print()***/ +} + bool -StyledEditWindow::Search(BString string, bool casesens, bool wrap, bool backsearch) +StyledEditWindow::Search(BString string, bool caseSensitive, bool wrap, bool backsearch) { - int32 start; - int32 finish; - int32 strlen; - + int32 start; + int32 finish; + start = B_ERROR; - - strlen = string.Length(); - if (strlen== 0) + + int32 length = string.Length(); + if (length == 0) return false; - + BString viewText(fTextView->Text()); int32 textStart, textFinish; fTextView->GetSelection(&textStart, &textFinish); - if (backsearch == true) { - if (casesens == true) { + if (backsearch) { + if (caseSensitive) { start = viewText.FindLast(string, textStart); } else { start = viewText.IFindLast(string, textStart); } } else { - if (casesens == true) { + if (caseSensitive == true) { start = viewText.FindFirst(string, textFinish); } else { start = viewText.IFindFirst(string, textFinish); } } - if ((start == B_ERROR) && (wrap == true)) { - if (backsearch == true) { - if (casesens == true) { + if (start == B_ERROR && wrap) { + if (backsearch) { + if (caseSensitive) { start = viewText.FindLast(string, viewText.Length()); } else { start = viewText.IFindLast(string, viewText.Length()); } } else { - if (casesens == true) { + if (caseSensitive) { start = viewText.FindFirst(string, 0); } else { start = viewText.IFindFirst(string, 0); } } } - + if (start != B_ERROR) { - finish = start + strlen; + finish = start + length; fTextView->Select(start, finish); fTextView->ScrollToSelection(); return true; - } else { - return false; } -}/***StyledEditWindow::Search***/ + + return false; +} + void StyledEditWindow::FindSelection() { int32 selectionStart, selectionFinish; - fTextView->GetSelection(&selectionStart,&selectionFinish); - - int32 selectionLength; - selectionLength= selectionFinish- selectionStart; - - BString viewText; - viewText= fTextView->Text(); - + fTextView->GetSelection(&selectionStart, &selectionFinish); + + int32 selectionLength = selectionFinish- selectionStart; + + BString viewText = fTextView->Text(); viewText.CopyInto(fStringToFind, selectionStart, selectionLength); fFindAgainItem->SetEnabled(true); Search(fStringToFind, fCaseSens, fWrapAround, fBackSearch); +} + -}/***StyledEditWindow::FindSelection()***/ - bool -StyledEditWindow::Replace(BString findthis, BString replaceWith, bool casesens, bool wrap, bool backsearch) +StyledEditWindow::Replace(BString findthis, BString replaceWith, bool caseSensitive, + bool wrap, bool backsearch) { - if (Search(findthis, casesens, wrap, backsearch)) { + if (Search(findthis, caseSensitive, wrap, backsearch)) { int32 start, finish; fTextView->GetSelection(&start, &finish); - + fTextView->Delete(start, start + findthis.Length()); fTextView->Insert(start, replaceWith.String(), replaceWith.Length()); fTextView->Select(start, start + replaceWith.Length()); fTextView->ScrollToSelection(); return true; - } else { - return false; } -}/***StyledEditWindow::Replace()***/ + + return false; +} + void -StyledEditWindow::ReplaceAll(BString findIt, BString replaceWith, bool caseSens) +StyledEditWindow::ReplaceAll(BString findIt, BString replaceWith, bool caseSensitive) { BString viewText(fTextView->Text()); - if (caseSens) - viewText.ReplaceAll(findIt.String(),replaceWith.String()); + if (caseSensitive) + viewText.ReplaceAll(findIt.String(), replaceWith.String()); else - viewText.IReplaceAll(findIt.String(),replaceWith.String()); - + viewText.IReplaceAll(findIt.String(), replaceWith.String()); + if (viewText.Compare(fTextView->Text()) == 0) { // they are the same return; } - + int32 textStart, textFinish; fTextView->GetSelection(&textStart, &textFinish); @@ -1317,10 +1284,10 @@ StyledEditWindow::ReplaceAll(BString findIt, BString replaceWith, bool caseSens) textStart = viewText.Length(); if (viewText.Length() < textFinish) textFinish = viewText.Length(); - + fTextView->Select(textStart,textFinish); fTextView->ScrollToSelection(); - + fClean = false; fUndoCleans = false; fRedoCleans = false; @@ -1330,31 +1297,31 @@ StyledEditWindow::ReplaceAll(BString findIt, BString replaceWith, bool caseSens) fUndoItem->SetEnabled(false); fCanUndo = false; fCanRedo = false; -}/***StyledEditWindow::ReplaceAll()***/ +} + void -StyledEditWindow::SearchAllWindows(BString find, BString replace, bool casesens) +StyledEditWindow::SearchAllWindows(BString find, BString replace, bool caseSensitive) { int32 numWindows; - numWindows= be_app->CountWindows(); - + 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); - + message->AddString("FindText", find); + message->AddString("ReplaceText", replace); + message->AddBool("casesens", caseSensitive); + + while (numWindows >= 0) { + StyledEditWindow *window = dynamic_cast( + be_app->WindowAt(numWindows)); + + BMessenger messenger(window); + messenger.SendMessage(message); + numWindows--; } - -}/***StyledEditWindow::SearchAllWindows***/ +} void @@ -1362,28 +1329,29 @@ StyledEditWindow::SetFontSize(float fontSize) { uint32 sameProperties; BFont font; - - fTextView->GetFontAndColor(&font,&sameProperties); + + fTextView->GetFontAndColor(&font, &sameProperties); font.SetSize(fontSize); - fTextView->SetFontAndColor(&font,B_FONT_SIZE); + fTextView->SetFontAndColor(&font, B_FONT_SIZE); fClean = false; fUndoCleans = false; - fRedoCleans = false; + fRedoCleans = false; fRevertItem->SetEnabled(fSaveMessage != NULL); fSaveItem->SetEnabled(true); - fUndoItem->SetLabel("Can't Undo"); + fUndoItem->SetLabel("Can't Undo"); fUndoItem->SetEnabled(false); fCanUndo = false; fCanRedo = false; -}/***StyledEditWindow::SetFontSize()***/ +} + void StyledEditWindow::SetFontColor(const rgb_color *color) { uint32 sameProperties; BFont font; - - fTextView->GetFontAndColor(&font,&sameProperties,NULL,NULL); + + fTextView->GetFontAndColor(&font, &sameProperties, NULL, NULL); fTextView->SetFontAndColor(&font, 0, color); fClean = false; fUndoCleans = false; @@ -1394,37 +1362,36 @@ StyledEditWindow::SetFontColor(const rgb_color *color) fUndoItem->SetEnabled(false); fCanUndo = false; fCanRedo = false; -}/***StyledEditWindow::SetFontColor()***/ +} + void StyledEditWindow::SetFontStyle(const char *fontFamily, const char *fontStyle) { BFont font; uint32 sameProperties; - + // find out what the old font was font_family oldFamily; font_style oldStyle; - fTextView->GetFontAndColor(&font,&sameProperties); - font.GetFamilyAndStyle(&oldFamily,&oldStyle); - + fTextView->GetFontAndColor(&font, &sameProperties); + font.GetFamilyAndStyle(&oldFamily, &oldStyle); + // clear that family's bit on the menu, if necessary - if (strcmp(oldFamily,fontFamily)) { - BMenuItem * oldItem = fFontMenu->FindItem(oldFamily); - if (oldItem != 0) { + if (strcmp(oldFamily, fontFamily)) { + BMenuItem* oldItem = fFontMenu->FindItem(oldFamily); + if (oldItem != NULL) oldItem->SetMarked(false); - } } - - font.SetFamilyAndStyle(fontFamily,fontStyle); + + font.SetFamilyAndStyle(fontFamily, fontStyle); fTextView->SetFontAndColor(&font); - - BMenuItem * superItem; + + BMenuItem* superItem; superItem = fFontMenu->FindItem(fontFamily); - if (superItem != 0) { + if (superItem != NULL) superItem->SetMarked(true); - } - + fClean = false; fUndoCleans = false; fRedoCleans = false; @@ -1434,4 +1401,4 @@ StyledEditWindow::SetFontStyle(const char *fontFamily, const char *fontStyle) fUndoItem->SetEnabled(false); fCanUndo = false; fCanRedo = false; -}/***StyledEditWindow::SetFontStyle()***/ +} diff --git a/src/apps/stylededit/StyledEditWindow.h b/src/apps/stylededit/StyledEditWindow.h index 55a1fdd550..5233434712 100644 --- a/src/apps/stylededit/StyledEditWindow.h +++ b/src/apps/stylededit/StyledEditWindow.h @@ -1,6 +1,15 @@ +/* + * Copyright 2002-2006, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Mattias Sundblad + * Andrew Bachmann + */ #ifndef STYLED_EDIT_WINDOW_H #define STYLED_EDIT_WINDOW_H + #include #include #include @@ -9,97 +18,96 @@ #include #include + class StyledEditView; -class StyledEditWindow - : public BWindow -{ -public: - StyledEditWindow(BRect frame, int32 id, uint32 encoding = 0); - StyledEditWindow(BRect frame, entry_ref *ref, uint32 encoding = 0); - virtual ~StyledEditWindow(); +class StyledEditWindow : public BWindow { + public: + StyledEditWindow(BRect frame, int32 id, uint32 encoding = 0); + StyledEditWindow(BRect frame, entry_ref *ref, uint32 encoding = 0); + virtual ~StyledEditWindow(); - virtual void Quit(); - virtual bool QuitRequested(); - virtual void MessageReceived(BMessage *message); - virtual void MenusBeginning(); - - status_t Save(BMessage *message = 0); - status_t SaveAs(BMessage *message = 0); - void OpenFile(entry_ref *ref); - status_t PageSetup(const char *documentname); - void Print(const char *documentname); - void SearchAllWindows(BString find, BString replace, bool casesens); + virtual void Quit(); + virtual bool QuitRequested(); + virtual void MessageReceived(BMessage *message); + virtual void MenusBeginning(); -private: - void InitWindow(uint32 encoding = 0); - bool Search(BString searchfor, bool casesens, bool wrap, bool backsearch); - void FindSelection(); - bool 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(const rgb_color *color); - void SetFontStyle(const char *fontFamily, const char *fontStyle); - void RevertToSaved(); - - BMenuBar *fMenuBar; - BMessage *fPrintSettings; - BMessage *fSaveMessage; - BMenu *fRecentMenu; - - BMenu *fFontMenu; - BMenu *fFontSizeMenu; - BMenu *fFontColorMenu; - BMenuItem *fCurrentFontItem; - - BMenuItem *fSaveItem; - BMenuItem *fRevertItem; - - BMenuItem *fUndoItem; - BMenuItem *fCutItem; - BMenuItem *fCopyItem; - BMenuItem *fClearItem; - - BMenuItem *fFindAgainItem; - BMenuItem *fReplaceSameItem; - - BMenuItem *fBlackItem; - BMenuItem *fRedItem; - BMenuItem *fGreenItem; - BMenuItem *fBlueItem; - BMenuItem *fCyanItem; - BMenuItem *fMagentaItem; - BMenuItem *fYellowItem; - - BMenuItem *fWrapItem; - BMenuItem *fAlignLeft; - BMenuItem *fAlignCenter; - BMenuItem *fAlignRight; - - BString fStringToFind; - BString fReplaceString; - - // undo modes - bool fUndoFlag; // we just did an undo action - bool fCanUndo; // we can do an undo action next - bool fRedoFlag; // we just did a redo action - bool fCanRedo; // we can do a redo action next - - // clean modes - bool fUndoCleans; // an undo action will put us in a clean state - bool fRedoCleans; // a redo action will put us in a clean state - bool fClean; // we are in a clean state - - bool fCaseSens; - bool fWrapAround; - bool fBackSearch; - - StyledEditView *fTextView; - BScrollView *fScrollView; - - BFilePanel *fSavePanel; - BMenu *fSavePanelEncodingMenu; - + status_t Save(BMessage *message = 0); + status_t SaveAs(BMessage *message = 0); + 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(uint32 encoding = 0); + bool Search(BString searchfor, bool casesens, bool wrap, bool backsearch); + void FindSelection(); + bool 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(const rgb_color *color); + void SetFontStyle(const char *fontFamily, const char *fontStyle); + status_t _LoadFile(entry_ref* ref); + void RevertToSaved(); + + BMenuBar *fMenuBar; + BMessage *fPrintSettings; + BMessage *fSaveMessage; + BMenu *fRecentMenu; + + BMenu *fFontMenu; + BMenu *fFontSizeMenu; + BMenu *fFontColorMenu; + BMenuItem *fCurrentFontItem; + + BMenuItem *fSaveItem; + BMenuItem *fRevertItem; + + BMenuItem *fUndoItem; + BMenuItem *fCutItem; + BMenuItem *fCopyItem; + BMenuItem *fClearItem; + + BMenuItem *fFindAgainItem; + BMenuItem *fReplaceSameItem; + + BMenuItem *fBlackItem; + BMenuItem *fRedItem; + BMenuItem *fGreenItem; + BMenuItem *fBlueItem; + BMenuItem *fCyanItem; + BMenuItem *fMagentaItem; + BMenuItem *fYellowItem; + + BMenuItem *fWrapItem; + BMenuItem *fAlignLeft; + BMenuItem *fAlignCenter; + BMenuItem *fAlignRight; + + BString fStringToFind; + BString fReplaceString; + + // undo modes + bool fUndoFlag; // we just did an undo action + bool fCanUndo; // we can do an undo action next + bool fRedoFlag; // we just did a redo action + bool fCanRedo; // we can do a redo action next + + // clean modes + bool fUndoCleans; // an undo action will put us in a clean state + bool fRedoCleans; // a redo action will put us in a clean state + bool fClean; // we are in a clean state + + bool fCaseSens; + bool fWrapAround; + bool fBackSearch; + + StyledEditView *fTextView; + BScrollView *fScrollView; + + BFilePanel *fSavePanel; + BMenu *fSavePanelEncodingMenu; }; -#endif // STYLED_EDIT_WINDOW_H +#endif // STYLED_EDIT_WINDOW_H