123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672 |
- #include <precomp.h>
- #include "virtualwnd.h"
- #include <tataki/region/api_region.h>
- #include <api/wnd/usermsg.h>
- #include <api/wnd/accessible.h>
- VirtualWnd::VirtualWnd()
- {
- virtualX = virtualY = virtualH = virtualW = 0;
- bypassvirtual = 0;
- focus = 0;
- resizecount = 0;
- lastratio = 1;
- }
- VirtualWnd::~VirtualWnd()
- {}
- int VirtualWnd::init(ifc_window *parWnd, int nochild)
- {
- if (!bypassvirtual)
- setParent(parWnd);
- return (VIRTUALWND_PARENT::init(parWnd, nochild));
- }
- int VirtualWnd::init(OSMODULEHANDLE moduleHandle, OSWINDOWHANDLE parent, int nochild)
- {
- if (!bypassvirtual)
- {
- ASSERTPR(getParent() != NULL, "Virtual window created without specifying BaseWnd parent");
- if (getStartHidden())
- this_visible = 0;
- else
- this_visible = 1;
- onInit();
- onPostOnInit();
- if (isVisible())
- onSetVisible(1);
- return 1;
- }
- else
- return VIRTUALWND_PARENT::init(moduleHandle, parent, nochild);
- }
- OSWINDOWHANDLE VirtualWnd::getOsWindowHandle()
- {
- // ASSERTPR(getParent() != NULL, "Virtual window used as base parent !");
- if (!bypassvirtual)
- {
- if (!getParent())
- return INVALIDOSWINDOWHANDLE;
- return getParent()->getOsWindowHandle();
- }
- else
- {
- return VIRTUALWND_PARENT::getOsWindowHandle();
- }
- }
- OSMODULEHANDLE VirtualWnd::getOsModuleHandle()
- {
- if (!bypassvirtual)
- {
- if (!getParent())
- return INVALIDOSMODULEHANDLE;
- return getParent()->getOsModuleHandle();
- }
- else
- return VIRTUALWND_PARENT::getOsModuleHandle();
- }
- void VirtualWnd::resize(RECT *r, int wantcb)
- {
- if (!bypassvirtual)
- {
- resize(r->left, r->top, r->right - r->left, r->bottom - r->top, wantcb);
- }
- else
- {
- VIRTUALWND_PARENT::resize( r, wantcb );
- //virtualX = rx;
- //virtualY = ry;
- //virtualW = rwidth;
- //virtualH = rheight;
- }
- }
- // fg> the resizecount > 1 is a hack, it should be 0 but i need more time to fix this thing, at least this way we don't lose the optim
- void VirtualWnd::resize(int x, int y, int w, int h, int wantcb)
- {
- if (!bypassvirtual)
- {
- if (x == NOCHANGE)
- x = virtualX;
- if (y == NOCHANGE)
- y = virtualY;
- if (w == NOCHANGE)
- w = virtualW;
- if (h == NOCHANGE)
- h = virtualH;
- double thisratio = getRenderRatio();
- if (resizecount > 1 && virtualX == x && virtualY == y && virtualW == w && virtualH == h && lastratio == thisratio)
- return ;
- lastratio = thisratio;
- if (isVisible())
- {
- RECT r;
- getNonClientRect(&r);
- invalidateRect(&r);
- }
- virtualX = x;
- virtualY = y;
- virtualW = w;
- virtualH = h;
- if (isVisible())
- {
- RECT r;
- getNonClientRect(&r);
- invalidateRect(&r);
- }
- setRSize(x, y, w, h);
- if (wantcb && isPostOnInit())
- {
- resizecount = MIN(resizecount + 1, 2);
- onResize();
- }
- }
- else
- {
- VIRTUALWND_PARENT::resize( x, y, w, h, wantcb );
- //virtualX = rx;
- //virtualY = ry;
- //virtualW = rwidth;
- //virtualH = rheight;
- }
- }
- //CUTvoid VirtualWnd::resize(RECT *r) {
- //CUT resize(r->left, r->top, r->right-r->left, r->bottom-r->top);
- //CUT}
- void VirtualWnd::move(int x, int y)
- {
- //DebugStringW( L"VirtualWnd::move( x = %d, y = %d )\n", x, y );
- if (!bypassvirtual)
- {
- if (isVisible())
- {
- RECT r;
- getNonClientRect(&r);
- invalidateRect(&r);
- }
- virtualX = x;
- virtualY = y;
- if (isVisible())
- {
- RECT r;
- getNonClientRect(&r);
- invalidateRect(&r);
- }
- }
- else
- {
- VIRTUALWND_PARENT::move( x, y );
- //virtualX = x;
- //virtualY = y;
- }
- }
- void VirtualWnd::invalidate()
- {
- if (!bypassvirtual)
- {
- if (!getRootParent()) return ;
- RECT r(clientRect());
- getRootParent()->invalidateRectFrom(&r, this);
- // VIRTUALWND_PARENT::invalidate();
- }
- else
- VIRTUALWND_PARENT::invalidate();
- }
- void VirtualWnd::invalidateRect(RECT *r)
- {
- if (!bypassvirtual)
- {
- if (!getRootParent()) return ;
- getRootParent()->invalidateRectFrom(r, this);
- }
- else
- VIRTUALWND_PARENT::invalidateRect(r);
- }
- void VirtualWnd::invalidateRgn(api_region *reg)
- {
- if (!bypassvirtual)
- {
- if (!getRootParent()) return ;
- getRootParent()->invalidateRgnFrom(reg, this);
- }
- else
- VIRTUALWND_PARENT::invalidateRgn(reg);
- }
- void VirtualWnd::validate()
- {
- if (!bypassvirtual)
- {
- if (!getRootParent()) return ;
- RECT r;
- getClientRect(&r);
- getRootParent()->validateRect(&r);
- }
- else
- VIRTUALWND_PARENT::validate();
- }
- void VirtualWnd::validateRect(RECT *r)
- {
- if (!bypassvirtual)
- {
- if (!getRootParent())
- return ;
- getRootParent()->validateRect(r);
- }
- else
- VIRTUALWND_PARENT::validateRect( r );
- }
- void VirtualWnd::validateRgn(api_region *reg)
- {
- if (!bypassvirtual)
- {
- if (!getRootParent()) return ;
- getRootParent()->validateRgn(reg);
- }
- else
- VIRTUALWND_PARENT::validateRgn(reg);
- }
- void VirtualWnd::getClientRect(RECT *rect)
- {
- if (!bypassvirtual)
- {
- // CT:getClientRect behaves differently here for virtual windows
- // so we can use onPaint directly on the destination canvas
- // without using another temporary canvas.
- Wasabi::Std::setRect(rect, virtualX, virtualY, virtualX + virtualW, virtualY + virtualH);
- // rect->left=0; rect->right=virtualW;
- // rect->top=0; rect->bottom=virtualH;
- }
- else
- VIRTUALWND_PARENT::getClientRect(rect);
- }
- void VirtualWnd::getNonClientRect(RECT *rect)
- {
- VirtualWnd::getClientRect(rect);
- }
- void VirtualWnd::getWindowRect(RECT *rect)
- {
- if (!bypassvirtual)
- {
- RECT a;
- getRootParent()->getWindowRect(&a);
- int x = virtualX, y = virtualY, w = virtualW, h = virtualH;
- if (renderRatioActive())
- {
- multRatio(&x, &y);
- multRatio(&w, &h);
- }
- rect->left = a.left + x; rect->right = rect->left + w;
- rect->top = a.top + y; rect->bottom = rect->top + h;
- }
- else
- VIRTUALWND_PARENT::getWindowRect(rect);
- }
- int VirtualWnd::beginCapture()
- {
- if (!bypassvirtual)
- {
- disable_tooltip_til_recapture = 0;
- getRootParent()->setVirtualChildCapture(this);
- return 1;
- }
- else
- return VIRTUALWND_PARENT::beginCapture();
- }
- int VirtualWnd::endCapture()
- {
- if (!bypassvirtual)
- {
- if (getRootParent() == NULL) return 0;
- getRootParent()->setVirtualChildCapture(NULL);
- return 1;
- }
- else
- return VIRTUALWND_PARENT::endCapture();
- }
- int VirtualWnd::getCapture()
- {
- if (!bypassvirtual)
- {
- if (getRootParent() == NULL) return 0;
- return getRootParent()->getVirtualChildCapture() == this;
- }
- else
- return VIRTUALWND_PARENT::getCapture();
- }
- void VirtualWnd::setVirtualChildCapture(BaseWnd *child)
- {
- if (!bypassvirtual)
- {
- getParent()->setVirtualChildCapture(child);
- }
- else
- VIRTUALWND_PARENT::setVirtualChildCapture(child);
- }
- // eek
- void VirtualWnd::repaint()
- {
- if (!bypassvirtual)
- {
- if (!getParent()) return ;
- getParent()->repaint();
- }
- else
- VIRTUALWND_PARENT::repaint();
- }
- /*int VirtualWnd::focusNextSibbling(int dochild) {
- return 1;
- }
-
- int VirtualWnd::focusNextVirtualChild(BaseWnd *child) {
- return 1;
- }*/
- int VirtualWnd::cascadeRepaint(int pack)
- {
- if (!bypassvirtual)
- {
- if (getRootParent())
- {
- RECT r;
- VirtualWnd::getNonClientRect(&r);
- getRootParent()->cascadeRepaintRectFrom(&r, this, pack);
- }
- return 1;
- }
- else
- return VIRTUALWND_PARENT::cascadeRepaint(pack);
- }
- int VirtualWnd::cascadeRepaintRect(RECT *r, int pack)
- {
- if (!bypassvirtual)
- {
- if (getRootParent())
- {
- getRootParent()->cascadeRepaintRectFrom(r, this, pack);
- }
- return 1;
- }
- else
- return VIRTUALWND_PARENT::cascadeRepaintRect(r, pack);
- }
- int VirtualWnd::cascadeRepaintRgn(api_region *r, int pack)
- {
- if (!bypassvirtual)
- {
- if (getRootParent())
- {
- getRootParent()->cascadeRepaintRgnFrom(r, this, pack);
- }
- return 1;
- }
- else
- return VIRTUALWND_PARENT::cascadeRepaintRgn(r, pack);
- }
- /*api_window *VirtualWnd::getWindowBehindMyself(int x, int y) {
- RECT r;
- if (!bypassvirtual) {
- if (!getParent()) return NULL;
- int n = getParent()->getNumVirtuals();
-
- api_window *c = NULL;
-
- for (int i=n-1;i>=0;i++) {
- c = getParent()->getVirtualChild(i);
- if (c == this) break;
- }
-
- i--;
- if (i < 0) return getParent();
-
- for (;i>=0; i--) {
- c = getParent()->getVirtualChild(i);
- c->getNonClientRect(&r);
- if (x>=r.left&&x<=r.right&&y>=r.top&&y<=r.bottom)
- return c;
- }
- return getParent();
- } else
- return NULL;
- }*/
- ifc_window *VirtualWnd::rootWndFromPoint(POINT *pt)
- {
- if (!bypassvirtual)
- {
- if (!getParent()) return NULL;
- return getParent()->rootWndFromPoint(pt);
- }
- else
- return VIRTUALWND_PARENT::rootWndFromPoint(pt);
- }
- double VirtualWnd::getRenderRatio()
- {
- if (!bypassvirtual)
- {
- if (!getParent()) return 1.0;
- return getParent()->getRenderRatio();
- }
- else
- return VIRTUALWND_PARENT::getRenderRatio();
- }
- void VirtualWnd::bringToFront()
- {
- if (!bypassvirtual)
- {
- if (!getParent()) return ;
- //getParent()->bringVirtualToFront(this); TODO: FIX!!!
- }
- else
- VIRTUALWND_PARENT::bringToFront();
- }
- void VirtualWnd::bringToBack()
- {
- if (!bypassvirtual)
- {
- if (!getParent()) return ;
- //getParent()->bringVirtualToBack(this); TODO: FIX!!!
- }
- else
- VIRTUALWND_PARENT::bringToBack();
- }
- void VirtualWnd::bringAbove(BaseWnd *o)
- {
- if (!bypassvirtual)
- {
- if (!getParent()) return ;
- getParent()->bringVirtualAbove(this, o);
- } /* else
- VIRTUALWND_PARENT::bringAbove();*/
- }
- void VirtualWnd::bringBelow(BaseWnd *o)
- {
- if (!bypassvirtual)
- {
- if (!getParent()) return ;
- getParent()->bringVirtualBelow(this, o);
- } /* else
- VIRTUALWND_PARENT::bringBelow();*/
- }
- int VirtualWnd::reparent(ifc_window *newparent)
- {
- if (!bypassvirtual)
- {
- if (getParent())
- getParent()->unregisterRootWndChild(this);
- parentWnd = NULL;
- newparent->registerRootWndChild(this);
- onSetParent(newparent);
- newparent->invalidate();
- return 1;
- }
- else
- {
- return VIRTUALWND_PARENT::reparent(newparent);
- }
- }
- int VirtualWnd::setVirtual(int i)
- {
- // ASSERT(!isInited()); // cut
- if (isInited()) return 0;
- bypassvirtual = !i;
- return 1;
- }
- ifc_window *VirtualWnd::getRootParent()
- {
- if (!bypassvirtual)
- {
- if (!getParent()) return NULL;
- ifc_window *t = this;
- while (t->isVirtual())
- {
- if (!t->getParent()) return NULL;
- t = t->getParent();
- }
- return t;
- }
- else
- {
- return VIRTUALWND_PARENT::getRootParent();
- }
- }
- int VirtualWnd::gotFocus()
- {
- if (!bypassvirtual)
- return focus;
- else
- return VIRTUALWND_PARENT::gotFocus();
- }
- int VirtualWnd::onGetFocus()
- {
- if (!bypassvirtual)
- {
- focus = 1;
- getRootParent()->onSetRootFocus(this);
- invalidate();
- Accessible *a = getAccessibleObject();
- if (a != NULL)
- a->onGetFocus();
- }
- else
- return VIRTUALWND_PARENT::onGetFocus();
- return 1;
- }
- int VirtualWnd::onKillFocus()
- {
- if (!bypassvirtual)
- {
- focus = 0;
- invalidate();
- }
- else
- return VIRTUALWND_PARENT::onKillFocus();
- return 1;
- }
- void VirtualWnd::setFocus()
- {
- ifc_window *f = this;
- if (!f->wantFocus() && f->getParent())
- {
- while (f)
- {
- ifc_window *rp = f->getRootParent();
- if (rp == f) rp = f->getParent();
- f = rp;
- if (f && (!f->getParent() || f->wantFocus() || f == WASABI_API_WND->main_getRootWnd()))
- {
- f->setFocus();
- break;
- }
- }
- }
- else
- {
- if (!bypassvirtual)
- {
- if (getParent())
- {
- getParent()->setVirtualChildFocus(this);
- }
- }
- else
- VIRTUALWND_PARENT::setFocus();
- }
- }
- void VirtualWnd::setVirtualChildFocus(ifc_window *child)
- {
- if (!bypassvirtual)
- {
- getParent()->setVirtualChildFocus(child);
- }
- else
- VIRTUALWND_PARENT::setVirtualChildFocus(child);
- }
- int VirtualWnd::onActivate()
- {
- if (bypassvirtual)
- return VIRTUALWND_PARENT::onActivate();
- return 1;
- }
- int VirtualWnd::onDeactivate()
- {
- if (bypassvirtual)
- return VIRTUALWND_PARENT::onDeactivate();
- return 1;
- }
- void VirtualWnd::setAllowDeactivation(int allow)
- {
- ifc_window *w = getDesktopParent();
- if (w != NULL && w != this)
- w->setAllowDeactivation(allow);
- else VIRTUALWND_PARENT::setAllowDeactivation(allow);
- }
- int VirtualWnd::allowDeactivation()
- {
- ifc_window *w = getDesktopParent();
- if (w != NULL && w != this)
- return w->allowDeactivation();
- return VIRTUALWND_PARENT::allowDeactivation();
- }
- /* todo: setCursor
-
- + real childs going invisible should deferedInvalidate their rect on their parent window if it has a virtualCanvas
- */
- // No need for screenToClient/clientToScreen overrides since the virtual's origin is the same as it's parent
|