Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsDialogParamBlock.h"
7 #include "nsString.h"
8 #include "nsReadableUtils.h"
10 NS_IMPL_ISUPPORTS(nsDialogParamBlock, nsIDialogParamBlock)
12 nsDialogParamBlock::nsDialogParamBlock() : mNumStrings(0), mString(nullptr)
13 {
14 for(int32_t i = 0; i < kNumInts; i++)
15 mInt[i] = 0;
16 }
18 nsDialogParamBlock::~nsDialogParamBlock()
19 {
20 delete [] mString;
21 }
23 NS_IMETHODIMP nsDialogParamBlock::SetNumberStrings(int32_t inNumStrings)
24 {
25 if (mString != nullptr)
26 return NS_ERROR_ALREADY_INITIALIZED;
28 mString = new nsString[inNumStrings];
29 if (!mString)
30 return NS_ERROR_OUT_OF_MEMORY;
31 mNumStrings = inNumStrings;
32 return NS_OK;
33 }
36 NS_IMETHODIMP nsDialogParamBlock::GetInt(int32_t inIndex, int32_t *_retval)
37 {
38 nsresult rv = InBounds(inIndex, kNumInts);
39 if (rv == NS_OK)
40 *_retval = mInt[inIndex];
41 return rv;
42 }
44 NS_IMETHODIMP nsDialogParamBlock::SetInt(int32_t inIndex, int32_t inInt)
45 {
46 nsresult rv = InBounds(inIndex, kNumInts);
47 if (rv == NS_OK)
48 mInt[inIndex]= inInt;
49 return rv;
50 }
53 NS_IMETHODIMP nsDialogParamBlock::GetString(int32_t inIndex, char16_t **_retval)
54 {
55 if (mNumStrings == 0)
56 SetNumberStrings(kNumStrings);
57 nsresult rv = InBounds(inIndex, mNumStrings);
58 if (rv == NS_OK)
59 *_retval = ToNewUnicode(mString[inIndex]);
60 return rv;
61 }
63 NS_IMETHODIMP nsDialogParamBlock::SetString(int32_t inIndex, const char16_t *inString)
64 {
65 if (mNumStrings == 0)
66 SetNumberStrings(kNumStrings);
67 nsresult rv = InBounds(inIndex, mNumStrings);
68 if (rv == NS_OK)
69 mString[inIndex]= inString;
70 return rv;
71 }
73 NS_IMETHODIMP
74 nsDialogParamBlock::GetObjects(nsIMutableArray * *aObjects)
75 {
76 NS_ENSURE_ARG_POINTER(aObjects);
77 NS_IF_ADDREF(*aObjects = mObjects);
78 return NS_OK;
79 }
81 NS_IMETHODIMP
82 nsDialogParamBlock::SetObjects(nsIMutableArray * aObjects)
83 {
84 mObjects = aObjects;
85 return NS_OK;
86 }