From af893ea2ce3f450d666c4e1d81ef4f35c0b2585d Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 13 Jun 2011 12:42:24 +0000 Subject: [PATCH] .developing rainbow git-svn-id: svn://ultimatepp.org/upp/trunk@3525 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CtrlCore/CtrlCore.h | 14 +- uppsrc/CtrlCore/Win32Ctrl.cpp | 12 + uppsrc/CtrlCore/X11Ctrl.cpp | 296 +++++---- uppsrc/CtrlLib/Ch.cpp | 3 +- uppsrc/CtrlLib/ChGtk.cpp | 2 +- uppsrc/CtrlLib/ChGtk.h | 2 +- uppsrc/CtrlLib/ChGtk0.cpp | 1060 +++++++++++++++--------------- uppsrc/CtrlLib/ChWin32.cpp | 2 +- uppsrc/CtrlLib/CtrlLib.icpp | 6 + uppsrc/CtrlLib/CtrlUtil.h | 12 +- uppsrc/CtrlLib/DlgColor.cpp | 10 +- uppsrc/CtrlLib/FileSel.cpp | 43 +- uppsrc/CtrlLib/MenuBar.cpp | 5 +- uppsrc/CtrlLib/PrinterJob.cpp | 6 +- uppsrc/CtrlLib/TrayIconWin32.cpp | 4 +- uppsrc/CtrlLib/TrayIconX11.cpp | 2 +- 16 files changed, 755 insertions(+), 724 deletions(-) diff --git a/uppsrc/CtrlCore/CtrlCore.h b/uppsrc/CtrlCore/CtrlCore.h index efbb99b54..1941d720b 100644 --- a/uppsrc/CtrlCore/CtrlCore.h +++ b/uppsrc/CtrlCore/CtrlCore.h @@ -3,14 +3,22 @@ #include +#include + +#ifndef GUIPLATFORM_INCLUDE + #ifdef PLATFORM_WIN32 -#include "Win32Gui.h" +#define GUIPLATFORM_INCLUDE "Win32Gui.h" #endif #ifdef PLATFORM_X11 -#include "X11Gui.h" +#define GUIPLATFORM_INCLUDE "X11Gui.h" #endif +#endif + +#include GUIPLATFORM_INCLUDE + NAMESPACE_UPP #ifdef _MULTITHREADED @@ -1215,6 +1223,8 @@ public: String GuiPlatformGetKeyDesc(dword key); bool GuiPlatformHasSizeGrip(); void GuiPlatformGripResize(TopWindow *q); +Color GuiPlatformGetScreenPixel(int x, int y); +void GuiPlatformAfterMenuPopUp(); Font FontZ(int face, int height = 0); diff --git a/uppsrc/CtrlCore/Win32Ctrl.cpp b/uppsrc/CtrlCore/Win32Ctrl.cpp index ed30af026..41bfa871d 100644 --- a/uppsrc/CtrlCore/Win32Ctrl.cpp +++ b/uppsrc/CtrlCore/Win32Ctrl.cpp @@ -85,6 +85,18 @@ void GuiPlatformGripResize(TopWindow *q) } } +Color GuiPlatformGetScreenPixel(int x, int y) +{ + HDC sdc = GetWindowDC(0); + Color c = Color::FromCR(GetPixel(sdc, x, y)); + ReleaseDC(0, sdc); + return c; +} + +void GuiPlatformAfterMenuPopUp() +{ +} + void Ctrl::SetCaret(int x, int y, int cx, int cy) { GuiLock __; diff --git a/uppsrc/CtrlCore/X11Ctrl.cpp b/uppsrc/CtrlCore/X11Ctrl.cpp index 44794f18a..b6de81321 100644 --- a/uppsrc/CtrlCore/X11Ctrl.cpp +++ b/uppsrc/CtrlCore/X11Ctrl.cpp @@ -1,143 +1,155 @@ -#include "CtrlCore.h" - -#ifdef GUI_X11 - -NAMESPACE_UPP - -void Ctrl::GuiPlatformConstruct() -{ -} - -void Ctrl::GuiPlatformDestruct() -{ -} - -void Ctrl::GuiPlatformRemove() -{ - if(popupgrab) { - EndPopupGrab(); - popupgrab = false; - } -} - -void Ctrl::GuiPlatformGetTopRect(Rect& r) const -{ -} - -String Ctrl::Name() const { - GuiLock __; -#ifdef CPU_64 - String s = String(typeid(*this).name()) + " : 0x" + FormatIntHex(this); -#else - String s = String(typeid(*this).name()) + " : " + Format("0x%x", (int) this); -#endif - if(IsChild()) - s << "(parent " << String(typeid(*parent).name()) << ")"; - else - s << Format("(window 0x%x)", (int)(intptr_t) GetWindow()); - return s; -} - -bool Ctrl::GuiPlatformRefreshFrameSpecial(const Rect&) -{ - return false; -} - - -bool Ctrl::GuiPlatformSetFullRefreshSpecial() -{ - return false; -} - -String GuiPlatformGetKeyDesc(dword key) -{ - static struct { - dword key; - const char *name; - } nkey[] = { - { 0x10060, "[`]" }, { 0x1002d, "[-]" }, { 0x1003d, "[=]" }, { 0x1005c, "[\\]" }, - { 0x1005b, "[[]" }, { 0x1005d, "[]]" }, - { 0x1003b, "[;]" }, { 0x10027, "[']" }, - { 0x1002c, "[,]" }, { 0x1002e, "[.]" }, { 0x1005f, "[/]" }, - { 0, NULL } - }; - for(int i = 0; nkey[i].key; i++) - if(nkey[i].key == key) - return nkey[i].name; - return Null; -} - -void Ctrl::GuiPlatformSelection(PasteClip& d) -{ - d.fmt.Clear(); - d.type = 2; -} - -void GuiPlatformAdjustDragImage(ImageBuffer& b) -{ - if(Ctrl::IsCompositedGui()) { - Image h = Rescale(b, 64, 64); - b = h; - } -} - -bool GuiPlatformHasSizeGrip() -{ - return _NET_Supported().Find(XAtom("_NET_WM_MOVERESIZE")) >= 0; -} - -void GuiPlatformGripResize(TopWindow *q) -{ - if(_NET_Supported().Find(XAtom("_NET_WM_MOVERESIZE")) >= 0) { - XUngrabPointer(Xdisplay, CurrentTime); // 2008-02-25 cxl/mdelfe... compiz fix... who has grabbed it anyway?... - XClientMessageEvent m; - m.type = ClientMessage; - m.serial = 0; - m.send_event = XTrue; - m.window = q->GetWindow(); - m.message_type = XAtom("_NET_WM_MOVERESIZE"); - m.format = 32; - Point p = GetMousePos(); - m.data.l[0] = p.x; - m.data.l[1] = p.y; - m.data.l[2] = 4; - m.data.l[3] = 0; - m.data.l[4] = 0; - XSendEvent(Xdisplay, Xroot, 0, SubstructureNotifyMask|SubstructureRedirectMask, - (XEvent*)&m); - } -} - -void Ctrl::PaintCaret(SystemDraw& w) -{ - GuiLock __; - if(this == caretCtrl && WndCaretVisible) - w.DrawRect(caretx, carety, caretcx, caretcy, InvertColor); -} - -void Ctrl::SetCaret(int x, int y, int cx, int cy) -{ - GuiLock __; - if(this == caretCtrl) - RefreshCaret(); - caretx = x; - carety = y; - caretcx = cx; - caretcy = cy; - WndCaretTime = GetTickCount(); - if(this == caretCtrl) - RefreshCaret(); -} - -void Ctrl::SyncCaret() { - GuiLock __; - if(focusCtrl != caretCtrl) { - RefreshCaret(); - caretCtrl = focusCtrl; - RefreshCaret(); - } -} - -END_UPP_NAMESPACE - +#include "CtrlCore.h" + +#ifdef GUI_X11 + +NAMESPACE_UPP + +void Ctrl::GuiPlatformConstruct() +{ +} + +void Ctrl::GuiPlatformDestruct() +{ +} + +void Ctrl::GuiPlatformRemove() +{ + if(popupgrab) { + EndPopupGrab(); + popupgrab = false; + } +} + +void Ctrl::GuiPlatformGetTopRect(Rect& r) const +{ +} + +String Ctrl::Name() const { + GuiLock __; +#ifdef CPU_64 + String s = String(typeid(*this).name()) + " : 0x" + FormatIntHex(this); +#else + String s = String(typeid(*this).name()) + " : " + Format("0x%x", (int) this); +#endif + if(IsChild()) + s << "(parent " << String(typeid(*parent).name()) << ")"; + else + s << Format("(window 0x%x)", (int)(intptr_t) GetWindow()); + return s; +} + +bool Ctrl::GuiPlatformRefreshFrameSpecial(const Rect&) +{ + return false; +} + + +bool Ctrl::GuiPlatformSetFullRefreshSpecial() +{ + return false; +} + +String GuiPlatformGetKeyDesc(dword key) +{ + static struct { + dword key; + const char *name; + } nkey[] = { + { 0x10060, "[`]" }, { 0x1002d, "[-]" }, { 0x1003d, "[=]" }, { 0x1005c, "[\\]" }, + { 0x1005b, "[[]" }, { 0x1005d, "[]]" }, + { 0x1003b, "[;]" }, { 0x10027, "[']" }, + { 0x1002c, "[,]" }, { 0x1002e, "[.]" }, { 0x1005f, "[/]" }, + { 0, NULL } + }; + for(int i = 0; nkey[i].key; i++) + if(nkey[i].key == key) + return nkey[i].name; + return Null; +} + +void Ctrl::GuiPlatformSelection(PasteClip& d) +{ + d.fmt.Clear(); + d.type = 2; +} + +void GuiPlatformAdjustDragImage(ImageBuffer& b) +{ + if(Ctrl::IsCompositedGui()) { + Image h = Rescale(b, 64, 64); + b = h; + } +} + +bool GuiPlatformHasSizeGrip() +{ + return _NET_Supported().Find(XAtom("_NET_WM_MOVERESIZE")) >= 0; +} + +void GuiPlatformGripResize(TopWindow *q) +{ + if(_NET_Supported().Find(XAtom("_NET_WM_MOVERESIZE")) >= 0) { + XUngrabPointer(Xdisplay, CurrentTime); // 2008-02-25 cxl/mdelfe... compiz fix... who has grabbed it anyway?... + XClientMessageEvent m; + m.type = ClientMessage; + m.serial = 0; + m.send_event = XTrue; + m.window = q->GetWindow(); + m.message_type = XAtom("_NET_WM_MOVERESIZE"); + m.format = 32; + p = GetMousePos(); + m.data.l[0] = p.x; + m.data.l[1] = p.y; + m.data.l[2] = 4; + m.data.l[3] = 0; + m.data.l[4] = 0; + XSendEvent(Xdisplay, Xroot, 0, SubstructureNotifyMask|SubstructureRedirectMask, + (XEvent*)&m); + } +} + +Color GuiPlatformGetScreenPixel(int x, int y) +{ + // TODO + return Black; +} + +void GuiPlatformAfterMenuPopUp() +{ + XSync(Xdisplay, false); + ProcessEvents(); +} + +void Ctrl::PaintCaret(SystemDraw& w) +{ + GuiLock __; + if(this == caretCtrl && WndCaretVisible) + w.DrawRect(caretx, carety, caretcx, caretcy, InvertColor); +} + +void Ctrl::SetCaret(int x, int y, int cx, int cy) +{ + GuiLock __; + if(this == caretCtrl) + RefreshCaret(); + caretx = x; + carety = y; + caretcx = cx; + caretcy = cy; + WndCaretTime = GetTickCount(); + if(this == caretCtrl) + RefreshCaret(); +} + +void Ctrl::SyncCaret() { + GuiLock __; + if(focusCtrl != caretCtrl) { + RefreshCaret(); + caretCtrl = focusCtrl; + RefreshCaret(); + } +} + +END_UPP_NAMESPACE + #endif \ No newline at end of file diff --git a/uppsrc/CtrlLib/Ch.cpp b/uppsrc/CtrlLib/Ch.cpp index 608216780..bca3c1355 100644 --- a/uppsrc/CtrlLib/Ch.cpp +++ b/uppsrc/CtrlLib/Ch.cpp @@ -1,6 +1,5 @@ #include "CtrlLib.h" - NAMESPACE_UPP #define LLOG(x) // RLOG(x) @@ -77,7 +76,7 @@ void ChClassicSkin() LabelBoxTextColor_Write(SColorText()); } -#ifdef PLATFORM_X11 +#ifdef GUI_X11 void ChSysInit() { diff --git a/uppsrc/CtrlLib/ChGtk.cpp b/uppsrc/CtrlLib/ChGtk.cpp index 3241b5b5b..18b3e3762 100644 --- a/uppsrc/CtrlLib/ChGtk.cpp +++ b/uppsrc/CtrlLib/ChGtk.cpp @@ -1,7 +1,7 @@ #include "CtrlLib.h" #include "ChGtk.h" -#ifdef PLATFORM_X11 +#ifdef GUI_X11 #ifndef flagNOGTK NAMESPACE_UPP diff --git a/uppsrc/CtrlLib/ChGtk.h b/uppsrc/CtrlLib/ChGtk.h index bbc62e604..655b1f450 100644 --- a/uppsrc/CtrlLib/ChGtk.h +++ b/uppsrc/CtrlLib/ChGtk.h @@ -1,4 +1,4 @@ -#ifdef PLATFORM_X11 +#ifdef GUI_X11 #define Time XTime #define Font XFont diff --git a/uppsrc/CtrlLib/ChGtk0.cpp b/uppsrc/CtrlLib/ChGtk0.cpp index bb3667a8f..0cda909bf 100644 --- a/uppsrc/CtrlLib/ChGtk0.cpp +++ b/uppsrc/CtrlLib/ChGtk0.cpp @@ -1,530 +1,530 @@ -#include "CtrlLib.h" - -#ifdef PLATFORM_X11 -#ifdef flagNOGTK - -NAMESPACE_UPP - -void ChHostSkin() {} - -END_UPP_NAMESPACE - -#else - -#include "ChGtk.h" - -NAMESPACE_UPP - -#if defined(_DEBUG)// && 0 -#include - -void LOGPNG(const Image& m) -{ - static int i; - PNGEncoder png; - png.SaveFile(ConfigFile(AsString(i++) + ".png"), m); -} - -#else - -#define LOGPNG(a) - -#endif - -GtkWidget *gtk__parent() -{ - static GtkWidget *p; - if(!p) { - p = gtk_window_new(GTK_WINDOW_POPUP); - gtk_widget_realize(p); - } - return p; -} - -GtkWidget *Setup(GtkWidget *widget) -{ - static GtkWidget *fl; - if (!fl) { - fl = gtk_fixed_new(); - gtk_container_add(GTK_CONTAINER(gtk__parent()), fl); - gtk_widget_realize(fl); - } - - gtk_fixed_put(GTK_FIXED(fl), widget, 0, 0); - gtk_widget_realize(widget); - gtk_widget_show(widget); - return widget; -} - -static Image sLastImage; - -Image GtkGetLastImage() -{ - return sLastImage; -} - -void (*chgtkspy__)(const char *name, int state, int shadow, const char *detail, int type, int cx, int cy, const Value& look); - -void SetChGtkSpy_(void (*spy)(const char *name, int state, int shadow, const char *detail, int type, int cx, int cy, const Value& look)) -{ - chgtkspy__ = spy; -} - -Image GetGTK(GtkWidget *widget, int state, int shadow, const char *detail, int type, int cx, int cy) -{ - MemoryIgnoreLeaksBlock __; - GdkPixbuf *icon; - if(type == GTK_ICON || type == GTK_THEMEICON) { - gtk_widget_set_sensitive(widget, 1); - gtk_widget_set_state(widget, GTK_STATE_NORMAL); - if(type == GTK_THEMEICON) - icon = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), detail, - (GtkIconSize)state, (GtkIconLookupFlags)0, NULL); - else - icon = gtk_widget_render_icon(widget, detail, (GtkIconSize)state, NULL); - if(!icon) return Null; - cx = gdk_pixbuf_get_width(icon); - cy = gdk_pixbuf_get_height(icon); - } - else { - gtk_widget_set_sensitive(widget, state != 4); - gtk_widget_set_state(widget, (GtkStateType)state); - } - Rect rect; - int ht = type & 0xf000; - rect.top = ht == GTK_VCENTER ? cy : ht == GTK_BOTTOM ? 2 * cy : 0; - rect.left = ht == GTK_HCENTER ? cx : ht == GTK_RIGHT ? 2 * cx : 0; - rect.SetSize(cx, cy); - if(ht >= GTK_LEFT && ht <= GTK_RIGHT) - cx *= 3; - if(ht >= GTK_TOP && ht <= GTK_BOTTOM) - cy *= 3; - type &= ~0xf000; - if(GTK_IS_RANGE(widget)) { - GtkRange *r = GTK_RANGE(widget); - r->has_stepper_a = r->has_stepper_b = r->has_stepper_c = r->has_stepper_d = 1; - GdkRectangle cr; - cr.x = rect.left; - cr.y = rect.top; - cr.width = 0; - cr.height = 0; - GtkRangeLayout_ *rl = (GtkRangeLayout_ *)r->layout; - rl->stepper_a = rl->stepper_b = rl->stepper_c = rl->stepper_d = cr; - cr.width = rect.GetWidth(); - cr.height = rect.GetHeight(); - if(type & GTK_RANGEA) rl->stepper_a = cr; - if(type & GTK_RANGEB) rl->stepper_b = cr; - if(type & GTK_RANGEC) rl->stepper_c = cr; - if(type & GTK_RANGED) rl->stepper_d = cr; - } - GdkRectangle& allocation = widget->allocation; - allocation.x = 0; - allocation.y = 0; - allocation.width = cx; - allocation.height = cy; - Image m[2]; - Color back = White; - int margin = (type >> 4) & 7; - for(int i = 0; i < 2; i++) { - ImageDraw iw(cx + 2 * margin, cy + 2 * margin); - iw.DrawRect(0, 0, cx + 2 * margin, cy + 2 * margin, back); - static GdkColormap *cm = gdk_x11_colormap_foreign_new( - gdkx_visual_get(XVisualIDFromVisual(Xvisual)), Xcolormap); - GdkPixmap *pixmap = gdk_pixmap_foreign_new(iw.GetDrawable()); - gdk_drawable_set_colormap(pixmap, cm); - GdkRectangle cr; - cr.x = 0; - cr.y = 0; - cr.width = cx; - cr.height = cy; - GtkStyle *style = gtk_widget_get_style(widget); - int rcx = max(rect.GetWidth() - 2 * margin, 0); - int rcy = max(rect.GetHeight() - 2 * margin, 0); - int t1 = (type & 0xf00) >> 8; - switch(type & 15) { - case GTK_BGBOX: - gtk_style_apply_default_background(style, pixmap, TRUE, (GtkStateType)state, - &cr, rect.left + margin, rect.top + margin, rcx, rcy); - case GTK_BOX: - gtk_paint_box(style, pixmap, (GtkStateType)state, (GtkShadowType)shadow, &cr, - widget, detail, - rect.left + margin, rect.top + margin, rcx, rcy); - break; - case GTK_FLATBOX: - gtk_paint_flat_box(style, pixmap, (GtkStateType)state, (GtkShadowType)shadow, &cr, - widget, detail, - rect.left + margin, rect.top + margin, rcx, rcy); - break; - case GTK_CHECK: - gtk_paint_check(style, pixmap, (GtkStateType)state, (GtkShadowType)shadow, &cr, - widget, detail, - rect.left + margin, rect.top + margin, rcx, rcy); - break; - case GTK_OPTION: - gtk_paint_option(style, pixmap, (GtkStateType)state, (GtkShadowType)shadow, &cr, - widget, detail, - rect.left + margin, rect.top + margin, rcx, rcy); - break; - case GTK_ARROW: - gtk_paint_arrow(style, pixmap, (GtkStateType)state, (GtkShadowType)shadow, &cr, - widget, detail, (GtkArrowType)t1, 1, - rect.left + margin, rect.top + margin, rcx, rcy); - break; - case GTK_SLIDER: - gtk_paint_slider(style, pixmap, (GtkStateType)state, (GtkShadowType)shadow, &cr, - widget, detail, - rect.left + margin, rect.top + margin, rcx, rcy, - (GtkOrientation)t1); - break; - case GTK_ICON: - case GTK_THEMEICON: - gdk_draw_pixbuf(pixmap, NULL, icon, 0, 0, 0, 0, -1, -1, (GdkRgbDither)0, 0, 0); - break; - case GTK_EXT: - gtk_paint_extension(style, pixmap, (GtkStateType)state, (GtkShadowType)shadow, &cr, - widget, (gchar *)detail, - rect.left + margin, rect.top + margin, rcx, rcy, - (GtkPositionType)t1); - break; - case GTK_SHADOW: - gtk_paint_shadow(style, pixmap, (GtkStateType)state, (GtkShadowType)shadow, &cr, - widget, (gchar *)detail, - rect.left + margin, rect.top + margin, rcx, rcy); - break; - case GTK_FOCUS: - gtk_paint_focus(style, pixmap, (GtkStateType)state, &cr, - widget, (gchar *)detail, - rect.left + margin, rect.top + margin, rcx, rcy); - break; - } - g_object_unref(pixmap); - m[i] = Crop(iw, rect.Inflated(margin)); - back = Black; - } - if(type == GTK_ICON) - g_object_unref(icon); - sLastImage = RecreateAlpha(m[0], m[1]); - if(chgtkspy__) - chgtkspy__(G_OBJECT_TYPE_NAME(widget), state, shadow, detail, type, cx, cy, sLastImage); - return sLastImage; -} - -Vector& ChGtkIs() -{ - static Vector x; - return x; -} - -GtkWidget *ChGtkLast() -{ - return ChGtkIs().Top().widget; -} - -const char *ChGtkLastDetail() -{ - return ChGtkIs().Top().detail; -} - -int ChGtkLastType() -{ - return ChGtkIs().Top().type; -} - -void ChGtkNew(GtkWidget *widget, const char *detail, int type) -{ - if(gtk_widget_get_parent(widget) == NULL) - Setup(widget); - ChGtkI& q = ChGtkIs().Add(); - q.widget = widget; - q.detail = detail; - q.type = type; -} - -void ChGtkNew(const char *detail, int type) -{ - ChGtkNew(ChGtkLast(), detail, type); -} - -struct GtkElement { - word gtki; - byte state; - byte shadow; - Rect reduce; - Rect margins; -}; - -struct GtkImageMaker : ImageMaker { - GtkElement e; - ChGtkI eg; - Size sz; - - virtual String Key() const { - StringBuffer key; - key.Cat((char *)&eg.widget, sizeof(eg.widget)); - key.Cat((char *)&eg.detail, sizeof(eg.detail)); - key.Cat((char *)&eg.type, sizeof(eg.type)); - key.Cat((char *)&e.gtki, sizeof(e.gtki)); - key.Cat((char *)&e.state, sizeof(e.state)); - key.Cat((char *)&e.shadow, sizeof(e.shadow)); - key.Cat((char *)&sz, sizeof(sz)); - return key; - } - virtual Image Make() const { - return GetGTK(eg.widget, e.state, e.shadow & 0x3f, eg.detail, eg.type, sz.cx, sz.cy); - } -}; - -Value GtkLookFn(Draw& w, const Rect& rect, const Value& v, int op) -{ - if(IsTypeRaw(v)) { - const GtkElement& e = ValueTo(v); - ChGtkI& eg = ChGtkIs()[e.gtki]; - switch(op) { - case LOOK_MARGINS: - return e.margins; - case LOOK_ISOPAQUE: - return false; - } - if(op == LOOK_PAINT || op == LOOK_PAINTEDGE) { - Rect r = rect.Inflated(eg.type & GTK_XMARGIN ? 0 : (eg.type >> 4) & 7); - r.Deflate((eg.type >> 16) & 15); - if(r.IsEmpty()) return 1; - GtkImageMaker gm; - gm.e = e; - gm.eg = eg; - gm.sz = r.Size(); - Image m; - if(e.shadow & 0x80) { - m = MakeImage(gm); - w.DrawImage(r.left, r.top, - m, RectC(0, 0, gm.sz.cx, gm.sz.cy - 7)); - w.DrawImage(r.left + 4, r.bottom - 7, - m, RectC(4, gm.sz.cy - 7, gm.sz.cx - 8, 5)); - } - else { - if(e.reduce.left || e.reduce.right || e.reduce.top || e.reduce.bottom) { - Rect rr = e.reduce; - rr.SetSize(gm.sz); - gm.sz.cx += e.reduce.left + e.reduce.right; - gm.sz.cy += e.reduce.top + e.reduce.bottom; - w.DrawImage(r.left, r.top, MakeImagePaintOnly(gm), rr); - } - else - w.DrawImage(r.left, r.top, MakeImagePaintOnly(gm)); - if((e.shadow & GTKELEMENT_TABFLAG) && r.GetWidth() > 0) { - w.DrawRect(r.left, r.top + 3, 1, r.GetHeight() - 6, SColorLight()); - w.DrawRect(r.right - 1, r.top + 3, 1, r.GetHeight() - 6, SColorShadow()); - } - } - return 1; - } - } - return Null; -} - -Value GtkMakeCh(int shadow, int state, const Rect& r, const Rect& m) -{ - GtkElement e; - e.gtki = ChGtkIs().GetCount() - 1; - e.shadow = shadow; - e.state = state; - e.reduce = r; - e.margins = m; - Value v = RawToValue(e); - if(chgtkspy__) { - ChGtkI& q = ChGtkIs().Top(); - chgtkspy__(String("Look: ") + G_OBJECT_TYPE_NAME(q.widget), state, shadow, q.detail, q.type, Null, Null, v); - } - return v; -} - -Value GtkMakeCh(int shadow, int state, const Rect& r) -{ - return GtkMakeCh(shadow, state, r, Rect(0, 0, 0, 0)); -} - -Value GtkMakeCh(int shadow, int state) -{ - return GtkMakeCh(shadow, state, Rect(0, 0, 0, 0)); -} - -void GtkCh(Value& look, int shadow, int state) -{ - look = GtkMakeCh(shadow, state); -} - -void GtkCh(Value *look, const char *d) -{ - GtkCh(look[CTRL_NORMAL], d[4] - '0', d[0] - '0'); - GtkCh(look[CTRL_HOT], d[5] - '0', d[1] - '0'); - GtkCh(look[CTRL_PRESSED], d[6] - '0', d[2] - '0'); - GtkCh(look[CTRL_DISABLED], d[7] - '0', d[3] - '0'); -} - -void GtkCh(Value *look) { GtkCh(look, "02140000"); } -void GtkChButton(Value *look) { GtkCh(look, "02142212"); } -void GtkChSlider(Value *look) { GtkCh(look, "02242222"); } -void GtkChTrough(Value *look) { GtkCh(look, "11141111"); } - -void GtkChWith(Value& look, int shadow, int state, const Image& img, Color c, Point offset) -{ - GtkElement e; - e.gtki = ChGtkIs().GetCount() - 1; - e.shadow = shadow; - e.state = state; - look = ChLookWith(GtkMakeCh(shadow, state), img, c, offset); -} - -void GtkChWith(Value *look, const char *d, const Image& img, Point offset) -{ - GtkChWith(look[CTRL_NORMAL], d[4] - '0', d[0] - '0', img, ButtonMonoColor(0)); - GtkChWith(look[CTRL_HOT], d[5] - '0', d[1] - '0', img, ButtonMonoColor(1)); - GtkChWith(look[CTRL_PRESSED], d[6] - '0', d[2] - '0', img, ButtonMonoColor(2), offset); - GtkChWith(look[CTRL_DISABLED], d[7] - '0', d[3] - '0', img, ButtonMonoColor(3)); -} - -void GtkChButtonWith(Value *look, const Image& img) { GtkChWith(look, "02142222", img); } - -void GtkChArrow(Value *look, const Image& img, Point offset) -{ - GtkChWith(look, "02142212", img, offset); -} - -int GtkInt(GtkWidget *widget, const char *id) -{ - int x = 0; - gtk_widget_style_get(widget, id, &x, NULL); - return x; -} - -int GtkInt(const char *id) -{ - return GtkInt(ChGtkLast(), id); -} - -void GtkIml(int uii, GtkWidget *w, int shadow, int state, const char *detail, int type, int cx, int cy) -{ - CtrlsImg::Set(uii, GetGTK(w, state, shadow, detail, type, cx, cy)); -} - -void GtkIml(int uii, GtkWidget *w, int shadow, const char *detail, int type, int cx, int cy) -{ - GtkIml(uii + 0, w, shadow, 0, detail, type, cx, cy); - GtkIml(uii + 1, w, shadow, 2, detail, type, cx, cy); - GtkIml(uii + 2, w, shadow, 1, detail, type, cx, cy); - GtkIml(uii + 3, w, shadow, 4, detail, type, cx, cy); -} - -Color ChGtkColor(int ii, GtkWidget *widget) -{ - GdkColor cc = ((GtkStyle *)gtk_widget_get_style(widget))->fg[ii]; - return Color(cc.red >> 8, cc.green >> 8, cc.blue >> 8); -} - -void ChGtkColor(Color& c, int ii) -{ - c = ChGtkColor(ii, ChGtkLast()); -} - -void ChGtkColor(Color *c, int ii) -{ - ChGtkColor(c[0], ii + 0); - ChGtkColor(c[1], ii + 2); - ChGtkColor(c[2], ii + 1); - ChGtkColor(c[3], ii + 4); -} - -Image GtkImage(const char *id, int size, int maxh) -{ - if(maxh != INT_MAX) - maxh = Ctrl::VertLayoutZoom(maxh); - Image m = GetGTK(gtk__parent(), size, 0, id, GTK_ICON, 0, 0); - if(!IsNull(m)) { - Size sz = m.GetSize(); - if(sz.cy > maxh && sz.cy) - m = Rescale(m, sz.cx * maxh / sz.cy, maxh); - } - return m; -} - -void ChCtrlImg(int ii, const char *id, int size, int maxh) -{ - Image m = GtkImage(id, size, maxh); - if(!IsNull(m)) - CtrlImg::Set(ii, m); -} - -Image GtkChImgLook(int shadow, int state, int kind) -{ - Image m = GetGTK(ChGtkLast(), state, shadow, ChGtkLastDetail(), ChGtkLastType(), 32, 32); - int g = max(1, ImageMargin(m, 4, 10)); - if((kind & 7) == 1) - m = WithHotSpots(Crop(m, 0, g, 32 - g, 32 - 2 * g), g, 0, 32 - 2 * g - 1, 0); - if((kind & 7) == 2) - m = WithHotSpots(Crop(m, g, g, 32 - g, 32 - 2 * g), 0, 0, 32 - 2 * g - g - 1, 0); - else - m = WithHotSpot(m, g, g); - if((kind & GTK_BOTTOMLINE) && m.GetHeight() > 0) { - ImageBuffer ib(m); - RGBA c = SColorShadow(); - for(int i = 1; i < ib.GetWidth(); i++) - ib[ib.GetHeight() - 1][i] = c; - m = ib; - } - return m; -} - -void GtkChImgWith(Value& look, int shadow, int state, const Image& img, Color c, int kind, Point offset) -{ - Value m = GtkChImgLook(shadow, state, kind); - look = IsNull(img) ? m : ChLookWith(m, img, c, offset); -} - -void GtkChImgWith(Value *look, const Image& img, int kind, Point offset) -{ - GtkChImgWith(look[CTRL_HOT], 2, 2, img, ButtonMonoColor(1), kind); - GtkChImgWith(look[CTRL_PRESSED], 1, 1, img, ButtonMonoColor(2), kind, offset); - GtkChImgWith(look[CTRL_DISABLED], 2, 4, img, ButtonMonoColor(3), kind); - GtkChImgWith(look[CTRL_NORMAL], 2, 0, img, ButtonMonoColor(0), kind); -} - -bool IsEmptyImage(const Image& m) -{ - const RGBA *s = ~m; - const RGBA *e = ~m + m.GetLength(); - while(s < e) { - if(s->a) - return false; - s++; - } - return true; -} - -Image GtkThemeIcon(const char *name, bool large) -{ - int rsz = large ? 48 : 16; - Image m = GetGTK(gtk__parent(), rsz, 0, name, GTK_THEMEICON, 0, 0); - Size sz = m.GetSize(); - if(sz.cx > rsz || sz.cy > rsz) - m = Rescale(m, rsz, rsz); - return m; -} - -int GtkStyleInt(const char *name) -{ - int h = Null; - g_object_get(gtk_settings_get_default(), name, &h, NULL); - return h; -} - -String GtkStyleString(const char *name) -{ - const char *h = ""; - g_object_get(gtk_settings_get_default(), name, &h, NULL); - return h; -} - -END_UPP_NAMESPACE - -#endif -#endif +#include "CtrlLib.h" + +#ifdef GUI_X11 +#ifdef flagNOGTK + +NAMESPACE_UPP + +void ChHostSkin() {} + +END_UPP_NAMESPACE + +#else + +#include "ChGtk.h" + +NAMESPACE_UPP + +#if defined(_DEBUG)// && 0 +#include + +void LOGPNG(const Image& m) +{ + static int i; + PNGEncoder png; + png.SaveFile(ConfigFile(AsString(i++) + ".png"), m); +} + +#else + +#define LOGPNG(a) + +#endif + +GtkWidget *gtk__parent() +{ + static GtkWidget *p; + if(!p) { + p = gtk_window_new(GTK_WINDOW_POPUP); + gtk_widget_realize(p); + } + return p; +} + +GtkWidget *Setup(GtkWidget *widget) +{ + static GtkWidget *fl; + if (!fl) { + fl = gtk_fixed_new(); + gtk_container_add(GTK_CONTAINER(gtk__parent()), fl); + gtk_widget_realize(fl); + } + + gtk_fixed_put(GTK_FIXED(fl), widget, 0, 0); + gtk_widget_realize(widget); + gtk_widget_show(widget); + return widget; +} + +static Image sLastImage; + +Image GtkGetLastImage() +{ + return sLastImage; +} + +void (*chgtkspy__)(const char *name, int state, int shadow, const char *detail, int type, int cx, int cy, const Value& look); + +void SetChGtkSpy_(void (*spy)(const char *name, int state, int shadow, const char *detail, int type, int cx, int cy, const Value& look)) +{ + chgtkspy__ = spy; +} + +Image GetGTK(GtkWidget *widget, int state, int shadow, const char *detail, int type, int cx, int cy) +{ + MemoryIgnoreLeaksBlock __; + GdkPixbuf *icon; + if(type == GTK_ICON || type == GTK_THEMEICON) { + gtk_widget_set_sensitive(widget, 1); + gtk_widget_set_state(widget, GTK_STATE_NORMAL); + if(type == GTK_THEMEICON) + icon = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), detail, + (GtkIconSize)state, (GtkIconLookupFlags)0, NULL); + else + icon = gtk_widget_render_icon(widget, detail, (GtkIconSize)state, NULL); + if(!icon) return Null; + cx = gdk_pixbuf_get_width(icon); + cy = gdk_pixbuf_get_height(icon); + } + else { + gtk_widget_set_sensitive(widget, state != 4); + gtk_widget_set_state(widget, (GtkStateType)state); + } + Rect rect; + int ht = type & 0xf000; + rect.top = ht == GTK_VCENTER ? cy : ht == GTK_BOTTOM ? 2 * cy : 0; + rect.left = ht == GTK_HCENTER ? cx : ht == GTK_RIGHT ? 2 * cx : 0; + rect.SetSize(cx, cy); + if(ht >= GTK_LEFT && ht <= GTK_RIGHT) + cx *= 3; + if(ht >= GTK_TOP && ht <= GTK_BOTTOM) + cy *= 3; + type &= ~0xf000; + if(GTK_IS_RANGE(widget)) { + GtkRange *r = GTK_RANGE(widget); + r->has_stepper_a = r->has_stepper_b = r->has_stepper_c = r->has_stepper_d = 1; + GdkRectangle cr; + cr.x = rect.left; + cr.y = rect.top; + cr.width = 0; + cr.height = 0; + GtkRangeLayout_ *rl = (GtkRangeLayout_ *)r->layout; + rl->stepper_a = rl->stepper_b = rl->stepper_c = rl->stepper_d = cr; + cr.width = rect.GetWidth(); + cr.height = rect.GetHeight(); + if(type & GTK_RANGEA) rl->stepper_a = cr; + if(type & GTK_RANGEB) rl->stepper_b = cr; + if(type & GTK_RANGEC) rl->stepper_c = cr; + if(type & GTK_RANGED) rl->stepper_d = cr; + } + GdkRectangle& allocation = widget->allocation; + allocation.x = 0; + allocation.y = 0; + allocation.width = cx; + allocation.height = cy; + Image m[2]; + Color back = White; + int margin = (type >> 4) & 7; + for(int i = 0; i < 2; i++) { + ImageDraw iw(cx + 2 * margin, cy + 2 * margin); + iw.DrawRect(0, 0, cx + 2 * margin, cy + 2 * margin, back); + static GdkColormap *cm = gdk_x11_colormap_foreign_new( + gdkx_visual_get(XVisualIDFromVisual(Xvisual)), Xcolormap); + GdkPixmap *pixmap = gdk_pixmap_foreign_new(iw.GetDrawable()); + gdk_drawable_set_colormap(pixmap, cm); + GdkRectangle cr; + cr.x = 0; + cr.y = 0; + cr.width = cx; + cr.height = cy; + GtkStyle *style = gtk_widget_get_style(widget); + int rcx = max(rect.GetWidth() - 2 * margin, 0); + int rcy = max(rect.GetHeight() - 2 * margin, 0); + int t1 = (type & 0xf00) >> 8; + switch(type & 15) { + case GTK_BGBOX: + gtk_style_apply_default_background(style, pixmap, TRUE, (GtkStateType)state, + &cr, rect.left + margin, rect.top + margin, rcx, rcy); + case GTK_BOX: + gtk_paint_box(style, pixmap, (GtkStateType)state, (GtkShadowType)shadow, &cr, + widget, detail, + rect.left + margin, rect.top + margin, rcx, rcy); + break; + case GTK_FLATBOX: + gtk_paint_flat_box(style, pixmap, (GtkStateType)state, (GtkShadowType)shadow, &cr, + widget, detail, + rect.left + margin, rect.top + margin, rcx, rcy); + break; + case GTK_CHECK: + gtk_paint_check(style, pixmap, (GtkStateType)state, (GtkShadowType)shadow, &cr, + widget, detail, + rect.left + margin, rect.top + margin, rcx, rcy); + break; + case GTK_OPTION: + gtk_paint_option(style, pixmap, (GtkStateType)state, (GtkShadowType)shadow, &cr, + widget, detail, + rect.left + margin, rect.top + margin, rcx, rcy); + break; + case GTK_ARROW: + gtk_paint_arrow(style, pixmap, (GtkStateType)state, (GtkShadowType)shadow, &cr, + widget, detail, (GtkArrowType)t1, 1, + rect.left + margin, rect.top + margin, rcx, rcy); + break; + case GTK_SLIDER: + gtk_paint_slider(style, pixmap, (GtkStateType)state, (GtkShadowType)shadow, &cr, + widget, detail, + rect.left + margin, rect.top + margin, rcx, rcy, + (GtkOrientation)t1); + break; + case GTK_ICON: + case GTK_THEMEICON: + gdk_draw_pixbuf(pixmap, NULL, icon, 0, 0, 0, 0, -1, -1, (GdkRgbDither)0, 0, 0); + break; + case GTK_EXT: + gtk_paint_extension(style, pixmap, (GtkStateType)state, (GtkShadowType)shadow, &cr, + widget, (gchar *)detail, + rect.left + margin, rect.top + margin, rcx, rcy, + (GtkPositionType)t1); + break; + case GTK_SHADOW: + gtk_paint_shadow(style, pixmap, (GtkStateType)state, (GtkShadowType)shadow, &cr, + widget, (gchar *)detail, + rect.left + margin, rect.top + margin, rcx, rcy); + break; + case GTK_FOCUS: + gtk_paint_focus(style, pixmap, (GtkStateType)state, &cr, + widget, (gchar *)detail, + rect.left + margin, rect.top + margin, rcx, rcy); + break; + } + g_object_unref(pixmap); + m[i] = Crop(iw, rect.Inflated(margin)); + back = Black; + } + if(type == GTK_ICON) + g_object_unref(icon); + sLastImage = RecreateAlpha(m[0], m[1]); + if(chgtkspy__) + chgtkspy__(G_OBJECT_TYPE_NAME(widget), state, shadow, detail, type, cx, cy, sLastImage); + return sLastImage; +} + +Vector& ChGtkIs() +{ + static Vector x; + return x; +} + +GtkWidget *ChGtkLast() +{ + return ChGtkIs().Top().widget; +} + +const char *ChGtkLastDetail() +{ + return ChGtkIs().Top().detail; +} + +int ChGtkLastType() +{ + return ChGtkIs().Top().type; +} + +void ChGtkNew(GtkWidget *widget, const char *detail, int type) +{ + if(gtk_widget_get_parent(widget) == NULL) + Setup(widget); + ChGtkI& q = ChGtkIs().Add(); + q.widget = widget; + q.detail = detail; + q.type = type; +} + +void ChGtkNew(const char *detail, int type) +{ + ChGtkNew(ChGtkLast(), detail, type); +} + +struct GtkElement { + word gtki; + byte state; + byte shadow; + Rect reduce; + Rect margins; +}; + +struct GtkImageMaker : ImageMaker { + GtkElement e; + ChGtkI eg; + Size sz; + + virtual String Key() const { + StringBuffer key; + key.Cat((char *)&eg.widget, sizeof(eg.widget)); + key.Cat((char *)&eg.detail, sizeof(eg.detail)); + key.Cat((char *)&eg.type, sizeof(eg.type)); + key.Cat((char *)&e.gtki, sizeof(e.gtki)); + key.Cat((char *)&e.state, sizeof(e.state)); + key.Cat((char *)&e.shadow, sizeof(e.shadow)); + key.Cat((char *)&sz, sizeof(sz)); + return key; + } + virtual Image Make() const { + return GetGTK(eg.widget, e.state, e.shadow & 0x3f, eg.detail, eg.type, sz.cx, sz.cy); + } +}; + +Value GtkLookFn(Draw& w, const Rect& rect, const Value& v, int op) +{ + if(IsTypeRaw(v)) { + const GtkElement& e = ValueTo(v); + ChGtkI& eg = ChGtkIs()[e.gtki]; + switch(op) { + case LOOK_MARGINS: + return e.margins; + case LOOK_ISOPAQUE: + return false; + } + if(op == LOOK_PAINT || op == LOOK_PAINTEDGE) { + Rect r = rect.Inflated(eg.type & GTK_XMARGIN ? 0 : (eg.type >> 4) & 7); + r.Deflate((eg.type >> 16) & 15); + if(r.IsEmpty()) return 1; + GtkImageMaker gm; + gm.e = e; + gm.eg = eg; + gm.sz = r.Size(); + Image m; + if(e.shadow & 0x80) { + m = MakeImage(gm); + w.DrawImage(r.left, r.top, + m, RectC(0, 0, gm.sz.cx, gm.sz.cy - 7)); + w.DrawImage(r.left + 4, r.bottom - 7, + m, RectC(4, gm.sz.cy - 7, gm.sz.cx - 8, 5)); + } + else { + if(e.reduce.left || e.reduce.right || e.reduce.top || e.reduce.bottom) { + Rect rr = e.reduce; + rr.SetSize(gm.sz); + gm.sz.cx += e.reduce.left + e.reduce.right; + gm.sz.cy += e.reduce.top + e.reduce.bottom; + w.DrawImage(r.left, r.top, MakeImagePaintOnly(gm), rr); + } + else + w.DrawImage(r.left, r.top, MakeImagePaintOnly(gm)); + if((e.shadow & GTKELEMENT_TABFLAG) && r.GetWidth() > 0) { + w.DrawRect(r.left, r.top + 3, 1, r.GetHeight() - 6, SColorLight()); + w.DrawRect(r.right - 1, r.top + 3, 1, r.GetHeight() - 6, SColorShadow()); + } + } + return 1; + } + } + return Null; +} + +Value GtkMakeCh(int shadow, int state, const Rect& r, const Rect& m) +{ + GtkElement e; + e.gtki = ChGtkIs().GetCount() - 1; + e.shadow = shadow; + e.state = state; + e.reduce = r; + e.margins = m; + Value v = RawToValue(e); + if(chgtkspy__) { + ChGtkI& q = ChGtkIs().Top(); + chgtkspy__(String("Look: ") + G_OBJECT_TYPE_NAME(q.widget), state, shadow, q.detail, q.type, Null, Null, v); + } + return v; +} + +Value GtkMakeCh(int shadow, int state, const Rect& r) +{ + return GtkMakeCh(shadow, state, r, Rect(0, 0, 0, 0)); +} + +Value GtkMakeCh(int shadow, int state) +{ + return GtkMakeCh(shadow, state, Rect(0, 0, 0, 0)); +} + +void GtkCh(Value& look, int shadow, int state) +{ + look = GtkMakeCh(shadow, state); +} + +void GtkCh(Value *look, const char *d) +{ + GtkCh(look[CTRL_NORMAL], d[4] - '0', d[0] - '0'); + GtkCh(look[CTRL_HOT], d[5] - '0', d[1] - '0'); + GtkCh(look[CTRL_PRESSED], d[6] - '0', d[2] - '0'); + GtkCh(look[CTRL_DISABLED], d[7] - '0', d[3] - '0'); +} + +void GtkCh(Value *look) { GtkCh(look, "02140000"); } +void GtkChButton(Value *look) { GtkCh(look, "02142212"); } +void GtkChSlider(Value *look) { GtkCh(look, "02242222"); } +void GtkChTrough(Value *look) { GtkCh(look, "11141111"); } + +void GtkChWith(Value& look, int shadow, int state, const Image& img, Color c, Point offset) +{ + GtkElement e; + e.gtki = ChGtkIs().GetCount() - 1; + e.shadow = shadow; + e.state = state; + look = ChLookWith(GtkMakeCh(shadow, state), img, c, offset); +} + +void GtkChWith(Value *look, const char *d, const Image& img, Point offset) +{ + GtkChWith(look[CTRL_NORMAL], d[4] - '0', d[0] - '0', img, ButtonMonoColor(0)); + GtkChWith(look[CTRL_HOT], d[5] - '0', d[1] - '0', img, ButtonMonoColor(1)); + GtkChWith(look[CTRL_PRESSED], d[6] - '0', d[2] - '0', img, ButtonMonoColor(2), offset); + GtkChWith(look[CTRL_DISABLED], d[7] - '0', d[3] - '0', img, ButtonMonoColor(3)); +} + +void GtkChButtonWith(Value *look, const Image& img) { GtkChWith(look, "02142222", img); } + +void GtkChArrow(Value *look, const Image& img, Point offset) +{ + GtkChWith(look, "02142212", img, offset); +} + +int GtkInt(GtkWidget *widget, const char *id) +{ + int x = 0; + gtk_widget_style_get(widget, id, &x, NULL); + return x; +} + +int GtkInt(const char *id) +{ + return GtkInt(ChGtkLast(), id); +} + +void GtkIml(int uii, GtkWidget *w, int shadow, int state, const char *detail, int type, int cx, int cy) +{ + CtrlsImg::Set(uii, GetGTK(w, state, shadow, detail, type, cx, cy)); +} + +void GtkIml(int uii, GtkWidget *w, int shadow, const char *detail, int type, int cx, int cy) +{ + GtkIml(uii + 0, w, shadow, 0, detail, type, cx, cy); + GtkIml(uii + 1, w, shadow, 2, detail, type, cx, cy); + GtkIml(uii + 2, w, shadow, 1, detail, type, cx, cy); + GtkIml(uii + 3, w, shadow, 4, detail, type, cx, cy); +} + +Color ChGtkColor(int ii, GtkWidget *widget) +{ + GdkColor cc = ((GtkStyle *)gtk_widget_get_style(widget))->fg[ii]; + return Color(cc.red >> 8, cc.green >> 8, cc.blue >> 8); +} + +void ChGtkColor(Color& c, int ii) +{ + c = ChGtkColor(ii, ChGtkLast()); +} + +void ChGtkColor(Color *c, int ii) +{ + ChGtkColor(c[0], ii + 0); + ChGtkColor(c[1], ii + 2); + ChGtkColor(c[2], ii + 1); + ChGtkColor(c[3], ii + 4); +} + +Image GtkImage(const char *id, int size, int maxh) +{ + if(maxh != INT_MAX) + maxh = Ctrl::VertLayoutZoom(maxh); + Image m = GetGTK(gtk__parent(), size, 0, id, GTK_ICON, 0, 0); + if(!IsNull(m)) { + Size sz = m.GetSize(); + if(sz.cy > maxh && sz.cy) + m = Rescale(m, sz.cx * maxh / sz.cy, maxh); + } + return m; +} + +void ChCtrlImg(int ii, const char *id, int size, int maxh) +{ + Image m = GtkImage(id, size, maxh); + if(!IsNull(m)) + CtrlImg::Set(ii, m); +} + +Image GtkChImgLook(int shadow, int state, int kind) +{ + Image m = GetGTK(ChGtkLast(), state, shadow, ChGtkLastDetail(), ChGtkLastType(), 32, 32); + int g = max(1, ImageMargin(m, 4, 10)); + if((kind & 7) == 1) + m = WithHotSpots(Crop(m, 0, g, 32 - g, 32 - 2 * g), g, 0, 32 - 2 * g - 1, 0); + if((kind & 7) == 2) + m = WithHotSpots(Crop(m, g, g, 32 - g, 32 - 2 * g), 0, 0, 32 - 2 * g - g - 1, 0); + else + m = WithHotSpot(m, g, g); + if((kind & GTK_BOTTOMLINE) && m.GetHeight() > 0) { + ImageBuffer ib(m); + RGBA c = SColorShadow(); + for(int i = 1; i < ib.GetWidth(); i++) + ib[ib.GetHeight() - 1][i] = c; + m = ib; + } + return m; +} + +void GtkChImgWith(Value& look, int shadow, int state, const Image& img, Color c, int kind, Point offset) +{ + Value m = GtkChImgLook(shadow, state, kind); + look = IsNull(img) ? m : ChLookWith(m, img, c, offset); +} + +void GtkChImgWith(Value *look, const Image& img, int kind, Point offset) +{ + GtkChImgWith(look[CTRL_HOT], 2, 2, img, ButtonMonoColor(1), kind); + GtkChImgWith(look[CTRL_PRESSED], 1, 1, img, ButtonMonoColor(2), kind, offset); + GtkChImgWith(look[CTRL_DISABLED], 2, 4, img, ButtonMonoColor(3), kind); + GtkChImgWith(look[CTRL_NORMAL], 2, 0, img, ButtonMonoColor(0), kind); +} + +bool IsEmptyImage(const Image& m) +{ + const RGBA *s = ~m; + const RGBA *e = ~m + m.GetLength(); + while(s < e) { + if(s->a) + return false; + s++; + } + return true; +} + +Image GtkThemeIcon(const char *name, bool large) +{ + int rsz = large ? 48 : 16; + Image m = GetGTK(gtk__parent(), rsz, 0, name, GTK_THEMEICON, 0, 0); + Size sz = m.GetSize(); + if(sz.cx > rsz || sz.cy > rsz) + m = Rescale(m, rsz, rsz); + return m; +} + +int GtkStyleInt(const char *name) +{ + int h = Null; + g_object_get(gtk_settings_get_default(), name, &h, NULL); + return h; +} + +String GtkStyleString(const char *name) +{ + const char *h = ""; + g_object_get(gtk_settings_get_default(), name, &h, NULL); + return h; +} + +END_UPP_NAMESPACE + +#endif +#endif diff --git a/uppsrc/CtrlLib/ChWin32.cpp b/uppsrc/CtrlLib/ChWin32.cpp index e6d6cacde..0f1721d26 100644 --- a/uppsrc/CtrlLib/ChWin32.cpp +++ b/uppsrc/CtrlLib/ChWin32.cpp @@ -7,7 +7,7 @@ NAMESPACE_UPP void ChSysInit(); -#ifdef PLATFORM_WIN32 +#ifdef GUI_WIN #ifdef PLATFORM_WINCE diff --git a/uppsrc/CtrlLib/CtrlLib.icpp b/uppsrc/CtrlLib/CtrlLib.icpp index ccbebef02..ace16b6fd 100644 --- a/uppsrc/CtrlLib/CtrlLib.icpp +++ b/uppsrc/CtrlLib/CtrlLib.icpp @@ -7,8 +7,14 @@ NAMESPACE_UPP void CtrlSetDefaultSkin(void (*fn1)(), void (*fn2)()); +#if defined(GUI_WIN) || defined(GUI_X11) INITBLOCK { CtrlSetDefaultSkin(ChStdSkin, ChHostSkin); }; +#else +INITBLOCK { + CtrlSetDefaultSkin(ChStdSkin, ChStdSkin); +}; +#endif END_UPP_NAMESPACE diff --git a/uppsrc/CtrlLib/CtrlUtil.h b/uppsrc/CtrlLib/CtrlUtil.h index 4da9baa6e..d912f8beb 100644 --- a/uppsrc/CtrlLib/CtrlUtil.h +++ b/uppsrc/CtrlLib/CtrlUtil.h @@ -37,17 +37,17 @@ public: ~DelayCallback() { KillTimeCallback(this); } }; -#ifdef PLATFORM_WIN32 +#ifdef GUI_WIN struct Win32PrintDlg_; #endif #ifndef PLATFORM_WINCE class PrinterJob { -#ifdef PLATFORM_WIN32 +#ifdef GUI_WIN One pdlg; #endif -#ifdef PLATFORM_X11 +#ifdef GUI_X11 Size pgsz; #endif One draw; @@ -79,7 +79,7 @@ public: #endif -#ifdef PLATFORM_X11 +#ifdef GUI_X11 class TrayIcon : Ctrl { virtual bool HookProc(XEvent *event); @@ -138,7 +138,7 @@ public: #endif -#ifdef PLATFORM_WIN32 +#ifdef GUI_WIN #ifndef PLATFORM_WINCE class TrayIcon : private Ctrl { @@ -276,7 +276,7 @@ public: #endif #endif -#ifdef PLATFORM_X11 +#ifdef GUI_X11 typedef FileSel FileSelector; #endif diff --git a/uppsrc/CtrlLib/DlgColor.cpp b/uppsrc/CtrlLib/DlgColor.cpp index 84e794d5a..26f7d8da2 100644 --- a/uppsrc/CtrlLib/DlgColor.cpp +++ b/uppsrc/CtrlLib/DlgColor.cpp @@ -55,15 +55,7 @@ void FetchColorCtrl::MouseMove(Point pt, dword keyflags) else { pt += GetScreenView().TopLeft(); -#ifdef PLATFORM_WIN32 - HDC sdc = GetWindowDC(0); - user_color = Color::FromCR(GetPixel(sdc, pt.x, pt.y)); - ReleaseDC(0, sdc); -#endif -#ifdef PLATFORM_X11 - // todo: is it possible to screenshot a single screen pixel? - user_color = Black; -#endif + user_color = GuiPlatformGetScreenPixel(pt.x, pt.y); Action(); } } diff --git a/uppsrc/CtrlLib/FileSel.cpp b/uppsrc/CtrlLib/FileSel.cpp index a930cc197..1a6a24df3 100644 --- a/uppsrc/CtrlLib/FileSel.cpp +++ b/uppsrc/CtrlLib/FileSel.cpp @@ -2,7 +2,7 @@ NAMESPACE_UPP -#ifdef PLATFORM_WIN32 +#ifdef GUI_WIN void AvoidPaintingCheck__(); struct FileIconMaker : ImageMaker { @@ -72,28 +72,12 @@ Image GetFileIcon(const char *path, bool dir, bool force, bool large, bool quick return MakeImage(m); } +#define GETFILEICON_DEFINED + #endif -#ifdef PLATFORM_X11 +#if defined(PLATFORM_X11) && !defined(flagNOGTK) -#ifdef flagNOGTK -Image PosixGetDriveImage(String dir, bool) -{ - if(dir.GetCount() == 0 || dir == "/") - return CtrlImg::Computer(); - if(dir.Find("cdrom") == 0 || dir.Find("cdrecorder") == 0) - return CtrlImg::CdRom(); - if(dir.Find("floppy") == 0 || dir.Find("zip") == 0) - return CtrlImg::Diskette(); - return CtrlImg::Hd(); -} - -Image GetFileIcon(const String& folder, const String& filename, bool isdir, bool isexe, bool) -{ - return Null; -} - -#else Image GtkThemeIcon(const char *name, bool large); Image GnomeImage(const char *s, bool large = false) @@ -237,7 +221,26 @@ Image GetFileIcon(const String& folder, const String& filename, bool isdir, bool return IsNull(img) ? isexe ? (large ? lexe : exe) : (large ? lfile : file) : img; } +#define GETFILEICON_DEFINED + #endif + +#ifndef GETFILEICON_DEFINED +Image PosixGetDriveImage(String dir, bool) +{ + if(dir.GetCount() == 0 || dir == "/") + return CtrlImg::Computer(); + if(dir.Find("cdrom") == 0 || dir.Find("cdrecorder") == 0) + return CtrlImg::CdRom(); + if(dir.Find("floppy") == 0 || dir.Find("zip") == 0) + return CtrlImg::Diskette(); + return CtrlImg::Hd(); +} + +Image GetFileIcon(const String& folder, const String& filename, bool isdir, bool isexe, bool) +{ + return Null; +} #endif Image NativePathIcon0(const char *path, bool folder, bool large) diff --git a/uppsrc/CtrlLib/MenuBar.cpp b/uppsrc/CtrlLib/MenuBar.cpp index ff9fa88e6..22ad2f19c 100644 --- a/uppsrc/CtrlLib/MenuBar.cpp +++ b/uppsrc/CtrlLib/MenuBar.cpp @@ -544,10 +544,7 @@ void MenuBar::PopUp(Ctrl *owner, Point p, Size rsz) #endif doeffect = true; Ctrl::PopUp(owner, true, true, GUI_DropShadows(), !owner); -#ifdef PLATFORM_X11 - XSync(Xdisplay, false); - ProcessEvents(); -#endif + GuiPlatformAfterMenuPopUp(); if(eff) Animate(*this, p.x, p.y, sz.cx, sz.cy); } diff --git a/uppsrc/CtrlLib/PrinterJob.cpp b/uppsrc/CtrlLib/PrinterJob.cpp index b31dc3425..be3e1356c 100644 --- a/uppsrc/CtrlLib/PrinterJob.cpp +++ b/uppsrc/CtrlLib/PrinterJob.cpp @@ -1,6 +1,6 @@ #include "CtrlLib.h" -#ifdef PLATFORM_WIN32 +#ifdef GUI_WIN #ifndef PLATFORM_WINCE #include @@ -15,7 +15,7 @@ NAMESPACE_UPP -#ifdef PLATFORM_WIN32 +#ifdef GUI_WIN #ifndef PLATFORM_WINCE @@ -140,7 +140,7 @@ PrinterJob& PrinterJob::CurrentPage(int i) #endif -#ifdef PLATFORM_POSIX +#ifdef GUI_X11 String System(const char *cmd, const String& in) { diff --git a/uppsrc/CtrlLib/TrayIconWin32.cpp b/uppsrc/CtrlLib/TrayIconWin32.cpp index 25ef87595..60a6b6bd7 100644 --- a/uppsrc/CtrlLib/TrayIconWin32.cpp +++ b/uppsrc/CtrlLib/TrayIconWin32.cpp @@ -1,6 +1,6 @@ #include "CtrlLib.h" -#ifdef PLATFORM_WIN32 +#ifdef GUI_WIN #ifndef PLATFORM_WINCE #include @@ -13,7 +13,7 @@ NAMESPACE_UPP -#ifdef PLATFORM_WIN32 +#ifdef GUI_WIN #ifndef PLATFORM_WINCE #define LLOG(x) diff --git a/uppsrc/CtrlLib/TrayIconX11.cpp b/uppsrc/CtrlLib/TrayIconX11.cpp index b57749e09..5c3b38aeb 100644 --- a/uppsrc/CtrlLib/TrayIconX11.cpp +++ b/uppsrc/CtrlLib/TrayIconX11.cpp @@ -2,7 +2,7 @@ #define LLOG(x) // LOG(x) -#ifdef PLATFORM_X11 +#ifdef GUI_X11 #if !defined(flagNOGTK) #include