Page 1 of 1

Generically Reference Visual Styles

Posted: Fri Jan 13, 2017 4:18 am
by jonathanboldt
Hi,
Trying to determine whether it's feasible to generically reference a visual style. The idea being to provide a data-driven or generic way to switch many components to a set of possible user-defined "themes". So, something like the following below (which doesn't work). Any ideas? Much appreciated!

Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_FORM) Clientwidth(589) Clientheight(301) Componentversion(2) Left(576) Top(144)
Define_Com Class(#STD_TEXT.Visual) Name(#STD_TEXT) Componentversion(1) Displayposition(1) Height(20) Left(16) Parent(#COM_OWNER) Tabposition(1) Top(16) Usepicklist(False) Width(505)
Define_Com Class(#PRIM_PHBN) Name(#Button1) Displayposition(2) Left(448) Parent(#COM_OWNER) Tabposition(2) Top(56) Caption('Set VS')

Define_Com Class(#prim_vs) Name(#SET_VS) Reference(*DYNAMIC)

Evtroutine Handling(#Button1.Click)
#com_owner.SetVisualStyle Theinput(#STD_TEXT)
Endroutine

Evtroutine Handling(#COM_OWNER.Initialize) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
#COM_OWNER.VisualStyle <= #VS_EMPH
Endroutine

Mthroutine Name(SetVisualStyle)
Define_Map For(*INPUT) Class(#prim_alph) Name(#TheInput)
Set_Ref Com(#SET_VS) To(*CREATE_FROM #TheInput) Com_Error(*SET_NULL)
#COM_OWNER.VisualStyle <= #SET_VS
Endroutine
End_Com

Re: Generically Reference Visual Styles

Posted: Fri Jan 13, 2017 4:37 am
by jyoung
You can add all your controls to a collection and then reference every item in the collection using <>.

Code: Select all

#MyControls<>.Style <= #MyStyle
or

Code: Select all

#MyControls<>.ThemeDrawStyle := "MyDrawStyle"
Edit:
Check out the PRIM_ACOL (Array Collection) object.
http://docs.lansa.com/14/en/lansa016/PRIM_ACOL.htm

Re: Generically Reference Visual Styles

Posted: Fri Jan 13, 2017 7:37 am
by jonathanboldt
Using a collection is an approach I'm considering that will solve 50% of the "generic" problem. I'm really hoping there's a dynamic and generic solution but I don't see a way, i.e. LANSA requires a hard-coded visual style reference name *somewhere* and cannot instantiate a reference to a visual style generically, e.g. the original coding example I provided. Please confirm.

Re: Generically Reference Visual Styles

Posted: Fri Jan 13, 2017 7:53 am
by jyoung
I think I see what you are trying to do now.
You want to enter a style into a text box and then have that style applied to the page/control/form etc. right?

I think you would have to dynamically compile that text and inject in to the containing object somehow. I have no idea how to do that or if it is even possible.

If you are using a web page, you could use a widget to get access to javascript which could dynamically update CSS, if your text is CSS. If the text in your input is RDML(X) you would have to invoke the compiler somehow.

Could be a very useful trick to have to allow customer/client customization of the app. If you find a solution, please share.

Re: Generically Reference Visual Styles

Posted: Fri Jan 13, 2017 8:40 am
by jonathanboldt
Well, not really, the example form I provided is really just a simple explanation of the concept I would like to take and apply elsewhere (not for the web). If my form worked then the more complicated implementation I would like to apply would work as well. Regardless, thanks for your feedback.

Re: Generically Reference Visual Styles

Posted: Fri Jan 13, 2017 9:09 am
by GregSippel
Jonathanboldt,

I have a question to try an clarify what you are trying to achieve. Are you seeking to let the users create their own theme inside of the application or letting them choose from a range of predefined themes ?

Cheers

Re: Generically Reference Visual Styles

Posted: Fri Jan 13, 2017 9:31 am
by jonathanboldt
Greg, I've coded pre-defined visual styles that represent a "theme" the users can then opt to apply. Dynamically applying those themes is not an issue so long as I hard-code every permutation and combination of distinct visual styles that are defined in the repository of which there are hundreds. So, the logic to apply the configured themes could elegantly be coded using dynamic programming in a matter a few small method routines which could be inherited and applied across hundreds of reusable parts. However, at this juncture, I will need to hard-code each specific visual style's component reference name into a component and push those references into a collection so that I can dynamically grab those references later. What I'm asking about is whether it would have been possible to simply instantiate a reference to a visual style given it's name (a string populated from a data-driven back-end) so that I could simply pass a name of an object which would correspond to a visual style of that objects name which would then instantiate that pre-defined visual style. Something like that. Hopefully this isn't confusing the matter further! But to re-iterate if the example form I have input here could be made to work then the above verbose explanation of what I'm working on could be simplified further. It's not a big deal but I would prefer to *not* have to hard-code a collection with hundreds of lines of code adding specific #this_visual_style1 through n into that collection.

Re: Generically Reference Visual Styles

Posted: Fri Jan 13, 2017 9:48 am
by Stewart Marshall
Visual Styles (Prim_VS) cannot be managed as dynamic objects. They are not compiled to a DLL, instead being handled as singletons within the application. Further, their definition at runtime is static. This means you can neither create an instance of a Prim_VS nor modify it's state at runtime.

This is a fundamental restriction for all Visual LANSA applications that use the Win32 rendering engine which was the only choice prior to version 13.


V13 introduced DirectX rendering and with it the concept of a style (http://www.lansa.com/support/tips/t0588.htm). Individual styles (Prim_vs.Style) are component instances the same as any other, and can therefore be created, destroyed and referenced. This means that you can now construct your own complex "theme" like features.

However, this requires that you use the DirectX rendering. While I thoroughly recommend that all VL users move to DirectX, it is not something that should be undertaken lightly if you have a large preexisting application, as explained in the PDF. (http://www.lansa.com/support/tips/t0587.htm)


V14 introduced Themes and ThemeDrawStyles which make a far more effective use of styles. Themes are compiled objects that use name matching at runtime and are specifically intended to resolve the problem you're trying to address.