~mantas/pinta/stable

« back to all changes in this revision

Viewing changes to Pinta/MainWindow.cs

  • Committer: Iain Lane
  • Date: 2010-03-13 18:20:18 UTC
  • mfrom: (1.1.2)
  • Revision ID: git-v1:1781694a68ecf232d0110c0b2f3d4a1b96c74ec2
Merge commit 'upstream/0.2'

Conflicts:
        debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
                        PintaCore.Actions.AccelGroup = new AccelGroup ();
49
49
                        this.AddAccelGroup (PintaCore.Actions.AccelGroup);
50
50
 
51
 
                        PintaCore.Initialize (tooltoolbar, label5, drawingarea1, treeview1, this);
 
51
                        PintaCore.Initialize (tooltoolbar, label5, drawingarea1, history_treeview, this);
52
52
                        colorpalettewidget1.Initialize ();
53
53
 
54
54
                        PintaCore.Chrome.StatusBarTextChanged += new EventHandler<TextChangedEventArgs> (Chrome_StatusBarTextChanged);
55
 
                        PintaCore.History.HistoryItemAdded += new EventHandler<HistoryItemAddedEventArgs> (History_HistoryItemAdded);
56
55
                        PintaCore.Workspace.CanvasInvalidated += new EventHandler<CanvasInvalidatedEventArgs> (Workspace_CanvasInvalidated);
57
56
                        PintaCore.Workspace.CanvasSizeChanged += new EventHandler (Workspace_CanvasSizeChanged);
58
57
                        CreateToolBox ();
84
83
                        }
85
84
                        
86
85
                        PintaCore.Workspace.Filename = "Untitled1";
 
86
                        PintaCore.History.PushNewItem (new BaseHistoryItem ("gtk-new", "New Image"));
87
87
                        PintaCore.Workspace.IsDirty = false;
88
 
                        
89
88
                        PintaCore.Workspace.Invalidate ();
90
89
 
91
 
                        treeview1.Model = new ListStore (typeof (Pixbuf), typeof (string));
92
 
                        treeview1.HeadersVisible = false;
93
 
                        AddColumns (treeview1);
 
90
                        //History
 
91
                        history_treeview.Model = PintaCore.History.ListStore;
 
92
                        history_treeview.HeadersVisible = false;
 
93
                        history_treeview.Selection.Mode = SelectionMode.Single;
 
94
                        history_treeview.Selection.SelectFunction = HistoryItemSelected;
 
95
                        
 
96
                        Gtk.TreeViewColumn icon_column = new Gtk.TreeViewColumn ();
 
97
                        Gtk.CellRendererPixbuf icon_cell = new Gtk.CellRendererPixbuf ();
 
98
                        icon_column.PackStart (icon_cell, true);
 
99
         
 
100
                        Gtk.TreeViewColumn text_column = new Gtk.TreeViewColumn ();
 
101
                        Gtk.CellRendererText text_cell = new Gtk.CellRendererText ();
 
102
                        text_column.PackStart (text_cell, true);
 
103
                
 
104
                        text_column.SetCellDataFunc (text_cell, new Gtk.TreeCellDataFunc (HistoryRenderText));
 
105
                        icon_column.SetCellDataFunc (icon_cell, new Gtk.TreeCellDataFunc (HistoryRenderIcon));
 
106
                        
 
107
                        history_treeview.AppendColumn (icon_column);
 
108
                        history_treeview.AppendColumn (text_column);
 
109
                        
 
110
                        PintaCore.History.HistoryItemAdded += new EventHandler<HistoryItemAddedEventArgs> (OnHistoryItemsChanged);
 
111
                        PintaCore.History.ActionUndone += new EventHandler (OnHistoryItemsChanged);
 
112
                        PintaCore.History.ActionRedone += new EventHandler (OnHistoryItemsChanged);
94
113
 
95
114
                        PintaCore.Actions.View.ZoomToWindow.Activated += new EventHandler (ZoomToWindow_Activated);
96
115
                        DeleteEvent += new DeleteEventHandler (MainWindow_DeleteEvent);
97
116
 
98
 
                        EffectsAction.Visible = false;
99
117
                        WindowAction.Visible = false;
 
118
 
 
119
                        if (Platform.GetOS () == Platform.OS.Mac)
 
120
                        {
 
121
                                try {
 
122
                                        //enable the global key handler for keyboard shortcuts
 
123
                                        IgeMacMenu.GlobalKeyHandlerEnabled = true;
 
124
                                        
 
125
                                        //Tell the IGE library to use your GTK menu as the Mac main menu
 
126
                                        IgeMacMenu.MenuBar = menubar1;
 
127
                                        /*
 
128
                                        //tell IGE which menu item should be used for the app menu's quit item
 
129
                                        IgeMacMenu.QuitMenuItem = yourQuitMenuItem;
 
130
                                        */
 
131
                                        //add a new group to the app menu, and add some items to it
 
132
                                        var appGroup = IgeMacMenu.AddAppMenuGroup();
 
133
                                        MenuItem aboutItem = (MenuItem) PintaCore.Actions.Help.About.CreateMenuItem();
 
134
                                        appGroup.AddMenuItem(aboutItem, Mono.Unix.Catalog.GetString ("About"));
 
135
                                        
 
136
                                        menubar1.Hide();
 
137
                                } catch {
 
138
                                        // If things don't work out, just use a normal menu.
 
139
                                }
 
140
                        }
100
141
                }
101
142
 
102
143
                private void MainWindow_DeleteEvent (object o, DeleteEventArgs args)
107
148
                private void Workspace_CanvasSizeChanged (object sender, EventArgs e)
108
149
                {
109
150
                        Requisition req = new Requisition ();
110
 
                        req.Height = (int)PintaCore.Workspace.CanvasSize.Y;
111
 
                        req.Width = (int)PintaCore.Workspace.CanvasSize.X;
 
151
                        req.Height = PintaCore.Workspace.CanvasSize.Y;
 
152
                        req.Width = PintaCore.Workspace.CanvasSize.X;
112
153
                        drawingarea1.Requisition = req;
113
154
 
114
155
                        drawingarea1.QueueResize ();
116
157
 
117
158
                private void ZoomToWindow_Activated (object sender, EventArgs e)
118
159
                {
119
 
                        int image_x = (int)PintaCore.Workspace.ImageSize.X;
120
 
                        int image_y = (int)PintaCore.Workspace.ImageSize.Y;
121
 
 
122
 
                        int window_x = GtkScrolledWindow.Children[0].Allocation.Width;
123
 
                        int window_y = GtkScrolledWindow.Children[0].Allocation.Height;
124
 
                        
125
160
                        // The image is small enough to fit in the window
126
 
                        if (image_x <= window_x && image_y <= window_y) {
 
161
                        if (PintaCore.Workspace.ImageFitsInWindow) {
127
162
                                PintaCore.Actions.View.ActualSize.Activate ();
128
163
                                return;
129
164
                        }
130
165
                        
 
166
                        int image_x = PintaCore.Workspace.ImageSize.X;
 
167
                        int image_y = PintaCore.Workspace.ImageSize.Y;
 
168
 
 
169
                        int window_x = GtkScrolledWindow.Children[0].Allocation.Width;
 
170
                        int window_y = GtkScrolledWindow.Children[0].Allocation.Height;
 
171
                        
131
172
                        // The image is more constrained by width than height
132
173
                        if ((double)image_x / (double)window_x >= (double)image_y / (double)window_y) {
133
174
                                double ratio = (double)(window_x - 20) / (double)image_x;
134
175
                                PintaCore.Workspace.Scale = ratio;
 
176
                                PintaCore.Actions.View.SuspendZoomUpdate ();
 
177
                                (PintaCore.Actions.View.ZoomComboBox.ComboBox as ComboBoxEntry).Entry.Text = string.Format ("{0}%", (int)(PintaCore.Workspace.Scale * 100));
 
178
                                PintaCore.Actions.View.ResumeZoomUpdate ();
135
179
                        } else {
136
180
                                double ratio2 = (double)(window_y - 20) / (double)image_y;
137
181
                                PintaCore.Workspace.Scale = ratio2;
 
182
                                PintaCore.Actions.View.SuspendZoomUpdate ();
 
183
                                (PintaCore.Actions.View.ZoomComboBox.ComboBox as ComboBoxEntry).Entry.Text = string.Format ("{0}%", (int)(PintaCore.Workspace.Scale * 100));
 
184
                                PintaCore.Actions.View.ResumeZoomUpdate ();
138
185
                        }
139
186
                }
140
187
 
146
193
                                drawingarea1.GdkWindow.InvalidateRect (e.Rectangle, false);
147
194
                }
148
195
 
149
 
                void History_HistoryItemAdded (object sender, HistoryItemAddedEventArgs e)
150
 
                {
151
 
                        (treeview1.Model as Gtk.ListStore).AppendValues (PintaCore.Resources.GetIcon (e.Item.Icon), e.Item.Text);
152
 
                }
153
 
 
154
196
                private void Chrome_StatusBarTextChanged (object sender, TextChangedEventArgs e)
155
197
                {
156
198
                        label5.Text = e.Text;
157
199
                }
158
 
 
159
 
                void AddColumns (TreeView treeView)
160
 
                {
161
 
                        CellRendererPixbuf pix = new CellRendererPixbuf ();
162
 
                        TreeViewColumn col1 = new TreeViewColumn (string.Empty, pix, "pixbuf", 0);
163
 
                        treeView.AppendColumn (col1);
164
 
 
165
 
                        CellRendererText rendererText = new CellRendererText ();
166
 
                        TreeViewColumn column = new TreeViewColumn (string.Empty, rendererText, "text", 1);
167
 
                        treeView.AppendColumn (column);
168
 
                }
169
 
 
 
200
                
 
201
                #region History
 
202
                public bool HistoryItemSelected (TreeSelection selection, TreeModel model, TreePath path, bool path_currently_selected)
 
203
                {
 
204
                        int current = path.Indices[0];
 
205
                        if (!path_currently_selected) {
 
206
                                while (PintaCore.History.Pointer < current) {
 
207
                                        PintaCore.History.Redo ();
 
208
                                }
 
209
                                while (PintaCore.History.Pointer > current) {
 
210
                                        PintaCore.History.Undo ();
 
211
                                }
 
212
                        }
 
213
                        return true;
 
214
                }
 
215
                
 
216
                private void HistoryRenderText (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
 
217
                {
 
218
                        BaseHistoryItem item = (BaseHistoryItem) model.GetValue (iter, 0);
 
219
                        if (item.State == HistoryItemState.Undo) {
 
220
                                (cell as Gtk.CellRendererText).Style = Pango.Style.Normal;
 
221
                                (cell as Gtk.CellRendererText).Foreground = "black";
 
222
                                (cell as Gtk.CellRendererText).Text = item.Text;                
 
223
                        } else if (item.State == HistoryItemState.Redo) {
 
224
                                (cell as Gtk.CellRendererText).Style = Pango.Style.Oblique;
 
225
                                (cell as Gtk.CellRendererText).Foreground = "gray";
 
226
                                (cell as Gtk.CellRendererText).Text = item.Text;
 
227
                        }
 
228
                
 
229
                }
 
230
         
 
231
                private void HistoryRenderIcon (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
 
232
                {
 
233
                        BaseHistoryItem item = (BaseHistoryItem) model.GetValue (iter, 0);
 
234
                        (cell as Gtk.CellRendererPixbuf).Pixbuf = PintaCore.Resources.GetIcon (item.Icon);
 
235
                }
 
236
                
 
237
                private void OnHistoryItemsChanged (object o, EventArgs args) {
 
238
                        if (PintaCore.History.Current != null) {
 
239
                                history_treeview.Selection.SelectIter (PintaCore.History.Current.Id);
 
240
                                history_treeview.ScrollToCell (history_treeview.Model.GetPath (PintaCore.History.Current.Id), history_treeview.Columns[1], true, (float)0.9, 0);
 
241
                        } 
 
242
                                
 
243
                }
 
244
                #endregion
 
245
                
170
246
                private void CreateToolBox ()
171
247
                {
172
248
                        // Create our tools