-
AvalonEditからフォーカスを外すと、Imeが無効になって直らない件
2013-03-19 00:361なかなか開発が進みませんが、引き続きAvalonEditへの置き換えを進めます。
なんとなく行けそう? な感じが出てきました。
ちょこちょこ触ってる限りでは、さくさく動くし、以前みたく文字が引っかかる感じもなく快適です。
しかし、ここから色々出てくるのが開発のさがではあります。
特に海外産ライブラリを使っていて不安になるところはやっぱりIMEの挙動です。
AvalonEditは色んな国の人が利用しているだけあって、比較的良い感じに対応してくれてるのですが・・・・・・
こういう風にバッテンマークが出てくると困るわけです。こうなると一切日本語入力を受け付けなくなります。直し方わかんないし。
「Ime Disable」「Ime Invalid」とか必死のGoogle検索も奏功せず、仕方なくよくある暫定対処の方法をとります。
見えないところにTextBoxを作っておいて、AvalonEditコントロールにフォーカスする直前にダミーのTextBoxにフォーカスするというパッチワーク。private void Editor_PreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
// 一旦フォーカスが外れると、IMEが無効になる問題への対処療法
DummyTextBox.Focus();
InputMethod.SetPreferredImeState(Editor, InputMethodState.On);
}
とりあえず、これで。お知らせ -
AvalonEditの実験(Offsetから座標を取る)
2013-02-19 23:44ArtOfWordsでも使ってる汎用のTextBoxがイマイチ使いづらい……。(何か挙動も怪しいし)
のでAvalonEditっていうコントロールに切り替えようと画策中です。
使える……といいなあ。
とりあえず自由に座標取ってテキストに色をつけられるかどうかが一番ネックになりそうだったのでそこから実験。
結果は……。
できたじゃないですか!
エンジニアならコード貼っとくのが一番わかる(至言)はずなのでペタンコ。
Xaml<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit" x:Class="AvalonTester.MainWindow"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel Orientation="Vertical"><avalonedit:TextEditor Name="Editor" Text="明日は明日の風が吹く"/>
<Button Content="「明日の風」に色をつける" Click="Button_Click_1" /></StackPanel>
<Canvas Name="CanvasForDraw" ClipToBounds="True"/>
</Grid>
</Window>
コードビハインド
因みに普通のTextBoxでは地道にGetRectFromCharacterIndexとか使って座標とってます。(ここが一番パフォーマンスでネックになってる)using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Rendering;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;namespace AvalonTester
{
/// <summary>
/// MainWindow.xaml の相互作用ロジック
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}private Rectangle GenerateRectangle(Rect r)
{
return new Rectangle()
{
Width = r.Width,
Height = r.Height,
Fill = new SolidColorBrush(Color.FromArgb(128, 0, 0, 128))
};
}private void DrawRectangle(Rect r)
{
var rectangle = GenerateRectangle(r);
Canvas.SetLeft(rectangle, r.Left);
Canvas.SetTop(rectangle, r.Top);CanvasForDraw.Children.Add(rectangle);
}private void Button_Click_1(object sender, RoutedEventArgs e)
{
string searchWord = "明日の風";
var index = this.Editor.Document.Text.IndexOf(searchWord);
if (index == -1)
{
return;
}var seg = new TextSegment()
{
StartOffset = index,
EndOffset = index + searchWord.Length,
};foreach (Rect r in BackgroundGeometryBuilder.GetRectsForSegment(this.Editor.TextArea.TextView, seg))
{
DrawRectangle(r);
}
}
}
}
-
マニュアル見直しながら、ふと気づいたこと
2013-02-18 00:32
1 / 3