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:
parent
af73a9fb93
commit
f303cd6cc2
@ -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();
|
||||
rgb_color menuColor = menu->HighColor();
|
||||
if (menu) {
|
||||
rgb_color menuColor = menu->HighColor();
|
||||
|
||||
menu->SetHighColor(fItemColor);
|
||||
BMenuItem::DrawContent();
|
||||
menu->SetHighColor(menuColor);
|
||||
menu->SetHighColor(fItemColor);
|
||||
BMenuItem::DrawContent();
|
||||
menu->SetHighColor(menuColor);
|
||||
}
|
||||
}
|
||||
|
@ -13,15 +13,16 @@
|
||||
#include <MenuItem.h>
|
||||
|
||||
|
||||
class BMessage;
|
||||
|
||||
|
||||
class ColorMenuItem: public BMenuItem {
|
||||
public:
|
||||
ColorMenuItem(const char *label, rgb_color color, BMessage *message);
|
||||
|
||||
protected:
|
||||
virtual void DrawContent();
|
||||
ColorMenuItem(const char *label, rgb_color color, BMessage *message);
|
||||
void DrawContent();
|
||||
|
||||
private:
|
||||
rgb_color fItemColor;
|
||||
rgb_color fItemColor;
|
||||
};
|
||||
|
||||
#endif // COLOR_MENU_ITEM_H
|
||||
|
@ -76,3 +76,4 @@ const uint32 SAVE_AS_ENCODING = 'FPse';
|
||||
const uint32 SAVE_THEN_QUIT = 'FPsq';
|
||||
|
||||
#endif // CONSTANTS_H
|
||||
|
||||
|
@ -18,12 +18,11 @@
|
||||
|
||||
|
||||
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));
|
||||
AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
|
||||
|
||||
fFindView = new BView(Bounds(), "FindView", B_FOLLOW_ALL, B_WILL_DRAW);
|
||||
fFindView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
@ -31,7 +30,7 @@ FindWindow::FindWindow(BRect frame, BHandler *_handler, BString *searchString,
|
||||
|
||||
font_height height;
|
||||
fFindView->GetFontHeight(&height);
|
||||
float lineHeight = height.ascent+height.descent + height.leading;
|
||||
float lineHeight = height.ascent + height.descent + height.leading;
|
||||
|
||||
float findWidth = fFindView->StringWidth("Find:") + 6;
|
||||
|
||||
@ -65,12 +64,12 @@ FindWindow::FindWindow(BRect frame, BHandler *_handler, BString *searchString,
|
||||
|
||||
const char *text = searchString->String();
|
||||
|
||||
fSearchString->SetText(text);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include <Window.h>
|
||||
|
||||
|
||||
class BButton;
|
||||
class BCheckBox;
|
||||
class BTextControl;
|
||||
@ -20,14 +21,14 @@ class BView;
|
||||
|
||||
class FindWindow : public BWindow {
|
||||
public:
|
||||
FindWindow(BRect frame, BHandler* handler, BString *searchString,
|
||||
bool *caseState, bool *wrapState, bool *backState);
|
||||
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);
|
||||
void MessageReceived(BMessage* message);
|
||||
void DispatchMessage(BMessage* message, BHandler* handler);
|
||||
|
||||
private:
|
||||
void _SendMessage();
|
||||
void _SendMessage();
|
||||
|
||||
BView *fFindView;
|
||||
BTextControl *fSearchString;
|
||||
@ -42,8 +43,3 @@ class FindWindow : public BWindow {
|
||||
|
||||
#endif // FIND_WINDOW_H
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -11,21 +11,23 @@
|
||||
#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));
|
||||
AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
|
||||
|
||||
fReplaceView = new BView(Bounds(), "ReplaceView", B_FOLLOW_ALL, B_WILL_DRAW);
|
||||
fReplaceView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
@ -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,16 +80,16 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ReplaceWindow::MessageReceived(BMessage *msg)
|
||||
{
|
||||
switch (msg->what){
|
||||
switch (msg->what) {
|
||||
case MSG_REPLACE:
|
||||
_SendMessage(MSG_REPLACE);
|
||||
break;
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,27 +11,29 @@
|
||||
|
||||
|
||||
#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);
|
||||
void _ChangeUI();
|
||||
void _SendMessage(uint32 what);
|
||||
void _ChangeUI();
|
||||
|
||||
BView *fReplaceView;
|
||||
BTextControl *fSearchString;
|
||||
@ -48,3 +50,4 @@ class ReplaceWindow : public BWindow {
|
||||
};
|
||||
|
||||
#endif // REPLACE_WINDOW_H
|
||||
|
||||
|
@ -8,61 +8,70 @@
|
||||
*/
|
||||
|
||||
|
||||
#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);
|
||||
|
||||
|
||||
void
|
||||
cascade()
|
||||
namespace
|
||||
{
|
||||
BScreen screen(NULL);
|
||||
BRect screenBorder = screen.Frame();
|
||||
float left = gWindowRect.left + 15;
|
||||
if (left + gWindowRect.Width() > screenBorder.right)
|
||||
left = 7;
|
||||
void
|
||||
cascade()
|
||||
{
|
||||
BScreen screen(NULL);
|
||||
BRect screenBorder = screen.Frame();
|
||||
float left = gWindowRect.left + 15;
|
||||
if (left + gWindowRect.Width() > screenBorder.right)
|
||||
left = 7;
|
||||
|
||||
float top = gWindowRect.top + 15;
|
||||
if (top + gWindowRect.Height() > screenBorder.bottom)
|
||||
top = 26;
|
||||
float top = gWindowRect.top + 15;
|
||||
if (top + gWindowRect.Height() > screenBorder.bottom)
|
||||
top = 26;
|
||||
|
||||
gWindowRect.OffsetTo(BPoint(left,top));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
uncascade()
|
||||
{
|
||||
BScreen screen(NULL);
|
||||
BRect screenBorder = screen.Frame();
|
||||
|
||||
float left = gWindowRect.left - 15;
|
||||
if (left < 7) {
|
||||
left = screenBorder.right - gWindowRect.Width() - 7;
|
||||
left = left - ((int)left % 15) + 7;
|
||||
gWindowRect.OffsetTo(BPoint(left,top));
|
||||
}
|
||||
|
||||
float top = gWindowRect.top - 15;
|
||||
if (top < 26) {
|
||||
top = screenBorder.bottom - gWindowRect.Height() - 26;
|
||||
top = top - ((int)left % 15) + 26;
|
||||
}
|
||||
|
||||
gWindowRect.OffsetTo(BPoint(left,top));
|
||||
void
|
||||
uncascade()
|
||||
{
|
||||
BScreen screen(NULL);
|
||||
BRect screenBorder = screen.Frame();
|
||||
|
||||
float left = gWindowRect.left - 15;
|
||||
if (left < 7) {
|
||||
left = screenBorder.right - gWindowRect.Width() - 7;
|
||||
left = left - ((int)left % 15) + 7;
|
||||
}
|
||||
|
||||
float top = gWindowRect.top - 15;
|
||||
if (top < 26) {
|
||||
top = screenBorder.bottom - gWindowRect.Height() - 26;
|
||||
top = top - ((int)left % 15) + 26;
|
||||
}
|
||||
|
||||
gWindowRect.OffsetTo(BPoint(left,top));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -71,9 +80,10 @@ uncascade()
|
||||
|
||||
StyledEditApp::StyledEditApp()
|
||||
: BApplication(APP_SIGNATURE)
|
||||
, fOpenPanel(NULL)
|
||||
{
|
||||
fOpenPanel= new BFilePanel();
|
||||
BMenuBar * menuBar =
|
||||
fOpenPanel = new BFilePanel();
|
||||
BMenuBar *menuBar =
|
||||
dynamic_cast<BMenuBar*>(fOpenPanel->Window()->FindView("MenuBar"));
|
||||
|
||||
fOpenAsEncoding = 0;
|
||||
@ -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;
|
||||
|
@ -11,36 +11,46 @@
|
||||
|
||||
|
||||
#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();
|
||||
~StyledEditApp();
|
||||
|
||||
virtual void DispatchMessage(BMessage *an_event, BHandler *handler);
|
||||
void MessageReceived(BMessage *message);
|
||||
void RefsReceived(BMessage *message);
|
||||
void ReadyToRun();
|
||||
|
||||
int32 NumberOfWindows();
|
||||
void OpenDocument();
|
||||
void OpenDocument(entry_ref * ref);
|
||||
void CloseDocument();
|
||||
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 fNextUntitledWindow;
|
||||
void ArgvReceivedEx(int32 argc, const char *argv[], const char * cwd);
|
||||
|
||||
private:
|
||||
BFilePanel *fOpenPanel;
|
||||
BMenu *fOpenPanelEncodingMenu;
|
||||
uint32 fOpenAsEncoding;
|
||||
int32 fWindowCount;
|
||||
int32 fNextUntitledWindow;
|
||||
|
||||
};
|
||||
|
||||
extern StyledEditApp* styled_edit_app;
|
||||
|
||||
#endif // STYLED_EDIT_APP
|
||||
|
||||
|
@ -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,35 +46,22 @@ 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(),®ion);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
@ -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 = "";
|
||||
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,31 +153,47 @@ StyledEditView::GetEncoding() const
|
||||
if (fEncoding == "")
|
||||
return 0;
|
||||
|
||||
const BCharacterSet* set = BCharacterSetRoster::FindCharacterSetByName(fEncoding.String());
|
||||
if (set != NULL)
|
||||
const BCharacterSet* set =
|
||||
BCharacterSetRoster::FindCharacterSetByName(fEncoding.String());
|
||||
if(set != NULL)
|
||||
return set->GetFontID();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
void SetEncoding(uint32 encoding);
|
||||
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;
|
||||
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
|
||||
|
||||
|
@ -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,58 +389,45 @@ 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:
|
||||
Replace(fStringToFind,fReplaceString,fCaseSens,fWrapAround,fBackSearch);
|
||||
Replace(fStringToFind, fReplaceString, fCaseSens, fWrapAround, fBackSearch);
|
||||
break;
|
||||
|
||||
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);
|
||||
textRect.SetRightBottom(BPoint(1500.0, textRect.RightBottom().y));
|
||||
} 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;
|
||||
}
|
||||
|
||||
|
@ -10,29 +10,34 @@
|
||||
#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 Save(BMessage *message = 0);
|
||||
status_t SaveAs(BMessage *message = 0);
|
||||
void OpenFile(entry_ref *ref);
|
||||
status_t PageSetup(const char *documentname);
|
||||
@ -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;
|
||||
@ -85,7 +92,7 @@ class StyledEditWindow : public BWindow {
|
||||
BMenuItem *fAlignCenter;
|
||||
BMenuItem *fAlignRight;
|
||||
|
||||
BString fStringToFind;
|
||||
BString fStringToFind;
|
||||
BString fReplaceString;
|
||||
|
||||
// undo modes
|
||||
@ -103,7 +110,7 @@ class StyledEditWindow : public BWindow {
|
||||
bool fWrapAround;
|
||||
bool fBackSearch;
|
||||
|
||||
StyledEditView *fTextView;
|
||||
StyledEditView *fTextView;
|
||||
BScrollView *fScrollView;
|
||||
|
||||
BFilePanel *fSavePanel;
|
||||
@ -111,3 +118,4 @@ class StyledEditWindow : public BWindow {
|
||||
};
|
||||
|
||||
#endif // STYLED_EDIT_WINDOW_H
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user