-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #169 from shundhammer/huha-menu-01
New Widget: MenuBar
- Loading branch information
Showing
159 changed files
with
1,627 additions
and
475 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
SET( VERSION_MAJOR "3") | ||
SET( VERSION_MINOR "10" ) | ||
SET( VERSION_PATCH "1" ) | ||
SET( VERSION_MINOR "11" ) | ||
SET( VERSION_PATCH "0" ) | ||
SET( VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}${GIT_SHA1_VERSION}" ) | ||
|
||
##### This is need for the libyui core, ONLY. | ||
##### These will be overridden from exports in LibyuiConfig.cmake | ||
# Currently you must also change so_version in libyui.spec | ||
# *and also in **all** other* libyui-*.spec files in the other repositories. | ||
# Yes, such a design is suboptimal. | ||
SET( SONAME_MAJOR "12" ) | ||
SET( SONAME_MAJOR "13" ) | ||
SET( SONAME_MINOR "0" ) | ||
SET( SONAME_PATCH "0" ) | ||
SET( SONAME "${SONAME_MAJOR}.${SONAME_MINOR}.${SONAME_PATCH}" ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,248 @@ | ||
/* | ||
Copyright (c) [2020] SUSE LLC | ||
This library is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License as | ||
published by the Free Software Foundation; either version 2.1 of the | ||
License, or (at your option) version 3.0 of the License. This library | ||
is distributed in the hope that it will be useful, but WITHOUT ANY | ||
WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public | ||
License for more details. You should have received a copy of the GNU | ||
Lesser General Public License along with this library; if not, write | ||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth | ||
Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
|
||
// MenuBar example. | ||
// | ||
// Compile with: | ||
// | ||
// g++ -I/usr/include/yui -lyui MenuBar1.cc -o MenuBar1 | ||
|
||
#define YUILogComponent "example" | ||
#include "YUILog.h" | ||
|
||
#include "YUI.h" | ||
#include "YAlignment.h" | ||
#include "YDialog.h" | ||
#include "YLabel.h" | ||
#include "YCheckBox.h" | ||
#include "YLayoutBox.h" | ||
#include "YMenuBar.h" | ||
#include "YSquash.h" | ||
#include "YWidgetFactory.h" | ||
#include "YShortcut.h" | ||
#include "YEvent.h" | ||
|
||
|
||
using std::string; | ||
|
||
|
||
// Widgets | ||
|
||
YDialog * dialog = 0; | ||
YMenuBar * menuBar = 0; | ||
YLabel * lastEventLabel = 0; | ||
YCheckBox * readOnlyCheckBox = 0; | ||
|
||
|
||
// Menus and Menu Items | ||
|
||
YMenuItem * fileMenu = 0; | ||
YMenuItem * editMenu = 0; | ||
YMenuItem * viewMenu = 0; | ||
YMenuItem * optionsMenu = 0; | ||
|
||
|
||
// "File" menu | ||
|
||
YMenuItem * actionOpen = 0; | ||
YMenuItem * actionSave = 0; | ||
YMenuItem * actionSaveAs = 0; | ||
YMenuItem * actionQuit = 0; | ||
|
||
|
||
// "Edit" menu | ||
|
||
YMenuItem * actionCut = 0; | ||
YMenuItem * actionCopy = 0; | ||
YMenuItem * actionPaste = 0; | ||
|
||
|
||
// "View" menu | ||
|
||
YMenuItem * actionViewNormal = 0; | ||
YMenuItem * actionViewCompact = 0; | ||
YMenuItem * actionViewDetailed = 0; | ||
|
||
|
||
// "View" -> "Zoom" submenu | ||
|
||
YMenuItem * zoomMenu = 0; | ||
YMenuItem * actionZoomIn = 0; | ||
YMenuItem * actionZoomOut = 0; | ||
YMenuItem * actionZoomDefault = 0; | ||
|
||
// "Options" menu | ||
|
||
YMenuItem * actionSettings = 0; | ||
|
||
|
||
// Function Prototypes | ||
|
||
void createWidgets(); | ||
void addMenus( YMenuBar * menuBar ); | ||
void handleEvents(); | ||
void showEvent( YMenuEvent * event ); | ||
void updateActions(); | ||
|
||
|
||
|
||
|
||
int main( int argc, char **argv ) | ||
{ | ||
YUILog::setLogFileName( "/tmp/libyui-examples.log" ); | ||
YUILog::enableDebugLogging(); | ||
|
||
createWidgets(); | ||
updateActions(); | ||
handleEvents(); | ||
|
||
dialog->destroy(); | ||
} | ||
|
||
|
||
/** | ||
* Create the widget tree for the main dialog | ||
**/ | ||
void createWidgets() | ||
{ | ||
yuiMilestone() << endl; | ||
|
||
YWidgetFactory * fac = YUI::widgetFactory(); | ||
|
||
dialog = fac->createPopupDialog(); | ||
YAlignment * minSize = fac->createMinSize( dialog, 50, 20 ); | ||
YLayoutBox * vbox1 = fac->createVBox( minSize ); | ||
menuBar = fac->createMenuBar( vbox1 ); | ||
|
||
addMenus( menuBar ); | ||
|
||
YAlignment * center = fac->createHVCenter( vbox1 ); | ||
YSquash * squash = fac->createHVSquash( center ); | ||
YLayoutBox * vbox2 = fac->createVBox( squash ); | ||
|
||
YAlignment * left = fac->createLeft( vbox2 ); | ||
fac->createLabel ( left, "Last Event:" ); | ||
fac->createVSpacing( vbox2, 0.2 ); | ||
YAlignment * minWidth = fac->createMinWidth( vbox2, 15 ); | ||
lastEventLabel = fac->createOutputField( minWidth, "<none>" ); | ||
|
||
fac->createVSpacing( vbox2, 2 ); | ||
readOnlyCheckBox = fac->createCheckBox( vbox2, "Read &Only", true ); | ||
readOnlyCheckBox->setNotify( true ); | ||
} | ||
|
||
|
||
void addMenus( YMenuBar * menuBar ) | ||
{ | ||
// The difference between a menu and a plain menu item is just that the | ||
// menu has child items whild the plain item does not. | ||
|
||
fileMenu = menuBar->addMenu( "&File" ); | ||
editMenu = menuBar->addMenu( "&Edit" ); | ||
viewMenu = menuBar->addMenu( "&View" ); | ||
optionsMenu = menuBar->addMenu( "&Options" ); | ||
|
||
actionOpen = fileMenu->addItem( "&Open..." ); | ||
actionSave = fileMenu->addItem( "&Save" ); | ||
actionSaveAs = fileMenu->addItem( "Save &As..." ); | ||
fileMenu->addSeparator(); | ||
actionQuit = fileMenu->addItem( "&Quit" ); | ||
|
||
actionCut = editMenu->addItem( "C&ut" ); | ||
actionCopy = editMenu->addItem( "&Copy" ); | ||
actionPaste = editMenu->addItem( "&Paste" ); | ||
|
||
actionViewNormal = viewMenu->addItem( "&Normal" ); | ||
actionViewCompact = viewMenu->addItem( "&Compact" ); | ||
actionViewDetailed = viewMenu->addItem( "&Detailed" ); | ||
viewMenu->addSeparator(); | ||
zoomMenu = viewMenu->addMenu( "&Zoom" ); | ||
|
||
actionZoomIn = zoomMenu->addItem( "Zoom &In" ); | ||
actionZoomOut = zoomMenu->addItem( "Zoom &Out" ); | ||
actionZoomDefault = zoomMenu->addItem( "Zoom &Default" ); | ||
|
||
actionSettings = optionsMenu->addItem( "&Settings..." ); | ||
|
||
menuBar->resolveShortcutConflicts(); | ||
menuBar->rebuildMenuTree(); | ||
} | ||
|
||
|
||
/** | ||
* Event loop and event handling for the main dialog | ||
**/ | ||
void handleEvents() | ||
{ | ||
yuiMilestone() << endl; | ||
|
||
while ( true ) | ||
{ | ||
YEvent * event = dialog->waitForEvent(); | ||
|
||
if ( event ) | ||
{ | ||
if ( event->eventType() == YEvent::CancelEvent ) // window manager "close window" button | ||
{ | ||
break; // leave event loop | ||
} | ||
|
||
if ( event->eventType() == YEvent::MenuEvent ) | ||
{ | ||
YMenuEvent * menuEvent = dynamic_cast<YMenuEvent *>( event ); | ||
|
||
if ( menuEvent ) | ||
{ | ||
showEvent( menuEvent ); | ||
|
||
if ( menuEvent->item() == actionQuit ) | ||
break; // leave event loop | ||
} | ||
} | ||
|
||
if ( event->widget() == readOnlyCheckBox ) | ||
updateActions(); | ||
} | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Show the (label of) the item causing a menu event in the 'lastEventLabel' | ||
* widget. | ||
**/ | ||
void showEvent( YMenuEvent * event ) | ||
{ | ||
if ( event && event->item() ) | ||
{ | ||
string text = YShortcut::cleanShortcutString( event->item()->label() ); | ||
lastEventLabel->setLabel( text ); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Update the available menu actions: Enable or disable some of them according | ||
* to the current status of the "Read Only" check box. | ||
**/ | ||
void updateActions() | ||
{ | ||
bool readOnly = readOnlyCheckBox->isChecked(); | ||
|
||
menuBar->setItemEnabled( actionSave, ! readOnly ); | ||
menuBar->setItemEnabled( actionCut, ! readOnly ); | ||
menuBar->setItemEnabled( actionPaste, ! readOnly ); | ||
} |
Oops, something went wrong.