~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/core/Mono.Texteditor/Mono.TextEditor.PopupWindow/ListWidget.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
                Pango.Layout layout;
42
42
                ListWindow<T> win;
43
43
                int selection = 0;
44
 
                int page = 0;
45
44
                int visibleRows = -1;
46
45
                int rowHeight;
47
46
                bool buttonPressed;
73
72
                        else
74
73
                                selection = 0;
75
74
 
76
 
                        page = 0;
77
75
                        disableSelection = false;
78
76
                        if (IsRealized) {
79
77
                                UpdateStyle ();
80
78
                                QueueDraw ();
81
79
                        }
82
80
                        OnSelectionChanged (EventArgs.Empty);
 
81
                        SetAdjustments (Allocation);
83
82
                }
84
83
                
85
84
                public int Selection
110
109
                
111
110
                void UpdatePage ()
112
111
                {
113
 
                        if (!IsRealized) {
114
 
                                page = 0;
 
112
                        var area = GetRowArea (selection);
 
113
                        if (area.Y < vadj.Value) {
 
114
                                vadj.Value = area.Y;
115
115
                                return;
116
116
                        }
117
 
                        
118
 
                        if (selection < page || selection >= page + VisibleRows) {
119
 
                                page = selection - (VisibleRows / 2);
120
 
                                if (page < 0) page = 0;
 
117
                        if (vadj.Value + Allocation.Height < area.Bottom) {
 
118
                                vadj.Value = System.Math.Max (0, area.Bottom - vadj.PageSize + 1);
121
119
                        }
122
120
                }
123
121
                
131
129
                        }
132
130
                }
133
131
                
134
 
                public int Page
135
 
                {
136
 
                        get { 
137
 
                                return page; 
138
 
                        }
139
 
                        
140
 
                        set {
141
 
                                page = value;
142
 
                                this.QueueDraw ();
143
 
                        }
144
 
                }
145
 
                
 
132
 
146
133
                protected override bool OnButtonPressEvent (EventButton e)
147
134
                {
148
 
                        Selection = GetRowByPosition ((int) e.Y);
 
135
                        Selection = GetRowByPosition ((int) (vadj.Value + e.Y));
149
136
                        buttonPressed = true;
150
137
                        return base.OnButtonPressEvent (e);
151
138
                }
170
157
                        else if (ypos >= winHeight) {
171
158
                        }
172
159
                        else
173
 
        */                      Selection = GetRowByPosition ((int) e.Y);
 
160
        */                      Selection = GetRowByPosition ((int) (vadj.Value + e.Y));
174
161
                        
175
162
                        return true;
176
163
                }
177
164
 
 
165
                Adjustment hadj;
 
166
                Adjustment vadj;
 
167
 
 
168
                protected override void OnSetScrollAdjustments (Adjustment hadj, Adjustment vadj)
 
169
                {
 
170
                        this.hadj = hadj;
 
171
                        this.vadj = vadj;
 
172
                        if (this.vadj != null)
 
173
                                this.vadj.ValueChanged += (sender, e) => QueueDraw ();
 
174
                        base.OnSetScrollAdjustments (hadj, vadj);
 
175
                }
 
176
 
 
177
                void SetAdjustments (Gdk.Rectangle allocation)
 
178
                {
 
179
                        hadj.SetBounds (0, allocation.Width, 0, 0, allocation.Width);
 
180
                        var height = System.Math.Max (allocation.Height, rowHeight * this.win.DataProvider.Count);
 
181
                        vadj.SetBounds (0, height, rowHeight, allocation.Height, allocation.Height);
 
182
                }
 
183
 
 
184
                protected override void OnSizeAllocated (Gdk.Rectangle allocation)
 
185
                {
 
186
                        SetAdjustments (allocation);
 
187
 
 
188
                        base.OnSizeAllocated (allocation);
 
189
                }
 
190
 
178
191
                protected override bool OnExposeEvent (Gdk.EventExpose args)
179
192
                {
180
193
                        base.OnExposeEvent (args);
209
222
                        var fgGCNormal = this.Style.ForegroundGC (StateType.Normal);
210
223
                                
211
224
                        int n = 0;
212
 
                        while (ypos < winHeight - margin && (page + n) < win.DataProvider.Count)
 
225
                        n = (int)(vadj.Value / rowHeight);
 
226
 
 
227
                        while (ypos < winHeight - margin && n < win.DataProvider.Count)
213
228
                        {
214
229
                                bool hasMarkup = false;
215
230
                                IMarkupListDataProvider<T> markupListDataProvider = win.DataProvider as IMarkupListDataProvider<T>;
216
231
                                if (markupListDataProvider != null) {
217
 
                                        if (markupListDataProvider.HasMarkup (page + n)) {
218
 
                                                layout.SetMarkup (markupListDataProvider.GetMarkup (page + n) ?? "&lt;null&gt;");
 
232
                                        if (markupListDataProvider.HasMarkup (n)) {
 
233
                                                layout.SetMarkup (markupListDataProvider.GetMarkup (n) ?? "&lt;null&gt;");
219
234
                                                hasMarkup = true;
220
235
                                        }
221
236
                                }
222
237
                                
223
238
                                if (!hasMarkup)
224
 
                                        layout.SetText (win.DataProvider.GetText (page + n) ?? "<null>");
 
239
                                        layout.SetText (win.DataProvider.GetText (n) ?? "<null>");
225
240
                                
226
 
                                Gdk.Pixbuf icon = win.DataProvider.GetIcon (page + n);
 
241
                                Gdk.Pixbuf icon = win.DataProvider.GetIcon (n);
227
242
                                int iconHeight, iconWidth;
228
243
                                
229
244
                                if (icon != null) {
238
253
                                typos = he < rowHeight ? ypos + (rowHeight - he) / 2 : ypos;
239
254
                                iypos = iconHeight < rowHeight ? ypos + (rowHeight - iconHeight) / 2 : ypos;
240
255
                                
241
 
                                if (page + n == selection) {
 
256
                                if (n == selection) {
242
257
                                        if (!disableSelection) {
243
258
                                                args.Window.DrawRectangle (this.Style.BaseGC (StateType.Selected),
244
259
                                                                              true, margin, ypos, lineWidth, he + padding);
268
283
                
269
284
                int GetRowByPosition (int ypos)
270
285
                {
271
 
                        if (visibleRows == -1) CalcVisibleRows ();
272
 
                        return page + (ypos-margin) / rowHeight;
 
286
                        return ypos / rowHeight;
273
287
                }
274
288
                
275
289
                public Gdk.Rectangle GetRowArea (int row)
276
290
                {
277
 
                        row -= page;
278
 
                        int winWidth, winHeight;
279
 
                        this.GdkWindow.GetSize (out winWidth, out winHeight);
280
 
                        
281
 
                        return new Gdk.Rectangle (margin, margin + rowHeight * row, winWidth, rowHeight);
 
291
                        return new Gdk.Rectangle (0, row * rowHeight, Allocation.Width, rowHeight);
282
292
                }
283
 
                
 
293
 
284
294
                public int VisibleRows
285
295
                {
286
296
                        get {
291
301
                
292
302
                void CalcVisibleRows ()
293
303
                {
294
 
                        int winHeight = 200;
 
304
                        //int winHeight = 200;
295
305
                        int lvWidth, lvHeight;
296
306
                        int rowWidth;
297
307
                        
299
309
 
300
310
                        layout.GetPixelSize (out rowWidth, out rowHeight);
301
311
                        rowHeight += padding;
302
 
                        visibleRows = (winHeight + padding - margin * 2) / rowHeight;
 
312
                        visibleRows = 7;//(winHeight + padding - margin * 2) / rowHeight;
303
313
                        
304
314
                        int newHeight;
305
315