Finale PDK Framework  0.54
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 
26 class FCDocument : public __FCBase
27 {
28  static FCString _lastundostring;
29 
30  EDOCID _docid;
31  EDOCID _lastdocid;
32  FCString _switchto_undostring;
33 public:
34 
35  virtual const char* ClassName() { return "FCDocument"; }
36 
41  FCDocument(EDOCID id = -1) : __FCBase()
42  {
43  if (id < 1)
44  _docid = FX_GetCurrentEnigmaDocument();
45  else
46  _docid = id;
47  _lastdocid = 0;
48  }
49 
54  EDOCID GetID() const { return _docid; }
55 
60  bool IsCurrent() { return _docid == FX_GetCurrentEnigmaDocument(); }
61 
63  virtual bool IsIdentical(__FCBase* pCompareObject)
64  {
65  FCDocument* pOtherDocument = (FCDocument*) pCompareObject;
66  return (GetID() == pOtherDocument->GetID());
67  }
68 
70  bool IsUntitled();
71 
81  bool GetPath(FCString* pString);
82 
84  bool GetPathSpec(void *pathspec, EVERSION convertversion);
85 
90  bool SetToCurrent()
91  {
92  if (_lastdocid != 0) return false;
93  _docid = FX_GetCurrentEnigmaDocument();
94  return true;
95  }
96 
116  bool SwitchTo(FCString* pUndoString, bool saveedits);
117 
118 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
119 
120  void _DiscardSwitchBack() { _lastdocid = 0; }
121 #endif /* #ifndef DOXYGEN_SHOULD_IGNORE_THIS */
122 
133  bool SwitchBack(bool saveedits);
134 
139  {
140  /* Try to find the docid in a window first. */
141  int windowcount = FX_GetWindowCount();
142  if (windowcount == 0) return false;
143 #if FXT_VERSION < FINALEVERSION_2012
144  int datasize = sizeof (EXDocWindow2009) * windowcount;
145  EXDocWindow2009* pDocwindowarray = new EXDocWindow2009[windowcount];
146 #elif FXT_VERSION < FINALEVERSION_25
147  int datasize = sizeof (EXDocWindow2012) * windowcount;
148  EXDocWindow2012* pDocwindowarray = new EXDocWindow2012[windowcount];
149 #else
150  int datasize = sizeof (EXDocWindow25) * windowcount;
151  EXDocWindow25* pDocwindowarray = new EXDocWindow25[windowcount];
152 #endif
153  memset(pDocwindowarray, 0, datasize);
154  /* Don't look at the return value of FX_GetWindowInfoList,
155  * since it returns false on Finale 2012 at least. */
156  FX_GetWindowInfoList(pDocwindowarray, windowcount);
157  bool windowswitched = false;
158  for (int i = 0; i < windowcount; i++)
159  {
160  if (pDocwindowarray[i].docID == _docid)
161  {
162  if (!FX_SetCurrentWindow(pDocwindowarray[i].hWnd))
163  {
164  delete [] pDocwindowarray;
165  return false;
166  }
167  windowswitched = true;
168  break;
169  }
170  }
171  if (!windowswitched) {
172  delete [] pDocwindowarray;
173  return false;
174  }
175  /* Window have switched, make sure Enigma contents is correct as well. */
176  if (!FX_SetCurrentEnigmaDocument(_docid))
177  {
178  delete [] pDocwindowarray;
179  return false;
180  }
181  FX_RedrawMusic(NULL);
182  _lastdocid = 0;
183  return true;
184  }
185 
192  bool Save();
193 
203  bool Open(FCString* pFilePath, bool createwindow, FCString* pUndoString);
204 
210 
215  bool Close();
216 
223  bool Print(FCPrintSettings* pSettings);
224 
230  bool GetDirty() const
231  {
232  return FX_IsEnigmaDocumentDirty(GetID()) != 0;
233  }
234 
240  void SetDirty(bool state)
241  {
242  return FX_SetEnigmaDocumentDirty(GetID(), state);
243  }
244 
247  static void _SetLastUndoString(FCString* pString)
248  {
249  _lastundostring.SetString(pString);
250  }
251 
254  static void GetLastUndoString(FCString* pString)
255  {
256  if (!pString) return;
257  pString->SetString(&_lastundostring);
258  }
259 
260 #ifdef PDK_FRAMEWORK_DEBUG
261  void DebugDump()
262  {
264  DebugOutDigit("Document ID: ", GetID());
265  FCString astring;
266  GetPath(&astring);
267  DebugOutString("Document path: ", astring.GetCString());
268  }
269 #endif
270 };
271 
278 {
279 public:
280  virtual const char* ClassName() { return "FCDocuments"; }
281 
288  int LoadAll();
289 
292  int ForEachWithScope(FCIteratorHandler* pIterator, FCString* pUndoString);
293 
301  {
302  for (int i = 0; i < GetCount(); i++)
303  {
304  FCDocument* pObject = (FCDocument*) GetItemAt(i);
305  if (pObject->IsCurrent()) return pObject;
306  }
307  return NULL;
308  }
309 
316  FCDocument* FindID(EDOCID docid)
317  {
318  for (int i = 0; i < GetCount(); i++)
319  {
320  FCDocument* pObject = (FCDocument*) GetItemAt(i);
321  if (pObject->GetID() == docid) return pObject;
322  }
323  return NULL;
324  }
325 
330  FCDocument* GetItemAt(int index) { return (FCDocument*) __FCCollection::GetItemAt(index); }
331 };
332 
333 
334 #endif /* FF_DOCUMENTS_H */
335 
__FCBase * GetItemAt(int index)
Returns the object at the index position. Index is 0-based.
Definition: finaleframework.cpp:12797
const char * GetCString() const
Returns a C-string version of the string.
Definition: finaleframework.cpp:1159
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:375
bool SwitchBack(bool saveedits)
Ends the started edit block and switch back to the previous document.
Definition: finaleframework.cpp:27152
Class for a collection of documents. Usually used to get all the currently loaded documents in Finale...
Definition: ff_documents.h:277
bool Close()
Closes the document.
Definition: finaleframework.cpp:27290
void SetDirty(bool state)
Sets the "dirty" flag for the document (that indicates that the document needs to be saved)...
Definition: ff_documents.h:240
FCDocument * FindCurrent()
Returns the document in the collection that is the current document.
Definition: ff_documents.h:300
bool SwitchTo(FCString *pUndoString, bool saveedits)
Switch document focus to this document and start a new (nested) undo/redo record, without closing the...
Definition: finaleframework.cpp:27129
bool Open(FCString *pFilePath, bool createwindow, FCString *pUndoString)
Opens a file as a new Finale documnent. The new document will automatically get editing focus...
Definition: finaleframework.cpp:27216
static void _SetLastUndoString(FCString *pString)
For internal use only. This method should be called whenever a new undo block is started.
Definition: ff_documents.h:247
bool CloseCurrentDocumentWindow()
Closes the current document Window.
Definition: finaleframework.cpp:27283
static void DebugOutDigit(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:274
bool IsUntitled()
Returns true if the document has no file connected to it.
Definition: finaleframework.cpp:27302
Class for an opened Finale document. An opened Finale document has a 1-based ID and can be displayed ...
Definition: ff_documents.h:26
int LoadAll()
Gets all open docs into the collection.
Definition: finaleframework.cpp:27378
void DebugDump()
Outputs the class data/information for debugging purposes.
Definition: ff_documents.h:261
int GetCount() const
Returns the number of elements of the collection.
Definition: ff_basecollection.h:86
void SetString(FCString *pString)
Copies a string.
Definition: finaleframework.cpp:2132
bool IsCurrent()
Returns true if the current document is the current document.
Definition: ff_documents.h:60
bool Print(FCPrintSettings *pSettings)
Prints the document, using the specified printer settings.
Definition: finaleframework.cpp:27296
FCDocument * GetItemAt(int index)
Overridden version of GetItemAt().
Definition: ff_documents.h:330
Base class for the Finale Framework classes.
Definition: ff_base.h:47
FCDocument(EDOCID id=-1)
The constructor.
Definition: ff_documents.h:41
EDOCID GetID() const
Returns the document ID.
Definition: ff_documents.h:54
bool Save()
Saves the current document at the current document path.
Definition: finaleframework.cpp:27211
bool DisplayVisually()
Moves the visual focus to the document.
Definition: ff_documents.h:138
static void GetLastUndoString(FCString *pString)
Fetches the last undo string for the edit block.
Definition: ff_documents.h:254
Class for iterator handlers.
Definition: ff_iterator.h:25
Class containing printing settings (and the ability to print documents).
Definition: ff_base.h:3969
Class that provides storage for text. This is to achieve platform-transparent text handling...
Definition: ff_base.h:1473
virtual const char * ClassName()
Returns the name of the class, for diagnostic purposes. This method MUST be overwritten in each child...
Definition: ff_documents.h:280
virtual const char * ClassName()
Returns the name of the class, for diagnostic purposes. This method MUST be overwritten in each child...
Definition: ff_documents.h:35
int ForEachWithScope(FCIteratorHandler *pIterator, FCString *pUndoString)
Works like ForEach, but sets each document into scope before calling the Iterate handler method...
Definition: finaleframework.cpp:27392
bool SetToCurrent()
Remaps the object to the current document.
Definition: ff_documents.h:90
virtual bool IsIdentical(__FCBase *pCompareObject)
Overridden method for comparison of documents.
Definition: ff_documents.h:63
FCDocument * FindID(EDOCID docid)
Tries to find the document with a specific document ID.
Definition: ff_documents.h:316
bool GetDirty() const
Returns the "dirty" flag for document (that indicates that the document needs to be saved)...
Definition: ff_documents.h:230
bool GetPath(FCString *pString)
Gets the full path of the document in a FCString object.
Definition: finaleframework.cpp:27314
bool GetPathSpec(void *pathspec, EVERSION convertversion)
Copies the document path to a path spec.
Definition: finaleframework.cpp:27171
Base class for all collection classes. A collection is a storage that can store multiple objects of s...
Definition: ff_basecollection.h:24
virtual void DebugDump()
Outputs the class data/information for debugging purposes.
Definition: finaleframework.cpp:547