Пример #1
0
 public static DcopClient GetDcopClient(String [] args)
 {
     try
     {
         Xsharp.Application app =
             new Xsharp.Application("DcopBrowser", args);
         return(new DcopClient(app.Display, null));
     }
     catch
     {
         return(null);
     }
 }
Пример #2
0
	public static DcopClient GetDcopClient(String [] args)
	{
		try
		{
			Xsharp.Application app = 
					new Xsharp.Application("DcopBrowser", args);
			return new DcopClient(app.Display, null);		
		}
		catch
		{
			return null;
		}
	}
	// Constructor.
	public DrawingToolkit()
			{
				// Create an Xsharp application instance.
				app = new Xsharp.Application(null, null);

				// Register the additional fonts that we required.
				RegisterFonts();

				// Get the placeholder widget for the screen.
				placeholder = app.Display.DefaultScreenOfDisplay.Placeholder;

				// Track changes to RESOURCE_MANAGER on the root window.
				app.Display.DefaultScreenOfDisplay.RootWindow.ResourcesChanged
					+= new EventHandler(ResourcesChanged);

				// And then load the initial state.
				LoadResources();
			}
Пример #4
0
	/// <summary>
	/// <para>Construct a new application object, process command-line
	/// options, and open the display.</para>
	/// </summary>
	///
	/// <param name="name">
	/// <para>The resource name and class for the application.</para>
	/// </param>
	///
	/// <param name="args">
	/// <para>The arguments that came from the application's "Main"
	/// method.</para>
	/// </param>
	///
	/// <exception cref="T:Xsharp.XCannotConnectException">
	/// <para>A connection to the X display server could not
	/// be established.</para>
	/// </exception>
	public Application(String name, String[] args)
			{
				String[] envCmdLine;
				int firstArg = 0;
				String fontName;
				bool synchronous = false;

				// Set this as the primary application object if necessary.
				lock(typeof(Application))
				{
					if(primary == null)
					{
						primary = this;
					}
				}

				// Choose defaults for the parameters.
				try
				{
					envCmdLine = Environment.GetCommandLineArgs();
				}
				catch(NotSupportedException)
				{
					envCmdLine = null;
				}
				if(envCmdLine != null && envCmdLine.Length > 0)
				{
					programName = envCmdLine[0];
				}
				else
				{
					programName = "Xsharp-application";
				}
				if(name == null)
				{
					// Strip the path from the program name to
					// get the default resource name to use.
					int index = programName.LastIndexOf('/');
					if(index == -1)
					{
						index = programName.LastIndexOf('\\');
					}
					if(index != -1)
					{
						name = programName.Substring(index + 1);
					}
					else
					{
						name = programName;
					}
					int len = name.Length;
					if(len > 4 && name[len - 4] == '.' &&
					   (name[len - 3] == 'e' || name[len - 3] == 'E') &&
					   (name[len - 2] == 'x' || name[len - 2] == 'X') &&
					   (name[len - 1] == 'e' || name[len - 1] == 'E'))
					{
						name = name.Substring(0, len - 4);
					}
				}
				if(args == null)
				{
					if(envCmdLine != null && envCmdLine.Length > 0)
					{
						args = envCmdLine;
						firstArg = 1;
					}
					else
					{
						args = new String [0];
					}
				}

				// Initialize the application state.
				resourceName = name;
				resourceClass = name;
				displayName = null;
				startIconic = false;
				title = null;
				geometry = null;
				fontName = null;

				// Process the standard Xt command-line options.
				ArrayList newArgs = new ArrayList();
				while(firstArg < args.Length)
				{
					switch(args[firstArg])
					{
						case "-display":
						{
							++firstArg;
							if(firstArg < args.Length)
							{
								displayName = args[firstArg];
							}
						}
						break;

						case "-iconic":
						{
							startIconic = true;
						}
						break;

						case "-name":
						{
							++firstArg;
							if(firstArg < args.Length)
							{
								resourceName = args[firstArg];
							}
						}
						break;

						case "-title":
						{
							++firstArg;
							if(firstArg < args.Length)
							{
								title = args[firstArg];
							}
						}
						break;

						case "-fn":
						case "-font":
						{
							++firstArg;
							if(firstArg < args.Length)
							{
								fontName = args[firstArg];
							}
						}
						break;

						case "-geometry":
						{
							++firstArg;
							if(firstArg < args.Length)
							{
								geometry = args[firstArg];
							}
						}
						break;

						case "+synchronous":
						case "-synchronous":
						{
							// Turn on synchronous processing to the X server.
							synchronous = true;
						}
						break;

						// Ignore other Xt toolkit options that aren't
						// relevant to us.  We may add some of these later.
						case "-reverse":
						case "-rv":
						case "+rv":
							break;
						case "-bg":
						case "-background":
						case "-bw":
						case "-borderwidth":
						case "-bd":
						case "-bordercolor":
						case "-fg":
						case "-foreground":
						case "-selectionTimeout":
						case "-xnllanguage":
						case "-xrm":
						case "-xtsessionID":
							++firstArg;
							break;

						default:
						{
							// Unknown option - copy it to "newArgs".
							newArgs.Add(args[firstArg]);
						}
						break;
					}
					++firstArg;
				}
				cmdLineArgs = (String[])(newArgs.ToArray(typeof(String)));

				// Connect to the display.
				if(displayName == null)
				{
					// Xlib will figure it by itself, but classes using displayName can get broken is it's null
					displayName = Environment.GetEnvironmentVariable("DISPLAY");
				}

				display = Xsharp.Display.Open(displayName, this, synchronous);

				// Create the default font.
				defaultFont = Font.CreateFromXLFD(fontName);
				defaultFont.GetFontSet(display);
			}
Пример #5
0
	/// <summary>
	/// <para>Close the application if it is currently active.</para>
	/// </summary>
	public void Close()
			{
				lock(typeof(Application))
				{
					if(display != null)
					{
						display.Close();
						display = null;
					}
					if(primary == this)
					{
						primary = null;
					}
				}

			}
Пример #6
0
	// Constructor.
	private Display(IntPtr dpy, String displayName, Application app)
			{
				// Copy parameters in from the create process.
				this.dpy = dpy;
				this.displayName = displayName;
				this.app = app;

				// Create objects for each of the display screens.
				int nscreens = (int)(Xlib.XScreenCount(dpy));
				screens = new Screen [nscreens];
				for(int scr = 0; scr < nscreens; ++scr)
				{
					screens[scr] = new Screen
						(this, scr, Xlib.XScreenOfDisplay(dpy, scr));
				}

				// Get the index of the default screen.
				defaultScreen = (int)(Xlib.XDefaultScreen(dpy));

				// Create an array to hold the standard cursors.
				cursors = new XCursor [(int)(CursorType.XC_num_glyphs)];

				// Reset the time of the last known event.
				knownEventTime = XTime.CurrentTime;

				// Construct the window handle map if not already present.
				if(handleMap == null)
				{
					handleMap = new HandleMap();
				}

				// Initialize the standard window manager atoms that we use.
				wmProtocols = Xlib.XInternAtom
					(dpy, "WM_PROTOCOLS", XBool.False);
				wmDeleteWindow = Xlib.XInternAtom
					(dpy, "WM_DELETE_WINDOW", XBool.False);
				wmTakeFocus = Xlib.XInternAtom
					(dpy, "WM_TAKE_FOCUS", XBool.False);
				wmMwmHints = Xlib.XInternAtom
					(dpy, "_MOTIF_WM_HINTS", XBool.False);
				wmContextHelp = Xlib.XInternAtom
					(dpy, "_NET_WM_CONTEXT_HELP", XBool.False);
				wmState = Xlib.XInternAtom
					(dpy, "WM_STATE", XBool.False);
				wmNetState = Xlib.XInternAtom
					(dpy, "_NET_WM_STATE", XBool.False);
				wmPing = Xlib.XInternAtom
					(dpy, "_NET_WM_PING", XBool.False);
				internalBeginInvoke = Xlib.XInternAtom
					(dpy, "INTERNAL_BEGIN_INVOKE", XBool.False);

				// Which buttons should we use for "Select" and "Menu"?
				byte[] buttons = new byte [5];
				if(Xlib.XGetPointerMapping(dpy, buttons, 5) == 3)
				{
					menuButton = ButtonName.Button3;
				}
				else
				{
					menuButton = ButtonName.Button2;
				}
				selectButton = ButtonName.Button1;

				// Construct the font map.
				fonts = new Hashtable();

				// Load the builtin bitmaps.
				bitmaps = new BuiltinBitmaps(this);
			}
Пример #7
0
	// Open a connection to a specific X display server.
	internal static Display Open(String displayName, Application app, bool sync)
			{
				lock(typeof(Display))
				{
					return OpenInternal(displayName, app, sync);
				}
			}
Пример #8
0
	// Internal version of "Open()" that is called once the
	// type lock has been acquired.
	private static Display OpenInternal
				(String displayName, Application app, bool sync)
			{
				try
				{
					if(Xlib.XSharpSupportPresent() == 0)
					{
						Console.WriteLine();
						Console.WriteLine
							("The XsharpSupport library appears to have " +
							 "been built without X support.");
						Console.WriteLine
							("Please rebuild pnetlib to rectify this problem.");
						Console.WriteLine();
						throw new XCannotConnectException
							(S._("X_LibraryNotPresent"));
					}
					try
					{
						// Initialize Xlib thread support.
						if(!threadsInited)
						{
							threadsInited = true;
							Xlib.XInitThreads();
						}
					}
					catch(MissingMethodException)
					{
						// The "X11" library may not have support for
						// threads, which is OK(-ish) because we will
						// be locking every access to the display anyway.
					}
					catch(EntryPointNotFoundException)
					{
						// Same as above.
					}
					IntPtr dpy = Xlib.XOpenDisplay(displayName);
					if(dpy != IntPtr.Zero)
					{
						// We have opened the display successfully.
						if(sync)
						{
							Xlib.XSynchronize(dpy, XBool.True);
						}
						return new Display(dpy, displayName, app);
					}
					else
					{
						// We were unable to connect to the display.
						if(displayName != null)
						{
							throw new XCannotConnectException
								(String.Format(S._("X_CannotOpenTo"),
											   displayName));
						}
						else
						{
							throw new XCannotConnectException
								(S._("X_CannotOpen"));
						}
					}
				}
				catch(MissingMethodException)
				{
					// The engine was unable to locate "XOpenDisplay",
					// so we probably don't have an X library, or it
					// is not on the LD_LIBRARY_PATH.
					throw new XCannotConnectException
						(S._("X_LibraryNotPresent"));
				}
				catch(DllNotFoundException de)
				{
					throw new XCannotConnectException
						(S._("X_LibraryNotPresent"), de);
				}
				catch(EntryPointNotFoundException ee)
				{
					throw new XCannotConnectException
						(S._("X_LibraryNotPresent"), ee);
				}
			}