You are on page 1of 4

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using unoidl.com.sun.star.lang;
using unoidl.com.sun.star.uno;
using unoidl.com.sun.star.bridge;
using unoidl.com.sun.star.frame;
using unoidl.com.sun.star.document;
using System.Threading;
using unoidl.com.sun.star.beans;
using unoidl.com.sun.star.container;
using unoidl.com.sun.star.util;
namespace DCT
{
public delegate void ChangedEventHandler(object sender, EventArgs e);
public partial class inherit : unoidl.com.sun.star.frame.XTerminateListener,
unoidl.com.sun.star.frame.XFrameActionListener
{
public string sam = "";
bool need2Terminate = false;
public static XComponent xcomponent;
XComponentLoader componentLoader;
XMultiServiceFactory multiServiceFactory;
XDesktop desktop;
XFrame xf;
MenuInterceptor mi;
reflect r;
public inherit()
{
r = new reflect();
}
public void takeReference()
{
mi = new MenuInterceptor();
unoidl.com.sun.star.uno.XComponentContext localContext = uno.util.Bo
otstrap.bootstrap();
multiServiceFactory = (XMultiServiceFactory)localContext.getServiceM
anager();
componentLoader = (XComponentLoader)multiServiceFactory.createInstan
ce("com.sun.star.frame.Desktop");
desktop = (XDesktop)componentLoader;
xf = desktop.getCurrentFrame();
xf.addFrameActionListener(this);
XDispatchProviderInterception xdispatch = (XDispatchProviderIntercep
tion)xf;
xdispatch.registerDispatchProviderInterceptor(mi);
mi.changed += new ChangedEventHandler(mi_changed);
}
void mi_changed(object sender, EventArgs e)
{
addin ad = new addin();
ad.ShowDialog();
if (reflect.sam != "")
{
Thread t1 = new Thread(new ThreadStart(r.my_thread));
t1.Start();
}
}
public void thread_method()
{
System.Windows.Forms.DialogResult dr = System.Windows.Forms.MessageB
ox.Show("Do you want to classify the document", "Genpact Classifications", Syste
m.Windows.Forms.MessageBoxButtons.YesNo);
if (dr.ToString().ToLower() == "yes")
{
addin ad = new addin();
ad.ShowDialog();
if (reflect.sam != "")
{
Thread t1 = new Thread(new ThreadStart(r.my_thread));
t1.Priority = ThreadPriority.Highest;
t1.Start();
t1.Join();
}
}
need2Terminate = true;
}
public void frameAction(unoidl.com.sun.star.frame.FrameActionEvent fae)
{
if (fae.Action == FrameAction.FRAME_UI_DEACTIVATING)
{
if (need2Terminate == false)
desktop.addTerminateListener(this);
else
{
desktop.removeTerminateListener(this);
need2Terminate = true;
}
}
}
public void disposing(unoidl.com.sun.star.lang.EventObject eventObj)
{

}
public void queryTermination(unoidl.com.sun.star.lang.EventObject eventO
bj)
{
if (need2Terminate == false)
{
Thread t = new Thread(thread_method);
t.Start();
need2Terminate = true;
throw new TerminationVetoException();
}
}
public void notifyTermination(unoidl.com.sun.star.lang.EventObject event
Obj)
{
}

}
public class MenuInterceptor : inherit, XDispatchProviderInterceptor, XDispa
tch
{
private XDispatchProvider xDispatchProviderMaster;
private XDispatchProvider xDispatchProviderSlave;
private XComponent xComponent;
static int i = 0;
public event ChangedEventHandler changed;
public MenuInterceptor()
{
//empty
}
public XDispatch queryDispatch(URL url, String target, int searchFlags)
{
if (url.Protocol.CompareTo("com.example.addon1:") == 0)
{
if (url.Path.CompareTo("Command1") == 0)
{
return this;
}
}
if (xDispatchProviderSlave != null)
{
return xDispatchProviderSlave.queryDispatch(url, target, searchF
lags);
}
return null;
}

public XDispatch[] queryDispatches(DispatchDescriptor[] descriptor)


{
int count = descriptor.Length;
XDispatch[] xDispatch = new XDispatch[count];
for (int i = 0; i < count; i++)
{
xDispatch[i] = queryDispatch(descriptor[i].FeatureURL, descripto
r[i].FrameName, descriptor[i].SearchFlags);
}
return xDispatch;
}
public XDispatchProvider getSlaveDispatchProvider()
{
return xDispatchProviderSlave;
}
public void setSlaveDispatchProvider(XDispatchProvider xDispatchProvider
Slave)
{
this.xDispatchProviderSlave = xDispatchProviderSlave;
}
public XDispatchProvider getMasterDispatchProvider()
{
return xDispatchProviderMaster;
}
public void setMasterDispatchProvider(XDispatchProvider xDispatchProvide
rMaster)
{
this.xDispatchProviderMaster = xDispatchProviderMaster;
}
public void dispatch(URL url, PropertyValue[] propertyValueArray)
{
}
public void addStatusListener(XStatusListener xStatusListener, URL url)
{
if (url.Path.CompareTo("Command1") == 0)
{
changed(this, EventArgs.Empty);
}
}
public void removeStatusListener(XStatusListener xStatusListener, URL ur
l)
{
}
}

You might also like