diff --git a/uppsrc/CtrlCore/CtrlClip.cpp b/uppsrc/CtrlCore/CtrlClip.cpp index ac4424707..1a9650b59 100644 --- a/uppsrc/CtrlCore/CtrlClip.cpp +++ b/uppsrc/CtrlCore/CtrlClip.cpp @@ -57,6 +57,14 @@ bool PasteClip::Accept() return paste; } +bool PasteClip::IsAnyAvailable(const char *fmt) const +{ + for(String f : Split(fmt, ';')) + if(IsAvailable(f)) + return true; + return false; +} + bool PasteClip::Accept(const char *_fmt) { Vector f = Split(_fmt, ';'); diff --git a/uppsrc/CtrlCore/CtrlCore.h b/uppsrc/CtrlCore/CtrlCore.h index e82fcd9f6..d43d6fab6 100644 --- a/uppsrc/CtrlCore/CtrlCore.h +++ b/uppsrc/CtrlCore/CtrlCore.h @@ -71,8 +71,6 @@ public: ~GuiUnlock() { EnterGuiMutex(n); } }; -bool ScreenInPaletteMode(); // Deprecated - typedef ImageDraw SystemImageDraw; void SetSurface(Draw& w, const Rect& dest, const RGBA *pixels, Size srcsz, Point poff); @@ -297,6 +295,7 @@ class PasteClip { public: bool IsAvailable(const char *fmt) const; + bool IsAnyAvailable(const char *fmt) const; String Get(const char *fmt) const; bool Accept(); @@ -335,6 +334,7 @@ void Append(VectorMap& data, const String& text); void Append(VectorMap& data, const WString& text); const char *ClipFmtsImage(); +inline bool IsAvailableImage(PasteClip& clip) { return clip.IsAnyAvailable(ClipFmtsImage()); } bool AcceptImage(PasteClip& clip); Image GetImage(PasteClip& clip); String GetImageClip(const Image& m, const String& fmt); @@ -1828,6 +1828,7 @@ inline T ReadClipboardFormat() { return object; } +bool IsClipboardAvailableImage(); Image ReadClipboardImage(); void AppendClipboardImage(const Image& img); diff --git a/uppsrc/CtrlCore/DrawWin32.cpp b/uppsrc/CtrlCore/DrawWin32.cpp index 4ff32563e..da86a67de 100644 --- a/uppsrc/CtrlCore/DrawWin32.cpp +++ b/uppsrc/CtrlCore/DrawWin32.cpp @@ -33,36 +33,6 @@ Size SystemDraw::GetNativeDpi() const return nativeDpi; } -#ifndef PLATFORM_WINCE -void Add(LOGPALETTE *pal, int r, int g, int b) -{ - pal->palPalEntry[pal->palNumEntries].peRed = min(r, 255); - pal->palPalEntry[pal->palNumEntries].peGreen = min(g, 255); - pal->palPalEntry[pal->palNumEntries].peBlue = min(b, 255); - pal->palPalEntry[pal->palNumEntries++].peFlags = PC_NOCOLLAPSE; -} - -HPALETTE GetQlibPalette() -{ - static HPALETTE hQlibPalette; - if(hQlibPalette) return hQlibPalette; - SystemDraw::InitColors(); - LOGPALETTE *pal = (LOGPALETTE *) new byte[sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)]; - pal->palNumEntries = 0; - pal->palVersion = 0x300; - for(int r = 0; r < 6; r++) - for(int g = 0; g < 6; g++) - for(int b = 0; b < 6; b++) - Add(pal, 255 * r / 5, 255 * g / 5, 255 * b / 5); - for(int q = 0; q <= 16; q++) - Add(pal, 16 * q, 16 * q, 16 * q); - Add(pal, GetRValue(sLightGray), GetGValue(sLightGray), GetBValue(sLightGray)); - hQlibPalette = CreatePalette(pal); - delete[] pal; - return hQlibPalette; -} -#endif - SystemDraw& ScreenInfo() { static ScreenDraw sd(true); @@ -78,43 +48,9 @@ HDC ScreenHDC() return hdc; } -static bool _AutoPalette = true; -bool SystemDraw::AutoPalette() { return _AutoPalette; } -void SystemDraw::SetAutoPalette(bool ap) { _AutoPalette = ap; } - COLORREF SystemDraw::GetColor(Color c) const { COLORREF color = c; -#ifdef PLATFORM_WINCE return color; -#else - if(!palette) - return color; - static Index *SColor; - ONCELOCK { - static Index StaticColor; - StaticColor << RGB(0x00, 0x00, 0x00) << RGB(0x80, 0x00, 0x00) << RGB(0x00, 0x80, 0x00) - << RGB(0x80, 0x80, 0x00) << RGB(0x00, 0x00, 0x80) << RGB(0x80, 0x00, 0x80) - << RGB(0x00, 0x80, 0x80) << RGB(0xC0, 0xC0, 0xC0) << RGB(0xC0, 0xDC, 0xC0) - << RGB(0xA6, 0xCA, 0xF0) << RGB(0xFF, 0xFB, 0xF0) << RGB(0xA0, 0xA0, 0xA4) - << RGB(0x80, 0x80, 0x80) << RGB(0xFF, 0x00, 0x00) << RGB(0x00, 0xFF, 0x00) - << RGB(0xFF, 0xFF, 0x00) << RGB(0x00, 0x00, 0xFF) << RGB(0xFF, 0x00, 0xFF) - << RGB(0x00, 0xFF, 0xFF) << RGB(0xFF, 0xFF, 0xFF); - SColor = &StaticColor; - } - if(color16 || !AutoPalette()) - return GetNearestColor(handle, color); - if(SColor->Find(color) >= 0) - return color; - if(color == sLightGray) - return PALETTEINDEX(216 + 17); - int r = GetRValue(color); - int g = GetGValue(color); - int b = GetBValue(color); - return PALETTEINDEX(r == g && g == b ? (r + 8) / 16 + 216 - : (r + 25) / 51 * 36 + - (g + 25) / 51 * 6 + - (b + 25) / 51); -#endif } void SystemDraw::InitColors() @@ -368,12 +304,6 @@ void BackDraw::Create(SystemDraw& w, int cx, int cy) { dcMem = ::CreateCompatibleDC(handle); ASSERT(hbmp); ASSERT(handle); -#ifndef PLATFORM_WINCE - if(AutoPalette()) { - ::SelectPalette(handle, GetQlibPalette(), FALSE); - ::RealizePalette(handle); - } -#endif hbmpold = (HBITMAP) ::SelectObject(handle, hbmp); Init(); InitClip(size); @@ -406,16 +336,8 @@ void BackDraw::Destroy() { ScreenDraw::ScreenDraw(bool ic) { GuiLock __; -#ifdef PLATFORM_WINCE - Attach(CreateDC(NULL, NULL, NULL, NULL)); -#else Attach(ic ? CreateIC("DISPLAY", NULL, NULL, NULL) : CreateDC("DISPLAY", NULL, NULL, NULL)); InitClip(GetVirtualScreenArea()); - if(AutoPalette()) { - SelectPalette(handle, GetQlibPalette(), TRUE); - RealizePalette(handle); - } -#endif } ScreenDraw::~ScreenDraw() { diff --git a/uppsrc/CtrlCore/UtilWin32.cpp b/uppsrc/CtrlCore/UtilWin32.cpp index 6daead016..8c0d5d79c 100644 --- a/uppsrc/CtrlCore/UtilWin32.cpp +++ b/uppsrc/CtrlCore/UtilWin32.cpp @@ -6,11 +6,6 @@ namespace Upp { SystemDraw& ScreenInfo(); -bool ScreenInPaletteMode() -{ - return ScreenInfo().PaletteMode(); -} - } #endif diff --git a/uppsrc/CtrlCore/Win32Clip.cpp b/uppsrc/CtrlCore/Win32Clip.cpp index d0818db09..f5290c516 100644 --- a/uppsrc/CtrlCore/Win32Clip.cpp +++ b/uppsrc/CtrlCore/Win32Clip.cpp @@ -391,6 +391,13 @@ Image GetImage(PasteClip& clip) return Null; } +bool IsClipboardAvailableImage() +{ + GuiLock __; + PasteClip d = Ctrl::Clipboard(); + return IsAvailableImage(d); +} + Image ReadClipboardImage() { GuiLock __; diff --git a/uppsrc/CtrlCore/Win32Gui.h b/uppsrc/CtrlCore/Win32Gui.h index 21e57eb9a..57cc8769a 100644 --- a/uppsrc/CtrlCore/Win32Gui.h +++ b/uppsrc/CtrlCore/Win32Gui.h @@ -105,10 +105,6 @@ protected: public: static Rect GetVirtualScreenArea(); - static void SetAutoPalette(bool ap); - static bool AutoPalette(); - bool PaletteMode() { return palette; } - static void Flush() { GdiFlush(); } static Image Win32IconCursor(LPCSTR id, int iconsize, bool cursor); @@ -258,7 +254,6 @@ inline void DrawEllipse(HDC hdc, const Rect& rc) { Ellipse(hdc, inline void DrawRect(HDC hdc, const Rect& rc) { Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom); } HDC ScreenHDC(); -HPALETTE GetQlibPalette(); Image Win32Icon(LPCSTR id, int iconsize = 0); Image Win32Icon(int id, int iconsize = 0); diff --git a/uppsrc/CtrlCore/Win32Proc.cpp b/uppsrc/CtrlCore/Win32Proc.cpp index 487f48509..578ea775a 100644 --- a/uppsrc/CtrlCore/Win32Proc.cpp +++ b/uppsrc/CtrlCore/Win32Proc.cpp @@ -401,22 +401,6 @@ LRESULT Ctrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { } } break; - case WM_PALETTECHANGED: - if((HWND)wParam == hwnd) - break; - case WM_QUERYNEWPALETTE: - if(!SystemDraw::AutoPalette()) break; - { - HDC hDC = GetDC(hwnd); - HPALETTE hOldPal = SelectPalette(hDC, GetQlibPalette(), FALSE); - int i = RealizePalette(hDC); - SelectPalette(hDC, hOldPal, TRUE); - RealizePalette(hDC); - ReleaseDC(hwnd, hDC); - LLOG("Realized " << i << " colors"); - if(i) InvalidateRect(hwnd, NULL, TRUE); - return i; - } case WM_ERASEBKGND: if(erasebg) { HDC hdc = (HDC)(wParam); @@ -440,15 +424,8 @@ LRESULT Ctrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { if(IsVisible()) { SystemDraw draw(dc); HPALETTE hOldPal; - if(draw.PaletteMode() && SystemDraw::AutoPalette()) { - hOldPal = SelectPalette(dc, GetQlibPalette(), TRUE); - int n = RealizePalette(dc); - LLOG("In paint realized " << n << " colors"); - } painting = true; UpdateArea(draw, Rect(ps.rcPaint)); - if(draw.PaletteMode() && SystemDraw::AutoPalette()) - SelectPalette(dc, hOldPal, TRUE); painting = false; } EndPaint(hwnd, &ps); diff --git a/uppsrc/CtrlCore/src.tpp/PasteClipUtil_en-us.tpp b/uppsrc/CtrlCore/src.tpp/PasteClipUtil_en-us.tpp index e61c81705..1916d1c37 100644 --- a/uppsrc/CtrlCore/src.tpp/PasteClipUtil_en-us.tpp +++ b/uppsrc/CtrlCore/src.tpp/PasteClipUtil_en-us.tpp @@ -1,5 +1,4 @@ topic "PasteClip basic formats support functions"; -[2 $$0,0#00000000000000000000000000000000:Default] [i448;a25;kKO9;2 $$1,0#37138531426314131252341829483380:class] [l288;2 $$2,2#27521748481378242620020725143825:desc] [0 $$3,0#96390100711032703541132217272105:end] @@ -9,6 +8,7 @@ topic "PasteClip basic formats support functions"; [l288;i1121;b17;O9;~~~.1408;2 $$7,0#10431211400427159095818037425705:param] [i448;b42;O9;2 $$8,8#61672508125594000341940100500538:tparam] [b42;2 $$9,9#13035079074754324216151401829390:normal] +[2 $$0,0#00000000000000000000000000000000:Default] [{_} [ {{10000@(113.42.0) [s0;%% [*@7;4 PasteClip basic formats support functions.]]}}&] [s3; &] @@ -52,6 +52,11 @@ end]([_^VectorMap^ VectorMap]<[_^String^ String], [_^ClipData^ ClipData]>`&_[*@3 format ids associated with raster images.&] [s3; &] [s4; &] +[s5;:Upp`:`:IsAvailableImage`(PasteClip`&`): [@(0.0.255) bool] [* IsAvailableImage](Paste +Clip[@(0.0.255) `&] [*@3 clip])&] +[s2;%% Returns true if [%-*@3 clip] contains an raster image.&] +[s3; &] +[s4; &] [s5;:AcceptImage`(PasteClip`&`): [@(0.0.255) bool]_[* AcceptImage]([_^PasteClip^ PasteClip][@(0.0.255) `& ]_[*@3 clip])&] [s2;%% Accepts [%-*@3 clip] if it contains an raster image (returns diff --git a/uppsrc/CtrlCore/src.tpp/PasteClip_en-us.tpp b/uppsrc/CtrlCore/src.tpp/PasteClip_en-us.tpp index 629f65794..388c68754 100644 --- a/uppsrc/CtrlCore/src.tpp/PasteClip_en-us.tpp +++ b/uppsrc/CtrlCore/src.tpp/PasteClip_en-us.tpp @@ -73,6 +73,14 @@ onst]_[@(0.0.255) char]_`*[*@3 fmt])_[@(0.0.255) const]&] [s2;%% Returns true when data source offers data in format [%-*@3 fmt].&] [s3;%% &] [s4; &] +[s5;:Upp`:`:PasteClip`:`:IsAnyAvailable`(const char`*`)const: [@(0.0.255) bool] +[* IsAnyAvailable]([@(0.0.255) const] [@(0.0.255) char] [@(0.0.255) `*][*@3 fmt]) +[@(0.0.255) const]&] +[s2;%% Parameter [%-*@3 fmt] contains a list of format identifiers +separated by semicolon. If any of them is available in the PasteClip, +function returns true.&] +[s3; &] +[s4; &] [s5;:PasteClip`:`:Get`(const char`*`)const: [_^String^ String]_[* Get]([@(0.0.255) const]_[@(0.0.255) c har]_`*[*@3 fmt])_[@(0.0.255) const]&] [s2;%% Returns binary data rendered in [%-*@3 fmt].&] diff --git a/uppsrc/RichEdit/Bar.cpp b/uppsrc/RichEdit/Bar.cpp index 9f39f66e6..55ddd286b 100644 --- a/uppsrc/RichEdit/Bar.cpp +++ b/uppsrc/RichEdit/Bar.cpp @@ -18,7 +18,7 @@ void DiagramEditor::TheBar(Bar& bar) bar.Add(b, "Copy", CtrlImg::copy(), [=] { Copy(); }) .Key(K_CTRL_INSERT) .Key(K_CTRL_C); - bar.Add(IsClipboardAvailableText() || IsClipboardAvailable("dib"), "Paste", CtrlImg::paste(), [=] { Paste(); }) + bar.Add(IsClipboardAvailableText() || IsClipboardAvailableImage(), "Paste", CtrlImg::paste(), [=] { Paste(); }) .Key(K_SHIFT_INSERT) .Key(K_CTRL_V); bar.Add(b, "Delete", CtrlImg::remove(), [=] { Delete(); }) diff --git a/upptst/IsClipboardAvailable/IsClipboardAvailable.upp b/upptst/IsClipboardAvailable/IsClipboardAvailable.upp new file mode 100644 index 000000000..5872304d3 --- /dev/null +++ b/upptst/IsClipboardAvailable/IsClipboardAvailable.upp @@ -0,0 +1,9 @@ +uses + CtrlLib; + +file + main.cpp; + +mainconfig + "" = "GUI"; + diff --git a/upptst/IsClipboardAvailable/main.cpp b/upptst/IsClipboardAvailable/main.cpp new file mode 100644 index 000000000..7c22fa6c5 --- /dev/null +++ b/upptst/IsClipboardAvailable/main.cpp @@ -0,0 +1,26 @@ +#include + +using namespace Upp; + +struct MyApp : TopWindow { + TimeCallback tm; + + void Paint(Draw& w) override { + w.DrawRect(GetSize(), SColorPaper()); + if(IsClipboardAvailableImage()) + w.DrawText(0, 0, "IMAGE"); + if(IsClipboardAvailableText()) + w.DrawText(0, 50, "TEXT"); + if(IsAvailableFiles(Ctrl::Clipboard())) + w.DrawText(0, 100, "FILES"); + } + + MyApp() { + tm.Set(-200, [=] { Refresh(); }); + } +}; + +GUI_APP_MAIN +{ + MyApp().Run(); +}