2001-12-21 04:10:07 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-10-14 14:58:25 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
1999-12-06 02:04:22 +03:00
|
|
|
This file provides the implementation for the XUL "controllers"
|
|
|
|
object.
|
1999-10-14 14:58:25 +04:00
|
|
|
|
1999-12-06 02:04:22 +03:00
|
|
|
*/
|
1999-10-14 14:58:25 +04:00
|
|
|
|
2001-03-30 07:20:56 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
|
1999-10-14 14:58:25 +04:00
|
|
|
#include "nsIControllers.h"
|
1999-12-06 02:04:22 +03:00
|
|
|
#include "nsXULControllers.h"
|
2013-09-23 03:23:30 +04:00
|
|
|
#include "nsIController.h"
|
2018-09-13 18:02:50 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
1999-10-14 14:58:25 +04:00
|
|
|
|
1999-12-06 02:04:22 +03:00
|
|
|
//----------------------------------------------------------------------
|
1999-10-14 14:58:25 +04:00
|
|
|
|
1999-12-06 02:04:22 +03:00
|
|
|
nsXULControllers::nsXULControllers() : mCurControllerID(0) {}
|
1999-10-14 14:58:25 +04:00
|
|
|
|
1999-12-06 02:04:22 +03:00
|
|
|
nsXULControllers::~nsXULControllers(void) { DeleteControllers(); }
|
2001-03-30 07:20:56 +04:00
|
|
|
|
|
|
|
void nsXULControllers::DeleteControllers() {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = mControllers.Length();
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
2009-03-20 11:15:35 +03:00
|
|
|
nsXULControllerData* controllerData = mControllers.ElementAt(i);
|
2011-05-17 18:01:36 +04:00
|
|
|
delete controllerData; // releases the nsIController
|
2001-03-30 07:20:56 +04:00
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2001-03-30 07:20:56 +04:00
|
|
|
mControllers.Clear();
|
1999-10-14 14:58:25 +04:00
|
|
|
}
|
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULControllers)
|
|
|
|
|
2007-03-08 14:17:16 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXULControllers)
|
|
|
|
tmp->DeleteControllers();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULControllers)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i, count = tmp->mControllers.Length();
|
2007-03-08 14:17:16 +03:00
|
|
|
for (i = 0; i < count; ++i) {
|
2009-03-20 11:15:35 +03:00
|
|
|
nsXULControllerData* controllerData = tmp->mControllers[i];
|
2007-03-08 14:17:16 +03:00
|
|
|
if (controllerData) {
|
|
|
|
cb.NoteXPCOMChild(controllerData->mController);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2007-04-25 20:35:27 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXULControllers)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIControllers)
|
2006-02-23 06:17:11 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIControllers)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-03-06 14:11:31 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsXULControllers)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsXULControllers)
|
1999-12-06 02:04:22 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-07-16 02:04:13 +04:00
|
|
|
nsXULControllers::GetControllerForCommand(const char* aCommand,
|
|
|
|
nsIController** _retval) {
|
2001-03-30 07:20:56 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2012-07-30 18:20:58 +04:00
|
|
|
*_retval = nullptr;
|
1999-10-14 14:58:25 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = mControllers.Length();
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
2009-03-20 11:15:35 +03:00
|
|
|
nsXULControllerData* controllerData = mControllers.ElementAt(i);
|
2001-03-30 07:20:56 +04:00
|
|
|
if (controllerData) {
|
2001-12-21 04:10:07 +03:00
|
|
|
nsCOMPtr<nsIController> controller;
|
2001-03-30 07:20:56 +04:00
|
|
|
controllerData->GetController(getter_AddRefs(controller));
|
|
|
|
if (controller) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool supportsCommand;
|
2001-03-30 07:20:56 +04:00
|
|
|
controller->SupportsCommand(aCommand, &supportsCommand);
|
|
|
|
if (supportsCommand) {
|
2015-03-31 17:03:49 +03:00
|
|
|
controller.forget(_retval);
|
2001-12-21 04:10:07 +03:00
|
|
|
return NS_OK;
|
1999-10-14 14:58:25 +04:00
|
|
|
}
|
2001-12-21 04:10:07 +03:00
|
|
|
}
|
1999-10-14 14:58:25 +04:00
|
|
|
}
|
2001-03-30 07:20:56 +04:00
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2001-12-21 04:10:07 +03:00
|
|
|
return NS_OK;
|
1999-12-06 02:04:22 +03:00
|
|
|
}
|
1999-10-14 14:58:25 +04:00
|
|
|
|
1999-12-06 02:04:22 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsXULControllers::InsertControllerAt(uint32_t aIndex,
|
|
|
|
nsIController* controller) {
|
2002-11-20 14:36:05 +03:00
|
|
|
nsXULControllerData* controllerData =
|
|
|
|
new nsXULControllerData(++mCurControllerID, controller);
|
2003-09-27 08:18:26 +04:00
|
|
|
#ifdef DEBUG
|
2009-03-20 11:15:35 +03:00
|
|
|
nsXULControllerData** inserted =
|
2003-09-27 08:18:26 +04:00
|
|
|
#endif
|
2009-03-20 11:15:35 +03:00
|
|
|
mControllers.InsertElementAt(aIndex, controllerData);
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(inserted != nullptr, "Insertion of controller failed");
|
2001-12-21 04:10:07 +03:00
|
|
|
return NS_OK;
|
1999-12-06 02:04:22 +03:00
|
|
|
}
|
1999-10-14 14:58:25 +04:00
|
|
|
|
1999-12-06 02:04:22 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsXULControllers::RemoveControllerAt(uint32_t aIndex, nsIController** _retval) {
|
2001-03-30 07:20:56 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2012-07-30 18:20:58 +04:00
|
|
|
*_retval = nullptr;
|
2001-12-21 04:10:07 +03:00
|
|
|
|
2009-03-20 11:15:35 +03:00
|
|
|
nsXULControllerData* controllerData = mControllers.SafeElementAt(aIndex);
|
2001-03-30 07:20:56 +04:00
|
|
|
if (!controllerData) return NS_ERROR_FAILURE;
|
2003-09-27 08:18:26 +04:00
|
|
|
|
|
|
|
mControllers.RemoveElementAt(aIndex);
|
|
|
|
|
2001-05-03 14:09:59 +04:00
|
|
|
controllerData->GetController(_retval);
|
2001-03-30 07:20:56 +04:00
|
|
|
delete controllerData;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2001-12-21 04:10:07 +03:00
|
|
|
return NS_OK;
|
1999-12-06 02:04:22 +03:00
|
|
|
}
|
1999-10-14 14:58:25 +04:00
|
|
|
|
1999-12-06 02:04:22 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsXULControllers::GetControllerAt(uint32_t aIndex, nsIController** _retval) {
|
2001-03-30 07:20:56 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2012-07-30 18:20:58 +04:00
|
|
|
*_retval = nullptr;
|
2001-03-30 07:20:56 +04:00
|
|
|
|
2009-03-20 11:15:35 +03:00
|
|
|
nsXULControllerData* controllerData = mControllers.SafeElementAt(aIndex);
|
2001-03-30 07:20:56 +04:00
|
|
|
if (!controllerData) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return controllerData->GetController(_retval); // does the addref
|
1999-12-06 02:04:22 +03:00
|
|
|
}
|
1999-10-14 14:58:25 +04:00
|
|
|
|
1999-12-06 02:04:22 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULControllers::AppendController(nsIController* controller) {
|
2002-11-13 02:03:27 +03:00
|
|
|
// This assigns controller IDs starting at 1 so we can use 0 to test if an ID
|
|
|
|
// was obtained
|
|
|
|
nsXULControllerData* controllerData =
|
|
|
|
new nsXULControllerData(++mCurControllerID, controller);
|
2003-09-27 08:18:26 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2009-03-20 11:15:35 +03:00
|
|
|
nsXULControllerData** appended =
|
2003-09-27 08:18:26 +04:00
|
|
|
#endif
|
2009-03-20 11:15:35 +03:00
|
|
|
mControllers.AppendElement(controllerData);
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(appended != nullptr, "Appending controller failed");
|
2001-12-21 04:10:07 +03:00
|
|
|
return NS_OK;
|
1999-12-06 02:04:22 +03:00
|
|
|
}
|
1999-10-14 14:58:25 +04:00
|
|
|
|
1999-12-06 02:04:22 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULControllers::RemoveController(nsIController* controller) {
|
2001-04-05 06:45:17 +04:00
|
|
|
// first get the identity pointer
|
|
|
|
nsCOMPtr<nsISupports> controllerSup(do_QueryInterface(controller));
|
|
|
|
// then find it
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = mControllers.Length();
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
2009-03-20 11:15:35 +03:00
|
|
|
nsXULControllerData* controllerData = mControllers.ElementAt(i);
|
2001-03-30 07:20:56 +04:00
|
|
|
if (controllerData) {
|
|
|
|
nsCOMPtr<nsIController> thisController;
|
|
|
|
controllerData->GetController(getter_AddRefs(thisController));
|
2001-04-05 06:45:17 +04:00
|
|
|
nsCOMPtr<nsISupports> thisControllerSup(
|
|
|
|
do_QueryInterface(thisController)); // get identity
|
|
|
|
if (thisControllerSup == controllerSup) {
|
2001-03-30 07:20:56 +04:00
|
|
|
mControllers.RemoveElementAt(i);
|
|
|
|
delete controllerData;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-10-14 14:58:25 +04:00
|
|
|
}
|
2001-03-30 07:20:56 +04:00
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE; // right thing to return if no controller found?
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2001-03-30 07:20:56 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsXULControllers::GetControllerId(nsIController* controller,
|
|
|
|
uint32_t* _retval) {
|
2001-03-30 07:20:56 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = mControllers.Length();
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
2009-03-20 11:15:35 +03:00
|
|
|
nsXULControllerData* controllerData = mControllers.ElementAt(i);
|
2001-03-30 07:20:56 +04:00
|
|
|
if (controllerData) {
|
|
|
|
nsCOMPtr<nsIController> thisController;
|
|
|
|
controllerData->GetController(getter_AddRefs(thisController));
|
|
|
|
if (thisController.get() == controller) {
|
|
|
|
*_retval = controllerData->GetControllerID();
|
2001-12-21 04:10:07 +03:00
|
|
|
return NS_OK;
|
2001-03-30 07:20:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE; // none found
|
1999-12-06 02:04:22 +03:00
|
|
|
}
|
1999-10-14 14:58:25 +04:00
|
|
|
|
1999-12-06 02:04:22 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsXULControllers::GetControllerById(uint32_t controllerID,
|
|
|
|
nsIController** _retval) {
|
2001-03-30 07:20:56 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = mControllers.Length();
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
2009-03-20 11:15:35 +03:00
|
|
|
nsXULControllerData* controllerData = mControllers.ElementAt(i);
|
2001-03-30 07:20:56 +04:00
|
|
|
if (controllerData && controllerData->GetControllerID() == controllerID) {
|
|
|
|
return controllerData->GetController(_retval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE; // none found
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsXULControllers::GetControllerCount(uint32_t* _retval) {
|
2001-03-30 07:20:56 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2009-03-20 11:15:35 +03:00
|
|
|
*_retval = mControllers.Length();
|
2001-12-21 04:10:07 +03:00
|
|
|
return NS_OK;
|
1999-10-14 14:58:25 +04:00
|
|
|
}
|