WinSkinForm.pas
上传用户:xjwsee
上传日期:2008-08-02
资源大小:796k
文件大小:228k
- end;
- if FMDIObjectInst<>nil then begin
- unsubclassMDI;
- end;
- //captionbuf.assign(nil);
- GetWindowRect(hwnd,r2);
- p:=point(r2.left,r2.top);
- if formstyle=sfsmdichild then
- screentoclient(skinmanager.clienthwnd,p);
- w:=(r2.right-r2.left)-(bw.left+bw.right-oldsize.right);
- h:=(r2.bottom-r2.top)-(bw.top+{menuheight+}bw.bottom-oldsize.bottom);
- if (Skinstate<>skin_Destory) and ((formstyle=sfsmdichild) or ((dwstyle and ws_child)=0)) then
- SetWindowPos(hwnd, 0, p.x, p.y,w,h,
- SWP_DRAWFRAME or SWP_NOZORDER or SWP_NOACTIVATE);
- SetWindowRgn(hwnd,0,true);
- if crop then begin //uncropwindow;
- deleteobject(winrgn);
- crop:=false;
- end;
- end;
- procedure TWinSkinForm.UnSubclass3;
- var w,h:integer;
- p:Tpoint;
- r2:Trect;
- style:dword;
- begin
- if not sMainMenu then begin
- Unsubclass2;
- exit;
- end;
- // if fform<>nil then InitPopmenu(fform,false,false);
- if sysmenu<>nil then begin
- sysmenu.free;
- sysmenu:=nil;
- end;
- timer.enabled:=false;
- if fobjectinst=nil then exit;
- if (fform<>nil) and assigned(oldwndproc) then begin
- fform.WindowProc := OldWndProc;
- oldwndproc:=nil;
- end;
- if fobjectinst<>nil then begin
- if isunicode then
- SetWindowLongW(hwnd, GWL_WNDPROC,LongInt(FPrevWndProc))
- else
- SetWindowLong(hwnd, GWL_WNDPROC,LongInt(FPrevWndProc));
- FreeObjectInstance(FObjectInst);
- fobjectinst:=nil;
- end;
- //if mode=0 then
- DeleteControls;
- if menu<>nil then begin
- menu.free;
- menu:=nil;
- end;
- //captionbuf.assign(nil);
- end;
- procedure TWinSkinForm.UnSubclass2;
- var i:integer;
- begin
- timer.enabled:=false;
- DeleteControls;
- if fform<>nil then begin
- InitPopMenu(fform,false,false);
- if (xcMenuitem in fsd.SkinControls) then
- InitMainMenu(fForm,false,false);
- if Skinstate<>skin_Destory then fform.color:=formcolor;
- end;
- if fobjectinst<>nil then begin
- if isunicode then
- SetWindowLongW(hwnd, GWL_WNDPROC,LongInt(FPrevWndProc))
- else
- SetWindowLong(hwnd, GWL_WNDPROC,LongInt(FPrevWndProc));
- FreeObjectInstance(FObjectInst);
- fobjectinst:=nil;
- end;
- if FMDIObjectInst<>nil then begin
- unsubclassMDI;
- end;
- if fform=nil then exit;
- if Skinstate<>skin_Destory then
- for i := 0 to fForm.ComponentCount - 1 do begin
- if fForm.Components[i] is Tcontrol then
- Tcontrol(fForm.Components[i]).invalidate;
- end;
- end;
- procedure TWinSkinForm.AfterSkin;
- var i:integer;
- sc:Tskincontrol;
- begin
- SendMessage(Hwnd, CM_BERUN, 0, BE_ID);
- if assigned(fsd.OnAfterSkinForm) then
- fsd.OnAfterSkinForm(fform,hwnd,formclass);
- exit;
- if fform=nil then exit;
- {$IFNDEF COMPILER_6_UP}
- { for i:= 0 to controllist.count-1 do begin
- sc:=Tskincontrol(controllist.items[i]);
- if assigned(sc.control) and (sc.control is Tscrollbox) then begin
- TSkinScrollbar(sc).vb.visible:=true;
- TSkinScrollbar(sc).hb.visible:=true;
- //control.invalidate;
- end;
- end; }
- {$ENDIF}
- end;
- procedure TWinSkinForm.StopUpdate;
- var dw:dword;
- begin
- if not skinmanager.wmsetdraw then exit;
- if not ischildform and sMainMenu and (formborder<>sbsnone)then begin
- dw := GetWindowLong(hwnd, GWL_STYLE);
- dw := dw and not WS_VISIBLE;
- SetWindowLong(hwnd, GWL_STYLE, dw);
- // sendmessage(hwnd,WM_SETREDRAW,0,0);
- end;
- end;
- procedure TWinSkinForm.BeginUpdate;
- var dw:dword;
- begin
- // exit;
- // has problem in virtual treeview demo, so give up
- if not skinmanager.wmsetdraw then exit;
- // only work for first form
- skinmanager.wmsetdraw:=false;
- dw := GetWindowLong(hwnd, GWL_STYLE);
- if (dw and WS_VISIBLE)=0 then begin
- dw := dw or WS_VISIBLE;
- SetWindowLong(hwnd, GWL_STYLE, dw);
- end;
- { if not ischildform and sMainMenu then begin
- sendmessage(hwnd,WM_SETREDRAW,1,0);
- Application.ProcessMessages;
- if IsWindowVisible(hwnd) then
- RedrawWindow(hwnd,0,0,RDW_INVALIDATE+RDW_INTERNALPAINT+RDW_ERASE);
- end;}
- end;
- procedure TWinSkinForm.WinWndProc(var aMsg: TMessage);
- var b1,b2,b3,b4,b5: boolean;
- s:string;
- begin
- {$IFDEF test}
- s:= MsgtoStr(aMsg);
- dolog(s);
- {$ENDIF}
- if (skinstate=skin_Creating) then begin
- if (amsg.Msg=WM_NCPAINT) then begin
- amsg.Result := 0 ;
- exit;
- end;
- end;
- b3:=false;b4:=false;
- case amsg.Msg of
- { WM_STYLECHANGED : begin
- if amsg.wParam=GWL_STYLE then
- dwstyle:= PSTYLESTRUCT(amsg.lParam)^.styleNew;
- default(amsg);
- end; }
- // WM_GETICON: default(amsg);
- CN_IsSkined : begin
- amsg.result := 1;
- // fsd.DoDebug('CN_IsSkined');
- PostMessage(Hwnd, CM_BERUN, 0, BE_ID);
- end;
- 174: amsg.Result:=0;
- WM_NCDESTROY: begin
- // skinaddlog('WM_NCDESTROY '+caption);
- // fsd.DoDebug('***WM_NCDESTROY '+caption);
- Skinstate:=skin_Destory;
- //if ischildform then
- unsubclass3;
- default(amsg);
- Skinstate:=skin_Deleted;
- end;
- WM_ERASEBKGND:WMERASEBKGND(aMsg);
- WM_CTLCOLORSTATIC:WMCtlcolor(amsg);
- WM_CTLCOLORBTN: begin
- default(amsg);
- if fform=nil then
- SetBkMode(amsg.wparam,TRANSPARENT);
- end;
- WM_INITMENUPOPUP: begin
- if amsg.WParam=hsysmenu then
- skinmanager.menutype:=m_systemmenu
- else
- skinmanager.menutype:=m_menuitem;
- default(amsg);
- end;
- WM_NCACTIVATE : begin
- if (skinstate=skin_Creating) and (formstyle<>sfsMDIChild) then
- amsg.Result := 0
- else if not sMainMenu then
- default(amsg)
- else b3:=true;
- end;
- CN_ReCreateWnd: begin
- WMReCreateWnd(amsg);
- end;
- CN_NewForm:begin
- factive:=true;
- // GetClientRect(hwnd,fClientRect);
- hsysmenu:=GetSystemMenu(hWnd, FALSE);
- geticon(iconbmp);
- // createsysmenu2;
- GetBorderSize;
- BeginUpdate();
- if fform<>nil then
- InitControls(fform)
- else InitHwndControls(hwnd);
- if (skinstate=skin_Creating) then begin
- if (formstyle=sfsmdichild) then begin
- if (windowstate=swsmax) then begin
- // if not skinmanager.MDIMax then
- // skinmanager.setmdimax(true);
- postmessage(skinmanager.clienthwnd,CN_NewMDIChild,hwnd,0);
- //postMessage(skinmanager.MDIForm.Handle, CN_FormUPdate, 0,0);
- end else if (windowstate=swsnormal) then begin
- skinstate:=skin_Updating;
- resizeform(0);
- skinstate:=Skin_Active;
- //LockWindowUpdate(0);
- cropwindow;
- end else Enablesysbtn(true);
- end else begin
- if not (ischildform or (formborder=sbsnone))
- and (windowstate<>swsmin) then begin
- skinstate:=skin_Updating;
- resizeform(0);
- skinstate:=Skin_Active;
- //LockWindowUpdate(0);
- if (windowstate=swsnormal) then cropwindow
- else refresh;
- end;
- end;
- end;
- AfterSkin;
- skinstate:=Skin_Active;
- dolog('*****Skin Active finish');
- //if (fform<>nil) then fform.Perform(CM_ACTIVATE,0,0);
- timer.enabled:=true;
- end;
- else begin
- if not sMainMenu then
- default(amsg)
- else b3:=true;
- end;
- end;
- // if not (xcMainMenu in fsd.SkinControls) then exit;
- //go, two message has handle
- if not b3 then exit;
- //embeded form
- if (not(formstyle=sfsmdichild)) and ((dwstyle and ws_child)>0) and b3 then begin
- default(amsg);
- exit;
- end;
- b3:=false;b4:=false;
- case amsg.Msg of
- WM_SysCommand: WMSysCommand(amsg);
- WM_Command: WMCommand(amsg);
- WM_WINDOWPOSCHANGED:WMWINDOWPOSCHANGED(amsg);
- WM_NCACTIVATE: begin ;
- fwindowactive:=BOOLean(amsg.wParam);
- b3:=true;
- end;
- WM_ACTIVATE: begin ;
- fwindowactive:=BOOLean(amsg.wParam);
- b3:=true;
- end;
- // CN_UPdateMainMenu:updatemainmenu;
- WM_CTLCOLORSTATIC:WMCtlcolor(amsg);
- WM_CTLCOLORBTN: begin
- default(amsg);
- if fform=nil then
- SetBkMode(amsg.wparam,TRANSPARENT);
- end;
- WM_GETMINMAXINFO:WMGETMINMAXINFO(amsg);
- CM_MENUCHANGED: begin
- b5:= fsd.menumsg;
- fsd.menumsg := false;
- default(amsg);
- fsd.menumsg := b5;
- if (getmenu(hwnd)<>0) then begin
- if (menu<>nil) and fsd.menuupdate then begin
- menu.hmenu := getmenu(hwnd);
- //SetMenu(hwnd, 0);
- if fsd.MenuMerge then menu.updatabtn
- else menu.updatabtn;
- end;
- setmenu(hwnd,0)
- end ;
- { if (menu<>nil) and fsd.menuupdate
- and (getmenu(hwnd)<>0) then begin
- menu.hmenu := getmenu(hwnd);
- //SetMenu(hwnd, 0);
- if fsd.MenuMerge then menu.updatabtn
- else menu.updatabtn;
- end ;
- if (getmenu(hwnd)<>0) then setmenu(hwnd,0); //remove menu}
- end;
- CN_MenuSelect: MenuSelect(amsg);
- WM_SIZE: WMSize(amsg);
- WM_SetICON : begin
- default(amsg);
- geticon(iconbmp);
- end;
- // WM_NCPAINT: WMNCPaint(amsg) ;
- else b3:=true;
- end;
- b1:=(formstyle=sfsmdichild) and (windowstate=swsmax);//<>swsnormal);
- b2:=false;
- // b2:=(windowstate=swsmin);
- if b1 or b2 or (skinstate=Skin_Creating) then begin
- if b3 then default(amsg);
- exit;
- end;
- case amsg.Msg of
- WM_NCPAINT: WMNCPaint(amsg) ;
- WM_NCACTIVATE:WMNcactive(amsg) ;
- WM_NCCALCSIZE: WMNCCalcSize(amsg);
- WM_SIZE: WMSize(amsg);
- WM_NCMouseMove:WMNCMouseMove(amsg);
- WM_NCLButtonDown:WMNCLButtonDown(amsg);
- WM_NCLBUTTONDBLCLK :WMNCLBUTTONDBLCLK(amsg);
- WM_NCLButtonUp : WMNCLButtonUp(amsg);
- WM_NCRBUTTONDOWN : WMNCRButtonUp(amsg);
- // WM_SysCommand: WMSysCommand(amsg);
- // WM_Command: WMCommand(amsg);
- WM_NCHitTest:WMNCHitTest(amsg);
- WM_MEASUREITEM:WMMEASUREITEM(amsg);
- WM_DRAWITEM:WMDRAWITEM(amsg);
- WM_WINDOWPOSCHANGING: WMWindowPosChanging(amsg);
- // WM_Paint:WMPaint(amsg);
- // WM_CTLCOLORSTATIC:WMCtlcolor(amsg);
- CN_FormUPdate:updatenc;
- else b4:=true;
- end;
- if b3 and b4 then default(amsg);
- // doLog('error');
- end;
- procedure TWinSkinForm.WMMDIACTIVATE(var aMsg: TMessage);
- begin
- exit;
- if not skinmanager.mdimax then exit;
- //MDIChild DeActive
- if (formstyle=sfsmdichild) and (hwnd=amsg.wparam) then
- enablesysbtn(false);
- if (formstyle=sfsmdichild) and (hwnd=amsg.Lparam) then
- enablesysbtn(true);
- end;
- {procedure TWinSkinForm.WinWndProc(var aMsg: TMessage);
- var
- Old: boolean;
- begin
- Done := false;
- with aMsg do begin
- case Msg of
- // WM_ACTIVATE:WMactive(amsg) ;
- WM_NCPAINT: WMactive(amsg) ;
- WM_NCACTIVATE:WMNcactive(amsg) ;
- WM_NCCALCSIZE: WMNCCalcSize(amsg);
- WM_SIZE: WMSize(amsg);
- WM_NCMouseMove:WMNCMouseMove(amsg);
- WM_NCLButtonDown:WMNCLButtonDown(amsg);
- WM_NCLBUTTONDBLCLK :WMNCLBUTTONDBLCLK(amsg);
- WM_NCLButtonUp : WMNCLButtonUp(amsg);
- WM_NCRBUTTONDOWN : WMNCRButtonUp(amsg);
- WM_SysCommand: WMSysCommand(amsg);
- WM_Command: WMCommand(amsg);
- WM_NCHitTest:WMNCHitTest(amsg);
- // WM_INITMENU:WMINITMENU(amsg.wparam);
- // WM_INITMENUPopup:WMINITMENU(amsg.wparam);
- // WM_MEASUREITEM:WMMEASUREITEM(amsg);
- WM_DRAWITEM:WMDRAWITEM(amsg);
- // WM_Paint:WMPaint(amsg);
- // WM_WINDOWPOSCHANGED:WMWINDOWPOSCHANGED(amsg);
- WM_ERASEBKGND:WMERASEBKGND(aMsg);
- WM_CTLCOLORSTATIC:WMCtlcolor(amsg);
- WM_SETTEXT : begin
- dolog('WM_SETTEXT');
- end;
- CN_SkinChanged:begin
- resizeform(1);
- cropwindow;
- done:=true;
- end;
- WM_DESTROY: begin
- if FMDIObjectInst<>nil then unsubclassMDI;
- if fobjectinst<>nil then begin
- SetWindowLong(hwnd, GWL_WNDPROC,LongInt(FPrevWndProc));
- FreeObjectInstance(FObjectInst);
- fobjectinst:=nil;
- if crop then deleteobject(winrgn);
- end;
- end;
- end;
- end;
- if not Done then default(amsg);
- // doLog('error');
- end;}
- procedure TWinSkinForm.WMMDITile(var aMsg: TMessage);
- procedure setcaption(b:boolean);
- var i:integer;
- fm:Tform;
- dw:dword;
- begin
- for i:= 0 to fform.MDIChildCount-1 do begin
- fm:=fform.MDIChildren[i];
- dw := GetWindowLong(fm.Handle, GWL_STYLE );
- if b then dw:=dw or WS_CAPTION
- else dw := dwstyle and ( not WS_CAPTION);
- SetWindowLong(fm.Handle, GWL_STYLE,dw );
- end;
- end;
- begin
- setcaption(true);
- defaultMDI(amsg);
- setcaption(false);
- end;
- procedure TWinSkinForm.WinMDIProc(var aMsg: TMessage);
- var s:string;
- mdidone,bmax:boolean;
- style,isskin:longint;
- b,b1:boolean;
- ahwnd:THandle;
- begin
- s:='';
- mdidone:=true;
- b:= sMainmenu;
- case amsg.Msg of
- CN_NewMDIChild : begin
- RedrawWindow(hwnd,0,0,
- RDW_UPDATENOW or RDW_ALLCHILDREN or RDW_ERASE or RDW_FRAME or RDW_INVALIDATE);
- end;
- WM_NCDESTROY: begin
- defaultMDI(amsg);
- unsubclassMDI;
- end;
- WM_NCCALCSIZE:begin
- if b then begin
- Style := GetWindowLong(clienthwnd, GWL_STYLE);
- Style := style and (not WS_HSCROLL);
- Style := style and (not WS_VSCROLL);
- if not (xoMDIScrollbar in fsd.Options) then
- SetWindowLong(clienthwnd, GWL_STYLE, Style);
- end;
- defaultMDI(amsg);
- end;
- WM_MDIACTIVATE: begin
- defaultMDI(amsg);
- end;
- WM_MDICREATE: begin
- //mdi do not handle CM_MenuChange
- fsd.menuUpdate:=false;
- defaultMDI(amsg);
- //newchildhwnd:=amsg.result;
- end;
- WM_MDIDESTROY: begin
- //s:='WM_MDIDESTROY '+format('%4x',[amsg.wparam]);
- //skinmanager.deleteform(amsg.wparam);
- defaultMDI(amsg);
- if b then begin
- skinmanager.setmdimax(MDIChildMax);
- ahwnd:=sendmessage(clienthwnd,WM_MDIGETACTIVE,0,longint(@b1));
- if (menu<>nil) and (ahwnd=0) then begin
- fsd.menuUpdate:=menuauto;
- menu.UpdataBtn;
- end;
- end;
- end;
- WM_MDICASCADE,WM_MDITILE: begin
- if b and (skinmanager.mdimax) then
- skinmanager.setmdimax(false);
- defaultMDI(amsg);
- end;
- WM_MDIREFRESHMENU : begin
- defaultMDI(amsg);
- { if (newchildhwnd<>0) then begin
- skinmanager.addform(newchildhwnd);
- postMessage(hwnd, CN_FormUPdate, 0,0);
- newchildhwnd:=0;
- end else begin
- ahwnd:=sendmessage(clienthwnd,WM_MDIGETACTIVE,0,longint(@b));
- if ahwnd<>0 then begin
- isskin :=sendmessage(ahwnd,CN_IsSkined,0,0);
- if isskin=0 then begin
- skinmanager.addform(ahwnd);
- postMessage(hwnd, CN_FormUPdate, 0,0);
- end;
- end;
- end; }
- end;
- //older code , menu merger work.
- { WM_MDISETMENU : begin
- defaultMDI(amsg);
- if (menu<>nil) and (amsg.WParam<>0) then
- menu.updatabtn2(amsg.WParam)
- else if (menu<>nil) then menu.updatabtn;
- end;}
- WM_MDISETMENU : begin
- defaultMDI(amsg);
- //DrawMenuBar(hwnd);
- if b then begin
- if (amsg.WParam<>0) and (menu<>nil) then begin
- //skinaddlog('WM_MDISETMENU*************');
- //when child menu merge main menu, it do not call
- //when active update,menu do not paint, menubutton.bounds=0,
- //so call setmenurect;
- menu.updatabtn2(amsg.WParam);//getmenu(hwnd));
- //bcb6 has bug
- //menu.SetMenuRect;
- end ;
- SetMenu(hwnd, 0);
- end;
- end;
- else defaultMDI(amsg);
- end;
- // if mdidone then defaultMDI(amsg);
- // if s<>'' then skinaddlog('**MDI: '+s);
- end;
- procedure TWinSkinForm.WMNCLBUTTONDBLCLK(Var Msg: TMessage);
- var P: TPoint;
- btn:TNCobject;
- b:boolean;
- i:integer;
- begin
- // if not fwindowactive then exit;
- P := GetWinXY(msg.LParamLo,msg.LParamhi);
- btn := findbtn(p);
- b:=false;
- if (btn<>nil) then begin
- i:= TWinsysbutton(btn).data.Action;
- if (i=3) or (i=11) then begin
- timer.enabled:=false;
- postmessage(hwnd,WM_SYSCOMMAND,SC_CLOSE,0);
- end;
- end else begin
- if (windowstate <> swsnormal) then
- restore
- else if (sbiMax in formIcons) then
- maximize
- else default(msg);
- end;
- done:=true;
- end;
- procedure TWinSkinForm.WMCtlcolor(Var Msg: TMessage);
- begin
- default(msg);
- if fform=nil then begin
- SetBkMode(msg.wparam,TRANSPARENT);
- msg.Result:=fsd.BGBrush;
- end;
- // msg.Result:=fsd.BGBrush;
- end;
- procedure TWinSkinForm.Default(Var Msg: TMessage);
- begin
- msg.result:=CallWindowProc(FPrevWndProc,hwnd,Msg.msg,msg.WParam,msg.LParam);
- end;
- procedure TWinSkinForm.WMNCActive(Var Msg: TMessage);
- var b,b1:boolean;
- begin
- {$ifdef ver130}
- if Msg.WParamLo<>WA_INACTIVE then begin
- // ShowWindow(Application.Handle, SW_SHOWNORMAL);
- end;
- {$endif ver130}
- fwindowactive:=BOOLean(msg.wParam);
- timer.enabled:= fwindowactive;
- if (not timer.enabled) and (activeskincontrol<>nil) then begin
- activeskincontrol.mouseleave;
- activeskincontrol:=nil;
- end;
- b:= (formstyle=sfsmdichild) and (windowstate=swsmax);//<>swsnormal);
- if formstyle=sfsMDIform then begin
- sendmessage(Clienthwnd,WM_NCACTIVATE,msg.wparam,0);
- //default(msg);
- end else if (formstyle=sfsMDIChild) then begin
- default(msg);
- end ;
- if not b then updatenc;
- msg.result:=1;
- end;
- procedure TWinSkinForm.WMSize(Var Msg: TMessage);
- begin
- default(msg);
- case msg.wparam of
- SIZE_RESTORED :windowstate:=swsnormal;
- SIZE_MINIMIZED : windowstate:=swsmin;
- SIZE_MAXIMIZED : windowstate:=swsmax;
- end;
- if windowstate=swsmin then exit;
- if (formstyle=sfsmdichild) and
- ((skinmanager.mdimax) or (windowstate<>swsnormal)) then exit;
- if (skinstate=skin_active) or (skinstate=skin_change) then
- cropwindow;
- end;
- procedure TWinSkinForm.WMGetMinMaxInfo(Var Msg: TMessage);
- var phwnd:Thandle;
- r:Trect;
- w:integer;
- begin
- // enablesysbtn(true);
- default(msg);
- GetWindowstate;
- if windowstate=swsmin then
- enablesysbtn(true)
- else if (formstyle=sfsmdichild) then begin
- //restore from max
- if (windowstate=swsnormal) then begin
- // if (skinmanager.mdimax) then skinmanager.setmdimax(false);
- EnableSysbtn(false);
- end else if(windowstate=swsmax) then begin
- //cause MDIChild max-close problem
- //if not skinmanager.mdimax then skinmanager.setmdimax(true);
- enablesysbtn(true);
- end;
- end else EnableSysbtn(false);
- //single no limit
- // if formborder=sbsSizeable then
- { with PMINMAXINFO(msg.lParam)^ do begin
- ptMaxTrackSize.x:=GetSystemMetrics(SM_CXMAXIMIZED);
- ptMaxTrackSize.y:=GetSystemMetrics(SM_CYMAXIMIZED);
- end;}
- // msg.result:=0;
- { if formborder = sbsSingle then
- with PMINMAXINFO(msg.lParam)^ do begin
- ptMaxTrackSize.y:=ptMaxTrackSize.y-8;
- end;}
- // skinaddlog(format('MINMAXINFO (%1d,%1d)',[PMINMAXINFO(msg.lParam)^.ptMaxTrackSize.x,
- // PMINMAXINFO(msg.lParam)^.ptMaxTrackSize.y ]));
- end;
- function TWinSkinForm.FindBtn(Point: TPoint): TNcobject;
- var i: integer;
- begin
- Result := nil;
- for i := 0 to high(sysbtn) do begin
- if sysbtn[i].visible and (sysbtn[i].data.action>=0) and
- PtInRect(sysbtn[i].bounds, Point) then begin
- Result := sysbtn[i];
- break;
- end;
- end;
- end;
- procedure TWinSkinForm.WMMouseMove(Var Msg: TMessage);
- begin
- if not fwindowactive then exit;
- // if activebtn<>-1 then begin
- // drawsysbtn(ActiveBtn,1);
- // ActiveBtn:=-1;
- // end;
- end;
- procedure TWinSkinForm.WMNCHitTest(Var Msg: TMessage);
- var p:Tpoint;
- begin
- default(msg);
- if (Msg.Result=0) or (Msg.Result=HTCAPTION) then begin
- P := getwinxy(msg.LParamLo,msg.LParamhi);
- if p.y>3 then Msg.Result:=HTCAPTION;
- if (p.y>bw.top) and (menuheight>0) then
- Msg.Result:=HTMENU;
- // fsd.DoDebug('hittest caption');
- end;
- end;
- function TWinSkinForm.GetWinXY(x,y:Smallint):Tpoint;
- var
- WindowPos, ClientPos,p: TPoint;
- begin
- p:=point(x,y);
- screentoclient(hwnd,p);
- if (windowstate<>swsmin) or (formstyle<>sfsmdichild) then begin
- inc(p.x,bw.left);
- inc(p.y,bw.top+menuheight);
- end;
- result:=p;
- end;
- procedure TWinSkinForm.HintReset();
- begin
- fsd.hintcount:=0;
- fsd.HideHint();
- end;
- function TWinSkinForm.GetSysBtnHint(i:integer):string;
- begin
- result:='';
- case i of
- 1,22: result:='Maximize';
- 2,23: result:='Minimize';
- 7,60 : result:='Minimize';
- 8,61 : result:='Restore';
- 9,0,62 : result:='Close';
- else result:='';
- end;
- end;
- procedure TWinSkinForm.OnTimer(Sender: TObject);
- var p,p1,p2:Tpoint;
- t:integer;
- s:string;
- begin
- if finmenu then exit;
- if activebtn<>nil then begin
- GetCursorPos(p);
- P1 := GetWinXY(p.x,p.y);
- if not PtInRect(activebtn.bounds, p1) then begin
- if not IsBadReadPtr(activebtn, InstanceSize) then begin
- activebtn.mouseleave;
- end;
- activebtn:=nil;
- hintreset();
- end else if not (ActiveBtn is TMenuBtn) then begin
- fsd.hintcount:=fsd.hintcount+timer.Interval;
- t:= Application.HintPause*2;
- if (fsd.hintcount<t) then begin
- end else if (fsd.hintcount < (t + Application.HintHidePause))then begin
- GetWindowRect(hwnd, wtr);
- p2 := Point(activebtn.bounds.Left+wtr.left,p.Y+24);
- s:=GetSysBtnHint(TWinsysbutton(activebtn).data.action);
- if (Length(s)>0) then
- fsd.ActivateHint(Rect(p2.x,p2.y,0,0),s);
- end else begin
- fsd.HideHint();
- end;
- end;
- end;
- if (fform=nil) and (activeskincontrol<>nil) then begin
- GetCursorPos(p);
- if not ptinrect(activeskincontrol.boundsrect,p) then begin
- activeskincontrol.mouseleave;
- activeskincontrol:=nil;
- end;
- end;
- end;
- procedure TWinSkinForm.WMNCMouseMove(Var Msg: TMessage);
- var P: TPoint;
- btn: TNCObject;
- b:boolean;
- begin
- if not fwindowactive then exit;
- P := GetWinXY(msg.LParamLo,msg.LParamhi);
- btn := findbtn(p);
- if (btn=nil) and (menu<>nil) then btn := menu.findbtn(p);
- b:=false;
- if btn<>nil then begin
- btn.mouseenter;
- b:=true;
- end else begin
- if activebtn<>nil then begin
- //drawsysbtn(ActiveBtn,1);
- activebtn.mouseleave;
- activebtn:=nil;
- end;
- end;
- if b then begin
- Msg.Result := 0;
- Msg.Msg := WM_NULL;
- end else default(msg);
- end;
- procedure TWinSkinForm.WMNCLButtonDown(var Msg:TMessage);
- var P: TPoint;
- btn:TNCobject;
- b:boolean;
- begin
- // if not fwindowactive then exit;
- P := GetWinXY(msg.LParamLo,msg.LParamhi);
- fsd.HideHint();
- btn := findbtn(p);
- if (btn=nil) and (menu<>nil) then btn := menu.findbtn(p);
- b:=false;
- if (btn<>nil) then begin
- if not fwindowactive then
- SetForegroundWindow(hwnd);
- btn.mousedown;
- if btn is TMenuBtn then begin
- if lastselect then //mousemove select menu
- CheckMenu(TMenuBtn(Btn))
- else begin // click directly
- // (TMenuBtn(Btn).hsubmenu=0) then
- //stmessage(hwnd,wm_command,TMenuBtn(Btn).mid,0);
- CheckMenu(TMenuBtn(Btn));
- end;
- activebtn:=btn;
- end;
- b:=true;
- end;
- if b then begin
- Msg.Result := 0;
- Msg.Msg := WM_NULL;
- end else begin
- if (windowstate=swsmax) and (msg.wparam=HTCAPTION) and fwindowactive then
- msg.wparam:=HTMENU;
- default(msg);
- end;
- end;
- procedure TWinSkinForm.WMNCLButtonUp(var Msg:TMessage);
- var P: TPoint;
- btn:TNcobject;
- b:boolean;
- begin
- P := GetWinXY(msg.LParamLo,msg.LParamhi);
- fsd.HideHint();
- // if msg.wparam=HTMENU then btn := menu.findbtn(p)
- // else btn := findbtn(p);
- btn := findbtn(p);
- if (btn=nil) and (menu<>nil) then btn := menu.findbtn(p);
- b:=false;
- if (Btn<>nil) then begin
- if btn is TWinSysbutton then begin
- if btn=activebtn then begin
- btn.mouseup;
- SysBtnAction(msg.LParamLo,msg.LParamhi);
- end ;
- end else if btn is Tmenubtn then begin
- // postmessage(hwnd,wm_command,tmenubtn(btn).mid,0);
- end;
- b:=true;
- end ;
- if b then begin
- Msg.Result := 0;
- Msg.Msg := WM_NULL;
- end else default(msg);
- end;
- procedure TWinSkinForm.WMNCRButtonUp(var Msg:TMessage);
- var b:boolean;
- begin
- b:=false;
- fsd.HideHint();
- if (msg.wparam=HTCAPTION) and (formstyle<>sfsMdichild) then begin
- // if (msg.wparam=HTCAPTION) then begin
- // sysmenu.popup(msg.LParamLo,msg.LParamhi);
- popsysmenu(point(msg.LParamLo,msg.LParamhi));
- b:=true;
- end ;
- if b then begin
- Msg.Result := 0;
- Msg.Msg := WM_NULL;
- end else default(msg);
- end;
- procedure TWinSkinForm.PopSysmenu(p:Tpoint);
- var AFlags: Integer;
- i:integer;
- begin
- { if sysmenu=nil then exit;
- for i:= 0 to sysmenu.items.count-1 do begin
- case sysmenu.Items.items[i].Tag of
- Sc_Restore:sysmenu.Items.items[i].enabled:= (windowstate<>swsnormal) ;
- SC_MAXIMIZE:sysmenu.Items.items[i].enabled:= (windowstate<>swsmax) and (sbimax in formicons);
- SC_MINIMIZE:sysmenu.Items.items[i].enabled:= (windowstate<>swsmin) and (sbimin in formicons);
- end;
- end;}
- //dll form right click problem.
- if skinmanager.mode <>0 then exit;
- if (gettickcount - poptime) >DoubleTime then begin
- skinmanager.menutype:=m_systemmenu;
- Aflags:= TPM_LEFTALIGN or TPM_RIGHTBUTTON;
- poptime := gettickcount ;
- createsysmenu2;
- if sysmenu<>nil then sysmenu.popup(p.x,p.y)
- { if (xcSystemMenu in fsd.SkinControls) and (formstyle<>sfsmdichild) then begin
- createsysmenu2;
- if sysmenu<>nil then sysmenu.popup(p.x,p.y)
- end else if hsysmenu<>0 then
- TrackPopupMenu(hsysmenu, aflags, p.x, p.y,0,hwnd,nil );}
- end else if (activebtn<>nil) then begin
- timer.enabled:=false;
- postmessage(hwnd,wm_close,0,0);
- end;
- end;
- {procedure TWinSkinForm.WMPaint(var Msg: TMessage);
- var OldMode: integer;
- dc:HDC;
- PS: TPaintStruct;
- begin
- dc:=msg.wparam;
- if dc=0 then
- msg.wparam:=BeginPaint(hwnd, PS);
- OldMode := SetBkMode(msg.wparam, TRANSPARENT);
- SetBkColor(msg.wparam,fsd.colors[csButtonFace]);
- default(msg);
- SetBkMode(msg.wparam, OldMode);
- if dc=0 then EndPaint(hwnd, PS);
- done:=true;
- end;}
- procedure TWinSkinForm.WMERASEBKGND(var Msg: TMessage);
- var r:Trect;
- begin
- default(msg);
- if (fform=nil) then begin
- GetClientRect(hwnd,r);
- FillRect( msg.wparam,r,fsd.BGbrush);
- Msg.Result := 1;
- end ;
- end;
- procedure TWinSkinForm.WMMEASUREITEM(var Msg: Tmessage);
- var ItemID:integer;
- b:boolean;
- mis:PMEASUREITEMSTRUCT;
- item:Tmenuitem;
- Canvas :TControlCanvas;
- dc:HDC;
- s:string;
- Buffer: array[0..79] of Char;
- begin
- // default(msg);
- mis:= PMEASUREITEMSTRUCT(msg.lparam);
- if (mis^.CtlType=ODT_MENU) and (hmenu<>0) then begin
- // default(msg);
- // skinaddlog('MENU WMMEASUREITEM');
- if fform=nil then begin
- WMMEASUREITEMH(msg);
- exit;
- end;
- skinmanager.setpopmenu;
- if menu.menu<>nil then
- Item := Menu.Menu.FindItem(mis^.itemID, fkCommand)
- else item:=nil;
- if Item <> nil then begin
- DC := GetWindowDC(hwnd);
- Canvas := TControlCanvas.Create;
- Canvas.Handle := DC;
- Canvas.Font := Screen.MenuFont;
- MeasureItem(item,Canvas,Integer(mis^.itemWidth), Integer(mis^.itemHeight));
- Canvas.Handle := 0;
- Canvas.Free;
- ReleaseDC(hwnd, DC);
- done:=true;
- end else begin
- //only draw MDI windows menu.
- if (mis^.itemID<Max_MenuitemID) and (mis^.itemID>0) then begin
- default(msg);
- exit;
- end;
- GetMenuString(activemenu,mis^.itemID,buffer,sizeof(buffer),MF_BYCOMMAND);
- s:=buffer;
- DC := GetWindowDC(hwnd);
- Canvas := TControlCanvas.Create;
- Canvas.Handle := DC;
- Canvas.Font := Screen.MenuFont;
- mis^.itemWidth:= canvas.TextWidth(s)+26;
- if fsd.MenuItem<>nil then mis^.itemWidth:=mis^.itemWidth+fsd.MenuItem.r.Left;
- Canvas.Handle := 0;
- Canvas.Free;
- ReleaseDC(hwnd, DC);
- if s='' then
- mis^.itemHeight:=8
- else inc(mis^.itemHeight,4);
- if (winversion >= $80000000) then
- inc(mis^.itemHeight,4);
- end;//if
- end else default(msg);
- end;
- procedure TWinSkinForm.WMMEASUREITEMH(var Msg: Tmessage);
- var ItemID:integer;
- b:boolean;
- mis:PMEASUREITEMSTRUCT;
- item:Tmenuitem;
- Canvas :TControlCanvas;
- dc:HDC;
- s:string;
- Buffer: array[0..79] of Char;
- begin
- // default(msg);
- mis:= PMEASUREITEMSTRUCT(msg.lparam);
- GetMenuString(activemenu,mis^.itemID,buffer,sizeof(buffer),MF_BYCOMMAND);
- s:=buffer;
- DC := GetWindowDC(hwnd);
- Canvas := TControlCanvas.Create;
- Canvas.Handle := DC;
- Canvas.Font := Screen.MenuFont;
- mis^.itemWidth:= canvas.TextWidth(s)+26;
- if fsd.MenuItem<>nil then mis^.itemWidth:=mis^.itemWidth+fsd.MenuItem.r.Left;
- Canvas.Handle := 0;
- Canvas.Free;
- ReleaseDC(hwnd, DC);
- if s='' then
- mis^.itemHeight:=8
- else inc(mis^.itemHeight,4);
- if (winversion >= $80000000) then
- inc(mis^.itemHeight,4);
- end;
- procedure TWinSkinForm.WMDRAWITEM(var Msg: Tmessage);
- var ItemID:integer;
- b:boolean;
- mis:PDrawItemStruct;
- // ahwnd:Thandle;
- // ptr:integer;
- begin
- mis:= PDrawItemStruct(msg.lparam);
- if (mis^.CtlType=ODT_MENU) and (hmenu<>0) then begin
- if (formstyle=sfsmdiform) and (Win32Platform = VER_PLATFORM_WIN32_NT)
- and (Win32MajorVersion = 4) then begin
- default(msg);
- exit;
- end;
- { if newskinmenu<>nil then begin
- newskinmenu.hmenu:=mis^.hwndItem;
- newskinmenu:=nil
- end;}
- skinmanager.sethmenu(mis^.hwndItem);
- skinmanager.setPopmenu;
- //skinmanager.UpdateSkinMenu(mis^.hwndItem);
- // DrawHmenuItem(mis^.hDC,mis^.rcItem,mis^.itemid,mis^.hwndItem,(mis^.itemState and ODS_SELECTED)>0);
- if fform<>nil then
- WMDrawMenuitem(Msg)
- else
- WMDrawMenuitemH(Msg);
- // done:=true;
- end else default(msg);
- end;
- procedure TWinSkinForm.WMDrawMenuitem(var Msg: Tmessage);
- var item,pitem:Tmenuitem;
- Canvas :TControlCanvas;
- begin
- with PDrawItemStruct(Msg.LParam)^ do begin
- Item := Menu.Menu.FindItem(itemID, fkCommand);
- if (Item = nil) then begin
- //only draw MDI windows menuite
- if (itemid<Max_MenuitemID) and (itemid>0) then begin
- default(msg);
- exit;
- end;
- Item := CreateMenuItem(hwndItem,itemid);
- Canvas := TControlCanvas.Create;
- Canvas.Handle := hDC;
- Canvas.Font := Screen.MenuFont;
- DrawHMenuItem2(hwndItem,item,canvas,rcitem,(itemState and ODS_SELECTED)>0);
- Canvas.Handle := 0;
- Canvas.Free;
- item.free;
- end else begin;
- Canvas := TControlCanvas.Create;
- Canvas.Handle := hDC;
- Canvas.Font := Screen.MenuFont;
- if fsd.menuitem= nil then begin
- DefaultMenuItem(item,canvas,rcitem,(itemState and ODS_SELECTED)>0);
- end else
- DrawMenuItem(item,canvas,rcitem,(itemState and ODS_SELECTED)>0);
- Canvas.Handle := 0;
- Canvas.Free;
- end;
- end;//with
- end;
- procedure TWinSkinForm.WMDrawMenuitemH(var Msg: Tmessage);
- var item,pitem:Tmenuitem;
- Canvas :TControlCanvas;
- begin
- with PDrawItemStruct(Msg.LParam)^ do begin
- Item := CreateMenuItem(hwndItem,itemid);
- Canvas := TControlCanvas.Create;
- Canvas.Handle := hDC;
- Canvas.Font := Screen.MenuFont;
- DrawHMenuItem2(hwndItem,item,canvas,rcitem,(itemState and ODS_SELECTED)>0);
- Canvas.Handle := 0;
- Canvas.Free;
- item.free;
- end;
- end;
- function TWinSkinForm.CreateMenuItem(amenu:Hmenu;aid:integer):Tmenuitem;
- var item:Tmenuitem;
- mi:TMenuItemInfo;
- Buffer: array[0..79] of Char;
- begin
- mi.cbSize:= sizeof(TMENUITEMINFO);
- mi.fMask:=MIIM_TYPE or MIIM_STATE ;
- mi.dwTypeData := Buffer;
- Mi.cch := SizeOf(Buffer);
- GetMenuItemInfo(amenu, aid, false, mi);
- Item := Tmenuitem.create(nil);
- GetMenuString(amenu,aid,buffer,sizeof(buffer),MF_BYCOMMAND);
- item.caption:=buffer;
- if item.caption='' then item.caption:='-';
- item.enabled:= (mi.fState and MFS_DISABLED)=0;
- item.checked:= (mi.fState and MFS_CHECKED)>0;
- result:=item;
- end;
- procedure TWinSkinForm.WMCommand(var Msg: Tmessage);
- var ItemID:integer;
- b:boolean;
- begin
- itemid:=TWMCommand(msg).ItemID;
- case itemid of
- SC_CLOSE,SC_MAXIMIZE,SC_MINIMIZE,SC_RESTORE:b:=true;
- SC_MOVE,SC_SIZE: b:=true;
- SC_NEXTWINDOW,SC_PREVWINDOW:b:=true;
- else b:=false;
- end;
- // skinaddlog(format('__________WMCommand %1d %1d',[msg.wparam,msg.lparam]));
- if itemid>= $ff00 then begin
- // setmenu(hwnd,0);
- default(msg);
- end else if b then begin
- postmessage(hwnd,wm_syscommand,itemid,0);
- exit;
- end else default(msg);
- end;
- procedure TWinSkinForm.WMINITMENU(hm:Hmenu);
- var i,n,v:integer;
- mi:TMenuItemInfo;
- Buffer: array[0..79] of Char;
- begin
- n:= GetMenuItemCount(hm);
- for i:= 0 to n-1 do begin
- mi.cbSize:= sizeof(TMENUITEMINFO);
- mi.fMask := MIIM_TYPE or MIIM_STATE or MIIM_SUBMENU;
- // mi.fType := MFT_STRING ;
- FillChar(buffer, SizeOf(buffer), 0);
- mi.dwTypeData := Buffer;
- Mi.cch := SizeOf(Buffer);
- GetMenuItemInfo(hm, i, TRUE, mi);
- mi.fMask := MIIM_TYPE ;
- mi.fType := mi.fType or MFT_OWNERDRAW;
- SetMenuItemInfo(hm, i, TRUE, mi);
- if mi.hSubMenu<>0 then WMINITMENU(mi.hSubMenu);
- end;
- end;
- procedure TWinSkinForm.WMReCreateWnd(var Msg: Tmessage);
- var i:integer;
- hctrl:Thandle;
- sc:Tskincontrol;
- ss:Tskinscrollbar;
- sv:TSkinListView;
- comp:TWincontrol;
- begin
- hctrl:=msg.WParam;
- if controllist=nil then exit;
- for i:= controllist.count-1 downto 0 do begin
- sc:=TSkinControl(Controllist.items[i]);
- if sc.hwnd=hctrl then begin
- comp:=sc.control;
- if sc is TSkinListView then begin
- Controllist.Delete(i);
- sc.Free;
- sv:=TSkinListView.create(comp);
- sv.initScrollbar(comp,self.fsd,self.fcanvas2,self);
- end else begin
- Controllist.Delete(i);
- sc.Free;
- ss:=TSkinScrollBar.create(comp);
- ss.initScrollbar(comp,self.fsd,self.fcanvas2,self);
- end;
- //fsd.DoDebug('Received RecreateWnd');
- break;
- end;
- end;
- end;
- procedure TWinSkinForm.WMSysCommand(var Msg: Tmessage);
- var Button:TMenuBtn;
- p:Tpoint;
- begin
- if not FInMenu then begin
- with TWMSysCommand(msg) do begin
- if (CmdType and $FFF0 = SC_KEYMENU) and (Key <> VK_SPACE) and
- (Key <> Word('-')) and (GetCapture = 0) then begin
- if (Key = 0) and (menu<>nil) then
- Button := Menu.Buttons[0]
- else
- Button := FindButtonFromAccel(Key);
- if (Key = 0) or (Button <> nil) then
- begin
- CheckMenu(button);
- // TrackMenu(Button);
- Result := 1;
- exit;
- end;
- end else if (CmdType and $FFF0 = SC_KEYMENU) and (Key = VK_SPACE) then begin
- p:=point(0,0);
- clienttoscreen(hwnd,p);
- PopSysmenu(p);
- end;
- end; //end with
- end;
- case msg.wparam of
- SC_MAXIMIZE: begin
- windowstate:=swsmax;
- {if formstyle=sfsmdichild then begin
- enablesysbtn(true);
- if not (skinmanager.mdimax) then
- skinmanager.setmdimax(true);
- end; }
- end;
- SC_MINIMIZE: begin
- windowstate:=swsmin;
- if formstyle=sfsmdichild then enablesysbtn(true);
- end;
- SC_RESTORE:begin
- windowstate:=swsnormal;
- if formstyle=sfsmdichild then begin
- enablesysbtn(false);
- if (skinmanager.mdimax) then
- skinmanager.setmdimax(false);
- end;
- end;
- end;
- default(msg);
- end;
- procedure TWinSkinForm.Maximize;
- begin
- if windowstate<>swsmax then begin
- if formstyle=sfsmdichild then
- SkinManager.SetMDIMax(true);
- // SetAnimation(false);
- windowstate:=swsmax;
- postmessage(hwnd,wm_syscommand,SC_MAXIMIZE,0);
- activebtn:=nil;
- end else restore;
- end;
- procedure TWinSkinForm.Restore;
- begin
- windowstate:=swsnormal;
- postmessage(hwnd,wm_syscommand,SC_Restore,0);
- end;
- procedure TWinSkinForm.RestoreMDI;
- begin
- if fform.ActiveMDIChild<>nil then
- fform.ActiveMDIChild.windowstate:=wsnormal;
- end;
- procedure TWinSkinForm.Minimize;
- begin
- if windowstate=swsmin then
- restore
- else begin
- // SetAnimation(false);
- windowstate:=swsmin;
- UpdateStyle(false);
- // ShowWindow(hwnd, SW_MINIMIZE);
- postmessage(hwnd,wm_syscommand,SC_MINIMIZE,0);
- // postmessage(hwnd,WM_SHOWWINDOW,0,SW_PARENTCLOSING);
- end;
- end;
- procedure TWinSkinForm.SysBtnAction(x,y:smallint);
- var i:integer;
- begin
- i:=TWinsysbutton(activebtn).data.action;
- case i of
- 1,22: if TWinsysbutton(activebtn).enabled then Maximize;
- 2,23: if TWinsysbutton(activebtn).enabled then Minimize;
- 0 : begin
- if checksysmenu then begin
- timer.enabled:=false;
- postmessage(hwnd,WM_SYSCOMMAND,SC_CLOSE,0);
- //postmessage(hwnd,wm_close,0,0);
- end;
- end;
- 3,11,12: popsysmenu(point(x+1,y+1));
- 4 : postmessage(hwnd,WM_SYSCOMMAND,SC_CONTEXTHELP,0);
- 7,60 : MDIchildaction(61472);//SC_MINIMIZE);
- 8,61 : MDIchildaction(SC_RESTORE);
- 9,62 : MDIchildaction(SC_Close);
- else postmessage(hwnd,cn_captionBtnClick,i,0);
- end;
- end;
- procedure TWinSkinForm.MDIChildAction(const action:Integer);
- var b:boolean;
- ahwnd:Thandle;
- acomm:integer;
- begin
- // SetAnimation(false);
- if (formstyle<>sfsMDIform) or (ClientHwnd=0) then exit;
- acomm:=action;
- //close last child,no action
- // if (action<>SC_Close) then
- // skinmanager.setmdimax(false);
- ahwnd:=sendmessage(clienthwnd,WM_MDIGETACTIVE,0,longint(@b));
- if (ahwnd=0) then exit;
- sendmessage(ahwnd,wm_syscommand,acomm,0);
- { if skinmanager.mdimax then begin
- if not MDIChildMax then skinmanager.setmdimax(false)
- end;}
- end;
- procedure TWinSkinForm.DoSysMenu(Sender: TObject);
- begin
- case TMenuitem(Sender).tag of
- 3: begin
- timer.enabled:=false;
- postmessage(hwnd,wm_close,0,0);
- end;
- 1: Maximize;
- 2: Minimize;
- 0: Restore;
- else begin
- end;
- end;
- end;
- procedure TWinSkinForm.DoSysMenu2(Sender: TObject);
- begin
- postmessage(hwnd,wm_syscommand,TMenuitem(Sender).tag,0);
- end;
- procedure TWinSkinForm.DrawSysbtn(btn:TWinSysButton;I:integer);
- var w:integer;
- r:Trect;
- FWorkDC: HDC;
- begin
- FWorkDC := GetWindowDC(hwnd);
- w:= btn.data.map.width div btn.data.frame;
- if not btn.enabled then begin
- i:=4;
- if i>btn.data.frame then i:=1;
- end;
- r:= rect((i-1)*w,0,i*w,btn.data.map.height);
- if btn.data.Visibility=100 then begin
- if i=3 then i:=4
- end;
- if btn.data.action in [3,11] then
- DrawIcon(fworkdc, btn.bounds)
- else
- DrawRect1(FWorkDC,btn.bounds,btn.data.map,i,btn.data.frame,1);
- ReleaseDC(hwnd, FWorkDC);
- end;
- procedure TWinSkinForm.WMWINDOWPOSCHANGED(Var Msg: TMessage);
- begin
- GetWindowstate;
- default(msg);
- end;
- procedure TWinSkinForm.WMWindowPosChanging(Var Msg: TMessage);
- begin
- default(msg);
- end;
- procedure TWinSkinForm.WMactive(Var Msg: TMessage);
- begin
- fwindowactive:=BOOLean(msg.wParam);
- default(msg);
- end;
- procedure TWinSkinForm.WMMDIACTIVATE2(Var Msg: TMessage);
- var dwstyle: Dword;
- begin
- dwstyle := GetWindowLong( hwnd, GWL_STYLE );
- SetWindowLong( hwnd, GWL_STYLE, dwstyle and (not WS_CAPTION));
- default(msg);
- SetWindowLong( hwnd, GWL_STYLE, dwstyle );
- end;
- procedure TWinSkinForm.WMNCPaint(Var Msg: TMessage);
- var dc:HDC;
- begin
- UpdateStyle(true);
- if (fsd.menumsg) then begin
- if ((formstyle=sfsmdichild) and (windowstate=swsmax))
- or (formborder = sbsnone) then begin
- default(msg);
- exit;
- end;
- {dc := GetDCEx(hwnd, msg.wParam, DCX_WINDOW or DCX_INTERSECTRGN);
- updatenc(dc);
- ReleaseDC(hwnd, dc); }
- updatenc(0);
- end;
- msg.result:=0;
- end;
- procedure TWinSkinForm.UpdateNc(adc:HDC=0);
- var WR, R1: TRect;
- FWorkDC: HDC;
- b:boolean;
- begin
- if bg=nil then exit;
- if (skinstate<>skin_active) and (skinstate<>skin_change) then exit;
- if (formborder = sbsnone) then exit;
- if (formstyle=sfsmdichild) and (windowstate=swsmax) then exit;
- // dolog(format('************Do UPdate NC %1d',[Ord(skinstate)]));
- if adc=0 then
- FWorkDC := GetWindowDC(hwnd)
- else
- FWorkDC := adc;
- try
- // UpdateStyle(true);
- if GetWindowRect(hwnd, WR) then begin;
- wtr:=wr;
- OffsetRect(wr,-wr.left,-wr.top);
- fwidth :=wr.right;
- fheight:=wr.bottom;
- if (windowstate<>swsmin) then begin
- drawborder(1,rect(0,0,bw.left,wr.bottom),fworkdc);
- drawborder(2,rect(wr.right-bw.right,0,wr.right,wr.bottom),fworkdc);
- drawborder(4,rect(bw.left,wr.bottom-bw.bottom,wr.right-bw.right,wr.bottom),fworkdc);
- DrawFLine(fworkdc);
- b:=true;
- if (menu<>nil) and b then
- menu.drawmenu(fworkdc,rect(bw.left,bw.top,
- wr.right-bw.right,bw.top+menuheight))
- else if (menuheight>0) then begin
- r1:=rect(bw.Left,bw.Top,wr.Right-bw.Right,bw.Top+menuheight);
- fillrect(fworkdc,r1,fsd.BGbrush);
- end;
- end else begin
- DrawFLine(fworkdc);
- // DrawMin(fworkdc);
- end;
- end;
- except
- end;
- activebtn:=nil;
- if adc=0 then
- ReleaseDC(hwnd, FWorkDC);
- end;
- procedure TWinSkinForm.UpdateStyle(b:boolean);
- var exstyle:Dword;
- b2:boolean;
- begin
- if sbicaption in formicons then exit;
- dwstyle := GetWindowLong( hwnd, GWL_STYLE );
- if false {(windowstate=swsmin)} then begin
- if (hsysmenu>0) then
- dwstyle := dwstyle or WS_SYSMENU;
- end else begin;
- if b then
- dwstyle := dwstyle and ( not WS_SYSMENU)
- else if (hsysmenu>0) then
- dwstyle := dwstyle or WS_SYSMENU;
- end;
- SetWindowLong( hwnd, GWL_STYLE, dwstyle );
- end;
- procedure TWinSkinForm.UpdateMainMenu;
- var WR, R1: TRect;
- FWorkDC: HDC;
- b:boolean;
- begin
- if (menu=nil) then exit;
- FWorkDC := GetWindowDC(hwnd);
- GetWindowRect(hwnd, WR);
- wtr:=wr;
- OffsetRect(wr,-wr.left,-wr.top);
- fwidth :=wr.right;
- fheight:=wr.bottom;
- menu.updataBtn;
- menu.drawmenu(fworkdc,rect(bw.left,bw.top,
- wr.right-bw.right,bw.top+menuheight));
- ReleaseDC(hwnd, FWorkDC);
- end;
- procedure TWinSkinForm.DrawFLine(dc:HDC);
- var rc,r1,r2:Trect;
- h,x,y:integer;
- begin
- rc:=rect(0,0,fwidth,bw.top);
- if windowstate=swsmin then begin
- CaptionBuf.height:=fheight;
- CaptionBuf.width:= fwidth;
- captionbuf.Canvas.Brush.color:=fsd.colors[csbuttonface];
- captionbuf.canvas.fillrect(rect(0,0,fwidth,fheight));
- //top border
- r1:=rect(0,0,fwidth,bw.Top);
- end else begin
- CaptionBuf.height:=rc.bottom;
- CaptionBuf.width:= rc.right;
- BitBlt(CaptionBuf.canvas.handle,rc.left,rc.top,rc.right,rc.bottom,
- dc,0 ,0 ,Srccopy);
- r1:=rect(bw.left,0,rc.right-bw.right,rc.bottom);
- end;
- //top border
- drawborder(3,r1,CaptionBuf.canvas.handle);
- //caption
- DrawLine(CaptionBuf.canvas,r1);
- {$IFDEF demo}
- x:=fsd.title.r.left++15;//+fsd.title.backleft;
- y:= ((r1.Bottom-r1.Top)-(fsd.logo.height)) div 2 +
- fsd.title.r.top div 2;
- CaptionBuf.canvas.draw(x,y,fsd.logo);
- {$Endif}
- //sysbtn
- SetSysbtnRect;
- drawallsysbtn(CaptionBuf.canvas,rc);
- BitBlt(dc,rc.left ,rc.top,CaptionBuf.Width,CaptionBuf.Height,
- CaptionBuf.canvas.handle,0 ,0 ,Srccopy);
- // H := GetSystemMetrics(SM_CYCAPTION)+GetSystemMetrics(SM_CXSIZEFRAME);
- SetBkMode(dc,OPAQUE);
- end;
- procedure TWinSkinForm.DrawMin(dc:HDC);
- var rc,r1,r2:Trect;
- h,y:integer;
- begin
- rc:=rect(0,0,fwidth,fheight);
- CaptionBuf.height:=rc.bottom;
- CaptionBuf.width:= rc.right;
- DrawRect2(CaptionBuf.canvas.handle,rc,fsd.MinCaption.Map,
- fsd.MinCaption.r,1,1);
- //caption
- r1:=rect(bw.left,0,rc.right-bw.right,rc.bottom);
- DrawLine(CaptionBuf.canvas,r1);
- //sysbtn
- SetSysbtnRect;
- drawallsysbtn(CaptionBuf.canvas,rc);
- BitBlt(dc,rc.left ,rc.top,rc.right,rc.bottom,
- CaptionBuf.canvas.handle,0 ,0 ,Srccopy);
- SetBkMode(dc,OPAQUE);
- end;
- procedure TWinSkinForm.DrawLine(acanvas:Tcanvas;rc:TRect);
- var ws:widestring;
- r1,r2:Trect;
- OldMode,x,y,i: integer;
- OldFont: HFont;
- DrawStyle: Longint;
- BtnCounter,mleft:Integer ;
- begin
- {$IFNDEF demo}
- if bidileft then
- DrawStyle := DT_NOPREFIX or DT_END_ELLIPSIS or DT_SINGLELINE or DT_Right or DT_RTLREADING
- else
- DrawStyle := DT_NOPREFIX or DT_END_ELLIPSIS or DT_SINGLELINE or DT_LEFT;
- ws:=' ';
- astr:=' ';
- if isunicode then
- ws:= bstr+getformcaption(hwnd)+astr
- else
- ws := StrToWideStr(bstr+getformcaptionA(hwnd)+astr);
- // By Shraga Milon because there was a problem in
- // if bidileft then begin
- rightbtn:=0;
- for BtnCounter:= 0 to high(sysbtn) do
- if (sysBtn[BtnCounter].data.Align = 1) and (not sysbtn[BtnCounter].data.map.empty) then begin
- if SysBtnVisible(BtnCounter) then begin
- if SysBtn[BtnCounter].data.XCoord >rightbtn then
- rightbtn:=SysBtn[BtnCounter].data.XCoord;
- end;
- end;
- // end;
- acanvas.font:=captionfont;
- OldMode := SetBkMode(aCanvas.Handle, TRANSPARENT);
- with acanvas do
- try
- if (fwindowactive) then begin
- font.color:=fsd.colors[csTitleTextActive];
- end else begin
- font.color:=fsd.colors[csTitleTextNoActive];
- end;
- r1:=rc;
- // DrawText(acanvas.Handle,PChar(bstr+Text+astr),length(bstr+Text+astr)
- // ,r1, DT_CALCRECT or DT_NOCLIP);
- TNT_DrawTextw(acanvas.Handle,ws,r1, DT_CALCRECT or DT_NOCLIP or DT_NOPREFIX);
- inc(r1.right,fsd.title.backleft+fsd.title.backright);
- x:=0;
- case fsd.title.Aligment of
- 0:x:=fsd.title.r.left;
- 1:x:=((rc.right-rc.left)-(r1.right-r1.left)) div 2;
- 2:x:=(rc.right-rc.left-fsd.title.r.right-(r1.right-r1.left)) ;
- end;
- // right button, caption button
- if bidileft then begin
- mleft := fsd.title.r.right;
- //some skin may have problem
- //if mleft<rightbtn+2 then
- mleft:=rightbtn;
- case fsd.title.Aligment of
- 2:x:=fsd.title.r.left;
- 1:x:=((rc.right-rc.left)-(r1.right-r1.left)-mLeft) div 2;
- 0:x:=(rc.right-rc.left-mLeft-(r1.right-r1.left));
- end;
- end;
- y:= ((rc.Bottom-rc.Top)-(r1.Bottom-r1.Top)) div 2 +
- fsd.title.r.top div 2;
- offsetrect(r1,x,y);
- if bidileft and (x<=0) then
- r1.left:=fsd.title.r.left;
- if (dwstyle and ws_popup) = 0 then begin
- // Fix by Shraga Milon to bring closer the caption to the button
- if bidileft then
- OffsetRect(r1,10,0) // i add this to bring closer the caption to the button
- else if r1.right>rc.right-fsd.title.r.right then
- r1.right:=rc.right-fsd.title.r.right;
- end else begin
- if bidileft then
- OffsetRect(r1,10,0) // i add this to bring closer the caption to the button
- else if (r1.right>rc.right-rightbtn-5) and (rightbtn>5) then
- r1.right:=rc.right-rightbtn-5;
- end;
- if (formborder = sbsDialog) and (fsd.title.Aligment=0) then dec(r1.left,16);
- ctr:=r1;
- if not fsd.title.map.empty then begin
- if (not fwindowactive) then i:=2 else i:=1;
- DrawRectTile(acanvas,rect(r1.left,rc.top,r1.right,rc.bottom),fsd.title.map,
- rect(fsd.title.backleft,0,fsd.title.backright,0),i,2,1);
- end;
- inc(r1.left,fsd.title.backleft);
- dec(r1.right,fsd.title.backright);
- Tnt_DrawTextW(acanvas.Handle,ws,r1, DrawStyle);
- finally
- SetBkMode(aCanvas.Handle, OldMode);
- end;
- {$else}
- x:=fsd.title.r.left++15;//+fsd.title.backleft;
- y:= ((rc.Bottom-rc.Top)-(fsd.logo.height)) div 2 +
- fsd.title.r.top div 2;
- acanvas.draw(x,y,fsd.logo);
- {$ENDIF}
- end;
- procedure TWinSkinForm.SetSysbtnRect;
- var i,j,w,y,minleft:integer;
- r1 :Trect;
- begin
- minleft:=0;
- for i:= 0 to high(sysbtn) do
- if SysBtnVisible(i) and
- (not sysbtn[i].data.map.empty) then begin
- w:= sysbtn[i].data.map.width div sysbtn[i].data.frame;
- r1:=rect(0,0,w,sysbtn[i].data.map.height);
- with sysbtn[i].data do
- case Align of
- 0: offsetrect(r1,XCoord,ycoord);
- 1: begin
- offsetrect(r1,fwidth-XCoord,ycoord);
- if minleft<r1.Left then minleft:=r1.left;
- end;
- // 2: offsetrect(r1,xcoord,fheight-Ycoord);
- // 3: offsetrect(r1,fwidth-xcoord,fheight-Ycoord);
- 2,8: offsetrect(r1,ctr.left-w-sysbtn[i].data.xcoord,ycoord);
- 3,9: offsetrect(r1,ctr.right+xcoord,ycoord);
- 100 : begin
- y:=bw.top+(menuheight-r1.bottom) div 2;
- if fsd.menubar<>nil then
- offsetrect(r1,fwidth-xcoord-bw.right-fsd.menubar.r.left,y)
- else
- offsetrect(r1,fwidth-xcoord-bw.right,y);
- { if bidileft then begin
- if fsd.menubar<>nil then
- offsetrect(r1,xcoord+bw.left+fsd.menubar.r.left,y)
- else
- offsetrect(r1,xcoord+bw.left,y);
- end else begin
- if fsd.menubar<>nil then
- offsetrect(r1,fwidth-xcoord-bw.right-fsd.menubar.r.left,y)
- else
- offsetrect(r1,fwidth-xcoord-bw.right,y);
- end;}
- end;
- end;
- sysbtn[i].bounds:=r1;
- end ;
- if minleft>0 then rightbtn:=minleft;
- end;
- procedure TWinSkinForm.DrawAllSysbtn(acanvas:Tcanvas;rc:TRect);
- var i,j:integer;
- begin
- for i:= 0 to High(sysbtn) do
- if SysBtnVisible(i) and (not sysbtn[i].data.map.empty)
- and (sysbtn[i].data.Visibility<>100) then begin
- // and (sysbtn[i].data.CombineOp=-1) then begin
- if (fwindowactive) then j:=1 else j:=4;
- if (not sysbtn[i].enabled) then j:=4;
- if sysbtn[i].data.frame<4 then j:=1;
- if sysbtn[i].data.action in [3,11] then begin
- DrawIcon(aCanvas.Handle, sysbtn[i].bounds);
- end else
- DrawRect1(acanvas.handle,sysbtn[i].bounds,sysbtn[i].data.map,j,sysbtn[i].data.frame,1);
- end;
- end;
- function TWinSkinForm.MDIChildMax:boolean;
- var b:boolean;
- ahwnd:Thandle;
- begin
- result:=false;
- if (formstyle<>sfsMDIform) or (ClientHwnd=0) then exit;
- ahwnd:=sendmessage(clienthwnd,WM_MDIGETACTIVE,0,longint(@b));
- if (ahwnd<>0) and b then result:=true;
- end;
- function TWinSkinForm.SysBtnVisible(i:integer):boolean;
- var b:boolean;
- begin
- case sysbtn[i].data.Visibility of
- -1 : b:=false;
- 0: begin
- result:=true; //always show
- //if (formborder = sbsDialog) then result:=false;
- // if (sysbtn[i].data.action=0) and (not(sbisystem in formicons)) then
- // result:=false;
- end;
- 1: result:= WindowState=swsMax;
- 2: result:= WindowState<>swsMax;
- 3: result:= fwindowactive;
- 4: result:= not fwindowactive;
- 6:begin
- result:= ((sbiMin in formIcons) or (sbiMax in formIcons)) and (sbisystem in formicons);
- // sysbtn[i].enabled:= (sbiMax in formIcons) and (sbisystem in formicons);
- end;
- 7:result:= not (sbiMax in formIcons);
- 8:result:= ((sbiMin in formIcons) or (sbiMax in formIcons)) and (sbisystem in formicons);
- 9:result:= not (sbiMin in formIcons);
- 100 : result:= MDIChildMax and (menu<>nil);
- 10:result:= (sbiHelp in formIcons)
- and (not ((sbiMin in formIcons) or (sbiMax in formIcons))) ;
- // 11:result:= not(biHelp in BorderIcons);
- { 100 :
- if (fform.FormStyle=fsMDIForm) and
- (fform.ActiveMDIChild<>nil) and
- (fform.ActiveMDIChild.windowstate=wsmaximized) then
- result:=true}
- 200 : result:= (not ismessagebox) and (formborder=sbsDialog);
- 201..999: result:= true;
- 1000..2000 : begin
- result:=sendmessage(hwnd,CN_CaptionBtnVisible,
- sysbtn[i].data.Visibility,sysbtn[i].data.action)>0;
- end;
- else result:=false;
- end;
- b:=false;
- case sysbtn[i].data.Visibility1 of
- -1 : b:=false;
- 0: b:=true; //always show
- 1: b:= WindowState=swsMax;
- 2: b:= WindowState<>swsMax;
- 3: b:= fwindowactive;
- 4: b:= not fwindowactive;
- 6:b:= ((sbiMin in formIcons) or (sbiMax in formIcons)) ; //show with minbutton
- 7:b:= not (sbiMax in formIcons);
- 8:b:= ((sbiMin in formIcons) or (sbiMax in formIcons)) ;
- 9:b:= not (sbiMin in formIcons);
- 10:b:= sbiHelp in formIcons;
- // 11:b:= not(sbiHelp in formIcons);
- 100 : b:=result;
- 200 : result:= (not ismessagebox) and (formborder=sbsDialog);
- 201..2000: result:= true;
- end;
- result:= result and b;
- case sysbtn[i].data.action of
- 0: if not (sbisystem in formIcons) then
- result:=false;
- 1: sysbtn[i].enabled:= (sbiMax in formIcons) and (sbisystem in formicons);
- 2: sysbtn[i].enabled:= (sbiMin in formIcons) and (sbisystem in formicons);
- { 1: if not (sbiMax in formIcons) then
- result:= false;
- 2: if not (sbiMin in formIcons) then
- result:=false; }
- 3,11,12: if (formborder = sbsDialog) then
- result:=false;
- end;
- sysbtn[i].Visible:= result;
- end;
- procedure TWinSkinForm.Drawborder(n:integer;Rc:Trect;dc:HDC);
- var r:Trect;
- temp:Tbitmap;
- i,tile,sp:integer;
- begin
- r:=rc;
- offsetrect(r,-rc.left,-rc.top);
- if (r.right<0) or (r.bottom<0) then exit;
- if (not fwindowactive) then
- i:=2 else i:=1;
- if (fsd.border[n].frame=1) then i:=1;
- if fsd.border[n].tile=1 then tile:=0 else tile:=1;
- if n<3 then sp:=0 else sp:=1;
- { if n<3 then begin
- DrawRectV(dc,rc,fsd.border[n].map,fsd.border[n].r,i,fsd.border[n].frame,tile,sp);
- end else
- DrawRectH(dc,rc,fsd.border[n].map,fsd.border[n].r,i,fsd.border[n].frame,tile,sp);}
- temp:=GetHMap(r,fsd.border[n].map,fsd.border[n].r,I,fsd.border[n].frame,
- Tile,sp);
- BitBlt(dc,rc.left ,rc.top,r.right,r.bottom,
- temp.Canvas.Handle ,0 ,0 ,Srccopy);
- temp.free;
- end;
- procedure TWinSkinForm.Uncropwindow;
- begin
- if crop then begin
- //captionbuf.assign(nil);
- deleteobject(winrgn);
- // skinstate:=skin_Creating;
- if formstyle=sfsmdichild then
- SetWindowRgn(hwnd,0,true)
- else
- SetWindowRgn(hwnd,0,false);
- // skinstate:=skin_Active;
- crop:=false;
- end;
- end;
- procedure TWinSkinForm.cropwindow;
- var rgn1,rgn2,rgn3,rgn4 : HRGN;
- WR,r1: TRect;
- fbmp:Tbitmap;
- t1 : dword;
- begin
- // dolog(format('****%s Crop Window Start',[caption]));
- // if formstyle=sfsMDIchild then exit;
- if (skinstate=skin_Deleted) or (not sMainMenu) then exit;
- GetWindowRect(hwnd, WR);
- OffsetRect(wr,-wr.left,-wr.top);
- if wr.bottom*wr.right=0 then exit;
- if (formstyle=sfsmdichild) and (windowstate<>swsnormal) then exit;
- // if (windowstate<>swsnormal) then exit;
- if (crwidth=wr.right) and (crheight=wr.bottom) then begin
- if (formstyle<>sfsmdichild) and (SkinState<>skin_change) then exit;
- end;
- if crop then deleteobject(winrgn);
- crop := false;
- if (fsd.border[1].trans+fsd.border[2].trans+
- fsd.border[3].trans+fsd.border[1].trans)= 0 then begin
- winrgn:= CreateRectRgn(0,0,wr.right,wr.bottom);
- SetWindowRgn(hwnd,WinRgn,true);
- crop:=true;
- exit;
- end;
- t1:=gettickcount;
- crwidth :=wr.right;
- crheight:=wr.bottom;
-
- winrgn:= CreateRectRgn(bw.left,bw.top,
- wr.right-bw.right,wr.bottom-bw.bottom);
- if formborder<>sbsnone then begin
- fbmp:=Tbitmap.create;
- if (fsd.border[1].trans=1) and (wr.bottom>1) then begin
- r1:=rect(0,0,bw.left,wr.bottom);
- fbmp.width:=r1.right;
- fbmp.height:=r1.bottom;
- drawborder(1,r1,fbmp.canvas.handle);
- rgn1:=BitmapToRegion(fbmp,0,0,clFuchsia);
- end else
- rgn1:=CreateRectRgn(0,0,bw.left,wr.bottom);
- if (fsd.border[2].trans=1) and (wr.bottom>1) then begin
- r1:=rect(0,0,bw.right,wr.bottom);
- fbmp.width:=r1.right;
- fbmp.height:=r1.bottom;
- drawborder(2,r1,fbmp.canvas.handle);
- rgn2:=BitmapToRegion(fbmp,wr.right-bw.right,0,clFuchsia);
- end else
- rgn2:=CreateRectRgn(wr.right-bw.right,0,wr.right,wr.bottom);
- if fsd.border[4].trans=1 then begin
- r1:=rect(0,0,wr.right-bw.left-bw.right,bw.bottom);
- fbmp.width:=r1.right;
- fbmp.height:=r1.bottom;
- drawborder(4,r1,fbmp.canvas.handle);
- if bw.bottom>1 then
- rgn4:=BitmapToRegion(fbmp,bw.left,wr.bottom-bw.bottom,clFuchsia)
- else rgn4:= CreateRectRgn(bw.left,wr.bottom-bw.bottom,
- wr.right-bw.right,wr.bottom);
- end else
- rgn4:= CreateRectRgn(bw.left,wr.bottom-bw.bottom,
- wr.right-bw.right,wr.bottom);
- if (fsd.border[3].trans=1) and (bw.top>1) then begin
- r1:=rect(0,0,wr.right-bw.left-bw.right,bw.top);
- if (r1.right>0) and (r1.bottom>0) then begin
- fbmp.width:=r1.right;
- fbmp.height:=r1.bottom;
- drawborder(3,r1,fbmp.canvas.handle);
- rgn3:=BitmapToRegion(fbmp,bw.left,0,clFuchsia);
- end else
- rgn3:= CreateRectRgn(bw.left,0,wr.right-bw.right,bw.top);
- end else
- rgn3:= CreateRectRgn(bw.left,0,wr.right-bw.right,bw.top);
- { if (fsd.border[3].trans=1) and (bw.top>1) then begin
- r1:=rect(0,0,wr.right-bw.left-bw.right,bw.top);
- if (r1.right>0) and (r1.bottom>0) then begin
- fbmp.width:=r1.right;
- fbmp.height:=r1.bottom;
- if not captionbuf.empty then
- fbmp.canvas.copyrect(r1,captionbuf.canvas,rect(bw.left,0,r1.right+bw.left,r1.bottom))
- else drawborder(3,r1,fbmp.canvas.handle);
- rgn3:=BitmapToRegion(fbmp,bw.left,0,clFuchsia);
- end else
- rgn3:= CreateRectRgn(bw.left,0,wr.right-bw.right,bw.top);
- end else
- rgn3:= CreateRectRgn(bw.left,0,wr.right-bw.right,bw.top);}
- CombineRgn(Rgn1, Rgn1, Rgn2, RGN_OR);
- CombineRgn(Rgn3, Rgn3, Rgn4, RGN_OR);
- CombineRgn(Rgn3, Rgn3, Rgn1, RGN_OR);
- CombineRgn(WinRgn, WinRgn, Rgn3, RGN_OR);
- DeleteObject(Rgn1);
- DeleteObject(Rgn2);
- DeleteObject(Rgn3);
- DeleteObject(Rgn4);
- fbmp.free;
- end;
- SetWindowRgn(hwnd,WinRgn,true);
- // SetWindowRgn(hwnd,WinRgn,false);
- crop:=true;
- {$IFDEF test}
- t1:=gettickcount-t1;
- doLog('crop window :'+inttostr(t1));
- {$endif}
- end;
- {procedure TWinSkinForm.cropwindow;
- var borderRgn : Thandle;
- WR: TRect;
- fbmp:Tbitmap;
- t1 : dword;
- begin
- t1:=gettickcount;
- if crop then deleteobject(winrgn);
- fbmp:=Tbitmap.create;
- GetWindowRect(fform.Handle, WR);
- OffsetRect(wr,-wr.left,-wr.top);
- fwidth :=wr.right;
- fheight:=wr.bottom;
- fbmp.width:=wr.right;
- fbmp.height:=wr.bottom;
- fbmp.canvas.Brush.color := clBtnFace;
- fbmp.canvas.FillRect(wr);
- // fbmp.canvas.copyrect(wr,fform.canvas,wr);
- drawborder(1,rect(0,0,bw.left,wr.bottom),fbmp.canvas.handle);
- drawborder(2,rect(wr.right-bw.right,0,wr.right,wr.bottom),fbmp.canvas.handle);
- DrawFLine(fbmp.canvas.handle);
- // drawborder(3,rect(bw.left,0,wr.right-bw.right,bw.top),fbmp.canvas);
- drawborder(4,rect(bw.left,wr.bottom-bw.bottom,wr.right-bw.right,wr.bottom),fbmp.canvas.handle);
- winrgn := BitmapToRegion(fbmp,0,0,clFuchsia);
- fbmp.free;
- SetWindowRgn(fform.Handle,WinRgn,True);
- crop:=true;
- t1:=gettickcount-t1;
- doLog('crop window :'+inttostr(t1));
- end;}
- procedure TWinSkinForm.getClipMap(fbmp:Tbitmap);
- var WR: TRect;
- begin
- GetWindowRect(fform.Handle, WR);
- OffsetRect(wr,-wr.left,-wr.top);
- fbmp.width:=wr.right;
- fbmp.height:=wr.bottom;
- // fillrect(fbmp.canvas.handle,wr,fsd
- fbmp.canvas.Brush.color := clBtnFace;
- fbmp.canvas.FillRect(wr);
- drawborder(1,rect(0,0,bw.left,wr.bottom),fbmp.canvas.handle);
- drawborder(2,rect(wr.right-bw.right,0,wr.right,wr.bottom),fbmp.canvas.handle);
- DrawFLine(fbmp.canvas.handle);
- // drawborder(3,rect(bw.left,0,wr.right-bw.right,bw.top),fbmp.canvas);
- drawborder(4,rect(bw.left,wr.bottom-bw.bottom,wr.right-bw.right,wr.bottom),fbmp.canvas.handle);
- end;
- procedure TWinSkinForm.GetWindowstate;
- var wp:WINDOWPLACEMENT;
- begin
- wp.length:=sizeof(WINDOWPLACEMENT);
- GetWindowPlacement(hWnd,@wp);
- case wp.showCmd of
- SW_MINIMIZE,SW_SHOWMINIMIZED,SW_SHOWMINNOACTIVE: windowstate:=swsmin;
- SW_SHOWMAXIMIZED:windowstate:=swsmax;
- else windowstate:=swsnormal;
- end;
- end;
- procedure TWinSkinForm.GetFormstyle;
- var hctrl : Thandle;
- aname:string;
- style:longint;
- begin
- formstyle:=sfsnormal;
- hCtrl := GetTopWindow( hWnd );
- while ( hCtrl<>0 ) do begin
- aname:=getwindowclassName( hCtrl);
- if aname='MDIClient' then begin
- formstyle:=sfsMDIform;
- clienthwnd:=hctrl;
- skinmanager.clienthwnd:=hctrl;
- skinmanager.MDIForm:=fform;
- break;
- end;
- hCtrl := GetNextWindow( hCtrl, GW_HWNDNEXT );
- end;
- end;
- procedure TWinSkinForm.WMNCCalcSize(Var Msg: TMessage);
- var rgrc: PNCCalcSizeParams;
- WP: PWindowPos;
- wr,sr:Trect;
- s:string;
- style:uint;
- m_lLeft, m_lRight, m_lTop, m_lBottom: integer;
- begin
- default(msg);
- if boolean(Msg.wParam) then begin
- rgrc := PNCCalcSizeParams(Msg.lParam);
- WP := rgrc^.lppos;
- // with rgrc^.rgrc[0] do
- // s:=format('%1d,%1d,%1d,%1d',[left,top,right,bottom]);
- if ((formstyle=sfsmdichild) and (windowstate <>swsnormal))
- or (formborder=sbsnone) then begin
- rgrc^.rgrc[1] := rgrc^.rgrc[0];
- Msg.lParam := longint(rgrc);
- Msg.Result := WVR_VALIDRECTS;
- // skinaddlog('Default WMNCCalcSize '+s);
- exit;
- end;
- with rgrc^.rgrc[0] do begin
- right := wp^.x+wp^.cx-bw.right;
- left := wp^.x+bw.left;
- top := wp^.y+bw.top+menuheight;
- bottom := wp^.y+wp^.cy-bw.bottom;
- // s:=format('%1d,%1d,%1d,%1d',[left,top,right,bottom]);
- end;
- // skinaddlog('*******Do WMNCCalcSize '+s);
- rgrc^.rgrc[1] := rgrc^.rgrc[0];
- Msg.lParam := longint(rgrc);
- Msg.Result := WVR_VALIDRECTS;
- Done:=true;
- end else begin
- Msg.Result:=0;
- end;
- end;
- function msgtostr(aMsg: Tmessage):string;
- var s,s1:string;
- i:integer;
- begin
- s:='';
- with amsg do
- case Msg of
- // WM_STYLECHANGED:s:='WM_STYLECHANGED';
- WM_DESTROY:s:='WM_DESTROY';
- WM_NCDESTROY:s:='WM_NCDESTROY';
- // WM_NCHITTEST: ok:=false;//dolog('WM_NCHITTEST');
- WM_NCPAINT: s:='WM_NCPAINT';
- WM_Paint: s:=format('WM_Paint %1x',[amsg.wparam]);
- WM_NCACTIVATE: begin
- s:='WM_NCACTIVATE';
- if BOOLean(wParam) then s:=s+' avtive'
- else s:=s+' Deavtive';
- end;
- WM_NCCALCSIZE: s:='WM_NCCALCSIZE' ;
- WM_SIZE:begin
- s:='WM_SIZE ';
- i:= WParam;
- case i of
- SIZE_RESTORED : s := s+'SIZE_RESTORED';
- SIZE_MINIMIZED : s := s+'SIZE_MINIMIZED';
- SIZE_MAXIMIZED : s := s+'SIZE_MAXIMIZED';
- end;
- s:=s+format(' (%1d,%1d)',[LParamLo,LParamhi]);
- end;
- WM_MENUCHAR : s:='WM_MENUCHAR';
- WM_WINDOWPOSCHANGED:begin
- s:='WM_WINDOWPOSCHANGED';
- end;
- WM_ACTIVATE:begin
- s:= 'WM_ACTIVATE';
- if LOWORD(amsg.wParam)=WA_INACTIVE then s:=s+' Deavtive'
- else s:=s+' avtive';
- end;
- WM_LBUTTONUP:s:='WM_LBUTTONUP';
- WM_LBUTTONDOWN:s:='WM_LBUTTONDOWN';
- WM_NCLButtonDown:s:='WM_NCLButtonDown';
- WM_NCLButtonUp:s:='WM_NCLButtonUp';
- WM_NCRButtonDown:s:='WM_NCRButtonDown';
- WM_NCRButtonUp:s:='WM_NCRButtonUp';
- // WM_NCMOUSEMOVE:s:='WM_NCMOUSEMOVE';
- WM_ERASEBKGND:s:='WM_ERASEBKGND';
- WM_INITMENU :s:='WM_INITMENU';
- WM_INITMENUPOPUP:s:='WM_INITMENUPOPUP';
- WM_MENUSELECT:s:='WM_MENUSELECT';
- WM_PRINTCLIENT:s:='WM_PRINTCLIENT';
- WM_PRINT:s:='WM_PRINT';
- WM_MEASUREITEM:s:='WM_MEASUREITEM';
- WM_DRAWITEM:s:='WM_DRAWITEM';
- WM_CTLCOLORSTATIC :s:=format('WM_CTLCOLORSTATIC %1x',[amsg.wparam]);
- // WM_CTLCOLOREDIT :s:='WM_CTLCOLOREDIT';
- WM_CTLCOLOR:s:=format('WM_CTLCOLOR %1x',[amsg.wparam]);
- WM_CTLCOLORBTN:s:=format('WM_CTLCOLORBTN %1x',[amsg.wparam]);
- WM_HSCROLL :begin
- s:='WM_HSCROLL';
- end;
- WM_VSCROLL : begin
- s:='WM_VSCROLL';
- case amsg.WParamLo of
- SB_LINEUp: s:=s+' SB_LINEUp';
- SB_LINEDown:s:=s+' SB_LINEDown';
- SB_THUMBPOSITION: s:=s+' SB_THUMBPOSITION';
- SB_THUMBTRACK : s:=s+' SB_THUMBTRACK';
- SB_PAGEUp:s:=s+' SB_PAGEUp';
- SB_PAGEDown :s:=s+' SB_PAGEDown';
- SB_ENDSCROLL :s:=s+' SB_ENDSCROLL';
- end;
- s:=s+format(' Pos:%1d',[amsg.WParamhi]);
- end;
- WM_INITDIALOG:s:='WM_INITDIALOG';
- WM_SETTEXT :s:='WM_SETTEXT';
- WM_COMMAND :s:='WM_COMMAND';
- WM_MDIREFRESHMENU:s:='WM_MDIREFRESHMENU';
- WM_GETMINMAXINFO:s:='WM_GETMINMAXINFO';
- WM_CHILDACTIVATE:s:='WM_CHILDACTIVATE';
- CN_NewForm :s:='CN_SkinActive';
- CN_HSCROLL:s:='CN_HSCROLL';
- WM_MOVE:s:='WM_MOVE';
- WM_SETREDRAW:s:='WM_SETREDRAW';
- CM_MENUCHANGED:s:='CM_MENUCHANGED';
- WM_WINDOWPOSCHANGING:s:='WM_WINDOWPOSCHANGING';
- WM_MDIACTIVATE :s:=format('WM_MDIACTIVATE deactive:%1x, active:%1x',[amsg.wparam,amsg.lparam]);
- WM_PARENTNOTIFY:begin
- if WParamLo = WM_CREATE then s:=s+format('WM_PARENTNOTIFY WM_CREATE %1x',[amsg.lparam]);
- if WParamLo = WM_DESTROY then s:=s+format('WM_PARENTNOTIFY WM_DESTROY %1x',[amsg.lparam]);
- end;
- CBN_DROPDOWN:s:='CBN_DROPDOWN';
- end;
- // if s='' then
- // s:=format('%4.0x,%04x,%04x',[amsg.msg,amsg.wparam,amsg.lparam]);
- if s<>'' then
- s:=format('%s,%04x,%04x',[s,amsg.wparam,amsg.lparam]);
- result:=s;
- end;
- procedure DrawBGbmp(acanvas:Tcanvas;Dst:Trect;Bitmap:TBitmap;SrcRect: TRect);
- var
- i, j: integer;
- W, H: integer;
- b:Tbitmap;
- begin
- W := SrcRect.right-srcrect.left;
- H := srcrect.bottom-srcrect.top;
- if (w<0) or (h<0) or (W * H = 0) then Exit;
- b:=Tbitmap.create;
- b.width:=w;
- b.height:=h;
- b.canvas.copyrect(rect(0,0,w,h),bitmap.canvas,srcrect);
- i := dst.left;
- While i < (dst.right ) do
- begin
- j := dst.top;
- While j < (dst.Bottom) do
- begin
- aCanvas.Draw(i, j, b);
- Inc(j, h);
- end;
- Inc(i, w);
- end;
- b.free;
- end;
- procedure TWinSkinForm.ToolBarDrawBackground(Sender: TToolBar; const ARect: TRect; var DefaultDraw: Boolean);
- var t:Ttoolbar;
- old:integer;
- begin
- t:=TToolbar(sender);
- if (fsd.Toolbar<>nil) and (not (xoToolbarBK in fsd.Options)) then begin
- old:=SetStretchBltMode(t.Canvas.Handle,STRETCH_DELETESCANS);
- StretchBlt(t.Canvas.Handle,
- arect.left,arect.top,arect.right-arect.left,arect.bottom-arect.top,
- fsd.Toolbar.map.canvas.handle,0,0,fsd.Toolbar.map.Width,fsd.Toolbar.map.Height,SRCCOPY);
- SetStretchBltMode(t.Canvas.Handle,old);
- end;
- // DefaultDraw:=true;
- end;
- procedure TWinSkinForm.MeasureItem(Sender: TObject; ACanvas: TCanvas;
- var Width, Height: Integer);
- var item:TMenuItemAccess;
- me:TMenuMeasureItemEvent;
- ImageList: TCustomImageList;
- begin
- item:=TMenuItemAccess(sender);
- ImageList := item.GetImageList;
- me:= item.OnMeasureItem;
- item.OnMeasureItem := nil;
- item.MeasureItem(acanvas,width,height);
- if fsd.MenuItem<>nil then inc(width,fsd.MenuItem.r.Left);
- if Assigned(ImageList) then inc(width,10)
- else inc(width,35);
- item.OnMeasureItem := me;
- end;
- {
- var item:Tmenuitem;
- s:string;
- begin
- item:=TMenuItem(sender);
- if item.ShortCut <> 0 then
- s := Concat(item.Caption, ShortCutToText(item.ShortCut))
- else s := item.Caption;
- width:= acanvas.TextWidth(s)+26;
- if (item.Caption <> cLineCaption) then inc(height,4)
- else height:=8;
- if (winversion >= $80000000) then
- inc(height,4);
- end;}
- procedure TWinSkinForm.MeasureItemPop(Sender: TObject; ACanvas: TCanvas;
- var Width, Height: Integer);
- var item:TMenuItemAccess;
- ImageList: TCustomImageList;
- begin
- if fsd=nil then exit;
- item:=TMenuItemAccess(sender);
- ImageList := item.GetImageList;
- // item.OnMeasureItem := nil;
- // item.MeasureItem(acanvas,width,height);
- try
- if (not IsBadReadPtr(fsd, fsd.InstanceSize)) and (fsd.MenuItem<>nil) then
- inc(width,fsd.MenuItem.r.Left);
- except
- end;
- if Assigned(ImageList) then inc(width,12)
- else inc(width,35);
- // item.OnMeasureItem := MeasureItempop;
- { inc(width,28);
- if (winversion >= $80000000) and
- (Tmenuitem(sender).Caption <> cLineCaption) then
- inc(height,4);}
- end;
- function TWinSkinForm.GetMenuBG:Tbitmap;
- var ahwnd:Thandle;
- pmenu:Twinskinpopmenu;
- begin
- result:=nil;
- ahwnd:=GetTopWindow(0);
- pmenu := Twinskinpopmenu(GetProp(ahwnd, c_menuprop));
- if pmenu<>nil then
- result := pmenu.menubg;
- end;
- procedure TWinSkinForm.DrawMenuItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect;
- Selected: Boolean);
- var i:integer;
- b,b1,temp:Tbitmap;
- rc,r1,r2:Trect;
- item:Tmenuitem;
- begin
- skinmanager.setpopmenu;
- if fsd.menuitem= nil then begin
- DefaultMenuItem(sender,acanvas,arect,selected);
- exit;
- end;
- rc:=arect;
- r1:=arect;
- offsetrect(r1,3,3);
- item:=Tmenuitem(Sender);
- { if (newskinmenu<>nil) and assigned(item.parent) then begin
- newskinmenu.hmenu:=item.parent.handle;
- newskinmenu:=nil;
- end;}
- if assigned(item.parent) then begin
- skinmanager.sethmenu(item.parent.handle);
- end;
- offsetrect(rc,-rc.left,-rc.top);
- b:=Tbitmap.create;
- b.width:=rc.right;
- b.height:=rc.bottom;
- b.Canvas.Font := Screen.MenuFont;
- temp:=SkinManager.getmenubg(item.parent.handle);
- // temp:=getmenubg();
- if (temp<>nil) and (not temp.empty) then begin
- b.canvas.copyrect(rc,temp.canvas,r1) ;
- // fsd.DoDebug('DrawMenuItem');
- end else begin
- b.canvas.brush.color:=fsd.colors[csMenubg];
- b.canvas.fillrect(rc);
- end;
- i:=1;
- if selected then i:=4;
- if item.caption<>cLineCaption then begin
- DrawRect2(b.canvas.handle,rc,fsd.menuitem.map,
- fsd.menuitem.r,i,5,fsd.menuitem.trans,fsd.menuitem.tile);
- DrawItemText(Item,b.Canvas,rc,Selected);
- acanvas.draw(arect.left,arect.top,b);
- end else begin
- i:=2;
- acanvas.draw(arect.left,arect.top,b);
- DrawMenuCaption(ACanvas,arect);
- end;
- b.free;
- end;
- procedure TWinSkinForm.DrawMenuCaption(ACanvas: TCanvas; ARect: TRect);
- var temp:Tbitmap;
- rc,r1,r2:Trect;
- w,h,x,y:integer;
- begin
- temp:=Tbitmap.create;
- rc:=arect;
- offsetrect(rc,-rc.left,-rc.top);
- temp.width:=rc.right;
- temp.height:=rc.bottom;
- w:=fsd.menuitem.map.width div 5;
- h:= fsd.menuitem.map.height;
- if h>rc.bottom then y:= h-rc.bottom
- else y:=0;
- x:= w;
- //left
- r1:=rect(0,0,fsd.menuitem.r.left,rc.bottom);
- r2:=rect(x,y,x+fsd.menuitem.r.left,h);
- temp.canvas.copyrect(r1,fsd.menuitem.map.canvas,r2);
- //right
- r1:=rect(rc.right-fsd.menuitem.r.right,0,rc.right,rc.bottom);
- r2:=rect(w+x-fsd.menuitem.r.right,y,w+x,h);
- temp.canvas.copyrect(r1,fsd.menuitem.map.canvas,r2);
- //center
- r1:=rect(fsd.menuitem.r.left,0,rc.right-fsd.menuitem.r.right,rc.bottom);
- r2:=rect(x+fsd.menuitem.r.left,y,w+x-fsd.menuitem.r.right,h);
- temp.canvas.copyrect(r1,fsd.menuitem.map.canvas,r2);
- temp.Transparent:=true;
- temp.Transparentcolor:=clFuchsia;
- acanvas.draw(arect.left,arect.top,temp);
- temp.free;
- end;
- procedure TWinSkinForm.DrawHMenuItem2(Amenu:Hmenu;Sender:TObject; ACanvas: TCanvas; ARect: TRect;
- Selected: Boolean);
- var i:integer;
- b,b1,temp:Tbitmap;
- rc,r1,r2:Trect;
- item:Tmenuitem;
- begin
- if fsd.menuitem= nil then begin
- // Drawmymenuitem(sender,acanvas,arect,selected);
- DefaultMenuItem(sender,acanvas,arect,selected);
- exit;
- end;
- rc:=arect;
- r1:=arect;
- offsetrect(r1,3,3);
- item:=Tmenuitem(Sender);
- offsetrect(rc,-rc.left,-rc.top);
- b:=Tbitmap.create;
- b.width:=rc.right;
- b.height:=rc.bottom;
- b.Canvas.Font := Screen.MenuFont;
- temp:=SkinManager.getmenubg(amenu);
- //temp:=getmenubg();
- if temp<>nil then
- b.canvas.copyrect(rc,temp.canvas,r1)
- else begin
- b.canvas.brush.color:=fsd.colors[csMenubg];
- b.canvas.fillrect(rc);
- end;
- i:=1;
- if selected then i:=4;
- DrawRect2(b.canvas.handle,rc,fsd.menuitem.map,
- fsd.menuitem.r,i,5,fsd.menuitem.trans,fsd.menuitem.tile);
- DrawItemText(Item,b.Canvas,rc,Selected);
- acanvas.draw(arect.left,arect.top,b);
- b.free;
- end;
- procedure TWinSkinForm.DefaultMenuItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect;
- Selected: Boolean);
- var i:integer;
- b,b1,temp:Tbitmap;
- rc,r1,r2:Trect;
- item:Tmenuitem;
- begin
- rc:=arect;
- item:=Tmenuitem(Sender);
- offsetrect(rc,-rc.left,-rc.top);
- b:=Tbitmap.create;
- b.width:=rc.right;
- b.height:=rc.bottom;
- b.Canvas.Font := Screen.MenuFont;
- if selected then
- b.canvas.brush.color:= fsd.colors[csHilight]
- else b.canvas.brush.color:=fsd.colors[csMenuBG];//[csbuttonface];
- b.canvas.fillrect(rc);
- DrawItemText(Item,b.Canvas,rc,Selected);
- acanvas.draw(arect.left,arect.top,b);
- b.free;
- end;
- procedure TWinSkinForm.DoDrawText(item:Tmenuitem;ACanvas: TCanvas; const ACaption: widestring;
- var Rect: TRect; Selected: Boolean; Flags: Longint);
- var Text: widestring;
- R: TRect;
- ParentMenu: TMenu;
- acolor:Tcolor;
- b:boolean;
- begin
- { ParentMenu := Item.GetParentMenu;
- if (ParentMenu <> nil) and (ParentMenu.IsRightToLeft) then begin
- if Flags and DT_RIGHT = DT_RIGHT then
- Flags := Flags and (not DT_RIGHT) or DT_LEFT
- else if Flags and DT_LEFT = DT_LEFT then
- Flags := Flags and (not DT_LEFT) or DT_RIGHT;
- Flags := Flags or DT_RTLREADING;
- end;}
- Text := ACaption;
- if (Flags and DT_CALCRECT <> 0) and ((Text = '') or
- (Text[1] = cHotkeyPrefix) and (Text[2] = #0)) then Text := Text + ' ';
- with ACanvas do begin
- if Text = cLineCaption then begin
- if Flags and DT_CALCRECT = 0 then begin
- R := Rect;
- Inc(R.Top, 4);
- inc(r.left,0);
- DrawEdge(Handle, R, EDGE_ETCHED, BF_TOP);
- end;
- end else begin
- Brush.Style := bsClear;
- if item.Default then
- Font.Style := Font.Style + [fsBold];
- // b:=item.Enabled;
- // if item.Action.
- if not item.Enabled then begin
- if fsd.colors[csbuttonshadow]<>fsd.colors[csMenuText] then
- Font.Color := fsd.colors[csbuttonshadow]
- else
- Font.Color := clBtnShadow;
- end else begin
- if Selected then begin
- Font.Color := fsd.colors[csHilightText];
- end else begin
- Font.Color := fsd.colors[csMenuText];
- end;
- end;
- // DrawText(Handle, PChar(Text), Length(Text), Rect, Flags);
- Tnt_DrawTextW(Handle,Text, Rect, Flags);
- end;
- end;
- end;
- procedure TWinSkinForm.DrawItemText(Item:TMenuitem;ACanvas: TCanvas;
- ARect: TRect;Selected:boolean);
- const
- Alignments: array[TPopupAlignment] of Word = (DT_LEFT, DT_RIGHT, DT_CENTER);
- EdgeStyle: array[Boolean] of Longint = (BDR_RAISEDINNER, BDR_SUNKENOUTER);
- var
- ImageList: TCustomImageList;
- ParentMenu: TMenu;
- Alignment: TPopupAlignment;
- DrawImage, DrawGlyph: Boolean;
- GlyphRect, SaveRect: TRect;
- DrawStyle,DrawStyle2: Longint;
- Glyph: TBitmap;
- OldBrushColor: TColor;
- w:integer;
- text:widestring;
-
- procedure DrawItemRight;
- begin
- GlyphRect.right := ARect.right -1;
- GlyphRect.Top := ARect.Top + 1;
- if fsd.MenuItem<>nil then glyphrect.right:=glyphrect.right-fsd.MenuItem.r.Left;
- if item.Caption = cLineCaption then begin
- GlyphRect.Left := ARect.right;
- GlyphRect.Right := ARect.right;//-2;
- DrawGlyph := False;
- end else begin
- GlyphRect.left := GlyphRect.right - w;
- GlyphRect.Bottom := GlyphRect.Top + w;
- if (ImageList<>nil) and (item.ImageIndex > -1) and (item.ImageIndex < ImageList.Count) then begin
- if item.checked then begin
- OldBrushColor := Acanvas.Brush.Color;
- Acanvas.Brush.Bitmap := AllocPatternBitmap(clBtnFace, clBtnHighlight);
- acanvas.FillRect(GlyphRect);
- //acanvas.FrameRect(GlyphRect);
- Acanvas.Brush.Color:=OldBrushColor;
- DrawEdge(acanvas.Handle,GlyphRect,BDR_SUNKENOUTER, BF_RECT);
- end ;
- ImageList.Draw(ACanvas, GlyphRect.Left, GlyphRect.Top, item.ImageIndex,
- item.Enabled);
- end else if item.checked then begin
- // { Draw a menu check
- Glyph := TBitmap.Create;
- try
- Glyph.Transparent := True;
- Glyph.Handle := LoadBitmap(0, PChar(OBM_CHECK));
- OldBrushColor := acanvas.Font.Color;
- acanvas.Font.Color := clBtnText;
- acanvas.Draw(GlyphRect.Left + (GlyphRect.Right - GlyphRect.Left - Glyph.Width) div 2 + 1,
- GlyphRect.Top + (GlyphRect.Bottom - GlyphRect.Top - Glyph.Height) div 2 + 1, Glyph);
- acanvas.Font.Color := OldBrushColor;
- finally
- Glyph.Free;
- end;
- end;
- end;
- ARect.right := GlyphRect.left - 1;
- Inc(ARect.Left, 1);
- Dec(ARect.Right, 2);
- // DrawStyle := DT_EXPANDTABS or DT_SINGLELINE or Alignments[Alignment];
- DrawStyle := DT_EXPANDTABS or DT_SINGLELINE or DT_RIGHT or DT_RTLREADING;
- DrawStyle2 := DT_Left;
- // Calculate vertical layout
- SaveRect := ARect;
- DoDrawText(item,ACanvas, text, ARect, Selected, DrawStyle or DT_CALCRECT or DT_NOCLIP);
- OffsetRect(ARect, 0, ((SaveRect.Bottom - SaveRect.Top) - (ARect.Bottom - ARect.Top)) div 2);
- arect.Left := saverect.left;arect.right:=saverect.Right;
- DoDrawText(item,ACanvas, text, ARect, Selected, DrawStyle);
- if (item.ShortCut <> 0) then begin
- //ARect.Right := ARect.left-2;
- ARect.Left := Saverect.left+10;
- //ARect.Right := SaveRect.Right - 2;
- DoDrawText(item,ACanvas, ShortCutToText(item.ShortCut), ARect, Selected, DrawStyle2);
- end;
- end;
- begin
- // if Assigned(item.Action) then item.Action.Update;
- text:=GetStringProp(item,'Caption');
- ParentMenu := item.GetParentMenu;
- ImageList := item.GetImageList;
- if (parentmenu = nil) and (menu<>nil) then
- parentmenu:=menu.menu;
- Alignment := paLeft;
- if ParentMenu is TMenu then
- Alignment := paLeft
- else if ParentMenu is TPopupMenu then
- Alignment := TPopupMenu(ParentMenu).Alignment
- else Alignment := paLeft;
- w:=16;
- if (ImageList<>nil) then w:=ImageList.Width ;
- //else w:=2;
- if item.checked and (w<16) then w:=16;
- if ParentMenu.IsRightToLeft then begin
- DrawitemRight;
- exit;
- end;
- GlyphRect.Left := ARect.Left + 1;
- GlyphRect.Top := ARect.Top + 1;
- if fsd.MenuItem<>nil then glyphrect.Left:=glyphrect.Left+fsd.MenuItem.r.Left;
- if item.Caption = cLineCaption then begin
- GlyphRect.Left := 0;
- GlyphRect.Right := 0;//-2;
- DrawGlyph := False;
- end else begin
- GlyphRect.Right := GlyphRect.Left + w;
- GlyphRect.Bottom := GlyphRect.Top + w;
- if (ImageList<>nil) and (item.ImageIndex > -1) and (item.ImageIndex < ImageList.Count) then begin
- if item.checked then begin
- OldBrushColor := Acanvas.Brush.Color;
- Acanvas.Brush.Bitmap := AllocPatternBitmap(clBtnFace, clBtnHighlight);
- acanvas.FillRect(GlyphRect);
- //acanvas.FrameRect(GlyphRect);
- Acanvas.Brush.Color:=OldBrushColor;
- GlyphRect.Top := arect.Top+((Arect.Bottom-arect.Top)-16) div 2;
- DrawEdge(acanvas.Handle,GlyphRect,BDR_SUNKENOUTER, BF_RECT);
- end else
- GlyphRect.Top := arect.Top+((Arect.Bottom-arect.Top)-imagelist.Height) div 2;
- ImageList.Draw(ACanvas, GlyphRect.Left, GlyphRect.Top, item.ImageIndex,
- item.Enabled);
- end else if item.checked then begin
- // { Draw a menu check
- Glyph := TBitmap.Create;
- try
- Glyph.Transparent := True;
- Glyph.Handle := LoadBitmap(0, PChar(OBM_CHECK));
- GlyphRect.Top := arect.Top+((Arect.Bottom-arect.Top)-glyph.Height) div 2;
- OldBrushColor := acanvas.Font.Color;
- acanvas.Font.Color := clBtnText;
- acanvas.Draw(GlyphRect.Left + (GlyphRect.Right - GlyphRect.Left - Glyph.Width) div 2 + 1,
- GlyphRect.Top + 1, Glyph);
- acanvas.Font.Color := OldBrushColor;
- finally
- Glyph.Free;
- end;
- end;
- end;
- ARect.Left := GlyphRect.Right + 1;
- Inc(ARect.Left, 2);
- Dec(ARect.Right, 1);
- // DrawStyle := DT_EXPANDTABS or DT_SINGLELINE or Alignments[Alignment];
- DrawStyle := DT_EXPANDTABS or DT_SINGLELINE or DT_Left;
- DrawStyle2 := DT_Right;
- // Calculate vertical layout
- SaveRect := ARect;
- DoDrawText(item,ACanvas, text, ARect, Selected, DrawStyle or DT_CALCRECT or DT_NOCLIP);
- OffsetRect(ARect, 0, ((SaveRect.Bottom - SaveRect.Top) - (ARect.Bottom - ARect.Top)) div 2);
- // arect.Left := saverect.left;arect.right:=saverect.Right;
- DoDrawText(item,ACanvas, text, ARect, Selected, DrawStyle);
- if (item.ShortCut <> 0) then begin
- ARect.Left := ARect.Right;
- ARect.Right := SaveRect.Right - 10;
- DoDrawText(item,ACanvas, ShortCutToText(item.ShortCut), ARect, Selected, DrawStyle2);
- end;
- end;
- procedure TWinSkinForm.ToolBarDrawButton(Sender: TToolBar;
- Button: TToolButton; State: TCustomDrawState; var DefaultDraw: Boolean);
- var i:integer;
- r1:Trect;
- begin
- if (fsd.button=nil) or (skinstate<>Skin_Active) or
- (xoToolbarButton in fsd.Options) then exit;
- i:=0;
- if cdsSelected in state then i:=2
- else if cdsFocused in state then i:=4
- else if cdsHot in State then i:=4
- else if cdsGrayed in state then i:=0
- else if cdsDisabled in state then i:=0
- else if cdsDefault in state then i:=1;
- if i=0 then exit;
-
- if (i=1) and (fsd.button.newnormal) then
- sender.canvas.Font.Color:= fsd.button.normalcolor2;
- if (i=4) and (fsd.button.newover) then
- sender.canvas.Font.Color:= fsd.button.overcolor2;
- if (i=2) and (fsd.Button.newdown) then
- sender.canvas.Font.Color:= fsd.button.downcolor2;
- r1:=Button.BoundsRect;
- InflateRect(r1,-1,-1);
- // clientRgn :=CreateRectRgn(r1.left,r1.top,r1.right,r1.bottom);
- // SelectClipRgn(sender.canvas.HANDLE, clientRgn);
- if fsd.button<>nil then
- DrawRect2(sender.canvas.handle,r1,fsd.button.map,
- fsd.button.r,i,5,fsd.button.trans);
- { if cdsSelected in state then i:=2
- else if cdsFocused in state then i:=4
- else if cdsHot in State then i:=4
- else if cdsGrayed in state then i:=3
- else if cdsDisabled in state then i:=3
- else if cdsDefault in state then i:=5;
- r1:=Button.BoundsRect;
- if fsd.toolbar<>nil then
- DrawRect2(sender.canvas.handle,r1,fsd.toolbar.map,
- fsd.toolbar.r,i,5,fsd.toolbar.trans);}
- // DefaultDraw:=false;
- end;
- procedure TWinSkinForm.InitDlg(afsd:Tskindata);
- begin
- InitSkin(afsd);
- end;
- destructor TWinSkinSpy.Destroy;
- begin
- // skinaddlog('TWinSkinSpy Destory');
- inherited destroy;
- end;
- procedure TWinSkinSpy.Notification(AComponent: TComponent;
- Operation: TOperation);
- var j:integer;
- sc:Tskincontrol;
- begin
- inherited Notification(AComponent, Operation);
- //do nothing
- // if (Operation = opRemove) and (AComponent <> nil) and
- // (AComponent is TGraphicControl) then begin
- // end;
- end;
- function BitmapToRegion(bmp: TBitmap; xx,yy:integer;TransparentColor: TColor=clFuchsia;
- RedTol: Byte=1; GreenTol: Byte=1; BlueTol: Byte=1): HRGN;
- const
- AllocUnit = 500;
- type
- PRectArray = ^TRectArray;
- TRectArray = Array[0..(MaxInt div SizeOf(TRect))-1] of TRect;
- var
- pr: PRectArray; // used to access the rects array of RgnData by index
- h: HRGN; // Handles to regions
- RgnData: PRgnData; // Pointer to structure RGNDATA used to create regions
- lr, lg, lb, hr, hg, hb: Byte; // values for lowest and hightest trans. colors
- x,y, x0: Integer; // coordinates of current rect of visible pixels
- b: PByteArray; // used to easy the task of testing the byte pixels (R,G,B)
- ScanLinePtr: Pointer; // Pointer to current ScanLine being scanned
- ScanLineInc: Integer; // Offset to next bitmap scanline (can be negative)
- maxRects: Cardinal; // Number of rects to realloc memory by chunks of AllocUnit
- begin
- Result := 0;
- { Keep on hand lowest and highest values for the "transparent" pixels }
- lr := GetRValue(TransparentColor);
- lg := GetGValue(TransparentColor);
- lb := GetBValue(TransparentColor);
- hr := Min($ff, lr + RedTol);
- hg := Min($ff, lg + GreenTol);
- hb := Min($ff, lb + BlueTol);
- { ensures that the pixel format is 32-bits per pixel }
- bmp.PixelFormat := pf32bit;
- { alloc initial region data }
- maxRects := AllocUnit;
- GetMem(RgnData,SizeOf(RGNDATAHEADER) + (SizeOf(TRect) * maxRects));
- try
- with RgnData^.rdh do
- begin
- dwSize := SizeOf(RGNDATAHEADER);
- iType := RDH_RECTANGLES;
- nCount := 0;
- nRgnSize := 0;
- SetRect(rcBound, MAXLONG, MAXLONG, 0, 0);
- end;
- { scan each bitmap row - the orientation doesn't matter (Bottom-up or not) }
- ScanLinePtr := bmp.ScanLine[0];
- ScanLineInc := Integer(bmp.ScanLine[1]) - Integer(ScanLinePtr);
- for y := 0 to bmp.Height - 1 do begin
- x := 0;
- while x < bmp.Width do begin
- x0 := x;
- while x < bmp.Width do begin
- b := @PByteArray(ScanLinePtr)[x*SizeOf(TRGBQuad)];
- // BGR-RGB: Windows 32bpp BMPs are made of BGRa quads (not RGBa)
- if (b[2] >= lr) and (b[2] <= hr) and
- (b[1] >= lg) and (b[1] <= hg) and
- (b[0] >= lb) and (b[0] <= hb) then
- Break; // pixel is transparent
- Inc(x);
- end;
- { test to see if we have a non-transparent area in the image }
- if x > x0 then begin
- { increase RgnData by AllocUnit rects if we exceeds maxRects }
- if RgnData^.rdh.nCount >= maxRects then begin
- Inc(maxRects,AllocUnit);
- ReallocMem(RgnData,SizeOf(RGNDATAHEADER) + (SizeOf(TRect) * MaxRects));
- end;
- { Add the rect (x0, y)-(x, y+1) as a new visible area in the region }
- pr := @RgnData^.Buffer; // Buffer is an array of rects
- with RgnData^.rdh do begin
- SetRect(pr[nCount], x0+xx, y+yy, x+xx, y+1+yy);
- { adjust the bound rectangle of the region if we are "out-of-bounds" }
- if x0 < rcBound.Left then rcBound.Left := x0;
- if y < rcBound.Top then rcBound.Top := y;
- if x > rcBound.Right then rcBound.Right := x;
- if y+1 > rcBound.Bottom then rcBound.Bottom := y+1;
- Inc(nCount);
- end;
- end; // if x > x0
- { Need to create the region by muliple calls to ExtCreateRegion, 'cause }
- { it will fail on Windows 98 if the number of rectangles is too large }
- if RgnData^.rdh.nCount = 2000 then
- begin
- h := ExtCreateRegion(nil, SizeOf(RGNDATAHEADER) + (SizeOf(TRect) * maxRects), RgnData^);
- if Result > 0 then
- begin // Expand the current region
- CombineRgn(Result, Result, h, RGN_OR);
- DeleteObject(h);
- end
- else // First region, assign it to Result
- Result := h;
- RgnData^.rdh.nCount := 0;
- SetRect(RgnData^.rdh.rcBound, MAXLONG, MAXLONG, 0, 0);
- end;
- Inc(x);
- end; // scan every sample byte of the image
- Inc(Integer(ScanLinePtr), ScanLineInc);
- end;
- { need to call ExCreateRegion one more time because we could have left }
- { a RgnData with less than 2000 rects, so it wasn't yet created/combined }
- h := ExtCreateRegion(nil, SizeOf(RGNDATAHEADER) + (SizeOf(TRect) * MaxRects), RgnData^);
- if Result > 0 then
- begin
- CombineRgn(Result, Result, h, RGN_OR);
- DeleteObject(h);
- end
- else
- Result := h;
- finally
- FreeMem(RgnData,SizeOf(RGNDATAHEADER) + (SizeOf(TRect) * MaxRects));
- end;
- end;
- procedure DrawRect2(DC:HDC;Dst:Trect;Bmp:TBitmap;Src: TRect;I,N:integer;
- Trans:integer=0;Tile:integer=0;Spliter:integer=0);
- var temp:Tbitmap;
- begin
- if (dst.right<dst.left) or (dst.bottom<dst.top) then exit;
- temp:= GetHMap(Dst,Bmp,Src,I,N,tile,spliter);
- if trans=0 then
- BitBlt(dc,dst.left,dst.top,dst.right-dst.left,dst.bottom-dst.top,
- temp.Canvas.Handle ,0 ,0 ,SrcCopy)
- else DrawTranmap(DC,Dst,temp);
- temp.free;
- end;
- procedure DrawRectTile(acanvas:Tcanvas;Dst:Trect;Bmp:TBitmap;Src: TRect;I,N:integer;
- Trans:integer=0;Spliter:integer=1);
- var temp:Tbitmap;
- x0,y0,x,y,w,h ,w1,h1,m:integer;
- begin
- if (dst.right<dst.left) or (dst.bottom<dst.top) then exit;
- temp:=Tbitmap.create;
- w:=dst.right-dst.left;
- h:=dst.bottom-dst.top;
- temp.width:=w;
- temp.height:=h;
- if Spliter=0 then begin
- w1:=bmp.width div n;
- h1:=bmp.height;
- x0:=(i-1)*w1;
- y0:=0;
- end else begin
- w1:=bmp.width ;
- h1:=bmp.height div N;
- y0:=(i-1)*h1;
- x0:=0;
- end;
- SetStretchBltMode(temp.canvas.handle,STRETCH_DELETESCANS);
- temp.canvas.copyrect(rect(0,0,src.left,h),bmp.canvas,
- rect(x0,y0,x0+src.left,y0+h1));
- x:=src.left;
- m:= w1-src.left-src.right;
- while x<(w-src.right) do begin
- temp.canvas.copyrect(rect(x,0,x+m,h),bmp.canvas,
- rect(x0+src.left,y0,x0+src.left+m,y0+h1));
- inc(x,m);
- end;
- temp.canvas.copyrect(rect(w-src.right,0,w,h),bmp.canvas,
- rect(x0+w1-src.right,y0,x0+w1,y0+h1));
- if trans=0 then
- BitBlt(acanvas.handle,dst.left,dst.top,dst.right-dst.left,dst.bottom-dst.top,
- temp.Canvas.Handle ,0 ,0 ,SrcCopy)
- else begin
- // DrawTranmap(DC,Dst,temp);
- temp.transparent:=true;
- temp.transparentcolor:=clFuchsia;
- acanvas.draw(dst.left,dst.top,temp)
- end;
- temp.free;
- end;
- function GetHMap(Dst:Trect;Bmp:TBitmap;Src:TRect;I,N:integer;
- Tile:integer=0;Spliter:integer=0):Tbitmap;
- var r1,r2:Trect;
- x,y,w,h,w2,h2:integer;
- color,c1,c2 :Tcolor;
- temp: Tbitmap;
- b1,b2:boolean;
- begin
- if Spliter=0 then begin
- w:=bmp.width div n;
- h:=bmp.height;
- x:=(i-1)*w;
- y:=0;
- end else begin
- w:=bmp.width ;
- h:=bmp.height div N;
- y:=(i-1)*h;
- x:=0;
- end;
- temp:=Tbitmap.create;
- w2:=dst.right-dst.left;
- h2:=dst.bottom-dst.top;
- temp.width:=w2;
- temp.height:=h2;
- b1:= w2<(src.left+src.right);
- b2:= h2<(src.top+src.bottom);
- if b1 then begin
- src.left:=0; src.right:=0;
- end;
- if b2 then begin
- src.top:=0; src.bottom:=0;
- end;
- //left-top-corner
- SetStretchBltMode(temp.canvas.handle,STRETCH_DELETESCANS);
- if (src.left*src.top>0) then begin
- r1:=rect(0,0,src.left,src.top);
- r2:=rect(x,y,x+src.left,y+src.top);
- temp.canvas.copyrect(r1,bmp.canvas,r2);
- end;
- //left-bottom-corner
- if (src.left*src.bottom>0) then begin
- r1:=rect(0,h2-src.bottom,src.left,h2);
- r2:=rect(x,y+h-src.bottom,x+src.left,y+h);
- temp.canvas.copyrect(r1,bmp.canvas,r2);
- end;
- //right-top-corner
- if src.right*src.top>0 then begin
- r1:=rect(w2-src.right,0,w2,src.top);
- r2:=rect(x+w-src.right,y,x+w,src.top+y);
- temp.canvas.copyrect(r1,bmp.canvas,r2);
- end;
- //left
- if src.left>0 then begin
- r1:=rect(0,src.top,src.left,h2-src.bottom);
- r2:=rect(x,y+src.top,x+src.left,y+h-src.bottom);
- temp.canvas.copyrect(r1,bmp.canvas,r2);
- end;
- //top
- if src.top>0 then begin
- r1:=rect(src.left,0,w2-src.right,src.top);
- r2:=rect(x+src.left,y,x+w-src.right,y+src.top);
- temp.canvas.copyrect(r1,bmp.canvas,r2);
- end;
- //center
- r1:=rect(src.left,src.top,w2-src.right,h2-src.bottom);
- r2:=rect(x+src.left,y+src.top,x+w-src.right,y+h-src.bottom);
- // temp.canvas.copyrect(r1,bmp.canvas,r2);
- if tile=0 then begin
- // temp.canvas.copyrect(r1,bmp.canvas,r2)
- StretchBlt(temp.canvas.handle,r1.left,r1.top,r1.right-r1.left,r1.bottom-r1.top,
- bmp.canvas.handle,r2.left,r2.top,r2.right-r2.left,r2.bottom-r2.top,SRCCOPY);
- end else
- DrawBGbmp(temp.canvas,r1,bmp,r2);
- //right-bottom-corner
- if src.right*src.bottom>0 then begin
- r1:=rect(w2-src.right,h2-src.bottom,w2,h2);
- r2:=rect(x+w-src.right,y+h-src.bottom,x+w,y+h);
- temp.canvas.copyrect(r1,bmp.canvas,r2);
- end;
- //right
- if src.right>0 then begin
- r1:=rect(w2-src.right,src.top,w2,h2-src.bottom);
- r2:=rect(x+w-src.right,y+src.top,x+w,y+h-src.bottom);
- temp.canvas.copyrect(r1,bmp.canvas,r2);
- end;
- //bottom
- if src.bottom>0 then begin
- r1:=rect(src.left,h2-src.bottom,w2-src.right,h2);
- r2:=rect(x+src.left,y+h-src.bottom,x+w-src.right,y+h);
- temp.canvas.copyrect(r1,bmp.canvas,r2);
- end;
- result:=temp;
- end;
- procedure DrawBorder(Dc:HDC;Dst:Trect;Bmp:TBitmap;Src:TRect;I,N:integer;
- Tile:integer=0;Spliter:integer=0);
- var r1,r2:Trect;
- x,y,w,h,w2,h2:integer;
- b1,b2:boolean;
- begin
- if Spliter=0 then begin
- w:=bmp.width div n;
- h:=bmp.height;
- x:=(i-1)*w;
- y:=0;
- end else begin
- w:=bmp.width ;
- h:=bmp.height div N;
- y:=(i-1)*h;
- x:=0;
- end;
- w2:=dst.right-dst.left;
- h2:=dst.bottom-dst.top;
- b1:= w2<(src.left+src.right);
- b2:= h2<(src.top+src.bottom);
- if b1 then begin
- src.left:=0; src.right:=0;
- end;
- if b2 then begin
- src.top:=0; src.bottom:=0;
- end;
- //left-top-corner
- SetStretchBltMode(dc,STRETCH_DELETESCANS);
- if (src.left*src.top>0) then begin
- r1:=rect(0,0,src.left,src.top);
- offsetrect(r1,dst.left,dst.top);
- r2:=rect(x,y,x+src.left,y+src.top);
- StretchBlt(dc,r1.left,r1.top,r1.right-r1.left,r1.bottom-r1.top,
- bmp.Canvas.Handle ,r2.left,r2.top,r2.right-r2.left,r2.bottom-r2.top,SrcCopy);
- end;
- //left-bottom-corner
- if (src.left*src.bottom>0) then begin
- r1:=rect(0,h2-src.bottom,src.left,h2);
- OffsetRect(r1,dst.left,dst.top);
- r2:=rect(x,y+h-src.bottom,x+src.left,y+h);
- StretchBlt(dc,r1.left,r1.top,r1.right-r1.left,r1.bottom-r1.top,
- bmp.Canvas.Handle ,r2.left,r2.top,r2.right-r2.left,r2.bottom-r2.top,SrcCopy);
- end;
- //right-top-corner
- if src.right*src.top>0 then begin
- r1:=rect(w2-src.right,0,w2,src.top);
- OffsetRect(r1,dst.left,dst.top);
- r2:=rect(x+w-src.right,y,x+w,src.top+y);
- StretchBlt(dc,r1.left,r1.top,r1.right-r1.left,r1.bottom-r1.top,
- bmp.Canvas.Handle ,r2.left,r2.top,r2.right-r2.left,r2.bottom-r2.top,SrcCopy);
- end;
- //left
- if src.left>0 then begin
- r1:=rect(0,src.top,src.left,h2-src.bottom);
- OffsetRect(r1,dst.left,dst.top);
- r2:=rect(x,y+src.top,x+src.left,y+h-src.bottom);
- StretchBlt(dc,r1.left,r1.top,r1.right-r1.left,r1.bottom-r1.top,
- bmp.Canvas.Handle ,r2.left,r2.top,r2.right-r2.left,r2.bottom-r2.top,SrcCopy);
- end;
- //top
- if src.top>0 then begin
- r1:=rect(src.left,0,w2-src.right,src.top);
- OffsetRect(r1,dst.left,dst.top);
- r2:=rect(x+src.left,y,x+w-src.right,y+src.top);
- StretchBlt(dc,r1.left,r1.top,r1.right-r1.left,r1.bottom-r1.top,
- bmp.Canvas.Handle ,r2.left,r2.top,r2.right-r2.left,r2.bottom-r2.top,SrcCopy);
- end;
- //right-bottom-corner
- if src.right*src.bottom>0 then begin
- r1:=rect(w2-src.right,h2-src.bottom,w2,h2);
- OffsetRect(r1,dst.left,dst.top);
- r2:=rect(x+w-src.right,y+h-src.bottom,x+w,y+h);
- StretchBlt(dc,r1.left,r1.top,r1.right-r1.left,r1.bottom-r1.top,
- bmp.Canvas.Handle ,r2.left,r2.top,r2.right-r2.left,r2.bottom-r2.top,SrcCopy);
- end;
- //right
- if src.right>0 then begin
- r1:=rect(w2-src.right,src.top,w2,h2-src.bottom);
- OffsetRect(r1,dst.left,dst.top);
- r2:=rect(x+w-src.right,y+src.top,x+w,y+h-src.bottom);
- StretchBlt(dc,r1.left,r1.top,r1.right-r1.left,r1.bottom-r1.top,
- bmp.Canvas.Handle ,r2.left,r2.top,r2.right-r2.left,r2.bottom-r2.top,SrcCopy);
- end;
- //bottom
- if src.bottom>0 then begin
- r1:=rect(src.left,h2-src.bottom,w2-src.right,h2);
- OffsetRect(r1,dst.left,dst.top);
- r2:=rect(x+src.left,y+h-src.bottom,x+w-src.right,y+h);
- StretchBlt(dc,r1.left,r1.top,r1.right-r1.left,r1.bottom-r1.top,
- bmp.Canvas.Handle ,r2.left,r2.top,r2.right-r2.left,r2.bottom-r2.top,SrcCopy);
- end;
- end;
- function GetThumbMap(Dst:Trect;Bmp:TBitmap;Src:TRect;I,N:integer;
- Tile:integer=0;Spliter:integer=0):Tbitmap;
- var r1,r2:Trect;
- x,y,w,h,w2,h2:integer;
- color,c1,c2 :Tcolor;
- temp: Tbitmap;
- b1,b2:boolean;
- begin
- w:=bmp.width div n;
- h:=bmp.height;
- x:=(i-1)*w;
- y:=0;
- temp:=Tbitmap.create;
- w2:=dst.right-dst.left;
- h2:=dst.bottom-dst.top;
- temp.width:=w2;
- temp.height:=h2;
- SetStretchBltMode(temp.canvas.handle,STRETCH_DELETESCANS);
- { b1:= w2<(src.left+src.right);
- b2:= h2<(src.top+src.bottom);
- if b1 then begin
- src.left:=0; src.right:=0;
- end;
- if b2 then begin
- src.top:=0; src.bottom:=0;
- end;}
- if Spliter=0 then begin//vscrollbar
- //top
- if src.top>0 then begin
- r1:=rect(0,0,w2,src.top);
- r2:=rect(x,y,x+w,y+src.top);
- temp.canvas.copyrect(r1,bmp.canvas,r2);
- end;
- //Center
- r1:=rect(0,src.top,w2,h2-src.bottom);
- r2:=rect(x,y+src.top,x+w,y+h-src.bottom);
- temp.canvas.copyrect(r1,bmp.canvas,r2);
- //bottom
- if src.bottom>0 then begin
- r1:=rect(0,h2-src.bottom,w2,h2);
- r2:=rect(x,y+h-src.bottom,x+w,y+h);
- temp.canvas.copyrect(r1,bmp.canvas,r2);
- end;
- end;
- result:=temp;
- end;
- {function SBCustomDraw(SB:Tskinscrollbar;PDraw:pNMCSBCUSTOMDRAW):integer;
- var rc,r1:Trect;
- OldBrush,Brush: HBrush;
- i:integer;
- procedure DrawArrow(bmp:Tbitmap;j,N:integer);
- var temp:Tbitmap;
- w,h,x:integer;
- begin
- w:=bmp.width div n;
- h:=bmp.height;
- x:=(j-1)*w;
- r1:= rect(x,0,x+w,h);
- StretchBlt(pDraw^.hdc,rc.left,rc.top,rc.right-rc.left,rc.bottom-rc.top,
- bmp.canvas.handle, r1.left, r1.top, w,h, SRCCOPY);
- end;
- procedure DrawBar(bmp:Tbitmap;rt:Trect;j,N:integer);
- var temp:Tbitmap;
- w,h,x:integer;
- begin
- w:=bmp.width div n;
- h:=bmp.height;
- x:=(j-1)*w;
- if(pDraw^.nBar = SB_HORZ) then begin
- if (rc.right-rc.left)<(rt.left+rt.right+2) then begin
- r1:= rect(x,0,x+w,h);
- StretchBlt(pDraw^.hdc,rc.left,rc.top,rc.right-rc.left, rc.bottom-rc.top,
- bmp.canvas.handle, r1.left, r1.top, w,h, SRCCOPY);
- end else begin
- StretchBlt(pDraw^.hdc,rc.left,rc.top,rt.left, rc.bottom-rc.top,
- bmp.canvas.handle, x, 0,rt.left,h, SRCCOPY);
- StretchBlt(pDraw^.hdc,rc.left+rt.left,rc.top,rc.right-rc.left-rt.right-rt.left, rc.bottom-rc.top,
- bmp.canvas.handle, x+rt.left, 0,w-rt.left-rt.right,h, SRCCOPY);
- StretchBlt(pDraw^.hdc,rc.right-rt.right,rc.top,rt.right, rc.bottom-rc.top,
- bmp.canvas.handle, w+x-rt.right, 0,rt.right,h, SRCCOPY);
- end;
- end else begin
- if (rc.bottom-rc.top)<(rt.top+rt.bottom+2) then begin
- r1:= rect(x,0,x+w,h);
- StretchBlt(pDraw^.hdc,rc.left,rc.top,rc.right-rc.left, rc.bottom-rc.top,
- bmp.canvas.handle, r1.left, r1.top, w,h, SRCCOPY);
- end else begin
- StretchBlt(pDraw^.hdc,rc.left,rc.top,rc.right-rc.left, rt.top,
- bmp.canvas.handle, x, 0,w,rt.top, SRCCOPY);
- StretchBlt(pDraw^.hdc,rc.left,rc.top+rt.top,rc.right-rc.left, rc.bottom-rc.top-rt.top-rt.bottom,
- bmp.canvas.handle, x, rt.top,w,h-rt.top-rt.bottom, SRCCOPY);
- StretchBlt(pDraw^.hdc,rc.left,rc.bottom-rt.bottom,rc.right-rc.left, rt.bottom,
- bmp.canvas.handle, x, h-rt.bottom,w,rt.bottom, SRCCOPY);
- end;
- end;
- end;
- begin
- if(pDraw^.dwDrawStage = CDDS_PREPAINT) then begin
- result := CDRF_SKIPDEFAULT;
- exit;
- end;
- //the sizing gripper in the bottom-right corner
- if(pDraw^.nBar = SB_BOTH) then begin
- Brush := CreateSolidBrush(sb.fsd.colors[csButtonFace]);
- fillrect(pdraw^.hdc,pDraw^.rc,brush);
- DeleteObject(Brush);
- result:= CDRF_SKIPDEFAULT;
- end else if(pDraw^.nBar = SB_HORZ) then begin
- if(pDraw^.uState=CDIS_HOT) then i:=2
- else if(pDraw^.uState=CDIS_SELECTED) then i:=1
- else i:=0;
- rc:=pDraw^.rc;
- rc.Bottom:=rc.top+16;
- case pdraw^.uItem of
- SB_LINELEFT:begin
- inc(i,1);
- Drawarrow(sb.fsd.SArrow.map,i,23);
- end;
- SB_LINERIGHT:begin
- inc(i,5);
- Drawarrow(sb.fsd.SArrow.map,i,23);
- end;
- SB_PAGELEFT: begin
- // DrawRect2(pDraw^.hdc,pDraw^.rc,sb.fsd.HBar.map,
- // sb.fsd.HBar.r,1,4,sb.fsd.Hbar.trans,sb.fsd.Hbar.tile);
- // DrawBar(sb.fsd.HBar.map,sb.fsd.HBar.r,1,4);
- // skinaddlog(format('PAGELEFT %1d %1d',[rc.right,rc.left]));
- end;
- SB_PAGERIGHT:begin
- DrawBar(sb.fsd.HBar.map,sb.fsd.HBar.r,1,4);
- // DrawRect2(pDraw^.hdc,pDraw^.rc,sb.fsd.HBar.map,
- // sb.fsd.HBar.r,1,4,sb.fsd.Hbar.trans,sb.fsd.Hbar.tile);
- // skinaddlog(format('PAGERight %1d %1d',[rc.right,rc.left]));
- end;
- SB_THUMBTRACK:begin
- rc.Bottom:=rc.top+16;
- inc(i,1);
- DrawRect2(pDraw^.hdc,rc,sb.fsd.hSlider.map,
- sb.fsd.hslider.r,i,sb.fsd.hslider.frame,sb.fsd.hslider.trans);
- // DrawBar(sb.fsd.hslider.map,sb.fsd.hslider.r,i,sb.fsd.hslider.frame);
- end;
- end;
- result:=CDRF_SKIPDEFAULT;
- end else if(pDraw^.nBar=SB_VERT) then begin
- if(pDraw^.uState=CDIS_HOT) then i:=2
- else if(pDraw^.uState=CDIS_SELECTED) then i:=1
- else i:=0;
- rc:=pDraw^.rc;
- rc.right:=rc.left+16;
- case pdraw^.uItem of
- SB_LINEUP:begin
- inc(i,9);
- Drawarrow(sb.fsd.SArrow.map,i,23);
- end;
- SB_LINEDOWN:begin
- inc(i,13);
- Drawarrow(sb.fsd.SArrow.map,i,23);
- end;
- SB_PAGEUP:begin
- // DrawRect2(pDraw^.hdc,pDraw^.rc,sb.fsd.VBar.map,
- // sb.fsd.VBar.r,1,4,sb.fsd.Vbar.trans,sb.fsd.Vbar.tile);
- // DrawBar(sb.fsd.VBar.map,sb.fsd.VBar.r,1,4);
- end;
- SB_PAGEDOWN:begin
- DrawBar(sb.fsd.VBar.map,sb.fsd.VBar.r,1,4);
- end;
- SB_THUMBTRACK:begin
- inc(i,1);
- rc.right:=rc.left+16;
- DrawRect2(pDraw^.hdc,rc,sb.fsd.VSlider.map,
- sb.fsd.Vslider.r,i,sb.fsd.vslider.frame,sb.fsd.vslider.trans);
- // DrawBar(sb.fsd.vslider.map,sb.fsd.vslider.r,i,sb.fsd.vslider.frame);
- end;
- end;
- result:= CDRF_SKIPDEFAULT;
- end else begin
- result:= CDRF_DODEFAULT;
- end;
- end;}
- function Max(const A, B: Integer): Integer;
- begin
- if A > B then
- Result := A
- else
- Result := B;
- end;
- function Min(const A, B: Integer): Integer;
- begin
- if A < B then
- Result := A
- else
- Result := B;
- end;
- procedure Bitmapdraw(DC:HDC;Dst:Trect;Bmp:TBitmap);
- var OldPalette: HPalette;
- RestorePalette: Boolean;
- begin
- OldPalette := 0;
- RestorePalette := False;
- TACBitmap(bmp).PaletteNeeded;
- if bmp.Palette <> 0 then
- begin
- OldPalette := SelectPalette(dc, bmp.Palette, True);
- RealizePalette(dc);
- RestorePalette := True;
- end;
- BitBlt(dc,dst.left,dst.top,dst.right-dst.left,dst.bottom-dst.top,
- bmp.Canvas.Handle ,0 ,0 ,SrcCopy);
- if RestorePalette then
- SelectPalette(Dc, OldPalette, True);
- end;
- procedure DrawRect1(DC:HDC;Dst:Trect;Bmp:TBitmap;I,N:integer;Trans:integer=0);
- var r1,r2:Trect;
- x,w,h,w1:integer;
- color,c1,c2 :Tcolor;
- temp : Tbitmap;
- begin
- if (dst.right<dst.left) or (dst.bottom<dst.top) then exit;
- temp:=Tbitmap.create;
- w:=dst.right-dst.left;
- h:=dst.bottom-dst.top;
- temp.width:=w;
- temp.height:=h;
- w1:=bmp.width div n;
- x:=(i-1)*w1;
- temp.canvas.copyrect(rect(0,0,w,h),bmp.canvas,rect(x,0,x+w1,bmp.height));
- if trans=0 then
- BitBlt(dc,dst.left,dst.top,dst.right-dst.left,dst.bottom-dst.top,
- temp.Canvas.Handle ,0 ,0 ,SrcCopy)
- else DrawTranmap(DC,dst,temp);
- temp.free;
- end;
- procedure DrawRect3(DC:HDC;Dst:Trect;Bmp:TBitmap;I,N:integer;Trans:integer=0);
- var r1,r2:Trect;
- x,y,w,h,w1:integer;
- color,c1,c2 :Tcolor;
- temp : Tbitmap;
- begin
- if (dst.right<dst.left) or (dst.bottom<dst.top) then exit;
- temp:=Tbitmap.create;
- w := bmp.width div n;
- h := bmp.Height;
- temp.width:=w;
- temp.height:=h;
- x:=(i-1)*w;
- BitBlt(temp.Canvas.handle,0,0,w,h,
- bmp.Canvas.Handle ,x,0 ,SrcCopy);
- x:= dst.Left+(dst.right-dst.Left-w) div 2;
- y:= dst.top+(dst.bottom-dst.top-h) div 2;
- if trans=0 then
- BitBlt(dc,x,y,w,h,
- temp.Canvas.Handle ,0 ,0 ,SrcCopy)
- else DrawTranmap(DC,rect(x,y,x+w,y+h),temp);
- temp.free;
- end;
- procedure DrawRectH(DC:HDC;Dst:Trect;Bmp:TBitmap;Src:TRect;I,N:integer;
- Tile:integer=0;Spliter:integer=0);
- var x,y,w,h,x1,y1:integer;
- begin
- if Spliter=0 then begin
- w:=bmp.width div n;
- h:=bmp.height;
- x:=(i-1)*w;
- y:=0;
- end else begin
- w:=bmp.width ;
- h:=bmp.height div N;
- y:=(i-1)*h;
- x:=0;
- end;
- // if (dst.Bottom-dst.Top)>h then
- // dst.Top:=dst.Top+(dst.Bottom-dst.Top-h) div 2;
- if (dst.Right-dst.Left)<w then begin
- StretchBlt(dc,dst.left,dst.top,dst.right-dst.left,dst.Bottom-dst.Top,
- bmp.canvas.handle,x,y,x+w,y+h,SRCCOPY);
- end else begin
- StretchBlt(dc,dst.Left,dst.Top,src.Left,dst.Bottom-dst.Top,
- bmp.canvas.handle,x,y,src.Left,h,SRCCOPY);
- StretchBlt(dc,dst.Left+src.Left,dst.Top,dst.Right-dst.Left-src.Left-src.Right,dst.Bottom-dst.Top,
- bmp.canvas.handle,x+src.Left,y,w-src.Left-src.Right,h,SRCCOPY);
- StretchBlt(dc,dst.Right-src.Right,dst.Top,src.Right,dst.Bottom-dst.Top,
- bmp.canvas.handle,x+w-src.Right,y,src.Right,h,SRCCOPY);
- end;
- end;
- procedure DrawRectV(DC:HDC;Dst:Trect;Bmp:TBitmap;Src:TRect;I,N:integer;
- Tile:integer=0;Spliter:integer=0);
- var x,y,w,h:integer;
- begin
- if Spliter=0 then begin
- w:=bmp.width div n;
- h:=bmp.height;
- x:=(i-1)*w;
- y:=0;
- end else begin
- w:=bmp.width ;
- h:=bmp.height div N;
- y:=(i-1)*h;
- x:=0;
- end;
- // if (dst.Right-dst.left)>w then
- // dst.Left:=dst.Left+(dst.Right-dst.Left-w) div 2;
- if (dst.Bottom-dst.Top)<h then begin
- StretchBlt(dc,dst.left,dst.top,dst.Right-dst.Left,dst.Bottom-dst.Top,
- bmp.canvas.handle,x,y,x+w,y+h,SRCCOPY);
- end else begin
- StretchBlt(dc,dst.Left,dst.Top,dst.Right-dst.Left,src.Top,
- bmp.canvas.handle,x,y,w,src.Top,SRCCOPY);
- StretchBlt(dc,dst.Left,dst.Top+src.Top,dst.Right-dst.Left,dst.Bottom-dst.Top-src.Top-src.Bottom,
- bmp.canvas.handle,x,y+src.Top,w,h-src.Top-src.Bottom,SRCCOPY);
- StretchBlt(dc,dst.Left,dst.Bottom-src.Bottom,dst.Right-dst.Left,src.Bottom,
- bmp.canvas.handle,x,y+h-src.Bottom,w,src.Bottom,SRCCOPY);
- end;
- end;
- procedure DrawParentImage( Control: TControl; DC: HDC; InvalidateParent: Boolean = False );
- var
- SaveIndex: Integer;
- P: TPoint;
- r:Trect;
- begin
- if Control.Parent = nil then
- Exit;
- r:=control.ClientRect;
- SaveIndex := SaveDC( DC );
- GetViewportOrgEx( DC, P );
- SetViewportOrgEx( DC, P.X - Control.Left, P.Y - Control.Top, nil );
- offsetrect(r,control.Left,control.Top);
- IntersectClipRect( DC, r.Left, r.Top, r.Right,r.Bottom);
- // IntersectClipRect( DC, 0, 0, Control.Parent.ClientWidth, Control.Parent.ClientHeight );
- if not ( csDesigning in Control.ComponentState ) then
- begin
- Control.Parent.Perform( wm_EraseBkgnd, DC, 0 );
- Control.Parent.Perform( wm_Paint, DC, 0 );
- end else begin
- try
- Control.Parent.Perform( wm_EraseBkgnd, DC, 0 );
- Control.Parent.Perform( wm_Paint, DC, 0 );
- except
- end;
- end;
- RestoreDC( DC, SaveIndex );
- { if InvalidateParent then begin
- if not ( Control.Parent is TCustomControl ) and
- not ( Control.Parent is TCustomForm ) and
- not ( csDesigning in Control.ComponentState ) then
- begin
- Control.Parent.Invalidate;
- end;
- end; }
- end;
- {procedure DrawTranmap(DC:HDC;Dst:Trect;temp:TBitmap;transcolor:Tcolor=clFuchsia);
- var color,c1,c2 :Tcolor;
- mask : Tbitmap;
- w,h:integer;
- begin
- if (dst.right<dst.left) or (dst.bottom<dst.top) then exit;
- c1:=SetBkColor(dc,clwhite);
- c2:=SetTextColor(dc,clblack);
- mask:=Tbitmap.create;
- mask.assign(temp);
- mask.mask(transcolor);
- // mask.mask(temp.Canvas.Pixels[0, 0]);
- w:=dst.right-dst.left;
- h:=dst.bottom-dst.top;
- BitBlt(dc,dst.left ,dst.top,w,h,
- temp.Canvas.Handle ,0 ,0 ,SrcInvert);
- BitBlt(dc,dst.left ,dst.top,w,h,
- mask.Canvas.Handle ,0 ,0 ,SrcAnd);
- BitBlt(dc,dst.left ,dst.top,w,h,
- temp.Canvas.Handle ,0 ,0 ,SrcInvert);
- SetBkColor(dc,c1);
- SetTextColor(dc,c2);
- mask.free;
- end;}
- procedure DrawTranmap(DC:HDC;Dst:Trect;temp:TBitmap;transcolor:Tcolor=clFuchsia);
- var color,c1,c2 :Tcolor;
- mask : Tbitmap;
- w,h:integer;
- begin
- if (dst.right<dst.left) or (dst.bottom<dst.top) then exit;
- mask:=Tbitmap.create;
- mask.assign(temp);
- mask.mask(transcolor);
- try
- if (Win32Platform = VER_PLATFORM_WIN32_NT) then begin
- MaskBlt(DC, Dst.left, Dst.top, Dst.Right-dst.left, Dst.Bottom-dst.top,
- temp.Canvas.handle,0,0,mask.handle,0,0, MakeRop4($00AA0029, SrcCopy));
- end else begin
- c1:=SetBkColor(dc,clwhite);
- c2:=SetTextColor(dc,clblack);
- w:=dst.right-dst.left;
- h:=dst.bottom-dst.top;
- BitBlt(dc,dst.left ,dst.top,w,h,
- temp.Canvas.Handle ,0 ,0 ,SrcInvert);
- BitBlt(dc,dst.left ,dst.top,w,h,
- mask.Canvas.Handle ,0 ,0 ,SrcAnd);
- BitBlt(dc,dst.left ,dst.top,w,h,
- temp.Canvas.Handle ,0 ,0 ,SrcInvert);
- SetBkColor(dc,c1);
- SetTextColor(dc,c2);
- end;
- finally
- mask.Free;
- end;
- end;
- procedure SkinAddLog(msg:string);
- begin
- {$IFDEF test}
- if msg='' then exit;
- if logstring<>nil then Logstring.add(msg);
- {$ENDIF}
- end;
- {procedure SetProperty(control: TObject;aprop,value:string);
- var PropInfo:PPropInfo;
- begin
- if control<>nil then begin
- PropInfo:=GetPropInfo(control,aprop);
- if PropInfo<>nil then begin
- if propinfo^.PropType^.Kind= tkEnumeration then
- SetEnumProp(control,PropInfo,value);
- end;
- end;
- end;}
- initialization
- bg:=Tbitmap.create;
- SetStretchBltMode(bg.canvas.handle,STRETCH_DELETESCANS);
- Logstring :=Tstringlist.create;
- finalization
- {$IFDEF test}
- logstring.savetofile(ExtractFilePath(ParamStr(0))+
- ExtractFileName(ParamStr(0))+'.txt');
- {$ENDIF}
- Logstring.free;
- bg.free;
- bg:=nil;
- end.