How to add some padding for a block in IAR linker configuration file - sections

I am working on an IAR project. In its linker configuration file, a block is defined as the following
define block MY_BLOCK with alignment = 32 { section myblock };
place in CODE_RAM { block MY_BLOCK };
This created a MY_BLOCK memory object with 32 byte alignment, which is linked into physical memory CODE_RAM.
What I want to achieve is, leaving some extra padding area (say 64 bytes) in the end of the block. The block definition directive have the size parameter, if I want the MY_BLOCK size to grow to 1024, I can use
define block MY_BLOCK with alignment = 32, size = 1024 { section myblock };
And it works well.
However, I want the size to be relative to the original size. So I use
define block MY_BLOCK with alignment = 32, size = __section_size(section myblock) + 64 { section myblock };
This time linker report a error
Error[Lc009]: "__section_size" undefined
Looks like __section_size can be only used in C instead of linker configuration file.
In comparision, ARMGCC we can simply use
. = . + 64
in linker file to achieve this purpose. I am wondering if it is achievable in IAR.
Can someone help me out?

The way to achieve this is to create an empty block with the padding and add it to MY_BLOCK. To ensure that the content and the padding are placed in the order listed in the file we add the attribute fixed order to MY_BLOCK. We also need to add keep { block MY_PADDING }; to the configuration file to tell the linker to include MY_PADDING even though its content is not referenced from the application. The result looks something like this:
define block MY_PADDING with size = 64 {};
define block MY_BLOCK with alignment = 32, fixed order { section myblock,
block MY_PADDING };
keep { block MY_PADDING };
place in CODE_RAM { block MY_BLOCK };

Related

Gtk (mm) limit width of combobox

Because I use Comboboxes that may contain text entries of very long size,
which leads to the combobox increasing its width far beyond reasonable size,
I am trying to give a maximum width to the combobox.
If I am doing this like this:
class MyCombo : public Gtk::ComboBox {
private:
CellRendererText render;
public:
MyCombo() {
render.property_width_chars() = 10;
render.property_ellipsize() = Pango::ELLIPSIZE_END;
pack_start(render, true);
}
};
The result will be an empty cell of the desired width, which seems logical since I did not specify which column to show. But how can I do this with that attempt? Using pack_start will just bypass the renderer...
Another approach is this one:
class MyCombo : public Gtk::ComboBox {
private:
CellRendererText render;
public:
MyCombo() {
pack_start(render, true);
set_cell_data_func(render, sigc::mem_fun(*this, &MyCombo::render_iter));
}
void render_iter(const TreeModel::const_iterator& iter) {
Glib::ustring data = get_string_from_iter(iter);
int desired_width_chars = 10; //for example
render.property_text() = ellipsize_string(data, desired_width_chars);
}
};
Using that approach, it works, but the text in the popup (what opens up when u click the combobox) is also shortened which is not what I want (obviously the user should be able to read the whole string and I dont care about the popup widht.)
Can you please help me with this? I would be happy for any advice/alternative solutions.
Regards tagelicht
NOTE: set_wrap_width is a function that wraps the total number of entries in the combo box over a number of columns specified; it does not answer the question.
Using set_wrap_width(1) | Using set_wrap_width(5)
Following Noup's answer as a guide I managed to get the below code; which directly answers the question and its requirements (C++/Gtkmm).
// Get the first cell renderer of the ComboBox.
auto v_cellRenderer = (Gtk::CellRendererText*)v_comboBox.get_first_cell();
// Probably obsolete; Sets character width to 1.
v_cellRenderer->property_width_chars() = 1;
// Sets the ellipses ("...") to be at the end, where text overflows.
// See Pango::ELLIPSIZE enum for other values.
v_cellRenderer->property_ellipsize() = Pango::ELLIPSIZE_END;
// Sets the size of the box, change this to suit your needs.
// -1 sets it to automatic scaling: (width, height).
v_cellRenderer->set_fixed_size(200, -1);
Result (image):
Result of code
BE AWARE: Depending on where you perform the above code; either all the cells will be the same size, or just the box itself (intended).
From experimenting, I've found:
In the parent object constructor: All cell sizes are the same.
In a separate function: Only the first cell (the box) is affected.
I'd recommend you put the code in a function that's connected to the comboBox's changed signal, such as:
v_comboBox.signal_changed().connect(sigc::mem_fun(*this, &YourClass::comboBox_changedFunction));
This may be what you are looking for:
cell_renderer_text.set_wrap_width(10)
This is for Python, but you get the idea :-)
Unfortunately, the documentation is scarce. I found this by poking around in Anjuta/Glade.
Edit:
the docs are here. They are not overly helpful, but they do exist.
As an alternative, the following works for me without having to set wrap_width nor to subclass ComboBox (in Gtk#):
ComboBoxText cb = new ComboBoxText();
cb.Hexpand = true; //If there's available space, we use it
CellRendererText renderer = (cb.Cells[0] as CellRendererText); //Get the ComboBoxText only renderer
renderer.WidthChars = 20; //Always show at least 20 chars
renderer.Ellipsize = Pango.EllipsizeMode.End;
Note: I'm using Expand to use space if it's available. If you just want to keep the combo box on a fixed width, just remove that bit.

wxPerl: add component which resizes automatically when parent frame gets resized

I am relatively new to Perl and I am using wxPerl to create a GUI application. Now, I want to add a Panel into a Frame, possibly using a sizer so that the panel resizes automatically as the frame gets resized.
So here's what I got:
(1) I have to use a BoxSizer, which stretch components in one direction.
(2) I have to pass parameters in the Add subroutines to stretch components in another direction.
I wrote the following code:
package Main;
use Wx;
use parent 'Wx::App';
sub OnInit {
my $frame = Wx::Frame->new(undef, -1, "SimpleCalc ".$Information::VERSION_NO, [-1,-1], [-1,-1]);
my $centerPanel = Wx::Panel->new($frame, -1, [-1,-1], [-1,-1]);
#set red background
$centerPanel->SetBackgroundColour(Wx::Colour->new(255,0,0));
my $frameSizer = Wx::BoxSizer->new(wxHORIZONTAL);
$frameSizer->Add($centerPanel, 1, 0, 0);
$frame->SetSizer($frameSizer);
$frame->Center();
$frame->Show(1);
return 1;
}
my $app = Main->new;
$app->MainLoop;
The unwanted result:
What I want is to stretch the red panel in both (horizontal and vertical) direction, or in short, I want something similar to BorderLayout in Java.
According to some online tutorials, I tried to replace $frameSizer->Add($centerPanel, 1, 0, 0); with
$frameSizer->Add($centerPanel, 1, wxEXPAND, 0);, but the script doesn't run. An error occurs saying that it is unable to resolve overload for Wx::Sizer::Add(Wx::Panel, number, scalar, number). I also tried $frameSizer->Add($centerPanel, 1, 0, 0, wxEXPAND);, but the frame obtained is exactly the same as the frame in the image.
Is it possible to have something similar to Java's BorderLayout in wxPerl? Thanks in advance.
P.S. I know there is a duplicate, but there are no concrete answers...
Update
In case you weren't aware, the default sizer for any child window will make it fill its available space, so to achieve the effect you're asking for all you need is this
use strict;
use warnings;
package Information;
our $VERSION_NO = 9.99;
package Main;
use Wx qw/ :colour /;
use parent 'Wx::App';
sub OnInit {
my $frame = Wx::Frame->new(undef, -1, "SimpleCalc $Information::VERSION_NO");
my $centerPanel = Wx::Panel->new($frame);
$centerPanel->SetBackgroundColour(wxRED);
$frame->Center;
$frame->Show;
return 1;
}
my $app = Main->new;
$app->MainLoop;
Original
It would have helped you a lot if you had use strict and use warnings in place! I and several others have to endlessly encourage people to do that but it seems sometimes that the message will never get across. Please try to make a habit of adding these statements to the top of every Perl program you write, and help us to spread the word
There are two things preventing your program from working
The value wxHORIZONTAL is undefined because you haven't imported it from Wx, so you are passing a value of zero to Wx::BoxSizer->new without any warning being raised
You have used a value of zero for the third parameter to $frameSizer->Add, which prevents the panel from expanding transversly to the direction of the sizer. You need wxEXPAND in there to enable it, and you will also need to import the value of that constant of course
Here's a rewrite of your code that fixes these problems, and also takes advantage of the defaults that will be used for missing parameters. I've also used wxRED instead of creating a new Wx::Colour object. I had to set a value for $Information::VERSION_NO too
This code works as you expected
use strict;
use warnings;
package Information;
our $VERSION_NO = 9.99;
package Main;
use Wx qw/ :sizer :colour /;
use parent 'Wx::App';
sub OnInit {
my $frame = Wx::Frame->new(undef, -1, "SimpleCalc $Information::VERSION_NO");
my $centerPanel = Wx::Panel->new($frame);
$centerPanel->SetBackgroundColour(wxRED);
my $frameSizer = Wx::BoxSizer->new(wxHORIZONTAL);
$frameSizer->Add($centerPanel, 1, wxEXPAND);
$frame->SetSizer($frameSizer);
$frame->Center;
$frame->Show;
return 1;
}
my $app = Main->new;
$app->MainLoop;
output
Fixed WxWidgets screen http://bit.ly/1JNrrEL

TinyMCE: Get orignial textarea reference within initialization

Problem
Width of the <textarea> is defined by CSS class, for ex.: wMax or wDefault. In first case it is 100%, in the second, lets say 200px. By default TinyMCE converts everything to fixed width in pixels. Ofcourse I can set width:100% inside tinyMCE.init(), but that will not cover textarea's with wDefault / fixed with.
What I need
I need TinyMCE width to behave the same as original, % or px depending on it's CSS class.
If I could find a reference to the original textarea element within tinyMCE.init() procedure, then I could read CSS class from it, and set width: (textarea.hasClass('wMax') ? '100%' : null) or something like that
I am aware of the getElement() function, which gets me exactly that textarea. But where do I run it from? tinyMCE.activeEditor is null within init().
I'm currently still using TinyMCE 3, but it would be nice if you could answer this also for 4.x version, if there is any difference ofcourse...
Found the solution myself. Sharing.
Answering my own question in the title: It's not possible to refer to the textarea within init() procedure directly, because it does not run for each tinyMCE instance. It runs only once. But: TinyMCE has a customizable setup function, which does run for every instance and has all required references to solve the mentioned problem.
With the following code:
tinyMCE.init({
// ... your settings here ...
setup: function(ed){
if(ed.getElement().hasClass('wMax')){
ed.settings.width = '100%';
}
}
});
Any textarea with CSS class 'wMax' (replace with your own) will be replaced by TinyMCE instance having 100% width. All others will have a fixed width, equal to the width of the textarea at the moment of initialization. You can expand this approach with any width, like wHalf width:50% etc.
Note: .hasClass() function is a part of Mootools JS library. Replace with another if you use a different library.
I don't know if this will lead you into the right direction. I use this code to adjust the iframe height to fit the entered content. You could tweak it a bit to adjust its height and width to your needs (you will need to get the textarea by $('#' + ed.id) onInit.
Here is the function. Basically it changes the style attributes explicitly of the editor iframe
resizeIframe: function(frameid) {
var frameid = frameid ? frameid : this.editor.id+'_ifr';
var currentfr=document.getElementById(frameid);
if (currentfr && !window.opera){
currentfr.style.display="block";
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) { //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight + 26;
}
else if (currentfr.Document && currentfr.Document.body.scrollHeight) { //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
}
styles = currentfr.getAttribute('style').split(';');
for (var i=0; i<styles.length; i++) {
if ( styles[i].search('height:') ==1 ){
styles.splice(i,1);
break;
}
};
currentfr.setAttribute('style', styles.join(';'));
}
},

Has anyone used MT.D MultilineEntryElement?

I'm using the most recent one created by Alxandr (Feb/2012).
I'm trying to add it to a section using the same technique as I would adding an EntryElement. The MultilineEntryElement adds to the section but the receiving cell will not expand past it's default size. The MLEE will then overwrite the section below. I would like it to default to full screen width and 10 lines long. What is the best way to do this?
Thanks you!
Matt
To deal with this problem, set the RootElement's UnevenRows property to true, like this:
var r = new RootElement ("foo") { ... }
r.UnevenRows = true;
I did a bit more research on this issue. Please note - I am using my own implementation of MultilineEntryElement which is probably a bit different than others'.
First, it's worth stating that the issue does not manifest for me in "simple" scenarios - where a MultilineEntryElement is placed inside a section which is created as part of the initial creation of the RootElement. The issue only manifests when I manipulate an existing RootElement that has already been rendered by the DialogViewController.
It appears that there is a bug in the way MonoTouch.Dialog computes sizing of rows. If an element implements IElementSizing, then MT.D will call its GetHeight() overload. Once MT.D has detected an element with "irregular" height, it appears to need to call this method every time it processes a change to the enclosing section. This can be expensive... So if MT.D lays out a RootElement and hasn't found an element that implements IElementSizing, it appears that (perhaps intended as an optimization?) MT.D will IGNORE IElementSizing information for any elements that are added POST initial rendering. So the CELL's RowHeight property will return a standard row height, and the MultilineEntryElement will render a UITextView that spills over the cells below it.
The workaround I've come up with is to create a simple element called DummyElement which implements IElementSizing and returns 0 for GetHeight(), and to add it to the initial RootElement before the initial layout happens. If you do that, MT.D will register that there's an element which has an irregular height, and call the GetHeight() method on your MultilineEntryElement when you later add it to your element "DOM".
Here is my minimal impl of DummyElement in case it helps:
public class DummyElement : Element, IElementSizing
{
public DummyElement() : base ("empty")
{
}
public float GetHeight (UITableView tableView, NSIndexPath indexPath)
{
return 0;
}
}

GtkImage File Name

How can I get the file name of the image used in a GtkImage widget?
I have a GtkImage widget that displays different images. I want to be able to click on the GtkImage, determine which image has been clicked i.e. get the file name, then display a larger version.
Thanks,
You can get the value of "file" property of GtkImage using g_object_get_property. Something on these lines:
GValue value = {0,};
/* If you have glib version 2.30 or higher use:
* GValue value = G_VALUE_INIT;
*/
g_value_init (&value, G_TYPE_STRING);
/* Assuming image is a valid GtkImage */
g_object_get_property(G_OBJECT(image), "file", &value);
printf("\n Filename = %s\n", g_value_get_string(&value));
Side note: To make use of the Glib's type system, g_type_init() should have been called. g_type_init() is called internally as a consequence of Gtk initialization through gtk_init.
Hope this helps!