--- wmprog.cc	2007-01-29 20:47:03.000000000 +0100
+++ ../../../d/icewm-1.3-dev/src/wmprog.cc	2007-01-25 10:42:25.000000000 +0100
@@ -19,7 +19,6 @@
 #include "objbutton.h"
 #include "objbar.h"
 #include "prefs.h"
-#include "yprefs.h"
 #include "wmapp.h"
 #include "sysdep.h"
 #include "base.h"
@@ -34,11 +33,11 @@
 extern bool parseKey(const char *arg, KeySym *key, unsigned int *mod);
 
 DObjectMenuItem::DObjectMenuItem(DObject *object):
-    YMenuItem(object->getName(), -3, 0, this, 0)
+    YMenuItem(object->getName(), -3, null, this, 0)
 {
     fObject = object;
 #ifndef LITE
-    if (object->getIcon())
+    if (object->getIcon() != null)
         setIcon(object->getIcon());
 #endif
 }
@@ -54,16 +53,15 @@
     fObject->open();
 }
 
-DFile::DFile(const char *name, YIcon *icon, const char *path): DObject(name, icon) {
-    fPath = strdup(path);
+DFile::DFile(const ustring &name, ref<YIcon> icon, upath path): DObject(name, icon) {
+    fPath = path;
 }
 
 DFile::~DFile() {
-    delete[] fPath;
 }
 
 void DFile::open() {
-    const char *args[] = { openCommand, fPath, 0 };
+    const char *args[] = { openCommand, cstring(fPath.path()).c_str(), 0 };
     app->runProgram(openCommand, args);
 }
 
@@ -83,9 +81,9 @@
 }
 
 #ifdef LITE
-void ObjectMenu::addContainer(char *name, YIcon */*icon*/, ObjectContainer *container) {
+void ObjectMenu::addContainer(const ustring &name, ref<YIcon> /*icon*/, ObjectContainer *container) {
 #else
-void ObjectMenu::addContainer(char *name, YIcon *icon, ObjectContainer *container) {
+void ObjectMenu::addContainer(const ustring &name, ref<YIcon> icon, ObjectContainer *container) {
 #endif
     if (container) {
 #ifndef LITE
@@ -94,75 +92,65 @@
             addSubmenu(name, -3, (ObjectMenu *)container);
 
 #ifndef LITE
-        if (item && icon)
+        if (item && icon != null)
             item->setIcon(icon);
 #endif
     }
 }
 
-DObject::DObject(const char *name, YIcon *icon) {
-    fName = newstr(name);
-    fIcon = icon;
+DObject::DObject(const ustring &name, ref<YIcon> icon):
+    fName(name), fIcon(icon)
+{
 }
 
 DObject::~DObject() {
-    delete[] fName; fName = 0;
-    //delete fIcon;
-    fIcon = 0; // !!! icons cached forever
+    fIcon = null;
 }
 
 void DObject::open() {
 }
 
-DProgram::DProgram(const char *name, YIcon *icon, const bool restart,
-                   const char *wmclass, const char *exe, YStringArray &args):
+DProgram::DProgram(const ustring &name, ref<YIcon> icon, const bool restart,
+                   const char *wmclass, upath exe, YStringArray &args):
     DObject(name, icon), fRestart(restart),
-    fRes(newstr(wmclass)), fCmd(newstr(exe)), fArgs(args) {
+    fRes(newstr(wmclass)), fCmd(exe), fArgs(args)
+{
     if (fArgs.isEmpty() || fArgs.getString(fArgs.getCount() - 1))
         fArgs.append(0);
 }
 
 DProgram::~DProgram() {
-    delete[] fCmd;
     delete[] fRes;
 }
 
 void DProgram::open() {
     if (fRestart)
-        wmapp->restartClient(fCmd, fArgs.getCArray());
+        wmapp->restartClient(cstring(fCmd.path()).c_str(), fArgs.getCArray());
     else if (fRes)
-        wmapp->runOnce(fRes, fCmd, fArgs.getCArray());
+        wmapp->runOnce(fRes, cstring(fCmd.path()).c_str(), fArgs.getCArray());
     else
-        app->runProgram(fCmd, fArgs.getCArray());
+        app->runProgram(cstring(fCmd.path()).c_str(), fArgs.getCArray());
 }
 
-DProgram *DProgram::newProgram(const char *name,  YIcon *
-#ifndef LITE //LXP FX
-icon
-#endif
-                               ,const bool restart, const char *wmclass,
-                               const char *exe, YStringArray &args) {
-    char *fullname(NULL);
-
-    MSG(("LOOKING FOR: %s\n", exe));
-    if (exe && exe[0] &&  // updates command with full path
-        NULL == (fullname = findPath(getenv("PATH"), X_OK, exe))) {
-        MSG(("Program %s (%s) not found.", name, exe));
+DProgram *DProgram::newProgram(const char *name, ref<YIcon> icon,
+                               const bool restart, const char *wmclass,
+                               upath exe, YStringArray &args) {
+
+    if (exe != null) {
+        MSG(("LOOKING FOR: %s\n", cstring(exe.path()).c_str()));
+        upath fullname = findPath(getenv("PATH"), X_OK, exe);
+        if (fullname == null) {
+            MSG(("Program %s (%s) not found.", name, cstring(exe.path()).c_str()));
         return 0;
     }
 
     DProgram *program =
-        new DProgram(name, 
-#ifndef LITE
-            icon && icon->getScaledIcon(menuIconSize)!=null?icon:Icon_Program, 
-#else	
-	    NULL,
-#endif
-	    restart, wmclass, fullname, args); //LXP SEE
+            new DProgram(name, icon, restart, wmclass, fullname, args); //MCMCMCMCM
 
-    delete[] fullname;
     return program;
 }
+    return NULL;
+}
 
 char *getWord(char *word, int maxlen, char *p) {
     while (*p && (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n'))
@@ -178,7 +166,7 @@
 static char *getCommandArgs(char *p, char **command,
                             YStringArray &args)
 {
-    p = getArgument(command, p, false);
+    p = YConfig::getArgument(command, p, false);
     if (p == 0) {
         msg(_("Missing command argument"));
         return p;
@@ -196,7 +184,7 @@
             break;
 
         // parse the argument into argx and set the new position
-        p = getArgument(&argx, p, false);
+        p = YConfig::getArgument(&argx, p, false);
         if (p == 0) {
             msg(_("Bad argument %d"), args.getCount() + 1);
             return p;
@@ -223,21 +211,20 @@
 char *parseIncludeStatement(char *p, ObjectContainer *container) {
     char *filename;
 
-    p = getArgument(&filename, p, false);
+    p = YConfig::getArgument(&filename, p, false);
     if (p == 0) {
         warn("invalid include filename");
         return p;
     }
 
-    char *path = *filename != '/'
-               ? YApplication::findConfigFile(filename)
-               : filename;
+    upath path(filename);
+    delete[] filename;
 
-    if (path) {
+    if (!path.isAbsolute())
+        path = YApplication::findConfigFile(path);
+
+    if (path != null)
         loadMenus(path, container);
-        if (path != filename) delete[] path;
-    }
-    delete[] filename;
 
     return p;
 }
@@ -261,23 +248,22 @@
                 container->addSeparator();
             else if (!(strcmp(word, "prog") &&
                        strcmp(word, "restart") &&
-                       strcmp(word, "runonce") 
-			))
+                       strcmp(word, "runonce")))
             {
                 char *name;
 
-                p = getArgument(&name, p, false);
+                p = YConfig::getArgument(&name, p, false);
                 if (p == 0) return p;
 
                 char *icons;
 
-                p = getArgument(&icons, p, false);
+                p = YConfig::getArgument(&icons, p, false);
                 if (p == 0) return p;
 
                 char *wmclass = 0;
 
                 if (word[1] == 'u') {
-                    p = getArgument(&wmclass, p, false);
+                    p = YConfig::getArgument(&wmclass, p, false);
                     if (p == 0) return p;
                 }
 
@@ -289,7 +275,7 @@
                     msg(_("Error at prog %s"), name); return p;
                 }
 
-                YIcon *icon = 0;
+                ref<YIcon> icon;
 #ifndef LITE
                 if (icons[0] != '-') icon = YIcon::getIcon(icons);
 #endif
@@ -307,19 +293,19 @@
             } else if (!strcmp(word, "menu")) {
                 char *name;
 
-                p = getArgument(&name, p, false);
+                p = YConfig::getArgument(&name, p, false);
                 if (p == 0) return p;
 
                 char *icons;
 
-                p = getArgument(&icons, p, false);
+                p = YConfig::getArgument(&icons, p, false);
                 if (p == 0) return p;
 
                 p = getWord(word, sizeof(word), p);
                 if (*p != '{') return 0;
                 p++;
 
-                YIcon *icon = 0;
+                ref<YIcon> icon;
 #ifndef LITE
                 if (icons[0] != '-')
                     icon = YIcon::getIcon(icons);
@@ -344,20 +330,20 @@
             } else if (!strcmp(word, "menufile")) {
                 char *name;
 
-                p = getArgument(&name, p, false);
+                p = YConfig::getArgument(&name, p, false);
                 if (p == 0) return p;
 
                 char *icons;
 
-                p = getArgument(&icons, p, false);
+                p = YConfig::getArgument(&icons, p, false);
                 if (p == 0) return p;
 
                 char *menufile;
 
-                p = getArgument(&menufile, p, false);
+                p = YConfig::getArgument(&menufile, p, false);
                 if (p == 0) return p;
 
-                YIcon *icon = 0;
+                ref<YIcon> icon;
 #ifndef LITE
                 if (icons[0] != '-')
                     icon = YIcon::getIcon(icons);
@@ -372,12 +358,12 @@
             } else if (!strcmp(word, "menuprog")) {
                 char *name;
 
-                p = getArgument(&name, p, false);
+                p = YConfig::getArgument(&name, p, false);
                 if (p == 0) return p;
 
                 char *icons;
 
-                p = getArgument(&icons, p, false);
+                p = YConfig::getArgument(&icons, p, false);
                 if (p == 0) return p;
 
                 char *command;
@@ -388,19 +374,18 @@
                     msg(_("Error at prog %s"), name); return p;
                 }
 
-                YIcon *icon = 0;
+                ref<YIcon> icon;
 #ifndef LITE
                 if (icons[0] != '-')
                     icon = YIcon::getIcon(icons);
 #endif
                 MSG(("menuprog %s %s", name, command));
 
-                char *fullPath = findPath(getenv("PATH"), X_OK, command);
-                if (fullPath) {
+                upath fullPath = findPath(getenv("PATH"), X_OK, command);
+                if (fullPath != null) {
                     ObjectMenu *progmenu = new MenuProgMenu(name, command, args, 0);
                     if (progmenu)
-                        container->addContainer(_(name), icon, progmenu); //LXP FIX
-                    delete [] fullPath;
+                        container->addContainer(_(name), icon, progmenu);
                 }
                 delete[] name;
                 delete[] icons;
@@ -408,18 +393,18 @@
             } else if (!strcmp(word, "menuprogreload")) {
                 char *name;
 
-                p = getArgument(&name, p, false);
+                p = YConfig::getArgument(&name, p, false);
                 if (p == 0) return p;
 
                 char *icons;
 
-                p = getArgument(&icons, p, false);
+                p = YConfig::getArgument(&icons, p, false);
                 if (p == 0) return p;
 
                 time_t timeout;
                 char *timeoutStr;
 
-                p = getArgument(&timeoutStr, p, false);
+                p = YConfig::getArgument(&timeoutStr, p, false);
                 if (p == 0) return p;
                 timeout = atoi(timeoutStr);
 
@@ -431,19 +416,18 @@
                     msg(_("Error at prog %s"), name); return p;
                 }
 
-                YIcon *icon = 0;
+                ref<YIcon> icon;
 #ifndef LITE
                 if (icons[0] != '-')
                     icon = YIcon::getIcon(icons);
 #endif
                 MSG(("menuprogreload %s %s", name, command));
 
-                char *fullPath = findPath(getenv("PATH"), X_OK, command);
-                if (fullPath) {
+                upath fullPath = findPath(getenv("PATH"), X_OK, command);
+                if (fullPath != null) {
                     ObjectMenu *progmenu = new MenuProgReloadMenu(name, timeout, command, args, 0);
                     if (progmenu)
                         container->addContainer(_(name), icon, progmenu);
-                    delete [] fullPath;
                 }
                 delete[] name;
                 delete[] icons;
@@ -462,13 +446,13 @@
             {
                 char *key;
 
-                p = getArgument(&key, p, false);
+                p = YConfig::getArgument(&key, p, false);
                 if (p == 0) return p;
 
                 char *wmclass = 0;
 
                 if (*word == 'r') {
-                    p = getArgument(&wmclass, p, false);
+                    p = YConfig::getArgument(&wmclass, p, false);
                     if (p == 0) return p;
                 }
 
@@ -482,8 +466,9 @@
                 }
 
                 DProgram *prog =
-                    DProgram::newProgram(key, 0,
-                                         false, *word == 'r' ? wmclass : 0, command, args);
+                    DProgram::newProgram(key, null, false,
+                                         *word == 'r' ? wmclass : 0,
+                                         command, args);
 
                 if (prog) new KProgram(key, prog);
                 delete[] key;
@@ -538,13 +523,14 @@
     delete[] buf;
 }
 
-void loadMenus(const char *menufile, ObjectContainer *container) {
-    MSG(("menufile: %s", menufile));
-    loadMenus(open(menufile, O_RDONLY | O_TEXT), container);
+void loadMenus(upath menufile, ObjectContainer *container) {
+    MSG(("menufile: %s", cstring(menufile.path()).c_str()));
+    cstring cs(menufile.path());
+    loadMenus(open(cs.c_str(), O_RDONLY | O_TEXT), container);
 }
 
-MenuFileMenu::MenuFileMenu(const char *name, YWindow *parent): ObjectMenu(parent) {
-    fName = newstr(name);
+MenuFileMenu::MenuFileMenu(ustring name, YWindow *parent): ObjectMenu(parent), fName(name) {
+    fName = name;
     fPath = 0;
     fModTime = 0;
     ///    updatePopup();
@@ -552,36 +538,33 @@
 }
 
 MenuFileMenu::~MenuFileMenu() {
-    delete[] fPath; fPath = 0;
-    delete[] fName; fName = 0;
 }
 
 void MenuFileMenu::updatePopup() {
-    if (!autoReloadMenus && fPath != 0)
+    if (!autoReloadMenus && fPath != null)
         return;
 
-    struct stat sb;
-    char *np = app->findConfigFile(fName);
+    upath np = YApplication::findConfigFile(upath(fName));
     bool rel = false;
 
 
-    if (fPath == 0) {
+    if (fPath == null) {
         fPath = np;
         rel = true;
     } else {
-        if (!np || strcmp(np, fPath) != 0) {
-            delete[] fPath;
+        if (np == null || np.equals(fPath)) {
             fPath = np;
             rel = true;
         } else
-            delete[] np;
+            np = null;
     }
 
-    if (fPath == 0) {
+    if (fPath == null) {
         refresh();
     } else {
-        if (stat(fPath, &sb) != 0) {
-            delete[] fPath;
+        struct stat sb;
+        cstring cs(fPath.path());
+        if (stat(cs.c_str(), &sb) != 0) {
             fPath = 0;
             refresh();
         } else if (sb.st_mtime > fModTime || rel) {
@@ -593,7 +576,8 @@
 
 void MenuFileMenu::refresh() {
     removeAll();
-    if (fPath) loadMenus(fPath, this);
+    if (fPath != null)
+        loadMenus(fPath, this);
 }
 
 void loadMenusProg(const char *command, char *const argv[], ObjectContainer *container) {
@@ -631,9 +615,9 @@
     }
 }
 
-MenuProgMenu::MenuProgMenu(const char *name, const char *command, YStringArray &args, YWindow *parent): ObjectMenu(parent), fArgs(args) {
-    fName = newstr(name);
-    fCommand = newstr(command);
+MenuProgMenu::MenuProgMenu(ustring name, upath command, YStringArray &args, YWindow *parent): ObjectMenu(parent), fName(name), fCommand(command), fArgs(args) {
+    fName = name;
+    fCommand = command;
     fArgs.append(0);
     fModTime = 0;
     ///    updatePopup();
@@ -641,8 +625,6 @@
 }
 
 MenuProgMenu::~MenuProgMenu() {
-    delete [] fCommand; fCommand = 0;
-    delete [] fName; fName = 0;
 }
 
 void MenuProgMenu::updatePopup() {
@@ -688,38 +670,12 @@
 /// TODO #warning "figure out some way for this to work"
 }
 
-#include <X11/cursorfont.h>
-
 void MenuProgMenu::refresh() {
-    //YMsgBox m = new YMsgBox(0);
-    //m->setTitle(_("Power notification"));
-    //m->setText(message);
-    //m->autoSize();
-    //m->showFocused(MSGB_BOTTON_RIGHT);
-    //m->setMsgBoxListener(this);
-
-
-	//fprintf(stderr,"MCM INI MenuProgMenu::refresh %s\n", fCommand);
     removeAll();
-    //Cursor xcursor = XCreateFontCursor (xapp->display(), XC_fleur);
-    if (fCommand) {
-        //xapp->grabEvents(this, xcursor, ButtonPressMask);
-
-	                       //XSetWindowAttributes attributes;
-			       //                       //attributes.cursor = xcursor;
-			       //                                              //XChangeWindowAttributes(xapp->display(), handle(), CWCursor, &attributes);
-        //XSetWindowAttributes attributes; attributes.cursor = xcursor;
-	//XChangeWindowAttributes(xapp->display(), handle(), CWCursor, &attributes);
-	//sleep(3);
-
-        loadMenusProg(fCommand, fArgs.getCArray(), this);
-    }
-	//fprintf(stderr,"MCM END MenuProgMenu::refresh %s\n", fCommand);
-
-     //manager->unmanageClient(m->handle());
+    if (fCommand != null)
+        loadMenusProg(cstring(fCommand.path()).c_str(), fArgs.getCArray(), this);
 }
 
-
 MenuProgReloadMenu::MenuProgReloadMenu(const char *name, time_t timeout, const char *command, YStringArray &args, YWindow *parent) : MenuProgMenu(name, command, args, parent) {
     fTimeout = timeout;
 }
@@ -731,8 +687,7 @@
     }
 }
 
-StartMenu::StartMenu(const char *name, int size, YWindow *parent): MenuFileMenu(name, parent) {
-    iconsSize = size; //LXP
+StartMenu::StartMenu(const char *name, YWindow *parent): MenuFileMenu(name, parent) {
     fHasGnomeAppsMenu =
         fHasGnomeUserMenu =
         fHasKDEMenu = false;
@@ -760,10 +715,6 @@
 }
 
 void StartMenu::refresh() {
-#ifdef CONFIG_LOOK_LXP
-    int m = menuIconSize; 
-    //if (wmLook==lookLxp) menuIconSize=startmenuIconSize; //LXP
-#endif
     MenuFileMenu::refresh();
 
     if (itemCount())
@@ -784,7 +735,7 @@
         const char *path[2];
         YMenu *sub;
 #ifndef LITE
-        YIcon *folder = YIcon::getIcon("folder");
+        ref<YIcon> folder = YIcon::getIcon("folder");
 #endif
         path[0] = "/";
         path[1] = getenv("HOME");
@@ -793,12 +744,12 @@
             const char *p = path[i];
 
             sub = new BrowseMenu(p);
-            DFile *file = new DFile(p, 0, p);
+            DFile *file = new DFile(p, null, p);
             YMenuItem *item = add(new DObjectMenuItem(file));
             if (item && sub) {
                 item->setSubmenu(sub);
 #ifndef LITE
-                if (folder)
+                if (folder != null)
                     item->setIcon(folder);
 #endif
             }
@@ -814,8 +765,8 @@
 
     if (showRun) {
         if (runDlgCommand && runDlgCommand[0])
-            addItem(_("_Run..."), -2, "", actionRun);
-        addSeparator(); //LXP FX
+            addItem(_("_Run..."), -2, null, actionRun);
+        addSeparator();
     }
 
 
@@ -834,7 +785,7 @@
         args.append(0);
 
         DProgram *help =
-            DProgram::newProgram(_("_Help"), NULL, false, "browser.IceHelp",
+            DProgram::newProgram(_("_Help"), null, false, "browser.IceHelp",
                                  ICEHELPEXE, args);
 
         if (help) addObject(help);
@@ -871,7 +822,7 @@
         if (showThemesMenu) {
             YMenu *themes = new ThemesMenu();
             if (themes)
-                settings->addSubmenu(_("_Themes"), -2, themes)_SetIcon(Icon_Theme);
+                settings->addSubmenu(_("_Themes"), -2, themes);
         }
         addSubmenu(_("Se_ttings"), -2, settings);
     }
@@ -880,10 +831,7 @@
         if (showLogoutSubMenu)
             addItem(_("_Logout..."), -2, actionLogout, logoutMenu);
         else
-            addItem(_("_Logout..."), -2, "", actionLogout)_SetIcon(Icon_Logout);
+            addItem(_("_Logout..."), -2, null, actionLogout);
     }
-#ifdef CONFIG_LOOK_LXP
-    menuIconSize = m; //LXP
-#endif
 }
 #endif
