/********************************************************************* * * _ChangeWindowPosSize */ static void _ChangeWindowPosSize(FRAMEWIN_Handle hWin, int* px, int* py) { int dx = 0, dy = 0; GUI_RECT Rect; WM_GetClientRectEx(hWin, &Rect); /* Calculate new size of window */ if (_HasCaptured & RESIZE_X) { dx = (_HasCaptured & REPOS_X) ? (_CaptureX - *px) : (*px - _CaptureX); } if (_HasCaptured & RESIZE_Y) { dy = (_HasCaptured & REPOS_Y) ? (_CaptureY - *py) : (*py - _CaptureY); } /* Check the minimal size of window */ if ((Rect.x1 + dx + 1) < MIN_SIZE_X) { dx = MIN_SIZE_X - (Rect.x1 + 1); *px = _CaptureX; } if ((Rect.y1 + dy + 1) < MIN_SIZE_Y) { dy = MIN_SIZE_Y - (Rect.y1 + 1); *py = _CaptureY; } /* Set new window position */ if (_HasCaptured & REPOS_X) { WM_MoveWindow(hWin, -dx, 0); } if (_HasCaptured & REPOS_Y) { WM_MoveWindow(hWin, 0, -dy); } /* Set new window size */ WM_ResizeWindow(hWin, dx, dy); }
/******************************************************************* * * _DemoResizeWindow Demonstrates the use of WM_ResizeWindow */ static void _DemoResizeWindow(void) { int i, tm,tDiff; _ChangeInfoText("WM_ResizeWindow()"); GUI_Delay(SPEED); _LiftUp(30); for (i = 0; i < 20; i++) { tm = GUI_GetTime(); WM_ResizeWindow(_hWindow1, 1, 1); WM_ResizeWindow(_hWindow2, -1, -1); tDiff = 15 - (GUI_GetTime() - tm); GUI_Delay(tDiff); } for (i = 0; i < 40; i++) { tm = GUI_GetTime(); WM_ResizeWindow(_hWindow1, -1, -1); WM_ResizeWindow(_hWindow2, 1, 1); tDiff = 15 - (GUI_GetTime() - tm); GUI_Delay(tDiff); } for (i = 0; i < 20; i++) { tm = GUI_GetTime(); WM_ResizeWindow(_hWindow1, 1, 1); WM_ResizeWindow(_hWindow2, -1, -1); tDiff = 15 - (GUI_GetTime() - tm); GUI_Delay(tDiff); } _LiftDown(30); GUI_Delay(SPEED); }
/********************************************************************* * * WM__UpdateChildPositions * * Purpose: * Move and/or resize all children of a resized window. * What exactly happens to the window depends on how the edges are * anchored. */ void WM__UpdateChildPositions(WM_Obj* pObj, int dx0, int dy0, int dx1, int dy1) { WM_HWIN hChild; WM_Obj* pChild; int dx, dy, dw, dh; for (hChild = pObj->hFirstChild; hChild; hChild = pChild->hNext) { int Status; GUI_RECT rOld, rNew; pChild = WM_H2P(hChild); /* Compute size of new rectangle */ rOld = pChild->Rect; rNew = rOld; Status = pChild->Status & (WM_SF_ANCHOR_RIGHT | WM_SF_ANCHOR_LEFT); switch (Status) { case WM_SF_ANCHOR_RIGHT: /* Right ANCHOR : Move window with right side */ rNew.x0 += dx1; rNew.x1 += dx1; break; case WM_SF_ANCHOR_RIGHT | WM_SF_ANCHOR_LEFT: /* Left & Right ANCHOR: Resize window */ rNew.x0 += dx0; rNew.x1 += dx1; break; default: /* Left ANCHOR: Move window with left side of parent */ rNew.x0 += dx0; rNew.x1 += dx0; } Status = pChild->Status & (WM_SF_ANCHOR_TOP | WM_SF_ANCHOR_BOTTOM); switch (Status) { case WM_SF_ANCHOR_BOTTOM: /* Bottom ANCHOR */ rNew.y0 += dy1; rNew.y1 += dy1; break; case WM_SF_ANCHOR_BOTTOM | WM_SF_ANCHOR_TOP: /* resize window */ rNew.y0 += dy0; rNew.y1 += dy1; break; default: /* Top ANCHOR */ rNew.y0 += dy0; rNew.y1 += dy0; } /* Set new window position using Move and Resize as required */ dx = rNew.x0 - rOld.x0; dy = rNew.y0 - rOld.y0; if (dx || dy) { WM_MoveWindow(hChild, dx, dy); } dw = (rNew.x1 - rNew.x0) - (rOld.x1 - rOld.x0); dh = (rNew.y1 - rNew.y0) - (rOld.y1 - rOld.y0); if (dw || dh) { WM_ResizeWindow(hChild, dw, dh); } } }
/********************************************************************* * * _RestoreMinimized */ static void _RestoreMinimized(FRAMEWIN_Handle hObj, FRAMEWIN_Obj* pObj) { /* When window was minimized, restore it */ if (pObj->Flags & FRAMEWIN_SF_MINIMIZED) { int OldHeight = 1 + pObj->Widget.Win.Rect.y1 - pObj->Widget.Win.Rect.y0; int NewHeight = 1 + pObj->rRestore.y1 - pObj->rRestore.y0; WM_ResizeWindow(hObj, 0, NewHeight - OldHeight); WM_ShowWindow(pObj->hClient); WM_ShowWindow(pObj->hMenu); FRAMEWIN__UpdatePositions(pObj); pObj->Flags &= ~FRAMEWIN_SF_MINIMIZED; _InvalidateButton(pObj, GUI_ID_MINIMIZE); } }
/********************************************************************* * * WM_SetXSize */ int WM_SetXSize(WM_HWIN hWin, int XSize) { WM_Obj* pWin; int dx; int r = 0; if (hWin) { WM_LOCK(); pWin = WM_H2P(hWin); dx = XSize - (pWin->Rect.x1 - pWin->Rect.x0 + 1); WM_ResizeWindow(hWin, dx, 0); r = pWin->Rect.x1 - pWin->Rect.x0 + 1; WM_UNLOCK(); } return r; }
/********************************************************************* * * WM_SetYSize */ int WM_SetYSize(WM_HWIN hWin, int YSize) { WM_Obj* pWin; int dy; int r = 0; if (hWin) { WM_LOCK(); pWin = WM_H2P(hWin); dy = YSize - (pWin->Rect.y1 - pWin->Rect.y0 + 1); WM_ResizeWindow(hWin, 0, dy); r = pWin->Rect.y1 - pWin->Rect.y0 + 1; WM_UNLOCK(); } return r; }
/********************************************************************* * * _MinimizeFramewin */ static void _MinimizeFramewin(FRAMEWIN_Handle hObj, FRAMEWIN_Obj* pObj) { _RestoreMaximized(hObj, pObj); /* When window is not minimized, minimize it */ if ((pObj->Flags & FRAMEWIN_SF_MINIMIZED) == 0) { int OldHeight = pObj->Widget.Win.Rect.y1 - pObj->Widget.Win.Rect.y0 + 1; int NewHeight = FRAMEWIN__CalcTitleHeight(pObj) + pObj->Widget.pEffect->EffectSize * 2 + 2; pObj->rRestore = pObj->Widget.Win.Rect; WM_HideWindow(pObj->hClient); WM_HideWindow(pObj->hMenu); WM_ResizeWindow(hObj, 0, NewHeight - OldHeight); FRAMEWIN__UpdatePositions(pObj); pObj->Flags |= FRAMEWIN_SF_MINIMIZED; _InvalidateButton(pObj, GUI_ID_MINIMIZE); } }
int IPC_Msg_SetWinPos(tIPC_Client *Client, tAxWin_IPCMessage *Msg) { tIPCMsg_SetWindowPos *info = (void*)Msg->Data; tWindow *win; ASSERT(Msg->ID == IPCMSG_SETWINPOS); if(Msg->Size < sizeof(*info)) return -1; win = IPC_int_GetWindow(Client, Msg->Window); if(!win) return 1; _SysDebug("info = {..., bSetPos=%i,bSetDims=%i}", info->bSetPos, info->bSetDims); if(info->bSetPos) WM_MoveWindow(win, info->X, info->Y); if(info->bSetDims) WM_ResizeWindow(win, info->W, info->H); return 0; }
/******************************************************************* * * _ShowSeveralFunctions */ static void _ShowSeveralFunctions(LISTBOX_Handle hListBox) { int NumEntries, i; /* Add scrollbar */ GUI_DispStringAtCEOL("SCROLLBAR_CreateAttached", 5, 55); GUI_Delay(SPEED); SCROLLBAR_CreateAttached(hListBox, SCROLLBAR_CF_VERTICAL); GUI_Delay(SPEED * 0.75); /* Add strings */ GUI_DispStringAtCEOL("LISTBOX_AddString", 5, 55); GUI_Delay(SPEED); LISTBOX_AddString(hListBox, "Français"); GUI_Delay(SPEED / 6); LISTBOX_AddString(hListBox, "Japanese"); GUI_Delay(SPEED / 6); LISTBOX_AddString(hListBox, "Italiano"); GUI_Delay(SPEED / 6); LISTBOX_AddString(hListBox, "Español"); GUI_Delay(SPEED / 6); LISTBOX_AddString(hListBox, "Other language ..."); GUI_Delay(SPEED * 0.6); /* Set focus */ GUI_DispStringAtCEOL("WM_SetFocus", 5, 55); GUI_Delay(SPEED * 0.9); WM_SetFocus(hListBox); GUI_Delay(SPEED * 0.7); /* Set font */ GUI_DispStringAtCEOL("LISTBOX_SetFont", 5, 55); GUI_Delay(SPEED * 0.9); LISTBOX_SetFont(hListBox, &GUI_Font13B_1); GUI_Delay(SPEED * 0.7); /* Increment selection */ GUI_DispStringAtCEOL("LISTBOX_IncSel", 5, 55); GUI_Delay(SPEED); NumEntries = LISTBOX_GetNumItems(hListBox); for (i = 0; i < NumEntries - 1; i++) { LISTBOX_IncSel(hListBox); GUI_Delay(SPEED / 6); } GUI_Delay(SPEED / 4); /* Show automatic scrollbar */ GUI_DispStringAtCEOL("Optional automatic scrollbar", 5, 55); GUI_Delay(SPEED); LISTBOX_SetAutoScrollH(hListBox, 1); LISTBOX_SetAutoScrollV(hListBox, 1); GUI_Delay(SPEED * 0.75); /* Set font */ GUI_DispStringAtCEOL("LISTBOX_SetFont", 5, 55); GUI_Delay(SPEED); LISTBOX_SetFont(hListBox, &GUI_Font16B_1); GUI_Delay(SPEED * 0.75); /* Decrement selection */ GUI_DispStringAtCEOL("LISTBOX_DecSel", 5, 55); GUI_Delay(SPEED); for (i = 0; i < NumEntries - 1; i++) { LISTBOX_DecSel(hListBox); GUI_Delay(SPEED / 6); } GUI_Delay(SPEED / 4); /* Change width of scrollbar */ GUI_DispStringAtCEOL("Change scrollbar width", 5, 55); GUI_Delay(SPEED * 0.7); { SCROLLBAR_Handle hScrollH = WM_GetDialogItem(hListBox, GUI_ID_HSCROLL); SCROLLBAR_Handle hScrollV = WM_GetDialogItem(hListBox, GUI_ID_VSCROLL); SCROLLBAR_SetWidth(hScrollV, 14); GUI_Delay(SPEED / 4); SCROLLBAR_SetWidth(hScrollH, 14); GUI_Delay(SPEED * 0.6); } /* Change size of listbox */ GUI_DispStringAtCEOL("Change size of listbox", 5, 55); GUI_Delay(SPEED * 0.75); WM_ResizeWindow(hListBox, -15, 0); GUI_Delay(SPEED / 4); WM_ResizeWindow(hListBox, 0, -15); GUI_Delay(SPEED / 4); WM_ResizeWindow(hListBox, 15, 0); GUI_Delay(SPEED / 4); WM_ResizeWindow(hListBox, 0, 15); GUI_Delay(SPEED / 2); /* Disable item */ GUI_DispStringAtCEOL("LISTBOX_SetItemDisabled", 5, 55); GUI_Delay(SPEED); LISTBOX_SetItemDisabled(hListBox, 4, 1); GUI_Delay(SPEED * 0.75); /* Set multi selection mode */ GUI_DispStringAtCEOL("LISTBOX_SetMulti", 5, 55); GUI_Delay(SPEED); LISTBOX_SetMulti(hListBox, 1); GUI_Delay(SPEED * 0.75); /* Select item */ GUI_DispStringAtCEOL("LISTBOX_SetItemSel", 5, 55); GUI_Delay(SPEED); LISTBOX_SetItemSel(hListBox, 0, 1); GUI_Delay(SPEED / 4); LISTBOX_SetItemSel(hListBox, 1, 1); GUI_Delay(SPEED / 4); LISTBOX_SetItemSel(hListBox, 2, 1); GUI_Delay(SPEED * 0.8); /* Delete listbox widget */ GUI_DispStringAtCEOL("LISTBOX_Delete", 5, 55); GUI_Delay(SPEED * 1.1); LISTBOX_Delete(hListBox); GUI_Delay(SPEED * 0.75); }
int Decorator_HandleMessage(tWindow *Window, int Message, int Length, const void *Data) { static tWindow *btn1_down; static enum { BTN1_MOVE, BTN1_RLEFT, BTN1_RRIGHT, BTN1_RBOTTOM, } btn1_mode; switch(Message) { case WNDMSG_MOUSEMOVE: { const struct sWndMsg_MouseMove *msg = Data; if( Window && btn1_down == Window ) { switch(btn1_mode) { case BTN1_MOVE: // Move WM_MoveWindow(Window, Window->X + msg->dX, Window->Y + msg->dY); break; case BTN1_RLEFT: // Resize left if( Window->W + msg->dX > 50 ) { WM_MoveWindow(Window, Window->X + msg->dX, Window->Y); WM_ResizeWindow(Window, Window->W - msg->dX, Window->H); } break; case BTN1_RRIGHT: // Resize right if( Window->W + msg->dX > 50 ) { WM_ResizeWindow(Window, Window->W + msg->dX, Window->H); } break; case BTN1_RBOTTOM: // Resize bottom if( Window->H + msg->dY > 50 ) { WM_ResizeWindow(Window, Window->W, Window->H + msg->dY); } break; } return 0; } // TODO: Change cursor when hovering over edges if(msg->Y >= 0) return 1; // Pass // TODO: Handle return 0; } case WNDMSG_MOUSEBTN: { const struct sWndMsg_MouseButton *msg = Data; // TODO: Do something with other buttons // - Window menu for example if( msg->Button != 0 ) return 1; // pass on if( !msg->bPressed ) btn1_down = 0; #define HOTSPOTR(x,y,w,h) Decorator_INT_CoordInRangeR(msg->X, msg->Y, x, y, w, h) #define HOTSPOTA(sx,sy,ex,ey) Decorator_INT_CoordInRange(msg->X, msg->Y, sx, sy, ew, eh) // Left resize border if( msg->bPressed && HOTSPOTR(-ciSideBorderWidth, -ciTitlebarHeight, ciSideBorderWidth, ciTitlebarHeight+Window->H+ciBottomBorderWidth) ) { btn1_down = Window; btn1_mode = BTN1_RLEFT; return 0; } // Right resize border if( msg->bPressed && HOTSPOTR(Window->W, -ciTitlebarHeight, ciSideBorderWidth, ciTitlebarHeight+Window->H+ciBottomBorderWidth) ) { btn1_down = Window; btn1_mode = BTN1_RRIGHT; return 0; } // Bottom resize border if( msg->bPressed && HOTSPOTR(0, Window->H, Window->W, ciTitlebarHeight) ) { btn1_down = Window; btn1_mode = BTN1_RBOTTOM; return 0; } // Titlebar buttons if( msg->bPressed && Decorator_INT_CoordInRangeR(msg->X, msg->Y, BTN_CLOSE(Window)) ) { WM_SendMessage(NULL, Window, WNDMSG_CLOSE, 0, NULL); return 0; } // Titlebar - Move if( msg->bPressed && msg->Y < 0 ) { btn1_down = Window; btn1_mode = BTN1_MOVE; return 0; } #undef HOTSPOTR #undef HOTSPOTA return 1; } default: // Anything unhandled is passed on return 1; } }
/********************************************************************* * * _cbCallback */ static void _cbCallback(WM_MESSAGE * pMsg) { WM_HWIN hWin = pMsg->hWin; #if GUIDEMO_LARGE int NCode, Id; #endif switch (pMsg->MsgId) { case WM_INIT_DIALOG: /* Initialize all widgets */ #if GUIDEMO_TINY EDIT_SetText(WM_GetDialogItem(hWin, GUI_ID_EDIT0), "EDIT"); #else EDIT_SetText(WM_GetDialogItem(hWin, GUI_ID_EDIT0), "EDIT widget 0"); EDIT_SetText(WM_GetDialogItem(hWin, GUI_ID_EDIT1), "EDIT widget 1"); #endif { #if GUIDEMO_LARGE WM_HWIN hListBox; EDIT_SetHexMode(WM_GetDialogItem(hWin, GUI_ID_EDIT2), 0x1234, 0, 0xffffff); EDIT_SetBinMode(WM_GetDialogItem(hWin, GUI_ID_EDIT3), 0x1234, 0, 0xffff); hListBox = WM_GetDialogItem(hWin, GUI_ID_LISTBOX0); LISTBOX_SetText(hListBox, _apListBox); SCROLLBAR_CreateAttached(hListBox, SCROLLBAR_CF_VERTICAL); #else GUI_RECT Rect; int x, y, ySize; ySize = LCD_GetYSize(); if (ySize < 120) { WM_ResizeWindow(hWin, 0, -24); } WM_GetWindowRectEx(hWin, &Rect); x = (LCD_GetXSize() - (Rect.x1 - Rect.x0 + 1)) >> 1; y = (ySize - (Rect.y1 - Rect.y0 + 1)) >> 1; #if GUIDEMO_TINY WM_MoveTo(hWin, x, y); #else WM_MoveTo(hWin, x, y - 4); #endif #endif } break; case WM_KEY: switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key) { case GUI_KEY_ESCAPE: GUI_EndDialog(hWin, 1); break; case GUI_KEY_ENTER: GUI_EndDialog(hWin, 0); break; } break; #if GUIDEMO_LARGE case WM_NOTIFY_PARENT: Id = WM_GetId(pMsg->hWinSrc); /* Id of widget */ NCode = pMsg->Data.v; /* Notification code */ switch (NCode) { case WM_NOTIFICATION_RELEASED: /* React only if released */ if (Id == GUI_ID_OK) { /* OK Button */ GUI_EndDialog(hWin, 0); } if (Id == GUI_ID_CANCEL) { /* Cancel Button */ GUI_EndDialog(hWin, 1); } break; case WM_NOTIFICATION_SEL_CHANGED: /* Selection changed */ FRAMEWIN_SetText(hWin, "Dialog - sel changed"); break; default: FRAMEWIN_SetText(hWin, "Dialog - notification received"); } break; #endif default: WM_DefaultProc(pMsg); } }