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 » Problems when using layouts
Problems when using layouts [message #27154] Mon, 28 June 2010 22:22 Go to next message
281264 is currently offline  281264
Messages: 270
Registered: June 2010
Location: Spain
Experienced Member
Hi,

I am training myself with layouts; however I am finding some “conceptual” problems. Here are the steps I have made:

1.- I created a GUI application with the U++, with its own lay out; in this step there is not problem;
2.- The I tried to add a new dialog by using the lay out designer; once I finished its design and used the Generate Code tool to get the class code generated;
3.-I pasted part of the code in a new header file and another part (the implementation) in a cpp file.

When I compile the application the outcome contains some errors. Please, be so kind to indicate what I am doing wrong.

Note: code is attached.

Many thanks,

Javier


  • Attachment: prueba.7z
    (Size: 1.13KB, Downloaded 184 times)
Re: Problems when using layouts [message #27156 is a reply to message #27154] Mon, 28 June 2010 23:33 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi Javier,

The problem is that the code in dialogoDlg.h doesn't know about the layout template, because that was included in prueba.h. The solution requires moving the code between the files a bit. I would say the simplest solution (but not only one) is to move the content of dialogoDLG.h into prueba.h and use only this one file.

Additionally, in class prueba you have :
dialogoDlg dialogo();
That is interpreted by compiler as function declaration, correctly it shoud be without the parenthesis:
dialogoDlg dialogo;


Honza
Re: Problems when using layouts [message #27157 is a reply to message #27156] Mon, 28 June 2010 23:53 Go to previous messageGo to next message
281264 is currently offline  281264
Messages: 270
Registered: June 2010
Location: Spain
Experienced Member
Thank you. Your proposal works but I like the idea of having a header file per class. So, is there another way of doing it? I reckon that for large applications there should be other solutions.
Re: Problems when using layouts [message #27158 is a reply to message #27157] Tue, 29 June 2010 01:46 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

In attachment - working code.
If you have tool for compare source file - compare line by line

Some comments:

In C++ isolation - by modules, because combine header files and combine layout files OR split header files and split layout files.
(I split dialogo and main window into different files)

Use Button variable name ok - and change from CtrlLayout to CtrlLayoutOK - logic of work added automaticaly.
(I change variable name from Cerrar to ok - and method Close is gone...)

Don't forget add
#define LAYOUTFILE <prueba/dialogo.lay>
#include <CtrlCore/lay.h>
for every dialog
and for every class.


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Problems when using layouts [message #27171 is a reply to message #27158] Tue, 29 June 2010 17:04 Go to previous messageGo to next message
281264 is currently offline  281264
Messages: 270
Registered: June 2010
Location: Spain
Experienced Member
Sergey,

Thanks a lot. I tried your proposal out and I have some question:

1.- Apparently, when the “Cancel” button is pressed in the dialog (in other words, when the user chooses not to do anything), the multiplication in the TopWindow is performed (which is something that shouldn’t ). How to avoid this? This question is related with the role of CtrlLayoutOKCancel: what is actually doing this function? How to control whether the user has pressed ok or cancel and, therefore, actuate accordingly in the TopWindow?

2.- So the conclusion is that it is better (from the stand point of C++ modularity) to have different “.lay” files, one for the “main window” and others for the respective dialogs.

3.- What is this?:
Result<<=(double)~dialogo.entrada_a*(double)~dialogo.entrada_b;


What is the role of ~ in the expression?

Thanks,

Javier
Re: Problems when using layouts [message #27173 is a reply to message #27171] Tue, 29 June 2010 17:36 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

281264 wrote on Tue, 29 June 2010 17:04

2.- So the conclusion is that it is better (from the stand point of C++ modularity) to have different “.lay” files, one for the “main window” and others for the respective dialogs.

I would say it is a matter of taste Very Happy For example if you look at theide, which is pretty complex application, you'll see that there is only single layout file included in ide.h. The separation of modules is used only for .cpp files.

281264 wrote on Tue, 29 June 2010 17:04

3.- What is this?:
Result<<=(double)~dialogo.entrada_a*(double)~dialogo.entrada_b;

What is the role of ~ in the expression?


In Ctrl, operator~() is used as a shorthand for GetData() and operator<<=(Value v) for SetData(Value v). It can save you some typing and increase readability of the code.

Honza
Re: Problems when using layouts [message #27177 is a reply to message #27173] Tue, 29 June 2010 18:27 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
1- The code is incorrect, instead of
	dialogo.Execute();
	Result <<= (int)~dialogo.entrada_a * (int)~dialogo.entrada_b;

it should be:
	if (dialogo.Execute() == IDOK)
	   Result <<= (int)~dialogo.entrada_a * (int)~dialogo.entrada_b;

or:
	if (dialogo.ExecuteOK())
	   Result <<= (int)~dialogo.entrada_a * (int)~dialogo.entrada_b;

so that the cancel response is filtered out.

CtrlLayoutOKCancel does 2 things that CtrlLayout doesn't:
- Assign standard OS icons to buttons (for X11 really). This uses the Button::OK() or Button::Cancel() functions.
- Give each button a callback that breaks the dialog's modal loop with a specific value (like IDOK). This value is then returned by Execute so that you can check which button was pushed (as above).

Using this method there is also additional behaviour when OK or Cancel is pushed by the user. OK calls Accept which validates all the ctrls on the dialog and stops the operation if any fail. Cancel calls Reject (which is used by some controls to end editing states) and if you have called Backup at any point it also calls Restore to revert to backed-up values.

Basically the idea is that by using CtrlLayoutOKCancel you get standard functionality automatically. Sometimes you want to over-ride the default OK handling, but this is easy to:
...
ok <<= THISBACK(OnOK);

void OnOK()
{
   if (!Accept()) 
      return;
   // Do something
   ...

   Break(IDOK);
}

Re: Problems when using layouts [message #27180 is a reply to message #27173] Tue, 29 June 2010 19:19 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

dolik.rce wrote on Tue, 29 June 2010 19:36

281264 wrote on Tue, 29 June 2010 17:04

2.- So the conclusion is that it is better (from the stand point of C++ modularity) to have different “.lay” files, one for the “main window” and others for the respective dialogs.

I would say it is a matter of taste Very Happy For example if you look at theide, which is pretty complex application, you'll see that there is only single layout file included in ide.h. The separation of modules is used only for .cpp files.

281264 wrote on Tue, 29 June 2010 17:04

3.- What is this?:
Result<<=(double)~dialogo.entrada_a*(double)~dialogo.entrada_b;

What is the role of ~ in the expression?


In Ctrl, operator~() is used as a shorthand for GetData() and operator<<=(Value v) for SetData(Value v). It can save you some typing and increase readability of the code.

Honza



I say
Quote:

In C++ isolation - by modules, because combine header files and combine layout files OR split header files and split layout files.
(I split dialogo and main window into different files)


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}

[Updated on: Tue, 29 June 2010 19:19]

Report message to a moderator

Re: Problems when using layouts [message #27181 is a reply to message #27180] Tue, 29 June 2010 19:28 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Read it:
http://www.ultimatepp.org/www$uppweb$overview$en-us.html

http://www.ultimatepp.org/srcdoc$CtrlLib$Tutorial$en-us.html

http://www.ultimatepp.org/srcdoc$Core$Tutorial$en-us.html



I read the articles several times a month,
until not understand everything before the last character.

If you're going to program in U + + I strongly recommend to do the same.

By the way thanks to the author of these articles.

And by the way, who is the author of these wonderful texts?


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Problems when using layouts [message #27182 is a reply to message #27181] Tue, 29 June 2010 20:28 Go to previous messageGo to next message
281264 is currently offline  281264
Messages: 270
Registered: June 2010
Location: Spain
Experienced Member
Thanks. Actually at the time I posted I was reading the example nº 16 in the GUI tutorial; I was not aware about the explanation in nº 20. I shall read it carefully.

Cheers,

Javier
Re: Problems when using layouts [message #27185 is a reply to message #27182] Tue, 29 June 2010 21:46 Go to previous message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Twisted Evil Yes!

SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Previous Topic: Message from the system.
Next Topic: is windows SDK needed after Visual Studio 2010
Goto Forum:
  


Current Time: Fri Apr 26 20:22:04 CEST 2024

Total time taken to generate the page: 0.03148 seconds