Invalidate() and child_wnd_name.InvalidateRect (&rect) cause different results - winapi

I am writing a dialog based application which has one static control, one button and two edit controls. The static's type is class MyStatic : public CStatic which has an OnPaint() defined as follows:
void MyStatic::OnPaint()
{
CPaintDC dc(this);
int Row = pBGDlg->iRow; //pBGDlg is a pointer to the dialog
int Column = pBGDlg->iColumn; //iRow and iColumn are variables of the two edit controls
int RowHei = pBGDlg->iRowHei;
int ColumnWid = pBGDlg->iColumnWid;
if (bBuPressed)
{
for (int i = 0; i <= Row; ++i)
{
dc.MoveTo (0, i * RowHei);
dc.LineTo (Column * ColumnWid, i * RowHei);
}
}
Whenever the user input two integers and press the button, the application will draw corresponding lines on the static
void CProjDlg::OnClickedIdpreview()
{
UpdateData ();
mystatic.GetClientRect (&rtStatic); //mystatic is the name of the static
iRowHei = (rtStatic.Height () - 1) / iRow;
iColumnWid = (rtStatic.Width () - 1) / iColumn;
mystatic.bBuPressed = true;
Invalidate ();
UpdateWindow ();
}
For Example:Input 4 to the 1st edit control and then input 1 to the 1st edit control. However, if I substitute mystatic.InvalidateRect(&rtStatic); and mystatic.UpdateWindow(); for Invalidate(); and UpdateWindow(); respectively, the application fails to erase previous results. For example: Input 4 to the 1st edit control and then input 5 to the 1st edit control. I can not figure out why the second method fails. Could anyone explain for me? Thank you very much.

Related

How to use auto scroll in Xamarin forms

I have number of records and it have option like click and drag to change places like music player.
In this case, if 10 records is there it shows 4 in screen we have to scroll the screen to see another record.
For that , if I have to change my 10 record to first , click the 10th record and if I go up the page must be scroll to top.
any idea? for this auto scroll ..answer or suggestion comment please.
//page view is may ui scroll view
//counter for if my image focus on last image then return on 1 img
//new PointF((float)(your image size * count),your top margin or your fram y);
int count = 0;
public async void StartTimer()
{
await Task.Delay(3000); //3 sec
count += 1;
if (count == 5)
{
count = 0;
}
var bottomOffset = new PointF((float)(UIScreen.MainScreen.Bounds.Width * count),0);
pageview.SetContentOffset(bottomOffset, animated: true);
StartTimer();
}
public override void ViewDidLoad(){
StartTimer();
}

Mouse Click Events on JTable

I want to get the index of selected row when user double clicks on a row.
Here is my code:
tab.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
int selectedRow = tab.getSelectedRow();
try {
String file = rows[selectedRow][2];
String path = "C:\\Users\\raj kumar\\Gallery\\" + file;
JLabel fileLable = new JLabel();
fileLable.setBounds(500, 600, 300, 300);
fileLable.setIcon(new ImageIcon(path));
pan.add(fileLable);
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
});
But the tab.getSelectedRow() returns -1 even though I double clicked the row in the table.
You want to know on which row your mouse points, but you ask which row is selected. So the simple solution is, instead of
int selectedRow = tab.getSelectedRow();
you can use
int row = tab.rowAtPoint(e.getPoint());
to get the wanted row. The Event e has every necessary information you need. The e.getPoint() returns the exact Point your cursor is currently located. And the rowAtPoint() should be self explaining.
This also makes sure that you only work with one row at a time, if this is important to you. I don't know how getSelectedRow() works if multiple rows are selected.

How could I choose one particular file to load with loadStrings

The title is explicit enough, I want to let the user choose the text file he want to open.
I do not know if there is an explorer or an input field already implemented on processing.
Any help would be great.
Use selectInput. From the Processing reference:
Opens a platform-specific file chooser dialog to select a file for input. After the selection is made, the selected File will be passed to the 'callback' function. If the dialog is closed or canceled, null will be sent to the function, so that the program is not waiting for additional input. The callback is necessary because of how threading works.
I've modified the example sketch they provide in the reference to include loading the file with the loadStrings method.
String[] txtFile;
void setup() {
selectInput("Select a file to process:", "fileSelected");
}
void fileSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
} else {
String filepath = selection.getAbsolutePath();
println("User selected " + filepath);
// load file here
txtFile = loadStrings(filepath);
}
}
There is no Implemented method, but you could could make a buffer and monitor key presses like so:
String[] File;
String keybuffer = "";
Char TriggerKey = Something;
void setup(){
//do whatever here
}
void draw(){
//Optional, to show the current buffer
background(255);
text(keybuffer,100,100);
}
void keyPressed(){
if(keyCode >= 'a' && keyCode <= 'z'){
keybuffer = keybuffer + key;
}
if(key == TriggerKey){
File = loadStrings(keybuffer + ".txt");
}
}
when triggerkey is pressed, it loads the file

IUP, mouse events on matrix

I have basic confusion in understanding of IUP events system.
Now I am talking about matrix.
This is how it is created:
Ihandle *create_mat(void)
{
mat = IupMatrix(NULL);
IupSetAttribute(mat, "READONLY", "YES");
IupSetCallback(mat, "CLICK_CB", (Icallback)click);
IupSetCallback(mat, "BUTTON_CB", (Icallback)button);
return mat;
}
Here are callbacks:
int click(Ihandle *mat, int lin, int col)
{
char* value = IupMatGetAttribute(mat, "", lin, col);
if (!value) value = "NULL";
printf("click_cb(%d, %d)\n", lin, col);
return IUP_DEFAULT;
}
int button(Ihandle *mat, int button, int pressed, int x, int y, char* status)
{
printf("button %d, %d, %d, %d %s\n", button, pressed, x, y, status);
return IUP_DEFAULT;
}
Problem is in that I need both callbacks active but in showed situation CLICK event isn't fired.
If I disable BUTTON_CB then CLICK event is fired. But I need both, for click, left button doubleclick, right button release etc...
Is this normal behavior that BUTTON_CB excludes CLICK_CB or I do something wrong?
Actually, how would I get "lin" and "col" from inside BUTTON_CB or WHEEL_CB handler of matrix if CLICK_CB, ENTERITEM_CB and LEAVEITEM_CB which gives lin and col is not available (not fired in described situation)?
And more, how would I get "active control" (name, type of control with focus) from event handlers used on form's level?
Is this normal behavior that BUTTON_CB excludes CLICK_CB or I do something wrong?
Yes, it is. Because the BUTTON_CB is a IupCanvas callback and CLICK_CB is a IupMatrix callback. Remeber that IupMatrix inherits from IupCanvas. So internally IupMatrix is using the BUTTON_CB callback to implement several features.
So in this case what you have to do is to save the previous callback before assigning a new one, and call the old one from inside your own. Something like this:
old_callback = IupGetCallback(mat, "BUTTON_CB");
IupSetCallback(mat, "BUTTON_CB", new_callback);
int new_callback(...)
{
return old_callback(...)
}
Actually, how would I get "lin" and "col" from inside BUTTON_CB or WHEEL_CB handler of matrix if CLICK_CB, ENTERITEM_CB and LEAVEITEM_CB which gives lin and col is not available (not fired in described situation)?
Use the function pos = IupConvertXYToPos(mat, x, y) where pos=lin*numcol + col. To compute lin and col is quite simple considering they are integer values.
And more, how would I get "active control" (name, type of control with focus) from event handlers used on form's level?
I don't fully undestood your question. But I think that IupGetFocus and IupGetClassName could be the functions you want.
I will answer to my own question by using Antonio's advices so other people interesting for IUP can have benefit from those posts.
If I understand well, what is not likely, here is how I make BUTTON_CB handler for my matrix:
int button(Ihandle *mat, int button, int pressed, int x, int y, char* status)
{
//actually 'name' is Ihandle
//and class name is a 'type'
//in compare with other toolkits
char* name = IupGetClassName(mat);
//so since we have handle already
//we can't be here if we are not in concrete matrix
//and this comparision is not needed
if (strncmp(name, "matrix", sizeof(name)) == 0)
{
//if left mouse button is down
if (button == IUP_BUTTON1 && pressed == 1)
{
//my calculation is not 100% correct
//but good enough for this sample
int pos = IupConvertXYToPos(mat, x, y);
_line = pos/numcol;
_col = pos%numcol;
//if is doubleclick
if (status[5] == 'D')
{
//press ENTER key
//and open another modal dialog
//with argument 'sel'
k_any(mat, K_CR);
printf("Doubleclick\n");
//say HANDLED for IUP
//but not matter when READONLY is "YES"
return IUP_IGNORE;
}
//calculate (public) sel
//for select a clicked line
sel = _line + from - 1;
refreshl(from, sel);
printf("Click\n");
return IUP_IGNORE;
}
}
return IUP_DEFAULT;
}
This work's as expected.
Please further suggestion if something is not OK.

BlackBerry - Custom centered cyclic HorizontalFieldManager

Trying to create a custom cyclical horizontal manager which will work as follows. It will control several field buttons where the buttons will always be positioned so that the focused button will be in the middle of the screen. As it is a cyclical manager once the focus moves to the right or left button, it will move to the center of the screen and all the buttons will move accordingly (and the last button will become the first to give it an cyclic and endless list feeling)
Any idea how to address this?
I tried doing this by implementing a custom manager which aligns the buttons according to the required layout. Each time moveFocus() is called I remove all fields (deleteAll() ) and add them again in the right order.
Unfortunately this does not work.
Using HorizontalButtonFieldSet class from KB How to - Implement advanced buttons, fields, and managers:
class CentricHManager extends HorizontalButtonFieldSet {
int focusedFieldIndex = 0;
public void focusChangeNotify(int arg0) {
super.focusChangeNotify(arg0);
int focusedFieldIndexNew = getFieldWithFocusIndex();
if (focusedFieldIndexNew != focusedFieldIndex) {
if (focusedFieldIndexNew - focusedFieldIndex > 0)
switchField(0, getFieldCount() - 1);
else
switchField(getFieldCount() - 1, 0);
}
}
private void switchField(int prevIndex, int newIndex) {
Field field = getField(prevIndex);
delete(field);
insert(field, newIndex);
}
public void add(Field field) {
super.add(field);
focusedFieldIndex = getFieldCount() / 2;
setFieldWithFocus(getField(focusedFieldIndex));
}
}

Resources