Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bk-mz committed Nov 26, 2011
0 parents commit 3ba52e6
Show file tree
Hide file tree
Showing 54 changed files with 4,077 additions and 0 deletions.
Binary file not shown.
Binary file added Lib/Microsoft.Practices.CompositeUI.dll
Binary file not shown.
Binary file added Lib/Microsoft.Practices.ObjectBuilder.dll
Binary file not shown.
86 changes: 86 additions & 0 deletions Source/Common/Common.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{07040940-073F-4CBE-A4AA-5977147A5F6C}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WordCAB.Common</RootNamespace>
<AssemblyName>Common</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Practices.CompositeUI, Version=1.0.51205.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Lib\Microsoft.Practices.CompositeUI.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Practices.CompositeUI.WinForms, Version=1.0.51205.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Lib\Microsoft.Practices.CompositeUI.WinForms.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Practices.ObjectBuilder, Version=1.0.51205.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Lib\Microsoft.Practices.ObjectBuilder.dll</HintPath>
</Reference>
<Reference Include="stdole, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\Program Files\Microsoft.NET\Primary Interop Assemblies\stdole.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Constants.cs" />
<Compile Include="Controls\WordButtonClickArgs.cs" />
<Compile Include="Extensions\CommandBarButtonUIAdapter.cs" />
<Compile Include="Extensions\CommandBarUIAdapter.cs" />
<Compile Include="Extensions\CommandBarUIAdapterFactory.cs" />
<Compile Include="Extensions\IUiElementFactory.cs" />
<Compile Include="Controls\IWordButton.cs" />
<Compile Include="Controls\IWordCommandBar.cs" />
<Compile Include="Controls\IWordCommandBarContainer.cs" />
<Compile Include="Guard.cs" />
<Compile Include="MVP\Presenter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Components\IconConverter.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Services\IWordSelectionGetter.cs" />
<Compile Include="Workspaces\CabModal.cs" />
<Compile Include="Workspaces\Modal.cs" />
<Compile Include="Workspaces\SimpleModalWorkspace.cs" />
<Compile Include="Workspaces\WindowSmartpartInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
85 changes: 85 additions & 0 deletions Source/Common/Components/IconConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using stdole;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;

namespace WordCAB.Common.Components
{
/// <summary>
/// Êëàññ, èíêàïñóëèðóþùèé ëîãèêó ïðåîáðàçîâàíèÿ èçîáðàæåíèé äëÿ COM è ActiveX ïðèëîæåíèé.
/// </summary>
public sealed class AxIconConverter : AxHost
{
#region Statics
public static readonly AxIconConverter Instance = new AxIconConverter();
#endregion

#region Ctor
public AxIconConverter()
: base("A9D9FE18-89C4-4cf2-884C-AD692CF5F268")
{ }
#endregion

#region Public Methods
public IPictureDisp Convert<T>(T image)
where T : Image
{
return GetIPictureFromPicture(image) as IPictureDisp;
}

public IPictureDisp Convert(Icon icon)
{
return Convert<Image>(icon.ToBitmap());
}

public IPictureDisp CreateMask(Image image)
{
return Convert<Image>(createMask(image));
}
#endregion

#region Private Methods
private Image createMask(Image sourceImage)
{
Guard.ArgumentNotNull(sourceImage, "sourceImage");

Bitmap resultBitmap = new Bitmap(sourceImage.Width, sourceImage.Height, PixelFormat.Format24bppRgb);

using ( Bitmap sourceBitmap = new Bitmap(sourceImage.Width, sourceImage.Height, PixelFormat.Format32bppArgb) )
{
using ( Graphics graphics = Graphics.FromImage(sourceBitmap) )
graphics.DrawImage(sourceImage, new Rectangle(0, 0, sourceImage.Width, sourceImage.Height), 0, 0, sourceImage.Width, sourceImage.Height, GraphicsUnit.Pixel);

BitmapData sourceData = sourceBitmap.LockBits(new Rectangle(0, 0, sourceBitmap.Width, sourceBitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
BitmapData resultData = resultBitmap.LockBits(new Rectangle(0, 0, resultBitmap.Width, resultBitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);

for ( int y = 0; y < sourceData.Height; y++ )
{
for ( int x = 0; x < sourceData.Width; x++ )
{
int pixel = y * sourceData.Stride + x * 4;

byte alpha = Marshal.ReadByte(sourceData.Scan0, pixel + 3);

if ( alpha == 0 )
{
Marshal.WriteByte(resultData.Scan0, ( y * resultData.Stride + x * 3 ), 255);
Marshal.WriteByte(resultData.Scan0, ( y * resultData.Stride + x * 3 ) + 1, 255);
Marshal.WriteByte(resultData.Scan0, ( y * resultData.Stride + x * 3 ) + 2, 255);
}
}
}

sourceBitmap.UnlockBits(sourceData);
resultBitmap.UnlockBits(resultData);
}

return resultBitmap;
}
#endregion
}
}
21 changes: 21 additions & 0 deletions Source/Common/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace WordCAB.Common
{
public class UIExtensionSiteNames
{
public const string WordBarsSite = "WordBarsSite";
}

public class CommandNames
{
public const string OpenForm = "OpenForm";
}

public class WorkspaceNames
{
public const string MainWorkspace = "MainWorkspace";
}
}
43 changes: 43 additions & 0 deletions Source/Common/Controls/IWordButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace WordCAB.Common.Controls
{
/// <summary>
/// Интерфейс для кнопки на тулбаре Microsoft Word
/// </summary>
public interface IWordButton
{
/// <summary>
/// Тулбар, которому принадлежит кнопка
/// </summary>
IWordCommandBar Parent { get; set; }
/// <summary>
/// Стиль представления изображения кнопки и текста Caption
/// </summary>
ToolStripItemDisplayStyle ImageDisplayStyle { get; set; }
/// <summary>
/// Текст кнопки
/// </summary>
string Caption { get; set; }
/// <summary>
/// Команда, которую отсылает кнопка
/// </summary>
string CommandId { get; set; }
/// <summary>
/// Изображение
/// </summary>
Image Glyph { get; set; }
/// <summary>
/// Флаг: кнопка начинает группу
/// </summary>
bool BeginsGroup { get; set; }
/// <summary>
/// Событие нажатия кнопки
/// </summary>
event EventHandler<WordButtonClickArgs> Click;
}
}
27 changes: 27 additions & 0 deletions Source/Common/Controls/IWordCommandBar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.CompositeUI;

namespace WordCAB.Common.Controls
{
/// <summary>
/// Интерфейс для тулбара Micosoft Word
/// </summary>
public interface IWordCommandBar
{
/// <summary>
/// Список кнопок
/// </summary>
List<IWordButton> Buttons { get; }
/// <summary>
/// Идентификатор тулбара
/// </summary>
string Id { get; }
/// <summary>
/// Добавить кнопку
/// </summary>
/// <param name="uiElement">Кнопка</param>
void AddButton(IWordButton uiElement);
}
}
18 changes: 18 additions & 0 deletions Source/Common/Controls/IWordCommandBarContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace WordCAB.Common.Controls
{
/// <summary>
/// Контейнер тулбаров для Microsoft Word
/// </summary>
public interface IWordCommandBarContainer
{
/// <summary>
/// Добавить тулбар
/// </summary>
/// <param name="bar">тулбар</param>
void AddBar(IWordCommandBar bar);
}
}
19 changes: 19 additions & 0 deletions Source/Common/Controls/WordButtonClickArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace WordCAB.Common.Controls
{
public class WordButtonClickArgs : EventArgs
{
private string _commandId = string.Empty;
/// <summary>
/// Идентификатор команды, которой соответствует кнопка
/// </summary>
public string CommandId
{
get { return _commandId; }
set { _commandId = value; }
}
}
}
29 changes: 29 additions & 0 deletions Source/Common/Extensions/CommandBarButtonUIAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.CompositeUI.UIElements;
using WordCAB.Common.Controls;

namespace WordCAB.Common.Extensions
{
public class CommandBarButtonUIAdapter : UIElementAdapter<IWordButton>
{
public CommandBarButtonUIAdapter(IWordCommandBar bar)
{
_bar = Guard.ArgumentNotNull<IWordCommandBar>(bar);
}

protected override IWordButton Add(IWordButton uiElement)
{
_bar.AddButton(uiElement);
return uiElement;
}

protected override void Remove(IWordButton uiElement)
{
throw new NotSupportedException("Удаление кнопок не поддерживается");
}

private IWordCommandBar _bar;
}
}
29 changes: 29 additions & 0 deletions Source/Common/Extensions/CommandBarUIAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.CompositeUI.UIElements;
using WordCAB.Common.Controls;

namespace WordCAB.Common.Extensions
{
public class CommandBarUIAdapter : UIElementAdapter<IWordCommandBar>
{
public CommandBarUIAdapter(IWordCommandBarContainer container)
{
_container = Guard.ArgumentNotNull<IWordCommandBarContainer>(container);
}

protected override IWordCommandBar Add(IWordCommandBar uiElement)
{
_container.AddBar(uiElement);
return uiElement;
}

protected override void Remove(IWordCommandBar uiElement)
{
throw new NotSupportedException("Удаление тулбаров не поддерживается");
}

private IWordCommandBarContainer _container;
}
}
26 changes: 26 additions & 0 deletions Source/Common/Extensions/CommandBarUIAdapterFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.CompositeUI.UIElements;
using WordCAB.Common.Controls;

namespace WordCAB.Common.Extensions
{
public class CommandBarUIAdapterFactory : IUIElementAdapterFactory
{
public IUIElementAdapter GetAdapter(object uiElement)
{
if ( uiElement is IWordCommandBarContainer )
return new CommandBarUIAdapter(( IWordCommandBarContainer )uiElement);
if ( uiElement is IWordCommandBar )
return new CommandBarButtonUIAdapter(( IWordCommandBar )uiElement);

throw new ArgumentException("uiElement");
}

public bool Supports(object uiElement)
{
return ( uiElement is IWordCommandBarContainer ) || ( uiElement is IWordCommandBar );
}
}
}
Loading

0 comments on commit 3ba52e6

Please sign in to comment.