ListContents.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. //////////////////////////////////////////////////////////////////////////////
  19. //
  20. // ListContents.CPP
  21. //
  22. // History:
  23. // 01/21/97 JMI Started.
  24. //
  25. //////////////////////////////////////////////////////////////////////////////
  26. //
  27. // This is a very simple class designed to be used as a container specifically
  28. // for use with an RListBox.
  29. //
  30. //////////////////////////////////////////////////////////////////////////////
  31. //////////////////////////////////////////////////////////////////////////////
  32. // C Headers -- Must be included before RSPiX.h b/c RSPiX utilizes SHMalloc.
  33. //////////////////////////////////////////////////////////////////////////////
  34. ///////////////////////////////////////////////////////////////////////////////
  35. // RSPiX Headers.
  36. // If PATHS_IN_INCLUDES macro is defined, we can utilize relative
  37. // paths to a header file. In this case we generally go off of our
  38. // RSPiX root directory. System.h MUST be included before this macro
  39. // is evaluated. System.h is the header that, based on the current
  40. // platform (or more so in this case on the compiler), defines
  41. // PATHS_IN_INCLUDES. Blue.h includes system.h so you can include that
  42. // instead.
  43. ///////////////////////////////////////////////////////////////////////////////
  44. #include "System.h"
  45. #ifdef PATHS_IN_INCLUDES
  46. #include "ORANGE/GUI/ListBox.h"
  47. #else
  48. #include "ListBox.h"
  49. #endif
  50. //////////////////////////////////////////////////////////////////////////////
  51. // Module specific macros.
  52. //////////////////////////////////////////////////////////////////////////////
  53. //////////////////////////////////////////////////////////////////////////////
  54. // Module specific typedefs.
  55. //////////////////////////////////////////////////////////////////////////////
  56. //////////////////////////////////////////////////////////////////////////////
  57. // Exported (extern) variables.
  58. //////////////////////////////////////////////////////////////////////////////
  59. //////////////////////////////////////////////////////////////////////////////
  60. // Module specific (static) variables / Instantiate class statics.
  61. //////////////////////////////////////////////////////////////////////////////
  62. //////////////////////////////////////////////////////////////////////////////
  63. // Module specific (static) protos.
  64. //////////////////////////////////////////////////////////////////////////////
  65. //////////////////////////////////////////////////////////////////////////////
  66. // Functions.
  67. //////////////////////////////////////////////////////////////////////////////
  68. //////////////////////////////////////////////////////////////////////////////
  69. // Internal.
  70. //////////////////////////////////////////////////////////////////////////////
  71. //////////////////////////////////////////////////////////////////////////////
  72. //
  73. // Save item's children to the specified file.
  74. // (protected/virtual (overridden here)).
  75. //
  76. //////////////////////////////////////////////////////////////////////////////
  77. short RListContents::SaveChildren( // Returns 0 on success.
  78. RFile* pfile) // File to save to.
  79. {
  80. short sRes = 0; // Assume success.
  81. ASSERT(pfile->IsOpen() != FALSE);
  82. // Determine number of child items.
  83. short sNum = 0;
  84. RGuiItem* pgui = m_listguiChildren.GetHead();
  85. while (pgui != NULL)
  86. {
  87. sNum++;
  88. pgui = m_listguiChildren.GetNext();
  89. }
  90. // Write number of children.
  91. pfile->Write(sNum);
  92. // Save children in reverse order.
  93. pgui = m_listguiChildren.GetTail();
  94. while (pgui != NULL && sRes == 0 && pfile->Error() == FALSE)
  95. {
  96. // Before each item is a value indicating whether the item
  97. // is an encapsulator.
  98. pfile->Write((short)pgui->IsProp(ENCAPSULATOR_PROP_KEY) );
  99. // Save child.
  100. sRes = pgui->Save(pfile);
  101. pgui = m_listguiChildren.GetPrev();
  102. }
  103. return sRes;
  104. }
  105. //////////////////////////////////////////////////////////////////////////////
  106. //
  107. // Load item's children from the specified file.
  108. // (protected/virtual (overridden here)).
  109. //
  110. //////////////////////////////////////////////////////////////////////////////
  111. short RListContents::LoadChildren( // Returns 0 on success.
  112. RFile* pfile) // File to load from.
  113. {
  114. short sRes = 0; // Assume success.
  115. ASSERT(pfile->IsOpen() != FALSE);
  116. // Need to know parent.
  117. ASSERT(GetParent() != NULL);
  118. short sNum;
  119. // Read number of children.
  120. pfile->Read(&sNum);
  121. // Instantiate children.
  122. RGuiItem* pgui;
  123. short sCurChild;
  124. short sEncapsulator;
  125. for ( sCurChild = 0;
  126. sCurChild < sNum && sRes == 0 && pfile->Error() == FALSE;
  127. sCurChild++)
  128. {
  129. // Before each item is a value indicating whether the item
  130. // is an encapsulator.
  131. pfile->Read(&sEncapsulator);
  132. pgui = LoadInstantiate(pfile);
  133. if (pgui != NULL)
  134. {
  135. pgui->SetParent(this);
  136. // If the item is an encapsulator . . .
  137. if (sEncapsulator != FALSE)
  138. {
  139. // Mark item as an encapsulator.
  140. pgui->SetProp(ENCAPSULATOR_PROP_KEY, TRUE);
  141. // Set callback.
  142. pgui->m_bcUser = RListBox::PressedCall;
  143. // Set instance to parent listbox.
  144. pgui->m_ulUserInstance = (ULONG)GetParent();
  145. // If pushed in . . .
  146. if (pgui->m_sInvertedBorder != FALSE)
  147. {
  148. // Select item.
  149. ((RListBox*)GetParent())->SetSel(pgui);
  150. }
  151. }
  152. }
  153. else
  154. {
  155. TRACE("LoadChildren(): LoadInstantiate() failed.\n");
  156. sRes = -1;
  157. }
  158. }
  159. return sRes;
  160. }
  161. ///////////////////////////////////////////////////////////////////////////////
  162. // EOF
  163. ///////////////////////////////////////////////////////////////////////////////