MFC Change CMFCToolBar button to Toggle instead of press/release? - winapi

I found an article online that said to setup the toolbar button to be a type that stays pressed you just set a style TBBS_CHECKBOX on the button but it doesn't work for me (it still acts like a normal button). I confirmed the style is set, just after created and the SetWindowText() MFC wizard setup of CMainFrame::OnCreate(). What am I doing wrong?
for (int i=0; ; i++) {
int id=m_wndToolBar.GetItemID(i);
if (id==0) {
break;
}
if (id == ID_THE_ID) {
m_wndToolBar.SetButtonStyle(i, TBBS_CHECKBOX);
}
}

Using Command Handlers is the recommended implementation here. A command ID may be used in multiple UI items, eg a menu item and a toolbar button. A handler affects all items with the same ID, so you don't need a separate one for each item. The CCmdUI Class provides methods that can cause UI items like menus or toolbar buttons to behave as push-buttons, check-boxes or radio-buttons, in addition to enabling/disabling.
In your example, suppose that the option whether to filter is instantiated on a per document basis, ie all views of the document would be filtered or non-filtered, all at the same time. You should define a boolean variable in your document class:
BOOL m_bFilterData = FALSE;
Then the ON_COMMAND and ON_UPDATE_COMMAND_UI handlers for the toolbar button with the Filter pic (and possibly a menu item as well):
BEGIN_MESSAGE_MAP(CMyDoc, CDocument)
.
.
ON_COMMAND(ID_VIEW_FILTERDATA, OnViewFilterData)
ON_UPDATE_COMMAND_UI(ID_VIEW_FILTERDATA, OnUpdateViewFilterData)
.
.
END_MESSAGE_MAP()
void CMyDoc::OnViewFilterData()
{
// Toggle filtered state
m_bFilterData = !m_bFilterData;
// Tell all views to refresh - You can limit this using the lHint/pHint params
UpdateAllViews(NULL, 0L, NULL);
}
void CMyDoc::OnUpdateViewFilterData(CCmdUI* pCmdUI)
{
// Enable/Disable as needed
pCmdUI->Enable(m_nTotalItems>0);
// Show pressed/checked if data filtered
pCmdUI->SetCheck(m_bFilterData);
}
Now, if the filter option is instantiated per view, ie each view can indpendently be filtered or non-filtered, the above must go to your view class(-es):
void CMyView::OnViewFilterData()
{
// Toggle filtered state
m_bFilterData = !m_bFilterData;
// Refresh this view only
.
.
}
void CMyView::OnUpdateViewFilterData(CCmdUI* pCmdUI)
{
// Enable/Disable as needed
pCmdUI->Enable(GetDocument()->m_nTotalItems > 0);
// Show pressed/checked if data filtered
pCmdUI->SetCheck(m_bFilterData);
}

Related

How to run javascript only after the view has loaded in Odoo 10

I installed web hide menu on https://www.odoo.com/apps/modules/8.0/web_menu_hide_8.0/
I modified to use it on Odoo 10, but the form will be adjusted to full width IF we press the hide button, if we were to change to another view after we pressed hide button, the form page will remain same as original (not full width).
So i need to adjust class "o_form_sheet" on form view after the page has been rendered. May i know how can i do that using javascript? Which class & method do i need to extend?
I'm going to answer my own question.
After some researched, i found out the best option was to inherit ViewManager widget using load_views function.
var ViewManager = require('web.ViewManager');
ViewManager.include({
load_views: function (load_fields) {
var self = this;
// Check if left menu visible
var root=self.$el.parents();
var visible=(root.find('.o_sub_menu').css('display') != 'none')
if (visible) {
// Show menu and resize form components to original values
root.find('.o_form_sheet_bg').css('padding', self.sheetbg_padding);
root.find('.o_form_sheet').css('max-width', self.sheetbg_maxwidth);
root.find('.o_form_view div.oe_chatter').css('max-width', self.chatter_maxwidth);
} else {
// Hide menu and save original values
self.sheetbg_padding=root.find('.o_form_sheet_bg').css('padding');
root.find('.o_form_sheet_bg').css('padding', '16px');
self.sheetbg_maxwidth=root.find('.o_form_sheet').css('max-width');
root.find('.o_form_sheet').css('max-width', '100%');
self.chatter_maxwidth=root.find('.o_form_view div.oe_chatter').css('max-width');
root.find('.o_form_view div.oe_chatter').css('max-width','100%');
}
return this._super.apply(this, arguments, load_fields);
},
});

Prevent TAB from landing on a CheckBoxTableCell<> in JavaFX 8

I have a TableView in JavaFX 8, which is editable. One of the fields is a CheckBoxTableCell.
I have noticed that the TAB key lands on the first CheckBoxTableCell in the grid and gets stuck there. I don't want this behavior. I like to navigate to the cell with the keyboard and activate with the SPACE. However I need tab to ignore this field - since it gets stuck.
I tried the following:
booleanColumn.setCellFactory (to -> {
CheckBoxTableCell<DTO, Boolean> cell = CheckBoxTableCell<>();
cell.setFocusTraversable(false);
return cell;
}
This however has no affect on the focus of the field, since it's editable, it lands on that control and gets stuck.
If I change to:
cell.setDisable(true);
Then TAB will skip the field, but I can land on the column with the arrow keys. However I can't select the checkbox with the mouse.
I am at a loss as what to do.
Thanks.
The workaround to get the TAB key working first implies consuming the event so the default TableView traversal engine doesn't process it, and selecting the next or previous cell instead.
This will move the selection from cell to cell:
table.getSelectionModel().setCellSelectionEnabled(true);
table.setOnKeyPressed(keyEvent -> {
switch (keyEvent.getCode()){
case TAB: {
keyEvent.consume();
if (keyEvent.isShiftDown()) {
personTable.getSelectionModel().selectPrevious();
} else {
personTable.getSelectionModel().selectNext();
}
break;
}
}
});
But it won't be enough to get the CheckBox focused, and the space key can't be used to select it. So a second step is required to move the focus from the selected cell to the inner checkbox.
When the cell gets the focus, its node will request it.
booleanColumn.setCellFactory (param -> {
CheckBoxTableCell<DTO, Boolean> cell = new CheckBoxTableCell<>();
cell.focusedProperty().addListener((obs, ov, nv) -> {
if (nv && cell.getGraphic() != null) {
cell.getGraphic().requestFocus();
}
});
return cell;
});
Notice you can't have both the cell and it's checkbox focused at the same time, so the cell will appear grey (selected but not focused), unless you modify its css.

How to make Sort Icon visible for all columns in GWT

I am creating an application where I need to do sort and search on header. I have used column.setSortable(true); and Creating sort handler. Again on other side I have created a custom header which will show textbox when clicking. I want to implement it like there will be sort icons clicking on that will sort while clicking on column label will open textbox.
Can anyone suggest how I can make sort icons visible in all the columns.
Currently when I click any column sort icon gets visible on that only.
Done fixing this. I have used overriding onPreviewColumnSortEvent and implemented is as below
#Override
public boolean onPreviewColumnSortEvent( Context context, Element elem, NativeEvent event )
{
if ( clickableTableCell.getColumnType().equals( ColumnType.TEXTBOX ) ) {
if ( sortFlag ) {
sortFlag = false;
} else {
sortFlag = true;
}
}
return sortFlag;
}

Adding functionality to wicket palette button

I want to add some functionality to the right arrow button, the one that puts the user selection into the selected elements panel. Specifically, when the user selects an element from the avaliable choices, I don't want the element to be taken to the selected elements panel if there are elements at the right panel of another palette. So basically, what I need is to execute custom java code when the button is pressed, and alter the default behavior of the palette when a condition occurs.
I found the solution somewhere else. Just in case someone needs it, here is what you have to do.
myPalette = new Palette<MyClass>(...) {
#Override
protected Recorder newRecorderComponent() {
Recorder<MyClass> recorder = super.newRecorderComponent();
recorder.add(new AjaxFormComponentUpdatingBehavior("onchange") {
protected void onUpdate(AjaxRequestTarget target) {
// Custom code
...
if (target != null)
// Update another component
target.add(anotherComponent);
}
}
);
return recorder;
}
};

SWT: paint on parts of a given composite control like Table-headers or the button of a Combo

The title is pretty self-explanatory, i'm currently adding PaintListeners to all the children, grand-children and so on, of the control i'd like to paint on. I have graphical errors with Tables and Combos at the moment, the PaintListener apparently doesn't apply to the header or the button in the combo.
How can i do this?
This is the code i use to add the listeners:
List<Control> controls = Lists.newArrayList();
controls.add(composite);
while (! controls.isEmpty()) {
Control c = controls.remove(0);
if (c instanceof Composite) {
controls.addAll(Arrays.asList(((Composite) c).getChildren()));
}
c.addPaintListener(new ControlPaintListener());
}

Resources