fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / condformat / condformatdlg.cxx
blobfe4ddbdfda87276ba0548a14214ffb4856764db5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include "condformatdlg.hxx"
11 #include "condformatdlg.hrc"
13 #include <vcl/vclevent.hxx>
14 #include <svl/style.hxx>
15 #include <sfx2/dispatch.hxx>
16 #include <svl/stritem.hxx>
17 #include <svl/intitem.hxx>
18 #include <svx/xtable.hxx>
19 #include <svx/drawitem.hxx>
20 #include <vcl/msgbox.hxx>
21 #include <vcl/settings.hxx>
22 #include <vcl/builderfactory.hxx>
23 #include <libxml/tree.h>
25 #include "anyrefdg.hxx"
26 #include "document.hxx"
27 #include "conditio.hxx"
28 #include "stlpool.hxx"
29 #include "tabvwsh.hxx"
30 #include "colorscale.hxx"
31 #include "colorformat.hxx"
32 #include "reffact.hxx"
33 #include "docsh.hxx"
34 #include "docfunc.hxx"
35 #include "condformatdlgentry.hxx"
37 #include "globstr.hrc"
39 ScCondFormatList::ScCondFormatList(vcl::Window* pParent, WinBits nStyle)
40 : Control(pParent, nStyle | WB_DIALOGCONTROL)
41 , mbHasScrollBar(false)
42 , mpScrollBar(VclPtr<ScrollBar>::Create(this, WB_VERT ))
43 , mpDoc(NULL)
44 , mpDialogParent(NULL)
46 mpScrollBar->SetScrollHdl( LINK( this, ScCondFormatList, ScrollHdl ) );
47 mpScrollBar->EnableDrag();
48 SetControlBackground( GetSettings().GetStyleSettings().GetWindowColor() );
49 SetBackground(GetControlBackground());
52 ScCondFormatList::~ScCondFormatList()
54 disposeOnce();
57 void ScCondFormatList::dispose()
59 mpDialogParent.clear();
60 mpScrollBar.disposeAndClear();
61 for (auto it = maEntries.begin(); it != maEntries.end(); ++it)
62 it->disposeAndClear();
63 maEntries.clear();
64 Control::dispose();
67 void ScCondFormatList::init(ScDocument* pDoc, ScCondFormatDlg* pDialogParent,
68 const ScConditionalFormat* pFormat, const ScRangeList& rRanges,
69 const ScAddress& rPos, condformat::dialog::ScCondFormatDialogType eType)
71 mpDialogParent = pDialogParent;
72 mpDoc = pDoc;
73 maPos = rPos;
74 maRanges = rRanges;
76 if(pFormat)
78 size_t nCount = pFormat->size();
79 for (size_t nIndex = 0; nIndex < nCount; ++nIndex)
81 const ScFormatEntry* pEntry = pFormat->GetEntry(nIndex);
82 switch(pEntry->GetType())
84 case condformat::CONDITION:
86 const ScCondFormatEntry* pConditionEntry = static_cast<const ScCondFormatEntry*>( pEntry );
87 if(pConditionEntry->GetOperation() != SC_COND_DIRECT)
88 maEntries.push_back(VclPtr<ScConditionFrmtEntry>::Create( this, mpDoc, pDialogParent, maPos, pConditionEntry ) );
89 else
90 maEntries.push_back(VclPtr<ScFormulaFrmtEntry>::Create( this, mpDoc, pDialogParent, maPos, pConditionEntry ) );
93 break;
94 case condformat::COLORSCALE:
96 const ScColorScaleFormat* pColorScale = static_cast<const ScColorScaleFormat*>( pEntry );
97 if( pColorScale->size() == 2 )
98 maEntries.push_back(VclPtr<ScColorScale2FrmtEntry>::Create( this, mpDoc, maPos, pColorScale ) );
99 else
100 maEntries.push_back(VclPtr<ScColorScale3FrmtEntry>::Create( this, mpDoc, maPos, pColorScale ) );
102 break;
103 case condformat::DATABAR:
104 maEntries.push_back(VclPtr<ScDataBarFrmtEntry>::Create( this, mpDoc, maPos, static_cast<const ScDataBarFormat*>( pEntry ) ) );
105 break;
106 case condformat::ICONSET:
107 maEntries.push_back(VclPtr<ScIconSetFrmtEntry>::Create( this, mpDoc, maPos, static_cast<const ScIconSetFormat*>( pEntry ) ) );
108 break;
109 case condformat::DATE:
110 maEntries.push_back(VclPtr<ScDateFrmtEntry>::Create( this, mpDoc, static_cast<const ScCondDateFormatEntry*>( pEntry ) ) );
111 break;
114 if(nCount)
115 EntrySelectHdl(maEntries[0].get());
117 else
119 switch(eType)
121 case condformat::dialog::CONDITION:
122 maEntries.push_back(VclPtr<ScConditionFrmtEntry>::Create( this, mpDoc, pDialogParent, maPos ));
123 break;
124 case condformat::dialog::COLORSCALE:
125 maEntries.push_back(VclPtr<ScColorScale3FrmtEntry>::Create( this, mpDoc, maPos ));
126 break;
127 case condformat::dialog::DATABAR:
128 maEntries.push_back(VclPtr<ScDataBarFrmtEntry>::Create( this, mpDoc, maPos ));
129 break;
130 case condformat::dialog::ICONSET:
131 maEntries.push_back(VclPtr<ScIconSetFrmtEntry>::Create( this, mpDoc, maPos ));
132 break;
133 case condformat::dialog::DATE:
134 maEntries.push_back(VclPtr<ScDateFrmtEntry>::Create( this, mpDoc ));
135 break;
136 case condformat::dialog::NONE:
137 break;
140 RecalcAll();
141 if (!maEntries.empty())
142 (*maEntries.begin())->SetActive();
144 RecalcAll();
147 VCL_BUILDER_DECL_FACTORY(ScCondFormatList)
149 WinBits nWinBits = 0;
151 OString sBorder = VclBuilder::extractCustomProperty(rMap);
152 if (!sBorder.isEmpty())
153 nWinBits |= WB_BORDER;
155 rRet = VclPtr<ScCondFormatList>::Create(pParent, nWinBits);
158 Size ScCondFormatList::GetOptimalSize() const
160 return LogicToPixel(Size(290, 185), MAP_APPFONT);
163 void ScCondFormatList::Resize()
165 Control::Resize();
166 RecalcAll();
169 ScConditionalFormat* ScCondFormatList::GetConditionalFormat() const
171 if(maEntries.empty())
172 return NULL;
174 ScConditionalFormat* pFormat = new ScConditionalFormat(0, mpDoc);
175 for(EntryContainer::const_iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr)
177 ScFormatEntry* pEntry = (*itr)->GetEntry();
178 if(pEntry)
179 pFormat->AddEntry(pEntry);
182 pFormat->SetRange(maRanges);
184 return pFormat;
187 void ScCondFormatList::RecalcAll()
189 sal_Int32 nTotalHeight = 0;
190 sal_Int32 nIndex = 1;
191 for(EntryContainer::iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr)
193 nTotalHeight += (*itr)->GetSizePixel().Height();
194 (*itr)->SetIndex( nIndex );
195 ++nIndex;
198 Size aCtrlSize = GetOutputSize();
199 long nSrcBarSize = GetSettings().GetStyleSettings().GetScrollBarSize();
200 if(nTotalHeight > GetSizePixel().Height())
202 mbHasScrollBar = true;
203 mpScrollBar->SetPosSizePixel(Point(aCtrlSize.Width() -nSrcBarSize, 0),
204 Size(nSrcBarSize, aCtrlSize.Height()) );
205 mpScrollBar->SetRangeMax(nTotalHeight);
206 mpScrollBar->SetVisibleSize(aCtrlSize.Height());
207 mpScrollBar->Show();
209 else
211 mbHasScrollBar = false;
212 mpScrollBar->Hide();
215 Point aPoint(0,-1*mpScrollBar->GetThumbPos());
216 for(EntryContainer::iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr)
218 (*itr)->SetPosPixel(aPoint);
219 Size aSize = (*itr)->GetSizePixel();
220 if(mbHasScrollBar)
221 aSize.Width() = aCtrlSize.Width() - nSrcBarSize;
222 else
223 aSize.Width() = aCtrlSize.Width();
224 (*itr)->SetSizePixel(aSize);
226 aPoint.Y() += (*itr)->GetSizePixel().Height();
230 void ScCondFormatList::DoScroll(long nDelta)
232 Point aNewPoint = mpScrollBar->GetPosPixel();
233 Rectangle aRect(Point(), GetOutputSize());
234 aRect.Right() -= mpScrollBar->GetSizePixel().Width();
235 Scroll( 0, -nDelta, aRect );
236 mpScrollBar->SetPosPixel(aNewPoint);
239 IMPL_LINK(ScCondFormatList, ColFormatTypeHdl, ListBox*, pBox)
241 EntryContainer::iterator itr = maEntries.begin();
242 for(; itr != maEntries.end(); ++itr)
244 if((*itr)->IsSelected())
245 break;
247 if(itr == maEntries.end())
248 return 0;
250 sal_Int32 nPos = pBox->GetSelectEntryPos();
251 switch(nPos)
253 case 0:
254 if((*itr)->GetType() == condformat::entry::COLORSCALE2)
255 return 0;
257 itr->disposeAndClear();
258 *itr = VclPtr<ScColorScale2FrmtEntry>::Create( this, mpDoc, maPos );
259 break;
260 case 1:
261 if((*itr)->GetType() == condformat::entry::COLORSCALE3)
262 return 0;
264 itr->disposeAndClear();
265 *itr = VclPtr<ScColorScale3FrmtEntry>::Create( this, mpDoc, maPos );
266 break;
267 case 2:
268 if((*itr)->GetType() == condformat::entry::DATABAR)
269 return 0;
271 itr->disposeAndClear();
272 *itr = VclPtr<ScDataBarFrmtEntry>::Create( this, mpDoc, maPos );
273 break;
274 case 3:
275 if((*itr)->GetType() == condformat::entry::ICONSET)
276 return 0;
278 itr->disposeAndClear();
279 *itr = VclPtr<ScIconSetFrmtEntry>::Create( this, mpDoc, maPos );
280 break;
281 default:
282 break;
284 mpDialogParent->InvalidateRefData();
285 (*itr)->SetActive();
286 RecalcAll();
287 return 0;
290 IMPL_LINK(ScCondFormatList, TypeListHdl, ListBox*, pBox)
292 //Resolves: fdo#79021 At this point we are still inside the ListBox Select.
293 //If we call maEntries.replace here then the pBox will be deleted before it
294 //has finished Select and will crash on accessing its deleted this. So Post
295 //to do the real work after the Select has completed
296 Application::PostUserEvent(LINK(this, ScCondFormatList, AfterTypeListHdl), pBox, true);
297 return 0;
300 IMPL_LINK(ScCondFormatList, AfterTypeListHdl, ListBox*, pBox)
302 EntryContainer::iterator itr = maEntries.begin();
303 for(; itr != maEntries.end(); ++itr)
305 if((*itr)->IsSelected())
306 break;
308 if(itr == maEntries.end())
309 return 0;;
311 sal_Int32 nPos = pBox->GetSelectEntryPos();
312 switch(nPos)
314 case 0:
315 switch((*itr)->GetType())
317 case condformat::entry::FORMULA:
318 case condformat::entry::CONDITION:
319 case condformat::entry::DATE:
320 break;
321 case condformat::entry::COLORSCALE2:
322 case condformat::entry::COLORSCALE3:
323 case condformat::entry::DATABAR:
324 case condformat::entry::ICONSET:
325 return 0;
327 itr->disposeAndClear();
328 *itr = VclPtr<ScColorScale3FrmtEntry>::Create(this, mpDoc, maPos);
329 mpDialogParent->InvalidateRefData();
330 (*itr)->SetActive();
331 break;
332 case 1:
333 if((*itr)->GetType() == condformat::entry::CONDITION)
334 return 0;
336 itr->disposeAndClear();
337 *itr = VclPtr<ScConditionFrmtEntry>::Create(this, mpDoc, mpDialogParent, maPos);
338 mpDialogParent->InvalidateRefData();
339 (*itr)->SetActive();
340 break;
341 case 2:
342 if((*itr)->GetType() == condformat::entry::FORMULA)
343 return 0;
345 itr->disposeAndClear();
346 *itr = VclPtr<ScFormulaFrmtEntry>::Create(this, mpDoc, mpDialogParent, maPos);
347 mpDialogParent->InvalidateRefData();
348 (*itr)->SetActive();
349 break;
350 case 3:
351 if((*itr)->GetType() == condformat::entry::DATE)
352 return 0;
354 itr->disposeAndClear();
355 *itr = VclPtr<ScDateFrmtEntry>::Create( this, mpDoc );
356 mpDialogParent->InvalidateRefData();
357 (*itr)->SetActive();
358 break;
361 RecalcAll();
362 return 0;
365 IMPL_LINK_NOARG( ScCondFormatList, AddBtnHdl )
367 VclPtr<ScCondFrmtEntry> pNewEntry = VclPtr<ScConditionFrmtEntry>::Create(this, mpDoc, mpDialogParent, maPos);
368 maEntries.push_back( pNewEntry );
369 for(EntryContainer::iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr)
371 (*itr)->SetInactive();
373 mpDialogParent->InvalidateRefData();
374 pNewEntry->SetActive();
375 RecalcAll();
376 return 0;
379 IMPL_LINK_NOARG( ScCondFormatList, RemoveBtnHdl )
381 for(EntryContainer::iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr)
383 if((*itr)->IsSelected())
385 itr->disposeAndClear();
386 maEntries.erase(itr);
387 break;
390 mpDialogParent->InvalidateRefData();
391 RecalcAll();
392 return 0;
395 IMPL_LINK( ScCondFormatList, EntrySelectHdl, ScCondFrmtEntry*, pEntry )
397 if(pEntry->IsSelected())
398 return 0;
400 //A child has focus, but we will hide that, so regrab to whatever new thing gets
401 //shown instead of leaving it stuck in the inaccessible hidden element
402 bool bReGrabFocus = HasChildPathFocus();
403 for(EntryContainer::iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr)
405 (*itr)->SetInactive();
407 mpDialogParent->InvalidateRefData();
408 pEntry->SetActive();
409 RecalcAll();
410 if (bReGrabFocus)
411 GrabFocus();
412 return 0;
415 IMPL_LINK_NOARG( ScCondFormatList, ScrollHdl )
417 DoScroll(mpScrollBar->GetDelta());
418 return 0;
421 // -------------------------------------------------------------------
422 // Conditional Format Dialog
424 ScCondFormatDlg::ScCondFormatDlg(SfxBindings* pB, SfxChildWindow* pCW,
425 vcl::Window* pParent, ScViewData* pViewData,
426 const ScConditionalFormat* pFormat, const ScRangeList& rRange,
427 const ScAddress& rPos, condformat::dialog::ScCondFormatDialogType eType,
428 bool bManaged)
429 : ScAnyRefDlg(pB, pCW, pParent, "ConditionalFormatDialog",
430 "modules/scalc/ui/conditionalformatdialog.ui")
431 , mbManaged(bManaged)
432 , maPos(rPos)
433 , mpViewData(pViewData)
434 , mpLastEdit(NULL)
436 get(mpBtnOk, "ok");
437 get(mpBtnAdd, "add");
438 get(mpBtnRemove, "delete");
439 get(mpBtnCancel, "cancel");
441 get(mpFtRange, "ftassign");
442 get(mpEdRange, "edassign");
443 mpEdRange->SetReferences(this, mpFtRange);
445 get(mpRbRange, "rbassign");
446 mpRbRange->SetReferences(this, mpEdRange);
448 maKey = pFormat ? pFormat->GetKey() : 0;
450 get(mpCondFormList, "list");
451 mpCondFormList->init(mpViewData->GetDocument(), this, pFormat, rRange, rPos, eType);
453 OUStringBuffer aTitle( GetText() );
454 aTitle.append(" ");
455 OUString aRangeString;
456 rRange.Format(aRangeString, SCA_VALID, pViewData->GetDocument(),
457 pViewData->GetDocument()->GetAddressConvention());
458 aTitle.append(aRangeString);
459 SetText(aTitle.makeStringAndClear());
460 mpBtnOk->SetClickHdl(LINK(this, ScCondFormatDlg, BtnPressedHdl ) );
461 mpBtnAdd->SetClickHdl( LINK( mpCondFormList, ScCondFormatList, AddBtnHdl ) );
462 mpBtnRemove->SetClickHdl( LINK( mpCondFormList, ScCondFormatList, RemoveBtnHdl ) );
463 mpBtnCancel->SetClickHdl( LINK(this, ScCondFormatDlg, BtnPressedHdl ) );
464 mpEdRange->SetModifyHdl( LINK( this, ScCondFormatDlg, EdRangeModifyHdl ) );
465 mpEdRange->SetGetFocusHdl( LINK( this, ScCondFormatDlg, RangeGetFocusHdl ) );
466 mpEdRange->SetLoseFocusHdl( LINK( this, ScCondFormatDlg, RangeLoseFocusHdl ) );
468 mpEdRange->SetText(aRangeString);
471 ScCondFormatDlg::~ScCondFormatDlg()
473 disposeOnce();
476 void ScCondFormatDlg::dispose()
478 mpBtnOk.clear();
479 mpBtnAdd.clear();
480 mpBtnRemove.clear();
481 mpBtnCancel.clear();
482 mpFtRange.clear();
483 mpEdRange.clear();
484 mpRbRange.clear();
485 mpCondFormList.clear();
486 mpLastEdit.clear();
488 ScAnyRefDlg::dispose();
491 void ScCondFormatDlg::SetActive()
493 if(mpLastEdit)
494 mpLastEdit->GrabFocus();
495 else
496 mpEdRange->GrabFocus();
498 RefInputDone();
501 void ScCondFormatDlg::RefInputDone( bool bForced )
503 ScAnyRefDlg::RefInputDone(bForced);
506 bool ScCondFormatDlg::IsTableLocked() const
508 if (mpLastEdit && mpLastEdit != mpEdRange)
509 return false;
511 return true;
514 bool ScCondFormatDlg::IsRefInputMode() const
516 return mpEdRange->IsEnabled();
519 #define ABS_SREF SCA_VALID \
520 | SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB_ABSOLUTE
521 #define ABS_DREF ABS_SREF \
522 | SCA_COL2_ABSOLUTE | SCA_ROW2_ABSOLUTE | SCA_TAB2_ABSOLUTE
523 #define ABS_DREF3D ABS_DREF | SCA_TAB_3D
525 void ScCondFormatDlg::SetReference(const ScRange& rRef, ScDocument*)
527 formula::RefEdit* pEdit = mpLastEdit;
528 if (!mpLastEdit)
529 pEdit = mpEdRange;
531 if( pEdit->IsEnabled() )
533 if(rRef.aStart != rRef.aEnd)
534 RefInputStart(pEdit);
536 sal_uInt16 n = 0;
537 if (mpLastEdit && mpLastEdit != mpEdRange)
538 n = ABS_DREF3D;
539 else
540 n = ABS_DREF;
542 OUString aRefStr(rRef.Format(n, mpViewData->GetDocument(),
543 ScAddress::Details(mpViewData->GetDocument()->GetAddressConvention(), 0, 0)));
544 pEdit->SetRefString( aRefStr );
548 ScConditionalFormat* ScCondFormatDlg::GetConditionalFormat() const
550 OUString aRangeStr = mpEdRange->GetText();
551 if(aRangeStr.isEmpty())
552 return NULL;
554 ScRangeList aRange;
555 sal_uInt16 nFlags = aRange.Parse(aRangeStr, mpViewData->GetDocument(),
556 SCA_VALID, mpViewData->GetDocument()->GetAddressConvention(), maPos.Tab());
557 ScConditionalFormat* pFormat = mpCondFormList->GetConditionalFormat();
559 if(nFlags & SCA_VALID && !aRange.empty() && pFormat)
560 pFormat->SetRange(aRange);
561 else
563 delete pFormat;
564 pFormat = NULL;
567 return pFormat;
570 void ScCondFormatDlg::InvalidateRefData()
572 mpLastEdit = NULL;
575 // -------------------------------------------------------------
576 // Close the Conditional Format Dialog
578 bool ScCondFormatDlg::Close()
580 return DoClose( ScCondFormatDlgWrapper::GetChildWindowId() );
583 // ------------------------------------------------------------------------
584 // Occurs when the Conditional Format Dialog the OK button is pressed.
586 void ScCondFormatDlg::OkPressed()
588 ScConditionalFormat* pFormat = GetConditionalFormat();
590 if(pFormat)
591 mpViewData->GetDocShell()->GetDocFunc().ReplaceConditionalFormat(maKey,
592 pFormat, maPos.Tab(), pFormat->GetRange());
593 else
594 mpViewData->GetDocShell()->GetDocFunc().ReplaceConditionalFormat(maKey,
595 NULL, maPos.Tab(), ScRangeList());
597 if ( mbManaged )
599 SetDispatcherLock( false );
600 // Queue message to open Conditional Format Manager Dialog
601 GetBindings().GetDispatcher()->Execute( SID_OPENDLG_CONDFRMT_MANAGER,
602 SfxCallMode::ASYNCHRON );
604 Close();
607 // ------------------------------------------------------------------------
608 // Occurs when the Conditional Format Dialog is cancelled.
610 void ScCondFormatDlg::CancelPressed()
612 if ( mbManaged )
614 SetDispatcherLock( false );
615 // Queue message to open Conditional Format Manager Dialog
616 GetBindings().GetDispatcher()->Execute( SID_OPENDLG_CONDFRMT_MANAGER,
617 SfxCallMode::ASYNCHRON );
619 Close();
622 // ------------------------------------------------------------------------------
623 // Parse xml string parameters used to initialize the Conditional Format Dialog
624 // when it is created.
626 bool ScCondFormatDlg::ParseXmlString(const OUString& sXMLString,
627 sal_uInt32& nIndex,
628 sal_uInt8& nType,
629 bool& bManaged)
631 bool bRetVal = false;
632 OString sTagName;
633 OUString sTagValue;
635 xmlNodePtr pXmlRoot = NULL;
636 xmlNodePtr pXmlNode = NULL;
638 OString sOString = OUStringToOString( sXMLString, RTL_TEXTENCODING_UTF8 );
639 xmlDocPtr pXmlDoc = xmlParseMemory(sOString.getStr(), sOString.getLength());
641 if( pXmlDoc )
643 bRetVal = true;
644 pXmlRoot = xmlDocGetRootElement( pXmlDoc );
645 pXmlNode = pXmlRoot->children;
647 while (pXmlNode != NULL && bRetVal)
649 sTagName = OUStringToOString(OUString("Index"), RTL_TEXTENCODING_UTF8);
650 if (xmlStrcmp(pXmlNode->name, reinterpret_cast<xmlChar const *>(sTagName.getStr())) == 0)
652 if (pXmlNode->children != NULL && pXmlNode->children->type == XML_TEXT_NODE)
654 sTagValue = OUString(reinterpret_cast<char*>(pXmlNode->children->content),
655 strlen(reinterpret_cast<char*>(pXmlNode->children->content)),
656 RTL_TEXTENCODING_UTF8);
657 nIndex = sTagValue.toUInt32();
658 pXmlNode = pXmlNode->next;
659 continue;
663 sTagName = OUStringToOString(OUString("Type"), RTL_TEXTENCODING_UTF8);
664 if (xmlStrcmp(pXmlNode->name, reinterpret_cast<xmlChar const *>(sTagName.getStr())) == 0)
666 if (pXmlNode->children != NULL && pXmlNode->children->type == XML_TEXT_NODE)
668 sTagValue = OUString(reinterpret_cast<char*>(pXmlNode->children->content),
669 strlen(reinterpret_cast<char*>(pXmlNode->children->content)),
670 RTL_TEXTENCODING_UTF8);
671 nType = sTagValue.toUInt32();
672 pXmlNode = pXmlNode->next;
673 continue;
677 sTagName = OUStringToOString(OUString("Managed"), RTL_TEXTENCODING_UTF8);
678 if (xmlStrcmp(pXmlNode->name, reinterpret_cast<xmlChar const *>(sTagName.getStr())) == 0)
680 if (pXmlNode->children != NULL && pXmlNode->children->type == XML_TEXT_NODE)
682 sTagValue = OUString(reinterpret_cast<char*>(pXmlNode->children->content),
683 strlen(reinterpret_cast<char*>(pXmlNode->children->content)),
684 RTL_TEXTENCODING_UTF8);
685 bManaged = sTagValue.toBoolean();
686 pXmlNode = pXmlNode->next;
687 continue;
690 bRetVal = false;
694 xmlFreeDoc(pXmlDoc);
695 return bRetVal;
698 // ---------------------------------------------------------------------------------------
699 // Generate xml string parameters used to initialize the Conditional Format Dialog
700 // when it is created.
702 OUString ScCondFormatDlg::GenerateXmlString(sal_uInt32 nIndex, sal_uInt8 nType, bool bManaged)
704 OUString sReturn;
705 sal_Int32 nSize = 0;
707 OString sTagName;
708 OString sTagValue;
710 xmlNodePtr pXmlRoot = NULL;
711 xmlNodePtr pXmlNode = NULL;
713 xmlChar* pBuffer = NULL;
714 const xmlChar* pTagName = NULL;
715 const xmlChar* pTagValue = NULL;
717 xmlDocPtr pXmlDoc = xmlNewDoc(reinterpret_cast<const xmlChar*>("1.0"));
719 sTagName = OUStringToOString(OUString("ScCondFormatDlg"), RTL_TEXTENCODING_UTF8);
720 pTagName = reinterpret_cast<const xmlChar*>(sTagName.getStr());
721 pXmlRoot = xmlNewDocNode(pXmlDoc, NULL, pTagName, NULL);
723 xmlDocSetRootElement(pXmlDoc, pXmlRoot);
725 sTagName = OUStringToOString(OUString("Index"), RTL_TEXTENCODING_UTF8);
726 sTagValue = OUStringToOString(OUString::number(nIndex), RTL_TEXTENCODING_UTF8);
727 pTagName = reinterpret_cast<const xmlChar*>(sTagName.getStr());
728 pTagValue = reinterpret_cast<const xmlChar*>(sTagValue.getStr());
729 pXmlNode = xmlNewDocNode(pXmlDoc, NULL, pTagName, pTagValue);
731 xmlAddChild(pXmlRoot, pXmlNode);
733 sTagName = OUStringToOString(OUString("Type"), RTL_TEXTENCODING_UTF8);
734 sTagValue = OUStringToOString(OUString::number(nType), RTL_TEXTENCODING_UTF8);
735 pTagName = reinterpret_cast<const xmlChar*>(sTagName.getStr());
736 pTagValue = reinterpret_cast<const xmlChar*>(sTagValue.getStr());
737 pXmlNode = xmlNewDocNode(pXmlDoc, NULL, pTagName, pTagValue);
739 xmlAddChild(pXmlRoot, pXmlNode);
741 sTagName = OUStringToOString(OUString("Managed"), RTL_TEXTENCODING_UTF8);
742 sTagValue = OUStringToOString(OUString::boolean(bManaged), RTL_TEXTENCODING_UTF8);
743 pTagName = reinterpret_cast<const xmlChar*>(sTagName.getStr());
744 pTagValue = reinterpret_cast<const xmlChar*>(sTagValue.getStr());
745 pXmlNode = xmlNewDocNode(pXmlDoc, NULL, pTagName, pTagValue);
747 xmlAddChild(pXmlRoot, pXmlNode);
749 xmlDocDumpMemory(pXmlDoc, &pBuffer, (int*)&nSize);
751 sReturn = OUString(reinterpret_cast<char const *>(pBuffer), nSize, RTL_TEXTENCODING_UTF8);
753 xmlFree(pBuffer);
754 xmlFreeDoc(pXmlDoc);
756 return sReturn;
760 IMPL_LINK( ScCondFormatDlg, EdRangeModifyHdl, Edit*, pEdit )
762 OUString aRangeStr = pEdit->GetText();
763 ScRangeList aRange;
764 sal_uInt16 nFlags = aRange.Parse(aRangeStr, mpViewData->GetDocument(),
765 SCA_VALID, mpViewData->GetDocument()->GetAddressConvention());
766 if(nFlags & SCA_VALID)
767 pEdit->SetControlBackground(GetSettings().GetStyleSettings().GetWindowColor());
768 else
769 pEdit->SetControlBackground(COL_LIGHTRED);
770 return 0;
773 IMPL_LINK( ScCondFormatDlg, RangeGetFocusHdl, formula::RefEdit*, pEdit )
775 mpLastEdit = pEdit;
776 return 0;
779 IMPL_STATIC_LINK_NOARG( ScCondFormatDlg, RangeLoseFocusHdl )
781 //mpLastEdit = NULL;
782 return 0;
785 // ------------------------------------------------------
786 // Conditional Format Dialog button click event handler.
788 IMPL_LINK( ScCondFormatDlg, BtnPressedHdl, Button*, pBtn)
790 if (pBtn == mpBtnOk)
791 OkPressed();
792 else if (pBtn == mpBtnCancel)
793 CancelPressed();
794 return 0;
797 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */