1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1999
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
51 #include "morkHandle.h"
55 #include "morkThumb.h"
63 #include "orkinThumb.h"
66 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
69 orkinThumb:: ~orkinThumb() // morkHandle destructor does everything
73 /*protected non-poly construction*/
74 orkinThumb::orkinThumb(morkEnv
* ev
, // morkUsage is morkUsage_kPool
75 morkHandleFace
* ioFace
, // must not be nil, cookie for this handle
76 morkThumb
* ioObject
) // must not be nil, the object for this handle
77 : morkHandle(ev
, ioFace
, ioObject
, morkMagic_kThumb
)
79 // do not modify mNode_Derived; leave it equal to morkDerived_kHandle
83 /*static */ orkinThumb
*
84 orkinThumb::MakeThumb(morkEnv
* ev
, morkThumb
* ioObject
)
86 mork_bool isEnv
= ev
->IsEnv();
90 morkHandleFace
* face
= ev
->NewHandle(sizeof(orkinThumb
));
92 return new(face
) orkinThumb(ev
, face
, ioObject
);
94 ev
->OutOfMemoryError();
97 return (orkinThumb
*) 0;
101 orkinThumb::CanUseThumb(nsIMdbEnv
* mev
,
102 mork_bool inMutable
, mdb_err
* outErr
) const
105 morkEnv
* ev
= morkEnv::FromMdbEnv(mev
);
108 morkThumb
* self
= (morkThumb
*)
109 this->GetGoodHandleObject(ev
, inMutable
, morkMagic_kThumb
,
110 /*inClosedOkay*/ morkBool_kFalse
);
113 if ( self
->IsThumb() )
116 self
->NonThumbTypeError(ev
);
118 *outErr
= ev
->AsErr();
125 // { ===== begin nsIMdbISupports methods =====
126 NS_IMPL_QUERY_INTERFACE1(orkinThumb
, nsIMdbThumb
)
129 orkinThumb::AddRef() // add strong ref with no
131 morkEnv
* ev
= mHandle_Env
;
132 if ( ev
&& ev
->IsEnv() )
133 return this->Handle_AddStrongRef(ev
->AsMdbEnv());
135 return morkEnv_kNonEnvTypeError
;
139 orkinThumb::Release() // cut strong ref
141 morkEnv
* ev
= mHandle_Env
;
142 if ( ev
&& ev
->IsEnv() )
143 return this->Handle_CutStrongRef(ev
->AsMdbEnv());
145 return morkEnv_kNonEnvTypeError
;
147 // } ===== end nsIMdbObject methods =====
150 // { ===== begin nsIMdbObject methods =====
152 // { ----- begin attribute methods -----
154 orkinThumb::IsFrozenMdbObject(nsIMdbEnv
* mev
, mdb_bool
* outIsReadonly
)
156 return this->Handle_IsFrozenMdbObject(mev
, outIsReadonly
);
158 // same as nsIMdbPort::GetIsPortReadonly() when this object is inside a port.
159 // } ----- end attribute methods -----
161 // { ----- begin factory methods -----
163 orkinThumb::GetMdbFactory(nsIMdbEnv
* mev
, nsIMdbFactory
** acqFactory
)
165 return this->Handle_GetMdbFactory(mev
, acqFactory
);
167 // } ----- end factory methods -----
169 // { ----- begin ref counting for well-behaved cyclic graphs -----
171 orkinThumb::GetWeakRefCount(nsIMdbEnv
* mev
, // weak refs
174 return this->Handle_GetWeakRefCount(mev
, outCount
);
177 orkinThumb::GetStrongRefCount(nsIMdbEnv
* mev
, // strong refs
180 return this->Handle_GetStrongRefCount(mev
, outCount
);
184 orkinThumb::AddWeakRef(nsIMdbEnv
* mev
)
186 return this->Handle_AddWeakRef(mev
);
189 orkinThumb::AddStrongRef(nsIMdbEnv
* mev
)
191 return this->Handle_AddStrongRef(mev
);
195 orkinThumb::CutWeakRef(nsIMdbEnv
* mev
)
197 return this->Handle_CutWeakRef(mev
);
200 orkinThumb::CutStrongRef(nsIMdbEnv
* mev
)
202 return this->Handle_CutStrongRef(mev
);
206 orkinThumb::CloseMdbObject(nsIMdbEnv
* mev
)
208 return this->Handle_CloseMdbObject(mev
);
212 orkinThumb::IsOpenMdbObject(nsIMdbEnv
* mev
, mdb_bool
* outOpen
)
214 return this->Handle_IsOpenMdbObject(mev
, outOpen
);
216 // } ----- end ref counting -----
218 // } ===== end nsIMdbObject methods =====
221 // { ===== begin nsIMdbThumb methods =====
223 orkinThumb::GetProgress(nsIMdbEnv
* mev
, mdb_count
* outTotal
,
224 mdb_count
* outCurrent
, mdb_bool
* outDone
, mdb_bool
* outBroken
)
227 morkEnv
* ev
= this->CanUseThumb(mev
, /*inMutable*/ morkBool_kFalse
, &outErr
);
230 ((morkThumb
*) mHandle_Object
)->GetProgress(ev
, outTotal
,
231 outCurrent
, outDone
, outBroken
);
232 outErr
= ev
->AsErr();
238 orkinThumb::DoMore(nsIMdbEnv
* mev
, mdb_count
* outTotal
,
239 mdb_count
* outCurrent
, mdb_bool
* outDone
, mdb_bool
* outBroken
)
242 morkEnv
* ev
= this->CanUseThumb(mev
, /*inMutable*/ morkBool_kFalse
, &outErr
);
245 morkThumb
* thumb
= (morkThumb
*) mHandle_Object
;
246 thumb
->DoMore(ev
, outTotal
, outCurrent
, outDone
, outBroken
);
247 outErr
= ev
->AsErr();
253 orkinThumb::CancelAndBreakThumb(nsIMdbEnv
* mev
)
256 morkEnv
* ev
= this->CanUseThumb(mev
, /*inMutable*/ morkBool_kFalse
, &outErr
);
259 morkThumb
* thumb
= (morkThumb
*) mHandle_Object
;
260 thumb
->mThumb_Done
= morkBool_kTrue
;
261 thumb
->mThumb_Broken
= morkBool_kTrue
;
262 thumb
->CloseMorkNode(ev
); // should I close this here?
263 outErr
= ev
->AsErr();
267 // } ===== end nsIMdbThumb methods =====
269 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789