LIST.CPP (49269B)
1 // 2 // Copyright 2020 Electronic Arts Inc. 3 // 4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 5 // software: you can redistribute it and/or modify it under the terms of 6 // the GNU General Public License as published by the Free Software Foundation, 7 // either version 3 of the License, or (at your option) any later version. 8 9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 10 // in the hope that it will be useful, but with permitted additional restrictions 11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 12 // distributed with this program. You should have received a copy of the 13 // GNU General Public License along with permitted additional restrictions 14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection 15 16 /* $Header: F:\projects\c&c\vcs\code\list.cpv 2.17 16 Oct 1995 16:51:36 JOE_BOSTIC $ */ 17 /*********************************************************************************************** 18 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S *** 19 *********************************************************************************************** 20 * * 21 * Project Name : Command & Conquer * 22 * * 23 * File Name : LIST.CPP * 24 * * 25 * Programmer : Joe L. Bostic * 26 * * 27 * Start Date : 01/15/95 * 28 * * 29 * Last Update : June 25, 1995 [JLB] * 30 * * 31 *---------------------------------------------------------------------------------------------* 32 * Functions: * 33 * ListClass::Add -- This object adds itself to the given list * 34 * ListClass::Add_Head -- This gadget makes itself the head of the given list. * 35 * ListClass::Add_Item -- Adds a text item (as number) to the list box. * 36 * ListClass::Add_Item -- Adds an item to the list box. * 37 * ListClass::Add_Scroll_Bar -- Adds a scroll bar to the list box. * 38 * ListClass::Add_Tail -- Add myself to the end of the given list. * 39 * ListClass::Bump -- Bumps the list box up/down one "page". * 40 * ListClass::Current_Index -- Fetches the current selected index. * 41 * ListClass::Current_Item -- Fetches pointer to current item string. * 42 * ListClass::Draw_Entry -- Draws a list box text line as indicated. * 43 * ListClass::Draw_Me -- Draws the listbox. * 44 * ListClass::Get_Item -- Fetches an arbitrary item string. * 45 * ListClass::Peer_To_Peer -- A peer gadget was touched -- make adjustments. * 46 * ListClass::Remove -- Removes the specified object from the list. * 47 * ListClass::Remove_Item -- Remove specified text from list box. * 48 * ListClass::Remove_Scroll_Bar -- Removes the scroll bar if present * 49 * ListClass::Set_Selected_Index -- Set the top of the listbox to index specified. * 50 * ListClass::Set_Tabs -- Sets the tab stop list to be used for text printing. * 51 * ListClass::Set_View_Index -- Sets the top line for the current list view. * 52 * ListClass::Step -- Moves the list view one line in direction specified. * 53 * ListClass::Step_Selected_Index -- Change the listbox top line in direction specified. * 54 * ListClass::~ListClass -- Destructor for list class objects. * 55 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 56 57 #include "function.h" 58 59 60 /*************************************************************************** 61 * ListClass::ListClass -- class constructor * 62 * * 63 * INPUT: id button ID * 64 * * 65 * x,y upper-left corner, in pixels * 66 * * 67 * w,h width, height, in pixels * 68 * * 69 * list ptr to array of char strings to list* 70 * * 71 * flags, style flags for mouse, style of listbox * 72 * * 73 * OUTPUT: none. * 74 * * 75 * WARNINGS: none. * 76 * * 77 * HISTORY: 01/05/1995 MML : Created. * 78 *=========================================================================*/ 79 ListClass::ListClass (int id, int x, int y, int w, int h, TextPrintType flags, void const * up, void const * down) : 80 ControlClass(id, x, y, w, h, LEFTPRESS | LEFTRELEASE | KEYBOARD, false), 81 UpGadget(0, up, x+w, y), 82 DownGadget(0, down, x+w, y+h), 83 ScrollGadget(0, x+w, y, 0, h, true) 84 { 85 /* 86 ** Set preliminary values for the slider related gadgets. They don't automatically 87 ** appear at this time, but there are some values that can be pre-filled in. 88 */ 89 UpGadget.X -= UpGadget.Width; 90 DownGadget.X -= DownGadget.Width; 91 DownGadget.Y -= DownGadget.Height; 92 ScrollGadget.X -= MAX(UpGadget.Width, DownGadget.Width); 93 ScrollGadget.Y = Y+UpGadget.Height; 94 ScrollGadget.Height -= UpGadget.Height + DownGadget.Height; 95 ScrollGadget.Width = MAX(UpGadget.Width, DownGadget.Width); 96 97 /* 98 ** Set the list box to a default state. 99 */ 100 TextFlags = flags; 101 IsScrollActive = false; 102 Tabs = 0; 103 SelectedIndex = 0; 104 CurrentTopIndex = 0; 105 Fancy_Text_Print(TXT_NONE, 0, 0, TBLACK, TBLACK, TextFlags); 106 LineHeight = FontHeight+FontYSpacing-1; 107 LineCount = (h-1) / LineHeight; 108 } 109 110 111 /*********************************************************************************************** 112 * ListClass::~ListClass -- Destructor for list class objects. * 113 * * 114 * This is the destructor for list objects. It handles removing anything it might have * 115 * allocated. This is typically the scroll bar. * 116 * * 117 * INPUT: none * 118 * OUTPUT: none * 119 * WARNINGS: none * 120 * HISTORY: 01/16/1995 JLB : Created. * 121 *=============================================================================================*/ 122 ListClass::~ListClass(void) 123 { 124 Remove_Scroll_Bar(); 125 } 126 127 128 /*********************************************************************************************** 129 * ListClass::Add_Item -- Adds an item to the list box. * 130 * * 131 * This will add the specified string to the list box. The string is added to the end * 132 * of the list. * 133 * * 134 * INPUT: text -- Pointer to the string to add to the list box. * 135 * OUTPUT: none * 136 * WARNINGS: none * 137 * HISTORY: 01/15/1995 JLB : Created. * 138 *=============================================================================================*/ 139 int ListClass::Add_Item(char const * text) 140 { 141 if (text) { 142 List.Add(text); 143 Flag_To_Redraw(); 144 145 /* 146 ** Add scroll gadget if the list gets too large to display all of the items 147 ** at the same time. 148 */ 149 if (List.Count() > LineCount) { 150 Add_Scroll_Bar(); 151 } 152 153 /* 154 ** Tell the slider that there is one more entry in the list. 155 */ 156 if (IsScrollActive) { 157 ScrollGadget.Set_Maximum(List.Count()); 158 } 159 } 160 return(List.Count() - 1); 161 } 162 163 164 /*********************************************************************************************** 165 * ListClass::Add_Item -- Adds a text item (as number) to the list box. * 166 * * 167 * This will add the text as specified by the text number provided, to the list box. * 168 * The string is added to the end of the list. * 169 * * 170 * INPUT: text -- The text number for the string to add to the list box. * 171 * OUTPUT: none * 172 * WARNINGS: Once a string is added to the list box in this fashion, there is no method of * 173 * retrieving the text number as it relates to any particular index in the list. * 174 * HISTORY: * 175 * 01/15/1995 JLB : Created. * 176 *=============================================================================================*/ 177 int ListClass::Add_Item(int text) 178 { 179 if (text != TXT_NONE) { 180 Add_Item(Text_String(text)); 181 } 182 return(List.Count() - 1); 183 } 184 185 186 /*********************************************************************************************** 187 * ListClass::Remove_Item -- Remove specified text from list box. * 188 * * 189 * This routine will remove the specified text string from the list box. * 190 * * 191 * INPUT: text -- Pointer to the string to remove. * 192 * OUTPUT: none * 193 * WARNINGS: The text pointer passed into this routine MUST be the same text pointer that * 194 * was used to add the string to the list. * 195 * HISTORY: * 196 * 01/15/1995 JLB : Created. * 197 *=============================================================================================*/ 198 void ListClass::Remove_Item(char const * text) 199 { 200 if (text) { 201 List.Delete(text); 202 203 /* 204 ** If the list is now small enough to display completely within the list box region, 205 ** then delete the slider gadget (if they are present). 206 */ 207 if (List.Count() <= LineCount) { 208 Remove_Scroll_Bar(); 209 } 210 211 /* 212 ** Tell the slider that there is one less entry in the list. 213 */ 214 if (IsScrollActive) { 215 ScrollGadget.Set_Maximum(List.Count()); 216 } 217 218 /* 219 ** If we just removed the selected entry, select the previous one 220 */ 221 if (SelectedIndex >= List.Count()) { 222 SelectedIndex--; 223 if (SelectedIndex < 0) 224 SelectedIndex = 0; 225 } 226 227 /* 228 ** If we just removed the top-displayed entry, step up one item 229 */ 230 if (CurrentTopIndex >= List.Count()) { 231 CurrentTopIndex--; 232 if (CurrentTopIndex < 0) 233 CurrentTopIndex = 0; 234 if (IsScrollActive) 235 ScrollGadget.Step(1); 236 } 237 } 238 } 239 240 241 /*************************************************************************** 242 * ListClass::Action -- If clicked on, do this! * 243 * * 244 * INPUT: int flags -- combination of mouse flags indicating * 245 * what action to take. * 246 * * 247 * OUTPUT: bool result. * 248 * * 249 * WARNINGS: none. * 250 * * 251 * HISTORY: 01/05/1995 MML : Created. * 252 *=========================================================================*/ 253 int ListClass::Action(unsigned flags, KeyNumType & key) 254 { 255 if (flags & LEFTRELEASE) { 256 key = KN_NONE; 257 flags &= (~LEFTRELEASE); 258 ControlClass::Action(flags, key); 259 return(true); 260 } else { 261 262 /* -------------------------------------------------- 263 ** Handle keyboard events here. 264 */ 265 if (flags & KEYBOARD) { 266 267 /* 268 ** Process the keyboard character. If indicated, consume this keyboard event 269 ** so that the edit gadget ID number is not returned. 270 */ 271 if (key == KN_UP) { 272 Step_Selected_Index(-1); 273 key = KN_NONE; 274 } else if (key == KN_DOWN) { 275 Step_Selected_Index(1); 276 key = KN_NONE; 277 } else { 278 flags &= ~KEYBOARD; 279 } 280 281 } else { 282 283 int index = Get_Mouse_Y() - (Y+1); 284 index = index / LineHeight; 285 SelectedIndex = CurrentTopIndex + index; 286 SelectedIndex = MIN(SelectedIndex, List.Count()-1); 287 } 288 } 289 return(ControlClass::Action(flags, key)); 290 } 291 292 293 /*********************************************************************************************** 294 * ListClass::Draw_Me -- Draws the listbox. * 295 * * 296 * This routine will render the listbox. * 297 * * 298 * INPUT: forced -- Should the listbox be redrawn even if it already thinks it doesn't * 299 * need to be? This is true when something outside of the gadget system * 300 * has trashed the screen. * 301 * * 302 * OUTPUT: Was the listbox redrawn? * 303 * * 304 * WARNINGS: none * 305 * * 306 * HISTORY: * 307 * 06/25/1995 JLB : Created. * 308 *=============================================================================================*/ 309 int ListClass::Draw_Me(int forced) 310 { 311 if (GadgetClass::Draw_Me(forced)) { 312 313 /* 314 ** Turn off the mouse. 315 */ 316 if (LogicPage == &SeenBuff) { 317 Conditional_Hide_Mouse(X, Y, X+Width, Y+Height); 318 } 319 320 Draw_Box (X, Y, Width, Height, BOXSTYLE_GREEN_BOX, true); 321 322 /* 323 ** Draw List. 324 */ 325 if (List.Count()) { 326 for (int index = 0; index < LineCount; index++) { 327 int line = CurrentTopIndex + index; 328 329 if (List.Count() > line) { 330 331 /* 332 ** Prints the text and handles right edge clipping and tabs. 333 */ 334 Draw_Entry(line, X+1, Y+(LineHeight*index)+1, Width-2, (line == SelectedIndex)); 335 } 336 } 337 } 338 339 /* 340 ** Turn on the mouse. 341 */ 342 if (LogicPage == &SeenBuff) { 343 Conditional_Show_Mouse(); 344 } 345 return(true); 346 } 347 return(false); 348 } 349 350 351 /*********************************************************************************************** 352 * ListClass::Bump -- Bumps the list box up/down one "page". * 353 * * 354 * Use this routine to adjust the "page" that is being viewed in the list box. The view * 355 * will move up or down (as specified) one page (screen full) of text strings. * 356 * * 357 * INPUT: up -- Should the adjustment be up? * 358 * * 359 * OUTPUT: none * 360 * * 361 * WARNINGS: none * 362 * * 363 * HISTORY: * 364 * 01/15/1995 JLB : Created. * 365 *=============================================================================================*/ 366 void ListClass::Bump(int up) 367 { 368 if (IsScrollActive) { 369 if (ScrollGadget.Step(up)) { 370 CurrentTopIndex = ScrollGadget.Get_Value(); 371 Flag_To_Redraw(); 372 } 373 } 374 } 375 376 377 /*********************************************************************************************** 378 * ListClass::Step -- Moves the list view one line in direction specified. * 379 * * 380 * This routine will move the current view "page" one line in the direction specified. * 381 * * 382 * INPUT: up -- Should the view be moved upward? * 383 * * 384 * OUTPUT: none * 385 * * 386 * WARNINGS: none * 387 * * 388 * HISTORY: * 389 * 01/15/1995 JLB : Created. * 390 *=============================================================================================*/ 391 void ListClass::Step(int up) 392 { 393 if (IsScrollActive) { 394 if (ScrollGadget.Step(up)) { 395 CurrentTopIndex = ScrollGadget.Get_Value(); 396 Flag_To_Redraw(); 397 } 398 } 399 } 400 401 402 /*********************************************************************************************** 403 * ListClass::Get_Item -- Fetches an arbitrary item string. * 404 * * 405 * This routine will fetch an item string from the list box. The item fetched can be any * 406 * one of the ones in the list. * 407 * * 408 * INPUT: index -- The index to examine and return the text pointer from. * 409 * * 410 * OUTPUT: Returns with the text pointer to the string at the index position specified. * 411 * * 412 * WARNINGS: none * 413 * * 414 * HISTORY: * 415 * 01/16/1995 JLB : Created. * 416 *=============================================================================================*/ 417 char const * ListClass::Get_Item(int index) const 418 { 419 if (List.Count() == 0) return (NULL); 420 421 index = MIN(index, List.Count()-1 ); 422 return(List[index]); 423 } 424 425 426 /*********************************************************************************************** 427 * ListClass::Current_Item -- Fetches pointer to current item string. * 428 * * 429 * This routine will fetch a pointer to the currently selected item's text. * 430 * * 431 * INPUT: none * 432 * * 433 * OUTPUT: Return with pointer to currently selected text. * 434 * * 435 * WARNINGS: none * 436 * * 437 * HISTORY: * 438 * 01/16/1995 JLB : Created. * 439 *=============================================================================================*/ 440 char const * ListClass::Current_Item(void) 441 { 442 return(List[SelectedIndex]); 443 } 444 445 446 /*********************************************************************************************** 447 * ListClass::Current_Index -- Fetches the current selected index. * 448 * * 449 * This routine will fetch the index number for the currently selected line. * 450 * * 451 * INPUT: none * 452 * * 453 * OUTPUT: Returns with the index of the currently selected line. This ranges from zero to * 454 * the number of items in the list minus one. * 455 * * 456 * WARNINGS: none * 457 * * 458 * HISTORY: * 459 * 01/16/1995 JLB : Created. * 460 *=============================================================================================*/ 461 int ListClass::Current_Index(void) 462 { 463 return(SelectedIndex); 464 } 465 466 467 /*********************************************************************************************** 468 * ListClass::Peer_To_Peer -- A peer gadget was touched -- make adjustments. * 469 * * 470 * This routine is called when one of the peer gadgets (the scroll arrows or the slider) * 471 * was touched in some fashion. This routine will sort out whom and why and then make * 472 * any necessary adjustments to the list box. * 473 * * 474 * INPUT: flags -- The event flags that affected the peer gadget. * 475 * * 476 * key -- The key value at the time of the event. * 477 * * 478 * whom -- Which gadget is being touched. * 479 * * 480 * OUTPUT: none * 481 * * 482 * WARNINGS: none * 483 * * 484 * HISTORY: * 485 * 01/16/1995 JLB : Created. * 486 *=============================================================================================*/ 487 void ListClass::Peer_To_Peer(unsigned flags, KeyNumType &, ControlClass & whom) 488 { 489 if (flags & LEFTRELEASE) { 490 if (&whom == &UpGadget) { 491 Step(true); 492 } 493 if (&whom == &DownGadget) { 494 Step(false); 495 } 496 } 497 498 /* 499 ** The slider has changed, so reflect the current list position 500 ** according to the slider setting. 501 */ 502 if (&whom == &ScrollGadget) { 503 Set_View_Index(ScrollGadget.Get_Value()); 504 } 505 } 506 507 508 /*********************************************************************************************** 509 * ListClass::Set_View_Index -- Sets the top line for the current list view. * 510 * * 511 * This routine is used to set the line that will be at the top of the list view. This is * 512 * how the view can be scrolled up and down. This does not affect the currently selected * 513 * item. * 514 * * 515 * INPUT: index -- The line (index) to move to the top of the list view. * 516 * * 517 * OUTPUT: bool; Was the view actually changed? * 518 * * 519 * WARNINGS: none * 520 * * 521 * HISTORY: * 522 * 01/16/1995 JLB : Created. * 523 *=============================================================================================*/ 524 int ListClass::Set_View_Index(int index) 525 { 526 index = Bound(index, 0, List.Count() - LineCount); 527 if (index != CurrentTopIndex) { 528 CurrentTopIndex = index; 529 Flag_To_Redraw(); 530 if (IsScrollActive) { 531 ScrollGadget.Set_Value(CurrentTopIndex); 532 } 533 return(true); 534 } 535 return(false); 536 } 537 538 539 /*********************************************************************************************** 540 * ListClass::Add_Scroll_Bar -- Adds a scroll bar to the list box. * 541 * * 542 * This routine will add a scroll bar (with matching arrows) to the list box. They are * 543 * added to the right edge and cause the interior of the list box to become narrower. * 544 * * 545 * INPUT: none * 546 * * 547 * OUTPUT: bool; Was the scroll bar added? * 548 * * 549 * WARNINGS: The list box becomes narrower when the scroll bar is added. * 550 * * 551 * HISTORY: * 552 * 01/16/1995 JLB : Created. * 553 *=============================================================================================*/ 554 int ListClass::Add_Scroll_Bar(void) 555 { 556 if (!IsScrollActive) { 557 IsScrollActive = true; 558 559 /* 560 ** Everything has been created successfully. Flag the list box to be 561 ** redrawn because it now must be made narrower to accomodate the new 562 ** slider gadgets. 563 */ 564 Flag_To_Redraw(); 565 Width -= ScrollGadget.Width; 566 567 /* 568 ** Tell the newly created gadgets that they should inform this list box 569 ** whenever they get touched. In this way, the list box will automatically 570 ** be updated under control of the slider buttons. 571 */ 572 UpGadget.Make_Peer(*this); 573 DownGadget.Make_Peer(*this); 574 ScrollGadget.Make_Peer(*this); 575 576 /* 577 ** Add these newly created gadgets to the same gadget list that the 578 ** list box is part of. 579 */ 580 UpGadget.Add(*this); 581 DownGadget.Add(*this); 582 ScrollGadget.Add(*this); 583 584 /* 585 ** Make sure these added gadgets get redrawn at the next opportunity. 586 */ 587 UpGadget.Flag_To_Redraw(); 588 DownGadget.Flag_To_Redraw(); 589 ScrollGadget.Flag_To_Redraw(); 590 591 /* 592 ** Inform the slider of the size of the window and the current view position. 593 */ 594 ScrollGadget.Set_Maximum(List.Count()); 595 ScrollGadget.Set_Thumb_Size(LineCount); 596 ScrollGadget.Set_Value(CurrentTopIndex); 597 598 /* 599 ** Return with success flag. 600 */ 601 return(true); 602 } 603 return(false); 604 } 605 606 607 /*********************************************************************************************** 608 * ListClass::Remove_Scroll_Bar -- Removes the scroll bar if present * 609 * * 610 * Use this routine to remove any attached scroll bar to this list box. If the scroll bar * 611 * is not present, then no action occurs. * 612 * * 613 * INPUT: none * 614 * * 615 * OUTPUT: bool; Was the scroll bar removed? * 616 * * 617 * WARNINGS: none * 618 * * 619 * HISTORY: * 620 * 01/16/1995 JLB : Created. * 621 *=============================================================================================*/ 622 int ListClass::Remove_Scroll_Bar(void) 623 { 624 if (IsScrollActive) { 625 IsScrollActive = false; 626 Width += ScrollGadget.Width; 627 ScrollGadget.Remove(); 628 UpGadget.Remove(); 629 DownGadget.Remove(); 630 Flag_To_Redraw(); 631 return(true); 632 } 633 return(false); 634 } 635 636 637 /*********************************************************************************************** 638 * ListClass::Set_Tabs -- Sets the tab stop list to be used for text printing. * 639 * * 640 * This sets the tab stop list to be used for text printing. It specifies a series of * 641 * pixel offsets for each tab stop. The offsets are from the starting pixel position that * 642 * the text begins at. * 643 * * 644 * INPUT: tabs -- Pointer to a list of tab pixel offsets. * 645 * * 646 * OUTPUT: none * 647 * * 648 * WARNINGS: Only a pointer to the tabs is recorded by the ListClass object. Make sure that * 649 * the list remains intact for the duration of the existence of this object. * 650 * * 651 * HISTORY: * 652 * 01/16/1995 JLB : Created. * 653 *=============================================================================================*/ 654 void ListClass::Set_Tabs(int const * tabs) 655 { 656 Tabs = tabs; 657 } 658 659 660 /*********************************************************************************************** 661 * ListClass::Draw_Entry -- Draws a list box text line as indicated. * 662 * * 663 * This routine is called by the Draw_Me function when it desired to redraw a particular * 664 * text line in the list box. * 665 * * 666 * INPUT: index -- The index of the list entry to draw. This index is based on the * 667 * total list and NOT the current visible view page. * 668 * * 669 * x,y -- Pixel coordinates for the upper left corner of the text entry. * 670 * * 671 * width -- The maximum width that the text may draw over. It is expected that * 672 * this drawing routine entirely fills this length. * 673 * * 674 * selected -- bool; Is this a selected (highlighted) listbox entry? * 675 * * 676 * OUTPUT: none * 677 * WARNINGS: none * 678 * HISTORY: * 679 * 01/16/1995 JLB : Created. * 680 *=============================================================================================*/ 681 void ListClass::Draw_Entry(int index, int x, int y, int width, int selected) 682 { 683 if (TextFlags & TPF_6PT_GRAD) { 684 TextPrintType flags = TextFlags; 685 686 if (selected) { 687 flags = flags | TPF_BRIGHT_COLOR; 688 LogicPage->Fill_Rect (x, y, x + width - 1, y + LineHeight - 1, CC_GREEN_SHADOW); 689 } else { 690 if (!(flags & TPF_USE_GRAD_PAL)) { 691 flags = flags | TPF_MEDIUM_COLOR; 692 } 693 } 694 695 Conquer_Clip_Text_Print(List[index], x, y, CC_GREEN, TBLACK, flags, width, Tabs); 696 697 } else { 698 Conquer_Clip_Text_Print(List[index], x, y, (selected ? BLUE : WHITE), TBLACK, TextFlags, width, Tabs); 699 } 700 } 701 702 703 /*********************************************************************************************** 704 * ListClass::Add -- Adds myself to list immediately after given object * 705 * * 706 * Adds the list box to the chain, immemdiately after the given object. The order will be: * 707 * - Listbox * 708 * - Up arrow (if active) * 709 * - Down arrow (if active) * 710 * - Scroll gadget (if active) * 711 * * * 712 * INPUT: object -- Pointer to the object to be added right after this one. * 713 * * 714 * OUTPUT: Returns with a pointer to the head of the list. * 715 * * 716 * WARNINGS: none * 717 * * 718 * HISTORY: * 719 * 01/19/1995 JLB : Created. * 720 *=============================================================================================*/ 721 LinkClass & ListClass::Add(LinkClass & list) 722 { 723 /* 724 ** Add the scroll bar gadgets if they're active. 725 */ 726 if (IsScrollActive) { 727 ScrollGadget.Add(list); 728 DownGadget.Add(list); 729 UpGadget.Add(list); 730 } 731 732 /* 733 ** Add myself to the list, then return. 734 */ 735 return(ControlClass::Add(list)); 736 } 737 738 739 /*********************************************************************************************** 740 * ListClass::Add_Head -- Adds myself to head of the given list * 741 * * 742 * INPUT: list -- list to add myself to * 743 * * 744 * OUTPUT: Returns with a reference to the object at the head of the list. This should be * 745 * the same object that is passed in. * 746 * * 747 * WARNINGS: none * 748 * * 749 * HISTORY: * 750 * 01/19/1995 JLB : Created. * 751 *=============================================================================================*/ 752 LinkClass & ListClass::Add_Head(LinkClass & list) 753 { 754 /* 755 ** Add the scroll bar gadgets if they're active. 756 */ 757 if (IsScrollActive) { 758 ScrollGadget.Add_Head(list); 759 DownGadget.Add_Head(list); 760 UpGadget.Add_Head(list); 761 } 762 763 /* 764 ** Add myself to the list, then return. 765 */ 766 return(ControlClass::Add_Head(list)); 767 } 768 769 770 /*********************************************************************************************** 771 * ListClass::Add_Tail -- Adds myself to tail of given list * 772 * * 773 * Adds the list box to the tail of the give chain. The order will be: * 774 * - Listbox * 775 * - Up arrow (if active) * 776 * - Down arrow (if active) * 777 * - Scroll gadget (if active) * 778 * * 779 * INPUT: list -- list to add myself to * 780 * * 781 * OUTPUT: none * 782 * * 783 * WARNINGS: The previous and next pointers for the added object MUST have been properly * 784 * initialized for this routine to work correctly. * 785 * * 786 * HISTORY: * 787 * 01/15/1995 JLB : Created. * 788 *=============================================================================================*/ 789 LinkClass & ListClass::Add_Tail(LinkClass & list) 790 { 791 /* 792 ** Add myself to the list. 793 */ 794 ControlClass::Add_Tail(list); 795 796 /* 797 ** Add the scroll bar gadgets if they're active. 798 */ 799 if (IsScrollActive) { 800 UpGadget.Add_Tail(list); 801 DownGadget.Add_Tail(list); 802 ScrollGadget.Add_Tail(list); 803 } 804 805 return(Head_Of_List()); 806 } 807 808 809 /*********************************************************************************************** 810 * ListClass::Remove -- Removes the specified object from the list. * 811 * * 812 * This routine will remove the specified object from the list of objects. Because of the * 813 * previous and next pointers, it is possible to remove an object from the list without * 814 * knowing the head of the list. To do this, just call Remove() with the parameter of * 815 * "this". * 816 * * 817 * INPUT: none * 818 * * 819 * OUTPUT: Returns with the new head of list. * 820 * * 821 * WARNINGS: none * 822 * * 823 * HISTORY: * 824 * 01/15/1995 JLB : Created. * 825 *=============================================================================================*/ 826 GadgetClass * ListClass::Remove(void) 827 { 828 /* 829 ** Remove the scroll bar if it's active 830 */ 831 if (IsScrollActive) { 832 ScrollGadget.Remove(); 833 DownGadget.Remove(); 834 UpGadget.Remove(); 835 } 836 837 /* 838 ** Remove myself & return 839 */ 840 return(ControlClass::Remove()); 841 } 842 843 844 /*********************************************************************************************** 845 * ListClass::Set_Selected_Index -- Set the top of the listbox to index specified. * 846 * * 847 * This routine will set the top line of the listbox to the index value specified. * 848 * * 849 * INPUT: index -- The index to set the top of the listbox to. * 850 * * 851 * OUTPUT: none * 852 * * 853 * WARNINGS: The requested index may be adjusted to fit within legal parameters. * 854 * * 855 * HISTORY: * 856 * 06/25/1995 JLB : Created. * 857 *=============================================================================================*/ 858 void ListClass::Set_Selected_Index(int index) 859 { 860 if (index < List.Count()) { 861 SelectedIndex = index; 862 Flag_To_Redraw(); 863 if (SelectedIndex < CurrentTopIndex) { 864 Set_View_Index(SelectedIndex); 865 } 866 if (SelectedIndex >= CurrentTopIndex+LineCount) { 867 Set_View_Index(SelectedIndex-(LineCount-1)); 868 } 869 } 870 } 871 872 873 /*********************************************************************************************** 874 * ListClass::Step_Selected_Index -- Change the listbox top line in direction specified. * 875 * * 876 * This routine will scroll the top line of the listbox in the direction specified. * 877 * * 878 * INPUT: step -- The direction (and amount) to adjust the listbox. If negative value, then * 879 * the top line is scrolled upward. * 880 * * 881 * OUTPUT: Returns with the original top line index number. * 882 * * 883 * WARNINGS: none * 884 * * 885 * HISTORY: * 886 * 06/25/1995 JLB : Created. * 887 *=============================================================================================*/ 888 int ListClass::Step_Selected_Index(int step) 889 { 890 int old = SelectedIndex; 891 892 Set_Selected_Index(old + step); 893 return(old); 894 }