1 /*****************************************************************************\
2 pmselect.cpp : Implimentation for the ModeSet class
4 Copyright (c) 2001 - 2002, Hewlett-Packard Co.
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15 3. Neither the name of Hewlett-Packard nor the names of its
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
20 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
22 NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24 TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
25 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 \*****************************************************************************/
43 m_ListHead = new MSNode;
45 if (m_ListHead != NULL)
47 m_ListHead->m_pNext = NULL;
48 m_ListHead->m_pPrintMode = pPM;
50 Reset(); // m_Current = m_ListHead;
56 if (m_ListHead != NULL)
59 while (m_Current != NULL)
61 MSNode* pDeleteable = m_Current;
62 Next(); //m_Current = m_Current->m_pNext;
69 // note that copy constructor, Head() and all "Subset" methods make NEW COPIES that need deleting
81 MSNode* t_SrcNode = pSource->m_ListHead;
85 Append(t_SrcNode->m_pPrintMode);
86 t_SrcNode = t_SrcNode->m_pNext;
91 BOOL ModeSet::Append(PrintMode* pPrM) // return TRUE for memerr
94 if (m_ListHead == NULL)
96 m_ListHead = new MSNode;
97 if (m_ListHead == NULL)
99 return TRUE; // memory error
101 m_ListHead->m_pPrintMode = pPrM;
106 if (m_Current != NULL) // try to be effiecient and not walk the whole list
112 t_walk = m_ListHead; // we know m_ListHead != NULL from above
115 while(t_walk->m_pNext != NULL)
117 t_walk = t_walk->m_pNext;
120 t_walk->m_pNext = new MSNode;
121 if (t_walk->m_pNext == NULL)
123 return TRUE; // memory error
126 // update current pointer (possible to shorten next append
127 // i.e. current will point to the last item in the list after an append
128 m_Current = t_walk->m_pNext;
129 m_Current->m_pPrintMode = pPrM; // finally!!
132 return FALSE; // no error
136 unsigned int ModeSet::Size() const
138 unsigned int uCount = 0;
140 MSNode* t_walk = m_ListHead;
141 while (t_walk != NULL)
144 t_walk = t_walk->m_pNext;
150 // strange name...? Create a new one entry list with the first entry of this list
151 ModeSet* ModeSet::Head()
154 ModeSet* pNew = new ModeSet(HeadPrintMode());
159 ModeSet* ModeSet::FontCapableSubset()
161 ModeSet* resMS = new ModeSet;
170 // if we have set up the list properly we never have to worry about m_pPrintMode
171 // being NULL. If it is NULL then we shouldn't even have a node.
172 ASSERT(CurrPrintMode());
174 if(CurrPrintMode()->bFontCapable)
176 if(resMS->Append(CurrPrintMode()))
178 delete resMS; // there was a memory error appending
182 Next(); //m_Current = m_Current->m_pNext;
185 } //FontCapableSubset
188 ModeSet* ModeSet::PenCompatibleSubset(PEN_TYPE pens)
190 ModeSet* resMS = new ModeSet;
199 ASSERT(CurrPrintMode()); // see comments above
201 if(CurrPrintMode()->Compatible(pens))
203 if(resMS->Append(CurrPrintMode()))
205 delete resMS; // memory error
212 } //PenCompatibleSubset
215 ModeSet* ModeSet::ColorCompatibleSubset(COLORMODE color)
217 ModeSet* resMS = new ModeSet;
226 ASSERT(CurrPrintMode()); // see comments above
228 if (CurrPrintMode()->ColorCompatible(color))
230 if(resMS->Append(CurrPrintMode()))
232 delete resMS; // memory error
239 } //ColorCompatibleSubset
242 ModeSet* ModeSet::QualitySubset(QUALITY_MODE eQuality)
244 ModeSet* resMS = new ModeSet;
253 ASSERT(CurrPrintMode()); // see comments above
255 if (CurrPrintMode()->QualityCompatible(eQuality))
257 if(resMS->Append(CurrPrintMode()))
259 delete resMS; // memory error
269 ModeSet* ModeSet::MediaSubset(MEDIATYPE eMedia)
271 ModeSet* resMS = new ModeSet;
280 ASSERT(CurrPrintMode()); // see comments above
282 if (CurrPrintMode()->MediaCompatible(eMedia))
284 if(resMS->Append(CurrPrintMode()))
286 delete resMS; // memory error