~ubuntu-branches/ubuntu/precise/thunderbird/precise

« back to all changes in this revision

Viewing changes to debian/globalmenu/src/uGlobalMenuItem.h

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2012-04-02 17:52:31 UTC
  • mfrom: (1.6.40)
  • Revision ID: package-import@ubuntu.com-20120402175231-tp40e2tjs63jy0ze
Tags: 11.0.1+build1-0ubuntu1
* New upstream stable release (THUNDERBIRD_11_0_1_BUILD1)
  - Fixes LP: #962631, LP: #971578

* Update globalmenu-extension to 3.1
  - Reduce our memory footprint a bit, which wasn't really a lot anyway
  - Avoid the use of the component manager for accessing commonly used
    services, where "commonly used" means "accessed when building every
    menu item". This should save some CPU cycles when building or
    refreshing menus
  - Try to recycle menuitems when they are removed from a menu by
    adding contiguous blocks of removed items to a "free list" which
    is emptied asynchronously, and reusing the items in this list when
    new items are added in place of the removed items. This means that
    menus which fully refresh on opening no longer alter the menu
    structure, but instead just update properties on existing nodes.
    This has a few benefits:
    + With no layout changes, unity-panel-service doesn't request
      the entire menu structure, which significantly reduces dbus traffic
      and makes it much faster to refresh the menu contents
    + The size of the menu doesn't change when it is refreshed, which
      eliminates the flicker that used to occur when opening some menus
    + The HUD can refresh our menus now without triggering layout updates
      (assuming that menu layout really hasn't changed)
  - Remove all use of the global observer service for sending our own
    internal notifications around
  - Get rid of a static initializer
  - Don't support older than Thunderbird 11
  - Fix some GError leaks
  - Hide the internal menu when creating a native menu, rather than
    waiting for confirmation that the native menu is registered
    successfully. We don't try to create a native menu if we don't
    find a menu service to register the menu with anyway
  - Keep menu contents updated whilst the menu is open, rather than
    just whilst it is opening

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
2
/* ***** BEGIN LICENSE BLOCK *****
 
3
 *       Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
4
 *
 
5
 * The contents of this file are subject to the Mozilla Public License Version
 
6
 * 1.1 (the "License"); you may not use this file except in compliance with
 
7
 * the License. You may obtain a copy of the License at
 
8
 * http://www.mozilla.org/MPL/
 
9
 * 
 
10
 * Software distributed under the License is distributed on an "AS IS" basis,
 
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
12
 * for the specific language governing rights and limitations under the
 
13
 * License.
 
14
 *
 
15
 * The Original Code is globalmenu-extension.
 
16
 *
 
17
 * The Initial Developer of the Original Code is
 
18
 * Canonical Ltd.
 
19
 * Portions created by the Initial Developer are Copyright (C) 2010
 
20
 * the Initial Developer. All Rights Reserved.
 
21
 *
 
22
 * Contributor(s):
 
23
 * Chris Coulson <chris.coulson@canonical.com>
 
24
 *
 
25
 * Alternatively, the contents of this file may be used under the terms of
 
26
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
27
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
28
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
29
 * of those above. If you wish to allow use of your version of this file only
 
30
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
31
 * use your version of this file under the terms of the MPL, indicate your
 
32
 * decision by deleting the provisions above and replace them with the notice
 
33
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
34
 * the provisions above, a recipient may use your version of this file under
 
35
 * the terms of any one of the MPL, the GPL or the LGPL.
 
36
 * 
 
37
 * ***** END LICENSE BLOCK ***** */
 
38
 
 
39
#ifndef _U_GLOBALMENUITEM_H
 
40
#define _U_GLOBALMENUITEM_H
 
41
 
 
42
#include <prtypes.h>
 
43
#include <nsCOMPtr.h>
 
44
#include <nsStringAPI.h>
 
45
 
 
46
#include <libdbusmenu-glib/server.h>
 
47
 
 
48
#include "uGlobalMenuObject.h"
 
49
#include "uMenuChangeObserver.h"
 
50
 
 
51
class nsIContent;
 
52
class uGlobalMenuDocListener;
 
53
class uGlobalMenuBar;
 
54
 
 
55
enum uMenuItemType {
 
56
  eNormal,
 
57
  eCheckBox,
 
58
  eRadio
 
59
};
 
60
 
 
61
class uGlobalMenuItem: public uGlobalMenuObject,
 
62
                       public uMenuChangeObserver
 
63
{
 
64
public:
 
65
  NS_DECL_UMENUCHANGEOBSERVER
 
66
 
 
67
  static uGlobalMenuObject* Create(uGlobalMenuObject *aParent,
 
68
                                   uGlobalMenuDocListener *aListener,
 
69
                                   nsIContent *aContent,
 
70
                                   uGlobalMenuBar *aMenuBar);
 
71
 
 
72
  void AboutToShowNotify();
 
73
 
 
74
private:
 
75
  uGlobalMenuItem();
 
76
 
 
77
  nsresult Init(uGlobalMenuObject *aParent,
 
78
                uGlobalMenuDocListener *aListener,
 
79
                nsIContent *aContent,
 
80
                uGlobalMenuBar *aMenuBar);
 
81
  ~uGlobalMenuItem();
 
82
 
 
83
  PRUint32 GetKeyCode(nsAString &aKeyName);
 
84
  PRUint32 MozKeyCodeToGdkKeyCode(PRUint32 aMozKeyCode);
 
85
  void SyncAccelFromContent();
 
86
  void SyncProperties();
 
87
  void SyncTypeAndStateFromContent();
 
88
  void InitializeDbusMenuItem();
 
89
  static void ItemActivatedCallback(DbusmenuMenuitem *menuItem,
 
90
                                    PRUint32 timeStamp,
 
91
                                    void *data);
 
92
  void Activate();
 
93
  void UncheckSiblings();
 
94
  void SetMenuItemType(uMenuItemType aType)
 
95
  {
 
96
    switch(aType) {
 
97
      case eNormal:
 
98
        ClearFlags(UNITY_MENUITEM_IS_CHECKBOX | UNITY_MENUITEM_IS_RADIO);
 
99
        break;
 
100
 
 
101
      case eCheckBox:
 
102
        ClearFlags(UNITY_MENUITEM_IS_RADIO);
 
103
        SetFlags(UNITY_MENUITEM_IS_CHECKBOX);
 
104
        break;
 
105
 
 
106
      case eRadio:
 
107
        ClearFlags(UNITY_MENUITEM_IS_CHECKBOX);
 
108
        SetFlags(UNITY_MENUITEM_IS_RADIO);
 
109
        break;
 
110
 
 
111
      default:
 
112
        NS_NOTREACHED("Invalid menuitem type");
 
113
    }
 
114
  }
 
115
 
 
116
  bool IsCheckboxOrRadioItem()
 
117
  {
 
118
    return (mFlags & UNITY_MENUITEM_IS_CHECKBOX) ||
 
119
           (mFlags & UNITY_MENUITEM_IS_RADIO);
 
120
  }
 
121
 
 
122
  void SetCheckState(bool aChecked)
 
123
  {
 
124
    NS_ASSERTION(IsCheckboxOrRadioItem(), "Not a checkbox or radio item");
 
125
    SetOrClearFlags(aChecked, UNITY_MENUITEM_TOGGLE_IS_ACTIVE);
 
126
  }
 
127
 
 
128
  bool IsChecked()
 
129
  {
 
130
    NS_ASSERTION(IsCheckboxOrRadioItem(), "Not a checkbox or radio item");
 
131
    return !!(mFlags & UNITY_MENUITEM_TOGGLE_IS_ACTIVE);
 
132
  }
 
133
 
 
134
  nsCOMPtr<nsIContent> mCommandContent;
 
135
  nsCOMPtr<nsIContent> mKeyContent;
 
136
};
 
137
 
 
138
 
 
139
#endif