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 » U++ Library support » Look and Chameleon Technology » A question of C++
A question of C++ [message #20619] Fri, 27 March 2009 10:06 Go to next message
kbyte is currently offline  kbyte
Messages: 87
Registered: July 2008
Member
I have a SDI like application (developed using UPP) that has a menu and in it client are there is the main data where user makes their work. This application has lots of dialogs that are opened, using the main menu, in a modal fashion.

Now the user doesn’t like the windows default colors and want to customize every color in every control (grids, labels, edits, etc) in all dialogs, including the client are of the main window.

Mirek had helped me in colorization (thank you again) of controls and the main Windows client are ready and sesnitive to colors stored in a binary file (windows background, label forecolor, edits textcolor, etc). Now I have to apply this to all modal dialogs too when they are invoked.

I know that C++ has means to make this without code copy-past, say, by deriving classes but has I don’t have enough skills for that I would like to ask you the best way to do that.

All my modal dialogs classes are follow this pattern:

class CChangeUnitsDlg : public WithChangeUnitsDlgLayout<TopWindow>
{

}

Hence, all dialogs must store and be sensitive to the selected colors for background, labels and text on edit controls and on painting time the dialogs must paint using the selected colors.

Thanks very much


Alex

Re: A question of C++ [message #20620 is a reply to message #20619] Fri, 27 March 2009 12:29 Go to previous messageGo to next message
kbyte is currently offline  kbyte
Messages: 87
Registered: July 2008
Member
I am trying this:

#include "ColoringSystem.h"
...

class CChangeUnitsDlg : public WithChangeUnitsDlgLayout<TopWindow> , public CColoringSystem
{

}

and the CColoringSystem will store all needed colors and the paint of the CChangeUnitsDlg will paint every control 1 by one using the colors in the CColoringSystem class.


Alex

[Updated on: Fri, 27 March 2009 12:35]

Report message to a moderator

Re: A question of C++ [message #20621 is a reply to message #20620] Fri, 27 March 2009 13:29 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
kbyte wrote on Fri, 27 March 2009 11:29

I am trying this:

#include "ColoringSystem.h"
...

class CChangeUnitsDlg : public WithChangeUnitsDlgLayout<TopWindow> , public CColoringSystem
{
�
}

and the CColoringSystem will store all needed colors and the paint of the CChangeUnitsDlg will paint every control 1 by one using the colors in the CColoringSystem class.


Alex



It doesn't work like that, Ctrls are respoionsible for drawing themselves.

You have several options here, but it depends on exactly what you are trying to do:
1- If you want to set colours globally (for all EditCtrls say) you can use EditField::StyleDefault().Write(). You can also do things like SColorFace_Write(Red()) to replace a particular colour.
2- If you need individual colouring for different ctrls of the same type (like username EditString is red, password is Blue) then you are going to have to do something more complicated. Unless you hard-code it this is going to be difficult to do, but possible.
One way would be to use your own version of the Layout macro that creates a string table from a .lay file and then use the table to read styling values from an Xml file. Or something.
3- Tell the user that they can set the colours themselves with ControlPanel->Display and that colours are deliberatley set to match the OS for a good reason Smile
Re: A question of C++ [message #20622 is a reply to message #20621] Fri, 27 March 2009 13:39 Go to previous messageGo to next message
kbyte is currently offline  kbyte
Messages: 87
Registered: July 2008
Member
Yes I want to change the colors for all controls of the same type.


I will try that. Thanks!


Alex
Re: A question of C++ [message #20623 is a reply to message #20622] Fri, 27 March 2009 13:57 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
In that case this thread might be useful:
Global style changes
Re: A question of C++ [message #20624 is a reply to message #20623] Fri, 27 March 2009 16:55 Go to previous messageGo to next message
kbyte is currently offline  kbyte
Messages: 87
Registered: July 2008
Member
Very usefull that thread but no sample code and chameleon is complex to understand Sad

Any simple code snipet for global edit or lable change?

Thank you

Alex

[Updated on: Fri, 27 March 2009 17:52]

Report message to a moderator

Re: A question of C++ [message #20625 is a reply to message #20624] Fri, 27 March 2009 18:07 Go to previous messageGo to next message
kbyte is currently offline  kbyte
Messages: 87
Registered: July 2008
Member
I am trying this to changle edit boxes globally:

Exemple:

#include "DG.h"
DG::DG()
{
CtrlLayout(*this, "Window title");

EditField::Style edits =EditField::StyleDefault();

edits.paper=Color(Color(255,0,0));
edits.focus=Color(Color(0,0,255));
edits.ink=Color(Color(0,255,0));

EditField::SetStyle(edits);
}

GUI_APP_MAIN
{
DG().Run();
}


But compiler says that i have to assign SetStyle to one object. So, I am confused. Can we set the global style or do I have to set control by control style?


Alex
Re: A question of C++ [message #20626 is a reply to message #20625] Fri, 27 March 2009 18:39 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
You can do both. To set it for a single ctrl you use SetStyle, which overrides StyleDefault() (which may be called something else on some ctrls).

To set it globally you change StyleDefault:
EditField::Style &s = EditField::StyleDefault().Write();
s.paper = Red;
s.focus = Green;
s.ink = Blue;

Incidentally, if you are going to set the style for a single ctrl you need to make sure that the Style instance you are using doesn't run out of scope (or gets deleted) before the Ctrl does. This is because the Ctrl stores a pointer to the Style internally (this is a pretty contrary to Upp style IMO. C'est la vie).
You can use a construct like this to make it work well:
void SetEditStyle(EditField &edit)
{
   static EditField::Style s = EditField::StyleDefault();
   s.paper = Red;
   s.focus = Green;
   s.ink = Blue;
   edit.SetStyle(s);
}
Re: A question of C++ [message #20634 is a reply to message #20626] Sat, 28 March 2009 08:45 Go to previous message
kbyte is currently offline  kbyte
Messages: 87
Registered: July 2008
Member
Great!

Thank you very much

Alex
Previous Topic: Custom Font
Next Topic: Questions about themeing plz
Goto Forum:
  


Current Time: Tue Feb 19 09:27:19 CET 2019

Total time taken to generate the page: 0.00549 seconds