* 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

View File

@ -1,21 +1,30 @@
#ifndef _MENU_ITEM_H
#include <MenuItem.h>
#endif
/*
* Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Mattias Sundblad
* Andrew Bachmann
*/
#ifndef COLOR_MENU_ITEM_H
#include "ColorMenuItem.h"
#endif
ColorMenuItem::ColorMenuItem(const char *label, rgb_color color,BMessage *message)
:BMenuItem(label, message,0,0){
fItemColor= color;
ColorMenuItem::ColorMenuItem(const char *label, rgb_color color, BMessage *message)
: BMenuItem(label, message, 0, 0)
{
fItemColor = color;
}
void ColorMenuItem::DrawContent(){
BMenu *menu= Menu();
rgb_color menuColor = menu->HighColor();
menu->SetHighColor(fItemColor);
BMenuItem::DrawContent();
menu->SetHighColor(menuColor);
void
ColorMenuItem::DrawContent()
{
BMenu *menu = Menu();
rgb_color menuColor = menu->HighColor();
menu->SetHighColor(fItemColor);
BMenuItem::DrawContent();
menu->SetHighColor(menuColor);
}

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
#define COLOR_MENU_ITEM_H
#include <MenuItem.h>
class ColorMenuItem: public BMenuItem {
public:
ColorMenuItem(const char *label, rgb_color color, BMessage *message);
protected:
virtual void DrawContent();
private:
rgb_color fItemColor;
};
#endif
protected:
virtual void DrawContent();
private:
rgb_color fItemColor;
};
#endif // COLOR_MENU_ITEM_H

View File

@ -1,44 +1,55 @@
/*StyledEdit: constants*/
/*
* Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Mattias Sundblad
* Andrew Bachmann
*/
#ifndef CONSTANTS_H
#define CONSTANTS_H
#include <GraphicsDefs.h>
#include <SupportDefs.h>
#define APP_SIGNATURE "application/x-vnd.obos.styled-edit"
const float TEXT_INSET = 3.0;
/*Messages for menu commands
file menu*/
const uint32 MENU_NEW ='MFnw';
const uint32 MENU_OPEN ='MFop';
const uint32 MENU_SAVE ='MSav';
const uint32 MENU_SAVEAS ='MEsa';
const uint32 MENU_REVERT ='MFre';
const uint32 MENU_CLOSE ='MFcl';
const uint32 MENU_PAGESETUP ='MFps';
const uint32 MENU_PRINT ='MFpr';
const uint32 MENU_QUIT ='MFqu';
//edit menu
const uint32 MENU_CLEAR ='MEcl';
const uint32 MENU_FIND ='MEfi';
const uint32 MENU_FIND_AGAIN ='MEfa';
const uint32 MENU_FIND_SELECTION ='MEfs';
const uint32 MENU_REPLACE ='MEre';
const uint32 MENU_REPLACE_SAME ='MErs';
// Messages for menu commands
const uint32 MSG_SEARCH ='msea';
const uint32 MSG_REPLACE ='msre';
const uint32 MSG_REPLACE_ALL ='mrea';
//"Font"-menu
const uint32 FONT_SIZE ='FMsi';
const uint32 FONT_FAMILY ='FFch';
const uint32 FONT_STYLE ='FSch';
const uint32 FONT_COLOR ='Fcol';
// file menu
const uint32 MENU_NEW = 'MFnw';
const uint32 MENU_OPEN = 'MFop';
const uint32 MENU_SAVE = 'MSav';
const uint32 MENU_SAVEAS = 'MEsa';
const uint32 MENU_REVERT = 'MFre';
const uint32 MENU_CLOSE = 'MFcl';
const uint32 MENU_PAGESETUP = 'MFps';
const uint32 MENU_PRINT = 'MFpr';
const uint32 MENU_QUIT = 'MFqu';
//fontcolors
//red, green, blue, alphachannel
// edit menu
const uint32 MENU_CLEAR = 'MEcl';
const uint32 MENU_FIND = 'MEfi';
const uint32 MENU_FIND_AGAIN = 'MEfa';
const uint32 MENU_FIND_SELECTION = 'MEfs';
const uint32 MENU_REPLACE = 'MEre';
const uint32 MENU_REPLACE_SAME = 'MErs';
const uint32 MSG_SEARCH = 'msea';
const uint32 MSG_REPLACE = 'msre';
const uint32 MSG_REPLACE_ALL = 'mrea';
// "Font"-menu
const uint32 FONT_SIZE = 'FMsi';
const uint32 FONT_FAMILY = 'FFch';
const uint32 FONT_STYLE = 'FSch';
const uint32 FONT_COLOR = 'Fcol';
// fontcolors
const rgb_color BLACK = {0, 0, 0, 255};
const rgb_color RED = {255, 0, 0, 255};
const rgb_color GREEN = {0, 255, 0, 255};
@ -47,21 +58,21 @@ const rgb_color CYAN = {0, 255, 255, 255};
const rgb_color MAGENTA = {255, 0, 255, 255};
const rgb_color YELLOW = {255, 255, 0, 255};
//"Document"-menu
const uint32 ALIGN_LEFT ='ALle';
const uint32 ALIGN_CENTER ='ALce';
const uint32 ALIGN_RIGHT ='ALri';
const uint32 WRAP_LINES ='MDwr';
// "Document"-menu
const uint32 ALIGN_LEFT = 'ALle';
const uint32 ALIGN_CENTER = 'ALce';
const uint32 ALIGN_RIGHT = 'ALri';
const uint32 WRAP_LINES = 'MDwr';
//enables "edit" menuitems
const uint32 ENABLE_ITEMS ='ENit';
const uint32 DISABLE_ITEMS ='DIit';
const uint32 CHANGE_WINDOW ='CHwi';
const uint32 TEXT_CHANGED ='TEch';
// enables "edit" menuitems
const uint32 ENABLE_ITEMS = 'ENit';
const uint32 DISABLE_ITEMS = 'DIit';
const uint32 CHANGE_WINDOW = 'CHwi';
const uint32 TEXT_CHANGED = 'TEch';
// file panel constants
const uint32 OPEN_AS_ENCODING ='FPoe';
const uint32 SAVE_AS_ENCODING ='FPse';
const uint32 SAVE_THEN_QUIT ='FPsq';
const uint32 OPEN_AS_ENCODING = 'FPoe';
const uint32 SAVE_AS_ENCODING = 'FPse';
const uint32 SAVE_THEN_QUIT = 'FPsq';
#endif // CONSTANTS_H
#endif // CONSTANTS_H

View File

@ -1,147 +1,127 @@
/*
* Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Mattias Sundblad
* Andrew Bachmann
*/
#include "Constants.h"
#include "FindWindow.h"
#include <Button.h>
#include <CheckBox.h>
#include <String.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,
bool *caseState, bool *wrapState, bool *backState)
: BWindow(frame, "FindWindow", B_MODAL_WINDOW,
B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS,
B_CURRENT_WORKSPACE)
{
fFindView = new BBox(Bounds(), "FindView", B_FOLLOW_ALL, B_WILL_DRAW, B_PLAIN_BORDER);
fFindView = new BView(Bounds(), "FindView", B_FOLLOW_ALL, B_WILL_DRAW);
fFindView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(fFindView);
font_height height;
fFindView->GetFontHeight(&height);
float lineHeight = height.ascent+height.descent+height.leading;
float findWidth = fFindView->StringWidth("Find:")+6;
float searchBottom = 12 + 2 + lineHeight + 2 + 1;
float buttonTop = frame.Height()-19-lineHeight;
float wrapBoxTop = (buttonTop+searchBottom-lineHeight)/2;
float wrapBoxBottom = (buttonTop+searchBottom+lineHeight)/2;
float caseBoxTop = (searchBottom+wrapBoxTop-lineHeight)/2;
float caseBoxBottom = (searchBottom+wrapBoxTop+lineHeight)/2;
float backBoxTop = (buttonTop+wrapBoxBottom-lineHeight)/2;
float backBoxBottom = (buttonTop+wrapBoxBottom+lineHeight)/2;
fFindView->AddChild(fSearchString= new BTextControl(BRect(14,12,frame.Width()-10,searchBottom), "", "Find:", NULL, NULL));
fSearchString->SetDivider(findWidth);
float lineHeight = height.ascent+height.descent + height.leading;
fFindView->AddChild(fCaseSensBox= new BCheckBox(BRect(16+findWidth,caseBoxTop,frame.Width()-12,caseBoxBottom),"","Case-sensitive", NULL));
fFindView->AddChild(fWrapBox= new BCheckBox(BRect(16+findWidth,wrapBoxTop,frame.Width()-12,wrapBoxBottom),"","Wrap-around search", NULL));
fFindView->AddChild(fBackSearchBox= new BCheckBox(BRect(16+findWidth,backBoxTop,frame.Width()-12,backBoxBottom),"","Search backwards", NULL));
fFindView->AddChild(fCancelButton= new BButton(BRect(142,buttonTop,212,frame.Height()-7),"","Cancel",new BMessage(B_QUIT_REQUESTED)));
fFindView->AddChild(fSearchButton= new BButton(BRect(221,buttonTop,291,frame.Height()-7),"","Find",new BMessage(MSG_SEARCH)));
float findWidth = fFindView->StringWidth("Find:") + 6;
float searchBottom = 12 + 2 + lineHeight + 2 + 1;
float buttonTop = frame.Height() - 19 - lineHeight;
float wrapBoxTop = (buttonTop + searchBottom - lineHeight) / 2;
float wrapBoxBottom = (buttonTop + searchBottom + lineHeight) / 2;
float caseBoxTop = (searchBottom + wrapBoxTop - lineHeight) / 2;
float caseBoxBottom = (searchBottom + wrapBoxTop + lineHeight) / 2;
float backBoxTop = (buttonTop + wrapBoxBottom - lineHeight) / 2;
float backBoxBottom = (buttonTop + wrapBoxBottom + lineHeight) / 2;
fFindView->AddChild(fSearchString = new BTextControl(BRect(14, 12,
frame.Width() - 10, searchBottom), "", "Find:", NULL, NULL));
fSearchString->SetDivider(findWidth);
fFindView->AddChild(fCaseSensBox = new BCheckBox(BRect(16 + findWidth, caseBoxTop,
frame.Width() - 12, caseBoxBottom), "", "Case-sensitive", NULL));
fFindView->AddChild(fWrapBox = new BCheckBox(BRect(16 + findWidth, wrapBoxTop,
frame.Width() - 12, wrapBoxBottom), "", "Wrap-around search", NULL));
fFindView->AddChild(fBackSearchBox = new BCheckBox(BRect(16 + findWidth,
backBoxTop, frame.Width() - 12, backBoxBottom), "", "Search backwards", NULL));
fFindView->AddChild(fCancelButton = new BButton(BRect(142, buttonTop, 212,
frame.Height() - 7), "", "Cancel", new BMessage(B_QUIT_REQUESTED)));
fFindView->AddChild(fSearchButton = new BButton(BRect(221, buttonTop, 291,
frame.Height() - 7), "", "Find", new BMessage(MSG_SEARCH)));
fSearchButton->MakeDefault(true);
fHandler=_handler;
const char *text= searchString->String();
fHandler = _handler;
const char *text = searchString->String();
fSearchString->SetText(text);
fSearchString-> MakeFocus(true); //021021
if(*caseState== true)
fCaseSensBox->SetValue(B_CONTROL_ON);
else
fCaseSensBox->SetValue(B_CONTROL_OFF);
if(*wrapState== true)
fWrapBox->SetValue(B_CONTROL_ON);
else
fWrapBox->SetValue(B_CONTROL_OFF);
if(*backState== true)
fBackSearchBox->SetValue(B_CONTROL_ON);
else
fBackSearchBox->SetValue(B_CONTROL_OFF);
Show();
fSearchString->MakeFocus(true);
fCaseSensBox->SetValue(*caseState ? B_CONTROL_ON : B_CONTROL_OFF);
fWrapBox->SetValue(*wrapState ? B_CONTROL_ON : B_CONTROL_OFF);
fBackSearchBox->SetValue(*backState ? B_CONTROL_ON : B_CONTROL_OFF);
}
void FindWindow::MessageReceived(BMessage *msg){
switch(msg->what){
void
FindWindow::MessageReceived(BMessage *msg)
{
switch (msg->what) {
case B_QUIT_REQUESTED:
Quit();
break;
break;
case MSG_SEARCH:
ExtractToMsg(new BMessage(MSG_SEARCH));
break;
default:
BWindow::MessageReceived(msg);
break;
}
}
void FindWindow::DispatchMessage(BMessage *message, BHandler *handler)
_SendMessage();
break;
default:
BWindow::MessageReceived(msg);
break;
}
}
void
FindWindow::DispatchMessage(BMessage *message, BHandler *handler)
{
int8 key;
if ( message->what == B_KEY_DOWN ) {
status_t result;
result= message->FindInt8("byte", 0, &key);
if (result== B_OK){
if (key== B_ESCAPE){
message-> MakeEmpty();
message-> what= B_QUIT_REQUESTED;
if (message->what == B_KEY_DOWN) {
int8 key;
if (message->FindInt8("byte", 0, &key) == B_OK) {
if (key == B_ESCAPE) {
message->MakeEmpty();
message->what = B_QUIT_REQUESTED;
}
}
}
BWindow::DispatchMessage(message,handler);
BWindow::DispatchMessage(message, handler);
}
void FindWindow::ExtractToMsg(BMessage *message){
int32 caseBoxState;
int32 wrapBoxState;
int32 backBoxState;
caseBoxState= fCaseSensBox-> Value();
wrapBoxState= fWrapBox-> Value();
backBoxState= fBackSearchBox-> Value();
bool caseSens;
bool wrapIt;
bool backSearch;
if(caseBoxState== B_CONTROL_ON)
caseSens=true;
else
caseSens= false;
if(wrapBoxState== B_CONTROL_ON)
wrapIt= true;
else
wrapIt= false;
if(backBoxState== B_CONTROL_ON)
backSearch= true;
else
backSearch= false;
//Add the string
message->AddString("findtext",fSearchString->Text());
//Add searchparameters from checkboxes
message->AddBool("casesens", caseSens);
message->AddBool("wrap", wrapIt);
message->AddBool("backsearch", backSearch);
fHandler->Looper()->PostMessage(message,fHandler);
delete(message);
void
FindWindow::_SendMessage()
{
BMessage message(MSG_SEARCH);
// Add the string
message.AddString("findtext", fSearchString->Text());
// Add searchparameters from checkboxes
message.AddBool("casesens", fCaseSensBox->Value() == B_CONTROL_ON);
message.AddBool("wrap", fWrapBox->Value() == B_CONTROL_ON);
message.AddBool("backsearch", fBackSearchBox->Value() == B_CONTROL_ON);
fHandler->Looper()->PostMessage(&message, fHandler);
PostMessage(B_QUIT_REQUESTED);
}

View File

@ -1,28 +1,46 @@
/*
* Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Mattias Sundblad
* Andrew Bachmann
*/
#ifndef FIND_WINDOW_H
#define FIND_WINDOW_H
#include <Window.h>
class BButton;
class BCheckBox;
class BTextControl;
class BView;
class FindWindow : public BWindow {
public:
FindWindow(BRect frame, BHandler* handler, BString *searchString, bool *caseState, bool *wrapState, bool *backState);
virtual void MessageReceived(BMessage* message);
virtual void DispatchMessage(BMessage* message, BHandler* handler);
FindWindow(BRect frame, BHandler* handler, BString *searchString,
bool *caseState, bool *wrapState, bool *backState);
virtual void MessageReceived(BMessage* message);
virtual void DispatchMessage(BMessage* message, BHandler* handler);
private:
void ExtractToMsg(BMessage *message);
BView *fFindView;
BTextControl *fSearchString;
BCheckBox *fCaseSensBox;
BCheckBox *fWrapBox;
BCheckBox *fBackSearchBox;
BButton *fCancelButton;
BButton *fSearchButton;
BHandler *fHandler;
void _SendMessage();
BView *fFindView;
BTextControl *fSearchString;
BCheckBox *fCaseSensBox;
BCheckBox *fWrapBox;
BCheckBox *fBackSearchBox;
BButton *fCancelButton;
BButton *fSearchButton;
BHandler *fHandler;
};
#endif
#endif // FIND_WINDOW_H

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 <CheckBox.h>
#include <String.h>
#include <TextControl.h>
#include <Window.h>
#include "Constants.h"
#include "ReplaceWindow.h"
ReplaceWindow::ReplaceWindow(BRect frame, BHandler *_handler, BString *searchString,
BString *replaceString, bool *caseState, bool *wrapState, bool *backState)
@ -15,177 +24,140 @@ ReplaceWindow::ReplaceWindow(BRect frame, BHandler *_handler, BString *searchStr
B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS,
B_CURRENT_WORKSPACE)
{
fReplaceView = new BBox(Bounds(), "ReplaceView", B_FOLLOW_ALL, B_WILL_DRAW, B_PLAIN_BORDER);
fReplaceView = new BView(Bounds(), "ReplaceView", B_FOLLOW_ALL, B_WILL_DRAW);
fReplaceView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(fReplaceView);
char *findLabel = "Find:";
char* findLabel = "Find:";
float findWidth = fReplaceView->StringWidth(findLabel);
fReplaceView->AddChild(fSearchString= new BTextControl(BRect(5,10,290,50), "", findLabel,NULL, NULL,
B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE));
fReplaceView->AddChild(fSearchString = new BTextControl(BRect(5, 10, 290, 50), "",
findLabel, NULL, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE));
char * replaceWithLabel = "Replace with:";
char* replaceWithLabel = "Replace with:";
float replaceWithWidth = fReplaceView->StringWidth(replaceWithLabel);
fReplaceView->AddChild(fReplaceString=new BTextControl(BRect(5,35,290,50), "", replaceWithLabel,NULL,
NULL,B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE));
fReplaceView->AddChild(fReplaceString = new BTextControl(BRect(5, 35, 290, 50), "",
replaceWithLabel, NULL, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE));
float maxWidth = (replaceWithWidth > findWidth ? replaceWithWidth : findWidth) + 1;
fSearchString->SetDivider(maxWidth);
fReplaceString->SetDivider(maxWidth);
fReplaceView->AddChild(fCaseSensBox=new BCheckBox(BRect(maxWidth+8,60,290,52),"","Case-sensitive", NULL,
B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE));
fReplaceView->AddChild(fWrapBox=new BCheckBox(BRect(maxWidth+8,80,290,70),"","Wrap-around search", NULL,
B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE));
fReplaceView->AddChild(fBackSearchBox=new BCheckBox(BRect(maxWidth+8,100,290,95),"","Search backwards", NULL,
B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE));
fReplaceView->AddChild(fAllWindowsBox=new BCheckBox(BRect(maxWidth+8,120,290,95),"","Replace in all windows",
new BMessage(CHANGE_WINDOW) ,B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE));
fUichange=false;
//vertical separator at 110 in StyledEdit
fReplaceView->AddChild(fReplaceAllButton=new BButton(BRect(10,150,98,166),"","Replace All",new BMessage(MSG_REPLACE_ALL),
B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE));
fReplaceView->AddChild(fCancelButton=new BButton(BRect(141,150,211,166),"","Cancel",new BMessage(B_QUIT_REQUESTED),
B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE));
fReplaceView->AddChild(fReplaceButton=new BButton(BRect(221,150,291,166),"","Replace",new BMessage(MSG_REPLACE),
B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE));
fReplaceView->AddChild(fCaseSensBox = new BCheckBox(BRect(maxWidth + 8, 60, 290, 52),
"", "Case-sensitive", NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE));
fReplaceView->AddChild(fWrapBox = new BCheckBox(BRect(maxWidth + 8, 80, 290, 70),
"", "Wrap-around search", NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE));
fReplaceView->AddChild(fBackSearchBox = new BCheckBox(BRect(maxWidth + 8, 100, 290, 95),
"", "Search backwards", NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE));
fReplaceView->AddChild(fAllWindowsBox = new BCheckBox(BRect(maxWidth + 8, 120, 290, 95),
"", "Replace in all windows", new BMessage(CHANGE_WINDOW),
B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE));
fUIchange = false;
fReplaceView->AddChild(fReplaceAllButton = new BButton(BRect(10, 150, 98, 166),
"", "Replace All", new BMessage(MSG_REPLACE_ALL), B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE));
fReplaceView->AddChild(fCancelButton = new BButton(BRect(141, 150, 211, 166),
"", "Cancel", new BMessage(B_QUIT_REQUESTED), B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE));
fReplaceView->AddChild(fReplaceButton = new BButton(BRect(221, 150, 291, 166),
"", "Replace", new BMessage(MSG_REPLACE), B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE));
fReplaceButton->MakeDefault(true);
fHandler= _handler;
const char *searchtext= searchString->String();
const char *replacetext= replaceString->String();
fHandler = _handler;
const char *searchtext = searchString->String();
const char *replacetext = replaceString->String();
fSearchString->SetText(searchtext);
fReplaceString->SetText(replacetext);
fSearchString-> MakeFocus(true); //021021
if(*caseState== true)
fCaseSensBox->SetValue(B_CONTROL_ON);
else
fCaseSensBox->SetValue(B_CONTROL_OFF);
if(*wrapState== true)
fWrapBox->SetValue(B_CONTROL_ON);
else
fWrapBox->SetValue(B_CONTROL_OFF);
if(*backState== true)
fBackSearchBox->SetValue(B_CONTROL_ON);
else
fBackSearchBox->SetValue(B_CONTROL_OFF);
Show();
fSearchString->MakeFocus(true);
fCaseSensBox->SetValue(*caseState ? B_CONTROL_ON : B_CONTROL_OFF);
fWrapBox->SetValue(*wrapState ? B_CONTROL_ON : B_CONTROL_OFF);
fBackSearchBox->SetValue(*backState ? B_CONTROL_ON : B_CONTROL_OFF);
}
void ReplaceWindow::MessageReceived(BMessage *msg){
switch(msg->what){
case B_QUIT_REQUESTED:
Quit();
break;
void
ReplaceWindow::MessageReceived(BMessage *msg)
{
switch (msg->what){
case MSG_REPLACE:
ExtractToMsg(new BMessage(MSG_REPLACE));
break;
_SendMessage(MSG_REPLACE);
break;
case CHANGE_WINDOW:
ChangeUi();
break;
_ChangeUI();
break;
case MSG_REPLACE_ALL:
ExtractToMsg(new BMessage(MSG_REPLACE_ALL));
break;
default:
BWindow::MessageReceived(msg);
break;
_SendMessage(MSG_REPLACE_ALL);
break;
default:
BWindow::MessageReceived(msg);
break;
}
}
void ReplaceWindow::ChangeUi(){
if(!fUichange){
void
ReplaceWindow::_ChangeUI()
{
if (!fUIchange) {
fReplaceAllButton->MakeDefault(true);
fReplaceButton->SetEnabled(false);
fWrapBox->SetValue(B_CONTROL_ON);
fWrapBox->SetEnabled(false);
fBackSearchBox->SetEnabled(false);
fUichange=true;
}
else{
fUIchange = true;
} else {
fReplaceButton->MakeDefault(true);
fReplaceButton->SetEnabled(true);
fReplaceAllButton->SetEnabled(true);
fWrapBox->SetValue(B_CONTROL_OFF);
fWrapBox->SetEnabled(true);
fBackSearchBox->SetEnabled(true);
fUichange=false;
}
}/***ReplaceWindow::ChangeUi()***/
void ReplaceWindow::DispatchMessage(BMessage *message, BHandler *fHandler){
int8 key;
if ( message->what == B_KEY_DOWN ) {
status_t result;
result= message-> FindInt8("byte", 0, &key);
if (result== B_OK) {
if(key== B_ESCAPE){
message-> MakeEmpty();
message-> what= B_QUIT_REQUESTED;
fUIchange = false;
}
}
void
ReplaceWindow::DispatchMessage(BMessage *message, BHandler *handler)
{
if (message->what == B_KEY_DOWN) {
int8 key;
if (message->FindInt8("byte", 0, &key) == B_OK) {
if (key == B_ESCAPE) {
message->MakeEmpty();
message->what = B_QUIT_REQUESTED;
}
}
}
BWindow::DispatchMessage(message,fHandler);
BWindow::DispatchMessage(message, handler);
}
void ReplaceWindow::ExtractToMsg(BMessage *message ){
int32 caseBoxState;
int32 wrapBoxState;
int32 backBoxState;
int32 allWinBoxState;
caseBoxState= fCaseSensBox-> Value();
wrapBoxState= fWrapBox-> Value();
backBoxState= fBackSearchBox-> Value();
allWinBoxState= fAllWindowsBox-> Value();
bool caseSens;
bool wrapIt;
bool backSearch;
bool allWindows;
if(caseBoxState== B_CONTROL_ON)
caseSens= true;
else
caseSens= false;
if(wrapBoxState== B_CONTROL_ON)
wrapIt= true;
else
wrapIt= false;
if(backBoxState== B_CONTROL_ON)
backSearch= true;
else
backSearch= false;
if(allWinBoxState== B_CONTROL_ON)
allWindows= true;
else
allWindows= false;
message->AddString("FindText",fSearchString->Text());
message->AddString("ReplaceText",fReplaceString->Text());
message->AddBool("casesens", caseSens);
message->AddBool("wrap", wrapIt);
message->AddBool("backsearch", backSearch);
message->AddBool("allwindows", allWindows);
fHandler->Looper()->PostMessage(message,fHandler);
delete(message);
void
ReplaceWindow::_SendMessage(uint32 what)
{
BMessage message(what);
// Add the strings
message.AddString("FindText", fSearchString->Text());
message.AddString("ReplaceText", fReplaceString->Text());
// Add searchparameters from checkboxes
message.AddBool("casesens", fCaseSensBox->Value() == B_CONTROL_ON);
message.AddBool("wrap", fWrapBox->Value() == B_CONTROL_ON);
message.AddBool("backsearch", fBackSearchBox->Value() == B_CONTROL_ON);
message.AddBool("allwindows", fAllWindowsBox->Value() == B_CONTROL_ON);
fHandler->Looper()->PostMessage(&message, fHandler);
PostMessage(B_QUIT_REQUESTED);
}

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
#define REPLACE_WINDOW_H
#include <Window.h>
#include <Rect.h>
#include <Handler.h>
@ -11,31 +20,31 @@
#include <CheckBox.h>
#include <Button.h>
class ReplaceWindow : public BWindow {
public:
ReplaceWindow(BRect frame, BHandler *_handler,BString *searchString,
BString *replaceString, bool *caseState, bool *wrapState, bool *backState);
virtual void MessageReceived(BMessage* message);
virtual void DispatchMessage(BMessage* message, BHandler *handler);
ReplaceWindow(BRect frame, BHandler *_handler,BString *searchString,
BString *replaceString, bool *caseState, bool *wrapState, bool *backState);
virtual void MessageReceived(BMessage* message);
virtual void DispatchMessage(BMessage* message, BHandler *handler);
private:
void ExtractToMsg(BMessage *message);
void ChangeUi();
BView *fReplaceView;
BTextControl *fSearchString;
BTextControl *fReplaceString;
BCheckBox *fCaseSensBox;
BCheckBox *fWrapBox;
BCheckBox *fBackSearchBox;
BCheckBox *fAllWindowsBox;
BButton *fReplaceButton;
BButton *fReplaceAllButton;
BButton *fCancelButton;
BHandler *fHandler;
bool fUichange;
void _SendMessage(uint32 what);
void _ChangeUI();
BView *fReplaceView;
BTextControl *fSearchString;
BTextControl *fReplaceString;
BCheckBox *fCaseSensBox;
BCheckBox *fWrapBox;
BCheckBox *fBackSearchBox;
BCheckBox *fAllWindowsBox;
BButton *fReplaceButton;
BButton *fReplaceAllButton;
BButton *fCancelButton;
BHandler *fHandler;
bool fUIchange;
};
#endif
#endif // REPLACE_WINDOW_H

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 <Autolock.h>
@ -14,47 +23,56 @@
using namespace BPrivate;
BRect windowRect(7-15,26-15,507,426);
StyledEditApp * styled_edit_app;
BRect gWindowRect(7-15, 26-15, 507, 426);
void cascade() {
void
cascade()
{
BScreen screen(NULL);
BRect screenBorder = screen.Frame();
float left = windowRect.left + 15;
if (left + windowRect.Width() > screenBorder.right) {
float left = gWindowRect.left + 15;
if (left + gWindowRect.Width() > screenBorder.right)
left = 7;
}
float top = windowRect.top + 15;
if (top + windowRect.Height() > screenBorder.bottom) {
float top = gWindowRect.top + 15;
if (top + gWindowRect.Height() > screenBorder.bottom)
top = 26;
}
windowRect.OffsetTo(BPoint(left,top));
gWindowRect.OffsetTo(BPoint(left,top));
}
void uncascade() {
void
uncascade()
{
BScreen screen(NULL);
BRect screenBorder = screen.Frame();
float left = windowRect.left - 15;
float left = gWindowRect.left - 15;
if (left < 7) {
left = screenBorder.right - windowRect.Width() - 7;
left = screenBorder.right - gWindowRect.Width() - 7;
left = left - ((int)left % 15) + 7;
}
float top = windowRect.top - 15;
float top = gWindowRect.top - 15;
if (top < 26) {
top = screenBorder.bottom - windowRect.Height() - 26;
top = screenBorder.bottom - gWindowRect.Height() - 26;
top = top - ((int)left % 15) + 26;
}
windowRect.OffsetTo(BPoint(left,top));
gWindowRect.OffsetTo(BPoint(left,top));
}
StyledEditApp * styled_edit_app;
StyledEditApp::StyledEditApp()
: BApplication(APP_SIGNATURE)
{
fOpenPanel= new BFilePanel();
BMenuBar * menuBar =
dynamic_cast<BMenuBar*>(fOpenPanel->Window()->FindView("MenuBar"));
dynamic_cast<BMenuBar*>(fOpenPanel->Window()->FindView("MenuBar"));
fOpenAsEncoding = 0;
fOpenPanelEncodingMenu= new BMenu("Encoding");
menuBar->AddItem(fOpenPanelEncodingMenu);
@ -64,92 +82,96 @@ StyledEditApp::StyledEditApp()
BCharacterSet charset;
while (roster.GetNextCharacterSet(&charset) == B_NO_ERROR) {
BString name(charset.GetPrintName());
const char * mime = charset.GetMIMEName();
const char* mime = charset.GetMIMEName();
if (mime) {
name.Append(" (");
name.Append(mime);
name.Append(")");
}
BMenuItem * item = new BMenuItem(name.String(),new BMessage(OPEN_AS_ENCODING));
BMenuItem* item = new BMenuItem(name.String(), new BMessage(OPEN_AS_ENCODING));
item->SetTarget(this);
fOpenPanelEncodingMenu->AddItem(item);
if (charset.GetFontID() == fOpenAsEncoding) {
if (charset.GetFontID() == fOpenAsEncoding)
item->SetMarked(true);
}
}
fWindowCount= 0;
fNext_Untitled_Window= 1;
styled_edit_app = this;
} /***StyledEditApp::StyledEditApp()***/
void StyledEditApp::DispatchMessage(BMessage *msg, BHandler *handler)
fWindowCount = 0;
fNextUntitledWindow = 1;
styled_edit_app = this;
}
void
StyledEditApp::DispatchMessage(BMessage *msg, BHandler *handler)
{
if ( msg->what == B_ARGV_RECEIVED ) {
if (msg->what == B_ARGV_RECEIVED) {
int32 argc;
if (msg->FindInt32("argc",&argc) != B_OK) {
argc=0;
}
const char ** argv = new const char*[argc];
for (int arg = 0; (arg < argc) ; arg++) {
if (msg->FindString("argv",arg,&argv[arg]) != B_OK) {
if (msg->FindInt32("argc", &argc) != B_OK)
argc = 0;
const char** argv = new const char*[argc];
for (int arg = 0; arg < argc; arg++) {
if (msg->FindString("argv", arg, &argv[arg]) != B_OK) {
argv[arg] = "";
}
}
const char * cwd;
if (msg->FindString("cwd",&cwd) != B_OK) {
const char* cwd;
if (msg->FindString("cwd", &cwd) != B_OK)
cwd = "";
}
ArgvReceived(argc, argv, cwd);
} else {
BApplication::DispatchMessage(msg,handler);
}
} else
BApplication::DispatchMessage(msg, handler);
}
void
StyledEditApp::MessageReceived(BMessage *message)
{
switch(message->what) {
switch (message->what) {
case MENU_NEW:
OpenDocument();
break;
break;
case MENU_OPEN:
fOpenPanel->Show(); //
break;
fOpenPanel->Show();
break;
case B_SILENT_RELAUNCH:
OpenDocument();
break;
break;
case OPEN_AS_ENCODING:
void * ptr;
if (message->FindPointer("source",&ptr) == B_OK) {
if (fOpenPanelEncodingMenu != 0) {
fOpenAsEncoding = (uint32)fOpenPanelEncodingMenu->IndexOf((BMenuItem*)ptr);
}
void* ptr;
if (message->FindPointer("source", &ptr) == B_OK
&& fOpenPanelEncodingMenu != 0) {
fOpenAsEncoding = (uint32)fOpenPanelEncodingMenu->IndexOf((BMenuItem*)ptr);
}
break;
break;
default:
BApplication::MessageReceived(message);
break;
break;
}
}
void
StyledEditApp::OpenDocument()
{
cascade();
new StyledEditWindow(windowRect,fNext_Untitled_Window++,fOpenAsEncoding);
new StyledEditWindow(gWindowRect, fNextUntitledWindow++, fOpenAsEncoding);
fWindowCount++;
}
void
StyledEditApp::OpenDocument(entry_ref * ref)
StyledEditApp::OpenDocument(entry_ref* ref)
{
cascade();
new StyledEditWindow(windowRect,ref,fOpenAsEncoding);
new StyledEditWindow(gWindowRect, ref, fOpenAsEncoding);
fWindowCount++;
}
void
StyledEditApp::CloseDocument()
{
@ -161,75 +183,71 @@ StyledEditApp::CloseDocument()
}
}
void
StyledEditApp::RefsReceived(BMessage *message)
{
int32 refNum;
entry_ref ref;
status_t err;
refNum = 0;
do {
err = message->FindRef("refs", refNum, &ref);
if (err != B_OK)
return;
int32 index = 0;
entry_ref ref;
while (message->FindRef("refs", index++, &ref) == B_OK) {
OpenDocument(&ref);
refNum++;
} while (true);
} /***StyledEditApp::RefsReceived();***/
}
}
void
StyledEditApp::ArgvReceived(int32 argc, const char *argv[], const char * cwd)
StyledEditApp::ArgvReceived(int32 argc, const char* argv[], const char* cwd)
{
for (int i = 1 ; (i < argc) ; i++) {
BPath path;
if (argv[i][0] == '/') {
if (argv[i][0] == '/')
path.SetTo(argv[i]);
} else {
path.SetTo(cwd,argv[i]);
}
else
path.SetTo(cwd, argv[i]);
if (path.InitCheck() != B_OK) {
printf("path.InitCheck failed: \"");
if (argv[i][0] == '/') {
printf("%s",argv[i]);
} else {
printf("%s/%s",cwd,argv[i]);
}
printf("\".\n");
fprintf(stderr, "Setting path failed: \"");
if (argv[i][0] == '/')
fprintf(stderr, "%s\".\n", argv[i]);
else
fprintf(stderr, "%s/%s\".\n", cwd, argv[i]);
continue;
}
entry_ref ref;
if (get_ref_for_path(path.Path(), &ref) != B_OK) {
printf("get_ref_for_path failed: \"");
printf("%s",path.Path());
printf("\".\n");
fprintf(stderr, "Entry not found: \"%s\".\n", path.Path());
continue;
}
OpenDocument(&ref);
}
}
void
StyledEditApp::ReadyToRun()
{
if (fWindowCount == 0) {
if (fWindowCount == 0)
OpenDocument();
}
}
int32
StyledEditApp::NumberOfWindows()
{
return fWindowCount;
}/***StyledEditApp::NumberOfWindows()***/
}
// #pragma mark -
int
main()
main(int argc, char** argv)
{
StyledEditApp styledEdit;
StyledEditApp styledEdit;
styledEdit.Run();
return 0;
}

View File

@ -1,39 +1,46 @@
/**StyledEdit: Application class*/
/*
* Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Mattias Sundblad
* Andrew Bachmann
*/
#ifndef STYLED_EDIT_APP
#define STYLED_EDIT_APP
#include <Application.h>
#include <Message.h>
#include <FilePanel.h>
class StyledEditWindow;
class StyledEditApp
: public BApplication
{
public:
StyledEditApp();
virtual void MessageReceived(BMessage *message);
void ArgvReceived(int32 argc, const char *argv[], const char * cwd);
virtual void RefsReceived(BMessage *message);
virtual void ReadyToRun();
class StyledEditApp : public BApplication {
public:
StyledEditApp();
virtual void MessageReceived(BMessage *message);
void ArgvReceived(int32 argc, const char *argv[], const char * cwd);
virtual void RefsReceived(BMessage *message);
virtual void ReadyToRun();
virtual void DispatchMessage(BMessage *an_event, BHandler *handler);
virtual void DispatchMessage(BMessage *an_event, BHandler *handler);
int32 NumberOfWindows();
void OpenDocument();
void OpenDocument(entry_ref * ref);
void CloseDocument();
private:
BFilePanel *fOpenPanel;
BMenu *fOpenPanelEncodingMenu;
uint32 fOpenAsEncoding;
int32 fWindowCount;
int32 fNext_Untitled_Window;
int32 NumberOfWindows();
void OpenDocument();
void OpenDocument(entry_ref * ref);
void CloseDocument();
private:
BFilePanel* fOpenPanel;
BMenu* fOpenPanelEncodingMenu;
uint32 fOpenAsEncoding;
int32 fWindowCount;
int32 fNextUntitledWindow;
};
extern StyledEditApp * styled_edit_app;
extern StyledEditApp* styled_edit_app;
#endif // STYLED_EDIT_APP
#endif // STYLED_EDIT_APP

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 <Messenger.h>
#include <Rect.h>
@ -10,38 +23,39 @@
#include <CharacterSetRoster.h>
#include <UTF8.h>
#include "StyledEditView.h"
#include "Constants.h"
using namespace BPrivate;
StyledEditView::StyledEditView(BRect viewFrame, BRect textBounds, BHandler *handler)
: BTextView(viewFrame, "textview", textBounds,
B_FOLLOW_ALL, B_FRAME_EVENTS|B_WILL_DRAW)
B_FOLLOW_ALL, B_FRAME_EVENTS|B_WILL_DRAW)
{
fHandler= handler;
fMessenger= new BMessenger(handler);
fHandler = handler;
fMessenger = new BMessenger(handler);
fSuppressChanges = false;
fEncoding = 0;
}
StyledEditView::~StyledEditView()
{
delete fMessenger;
}
void
StyledEditView::FrameResized(float width, float height)
{
BTextView::FrameResized(width, height);
if (DoesWordWrap()) {
BRect textRect;
textRect = Bounds();
textRect.OffsetTo(B_ORIGIN);
textRect.InsetBy(TEXT_INSET,TEXT_INSET);
textRect.InsetBy(TEXT_INSET, TEXT_INSET);
SetTextRect(textRect);
}
/* // I tried to do some sort of intelligent resize thing but it just doesn't work
// so we revert to the R5 stylededit yucky practice of setting the text rect to
// some crazy large number when word wrap is turned off :-(
@ -60,126 +74,129 @@ StyledEditView::FrameResized(float width, float height)
*/
}
status_t
StyledEditView::GetStyledText(BPositionIO * stream)
StyledEditView::GetStyledText(BPositionIO* stream)
{
status_t result = B_OK;
fSuppressChanges = true;
result = BTranslationUtils::GetStyledText(stream, this, NULL);
status_t result = BTranslationUtils::GetStyledText(stream, this, NULL);
fSuppressChanges = false;
if (result != B_OK) {
return result;
}
BNode * node = dynamic_cast<BNode*>(stream);
if (node != 0) {
if (result != B_OK)
return result;
BNode* node = dynamic_cast<BNode*>(stream);
if (node != NULL) {
ssize_t bytesRead;
// decode encoding
int32 encoding;
bytesRead = node->ReadAttr("be:encoding",0,0,&encoding,sizeof(encoding));
if (bytesRead > 0) {
bytesRead = node->ReadAttr("be:encoding", 0, 0, &encoding, sizeof(encoding));
if (bytesRead == (ssize_t)sizeof(encoding)) {
if (encoding == 65535) {
fEncoding = 0;
} else {
const BCharacterSet * cs = BCharacterSetRoster::GetCharacterSetByConversionID(encoding);
if (cs != 0) {
fEncoding = cs->GetFontID();
}
const BCharacterSet* characterSet
= BCharacterSetRoster::GetCharacterSetByConversionID(encoding);
if (characterSet != 0)
fEncoding = characterSet->GetFontID();
}
}
// restore alignment
alignment align;
bytesRead = node->ReadAttr("alignment",0,0,&align,sizeof(align));
if (bytesRead > 0) {
bytesRead = node->ReadAttr("alignment", 0, 0, &align, sizeof(align));
if (bytesRead == (ssize_t)sizeof(align))
SetAlignment(align);
}
// restore wrapping
bool wrap;
bytesRead = node->ReadAttr("wrap",0,0,&wrap,sizeof(wrap));
if (bytesRead > 0) {
bytesRead = node->ReadAttr("wrap", 0, 0, &wrap, sizeof(wrap));
if (bytesRead == (ssize_t)sizeof(wrap)) {
SetWordWrap(wrap);
if (wrap == false) {
BRect textRect;
textRect = Bounds();
textRect.OffsetTo(B_ORIGIN);
textRect.InsetBy(TEXT_INSET,TEXT_INSET);
textRect.InsetBy(TEXT_INSET, TEXT_INSET);
// the width comes from stylededit R5. TODO: find a better way
textRect.SetRightBottom(BPoint(1500.0,textRect.RightBottom().y));
textRect.SetRightBottom(BPoint(1500.0, textRect.RightBottom().y));
SetTextRect(textRect);
}
}
}
if (fEncoding != 0) {
int32 length = stream->Seek(0,SEEK_END);
int32 length = stream->Seek(0, SEEK_END);
// Here we save the run_array before it gets overwritten...
text_run_array * run_array = RunArray(0,length);
text_run_array* runArray = RunArray(0, length);
uint32 id = BCharacterSetRoster::GetCharacterSetByFontID(fEncoding)->GetConversionID();
fSuppressChanges = true;
SetText("");
fSuppressChanges = false;
char inBuffer[32768];
off_t location = 0;
int32 textOffset = 0;
int32 state = 0;
int32 bytesRead;
while ((bytesRead = stream->ReadAt(location,inBuffer,32768)) > 0) {
char * inPtr = inBuffer;
while ((bytesRead = stream->ReadAt(location, inBuffer, sizeof(inBuffer))) > 0) {
char* inPtr = inBuffer;
char textBuffer[32768];
int32 textLength = 32768;
int32 textLength = sizeof(textBuffer);
int32 bytes = bytesRead;
while ((textLength > 0) && (bytes > 0)) {
result = convert_to_utf8(id,inPtr,&bytes,textBuffer,&textLength,&state);
if (result != B_OK) {
while (textLength > 0 && bytes > 0) {
result = convert_to_utf8(id, inPtr, &bytes, textBuffer, &textLength, &state);
if (result != B_OK)
return result;
}
fSuppressChanges = true;
InsertText(textBuffer,textLength,textOffset);
InsertText(textBuffer, textLength, textOffset);
fSuppressChanges = false;
textOffset += textLength;
inPtr += bytes;
location += bytes;
bytesRead -= bytes;
bytes = bytesRead;
if (textLength > 0) {
textLength = 32768;
}
if (textLength > 0)
textLength = sizeof(textBuffer);
}
}
// ... and here we restore it
SetRunArray(0,length,run_array);
free(run_array);
SetRunArray(0, length, runArray);
free(runArray);
}
return result;
}
status_t
StyledEditView::WriteStyledEditFile(BFile * file)
StyledEditView::WriteStyledEditFile(BFile* file)
{
status_t result = B_OK;
ssize_t bytes = 0;
result = BTranslationUtils::WriteStyledEditFile(this,file);
if (result != B_OK) {
result = BTranslationUtils::WriteStyledEditFile(this, file);
if (result != B_OK)
return result;
}
if (fEncoding == 0) {
int32 encoding = 65535;
bytes = file->WriteAttr("be:encoding",B_INT32_TYPE,0,&encoding,sizeof(encoding));
bytes = file->WriteAttr("be:encoding", B_INT32_TYPE, 0, &encoding, sizeof(encoding));
if (bytes < 0)
return bytes;
} else {
result = file->SetSize(0);
if (result != B_OK) {
if (result != B_OK)
return result;
}
bytes = file->Seek(0, SEEK_SET);
if (bytes != 0) {
if (bytes != 0)
return bytes;
}
const BCharacterSet * cs = BCharacterSetRoster::GetCharacterSetByFontID(fEncoding);
const BCharacterSet* cs = BCharacterSetRoster::GetCharacterSetByFontID(fEncoding);
if (cs != 0) {
uint32 id = cs->GetConversionID();
const char * outText = Text();
@ -199,23 +216,26 @@ StyledEditView::WriteStyledEditFile(BFile * file)
sourceLength -= length;
outText += length;
}
bytes = file->WriteAttr("be:encoding",B_INT32_TYPE,0,&id,sizeof(id));
bytes = file->WriteAttr("be:encoding", B_INT32_TYPE, 0, &id, sizeof(id));
if (bytes < 0)
return bytes;
}
}
}
alignment align = Alignment();
bytes = file->WriteAttr("alignment",B_INT32_TYPE,0,&align,sizeof(align));
bytes = file->WriteAttr("alignment", B_INT32_TYPE, 0, &align, sizeof(align));
if (bytes < 0)
return bytes;
bool wrap = DoesWordWrap();
bytes = file->WriteAttr("wrap",B_BOOL_TYPE,0,&wrap,sizeof(wrap));
bytes = file->WriteAttr("wrap", B_BOOL_TYPE, 0, &wrap, sizeof(wrap));
if (bytes < 0)
return bytes;
return result;
}
void
StyledEditView::Reset()
{
@ -224,47 +244,48 @@ StyledEditView::Reset()
fSuppressChanges = false;
}
void
StyledEditView::Select(int32 start, int32 finish)
{
if(start==finish)
fChangeMessage= new BMessage(DISABLE_ITEMS);
else
fChangeMessage= new BMessage(ENABLE_ITEMS);
fChangeMessage = new BMessage(start == finish ? DISABLE_ITEMS : ENABLE_ITEMS);
fMessenger->SendMessage(fChangeMessage);
BTextView::Select(start, finish);
}
void
StyledEditView::SetEncoding(uint32 encoding)
{
fEncoding = encoding;
}
uint32
StyledEditView::GetEncoding() const
{
return fEncoding;
}
void
StyledEditView::InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs)
StyledEditView::InsertText(const char *text, int32 length, int32 offset,
const text_run_array *runs)
{
if (!fSuppressChanges)
fMessenger-> SendMessage(new BMessage(TEXT_CHANGED));
BTextView::InsertText(text, length, offset, runs);
}/****StyledEditView::InsertText()***/
fMessenger->SendMessage(new BMessage(TEXT_CHANGED));
BTextView::InsertText(text, length, offset, runs);
}
void
StyledEditView::DeleteText(int32 start, int32 finish)
{
if (!fSuppressChanges)
fMessenger-> SendMessage(new BMessage(TEXT_CHANGED));
BTextView::DeleteText(start, finish);
}/***StyledEditView::DeleteText***/
BTextView::DeleteText(start, finish);
}

View File

@ -1,34 +1,45 @@
/*
* Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Mattias Sundblad
* Andrew Bachmann
*/
#ifndef STYLED_EDIT_VIEW_H
#define STYLED_EDIT_VIEW_H
#include <File.h>
#include <TextView.h>
#include <DataIO.h>
class StyledEditView : public BTextView {
public:
StyledEditView(BRect viewframe, BRect textframe, BHandler *handler);
virtual ~StyledEditView();
virtual void Select(int32 start, int32 finish);
virtual void FrameResized(float width, float height);
class StyledEditView : public BTextView {
public:
StyledEditView(BRect viewframe, BRect textframe, BHandler *handler);
virtual ~StyledEditView();
virtual void Select(int32 start, int32 finish);
virtual void FrameResized(float width, float height);
virtual void Reset();
virtual status_t GetStyledText(BPositionIO * stream);
virtual status_t WriteStyledEditFile(BFile * file);
virtual void Reset();
virtual status_t GetStyledText(BPositionIO * stream);
virtual status_t WriteStyledEditFile(BFile * file);
virtual void SetEncoding(uint32 encoding);
virtual uint32 GetEncoding() const;
protected:
virtual void InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs = NULL);
virtual void DeleteText(int32 start, int32 finish);
virtual void SetEncoding(uint32 encoding);
virtual uint32 GetEncoding() const;
protected:
virtual void InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs = NULL);
virtual void DeleteText(int32 start, int32 finish);
private:
BHandler *fHandler;
BMessage *fChangeMessage;
BMessenger *fMessenger;
bool fSuppressChanges;
uint32 fEncoding;
private:
BHandler *fHandler;
BMessage *fChangeMessage;
BMessenger *fMessenger;
bool fSuppressChanges;
uint32 fEncoding;
};
#endif // STYLED_EDIT_VIEW_H
#endif // STYLED_EDIT_VIEW_H

File diff suppressed because it is too large Load Diff

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
#define STYLED_EDIT_WINDOW_H
#include <FilePanel.h>
#include <MenuBar.h>
#include <Message.h>
@ -9,97 +18,96 @@
#include <TextView.h>
#include <Window.h>
class StyledEditView;
class StyledEditWindow
: public BWindow
{
public:
StyledEditWindow(BRect frame, int32 id, uint32 encoding = 0);
StyledEditWindow(BRect frame, entry_ref *ref, uint32 encoding = 0);
virtual ~StyledEditWindow();
class StyledEditWindow : public BWindow {
public:
StyledEditWindow(BRect frame, int32 id, uint32 encoding = 0);
StyledEditWindow(BRect frame, entry_ref *ref, uint32 encoding = 0);
virtual ~StyledEditWindow();
virtual void Quit();
virtual bool QuitRequested();
virtual void MessageReceived(BMessage *message);
virtual void MenusBeginning();
status_t Save(BMessage *message = 0);
status_t SaveAs(BMessage *message = 0);
void OpenFile(entry_ref *ref);
status_t PageSetup(const char *documentname);
void Print(const char *documentname);
void SearchAllWindows(BString find, BString replace, bool casesens);
virtual void Quit();
virtual bool QuitRequested();
virtual void MessageReceived(BMessage *message);
virtual void MenusBeginning();
private:
void InitWindow(uint32 encoding = 0);
bool Search(BString searchfor, bool casesens, bool wrap, bool backsearch);
void FindSelection();
bool Replace(BString findthis, BString replacewith, bool casesens, bool wrap, bool backsearch);
void ReplaceAll(BString find, BString replace, bool casesens);
void SetFontSize(float fontSize);
void SetFontColor(const rgb_color *color);
void SetFontStyle(const char *fontFamily, const char *fontStyle);
void RevertToSaved();
BMenuBar *fMenuBar;
BMessage *fPrintSettings;
BMessage *fSaveMessage;
BMenu *fRecentMenu;
BMenu *fFontMenu;
BMenu *fFontSizeMenu;
BMenu *fFontColorMenu;
BMenuItem *fCurrentFontItem;
BMenuItem *fSaveItem;
BMenuItem *fRevertItem;
BMenuItem *fUndoItem;
BMenuItem *fCutItem;
BMenuItem *fCopyItem;
BMenuItem *fClearItem;
BMenuItem *fFindAgainItem;
BMenuItem *fReplaceSameItem;
BMenuItem *fBlackItem;
BMenuItem *fRedItem;
BMenuItem *fGreenItem;
BMenuItem *fBlueItem;
BMenuItem *fCyanItem;
BMenuItem *fMagentaItem;
BMenuItem *fYellowItem;
BMenuItem *fWrapItem;
BMenuItem *fAlignLeft;
BMenuItem *fAlignCenter;
BMenuItem *fAlignRight;
BString fStringToFind;
BString fReplaceString;
// undo modes
bool fUndoFlag; // we just did an undo action
bool fCanUndo; // we can do an undo action next
bool fRedoFlag; // we just did a redo action
bool fCanRedo; // we can do a redo action next
// clean modes
bool fUndoCleans; // an undo action will put us in a clean state
bool fRedoCleans; // a redo action will put us in a clean state
bool fClean; // we are in a clean state
bool fCaseSens;
bool fWrapAround;
bool fBackSearch;
StyledEditView *fTextView;
BScrollView *fScrollView;
BFilePanel *fSavePanel;
BMenu *fSavePanelEncodingMenu;
status_t Save(BMessage *message = 0);
status_t SaveAs(BMessage *message = 0);
void OpenFile(entry_ref *ref);
status_t PageSetup(const char *documentname);
void Print(const char *documentname);
void SearchAllWindows(BString find, BString replace, bool casesens);
private:
void InitWindow(uint32 encoding = 0);
bool Search(BString searchfor, bool casesens, bool wrap, bool backsearch);
void FindSelection();
bool Replace(BString findthis, BString replacewith, bool casesens, bool wrap, bool backsearch);
void ReplaceAll(BString find, BString replace, bool casesens);
void SetFontSize(float fontSize);
void SetFontColor(const rgb_color *color);
void SetFontStyle(const char *fontFamily, const char *fontStyle);
status_t _LoadFile(entry_ref* ref);
void RevertToSaved();
BMenuBar *fMenuBar;
BMessage *fPrintSettings;
BMessage *fSaveMessage;
BMenu *fRecentMenu;
BMenu *fFontMenu;
BMenu *fFontSizeMenu;
BMenu *fFontColorMenu;
BMenuItem *fCurrentFontItem;
BMenuItem *fSaveItem;
BMenuItem *fRevertItem;
BMenuItem *fUndoItem;
BMenuItem *fCutItem;
BMenuItem *fCopyItem;
BMenuItem *fClearItem;
BMenuItem *fFindAgainItem;
BMenuItem *fReplaceSameItem;
BMenuItem *fBlackItem;
BMenuItem *fRedItem;
BMenuItem *fGreenItem;
BMenuItem *fBlueItem;
BMenuItem *fCyanItem;
BMenuItem *fMagentaItem;
BMenuItem *fYellowItem;
BMenuItem *fWrapItem;
BMenuItem *fAlignLeft;
BMenuItem *fAlignCenter;
BMenuItem *fAlignRight;
BString fStringToFind;
BString fReplaceString;
// undo modes
bool fUndoFlag; // we just did an undo action
bool fCanUndo; // we can do an undo action next
bool fRedoFlag; // we just did a redo action
bool fCanRedo; // we can do a redo action next
// clean modes
bool fUndoCleans; // an undo action will put us in a clean state
bool fRedoCleans; // a redo action will put us in a clean state
bool fClean; // we are in a clean state
bool fCaseSens;
bool fWrapAround;
bool fBackSearch;
StyledEditView *fTextView;
BScrollView *fScrollView;
BFilePanel *fSavePanel;
BMenu *fSavePanelEncodingMenu;
};
#endif // STYLED_EDIT_WINDOW_H
#endif // STYLED_EDIT_WINDOW_H