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
+1 -11
View File
@@ -2,13 +2,8 @@
#ifndef CONSTANTS_H #ifndef CONSTANTS_H
#define CONSTANTS_H #define CONSTANTS_H
#ifndef _GRAPHICS_DEFS_H
#include <GraphicsDefs.h> #include <GraphicsDefs.h>
#endif
#ifndef _SUPPORT_DEFS_H
#include <SupportDefs.h> #include <SupportDefs.h>
#endif
//See if this takes care of some problems with closing the application //See if this takes care of some problems with closing the application
//by clicking the windowtab //by clicking the windowtab
@@ -17,7 +12,6 @@
//seems to work, 021021 //seems to work, 021021
#define APP_SIGNATURE "application/x-vnd.obos.styled-edit" #define APP_SIGNATURE "application/x-vnd.obos.styled-edit"
const float MENU_BAR_HEIGHT= 19.0;
const float TEXT_INSET= 3.0; const float TEXT_INSET= 3.0;
/*Messages for window registry with application*/ /*Messages for window registry with application*/
@@ -73,8 +67,4 @@ 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';
#endif // CONSTANTS_H
#endif
+62 -48
View File
@@ -1,88 +1,102 @@
#ifndef CONSTANTS_H #include <Autolock.h>
#include "Constants.h" #include "Constants.h"
#endif
#ifndef STYLED_EDIT_APP
#include "StyledEditApp.h" #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() StyledEditApp::StyledEditApp()
: BApplication(APP_SIGNATURE) : BApplication(APP_SIGNATURE)
{ {
new StyledEditWindow(windowRect);
fOpenPanel= new BFilePanel; fOpenPanel= new BFilePanel;
fWindowCount= 0; fWindowCount= 0;
fNext_Untitled_Window= 1; fNext_Untitled_Window= 1;
} /***StyledEditApp::StyledEditApp()***/ styled_edit_app = this;
} /***StyledEditApp::StyledEditApp()***/
void StyledEditApp::MessageReceived(BMessage *message){ void
switch(message->what){ StyledEditApp::MessageReceived(BMessage *message)
{
switch(message->what) {
case MENU_NEW:
OpenDocument();
break;
case MENU_OPEN: case MENU_OPEN:
fOpenPanel->Show(); // fOpenPanel->Show(); //
break; 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: default:
BApplication::MessageReceived(message); BApplication::MessageReceived(message);
break; 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; int32 refNum;
entry_ref ref; entry_ref ref;
status_t err; status_t err;
refNum=0; refNum=0;
do{ do {
if((err= message->FindRef("refs", refNum, &ref)) != B_OK) if((err= message->FindRef("refs", refNum, &ref)) != B_OK)
return; return;
new StyledEditWindow(windowRect, &ref); OpenDocument(&ref);
refNum++; refNum++;
} while(1); } while(1);
} /***StyledEditApp::RefsReceived();***/ } /***StyledEditApp::RefsReceived();***/
int32 StyledEditApp::NumberOfWindows(){ void
StyledEditApp::ReadyToRun()
{
if (fWindowCount == 0) {
OpenDocument();
}
}
int32
StyledEditApp::NumberOfWindows()
{
return fWindowCount; return fWindowCount;
}/***StyledEditApp::NumberOfWindows()***/ }/***StyledEditApp::NumberOfWindows()***/
int main(){ int
StyledEditApp StyledEdit; main()
StyledEdit.Run(); {
StyledEditApp styledEdit;
styledEdit.Run();
return 0; return 0;
} }
+23 -21
View File
@@ -2,31 +2,33 @@
#ifndef STYLED_EDIT_APP #ifndef STYLED_EDIT_APP
#define STYLED_EDIT_APP #define STYLED_EDIT_APP
#ifndef _APPLICATION_H
#include <Application.h> #include <Application.h>
#endif #include <Message.h>
#include <FilePanel.h>
#ifndef STYLED_EDIT_WINDOW_H class StyledEditWindow;
#include "StyledEditWindow.h"
#endif
class StyledEditApp: public BApplication{ class StyledEditApp
public: : public BApplication
StyledEditApp(); {
virtual void MessageReceived(BMessage *message); public:
virtual void RefsReceived(BMessage *message); StyledEditApp();
int32 NumberOfWindows(); virtual void MessageReceived(BMessage *message);
virtual void RefsReceived(BMessage *message);
virtual void ReadyToRun();
private:
BFilePanel *fOpenPanel; int32 NumberOfWindows();
int32 fWindowCount; void OpenDocument();
int32 fNext_Untitled_Window; 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
+45 -55
View File
@@ -1,36 +1,27 @@
#ifndef STYLED_EDIT_VIEW_H
#include "StyledEditView.h"
#endif
#ifndef _MESSAGE_H
#include <Message.h> #include <Message.h>
#endif
#ifndef CONSTANTS_H
#include "Constants.h"
#endif
#ifndef _MESSENGER_H
#include <Messenger.h> #include <Messenger.h>
#endif
#ifndef _RECT_H
#include <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", StyledEditView::~StyledEditView(){
textBounds, B_FOLLOW_ALL, B_FRAME_EVENTS|B_WILL_DRAW){
fHandler= handler;
fMessenger= new BMessenger(handler);
}/***StyledEditView()***/
StyledEditView::~StyledEditView(){ }/***~StyledEditView***/
}/***~StyledEditView***/
void StyledEditView::FrameResized(float width, float height){ void
StyledEditView::FrameResized(float width, float height)
{
BTextView::FrameResized(width, height); BTextView::FrameResized(width, height);
if(DoesWordWrap()){ 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) if(start==finish)
fChangeMessage= new BMessage(DISABLE_ITEMS); fChangeMessage= new BMessage(DISABLE_ITEMS);
else else
@@ -54,40 +64,20 @@ void StyledEditView::Select(int32 start, int32 finish){
BTextView::Select(start, finish); BTextView::Select(start, finish);
} }
void StyledEditView::InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs){ void StyledEditView::InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs)
{
fMessenger-> SendMessage(new BMessage(TEXT_CHANGED)); if (!fSuppressChanges)
fMessenger-> SendMessage(new BMessage(TEXT_CHANGED));
BTextView::InsertText(text, length, offset, runs); BTextView::InsertText(text, length, offset, runs);
}/****StyledEditView::InsertText()***/ }/****StyledEditView::InsertText()***/
void StyledEditView::DeleteText(int32 start, int32 finish){ void StyledEditView::DeleteText(int32 start, int32 finish)
{
fMessenger-> SendMessage(new BMessage(TEXT_CHANGED)); if (!fSuppressChanges)
fMessenger-> SendMessage(new BMessage(TEXT_CHANGED));
BTextView::DeleteText(start, finish); BTextView::DeleteText(start, finish);
}/***StyledEditView::DeleteText***/ }/***StyledEditView::DeleteText***/
+19 -25
View File
@@ -1,34 +1,28 @@
#ifndef STYLED_EDIT_VIEW_H #ifndef STYLED_EDIT_VIEW_H
#define STYLED_EDIT_VIEW_H #define STYLED_EDIT_VIEW_H
#ifndef _TEXTVIEW_H
#include <TextView.h> #include <TextView.h>
#endif #include <DataIO.h>
class StyledEditView : public BTextView { class StyledEditView : public BTextView {
public: public:
StyledEditView(BRect viewframe, BRect textframe, BHandler *handler); StyledEditView(BRect viewframe, BRect textframe, BHandler *handler);
~StyledEditView(); ~StyledEditView();
virtual void Select(int32 start, int32 finish);
virtual void FrameResized(float width, float height);
virtual void Select(int32 start, int32 finish); virtual void Reset();
virtual void FrameResized(float width, float height); virtual status_t GetStyledText(BPositionIO * stream);
protected: protected:
virtual void InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs); virtual void InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs);
virtual void DeleteText(int32 start, int32 finish); virtual void DeleteText(int32 start, int32 finish);
private: private:
BHandler *fHandler; BHandler *fHandler;
BMessage *fChangeMessage; BMessage *fChangeMessage;
BMessenger *fMessenger; BMessenger *fMessenger;
bool fSuppressChanges;
}; };
#endif
#endif // STYLED_EDIT_VIEW_H
File diff suppressed because it is too large Load Diff
+61 -78
View File
@@ -1,94 +1,77 @@
#ifndef STYLED_EDIT_WINDOW_H #ifndef STYLED_EDIT_WINDOW_H
#define STYLED_EDIT_WINDOW_H #define STYLED_EDIT_WINDOW_H
#ifndef _FILE_PANEL_H
#include <FilePanel.h> #include <FilePanel.h>
#endif
#ifndef _MENUBAR_H
#include <MenuBar.h> #include <MenuBar.h>
#endif
#ifndef _MESSAGE_H
#include <Message.h> #include <Message.h>
#endif
#ifndef _RECT_H
#include <Rect.h> #include <Rect.h>
#endif
#ifndef _STRING_H
#include <String.h> #include <String.h>
#endif
#ifndef _TEXTVIEW_H
#include <TextView.h> #include <TextView.h>
#endif
#ifndef _WINDOW_H
#include <Window.h> #include <Window.h>
#endif
#ifndef STYLED_EDIT_VIEW_H class StyledEditView;
#include "StyledEditView.h"
#endif
class StyledEditWindow
class StyledEditWindow: public BWindow{ : public BWindow
public: {
StyledEditWindow(BRect frame); public:
StyledEditWindow(BRect frame, entry_ref *ref); StyledEditWindow(BRect frame, int32 id);
~StyledEditWindow(); 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);
private: virtual void Quit();
void InitWindow(); virtual bool QuitRequested();
void Register(bool need_id); virtual void MessageReceived(BMessage *message);
void Unregister(void);
bool Search(BString searchfor, bool casesens, bool wrap, bool backsearch); status_t Save(BMessage *message);
void FindSelection(); void OpenFile(entry_ref *ref);
void Replace(BString findthis, BString replacewith, bool casesens, bool wrap, bool backsearch); status_t PageSetup(const char *documentname);
void ReplaceAll(BString find, BString replace, bool casesens); void Print(const char *documentname);
void SetFontSize(float fontSize); void SearchAllWindows(BString find, BString replace, bool casesens);
void SetFontColor(rgb_color *color);
void SetFontStyle(const char *fontFamily, const char *fontStyle); private:
void RevertToSaved(); void InitWindow();
bool Search(BString searchfor, bool casesens, bool wrap, bool backsearch);
void FindSelection();
BMenuBar *fMenuBar; void 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);
BMenuItem *fSaveItem; void SetFontColor(rgb_color *color);
BMenuItem *fRevertItem; void SetFontStyle(const char *fontFamily, const char *fontStyle);
BMenuItem *fUndoItem; void RevertToSaved();
BMenuItem *fCutItem;
BMenuItem *fCopyItem; BMenuBar *fMenuBar;
BMenuItem *fClearItem; BMessage *fPrintSettings;
BMenuItem *fWrapItem; BMessage *fSaveMessage;
BString fStringToFind; BMenuItem *fSaveItem;
BString fReplaceString; BMenuItem *fRevertItem;
bool fEnableItems; BMenuItem *fUndoItem;
bool fFirstEdit; BMenuItem *fCutItem;
bool fTextSaved; BMenuItem *fCopyItem;
bool fUnDoneFlag; BMenuItem *fClearItem;
bool fCaseSens; BMenuItem *fWrapItem;
bool fWrapAround; BString fStringToFind;
bool fBackSearch; BString fReplaceString;
StyledEditView *fTextView;
BScrollView *fScrollView; // undo modes
BFilePanel *fSavePanel; bool fUndoFlag; // we just did an undo action
int32 fWindow_Id; 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