Ejemplo n.º 1
0
LRESULT CSVGSwatchesDlg::OnSwatchesDefinePattern(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	CComPtr<IEXMLDocument> eXMLDocument;
	m_viewGroup->get_eXMLDocument(&eXMLDocument);

	CComQIPtr<IEDocument> eDocument = eXMLDocument;

	CComPtr<ILDOMDocument> document;
	eXMLDocument->get_DOMDocument(&document);

	CSVGFilterOptionsDlg dlg;
	dlg.m_document = document;

	if (dlg.DoModal() == IDOK)
	{
		CComPtr<IOleUndoManager> undoManager;
		eDocument->get_undoManager(&undoManager);

		CComObject<CUndoParent>* pParentUndo;
		CComObject<CUndoParent>::CreateInstance(&pParentUndo);
		if (pParentUndo)
		{
			pParentUndo->AddRef();	// ???
			undoManager->Open(pParentUndo);

			CComPtr<ILSVGElement> svgDefsElement;
			eXMLDocument->FindOrCreateSVGDefs(&svgDefsElement);

			if (svgDefsElement)
			{
				CComPtr<ILSVGSymbolElement> svgFilterElement;
				document->createElementNS(L"http://www.w3.org/2000/svg", L"pattern", (ILDOMElement**)&svgFilterElement);

				if (svgFilterElement)
				{
					svgFilterElement->setAttribute(L"id", dlg.m_id);

					{
						double minx = 99999999;
						double miny = 99999999;
						double maxx = -99999999;
						double maxy = -99999999;

						for (int i = 0; i < m_viewGroup->m_targetElements.GetSize(); i++)
						{
							CComPtr<IEElement> eElement;
							m_viewGroup->m_targetElements[i]->get_eElement(&eElement);

							CComPtr<ILDOMElement> element;
							eElement->get_domElement(&element);

							CComQIPtr<ILSVGLocatable> locatable = element;
							if (locatable)
							{
								CComPtr<ILSVGRect> svgrect;
								locatable->getBBox(&svgrect);
								SVGRect rect = svgrect;

								minx = min(minx, rect.X);
								miny = min(miny, rect.Y);
								maxx = max(maxx, rect.X+rect.Width);
								maxy = max(maxy, rect.Y+rect.Height);

								CComPtr<ILDOMNode> clone;
								element->cloneNode(VARIANT_TRUE/*bDeep*/, &clone);

								svgFilterElement->appendChild(clone, NULL);
							}
						}

						WCHAR buf[256];

						swprintf(buf, L"%g", maxx-minx);
						svgFilterElement->setAttribute(L"width", buf);

						swprintf(buf, L"%g", maxy-miny);
						svgFilterElement->setAttribute(L"height", buf);

						swprintf(buf, L"%g %g %g %g", minx, miny, maxx-minx, maxy-miny);
						svgFilterElement->setAttribute(L"viewBox", buf);
					}

					//CComPtr<IOleUndoManager> undoManager;
					//m_document->get_undoManager(&undoManager);

					CComObject<CWEUndoNewElement>* pUndo;
					CComObject<CWEUndoNewElement>::CreateInstance(&pUndo);
					if (pUndo)
					{
					//	pUndo->AddRef();
						pUndo->m_pDocument = static_cast<CEXMLDocument*>(eXMLDocument.p);

						pUndo->DoInitial(undoManager, svgFilterElement, svgDefsElement, NULL);

						{
							CEXMLViewGroup* pViewGroup = static_cast<CEXMLViewGroup*>(m_viewGroup);

							CComPtr<IEElement> eElement;
							eXMLDocument->GetEElementFromDOMElement(svgFilterElement, &eElement);

							pViewGroup->m_activeReferencedElement = eElement;	// ??? reference element is still NULL
							m_viewGroup->ActivateElement(eElement, 0, NULL);
						}
					}
				}
			}

			undoManager->Close(pParentUndo, TRUE/*commit*/);
		}
	}

	return 0;
}
Ejemplo n.º 2
0
LRESULT CSVGSwatchesDlg::OnSwatchesNewLinearGradient(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	if (m_viewGroup)
	{
		CComPtr<IEXMLDocument> eXMLDocument;
		m_viewGroup->get_eXMLDocument(&eXMLDocument);

		CComQIPtr<IEDocument> eDocument = eXMLDocument;

		CComPtr<ILDOMDocument> document;
		eXMLDocument->get_DOMDocument(&document);

		CSVGFilterOptionsDlg dlg;
		dlg.m_document = document;

		if (dlg.DoModal() == IDOK)
		{
			CComPtr<IOleUndoManager> undoManager;
			eDocument->get_undoManager(&undoManager);

			CComObject<CUndoParent>* pParentUndo;
			CComObject<CUndoParent>::CreateInstance(&pParentUndo);
			if (pParentUndo)
			{
				pParentUndo->AddRef();	// ???
				undoManager->Open(pParentUndo);

				CComPtr<ILSVGElement> svgDefsElement;
				eXMLDocument->FindOrCreateSVGDefs(&svgDefsElement);

				if (svgDefsElement)
				{
					CComPtr<ILSVGElement> svgElement;
					document->createElementNS(L"http://www.w3.org/2000/svg", L"linearGradient", (ILDOMElement**)&svgElement);

					if (svgElement)
					{
						svgElement->setAttribute(L"id", dlg.m_id);
						svgElement->setAttribute(L"gradientUnits", L"userSpaceOnUse");

						// black
						{
							CComPtr<ILDOMElement> stop;
							document->createElementNS(L"http://www.w3.org/2000/svg", L"stop", &stop);
							stop->setAttribute(L"offset", L"0");
							stop->setAttribute(L"style", L"stop-color:#ff0000");

							svgElement->appendChild(stop, NULL);
						}

						// white
						{
							CComPtr<ILDOMElement> stop;
							document->createElementNS(L"http://www.w3.org/2000/svg", L"stop", &stop);
							stop->setAttribute(L"offset", L"1");
							stop->setAttribute(L"style", L"stop-color:#ffff00");

							svgElement->appendChild(stop, NULL);
						}

					//	CComPtr<IOleUndoManager> undoManager;
					//	m_document->get_undoManager(&undoManager);

						CComObject<CWEUndoNewElement>* pUndo;
						CComObject<CWEUndoNewElement>::CreateInstance(&pUndo);
						if (pUndo)
						{
						//	pUndo->AddRef();
							pUndo->m_pDocument = static_cast<CEXMLDocument*>(eXMLDocument.p);

							pUndo->DoInitial(undoManager, svgElement, svgDefsElement, NULL);

							// TODO: do this here?
						//	CComPtr<IWebXMLViewGroup> viewGroup;
						//	m_document->GetActiveViewGroup(&viewGroup);
						//	if (viewGroup)
							{
								CEXMLViewGroup* pViewGroup = m_viewGroup;

	//							CElementImpl* pElement = ((CEXMLDocument*)m_document.p)->m_pTree->FindDOMElement(svgFilterElement);
								CComPtr<IEElement> eElement;
								eXMLDocument->GetEElementFromDOMElement(svgElement, &eElement);

								pViewGroup->m_activeReferencedElement = eElement;	// ??? reference element is still NULL
								m_viewGroup->ActivateElement(eElement, 0, NULL);
							}
						}
					}
				}

				undoManager->Close(pParentUndo, TRUE/*commit*/);
			}
		}
	}

	return 0;
}
Ejemplo n.º 3
0
LRESULT CSVGSwatchesDlg::OnSwatchesNewSolidColor(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	if (m_viewGroup)
	{
		CComPtr<IEXMLDocument> eXMLDocument;
		m_viewGroup->get_eXMLDocument(&eXMLDocument);

		CComQIPtr<IEDocument> eDocument = eXMLDocument;

		CComPtr<ILDOMDocument> document;
		eXMLDocument->get_DOMDocument(&document);

		CSVGFilterOptionsDlg dlg;
		dlg.m_document = document;

		if (dlg.DoModal() == IDOK)
		{
			CComPtr<IOleUndoManager> undoManager;
			eDocument->get_undoManager(&undoManager);

			CComObject<CUndoParent>* pParentUndo;
			CComObject<CUndoParent>::CreateInstance(&pParentUndo);
			if (pParentUndo)
			{
				pParentUndo->AddRef();	// ???
				undoManager->Open(pParentUndo);

				CComPtr<ILSVGElement> svgDefsElement;
				eXMLDocument->FindOrCreateSVGDefs(&svgDefsElement);

				if (svgDefsElement)
				{
					CComPtr<ILSVGElement> svgElement;
					document->createElementNS(L"http://www.w3.org/2000/svg", L"solidColor", (ILDOMElement**)&svgElement);

					if (svgElement)
					{
						svgElement->setAttribute(L"id", dlg.m_id);

					//	CComPtr<IOleUndoManager> undoManager;
					//	m_document->get_undoManager(&undoManager);

						CComBSTR styleValue;
						styleValue += L"solid-color:";
						styleValue += static_cast<CEXMLDocument*>(eXMLDocument.p)->m_lastColor;
						styleValue += L";";

						svgElement->setAttribute(L"style", styleValue);

						CComObject<CWEUndoNewElement>* pUndo;
						CComObject<CWEUndoNewElement>::CreateInstance(&pUndo);
						if (pUndo)
						{
						//	pUndo->AddRef();
							pUndo->m_pDocument = static_cast<CEXMLDocument*>(eXMLDocument.p);

							pUndo->DoInitial(undoManager, svgElement, svgDefsElement, NULL);

							// TODO: do this here?
							//CComPtr<IWebXMLViewGroup> viewGroup;
							//m_document->GetActiveViewGroup(&viewGroup);
							//if (viewGroup)
							{
								CEXMLViewGroup* pViewGroup = m_viewGroup;

	//							CElementImpl* pElement = ((CEXMLDocument*)m_document.p)->m_pTree->FindDOMElement(svgFilterElement);
								CComPtr<IEElement> eElement;
								eXMLDocument->GetEElementFromDOMElement(svgElement, &eElement);

								{
									pViewGroup->m_colorEditing = L"solid-color";

									pViewGroup->SetCurrentSelectionColor();
									pViewGroup->Fire_ColorChanged();
								}

								pViewGroup->m_activeReferencedElement = eElement;	// ??? reference element is still NULL
								m_viewGroup->ActivateElement(eElement, 0, NULL);
							}
						}
					}
				}

				undoManager->Close(pParentUndo, TRUE/*commit*/);
			}
		}
	}

	return 0;
}
Ejemplo n.º 4
0
STDMETHODIMP CSVGSwatchesDlg::Drop(IDataObject * pDataObject, DWORD grfKeyState, POINTL pt, DWORD * pdwEffect)
{
	ASSERT(0);
#if 0
	POINT point;
	point.x = pt.x;
	point.y = pt.y;
	ScreenToClient(&point);

	COleDataObjectWrapper dataObject;
	dataObject.Attach(pDataObject);

	HGLOBAL hData;

	if (m_viewGroup)
	{
		CComPtr<IEXMLDocument> eXMLDocument;
		m_viewGroup->get_eXMLDocument(&eXMLDocument);

	#if 0
		if (hData = dataObject.GetGlobalData(CF_HDROP))
		{
			DROPFILES* dp = (DROPFILES*)GlobalLock(hData);
			if (dp)
			{
				char* p = (char*)(dp+1);

				int i = 0;
				TCHAR filename[512];
				while (*p)
				{
					filename[i++] = *p++;
				}
				filename[i] = 0;

				CHTMDesignFrame* pFrame = NULL;
				m_pFrameSet->OnButtonDown(0, point, 0, FALSE, &pFrame);
				if (pFrame)
				{
					pFrame->m_pElement->setAttribute(L"src", _bstr_t(filename));
					//m_pDocument->CreateHTMLTree();
					//m_pDocument->UpdateAllViews(NULL);
				}
			}

			GlobalUnlock(hData);

			{
				BuildFrames();

				OnSize();
				InvalidateRect(NULL, TRUE);
			}

			*pdwEffect = DROPEFFECT_COPY;
		}
		else
	#endif
		if (hData = dataObject.GetGlobalData(CF_UNICODETEXT))
		{
			WCHAR* text = (WCHAR*)GlobalLock(hData);
			int len = GlobalSize(hData);

			CComPtr<ILSVGDocument> svgdocument;
			svgdocument.CoCreateInstance(CLSID_LSVGDocument);

			VARIANT_BOOL bsuccess;
			svgdocument->loadXML(_bstr_t(text), &bsuccess);

			if (bsuccess)
			{
				CComQIPtr<IEDocument> eDocument = eXMLDocument;

				IUndoManager* undoManager;
				eDocument->get_undoManager(&undoManager);

				CComObject<CUndoParent>* pParentUndo;
				CComObject<CUndoParent>::CreateInstance(&pParentUndo);
				if (pParentUndo)
				{
					pParentUndo->AddRef();	// ???
					undoManager->Open(pParentUndo);

					CComPtr<ILSVGElement> svgDefsElement;
					eXMLDocument->FindOrCreateSVGDefs(&svgDefsElement);

					if (svgDefsElement)
					{
						CComPtr<ILDOMElement> documentElement;
						svgdocument->get_documentElement(&documentElement);

						CComPtr<ILDOMNode> node;
						documentElement->get_firstChild(&node);
						while (node)
						{
							CComPtr<ILDOMNode> nextSibling;
							node->get_nextSibling(&nextSibling);

							CComQIPtr<ILSVGGradientElement> svgGradientElement = node;
							if (svgGradientElement)
							{
								m_listView.m_xmlDocument->adoptNode(svgGradientElement, NULL);

								CComObject<CWEUndoNewElement>* pUndo;
								CComObject<CWEUndoNewElement>::CreateInstance(&pUndo);
								if (pUndo)
								{
								//	pUndo->AddRef();
									pUndo->m_pDocument = static_cast<CEXMLDocument*>(eXMLDocument.p);

									pUndo->DoInitial(undoManager, svgGradientElement, svgDefsElement, NULL);
								}
							}

							node = nextSibling;
						}
					}

					undoManager->Close(pParentUndo, TRUE/*commit*/);
				}
			}

			GlobalUnlock(hData);
			//return TRUE;
		}
	}
#endif

	return S_OK;
}
Ejemplo n.º 5
0
LRESULT CSVGFontsDlg::OnFontNewFont(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	if (m_document)
	{
		CComQIPtr<IEDocument> eDocument = m_document;

		CComPtr<ILDOMDocument> document;
		m_document->get_DOMDocument(&document);

		CSVGFilterOptionsDlg dlg;
		dlg.m_document = document;

		if (dlg.DoModal() == IDOK)
		{
			CComPtr<IOleUndoManager> undoManager;
			eDocument->get_undoManager(&undoManager);

			CComObject<CUndoParent>* pParentUndo;
			CComObject<CUndoParent>::CreateInstance(&pParentUndo);
			if (pParentUndo)
			{
				pParentUndo->AddRef();	// ???
				undoManager->Open(pParentUndo);

				CComPtr<ILSVGElement> svgDefsElement;
				m_document->FindOrCreateSVGDefs(&svgDefsElement);

				if (svgDefsElement)
				{
					CComPtr<ILSVGFilterElement> svgElement;
					document->createElementNS(L"http://www.w3.org/2000/svg", L"font", (ILDOMElement**)&svgElement);

					if (svgElement)
					{
						svgElement->setAttribute(L"id", dlg.m_id);

						CComObject<CWEUndoNewElement>* pUndo;
						CComObject<CWEUndoNewElement>::CreateInstance(&pUndo);
						if (pUndo)
						{
						//	pUndo->AddRef();
							pUndo->m_pDocument = static_cast<CEXMLDocument*>(m_document.p);

							pUndo->DoInitial(undoManager, svgElement, svgDefsElement, NULL);

							// TODO: do this here?
							CComPtr<IEXMLViewGroup> viewGroup;
							m_document->GetActiveViewGroup(&viewGroup);
							if (viewGroup)
							{
								CEXMLViewGroup* pViewGroup = static_cast<CEXMLViewGroup*>(viewGroup.p);

	//							CElementImpl* pElement = ((CEXMLDocument*)m_document.p)->m_pTree->FindDOMElement(svgFilterElement);
								CComPtr<IEElement> pElement;
								m_document->GetEElementFromDOMElement(svgElement, &pElement);

								pViewGroup->ActivateElement(pElement, 0, NULL);
							}
						}
					}
				}

				undoManager->Close(pParentUndo, TRUE/*commit*/);
			}
		}
	}

	return 0;
}
Ejemplo n.º 6
0
LRESULT CEditGradientDlg::OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
// Create default gradient
	if (m_viewGroup)
	{
		CComPtr<IEXMLDocument> eXMLDocument;
		m_viewGroup->get_eXMLDocument(&eXMLDocument);

		CComQIPtr<IEDocument> eDocument = eXMLDocument;

		CComPtr<ILDOMDocument> document;
		eXMLDocument->get_DOMDocument(&document);

//		CSVGFilterOptionsDlg dlg;
//		dlg.m_document = document;

//		if (dlg.DoModal(GetMainHwnd()) == IDOK)
		{
			CComPtr<IOleUndoManager> undoManager;
			eDocument->get_undoManager(&undoManager);

			CComObject<CUndoParent>* pParentUndo;
			CComObject<CUndoParent>::CreateInstance(&pParentUndo);
			if (pParentUndo)
			{
				pParentUndo->AddRef();	// ???
				undoManager->Open(pParentUndo);

				CComPtr<ILSVGElement> svgDefsElement;
				eXMLDocument->FindOrCreateSVGDefs(&svgDefsElement);

				if (svgDefsElement)
				{
					CComPtr<ILSVGElement> svgElement;
					document->createElementNS(L"http://www.w3.org/2000/svg", L"linearGradient", (ILDOMElement**)&svgElement);

					if (svgElement)
					{
						// TODO, create unique ID

						CComBSTR id = L"gradient";

						svgElement->setAttribute(L"id", id);
						svgElement->setAttribute(L"gradientUnits", L"userSpaceOnUse");
						svgElement->setAttribute(L"x1", L"0%");
						svgElement->setAttribute(L"y1", L"0%");
						svgElement->setAttribute(L"x2", L"100%");
						svgElement->setAttribute(L"y2", L"0%");

						// black
						{
							CComPtr<ILDOMElement> stop;
							document->createElementNS(L"http://www.w3.org/2000/svg", L"stop", &stop);
							stop->setAttribute(L"offset", L"0");
							stop->setAttribute(L"style", L"stop-color:#000000");

							svgElement->appendChild(stop, NULL);
						}

						// white
						{
							CComPtr<ILDOMElement> stop;
							document->createElementNS(L"http://www.w3.org/2000/svg", L"stop", &stop);
							stop->setAttribute(L"offset", L"1");
							stop->setAttribute(L"style", L"stop-color:#ffffff");

							svgElement->appendChild(stop, NULL);
						}

						CComObject<CWEUndoNewElement>* pUndo;
						CComObject<CWEUndoNewElement>::CreateInstance(&pUndo);
						if (pUndo)
						{
						//	pUndo->AddRef();
							pUndo->m_pDocument = static_cast<CEXMLDocument*>(eXMLDocument.p);

							pUndo->DoInitial(undoManager, svgElement, svgDefsElement, NULL);

							// TODO: do this here?
							CComPtr<IEXMLViewGroup> viewGroup;
							eXMLDocument->GetActiveViewGroup(&viewGroup);
							if (viewGroup)
							{
								//CWebXMLViewGroup* pViewGroup = static_cast<CWebXMLViewGroup*>(viewGroup.p);

								CComPtr<IEElement> pElement;
								eXMLDocument->GetEElementFromDOMElement(svgElement, &pElement);

								CComBSTR gradient;
								gradient = L"url(#";
								gradient += id;
								gradient += L")";

								if (SelectionCanHavePaint(viewGroup))
								{
#if 0
									CComPtr<ILCSSStyleDeclaration> style;
									viewGroup->GetCurrentSelectionCSSStyle(&style);
#endif

									ATLASSERT(0);
#if 0
									style->setProperty(gApp->m_strokeOrFill == 0? L"stroke": L"fill", gradient, NULL);
#endif

#if 0
									viewGroup->ApplyCurrentSelectionCSSStyle();
#endif
								}

							//
								static_cast<CEXMLDocument*>(eXMLDocument.p)->m_lastGradient = gradient;
							//

								viewGroup->ActivateElement(pElement, 0, NULL);
							}
						}
					}
				}

				undoManager->Close(pParentUndo, TRUE/*commit*/);
			}
		}
	}

	return 0;
}