void CEColorDlg::SetColorPicker(int nColorPicker) { if (m_nColorPicker != nColorPicker) { CComPtr<IUIDlg> colorDlg = CreateColorPicker(nColorPicker); if (colorDlg) { // Remove previous color picker if (m_colorDlg) { m_colorDlg->DestroyWindow(); m_colorDlg.Release(); } m_colorDlg = colorDlg; m_nColorPicker = nColorPicker; SetColorPickerColor(); OnSize(); } else { MessageBox("Failed to create color picker", "LXMLEditor", MB_OK | MB_ICONERROR); } } }
FReply FColorStructCustomization::OnOpenFullColorPickerClicked() { CreateColorPicker( /*bUseAlpha*/ true, /*bRefreshOnlyOnOk*/ false ); bIsInlineColorPickerVisible = false; return FReply::Handled(); }
LRESULT CEColorDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { GetDlgControl(IDC_COLOR_ALPHASLIDER, IID_IUISlider, (void**)&m_alphaSlider); IDispEventImpl<1, CEColorDlg, &DIID__IUISliderEvents, &LIBID_UILib, 1, 0>::DispEventAdvise(m_alphaSlider); m_alphaSlider->put_minValue(0); m_alphaSlider->put_maxValue(255); if (FALSE) { #if 0 CComPtr<IUnknown> spUnknown; ::CoCreateInstance(CLSID_LHTMLActiveDocument, NULL, CLSCTX_ALL, IID_IUnknown, (void**)&spUnknown); m_htmlActiveDoc = spUnknown; if (m_htmlActiveDoc) { CComQIPtr<IOleDocument> oleDocument = m_htmlActiveDoc; CComPtr<IOleDocumentView> oleView; oleDocument->CreateView(NULL,// *pIPSite, NULL,///* [unique][in] */ IStream __RPC_FAR *pstm, 0,///* [in] */ DWORD dwReserved, &oleView); m_htmlView = oleView; } #endif } m_fillrc = CRect(6, 6, 6+18, 6+18); m_strokerc = CRect(6+9, 6+9, 6+18+9, 6+18+9); m_colorDlg = CreateColorPicker(m_nColorPicker); OnSize(); // CComQIPtr<IUIActiveManager> uiActiveManager = m_app; // uiActiveManager->AddEventHandler(this); { #if 0 static_cast<CWebXMLViewGroup*>(m_viewGroup.p)->m_currentSelectionStyle->addHandler(this); #endif IDispEventImpl<7, CEColorDlg, &DIID__IEXMLViewGroupEvents, &LIBID_LXMLEDITORLib, 1, 0>::DispEventAdvise(m_viewGroup); /* CComPtr<ILCSSStyleDeclaration> style; m_viewGroup->GetCurrentSelectionCSSStyle(&style); style->addHandler(this); */ // IDispEventImpl<2, CSVGFiltersDlg, &DIID__IWebXMLDocumentEvents, &LIBID_WEBEDITORLib, 1, 0>::DispEventAdvise(m_document); OnColorChanged(); } return 0; }
FReply FReplaceVectorWithLinearColorBuilder::OnMouseButtonDownColorBlock(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, TSharedPtr<IPropertyHandle> StructHandle) { if (MouseEvent.GetEffectingButton() != EKeys::LeftMouseButton) { return FReply::Unhandled(); } CreateColorPicker(StructHandle); return FReply::Handled(); }
FReply FColorStructCustomization::OnMouseButtonDownColorBlock(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) { if ( MouseEvent.GetEffectingButton() != EKeys::LeftMouseButton ) { return FReply::Unhandled(); } CreateColorPicker( /*bUseAlpha*/ true, /*bRefreshOnlyOnOk*/ false ); //bIsInlineColorPickerVisible = !bIsInlineColorPickerVisible; return FReply::Handled(); }
bool CheckForHexColor(const HWND h_scintilla, const int start, const int end){ int len = end - start; // break - wrong length: fc6 ffcc66 if (len != 3 && len != 6) return false; char prev_char = (char)::SendMessage(h_scintilla, SCI_GETCHARAT, start - 1, 0); // break - no # mark if (prev_char == 0 || prev_char != '#') return false; char next_char = (char)::SendMessage(h_scintilla, SCI_GETCHARAT, end, 0); // break - next char is still hex char if (next_char != 0 && strchr("01234567890abcdefABCDEF", next_char) != NULL) return false; // passed - // create the color picker if not created if (!_pColorPicker) CreateColorPicker(); // get hex text - scintilla only accept char char hex_str[10]; ::SendMessage(h_scintilla, SCI_GETSELTEXT, 0, (LPARAM)&hex_str); wchar_t hex_color[20]; ::MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, hex_str, -1, hex_color, sizeof(hex_str)); // put current color to picker if (!_pColorPicker->SetHexColor(hex_color)) { // not a valid hex color string return false; } return true; }
bool CheckForRgbColor(const HWND h_scintilla, const int start, const int end){ int len = end - start; // break - wrong length: rgb rgba if (len != 3 && len != 4) return false; char next_char = (char)::SendMessage(h_scintilla, SCI_GETCHARAT, end, 0); // break - next char should be the open bracket if (next_char != '(') return false; int line = ::SendMessage(h_scintilla, SCI_LINEFROMPOSITION, end, 0); int line_end = ::SendMessage(h_scintilla, SCI_GETLINEENDPOSITION, line, 0); // get first close bracket position char close_bracket[] = ")"; ::SendMessage(h_scintilla, SCI_SETTARGETSTART, end, 0); ::SendMessage(h_scintilla, SCI_SETTARGETEND, line_end, 0); ::SendMessage(h_scintilla, SCI_SETSEARCHFLAGS, 0, 0); ::SendMessage(h_scintilla, SCI_SEARCHANCHOR, 0, 0); int close_pos = ::SendMessage(h_scintilla, SCI_SEARCHINTARGET, strlen(close_bracket), (LPARAM)close_bracket); // no close bracket if(close_pos == -1) return false; // only match the first 3 values char regexp[] = "(?i:rgb\\(|rgba\\()([0-9]{1,3})(?:[ ]*,[ ]*)([0-9]{1,3})(?:[ ]*,[ ]*)([0-9]{1,3})(?:[ ]*)"; ::SendMessage(h_scintilla, SCI_SETTARGETSTART, start, 0); ::SendMessage(h_scintilla, SCI_SETTARGETEND, close_pos+1, 0); ::SendMessage(h_scintilla, SCI_SETSEARCHFLAGS, SCFIND_REGEXP, 0); ::SendMessage(h_scintilla, SCI_SEARCHANCHOR, 0, 0); int target_pos = ::SendMessage(h_scintilla, SCI_SEARCHINTARGET, strlen(regexp), (LPARAM)regexp); // no match if(target_pos == -1) return false; char r[6], g[6], b[6]; ::SendMessage(h_scintilla, SCI_GETTAG, 1, (LPARAM)&r); ::SendMessage(h_scintilla, SCI_GETTAG, 2, (LPARAM)&g); ::SendMessage(h_scintilla, SCI_GETTAG, 3, (LPARAM)&b); int ir = strtol(r, NULL, 10); int ig = strtol(g, NULL, 10); int ib = strtol(b, NULL, 10); // invalid color value if(ir>255 || ig>255 || ib>255) return false; // passed - COLORREF color = RGB(ir, ig, ib); // prepare seletion range for replacement _rgb_start = end + 1; _rgb_end = ::SendMessage(h_scintilla, SCI_GETTARGETEND, 0, 0); // create the color picker if not created if (!_pColorPicker) CreateColorPicker(); // put current color to picker _pColorPicker->Color(color); return true; }