CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

LIST.CPP (51059B)


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