Finale PDK Framework 0.79
Lua Power for Finale Music Software
Loading...
Searching...
No Matches
ff_documents.h
1/*
2 * File: ff_documents.h
3 * Author: Jari Williamsson
4 *
5 * Created on den 22 mars 2011, 17:30
6 */
7
8#ifndef FF_DOCUMENTS_H
9#define FF_DOCUMENTS_H
10
11#include <map>
12#include <string>
13
28class FCDocument : public __FCBase
29{
30 EDOCID _docid;
31 EDOCID _lastdocid;
32
33 void _StoreIDForSwitchBack()
34 {
35 _lastdocid = FX_GetCurrentEnigmaDocument();
36 if (FX_GetCurrentEnigmaDocument() < 1) _lastdocid = 0;
37 }
38
39public:
40
41 const char* ClassName() const override { return "FCDocument"; }
42
43#ifdef PDK_FRAMEWORK_LUAFRIENDLY
45 static FCDocument* FCDocument_Lua(void* ptr, lua_State* L)
46 {
47 return _OneOptionalParamLuaConstructor<FCDocument, EDOCID>(ptr, L);
48 }
49#endif
50
57 FCDocument(EDOCID id = -1) : __FCBase()
58 {
59 if (id < 1)
60 _docid = FX_GetCurrentEnigmaDocument();
61 else
62 _docid = id;
63 _lastdocid = 0;
64 }
65
70 EDOCID GetID() const { return _docid; }
71
76 bool IsCurrent() { return _docid == FX_GetCurrentEnigmaDocument(); }
77
79 bool IsIdentical(const __FCBase* pCompareObject) const override
80 {
81 const FCDocument* pOtherDocument = dynamic_cast<const FCDocument*>(pCompareObject);
82 if (!pOtherDocument) return false;
83 return (GetID() == pOtherDocument->GetID());
84 }
85
87 bool IsUntitled();
88
98 bool GetPath(FCString* pString);
99
107 std::string GetCreatedDate() const;
108
116 std::string GetModifiedDate() const;
117
124 EVERSION GetCreatedVersion() const;
125
132 EVERSION GetModifiedVersion() const;
133
135 bool GetPathSpec(void *pathspec, EVERSION convertversion);
136
142 {
143 if (_lastdocid != 0) return false;
144 _docid = FX_GetCurrentEnigmaDocument();
145 return true;
146 }
147
149 bool _SetID(EDOCID docID)
150 {
151 if (_lastdocid != 0) return false;
152 _docid = docID;
153 return true;
154 }
155
201#ifdef PDK_FRAMEWORK_LUAFRIENDLY
202 bool SwitchTo(const FCString* pUndoString, bool saveedits, _state_ptr S);
203#else
204 bool SwitchTo(const FCString* pUndoString, bool saveedits, _state_ptr S = nullptr);
205#endif
206
218#ifdef PDK_FRAMEWORK_LUAFRIENDLY
219 bool SwitchBack(bool saveedits, _state_ptr S);
220#else
221 bool SwitchBack(bool saveedits, _state_ptr S = nullptr);
222#endif
231 {
232 /* Try to find the docid in a window first. */
233 int windowcount = FX_GetWindowCount();
234 if (windowcount == 0) return false;
235#if FXT_VERSION < FINALEVERSION_2012
236 int datasize = sizeof (EXDocWindow2009) * windowcount;
237 EXDocWindow2009* pDocwindowarray = new EXDocWindow2009[windowcount];
238#elif FXT_VERSION < FINALEVERSION_25
239 int datasize = sizeof (EXDocWindow2012) * windowcount;
240 EXDocWindow2012* pDocwindowarray = new EXDocWindow2012[windowcount];
241#else
242 int datasize = sizeof (EXDocWindow25) * windowcount;
243 EXDocWindow25* pDocwindowarray = new EXDocWindow25[windowcount];
244#endif
245 memset(pDocwindowarray, 0, datasize);
246 /* Don't look at the return value of FX_GetWindowInfoList,
247 * since it returns false on Finale 2012 at least. */
248 FX_GetWindowInfoList(pDocwindowarray, windowcount);
249 bool windowswitched = false;
250 for (int i = 0; i < windowcount; i++)
251 {
252 if (pDocwindowarray[i].docID == _docid)
253 {
254 if (!FX_SetCurrentWindow(pDocwindowarray[i].hWnd))
255 {
256 delete [] pDocwindowarray;
257 return false;
258 }
259 windowswitched = true;
260 break;
261 }
262 }
263 if (!windowswitched) {
264 delete [] pDocwindowarray;
265 return false;
266 }
267 /* Window have switched, make sure Enigma contents is correct as well. */
268 if (!FX_SetCurrentEnigmaDocument(_docid))
269 {
270 delete [] pDocwindowarray;
271 return false;
272 }
273 FX_RedrawMusic(NULL);
274 _lastdocid = 0;
275 return true;
276 }
277
290 bool Save(const FCString* pFilePath = nullptr);
291
292#ifdef PDK_FRAMEWORK_LUAFRIENDLY_CPP
294 static int Save_CFunc(lua_State* L)
295 {
296 return _CFunctionOneOptionalParameter<FCDocument, bool, const FCString*, &FCDocument::Save>(L, nullptr);
297 }
298#endif
299
316#ifdef PDK_FRAMEWORK_LUAFRIENDLY
317 bool Open(const FCString* pFilePath, bool createwindow, const FCString* pUndoString, bool saveedits, bool addtorecents, bool hidedialogs, _state_ptr S);
318#else
319 bool Open(const FCString* pFilePath, bool createwindow, const FCString* pUndoString, bool saveedits, bool addtorecents, bool hidedialogs, _state_ptr S = nullptr);
320#endif
321
334#ifdef PDK_FRAMEWORK_LUAFRIENDLY
335 bool New(const FCString* pUndoString, bool saveedits, _state_ptr S);
336#else
337 bool New(const FCString* pUndoString, bool saveedits, _state_ptr S = nullptr);
338#endif
339
349 bool CloseCurrentDocumentAndWindow(bool saveedits = true, _state_ptr S = nullptr);
350
351#ifdef PDK_FRAMEWORK_LUAFRIENDLY_CPP
353 static int CloseCurrentDocumentAndWindow_CFunc(lua_State *L)
354 {
355 return _CFunctionOneOptionalParameterWithState<FCDocument, bool, bool, &FCDocument::CloseCurrentDocumentAndWindow>(L, true);
356 }
357#endif
358
368 bool Close(bool saveedits = true, _state_ptr S = nullptr);
369
370#ifdef PDK_FRAMEWORK_LUAFRIENDLY_CPP
372 static int Close_CFunc(lua_State *L)
373 {
374 return _CFunctionOneOptionalParameterWithState<FCDocument, bool, bool, &FCDocument::Close>(L, true);
375 }
376#endif
377
384 bool Print(FCPrintSettings* pSettings);
385
391 bool GetDirty() const
392 {
393 return FX_IsEnigmaDocumentDirty(GetID()) != 0;
394 }
395
401 void SetDirty(bool state)
402 {
403 return FX_SetEnigmaDocumentDirty(GetID(), state);
404 }
405
406#ifdef PDK_FRAMEWORK_DEBUG
407 void DebugDump() override
408 {
410 DebugOutInt("Document ID: ", GetID());
411 FCString astring;
412 GetPath(&astring);
413 DebugOutString("Document path: ", astring.GetCString());
414 }
415#endif
416};
417
426{
427public:
428 const char* ClassName() const override { return "FCDocuments"; }
429
436 int LoadAll();
437
440 int ForEachWithScope(FCIteratorHandler* pIterator, FCString* pUndoString, _state_ptr S _NOLUACODE(= nullptr));
441
449 {
450 for (int i = 0; i < GetCount(); i++)
451 {
452 FCDocument* pObject = (FCDocument*) GetItemAt(i);
453 if (pObject->IsCurrent()) return pObject;
454 }
455 return NULL;
456 }
457
464 FCDocument* FindID(EDOCID docid)
465 {
466 for (int i = 0; i < GetCount(); i++)
467 {
468 FCDocument* pObject = (FCDocument*) GetItemAt(i);
469 if (pObject->GetID() == docid) return pObject;
470 }
471 return NULL;
472 }
473
478 FCDocument* GetItemAt(int index) const { return (FCDocument*) __FCCollection::GetItemAt(index); }
479};
480
481
482#endif /* FF_DOCUMENTS_H */
Base class for the Finale Framework classes.
Definition ff_base.h:71
static void DebugOutString(const char *pszPrefixText, const char *thestring)
Static method that outputs a line for debugging purposes (C string version). The text appears with th...
Definition finaleframework.cpp:864
static void DebugOutInt(const char *pszPrefixText, int i)
Static method that outputs a line for debugging purposes. The text appears with the extra digit (in d...
Definition finaleframework.cpp:763
virtual void DebugDump()
Outputs the class data/information for debugging purposes.
Definition finaleframework.cpp:1037
Base class for all collection classes. A collection is a storage that can store multiple objects of s...
Definition ff_basecollection.h:26
int GetCount() const
Returns the number of elements of the collection.
Definition ff_basecollection.h:102
__FCBase * GetItemAt(int index) const
Returns the object at the index position. Index is 0-based.
Definition finaleframework.cpp:14195
Class for an opened Finale document. An opened Finale document has a 1-based ID and can be displayed ...
Definition ff_documents.h:29
EVERSION GetModifiedVersion() const
Returns the Enigma version from the "modified" file header field.
Definition finaleframework.cpp:32978
bool Close(bool saveedits=true, _state_ptr S=nullptr)
Closes the document. Use this function to close a document if you did not open a document window when...
Definition finaleframework.cpp:33179
const char * ClassName() const override
Returns the name of the class, for diagnostic purposes. This method MUST be overwritten in each child...
Definition ff_documents.h:41
bool New(const FCString *pUndoString, bool saveedits, _state_ptr S=nullptr)
Creates an new untitled Finale documnent. The new document automatically gets editing focus....
Definition finaleframework.cpp:33150
bool Print(FCPrintSettings *pSettings)
Prints the document, using the specified printer settings.
Definition finaleframework.cpp:33186
bool Save(const FCString *pFilePath=nullptr)
Saves the current document at the current document path or the specified document path.
Definition finaleframework.cpp:33067
void SetDirty(bool state)
Sets the "dirty" flag for the document (that indicates that the document needs to be saved).
Definition ff_documents.h:401
bool GetPathSpec(void *pathspec, EVERSION convertversion)
Copies the document path to a path spec.
Definition finaleframework.cpp:33027
bool CloseCurrentDocumentAndWindow(bool saveedits=true, _state_ptr S=nullptr)
Closes the current document and any windows it has open. Use this function to close a document if you...
Definition finaleframework.cpp:33170
FCDocument(EDOCID id=-1)
The constructor.
Definition ff_documents.h:57
bool GetPath(FCString *pString)
Gets the full path of the document in a FCString object.
Definition finaleframework.cpp:33204
void DebugDump() override
Outputs the class data/information for debugging purposes.
Definition ff_documents.h:407
bool SwitchBack(bool saveedits, _state_ptr S=nullptr)
Ends the started edit block and switch back to the previous document.
Definition finaleframework.cpp:33009
std::string GetCreatedDate() const
Returns the document creation date from the file header in ISO format.
Definition finaleframework.cpp:32957
bool DisplayVisually()
Moves the visual focus to the document.
Definition ff_documents.h:230
bool IsIdentical(const __FCBase *pCompareObject) const override
Overridden method for comparison of documents.
Definition ff_documents.h:79
EVERSION GetCreatedVersion() const
Returns the Enigma version from the "created" file header field.
Definition finaleframework.cpp:32971
bool GetDirty() const
Returns the "dirty" flag for document (that indicates that the document needs to be saved).
Definition ff_documents.h:391
bool SwitchTo(const FCString *pUndoString, bool saveedits, _state_ptr S=nullptr)
Switch document focus to this document and start a new undo/redo record, without closing the previous...
Definition finaleframework.cpp:32985
bool IsCurrent()
Returns true if the current document is the current document.
Definition ff_documents.h:76
EDOCID GetID() const
Returns the document ID.
Definition ff_documents.h:70
bool _SetID(EDOCID docID)
Directly sets the ID.
Definition ff_documents.h:149
bool SetToCurrent()
Remaps the object to the current document.
Definition ff_documents.h:141
std::string GetModifiedDate() const
Returns the document modified date from the file header in ISO format.
Definition finaleframework.cpp:32964
bool IsUntitled()
Returns true if the document has no file connected to it.
Definition finaleframework.cpp:33192
bool Open(const FCString *pFilePath, bool createwindow, const FCString *pUndoString, bool saveedits, bool addtorecents, bool hidedialogs, _state_ptr S=nullptr)
Opens a file as a new Finale document. The new document automatically gets editing focus....
Definition finaleframework.cpp:33077
Class for a collection of documents. Usually used to get all the currently loaded documents in Finale...
Definition ff_documents.h:426
int ForEachWithScope(FCIteratorHandler *pIterator, FCString *pUndoString, _state_ptr S _NOLUACODE(=nullptr))
Works like ForEach, but sets each document into scope before calling the Iterate handler method.
Definition finaleframework.cpp:33298
const char * ClassName() const override
Returns the name of the class, for diagnostic purposes. This method MUST be overwritten in each child...
Definition ff_documents.h:428
FCDocument * FindID(EDOCID docid)
Tries to find the document with a specific document ID.
Definition ff_documents.h:464
FCDocument * FindCurrent()
Returns the document in the collection that is the current document.
Definition ff_documents.h:448
FCDocument * GetItemAt(int index) const
Overridden version of GetItemAt().
Definition ff_documents.h:478
int LoadAll()
Gets all open docs into the collection.
Definition finaleframework.cpp:33284
Class for iterator handlers.
Definition ff_iterator.h:26
Class containing printing settings (and the ability to print documents).
Definition ff_base.h:5023
Class that provides storage for text. This is to achieve platform-transparent text handling,...
Definition ff_base.h:1931
const char * GetCString() const
Returns a C-string version of the string.
Definition finaleframework.cpp:1766