OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
editfile.h
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1992, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Definition of class TEditFile, a text edit which can find/replace and
7/// read/write from/to a file.
8//----------------------------------------------------------------------------
9
10#if !defined(OWL_EDITFILE_H)
11#define OWL_EDITFILE_H
12
13#include <owl/private/defs.h>
14#if defined(BI_HAS_PRAGMA_ONCE)
15# pragma once
16#endif
17
18#include <owl/editsear.h>
19#include <owl/opensave.h>
20#include <owl/editfile.rh>
21
22
23namespace owl {
24
25#include <owl/preclass.h>
26
27/// \addtogroup ctrl
28/// @{
29/// \class TEditFile
30// ~~~~~ ~~~~~~~~~
31/// TEditFile is a file-editing window. TEditFile's data members and member
32/// functions manage the file dialog box and automatic responses for file commands
33/// such as Open, Read, Write, Save, and SaveAs. TEditFile is streamable.
34//
36 public:
37 TEditFile(TWindow* parent = nullptr,
38 int id = 0,
39 LPCTSTR text = nullptr,
40 int x = 0, int y = 0, int w = 0, int h = 0,
41 LPCTSTR fileName = nullptr,
42 TModule* module = nullptr);
43
45 TWindow* parent,
46 int id,
47 const tstring& text,
48 int x = 0, int y = 0, int w = 0, int h = 0,
49 const tstring& fileName = tstring(),
50 TModule* module = nullptr);
51
52 TEditFile(TWindow* parent,
53 int resourceId,
54 TModule& module);
55
56 ~TEditFile() override;
57
58 virtual bool CanClear();
59 auto CanClose() -> bool override;
60
61 virtual void NewFile();
62 virtual void Open();
63 virtual bool Read(LPCTSTR fileName = nullptr);
64 bool Read(const tstring& fileName) {return Read(fileName.c_str());}
65 virtual void ReplaceWith(LPCTSTR fileName);
67 virtual bool Save();
68 virtual bool SaveAs();
69 virtual bool Write(LPCTSTR fileName = nullptr);
70 bool Write(const tstring& fileName) {return Write(fileName.c_str());}
71
72 LPCTSTR GetFileName() const;
73 void SetFileName(LPCTSTR fileName);
75
76 TOpenSaveDialog::TData& GetFileData();
77 void SetFileData(const TOpenSaveDialog::TData& fd);
78
79 protected: // !CQ these command handlers were public...
80
81 // Command response functions
82 //
83 void CmFileNew(); ///< CM_FILENEW
84 void CmFileOpen(); ///< CM_FILEOPEN
85 void CmFileSave(); ///< CM_FILESAVE
86 void CmFileSaveAs(); ///< CM_FILESAVEAS
87
88 // Command enabler functions
89 //
90 void CmSaveEnable(TCommandEnabler& commandHandler);
91
92 protected:
93 // Override virtual functions defined by TWindow
94 //
95 void SetupWindow() override;
96
98/// Contains information about the user's file open or save selection.
100
101/// Contains the name of the file being edited.
102 LPTSTR FileName;
103
104 private:
105 // Hidden to prevent accidental copying or assignment
106 //
107 TEditFile(const TEditFile&);
109
112};
113/// @}
114
116
117#include <owl/posclass.h>
118
119//----------------------------------------------------------------------------
120// Inline implementations
121//
122
123//
124/// This constructor, which aliases an Edit control created from a
125/// dialog resource is 'unconventional' in that it expects a TModule reference
126/// instead of the traditional 'TModule* = 0'. This is, however, to avoid
127/// ambiguities between the two forms of constructor. Since it is traditionally
128/// created as a child of a TDialog-derived class, you can simply use the module of
129/// the parent object.
130/// For example:
131/// \code
132/// TMyDialog::TMyDialog(....)
133/// {
134/// edit = new TEditFile(this, ID_EDIT1, *GetModule());
135/// }
136/// \endcode
137//
138inline
140 :TEditSearch(parent, resourceId, module),
141 FileName(nullptr)
142{
143}
144
145/// Return the filename for this buffer.
146//
148 return FileName;
149}
150
151//
152/// Return the FileData data member used for the common dialogs.
153//
155 return FileData;
156}
157
158//
160 FileData = fd;
161}
162
163//
164/// Calls NewFile() in response to an incoming File New command with a CM_FILENEW
165/// command identifier.
166//
167inline void TEditFile::CmFileNew() {
168 NewFile();
169}
170
171//
172/// Calls Open() in response to an incoming File Open command with a CM_FILEOPEN
173/// command identifier.
174//
176 Open();
177}
178
179//
180/// Calls Save() in response to an incoming File Save command with a CM_FILESAVE
181/// command identifier.
182//
184 Save();
185}
186
187//
188/// Calls SaveAs() in response to an incoming File SaveAs command with a CM_FILESAVEAS
189/// command identifier.
190//
192 SaveAs();
193}
194
195
196} // OWL namespace
197
198
199#endif // OWL_EDITFILE_H
Base class for an extensible interface for auto enabling/disabling of commands (menu items,...
Definition window.h:209
TEditFile is a file-editing window.
Definition editfile.h:35
void SetFileName(const tstring &fileName)
Definition editfile.h:74
void CmFileSave()
CM_FILESAVE.
Definition editfile.h:183
void CmFileSaveAs()
CM_FILESAVEAS.
Definition editfile.h:191
void CmFileOpen()
CM_FILEOPEN.
Definition editfile.h:175
virtual void NewFile()
Begins the edit of a new file after calling CanClear to determine that it is safe to clear the text o...
Definition editfile.cpp:118
virtual bool SaveAs()
Saves the contents of the Editor to a file whose name is retrieved from the user, through execution o...
Definition editfile.cpp:236
bool Write(const tstring &fileName)
Definition editfile.h:70
void CmFileNew()
CM_FILENEW.
Definition editfile.h:167
LPCTSTR GetFileName() const
Return the filename for this buffer.
Definition editfile.h:147
TOpenSaveDialog::TData & GetFileData()
Return the FileData data member used for the common dialogs.
Definition editfile.h:154
void SetFileData(const TOpenSaveDialog::TData &fd)
Definition editfile.h:159
bool Read(const tstring &fileName)
Definition editfile.h:64
virtual bool Save()
Saves changes to the contents of the Editor to a file.
Definition editfile.cpp:214
virtual void Open()
Opens a new file after determining that it is OK to clear the text of the Editor.
Definition editfile.cpp:155
void ReplaceWith(const tstring &fileName)
Definition editfile.h:66
TEditFile(TWindow *parent=nullptr, int id=0, LPCTSTR text=nullptr, int x=0, int y=0, int w=0, int h=0, LPCTSTR fileName=nullptr, TModule *module=nullptr)
Constructs a TEditFile window given the parent window, resource ID (Id), text, file name,...
Definition editfile.cpp:38
TEditSearch is an edit control that responds to Find, Replace, and FindNext menu commands.
Definition editsear.h:35
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TOpenSaveDialog structure contains information about the user's file open or save selection.
Definition opensave.h:44
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
Definition of class TEditSearch, an edit control that responds to Find, Replace and FindNext menu com...
#define DECLARE_RESPONSE_TABLE(cls)
Definition eventhan.h:436
#define DECLARE_STREAMABLE_OWL(cls, ver)
Definition objstrm.h:1529
#define DECLARE_STREAMABLE_INLINES(cls)
Definition objstrm.h:1538
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
std::string tstring
Definition defs.h:79
Definition of TOpenSave abstract, TFileOpen, TFileSave common Dialog classes.
#define public_data
Definition defs.h:207
#define _OWLCLASS
Definition defs.h:338