|
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/. */ |
|
5 |
|
6 #include "nsDialogParamBlock.h" |
|
7 #include "nsString.h" |
|
8 #include "nsReadableUtils.h" |
|
9 |
|
10 NS_IMPL_ISUPPORTS(nsDialogParamBlock, nsIDialogParamBlock) |
|
11 |
|
12 nsDialogParamBlock::nsDialogParamBlock() : mNumStrings(0), mString(nullptr) |
|
13 { |
|
14 for(int32_t i = 0; i < kNumInts; i++) |
|
15 mInt[i] = 0; |
|
16 } |
|
17 |
|
18 nsDialogParamBlock::~nsDialogParamBlock() |
|
19 { |
|
20 delete [] mString; |
|
21 } |
|
22 |
|
23 NS_IMETHODIMP nsDialogParamBlock::SetNumberStrings(int32_t inNumStrings) |
|
24 { |
|
25 if (mString != nullptr) |
|
26 return NS_ERROR_ALREADY_INITIALIZED; |
|
27 |
|
28 mString = new nsString[inNumStrings]; |
|
29 if (!mString) |
|
30 return NS_ERROR_OUT_OF_MEMORY; |
|
31 mNumStrings = inNumStrings; |
|
32 return NS_OK; |
|
33 } |
|
34 |
|
35 |
|
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 } |
|
43 |
|
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 } |
|
51 |
|
52 |
|
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 } |
|
62 |
|
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 } |
|
72 |
|
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 } |
|
80 |
|
81 NS_IMETHODIMP |
|
82 nsDialogParamBlock::SetObjects(nsIMutableArray * aObjects) |
|
83 { |
|
84 mObjects = aObjects; |
|
85 return NS_OK; |
|
86 } |
|
87 |
|
88 |