~ubuntu-branches/ubuntu/trusty/keepass2/trusty-proposed

« back to all changes in this revision

Viewing changes to KeePass/UI/CustomListViewEx.cs

  • Committer: Package Import Robot
  • Author(s): Julian Taylor
  • Date: 2011-12-30 15:45:59 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20111230154559-3en1b9v90hswvs1w
Tags: 2.18+dfsg-1
* New upstream release
  - refresh patches
  - drop upstream applied patches:
    explicitly-PUT-for-webdav-writes.patch
    prefer-4.0-framework-if-available.patch
* add patch to improve autotype when dealing with multiple keyboard layouts
  - Thanks to amiryal for the patch
* disable initial autoupdate popup via patch
* update years in debian/copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
  KeePass Password Safe - The Open-Source Password Manager
3
 
  Copyright (C) 2003-2011 Dominik Reichl <dominik.reichl@t-online.de>
 
3
  Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
4
4
 
5
5
  This program is free software; you can redistribute it and/or modify
6
6
  it under the terms of the GNU General Public License as published by
21
21
using System.Collections.Generic;
22
22
using System.Text;
23
23
using System.Windows.Forms;
 
24
using System.Threading;
24
25
using System.Diagnostics;
25
26
 
26
27
using KeePass.Native;
 
28
using KeePass.Util;
27
29
 
28
30
namespace KeePass.UI
29
31
{
57
59
 
58
60
                        base.OnMouseHover(e);
59
61
                } */
 
62
 
 
63
                /* protected override void OnKeyUp(KeyEventArgs e)
 
64
                {
 
65
                        base.OnKeyUp(e);
 
66
                        UnfocusGroupInSingleMode();
 
67
                }
 
68
                private void UnfocusGroupInSingleMode()
 
69
                {
 
70
                        try
 
71
                        {
 
72
                                if(!WinUtil.IsAtLeastWindowsVista) return;
 
73
                                if(KeePassLib.Native.NativeLib.IsUnix()) return;
 
74
                                if(!this.ShowGroups) return;
 
75
                                if(this.MultiSelect) return;
 
76
 
 
77
                                const uint m = (NativeMethods.LVGS_FOCUSED | NativeMethods.LVGS_SELECTED);
 
78
 
 
79
                                uint uGroups = (uint)this.Groups.Count;
 
80
                                for(uint u = 0; u < uGroups; ++u)
 
81
                                {
 
82
                                        int iGroupID;
 
83
                                        if(NativeMethods.GetGroupStateByIndex(this, u, m,
 
84
                                                out iGroupID) == m)
 
85
                                        {
 
86
                                                NativeMethods.SetGroupState(this, iGroupID, m,
 
87
                                                        NativeMethods.LVGS_SELECTED);
 
88
                                                return;
 
89
                                        }
 
90
                                }
 
91
                        }
 
92
                        catch(Exception) { Debug.Assert(false); }
 
93
                } */
 
94
 
 
95
                protected override void OnKeyDown(KeyEventArgs e)
 
96
                {
 
97
                        try { if(SkipGroupHeaderIfRequired(e)) return; }
 
98
                        catch(Exception) { Debug.Assert(false); }
 
99
 
 
100
                        base.OnKeyDown(e);
 
101
                }
 
102
 
 
103
                private bool SkipGroupHeaderIfRequired(KeyEventArgs e)
 
104
                {
 
105
                        if(!this.ShowGroups) return false;
 
106
                        if(this.MultiSelect) return false;
 
107
 
 
108
                        ListViewItem lvi = this.FocusedItem;
 
109
                        if(lvi != null)
 
110
                        {
 
111
                                ListViewGroup g = lvi.Group;
 
112
                                ListViewItem lviChangeTo = null;
 
113
 
 
114
                                if((e.KeyCode == Keys.Up) && IsFirstLastItemInGroup(g, lvi, true))
 
115
                                        lviChangeTo = (GetNextLvi(g, true) ?? lvi); // '??' for top item
 
116
                                else if((e.KeyCode == Keys.Down) && IsFirstLastItemInGroup(g, lvi, false))
 
117
                                        lviChangeTo = (GetNextLvi(g, false) ?? lvi); // '??' for bottom item
 
118
 
 
119
                                if(lviChangeTo != null)
 
120
                                {
 
121
                                        foreach(ListViewItem lviEnum in this.Items)
 
122
                                                lviEnum.Selected = false;
 
123
 
 
124
                                        lviChangeTo.Selected = true;
 
125
                                        lviChangeTo.Focused = true;
 
126
                                        EnsureVisible(lviChangeTo.Index);
 
127
 
 
128
                                        e.Handled = true;
 
129
                                        return true;
 
130
                                }
 
131
                        }
 
132
 
 
133
                        return false;
 
134
                }
 
135
 
 
136
                private static bool IsFirstLastItemInGroup(ListViewGroup g,
 
137
                        ListViewItem lvi, bool bFirst)
 
138
                {
 
139
                        if(g == null) { Debug.Assert(false); return false; }
 
140
 
 
141
                        ListViewItemCollection c = g.Items;
 
142
                        if(c.Count == 0) { Debug.Assert(false); return false; }
 
143
 
 
144
                        return (bFirst ? (c[0] == lvi) : (c[c.Count - 1] == lvi));
 
145
                }
 
146
 
 
147
                private ListViewItem GetNextLvi(ListViewGroup gBaseExcl, bool bUp)
 
148
                {
 
149
                        if(gBaseExcl == null) { Debug.Assert(false); return null; }
 
150
 
 
151
                        int i = this.Groups.IndexOf(gBaseExcl);
 
152
                        if(i < 0) { Debug.Assert(false); return null; }
 
153
 
 
154
                        if(bUp)
 
155
                        {
 
156
                                --i;
 
157
                                while(i >= 0)
 
158
                                {
 
159
                                        ListViewGroup g = this.Groups[i];
 
160
                                        if(g.Items.Count > 0) return g.Items[g.Items.Count - 1];
 
161
 
 
162
                                        --i;
 
163
                                }
 
164
                        }
 
165
                        else // Down
 
166
                        {
 
167
                                ++i;
 
168
                                int nGroups = this.Groups.Count;
 
169
                                while(i < nGroups)
 
170
                                {
 
171
                                        ListViewGroup g = this.Groups[i];
 
172
                                        if(g.Items.Count > 0) return g.Items[0];
 
173
 
 
174
                                        ++i;
 
175
                                }
 
176
                        }
 
177
 
 
178
                        return null;
 
179
                }
60
180
        }
61
181
}