style cleanup ; undo, revert, redo, save, quit functions fixed up ; no more extra windows ; quit when all windows are closed ; fix grey lines when scrolling

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1848 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
shatty 2002-11-05 09:24:25 +00:00
parent 96462df1ad
commit ed48868f63
7 changed files with 778 additions and 816 deletions

View File

@ -2,13 +2,8 @@
#ifndef CONSTANTS_H
#define CONSTANTS_H
#ifndef _GRAPHICS_DEFS_H
#include <GraphicsDefs.h>
#endif
#ifndef _SUPPORT_DEFS_H
#include <SupportDefs.h>
#endif
//See if this takes care of some problems with closing the application
//by clicking the windowtab
@ -17,7 +12,6 @@
//seems to work, 021021
#define APP_SIGNATURE "application/x-vnd.obos.styled-edit"
const float MENU_BAR_HEIGHT= 19.0;
const float TEXT_INSET= 3.0;
/*Messages for window registry with application*/
@ -73,8 +67,4 @@ const uint32 DISABLE_ITEMS ='DIit';
const uint32 CHANGE_WINDOW ='CHwi';
const uint32 TEXT_CHANGED ='TEch';
#endif
#endif // CONSTANTS_H

View File

@ -1,88 +1,102 @@
#ifndef CONSTANTS_H
#include <Autolock.h>
#include "Constants.h"
#endif
#ifndef STYLED_EDIT_APP
#include "StyledEditApp.h"
#endif
#include "StyledEditWindow.h"
BRect windowRect(7,25,599,399);
BRect windowRect(50,50,599,399);
StyledEditApp * styled_edit_app;
StyledEditApp::StyledEditApp()
: BApplication(APP_SIGNATURE)
{
new StyledEditWindow(windowRect);
{
fOpenPanel= new BFilePanel;
fWindowCount= 0;
fNext_Untitled_Window= 1;
} /***StyledEditApp::StyledEditApp()***/
styled_edit_app = this;
} /***StyledEditApp::StyledEditApp()***/
void StyledEditApp::MessageReceived(BMessage *message){
switch(message->what){
void
StyledEditApp::MessageReceived(BMessage *message)
{
switch(message->what) {
case MENU_NEW:
OpenDocument();
break;
case MENU_OPEN:
fOpenPanel->Show(); //
break;
case WINDOW_REGISTRY_ADD:
{
bool need_id= false;
BMessage reply(WINDOW_REGISTRY_ADDED);
if(message->FindBool("need_id", &need_id)== B_OK)
{
if(need_id)
{
reply.AddInt32("new_window_number", fNext_Untitled_Window);
fNext_Untitled_Window++;
}
fWindowCount++;
}
reply.AddRect("rect",windowRect);
windowRect.OffsetBy(20,20);
message->SendReply(&reply);
break;
}
case WINDOW_REGISTRY_SUB:
fWindowCount--;
if (!fWindowCount)
{
Quit();
}
break;
default:
BApplication::MessageReceived(message);
break;
}
}
void StyledEditApp::RefsReceived(BMessage *message){
void
StyledEditApp::OpenDocument()
{
new StyledEditWindow(windowRect,fNext_Untitled_Window++);
windowRect.OffsetBy(20,20); // todo: wrap around screen
fWindowCount++;
}
void
StyledEditApp::OpenDocument(entry_ref * ref)
{
new StyledEditWindow(windowRect,ref);
windowRect.OffsetBy(20,20); // todo: wrap around screen
fWindowCount++;
}
void
StyledEditApp::CloseDocument()
{
fWindowCount--;
if (fWindowCount == 0) {
BAutolock lock(this);
Quit();
}
}
void
StyledEditApp::RefsReceived(BMessage *message)
{
int32 refNum;
entry_ref ref;
status_t err;
refNum=0;
do{
do {
if((err= message->FindRef("refs", refNum, &ref)) != B_OK)
return;
new StyledEditWindow(windowRect, &ref);
OpenDocument(&ref);
refNum++;
} while(1);
} /***StyledEditApp::RefsReceived();***/
int32 StyledEditApp::NumberOfWindows(){
void
StyledEditApp::ReadyToRun()
{
if (fWindowCount == 0) {
OpenDocument();
}
}
int32
StyledEditApp::NumberOfWindows()
{
return fWindowCount;
}/***StyledEditApp::NumberOfWindows()***/
int main(){
StyledEditApp StyledEdit;
StyledEdit.Run();
int
main()
{
StyledEditApp styledEdit;
styledEdit.Run();
return 0;
}
}

View File

@ -2,31 +2,33 @@
#ifndef STYLED_EDIT_APP
#define STYLED_EDIT_APP
#ifndef _APPLICATION_H
#include <Application.h>
#endif
#include <Message.h>
#include <FilePanel.h>
#ifndef STYLED_EDIT_WINDOW_H
#include "StyledEditWindow.h"
#endif
class StyledEditWindow;
class StyledEditApp: public BApplication{
public:
StyledEditApp();
virtual void MessageReceived(BMessage *message);
virtual void RefsReceived(BMessage *message);
int32 NumberOfWindows();
private:
BFilePanel *fOpenPanel;
int32 fWindowCount;
int32 fNext_Untitled_Window;
class StyledEditApp
: public BApplication
{
public:
StyledEditApp();
virtual void MessageReceived(BMessage *message);
virtual void RefsReceived(BMessage *message);
virtual void ReadyToRun();
int32 NumberOfWindows();
void OpenDocument();
void OpenDocument(entry_ref * ref);
void CloseDocument();
private:
BFilePanel *fOpenPanel;
int32 fWindowCount;
int32 fNext_Untitled_Window;
};
#endif
extern StyledEditApp * styled_edit_app;
#endif // STYLED_EDIT_APP

View File

@ -1,36 +1,27 @@
#ifndef STYLED_EDIT_VIEW_H
#include "StyledEditView.h"
#endif
#ifndef _MESSAGE_H
#include <Message.h>
#endif
#ifndef CONSTANTS_H
#include "Constants.h"
#endif
#ifndef _MESSENGER_H
#include <Messenger.h>
#endif
#ifndef _RECT_H
#include <Rect.h>
#endif
#include <TranslationUtils.h>
#include "StyledEditView.h"
#include "Constants.h"
StyledEditView::StyledEditView(BRect viewFrame, BRect textBounds, BHandler *handler)
: BTextView(viewFrame, "textview", textBounds,
B_FOLLOW_ALL, B_FRAME_EVENTS|B_WILL_DRAW)
{
fHandler= handler;
fMessenger= new BMessenger(handler);
fSuppressChanges = false;
}/***StyledEditView()***/
StyledEditView::StyledEditView(BRect viewFrame, BRect textBounds, BHandler *handler) : BTextView(viewFrame, "textview",
textBounds, B_FOLLOW_ALL, B_FRAME_EVENTS|B_WILL_DRAW){
fHandler= handler;
fMessenger= new BMessenger(handler);
}/***StyledEditView()***/
StyledEditView::~StyledEditView(){
StyledEditView::~StyledEditView(){
}/***~StyledEditView***/
}/***~StyledEditView***/
void StyledEditView::FrameResized(float width, float height){
void
StyledEditView::FrameResized(float width, float height)
{
BTextView::FrameResized(width, height);
if(DoesWordWrap()){
@ -42,8 +33,27 @@ void StyledEditView::FrameResized(float width, float height){
}
}
void StyledEditView::Select(int32 start, int32 finish){
status_t
StyledEditView::GetStyledText(BPositionIO * stream)
{
status_t result = B_OK;
fSuppressChanges = true;
result = BTranslationUtils::GetStyledText(stream, this, NULL);
fSuppressChanges = false;
return result;
}
void
StyledEditView::Reset()
{
fSuppressChanges = true;
SetText("");
fSuppressChanges = false;
}
void
StyledEditView::Select(int32 start, int32 finish)
{
if(start==finish)
fChangeMessage= new BMessage(DISABLE_ITEMS);
else
@ -54,40 +64,20 @@ void StyledEditView::Select(int32 start, int32 finish){
BTextView::Select(start, finish);
}
void StyledEditView::InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs){
fMessenger-> SendMessage(new BMessage(TEXT_CHANGED));
void 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){
fMessenger-> SendMessage(new BMessage(TEXT_CHANGED));
void StyledEditView::DeleteText(int32 start, int32 finish)
{
if (!fSuppressChanges)
fMessenger-> SendMessage(new BMessage(TEXT_CHANGED));
BTextView::DeleteText(start, finish);
}/***StyledEditView::DeleteText***/

View File

@ -1,34 +1,28 @@
#ifndef STYLED_EDIT_VIEW_H
#define STYLED_EDIT_VIEW_H
#ifndef _TEXTVIEW_H
#include <TextView.h>
#endif
#include <DataIO.h>
class StyledEditView : public BTextView {
public:
StyledEditView(BRect viewframe, BRect textframe, BHandler *handler);
~StyledEditView();
public:
StyledEditView(BRect viewframe, BRect textframe, BHandler *handler);
~StyledEditView();
virtual void Select(int32 start, int32 finish);
virtual void FrameResized(float width, float height);
virtual void Select(int32 start, int32 finish);
virtual void FrameResized(float width, float height);
protected:
virtual void InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs);
virtual void DeleteText(int32 start, int32 finish);
private:
BHandler *fHandler;
BMessage *fChangeMessage;
BMessenger *fMessenger;
virtual void Reset();
virtual status_t GetStyledText(BPositionIO * stream);
protected:
virtual void InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs);
virtual void DeleteText(int32 start, int32 finish);
private:
BHandler *fHandler;
BMessage *fChangeMessage;
BMessenger *fMessenger;
bool fSuppressChanges;
};
#endif
#endif // STYLED_EDIT_VIEW_H

File diff suppressed because it is too large Load Diff

View File

@ -1,94 +1,77 @@
#ifndef STYLED_EDIT_WINDOW_H
#define STYLED_EDIT_WINDOW_H
#ifndef _FILE_PANEL_H
#include <FilePanel.h>
#endif
#ifndef _MENUBAR_H
#include <MenuBar.h>
#endif
#ifndef _MESSAGE_H
#include <Message.h>
#endif
#ifndef _RECT_H
#include <Rect.h>
#endif
#ifndef _STRING_H
#include <String.h>
#endif
#ifndef _TEXTVIEW_H
#include <TextView.h>
#endif
#ifndef _WINDOW_H
#include <Window.h>
#endif
#ifndef STYLED_EDIT_VIEW_H
#include "StyledEditView.h"
#endif
class StyledEditView;
class StyledEditWindow: public BWindow{
public:
StyledEditWindow(BRect frame);
StyledEditWindow(BRect frame, entry_ref *ref);
~StyledEditWindow();
virtual bool QuitRequested();
virtual void MessageReceived(BMessage *message);
status_t Save(BMessage *message);
void OpenFile(entry_ref *ref);
status_t PageSetup(const char *documentname);
void Print(const char *documentname);
void SearchAllWindows(BString find, BString replace, bool casesens);
class StyledEditWindow
: public BWindow
{
public:
StyledEditWindow(BRect frame, int32 id);
StyledEditWindow(BRect frame, entry_ref *ref);
~StyledEditWindow();
private:
void InitWindow();
void Register(bool need_id);
void Unregister(void);
bool Search(BString searchfor, bool casesens, bool wrap, bool backsearch);
void FindSelection();
void 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(rgb_color *color);
void SetFontStyle(const char *fontFamily, const char *fontStyle);
void RevertToSaved();
BMenuBar *fMenuBar;
BMessage *fPrintSettings;
BMessage *fSaveMessage;
BMenuItem *fSaveItem;
BMenuItem *fRevertItem;
BMenuItem *fUndoItem;
BMenuItem *fCutItem;
BMenuItem *fCopyItem;
BMenuItem *fClearItem;
BMenuItem *fWrapItem;
BString fStringToFind;
BString fReplaceString;
bool fEnableItems;
bool fFirstEdit;
bool fTextSaved;
bool fUnDoneFlag;
bool fCaseSens;
bool fWrapAround;
bool fBackSearch;
StyledEditView *fTextView;
BScrollView *fScrollView;
BFilePanel *fSavePanel;
int32 fWindow_Id;
virtual void Quit();
virtual bool QuitRequested();
virtual void MessageReceived(BMessage *message);
status_t Save(BMessage *message);
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();
bool Search(BString searchfor, bool casesens, bool wrap, bool backsearch);
void FindSelection();
void 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(rgb_color *color);
void SetFontStyle(const char *fontFamily, const char *fontStyle);
void RevertToSaved();
BMenuBar *fMenuBar;
BMessage *fPrintSettings;
BMessage *fSaveMessage;
BMenuItem *fSaveItem;
BMenuItem *fRevertItem;
BMenuItem *fUndoItem;
BMenuItem *fCutItem;
BMenuItem *fCopyItem;
BMenuItem *fClearItem;
BMenuItem *fWrapItem;
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;
};
#endif
#endif // STYLED_EDIT_WINDOW_H