* Fixed some minor bugs and oddities, improved error messages.

* Big-time cleanup, added license.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16696 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-03-11 00:13:18 +00:00
parent 6d24fdc557
commit 31139022cd
13 changed files with 1361 additions and 1316 deletions
+16 -7
View File
@@ -1,20 +1,29 @@
#ifndef _MENU_ITEM_H /*
#include <MenuItem.h> * Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
#endif * Distributed under the terms of the MIT License.
*
* Authors:
* Mattias Sundblad
* Andrew Bachmann
*/
#ifndef COLOR_MENU_ITEM_H
#include "ColorMenuItem.h" #include "ColorMenuItem.h"
#endif
ColorMenuItem::ColorMenuItem(const char *label, rgb_color color, BMessage *message) ColorMenuItem::ColorMenuItem(const char *label, rgb_color color, BMessage *message)
:BMenuItem(label, message,0,0){ : BMenuItem(label, message, 0, 0)
{
fItemColor = color; fItemColor = color;
} }
void ColorMenuItem::DrawContent(){
void
ColorMenuItem::DrawContent()
{
BMenu *menu = Menu(); BMenu *menu = Menu();
rgb_color menuColor = menu->HighColor(); rgb_color menuColor = menu->HighColor();
menu->SetHighColor(fItemColor); menu->SetHighColor(fItemColor);
BMenuItem::DrawContent(); BMenuItem::DrawContent();
menu->SetHighColor(menuColor); menu->SetHighColor(menuColor);
+16 -2
View File
@@ -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 #ifndef COLOR_MENU_ITEM_H
#define COLOR_MENU_ITEM_H #define COLOR_MENU_ITEM_H
#include <MenuItem.h>
class ColorMenuItem: public BMenuItem { class ColorMenuItem: public BMenuItem {
public: public:
ColorMenuItem(const char *label, rgb_color color, BMessage *message); ColorMenuItem(const char *label, rgb_color color, BMessage *message);
protected: protected:
virtual void DrawContent(); virtual void DrawContent();
private: private:
rgb_color fItemColor; rgb_color fItemColor;
}; };
#endif
#endif // COLOR_MENU_ITEM_H
+15 -4
View File
@@ -1,16 +1,26 @@
/*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 #ifndef CONSTANTS_H
#define CONSTANTS_H #define CONSTANTS_H
#include <GraphicsDefs.h> #include <GraphicsDefs.h>
#include <SupportDefs.h> #include <SupportDefs.h>
#define APP_SIGNATURE "application/x-vnd.obos.styled-edit" #define APP_SIGNATURE "application/x-vnd.obos.styled-edit"
const float TEXT_INSET = 3.0; const float TEXT_INSET = 3.0;
/*Messages for menu commands // Messages for menu commands
file menu*/
// file menu
const uint32 MENU_NEW = 'MFnw'; const uint32 MENU_NEW = 'MFnw';
const uint32 MENU_OPEN = 'MFop'; const uint32 MENU_OPEN = 'MFop';
const uint32 MENU_SAVE = 'MSav'; const uint32 MENU_SAVE = 'MSav';
@@ -20,6 +30,7 @@ const uint32 MENU_CLOSE ='MFcl';
const uint32 MENU_PAGESETUP = 'MFps'; const uint32 MENU_PAGESETUP = 'MFps';
const uint32 MENU_PRINT = 'MFpr'; const uint32 MENU_PRINT = 'MFpr';
const uint32 MENU_QUIT = 'MFqu'; const uint32 MENU_QUIT = 'MFqu';
// edit menu // edit menu
const uint32 MENU_CLEAR = 'MEcl'; const uint32 MENU_CLEAR = 'MEcl';
const uint32 MENU_FIND = 'MEfi'; const uint32 MENU_FIND = 'MEfi';
@@ -31,6 +42,7 @@ const uint32 MENU_REPLACE_SAME ='MErs';
const uint32 MSG_SEARCH = 'msea'; const uint32 MSG_SEARCH = 'msea';
const uint32 MSG_REPLACE = 'msre'; const uint32 MSG_REPLACE = 'msre';
const uint32 MSG_REPLACE_ALL = 'mrea'; const uint32 MSG_REPLACE_ALL = 'mrea';
// "Font"-menu // "Font"-menu
const uint32 FONT_SIZE = 'FMsi'; const uint32 FONT_SIZE = 'FMsi';
const uint32 FONT_FAMILY = 'FFch'; const uint32 FONT_FAMILY = 'FFch';
@@ -38,7 +50,6 @@ const uint32 FONT_STYLE ='FSch';
const uint32 FONT_COLOR = 'Fcol'; const uint32 FONT_COLOR = 'Fcol';
// fontcolors // fontcolors
//red, green, blue, alphachannel
const rgb_color BLACK = {0, 0, 0, 255}; const rgb_color BLACK = {0, 0, 0, 255};
const rgb_color RED = {255, 0, 0, 255}; const rgb_color RED = {255, 0, 0, 255};
const rgb_color GREEN = {0, 255, 0, 255}; const rgb_color GREEN = {0, 255, 0, 255};
+51 -71
View File
@@ -1,21 +1,29 @@
/*
* 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 <Button.h> #include <Button.h>
#include <CheckBox.h> #include <CheckBox.h>
#include <String.h> #include <String.h>
#include <TextControl.h> #include <TextControl.h>
#include <Window.h>
#include <Box.h>
#include "Constants.h"
#include "FindWindow.h"
// FindWindow::FindWindow()
FindWindow::FindWindow(BRect frame, BHandler *_handler, BString *searchString, 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, : BWindow(frame, "FindWindow", B_MODAL_WINDOW,
B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS, B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS,
B_CURRENT_WORKSPACE) 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)); fFindView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(fFindView); AddChild(fFindView);
@@ -34,15 +42,21 @@ FindWindow::FindWindow(BRect frame, BHandler *_handler, BString *searchString,
float backBoxTop = (buttonTop + wrapBoxBottom - lineHeight) / 2; float backBoxTop = (buttonTop + wrapBoxBottom - lineHeight) / 2;
float backBoxBottom = (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)); fFindView->AddChild(fSearchString = new BTextControl(BRect(14, 12,
frame.Width() - 10, searchBottom), "", "Find:", NULL, NULL));
fSearchString->SetDivider(findWidth); fSearchString->SetDivider(findWidth);
fFindView->AddChild(fCaseSensBox= new BCheckBox(BRect(16+findWidth,caseBoxTop,frame.Width()-12,caseBoxBottom),"","Case-sensitive", NULL)); fFindView->AddChild(fCaseSensBox = new BCheckBox(BRect(16 + findWidth, caseBoxTop,
fFindView->AddChild(fWrapBox= new BCheckBox(BRect(16+findWidth,wrapBoxTop,frame.Width()-12,wrapBoxBottom),"","Wrap-around search", NULL)); frame.Width() - 12, caseBoxBottom), "", "Case-sensitive", NULL));
fFindView->AddChild(fBackSearchBox= new BCheckBox(BRect(16+findWidth,backBoxTop,frame.Width()-12,backBoxBottom),"","Search backwards", 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(fCancelButton = new BButton(BRect(142, buttonTop, 212,
fFindView->AddChild(fSearchButton= new BButton(BRect(221,buttonTop,291,frame.Height()-7),"","Find",new BMessage(MSG_SEARCH))); 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); fSearchButton->MakeDefault(true);
fHandler = _handler; fHandler = _handler;
@@ -50,98 +64,64 @@ FindWindow::FindWindow(BRect frame, BHandler *_handler, BString *searchString,
const char *text = searchString->String(); const char *text = searchString->String();
fSearchString->SetText(text); fSearchString->SetText(text);
fSearchString-> MakeFocus(true); //021021 fSearchString->MakeFocus(true);
if(*caseState== true) fCaseSensBox->SetValue(*caseState ? B_CONTROL_ON : B_CONTROL_OFF);
fCaseSensBox->SetValue(B_CONTROL_ON); fWrapBox->SetValue(*wrapState ? B_CONTROL_ON : B_CONTROL_OFF);
else fBackSearchBox->SetValue(*backState ? B_CONTROL_ON : B_CONTROL_OFF);
fCaseSensBox->SetValue(B_CONTROL_OFF);
if(*wrapState== true)
fWrapBox->SetValue(B_CONTROL_ON);
else
fWrapBox->SetValue(B_CONTROL_OFF);
if(*backState== true)
fBackSearchBox->SetValue(B_CONTROL_ON);
else
fBackSearchBox->SetValue(B_CONTROL_OFF);
Show();
} }
void FindWindow::MessageReceived(BMessage *msg){
void
FindWindow::MessageReceived(BMessage *msg)
{
switch (msg->what) { switch (msg->what) {
case B_QUIT_REQUESTED: case B_QUIT_REQUESTED:
Quit(); Quit();
break; break;
case MSG_SEARCH: case MSG_SEARCH:
ExtractToMsg(new BMessage(MSG_SEARCH)); _SendMessage();
break; break;
default: default:
BWindow::MessageReceived(msg); BWindow::MessageReceived(msg);
break; break;
} }
} }
void FindWindow::DispatchMessage(BMessage *message, BHandler *handler)
void
FindWindow::DispatchMessage(BMessage *message, BHandler *handler)
{ {
int8 key;
if (message->what == B_KEY_DOWN) { if (message->what == B_KEY_DOWN) {
status_t result; int8 key;
result= message->FindInt8("byte", 0, &key); if (message->FindInt8("byte", 0, &key) == B_OK) {
if (result== B_OK){
if (key == B_ESCAPE) { if (key == B_ESCAPE) {
message->MakeEmpty(); message->MakeEmpty();
message->what = B_QUIT_REQUESTED; message->what = B_QUIT_REQUESTED;
} }
} }
} }
BWindow::DispatchMessage(message, handler); BWindow::DispatchMessage(message, handler);
} }
void FindWindow::ExtractToMsg(BMessage *message){
int32 caseBoxState; void
int32 wrapBoxState; FindWindow::_SendMessage()
int32 backBoxState; {
BMessage message(MSG_SEARCH);
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 // Add the string
message->AddString("findtext",fSearchString->Text()); message.AddString("findtext", fSearchString->Text());
// Add searchparameters from checkboxes // Add searchparameters from checkboxes
message->AddBool("casesens", caseSens); message.AddBool("casesens", fCaseSensBox->Value() == B_CONTROL_ON);
message->AddBool("wrap", wrapIt); message.AddBool("wrap", fWrapBox->Value() == B_CONTROL_ON);
message->AddBool("backsearch", backSearch); message.AddBool("backsearch", fBackSearchBox->Value() == B_CONTROL_ON);
fHandler->Looper()->PostMessage(&message, fHandler);
fHandler->Looper()->PostMessage(message,fHandler);
delete(message);
PostMessage(B_QUIT_REQUESTED); PostMessage(B_QUIT_REQUESTED);
} }
+22 -4
View File
@@ -1,15 +1,33 @@
/*
* 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 #ifndef FIND_WINDOW_H
#define FIND_WINDOW_H #define FIND_WINDOW_H
#include <Window.h>
class BButton;
class BCheckBox;
class BTextControl;
class BView;
class FindWindow : public BWindow { class FindWindow : public BWindow {
public: 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 MessageReceived(BMessage* message);
virtual void DispatchMessage(BMessage* message, BHandler* handler); virtual void DispatchMessage(BMessage* message, BHandler* handler);
private: private:
void ExtractToMsg(BMessage *message); void _SendMessage();
BView *fFindView; BView *fFindView;
BTextControl *fSearchString; BTextControl *fSearchString;
@@ -20,9 +38,9 @@ class FindWindow : public BWindow {
BButton *fSearchButton; BButton *fSearchButton;
BHandler *fHandler; BHandler *fHandler;
}; };
#endif
#endif // FIND_WINDOW_H
+79 -107
View File
@@ -1,13 +1,22 @@
#include <Box.h> /*
* 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 <Button.h> #include <Button.h>
#include <CheckBox.h> #include <CheckBox.h>
#include <String.h> #include <String.h>
#include <TextControl.h> #include <TextControl.h>
#include <Window.h> #include <Window.h>
#include "Constants.h"
#include "ReplaceWindow.h"
ReplaceWindow::ReplaceWindow(BRect frame, BHandler *_handler, BString *searchString, ReplaceWindow::ReplaceWindow(BRect frame, BHandler *_handler, BString *searchString,
BString *replaceString, bool *caseState, bool *wrapState, bool *backState) BString *replaceString, bool *caseState, bool *wrapState, bool *backState)
@@ -15,40 +24,46 @@ ReplaceWindow::ReplaceWindow(BRect frame, BHandler *_handler, BString *searchStr
B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS, B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS,
B_CURRENT_WORKSPACE) 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)); fReplaceView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(fReplaceView); AddChild(fReplaceView);
char* findLabel = "Find:"; char* findLabel = "Find:";
float findWidth = fReplaceView->StringWidth(findLabel); float findWidth = fReplaceView->StringWidth(findLabel);
fReplaceView->AddChild(fSearchString= new BTextControl(BRect(5,10,290,50), "", findLabel,NULL, NULL, fReplaceView->AddChild(fSearchString = new BTextControl(BRect(5, 10, 290, 50), "",
B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); 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); float replaceWithWidth = fReplaceView->StringWidth(replaceWithLabel);
fReplaceView->AddChild(fReplaceString=new BTextControl(BRect(5,35,290,50), "", replaceWithLabel,NULL, fReplaceView->AddChild(fReplaceString = new BTextControl(BRect(5, 35, 290, 50), "",
NULL,B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); 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) + 1;
fSearchString->SetDivider(maxWidth); fSearchString->SetDivider(maxWidth);
fReplaceString->SetDivider(maxWidth); fReplaceString->SetDivider(maxWidth);
fReplaceView->AddChild(fCaseSensBox=new BCheckBox(BRect(maxWidth+8,60,290,52),"","Case-sensitive", NULL, 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)); 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, fUIchange = false;
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),
fReplaceView->AddChild(fReplaceAllButton=new BButton(BRect(10,150,98,166),"","Replace All",new BMessage(MSG_REPLACE_ALL), "", "Replace All", new BMessage(MSG_REPLACE_ALL), B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); B_WILL_DRAW | B_NAVIGABLE));
fReplaceView->AddChild(fCancelButton=new BButton(BRect(141,150,211,166),"","Cancel",new BMessage(B_QUIT_REQUESTED), fReplaceView->AddChild(fCancelButton = new BButton(BRect(141, 150, 211, 166),
B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); "", "Cancel", new BMessage(B_QUIT_REQUESTED), B_FOLLOW_LEFT | B_FOLLOW_TOP,
fReplaceView->AddChild(fReplaceButton=new BButton(BRect(221,150,291,166),"","Replace",new BMessage(MSG_REPLACE), B_WILL_DRAW | B_NAVIGABLE));
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); fReplaceButton->MakeDefault(true);
fHandler = _handler; fHandler = _handler;
@@ -58,134 +73,91 @@ ReplaceWindow::ReplaceWindow(BRect frame, BHandler *_handler, BString *searchStr
fSearchString->SetText(searchtext); fSearchString->SetText(searchtext);
fReplaceString->SetText(replacetext); fReplaceString->SetText(replacetext);
fSearchString-> MakeFocus(true); //021021 fSearchString->MakeFocus(true);
if(*caseState== true) fCaseSensBox->SetValue(*caseState ? B_CONTROL_ON : B_CONTROL_OFF);
fCaseSensBox->SetValue(B_CONTROL_ON); fWrapBox->SetValue(*wrapState ? B_CONTROL_ON : B_CONTROL_OFF);
else fBackSearchBox->SetValue(*backState ? B_CONTROL_ON : B_CONTROL_OFF);
fCaseSensBox->SetValue(B_CONTROL_OFF);
if(*wrapState== true)
fWrapBox->SetValue(B_CONTROL_ON);
else
fWrapBox->SetValue(B_CONTROL_OFF);
if(*backState== true)
fBackSearchBox->SetValue(B_CONTROL_ON);
else
fBackSearchBox->SetValue(B_CONTROL_OFF);
Show();
} }
void ReplaceWindow::MessageReceived(BMessage *msg){
void
ReplaceWindow::MessageReceived(BMessage *msg)
{
switch (msg->what){ switch (msg->what){
case B_QUIT_REQUESTED:
Quit();
break;
case MSG_REPLACE: case MSG_REPLACE:
ExtractToMsg(new BMessage(MSG_REPLACE)); _SendMessage(MSG_REPLACE);
break; break;
case CHANGE_WINDOW: case CHANGE_WINDOW:
ChangeUi(); _ChangeUI();
break; break;
case MSG_REPLACE_ALL: case MSG_REPLACE_ALL:
ExtractToMsg(new BMessage(MSG_REPLACE_ALL)); _SendMessage(MSG_REPLACE_ALL);
break; break;
default: default:
BWindow::MessageReceived(msg); BWindow::MessageReceived(msg);
break; break;
} }
} }
void ReplaceWindow::ChangeUi(){
if(!fUichange){ void
ReplaceWindow::_ChangeUI()
{
if (!fUIchange) {
fReplaceAllButton->MakeDefault(true); fReplaceAllButton->MakeDefault(true);
fReplaceButton->SetEnabled(false); fReplaceButton->SetEnabled(false);
fWrapBox->SetValue(B_CONTROL_ON); fWrapBox->SetValue(B_CONTROL_ON);
fWrapBox->SetEnabled(false); fWrapBox->SetEnabled(false);
fBackSearchBox->SetEnabled(false); fBackSearchBox->SetEnabled(false);
fUichange=true; fUIchange = true;
} } else {
else{
fReplaceButton->MakeDefault(true); fReplaceButton->MakeDefault(true);
fReplaceButton->SetEnabled(true); fReplaceButton->SetEnabled(true);
fReplaceAllButton->SetEnabled(true); fReplaceAllButton->SetEnabled(true);
fWrapBox->SetValue(B_CONTROL_OFF); fWrapBox->SetValue(B_CONTROL_OFF);
fWrapBox->SetEnabled(true); fWrapBox->SetEnabled(true);
fBackSearchBox->SetEnabled(true); fBackSearchBox->SetEnabled(true);
fUichange=false; fUIchange = false;
}
} }
}/***ReplaceWindow::ChangeUi()***/
void ReplaceWindow::DispatchMessage(BMessage *message, BHandler *fHandler){ void
int8 key; ReplaceWindow::DispatchMessage(BMessage *message, BHandler *handler)
{
if (message->what == B_KEY_DOWN) { if (message->what == B_KEY_DOWN) {
status_t result; int8 key;
result= message-> FindInt8("byte", 0, &key); if (message->FindInt8("byte", 0, &key) == B_OK) {
if (result== B_OK) {
if (key == B_ESCAPE) { if (key == B_ESCAPE) {
message->MakeEmpty(); message->MakeEmpty();
message->what = B_QUIT_REQUESTED; message->what = B_QUIT_REQUESTED;
} }
} }
} }
BWindow::DispatchMessage(message,fHandler);
BWindow::DispatchMessage(message, handler);
} }
void ReplaceWindow::ExtractToMsg(BMessage *message ){
int32 caseBoxState; void
int32 wrapBoxState; ReplaceWindow::_SendMessage(uint32 what)
int32 backBoxState; {
int32 allWinBoxState; BMessage message(what);
caseBoxState= fCaseSensBox-> Value(); // Add the strings
wrapBoxState= fWrapBox-> Value(); message.AddString("FindText", fSearchString->Text());
backBoxState= fBackSearchBox-> Value(); message.AddString("ReplaceText", fReplaceString->Text());
allWinBoxState= fAllWindowsBox-> Value();
bool caseSens; // Add searchparameters from checkboxes
bool wrapIt; message.AddBool("casesens", fCaseSensBox->Value() == B_CONTROL_ON);
bool backSearch; message.AddBool("wrap", fWrapBox->Value() == B_CONTROL_ON);
bool allWindows; message.AddBool("backsearch", fBackSearchBox->Value() == B_CONTROL_ON);
message.AddBool("allwindows", fAllWindowsBox->Value() == B_CONTROL_ON);
if(caseBoxState== B_CONTROL_ON) fHandler->Looper()->PostMessage(&message, fHandler);
caseSens= true;
else
caseSens= false;
if(wrapBoxState== B_CONTROL_ON)
wrapIt= true;
else
wrapIt= false;
if(backBoxState== B_CONTROL_ON)
backSearch= true;
else
backSearch= false;
if(allWinBoxState== B_CONTROL_ON)
allWindows= true;
else
allWindows= false;
message->AddString("FindText",fSearchString->Text());
message->AddString("ReplaceText",fReplaceString->Text());
message->AddBool("casesens", caseSens);
message->AddBool("wrap", wrapIt);
message->AddBool("backsearch", backSearch);
message->AddBool("allwindows", allWindows);
fHandler->Looper()->PostMessage(message,fHandler);
delete(message);
PostMessage(B_QUIT_REQUESTED); PostMessage(B_QUIT_REQUESTED);
} }
+15 -6
View File
@@ -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 #ifndef REPLACE_WINDOW_H
#define REPLACE_WINDOW_H #define REPLACE_WINDOW_H
#include <Window.h> #include <Window.h>
#include <Rect.h> #include <Rect.h>
#include <Handler.h> #include <Handler.h>
@@ -11,6 +20,7 @@
#include <CheckBox.h> #include <CheckBox.h>
#include <Button.h> #include <Button.h>
class ReplaceWindow : public BWindow { class ReplaceWindow : public BWindow {
public: public:
ReplaceWindow(BRect frame, BHandler *_handler,BString *searchString, ReplaceWindow(BRect frame, BHandler *_handler,BString *searchString,
@@ -19,10 +29,10 @@ class ReplaceWindow : public BWindow {
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
virtual void DispatchMessage(BMessage* message, BHandler *handler); virtual void DispatchMessage(BMessage* message, BHandler *handler);
private: private:
void ExtractToMsg(BMessage *message); void _SendMessage(uint32 what);
void ChangeUi(); void _ChangeUI();
BView *fReplaceView; BView *fReplaceView;
BTextControl *fSearchString; BTextControl *fSearchString;
BTextControl *fReplaceString; BTextControl *fReplaceString;
@@ -34,8 +44,7 @@ class ReplaceWindow : public BWindow {
BButton *fReplaceAllButton; BButton *fReplaceAllButton;
BButton *fCancelButton; BButton *fCancelButton;
BHandler *fHandler; BHandler *fHandler;
bool fUichange; bool fUIchange;
}; };
#endif #endif // REPLACE_WINDOW_H
+81 -63
View File
@@ -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 <Alert.h> #include <Alert.h>
#include <Autolock.h> #include <Autolock.h>
@@ -14,39 +23,48 @@
using namespace BPrivate; 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); BScreen screen(NULL);
BRect screenBorder = screen.Frame(); BRect screenBorder = screen.Frame();
float left = windowRect.left + 15; float left = gWindowRect.left + 15;
if (left + windowRect.Width() > screenBorder.right) { if (left + gWindowRect.Width() > screenBorder.right)
left = 7; left = 7;
}
float top = windowRect.top + 15; float top = gWindowRect.top + 15;
if (top + windowRect.Height() > screenBorder.bottom) { if (top + gWindowRect.Height() > screenBorder.bottom)
top = 26; top = 26;
}
windowRect.OffsetTo(BPoint(left,top)); gWindowRect.OffsetTo(BPoint(left,top));
} }
void uncascade() {
void
uncascade()
{
BScreen screen(NULL); BScreen screen(NULL);
BRect screenBorder = screen.Frame(); BRect screenBorder = screen.Frame();
float left = windowRect.left - 15;
float left = gWindowRect.left - 15;
if (left < 7) { if (left < 7) {
left = screenBorder.right - windowRect.Width() - 7; left = screenBorder.right - gWindowRect.Width() - 7;
left = left - ((int)left % 15) + 7; left = left - ((int)left % 15) + 7;
} }
float top = windowRect.top - 15;
float top = gWindowRect.top - 15;
if (top < 26) { if (top < 26) {
top = screenBorder.bottom - windowRect.Height() - 26; top = screenBorder.bottom - gWindowRect.Height() - 26;
top = top - ((int)left % 15) + 26; top = top - ((int)left % 15) + 26;
} }
windowRect.OffsetTo(BPoint(left,top));
gWindowRect.OffsetTo(BPoint(left,top));
} }
StyledEditApp * styled_edit_app;
StyledEditApp::StyledEditApp() StyledEditApp::StyledEditApp()
: BApplication(APP_SIGNATURE) : BApplication(APP_SIGNATURE)
@@ -73,38 +91,39 @@ StyledEditApp::StyledEditApp()
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); item->SetTarget(this);
fOpenPanelEncodingMenu->AddItem(item); fOpenPanelEncodingMenu->AddItem(item);
if (charset.GetFontID() == fOpenAsEncoding) { if (charset.GetFontID() == fOpenAsEncoding)
item->SetMarked(true); item->SetMarked(true);
} }
}
fWindowCount = 0; fWindowCount = 0;
fNext_Untitled_Window= 1; fNextUntitledWindow = 1;
styled_edit_app = this;
} /***StyledEditApp::StyledEditApp()***/
void StyledEditApp::DispatchMessage(BMessage *msg, BHandler *handler) 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; int32 argc;
if (msg->FindInt32("argc",&argc) != B_OK) { if (msg->FindInt32("argc", &argc) != B_OK)
argc = 0; argc = 0;
}
const char** argv = new const char*[argc]; const char** argv = new const char*[argc];
for (int arg = 0; (arg < argc) ; arg++) { for (int arg = 0; arg < argc; arg++) {
if (msg->FindString("argv", arg, &argv[arg]) != B_OK) { if (msg->FindString("argv", arg, &argv[arg]) != B_OK) {
argv[arg] = ""; argv[arg] = "";
} }
} }
const char* cwd; const char* cwd;
if (msg->FindString("cwd",&cwd) != B_OK) { if (msg->FindString("cwd", &cwd) != B_OK)
cwd = ""; cwd = "";
}
ArgvReceived(argc, argv, cwd); ArgvReceived(argc, argv, cwd);
} else { } else
BApplication::DispatchMessage(msg, handler); BApplication::DispatchMessage(msg, handler);
} }
}
void void
@@ -115,41 +134,44 @@ StyledEditApp::MessageReceived(BMessage *message)
OpenDocument(); OpenDocument();
break; break;
case MENU_OPEN: case MENU_OPEN:
fOpenPanel->Show(); // fOpenPanel->Show();
break; break;
case B_SILENT_RELAUNCH: case B_SILENT_RELAUNCH:
OpenDocument(); OpenDocument();
break; break;
case OPEN_AS_ENCODING: case OPEN_AS_ENCODING:
void* ptr; void* ptr;
if (message->FindPointer("source",&ptr) == B_OK) { if (message->FindPointer("source", &ptr) == B_OK
if (fOpenPanelEncodingMenu != 0) { && fOpenPanelEncodingMenu != 0) {
fOpenAsEncoding = (uint32)fOpenPanelEncodingMenu->IndexOf((BMenuItem*)ptr); fOpenAsEncoding = (uint32)fOpenPanelEncodingMenu->IndexOf((BMenuItem*)ptr);
} }
}
break; break;
default: default:
BApplication::MessageReceived(message); BApplication::MessageReceived(message);
break; break;
} }
} }
void void
StyledEditApp::OpenDocument() StyledEditApp::OpenDocument()
{ {
cascade(); cascade();
new StyledEditWindow(windowRect,fNext_Untitled_Window++,fOpenAsEncoding); new StyledEditWindow(gWindowRect, fNextUntitledWindow++, fOpenAsEncoding);
fWindowCount++; fWindowCount++;
} }
void void
StyledEditApp::OpenDocument(entry_ref* ref) StyledEditApp::OpenDocument(entry_ref* ref)
{ {
cascade(); cascade();
new StyledEditWindow(windowRect,ref,fOpenAsEncoding); new StyledEditWindow(gWindowRect, ref, fOpenAsEncoding);
fWindowCount++; fWindowCount++;
} }
void void
StyledEditApp::CloseDocument() StyledEditApp::CloseDocument()
{ {
@@ -161,73 +183,69 @@ StyledEditApp::CloseDocument()
} }
} }
void void
StyledEditApp::RefsReceived(BMessage *message) StyledEditApp::RefsReceived(BMessage *message)
{ {
int32 refNum; int32 index = 0;
entry_ref ref; entry_ref ref;
status_t err;
refNum = 0; while (message->FindRef("refs", index++, &ref) == B_OK) {
do {
err = message->FindRef("refs", refNum, &ref);
if (err != B_OK)
return;
OpenDocument(&ref); OpenDocument(&ref);
refNum++; }
} while (true); }
} /***StyledEditApp::RefsReceived();***/
void 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++) { for (int i = 1 ; (i < argc) ; i++) {
BPath path; BPath path;
if (argv[i][0] == '/') { if (argv[i][0] == '/')
path.SetTo(argv[i]); path.SetTo(argv[i]);
} else { else
path.SetTo(cwd, argv[i]); path.SetTo(cwd, argv[i]);
}
if (path.InitCheck() != B_OK) { if (path.InitCheck() != B_OK) {
printf("path.InitCheck failed: \""); fprintf(stderr, "Setting path failed: \"");
if (argv[i][0] == '/') { if (argv[i][0] == '/')
printf("%s",argv[i]); fprintf(stderr, "%s\".\n", argv[i]);
} else { else
printf("%s/%s",cwd,argv[i]); fprintf(stderr, "%s/%s\".\n", cwd, argv[i]);
}
printf("\".\n");
continue; continue;
} }
entry_ref ref; entry_ref ref;
if (get_ref_for_path(path.Path(), &ref) != B_OK) { if (get_ref_for_path(path.Path(), &ref) != B_OK) {
printf("get_ref_for_path failed: \""); fprintf(stderr, "Entry not found: \"%s\".\n", path.Path());
printf("%s",path.Path());
printf("\".\n");
continue; continue;
} }
OpenDocument(&ref); OpenDocument(&ref);
} }
} }
void void
StyledEditApp::ReadyToRun() StyledEditApp::ReadyToRun()
{ {
if (fWindowCount == 0) { if (fWindowCount == 0)
OpenDocument(); OpenDocument();
} }
}
int32 int32
StyledEditApp::NumberOfWindows() StyledEditApp::NumberOfWindows()
{ {
return fWindowCount; return fWindowCount;
}/***StyledEditApp::NumberOfWindows()***/ }
// #pragma mark -
int int
main() main(int argc, char** argv)
{ {
StyledEditApp styledEdit; StyledEditApp styledEdit;
styledEdit.Run(); styledEdit.Run();
+12 -5
View File
@@ -1,16 +1,23 @@
/**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 #ifndef STYLED_EDIT_APP
#define STYLED_EDIT_APP #define STYLED_EDIT_APP
#include <Application.h> #include <Application.h>
#include <Message.h> #include <Message.h>
#include <FilePanel.h> #include <FilePanel.h>
class StyledEditWindow; class StyledEditWindow;
class StyledEditApp class StyledEditApp : public BApplication {
: public BApplication
{
public: public:
StyledEditApp(); StyledEditApp();
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
@@ -30,7 +37,7 @@ private:
BMenu* fOpenPanelEncodingMenu; BMenu* fOpenPanelEncodingMenu;
uint32 fOpenAsEncoding; uint32 fOpenAsEncoding;
int32 fWindowCount; int32 fWindowCount;
int32 fNext_Untitled_Window; int32 fNextUntitledWindow;
}; };
+63 -42
View File
@@ -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 <Message.h> #include <Message.h>
#include <Messenger.h> #include <Messenger.h>
#include <Rect.h> #include <Rect.h>
@@ -10,11 +23,9 @@
#include <CharacterSetRoster.h> #include <CharacterSetRoster.h>
#include <UTF8.h> #include <UTF8.h>
#include "StyledEditView.h"
#include "Constants.h"
using namespace BPrivate; using namespace BPrivate;
StyledEditView::StyledEditView(BRect viewFrame, BRect textBounds, BHandler *handler) StyledEditView::StyledEditView(BRect viewFrame, BRect textBounds, BHandler *handler)
: BTextView(viewFrame, "textview", textBounds, : BTextView(viewFrame, "textview", textBounds,
B_FOLLOW_ALL, B_FRAME_EVENTS|B_WILL_DRAW) B_FOLLOW_ALL, B_FRAME_EVENTS|B_WILL_DRAW)
@@ -25,11 +36,13 @@ StyledEditView::StyledEditView(BRect viewFrame, BRect textBounds, BHandler *hand
fEncoding = 0; fEncoding = 0;
} }
StyledEditView::~StyledEditView() StyledEditView::~StyledEditView()
{ {
delete fMessenger; delete fMessenger;
} }
void void
StyledEditView::FrameResized(float width, float height) StyledEditView::FrameResized(float width, float height)
{ {
@@ -42,6 +55,7 @@ StyledEditView::FrameResized(float width, float height)
textRect.InsetBy(TEXT_INSET, TEXT_INSET); textRect.InsetBy(TEXT_INSET, TEXT_INSET);
SetTextRect(textRect); SetTextRect(textRect);
} }
/* // I tried to do some sort of intelligent resize thing but it just doesn't work /* // 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 // 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 :-( // some crazy large number when word wrap is turned off :-(
@@ -60,45 +74,44 @@ StyledEditView::FrameResized(float width, float height)
*/ */
} }
status_t status_t
StyledEditView::GetStyledText(BPositionIO* stream) StyledEditView::GetStyledText(BPositionIO* stream)
{ {
status_t result = B_OK;
fSuppressChanges = true; fSuppressChanges = true;
result = BTranslationUtils::GetStyledText(stream, this, NULL); status_t result = BTranslationUtils::GetStyledText(stream, this, NULL);
fSuppressChanges = false; fSuppressChanges = false;
if (result != B_OK) {
if (result != B_OK)
return result; return result;
}
BNode* node = dynamic_cast<BNode*>(stream); BNode* node = dynamic_cast<BNode*>(stream);
if (node != 0) { if (node != NULL) {
ssize_t bytesRead; ssize_t bytesRead;
// decode encoding // decode encoding
int32 encoding; int32 encoding;
bytesRead = node->ReadAttr("be:encoding", 0, 0, &encoding, sizeof(encoding)); bytesRead = node->ReadAttr("be:encoding", 0, 0, &encoding, sizeof(encoding));
if (bytesRead > 0) { if (bytesRead == (ssize_t)sizeof(encoding)) {
if (encoding == 65535) { if (encoding == 65535) {
fEncoding = 0; fEncoding = 0;
} else { } else {
const BCharacterSet * cs = BCharacterSetRoster::GetCharacterSetByConversionID(encoding); const BCharacterSet* characterSet
if (cs != 0) { = BCharacterSetRoster::GetCharacterSetByConversionID(encoding);
fEncoding = cs->GetFontID(); if (characterSet != 0)
} fEncoding = characterSet->GetFontID();
} }
} }
// restore alignment // restore alignment
alignment align; alignment align;
bytesRead = node->ReadAttr("alignment", 0, 0, &align, sizeof(align)); bytesRead = node->ReadAttr("alignment", 0, 0, &align, sizeof(align));
if (bytesRead > 0) { if (bytesRead == (ssize_t)sizeof(align))
SetAlignment(align); SetAlignment(align);
}
// restore wrapping // restore wrapping
bool wrap; bool wrap;
bytesRead = node->ReadAttr("wrap", 0, 0, &wrap, sizeof(wrap)); bytesRead = node->ReadAttr("wrap", 0, 0, &wrap, sizeof(wrap));
if (bytesRead > 0) { if (bytesRead == (ssize_t)sizeof(wrap)) {
SetWordWrap(wrap); SetWordWrap(wrap);
if (wrap == false) { if (wrap == false) {
BRect textRect; BRect textRect;
@@ -111,30 +124,33 @@ StyledEditView::GetStyledText(BPositionIO * stream)
} }
} }
} }
if (fEncoding != 0) { 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... // 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(); uint32 id = BCharacterSetRoster::GetCharacterSetByFontID(fEncoding)->GetConversionID();
fSuppressChanges = true; fSuppressChanges = true;
SetText(""); SetText("");
fSuppressChanges = false; fSuppressChanges = false;
char inBuffer[32768]; char inBuffer[32768];
off_t location = 0; off_t location = 0;
int32 textOffset = 0; int32 textOffset = 0;
int32 state = 0; int32 state = 0;
int32 bytesRead; int32 bytesRead;
while ((bytesRead = stream->ReadAt(location,inBuffer,32768)) > 0) { while ((bytesRead = stream->ReadAt(location, inBuffer, sizeof(inBuffer))) > 0) {
char* inPtr = inBuffer; char* inPtr = inBuffer;
char textBuffer[32768]; char textBuffer[32768];
int32 textLength = 32768; int32 textLength = sizeof(textBuffer);
int32 bytes = bytesRead; int32 bytes = bytesRead;
while ((textLength > 0) && (bytes > 0)) { while (textLength > 0 && bytes > 0) {
result = convert_to_utf8(id, inPtr, &bytes, textBuffer, &textLength, &state); result = convert_to_utf8(id, inPtr, &bytes, textBuffer, &textLength, &state);
if (result != B_OK) { if (result != B_OK)
return result; return result;
}
fSuppressChanges = true; fSuppressChanges = true;
InsertText(textBuffer, textLength, textOffset); InsertText(textBuffer, textLength, textOffset);
fSuppressChanges = false; fSuppressChanges = false;
@@ -143,28 +159,29 @@ StyledEditView::GetStyledText(BPositionIO * stream)
location += bytes; location += bytes;
bytesRead -= bytes; bytesRead -= bytes;
bytes = bytesRead; bytes = bytesRead;
if (textLength > 0) { if (textLength > 0)
textLength = 32768; textLength = sizeof(textBuffer);
}
} }
} }
// ... and here we restore it // ... and here we restore it
SetRunArray(0,length,run_array); SetRunArray(0, length, runArray);
free(run_array); free(runArray);
} }
return result; return result;
} }
status_t status_t
StyledEditView::WriteStyledEditFile(BFile* file) StyledEditView::WriteStyledEditFile(BFile* file)
{ {
status_t result = B_OK; status_t result = B_OK;
ssize_t bytes = 0; ssize_t bytes = 0;
result = BTranslationUtils::WriteStyledEditFile(this, file); result = BTranslationUtils::WriteStyledEditFile(this, file);
if (result != B_OK) { if (result != B_OK)
return result; return result;
}
if (fEncoding == 0) { if (fEncoding == 0) {
int32 encoding = 65535; 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));
@@ -172,13 +189,13 @@ StyledEditView::WriteStyledEditFile(BFile * file)
return bytes; return bytes;
} else { } else {
result = file->SetSize(0); result = file->SetSize(0);
if (result != B_OK) { if (result != B_OK)
return result; return result;
}
bytes = file->Seek(0, SEEK_SET); bytes = file->Seek(0, SEEK_SET);
if (bytes != 0) { if (bytes != 0)
return bytes; return bytes;
}
const BCharacterSet* cs = BCharacterSetRoster::GetCharacterSetByFontID(fEncoding); const BCharacterSet* cs = BCharacterSetRoster::GetCharacterSetByFontID(fEncoding);
if (cs != 0) { if (cs != 0) {
uint32 id = cs->GetConversionID(); uint32 id = cs->GetConversionID();
@@ -209,13 +226,16 @@ StyledEditView::WriteStyledEditFile(BFile * file)
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) if (bytes < 0)
return bytes; return bytes;
bool wrap = DoesWordWrap(); 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) if (bytes < 0)
return bytes; return bytes;
return result; return result;
} }
void void
StyledEditView::Reset() StyledEditView::Reset()
{ {
@@ -224,40 +244,41 @@ StyledEditView::Reset()
fSuppressChanges = false; fSuppressChanges = false;
} }
void void
StyledEditView::Select(int32 start, int32 finish) StyledEditView::Select(int32 start, int32 finish)
{ {
if(start==finish) fChangeMessage = new BMessage(start == finish ? DISABLE_ITEMS : ENABLE_ITEMS);
fChangeMessage= new BMessage(DISABLE_ITEMS);
else
fChangeMessage= new BMessage(ENABLE_ITEMS);
fMessenger->SendMessage(fChangeMessage); fMessenger->SendMessage(fChangeMessage);
BTextView::Select(start, finish); BTextView::Select(start, finish);
} }
void void
StyledEditView::SetEncoding(uint32 encoding) StyledEditView::SetEncoding(uint32 encoding)
{ {
fEncoding = encoding; fEncoding = encoding;
} }
uint32 uint32
StyledEditView::GetEncoding() const StyledEditView::GetEncoding() const
{ {
return fEncoding; return fEncoding;
} }
void 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) if (!fSuppressChanges)
fMessenger->SendMessage(new BMessage(TEXT_CHANGED)); fMessenger->SendMessage(new BMessage(TEXT_CHANGED));
BTextView::InsertText(text, length, offset, runs); BTextView::InsertText(text, length, offset, runs);
}
}/****StyledEditView::InsertText()***/
void void
StyledEditView::DeleteText(int32 start, int32 finish) StyledEditView::DeleteText(int32 start, int32 finish)
@@ -266,5 +287,5 @@ StyledEditView::DeleteText(int32 start, int32 finish)
fMessenger-> SendMessage(new BMessage(TEXT_CHANGED)); fMessenger-> SendMessage(new BMessage(TEXT_CHANGED));
BTextView::DeleteText(start, finish); BTextView::DeleteText(start, finish);
}
}/***StyledEditView::DeleteText***/
+11
View File
@@ -1,10 +1,20 @@
/*
* 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 #ifndef STYLED_EDIT_VIEW_H
#define STYLED_EDIT_VIEW_H #define STYLED_EDIT_VIEW_H
#include <File.h> #include <File.h>
#include <TextView.h> #include <TextView.h>
#include <DataIO.h> #include <DataIO.h>
class StyledEditView : public BTextView { class StyledEditView : public BTextView {
public: public:
StyledEditView(BRect viewframe, BRect textframe, BHandler *handler); StyledEditView(BRect viewframe, BRect textframe, BHandler *handler);
@@ -19,6 +29,7 @@ public:
virtual void SetEncoding(uint32 encoding); virtual void SetEncoding(uint32 encoding);
virtual uint32 GetEncoding() const; virtual uint32 GetEncoding() const;
protected: protected:
virtual void InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs = NULL); 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 DeleteText(int32 start, int32 finish);
File diff suppressed because it is too large Load Diff
+12 -4
View File
@@ -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 #ifndef STYLED_EDIT_WINDOW_H
#define STYLED_EDIT_WINDOW_H #define STYLED_EDIT_WINDOW_H
#include <FilePanel.h> #include <FilePanel.h>
#include <MenuBar.h> #include <MenuBar.h>
#include <Message.h> #include <Message.h>
@@ -9,11 +18,10 @@
#include <TextView.h> #include <TextView.h>
#include <Window.h> #include <Window.h>
class StyledEditView; class StyledEditView;
class StyledEditWindow class StyledEditWindow : public BWindow {
: public BWindow
{
public: public:
StyledEditWindow(BRect frame, int32 id, uint32 encoding = 0); StyledEditWindow(BRect frame, int32 id, uint32 encoding = 0);
StyledEditWindow(BRect frame, entry_ref *ref, uint32 encoding = 0); StyledEditWindow(BRect frame, entry_ref *ref, uint32 encoding = 0);
@@ -40,6 +48,7 @@ private:
void SetFontSize(float fontSize); void SetFontSize(float fontSize);
void SetFontColor(const rgb_color *color); void SetFontColor(const rgb_color *color);
void SetFontStyle(const char *fontFamily, const char *fontStyle); void SetFontStyle(const char *fontFamily, const char *fontStyle);
status_t _LoadFile(entry_ref* ref);
void RevertToSaved(); void RevertToSaved();
BMenuBar *fMenuBar; BMenuBar *fMenuBar;
@@ -99,7 +108,6 @@ private:
BFilePanel *fSavePanel; BFilePanel *fSavePanel;
BMenu *fSavePanelEncodingMenu; BMenu *fSavePanelEncodingMenu;
}; };
#endif // STYLED_EDIT_WINDOW_H #endif // STYLED_EDIT_WINDOW_H