Applied patch from "HOST", with a few small style fixes myself.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22163 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ryan Leavengood 2007-09-04 03:08:40 +00:00
parent af73a9fb93
commit f303cd6cc2
13 changed files with 305 additions and 349 deletions

View File

@ -7,14 +7,14 @@
* Andrew Bachmann
*/
#include "ColorMenuItem.h"
#include <Message.h>
ColorMenuItem::ColorMenuItem(const char *label, rgb_color color, BMessage *message)
: BMenuItem(label, message, 0, 0)
, fItemColor(color)
{
fItemColor = color;
}
@ -22,9 +22,11 @@ void
ColorMenuItem::DrawContent()
{
BMenu *menu = Menu();
if (menu) {
rgb_color menuColor = menu->HighColor();
menu->SetHighColor(fItemColor);
BMenuItem::DrawContent();
menu->SetHighColor(menuColor);
}
}

View File

@ -13,12 +13,13 @@
#include <MenuItem.h>
class BMessage;
class ColorMenuItem: public BMenuItem {
public:
ColorMenuItem(const char *label, rgb_color color, BMessage *message);
protected:
virtual void DrawContent();
void DrawContent();
private:
rgb_color fItemColor;

View File

@ -76,3 +76,4 @@ const uint32 SAVE_AS_ENCODING = 'FPse';
const uint32 SAVE_THEN_QUIT = 'FPsq';
#endif // CONSTANTS_H

View File

@ -18,10 +18,9 @@
FindWindow::FindWindow(BRect frame, BHandler *_handler, BString *searchString,
bool *caseState, bool *wrapState, bool *backState)
bool caseState, bool wrapState, bool backState)
: BWindow(frame, "FindWindow", B_MODAL_WINDOW,
B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS,
B_CURRENT_WORKSPACE)
B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS, B_CURRENT_WORKSPACE)
{
AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
@ -68,9 +67,9 @@ FindWindow::FindWindow(BRect frame, BHandler *_handler, BString *searchString,
fSearchString->SetText(text);
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);
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);
}

View File

@ -12,6 +12,7 @@
#include <Window.h>
class BButton;
class BCheckBox;
class BTextControl;
@ -21,10 +22,10 @@ class BView;
class FindWindow : public BWindow {
public:
FindWindow(BRect frame, BHandler* handler, BString *searchString,
bool *caseState, bool *wrapState, bool *backState);
bool caseState, bool wrapState, bool backState);
virtual void MessageReceived(BMessage* message);
virtual void DispatchMessage(BMessage* message, BHandler* handler);
void MessageReceived(BMessage* message);
void DispatchMessage(BMessage* message, BHandler* handler);
private:
void _SendMessage();
@ -42,8 +43,3 @@ class FindWindow : public BWindow {
#endif // FIND_WINDOW_H

View File

@ -11,19 +11,21 @@
#include "Constants.h"
#include "ReplaceWindow.h"
#include <Messenger.h>
#include <Button.h>
#include <CheckBox.h>
#include <Handler.h>
#include <Message.h>
#include <Messenger.h>
#include <Rect.h>
#include <String.h>
#include <TextControl.h>
#include <Window.h>
#include <View.h>
ReplaceWindow::ReplaceWindow(BRect frame, BHandler *_handler, BString *searchString,
BString *replaceString, bool *caseState, bool *wrapState, bool *backState)
BString *replaceString, bool caseState, bool wrapState, bool backState)
: BWindow(frame, "ReplaceWindow", B_MODAL_WINDOW,
B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS,
B_CURRENT_WORKSPACE)
B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS, B_CURRENT_WORKSPACE)
{
AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
@ -41,7 +43,7 @@ ReplaceWindow::ReplaceWindow(BRect frame, BHandler *_handler, BString *searchStr
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;
float maxWidth = (replaceWithWidth > findWidth ? replaceWithWidth : findWidth) + TEXT_INSET;
fSearchString->SetDivider(maxWidth);
fReplaceString->SetDivider(maxWidth);
@ -78,9 +80,9 @@ ReplaceWindow::ReplaceWindow(BRect frame, BHandler *_handler, BString *searchStr
fReplaceString->SetText(replacetext);
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);
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);
}
@ -108,22 +110,16 @@ ReplaceWindow::MessageReceived(BMessage *msg)
void
ReplaceWindow::_ChangeUI()
{
if (!fUIchange) {
fReplaceAllButton->MakeDefault(true);
fReplaceButton->SetEnabled(false);
fWrapBox->SetValue(B_CONTROL_ON);
fWrapBox->SetEnabled(false);
fBackSearchBox->SetEnabled(false);
fUIchange = true;
} else {
fReplaceButton->MakeDefault(true);
fReplaceButton->SetEnabled(true);
fReplaceAllButton->SetEnabled(true);
fWrapBox->SetValue(B_CONTROL_OFF);
fWrapBox->SetEnabled(true);
fBackSearchBox->SetEnabled(true);
fUIchange = false;
}
fWrapBox->SetEnabled(fUIchange);
fWrapBox->SetValue(fUIchange ? B_CONTROL_OFF : B_CONTROL_ON);
fBackSearchBox->SetEnabled(fUIchange);
fReplaceButton->SetEnabled(fUIchange);
fUIchange ? fReplaceButton->MakeDefault(true)
: fReplaceAllButton->MakeDefault(true);
fUIchange = !fUIchange;
}

View File

@ -11,23 +11,25 @@
#include <Window.h>
#include <Rect.h>
#include <Handler.h>
#include <String.h>
#include <Message.h>
#include <View.h>
#include <TextControl.h>
#include <CheckBox.h>
#include <Button.h>
class BView;
class BString;
class BButton;
class BHandler;
class BMessage;
class BCheckBox;
class BTextControl;
class ReplaceWindow : public BWindow {
public:
ReplaceWindow(BRect frame, BHandler *_handler,BString *searchString,
BString *replaceString, bool *caseState, bool *wrapState, bool *backState);
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);
void MessageReceived(BMessage* message);
void DispatchMessage(BMessage* message, BHandler *handler);
private:
void _SendMessage(uint32 what);
@ -48,3 +50,4 @@ class ReplaceWindow : public BWindow {
};
#endif // REPLACE_WINDOW_H

View File

@ -8,25 +8,33 @@
*/
#include <Alert.h>
#include <Autolock.h>
#include <Path.h>
#include <MenuItem.h>
#include <CharacterSet.h>
#include <CharacterSetRoster.h>
#include <Screen.h>
#include <stdio.h>
#include "Constants.h"
#include "StyledEditApp.h"
#include "StyledEditWindow.h"
#include <Alert.h>
#include <Autolock.h>
#include <MenuBar.h>
#include <CharacterSet.h>
#include <CharacterSetRoster.h>
#include <FilePanel.h>
#include <MenuItem.h>
#include <Message.h>
#include <Path.h>
#include <Screen.h>
#include <stdio.h>
using namespace BPrivate;
StyledEditApp * styled_edit_app;
BRect gWindowRect(7-15, 26-15, 507, 426);
namespace
{
void
cascade()
{
@ -64,6 +72,7 @@ uncascade()
gWindowRect.OffsetTo(BPoint(left,top));
}
}
// #pragma mark -
@ -71,6 +80,7 @@ uncascade()
StyledEditApp::StyledEditApp()
: BApplication(APP_SIGNATURE)
, fOpenPanel(NULL)
{
fOpenPanel = new BFilePanel();
BMenuBar *menuBar =
@ -110,6 +120,12 @@ StyledEditApp::StyledEditApp()
}
StyledEditApp::~StyledEditApp()
{
delete fOpenPanel;
}
void
StyledEditApp::DispatchMessage(BMessage *msg, BHandler *handler)
{
@ -128,7 +144,7 @@ StyledEditApp::DispatchMessage(BMessage *msg, BHandler *handler)
if (msg->FindString("cwd", &cwd) != B_OK)
cwd = "";
ArgvReceived(argc, argv, cwd);
ArgvReceivedEx(argc, argv, cwd);
} else
BApplication::DispatchMessage(msg, handler);
}
@ -205,7 +221,7 @@ StyledEditApp::RefsReceived(BMessage *message)
void
StyledEditApp::ArgvReceived(int32 argc, const char* argv[], const char* cwd)
StyledEditApp::ArgvReceivedEx(int32 argc, const char* argv[], const char* cwd)
{
for (int i = 1 ; (i < argc) ; i++) {
BPath path;

View File

@ -11,27 +11,36 @@
#include <Application.h>
#include <Message.h>
#include <FilePanel.h>
struct entry_ref;
class BMenu;
class BHandler;
class BMessage;
class BFilePanel;
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();
~StyledEditApp();
virtual void DispatchMessage(BMessage *an_event, BHandler *handler);
void MessageReceived(BMessage *message);
void RefsReceived(BMessage *message);
void ReadyToRun();
void DispatchMessage(BMessage *an_event, BHandler *handler);
int32 NumberOfWindows();
void OpenDocument();
void OpenDocument(entry_ref * ref);
void CloseDocument();
private:
void ArgvReceivedEx(int32 argc, const char *argv[], const char * cwd);
private:
BFilePanel *fOpenPanel;
BMenu *fOpenPanelEncodingMenu;
@ -44,3 +53,4 @@ class StyledEditApp : public BApplication {
extern StyledEditApp* styled_edit_app;
#endif // STYLED_EDIT_APP

View File

@ -12,18 +12,20 @@
#include "Constants.h"
#include "StyledEditView.h"
#include <Message.h>
#include <Messenger.h>
#include <Rect.h>
#include <Region.h>
#include <TranslationUtils.h>
#include <Node.h>
#include <stdio.h>
#include <stdlib.h>
#include <CharacterSet.h>
#include <CharacterSetRoster.h>
#include <DataIO.h>
#include <File.h>
#include <Message.h>
#include <Messenger.h>
#include <Node.h>
#include <Rect.h>
#include <TranslationUtils.h>
#include <UTF8.h>
#include <stdio.h>
#include <stdlib.h>
using namespace BPrivate;
@ -32,7 +34,6 @@ StyledEditView::StyledEditView(BRect viewFrame, BRect textBounds, BHandler *hand
: BTextView(viewFrame, "textview", textBounds,
B_FOLLOW_ALL, B_FRAME_EVENTS | B_WILL_DRAW)
{
fHandler = handler;
fMessenger = new BMessenger(handler);
fSuppressChanges = false;
}
@ -45,34 +46,21 @@ StyledEditView::~StyledEditView()
void
StyledEditView::FrameResized(float width, float height)
StyledEditView::Select(int32 start, int32 finish)
{
BTextView::FrameResized(width, height);
fMessenger->SendMessage(start == finish ? DISABLE_ITEMS : ENABLE_ITEMS);
if (DoesWordWrap()) {
BRect textRect;
textRect = Bounds();
textRect.OffsetTo(B_ORIGIN);
textRect.InsetBy(TEXT_INSET, TEXT_INSET);
SetTextRect(textRect);
BTextView::Select(start, finish);
}
/* // 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 :-(
else if (textRect.Width() > TextRect().Width()) {
SetTextRect(textRect);
}
BRegion region;
GetTextRegion(0,TextLength(),&region);
float textWidth = region.Frame().Width();
if (textWidth < textRect.Width()) {
BRect textRect(B_ORIGIN,BPoint(textWidth+TEXT_INSET*2,Bounds().Height()));
textRect.InsetBy(TEXT_INSET,TEXT_INSET);
SetTextRect(textRect);
}
*/
void
StyledEditView::Reset()
{
fSuppressChanges = true;
SetText("");
fEncoding = "";
fSuppressChanges = false;
}
@ -144,39 +132,18 @@ StyledEditView::WriteStyledEditFile(BFile* file)
}
void
StyledEditView::Reset()
{
fSuppressChanges = true;
SetText("");
fEncoding = "";
fSuppressChanges = false;
}
void
StyledEditView::Select(int32 start, int32 finish)
{
fChangeMessage = new BMessage(start == finish ? DISABLE_ITEMS : ENABLE_ITEMS);
fMessenger->SendMessage(fChangeMessage);
BTextView::Select(start, finish);
}
void
StyledEditView::SetEncoding(uint32 encoding)
{
if (encoding == 0) {
fEncoding = "";
if (encoding == 0)
return;
}
const BCharacterSet* set = BCharacterSetRoster::GetCharacterSetByFontID(encoding);
const BCharacterSet* set
= BCharacterSetRoster::GetCharacterSetByFontID(encoding);
if (set != NULL)
fEncoding = set->GetName();
else
fEncoding = "";
}
@ -186,7 +153,8 @@ StyledEditView::GetEncoding() const
if (fEncoding == "")
return 0;
const BCharacterSet* set = BCharacterSetRoster::FindCharacterSetByName(fEncoding.String());
const BCharacterSet* set =
BCharacterSetRoster::FindCharacterSetByName(fEncoding.String());
if(set != NULL)
return set->GetFontID();
@ -194,23 +162,38 @@ StyledEditView::GetEncoding() const
}
void
StyledEditView::DeleteText(int32 start, int32 finish)
{
if (!fSuppressChanges)
fMessenger-> SendMessage(TEXT_CHANGED);
BTextView::DeleteText(start, finish);
}
void
StyledEditView::InsertText(const char *text, int32 length, int32 offset,
const text_run_array *runs)
{
if (!fSuppressChanges)
fMessenger->SendMessage(new BMessage(TEXT_CHANGED));
fMessenger->SendMessage(TEXT_CHANGED);
BTextView::InsertText(text, length, offset, runs);
}
void
StyledEditView::DeleteText(int32 start, int32 finish)
StyledEditView::FrameResized(float width, float height)
{
if (!fSuppressChanges)
fMessenger-> SendMessage(new BMessage(TEXT_CHANGED));
BTextView::FrameResized(width, height);
BTextView::DeleteText(start, finish);
if (DoesWordWrap()) {
BRect textRect;
textRect = Bounds();
textRect.OffsetTo(B_ORIGIN);
textRect.InsetBy(TEXT_INSET, TEXT_INSET);
SetTextRect(textRect);
}
}

View File

@ -11,37 +11,40 @@
#define STYLED_EDIT_VIEW_H
#include <File.h>
#include <DataIO.h>
#include <String.h>
#include <TextView.h>
class BFile;
class BHandler;
class BMessanger;
class StyledEditView : public BTextView {
public:
StyledEditView(BRect viewframe, BRect textframe, BHandler *handler);
virtual ~StyledEditView();
StyledEditView(BRect viewframe, BRect textframe,
BHandler *handler);
~StyledEditView();
virtual void Select(int32 start, int32 finish);
virtual void FrameResized(float width, float height);
void Select(int32 start, int32 finish);
virtual void Reset();
virtual status_t GetStyledText(BPositionIO * stream);
virtual status_t WriteStyledEditFile(BFile * file);
void Reset();
status_t GetStyledText(BPositionIO * stream);
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);
void SetEncoding(uint32 encoding);
uint32 GetEncoding() const;
private:
BHandler *fHandler;
BMessage *fChangeMessage;
void DeleteText(int32 start, int32 finish);
void FrameResized(float width, float height);
void InsertText(const char *text, int32 length, int32 offset,
const text_run_array *runs = NULL);
BMessenger *fMessenger;
bool fSuppressChanges;
BString fEncoding;
};
#endif // STYLED_EDIT_VIEW_H

View File

@ -18,24 +18,26 @@
#include <Alert.h>
#include <Autolock.h>
#include <Debug.h>
#include <Clipboard.h>
#include <File.h>
#include <Menu.h>
#include <MenuItem.h>
#include <PrintJob.h>
#include <Roster.h>
#include <ScrollView.h>
#include <String.h>
#include <TextControl.h>
#include <TranslationUtils.h>
#include <Window.h>
#include <CharacterSet.h>
#include <CharacterSetRoster.h>
#include <Clipboard.h>
#include <Debug.h>
#include <File.h>
#include <FilePanel.h>
#include <Menu.h>
#include <MenuBar.h>
#include <MenuItem.h>
#include <PrintJob.h>
#include <Rect.h>
#include <ScrollView.h>
#include <TextControl.h>
#include <TextView.h>
#include <TranslationUtils.h>
#include <Roster.h>
#include <stdlib.h>
using namespace BPrivate;
@ -43,8 +45,7 @@ StyledEditWindow::StyledEditWindow(BRect frame, int32 id, uint32 encoding)
: BWindow(frame, "untitled", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS)
{
InitWindow(encoding);
BString unTitled;
unTitled.SetTo("Untitled ");
BString unTitled("Untitled ");
unTitled << id;
SetTitle(unTitled.String());
fSaveItem->SetEnabled(true);
@ -365,7 +366,7 @@ StyledEditWindow::MessageReceived(BMessage *message)
{
BRect findWindowFrame(100, 100, 400, 235);
BWindow* window = new FindWindow(findWindowFrame, this,
&fStringToFind, &fCaseSens, &fWrapAround, &fBackSearch);
&fStringToFind, fCaseSens, fWrapAround, fBackSearch);
window->Show();
break;
}
@ -388,31 +389,23 @@ StyledEditWindow::MessageReceived(BMessage *message)
{
BRect replaceWindowFrame(100, 100, 400, 284);
BWindow* window = new ReplaceWindow(replaceWindowFrame, this,
&fStringToFind, &fReplaceString, &fCaseSens, &fWrapAround, &fBackSearch);
&fStringToFind, &fReplaceString, fCaseSens, fWrapAround, fBackSearch);
window->Show();
break;
}
case MSG_REPLACE:
{
BString findIt;
BString replaceWith;
bool caseSens, wrap, backSearch;
message->FindBool("casesens", &fCaseSens);
message->FindBool("wrap", &fWrapAround);
message->FindBool("backsearch", &fBackSearch);
message->FindBool("casesens", &caseSens);
message->FindBool("wrap", &wrap);
message->FindBool("backsearch", &backSearch);
message->FindString("FindText", &fStringToFind);
message->FindString("ReplaceText", &fReplaceString);
message->FindString("FindText", &findIt);
message->FindString("ReplaceText", &replaceWith);
fStringToFind = findIt;
fFindAgainItem->SetEnabled(true);
fReplaceString = replaceWith;
fReplaceSameItem->SetEnabled(true);
fCaseSens = caseSens;
fWrapAround = wrap;
fBackSearch = backSearch;
Replace(findIt, replaceWith, caseSens, wrap, backSearch);
Replace(fStringToFind, fReplaceString, fCaseSens, fWrapAround, fBackSearch);
break;
}
case MENU_REPLACE_SAME:
@ -421,25 +414,20 @@ StyledEditWindow::MessageReceived(BMessage *message)
case MSG_REPLACE_ALL:
{
BString findIt;
BString replaceWith;
bool caseSens, allWindows;
message->FindBool("casesens", &fCaseSens);
message->FindString("FindText",&fStringToFind);
message->FindString("ReplaceText",&fReplaceString);
message->FindBool("casesens", &caseSens);
message->FindString("FindText",&findIt);
message->FindString("ReplaceText",&replaceWith);
bool allWindows;
message->FindBool("allwindows", &allWindows);
fStringToFind = findIt;
fFindAgainItem->SetEnabled(true);
fReplaceString = replaceWith;
fReplaceSameItem->SetEnabled(true);
fCaseSens = caseSens;
if (allWindows)
SearchAllWindows(findIt, replaceWith, caseSens);
SearchAllWindows(fStringToFind, fReplaceString, fCaseSens);
else
ReplaceAll(findIt, replaceWith,caseSens);
ReplaceAll(fStringToFind, fReplaceString, fCaseSens);
break;
}
@ -508,70 +496,35 @@ StyledEditWindow::MessageReceived(BMessage *message)
case ALIGN_LEFT:
fTextView->SetAlignment(B_ALIGN_LEFT);
fClean = false;
fUndoCleans = false;
fRedoCleans = false;
fRevertItem->SetEnabled(fSaveMessage != NULL);
fSaveItem->SetEnabled(true);
fUndoItem->SetLabel("Can't Undo");
fUndoItem->SetEnabled(false);
fCanUndo = false;
fCanRedo = false;
_UpdateCleanUndoRedoSaveRevert();
break;
case ALIGN_CENTER:
fTextView->SetAlignment(B_ALIGN_CENTER);
fClean = false;
fUndoCleans = false;
fRedoCleans = false;
fRevertItem->SetEnabled(fSaveMessage != NULL);
fSaveItem->SetEnabled(true);
fUndoItem->SetLabel("Can't Undo");
fUndoItem->SetEnabled(false);
fCanUndo = false;
fCanRedo = false;
_UpdateCleanUndoRedoSaveRevert();
break;
case ALIGN_RIGHT:
fTextView->SetAlignment(B_ALIGN_RIGHT);
fClean = false;
fUndoCleans = false;
fRedoCleans = false;
fRevertItem->SetEnabled(fSaveMessage != NULL);
fSaveItem->SetEnabled(true);
fUndoItem->SetLabel("Can't Undo");
fUndoItem->SetEnabled(false);
fCanUndo = false;
fCanRedo = false;
_UpdateCleanUndoRedoSaveRevert();
break;
case WRAP_LINES:
{
BRect textRect(fTextView->Bounds());
textRect.OffsetTo(B_ORIGIN);
textRect.InsetBy(TEXT_INSET,TEXT_INSET);
if (fTextView->DoesWordWrap()) {
fTextView->SetWordWrap(false);
fWrapItem->SetMarked(false);
BRect textRect;
textRect = fTextView->Bounds();
textRect.OffsetTo(B_ORIGIN);
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));
fTextView->SetTextRect(textRect);
} else {
fTextView->SetWordWrap(true);
fWrapItem->SetMarked(true);
BRect textRect;
textRect = fTextView->Bounds();
textRect.OffsetTo(B_ORIGIN);
textRect.InsetBy(TEXT_INSET,TEXT_INSET);
fTextView->SetTextRect(textRect);
}
fClean = false;
fUndoCleans = false;
fRedoCleans = false;
fRevertItem->SetEnabled(fSaveMessage != NULL);
fSaveItem->SetEnabled(true);
fUndoItem->SetLabel("Can't Undo");
fUndoItem->SetEnabled(false);
fCanUndo = false;
fCanRedo = false;
fTextView->SetTextRect(textRect);
_UpdateCleanUndoRedoSaveRevert();
break;
}
case ENABLE_ITEMS:
fCutItem->SetEnabled(true);
fCopyItem->SetEnabled(true);
@ -1303,15 +1256,7 @@ StyledEditWindow::ReplaceAll(BString findIt, BString replaceWith, bool caseSensi
fTextView->Select(textStart,textFinish);
fTextView->ScrollToSelection();
fClean = false;
fUndoCleans = false;
fRedoCleans = false;
fRevertItem->SetEnabled(fSaveMessage != NULL);
fSaveItem->SetEnabled(true);
fUndoItem->SetLabel("Can't Undo");
fUndoItem->SetEnabled(false);
fCanUndo = false;
fCanRedo = false;
_UpdateCleanUndoRedoSaveRevert();
}
@ -1348,15 +1293,8 @@ StyledEditWindow::SetFontSize(float fontSize)
fTextView->GetFontAndColor(&font, &sameProperties);
font.SetSize(fontSize);
fTextView->SetFontAndColor(&font, B_FONT_SIZE);
fClean = false;
fUndoCleans = false;
fRedoCleans = false;
fRevertItem->SetEnabled(fSaveMessage != NULL);
fSaveItem->SetEnabled(true);
fUndoItem->SetLabel("Can't Undo");
fUndoItem->SetEnabled(false);
fCanUndo = false;
fCanRedo = false;
_UpdateCleanUndoRedoSaveRevert();
}
@ -1368,15 +1306,8 @@ StyledEditWindow::SetFontColor(const rgb_color *color)
fTextView->GetFontAndColor(&font, &sameProperties, NULL, NULL);
fTextView->SetFontAndColor(&font, 0, color);
fClean = false;
fUndoCleans = false;
fRedoCleans = false;
fRevertItem->SetEnabled(fSaveMessage != NULL);
fSaveItem->SetEnabled(true);
fUndoItem->SetLabel("Can't Undo");
fUndoItem->SetEnabled(false);
fCanUndo = false;
fCanRedo = false;
_UpdateCleanUndoRedoSaveRevert();
}
@ -1407,6 +1338,12 @@ StyledEditWindow::SetFontStyle(const char *fontFamily, const char *fontStyle)
if (superItem != NULL)
superItem->SetMarked(true);
_UpdateCleanUndoRedoSaveRevert();
}
void
StyledEditWindow::_UpdateCleanUndoRedoSaveRevert()
{
fClean = false;
fUndoCleans = false;
fRedoCleans = false;
@ -1417,3 +1354,4 @@ StyledEditWindow::SetFontStyle(const char *fontFamily, const char *fontStyle)
fCanUndo = false;
fCanRedo = false;
}

View File

@ -10,27 +10,32 @@
#define STYLED_EDIT_WINDOW_H
#include <FilePanel.h>
#include <MenuBar.h>
#include <Message.h>
#include <Rect.h>
#include <String.h>
#include <TextView.h>
#include <Window.h>
#include <String.h>
#include <Message.h>
struct entry_ref;
class BMenu;
class BMessage;
class BMenuBar;
class BMenuItem;
class BFilePanel;
class BScrollView;
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();
~StyledEditWindow();
virtual void Quit();
virtual bool QuitRequested();
virtual void MessageReceived(BMessage *message);
virtual void MenusBeginning();
void Quit();
bool QuitRequested();
void MessageReceived(BMessage *message);
void MenusBeginning();
status_t Save(BMessage *message = 0);
status_t SaveAs(BMessage *message = 0);
@ -43,13 +48,15 @@ class StyledEditWindow : public BWindow {
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);
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();
void _UpdateCleanUndoRedoSaveRevert();
BMenuBar *fMenuBar;
BMessage *fPrintSettings;
@ -111,3 +118,4 @@ class StyledEditWindow : public BWindow {
};
#endif // STYLED_EDIT_WINDOW_H