Finale PDK Framework 0.77
Power Up Your 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
27class FCDocument : public __FCBase
28{
29 EDOCID _docid;
30 EDOCID _lastdocid;
31
32 void _StoreIDForSwitchBack()
33 {
34 _lastdocid = FX_GetCurrentEnigmaDocument();
35 if (FX_GetCurrentEnigmaDocument() < 1) _lastdocid = 0;
36 }
37
38public:
39
40 const char* ClassName() const override { return "FCDocument"; }
41
42#ifdef PDK_FRAMEWORK_LUAFRIENDLY
44 static FCDocument* FCDocument_Lua(void* ptr, lua_State* L)
45 {
46 return _OneOptionalParamLuaConstructor<FCDocument, EDOCID>(ptr, L);
47 }
48#endif
49
56 FCDocument(EDOCID id = -1) : __FCBase()
57 {
58 if (id < 1)
59 _docid = FX_GetCurrentEnigmaDocument();
60 else
61 _docid = id;
62 _lastdocid = 0;
63 }
64
69 EDOCID GetID() const { return _docid; }
70
75 bool IsCurrent() { return _docid == FX_GetCurrentEnigmaDocument(); }
76
78 bool IsIdentical(const __FCBase* pCompareObject) const override
79 {
80 const FCDocument* pOtherDocument = dynamic_cast<const FCDocument*>(pCompareObject);
81 if (!pOtherDocument) return false;
82 return (GetID() == pOtherDocument->GetID());
83 }
84
86 bool IsUntitled();
87
97 bool GetPath(FCString* pString);
98
100 bool GetPathSpec(void *pathspec, EVERSION convertversion);
101
107 {
108 if (_lastdocid != 0) return false;
109 _docid = FX_GetCurrentEnigmaDocument();
110 return true;
111 }
112
114 bool _SetID(EDOCID docID)
115 {
116 if (_lastdocid != 0) return false;
117 _docid = docID;
118 return true;
119 }
120
166#ifdef PDK_FRAMEWORK_LUAFRIENDLY
167 bool SwitchTo(const FCString* pUndoString, bool saveedits, _state_ptr S);
168#else
169 bool SwitchTo(const FCString* pUndoString, bool saveedits, _state_ptr S = nullptr);
170#endif
171
183#ifdef PDK_FRAMEWORK_LUAFRIENDLY
184 bool SwitchBack(bool saveedits, _state_ptr S);
185#else
186 bool SwitchBack(bool saveedits, _state_ptr S = nullptr);
187#endif
196 {
197 /* Try to find the docid in a window first. */
198 int windowcount = FX_GetWindowCount();
199 if (windowcount == 0) return false;
200#if FXT_VERSION < FINALEVERSION_2012
201 int datasize = sizeof (EXDocWindow2009) * windowcount;
202 EXDocWindow2009* pDocwindowarray = new EXDocWindow2009[windowcount];
203#elif FXT_VERSION < FINALEVERSION_25
204 int datasize = sizeof (EXDocWindow2012) * windowcount;
205 EXDocWindow2012* pDocwindowarray = new EXDocWindow2012[windowcount];
206#else
207 int datasize = sizeof (EXDocWindow25) * windowcount;
208 EXDocWindow25* pDocwindowarray = new EXDocWindow25[windowcount];
209#endif
210 memset(pDocwindowarray, 0, datasize);
211 /* Don't look at the return value of FX_GetWindowInfoList,
212 * since it returns false on Finale 2012 at least. */
213 FX_GetWindowInfoList(pDocwindowarray, windowcount);
214 bool windowswitched = false;
215 for (int i = 0; i < windowcount; i++)
216 {
217 if (pDocwindowarray[i].docID == _docid)
218 {
219 if (!FX_SetCurrentWindow(pDocwindowarray[i].hWnd))
220 {
221 delete [] pDocwindowarray;
222 return false;
223 }
224 windowswitched = true;
225 break;
226 }
227 }
228 if (!windowswitched) {
229 delete [] pDocwindowarray;
230 return false;
231 }
232 /* Window have switched, make sure Enigma contents is correct as well. */
233 if (!FX_SetCurrentEnigmaDocument(_docid))
234 {
235 delete [] pDocwindowarray;
236 return false;
237 }
238 FX_RedrawMusic(NULL);
239 _lastdocid = 0;
240 return true;
241 }
242
255 bool Save(const FCString* pFilePath = nullptr);
256
257#ifdef PDK_FRAMEWORK_LUAFRIENDLY_CPP
259 static int Save_CFunc(lua_State* L)
260 {
261 return _CFunctionOneOptionalParameter<FCDocument, bool, const FCString*, &FCDocument::Save>(L, nullptr);
262 }
263#endif
264
281#ifdef PDK_FRAMEWORK_LUAFRIENDLY
282 bool Open(const FCString* pFilePath, bool createwindow, const FCString* pUndoString, bool saveedits, bool addtorecents, bool hidedialogs, _state_ptr S);
283#else
284 bool Open(const FCString* pFilePath, bool createwindow, const FCString* pUndoString, bool saveedits, bool addtorecents, bool hidedialogs, _state_ptr S = nullptr);
285#endif
286
299#ifdef PDK_FRAMEWORK_LUAFRIENDLY
300 bool New(const FCString* pUndoString, bool saveedits, _state_ptr S);
301#else
302 bool New(const FCString* pUndoString, bool saveedits, _state_ptr S = nullptr);
303#endif
304
314 bool CloseCurrentDocumentAndWindow(bool saveedits = true, _state_ptr S = nullptr);
315
316#ifdef PDK_FRAMEWORK_LUAFRIENDLY_CPP
318 static int CloseCurrentDocumentAndWindow_CFunc(lua_State *L)
319 {
320 return _CFunctionOneOptionalParameterWithState<FCDocument, bool, bool, &FCDocument::CloseCurrentDocumentAndWindow>(L, true);
321 }
322#endif
323
333 bool Close(bool saveedits = true, _state_ptr S = nullptr);
334
335#ifdef PDK_FRAMEWORK_LUAFRIENDLY_CPP
337 static int Close_CFunc(lua_State *L)
338 {
339 return _CFunctionOneOptionalParameterWithState<FCDocument, bool, bool, &FCDocument::Close>(L, true);
340 }
341#endif
342
349 bool Print(FCPrintSettings* pSettings);
350
356 bool GetDirty() const
357 {
358 return FX_IsEnigmaDocumentDirty(GetID()) != 0;
359 }
360
366 void SetDirty(bool state)
367 {
368 return FX_SetEnigmaDocumentDirty(GetID(), state);
369 }
370
371#ifdef PDK_FRAMEWORK_DEBUG
372 void DebugDump() override
373 {
375 DebugOutInt("Document ID: ", GetID());
376 FCString astring;
377 GetPath(&astring);
378 DebugOutString("Document path: ", astring.GetCString());
379 }
380#endif
381};
382
391{
392public:
393 const char* ClassName() const override { return "FCDocuments"; }
394
401 int LoadAll();
402
405 int ForEachWithScope(FCIteratorHandler* pIterator, FCString* pUndoString, _state_ptr S _NOLUACODE(= nullptr));
406
414 {
415 for (int i = 0; i < GetCount(); i++)
416 {
417 FCDocument* pObject = (FCDocument*) GetItemAt(i);
418 if (pObject->IsCurrent()) return pObject;
419 }
420 return NULL;
421 }
422
429 FCDocument* FindID(EDOCID docid)
430 {
431 for (int i = 0; i < GetCount(); i++)
432 {
433 FCDocument* pObject = (FCDocument*) GetItemAt(i);
434 if (pObject->GetID() == docid) return pObject;
435 }
436 return NULL;
437 }
438
443 FCDocument* GetItemAt(int index) const { return (FCDocument*) __FCCollection::GetItemAt(index); }
444};
445
446
447#endif /* FF_DOCUMENTS_H */
448
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:436
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:335
virtual void DebugDump()
Outputs the class data/information for debugging purposes.
Definition finaleframework.cpp:609
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:13767
Class for an opened Finale document. An opened Finale document has a 1-based ID and can be displayed ...
Definition ff_documents.h:28
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:32684
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:40
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:32655
bool Print(FCPrintSettings *pSettings)
Prints the document, using the specified printer settings.
Definition finaleframework.cpp:32691
bool Save(const FCString *pFilePath=nullptr)
Saves the current document at the current document path or the specified document path.
Definition finaleframework.cpp:32572
void SetDirty(bool state)
Sets the "dirty" flag for the document (that indicates that the document needs to be saved).
Definition ff_documents.h:366
bool GetPathSpec(void *pathspec, EVERSION convertversion)
Copies the document path to a path spec.
Definition finaleframework.cpp:32532
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:32675
FCDocument(EDOCID id=-1)
The constructor.
Definition ff_documents.h:56
bool GetPath(FCString *pString)
Gets the full path of the document in a FCString object.
Definition finaleframework.cpp:32709
void DebugDump() override
Outputs the class data/information for debugging purposes.
Definition ff_documents.h:372
bool SwitchBack(bool saveedits, _state_ptr S=nullptr)
Ends the started edit block and switch back to the previous document.
Definition finaleframework.cpp:32514
bool DisplayVisually()
Moves the visual focus to the document.
Definition ff_documents.h:195
bool IsIdentical(const __FCBase *pCompareObject) const override
Overridden method for comparison of documents.
Definition ff_documents.h:78
bool GetDirty() const
Returns the "dirty" flag for document (that indicates that the document needs to be saved).
Definition ff_documents.h:356
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:32490
bool IsCurrent()
Returns true if the current document is the current document.
Definition ff_documents.h:75
EDOCID GetID() const
Returns the document ID.
Definition ff_documents.h:69
bool _SetID(EDOCID docID)
Directly sets the ID.
Definition ff_documents.h:114
bool SetToCurrent()
Remaps the object to the current document.
Definition ff_documents.h:106
bool IsUntitled()
Returns true if the document has no file connected to it.
Definition finaleframework.cpp:32697
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:32582
Class for a collection of documents. Usually used to get all the currently loaded documents in Finale...
Definition ff_documents.h:391
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:32803
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:393
FCDocument * FindID(EDOCID docid)
Tries to find the document with a specific document ID.
Definition ff_documents.h:429
FCDocument * FindCurrent()
Returns the document in the collection that is the current document.
Definition ff_documents.h:413
FCDocument * GetItemAt(int index) const
Overridden version of GetItemAt().
Definition ff_documents.h:443
int LoadAll()
Gets all open docs into the collection.
Definition finaleframework.cpp:32789
Class for iterator handlers.
Definition ff_iterator.h:26
Class containing printing settings (and the ability to print documents).
Definition ff_base.h:4969
Class that provides storage for text. This is to achieve platform-transparent text handling,...
Definition ff_base.h:1877
const char * GetCString() const
Returns a C-string version of the string.
Definition finaleframework.cpp:1338