Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
elw00d committed Mar 1, 2016
2 parents 974a62e + dcce2dd commit 6a4651b
Show file tree
Hide file tree
Showing 33 changed files with 578 additions and 87 deletions.
17 changes: 12 additions & 5 deletions ConsoleFramework/ConsoleApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,15 @@ public static Control LoadFromXaml( string xamlResourceName, object dataContext
}
using ( StreamReader reader = new StreamReader( stream ) ) {
string result = reader.ReadToEnd( );
return XamlParser.CreateFromXaml<Control>(result, dataContext, new List<string>()
Control control = XamlParser.CreateFromXaml<Control>(result, dataContext, new List<string>()
{
"clr-namespace:Xaml;assembly=Xaml",
"clr-namespace:ConsoleFramework.Xaml;assembly=ConsoleFramework",
"clr-namespace:ConsoleFramework.Controls;assembly=ConsoleFramework",
});
control.DataContext = dataContext;
control.Created( );
return control;
}
}
}
Expand Down Expand Up @@ -720,10 +723,14 @@ private void processLinuxInput (TermKeyKey key)
inputRecord.MouseEvent.dwMousePosition = new COORD((short) (col - 1), (short) (line - 1));
if (ev == TermKeyMouseEvent.TERMKEY_MOUSE_RELEASE) {
inputRecord.MouseEvent.dwButtonState = 0;
} else if (ev == TermKeyMouseEvent.TERMKEY_MOUSE_DRAG) {
inputRecord.MouseEvent.dwButtonState = MOUSE_BUTTON_STATE.FROM_LEFT_1ST_BUTTON_PRESSED;
} else if (ev == TermKeyMouseEvent.TERMKEY_MOUSE_PRESS) {
inputRecord.MouseEvent.dwButtonState = MOUSE_BUTTON_STATE.FROM_LEFT_1ST_BUTTON_PRESSED;
} else if (ev == TermKeyMouseEvent.TERMKEY_MOUSE_DRAG || ev == TermKeyMouseEvent.TERMKEY_MOUSE_PRESS) {
if (1 == button) {
inputRecord.MouseEvent.dwButtonState = MOUSE_BUTTON_STATE.FROM_LEFT_1ST_BUTTON_PRESSED;
} else if (2 == button) {
inputRecord.MouseEvent.dwButtonState = MOUSE_BUTTON_STATE.FROM_LEFT_2ND_BUTTON_PRESSED;
} else if (3 == button) {
inputRecord.MouseEvent.dwButtonState = MOUSE_BUTTON_STATE.RIGHTMOST_BUTTON_PRESSED;
}
}
//
processInputEvent(inputRecord);
Expand Down
2 changes: 2 additions & 0 deletions ConsoleFramework/ConsoleFramework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<Compile Include="Controls\ButtonBase.cs" />
<Compile Include="Controls\CheckBox.cs" />
<Compile Include="Controls\ComboBox.cs" />
<Compile Include="Controls\ContextMenu.cs" />
<Compile Include="Controls\Grid.cs" />
<Compile Include="Controls\GroupBox.cs" />
<Compile Include="Controls\ListBox.cs" />
Expand All @@ -69,6 +70,7 @@
<Compile Include="Controls\ProgressBar.cs" />
<Compile Include="Controls\RadioButton.cs" />
<Compile Include="Controls\ScrollViewer.cs" />
<Compile Include="Controls\TabControl.cs" />
<Compile Include="Controls\TextBox.cs" />
<Compile Include="Controls\TreeView.cs" />
<Compile Include="Controls\UIElementCollection.cs" />
Expand Down
2 changes: 1 addition & 1 deletion ConsoleFramework/Controls/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public string Caption {

protected override Size MeasureOverride(Size availableSize) {
if (!string.IsNullOrEmpty(caption)) {
Size minButtonSize = new Size(caption.Length + 14, 2);
Size minButtonSize = new Size(caption.Length + 10, 2);
return minButtonSize;
} else return new Size(8, 2);
}
Expand Down
3 changes: 2 additions & 1 deletion ConsoleFramework/Controls/ComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ private void OnKeyDown( object sender, KeyEventArgs args ) {
}

private void OnMouseDown( object sender, MouseButtonEventArgs mouseButtonEventArgs ) {
openPopup( );
if ( !opened )
openPopup( );
}

private void OnPopupClosed( object o, EventArgs args ) {
Expand Down
102 changes: 102 additions & 0 deletions ConsoleFramework/Controls/ContextMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Binding.Observables;
using ConsoleFramework.Core;
using ConsoleFramework.Events;
using ConsoleFramework.Native;
using Xaml;

namespace ConsoleFramework.Controls
{
[ContentProperty( "Items" )]
public class ContextMenu
{
private readonly ObservableList< MenuItemBase > items = new ObservableList< MenuItemBase >(
new List< MenuItemBase >( ) );

public IList< MenuItemBase > Items {
get { return items; }
}

private MenuItem.Popup popup;
private bool expanded;

private bool popupShadow = true;
public bool PopupShadow {
get { return popupShadow; }
set { popupShadow = value; }
}

/// <summary>
/// Forces all open submenus to be closed.
/// </summary>
public void CloseAllSubmenus( ) {
List<MenuItem> expandedSubmenus = new List< MenuItem >();
MenuItem currentItem = ( MenuItem ) this.Items.SingleOrDefault(
item => item is MenuItem && ((MenuItem)item).expanded);
while ( null != currentItem ) {
expandedSubmenus.Add( currentItem );
currentItem = (MenuItem)currentItem.Items.SingleOrDefault(
item => item is MenuItem && ((MenuItem)item).expanded);
}
expandedSubmenus.Reverse( );
foreach ( MenuItem expandedSubmenu in expandedSubmenus ) {
expandedSubmenu.Close( );
}
}

private WindowsHost windowsHost;
private RoutedEventHandler windowsHostClick;
private KeyEventHandler windowsHostControlKeyPressed;

public void OpenMenu( WindowsHost windowsHost, Point point ) {
if ( expanded ) return;

// Вешаем на WindowsHost обработчик события MenuItem.ClickEvent,
// чтобы ловить момент выбора пункта меню в одном из модальных всплывающих окошек
// Дело в том, что эти окошки не являются дочерними элементами контрола Menu,
// а напрямую являются дочерними элементами WindowsHost (т.к. именно он создаёт
// окна). И событие выбора пункта меню из всплывающего окошка может быть поймано
// в WindowsHost, но не в Menu. А нам нужно повесить обработчик, который закроет
// все показанные попапы.
EventManager.AddHandler( windowsHost, MenuItem.ClickEvent,
windowsHostClick = ( sender, args ) => {
CloseAllSubmenus( );
popup.Close( );
}, true );

EventManager.AddHandler( windowsHost, MenuItem.Popup.ControlKeyPressedEvent,
windowsHostControlKeyPressed = ( sender, args ) => {
CloseAllSubmenus( );
//
//ConsoleApplication.Instance.FocusManager.SetFocusScope(this);
if ( args.wVirtualKeyCode == VirtualKeys.Right )
ConsoleApplication.Instance.FocusManager.MoveFocusNext( );
else if ( args.wVirtualKeyCode == VirtualKeys.Left )
ConsoleApplication.Instance.FocusManager.MoveFocusPrev( );
MenuItem focusedItem = ( MenuItem ) this.Items.SingleOrDefault(
item => item is MenuItem && item.HasFocus );
focusedItem.Expand( );
} );

if ( null == popup ) {
popup = new MenuItem.Popup( this.Items, this.popupShadow, 0 );
popup.AddHandler( Window.ClosedEvent, new EventHandler( onPopupClosed ) );
}
popup.X = point.X;
popup.Y = point.Y;
windowsHost.ShowModal( popup, true );
expanded = true;
this.windowsHost = windowsHost;
}

private void onPopupClosed( object sender, EventArgs eventArgs ) {
if (!expanded) throw new InvalidOperationException("This shouldn't happen");
expanded = false;
EventManager.RemoveHandler( windowsHost, MenuItem.ClickEvent, windowsHostClick );
EventManager.RemoveHandler( windowsHost, MenuItem.Popup.ControlKeyPressedEvent,
windowsHostControlKeyPressed );
}
}
}
65 changes: 45 additions & 20 deletions ConsoleFramework/Controls/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,16 @@ public T FindDirectChildByName< T >( string name ) where T:Control {
internal LayoutInfo layoutInfo = new LayoutInfo();
internal LayoutInfo lastLayoutInfo = new LayoutInfo();

private Visibility visibility;

public Visibility Visibility {
get;
set;
get { return visibility; }
set {
if ( visibility != value ) {
visibility = value;
Invalidate();
}
}
}

/// <summary>
Expand Down Expand Up @@ -1321,29 +1328,47 @@ protected static void assert( bool assertion ) {

/// <summary>
/// Определяет дочерний элемент, находящийся под курсором мыши,
/// и передаёт на него фокус, если он - Focusable и Visible.
/// и передаёт на него фокус, если он - Focusable. А если нажата правая кнопка мыши и у
/// контрола есть контекстное меню, активизирует его.
/// </summary>
protected void PassFocusToChildUnderPoint( MouseEventArgs args ) {
Control tofocus = null;
Control parent = this;
Control hitTested = null;
do
{
Point position = args.GetPosition(parent);
hitTested = parent.GetTopChildAtPoint(position);
if (null != hitTested)
{
parent = hitTested;
if (hitTested.Visibility == Visibility.Visible && hitTested.Focusable)
{
tofocus = hitTested;
Control topControl = VisualTreeHelper.FindTopControlUnderMouse( this, args.GetPosition( this ) );
if ( topControl != null ) {
if ( topControl.Focusable ) {
ConsoleApplication.Instance.FocusManager.SetFocus(this, topControl);
}
if ( args.RightButton == MouseButtonState.Pressed ) {
if ( topControl.ContextMenu != null ) {
var windowsHost = VisualTreeHelper.FindClosestParent< WindowsHost >( this );
topControl.ContextMenu.OpenMenu( windowsHost, args.GetPosition( windowsHost ) );
}
}
} while (hitTested != null);
if (tofocus != null)
{
ConsoleApplication.Instance.FocusManager.SetFocus(this, tofocus);
}
}

/// <summary>
/// This method is called after control has been created and filled with children.
/// todo : think about avoiding reentrant Created() calls
/// </summary>
public void Created( ) {
foreach ( var child in Children ) {
child.Created( );
}
OnCreated( );
}

/// <summary>
/// This method is invoked after control has been created and all children
/// controls are created too (and children' OnCreated called). So, you can
/// find any child control in this method and subscribe for events.
/// </summary>
protected virtual void OnCreated( ) {
}

private ContextMenu contextMenu;
public ContextMenu ContextMenu {
get { return contextMenu; }
set { contextMenu = value; }
}
}
}
2 changes: 1 addition & 1 deletion ConsoleFramework/Controls/ListBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ListBox : Control
public int? PageSize { get; set; }

private readonly ObservableList<string> items = new ObservableList<string>(new List<string>());
public IList<String> Items {
public ObservableList<String> Items {
get { return items; }
}

Expand Down
4 changes: 3 additions & 1 deletion ConsoleFramework/Controls/MessageBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public static void Show( string title, string text, MessageBoxClosedEventHandler
messageBox.Title = title;
messageBox.Text = text;
messageBox.AddHandler( ClosedEvent, new EventHandler(( sender, args ) => {
onClosed(MessageBoxResult.Button1);
if ( null != onClosed ) {
onClosed( MessageBoxResult.Button1 );
}
}) );
//messageBox.X =
windowsHost.ShowModal( messageBox );
Expand Down
2 changes: 1 addition & 1 deletion ConsoleFramework/Controls/Panel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using ConsoleFramework.Core;
using ConsoleFramework.Native;
using ConsoleFramework.Rendering;
Expand Down Expand Up @@ -131,6 +130,7 @@ public override void Render(RenderingBuffer buffer) {
buffer.SetPixel(x, y, ' ', Attr.BACKGROUND_BLUE |
Attr.BACKGROUND_GREEN | Attr.BACKGROUND_RED | Attr.FOREGROUND_BLUE |
Attr.FOREGROUND_GREEN | Attr.FOREGROUND_RED | Attr.FOREGROUND_INTENSITY);
buffer.SetOpacity( x, y, 4 );
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions ConsoleFramework/Controls/ProgressBar.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ConsoleFramework.Core;
using System;
using ConsoleFramework.Core;
using ConsoleFramework.Native;
using ConsoleFramework.Rendering;

Expand All @@ -25,7 +26,7 @@ public override void Render( RenderingBuffer buffer ) {
Attr attr = Colors.Blend( Color.DarkCyan, Color.DarkBlue );
buffer.FillRectangle(0, 0, ActualWidth, ActualHeight, UnicodeTable.MediumShade, attr);
int filled = ( int ) ( ActualWidth*( Percent*0.01 ) );
buffer.FillRectangle(0, 0, filled, ActualHeight, UnicodeTable.DarkShade, attr);
buffer.FillRectangle(0, 0, Math.Min( filled, ActualWidth ), ActualHeight, UnicodeTable.DarkShade, attr);
}
}
}
Loading

0 comments on commit 6a4651b

Please sign in to comment.