Skip to content

Commit

Permalink
wpf tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
ataranto committed Feb 29, 2012
1 parent 1dc6da1 commit ab91d46
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CefSharp.Example/CefSharp.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<Content Include="Resources\BindingTest.html" />
<Content Include="Resources\PopupTest.html" />
<Content Include="Resources\SchemeTest.html" />
<Content Include="Resources\TooltipTest.html" />
<Content Include="Resources\TooltipsTest.html" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
7 changes: 7 additions & 0 deletions CefSharp.Example/ExamplePresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static void Init()
private const string resource_url = "http://test/resource/load";
private const string scheme_url = "test://test/SchemeTest.html";
private const string bind_url = "test://test/BindingTest.html";
private const string tooltips_url = "test://test/TooltipsTest.html";

private int color_index = 0;
private readonly string[] colors =
Expand Down Expand Up @@ -54,6 +55,7 @@ public ExamplePresenter(IWebBrowser model, IExampleView view,
this.view.TestEvaluateScriptActivated += view_TestEvaluateScriptActivated;
this.view.TestBindActivated += view_TestBindActivated;
this.view.TestConsoleMessageActivated += view_TestConsoleMessageActivated;
this.view.TestTooltipsActivated += view_TestTooltipsActivated;
this.view.ExitActivated += view_ExitActivated;
}

Expand Down Expand Up @@ -157,6 +159,11 @@ private void view_TestConsoleMessageActivated(object sender, EventArgs e)
view.ExecuteScript(script);
}

private void view_TestTooltipsActivated(object sender, EventArgs e)
{
model.Load(tooltips_url);
}

private void view_ExitActivated(object sender, EventArgs e)
{
CEF.Shutdown();
Expand Down
1 change: 1 addition & 0 deletions CefSharp.Example/IExampleView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public interface IExampleView
event EventHandler TestEvaluateScriptActivated;
event EventHandler TestBindActivated;
event EventHandler TestConsoleMessageActivated;
event EventHandler TestTooltipsActivated;
event EventHandler ExitActivated;

void SetTitle(string title);
Expand Down
4 changes: 2 additions & 2 deletions CefSharp.Example/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions CefSharp.Example/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
<data name="SchemeTest" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\SchemeTest.html;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="TooltipTest" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\TooltipTest.html;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
<data name="TooltipsTest" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\TooltipsTest.html;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<body>
<form>
<input type="text" size=25 title="This is the first tooltip">
<br />
<input type="text" size=25 title="This is the second tooltip">
<input type="button" value="Submit">
</form>
</body>
</html>
2 changes: 1 addition & 1 deletion CefSharp.Example/SchemeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public SchemeHandler()
{ "BindingTest.html", Resources.BindingTest },
{ "PopupTest.html", Resources.PopupTest },
{ "SchemeTest.html", Resources.SchemeTest },
{ "TooltipTest.html", Resources.TooltipTest },
{ "TooltipsTest.html", Resources.TooltipsTest },
};
}

Expand Down
29 changes: 29 additions & 0 deletions CefSharp.Test/BrowserCoreTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using NUnit.Framework;

namespace CefSharp.Test
{
[TestFixture]
public class BrowserCoreTest
{
private BrowserCore browser_core;

[SetUp]
public void SetUp()
{
browser_core = new BrowserCore();
}

[Test]
public void Test()
{
int event_count = 0;
browser_core.PropertyChanged += (sender, e) => event_count++;

browser_core.Tooltip = "foo";
browser_core.Tooltip = null;
browser_core.Tooltip = null;

Assert.AreEqual(2, event_count);
}
}
}
3 changes: 3 additions & 0 deletions CefSharp.Test/CefSharp.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@
<HintPath>..\nunit\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BrowserCoreTest.cs" />
<Compile Include="BrowserTest.cs" />
<Compile Include="Fixture.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
11 changes: 10 additions & 1 deletion CefSharp.WinForms.Example/Browser.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions CefSharp.WinForms.Example/Browser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public event EventHandler TestConsoleMessageActivated
remove { testConsoleMessageMenuItem.Click -= value; }
}

public event EventHandler TestTooltipsActivated
{
add { testTooltipsMenuItem.Click += value; }
remove { testTooltipsMenuItem.Click -= value; }
}

public event EventHandler ExitActivated
{
add { exitToolStripMenuItem.Click += value; }
Expand Down
1 change: 1 addition & 0 deletions CefSharp.Wpf.Example/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<MenuItem Header="Test Evaluate JavaScript" Name="testEvaluateScriptMenuItem" Click="control_Activated" />
<MenuItem Header="Test Bind CLR Object to JavaScript" Name="testBindMenuItem" Click="control_Activated" />
<MenuItem Header="Test Console Message" Name="testConsoleMessageMenuItem" Click="control_Activated" />
<MenuItem Header="Test Tooltips" Name="testTooltipsMenuItem" Click="control_Activated" />
</MenuItem>
<MenuItem Header="Bookmarks">
<MenuItem Header="CefSharp Home" Name="homeMenuItem" />
Expand Down
2 changes: 2 additions & 0 deletions CefSharp.Wpf.Example/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public partial class MainWindow : Window, IExampleView
public event EventHandler TestEvaluateScriptActivated;
public event EventHandler TestBindActivated;
public event EventHandler TestConsoleMessageActivated;
public event EventHandler TestTooltipsActivated;
public event EventHandler ExitActivated;

private WebView web_view;
Expand Down Expand Up @@ -51,6 +52,7 @@ private void Window_SourceInitialized(object sender, EventArgs e)
{ testEvaluateScriptMenuItem, TestEvaluateScriptActivated },
{ testBindMenuItem, TestBindActivated },
{ testConsoleMessageMenuItem, TestConsoleMessageActivated },
{ testTooltipsMenuItem, TestTooltipsActivated },
{ exitMenuItem, ExitActivated },
};
}
Expand Down
14 changes: 12 additions & 2 deletions CefSharp.Wpf/WebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,19 @@ namespace Wpf
gcnew Action<SafeFileHandle^>(this, &WebView::SetCursor), handle);
}

void WebView::SetTooltip(String^ tooltip)
void WebView::SetTooltip(String^ text)
{
ToolTip = tooltip;
_toolTip->Placement = Primitives::PlacementMode::Mouse;

if (String::IsNullOrEmpty(text))
{
_toolTip->IsOpen = false;
}
else
{
_toolTip->Content = text;
_toolTip->IsOpen = true;
}
}

void WebView::SetBuffer(int width, int height, const void* buffer)
Expand Down
8 changes: 7 additions & 1 deletion CefSharp.Wpf/WebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using namespace System::ComponentModel;
using namespace System::Runtime::InteropServices;
using namespace System::Windows;
using namespace System::Windows::Controls;
using namespace System::Windows::Controls::Primitives;
using namespace System::Windows::Input;
using namespace System::Windows::Interop;
using namespace System::Windows::Media;
Expand All @@ -32,6 +33,7 @@ namespace Wpf
MCefRefPtr<ScriptCore> _scriptCore;

Image^ _image;
System::Windows::Controls::ToolTip^ _toolTip;

int _width, _height;
InteropBitmap^ _ibitmap;
Expand All @@ -42,7 +44,7 @@ namespace Wpf
void WaitForInitialized();
void BrowserCore_PropertyChanged(Object^ sender, PropertyChangedEventArgs^ e);
void SetCursor(SafeFileHandle^ handle);
void SetTooltip(String^ tooltip);
void SetTooltip(String^ text);
IntPtr SourceHook(IntPtr hWnd, int message, IntPtr wParam, IntPtr lParam, bool% handled);
void SetBitmap();

Expand Down Expand Up @@ -94,6 +96,10 @@ namespace Wpf
_paintDelegate = gcnew ActionDelegate(this, &WebView::SetBitmap);
source->AddHook(gcnew Interop::HwndSourceHook(this, &WebView::SourceHook));

ToolTip = _toolTip =
gcnew System::Windows::Controls::ToolTip();
_toolTip->StaysOpen = true;

HWND hWnd = static_cast<HWND>(source->Handle.ToPointer());
CefWindowInfo window;
window.SetAsOffScreen(hWnd);
Expand Down

0 comments on commit ab91d46

Please sign in to comment.