source: libpipi/trunk/ThePimp/src/MainWindow.cs @ 3144

Last change on this file since 3144 was 3144, checked in by Sam Hocevar, 14 years ago

ThePimp?: add Fullscreen support, including the F11 binding.

File size: 3.5 KB
Line 
1//
2//  The Pimp      The Pathetic Image Manipulation Program
3//  Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
4//                All Rights Reserved
5//
6//  $Id$
7//
8//  This library is free software. It comes without any warranty, to
9//  the extent permitted by applicable law. You can redistribute it
10//  and/or modify it under the terms of the Do What The Fuck You Want
11//  To Public License, Version 2, as published by Sam Hocevar. See
12//  http://sam.zoy.org/wtfpl/COPYING for more details.
13//
14
15using System;
16using Gtk;
17using Pipi;
18using ThePimp;
19
20namespace ThePimp
21{
22    [Gtk.Binding(Gdk.Key.F11, "ToggleFullScreen")]
23
24    public partial class MainWindow: Gtk.Window
25    {
26        public MainWindow (): base (Gtk.WindowType.Toplevel)
27        {
28            Build ();
29            vpaned1.Add1(new ToolBox());
30        }
31
32        protected void OnDeleteEvent (object sender, DeleteEventArgs a)
33        {
34            Application.Quit ();
35            a.RetVal = true;
36        }
37
38        protected virtual void OnOpenActionActivated (object sender, System.EventArgs e)
39        {
40            OpenFile dialog = new OpenFile();
41
42            string s = dialog.GetChoice();
43            dialog.Destroy();
44            if(s == null)
45                return;
46
47            Pipi.Picture p = Pipi.Picture.Load(s);
48            if(p == null)
49            {
50                new ErrorWindow("Could not open \"" + s + "\". Check the file format.");
51                return;
52            }
53
54            while(notebook1.NPages > 0)
55                notebook1.RemovePage(0);
56            int n = notebook1.AppendPage(new PictureView(p),
57                                         new Label(p.FileName));
58            notebook1.Page = n;
59        }
60
61        protected virtual void OnNewActionActivated (object sender, System.EventArgs e)
62        {
63            NewFile dialog = new NewFile();
64
65            string s = dialog.GetChoice();
66            dialog.Destroy();
67            if(s == null)
68                return;
69
70            Pipi.Picture p = Pipi.Picture.Load(s);
71            if(p == null)
72            {
73                new ErrorWindow("Could not create image.");
74                return;
75            }
76
77            while(notebook1.NPages > 0)
78                notebook1.RemovePage(0);
79            int n = notebook1.AppendPage(new PictureView(p),
80                                         new Label(p.FileName));
81            notebook1.Page = n;
82        }
83
84        protected virtual void OnQuitActionActivated (object sender, System.EventArgs e)
85        {
86            Application.Quit ();
87        }
88
89        protected virtual void OnSaveAsActionActivated (object sender, System.EventArgs e)
90        {
91            if(notebook1.NPages <= 0)
92                return;
93            SaveFile save = new SaveFile();
94            PictureView view = notebook1.CurrentPageWidget as PictureView;
95            save.Save(view.Picture);
96            save.Destroy();
97        }
98
99        protected virtual void OnAboutActionActivated (object sender, System.EventArgs e)
100        {
101            new AboutWindow();
102        }
103
104        protected virtual void OnSaveActionActivated (object sender, System.EventArgs e)
105        {
106        }
107
108        private bool _fullscreen = false;
109        protected virtual void ToggleFullScreen()
110        {
111            _fullscreen = !_fullscreen;
112
113            if(_fullscreen)
114                Fullscreen();
115            else
116                Unfullscreen();
117        }
118
119        protected virtual void OnFullscreenActionActivated (object sender, System.EventArgs e)
120        {
121            ToggleFullScreen();
122        }
123    }
124}
Note: See TracBrowser for help on using the repository browser.