[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: IUP - Minimizing and restoring programmatically
- From: "Mark Meijer" <meijer78@...>
- Date: Fri, 23 Dec 2005 13:10:25 +0000
Thanks again regarding my previous questions. Obviously I got to it
yesterday to revisit the tray functionality of the app in question, and
bumped into a few more problems. The app's main dialog should minimize to
the system tray, but I'm not sure if I'm going about it the right way.
Particularly because I can't seem to bring the dialog back up
programmatically (i.e. using the tray popup menu).
Minimizing appears to work fine, either using the regular minimize button on
the dialog, or using the designated menu item from the tray popup menu. When
using the tray menu, its action callback minimizes the dialog with
dlg.placement = "MINIMIZE" followed by dlg:show(). The show_cb of the dialog
gets called with the mode argument set to 2, as expected when it gets
minimized, and there it does self.hidetaskbar = "YES" successfully, and the
tray menu item title is changed from "Hide" to "Show" (I did consider truely
hiding the dialog by means of dlg:hide() but that leaves no other dialogs
open, and thus causes IUP to quit the mainloop irrevocably).
When I try to bring the dialog back up using the tray menu (as the taskbar
button is gone), well, it doesn't come back up. The action callback of the
tray menu item tries to restore the dialog with dlg.placement = "NORMAL" and
dlg:show(). When this happens, the button reappears back into the taskbar,
but the dialog stays minimized. The show_cb gets called with mode == 0, as
always, which is ignored by my code there. But it does not get called with
mode == 1, probably because the dialog is not actually restored. So, oddly,
it turns out that it's not (directly) my code that un-hides the taskbar
button.
The show_cb then is where my code would set self.hidetaskbar = "NO" and
change the tray menu item from "Show" back to "Hide", if it would ever get
there (e.g. when it gets mode == 1). But it does not, indeed the menu item
title remains unchanged. It's not clear to me why the taskbar button
magically reappears and the dialog does not. Note that once the taskbar
button reappears, clicking on it will restore the dialog (and calls show_cb
with mode == 1) as expected. I just can't get it to restore
programmatically.
If I try dlg.placement = "MAXIMIZED" (instead of "NORMAL") in the tray menu
item's action callback, then the dialog gets maximized as expected. And then
the show_cb gets called with mode == 1. So I tried maximizing it first just
to have the dialog come back up, and then trying to restore it to its
original size in the same way as before, but it stays maximized. In any
event, setting dlg.placement = "NORMAL" does not seem to have any effect at
all. I've also tried refresh, show and showXY in all kinds of combinations,
but to no avail.
Furthermore, once I've used that tray menu to try and get the dialog back
up, the iup.MainLoop doesn't return anymore when the dialog is closed
(although the dialog itself closes and its close_cb gets called). This means
the app doesn't shut down (which I only noticed because the I/O console
stays open) Another (probably unrelated) problem is that the other item in
my little tray menu, which looks like this... iup.item {title = "Exit",
action = function() return iup.CLOSE; end}; ...doesn't seem to have any
effect. The callback is called, but nothing happens when iup.CLOSE is
returned.
By the way I didn't move to IUP 2.4 final yet, the current build of my app
is statically linked to the prebuilt VC6 libs of IUP version 2.4b, and to
lua 5.0.2.
I've reduced my code to the following little test proggie for purposes of
reproducing the problems. All it needs is lua and IUP (for example the
prebuilt iuplua5.exe binary download).
-----8<----------8<--[snip]--8<----------8<----------
local MainDialog = nil;
local function Hide(dlg)
if dlg then
dlg.placement = "MINIMIZED";
dlg:show();
end
end
local function Show(dlg)
if dlg then
dlg.placement = "NORMAL";
dlg:show();
end
end
local TrayMenuToggle = iup.item {
title = "Hide";
action = function(self)
local text = self.title;
if text == "Hide" then Hide(MainDialog); else Show(MainDialog); end
end;
};
local TrayMenu = iup.menu {
TrayMenuToggle;
iup.item {title = "Exit", action = function() return iup.CLOSE; end};
};
MainDialog = iup.dialog {
title = "MyApp";
icon = "MyIcon";
maxbox = "NO";
resize = "NO";
tray = "YES";
traytip = "Hello World";
trayimage = "MyIcon";
iup.label{title = " Hello World "};
trayclick_cb = function()
TrayMenu:popup(iup.MOUSEPOS, iup.MOUSEPOS);
end;
show_cb = function(self, mode)
if 1 == mode then -- Restore
TrayMenuToggle.title = "Hide";
self.hidetaskbar = "NO";
elseif 2 == mode then -- Minimize
TrayMenuToggle.title = "Show";
self.hidetaskbar = "YES";
else -- Show dialog (mode == 0)
--iup.Message("Just checking...", tostring(mode));
end
end;
close_cb = function(self)
self.tray = "NO";
return iup.CLOSE;
end;
};
MainDialog:show();
iup.MainLoop();
----->8---------->8--[snip]-->8---------->8----------
Does anyone have any clues what's going wrong?