2015-05-23 12:40:49 -04:00
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
// DirectDraw Surface Stack implementation
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
|
2013-08-25 12:38:13 -04:00
|
|
|
#define _CRT_SECURE_NO_WARNINGS
|
|
|
|
|
2012-12-24 10:20:23 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "dxwnd.h"
|
2013-01-04 10:30:38 -05:00
|
|
|
#include "dxwcore.hpp"
|
2012-12-24 10:20:23 -05:00
|
|
|
|
2015-05-23 12:40:49 -04:00
|
|
|
//#define DXW_WINPROC_STACK_TRACING
|
2013-07-21 12:38:09 -04:00
|
|
|
#define MAXWNDHSTACK 256
|
2012-12-24 10:20:23 -05:00
|
|
|
|
2015-05-23 12:40:49 -04:00
|
|
|
dxwWStack::dxwWStack()
|
2012-12-24 10:20:23 -05:00
|
|
|
{
|
2015-05-23 12:40:49 -04:00
|
|
|
WhndTOS = 0;
|
2014-05-20 12:39:14 -04:00
|
|
|
WhndSize = MAXWNDHSTACK;
|
|
|
|
WhndStack = (wndstack_entry *)malloc(WhndSize * sizeof(wndstack_entry));
|
2012-12-24 10:20:23 -05:00
|
|
|
}
|
|
|
|
|
2015-05-23 12:40:49 -04:00
|
|
|
dxwWStack::~dxwWStack()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void dxwWStack::Put(HWND hwnd, WNDPROC wndproc, int w, int h)
|
2012-12-24 10:20:23 -05:00
|
|
|
{
|
|
|
|
int StackIdx;
|
2014-05-20 12:39:14 -04:00
|
|
|
|
2014-07-13 12:39:33 -04:00
|
|
|
// add extra space when necessary, in chunks of MAXWNDHSTACK entries
|
2014-05-20 12:39:14 -04:00
|
|
|
if(WhndTOS == WhndSize){
|
|
|
|
WhndSize += MAXWNDHSTACK;
|
|
|
|
WhndStack = (wndstack_entry *)realloc(WhndStack, WhndSize * sizeof(wndstack_entry));
|
|
|
|
}
|
2012-12-24 10:20:23 -05:00
|
|
|
// wndproc values of 0xFFFFxxxx type seems to be error codes rather than valid callback addresses ....
|
2013-09-22 12:38:19 -04:00
|
|
|
// v2.02.36 using CallWindowProc you can pass WinProc handles, so you don't need to eliminate them!
|
|
|
|
//if (((DWORD)wndproc & 0xFFFF0000) == 0xFFFF0000) return;
|
2013-12-22 11:38:36 -05:00
|
|
|
//OutTraceDW("DEBUG: WNDPROC STACK push hwnd=%x, wndproc=%x\n", hwnd, wndproc);
|
2012-12-24 10:20:23 -05:00
|
|
|
// try update first...
|
|
|
|
for(StackIdx=0; StackIdx<WhndTOS; StackIdx++)
|
|
|
|
if (WhndStack[StackIdx].hwnd==hwnd) {
|
2014-07-13 12:39:33 -04:00
|
|
|
// update only valid fields
|
|
|
|
if(wndproc) WhndStack[StackIdx].wndproc=wndproc;
|
|
|
|
if(w) WhndStack[StackIdx].w=w;
|
|
|
|
if(h) WhndStack[StackIdx].h=h;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
WhndStack[WhndTOS].hwnd=hwnd;
|
|
|
|
// initialize ...
|
|
|
|
WhndStack[WhndTOS].wndproc=NULL;
|
|
|
|
WhndStack[WhndTOS].w=0;
|
|
|
|
WhndStack[WhndTOS].h=0;
|
|
|
|
// update only valid fields
|
|
|
|
if(wndproc) WhndStack[WhndTOS].wndproc=wndproc;
|
|
|
|
if(w) WhndStack[WhndTOS].w=w;
|
|
|
|
if(h) WhndStack[WhndTOS].h=h;
|
|
|
|
// increment TOS.
|
|
|
|
WhndTOS++;
|
|
|
|
}
|
|
|
|
|
2015-05-23 12:40:49 -04:00
|
|
|
void dxwWStack::PutProc(HWND hwnd, WNDPROC wndproc)
|
2014-07-13 12:39:33 -04:00
|
|
|
{
|
|
|
|
int StackIdx;
|
|
|
|
|
|
|
|
// add extra space when necessary, in chunks of MAXWNDHSTACK entries
|
|
|
|
if(WhndTOS == WhndSize){
|
|
|
|
WhndSize += MAXWNDHSTACK;
|
|
|
|
WhndStack = (wndstack_entry *)realloc(WhndStack, WhndSize * sizeof(wndstack_entry));
|
|
|
|
}
|
|
|
|
// wndproc values of 0xFFFFxxxx type seems to be error codes rather than valid callback addresses ....
|
|
|
|
// v2.02.36 using CallWindowProc you can pass WinProc handles, so you don't need to eliminate them!
|
|
|
|
//if (((DWORD)wndproc & 0xFFFF0000) == 0xFFFF0000) return;
|
|
|
|
//OutTraceDW("DEBUG: WNDPROC STACK push hwnd=%x, wndproc=%x\n", hwnd, wndproc);
|
|
|
|
// try update first...
|
|
|
|
for(StackIdx=0; StackIdx<WhndTOS; StackIdx++)
|
|
|
|
if (WhndStack[StackIdx].hwnd==hwnd) {
|
|
|
|
// update only valid fields
|
2012-12-24 10:20:23 -05:00
|
|
|
WhndStack[StackIdx].wndproc=wndproc;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
WhndStack[WhndTOS].hwnd=hwnd;
|
|
|
|
WhndStack[WhndTOS].wndproc=wndproc;
|
2014-07-13 12:39:33 -04:00
|
|
|
WhndStack[WhndTOS].w=0; // unknown
|
|
|
|
WhndStack[WhndTOS].h=0; // unknown
|
|
|
|
// increment TOS.
|
|
|
|
WhndTOS++;
|
|
|
|
}
|
|
|
|
|
2015-05-23 12:40:49 -04:00
|
|
|
void dxwWStack::PutSize(HWND hwnd, int w, int h)
|
2014-07-13 12:39:33 -04:00
|
|
|
{
|
|
|
|
int StackIdx;
|
|
|
|
|
|
|
|
// add extra space when necessary, in chunks of MAXWNDHSTACK entries
|
|
|
|
if(WhndTOS == WhndSize){
|
|
|
|
WhndSize += MAXWNDHSTACK;
|
|
|
|
WhndStack = (wndstack_entry *)realloc(WhndStack, WhndSize * sizeof(wndstack_entry));
|
|
|
|
}
|
|
|
|
// try update first...
|
|
|
|
for(StackIdx=0; StackIdx<WhndTOS; StackIdx++)
|
|
|
|
if (WhndStack[StackIdx].hwnd==hwnd) {
|
|
|
|
// update only valid fields
|
|
|
|
WhndStack[StackIdx].w=w;
|
|
|
|
WhndStack[StackIdx].h=h;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
WhndStack[WhndTOS].hwnd=hwnd;
|
|
|
|
WhndStack[WhndTOS].wndproc=NULL; // unknown
|
|
|
|
WhndStack[WhndTOS].w=w;
|
|
|
|
WhndStack[WhndTOS].h=h;
|
|
|
|
// increment TOS.
|
2012-12-24 10:20:23 -05:00
|
|
|
WhndTOS++;
|
|
|
|
}
|
|
|
|
|
2015-05-23 12:40:49 -04:00
|
|
|
BOOL dxwWStack::GetSize(HWND hwnd, int *w, int *h)
|
2014-07-13 12:39:33 -04:00
|
|
|
{
|
|
|
|
int StackIdx;
|
|
|
|
for(StackIdx=0; StackIdx<WhndTOS; StackIdx++) if (WhndStack[StackIdx].hwnd==hwnd) {
|
|
|
|
//OutTraceDW("DEBUG: WNDPROC STACK pop hwnd=%x, wndproc=%x\n", hwnd, WhndStack[StackIdx].wndproc);
|
|
|
|
if((WhndStack[StackIdx].w==0) || (WhndStack[StackIdx].h==0)) return FALSE;
|
|
|
|
if(w) *w=WhndStack[StackIdx].w;
|
|
|
|
if(h) *h=WhndStack[StackIdx].h;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
//OutTraceDW("DEBUG: WNDPROC STACK pop hwnd=%x, wndproc=NULL\n", hwnd);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-05-23 12:40:49 -04:00
|
|
|
WNDPROC dxwWStack::GetProc(HWND hwnd)
|
2012-12-24 10:20:23 -05:00
|
|
|
{
|
|
|
|
int StackIdx;
|
2015-05-23 12:40:49 -04:00
|
|
|
//if(dxw.dwFlags6 & USEDEFWINDOWPROC) return pDefWindowProcA;
|
2014-10-30 12:39:54 -04:00
|
|
|
//OutTraceDW("DEBUG: WNDPROC STACK pop hwnd=%x TOS=%d\n", hwnd, WhndTOS);
|
|
|
|
for(StackIdx=0; StackIdx<WhndTOS; StackIdx++) {
|
|
|
|
if (WhndStack[StackIdx].hwnd==hwnd) {
|
2015-05-23 12:40:49 -04:00
|
|
|
//OutTraceDW("DEBUG: WNDPROC STACK pop hwnd=%x, wndproc=%x\n", hwnd, WhndStack[StackIdx].wndproc);
|
|
|
|
return WhndStack[StackIdx].wndproc; // either a good value, or NULL
|
|
|
|
}
|
2014-10-30 12:39:54 -04:00
|
|
|
}
|
2013-12-22 11:38:36 -05:00
|
|
|
//OutTraceDW("DEBUG: WNDPROC STACK pop hwnd=%x, wndproc=NULL\n", hwnd);
|
2012-12-24 10:20:23 -05:00
|
|
|
return NULL;
|
|
|
|
}
|