ICONLIST.CPP 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910
  1. /*
  2. ** Command & Conquer Red Alert(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifdef WOLAPI_INTEGRATION
  19. // Iconlist.cpp - created by ajw 07/07/98
  20. // IconListClass is ListClass plus the option to include an icon on each line entry,
  21. // the option to have the class maintain its own copies of strings passed to it
  22. // for display, and the option to limit the maximum number of these strings that are
  23. // kept (entries are removed from the top when this maximum is reached).
  24. // Also added: multiple item selection capability. Note that the old selection code
  25. // runs as normal, but it simply not used when it comes time to display.
  26. // Also added: if mem. allocation is being done by this, the ability to break new items
  27. // into multiple lines of text is enabled.
  28. // Also added: extra data can be invisibly stored with each item, if memory allocation is
  29. // being done by this.
  30. // Extra data included 3 item preceding icons, 1 fixed position icon, an extra string,
  31. // an extra void pointer, and a color remapping value.
  32. #include "iconlist.h"
  33. #include "dibapi.h"
  34. int Format_Window_String_New( const char* string, int maxlinelen, int& width, int& height, char* szReturn, int iExtraChars );
  35. void CC_Draw_DIB( const char* pDIB, int xDest, int yDest, int iWidth, WindowNumberType window );
  36. //***********************************************************************************************
  37. IconListClass::IconListClass( int id, int x, int y, int w, int h, TextPrintType flags, void const * up, void const * down,
  38. bool bResponsibleForStringAlloc, int iSelectionType, int iMaxItemsSaved ) :
  39. ListClass( id, x, y, w, h, flags, up, down )
  40. {
  41. // If bResponsibleForStringAlloc, COPIES of strings are stored in the list. Deletion is
  42. // handled by this class. Icons are different - the caller is responsible for what's on
  43. // the other end of the pointer.
  44. bDoAlloc = bResponsibleForStringAlloc;
  45. // iSelectionType = 0 for no selection shown, 1 for normal ListClass selection, 2 for n multiple selections
  46. if( iSelectionType < 0 || iSelectionType > 2 ) iSelectionType = 1;
  47. iSelectType = iSelectionType;
  48. // If iMaxItemsSaved is 0, there is no limit to the number of text lines. The list can grow forever.
  49. // Otherwise items are deleted from the head of the list when the maximum is passed.
  50. // iMaxItemsSaved only applies when bResponsibleForStringAlloc.
  51. iMaxItems = iMaxItemsSaved;
  52. }
  53. //***********************************************************************************************
  54. IconListClass::~IconListClass( void )
  55. {
  56. // Delete the IconList_ItemExtras structs created to hold extra info on each item.
  57. for( int i = 0; i < ExtrasList.Count(); i++ )
  58. delete (IconList_ItemExtras*)ExtrasList[ i ];
  59. if( bDoAlloc )
  60. {
  61. // Delete all alloc'ed strings.
  62. for( int i = 0; i < List.Count(); i++ )
  63. delete [] (char*)List[i];
  64. }
  65. }
  66. /***********************************************************************************************
  67. * IconListClass::Add_Item -- Adds an item to the list box. *
  68. * *
  69. * This will add the specified string to the list box. The string is added to the end *
  70. * of the list. *
  71. * *
  72. * INPUT: text -- Pointer to the string to add to the list box. *
  73. * pIcon -- Pointer to the shape to add.
  74. * IconKind -- Indicates what type of image pIcon points to.
  75. * szExtraDataString -- Extra string data that gets copied and stored along with item.
  76. * szExtraDataPtr -- Extra data that gets stored along with item.
  77. * pColorRemap -- Points to a color remapping used when drawing the item.
  78. *
  79. * OUTPUT: Returns new item index. *
  80. * WARNINGS: none *
  81. * HISTORY: 07/07/1998 ajw : Created. *
  82. *=============================================================================================*/
  83. int IconListClass::Add_Item(char const * text)
  84. {
  85. return Add_Item( text, NULL, NULL, ICON_SHAPE );
  86. }
  87. int IconListClass::Add_Item( const char* text, const char* szHelp,
  88. void* pIcon0, ICONKIND IconKind0, const char* szExtraDataString /* = NULL */,
  89. void* pvExtraDataPtr /* = NULL */, RemapControlType* pColorRemap /* = NULL */,
  90. void* pIcon1 /* = NULL */, ICONKIND IconKind1 /* = ICON_SHAPE */,
  91. void* pIcon2 /* = NULL */, ICONKIND IconKind2 /* = ICON_SHAPE */,
  92. void* pFixedIcon /* = NULL */, ICONKIND FixedIconKind /* = ICON_SHAPE */, int iXFixedIcon /* = 0 */, int iYFixedIcon /* = 0 */, int iFixedIconWidth /* = -1 */ )
  93. {
  94. if( text )
  95. {
  96. if( bDoAlloc )
  97. {
  98. int iRetVal;
  99. char* szText = new char[ strlen( text ) + 51 ]; // 50 extra chars added for line breaks later.
  100. strcpy( szText, text );
  101. int iWidthMax, iHeight;
  102. // Stupid usage of globals for font stuff... <grumble>
  103. if( TextFlags == TPF_TYPE )
  104. {
  105. void* pFontBefore = Set_Font( TypeFontPtr );
  106. DWORD FontXSpacingBefore = FontXSpacing;
  107. FontXSpacing = -2;
  108. int iWidthToClipAt = IsScrollActive ? Width : Width - UpGadget.Width;
  109. // This call will place '\r's in the string where line breaks should occur.
  110. Format_Window_String_New( text, iWidthToClipAt, iWidthMax, iHeight, szText, 50 );
  111. Set_Font( pFontBefore );
  112. FontXSpacing = FontXSpacingBefore; // Just in case it matters... Doubt it.
  113. }
  114. else
  115. {
  116. // Currently never called. Test well if you use IconList with a font other than TPF_TYPE,
  117. // as the character spacing globals get set weirdly, I've found.
  118. int iWidthToClipAt = IsScrollActive ? Width : Width - UpGadget.Width;
  119. // This call will place '\r's in the string where line breaks should occur.
  120. Format_Window_String_New( text, iWidthToClipAt, iWidthMax, iHeight, szText, 50 );
  121. }
  122. // Each break character causes a line to be added to list.
  123. char szBreakchars[] = "\r\n\v\f";
  124. char* szToken;
  125. char* szNextChar = szText;
  126. szToken = strtok( szText, szBreakchars );
  127. while( szToken )
  128. {
  129. while( szNextChar < szToken )
  130. {
  131. // We expected szToken to begin at szNextChar. Since it doesn't, extra break
  132. // characters must have been removed by strtok as they were adjacent. We want
  133. // a line break for every break character, so add lines for each space that
  134. // szNextChar is off by.
  135. szNextChar++;
  136. Add_Item_Detail( " ", szHelp, pIcon0, IconKind0, szExtraDataString, pvExtraDataPtr, pColorRemap, pIcon1, IconKind1, pIcon2, IconKind2, pFixedIcon, FixedIconKind, iXFixedIcon, iYFixedIcon, iFixedIconWidth );
  137. }
  138. iRetVal = Add_Item_Detail( szToken, szHelp, pIcon0, IconKind0, szExtraDataString, pvExtraDataPtr, pColorRemap, pIcon1, IconKind1, pIcon2, IconKind2, pFixedIcon, FixedIconKind, iXFixedIcon, iYFixedIcon, iFixedIconWidth );
  139. // Expect next token two chars after the end of this one.
  140. szNextChar = szToken + strlen( szToken ) + 1;
  141. // Get next token.
  142. szToken = strtok( NULL, szBreakchars );
  143. }
  144. delete [] szText;
  145. return iRetVal; // Last value returned by ListClass::Add_Item
  146. }
  147. else
  148. {
  149. // Add one item to list.
  150. IconList_ItemExtras* pItemExtra = new IconList_ItemExtras;
  151. pItemExtra->bMultiSelected = false;
  152. pItemExtra->pIcon[0] = pIcon0;
  153. pItemExtra->IconKind[0] = IconKind0;
  154. pItemExtra->pIcon[1] = pIcon1;
  155. pItemExtra->IconKind[1] = IconKind1;
  156. pItemExtra->pIcon[2] = pIcon2;
  157. pItemExtra->IconKind[2] = IconKind2;
  158. pItemExtra->FixedIcon.pIcon = pFixedIcon;
  159. pItemExtra->FixedIcon.IconKind = FixedIconKind;
  160. pItemExtra->FixedIcon.xOffset = iXFixedIcon;
  161. pItemExtra->FixedIcon.yOffset = iYFixedIcon;
  162. pItemExtra->FixedIcon.iWidth = iFixedIconWidth;
  163. pItemExtra->pvExtraData = pvExtraDataPtr;
  164. pItemExtra->pColorRemap = pColorRemap;
  165. if( szHelp )
  166. {
  167. // Copy help into new help string.
  168. pItemExtra->szHelp = new char[ strlen( szHelp ) + 1 ];
  169. strcpy( pItemExtra->szHelp, szHelp );
  170. }
  171. if( szExtraDataString )
  172. {
  173. // Copy special data string into new extradata string.
  174. pItemExtra->szExtraData = new char[ strlen( szExtraDataString ) + 1 ];
  175. strcpy( pItemExtra->szExtraData, szExtraDataString );
  176. }
  177. ExtrasList.Add( pItemExtra );
  178. return ListClass::Add_Item( text );
  179. }
  180. }
  181. else
  182. {
  183. // (no text for new item)
  184. if( pIcon0 || pIcon1 || pIcon2 )
  185. {
  186. // Note: Cannot add an entry without text unless string allocation is being handled by me.
  187. // Otherwise, because we want the icon to show up, create a blank entry for the ListClass.
  188. if( bDoAlloc )
  189. {
  190. IconList_ItemExtras* pItemExtra = new IconList_ItemExtras;
  191. pItemExtra->bMultiSelected = false;
  192. pItemExtra->pIcon[0] = pIcon0;
  193. pItemExtra->IconKind[0] = IconKind0;
  194. pItemExtra->pIcon[1] = pIcon1;
  195. pItemExtra->IconKind[1] = IconKind1;
  196. pItemExtra->pIcon[2] = pIcon2;
  197. pItemExtra->IconKind[2] = IconKind2;
  198. pItemExtra->FixedIcon.pIcon = pFixedIcon;
  199. pItemExtra->FixedIcon.IconKind = FixedIconKind;
  200. pItemExtra->FixedIcon.xOffset = iXFixedIcon;
  201. pItemExtra->FixedIcon.yOffset = iYFixedIcon;
  202. pItemExtra->FixedIcon.iWidth = iFixedIconWidth;
  203. pItemExtra->pvExtraData = pvExtraDataPtr;
  204. pItemExtra->pColorRemap = pColorRemap;
  205. if( szHelp )
  206. {
  207. // Copy help into new help string.
  208. pItemExtra->szHelp = new char[ strlen( szHelp ) + 1 ];
  209. strcpy( pItemExtra->szHelp, szHelp );
  210. }
  211. if( szExtraDataString )
  212. {
  213. // Copy special data string into new extradata string.
  214. pItemExtra->szExtraData = new char[ strlen( szExtraDataString ) + 1 ];
  215. strcpy( pItemExtra->szExtraData, szExtraDataString );
  216. }
  217. ExtrasList.Add( pItemExtra );
  218. if( iMaxItems && List.Count() == iMaxItems )
  219. {
  220. // Delete head of list.
  221. Remove_Item( 0 );
  222. }
  223. // Create new string, essentially blank.
  224. char* szText = new char[2];
  225. strcpy( szText, " " );
  226. return ListClass::Add_Item( szText );
  227. }
  228. else
  229. // Cannot add entry, as text is blank and ListClass::Add_Item will do nothing.
  230. // The Icon we want will not show up.
  231. return List.Count() - 1;
  232. }
  233. else
  234. return ListClass::Add_Item( text );
  235. }
  236. }
  237. //***********************************************************************************************
  238. int IconListClass::Add_Item_Detail( const char* szToken, const char* szHelp,
  239. void* pIcon0, ICONKIND IconKind0, const char* szExtraDataString,
  240. void* pvExtraData, RemapControlType* pColorRemap,
  241. void* pIcon1, ICONKIND IconKind1,
  242. void* pIcon2, ICONKIND IconKind2,
  243. void* pFixedIcon, ICONKIND FixedIconKind, int iXFixedIcon, int iYFixedIcon, int iFixedIconWidth )
  244. {
  245. // Broken out of above function as it is repeated.
  246. // Add one item to list.
  247. // Too many entries?
  248. if( iMaxItems && List.Count() == iMaxItems )
  249. {
  250. // Delete head of list.
  251. Remove_Item( 0 );
  252. }
  253. // Create icon entry.
  254. IconList_ItemExtras* pItemExtra = new IconList_ItemExtras;
  255. pItemExtra->bMultiSelected = false;
  256. pItemExtra->pIcon[0] = pIcon0; // ajw - Question: repeat the icon for each entry? make it optional?
  257. pItemExtra->IconKind[0] = IconKind0;
  258. pItemExtra->pIcon[1] = pIcon1;
  259. pItemExtra->IconKind[1] = IconKind1;
  260. pItemExtra->pIcon[2] = pIcon2;
  261. pItemExtra->IconKind[2] = IconKind2;
  262. pItemExtra->FixedIcon.pIcon = pFixedIcon;
  263. pItemExtra->FixedIcon.IconKind = FixedIconKind;
  264. pItemExtra->FixedIcon.xOffset = iXFixedIcon;
  265. pItemExtra->FixedIcon.yOffset = iYFixedIcon;
  266. pItemExtra->FixedIcon.iWidth = iFixedIconWidth;
  267. pItemExtra->pvExtraData = pvExtraData;
  268. pItemExtra->pColorRemap = pColorRemap;
  269. if( szHelp )
  270. {
  271. // Copy help into new help string.
  272. pItemExtra->szHelp = new char[ strlen( szHelp ) + 1 ];
  273. strcpy( pItemExtra->szHelp, szHelp );
  274. }
  275. if( szExtraDataString )
  276. {
  277. // Copy special data string into new extradata string.
  278. pItemExtra->szExtraData = new char[ strlen( szExtraDataString ) + 1 ];
  279. strcpy( pItemExtra->szExtraData, szExtraDataString );
  280. }
  281. ExtrasList.Add( pItemExtra );
  282. // Create text entry.
  283. // Copy text to new string.
  284. char* szTextBit = new char[ strlen( szToken ) + 1 ];
  285. strcpy( szTextBit, szToken );
  286. return ListClass::Add_Item( szTextBit );
  287. }
  288. //***********************************************************************************************
  289. int IconListClass::Add_Item( int text )
  290. {
  291. return Add_Item( Text_String(text), NULL, NULL, ICON_SHAPE );
  292. }
  293. //***********************************************************************************************
  294. int IconListClass::Add_Item( int text, const char* szHelp,
  295. void* pIcon0, ICONKIND IconKind0, const char* szExtraDataString /* = NULL */,
  296. void* pvExtraDataPtr /* = NULL */, RemapControlType* pColorRemap /* = NULL */,
  297. void* pIcon1 /* = NULL */, ICONKIND IconKind1 /* = ICON_SHAPE */,
  298. void* pIcon2 /* = NULL */, ICONKIND IconKind2 /* = ICON_SHAPE */,
  299. void* pFixedIcon /* = NULL */, ICONKIND FixedIconKind /* = ICON_SHAPE */, int iXFixedIcon /* = 0 */, int iYFixedIcon /* = 0 */, int iFixedIconWidth /* = -1 */ )
  300. {
  301. return Add_Item( Text_String(text), szHelp, pIcon0, IconKind0, szExtraDataString, pvExtraDataPtr, pColorRemap,
  302. pIcon1, IconKind1, pIcon2, IconKind2, pFixedIcon, FixedIconKind, iXFixedIcon, iYFixedIcon, iFixedIconWidth );
  303. }
  304. //***********************************************************************************************
  305. void IconListClass::Remove_Item( char const * text )
  306. {
  307. if( text )
  308. Remove_Item( List.ID(text) );
  309. }
  310. //***********************************************************************************************
  311. void IconListClass::Remove_Item( int index )
  312. {
  313. if( (unsigned)index < List.Count() )
  314. {
  315. delete (IconList_ItemExtras*)ExtrasList[ index ];
  316. ExtrasList.Delete( index );
  317. if( bDoAlloc )
  318. // Delete alloc'ed string.
  319. delete [] (char*)List[index];
  320. ListClass::Remove_Item( index );
  321. // I should probably put this in ListClass:Remove_Item(), as it seems clearly to be
  322. // missing, but I want to only affect my own new code, to not introduce possible bugs.
  323. // Shift the selected index if appropriate...
  324. if( SelectedIndex >= index )
  325. {
  326. SelectedIndex--;
  327. if( SelectedIndex < 0 )
  328. SelectedIndex = 0;
  329. }
  330. }
  331. }
  332. /***********************************************************************************************
  333. * IconListClass::Draw_Entry -- Calls ListClass::Draw_Entry, then adds icon. *
  334. * *
  335. * This routine is called by the Draw_Me function when it desired to redraw a particular *
  336. * text line in the list box. *
  337. * *
  338. * INPUT: index -- The index of the list entry to draw. This index is based on the *
  339. * total list and NOT the current visible view page. *
  340. * *
  341. * x,y -- Pixel coordinates for the upper left corner of the text entry. *
  342. * *
  343. * width -- The maximum width that the text may draw over. It is expected that *
  344. * this drawing routine entirely fills this length. *
  345. * *
  346. * selected -- bool; Is this a selected (highlighted) listbox entry? *
  347. * *
  348. * OUTPUT: none *
  349. * WARNINGS: none *
  350. * HISTORY: *
  351. * 07/07/1998 ajw: Created. *
  352. *=============================================================================================*/
  353. #define PREICONGAP 1
  354. #define ICONTEXTGAP 2
  355. void IconListClass::Draw_Entry( int index, int x, int y, int width, int selected )
  356. {
  357. IconList_ItemExtras* pExtras = (IconList_ItemExtras*)ExtrasList[ index ];
  358. int xText = x;
  359. // ajw If I end up needing to use SHAPEs for icons, figure out shape width here and offset x.
  360. bool bIconsPresent = false;
  361. for( int iIcon = 0; iIcon != 3; iIcon++ )
  362. if( pExtras->pIcon[ iIcon ] && pExtras->IconKind[ iIcon ] == ICON_DIB )
  363. {
  364. // Push text over to accommodate icon.
  365. int iWidthIcon = PREICONGAP + DIBWidth( (char*)pExtras->pIcon[ iIcon ] );
  366. xText += iWidthIcon;
  367. width -= iWidthIcon;
  368. bIconsPresent = true;
  369. }
  370. if( bIconsPresent )
  371. {
  372. xText += ICONTEXTGAP;
  373. width -= ICONTEXTGAP;
  374. }
  375. RemapControlType* pRemap = pExtras->pColorRemap;
  376. if( !pRemap )
  377. {
  378. // Tabs hack. If there are icons, and a tab, push back the FIRST tab appropriately.
  379. // (Ignore others. This is a hack because having more than one tab will now break this.)
  380. // See local version of this same hack, below.
  381. int TempTabs;
  382. const int* TabsSave;
  383. if( Tabs )
  384. {
  385. TempTabs = *Tabs - ( xText - x );
  386. TabsSave = Tabs;
  387. Tabs = &TempTabs;
  388. }
  389. switch( iSelectType )
  390. {
  391. case 0:
  392. // Don't draw any items selected (even if they are, really, in ListClass).
  393. ListClass::Draw_Entry( index, xText, y, width, false );
  394. break;
  395. case 1:
  396. ListClass::Draw_Entry( index, xText, y, width, selected );
  397. break;
  398. case 2:
  399. // Ignore 'selected' parameter. We use our own records.
  400. ListClass::Draw_Entry( index, xText, y, width, pExtras->bMultiSelected );
  401. break;
  402. }
  403. // Restore Tabs.
  404. if( Tabs )
  405. Tabs = TabsSave;
  406. }
  407. else
  408. {
  409. // Use different color remapping.
  410. // This is largely copied straight from ListClass::Draw_Entry()...
  411. TextPrintType flags = TextFlags;
  412. bool bShowSelected;
  413. switch( iSelectType )
  414. {
  415. case 0:
  416. bShowSelected = false;
  417. break;
  418. case 1:
  419. bShowSelected = selected;
  420. break;
  421. case 2:
  422. bShowSelected = pExtras->bMultiSelected;
  423. break;
  424. }
  425. if( bShowSelected )
  426. {
  427. flags = flags | TPF_BRIGHT_COLOR;
  428. LogicPage->Fill_Rect( xText, y, xText + width - 1, y + LineHeight - 1, pRemap->Shadow );
  429. }
  430. else
  431. {
  432. if (!(flags & TPF_USE_GRAD_PAL))
  433. {
  434. flags = flags | TPF_MEDIUM_COLOR;
  435. }
  436. }
  437. // Tabs hack. If there are icons, and a tab, push back the FIRST tab appropriately.
  438. // (Ignore others. This is a hack because having more than one tab will now break this.)
  439. if( Tabs )
  440. {
  441. int tab = *Tabs - ( xText - x );
  442. Conquer_Clip_Text_Print( List[index], xText, y, pRemap, TBLACK, flags, width, &tab );
  443. }
  444. else
  445. Conquer_Clip_Text_Print( List[index], xText, y, pRemap, TBLACK, flags, width, NULL );
  446. }
  447. // Draw fixed position icon.
  448. if( pExtras->FixedIcon.pIcon )
  449. {
  450. if( pExtras->FixedIcon.IconKind == ICON_SHAPE )
  451. CC_Draw_Shape( pExtras->FixedIcon.pIcon, 0, x + pExtras->FixedIcon.xOffset, y + pExtras->FixedIcon.yOffset, WINDOW_MAIN, SHAPE_NORMAL );
  452. // Put similar code in here for shapes if used...
  453. else
  454. CC_Draw_DIB( (char*)pExtras->FixedIcon.pIcon, x + pExtras->FixedIcon.xOffset, y + pExtras->FixedIcon.yOffset, pExtras->FixedIcon.iWidth, WINDOW_MAIN );
  455. }
  456. // Draw variable position left-of-text icons.
  457. for( iIcon = 0; iIcon != 3; iIcon++ )
  458. {
  459. if( pExtras->pIcon[ iIcon ] )
  460. {
  461. x += PREICONGAP;
  462. if( pExtras->IconKind[ iIcon ] == ICON_SHAPE )
  463. CC_Draw_Shape( pExtras->pIcon[ iIcon ], 0, x, y, WINDOW_MAIN, SHAPE_NORMAL );
  464. // Put similar code in here for shapes if used...
  465. else
  466. {
  467. CC_Draw_DIB( (char*)pExtras->pIcon[ iIcon ], x, y, 9999, WINDOW_MAIN );
  468. x += DIBWidth( (char*)pExtras->pIcon[ iIcon ] );
  469. }
  470. }
  471. }
  472. }
  473. //***********************************************************************************************
  474. int IconListClass::Action(unsigned flags, KeyNumType & key)
  475. {
  476. // Overriding of function is for the sake of MultiSelecting only.
  477. if( iSelectType == 2 )
  478. {
  479. if( !( flags & LEFTRELEASE ) )
  480. {
  481. if( !( flags & KEYBOARD ) )
  482. {
  483. int index = Get_Mouse_Y() - (Y+1);
  484. index = index / LineHeight;
  485. int iSelected = CurrentTopIndex + index;
  486. iSelected = min( iSelected, List.Count() - 1 );
  487. if( iSelected >= 0 )
  488. ((IconList_ItemExtras*)ExtrasList[ iSelected ])->bMultiSelected =
  489. !((IconList_ItemExtras*)ExtrasList[ iSelected ])->bMultiSelected;
  490. }
  491. }
  492. }
  493. return ListClass::Action( flags, key );
  494. }
  495. //***********************************************************************************************
  496. // * IconListClass::Show_Last_Item -- Scrolls listbox down to ensure that last entry is visible.
  497. // ajw 07/09/98
  498. void IconListClass::Show_Last_Item()
  499. {
  500. int iItemLast = List.Count() - 1;
  501. if( iItemLast - LineCount + 1 != CurrentTopIndex )
  502. {
  503. Flag_To_Redraw();
  504. Set_View_Index( iItemLast - LineCount + 1 );
  505. }
  506. }
  507. //***********************************************************************************************
  508. bool IconListClass::bItemIsMultiSelected( int index ) const
  509. {
  510. if( index < ExtrasList.Count() && index > -1 )
  511. return ( (IconList_ItemExtras*)ExtrasList[ index ] )->bMultiSelected;
  512. else
  513. return false;
  514. }
  515. //***********************************************************************************************
  516. void IconListClass::MultiSelect( int index, bool bSelect )
  517. {
  518. if( index < ExtrasList.Count() && index > -1 )
  519. ( (IconList_ItemExtras*)ExtrasList[ index ] )->bMultiSelected = bSelect;
  520. }
  521. //***********************************************************************************************
  522. const char* IconListClass::Get_Item_ExtraDataString( int index ) const
  523. {
  524. // Returns const pointer to the hidden "extra data" string that can be associated with each item.
  525. // This is NULL if no extra data was assigned.
  526. if( index < ExtrasList.Count() && index > -1 )
  527. {
  528. return ( (IconList_ItemExtras*)ExtrasList[ index ] )->szExtraData;
  529. }
  530. return NULL;
  531. }
  532. //***********************************************************************************************
  533. void IconListClass::Set_Item_ExtraDataString( int index, const char* szNewString )
  534. {
  535. if( index < ExtrasList.Count() && index > -1 )
  536. {
  537. IconList_ItemExtras* pItemExtra = (IconList_ItemExtras*)ExtrasList[ index ];
  538. if( pItemExtra->szExtraData )
  539. {
  540. // Delete the existing string.
  541. delete [] pItemExtra->szExtraData;
  542. }
  543. if( szNewString )
  544. {
  545. // Copy special data string into new extradata string.
  546. pItemExtra->szExtraData = new char[ strlen( szNewString ) + 1 ];
  547. strcpy( pItemExtra->szExtraData, szNewString );
  548. }
  549. else
  550. pItemExtra->szExtraData = NULL;
  551. }
  552. }
  553. //***********************************************************************************************
  554. void* IconListClass::Get_Item_ExtraDataPtr( int index ) const
  555. {
  556. // Returns the hidden "extra data" void pointer that can be associated with each item.
  557. // This is NULL if no value was assigned.
  558. if( index < ExtrasList.Count() && index > -1 )
  559. return ( (IconList_ItemExtras*)ExtrasList[ index ] )->pvExtraData;
  560. else
  561. return NULL;
  562. }
  563. //***********************************************************************************************
  564. void IconListClass::Set_Item_ExtraDataPtr( int index, void* pNewValue )
  565. {
  566. // Sets the hidden "extra data" void pointer that can be associated with each item.
  567. if( index < ExtrasList.Count() && index > -1 )
  568. ( (IconList_ItemExtras*)ExtrasList[ index ] )->pvExtraData = pNewValue;
  569. }
  570. //***********************************************************************************************
  571. const IconList_ItemExtras* IconListClass::Get_ItemExtras( int index ) const
  572. {
  573. if( index < ExtrasList.Count() && index > -1 )
  574. return (IconList_ItemExtras*)ExtrasList[ index ];
  575. else
  576. return NULL;
  577. }
  578. //***********************************************************************************************
  579. const char* IconListClass::Get_Item_Help( int index ) const
  580. {
  581. // Returns pointer to the string allocated for tooltip help.
  582. if( index < ExtrasList.Count() && index > -1 )
  583. return ( (IconList_ItemExtras*)ExtrasList[ index ] )->szHelp;
  584. else
  585. return NULL;
  586. }
  587. //***********************************************************************************************
  588. void IconListClass::Clear()
  589. {
  590. // Removes all items from list.
  591. // Delete the IconList_ItemExtras structs created to hold extra info on each item.
  592. for( int i = 0; i < ExtrasList.Count(); i++ )
  593. delete (IconList_ItemExtras*)ExtrasList[ i ];
  594. ExtrasList.Clear();
  595. if( bDoAlloc )
  596. {
  597. // Delete all alloc'ed strings.
  598. for( int i = 0; i < List.Count(); i++ )
  599. delete [] (char*)List[i];
  600. }
  601. List.Clear();
  602. Remove_Scroll_Bar();
  603. CurrentTopIndex = 0;
  604. }
  605. //***********************************************************************************************
  606. RemapControlType* IconListClass::Get_Item_Color( int index )
  607. {
  608. if( index < ExtrasList.Count() && index > -1 )
  609. return ( (IconList_ItemExtras*)ExtrasList[ index ] )->pColorRemap;
  610. else
  611. return NULL;
  612. }
  613. //***********************************************************************************************
  614. void IconListClass::Set_Item_Color( int index, RemapControlType* pColorRemap )
  615. {
  616. if( index < ExtrasList.Count() && index > -1 )
  617. ( (IconList_ItemExtras*)ExtrasList[ index ] )->pColorRemap = pColorRemap;
  618. }
  619. //***********************************************************************************************
  620. int IconListClass::Find( const char* szItemToFind )
  621. {
  622. // Returns -1 if szItemToFind is not found as the text BEGINNING one of the list entries, else index of item.
  623. // Compare is case-sensitive.
  624. for( int i = 0; i < List.Count(); i++ )
  625. {
  626. if( strncmp( List[ i ], szItemToFind, strlen( szItemToFind ) ) == 0 )
  627. return i;
  628. }
  629. return -1;
  630. }
  631. //***********************************************************************************************
  632. int IconListClass::FindColor( RemapControlType* pColorRemap )
  633. {
  634. // Returns -1 if no items of specified color are found, else first index. Assumes colorptr == colorptr is a valid equality test.
  635. for( int i = 0; i < List.Count(); i++ )
  636. {
  637. if( Get_Item_Color( i ) == pColorRemap )
  638. return i;
  639. }
  640. return -1;
  641. }
  642. //***********************************************************************************************
  643. bool IconListClass::Set_Item( unsigned int index, const char* szText )
  644. {
  645. // Resets the text string allocated for an item.
  646. if( !bDoAlloc || index >= List.Count() )
  647. return false;
  648. // Delete alloc'ed string.
  649. delete [] (char*)List[ index ];
  650. // Copy text to new string.
  651. char* szTextNew = new char[ strlen( szText ) + 1 ];
  652. strcpy( szTextNew, szText );
  653. // Reassign List's ptr.
  654. List[ index ] = szTextNew;
  655. return true;
  656. }
  657. //***********************************************************************************************
  658. bool IconListClass::Set_Icon( unsigned int index, unsigned int iIconNumber, void* pIcon, ICONKIND IconKind )
  659. {
  660. if( index >= List.Count() )
  661. return false;
  662. // Sets one of the left-aligned icons.
  663. ( (IconList_ItemExtras*)ExtrasList[ index ] )->pIcon[ iIconNumber ] = pIcon;
  664. ( (IconList_ItemExtras*)ExtrasList[ index ] )->IconKind[ iIconNumber ] = IconKind;
  665. return true;
  666. }
  667. //***********************************************************************************************
  668. int IconListClass::GetRealWidth() // sigh
  669. {
  670. if( IsScrollActive )
  671. return Width + ScrollGadget.Width;
  672. return Width;
  673. }
  674. //***********************************************************************************************
  675. void IconListClass::Resize( int x, int y, int w, int h )
  676. {
  677. Remove_Scroll_Bar(); // If there is one.
  678. X = x;
  679. Y = y;
  680. Width = w;
  681. Height = h;
  682. Set_Position( x, y );
  683. LineCount = (h-1) / LineHeight;
  684. if (List.Count() > LineCount) {
  685. Add_Scroll_Bar();
  686. }
  687. Flag_To_Redraw();
  688. }
  689. //***********************************************************************************************
  690. int IconListClass::IndexUnderMouse()
  691. {
  692. // Returns index of line that mouse is currently over, or -1 for mouse not hitting valid index.
  693. // Assumes that x position of mouse is already known to be over the iconlist.
  694. int index = Get_Mouse_Y() - (Y+1);
  695. index = index / LineHeight + CurrentTopIndex;
  696. if( index > List.Count() - 1 || index < 0 )
  697. return -1;
  698. return index;
  699. }
  700. //***********************************************************************************************
  701. int IconListClass::OffsetToIndex( int iIndex, int y )
  702. {
  703. // Finds the current offset of item iIndex from the current top view index, in pixels, and add it to y.
  704. return y + ( iIndex - CurrentTopIndex ) * LineHeight;
  705. }
  706. //***********************************************************************************************
  707. //***********************************************************************************************
  708. // * Format_Window_String_New
  709. // Functions like Format_Window_String except it fixes an infinite loop bug that occurred when strings
  710. // lacked suitable break points, eliminates the '@' as an escape character, and operates differently
  711. // in that it leaves the original string along, writing results instead to a second string parameter,
  712. // that is iExtraChars longer than the original string. This is all a big hack so that I can insert
  713. // extra break characters when a break in a long single word has to be made.
  714. // Hey - it's better than an infinite loop that forces you to reset your machine, as in the original code...
  715. int Format_Window_String_New( const char* string, int maxlinelen, int& width, int& height, char* szReturn, int iExtraChars )
  716. {
  717. int linelen;
  718. int lines = 0;
  719. width = 0;
  720. height = 0;
  721. // In no string was passed in, then there are no lines.
  722. if (!string) return(0);
  723. // While there are more letters left divide the line up.
  724. while (*string) {
  725. linelen = 0;
  726. height += FontHeight + FontYSpacing;
  727. lines++;
  728. // While the current line is less then the max length...
  729. *szReturn = *string;
  730. linelen += Char_Pixel_Width( *string );
  731. while ( linelen < maxlinelen && *string != '\r' && *string != '\0' )
  732. {
  733. *++szReturn = *++string;
  734. linelen += Char_Pixel_Width( *string );
  735. }
  736. // if the line is too long...
  737. if (linelen >= maxlinelen)
  738. {
  739. /*
  740. ** Back up to an appropriate location to break.
  741. */
  742. const char* stringOverEnd = string;
  743. while( linelen > 0 && *string != ' ' && *string != '\r' && *string != '\0' )
  744. {
  745. linelen -= Char_Pixel_Width(*string--);
  746. }
  747. if( linelen <= 0 )
  748. {
  749. // We could not find a nice break point.
  750. // Go back one char from over-the-end point and add in a break there.
  751. string = stringOverEnd - 1;
  752. if( iExtraChars > 0 )
  753. iExtraChars--; // One less to make use of later.
  754. else
  755. // We've used up all our extras characters.
  756. // Put in a break below by wiping out a valid char here.
  757. szReturn--;
  758. }
  759. else
  760. {
  761. // Back up szReturn to same location.
  762. szReturn -= ( stringOverEnd - string );
  763. }
  764. }
  765. /*
  766. ** Record the largest width of the worst case string.
  767. */
  768. if (linelen > width) {
  769. width = linelen;
  770. }
  771. /*
  772. ** Force a break at the end of the line.
  773. */
  774. if (*string) {
  775. *szReturn++ = '\r';
  776. string++;
  777. }
  778. }
  779. return(lines);
  780. }
  781. //***********************************************************************************************
  782. void CC_Draw_DIB( const char* pDIB, int xDest, int yDest, int iWidth, WindowNumberType window )
  783. {
  784. // A very basic DIB drawing routine. No clipping. No edge of window overrun checking.
  785. // If iWidth is too large, default width of dib is used.
  786. // If iWidth is negative, dib isn't drawn.
  787. if( pDIB && iWidth >= 0 )
  788. {
  789. int iWidthDIB = DIBWidth( pDIB );
  790. int iHeight = DIBHeight( pDIB );
  791. const char* pBits = FindDIBBits( pDIB );
  792. int iSrcPitch = ( iWidthDIB + 3 ) & ~3;
  793. if( iWidth > iWidthDIB )
  794. iWidth = iWidthDIB;
  795. GraphicViewPortClass draw_window( LogicPage->Get_Graphic_Buffer(),
  796. WindowList[window][WINDOWX] + LogicPage->Get_XPos(),
  797. WindowList[window][WINDOWY] + LogicPage->Get_YPos(),
  798. WindowList[window][WINDOWWIDTH],
  799. WindowList[window][WINDOWHEIGHT] );
  800. if( draw_window.Lock() )
  801. {
  802. int iDestPitch = draw_window.Get_Pitch() + draw_window.Get_Width(); // Meaning of "Pitch" in this class seems to mean the eol skip.
  803. char* pLineDest = (char*)draw_window.Get_Offset() + xDest + ( yDest + iHeight - 1 ) * iDestPitch;
  804. const char* pLineSrc = pBits;
  805. for( int y = 0; y != iHeight; y++ )
  806. {
  807. char* pDest = pLineDest;
  808. const char* pSrc = pLineSrc;
  809. for( int x = 0; x != iWidth; x++ )
  810. {
  811. *pDest++ = *pSrc++;
  812. }
  813. pLineDest -= iDestPitch;
  814. pLineSrc += iSrcPitch;
  815. }
  816. draw_window.Unlock();
  817. }
  818. }
  819. // else
  820. // debugprint( "CC_Draw_DIB bad case ------------ pDib %i, iWidth %i\n", pDIB, iWidth );
  821. }
  822. #endif