UWindow
Class UWindowListBox

source: e:\games\UnrealTournament\UWindow\Classes\UWindowListBox.uc
Core.Object
   |
   +--UWindow.UWindowBase
      |
      +--UWindow.UWindowWindow
         |
         +--UWindow.UWindowDialogControl
            |
            +--UWindow.UWindowListControl
               |
               +--UWindow.UWindowListBox
Direct Known Subclasses:UBrowserIRCUserListBox, UMenuMapListBox, UMenuMutatorListBox, UMenuWeaponPriorityListBox

class UWindowListBox
extends UWindow.UWindowListControl

//============================================================================= // UWindowListBox - a listbox //=============================================================================
Variables
 string DefaultHelpText
 UWindowListBox DoubleClickList
           list to send items to on double-click
 float DragY
 float ItemHeight
 UWindowListBoxItem SelectedItem
 UWindowVScrollBar VertSB
 bool bCanDrag
 bool bCanDragExternal
 bool bDragging


Function Summary
 void BeforePaint(Canvas C, float MouseX, float MouseY)
 void Created()
 void DoubleClick(float X, float Y)
 void DoubleClickItem(UWindowListBoxItem I)
 bool ExternalDragOver(UWindowDialogControl ExternalControl, float X, float Y)
 UWindowListBoxItem GetItemAt(float MouseX, float MouseY)
 void LMouseDown(float X, float Y)
 void MakeSelectedVisible()
 void MouseMove(float X, float Y)
 void Paint(Canvas C, float MouseX, float MouseY)
 void ReceiveDoubleClickItem(UWindowListBox L, UWindowListBoxItem I)
 void Resized()
 void SetHelpText(string T)
 void SetSelected(float X, float Y)
 void SetSelectedItem(UWindowListBoxItem NewSelected)
 void Sort()



Source Code


00001	//=============================================================================
00002	// UWindowListBox - a listbox
00003	//=============================================================================
00004	class UWindowListBox extends UWindowListControl;
00005	
00006	var float				ItemHeight;
00007	var UWindowVScrollbar	VertSB;
00008	var UWindowListBoxItem	SelectedItem;
00009	
00010	var bool				bCanDrag;
00011	var bool				bCanDragExternal;
00012	var string				DefaultHelpText;
00013	var bool				bDragging;
00014	var float				DragY;
00015	var UWindowListBox		DoubleClickList;	// list to send items to on double-click
00016	
00017	function Created()
00018	{
00019		Super.Created();
00020		VertSB = UWindowVScrollbar(CreateWindow(class'UWindowVScrollbar', WinWidth-12, 0, 12, WinHeight));
00021	}
00022	
00023	function BeforePaint(Canvas C, float MouseX, float MouseY)
00024	{
00025		local UWindowListBoxItem OverItem;
00026		local string NewHelpText;
00027	
00028		VertSB.SetRange(0, Items.CountShown(), int(WinHeight/ItemHeight));
00029	
00030		NewHelpText = DefaultHelpText;
00031		if(SelectedItem != None)
00032		{
00033			OverItem = GetItemAt(MouseX, MouseY);
00034			if(OverItem == SelectedItem && OverItem.HelpText != "")
00035				NewHelpText = OverItem.HelpText;
00036		}
00037		
00038		if(NewHelpText != HelpText)
00039		{
00040			HelpText = NewHelpText;
00041			Notify(DE_HelpChanged);
00042		}
00043	}
00044	
00045	function SetHelpText(string T)
00046	{
00047		Super.SetHelpText(T);
00048		DefaultHelpText = T;
00049	}
00050	
00051	function Sort()
00052	{
00053		Items.Sort();
00054	}
00055	
00056	function Paint(Canvas C, float MouseX, float MouseY)
00057	{
00058		local float y;
00059		local UWindowList CurItem;
00060		local int i;
00061		
00062		CurItem = Items.Next;
00063		i = 0;
00064	
00065		while((CurItem != None) && (i < VertSB.Pos)) 
00066		{
00067			if(CurItem.ShowThisItem())
00068				i++;
00069			CurItem = CurItem.Next;
00070		}
00071	
00072		for(y=0;(y < WinHeight) && (CurItem != None);CurItem = CurItem.Next)
00073		{
00074			if(CurItem.ShowThisItem())
00075			{
00076				DrawItem(C, CurItem, 0, y, WinWidth - 12, ItemHeight);
00077				y = y + ItemHeight;
00078			}
00079		}
00080	}
00081	
00082	function Resized()
00083	{
00084		Super.Resized();
00085	
00086		VertSB.WinLeft = WinWidth-12;
00087		VertSB.WinTop = 0;
00088		VertSB.SetSize(12, WinHeight);
00089	}
00090	
00091	function UWindowListBoxItem GetItemAt(float MouseX, float MouseY)
00092	{
00093		local float y;
00094		local UWindowList CurItem;
00095		local int i;
00096		
00097		if(MouseX < 0 || MouseX > WinWidth)
00098			return None;
00099	
00100		CurItem = Items.Next;
00101		i = 0;
00102	
00103		while((CurItem != None) && (i < VertSB.Pos)) 
00104		{
00105			if(CurItem.ShowThisItem())
00106				i++;
00107			CurItem = CurItem.Next;
00108		}
00109	
00110		for(y=0;(y < WinHeight) && (CurItem != None);CurItem = CurItem.Next)
00111		{
00112			if(CurItem.ShowThisItem())
00113			{
00114				if(MouseY >= y && MouseY <= y+ItemHeight)
00115					return UWindowListBoxItem(CurItem);
00116				y = y + ItemHeight;
00117			}
00118		}
00119	
00120		return None;
00121	}
00122	
00123	function MakeSelectedVisible()
00124	{
00125		local UWindowList CurItem;
00126		local int i;
00127		
00128		VertSB.SetRange(0, Items.CountShown(), int(WinHeight/ItemHeight));
00129	
00130		if(SelectedItem == None)
00131			return;
00132	
00133		i = 0;
00134		for(CurItem=Items.Next; CurItem != None; CurItem = CurItem.Next)
00135		{
00136			if(CurItem == SelectedItem)
00137				break;
00138			if(CurItem.ShowThisItem())
00139				i++;
00140		}
00141	
00142		VertSB.Show(i);
00143	}
00144	
00145	function SetSelectedItem(UWindowListBoxItem NewSelected)
00146	{
00147		if(NewSelected != None && SelectedItem != NewSelected)
00148		{
00149			if(SelectedItem != None)
00150				SelectedItem.bSelected = False;
00151	
00152			SelectedItem = NewSelected;
00153	
00154			if(SelectedItem != None)
00155				SelectedItem.bSelected = True;
00156			
00157			Notify(DE_Click);
00158		}
00159	}
00160	
00161	function SetSelected(float X, float Y)
00162	{
00163		local UWindowListBoxItem NewSelected;
00164	
00165		NewSelected = GetItemAt(X, Y);
00166		SetSelectedItem(NewSelected);
00167	}
00168	
00169	function LMouseDown(float X, float Y)
00170	{
00171		Super.LMouseDown(X, Y);
00172	
00173		SetSelected(X, Y);
00174	
00175		if(bCanDrag || bCanDragExternal)
00176		{
00177			bDragging = True;
00178			Root.CaptureMouse();
00179			DragY = Y;
00180		}
00181	}
00182	
00183	function DoubleClick(float X, float Y)
00184	{
00185		Super.DoubleClick(X, Y);
00186	
00187		if(GetItemAt(X, Y) == SelectedItem)
00188		{
00189			DoubleClickItem(SelectedItem);
00190		}	
00191	}
00192	
00193	function ReceiveDoubleClickItem(UWindowListBox L, UWindowListBoxItem I)
00194	{
00195		I.Remove();
00196		Items.AppendItem(I);
00197		SetSelectedItem(I);
00198		L.SelectedItem = None;
00199		L.Notify(DE_Change);
00200		Notify(DE_Change);
00201	}
00202	
00203	function DoubleClickItem(UWindowListBoxItem I)
00204	{
00205		if(DoubleClickList != None && I != None)
00206			DoubleClickList.ReceiveDoubleClickItem(Self, I);
00207	}
00208	
00209	function MouseMove(float X, float Y)
00210	{
00211		local UWindowListBoxItem OverItem;
00212		Super.MouseMove(X, Y);
00213	
00214		if(bDragging && bMouseDown)
00215		{
00216			OverItem = GetItemAt(X, Y);
00217			if(bCanDrag && OverItem != SelectedItem && OverItem != None && SelectedItem != None)
00218			{
00219				SelectedItem.Remove();
00220				if(Y < DragY)
00221					OverItem.InsertItemBefore(SelectedItem);
00222				else
00223					OverItem.InsertItemAfter(SelectedItem, True);
00224	
00225				Notify(DE_Change);
00226	
00227				DragY = Y;
00228			}
00229			else
00230			{
00231				if(bCanDragExternal && CheckExternalDrag(X, Y) != None)
00232					bDragging = False;
00233			}
00234		}
00235		else
00236			bDragging = False;
00237	}
00238	
00239	function bool ExternalDragOver(UWindowDialogControl ExternalControl, float X, float Y)
00240	{
00241		local UWindowListBox B;
00242		local UWindowListBoxItem OverItem;
00243	
00244		// Subclass should return false and not call this version if this external
00245		// drag should be denied.
00246	
00247		B = UWindowListBox(ExternalControl);
00248		if(B != None && B.SelectedItem != None)
00249		{	
00250			OverItem = GetItemAt(X, Y);
00251	
00252			B.SelectedItem.Remove();
00253			if(OverItem != None)
00254				OverItem.InsertItemBefore(B.SelectedItem);
00255			else
00256				Items.AppendItem(B.SelectedItem);
00257	
00258			SetSelectedItem(B.SelectedItem);
00259			B.SelectedItem = None;
00260			B.Notify(DE_Change);
00261			Notify(DE_Change);
00262	
00263			if(bCanDrag || bCanDragExternal)
00264			{
00265				Root.CancelCapture();
00266				bDragging = True;
00267				bMouseDown = True;
00268				Root.CaptureMouse(Self);
00269				DragY = Y;	
00270			}
00271	
00272			return True;
00273		}
00274	
00275		return False;	
00276	}
00277	
00278	defaultproperties
00279	{
00280	     ItemHeight=10.000000
00281	}

End Source Code