* 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,20 +1,29 @@
#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){
: BMenuItem(label, message, 0, 0)
{
fItemColor = color;
}
void ColorMenuItem::DrawContent(){
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
#endif // COLOR_MENU_ITEM_H

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
#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*/
// Messages for menu commands
// file menu
const uint32 MENU_NEW = 'MFnw';
const uint32 MENU_OPEN = 'MFop';
const uint32 MENU_SAVE = 'MSav';
@ -20,6 +30,7 @@ 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';
@ -31,6 +42,7 @@ 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';
@ -38,7 +50,6 @@ const uint32 FONT_STYLE ='FSch';
const uint32 FONT_COLOR = 'Fcol';
// fontcolors
//red, green, blue, alphachannel
const rgb_color BLACK = {0, 0, 0, 255};
const rgb_color RED = {255, 0, 0, 255};
const rgb_color GREEN = {0, 255, 0, 255};

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 <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);
@ -34,15 +42,21 @@ FindWindow::FindWindow(BRect frame, BHandler *_handler, BString *searchString,
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));
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(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)));
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;
@ -50,98 +64,64 @@ FindWindow::FindWindow(BRect frame, BHandler *_handler, BString *searchString,
const char *text = searchString->String();
fSearchString->SetText(text);
fSearchString-> MakeFocus(true); //021021
fSearchString->MakeFocus(true);
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();
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){
void
FindWindow::MessageReceived(BMessage *msg)
{
switch (msg->what) {
case B_QUIT_REQUESTED:
Quit();
break;
case MSG_SEARCH:
ExtractToMsg(new BMessage(MSG_SEARCH));
_SendMessage();
break;
default:
BWindow::MessageReceived(msg);
break;
}
}
void FindWindow::DispatchMessage(BMessage *message, BHandler *handler)
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){
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);
}
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;
void
FindWindow::_SendMessage()
{
BMessage message(MSG_SEARCH);
// Add the string
message->AddString("findtext",fSearchString->Text());
message.AddString("findtext", fSearchString->Text());
// Add searchparameters from checkboxes
message->AddBool("casesens", caseSens);
message->AddBool("wrap", wrapIt);
message->AddBool("backsearch", backSearch);
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);
fHandler->Looper()->PostMessage(message,fHandler);
delete(message);
PostMessage(B_QUIT_REQUESTED);
}

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
#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);
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);
void _SendMessage();
BView *fFindView;
BTextControl *fSearchString;
@ -20,9 +38,9 @@ class FindWindow : public BWindow {
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,40 +24,46 @@ 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:";
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:";
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,
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));
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;
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(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;
@ -58,134 +73,91 @@ ReplaceWindow::ReplaceWindow(BRect frame, BHandler *_handler, BString *searchStr
fSearchString->SetText(searchtext);
fReplaceString->SetText(replacetext);
fSearchString-> MakeFocus(true); //021021
fSearchString->MakeFocus(true);
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();
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){
void
ReplaceWindow::MessageReceived(BMessage *msg)
{
switch (msg->what){
case B_QUIT_REQUESTED:
Quit();
break;
case MSG_REPLACE:
ExtractToMsg(new BMessage(MSG_REPLACE));
_SendMessage(MSG_REPLACE);
break;
case CHANGE_WINDOW:
ChangeUi();
_ChangeUI();
break;
case MSG_REPLACE_ALL:
ExtractToMsg(new BMessage(MSG_REPLACE_ALL));
_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;
fUIchange = false;
}
}
}/***ReplaceWindow::ChangeUi()***/
void ReplaceWindow::DispatchMessage(BMessage *message, BHandler *fHandler){
int8 key;
void
ReplaceWindow::DispatchMessage(BMessage *message, BHandler *handler)
{
if (message->what == B_KEY_DOWN) {
status_t result;
result= message-> FindInt8("byte", 0, &key);
if (result== B_OK) {
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;
void
ReplaceWindow::_SendMessage(uint32 what)
{
BMessage message(what);
caseBoxState= fCaseSensBox-> Value();
wrapBoxState= fWrapBox-> Value();
backBoxState= fBackSearchBox-> Value();
allWinBoxState= fAllWindowsBox-> Value();
// Add the strings
message.AddString("FindText", fSearchString->Text());
message.AddString("ReplaceText", fReplaceString->Text());
bool caseSens;
bool wrapIt;
bool backSearch;
bool allWindows;
// 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);
if(caseBoxState== B_CONTROL_ON)
caseSens= true;
else
caseSens= false;
fHandler->Looper()->PostMessage(&message, fHandler);
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);
}

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,6 +20,7 @@
#include <CheckBox.h>
#include <Button.h>
class ReplaceWindow : public BWindow {
public:
ReplaceWindow(BRect frame, BHandler *_handler,BString *searchString,
@ -19,10 +29,10 @@ class ReplaceWindow : public BWindow {
virtual void MessageReceived(BMessage* message);
virtual void DispatchMessage(BMessage* message, BHandler *handler);
private:
void ExtractToMsg(BMessage *message);
void ChangeUi();
void _SendMessage(uint32 what);
void _ChangeUI();
BView *fReplaceView;
BTextControl *fSearchString;
BTextControl *fReplaceString;
@ -34,8 +44,7 @@ class ReplaceWindow : public BWindow {
BButton *fReplaceAllButton;
BButton *fCancelButton;
BHandler *fHandler;
bool fUichange;
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,39 +23,48 @@
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)
@ -73,38 +91,39 @@ StyledEditApp::StyledEditApp()
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()***/
fNextUntitledWindow = 1;
void StyledEditApp::DispatchMessage(BMessage *msg, BHandler *handler)
styled_edit_app = this;
}
void
StyledEditApp::DispatchMessage(BMessage *msg, BHandler *handler)
{
if (msg->what == B_ARGV_RECEIVED) {
int32 argc;
if (msg->FindInt32("argc",&argc) != 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++) {
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) {
if (msg->FindString("cwd", &cwd) != B_OK)
cwd = "";
}
ArgvReceived(argc, argv, cwd);
} else {
} else
BApplication::DispatchMessage(msg, handler);
}
}
void
@ -115,41 +134,44 @@ StyledEditApp::MessageReceived(BMessage *message)
OpenDocument();
break;
case MENU_OPEN:
fOpenPanel->Show(); //
fOpenPanel->Show();
break;
case B_SILENT_RELAUNCH:
OpenDocument();
break;
case OPEN_AS_ENCODING:
void* ptr;
if (message->FindPointer("source",&ptr) == B_OK) {
if (fOpenPanelEncodingMenu != 0) {
if (message->FindPointer("source", &ptr) == B_OK
&& fOpenPanelEncodingMenu != 0) {
fOpenAsEncoding = (uint32)fOpenPanelEncodingMenu->IndexOf((BMenuItem*)ptr);
}
}
break;
default:
BApplication::MessageReceived(message);
break;
}
}
void
StyledEditApp::OpenDocument()
{
cascade();
new StyledEditWindow(windowRect,fNext_Untitled_Window++,fOpenAsEncoding);
new StyledEditWindow(gWindowRect, fNextUntitledWindow++, fOpenAsEncoding);
fWindowCount++;
}
void
StyledEditApp::OpenDocument(entry_ref* ref)
{
cascade();
new StyledEditWindow(windowRect,ref,fOpenAsEncoding);
new StyledEditWindow(gWindowRect, ref, fOpenAsEncoding);
fWindowCount++;
}
void
StyledEditApp::CloseDocument()
{
@ -161,73 +183,69 @@ StyledEditApp::CloseDocument()
}
}
void
StyledEditApp::RefsReceived(BMessage *message)
{
int32 refNum;
int32 index = 0;
entry_ref ref;
status_t err;
refNum = 0;
do {
err = message->FindRef("refs", refNum, &ref);
if (err != B_OK)
return;
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)
{
for (int i = 1 ; (i < argc) ; i++) {
BPath path;
if (argv[i][0] == '/') {
if (argv[i][0] == '/')
path.SetTo(argv[i]);
} else {
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;
styledEdit.Run();

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
#define STYLED_EDIT_APP
#include <Application.h>
#include <Message.h>
#include <FilePanel.h>
class StyledEditWindow;
class StyledEditApp
: public BApplication
{
class StyledEditApp : public BApplication {
public:
StyledEditApp();
virtual void MessageReceived(BMessage *message);
@ -30,7 +37,7 @@ private:
BMenu* fOpenPanelEncodingMenu;
uint32 fOpenAsEncoding;
int32 fWindowCount;
int32 fNext_Untitled_Window;
int32 fNextUntitledWindow;
};

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,11 +23,9 @@
#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)
@ -25,11 +36,13 @@ StyledEditView::StyledEditView(BRect viewFrame, BRect textBounds, BHandler *hand
fEncoding = 0;
}
StyledEditView::~StyledEditView()
{
delete fMessenger;
}
void
StyledEditView::FrameResized(float width, float height)
{
@ -42,6 +55,7 @@ StyledEditView::FrameResized(float width, float height)
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,45 +74,44 @@ StyledEditView::FrameResized(float width, float height)
*/
}
status_t
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) {
if (result != B_OK)
return result;
}
BNode* node = dynamic_cast<BNode*>(stream);
if (node != 0) {
if (node != NULL) {
ssize_t bytesRead;
// decode encoding
int32 encoding;
bytesRead = node->ReadAttr("be:encoding", 0, 0, &encoding, sizeof(encoding));
if (bytesRead > 0) {
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) {
if (bytesRead == (ssize_t)sizeof(align))
SetAlignment(align);
}
// restore wrapping
bool wrap;
bytesRead = node->ReadAttr("wrap", 0, 0, &wrap, sizeof(wrap));
if (bytesRead > 0) {
if (bytesRead == (ssize_t)sizeof(wrap)) {
SetWordWrap(wrap);
if (wrap == false) {
BRect textRect;
@ -111,30 +124,33 @@ StyledEditView::GetStyledText(BPositionIO * stream)
}
}
}
if (fEncoding != 0) {
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) {
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)) {
while (textLength > 0 && bytes > 0) {
result = convert_to_utf8(id, inPtr, &bytes, textBuffer, &textLength, &state);
if (result != B_OK) {
if (result != B_OK)
return result;
}
fSuppressChanges = true;
InsertText(textBuffer, textLength, textOffset);
fSuppressChanges = false;
@ -143,28 +159,29 @@ StyledEditView::GetStyledText(BPositionIO * stream)
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)
{
status_t result = B_OK;
ssize_t bytes = 0;
result = BTranslationUtils::WriteStyledEditFile(this, file);
if (result != B_OK) {
if (result != B_OK)
return result;
}
if (fEncoding == 0) {
int32 encoding = 65535;
bytes = file->WriteAttr("be:encoding", B_INT32_TYPE, 0, &encoding, sizeof(encoding));
@ -172,13 +189,13 @@ StyledEditView::WriteStyledEditFile(BFile * file)
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);
if (cs != 0) {
uint32 id = cs->GetConversionID();
@ -209,13 +226,16 @@ StyledEditView::WriteStyledEditFile(BFile * file)
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));
if (bytes < 0)
return bytes;
return result;
}
void
StyledEditView::Reset()
{
@ -224,40 +244,41 @@ 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()***/
void
StyledEditView::DeleteText(int32 start, int32 finish)
@ -266,5 +287,5 @@ StyledEditView::DeleteText(int32 start, int32 finish)
fMessenger-> SendMessage(new BMessage(TEXT_CHANGED));
BTextView::DeleteText(start, finish);
}
}/***StyledEditView::DeleteText***/

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
#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);
@ -19,6 +29,7 @@ public:
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);

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,11 +18,10 @@
#include <TextView.h>
#include <Window.h>
class StyledEditView;
class StyledEditWindow
: public BWindow
{
class StyledEditWindow : public BWindow {
public:
StyledEditWindow(BRect frame, int32 id, uint32 encoding = 0);
StyledEditWindow(BRect frame, entry_ref *ref, uint32 encoding = 0);
@ -40,6 +48,7 @@ private:
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;
@ -99,7 +108,6 @@ private:
BFilePanel *fSavePanel;
BMenu *fSavePanelEncodingMenu;
};
#endif // STYLED_EDIT_WINDOW_H