Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Non-modal - Dialog will not stay open (Can not get non-modal dialog to stay open - Just flashes then closes)
Non-modal - Dialog will not stay open [message #48318] Thu, 22 June 2017 00:46 Go to next message
Zed1 is currently offline  Zed1
Messages: 11
Registered: June 2017
Promising Member
Hi,

I have been reading up on Ultimate++ and really like the look of it.

I have got basic code working but I am struggling with launching non-modal dialogs / windows.

Please look at the code in main.cpp (Hello::AddressList()) this is where I am trying to launch the dialog from.

I can get the dialog to open with Addr.Run(); (modal) but it locks the main window so I can not access and of the menu items etc...

When I call Addr.Open(); (non-modal) the dialog just flashes open then closes immediately.

What am I missing.

Hello.h
#ifndef _Hello_Hello_h
#define _Hello_Hello_h

#include <CtrlLib/CtrlLib.h>
#include "Address.h"

#define IMAGEFILE <Hello/Hello.iml>
#define IMAGECLASS HelloImg
#include <Draw/iml.h>

using namespace Upp;

class Hello : public TopWindow {

    public:
        typedef Hello CLASSNAME;

        Hello();

        // Paint override
        void Paint(Draw& w) {
            w.DrawRect(GetSize(), Color(66, 134, 244));       // <= enter your background color here
        }

    private:
        MenuBar menu;
        StatusBar status;

        void FileMenu(Bar& bar);
        void MainMenu(Bar& bar);
        void About();
        void AddressList();

        void Exit() {
            Break();
        }
};

#endif


main.cpp
#include "Hello.h"

Hello::Hello() {
    Title("Hello World");
    Sizeable().Zoomable();
    Maximize();
    CenterScreen();
    Icon(HelloImg::appicon());
    AddFrame(menu);
    AddFrame(status);
    menu.Set(THISBACK(MainMenu));
    menu.WhenHelp = status;
    status = "Welcome to the Application";
}

void Hello::About() {
    status = "About the application";
    PromptOK("{{1@5 [@9= This is the]::@2 [A5@0 Ultimate`+`+ Hello world sample}}");
    status = "Ready";
}

void Hello::AddressList() {
    status = "Manage Addresses";
    Address Addr;

    // Modal - Can not access main window menu
    //if (Addr.Run(this) != IDOK) { // (this) is the owner of the new window 
    //    status = "Ready";
    //    return;    
    //}
    
    // Non Modal - Causes dialog to flash open then close immediately
    Addr.Open();
    
    status = "Ready";
}

void Hello::FileMenu(Bar& bar) {
    bar.Add("&Adress List", THISBACK(AddressList)).Help("Display all addresses");
    bar.Add("About..", THISBACK(About)).Help("About the application");
    bar.Separator();
    bar.Add("E&xit", [=] { Exit(); }).Help("Exit the application");
}

void Hello::MainMenu(Bar& bar) {
    menu.Add("&File", THISBACK(FileMenu));
}

GUI_APP_MAIN {
    SetLanguage(LNG_ENGLISH);
    Hello().Run();
}


Address.h
#ifndef _Hello_Address_h_
#define _Hello_Address_h_

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

#define LAYOUTFILE <Hello/Address.lay>
#include <CtrlCore/lay.h>

class Address : public WithAddressDlg<TopWindow> {

    public:
        typedef Address CLASSNAME;
        Address();

    private:
        void ShowInfo();
};

#endif


Address.cpp
#include "Address.h"

Address::Address() {
    CtrlLayoutCancel(*this, "Addresses");    // With Cancel button
    Sizeable().Zoomable();
    
    addressList.AddColumn("Name");
    addressList.AddColumn("Surname");
    addressList.AddColumn("Address");
    addressList.AddColumn("Email");

    for (int j = 0; j < 25; j++) {
        Vector<Value> q;

        for (int i = j; i < j + 4; i++)
            q.Add(i);
        
        addressList.Add(q);
    }

    addressList.WhenLeftDouble = THISBACK(ShowInfo);
}

void Address::ShowInfo() {
    PromptOK(String().Cat() << "First Column: " << addressList.Get(0) << ", Second Column: " << addressList.Get(1));
}


Address.lay
LAYOUT(AddressDlg, 800, 300)
	ITEM(ArrayCtrl, addressList, HSizePosZ(4, 4).VSizePosZ(4, 40))
	ITEM(Button, cancel, SetLabel(t_("Cancel")).RightPosZ(12, 68).BottomPosZ(9, 23))
END_LAYOUT


Hello.iml
PREMULTIPLIED
IMAGE_ID(appicon)

IMAGE_BEGIN_DATA
IMAGE_DATA(120,156,99,16,96,16,96,192,7,196,116,157,67,157,218,79,253,71,198,32,49,188,154,176,234,59,13,197,132,205,129,232)
IMAGE_DATA(61,141,166,15,29,67,228,208,205,32,78,47,110,51,48,221,75,140,25,167,254,163,250,25,187,26,220,102,67,194,2,187)
IMAGE_DATA(252,169,255,229,11,218,255,31,59,166,8,198,32,54,54,53,248,204,6,233,123,120,153,1,140,65,108,252,110,164,84,63)
IMAGE_DATA(249,238,167,52,252,40,141,63,106,164,31,74,211,47,53,242,15,126,115,112,235,3,0,83,220,246,108,0,0,0,0,0)
IMAGE_END_DATA(128, 1)
Re: Non-modal - Dialog will not stay open [message #48321 is a reply to message #48318] Thu, 22 June 2017 09:57 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
You need to do two things.

1. Make "Address Addr" non local to a method. The Addr variable needs to survive the call of AddressList(). Addr gets destroyed as soon as the method finishes, closing the dialog.
2. Don't call Open or run or other methods that do an event loop, locking up control. Try a simple show.
Re: Non-modal - Dialog will not stay open [message #48325 is a reply to message #48318] Thu, 22 June 2017 18:38 Go to previous message
Zed1 is currently offline  Zed1
Messages: 11
Registered: June 2017
Promising Member
Dohh - Sorry Embarassed

Thank you cbpporter

In my defence I had been reading and playing with U++ all day so was getting tired.

Anyway this what I did to get it working just in case anyone else has issues with non-modal calls.

1. Moved "Address Addr" to the public section of the Hello.h class declaration.
2. Changed the "CtrlLayoutCancel(*this, "Addresses");" to "CtrlLayout(*this, "Addresses");" in the Address constructor in Address.cpp.
3. Added "cancel <<= THISBACK(Cancel);" to Address class constructor in Address.cpp.
4. Added "void Cancel() { Close(); }" to the private section of the of the Address class declaration in Address.h.
5. Altered Hello::AddressList() function to simply "Addr.IsOpen() ? Addr.Close() : Addr.Open(this);" in main.cpp.

I have attached the code to help others get started using Ultimate++

Very Happy
  • Attachment: Hello.zip
    (Size: 3.51KB, Downloaded 173 times)

[Updated on: Thu, 22 June 2017 18:46]

Report message to a moderator

Previous Topic: Save sccatterCtrl to png: resolution
Next Topic: windows console utf-8 output problem
Goto Forum:
  


Current Time: Thu Mar 28 13:27:08 CET 2024

Total time taken to generate the page: 0.01326 seconds