Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » "Balloon Tip": Shell Focus problem
"Balloon Tip": Shell Focus problem [message #439844] Sun, 18 July 2004 10:40 Go to next message
Benjamin Pasero is currently offline Benjamin PaseroFriend
Messages: 337
Registered: July 2009
Senior Member
Hi,

I am using an ON_TOP, NO_TRIM Shell as small popup that appears over the
systemtray to alert the user. That is working, but when calling the open()
Method on that Shell it grabs focus. This is very annoying when the user
is working with a another application and suddely looses focus to the
popup.

I am now calling setVisible(true) instead of open(), and the focus is not
lost. But I am not sure if setVisible() is intended for a Shell that was
not opened yet. I noticed, that calling setVisible() on the Shell that
normally does not appear in the Alt-Tab Menu of Windows, appears with no
text and no image as an entry in that Menu.

Is there a better way to have a shell open without grabbing focus?

Ben
Re: "Balloon Tip": Shell Focus problem [message #439848 is a reply to message #439844] Sun, 18 July 2004 16:04 Go to previous messageGo to next message
Vadalus is currently offline VadalusFriend
Messages: 24
Registered: July 2009
Junior Member
Hi,

Here's how I solved the problem with BalloonText. Just implement a new
version TrayItem (I called it TrayItemEx) which has a setBalloonText()
method. All this does is change the flags in the NOTIFYICONDATA to
change the text from a tooltip to a proper windowsXP balloon tip (none
of your focus problems!). This requires no modification to the native
code. The only slightly annoying thing is that you have a have this
class in the org.eclipse.swt.widgets package. Oh and i guess this is
windowsXP specific?

The only thing which does not work at the moment is the "timeout" this
requires the eclipse guys to expose an additional property on the
NOTIFYICONDATA.. Maybe they'll do it one day.

Thanks

L

package org.eclipse.swt.widgets;


import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.internal.win32.NOTIFYICONDATA;
import org.eclipse.swt.internal.win32.NOTIFYICONDATAA;
import org.eclipse.swt.internal.win32.NOTIFYICONDATAW;
import org.eclipse.swt.internal.win32.OS;
import org.eclipse.swt.internal.win32.TCHAR;

/**
* Instances of this class represent icons that can be placed on the
* system tray or task bar status area.
*
* <dl>
* <dt><b>Styles:</b></dt>
* <dd>(none)</dd>
* <dt><b>Events:</b></dt>
* <dd>DefaultSelection, MenuDetect, Selection</dd>
* </dl>
* <p>
* IMPORTANT: This class is <em>not</em> intended to be subclassed.
* </p>
*
* @since 3.0
*/
public class TrayItemEx extends TrayItem {

public static final int ERROR = OS.NIIF_ERROR;
public static final int INFO = OS.NIIF_INFO;
public static final int NONE = OS.NIIF_NONE;
public static final int WARNING = OS.NIIF_WARNING;
/**/
/**
* Constructs a new instance of this class given its parent
* (which must be a <code>Tray</code>) and a style value
* describing its behavior and appearance. The item is added
* to the end of the items maintained by its parent.
* <p>
* The style value is either one of the style constants defined in
* class <code>SWT</code> which is applicable to instances of this
* class, or must be built by <em>bitwise OR</em>'ing together
* (that is, using the <code>int</code> "|" operator) two or more
* of those <code>SWT</code> style constants. The class description
* lists the style constants that are applicable to the class.
* Style bits are also inherited from superclasses.
* </p>
*
* @param parent a composite control which will be the parent of the
new instance (cannot be null)
* @param style the style of control to construct
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread
that created the parent</li>
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed
subclass</li>
* </ul>
*
* @see SWT
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
public TrayItemEx (Tray parent, int style)
{
super (parent, style);
/* this.parent = parent;
parent.createItem (this, parent.getItemCount ());
if (OS.IsWinCE) return;
NOTIFYICONDATA iconData = OS.IsUnicode ? (NOTIFYICONDATA) new
NOTIFYICONDATAW () : new NOTIFYICONDATAA ();
iconData.cbSize = NOTIFYICONDATA.sizeof;
iconData.uID = id = display.nextTrayId++;
iconData.hWnd = display.hwndMessage;
iconData.uFlags = OS.NIF_MESSAGE;
iconData.uCallbackMessage = Display.SWT_TRAYICONMSG;
OS.Shell_NotifyIcon (OS.NIM_ADD, iconData);
*/}

public void setBalloonText (int iconState, String title, String text,
int msTimeout) {
checkWidget ();
if (OS.IsWinCE) return;
NOTIFYICONDATA iconData = OS.IsUnicode ? (NOTIFYICONDATA) new
NOTIFYICONDATAW () : new NOTIFYICONDATAA ();
TCHAR buffer1 = new TCHAR (0, title == null ? "" : title, true);
TCHAR buffer2 = new TCHAR (0, text == null ? "" : text, true);
/*
* Note that the size of the szTip field is different
* in version 5.0 of shell32.dll.
*/
int length1 = OS.SHELL32_MAJOR < 5 ? 64 : 128;
int length2 = OS.SHELL32_MAJOR < 5 ? 64 : 128;

if (OS.IsUnicode) {
char [] szInfo = ((NOTIFYICONDATAW) iconData).szInfo;
char [] szInfoTitle = ((NOTIFYICONDATAW) iconData).szInfoTitle;
length1 = Math.min (length1 - 1, buffer1.length ());
System.arraycopy (buffer1.chars, 0, szInfoTitle, 0, length1);
length2 = Math.min (length2 - 1, buffer2.length ());
System.arraycopy (buffer2.chars, 0, szInfo, 0, length2);
} else {
byte [] szInfo = ((NOTIFYICONDATAA) iconData).szInfo;
byte [] szInfoTitle = ((NOTIFYICONDATAA) iconData).szInfoTitle;
length1 = Math.min (length1 - 1, buffer1.length ());
System.arraycopy (buffer1.bytes, 0, szInfoTitle, 0, length1);
length2 = Math.min (length2 - 1, buffer2.length ());
System.arraycopy (buffer2.bytes, 0, szInfo, 0, length2);
}
iconData.cbSize = NOTIFYICONDATA.sizeof;
iconData.uID = id;
iconData.hWnd = display.hwndMessage;
iconData.uFlags = OS.NIF_INFO;
iconData.dwInfoFlags = iconState;
iconData.uVersion = msTimeout;

OS.Shell_NotifyIcon (OS.NIM_MODIFY, iconData);
}

}



Benjamin Pasero wrote:
> Hi,
>
> I am using an ON_TOP, NO_TRIM Shell as small popup that appears over the
> systemtray to alert the user. That is working, but when calling the
open()
> Method on that Shell it grabs focus. This is very annoying when the user
> is working with a another application and suddely looses focus to the
> popup.
>
> I am now calling setVisible(true) instead of open(), and the focus is not
> lost. But I am not sure if setVisible() is intended for a Shell that was
> not opened yet. I noticed, that calling setVisible() on the Shell that
> normally does not appear in the Alt-Tab Menu of Windows, appears with no
> text and no image as an entry in that Menu.
>
> Is there a better way to have a shell open without grabbing focus?
>
> Ben
>


Benjamin Pasero wrote:

> Hi,
>
> I am using an ON_TOP, NO_TRIM Shell as small popup that appears over the
> systemtray to alert the user. That is working, but when calling the open()
> Method on that Shell it grabs focus. This is very annoying when the user
> is working with a another application and suddely looses focus to the
> popup.
>
> I am now calling setVisible(true) instead of open(), and the focus is not
> lost. But I am not sure if setVisible() is intended for a Shell that was
> not opened yet. I noticed, that calling setVisible() on the Shell that
> normally does not appear in the Alt-Tab Menu of Windows, appears with no
> text and no image as an entry in that Menu.
>
> Is there a better way to have a shell open without grabbing focus?
>
> Ben
>
Re: "Balloon Tip": Shell Focus problem [message #439849 is a reply to message #439848] Sun, 18 July 2004 17:31 Go to previous messageGo to next message
Benjamin Pasero is currently offline Benjamin PaseroFriend
Messages: 337
Registered: July 2009
Senior Member
Hi Vadalus,

thanks for your implementation, but I am in need of a solution that
also runs on Linux. The "balloon" I implemented is not a real, native
balloon tip, its just a small Shell that appears above the system
tray.

I think SWT's API should offer a way to open a Shell without having to
set focus on it.

I am now using setVisible(true), but looking in the open() Method,
there are more things done than setting focus and making the Shell
visible. But to keep my sourcecode platform independant, I dont
want to copy what is done in the open() Method.

I'll open a feature request on that topic, if there is no known
solution for that.

Regards,
Ben

> Hi,

> Here's how I solved the problem with BalloonText. Just implement a new
> version TrayItem (I called it TrayItemEx) which has a setBalloonText()
> method. All this does is change the flags in the NOTIFYICONDATA to
> change the text from a tooltip to a proper windowsXP balloon tip (none
> of your focus problems!). This requires no modification to the native
> code. The only slightly annoying thing is that you have a have this
> class in the org.eclipse.swt.widgets package. Oh and i guess this is
> windowsXP specific?

> The only thing which does not work at the moment is the "timeout" this
> requires the eclipse guys to expose an additional property on the
> NOTIFYICONDATA.. Maybe they'll do it one day.

> Thanks

> L

> package org.eclipse.swt.widgets;


> import org.eclipse.swt.SWT;
> import org.eclipse.swt.SWTException;
> import org.eclipse.swt.internal.win32.NOTIFYICONDATA;
> import org.eclipse.swt.internal.win32.NOTIFYICONDATAA;
> import org.eclipse.swt.internal.win32.NOTIFYICONDATAW;
> import org.eclipse.swt.internal.win32.OS;
> import org.eclipse.swt.internal.win32.TCHAR;

> /**
> * Instances of this class represent icons that can be placed on the
> * system tray or task bar status area.
> *
> * <dl>
> * <dt><b>Styles:</b></dt>
> * <dd>(none)</dd>
> * <dt><b>Events:</b></dt>
> * <dd>DefaultSelection, MenuDetect, Selection</dd>
> * </dl>
> * <p>
> * IMPORTANT: This class is <em>not</em> intended to be subclassed.
> * </p>
> *
> * @since 3.0
> */
> public class TrayItemEx extends TrayItem {

> public static final int ERROR = OS.NIIF_ERROR;
> public static final int INFO = OS.NIIF_INFO;
> public static final int NONE = OS.NIIF_NONE;
> public static final int WARNING = OS.NIIF_WARNING;
> /**/
> /**
> * Constructs a new instance of this class given its parent
> * (which must be a <code>Tray</code>) and a style value
> * describing its behavior and appearance. The item is added
> * to the end of the items maintained by its parent.
> * <p>
> * The style value is either one of the style constants defined in
> * class <code>SWT</code> which is applicable to instances of this
> * class, or must be built by <em>bitwise OR</em>'ing together
> * (that is, using the <code>int</code> "|" operator) two or more
> * of those <code>SWT</code> style constants. The class description
> * lists the style constants that are applicable to the class.
> * Style bits are also inherited from superclasses.
> * </p>
> *
> * @param parent a composite control which will be the parent of the
> new instance (cannot be null)
> * @param style the style of control to construct
> *
> * @exception IllegalArgumentException <ul>
> * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
> * </ul>
> * @exception SWTException <ul>
> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread
> that created the parent</li>
> * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed
> subclass</li>
> * </ul>
> *
> * @see SWT
> * @see Widget#checkSubclass
> * @see Widget#getStyle
> */
> public TrayItemEx (Tray parent, int style)
> {
> super (parent, style);
> /* this.parent = parent;
> parent.createItem (this, parent.getItemCount ());
> if (OS.IsWinCE) return;
> NOTIFYICONDATA iconData = OS.IsUnicode ? (NOTIFYICONDATA) new
> NOTIFYICONDATAW () : new NOTIFYICONDATAA ();
> iconData.cbSize = NOTIFYICONDATA.sizeof;
> iconData.uID = id = display.nextTrayId++;
> iconData.hWnd = display.hwndMessage;
> iconData.uFlags = OS.NIF_MESSAGE;
> iconData.uCallbackMessage = Display.SWT_TRAYICONMSG;
> OS.Shell_NotifyIcon (OS.NIM_ADD, iconData);
> */}

> public void setBalloonText (int iconState, String title, String text,
> int msTimeout) {
> checkWidget ();
> if (OS.IsWinCE) return;
> NOTIFYICONDATA iconData = OS.IsUnicode ? (NOTIFYICONDATA) new
> NOTIFYICONDATAW () : new NOTIFYICONDATAA ();
> TCHAR buffer1 = new TCHAR (0, title == null ? "" : title, true);
> TCHAR buffer2 = new TCHAR (0, text == null ? "" : text, true);
> /*
> * Note that the size of the szTip field is different
> * in version 5.0 of shell32.dll.
> */
> int length1 = OS.SHELL32_MAJOR < 5 ? 64 : 128;
> int length2 = OS.SHELL32_MAJOR < 5 ? 64 : 128;

> if (OS.IsUnicode) {
> char [] szInfo = ((NOTIFYICONDATAW) iconData).szInfo;
> char [] szInfoTitle = ((NOTIFYICONDATAW) iconData).szInfoTitle;
> length1 = Math.min (length1 - 1, buffer1.length ());
> System.arraycopy (buffer1.chars, 0, szInfoTitle, 0, length1);
> length2 = Math.min (length2 - 1, buffer2.length ());
> System.arraycopy (buffer2.chars, 0, szInfo, 0, length2);
> } else {
> byte [] szInfo = ((NOTIFYICONDATAA) iconData).szInfo;
> byte [] szInfoTitle = ((NOTIFYICONDATAA) iconData).szInfoTitle;
> length1 = Math.min (length1 - 1, buffer1.length ());
> System.arraycopy (buffer1.bytes, 0, szInfoTitle, 0, length1);
> length2 = Math.min (length2 - 1, buffer2.length ());
> System.arraycopy (buffer2.bytes, 0, szInfo, 0, length2);
> }
> iconData.cbSize = NOTIFYICONDATA.sizeof;
> iconData.uID = id;
> iconData.hWnd = display.hwndMessage;
> iconData.uFlags = OS.NIF_INFO;
> iconData.dwInfoFlags = iconState;
> iconData.uVersion = msTimeout;

> OS.Shell_NotifyIcon (OS.NIM_MODIFY, iconData);
> }

> }



> Benjamin Pasero wrote:
> > Hi,
> >
> > I am using an ON_TOP, NO_TRIM Shell as small popup that appears over the
> > systemtray to alert the user. That is working, but when calling the
> open()
> > Method on that Shell it grabs focus. This is very annoying when the user
> > is working with a another application and suddely looses focus to the
> > popup.
> >
> > I am now calling setVisible(true) instead of open(), and the focus is not
> > lost. But I am not sure if setVisible() is intended for a Shell that was
> > not opened yet. I noticed, that calling setVisible() on the Shell that
> > normally does not appear in the Alt-Tab Menu of Windows, appears with no
> > text and no image as an entry in that Menu.
> >
> > Is there a better way to have a shell open without grabbing focus?
> >
> > Ben
> >


> Benjamin Pasero wrote:

> > Hi,
> >
> > I am using an ON_TOP, NO_TRIM Shell as small popup that appears over the
> > systemtray to alert the user. That is working, but when calling the open()
> > Method on that Shell it grabs focus. This is very annoying when the user
> > is working with a another application and suddely looses focus to the
> > popup.
> >
> > I am now calling setVisible(true) instead of open(), and the focus is not
> > lost. But I am not sure if setVisible() is intended for a Shell that was
> > not opened yet. I noticed, that calling setVisible() on the Shell that
> > normally does not appear in the Alt-Tab Menu of Windows, appears with no
> > text and no image as an entry in that Menu.
> >
> > Is there a better way to have a shell open without grabbing focus?
> >
> > Ben
> >
Re: "Balloon Tip": Shell Focus problem [message #439930 is a reply to message #439844] Mon, 19 July 2004 16:39 Go to previous message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
Shell.setVisible() is intended to show the shell only and not set focus. On
some platforms (X systems), the window manager forces focus to shells that
were not created with SWT.ON_TOP.

"Benjamin Pasero" <bpasero@rssowl.org> wrote in message
news:cddk37$q3$1@eclipse.org...
> Hi,
>
> I am using an ON_TOP, NO_TRIM Shell as small popup that appears over the
> systemtray to alert the user. That is working, but when calling the open()
> Method on that Shell it grabs focus. This is very annoying when the user
> is working with a another application and suddely looses focus to the
> popup.
>
> I am now calling setVisible(true) instead of open(), and the focus is not
> lost. But I am not sure if setVisible() is intended for a Shell that was
> not opened yet. I noticed, that calling setVisible() on the Shell that
> normally does not appear in the Alt-Tab Menu of Windows, appears with no
> text and no image as an entry in that Menu.
>
> Is there a better way to have a shell open without grabbing focus?
>
> Ben
>
Previous Topic:Why TableTreeViewer items are not whole length?
Next Topic:Help! setLineBackground doesn't work well with wrapped text in StyledText widget.
Goto Forum:
  


Current Time: Thu Apr 25 14:24:12 GMT 2024

Powered by FUDForum. Page generated in 0.03119 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top