UWindow
Class UWindowComboList

source: e:\games\UnrealTournament\UWindow\Classes\UWindowComboList.uc
Core.Object
   |
   +--UWindow.UWindowBase
      |
      +--UWindow.UWindowWindow
         |
         +--UWindow.UWindowDialogControl
            |
            +--UWindow.UWindowListControl
               |
               +--UWindow.UWindowComboList
Direct Known Subclasses:None

class UWindowComboList
extends UWindow.UWindowListControl


Variables
 int HBorder
 int ItemHeight
 int MaxVisible
 UWindowComboControl Owner
 UWindowComboListItem Selected
 int TextBorder
 int VBorder
 UWindowVScrollBar VertSB


Function Summary
 void AddItem(string Value, optional string, optional int)
 void BeforePaint(Canvas C, float X, float Y)
 void Clear()
 void CloseUp()
 void Created()
 void DrawItem(Canvas C, UWindowList Item, float X, float Y, float W, float H)
 void DrawMenuBackground(Canvas C)
 void ExecuteItem(UWindowComboListItem I)
 int FindItemIndex(string Value, optional bool)
 int FindItemIndex2(string Value2, optional bool)
 void FocusOtherWindow(UWindowWindow W)
 string GetItemValue(int Index)
 string GetItemValue2(int Index)
 Texture GetLookAndFeelTexture()
 void InsertItem(string Value, optional string, optional int)
 void LMouseDown(float X, float Y)
 void LMouseUp(float X, float Y)
 void MouseMove(float X, float Y)
 void Paint(Canvas C, float X, float Y)
 void RemoveItem(int Index)
 void SetSelected(float X, float Y)
 void Setup()
 void Sort()
 void WindowShown()



Source Code


00001	class UWindowComboList extends UWindowListControl;
00002	
00003	var UWindowComboControl		Owner;
00004	var UWindowVScrollBar		VertSB;
00005	var UWindowComboListItem	Selected;
00006	var int ItemHeight;
00007	var int VBorder;
00008	var int HBorder;
00009	var int TextBorder;
00010	var int MaxVisible;
00011	
00012	function Sort()
00013	{
00014		Items.Sort();
00015	}
00016	
00017	function WindowShown()
00018	{
00019		Super.WindowShown();
00020		FocusWindow();
00021	}
00022	
00023	function Clear()
00024	{
00025		Items.Clear();
00026	}
00027	
00028	function Texture GetLookAndFeelTexture()
00029	{
00030		return LookAndFeel.Active;
00031	}
00032	
00033	function Setup()
00034	{
00035		VertSB = UWindowVScrollBar(CreateWindow(class'UWindowVScrollBar', 0, WinWidth - 16, 16, WinHeight));
00036	}
00037	
00038	function Created()
00039	{
00040		ListClass = class'UWindowComboListItem';
00041		bAlwaysOnTop = True;
00042		bTransient = True;
00043		Super.Created();
00044		ItemHeight = 15;
00045		VBorder = 3;
00046		HBorder = 3;
00047		TextBorder = 9;
00048	
00049		Super.Created();
00050	}
00051	
00052	function int FindItemIndex(string Value, optional bool bIgnoreCase)
00053	{
00054		local UWindowComboListItem I;
00055		local int Count;
00056	
00057		I = UWindowComboListItem(Items.Next);
00058		Count = 0;
00059			
00060		while(I != None)
00061		{
00062			if(bIgnoreCase && I.Value ~= Value) return Count;
00063			if(I.Value == Value) return Count;
00064	
00065			Count++;
00066			I = UWindowComboListItem(I.Next);
00067		}
00068	
00069		return -1;
00070	}
00071	
00072	function int FindItemIndex2(string Value2, optional bool bIgnoreCase)
00073	{
00074		local UWindowComboListItem I;
00075		local int Count;
00076	
00077		I = UWindowComboListItem(Items.Next);
00078		Count = 0;
00079			
00080		while(I != None)
00081		{
00082			if(bIgnoreCase && I.Value2 ~= Value2) return Count;
00083			if(I.Value2 == Value2) return Count;
00084	
00085			Count++;
00086			I = UWindowComboListItem(I.Next);
00087		}
00088	
00089		return -1;
00090	}
00091	
00092	function string GetItemValue(int Index)
00093	{
00094		local UWindowComboListItem I;
00095		local int Count;
00096	
00097		I = UWindowComboListItem(Items.Next);
00098		Count = 0;
00099			
00100		while(I != None)
00101		{
00102			if(Count == Index) return I.Value;
00103	
00104			Count++;
00105			I = UWindowComboListItem(I.Next);
00106		}
00107	
00108		return "";
00109	}
00110	
00111	function RemoveItem(int Index)
00112	{
00113		local UWindowComboListItem I;
00114		local int Count;
00115	
00116		if(Index == -1)
00117			return;
00118	
00119		I = UWindowComboListItem(Items.Next);
00120		Count = 0;
00121			
00122		while(I != None)
00123		{
00124			if(Count == Index)
00125			{
00126				I.Remove();
00127				return;
00128			}
00129	
00130			Count++;
00131			I = UWindowComboListItem(I.Next);
00132		}
00133	}
00134	
00135	function string GetItemValue2(int Index)
00136	{
00137		local UWindowComboListItem I;
00138		local int Count;
00139	
00140		I = UWindowComboListItem(Items.Next);
00141		Count = 0;
00142			
00143		while(I != None)
00144		{
00145			if(Count == Index) return I.Value2;
00146	
00147			Count++;
00148			I = UWindowComboListItem(I.Next);
00149		}
00150	
00151		return "";
00152	}
00153	
00154	function AddItem(string Value, optional string Value2, optional int SortWeight)
00155	{
00156		local UWindowComboListItem I;
00157		I = UWindowComboListItem(Items.Append(class'UWindowComboListItem'));
00158		I.Value = Value;
00159		I.Value2 = Value2;
00160		I.SortWeight = SortWeight;
00161	}
00162	
00163	function InsertItem(string Value, optional string Value2, optional int SortWeight)
00164	{
00165		local UWindowComboListItem I;
00166		I = UWindowComboListItem(Items.Insert(class'UWindowComboListItem'));
00167		I.Value = Value;
00168		I.Value2 = Value2;
00169		I.SortWeight = SortWeight;
00170	}
00171	
00172	function SetSelected(float X, float Y)
00173	{
00174		local UWindowComboListItem NewSelected, Item;
00175		local int i, Count;
00176	
00177		Count = 0;
00178		for( Item = UWindowComboListItem(Items.Next);Item != None; Item = UWindowComboListItem(Item.Next) )
00179			Count++;
00180	
00181		i = (Y - VBorder) / ItemHeight + VertSB.Pos;
00182	
00183		if(i < 0)
00184			i = 0;
00185	
00186		if(i >= VertSB.Pos + Min(Count, MaxVisible))
00187			i = VertSB.Pos + Min(Count, MaxVisible) - 1;
00188	
00189		NewSelected = UWindowComboListItem(Items.FindEntry(i));
00190	
00191		if(NewSelected != Selected)
00192		{
00193			if(NewSelected == None) 
00194				Selected = None;
00195			else
00196				Selected = NewSelected;
00197		}	
00198	}
00199	
00200	function MouseMove(float X, float Y)
00201	{
00202		Super.MouseMove(X, Y);
00203		if(Y > WinHeight) VertSB.Scroll(1);
00204		if(Y < 0) VertSB.Scroll(-1);
00205	
00206		SetSelected(X, Y);
00207	
00208		FocusWindow();
00209	}
00210	
00211	function LMouseUp(float X, float Y)
00212	{
00213		If(Y >= 0 && Y <= WinHeight && Selected != None)
00214		{
00215			ExecuteItem(Selected);
00216		}
00217		Super.LMouseUp(X, Y);
00218	}
00219	
00220	function LMouseDown(float X, float Y)
00221	{
00222		Root.CaptureMouse();
00223	}
00224	
00225	function BeforePaint(Canvas C, float X, float Y)
00226	{
00227		local float W, H, MaxWidth;
00228		local int Count;
00229		local UWindowComboListItem I;
00230		local float ListX, ListY;
00231		local float ExtraWidth;
00232			
00233		C.Font = Root.Fonts[F_Normal];
00234		C.SetPos(0, 0);
00235	
00236		MaxWidth = Owner.EditBoxWidth;
00237		ExtraWidth = ((HBorder + TextBorder) * 2);
00238	
00239		Count = Items.Count();
00240		if(Count > MaxVisible)
00241		{
00242			ExtraWidth += LookAndFeel.Size_ScrollbarWidth;
00243			WinHeight = (ItemHeight * MaxVisible) + (VBorder * 2);
00244		}
00245		else
00246		{
00247			VertSB.Pos = 0;
00248			WinHeight = (ItemHeight * Count) + (VBorder * 2);
00249		}
00250	
00251		for( I = UWindowComboListItem(Items.Next);I != None; I = UWindowComboListItem(I.Next) )
00252		{
00253			TextSize(C, RemoveAmpersand(I.Value), W, H);
00254			if(W + ExtraWidth > MaxWidth)
00255				MaxWidth = W + ExtraWidth;
00256		}
00257	
00258		WinWidth = MaxWidth;
00259	
00260		ListX = Owner.EditAreaDrawX + Owner.EditBoxWidth - WinWidth;
00261		ListY = Owner.Button.WinTop + Owner.Button.WinHeight;
00262	
00263		if(Count > MaxVisible)
00264		{
00265			VertSB.ShowWindow();
00266			VertSB.SetRange(0, Count, MaxVisible);
00267			VertSB.WinLeft = WinWidth - LookAndFeel.Size_ScrollbarWidth - HBorder;
00268			VertSB.WinTop = HBorder;
00269			VertSB.WinWidth = LookAndFeel.Size_ScrollbarWidth;
00270			VertSB.WinHeight = WinHeight - 2*VBorder;
00271		}
00272		else
00273		{
00274			VertSB.HideWindow();
00275		}
00276	
00277		Owner.WindowToGlobal(ListX, ListY, WinLeft, WinTop);
00278	}
00279	
00280	function Paint(Canvas C, float X, float Y)
00281	{
00282		local int Count;
00283		local UWindowComboListItem I;
00284	
00285		DrawMenuBackground(C);
00286		
00287		Count = 0;
00288	
00289		for( I = UWindowComboListItem(Items.Next);I != None; I = UWindowComboListItem(I.Next) )
00290		{
00291			if(VertSB.bWindowVisible)
00292			{
00293				if(Count >= VertSB.Pos)
00294					DrawItem(C, I, HBorder, VBorder + (ItemHeight * (Count - VertSB.Pos)), WinWidth - (2 * HBorder) - VertSB.WinWidth, ItemHeight);
00295			}
00296			else
00297				DrawItem(C, I, HBorder, VBorder + (ItemHeight * Count), WinWidth - (2 * HBorder), ItemHeight);
00298			Count++;
00299		}
00300	}
00301	
00302	function DrawMenuBackground(Canvas C)
00303	{
00304		LookAndFeel.ComboList_DrawBackground(Self, C);
00305	}
00306	
00307	function DrawItem(Canvas C, UWindowList Item, float X, float Y, float W, float H)
00308	{
00309		LookAndFeel.ComboList_DrawItem(Self, C, X, Y, W, H, UWindowComboListItem(Item).Value, Selected == Item);
00310	}
00311	
00312	function ExecuteItem(UWindowComboListItem I)
00313	{
00314		Owner.SetValue(I.Value, I.Value2);
00315		CloseUp();
00316	}
00317	
00318	function CloseUp() 
00319	{
00320		Owner.CloseUp();
00321	}
00322	
00323	function FocusOtherWindow(UWindowWindow W)
00324	{
00325		Super.FocusOtherWindow(W);
00326	
00327		if(bWindowVisible && W.ParentWindow.ParentWindow != Self && W.ParentWindow != Self && W.ParentWindow != Owner)
00328			CloseUp();
00329	}
00330	
00331	defaultproperties
00332	{
00333	     MaxVisible=10
00334	}

End Source Code