HMG4 menu handling

Moderator: Rathinagiri

Post Reply
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

HMG4 menu handling

Post by l3whmg » Thu Jul 07, 2011 4:32 pm

Hello friends.
I want to offer a different solution for menu management.
Attached, you will find a compressed file with everything you need to check my proposal.

CAUTION: what you find is a proposal, which alter the contents of your HMG4 distribution.
Therefore, you must preserve a valid copy of the HMG4 library (before copying this content) and
when finished you must restore the originals.

THIS IS THE CONTENT:
hmg.hbp : added lqt-menu.prg and removed: source/mainmenu.prg, source/menupopup.prg, source/menuitem.prg
source/lqt-menu.prg : the new menu management system
source/window.prg : added DATA oMainMenu and SetUpMenu() method
include/hmg.ch : to handle XBase command styel
samples/newmenu : folder with demo (note: after evaluation you must remove it)

BRIEF EXPLANATION:
The code is based on creating nested objects inside the class.
In this phase, are created only HMG4 objects. The real QT menu is activated with the CREATE() method.
This method is called by the function "CREATEPENDINGCHILDCONTROLS" within the class WINDOW. In this way I preserve the HMG4 logic.
Unlike the previous version, I add that:
- there are only two classes, but the real used it's only one
- external variables are not necessary, reducing the load of code into the file "HMG.CH"

2011-07-09 THIS lines below ARE WRONG
VERY IMPORTANT REMARK:
I was able to maintain compatibility with HMG3, about this syntax: MainForm.ItemMenu.value, but I believe
that this compatibility is to be DEPRECATED because it's completely out of HMG4 logic and it's very dangerous!
Moreover, as the current version, this "compatibility" creates a serious problem: there are two identical objects, but positioned at different level.
Within the HMG4 library, this is a hypothetical creation of an item: Mainform:MainMenu:MenuPopUp:MenuItem.
Wanting to maintain compatibility with HMG3, is added an object in this way: Mainform:MainMenu:MenuItem.
They have the same name, the same properties, but may contain different settings: depending on the access method chosen by the programmer.
In example:
  • if I use this ===> Mainform:MainMenu:MenuPopUp:MenuItem:Enabled := .F.
    I must repeat ==> Mainform:MainMenu:MenuItem:Enabled := .F.
    ELSE
    I can have the first one disabled and the second one enabled.
THIS IS REALLY DANGEROUS. FOR THIS REASON, I BELIEVE, IS NOT APPROPRIATE TO MAKE IT AVAILABLE.
2011-07-09 end correction

You can follow this compatibility, looking for this "aHmg3Comp" var name within the class.
If we remove this var and related use, we remove the HMG3 compatibility.

DEMO SOURCES:
demo_1.prg: demonstrates the use of the class, OOP syntax, but without assigning names to objects
demo_2.prg: demonstrates the use of the class, with XBase syntax, but without assigning names to objects
demo_3.prg: demonstrates the use of the class, OOP syntax, with assigning names to objects
demo_4.prg: demonstrates the use of the class, with XBase syntax, with assigning names to objects

I introduced some new features:
- You can define the font, which is inherited by every object that make up the menu
- Include icons
- Assign a name to all objects that make up the menu

At this time, I preferred to keep clear the difference from the HMG4, using different names.
Obviously, these will be aligned if it sees fit to apply this solution.
The only thing that I intend to keep different than HMG4, is the internal name of the object (generated automatically).
HMG4 use this solution: "'_HMG_OBJECT_' + hb_nToS(...." you can find in control.prg
I want use this: "'_HMG_MENU_' + hb_nToS(....".
In this way we can identify menu object and having: a different prefix name and a number sequence dedicated (see nMnuObjCounter)

Well, that's all folk.

I will wait your opinions.
2011-07-09 I have update zip file
Attachments
NewHmg4MenuHandler.zip
sources update
(44.04 KiB) Downloaded 60 times
Last edited by l3whmg on Sat Jul 09, 2011 1:23 pm, edited 1 time in total.
Luigi from Italy
www.L3W.it

User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Post by l3whmg » Sat Jul 09, 2011 12:53 pm

Hi friends.
I do a great mistake! I'm very, very :oops: .
The object it's ONLY ONE: yes, on a different level, but the same.
We can preserve HMG3 compatibility without problem.
I've update demo (some ot these were wrong) and Hmg.ch

Please geve me a sentence!
Attachments
NewHmg4MenuHandler.zip
souce update
(44.04 KiB) Downloaded 66 times
Luigi from Italy
www.L3W.it

User avatar
concentra
Posts: 256
Joined: Fri Nov 26, 2010 11:31 am
Location: Piracicaba - Brasil

Post by concentra » Mon Jul 11, 2011 12:24 pm

Hi Luigi.
The LQtMenu class mixes different object types in the same class.
A LQtMenu object can be a menu, a menubar, a menuitem, an action or a separator.
In my opinion, this isn't an object oriented practice.
Each different object type must have its own class, sharing code at a higher level when necessary, inheriting from an intermediary class.
Just my 2 cents ...
[[]] Mauricio Ventura Faria

User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Post by l3whmg » Sat Jul 16, 2011 3:25 pm

I'm just back today from holiday.
I understand your POW, but I think not always every QT object must have a HMG4 object. On the other hand QT have only three objects: QMenubar (mainmenu), QMenu(sublevel or popup) and QAction( item and separator).
But most important: at this moment you can explore programs that using QT library. Their logic is to have a place where QMenubar, QMenu and QAction are used all together in a defined order. For example:

Code: Select all

............
     QMenu *fileMenu;
     QMenu *editMenu;
     QMenu *helpMenu;
..........
void MainWindow::createMenus()
 {
     fileMenu = menuBar()->addMenu(tr("&File"));
     fileMenu->addAction(newAct);
     fileMenu->addAction(openAct);
     fileMenu->addAction(saveAct);
     fileMenu->addAction(saveAsAct);
     fileMenu->addSeparator();
     fileMenu->addAction(exitAct);

     editMenu = menuBar()->addMenu(tr("&Edit"));
     editMenu->addAction(cutAct);
     editMenu->addAction(copyAct);
     editMenu->addAction(pasteAct);

     menuBar()->addSeparator();

     helpMenu = menuBar()->addMenu(tr("&Help"));
     helpMenu->addAction(aboutAct);
     helpMenu->addAction(aboutQtAct);
 }
But, we are writing a layer on top of HbQt and Qt and we can't have a single place.
My intention was to gives an idea: there are other POW or better code to remove var from .CH ? This was my target.
Please remember that the old HMG3 programs must run without a lot of changes.

Anyway.

Cheers.
Luigi from Italy
www.L3W.it

Post Reply