1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Embeddable: Fix if_exists (restore)

This commit is contained in:
gnosygnu
2016-11-24 08:58:55 -05:00
parent fcbdf8bbd8
commit 81dc7ea4ea
1351 changed files with 88510 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui.gfxs; import gplx.*; import gplx.gfui.*;
import gplx.gfui.draws.*; import gplx.gfui.imgs.*;
public interface GfxAdp extends Rls_able {
void DrawLine(PenAdp pen, PointAdp src, PointAdp trg);
void DrawRect(PenAdp pen, int x, int y, int width, int height);
void DrawRect(PenAdp pen, PointAdp location, SizeAdp size);
void DrawRect(PenAdp pen, RectAdp rect);
void FillRect(SolidBrushAdp brush, int x, int y, int width, int height);
void DrawImage(ImageAdp image, PointAdp location);
void DrawImage(ImageAdp img, int trg_x, int trg_y, int trg_w, int trg_h, int src_x, int src_y, int src_w, int src_h);
void DrawStringXtn(String s, FontAdp font, SolidBrushAdp brush, float x, float y, float width, float height, GfxStringData sd);
float[] MeasureStringXtn(String s, FontAdp font, GfxStringData sd);
}

View File

@@ -0,0 +1,108 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui.gfxs; import gplx.*; import gplx.gfui.*;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Rectangle2D;
import javax.swing.JComponent;
import gplx.gfui.draws.*; import gplx.gfui.imgs.*; import gplx.gfui.controls.gxws.*;
public class GfxAdpBase implements GfxAdp {
public void DrawLine(PenAdp pen, PointAdp src, PointAdp trg) {
gfx.setColor(ColorAdpCache.Instance.GetNativeColor(pen.Color()));
gfx.setStroke(pen.UnderStroke());
gfx.drawLine(src.X(), src.Y(), trg.X(), trg.Y());
}
public void DrawRect(PenAdp pen, PointAdp pos, SizeAdp size) {this.DrawRect(pen, pos.X(), pos.Y(), size.Width(), size.Height());}
public void DrawRect(PenAdp pen, RectAdp rect) {this.DrawRect(pen, rect.X(), rect.Y(), rect.Width(), rect.Height());}
public void DrawRect(PenAdp pen, int x, int y, int width, int height) {
gfx.setPaint(ColorAdpCache.Instance.GetNativeColor(pen.Color()));
gfx.setStroke(pen.UnderStroke());
gfx.drawRect(x, y, width, height);
}
public void FillRect(SolidBrushAdp brush, int x, int y, int width, int height) {
gfx.setPaint(ColorAdpCache.Instance.GetNativeColor(brush.Color()));
gfx.fillRect(x, y, width, height);
}
public void DrawStringXtn(String s, FontAdp font, SolidBrushAdp brush, float x, float y, float width, float height, GfxStringData sd) {
gfx.setPaint(ColorAdpCache.Instance.GetNativeColor(brush.Color()));
// height = y - ascent + descent -> rect.y - rect.height [assume ascent] + 2 [assume descent]
gfx.setClip((int)x, (int)y - (int)height + 2, (int)width, (int)height);
if (sd == null || sd.mnemonicString == null) {
gfx.setFont(font.UnderFont());
gfx.drawString(s, x, y - 2);
}
else {
gfx.drawString(sd.mnemonicString.getIterator(), x, y - 2);
}
gfx.setClip(null);
}
public float[] MeasureStringXtn(String s, FontAdp font, GfxStringData sd) {
FontMetrics fontMetrics = gfx.getFontMetrics(font.UnderFont());
Rectangle2D stringMetrics = fontMetrics.getStringBounds(s, gfx);
float width = (float)stringMetrics.getWidth();
int height = fontMetrics.getHeight();
int descent = fontMetrics.getDescent();
return new float[] {width, height, descent};
}
public static float[] GetStringBounds(String s, FontAdp font, Object o) {
JComponent jcomponent = (JComponent)o;
Graphics2D gfx = (Graphics2D)jcomponent.getGraphics();
FontMetrics fontMetrics = gfx.getFontMetrics(font.UnderFont());
Rectangle2D stringMetrics = fontMetrics.getStringBounds(s, gfx);
float width = (float)stringMetrics.getWidth();
int height = fontMetrics.getHeight();
int descent = fontMetrics.getDescent();
return new float[] {width, height, descent};
}
public void DrawImage(ImageAdp image, PointAdp pt) {
if (image == ImageAdp_.Null) return;
gfx.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
gfx.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
gfx.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
gfx.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
gfx.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
gfx.drawImage((java.awt.Image)image.Under(), pt.X(), pt.Y(), null);
// gfx.drawImage(image.UnderImage(),pt.X(),pt.Y(),
// pt.X()+image.Width(),pt.Y()+image.Height(),
// pt.X(),pt.Y(),
// pt.X()+image.Width(),pt.Y()+image.Height(),
// null);
}
public void DrawImage(ImageAdp img, int trg_x, int trg_y, int trg_w, int trg_h, int src_x, int src_y, int src_w, int src_h) {
if (img == ImageAdp_.Null) return;
gfx.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
gfx.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
gfx.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
gfx.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
gfx.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
gfx.drawImage((java.awt.Image)img.Under(), trg_x, trg_y, trg_x + trg_w, trg_y + trg_h, src_x, src_y, src_x + src_w, src_y + src_h, null);
}
public void Rls() {gfx.dispose();}
public Object Under() {return gfx;}
Graphics2D gfx;
public static GfxAdpBase new_(Graphics2D gfx) {
GfxAdpBase rv = new GfxAdpBase();
rv.gfx = gfx;
return rv;
} GfxAdpBase() {}
}

View File

@@ -0,0 +1,50 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui.gfxs; import gplx.*; import gplx.gfui.*;
import gplx.gfui.draws.*; import gplx.gfui.imgs.*;
public class GfxAdpMok implements GfxAdp {
public GfxItmList SubItms() {return subItms;} GfxItmList subItms = new GfxItmList();
public void DrawStringXtn(String s, FontAdp font, SolidBrushAdp brush, float x, float y, float width, float height, GfxStringData sd) {
float[] sizeAry = MeasureStringXtn(s, font, null);
SizeAdp size = SizeAdp_.new_((int)sizeAry[0], (int)sizeAry[1]);
GfxStringItm str = GfxStringItm.new_(PointAdp_.new_((int)x, (int)y), size, s, font, brush);
subItms.Add(str);
}
public void DrawRect(PenAdp pen, PointAdp location, SizeAdp size) {this.DrawRect(pen, location.X(), location.Y(), size.Width(), size.Height());}
public void DrawRect(PenAdp pen, RectAdp rect) {this.DrawRect(pen, rect.X(), rect.Y(), rect.Width(), rect.Height());}
public void DrawRect(PenAdp pen, int x, int y, int width, int height) {
GfxRectItm rect = GfxRectItm.new_(PointAdp_.new_(x, y), SizeAdp_.new_(width, height), pen.Width(), pen.Color());
subItms.Add(rect);
}
public void DrawLine(PenAdp pen, PointAdp src, PointAdp trg) {
GfxLineItm line = GfxLineItm.new_(src, trg, pen.Width(), pen.Color());
subItms.Add(line);
}
public void DrawImage(ImageAdp image, PointAdp location) {
// gfx.DrawImage(image, width, height);
}
public void DrawImage(ImageAdp img, int trg_x, int trg_y, int trg_w, int trg_h, int src_x, int src_y, int src_w, int src_h) {
// gfx.DrawImage(image, dst, src, GraphicsUnit.Pixel);
}
public void FillRect(SolidBrushAdp brush, int x, int y, int width, int height) {
// gfx.FillRect(brush, x, y, width, height);
}
public float[] MeasureStringXtn(String s, FontAdp font, GfxStringData str) {return new float[] {13 * String_.Len(s), 17};}
public void Rls() {}
public static GfxAdpMok new_() {return new GfxAdpMok();} GfxAdpMok() {}
}

View File

@@ -0,0 +1,27 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui.gfxs; import gplx.*; import gplx.gfui.*;
import java.awt.Graphics2D;
import gplx.gfui.imgs.*;
public class GfxAdp_ {
@gplx.Internal protected static GfxAdp new_(Graphics2D graphics) {return GfxAdpBase.new_(graphics);}
public static GfxAdp image_(ImageAdp image) {
Graphics2D graphics = (Graphics2D)((java.awt.Image)image.Under()).getGraphics();
return GfxAdpBase.new_(graphics);
}
}

View File

@@ -0,0 +1,19 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui.gfxs; import gplx.*; import gplx.gfui.*;
public interface GfxItm {}

View File

@@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui.gfxs; import gplx.*; import gplx.gfui.*;
public class GfxItmList extends List_adp_base {
@gplx.New public GfxItm Get_at(int i) {return (GfxItm)Get_at_base(i);}
public void Add(GfxItm gfxItm) {Add_base(gfxItm);}
}
class GfxItmListFxt {
public void tst_SubItm_count(GfxAdpMok gfx, int expd) {Tfds.Eq(expd, gfx.SubItms().Count());}
public void tst_SubItm(GfxAdpMok gfx, int i, GfxItm expd) {
GfxItm actl = gfx.SubItms().Get_at(i);
Tfds.Eq(expd, actl);
}
public static GfxItmListFxt new_() {return new GfxItmListFxt();} GfxItmListFxt() {}
}

View File

@@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui.gfxs; import gplx.*; import gplx.gfui.*;
import gplx.core.strings.*;
public abstract class GfxItm_base implements GfxItm {
public PointAdp Pos() {return pos;} PointAdp pos = PointAdp_.Zero;
public SizeAdp Size() {return size;} SizeAdp size = SizeAdp_.Zero;
@Override public String toString() {return String_bldr_.new_().Add_kv_obj("pos", pos).Add_kv_obj("size", size).To_str();}
@Override public int hashCode() {return this.toString().hashCode();}
@Override public boolean equals(Object obj) {
GfxItm_base comp = GfxItm_base.as_(obj); if (comp == null) return false;
return Object_.Eq(pos, comp.pos) && Object_.Eq(size, comp.size);
}
@gplx.Virtual public void ctor_GfxItmBase(PointAdp posVal, SizeAdp sizeVal) {
pos = posVal; size = sizeVal;
}
public static GfxItm_base as_(Object obj) {return obj instanceof GfxItm_base ? (GfxItm_base)obj : null;}
public static GfxItm_base cast(Object obj) {try {return (GfxItm_base)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, GfxItm_base.class, obj);}}
}

View File

@@ -0,0 +1,41 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui.gfxs; import gplx.*; import gplx.gfui.*;
import gplx.core.strings.*;
import gplx.gfui.draws.*;
public class GfxLineItm implements GfxItm {
public PointAdp Src() {return src;} PointAdp src = PointAdp_.Zero;
public PointAdp Trg() {return trg;} PointAdp trg = PointAdp_.Zero;
public float Width() {return width;} float width;
public ColorAdp Color() {return color;} ColorAdp color;
@Override public String toString() {return String_bldr_.new_().Add_kv_obj("src", src).Add_kv_obj("trg", trg).Add_kv_obj("width", width).Add_kv_obj("color", color.XtoHexStr()).To_str();}
@Override public int hashCode() {return this.toString().hashCode();}
@Override public boolean equals(Object obj) {
GfxLineItm comp = GfxLineItm.as_(obj); if (comp == null) return false;
return src.Eq(comp.src) && trg.Eq(comp.trg) && width == comp.width && color.Eq(comp.color);
}
public static GfxLineItm new_(PointAdp src, PointAdp trg, float width, ColorAdp color) {
GfxLineItm rv = new GfxLineItm();
rv.src = src; rv.trg = trg;
rv.width = width; rv.color = color;
return rv;
} GfxLineItm() {}
public static GfxLineItm as_(Object obj) {return obj instanceof GfxLineItm ? (GfxLineItm)obj : null;}
public static GfxLineItm cast(Object obj) {try {return (GfxLineItm)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, GfxLineItm.class, obj);}}
}

View File

@@ -0,0 +1,38 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui.gfxs; import gplx.*; import gplx.gfui.*;
import gplx.core.strings.*;
import gplx.gfui.draws.*;
public class GfxRectItm extends GfxItm_base {
public float Width() {return width;} float width;
public ColorAdp Color() {return color;} ColorAdp color;
@Override public String toString() {return String_.Concat(super.toString(), String_bldr_.new_().Add_kv_obj("width", width).Add_kv("color", color.XtoHexStr()).To_str());}
@Override public int hashCode() {return this.toString().hashCode();}
@Override public boolean equals(Object obj) {
GfxRectItm comp = GfxRectItm.as_(obj); if (comp == null) return false;
return super.equals(comp) && width == comp.width && color.Eq(comp.color);
}
public static GfxRectItm new_(PointAdp pos, SizeAdp size, float width, ColorAdp color) {
GfxRectItm rv = new GfxRectItm();
rv.ctor_GfxItmBase(pos, size);
rv.width = width; rv.color = color;
return rv;
} GfxRectItm() {}
@gplx.New public static GfxRectItm as_(Object obj) {return obj instanceof GfxRectItm ? (GfxRectItm)obj : null;}
}

View File

@@ -0,0 +1,117 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui.gfxs; import gplx.*; import gplx.gfui.*;
import java.awt.font.TextAttribute;
import java.text.AttributedString;
import gplx.core.envs.*;
import gplx.gfui.draws.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.elems.*; import gplx.gfui.controls.windows.*;
public class GfxStringData {
public String Val() {
if (ownerElem == null) return val;
if (ownerElem.TextVal() == null) return "";
return ownerElem.TextVal();
} String val = "";
public GfuiAlign AlignH() {return alignH;} GfuiAlign alignH;
public GfxStringData AlignH_(GfuiAlign val) {
alignH = val;
if (ownerElem != null) Gfo_invk_.Invk_by_val(ownerElem, GxwElem_lang.AlignH_cmd, alignH); // needed for TextBox, since its Paint is not overriden
TextRect_setNull();
return this;
}
public GfuiAlign AlignV() {return alignV;} public GfxStringData AlignV_(GfuiAlign val) {alignV = val; return this;} GfuiAlign alignV = GfuiAlign_.Mid;
public ColorAdp Color() {return brush.Color();}
public SolidBrushAdp UnderBrush() {return brush;} SolidBrushAdp brush;
public AttributedString MnemonicString() {return mnemonicString;} AttributedString mnemonicString;
String drawn = "";
public void MnemonicString_sync() {
int pos = GfuiWinKeyCmdMgr.ExtractPosFromText(this.Val()); if (pos == String_.Find_none) return;
drawn = String_.MidByLen(this.Val(), 0, pos) + String_.Mid(this.Val(), pos + 1); // rebuild string without &
mnemonicString = new AttributedString(drawn);
mnemonicString.addAttribute(TextAttribute.FONT, font.UnderFont());
mnemonicString.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, pos, pos + 1);
}
public GfxStringData Color_(ColorAdp val) {
brush = SolidBrushAdp_.new_(val);
if (ownerElem != null) ownerElem.Core().ForeColor_set(val);
TextRect_setNull();
return this;
}
public FontAdp Font() {return font;} FontAdp font;
public GfxStringData Font_(FontAdp val) {
font = val;
if (!Env_.Mode_testing() && ownerElem != null) ownerElem.Core().TextFont_set(font);
TextRect_setNull();
MnemonicString_sync();
return this;
}
public RectAdpF TextRect() {return textRect;} public void TextRect_set(RectAdpF val) {textRect = val;} public void TextRect_setNull() {textRect = RectAdpF.Null;} RectAdpF textRect = RectAdpF.Null;
public RectAdpF TextRect_setX(int x) {
textRect = RectAdpF.new_(x, textRect.Y(), textRect.Width(), textRect.Height());
return textRect;
}
@gplx.Internal protected SizeAdp OwnerSize() {return ownerSize;}
public void OwnerSize_sync(SizeAdp val) {
ownerSize = val; TextRect_setNull();
ownerElem.Core().Invalidate(); // NOTE: force redraw; this may be redundant in WINFORMS but needed in SWING especially when windowOpened causes resize; SWING seems to execute windowOpened -> resize -> paint -> componentResized
} SizeAdp ownerSize = SizeAdp_.new_(20, 20);
@gplx.Internal protected GxwElem UnderElem() {return owner.UnderElem();}
public void DrawData(GfxAdp gfx) {
if (textRect.Eq(RectAdpF.Null)) {textRect = TextRect_calc(gfx);}
gfx.DrawStringXtn(this.Val(), font, brush, textRect.X(), textRect.Y(), textRect.Width(), textRect.Height(), this);
}
public void Text_set(String v) {
if (this.Val() == v) return;
if (ownerElem != null) {
ownerElem.TextVal_set(v);
if (owner.CustomDraw()) ownerElem.Core().Invalidate();
}
else
this.val = v;
TextRect_setNull();
MnemonicString_sync();
}
public RectAdpF TextRect_calc(GfxAdp gfx) {
float[] sizeAry = gfx.MeasureStringXtn(drawn == "" ? this.Val() : drawn, font, this);
float width = sizeAry[0], height = sizeAry[1], descent = sizeAry[2];
// if (String_.Eq("opal.gfds 0.0.1", this.Val())) {
// Tfds.Write(this.Val(), alignH.Val(), (int)width, ownerSize.Width());
// }
float x = GfuiAlign_.CalcInsideOfAxis(alignH.Val(), (int)width, ownerSize.Width());
float y = 0; int alignVVal = alignV.Val(); float ownerHeight = ownerSize.Height();
if (alignVVal == GfuiAlign_.Null.Val()) y = Int_.Min_value;
else if (alignVVal == GfuiAlign_.Lo.Val()) y = height - descent;
else if (alignVVal == GfuiAlign_.Mid.Val()) y = (ownerHeight - (ownerHeight - height) / 2);// - descent; // COMMENT: subtracting descent is theoretically correct, but practically results in text shifted up
else if (alignVVal == GfuiAlign_.Hi.Val()) y = ownerHeight - descent;
if (width > ownerElem.Core().Width()) width = ownerElem.Core().Width(); // clip to elem size or else text overflows; EX: tab buttons
if (x < 0) x = 0; if (y < 0) y = 0; // occurs when text is larger than elem; do not allow negative values
return RectAdpF.new_(x, y, width, height);
} GfuiElemBase owner; GxwElem ownerElem;
public static GfxStringData new_(GfuiElemBase owner, GxwElem ownerElem) {
GfxStringData rv = new GfxStringData();
rv.brush = SolidBrushAdp_.Black;
rv.alignH = GfuiAlign_.Left;
rv.owner = owner;
rv.ownerElem = ownerElem;
// WORKAROUND:.NET: setting font on textBox causes odd selection behavior for MediaTimeBox
rv.Font_(FontAdp.new_("Arial", 8, FontStyleAdp_.Plain)); // needed for TextBox, since its Paint is not overriden, and .Font property must be set
return rv;
} GfxStringData() {}
public static final GfxStringData Null = null;
}

View File

@@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui.gfxs; import gplx.*; import gplx.gfui.*;
import gplx.gfui.draws.*;
public class GfxStringItm extends GfxItm_base {
public String Text() {return text;} private String text;
public FontAdp Font() {return font;} FontAdp font;
public SolidBrushAdp Brush() {return brush;} SolidBrushAdp brush;
@Override public int hashCode() {return this.toString().hashCode();}
@Override public boolean equals(Object obj) {
GfxStringItm comp = GfxStringItm.as_(obj); if (comp == null) return false;
return super.equals(obj) && String_.Eq(text, comp.text) && font.Eq(comp.font) && brush.Eq(comp.brush);
}
public static GfxStringItm new_(PointAdp pos, SizeAdp size, String text, FontAdp font, SolidBrushAdp brush) {
GfxStringItm rv = new GfxStringItm();
rv.ctor_GfxItmBase(pos, size);
rv.text = text; rv.font = font; rv.brush = brush;
return rv;
} GfxStringItm() {}
public static GfxStringItm test_(String text, FontAdp font, SolidBrushAdp brush) {
return GfxStringItm.new_(PointAdp_.Null, SizeAdp_.Null, text, font, brush);
}
@gplx.New public static GfxStringItm as_(Object obj) {return obj instanceof GfxStringItm ? (GfxStringItm)obj : null;}
}

View File

@@ -0,0 +1,29 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui.gfxs; import gplx.*; import gplx.gfui.*;
public class PaintArgs {
public GfxAdp Graphics() {return graphics;} GfxAdp graphics;
public RectAdp ClipRect() {return clipRect;} RectAdp clipRect;
public static PaintArgs cast(Object obj) {try {return (PaintArgs)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, PaintArgs.class, obj);}}
public static PaintArgs new_(GfxAdp graphics, RectAdp clipRect) {
PaintArgs rv = new PaintArgs();
rv.graphics = graphics; rv.clipRect = clipRect;
return rv;
}
}