wxRibbon shows but does not refresh or respond - wxwidgets

From the old style menus, I am trying to switch to ribbons. I have a wxMDIParentFrame which has two main children. Here is my attempt to switch to ribbons.
The code:
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
m_StatusBar = this->CreateStatusBar( 2, wxST_SIZEGRIP, wxID_ANY );
wxMenuBar* m_MenuBar = new wxMenuBar( 0 ); //looks nonsense but I am getting warning messages because MDIParentFrame automatically adds a window menu
this->SetMenuBar(m_MenuBar);
wxBoxSizer* bSizer1;
bSizer1 = new wxBoxSizer( wxVERTICAL );
m_ribbonBar = new wxRibbonBar( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxRIBBON_BAR_DEFAULT_STYLE );
m_ribbonBar->SetArtProvider(new wxRibbonDefaultArtProvider);
m_RibbonPage_Home = new wxRibbonPage( m_ribbonBar, wxID_ANY, wxT("Home") , wxBitmap( wxT("images/icons/open.bmp"), wxBITMAP_TYPE_ANY ) , 0 );
m_ribbonPanelHome = new wxRibbonPanel( m_RibbonPage_Home, wxID_ANY, wxT("Document") , wxNullBitmap , wxDefaultPosition, wxDefaultSize, wxRIBBON_PANEL_DEFAULT_STYLE );
m_ribbonButtonBarDocument = new wxRibbonButtonBar( m_ribbonPanelHome, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
m_ribbonButtonBarDocument->AddButton( wxID_ANY, wxT("Open"), wxBitmap( wxT("images/icons/open.bmp"), wxBITMAP_TYPE_ANY ), wxEmptyString);
m_ribbonPageTools = new wxRibbonPage( m_ribbonBar, wxID_ANY, wxT("Tools") , wxNullBitmap , 0 );
m_ribbonBar->SetActivePage( m_ribbonPageTools );
m_ribbonPanelProcessEngTools = new wxRibbonPanel( m_ribbonPageTools, wxID_ANY, wxT("Process Engineering Tools") , wxBitmap( wxT("images/icons/open.bmp"), wxBITMAP_TYPE_ANY ) , wxDefaultPosition, wxDefaultSize, wxRIBBON_PANEL_DEFAULT_STYLE );
m_ribbonButtonBar2 = new wxRibbonButtonBar( m_ribbonPanelProcessEngTools, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
m_ribbonButtonBar2->AddButton( wxID_ANY, wxT("Unit Convertor"), wxBitmap( wxT("images/icons/open.bmp"), wxBITMAP_TYPE_ANY ), wxEmptyString);
m_ribbonBar->Realize();
// Connect Events
this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( myFrame::mainFrameOnClose ) );
this->Connect( wxEVT_ICONIZE, wxIconizeEventHandler( myFrame::mainFrameOnIconize ) );
this->Connect( wxEVT_IDLE, wxIdleEventHandler( myFrame::mainFrameOnIdle ) );
this->Connect( wxID_ANY, wxEVT_COMMAND_RIBBONBAR_HELP_CLICKED, wxRibbonBarEventHandler( myFrame::OnRibbonBarHelpClick ) );
this->Connect( wxID_ANY, wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_UP, wxRibbonBarEventHandler( myFrame::OnRibbonBarTabRightUp ) );
this->Connect( wxID_ANY, wxEVT_COMMAND_RIBBONBAR_TOGGLED, wxRibbonBarEventHandler( myFrame::OnRibbonBarToggled ) );
this->Connect( wxID_ANY, wxEVT_COMMAND_RIBBONBUTTON_CLICKED, wxRibbonButtonBarEventHandler( myFrame::OpenOnRibbonButtonClicked ) );
this->Connect( wxID_ANY, wxEVT_COMMAND_RIBBONBUTTON_CLICKED, wxRibbonButtonBarEventHandler( myFrame::UCOnRibbonButtonClicked ) );
#if wxUSE_STATUSBAR
m_StatusBar->SetStatusText(_("Welcome..."), 0);
m_StatusBar->SetStatusText(_(""), 1);
#endif
m_frmCmdWindow=new frmCommandWindow(this); //wxMDIChildFrame
//m_frmCmdWindow->Show(true);
m_frmICell=CreateFrmICell(this); //wxMDIChildFrame
//m_frmICell->Show(true);
int height=0, width=0;
wxDisplaySize(&width,&height);
this->SetSize(width,height);
this->Tile();
bSizer1->Add( m_ribbonBar, 0, wxALL|wxEXPAND, 5 );
this->SetSizer( bSizer1 );
this->Centre( wxBOTH );
The appearance of the ribbon looks normal however following are the problems:
1) I can not interact with any of the buttons on the ribbon
2) It does not refresh (does not redraw itself).
*The ribbon is there as if there is a picture drawn and when I show any of the child frames the ribbon disappears.
3) wxMDIParentFrame has an automatic window menu attached to menubar to manage its child windows. How can I disable this window menu so that I can remove menubar.
By the way, I am using Windows 10, gcc 4.6.2 and wxWidgets 3.0.2.
What could I be doing wrong?
Thanking you in advance!

This solution works for me:
void MainFrame::CreateControls()
{
////#begin MainFrame content construction
// Generated by DialogBlocks, 18/10/2015 12:17:49 (unregistered)
MainFrame* itemMDIParentFrame1 = this;
wxStatusBar* itemStatusBar2 = new wxStatusBar( itemMDIParentFrame1, ID_STATUSBAR, wxST_SIZEGRIP|wxNO_BORDER );
itemStatusBar2->SetFieldsCount(2);
itemMDIParentFrame1->SetStatusBar(itemStatusBar2);
////#end MainFrame content construction
wxBitmap tmp(16, 16);
m_RibbonBar = new wxRibbonBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxRIBBON_BAR_DEFAULT_STYLE);
m_RibbonBar->SetArtProvider(new wxRibbonDefaultArtProvider);
auto m_RibbonPage_Home = new wxRibbonPage(m_RibbonBar, wxID_ANY, wxT("Home"), wxNullBitmap, 0);
auto m_ribbonPageTools = new wxRibbonPage(m_RibbonBar, wxID_ANY, wxT("Tools"), wxNullBitmap, 0);
auto m_ribbonPanelHome = new wxRibbonPanel(m_RibbonPage_Home, wxID_ANY, wxT("Document"), wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxRIBBON_PANEL_DEFAULT_STYLE);
auto m_ribbonPanelProcessEngTools = new wxRibbonPanel(m_ribbonPageTools, wxID_ANY, wxT("Process Engineering Tools"), wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxRIBBON_PANEL_DEFAULT_STYLE);
auto m_ribbonButtonBar2 = new wxRibbonButtonBar(m_ribbonPanelProcessEngTools, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
auto m_ribbonButtonBarDocument = new wxRibbonButtonBar(m_ribbonPanelHome, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
m_ribbonButtonBarDocument->AddButton(wxID_NEW, wxT("Open"), tmp, wxEmptyString);
m_RibbonBar->SetActivePage(m_ribbonPageTools);
m_ribbonButtonBar2->AddButton(wxID_OPEN, wxT("Unit Convertor"), tmp, wxEmptyString);
auto clientWindow = GetClientWindow();
wxBoxSizer * sizer = new wxBoxSizer(wxVERTICAL);
SetSizer(sizer);
sizer->Add(m_RibbonBar, 0, wxGROW);
sizer->Add(clientWindow, 1, wxEXPAND);
m_RibbonBar->Realize();
}
Here is the resulting frame

Related

How to use PDF Sharp objects in my Migradoc document

I have an application that generates PDFs using the MigraDoc framework, however I have a requirement to add in a text driven watermark. I have found some examples of this being done using PDF Sharp here, however I just cant seem t be able to figure out how this will integrate with my Migradoc Document() object I am rendering.
I have the following code:
public byte[] render()
{
PdfDocument document = new PdfDocument();
CreateWaterMarks(document);
// *****************************
PdfDocumentRenderer renderer = new PdfDocumentRenderer(true);
renderer.Document = this.document;
renderer.RenderDocument();
byte[] pdfContents = null;
using (MemoryStream stream = new MemoryStream())
{
renderer.PdfDocument.Save(stream, true);
pdfContents = stream.ToArray();
}
return pdfContents;
}
This method is what is called to render the MigraDoc document and pass it out as a byte array. The second line of code in here calls the following method which is not doing what I am looking for:
void CreateWaterMarks(PdfDocument document)
{
PdfPage page = document.AddPage();
Document doc = this.document;
MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc);
docRenderer.PrepareDocument();
XRect A4Rect = new XRect(0, 0, pageActiveWidth, pageActiveHeight);
int pageCount = docRenderer.FormattedDocument.PageCount;
for (int idx = 0; idx < pageCount; idx++)
{
XFont font = new XFont("Verdana", 13, XFontStyle.Bold);
XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend);
XSize size = gfx.MeasureString("Watermark", font);
gfx.TranslateTransform(pageActiveWidth / 2, pageActiveHeight / 2);
gfx.RotateTransform(-Math.Atan(pageActiveHeight / pageActiveWidth) * 180 / Math.PI);
gfx.TranslateTransform(-pageActiveWidth / 2, -pageActiveHeight / 2);
XStringFormat format = new XStringFormat();
format.Alignment = XStringAlignment.Near;
format.LineAlignment = XLineAlignment.Near;
XBrush brush = new XSolidBrush(XColor.FromArgb(128, 255, 0, 0));
gfx.DrawString("Watermark", font, brush, new XPoint((pageActiveWidth - size.Width) / 2, (pageActiveHeight - size.Height) / 2), format);
docRenderer.RenderPage(gfx, idx + 1);
}
}
I was hoping that this would magically make these PDFSharp watermarks appear but alas I get nothing!
I have this working using the following code:
public byte[] render()
{
PdfDocumentRenderer renderer = new PdfDocumentRenderer(true);
renderer.Document = this.document;
renderer.RenderDocument();
renderer.PrepareRenderPages();
CreateWatermarks(renderer);
byte[] pdfContents = null;
using (MemoryStream stream = new MemoryStream())
{
renderer.PdfDocument.Save(stream, true);
pdfContents = stream.ToArray();
}
return pdfContents;
}
private void CreateWatermarks(PdfDocumentRenderer renderer)
{
int pages = renderer.DocumentRenderer.FormattedDocument.PageCount;
for (int i = 0; i < pages; ++i)
{
var page = renderer.PdfDocument.Pages[i];
XFont font = new XFont("Verdana", 27, XFontStyle.Bold);
XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend);
XSize size = gfx.MeasureString("Watermark", font);
gfx.TranslateTransform(pageActiveWidth / 2, pageActiveHeight / 2);
gfx.RotateTransform(-Math.Atan(pageActiveHeight / pageActiveWidth) * 180 / Math.PI);
gfx.TranslateTransform(-pageActiveWidth / 2, -pageActiveHeight / 2);
XStringFormat format = new XStringFormat();
format.Alignment = XStringAlignment.Near;
format.LineAlignment = XLineAlignment.Near;
XBrush brush = new XSolidBrush(XColor.FromArgb(128, 255, 0, 0));
gfx.DrawString("Watermark", font, brush, new XPoint((pageActiveWidth - size.Width) / 2, (pageActiveHeight - size.Height) / 2), format);
}
}

3d cube using java3d virtualUniverse

I am interested in java3d API. I have been following java 3d programming by Daniel Selman. I tried to create a simple 3d cube using the following code given in the book:
public static void main(String[] args)
{
Cude3d cd= new Cude3d();
cd.go();
//create the Universe
}
The go method is:
private void go() {
VirtualUniverse m_Universe = new VirtualUniverse();
//create the position for the Locale
int[] xPos = { 0, 0, 0, 0, 0, 0, 0, 0 }; int[] yPos = { 0, 0, 0, 0, 0, 0, 0, 0 };
int[] zPos = { 0, 0, 0, 1, 0, 0, 0, 0 };
HiResCoord hiResCoord = new HiResCoord( xPos, yPos, zPos );
//create the Locale and attach to the VirtualUniverse
Locale locale = new Locale( m_Universe, hiResCoord );
//create the BranchGroup containing the Geometry for the scene
BranchGroup sceneBranchGroup = createSceneBranchGroup();
sceneBranchGroup.compile();
//add the scene BranchGroup to the Locale
locale.addBranchGraph( sceneBranchGroup );
The scene graph is created as:
BranchGroup vpBranchGroup = new BranchGroup();
//create a TransformGroup to scale the ViewPlatform //(and hence View)
TransformGroup tg = new TransformGroup();
ColorCube cc= new ColorCube(.2);
cc.setBounds(new BoundingSphere());
tg.addChild(cc);
//create the ViewPlatform
ViewPlatform vp = new ViewPlatform(); vp.setViewAttachPolicy( View.RELATIVE_TO_FIELD_OF_VIEW );
//attach the ViewPlatform to the TransformGroup
tg.addChild( vp );
//attach the TransformGroup to the BranchGroup
vpBranchGroup.addChild( tg );
Transform3D t3d = new Transform3D();
t3d.setTranslation( new Vector3d( 10.0, 10.0, 10.0 ) ); tg.setTransform( t3d );
View view = new View();
//create the PhysicalBody and PhysicalEnvironment for the View
//and attach to the View
PhysicalBody pb = new PhysicalBody();
PhysicalEnvironment pe = new PhysicalEnvironment();
view.setPhysicalEnvironment( pe );
view.setPhysicalBody( pb );
//attach the View to the ViewPlatform
view.attachViewPlatform( vp );
//set the near and far clipping planes for the View
view.setBackClipDistance( 110 );
view.setFrontClipDistance( 10 );
GraphicsConfigTemplate3D gc3D = new GraphicsConfigTemplate3D();
gc3D.setSceneAntialiasing( GraphicsConfigTemplate.PREFERRED );
GraphicsDevice gd[] = GraphicsEnvironment.
getLocalGraphicsEnvironment().getScreenDevices();
Canvas3D c3d = new Canvas3D( gd[0].getBestConfiguration( gc3D ) );
//set the size of the Canvas3D
c3d.setSize( 512, 512 );
//add the Canvas3D to the View so that it is rendered into
view.addCanvas3D( c3d );
//add the Canvas3D component to a parent AWT or Swing Panel
add( c3d );
this.setVisible(true);
this.setSize(500, 500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
return vpBranchGroup;
I am not able to know where it went wrong. Any help is appreciated.
Thanks in advance.

how Html helper tag to display dynamically image

iam create dynamically image but can`t show in tag img
Please guide me how to set the path dynamically in View.
this my code
public class VisitCounterController : Controller
{
// GET: VisitCounter
public ActionResult Visit()
{
Response.Clear();
Response.Cache.SetNoStore();
Response.ContentType = "image/jpeg";
int length = 6;
int fontSize = 16;
int letterWidth = 15;
int letterHeight = 18;
int letterOffsetX = 2;
Color backgroundColor = Color.Black;
int number = 100;
string sNum = number.ToString().PadLeft(length, '0');
Bitmap bmp = new Bitmap(letterWidth * length + 2, letterHeight + 2);
Graphics gr = Graphics.FromImage(bmp);
gr.CompositingQuality = CompositingQuality.HighQuality;
gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
gr.SmoothingMode = SmoothingMode.HighQuality;
SolidBrush bgBrush = new SolidBrush(backgroundColor);
gr.FillRegion(bgBrush, new Region(new Rectangle(0, 0, bmp.Width, bmp.Height)));
Font font = new Font("Arial", fontSize, FontStyle.Bold, GraphicsUnit.Pixel);
for (int i = 0; i <= length - 1; i++)
{
gr.DrawRectangle(Pens.LightGray, new Rectangle(i * letterWidth + 1, 1, letterWidth, letterHeight));
gr.DrawString(sNum[i].ToString(), font, Brushes.White, i * letterWidth + letterOffsetX, 1);
}
gr.DrawRectangle(Pens.Gray, new Rectangle(0, 0, letterWidth * length + 2, letterHeight + 2));
MemoryStream ms = new MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
return File(ms.ToArray(), "image/png");
}
iam use this code for show image but this not correct how shoved this problem thanks
<img src="~/Views/VisitCounter/Visit.cshtml" alt="Sample Image" width="300px" />
In this line you are referencing the view itself and not the controller action.
<img src="~/Views/VisitCounter/Visit.cshtml" alt="Sample Image" width="300px" />
Set the img src to #Url.Action("Visit", "VisitCounter").
<img src="#Url.Action("Visit", "VisitCounter")" alt="Sample Image" width="300px" />

Special character doesn't appear the same on windows phone emulator and real device

my problem is a bit strange!! I'm going to create a calendar tile with writable bitmap for windows phone 8. so I'm using this character "📆".
I'm using the below code and everything works fine as I expected on emulator. but when I test my app on a real device,calendar character will be appeared different
private void RenderText9()
{
int width = 159;
int height = 159;
string imagename = "SmallBackground";
WriteableBitmap b = new WriteableBitmap(width, height);
var canvas = new Grid();
canvas.Width = b.PixelWidth;
canvas.Height = b.PixelHeight;
var background = new Canvas();
background.Height = b.PixelHeight;
background.Width = b.PixelWidth;
SolidColorBrush backColor = new SolidColorBrush((Color)Application.Current.Resources["PhoneAccentColor"]);
background.Background = backColor;
var textBlock = new TextBlock();
textBlock.Text = "25";
textBlock.TextAlignment = TextAlignment.Center;
textBlock.Margin = new Thickness(0, 72, 0, 0);
textBlock.Width = 159;
textBlock.TextWrapping = TextWrapping.Wrap;
textBlock.Foreground = new SolidColorBrush(Colors.White);
textBlock.FontSize = 35;
var textBlock2 = new TextBlock();
textBlock2.Text = "📆";
textBlock2.TextAlignment = TextAlignment.Center;
textBlock2.Margin = new Thickness(0, 40, 0, 0);
textBlock2.Width = 159;
textBlock2.TextWrapping = TextWrapping.Wrap;
textBlock2.Foreground = new SolidColorBrush(Colors.White); //color of the text on the Tile
textBlock2.FontSize = 75;
canvas.Children.Add(textBlock);
canvas.Children.Add(textBlock2);
b.Render(background, null);
b.Render(canvas, null);
b.Invalidate(); //Draw bitmap
//Save bitmap as jpeg file in Isolated Storage
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream imageStream = new IsolatedStorageFileStream("/Shared/ShellContent/" + imagename + ".jpg", System.IO.FileMode.Create, isf))
{
b.SaveJpeg(imageStream, b.PixelWidth, b.PixelHeight, 0, 100);
}
}
}
this is the tile on both emulator and real device(pay attention to difference).
anybody knows any solution??? I don't understand the reason !!

Photoshop script hide and save with level name

I have a Photoshop file with around 200 levels, I need to save for web every single level with the level's name hiding the other levels...Is there any way to do that with script?
Thanks
This will save out each layer as a jpeg, named after the layer name. You don't need to hide the layers as you go; instead each layer it gets duplicated as a new image, flattened, saved and then closed. Won't work with any groups (normally you have to pay extra for that ;) )
var srcDoc = app.activeDocument;
var numOfLayers = srcDoc.layers.length;
var jpegQuality = 12;
for (var i = numOfLayers -1; i >= 0 ; i--)
{
var theLayerName = srcDoc.layers[i].name;
var theFile = srcDoc.path;
srcDoc.activeLayer = srcDoc.artLayers[i];
var id2784 = charIDToTypeID( "Mk " );
var desc707 = new ActionDescriptor();
var id2785 = charIDToTypeID( "null" );
var ref508 = new ActionReference();
var id2786 = charIDToTypeID( "Dcmn" );
ref508.putClass( id2786 );
desc707.putReference( id2785, ref508 );
var id2787 = charIDToTypeID( "Nm " );
desc707.putString( id2787, theLayerName );
var id2788 = charIDToTypeID( "Usng" );
var ref509 = new ActionReference();
var id2789 = charIDToTypeID( "Lyr " );
var id2790 = charIDToTypeID( "Ordn" );
var id2791 = charIDToTypeID( "Trgt" );
ref509.putEnumerated( id2789, id2790, id2791 );
desc707.putReference( id2788, ref509 );
executeAction( id2784, desc707, DialogModes.NO );
app.activeDocument.flatten();
SaveForWeb(theFile, jpegQuality);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
app.activeDocument = srcDoc;
}
function SaveForWeb(saveFile, jquality)
{
var sfwOptions = new ExportOptionsSaveForWeb();
sfwOptions.format = SaveDocumentType.JPEG;
sfwOptions.includeProfile = false;
sfwOptions.interlaced = 0;
sfwOptions.optimized = true;
sfwOptions.quality = jquality;
activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);
}