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
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/
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
15
* The Original Code is globalmenu-extension.
17
* The Initial Developer of the Original Code is
19
* Portions created by the Initial Developer are Copyright (C) 2010
20
* the Initial Developer. All Rights Reserved.
23
* Chris Coulson <chris.coulson@canonical.com>
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.
37
* ***** END LICENSE BLOCK ***** */
39
#ifndef _U_GLOBALMENU_H
40
#define _U_GLOBALMENU_H
44
#include <nsAutoPtr.h>
46
#include <nsIContent.h>
47
#include <nsThreadUtils.h>
49
#include <libdbusmenu-glib/server.h>
51
#include "uGlobalMenuObject.h"
52
#include "uWidgetAtoms.h"
54
#define UNITY_MENU_POPUP_STATE_0 FLAG(8)
55
#define UNITY_MENU_POPUP_STATE_1 FLAG(9)
56
#define UNITY_MENU_POPUP_STATE_2 FLAG(10)
57
#define UNITY_MENU_POPUP_STATE_MASK (UNITY_MENU_POPUP_STATE_2 | UNITY_MENU_POPUP_STATE_1 | UNITY_MENU_POPUP_STATE_0)
59
// The menu needs rebuilding
60
#define UNITY_MENU_NEEDS_REBUILDING FLAG(11)
62
// The shell sent the first "AboutToOpen" event
63
#define UNITY_MENU_READY FLAG(12)
65
class uGlobalMenuItem;
66
class uGlobalMenuDocListener;
69
enum uMenuPopupState {
72
ePopupOpen1, // Menu was opened with an "about-to-show" signal
73
ePopupOpen2, // Menu was opened with an "opened" event
77
class uGlobalMenu: public uGlobalMenuObject
80
static uGlobalMenuObject* Create(uGlobalMenuObject *aParent,
81
uGlobalMenuDocListener *aListener,
82
nsIContent *aContent);
83
virtual void Destroy();
84
virtual ~uGlobalMenu();
86
virtual uMenuObjectType GetType() { return eMenu; }
89
void OpenMenuDelayed();
92
virtual void ObserveAttributeChanged(nsIContent *aContent,
94
virtual void ObserveContentRemoved(nsIContent *aContainer,
96
virtual void ObserveContentInserted(nsIContent *aContainer,
98
nsIContent *aPrevSibling);
103
// Initialize the menu structure
104
nsresult Init(uGlobalMenuObject *aParent,
105
uGlobalMenuDocListener *aListener,
106
nsIContent *aContent);
108
uint32_t IndexOf(nsIContent *aContent);
109
bool InsertMenuObjectAfterContent(uGlobalMenuObject *menuObj,
110
nsIContent *aPrevSibling);
111
bool AppendMenuObject(uGlobalMenuObject *menuObj);
112
bool RemoveMenuObjectAt(uint32_t index, bool recycle);
113
bool RemoveMenuObjectForContent(nsIContent *aContent, bool recycle);
114
virtual void InitializeDbusMenuItem();
115
virtual void Refresh(uMenuObjectRefreshMode aMode);
116
virtual uMenuObjectProperties GetValidProperties()
118
return static_cast<uMenuObjectProperties>(eLabel | eEnabled | eVisible |
119
eIconData | eChildDisplay);
122
void InitializePopup();
123
static bool MenuAboutToOpenCallback(DbusmenuMenuitem *menu,
125
static bool MenuEventCallback(DbusmenuMenuitem *menu,
130
static void DoOpen(nsITimer *aTimer, void *aClosure);
131
void AboutToOpen(bool aOpenedEvent, bool aWantPopupShownEvent = true);
132
void FirePopupShownEvent();
134
void FirePopupHidingEvent();
135
void SetNeedsRebuild() { mFlags = mFlags | UNITY_MENU_NEEDS_REBUILDING; }
136
void ClearNeedsRebuild() { mFlags = mFlags & ~UNITY_MENU_NEEDS_REBUILDING; }
137
bool DoesNeedRebuild() { return !!(mFlags & UNITY_MENU_NEEDS_REBUILDING); }
138
void FlushRecycleList() { mRecycleList = nullptr; }
139
uMenuPopupState GetPopupState()
141
return static_cast<uMenuPopupState>((mFlags & UNITY_MENU_POPUP_STATE_MASK) >> 8);
143
void SetPopupState(uMenuPopupState aState);
148
RecycleList(uGlobalMenu *aMenu);
151
DbusmenuMenuitem* RecycleForAppend(uGlobalMenuObject *aMenuObj);
152
DbusmenuMenuitem* RecycleForInsert(uGlobalMenuObject *aMenuObj,
154
uint32_t *aCorrectedIndex);
155
void TakeItem(DbusmenuMenuitem *aMenuObj, uint32_t aIndex);
159
DbusmenuMenuitem* Shift(uGlobalMenuObject *aMenuObj = nullptr);
162
nsTArray<DbusmenuMenuitem *> mList;
164
nsRefPtr<nsRunnableMethod<uGlobalMenu, void, false> > mFreeEvent;
167
nsCOMPtr<nsIContent> mPopupContent;
168
nsTArray< nsRefPtr<uGlobalMenuObject> > mMenuObjects;
169
nsAutoPtr<RecycleList> mRecycleList;