You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
5.5 KiB
124 lines
5.5 KiB
using System ;
|
|
using System.Text ;
|
|
using System.Drawing ;
|
|
using System.IO ;
|
|
using System.Runtime.InteropServices ;
|
|
using System.Collections.Generic ;
|
|
using System.Windows.Forms ;
|
|
using System.Diagnostics ;
|
|
|
|
using Manina.Windows.Forms ;
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
public partial class MainForm : Form
|
|
{
|
|
private void InitializeComponent()
|
|
{
|
|
// initialize the form
|
|
this.Text = Program.APP_NAME ;
|
|
this.MinimumSize = new Size( 800, 500 ) ;
|
|
|
|
// initialize the main splitter
|
|
this.mSplitter.Orientation = Orientation.Horizontal ;
|
|
this.mSplitter.Location = new Point( 0, 0 ) ;
|
|
this.mSplitter.Size = new Size( this.Width, this.Height ) ;
|
|
this.mSplitter.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right ;
|
|
this.mSplitter.FixedPanel = FixedPanel.Panel1 ;
|
|
this.mSplitter.Panel1MinSize = 140 ;
|
|
this.mSplitter.Panel2MinSize = 300 ;
|
|
this.mSplitter.SplitterDistance = this.mSplitter.Panel1MinSize ;
|
|
this.mSplitter.Panel1.BackColor = Color.White ;
|
|
this.mSplitter.Panel2.BackColor = Color.White ;
|
|
this.mSplitter.BackColor = SystemColors.Control ;
|
|
this.mSplitter.SplitterWidth = 2 ;
|
|
this.Controls.Add( mSplitter ) ;
|
|
|
|
// initialize the top pane (search)
|
|
int margin = 2 ;
|
|
this.mSearchUserControl.Size = new Size( 100, mSplitter.Panel1.Size.Height ) ;
|
|
this.mSearchLabel.Location = new Point( margin, margin ) ;
|
|
this.mSearchLabel.Size = new Size( mSearchUserControl.Width - 2*margin, 15 ) ;
|
|
this.mSearchLabel.Font = new Font( mSearchLabel.Font, FontStyle.Bold ) ;
|
|
this.mSearchLabel.Text = "Search for:" ;
|
|
this.mSearchUserControl.Controls.Add( mSearchLabel ) ;
|
|
this.mSearchQuery.Location = new Point( margin, mSearchLabel.Location.Y + mSearchLabel.Height ) ;
|
|
this.mSearchQuery.Width = mSearchLabel.Width ;
|
|
this.mSearchQuery.BorderStyle = BorderStyle.FixedSingle ;
|
|
this.mSearchUserControl.Controls.Add( mSearchQuery ) ;
|
|
this.mSplitter.Panel1.Controls.Add( mSearchUserControl ) ;
|
|
this.mSearchResults.View = Manina.Windows.Forms.View.Gallery ;
|
|
this.mSearchResults.SetRenderer( new AppImageListView.AppImageListViewRenderer() ) ;
|
|
this.mSearchResults.CacheMode = CacheMode.Continuous ;
|
|
this.mSearchResults.Location = new Point( mSearchUserControl.Location.X + mSearchUserControl.Width, margin ) ;
|
|
Size searchResultsSize = new Size( mSplitter.Width - (mSearchQuery.Location.X + mSearchQuery.Width) - margin, mSplitter.Panel1MinSize ) ;
|
|
this.mSearchResults.Size = searchResultsSize ;
|
|
this.mSearchResults.BorderStyle = BorderStyle.None ;
|
|
this.mSearchResults.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom ;
|
|
this.mSplitter.Panel1.Controls.Add( mSearchResults ) ;
|
|
this.mSearchResults.Size = searchResultsSize ; // FUDGE! need to do this again :shrug:
|
|
|
|
// initialize the bottom pane (image viewer)
|
|
// FIXME! We will probably need something better to render the images, but this will do, for now...
|
|
this.mImagePictureBox.Dock = DockStyle.Fill ;
|
|
this.mImagePictureBox.SizeMode = PictureBoxSizeMode.Zoom ;
|
|
this.mSplitter.Panel2.Controls.Add( mImagePictureBox ) ;
|
|
|
|
// initialize handlers
|
|
this.Load += new EventHandler( this.MainForm_Load ) ;
|
|
this.mSearchQuery.TextChanged += new EventHandler( this.SearchQuery_TextChanged ) ;
|
|
this.mSearchQuery.KeyDown += new KeyEventHandler( this.SearchQuery_KeyDown ) ;
|
|
this.mSearchResults.KeyPress += new KeyPressEventHandler( this.SearchResults_KeyPress ) ;
|
|
this.mSearchResults.SelectionChanged += new EventHandler( this.SearchResults_SelectionChanged ) ;
|
|
}
|
|
|
|
private void MainForm_Load( object sender, EventArgs e )
|
|
{
|
|
// load the chart images
|
|
loadChartImages() ;
|
|
loadSearchResults( mChartImages.Values ) ;
|
|
}
|
|
|
|
private void SearchResults_SelectionChanged( object sender, EventArgs e )
|
|
{
|
|
// show the selected chart image
|
|
Debug.Assert( mSearchResults.SelectedItems.Count == 1 ) ;
|
|
ChartImage chartImage ;
|
|
if ( mSearchResults.SelectedItems.Count > 0 ) {
|
|
chartImage = (ChartImage) mSearchResults.SelectedItems[0].Tag ;
|
|
mImagePictureBox.Image = chartImage.image ;
|
|
} else
|
|
mImagePictureBox.Image = null ;
|
|
}
|
|
|
|
private void SearchQuery_TextChanged( object sender, EventArgs e )
|
|
{
|
|
// update the search results
|
|
updateSearchResults( mSearchQuery.Text.Trim() ) ;
|
|
}
|
|
|
|
private void SearchQuery_KeyDown( object sender, KeyEventArgs e )
|
|
{
|
|
// check if we should apply the keypress to the search results
|
|
if ( e.KeyCode == Keys.Escape )
|
|
mSearchQuery.Text = "" ;
|
|
else if ( e.KeyCode == Keys.Left || e.KeyCode == Keys.Right ) {
|
|
mSearchResults.Focus() ;
|
|
SendKeys.SendWait( "{" + e.KeyCode.ToString() + "}" ) ;
|
|
mSearchQuery.Focus() ;
|
|
e.Handled = true ;
|
|
}
|
|
}
|
|
|
|
private void SearchResults_KeyPress( object sender, KeyPressEventArgs e )
|
|
{
|
|
// check if we should apply the keypress to the search query
|
|
int ch = (int) e.KeyChar ;
|
|
if ( ch == 27 )
|
|
mSearchQuery.Text = "" ;
|
|
else if ( ch >= 32 && ch < 127 ) {
|
|
mSearchQuery.AppendText( e.KeyChar.ToString() ) ;
|
|
mSearchQuery.Focus() ;
|
|
}
|
|
}
|
|
}
|
|
|