1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
13 from libreoffice
.util
import printing
15 class ItemSetPrinter(object):
16 '''Prints SfxItemSets'''
18 def __init__(self
, typename
, value
):
19 self
.typename
= typename
23 whichranges
= self
.which_ranges()
24 return "SfxItemSet of pool %s with parent %s and Which ranges: %s" \
25 % (self
.value
['m_pPool'], self
.value
['m_pParent'], whichranges
)
27 def which_ranges(self
):
28 whichranges
= self
.value
['m_pWhichRanges']
31 while (whichranges
[index
]):
32 whiches
.append((int(whichranges
[index
]), int(whichranges
[index
+1])))
37 whichranges
= self
.which_ranges()
40 for (whichfrom
, whichto
) in whichranges
:
41 size
+= whichto
- whichfrom
+ 1
42 whichids
+= [which
for which
in range(whichfrom
, whichto
+1)]
43 return self
._iterator
(self
.value
['m_pItems']['_M_t']['_M_t']['_M_head_impl'], size
, whichids
)
45 class _iterator(six
.Iterator
):
47 def __init__(self
, data
, count
, whichids
):
49 self
.whichids
= whichids
52 self
._check
_invariant
()
58 if self
.pos
== self
.count
:
61 which
= self
.whichids
[self
.pos
]
62 elem
= self
.data
[self
.pos
]
63 self
.pos
= self
.pos
+ 1
65 self
._check
_invariant
()
69 # let's try how well that works...
70 elem
= elem
.cast(elem
.dynamic_type
).dereference()
71 return (str(which
), elem
)
73 def _check_invariant(self
):
74 assert self
.count
>= 0
77 assert self
.pos
<= self
.count
78 assert len(self
.whichids
) == self
.count
82 def build_pretty_printers():
85 printer
= printing
.Printer("libreoffice/svl")
87 printer
.add('SfxItemSet', ItemSetPrinter
)
89 def register_pretty_printers(obj
):
90 printing
.register_pretty_printer(printer
, obj
)
92 build_pretty_printers()
94 # vim:set shiftwidth=4 softtabstop=4 expandtab: