ALISTBOX.H 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. #ifndef ALISTBOX_H
  5. #define ALISTBOX_H
  6. #define MAX_LIST_ITEMS 128
  7. #define TOO_MANY_ITEMS 0xEEEE0001
  8. #define ITEM_OUT_OF_RANGE 0xEEEE0002
  9. #ifndef ASCROLL_H
  10. #include "aScroll.h"
  11. #endif
  12. #ifndef AEDIT_H
  13. #include "aEdit.h"
  14. #endif
  15. #ifndef AFONT_H
  16. #include "aFont.h"
  17. #endif
  18. #ifndef ESTRING_H
  19. #include "EString.h"
  20. #endif
  21. class aListItem : public aObject
  22. {
  23. public:
  24. enum State
  25. {
  26. ENABLED = 0,
  27. SELECTED,
  28. HIGHLITE,
  29. PRESSED_HIGHLITE,
  30. DISABLED,
  31. };
  32. virtual void update(){ aObject::update(); }
  33. virtual void render(){ aObject::render(); }
  34. void setState( int newState ){ state = (State)newState; }
  35. State getState( ) { return state; }
  36. void select(){ state = SELECTED; }
  37. void disable(){ state = DISABLED; }
  38. void highlite(){ state = HIGHLITE; }
  39. void deselect(){ state = state == DISABLED ? DISABLED : ENABLED; }
  40. virtual bool isChecked() { return false; }
  41. virtual void setCheck( bool ){}
  42. protected:
  43. State state;
  44. };
  45. class aTextListItem : public aListItem
  46. {
  47. public:
  48. aTextListItem(HGOSFONT3D newFont); // need the font, so we can determine the size
  49. aTextListItem( const aFont& newFont );
  50. aTextListItem( long fontResID );
  51. virtual ~aTextListItem();
  52. void setText( const char* text );
  53. void setText( long resID );
  54. const char* getText() const;
  55. void sizeToText();
  56. void init( FitIniFile& file, const char* blockName = "Text0" );
  57. virtual void render();
  58. void setAlignment( long newA ){ alignment = newA; }
  59. void forceToTop( bool bForce ) { bForceToTop = bForce; }
  60. protected:
  61. aTextListItem() {}
  62. void init( long fontResID );
  63. aFont font;
  64. EString text;
  65. long alignment;
  66. bool bForceToTop;
  67. };
  68. class aAnimTextListItem : public aTextListItem
  69. {
  70. public:
  71. aAnimTextListItem(HGOSFONT3D newFont) : aTextListItem( newFont ) {}
  72. aAnimTextListItem( const aFont& newFont ) : aTextListItem( newFont ){}
  73. aAnimTextListItem( long fontResID ) : aTextListItem( fontResID ){}
  74. aAnimTextListItem( const aAnimTextListItem& src );
  75. aAnimTextListItem& operator=( const aAnimTextListItem& src );
  76. void init( FitIniFile& file, const char* blockName = "Text0" );
  77. virtual void render();
  78. virtual void update();
  79. protected:
  80. aAnimGroup animInfo;
  81. void CopyData( const aAnimTextListItem& src );
  82. };
  83. class aLocalizedListItem : public aAnimTextListItem
  84. {
  85. public:
  86. aLocalizedListItem();
  87. virtual long init( FitIniFile* file, const char* blockName );
  88. virtual void render();
  89. void setHiddenText( const char* pText ){ hiddenText = pText; }
  90. const char* getHiddenText( ) const { return hiddenText;}
  91. protected:
  92. EString hiddenText;
  93. };
  94. class aListBox : public aObject
  95. {
  96. public:
  97. aListBox();
  98. virtual long init(long xPos, long yPos, long w, long h);
  99. void init( FitIniFile* file, const char* blockName );
  100. virtual void destroy();
  101. virtual void render();
  102. virtual void update();
  103. virtual int handleMessage( unsigned long message, unsigned long who );
  104. virtual void resize(long w, long h);
  105. virtual long AddItem(aListItem* itemString);
  106. virtual long InsertItem(aListItem* itemString, long where);
  107. virtual long RemoveItem( aListItem* itemString, bool bDelete );
  108. long ChangeItemString(short itemNumber, char* newString);
  109. long GetSelectedItem(void) {return itemSelected;};
  110. long GetCheckedItem() const;
  111. long SelectItem(long itemNumber);
  112. bool IsScrollActive(void) {return scrollActive;};
  113. long ActivateScrollbar(void);
  114. aListItem* GetItem(long itemNumber);
  115. long GetItemCount(){ return itemCount; }
  116. void removeAllItems( bool bDelete );
  117. void setSpaceBetweenItems( long newSpace ){ skipAmount = newSpace; }
  118. long getSpaceBetweenItems(){ return skipAmount; }
  119. void setSingleCheck(bool checkOnlyOne){ singleCheck = checkOnlyOne; }
  120. virtual void move( float offsetX, float offsetY );
  121. void setScrollPos( int pos );
  122. long getScrollBarWidth();
  123. void setOrange( bool bOrange );
  124. void enableAllItems();
  125. void setPressFX( int newFX ){ clickSFX = newFX; }
  126. void setHighlightFX( int newFX ){ highlightSFX = newFX; }
  127. void setDisabledFX( int newFX ){ disabledSFX = newFX; }
  128. void setTopSkip( long newSkip ){ topSkip = newSkip; }
  129. bool pointInScrollBar( long mouseX, long mouseY );
  130. float getScrollPos() {return scrollBar ? scrollBar->GetScrollPos() : 0; }
  131. protected:
  132. long itemCount;
  133. long itemSelected;
  134. long skipAmount;
  135. aListItem* items[MAX_LIST_ITEMS];
  136. mcScrollBar* scrollBar;
  137. long itemHeight;
  138. bool scrollActive;
  139. bool singleCheck;
  140. int clickSFX;
  141. int highlightSFX;
  142. int disabledSFX;
  143. int topSkip;
  144. void scroll( int amount );
  145. };
  146. /* Note that items in an aDropList items do not have to be aTextListItems, whereas in an
  147. aComboBox they do (well, selectable items do).*/
  148. class aDropList : public aObject
  149. {
  150. public:
  151. aDropList();
  152. virtual long init( FitIniFile* file, const char* blockName );
  153. virtual void destroy();
  154. void specialDestroy();
  155. virtual void render();
  156. virtual void update();
  157. virtual int handleMessage( unsigned long message, unsigned long who );
  158. virtual bool pointInside(long xPos, long yPos) const;
  159. //virtual void resize(long w, long h);
  160. virtual long AddItem(aListItem* itemString);
  161. long SelectItem(long item);
  162. aListBox &ListBox() { return listBox; }
  163. bool IsExpanded() { return listBox.isShowing(); }
  164. void IsExpanded(bool isExpanded);
  165. void disable( bool bDisable ){
  166. if ( bDisable )
  167. IsExpanded( 0 );
  168. expandButton.showGUIWindow( !bDisable );
  169. rects[0].showGUIWindow( !bDisable ); rects[1].showGUIWindow( !bDisable );
  170. }
  171. long AddItem( unsigned long textID, unsigned long color );
  172. long AddItem( const char* text, unsigned long color );
  173. long GetSelectedItem() const { return selectionIndex; }
  174. aDropList& operator=( const aDropList& );
  175. protected:
  176. aRect* rects;
  177. long rectCount;
  178. aAnimButton expandButton;
  179. aListBox listBox;
  180. float listBoxMaxHeight;
  181. int selectionIndex;
  182. aAnimTextListItem templateItem;
  183. aDropList( const aDropList& );
  184. long textLeft;
  185. long textTop;
  186. };
  187. class aComboBox : public aObject
  188. {
  189. public:
  190. aComboBox();
  191. ~aComboBox() {};
  192. virtual long init( FitIniFile* file, const char* blockName );
  193. virtual void destroy();
  194. virtual void render();
  195. virtual void update();
  196. virtual int handleMessage( unsigned long message, unsigned long who );
  197. virtual bool pointInside(long xPos, long yPos) const;
  198. //virtual void resize(long w, long h);
  199. virtual long AddItem(aListItem* itemString);
  200. long SelectItem(long item);
  201. void setReadOnly( bool bReadOnly ){ entry.setReadOnly( bReadOnly ); }
  202. long AddItem( unsigned long textID, unsigned long color );
  203. long AddItem( const char* text, unsigned long color );
  204. long GetSelectedItem() const { return selectionIndex; }
  205. aComboBox& operator=( const aComboBox& );
  206. aEdit &EditBox() { return entry; }
  207. aListBox &ListBox() { return listBox; }
  208. void setFocus( bool bFocus ) { EditBox().setFocus( bFocus ); }
  209. protected:
  210. aEdit entry;
  211. aRect* rects;
  212. long rectCount;
  213. aAnimButton expandButton;
  214. aListBox listBox;
  215. float listBoxMaxHeight;
  216. int selectionIndex;
  217. aComboBox( const aComboBox& );
  218. aAnimTextListItem templateItem;
  219. };
  220. #endif