1 /*
2  *  "GEDKeeper", the personal genealogical database editor.
3  *  Copyright (C) 2009-2018 by Sergey V. Zhdanovskih.
4  *
5  *  This file is part of "GEDKeeper".
6  *
7  *  This program is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 using System;
22 using Eto.Forms;
23 using GDModel;
24 using GKCore;
25 using GKCore.Controllers;
26 using GKCore.Interfaces;
27 using GKCore.MVP.Controls;
28 using GKCore.MVP.Views;
29 using GKUI.Components;
30 
31 namespace GKUI.Forms
32 {
33     public sealed partial class PortraitSelectDlg : EditorDialog, IPortraitSelectDlg
34     {
35         private readonly PortraitSelectDlgController fController;
36 
37         private ITimer fTimer;
38 
39         public GDMMultimediaLink MultimediaLink
40         {
41             get { return fController.MultimediaLink; }
42             set { fController.MultimediaLink = value; }
43         }
44 
45         #region View Interface
46 
47         IImageView IPortraitSelectDlg.ImageCtl
48         {
49             get { return imageView1; }
50         }
51 
52         #endregion
53 
btnAccept_Click(object sender, EventArgs e)54         private void btnAccept_Click(object sender, EventArgs e)
55         {
56             DialogResult = fController.Accept() ? DialogResult.Ok : DialogResult.None;
57         }
58 
PortraitSelectDlg(IBaseWindow baseWin)59         public PortraitSelectDlg(IBaseWindow baseWin)
60         {
61             InitializeComponent();
62 
63             btnAccept.Image = UIHelper.LoadResourceImage("Resources.btn_accept.gif");
64             btnCancel.Image = UIHelper.LoadResourceImage("Resources.btn_cancel.gif");
65 
66             imageView1.SelectionMode = ImageBoxSelectionMode.Rectangle;
67 
68             // SetLocale()
69             btnAccept.Text = LangMan.LS(LSID.LSID_DlgAccept);
70             btnCancel.Text = LangMan.LS(LSID.LSID_DlgCancel);
71             Title = LangMan.LS(LSID.LSID_PortraitSelect);
72 
73             fTimer = AppHost.Instance.CreateTimer(100.0f, InitViewer_Tick);
74             fTimer.Start();
75 
76             fController = new PortraitSelectDlgController(this);
77             fController.Init(baseWin);
78         }
79 
OnLoad(EventArgs e)80         protected override void OnLoad(EventArgs e)
81         {
82             base.OnLoad(e);
83 
84             if (imageView1 != null) {
85                 imageView1.Focus();
86                 imageView1.Invalidate();
87                 imageView1.ZoomToFit();
88             }
89         }
90 
91         // dirty temporary hack
InitViewer_Tick(object sender, EventArgs e)92         private void InitViewer_Tick(object sender, EventArgs e)
93         {
94             if (imageView1 != null && !imageView1.Viewport.Size.IsEmpty) {
95                 imageView1.ZoomToFit();
96                 fTimer.Stop();
97             }
98         }
99     }
100 }
101