PDA

View Full Version : UI: alternate Visual Designers



ReneMiner
12-10-2013, 20:39
Thanks Maxer73 for pushing the idea.

EDIT: Below was a script that "translates" .RC-files as written with this editor (ResEd) (http://oby.ro/rad_asm/resed/) (there are certainly others) to TB-code. Now it's attached one post below this

You just run this script, load some .rc-file when prompted- thereafter you have code on clipboard and can insert to thinAir.

The generated code is supposed to be a .tBasicU-file but can be tested also as .tBasic-File when uncommenting the marked line in the beginning.

PS.: I really hope the tB-Equate %WS_Child equals Win32ish WS_ChildWindow :) and its a little messed up with those font-styles - style means bold, underline italic and the third I'm not sure about.
Somehow it's still buggy and I don't have the powers to delete the thread nor the idea how to fix it yet. Maybe someone else comes up with something better....

ReneMiner
14-10-2013, 15:44
Better working version now:

I would recommend to remove the assigned ControlIDs and leave the enumeration to tB - but Max insists to keep these ;)

Edit- attachement 2 posts below...

Billbo
14-10-2013, 16:42
Rene,

There's a bad link to your file.

Bill

ReneMiner
14-10-2013, 16:45
No- i just updated it - probably same moment when you tried to download it :)

In the generated code you'll find something like



'...
DWord IDD_DLG1

' uncomment following to test
' IDD_DLG1 = IDD_DLG1_StartUp(0)
' Dialog Show Modal IDD_DLG1


for better understanding: if it reads like this:


'...
DWord IDD_DLG1

IDD_DLG1 = IDD_DLG1_StartUp(0)
Dialog Show Modal IDD_DLG1

you have a stand-alone .tBasic-script to test-run it. Intentionally it's supposed to be a tBasicU-code-unit so the UI-setup can be easily exchanged when the layout changes or another dialog gets added to the project.

Edit: attachement removed- see below

Billbo
15-10-2013, 03:18
Thanks, Rene.

Bill

ReneMiner
15-10-2013, 12:39
I made a little new version:

It now creates also a TBMain-function and a simple skeleton for callbacks.
If using more than one dialog the first one becomes the parent of the following, but you can change this as you like.
Also a bit of cosmetics so you get now a time/date and resource-information into the code.


Edit : attachement removed - see further below

Petr Schreiber
15-10-2013, 20:55
Thank you Rene,

works good on my testing samples!


Petr

ReneMiner
16-10-2013, 12:46
A new version again:

Now it also creates dialog-menus. But there seems to be a problem with ACCEL ATTACH -method.
I tried different ways but it does not attach the accelerator-keys to the menu.

Anyway- the script creates the code also for the Accel-Keys (they just don't work - but I think that's not my fault) - maybe someone has some hint for me why it does not attach the Accel-Keys to controls nor menuitems.

Also there might be other visual editors than Resed, that save Menu-Flags in different way - I saw for example some strange "0x00008000" in a few rc-files that Maxer73 sent me - these do not work with tokenizer - it makes one numeral (0) and one string of it ("x00008000") - so two tokens from one expression -
I sticked to Resed-syntax here which reads like "GRAYED" and "CHECKED" for menu-flags. Other hex-values for styles & ex-styles are valid - but not for menu

Another point:
Resed saves rc-files even if controls have no IDs or IDs are not unique. So you have to be very attentive and check yourself that every dialog, control and menuItem has its unique, valid ID. IDs (i.e. constants in the created tB-code) ending with underscore seem to create some hiccups so better check IDs twice.

EDIT:

Also the created script has in front a few more windows-constants that I've found not available in UI - but I think there are a few still missing.


Begin Const
%WS_EX_DLGMODALFRAME = &H00000001
%ES_VERTICAL = &H00400000
%WS_CHILDWINDOW = %WS_CHILD
%WS_SIZEBOX = &H00040000
%DS_FixedSys = &H00000008
%DS_ShellFont = %DS_FixedSys | %DS_SETFONT
%LWS_TRANSPARENT = &H00000001
%PGS_HORZ = &H00000001
%SS_ICON = &H00000003
%HDS_BUTTONS = &H00000002
End Const

You can remove these of course if they are not used in your script. If you come across some unknown equate - I've found a page that lists them (http://doxygen.reactos.org/dc/d0c/richedit_8h_ad3264e086d26efd029f7d6337c17e0b1.html#ad3264e086d26efd029f7d6337c17e0b1) - use the search-function there and type in the equate, select the first suggested then and find the value on top there.

...the attachement one post below now

ReneMiner
17-10-2013, 13:46
Maxer urged me to rewrite this. Anyway I've found a bug if control-id's are not ucase$ (fixed) and another one that occured because - (minus) was not treated as part of numeric expression. Now this has a small dialog in the beginning (created with resed and translated by itself) so you can specify in advance what parts of code you want to have created.

Still unsolved mystery is the accell attach that seems not to do anything...

Attachement futher below now...

ReneMiner
17-10-2013, 17:16
Accel Attach issue solved:

It works only if the dialog has focus - but not if one of the controls has focus.

This is some created testing script, I only modified the callback to end on CTRL+E for a test.



Uses "UI"

' code created from .rc-file
' C:\<path removed>\DialogMenu(1).rc
' 2013-10-17 16:56:56




Begin ControlID
%IDC_EDT1 ' = 1002
%IDC_CBE1 ' = 1001
%IDM_OPEN ' = 10002
%IDM_SAVE ' = 10003
%IDM_EXIT ' = 10005
%IDM_OPENPDF ' = 10008
%IDM_ABOUT ' = 10007
End ControlID



Begin Const
%WS_EX_DLGMODALFRAME = &H00000001
%ES_VERTICAL = &H00400000
%WS_CHILDWINDOW = %WS_CHILD
%WS_SIZEBOX = &H00040000
%DS_FIXEDSYS = &H00000008
%DS_SHELLFONT = %DS_FIXEDSYS | %DS_SETFONT
%LWS_TRANSPARENT = &H00000001
%PGS_HORZ = &H00000001
%SS_ICON = &H00000003
%HDS_BUTTONS = &H00000002
End Const

Boolean keepRunning = TRUE

DWord IDD_DLG1


' - - - - - - - - - - - - - - - - - - - -

Function IDD_DLG1_StartUp(ByVal hParent As DWord) As DWord

DWord hDlg, hFont, hMenu

MENU New Bar To hMenu

DWord hPopUp_001
MENU New Popup To hPopup_001
MENU Add Popup, hMenu, "&File", hPopup_001, %MF_ENABLED
MENU Add String, hPopup_001, "&Open", %IDM_OPEN, %MF_ENABLED
MENU Add String, hPopup_001, "&Save", %IDM_SAVE, %MF_ENABLED
MENU Add String, hPopup_001, "-", 0, 0
MENU Add String, hPopup_001, "&Exit", %IDM_EXIT, %MF_ENABLED

DWord hPopUp_002
MENU New Popup To hPopup_002
MENU Add Popup, hMenu, "&Help", hPopup_002, %MF_ENABLED
MENU Add String, hPopup_002, "&Open PDF Help", %IDM_OPENPDF, %MF_ENABLED
MENU Add String, hPopup_002, "&About", %IDM_ABOUT, %MF_ENABLED



hDlg = Dialog New hParent,
"IDD_DLG1",
0,0,336,207,
%WS_VISIBLE | %WS_OVERLAPPEDWINDOW | %DS_CENTER
hFont = Font_Create("MS Sans Serif", 8)
Dialog Send hDlg, %WM_SETFONT, hFont, 0

Control Add "Edit", hDlg, %IDC_EDT1, "", 177, 141, 81, 12, %WS_CHILDWINDOW | %WS_VISIBLE | %WS_TABSTOP, %WS_EX_CLIENTEDGE
Control Add "ComboBoxEx32", hDlg, %IDC_CBE1, "", 135, 39, 129, 105, %WS_CHILDWINDOW | %WS_VISIBLE | %WS_TABSTOP | &H00000003

MENU Attach hMenu, hDlg

Local AccelTable(4) As ACCELAPI
DWord hAccel

AccelTable(1).fvirt = %FVIRTKEY Or %FCONTROL
AccelTable(1).key = %VK_O
AccelTable(1).cmd = %IDM_OPEN

AccelTable(2).fvirt = %FVIRTKEY Or %FCONTROL
AccelTable(2).key = %VK_S
AccelTable(2).cmd = %IDM_SAVE

AccelTable(3).fvirt = %FVIRTKEY Or %FCONTROL
AccelTable(3).key = %VK_E
AccelTable(3).cmd = %IDM_EXIT

AccelTable(4).fvirt = %FVIRTKEY Or %FCONTROL
AccelTable(4).key = %VK_A
AccelTable(4).cmd = %IDM_ABOUT


ACCEL Attach hDlg, AccelTable() To hAccel

Function = hDlg

End Function


' - - - - - - - - - - - - - - - - - - - -

CallBack Function IDD_DLG1_Callback()

Select Case CBMSG
Case %WM_INITDIALOG
' -- Put code to be executed after dialog creation here
Case %WM_COMMAND
' -- You can handle controls here
Select Case CBCTL
Case %IDC_EDT1
Case %IDC_CBE1
Case %IDM_OPEN
Case %IDM_SAVE
Case %IDM_EXIT
keepRunning = FALSE
Case %IDM_OPENPDF
Case %IDM_ABOUT
End Select
Case %WM_SYSCOMMAND

Case %WM_CLOSE
' -- Put code to be executed before dialog end here
keepRunning = FALSE
End Select

End Function


' --------------------------------------------------
Function TBMain()

Long numberOfDialogsAlive

IDD_DLG1 = IDD_DLG1_StartUp(%HWND_DESKTOP)
Dialog Show Modeless IDD_DLG1 Call IDD_DLG1_Callback


While keepRunning
Dialog DoEvents To NumberOfDialogsAlive
Wend


End Function


Edit:

Now takes also those "0x00000003" & "0x00000008" -flags for menuitems

see next page for the file :D

ReneMiner
19-10-2013, 17:53
Another improvement added - better to say a few of them:

This now can create a skeleton that includes global keyboard-watch, alternative to Accel Attach - so shortcuts will work always, no matter what currently has focus. Therefore it creates also "Events" to MenuItems, so you don't need to handle Menu-Items in callback: each menuItem gets created it's own sub if you decide to include the Keyboard-Check- the call of the subs is contained in callbacks & shortcuts. For these Shortcuts there will be next to TBMain a TBKeyboard-Function which gets called from Main-Loop - and you can add any global keyboard-related actions there. By default it contains to end the app on escape-key. You also can add shortcuts to any other control if you like to, just stick to the way of the template then and send those CBCTL-cases with the needed parameters to some sub like



'...your example-sub
Sub OnClick_ID_myButton(Byval hDlg as Dword)

' write here what happens if ID_myButton gets clicked
' if hDlg = 0 then this call came from keyboard

End Sub

'...within callback
'...
Case %WM_Command
Select Case CBCTL
Case ID_MyButton
If CBMSG = %BN_Clicked Then OnClick_ID_myButton(CBHNDL)
'...

'... your shortcut within TBMain
'...
While keepRunning
Dialog DoEvents To NumberOfDialogsAlive

Select Case TBKeyboard

Case %VK_ESCAPE
keepRunning = FALSE

Case %VK_F12 ' lets say it shall react on CTRL+F12:
If GetAsyncKeyState(%VK_CONTROL) Then
OnClick_ID_myButton(0)
EndIf
'...


Also possible to include mouse-handling to callbacks, so the skeleton contains all mouse-stuff within callbacks and creates a generic mouse-UDT. I refrained from adding equates for mouse-button-states here, I just used values which mean

0 - mousebutton nothing
1 - mousebutton just went down
2 - mousebutton hold down
-1 - mousebutton just released


I would like to use Name-option for dialogs -
but there are two problems: currently the automatic control-callbacks are not done yet (this is the smaller problem)
and sizes of dialogs & controls do not match the sizes during creation - not if Dialog New Name, Pixels nor Units are used.