📄 cwindow.cpp
字号:
{ flags &= ~WStyle_StaysOnTop; //flags &= ~WX11BypassWM; //flags &= ~WType_Popup; //parent = CWINDOW_Main ? CWINDOW_Main->widget.widget : 0; } // #if QT_VERSION < 0x030200 /* QT bug */ hasIcon = icon() != 0; if (hasIcon) p = *icon(); //# endif //qDebug("setTopOnly"); reparent(parentWidget(), flags, pos()); //#if QT_VERSION < 0x030200 if (hasIcon) setIcon(p); //# endif #endif}void MyMainWindow::setSkipTaskbar(bool show){ CWINDOW_change_property(this, _atom_net_wm_state_skip_taskbar, show); /* load_window_state(x11Display(), winId()); if (show) set_window_state(_atom_net_wm_state_skip_taskbar); else clear_window_state(_atom_net_wm_state_skip_taskbar); save_window_state(x11Display(), winId()); */}/*QSize MyMainWindow::sizeHint() const{ //if (fixed) return QSize(width(), height()); //return QFrame::sizeHint();}*/void MyMainWindow::moveSizeGrip(){ CWINDOW *window; QWidget *cont; if (sg == 0) return; window = (CWINDOW *)CWidget::get(this); cont = window->container; sg->move(cont->rect().bottomRight() - sg->rect().bottomRight());}void MyMainWindow::setSizeGrip(bool on){ if (on == (sg != 0)) return; if (!on) { delete sg; sg = 0; } else //if (!parentWidget()) { sg = new QSizeGrip(((CWINDOW *)CWidget::get(this))->container); sg->adjustSize(); moveSizeGrip(); sg->lower(); sg->show(); }}void MyMainWindow::setBorder(int b){ int f; if (b == border || b < 0 || b > 2) return; if (b == BorderNone) { //clearWFlags(Qt::WStyle_NormalBorder); //clearWFlags(Qt::WStyle_DialogBorder); //setWFlags(Qt::WStyle_NoBorderEx); //reparent(parentWidget(), getWFlags(), pos()); f = WStyle_Customize | WStyle_NoBorderEx | getWFlags(); // & 0xffff0000); /*if (f & WStyle_StaysOnTop) f |= WType_Popup; else f &= ~WType_Popup;*/ if (!mdichild) f |= WType_TopLevel; doReparent(parentWidget(), f, pos()); border = b; return; } if (border == BorderNone) doReparent(parentWidget(), (mdichild ? 0 : WType_TopLevel) | (getWFlags() /*& 0xffff0000*/), QPoint(0,0) ); if (b == BorderFixed) { layout()->setResizeMode(QLayout::FreeResize); setMinimumSize(width(), height()); setMaximumSize(width(), height()); } else { setMinimumSize(0, 0); setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); layout()->setResizeMode(QLayout::Minimum); } border = b;}/*bool MyMainWindow::isFixed(void){ QWidget *cont = centralWidget(); return (!(cont->minimumWidth() == 0 && cont->minimumHeight() == 0));}*/void MyMainWindow::paintUnclip(bool on){ if (on) setWFlags(Qt::WPaintUnclipped); else clearWFlags(Qt::WPaintUnclipped);}void MyMainWindow::moveEvent(QMoveEvent *e){ CWIDGET *_object = CWidget::getReal(this); //qDebug("Move"); QMainWindow::moveEvent(e); //qDebug("Move (pos %d %d) (oldPos %d %d)", e->pos().x(), e->pos().y(), e->oldPos().x(), e->oldPos().y()); //qDebug(" (geom %d %d) (fgeom %d %d)", geometry().x(), geometry().y(), frameGeometry().x(), frameGeometry().y()); //qDebug(" Visible = %s Hidden = %s", (isVisible() ? "Yes" : "No"), (isHidden() ? "Yes" : "No")); //qDebug(" Flags = 0x%s State = 0x%s", QString::number(getWFlags(), 16).latin1(), QString::number(getWState(), 16).latin1()); //if (CWIDGET_test_flag(ob, WF_IGNORE_MOVE)) if (!testWFlags(Qt::WStyle_NoBorderEx)) { if (geometry().x() == frameGeometry().x() && geometry().y() == frameGeometry().y()) { //qDebug("...Ignore"); return; } } if (!isHidden()) { THIS->x = x(); THIS->y = y(); //qDebug("moveEvent: x= %d y = %d", x(), y()); } //qDebug("moveEvent %ld %ld isHidden:%s shown:%s ", THIS->x, THIS->y, isHidden() ? "1" : "0", shown ? "1" : "0"); if (shown) GB.Raise(THIS, EVENT_Move, 0);}/*static void post_resize_event(CWINDOW *_object){ qDebug("post resize: %d %d", THIS->w, THIS->h); WINDOW->resize(THIS->w, THIS->h); GB.Unref((void **)&_object);}*/void MyMainWindow::resizeEvent(QResizeEvent *e){ CWINDOW *_object = (CWINDOW *)CWidget::getReal(this); //int w, h; //qDebug("Resize"); //qDebug("Resize %p: %d %d <- %d %d", _object, e->size().width(), e->size().height(), e->oldSize().width(), e->oldSize().height()); QMainWindow::resizeEvent(e); //if (e->size() == e->oldSize()) //{ // qDebug("...Ignore"); // return; //} if (sg) moveSizeGrip(); if (!isHidden()) { updateGeometry(); THIS->w = THIS->container->width(); THIS->h = THIS->container->height(); //qDebug("THIS->w = %d THIS->h = %d", THIS->w, THIS->h); } //qDebug("resizeEvent %ld %ld isHidden:%s shown:%s ", THIS->w, THIS->h, isHidden() ? "1" : "0", shown ? "1" : "0"); //qDebug("THIS->h = %ld THIS->container->height() = %ld height() = %ld", THIS->h, THIS->container->height(), height()); if (shown) { /*w = THIS->w; h = THIS->h;*/ GB.Raise(THIS, EVENT_Resize, 0); /*if (w != THIS->w || h != THIS->h) { GB.Ref(THIS); GB.Post((void (*)())post_resize_event, (long)THIS); }*/ }}void MyMainWindow::keyPressEvent(QKeyEvent *e){ QPushButton *test = 0; if (e->state() == 0 || ( e->state() & Keypad && e->key() == Key_Enter )) { switch (e->key()) { case Key_Enter: case Key_Return: test = defaultButton(); break; case Key_Escape: test = cancelButton(); break; } if (test && CWidget::get(test)) { if (test->isVisible() && test->isEnabled()) { test->animateClick(); return; } /* QObjectList *list = queryList( "QPushButton" ); QObjectListIt it( *list ); QPushButton *pb; while ((pb = (QPushButton*)it.current())) { if (pb == test) { delete list; if (pb->isVisible() && pb->isEnabled()) pb->animateClick(); return; } ++it; } delete list; */ } } //e->ignore();}static bool closeAll(){ CWINDOW *win; QPtrDictIterator<CWINDOW> iter(CWindow::dict); //qDebug("CLOSE ALL"); for(;;) { win = iter.current(); if (!win) break; if (win != CWINDOW_Main && do_close(win, 0)) { //qDebug("ABORTED %p", win); return true; } ++iter; } return false;}static void deleteAll(){ CWINDOW *win; QPtrDictIterator<CWINDOW> iter(CWindow::dict); //qDebug("DELETE ALL"); for(;;) { win = iter.current(); if (!win) break; ++iter; if (win != CWINDOW_Main) { //CWIDGET_set_flag(win, WF_CLOSED); //qDebug("post DELETE to %p", win); //qApp->postEvent(win->widget.widget, new QEvent(EVENT_CLOSE)); CWIDGET_destroy((CWIDGET *)win); //GB.Post((void *)deleteAfter, win //delete win; } } //qApp->eventLoop()->processEvents(QEventLoop::AllEvents);}void MyMainWindow::closeEvent(QCloseEvent *e){ CWINDOW *_object = (CWINDOW *)CWidget::get(this); bool cancel; e->ignore(); //if (qApp->loopLevel() != THIS->level) // return; //if (_object == CWINDOW_Main && qApp->loopLevel() > 1) // return; //qDebug("closeEvent: level = %d", qApp->loopLevel()); if (MAIN_in_wait) goto IGNORE; if (CWINDOW_Current && (THIS != CWINDOW_Current)) goto IGNORE; if (!THIS) { qWarning("closeEvent: THIS == NULL"); goto IGNORE; } CWIDGET_set_flag(_object, WF_IN_CLOSE); cancel = GB.Raise(_object, EVENT_Close, 0); CWIDGET_clear_flag(_object, WF_IN_CLOSE); if (!cancel && THIS == CWINDOW_Main) { if (closeAll()) cancel = true; } CWIDGET_set_flag(THIS, WF_CLOSED); if (!CWIDGET_test_flag(_object, WF_PERSISTENT)) { if (cancel) goto IGNORE; if (CWINDOW_Main == THIS) { deleteAll(); CWINDOW_Main = 0; } CWIDGET_destroy((CWIDGET *)THIS); } //qDebug("Accept !"); e->accept(); if (testWFlags(Qt::WShowModal)) { //qDebug("exit_loop"); qApp->eventLoop()->exitLoop(); } return;IGNORE: CWIDGET_clear_flag(THIS, WF_CLOSED); e->ignore();}bool MyMainWindow::isPersistent(void){ return !testWFlags(WDestructiveClose);}void MyMainWindow::setPersistent(bool pers){ if (!pers) setWFlags(WDestructiveClose); else clearWFlags(WDestructiveClose);}void MyMainWindow::defineMask(){ CWINDOW *_object = (CWINDOW *)CWidget::get(this); QPixmap *p; //QBitmap b; if (!THIS->mask) { clearMask(); THIS->container->setErasePixmap(0); THIS->container->setBackgroundMode(Qt::PaletteBackground); } else { p = THIS->mask->pixmap; THIS->container->setErasePixmap(*p); if (p->hasAlpha()) { //b = *(p->mask()); setMask(*(p->mask())); //XShapeCombineMask( x11Display(), winId(), ShapeBounding, 0, 0, b.handle(), ShapeSet ); } else clearMask(); } //doReparent(parentWidget(), getWFlags(), pos());}void MyMainWindow::doReparent(QWidget *parent, WFlags f, const QPoint &pos){ bool hasIcon; QPixmap p; CWINDOW *_object = (CWINDOW *)CWidget::get(this); //qDebug("reparent %p to %p", this, parent); hasIcon = icon() != 0; if (hasIcon) p = *icon(); reparent(parent, f, pos); setTopOnly(THIS->topOnly); setSkipTaskbar(THIS->skipTaskbar); if (hasIcon) setIcon(p); //qDebug("new parent = %p", parentWidget());}void MyMainWindow::center(bool force = false){ QPoint p; if (!force && !mustCenter) return; mustCenter = false; p.setX((qApp->desktop()->width() - width()) / 2); p.setY((qApp->desktop()->height() - height()) / 2); move(p);}/*************************************************************************** CWindow***************************************************************************/CWindow CWindow::manager;int CWindow::count = 0;QPtrDict<CWINDOW> CWindow::dict;static void post_activate_event(void *ob){ GB.Raise(ob, EVENT_Activate, 0); GB.Unref(&ob);}static void post_deactivate_event(void *ob){ GB.Raise(ob, EVENT_Deactivate, 0); GB.Unref(&ob);}bool CWindow::eventFilter(QObject *o, QEvent *e){ CWINDOW *ob; //bool cancel; ob = (CWINDOW *)CWidget::get(o); if (ob != NULL) { if (e->type() == QEvent::WindowActivate) { if (ob->window) { //qDebug("Activate: CWINDOW_Current = %p ob = %p", CWINDOW_Current, ob); #if QT_VERSION >= 0x030100 if ((ob == CWINDOW_Current) || (qApp->eventLoop()->loopLevel() <= 1)) #else if ((ob == CWINDOW_Current) || (qApp->loopLevel() <= 1)) #endif //GB.Raise(ob, EVENT_Activate, 0); if (GB.CanRaise(ob, EVENT_Activate)) { GB.Ref(ob); GB.Post((void (*)())post_activate_event, (long)ob); } } } else if (e->type() == QEvent::WindowDeactivate) { if (ob->window) { //qDebug("Deactivate: CWINDOW_Current = %p ob = %p", CWINDOW_Current, ob); #if QT_VERSION >= 0x030100 if ((ob == CWINDOW_Current) || (qApp->eventLoop()->loopLevel() <= 1)) #else if ((ob == CWINDOW_Current) || (qApp->loopLevel() <= 1)) #endif //GB.Raise(ob, EVENT_Deactivate, 0); //((MyMainWindow *)o)->setLastFocus(qApp->focusWidget()); if (GB.CanRaise(ob, EVENT_Deactivate)) { GB.Ref(ob); GB.Post((void (*)())post_deactivate_event, (long)ob); } } } else if (e->type() == QEvent::Show) { MyMainWindow *w = (MyMainWindow *)o; if (ob->window) w->center(); GB.Raise(ob, EVENT_Show, 0); if (ob->focus) { ob->focus->widget->setFocus(); GB.Unref((void **)&ob->focus); ob->focus = NULL; } } else if (e->type() == QEvent::Hide) { GB.Raise(ob, EVENT_Hide, 0); } /*else if (e->type() == EVENT_CLOSE) { qDebug("EVENT_CLOSE %p", ob); s o; return true; }*/ } return QObject::eventFilter(o, e); // standard event processing}/*************************************************************************** CWorkspace***************************************************************************/CWorkspace CWorkspace::manager;bool CWorkspace::eventFilter(QObject *o, QEvent *e){ CWINDOW *ob; QWidget *w; if (e->type() == QEvent::Move) { qDebug("CWorkspace: got move on %p %s", o, o->className()); w = (QWidget *)qt_find_obj_child(o, "MyMainWindow", ""); if (w) { ob = (CWINDOW *)CWidget::get(w); if (ob != NULL) { qDebug("CWorkspace: move"); ((MyMainWindow *)w)->moveEvent((QMoveEvent *)e); } } } return QObject::eventFilter(o, e); // standard event processing}/*************************************************************************** MyEmbeddedWindow***************************************************************************/MyEmbeddedWindow::MyEmbeddedWindow(QWidget *parent) : MyContainer(parent){ shown = false;}MyEmbeddedWindow::~MyEmbeddedWindow(){ void *ob = CWidget::get(this); do_close((CWINDOW *)ob, 0, true);}static void post_show_event(void *_object){ //qDebug("post_show_event %p", WINDOW); GB.Raise(THIS, EVENT_Open, 0); GB.Raise(THIS, EVENT_Move, 0); GB.Raise(THIS, EVENT_Resize, 0); GB.Unref(&_object);}void MyEmbeddedWindow::show(){ //qDebug("MyEmbeddedWindow::show: %p", this); MyContainer::show();}void MyEmbeddedWindow::showEvent(QShowEvent *e){ CWIDGET *ob = CWidget::getReal(this); //qDebug("MyEmbeddedWindow::showEvent: %p", this); MyContainer::showEvent(e); if (!shown) { //qDebug("MyEmbeddedWindow::showEvent: post_show_event"); GB.Ref(ob); GB.Post((void (*)())post_show_event, (long)ob); shown = true; }}void MyEmbeddedWindow::resizeEvent(QResizeEvent *e){ //qDebug("MyEmbeddedWindow::resizeEvent: %p (%d x %d)", this, e->size().width(), e->size().height()); MyContainer::resizeEvent(e); if (shown) GB.Raise(CWidget::getReal(this), EVENT_Resize, 0); //qDebug("--> (%d %d) %s", this->width(), this->height(), shown ? "1" : "0");}void MyEmbeddedWindow::moveEvent(QMoveEvent *e){ CWIDGET *ob = CWidget::getReal(this); //qDebug("embedded Move %p (%d %d)", this, e->pos().x(), e->pos().y()); MyContainer::moveEvent(e); if (shown) GB.Raise(ob, EVENT_Move, 0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -