📄 control.c
字号:
if(i+pListCtrl->CurrentHead>=pListCtrl->ListNum) break; if(i+pListCtrl->CurrentHead==pListCtrl->CurrentSel) //文本被选中 TextOutRect(pdc, &textRect, pListCtrl->pListText[i+pListCtrl->CurrentHead], TRUE, pListCtrl->FontSize|FONT_BLACKBK,TEXTOUT_MID_Y); else TextOutRect(pdc,&textRect, pListCtrl->pListText[i+pListCtrl->CurrentHead], TRUE, pListCtrl->FontSize,TEXTOUT_MID_Y); }}void DrawListCtrl(PListCtrl pListCtrl){ structRECT rect; PDC pdc; pdc=GetCtrlParentDC((POS_Ctrl)pListCtrl); if(!pdc) return; //清空列表框的显示区域 FillRect2(pdc,&pListCtrl->ListCtrlRect,GRAPH_MODE_NORMAL,COLOR_WHITE); CopyRect(&rect, &pListCtrl->ListCtrlRect); switch(pListCtrl->style){ case CTRL_STYLE_DBFRAME: Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(0,0,0)); InflateRect(&rect, -1,-1); Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(0,0,0)); InflateRect(&rect, -1,-1); Draw3DRect2(pdc, &rect, RGB(128,128,128), RGB(0,0,0)); InflateRect(&rect, -1,-1); Draw3DRect2(pdc, &rect, RGB(255,255,255), RGB(255,255,255)); InflateRect(&rect, -1,-1); Draw3DRect2(pdc, &rect, RGB(128,128,128), RGB(192,192,192)); InflateRect(&rect, -1,-1); Draw3DRect2(pdc, &rect, RGB(0,0,0), RGB(192,192,192)); break; case CTRL_STYLE_FRAME: DrawRectFrame2(pdc,&rect); break; case CTRL_STYLE_3DUPFRAME: Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(0,0,0)); InflateRect(&rect, -1,-1); Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(128,128,128)); break; case CTRL_STYLE_3DDOWNFRAME: Draw3DRect2(pdc, &rect, RGB(0,0,0),RGB(192,192,192)); InflateRect(&rect, -1,-1); Draw3DRect2(pdc, &rect, RGB(128,128,128), RGB(192,192,192)); break; case CTRL_STYLE_NOFRAME: break; } InflateRect(&rect, -1,-1); pListCtrl->ListCtrlRollRect.left=rect.right-ROLLBUTTON_WIDTH; pListCtrl->ListCtrlRollRect.top=rect.top; pListCtrl->ListCtrlRollRect.right=rect.right; pListCtrl->ListCtrlRollRect.bottom=rect.bottom; pListCtrl->ClientRect.left=rect.left; pListCtrl->ClientRect.top=rect.top; pListCtrl->ClientRect.right=rect.right-ROLLBUTTON_WIDTH; pListCtrl->ClientRect.bottom=rect.bottom; ListCtrlDrawClient(pListCtrl, pdc); ListCtrlDrawRollBar(pListCtrl, pdc); ReleaseCtrlParentDC((POS_Ctrl)pListCtrl);}void ListCtrlOnTchScr(PListCtrl pListCtrl, int x, int y, U32 tchaction){ int sel; POSMSG pMsg; if(IsInRect(&pListCtrl->ClientRect,x,y)){ //在客户区域内单击,改变列表框的选择 PDC pdc; sel=(y-pListCtrl->ClientRect.top)/OSFontSize[pListCtrl->FontSize]; if(pListCtrl->CurrentHead+sel+1>pListCtrl->ListNum) return; pdc=GetCtrlParentDC((POS_Ctrl)pListCtrl); pListCtrl->CurrentSel=pListCtrl->CurrentHead+sel; ListCtrlDrawClient(pListCtrl,pdc); ReleaseCtrlParentDC((POS_Ctrl)pListCtrl); switch(tchaction){ case TCHSCR_ACTION_CLICK: pMsg=OSCreateMessage((POS_Ctrl)pListCtrl->parentWnd, OSM_LISTCTRL_SELCHANGE, pListCtrl->CtrlID, pListCtrl->CurrentSel); SendMessage(pMsg); break; case TCHSCR_ACTION_DBCLICK: pMsg=OSCreateMessage((POS_Ctrl)pListCtrl->parentWnd, OSM_LISTCTRL_SELDBCLICK, pListCtrl->CtrlID, pListCtrl->CurrentSel); SendMessage(pMsg); break; } return; } if(IsInRect(&pListCtrl->ListCtrlRollRect,x,y)){ //在滚动条区域内 int rolltop,rollbottom; structRECT rect; PDC pdc; rolltop=pListCtrl->ListCtrlRollRect.top; rollbottom=pListCtrl->ListCtrlRollRect.bottom; if(y<rolltop+ROLLBUTTON_WIDTH && tchaction!=TCHSCR_ACTION_MOVE){ //向上移动一格 rect.left=pListCtrl->ListCtrlRollRect.left; rect.top=pListCtrl->ListCtrlRollRect.top; rect.right=pListCtrl->ListCtrlRollRect.right; rect.bottom=pListCtrl->ListCtrlRollRect.top+ROLLBUTTON_WIDTH; switch(tchaction){ case TCHSCR_ACTION_UP: pListCtrl->CurrentHead=MAX(0,pListCtrl->CurrentHead-1); DrawListCtrl(pListCtrl); break; case TCHSCR_ACTION_DOWN: pdc=GetCtrlParentDC((POS_Ctrl)pListCtrl); Draw3DRect2(pdc,&rect, RGB(0,0,0), RGB(192,192,192)); InflateRect(&rect, -1, -1); Draw3DRect2(pdc,&rect, RGB(128,128,128),RGB(192,192,192)); ReleaseCtrlParentDC((POS_Ctrl)pListCtrl); break; } return; } if(y<rollbottom && y>rollbottom-ROLLBUTTON_WIDTH && tchaction!=TCHSCR_ACTION_MOVE){ //向下移动一格 rect.left=pListCtrl->ListCtrlRollRect.left; rect.top=pListCtrl->ListCtrlRollRect.bottom-ROLLBUTTON_WIDTH; rect.right=pListCtrl->ListCtrlRollRect.right; rect.bottom=pListCtrl->ListCtrlRollRect.bottom; switch(tchaction){/* case TCHSCR_ACTION_CLICK: pdc=GetCtrlParentDC((POS_Ctrl)pListCtrl); Draw3DRect2(pdc,&rect, RGB(0,0,0), RGB(192,192,192)); InflateRect(&rect, -1, -1); Draw3DRect2(pdc,&rect, RGB(128,128,128),RGB(192,192,192)); ReleaseCtrlParentDC((POS_Ctrl)pListCtrl);*/ case TCHSCR_ACTION_UP: pListCtrl->CurrentHead=MIN(pListCtrl->CurrentHead+1,pListCtrl->ListNum-pListCtrl->ListShowNum); pListCtrl->CurrentHead=MAX(0,pListCtrl->CurrentHead); DrawListCtrl(pListCtrl); break; case TCHSCR_ACTION_DOWN: pdc=GetCtrlParentDC((POS_Ctrl)pListCtrl); Draw3DRect2(pdc,&rect, RGB(0,0,0), RGB(192,192,192)); InflateRect(&rect, -1, -1); Draw3DRect2(pdc,&rect, RGB(128,128,128),RGB(192,192,192)); ReleaseCtrlParentDC((POS_Ctrl)pListCtrl); break; } return; } if(IsInRect(&pListCtrl->RollBlockRect, x, y)|| tchaction==TCHSCR_ACTION_MOVE ){ //拖动滑块 int head,preCurhead=pListCtrl->CurrentHead, length1=GetRectHeight(&pListCtrl->ListCtrlRollRect) -ROLLBUTTON_WIDTH*2-GetRectHeight(&pListCtrl->RollBlockRect), freenum=pListCtrl->ListNum-pListCtrl->ListShowNum; static int oldy; if(freenum>0 && tchaction==TCHSCR_ACTION_MOVE){ //拖动滑块 head=(y-oldy)*freenum/length1; preCurhead=MIN(preCurhead+head,freenum); preCurhead=MAX(0,preCurhead); if(preCurhead!=pListCtrl->CurrentHead){ oldy=y; pListCtrl->CurrentHead=preCurhead; DrawListCtrl(pListCtrl); } } else if(tchaction==TCHSCR_ACTION_DOWN){ oldy=y; } return; } if(y<pListCtrl->RollBlockRect.top && tchaction==TCHSCR_ACTION_CLICK){//向上翻页 int preCurhead=pListCtrl->CurrentHead; preCurhead=MAX(preCurhead-pListCtrl->ListShowNum,0); if(preCurhead!=pListCtrl->CurrentHead){ pListCtrl->CurrentHead=preCurhead; DrawListCtrl(pListCtrl); } return; } if(y>pListCtrl->RollBlockRect.bottom && tchaction==TCHSCR_ACTION_CLICK){//向下翻页 int preCurhead=pListCtrl->CurrentHead; preCurhead=MIN(preCurhead+pListCtrl->ListShowNum,pListCtrl->ListNum-pListCtrl->ListShowNum); preCurhead=MAX(0,preCurhead); if(preCurhead!=pListCtrl->CurrentHead){ pListCtrl->CurrentHead=preCurhead; DrawListCtrl(pListCtrl); } } }}void ListCtrlSelMove(PListCtrl pListCtrl, int moveNum, U8 Redraw) //列表框高亮度条移,正数下移,负数上移{ POSMSG pMsg; int oldsel=pListCtrl->CurrentSel; if(moveNum<0){ //向上滚动 if(pListCtrl->CurrentSel+moveNum>=pListCtrl->CurrentHead) pListCtrl->CurrentSel+=moveNum; else{ pListCtrl->CurrentSel=MAX(pListCtrl->CurrentSel+moveNum,0); pListCtrl->CurrentHead=pListCtrl->CurrentSel; } } else{ //向下滚动 if(pListCtrl->CurrentSel+moveNum<pListCtrl->CurrentHead+pListCtrl->ListShowNum && pListCtrl->CurrentSel+moveNum<(pListCtrl->ListNum-1)) pListCtrl->CurrentSel+=moveNum; else{ pListCtrl->CurrentSel=MIN(pListCtrl->CurrentSel+moveNum,pListCtrl->ListNum-1); pListCtrl->CurrentHead=MAX(pListCtrl->CurrentSel-pListCtrl->ListShowNum+1,0); } } if(oldsel==pListCtrl->CurrentSel) return; if(Redraw) DrawListCtrl(pListCtrl); //发送列表框选择改变消息 pMsg=OSCreateMessage((POS_Ctrl)pListCtrl->parentWnd,OSM_LISTCTRL_SELCHANGE, pListCtrl->CtrlID, pListCtrl->CurrentSel); SendMessage(pMsg);}void ListCtrlOnKey(PListCtrl pListCtrl, int nkey, int fnkey){ switch(nkey){ case 3: //F1=move up ListCtrlSelMove(pListCtrl,-1,TRUE); return; case 7: //F2=move down ListCtrlSelMove(pListCtrl,1,TRUE); return; }}void OSListCtrlOnMessage(PListCtrl pListCtrl, POSMSG pMsg){ switch(pMsg->Message){ case OSM_TOUCH_SCREEN: ListCtrlOnTchScr(pListCtrl, (S16)(pMsg->WParam&0xffff), (S16)(pMsg->WParam>>16), pMsg->LParam); break; case OSM_KEY: if(IsCtrlFocus((POS_Ctrl)pListCtrl)) ListCtrlOnKey(pListCtrl, pMsg->WParam,pMsg->LParam); break; }}char TextDefKeyTable[]={'1','2','3',0,'4','5','6',0,'7','8','9',0,'.','0','\b',0};PTextCtrl CreateTextCtrl(U32 CtrlID, structRECT* prect, U32 FontSize, U32 style,char* KeyTable, PWnd parentWnd){ PTextCtrl pTextCtrl; pTextCtrl=(PTextCtrl)CreateOSCtrl(CtrlID,CTRLTYPE_TEXTCTRL,prect, FontSize,style, parentWnd); pTextCtrl->bIsEdit=FALSE; pTextCtrl->text[0]=NULL; if(KeyTable) pTextCtrl->KeyTable=KeyTable; else pTextCtrl->KeyTable=TextDefKeyTable; return pTextCtrl;}void DestoryTextCtrl(PTextCtrl pTextCtrl){ PList pList=GetCtrlList(pTextCtrl->parentWnd, pTextCtrl->CtrlID); DeleteListNode(pList); OSMemPut(pCtrlMem, (void*)pTextCtrl);}void SetTextCtrlText(PTextCtrl pTextCtrl, U16 *pch, U8 IsRedraw){ UstrCpy(pTextCtrl->text, pch); if(IsRedraw /*&& pTextCtrl->CtrlID==GetWndCtrlFocus(pTextCtrl->parentWnd)*/) DrawTextCtrl(pTextCtrl);}U16* GetTextCtrlText(PTextCtrl pTextCtrl){ return pTextCtrl->text;}void DrawTextCtrl(PTextCtrl pTextCtrl){ structRECT rect; int tmp; PDC pdc; pdc=GetCtrlParentDC((POS_Ctrl)pTextCtrl); if(!pdc) return; //清空列表框的显示区域 FillRect2(pdc, &pTextCtrl->TextCtrlRect,GRAPH_MODE_NORMAL, COLOR_WHITE); CopyRect(&rect, &pTextCtrl->TextCtrlRect); if(GetWndCtrlFocus(pTextCtrl->parentWnd)==pTextCtrl->CtrlID){ //当前的控件为焦点 switch(pTextCtrl->style){ case CTRL_STYLE_DBFRAME: Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(0,0,0)); InflateRect(&rect, -1,-1); Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(0,0,0)); InflateRect(&rect, -1,-1); Draw3DRect2(pdc, &rect, RGB(128,128,128), RGB(0,0,0)); InflateRect(&rect, -1,-1); Draw3DRect2(pdc, &rect, RGB(255,255,255), RGB(255,255,255)); InflateRect(&rect, -1,-1); Draw3DRect2(pdc, &rect, RGB(128,128,128), RGB(192,192,192)); InflateRect(&rect, -1,-1); Draw3DRect2(pdc, &rect, RGB(0,0,0), RGB(192,192,192)); break; case CTRL_STYLE_FRAME: Draw3DRect2(pdc, &rect, RGB(0,0,0), RGB(0,0,0)); break; case CTRL_STYLE_3DUPFRAME: Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(0,0,0)); InflateRect(&rect, -1,-1); Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(128,128,128)); InflateRect(&rect, -1,-1); Draw3DRect2(pdc, &rect, RGB(128,128,128), RGB(192,192,192)); break; case CTRL_STYLE_3DDOWNFRAME: Draw3DRect2(pdc, &rect, RGB(0,0,0),RGB(192,192,192)); InflateRect(&rect, -1,-1); Draw3DRect2(pdc, &rect, RGB(128,128,128), RGB(192,192,192)); InflateRect(&rect, -1,-1); Draw3DRect2(pdc, &rect, RGB(128,128,128), RGB(192,192,192)); break; case CTRL_STYLE_NOFRAME: break; } } else{ switch(pTextCtrl->style){ case CTRL_STYLE_DBFRAME: Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(0,0,0)); InflateRect(&rect, -1,-1); Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(0,0,0)); InflateRect(&rect, -1,-1); Draw3DRect2(pdc, &rect, RGB(128,128,128), RGB(0,0,0)); break; case CTRL_STYLE_FRAME: Draw3DRect2(pdc, &rect, RGB(128,128,128), RGB(128,128,128)); break; case CTRL_STYLE_3DUPFRAME: Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(0,0,0)); InflateRect(&rect, -1,-1); Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(128,128,128)); break; case CTRL_STYLE_3DDOWNFRAME: Draw3DRect2(pdc, &rect, RGB(0,0,0),RGB(192,192,192)); InflateRect(&rect, -1,-1); Draw3DRect2(pdc, &rect, RGB(128,128,128), RGB(192,192,192)); break; case CTRL_STYLE_NOFRAME: break; } } InflateRect(&rect, -1,-1); if(pTextCtrl->bIsEdit) //文本框处于编辑状态 TextOutRect(pdc, &rect, pTextCtrl->text, TRUE, pTextCtrl->FontSize|FONT_BLACKBK,TEXTOUT_MID_Y); else TextOutRect(pdc, &rect, pTextCtrl->text, TRUE, pTextCtrl->FontSize,TEXTOUT_MID_Y); ReleaseCtrlParentDC((POS_Ctrl)pTextCtrl);}void AppendChar2TextCtrl(PTextCtrl pTextCtrl, U16 ch, U8 IsReDraw){ int i; for(i=0;pTextCtrl->text[i];i++){ if(i>39) return; } pTextCtrl->text[i++]=ch; pTextCtrl->text[i]=0; if(IsReDraw) DrawTextCtrl(pTextCtrl);}void TextCtrlDeleteChar(PTextCtrl pTextCtrl,U8 IsReDraw){ int i; for(i=0;pTextCtrl->text[i];i++){ if(i>39) return; } if(i==0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -