* 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
+24 -15
View File
@@ -1,21 +1,30 @@
#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)
:BMenuItem(label, message,0,0){ ColorMenuItem::ColorMenuItem(const char *label, rgb_color color, BMessage *message)
fItemColor= color; : BMenuItem(label, message, 0, 0)
{
fItemColor = color;
} }
void ColorMenuItem::DrawContent(){
void
BMenu *menu= Menu(); ColorMenuItem::DrawContent()
rgb_color menuColor = menu->HighColor(); {
menu->SetHighColor(fItemColor); BMenu *menu = Menu();
BMenuItem::DrawContent(); rgb_color menuColor = menu->HighColor();
menu->SetHighColor(menuColor);
menu->SetHighColor(fItemColor);
BMenuItem::DrawContent();
menu->SetHighColor(menuColor);
} }
+21 -7
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:
virtual void DrawContent(); protected:
private: virtual void DrawContent();
rgb_color fItemColor;
private:
}; rgb_color fItemColor;
#endif };
#endif // COLOR_MENU_ITEM_H
+54 -43
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 #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*/
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';
const uint32 MSG_SEARCH ='msea'; // file menu
const uint32 MSG_REPLACE ='msre'; const uint32 MENU_NEW = 'MFnw';
const uint32 MSG_REPLACE_ALL ='mrea'; const uint32 MENU_OPEN = 'MFop';
//"Font"-menu const uint32 MENU_SAVE = 'MSav';
const uint32 FONT_SIZE ='FMsi'; const uint32 MENU_SAVEAS = 'MEsa';
const uint32 FONT_FAMILY ='FFch'; const uint32 MENU_REVERT = 'MFre';
const uint32 FONT_STYLE ='FSch'; const uint32 MENU_CLOSE = 'MFcl';
const uint32 FONT_COLOR ='Fcol'; const uint32 MENU_PAGESETUP = 'MFps';
const uint32 MENU_PRINT = 'MFpr';
const uint32 MENU_QUIT = 'MFqu';
//fontcolors // edit menu
//red, green, blue, alphachannel 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 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};
@@ -47,21 +58,21 @@ const rgb_color CYAN = {0, 255, 255, 255};
const rgb_color MAGENTA = {255, 0, 255, 255}; const rgb_color MAGENTA = {255, 0, 255, 255};
const rgb_color YELLOW = {255, 255, 0, 255}; const rgb_color YELLOW = {255, 255, 0, 255};
//"Document"-menu // "Document"-menu
const uint32 ALIGN_LEFT ='ALle'; const uint32 ALIGN_LEFT = 'ALle';
const uint32 ALIGN_CENTER ='ALce'; const uint32 ALIGN_CENTER = 'ALce';
const uint32 ALIGN_RIGHT ='ALri'; const uint32 ALIGN_RIGHT = 'ALri';
const uint32 WRAP_LINES ='MDwr'; const uint32 WRAP_LINES = 'MDwr';
//enables "edit" menuitems // enables "edit" menuitems
const uint32 ENABLE_ITEMS ='ENit'; const uint32 ENABLE_ITEMS = 'ENit';
const uint32 DISABLE_ITEMS ='DIit'; const uint32 DISABLE_ITEMS = 'DIit';
const uint32 CHANGE_WINDOW ='CHwi'; const uint32 CHANGE_WINDOW = 'CHwi';
const uint32 TEXT_CHANGED ='TEch'; const uint32 TEXT_CHANGED = 'TEch';
// file panel constants // file panel constants
const uint32 OPEN_AS_ENCODING ='FPoe'; const uint32 OPEN_AS_ENCODING = 'FPoe';
const uint32 SAVE_AS_ENCODING ='FPse'; const uint32 SAVE_AS_ENCODING = 'FPse';
const uint32 SAVE_THEN_QUIT ='FPsq'; const uint32 SAVE_THEN_QUIT = 'FPsq';
#endif // CONSTANTS_H #endif // CONSTANTS_H
+90 -110
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 <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);
font_height height; font_height height;
fFindView->GetFontHeight(&height); fFindView->GetFontHeight(&height);
float lineHeight = height.ascent+height.descent+height.leading; float lineHeight = height.ascent+height.descent + height.leading;
float findWidth = fFindView->StringWidth("Find:")+6;
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)); float findWidth = fFindView->StringWidth("Find:") + 6;
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)); float searchBottom = 12 + 2 + lineHeight + 2 + 1;
float buttonTop = frame.Height() - 19 - lineHeight;
fFindView->AddChild(fCancelButton= new BButton(BRect(142,buttonTop,212,frame.Height()-7),"","Cancel",new BMessage(B_QUIT_REQUESTED))); float wrapBoxTop = (buttonTop + searchBottom - lineHeight) / 2;
fFindView->AddChild(fSearchButton= new BButton(BRect(221,buttonTop,291,frame.Height()-7),"","Find",new BMessage(MSG_SEARCH))); 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); fSearchButton->MakeDefault(true);
fHandler=_handler; fHandler = _handler;
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){
switch(msg->what){ void
FindWindow::MessageReceived(BMessage *msg)
{
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:
BWindow::MessageReceived(msg);
break;
}
}
void FindWindow::DispatchMessage(BMessage *message, BHandler *handler)
default:
BWindow::MessageReceived(msg);
break;
}
}
void
FindWindow::DispatchMessage(BMessage *message, BHandler *handler)
{ {
int8 key; if (message->what == B_KEY_DOWN) {
int8 key;
if ( message->what == B_KEY_DOWN ) { if (message->FindInt8("byte", 0, &key) == B_OK) {
status_t result; if (key == B_ESCAPE) {
result= message->FindInt8("byte", 0, &key); message->MakeEmpty();
message->what = B_QUIT_REQUESTED;
if (result== 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); void
delete(message); 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); PostMessage(B_QUIT_REQUESTED);
} }
+36 -18
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 #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 DispatchMessage(BMessage* message, BHandler* handler); virtual void MessageReceived(BMessage* message);
virtual void DispatchMessage(BMessage* message, BHandler* handler);
private: private:
void ExtractToMsg(BMessage *message); void _SendMessage();
BView *fFindView; BView *fFindView;
BTextControl *fSearchString; BTextControl *fSearchString;
BCheckBox *fCaseSensBox; BCheckBox *fCaseSensBox;
BCheckBox *fWrapBox; BCheckBox *fWrapBox;
BCheckBox *fBackSearchBox; BCheckBox *fBackSearchBox;
BButton *fCancelButton; BButton *fCancelButton;
BButton *fSearchButton; BButton *fSearchButton;
BHandler *fHandler; BHandler *fHandler;
}; };
#endif
#endif // FIND_WINDOW_H
+111 -139
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,177 +24,140 @@ 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),
B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); "", "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, fReplaceView->AddChild(fWrapBox = new BCheckBox(BRect(maxWidth + 8, 80, 290, 70),
B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); "", "Wrap-around search", NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP,
fReplaceView->AddChild(fBackSearchBox=new BCheckBox(BRect(maxWidth+8,100,290,95),"","Search backwards", NULL, B_WILL_DRAW | B_NAVIGABLE));
B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); fReplaceView->AddChild(fBackSearchBox = new BCheckBox(BRect(maxWidth + 8, 100, 290, 95),
fReplaceView->AddChild(fAllWindowsBox=new BCheckBox(BRect(maxWidth+8,120,290,95),"","Replace in all windows", "", "Search backwards", NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP,
new BMessage(CHANGE_WINDOW) ,B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); B_WILL_DRAW | B_NAVIGABLE));
fUichange=false; fReplaceView->AddChild(fAllWindowsBox = new BCheckBox(BRect(maxWidth + 8, 120, 290, 95),
"", "Replace in all windows", new BMessage(CHANGE_WINDOW),
//vertical separator at 110 in StyledEdit 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), fUIchange = false;
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), fReplaceView->AddChild(fReplaceAllButton = new BButton(BRect(10, 150, 98, 166),
B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); "", "Replace All", new BMessage(MSG_REPLACE_ALL), 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(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); fReplaceButton->MakeDefault(true);
fHandler= _handler; fHandler = _handler;
const char *searchtext= searchString->String(); const char *searchtext = searchString->String();
const char *replacetext= replaceString->String(); const char *replacetext = replaceString->String();
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){
switch(msg->what){ void
case B_QUIT_REQUESTED: ReplaceWindow::MessageReceived(BMessage *msg)
Quit(); {
break; switch (msg->what){
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:
BWindow::MessageReceived(msg); default:
break; BWindow::MessageReceived(msg);
break;
} }
} }
void ReplaceWindow::ChangeUi(){
void
if(!fUichange){ 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 ) { {
status_t result; if (message->what == B_KEY_DOWN) {
result= message-> FindInt8("byte", 0, &key); int8 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 ){
void
int32 caseBoxState; ReplaceWindow::_SendMessage(uint32 what)
int32 wrapBoxState; {
int32 backBoxState; BMessage message(what);
int32 allWinBoxState;
// Add the strings
caseBoxState= fCaseSensBox-> Value(); message.AddString("FindText", fSearchString->Text());
wrapBoxState= fWrapBox-> Value(); message.AddString("ReplaceText", fReplaceString->Text());
backBoxState= fBackSearchBox-> Value();
allWinBoxState= fAllWindowsBox-> Value(); // Add searchparameters from checkboxes
message.AddBool("casesens", fCaseSensBox->Value() == B_CONTROL_ON);
bool caseSens; message.AddBool("wrap", fWrapBox->Value() == B_CONTROL_ON);
bool wrapIt; message.AddBool("backsearch", fBackSearchBox->Value() == B_CONTROL_ON);
bool backSearch; message.AddBool("allwindows", fAllWindowsBox->Value() == B_CONTROL_ON);
bool allWindows;
fHandler->Looper()->PostMessage(&message, fHandler);
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);
PostMessage(B_QUIT_REQUESTED); PostMessage(B_QUIT_REQUESTED);
} }
+32 -23
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,31 +20,31 @@
#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,
BString *replaceString, bool *caseState, bool *wrapState, bool *backState); BString *replaceString, 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(uint32 what);
void ChangeUi(); void _ChangeUI();
BView *fReplaceView;
BTextControl *fSearchString; BView *fReplaceView;
BTextControl *fReplaceString; BTextControl *fSearchString;
BCheckBox *fCaseSensBox; BTextControl *fReplaceString;
BCheckBox *fWrapBox; BCheckBox *fCaseSensBox;
BCheckBox *fBackSearchBox; BCheckBox *fWrapBox;
BCheckBox *fAllWindowsBox; BCheckBox *fBackSearchBox;
BButton *fReplaceButton; BCheckBox *fAllWindowsBox;
BButton *fReplaceAllButton; BButton *fReplaceButton;
BButton *fCancelButton; BButton *fReplaceAllButton;
BHandler *fHandler; BButton *fCancelButton;
bool fUichange; BHandler *fHandler;
bool fUIchange;
}; };
#endif #endif // REPLACE_WINDOW_H
+108 -90
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,47 +23,56 @@
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)
{ {
fOpenPanel= new BFilePanel(); fOpenPanel= new BFilePanel();
BMenuBar * menuBar = BMenuBar * menuBar =
dynamic_cast<BMenuBar*>(fOpenPanel->Window()->FindView("MenuBar")); dynamic_cast<BMenuBar*>(fOpenPanel->Window()->FindView("MenuBar"));
fOpenAsEncoding = 0; fOpenAsEncoding = 0;
fOpenPanelEncodingMenu= new BMenu("Encoding"); fOpenPanelEncodingMenu= new BMenu("Encoding");
menuBar->AddItem(fOpenPanelEncodingMenu); menuBar->AddItem(fOpenPanelEncodingMenu);
@@ -64,92 +82,96 @@ StyledEditApp::StyledEditApp()
BCharacterSet charset; BCharacterSet charset;
while (roster.GetNextCharacterSet(&charset) == B_NO_ERROR) { while (roster.GetNextCharacterSet(&charset) == B_NO_ERROR) {
BString name(charset.GetPrintName()); BString name(charset.GetPrintName());
const char * mime = charset.GetMIMEName(); const char* mime = charset.GetMIMEName();
if (mime) { if (mime) {
name.Append(" ("); name.Append(" (");
name.Append(mime); name.Append(mime);
name.Append(")"); 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); 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;
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; 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
StyledEditApp::MessageReceived(BMessage *message) StyledEditApp::MessageReceived(BMessage *message)
{ {
switch(message->what) { switch (message->what) {
case MENU_NEW: case MENU_NEW:
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,75 +183,71 @@ 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;
while (message->FindRef("refs", index++, &ref) == B_OK) {
refNum = 0;
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();
return 0; return 0;
} }
+31 -24
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 #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:
{ StyledEditApp();
public: virtual void MessageReceived(BMessage *message);
StyledEditApp(); void ArgvReceived(int32 argc, const char *argv[], const char * cwd);
virtual void MessageReceived(BMessage *message); virtual void RefsReceived(BMessage *message);
void ArgvReceived(int32 argc, const char *argv[], const char * cwd); virtual void ReadyToRun();
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(); int32 NumberOfWindows();
void OpenDocument(); void OpenDocument();
void OpenDocument(entry_ref * ref); void OpenDocument(entry_ref * ref);
void CloseDocument(); void CloseDocument();
private: private:
BFilePanel *fOpenPanel; BFilePanel* fOpenPanel;
BMenu *fOpenPanelEncodingMenu; BMenu* fOpenPanelEncodingMenu;
uint32 fOpenAsEncoding; uint32 fOpenAsEncoding;
int32 fWindowCount; int32 fWindowCount;
int32 fNext_Untitled_Window; int32 fNextUntitledWindow;
}; };
extern StyledEditApp * styled_edit_app; extern StyledEditApp* styled_edit_app;
#endif // STYLED_EDIT_APP #endif // STYLED_EDIT_APP
+97 -76
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,38 +23,39 @@
#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)
{ {
fHandler= handler; fHandler = handler;
fMessenger= new BMessenger(handler); fMessenger = new BMessenger(handler);
fSuppressChanges = false; fSuppressChanges = false;
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)
{ {
BTextView::FrameResized(width, height); BTextView::FrameResized(width, height);
if (DoesWordWrap()) { if (DoesWordWrap()) {
BRect textRect; BRect textRect;
textRect = Bounds(); textRect = Bounds();
textRect.OffsetTo(B_ORIGIN); textRect.OffsetTo(B_ORIGIN);
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,126 +74,129 @@ 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) {
return result;
}
BNode * node = dynamic_cast<BNode*>(stream); if (result != B_OK)
if (node != 0) { return result;
BNode* node = dynamic_cast<BNode*>(stream);
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;
textRect = Bounds(); textRect = Bounds();
textRect.OffsetTo(B_ORIGIN); 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 // 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); SetTextRect(textRect);
} }
} }
} }
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;
textOffset += textLength; textOffset += textLength;
inPtr += bytes; inPtr += bytes;
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));
if (bytes < 0) if (bytes < 0)
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();
const char * outText = Text(); const char * outText = Text();
@@ -199,23 +216,26 @@ StyledEditView::WriteStyledEditFile(BFile * file)
sourceLength -= length; sourceLength -= length;
outText += 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) if (bytes < 0)
return bytes; return bytes;
} }
} }
alignment align = Alignment(); 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) 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,47 +244,48 @@ 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)
{ {
if (!fSuppressChanges) if (!fSuppressChanges)
fMessenger-> SendMessage(new BMessage(TEXT_CHANGED)); fMessenger-> SendMessage(new BMessage(TEXT_CHANGED));
BTextView::DeleteText(start, finish);
}/***StyledEditView::DeleteText***/ BTextView::DeleteText(start, finish);
}
+32 -21
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 #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 {
public:
StyledEditView(BRect viewframe, BRect textframe, BHandler *handler);
virtual ~StyledEditView();
virtual void Select(int32 start, int32 finish); class StyledEditView : public BTextView {
virtual void FrameResized(float width, float height); 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 void Reset();
virtual status_t GetStyledText(BPositionIO * stream); virtual status_t GetStyledText(BPositionIO * stream);
virtual status_t WriteStyledEditFile(BFile * file); virtual status_t WriteStyledEditFile(BFile * file);
virtual void SetEncoding(uint32 encoding); virtual void SetEncoding(uint32 encoding);
virtual uint32 GetEncoding() const; virtual uint32 GetEncoding() const;
protected:
virtual void InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs = NULL); protected:
virtual void DeleteText(int32 start, int32 finish); virtual void InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs = NULL);
virtual void DeleteText(int32 start, int32 finish);
private: private:
BHandler *fHandler; BHandler *fHandler;
BMessage *fChangeMessage; BMessage *fChangeMessage;
BMessenger *fMessenger; BMessenger *fMessenger;
bool fSuppressChanges; bool fSuppressChanges;
uint32 fEncoding; uint32 fEncoding;
}; };
#endif // STYLED_EDIT_VIEW_H #endif // STYLED_EDIT_VIEW_H
File diff suppressed because it is too large Load Diff
+96 -88
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,97 +18,96 @@
#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:
{ StyledEditWindow(BRect frame, int32 id, uint32 encoding = 0);
public: StyledEditWindow(BRect frame, entry_ref *ref, uint32 encoding = 0);
StyledEditWindow(BRect frame, int32 id, uint32 encoding = 0); virtual ~StyledEditWindow();
StyledEditWindow(BRect frame, entry_ref *ref, uint32 encoding = 0);
virtual ~StyledEditWindow();
virtual void Quit(); virtual void Quit();
virtual bool QuitRequested(); virtual bool QuitRequested();
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
virtual void MenusBeginning(); 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);
private: status_t Save(BMessage *message = 0);
void InitWindow(uint32 encoding = 0); status_t SaveAs(BMessage *message = 0);
bool Search(BString searchfor, bool casesens, bool wrap, bool backsearch); void OpenFile(entry_ref *ref);
void FindSelection(); status_t PageSetup(const char *documentname);
bool Replace(BString findthis, BString replacewith, bool casesens, bool wrap, bool backsearch); void Print(const char *documentname);
void ReplaceAll(BString find, BString replace, bool casesens); void SearchAllWindows(BString find, BString replace, bool casesens);
void SetFontSize(float fontSize);
void SetFontColor(const rgb_color *color); private:
void SetFontStyle(const char *fontFamily, const char *fontStyle); void InitWindow(uint32 encoding = 0);
void RevertToSaved(); bool Search(BString searchfor, bool casesens, bool wrap, bool backsearch);
void FindSelection();
BMenuBar *fMenuBar; bool Replace(BString findthis, BString replacewith, bool casesens, bool wrap, bool backsearch);
BMessage *fPrintSettings; void ReplaceAll(BString find, BString replace, bool casesens);
BMessage *fSaveMessage; void SetFontSize(float fontSize);
BMenu *fRecentMenu; void SetFontColor(const rgb_color *color);
void SetFontStyle(const char *fontFamily, const char *fontStyle);
BMenu *fFontMenu; status_t _LoadFile(entry_ref* ref);
BMenu *fFontSizeMenu; void RevertToSaved();
BMenu *fFontColorMenu;
BMenuItem *fCurrentFontItem; BMenuBar *fMenuBar;
BMessage *fPrintSettings;
BMenuItem *fSaveItem; BMessage *fSaveMessage;
BMenuItem *fRevertItem; BMenu *fRecentMenu;
BMenuItem *fUndoItem; BMenu *fFontMenu;
BMenuItem *fCutItem; BMenu *fFontSizeMenu;
BMenuItem *fCopyItem; BMenu *fFontColorMenu;
BMenuItem *fClearItem; BMenuItem *fCurrentFontItem;
BMenuItem *fFindAgainItem; BMenuItem *fSaveItem;
BMenuItem *fReplaceSameItem; BMenuItem *fRevertItem;
BMenuItem *fBlackItem; BMenuItem *fUndoItem;
BMenuItem *fRedItem; BMenuItem *fCutItem;
BMenuItem *fGreenItem; BMenuItem *fCopyItem;
BMenuItem *fBlueItem; BMenuItem *fClearItem;
BMenuItem *fCyanItem;
BMenuItem *fMagentaItem; BMenuItem *fFindAgainItem;
BMenuItem *fYellowItem; BMenuItem *fReplaceSameItem;
BMenuItem *fWrapItem; BMenuItem *fBlackItem;
BMenuItem *fAlignLeft; BMenuItem *fRedItem;
BMenuItem *fAlignCenter; BMenuItem *fGreenItem;
BMenuItem *fAlignRight; BMenuItem *fBlueItem;
BMenuItem *fCyanItem;
BString fStringToFind; BMenuItem *fMagentaItem;
BString fReplaceString; BMenuItem *fYellowItem;
// undo modes BMenuItem *fWrapItem;
bool fUndoFlag; // we just did an undo action BMenuItem *fAlignLeft;
bool fCanUndo; // we can do an undo action next BMenuItem *fAlignCenter;
bool fRedoFlag; // we just did a redo action BMenuItem *fAlignRight;
bool fCanRedo; // we can do a redo action next
BString fStringToFind;
// clean modes BString fReplaceString;
bool fUndoCleans; // an undo action will put us in a clean state
bool fRedoCleans; // a redo action will put us in a clean state // undo modes
bool fClean; // we are in a clean state bool fUndoFlag; // we just did an undo action
bool fCanUndo; // we can do an undo action next
bool fCaseSens; bool fRedoFlag; // we just did a redo action
bool fWrapAround; bool fCanRedo; // we can do a redo action next
bool fBackSearch;
// clean modes
StyledEditView *fTextView; bool fUndoCleans; // an undo action will put us in a clean state
BScrollView *fScrollView; bool fRedoCleans; // a redo action will put us in a clean state
bool fClean; // we are in a clean state
BFilePanel *fSavePanel;
BMenu *fSavePanelEncodingMenu; bool fCaseSens;
bool fWrapAround;
bool fBackSearch;
StyledEditView *fTextView;
BScrollView *fScrollView;
BFilePanel *fSavePanel;
BMenu *fSavePanelEncodingMenu;
}; };
#endif // STYLED_EDIT_WINDOW_H #endif // STYLED_EDIT_WINDOW_H