/// <summary> /// 可见状态改变方法 /// </summary> public override void onVisibleChanged() { base.onVisibleChanged(); FCNative native = Native; if (native != null) { if (Visible) { if (m_frame == null) { m_frame = new FCWindowFrame(); } native.removeControl(this); native.addControl(m_frame); m_frame.Size = native.DisplaySize; if (!m_frame.containsControl(this)) { m_frame.addControl(this); } } else { if (m_frame != null) { m_frame.removeControl(this); native.removeControl(m_frame); } } } }
/// <summary> /// 窗体关闭事件 /// </summary> /// <param name="e"></param> protected override void OnFormClosing(FormClosingEventArgs e) { base.OnFormClosing(e); List <FCView> controls = m_native.getControls(); List <FCView> removeControls = new List <FCView>(); int controlsSize = controls.Count; for (int i = 0; i < controlsSize; i++) { removeControls.Add(controls[i]); } for (int i = 0; i < controlsSize; i++) { m_native.removeMirror(removeControls[i]); } removeControls.Clear(); if (m_native != null) { m_native.delete(); m_native = null; } if (m_window != null) { WindowXmlEx window = m_window; m_window = null; window.close(); } }
/// <summary> /// 获取用于绘制的背景图片 /// </summary> protected override String getPaintingBackImage() { String backImage = null; if (isPaintEnabled(this)) { FCNative native = Native; if (this == native.PushedControl) { backImage = m_pushedBackImage; } else if (this == native.HoveredControl) { backImage = m_hoveredBackImage; } } else { backImage = m_disabledBackImage; } if (backImage != null) { return(backImage); } else { return(base.getPaintingBackImage()); } }
/// <summary> /// 更新编辑器 /// </summary> /// <param name="parent">控件</param> private void updateScintilla() { FCNative native = m_parentDiv.Native; if (native != null) { if (m_parentDiv.isPaintVisible(m_parentDiv)) { ShowWindow(Handle, SW_SHOWNOACTIVATE); float scaleFactorX = 1, scaleFactorY = 1; FCSize scaleSize = native.ScaleSize; WinHostEx winHost = native.Host as WinHostEx; Control control = Control.FromHandle(winHost.HWnd); FCSize size = new FCSize(control.ClientSize.Width, control.ClientSize.Height); if (size.cx > 0 & size.cy > 0) { scaleFactorX = (float)scaleSize.cx / size.cx; scaleFactorY = (float)scaleSize.cy / size.cy; } int x = (int)(native.clientX(m_parentDiv) / scaleFactorX); int y = (int)(native.clientY(m_parentDiv) / scaleFactorY); int cx = (int)(m_parentDiv.Width / scaleFactorX); int cy = (int)(m_parentDiv.Height / scaleFactorY); MoveWindow(Handle, x, y, cx, cy, true); } else { ShowWindow(Handle, SW_HIDE); } } }
/// <summary> /// 创建控件 /// </summary> /// <param name="node">节点</param> /// <param name="type">类型</param> /// <returns>控件</returns> public override FCView createControl(XmlNode node, String type) { FCNative native = Native; if (type == "ribbonbutton") { return(new RibbonButton()); } //透明按钮2 else if (type == "ribbonbutton2") { return(new RibbonButton2()); } else if (type == "propertygrid") { PropertyGrid propertyGrid = new PropertyGrid(); return(propertyGrid); } else if (type == "windowex") { FCWindow window = new FCWindow(); window.Native = Native; window.show(); return(window); } else { return(base.createControl(node, type)); } }
/// <summary> /// 自动适应位置和大小 /// </summary> /// <param name="menu">菜单</param> protected void adjust(FCMenu menu) { FCNative native = Native; if (AutoSize) { int contentHeight = menu.getContentHeight(); int maximumHeight = MaximumSize.cy; menu.Height = Math.Min(contentHeight, maximumHeight); } FCPoint mPoint = menu.Location; FCSize mSize = menu.Size; FCSize nSize = native.DisplaySize; if (mPoint.x < 0) { mPoint.x = 0; } if (mPoint.y < 0) { mPoint.y = 0; } if (mPoint.x + mSize.cx > nSize.cx) { mPoint.x = nSize.cx - mSize.cx; } if (mPoint.y + mSize.cy > nSize.cy) { mPoint.y = nSize.cy - mSize.cy; } menu.Location = mPoint; menu.update(); }
/// <summary> /// 创建方法 /// </summary> /// <param name="indicator">指标</param> /// <param name="id">ID</param> /// <param name="name">名称</param> /// <param name="withParameters">是否有参数</param> public NFunctionBase(FCScript indicator, int id, String name, FCNative native) { m_indicator = indicator; m_ID = id; m_name = name; m_native = native; }
/// <summary> /// 加载 /// </summary> /// <param name="name">名称</param> public void loadXml(String name) { if (name == "MainFrame") { m_xml = new MainFrame(); } m_xml.createNative(); m_native = m_xml.Native; m_native.Paint = new GdiPlusPaintEx(); m_host = new WinHostEx(); m_host.Native = m_native; m_native.Host = m_host; m_host.HWnd = Handle; m_native.AllowScaleSize = true; m_native.DisplaySize = new FCSize(ClientSize.Width, ClientSize.Height); m_xml.resetScaleSize(GetClientSize()); m_xml.Script = new FaceCatScript(m_xml); m_xml.Native.ResourcePath = DataCenter.getAppPath() + "\\config"; m_xml.load(DataCenter.getAppPath() + "\\config\\" + name + ".html"); m_host.ToolTip = new FCToolTip(); m_host.ToolTip.Font = new FCFont("SimSun", 20, true, false, false); (m_host.ToolTip as FCToolTip).InitialDelay = 250; m_native.update(); Invalidate(); }
/// <summary> /// 可见状态改变方法 /// </summary> public override void onVisibleChanged() { base.onVisibleChanged(); if (Visible) { if (m_popup) { FCHScrollBar hScrollBar = HScrollBar; FCVScrollBar vScrollBar = VScrollBar; if (hScrollBar != null) { hScrollBar.Pos = 0; } if (vScrollBar != null) { vScrollBar.Pos = 0; } focus(); //修正显示位置 adjust(this); } startTimer(m_timerID, 10); } else { stopTimer(m_timerID); bool close = closeMenus(m_items); FCNative native = Native; if (native != null) { native.invalidate(); } } }
/// <summary> /// 重置缩放尺寸 /// </summary> /// <param name="clientSize">客户端大小</param> public void resetScaleSize(FCSize clientSize) { FCNative native = Native; if (native != null) { FCHost host = native.Host; FCSize nativeSize = native.DisplaySize; List <FCView> controls = native.getControls(); int controlsSize = controls.Count; for (int i = 0; i < controlsSize; i++) { FCWindowFrame frame = controls[i] as FCWindowFrame; if (frame != null) { WindowEx window = frame.getControls()[0] as WindowEx; if (window != null && !window.AnimateMoving) { FCPoint location = window.Location; if (location.x < 10 || location.x > nativeSize.cx - 10) { location.x = 0; } if (location.y < 30 || location.y > nativeSize.cy - 30) { location.y = 0; } window.Location = location; } } } native.ScaleSize = new FCSize((int)(clientSize.cx * m_scaleFactor), (int)(clientSize.cy * m_scaleFactor)); native.update(); } }
/// <summary> /// 获取要绘制的超链接颜色 /// </summary> /// <returns>前景色</returns> protected virtual long getPaintingLinkColor() { if (Enabled) { FCNative native = Native; if (this == native.HoveredControl) { return(m_activeLinkColor); } else if (this == native.PushedControl) { return(m_activeLinkColor); } else { if (m_linkVisited && m_visited) { return(m_visitedLinkColor); } else { return(m_linkColor); } } } else { return(m_disabledLinkColor); } }
/// <summary> /// 退出拖动 /// </summary> public void cancelDragging() { if (IsDragging) { FCNative native = Native; native.cancelDragging(); invalidate(); } }
/// <summary> /// 创建界面 /// </summary> /// <param name="native">方法库</param> public CollectionWindow(FCNative native) { load(native, "CollectionWindow", "windowCollection"); m_tvCollection = getTree("tvCollection"); m_tvCollection.AllowDragRow = true; m_gridProperty = getGrid("gridProperty") as PropertyGrid; m_gridProperty.CollectionWindow = this; //注册点击事件 registerEvents(m_window); }
/// <summary> /// 添加方法 /// </summary> /// <param name="indicator">方法库</param> /// <param name="native">脚本</param> /// <param name="xml">XML</param> /// <returns>指标</returns> public static void addFunctions(FCScript indicator, FCNative native) { string[] functions = FUNCTIONS.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); int functionsSize = functions.Length; for (int i = 0; i < functionsSize; i++) { indicator.addFunction(new NFunctionBase(indicator, STARTINDEX + i, PREFIX + functions[i], native)); } }
/// <summary> /// 获取编辑页偏移 /// </summary> /// <returns>坐标</returns> public FCPoint getDesignerOffset() { FCNative native = Native; int clientX = native.clientX(m_designerTabPage); int clientY = native.clientY(m_designerTabPage); clientX -= (m_designerTabPage.HScrollBar != null ? m_designerTabPage.HScrollBar.Pos : 0); clientY -= (m_designerTabPage.VScrollBar != null ? m_designerTabPage.VScrollBar.Pos : 0); return(new FCPoint(clientX, clientY)); }
/// <summary> /// 重置缩放尺寸 /// </summary> /// <param name="clientSize">客户端大小</param> public void resetScaleSize(FCSize clientSize) { FCNative native = Native; if (native != null) { native.ScaleSize = new FCSize((int)(clientSize.cx * m_scaleFactor), (int)(clientSize.cy * m_scaleFactor)); native.update(); } }
/// <summary> /// 以动画形式隐藏 /// </summary> public void animateHide() { m_animateType = 1; FCNative native = Native; FCHost host = native.Host; m_animateDirection = m_rd.Next(0, 4); startTimer(m_timerID, 10); m_animateMoving = true; host.AllowOperate = false; }
/// <summary> /// Öػ汳¾° /// </summary> /// <param name="paint">»æͼ¶ÔÏó</param> /// <param name="clipRect">²Ã¼ôÇøÓò</param> public override void onPaintBackground(FCPaint paint, FCRect clipRect) { int width = Width; int height = Height; String text = Text; FCFont font = Font; FCSize tSize = paint.textSize(text, font); int drawWidth = tSize.cx + 20; FCRect drawRect = new FCRect(0, 0, width, height); FCNative native = Native; //»æÖƱ³¾° if (this == native.HoveredControl) { paint.fillGradientRect(FCDraw.FCCOLORS_BACKCOLOR5, FCDraw.FCCOLORS_BACKCOLOR6, drawRect, 2, 90); } //»æÖÆͼ±ê String backImage = getPaintingBackImage(); FCRect imageRect = new FCRect(2, (height - 16) / 2, 18, (height + 16) / 2); if (backImage != null && backImage.Length > 0) { paint.fillRect(getPaintingBackColor(), imageRect); paint.drawImage(getPaintingBackImage(), imageRect); } //»æÖÆÎÄ×Ö FCRect tRect = new FCRect(); tRect.left = imageRect.right + 4; tRect.top = (height - tSize.cy) / 2; tRect.right = tRect.left + tSize.cx; tRect.bottom = tRect.top + tSize.cy; paint.drawText(text, getPaintingTextColor(), font, tRect); //»æÖƱßÏß if (this == native.HoveredControl) { paint.drawRoundRect(getPaintingBorderColor(), 1, 0, drawRect, 2); } if (Enabled) { if (this == native.PushedControl) { paint.fillRect(FCDraw.FCCOLORS_BACKCOLOR4, drawRect); } else if (this == native.HoveredControl) { paint.fillRect(FCDraw.FCCOLORS_BACKCOLOR3, drawRect); } } else { paint.fillRect(FCDraw.FCCOLORS_BACKCOLOR7, drawRect); } }
/// <summary> /// 创建界面 /// </summary> /// <param name="native">方法库</param> public ProjectWindow(FCNative native) { load(native, "ProjectWindow", "windowProject"); //注册点击事件 registerEvents(m_window); m_tvTypes = getTree("tvTypes"); m_gridTemplate = getGrid("gridTemplate"); FCTextBox txtPath = getTextBox("txtPath"); txtPath.Text = DataCenter.GetUserPath(); onGridSelectedRowsChanged(); }
/// <summary> /// 加载界面 /// </summary> public virtual void load(FCNative native, String xmlName, String windowName) { Native = native; String xmlPath = DataCenter.getAppPath() + "\\config\\" + xmlName + ".html"; Script = new FaceCatScript(this); loadFile(xmlPath, null); m_window = findControl(windowName) as WindowEx; m_invokeEvent = new FCInvokeEvent(invoke); m_window.addEvent(m_invokeEvent, FCEventID.INVOKE); //注册点击事件 registerEvents(m_window); }
/// <summary> /// 页选中改变方法 /// </summary> public override void onSelectedTabPageChanged() { base.onSelectedTabPageChanged(); if (m_xml != null) { FCNative native = Native; FCTabPage selectedTabPage = SelectedTabPage; if (selectedTabPage != null) { bool modified = Modified; m_canModifyCaption = false; //设计视图 if (selectedTabPage == m_designerTabPage) { if (m_sourceCodeChanged) { if (m_scintilla != null) { String xml = m_scintilla.Text; String error = ""; if (m_xml.checkXml(xml, ref error)) { saveUndo(); openXml(xml); m_sourceCodeChanged = false; } } } } //源代码 else if (selectedTabPage == m_sourceCodeTabPage) { if (m_scintilla != null) { String xml = m_scintilla.Text; if (xml.Length == 0 || modified) { String error = ""; if (xml.Length == 0 || m_xml.checkXml(xml, ref error)) { m_scintilla.loadXml(m_xml.DocumentText.Replace("<", "<")); m_ignoreNextInput = true; } } m_designer.viewSource(); } } m_canModifyCaption = true; } } }
/// <summary> /// 获取正在绘制的背景色 /// </summary> /// <returns></returns> protected override long getPaintingBackColor() { FCNative native = Native; if (m_style == WindowButtonStyle.Close) { if (native.PushedControl == this) { return(FCColor.argb(255, 0, 0)); } else if (native.HoveredControl == this) { return(FCColor.argb(255, 150, 150)); } else { return(FCColor.argb(255, 80, 80)); } } else if (m_style == WindowButtonStyle.Min) { if (native.PushedControl == this) { return(FCColor.argb(0, 255, 0)); } else if (native.HoveredControl == this) { return(FCColor.argb(150, 255, 150)); } else { return(FCColor.argb(80, 255, 80)); } } else { if (native.PushedControl == this) { return(FCColor.argb(255, 255, 0)); } else if (native.HoveredControl == this) { return(FCColor.argb(255, 255, 150)); } else { return(FCColor.argb(255, 255, 80)); } } }
/// <summary> /// 拖动结束方法 /// </summary> public override void onDragEnd() { base.onDragEnd(); int targetsSize = m_targets.Count; FCView divDesigner = Parent; //判定区域 FCNative native = Native; m_designerDiv.saveUndo(); FCPoint mp = Native.TouchPoint; for (int i = 0; i < targetsSize; i++) { FCView target = m_targets[i]; FCView parent = target.Parent; bool outControl = false; FCPoint oldNativeLocation = target.pointToNative(new FCPoint(0, 0)); if (parent != null) { if (divDesigner != null) { //查找新的控件 m_acceptTouch = false; FCView newParent = native.findControl(mp, divDesigner); m_acceptTouch = true; if (newParent != null && m_xml.isContainer(newParent) && newParent != this && newParent != parent && target != newParent) { //移除控件 m_xml.removeControl(target); //添加控件 m_xml.addControl(target, newParent); parent = newParent; outControl = true; } } } if (outControl || canDragTargets()) { FCRect newRect = convertBoundsToPRect(Bounds); oldNativeLocation.x += newRect.left - m_startRect.left; oldNativeLocation.y += newRect.top - m_startRect.top; m_xml.setProperty(target, "location", FCStr.convertPointToStr(target.Parent.pointToControl(oldNativeLocation))); target.update(); } } m_designerDiv.Designer.refreshProperties(); refreshStatusBar(); divDesigner.update(); }
/// <summary> /// 显示右键菜单 /// </summary> /// <param name="var">变量</param> /// <returns>状态</returns> private double SHOWRIGHTMENU(CVariable var) { DesignerScript designerScript = m_xml.Script as DesignerScript; FCNative native = m_xml.Native; FCView control = m_xml.findControl(designerScript.getSender()); int clientX = native.clientX(control); int clientY = native.clientY(control); FCMenu menu = m_xml.getMenu(m_indicator.getText(var.m_parameters[0])); menu.Location = new FCPoint(clientX, clientY + control.Height); menu.Visible = true; menu.Focused = true; menu.bringToFront(); native.invalidate(); return(0); }
/// <summary> /// 窗体关闭事件 /// </summary> /// <param name="e"></param> protected override void OnFormClosing(FormClosingEventArgs e) { base.OnFormClosing(e); List <FCView> controls = m_native.getControls(); int controlsSize = controls.Count; for (int i = 0; i < controlsSize; i++) { m_native.removeMirror(controls[i]); } if (m_native != null) { m_native.delete(); m_native = null; } }
/// <summary> /// 启动监听 /// </summary> public void start() { m_useScript = FCFile.isFileExist(m_fileName); if (m_useScript) { m_native = new FCNative(); FCFile.read(m_fileName, ref m_script); m_indicator = CFunctionEx.CreateScript(m_script, m_native); Console.WriteLine(m_script); } try { //string host = "127.0.0.1"; //IPAddress ip = IPAddress.Parse(host); if (m_indicator != null) { m_indicator.callFunction("ONHTTPSERVERSTARTING('" + m_fileName + "');"); } IPEndPoint ipe = new IPEndPoint(IPAddress.Any, m_port); m_listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); m_listener.Bind(ipe); m_listener.Listen(0); } catch (Exception ex) { if (m_indicator != null) { m_indicator.callFunction("ONHTTPSERVERSTARTFAIL('" + ex.Message + "\r\n" + ex.StackTrace + "');"); } return; } int minThreadNum = 0, portThreadNum = 0, maxThreadNum = 0; ThreadPool.GetMaxThreads(out maxThreadNum, out portThreadNum); ThreadPool.GetMinThreads(out minThreadNum, out portThreadNum); if (m_indicator != null) { m_indicator.callFunction("ONHTTPSERVERSTART(" + FCStr.convertIntToStr(maxThreadNum) + "," + FCStr.convertIntToStr(minThreadNum) + ");"); } while (true) { Socket socket = m_listener.Accept(); ThreadPool.QueueUserWorkItem(new WaitCallback(readData), socket); } m_listener.Close(); }
/// <summary> /// 以动画形式显示 /// </summary> /// <param name="showDialog">是否对话框打开</param> public void animateShow(bool showDialog) { FCNative native = Native; FCSize nativeSize = native.DisplaySize; int width = Width, height = Height, mx = (nativeSize.cx - width) / 2, my = (nativeSize.cy - height) / 2, x = mx, y = my; FCPoint location = new FCPoint(x, y); Location = location; if (showDialog) { this.showDialog(); } else { show(); } update(); }
/// <summary> /// 获取要绘制的背景色 /// </summary> /// <returns>背景色</returns> protected override long getPaintingBackColor() { long backColor = base.getPaintingBackColor(); if (backColor != FCColor.None && isPaintEnabled(this)) { FCNative native = Native; if (this == native.PushedControl) { backColor = FCColor.Pushed; } else if (this == native.HoveredControl) { backColor = FCColor.Hovered; } } return(backColor); }
/// <summary> /// 是否正在调整尺寸 /// </summary> /// <param name="mp">坐标</param> /// <returns>正在调整尺寸</returns> public bool isResizing(FCPoint mp) { FCNative native = Native; int clientX = native.clientX(this); int clientY = native.clientY(this); int width = Width, height = Height; if (mp.x >= clientX && mp.x <= clientX + width && mp.y >= clientY && mp.y <= clientY + height) { mp.x -= clientX; mp.y -= clientY; if (getResizePoint(TouchPoint) != -1) { return(true); } } return(false); }
/// <summary> /// 以动画形式显示 /// </summary> /// <param name="showDialog">是否对话框打开</param> public void animateShow(bool showDialog) { m_animateType = 0; FCNative native = Native; FCHost host = native.Host; FCSize nativeSize = native.DisplaySize; int width = Width, height = Height, mx = (nativeSize.cx - width) / 2, my = (nativeSize.cy - height) / 2, x = mx, y = my; m_animateDirection = m_rd.Next(0, 4); switch (m_animateDirection) { case 0: x = -width; break; case 1: x = nativeSize.cx; break; case 2: y = -height; break; case 3: y = nativeSize.cy; break; } FCPoint location = new FCPoint(x, y); Location = location; if (showDialog) { base.showDialog(); } else { show(); } update(); startTimer(m_timerID, 10); m_animateMoving = true; host.AllowOperate = false; }